| @@ -165,6 +165,19 @@ static const char * const iio_chan_info_postfix[] = { · 164 unmodified lines |
| 165 | 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 | 182 | * iio_find_channel_from_si() - get channel from its scan index |
| 170 | 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 | 321 | size_t count, loff_t *ppos) |
| 309 | 322 | { |
| 310 | 323 | struct iio_dev *indio_dev = file->private_data; |
| 324 | + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); |
| 311 | 325 | unsigned val = 0; |
| 312 | 326 | int ret; |
| 313 | 327 | |
| 314 | 328 | if (*ppos > 0) |
| 315 | 329 | return simple_read_from_buffer(userbuf, count, ppos, |
| 316 | | − indio_dev->read_buf, |
| 317 | | − indio_dev->read_buf_len); |
| 330 | + iio_dev_opaque->read_buf, |
| 331 | + iio_dev_opaque->read_buf_len); |
| 318 | 332 | |
| 319 | 333 | ret = indio_dev->info->debugfs_reg_access(indio_dev, |
| 320 | | − indio_dev->cached_reg_addr, |
| 334 | + iio_dev_opaque->cached_reg_addr, |
| 321 | 335 | 0, &val); |
| 322 | 336 | if (ret) { |
| 323 | 337 | dev_err(indio_dev->dev.parent, "%s: read failed\n", __func__); |
| 324 | 338 | return ret; |
| 325 | 339 | } |
| 326 | 340 | |
| 327 | | − indio_dev->read_buf_len = snprintf(indio_dev->read_buf, |
| 328 | | − sizeof(indio_dev->read_buf), |
| 329 | | − "0x%X\n", val); |
| 341 | + iio_dev_opaque->read_buf_len = snprintf(iio_dev_opaque->read_buf, |
| 342 | + sizeof(iio_dev_opaque->read_buf), |
| 343 | + "0x%X\n", val); |
| 330 | 344 | |
| 331 | 345 | return simple_read_from_buffer(userbuf, count, ppos, |
| 332 | | − indio_dev->read_buf, |
| 333 | | − indio_dev->read_buf_len); |
| 346 | + iio_dev_opaque->read_buf, |
| 347 | + iio_dev_opaque->read_buf_len); |
| 334 | 348 | } |
| 335 | 349 | |
| 336 | 350 | static ssize_t iio_debugfs_write_reg(struct file *file, |
| 337 | 351 | const char __user *userbuf, size_t count, loff_t *ppos) |
| 338 | 352 | { |
| 339 | 353 | struct iio_dev *indio_dev = file->private_data; |
| 354 | + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); |
| 340 | 355 | unsigned reg, val; |
| 341 | 356 | char buf[80]; |
| 342 | 357 | int ret; |
| @@ -351,10 +366,10 @@ static ssize_t iio_debugfs_write_reg(struct file *file, · 8 unmodified lines |
| 351 | 366 | |
| 352 | 367 | switch (ret) { |
| 353 | 368 | case 1: |
| 354 | | − indio_dev->cached_reg_addr = reg; |
| 369 | + iio_dev_opaque->cached_reg_addr = reg; |
| 355 | 370 | break; |
| 356 | 371 | case 2: |
| 357 | | − indio_dev->cached_reg_addr = reg; |
| 372 | + iio_dev_opaque->cached_reg_addr = reg; |
| 358 | 373 | ret = indio_dev->info->debugfs_reg_access(indio_dev, reg, |
| 359 | 374 | val, NULL); |
| 360 | 375 | if (ret) { |
| @@ -378,23 +393,28 @@ static const struct file_operations iio_debugfs_reg_fops = { · 17 unmodified lines |
| 378 | 393 | |
| 379 | 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 | 400 | static void iio_device_register_debugfs(struct iio_dev *indio_dev) |
| 385 | 401 | { |
| 402 | + struct iio_dev_opaque *iio_dev_opaque; |
| 403 | + |
| 386 | 404 | if (indio_dev->info->debugfs_reg_access == NULL) |
| 387 | 405 | return; |
| 388 | 406 | |
| 389 | 407 | if (!iio_debugfs_dentry) |
| 390 | 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 | 413 | debugfs_create_dir(dev_name(&indio_dev->dev), |
| 394 | 414 | iio_debugfs_dentry); |
| 395 | 415 | |
| 396 | 416 | debugfs_create_file("direct_reg_access", 0644, |
| 397 | | − indio_dev->debugfs_dentry, indio_dev, |
| 417 | + iio_dev_opaque->debugfs_dentry, indio_dev, |
| 398 | 418 | &iio_debugfs_reg_fops); |
| 399 | 419 | } |
| 400 | 420 | #else |