linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Single gpio shared by LED and switch?
@ 2015-09-01 17:00 Geert Uytterhoeven
  2015-09-07 13:03 ` Jacek Anaszewski
  0 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2015-09-01 17:00 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio@vger.kernel.org, linux-leds@vger.kernel.org

Hi,

I'm wondering if there already exists a driver for a gpio that's connected
to both an LED and an input switch.

I'd expect such a hardware configuration to be fairly common, as gpios can be
a limited resource.
Most of the time the gpio would be in output mode, driving the LED, but at
regular intervals the mode would be changed for a very short moment to input,
to monitor the state of the switch.

I had a quick look at various drivers (and of course at
Documentation/gpio/drivers-on-gpio.txt), but couldn't find any.

Does such a hybrid of "leds-gpio" and "gpio-keys(-polled)" already exists?

Thanks in advance!

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Single gpio shared by LED and switch?
  2015-09-01 17:00 Single gpio shared by LED and switch? Geert Uytterhoeven
@ 2015-09-07 13:03 ` Jacek Anaszewski
  2015-09-07 13:22   ` Geert Uytterhoeven
  0 siblings, 1 reply; 7+ messages in thread
From: Jacek Anaszewski @ 2015-09-07 13:03 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Linus Walleij, linux-gpio@vger.kernel.org,
	linux-leds@vger.kernel.org

Hi Geert,

On 09/01/2015 07:00 PM, Geert Uytterhoeven wrote:
> Hi,
>
> I'm wondering if there already exists a driver for a gpio that's connected
> to both an LED and an input switch.
>
> I'd expect such a hardware configuration to be fairly common, as gpios can be
> a limited resource.
> Most of the time the gpio would be in output mode, driving the LED, but at
> regular intervals the mode would be changed for a very short moment to input,
> to monitor the state of the switch.
>
> I had a quick look at various drivers (and of course at
> Documentation/gpio/drivers-on-gpio.txt), but couldn't find any.
>
> Does such a hybrid of "leds-gpio" and "gpio-keys(-polled)" already exists?

Can you share an example of such a circuit? Would it be possible to
construct it without additional GPIO driven transistor?

-- 
Best Regards,
Jacek Anaszewski

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Single gpio shared by LED and switch?
  2015-09-07 13:03 ` Jacek Anaszewski
@ 2015-09-07 13:22   ` Geert Uytterhoeven
  2015-09-08 10:51     ` Jacek Anaszewski
  0 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2015-09-07 13:22 UTC (permalink / raw)
  To: Jacek Anaszewski
  Cc: Linus Walleij, linux-gpio@vger.kernel.org,
	linux-leds@vger.kernel.org

Hi Jacek,

On Mon, Sep 7, 2015 at 3:03 PM, Jacek Anaszewski
<j.anaszewski@samsung.com> wrote:
> On 09/01/2015 07:00 PM, Geert Uytterhoeven wrote:
>> I'm wondering if there already exists a driver for a gpio that's connected
>> to both an LED and an input switch.
>>
>> I'd expect such a hardware configuration to be fairly common, as gpios can
>> be
>> a limited resource.
>> Most of the time the gpio would be in output mode, driving the LED, but at
>> regular intervals the mode would be changed for a very short moment to
>> input,
>> to monitor the state of the switch.
>>
>> I had a quick look at various drivers (and of course at
>> Documentation/gpio/drivers-on-gpio.txt), but couldn't find any.
>>
>> Does such a hybrid of "leds-gpio" and "gpio-keys(-polled)" already exists?
>
> Can you share an example of such a circuit? Would it be possible to

Something like this?

                     VCC         VCC
                      |           |
                      R           R
                      |           |
              __|__   |           |
          +---o   o---+          _|_
          |           |          \ /
          |           |          ---
         GND          R           |
                      |           |
                      |         |-+
                      |         |<+
GPIO -----------------+---------|-|
                                  |
                                  |
                                 GND

> construct it without additional GPIO driven transistor?

Perhaps just like this?

                     VCC
                      |
                      R
                      |
                      |
                     _|_
                     \ /
                     ---
                      |
                      |
