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+hy"
99 #include <acpi/acpi_bus.h>
100 #include <acpi/acpi_drivers.h>
101 #include <asm/uaccess.h>
102 #include <linux/ctype.h>
103 #include <linux/init.h>
104 #include <linux/input.h>
105 #include <linux/kernel.h>
106 #include <linux/module.h>
107 #include <linux/proc_fs.h>
108 #include <linux/seq_file.h>
109 #include <linux/slab.h>
110 #include <linux/types.h>
111 #include <linux/version.h>
114 /*************************************************************************
115 * "seq" file template definition.
117 /* "seq" initializer */
118 #define SEQ_OPEN_FS(_open_func_name_, _show_func_name_) \
119 static int _open_func_name_(struct inode *inode, struct file *file) \
121 return single_open(file, _show_func_name_, PDE(inode)->data); \
124 /*-------------------------------------------------------------------------
125 * "seq" fops template for read-only files.
127 #define SEQ_FILEOPS_R(_open_func_name_) \
129 .open = _open_func_name_, \
131 .llseek = seq_lseek, \
132 .release = single_release, \
135 /*------------------------------------------------------------------------
136 * "seq" fops template for read-write files.
138 #define SEQ_FILEOPS_RW(_open_func_name_, _write_func_name_) \
140 .open = _open_func_name_ , \
142 .write = _write_func_name_, \
143 .llseek = seq_lseek, \
144 .release = single_release, \
148 * "seq" file template definition ended.
149 ***************************************************************************
151 #ifndef ACPI_HOTKEY_COMPONENT
152 #define ACPI_HOTKEY_COMPONENT 0x10000000
155 #define _COMPONENT ACPI_HOTKEY_COMPONENT
156 ACPI_MODULE_NAME("pcc_acpi");
158 MODULE_AUTHOR("Hiroshi Miura, Hiroshi Yokota");
159 MODULE_DESCRIPTION("ACPI HotKey driver for Panasonic Let's Note laptops");
160 MODULE_LICENSE("GPL");
162 #define LOGPREFIX "pcc_acpi: "
164 /****************************************************
166 ****************************************************/
167 /* Lets note hotkeys */
168 #define METHOD_HKEY_QUERY "HINF"
169 #define METHOD_HKEY_SQTY "SQTY"
170 #define METHOD_HKEY_SINF "SINF"
171 #define METHOD_HKEY_SSET "SSET"
172 #define HKEY_NOTIFY 0x80
174 /* for brightness control */
175 #define LCD_MAX_BRIGHTNESS 255
176 /* This may be magical -- beware */
177 #define LCD_BRIGHTNESS_INCREMENT 17
178 /* Registers of SINF */
179 #define SINF_LCD_BRIGHTNESS 4
181 /*******************************************************************
183 * definitions for /proc/ interface
185 *******************************************************************/
186 #define ACPI_PCC_DRIVER_NAME "pcc_acpi"
187 #define ACPI_PCC_DEVICE_NAME "PCCExtra"
188 #define ACPI_PCC_CLASS "pcc"
189 #define PROC_PCC ACPI_PCC_CLASS
191 #define ACPI_PCC_INPUT_PHYS "panasonic/hkey0"
193 /* This is transitional definition */
195 # define KEY_BATT 227
198 #define PROC_STR_MAX_LEN 8
200 #define BUS_PCC_HOTKEY BUS_I8042 /*0x1a*/ /* FIXME: BUS_I8042? */
202 /* Fn+F4/F5 confricts with Shift+F1/F2 */
203 /* This hack avoids key number confrict */
204 #define PCC_KEYINPUT_MODE (0)
206 /* LCD_TYPEs: 0 = Normal, 1 = Semi-transparent
207 ENV_STATEs: Normal temp=0x01, High temp=0x81, N/A=0x00
209 enum SINF_BITS { SINF_NUM_BATTERIES = 0,
210 SINF_LCD_TYPE, /* 1 */
211 SINF_AC_MAX_BRIGHT, SINF_AC_MIN_BRIGHT, SINF_AC_CUR_BRIGHT, /* 2, 3, 4 */
212 /* 4 = R1 only handle SINF_AC_CUR_BRIGHT as SINF_CUR_BRIGHT and don't know AC state */
213 SINF_DC_MAX_BRIGHT, SINF_DC_MIN_BRIGHT, SINF_DC_CUR_BRIGHT, /* 5, 6, 7 */
215 SINF_RESERVED, SINF_ENV_STATE, /* 9, 10 */
216 SINF_STICKY_KEY = 0x80,
219 static struct acpi_device_id pcc_device_ids[] = {
226 MODULE_DEVICE_TABLE(acpi, pcc_device_ids);
229 static int __devinit acpi_pcc_hotkey_add(struct acpi_device *device);
230 static int __devexit acpi_pcc_hotkey_remove(struct acpi_device *device, int type);
231 static int acpi_pcc_hotkey_resume(struct acpi_device *device);
234 static struct acpi_driver acpi_pcc_driver = {
235 .name = ACPI_PCC_DRIVER_NAME,
236 .class = ACPI_PCC_CLASS,
237 .ids = pcc_device_ids,
239 .add = acpi_pcc_hotkey_add,
240 .remove = __devexit_p(acpi_pcc_hotkey_remove),
242 /*.suspend = acpi_pcc_hotkey_suspend,*/
243 .resume = acpi_pcc_hotkey_resume,
250 struct acpi_device *device;
251 struct proc_dir_entry *proc_dir_entry;
252 unsigned long num_sifr;
253 unsigned long status;
254 struct input_dev *input_dev;
258 struct pcc_keyinput {
259 struct acpi_hotkey *hotkey;
263 /* *************************************************************************
265 ************************************************************************* */
266 /* -------------------------------------------------------------------------
267 method access functions
268 ------------------------------------------------------------------------- */
269 static int acpi_pcc_write_sset(struct acpi_hotkey *hotkey, int func, int val)
271 union acpi_object in_objs[] = {
272 { .integer.type = ACPI_TYPE_INTEGER,
273 .integer.value = func, },
274 { .integer.type = ACPI_TYPE_INTEGER,
275 .integer.value = val, },
277 struct acpi_object_list params = {
278 .count = ARRAY_SIZE(in_objs),
283 ACPI_FUNCTION_TRACE("acpi_pcc_write_sset");
285 status = acpi_evaluate_object(hotkey->handle, METHOD_HKEY_SSET, ¶ms, NULL);
287 return_VALUE(status == AE_OK ? AE_OK : AE_ERROR);
290 static inline int acpi_pcc_get_sqty(struct acpi_device *device)
295 ACPI_FUNCTION_TRACE("acpi_pcc_get_sqty");
297 status = acpi_evaluate_integer(device->handle, METHOD_HKEY_SQTY, NULL, &s);
298 if (ACPI_SUCCESS(status)) {
301 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
302 "evaluation error HKEY.SQTY\n"));
303 return_VALUE(-EINVAL);
307 static int acpi_pcc_retrieve_biosdata(struct acpi_hotkey *hotkey, u32* sinf)
310 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
311 union acpi_object *hkey = NULL;
314 ACPI_FUNCTION_TRACE("acpi_pcc_retrieve_biosdata");
316 status = acpi_evaluate_object(hotkey->handle, METHOD_HKEY_SINF, 0 , &buffer);
317 if (ACPI_FAILURE(status)) {
318 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "evaluation error HKEY.SINF\n"));
320 return_VALUE(status);
323 hkey = buffer.pointer;
324 if (!hkey || (hkey->type != ACPI_TYPE_PACKAGE)) {
325 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid HKEY.SINF\n"));
329 if (hotkey->num_sifr < hkey->package.count) {
330 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "SQTY reports bad SINF length\n"));
335 for (i = 0; i < hkey->package.count; i++) {
336 union acpi_object *element = &(hkey->package.elements[i]);
337 if (likely(element->type == ACPI_TYPE_INTEGER)) {
338 sinf[i] = element->integer.value;
340 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid HKEY.SINF data\n"));
345 sinf[hkey->package.count] = -1;
348 kfree(buffer.pointer);
349 return_VALUE(status == AE_OK ? AE_OK : AE_ERROR);
352 static int acpi_pcc_read_sinf_field(struct seq_file *seq, int field)
354 struct acpi_hotkey *hotkey = (struct acpi_hotkey *) seq->private;
355 u32 sinf[hotkey->num_sifr + 1];
357 ACPI_FUNCTION_TRACE("acpi_pcc_read_sinf_field");
359 if (ACPI_SUCCESS(acpi_pcc_retrieve_biosdata(hotkey, sinf))) {
360 seq_printf(seq, "%u\n", sinf[field]);
362 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Couldn't retrieve BIOS data\n"));
368 /* -------------------------------------------------------------------------
369 user interface functions
370 ------------------------------------------------------------------------- */
372 /* Sinf read methods */
373 #define PCC_SINF_READ_F(_name_, FUNC) \
374 static int _name_ (struct seq_file *seq, void *offset) \
376 return_VALUE(ACPI_SUCCESS(acpi_pcc_read_sinf_field(seq, (FUNC))) ? 0 : -EINVAL); \
379 PCC_SINF_READ_F(acpi_pcc_numbatteries_show, SINF_NUM_BATTERIES);
380 PCC_SINF_READ_F(acpi_pcc_lcdtype_show, SINF_LCD_TYPE);
381 PCC_SINF_READ_F(acpi_pcc_ac_brightness_max_show, SINF_AC_MAX_BRIGHT);
382 PCC_SINF_READ_F(acpi_pcc_ac_brightness_min_show, SINF_AC_MIN_BRIGHT);
383 PCC_SINF_READ_F(acpi_pcc_ac_brightness_show, SINF_AC_CUR_BRIGHT);
384 PCC_SINF_READ_F(acpi_pcc_dc_brightness_max_show, SINF_DC_MAX_BRIGHT);
385 PCC_SINF_READ_F(acpi_pcc_dc_brightness_min_show, SINF_DC_MIN_BRIGHT);
386 PCC_SINF_READ_F(acpi_pcc_dc_brightness_show, SINF_DC_CUR_BRIGHT);
387 PCC_SINF_READ_F(acpi_pcc_brightness_show, SINF_AC_CUR_BRIGHT);
388 PCC_SINF_READ_F(acpi_pcc_mute_show, SINF_MUTE);
390 static int acpi_pcc_sticky_key_show(struct seq_file *seq, void *offset)
392 struct acpi_hotkey *hotkey = seq->private;
394 ACPI_FUNCTION_TRACE("acpi_pcc_sticky_key_show");
396 if (!hotkey || !hotkey->device) {
397 return_VALUE(-EINVAL);
400 seq_printf(seq, "%d\n", hotkey->sticky_mode);
405 static int acpi_pcc_keyinput_show(struct seq_file *seq, void *offset)
407 struct acpi_hotkey *hotkey = (struct acpi_hotkey *) seq->private;
408 struct input_dev *hotk_input_dev = hotkey->input_dev;
409 struct pcc_keyinput *keyinput = input_get_drvdata(hotk_input_dev);
411 ACPI_FUNCTION_TRACE("acpi_pcc_keyinput_show");
413 seq_printf(seq, "%d\n", keyinput->key_mode);
418 static int acpi_pcc_version_show(struct seq_file *seq, void *offset)
420 struct acpi_hotkey *hotkey = (struct acpi_hotkey *) seq->private;
422 ACPI_FUNCTION_TRACE("acpi_pcc_version_show");
424 if (!hotkey || !hotkey->device) {
425 return_VALUE(-EINVAL);
428 seq_printf(seq, "%s version %s\n", ACPI_PCC_DRIVER_NAME, ACPI_PCC_VERSION);
429 seq_printf(seq, "%li functions\n", hotkey->num_sifr);
435 static ssize_t acpi_pcc_write_single_flag (struct file *file,
436 const char __user *buffer,
440 struct seq_file *seq = file->private_data;
441 struct acpi_hotkey *hotkey = seq->private;
442 char write_string[PROC_STR_MAX_LEN];
445 ACPI_FUNCTION_TRACE("acpi_pcc_write_single_flag");
447 if (!hotkey || (count > sizeof(write_string) - 1)) {
448 return_VALUE(-EINVAL);
451 if (copy_from_user(write_string, buffer, count)) {
452 return_VALUE(-EFAULT);
454 write_string[count] = '\0';
456 if ((sscanf(write_string, "%3i", &val) == 1) &&
457 (val == 0 || val == 1)) {
458 acpi_pcc_write_sset(hotkey, sinf_func, val);
464 static unsigned long acpi_pcc_write_brightness(struct file *file, const char __user *buffer,
466 int min_index, int max_index,
469 struct seq_file *seq = (struct seq_file *)file->private_data;
470 struct acpi_hotkey *hotkey = (struct acpi_hotkey *)seq->private;
471 char write_string[PROC_STR_MAX_LEN];
473 u32 sinf[hotkey->num_sifr + 1];
475 ACPI_FUNCTION_TRACE("acpi_pcc_write_brightness");
477 if (!hotkey || (count > sizeof(write_string) - 1)) {
478 return_VALUE(-EINVAL);
481 if (copy_from_user(write_string, buffer, count)) {
482 return_VALUE(-EFAULT);
485 write_string[count] = '\0';
487 if (ACPI_FAILURE(acpi_pcc_retrieve_biosdata(hotkey, sinf))) {
488 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Couldn't retrieve BIOS data\n"));
492 if ((sscanf(write_string, "%4i", &bright) == 1) &&
493 (bright >= sinf[min_index] ) &&
494 (bright <= sinf[max_index] )) {
495 acpi_pcc_write_sset(hotkey, cur_index, bright);
502 static ssize_t acpi_pcc_write_ac_brightness(struct file *file, const char __user *buffer,
503 size_t count, loff_t *ppos)
505 return_VALUE(acpi_pcc_write_brightness(file, buffer, count,
508 SINF_AC_CUR_BRIGHT));
511 static ssize_t acpi_pcc_write_dc_brightness(struct file *file, const char __user *buffer,
512 size_t count, loff_t *ppos)
514 return_VALUE(acpi_pcc_write_brightness(file, buffer, count,
517 SINF_DC_CUR_BRIGHT));
520 static ssize_t acpi_pcc_write_no_brightness(struct file *file, const char __user *buffer,
521 size_t count, loff_t *ppos)
523 return acpi_pcc_write_brightness(file, buffer, count, SINF_AC_MIN_BRIGHT,
528 static ssize_t acpi_pcc_write_mute (struct file *file,
529 const char __user *buffer,
530 size_t count, loff_t *ppos)
532 return_VALUE(acpi_pcc_write_single_flag(file, buffer, count, SINF_MUTE));
535 static ssize_t acpi_pcc_write_sticky_key (struct file *file,
536 const char __user *buffer,
537 size_t count, loff_t *ppos)
539 struct seq_file *seq = (struct seq_file *)file->private_data;
540 struct acpi_hotkey *hotkey = (struct acpi_hotkey *)seq->private;
541 char write_string[PROC_STR_MAX_LEN];
544 ACPI_FUNCTION_TRACE("acpi_pcc_write_sticky_key");
546 if (!hotkey || (count > sizeof(write_string) - 1)) {
547 return_VALUE(-EINVAL);
550 if (copy_from_user(write_string, buffer, count)) {
551 return_VALUE(-EFAULT);
553 write_string[count] = '\0';
555 if ((sscanf(write_string, "%3i", &mode) == 1) &&
556 (mode == 0 || mode == 1)) {
557 acpi_pcc_write_sset(hotkey, SINF_STICKY_KEY, mode);
558 hotkey->sticky_mode = mode;
564 static ssize_t acpi_pcc_write_keyinput(struct file *file, const char __user *buffer,
565 size_t count, loff_t *ppos)
567 struct seq_file *seq = (struct seq_file *)file->private_data;
568 struct acpi_hotkey *hotkey = (struct acpi_hotkey *)seq->private;
569 struct pcc_keyinput *keyinput;
570 char write_string[PROC_STR_MAX_LEN];
573 ACPI_FUNCTION_TRACE("acpi_pcc_write_keyinput");
575 if (!hotkey || (count > (sizeof(write_string) - 1))) {
576 return_VALUE(-EINVAL);
579 if (copy_from_user(write_string, buffer, count)) {
580 return_VALUE(-EFAULT);
583 write_string[count] = '\0';
585 if ((sscanf(write_string, "%4i", &key_mode) == 1) &&
586 (key_mode == 0 || key_mode == 1)) {
587 keyinput = input_get_drvdata(hotkey->input_dev);
588 keyinput->key_mode = key_mode;
594 /* -------------------------------------------------------------------------
596 ------------------------------------------------------------------------- */
597 static void acpi_pcc_generete_keyinput(struct acpi_hotkey *hotkey)
599 struct input_dev *hotk_input_dev = hotkey->input_dev;
600 struct pcc_keyinput *keyinput = input_get_drvdata(hotk_input_dev);
601 int hinf = hotkey->status;
602 int key_code, hkey_num;
603 const int key_map[] = {
605 /* 1 */ KEY_BRIGHTNESSDOWN,
606 /* 2 */ KEY_BRIGHTNESSUP,
607 /* 3 */ -1, /* vga/lcd switch event is not occur on hotkey driver. */
609 /* 5 */ KEY_VOLUMEDOWN,
610 /* 6 */ KEY_VOLUMEUP,
612 /* 8 */ -1, /* Change CPU boost: do nothing */
614 /* 10 */ KEY_SUSPEND,
617 ACPI_FUNCTION_TRACE("acpi_pcc_generete_keyinput");
619 if (keyinput->key_mode == 0) { return_VOID; }
621 hkey_num = hinf & 0xf;
623 if (( 0 > hkey_num ) ||
624 (hkey_num > ARRAY_SIZE(key_map))) {
625 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
626 "hotkey number out of range: %d\n",
631 key_code = key_map[hkey_num];
633 if (key_code != -1) {
634 int pushed = (hinf & 0x80) ? TRUE : FALSE;
636 input_report_key(hotk_input_dev, key_code, pushed);
637 input_sync(hotk_input_dev);
641 static int acpi_pcc_hotkey_get_key(struct acpi_hotkey *hotkey)
643 unsigned long result;
644 acpi_status status = AE_OK;
646 ACPI_FUNCTION_TRACE("acpi_pcc_hotkey_get_key");
648 status = acpi_evaluate_integer(hotkey->handle, METHOD_HKEY_QUERY, NULL, &result);
649 if (likely(ACPI_SUCCESS(status))) {
650 hotkey->status = result;
652 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "error getting hotkey status\n"));
655 return_VALUE(status == AE_OK);
658 void acpi_pcc_hotkey_notify(acpi_handle handle, u32 event, void *data)
660 struct acpi_hotkey *hotkey = (struct acpi_hotkey *) data;
662 ACPI_FUNCTION_TRACE("acpi_pcc_hotkey_notify");
666 if (acpi_pcc_hotkey_get_key(hotkey)) {
667 /* generate event like '"pcc HKEY 00000080 00000084"' when Fn+F4 pressed */
668 acpi_bus_generate_proc_event(hotkey->device, event, hotkey->status);
670 acpi_pcc_generete_keyinput(hotkey);
679 /* *************************************************************************
681 ************************************************************************* */
682 /* oepn proc file fs*/
683 SEQ_OPEN_FS(acpi_pcc_dc_brightness_open_fs, acpi_pcc_dc_brightness_show);
684 SEQ_OPEN_FS(acpi_pcc_numbatteries_open_fs, acpi_pcc_numbatteries_show);
685 SEQ_OPEN_FS(acpi_pcc_lcdtype_open_fs, acpi_pcc_lcdtype_show);
686 SEQ_OPEN_FS(acpi_pcc_ac_brightness_max_open_fs, acpi_pcc_ac_brightness_max_show);
687 SEQ_OPEN_FS(acpi_pcc_ac_brightness_min_open_fs, acpi_pcc_ac_brightness_min_show);
688 SEQ_OPEN_FS(acpi_pcc_ac_brightness_open_fs, acpi_pcc_ac_brightness_show);
689 SEQ_OPEN_FS(acpi_pcc_dc_brightness_max_open_fs, acpi_pcc_dc_brightness_max_show);
690 SEQ_OPEN_FS(acpi_pcc_dc_brightness_min_open_fs, acpi_pcc_dc_brightness_min_show);
691 SEQ_OPEN_FS(acpi_pcc_brightness_open_fs, acpi_pcc_brightness_show);
692 SEQ_OPEN_FS(acpi_pcc_mute_open_fs, acpi_pcc_mute_show);
693 SEQ_OPEN_FS(acpi_pcc_version_open_fs, acpi_pcc_version_show);
694 SEQ_OPEN_FS(acpi_pcc_keyinput_open_fs, acpi_pcc_keyinput_show);
695 SEQ_OPEN_FS(acpi_pcc_sticky_key_open_fs, acpi_pcc_sticky_key_show);
697 typedef struct file_operations fops_t;
698 static fops_t acpi_pcc_numbatteries_fops = SEQ_FILEOPS_R (acpi_pcc_numbatteries_open_fs);
699 static fops_t acpi_pcc_lcdtype_fops = SEQ_FILEOPS_R (acpi_pcc_lcdtype_open_fs);
700 static fops_t acpi_pcc_mute_fops = SEQ_FILEOPS_RW(acpi_pcc_mute_open_fs, acpi_pcc_write_mute);
701 static fops_t acpi_pcc_ac_brightness_fops = SEQ_FILEOPS_RW(acpi_pcc_ac_brightness_open_fs, acpi_pcc_write_ac_brightness);
702 static fops_t acpi_pcc_ac_brightness_max_fops = SEQ_FILEOPS_R (acpi_pcc_ac_brightness_max_open_fs);
703 static fops_t acpi_pcc_ac_brightness_min_fops = SEQ_FILEOPS_R (acpi_pcc_ac_brightness_min_open_fs);
704 static fops_t acpi_pcc_dc_brightness_fops = SEQ_FILEOPS_RW(acpi_pcc_dc_brightness_open_fs, acpi_pcc_write_dc_brightness);
705 static fops_t acpi_pcc_dc_brightness_max_fops = SEQ_FILEOPS_R (acpi_pcc_dc_brightness_max_open_fs);
706 static fops_t acpi_pcc_dc_brightness_min_fops = SEQ_FILEOPS_R (acpi_pcc_dc_brightness_min_open_fs);
707 static fops_t acpi_pcc_brightness_fops = SEQ_FILEOPS_RW(acpi_pcc_brightness_open_fs, acpi_pcc_write_no_brightness);
708 static fops_t acpi_pcc_sticky_key_fops = SEQ_FILEOPS_RW(acpi_pcc_sticky_key_open_fs, acpi_pcc_write_sticky_key);
709 static fops_t acpi_pcc_keyinput_fops = SEQ_FILEOPS_RW(acpi_pcc_keyinput_open_fs, acpi_pcc_write_keyinput);
710 static fops_t acpi_pcc_version_fops = SEQ_FILEOPS_R (acpi_pcc_version_open_fs);
712 typedef struct _ProcItem
715 struct file_operations *fops;
719 /* Note: These functions map *exactly* to the SINF/SSET functions */
720 ProcItem acpi_pcc_proc_items_sifr[] = {
721 { "num_batteries", &acpi_pcc_numbatteries_fops, S_IRUGO },
722 { "lcd_type", &acpi_pcc_lcdtype_fops, S_IRUGO },
723 { "ac_brightness_max" , &acpi_pcc_ac_brightness_max_fops,S_IRUGO },
724 { "ac_brightness_min" , &acpi_pcc_ac_brightness_min_fops,S_IRUGO },
725 { "ac_brightness" , &acpi_pcc_ac_brightness_fops, S_IFREG | S_IRUGO | S_IWUSR },
726 { "dc_brightness_max" , &acpi_pcc_dc_brightness_max_fops,S_IRUGO },
727 { "dc_brightness_min" , &acpi_pcc_dc_brightness_min_fops,S_IRUGO },
728 { "dc_brightness" , &acpi_pcc_dc_brightness_fops, S_IFREG | S_IRUGO | S_IWUSR },
729 { "brightness" , &acpi_pcc_brightness_fops, S_IFREG | S_IRUGO | S_IWUSR },
730 { "mute", &acpi_pcc_mute_fops, S_IFREG | S_IRUGO | S_IWUSR },
734 ProcItem acpi_pcc_proc_items[] = {
735 { "sticky_key", &acpi_pcc_sticky_key_fops, S_IFREG | S_IRUGO | S_IWUSR },
736 { "keyinput", &acpi_pcc_keyinput_fops, S_IFREG | S_IRUGO | S_IWUSR },
737 { "version", &acpi_pcc_version_fops, S_IRUGO },
741 static int __devinit acpi_pcc_add_device(struct acpi_device *device,
742 ProcItem *proc_items,
745 struct acpi_hotkey *hotkey = (struct acpi_hotkey*)acpi_driver_data(device);
746 struct proc_dir_entry* proc;
750 for (item = proc_items, i = 0; item->name && i < num; ++item, ++i) {
751 proc = create_proc_entry(item->name, item->flag, hotkey->proc_dir_entry);
753 proc->proc_fops = item->fops;
755 proc->owner = THIS_MODULE;
759 remove_proc_entry(item->name, hotkey->proc_dir_entry);
761 return_VALUE(-ENODEV);
767 static int __devinit acpi_pcc_proc_init(struct acpi_device *device)
769 struct proc_dir_entry *acpi_pcc_dir;
770 struct acpi_hotkey *hotkey = (struct acpi_hotkey*)acpi_driver_data(device);
773 ACPI_FUNCTION_TRACE("acpi_pcc_proc_init");
775 acpi_pcc_dir = proc_mkdir(PROC_PCC, acpi_root_dir);
777 if (unlikely(!acpi_pcc_dir)) {
778 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Couldn't create dir in /proc\n"));
779 return_VALUE(-ENODEV);
782 acpi_pcc_dir->owner = THIS_MODULE;
783 hotkey->proc_dir_entry = acpi_pcc_dir;
785 status = acpi_pcc_add_device(device, acpi_pcc_proc_items_sifr, hotkey->num_sifr);
786 status |= acpi_pcc_add_device(device, acpi_pcc_proc_items, ARRAY_SIZE(acpi_pcc_proc_items));
787 if (unlikely(status)) {
788 remove_proc_entry(PROC_PCC, acpi_root_dir);
789 hotkey->proc_dir_entry = NULL;
790 return_VALUE(-ENODEV);
793 return_VALUE(status);
796 static void __devexit acpi_pcc_remove_device(struct acpi_device *device,
797 ProcItem *proc_items,
800 struct acpi_hotkey *hotkey = (struct acpi_hotkey*)acpi_driver_data(device);
804 for (item = proc_items, i = 0; item->name != NULL && i < num; ++item, ++i) {
805 remove_proc_entry(item->name, hotkey->proc_dir_entry);
811 /* *************************************************************************
813 ************************************************************************* */
815 static int acpi_pcc_hotkey_resume(struct acpi_device *device)
817 struct acpi_hotkey *hotkey = acpi_driver_data(device);
818 acpi_status status = AE_OK;
820 ACPI_FUNCTION_TRACE("acpi_pcc_hotkey_resume");
822 if (device == NULL || hotkey == NULL) { return_VALUE(-EINVAL); }
824 if (hotkey->num_sifr != 0) {
825 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Sticky mode restore: %d\n", hotkey->sticky_mode));
827 status = acpi_pcc_write_sset(hotkey, SINF_STICKY_KEY, hotkey->sticky_mode);
829 if (status != AE_OK) { return_VALUE(-EINVAL); }
835 /* *************************************************************************
837 ************************************************************************* */
838 /* -------------------------------------------------------------------------
840 ------------------------------------------------------------------------- */
841 static int __devinit acpi_pcc_init_input(struct acpi_hotkey *hotkey)
843 struct input_dev *hotk_input_dev;
844 struct pcc_keyinput *pcc_keyinput;
847 ACPI_FUNCTION_TRACE("acpi_pcc_init_input");
849 hotk_input_dev = input_allocate_device();
850 if (hotk_input_dev == NULL) {
851 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Couldn't allocate input device for hotkey"));
855 pcc_keyinput = kcalloc(1, sizeof(struct pcc_keyinput), GFP_KERNEL);
857 if (pcc_keyinput == NULL) {
858 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Couldn't allocate mem for private data"));
862 hotk_input_dev->evbit[0] = BIT(EV_KEY);
864 set_bit(KEY_BRIGHTNESSDOWN, hotk_input_dev->keybit);
865 set_bit(KEY_BRIGHTNESSUP, hotk_input_dev->keybit);
866 set_bit(KEY_MUTE, hotk_input_dev->keybit);
867 set_bit(KEY_VOLUMEDOWN, hotk_input_dev->keybit);
868 set_bit(KEY_VOLUMEUP, hotk_input_dev->keybit);
869 set_bit(KEY_SLEEP, hotk_input_dev->keybit);
870 set_bit(KEY_BATT, hotk_input_dev->keybit);
871 set_bit(KEY_SUSPEND, hotk_input_dev->keybit);
873 hotk_input_dev->name = ACPI_PCC_DRIVER_NAME;
874 hotk_input_dev->phys = ACPI_PCC_INPUT_PHYS;
875 hotk_input_dev->id.bustype = BUS_PCC_HOTKEY;
876 hotk_input_dev->id.vendor = 0x0001;
877 hotk_input_dev->id.product = 0x0001;
878 hotk_input_dev->id.version = 0x0100;
880 pcc_keyinput->key_mode = PCC_KEYINPUT_MODE;
881 pcc_keyinput->hotkey = hotkey;
883 input_set_drvdata(hotk_input_dev, pcc_keyinput);
885 hotkey->input_dev = hotk_input_dev;
887 error = input_register_device(hotk_input_dev);
896 input_unregister_device(hotk_input_dev);
898 return_VALUE(-ENOMEM);
901 static void __devexit acpi_pcc_remove_input(struct acpi_hotkey *hotkey)
903 struct input_dev *hotk_input_dev;
904 struct pcc_keyinput *pcc_keyinput;
906 ACPI_FUNCTION_TRACE("acpi_pcc_remove_input");
908 if (hotkey == NULL) {
909 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Can't free memory"));
913 hotk_input_dev = hotkey->input_dev;
914 pcc_keyinput = input_get_drvdata(hotk_input_dev);
916 input_unregister_device(hotk_input_dev);
921 /* -------------------------------------------------------------------------
923 ------------------------------------------------------------------------- */
924 static int __devinit acpi_pcc_hotkey_add (struct acpi_device *device)
926 acpi_status status = AE_OK;
927 struct acpi_hotkey *hotkey = NULL;
928 int sifr_status, num_sifr, result;
930 ACPI_FUNCTION_TRACE("acpi_pcc_hotkey_add");
932 if (device == NULL) {
933 return_VALUE(-EINVAL);
936 sifr_status = acpi_pcc_get_sqty(device);
938 if (sifr_status > 255) {
939 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "num_sifr too large"));
940 return_VALUE(-ENODEV);
943 if (sifr_status < 0) {
944 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "not support SQTY"));
947 num_sifr = sifr_status;
950 hotkey = kcalloc(1, sizeof(struct acpi_hotkey), GFP_KERNEL);
951 if (hotkey == NULL) {
952 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Couldn't allocate mem for hotkey"));
953 return_VALUE(-ENOMEM);
956 hotkey->device = device;
957 hotkey->handle = device->handle;
958 hotkey->num_sifr = num_sifr;
959 acpi_driver_data(device) = hotkey;
960 strcpy(acpi_device_name(device), ACPI_PCC_DEVICE_NAME);
961 strcpy(acpi_device_class(device), ACPI_PCC_CLASS);
963 status = acpi_install_notify_handler(hotkey->handle,
965 acpi_pcc_hotkey_notify,
968 if (ACPI_FAILURE(status)) {
969 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error installing notify handler\n"));
971 return_VALUE(-ENODEV);
974 result = acpi_pcc_init_input(hotkey);
976 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error installing keyinput handler\n"));
978 return_VALUE(result);
981 return_VALUE(acpi_pcc_proc_init(device));
984 static int __devexit acpi_pcc_hotkey_remove(struct acpi_device *device, int type)
986 acpi_status status = AE_OK;
987 struct acpi_hotkey *hotkey = acpi_driver_data(device);
989 ACPI_FUNCTION_TRACE("acpi_pcc_hotkey_remove");
991 if (!device || !hotkey) {
992 return_VALUE(-EINVAL);
995 if (hotkey->proc_dir_entry) {
996 acpi_pcc_remove_device(device, acpi_pcc_proc_items_sifr, hotkey->num_sifr);
997 acpi_pcc_remove_device(device, acpi_pcc_proc_items, ARRAY_SIZE(acpi_pcc_proc_items));
998 remove_proc_entry(PROC_PCC, acpi_root_dir);
1001 status = acpi_remove_notify_handler(hotkey->handle,
1002 ACPI_DEVICE_NOTIFY, acpi_pcc_hotkey_notify);
1004 if (ACPI_FAILURE(status)) {
1005 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error removing notify handler\n"));
1008 acpi_pcc_remove_input(hotkey);
1009 if (hotkey != NULL) {
1012 return_VALUE(status == AE_OK);
1015 /* *********************************************************************
1017 ********************************************************************* */
1018 static int __init acpi_pcc_init(void)
1022 ACPI_FUNCTION_TRACE("acpi_pcc_init");
1024 printk(KERN_INFO LOGPREFIX "loading...\n");
1026 if (acpi_disabled) {
1027 printk(KERN_INFO LOGPREFIX "ACPI disabled.\n");
1028 return_VALUE(-ENODEV);
1031 result = acpi_bus_register_driver(&acpi_pcc_driver);
1033 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error registering hotkey driver\n"));
1034 return_VALUE(-ENODEV);
1037 return_VALUE(result);
1040 static void __exit acpi_pcc_exit(void)
1042 ACPI_FUNCTION_TRACE("acpi_pcc_exit");
1044 printk(KERN_INFO LOGPREFIX "unloading...\n");
1046 acpi_bus_unregister_driver(&acpi_pcc_driver);
1051 module_init(acpi_pcc_init);
1052 module_exit(acpi_pcc_exit);