Re: add lid status sensor to acpibtn

2013-08-14 Thread Vadim Zhukov
2013/8/13 Landry Breuil lan...@rhaalovely.net:
 On Mon, Aug 12, 2013 at 06:01:25PM +0200, David Coppa wrote:
 On Mon, Aug 12, 2013 at 5:40 PM, Landry Breuil lan...@rhaalovely.net wrote:
  Hi,
 
  this diff adds a sensor for acpibtn to show lid status. This allows
  userland to monitor/react on lid close/open events, in case one is not
  using machdep.lidsuspend. I know sysutils/upower can make use of this, i
  just need to add the corresponding code there.
 
  comments ? I wonder if/how the case when aml_evalinteger() fails should
  be handled in acpibtn_attach()..

 Where's the diff?

 Err.. here it is.

 Index: acpibtn.c
 ===
 RCS file: /cvs/src/sys/dev/acpi/acpibtn.c,v
 retrieving revision 1.34
 diff -u -r1.34 acpibtn.c
 --- acpibtn.c   2 Jan 2011 04:56:57 -   1.34
 +++ acpibtn.c   12 Aug 2013 15:35:35 -
 @@ -46,6 +46,9 @@
 struct acpi_softc   *sc_acpi;
 struct aml_node *sc_devnode;

 +   struct ksensor  sc_sens;
 +   struct ksensordev   sc_sensdev;
 +
 int sc_btn_type;
  #defineACPIBTN_UNKNOWN 0
  #define ACPIBTN_LID1
 @@ -123,6 +126,7 @@
 struct acpibtn_softc*sc = (struct acpibtn_softc *)self;
 struct acpi_attach_args *aa = aux;
 struct acpi_lid *lid;
 +   int64_t lid_open;

 sc-sc_acpi = (struct acpi_softc *)parent;
 sc-sc_devnode = aa-aaa_node;
 @@ -143,6 +147,20 @@

 printf(: %s\n, sc-sc_devnode-name);

 +   if (sc-sc_btn_type == ACPIBTN_LID) {
 +   strlcpy(sc-sc_sensdev.xname, DEVNAME(sc),
 +   sizeof(sc-sc_sensdev.xname));
 +   strlcpy(sc-sc_sens.desc, lid open,
 +   sizeof(sc-sc_sens.desc));
 +   sc-sc_sens.type = SENSOR_INDICATOR;
 +   sensor_attach(sc-sc_sensdev, sc-sc_sens);
 +   sensordev_install(sc-sc_sensdev);
 +
 +   aml_evalinteger(sc-sc_acpi, sc-sc_devnode,
 +   _LID, 0, NULL, lid_open);
 +   sc-sc_sens.value = lid_open;
 +   }
 +
 aml_register_notify(sc-sc_devnode, aa-aaa_dev, acpibtn_notify,
 sc, ACPIDEV_NOPOLL);
  }
 @@ -179,11 +197,12 @@
  * _LID method.  0 means the lid is closed and we
  * should go to sleep.
  */
 -   if (lid_suspend == 0)
 -   break;
 if (aml_evalinteger(sc-sc_acpi, sc-sc_devnode,
 _LID, 0, NULL, lid))
 return (0);
 +   sc-sc_sens.value = lid;
 +   if (lid_suspend == 0)
 +   break;

Probably a stupid question, but is it safe to call aml_evalinteger()
when we're suspending (lid_suspend!=0)?

 if (lid == 0)
 goto sleep;
  #endif /* SMALL_KERNEL */


--
  WBR,
  Vadim Zhukov



Re: add lid status sensor to acpibtn

2013-08-14 Thread Landry Breuil
On Wed, Aug 14, 2013 at 01:55:27PM +0400, Vadim Zhukov wrote:
 2013/8/13 Landry Breuil lan...@rhaalovely.net:
  On Mon, Aug 12, 2013 at 06:01:25PM +0200, David Coppa wrote:
  On Mon, Aug 12, 2013 at 5:40 PM, Landry Breuil lan...@rhaalovely.net 
  wrote:
   * _LID method.  0 means the lid is closed and we
   * should go to sleep.
   */
  -   if (lid_suspend == 0)
  -   break;
  if (aml_evalinteger(sc-sc_acpi, sc-sc_devnode,
  _LID, 0, NULL, lid))
  return (0);
  +   sc-sc_sens.value = lid;
  +   if (lid_suspend == 0)
  +   break;
 
 Probably a stupid question, but is it safe to call aml_evalinteger()
 when we're suspending (lid_suspend!=0)?

