35 #include <linux/kernel.h>
36 #include <linux/errno.h>
38 #include <linux/slab.h>
39 #include <linux/module.h>
41 #include <linux/hid.h>
45 #define USB_VENDOR_ID_APPLE 0x05ac
48 #define USB_DEVICE_ID_APPLE_WELLSPRING_ANSI 0x0223
49 #define USB_DEVICE_ID_APPLE_WELLSPRING_ISO 0x0224
50 #define USB_DEVICE_ID_APPLE_WELLSPRING_JIS 0x0225
52 #define USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI 0x0230
53 #define USB_DEVICE_ID_APPLE_WELLSPRING2_ISO 0x0231
54 #define USB_DEVICE_ID_APPLE_WELLSPRING2_JIS 0x0232
56 #define USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI 0x0236
57 #define USB_DEVICE_ID_APPLE_WELLSPRING3_ISO 0x0237
58 #define USB_DEVICE_ID_APPLE_WELLSPRING3_JIS 0x0238
60 #define USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI 0x023f
61 #define USB_DEVICE_ID_APPLE_WELLSPRING4_ISO 0x0240
62 #define USB_DEVICE_ID_APPLE_WELLSPRING4_JIS 0x0241
64 #define USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI 0x0242
65 #define USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO 0x0243
66 #define USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS 0x0244
68 #define USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI 0x0245
69 #define USB_DEVICE_ID_APPLE_WELLSPRING5_ISO 0x0246
70 #define USB_DEVICE_ID_APPLE_WELLSPRING5_JIS 0x0247
72 #define USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI 0x0249
73 #define USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO 0x024a
74 #define USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS 0x024b
76 #define USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI 0x024c
77 #define USB_DEVICE_ID_APPLE_WELLSPRING6_ISO 0x024d
78 #define USB_DEVICE_ID_APPLE_WELLSPRING6_JIS 0x024e
80 #define USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI 0x0252
81 #define USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO 0x0253
82 #define USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS 0x0254
84 #define USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI 0x0262
85 #define USB_DEVICE_ID_APPLE_WELLSPRING7_ISO 0x0263
86 #define USB_DEVICE_ID_APPLE_WELLSPRING7_JIS 0x0264
88 #define USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI 0x0259
89 #define USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO 0x025a
90 #define USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS 0x025b
92 #define BCM5974_DEVICE(prod) { \
93 .match_flags = (USB_DEVICE_ID_MATCH_DEVICE | \
94 USB_DEVICE_ID_MATCH_INT_CLASS | \
95 USB_DEVICE_ID_MATCH_INT_PROTOCOL), \
96 .idVendor = USB_VENDOR_ID_APPLE, \
97 .idProduct = (prod), \
98 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
99 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE \
157 #define dprintk(level, format, a...)\
158 { if (debug >= level) printk(KERN_DEBUG format, ##a); }
160 static int debug = 1;
179 #define FINGER_TYPE1 (13 * sizeof(__le16))
180 #define FINGER_TYPE2 (15 * sizeof(__le16))
183 #define BUTTON_TYPE2 15
186 #define HAS_INTEGRATED_BUTTON 1
205 #define MAX_FINGERS 16
206 #define SIZEOF_FINGER sizeof(struct tp_finger)
207 #define SIZEOF_ALL_FINGERS (MAX_FINGERS * SIZEOF_FINGER)
208 #define MAX_FINGER_ORIENTATION 16384
253 #define SN_PRESSURE 45
266 0x81, TYPE1, FINGER_TYPE1, FINGER_TYPE1 + SIZEOF_ALL_FINGERS,
279 0x81, TYPE1, FINGER_TYPE1, FINGER_TYPE1 + SIZEOF_ALL_FINGERS,
292 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
305 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
318 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
331 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
344 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
357 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
370 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
383 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
396 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
412 for (cfg = bcm5974_config_table; cfg->
ansi; ++
cfg)
413 if (cfg->
ansi ==
id || cfg->
iso ==
id || cfg->
jis ==
id)
416 return bcm5974_config_table;
420 static inline int raw2int(
__le16 x)
425 static void set_abs(
struct input_dev *
input,
unsigned int code,
429 input_set_abs_params(input, code, p->
min, p->
max, fuzz, 0);
433 static void setup_events_to_report(
struct input_dev *input_dev,
439 input_set_abs_params(input_dev,
ABS_PRESSURE, 0, 256, 5, 0);
467 if (size !=
sizeof(
struct bt_data))
471 "bcm5974: button data: %x %x %x %x\n",
476 input_sync(dev->
input);
481 static void report_finger_data(
struct input_dev *input,
int slot,
502 static void report_synaptics_data(
struct input_dev *input,
506 int abs_p = 0, abs_w = 0;
511 if (p > 0 && raw2int(f->
origin)) {
512 abs_p =
clamp_val(256 * p / cfg->
p.max, 0, 255);
513 abs_w =
clamp_val(16 * w / cfg->
w.max, 0, 15);
522 static int report_tp_state(
struct bcm5974 *dev,
int size)
526 struct input_dev *input = dev->
input;
536 for (i = 0; i < raw_n; i++) {
540 dev->
pos[
n].y = c->
y.min + c->
y.max - raw2int(f[i].
abs_y);
546 for (i = 0; i <
n; i++)
547 report_finger_data(input, dev->
slots[i],
552 report_synaptics_data(input, c, f, raw_n);
557 input_report_key(input,
BTN_LEFT, ibt);
566 #define BCM5974_WELLSPRING_MODE_READ_REQUEST_ID 1
567 #define BCM5974_WELLSPRING_MODE_WRITE_REQUEST_ID 9
568 #define BCM5974_WELLSPRING_MODE_REQUEST_VALUE 0x300
569 #define BCM5974_WELLSPRING_MODE_REQUEST_INDEX 0
570 #define BCM5974_WELLSPRING_MODE_VENDOR_VALUE 0x01
571 #define BCM5974_WELLSPRING_MODE_NORMAL_VALUE 0x08
573 static int bcm5974_wellspring_mode(
struct bcm5974 *dev,
bool on)
592 dev_err(&dev->
intf->dev,
"could not read from device\n");
610 dev_err(&dev->
intf->dev,
"could not write to device\n");
615 dprintk(2,
"bcm5974: switched to %s mode.\n",
616 on ?
"wellspring" :
"normal");
623 static void bcm5974_irq_button(
struct urb *
urb)
625 struct bcm5974 *dev = urb->context;
629 switch (urb->status) {
636 dev_dbg(&intf->dev,
"button urb shutting down: %d\n",
640 dev_dbg(&intf->dev,
"button urb status: %d\n", urb->status);
644 if (report_bt_state(dev, dev->
bt_urb->actual_length))
645 dprintk(1,
"bcm5974: bad button package, length: %d\n",
646 dev->
bt_urb->actual_length);
651 dev_err(&intf->dev,
"button urb failed: %d\n", error);
654 static void bcm5974_irq_trackpad(
struct urb *urb)
656 struct bcm5974 *dev = urb->context;
660 switch (urb->status) {
667 dev_dbg(&intf->dev,
"trackpad urb shutting down: %d\n",
671 dev_dbg(&intf->dev,
"trackpad urb status: %d\n", urb->status);
676 if (dev->
tp_urb->actual_length == 2)
679 if (report_tp_state(dev, dev->
tp_urb->actual_length))
680 dprintk(1,
"bcm5974: bad trackpad package, length: %d\n",
681 dev->
tp_urb->actual_length);
686 dev_err(&intf->dev,
"trackpad urb failed: %d\n", error);
707 static int bcm5974_start_traffic(
struct bcm5974 *dev)
711 error = bcm5974_wellspring_mode(dev,
true);
713 dprintk(1,
"bcm5974: mode switch failed\n");
732 bcm5974_wellspring_mode(dev,
false);
737 static void bcm5974_pause_traffic(
struct bcm5974 *dev)
741 bcm5974_wellspring_mode(dev,
false);
752 static int bcm5974_open(
struct input_dev *input)
754 struct bcm5974 *dev = input_get_drvdata(input);
757 error = usb_autopm_get_interface(dev->
intf);
763 error = bcm5974_start_traffic(dev);
770 usb_autopm_put_interface(dev->
intf);
775 static void bcm5974_close(
struct input_dev *input)
777 struct bcm5974 *dev = input_get_drvdata(input);
781 bcm5974_pause_traffic(dev);
786 usb_autopm_put_interface(dev->
intf);
791 struct bcm5974 *dev = usb_get_intfdata(iface);
796 bcm5974_pause_traffic(dev);
805 struct bcm5974 *dev = usb_get_intfdata(iface);
811 error = bcm5974_start_traffic(dev);
821 struct usb_device *udev = interface_to_usbdev(iface);
824 struct input_dev *input_dev;
828 cfg = bcm5974_get_config(udev);
832 input_dev = input_allocate_device();
833 if (!dev || !input_dev) {
834 dev_err(&iface->dev,
"out of memory\n");
840 dev->
input = input_dev;
853 goto err_free_bt_urb;
858 &dev->
bt_urb->transfer_dma);
865 &dev->
tp_urb->transfer_dma);
867 goto err_free_bt_buffer;
870 usb_fill_int_urb(dev->
bt_urb, udev,
871 usb_rcvintpipe(udev, cfg->
bt_ep),
873 bcm5974_irq_button, dev, 1);
875 usb_fill_int_urb(dev->
tp_urb, udev,
876 usb_rcvintpipe(udev, cfg->
tp_ep),
878 bcm5974_irq_trackpad, dev, 1);
881 usb_make_path(udev, dev->
phys,
sizeof(dev->
phys));
884 input_dev->name =
"bcm5974";
885 input_dev->phys = dev->
phys;
886 usb_to_input_id(dev->
udev, &input_dev->id);
888 input_dev->id.version = cfg->
caps;
889 input_dev->dev.parent = &iface->dev;
891 input_set_drvdata(input_dev, dev);
893 input_dev->open = bcm5974_open;
894 input_dev->close = bcm5974_close;
896 setup_events_to_report(input_dev, cfg);
898 error = input_register_device(dev->
input);
900 goto err_free_buffer;
903 usb_set_intfdata(iface, dev);
919 usb_set_intfdata(iface,
NULL);
920 input_free_device(input_dev);
927 struct bcm5974 *dev = usb_get_intfdata(iface);
929 usb_set_intfdata(iface,
NULL);
931 input_unregister_device(dev->
input);
942 static struct usb_driver bcm5974_driver = {
944 .probe = bcm5974_probe,
945 .disconnect = bcm5974_disconnect,
946 .suspend = bcm5974_suspend,
947 .resume = bcm5974_resume,
948 .id_table = bcm5974_table,
949 .supports_autosuspend = 1,