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 static int cmpc_accel_suspend_v4(struct device *dev)
355 struct input_dev *inputdev;
356 struct cmpc_accel *accel;
358 inputdev = dev_get_drvdata(dev);
359 accel = dev_get_drvdata(&inputdev->dev);
361 if (accel->inputdev_state == CMPC_ACCEL_DEV_STATE_OPEN)
362 return cmpc_stop_accel_v4(to_acpi_device(dev)->handle);
367 static int cmpc_accel_resume_v4(struct device *dev)
369 struct input_dev *inputdev;
370 struct cmpc_accel *accel;
372 inputdev = dev_get_drvdata(dev);
373 accel = dev_get_drvdata(&inputdev->dev);
375 if (accel->inputdev_state == CMPC_ACCEL_DEV_STATE_OPEN) {
376 cmpc_accel_set_sensitivity_v4(to_acpi_device(dev)->handle,
378 cmpc_accel_set_g_select_v4(to_acpi_device(dev)->handle,
381 if (ACPI_FAILURE(cmpc_start_accel_v4(to_acpi_device(dev)->handle)))
388 static int cmpc_accel_add_v4(struct acpi_device *acpi)
391 struct input_dev *inputdev;
392 struct cmpc_accel *accel;
394 accel = kmalloc(sizeof(*accel), GFP_KERNEL);
398 accel->inputdev_state = CMPC_ACCEL_DEV_STATE_CLOSED;
400 accel->sensitivity = CMPC_ACCEL_SENSITIVITY_DEFAULT;
401 cmpc_accel_set_sensitivity_v4(acpi->handle, accel->sensitivity);
403 error = device_create_file(&acpi->dev, &cmpc_accel_sensitivity_attr_v4);
405 goto failed_sensitivity;
407 accel->g_select = CMPC_ACCEL_G_SELECT_DEFAULT;
408 cmpc_accel_set_g_select_v4(acpi->handle, accel->g_select);
410 error = device_create_file(&acpi->dev, &cmpc_accel_g_select_attr_v4);
412 goto failed_g_select;
414 error = cmpc_add_acpi_notify_device(acpi, "cmpc_accel_v4",
415 cmpc_accel_idev_init_v4);
419 inputdev = dev_get_drvdata(&acpi->dev);
420 dev_set_drvdata(&inputdev->dev, accel);
425 device_remove_file(&acpi->dev, &cmpc_accel_g_select_attr_v4);
427 device_remove_file(&acpi->dev, &cmpc_accel_sensitivity_attr_v4);
433 static int cmpc_accel_remove_v4(struct acpi_device *acpi, int type)
435 struct input_dev *inputdev;
436 struct cmpc_accel *accel;
438 inputdev = dev_get_drvdata(&acpi->dev);
439 accel = dev_get_drvdata(&inputdev->dev);
441 device_remove_file(&acpi->dev, &cmpc_accel_sensitivity_attr_v4);
442 device_remove_file(&acpi->dev, &cmpc_accel_g_select_attr_v4);
443 return cmpc_remove_acpi_notify_device(acpi);
446 static SIMPLE_DEV_PM_OPS(cmpc_accel_pm, cmpc_accel_suspend_v4,
447 cmpc_accel_resume_v4);
449 static const struct acpi_device_id cmpc_accel_device_ids_v4[] = {
450 {CMPC_ACCEL_HID_V4, 0},
454 static struct acpi_driver cmpc_accel_acpi_driver_v4 = {
455 .owner = THIS_MODULE,
456 .name = "cmpc_accel_v4",
457 .class = "cmpc_accel_v4",
458 .ids = cmpc_accel_device_ids_v4,
460 .add = cmpc_accel_add_v4,
461 .remove = cmpc_accel_remove_v4,
462 .notify = cmpc_accel_handler_v4,
464 .drv.pm = &cmpc_accel_pm,
469 * Accelerometer code for Classmate versions prior to V4
471 static acpi_status cmpc_start_accel(acpi_handle handle)
473 union acpi_object param[2];
474 struct acpi_object_list input;
477 param[0].type = ACPI_TYPE_INTEGER;
478 param[0].integer.value = 0x3;
479 param[1].type = ACPI_TYPE_INTEGER;
481 input.pointer = param;
482 status = acpi_evaluate_object(handle, "ACMD", &input, NULL);
486 static acpi_status cmpc_stop_accel(acpi_handle handle)
488 union acpi_object param[2];
489 struct acpi_object_list input;
492 param[0].type = ACPI_TYPE_INTEGER;
493 param[0].integer.value = 0x4;
494 param[1].type = ACPI_TYPE_INTEGER;
496 input.pointer = param;
497 status = acpi_evaluate_object(handle, "ACMD", &input, NULL);
501 static acpi_status cmpc_accel_set_sensitivity(acpi_handle handle, int val)
503 union acpi_object param[2];
504 struct acpi_object_list input;
506 param[0].type = ACPI_TYPE_INTEGER;
507 param[0].integer.value = 0x02;
508 param[1].type = ACPI_TYPE_INTEGER;
509 param[1].integer.value = val;
511 input.pointer = param;
512 return acpi_evaluate_object(handle, "ACMD", &input, NULL);
515 static acpi_status cmpc_get_accel(acpi_handle handle,
520 union acpi_object param[2];
521 struct acpi_object_list input;
522 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, 0 };
526 param[0].type = ACPI_TYPE_INTEGER;
527 param[0].integer.value = 0x01;
528 param[1].type = ACPI_TYPE_INTEGER;
530 input.pointer = param;
531 status = acpi_evaluate_object(handle, "ACMD", &input, &output);
532 if (ACPI_SUCCESS(status)) {
533 union acpi_object *obj;
534 obj = output.pointer;
535 locs = obj->buffer.pointer;
539 kfree(output.pointer);
544 static void cmpc_accel_handler(struct acpi_device *dev, u32 event)
547 unsigned char x, y, z;
550 status = cmpc_get_accel(dev->handle, &x, &y, &z);
551 if (ACPI_SUCCESS(status)) {
552 struct input_dev *inputdev = dev_get_drvdata(&dev->dev);
554 input_report_abs(inputdev, ABS_X, x);
555 input_report_abs(inputdev, ABS_Y, y);
556 input_report_abs(inputdev, ABS_Z, z);
557 input_sync(inputdev);
562 static ssize_t cmpc_accel_sensitivity_show(struct device *dev,
563 struct device_attribute *attr,
566 struct acpi_device *acpi;
567 struct input_dev *inputdev;
568 struct cmpc_accel *accel;
570 acpi = to_acpi_device(dev);
571 inputdev = dev_get_drvdata(&acpi->dev);
572 accel = dev_get_drvdata(&inputdev->dev);
574 return sprintf(buf, "%d\n", accel->sensitivity);
577 static ssize_t cmpc_accel_sensitivity_store(struct device *dev,
578 struct device_attribute *attr,
579 const char *buf, size_t count)
581 struct acpi_device *acpi;
582 struct input_dev *inputdev;
583 struct cmpc_accel *accel;
584 unsigned long sensitivity;
587 acpi = to_acpi_device(dev);
588 inputdev = dev_get_drvdata(&acpi->dev);
589 accel = dev_get_drvdata(&inputdev->dev);
591 r = strict_strtoul(buf, 0, &sensitivity);
595 accel->sensitivity = sensitivity;
596 cmpc_accel_set_sensitivity(acpi->handle, sensitivity);
598 return strnlen(buf, count);
601 static struct device_attribute cmpc_accel_sensitivity_attr = {
602 .attr = { .name = "sensitivity", .mode = 0660 },
603 .show = cmpc_accel_sensitivity_show,
604 .store = cmpc_accel_sensitivity_store
607 static int cmpc_accel_open(struct input_dev *input)
609 struct acpi_device *acpi;
611 acpi = to_acpi_device(input->dev.parent);
612 if (ACPI_SUCCESS(cmpc_start_accel(acpi->handle)))
617 static void cmpc_accel_close(struct input_dev *input)
619 struct acpi_device *acpi;
621 acpi = to_acpi_device(input->dev.parent);
622 cmpc_stop_accel(acpi->handle);
625 static void cmpc_accel_idev_init(struct input_dev *inputdev)
627 set_bit(EV_ABS, inputdev->evbit);
628 input_set_abs_params(inputdev, ABS_X, 0, 255, 8, 0);
629 input_set_abs_params(inputdev, ABS_Y, 0, 255, 8, 0);
630 input_set_abs_params(inputdev, ABS_Z, 0, 255, 8, 0);
631 inputdev->open = cmpc_accel_open;
632 inputdev->close = cmpc_accel_close;
635 static int cmpc_accel_add(struct acpi_device *acpi)
638 struct input_dev *inputdev;
639 struct cmpc_accel *accel;
641 accel = kmalloc(sizeof(*accel), GFP_KERNEL);
645 accel->sensitivity = CMPC_ACCEL_SENSITIVITY_DEFAULT;
646 cmpc_accel_set_sensitivity(acpi->handle, accel->sensitivity);
648 error = device_create_file(&acpi->dev, &cmpc_accel_sensitivity_attr);
652 error = cmpc_add_acpi_notify_device(acpi, "cmpc_accel",
653 cmpc_accel_idev_init);
657 inputdev = dev_get_drvdata(&acpi->dev);
658 dev_set_drvdata(&inputdev->dev, accel);
663 device_remove_file(&acpi->dev, &cmpc_accel_sensitivity_attr);
669 static int cmpc_accel_remove(struct acpi_device *acpi, int type)
671 struct input_dev *inputdev;
672 struct cmpc_accel *accel;
674 inputdev = dev_get_drvdata(&acpi->dev);
675 accel = dev_get_drvdata(&inputdev->dev);
677 device_remove_file(&acpi->dev, &cmpc_accel_sensitivity_attr);
678 return cmpc_remove_acpi_notify_device(acpi);
681 static const struct acpi_device_id cmpc_accel_device_ids[] = {
686 static struct acpi_driver cmpc_accel_acpi_driver = {
687 .owner = THIS_MODULE,
688 .name = "cmpc_accel",
689 .class = "cmpc_accel",
690 .ids = cmpc_accel_device_ids,
692 .add = cmpc_accel_add,
693 .remove = cmpc_accel_remove,
694 .notify = cmpc_accel_handler,
702 static acpi_status cmpc_get_tablet(acpi_handle handle,
703 unsigned long long *value)
705 union acpi_object param;
706 struct acpi_object_list input;
707 unsigned long long output;
710 param.type = ACPI_TYPE_INTEGER;
711 param.integer.value = 0x01;
713 input.pointer = ¶m;
714 status = acpi_evaluate_integer(handle, "TCMD", &input, &output);
715 if (ACPI_SUCCESS(status))
720 static void cmpc_tablet_handler(struct acpi_device *dev, u32 event)
722 unsigned long long val = 0;
723 struct input_dev *inputdev = dev_get_drvdata(&dev->dev);
726 if (ACPI_SUCCESS(cmpc_get_tablet(dev->handle, &val)))
727 input_report_switch(inputdev, SW_TABLET_MODE, !val);
731 static void cmpc_tablet_idev_init(struct input_dev *inputdev)
733 unsigned long long val = 0;
734 struct acpi_device *acpi;
736 set_bit(EV_SW, inputdev->evbit);
737 set_bit(SW_TABLET_MODE, inputdev->swbit);
739 acpi = to_acpi_device(inputdev->dev.parent);
740 if (ACPI_SUCCESS(cmpc_get_tablet(acpi->handle, &val)))
741 input_report_switch(inputdev, SW_TABLET_MODE, !val);
744 static int cmpc_tablet_add(struct acpi_device *acpi)
746 return cmpc_add_acpi_notify_device(acpi, "cmpc_tablet",
747 cmpc_tablet_idev_init);
750 static int cmpc_tablet_remove(struct acpi_device *acpi, int type)
752 return cmpc_remove_acpi_notify_device(acpi);
755 static int cmpc_tablet_resume(struct device *dev)
757 struct input_dev *inputdev = dev_get_drvdata(dev);
759 unsigned long long val = 0;
760 if (ACPI_SUCCESS(cmpc_get_tablet(to_acpi_device(dev)->handle, &val)))
761 input_report_switch(inputdev, SW_TABLET_MODE, !val);
765 static SIMPLE_DEV_PM_OPS(cmpc_tablet_pm, NULL, cmpc_tablet_resume);
767 static const struct acpi_device_id cmpc_tablet_device_ids[] = {
768 {CMPC_TABLET_HID, 0},
772 static struct acpi_driver cmpc_tablet_acpi_driver = {
773 .owner = THIS_MODULE,
774 .name = "cmpc_tablet",
775 .class = "cmpc_tablet",
776 .ids = cmpc_tablet_device_ids,
778 .add = cmpc_tablet_add,
779 .remove = cmpc_tablet_remove,
780 .notify = cmpc_tablet_handler,
782 .drv.pm = &cmpc_tablet_pm,
790 static acpi_status cmpc_get_brightness(acpi_handle handle,
791 unsigned long long *value)
793 union acpi_object param;
794 struct acpi_object_list input;
795 unsigned long long output;
798 param.type = ACPI_TYPE_INTEGER;
799 param.integer.value = 0xC0;
801 input.pointer = ¶m;
802 status = acpi_evaluate_integer(handle, "GRDI", &input, &output);
803 if (ACPI_SUCCESS(status))
808 static acpi_status cmpc_set_brightness(acpi_handle handle,
809 unsigned long long value)
811 union acpi_object param[2];
812 struct acpi_object_list input;
814 unsigned long long output;
816 param[0].type = ACPI_TYPE_INTEGER;
817 param[0].integer.value = 0xC0;
818 param[1].type = ACPI_TYPE_INTEGER;
819 param[1].integer.value = value;
821 input.pointer = param;
822 status = acpi_evaluate_integer(handle, "GWRI", &input, &output);
826 static int cmpc_bl_get_brightness(struct backlight_device *bd)
830 unsigned long long brightness;
832 handle = bl_get_data(bd);
833 status = cmpc_get_brightness(handle, &brightness);
834 if (ACPI_SUCCESS(status))
840 static int cmpc_bl_update_status(struct backlight_device *bd)
845 handle = bl_get_data(bd);
846 status = cmpc_set_brightness(handle, bd->props.brightness);
847 if (ACPI_SUCCESS(status))
853 static const struct backlight_ops cmpc_bl_ops = {
854 .get_brightness = cmpc_bl_get_brightness,
855 .update_status = cmpc_bl_update_status
862 static acpi_status cmpc_get_rfkill_wlan(acpi_handle handle,
863 unsigned long long *value)
865 union acpi_object param;
866 struct acpi_object_list input;
867 unsigned long long output;
870 param.type = ACPI_TYPE_INTEGER;
871 param.integer.value = 0xC1;
873 input.pointer = ¶m;
874 status = acpi_evaluate_integer(handle, "GRDI", &input, &output);
875 if (ACPI_SUCCESS(status))
880 static acpi_status cmpc_set_rfkill_wlan(acpi_handle handle,
881 unsigned long long value)
883 union acpi_object param[2];
884 struct acpi_object_list input;
886 unsigned long long output;
888 param[0].type = ACPI_TYPE_INTEGER;
889 param[0].integer.value = 0xC1;
890 param[1].type = ACPI_TYPE_INTEGER;
891 param[1].integer.value = value;
893 input.pointer = param;
894 status = acpi_evaluate_integer(handle, "GWRI", &input, &output);
898 static void cmpc_rfkill_query(struct rfkill *rfkill, void *data)
902 unsigned long long state;
906 status = cmpc_get_rfkill_wlan(handle, &state);
907 if (ACPI_SUCCESS(status)) {
908 blocked = state & 1 ? false : true;
909 rfkill_set_sw_state(rfkill, blocked);
913 static int cmpc_rfkill_block(void *data, bool blocked)
917 unsigned long long state;
921 status = cmpc_get_rfkill_wlan(handle, &state);
922 if (ACPI_FAILURE(status))
924 /* Check if we really need to call cmpc_set_rfkill_wlan */
925 is_blocked = state & 1 ? false : true;
926 if (is_blocked != blocked) {
927 state = blocked ? 0 : 1;
928 status = cmpc_set_rfkill_wlan(handle, state);
929 if (ACPI_FAILURE(status))
935 static const struct rfkill_ops cmpc_rfkill_ops = {
936 .query = cmpc_rfkill_query,
937 .set_block = cmpc_rfkill_block,
941 * Common backlight and rfkill code.
945 struct backlight_device *bd;
949 static int cmpc_ipml_add(struct acpi_device *acpi)
952 struct ipml200_dev *ipml;
953 struct backlight_properties props;
955 ipml = kmalloc(sizeof(*ipml), GFP_KERNEL);
959 memset(&props, 0, sizeof(struct backlight_properties));
960 props.type = BACKLIGHT_PLATFORM;
961 props.max_brightness = 7;
962 ipml->bd = backlight_device_register("cmpc_bl", &acpi->dev,
963 acpi->handle, &cmpc_bl_ops,
965 if (IS_ERR(ipml->bd)) {
966 retval = PTR_ERR(ipml->bd);
970 ipml->rf = rfkill_alloc("cmpc_rfkill", &acpi->dev, RFKILL_TYPE_WLAN,
971 &cmpc_rfkill_ops, acpi->handle);
973 * If RFKILL is disabled, rfkill_alloc will return ERR_PTR(-ENODEV).
974 * This is OK, however, since all other uses of the device will not
978 retval = rfkill_register(ipml->rf);
980 rfkill_destroy(ipml->rf);
985 dev_set_drvdata(&acpi->dev, ipml);
993 static int cmpc_ipml_remove(struct acpi_device *acpi, int type)
995 struct ipml200_dev *ipml;
997 ipml = dev_get_drvdata(&acpi->dev);
999 backlight_device_unregister(ipml->bd);
1002 rfkill_unregister(ipml->rf);
1003 rfkill_destroy(ipml->rf);
1011 static const struct acpi_device_id cmpc_ipml_device_ids[] = {
1016 static struct acpi_driver cmpc_ipml_acpi_driver = {
1017 .owner = THIS_MODULE,
1020 .ids = cmpc_ipml_device_ids,
1022 .add = cmpc_ipml_add,
1023 .remove = cmpc_ipml_remove
1031 static int cmpc_keys_codes[] = {
1034 KEY_SWITCHVIDEOMODE,
1045 static void cmpc_keys_handler(struct acpi_device *dev, u32 event)
1047 struct input_dev *inputdev;
1050 if ((event & 0x0F) < ARRAY_SIZE(cmpc_keys_codes))
1051 code = cmpc_keys_codes[event & 0x0F];
1052 inputdev = dev_get_drvdata(&dev->dev);
1053 input_report_key(inputdev, code, !(event & 0x10));
1054 input_sync(inputdev);
1057 static void cmpc_keys_idev_init(struct input_dev *inputdev)
1061 set_bit(EV_KEY, inputdev->evbit);
1062 for (i = 0; cmpc_keys_codes[i] != KEY_MAX; i++)
1063 set_bit(cmpc_keys_codes[i], inputdev->keybit);
1066 static int cmpc_keys_add(struct acpi_device *acpi)
1068 return cmpc_add_acpi_notify_device(acpi, "cmpc_keys",
1069 cmpc_keys_idev_init);
1072 static int cmpc_keys_remove(struct acpi_device *acpi, int type)
1074 return cmpc_remove_acpi_notify_device(acpi);
1077 static const struct acpi_device_id cmpc_keys_device_ids[] = {
1082 static struct acpi_driver cmpc_keys_acpi_driver = {
1083 .owner = THIS_MODULE,
1084 .name = "cmpc_keys",
1085 .class = "cmpc_keys",
1086 .ids = cmpc_keys_device_ids,
1088 .add = cmpc_keys_add,
1089 .remove = cmpc_keys_remove,
1090 .notify = cmpc_keys_handler,
1096 * General init/exit code.
1099 static int cmpc_init(void)
1103 r = acpi_bus_register_driver(&cmpc_keys_acpi_driver);
1107 r = acpi_bus_register_driver(&cmpc_ipml_acpi_driver);
1111 r = acpi_bus_register_driver(&cmpc_tablet_acpi_driver);
1115 r = acpi_bus_register_driver(&cmpc_accel_acpi_driver);
1119 r = acpi_bus_register_driver(&cmpc_accel_acpi_driver_v4);
1121 goto failed_accel_v4;
1126 acpi_bus_unregister_driver(&cmpc_accel_acpi_driver);
1129 acpi_bus_unregister_driver(&cmpc_tablet_acpi_driver);
1132 acpi_bus_unregister_driver(&cmpc_ipml_acpi_driver);
1135 acpi_bus_unregister_driver(&cmpc_keys_acpi_driver);
1141 static void cmpc_exit(void)
1143 acpi_bus_unregister_driver(&cmpc_accel_acpi_driver_v4);
1144 acpi_bus_unregister_driver(&cmpc_accel_acpi_driver);
1145 acpi_bus_unregister_driver(&cmpc_tablet_acpi_driver);
1146 acpi_bus_unregister_driver(&cmpc_ipml_acpi_driver);
1147 acpi_bus_unregister_driver(&cmpc_keys_acpi_driver);
1150 module_init(cmpc_init);
1151 module_exit(cmpc_exit);
1153 static const struct acpi_device_id cmpc_device_ids[] = {
1154 {CMPC_ACCEL_HID, 0},
1155 {CMPC_ACCEL_HID_V4, 0},
1156 {CMPC_TABLET_HID, 0},
1162 MODULE_DEVICE_TABLE(acpi, cmpc_device_ids);