Re: [PATCH] iio: core: centralize ioctl() calls to the main chardev

2020-11-14 Thread Alexandru Ardelean
On Sat, Nov 14, 2020 at 5:32 PM Jonathan Cameron
 wrote:
>
> On Sat, 14 Nov 2020 15:30:23 +
> Jonathan Cameron  wrote:
>
> > On Mon, 2 Nov 2020 08:59:57 +0200
> > Alexandru Ardelean  wrote:
> >
> > > On Fri, Sep 25, 2020 at 3:38 PM Jonathan Cameron  wrote:
> > > >
> > > > On Thu, 24 Sep 2020 11:41:55 +0300
> > > > Alexandru Ardelean  wrote:
> > > >
> > > > > The aim of this is to improve a bit the organization of ioctl() calls 
> > > > > in
> > > > > IIO core. Currently the chardev is split across IIO core 
> > > > > sub-modules/files.
> > > > > The main chardev has to be able to handle ioctl() calls, and if we 
> > > > > need to
> > > > > add buffer ioctl() calls, this would complicate things.
> > > > >
> > > > > The 'industrialio-core.c' file will provide a 'iio_device_ioctl()' 
> > > > > which
> > > > > will iterate over a list of ioctls registered with the IIO device. 
> > > > > These
> > > > > can be event ioctl() or buffer ioctl() calls, or something else.
> > > > >
> > > > > Each ioctl() handler will have to return a IIO_IOCTL_UNHANDLED code 
> > > > > (which
> > > > > is positive 1), if the ioctl() did not handle the call in any. This
> > > > > eliminates any potential ambiguities about negative error codes, which
> > > > > should fail the call altogether.
> > > > >
> > > > > If any ioctl() returns 0, it was considered that it was serviced
> > > > > successfully and the loop will exit.
> > > > >
> > > > > This change also moves the handling of the IIO_GET_EVENT_FD_IOCTL 
> > > > > command
> > > > > inside 'industrialio-event.c', where this is better suited.
> > > > >
> > > > > This patch is a combination of 2 other patches from an older series:
> > > > > Patch 1: iio: core: add simple centralized mechanism for ioctl() 
> > > > > handlers
> > > > >   Link: 
> > > > > https://lore.kernel.org/linux-iio/20200427131100.50845-6-alexandru.ardel...@analog.com/
> > > > > Patch 2: iio: core: use new common ioctl() mechanism
> > > > >   Link: 
> > > > > https://lore.kernel.org/linux-iio/20200427131100.50845-7-alexandru.ardel...@analog.com/
> > > > >
> > > > > Signed-off-by: Alexandru Ardelean 
> > > > > ---
> > > > >
> > > > > Note: since this is a change to the IIO core, we don't need to put 
> > > > > this in
> > > > > right now; especially if there is a tight schedule, or we are too 
> > > > > close to
> > > > > a merge window.
> > > >
> > > > Looks good to me.  As you suggest, lets let this one sit on the list 
> > > > for a
> > > > while though!
> > >
> > > ping on this
> >
> > Thanks.  Was still on my list, but I've been lazy and not been clearing that
> > out for a while - too many scary things there :)
> >
> > Anyhow, applied to the togreg branch of iio.git and pushed out as testing 
> > for
> > all the normal reasons.
> Hmm. I should really wait for local build tests to finish.  Tweaked to
> remove the bonus @ where you have @@ in the docs.
>
> Note I'm build testing with W=1 these days that finds this sort of docs
> issue.

I should also start using W=1 that in my build-checks.
I think I am getting more often hit by these lately.

