mbox series

[0/3] Introduce a counter inkernel API

Message ID 20200406155806.1295169-1-kamel.bouhara@bootlin.com (mailing list archive)
Headers show
Series Introduce a counter inkernel API | expand

Message

Kamel BOUHARA April 6, 2020, 3:58 p.m. UTC
Hello everyone,

This series introduce a basic inkernel API for the counter subsystem and
add a new rotary encoder driver that use a counter interface instead of
the GPIO existing one.

See commit log in 0001-counter-add-an-inkernel-API.patch for further
details.

Kamel Bouhara (3):
  counter: add an inkernel API
  Input: rotary-encoder-counter: add DT bindings
  Input: add a rotary encoders based on counter devices

 .../input/rotary-encoder-counter.yaml         |  67 ++++++
 drivers/counter/counter.c                     | 213 ++++++++++++++++++
 drivers/input/misc/Kconfig                    |   9 +
 drivers/input/misc/Makefile                   |   1 +
 drivers/input/misc/rotary_encoder_counter.c   | 152 +++++++++++++
 include/linux/counter.h                       |  27 +++
 6 files changed, 469 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/rotary-encoder-counter.yaml
 create mode 100644 drivers/input/misc/rotary_encoder_counter.c

--
2.25.0

Comments

William Breathitt Gray April 11, 2020, 5:22 p.m. UTC | #1
On Mon, Apr 06, 2020 at 05:58:03PM +0200, Kamel Bouhara wrote:
> Hello everyone,
> 
> This series introduce a basic inkernel API for the counter subsystem and
> add a new rotary encoder driver that use a counter interface instead of
> the GPIO existing one.
> 
> See commit log in 0001-counter-add-an-inkernel-API.patch for further
> details.
> 
> Kamel Bouhara (3):
>   counter: add an inkernel API
>   Input: rotary-encoder-counter: add DT bindings
>   Input: add a rotary encoders based on counter devices
> 
>  .../input/rotary-encoder-counter.yaml         |  67 ++++++
>  drivers/counter/counter.c                     | 213 ++++++++++++++++++
>  drivers/input/misc/Kconfig                    |   9 +
>  drivers/input/misc/Makefile                   |   1 +
>  drivers/input/misc/rotary_encoder_counter.c   | 152 +++++++++++++
>  include/linux/counter.h                       |  27 +++
>  6 files changed, 469 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/input/rotary-encoder-counter.yaml
>  create mode 100644 drivers/input/misc/rotary_encoder_counter.c
> 
> --
> 2.25.0

Hello Kamel,

I'm not inherently opposed to adding an in-kernel API for the Counter
subsystem, but I'm not sure yet if it's necessary for this particular
situation.

Is the purpose of this driver to allow users to poll on the rotary
encoder position value? If so, perhaps instead of an in-kernel API, the
polling functionality should be added as part of the Counter subsystem;
I can see this being a useful feature for many counter devices, and
it'll keep the code contained to a single subsystem.

By the way, I'm going to be submitting a major update to the Counter
subsystem code in the next couple weeks that isolates the sysfs code
from the rest of the subsystem -- it'll likely affect the interface and
code here -- so I'll probably wait to decide for certain until that
patch lands; I anticipate it making things easier for you here after
it's merged.

For now, I want to get a better high-level understanding about how users
would interact with this driver to use the device (input_setup_polling
is a new call for me). That should help me understand whether an
in-kernel API is the best choice here.

William Breathitt Gray
Alexandre Belloni April 11, 2020, 11:31 p.m. UTC | #2
Hi,