In that context, lid_suspend maps to machdep.lidsuspend, which means 'i
want to suspend if the lid is being closed'. The actual 'going to sleep'
is done just below, so WRT aml_evalinteger it changes nothing.

  if (lid == 0)
  goto sleep;
   #endif /* SMALL_KERNEL */

Landry



Re: add lid status sensor to acpibtn

2013-08-13 Thread Mark Kettenis
 Date: Tue, 13 Aug 2013 00:00:19 +0200
 From: Landry Breuil lan...@rhaalovely.net
 
 On Mon, Aug 12, 2013 at 06:01:25PM +0200, David Coppa wrote:
  On Mon, Aug 12, 2013 at 5:40 PM, Landry Breuil lan...@rhaalovely.net 
  wrote:
   Hi,
  
   this diff adds a sensor for acpibtn to show lid status. This allows
   userland to monitor/react on lid close/open events, in case one is not
   using machdep.lidsuspend. I know sysutils/upower can make use of this, i
   just need to add the corresponding code there.
  
   comments ? I wonder if/how the case when aml_evalinteger() fails should
   be handled in acpibtn_attach()..
  
  Where's the diff?
  
 Err.. here it is.

ok kettenis@

Wonder if this should change the description to reflect the lid status
like acpidock0 does for the dock status.  But that can be done as a
seperate diff.


 Index: acpibtn.c
 ===
 RCS file: /cvs/src/sys/dev/acpi/acpibtn.c,v
 retrieving revision 1.34
 diff -u -r1.34 acpibtn.c
 --- acpibtn.c 2 Jan 2011 04:56:57 -   1.34
 +++ acpibtn.c 12 Aug 2013 15:35:35 -
 @@ -46,6 +46,9 @@
   struct acpi_softc   *sc_acpi;
   struct aml_node *sc_devnode;
  
 + struct ksensor  sc_sens;
 + struct ksensordev   sc_sensdev;
 +
   int sc_btn_type;
  #define  ACPIBTN_UNKNOWN 0
  #define ACPIBTN_LID  1
 @@ -123,6 +126,7 @@
   struct acpibtn_softc*sc = (struct acpibtn_softc *)self;
   struct acpi_attach_args *aa = aux;
   struct acpi_lid *lid;
 + int64_t lid_open;
  
   sc-sc_acpi = (struct acpi_softc *)parent;
   sc-sc_devnode = aa-aaa_node;
 @@ -143,6 +147,20 @@
  
   printf(: %s\n, sc-sc_devnode-name);
  
 + if (sc-sc_btn_type == ACPIBTN_LID) {
 + strlcpy(sc-sc_sensdev.xname, DEVNAME(sc),
 + sizeof(sc-sc_sensdev.xname));
 + strlcpy(sc-sc_sens.desc, lid open,
 + sizeof(sc-sc_sens.desc));
 + sc-sc_sens.type = SENSOR_INDICATOR;
 + sensor_attach(sc-sc_sensdev, sc-sc_sens);
 + sensordev_install(sc-sc_sensdev);
 +
 + aml_evalinteger(sc-sc_acpi, sc-sc_devnode,
 + _LID, 0, NULL, lid_open);
 + sc-sc_sens.value = lid_open;
 + }
 +
   aml_register_notify(sc-sc_devnode, aa-aaa_dev, acpibtn_notify,
   sc, ACPIDEV_NOPOLL);
  }
 @@ -179,11 +197,12 @@
* _LID method.  0 means the lid is closed and we
* should go to sleep.
*/
 - if (lid_suspend == 0)
 - break;
   if (aml_evalinteger(sc-sc_acpi, sc-sc_devnode,
   _LID, 0, NULL, lid))
   return (0);
 + sc-sc_sens.value = lid;
 + if (lid_suspend == 0)
 + break;
   if (lid == 0)
   goto sleep;
  #endif /* SMALL_KERNEL */
 
 



add lid status sensor to acpibtn

2013-08-12 Thread Landry Breuil
Hi,

