[Gta04-owner] [PATCH 3/3] tty/slaves: add a driver to power on/off UART attached devices.

Sebastian Reichel sre at kernel.org
Thu Mar 26 19:08:05 CET 2015


Hi,

On Wed, Mar 25, 2015 at 05:44:42PM +0100, Dr. H. Nikolaus Schaller wrote:
> Am 25.03.2015 um 16:21 schrieb Sebastian Reichel <sre at kernel.org>:
> > On Wed, Mar 25, 2015 at 08:59:14AM +0100, Dr. H. Nikolaus Schaller wrote:
> >> Am 25.03.2015 um 02:45 schrieb Sebastian Reichel <sre at kernel.org>:
> >>> On Tue, Mar 24, 2015 at 06:58:15PM +0100, Dr. H. Nikolaus Schaller wrote:
> >>>> So you propose that the parent->child relationship is “control”? I.e. some
> >>>> channel which allows to address some bus client (through <reg>) and
> >>>> control that devices.
> >>>> 
> >>>> Makes sense. This is how i2c and spi clients are specified.
> >>>> 
> >>>>> In the case of our GPS, it receives control over the serial connection from
> >>>>> the UART,
> >>>> 
> >>>> Ahem - does it?
> >>>> 
> >>>> AFAIK the chip simply starts to emit NMEA records if powered on.
> >>>> There is no command going over the serial interface to address it
> >>>> or control it.
> >>> 
> >>> Right, since GPS basically doesn't need any configuration/control.
> >>> That’s not true for other UART attached devices, though.
> >> 
> >> Do you have an example? Usually an UART data stream is transparently
> >> presented to a /dev/tty - and user-space daemon can configure/control the
> >> attached device. In most cases it can mix payload data and control command
> >> by some AT command and escape sequences.
> > 
> > Yes, but the configuration is minimal. Anyways as you said there
> > *is* some kind of control happening over the UART.
> 
> Control is happening on a higher network stack level than UART. It
> control is done through AT commands.

Yes, obviously UART is only the physical layer. The same is true for
busses and does not really matter.

> >>>>> also receives control via a GPIO to the on/off pin, and also needs
> >>>>> a regulator to power the antenna.
> >>>>> 
> >>>>> So should the parent be the uart, the on/off GPIO, or the regulator?
> >>>>> 
> >>>>> I would much rather there wasn't a parent, and that each of these were listed
> >>>>> as ad-hoc attribute assignments.  But device-tree says there must be a parent
> >>>>> (where possible), and the parent is the thing that is “primarily" in control.
> >>>> 
> >>>> Well, IMHO the “parent” could also be the root. Representing the
> >>>> whole board.
> >>>> 
> >>>> Nevertheless, I doubt your rule that “ability to control” defines
> >>>> the parent>child relation (see below).
> >>>> 
> >>>>> 
> >>>>> I think the GPS is “primarily" a uart-attached device.
> >>>> 
> >>>> But not in the same way as an I2C device.
> >>>> 
> >>>> Especially the serial interface is not a bus and not used for
> >>>> signalling and power control. It is payload data (only).
> >>> 
> >>> Actually many I2C devices are also powered on/off via a GPIO and
> >>> even use additional GPIOs for sending interrupts. Nevertheless they
> >>> are normally identified as an I2C device.
> >> 
> >> Because I2C is a bus that can address multiple clients and gpio isn’t
> >> a bus and a point-to-point connection.
> >> 
> >> But IMHO it is not because they (can) send payload data over i2c.
> > 
> > From my POV it's not because I2C is a bus, but because the primary
> > function is happening via I2C (e.g. configuring sensor, gettings its
> > data). The GPIOs are only needed to compensate some I2C shortcomings
> > (missing irq feature in I2C) or reduce the complexity of the client
> > (power GPIO). The actual system interaction with the I2C chip is
> > going via I2C, though.
> 
> Yes, but this is in my new understanding irrelevant for proper DT
> description.

