Commit 396f7234 authored by Jonathan Cameron's avatar Jonathan Cameron

iio: core: move @chrdev from struct iio_dev to struct iio_dev_opaque

No reason for this to be exposed to the drivers, so lets move it to the
opaque structure.
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: default avatarAlexandru Ardelean <ardeleanalex@gmail.com>
Link: https://lore.kernel.org/r/20210426174911.397061-8-jic23@kernel.org
parent b804e2b7
...@@ -1715,8 +1715,9 @@ EXPORT_SYMBOL_GPL(devm_iio_device_alloc); ...@@ -1715,8 +1715,9 @@ EXPORT_SYMBOL_GPL(devm_iio_device_alloc);
**/ **/
static int iio_chrdev_open(struct inode *inode, struct file *filp) static int iio_chrdev_open(struct inode *inode, struct file *filp)
{ {
struct iio_dev *indio_dev = container_of(inode->i_cdev, struct iio_dev_opaque *iio_dev_opaque =
struct iio_dev, chrdev); container_of(inode->i_cdev, struct iio_dev_opaque, chrdev);
struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;
struct iio_dev_buffer_pair *ib; struct iio_dev_buffer_pair *ib;
if (test_and_set_bit(IIO_BUSY_BIT_POS, &indio_dev->flags)) if (test_and_set_bit(IIO_BUSY_BIT_POS, &indio_dev->flags))
...@@ -1749,8 +1750,9 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp) ...@@ -1749,8 +1750,9 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp)
static int iio_chrdev_release(struct inode *inode, struct file *filp) static int iio_chrdev_release(struct inode *inode, struct file *filp)
{ {
struct iio_dev_buffer_pair *ib = filp->private_data; struct iio_dev_buffer_pair *ib = filp->private_data;
struct iio_dev *indio_dev = container_of(inode->i_cdev, struct iio_dev_opaque *iio_dev_opaque =
struct iio_dev, chrdev); container_of(inode->i_cdev, struct iio_dev_opaque, chrdev);
struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;
kfree(ib); kfree(ib);
clear_bit(IIO_BUSY_BIT_POS, &indio_dev->flags); clear_bit(IIO_BUSY_BIT_POS, &indio_dev->flags);
iio_device_put(indio_dev); iio_device_put(indio_dev);
...@@ -1900,19 +1902,19 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) ...@@ -1900,19 +1902,19 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
indio_dev->setup_ops = &noop_ring_setup_ops; indio_dev->setup_ops = &noop_ring_setup_ops;
if (iio_dev_opaque->attached_buffers_cnt) if (iio_dev_opaque->attached_buffers_cnt)
cdev_init(&indio_dev->chrdev, &iio_buffer_fileops); cdev_init(&iio_dev_opaque->chrdev, &iio_buffer_fileops);
else if (iio_dev_opaque->event_interface) else if (iio_dev_opaque->event_interface)
cdev_init(&indio_dev->chrdev, &iio_event_fileops); cdev_init(&iio_dev_opaque->chrdev, &iio_event_fileops);
if (iio_dev_opaque->attached_buffers_cnt || iio_dev_opaque->event_interface) { if (iio_dev_opaque->attached_buffers_cnt || iio_dev_opaque->event_interface) {
indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), iio_dev_opaque->id); indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), iio_dev_opaque->id);
indio_dev->chrdev.owner = this_mod; iio_dev_opaque->chrdev.owner = this_mod;
} }
/* assign device groups now; they should be all registered now */ /* assign device groups now; they should be all registered now */
indio_dev->dev.groups = iio_dev_opaque->groups; indio_dev->dev.groups = iio_dev_opaque->groups;
ret = cdev_device_add(&indio_dev->chrdev, &indio_dev->dev); ret = cdev_device_add(&iio_dev_opaque->chrdev, &indio_dev->dev);
if (ret < 0) if (ret < 0)
goto error_unreg_eventset; goto error_unreg_eventset;
...@@ -1936,7 +1938,9 @@ EXPORT_SYMBOL(__iio_device_register); ...@@ -1936,7 +1938,9 @@ EXPORT_SYMBOL(__iio_device_register);
**/ **/
void iio_device_unregister(struct iio_dev *indio_dev) void iio_device_unregister(struct iio_dev *indio_dev)
{ {
cdev_device_del(&indio_dev->chrdev, &indio_dev->dev); struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
cdev_device_del(&iio_dev_opaque->chrdev, &indio_dev->dev);
mutex_lock(&iio_dev_opaque->info_exist_lock); mutex_lock(&iio_dev_opaque->info_exist_lock);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
* @legacy_scan_el_group: attribute group for legacy scan elements attribute group * @legacy_scan_el_group: attribute group for legacy scan elements attribute group
* @legacy_buffer_group: attribute group for legacy buffer attributes group * @legacy_buffer_group: attribute group for legacy buffer attributes group
* @scan_index_timestamp: cache of the index to the timestamp * @scan_index_timestamp: cache of the index to the timestamp
* @chrdev: associated character device
* @debugfs_dentry: device specific debugfs dentry * @debugfs_dentry: device specific debugfs dentry
* @cached_reg_addr: cached register address for debugfs reads * @cached_reg_addr: cached register address for debugfs reads
* @read_buf: read buffer to be used for the initial reg read * @read_buf: read buffer to be used for the initial reg read
...@@ -49,6 +50,7 @@ struct iio_dev_opaque { ...@@ -49,6 +50,7 @@ struct iio_dev_opaque {
struct attribute_group legacy_buffer_group; struct attribute_group legacy_buffer_group;
unsigned int scan_index_timestamp; unsigned int scan_index_timestamp;
struct cdev chrdev;
#if defined(CONFIG_DEBUG_FS) #if defined(CONFIG_DEBUG_FS)
struct dentry *debugfs_dentry; struct dentry *debugfs_dentry;
......
...@@ -512,7 +512,6 @@ struct iio_buffer_setup_ops { ...@@ -512,7 +512,6 @@ struct iio_buffer_setup_ops {
* @clock_id: [INTERN] timestamping clock posix identifier * @clock_id: [INTERN] timestamping clock posix identifier
* @setup_ops: [DRIVER] callbacks to call before and after buffer * @setup_ops: [DRIVER] callbacks to call before and after buffer
* enable/disable * enable/disable
* @chrdev: [INTERN] associated character device
* @flags: [INTERN] file ops related flags including busy flag. * @flags: [INTERN] file ops related flags including busy flag.
* @priv: [DRIVER] reference to driver's private information * @priv: [DRIVER] reference to driver's private information
* **MUST** be accessed **ONLY** via iio_priv() helper * **MUST** be accessed **ONLY** via iio_priv() helper
...@@ -542,7 +541,6 @@ struct iio_dev { ...@@ -542,7 +541,6 @@ struct iio_dev {
const struct iio_info *info; const struct iio_info *info;
clockid_t clock_id; clockid_t clock_id;
const struct iio_buffer_setup_ops *setup_ops; const struct iio_buffer_setup_ops *setup_ops;
struct cdev chrdev;
unsigned long flags; unsigned long flags;
void *priv; void *priv;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment