From 59d2334ac9f4255f5f8f3e4e1bf41653e0bba99e Mon Sep 17 00:00:00 2001 From: Przemo Firszt Date: Mon, 15 Mar 2010 19:16:23 +0000 Subject: HID: expose wacom pen tablet battery through power_supply class This patch exposes wacom pen tablet battery capacity and ac state thru power_supply class is sysfs. Signed-off-by: Przemo Firszt Signed-off-by: Jiri Kosina --- drivers/hid/hid-wacom.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) (limited to 'drivers/hid/hid-wacom.c') diff --git a/drivers/hid/hid-wacom.c b/drivers/hid/hid-wacom.c index 8d3b46f5d149..4d2d2a2e1a5f 100644 --- a/drivers/hid/hid-wacom.c +++ b/drivers/hid/hid-wacom.c @@ -21,14 +21,88 @@ #include #include #include +#ifdef CONFIG_HID_WACOM_POWER_SUPPLY +#include +#endif #include "hid-ids.h" struct wacom_data { __u16 tool; unsigned char butstate; +#ifdef CONFIG_HID_WACOM_POWER_SUPPLY + int battery_capacity; + struct power_supply battery; + struct power_supply ac; +#endif }; +#ifdef CONFIG_HID_WACOM_POWER_SUPPLY +/*percent of battery capacity, 0 means AC online*/ +static unsigned short batcap[8] = { 1, 15, 25, 35, 50, 70, 100, 0 }; + +static enum power_supply_property wacom_battery_props[] = { + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_CAPACITY +}; + +static enum power_supply_property wacom_ac_props[] = { + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_ONLINE +}; + +static int wacom_battery_get_property(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + struct wacom_data *wdata = container_of(psy, + struct wacom_data, battery); + int power_state = batcap[wdata->battery_capacity]; + int ret = 0; + + switch (psp) { + case POWER_SUPPLY_PROP_PRESENT: + val->intval = 1; + break; + case POWER_SUPPLY_PROP_CAPACITY: + /* show 100% battery capacity when charging */ + if (power_state == 0) + val->intval = 100; + else + val->intval = power_state; + break; + default: + ret = -EINVAL; + break; + } + return ret; +} + +static int wacom_ac_get_property(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + struct wacom_data *wdata = container_of(psy, struct wacom_data, ac); + int power_state = batcap[wdata->battery_capacity]; + int ret = 0; + + switch (psp) { + case POWER_SUPPLY_PROP_PRESENT: + /* fall through */ + case POWER_SUPPLY_PROP_ONLINE: + if (power_state == 0) + val->intval = 1; + else + val->intval = 0; + break; + default: + ret = -EINVAL; + break; + } + return ret; +} +#endif + static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report, u8 *raw_data, int size) { @@ -147,6 +221,12 @@ static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report, input_sync(input); } +#ifdef CONFIG_HID_WACOM_POWER_SUPPLY + /* Store current battery capacity */ + rw = (data[7] >> 2 & 0x07); + if (rw != wdata->battery_capacity) + wdata->battery_capacity = rw; +#endif return 1; } @@ -206,6 +286,45 @@ static int wacom_probe(struct hid_device *hdev, if (ret < 0) dev_warn(&hdev->dev, "failed to poke device #2, %d\n", ret); +#ifdef CONFIG_HID_WACOM_POWER_SUPPLY + wdata->battery.properties = wacom_battery_props; + wdata->battery.num_properties = ARRAY_SIZE(wacom_battery_props); + wdata->battery.get_property = wacom_battery_get_property; + wdata->battery.name = "wacom_battery"; + wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY; + wdata->battery.use_for_apm = 0; + + ret = power_supply_register(&hdev->dev, &wdata->battery); + if (ret) { + dev_warn(&hdev->dev, + "can't create sysfs battery attribute, err: %d\n", ret); + /* + * battery attribute is not critical for the tablet, but if it + * failed then there is no need to create ac attribute + */ + goto move_on; + } + + wdata->ac.properties = wacom_ac_props; + wdata->ac.num_properties = ARRAY_SIZE(wacom_ac_props); + wdata->ac.get_property = wacom_ac_get_property; + wdata->ac.name = "wacom_ac"; + wdata->ac.type = POWER_SUPPLY_TYPE_MAINS; + wdata->ac.use_for_apm = 0; + + ret = power_supply_register(&hdev->dev, &wdata->ac); + if (ret) { + dev_warn(&hdev->dev, + "can't create ac battery attribute, err: %d\n", ret); + /* + * ac attribute is not critical for the tablet, but if it + * failed then we don't want to battery attribute to exist + */ + power_supply_unregister(&wdata->battery); + } + +move_on: +#endif hidinput = list_entry(hdev->inputs.next, struct hid_input, list); input = hidinput->input; @@ -250,7 +369,15 @@ err_free: static void wacom_remove(struct hid_device *hdev) { +#ifdef CONFIG_HID_WACOM_POWER_SUPPLY + struct wacom_data *wdata = hid_get_drvdata(hdev); +#endif hid_hw_stop(hdev); + +#ifdef CONFIG_HID_WACOM_POWER_SUPPLY + power_supply_unregister(&wdata->battery); + power_supply_unregister(&wdata->ac); +#endif kfree(hid_get_drvdata(hdev)); } -- cgit v1.2.3-59-g8ed1b From 06c7c313b5605471e321337c770683cf70464197 Mon Sep 17 00:00:00 2001 From: Przemo Firszt Date: Mon, 22 Mar 2010 09:55:04 +0100 Subject: HID: separate mode switching function for wacom bluetooth driver wacom_poke function allows to switch tablet reporting speed. The patch dosen't add any new functionality, but it's preparation for user-space speed switching through sysfs. Signed-off-by: Przemo Firszt Signed-off-by: Bastien Nocera Signed-off-by: Jiri Kosina --- drivers/hid/hid-wacom.c | 66 ++++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 26 deletions(-) (limited to 'drivers/hid/hid-wacom.c') diff --git a/drivers/hid/hid-wacom.c b/drivers/hid/hid-wacom.c index 4d2d2a2e1a5f..f9d493931b02 100644 --- a/drivers/hid/hid-wacom.c +++ b/drivers/hid/hid-wacom.c @@ -103,6 +103,44 @@ static int wacom_ac_get_property(struct power_supply *psy, } #endif +static void wacom_poke(struct hid_device *hdev, u8 speed) +{ + int limit, ret; + char rep_data[2]; + + rep_data[0] = 0x03 ; rep_data[1] = 0x00; + limit = 3; + do { + ret = hdev->hid_output_raw_report(hdev, rep_data, 2, + HID_FEATURE_REPORT); + } while (ret < 0 && limit-- > 0); + + if (ret >= 0) { + if (speed == 0) + rep_data[0] = 0x05; + else + rep_data[0] = 0x06; + + rep_data[1] = 0x00; + limit = 3; + do { + ret = hdev->hid_output_raw_report(hdev, rep_data, 2, + HID_FEATURE_REPORT); + } while (ret < 0 && limit-- > 0); + + if (ret >= 0) + return; + } + + /* + * Note that if the raw queries fail, it's not a hard failure and it + * is safe to continue + */ + dev_warn(&hdev->dev, "failed to poke device, command %d, err %d\n", + rep_data[0], ret); + return; +} + static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report, u8 *raw_data, int size) { @@ -236,9 +274,7 @@ static int wacom_probe(struct hid_device *hdev, struct hid_input *hidinput; struct input_dev *input; struct wacom_data *wdata; - char rep_data[2]; int ret; - int limit; wdata = kzalloc(sizeof(*wdata), GFP_KERNEL); if (wdata == NULL) { @@ -261,30 +297,8 @@ static int wacom_probe(struct hid_device *hdev, goto err_free; } - /* - * Note that if the raw queries fail, it's not a hard failure and it - * is safe to continue - */ - - /* Set Wacom mode2 */ - rep_data[0] = 0x03; rep_data[1] = 0x00; - limit = 3; - do { - ret = hdev->hid_output_raw_report(hdev, rep_data, 2, - HID_FEATURE_REPORT); - } while (ret < 0 && limit-- > 0); - if (ret < 0) - dev_warn(&hdev->dev, "failed to poke device #1, %d\n", ret); - - /* 0x06 - high reporting speed, 0x05 - low speed */ - rep_data[0] = 0x06; rep_data[1] = 0x00; - limit = 3; - do { - ret = hdev->hid_output_raw_report(hdev, rep_data, 2, - HID_FEATURE_REPORT); - } while (ret < 0 && limit-- > 0); - if (ret < 0) - dev_warn(&hdev->dev, "failed to poke device #2, %d\n", ret); + /* Set Wacom mode 2 with high reporting speed */ + wacom_poke(hdev, 1); #ifdef CONFIG_HID_WACOM_POWER_SUPPLY wdata->battery.properties = wacom_battery_props; -- cgit v1.2.3-59-g8ed1b From 20a3ce7e490c5015d051f78414f6dd146eec283f Mon Sep 17 00:00:00 2001 From: Przemo Firszt Date: Thu, 18 Mar 2010 14:34:34 +0000 Subject: HID: add sysfs speed attribute for wacom bluetooth tablet The attribute allows to change reporting speed of tablet from userspace through sysfs file. The attribute is RW, valid values: 0 is low speed, 1 is high speed. High speed is the default setting. Using low speed is a workaround if you experience lag when using the tablet. Signed-off-by: Przemo Firszt Signed-off-by: Jiri Kosina --- drivers/hid/hid-wacom.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'drivers/hid/hid-wacom.c') diff --git a/drivers/hid/hid-wacom.c b/drivers/hid/hid-wacom.c index f9d493931b02..97ef6260fda0 100644 --- a/drivers/hid/hid-wacom.c +++ b/drivers/hid/hid-wacom.c @@ -30,6 +30,7 @@ struct wacom_data { __u16 tool; unsigned char butstate; + unsigned char high_speed; #ifdef CONFIG_HID_WACOM_POWER_SUPPLY int battery_capacity; struct power_supply battery; @@ -105,6 +106,7 @@ static int wacom_ac_get_property(struct power_supply *psy, static void wacom_poke(struct hid_device *hdev, u8 speed) { + struct wacom_data *wdata = hid_get_drvdata(hdev); int limit, ret; char rep_data[2]; @@ -128,8 +130,10 @@ static void wacom_poke(struct hid_device *hdev, u8 speed) HID_FEATURE_REPORT); } while (ret < 0 && limit-- > 0); - if (ret >= 0) + if (ret >= 0) { + wdata->high_speed = speed; return; + } } /* @@ -141,6 +145,35 @@ static void wacom_poke(struct hid_device *hdev, u8 speed) return; } +static ssize_t wacom_show_speed(struct device *dev, + struct device_attribute + *attr, char *buf) +{ + struct wacom_data *wdata = dev_get_drvdata(dev); + + return snprintf(buf, PAGE_SIZE, "%i\n", wdata->high_speed); +} + +static ssize_t wacom_store_speed(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct hid_device *hdev = container_of(dev, struct hid_device, dev); + int new_speed; + + if (sscanf(buf, "%1d", &new_speed ) != 1) + return -EINVAL; + + if (new_speed == 0 || new_speed == 1) { + wacom_poke(hdev, new_speed); + return strnlen(buf, PAGE_SIZE); + } else + return -EINVAL; +} + +static DEVICE_ATTR(speed, S_IRUGO | S_IWUGO, + wacom_show_speed, wacom_store_speed); + static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report, u8 *raw_data, int size) { @@ -297,6 +330,11 @@ static int wacom_probe(struct hid_device *hdev, goto err_free; } + ret = device_create_file(&hdev->dev, &dev_attr_speed); + if (ret) + dev_warn(&hdev->dev, + "can't create sysfs speed attribute err: %d\n", ret); + /* Set Wacom mode 2 with high reporting speed */ wacom_poke(hdev, 1); -- cgit v1.2.3-59-g8ed1b From ed9eac5b493c679ef5fc52273758fe334de82714 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 21 Apr 2010 14:52:00 +0100 Subject: HID: add support for the Wacom Intuos 4 wireless Same command set as the Graphire Bluetooth tablet. Signed-off-by: Bastien Nocera Signed-off-by: Jiri Kosina --- drivers/hid/hid-ids.h | 1 + drivers/hid/hid-wacom.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/hid/hid-wacom.c') diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index e1b4ce4eeb6e..0786bbdafb4a 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h @@ -456,6 +456,7 @@ #define USB_VENDOR_ID_WACOM 0x056a #define USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH 0x81 +#define USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH 0xbd #define USB_VENDOR_ID_WISEGROUP 0x0925 #define USB_DEVICE_ID_SMARTJOY_PLUS 0x0005 diff --git a/drivers/hid/hid-wacom.c b/drivers/hid/hid-wacom.c index 97ef6260fda0..51d7d77eb43b 100644 --- a/drivers/hid/hid-wacom.c +++ b/drivers/hid/hid-wacom.c @@ -435,7 +435,7 @@ static void wacom_remove(struct hid_device *hdev) static const struct hid_device_id wacom_devices[] = { { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) }, - + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) }, { } }; MODULE_DEVICE_TABLE(hid, wacom_devices); -- cgit v1.2.3-59-g8ed1b