On 11/04/2020 13:22:59-0400, William Breathitt Gray wrote:
> I'm not inherently opposed to adding an in-kernel API for the Counter
> subsystem, but I'm not sure yet if it's necessary for this particular
> situation.
> 
> Is the purpose of this driver to allow users to poll on the rotary
> encoder position value? If so, perhaps instead of an in-kernel API, the
> polling functionality should be added as part of the Counter subsystem;
> I can see this being a useful feature for many counter devices, and
> it'll keep the code contained to a single subsystem.
> 
> By the way, I'm going to be submitting a major update to the Counter
> subsystem code in the next couple weeks that isolates the sysfs code
> from the rest of the subsystem -- it'll likely affect the interface and
> code here -- so I'll probably wait to decide for certain until that
> patch lands; I anticipate it making things easier for you here after
> it's merged.
> 
> For now, I want to get a better high-level understanding about how users
> would interact with this driver to use the device (input_setup_polling
> is a new call for me). That should help me understand whether an
> in-kernel API is the best choice here.
> 

Well, the goal is not really polling the counters but mainly exposing
the correct userspace interface for the rotary encoders that are
connected to quadrature decoders.

The input driver is using polling because this reduces the complexity of
the patches but the ultimate goal is to also have interrupts working.

I'm pretty sure the in-kernel interface can also have other usages like
for example iio triggers. I could envision having to read an ADC after x
turns of a motor to check for the torque.

I also think that having the sysfs code separate would help as it could
be considered as one of the in-kernel interface user.

BTW, do you have plans to add a character device interface?
William Breathitt Gray April 12, 2020, 1:48 a.m. UTC | #3
On Sun, Apr 12, 2020 at 01:31:45AM +0200, Alexandre Belloni wrote:
> Hi,
> 
> On 11/04/2020 13:22:59-0400, William Breathitt Gray wrote:
> > I'm not inherently opposed to adding an in-kernel API for the Counter
> > subsystem, but I'm not sure yet if it's necessary for this particular
> > situation.
> > 
> > Is the purpose of this driver to allow users to poll on the rotary
> > encoder position value? If so, perhaps instead of an in-kernel API, the
> > polling functionality should be added as part of the Counter subsystem;
> > I can see this being a useful feature for many counter devices, and
> > it'll keep the code contained to a single subsystem.
> > 
> > By the way, I'm going to be submitting a major update to the Counter
> > subsystem code in the next couple weeks that isolates the sysfs code
> > from the rest of the subsystem -- it'll likely affect the interface and
> > code here -- so I'll probably wait to decide for certain until that
> > patch lands; I anticipate it making things easier for you here after
> > it's merged.
> > 
> > For now, I want to get a better high-level understanding about how users
> > would interact with this driver to use the device (input_setup_polling
> > is a new call for me). That should help me understand whether an
> > in-kernel API is the best choice here.
> > 
> 
> Well, the goal is not really polling the counters but mainly exposing
> the correct userspace interface for the rotary encoders that are
> connected to quadrature decoders.
> 
> The input driver is using polling because this reduces the complexity of
> the patches but the ultimate goal is to also have interrupts working.

Okay, I think understand now. Interrupt support is another feature I
want to get working for counters too, so that development will probably
overlap with this driver as well. Hopefully with interrupts working
you'll be able to signal to the input driver whenever data is ready,
rather than just polling periodically to check.

> I'm pretty sure the in-kernel interface can also have other usages like
> for example iio triggers. I could envision having to read an ADC after x
> turns of a motor to check for the torque.

That's an interesting use case. I can see how an in-kernel interface
would be helpful here.

> I also think that having the sysfs code separate would help as it could
> be considered as one of the in-kernel interface user.
> 
> BTW, do you have plans to add a character device interface?

Yes, actually a character device interface (and the timestamp feature)
is the primary motivation for this refactoring: sysfs code is separated
so that it can share a common core of functionality with the character
device code.

Implementing an in-kernel API should be trivial after these changes
since it will be just a matter of codifying the shared code that forms
the new core of the Counter subsystem. So perhaps this patchset should
wait until the Counter subsystem is updated, since it may be easier to
interact with counter devices once that is complete.

If you're curious about this patch, it's available on my personal iio
tree in the counter_chardev branch:
https://gitlab.com/vilhelmgray/iio/-/commits/counter_chardev/

I still need to add the character device code and respective userspace
API, but I expect to have it completed in the next couple weeks,
assuming no major issues or delays arise.

William Breathitt Gray