summaryrefslogtreecommitdiff
path: root/include/linux/iio/iio.h
diff options
context:
space:
mode:
authorJonathan Cameron <jic23@kernel.org>2017-07-23 17:25:43 +0100
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2017-08-22 20:03:14 +0100
commit63b19547cc3d96041d7bc7ab8de6292b0ebaf2c9 (patch)
tree471c61258a87337a3458077411f8638fe976b3c8 /include/linux/iio/iio.h
parenta575de2da5e20c31f4ffcb1df555c199ad77fc20 (diff)
iio: Use macro magic to avoid manual assign of driver_module
Starting point in boiler plate reduction similar to that done for many similar cases elsewhere in the kernel. Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
Diffstat (limited to 'include/linux/iio/iio.h')
-rw-r--r--include/linux/iio/iio.h31
1 files changed, 29 insertions, 2 deletions
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index d68bec297a45..97a014300947 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -518,6 +518,7 @@ struct iio_buffer_setup_ops {
/**
* struct iio_dev - industrial I/O device
* @id: [INTERN] used to identify device internally
+ * @driver_module: [INTERN] used to make it harder to undercut users
* @modes: [DRIVER] operating modes supported by device
* @currentmode: [DRIVER] current operating mode
* @dev: [DRIVER] device structure, should be assigned a parent
@@ -558,6 +559,7 @@ struct iio_buffer_setup_ops {
*/
struct iio_dev {
int id;
+ struct module *driver_module;
int modes;
int currentmode;
@@ -604,9 +606,34 @@ struct iio_dev {
const struct iio_chan_spec
*iio_find_channel_from_si(struct iio_dev *indio_dev, int si);
-int iio_device_register(struct iio_dev *indio_dev);
+/**
+ * iio_device_register() - register a device with the IIO subsystem
+ * @indio_dev: Device structure filled by the device driver
+ **/
+#define iio_device_register(iio_dev) \
+ __iio_device_register((iio_dev), THIS_MODULE)
+int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod);
void iio_device_unregister(struct iio_dev *indio_dev);
-int devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev);
+/**
+ * devm_iio_device_register - Resource-managed iio_device_register()
+ * @dev: Device to allocate iio_dev for
+ * @indio_dev: Device structure filled by the device driver
+ *
+ * Managed iio_device_register. The IIO device registered with this
+ * function is automatically unregistered on driver detach. This function
+ * calls iio_device_register() internally. Refer to that function for more
+ * information.
+ *
+ * If an iio_dev registered with this function needs to be unregistered
+ * separately, devm_iio_device_unregister() must be used.
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+#define devm_iio_device_register(dev, indio_dev) \
+ __devm_iio_device_register((dev), (indio_dev), THIS_MODULE);
+int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev,
+ struct module *this_mod);
void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev);
int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp);
int iio_device_claim_direct_mode(struct iio_dev *indio_dev);