hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/include/linux/iio/iio.h
....@@ -1,11 +1,8 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12
23 /* The industrial I/O core
34 *
45 * Copyright (c) 2008 Jonathan Cameron
5
- *
6
- * This program is free software; you can redistribute it and/or modify it
7
- * under the terms of the GNU General Public License version 2 as published by
8
- * the Free Software Foundation.
96 */
107 #ifndef _INDUSTRIAL_IO_H_
118 #define _INDUSTRIAL_IO_H_
....@@ -130,8 +127,8 @@
130127
131128 ssize_t iio_show_mount_matrix(struct iio_dev *indio_dev, uintptr_t priv,
132129 const struct iio_chan_spec *chan, char *buf);
133
-int of_iio_read_mount_matrix(const struct device *dev, const char *propname,
134
- struct iio_mount_matrix *matrix);
130
+int iio_read_mount_matrix(struct device *dev, const char *propname,
131
+ struct iio_mount_matrix *matrix);
135132
136133 typedef const struct iio_mount_matrix *
137134 (iio_get_mount_matrix_t)(const struct iio_dev *indio_dev,
....@@ -491,11 +488,9 @@
491488 * @currentmode: [DRIVER] current operating mode
492489 * @dev: [DRIVER] device structure, should be assigned a parent
493490 * and owner
494
- * @event_interface: [INTERN] event chrdevs associated with interrupt lines
495491 * @buffer: [DRIVER] any buffer present
496
- * @buffer_list: [INTERN] list of all buffers currently attached
497492 * @scan_bytes: [INTERN] num bytes captured to be fed to buffer demux
498
- * @mlock: [DRIVER] lock used to prevent simultaneous device state
493
+ * @mlock: [INTERN] lock used to prevent simultaneous device state
499494 * changes
500495 * @available_scan_masks: [DRIVER] optional array of allowed bitmasks
501496 * @masklength: [INTERN] the length of the mask established from
....@@ -509,10 +504,8 @@
509504 * @pollfunc_event: [DRIVER] function run on events trigger being received
510505 * @channels: [DRIVER] channel specification structure table
511506 * @num_channels: [DRIVER] number of channels specified in @channels.
512
- * @channel_attr_list: [INTERN] keep track of automatically created channel
513
- * attributes
514
- * @chan_attr_group: [INTERN] group for all attrs in base directory
515507 * @name: [DRIVER] name of the device.
508
+ * @label: [DRIVER] unique name to identify which device this is
516509 * @info: [DRIVER] callbacks and constant info from driver
517510 * @clock_id: [INTERN] timestamping clock posix identifier
518511 * @info_exist_lock: [INTERN] lock to prevent use during removal
....@@ -522,8 +515,8 @@
522515 * @groups: [INTERN] attribute groups
523516 * @groupcounter: [INTERN] index of next attribute group
524517 * @flags: [INTERN] file ops related flags including busy flag.
525
- * @debugfs_dentry: [INTERN] device specific debugfs dentry.
526
- * @cached_reg_addr: [INTERN] cached register address for debugfs reads.
518
+ * @priv: [DRIVER] reference to driver's private information
519
+ * **MUST** be accessed **ONLY** via iio_priv() helper
527520 */
528521 struct iio_dev {
529522 int id;
....@@ -533,10 +526,7 @@
533526 int currentmode;
534527 struct device dev;
535528
536
- struct iio_event_interface *event_interface;
537
-
538529 struct iio_buffer *buffer;
539
- struct list_head buffer_list;
540530 int scan_bytes;
541531 struct mutex mlock;
542532
....@@ -553,9 +543,8 @@
553543 struct iio_chan_spec const *channels;
554544 int num_channels;
555545
556
- struct list_head channel_attr_list;
557
- struct attribute_group chan_attr_group;
558546 const char *name;
547
+ const char *label;
559548 const struct iio_info *info;
560549 clockid_t clock_id;
561550 struct mutex info_exist_lock;
....@@ -566,10 +555,7 @@
566555 int groupcounter;
567556
568557 unsigned long flags;
569
-#if defined(CONFIG_DEBUG_FS)
570
- struct dentry *debugfs_dentry;
571
- unsigned cached_reg_addr;
572
-#endif
558
+ void *priv;
573559 };
574560
575561 const struct iio_chan_spec
....@@ -592,9 +578,6 @@
592578 * calls iio_device_register() internally. Refer to that function for more
593579 * information.
594580 *
595
- * If an iio_dev registered with this function needs to be unregistered
596
- * separately, devm_iio_device_unregister() must be used.
597
- *
598581 * RETURNS:
599582 * 0 on success, negative error number on failure.
600583 */
....@@ -602,7 +585,6 @@
602585 __devm_iio_device_register((dev), (indio_dev), THIS_MODULE)
603586 int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev,
604587 struct module *this_mod);
605
-void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev);
606588 int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp);
607589 int iio_device_claim_direct_mode(struct iio_dev *indio_dev);
608590 void iio_device_release_direct_mode(struct iio_dev *indio_dev);
....@@ -628,6 +610,8 @@
628610 return indio_dev->clock_id;
629611 }
630612
613
+int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id);
614
+
631615 /**
632616 * dev_to_iio_dev() - Get IIO device struct from a device struct
633617 * @dev: The device embedded in the IIO device
....@@ -650,6 +634,26 @@
650634 return indio_dev ? dev_to_iio_dev(get_device(&indio_dev->dev)) : NULL;
651635 }
652636
637
+/**
638
+ * iio_device_set_parent() - assign parent device to the IIO device object
639
+ * @indio_dev: IIO device structure
640
+ * @parent: reference to parent device object
641
+ *
642
+ * This utility must be called between IIO device allocation
643
+ * (via devm_iio_device_alloc()) & IIO device registration
644
+ * (via iio_device_register() and devm_iio_device_register())).
645
+ * By default, the device allocation will also assign a parent device to
646
+ * the IIO device object. In cases where devm_iio_device_alloc() is used,
647
+ * sometimes the parent device must be different than the device used to
648
+ * manage the allocation.
649
+ * In that case, this helper should be used to change the parent, hence the
650
+ * requirement to call this between allocation & registration.
651
+ **/
652
+static inline void iio_device_set_parent(struct iio_dev *indio_dev,
653
+ struct device *parent)
654
+{
655
+ indio_dev->dev.parent = parent;
656
+}
653657
654658 /**
655659 * iio_device_set_drvdata() - Set device driver data
....@@ -670,34 +674,26 @@
670674 *
671675 * Returns the data previously set with iio_device_set_drvdata()
672676 */
673
-static inline void *iio_device_get_drvdata(struct iio_dev *indio_dev)
677
+static inline void *iio_device_get_drvdata(const struct iio_dev *indio_dev)
674678 {
675679 return dev_get_drvdata(&indio_dev->dev);
676680 }
677681
678682 /* Can we make this smaller? */
679683 #define IIO_ALIGN L1_CACHE_BYTES
680
-struct iio_dev *iio_device_alloc(int sizeof_priv);
684
+struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv);
681685
686
+/* The information at the returned address is guaranteed to be cacheline aligned */
682687 static inline void *iio_priv(const struct iio_dev *indio_dev)
683688 {
684
- return (char *)indio_dev + ALIGN(sizeof(struct iio_dev), IIO_ALIGN);
685
-}
686
-
687
-static inline struct iio_dev *iio_priv_to_dev(void *priv)
688
-{
689
- return (struct iio_dev *)((char *)priv -
690
- ALIGN(sizeof(struct iio_dev), IIO_ALIGN));
689
+ return indio_dev->priv;
691690 }
692691
693692 void iio_device_free(struct iio_dev *indio_dev);
694
-int devm_iio_device_match(struct device *dev, void *res, void *data);
695
-struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv);
696
-void devm_iio_device_free(struct device *dev, struct iio_dev *indio_dev);
693
+struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv);
694
+__printf(2, 3)
697695 struct iio_trigger *devm_iio_trigger_alloc(struct device *dev,
698
- const char *fmt, ...);
699
-void devm_iio_trigger_free(struct device *dev, struct iio_trigger *iio_trig);
700
-
696
+ const char *fmt, ...);
701697 /**
702698 * iio_buffer_enabled() - helper function to test if the buffer is enabled
703699 * @indio_dev: IIO device structure for device
....@@ -714,10 +710,7 @@
714710 * @indio_dev: IIO device structure for device
715711 **/
716712 #if defined(CONFIG_DEBUG_FS)
717
-static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
718
-{
719
- return indio_dev->debugfs_dentry;
720
-}
713
+struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev);
721714 #else
722715 static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
723716 {