History

iio: core: move debugfs data on the private iio dev info

This change moves all iio_dev debugfs fields to the iio_dev_priv object. It's not the biggest advantage yet (to the whole thing of abstractization) but it's a start. The iio_get_debugfs_dentry() function (which is moved in industrialio-core.c) needs to also be guarded against the CONFIG_DEBUG_FS symbol, when it isn't defined. We do want to keep the inline definition in the iio.h header, so that the compiler can better infer when to compile out debugfs code that is related to the IIO debugfs directory.

Alexandru Ardelean committed 6 years ago

Commit 96fb1b61 parent 09673d53 files · +44 −25Browse files

Unified · Split

3 files
  1. drivers/iio/industrialio-core.c +33 −13
  2. include/linux/iio/iio-opaque.h +10 −0
  3. include/linux/iio/iio.h +1 −12
drivers/iio/industrialio-core.c+33−13
@@ -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 */
173struct 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}
178EXPORT_SYMBOL_GPL(iio_get_debugfs_dentry);
179#endif
180
168/**181/**
169 * iio_find_channel_from_si() - get channel from its scan index182 * iio_find_channel_from_si() - get channel from its scan index
170 * @indio_dev: device183 * @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
336static ssize_t iio_debugfs_write_reg(struct file *file,350static 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
379static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)394static 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
384static void iio_device_register_debugfs(struct iio_dev *indio_dev)400static 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#else420#else
include/linux/iio/iio-opaque.h+10−0
@@ -6,9 +6,19 @@ · 5 unmodified lines
6/**6/**
7 * struct iio_dev_opaque - industrial I/O device opaque information7 * struct iio_dev_opaque - industrial I/O device opaque information
8 * @indio_dev: public industrial I/O device information8 * @indio_dev: public industrial I/O device information
9 * @debugfs_dentry: device specific debugfs dentry
10 * @cached_reg_addr: cached register address for debugfs reads
11 * @read_buf: read buffer to be used for the initial reg read
12 * @read_buf_len: data length in @read_buf
9 */13 */
10struct iio_dev_opaque {14struct iio_dev_opaque {
11 struct iio_dev indio_dev;15 struct iio_dev indio_dev;
16#if defined(CONFIG_DEBUG_FS)
17 struct dentry *debugfs_dentry;
18 unsigned cached_reg_addr;
19 char read_buf[20];
20 unsigned int read_buf_len;
21#endif
12};22};
13 23
14#define to_iio_dev_opaque(indio_dev) \24#define to_iio_dev_opaque(indio_dev) \
include/linux/iio/iio.h+1−12
@@ -520,8 +520,6 @@ struct iio_buffer_setup_ops { · 519 unmodified lines
520 * @groups: [INTERN] attribute groups520 * @groups: [INTERN] attribute groups
521 * @groupcounter: [INTERN] index of next attribute group521 * @groupcounter: [INTERN] index of next attribute group
522 * @flags: [INTERN] file ops related flags including busy flag.522 * @flags: [INTERN] file ops related flags including busy flag.
523 * @debugfs_dentry: [INTERN] device specific debugfs dentry.
524 * @cached_reg_addr: [INTERN] cached register address for debugfs reads.
525 * @priv: [DRIVER] reference to driver's private information523 * @priv: [DRIVER] reference to driver's private information
526 * **MUST** be accessed **ONLY** via iio_priv() helper524 * **MUST** be accessed **ONLY** via iio_priv() helper
527 */525 */
@@ -567,12 +565,6 @@ struct iio_dev { · 39 unmodified lines
567 int groupcounter;565 int groupcounter;
568 566
569 unsigned long flags;567 unsigned long flags;
570#if defined(CONFIG_DEBUG_FS)
571 struct dentry *debugfs_dentry;
572 unsigned cached_reg_addr;
573 char read_buf[20];
574 unsigned int read_buf_len;
575#endif
576 void *priv;568 void *priv;
577};569};
578 570
@@ -733,10 +725,7 @@ static inline bool iio_buffer_enabled(struct iio_dev *indio_dev) · 154 unmodified lines
733 * @indio_dev: IIO device structure for device725 * @indio_dev: IIO device structure for device
734 **/726 **/
735#if defined(CONFIG_DEBUG_FS)727#if defined(CONFIG_DEBUG_FS)
736static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)728struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev);
737{
738 return indio_dev->debugfs_dentry;
739}
740#else729#else
741static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)730static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
742{731{