1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * drivers/usb/input/yealink.c
5 * Copyright (c) 2005 Henk Vergonet <Henk.Vergonet@gmail.com>
9 * Driver for the USB-P1K voip usb phone.
10 * This device is produced by Yealink Network Technology Co Ltd
11 * but may be branded under several names:
16 * This driver is based on:
17 * - the usbb2k-api http://savannah.nongnu.org/projects/usbb2k-api/
18 * - information from http://memeteau.free.fr/usbb2k
19 * - the xpad-driver drivers/input/joystick/xpad.c
22 * - Olivier Vandorpe, for providing the usbb2k-api.
23 * - Martin Diehl, for spotting my memory allocation bug.
26 * 20050527 henk First version, functional keyboard. Keyboard events
27 * will pop-up on the ../input/eventX bus.
28 * 20050531 henk Added led, LCD, dialtone and sysfs interface.
29 * 20050610 henk Cleanups, make it ready for public consumption.
30 * 20050630 henk Cleanups, fixes in response to comments.
31 * 20050701 henk sysfs write serialisation, fix potential unload races
32 * 20050801 henk Added ringtone, restructure USB
33 * 20050816 henk Merge 2.6.13-rc6
36 #include <linux/kernel.h>
37 #include <linux/slab.h>
38 #include <linux/module.h>
39 #include <linux/rwsem.h>
40 #include <linux/usb/input.h>
41 #include <linux/map_to_7segment.h>
45 #define DRIVER_VERSION "yld-20051230"
47 #define YEALINK_POLLING_FREQUENCY 10 /* in [Hz] */
55 } __attribute__ ((packed
));
58 * Register the LCD segment and icon map
60 #define _LOC(k,l) { .a = (k), .m = (l) }
61 #define _SEG(t, a, am, b, bm, c, cm, d, dm, e, em, f, fm, g, gm) \
63 .u = { .s = { _LOC(a, am), _LOC(b, bm), _LOC(c, cm), \
64 _LOC(d, dm), _LOC(e, em), _LOC(g, gm), \
66 #define _PIC(t, h, hm, n) \
68 .u = { .p = { .name = (n), .a = (h), .m = (hm) } } }
70 static const struct lcd_segment_map
{
73 struct pictogram_map
{
86 struct input_dev
*idev
; /* input device */
87 struct usb_device
*udev
; /* usb device */
88 struct usb_interface
*intf
; /* usb interface */
90 /* irq input channel */
91 struct yld_ctl_packet
*irq_data
;
95 /* control output channel */
96 struct yld_ctl_packet
*ctl_data
;
98 struct usb_ctrlrequest
*ctl_req
;
101 char phys
[64]; /* physical device path */
103 u8 lcdMap
[ARRAY_SIZE(lcdMap
)]; /* state of LCD, LED ... */
104 int key_code
; /* last reported key */
106 unsigned int shutdown
:1;
111 u8 b
[sizeof(struct yld_status
)];
116 /*******************************************************************************
117 * Yealink lcd interface
118 ******************************************************************************/
121 * Register a default 7 segment character set
123 static SEG7_DEFAULT_MAP(map_seg7
);
126 * char '\9' and '\n' are placeholders and do not overwrite the original text.
127 * A space will always hide an icon.
129 static int setChar(struct yealink_dev
*yld
, int el
, int chr
)
133 if (el
>= ARRAY_SIZE(lcdMap
))
136 if (chr
== '\t' || chr
== '\n')
139 yld
->lcdMap
[el
] = chr
;
141 if (lcdMap
[el
].type
== '.') {
142 a
= lcdMap
[el
].u
.p
.a
;
143 m
= lcdMap
[el
].u
.p
.m
;
145 yld
->master
.b
[a
] |= m
;
147 yld
->master
.b
[a
] &= ~m
;
151 val
= map_to_seg7(&map_seg7
, chr
);
152 for (i
= 0; i
< ARRAY_SIZE(lcdMap
[0].u
.s
); i
++) {
153 m
= lcdMap
[el
].u
.s
[i
].m
;
158 a
= lcdMap
[el
].u
.s
[i
].a
;
160 yld
->master
.b
[a
] |= m
;
162 yld
->master
.b
[a
] &= ~m
;
168 /*******************************************************************************
169 * Yealink key interface
170 ******************************************************************************/
172 /* Map device buttons to internal key events.
174 * USB-P1K button layout:
186 * The "up" and "down" keys, are symbolised by arrows on the button.
187 * The "pickup" and "hangup" keys are symbolised by a green and red phone
190 static int map_p1k_to_key(int scancode
)
192 switch(scancode
) { /* phone key: */
193 case 0x23: return KEY_LEFT
; /* IN */
194 case 0x33: return KEY_UP
; /* up */
195 case 0x04: return KEY_RIGHT
; /* OUT */
196 case 0x24: return KEY_DOWN
; /* down */
197 case 0x03: return KEY_ENTER
; /* pickup */
198 case 0x14: return KEY_BACKSPACE
; /* C */
199 case 0x13: return KEY_ESC
; /* hangup */
200 case 0x00: return KEY_1
; /* 1 */
201 case 0x01: return KEY_2
; /* 2 */
202 case 0x02: return KEY_3
; /* 3 */
203 case 0x10: return KEY_4
; /* 4 */
204 case 0x11: return KEY_5
; /* 5 */
205 case 0x12: return KEY_6
; /* 6 */
206 case 0x20: return KEY_7
; /* 7 */
207 case 0x21: return KEY_8
; /* 8 */
208 case 0x22: return KEY_9
; /* 9 */
209 case 0x30: return KEY_KPASTERISK
; /* * */
210 case 0x31: return KEY_0
; /* 0 */
211 case 0x32: return KEY_LEFTSHIFT
|
217 /* Completes a request by converting the data into events for the
220 * The key parameter can be cascaded: key2 << 8 | key1
222 static void report_key(struct yealink_dev
*yld
, int key
)
224 struct input_dev
*idev
= yld
->idev
;
226 if (yld
->key_code
>= 0) {
228 input_report_key(idev
, yld
->key_code
& 0xff, 0);
229 if (yld
->key_code
>> 8)
230 input_report_key(idev
, yld
->key_code
>> 8, 0);
236 input_report_key(idev
, key
& 0xff, 1);
238 input_report_key(idev
, key
>> 8, 1);
243 /*******************************************************************************
244 * Yealink usb communication interface
245 ******************************************************************************/
247 static int yealink_cmd(struct yealink_dev
*yld
, struct yld_ctl_packet
*p
)
253 for(i
=0; i
<USB_PKT_LEN
-1; i
++)
256 return usb_control_msg(yld
->udev
,
257 usb_sndctrlpipe(yld
->udev
, 0),
258 USB_REQ_SET_CONFIGURATION
,
259 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| USB_DIR_OUT
,
262 USB_CTRL_SET_TIMEOUT
);
265 static u8 default_ringtone
[] = {
266 0xEF, /* volume [0-255] */
267 0xFB, 0x1E, 0x00, 0x0C, /* 1250 [hz], 12/100 [s] */
268 0xFC, 0x18, 0x00, 0x0C, /* 1000 [hz], 12/100 [s] */
269 0xFB, 0x1E, 0x00, 0x0C,
270 0xFC, 0x18, 0x00, 0x0C,
271 0xFB, 0x1E, 0x00, 0x0C,
272 0xFC, 0x18, 0x00, 0x0C,
273 0xFB, 0x1E, 0x00, 0x0C,
274 0xFC, 0x18, 0x00, 0x0C,
275 0xFF, 0xFF, 0x01, 0x90, /* silent, 400/100 [s] */
276 0x00, 0x00 /* end of sequence */
279 static int yealink_set_ringtone(struct yealink_dev
*yld
, u8
*buf
, size_t size
)
281 struct yld_ctl_packet
*p
= yld
->ctl_data
;
287 /* Set the ringtone volume */
288 memset(yld
->ctl_data
, 0, sizeof(*(yld
->ctl_data
)));
289 yld
->ctl_data
->cmd
= CMD_RING_VOLUME
;
290 yld
->ctl_data
->size
= 1;
291 yld
->ctl_data
->data
[0] = buf
[0];
297 p
->cmd
= CMD_RING_NOTE
;
301 if (len
> sizeof(p
->data
))
302 len
= sizeof(p
->data
);
304 p
->offset
= cpu_to_be16(ix
);
305 memcpy(p
->data
, &buf
[ix
], len
);
312 /* keep stat_master & stat_copy in sync.
314 static int yealink_do_idle_tasks(struct yealink_dev
*yld
)
321 memset(yld
->ctl_data
, 0, sizeof(*(yld
->ctl_data
)));
322 yld
->ctl_data
->cmd
= CMD_KEYPRESS
;
323 yld
->ctl_data
->size
= 1;
324 yld
->ctl_data
->sum
= 0xff - CMD_KEYPRESS
;
326 /* If state update pointer wraps do a KEYPRESS first. */
327 if (ix
>= sizeof(yld
->master
)) {
332 /* find update candidates: copy != master */
334 val
= yld
->master
.b
[ix
];
335 if (val
!= yld
->copy
.b
[ix
])
337 } while (++ix
< sizeof(yld
->master
));
339 /* nothing todo, wait a bit and poll for a KEYPRESS */
341 /* TODO how can we wait abit. ??
342 * msleep_interruptible(1000 / YEALINK_POLLING_FREQUENCY);
348 /* Setup an appropriate update request */
349 yld
->copy
.b
[ix
] = val
;
350 yld
->ctl_data
->data
[0] = val
;
353 case offsetof(struct yld_status
, led
):
354 yld
->ctl_data
->cmd
= CMD_LED
;
355 yld
->ctl_data
->sum
= -1 - CMD_LED
- val
;
357 case offsetof(struct yld_status
, dialtone
):
358 yld
->ctl_data
->cmd
= CMD_DIALTONE
;
359 yld
->ctl_data
->sum
= -1 - CMD_DIALTONE
- val
;
361 case offsetof(struct yld_status
, ringtone
):
362 yld
->ctl_data
->cmd
= CMD_RINGTONE
;
363 yld
->ctl_data
->sum
= -1 - CMD_RINGTONE
- val
;
365 case offsetof(struct yld_status
, keynum
):
368 yld
->ctl_data
->cmd
= CMD_SCANCODE
;
369 yld
->ctl_data
->offset
= cpu_to_be16(val
);
370 yld
->ctl_data
->data
[0] = 0;
371 yld
->ctl_data
->sum
= -1 - CMD_SCANCODE
- val
;
374 len
= sizeof(yld
->master
.s
.lcd
) - ix
;
375 if (len
> sizeof(yld
->ctl_data
->data
))
376 len
= sizeof(yld
->ctl_data
->data
);
378 /* Combine up to <len> consecutive LCD bytes in a singe request
380 yld
->ctl_data
->cmd
= CMD_LCD
;
381 yld
->ctl_data
->offset
= cpu_to_be16(ix
);
382 yld
->ctl_data
->size
= len
;
383 yld
->ctl_data
->sum
= -CMD_LCD
- ix
- val
- len
;
384 for(i
=1; i
<len
; i
++) {
386 val
= yld
->master
.b
[ix
];
387 yld
->copy
.b
[ix
] = val
;
388 yld
->ctl_data
->data
[i
] = val
;
389 yld
->ctl_data
->sum
-= val
;
392 yld
->stat_ix
= ix
+ 1;
396 /* Decide on how to handle responses
398 * The state transition diagram is somethhing like:
404 * init --ok--> waitForKey --ok--> getKey
406 * | +-------ok-------+
410 static void urb_irq_callback(struct urb
*urb
)
412 struct yealink_dev
*yld
= urb
->context
;
413 int ret
, status
= urb
->status
;
416 dev_err(&yld
->intf
->dev
, "%s - urb status %d\n",
419 switch (yld
->irq_data
->cmd
) {
422 yld
->master
.s
.keynum
= yld
->irq_data
->data
[0];
426 dev_dbg(&yld
->intf
->dev
, "get scancode %x\n",
427 yld
->irq_data
->data
[0]);
429 report_key(yld
, map_p1k_to_key(yld
->irq_data
->data
[0]));
433 dev_err(&yld
->intf
->dev
, "unexpected response %x\n",
437 yealink_do_idle_tasks(yld
);
439 if (!yld
->shutdown
) {
440 ret
= usb_submit_urb(yld
->urb_ctl
, GFP_ATOMIC
);
441 if (ret
&& ret
!= -EPERM
)
442 dev_err(&yld
->intf
->dev
,
443 "%s - usb_submit_urb failed %d\n",
448 static void urb_ctl_callback(struct urb
*urb
)
450 struct yealink_dev
*yld
= urb
->context
;
451 int ret
= 0, status
= urb
->status
;
454 dev_err(&yld
->intf
->dev
, "%s - urb status %d\n",
457 switch (yld
->ctl_data
->cmd
) {
460 /* ask for a response */
462 ret
= usb_submit_urb(yld
->urb_irq
, GFP_ATOMIC
);
465 /* send new command */
466 yealink_do_idle_tasks(yld
);
468 ret
= usb_submit_urb(yld
->urb_ctl
, GFP_ATOMIC
);
472 if (ret
&& ret
!= -EPERM
)
473 dev_err(&yld
->intf
->dev
, "%s - usb_submit_urb failed %d\n",
477 /*******************************************************************************
478 * input event interface
479 ******************************************************************************/
481 /* TODO should we issue a ringtone on a SND_BELL event?
482 static int input_ev(struct input_dev *dev, unsigned int type,
483 unsigned int code, int value)
501 static int input_open(struct input_dev
*dev
)
503 struct yealink_dev
*yld
= input_get_drvdata(dev
);
506 dev_dbg(&yld
->intf
->dev
, "%s\n", __func__
);
508 /* force updates to device */
509 for (i
= 0; i
<sizeof(yld
->master
); i
++)
510 yld
->copy
.b
[i
] = ~yld
->master
.b
[i
];
511 yld
->key_code
= -1; /* no keys pressed */
513 yealink_set_ringtone(yld
, default_ringtone
, sizeof(default_ringtone
));
516 memset(yld
->ctl_data
, 0, sizeof(*(yld
->ctl_data
)));
517 yld
->ctl_data
->cmd
= CMD_INIT
;
518 yld
->ctl_data
->size
= 10;
519 yld
->ctl_data
->sum
= 0x100-CMD_INIT
-10;
520 if ((ret
= usb_submit_urb(yld
->urb_ctl
, GFP_KERNEL
)) != 0) {
521 dev_dbg(&yld
->intf
->dev
,
522 "%s - usb_submit_urb failed with result %d\n",
529 static void input_close(struct input_dev
*dev
)
531 struct yealink_dev
*yld
= input_get_drvdata(dev
);
535 * Make sure the flag is seen by other CPUs before we start
536 * killing URBs so new URBs won't be submitted
540 usb_kill_urb(yld
->urb_ctl
);
541 usb_kill_urb(yld
->urb_irq
);
547 /*******************************************************************************
549 ******************************************************************************/
551 static DECLARE_RWSEM(sysfs_rwsema
);
553 /* Interface to the 7-segments translation table aka. char set.
555 static ssize_t
show_map(struct device
*dev
, struct device_attribute
*attr
,
558 memcpy(buf
, &map_seg7
, sizeof(map_seg7
));
559 return sizeof(map_seg7
);
562 static ssize_t
store_map(struct device
*dev
, struct device_attribute
*attr
,
563 const char *buf
, size_t cnt
)
565 if (cnt
!= sizeof(map_seg7
))
567 memcpy(&map_seg7
, buf
, sizeof(map_seg7
));
568 return sizeof(map_seg7
);
571 /* Interface to the LCD.
574 /* Reading /sys/../lineX will return the format string with its settings:
581 static ssize_t
show_line(struct device
*dev
, char *buf
, int a
, int b
)
583 struct yealink_dev
*yld
;
586 down_read(&sysfs_rwsema
);
587 yld
= dev_get_drvdata(dev
);
589 up_read(&sysfs_rwsema
);
593 for (i
= a
; i
< b
; i
++)
594 *buf
++ = lcdMap
[i
].type
;
596 for (i
= a
; i
< b
; i
++)
597 *buf
++ = yld
->lcdMap
[i
];
601 up_read(&sysfs_rwsema
);
602 return 3 + ((b
- a
) << 1);
605 static ssize_t
show_line1(struct device
*dev
, struct device_attribute
*attr
,
608 return show_line(dev
, buf
, LCD_LINE1_OFFSET
, LCD_LINE2_OFFSET
);
611 static ssize_t
show_line2(struct device
*dev
, struct device_attribute
*attr
,
614 return show_line(dev
, buf
, LCD_LINE2_OFFSET
, LCD_LINE3_OFFSET
);
617 static ssize_t
show_line3(struct device
*dev
, struct device_attribute
*attr
,
620 return show_line(dev
, buf
, LCD_LINE3_OFFSET
, LCD_LINE4_OFFSET
);
623 /* Writing to /sys/../lineX will set the coresponding LCD line.
624 * - Excess characters are ignored.
625 * - If less characters are written than allowed, the remaining digits are
627 * - The '\n' or '\t' char is a placeholder, it does not overwrite the
630 static ssize_t
store_line(struct device
*dev
, const char *buf
, size_t count
,
633 struct yealink_dev
*yld
;
636 down_write(&sysfs_rwsema
);
637 yld
= dev_get_drvdata(dev
);
639 up_write(&sysfs_rwsema
);
645 for (i
= 0; i
< len
; i
++)
646 setChar(yld
, el
++, buf
[i
]);
648 up_write(&sysfs_rwsema
);
652 static ssize_t
store_line1(struct device
*dev
, struct device_attribute
*attr
,
653 const char *buf
, size_t count
)
655 return store_line(dev
, buf
, count
, LCD_LINE1_OFFSET
, LCD_LINE1_SIZE
);
658 static ssize_t
store_line2(struct device
*dev
, struct device_attribute
*attr
,
659 const char *buf
, size_t count
)
661 return store_line(dev
, buf
, count
, LCD_LINE2_OFFSET
, LCD_LINE2_SIZE
);
664 static ssize_t
store_line3(struct device
*dev
, struct device_attribute
*attr
,
665 const char *buf
, size_t count
)
667 return store_line(dev
, buf
, count
, LCD_LINE3_OFFSET
, LCD_LINE3_SIZE
);
670 /* Interface to visible and audible "icons", these include:
671 * pictures on the LCD, the LED, and the dialtone signal.
674 /* Get a list of "switchable elements" with their current state. */
675 static ssize_t
get_icons(struct device
*dev
, struct device_attribute
*attr
,
678 struct yealink_dev
*yld
;
681 down_read(&sysfs_rwsema
);
682 yld
= dev_get_drvdata(dev
);
684 up_read(&sysfs_rwsema
);
688 for (i
= 0; i
< ARRAY_SIZE(lcdMap
); i
++) {
689 if (lcdMap
[i
].type
!= '.')
691 ret
+= sprintf(&buf
[ret
], "%s %s\n",
692 yld
->lcdMap
[i
] == ' ' ? " " : "on",
695 up_read(&sysfs_rwsema
);
699 /* Change the visibility of a particular element. */
700 static ssize_t
set_icon(struct device
*dev
, const char *buf
, size_t count
,
703 struct yealink_dev
*yld
;
706 down_write(&sysfs_rwsema
);
707 yld
= dev_get_drvdata(dev
);
709 up_write(&sysfs_rwsema
);
713 for (i
= 0; i
< ARRAY_SIZE(lcdMap
); i
++) {
714 if (lcdMap
[i
].type
!= '.')
716 if (strncmp(buf
, lcdMap
[i
].u
.p
.name
, count
) == 0) {
717 setChar(yld
, i
, chr
);
722 up_write(&sysfs_rwsema
);
726 static ssize_t
show_icon(struct device
*dev
, struct device_attribute
*attr
,
727 const char *buf
, size_t count
)
729 return set_icon(dev
, buf
, count
, buf
[0]);
732 static ssize_t
hide_icon(struct device
*dev
, struct device_attribute
*attr
,
733 const char *buf
, size_t count
)
735 return set_icon(dev
, buf
, count
, ' ');
738 /* Upload a ringtone to the device.
741 /* Stores raw ringtone data in the phone */
742 static ssize_t
store_ringtone(struct device
*dev
,
743 struct device_attribute
*attr
,
744 const char *buf
, size_t count
)
746 struct yealink_dev
*yld
;
748 down_write(&sysfs_rwsema
);
749 yld
= dev_get_drvdata(dev
);
751 up_write(&sysfs_rwsema
);
755 /* TODO locking with async usb control interface??? */
756 yealink_set_ringtone(yld
, (char *)buf
, count
);
757 up_write(&sysfs_rwsema
);
761 #define _M444 S_IRUGO
762 #define _M664 S_IRUGO|S_IWUSR|S_IWGRP
763 #define _M220 S_IWUSR|S_IWGRP
765 static DEVICE_ATTR(map_seg7
, _M664
, show_map
, store_map
);
766 static DEVICE_ATTR(line1
, _M664
, show_line1
, store_line1
);
767 static DEVICE_ATTR(line2
, _M664
, show_line2
, store_line2
);
768 static DEVICE_ATTR(line3
, _M664
, show_line3
, store_line3
);
769 static DEVICE_ATTR(get_icons
, _M444
, get_icons
, NULL
);
770 static DEVICE_ATTR(show_icon
, _M220
, NULL
, show_icon
);
771 static DEVICE_ATTR(hide_icon
, _M220
, NULL
, hide_icon
);
772 static DEVICE_ATTR(ringtone
, _M220
, NULL
, store_ringtone
);
774 static struct attribute
*yld_attributes
[] = {
775 &dev_attr_line1
.attr
,
776 &dev_attr_line2
.attr
,
777 &dev_attr_line3
.attr
,
778 &dev_attr_get_icons
.attr
,
779 &dev_attr_show_icon
.attr
,
780 &dev_attr_hide_icon
.attr
,
781 &dev_attr_map_seg7
.attr
,
782 &dev_attr_ringtone
.attr
,
786 static const struct attribute_group yld_attr_group
= {
787 .attrs
= yld_attributes
790 /*******************************************************************************
791 * Linux interface and usb initialisation
792 ******************************************************************************/
798 static const struct driver_info info_P1K
= {
799 .name
= "Yealink usb-p1k",
802 static const struct usb_device_id usb_table
[] = {
804 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
|
805 USB_DEVICE_ID_MATCH_INT_INFO
,
808 .bInterfaceClass
= USB_CLASS_HID
,
809 .bInterfaceSubClass
= 0,
810 .bInterfaceProtocol
= 0,
811 .driver_info
= (kernel_ulong_t
)&info_P1K
816 static int usb_cleanup(struct yealink_dev
*yld
, int err
)
823 input_free_device(yld
->idev
);
825 input_unregister_device(yld
->idev
);
828 usb_free_urb(yld
->urb_irq
);
829 usb_free_urb(yld
->urb_ctl
);
832 usb_free_coherent(yld
->udev
, USB_PKT_LEN
, yld
->ctl_data
, yld
->ctl_dma
);
833 usb_free_coherent(yld
->udev
, USB_PKT_LEN
, yld
->irq_data
, yld
->irq_dma
);
839 static void usb_disconnect(struct usb_interface
*intf
)
841 struct yealink_dev
*yld
;
843 down_write(&sysfs_rwsema
);
844 yld
= usb_get_intfdata(intf
);
845 sysfs_remove_group(&intf
->dev
.kobj
, &yld_attr_group
);
846 usb_set_intfdata(intf
, NULL
);
847 up_write(&sysfs_rwsema
);
852 static int usb_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
854 struct usb_device
*udev
= interface_to_usbdev (intf
);
855 struct driver_info
*nfo
= (struct driver_info
*)id
->driver_info
;
856 struct usb_host_interface
*interface
;
857 struct usb_endpoint_descriptor
*endpoint
;
858 struct yealink_dev
*yld
;
859 struct input_dev
*input_dev
;
862 interface
= intf
->cur_altsetting
;
864 if (interface
->desc
.bNumEndpoints
< 1)
867 endpoint
= &interface
->endpoint
[0].desc
;
868 if (!usb_endpoint_is_int_in(endpoint
))
871 yld
= kzalloc(sizeof(struct yealink_dev
), GFP_KERNEL
);
878 yld
->idev
= input_dev
= input_allocate_device();
880 return usb_cleanup(yld
, -ENOMEM
);
882 /* allocate usb buffers */
883 yld
->irq_data
= usb_alloc_coherent(udev
, USB_PKT_LEN
,
884 GFP_KERNEL
, &yld
->irq_dma
);
885 if (yld
->irq_data
== NULL
)
886 return usb_cleanup(yld
, -ENOMEM
);
888 yld
->ctl_data
= usb_alloc_coherent(udev
, USB_PKT_LEN
,
889 GFP_KERNEL
, &yld
->ctl_dma
);
891 return usb_cleanup(yld
, -ENOMEM
);
893 yld
->ctl_req
= kmalloc(sizeof(*(yld
->ctl_req
)), GFP_KERNEL
);
894 if (yld
->ctl_req
== NULL
)
895 return usb_cleanup(yld
, -ENOMEM
);
897 /* allocate urb structures */
898 yld
->urb_irq
= usb_alloc_urb(0, GFP_KERNEL
);
899 if (yld
->urb_irq
== NULL
)
900 return usb_cleanup(yld
, -ENOMEM
);
902 yld
->urb_ctl
= usb_alloc_urb(0, GFP_KERNEL
);
903 if (yld
->urb_ctl
== NULL
)
904 return usb_cleanup(yld
, -ENOMEM
);
906 /* get a handle to the interrupt data pipe */
907 pipe
= usb_rcvintpipe(udev
, endpoint
->bEndpointAddress
);
908 ret
= usb_maxpacket(udev
, pipe
, usb_pipeout(pipe
));
909 if (ret
!= USB_PKT_LEN
)
910 dev_err(&intf
->dev
, "invalid payload size %d, expected %zd\n",
913 /* initialise irq urb */
914 usb_fill_int_urb(yld
->urb_irq
, udev
, pipe
, yld
->irq_data
,
917 yld
, endpoint
->bInterval
);
918 yld
->urb_irq
->transfer_dma
= yld
->irq_dma
;
919 yld
->urb_irq
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
920 yld
->urb_irq
->dev
= udev
;
922 /* initialise ctl urb */
923 yld
->ctl_req
->bRequestType
= USB_TYPE_CLASS
| USB_RECIP_INTERFACE
|
925 yld
->ctl_req
->bRequest
= USB_REQ_SET_CONFIGURATION
;
926 yld
->ctl_req
->wValue
= cpu_to_le16(0x200);
927 yld
->ctl_req
->wIndex
= cpu_to_le16(interface
->desc
.bInterfaceNumber
);
928 yld
->ctl_req
->wLength
= cpu_to_le16(USB_PKT_LEN
);
930 usb_fill_control_urb(yld
->urb_ctl
, udev
, usb_sndctrlpipe(udev
, 0),
931 (void *)yld
->ctl_req
, yld
->ctl_data
, USB_PKT_LEN
,
932 urb_ctl_callback
, yld
);
933 yld
->urb_ctl
->transfer_dma
= yld
->ctl_dma
;
934 yld
->urb_ctl
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
935 yld
->urb_ctl
->dev
= udev
;
937 /* find out the physical bus location */
938 usb_make_path(udev
, yld
->phys
, sizeof(yld
->phys
));
939 strlcat(yld
->phys
, "/input0", sizeof(yld
->phys
));
941 /* register settings for the input device */
942 input_dev
->name
= nfo
->name
;
943 input_dev
->phys
= yld
->phys
;
944 usb_to_input_id(udev
, &input_dev
->id
);
945 input_dev
->dev
.parent
= &intf
->dev
;
947 input_set_drvdata(input_dev
, yld
);
949 input_dev
->open
= input_open
;
950 input_dev
->close
= input_close
;
951 /* input_dev->event = input_ev; TODO */
953 /* register available key events */
954 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
);
955 for (i
= 0; i
< 256; i
++) {
956 int k
= map_p1k_to_key(i
);
958 set_bit(k
& 0xff, input_dev
->keybit
);
960 set_bit(k
>> 8, input_dev
->keybit
);
964 ret
= input_register_device(yld
->idev
);
966 return usb_cleanup(yld
, ret
);
968 usb_set_intfdata(intf
, yld
);
970 /* clear visible elements */
971 for (i
= 0; i
< ARRAY_SIZE(lcdMap
); i
++)
972 setChar(yld
, i
, ' ');
974 /* display driver version on LCD line 3 */
975 store_line3(&intf
->dev
, NULL
,
976 DRIVER_VERSION
, sizeof(DRIVER_VERSION
));
978 /* Register sysfs hooks (don't care about failure) */
979 ret
= sysfs_create_group(&intf
->dev
.kobj
, &yld_attr_group
);
983 static struct usb_driver yealink_driver
= {
986 .disconnect
= usb_disconnect
,
987 .id_table
= usb_table
,
990 module_usb_driver(yealink_driver
);
992 MODULE_DEVICE_TABLE (usb
, usb_table
);
994 MODULE_AUTHOR("Henk Vergonet");
995 MODULE_DESCRIPTION("Yealink phone driver");
996 MODULE_LICENSE("GPL");