Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * drivers/input/tablet/wacom.h
0004  *
0005  *  USB Wacom tablet support
0006  *
0007  *  Copyright (c) 2000-2004 Vojtech Pavlik  <vojtech@ucw.cz>
0008  *  Copyright (c) 2000 Andreas Bach Aaen    <abach@stofanet.dk>
0009  *  Copyright (c) 2000 Clifford Wolf        <clifford@clifford.at>
0010  *  Copyright (c) 2000 Sam Mosel        <sam.mosel@computer.org>
0011  *  Copyright (c) 2000 James E. Blair       <corvus@gnu.org>
0012  *  Copyright (c) 2000 Daniel Egger     <egger@suse.de>
0013  *  Copyright (c) 2001 Frederic Lepied      <flepied@mandrakesoft.com>
0014  *  Copyright (c) 2004 Panagiotis Issaris   <panagiotis.issaris@mech.kuleuven.ac.be>
0015  *  Copyright (c) 2002-2011 Ping Cheng      <pingc@wacom.com>
0016  *  Copyright (c) 2014 Benjamin Tissoires   <benjamin.tissoires@redhat.com>
0017  *
0018  *  ChangeLog:
0019  *      v0.1 (vp)  - Initial release
0020  *      v0.2 (aba) - Support for all buttons / combinations
0021  *      v0.3 (vp)  - Support for Intuos added
0022  *  v0.4 (sm)  - Support for more Intuos models, menustrip
0023  *          relative mode, proximity.
0024  *  v0.5 (vp)  - Big cleanup, nifty features removed,
0025  *          they belong in userspace
0026  *  v1.8 (vp)  - Submit URB only when operating, moved to CVS,
0027  *          use input_report_key instead of report_btn and
0028  *          other cleanups
0029  *  v1.11 (vp) - Add URB ->dev setting for new kernels
0030  *  v1.11 (jb) - Add support for the 4D Mouse & Lens
0031  *  v1.12 (de) - Add support for two more inking pen IDs
0032  *  v1.14 (vp) - Use new USB device id probing scheme.
0033  *           Fix Wacom Graphire mouse wheel
0034  *  v1.18 (vp) - Fix mouse wheel direction
0035  *           Make mouse relative
0036  *      v1.20 (fl) - Report tool id for Intuos devices
0037  *                 - Multi tools support
0038  *                 - Corrected Intuos protocol decoding (airbrush, 4D mouse, lens cursor...)
0039  *                 - Add PL models support
0040  *         - Fix Wacom Graphire mouse wheel again
0041  *  v1.21 (vp) - Removed protocol descriptions
0042  *         - Added MISC_SERIAL for tool serial numbers
0043  *        (gb) - Identify version on module load.
0044  *    v1.21.1 (fl) - added Graphire2 support
0045  *    v1.21.2 (fl) - added Intuos2 support
0046  *                 - added all the PL ids
0047  *    v1.21.3 (fl) - added another eraser id from Neil Okamoto
0048  *                 - added smooth filter for Graphire from Peri Hankey
0049  *                 - added PenPartner support from Olaf van Es
0050  *                 - new tool ids from Ole Martin Bjoerndalen
0051  *  v1.29 (pc) - Add support for more tablets
0052  *         - Fix pressure reporting
0053  *  v1.30 (vp) - Merge 2.4 and 2.5 drivers
0054  *         - Since 2.5 now has input_sync(), remove MSC_SERIAL abuse
0055  *         - Cleanups here and there
0056  *    v1.30.1 (pi) - Added Graphire3 support
0057  *  v1.40 (pc) - Add support for several new devices, fix eraser reporting, ...
0058  *  v1.43 (pc) - Added support for Cintiq 21UX
0059  *         - Fixed a Graphire bug
0060  *         - Merged wacom_intuos3_irq into wacom_intuos_irq
0061  *  v1.44 (pc) - Added support for Graphire4, Cintiq 710, Intuos3 6x11, etc.
0062  *         - Report Device IDs
0063  *      v1.45 (pc) - Added support for DTF 521, Intuos3 12x12 and 12x19
0064  *                 - Minor data report fix
0065  *      v1.46 (pc) - Split wacom.c into wacom_sys.c and wacom_wac.c,
0066  *         - where wacom_sys.c deals with system specific code,
0067  *         - and wacom_wac.c deals with Wacom specific code
0068  *         - Support Intuos3 4x6
0069  *      v1.47 (pc) - Added support for Bamboo
0070  *      v1.48 (pc) - Added support for Bamboo1, BambooFun, and Cintiq 12WX
0071  *      v1.49 (pc) - Added support for USB Tablet PC (0x90, 0x93, and 0x9A)
0072  *      v1.50 (pc) - Fixed a TabletPC touch bug in 2.6.28
0073  *      v1.51 (pc) - Added support for Intuos4
0074  *      v1.52 (pc) - Query Wacom data upon system resume
0075  *                 - add defines for features->type
0076  *                 - add new devices (0x9F, 0xE2, and 0XE3)
0077  *      v2.00 (bt) - conversion to a HID driver
0078  *                 - integration of the Bluetooth devices
0079  */
0080 
0081 /*
0082  */
0083 #ifndef WACOM_H
0084 #define WACOM_H
0085 #include <linux/kernel.h>
0086 #include <linux/slab.h>
0087 #include <linux/module.h>
0088 #include <linux/mod_devicetable.h>
0089 #include <linux/hid.h>
0090 #include <linux/kfifo.h>
0091 #include <linux/leds.h>
0092 #include <linux/usb/input.h>
0093 #include <linux/power_supply.h>
0094 #include <linux/timer.h>
0095 #include <asm/unaligned.h>
0096 
0097 /*
0098  * Version Information
0099  */
0100 #define DRIVER_VERSION "v2.00"
0101 #define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
0102 #define DRIVER_DESC "USB Wacom tablet driver"
0103 
0104 #define USB_VENDOR_ID_WACOM 0x056a
0105 #define USB_VENDOR_ID_LENOVO    0x17ef
0106 
0107 enum wacom_worker {
0108     WACOM_WORKER_WIRELESS,
0109     WACOM_WORKER_BATTERY,
0110     WACOM_WORKER_REMOTE,
0111     WACOM_WORKER_MODE_CHANGE,
0112 };
0113 
0114 struct wacom;
0115 
0116 struct wacom_led {
0117     struct led_classdev cdev;
0118     struct led_trigger trigger;
0119     struct wacom *wacom;
0120     unsigned int group;
0121     unsigned int id;
0122     u8 llv;
0123     u8 hlv;
0124     bool held;
0125 };
0126 
0127 struct wacom_group_leds {
0128     u8 select; /* status led selector (0..3) */
0129     struct wacom_led *leds;
0130     unsigned int count;
0131     struct device *dev;
0132 };
0133 
0134 struct wacom_battery {
0135     struct wacom *wacom;
0136     struct power_supply_desc bat_desc;
0137     struct power_supply *battery;
0138     char bat_name[WACOM_NAME_MAX];
0139     int bat_status;
0140     int battery_capacity;
0141     int bat_charging;
0142     int bat_connected;
0143     int ps_connected;
0144 };
0145 
0146 struct wacom_remote {
0147     spinlock_t remote_lock;
0148     struct kfifo remote_fifo;
0149     struct kobject *remote_dir;
0150     struct {
0151         struct attribute_group group;
0152         u32 serial;
0153         struct input_dev *input;
0154         bool registered;
0155         struct wacom_battery battery;
0156     } remotes[WACOM_MAX_REMOTES];
0157 };
0158 
0159 struct wacom {
0160     struct usb_device *usbdev;
0161     struct usb_interface *intf;
0162     struct wacom_wac wacom_wac;
0163     struct hid_device *hdev;
0164     struct mutex lock;
0165     struct work_struct wireless_work;
0166     struct work_struct battery_work;
0167     struct work_struct remote_work;
0168     struct delayed_work init_work;
0169     struct wacom_remote *remote;
0170     struct work_struct mode_change_work;
0171     struct timer_list idleprox_timer;
0172     bool generic_has_leds;
0173     struct wacom_leds {
0174         struct wacom_group_leds *groups;
0175         unsigned int count;
0176         u8 llv;       /* status led brightness no button (1..127) */
0177         u8 hlv;       /* status led brightness button pressed (1..127) */
0178         u8 img_lum;   /* OLED matrix display brightness */
0179         u8 max_llv;   /* maximum brightness of LED (llv) */
0180         u8 max_hlv;   /* maximum brightness of LED (hlv) */
0181     } led;
0182     struct wacom_battery battery;
0183     bool resources;
0184 };
0185 
0186 static inline void wacom_schedule_work(struct wacom_wac *wacom_wac,
0187                        enum wacom_worker which)
0188 {
0189     struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
0190 
0191     switch (which) {
0192     case WACOM_WORKER_WIRELESS:
0193         schedule_work(&wacom->wireless_work);
0194         break;
0195     case WACOM_WORKER_BATTERY:
0196         schedule_work(&wacom->battery_work);
0197         break;
0198     case WACOM_WORKER_REMOTE:
0199         schedule_work(&wacom->remote_work);
0200         break;
0201     case WACOM_WORKER_MODE_CHANGE:
0202         schedule_work(&wacom->mode_change_work);
0203         break;
0204     }
0205 }
0206 
0207 /*
0208  * Convert a signed 32-bit integer to an unsigned n-bit integer. Undoes
0209  * the normally-helpful work of 'hid_snto32' for fields that use signed
0210  * ranges for questionable reasons.
0211  */
0212 static inline __u32 wacom_s32tou(s32 value, __u8 n)
0213 {
0214     switch (n) {
0215     case 8:  return ((__u8)value);
0216     case 16: return ((__u16)value);
0217     case 32: return ((__u32)value);
0218     }
0219     return value & (1 << (n - 1)) ? value & (~(~0U << n)) : value;
0220 }
0221 
0222 extern const struct hid_device_id wacom_ids[];
0223 
0224 void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len);
0225 void wacom_setup_device_quirks(struct wacom *wacom);
0226 int wacom_setup_pen_input_capabilities(struct input_dev *input_dev,
0227                    struct wacom_wac *wacom_wac);
0228 int wacom_setup_touch_input_capabilities(struct input_dev *input_dev,
0229                    struct wacom_wac *wacom_wac);
0230 int wacom_setup_pad_input_capabilities(struct input_dev *input_dev,
0231                        struct wacom_wac *wacom_wac);
0232 void wacom_wac_usage_mapping(struct hid_device *hdev,
0233         struct hid_field *field, struct hid_usage *usage);
0234 void wacom_wac_event(struct hid_device *hdev, struct hid_field *field,
0235         struct hid_usage *usage, __s32 value);
0236 void wacom_wac_report(struct hid_device *hdev, struct hid_report *report);
0237 void wacom_battery_work(struct work_struct *work);
0238 enum led_brightness wacom_leds_brightness_get(struct wacom_led *led);
0239 struct wacom_led *wacom_led_find(struct wacom *wacom, unsigned int group,
0240                  unsigned int id);
0241 struct wacom_led *wacom_led_next(struct wacom *wacom, struct wacom_led *cur);
0242 int wacom_equivalent_usage(int usage);
0243 int wacom_initialize_leds(struct wacom *wacom);
0244 void wacom_idleprox_timeout(struct timer_list *list);
0245 #endif