[haiku-commits] haiku: hrev46280 - src/add-ons/kernel/drivers/power/acpi_button build/jam/packages

  • From: korli@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 23 Oct 2013 19:10:04 +0200 (CEST)

hrev46280 adds 1 changeset to branch 'master'
old head: 6c1a6532d5429b1dd5c23760b5f6dcd31cb2dbd7
new head: 1926af4fde4ff5510ee7ba89f03f739cc21f9e2f
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=1926af4+%5E6c1a653

----------------------------------------------------------------------------

1926af4: acpi_button: migrated to the new driver API.
  
  * HaikuImage: SYSTEM_ADD_ONS_DRIVERS_POWER is now used for new drivers.

                                   [ Jérôme Duval <jerome.duval@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev46280
Commit:      1926af4fde4ff5510ee7ba89f03f739cc21f9e2f
URL:         http://cgit.haiku-os.org/haiku/commit/?id=1926af4
Author:      Jérôme Duval <jerome.duval@xxxxxxxxx>
Date:        Wed Oct 23 17:07:22 2013 UTC

----------------------------------------------------------------------------

4 files changed, 267 insertions(+), 5 deletions(-)
build/jam/images/HaikuImage                      |   2 +-
build/jam/packages/Haiku                         |   3 +-
.../kernel/drivers/power/acpi_button/Jamfile     |   3 +-
.../drivers/power/acpi_button/acpi_button.cpp    | 264 +++++++++++++++++++

----------------------------------------------------------------------------

diff --git a/build/jam/images/HaikuImage b/build/jam/images/HaikuImage
index bd5a217..56f4cbe 100644
--- a/build/jam/images/HaikuImage
+++ b/build/jam/images/HaikuImage
@@ -202,7 +202,7 @@ SYSTEM_ADD_ONS_DRIVERS_NET = [ FFilterByBuildFeatures
        #usb_beceemwmx@gpl
 ] ;
 SYSTEM_ADD_ONS_DRIVERS_POWER = [ FFilterByBuildFeatures
-       acpi_button@x86,x86_64
+       acpi_battery@x86 acpi_button@x86,x86_64
 ] ;
 SYSTEM_ADD_ONS_BUS_MANAGERS = [ FFilterByBuildFeatures
        ata@ata pci ps2@x86,x86_64 isa@x86,x86_64
diff --git a/build/jam/packages/Haiku b/build/jam/packages/Haiku
index 26c6f62..44d208a 100644
--- a/build/jam/packages/Haiku
+++ b/build/jam/packages/Haiku
@@ -61,7 +61,7 @@ if $(TARGET_ARCH) = x86 || $(TARGET_ARCH) = x86_64 {
 AddNewDriversToPackage disk scsi       : scsi_cd scsi_disk ;
 AddNewDriversToPackage disk virtual : virtio_block ;
 AddNewDriversToPackage power           : enhanced_speedstep@x86 ;
-AddNewDriversToPackage power           : acpi_battery@x86 ;
+AddNewDriversToPackage power           : $(SYSTEM_ADD_ONS_DRIVERS_POWER) ;
 #AddNewDriversToPackage display                : display_controls@x86 ;
 
 # legacy drivers
@@ -81,7 +81,6 @@ AddDriversToPackage input                     : ps2_hid 
usb_hid wacom ;
 AddDriversToPackage misc                       : <driver>poke <driver>mem ;
 AddDriversToPackage net                                : 
$(SYSTEM_ADD_ONS_DRIVERS_NET) ;
 AddDriversToPackage ports                      : usb_serial ;
-AddDriversToPackage power                      : 
$(SYSTEM_ADD_ONS_DRIVERS_POWER) ;
 
 # kernel
 AddFilesToPackage : <revisioned>kernel_$(TARGET_ARCH) ;
diff --git a/src/add-ons/kernel/drivers/power/acpi_button/Jamfile 
b/src/add-ons/kernel/drivers/power/acpi_button/Jamfile
index de2c099..4c1b115 100644
--- a/src/add-ons/kernel/drivers/power/acpi_button/Jamfile
+++ b/src/add-ons/kernel/drivers/power/acpi_button/Jamfile
@@ -9,8 +9,7 @@ if $(TARGET_PLATFORM) != haiku {
 }
 
 KernelAddon acpi_button :
-       acpi_button.c
+       acpi_button.cpp
        ;
 
 Depends acpi_button : acpi ;
-
diff --git a/src/add-ons/kernel/drivers/power/acpi_button/acpi_button.cpp 
b/src/add-ons/kernel/drivers/power/acpi_button/acpi_button.cpp
new file mode 100644
index 0000000..f9f9c4a
--- /dev/null
+++ b/src/add-ons/kernel/drivers/power/acpi_button/acpi_button.cpp
@@ -0,0 +1,264 @@
+/*
+ * Copyright 2013, Jérôme Duval, korli@xxxxxxxxxxxxxxxx.
+ * Copyright 2005, Nathan Whitehorn.
+ *
+ * Distributed under the terms of the MIT License.
+ *
+ * ACPI Button Driver, used to get info on power buttons, etc.
+ */
+
+
+#include <ACPI.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+
+#define ACPI_BUTTON_MODULE_NAME "drivers/power/acpi_button/driver_v1"
+
+#define ACPI_BUTTON_DEVICE_MODULE_NAME "drivers/power/acpi_button/device_v1"
+
+
+static device_manager_info *sDeviceManager;
+static struct acpi_module_info *sAcpi;
+
+
+typedef struct acpi_ns_device_info {
+       device_node *node;
+       acpi_device_module_info *acpi;
+       acpi_device acpi_cookie;
+       uint32 type;
+} acpi_button_device_info;
+
+
+//     #pragma mark - device module API
+
+
+static status_t
+acpi_button_init_device(void *_cookie, void **cookie)
+{
+       device_node *node = (device_node *)_cookie;
+       acpi_button_device_info *device;
+       device_node *parent;
+
+       device = (acpi_button_device_info *)calloc(1, sizeof(*device));
+       if (device == NULL)
+               return B_NO_MEMORY;
+
+       device->node = node;
+
+       parent = sDeviceManager->get_parent_node(node);
+       sDeviceManager->get_driver(parent, (driver_module_info **)&device->acpi,
+               (void **)&device->acpi_cookie);
+       sDeviceManager->put_node(parent);
+
+       *cookie = device;
+       return B_OK;
+}
+
+
+static void
+acpi_button_uninit_device(void *_cookie)
+{
+       acpi_button_device_info *device = (acpi_button_device_info *)_cookie;
+       free(device);
+}
+
+
+static status_t
+acpi_button_open(void *_cookie, const char *path, int flags, void** cookie)
+{
+       acpi_button_device_info *device = (acpi_button_device_info *)_cookie;
+       if (strcmp(path,"power/button/power") == 0)
+               device->type = ACPI_EVENT_POWER_BUTTON;
+       else if (strcmp(path,"power/button/sleep") == 0)
+               device->type = ACPI_EVENT_SLEEP_BUTTON;
+       else
+               return B_ERROR;
+
+       sAcpi->enable_fixed_event(device->type);
+
+       *cookie = device;
+       return B_OK;
+}
+
+
+static status_t
+acpi_button_read(void* _cookie, off_t position, void *buf, size_t* num_bytes)
+{
+       acpi_button_device_info* device = (acpi_button_device_info*)_cookie;
+       if (*num_bytes < 1)
+               return B_IO_ERROR;
+
+       *((uint8 *)(buf)) = sAcpi->fixed_event_status(device->type) ? 1 : 0;
+
+       sAcpi->reset_fixed_event(device->type);
+
+       *num_bytes = 1;
+       return B_OK;
+}
+
+
+static status_t
+acpi_button_write(void* cookie, off_t position, const void* buffer, size_t* 
num_bytes)
+{
+       return B_ERROR;
+}
+
+
+static status_t
+acpi_button_control(void* _cookie, uint32 op, void* arg, size_t len)
+{
+       return B_ERROR;
+}
+
+
+static status_t
+acpi_button_close (void* cookie)
+{
+       acpi_button_device_info* device = (acpi_button_device_info*)cookie;
+       sAcpi->disable_fixed_event(device->type);
+       return B_OK;
+}
+
+
+static status_t
+acpi_button_free (void* cookie)
+{
+       return B_OK;
+}
+
+
+//     #pragma mark - driver module API
+
+
+static float
+acpi_button_support(device_node *parent)
+{
+       const char *bus;
+       uint32 device_type;
+       const char *hid;
+
+       dprintf("acpi_button_support\n");
+
+       // make sure parent is really the ACPI bus manager
+       if (sDeviceManager->get_attr_string(parent, B_DEVICE_BUS, &bus, false))
+               return -1;
+
+       if (strcmp(bus, "acpi"))
+               return 0.0;
+
+       // check whether it's really a device
+       if (sDeviceManager->get_attr_uint32(parent, ACPI_DEVICE_TYPE_ITEM,
+               &device_type, false) != B_OK || device_type != 
ACPI_TYPE_DEVICE) {
+               return 0.0;
+       }
+
+       // check whether it's a lid device
+       if (sDeviceManager->get_attr_string(parent, ACPI_DEVICE_HID_ITEM, &hid,
+               false) != B_OK || (strcmp(hid, "PNP0C0C") && strcmp(hid, 
"ACPI_FPB")
+                       && strcmp(hid, "PNP0C0E") && strcmp(hid, "ACPI_FSB"))) {
+               return 0.0;
+       }
+
+       dprintf("acpi_button_support lid device found\n");
+
+       return 0.6;
+}
+
+
+static status_t
+acpi_button_register_device(device_node *node)
+{
+       device_attr attrs[] = {
+               { B_DEVICE_PRETTY_NAME, B_STRING_TYPE, { string: "ACPI Button" 
}},
+               { NULL }
+       };
+
+       return sDeviceManager->register_node(node, ACPI_BUTTON_MODULE_NAME, 
attrs, NULL, NULL);
+}
+
+
+static status_t
+acpi_button_init_driver(device_node *node, void **_driverCookie)
+{
+       *_driverCookie = node;
+       return B_OK;
+}
+
+
+static void
+acpi_button_uninit_driver(void *driverCookie)
+{
+}
+
+
+static status_t
+acpi_button_register_child_devices(void *_cookie)
+{
+       device_node *node = (device_node*)_cookie;
+
+       dprintf("acpi_button_register_child_devices\n");
+
+       status_t status = sDeviceManager->publish_device(node,
+               "power/button/power", ACPI_BUTTON_DEVICE_MODULE_NAME);
+       if (status != B_OK)
+               return status;
+
+       return sDeviceManager->publish_device(node, "power/button/sleep",
+               ACPI_BUTTON_DEVICE_MODULE_NAME);
+}
+
+
+module_dependency module_dependencies[] = {
+       { B_DEVICE_MANAGER_MODULE_NAME, (module_info **)&sDeviceManager },
+       { B_ACPI_MODULE_NAME, (module_info **)&sAcpi },
+       {}
+};
+
+
+driver_module_info acpi_button_driver_module = {
+       {
+               ACPI_BUTTON_MODULE_NAME,
+               0,
+               NULL
+       },
+
+       acpi_button_support,
+       acpi_button_register_device,
+       acpi_button_init_driver,
+       acpi_button_uninit_driver,
+       acpi_button_register_child_devices,
+       NULL,   // rescan
+       NULL,   // removed
+};
+
+
+struct device_module_info acpi_button_device_module = {
+       {
+               ACPI_BUTTON_DEVICE_MODULE_NAME,
+               0,
+               NULL
+       },
+
+       acpi_button_init_device,
+       acpi_button_uninit_device,
+       NULL,
+
+       acpi_button_open,
+       acpi_button_close,
+       acpi_button_free,
+       acpi_button_read,
+       acpi_button_write,
+       NULL,
+       acpi_button_control,
+
+       NULL,
+       NULL
+};
+
+module_info *modules[] = {
+       (module_info *)&acpi_button_driver_module,
+       (module_info *)&acpi_button_device_module,
+       NULL
+};


Other related posts:

  • » [haiku-commits] haiku: hrev46280 - src/add-ons/kernel/drivers/power/acpi_button build/jam/packages - korli