And for my understanding it is. We are arguing in a circle...

> >>>> If you assume that parent>child relationship is about control (only). But if it
> >>>> is about data flow, there is a different concept in DT. For example the CSI/DSI
> >>>> (OMAP DSS) use the “port” concept.
> >>> 
> >>> Yes, this is about data not going to the cpu / system memory.
> >> 
> >> Really? The frame buffer data is in system memory and gets to the panel. Or a
> >> camera image ends up in system memory.
> > 
> > Really? So the panel accesses the system memory? Check again. The
> > panel is simply connected via DSI/SDI/... and does not access the
> > system memory at all. The display controller OTH does. So let's have
> > a look at the DT structure (simplified):
> > 
> > ocp -> dss -> { port = <&panel>; }
> > ... -> spi -> panel { port = <&dss>; }
> > 
> > So the port models a device-to-device connection, which works
> > independent of the remaining system. No system memory is involved.
> 
> Sorry, but I can’t exactly follow what you want to show.
> 
> Yes, the port mechanism describes a device to device connection.
> 
> But it does not describe system memory. Although it is the source of
> the video (i.e. the framebuffer).
> 
> This shows that the DT does not necessarily describe data flow.
> 
> So why do you want to describe data flow from tty to uart to some
> connected device?

It shows, that the tree models system memory flow and adds
references for stuff not being about the system memory flow.

So let's say I want to configure the panel - I can simply walk
through the parent structure to know how to access it. The same
is true for the display controller.

> >>>> This means that indeed parent>child is used for control, e.g. I2C
> >>>> or SPI to tell the panel controller to switch on.
> >>> 
> >>> well parent > child is not about power control, but about "primary"
> >>> control.
> >> 
> >> Can you clearly and precisely define what “primary” control is? I think
> >> two people will have three opinions about that.
> >> 
> >> For example I would see the w2sg0004 on/off gpio as the primary “control”
> >> which makes the light (NMES records) turned on.
> >> 
> >> Therefore we should make it the subnode of some gpio-controller, shouldn’t we?
> > 
> > I never thing of enable gpios to be the main interface, since it can
> > simply be connected to some voltage and be enabled constantly. It's
> > just some kind of helper for the device. It does not really exchange
> > data between the system and the device, though. (Note: This is
> > not true, if the GPIOs are used for bitbanging some high-level
> > protocol, in which case a virtual controller (like i2c-gpio) is
> > modelled in DT).
> > 
> > So let's have a look at the UART link again. It is transporting
> > non-trivial data from the UART to the system and it is handling
> > the data I actually want. It's providing access to the device's
> > “registers".
> 
> Well, this view can be followed, but is as strange and bent to fit
> like my view of the w2sg0004 as a “regulator”.
> 
> > 
> > For me its clear, that one would expect the GPS under the UART
> > port, since when speaking with other developers I would describe
> > the GPS as being a "UART attached GPS chip". From me the
> > differences between a UART port and a SPI port from a system
> > software’s POV can be reduced to missing multi-device support.
> 
> DT does not necessarily have to describe data flow as we have seen
> in the video pipeline example.

sure, it shows how to access the device. This link may not
necessarily be the same as the one, which takes care of the
data.

> > so show me some non-bus connections, which are actually used to
> > exchange non-trivial data (with on/off being trivial). We currently
> > do not really have them.
> 
> Are we talking about DT or data flow from user space through the
> kernel?

/me is not sure why you are regularly introducing userspace. It's
completly irrelevant when its assumed, that the kernel should
abstract devices. DT is about giving the kernel knowledge about
the *hardware*, so that it can implement this abstraction without
any user interaction.

Coming back at my sentence: I asked about a non-trivial, non-bus
connected HW, which has a DT binding.

