2 * drivers/usb/input/yealink.c
4 * Copyright (c) 2005 Henk Vergonet <Henk.Vergonet@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Driver for the USB-P1K voip usb phone.
23 * This device is produced by Yealink Network Technology Co Ltd
24 * but may be branded under several names:
29 * This driver is based on:
30 * - the usbb2k-api http://savannah.nongnu.org/projects/usbb2k-api/
31 * - information from http://memeteau.free.fr/usbb2k
32 * - the xpad-driver drivers/usb/input/xpad.c
35 * - Olivier Vandorpe, for providing the usbb2k-api.
36 * - Martin Diehl, for spotting my memory allocation bug.
39 * 20050527 henk First version, functional keyboard. Keyboard events
40 * will pop-up on the ../input/eventX bus.
41 * 20050531 henk Added led, LCD, dialtone and sysfs interface.
42 * 20050610 henk Cleanups, make it ready for public consumption.
43 * 20050630 henk Cleanups, fixes in response to comments.
44 * 20050701 henk sysfs write serialisation, fix potential unload races
45 * 20050801 henk Added ringtone, restructure USB
46 * 20050816 henk Merge 2.6.13-rc6
49 #include <linux/kernel.h>
50 #include <linux/init.h>
51 #include <linux/slab.h>
52 #include <linux/module.h>
53 #include <linux/rwsem.h>
54 #include <linux/usb/input.h>
56 #include "map_to_7segment.h"
59 #define DRIVER_VERSION "yld-20051230"
60 #define DRIVER_AUTHOR "Henk Vergonet"
61 #define DRIVER_DESC "Yealink phone driver"
63 #define YEALINK_POLLING_FREQUENCY 10 /* in [Hz] */
71 } __attribute__ ((packed));
74 * Register the LCD segment and icon map
76 #define _LOC(k,l) { .a = (k), .m = (l) }
77 #define _SEG(t, a, am, b, bm, c, cm, d, dm, e, em, f, fm, g, gm) \
79 .u = { .s = { _LOC(a, am), _LOC(b, bm), _LOC(c, cm), \
80 _LOC(d, dm), _LOC(e, em), _LOC(g, gm), \
82 #define _PIC(t, h, hm, n) \
84 .u = { .p = { .name = (n), .a = (h), .m = (hm) } } }
86 static const struct lcd_segment_map {
89 struct pictogram_map {
102 struct input_dev *idev; /* input device */
103 struct usb_device *udev; /* usb device */
105 /* irq input channel */
106 struct yld_ctl_packet *irq_data;
110 /* control output channel */
111 struct yld_ctl_packet *ctl_data;
113 struct usb_ctrlrequest *ctl_req;
114 dma_addr_t ctl_req_dma;
117 char phys[64]; /* physical device path */
119 u8 lcdMap[ARRAY_SIZE(lcdMap)]; /* state of LCD, LED ... */
120 int key_code; /* last reported key */
125 u8 b[sizeof(struct yld_status)];
130 /*******************************************************************************
131 * Yealink lcd interface
132 ******************************************************************************/
135 * Register a default 7 segment character set
137 static SEG7_DEFAULT_MAP(map_seg7);
140 * char '\9' and '\n' are placeholders and do not overwrite the original text.
141 * A space will always hide an icon.
143 static int setChar(struct yealink_dev *yld, int el, int chr)
147 if (el >= ARRAY_SIZE(lcdMap))
150 if (chr == '\t' || chr == '\n')
153 yld->lcdMap[el] = chr;
155 if (lcdMap[el].type == '.') {
156 a = lcdMap[el].u.p.a;
157 m = lcdMap[el].u.p.m;
159 yld->master.b[a] |= m;
161 yld->master.b[a] &= ~m;
165 val = map_to_seg7(&map_seg7, chr);
166 for (i = 0; i < ARRAY_SIZE(lcdMap[0].u.s); i++) {
167 m = lcdMap[el].u.s[i].m;
172 a = lcdMap[el].u.s[i].a;
174 yld->master.b[a] |= m;
176 yld->master.b[a] &= ~m;
182 /*******************************************************************************
183 * Yealink key interface
184 ******************************************************************************/
186 /* Map device buttons to internal key events.
188 * USB-P1K button layout:
200 * The "up" and "down" keys, are symbolised by arrows on the button.
201 * The "pickup" and "hangup" keys are symbolised by a green and red phone
204 static int map_p1k_to_key(int scancode)
206 switch(scancode) { /* phone key: */
207 case 0x23: return KEY_LEFT; /* IN */
208 case 0x33: return KEY_UP; /* up */
209 case 0x04: return KEY_RIGHT; /* OUT */
210 case 0x24: return KEY_DOWN; /* down */
211 case 0x03: return KEY_ENTER; /* pickup */
212 case 0x14: return KEY_BACKSPACE; /* C */
213 case 0x13: return KEY_ESC; /* hangup */
214 case 0x00: return KEY_1; /* 1 */
215 case 0x01: return KEY_2; /* 2 */
216 case 0x02: return KEY_3; /* 3 */
217 case 0x10: return KEY_4; /* 4 */
218 case 0x11: return KEY_5; /* 5 */
219 case 0x12: return KEY_6; /* 6 */
220 case 0x20: return KEY_7; /* 7 */
221 case 0x21: return KEY_8; /* 8 */
222 case 0x22: return KEY_9; /* 9 */
223 case 0x30: return KEY_KPASTERISK; /* * */
224 case 0x31: return KEY_0; /* 0 */
225 case 0x32: return KEY_LEFTSHIFT |
231 /* Completes a request by converting the data into events for the
234 * The key parameter can be cascaded: key2 << 8 | key1
236 static void report_key(struct yealink_dev *yld, int key, struct pt_regs *regs)
238 struct input_dev *idev = yld->idev;
240 input_regs(idev, regs);
241 if (yld->key_code >= 0) {
243 input_report_key(idev, yld->key_code & 0xff, 0);
244 if (yld->key_code >> 8)
245 input_report_key(idev, yld->key_code >> 8, 0);
251 input_report_key(idev, key & 0xff, 1);
253 input_report_key(idev, key >> 8, 1);
258 /*******************************************************************************
259 * Yealink usb communication interface
260 ******************************************************************************/
262 static int yealink_cmd(struct yealink_dev *yld, struct yld_ctl_packet *p)
268 for(i=0; i<USB_PKT_LEN-1; i++)
271 return usb_control_msg(yld->udev,
272 usb_sndctrlpipe(yld->udev, 0),
273 USB_REQ_SET_CONFIGURATION,
274 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
277 USB_CTRL_SET_TIMEOUT);
280 static u8 default_ringtone[] = {
281 0xEF, /* volume [0-255] */
282 0xFB, 0x1E, 0x00, 0x0C, /* 1250 [hz], 12/100 [s] */
283 0xFC, 0x18, 0x00, 0x0C, /* 1000 [hz], 12/100 [s] */
284 0xFB, 0x1E, 0x00, 0x0C,
285 0xFC, 0x18, 0x00, 0x0C,
286 0xFB, 0x1E, 0x00, 0x0C,
287 0xFC, 0x18, 0x00, 0x0C,
288 0xFB, 0x1E, 0x00, 0x0C,
289 0xFC, 0x18, 0x00, 0x0C,
290 0xFF, 0xFF, 0x01, 0x90, /* silent, 400/100 [s] */
291 0x00, 0x00 /* end of sequence */
294 static int yealink_set_ringtone(struct yealink_dev *yld, u8 *buf, size_t size)
296 struct yld_ctl_packet *p = yld->ctl_data;
302 /* Set the ringtone volume */
303 memset(yld->ctl_data, 0, sizeof(*(yld->ctl_data)));
304 yld->ctl_data->cmd = CMD_RING_VOLUME;
305 yld->ctl_data->size = 1;
306 yld->ctl_data->data[0] = buf[0];
312 p->cmd = CMD_RING_NOTE;
316 if (len > sizeof(p->data))
317 len = sizeof(p->data);
319 p->offset = cpu_to_be16(ix);
320 memcpy(p->data, &buf[ix], len);
327 /* keep stat_master & stat_copy in sync.
329 static int yealink_do_idle_tasks(struct yealink_dev *yld)
336 memset(yld->ctl_data, 0, sizeof(*(yld->ctl_data)));
337 yld->ctl_data->cmd = CMD_KEYPRESS;
338 yld->ctl_data->size = 1;
339 yld->ctl_data->sum = 0xff - CMD_KEYPRESS;
341 /* If state update pointer wraps do a KEYPRESS first. */
342 if (ix >= sizeof(yld->master)) {
347 /* find update candidates: copy != master */
349 val = yld->master.b[ix];
350 if (val != yld->copy.b[ix])
352 } while (++ix < sizeof(yld->master));
354 /* nothing todo, wait a bit and poll for a KEYPRESS */
356 /* TODO how can we wait abit. ??
357 * msleep_interruptible(1000 / YEALINK_POLLING_FREQUENCY);
363 /* Setup an appropriate update request */
364 yld->copy.b[ix] = val;
365 yld->ctl_data->data[0] = val;
368 case offsetof(struct yld_status, led):
369 yld->ctl_data->cmd = CMD_LED;
370 yld->ctl_data->sum = -1 - CMD_LED - val;
372 case offsetof(struct yld_status, dialtone):
373 yld->ctl_data->cmd = CMD_DIALTONE;
374 yld->ctl_data->sum = -1 - CMD_DIALTONE - val;
376 case offsetof(struct yld_status, ringtone):
377 yld->ctl_data->cmd = CMD_RINGTONE;
378 yld->ctl_data->sum = -1 - CMD_RINGTONE - val;
380 case offsetof(struct yld_status, keynum):
383 yld->ctl_data->cmd = CMD_SCANCODE;
384 yld->ctl_data->offset = cpu_to_be16(val);
385 yld->ctl_data->data[0] = 0;
386 yld->ctl_data->sum = -1 - CMD_SCANCODE - val;
389 len = sizeof(yld->master.s.lcd) - ix;
390 if (len > sizeof(yld->ctl_data->data))
391 len = sizeof(yld->ctl_data->data);
393 /* Combine up to <len> consecutive LCD bytes in a singe request
395 yld->ctl_data->cmd = CMD_LCD;
396 yld->ctl_data->offset = cpu_to_be16(ix);
397 yld->ctl_data->size = len;
398 yld->ctl_data->sum = -CMD_LCD - ix - val - len;
399 for(i=1; i<len; i++) {
401 val = yld->master.b[ix];
402 yld->copy.b[ix] = val;
403 yld->ctl_data->data[i] = val;
404 yld->ctl_data->sum -= val;
407 yld->stat_ix = ix + 1;
411 /* Decide on how to handle responses
413 * The state transition diagram is somethhing like:
419 * init --ok--> waitForKey --ok--> getKey
421 * | +-------ok-------+
425 static void urb_irq_callback(struct urb *urb, struct pt_regs *regs)
427 struct yealink_dev *yld = urb->context;
431 err("%s - urb status %d", __FUNCTION__, urb->status);
433 switch (yld->irq_data->cmd) {
436 yld->master.s.keynum = yld->irq_data->data[0];
440 dbg("get scancode %x", yld->irq_data->data[0]);
442 report_key(yld, map_p1k_to_key(yld->irq_data->data[0]), regs);
446 err("unexpected response %x", yld->irq_data->cmd);
449 yealink_do_idle_tasks(yld);
451 ret = usb_submit_urb(yld->urb_ctl, GFP_ATOMIC);
453 err("%s - usb_submit_urb failed %d", __FUNCTION__, ret);
456 static void urb_ctl_callback(struct urb *urb, struct pt_regs *regs)
458 struct yealink_dev *yld = urb->context;
462 err("%s - urb status %d", __FUNCTION__, urb->status);
464 switch (yld->ctl_data->cmd) {
467 /* ask for a response */
468 ret = usb_submit_urb(yld->urb_irq, GFP_ATOMIC);
471 /* send new command */
472 yealink_do_idle_tasks(yld);
473 ret = usb_submit_urb(yld->urb_ctl, GFP_ATOMIC);
477 err("%s - usb_submit_urb failed %d", __FUNCTION__, ret);
480 /*******************************************************************************
481 * input event interface
482 ******************************************************************************/
484 /* TODO should we issue a ringtone on a SND_BELL event?
485 static int input_ev(struct input_dev *dev, unsigned int type,
486 unsigned int code, int value)
504 static int input_open(struct input_dev *dev)
506 struct yealink_dev *yld = dev->private;
509 dbg("%s", __FUNCTION__);
511 /* force updates to device */
512 for (i = 0; i<sizeof(yld->master); i++)
513 yld->copy.b[i] = ~yld->master.b[i];
514 yld->key_code = -1; /* no keys pressed */
516 yealink_set_ringtone(yld, default_ringtone, sizeof(default_ringtone));
519 memset(yld->ctl_data, 0, sizeof(*(yld->ctl_data)));
520 yld->ctl_data->cmd = CMD_INIT;
521 yld->ctl_data->size = 10;
522 yld->ctl_data->sum = 0x100-CMD_INIT-10;
523 if ((ret = usb_submit_urb(yld->urb_ctl, GFP_KERNEL)) != 0) {
524 dbg("%s - usb_submit_urb failed with result %d",
531 static void input_close(struct input_dev *dev)
533 struct yealink_dev *yld = dev->private;
535 usb_kill_urb(yld->urb_ctl);
536 usb_kill_urb(yld->urb_irq);
539 /*******************************************************************************
541 ******************************************************************************/
543 static DECLARE_RWSEM(sysfs_rwsema);
545 /* Interface to the 7-segments translation table aka. char set.
547 static ssize_t show_map(struct device *dev, struct device_attribute *attr,
550 memcpy(buf, &map_seg7, sizeof(map_seg7));
551 return sizeof(map_seg7);
554 static ssize_t store_map(struct device *dev, struct device_attribute *attr,
555 const char *buf, size_t cnt)
557 if (cnt != sizeof(map_seg7))
559 memcpy(&map_seg7, buf, sizeof(map_seg7));
560 return sizeof(map_seg7);
563 /* Interface to the LCD.
566 /* Reading /sys/../lineX will return the format string with its settings:
573 static ssize_t show_line(struct device *dev, char *buf, int a, int b)
575 struct yealink_dev *yld;
578 down_read(&sysfs_rwsema);
579 yld = dev_get_drvdata(dev);
581 up_read(&sysfs_rwsema);
585 for (i = a; i < b; i++)
586 *buf++ = lcdMap[i].type;
588 for (i = a; i < b; i++)
589 *buf++ = yld->lcdMap[i];
593 up_read(&sysfs_rwsema);
594 return 3 + ((b - a) << 1);
597 static ssize_t show_line1(struct device *dev, struct device_attribute *attr,
600 return show_line(dev, buf, LCD_LINE1_OFFSET, LCD_LINE2_OFFSET);
603 static ssize_t show_line2(struct device *dev, struct device_attribute *attr,
606 return show_line(dev, buf, LCD_LINE2_OFFSET, LCD_LINE3_OFFSET);
609 static ssize_t show_line3(struct device *dev, struct device_attribute *attr,
612 return show_line(dev, buf, LCD_LINE3_OFFSET, LCD_LINE4_OFFSET);
615 /* Writing to /sys/../lineX will set the coresponding LCD line.
616 * - Excess characters are ignored.
617 * - If less characters are written than allowed, the remaining digits are
619 * - The '\n' or '\t' char is a placeholder, it does not overwrite the
622 static ssize_t store_line(struct device *dev, const char *buf, size_t count,
625 struct yealink_dev *yld;
628 down_write(&sysfs_rwsema);
629 yld = dev_get_drvdata(dev);
631 up_write(&sysfs_rwsema);
637 for (i = 0; i < len; i++)
638 setChar(yld, el++, buf[i]);
640 up_write(&sysfs_rwsema);
644 static ssize_t store_line1(struct device *dev, struct device_attribute *attr,
645 const char *buf, size_t count)
647 return store_line(dev, buf, count, LCD_LINE1_OFFSET, LCD_LINE1_SIZE);
650 static ssize_t store_line2(struct device *dev, struct device_attribute *attr,
651 const char *buf, size_t count)
653 return store_line(dev, buf, count, LCD_LINE2_OFFSET, LCD_LINE2_SIZE);
656 static ssize_t store_line3(struct device *dev, struct device_attribute *attr,
657 const char *buf, size_t count)
659 return store_line(dev, buf, count, LCD_LINE3_OFFSET, LCD_LINE3_SIZE);
662 /* Interface to visible and audible "icons", these include:
663 * pictures on the LCD, the LED, and the dialtone signal.
666 /* Get a list of "switchable elements" with their current state. */
667 static ssize_t get_icons(struct device *dev, struct device_attribute *attr,
670 struct yealink_dev *yld;
673 down_read(&sysfs_rwsema);
674 yld = dev_get_drvdata(dev);
676 up_read(&sysfs_rwsema);
680 for (i = 0; i < ARRAY_SIZE(lcdMap); i++) {
681 if (lcdMap[i].type != '.')
683 ret += sprintf(&buf[ret], "%s %s\n",
684 yld->lcdMap[i] == ' ' ? " " : "on",
687 up_read(&sysfs_rwsema);
691 /* Change the visibility of a particular element. */
692 static ssize_t set_icon(struct device *dev, const char *buf, size_t count,
695 struct yealink_dev *yld;
698 down_write(&sysfs_rwsema);
699 yld = dev_get_drvdata(dev);
701 up_write(&sysfs_rwsema);
705 for (i = 0; i < ARRAY_SIZE(lcdMap); i++) {
706 if (lcdMap[i].type != '.')
708 if (strncmp(buf, lcdMap[i].u.p.name, count) == 0) {
709 setChar(yld, i, chr);
714 up_write(&sysfs_rwsema);
718 static ssize_t show_icon(struct device *dev, struct device_attribute *attr,
719 const char *buf, size_t count)
721 return set_icon(dev, buf, count, buf[0]);
724 static ssize_t hide_icon(struct device *dev, struct device_attribute *attr,
725 const char *buf, size_t count)
727 return set_icon(dev, buf, count, ' ');
730 /* Upload a ringtone to the device.
733 /* Stores raw ringtone data in the phone */
734 static ssize_t store_ringtone(struct device *dev,
735 struct device_attribute *attr,
736 const char *buf, size_t count)
738 struct yealink_dev *yld;
740 down_write(&sysfs_rwsema);
741 yld = dev_get_drvdata(dev);
743 up_write(&sysfs_rwsema);
747 /* TODO locking with async usb control interface??? */
748 yealink_set_ringtone(yld, (char *)buf, count);
749 up_write(&sysfs_rwsema);
753 #define _M444 S_IRUGO
754 #define _M664 S_IRUGO|S_IWUSR|S_IWGRP
755 #define _M220 S_IWUSR|S_IWGRP
757 static DEVICE_ATTR(map_seg7 , _M664, show_map , store_map );
758 static DEVICE_ATTR(line1 , _M664, show_line1 , store_line1 );
759 static DEVICE_ATTR(line2 , _M664, show_line2 , store_line2 );
760 static DEVICE_ATTR(line3 , _M664, show_line3 , store_line3 );
761 static DEVICE_ATTR(get_icons , _M444, get_icons , NULL );
762 static DEVICE_ATTR(show_icon , _M220, NULL , show_icon );
763 static DEVICE_ATTR(hide_icon , _M220, NULL , hide_icon );
764 static DEVICE_ATTR(ringtone , _M220, NULL , store_ringtone);
766 static struct attribute *yld_attributes[] = {
767 &dev_attr_line1.attr,
768 &dev_attr_line2.attr,
769 &dev_attr_line3.attr,
770 &dev_attr_get_icons.attr,
771 &dev_attr_show_icon.attr,
772 &dev_attr_hide_icon.attr,
773 &dev_attr_map_seg7.attr,
774 &dev_attr_ringtone.attr,
778 static struct attribute_group yld_attr_group = {
779 .attrs = yld_attributes
782 /*******************************************************************************
783 * Linux interface and usb initialisation
784 ******************************************************************************/
790 static const struct driver_info info_P1K = {
791 .name = "Yealink usb-p1k",
794 static const struct usb_device_id usb_table [] = {
796 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
797 USB_DEVICE_ID_MATCH_INT_INFO,
800 .bInterfaceClass = USB_CLASS_HID,
801 .bInterfaceSubClass = 0,
802 .bInterfaceProtocol = 0,
803 .driver_info = (kernel_ulong_t)&info_P1K
808 static int usb_cleanup(struct yealink_dev *yld, int err)
813 usb_kill_urb(yld->urb_irq); /* parameter validation in core/urb */
814 usb_kill_urb(yld->urb_ctl); /* parameter validation in core/urb */
818 input_free_device(yld->idev);
820 input_unregister_device(yld->idev);
823 usb_buffer_free(yld->udev, sizeof(*(yld->ctl_req)),
824 yld->ctl_req, yld->ctl_req_dma);
826 usb_buffer_free(yld->udev, USB_PKT_LEN,
827 yld->ctl_data, yld->ctl_dma);
829 usb_buffer_free(yld->udev, USB_PKT_LEN,
830 yld->irq_data, yld->irq_dma);
832 usb_free_urb(yld->urb_irq); /* parameter validation in core/urb */
833 usb_free_urb(yld->urb_ctl); /* parameter validation in core/urb */
838 static void usb_disconnect(struct usb_interface *intf)
840 struct yealink_dev *yld;
842 down_write(&sysfs_rwsema);
843 yld = usb_get_intfdata(intf);
844 sysfs_remove_group(&intf->dev.kobj, &yld_attr_group);
845 usb_set_intfdata(intf, NULL);
846 up_write(&sysfs_rwsema);
851 static int usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
853 struct usb_device *udev = interface_to_usbdev (intf);
854 struct driver_info *nfo = (struct driver_info *)id->driver_info;
855 struct usb_host_interface *interface;
856 struct usb_endpoint_descriptor *endpoint;
857 struct yealink_dev *yld;
858 struct input_dev *input_dev;
861 interface = intf->cur_altsetting;
862 endpoint = &interface->endpoint[0].desc;
863 if (!(endpoint->bEndpointAddress & USB_DIR_IN))
865 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT)
868 yld = kzalloc(sizeof(struct yealink_dev), GFP_KERNEL);
874 yld->idev = input_dev = input_allocate_device();
876 return usb_cleanup(yld, -ENOMEM);
878 /* allocate usb buffers */
879 yld->irq_data = usb_buffer_alloc(udev, USB_PKT_LEN,
880 SLAB_ATOMIC, &yld->irq_dma);
881 if (yld->irq_data == NULL)
882 return usb_cleanup(yld, -ENOMEM);
884 yld->ctl_data = usb_buffer_alloc(udev, USB_PKT_LEN,
885 SLAB_ATOMIC, &yld->ctl_dma);
887 return usb_cleanup(yld, -ENOMEM);
889 yld->ctl_req = usb_buffer_alloc(udev, sizeof(*(yld->ctl_req)),
890 SLAB_ATOMIC, &yld->ctl_req_dma);
891 if (yld->ctl_req == NULL)
892 return usb_cleanup(yld, -ENOMEM);
894 /* allocate urb structures */
895 yld->urb_irq = usb_alloc_urb(0, GFP_KERNEL);
896 if (yld->urb_irq == NULL)
897 return usb_cleanup(yld, -ENOMEM);
899 yld->urb_ctl = usb_alloc_urb(0, GFP_KERNEL);
900 if (yld->urb_ctl == NULL)
901 return usb_cleanup(yld, -ENOMEM);
903 /* get a handle to the interrupt data pipe */
904 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
905 ret = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
906 if (ret != USB_PKT_LEN)
907 err("invalid payload size %d, expected %zd", ret, USB_PKT_LEN);
909 /* initialise irq urb */
910 usb_fill_int_urb(yld->urb_irq, udev, pipe, yld->irq_data,
913 yld, endpoint->bInterval);
914 yld->urb_irq->transfer_dma = yld->irq_dma;
915 yld->urb_irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
916 yld->urb_irq->dev = udev;
918 /* initialise ctl urb */
919 yld->ctl_req->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE |
921 yld->ctl_req->bRequest = USB_REQ_SET_CONFIGURATION;
922 yld->ctl_req->wValue = cpu_to_le16(0x200);
923 yld->ctl_req->wIndex = cpu_to_le16(interface->desc.bInterfaceNumber);
924 yld->ctl_req->wLength = cpu_to_le16(USB_PKT_LEN);
926 usb_fill_control_urb(yld->urb_ctl, udev, usb_sndctrlpipe(udev, 0),
927 (void *)yld->ctl_req, yld->ctl_data, USB_PKT_LEN,
928 urb_ctl_callback, yld);
929 yld->urb_ctl->setup_dma = yld->ctl_req_dma;
930 yld->urb_ctl->transfer_dma = yld->ctl_dma;
931 yld->urb_ctl->transfer_flags |= URB_NO_SETUP_DMA_MAP |
932 URB_NO_TRANSFER_DMA_MAP;
933 yld->urb_ctl->dev = udev;
935 /* find out the physical bus location */
936 usb_make_path(udev, yld->phys, sizeof(yld->phys));
937 strlcat(yld->phys, "/input0", sizeof(yld->phys));
939 /* register settings for the input device */
940 input_dev->name = nfo->name;
941 input_dev->phys = yld->phys;
942 usb_to_input_id(udev, &input_dev->id);
943 input_dev->cdev.dev = &intf->dev;
945 input_dev->private = yld;
946 input_dev->open = input_open;
947 input_dev->close = input_close;
948 /* input_dev->event = input_ev; TODO */
950 /* register available key events */
951 input_dev->evbit[0] = BIT(EV_KEY);
952 for (i = 0; i < 256; i++) {
953 int k = map_p1k_to_key(i);
955 set_bit(k & 0xff, input_dev->keybit);
957 set_bit(k >> 8, input_dev->keybit);
961 input_register_device(yld->idev);
963 usb_set_intfdata(intf, yld);
965 /* clear visible elements */
966 for (i = 0; i < ARRAY_SIZE(lcdMap); i++)
967 setChar(yld, i, ' ');
969 /* display driver version on LCD line 3 */
970 store_line3(&intf->dev, NULL,
971 DRIVER_VERSION, sizeof(DRIVER_VERSION));
973 /* Register sysfs hooks (don't care about failure) */
974 sysfs_create_group(&intf->dev.kobj, &yld_attr_group);
978 static struct usb_driver yealink_driver = {
981 .disconnect = usb_disconnect,
982 .id_table = usb_table,
985 static int __init yealink_dev_init(void)
987 int ret = usb_register(&yealink_driver);
989 info(DRIVER_DESC ":" DRIVER_VERSION);
993 static void __exit yealink_dev_exit(void)
995 usb_deregister(&yealink_driver);
998 module_init(yealink_dev_init);
999 module_exit(yealink_dev_exit);
1001 MODULE_DEVICE_TABLE (usb, usb_table);
1003 MODULE_AUTHOR(DRIVER_AUTHOR);
1004 MODULE_DESCRIPTION(DRIVER_DESC);
1005 MODULE_LICENSE("GPL");