2 * Copyright (C) 2009 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/slab.h>
23 #include <linux/workqueue.h>
24 #include <acpi/acpi_drivers.h>
25 #include <linux/backlight.h>
26 #include <linux/input.h>
27 #include <linux/rfkill.h>
29 MODULE_LICENSE("GPL");
38 #define CMPC_ACCEL_DEV_STATE_CLOSED 0
39 #define CMPC_ACCEL_DEV_STATE_OPEN 1
41 #define CMPC_ACCEL_SENSITIVITY_DEFAULT 5
42 #define CMPC_ACCEL_G_SELECT_DEFAULT 0
44 #define CMPC_ACCEL_HID "ACCE0000"
45 #define CMPC_ACCEL_HID_V4 "ACCE0001"
46 #define CMPC_TABLET_HID "TBLT0000"
47 #define CMPC_IPML_HID "IPML200"
48 #define CMPC_KEYS_HID "FNBT0000"
51 * Generic input device code.
54 typedef void (*input_device_init
)(struct input_dev
*dev
);
56 static int cmpc_add_acpi_notify_device(struct acpi_device
*acpi
, char *name
,
57 input_device_init idev_init
)
59 struct input_dev
*inputdev
;
62 inputdev
= input_allocate_device();
65 inputdev
->name
= name
;
66 inputdev
->dev
.parent
= &acpi
->dev
;
68 error
= input_register_device(inputdev
);
70 input_free_device(inputdev
);
73 dev_set_drvdata(&acpi
->dev
, inputdev
);
77 static int cmpc_remove_acpi_notify_device(struct acpi_device
*acpi
)
79 struct input_dev
*inputdev
= dev_get_drvdata(&acpi
->dev
);
80 input_unregister_device(inputdev
);
85 * Accelerometer code for Classmate V4
87 static acpi_status
cmpc_start_accel_v4(acpi_handle handle
)
89 union acpi_object param
[4];
90 struct acpi_object_list input
;
93 param
[0].type
= ACPI_TYPE_INTEGER
;
94 param
[0].integer
.value
= 0x3;
95 param
[1].type
= ACPI_TYPE_INTEGER
;
96 param
[1].integer
.value
= 0;
97 param
[2].type
= ACPI_TYPE_INTEGER
;
98 param
[2].integer
.value
= 0;
99 param
[3].type
= ACPI_TYPE_INTEGER
;
100 param
[3].integer
.value
= 0;
102 input
.pointer
= param
;
103 status
= acpi_evaluate_object(handle
, "ACMD", &input
, NULL
);
107 static acpi_status
cmpc_stop_accel_v4(acpi_handle handle
)
109 union acpi_object param
[4];
110 struct acpi_object_list input
;
113 param
[0].type
= ACPI_TYPE_INTEGER
;
114 param
[0].integer
.value
= 0x4;
115 param
[1].type
= ACPI_TYPE_INTEGER
;
116 param
[1].integer
.value
= 0;
117 param
[2].type
= ACPI_TYPE_INTEGER
;
118 param
[2].integer
.value
= 0;
119 param
[3].type
= ACPI_TYPE_INTEGER
;
120 param
[3].integer
.value
= 0;
122 input
.pointer
= param
;
123 status
= acpi_evaluate_object(handle
, "ACMD", &input
, NULL
);
127 static acpi_status
cmpc_accel_set_sensitivity_v4(acpi_handle handle
, int val
)
129 union acpi_object param
[4];
130 struct acpi_object_list input
;
132 param
[0].type
= ACPI_TYPE_INTEGER
;
133 param
[0].integer
.value
= 0x02;
134 param
[1].type
= ACPI_TYPE_INTEGER
;
135 param
[1].integer
.value
= val
;
136 param
[2].type
= ACPI_TYPE_INTEGER
;
137 param
[2].integer
.value
= 0;
138 param
[3].type
= ACPI_TYPE_INTEGER
;
139 param
[3].integer
.value
= 0;
141 input
.pointer
= param
;
142 return acpi_evaluate_object(handle
, "ACMD", &input
, NULL
);
145 static acpi_status
cmpc_accel_set_g_select_v4(acpi_handle handle
, int val
)
147 union acpi_object param
[4];
148 struct acpi_object_list input
;
150 param
[0].type
= ACPI_TYPE_INTEGER
;
151 param
[0].integer
.value
= 0x05;
152 param
[1].type
= ACPI_TYPE_INTEGER
;
153 param
[1].integer
.value
= val
;
154 param
[2].type
= ACPI_TYPE_INTEGER
;
155 param
[2].integer
.value
= 0;
156 param
[3].type
= ACPI_TYPE_INTEGER
;
157 param
[3].integer
.value
= 0;
159 input
.pointer
= param
;
160 return acpi_evaluate_object(handle
, "ACMD", &input
, NULL
);
163 static acpi_status
cmpc_get_accel_v4(acpi_handle handle
,
168 union acpi_object param
[4];
169 struct acpi_object_list input
;
170 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
174 param
[0].type
= ACPI_TYPE_INTEGER
;
175 param
[0].integer
.value
= 0x01;
176 param
[1].type
= ACPI_TYPE_INTEGER
;
177 param
[1].integer
.value
= 0;
178 param
[2].type
= ACPI_TYPE_INTEGER
;
179 param
[2].integer
.value
= 0;
180 param
[3].type
= ACPI_TYPE_INTEGER
;
181 param
[3].integer
.value
= 0;
183 input
.pointer
= param
;
184 status
= acpi_evaluate_object(handle
, "ACMD", &input
, &output
);
185 if (ACPI_SUCCESS(status
)) {
186 union acpi_object
*obj
;
187 obj
= output
.pointer
;
188 locs
= (int16_t *) obj
->buffer
.pointer
;
192 kfree(output
.pointer
);
197 static void cmpc_accel_handler_v4(struct acpi_device
*dev
, u32 event
)
203 status
= cmpc_get_accel_v4(dev
->handle
, &x
, &y
, &z
);
204 if (ACPI_SUCCESS(status
)) {
205 struct input_dev
*inputdev
= dev_get_drvdata(&dev
->dev
);
207 input_report_abs(inputdev
, ABS_X
, x
);
208 input_report_abs(inputdev
, ABS_Y
, y
);
209 input_report_abs(inputdev
, ABS_Z
, z
);
210 input_sync(inputdev
);
215 static ssize_t
cmpc_accel_sensitivity_show_v4(struct device
*dev
,
216 struct device_attribute
*attr
,
219 struct acpi_device
*acpi
;
220 struct input_dev
*inputdev
;
221 struct cmpc_accel
*accel
;
223 acpi
= to_acpi_device(dev
);
224 inputdev
= dev_get_drvdata(&acpi
->dev
);
225 accel
= dev_get_drvdata(&inputdev
->dev
);
227 return sprintf(buf
, "%d\n", accel
->sensitivity
);
230 static ssize_t
cmpc_accel_sensitivity_store_v4(struct device
*dev
,
231 struct device_attribute
*attr
,
232 const char *buf
, size_t count
)
234 struct acpi_device
*acpi
;
235 struct input_dev
*inputdev
;
236 struct cmpc_accel
*accel
;
237 unsigned long sensitivity
;
240 acpi
= to_acpi_device(dev
);
241 inputdev
= dev_get_drvdata(&acpi
->dev
);
242 accel
= dev_get_drvdata(&inputdev
->dev
);
244 r
= kstrtoul(buf
, 0, &sensitivity
);
248 /* sensitivity must be between 1 and 127 */
249 if (sensitivity
< 1 || sensitivity
> 127)
252 accel
->sensitivity
= sensitivity
;
253 cmpc_accel_set_sensitivity_v4(acpi
->handle
, sensitivity
);
255 return strnlen(buf
, count
);
258 static struct device_attribute cmpc_accel_sensitivity_attr_v4
= {
259 .attr
= { .name
= "sensitivity", .mode
= 0660 },
260 .show
= cmpc_accel_sensitivity_show_v4
,
261 .store
= cmpc_accel_sensitivity_store_v4
264 static ssize_t
cmpc_accel_g_select_show_v4(struct device
*dev
,
265 struct device_attribute
*attr
,
268 struct acpi_device
*acpi
;
269 struct input_dev
*inputdev
;
270 struct cmpc_accel
*accel
;
272 acpi
= to_acpi_device(dev
);
273 inputdev
= dev_get_drvdata(&acpi
->dev
);
274 accel
= dev_get_drvdata(&inputdev
->dev
);
276 return sprintf(buf
, "%d\n", accel
->g_select
);
279 static ssize_t
cmpc_accel_g_select_store_v4(struct device
*dev
,
280 struct device_attribute
*attr
,
281 const char *buf
, size_t count
)
283 struct acpi_device
*acpi
;
284 struct input_dev
*inputdev
;
285 struct cmpc_accel
*accel
;
286 unsigned long g_select
;
289 acpi
= to_acpi_device(dev
);
290 inputdev
= dev_get_drvdata(&acpi
->dev
);
291 accel
= dev_get_drvdata(&inputdev
->dev
);
293 r
= kstrtoul(buf
, 0, &g_select
);
297 /* 0 means 1.5g, 1 means 6g, everything else is wrong */
298 if (g_select
!= 0 && g_select
!= 1)
301 accel
->g_select
= g_select
;
302 cmpc_accel_set_g_select_v4(acpi
->handle
, g_select
);
304 return strnlen(buf
, count
);
307 static struct device_attribute cmpc_accel_g_select_attr_v4
= {
308 .attr
= { .name
= "g_select", .mode
= 0660 },
309 .show
= cmpc_accel_g_select_show_v4
,
310 .store
= cmpc_accel_g_select_store_v4
313 static int cmpc_accel_open_v4(struct input_dev
*input
)
315 struct acpi_device
*acpi
;
316 struct cmpc_accel
*accel
;
318 acpi
= to_acpi_device(input
->dev
.parent
);
319 accel
= dev_get_drvdata(&input
->dev
);
321 cmpc_accel_set_sensitivity_v4(acpi
->handle
, accel
->sensitivity
);
322 cmpc_accel_set_g_select_v4(acpi
->handle
, accel
->g_select
);
324 if (ACPI_SUCCESS(cmpc_start_accel_v4(acpi
->handle
))) {
325 accel
->inputdev_state
= CMPC_ACCEL_DEV_STATE_OPEN
;
331 static void cmpc_accel_close_v4(struct input_dev
*input
)
333 struct acpi_device
*acpi
;
334 struct cmpc_accel
*accel
;
336 acpi
= to_acpi_device(input
->dev
.parent
);
337 accel
= dev_get_drvdata(&input
->dev
);
339 cmpc_stop_accel_v4(acpi
->handle
);
340 accel
->inputdev_state
= CMPC_ACCEL_DEV_STATE_CLOSED
;
343 static void cmpc_accel_idev_init_v4(struct input_dev
*inputdev
)
345 set_bit(EV_ABS
, inputdev
->evbit
);
346 input_set_abs_params(inputdev
, ABS_X
, -255, 255, 16, 0);
347 input_set_abs_params(inputdev
, ABS_Y
, -255, 255, 16, 0);
348 input_set_abs_params(inputdev
, ABS_Z
, -255, 255, 16, 0);
349 inputdev
->open
= cmpc_accel_open_v4
;
350 inputdev
->close
= cmpc_accel_close_v4
;
353 #ifdef CONFIG_PM_SLEEP
354 static int cmpc_accel_suspend_v4(struct device
*dev
)
356 struct input_dev
*inputdev
;
357 struct cmpc_accel
*accel
;
359 inputdev
= dev_get_drvdata(dev
);
360 accel
= dev_get_drvdata(&inputdev
->dev
);
362 if (accel
->inputdev_state
== CMPC_ACCEL_DEV_STATE_OPEN
)
363 return cmpc_stop_accel_v4(to_acpi_device(dev
)->handle
);
368 static int cmpc_accel_resume_v4(struct device
*dev
)
370 struct input_dev
*inputdev
;
371 struct cmpc_accel
*accel
;
373 inputdev
= dev_get_drvdata(dev
);
374 accel
= dev_get_drvdata(&inputdev
->dev
);
376 if (accel
->inputdev_state
== CMPC_ACCEL_DEV_STATE_OPEN
) {
377 cmpc_accel_set_sensitivity_v4(to_acpi_device(dev
)->handle
,
379 cmpc_accel_set_g_select_v4(to_acpi_device(dev
)->handle
,
382 if (ACPI_FAILURE(cmpc_start_accel_v4(to_acpi_device(dev
)->handle
)))
390 static int cmpc_accel_add_v4(struct acpi_device
*acpi
)
393 struct input_dev
*inputdev
;
394 struct cmpc_accel
*accel
;
396 accel
= kmalloc(sizeof(*accel
), GFP_KERNEL
);
400 accel
->inputdev_state
= CMPC_ACCEL_DEV_STATE_CLOSED
;
402 accel
->sensitivity
= CMPC_ACCEL_SENSITIVITY_DEFAULT
;
403 cmpc_accel_set_sensitivity_v4(acpi
->handle
, accel
->sensitivity
);
405 error
= device_create_file(&acpi
->dev
, &cmpc_accel_sensitivity_attr_v4
);
407 goto failed_sensitivity
;
409 accel
->g_select
= CMPC_ACCEL_G_SELECT_DEFAULT
;
410 cmpc_accel_set_g_select_v4(acpi
->handle
, accel
->g_select
);
412 error
= device_create_file(&acpi
->dev
, &cmpc_accel_g_select_attr_v4
);
414 goto failed_g_select
;
416 error
= cmpc_add_acpi_notify_device(acpi
, "cmpc_accel_v4",
417 cmpc_accel_idev_init_v4
);
421 inputdev
= dev_get_drvdata(&acpi
->dev
);
422 dev_set_drvdata(&inputdev
->dev
, accel
);
427 device_remove_file(&acpi
->dev
, &cmpc_accel_g_select_attr_v4
);
429 device_remove_file(&acpi
->dev
, &cmpc_accel_sensitivity_attr_v4
);
435 static int cmpc_accel_remove_v4(struct acpi_device
*acpi
)
437 struct input_dev
*inputdev
;
438 struct cmpc_accel
*accel
;
440 inputdev
= dev_get_drvdata(&acpi
->dev
);
441 accel
= dev_get_drvdata(&inputdev
->dev
);
443 device_remove_file(&acpi
->dev
, &cmpc_accel_sensitivity_attr_v4
);
444 device_remove_file(&acpi
->dev
, &cmpc_accel_g_select_attr_v4
);
445 return cmpc_remove_acpi_notify_device(acpi
);
448 static SIMPLE_DEV_PM_OPS(cmpc_accel_pm
, cmpc_accel_suspend_v4
,
449 cmpc_accel_resume_v4
);
451 static const struct acpi_device_id cmpc_accel_device_ids_v4
[] = {
452 {CMPC_ACCEL_HID_V4
, 0},
456 static struct acpi_driver cmpc_accel_acpi_driver_v4
= {
457 .owner
= THIS_MODULE
,
458 .name
= "cmpc_accel_v4",
459 .class = "cmpc_accel_v4",
460 .ids
= cmpc_accel_device_ids_v4
,
462 .add
= cmpc_accel_add_v4
,
463 .remove
= cmpc_accel_remove_v4
,
464 .notify
= cmpc_accel_handler_v4
,
466 .drv
.pm
= &cmpc_accel_pm
,
471 * Accelerometer code for Classmate versions prior to V4
473 static acpi_status
cmpc_start_accel(acpi_handle handle
)
475 union acpi_object param
[2];
476 struct acpi_object_list input
;
479 param
[0].type
= ACPI_TYPE_INTEGER
;
480 param
[0].integer
.value
= 0x3;
481 param
[1].type
= ACPI_TYPE_INTEGER
;
483 input
.pointer
= param
;
484 status
= acpi_evaluate_object(handle
, "ACMD", &input
, NULL
);
488 static acpi_status
cmpc_stop_accel(acpi_handle handle
)
490 union acpi_object param
[2];
491 struct acpi_object_list input
;
494 param
[0].type
= ACPI_TYPE_INTEGER
;
495 param
[0].integer
.value
= 0x4;
496 param
[1].type
= ACPI_TYPE_INTEGER
;
498 input
.pointer
= param
;
499 status
= acpi_evaluate_object(handle
, "ACMD", &input
, NULL
);
503 static acpi_status
cmpc_accel_set_sensitivity(acpi_handle handle
, int val
)
505 union acpi_object param
[2];
506 struct acpi_object_list input
;
508 param
[0].type
= ACPI_TYPE_INTEGER
;
509 param
[0].integer
.value
= 0x02;
510 param
[1].type
= ACPI_TYPE_INTEGER
;
511 param
[1].integer
.value
= val
;
513 input
.pointer
= param
;
514 return acpi_evaluate_object(handle
, "ACMD", &input
, NULL
);
517 static acpi_status
cmpc_get_accel(acpi_handle handle
,
522 union acpi_object param
[2];
523 struct acpi_object_list input
;
524 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, 0 };
528 param
[0].type
= ACPI_TYPE_INTEGER
;
529 param
[0].integer
.value
= 0x01;
530 param
[1].type
= ACPI_TYPE_INTEGER
;
532 input
.pointer
= param
;
533 status
= acpi_evaluate_object(handle
, "ACMD", &input
, &output
);
534 if (ACPI_SUCCESS(status
)) {
535 union acpi_object
*obj
;
536 obj
= output
.pointer
;
537 locs
= obj
->buffer
.pointer
;
541 kfree(output
.pointer
);
546 static void cmpc_accel_handler(struct acpi_device
*dev
, u32 event
)
549 unsigned char x
, y
, z
;
552 status
= cmpc_get_accel(dev
->handle
, &x
, &y
, &z
);
553 if (ACPI_SUCCESS(status
)) {
554 struct input_dev
*inputdev
= dev_get_drvdata(&dev
->dev
);
556 input_report_abs(inputdev
, ABS_X
, x
);
557 input_report_abs(inputdev
, ABS_Y
, y
);
558 input_report_abs(inputdev
, ABS_Z
, z
);
559 input_sync(inputdev
);
564 static ssize_t
cmpc_accel_sensitivity_show(struct device
*dev
,
565 struct device_attribute
*attr
,
568 struct acpi_device
*acpi
;
569 struct input_dev
*inputdev
;
570 struct cmpc_accel
*accel
;
572 acpi
= to_acpi_device(dev
);
573 inputdev
= dev_get_drvdata(&acpi
->dev
);
574 accel
= dev_get_drvdata(&inputdev
->dev
);
576 return sprintf(buf
, "%d\n", accel
->sensitivity
);
579 static ssize_t
cmpc_accel_sensitivity_store(struct device
*dev
,
580 struct device_attribute
*attr
,
581 const char *buf
, size_t count
)
583 struct acpi_device
*acpi
;
584 struct input_dev
*inputdev
;
585 struct cmpc_accel
*accel
;
586 unsigned long sensitivity
;
589 acpi
= to_acpi_device(dev
);
590 inputdev
= dev_get_drvdata(&acpi
->dev
);
591 accel
= dev_get_drvdata(&inputdev
->dev
);
593 r
= kstrtoul(buf
, 0, &sensitivity
);
597 accel
->sensitivity
= sensitivity
;
598 cmpc_accel_set_sensitivity(acpi
->handle
, sensitivity
);
600 return strnlen(buf
, count
);
603 static struct device_attribute cmpc_accel_sensitivity_attr
= {
604 .attr
= { .name
= "sensitivity", .mode
= 0660 },
605 .show
= cmpc_accel_sensitivity_show
,
606 .store
= cmpc_accel_sensitivity_store
609 static int cmpc_accel_open(struct input_dev
*input
)
611 struct acpi_device
*acpi
;
613 acpi
= to_acpi_device(input
->dev
.parent
);
614 if (ACPI_SUCCESS(cmpc_start_accel(acpi
->handle
)))
619 static void cmpc_accel_close(struct input_dev
*input
)
621 struct acpi_device
*acpi
;
623 acpi
= to_acpi_device(input
->dev
.parent
);
624 cmpc_stop_accel(acpi
->handle
);
627 static void cmpc_accel_idev_init(struct input_dev
*inputdev
)
629 set_bit(EV_ABS
, inputdev
->evbit
);
630 input_set_abs_params(inputdev
, ABS_X
, 0, 255, 8, 0);
631 input_set_abs_params(inputdev
, ABS_Y
, 0, 255, 8, 0);
632 input_set_abs_params(inputdev
, ABS_Z
, 0, 255, 8, 0);
633 inputdev
->open
= cmpc_accel_open
;
634 inputdev
->close
= cmpc_accel_close
;
637 static int cmpc_accel_add(struct acpi_device
*acpi
)
640 struct input_dev
*inputdev
;
641 struct cmpc_accel
*accel
;
643 accel
= kmalloc(sizeof(*accel
), GFP_KERNEL
);
647 accel
->sensitivity
= CMPC_ACCEL_SENSITIVITY_DEFAULT
;
648 cmpc_accel_set_sensitivity(acpi
->handle
, accel
->sensitivity
);
650 error
= device_create_file(&acpi
->dev
, &cmpc_accel_sensitivity_attr
);
654 error
= cmpc_add_acpi_notify_device(acpi
, "cmpc_accel",
655 cmpc_accel_idev_init
);
659 inputdev
= dev_get_drvdata(&acpi
->dev
);
660 dev_set_drvdata(&inputdev
->dev
, accel
);
665 device_remove_file(&acpi
->dev
, &cmpc_accel_sensitivity_attr
);
671 static int cmpc_accel_remove(struct acpi_device
*acpi
)
673 struct input_dev
*inputdev
;
674 struct cmpc_accel
*accel
;
676 inputdev
= dev_get_drvdata(&acpi
->dev
);
677 accel
= dev_get_drvdata(&inputdev
->dev
);
679 device_remove_file(&acpi
->dev
, &cmpc_accel_sensitivity_attr
);
680 return cmpc_remove_acpi_notify_device(acpi
);
683 static const struct acpi_device_id cmpc_accel_device_ids
[] = {
688 static struct acpi_driver cmpc_accel_acpi_driver
= {
689 .owner
= THIS_MODULE
,
690 .name
= "cmpc_accel",
691 .class = "cmpc_accel",
692 .ids
= cmpc_accel_device_ids
,
694 .add
= cmpc_accel_add
,
695 .remove
= cmpc_accel_remove
,
696 .notify
= cmpc_accel_handler
,
704 static acpi_status
cmpc_get_tablet(acpi_handle handle
,
705 unsigned long long *value
)
707 union acpi_object param
;
708 struct acpi_object_list input
;
709 unsigned long long output
;
712 param
.type
= ACPI_TYPE_INTEGER
;
713 param
.integer
.value
= 0x01;
715 input
.pointer
= ¶m
;
716 status
= acpi_evaluate_integer(handle
, "TCMD", &input
, &output
);
717 if (ACPI_SUCCESS(status
))
722 static void cmpc_tablet_handler(struct acpi_device
*dev
, u32 event
)
724 unsigned long long val
= 0;
725 struct input_dev
*inputdev
= dev_get_drvdata(&dev
->dev
);
728 if (ACPI_SUCCESS(cmpc_get_tablet(dev
->handle
, &val
))) {
729 input_report_switch(inputdev
, SW_TABLET_MODE
, !val
);
730 input_sync(inputdev
);
735 static void cmpc_tablet_idev_init(struct input_dev
*inputdev
)
737 unsigned long long val
= 0;
738 struct acpi_device
*acpi
;
740 set_bit(EV_SW
, inputdev
->evbit
);
741 set_bit(SW_TABLET_MODE
, inputdev
->swbit
);
743 acpi
= to_acpi_device(inputdev
->dev
.parent
);
744 if (ACPI_SUCCESS(cmpc_get_tablet(acpi
->handle
, &val
))) {
745 input_report_switch(inputdev
, SW_TABLET_MODE
, !val
);
746 input_sync(inputdev
);
750 static int cmpc_tablet_add(struct acpi_device
*acpi
)
752 return cmpc_add_acpi_notify_device(acpi
, "cmpc_tablet",
753 cmpc_tablet_idev_init
);
756 static int cmpc_tablet_remove(struct acpi_device
*acpi
)
758 return cmpc_remove_acpi_notify_device(acpi
);
761 #ifdef CONFIG_PM_SLEEP
762 static int cmpc_tablet_resume(struct device
*dev
)
764 struct input_dev
*inputdev
= dev_get_drvdata(dev
);
766 unsigned long long val
= 0;
767 if (ACPI_SUCCESS(cmpc_get_tablet(to_acpi_device(dev
)->handle
, &val
))) {
768 input_report_switch(inputdev
, SW_TABLET_MODE
, !val
);
769 input_sync(inputdev
);
775 static SIMPLE_DEV_PM_OPS(cmpc_tablet_pm
, NULL
, cmpc_tablet_resume
);
777 static const struct acpi_device_id cmpc_tablet_device_ids
[] = {
778 {CMPC_TABLET_HID
, 0},
782 static struct acpi_driver cmpc_tablet_acpi_driver
= {
783 .owner
= THIS_MODULE
,
784 .name
= "cmpc_tablet",
785 .class = "cmpc_tablet",
786 .ids
= cmpc_tablet_device_ids
,
788 .add
= cmpc_tablet_add
,
789 .remove
= cmpc_tablet_remove
,
790 .notify
= cmpc_tablet_handler
,
792 .drv
.pm
= &cmpc_tablet_pm
,
800 static acpi_status
cmpc_get_brightness(acpi_handle handle
,
801 unsigned long long *value
)
803 union acpi_object param
;
804 struct acpi_object_list input
;
805 unsigned long long output
;
808 param
.type
= ACPI_TYPE_INTEGER
;
809 param
.integer
.value
= 0xC0;
811 input
.pointer
= ¶m
;
812 status
= acpi_evaluate_integer(handle
, "GRDI", &input
, &output
);
813 if (ACPI_SUCCESS(status
))
818 static acpi_status
cmpc_set_brightness(acpi_handle handle
,
819 unsigned long long value
)
821 union acpi_object param
[2];
822 struct acpi_object_list input
;
824 unsigned long long output
;
826 param
[0].type
= ACPI_TYPE_INTEGER
;
827 param
[0].integer
.value
= 0xC0;
828 param
[1].type
= ACPI_TYPE_INTEGER
;
829 param
[1].integer
.value
= value
;
831 input
.pointer
= param
;
832 status
= acpi_evaluate_integer(handle
, "GWRI", &input
, &output
);
836 static int cmpc_bl_get_brightness(struct backlight_device
*bd
)
840 unsigned long long brightness
;
842 handle
= bl_get_data(bd
);
843 status
= cmpc_get_brightness(handle
, &brightness
);
844 if (ACPI_SUCCESS(status
))
850 static int cmpc_bl_update_status(struct backlight_device
*bd
)
855 handle
= bl_get_data(bd
);
856 status
= cmpc_set_brightness(handle
, bd
->props
.brightness
);
857 if (ACPI_SUCCESS(status
))
863 static const struct backlight_ops cmpc_bl_ops
= {
864 .get_brightness
= cmpc_bl_get_brightness
,
865 .update_status
= cmpc_bl_update_status
872 static acpi_status
cmpc_get_rfkill_wlan(acpi_handle handle
,
873 unsigned long long *value
)
875 union acpi_object param
;
876 struct acpi_object_list input
;
877 unsigned long long output
;
880 param
.type
= ACPI_TYPE_INTEGER
;
881 param
.integer
.value
= 0xC1;
883 input
.pointer
= ¶m
;
884 status
= acpi_evaluate_integer(handle
, "GRDI", &input
, &output
);
885 if (ACPI_SUCCESS(status
))
890 static acpi_status
cmpc_set_rfkill_wlan(acpi_handle handle
,
891 unsigned long long value
)
893 union acpi_object param
[2];
894 struct acpi_object_list input
;
896 unsigned long long output
;
898 param
[0].type
= ACPI_TYPE_INTEGER
;
899 param
[0].integer
.value
= 0xC1;
900 param
[1].type
= ACPI_TYPE_INTEGER
;
901 param
[1].integer
.value
= value
;
903 input
.pointer
= param
;
904 status
= acpi_evaluate_integer(handle
, "GWRI", &input
, &output
);
908 static void cmpc_rfkill_query(struct rfkill
*rfkill
, void *data
)
912 unsigned long long state
;
916 status
= cmpc_get_rfkill_wlan(handle
, &state
);
917 if (ACPI_SUCCESS(status
)) {
918 blocked
= state
& 1 ? false : true;
919 rfkill_set_sw_state(rfkill
, blocked
);
923 static int cmpc_rfkill_block(void *data
, bool blocked
)
927 unsigned long long state
;
931 status
= cmpc_get_rfkill_wlan(handle
, &state
);
932 if (ACPI_FAILURE(status
))
934 /* Check if we really need to call cmpc_set_rfkill_wlan */
935 is_blocked
= state
& 1 ? false : true;
936 if (is_blocked
!= blocked
) {
937 state
= blocked
? 0 : 1;
938 status
= cmpc_set_rfkill_wlan(handle
, state
);
939 if (ACPI_FAILURE(status
))
945 static const struct rfkill_ops cmpc_rfkill_ops
= {
946 .query
= cmpc_rfkill_query
,
947 .set_block
= cmpc_rfkill_block
,
951 * Common backlight and rfkill code.
955 struct backlight_device
*bd
;
959 static int cmpc_ipml_add(struct acpi_device
*acpi
)
962 struct ipml200_dev
*ipml
;
963 struct backlight_properties props
;
965 ipml
= kmalloc(sizeof(*ipml
), GFP_KERNEL
);
969 memset(&props
, 0, sizeof(struct backlight_properties
));
970 props
.type
= BACKLIGHT_PLATFORM
;
971 props
.max_brightness
= 7;
972 ipml
->bd
= backlight_device_register("cmpc_bl", &acpi
->dev
,
973 acpi
->handle
, &cmpc_bl_ops
,
975 if (IS_ERR(ipml
->bd
)) {
976 retval
= PTR_ERR(ipml
->bd
);
980 ipml
->rf
= rfkill_alloc("cmpc_rfkill", &acpi
->dev
, RFKILL_TYPE_WLAN
,
981 &cmpc_rfkill_ops
, acpi
->handle
);
983 * If RFKILL is disabled, rfkill_alloc will return ERR_PTR(-ENODEV).
984 * This is OK, however, since all other uses of the device will not
988 retval
= rfkill_register(ipml
->rf
);
990 rfkill_destroy(ipml
->rf
);
995 dev_set_drvdata(&acpi
->dev
, ipml
);
1003 static int cmpc_ipml_remove(struct acpi_device
*acpi
)
1005 struct ipml200_dev
*ipml
;
1007 ipml
= dev_get_drvdata(&acpi
->dev
);
1009 backlight_device_unregister(ipml
->bd
);
1012 rfkill_unregister(ipml
->rf
);
1013 rfkill_destroy(ipml
->rf
);
1021 static const struct acpi_device_id cmpc_ipml_device_ids
[] = {
1026 static struct acpi_driver cmpc_ipml_acpi_driver
= {
1027 .owner
= THIS_MODULE
,
1030 .ids
= cmpc_ipml_device_ids
,
1032 .add
= cmpc_ipml_add
,
1033 .remove
= cmpc_ipml_remove
1041 static int cmpc_keys_codes
[] = {
1044 KEY_SWITCHVIDEOMODE
,
1055 static void cmpc_keys_handler(struct acpi_device
*dev
, u32 event
)
1057 struct input_dev
*inputdev
;
1060 if ((event
& 0x0F) < ARRAY_SIZE(cmpc_keys_codes
))
1061 code
= cmpc_keys_codes
[event
& 0x0F];
1062 inputdev
= dev_get_drvdata(&dev
->dev
);
1063 input_report_key(inputdev
, code
, !(event
& 0x10));
1064 input_sync(inputdev
);
1067 static void cmpc_keys_idev_init(struct input_dev
*inputdev
)
1071 set_bit(EV_KEY
, inputdev
->evbit
);
1072 for (i
= 0; cmpc_keys_codes
[i
] != KEY_MAX
; i
++)
1073 set_bit(cmpc_keys_codes
[i
], inputdev
->keybit
);
1076 static int cmpc_keys_add(struct acpi_device
*acpi
)
1078 return cmpc_add_acpi_notify_device(acpi
, "cmpc_keys",
1079 cmpc_keys_idev_init
);
1082 static int cmpc_keys_remove(struct acpi_device
*acpi
)
1084 return cmpc_remove_acpi_notify_device(acpi
);
1087 static const struct acpi_device_id cmpc_keys_device_ids
[] = {
1092 static struct acpi_driver cmpc_keys_acpi_driver
= {
1093 .owner
= THIS_MODULE
,
1094 .name
= "cmpc_keys",
1095 .class = "cmpc_keys",
1096 .ids
= cmpc_keys_device_ids
,
1098 .add
= cmpc_keys_add
,
1099 .remove
= cmpc_keys_remove
,
1100 .notify
= cmpc_keys_handler
,
1106 * General init/exit code.
1109 static int cmpc_init(void)
1113 r
= acpi_bus_register_driver(&cmpc_keys_acpi_driver
);
1117 r
= acpi_bus_register_driver(&cmpc_ipml_acpi_driver
);
1121 r
= acpi_bus_register_driver(&cmpc_tablet_acpi_driver
);
1125 r
= acpi_bus_register_driver(&cmpc_accel_acpi_driver
);
1129 r
= acpi_bus_register_driver(&cmpc_accel_acpi_driver_v4
);
1131 goto failed_accel_v4
;
1136 acpi_bus_unregister_driver(&cmpc_accel_acpi_driver
);
1139 acpi_bus_unregister_driver(&cmpc_tablet_acpi_driver
);
1142 acpi_bus_unregister_driver(&cmpc_ipml_acpi_driver
);
1145 acpi_bus_unregister_driver(&cmpc_keys_acpi_driver
);
1151 static void cmpc_exit(void)
1153 acpi_bus_unregister_driver(&cmpc_accel_acpi_driver_v4
);
1154 acpi_bus_unregister_driver(&cmpc_accel_acpi_driver
);
1155 acpi_bus_unregister_driver(&cmpc_tablet_acpi_driver
);
1156 acpi_bus_unregister_driver(&cmpc_ipml_acpi_driver
);
1157 acpi_bus_unregister_driver(&cmpc_keys_acpi_driver
);
1160 module_init(cmpc_init
);
1161 module_exit(cmpc_exit
);
1163 static const struct acpi_device_id cmpc_device_ids
[] = {
1164 {CMPC_ACCEL_HID
, 0},
1165 {CMPC_ACCEL_HID_V4
, 0},
1166 {CMPC_TABLET_HID
, 0},
1172 MODULE_DEVICE_TABLE(acpi
, cmpc_device_ids
);