> > I have missed virtual-gpio UART DTR discussion and assume, that the
> > regulator is about the regulator on the GPS chip?
> 
> Well, it was introduced in platform device kernels that it was possible
> to define a dtr-gpio for the uart. And there was a driver for the w2sg0004
> that presented itself as a gpio-controller with a single gpio. This “virtual”
> gpio was used to power on the chip as soon as DTR was asserted.
> 
> Parts of this had been in mainline but have been removed some months
> ago.

I can't find any w2sg0004 reference in the mainline kernel's commit
messages.

> > I don't think the regulator is not acceptable. I simply think its
> > not useful. Basically the structure would be
> > 
> > uart {
> >    /* stuff */
> >    gps {
> >        vdd-supply = <&gpsreg>;
> >        /* stuff */
> > 
> >        gpsreg: regulator {
> >            enable-gpio = <GPIO 42>;
> >            /* stuff */
> >        }
> >    }
> > }
> 
> Except that the gpsreg is a subnode of /

I obviously disagree with that ;)
But even then the regulator is useless.

> > 
> > and could simply be
> > 
> > uart {
> >    /* stuff */
> >    gps {
> >        enable-gpio = <GPIO 42>;
> >        /* stuff */
> >    }
> > }
> > 
> > Without loosing important information.
> 
> Only if you assume that the gpsreg must be a subnode of the uart.

DT means device tree and not device net. I sure can follow your
argument, but from my POV its trying to create a net from the tree.

> > The regulator would only be
> > interesting if it is also used by other devices. Other devices also
> > do not expose their internal clocks etc.
> > 
> >>>> The reason is there no well defined protocol to make multiple clients and
> >>>> you can’t specify a <reg>.
> >>>> 
> >>>> So you are either abusing the notion of a bus or the gps chip must be a separate
> >>>> DT node (child of something else).
> >>>> 
> >>>> I hope my gut feeling that we are trying to do something fundamentally wrong
> >>>> with making the gps chip a subode of serial is now argued a little better.
> >>>> 
> >>>> For making the serial device control some regulator through a reference to
> >>>> a regulator, I am very fine. It is what you do for the W2CBW bluetooth part.
> >>> 
> >>> NAK about referencing the regulator from the UART node. It should be
> >>> referenced from the Bluetooth / GPS node. The UART port works
> >>> without the regulator. It's the remote side, that does not work.
> >>> We also do not add the regulators of I2C clients to the I2C host.
> >> 
> >> I think Pavel made a very good comment:
> >> 
> >> The uart node should be able to power a rs232 converter/level shifter directly
> >> connected to it (through a regulator or gpio-regulator).
> > 
> > Yes and this may belong to the UART node.
> > 
> >> And there must be a separate mechanism to power the remote rs232 converter
> >> and the remote device.
> > 
> > Yes and I think this goes to the remote device's node.
> > 
> >> The standard signalling for this are the RTS/DTR lines of an UART/RS232.
> >> UART is not only RX+TX.
> > 
> > so?
> 
> You said NAK about referencing a regulator from the UART node and
> now?

No. I said NAK about referencing *the* regulator from the BT/GPS
node. My NAK was about referencing a regulator in the UART node
(local side), which is actually needed by the GPS/BT module (remote
side).

