| @@ -165,6 +165,19 @@ static const char * const iio_chan_info_postfix[] = { · 164 unmodified lines |
| 165 | [IIO_CHAN_INFO_THERMOCOUPLE_TYPE] = "thermocouple_type", | 165 | [IIO_CHAN_INFO_THERMOCOUPLE_TYPE] = "thermocouple_type", |
| 166 | }; | 166 | }; |
| 167 | | 167 | |
| | 168 | #if defined(CONFIG_DEBUG_FS) |
| | 169 | /** |
| | 170 | * There's also a CONFIG_DEBUG_FS guard in include/linux/iio/iio.h for |
| | 171 | * iio_get_debugfs_dentry() to make it inline if CONFIG_DEBUG_FS is undefined |
| | 172 | */ |
| | 173 | struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev) |
| | 174 | { |
| | 175 | struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); |
| | 176 | return iio_dev_opaque->debugfs_dentry; |
| | 177 | } |
| | 178 | EXPORT_SYMBOL_GPL(iio_get_debugfs_dentry); |
| | 179 | #endif |
| | 180 | |
| 168 | /** | 181 | /** |
| 169 | * iio_find_channel_from_si() - get channel from its scan index | 182 | * iio_find_channel_from_si() - get channel from its scan index |
| 170 | * @indio_dev: device | 183 | * @indio_dev: device |
| @@ -308,35 +321,37 @@ static ssize_t iio_debugfs_read_reg(struct file *file, char __user *userbuf, · 137 unmodified lines |
| 308 | size_t count, loff_t *ppos) | 321 | size_t count, loff_t *ppos) |
| 309 | { | 322 | { |
| 310 | struct iio_dev *indio_dev = file->private_data; | 323 | struct iio_dev *indio_dev = file->private_data; |
| | 324 | struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); |
| 311 | unsigned val = 0; | 325 | unsigned val = 0; |
| 312 | int ret; | 326 | int ret; |
| 313 | | 327 | |
| 314 | if (*ppos > 0) | 328 | if (*ppos > 0) |
| 315 | return simple_read_from_buffer(userbuf, count, ppos, | 329 | return simple_read_from_buffer(userbuf, count, ppos, |
| 316 | indio_dev->read_buf, | 330 | iio_dev_opaque->read_buf, |
| 317 | indio_dev->read_buf_len); | 331 | iio_dev_opaque->read_buf_len); |
| 318 | | 332 | |
| 319 | ret = indio_dev->info->debugfs_reg_access(indio_dev, | 333 | ret = indio_dev->info->debugfs_reg_access(indio_dev, |
| 320 | indio_dev->cached_reg_addr, | 334 | iio_dev_opaque->cached_reg_addr, |
| 321 | 0, &val); | 335 | 0, &val); |
| 322 | if (ret) { | 336 | if (ret) { |
| 323 | dev_err(indio_dev->dev.parent, "%s: read failed\n", __func__); | 337 | dev_err(indio_dev->dev.parent, "%s: read failed\n", __func__); |
| 324 | return ret; | 338 | return ret; |
| 325 | } | 339 | } |
| 326 | | 340 | |
| 327 | indio_dev->read_buf_len = snprintf(indio_dev->read_buf, | 341 | iio_dev_opaque->read_buf_len = snprintf(iio_dev_opaque->read_buf, |
| 328 | sizeof(indio_dev->read_buf), | 342 | sizeof(iio_dev_opaque->read_buf), |
| 329 | "0x%X\n", val); | 343 | "0x%X\n", val); |
| 330 | | 344 | |
| 331 | return simple_read_from_buffer(userbuf, count, ppos, | 345 | return simple_read_from_buffer(userbuf, count, ppos, |
| 332 | indio_dev->read_buf, | 346 | iio_dev_opaque->read_buf, |
| 333 | indio_dev->read_buf_len); | 347 | iio_dev_opaque->read_buf_len); |
| 334 | } | 348 | } |
| 335 | | 349 | |
| 336 | static ssize_t iio_debugfs_write_reg(struct file *file, | 350 | static ssize_t iio_debugfs_write_reg(struct file *file, |
| 337 | const char __user *userbuf, size_t count, loff_t *ppos) | 351 | const char __user *userbuf, size_t count, loff_t *ppos) |
| 338 | { | 352 | { |
| 339 | struct iio_dev *indio_dev = file->private_data; | 353 | struct iio_dev *indio_dev = file->private_data; |
| | 354 | struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); |
| 340 | unsigned reg, val; | 355 | unsigned reg, val; |
| 341 | char buf[80]; | 356 | char buf[80]; |
| 342 | int ret; | 357 | int ret; |
| @@ -351,10 +366,10 @@ static ssize_t iio_debugfs_write_reg(struct file *file, · 8 unmodified lines |
| 351 | | 366 | |
| 352 | switch (ret) { | 367 | switch (ret) { |
| 353 | case 1: | 368 | case 1: |
| 354 | indio_dev->cached_reg_addr = reg; | 369 | iio_dev_opaque->cached_reg_addr = reg; |
| 355 | break; | 370 | break; |
| 356 | case 2: | 371 | case 2: |
| 357 | indio_dev->cached_reg_addr = reg; | 372 | iio_dev_opaque->cached_reg_addr = reg; |
| 358 | ret = indio_dev->info->debugfs_reg_access(indio_dev, reg, | 373 | ret = indio_dev->info->debugfs_reg_access(indio_dev, reg, |
| 359 | val, NULL); | 374 | val, NULL); |
| 360 | if (ret) { | 375 | if (ret) { |
| @@ -378,23 +393,28 @@ static const struct file_operations iio_debugfs_reg_fops = { · 17 unmodified lines |
| 378 | | 393 | |
| 379 | static void iio_device_unregister_debugfs(struct iio_dev *indio_dev) | 394 | static void iio_device_unregister_debugfs(struct iio_dev *indio_dev) |
| 380 | { | 395 | { |
| 381 | debugfs_remove_recursive(indio_dev->debugfs_dentry); | 396 | struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); |
| | 397 | debugfs_remove_recursive(iio_dev_opaque->debugfs_dentry); |
| 382 | } | 398 | } |
| 383 | | 399 | |
| 384 | static void iio_device_register_debugfs(struct iio_dev *indio_dev) | 400 | static void iio_device_register_debugfs(struct iio_dev *indio_dev) |
| 385 | { | 401 | { |
| | 402 | struct iio_dev_opaque *iio_dev_opaque; |
| | 403 | |
| 386 | if (indio_dev->info->debugfs_reg_access == NULL) | 404 | if (indio_dev->info->debugfs_reg_access == NULL) |
| 387 | return; | 405 | return; |
| 388 | | 406 | |
| 389 | if (!iio_debugfs_dentry) | 407 | if (!iio_debugfs_dentry) |
| 390 | return; | 408 | return; |
| 391 | | 409 | |
| 392 | indio_dev->debugfs_dentry = | 410 | iio_dev_opaque = to_iio_dev_opaque(indio_dev); |
| | 411 | |
| | 412 | iio_dev_opaque->debugfs_dentry = |
| 393 | debugfs_create_dir(dev_name(&indio_dev->dev), | 413 | debugfs_create_dir(dev_name(&indio_dev->dev), |
| 394 | iio_debugfs_dentry); | 414 | iio_debugfs_dentry); |
| 395 | | 415 | |
| 396 | debugfs_create_file("direct_reg_access", 0644, | 416 | debugfs_create_file("direct_reg_access", 0644, |
| 397 | indio_dev->debugfs_dentry, indio_dev, | 417 | iio_dev_opaque->debugfs_dentry, indio_dev, |
| 398 | &iio_debugfs_reg_fops); | 418 | &iio_debugfs_reg_fops); |
| 399 | } | 419 | } |
| 400 | #else | 420 | #else |