31 #include <linux/kernel.h>
33 #include <linux/slab.h>
34 #include <linux/module.h>
39 #define DRIVER_VERSION "20080805"
40 #define DRIVER_AUTHOR "Alfred E. Heggestad"
41 #define DRIVER_DESC "CM109 phone driver"
43 static char *
phone =
"kip1000";
138 static unsigned short special_keymap(
int code)
141 switch (code - 0xff) {
175 static unsigned short keymap_kip1000(
int scancode)
194 default:
return special_keymap(scancode);
208 static unsigned short keymap_gtalk(
int scancode)
227 default:
return special_keymap(scancode);
237 static unsigned short keymap_usbph01(
int scancode)
256 default:
return special_keymap(scancode);
268 static unsigned short keymap_atcom(
int scancode)
287 default:
return special_keymap(scancode);
291 static unsigned short (*keymap)(
int) = keymap_kip1000;
303 input_report_key(idev, dev->
key_code, 0);
309 input_report_key(idev, key, 1);
319 static void cm109_submit_buzz_toggle(
struct cm109_dev *dev)
331 "%s: usb_submit_urb (urb_ctl) failed %d\n",
338 static void cm109_urb_irq_callback(
struct urb *
urb)
341 const int status = urb->status;
344 dev_dbg(&dev->
intf->dev,
"### URB IRQ: [0x%02x 0x%02x 0x%02x 0x%02x] keybit=0x%02x\n",
354 dev_err(&dev->
intf->dev,
"%s: urb status %d\n", __func__, status);
360 report_key(dev, dev->
keymap[0xff + code]);
402 "%s: usb_submit_urb (urb_ctl) failed %d\n",
409 static void cm109_urb_ctl_callback(
struct urb *urb)
412 const int status = urb->status;
415 dev_dbg(&dev->
intf->dev,
"### URB CTL: [0x%02x 0x%02x 0x%02x 0x%02x]\n",
422 dev_err(&dev->
intf->dev,
"%s: urb status %d\n", __func__, status);
433 cm109_submit_buzz_toggle(dev);
440 "%s: usb_submit_urb (urb_irq) failed %d\n",
448 static void cm109_toggle_buzzer_async(
struct cm109_dev *dev)
459 cm109_submit_buzz_toggle(dev);
465 static void cm109_toggle_buzzer_sync(
struct cm109_dev *dev,
int on)
475 usb_sndctrlpipe(dev->
udev, 0),
482 if (error < 0 && error != -
EINTR)
483 dev_err(&dev->
intf->dev,
"%s: usb_control_msg() failed %d\n",
487 static void cm109_stop_traffic(
struct cm109_dev *dev)
498 cm109_toggle_buzzer_sync(dev, 0);
504 static void cm109_restore_state(
struct cm109_dev *dev)
511 cm109_toggle_buzzer_async(dev);
519 static int cm109_input_open(
struct input_dev *idev)
521 struct cm109_dev *dev = input_get_drvdata(idev);
524 error = usb_autopm_get_interface(dev->
intf);
526 dev_err(&idev->dev,
"%s - cannot autoresume, result %d\n",
545 dev_err(&dev->
intf->dev,
"%s: usb_submit_urb (urb_ctl) failed %d\n",
553 usb_autopm_put_interface(dev->
intf);
558 static void cm109_input_close(
struct input_dev *idev)
560 struct cm109_dev *dev = input_get_drvdata(idev);
569 cm109_stop_traffic(dev);
574 usb_autopm_put_interface(dev->
intf);
577 static int cm109_input_ev(
struct input_dev *idev,
unsigned int type,
580 struct cm109_dev *dev = input_get_drvdata(idev);
583 "input_ev: type=%u code=%u value=%d\n", type, code, value);
593 cm109_toggle_buzzer_async(dev);
611 .name =
"CM109 USB driver",
622 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
623 USB_DEVICE_ID_MATCH_INT_INFO,
627 .bInterfaceSubClass = 0,
628 .bInterfaceProtocol = 0,
635 static void cm109_usb_cleanup(
struct cm109_dev *dev)
652 struct cm109_dev *dev = usb_get_intfdata(interface);
654 usb_set_intfdata(interface,
NULL);
655 input_unregister_device(dev->
idev);
656 cm109_usb_cleanup(dev);
662 struct usb_device *
udev = interface_to_usbdev(intf);
667 struct input_dev *input_dev =
NULL;
687 dev->
idev = input_dev = input_allocate_device();
716 pipe = usb_rcvintpipe(udev,
endpoint->bEndpointAddress);
717 ret = usb_maxpacket(udev,
pipe, usb_pipeout(
pipe));
719 dev_err(&intf->dev,
"invalid payload size %d, expected %d\n",
725 cm109_urb_irq_callback, dev,
endpoint->bInterval);
727 dev->
urb_irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
738 usb_fill_control_urb(dev->
urb_ctl, udev, usb_sndctrlpipe(udev, 0),
740 cm109_urb_ctl_callback, dev);
742 dev->
urb_ctl->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
746 usb_make_path(udev, dev->
phys,
sizeof(dev->
phys));
750 input_dev->name = nfo->
name;
751 input_dev->phys = dev->
phys;
752 usb_to_input_id(udev, &input_dev->id);
753 input_dev->dev.parent = &intf->dev;
755 input_set_drvdata(input_dev, dev);
756 input_dev->open = cm109_input_open;
757 input_dev->close = cm109_input_close;
758 input_dev->event = cm109_input_ev;
760 input_dev->keycode = dev->
keymap;
761 input_dev->keycodesize =
sizeof(
unsigned char);
769 unsigned short k = keymap(
i);
775 error = input_register_device(dev->
idev);
779 usb_set_intfdata(intf, dev);
784 input_free_device(input_dev);
785 cm109_usb_cleanup(dev);
791 struct cm109_dev *dev = usb_get_intfdata(intf);
793 dev_info(&intf->dev,
"cm109: usb_suspend (event=%d)\n", message.
event);
796 cm109_stop_traffic(dev);
804 struct cm109_dev *dev = usb_get_intfdata(intf);
806 dev_info(&intf->dev,
"cm109: usb_resume\n");
809 cm109_restore_state(dev);
817 struct cm109_dev *dev = usb_get_intfdata(intf);
828 cm109_stop_traffic(dev);
835 struct cm109_dev *dev = usb_get_intfdata(intf);
840 cm109_restore_state(dev);
847 static struct usb_driver cm109_driver = {
849 .probe = cm109_usb_probe,
850 .disconnect = cm109_usb_disconnect,
851 .suspend = cm109_usb_suspend,
852 .resume = cm109_usb_resume,
853 .reset_resume = cm109_usb_resume,
854 .pre_reset = cm109_usb_pre_reset,
855 .post_reset = cm109_usb_post_reset,
856 .id_table = cm109_usb_table,
857 .supports_autosuspend = 1,
860 static int __init cm109_select_keymap(
void)
864 keymap = keymap_kip1000;
866 "Keymap for Komunikate KIP1000 phone loaded\n");
868 keymap = keymap_gtalk;
870 "Keymap for Genius G-talk phone loaded\n");
872 keymap = keymap_usbph01;
874 "Keymap for Allied-Telesis Corega USBPH01 phone loaded\n");
876 keymap = keymap_atcom;
878 "Keymap for ATCom AU-100 phone loaded\n");
881 "Unsupported phone: %s\n", phone);
888 static int __init cm109_init(
void)
892 err = cm109_select_keymap();
896 err = usb_register(&cm109_driver);
906 static void __exit cm109_exit(
void)