1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2009 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
7 #include <linux/init.h>
8 #include <linux/module.h>
9 #include <linux/slab.h>
10 #include <linux/workqueue.h>
11 #include <linux/acpi.h>
12 #include <linux/backlight.h>
13 #include <linux/input.h>
14 #include <linux/rfkill.h>
16 MODULE_LICENSE("GPL");
24 #define CMPC_ACCEL_DEV_STATE_CLOSED 0
25 #define CMPC_ACCEL_DEV_STATE_OPEN 1
27 #define CMPC_ACCEL_SENSITIVITY_DEFAULT 5
28 #define CMPC_ACCEL_G_SELECT_DEFAULT 0
30 #define CMPC_ACCEL_HID "ACCE0000"
31 #define CMPC_ACCEL_HID_V4 "ACCE0001"
32 #define CMPC_TABLET_HID "TBLT0000"
33 #define CMPC_IPML_HID "IPML200"
34 #define CMPC_KEYS_HID "FNBT0000"
37 * Generic input device code.
40 typedef void (*input_device_init
)(struct input_dev
*dev
);
42 static int cmpc_add_acpi_notify_device(struct acpi_device
*acpi
, char *name
,
43 input_device_init idev_init
)
45 struct input_dev
*inputdev
;
48 inputdev
= input_allocate_device();
51 inputdev
->name
= name
;
52 inputdev
->dev
.parent
= &acpi
->dev
;
54 error
= input_register_device(inputdev
);
56 input_free_device(inputdev
);
59 dev_set_drvdata(&acpi
->dev
, inputdev
);
63 static int cmpc_remove_acpi_notify_device(struct acpi_device
*acpi
)
65 struct input_dev
*inputdev
= dev_get_drvdata(&acpi
->dev
);
66 input_unregister_device(inputdev
);
71 * Accelerometer code for Classmate V4
73 static acpi_status
cmpc_start_accel_v4(acpi_handle handle
)
75 union acpi_object param
[4];
76 struct acpi_object_list input
;
79 param
[0].type
= ACPI_TYPE_INTEGER
;
80 param
[0].integer
.value
= 0x3;
81 param
[1].type
= ACPI_TYPE_INTEGER
;
82 param
[1].integer
.value
= 0;
83 param
[2].type
= ACPI_TYPE_INTEGER
;
84 param
[2].integer
.value
= 0;
85 param
[3].type
= ACPI_TYPE_INTEGER
;
86 param
[3].integer
.value
= 0;
88 input
.pointer
= param
;
89 status
= acpi_evaluate_object(handle
, "ACMD", &input
, NULL
);
93 static acpi_status
cmpc_stop_accel_v4(acpi_handle handle
)
95 union acpi_object param
[4];
96 struct acpi_object_list input
;
99 param
[0].type
= ACPI_TYPE_INTEGER
;
100 param
[0].integer
.value
= 0x4;
101 param
[1].type
= ACPI_TYPE_INTEGER
;
102 param
[1].integer
.value
= 0;
103 param
[2].type
= ACPI_TYPE_INTEGER
;
104 param
[2].integer
.value
= 0;
105 param
[3].type
= ACPI_TYPE_INTEGER
;
106 param
[3].integer
.value
= 0;
108 input
.pointer
= param
;
109 status
= acpi_evaluate_object(handle
, "ACMD", &input
, NULL
);
113 static acpi_status
cmpc_accel_set_sensitivity_v4(acpi_handle handle
, int val
)
115 union acpi_object param
[4];
116 struct acpi_object_list input
;
118 param
[0].type
= ACPI_TYPE_INTEGER
;
119 param
[0].integer
.value
= 0x02;
120 param
[1].type
= ACPI_TYPE_INTEGER
;
121 param
[1].integer
.value
= val
;
122 param
[2].type
= ACPI_TYPE_INTEGER
;
123 param
[2].integer
.value
= 0;
124 param
[3].type
= ACPI_TYPE_INTEGER
;
125 param
[3].integer
.value
= 0;
127 input
.pointer
= param
;
128 return acpi_evaluate_object(handle
, "ACMD", &input
, NULL
);
131 static acpi_status
cmpc_accel_set_g_select_v4(acpi_handle handle
, int val
)
133 union acpi_object param
[4];
134 struct acpi_object_list input
;
136 param
[0].type
= ACPI_TYPE_INTEGER
;
137 param
[0].integer
.value
= 0x05;
138 param
[1].type
= ACPI_TYPE_INTEGER
;
139 param
[1].integer
.value
= val
;
140 param
[2].type
= ACPI_TYPE_INTEGER
;
141 param
[2].integer
.value
= 0;
142 param
[3].type
= ACPI_TYPE_INTEGER
;
143 param
[3].integer
.value
= 0;
145 input
.pointer
= param
;
146 return acpi_evaluate_object(handle
, "ACMD", &input
, NULL
);
149 static acpi_status
cmpc_get_accel_v4(acpi_handle handle
,
154 union acpi_object param
[4];
155 struct acpi_object_list input
;
156 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
160 param
[0].type
= ACPI_TYPE_INTEGER
;
161 param
[0].integer
.value
= 0x01;
162 param
[1].type
= ACPI_TYPE_INTEGER
;
163 param
[1].integer
.value
= 0;
164 param
[2].type
= ACPI_TYPE_INTEGER
;
165 param
[2].integer
.value
= 0;
166 param
[3].type
= ACPI_TYPE_INTEGER
;
167 param
[3].integer
.value
= 0;
169 input
.pointer
= param
;
170 status
= acpi_evaluate_object(handle
, "ACMD", &input
, &output
);
171 if (ACPI_SUCCESS(status
)) {
172 union acpi_object
*obj
;
173 obj
= output
.pointer
;
174 locs
= (int16_t *) obj
->buffer
.pointer
;
178 kfree(output
.pointer
);
183 static void cmpc_accel_handler_v4(struct acpi_device
*dev
, u32 event
)
189 status
= cmpc_get_accel_v4(dev
->handle
, &x
, &y
, &z
);
190 if (ACPI_SUCCESS(status
)) {
191 struct input_dev
*inputdev
= dev_get_drvdata(&dev
->dev
);
193 input_report_abs(inputdev
, ABS_X
, x
);
194 input_report_abs(inputdev
, ABS_Y
, y
);
195 input_report_abs(inputdev
, ABS_Z
, z
);
196 input_sync(inputdev
);
201 static ssize_t
cmpc_accel_sensitivity_show_v4(struct device
*dev
,
202 struct device_attribute
*attr
,
205 struct acpi_device
*acpi
;
206 struct input_dev
*inputdev
;
207 struct cmpc_accel
*accel
;
209 acpi
= to_acpi_device(dev
);
210 inputdev
= dev_get_drvdata(&acpi
->dev
);
211 accel
= dev_get_drvdata(&inputdev
->dev
);
213 return sprintf(buf
, "%d\n", accel
->sensitivity
);
216 static ssize_t
cmpc_accel_sensitivity_store_v4(struct device
*dev
,
217 struct device_attribute
*attr
,
218 const char *buf
, size_t count
)
220 struct acpi_device
*acpi
;
221 struct input_dev
*inputdev
;
222 struct cmpc_accel
*accel
;
223 unsigned long sensitivity
;
226 acpi
= to_acpi_device(dev
);
227 inputdev
= dev_get_drvdata(&acpi
->dev
);
228 accel
= dev_get_drvdata(&inputdev
->dev
);
230 r
= kstrtoul(buf
, 0, &sensitivity
);
234 /* sensitivity must be between 1 and 127 */
235 if (sensitivity
< 1 || sensitivity
> 127)
238 accel
->sensitivity
= sensitivity
;
239 cmpc_accel_set_sensitivity_v4(acpi
->handle
, sensitivity
);
241 return strnlen(buf
, count
);
244 static struct device_attribute cmpc_accel_sensitivity_attr_v4
= {
245 .attr
= { .name
= "sensitivity", .mode
= 0660 },
246 .show
= cmpc_accel_sensitivity_show_v4
,
247 .store
= cmpc_accel_sensitivity_store_v4
250 static ssize_t
cmpc_accel_g_select_show_v4(struct device
*dev
,
251 struct device_attribute
*attr
,
254 struct acpi_device
*acpi
;
255 struct input_dev
*inputdev
;
256 struct cmpc_accel
*accel
;
258 acpi
= to_acpi_device(dev
);
259 inputdev
= dev_get_drvdata(&acpi
->dev
);
260 accel
= dev_get_drvdata(&inputdev
->dev
);
262 return sprintf(buf
, "%d\n", accel
->g_select
);
265 static ssize_t
cmpc_accel_g_select_store_v4(struct device
*dev
,
266 struct device_attribute
*attr
,
267 const char *buf
, size_t count
)
269 struct acpi_device
*acpi
;
270 struct input_dev
*inputdev
;
271 struct cmpc_accel
*accel
;
272 unsigned long g_select
;
275 acpi
= to_acpi_device(dev
);
276 inputdev
= dev_get_drvdata(&acpi
->dev
);
277 accel
= dev_get_drvdata(&inputdev
->dev
);
279 r
= kstrtoul(buf
, 0, &g_select
);
283 /* 0 means 1.5g, 1 means 6g, everything else is wrong */
284 if (g_select
!= 0 && g_select
!= 1)
287 accel
->g_select
= g_select
;
288 cmpc_accel_set_g_select_v4(acpi
->handle
, g_select
);
290 return strnlen(buf
, count
);
293 static struct device_attribute cmpc_accel_g_select_attr_v4
= {
294 .attr
= { .name
= "g_select", .mode
= 0660 },
295 .show
= cmpc_accel_g_select_show_v4
,
296 .store
= cmpc_accel_g_select_store_v4
299 static int cmpc_accel_open_v4(struct input_dev
*input
)
301 struct acpi_device
*acpi
;
302 struct cmpc_accel
*accel
;
304 acpi
= to_acpi_device(input
->dev
.parent
);
305 accel
= dev_get_drvdata(&input
->dev
);
307 cmpc_accel_set_sensitivity_v4(acpi
->handle
, accel
->sensitivity
);
308 cmpc_accel_set_g_select_v4(acpi
->handle
, accel
->g_select
);
310 if (ACPI_SUCCESS(cmpc_start_accel_v4(acpi
->handle
))) {
311 accel
->inputdev_state
= CMPC_ACCEL_DEV_STATE_OPEN
;
317 static void cmpc_accel_close_v4(struct input_dev
*input
)
319 struct acpi_device
*acpi
;
320 struct cmpc_accel
*accel
;
322 acpi
= to_acpi_device(input
->dev
.parent
);
323 accel
= dev_get_drvdata(&input
->dev
);
325 cmpc_stop_accel_v4(acpi
->handle
);
326 accel
->inputdev_state
= CMPC_ACCEL_DEV_STATE_CLOSED
;
329 static void cmpc_accel_idev_init_v4(struct input_dev
*inputdev
)
331 set_bit(EV_ABS
, inputdev
->evbit
);
332 input_set_abs_params(inputdev
, ABS_X
, -255, 255, 16, 0);
333 input_set_abs_params(inputdev
, ABS_Y
, -255, 255, 16, 0);
334 input_set_abs_params(inputdev
, ABS_Z
, -255, 255, 16, 0);
335 inputdev
->open
= cmpc_accel_open_v4
;
336 inputdev
->close
= cmpc_accel_close_v4
;
339 #ifdef CONFIG_PM_SLEEP
340 static int cmpc_accel_suspend_v4(struct device
*dev
)
342 struct input_dev
*inputdev
;
343 struct cmpc_accel
*accel
;
345 inputdev
= dev_get_drvdata(dev
);
346 accel
= dev_get_drvdata(&inputdev
->dev
);
348 if (accel
->inputdev_state
== CMPC_ACCEL_DEV_STATE_OPEN
)
349 return cmpc_stop_accel_v4(to_acpi_device(dev
)->handle
);
354 static int cmpc_accel_resume_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 cmpc_accel_set_sensitivity_v4(to_acpi_device(dev
)->handle
,
365 cmpc_accel_set_g_select_v4(to_acpi_device(dev
)->handle
,
368 if (ACPI_FAILURE(cmpc_start_accel_v4(to_acpi_device(dev
)->handle
)))
376 static int cmpc_accel_add_v4(struct acpi_device
*acpi
)
379 struct input_dev
*inputdev
;
380 struct cmpc_accel
*accel
;
382 accel
= kmalloc(sizeof(*accel
), GFP_KERNEL
);
386 accel
->inputdev_state
= CMPC_ACCEL_DEV_STATE_CLOSED
;
388 accel
->sensitivity
= CMPC_ACCEL_SENSITIVITY_DEFAULT
;
389 cmpc_accel_set_sensitivity_v4(acpi
->handle
, accel
->sensitivity
);
391 error
= device_create_file(&acpi
->dev
, &cmpc_accel_sensitivity_attr_v4
);
393 goto failed_sensitivity
;
395 accel
->g_select
= CMPC_ACCEL_G_SELECT_DEFAULT
;
396 cmpc_accel_set_g_select_v4(acpi
->handle
, accel
->g_select
);
398 error
= device_create_file(&acpi
->dev
, &cmpc_accel_g_select_attr_v4
);
400 goto failed_g_select
;
402 error
= cmpc_add_acpi_notify_device(acpi
, "cmpc_accel_v4",
403 cmpc_accel_idev_init_v4
);
407 inputdev
= dev_get_drvdata(&acpi
->dev
);
408 dev_set_drvdata(&inputdev
->dev
, accel
);
413 device_remove_file(&acpi
->dev
, &cmpc_accel_g_select_attr_v4
);
415 device_remove_file(&acpi
->dev
, &cmpc_accel_sensitivity_attr_v4
);
421 static int cmpc_accel_remove_v4(struct acpi_device
*acpi
)
423 device_remove_file(&acpi
->dev
, &cmpc_accel_sensitivity_attr_v4
);
424 device_remove_file(&acpi
->dev
, &cmpc_accel_g_select_attr_v4
);
425 return cmpc_remove_acpi_notify_device(acpi
);
428 static SIMPLE_DEV_PM_OPS(cmpc_accel_pm
, cmpc_accel_suspend_v4
,
429 cmpc_accel_resume_v4
);
431 static const struct acpi_device_id cmpc_accel_device_ids_v4
[] = {
432 {CMPC_ACCEL_HID_V4
, 0},
436 static struct acpi_driver cmpc_accel_acpi_driver_v4
= {
437 .owner
= THIS_MODULE
,
438 .name
= "cmpc_accel_v4",
439 .class = "cmpc_accel_v4",
440 .ids
= cmpc_accel_device_ids_v4
,
442 .add
= cmpc_accel_add_v4
,
443 .remove
= cmpc_accel_remove_v4
,
444 .notify
= cmpc_accel_handler_v4
,
446 .drv
.pm
= &cmpc_accel_pm
,
451 * Accelerometer code for Classmate versions prior to V4
453 static acpi_status
cmpc_start_accel(acpi_handle handle
)
455 union acpi_object param
[2];
456 struct acpi_object_list input
;
459 param
[0].type
= ACPI_TYPE_INTEGER
;
460 param
[0].integer
.value
= 0x3;
461 param
[1].type
= ACPI_TYPE_INTEGER
;
463 input
.pointer
= param
;
464 status
= acpi_evaluate_object(handle
, "ACMD", &input
, NULL
);
468 static acpi_status
cmpc_stop_accel(acpi_handle handle
)
470 union acpi_object param
[2];
471 struct acpi_object_list input
;
474 param
[0].type
= ACPI_TYPE_INTEGER
;
475 param
[0].integer
.value
= 0x4;
476 param
[1].type
= ACPI_TYPE_INTEGER
;
478 input
.pointer
= param
;
479 status
= acpi_evaluate_object(handle
, "ACMD", &input
, NULL
);
483 static acpi_status
cmpc_accel_set_sensitivity(acpi_handle handle
, int val
)
485 union acpi_object param
[2];
486 struct acpi_object_list input
;
488 param
[0].type
= ACPI_TYPE_INTEGER
;
489 param
[0].integer
.value
= 0x02;
490 param
[1].type
= ACPI_TYPE_INTEGER
;
491 param
[1].integer
.value
= val
;
493 input
.pointer
= param
;
494 return acpi_evaluate_object(handle
, "ACMD", &input
, NULL
);
497 static acpi_status
cmpc_get_accel(acpi_handle handle
,
502 union acpi_object param
[2];
503 struct acpi_object_list input
;
504 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
508 param
[0].type
= ACPI_TYPE_INTEGER
;
509 param
[0].integer
.value
= 0x01;
510 param
[1].type
= ACPI_TYPE_INTEGER
;
512 input
.pointer
= param
;
513 status
= acpi_evaluate_object(handle
, "ACMD", &input
, &output
);
514 if (ACPI_SUCCESS(status
)) {
515 union acpi_object
*obj
;
516 obj
= output
.pointer
;
517 locs
= obj
->buffer
.pointer
;
521 kfree(output
.pointer
);
526 static void cmpc_accel_handler(struct acpi_device
*dev
, u32 event
)
529 unsigned char x
, y
, z
;
532 status
= cmpc_get_accel(dev
->handle
, &x
, &y
, &z
);
533 if (ACPI_SUCCESS(status
)) {
534 struct input_dev
*inputdev
= dev_get_drvdata(&dev
->dev
);
536 input_report_abs(inputdev
, ABS_X
, x
);
537 input_report_abs(inputdev
, ABS_Y
, y
);
538 input_report_abs(inputdev
, ABS_Z
, z
);
539 input_sync(inputdev
);
544 static ssize_t
cmpc_accel_sensitivity_show(struct device
*dev
,
545 struct device_attribute
*attr
,
548 struct acpi_device
*acpi
;
549 struct input_dev
*inputdev
;
550 struct cmpc_accel
*accel
;
552 acpi
= to_acpi_device(dev
);
553 inputdev
= dev_get_drvdata(&acpi
->dev
);
554 accel
= dev_get_drvdata(&inputdev
->dev
);
556 return sprintf(buf
, "%d\n", accel
->sensitivity
);
559 static ssize_t
cmpc_accel_sensitivity_store(struct device
*dev
,
560 struct device_attribute
*attr
,
561 const char *buf
, size_t count
)
563 struct acpi_device
*acpi
;
564 struct input_dev
*inputdev
;
565 struct cmpc_accel
*accel
;
566 unsigned long sensitivity
;
569 acpi
= to_acpi_device(dev
);
570 inputdev
= dev_get_drvdata(&acpi
->dev
);
571 accel
= dev_get_drvdata(&inputdev
->dev
);
573 r
= kstrtoul(buf
, 0, &sensitivity
);
577 accel
->sensitivity
= sensitivity
;
578 cmpc_accel_set_sensitivity(acpi
->handle
, sensitivity
);
580 return strnlen(buf
, count
);
583 static struct device_attribute cmpc_accel_sensitivity_attr
= {
584 .attr
= { .name
= "sensitivity", .mode
= 0660 },
585 .show
= cmpc_accel_sensitivity_show
,
586 .store
= cmpc_accel_sensitivity_store
589 static int cmpc_accel_open(struct input_dev
*input
)
591 struct acpi_device
*acpi
;
593 acpi
= to_acpi_device(input
->dev
.parent
);
594 if (ACPI_SUCCESS(cmpc_start_accel(acpi
->handle
)))
599 static void cmpc_accel_close(struct input_dev
*input
)
601 struct acpi_device
*acpi
;
603 acpi
= to_acpi_device(input
->dev
.parent
);
604 cmpc_stop_accel(acpi
->handle
);
607 static void cmpc_accel_idev_init(struct input_dev
*inputdev
)
609 set_bit(EV_ABS
, inputdev
->evbit
);
610 input_set_abs_params(inputdev
, ABS_X
, 0, 255, 8, 0);
611 input_set_abs_params(inputdev
, ABS_Y
, 0, 255, 8, 0);
612 input_set_abs_params(inputdev
, ABS_Z
, 0, 255, 8, 0);
613 inputdev
->open
= cmpc_accel_open
;
614 inputdev
->close
= cmpc_accel_close
;
617 static int cmpc_accel_add(struct acpi_device
*acpi
)
620 struct input_dev
*inputdev
;
621 struct cmpc_accel
*accel
;
623 accel
= kmalloc(sizeof(*accel
), GFP_KERNEL
);
627 accel
->sensitivity
= CMPC_ACCEL_SENSITIVITY_DEFAULT
;
628 cmpc_accel_set_sensitivity(acpi
->handle
, accel
->sensitivity
);
630 error
= device_create_file(&acpi
->dev
, &cmpc_accel_sensitivity_attr
);
634 error
= cmpc_add_acpi_notify_device(acpi
, "cmpc_accel",
635 cmpc_accel_idev_init
);
639 inputdev
= dev_get_drvdata(&acpi
->dev
);
640 dev_set_drvdata(&inputdev
->dev
, accel
);
645 device_remove_file(&acpi
->dev
, &cmpc_accel_sensitivity_attr
);
651 static int cmpc_accel_remove(struct acpi_device
*acpi
)
653 device_remove_file(&acpi
->dev
, &cmpc_accel_sensitivity_attr
);
654 return cmpc_remove_acpi_notify_device(acpi
);
657 static const struct acpi_device_id cmpc_accel_device_ids
[] = {
662 static struct acpi_driver cmpc_accel_acpi_driver
= {
663 .owner
= THIS_MODULE
,
664 .name
= "cmpc_accel",
665 .class = "cmpc_accel",
666 .ids
= cmpc_accel_device_ids
,
668 .add
= cmpc_accel_add
,
669 .remove
= cmpc_accel_remove
,
670 .notify
= cmpc_accel_handler
,
678 static acpi_status
cmpc_get_tablet(acpi_handle handle
,
679 unsigned long long *value
)
681 union acpi_object param
;
682 struct acpi_object_list input
;
683 unsigned long long output
;
686 param
.type
= ACPI_TYPE_INTEGER
;
687 param
.integer
.value
= 0x01;
689 input
.pointer
= ¶m
;
690 status
= acpi_evaluate_integer(handle
, "TCMD", &input
, &output
);
691 if (ACPI_SUCCESS(status
))
696 static void cmpc_tablet_handler(struct acpi_device
*dev
, u32 event
)
698 unsigned long long val
= 0;
699 struct input_dev
*inputdev
= dev_get_drvdata(&dev
->dev
);
702 if (ACPI_SUCCESS(cmpc_get_tablet(dev
->handle
, &val
))) {
703 input_report_switch(inputdev
, SW_TABLET_MODE
, !val
);
704 input_sync(inputdev
);
709 static void cmpc_tablet_idev_init(struct input_dev
*inputdev
)
711 unsigned long long val
= 0;
712 struct acpi_device
*acpi
;
714 set_bit(EV_SW
, inputdev
->evbit
);
715 set_bit(SW_TABLET_MODE
, inputdev
->swbit
);
717 acpi
= to_acpi_device(inputdev
->dev
.parent
);
718 if (ACPI_SUCCESS(cmpc_get_tablet(acpi
->handle
, &val
))) {
719 input_report_switch(inputdev
, SW_TABLET_MODE
, !val
);
720 input_sync(inputdev
);
724 static int cmpc_tablet_add(struct acpi_device
*acpi
)
726 return cmpc_add_acpi_notify_device(acpi
, "cmpc_tablet",
727 cmpc_tablet_idev_init
);
730 static int cmpc_tablet_remove(struct acpi_device
*acpi
)
732 return cmpc_remove_acpi_notify_device(acpi
);
735 #ifdef CONFIG_PM_SLEEP
736 static int cmpc_tablet_resume(struct device
*dev
)
738 struct input_dev
*inputdev
= dev_get_drvdata(dev
);
740 unsigned long long val
= 0;
741 if (ACPI_SUCCESS(cmpc_get_tablet(to_acpi_device(dev
)->handle
, &val
))) {
742 input_report_switch(inputdev
, SW_TABLET_MODE
, !val
);
743 input_sync(inputdev
);
749 static SIMPLE_DEV_PM_OPS(cmpc_tablet_pm
, NULL
, cmpc_tablet_resume
);
751 static const struct acpi_device_id cmpc_tablet_device_ids
[] = {
752 {CMPC_TABLET_HID
, 0},
756 static struct acpi_driver cmpc_tablet_acpi_driver
= {
757 .owner
= THIS_MODULE
,
758 .name
= "cmpc_tablet",
759 .class = "cmpc_tablet",
760 .ids
= cmpc_tablet_device_ids
,
762 .add
= cmpc_tablet_add
,
763 .remove
= cmpc_tablet_remove
,
764 .notify
= cmpc_tablet_handler
,
766 .drv
.pm
= &cmpc_tablet_pm
,
774 static acpi_status
cmpc_get_brightness(acpi_handle handle
,
775 unsigned long long *value
)
777 union acpi_object param
;
778 struct acpi_object_list input
;
779 unsigned long long output
;
782 param
.type
= ACPI_TYPE_INTEGER
;
783 param
.integer
.value
= 0xC0;
785 input
.pointer
= ¶m
;
786 status
= acpi_evaluate_integer(handle
, "GRDI", &input
, &output
);
787 if (ACPI_SUCCESS(status
))
792 static acpi_status
cmpc_set_brightness(acpi_handle handle
,
793 unsigned long long value
)
795 union acpi_object param
[2];
796 struct acpi_object_list input
;
798 unsigned long long output
;
800 param
[0].type
= ACPI_TYPE_INTEGER
;
801 param
[0].integer
.value
= 0xC0;
802 param
[1].type
= ACPI_TYPE_INTEGER
;
803 param
[1].integer
.value
= value
;
805 input
.pointer
= param
;
806 status
= acpi_evaluate_integer(handle
, "GWRI", &input
, &output
);
810 static int cmpc_bl_get_brightness(struct backlight_device
*bd
)
814 unsigned long long brightness
;
816 handle
= bl_get_data(bd
);
817 status
= cmpc_get_brightness(handle
, &brightness
);
818 if (ACPI_SUCCESS(status
))
824 static int cmpc_bl_update_status(struct backlight_device
*bd
)
829 handle
= bl_get_data(bd
);
830 status
= cmpc_set_brightness(handle
, bd
->props
.brightness
);
831 if (ACPI_SUCCESS(status
))
837 static const struct backlight_ops cmpc_bl_ops
= {
838 .get_brightness
= cmpc_bl_get_brightness
,
839 .update_status
= cmpc_bl_update_status
846 static acpi_status
cmpc_get_rfkill_wlan(acpi_handle handle
,
847 unsigned long long *value
)
849 union acpi_object param
;
850 struct acpi_object_list input
;
851 unsigned long long output
;
854 param
.type
= ACPI_TYPE_INTEGER
;
855 param
.integer
.value
= 0xC1;
857 input
.pointer
= ¶m
;
858 status
= acpi_evaluate_integer(handle
, "GRDI", &input
, &output
);
859 if (ACPI_SUCCESS(status
))
864 static acpi_status
cmpc_set_rfkill_wlan(acpi_handle handle
,
865 unsigned long long value
)
867 union acpi_object param
[2];
868 struct acpi_object_list input
;
870 unsigned long long output
;
872 param
[0].type
= ACPI_TYPE_INTEGER
;
873 param
[0].integer
.value
= 0xC1;
874 param
[1].type
= ACPI_TYPE_INTEGER
;
875 param
[1].integer
.value
= value
;
877 input
.pointer
= param
;
878 status
= acpi_evaluate_integer(handle
, "GWRI", &input
, &output
);
882 static void cmpc_rfkill_query(struct rfkill
*rfkill
, void *data
)
886 unsigned long long state
;
890 status
= cmpc_get_rfkill_wlan(handle
, &state
);
891 if (ACPI_SUCCESS(status
)) {
892 blocked
= state
& 1 ? false : true;
893 rfkill_set_sw_state(rfkill
, blocked
);
897 static int cmpc_rfkill_block(void *data
, bool blocked
)
901 unsigned long long state
;
905 status
= cmpc_get_rfkill_wlan(handle
, &state
);
906 if (ACPI_FAILURE(status
))
908 /* Check if we really need to call cmpc_set_rfkill_wlan */
909 is_blocked
= state
& 1 ? false : true;
910 if (is_blocked
!= blocked
) {
911 state
= blocked
? 0 : 1;
912 status
= cmpc_set_rfkill_wlan(handle
, state
);
913 if (ACPI_FAILURE(status
))
919 static const struct rfkill_ops cmpc_rfkill_ops
= {
920 .query
= cmpc_rfkill_query
,
921 .set_block
= cmpc_rfkill_block
,
925 * Common backlight and rfkill code.
929 struct backlight_device
*bd
;
933 static int cmpc_ipml_add(struct acpi_device
*acpi
)
936 struct ipml200_dev
*ipml
;
937 struct backlight_properties props
;
939 ipml
= kmalloc(sizeof(*ipml
), GFP_KERNEL
);
943 memset(&props
, 0, sizeof(struct backlight_properties
));
944 props
.type
= BACKLIGHT_PLATFORM
;
945 props
.max_brightness
= 7;
946 ipml
->bd
= backlight_device_register("cmpc_bl", &acpi
->dev
,
947 acpi
->handle
, &cmpc_bl_ops
,
949 if (IS_ERR(ipml
->bd
)) {
950 retval
= PTR_ERR(ipml
->bd
);
954 ipml
->rf
= rfkill_alloc("cmpc_rfkill", &acpi
->dev
, RFKILL_TYPE_WLAN
,
955 &cmpc_rfkill_ops
, acpi
->handle
);
957 * If RFKILL is disabled, rfkill_alloc will return ERR_PTR(-ENODEV).
958 * This is OK, however, since all other uses of the device will not
962 retval
= rfkill_register(ipml
->rf
);
964 rfkill_destroy(ipml
->rf
);
969 dev_set_drvdata(&acpi
->dev
, ipml
);
977 static int cmpc_ipml_remove(struct acpi_device
*acpi
)
979 struct ipml200_dev
*ipml
;
981 ipml
= dev_get_drvdata(&acpi
->dev
);
983 backlight_device_unregister(ipml
->bd
);
986 rfkill_unregister(ipml
->rf
);
987 rfkill_destroy(ipml
->rf
);
995 static const struct acpi_device_id cmpc_ipml_device_ids
[] = {
1000 static struct acpi_driver cmpc_ipml_acpi_driver
= {
1001 .owner
= THIS_MODULE
,
1004 .ids
= cmpc_ipml_device_ids
,
1006 .add
= cmpc_ipml_add
,
1007 .remove
= cmpc_ipml_remove
1015 static int cmpc_keys_codes
[] = {
1018 KEY_SWITCHVIDEOMODE
,
1027 KEY_WLAN
, /* NL3: 0x8b (press), 0x9b (release) */
1031 static void cmpc_keys_handler(struct acpi_device
*dev
, u32 event
)
1033 struct input_dev
*inputdev
;
1036 if ((event
& 0x0F) < ARRAY_SIZE(cmpc_keys_codes
))
1037 code
= cmpc_keys_codes
[event
& 0x0F];
1038 inputdev
= dev_get_drvdata(&dev
->dev
);
1039 input_report_key(inputdev
, code
, !(event
& 0x10));
1040 input_sync(inputdev
);
1043 static void cmpc_keys_idev_init(struct input_dev
*inputdev
)
1047 set_bit(EV_KEY
, inputdev
->evbit
);
1048 for (i
= 0; cmpc_keys_codes
[i
] != KEY_MAX
; i
++)
1049 set_bit(cmpc_keys_codes
[i
], inputdev
->keybit
);
1052 static int cmpc_keys_add(struct acpi_device
*acpi
)
1054 return cmpc_add_acpi_notify_device(acpi
, "cmpc_keys",
1055 cmpc_keys_idev_init
);
1058 static int cmpc_keys_remove(struct acpi_device
*acpi
)
1060 return cmpc_remove_acpi_notify_device(acpi
);
1063 static const struct acpi_device_id cmpc_keys_device_ids
[] = {
1068 static struct acpi_driver cmpc_keys_acpi_driver
= {
1069 .owner
= THIS_MODULE
,
1070 .name
= "cmpc_keys",
1071 .class = "cmpc_keys",
1072 .ids
= cmpc_keys_device_ids
,
1074 .add
= cmpc_keys_add
,
1075 .remove
= cmpc_keys_remove
,
1076 .notify
= cmpc_keys_handler
,
1082 * General init/exit code.
1085 static int cmpc_init(void)
1089 r
= acpi_bus_register_driver(&cmpc_keys_acpi_driver
);
1093 r
= acpi_bus_register_driver(&cmpc_ipml_acpi_driver
);
1097 r
= acpi_bus_register_driver(&cmpc_tablet_acpi_driver
);
1101 r
= acpi_bus_register_driver(&cmpc_accel_acpi_driver
);
1105 r
= acpi_bus_register_driver(&cmpc_accel_acpi_driver_v4
);
1107 goto failed_accel_v4
;
1112 acpi_bus_unregister_driver(&cmpc_accel_acpi_driver
);
1115 acpi_bus_unregister_driver(&cmpc_tablet_acpi_driver
);
1118 acpi_bus_unregister_driver(&cmpc_ipml_acpi_driver
);
1121 acpi_bus_unregister_driver(&cmpc_keys_acpi_driver
);
1127 static void cmpc_exit(void)
1129 acpi_bus_unregister_driver(&cmpc_accel_acpi_driver_v4
);
1130 acpi_bus_unregister_driver(&cmpc_accel_acpi_driver
);
1131 acpi_bus_unregister_driver(&cmpc_tablet_acpi_driver
);
1132 acpi_bus_unregister_driver(&cmpc_ipml_acpi_driver
);
1133 acpi_bus_unregister_driver(&cmpc_keys_acpi_driver
);
1136 module_init(cmpc_init
);
1137 module_exit(cmpc_exit
);
1139 static const struct acpi_device_id cmpc_device_ids
[] = {
1140 {CMPC_ACCEL_HID
, 0},
1141 {CMPC_ACCEL_HID_V4
, 0},
1142 {CMPC_TABLET_HID
, 0},
1148 MODULE_DEVICE_TABLE(acpi
, cmpc_device_ids
);