Skip to content

Commit 2d66f38

Browse files
larsclausenjic23
authored andcommitted
iio: Introduce iio_device_{set,get}_drvdata()
Introduce two new helper functions to attach a arbitrary pointer to a IIO device. This is useful to get access to external non-global data from within a IIO device callbacks where only the IIO device is available. Internally these functions use dev_{set,get}_drvdata() on the struct device embedded in the IIO device. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent 49f8812 commit 2d66f38

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

include/linux/iio/iio.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,31 @@ static inline struct iio_dev *iio_device_get(struct iio_dev *indio_dev)
516516
return indio_dev ? dev_to_iio_dev(get_device(&indio_dev->dev)) : NULL;
517517
}
518518

519+
520+
/**
521+
* iio_device_set_drvdata() - Set device driver data
522+
* @indio_dev: IIO device structure
523+
* @data: Driver specific data
524+
*
525+
* Allows to attach an arbitrary pointer to an IIO device, which can later be
526+
* retrieved by iio_device_get_drvdata().
527+
*/
528+
static inline void iio_device_set_drvdata(struct iio_dev *indio_dev, void *data)
529+
{
530+
dev_set_drvdata(&indio_dev->dev, data);
531+
}
532+
533+
/**
534+
* iio_device_get_drvdata() - Get device driver data
535+
* @indio_dev: IIO device structure
536+
*
537+
* Returns the data previously set with iio_device_set_drvdata()
538+
*/
539+
static inline void *iio_device_get_drvdata(struct iio_dev *indio_dev)
540+
{
541+
return dev_get_drvdata(&indio_dev->dev);
542+
}
543+
519544
/* Can we make this smaller? */
520545
#define IIO_ALIGN L1_CACHE_BYTES
521546
/**

0 commit comments

Comments
 (0)