/*
* Bluetooth Wacom Tablet support
*
* Copyright (c) 1999 Andreas Gal
* Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
* Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
* Copyright (c) 2006-2007 Jiri Kosina
* Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com>
* Copyright (c) 2006 Andrew Zabolotny <zap@homelink.ru>
* Copyright (c) 2009 Bastien Nocera <hadess@hadess.net>
* Copyright (c) 2011 Przemysław Firszt <przemo@firszt.eu>
*/
/*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/device.h>
#include <linux/hid.h>
#include <linux/module.h>
#include <linux/leds.h>
#include <linux/slab.h>
#include <linux/power_supply.h>
#include "hid-ids.h"
#define PAD_DEVICE_ID 0x0F
#define WAC_CMD_LED_CONTROL 0x20
#define WAC_CMD_ICON_START_STOP 0x21
#define WAC_CMD_ICON_TRANSFER 0x26
struct wacom_data {
__u16 tool;
__u16 butstate;
__u8 whlstate;
__u8 features;
__u32 id;
__u32 serial;
unsigned char high_speed;
__u8 battery_capacity;
__u8 power_raw;
__u8 ps_connected;
struct power_supply battery;
struct power_supply ac;
__u8 led_selector;
struct led_classdev *leds[4];
};
/*percent of battery capacity for Graphire
8th value means AC online and show 100% capacity */
static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
/*percent of battery capacity for Intuos4 WL, AC has a separate bit*/
static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 };
static enum power_supply_property wacom_battery_props[] = {
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_CAPACITY,
POWER_SUPPLY_PROP_SCOPE,
};
static enum power_supply_property wacom_ac_props[] = {
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_ONLINE,
POWER_SUPPLY_PROP_SCOPE,
};
static void wacom_scramble(__u8 *image)
{
__u16 mask;
__u16 s1;
__u16 s2;
__u16 r1 ;
__u16 r2 ;
__u16 r;
__u8 buf[256];
int i, w, x, y, z;
for (x = 0; x < 32; x++) {
for (y = 0; y < 8; y++)
buf[(8 * x) + (7 - y)] = image[(8 * x) + y];
}
/* Change 76543210 into GECA6420 as required by Intuos4 WL
* HGFEDCBA HFDB7531
*/
for (x = 0; x < 4; x++) {
for (y = 0; y < 4; y++) {
for (z = 0; z < 8; z++) {
mask = 0x0001;
r1 = 0;
r2 = 0;
i = (x << 6) + (y << 4) + z;
s1 = buf[i];
s2 = buf[i+8];
for (w = 0; w < 8; w++) {
r1 |= (s1 & mask);
r2 |= (s2 & mask);
s1 <<= 1;
s2 <<= 1;
mask <<= 2;
}
r = r1 | (r2 << 1);
i = (x << 6) + (y << 4) + (z << 1);
image[i] = 0xFF & r;
image[i+1] = (0xFF00 & r) >> 8;
}
}
}
}
static void wacom_set_image(struct hid_device *hdev, const char *image,
__u8 icon_no)
{
__u8 rep_data[68];
__u8 p[256];
int ret, i, j;
for (i = 0; i < 256; i++)
p[i] = image[i];
rep_data[0] = WAC_CMD_ICON_START_STOP;
rep_data[1] = 0;
ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
HID_FEATURE_REPORT);
if (ret < 0)
goto err;
rep_data[0] = WAC_CMD_ICON_TRANSFER;
rep_data[1] = icon_no & 0x07;
wacom_scramble(p);
for (i = 0; i <