diff --git a/src/add-ons/kernel/drivers/Jamfile b/src/add-ons/kernel/drivers/Jamfile index a9ba3668c3..4fb4f596e1 100644 --- a/src/add-ons/kernel/drivers/Jamfile +++ b/src/add-ons/kernel/drivers/Jamfile @@ -9,5 +9,6 @@ SubInclude OBOS_TOP src add-ons kernel drivers input ; SubInclude OBOS_TOP src add-ons kernel drivers graphics ; SubInclude OBOS_TOP src add-ons kernel drivers misc ; SubInclude OBOS_TOP src add-ons kernel drivers network ; +SubInclude OBOS_TOP src add-ons kernel drivers power ; SubInclude OBOS_TOP src add-ons kernel drivers random ; SubInclude OBOS_TOP src add-ons kernel drivers tty ; diff --git a/src/add-ons/kernel/drivers/power/Jamfile b/src/add-ons/kernel/drivers/power/Jamfile new file mode 100644 index 0000000000..f6b526ef5f --- /dev/null +++ b/src/add-ons/kernel/drivers/power/Jamfile @@ -0,0 +1,3 @@ +SubDir OBOS_TOP src add-ons kernel drivers power ; + +SubInclude OBOS_TOP src add-ons kernel drivers power acpi_button ; diff --git a/src/add-ons/kernel/drivers/power/acpi_button/Jamfile b/src/add-ons/kernel/drivers/power/acpi_button/Jamfile new file mode 100644 index 0000000000..6e0f6eb0fa --- /dev/null +++ b/src/add-ons/kernel/drivers/power/acpi_button/Jamfile @@ -0,0 +1,16 @@ +SubDir OBOS_TOP src add-ons kernel drivers power acpi_button ; + +R5KernelAddon acpi_button : kernel drivers bin : + acpi_button.c + ; + +Depends acpi_button : acpi ; + +# Link driver(s) to kernel/drivers/dev/power +{ + local dir = [ FDirName $(OBOS_ADDON_DIR) kernel drivers dev power ] ; + + local instDriver = acpi_button ; + MakeLocate $(instDriver) : $(dir) ; + RelSymLink $(instDriver) : acpi_button ; +} diff --git a/src/add-ons/kernel/drivers/power/acpi_button/acpi_button.c b/src/add-ons/kernel/drivers/power/acpi_button/acpi_button.c new file mode 100644 index 0000000000..cb45d766b3 --- /dev/null +++ b/src/add-ons/kernel/drivers/power/acpi_button/acpi_button.c @@ -0,0 +1,159 @@ +/* ++++++++++ + ACPI Button Driver, used to get info on power buttons, etc. ++++++ */ + +#include +#include +#include + +#include + +acpi_module_info *acpi; + +status_t +init_hardware (void) +{ + return B_OK; +} + +status_t +init_driver (void) +{ + get_module(B_ACPI_MODULE_NAME,(module_info **)&acpi); + return B_OK; +} + +void +uninit_driver (void) +{ + put_module(B_ACPI_MODULE_NAME); +} + + +/* ---------- + acpi_button_open - handle open() calls +----- */ + +static status_t +acpi_button_open (const char *name, uint32 flags, void** cookie) +{ + return B_OK; +} + + +/* ---------- + acpi_button_read - handle read() calls +----- */ + +static status_t +acpi_button_read (void* cookie, off_t position, void *buf, size_t* num_bytes) +{ + *num_bytes = 0; /* tell caller nothing was read */ + return B_IO_ERROR; +} + + +/* ---------- + acpi_button_write - handle write() calls +----- */ + +static status_t +acpi_button_write (void* cookie, off_t position, const void* buffer, size_t* num_bytes) +{ + *num_bytes = 0; /* tell caller nothing was written */ + return B_IO_ERROR; +} + + +/* ---------- + acpi_button_control - handle ioctl calls +----- */ + +static status_t +acpi_button_control (void* cookie, uint32 op, void* arg, size_t len) +{ + switch (op) { + case ~ACPI_BITREG_POWER_BUTTON_ENABLE: + case ~ACPI_BITREG_SLEEP_BUTTON_ENABLE: + case ~ACPI_BITREG_POWER_BUTTON_STATUS: + case ~ACPI_BITREG_SLEEP_BUTTON_STATUS: + acpi->write_acpi_reg(op,*((uint32 *)(arg))); + break; + case ACPI_BITREG_POWER_BUTTON_STATUS: + case ACPI_BITREG_SLEEP_BUTTON_STATUS: + *((uint32 *)(arg)) = acpi->read_acpi_reg(op); + break; + default: + return B_ERROR; + } + return B_OK; +} + + +/* ---------- + acpi_button_close - handle close() calls +----- */ + +static status_t +acpi_button_close (void* cookie) +{ + return B_OK; +} + + +/* ----- + acpi_button_free - called after the last device is closed, and after + all i/o is complete. +----- */ +static status_t +acpi_button_free (void* cookie) +{ + return B_OK; +} + + +/* ----- + null-terminated array of device names supported by this driver +----- */ + +static const char *acpi_button_name[] = { + "power/acpi_button", + NULL +}; + +/* ----- + function pointers for the device hooks entry points +----- */ + +device_hooks acpi_button_hooks = { + acpi_button_open, /* -> open entry point */ + acpi_button_close, /* -> close entry point */ + acpi_button_free, /* -> free cookie */ + acpi_button_control, /* -> control entry point */ + acpi_button_read, /* -> read entry point */ + acpi_button_write, /* -> write entry point */ + NULL, NULL, NULL, NULL +}; + +/* ---------- + publish_devices - return a null-terminated array of devices + supported by this driver. +----- */ + +const char** +publish_devices() +{ + return acpi_button_name; +} + +/* ---------- + find_device - return ptr to device hooks structure for a + given device name +----- */ + +device_hooks* +find_device(const char* name) +{ + return &acpi_button_hooks; +} +