> >>> If you want to talk with an I2C device you enable the I2C device
> >>> *and* its parent (aka the I2C host controller). I guess the same
> >>> should be done for the UART.
> >>> 
> >>>>>>>> All the following is very special logic for the w2sg0004 chip which should be
> >>>>>>>> divided out into a separate driver.
> >>>>>>>> 
> >>>>>>>> Marek and me already had proposed such a chip specific driver (to be located
> >>>>>>>> in drivers/misc) some months ago. It would encapsulate everything w2sg0004
> >>>>>>>> specific and present itself as a regulator (because that is its main purpose:
> >>>>>>>> control the LDO regulator inside the w2sg0004 chip).
> >>>>>>> 
> >>>>>>> Presenting itself as a regulator would be wrong because it isn’t a regulator.
> >>>>>> 
> >>>>>> It has a regulator that can be controlled by a gpio…
> >>>>> 
> >>>>> Does it?  I guess may it does.
> >>>>> Maybe it also has an ARM core and some memory and assorted other bits and
> >>>>> pieces.  But we don’t really need to describe them to device tree.
> >>>> 
> >>>> Well, if I look into the data sheet, it has indeed an LDO from 3.3V to 1.8V.
> >>>> 
> >>>> Not to make you confused: the w2sg0084 would have a WAKEUP output which - if
> >>>> connected to a GPIO - would tell if the module is really active or not. Using this would
> >>>> make monitoring the RX line through different pinmux states obsolete.
> >>>> 
> >>>> But the only Linux board using the w2sg00x4 appears to be the GTA04 and it has
> >>>> not wired the WAKEUP line to a  GPIO.
> >>>> 
> >>>>> The w2sg0004 is primarily a GPS device, so that needs to be stated in the
> >>>>> devices tree description.  If there are subcomponents that can usefully be
> >>>>> described as well then there could be a place to describe those subcomponents.
> >>>>> I notice that there is a "1V8-out" pin, so presumable the chip can deliver a
> >>>>> 1V8 source based on its 3V3 input.  If a board made use of that, it could be
> >>>>> useful to describe the regulator inside the GPS so it could be declare that
> >>>>> some other device which needed 1V8 made use of that regulator….
> >>>> 
> >>>> Yes. Well, even if *we* do not use it in this way yet, we should not make it
> >>>> difficult for others to do by enforcing the wrong description.
> >>> 
> >>> well this has nothing to do with the parent-child discussion, since
> >>> you can obviously reference a regulator independently of its
> >>> position in the DT.
> >>> 
> >>>>>> Another example to think about: the twl4030 is also not a regulator.
> >>>>>> Nevertheless they present some regulator nodes.
> >>>>> 
> >>>>> The TWL4030 is a multifunction device which contains regulators and GPIOs and
> >>>>> audio codec and  USB PHY etc etc etc.
> >>>>> 
> >>>>> So in device-tree there is a device-node for the TWL4030, and it has
> >>>>> child-nodes for each sub-device.   They in turn can provide services to other
> >>>>> devices on the board.
> >>>> 
> >>>> Exactly as discussed above. And there, the parent>child relation for the twl4030
> >>>> and its subdevices is right.
> >>>> 
> >>>>> These sub-devices are much more independent of the whole than the regulator
> >>>>> inside the w2sg0004 is.
> >>>> 
> >>>> Hm. That is probably argueable as well. At least a vague ciriterion.
> >>>>> 
> >>>>>> 
> >>>>>> Or take the OMAP3 pbias_regulator. The OMAP3 isn’t a regulator as well
> >>>>>> but has an internal pbias_regulator that needs to be controlled.
> >>>>> 
> >>>>> I don't know much about a "pbias_regulator", but the OMAP3 is a multifunction
> >>>>> device which contains a CPU and multiple other controllers and  communicators
> >>>>> and stuff.  One of the components in the OMAP3 is this pbias_regulator, and
> >>>>> it has a device-node which is a child of the 'ocp' node - which is the main
> >>>>> interconnect in the OMAP3 I think.
> >>>>> 
> >>>>> So I'm not against describing the regulator in the w2sg0004, but for
> >>>>> consistency with everything else, it would need to be child-node of a
> >>>>> device-node which describes the w2sg0004 as a whole.  I'm not sure that doing
> >>>>> that would gain anything.
> >>>> 
> >>>> Well, it would gain consistency how chips with multiple components inside
> >>>> are described.
> >>> 
> >>> I don't think so. Many devices do not expose all of their
> >>> subdevices. e.g. they do not expose their internal clocks.
> >>> Apart from that there are a few devices in the kernel, which
> >>> do use enable-gpio(s).
> >> 
> >> After reading http://www.devicetree.org/Device_Tree_Usage#Devices I must
> >> revise my formulation a little.
> >> 
> >> It is not that parent>child is used for describing “busses or grouping subdevices".
> >> 
> >> It is only for “grouping addressable components”, which implies some bus.
> >> 
> >> This still explains the ocp component of the OMAP3 - which represents the
> >> whole internal “interconnect” bus (see comment in omap3.dtsi).
> >> 
> >> Therefore you are right. It is not correct to split up a device into arbitrary
> >> components and group them again by the parent>child pattern.
> >> 
> >> Although the structure of twl4030.dtsi appears to simply list and group
> >> subcomponents without telling explicitly how to address them.
> > 
> > Yes and this style is not only used for twl4030, but also for other
> > multi function devices. I do not have a problem with splitting up a
> > device into components as long as they are referenced by other
> > components. There is no point in exposing all internal information.
> > For the system its not relevant, that the GPS chip has a 30MHz
> > clock if its part of the chip and nobody else is using it.
> > 
> >>>> And would make it easier to see the whole w2sg0004 a child of /.
> >>> 
> >>> Even with the regulator subdevice I would still make the w2sg0004 a
> >>> child of the UART port.
> >> 
> >> This would mean that a tty / uart is able to address multiple clients. How
> >> could it do that?
> > 
> > In theory it's possible:
> > 
> > ? -> uart -> multiplexer -> { device1, device2 }
> > 
> > I hope nobody will build such a device, though :)
> > 
> > I don't think addressability is important for a parent > child
> > connection, though. It is important for a reg node, of course.
> 
> That is the key question I am trying to get founded answers, not
> opinions :)
> 
> > 
> >>> Main reason is, that I would need to go
> >>> through the UART to “communicate" with the w2sg0004.
> >> 
> >> You can always "communicate” through the UART. Even without DT. As
> >> long as the connected chip is powered up by any means (could be
> >> some fixed-regulator or hard wired).
> >> 
> >> Power control for open()/close() did even work with the DT based
> >> DTR->virtual-gpio approach.
> >> 
> >> We just do not described in the DT that there is a data connection
> >> from uart1 to the RX/TX pins. But you just open /dev/ttyO1.
> >> 
> >> Thus, describing a relation between the uart node and the GPS chip
> >> in the DT is not even a requirement.
> > 
> > It is when the kernel should be able to handle the GPS. The DT is
> > supposed to be independent from Linux and other operating systems
> > may want to hide the tty if a GPS is attached to it and instead
> > provide something like /dev/gps, which could automatically be picked
> > up by userspace software.
> 
> Well, it is difficult to cover all future use cases.
> 
> But then you can still add a uart = <&uart1> reference to the DT node
> of the driver. Because I understand that then the driver is the master
> (and needs access to a hidden UART) and not the GPS chip a slave of
> an exposed UART.

