2 * Panasonic HotKey and lcd brightness control Extra driver
3 * (C) 2004 Hiroshi Miura <miura@da-cha.org>
4 * (C) 2004 NTT DATA Intellilink Co. http://www.intellilink.co.jp/
5 * (C) YOKOTA Hiroshi <yokota (at) netlab. is. tsukuba. ac. jp>
6 * (C) 2004 David Bronaugh <dbronaugh>
8 * derived from toshiba_acpi.c, Copyright (C) 2002-2004 John Belmonte
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * publicshed by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *---------------------------------------------------------------------------
27 * Nov.04, 2006 Hiroshi Miura <miura@da-cha.org>
28 * -v0.9 remove warning about section reference.
30 * add /proc/acpi/pcc/brightness interface to allow HAL to access.
31 * merge dbronaugh's enhancement
32 * Aug.17, 2004 David Bronaugh (dbronaugh)
33 * - Added screen brightness setting interface
34 * Thanks to the FreeBSD crew (acpi_panasonic.c authors)
35 * for the ideas I needed to accomplish it
37 * May.29, 2006 Hiroshi Miura <miura@da-cha.org>
38 * -v0.8.4 follow to change keyinput structure
39 * thanks Fabian Yamaguchi <fabs@cs.tu-berlin.de>,
40 * Jacob Bower <jacob.bower@ic.ac.uk> and
41 * Hiroshi Yokota for providing solutions.
43 * Oct.02, 2004 Hiroshi Miura <miura@da-cha.org>
44 * -v0.8.2 merge code of YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp>.
45 * Add sticky key mode interface.
46 * Refactoring acpi_pcc_generete_keyinput().
48 * Sep.15, 2004 Hiroshi Miura <miura@da-cha.org>
49 * -v0.8 Generate key input event on input subsystem.
50 * This is based on yet another driver written by Ryuta Nakanishi.
52 * Sep.10, 2004 Hiroshi Miura <miura@da-cha.org>
53 * -v0.7 Change proc interface functions using seq_file
54 * facility as same as other ACPI drivers.
56 * Aug.28, 2004 Hiroshi Miura <miura@da-cha.org>
57 * -v0.6.4 Fix a silly error with status checking
59 * Aug.25, 2004 Hiroshi Miura <miura@da-cha.org>
60 * -v0.6.3 replace read_acpi_int by standard function acpi_evaluate_integer
61 * some clean up and make smart copyright notice.
62 * fix return value of pcc_acpi_get_key()
63 * fix checking return value of acpi_bus_register_driver()
65 * Aug.22, 2004 David Bronaugh <dbronaugh@linuxboxen.org>
66 * -v0.6.2 Add check on ACPI data (num_sifr)
67 * Coding style cleanups, better error messages/handling
68 * Fixed an off-by-one error in memory allocation
70 * Aug.21, 2004 David Bronaugh <dbronaugh@linuxboxen.org>
71 * -v0.6.1 Fix a silly error with status checking
73 * Aug.20, 2004 David Bronaugh <dbronaugh@linuxboxen.org>
74 * - v0.6 Correct brightness controls to reflect reality
75 * based on information gleaned by Hiroshi Miura
76 * and discussions with Hiroshi Miura
78 * Aug.10, 2004 Hiroshi Miura <miura@da-cha.org>
79 * - v0.5 support LCD brightness control
80 * based on the disclosed information by MEI.
82 * Jul.25, 2004 Hiroshi Miura <miura@da-cha.org>
83 * - v0.4 first post version
84 * add function to retrive SIFR
86 * Jul.24, 2004 Hiroshi Miura <miura@da-cha.org>
87 * - v0.3 get proper status of hotkey
89 * Jul.22, 2004 Hiroshi Miura <miura@da-cha.org>
90 * - v0.2 add HotKey handler
92 * Jul.17, 2004 Hiroshi Miura <miura@da-cha.org>
93 * - v0.1 start from toshiba_acpi driver written by John Belmonte
97 #define ACPI_PCC_VERSION "0.9"
99 #include <linux/version.h>
100 #include <linux/kernel.h>
101 #include <linux/module.h>
102 #include <linux/init.h>
103 #include <linux/types.h>
104 #include <linux/proc_fs.h>
105 #include <linux/ctype.h>
106 #include <linux/seq_file.h>
107 #include <asm/uaccess.h>
108 #include <acpi/acpi_bus.h>
109 #include <acpi/acpi_drivers.h>
110 #include <linux/input.h>
113 /*************************************************************************
114 * "seq" file template definition.
116 /* "seq" initializer */
117 #define SEQ_OPEN_FS(_open_func_name_, _show_func_name_) \
118 static int _open_func_name_(struct inode *inode, struct file *file) \
120 return single_open(file, _show_func_name_, PDE(inode)->data); \
123 /*-------------------------------------------------------------------------
124 * "seq" fops template for read-only files.
126 #define SEQ_FILEOPS_R(_open_func_name_) \
128 .open = _open_func_name_, \
130 .llseek = seq_lseek, \
131 .release = single_release, \
134 /*------------------------------------------------------------------------
135 * "seq" fops template for read-write files.
137 #define SEQ_FILEOPS_RW(_open_func_name_, _write_func_name_) \
139 .open = _open_func_name_ , \
141 .write = _write_func_name_, \
142 .llseek = seq_lseek, \
143 .release = single_release, \
147 * "seq" file template definition ended.
148 ***************************************************************************
150 #ifndef ACPI_HOTKEY_COMPONENT
151 #define ACPI_HOTKEY_COMPONENT 0x10000000
154 #define _COMPONENT ACPI_HOTKEY_COMPONENT
155 ACPI_MODULE_NAME("pcc_acpi")
157 MODULE_AUTHOR("Hiroshi Miura");
158 MODULE_DESCRIPTION("ACPI HotKey driver for Panasonic Lets Note laptops");
159 MODULE_LICENSE("GPL");
161 #define LOGPREFIX "pcc_acpi: "
163 /****************************************************
165 ****************************************************/
166 /* Lets note hotkeys */
167 #define METHOD_HKEY_QUERY "HINF"
168 #define METHOD_HKEY_SQTY "SQTY"
169 #define METHOD_HKEY_SINF "SINF"
170 #define METHOD_HKEY_SSET "SSET"
171 #define HKEY_NOTIFY 0x80
173 /* for brightness control */
174 #define LCD_MAX_BRIGHTNESS 255
175 /* This may be magical -- beware */
176 #define LCD_BRIGHTNESS_INCREMENT 17
177 /* Registers of SINF */
178 #define SINF_LCD_BRIGHTNESS 4
180 /*******************************************************************
182 * definitions for /proc/ interface
184 *******************************************************************/
185 #define ACPI_PCC_DRIVER_NAME "PCC Extra Driver"
186 #define ACPI_PCC_DEVICE_NAME "PCCExtra"
187 #define ACPI_PCC_CLASS "pcc"
188 #define PROC_PCC ACPI_PCC_CLASS
190 #define ACPI_PCC_INPUT_PHYS "panasonic/hkey0"
192 /* This is transitional definition */
194 # define KEY_BATT 227
197 #define PROC_STR_MAX_LEN 8
199 /* LCD_TYPEs: 0 = Normal, 1 = Semi-transparent
200 ENV_STATEs: Normal temp=0x01, High temp=0x81, N/A=0x00
202 enum SINF_BITS { SINF_NUM_BATTERIES = 0,
203 SINF_LCD_TYPE, /* 1 */
204 SINF_AC_MAX_BRIGHT, SINF_AC_MIN_BRIGHT, SINF_AC_CUR_BRIGHT, /* 2, 3, 4 */
205 /* 4 = R1 only handle SINF_AC_CUR_BRIGHT as SINF_CUR_BRIGHT and don't know AC state */
206 SINF_DC_MAX_BRIGHT, SINF_DC_MIN_BRIGHT, SINF_DC_CUR_BRIGHT, /* 5, 6, 7 */
208 SINF_RESERVED, SINF_ENV_STATE, /* 9, 10 */
209 SINF_STICKY_KEY = 0x80,
212 static int acpi_pcc_hotkey_add(struct acpi_device *device);
213 static int acpi_pcc_hotkey_remove(struct acpi_device *device, int type);
214 static int acpi_pcc_hotkey_resume(struct acpi_device *device);
216 static const struct acpi_device_id pcc_device_ids[] = {
223 MODULE_DEVICE_TABLE(acpi, pcc_device_ids);
225 static struct acpi_driver acpi_pcc_driver = {
226 .name = ACPI_PCC_DRIVER_NAME,
227 .class = ACPI_PCC_CLASS,
228 .ids = pcc_device_ids,
230 .add = acpi_pcc_hotkey_add,
231 .remove = acpi_pcc_hotkey_remove,
232 .resume = acpi_pcc_hotkey_resume,
238 struct acpi_device *device;
239 struct proc_dir_entry *proc_dir_entry;
240 unsigned long num_sifr;
241 unsigned long status;
242 struct input_dev *input_dev;
246 struct pcc_keyinput {
247 struct acpi_hotkey *hotkey;
251 /* --------------------------------------------------------------------------
252 method access functions
253 -------------------------------------------------------------------------- */
254 static int acpi_pcc_write_sset(struct acpi_hotkey *hotkey, int func, int val)
256 union acpi_object in_objs[] = {
257 { .integer.type = ACPI_TYPE_INTEGER,
258 .integer.value = func, },
259 { .integer.type = ACPI_TYPE_INTEGER,
260 .integer.value = val, },
262 struct acpi_object_list params = {
263 .count = ARRAY_SIZE(in_objs),
266 acpi_status status = AE_OK;
268 ACPI_FUNCTION_TRACE("acpi_pcc_write_sset");
270 status = acpi_evaluate_object(hotkey->handle, METHOD_HKEY_SSET, ¶ms, NULL);
272 return_VALUE(status == AE_OK);
275 static inline int acpi_pcc_get_sqty(struct acpi_device *device)
280 ACPI_FUNCTION_TRACE("acpi_pcc_get_sqty");
282 status = acpi_evaluate_integer(device->handle, METHOD_HKEY_SQTY, NULL, &s);
283 if (ACPI_SUCCESS(status)) {
286 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
287 "evaluation error HKEY.SQTY\n"));
288 return_VALUE(-EINVAL);
292 static int acpi_pcc_retrieve_biosdata(struct acpi_hotkey *hotkey, u32* sinf)
295 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
296 union acpi_object *hkey = NULL;
299 ACPI_FUNCTION_TRACE("acpi_pcc_retrieve_biosdata");
301 status = acpi_evaluate_object(hotkey->handle, METHOD_HKEY_SINF, 0 , &buffer);
302 if (ACPI_FAILURE(status)) {
303 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "evaluation error HKEY.SINF\n"));
307 hkey = buffer.pointer;
308 if (!hkey || (hkey->type != ACPI_TYPE_PACKAGE)) {
309 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid HKEY.SINF\n"));
313 if (hotkey->num_sifr < hkey->package.count) {
314 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "SQTY reports bad SINF length\n"));
319 for (i = 0; i < hkey->package.count; i++) {
320 union acpi_object *element = &(hkey->package.elements[i]);
321 if (likely(element->type == ACPI_TYPE_INTEGER)) {
322 sinf[i] = element->integer.value;
324 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid HKEY.SINF data\n"));
327 sinf[hkey->package.count] = -1;
330 kfree(buffer.pointer);
331 return_VALUE(status == AE_OK);
334 static int acpi_pcc_read_sinf_field(struct seq_file *seq, int field)
336 struct acpi_hotkey *hotkey = (struct acpi_hotkey *) seq->private;
337 u32* sinf = kmalloc(sizeof(u32) * (hotkey->num_sifr + 1), GFP_KERNEL);
339 ACPI_FUNCTION_TRACE("acpi_pcc_read_sinf_field");
342 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Couldn't allocate %li bytes\n",
343 sizeof(u32) * hotkey->num_sifr));
347 if (acpi_pcc_retrieve_biosdata(hotkey, sinf)) {
348 seq_printf(seq, "%u\n", sinf[field]);
350 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Couldn't retrieve BIOS data\n"));
357 /* --------------------------------------------------------------------------
358 user interface functions
359 -------------------------------------------------------------------------- */
361 /* Sinf read methods */
362 #define PCC_SINF_READ_F(_name_, FUNC) \
363 static int _name_ (struct seq_file *seq, void *offset) \
365 return acpi_pcc_read_sinf_field(seq, (FUNC)); \
368 PCC_SINF_READ_F(acpi_pcc_numbatteries_show, SINF_NUM_BATTERIES);
369 PCC_SINF_READ_F(acpi_pcc_lcdtype_show, SINF_LCD_TYPE);
370 PCC_SINF_READ_F(acpi_pcc_ac_brightness_max_show, SINF_AC_MAX_BRIGHT);
371 PCC_SINF_READ_F(acpi_pcc_ac_brightness_min_show, SINF_AC_MIN_BRIGHT);
372 PCC_SINF_READ_F(acpi_pcc_ac_brightness_show, SINF_AC_CUR_BRIGHT);
373 PCC_SINF_READ_F(acpi_pcc_dc_brightness_max_show, SINF_DC_MAX_BRIGHT);
374 PCC_SINF_READ_F(acpi_pcc_dc_brightness_min_show, SINF_DC_MIN_BRIGHT);
375 PCC_SINF_READ_F(acpi_pcc_dc_brightness_show, SINF_DC_CUR_BRIGHT);
376 PCC_SINF_READ_F(acpi_pcc_brightness_show, SINF_AC_CUR_BRIGHT);
377 PCC_SINF_READ_F(acpi_pcc_mute_show, SINF_MUTE);
379 static int acpi_pcc_sticky_key_show(struct seq_file *seq, void *offset)
381 struct acpi_hotkey *hotkey = seq->private;
383 ACPI_FUNCTION_TRACE("acpi_pcc_sticky_key_show");
385 if (!hotkey || !hotkey->device) {
389 seq_printf(seq, "%d\n", hotkey->sticky_mode);
394 static int acpi_pcc_keyinput_show(struct seq_file *seq, void *offset)
396 struct acpi_hotkey *hotkey = (struct acpi_hotkey *) seq->private;
397 struct input_dev *hotk_input_dev = hotkey->input_dev;
398 struct pcc_keyinput *keyinput = input_get_drvdata(hotk_input_dev);
400 ACPI_FUNCTION_TRACE("acpi_pcc_keyinput_show");
402 seq_printf(seq, "%d\n", keyinput->key_mode);
407 static int acpi_pcc_version_show(struct seq_file *seq, void *offset)
409 struct acpi_hotkey *hotkey = (struct acpi_hotkey *) seq->private;
411 ACPI_FUNCTION_TRACE("acpi_pcc_version_show");
413 if (!hotkey || !hotkey->device)
416 seq_printf(seq, "%s version %s\n", ACPI_PCC_DRIVER_NAME, ACPI_PCC_VERSION);
417 seq_printf(seq, "%li functions\n", hotkey->num_sifr);
423 static ssize_t acpi_pcc_write_single_flag (struct file *file,
424 const char __user *buffer,
428 struct seq_file *seq = file->private_data;
429 struct acpi_hotkey *hotkey = seq->private;
430 char write_string[PROC_STR_MAX_LEN];
433 ACPI_FUNCTION_TRACE("acpi_pcc_write_single_flag");
435 if (!hotkey || (count > sizeof(write_string) - 1)) {
436 return_VALUE(-EINVAL);
439 if (copy_from_user(write_string, buffer, count)) {
440 return_VALUE(-EFAULT);
442 write_string[count] = '\0';
444 if (sscanf(write_string, "%i", &val) == 1 && (val == 0 || val == 1)) {
445 acpi_pcc_write_sset(hotkey, sinf_func, val);
451 static unsigned long acpi_pcc_write_brightness(struct file *file, const char __user *buffer,
453 int min_index, int max_index,
456 struct seq_file *seq = (struct seq_file *)file->private_data;
457 struct acpi_hotkey *hotkey = (struct acpi_hotkey *)seq->private;
458 char write_string[PROC_STR_MAX_LEN];
460 u32* sinf = kmalloc(sizeof(u32) * (hotkey->num_sifr + 1), GFP_KERNEL);
462 ACPI_FUNCTION_TRACE("acpi_pcc_write_brightness");
464 if (!hotkey || (count > sizeof(write_string) - 1))
465 return_VALUE(-EINVAL);
468 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Couldn't allocate %li bytes\n",
469 sizeof(u32) * hotkey->num_sifr));
470 return_VALUE(-EFAULT);
473 if (copy_from_user(write_string, buffer, count))
474 return_VALUE(-EFAULT);
476 write_string[count] = '\0';
478 if (!acpi_pcc_retrieve_biosdata(hotkey, sinf)) {
479 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Couldn't retrieve BIOS data\n"));
483 if (sscanf(write_string, "%i", &bright) == 1 &&
484 bright >= sinf[min_index] && bright <= sinf[max_index]) {
485 acpi_pcc_write_sset(hotkey, cur_index, bright);
493 static ssize_t acpi_pcc_write_ac_brightness(struct file *file, const char __user *buffer,
494 size_t count, loff_t *ppos)
496 return acpi_pcc_write_brightness(file, buffer, count, SINF_AC_MIN_BRIGHT,
501 static ssize_t acpi_pcc_write_dc_brightness(struct file *file, const char __user *buffer,
502 size_t count, loff_t *ppos)
504 return acpi_pcc_write_brightness(file, buffer, count, SINF_DC_MIN_BRIGHT,
509 static ssize_t acpi_pcc_write_no_brightness(struct file *file, const char __user *buffer,
510 size_t count, loff_t *ppos)
512 return acpi_pcc_write_brightness(file, buffer, count, SINF_AC_MIN_BRIGHT,
517 static ssize_t acpi_pcc_write_mute (struct file *file,
518 const char __user *buffer,
519 size_t count, loff_t *ppos)
521 return acpi_pcc_write_single_flag(file, buffer, count, SINF_MUTE);
524 static ssize_t acpi_pcc_write_sticky_key (struct file *file,
525 const char __user *buffer,
526 size_t count, loff_t *ppos)
528 return acpi_pcc_write_single_flag(file, buffer, count, SINF_STICKY_KEY);
531 static ssize_t acpi_pcc_write_keyinput(struct file *file, const char __user *buffer,
532 size_t count, loff_t *ppos)
534 struct seq_file *seq = (struct seq_file *)file->private_data;
535 struct acpi_hotkey *hotkey = (struct acpi_hotkey *)seq->private;
536 struct pcc_keyinput *keyinput;
537 char write_string[PROC_STR_MAX_LEN];
540 ACPI_FUNCTION_TRACE("acpi_pcc_write_keyinput");
542 if (!hotkey || (count > sizeof(write_string) - 1))
543 return_VALUE(-EINVAL);
545 if (copy_from_user(write_string, buffer, count))
546 return_VALUE(-EFAULT);
548 write_string[count] = '\0';
550 if (sscanf(write_string, "%i", &key_mode) == 1 && (key_mode == 0 || key_mode == 1)) {
551 keyinput = (struct pcc_keyinput *)input_get_drvdata(hotkey->input_dev);
552 keyinput->key_mode = key_mode;
558 /* --------------------------------------------------------------------------
560 -------------------------------------------------------------------------- */
561 static void acpi_pcc_generete_keyinput(struct acpi_hotkey *hotkey)
563 struct input_dev *hotk_input_dev = hotkey->input_dev;
564 struct pcc_keyinput *keyinput = input_get_drvdata(hotk_input_dev);
565 int hinf = hotkey->status;
566 int key_code, hkey_num;
567 const int key_map[] = {
569 /* 1 */ KEY_BRIGHTNESSDOWN,
570 /* 2 */ KEY_BRIGHTNESSUP,
571 /* 3 */ -1, /* vga/lcd switch event is not occur on hotkey driver. */
573 /* 5 */ KEY_VOLUMEDOWN,
574 /* 6 */ KEY_VOLUMEUP,
576 /* 8 */ -1, /* Change CPU boost: do nothing */
578 /* 10 */ KEY_SUSPEND,
581 ACPI_FUNCTION_TRACE("acpi_pcc_generete_keyinput");
583 if (keyinput->key_mode == 0) { return_VOID; }
585 hkey_num = hinf & 0xf;
587 if (( 0 > hkey_num ) ||
588 (hkey_num > ARRAY_SIZE(key_map))) {
589 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
590 "hotkey number out of range: %d\n",
595 key_code = key_map[hkey_num];
597 if (key_code != -1) {
598 int pushed = (hinf & 0x80) ? TRUE : FALSE;
600 input_report_key(hotk_input_dev, key_code, pushed);
601 input_sync(hotk_input_dev);
605 static int acpi_pcc_hotkey_get_key(struct acpi_hotkey *hotkey)
607 unsigned long result;
608 acpi_status status = AE_OK;
610 ACPI_FUNCTION_TRACE("acpi_pcc_hotkey_get_key");
612 status = acpi_evaluate_integer(hotkey->handle, METHOD_HKEY_QUERY, NULL, &result);
613 if (likely(ACPI_SUCCESS(status))) {
614 hotkey->status = result;
616 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "error getting hotkey status\n"));
619 return_VALUE(status == AE_OK);
622 void acpi_pcc_hotkey_notify(acpi_handle handle, u32 event, void *data)
624 struct acpi_hotkey *hotkey = (struct acpi_hotkey *) data;
626 ACPI_FUNCTION_TRACE("acpi_pcc_hotkey_notify");
630 if (acpi_pcc_hotkey_get_key(hotkey)) {
631 /* generate event like '"pcc HKEY 00000080 00000084"' when Fn+F4 pressed */
632 acpi_bus_generate_proc_event(hotkey->device, event, hotkey->status);
634 acpi_pcc_generete_keyinput(hotkey);
643 /* --------------------------------------------------------------------------
645 -------------------------------------------------------------------------- */
646 /* oepn proc file fs*/
647 SEQ_OPEN_FS(acpi_pcc_dc_brightness_open_fs, acpi_pcc_dc_brightness_show);
648 SEQ_OPEN_FS(acpi_pcc_numbatteries_open_fs, acpi_pcc_numbatteries_show);
649 SEQ_OPEN_FS(acpi_pcc_lcdtype_open_fs, acpi_pcc_lcdtype_show);
650 SEQ_OPEN_FS(acpi_pcc_ac_brightness_max_open_fs, acpi_pcc_ac_brightness_max_show);
651 SEQ_OPEN_FS(acpi_pcc_ac_brightness_min_open_fs, acpi_pcc_ac_brightness_min_show);
652 SEQ_OPEN_FS(acpi_pcc_ac_brightness_open_fs, acpi_pcc_ac_brightness_show);
653 SEQ_OPEN_FS(acpi_pcc_dc_brightness_max_open_fs, acpi_pcc_dc_brightness_max_show);
654 SEQ_OPEN_FS(acpi_pcc_dc_brightness_min_open_fs, acpi_pcc_dc_brightness_min_show);
655 SEQ_OPEN_FS(acpi_pcc_brightness_open_fs, acpi_pcc_brightness_show);
656 SEQ_OPEN_FS(acpi_pcc_mute_open_fs, acpi_pcc_mute_show);
657 SEQ_OPEN_FS(acpi_pcc_version_open_fs, acpi_pcc_version_show);
658 SEQ_OPEN_FS(acpi_pcc_keyinput_open_fs, acpi_pcc_keyinput_show);
659 SEQ_OPEN_FS(acpi_pcc_sticky_key_open_fs, acpi_pcc_sticky_key_show);
661 typedef struct file_operations fops_t;
662 static fops_t acpi_pcc_numbatteries_fops = SEQ_FILEOPS_R (acpi_pcc_numbatteries_open_fs);
663 static fops_t acpi_pcc_lcdtype_fops = SEQ_FILEOPS_R (acpi_pcc_lcdtype_open_fs);
664 static fops_t acpi_pcc_mute_fops = SEQ_FILEOPS_RW(acpi_pcc_mute_open_fs, acpi_pcc_write_mute);
665 static fops_t acpi_pcc_ac_brightness_fops = SEQ_FILEOPS_RW(acpi_pcc_ac_brightness_open_fs, acpi_pcc_write_ac_brightness);
666 static fops_t acpi_pcc_ac_brightness_max_fops = SEQ_FILEOPS_R(acpi_pcc_ac_brightness_max_open_fs);
667 static fops_t acpi_pcc_ac_brightness_min_fops = SEQ_FILEOPS_R(acpi_pcc_ac_brightness_min_open_fs);
668 static fops_t acpi_pcc_dc_brightness_fops = SEQ_FILEOPS_RW(acpi_pcc_dc_brightness_open_fs, acpi_pcc_write_dc_brightness);
669 static fops_t acpi_pcc_dc_brightness_max_fops = SEQ_FILEOPS_R(acpi_pcc_dc_brightness_max_open_fs);
670 static fops_t acpi_pcc_dc_brightness_min_fops = SEQ_FILEOPS_R(acpi_pcc_dc_brightness_min_open_fs);
671 static fops_t acpi_pcc_brightness_fops = SEQ_FILEOPS_RW(acpi_pcc_brightness_open_fs, acpi_pcc_write_no_brightness);
672 static fops_t acpi_pcc_sticky_key_fops = SEQ_FILEOPS_RW(acpi_pcc_sticky_key_open_fs, acpi_pcc_write_sticky_key);
673 static fops_t acpi_pcc_keyinput_fops = SEQ_FILEOPS_RW(acpi_pcc_keyinput_open_fs, acpi_pcc_write_keyinput);
674 static fops_t acpi_pcc_version_fops = SEQ_FILEOPS_R (acpi_pcc_version_open_fs);
676 typedef struct _ProcItem
679 struct file_operations *fops;
683 /* Note: These functions map *exactly* to the SINF/SSET functions */
684 ProcItem pcc_proc_items_sifr[] =
686 { "num_batteries", &acpi_pcc_numbatteries_fops, S_IRUGO },
687 { "lcd_type", &acpi_pcc_lcdtype_fops, S_IRUGO },
688 { "ac_brightness_max" , &acpi_pcc_ac_brightness_max_fops,S_IRUGO },
689 { "ac_brightness_min" , &acpi_pcc_ac_brightness_min_fops,S_IRUGO },
690 { "ac_brightness" , &acpi_pcc_ac_brightness_fops, S_IFREG | S_IRUGO | S_IWUSR },
691 { "dc_brightness_max" , &acpi_pcc_dc_brightness_max_fops,S_IRUGO },
692 { "dc_brightness_min" , &acpi_pcc_dc_brightness_min_fops,S_IRUGO },
693 { "dc_brightness" , &acpi_pcc_dc_brightness_fops, S_IFREG | S_IRUGO | S_IWUSR },
694 { "brightness" , &acpi_pcc_brightness_fops, S_IFREG | S_IRUGO | S_IWUSR },
695 { "mute", &acpi_pcc_mute_fops, S_IFREG | S_IRUGO | S_IWUSR },
699 ProcItem pcc_proc_items[] =
701 { "sticky_key", &acpi_pcc_sticky_key_fops, S_IFREG | S_IRUGO | S_IWUSR },
702 { "keyinput", &acpi_pcc_keyinput_fops, S_IFREG | S_IRUGO | S_IWUSR },
703 { "version", &acpi_pcc_version_fops, S_IRUGO },
707 static int acpi_pcc_add_device(struct acpi_device *device,
708 ProcItem *proc_items,
711 struct proc_dir_entry* proc;
714 struct acpi_hotkey *hotkey = (struct acpi_hotkey*)acpi_driver_data(device);
716 for (item = proc_items, i = 0; item->name && i < num; ++item, ++i) {
717 proc = create_proc_entry(item->name, item->flag, hotkey->proc_dir_entry);
719 proc->proc_fops = item->fops;
721 proc->owner = THIS_MODULE;
725 remove_proc_entry(item->name, hotkey->proc_dir_entry);
733 static int acpi_pcc_proc_init(struct acpi_device *device)
735 struct proc_dir_entry* acpi_pcc_dir;
736 struct acpi_hotkey *hotkey = (struct acpi_hotkey*)acpi_driver_data(device);
739 ACPI_FUNCTION_TRACE("acpi_pcc_proc_init");
741 acpi_pcc_dir = proc_mkdir(PROC_PCC, acpi_root_dir);
743 if (unlikely(!acpi_pcc_dir)) {
744 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Couldn't create dir in /proc\n"));
745 return_VALUE(-ENODEV);
748 acpi_pcc_dir->owner = THIS_MODULE;
749 hotkey->proc_dir_entry = acpi_pcc_dir;
751 status = acpi_pcc_add_device(device, pcc_proc_items_sifr, hotkey->num_sifr);
752 status |= acpi_pcc_add_device(device, pcc_proc_items, sizeof(pcc_proc_items)/sizeof(ProcItem));
753 if (unlikely(status)) {
754 remove_proc_entry(PROC_PCC, acpi_root_dir);
755 hotkey->proc_dir_entry = NULL;
756 return_VALUE(-ENODEV);
759 return_VALUE(status);
762 static void acpi_pcc_remove_device(struct acpi_device *device,
763 ProcItem *proc_items,
766 struct acpi_hotkey *hotkey = (struct acpi_hotkey*)acpi_driver_data(device);
770 for (item = proc_items, i = 0; item->name != NULL && i < num; ++item, ++i) {
771 remove_proc_entry(item->name, hotkey->proc_dir_entry);
777 /* --------------------------------------------------------------------------
779 -------------------------------------------------------------------------- */
780 static int acpi_pcc_init_input(struct acpi_hotkey *hotkey)
782 struct input_dev *hotk_input_dev;
783 struct pcc_keyinput *pcc_keyinput;
785 ACPI_FUNCTION_TRACE("acpi_pcc_init_input");
787 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
788 hotk_input_dev = input_allocate_device();
789 if (!hotk_input_dev) {
790 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Couldn't allocate input device for hotkey"));
791 return_VALUE(-ENOMEM);
794 hotk_input_dev = kcalloc(1, sizeof(struct input_dev),GFP_KERNEL);
795 if (hotk_input_dev == NULL) {
796 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Couldn't allocate mem for hotkey"));
797 return_VALUE(-ENOMEM);
801 pcc_keyinput = kcalloc(1,sizeof(struct pcc_keyinput),GFP_KERNEL);
803 if (pcc_keyinput == NULL) {
804 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Couldn't allocate mem for hotkey"));
805 input_unregister_device(hotk_input_dev);
806 return_VALUE(-ENOMEM);
809 hotk_input_dev->evbit[0] = BIT(EV_KEY);
811 set_bit(KEY_BRIGHTNESSDOWN, hotk_input_dev->keybit);
812 set_bit(KEY_BRIGHTNESSUP, hotk_input_dev->keybit);
813 set_bit(KEY_MUTE, hotk_input_dev->keybit);
814 set_bit(KEY_VOLUMEDOWN, hotk_input_dev->keybit);
815 set_bit(KEY_VOLUMEUP, hotk_input_dev->keybit);
816 set_bit(KEY_SLEEP, hotk_input_dev->keybit);
817 set_bit(KEY_BATT, hotk_input_dev->keybit);
818 set_bit(KEY_SUSPEND, hotk_input_dev->keybit);
820 hotk_input_dev->name = ACPI_PCC_DRIVER_NAME;
821 hotk_input_dev->phys = ACPI_PCC_INPUT_PHYS;
822 hotk_input_dev->id.bustype = 0x1a; /* XXX FIXME: BUS_I8042? */
823 hotk_input_dev->id.vendor = 0x0001;
824 hotk_input_dev->id.product = 0x0001;
825 hotk_input_dev->id.version = 0x0100;
827 pcc_keyinput->key_mode = 1; /* default on */
828 pcc_keyinput->hotkey = hotkey;
830 input_set_drvdata(hotk_input_dev, pcc_keyinput);
832 hotkey->input_dev = hotk_input_dev;
835 input_register_device(hotk_input_dev);
840 /* --------------------------------------------------------------------------
842 -------------------------------------------------------------------------- */
844 static int acpi_pcc_hotkey_resume(struct acpi_device *device)
846 struct acpi_hotkey *hotkey = acpi_driver_data(device);
847 acpi_status status = AE_OK;
849 ACPI_FUNCTION_TRACE("acpi_pcc_hotkey_resume");
851 if (device == NULL || hotkey == NULL) { return_VALUE(-EINVAL); }
853 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Sticky mode restore: %d\n", hotkey->sticky_mode));
855 status = acpi_pcc_write_sset(hotkey, SINF_STICKY_KEY, hotkey->sticky_mode);
857 return_VALUE(status == AE_OK ? 0 : -EINVAL);
860 static int acpi_pcc_hotkey_add (struct acpi_device *device)
862 acpi_status status = AE_OK;
863 struct acpi_hotkey *hotkey = NULL;
864 int num_sifr, result;
866 ACPI_FUNCTION_TRACE("acpi_pcc_hotkey_add");
869 return_VALUE(-EINVAL);
872 num_sifr = acpi_pcc_get_sqty(device);
874 if (num_sifr > 255) {
875 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "num_sifr too large"));
876 return_VALUE(-ENODEV);
879 hotkey = kmalloc(sizeof(struct acpi_hotkey), GFP_KERNEL);
881 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Couldn't allocate mem for hotkey"));
882 return_VALUE(-ENOMEM);
885 memset(hotkey, 0, sizeof(struct acpi_hotkey));
887 hotkey->device = device;
888 hotkey->handle = device->handle;
889 hotkey->num_sifr = num_sifr;
890 acpi_driver_data(device) = hotkey;
891 strcpy(acpi_device_name(device), ACPI_PCC_DEVICE_NAME);
892 strcpy(acpi_device_class(device), ACPI_PCC_CLASS);
894 status = acpi_install_notify_handler (
897 acpi_pcc_hotkey_notify,
900 if (ACPI_FAILURE(status)) {
901 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error installing notify handler\n"));
903 return_VALUE(-ENODEV);
906 result = acpi_pcc_init_input(hotkey);
908 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error installing keyinput handler\n"));
910 return_VALUE(result);
913 return_VALUE(acpi_pcc_proc_init(device));
916 static int __init acpi_pcc_init(void)
920 ACPI_FUNCTION_TRACE("acpi_pcc_init");
923 return_VALUE(-ENODEV);
926 result = acpi_bus_register_driver(&acpi_pcc_driver);
928 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error registering hotkey driver\n"));
929 return_VALUE(-ENODEV);
935 module_init(acpi_pcc_init);
937 static int acpi_pcc_hotkey_remove(struct acpi_device *device, int type)
939 acpi_status status = AE_OK;
940 struct acpi_hotkey *hotkey = acpi_driver_data(device);
942 ACPI_FUNCTION_TRACE("acpi_pcc_hotkey_remove");
944 if (!device || !hotkey)
945 return_VALUE(-EINVAL);
947 if (hotkey->proc_dir_entry) {
948 acpi_pcc_remove_device(device, pcc_proc_items_sifr, hotkey->num_sifr);
949 acpi_pcc_remove_device(device, pcc_proc_items, sizeof(pcc_proc_items)/sizeof(ProcItem));
950 remove_proc_entry(PROC_PCC, acpi_root_dir);
953 status = acpi_remove_notify_handler(hotkey->handle,
954 ACPI_DEVICE_NOTIFY, acpi_pcc_hotkey_notify);
956 if (ACPI_FAILURE(status))
957 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error removing notify handler\n"));
959 input_unregister_device(hotkey->input_dev);
962 return_VALUE(status == AE_OK);
965 static void __exit acpi_pcc_exit(void)
967 ACPI_FUNCTION_TRACE("acpi_pcc_exit");
969 acpi_bus_unregister_driver(&acpi_pcc_driver);
974 module_exit(acpi_pcc_exit);