31 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/module.h>
38 #define POWERMATE_VENDOR 0x077d
39 #define POWERMATE_PRODUCT_NEW 0x0410
40 #define POWERMATE_PRODUCT_OLD 0x04AA
42 #define CONTOUR_VENDOR 0x05f3
43 #define CONTOUR_JOG 0x0240
46 #define SET_STATIC_BRIGHTNESS 0x01
47 #define SET_PULSE_ASLEEP 0x02
48 #define SET_PULSE_AWAKE 0x03
49 #define SET_PULSE_MODE 0x04
52 #define UPDATE_STATIC_BRIGHTNESS (1<<0)
53 #define UPDATE_PULSE_ASLEEP (1<<1)
54 #define UPDATE_PULSE_AWAKE (1<<2)
55 #define UPDATE_PULSE_MODE (1<<3)
60 #define POWERMATE_PAYLOAD_SIZE_MAX 6
61 #define POWERMATE_PAYLOAD_SIZE_MIN 3
80 static char pm_name_powermate[] =
"Griffin PowerMate";
81 static char pm_name_soundknob[] =
"Griffin SoundKnob";
83 static void powermate_config_complete(
struct urb *
urb);
86 static void powermate_irq(
struct urb *
urb)
92 switch (urb->status) {
100 dev_dbg(dev,
"%s - urb shutting down with status: %d\n",
101 __func__, urb->status);
104 dev_dbg(dev,
"%s - nonzero urb status received: %d\n",
105 __func__, urb->status);
112 input_sync(pm->
input);
117 dev_err(dev,
"%s - usb_submit_urb failed with result: %d\n",
185 usb_fill_control_urb(pm->
config, pm->
udev, usb_sndctrlpipe(pm->
udev, 0),
187 powermate_config_complete, pm);
194 static void powermate_config_complete(
struct urb *urb)
200 printk(
KERN_ERR "powermate: config urb returned %d\n", urb->status);
203 powermate_sync_state(pm);
204 spin_unlock_irqrestore(&pm->
lock, flags);
217 if (pulse_speed > 510)
247 powermate_sync_state(pm);
249 spin_unlock_irqrestore(&pm->
lock, flags);
253 static int powermate_input_event(
struct input_dev *dev,
unsigned int type,
unsigned int code,
int _value)
266 int static_brightness = command & 0xFF;
267 int pulse_speed = (command >> 8) & 0x1FF;
268 int pulse_table = (command >> 17) & 0x3;
269 int pulse_asleep = (command >> 19) & 0x1;
270 int pulse_awake = (command >> 20) & 0x1;
272 powermate_pulse_led(pm, static_brightness, pulse_speed, pulse_table, pulse_asleep, pulse_awake);
292 static void powermate_free_buffers(
struct usb_device *udev,
struct powermate_device *pm)
302 struct usb_device *udev = interface_to_usbdev (intf);
306 struct input_dev *input_dev;
310 interface = intf->cur_altsetting;
311 endpoint = &interface->endpoint[0].desc;
312 if (!usb_endpoint_is_int_in(endpoint))
317 0, interface->desc.bInterfaceNumber,
NULL, 0,
318 USB_CTRL_SET_TIMEOUT);
321 input_dev = input_allocate_device();
322 if (!pm || !input_dev)
325 if (powermate_alloc_buffers(udev, pm))
338 pm->
input = input_dev;
340 usb_make_path(udev, pm->
phys,
sizeof(pm->
phys));
347 input_dev->name = pm_name_powermate;
350 input_dev->name = pm_name_soundknob;
353 input_dev->name = pm_name_soundknob;
358 input_dev->phys = pm->
phys;
359 usb_to_input_id(udev, &input_dev->id);
360 input_dev->dev.parent = &intf->dev;
362 input_set_drvdata(input_dev, pm);
364 input_dev->event = powermate_input_event;
373 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
374 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
382 usb_fill_int_urb(pm->
irq, udev, pipe, pm->
data,
384 pm, endpoint->bInterval);
386 pm->
irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
394 error = input_register_device(pm->
input);
401 powermate_pulse_led(pm, 0x80, 255, 0, 1, 0);
403 usb_set_intfdata(intf, pm);
409 fail2: powermate_free_buffers(udev, pm);
410 fail1: input_free_device(input_dev);
420 usb_set_intfdata(intf,
NULL);
424 input_unregister_device(pm->
input);
427 powermate_free_buffers(interface_to_usbdev(intf), pm);
442 static struct usb_driver powermate_driver = {
444 .probe = powermate_probe,
445 .disconnect = powermate_disconnect,
446 .id_table = powermate_devices,