2022-09-22 11:03:11

by Quentin Schulz

[permalink] [raw]
Subject: [PATCH 1/3] Input: add `SW_BOOT_ALT`

From: Quentin Schulz <[email protected]>

This event code represents the firmware source to use at boot.
Value 0 means using "standard" firmware source, value 1 means using
"alternative" firmware source.

For example, some hardware has the ability to force the BOOTROM to load
the bootloader from a secondary firmware source (say SD card) instead of
trying with the standard first and then the secondary. This event allows
the userspace to know which firmware source was requested *in hardware*.

Signed-off-by: Quentin Schulz <[email protected]>
---
include/linux/mod_devicetable.h | 2 +-
include/uapi/linux/input-event-codes.h | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index 549590e9c644..009e71376a61 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -326,7 +326,7 @@ struct pcmcia_device_id {
#define INPUT_DEVICE_ID_LED_MAX 0x0f
#define INPUT_DEVICE_ID_SND_MAX 0x07
#define INPUT_DEVICE_ID_FF_MAX 0x7f
-#define INPUT_DEVICE_ID_SW_MAX 0x10
+#define INPUT_DEVICE_ID_SW_MAX 0x11
#define INPUT_DEVICE_ID_PROP_MAX 0x1f

#define INPUT_DEVICE_ID_MATCH_BUS 1
diff --git a/include/uapi/linux/input-event-codes.h b/include/uapi/linux/input-event-codes.h
index dff8e7f17074..8cd2b58c81d7 100644
--- a/include/uapi/linux/input-event-codes.h
+++ b/include/uapi/linux/input-event-codes.h
@@ -917,7 +917,8 @@
#define SW_MUTE_DEVICE 0x0e /* set = device disabled */
#define SW_PEN_INSERTED 0x0f /* set = pen inserted */
#define SW_MACHINE_COVER 0x10 /* set = cover closed */
-#define SW_MAX 0x10
+#define SW_BOOT_ALT 0x11 /* set = alternative boot firmware source */
+#define SW_MAX 0x11
#define SW_CNT (SW_MAX+1)

/*
--
2.37.3


2022-09-22 18:15:51

by Jeff LaBundy

[permalink] [raw]
Subject: Re: [PATCH 1/3] Input: add `SW_BOOT_ALT`

Hi Quentin,

On Thu, Sep 22, 2022 at 12:12:09PM +0200, Quentin Schulz wrote:
> From: Quentin Schulz <[email protected]>
>
> This event code represents the firmware source to use at boot.
> Value 0 means using "standard" firmware source, value 1 means using
> "alternative" firmware source.
>
> For example, some hardware has the ability to force the BOOTROM to load
> the bootloader from a secondary firmware source (say SD card) instead of
> trying with the standard first and then the secondary. This event allows
> the userspace to know which firmware source was requested *in hardware*.
>
> Signed-off-by: Quentin Schulz <[email protected]>

This does not seem like the right approach, especially since the switch
can easily be flipped after the state is already latched.

If the bootloader needs to pass information to the kernel (boot source or
otherwise), a safer and more flexible approach is to share some variables
in eMMC, or pass information using the kernel cmdline.

> ---
> include/linux/mod_devicetable.h | 2 +-
> include/uapi/linux/input-event-codes.h | 3 ++-
> 2 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
> index 549590e9c644..009e71376a61 100644
> --- a/include/linux/mod_devicetable.h
> +++ b/include/linux/mod_devicetable.h
> @@ -326,7 +326,7 @@ struct pcmcia_device_id {
> #define INPUT_DEVICE_ID_LED_MAX 0x0f
> #define INPUT_DEVICE_ID_SND_MAX 0x07
> #define INPUT_DEVICE_ID_FF_MAX 0x7f
> -#define INPUT_DEVICE_ID_SW_MAX 0x10
> +#define INPUT_DEVICE_ID_SW_MAX 0x11
> #define INPUT_DEVICE_ID_PROP_MAX 0x1f
>
> #define INPUT_DEVICE_ID_MATCH_BUS 1
> diff --git a/include/uapi/linux/input-event-codes.h b/include/uapi/linux/input-event-codes.h
> index dff8e7f17074..8cd2b58c81d7 100644
> --- a/include/uapi/linux/input-event-codes.h
> +++ b/include/uapi/linux/input-event-codes.h
> @@ -917,7 +917,8 @@
> #define SW_MUTE_DEVICE 0x0e /* set = device disabled */
> #define SW_PEN_INSERTED 0x0f /* set = pen inserted */
> #define SW_MACHINE_COVER 0x10 /* set = cover closed */
> -#define SW_MAX 0x10
> +#define SW_BOOT_ALT 0x11 /* set = alternative boot firmware source */
> +#define SW_MAX 0x11
> #define SW_CNT (SW_MAX+1)
>
> /*
> --
> 2.37.3
>

Kind regards,
Jeff LaBundy

2022-09-23 08:42:36

by Quentin Schulz

[permalink] [raw]
Subject: Re: [PATCH 1/3] Input: add `SW_BOOT_ALT`

Hi Jeff,

On 9/22/22 19:20, Jeff LaBundy wrote:
> Hi Quentin,
>
> On Thu, Sep 22, 2022 at 12:12:09PM +0200, Quentin Schulz wrote:
>> From: Quentin Schulz <[email protected]>
>>
>> This event code represents the firmware source to use at boot.
>> Value 0 means using "standard" firmware source, value 1 means using
>> "alternative" firmware source.
>>
>> For example, some hardware has the ability to force the BOOTROM to load
>> the bootloader from a secondary firmware source (say SD card) instead of
>> trying with the standard first and then the secondary. This event allows
>> the userspace to know which firmware source was requested *in hardware*.
>>
>> Signed-off-by: Quentin Schulz <[email protected]>
>
> This does not seem like the right approach, especially since the switch
> can easily be flipped after the state is already latched.
>
> If the bootloader needs to pass information to the kernel (boot source or
> otherwise), a safer and more flexible approach is to share some variables
> in eMMC, or pass information using the kernel cmdline.
>

I made a terrible job at explaining what this switch is for, sorry.

Obviously, the state of the switch cannot represent which firmware boot
source was used as only the bootloader will be able to tell (since it
usually tries storage media in a specific order and the primary boot
source could get corrupted at one point in time). Anyway, like you
rightfully stated, this is useless "info" and the important one would be
passed by the bootloader to the kernel (possibly via Device Tree fixup
in case of Aarch64). U-Boot does this to set the memory node so this
could be done again with a different property or something like that.
Anyways, not something I'm really interested in.

I have a switch on my devkit which implements the
BOOT_ALT#/BIOS_DISABLE# functionality from the Q7 standard, see section
3.1.17 Miscellaneous Signals in the specs:
https://sget.org/wp-content/uploads/2018/09/Qseven-Spec_2.1.pdf

"""
BIOS_DISABLE#
/BOOT_ALT#
Module BIOS disable input signal. Pull low to disable
module's on-board BIOS. Allows off-module BIOS
implementations. This signal can also be used to disable
standard boot firmware flash device and enable an alternative
boot firmware source, for example a boot loader.
"""

This is basically the configuration of the firmware boot source to use
for *the next boot*. It does not represent which boot source was used,
nor which one will effectively be used.

In our case, this switch electrically disables eMMC and SPI flashes and
only allow to boot from SD card (this switch is then electrically
overridden by another GPIO at runtime by the bootloader/Linux kernel,
but the state of the switch is still available to the user via another
GPIO).

I have this switch on the board and I want to expose its state to the
user, if this new event code is not possible/a good idea what would you
suggest we could use?

Note that we already support the same switch but in a different way:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/rockchip/rk3399-puma-haikou.dts#n167
We are just configuring the GPIOs into the GPIO mode with a pull-up, and
then it's up to the user to use gpiod or gpio-sysfs to check the state
of the GPIO used for this switch. I don't like this, very not
user-friendly and was looking for something better :)

Hope I explained myself a bit better this time, lemme know if I can
clarify anything.

Thanks!
Quentin

2022-09-23 17:34:38

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH 1/3] Input: add `SW_BOOT_ALT`

On Fri, Sep 23, 2022 at 12:19:11PM -0500, Jeff LaBundy wrote:
> Hi Quentin,
>
> On Fri, Sep 23, 2022 at 10:25:58AM +0200, Quentin Schulz wrote:
> > Hi Jeff,
> >
> > On 9/22/22 19:20, Jeff LaBundy wrote:
> > > Hi Quentin,
> > >
> > > On Thu, Sep 22, 2022 at 12:12:09PM +0200, Quentin Schulz wrote:
> > > > From: Quentin Schulz <[email protected]>
> > > >
> > > > This event code represents the firmware source to use at boot.
> > > > Value 0 means using "standard" firmware source, value 1 means using
> > > > "alternative" firmware source.
> > > >
> > > > For example, some hardware has the ability to force the BOOTROM to load
> > > > the bootloader from a secondary firmware source (say SD card) instead of
> > > > trying with the standard first and then the secondary. This event allows
> > > > the userspace to know which firmware source was requested *in hardware*.
> > > >
> > > > Signed-off-by: Quentin Schulz <[email protected]>
> > >
> > > This does not seem like the right approach, especially since the switch
> > > can easily be flipped after the state is already latched.
> > >
> > > If the bootloader needs to pass information to the kernel (boot source or
> > > otherwise), a safer and more flexible approach is to share some variables
> > > in eMMC, or pass information using the kernel cmdline.
> > >
> >
> > I made a terrible job at explaining what this switch is for, sorry.
> >
> > Obviously, the state of the switch cannot represent which firmware boot
> > source was used as only the bootloader will be able to tell (since it
> > usually tries storage media in a specific order and the primary boot source
> > could get corrupted at one point in time). Anyway, like you rightfully
> > stated, this is useless "info" and the important one would be passed by the
> > bootloader to the kernel (possibly via Device Tree fixup in case of
> > Aarch64). U-Boot does this to set the memory node so this could be done
> > again with a different property or something like that. Anyways, not
> > something I'm really interested in.
> >
> > I have a switch on my devkit which implements the BOOT_ALT#/BIOS_DISABLE#
> > functionality from the Q7 standard, see section 3.1.17 Miscellaneous Signals
> > in the specs:
> > https://sget.org/wp-content/uploads/2018/09/Qseven-Spec_2.1.pdf
> >
> > """
> > BIOS_DISABLE#
> > /BOOT_ALT#
> > Module BIOS disable input signal. Pull low to disable
> > module's on-board BIOS. Allows off-module BIOS
> > implementations. This signal can also be used to disable
> > standard boot firmware flash device and enable an alternative
> > boot firmware source, for example a boot loader.
> > """
> >
> > This is basically the configuration of the firmware boot source to use for
> > *the next boot*. It does not represent which boot source was used, nor which
> > one will effectively be used.
> >
> > In our case, this switch electrically disables eMMC and SPI flashes and only
> > allow to boot from SD card (this switch is then electrically overridden by
> > another GPIO at runtime by the bootloader/Linux kernel, but the state of the
> > switch is still available to the user via another GPIO).
>
> Thanks for the additional detail and the use-case is quite clear; I just
> don't think input is the right home for this. Input makes more sense for
> switches that a user may change during runtime with the expectation that
> an event handler effects some sort of response.
>
> Such is the case for lid open/close and headphone insertion, but here we
> are just interested in the state of a muxed GPIO.
>
> >
> > I have this switch on the board and I want to expose its state to the user,
> > if this new event code is not possible/a good idea what would you suggest we
> > could use?
> >
> > Note that we already support the same switch but in a different way: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/rockchip/rk3399-puma-haikou.dts#n167
> > We are just configuring the GPIOs into the GPIO mode with a pull-up, and
> > then it's up to the user to use gpiod or gpio-sysfs to check the state of
> > the GPIO used for this switch. I don't like this, very not user-friendly and
> > was looking for something better :)
>
> Actually, that's exactly what I was going to suggest. What in particular
> is not user-friendly about it?
>
> Of course, this is just my opinion as a fellow customer of input and it
> is ultimately up to Dmitry.

I agree with Jeff that input subsystem is not the right place for this
one-off platform feature. Just having userspace piece observing some
GPIO state should be fine for this. The layers dealing with it and
layers dealing with typical user interaction will be quite different,
so I do not see the reason for including the boot mode into the list
of input switches.

Thanks.

--
Dmitry

2022-09-23 17:59:43

by Jeff LaBundy

[permalink] [raw]
Subject: Re: [PATCH 1/3] Input: add `SW_BOOT_ALT`

Hi Quentin,

On Fri, Sep 23, 2022 at 10:25:58AM +0200, Quentin Schulz wrote:
> Hi Jeff,
>
> On 9/22/22 19:20, Jeff LaBundy wrote:
> > Hi Quentin,
> >
> > On Thu, Sep 22, 2022 at 12:12:09PM +0200, Quentin Schulz wrote:
> > > From: Quentin Schulz <[email protected]>
> > >
> > > This event code represents the firmware source to use at boot.
> > > Value 0 means using "standard" firmware source, value 1 means using
> > > "alternative" firmware source.
> > >
> > > For example, some hardware has the ability to force the BOOTROM to load
> > > the bootloader from a secondary firmware source (say SD card) instead of
> > > trying with the standard first and then the secondary. This event allows
> > > the userspace to know which firmware source was requested *in hardware*.
> > >
> > > Signed-off-by: Quentin Schulz <[email protected]>
> >
> > This does not seem like the right approach, especially since the switch
> > can easily be flipped after the state is already latched.
> >
> > If the bootloader needs to pass information to the kernel (boot source or
> > otherwise), a safer and more flexible approach is to share some variables
> > in eMMC, or pass information using the kernel cmdline.
> >
>
> I made a terrible job at explaining what this switch is for, sorry.
>
> Obviously, the state of the switch cannot represent which firmware boot
> source was used as only the bootloader will be able to tell (since it
> usually tries storage media in a specific order and the primary boot source
> could get corrupted at one point in time). Anyway, like you rightfully
> stated, this is useless "info" and the important one would be passed by the
> bootloader to the kernel (possibly via Device Tree fixup in case of
> Aarch64). U-Boot does this to set the memory node so this could be done
> again with a different property or something like that. Anyways, not
> something I'm really interested in.
>
> I have a switch on my devkit which implements the BOOT_ALT#/BIOS_DISABLE#
> functionality from the Q7 standard, see section 3.1.17 Miscellaneous Signals
> in the specs:
> https://sget.org/wp-content/uploads/2018/09/Qseven-Spec_2.1.pdf
>
> """
> BIOS_DISABLE#
> /BOOT_ALT#
> Module BIOS disable input signal. Pull low to disable
> module's on-board BIOS. Allows off-module BIOS
> implementations. This signal can also be used to disable
> standard boot firmware flash device and enable an alternative
> boot firmware source, for example a boot loader.
> """
>
> This is basically the configuration of the firmware boot source to use for
> *the next boot*. It does not represent which boot source was used, nor which
> one will effectively be used.
>
> In our case, this switch electrically disables eMMC and SPI flashes and only
> allow to boot from SD card (this switch is then electrically overridden by
> another GPIO at runtime by the bootloader/Linux kernel, but the state of the
> switch is still available to the user via another GPIO).

Thanks for the additional detail and the use-case is quite clear; I just
don't think input is the right home for this. Input makes more sense for
switches that a user may change during runtime with the expectation that
an event handler effects some sort of response.

Such is the case for lid open/close and headphone insertion, but here we
are just interested in the state of a muxed GPIO.

>
> I have this switch on the board and I want to expose its state to the user,
> if this new event code is not possible/a good idea what would you suggest we
> could use?
>
> Note that we already support the same switch but in a different way: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/rockchip/rk3399-puma-haikou.dts#n167
> We are just configuring the GPIOs into the GPIO mode with a pull-up, and
> then it's up to the user to use gpiod or gpio-sysfs to check the state of
> the GPIO used for this switch. I don't like this, very not user-friendly and
> was looking for something better :)

Actually, that's exactly what I was going to suggest. What in particular
is not user-friendly about it?

Of course, this is just my opinion as a fellow customer of input and it
is ultimately up to Dmitry.

>
> Hope I explained myself a bit better this time, lemme know if I can clarify
> anything.
>
> Thanks!
> Quentin

Kind regards,
Jeff LaBundy

2022-09-26 10:15:01

by Quentin Schulz

[permalink] [raw]
Subject: Re: [PATCH 1/3] Input: add `SW_BOOT_ALT`

Hi all,

On 9/23/22 19:19, Jeff LaBundy wrote:
[...]
>>
>> I have this switch on the board and I want to expose its state to the user,
>> if this new event code is not possible/a good idea what would you suggest we
>> could use?
>>
>> Note that we already support the same switch but in a different way: https://urldefense.proofpoint.com/v2/url?u=https-3A__git.kernel.org_pub_scm_linux_kernel_git_torvalds_linux.git_tree_arch_arm64_boot_dts_rockchip_rk3399-2Dpuma-2Dhaikou.dts-23n167&d=DwIBAg&c=_sEr5x9kUWhuk4_nFwjJtA&r=LYjLexDn7rXIzVmkNPvw5ymA1XTSqHGq8yBP6m6qZZ4njZguQhZhkI_-172IIy1t&m=vObtDja6hUlL_kVvKRILCvaQfklw1gl7TAW7cm5_9H_Yi00zkzGV6-D3yzazR2gU&s=0Xo-7CDmMoriaTNn_hJdMwftLlcY-tgopPcgzXfQtJE&e=
>> We are just configuring the GPIOs into the GPIO mode with a pull-up, and
>> then it's up to the user to use gpiod or gpio-sysfs to check the state of
>> the GPIO used for this switch. I don't like this, very not user-friendly and
>> was looking for something better :)
>
> Actually, that's exactly what I was going to suggest. What in particular
> is not user-friendly about it?
>

The implementation we currently have in place for Puma Haikou is just
muxing the pins in their GPIO function with a pull-up. Nothing else.
This means the user still needs to know exactly which GPIO number is for
which signal/event. Not that great. Also does not allow for a consistent
user "experience" across modules on the same devkit (different GPIOs
depending on the SoM).

I had hoped gpio-hog in input mode would expose it to userspace but it
does not seem to?

Anything to recommend so that we can export a GPIO line for a specific
function to usersapce without needing the user to know which GPIO number
they should look at?

While I have your attention, I was wondering about the BATTERY event. We
have a BATLOW button, following the Q7 standard:
"""
Battery low input. This signal may be driven active low by external
circuitry to signal that the system battery is low or may be used to
signal some other external battery management event.
"""

Oddly vague, but the EV_BATTERY event is not really more precise though
(at least didn't find more precise information and the introducing
commit is a bit vague too on the usage). Was just wondering if there was
any specific usage for this event or if I'm using it correctly here?

Cheers,
Quentin

2022-09-27 02:30:44

by Jeff LaBundy

[permalink] [raw]
Subject: Re: [PATCH 1/3] Input: add `SW_BOOT_ALT`

Hi Quentin,

On Mon, Sep 26, 2022 at 11:37:45AM +0200, Quentin Schulz wrote:
> Hi all,
>
> On 9/23/22 19:19, Jeff LaBundy wrote:
> [...]
> > >
> > > I have this switch on the board and I want to expose its state to the user,
> > > if this new event code is not possible/a good idea what would you suggest we
> > > could use?
> > >
> > > Note that we already support the same switch but in a different way: https://urldefense.proofpoint.com/v2/url?u=https-3A__git.kernel.org_pub_scm_linux_kernel_git_torvalds_linux.git_tree_arch_arm64_boot_dts_rockchip_rk3399-2Dpuma-2Dhaikou.dts-23n167&d=DwIBAg&c=_sEr5x9kUWhuk4_nFwjJtA&r=LYjLexDn7rXIzVmkNPvw5ymA1XTSqHGq8yBP6m6qZZ4njZguQhZhkI_-172IIy1t&m=vObtDja6hUlL_kVvKRILCvaQfklw1gl7TAW7cm5_9H_Yi00zkzGV6-D3yzazR2gU&s=0Xo-7CDmMoriaTNn_hJdMwftLlcY-tgopPcgzXfQtJE&e=
> > > We are just configuring the GPIOs into the GPIO mode with a pull-up, and
> > > then it's up to the user to use gpiod or gpio-sysfs to check the state of
> > > the GPIO used for this switch. I don't like this, very not user-friendly and
> > > was looking for something better :)
> >
> > Actually, that's exactly what I was going to suggest. What in particular
> > is not user-friendly about it?
> >
>
> The implementation we currently have in place for Puma Haikou is just muxing
> the pins in their GPIO function with a pull-up. Nothing else. This means the
> user still needs to know exactly which GPIO number is for which
> signal/event. Not that great. Also does not allow for a consistent user
> "experience" across modules on the same devkit (different GPIOs depending on
> the SoM).
>
> I had hoped gpio-hog in input mode would expose it to userspace but it does
> not seem to?

No, I don't believe that is the case. That being said, you should be
able to grep /sys/kernel/debug/gpio for the hog node's label and get
the pin state (lo or hi).

>
> Anything to recommend so that we can export a GPIO line for a specific
> function to usersapce without needing the user to know which GPIO number
> they should look at?

If debugfs won't work for your purposes, another option is to request
the GPIO from a general-purpose platform driver and return one of two
strings via sysfs.

>
> While I have your attention, I was wondering about the BATTERY event. We
> have a BATLOW button, following the Q7 standard:
> """
> Battery low input. This signal may be driven active low by external
> circuitry to signal that the system battery is low or may be used to
> signal some other external battery management event.
> """
>
> Oddly vague, but the EV_BATTERY event is not really more precise though (at
> least didn't find more precise information and the introducing commit is a
> bit vague too on the usage). Was just wondering if there was any specific
> usage for this event or if I'm using it correctly here?

Do you mean KEY_BATTERY?

>
> Cheers,
> Quentin

Kind regards,
Jeff LaBundy

2022-09-27 09:12:37

by Quentin Schulz

[permalink] [raw]
Subject: Re: [PATCH 1/3] Input: add `SW_BOOT_ALT`

Hi Jeff,

On 9/27/22 03:56, Jeff LaBundy wrote:
> Hi Quentin,
>
> On Mon, Sep 26, 2022 at 11:37:45AM +0200, Quentin Schulz wrote:
>> Hi all,
>>
>> On 9/23/22 19:19, Jeff LaBundy wrote:
>> [...]
>>>>
>>>> I have this switch on the board and I want to expose its state to the user,
>>>> if this new event code is not possible/a good idea what would you suggest we
>>>> could use?
>>>>
>>>> Note that we already support the same switch but in a different way: https://urldefense.proofpoint.com/v2/url?u=https-3A__git.kernel.org_pub_scm_linux_kernel_git_torvalds_linux.git_tree_arch_arm64_boot_dts_rockchip_rk3399-2Dpuma-2Dhaikou.dts-23n167&d=DwIBAg&c=_sEr5x9kUWhuk4_nFwjJtA&r=LYjLexDn7rXIzVmkNPvw5ymA1XTSqHGq8yBP6m6qZZ4njZguQhZhkI_-172IIy1t&m=vObtDja6hUlL_kVvKRILCvaQfklw1gl7TAW7cm5_9H_Yi00zkzGV6-D3yzazR2gU&s=0Xo-7CDmMoriaTNn_hJdMwftLlcY-tgopPcgzXfQtJE&e=
>>>> We are just configuring the GPIOs into the GPIO mode with a pull-up, and
>>>> then it's up to the user to use gpiod or gpio-sysfs to check the state of
>>>> the GPIO used for this switch. I don't like this, very not user-friendly and
>>>> was looking for something better :)
>>>
>>> Actually, that's exactly what I was going to suggest. What in particular
>>> is not user-friendly about it?
>>>
>>
>> The implementation we currently have in place for Puma Haikou is just muxing
>> the pins in their GPIO function with a pull-up. Nothing else. This means the
>> user still needs to know exactly which GPIO number is for which
>> signal/event. Not that great. Also does not allow for a consistent user
>> "experience" across modules on the same devkit (different GPIOs depending on
>> the SoM).
>>
>> I had hoped gpio-hog in input mode would expose it to userspace but it does
>> not seem to?
>
> No, I don't believe that is the case. That being said, you should be
> able to grep /sys/kernel/debug/gpio for the hog node's label and get
> the pin state (lo or hi).
>
>>
>> Anything to recommend so that we can export a GPIO line for a specific
>> function to usersapce without needing the user to know which GPIO number
>> they should look at?
>
> If debugfs won't work for your purposes, another option is to request
> the GPIO from a general-purpose platform driver and return one of two
> strings via sysfs.
>

This board will be fully supported upstream and I don't feel like this
general-purpose platform driver would be accepted, but maybe I'm wrong.

I didn't know about the /sys/kernel/debug/gpio file just yet for some
reason, so that's one way to do it, thanks for the info.

Good thing is that the kernel requests this pin in GPIO input mode so at
least that's one less possible misconfiguration from userspace. Not so
good thing is that you need to grep in this file and it's not that great
for scripts :) We'll discuss internally what feels the best to us and go
for it, thanks for the tips!

I'm wondering if allowing sysfs/libgpiod to access the state of GPIOs
requested by the kernel would make sense on the subsystem level though.
I'm sure I'm missing obvious security/HW-limitations pitfalls, but I
think allowing userspace to get the value of a GPIO input pin requested
by the kernel would be nice? Nothing for the input subsystem folks though :)

>>
>> While I have your attention, I was wondering about the BATTERY event. We
>> have a BATLOW button, following the Q7 standard:
>> """
>> Battery low input. This signal may be driven active low by external
>> circuitry to signal that the system battery is low or may be used to
>> signal some other external battery management event.
>> """
>>
>> Oddly vague, but the EV_BATTERY event is not really more precise though (at
>> least didn't find more precise information and the introducing commit is a
>> bit vague too on the usage). Was just wondering if there was any specific
>> usage for this event or if I'm using it correctly here?
>
> Do you mean KEY_BATTERY?
>

Yes sorry.

Cheers,
Quentin

2022-09-27 14:09:30

by Robin Murphy

[permalink] [raw]
Subject: Re: [PATCH 1/3] Input: add `SW_BOOT_ALT`

On 2022-09-27 09:51, Quentin Schulz wrote:
> Hi Jeff,
>
> On 9/27/22 03:56, Jeff LaBundy wrote:
>> Hi Quentin,
>>
>> On Mon, Sep 26, 2022 at 11:37:45AM +0200, Quentin Schulz wrote:
>>> Hi all,
>>>
>>> On 9/23/22 19:19, Jeff LaBundy wrote:
>>> [...]
>>>>>
>>>>> I have this switch on the board and I want to expose its state to
>>>>> the user,
>>>>> if this new event code is not possible/a good idea what would you
>>>>> suggest we
>>>>> could use?
>>>>>
>>>>> Note that we already support the same switch but in a different
>>>>> way:
>>>>> https://urldefense.proofpoint.com/v2/url?u=https-3A__git.kernel.org_pub_scm_linux_kernel_git_torvalds_linux.git_tree_arch_arm64_boot_dts_rockchip_rk3399-2Dpuma-2Dhaikou.dts-23n167&d=DwIBAg&c=_sEr5x9kUWhuk4_nFwjJtA&r=LYjLexDn7rXIzVmkNPvw5ymA1XTSqHGq8yBP6m6qZZ4njZguQhZhkI_-172IIy1t&m=vObtDja6hUlL_kVvKRILCvaQfklw1gl7TAW7cm5_9H_Yi00zkzGV6-D3yzazR2gU&s=0Xo-7CDmMoriaTNn_hJdMwftLlcY-tgopPcgzXfQtJE&e=
>>>>> We are just configuring the GPIOs into the GPIO mode with a
>>>>> pull-up, and
>>>>> then it's up to the user to use gpiod or gpio-sysfs to check the
>>>>> state of
>>>>> the GPIO used for this switch. I don't like this, very not
>>>>> user-friendly and
>>>>> was looking for something better :)
>>>>
>>>> Actually, that's exactly what I was going to suggest. What in
>>>> particular
>>>> is not user-friendly about it?
>>>>
>>>
>>> The implementation we currently have in place for Puma Haikou is just
>>> muxing
>>> the pins in their GPIO function with a pull-up. Nothing else. This
>>> means the
>>> user still needs to know exactly which GPIO number is for which
>>> signal/event. Not that great. Also does not allow for a consistent user
>>> "experience" across modules on the same devkit (different GPIOs
>>> depending on
>>> the SoM).
>>>
>>> I had hoped gpio-hog in input mode would expose it to userspace but
>>> it does
>>> not seem to?
>>
>> No, I don't believe that is the case. That being said, you should be
>> able to grep /sys/kernel/debug/gpio for the hog node's label and get
>> the pin state (lo or hi).
>>
>>>
>>> Anything to recommend so that we can export a GPIO line for a specific
>>> function to usersapce without needing the user to know which GPIO number
>>> they should look at?
>>
>> If debugfs won't work for your purposes, another option is to request
>> the GPIO from a general-purpose platform driver and return one of two
>> strings via sysfs.
>>
>
> This board will be fully supported upstream and I don't feel like this
> general-purpose platform driver would be accepted, but maybe I'm wrong.
>
> I didn't know about the /sys/kernel/debug/gpio file just yet for some
> reason, so that's one way to do it, thanks for the info.
>
> Good thing is that the kernel requests this pin in GPIO input mode so at
> least that's one less possible misconfiguration from userspace. Not so
> good thing is that you need to grep in this file and it's not that great
> for scripts :) We'll discuss internally what feels the best to us and go
> for it, thanks for the tips!
>
> I'm wondering if allowing sysfs/libgpiod to access the state of GPIOs
> requested by the kernel would make sense on the subsystem level though.
> I'm sure I'm missing obvious security/HW-limitations pitfalls, but I
> think allowing userspace to get the value of a GPIO input pin requested
> by the kernel would be nice? Nothing for the input subsystem folks
> though :)

FWIW there was a series a while back proposing to add a boot status
interface, but I'm not sure if there was any further progress:

https://lore.kernel.org/lkml/[email protected]/

Either way though, these kinds of GPIO (or ADC) configuration inputs for
things like boot functionality or board ID are just about common enough
that even if not tied in to any other specific interface, I reckon there
might be a valid argument to be made for a simple generic driver for
reporting the state of a named configuration input in a standardised
manner. Perhaps hwmon might be a better fit?

Robin.