Ok. It seems we are still talk past each other. All use cases can be
implemented using both ways - putting the node to / or putting it
below the UART node. It simply does not matter, since kernel code
can interpret it as needed. You just asked at some time why we need
to know about the remote side.

From my POV putting it below the UART node is more logical and from
your POV putting it below / is more logical.

> >> Probably the main problem we have is that we want to describe this
> >> data connection but the device tree is about describing how to
> >> address components and data flow is left to internal APIs. Or
> >> “ports” like in the video pipelines.
> > 
> > As I wrote the tree structure shows how to "reach" a component for
> > accessing its configuration/data from the system.
> 
> Yes, you wrote and I already pointed out that I disagree. It
> contradicts what
> 
> http://www.devicetree.org/Device_Tree_Usage#Devices
> 
> appears to tell me. So who is right?

From my POV the page is simply focused on standard bindings, which
have already been established. If I understand you right, your POV
does not allow child nodes (which are not directly under /) without
reg property / address. Just have a look at the DT binding
documentation directory in the kernel - we already have them.

> >> Let me raise the question:
> >> 
> >> Why do we need to describe in the DT (independently of Linux power
> >> control structures and drivers!) that the GPS data interface is
> >> connected to a specific UART?
> >> Who needs this information and for which purpose?
> > 
> > Because an operating system can provide drivers, which completly
> > hide away the UART connection. Example:
> > 
> > Let's assume we have an UART attached Bluetooth chip connected to
> > the second UART.
> > 
> > In Linux, userspace currently must know, that the BT module is
> > connected to this port and correctly setup the port for BT usage.
> > Once this has been done the port is completly handled in the kernel
> > and userspace can ignore the UART.
> 
> Ok, this is a reasonable example. But I still don’ see that it
> requires that the bt chip must be a subnode of the uart.

