Thread (19 messages) 19 messages, 7 authors, 2017-01-09

Re: [PATCH] iio: misc: add a generic regulator driver

From: Jonathan Cameron <hidden>
Date: 2016-12-24 10:43:23
Also in: linux-iio, lkml


On 23 December 2016 12:56:11 GMT+00:00, Geert Uytterhoeven [off-list ref] wrote:
Hi Lars,

On Fri, Dec 23, 2016 at 12:35 PM, Lars-Peter Clausen [off-list ref]
wrote:
quoted
On 12/23/2016 11:00 AM, Geert Uytterhoeven wrote:
quoted
On Mon, Dec 12, 2016 at 6:15 PM, Lars-Peter Clausen
[off-list ref] wrote:
quoted
quoted
quoted
On 12/06/2016 12:12 PM, Bartosz Golaszewski wrote:
quoted
We're already using libiio to read the measured data from the
power
quoted
quoted
quoted
quoted
monitor, that's why we'd like to use the iio framework for
power-cycling the devices as well. My question is: would bridging
the
quoted
quoted
quoted
quoted
regulator framework be the right solution? Should we look for
something else? Bridge the GPIO framework instead?
I wouldn't necessaries create bridge, but instead just use the GPIO
framework directly.

We now have the GPIO chardev interface which meant to be used to
support
quoted
quoted
quoted
application specific logic that control the GPIOs, but where you
don't want
quoted
quoted
quoted
to write a kernel driver.

My idea was to add GPIOs and GPIO chips as high level object inside
libiio
quoted
quoted
quoted
that can be accessed through the same context as the IIO devices.
Similar to
quoted
quoted
quoted
the current IIO API you have a API for gpios that allows to
enumerate the
quoted
quoted
quoted
GPIO devices and their pins as well as modify the pin state.
That would mean libiio has access to all GPIOs, allowing a remote
person
quoted
quoted
to not only control through iiod the GPIOs for industrial control,
but also the
quoted
quoted
GPIOs not intended for export, right?
Well, it is a policy question. Who gets access to what. Right now it
is all
quoted
or nothing, a privileged application gets access to all
devices/GPIOs, a
quoted
unprivileged application gets access to nothing. Same for GPIOs as
well as
quoted
IIO devices.

iiod at the moment does not have any access control at all, which in
itself
quoted
is a problem. We need to add support for that at some point. I don't
see an
quoted
issue with implementing a finer grained access scheme when we do so.
E.g.
quoted
unprivileged applications only get access to certain pins.
OK, so that's WIP.
quoted
quoted
Having a separate GPIO switch driver avoids that, as DT (or some
other means)
quoted
quoted
can be used to specify and label the GPIOs for IIO use.
Sure, functionally this would be equivalent, but we have to ask
whether this
quoted
is the right way to use the DT. Is access policy specification part
of the
quoted
hardware description? In my opinion the answer is no. At the hardware
description level there is no operating system, there is no userspace
or
quoted
kernelspace, there is are no access levels. Putting the distinction
between
quoted
a switch/regulator that can be controlled from userspace or can only
be
quoted
controlled from kernel space into the DT would be a layering
violation. It
quoted
is analogous to why we don't have spidev DT bindings. This is an
issue that
quoted
needs to be solved at a higher level. In my opinion this level is a
cooperation between kernel- and userspace. Kernelspace offering an
interface
quoted
to export a device for userspace access and userspace making use of
that
quoted
interface to request access to a device. In a similar way to how vfio
is
quoted
structured.
I'm not advocating using DT for policy, only for hardware description.

We have means (bindings) to describe GPIOs connected to LEDs and
switches
(incl. their labels), while you can control LEDs through plain GPIO
sysfs
export or chardev, too. It's just more error prone to use the latter.

We do not have bindings to describe GPIOs connected to e.g. relays.
We should.
Switching external devices (the internals of those devices not
described
itself in DT, like in an industrial context), sounds more like
something to
be handled by IIO, doesn't it?
Certainly, if there is known hardware to describe, we should endeavour to describe it.
Userspace interfaces are needed wherever we hit the boundary of what we can describe,
 whether because we are measuring things not in our control (e.g. what key is pressed on a
 keyboard) or because the next bit of hardware is interchangeable (e.g. your relay example, or
 this power switch).

The challenge is to structure the device model for the interchangeable edge case to be the
 same, more or less, as it would be if we knew what was hanging off the switch.
Hence, we either cut out early (gpio) or we attempt to put an appropriate consumer in place
 for the gpio (or possibly the power switch if we describe that). No problem at all in doing that
 last chunk with IIO or GPIO userspace as appropriate...

The challenge is that we are representing the fact the hardware is unknown in device tree.
Perhaps we need a way to make that explicit? Is there one already? Things like extcon do similar
 things I guess.
Same is true for regulators, when they are at the edge of the device...

On the binary channel types in IIO we have discussed this a fair bit in the past. There
Is a non trivial amount of work needed to do triggered input (demuxing to multiple consumers
In particular). 
Sysfs stuff would be simple but then it would really be gpio interface wrapped up a bit.
What IIO would bring to the mix ultimately is synchronized triggering of input and output.
(Speaking of which, Lars any progress on output buffers? Perhaps if we post that someone else might pick it up and run with it?)

One could argue the relay case is more of a mux than anything else so perhaps the ongoing
 generic mux subsystem discussion would be a good place to talk about that?

Interesting discussion, sorry it took me until my Christmas train journey to join in).

Linus, if you get a chance, you have probably thought more about gpio IIO interactions than I have!

Jonathan
Gr{oetje,eeting}s,

                       Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 --
geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org

In personal conversations with technical people, I call myself a
hacker. But
when I'm talking to journalists I just say "programmer" or something
like that.
                               -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help