>
> thanks,
>
> Jonathan
>
> >
> > Thanks,
> >
> > Jonathan
> >
> > >
> > > thanks
> > > Alex
> > >
> > > >
> > > > Jonathan
> > > >
> > > > >
> > > > >  drivers/iio/iio_core.h   | 15 -
> > > > >  drivers/iio/industrialio-core.c  | 56 
> > > > > 
> > > > >  drivers/iio/industrialio-event.c | 28 +++-
> > > > >  include/linux/iio/iio-opaque.h   |  2 ++
> > > > >  4 files changed, 85 insertions(+), 16 deletions(-)
> > > > >
> > > > > diff --git a/drivers/iio/iio_core.h b/drivers/iio/iio_core.h
> > > > > index fd9a5f1d5e51..fced02cadcc3 100644
> > > > > --- a/drivers/iio/iio_core.h
> > > > > +++ b/drivers/iio/iio_core.h
> > > > > @@ -17,6 +17,20 @@ struct iio_dev;
> > > > >
> > > > >  extern struct device_type iio_device_type;
> > > > >
> > > > > +#define IIO_IOCTL_UNHANDLED  1
> > > > > +struct iio_ioctl_handler {
> > > > > + struct list_head entry;
> > > > > + long (*ioctl)(struct iio_dev *indio_dev, struct file *filp,
> > > > > +   unsigned int cmd, unsigned long arg);
> > > > > +};
> > > > > +
> > > > > +long iio_device_ioctl(struct iio_dev *indio_dev, struct file *filp,
> > > > > +   unsigned int cmd, unsigned long arg);
> > > > > +
> > > > > +void iio_device_ioctl_handler_register(struct iio_dev *indio_dev,
> > > > > +struct iio_ioctl_handler *h);
> > > > > +void iio_device_ioctl_handler_unregister(struct iio_ioctl_handler 
> > > > > *h);
> > > > > +
> > > > >  int __iio_add_chan_devattr(const char *postfix,
> > > > >  struct iio_chan_spec const *chan,
> > > > >  ssize_t (*func)(struct device *dev,
> > > > > @@ -74,7 +88,6 @@ static inline void iio_buffer_wakeup_poll(struct 
> > > > > iio_dev *indio_dev) {}
> > > > >  int iio_device_register_eventset(struct iio_dev *indio_dev);
> > > > 

Re: [PATCH] iio: core: centralize ioctl() calls to the main chardev

2020-11-14 Thread Jonathan Cameron
On Sat, 14 Nov 2020 15:30:23 +
Jonathan Cameron  wrote:

> On Mon, 2 Nov 2020 08:59:57 +0200
> Alexandru Ardelean  wrote:
> 
> > On Fri, Sep 25, 2020 at 3:38 PM Jonathan Cameron  wrote:  
> > >
> > > On Thu, 24 Sep 2020 11:41:55 +0300
> > > Alexandru Ardelean  wrote:
> > >
> > > > The aim of this is to improve a bit the organization of ioctl() calls in
> > > > IIO core. Currently the chardev is split across IIO core 
> > > > sub-modules/files.
> > > > The main chardev has to be able to handle ioctl() calls, and if we need 
> > > > to
> > > > add buffer ioctl() calls, this would complicate things.
> > > >
> > > > The 'industrialio-core.c' file will provide a 'iio_device_ioctl()' which
> > > > will iterate over a list of ioctls registered with the IIO device. These
> > > > can be event ioctl() or buffer ioctl() calls, or something else.
> > > >
> > > > Each ioctl() handler will have to return a IIO_IOCTL_UNHANDLED code 
> > > > (which
> > > > is positive 1), if the ioctl() did not handle the call in any. This
> > > > eliminates any potential ambiguities about negative error codes, which
> > > > should fail the call altogether.
> > > >
> > > > If any ioctl() returns 0, it was considered that it was serviced
> > > > successfully and the loop will exit.
> > > >
> > > > This change also moves the handling of the IIO_GET_EVENT_FD_IOCTL 
> > > > command
> > > > inside 'industrialio-event.c', where this is better suited.
> > > >
> > > > This patch is a combination of 2 other patches from an older series:
> > > > Patch 1: iio: core: add simple centralized mechanism for ioctl() 
> > > > handlers
> > > >   Link: 
> > > > https://lore.kernel.org/linux-iio/20200427131100.50845-6-alexandru.ardel...@analog.com/
> > > > Patch 2: iio: core: use new common ioctl() mechanism
> > > >   Link: 
> > > > https://lore.kernel.org/linux-iio/20200427131100.50845-7-alexandru.ardel...@analog.com/
> > > >
> > > > Signed-off-by: Alexandru Ardelean 
> > > > ---
> > > >
> > > > Note: since this is a change to the IIO core, we don't need to put this 
> > > > in
> > > > right now; especially if there is a tight schedule, or we are too close 
> > > > to
> > > > a merge window.
> > >
> > > Looks good to me.  As you suggest, lets let this one sit on the list for a
> > > while though!
> > 
> > ping on this  
> 
> Thanks.  Was still on my list, but I've been lazy and not been clearing that
> out for a while - too many scary things there :)
> 
> Anyhow, applied to the togreg branch of iio.git and pushed out as testing for
> all the normal reasons.
Hmm. I should really wait for local build tests to finish.  Tweaked to
remove the bonus @ where you have @@ in the docs.

Note I'm build testing with W=1 these days that finds this sort of docs
issue.

thanks,

Jonathan

> 
> Thanks,
> 
> Jonathan
> 
> > 
> > thanks
> > Alex
> >   
> > >
> > > Jonathan
> > >
> > > >
> > > >  drivers/iio/iio_core.h   | 15 -
> > > >  drivers/iio/industrialio-core.c  | 56 
> > > >  drivers/iio/industrialio-event.c | 28 +++-
> > > >  include/linux/iio/iio-opaque.h   |  2 ++
> > > >  4 files changed, 85 insertions(+), 16 deletions(-)
> > > >
> > > > diff --git a/drivers/iio/iio_core.h b/drivers/iio/iio_core.h
> > > > index fd9a5f1d5e51..fced02cadcc3 100644
> > > > --- a/drivers/iio/iio_core.h
> > > > +++ b/drivers/iio/iio_core.h
> > > > @@ -17,6 +17,20 @@ struct iio_dev;
> > > >
> > > >  extern struct device_type iio_device_type;
> > > >
> > > > +#define IIO_IOCTL_UNHANDLED  1
> > > > +struct iio_ioctl_handler {
> > > > + struct list_head entry;
> > > > + long (*ioctl)(struct iio_dev *indio_dev, struct file *filp,
> > > > +   unsigned int cmd, unsigned long arg);
> > > > +};
> > > > +
> > > > +long iio_device_ioctl(struct iio_dev *indio_dev, struct file *filp,
> > > > +   unsigned int cmd, unsigned long arg);
> > > > +
> > > > +void iio_device_ioctl_handler_register(struct iio_dev *indio_dev,
> > > > +struct iio_ioctl_handler *h);
> > > > +void iio_device_ioctl_handler_unregister(struct iio_ioctl_handler *h);
> > > > +
> > > >  int __iio_add_chan_devattr(const char *postfix,
> > > >  struct iio_chan_spec const *chan,
> > > >  ssize_t (*func)(struct device *dev,
> > > > @@ -74,7 +88,6 @@ static inline void iio_buffer_wakeup_poll(struct 
> > > > iio_dev *indio_dev) {}
> > > >  int iio_device_register_eventset(struct iio_dev *indio_dev);
> > > >  void iio_device_unregister_eventset(struct iio_dev *indio_dev);
> > > >  void iio_device_wakeup_eventset(struct iio_dev *indio_dev);
> > > > -int iio_event_getfd(struct iio_dev *indio_dev);
> > > >
> > > >  struct iio_event_interface;
> > > >  bool iio_event_enabled(const struct iio_event_interface *ev_int);
> > > > diff --git a/drivers/iio/industrialio-core.c 
> > > > b/drivers/iio/industrialio-core.c
> > > > index 

Re: [PATCH] iio: core: centralize ioctl() calls to the main chardev

2020-11-14 Thread Jonathan Cameron
On Mon, 2 Nov 2020 08:59:57 +0200
Alexandru Ardelean  wrote:

> On Fri, Sep 25, 2020 at 3:38 PM Jonathan Cameron  wrote:
> >
> > On Thu, 24 Sep 2020 11:41:55 +0300
> > Alexandru Ardelean  wrote:
> >  
> > > The aim of this is to improve a bit the organization of ioctl() calls in
> > > IIO core. Currently the chardev is split across IIO core 
> > > sub-modules/files.
> > > The main chardev has to be able to handle ioctl() calls, and if we need to
> > > add buffer ioctl() calls, this would complicate things.
> > >
> > > The 'industrialio-core.c' file will provide a 'iio_device_ioctl()' which
> > > will iterate over a list of ioctls registered with the IIO device. These
> > > can be event ioctl() or buffer ioctl() calls, or something else.
> > >
> > > Each ioctl() handler will have to return a IIO_IOCTL_UNHANDLED code (which
> > > is positive 1), if the ioctl() did not handle the call in any. This
> > > eliminates any potential ambiguities about negative error codes, which
> > > should fail the call altogether.
> > >
> > > If any ioctl() returns 0, it was considered that it was serviced
> > > successfully and the loop will exit.
> > >
> > > This change also moves the handling of the IIO_GET_EVENT_FD_IOCTL command
> > > inside 'industrialio-event.c', where this is better suited.
> > >
> > > This patch is a combination of 2 other patches from an older series:
> > > Patch 1: iio: core: add simple centralized mechanism for ioctl() handlers
> > >   Link: 
> > > https://lore.kernel.org/linux-iio/20200427131100.50845-6-alexandru.ardel...@analog.com/
> > > Patch 2: iio: core: use new common ioctl() mechanism
> > >   Link: 
> > > https://lore.kernel.org/linux-iio/20200427131100.50845-7-alexandru.ardel...@analog.com/
> > >
> > > Signed-off-by: Alexandru Ardelean 
> > > ---
> > >
> > > Note: since this is a change to the IIO core, we don't need to put this in
> > > right now; especially if there is a tight schedule, or we are too close to
> > > a merge window.  
> >
> > Looks good to me.  As you suggest, lets let this one sit on the list for a
> > while though!  
> 
> ping on this

Thanks.  Was still on my list, but I've been lazy and not been clearing that
out for a while - too many scary things there :)

Anyhow, applied to the togreg branch of iio.git and pushed out as testing for
all the normal reasons.

Thanks,

Jonathan

> 
> thanks
> Alex
> 
> >
> > Jonathan
> >  
> > >
> > >  drivers/iio/iio_core.h   | 15 -
> > >  drivers/iio/industrialio-core.c  | 56 
> > >  drivers/iio/industrialio-event.c | 28 +++-
> > >  include/linux/iio/iio-opaque.h   |  2 ++
> > >  4 files changed, 85 insertions(+), 16 deletions(-)
> > >
> > > diff --git a/drivers/iio/iio_core.h b/drivers/iio/iio_core.h
> > > index fd9a5f1d5e51..fced02cadcc3 100644
> > > --- a/drivers/iio/iio_core.h
> > > +++ b/drivers/iio/iio_core.h
> > > @@ -17,6 +17,20 @@ struct iio_dev;
> > >
> > >  extern struct device_type iio_device_type;
> > >
> > > +#define IIO_IOCTL_UNHANDLED  1
> > > +struct iio_ioctl_handler {
> > > + struct list_head entry;
> > > + long (*ioctl)(struct iio_dev *indio_dev, struct file *filp,
> > > +   unsigned int cmd, unsigned long arg);
> > > +};
> > > +
> > > +long iio_device_ioctl(struct iio_dev *indio_dev, struct file *filp,
> > > +   unsigned int cmd, unsigned long arg);
> > > +
> > > +void iio_device_ioctl_handler_register(struct iio_dev *indio_dev,
> > > +struct iio_ioctl_handler *h);
> > > +void iio_device_ioctl_handler_unregister(struct iio_ioctl_handler *h);
> > > +
> > >  int __iio_add_chan_devattr(const char *postfix,
> > >  struct iio_chan_spec const *chan,
> > >  ssize_t (*func)(struct device *dev,
> > > @@ -74,7 +88,6 @@ static inline void iio_buffer_wakeup_poll(struct 
> > > iio_dev *indio_dev) {}
> > >  int iio_device_register_eventset(struct iio_dev *indio_dev);
> > >  void iio_device_unregister_eventset(struct iio_dev *indio_dev);
> > >  void iio_device_wakeup_eventset(struct iio_dev *indio_dev);
> > > -int iio_event_getfd(struct iio_dev *indio_dev);
> > >
> > >  struct iio_event_interface;
> > >  bool iio_event_enabled(const struct iio_event_interface *ev_int);
> > > diff --git a/drivers/iio/industrialio-core.c 
> > > b/drivers/iio/industrialio-core.c
> > > index 261d3b17edc9..964a0a2d6f8b 100644
> > > --- a/drivers/iio/industrialio-core.c
> > > +++ b/drivers/iio/industrialio-core.c
> > > @@ -1567,6 +1567,7 @@ struct iio_dev *iio_device_alloc(struct device 
> > > *parent, int sizeof_priv)
> > >   }
> > >   dev_set_name(>dev, "iio:device%d", dev->id);
> > >   INIT_LIST_HEAD(_dev_opaque->buffer_list);
> > > + INIT_LIST_HEAD(_dev_opaque->ioctl_handlers);
> > >
> > >   return dev;
> > >  }
> > > @@ -1660,26 +1661,47 @@ static int iio_chrdev_release(struct inode 
> > > *inode, struct file *filp)
> > >   return 0;
> > >  }
> 

Re: [PATCH] iio: core: centralize ioctl() calls to the main chardev

2020-11-01 Thread Alexandru Ardelean
On Fri, Sep 25, 2020 at 3:38 PM Jonathan Cameron  wrote:
>
> On Thu, 24 Sep 2020 11:41:55 +0300
> Alexandru Ardelean  wrote:
>
> > The aim of this is to improve a bit the organization of ioctl() calls in
> > IIO core. Currently the chardev is split across IIO core sub-modules/files.
> > The main chardev has to be able to handle ioctl() calls, and if we need to
> > add buffer ioctl() calls, this would complicate things.
> >
> > The 'industrialio-core.c' file will provide a 'iio_device_ioctl()' which
> > will iterate over a list of ioctls registered with the IIO device. These
> > can be event ioctl() or buffer ioctl() calls, or something else.
> >
> > Each ioctl() handler will have to return a IIO_IOCTL_UNHANDLED code (which
> > is positive 1), if the ioctl() did not handle the call in any. This
> > eliminates any potential ambiguities about negative error codes, which
> > should fail the call altogether.
> >
> > If any ioctl() returns 0, it was considered that it was serviced
> > successfully and the loop will exit.
> >
> > This change also moves the handling of the IIO_GET_EVENT_FD_IOCTL command
> > inside 'industrialio-event.c', where this is better suited.
> >
> > This patch is a combination of 2 other patches from an older series:
> > Patch 1: iio: core: add simple centralized mechanism for ioctl() handlers
> >   Link: 
> > https://lore.kernel.org/linux-iio/20200427131100.50845-6-alexandru.ardel...@analog.com/
> > Patch 2: iio: core: use new common ioctl() mechanism
> >   Link: 
> > https://lore.kernel.org/linux-iio/20200427131100.50845-7-alexandru.ardel...@analog.com/
> >
> > Signed-off-by: Alexandru Ardelean 
> > ---
> >
> > Note: since this is a change to the IIO core, we don't need to put this in
> > right now; especially if there is a tight schedule, or we are too close to
> > a merge window.
>
> Looks good to me.  As you suggest, lets let this one sit on the list for a
> while though!

ping on this

thanks
Alex

>
> Jonathan
>
> >
> >  drivers/iio/iio_core.h   | 15 -
> >  drivers/iio/industrialio-core.c  | 56 
> >  drivers/iio/industrialio-event.c | 28 +++-
> >  include/linux/iio/iio-opaque.h   |  2 ++
> >  4 files changed, 85 insertions(+), 16 deletions(-)
> >
> > diff --git a/drivers/iio/iio_core.h b/drivers/iio/iio_core.h
> > index fd9a5f1d5e51..fced02cadcc3 100644
> > --- a/drivers/iio/iio_core.h
> > +++ b/drivers/iio/iio_core.h
> > @@ -17,6 +17,20 @@ struct iio_dev;
> >
> >  extern struct device_type iio_device_type;
> >
> > +#define IIO_IOCTL_UNHANDLED  1
> > +struct iio_ioctl_handler {
> > + struct list_head entry;
> > + long (*ioctl)(struct iio_dev *indio_dev, struct file *filp,
> > +   unsigned int cmd, unsigned long arg);
> > +};
> > +
> > +long iio_device_ioctl(struct iio_dev *indio_dev, struct file *filp,
> > +   unsigned int cmd, unsigned long arg);
> > +
> > +void iio_device_ioctl_handler_register(struct iio_dev *indio_dev,
> > +struct iio_ioctl_handler *h);
> > +void iio_device_ioctl_handler_unregister(struct iio_ioctl_handler *h);
> > +
> >  int __iio_add_chan_devattr(const char *postfix,
> >  struct iio_chan_spec const *chan,
> >  ssize_t (*func)(struct device *dev,
> > @@ -74,7 +88,6 @@ static inline void iio_buffer_wakeup_poll(struct iio_dev 
> > *indio_dev) {}
> >  int iio_device_register_eventset(struct iio_dev *indio_dev);
> >  void iio_device_unregister_eventset(struct iio_dev *indio_dev);
> >  void iio_device_wakeup_eventset(struct iio_dev *indio_dev);
> > -int iio_event_getfd(struct iio_dev *indio_dev);
> >
> >  struct iio_event_interface;
> >  bool iio_event_enabled(const struct iio_event_interface *ev_int);
> > diff --git a/drivers/iio/industrialio-core.c 
> > b/drivers/iio/industrialio-core.c
> > index 261d3b17edc9..964a0a2d6f8b 100644
> > --- a/drivers/iio/industrialio-core.c
> > +++ b/drivers/iio/industrialio-core.c
> > @@ -1567,6 +1567,7 @@ struct iio_dev *iio_device_alloc(struct device 
> > *parent, int sizeof_priv)
> >   }
> >   dev_set_name(>dev, "iio:device%d", dev->id);
> >   INIT_LIST_HEAD(_dev_opaque->buffer_list);
> > + INIT_LIST_HEAD(_dev_opaque->ioctl_handlers);
> >
> >   return dev;
> >  }
> > @@ -1660,26 +1661,47 @@ static int iio_chrdev_release(struct inode *inode, 
> > struct file *filp)
> >   return 0;
> >  }
> >
> > -/* Somewhat of a cross file organization violation - ioctls here are 
> > actually
> > - * event related */
> > +void iio_device_ioctl_handler_register(struct iio_dev *indio_dev,
> > +struct iio_ioctl_handler *h)
> > +{
> > + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> > +
> > + list_add_tail(>entry, _dev_opaque->ioctl_handlers);
> > +}
> > +
> > +void iio_device_ioctl_handler_unregister(struct iio_ioctl_handler *h)
> > +{
> > + list_del(>entry);
> > +}
> > +

