diff mbox

[v3,4/7] Input - wacom: Check for bluetooth protocol while setting OLEDs

Message ID 1406659385-3256-5-git-send-email-benjamin.tissoires@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Benjamin Tissoires July 29, 2014, 6:43 p.m. UTC
Bluetooth Intuos 4 use 1-bit definition while the USB ones use a 4-bits
definition. This changes the size of the raw image we receive, and thus
the kernel will only accept 1-bit images for Bluetooth and 4-bits for
USB.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/hid/wacom_sys.c | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

Comments

Przemysław Firszt July 29, 2014, 10:53 p.m. UTC | #1
Dnia 2014-07-29, wto o godzinie 14:43 -0400, Benjamin Tissoires pisze:
> Bluetooth Intuos 4 use 1-bit definition while the USB ones use a 4-bits
> definition. This changes the size of the raw image we receive, and thus
> the kernel will only accept 1-bit images for Bluetooth and 4-bits for
> USB.
> 
> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
> ---
>  drivers/hid/wacom_sys.c | 29 +++++++++++++++++++++--------
>  1 file changed, 21 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
> index f5c9c56..a12cd9c 100644
> --- a/drivers/hid/wacom_sys.c
> +++ b/drivers/hid/wacom_sys.c
> @@ -20,6 +20,7 @@
>  #define WAC_CMD_LED_CONTROL	0x20
>  #define WAC_CMD_ICON_START	0x21
>  #define WAC_CMD_ICON_XFER	0x23
> +#define WAC_CMD_ICON_BT_XFER	0x26
>  #define WAC_CMD_RETRIES		10
>  
>  static int wacom_get_report(struct hid_device *hdev, u8 type, u8 id,
> @@ -526,12 +527,14 @@ static int wacom_led_control(struct wacom *wacom)
>  	return retval;
>  }
>  
> -static int wacom_led_putimage(struct wacom *wacom, int button_id, const void *img)
> +static int wacom_led_putimage(struct wacom *wacom, int button_id, u8 xfer_id,
> +		const unsigned len, const void *img)
>  {
>  	unsigned char *buf;
>  	int i, retval;
> +	const unsigned chunk_len = len / 4; /* 4 chunks are needed to be sent */
>  
> -	buf = kzalloc(259, GFP_KERNEL);
> +	buf = kzalloc(chunk_len + 3 , GFP_KERNEL);
>  	if (!buf)
>  		return -ENOMEM;
>  
> @@ -543,15 +546,15 @@ static int wacom_led_putimage(struct wacom *wacom, int button_id, const void *im
>  	if (retval < 0)
>  		goto out;
>  
> -	buf[0] = WAC_CMD_ICON_XFER;
> +	buf[0] = xfer_id;
>  	buf[1] = button_id & 0x07;
>  	for (i = 0; i < 4; i++) {
>  		buf[2] = i;
> -		memcpy(buf + 3, img + i * 256, 256);
> +		memcpy(buf + 3, img + i * chunk_len, chunk_len);
>  
>  		retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT,
> -					  WAC_CMD_ICON_XFER,
> -					  buf, 259, WAC_CMD_RETRIES);
> +					  xfer_id, buf, chunk_len + 3,
> +					  WAC_CMD_RETRIES);
>  		if (retval < 0)
>  			break;
>  	}
> @@ -652,13 +655,23 @@ static ssize_t wacom_button_image_store(struct device *dev, int button_id,
>  	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
>  	struct wacom *wacom = hid_get_drvdata(hdev);
>  	int err;
> +	unsigned len;
> +	u8 xfer_id;
>  
> -	if (count != 1024)
> +	if (hdev->bus == BUS_BLUETOOTH) {
> +		len = 256;
> +		xfer_id = WAC_CMD_ICON_BT_XFER;
> +	} else {
> +		len = 1024;
> +		xfer_id = WAC_CMD_ICON_XFER;
> +	}
> +
> +	if (count != len)
>  		return -EINVAL;
>  
>  	mutex_lock(&wacom->lock);
>  
> -	err = wacom_led_putimage(wacom, button_id, buf);
> +	err = wacom_led_putimage(wacom, button_id, xfer_id, len, buf);
>  
>  	mutex_unlock(&wacom->lock);

Signed-off-by: Przemo Firszt <przemo@firszt.eu>

I'll test the whole series tomorrow.
Ping Cheng July 31, 2014, 3:56 p.m. UTC | #2
On Tue, Jul 29, 2014 at 3:53 PM, Przemo Firszt <przemo@firszt.eu> wrote:
> Dnia 2014-07-29, wto o godzinie 14:43 -0400, Benjamin Tissoires pisze:
>> Bluetooth Intuos 4 use 1-bit definition while the USB ones use a 4-bits
>> definition. This changes the size of the raw image we receive, and thus
>> the kernel will only accept 1-bit images for Bluetooth and 4-bits for
>> USB.
>>
>> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
>> ---
>>  drivers/hid/wacom_sys.c | 29 +++++++++++++++++++++--------
>>  1 file changed, 21 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
>> index f5c9c56..a12cd9c 100644
>> --- a/drivers/hid/wacom_sys.c
>> +++ b/drivers/hid/wacom_sys.c
>> @@ -20,6 +20,7 @@
>>  #define WAC_CMD_LED_CONTROL  0x20
>>  #define WAC_CMD_ICON_START   0x21
>>  #define WAC_CMD_ICON_XFER    0x23
>> +#define WAC_CMD_ICON_BT_XFER 0x26
>>  #define WAC_CMD_RETRIES              10
>>
>>  static int wacom_get_report(struct hid_device *hdev, u8 type, u8 id,
>> @@ -526,12 +527,14 @@ static int wacom_led_control(struct wacom *wacom)
>>       return retval;
>>  }
>>
>> -static int wacom_led_putimage(struct wacom *wacom, int button_id, const void *img)
>> +static int wacom_led_putimage(struct wacom *wacom, int button_id, u8 xfer_id,
>> +             const unsigned len, const void *img)
>>  {
>>       unsigned char *buf;
>>       int i, retval;
>> +     const unsigned chunk_len = len / 4; /* 4 chunks are needed to be sent */
>>
>> -     buf = kzalloc(259, GFP_KERNEL);
>> +     buf = kzalloc(chunk_len + 3 , GFP_KERNEL);
>>       if (!buf)
>>               return -ENOMEM;
>>
>> @@ -543,15 +546,15 @@ static int wacom_led_putimage(struct wacom *wacom, int button_id, const void *im
>>       if (retval < 0)
>>               goto out;
>>
>> -     buf[0] = WAC_CMD_ICON_XFER;
>> +     buf[0] = xfer_id;
>>       buf[1] = button_id & 0x07;
>>       for (i = 0; i < 4; i++) {
>>               buf[2] = i;
>> -             memcpy(buf + 3, img + i * 256, 256);
>> +             memcpy(buf + 3, img + i * chunk_len, chunk_len);
>>
>>               retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT,
>> -                                       WAC_CMD_ICON_XFER,
>> -                                       buf, 259, WAC_CMD_RETRIES);
>> +                                       xfer_id, buf, chunk_len + 3,
>> +                                       WAC_CMD_RETRIES);
>>               if (retval < 0)
>>                       break;
>>       }
>> @@ -652,13 +655,23 @@ static ssize_t wacom_button_image_store(struct device *dev, int button_id,
>>       struct hid_device *hdev = container_of(dev, struct hid_device, dev);
>>       struct wacom *wacom = hid_get_drvdata(hdev);
>>       int err;
>> +     unsigned len;
>> +     u8 xfer_id;
>>
>> -     if (count != 1024)
>> +     if (hdev->bus == BUS_BLUETOOTH) {
>> +             len = 256;
>> +             xfer_id = WAC_CMD_ICON_BT_XFER;
>> +     } else {
>> +             len = 1024;
>> +             xfer_id = WAC_CMD_ICON_XFER;
>> +     }
>> +
>> +     if (count != len)
>>               return -EINVAL;
>>
>>       mutex_lock(&wacom->lock);
>>
>> -     err = wacom_led_putimage(wacom, button_id, buf);
>> +     err = wacom_led_putimage(wacom, button_id, xfer_id, len, buf);
>>
>>       mutex_unlock(&wacom->lock);
>
> Signed-off-by: Przemo Firszt <przemo@firszt.eu>

Reviewed-by: Ping Cheng <pingc@wacom.com>

> I'll test the whole series tomorrow.

I'd like to see Przemo's Tested-by tag here as well. Przemo, are you
done with your testing?

Thank you Przemo and Benjamin for your effort in making this
transition smooth and successful. We, at Wacom, are very grateful to
be part of this great community.

Cheers,

Ping
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Przemysław Firszt July 31, 2014, 9:14 p.m. UTC | #3
Dnia 2014-07-31, czw o godzinie 08:56 -0700, Ping Cheng pisze:
[..]
Hi Ping, 
> I'd like to see Przemo's Tested-by tag here as well. Przemo, are you
> done with your testing?

Whole series:
Tested-by: Przemo Firszt <przemo@firszt.eu>

Tested on two Intuos4 Wireless (usb + bt) tablets. Everything works as
expected. 

If someone wants to test icons scrambling in the userspace I added
option to i4oled (switch -B):

https://github.com/PrzemoF/i4oled/tree/v1.3

> Thank you Przemo and Benjamin for your effort in making this
> transition smooth and successful. We, at Wacom, are very grateful to
> be part of this great community.
Thanks! All credit goes to Benjamin :-)
diff mbox

Patch

diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index f5c9c56..a12cd9c 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -20,6 +20,7 @@ 
 #define WAC_CMD_LED_CONTROL	0x20
 #define WAC_CMD_ICON_START	0x21
 #define WAC_CMD_ICON_XFER	0x23
+#define WAC_CMD_ICON_BT_XFER	0x26
 #define WAC_CMD_RETRIES		10
 
 static int wacom_get_report(struct hid_device *hdev, u8 type, u8 id,
@@ -526,12 +527,14 @@  static int wacom_led_control(struct wacom *wacom)
 	return retval;
 }
 
-static int wacom_led_putimage(struct wacom *wacom, int button_id, const void *img)
+static int wacom_led_putimage(struct wacom *wacom, int button_id, u8 xfer_id,
+		const unsigned len, const void *img)
 {
 	unsigned char *buf;
 	int i, retval;
+	const unsigned chunk_len = len / 4; /* 4 chunks are needed to be sent */
 
-	buf = kzalloc(259, GFP_KERNEL);
+	buf = kzalloc(chunk_len + 3 , GFP_KERNEL);
 	if (!buf)
 		return -ENOMEM;
 
@@ -543,15 +546,15 @@  static int wacom_led_putimage(struct wacom *wacom, int button_id, const void *im
 	if (retval < 0)
 		goto out;
 
-	buf[0] = WAC_CMD_ICON_XFER;
+	buf[0] = xfer_id;
 	buf[1] = button_id & 0x07;
 	for (i = 0; i < 4; i++) {
 		buf[2] = i;
-		memcpy(buf + 3, img + i * 256, 256);
+		memcpy(buf + 3, img + i * chunk_len, chunk_len);
 
 		retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT,
-					  WAC_CMD_ICON_XFER,
-					  buf, 259, WAC_CMD_RETRIES);
+					  xfer_id, buf, chunk_len + 3,
+					  WAC_CMD_RETRIES);
 		if (retval < 0)
 			break;
 	}
@@ -652,13 +655,23 @@  static ssize_t wacom_button_image_store(struct device *dev, int button_id,
 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
 	struct wacom *wacom = hid_get_drvdata(hdev);
 	int err;
+	unsigned len;
+	u8 xfer_id;
 
-	if (count != 1024)
+	if (hdev->bus == BUS_BLUETOOTH) {
+		len = 256;
+		xfer_id = WAC_CMD_ICON_BT_XFER;
+	} else {
+		len = 1024;
+		xfer_id = WAC_CMD_ICON_XFER;
+	}
+
+	if (count != len)
 		return -EINVAL;
 
 	mutex_lock(&wacom->lock);
 
-	err = wacom_led_putimage(wacom, button_id, buf);
+	err = wacom_led_putimage(wacom, button_id, xfer_id, len, buf);
 
 	mutex_unlock(&wacom->lock);