119 #include <linux/kernel.h>
120 #include <linux/module.h>
122 #include <linux/types.h>
124 #include <linux/ctype.h>
127 #include <linux/slab.h>
130 #include <linux/input.h>
134 #ifndef ACPI_HOTKEY_COMPONENT
135 #define ACPI_HOTKEY_COMPONENT 0x10000000
138 #define _COMPONENT ACPI_HOTKEY_COMPONENT
140 MODULE_AUTHOR(
"Hiroshi Miura, David Bronaugh and Harald Welte");
144 #define LOGPREFIX "pcc_acpi: "
148 #define METHOD_HKEY_QUERY "HINF"
149 #define METHOD_HKEY_SQTY "SQTY"
150 #define METHOD_HKEY_SINF "SINF"
151 #define METHOD_HKEY_SSET "SSET"
152 #define HKEY_NOTIFY 0x80
154 #define ACPI_PCC_DRIVER_NAME "Panasonic Laptop Support"
155 #define ACPI_PCC_DEVICE_NAME "Hotkey"
156 #define ACPI_PCC_CLASS "pcc"
158 #define ACPI_PCC_INPUT_PHYS "panasonic/hkey0"
178 static int acpi_pcc_hotkey_add(
struct acpi_device *
device);
179 static int acpi_pcc_hotkey_remove(
struct acpi_device *
device,
int type);
180 static void acpi_pcc_hotkey_notify(
struct acpi_device *
device,
u32 event);
191 #ifdef CONFIG_PM_SLEEP
192 static int acpi_pcc_hotkey_resume(
struct device *
dev);
196 static struct acpi_driver acpi_pcc_driver = {
199 .ids = pcc_device_ids,
201 .add = acpi_pcc_hotkey_add,
202 .remove = acpi_pcc_hotkey_remove,
203 .notify = acpi_pcc_hotkey_notify,
205 .drv.pm = &acpi_pcc_hotkey_pm,
208 static const struct key_entry panasonic_keymap[] = {
238 static int acpi_pcc_write_sset(
struct pcc_acpi *pcc,
int func,
int val)
242 .integer.value =
func, },
244 .integer.value =
val, },
255 return (status ==
AE_OK) ? 0 : -
EIO;
258 static inline int acpi_pcc_get_sqty(
struct acpi_device *
device)
260 unsigned long long s;
269 "evaluation error HKEY.SQTY\n"));
274 static int acpi_pcc_retrieve_biosdata(
struct pcc_acpi *pcc)
285 "evaluation error HKEY.SINF\n"));
298 "SQTY reports bad SINF length\n"));
303 for (i = 0; i < hkey->
package.count; i++) {
309 "Invalid HKEY.SINF data\n"));
315 return status ==
AE_OK;
327 struct pcc_acpi *pcc = bl_get_data(bd);
329 if (!acpi_pcc_retrieve_biosdata(pcc))
337 struct pcc_acpi *pcc = bl_get_data(bd);
338 int bright = bd->
props.brightness;
341 if (!acpi_pcc_retrieve_biosdata(pcc))
350 if (bright < pcc->
sinf[SINF_AC_MIN_BRIGHT] ||
362 .get_brightness = bl_get,
363 .update_status = bl_set_status,
372 struct acpi_device *acpi = to_acpi_device(dev);
373 struct pcc_acpi *pcc = acpi_driver_data(acpi);
375 if (!acpi_pcc_retrieve_biosdata(pcc))
384 struct acpi_device *acpi = to_acpi_device(dev);
385 struct pcc_acpi *pcc = acpi_driver_data(acpi);
387 if (!acpi_pcc_retrieve_biosdata(pcc))
396 struct acpi_device *acpi = to_acpi_device(dev);
397 struct pcc_acpi *pcc = acpi_driver_data(acpi);
399 if (!acpi_pcc_retrieve_biosdata(pcc))
408 struct acpi_device *acpi = to_acpi_device(dev);
409 struct pcc_acpi *pcc = acpi_driver_data(acpi);
411 if (!acpi_pcc_retrieve_biosdata(pcc))
418 const char *buf,
size_t count)
420 struct acpi_device *acpi = to_acpi_device(dev);
421 struct pcc_acpi *pcc = acpi_driver_data(acpi);
424 if (count &&
sscanf(buf,
"%i", &val) == 1 &&
425 (val == 0 || val == 1)) {
438 static struct attribute *pcc_sysfs_entries[] = {
439 &dev_attr_numbatt.attr,
440 &dev_attr_lcdtype.attr,
442 &dev_attr_sticky_key.attr,
448 .attrs = pcc_sysfs_entries,
454 static void acpi_pcc_generate_keyinput(
struct pcc_acpi *pcc)
456 struct input_dev *hotk_input_dev = pcc->
input_dev;
458 unsigned long long result;
464 "error getting hotkey status\n"));
470 if (!sparse_keymap_report_event(hotk_input_dev,
471 result & 0xf, result & 0x80,
false))
473 "Unknown hotkey event: %d\n", result));
476 static void acpi_pcc_hotkey_notify(
struct acpi_device *device,
u32 event)
478 struct pcc_acpi *pcc = acpi_driver_data(device);
482 acpi_pcc_generate_keyinput(pcc);
490 static int acpi_pcc_init_input(
struct pcc_acpi *pcc)
492 struct input_dev *input_dev;
495 input_dev = input_allocate_device();
498 "Couldn't allocate input device for hotkey"));
505 input_dev->id.vendor = 0x0001;
506 input_dev->id.product = 0x0001;
507 input_dev->id.version = 0x0100;
509 error = sparse_keymap_setup(input_dev, panasonic_keymap,
NULL);
512 "Unable to setup input device keymap\n"));
516 error = input_register_device(input_dev);
519 "Unable to register input device\n"));
520 goto err_free_keymap;
527 sparse_keymap_free(input_dev);
529 input_free_device(input_dev);
533 static void acpi_pcc_destroy_input(
struct pcc_acpi *pcc)
545 #ifdef CONFIG_PM_SLEEP
546 static int acpi_pcc_hotkey_resume(
struct device *dev)
553 pcc = acpi_driver_data(to_acpi_device(dev));
564 static int acpi_pcc_hotkey_add(
struct acpi_device *device)
573 num_sifr = acpi_pcc_get_sqty(device);
575 if (num_sifr < 0 || num_sifr > 255) {
583 "Couldn't allocate mem for pcc"));
594 pcc->
handle = device->handle;
596 device->driver_data = pcc;
600 result = acpi_pcc_init_input(pcc);
603 "Error installing keyinput handler\n"));
607 if (!acpi_pcc_retrieve_biosdata(pcc)) {
609 "Couldn't retrieve BIOS data\n"));
618 &pcc_backlight_ops, &props);
640 acpi_pcc_destroy_input(pcc);
649 static int __init acpi_pcc_init(
void)
659 "Error registering hotkey driver\n"));
666 static int acpi_pcc_hotkey_remove(
struct acpi_device *device,
int type)
668 struct pcc_acpi *pcc = acpi_driver_data(device);
677 acpi_pcc_destroy_input(pcc);
685 static void __exit acpi_pcc_exit(
void)