GPIO -----R-----------+
                      |
                      |
                    | o
                   -|
                    | o
                      |
                      |
                     GND

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Single gpio shared by LED and switch?
  2015-09-07 13:22   ` Geert Uytterhoeven
@ 2015-09-08 10:51     ` Jacek Anaszewski
  2015-09-08 14:37       ` Linus Walleij
  0 siblings, 1 reply; 7+ messages in thread
From: Jacek Anaszewski @ 2015-09-08 10:51 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Linus Walleij, linux-gpio@vger.kernel.org,
	linux-leds@vger.kernel.org

Hi Geert,

Thanks for sharing this.

On 09/07/2015 03:22 PM, Geert Uytterhoeven wrote:
> Hi Jacek,
>
> On Mon, Sep 7, 2015 at 3:03 PM, Jacek Anaszewski
> <j.anaszewski@samsung.com> wrote:
>> On 09/01/2015 07:00 PM, Geert Uytterhoeven wrote:
>>> I'm wondering if there already exists a driver for a gpio that's connected
>>> to both an LED and an input switch.
>>>
>>> I'd expect such a hardware configuration to be fairly common, as gpios can
>>> be
>>> a limited resource.
>>> Most of the time the gpio would be in output mode, driving the LED, but at
>>> regular intervals the mode would be changed for a very short moment to
>>> input,
>>> to monitor the state of the switch.
>>>
>>> I had a quick look at various drivers (and of course at
>>> Documentation/gpio/drivers-on-gpio.txt), but couldn't find any.
>>>
>>> Does such a hybrid of "leds-gpio" and "gpio-keys(-polled)" already exists?
>>
>> Can you share an example of such a circuit? Would it be possible to
>
> Something like this?
>
>                       VCC         VCC
>                        |           |
>                        R           R
>                        |           |
>                __|__   |           |
>            +---o   o---+          _|_
>            |           |          \ /
>            |           |          ---
>           GND          R           |
>                        |           |
>                        |         |-+
>                        |         |<+
> GPIO -----------------+---------|-|
>                                    |
>                                    |
>                                   GND

You would need also resistor to avoid short-circuit
when the switch is on.

>
>> construct it without additional GPIO driven transistor?
>
> Perhaps just like this?
>
>                       VCC
>                        |
>                        R
>                        |
>                        |
>                       _|_
>                       \ /
>                       ---
>                        |
>                        |
> GPIO -----R-----------+
>                        |
>                        |
>                      | o
>                     -|
>                      | o
>                        |
>                        |
>                       GND
>

We'd have to ask Linus if he welcomes drivers for this type
of home-made circuits in mainline. If yes, then probably someone would
have to build the circuit, develop and test the driver on it, and
finally come up with a detailed documentation.
Are you the volunteer? :)

-- 
Best Regards,
Jacek Anaszewski

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Single gpio shared by LED and switch?
  2015-09-08 10:51     ` Jacek Anaszewski
@ 2015-09-08 14:37       ` Linus Walleij
  2015-09-09  7:25         ` Jacek Anaszewski
  0 siblings, 1 reply; 7+ messages in thread
From: Linus Walleij @ 2015-09-08 14:37 UTC (permalink / raw)
  To: Jacek Anaszewski
  Cc: Geert Uytterhoeven, linux-gpio@vger.kernel.org,
	linux-leds@vger.kernel.org

On Tue, Sep 8, 2015 at 12:51 PM, Jacek Anaszewski
<j.anaszewski@samsung.com> wrote:
> On 09/07/2015 03:22 PM, Geert Uytterhoeven wrote:

>> Something like this?
>>
>>                       VCC         VCC
>>                        |           |
>>                        R           R
>>                        |           |
>>                __|__   |           |
>>            +---o   o---+          _|_
>>            |           |          \ /
>>            |           |          ---
>>           GND          R           |
>>                        |           |
>>                        |         |-+
>>                        |         |<+
>> GPIO -----------------+---------|-|
>>                                    |
>>                                    |
>>                                   GND
>
>
> You would need also resistor to avoid short-circuit
> when the switch is on.

There is a resistor AFAICT.

But consider the GPIO side which is opaque
here. When used as input it is often high impedance
but when used to drive it is not.

Doesn't this mean the output actually has to be
open collector (open drain)?

In that case we should enforce that in the software
framework too so we protect people from shooting
themselves in the foot.

> We'd have to ask Linus if he welcomes drivers for this type
> of home-made circuits in mainline. If yes, then probably someone would
> have to build the circuit, develop and test the driver on it, and
> finally come up with a detailed documentation.
> Are you the volunteer? :)

Of course he's considering it or he wouldn't write :)

