Skip to contentSkip to conversation

a question about lid input device

DISCUSSION Zhang Rui 6 participants 19 messages Jun 13, 2010 – Sep 29, 2010 ACPI

lore
Share & tools
lore

Zhang Rui

author
#0 lore raw

Hi, Dmitry,

I have a question about the ACPI lid button input device.

By reading commit c0968f0e, I think the acpi lid button is registered as a switch (EV_SW set), and the lid status is reported via SW_LID bit, e.g. lid closed when SW_LID is set and vice versa.
Then we update the lid switch status when a Lid notification comes. right?

Then, IMO, userspace can get the lid status
via /sys/class/input/inputX/uevent, right?

here is a the output of this file on my laptop, /sys/class/input/input1/modalias:input:b0019v0000p0005e0000-e0,5,kramlsfw0, /sys/class/input/input1/name:Lid Switch /sys/class/input/input1/phys:PNP0C0D/button/input0 /sys/class/input/input1/uevent:PRODUCT=19/0/5/0 /sys/class/input/input1/uevent:NAME="Lid Switch" /sys/class/input/input1/uevent:PHYS="PNP0C0D/button/input0" /sys/class/input/input1/uevent:EV==21 /sys/class/input/input1/uevent:SW==1 /sys/class/input/input1/uevent:MODALIAS=input:b0019v0000p0005e0000-e0,5,kramlsfw0,

Lid is opened but SW is set, I tried to close/open the lid and found that this bit never changes. is there something I misunderstand? can we get the lid status in userspace?

thanks,
rui

#1 lore raw
Quoted 2 lines · Zhang Rui

Then we update the lid switch status when a Lid notification comes. right?

Yes.

Quoted 2 lines

Then, IMO, userspace can get the lid status
via /sys/class/input/inputX/uevent, right?

No, only through an IOCTL.

Quoted 1 line

/sys/class/input/input1/uevent:EV==21

That's an bitmap of al EV_EV it supports.

Quoted 1 line

/sys/class/input/input1/uevent:SW==1

That's an bitmap of al EV_SW it supports.

Quoted 3 lines

Lid is opened but SW is set, I tried to close/open the lid and found that this bit never changes. is there something I misunderstand? can we get the lid status in userspace?

IOCTL(), only.

Since nobody got a input-utils standard package (or added something to util-linux) yet to do that (AFAIK anyway), it is a MAJOR annoyance for shell scripts that want to query EV_SW state...

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
reviewer
#2 lore raw

Dmitry,
Is there a reason not to simply add a "state" attribute to a LID input device?

thanks,
Len Brown, Intel Open Source Technology Center

Quoted 29 lines · Henrique de Moraes Holschuh
Quoted 2 lines · Zhang Rui

Then we update the lid switch status when a Lid notification comes. right?

Yes.

Quoted 2 lines

Then, IMO, userspace can get the lid status
via /sys/class/input/inputX/uevent, right?

No, only through an IOCTL.

Quoted 1 line

/sys/class/input/input1/uevent:EV==21

That's an bitmap of al EV_EV it supports.

Quoted 1 line

/sys/class/input/input1/uevent:SW==1

That's an bitmap of al EV_SW it supports.

Quoted 3 lines

Lid is opened but SW is set, I tried to close/open the lid and found that this bit never changes. is there something I misunderstand? can we get the lid status in userspace?

IOCTL(), only.

Since nobody got a input-utils standard package (or added something to util-linux) yet to do that (AFAIK anyway), it is a MAJOR annoyance for shell scripts that want to query EV_SW state...

#3 lore raw
Quoted 4 lines · Len Brown

Dmitry,
Is there a reason not to simply add a "state" attribute to a LID input device?

Len,

There is no LED input device, there is an input device that happens to report EV_SW/SW_LID state. If we did that we'd need to add attributes for all types of switches, keys, current values of REL and ABS axis, min/max/fuzz/flat settings of ABS axis and so forth that input device might report. I do not think it is a good idea.

Quoted 36 lines

thanks,
Len Brown, Intel Open Source Technology Center

Quoted 29 lines · Henrique de Moraes Holschuh
Quoted 2 lines · Zhang Rui

Then we update the lid switch status when a Lid notification comes. right?

Yes.

Quoted 2 lines

Then, IMO, userspace can get the lid status
via /sys/class/input/inputX/uevent, right?

No, only through an IOCTL.

Quoted 1 line

/sys/class/input/input1/uevent:EV==21

That's an bitmap of al EV_EV it supports.

