49 #include <linux/kernel.h>
51 #include <linux/slab.h>
52 #include <linux/module.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
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 {
152 if (chr ==
'\t' || chr ==
'\n')
157 if (lcdMap[el].
type ==
'.') {
158 a = lcdMap[
el].u.p.a;
159 m = lcdMap[
el].u.p.m;
167 val = map_to_seg7(&map_seg7, chr);
169 m = lcdMap[
el].u.s[
i].m;
174 a = lcdMap[
el].u.s[
i].a;
206 static int map_p1k_to_key(
int scancode)
216 case 0x00:
return KEY_1;
217 case 0x01:
return KEY_2;
218 case 0x02:
return KEY_3;
219 case 0x10:
return KEY_4;
220 case 0x11:
return KEY_5;
221 case 0x12:
return KEY_6;
222 case 0x20:
return KEY_7;
223 case 0x21:
return KEY_8;
224 case 0x22:
return KEY_9;
226 case 0x31:
return KEY_0;
244 input_report_key(idev, yld->
key_code & 0xff, 0);
246 input_report_key(idev, yld->
key_code >> 8, 0);
252 input_report_key(idev, key & 0xff, 1);
254 input_report_key(idev, key >> 8, 1);
273 usb_sndctrlpipe(yld->
udev, 0),
278 USB_CTRL_SET_TIMEOUT);
281 static u8 default_ringtone[] = {
283 0xFB, 0x1E, 0x00, 0x0C,
284 0xFC, 0x18, 0x00, 0x0C,
285 0xFB, 0x1E, 0x00, 0x0C,
286 0xFC, 0x18, 0x00, 0x0C,
287 0xFB, 0x1E, 0x00, 0x0C,
288 0xFC, 0x18, 0x00, 0x0C,
289 0xFB, 0x1E, 0x00, 0x0C,
290 0xFC, 0x18, 0x00, 0x0C,
291 0xFF, 0xFF, 0x01, 0x90,
317 if (len >
sizeof(p->
data))
318 len =
sizeof(p->
data);
330 static int yealink_do_idle_tasks(
struct yealink_dev *yld)
343 if (ix >=
sizeof(yld->
master)) {
351 if (val != yld->
copy.
b[ix])
353 }
while (++ix <
sizeof(yld->
master));
390 len =
sizeof(yld->
master.
s.lcd) - ix;
391 if (len >
sizeof(yld->
ctl_data->data))
400 for(i=1; i<len; i++) {
426 static void urb_irq_callback(
struct urb *
urb)
445 report_key(yld, map_p1k_to_key(yld->
irq_data->data[0]));
449 dev_err(&yld->
intf->dev,
"unexpected response %x\n",
453 yealink_do_idle_tasks(yld);
457 if (ret && ret != -
EPERM)
459 "%s - usb_submit_urb failed %d\n",
464 static void urb_ctl_callback(
struct urb *urb)
467 int ret = 0, status = urb->status;
482 yealink_do_idle_tasks(yld);
488 if (ret && ret != -
EPERM)
489 dev_err(&yld->
intf->dev,
"%s - usb_submit_urb failed %d\n",
517 static int input_open(
struct input_dev *
dev)
525 for (i = 0; i<
sizeof(yld->
master); i++)
529 yealink_set_ringtone(yld, default_ringtone,
sizeof(default_ringtone));
538 "%s - usb_submit_urb failed with result %d\n",
545 static void input_close(
struct input_dev *dev)
574 memcpy(buf, &map_seg7,
sizeof(map_seg7));
575 return sizeof(map_seg7);
579 const char *buf,
size_t cnt)
581 if (cnt !=
sizeof(map_seg7))
583 memcpy(&map_seg7, buf,
sizeof(map_seg7));
584 return sizeof(map_seg7);
597 static ssize_t show_line(
struct device *dev,
char *buf,
int a,
int b)
609 for (i = a; i <
b; i++)
612 for (i = a; i <
b; i++)
618 return 3 + ((b -
a) << 1);
624 return show_line(dev, buf, LCD_LINE1_OFFSET, LCD_LINE2_OFFSET);
630 return show_line(dev, buf, LCD_LINE2_OFFSET, LCD_LINE3_OFFSET);
636 return show_line(dev, buf, LCD_LINE3_OFFSET, LCD_LINE4_OFFSET);
661 for (i = 0; i < len; i++)
662 setChar(yld, el++, buf[i]);
669 const char *buf,
size_t count)
671 return store_line(dev, buf, count, LCD_LINE1_OFFSET, LCD_LINE1_SIZE);
675 const char *buf,
size_t count)
677 return store_line(dev, buf, count, LCD_LINE2_OFFSET, LCD_LINE2_SIZE);
681 const char *buf,
size_t count)
683 return store_line(dev, buf, count, LCD_LINE3_OFFSET, LCD_LINE3_SIZE);
707 ret +=
sprintf(&buf[ret],
"%s %s\n",
708 yld->
lcdMap[i] ==
' ' ?
" " :
"on",
716 static ssize_t set_icon(
struct device *dev,
const char *buf,
size_t count,
733 setChar(yld, i, chr);
743 const char *buf,
size_t count)
745 return set_icon(dev, buf, count, buf[0]);
749 const char *buf,
size_t count)
751 return set_icon(dev, buf, count,
' ');
760 const char *buf,
size_t count)
772 yealink_set_ringtone(yld, (
char *)buf, count);
777 #define _M444 S_IRUGO
778 #define _M664 S_IRUGO|S_IWUSR|S_IWGRP
779 #define _M220 S_IWUSR|S_IWGRP
790 static struct attribute *yld_attributes[] = {
791 &dev_attr_line1.attr,
792 &dev_attr_line2.attr,
793 &dev_attr_line3.attr,
794 &dev_attr_get_icons.attr,
795 &dev_attr_show_icon.attr,
796 &dev_attr_hide_icon.attr,
797 &dev_attr_map_seg7.attr,
798 &dev_attr_ringtone.attr,
803 .attrs = yld_attributes
815 .name =
"Yealink usb-p1k",
820 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
821 USB_DEVICE_ID_MATCH_INT_INFO,
825 .bInterfaceSubClass = 0,
826 .bInterfaceProtocol = 0,
839 input_free_device(yld->
idev);
841 input_unregister_device(yld->
idev);
860 yld = usb_get_intfdata(intf);
862 usb_set_intfdata(intf,
NULL);
870 struct usb_device *
udev = interface_to_usbdev (intf);
875 struct input_dev *input_dev;
890 yld->
idev = input_dev = input_allocate_device();
892 return usb_cleanup(yld, -
ENOMEM);
898 return usb_cleanup(yld, -
ENOMEM);
903 return usb_cleanup(yld, -
ENOMEM);
907 return usb_cleanup(yld, -
ENOMEM);
912 return usb_cleanup(yld, -
ENOMEM);
916 return usb_cleanup(yld, -
ENOMEM);
919 pipe = usb_rcvintpipe(udev,
endpoint->bEndpointAddress);
920 ret = usb_maxpacket(udev,
pipe, usb_pipeout(
pipe));
921 if (ret != USB_PKT_LEN)
922 dev_err(&intf->dev,
"invalid payload size %d, expected %zd\n",
931 yld->
urb_irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
942 usb_fill_control_urb(yld->
urb_ctl, udev, usb_sndctrlpipe(udev, 0),
944 urb_ctl_callback, yld);
946 yld->
urb_ctl->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
950 usb_make_path(udev, yld->
phys,
sizeof(yld->
phys));
954 input_dev->name = nfo->
name;
955 input_dev->phys = yld->
phys;
956 usb_to_input_id(udev, &input_dev->id);
957 input_dev->dev.parent = &intf->dev;
959 input_set_drvdata(input_dev, yld);
961 input_dev->open = input_open;
962 input_dev->close = input_close;
967 for (i = 0; i < 256; i++) {
968 int k = map_p1k_to_key(i);
970 set_bit(k & 0xff, input_dev->keybit);
972 set_bit(k >> 8, input_dev->keybit);
976 ret = input_register_device(yld->
idev);
978 return usb_cleanup(yld, ret);
980 usb_set_intfdata(intf, yld);
984 setChar(yld, i,
' ');
987 store_line3(&intf->dev,
NULL,
995 static struct usb_driver yealink_driver = {
999 .id_table = usb_table,