From: Hiroshi Miura Subject: [PATCH]Panasonic Hotkey Driver v0.5 [2/2] Date: Fri, 20 Aug 2004 15:25:52 +0900 Sender: acpi-devel-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Message-ID: <87u0uyqqa7.wl%miura@da-cha.org> References: <41244219.1090603@linuxboxen.org> <87acwqserw.wl%miura@da-cha.org> Mime-Version: 1.0 (generated by SEMI 1.14.6 - =?ISO-2022-JP?B?IhskQjRdGyhC?= =?ISO-2022-JP?B?GyRCMiwbKEIi?=) Content-Type: text/plain; charset=US-ASCII Return-path: In-Reply-To: <87acwqserw.wl%miura-yiisDzvROlQdnm+yROfE0A@public.gmane.org> Errors-To: acpi-devel-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , List-Archive: To: Len Brown Cc: David Bronaugh , acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org, letsnote-tech-eXqGM+LsbTTAqL8d+zIrHngSJqDPrsil@public.gmane.org List-Id: linux-acpi@vger.kernel.org Hi, This is incremental bkpatch against pcc_acpi driver v0.4. It is made using bkexport. At Fri, 20 Aug 2004 11:51:31 +0900, Hiroshi Miura wrote: > > Hi, > > I'm also developing lcd brightness driver and clean ups. > An infomation of BIOS data is gotten from hardware vendor. > > These are a little diffence in David's code about bios spec. > > I want to post my driver soon. Hiroshi Miura --- http://www.da-cha.org/ --- miura-yiisDzvROlQdnm+yROfE0A@public.gmane.org NTTDATA Corp. OpenSource Software Center. --- miurahr-3MafRgGXt7BL9jVzuh4AOg@public.gmane.org NTTDATA Intellilink Corp. OpenSource Engineering Dev. -- miurahr-w0OK63jvRlAuJ+9fw/WgBHgSJqDPrsil@public.gmane.org Key fingerprint = 9117 9407 5684 FBF1 4063 15B4 401D D077 04AB 8617 #### AUTHOR miura-yiisDzvROlQdnm+yROfE0A@public.gmane.org #### COMMENT START ### Comments for ChangeSet implement LCD brightness control based on infomation from Panasonic Let's Note team. implement Mute function. several clean up. fix credit. ### Comments for drivers/acpi/pcc_acpi.c implement LCD brightness control based on infomation from Panasonic Let's Note team. implement Mute function. several clean up. fix credit. #### COMMENT END # This is a BitKeeper generated diff -Nru style patch. # # ChangeSet # 2004/08/20 12:00:20+09:00 miura-yiisDzvROlQdnm+yROfE0A@public.gmane.org # implement LCD brightness control based on infomation from Panasonic Let's Note team. # implement Mute function. # several clean up. # fix credit. # # drivers/acpi/pcc_acpi.c # 2004/08/20 11:59:55+09:00 miura-yiisDzvROlQdnm+yROfE0A@public.gmane.org +221 -196 # implement LCD brightness control based on infomation from Panasonic Let's Note team. # implement Mute function. # several clean up. # fix credit. # diff -Nru a/drivers/acpi/pcc_acpi.c b/drivers/acpi/pcc_acpi.c --- a/drivers/acpi/pcc_acpi.c 2004-08-20 14:57:44 +09:00 +++ b/drivers/acpi/pcc_acpi.c 2004-08-20 14:57:44 +09:00 @@ -1,8 +1,8 @@ /* - * Panasonic HotKey control Extra driver - * (C) 2004 Hiroshi Miura - * (C) 2004 NTT DATA Intellilink Co. http://www.intellilink.co.jp/ - * All Rights Reserved + * Panasonic HotKey and lcd brightness control Extra driver + * Written by Hiroshi Miura 2004 + * + * Copyright (C) 2002-2004 John Belmonte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -12,19 +12,21 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * * You should have received a copy of the GNU General Public License + * + * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * The devolpment page for this driver will be located at - * http://www.da-cha.org/ - * *--------------------------------------------------------------------------- * * ChangeLog: + * Aug.10, 2004 Hiroshi Miura + * - v0.5 support LCD brightness control + * based on the disclosed information by MEI. + * * Jul.25, 2004 Hiroshi Miura * - v0.4 first post version - * - add debug function to retrive SIFR + * add function to retrive SIFR * * Jul.24, 2004 Hiroshi Miura * - v0.3 get proper status of hotkey @@ -33,15 +35,11 @@ * - v0.2 add HotKey handler * * Jul.17, 2004 Hiroshi Miura - * - v0.1 based on acpi video driver - * - * TODO - * everything all + * - v0.1 start from toshiba_acpi driver written by John Belmonte * */ -#define ACPI_PCC_VERSION "0.4" -#define PROC_INTERFACE_VERSION 2 +#define ACPI_PCC_VERSION "0.5" #include #include @@ -53,6 +51,10 @@ #include #include +#define ACPI_HOTKEY_COMPONENT 0x10000000 +#define _COMPONENT ACPI_HOTKEY_COMPONENT +ACPI_MODULE_NAME ("pcc_acpi") + MODULE_AUTHOR("Hiroshi Miura"); MODULE_DESCRIPTION("ACPI HotKey driver for lets note"); MODULE_LICENSE("GPL"); @@ -62,28 +64,12 @@ /**************************************************** * Define ACPI PATHs ****************************************************/ -/* crt/lcd hot key definitions */ -#define DEVICE_NAME_VGA "\\_SB_.PCI0.GRFX" -#define DEVICE_NAME_CRT "CRT1" -#define DEVICE_NAME_LCD "LCD1" -#define METHOD_CHGD "\\_SB_.CHGD" - -/* Lets note hotkeys definitions */ +/* Lets note hotkeys */ #define DEVICE_NAME_HKEY "\\_SB_.HKEY" #define METHOD_HKEY_QUERY "HINF" - -/* ACPI BIOS inside use only? */ -#define METHOD_HKEY_RESET "HRES" -#define METHOD_HKEY_SAVE "HSAV" -#define METHOD_HKEY_HIND "HIND" - -/* event read/write functions */ #define METHOD_HKEY_SQTY "SQTY" #define METHOD_HKEY_SINF "SINF" #define METHOD_HKEY_SSET "SSET" - - -/* device(HKEY) definitions */ #define HKEY_HID "MAT0019" #define HKEY_NOTIFY 0x80 @@ -93,21 +79,22 @@ * *******************************************************************/ #define PROC_PCC "pcc" +#define PROC_VIDEO "video" #define ACPI_HOTKEY_DRIVER_NAME "PCC HotKey Driver" #define ACPI_HOTKEY_DEVICE_NAME "HotKey" #define ACPI_HOTKEY_CLASS "HKEY" -static int acpi_hotkey_add (struct acpi_device *device); -static int acpi_hotkey_remove (struct acpi_device *device, int type); +static int acpi_pcc_hotkey_add (struct acpi_device *device); +static int acpi_pcc_hotkey_remove (struct acpi_device *device, int type); static struct acpi_driver acpi_hotkey_driver = { .name = ACPI_HOTKEY_DRIVER_NAME, .class = ACPI_HOTKEY_CLASS, .ids = HKEY_HID, .ops = { - .add = acpi_hotkey_add, - .remove = acpi_hotkey_remove, + .add = acpi_pcc_hotkey_add, + .remove = acpi_pcc_hotkey_remove, }, }; @@ -117,45 +104,25 @@ unsigned long status; }; - -/* - * utility functions - */ -static __inline__ void -_set_bit(u32* word, u32 mask, int value) -{ - *word = (*word & ~mask) | (mask * value); -} - -/* acpi interface wrappers - */ -static int -is_valid_acpi_path(const char* methodName) -{ - acpi_handle handle; - acpi_status status; - - status = acpi_get_handle(0, (char*)methodName, &handle); - return !ACPI_FAILURE(status); -} - -#if 0 static int -write_acpi_int(const char* methodName, int val) +write_sset(int func, int val) { struct acpi_object_list params; - union acpi_object in_objs[1]; + union acpi_object in_objs[2]; acpi_status status; + ACPI_FUNCTION_TRACE("acpi_pcc_write_sset"); + params.count = sizeof(in_objs)/sizeof(in_objs[0]); params.pointer = in_objs; in_objs[0].type = ACPI_TYPE_INTEGER; - in_objs[0].integer.value = val; + in_objs[0].integer.value = func; + in_objs[1].type = ACPI_TYPE_INTEGER; + in_objs[1].integer.value = val; - status = acpi_evaluate_object(0, (char*)methodName, ¶ms, 0); - return (status == AE_OK); + status = acpi_evaluate_object(0, DEVICE_NAME_HKEY "." METHOD_HKEY_SSET, ¶ms, 0); + return_VALUE(status == AE_OK); } -#endif static int read_acpi_int(acpi_handle handle, const char* methodName, int* pVal) @@ -201,8 +168,10 @@ char* p = page; int len; - if (off == 0) - p = item->read_func(p); + if (off == 0) { + if (item->read_func) + p = item->read_func(p); + } /* ISSUE: I don't understand this code */ len = (p - page); @@ -237,94 +206,146 @@ return result; } -/* - * proc file handlers - */ -#ifdef DEBUG_PCC_VGA -static unsigned long -write_chgd(const char* buffer, unsigned long count) +static int* sinf; +static int num_sifr; + +static int +acpi_pcc_init_sinf_buffer(void) { - int value; - acpi_status status; + acpi_status status = AE_OK; - if (sscanf(buffer, "%i", &value) == 1 && value >= 0 && value < 2) { - if (value == 0) - /* do nothing */ - status = AE_OK; - else { - status = acpi_evaluate_object(0, METHOD_CHGD, 0 , 0); - } - if (ACPI_FAILURE(status)) { - printk(KERN_INFO LOGPREFIX "fail evaluate CHGD()\n"); - return -EFAULT; - } - } - return count; + ACPI_FUNCTION_TRACE("acpi_pcc_init_sinf_buffer"); -} + if (!read_acpi_int(NULL, DEVICE_NAME_HKEY "." METHOD_HKEY_SQTY, &num_sifr)){ + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "evaluation error HKEY.SQTY\n")); + return_VALUE(-EINVAL); + } -static char* -read_nothing(char* p) -{ - /* nothing to do*/ - return p; + if ((sinf = (int*)kmalloc(sizeof(int) * (num_sifr + 1), GFP_KERNEL)) == NULL ) { + status = AE_ERROR; + } + + return_VALUE(status == AE_OK); } -#endif -static char* -read_hkey_status(char* p) +static int +acpi_pcc_retrive_biosdata(void) { acpi_status status; struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; union acpi_object *hkey = NULL; - int i, num_sifr; + int i; - if (!read_acpi_int(NULL, DEVICE_NAME_HKEY "." METHOD_HKEY_SQTY, &num_sifr)){ - printk(KERN_INFO LOGPREFIX "evaluation error HKEY.SQTY\n"); - return p; - } + ACPI_FUNCTION_TRACE("acpi_pcc_retrive_biosdata"); status = acpi_evaluate_object(NULL, DEVICE_NAME_HKEY "." METHOD_HKEY_SINF, 0 , &buffer); if (ACPI_FAILURE(status)) { - printk(KERN_INFO LOGPREFIX "evaluation error HEKY.SINF\n"); - return p; + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "evaluation error HEKY.SINF\n")); + return_VALUE(0); } + hkey = (union acpi_object *) buffer.pointer; if (!hkey || (hkey->type != ACPI_TYPE_PACKAGE)) { - printk(KERN_INFO LOGPREFIX "Invalid HKEY.SINF\n"); + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid HKEY.SINF\n")); goto end; } - if (num_sifr != hkey->package.count) { - printk(KERN_INFO LOGPREFIX "SQTY is not equal to SINF length?\n"); + if (num_sifr < hkey->package.count) { + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "SQTY reports bad SINF length\n")); + status = AE_ERROR; goto end; } for (i = 0; i < hkey->package.count; i++) { union acpi_object *element = &(hkey->package.elements[i]); if (likely(element->type == ACPI_TYPE_INTEGER)) { - p += sprintf(p, "0x%02x,\n", (unsigned int)element->integer.value); - } else - printk(KERN_INFO LOGPREFIX "Invalid HKEY.SINF value\n"); + sinf[i] = (int)element->integer.value; + } else + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid HKEY.SINF data\n")); } + sinf[hkey->package.count] = -1; + end: acpi_os_free(buffer.pointer); + return_VALUE(status == AE_OK); +} + +static char* +acpi_pcc_read_brightness(char* p) +{ + int i; + + if (!acpi_pcc_retrive_biosdata()) + return p; + + for (i = 2; i < 8 ; i++) { + p += sprintf(p, "%d", sinf[i]); + switch (i) { + case 2: + case 3: + case 5: + case 6: + p += sprintf(p, ","); + break; + case 4: + case 7: + p += sprintf(p, "\n"); + break; + default: + p += sprintf(p, ","); + } + } + + return p; +} + +static char* +read_mute(char* p) +{ + if (!acpi_pcc_retrive_biosdata()) + return p; + + p += sprintf(p, "%d\n", sinf[8]); + return p; } +static unsigned long +write_mute(const char* buffer, unsigned long count) +{ + int value; + + if (sscanf(buffer, "%i", &value) == 1 && value >= 0 && value <= 1) { + write_sset(8, value); + } + + return count; +} + +static unsigned long +acpi_pcc_write_brightness(const char* buffer, unsigned long count) +{ + int value1, value2; + + if (sscanf(buffer, "%i,%i", &value1, &value2) == 2 && value1 >= 0 && value1 < 2 && value2 >=0 && value2 < 20) { + write_sset((value1 == 1)?7:4, value2); + } else + printk("write_brightness error\n"); + + return count; +} static char* -read_version(char* p) +acpi_pcc_read_version(char* p) { p += sprintf(p, "%s version %s\n", ACPI_HOTKEY_DRIVER_NAME, ACPI_PCC_VERSION); - p += sprintf(p, "proc_interface version %d\n", PROC_INTERFACE_VERSION); return p; } /* hotkey driver */ static int -acpi_hotkey_get_key(struct acpi_hotkey *hotkey) +acpi_pcc_hotkey_get_key(struct acpi_hotkey *hotkey) { int result; int status; @@ -339,7 +360,7 @@ } void -acpi_hotkey_notify(acpi_handle handle, u32 event, void *data) +acpi_pcc_hotkey_notify(acpi_handle handle, u32 event, void *data) { struct acpi_hotkey *hotkey = (struct acpi_hotkey *) data; @@ -348,84 +369,25 @@ switch(event) { case HKEY_NOTIFY: - if (acpi_hotkey_get_key(hotkey)) + if (acpi_pcc_hotkey_get_key(hotkey)) acpi_bus_generate_event(hotkey->device, event, hotkey->status); break; default: /* nothing to do */ break; } - return; } -static int -acpi_hotkey_add (struct acpi_device *device) -{ - int result = 0; - acpi_status status = AE_OK; - struct acpi_hotkey *hotkey = NULL; - - if (!device) - return (-EINVAL); - - hotkey = kmalloc(sizeof(struct acpi_hotkey), GFP_KERNEL); - if (!hotkey) - return (-ENOMEM); - - memset(hotkey, 0, sizeof(struct acpi_hotkey)); - - hotkey->device = device; - hotkey->handle = device->handle; - acpi_driver_data(device) = hotkey; - strcpy(acpi_device_name(device), ACPI_HOTKEY_DEVICE_NAME); - strcpy(acpi_device_class(device), ACPI_HOTKEY_CLASS); - - status = acpi_install_notify_handler ( - hotkey->handle, - ACPI_DEVICE_NOTIFY, - acpi_hotkey_notify, - hotkey); - if (ACPI_FAILURE(status)) - result = -ENODEV; - - if (result) - kfree(hotkey); - - return (result); -} - -static int -acpi_hotkey_remove(struct acpi_device *device, int type) -{ - acpi_status status = 0; - struct acpi_hotkey *hotkey = NULL; - - if (!device || !acpi_driver_data(device)) - return(-EINVAL); - - hotkey = acpi_driver_data(device); - status = acpi_remove_notify_handler(hotkey->handle, - ACPI_DEVICE_NOTIFY, acpi_hotkey_notify); - if (ACPI_FAILURE(status)) - printk(KERN_INFO LOGPREFIX "Error removing notify handler\n"); - - kfree(hotkey); - - return(0); -} - /* * proc and module init */ ProcItem pcc_proc_items[] = { -#ifdef DEBUG_PCC_VGA - { "chgd" , read_nothing , write_chgd}, -#endif - { "hkey_status", read_hkey_status, NULL}, - { "version", read_version , NULL}, + { "brightness" , acpi_pcc_read_brightness , acpi_pcc_write_brightness}, + { "mute", read_mute, write_mute}, + { "version", acpi_pcc_read_version , NULL}, { NULL , NULL , NULL}, }; @@ -451,7 +413,7 @@ static int __init -pcc_proc_init(void) +acpi_pcc_proc_init(void) { acpi_status status = AE_OK; @@ -479,39 +441,102 @@ } +static int +acpi_pcc_hotkey_add (struct acpi_device *device) +{ + acpi_status status = AE_OK; + struct acpi_hotkey *hotkey = NULL; + + ACPI_FUNCTION_TRACE("acpi_pcc_hotkey_add"); + + if (!device) + return_VALUE(-EINVAL); + + acpi_pcc_proc_init(); + acpi_pcc_init_sinf_buffer(); + + hotkey = kmalloc(sizeof(struct acpi_hotkey), GFP_KERNEL); + if (!hotkey) + return_VALUE(-ENOMEM); + + memset(hotkey, 0, sizeof(struct acpi_hotkey)); + + hotkey->device = device; + hotkey->handle = device->handle; + acpi_driver_data(device) = hotkey; + strcpy(acpi_device_name(device), ACPI_HOTKEY_DEVICE_NAME); + strcpy(acpi_device_class(device), ACPI_HOTKEY_CLASS); + + status = acpi_install_notify_handler ( + hotkey->handle, + ACPI_DEVICE_NOTIFY, + acpi_pcc_hotkey_notify, + hotkey); + + if (ACPI_FAILURE(status)) { + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error installing notify handler\n")); + kfree(hotkey); + return_VALUE(-ENODEV); + } + + return_VALUE(0); +} + +static int +acpi_pcc_hotkey_remove(struct acpi_device *device, int type) +{ + acpi_status status = AE_OK; + struct acpi_hotkey *hotkey = NULL; + + ACPI_FUNCTION_TRACE("acpi_pcc_hotkey_remove"); + + if (!device || !acpi_driver_data(device)) + return_VALUE(-EINVAL); + + if (acpi_pcc_dir) { + remove_device(pcc_proc_items, acpi_pcc_dir); + remove_proc_entry(PROC_PCC, acpi_root_dir); + } + + hotkey = acpi_driver_data(device); + + status = acpi_remove_notify_handler(hotkey->handle, + ACPI_DEVICE_NOTIFY, acpi_pcc_hotkey_notify); + + if (ACPI_FAILURE(status)) + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error removing notify handler\n")); + + kfree(hotkey); + + return_VALUE(status == AE_OK); +} -/* init funcs. */ static int __init acpi_pcc_init(void) { acpi_status result = AE_OK; - if (acpi_disabled) - return -ENODEV; + ACPI_FUNCTION_TRACE("acpi_pcc_init"); - /* simple device detection: look forI method */ - if (!(is_valid_acpi_path(METHOD_CHGD))) - return -ENODEV; + if (acpi_disabled) + return_VALUE(-ENODEV); result = acpi_bus_register_driver(&acpi_hotkey_driver); - if (ACPI_FAILURE(result)) - printk(KERN_INFO LOGPREFIX "Error registering hotkey driver\n"); - - printk(KERN_INFO LOGPREFIX "ACPI PCC HotKey driver version %s\n", ACPI_PCC_VERSION); - - return (pcc_proc_init()); - + if (ACPI_FAILURE(result)) { + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error registering hotkey driver\n")); + return_VALUE(-ENODEV); + } + return_VALUE(0); } static void __exit acpi_pcc_exit(void) { - if (acpi_pcc_dir) { - remove_device(pcc_proc_items, acpi_pcc_dir); - remove_proc_entry(PROC_PCC, acpi_root_dir); - } + ACPI_FUNCTION_TRACE("acpi_pcc_exit"); + acpi_bus_unregister_driver(&acpi_hotkey_driver); - return; + + return_VOID; } module_init(acpi_pcc_init); ------------------------------------------------------- SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift. http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285