I'm curious about what comes out of this, this is exactly
the type of problems that the GPIO subsystem is about
to help with.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Single gpio shared by LED and switch?
  2015-09-08 14:37       ` Linus Walleij
@ 2015-09-09  7:25         ` Jacek Anaszewski
  2015-09-09  7:35           ` Geert Uytterhoeven
  0 siblings, 1 reply; 7+ messages in thread
From: Jacek Anaszewski @ 2015-09-09  7:25 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Geert Uytterhoeven, linux-gpio@vger.kernel.org,
	linux-leds@vger.kernel.org

On 09/08/2015 04:37 PM, Linus Walleij wrote:
> On Tue, Sep 8, 2015 at 12:51 PM, Jacek Anaszewski
> <j.anaszewski@samsung.com> wrote:
>> On 09/07/2015 03:22 PM, Geert Uytterhoeven wrote:
>
>>> Something like this?
>>>
>>>                        VCC         VCC
>>>                         |           |
>>>                         R           R
>>>                         |           |
>>>                 __|__   |           |
>>>             +---o   o---+          _|_
>>>             |           |          \ /
>>>             |           |          ---
>>>            GND          R           |
>>>                         |           |
>>>                         |         |-+
>>>                         |         |<+
>>> GPIO -----------------+---------|-|
>>>                                     |
>>>                                     |
>>>                                    GND
>>
>>
>> You would need also resistor to avoid short-circuit
>> when the switch is on.
>
> There is a resistor AFAICT.

Indeed. For some reason my mind filtered out these 'R'
characters.

> But consider the GPIO side which is opaque
> here. When used as input it is often high impedance
> but when used to drive it is not.
>
> Doesn't this mean the output actually has to be
> open collector (open drain)?

I think that GPIO control register would have to be
altered to switch between particular modes.

Let's analyze possible modes, assuming that the transistor
is a bipolar PNP:

LED_OFF: GPIO in output mode, state 1.
LED_ON: GPIO in pull down mode (or output 0?) The drawback here
         is that additional current flow will occur from VCC to GPIO,
read SW state: GPIO in input mode, high impedance
                (the LED would be off for this period)

Correct me if I'm wrong, I haven't played with electronics
for a long time.

> In that case we should enforce that in the software
> framework too so we protect people from shooting
> themselves in the foot.

We would have to use pinctrl for this, I presume.

>> We'd have to ask Linus if he welcomes drivers for this type
>> of home-made circuits in mainline. If yes, then probably someone would
>> have to build the circuit, develop and test the driver on it, and
>> finally come up with a detailed documentation.
>> Are you the volunteer? :)
>
> Of course he's considering it or he wouldn't write :)
>
> I'm curious about what comes out of this, this is exactly
> the type of problems that the GPIO subsystem is about
> to help with.

That's great. It seems that the potential driver would
best fit for GPIO subsystem, and we could think about creating
some wrapper in the LED subsystem, to make it compatible
with led-triggers.

-- 
Best Regards,
Jacek Anaszewski

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Single gpio shared by LED and switch?
  2015-09-09  7:25         ` Jacek Anaszewski
@ 2015-09-09  7:35           ` Geert Uytterhoeven
  0 siblings, 0 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2015-09-09  7:35 UTC (permalink / raw)
  To: Jacek Anaszewski
  Cc: Linus Walleij, linux-gpio@vger.kernel.org,
	linux-leds@vger.kernel.org

Hi Jacek,

On Wed, Sep 9, 2015 at 9:25 AM, Jacek Anaszewski
<j.anaszewski@samsung.com> wrote:
> On 09/08/2015 04:37 PM, Linus Walleij wrote:
>> On Tue, Sep 8, 2015 at 12:51 PM, Jacek Anaszewski
>> <j.anaszewski@samsung.com> wrote:
>>> On 09/07/2015 03:22 PM, Geert Uytterhoeven wrote:
>>>> Something like this?
>>>>
>>>>                        VCC         VCC
>>>>                         |           |
>>>>                         R           R
>>>>                         |           |
>>>>                 __|__   |           |
>>>>             +---o   o---+          _|_
>>>>             |           |          \ /
>>>>             |           |          ---
>>>>            GND          R           |
>>>>                         |           |
>>>>                         |         |-+
>>>>                         |         |<+
>>>> GPIO -----------------+---------|-|
>>>>                                     |
>>>>                                     |
>>>>                                    GND
>>>
>>> You would need also resistor to avoid short-circuit
>>> when the switch is on.
>>
>> There is a resistor AFAICT.
>
> Indeed. For some reason my mind filtered out these 'R'
> characters.

Sorry for the bad drawing, which is a simplified extract from the real
schematic diagram.

>> But consider the GPIO side which is opaque
>> here. When used as input it is often high impedance
>> but when used to drive it is not.
>>
>> Doesn't this mean the output actually has to be
>> open collector (open drain)?

I think the GPIO is just a standard push-pull output in output mode.

> I think that GPIO control register would have to be
> altered to switch between particular modes.
>
> Let's analyze possible modes, assuming that the transistor
> is a bipolar PNP:

Actually it's an N-channel MOSFET.

>>> We'd have to ask Linus if he welcomes drivers for this type
>>> of home-made circuits in mainline. If yes, then probably someone would
>>> have to build the circuit, develop and test the driver on it, and
>>> finally come up with a detailed documentation.
>>> Are you the volunteer? :)
>>
>> Of course he's considering it or he wouldn't write :)

This is not a home-made circuit.
Let's see how it goes when the hardware arrives...

Thanks, now I know no driver exists yet.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-09-09  7:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-01 17:00 Single gpio shared by LED and switch? Geert Uytterhoeven
2015-09-07 13:03 ` Jacek Anaszewski
2015-09-07 13:22   ` Geert Uytterhoeven
2015-09-08 10:51     ` Jacek Anaszewski
2015-09-08 14:37       ` Linus Walleij
2015-09-09  7:25         ` Jacek Anaszewski
2015-09-09  7:35           ` Geert Uytterhoeven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).