acpi_panasonic.c (132501) | acpi_panasonic.c (132611) |
---|---|
1/*- 2 * Copyright (c) 2003 OGAWA Takaya <t-ogawa@triaez.kaisei.org> 3 * Copyright (c) 2004 Yoshihiro TAKAHASHI <nyan@FreeBSD.org> 4 * All rights Reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 13 unchanged lines hidden (view full) --- 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 */ 28 29#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2003 OGAWA Takaya <t-ogawa@triaez.kaisei.org> 3 * Copyright (c) 2004 Yoshihiro TAKAHASHI <nyan@FreeBSD.org> 4 * All rights Reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 13 unchanged lines hidden (view full) --- 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/sys/dev/acpi_support/acpi_panasonic.c 132501 2004-07-21 14:47:54Z nyan $"); | 30__FBSDID("$FreeBSD: head/sys/dev/acpi_support/acpi_panasonic.c 132611 2004-07-24 20:40:02Z njl $"); |
31 32#include "opt_acpi.h" 33#include <sys/param.h> 34#include <sys/kernel.h> 35#include <sys/malloc.h> 36#include <sys/module.h> 37#include <sys/bus.h> 38 39#include "acpi.h" 40#include <dev/acpica/acpivar.h> 41 42/* Debug */ 43#undef ACPI_PANASONIC_DEBUG 44 45/* Operations */ 46#define HKEY_SET 0 47#define HKEY_GET 1 48 49/* Functions */ | 31 32#include "opt_acpi.h" 33#include <sys/param.h> 34#include <sys/kernel.h> 35#include <sys/malloc.h> 36#include <sys/module.h> 37#include <sys/bus.h> 38 39#include "acpi.h" 40#include <dev/acpica/acpivar.h> 41 42/* Debug */ 43#undef ACPI_PANASONIC_DEBUG 44 45/* Operations */ 46#define HKEY_SET 0 47#define HKEY_GET 1 48 49/* Functions */ |
50#define HKEY_REG_LCD_BRIGHTNESS 0x04 51#define HKEY_REG_SOUND_MUTE 0x08 | 50#define HKEY_REG_LCD_BRIGHTNESS 0x04 51#define HKEY_REG_SOUND_MUTE 0x08 |
52 53/* Field definitions */ 54#define HKEY_LCD_BRIGHTNESS_BITS 4 55#define HKEY_LCD_BRIGHTNESS_DIV ((1 << HKEY_LCD_BRIGHTNESS_BITS) - 1) 56 57struct acpi_panasonic_softc { 58 device_t dev; 59 ACPI_HANDLE handle; --- 4 unchanged lines hidden (view full) --- 64 65/* Prototype for HKEY functions for getting/setting a value. */ 66typedef int hkey_fn_t(ACPI_HANDLE, int, UINT32 *); 67 68static int acpi_panasonic_probe(device_t dev); 69static int acpi_panasonic_attach(device_t dev); 70static int acpi_panasonic_detach(device_t dev); 71static int acpi_panasonic_sysctl(SYSCTL_HANDLER_ARGS); | 52 53/* Field definitions */ 54#define HKEY_LCD_BRIGHTNESS_BITS 4 55#define HKEY_LCD_BRIGHTNESS_DIV ((1 << HKEY_LCD_BRIGHTNESS_BITS) - 1) 56 57struct acpi_panasonic_softc { 58 device_t dev; 59 ACPI_HANDLE handle; --- 4 unchanged lines hidden (view full) --- 64 65/* Prototype for HKEY functions for getting/setting a value. */ 66typedef int hkey_fn_t(ACPI_HANDLE, int, UINT32 *); 67 68static int acpi_panasonic_probe(device_t dev); 69static int acpi_panasonic_attach(device_t dev); 70static int acpi_panasonic_detach(device_t dev); 71static int acpi_panasonic_sysctl(SYSCTL_HANDLER_ARGS); |
72static ACPI_INTEGER acpi_panasonic_sinf(ACPI_HANDLE h, ACPI_INTEGER index); | 72static ACPI_INTEGER acpi_panasonic_sinf(ACPI_HANDLE h, ACPI_INTEGER index); |
73static void acpi_panasonic_sset(ACPI_HANDLE h, ACPI_INTEGER index, | 73static void acpi_panasonic_sset(ACPI_HANDLE h, ACPI_INTEGER index, |
74 ACPI_INTEGER val); 75static hkey_fn_t hkey_lcd_brightness_max; 76static hkey_fn_t hkey_lcd_brightness; 77static hkey_fn_t hkey_sound_mute; | 74 ACPI_INTEGER val); |
78static int acpi_panasonic_hkey_event(struct acpi_panasonic_softc *sc, | 75static int acpi_panasonic_hkey_event(struct acpi_panasonic_softc *sc, |
79 ACPI_HANDLE h, UINT32 *arg); | 76 ACPI_HANDLE h, UINT32 *arg); |
80static void acpi_panasonic_hkey_action(struct acpi_panasonic_softc *sc, | 77static void acpi_panasonic_hkey_action(struct acpi_panasonic_softc *sc, |
81 ACPI_HANDLE h, UINT32 key); | 78 ACPI_HANDLE h, UINT32 key); |
82static void acpi_panasonic_notify(ACPI_HANDLE h, UINT32 notify, | 79static void acpi_panasonic_notify(ACPI_HANDLE h, UINT32 notify, |
83 void *context); | 80 void *context); |
84 | 81 |
82static hkey_fn_t hkey_lcd_brightness_max; 83static hkey_fn_t hkey_lcd_brightness; 84static hkey_fn_t hkey_sound_mute; 85static int lcd_brightness_max = 255; 86 |
|
85/* Table of sysctl names and HKEY functions to call. */ 86static struct { 87 char *name; 88 hkey_fn_t *handler; 89} sysctl_table[] = { 90 /* name, handler */ 91 {"lcd_brightness_max", hkey_lcd_brightness_max}, 92 {"lcd_brightness", hkey_lcd_brightness}, --- 13 unchanged lines hidden (view full) --- 106 "acpi_panasonic", 107 acpi_panasonic_methods, 108 sizeof(struct acpi_panasonic_softc), 109}; 110 111static devclass_t acpi_panasonic_devclass; 112 113DRIVER_MODULE(acpi_panasonic, acpi, acpi_panasonic_driver, | 87/* Table of sysctl names and HKEY functions to call. */ 88static struct { 89 char *name; 90 hkey_fn_t *handler; 91} sysctl_table[] = { 92 /* name, handler */ 93 {"lcd_brightness_max", hkey_lcd_brightness_max}, 94 {"lcd_brightness", hkey_lcd_brightness}, --- 13 unchanged lines hidden (view full) --- 108 "acpi_panasonic", 109 acpi_panasonic_methods, 110 sizeof(struct acpi_panasonic_softc), 111}; 112 113static devclass_t acpi_panasonic_devclass; 114 115DRIVER_MODULE(acpi_panasonic, acpi, acpi_panasonic_driver, |
114 acpi_panasonic_devclass, 0, 0); | 116 acpi_panasonic_devclass, 0, 0); |
115MODULE_DEPEND(acpi_panasonic, acpi, 1, 1, 1); 116 | 117MODULE_DEPEND(acpi_panasonic, acpi, 1, 1, 1); 118 |
117static int lcd_brightness_max = 255; 118 | |
119static int 120acpi_panasonic_probe(device_t dev) 121{ 122 static char *mat_ids[] = { "MAT0019", NULL }; 123 124 if (acpi_disabled("panasonic") || 125 ACPI_ID_PROBE(device_get_parent(dev), dev, mat_ids) == NULL || 126 device_get_unit(dev) != 0) --- 19 unchanged lines hidden (view full) --- 146 147 /* Build sysctl tree */ 148 sysctl_ctx_init(&sc->sysctl_ctx); 149 sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx, 150 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree), OID_AUTO, 151 "panasonic", CTLFLAG_RD, 0, ""); 152 for (i = 0; sysctl_table[i].name != NULL; i++) { 153 SYSCTL_ADD_PROC(&sc->sysctl_ctx, | 119static int 120acpi_panasonic_probe(device_t dev) 121{ 122 static char *mat_ids[] = { "MAT0019", NULL }; 123 124 if (acpi_disabled("panasonic") || 125 ACPI_ID_PROBE(device_get_parent(dev), dev, mat_ids) == NULL || 126 device_get_unit(dev) != 0) --- 19 unchanged lines hidden (view full) --- 146 147 /* Build sysctl tree */ 148 sysctl_ctx_init(&sc->sysctl_ctx); 149 sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx, 150 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree), OID_AUTO, 151 "panasonic", CTLFLAG_RD, 0, ""); 152 for (i = 0; sysctl_table[i].name != NULL; i++) { 153 SYSCTL_ADD_PROC(&sc->sysctl_ctx, |
154 SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO, 155 sysctl_table[i].name, 156 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY, 157 sc, i, acpi_panasonic_sysctl, "I", ""); | 154 SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO, 155 sysctl_table[i].name, 156 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY, 157 sc, i, acpi_panasonic_sysctl, "I", ""); |
158 } 159 160#if 0 161 /* Activate hotkeys */ 162 status = AcpiEvaluateObject(sc->handle, "", NULL, NULL); 163 if (ACPI_FAILURE(status)) { 164 device_printf(dev, "enable FN keys failed\n"); 165 sysctl_ctx_free(&sc->sysctl_ctx); 166 return (ENXIO); 167 } 168#endif 169 170 /* Handle notifies */ 171 status = AcpiInstallNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY, | 158 } 159 160#if 0 161 /* Activate hotkeys */ 162 status = AcpiEvaluateObject(sc->handle, "", NULL, NULL); 163 if (ACPI_FAILURE(status)) { 164 device_printf(dev, "enable FN keys failed\n"); 165 sysctl_ctx_free(&sc->sysctl_ctx); 166 return (ENXIO); 167 } 168#endif 169 170 /* Handle notifies */ 171 status = AcpiInstallNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY, |
172 acpi_panasonic_notify, sc); | 172 acpi_panasonic_notify, sc); |
173 if (ACPI_FAILURE(status)) { 174 device_printf(dev, "couldn't install notify handler - %s\n", | 173 if (ACPI_FAILURE(status)) { 174 device_printf(dev, "couldn't install notify handler - %s\n", |
175 AcpiFormatException(status)); | 175 AcpiFormatException(status)); |
176 sysctl_ctx_free(&sc->sysctl_ctx); 177 return (ENXIO); 178 } 179 180 return (0); 181} 182 183static int 184acpi_panasonic_detach(device_t dev) 185{ 186 struct acpi_panasonic_softc *sc; 187 188 sc = device_get_softc(dev); 189 190 /* Remove notify handler */ 191 AcpiRemoveNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY, | 176 sysctl_ctx_free(&sc->sysctl_ctx); 177 return (ENXIO); 178 } 179 180 return (0); 181} 182 183static int 184acpi_panasonic_detach(device_t dev) 185{ 186 struct acpi_panasonic_softc *sc; 187 188 sc = device_get_softc(dev); 189 190 /* Remove notify handler */ 191 AcpiRemoveNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY, |
192 acpi_panasonic_notify); | 192 acpi_panasonic_notify); |
193 194 /* Free sysctl tree */ 195 sysctl_ctx_free(&sc->sysctl_ctx); 196 197 return (0); 198} 199 200static int --- 109 unchanged lines hidden (view full) --- 310 break; 311 } 312 313 return (0); 314} 315 316static int 317acpi_panasonic_hkey_event(struct acpi_panasonic_softc *sc, ACPI_HANDLE h, | 193 194 /* Free sysctl tree */ 195 sysctl_ctx_free(&sc->sysctl_ctx); 196 197 return (0); 198} 199 200static int --- 109 unchanged lines hidden (view full) --- 310 break; 311 } 312 313 return (0); 314} 315 316static int 317acpi_panasonic_hkey_event(struct acpi_panasonic_softc *sc, ACPI_HANDLE h, |
318 UINT32 *arg) | 318 UINT32 *arg) |
319{ 320 ACPI_BUFFER buf; 321 ACPI_OBJECT *res; 322 ACPI_INTEGER val; 323 int status; 324 325 status = ENXIO; 326 --- 19 unchanged lines hidden (view full) --- 346 if (buf.Pointer) 347 AcpiOsFree(buf.Pointer); 348 349 return (status); 350} 351 352static void 353acpi_panasonic_hkey_action(struct acpi_panasonic_softc *sc, ACPI_HANDLE h, | 319{ 320 ACPI_BUFFER buf; 321 ACPI_OBJECT *res; 322 ACPI_INTEGER val; 323 int status; 324 325 status = ENXIO; 326 --- 19 unchanged lines hidden (view full) --- 346 if (buf.Pointer) 347 AcpiOsFree(buf.Pointer); 348 349 return (status); 350} 351 352static void 353acpi_panasonic_hkey_action(struct acpi_panasonic_softc *sc, ACPI_HANDLE h, |
354 UINT32 key) | 354 UINT32 key) |
355{ 356 int arg; 357 358 switch (key) { 359 case 1: 360 /* Decrease LCD brightness. */ 361 hkey_lcd_brightness(h, HKEY_GET, &arg); 362 arg -= lcd_brightness_max / HKEY_LCD_BRIGHTNESS_DIV; --- 36 unchanged lines hidden (view full) --- 399 switch (notify) { 400 case 0x80: 401 if (acpi_panasonic_hkey_event(sc, h, &key) == 0) { 402 acpi_panasonic_hkey_action(sc, h, key); 403 acpi_UserNotify("Panasonic", h, (uint8_t)key); 404 } 405 break; 406 default: | 355{ 356 int arg; 357 358 switch (key) { 359 case 1: 360 /* Decrease LCD brightness. */ 361 hkey_lcd_brightness(h, HKEY_GET, &arg); 362 arg -= lcd_brightness_max / HKEY_LCD_BRIGHTNESS_DIV; --- 36 unchanged lines hidden (view full) --- 399 switch (notify) { 400 case 0x80: 401 if (acpi_panasonic_hkey_event(sc, h, &key) == 0) { 402 acpi_panasonic_hkey_action(sc, h, key); 403 acpi_UserNotify("Panasonic", h, (uint8_t)key); 404 } 405 break; 406 default: |
407 device_printf(sc->dev, "unknown Notify: 0x%x\n", notify); | 407 device_printf(sc->dev, "unknown notify: %#x\n", notify); |
408 break; 409 } 410} | 408 break; 409 } 410} |