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/config.h>
50 #include <linux/kernel.h>
51 #include <linux/input.h>
52 #include <linux/init.h>
53 #include <linux/slab.h>
54 #include <linux/module.h>
55 #include <linux/rwsem.h>
56 #include <linux/usb.h>
58 #include "map_to_7segment.h"
61 #define DRIVER_VERSION "yld-20050816"
62 #define DRIVER_AUTHOR "Henk Vergonet"
63 #define DRIVER_DESC "Yealink phone driver"
65 #define YEALINK_POLLING_FREQUENCY 10 /* in [Hz] */
73 } __attribute__ ((packed));
76 * Register the LCD segment and icon map
78 #define _LOC(k,l) { .a = (k), .m = (l) }
79 #define _SEG(t, a, am, b, bm, c, cm, d, dm, e, em, f, fm, g, gm) \
81 .u = { .s = { _LOC(a, am), _LOC(b, bm), _LOC(c, cm), \
82 _LOC(d, dm), _LOC(e, em), _LOC(g, gm), \
84 #define _PIC(t, h, hm, n) \
86 .u = { .p = { .name = (n), .a = (h), .m = (hm) } } }
88 static const struct lcd_segment_map {
91 struct pictogram_map {
104 struct input_dev idev; /* input device */
105 struct usb_device *udev; /* usb device */
107 /* irq input channel */
108 struct yld_ctl_packet *irq_data;
112 /* control output channel */
113 struct yld_ctl_packet *ctl_data;
115 struct usb_ctrlrequest *ctl_req;
116 dma_addr_t ctl_req_dma;
119 char phys[64]; /* physical device path */
121 u8 lcdMap[ARRAY_SIZE(lcdMap)]; /* state of LCD, LED ... */
122 int key_code; /* last reported key */
127 u8 b[sizeof(struct yld_status)];
132 /*******************************************************************************
133 * Yealink lcd interface
134 ******************************************************************************/
137 * Register a default 7 segment character set
139 static SEG7_DEFAULT_MAP(map_seg7);
142 * char '\9' and '\n' are placeholders and do not overwrite the original text.
143 * A space will always hide an icon.
145 static int setChar(struct yealink_dev *yld, int el, int chr)
149 if (el >= ARRAY_SIZE(lcdMap))
152 if (chr == '\t' || chr == '\n')
155 yld->lcdMap[el] = chr;
157 if (lcdMap[el].type == '.') {
158 a = lcdMap[el].u.p.a;
159 m = lcdMap[el].u.p.m;
161 yld->master.b[a] |= m;
163 yld->master.b[a] &= ~m;
167 val = map_to_seg7(&map_seg7, chr);
168 for (i = 0; i < ARRAY_SIZE(lcdMap[0].u.s); i++) {
169 m = lcdMap[el].u.s[i].m;
174 a = lcdMap[el].u.s[i].a;
176 yld->master.b[a] |= m;
178 yld->master.b[a] &= ~m;
184 /*******************************************************************************
185 * Yealink key interface
186 ******************************************************************************/
188 /* Map device buttons to internal key events.
190 * USB-P1K button layout:
202 * The "up" and "down" keys, are symbolised by arrows on the button.
203 * The "pickup" and "hangup" keys are symbolised by a green and red phone
206 static int map_p1k_to_key(int scancode)
208 switch(scancode) { /* phone key: */
209 case 0x23: return KEY_LEFT; /* IN */
210 case 0x33: return KEY_UP; /* up */
211 case 0x04: return KEY_RIGHT; /* OUT */
212 case 0x24: return KEY_DOWN; /* down */
213 case 0x03: return KEY_ENTER; /* pickup */
214 case 0x14: return KEY_BACKSPACE; /* C */
215 case 0x13: return KEY_ESC; /* hangup */
216 case 0x00: return KEY_1; /* 1 */
217 case 0x01: return KEY_2; /* 2 */
218 case 0x02: return KEY_3; /* 3 */
219 case 0x10: return KEY_4; /* 4 */
220 case 0x11: return KEY_5; /* 5 */
221 case 0x12: return KEY_6; /* 6 */
222 case 0x20: return KEY_7; /* 7 */
223 case 0x21: return KEY_8; /* 8 */
224 case 0x22: return KEY_9; /* 9 */
225 case 0x30: return KEY_KPASTERISK; /* * */
226 case 0x31: return KEY_0; /* 0 */
227 case 0x32: return KEY_LEFTSHIFT |
233 /* Completes a request by converting the data into events for the
236 * The key parameter can be cascaded: key2 << 8 | key1
238 static void report_key(struct yealink_dev *yld, int key, struct pt_regs *regs)
240 struct input_dev *idev = &yld->idev;
242 input_regs(idev, regs);
243 if (yld->key_code >= 0) {
245 input_report_key(idev, yld->key_code & 0xff, 0);
246 if (yld->key_code >> 8)
247 input_report_key(idev, yld->key_code >> 8, 0);
253 input_report_key(idev, key & 0xff, 1);
255 input_report_key(idev, key >> 8, 1);
260 /*******************************************************************************
261 * Yealink usb communication interface
262 ******************************************************************************/
264 static int yealink_cmd(struct yealink_dev *yld, struct yld_ctl_packet *p)
270 for(i=0; i<USB_PKT_LEN-1; i++)
273 return usb_control_msg(yld->udev,
274 usb_sndctrlpipe(yld->udev, 0),
275 USB_REQ_SET_CONFIGURATION,
276 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
279 USB_CTRL_SET_TIMEOUT);
282 static u8 default_ringtone[] = {
283 0xEF, /* volume [0-255] */
284 0xFB, 0x1E, 0x00, 0x0C, /* 1250 [hz], 12/100 [s] */
285 0xFC, 0x18, 0x00, 0x0C, /* 1000 [hz], 12/100 [s] */
286 0xFB, 0x1E, 0x00, 0x0C,
287 0xFC, 0x18, 0x00, 0x0C,
288 0xFB, 0x1E, 0x00, 0x0C,
289 0xFC, 0x18, 0x00, 0x0C,
290 0xFB, 0x1E, 0x00, 0x0C,
291 0xFC, 0x18, 0x00, 0x0C,
292 0xFF, 0xFF, 0x01, 0x90, /* silent, 400/100 [s] */
293 0x00, 0x00 /* end of sequence */
296 static int yealink_set_ringtone(struct yealink_dev *yld, u8 *buf, size_t size)
298 struct yld_ctl_packet *p = yld->ctl_data;
304 /* Set the ringtone volume */
305 memset(yld->ctl_data, 0, sizeof(*(yld->ctl_data)));
306 yld->ctl_data->cmd = CMD_RING_VOLUME;
307 yld->ctl_data->size = 1;
308 yld->ctl_data->data[0] = buf[0];
314 p->cmd = CMD_RING_NOTE;
318 if (len > sizeof(p->data))
319 len = sizeof(p->data);
321 p->offset = cpu_to_be16(ix);
322 memcpy(p->data, &buf[ix], len);
329 /* keep stat_master & stat_copy in sync.
331 static int yealink_do_idle_tasks(struct yealink_dev *yld)
338 memset(yld->ctl_data, 0, sizeof(*(yld->ctl_data)));
339 yld->ctl_data->cmd = CMD_KEYPRESS;
340 yld->ctl_data->size = 1;
341 yld->ctl_data->sum = 0xff - CMD_KEYPRESS;
343 /* If state update pointer wraps do a KEYPRESS first. */
344 if (ix >= sizeof(yld->master)) {
349 /* find update candidates: copy != master */
351 val = yld->master.b[ix];
352 if (val != yld->copy.b[ix])
354 } while (++ix < sizeof(yld->master));
356 /* nothing todo, wait a bit and poll for a KEYPRESS */
358 /* TODO how can we wait abit. ??
359 * msleep_interruptible(1000 / YEALINK_POLLING_FREQUENCY);
365 /* Setup an appropriate update request */
366 yld->copy.b[ix] = val;
367 yld->ctl_data->data[0] = val;
370 case offsetof(struct yld_status, led):
371 yld->ctl_data->cmd = CMD_LED;
372 yld->ctl_data->sum = -1 - CMD_LED - val;
374 case offsetof(struct yld_status, dialtone):
375 yld->ctl_data->cmd = CMD_DIALTONE;
376 yld->ctl_data->sum = -1 - CMD_DIALTONE - val;
378 case offsetof(struct yld_status, ringtone):
379 yld->ctl_data->cmd = CMD_RINGTONE;
380 yld->ctl_data->sum = -1 - CMD_RINGTONE - val;
382 case offsetof(struct yld_status, keynum):
385 yld->ctl_data->cmd = CMD_SCANCODE;
386 yld->ctl_data->offset = cpu_to_be16(val);
387 yld->ctl_data->data[0] = 0;
388 yld->ctl_data->sum = -1 - CMD_SCANCODE - val;
391 len = sizeof(yld->master.s.lcd) - ix;
392 if (len > sizeof(yld->ctl_data->data))
393 len = sizeof(yld->ctl_data->data);
395 /* Combine up to <len> consecutive LCD bytes in a singe request
397 yld->ctl_data->cmd = CMD_LCD;
398 yld->ctl_data->offset = cpu_to_be16(ix);
399 yld->ctl_data->size = len;
400 yld->ctl_data->sum = -CMD_LCD - ix - val - len;
401 for(i=1; i<len; i++) {
403 val = yld->master.b[ix];
404 yld->copy.b[ix] = val;
405 yld->ctl_data->data[i] = val;
406 yld->ctl_data->sum -= val;
409 yld->stat_ix = ix + 1;
413 /* Decide on how to handle responses
415 * The state transition diagram is somethhing like:
421 * init --ok--> waitForKey --ok--> getKey
423 * | +-------ok-------+
427 static void urb_irq_callback(struct urb *urb, struct pt_regs *regs)
429 struct yealink_dev *yld = urb->context;
433 err("%s - urb status %d", __FUNCTION__, urb->status);
435 switch (yld->irq_data->cmd) {
438 yld->master.s.keynum = yld->irq_data->data[0];
442 dbg("get scancode %x", yld->irq_data->data[0]);
444 report_key(yld, map_p1k_to_key(yld->irq_data->data[0]), regs);
448 err("unexpected response %x", yld->irq_data->cmd);
451 yealink_do_idle_tasks(yld);
453 ret = usb_submit_urb(yld->urb_ctl, GFP_ATOMIC);
455 err("%s - usb_submit_urb failed %d", __FUNCTION__, ret);
458 static void urb_ctl_callback(struct urb *urb, struct pt_regs *regs)
460 struct yealink_dev *yld = urb->context;
464 err("%s - urb status %d", __FUNCTION__, urb->status);
466 switch (yld->ctl_data->cmd) {
469 /* ask for a response */
470 ret = usb_submit_urb(yld->urb_irq, GFP_ATOMIC);
473 /* send new command */
474 yealink_do_idle_tasks(yld);
475 ret = usb_submit_urb(yld->urb_ctl, GFP_ATOMIC);
479 err("%s - usb_submit_urb failed %d", __FUNCTION__, ret);
482 /*******************************************************************************
483 * input event interface
484 ******************************************************************************/
486 /* TODO should we issue a ringtone on a SND_BELL event?
487 static int input_ev(struct input_dev *dev, unsigned int type,
488 unsigned int code, int value)
506 static int input_open(struct input_dev *dev)
508 struct yealink_dev *yld = dev->private;
511 dbg("%s", __FUNCTION__);
513 /* force updates to device */
514 for (i = 0; i<sizeof(yld->master); i++)
515 yld->copy.b[i] = ~yld->master.b[i];
516 yld->key_code = -1; /* no keys pressed */
518 yealink_set_ringtone(yld, default_ringtone, sizeof(default_ringtone));
521 memset(yld->ctl_data, 0, sizeof(*(yld->ctl_data)));
522 yld->ctl_data->cmd = CMD_INIT;
523 yld->ctl_data->size = 10;
524 yld->ctl_data->sum = 0x100-CMD_INIT-10;
525 if ((ret = usb_submit_urb(yld->urb_ctl, GFP_KERNEL)) != 0) {
526 dbg("%s - usb_submit_urb failed with result %d",
533 static void input_close(struct input_dev *dev)
535 struct yealink_dev *yld = dev->private;
537 usb_kill_urb(yld->urb_ctl);
538 usb_kill_urb(yld->urb_irq);
541 /*******************************************************************************
543 ******************************************************************************/
545 static DECLARE_RWSEM(sysfs_rwsema);
547 /* Interface to the 7-segments translation table aka. char set.
549 static ssize_t show_map(struct device *dev, struct device_attribute *attr,
552 memcpy(buf, &map_seg7, sizeof(map_seg7));
553 return sizeof(map_seg7);
556 static ssize_t store_map(struct device *dev, struct device_attribute *attr,
557 const char *buf, size_t cnt)
559 if (cnt != sizeof(map_seg7))
561 memcpy(&map_seg7, buf, sizeof(map_seg7));
562 return sizeof(map_seg7);
565 /* Interface to the LCD.
568 /* Reading /sys/../lineX will return the format string with its settings:
575 static ssize_t show_line(struct device *dev, char *buf, int a, int b)
577 struct yealink_dev *yld;
580 down_read(&sysfs_rwsema);
581 yld = dev_get_drvdata(dev);
583 up_read(&sysfs_rwsema);
587 for (i = a; i < b; i++)
588 *buf++ = lcdMap[i].type;
590 for (i = a; i < b; i++)
591 *buf++ = yld->lcdMap[i];
595 up_read(&sysfs_rwsema);
596 return 3 + ((b - a) << 1);
599 static ssize_t show_line1(struct device *dev, struct device_attribute *attr,
602 return show_line(dev, buf, LCD_LINE1_OFFSET, LCD_LINE2_OFFSET);
605 static ssize_t show_line2(struct device *dev, struct device_attribute *attr,
608 return show_line(dev, buf, LCD_LINE2_OFFSET, LCD_LINE3_OFFSET);
611 static ssize_t show_line3(struct device *dev, struct device_attribute *attr,
614 return show_line(dev, buf, LCD_LINE3_OFFSET, LCD_LINE4_OFFSET);
617 /* Writing to /sys/../lineX will set the coresponding LCD line.
618 * - Excess characters are ignored.
619 * - If less characters are written than allowed, the remaining digits are
621 * - The '\n' or '\t' char is a placeholder, it does not overwrite the
624 static ssize_t store_line(struct device *dev, const char *buf, size_t count,
627 struct yealink_dev *yld;
630 down_write(&sysfs_rwsema);
631 yld = dev_get_drvdata(dev);
633 up_write(&sysfs_rwsema);
639 for (i = 0; i < len; i++)
640 setChar(yld, el++, buf[i]);
642 up_write(&sysfs_rwsema);
646 static ssize_t store_line1(struct device *dev, struct device_attribute *attr,
647 const char *buf, size_t count)
649 return store_line(dev, buf, count, LCD_LINE1_OFFSET, LCD_LINE1_SIZE);
652 static ssize_t store_line2(struct device *dev, struct device_attribute *attr,
653 const char *buf, size_t count)
655 return store_line(dev, buf, count, LCD_LINE2_OFFSET, LCD_LINE2_SIZE);
658 static ssize_t store_line3(struct device *dev, struct device_attribute *attr,
659 const char *buf, size_t count)
661 return store_line(dev, buf, count, LCD_LINE3_OFFSET, LCD_LINE3_SIZE);
664 /* Interface to visible and audible "icons", these include:
665 * pictures on the LCD, the LED, and the dialtone signal.
668 /* Get a list of "switchable elements" with their current state. */
669 static ssize_t get_icons(struct device *dev, struct device_attribute *attr,
672 struct yealink_dev *yld;
675 down_read(&sysfs_rwsema);
676 yld = dev_get_drvdata(dev);
678 up_read(&sysfs_rwsema);
682 for (i = 0; i < ARRAY_SIZE(lcdMap); i++) {
683 if (lcdMap[i].type != '.')
685 ret += sprintf(&buf[ret], "%s %s\n",
686 yld->lcdMap[i] == ' ' ? " " : "on",
689 up_read(&sysfs_rwsema);
693 /* Change the visibility of a particular element. */
694 static ssize_t set_icon(struct device *dev, const char *buf, size_t count,
697 struct yealink_dev *yld;
700 down_write(&sysfs_rwsema);
701 yld = dev_get_drvdata(dev);
703 up_write(&sysfs_rwsema);
707 for (i = 0; i < ARRAY_SIZE(lcdMap); i++) {
708 if (lcdMap[i].type != '.')
710 if (strncmp(buf, lcdMap[i].u.p.name, count) == 0) {
711 setChar(yld, i, chr);
716 up_write(&sysfs_rwsema);
720 static ssize_t show_icon(struct device *dev, struct device_attribute *attr,
721 const char *buf, size_t count)
723 return set_icon(dev, buf, count, buf[0]);
726 static ssize_t hide_icon(struct device *dev, struct device_attribute *attr,
727 const char *buf, size_t count)
729 return set_icon(dev, buf, count, ' ');
732 /* Upload a ringtone to the device.
735 /* Stores raw ringtone data in the phone */
736 static ssize_t store_ringtone(struct device *dev,
737 struct device_attribute *attr,
738 const char *buf, size_t count)
740 struct yealink_dev *yld;
742 down_write(&sysfs_rwsema);
743 yld = dev_get_drvdata(dev);
745 up_write(&sysfs_rwsema);
749 /* TODO locking with async usb control interface??? */
750 yealink_set_ringtone(yld, (char *)buf, count);
751 up_write(&sysfs_rwsema);
755 #define _M444 S_IRUGO
756 #define _M664 S_IRUGO|S_IWUSR|S_IWGRP
757 #define _M220 S_IWUSR|S_IWGRP
759 static DEVICE_ATTR(map_seg7 , _M664, show_map , store_map );
760 static DEVICE_ATTR(line1 , _M664, show_line1 , store_line1 );
761 static DEVICE_ATTR(line2 , _M664, show_line2 , store_line2 );
762 static DEVICE_ATTR(line3 , _M664, show_line3 , store_line3 );
763 static DEVICE_ATTR(get_icons , _M444, get_icons , NULL );
764 static DEVICE_ATTR(show_icon , _M220, NULL , show_icon );
765 static DEVICE_ATTR(hide_icon , _M220, NULL , hide_icon );
766 static DEVICE_ATTR(ringtone , _M220, NULL , store_ringtone);
768 static struct attribute *yld_attributes[] = {
769 &dev_attr_line1.attr,
770 &dev_attr_line2.attr,
771 &dev_attr_line3.attr,
772 &dev_attr_get_icons.attr,
773 &dev_attr_show_icon.attr,
774 &dev_attr_hide_icon.attr,
775 &dev_attr_map_seg7.attr,
776 &dev_attr_ringtone.attr,
780 static struct attribute_group yld_attr_group = {
781 .attrs = yld_attributes
784 /*******************************************************************************
785 * Linux interface and usb initialisation
786 ******************************************************************************/
788 static const struct yld_device {
793 { 0x6993, 0xb001, "Yealink usb-p1k" },
796 static struct usb_device_id usb_table [] = {
797 { USB_INTERFACE_INFO(USB_CLASS_HID, 0, 0) },
801 static int usb_cleanup(struct yealink_dev *yld, int err)
807 usb_kill_urb(yld->urb_irq);
808 usb_free_urb(yld->urb_irq);
811 usb_free_urb(yld->urb_ctl);
813 input_unregister_device(&yld->idev);
815 usb_buffer_free(yld->udev, sizeof(*(yld->ctl_req)),
816 yld->ctl_req, yld->ctl_req_dma);
818 usb_buffer_free(yld->udev, USB_PKT_LEN,
819 yld->ctl_data, yld->ctl_dma);
821 usb_buffer_free(yld->udev, USB_PKT_LEN,
822 yld->irq_data, yld->irq_dma);
827 static void usb_disconnect(struct usb_interface *intf)
829 struct yealink_dev *yld;
831 down_write(&sysfs_rwsema);
832 yld = usb_get_intfdata(intf);
833 sysfs_remove_group(&intf->dev.kobj, &yld_attr_group);
834 usb_set_intfdata(intf, NULL);
835 up_write(&sysfs_rwsema);
840 static int usb_match(struct usb_device *udev)
843 u16 idVendor = le16_to_cpu(udev->descriptor.idVendor);
844 u16 idProduct = le16_to_cpu(udev->descriptor.idProduct);
846 for (i = 0; i < ARRAY_SIZE(yld_device); i++) {
847 if ((idVendor == yld_device[i].idVendor) &&
848 (idProduct == yld_device[i].idProduct))
854 static int usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
856 struct usb_device *udev = interface_to_usbdev (intf);
857 struct usb_host_interface *interface;
858 struct usb_endpoint_descriptor *endpoint;
859 struct yealink_dev *yld;
867 interface = intf->cur_altsetting;
868 endpoint = &interface->endpoint[0].desc;
869 if (!(endpoint->bEndpointAddress & 0x80))
871 if ((endpoint->bmAttributes & 3) != 3)
874 if ((yld = kmalloc(sizeof(struct yealink_dev), GFP_KERNEL)) == NULL)
877 memset(yld, 0, sizeof(*yld));
880 /* allocate usb buffers */
881 yld->irq_data = usb_buffer_alloc(udev, USB_PKT_LEN,
882 SLAB_ATOMIC, &yld->irq_dma);
883 if (yld->irq_data == NULL)
884 return usb_cleanup(yld, -ENOMEM);
886 yld->ctl_data = usb_buffer_alloc(udev, USB_PKT_LEN,
887 SLAB_ATOMIC, &yld->ctl_dma);
889 return usb_cleanup(yld, -ENOMEM);
891 yld->ctl_req = usb_buffer_alloc(udev, sizeof(*(yld->ctl_req)),
892 SLAB_ATOMIC, &yld->ctl_req_dma);
893 if (yld->ctl_req == NULL)
894 return usb_cleanup(yld, -ENOMEM);
896 /* allocate urb structures */
897 yld->urb_irq = usb_alloc_urb(0, GFP_KERNEL);
898 if (yld->urb_irq == NULL)
899 return usb_cleanup(yld, -ENOMEM);
901 yld->urb_ctl = usb_alloc_urb(0, GFP_KERNEL);
902 if (yld->urb_ctl == NULL)
903 return usb_cleanup(yld, -ENOMEM);
905 /* get a handle to the interrupt data pipe */
906 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
907 ret = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
908 if (ret != USB_PKT_LEN)
909 err("invalid payload size %d, expected %d", ret, USB_PKT_LEN);
911 /* initialise irq urb */
912 usb_fill_int_urb(yld->urb_irq, udev, pipe, yld->irq_data,
915 yld, endpoint->bInterval);
916 yld->urb_irq->transfer_dma = yld->irq_dma;
917 yld->urb_irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
918 yld->urb_irq->dev = udev;
920 /* initialise ctl urb */
921 yld->ctl_req->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE |
923 yld->ctl_req->bRequest = USB_REQ_SET_CONFIGURATION;
924 yld->ctl_req->wValue = cpu_to_le16(0x200);
925 yld->ctl_req->wIndex = cpu_to_le16(interface->desc.bInterfaceNumber);
926 yld->ctl_req->wLength = cpu_to_le16(USB_PKT_LEN);
928 usb_fill_control_urb(yld->urb_ctl, udev, usb_sndctrlpipe(udev, 0),
929 (void *)yld->ctl_req, yld->ctl_data, USB_PKT_LEN,
930 urb_ctl_callback, yld);
931 yld->urb_ctl->setup_dma = yld->ctl_req_dma;
932 yld->urb_ctl->transfer_dma = yld->ctl_dma;
933 yld->urb_ctl->transfer_flags |= URB_NO_SETUP_DMA_MAP |
934 URB_NO_TRANSFER_DMA_MAP;
935 yld->urb_ctl->dev = udev;
937 /* find out the physical bus location */
938 if (usb_make_path(udev, path, sizeof(path)) > 0)
939 snprintf(yld->phys, sizeof(yld->phys)-1, "%s/input0", path);
941 /* register settings for the input device */
942 init_input_dev(&yld->idev);
943 yld->idev.private = yld;
944 yld->idev.id.bustype = BUS_USB;
945 yld->idev.id.vendor = le16_to_cpu(udev->descriptor.idVendor);
946 yld->idev.id.product = le16_to_cpu(udev->descriptor.idProduct);
947 yld->idev.id.version = le16_to_cpu(udev->descriptor.bcdDevice);
948 yld->idev.dev = &intf->dev;
949 yld->idev.name = yld_device[i].name;
950 yld->idev.phys = yld->phys;
951 /* yld->idev.event = input_ev; TODO */
952 yld->idev.open = input_open;
953 yld->idev.close = input_close;
955 /* register available key events */
956 yld->idev.evbit[0] = BIT(EV_KEY);
957 for (i = 0; i < 256; i++) {
958 int k = map_p1k_to_key(i);
960 set_bit(k & 0xff, yld->idev.keybit);
962 set_bit(k >> 8, yld->idev.keybit);
966 printk(KERN_INFO "input: %s on %s\n", yld->idev.name, path);
968 input_register_device(&yld->idev);
970 usb_set_intfdata(intf, yld);
972 /* clear visible elements */
973 for (i=0; i<ARRAY_SIZE(lcdMap); i++)
974 setChar(yld, i, ' ');
976 /* display driver version on LCD line 3 */
977 store_line3(&intf->dev, NULL,
978 DRIVER_VERSION, sizeof(DRIVER_VERSION));
980 /* Register sysfs hooks (don't care about failure) */
981 sysfs_create_group(&intf->dev.kobj, &yld_attr_group);
985 static struct usb_driver yealink_driver = {
986 .owner = THIS_MODULE,
989 .disconnect = usb_disconnect,
990 .id_table = usb_table,
993 static int __init yealink_dev_init(void)
995 int ret = usb_register(&yealink_driver);
997 info(DRIVER_DESC ":" DRIVER_VERSION);
1001 static void __exit yealink_dev_exit(void)
1003 usb_deregister(&yealink_driver);
1006 module_init(yealink_dev_init);
1007 module_exit(yealink_dev_exit);
1009 MODULE_DEVICE_TABLE (usb, usb_table);
1011 MODULE_AUTHOR(DRIVER_AUTHOR);
1012 MODULE_DESCRIPTION(DRIVER_DESC);
1013 MODULE_LICENSE("GPL");