Re: [PATCH] iio: core: centralize ioctl() calls to the main chardev

2020-09-25 Thread Jonathan Cameron
On Thu, 24 Sep 2020 11:41:55 +0300
Alexandru Ardelean  wrote:

> The aim of this is to improve a bit the organization of ioctl() calls in
> IIO core. Currently the chardev is split across IIO core sub-modules/files.
> The main chardev has to be able to handle ioctl() calls, and if we need to
> add buffer ioctl() calls, this would complicate things.
> 
> The 'industrialio-core.c' file will provide a 'iio_device_ioctl()' which
> will iterate over a list of ioctls registered with the IIO device. These
> can be event ioctl() or buffer ioctl() calls, or something else.
> 
> Each ioctl() handler will have to return a IIO_IOCTL_UNHANDLED code (which
> is positive 1), if the ioctl() did not handle the call in any. This
> eliminates any potential ambiguities about negative error codes, which
> should fail the call altogether.
> 
> If any ioctl() returns 0, it was considered that it was serviced
> successfully and the loop will exit.
> 
> This change also moves the handling of the IIO_GET_EVENT_FD_IOCTL command
> inside 'industrialio-event.c', where this is better suited.
> 
> This patch is a combination of 2 other patches from an older series:
> Patch 1: iio: core: add simple centralized mechanism for ioctl() handlers
>   Link: 
> https://lore.kernel.org/linux-iio/20200427131100.50845-6-alexandru.ardel...@analog.com/
> Patch 2: iio: core: use new common ioctl() mechanism
>   Link: 
> https://lore.kernel.org/linux-iio/20200427131100.50845-7-alexandru.ardel...@analog.com/
> 
> Signed-off-by: Alexandru Ardelean 
> ---
> 
> Note: since this is a change to the IIO core, we don't need to put this in
> right now; especially if there is a tight schedule, or we are too close to
> a merge window.