Quoted 1 line

/sys/class/input/input1/uevent:SW==1

That's an bitmap of al EV_SW it supports.

Quoted 3 lines

Lid is opened but SW is set, I tried to close/open the lid and found that this bit never changes. is there something I misunderstand? can we get the lid status in userspace?

IOCTL(), only.

Since nobody got a input-utils standard package (or added something to util-linux) yet to do that (AFAIK anyway), it is a MAJOR annoyance for shell scripts that want to query EV_SW state...

Signature · 1 line
Dmitry
author
#4 lore raw
Quoted 6 lines · Dmitry Torokhov
Quoted 4 lines · Len Brown

Dmitry,
Is there a reason not to simply add a "state" attribute to a LID input device?

Quoted 8 lines

Len,

There is no LED input device, there is an input device that happens to report EV_SW/SW_LID state. If we did that we'd need to add attributes for all types of switches, keys, current values of REL and ABS axis, min/max/fuzz/flat settings of ABS axis and so forth that input device might report. I do not think it is a good idea.

I agree.
How about adding a field in uevent file that reports the switch status?

thanks,
rui

Quoted 37 lines
Quoted 36 lines

thanks,
Len Brown, Intel Open Source Technology Center

Quoted 29 lines · Henrique de Moraes Holschuh
Quoted 2 lines · Zhang Rui

Then we update the lid switch status when a Lid notification comes. right?

Yes.

Quoted 2 lines

Then, IMO, userspace can get the lid status
via /sys/class/input/inputX/uevent, right?

No, only through an IOCTL.

Quoted 1 line

/sys/class/input/input1/uevent:EV==21

That's an bitmap of al EV_EV it supports.

Quoted 1 line

/sys/class/input/input1/uevent:SW==1

That's an bitmap of al EV_SW it supports.

Quoted 3 lines

Lid is opened but SW is set, I tried to close/open the lid and found that this bit never changes. is there something I misunderstand? can we get the lid status in userspace?

IOCTL(), only.

Since nobody got a input-utils standard package (or added something to util-linux) yet to do that (AFAIK anyway), it is a MAJOR annoyance for shell scripts that want to query EV_SW state...

#5 lore raw
Quoted 9 lines · Zhang Rui
Quoted 8 lines · Dmitry Torokhov
Quoted 4 lines · Len Brown

Dmitry,
Is there a reason not to simply add a "state" attribute to a LID input device?

Len,

Quoted 9 lines
Quoted 6 lines

There is no LED input device, there is an input device that happens to report EV_SW/SW_LID state. If we did that we'd need to add attributes for all types of switches, keys, current values of REL and ABS axis, min/max/fuzz/flat settings of ABS axis and so forth that input device might report. I do not think it is a good idea.

I agree.
How about adding a field in uevent file that reports the switch status?

I think if you can listen to uevents you can just as easily open /dev/input/eventX and listen to proper input events.

Thanks.

Signature · 1 line
Dmitry
author
#6 lore raw
Quoted 18 lines · Dmitry Torokhov
Quoted 16 lines · Zhang Rui
Quoted 15 lines · Dmitry Torokhov
Quoted 4 lines · Len Brown

Dmitry,
Is there a reason not to simply add a "state" attribute to a LID input device?

Len,

There is no LED input device, there is an input device that happens to
report EV_SW/SW_LID state. If we did that we'd need to add attributes for all types of switches, keys, current values of REL and ABS axis, min/max/fuzz/flat settings of ABS axis and so forth that input device might report. I do not think it is a good idea.

Quoted 9 lines
Quoted 4 lines

I agree.
How about adding a field in uevent file that reports the switch status?

I think if you can listen to uevents you can just as easily open /dev/ input/eventX and listen to proper input events.

the question is users may want to get the lid switch STATUS, asynchronously.

thank,
rui

#7 lore raw
Quoted 5 lines · Zhang Rui
Quoted 3 lines

I think if you can listen to uevents you can just as easily open /dev/ input/eventX and listen to proper input events.

the question is users may want to get the lid switch STATUS, asynchronously.

More often than not, you need to know the current state when dealing with EV_SW, to be able to do anything sensbile with it in GUIs, etc.

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
#8 lore raw
Quoted 9 lines · henrique de moraes holschuh
Quoted 5 lines · Zhang Rui
Quoted 3 lines

I think if you can listen to uevents you can just as easily open /dev/ input/eventX and listen to proper input events.

the question is users may want to get the lid switch STATUS, asynchronously.

