input: Add new sun4i-lradc-keys driver
Subsystems (5)
cover input: Add new sun4i-lradc-keys driver
Hi Dimitri,
Here is another input driver for Allwinner sunxi SoCs. As with the touchscreen driver the dts files are posted here for completeness and will be merged through Maxime's tree.
Please review and if everything is ok, add this to your tree for Linus.
Thanks & Regards,
Hans
PATCH 1/4 input: Add new sun4i-lradc-keys drivers
Allwinnner sunxi SoCs have a low resolution adc (called lradc) which is specifically designed to have various (tablet) keys (ie home, back, search, etc). attached to it using a resistor network. This adds a driver for this.
There are 2 channels, currently this driver only supports chan0 since there are no boards known to use chan1. The devicetree properties are already prefixed with chan0 as preparation for chan1 support in the future.
This has been tested on an olimex a10s-olinuxino-micro, a13-olinuxino, and a20-olinuxino-micro.
--- .../devicetree/bindings/input/sun4i-lradc-keys.txt | 20 ++ drivers/input/keyboard/Kconfig | 10 + drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/sun4i-lradc-keys.c | 243 +++++++++++++++++++++ 4 files changed, 274 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/sun4i-lradc-keys.txt create mode 100644 drivers/input/keyboard/sun4i-lradc-keys.c
Documentation/devicetree/bindings/input/sun4i-lradc-keys.txt new file +20 -0
@@ -0,0 +1,20 @@ +Allwinner sun4i low res adc attached tablet keys +------------------------------------------------ + +Required properties: + - compatible: "allwinner,sun4i-lradc-keys" + - reg: mmio address range of the chip + - interrupts: interrupt to which the chip is connected + - allwinner,chan0-step: step in mV between keys must be 150 or 200 + - allwinner,chan0-keycodes: array of include/uapi/linux/input.h KEY_ codes + +Example: + + lradc: lradc at 01c22800 { + compatible = "allwinner,sun4i-lradc-keys"; + reg = <0x01c22800 0x100>; + interrupts = <31>; + allwinner,chan0-step = <200>; + /* KEY_VOLUMEUP VOLUMEDOWN MENU ENTER HOME */ + allwinner,chan0-keycodes = <115 114 139 28 102>; + };
drivers/input/keyboard/Kconfig +10 -0
@@ -544,6 +544,16 @@ config KEYBOARD_STMPE To compile this driver as a module, choose M here: the module will be called stmpe-keypad. +config KEYBOARD_SUN4I_LRADC + tristate "Allwinner sun4i low res adc attached tablet keys support" + depends on ARCH_SUNXI + help + This selects support for the Allwinner low res adc attached tablet + keys found on Allwinner sunxi SoCs. + + To compile this driver as a module, choose M here: the + module will be called sun4i-lradc-keys. + config KEYBOARD_DAVINCI tristate "TI DaVinci Key Scan" depends on ARCH_DAVINCI_DM365
drivers/input/keyboard/Makefile +1 -0
@@ -50,6 +50,7 @@ obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o obj-$(CONFIG_KEYBOARD_SPEAR) += spear-keyboard.o obj-$(CONFIG_KEYBOARD_STMPE) += stmpe-keypad.o obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o +obj-$(CONFIG_KEYBOARD_SUN4I_LRADC) += sun4i-lradc-keys.o obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o obj-$(CONFIG_KEYBOARD_TC3589X) += tc3589x-keypad.o obj-$(CONFIG_KEYBOARD_TEGRA) += tegra-kbc.o
drivers/input/keyboard/sun4i-lradc-keys.c new file +243 -0
243 lines not on this page · raw message
Signature · 1 line
1.8.4.2
Dmitry Torokhov
maintainerPATCH 1/4 input: Add new sun4i-lradc-keys drivers
Hi Hans,
Quoted 6 lines · Hans de Goede
+Required properties:
+ - compatible: "allwinner,sun4i-lradc-keys"
+ - reg: mmio address range of the chip
+ - interrupts: interrupt to which the chip is connected
+ - allwinner,chan0-step: step in mV between keys must be 150 or 200
+ - allwinner,chan0-keycodes: array ofinclude/uapi/linux/input.hKEY_codes
I think this should be "linux,chan0-keycodes".
Thanks.
Signature · 1 line
Dmitry
PATCH 1/4 input: Add new sun4i-lradc-keys drivers
Hi,
Quoted 11 lines · Dmitry Torokhov
Hi Hans,
Quoted 6 lines · Hans de Goede
+Required properties:
+ - compatible: "allwinner,sun4i-lradc-keys"
+ - reg: mmio address range of the chip
+ - interrupts: interrupt to which the chip is connected
+ - allwinner,chan0-step: step in mV between keys must be 150 or 200
+ - allwinner,chan0-keycodes: array ofinclude/uapi/linux/input.hKEY_codesI think this should be "linux,chan0-keycodes".
Right, because the codes are Linux specific, will fix in v2.
Regards,
Hans
PATCH 1/4 input: Add new sun4i-lradc-keys drivers
Hi Hans, Dmitry,
Am Donnerstag, 2. Januar 2014, 10:37:47 schrieb Hans de Goede:
Quoted 13 lines
Hi,
Quoted 10 lines · Dmitry Torokhov
Hi Hans,
Quoted 7 lines · Hans de Goede
+Required properties:
+ - compatible: "allwinner,sun4i-lradc-keys"
+ - reg: mmio address range of the chip
+ - interrupts: interrupt to which the chip is connected
+ - allwinner,chan0-step: step in mV between keys must be 150 or 200
+ - allwinner,chan0-keycodes: array ofinclude/uapi/linux/input.hKEY_codes>
Quoted 3 lines
Quoted 1 line
I think this should be "linux,chan0-keycodes".
Right, because the codes are Linux specific, will fix in v2.
but the property with its "chan0-" thingy would be allwinner-specific if I'm not mistaken.
Also, instead of inventing yet another vendor-specific property, why not re-use a button binding similar to gpio-keys like:
lradc: lradc at 01c22800 {
compatible = "allwinner,sun4i-lradc-keys";
reg = <0x01c22800 0x100>;
interrupts = <31>;
allwinner,chan0-step = <200>;
#address-cells = <1>;
#size-cells = <0>;
button at 0 {
reg = <0>; /* your channel index from above */
linux,code = <115>; /* already used as dt-property */
};
button at 1 {
reg = <1>;
linux,code = <114>;
};...
};
But I may be on the wrong track here, so I've included the devicetree-people for help, which I guess should've been included from the beginning.
Heiko
PATCH 1/4 input: Add new sun4i-lradc-keys drivers
Hi,
Quoted 16 lines · Heiko St?bner
Hi Hans, Dmitry,
Am Donnerstag, 2. Januar 2014, 10:37:47 schrieb Hans de Goede:
Quoted 13 lines
Hi,
Quoted 10 lines · Dmitry Torokhov
Hi Hans,
Quoted 7 lines · Hans de Goede
+Required properties:
+ - compatible: "allwinner,sun4i-lradc-keys"
+ - reg: mmio address range of the chip
+ - interrupts: interrupt to which the chip is connected
+ - allwinner,chan0-step: step in mV between keys must be 150 or 200
+ - allwinner,chan0-keycodes: array ofinclude/uapi/linux/input.hKEY_codes>
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
I think this should be "linux,chan0-keycodes".
Right, because the codes are Linux specific, will fix in v2.
but the property with its "chan0-" thingy would be allwinner-specific if I'm not mistaken.
Correct, but denoting that this is linux only is more important, so as to avoid namespace collisions.
Quoted 14 lines
Also, instead of inventing yet another vendor-specific property, why not re-use a button binding similar to gpio-keys like:
lradc: lradc at 01c22800 { compatible = "allwinner,sun4i-lradc-keys"; reg = <0x01c22800 0x100>; interrupts = <31>; allwinner,chan0-step = <200>; #address-cells = <1>; #size-cells = <0>; button at 0 {
Quoted 8 lines
reg = <0>; /* your channel index from above */
linux,code = <115>; /* already used as dt-property */
};
button at 1 {
reg = <1>;
linux,code = <114>;
};Ugh no. Having a vendor specific property which is KISS certainly beats this, both wrt ease of writing dts files as well as wrt the dts parsing code in the driver.
Regards,
Hans
PATCH 1/4 input: Add new sun4i-lradc-keys drivers
Quoted 17 lines · Hans de Goede
Quoted 17 lines
Also, instead of inventing yet another vendor-specific property, why not re-use a button binding similar to gpio-keys like:
lradc: lradc at 01c22800 { compatible = "allwinner,sun4i-lradc-keys"; reg = <0x01c22800 0x100>; interrupts = <31>; allwinner,chan0-step = <200>; #address-cells = <1>; #size-cells = <0>; button at 0 { reg = <0>; /* your channel index from above */ linux,code = <115>; /* already used as dt-property */ };
Quoted 8 lines
Quoted 4 lines
button at 1 { reg = <1>; linux,code = <114>; };Ugh no. Having a vendor specific property which is KISS certainly beats this, both wrt ease of writing dts files as well as wrt the dts parsing code in the driver.
I'd agree with Heiko here. This is pretty much the same construct that's already in use in other input drivers, like gpio-keys.
This is also something that can really easily be made generic, since this is something that is rather common.
Speaking of which. I believe this should actually come in two different drivers:
- The ADC driver itself, using IIO
- A generic button handler driver on top of IIO.
The fact that on most board this adc is used for buttons doesn't make any difference, it's actually a hardware designer choice, we should support that choice, but we should also be able to use it just as an ADC.
Carlo Caione already started to work on an IIO driver for the LRADC:
https://github.com/carlocaione/linux/tree/sunxi-lradc
maybe you can take over his work.
I also wonder wether it would be possible in that case to use reg as the "button" voltage, to get rid of both the chan0-step property, and those big fat arrays in the driver.
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140102/abfbd9fe/attachment.sig>
Dmitry Torokhov
maintainerPATCH 1/4 input: Add new sun4i-lradc-keys drivers
Quoted 27 lines · Maxime Ripard
Quoted 17 lines · Hans de Goede
Quoted 17 lines
Also, instead of inventing yet another vendor-specific property, why not re-use a button binding similar to gpio-keys like:
lradc: lradc at 01c22800 { compatible = "allwinner,sun4i-lradc-keys"; reg = <0x01c22800 0x100>; interrupts = <31>; allwinner,chan0-step = <200>; #address-cells = <1>; #size-cells = <0>; button at 0 { reg = <0>; /* your channel index from above */ linux,code = <115>; /* already used as dt-property */ };Quoted 8 lines
Quoted 4 lines
button at 1 { reg = <1>; linux,code = <114>; };Ugh no. Having a vendor specific property which is KISS certainly beats this, both wrt ease of writing dts files as well as wrt the dts parsing code in the driver.
Quoted 5 lines
I'd agree with Heiko here. This is pretty much the same construct that's already in use in other input drivers, like gpio-keys.
This is also something that can really easily be made generic, since this is something that is rather common.
Except that button definition from gpio-keys does not use 'reg' property but rather gpio. I'd rather we did not cram non-applicable attributes into that definition just to make it "reusable" like that.
I'd be OK with having similar (but not claiming to be the same) mappings though.
Thanks.
Signature · 1 line
Dmitry
PATCH 1/4 input: Add new sun4i-lradc-keys drivers
Quoted 34 lines · Dmitry Torokhov
Quoted 27 lines · Maxime Ripard
Quoted 17 lines · Hans de Goede
Quoted 17 lines
Also, instead of inventing yet another vendor-specific property, why not re-use a button binding similar to gpio-keys like:
lradc: lradc at 01c22800 { compatible = "allwinner,sun4i-lradc-keys"; reg = <0x01c22800 0x100>; interrupts = <31>; allwinner,chan0-step = <200>; #address-cells = <1>; #size-cells = <0>; button at 0 { reg = <0>; /* your channel index from above */ linux,code = <115>; /* already used as dt-property */ };Quoted 8 lines
Quoted 4 lines
button at 1 { reg = <1>; linux,code = <114>; };Ugh no. Having a vendor specific property which is KISS certainly beats this, both wrt ease of writing dts files as well as wrt the dts parsing code in the driver.
Quoted 5 lines
I'd agree with Heiko here. This is pretty much the same construct that's already in use in other input drivers, like gpio-keys.
This is also something that can really easily be made generic, since this is something that is rather common.
Quoted 6 lines
Except that button definition from gpio-keys does not use 'reg' property but rather gpio. I'd rather we did not cram non-applicable attributes into that definition just to make it "reusable" like that.
I'd be OK with having similar (but not claiming to be the same) mappings though.
Yes, this is what I was meaning. Sorry if it was not clear enough.
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140103/b1b5c3a0/attachment.sig>
PATCH 1/4 input: Add new sun4i-lradc-keys drivers
In reply to Maxime RipardHi,
Quoted 23 lines · Maxime Ripard
Quoted 22 lines · Hans de Goede
Quoted 21 lines
Also, instead of inventing yet another vendor-specific property, why not re-use a button binding similar to gpio-keys like:
lradc: lradc at 01c22800 { compatible = "allwinner,sun4i-lradc-keys"; reg = <0x01c22800 0x100>; interrupts = <31>; allwinner,chan0-step = <200>; #address-cells = <1>; #size-cells = <0>; button at 0 { reg = <0>; /* your channel index from above */ linux,code = <115>; /* already used as dt-property */ }; button at 1 { reg = <1>; linux,code = <114>; };
Quoted 6 lines
Quoted 3 lines
Ugh no. Having a vendor specific property which is KISS certainly beats this, both wrt ease of writing dts files as well as wrt the dts parsing code in the driver.
I'd agree with Heiko here. This is pretty much the same construct that's already in use in other input drivers, like gpio-keys.
In the gpio case there is a 1 on 1 relation between a single hw entity (the gpio-pin) and a single keycode. Here there is 1 hw entity which maps to an array of key-codes, certainly using an array rather then a much more complicated construct is the correct data-structure to represent this.
Quoted 9 lines
This is also something that can really easily be made generic, since this is something that is rather common.
Speaking of which. I believe this should actually come in two different drivers:
- The ADC driver itself, using IIO
- A generic button handler driver on top of IIO.
Quoted 4 lines
The fact that on most board this adc is used for buttons doesn't make any difference, it's actually a hardware designer choice, we should support that choice, but we should also be able to use it just as an ADC.
No, this is not a generic adc, as mentioned in the commit msg, this adc is specifically designed to be used this way.
The adc won't start sampling data, and won't generate any interrupts until a button is pressed. That is until the input voltage drops below 2/3 of Vref, this is checked through a built-in analog comparator, which hooks into the control logic.
It has button down and button up interrupts, and can detect long presses (unused) and generate a second type of down interrupt for those.
This really is an input device, which happens to use an adc.
Quoted 3 lines
Carlo Caione already started to work on an IIO driver for the LRADC:
https://github.com/carlocaione/linux/tree/sunxi-lradc
maybe you can take over his work.
That won't work because the adc won't sample if the input gets above 2/3 of Vref. There may be some other mode which does not do that, but that is not clearly documented.
Even if an IIO driver turns out to be doable, I strongly believe that having a separate input driver for this is best, since this device was designed to be used as such. Building input on top of IIO would mean polling the adc, while with my driver it actually generates button down / up interrupts without any polling being involved.
And no boards I know of are using this as a generic analog input, where as many boards are using it as designed.
Regards,
Hans
PATCH 1/4 input: Add new sun4i-lradc-keys drivers
Quoted 30 lines · Hans de Goede
Hi,
Quoted 27 lines · Maxime Ripard
Quoted 25 lines · Hans de Goede
Quoted 13 lines
Also, instead of inventing yet another vendor-specific property, why not re-use a button binding similar to gpio-keys like:
lradc: lradc at 01c22800 { compatible = "allwinner,sun4i-lradc-keys"; reg = <0x01c22800 0x100>; interrupts = <31>; allwinner,chan0-step = <200>; #address-cells = <1>; #size-cells = <0>; button at 0 {Quoted 8 lines
reg = <0>; /* your channel index from above */ linux,code = <115>; /* already used as dt-property */ }; button at 1 { reg = <1>; linux,code = <114>; };Ugh no. Having a vendor specific property which is KISS certainly beats this, both wrt ease of writing dts files as well as wrt the dts parsing code in the driver.
Quoted 8 lines
Quoted 2 lines
I'd agree with Heiko here. This is pretty much the same construct that's already in use in other input drivers, like gpio-keys.
In the gpio case there is a 1 on 1 relation between a single hw entity (the gpio-pin) and a single keycode. Here there is 1 hw entity which maps to an array of key-codes, certainly using an array rather then a much more complicated construct is the correct data-structure to represent this.
You can build an array in your driver out of this very easily, it's 10 lines in your probe. And you gain from this something that is more generic, can be shared by other similar drivers and is consistent with what is already in use.
Quoted 21 lines
Quoted 8 lines
This is also something that can really easily be made generic, since this is something that is rather common.
Speaking of which. I believe this should actually come in two different drivers:
- The ADC driver itself, using IIO
- A generic button handler driver on top of IIO.Quoted 4 lines
The fact that on most board this adc is used for buttons doesn't make any difference, it's actually a hardware designer choice, we should support that choice, but we should also be able to use it just as an ADC.
No, this is not a generic adc, as mentioned in the commit msg, this adc is specifically designed to be used this way.
The adc won't start sampling data, and won't generate any interrupts until a button is pressed. That is until the input voltage drops below 2/3 of Vref, this is checked through a built-in analog comparator, which hooks into the control logic.
Quoted 4 lines
It has button down and button up interrupts, and can detect long presses (unused) and generate a second type of down interrupt for those.
This really is an input device, which happens to use an adc.
Hmm, yes, ok.
Quoted 8 lines
Quoted 3 lines
Carlo Caione already started to work on an IIO driver for the LRADC:
https://github.com/carlocaione/linux/tree/sunxi-lradc
maybe you can take over his work.That won't work because the adc won't sample if the input gets above 2/3 of Vref. There may be some other mode which does not do that, but that is not clearly documented.
Quoted 5 lines
Even if an IIO driver turns out to be doable, I strongly believe that having a separate input driver for this is best, since this device was designed to be used as such. Building input on top of IIO would mean polling the adc, while with my driver it actually generates button down / up interrupts without any polling being involved.
Not really. iio_channel_read calls the read_raw function (in that case) of your driver. If the read_raw function in your driver wants to poll the device, fine, but most of the time, it will just block waiting for an interrupt to come and return the data to the caller, which is obviously the saner behaviour, and you don't actually end up polling the device. Which is pretty much the architecture you're using already, just with an intermediate layer in between.
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140103/51ae2083/attachment-0001.sig>
Dmitry Torokhov
maintainerPATCH 1/4 input: Add new sun4i-lradc-keys drivers
Quoted 40 lines · Maxime Ripard
Quoted 30 lines · Hans de Goede
Hi,
Quoted 27 lines · Maxime Ripard
Quoted 25 lines · Hans de Goede
Quoted 13 lines
Also, instead of inventing yet another vendor-specific property, why not re-use a button binding similar to gpio-keys like:
lradc: lradc at 01c22800 { compatible = "allwinner,sun4i-lradc-keys"; reg = <0x01c22800 0x100>; interrupts = <31>; allwinner,chan0-step = <200>; #address-cells = <1>; #size-cells = <0>; button at 0 {Quoted 8 lines
reg = <0>; /* your channel index from above */ linux,code = <115>; /* already used as dt-property */ }; button at 1 { reg = <1>; linux,code = <114>; };Ugh no. Having a vendor specific property which is KISS certainly beats this, both wrt ease of writing dts files as well as wrt the dts parsing code in the driver.
Quoted 8 lines
Quoted 2 lines
I'd agree with Heiko here. This is pretty much the same construct that's already in use in other input drivers, like gpio-keys.
In the gpio case there is a 1 on 1 relation between a single hw entity (the gpio-pin) and a single keycode. Here there is 1 hw entity which maps to an array of key-codes, certainly using an array rather then a much more complicated construct is the correct data-structure to represent this.
Quoted 4 lines
You can build an array in your driver out of this very easily, it's 10 lines in your probe. And you gain from this something that is more generic, can be shared by other similar drivers and is consistent with what is already in use.
How will it be shared? Surely not code-wise, but basically in spirit only. It seems to me that the originally proposed binding is simple and concise and works well for the driver.
Quoted 43 lines
Quoted 22 lines
Quoted 9 lines
This is also something that can really easily be made generic, since this is something that is rather common.
Speaking of which. I believe this should actually come in two different drivers:
- The ADC driver itself, using IIO
- A generic button handler driver on top of IIO.Quoted 4 lines
The fact that on most board this adc is used for buttons doesn't make any difference, it's actually a hardware designer choice, we should support that choice, but we should also be able to use it just as an ADC.
No, this is not a generic adc, as mentioned in the commit msg, this adc is specifically designed to be used this way.
The adc won't start sampling data, and won't generate any interrupts until a button is pressed. That is until the input voltage drops below 2/3 of Vref, this is checked through a built-in analog comparator, which hooks into the control logic.
Quoted 4 lines
It has button down and button up interrupts, and can detect long presses (unused) and generate a second type of down interrupt for those.
This really is an input device, which happens to use an adc.
Hmm, yes, ok.
Quoted 8 lines
Quoted 3 lines
Carlo Caione already started to work on an IIO driver for the LRADC:
https://github.com/carlocaione/linux/tree/sunxi-lradc
maybe you can take over his work.That won't work because the adc won't sample if the input gets above 2/3 of Vref. There may be some other mode which does not do that, but that is not clearly documented.
Quoted 5 lines
Even if an IIO driver turns out to be doable, I strongly believe that having a separate input driver for this is best, since this device was designed to be used as such. Building input on top of IIO would mean polling the adc, while with my driver it actually generates button down / up interrupts without any polling being involved.
Quoted 7 lines
Not really.
iio_channel_readcalls theread_rawfunction (in that case) of your driver. If theread_rawfunction in your driver wants to poll the device, fine, but most of the time, it will just block waiting for an interrupt to come and return the data to the caller, which is obviously the saner behaviour, and you don't actually end up polling the device. Which is pretty much the architecture you're using already, just with an intermediate layer in between.
What is the benefit of the IIO layer if device can't really be used as IIO? I am all for moving as many generic devices as we can to IIO but we should recognize that sometimes the device is not an IIO device.
Thanks.
Signature · 1 line
Dmitry
PATCH 1/4 input: Add new sun4i-lradc-keys drivers
Am Freitag, 3. Januar 2014, 10:23:50 schrieb Dmitry Torokhov:
Quoted 46 lines · Maxime Ripard
Quoted 45 lines · Hans de Goede
Quoted 43 lines
Hi,
Quoted 26 lines · Maxime Ripard
Quoted 25 lines · Hans de Goede
Quoted 25 lines
Also, instead of inventing yet another vendor-specific property, why not re-use> > >>>
a button binding similar to gpio-keys like:lradc: lradc at 01c22800 { compatible = "allwinner,sun4i-lradc-keys"; reg = <0x01c22800 0x100>; interrupts = <31>; allwinner,chan0-step = <200>; #address-cells = <1>; #size-cells = <0>; button at 0 { reg = <0>; /* your channel index from above */ linux,code = <115>; /* already used as dt-property */ }; button at 1 { reg = <1>; linux,code = <114>;Quoted 8 lines
Quoted 5 lines
Quoted 1 line
};Ugh no. Having a vendor specific property which is KISS certainly beats this, both wrt ease of writing dts files as well as wrt the dts parsing code in the driver.
I'd agree with Heiko here. This is pretty much the same construct that's already in use in other input drivers, like gpio-keys.
In the gpio case there is a 1 on 1 relation between a single hw entity (the gpio-pin) and a single keycode. Here there is 1 hw entity which maps to an array of key-codes, certainly using an array rather then a much more complicated construct is the correct data-structure to represent this.
Quoted 8 lines
Quoted 4 lines
You can build an array in your driver out of this very easily, it's 10 lines in your probe. And you gain from this something that is more generic, can be shared by other similar drivers and is consistent with what is already in use.
How will it be shared? Surely not code-wise, but basically in spirit only. It seems to me that the originally proposed binding is simple and concise and works well for the driver.
I don't think "binding [...] works well for the driver" is the correct direction. From my understanding the binding should describe the hardware in an os-agnostic way (so "linux,foo" properties should stay the exception) and not the data structures used in the driver. The driver itself then implements the binding to convert the binding-data into a structure it wants to use.
The sharing would, as you suggested, be in spirit and in the use of already established dt-properties without introducing more non-standard ones.
Heiko
PATCH 1/4 input: Add new sun4i-lradc-keys drivers
In reply to Dmitry TorokhovQuoted 41 lines · Dmitry Torokhov
Quoted 40 lines · Maxime Ripard
Quoted 38 lines · Hans de Goede
Hi,
Quoted 23 lines · Maxime Ripard
Quoted 22 lines · Hans de Goede
Quoted 21 lines
Also, instead of inventing yet another vendor-specific property, why not re-use a button binding similar to gpio-keys like:
lradc: lradc at 01c22800 { compatible = "allwinner,sun4i-lradc-keys"; reg = <0x01c22800 0x100>; interrupts = <31>; allwinner,chan0-step = <200>; #address-cells = <1>; #size-cells = <0>; button at 0 { reg = <0>; /* your channel index from above */ linux,code = <115>; /* already used as dt-property */ }; button at 1 { reg = <1>; linux,code = <114>; };Quoted 6 lines
Quoted 3 lines
Ugh no. Having a vendor specific property which is KISS certainly beats this, both wrt ease of writing dts files as well as wrt the dts parsing code in the driver.
I'd agree with Heiko here. This is pretty much the same construct that's already in use in other input drivers, like gpio-keys.
In the gpio case there is a 1 on 1 relation between a single hw entity (the gpio-pin) and a single keycode. Here there is 1 hw entity which maps to an array of key-codes, certainly using an array rather then a much more complicated construct is the correct data-structure to represent this.
Quoted 8 lines
Quoted 4 lines
You can build an array in your driver out of this very easily, it's 10 lines in your probe. And you gain from this something that is more generic, can be shared by other similar drivers and is consistent with what is already in use.
How will it be shared? Surely not code-wise, but basically in spirit only. It seems to me that the originally proposed binding is simple and concise and works well for the driver.
See Heiko's answer, but I do believe the code can be shared as well if needs be.
Quoted 50 lines
Quoted 42 lines
Quoted 21 lines
Quoted 8 lines
This is also something that can really easily be made generic, since this is something that is rather common.
Speaking of which. I believe this should actually come in two different drivers:
- The ADC driver itself, using IIO
- A generic button handler driver on top of IIO.Quoted 4 lines
The fact that on most board this adc is used for buttons doesn't make any difference, it's actually a hardware designer choice, we should support that choice, but we should also be able to use it just as an ADC.
No, this is not a generic adc, as mentioned in the commit msg, this adc is specifically designed to be used this way.
The adc won't start sampling data, and won't generate any interrupts until a button is pressed. That is until the input voltage drops below 2/3 of Vref, this is checked through a built-in analog comparator, which hooks into the control logic.
Quoted 4 lines
It has button down and button up interrupts, and can detect long presses (unused) and generate a second type of down interrupt for those.
This really is an input device, which happens to use an adc.
Hmm, yes, ok.
Quoted 8 lines
Quoted 3 lines
Carlo Caione already started to work on an IIO driver for the LRADC:
https://github.com/carlocaione/linux/tree/sunxi-lradc
maybe you can take over his work.That won't work because the adc won't sample if the input gets above 2/3 of Vref. There may be some other mode which does not do that, but that is not clearly documented.
Quoted 5 lines
Even if an IIO driver turns out to be doable, I strongly believe that having a separate input driver for this is best, since this device was designed to be used as such. Building input on top of IIO would mean polling the adc, while with my driver it actually generates button down / up interrupts without any polling being involved.
Quoted 7 lines
Not really.
iio_channel_readcalls theread_rawfunction (in that case) of your driver. If theread_rawfunction in your driver wants to poll the device, fine, but most of the time, it will just block waiting for an interrupt to come and return the data to the caller, which is obviously the saner behaviour, and you don't actually end up polling the device. Which is pretty much the architecture you're using already, just with an intermediate layer in between.
Quoted 3 lines
What is the benefit of the IIO layer if device can't really be used as IIO? I am all for moving as many generic devices as we can to IIO but we should recognize that sometimes the device is not an IIO device.
Yes, I've agreed to that. I was just clarifying Hans' statement.
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140106/7fcbda8b/attachment.sig>
PATCH 2/4 ARM: dts: sun4i: Add lradc node
In reply to Hans de Goede--- arch/arm/boot/dts/sun4i-a10.dtsi | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm/boot/dts/sun4i-a10.dtsi +7 -0
@@ -447,6 +447,13 @@ interrupts = <24>; }; + lradc: lradc at 01c22800 { + compatible = "allwinner,sun4i-lradc-keys"; + reg = <0x01c22800 0x100>; + interrupts = <31>; + status = "disabled"; + }; + sid: eeprom at 01c23800 { compatible = "allwinner,sun4i-sid"; reg = <0x01c23800 0x10>;
Signature · 1 line
1.8.4.2
PATCH 3/4 ARM: dts: sun5i: Add lradc node
In reply to Hans de Goede--- arch/arm/boot/dts/sun5i-a10s-olinuxino-micro.dts | 7 +++++++ arch/arm/boot/dts/sun5i-a10s.dtsi | 7 +++++++ arch/arm/boot/dts/sun5i-a13-olinuxino.dts | 7 +++++++ arch/arm/boot/dts/sun5i-a13.dtsi | 7 +++++++ 4 files changed, 28 insertions(+)
arch/arm/boot/dts/sun5i-a10s-olinuxino-micro.dts +7 -0
@@ -75,6 +75,13 @@ }; }; + lradc: lradc at 01c22800 { + allwinner,chan0-step = <200>; + /* KEY_VOLUMEUP VOLUMEDOWN MENU ENTER HOME */ + allwinner,chan0-keycodes = <115 114 139 28 102>; + status = "okay"; + }; + uart0: serial at 01c28000 { pinctrl-names = "default"; pinctrl-0 = <&uart0_pins_a>;
arch/arm/boot/dts/sun5i-a10s.dtsi +7 -0
@@ -404,6 +404,13 @@ reg = <0x01c20c90 0x10>; }; + lradc: lradc at 01c22800 { + compatible = "allwinner,sun4i-lradc-keys"; + reg = <0x01c22800 0x100>; + interrupts = <31>; + status = "disabled"; + }; + sid: eeprom at 01c23800 { compatible = "allwinner,sun4i-sid"; reg = <0x01c23800 0x10>;
arch/arm/boot/dts/sun5i-a13-olinuxino.dts +7 -0
@@ -55,6 +55,13 @@ }; }; + lradc: lradc at 01c22800 { + allwinner,chan0-step = <200>; + /* KEY_VOLUMEUP VOLUMEDOWN MENU ENTER HOME */ + allwinner,chan0-keycodes = <115 114 139 28 102>; + status = "okay"; + }; + uart1: serial at 01c28400 { pinctrl-names = "default"; pinctrl-0 = <&uart1_pins_b>;
arch/arm/boot/dts/sun5i-a13.dtsi +7 -0
@@ -362,6 +362,13 @@ reg = <0x01c20c90 0x10>; }; + lradc: lradc at 01c22800 { + compatible = "allwinner,sun4i-lradc-keys"; + reg = <0x01c22800 0x100>; + interrupts = <31>; + status = "disabled"; + }; + sid: eeprom at 01c23800 { compatible = "allwinner,sun4i-sid"; reg = <0x01c23800 0x10>;
Signature · 1 line
1.8.4.2
PATCH 3/4 ARM: dts: sun5i: Add lradc node
Quoted 13 lines · Hans de Goede
Signed-off-by Hans de Goede <[email protected]>--- arch/arm/boot/dts/sun5i-a10s-olinuxino-micro.dts | 7 +++++++ arch/arm/boot/dts/sun5i-a10s.dtsi | 7 +++++++ arch/arm/boot/dts/sun5i-a13-olinuxino.dts | 7 +++++++ arch/arm/boot/dts/sun5i-a13.dtsi | 7 +++++++ 4 files changed, 28 insertions(+)arch/arm/boot/dts/sun5i-a10s-olinuxino-micro.dts +0
-0
arch/arm/boot/dts/sun5i-a10s-olinuxino-micro.dts line 81
Quoted 7 lines
arch/arm/boot/dts/sun5i-a10s-olinuxino-micro.dts +4
-0@@ -75,6 +75,13 @@ }; }; + lradc: lradc at 01c22800 { + allwinner,chan0-step = <200>; + /* KEY_VOLUMEUP VOLUMEDOWN MENU ENTER HOME */ + allwinner,chan0-keycodes = <115 114 139 28 102>;
Hi Hans
You might want to consider using arch/arm/boot/dts/include/dt-bindings/input/input.h
and then you could have the node:
arch/arm/boot/dts/sun5i-a10s-olinuxino-micro.dts
Quoted 3 lines
arch/arm/boot/dts/sun5i-a10s-olinuxino-micro.dts +3
-0+ lradc: lradc at 01c22800 { + allwinner,chan0-step = <200>; + allwinner,chan0-keycodes = <KEY_VOLUMEUP VOLUMEDOWN MENU ENTER HOME>;
which is much more readable.
Andrew
[linux-sunxi] Re: [PATCH 3/4] ARM: dts: sun5i: Add lradc node
Hi,
Quoted 26 lines · Andrew Lunn
Quoted 13 lines · Hans de Goede
Signed-off-by Hans de Goede <[email protected]>--- arch/arm/boot/dts/sun5i-a10s-olinuxino-micro.dts | 7 +++++++ arch/arm/boot/dts/sun5i-a10s.dtsi | 7 +++++++ arch/arm/boot/dts/sun5i-a13-olinuxino.dts | 7 +++++++ arch/arm/boot/dts/sun5i-a13.dtsi | 7 +++++++ 4 files changed, 28 insertions(+)arch/arm/boot/dts/sun5i-a10s-olinuxino-micro.dts +0
-0arch/arm/boot/dts/sun5i-a10s-olinuxino-micro.dts line 81
Quoted 7 lines
arch/arm/boot/dts/sun5i-a10s-olinuxino-micro.dts +4
-0@@ -75,6 +75,13 @@ }; }; + lradc: lradc at 01c22800 { + allwinner,chan0-step = <200>; + /* KEY_VOLUMEUP VOLUMEDOWN MENU ENTER HOME */ + allwinner,chan0-keycodes = <115 114 139 28 102>;Hi Hans
You might want to consider using
arch/arm/boot/dts/include/dt-bindings/input/input.h
Quoted 7 lines
and then you could have the node:
arch/arm/boot/dts/sun5i-a10s-olinuxino-micro.dts
Quoted 3 lines
arch/arm/boot/dts/sun5i-a10s-olinuxino-micro.dts +3
-0+ lradc: lradc at 01c22800 { + allwinner,chan0-step = <200>; + allwinner,chan0-keycodes = <KEY_VOLUMEUP VOLUMEDOWN MENU ENTER HOME>;which is much more readable.
Ah, I did not know about that include. Good tip, will fix this in v2.
Regards,
Hans
PATCH 4/4 ARM: dts: sun7i: Add lradc node
In reply to Hans de Goede--- arch/arm/boot/dts/sun7i-a20-olinuxino-micro.dts | 7 +++++++ arch/arm/boot/dts/sun7i-a20.dtsi | 7 +++++++ 2 files changed, 14 insertions(+)
arch/arm/boot/dts/sun7i-a20-olinuxino-micro.dts +7 -0
@@ -86,6 +86,13 @@ }; }; + lradc: lradc at 01c22800 { + allwinner,chan0-step = <200>; + /* VOLUMEUP VOLUMEDOWN MENU SEARCH HOME ESC ENTER */ + allwinner,chan0-keycodes = <115 114 139 217 102 1 28>; + status = "okay"; + }; + uart0: serial at 01c28000 { pinctrl-names = "default"; pinctrl-0 = <&uart0_pins_a>;
arch/arm/boot/dts/sun7i-a20.dtsi +7 -0
@@ -531,6 +531,13 @@ interrupts = <0 24 1>; }; + lradc: lradc at 01c22800 { + compatible = "allwinner,sun4i-lradc-keys"; + reg = <0x01c22800 0x100>; + interrupts = <0 31 4>; + status = "disabled"; + }; + sid: eeprom at 01c23800 { compatible = "allwinner,sun7i-a20-sid"; reg = <0x01c23800 0x200>;
Signature · 1 line
1.8.4.2