this diff adds a sensor for acpibtn to show lid status. This allows
userland to monitor/react on lid close/open events, in case one is not
using machdep.lidsuspend. I know sysutils/upower can make use of this, i
just need to add the corresponding code there.

comments ? I wonder if/how the case when aml_evalinteger() fails should
be handled in acpibtn_attach()..

Tests of course welcome, only tested on i386/MSI Wind U100 here where LID is 
acpibtn0.

Landry



Re: add lid status sensor to acpibtn

2013-08-12 Thread David Coppa
On Mon, Aug 12, 2013 at 5:40 PM, Landry Breuil lan...@rhaalovely.net wrote:
 Hi,

 this diff adds a sensor for acpibtn to show lid status. This allows
 userland to monitor/react on lid close/open events, in case one is not
 using machdep.lidsuspend. I know sysutils/upower can make use of this, i
 just need to add the corresponding code there.

 comments ? I wonder if/how the case when aml_evalinteger() fails should
 be handled in acpibtn_attach()..

Where's the diff?



Re: add lid status sensor to acpibtn

2013-08-12 Thread Landry Breuil
On Mon, Aug 12, 2013 at 06:01:25PM +0200, David Coppa wrote:
 On Mon, Aug 12, 2013 at 5:40 PM, Landry Breuil lan...@rhaalovely.net wrote:
  Hi,
 
  this diff adds a sensor for acpibtn to show lid status. This allows
  userland to monitor/react on lid close/open events, in case one is not
  using machdep.lidsuspend. I know sysutils/upower can make use of this, i
  just need to add the corresponding code there.
 
  comments ? I wonder if/how the case when aml_evalinteger() fails should
  be handled in acpibtn_attach()..
 
 Where's the diff?
 
Err.. here it is.

Index: acpibtn.c
===
RCS file: /cvs/src/sys/dev/acpi/acpibtn.c,v
retrieving revision 1.34
diff -u -r1.34 acpibtn.c
--- acpibtn.c   2 Jan 2011 04:56:57 -   1.34
+++ acpibtn.c   12 Aug 2013 15:35:35 -
@@ -46,6 +46,9 @@
struct acpi_softc   *sc_acpi;
struct aml_node *sc_devnode;
 
+   struct ksensor  sc_sens;
+   struct ksensordev   sc_sensdev;
+
int sc_btn_type;
 #defineACPIBTN_UNKNOWN 0
 #define ACPIBTN_LID1
@@ -123,6 +126,7 @@
struct acpibtn_softc*sc = (struct acpibtn_softc *)self;
struct acpi_attach_args *aa = aux;
struct acpi_lid *lid;
+   int64_t lid_open;
 
sc-sc_acpi = (struct acpi_softc *)parent;
sc-sc_devnode = aa-aaa_node;
@@ -143,6 +147,20 @@
 
printf(: %s\n, sc-sc_devnode-name);
 
+   if (sc-sc_btn_type == ACPIBTN_LID) {
+   strlcpy(sc-sc_sensdev.xname, DEVNAME(sc),
+   sizeof(sc-sc_sensdev.xname));
+   strlcpy(sc-sc_sens.desc, lid open,
+   sizeof(sc-sc_sens.desc));
+   sc-sc_sens.type = SENSOR_INDICATOR;
+   sensor_attach(sc-sc_sensdev, sc-sc_sens);
+   sensordev_install(sc-sc_sensdev);
+
+   aml_evalinteger(sc-sc_acpi, sc-sc_devnode,
+   _LID, 0, NULL, lid_open);
+   sc-sc_sens.value = lid_open;
+   }
+
aml_register_notify(sc-sc_devnode, aa-aaa_dev, acpibtn_notify,
sc, ACPIDEV_NOPOLL);
 }
@@ -179,11 +197,12 @@
 * _LID method.  0 means the lid is closed and we
 * should go to sleep.
 */
-   if (lid_suspend == 0)
-   break;
if (aml_evalinteger(sc-sc_acpi, sc-sc_devnode,
_LID, 0, NULL, lid))
return (0);
+   sc-sc_sens.value = lid;
+   if (lid_suspend == 0)
+   break;
if (lid == 0)
goto sleep;
 #endif /* SMALL_KERNEL */