It doesn't. I just answered your question, which was independent
of the actual node position.

> > So why must the user configure the port? Because the kernel does not
> > know, that a BT chip is connected to the port.
> 
> Then, I would suggest to write it like you have done:
> 
> “the BT chip is connected to the port uart1”
> 
> This can be easily translated into DT language:
> 
> / {
> 	bt {
> 		compatible = “vendor,chip”;
> 		uart = <&uart1>;	/* this chip is connected to uart1 */
> 		enable-gpio = <&gpio3 17 0>;
> 	};
> };
> 
> This also resembles the “port” mechanism (just simplified because it is not
> a backwards forward linkage).
> 
> Or exactly follows the pattern that a driver that wants to use
> some gpio simply links to the gpio controller. Or a driver wants
> to control a gpio.
> 
> What I don’t understand is what is here so special to not use this
> DT pattern.
> 
> But It could also open a different solution for the tty open() ->
> w2sg power on problem.
> 
> / {
> 	gps {
> 		compatible = “wi2wi,w2sg0004”;
> 		uart = <&uart1>;	/* this chip is connected to uart1 */
> 		enable-gpio = <&gpio3 17 0>;
> 	};
> };
> 
> Here, the w2sg0004 probe function could register with uart1 to get notified
> about open/close events and then do what it has to do.
> 
> In that case the w2sg0004 driver would not even need to present itself
> as a virtual gpio (for DTR) or a regulator because it has a kernel internal
> API to apply to tell the uart what it wants to do.

Again the same can be done if its a child-node of the UART. It is
simply a question of reading the "uart" property vs loading the
driver from the UART and access the parent device.

> > If the kernel gets
> > this information from DT it can do all the UART handling itself and
> > provide a bluetooth device without any user interaction.
> 
> I think we should get a better understanding of the DT design patterns.
> 
> IMHO (or IMPoV):
> 
> * parent>child is not for describing “control” or “primary interface” but addressability

We obviously disagree here :)

> * if a driver needs access to another component, a reference property is used

Here we also disagree. The kernel also makes use of parent > child
connections (e.g. the driver for an i2c client node will request
data via its parent) and sometimes even sibling relationships (in
MFD devices).

So let me summarize:

 * Option A: Do not encode remote side information
   Rationale: UART port can be opened in userspace without that info
   Counterargument: This information is needed if the OS should be
   able to hide away the tty and provide support for the connected
   remote device (e.g. provide a bluetooth device instead of a tty)

 * Option B: Put UART remote side node to / and add a reference to the UART port
   Rationale: DT wiki page indicates, that child nodes must be addressable

 * Option C: Put UART remote side node below the UART node
   Rationale: Remote device is accessed through the UART

Since this is about a subsystem binding DT maintainers ACK is
definitely needed, so maybe we should just wait for their decision.

-- Sebastian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.goldelico.com/pipermail/gta04-owner/attachments/20150326/01415134/attachment-0001.asc>


More information about the Gta04-owner mailing list