^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * A driver for the Griffin Technology, Inc. "PowerMate" USB controller dial.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * v1.1, (c)2002 William R Sowerbutts <will@sowerbutts.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * This device is a anodised aluminium knob which connects over USB. It can measure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * clockwise and anticlockwise rotation. The dial also acts as a pushbutton with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * a spring for automatic release. The base contains a pair of LEDs which illuminate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * the translucent base. It rotates without limit and reports its relative rotation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * back to the host when polled by the USB controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Testing with the knob I have has shown that it measures approximately 94 "clicks"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * for one full rotation. Testing with my High Speed Rotation Actuator (ok, it was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * a variable speed cordless electric drill) has shown that the device can measure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * speeds of up to 7 clicks either clockwise or anticlockwise between pollings from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * the host. If it counts more than 7 clicks before it is polled, it will wrap back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * to zero and start counting again. This was at quite high speed, however, almost
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * certainly faster than the human hand could turn it. Griffin say that it loses a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * pulse or two on a direction change; the granularity is so fine that I never
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * noticed this in practice.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * The device's microcontroller can be programmed to set the LED to either a constant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * intensity, or to a rhythmic pulsing. Several patterns and speeds are available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * Griffin were very happy to provide documentation and free hardware for development.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * Some userspace tools are available on the web: http://sowerbutts.com/powermate/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/usb/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define POWERMATE_VENDOR 0x077d /* Griffin Technology, Inc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define POWERMATE_PRODUCT_NEW 0x0410 /* Griffin PowerMate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define POWERMATE_PRODUCT_OLD 0x04AA /* Griffin soundKnob */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define CONTOUR_VENDOR 0x05f3 /* Contour Design, Inc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define CONTOUR_JOG 0x0240 /* Jog and Shuttle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* these are the command codes we send to the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define SET_STATIC_BRIGHTNESS 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define SET_PULSE_ASLEEP 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define SET_PULSE_AWAKE 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define SET_PULSE_MODE 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* these refer to bits in the powermate_device's requires_update field. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define UPDATE_STATIC_BRIGHTNESS (1<<0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define UPDATE_PULSE_ASLEEP (1<<1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define UPDATE_PULSE_AWAKE (1<<2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define UPDATE_PULSE_MODE (1<<3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* at least two versions of the hardware exist, with differing payload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) sizes. the first three bytes always contain the "interesting" data in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) the relevant format. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define POWERMATE_PAYLOAD_SIZE_MAX 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define POWERMATE_PAYLOAD_SIZE_MIN 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct powermate_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) signed char *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) dma_addr_t data_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct urb *irq, *config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct usb_ctrlrequest *configcr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct usb_interface *intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int static_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) int pulse_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int pulse_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) int pulse_asleep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) int pulse_awake;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int requires_update; // physical settings which are out of sync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) char phys[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static char pm_name_powermate[] = "Griffin PowerMate";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static char pm_name_soundknob[] = "Griffin SoundKnob";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static void powermate_config_complete(struct urb *urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* Callback for data arriving from the PowerMate over the USB interrupt pipe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static void powermate_irq(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct powermate_device *pm = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct device *dev = &pm->intf->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) switch (urb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) case -ECONNRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* this urb is terminated, clean up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) dev_dbg(dev, "%s - urb shutting down with status: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) __func__, urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) dev_dbg(dev, "%s - nonzero urb status received: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) __func__, urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /* handle updates to device state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) input_report_key(pm->input, BTN_0, pm->data[0] & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) input_report_rel(pm->input, REL_DIAL, pm->data[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) input_sync(pm->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) retval = usb_submit_urb (urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) dev_err(dev, "%s - usb_submit_urb failed with result: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) __func__, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* Decide if we need to issue a control message and do so. Must be called with pm->lock taken */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static void powermate_sync_state(struct powermate_device *pm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (pm->requires_update == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return; /* no updates are required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (pm->config->status == -EINPROGRESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return; /* an update is already in progress; it'll issue this update when it completes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (pm->requires_update & UPDATE_PULSE_ASLEEP){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) pm->configcr->wValue = cpu_to_le16( SET_PULSE_ASLEEP );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) pm->configcr->wIndex = cpu_to_le16( pm->pulse_asleep ? 1 : 0 );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) pm->requires_update &= ~UPDATE_PULSE_ASLEEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }else if (pm->requires_update & UPDATE_PULSE_AWAKE){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) pm->configcr->wValue = cpu_to_le16( SET_PULSE_AWAKE );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) pm->configcr->wIndex = cpu_to_le16( pm->pulse_awake ? 1 : 0 );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) pm->requires_update &= ~UPDATE_PULSE_AWAKE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }else if (pm->requires_update & UPDATE_PULSE_MODE){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int op, arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /* the powermate takes an operation and an argument for its pulse algorithm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) the operation can be:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 0: divide the speed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 1: pulse at normal speed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 2: multiply the speed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) the argument only has an effect for operations 0 and 2, and ranges between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 1 (least effect) to 255 (maximum effect).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) thus, several states are equivalent and are coalesced into one state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) we map this onto a range from 0 to 510, with:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 0 -- 254 -- use divide (0 = slowest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 255 -- use normal speed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 256 -- 510 -- use multiple (510 = fastest).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) Only values of 'arg' quite close to 255 are particularly useful/spectacular.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (pm->pulse_speed < 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) op = 0; // divide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) arg = 255 - pm->pulse_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) } else if (pm->pulse_speed > 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) op = 2; // multiply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) arg = pm->pulse_speed - 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) op = 1; // normal speed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) arg = 0; // can be any value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) pm->configcr->wValue = cpu_to_le16( (pm->pulse_table << 8) | SET_PULSE_MODE );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) pm->configcr->wIndex = cpu_to_le16( (arg << 8) | op );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) pm->requires_update &= ~UPDATE_PULSE_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) } else if (pm->requires_update & UPDATE_STATIC_BRIGHTNESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) pm->configcr->wValue = cpu_to_le16( SET_STATIC_BRIGHTNESS );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) pm->configcr->wIndex = cpu_to_le16( pm->static_brightness );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) pm->requires_update &= ~UPDATE_STATIC_BRIGHTNESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) printk(KERN_ERR "powermate: unknown update required");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) pm->requires_update = 0; /* fudge the bug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /* printk("powermate: %04x %04x\n", pm->configcr->wValue, pm->configcr->wIndex); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) pm->configcr->bRequestType = 0x41; /* vendor request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) pm->configcr->bRequest = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) pm->configcr->wLength = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) usb_fill_control_urb(pm->config, pm->udev, usb_sndctrlpipe(pm->udev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) (void *) pm->configcr, NULL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) powermate_config_complete, pm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (usb_submit_urb(pm->config, GFP_ATOMIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) printk(KERN_ERR "powermate: usb_submit_urb(config) failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /* Called when our asynchronous control message completes. We may need to issue another immediately */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static void powermate_config_complete(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct powermate_device *pm = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (urb->status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) printk(KERN_ERR "powermate: config urb returned %d\n", urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) spin_lock_irqsave(&pm->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) powermate_sync_state(pm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) spin_unlock_irqrestore(&pm->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /* Set the LED up as described and begin the sync with the hardware if required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static void powermate_pulse_led(struct powermate_device *pm, int static_brightness, int pulse_speed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) int pulse_table, int pulse_asleep, int pulse_awake)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (pulse_speed < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) pulse_speed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (pulse_table < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) pulse_table = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (pulse_speed > 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) pulse_speed = 510;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (pulse_table > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) pulse_table = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) pulse_asleep = !!pulse_asleep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) pulse_awake = !!pulse_awake;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) spin_lock_irqsave(&pm->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* mark state updates which are required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (static_brightness != pm->static_brightness) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) pm->static_brightness = static_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) pm->requires_update |= UPDATE_STATIC_BRIGHTNESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (pulse_asleep != pm->pulse_asleep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) pm->pulse_asleep = pulse_asleep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) pm->requires_update |= (UPDATE_PULSE_ASLEEP | UPDATE_STATIC_BRIGHTNESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (pulse_awake != pm->pulse_awake) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) pm->pulse_awake = pulse_awake;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) pm->requires_update |= (UPDATE_PULSE_AWAKE | UPDATE_STATIC_BRIGHTNESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (pulse_speed != pm->pulse_speed || pulse_table != pm->pulse_table) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) pm->pulse_speed = pulse_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) pm->pulse_table = pulse_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) pm->requires_update |= UPDATE_PULSE_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) powermate_sync_state(pm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) spin_unlock_irqrestore(&pm->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /* Callback from the Input layer when an event arrives from userspace to configure the LED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static int powermate_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int _value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) unsigned int command = (unsigned int)_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) struct powermate_device *pm = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (type == EV_MSC && code == MSC_PULSELED){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) bits 0- 7: 8 bits: LED brightness
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) bits 8-16: 9 bits: pulsing speed modifier (0 ... 510); 0-254 = slower, 255 = standard, 256-510 = faster.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) bits 17-18: 2 bits: pulse table (0, 1, 2 valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) bit 19: 1 bit : pulse whilst asleep?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) bit 20: 1 bit : pulse constantly?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) int static_brightness = command & 0xFF; // bits 0-7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) int pulse_speed = (command >> 8) & 0x1FF; // bits 8-16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) int pulse_table = (command >> 17) & 0x3; // bits 17-18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) int pulse_asleep = (command >> 19) & 0x1; // bit 19
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) int pulse_awake = (command >> 20) & 0x1; // bit 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) powermate_pulse_led(pm, static_brightness, pulse_speed, pulse_table, pulse_asleep, pulse_awake);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static int powermate_alloc_buffers(struct usb_device *udev, struct powermate_device *pm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) pm->data = usb_alloc_coherent(udev, POWERMATE_PAYLOAD_SIZE_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) GFP_KERNEL, &pm->data_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (!pm->data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) pm->configcr = kmalloc(sizeof(*(pm->configcr)), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) if (!pm->configcr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static void powermate_free_buffers(struct usb_device *udev, struct powermate_device *pm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) usb_free_coherent(udev, POWERMATE_PAYLOAD_SIZE_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) pm->data, pm->data_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) kfree(pm->configcr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /* Called whenever a USB device matching one in our supported devices table is connected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static int powermate_probe(struct usb_interface *intf, const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) struct usb_device *udev = interface_to_usbdev (intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) struct usb_host_interface *interface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) struct usb_endpoint_descriptor *endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) struct powermate_device *pm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) int pipe, maxp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) int error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) interface = intf->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (interface->desc.bNumEndpoints < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) endpoint = &interface->endpoint[0].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (!usb_endpoint_is_int_in(endpoint))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 0x0a, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 0, interface->desc.bInterfaceNumber, NULL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) USB_CTRL_SET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) pm = kzalloc(sizeof(struct powermate_device), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (!pm || !input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (powermate_alloc_buffers(udev, pm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) pm->irq = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (!pm->irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) pm->config = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (!pm->config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) goto fail3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) pm->udev = udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) pm->intf = intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) pm->input = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) usb_make_path(udev, pm->phys, sizeof(pm->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) strlcat(pm->phys, "/input0", sizeof(pm->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) spin_lock_init(&pm->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) switch (le16_to_cpu(udev->descriptor.idProduct)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) case POWERMATE_PRODUCT_NEW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) input_dev->name = pm_name_powermate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) case POWERMATE_PRODUCT_OLD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) input_dev->name = pm_name_soundknob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) input_dev->name = pm_name_soundknob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) printk(KERN_WARNING "powermate: unknown product id %04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) le16_to_cpu(udev->descriptor.idProduct));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) input_dev->phys = pm->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) usb_to_input_id(udev, &input_dev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) input_dev->dev.parent = &intf->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) input_set_drvdata(input_dev, pm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) input_dev->event = powermate_input_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) BIT_MASK(EV_MSC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) input_dev->keybit[BIT_WORD(BTN_0)] = BIT_MASK(BTN_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) input_dev->relbit[BIT_WORD(REL_DIAL)] = BIT_MASK(REL_DIAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) input_dev->mscbit[BIT_WORD(MSC_PULSELED)] = BIT_MASK(MSC_PULSELED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /* get a handle to the interrupt data pipe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (maxp < POWERMATE_PAYLOAD_SIZE_MIN || maxp > POWERMATE_PAYLOAD_SIZE_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) printk(KERN_WARNING "powermate: Expected payload of %d--%d bytes, found %d bytes!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) POWERMATE_PAYLOAD_SIZE_MIN, POWERMATE_PAYLOAD_SIZE_MAX, maxp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) maxp = POWERMATE_PAYLOAD_SIZE_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) usb_fill_int_urb(pm->irq, udev, pipe, pm->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) maxp, powermate_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) pm, endpoint->bInterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) pm->irq->transfer_dma = pm->data_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) pm->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) /* register our interrupt URB with the USB system */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (usb_submit_urb(pm->irq, GFP_KERNEL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) goto fail4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) error = input_register_device(pm->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) goto fail5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) /* force an update of everything */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) pm->requires_update = UPDATE_PULSE_ASLEEP | UPDATE_PULSE_AWAKE | UPDATE_PULSE_MODE | UPDATE_STATIC_BRIGHTNESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) powermate_pulse_led(pm, 0x80, 255, 0, 1, 0); // set default pulse parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) usb_set_intfdata(intf, pm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) fail5: usb_kill_urb(pm->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) fail4: usb_free_urb(pm->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) fail3: usb_free_urb(pm->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) fail2: powermate_free_buffers(udev, pm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) fail1: input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) kfree(pm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) /* Called when a USB device we've accepted ownership of is removed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static void powermate_disconnect(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) struct powermate_device *pm = usb_get_intfdata (intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) usb_set_intfdata(intf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) if (pm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) pm->requires_update = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) usb_kill_urb(pm->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) input_unregister_device(pm->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) usb_free_urb(pm->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) usb_free_urb(pm->config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) powermate_free_buffers(interface_to_usbdev(intf), pm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) kfree(pm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) static const struct usb_device_id powermate_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) { USB_DEVICE(POWERMATE_VENDOR, POWERMATE_PRODUCT_NEW) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) { USB_DEVICE(POWERMATE_VENDOR, POWERMATE_PRODUCT_OLD) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) { USB_DEVICE(CONTOUR_VENDOR, CONTOUR_JOG) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) { } /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) MODULE_DEVICE_TABLE (usb, powermate_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) static struct usb_driver powermate_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) .name = "powermate",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) .probe = powermate_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) .disconnect = powermate_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) .id_table = powermate_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) module_usb_driver(powermate_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) MODULE_AUTHOR( "William R Sowerbutts" );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) MODULE_DESCRIPTION( "Griffin Technology, Inc PowerMate driver" );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) MODULE_LICENSE("GPL");