21 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 #include <linux/device.h>
24 #include <linux/hid.h>
25 #include <linux/module.h>
27 #include <linux/slab.h>
32 #define PAD_DEVICE_ID 0x0F
34 #define WAC_CMD_LED_CONTROL 0x20
35 #define WAC_CMD_ICON_START_STOP 0x21
36 #define WAC_CMD_ICON_TRANSFER 0x26
57 static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
59 static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 };
84 for (x = 0; x < 32; x++) {
85 for (y = 0; y < 8; y++)
86 buf[(8 * x) + (7 -
y)] = image[(8 * x) +
y];
92 for (x = 0; x < 4; x++) {
93 for (y = 0; y < 4; y++) {
94 for (z = 0; z < 8; z++) {
98 i = (x << 6) + (y << 4) + z;
101 for (w = 0; w < 8; w++) {
109 i = (x << 6) + (y << 4) + (z << 1);
111 image[i+1] = (0xFF00 &
r) >> 8;
117 static void wacom_set_image(
struct hid_device *hdev,
const char *image,
124 for (i = 0; i < 256; i++)
135 rep_data[1] = icon_no & 0x07;
139 for (i = 0; i < 4; i++) {
140 for (j = 0; j < 64; j++)
141 rep_data[j + 3] = p[(i << 6) +
j];
158 static void wacom_leds_set_brightness(
struct led_classdev *led_dev,
169 wdata = hid_get_drvdata(hdev);
170 for (i = 0; i < 4; ++
i) {
171 if (wdata->
leds[i] == led_dev)
194 struct device *dev = led_dev->
dev->parent;
200 for (i = 0; i < 4; ++
i) {
201 if (wdata->
leds[i] == led_dev) {
202 value = wdata->
leds[
i]->brightness;
211 static int wacom_initialize_leds(
struct hid_device *hdev)
213 struct wacom_data *wdata = hid_get_drvdata(hdev);
216 size_t namesz =
strlen(dev_name(dev)) + 12;
222 for (i = 0; i < 4; i++) {
226 "can't allocate memory for LED selector\n");
231 name = (
void *)&led[1];
232 snprintf(name, namesz,
"%s:selector:%d", dev_name(dev), i);
246 hid_warn(hdev,
"can't register LED\n");
255 static void wacom_destroy_leds(
struct hid_device *hdev)
257 struct wacom_data *wdata = hid_get_drvdata(hdev);
261 for (i = 0; i < 4; ++
i) {
262 if (wdata->
leds[i]) {
263 led = wdata->
leds[
i];
272 static int wacom_battery_get_property(
struct power_supply *psy,
297 static int wacom_ac_get_property(
struct power_supply *psy,
320 static void wacom_set_features(
struct hid_device *hdev,
u8 speed)
322 struct wacom_data *wdata = hid_get_drvdata(hdev);
328 rep_data[0] = 0x03 ; rep_data[1] = 0x00;
333 }
while (ret < 0 && limit-- > 0);
346 }
while (ret < 0 && limit-- > 0);
358 hid_warn(hdev,
"failed to poke device, command %d, err %d\n",
391 const char *buf,
size_t count)
396 if (
sscanf(buf,
"%1d", &new_speed ) != 1)
399 if (new_speed == 0 || new_speed == 1) {
400 wacom_set_features(hdev, new_speed);
407 wacom_show_speed, wacom_store_speed);
409 #define WACOM_STORE(OLED_ID) \
410 static ssize_t wacom_oled##OLED_ID##_store(struct device *dev, \
411 struct device_attribute *attr, \
412 const char *buf, size_t count) \
414 struct hid_device *hdev = container_of(dev, struct hid_device, \
420 wacom_set_image(hdev, buf, OLED_ID); \
425 static DEVICE_ATTR(oled##OLED_ID##_img, S_IWUSR | S_IWGRP, NULL, \
426 wacom_oled##OLED_ID##_store)
437 static int wacom_gr_parse_report(
struct hid_device *hdev,
439 struct input_dev *
input,
unsigned char *
data)
449 if (data[1] & 0x90) {
450 switch ((data[1] >> 5) & 3) {
466 if (!(data[1] & 0x10))
471 if (wdata->
tool != tool) {
475 input_report_key(input,
BTN_LEFT, 0);
486 input_report_key(input, wdata->
tool, 0);
491 input_report_key(input, tool, 1);
495 input_report_abs(input,
ABS_X, x);
496 input_report_abs(input,
ABS_Y, y);
498 switch ((data[1] >> 5) & 3) {
500 input_report_key(input,
BTN_MIDDLE, data[1] & 0x04);
501 rw = (data[6] & 0x01) ? -1 :
502 (data[6] & 0x02) ? 1 : 0;
507 input_report_key(input,
BTN_LEFT, data[1] & 0x01);
508 input_report_key(input,
BTN_RIGHT, data[1] & 0x02);
510 rw = 44 - (data[6] >> 2);
520 data[6] | (((
__u16) (data[1] & 0x08)) << 5));
521 input_report_key(input,
BTN_TOUCH, data[1] & 0x01);
522 input_report_key(input,
BTN_STYLUS, data[1] & 0x02);
535 input_report_key(input,
BTN_0, rw & 0x02);
536 input_report_key(input,
BTN_1, rw & 0x01);
543 rw = (data[7] >> 2 & 0x07);
555 static void wacom_i4_parse_button_report(
struct wacom_data *wdata,
556 struct input_dev *input,
unsigned char *data)
562 new_whlstate = data[1];
563 if (new_whlstate != wdata->
whlstate) {
565 if (new_whlstate & 0x80) {
567 input_report_abs(input,
ABS_WHEEL, (new_whlstate & 0x7f));
577 new_butstate = (data[3] << 1) | (data[2] & 0x01);
578 if (new_butstate != wdata->
butstate) {
580 input_report_key(input,
BTN_0, new_butstate & 0x001);
581 input_report_key(input,
BTN_1, new_butstate & 0x002);
582 input_report_key(input,
BTN_2, new_butstate & 0x004);
583 input_report_key(input,
BTN_3, new_butstate & 0x008);
584 input_report_key(input,
BTN_4, new_butstate & 0x010);
585 input_report_key(input,
BTN_5, new_butstate & 0x020);
586 input_report_key(input,
BTN_6, new_butstate & 0x040);
587 input_report_key(input,
BTN_7, new_butstate & 0x080);
588 input_report_key(input,
BTN_8, new_butstate & 0x100);
600 static void wacom_i4_parse_pen_report(
struct wacom_data *wdata,
601 struct input_dev *input,
unsigned char *data)
613 input_report_key(input, wdata->
tool, 0);
614 input_report_abs(input,
ABS_MISC, 0);
620 wdata->
id = ((data[2] << 4) | (data[3] >> 4) |
621 ((data[7] & 0x0f) << 20) |
622 ((data[8] & 0xf0) << 12));
623 wdata->
serial = ((data[3] & 0x0f) << 28) +
624 (data[4] << 20) + (data[5] << 12) +
625 (data[6] << 4) + (data[7] >> 4);
637 x = data[2] << 9 | data[3] << 1 | ((data[9] & 0x02) >> 1);
638 y = data[4] << 9 | data[5] << 1 | (data[9] & 0x01);
639 pressure = (data[6] << 3) | ((data[7] & 0xC0) >> 5)
641 distance = (data[9] >> 2) & 0x3f;
642 tilt_x = ((data[7] << 1) & 0x7e) | (data[8] >> 7);
643 tilt_y = data[8] & 0x7f;
645 input_report_key(input,
BTN_TOUCH, pressure > 1);
647 input_report_key(input,
BTN_STYLUS, data[1] & 0x02);
648 input_report_key(input,
BTN_STYLUS2, data[1] & 0x04);
649 input_report_key(input, wdata->
tool, 1);
650 input_report_abs(input,
ABS_X, x);
651 input_report_abs(input,
ABS_Y, y);
658 input_report_key(input, wdata->
tool, 1);
666 static void wacom_i4_parse_report(
struct hid_device *hdev,
668 struct input_dev *input,
unsigned char *data)
674 wacom_i4_parse_pen_report(wdata, input, data);
680 wacom_i4_parse_button_report(wdata, input, data);
683 hid_err(hdev,
"Unknown report: %d,%d\n", data[0], data[1]);
691 struct wacom_data *wdata = hid_get_drvdata(hdev);
693 struct input_dev *
input;
694 unsigned char *data = (
unsigned char *) raw_data;
702 input = hidinput->
input;
706 if (data[0] == 0x03) {
707 return wacom_gr_parse_report(hdev, wdata, input, data);
709 hid_err(hdev,
"Unknown report: %d,%d size:%d\n",
710 data[0], data[1], size);
719 wacom_i4_parse_report(hdev, wdata, input, data + i);
723 wacom_i4_parse_report(hdev, wdata, input, data + i);
725 wacom_i4_parse_report(hdev, wdata, input, data + i);
726 power_raw = data[i+10];
735 hid_err(hdev,
"Unknown report: %d,%d size:%d\n",
736 data[0], data[1], size);
747 struct input_dev *input = hi->
input;
777 input_set_abs_params(input,
ABS_X, 0, 16704, 4, 0);
778 input_set_abs_params(input,
ABS_Y, 0, 12064, 4, 0);
779 input_set_abs_params(input,
ABS_PRESSURE, 0, 511, 0, 0);
792 input_set_abs_params(input,
ABS_WHEEL, 0, 71, 0, 0);
793 input_set_abs_params(input,
ABS_X, 0, 40640, 4, 0);
794 input_set_abs_params(input,
ABS_Y, 0, 25400, 4, 0);
795 input_set_abs_params(input,
ABS_PRESSURE, 0, 2047, 0, 0);
797 input_set_abs_params(input,
ABS_TILT_X, 0, 127, 0, 0);
798 input_set_abs_params(input,
ABS_TILT_Y, 0, 127, 0, 0);
805 static int wacom_probe(
struct hid_device *hdev,
813 hid_err(hdev,
"can't alloc wacom descriptor\n");
817 hid_set_drvdata(hdev, wdata);
820 ret = hid_parse(hdev);
822 hid_err(hdev,
"parse failed\n");
828 hid_err(hdev,
"hw start failed\n");
835 "can't create sysfs speed attribute err: %d\n", ret);
837 #define OLED_INIT(OLED_ID) \
839 ret = device_create_file(&hdev->dev, \
840 &dev_attr_oled##OLED_ID##_img); \
843 "can't create sysfs oled attribute, err: %d\n", ret);\
856 wacom_set_features(hdev, 1);
860 ret = wacom_initialize_leds(hdev);
863 "can't create led attribute, err: %d\n", ret);
866 wdata->
battery.properties = wacom_battery_props;
868 wdata->
battery.get_property = wacom_battery_get_property;
869 wdata->
battery.name =
"wacom_battery";
871 wdata->
battery.use_for_apm = 0;
876 hid_err(hdev,
"can't create sysfs battery attribute, err: %d\n",
883 wdata->
ac.properties = wacom_ac_props;
885 wdata->
ac.get_property = wacom_ac_get_property;
886 wdata->
ac.name =
"wacom_ac";
888 wdata->
ac.use_for_apm = 0;
893 "can't create ac battery attribute, err: %d\n", ret);
903 wacom_destroy_leds(hdev);
919 static void wacom_remove(
struct hid_device *hdev)
921 struct wacom_data *wdata = hid_get_drvdata(hdev);
923 wacom_destroy_leds(hdev);
937 kfree(hid_get_drvdata(hdev));
950 .id_table = wacom_devices,
951 .probe = wacom_probe,
952 .remove = wacom_remove,
953 .raw_event = wacom_raw_event,
954 .input_mapped = wacom_input_mapped,
957 static int __init wacom_init(
void)
963 pr_err(
"can't register wacom driver\n");
967 static void __exit wacom_exit(
void)