More often than not, you need to know the current state when dealing with EV_SW, to be able to do anything sensbile with it in GUIs, etc.

indeed, this is true for almost any event-on-change interface -- tablet mode, AC insertion, etc. the change event alone is never enough.

paul
=---------------------
paul fox, [email protected]

#9 lore raw
In reply to Henrique de Moraes Holschuh
Quoted 10 lines · Henrique de Moraes Holschuh
Quoted 5 lines · Zhang Rui
Quoted 3 lines

I think if you can listen to uevents you can just as easily open /dev/ input/eventX and listen to proper input events.

the question is users may want to get the lid switch STATUS, asynchronously.

More often than not, you need to know the current state when dealing with EV_SW, to be able to do anything sensbile with it in GUIs, etc.

I understand the need of getting the current state of a lid switch/key/etc (and for that someone just need to write a utility useable from shell scripts). But I do not understand how adding switch state to uevents (that are emitted normally only when a new device is created) will help here.

Signature · 1 line
Dmitry
author
#10 lore raw
Quoted 12 lines · Dmitry Torokhov
Quoted 10 lines · Henrique de Moraes Holschuh
Quoted 5 lines · Zhang Rui
Quoted 3 lines

I think if you can listen to uevents you can just as easily open /dev/ input/eventX and listen to proper input events.

the question is users may want to get the lid switch STATUS, asynchronously.

More often than not, you need to know the current state when dealing with EV_SW, to be able to do anything sensbile with it in GUIs, etc.

Quoted 6 lines

I understand the need of getting the current state of a lid switch/key/etc (and for that someone just need to write a utility useable from shell scripts). But I do not understand how adding switch state to uevents (that are emitted normally only when a new device is created) will help here.

driver core creates a sysfs attribute for uevent. and users may query this file to get the lid state, say:

$ cat /sys/class/input/input1/uevent 
PRODUCT=19/0/5/0
NAME="Lid Switch"
PHYS="PNP0C0D/button/input0"
EV==21
SW==1
MODALIAS=input:b0019v0000p0005e0000-e0,5,kramlsfw0,

I'm not quite familiar with the uevent stuff, so please correct me if I'm wrong. :)
IMO, for input switch device, it's reasonable to report the switch state in uevent, in which HAL may also be interested. And users may get the switch status by running "cat /sys/class/input/inputX/uevent" as well.

thanks,
rui

#11 lore raw
Quoted 29 lines · Zhang Rui
Quoted 12 lines · Dmitry Torokhov
Quoted 10 lines · Henrique de Moraes Holschuh
Quoted 5 lines · Zhang Rui
Quoted 3 lines

I think if you can listen to uevents you can just as easily open /dev/ input/eventX and listen to proper input events.

the question is users may want to get the lid switch STATUS, asynchronously.

More often than not, you need to know the current state when dealing with EV_SW, to be able to do anything sensbile with it in GUIs, etc.

Quoted 6 lines

I understand the need of getting the current state of a lid switch/key/etc (and for that someone just need to write a utility useable from shell scripts). But I do not understand how adding switch state to uevents (that are emitted normally only when a new device is created) will help here.

driver core creates a sysfs attribute for uevent. and users may query this file to get the lid state, say:

$ cat /sys/class/input/input1/uevent 
PRODUCT=19/0/5/0
NAME="Lid Switch"
PHYS="PNP0C0D/button/input0"
EV==21
SW==1
MODALIAS=input:b0019v0000p0005e0000-e0,5,kramlsfw0,
Quoted 6 lines

I'm not quite familiar with the uevent stuff, so please correct me if I'm wrong. :)
IMO, for input switch device, it's reasonable to report the switch state in uevent, in which HAL may also be interested. And users may get the switch status by running "cat /sys/class/input/inputX/uevent" as well.

No, I am sorry, you are inventing a new interface. Uevents normally signal device creation and removal and carry capabilities, not the state; there can be more than one switch/button per device, and so on.

Just write an utility that queries state via ioctl.

Thanks,

Signature · 1 line
Dmitry
#12 lore raw
In reply to Henrique de Moraes Holschuh
Quoted 23 lines · henrique de moraes holschuh
Quoted 2 lines · Zhang Rui

Then we update the lid switch status when a Lid notification comes. right?

Yes.

Quoted 2 lines

Then, IMO, userspace can get the lid status
via /sys/class/input/inputX/uevent, right?

No, only through an IOCTL.

Quoted 1 line

/sys/class/input/input1/uevent:EV==21

That's an bitmap of al EV_EV it supports.

