Add Panasonic Laptop ACPI extras driver
PATCH 1/1 Add Panasonic Laptop ACPI extras driver
[PATCH] Add Panasonic Laptop ACPI extras driver
This is a driver for ACPI extras such as hotkeys and backlight brightness control on various Panasonic "Let's Note" series laptop computers.
It exports the backlight via the backlight class device API, and the hotkeys as input event device. Some more esoteric items like number of installed batteries are exported via sysfs device attributes.
Hotkey events also generate old-style ACPI enents through /proc/acpi/event to interoperate with current versions of acpid.
---
non-changelog description:
Ever since I bought my Panasonic Let's Note CF-R5 in September 2006 (like other well-known kernel hackers such as Jamal Selim and Stephen Hemminger) I'm using the (apparently abandoned) out-of-tree pcc_acpi.c driver. Various changes in the kernel API's have required me to merge/forward-port it from one kernel release to the other.
In more than three attempts (two of them in the last 6 months), I have tried to contact the main author (Hiroshi Miura, see Cc) and asked if he had plans to submit the driver for mainline inclusion or if he'd support any such submission attempt by me.
The co-author David Bronaugh has promptly responded and is fine with merging it mainline.
Though we are now in the unfortunate situation where the main author is no longer reachable, I don't want to delay this even longer and want to get this driver merged. The original code was explicitly GPL licensed, so there is no legal requirement to have explicit permission from Hiroshi Miura.
For the time being, I'm also willing to be the maintainer of this driver.
This driver has already received review and feedback on the linux-acpi mailing list. There were no issues that have not been adressed.
Please merge this driver. Thanks.
MAINTAINERS +5 -0
@@ -3108,6 +3108,11 @@ M: [email protected] L: [email protected] S: Maintained +PANASONIC LAPTOP ACPI EXTRAS DRIVER +P: Harald Welte +M: [email protected] +S: Maintained + PARALLEL PORT SUPPORT L: [email protected] (subscribers-only) S: Orphan
drivers/acpi/Kconfig +11 -0
@@ -259,6 +259,17 @@ config ACPI_ASUS NOTE: This driver is deprecated and will probably be removed soon, use asus-laptop instead. +config ACPI_PANASONIC + tristate "Panasonic Laptop Extras" + depends on X86 + select BACKLIGHT_CLASS_DEVICE + ---help--- + This driver adds support for access to certain system settings + on Panasonic Let's Note laptops. + + If you have a Panasonic Let's note laptop (such as the R1(N variant), + R2, R3, R5, T2, W2 and Y2 series), say Y. + config ACPI_TOSHIBA tristate "Toshiba Laptop Extras" depends on X86
drivers/acpi/Makefile +1 -0
@@ -59,6 +59,7 @@ obj-$(CONFIG_ACPI_WMI) += wmi.o obj-$(CONFIG_ACPI_ASUS) += asus_acpi.o obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o +obj-$(CONFIG_ACPI_PANASONIC) += pcc_acpi.o obj-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o obj-$(CONFIG_ACPI_SBS) += sbshc.o obj-$(CONFIG_ACPI_SBS) += sbs.o
drivers/acpi/pcc_acpi.c new file +779 -0
779 lines not on this page · raw message
Signature · 4 lines
- Harald Welte <[email protected]> http://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6)
Hi Harald,
Quoted 2 lines · Harald Welte
[PATCH] Add Panasonic Laptop ACPI extras driver
Since I don't usually read ACPI list I did not have a chance to reply earlier, could you please CC linux-input and/or myself when working with drivers that implement input devices?
drivers/acpi/pcc_acpi.c line 206
Quoted 4 lines
drivers/acpi/pcc_acpi.c new file +4
-0+ +#define KEYMAP_SIZE 11 +static const int initial_keymap[KEYMAP_SIZE ] = { +/* 0 */ -1 ,
Normally KEY_RESERVED is used for invalid entries.
Quoted 29 lines
drivers/acpi/pcc_acpi.c new file +28
-0+/* 1 */ KEY_BRIGHTNESSDOWN , +/* 2 */ KEY_BRIGHTNESSUP , +/* 3 */ KEY_DISPLAYTOGGLE , +/* 4 */ KEY_MUTE , +/* 5 */ KEY_VOLUMEDOWN , +/* 6 */ KEY_VOLUMEUP , +/* 7 */ KEY_SLEEP , +/* 8 */ KEY_PROG1 ,/* Change CPU boost */ +/* 9 */ KEY_BATTERY , + /* 10 */ KEY_SUSPEND, +}; + + +static int acpi_pcc_init_input (struct pcc_acpi *pcc) +{ +int rc; + +ACPI_FUNCTION_TRACE ("acpi_pcc_init_input" ); + + pcc->input_dev =input_allocate_device (); +if (!pcc->input_dev) { +ACPI_DEBUG_PRINT ((ACPI_DB_ERROR , +"Couldn't allocate input device for hotkey" )); +return -ENOMEM ; + } + + pcc->input_dev->evbit[0 ] =BIT (EV_KEY ); +
drivers/acpi/pcc_acpi.c
Quoted 10 lines
drivers/acpi/pcc_acpi.c new file +10
-0+set_bit (KEY_BRIGHTNESSDOWN , pcc->input_dev->keybit); +set_bit (KEY_BRIGHTNESSUP , pcc->input_dev->keybit); +set_bit (KEY_MUTE , pcc->input_dev->keybit); +set_bit (KEY_VOLUMEDOWN , pcc->input_dev->keybit); +set_bit (KEY_VOLUMEUP , pcc->input_dev->keybit); +set_bit (KEY_SLEEP , pcc->input_dev->keybit); +set_bit (KEY_BATTERY , pcc->input_dev->keybit); +set_bit (KEY_SUSPEND , pcc->input_dev->keybit); +set_bit (KEY_DISPLAYTOGGLE , pcc->input_dev->keybit); +set_bit (KEY_PROG1 , pcc->input_dev->keybit);
I like doing:
for (i = 0; i < sizeof(pcc->keymap); i++) __set_bit(pcc->keymap[i], input_dev->keybit); __clear_bit(KEY_RESERVED, input_dev->keybit);
after copying the keymap, as this helps maintaining the keymap in just one place.
drivers/acpi/pcc_acpi.c line 586
Quoted 4 lines
drivers/acpi/pcc_acpi.c new file +4
-0+ + pcc->input_dev->name =ACPI_PCC_DRIVER_NAME ; + pcc->input_dev->phys =ACPI_PCC_INPUT_PHYS ; + pcc->input_dev->id.bustype =0x1a ;/* XXX FIXME: BUS_I8042? */
I think BUS_HOST is most appropriate here.
Quoted 28 lines
drivers/acpi/pcc_acpi.c new file +27
-0+ pcc->input_dev->id.vendor =0x0001 ; + pcc->input_dev->id.product =0x0001 ; + pcc->input_dev->id.version =0x0100 ; + pcc->input_dev->getkeycode = pcc_getkeycode; + pcc->input_dev->setkeycode = pcc_setkeycode; + +/* load initial keymap */ +memcpy (pcc->keymap, initial_keymap,sizeof (pcc->keymap)); + +input_set_drvdata (pcc->input_dev, pcc); + + rc =input_register_device (pcc->input_dev); +if (rc <0 ) +input_free_device (pcc->input_dev); + +return rc; +} + +static int acpi_pcc_hotkey_add (struct acpi_device *device) +{ +acpi_status status; +struct pcc_acpi *pcc; +int num_sifr, result; + +ACPI_FUNCTION_TRACE ("acpi_pcc_hotkey_add" ); + +if (!device)
drivers/acpi/pcc_acpi.c line 643
Quoted 10 lines
drivers/acpi/pcc_acpi.c new file +10
-0+return -EINVAL ; + + num_sifr =acpi_pcc_get_sqty (device); + +if (num_sifr >255 ) { +ACPI_DEBUG_PRINT ((ACPI_DB_ERROR ,"num_sifr too large" )); +return -ENODEV ; + } + + pcc =kmalloc (sizeof (struct pcc_acpi ),GFP_KERNEL );
kzalloc?
drivers/acpi/pcc_acpi.c line 651
Quoted 8 lines
drivers/acpi/pcc_acpi.c new file +8
-0+if (!pcc) { +ACPI_DEBUG_PRINT ((ACPI_DB_ERROR , +"Couldn't allocate mem for pcc" )); +return -ENOMEM ; + } +memset (pcc,0 ,sizeof (struct pcc_acpi )); + + pcc->sinf =kmalloc (sizeof (u32) * (num_sifr +1 ),GFP_KERNEL );
kcalloc?
Quoted 56 lines
drivers/acpi/pcc_acpi.c new file +56
-0+if (!pcc->sinf) { + result = -ENOMEM ; + goto out_hotkey; + } + + pcc->device = device; + pcc->handle = device->handle; + pcc->num_sifr = num_sifr; +acpi_driver_data (device) = pcc; +strcpy (acpi_device_name (device),ACPI_PCC_DEVICE_NAME ); +strcpy (acpi_device_class (device),ACPI_PCC_CLASS ); + + result =acpi_pcc_init_input (pcc); +if (result) { +ACPI_DEBUG_PRINT ((ACPI_DB_ERROR , +"Error installing keyinput handler\n" )); + goto out_sinf; + } + +/* initialize hotkey input device */ + status =acpi_install_notify_handler (pcc->handle,ACPI_DEVICE_NOTIFY , + acpi_pcc_hotkey_notify, pcc); + +if (ACPI_FAILURE (status)) { +ACPI_DEBUG_PRINT ((ACPI_DB_ERROR , +"Error installing notify handler\n" )); + result = -ENODEV ; + goto out_input; + } + +/* initialize backlight */ + pcc->backlight =backlight_device_register ("panasonic" ,NULL , pcc, + &pcc_backlight_ops); +if (IS_ERR (pcc->backlight)) + goto out_notify; + +if (!acpi_pcc_retrieve_biosdata (pcc, pcc->sinf)) { +ACPI_DEBUG_PRINT ((ACPI_DB_ERROR , +"Couldn't retrieve BIOS data\n" )); + goto out_backlight; + } + +/* read the initial brightness setting from the hardware */ + pcc->backlight->props.max_brightness = + pcc->sinf[SINF_AC_MAX_BRIGHT ]; + pcc->backlight->props.brightness = pcc->sinf[SINF_AC_CUR_BRIGHT ]; + +/* read the initial sticky key mode from the hardware */ + pcc->sticky_mode = pcc->sinf[SINF_STICKY_KEY ]; + +/* add sysfs attributes */ + result =sysfs_create_group (&device->dev.kobj, &pcc_attr_group); +if (result) + goto out_backlight; + +return 0 ;
drivers/acpi/pcc_acpi.c line 717
Quoted 10 lines
drivers/acpi/pcc_acpi.c new file +10
-0+ +out_backlight: +backlight_device_unregister (pcc->backlight); +out_notify: +acpi_remove_notify_handler (pcc->handle,ACPI_DEVICE_NOTIFY , + acpi_pcc_hotkey_notify); +out_input: +input_unregister_device (pcc->input_dev); +kfree (input_get_drvdata (pcc->input_dev)); +input_free_device (pcc->input_dev);
This will bomb. You are not allowed to call input_free_device after input_unregister_device - input_dev is refcounted and will be freed after the last reference is dropped. Plus acpi_pcc_init_input frees input device itself if input_register_device_fails. Also drvdata of input_dev is set to point to 'pcc' which is being freed again below. So I think you just need to call input_unregister_device() here.
Quoted 18 lines
drivers/acpi/pcc_acpi.c new file +18
-0+out_sinf: +kfree (pcc->sinf); +out_hotkey: +kfree (pcc); + +return result; +} + +static int acpi_pcc_hotkey_remove (struct acpi_device *device,int type) +{ +struct pcc_acpi *pcc =acpi_driver_data (device); + +ACPI_FUNCTION_TRACE ("acpi_pcc_hotkey_remove" ); + +if (!device || !pcc) +return -EINVAL ; + +sysfs_remove_group (&device->dev.kobj, &pcc_attr_group);
drivers/acpi/pcc_acpi.c line 764
Quoted 10 lines
drivers/acpi/pcc_acpi.c new file +10
-0+ +backlight_device_unregister (pcc->backlight); + +acpi_remove_notify_handler (pcc->handle,ACPI_DEVICE_NOTIFY , + acpi_pcc_hotkey_notify); + +input_unregister_device (pcc->input_dev); +kfree (input_get_drvdata (pcc->input_dev)); +input_free_device (pcc->input_dev); +
Same as above, simply input_unregister_device(pcc->input_dev); should suffice.
drivers/acpi/pcc_acpi.c line 743
Quoted 5 lines
drivers/acpi/pcc_acpi.c new file +5
-0+kfree (pcc->sinf); +kfree (pcc); + +return 0 ; +}
Thanks!
Signature · 1 line
Dmitry
PATCH 1/1 Add Panasonic Laptop ACPI extras driver
Hi Dmitry,
thanks for your valuable feedback and sorry for not including you into the loop earlier.
This is a new version of the patch including all your feedback.
Andi, I hope we're clear to merge it now.
--------------------------
Panasonic Let's Note ACPI extras driver
This is a driver for ACPI extras such as hotkeys and backlight brightness control on various Panasonic "Let's Note" series laptop computers.
It exports the backlight via the backlight class device API, and the hotkeys as input event device. Some more esoteric items like number of installed batteries are exported via sysfs device attributes.
Hotkey events also generate old-style ACPI enents through /proc/acpi/event to interoperate with current versions of acpid.
MAINTAINERS +5 -0
@@ -3155,6 +3155,11 @@ M: [email protected] L: [email protected] S: Maintained +PANASONIC LAPTOP ACPI EXTRAS DRIVER +P: Harald Welte +M: [email protected] +S: Maintained + PARALLEL PORT SUPPORT L: [email protected] (subscribers-only) S: Orphan
drivers/acpi/Kconfig +11 -0
@@ -257,6 +257,17 @@ config ACPI_ASUS NOTE: This driver is deprecated and will probably be removed soon, use asus-laptop instead. +config ACPI_PANASONIC + tristate "Panasonic Laptop Extras" + depends on X86 + select BACKLIGHT_CLASS_DEVICE + ---help--- + This driver adds support for access to certain system settings + on Panasonic Let's Note laptops. + + If you have a Panasonic Let's note laptop (such as the R1(N variant), + R2, R3, R5, T2, W2 and Y2 series), say Y. + config ACPI_TOSHIBA tristate "Toshiba Laptop Extras" depends on X86
drivers/acpi/Makefile +1 -0
@@ -60,6 +60,7 @@ obj-$(CONFIG_ACPI_WMI) += wmi.o obj-$(CONFIG_ACPI_ASUS) += asus_acpi.o obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o +obj-$(CONFIG_ACPI_PANASONIC) += pcc_acpi.o obj-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o obj-$(CONFIG_ACPI_SBS) += sbshc.o obj-$(CONFIG_ACPI_SBS) += sbs.o
drivers/acpi/pcc_acpi.c new file +771 -0
771 lines not on this page · raw message
Signature · 4 lines
- Harald Welte <[email protected]> http://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6)
Hi Harald,
Quoted 9 lines · Harald Welte
Hi Dmitry,
thanks for your valuable feedback and sorry for not including you into the loop earlier.
This is a new version of the patch including all your feedback.
Andi, I hope we're clear to merge it now.
Just couple more things after your last round of fixes. If these are corrected you may add:
Quoted 2 lines
drivers/acpi/pcc_acpi.c new file +2
-0+ +static void acpi_pcc_generate_keyinput (struct pcc_acpi *pcc)
[..skip..]
drivers/acpi/pcc_acpi.c line 532
Quoted 4 lines
drivers/acpi/pcc_acpi.c new file +4
-0+ + key_code = pcc->keymap[hkey_num]; + +if (key_code !=-1 ) {
This should be either KEY_RESERVED now or just remove the check completely - since you reset the bit for KEY_RESERVED in the keybit the input core will not propagate this event even if reported.
Quoted 7 lines
drivers/acpi/pcc_acpi.c new file +7
-0+int pushed = (result &0x80 ) ? TRUE : FALSE; + +input_report_key (hotk_input_dev, key_code, pushed); +input_sync (hotk_input_dev); + } + +}
[..skip..]
Quoted 9 lines
drivers/acpi/pcc_acpi.c new file +9
-0+static int acpi_pcc_init_input (struct pcc_acpi *pcc) +{ +int i, rc; + +ACPI_FUNCTION_TRACE ("acpi_pcc_init_input" ); + + pcc->input_dev =input_allocate_device (); +if (!pcc->input_dev) { + ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
drivers/acpi/pcc_acpi.c line 576
Quoted 10 lines
drivers/acpi/pcc_acpi.c new file +10
-0+ "Couldn't allocate input device for hotkey")); +return -ENOMEM ; + } + + pcc->input_dev->evbit[0 ] =BIT (EV_KEY ); + +for (i =0 ; i <sizeof (pcc->keymap); i++) +__set_bit (pcc->keymap[i], pcc->input_dev->keybit); +__clear_bit (KEY_RESERVED , pcc->input_dev->keybit); +
This should be done after copying the initial keymap, otherwise you won't really set any bits because pcc is zeroed upon allocation.
drivers/acpi/pcc_acpi.c line 588
Quoted 12 lines
drivers/acpi/pcc_acpi.c new file +12
-0+ pcc->input_dev->name =ACPI_PCC_DRIVER_NAME ; + pcc->input_dev->phys =ACPI_PCC_INPUT_PHYS ; + pcc->input_dev->id.bustype =BUS_HOST ; + pcc->input_dev->id.vendor =0x0001 ; + pcc->input_dev->id.product =0x0001 ; + pcc->input_dev->id.version =0x0100 ; + pcc->input_dev->getkeycode = pcc_getkeycode; + pcc->input_dev->setkeycode = pcc_setkeycode; + +/* load initial keymap */ +memcpy (pcc->keymap, initial_keymap,sizeof (pcc->keymap)); +
Thanks!
Signature · 1 line
Dmitry
PATCH 1/1 Add Panasonic Laptop ACPI extras driver
Quoted 2 lines · Dmitry Torokhov
Just couple more things after your last round of fixes. If these are corrected you may add:
ok. thanks. I've integrated your feedback. hopefully this version can now get merged:
======
Panasonic Let's Note ACPI extras driver
This is a driver for ACPI extras such as hotkeys and backlight brightness control on various Panasonic "Let's Note" series laptop computers.
It exports the backlight via the backlight class device API, and the hotkeys as input event device. Some more esoteric items like number of installed batteries are exported via sysfs device attributes.
Hotkey events also generate old-style ACPI enents through /proc/acpi/event to interoperate with current versions of acpid.
MAINTAINERS +5 -0
@@ -3155,6 +3155,11 @@ M: [email protected] L: [email protected] S: Maintained +PANASONIC LAPTOP ACPI EXTRAS DRIVER +P: Harald Welte +M: [email protected] +S: Maintained + PARALLEL PORT SUPPORT L: [email protected] (subscribers-only) S: Orphan
drivers/acpi/Kconfig +11 -0
@@ -257,6 +257,17 @@ config ACPI_ASUS NOTE: This driver is deprecated and will probably be removed soon, use asus-laptop instead. +config ACPI_PANASONIC + tristate "Panasonic Laptop Extras" + depends on X86 + select BACKLIGHT_CLASS_DEVICE + ---help--- + This driver adds support for access to certain system settings + on Panasonic Let's Note laptops. + + If you have a Panasonic Let's note laptop (such as the R1(N variant), + R2, R3, R5, T2, W2 and Y2 series), say Y. + config ACPI_TOSHIBA tristate "Toshiba Laptop Extras" depends on X86
drivers/acpi/Makefile +1 -0
@@ -60,6 +60,7 @@ obj-$(CONFIG_ACPI_WMI) += wmi.o obj-$(CONFIG_ACPI_ASUS) += asus_acpi.o obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o +obj-$(CONFIG_ACPI_PANASONIC) += pcc_acpi.o obj-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o obj-$(CONFIG_ACPI_SBS) += sbshc.o obj-$(CONFIG_ACPI_SBS) += sbs.o
drivers/acpi/pcc_acpi.c new file +769 -0
769 lines not on this page · raw message
Signature · 4 lines
- Harald Welte <[email protected]> http://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6)
drivers/acpi/Kconfig config ACPI_ASUS · line 262
Quoted 4 lines · Harald Welte
drivers/acpi/Kconfig +3
-0+config ACPI_PANASONIC + tristate "Panasonic Laptop Extras" + depends on X86
Also needs "depends on INPUT" otherwise "make randconfig" guys will come after you with venegance ;)
Sorry for not noticing this before.
Signature · 1 line
Dmitry
PATCH 1/1 Add Panasonic Laptop ACPI extras driver
Quoted 2 lines
Also needs "depends on INPUT" otherwise "make randconfig" guys will come after you with venegance ;)
fixed. andi: sorry for the many re-posts :( let's hope we have it finished now.
======
Panasonic Let's Note ACPI extras driver
This is a driver for ACPI extras such as hotkeys and backlight brightness control on various Panasonic "Let's Note" series laptop computers.
It exports the backlight via the backlight class device API, and the hotkeys as input event device. Some more esoteric items like number of installed batteries are exported via sysfs device attributes.
Hotkey events also generate old-style ACPI enents through /proc/acpi/event to interoperate with current versions of acpid.
MAINTAINERS +5 -0
@@ -3155,6 +3155,11 @@ M: [email protected] L: [email protected] S: Maintained +PANASONIC LAPTOP ACPI EXTRAS DRIVER +P: Harald Welte +M: [email protected] +S: Maintained + PARALLEL PORT SUPPORT L: [email protected] (subscribers-only) S: Orphan
drivers/acpi/Kconfig +12 -0
@@ -257,6 +257,18 @@ config ACPI_ASUS NOTE: This driver is deprecated and will probably be removed soon, use asus-laptop instead. +config ACPI_PANASONIC + tristate "Panasonic Laptop Extras" + depends on X86 + depends on INPUT + select BACKLIGHT_CLASS_DEVICE + ---help--- + This driver adds support for access to certain system settings + on Panasonic Let's Note laptops. + + If you have a Panasonic Let's note laptop (such as the R1(N variant), + R2, R3, R5, T2, W2 and Y2 series), say Y. + config ACPI_TOSHIBA tristate "Toshiba Laptop Extras" depends on X86
drivers/acpi/Makefile +1 -0
@@ -60,6 +60,7 @@ obj-$(CONFIG_ACPI_WMI) += wmi.o obj-$(CONFIG_ACPI_ASUS) += asus_acpi.o obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o +obj-$(CONFIG_ACPI_PANASONIC) += pcc_acpi.o obj-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o obj-$(CONFIG_ACPI_SBS) += sbshc.o obj-$(CONFIG_ACPI_SBS) += sbs.o
drivers/acpi/pcc_acpi.c new file +769 -0
769 lines not on this page · raw message
Signature · 4 lines
- Harald Welte <[email protected]> http://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6)