From: Przemo Firszt <przemo@firszt.eu>
To: Bastien Nocera <hadess@hadess.net>,
linux-bluetooth <linux-bluetooth@vger.kernel.org>,
marcel <marcel@holtmann.org>, Jiri Kosina <jkosina@suse.cz>,
Peter Hutterer <peter.hutterer@who-t.net>
Cc: Ping <pinglinux@gmail.com>
Subject: [PATCH] Add sysfs battery & speed attributes for wacom bluetooth tablet
Date: Sun, 28 Feb 2010 20:39:13 +0000 [thread overview]
Message-ID: <1267389553.24791.22.camel@pldmachine> (raw)
[-- Attachment #1: Type: text/plain, Size: 826 bytes --]
Hi,
I need your opinion if reporting battery condition/changing reporting
speed of a bluetooth device through sysfs is an acceptable practice.
[PATCH] Add sysfs battery & speed attributes for wacom bluetooth tablet
The patch creates 2 sysfs attributes:
The battery attribute is read-only and it appears in:
/sys/bus/hid/devices/{btaddr}/battery
/sys/class/bluetooth/hci*:*/{btaddr}/battery
/sys/class/hidraw/hidraw*/device/battery
Capacity values are in %, zero value means AC plug is connected.
The speed attribute allows to poke reporting speed of wacom tablet.
This attribute is RW, valid values are: 5 for low speed, 6 is high
speed. High speed is the default value. Using low speed is
a workaround if you experience big delay between move of stylus on
the tablet and move of cursor on screen.
--
Kind regards,
Przemo
[-- Attachment #2: 0001-Add-sysfs-battery-speed-attributes-for-wacom-bluetoo.patch --]
[-- Type: text/x-patch, Size: 5240 bytes --]
>From d61bb3eb0fd8109c235ade904a8d7184fc96b68a Mon Sep 17 00:00:00 2001
From: Przemo Firszt <przemo@firszt.eu>
Date: Sat, 20 Feb 2010 12:58:41 +0000
Subject: [PATCH] Add sysfs battery & speed attributes for wacom bluetooth tablet
The patch creates 2 sysfs attributes:
The battery attribute is read-only and it appears in:
/sys/bus/hid/devices/{btaddr}/battery
/sys/class/bluetooth/hci*:*/{btaddr}/battery
/sys/class/hidraw/hidraw*/device/battery
Capacity values are in %, zero value means AC plug is connected.
The speed attribute allows to poke reporting speed of wacom tablet.
This attribute is RW, valid values are: 5 for low speed, 6 is high
speed. High speed is the default value. Using low speed is
a workaround if you experience big delay between move of stylus on
the tablet and move of cursor on screen.
Signed-off-by: Przemo Firszt <przemo@firszt.eu>
Acked-by: Ping Cheng <pingc@wacom.com>
---
drivers/hid/hid-wacom.c | 113 +++++++++++++++++++++++++++++++++++++----------
1 files changed, 89 insertions(+), 24 deletions(-)
diff --git a/drivers/hid/hid-wacom.c b/drivers/hid/hid-wacom.c
index 8d3b46f..ce2782c 100644
--- a/drivers/hid/hid-wacom.c
+++ b/drivers/hid/hid-wacom.c
@@ -24,11 +24,86 @@
#include "hid-ids.h"
+#define WACOM_SPEED_LO 0X05
+#define WACOM_SPEED_HI 0x06
+
struct wacom_data {
__u16 tool;
unsigned char butstate;
+ unsigned char battery;
};
+/* Battery capacity, 0 value means AC connected */
+static unsigned short batcap[8] = { 1, 15, 25, 35, 50, 70, 100, 0 };
+
+static void wacom_poke(struct hid_device *hdev, u8 data)
+{
+ struct wacom_data *wdata = hid_get_drvdata(hdev);
+ int limit;
+ int ret;
+ char rep_data[2];
+
+ /*
+ * Note that if the raw queries fail, it's not a hard failure and it
+ * is safe to continue
+ */
+ 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)
+ rep_data[0] = data ; 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) {
+ wdata->speed = data;
+ return;
+ }
+
+ dev_warn(&hdev->dev, "failed to poke device, command %d, err %d\n",
+ data, ret);
+}
+
+static ssize_t wacom_show_battery(struct device *dev, struct device_attribute
+ *attr, char *buf)
+{
+ struct wacom_data *wdata = dev_get_drvdata(dev);
+ return snprintf(buf, PAGE_SIZE, "%i\n", batcap[wdata->battery]);
+}
+
+static DEVICE_ATTR(battery, S_IRUGO, wacom_show_battery, NULL);
+
+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->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;
+
+ sscanf(buf, "%1d", &new_speed);
+ if (new_speed == WACOM_SPEED_HI || new_speed == WACOM_SPEED_LO) {
+ 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)
{
@@ -147,6 +222,11 @@ static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
input_sync(input);
}
+ /* Store current battery capacity */
+ rw = (data[7] >> 2 & 0x07);
+ if (rw != wdata->battery)
+ wdata->battery = rw;
+
return 1;
}
@@ -156,9 +236,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) {
@@ -181,30 +259,17 @@ 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
- */
+ ret = device_create_file(&hdev->dev, &dev_attr_battery);
+ if (ret)
+ dev_warn(&hdev->dev,
+ "can't create sysfs battery attribute err: %d\n", ret);
- /* 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);
+ 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);
- /* 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);
+ wacom_poke(hdev, WACOM_SPEED_HI);
hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
input = hidinput->input;
--
1.6.6.1
next reply other threads:[~2010-02-28 20:39 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-28 20:39 Przemo Firszt [this message]
2010-03-02 12:02 ` [PATCH] Add sysfs battery & speed attributes for wacom bluetooth tablet Bastien Nocera
2010-03-02 12:11 ` Bastien Nocera
2010-03-09 19:12 ` [PATCH] Expose wacom pen tablet battery and ac thru power_supply class Przemo Firszt
2010-03-09 19:25 ` Przemo Firszt
2010-03-09 21:22 ` Jiri Kosina
2010-03-10 19:03 ` Przemo Firszt
2010-03-15 13:54 ` Jiri Kosina
2010-03-15 22:00 ` Przemo Firszt
2010-03-16 10:49 ` Jiri Kosina
2010-03-16 14:09 ` Przemo Firszt
2010-03-08 11:07 ` [PATCH] Add sysfs battery & speed attributes for wacom bluetooth tablet Jiri Kosina
2010-03-08 20:04 ` Przemo Firszt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1267389553.24791.22.camel@pldmachine \
--to=przemo@firszt.eu \
--cc=hadess@hadess.net \
--cc=jkosina@suse.cz \
--cc=linux-bluetooth@vger.kernel.org \
--cc=marcel@holtmann.org \
--cc=peter.hutterer@who-t.net \
--cc=pinglinux@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.