Quoted 1 line

/sys/class/input/input1/uevent:SW==1

That's an bitmap of al EV_SW it supports.

Quoted 3 lines

Lid is opened but SW is set, I tried to close/open the lid and found that this bit never changes. is there something I misunderstand? can we get the lid status in userspace?

Quoted 5 lines

IOCTL(), only.

Since nobody got a input-utils standard package (or added something to util-linux) yet to do that (AFAIK anyway), it is a MAJOR annoyance for shell scripts that want to query EV_SW state...

i understand that it's not fully general, but for the case of the lid: is /proc/acpi/button/lid/LID/state going away?

paul
=---------------------
paul fox, [email protected] (arlington, ma, where it's 87.1 degrees)

#13 lore raw
Quoted 24 lines · Paul Fox
Quoted 23 lines · henrique de moraes holschuh
Quoted 2 lines · Zhang Rui

Then we update the lid switch status when a Lid notification comes. right?

Yes.

Quoted 2 lines

Then, IMO, userspace can get the lid status
via /sys/class/input/inputX/uevent, right?

No, only through an IOCTL.

Quoted 1 line

/sys/class/input/input1/uevent:EV==21

That's an bitmap of al EV_EV it supports.

Quoted 1 line

/sys/class/input/input1/uevent:SW==1

That's an bitmap of al EV_SW it supports.

Quoted 3 lines

Lid is opened but SW is set, I tried to close/open the lid and found that this bit never changes. is there something I misunderstand? can we get the lid status in userspace?

Quoted 9 lines
Quoted 5 lines

IOCTL(), only.

Since nobody got a input-utils standard package (or added something to util-linux) yet to do that (AFAIK anyway), it is a MAJOR annoyance for shell scripts that want to query EV_SW state...

i understand that it's not fully general, but for the case of the lid: is /proc/acpi/button/lid/LID/state going away?

Yes, according to feature-removal.txt ACPI procfs interface shoudl have been gone back in 2008.

Signature · 1 line
Dmitry
#14 lore raw
Quoted 31 lines · dmitry
Quoted 30 lines · Paul Fox
Quoted 28 lines · henrique de moraes holschuh
Quoted 2 lines · Zhang Rui

Then we update the lid switch status when a Lid notification comes. right?

Yes.

Quoted 2 lines

Then, IMO, userspace can get the lid status
via /sys/class/input/inputX/uevent, right?

No, only through an IOCTL.

Quoted 1 line

/sys/class/input/input1/uevent:EV==21

That's an bitmap of al EV_EV it supports.

Quoted 1 line

/sys/class/input/input1/uevent:SW==1

That's an bitmap of al EV_SW it supports.

Quoted 3 lines

Lid is opened but SW is set, I tried to close/open the lid and found that this bit never changes. is there something I misunderstand? can we get the lid status in userspace?

IOCTL(), only.

Since nobody got a input-utils standard package (or added something to util-linux) yet to do that (AFAIK anyway), it is a MAJOR annoyance for shell scripts that want to query EV_SW state...

Quoted 6 lines
Quoted 3 lines

i understand that it's not fully general, but for the case of the lid: is /proc/acpi/button/lid/LID/state going away?

Yes, according to feature-removal.txt ACPI procfs interface shoudl have been gone back in 2008.

thanks. i understand that adding sysfs entries for all the bells and whistles on modern input devices might seem prohibitive. on the other hand, there are some basic interfaces that are very usefully accessed from the shell. i guess either way the information is available, but having to rely on a utility package for intermediate access always introduces new packaging dependencies, release skew issues, etc, etc.

paul
=---------------------
paul fox, [email protected]

#15 lore raw
Quoted 39 lines · Paul Fox
Quoted 31 lines · dmitry
Quoted 30 lines · Paul Fox
Quoted 28 lines · henrique de moraes holschuh
Quoted 2 lines · Zhang Rui

Then we update the lid switch status when a Lid notification comes. right?

Yes.

Quoted 2 lines

Then, IMO, userspace can get the lid status
via /sys/class/input/inputX/uevent, right?

No, only through an IOCTL.

Quoted 1 line

/sys/class/input/input1/uevent:EV==21

That's an bitmap of al EV_EV it supports.

Quoted 1 line

/sys/class/input/input1/uevent:SW==1

That's an bitmap of al EV_SW it supports.

Quoted 3 lines

Lid is opened but SW is set, I tried to close/open the lid and found that this bit never changes. is there something I misunderstand? can we get the lid status in userspace?

IOCTL(), only.

Since nobody got a input-utils standard package (or added something to util-linux) yet to do that (AFAIK anyway), it is a MAJOR annoyance for shell scripts that want to query EV_SW state...

Quoted 6 lines
Quoted 3 lines

i understand that it's not fully general, but for the case of the lid: is /proc/acpi/button/lid/LID/state going away?

Yes, according to feature-removal.txt ACPI procfs interface shoudl have been gone back in 2008.

Quoted 8 lines

thanks. i understand that adding sysfs entries for all the bells and whistles on modern input devices might seem prohibitive. on the other hand, there are some basic interfaces that are very usefully accessed from the shell. i guess either way the information is available, but having to rely on a utility package for intermediate access always introduces new packaging dependencies, release skew issues, etc, etc.

I am not wasting kernel memory to export full state of an arbitrary input device via sysfs just so someone out there might avoid writing or installig a utility. The interface was there for many years and is quite stable, I do not understand what release skew issues you are talking about.

Thanks.

Signature · 1 line
Dmitry
#16 lore raw
Quoted 3 lines · dmitry
Quoted 2 lines · Paul Fox
Quoted 1 line · dmitry

On Wed, Jul 07, 2010 at 11:14:20AM -0400, Paul Fox wrote:

...

Quoted 15 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

i understand that it's not fully general, but for the case of the lid: is /proc/acpi/button/lid/LID/state going away?

Yes, according to feature-removal.txt ACPI procfs interface shoudl have been gone back in 2008.

Quoted 8 lines

thanks. i understand that adding sysfs entries for all the bells and whistles on modern input devices might seem prohibitive. on the other hand, there are some basic interfaces that are very usefully accessed from the shell. i guess either way the information is available, but having to rely on a utility package for intermediate access always introduces new packaging dependencies, release skew issues, etc, etc.

Quoted 5 lines

I am not wasting kernel memory to export full state of an arbitrary input device via sysfs just so someone out there might avoid writing or installig a utility. The interface was there for many years and is quite stable, I do not understand what release skew issues you are talking about.

if, for example, the utility package available in a distro lags behind the kernel.

but please consider my comments above as more of a lament than a complaint. i understand your design decision -- it will make your life easier, at the expense of making mine somewhat more difficult. :-)

