21 #include <linux/module.h>
22 #include <linux/slab.h>
26 #include <linux/input.h>
27 #include <linux/rfkill.h>
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"
56 static int cmpc_add_acpi_notify_device(
struct acpi_device *acpi,
char *
name,
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);
77 static int cmpc_remove_acpi_notify_device(
struct acpi_device *acpi)
80 input_unregister_device(inputdev);
94 param[0].integer.value = 0x3;
96 param[1].integer.value = 0;
98 param[2].integer.value = 0;
100 param[3].integer.value = 0;
114 param[0].integer.value = 0x4;
116 param[1].integer.value = 0;
118 param[2].integer.value = 0;
120 param[3].integer.value = 0;
133 param[0].integer.value = 0x02;
137 param[2].integer.value = 0;
139 param[3].integer.value = 0;
151 param[0].integer.value = 0x05;
155 param[2].integer.value = 0;
157 param[3].integer.value = 0;
175 param[0].integer.value = 0x01;
177 param[1].integer.value = 0;
179 param[2].integer.value = 0;
181 param[3].integer.value = 0;
197 static void cmpc_accel_handler_v4(
struct acpi_device *
dev,
u32 event)
203 status = cmpc_get_accel_v4(dev->handle, &x, &y, &z);
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,
219 struct acpi_device *acpi;
220 struct input_dev *inputdev;
223 acpi = to_acpi_device(dev);
230 static ssize_t cmpc_accel_sensitivity_store_v4(
struct device *dev,
234 struct acpi_device *acpi;
235 struct input_dev *inputdev;
240 acpi = to_acpi_device(dev);
244 r = kstrtoul(buf, 0, &sensitivity);
249 if (sensitivity < 1 || sensitivity > 127)
253 cmpc_accel_set_sensitivity_v4(acpi->handle, sensitivity);
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,
268 struct acpi_device *acpi;
269 struct input_dev *inputdev;
272 acpi = to_acpi_device(dev);
279 static ssize_t cmpc_accel_g_select_store_v4(
struct device *dev,
281 const char *buf,
size_t count)
283 struct acpi_device *acpi;
284 struct input_dev *inputdev;
289 acpi = to_acpi_device(dev);
293 r = kstrtoul(buf, 0, &g_select);
298 if (g_select != 0 && g_select != 1)
302 cmpc_accel_set_g_select_v4(acpi->handle, g_select);
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;
318 acpi = to_acpi_device(input->dev.parent);
321 cmpc_accel_set_sensitivity_v4(acpi->handle, accel->
sensitivity);
322 cmpc_accel_set_g_select_v4(acpi->handle, accel->
g_select);
331 static void cmpc_accel_close_v4(
struct input_dev *input)
333 struct acpi_device *acpi;
336 acpi = to_acpi_device(input->dev.parent);
339 cmpc_stop_accel_v4(acpi->handle);
343 static void cmpc_accel_idev_init_v4(
struct input_dev *inputdev)
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;
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;
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;
403 cmpc_accel_set_sensitivity_v4(acpi->handle, accel->
sensitivity);
407 goto failed_sensitivity;
410 cmpc_accel_set_g_select_v4(acpi->handle, accel->
g_select);
414 goto failed_g_select;
416 error = cmpc_add_acpi_notify_device(acpi,
"cmpc_accel_v4",
417 cmpc_accel_idev_init_v4);
435 static int cmpc_accel_remove_v4(
struct acpi_device *acpi,
int type)
437 struct input_dev *inputdev;
445 return cmpc_remove_acpi_notify_device(acpi);
449 cmpc_accel_resume_v4);
456 static struct acpi_driver cmpc_accel_acpi_driver_v4 = {
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,
480 param[0].integer.value = 0x3;
483 input.pointer =
param;
495 param[0].integer.value = 0x4;
498 input.pointer =
param;
509 param[0].integer.value = 0x02;
513 input.pointer =
param;
529 param[0].integer.value = 0x01;
532 input.pointer =
param;
537 locs = obj->
buffer.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);
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,
568 struct acpi_device *acpi;
569 struct input_dev *inputdev;
572 acpi = to_acpi_device(dev);
579 static ssize_t cmpc_accel_sensitivity_store(
struct device *dev,
581 const char *buf,
size_t count)
583 struct acpi_device *acpi;
584 struct input_dev *inputdev;
589 acpi = to_acpi_device(dev);
598 cmpc_accel_set_sensitivity(acpi->handle, sensitivity);
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);
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)
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;
648 cmpc_accel_set_sensitivity(acpi->handle, accel->
sensitivity);
654 error = cmpc_add_acpi_notify_device(acpi,
"cmpc_accel",
655 cmpc_accel_idev_init);
671 static int cmpc_accel_remove(
struct acpi_device *acpi,
int type)
673 struct input_dev *inputdev;
680 return cmpc_remove_acpi_notify_device(acpi);
688 static struct acpi_driver cmpc_accel_acpi_driver = {
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,
705 unsigned long long *
value)
709 unsigned long long output;
713 param.integer.value = 0x01;
715 input.pointer = &
param;
722 static void cmpc_tablet_handler(
struct acpi_device *dev,
u32 event)
724 unsigned long long val = 0;
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;
743 acpi = to_acpi_device(inputdev->dev.parent);
744 if (
ACPI_SUCCESS(cmpc_get_tablet(acpi->handle, &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,
int type)
758 return cmpc_remove_acpi_notify_device(acpi);
761 #ifdef CONFIG_PM_SLEEP
762 static int cmpc_tablet_resume(
struct device *dev)
766 unsigned long long val = 0;
767 if (
ACPI_SUCCESS(cmpc_get_tablet(to_acpi_device(dev)->handle, &val))) {
769 input_sync(inputdev);
782 static struct acpi_driver cmpc_tablet_acpi_driver = {
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,
801 unsigned long long *value)
805 unsigned long long output;
809 param.integer.value = 0xC0;
811 input.pointer = &
param;
819 unsigned long long value)
824 unsigned long long output;
827 param[0].integer.value = 0xC0;
831 input.pointer =
param;
842 handle = bl_get_data(bd);
843 status = cmpc_get_brightness(handle, &brightness);
855 handle = bl_get_data(bd);
856 status = cmpc_set_brightness(handle, bd->
props.brightness);
864 .get_brightness = cmpc_bl_get_brightness,
865 .update_status = cmpc_bl_update_status
873 unsigned long long *value)
877 unsigned long long output;
881 param.integer.value = 0xC1;
883 input.pointer = &
param;
891 unsigned long long value)
896 unsigned long long output;
899 param[0].integer.value = 0xC1;
903 input.pointer =
param;
912 unsigned long long state;
916 status = cmpc_get_rfkill_wlan(handle, &state);
918 blocked = state & 1 ?
false :
true;
923 static int cmpc_rfkill_block(
void *data,
bool blocked)
927 unsigned long long state;
931 status = cmpc_get_rfkill_wlan(handle, &state);
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);
945 static const struct rfkill_ops cmpc_rfkill_ops = {
946 .query = cmpc_rfkill_query,
947 .set_block = cmpc_rfkill_block,
959 static int cmpc_ipml_add(
struct acpi_device *acpi)
973 acpi->handle, &cmpc_bl_ops,
975 if (IS_ERR(ipml->bd)) {
976 retval = PTR_ERR(ipml->bd);
981 &cmpc_rfkill_ops, acpi->handle);
1003 static int cmpc_ipml_remove(
struct acpi_device *acpi,
int type)
1026 static struct acpi_driver cmpc_ipml_acpi_driver = {
1030 .ids = cmpc_ipml_device_ids,
1032 .add = cmpc_ipml_add,
1033 .remove = cmpc_ipml_remove
1041 static int cmpc_keys_codes[] = {
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];
1063 input_report_key(inputdev, code, !(event & 0x10));
1064 input_sync(inputdev);
1067 static void cmpc_keys_idev_init(
struct input_dev *inputdev)
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,
int type)
1084 return cmpc_remove_acpi_notify_device(acpi);
1092 static struct acpi_driver cmpc_keys_acpi_driver = {
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,
1109 static int cmpc_init(
void)
1131 goto failed_accel_v4;
1151 static void cmpc_exit(
void)