Looks good to me.  As you suggest, lets let this one sit on the list for a
while though!

Jonathan

> 
>  drivers/iio/iio_core.h   | 15 -
>  drivers/iio/industrialio-core.c  | 56 
>  drivers/iio/industrialio-event.c | 28 +++-
>  include/linux/iio/iio-opaque.h   |  2 ++
>  4 files changed, 85 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/iio/iio_core.h b/drivers/iio/iio_core.h
> index fd9a5f1d5e51..fced02cadcc3 100644
> --- a/drivers/iio/iio_core.h
> +++ b/drivers/iio/iio_core.h
> @@ -17,6 +17,20 @@ struct iio_dev;
>  
>  extern struct device_type iio_device_type;
>  
> +#define IIO_IOCTL_UNHANDLED  1
> +struct iio_ioctl_handler {
> + struct list_head entry;
> + long (*ioctl)(struct iio_dev *indio_dev, struct file *filp,
> +   unsigned int cmd, unsigned long arg);
> +};
> +
> +long iio_device_ioctl(struct iio_dev *indio_dev, struct file *filp,
> +   unsigned int cmd, unsigned long arg);
> +
> +void iio_device_ioctl_handler_register(struct iio_dev *indio_dev,
> +struct iio_ioctl_handler *h);
> +void iio_device_ioctl_handler_unregister(struct iio_ioctl_handler *h);
> +
>  int __iio_add_chan_devattr(const char *postfix,
>  struct iio_chan_spec const *chan,
>  ssize_t (*func)(struct device *dev,
> @@ -74,7 +88,6 @@ static inline void iio_buffer_wakeup_poll(struct iio_dev 
> *indio_dev) {}
>  int iio_device_register_eventset(struct iio_dev *indio_dev);
>  void iio_device_unregister_eventset(struct iio_dev *indio_dev);
>  void iio_device_wakeup_eventset(struct iio_dev *indio_dev);
> -int iio_event_getfd(struct iio_dev *indio_dev);
>  
>  struct iio_event_interface;
>  bool iio_event_enabled(const struct iio_event_interface *ev_int);
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 261d3b17edc9..964a0a2d6f8b 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -1567,6 +1567,7 @@ struct iio_dev *iio_device_alloc(struct device *parent, 
> int sizeof_priv)
>   }
>   dev_set_name(>dev, "iio:device%d", dev->id);
>   INIT_LIST_HEAD(_dev_opaque->buffer_list);
> + INIT_LIST_HEAD(_dev_opaque->ioctl_handlers);
>  
>   return dev;
>  }
> @@ -1660,26 +1661,47 @@ static int iio_chrdev_release(struct inode *inode, 
> struct file *filp)
>   return 0;
>  }
>  
> -/* Somewhat of a cross file organization violation - ioctls here are actually
> - * event related */
> +void iio_device_ioctl_handler_register(struct iio_dev *indio_dev,
> +struct iio_ioctl_handler *h)
> +{
> + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> +
> + list_add_tail(>entry, _dev_opaque->ioctl_handlers);
> +}
> +
> +void iio_device_ioctl_handler_unregister(struct iio_ioctl_handler *h)
> +{
> + list_del(>entry);
> +}
> +
>  static long iio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>  {
>   struct iio_dev *indio_dev = filp->private_data;
> - int __user *ip = (int __user *)arg;
> - int fd;
> + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> + struct