paul
=---------------------
paul fox, [email protected]

#17 lore raw
Quoted 20 lines · Paul Fox
Quoted 3 lines · dmitry
Quoted 2 lines · Paul Fox
Quoted 1 line · dmitry

On Wed, Jul 07, 2010 at 11:14:20AM -0400, Paul Fox wrote:

...

Quoted 15 lines
Quoted 14 lines
Quoted 5 lines
Quoted 2 lines

i understand that it's not fully general, but for the case of the lid: is /proc/acpi/button/lid/LID/state going away?

Yes, according to feature-removal.txt ACPI procfs interface shoudl have been gone back in 2008.

thanks. i understand that adding sysfs entries for all the bells and whistles on modern input devices might seem prohibitive. on the other hand, there are some basic interfaces that are very usefully accessed from the shell. i guess either way the information is available, but having to rely on a utility package for intermediate access always introduces new packaging dependencies, release skew issues, etc, etc.

Quoted 9 lines
Quoted 5 lines

I am not wasting kernel memory to export full state of an arbitrary input device via sysfs just so someone out there might avoid writing or installig a utility. The interface was there for many years and is quite stable, I do not understand what release skew issues you are talking about.

if, for example, the utility package available in a distro lags behind the kernel.

How can it lag? The interface to query the state is available at least since 2.6.0 and is not likely to change for years to come.

Quoted 5 lines

but please consider my comments above as more of a lament than a complaint. i understand your design decision -- it will make your life easier, at the expense of making mine somewhat more difficult. :-)

It is not that it will make my life easier. Exporting state in sysfs is easy, but do you really want your keyboard device to consume memory needed for 100+ sysfs nodes that nobody cares about?

Signature · 1 line
Dmitry
reviewer
#18 lore raw
In reply to Dmitry Torokhov
Quoted 4 lines
Quoted 1 line

the lid: is /proc/acpi/button/lid/LID/state going away?

Yes, according to feature-removal.txt ACPI procfs interface shoudl have been gone back in 2008.

Note that /proc/acpi/button/lid/*/state is not reliable on a measurable portion of systems.

We suspect that other operating systems do not use it, and thus when Linux tries to use it, sometimes we get burnt.

thanks,
-Len Brown, Intel Open Source Technology Center