1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31#include <linux/kernel.h>
32#include <linux/init.h>
33#include <linux/slab.h>
34#include <linux/module.h>
35#include <linux/moduleparam.h>
36#include <linux/rwsem.h>
37#include <linux/usb/input.h>
38
39#define DRIVER_VERSION "20080805"
40#define DRIVER_AUTHOR "Alfred E. Heggestad"
41#define DRIVER_DESC "CM109 phone driver"
42
43static char *phone = "kip1000";
44module_param(phone, charp, S_IRUSR);
45MODULE_PARM_DESC(phone, "Phone name {kip1000, gtalk, usbph01, atcom}");
46
47enum {
48
49 HID_IR0 = 0x00,
50 HID_IR1 = 0x01,
51 HID_IR2 = 0x02,
52 HID_IR3 = 0x03,
53 HID_OR0 = 0x00,
54 HID_OR1 = 0x01,
55 HID_OR2 = 0x02,
56 HID_OR3 = 0x03,
57
58
59 RECORD_MUTE = 1 << 3,
60 PLAYBACK_MUTE = 1 << 2,
61 VOLUME_DOWN = 1 << 1,
62 VOLUME_UP = 1 << 0,
63
64
65
66
67
68
69
70
71
72
73 HID_OR_GPO_BUZ_SPDIF = 0 << 6,
74 HID_OR_GENERIC_HID_REG = 1 << 6,
75 HID_OR_MAP_MCU_EEPROM = 2 << 6,
76
77 BUZZER_ON = 1 << 5,
78
79
80 KEYMAP_SIZE = 256 + 15,
81};
82
83
84struct cm109_ctl_packet {
85 u8 byte[4];
86} __attribute__ ((packed));
87
88enum { USB_PKT_LEN = sizeof(struct cm109_ctl_packet) };
89
90
91struct cm109_dev {
92 struct input_dev *idev;
93 struct usb_device *udev;
94 struct usb_interface *intf;
95
96
97 struct cm109_ctl_packet *irq_data;
98 dma_addr_t irq_dma;
99 struct urb *urb_irq;
100
101
102 struct cm109_ctl_packet *ctl_data;
103 dma_addr_t ctl_dma;
104 struct usb_ctrlrequest *ctl_req;
105 struct urb *urb_ctl;
106
107
108
109
110
111 unsigned irq_urb_pending:1;
112 unsigned ctl_urb_pending:1;
113 unsigned buzzer_pending:1;
114 spinlock_t ctl_submit_lock;
115
116 unsigned char buzzer_state;
117
118
119 unsigned open:1;
120 unsigned resetting:1;
121 unsigned shutdown:1;
122
123
124 struct mutex pm_mutex;
125
126 unsigned short keymap[KEYMAP_SIZE];
127
128 char phys[64];
129 int key_code;
130 int keybit;
131 u8 gpi;
132};
133
134
135
136
137
138static unsigned short special_keymap(int code)
139{
140 if (code > 0xff) {
141 switch (code - 0xff) {
142 case RECORD_MUTE: return KEY_MICMUTE;
143 case PLAYBACK_MUTE: return KEY_MUTE;
144 case VOLUME_DOWN: return KEY_VOLUMEDOWN;
145 case VOLUME_UP: return KEY_VOLUMEUP;
146 }
147 }
148 return KEY_RESERVED;
149}
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175static unsigned short keymap_kip1000(int scancode)
176{
177 switch (scancode) {
178 case 0x82: return KEY_NUMERIC_0;
179 case 0x14: return KEY_NUMERIC_1;
180 case 0x12: return KEY_NUMERIC_2;
181 case 0x11: return KEY_NUMERIC_3;
182 case 0x24: return KEY_NUMERIC_4;
183 case 0x22: return KEY_NUMERIC_5;
184 case 0x21: return KEY_NUMERIC_6;
185 case 0x44: return KEY_NUMERIC_7;
186 case 0x42: return KEY_NUMERIC_8;
187 case 0x41: return KEY_NUMERIC_9;
188 case 0x81: return KEY_NUMERIC_POUND;
189 case 0x84: return KEY_NUMERIC_STAR;
190 case 0x88: return KEY_ENTER;
191 case 0x48: return KEY_ESC;
192 case 0x28: return KEY_LEFT;
193 case 0x18: return KEY_RIGHT;
194 default: return special_keymap(scancode);
195 }
196}
197
198
199
200
201
202
203
204
205
206
207
208static unsigned short keymap_gtalk(int scancode)
209{
210 switch (scancode) {
211 case 0x11: return KEY_NUMERIC_0;
212 case 0x21: return KEY_NUMERIC_1;
213 case 0x41: return KEY_NUMERIC_2;
214 case 0x81: return KEY_NUMERIC_3;
215 case 0x12: return KEY_NUMERIC_4;
216 case 0x22: return KEY_NUMERIC_5;
217 case 0x42: return KEY_NUMERIC_6;
218 case 0x82: return KEY_NUMERIC_7;
219 case 0x14: return KEY_NUMERIC_8;
220 case 0x24: return KEY_NUMERIC_9;
221 case 0x44: return KEY_NUMERIC_POUND;
222 case 0x84: return KEY_NUMERIC_STAR;
223 case 0x18: return KEY_ENTER;
224 case 0x28: return KEY_ESC;
225 case 0x48: return KEY_UP;
226 case 0x88: return KEY_DOWN;
227 default: return special_keymap(scancode);
228 }
229}
230
231
232
233
234
235
236
237static unsigned short keymap_usbph01(int scancode)
238{
239 switch (scancode) {
240 case 0x11: return KEY_NUMERIC_0;
241 case 0x21: return KEY_NUMERIC_1;
242 case 0x41: return KEY_NUMERIC_2;
243 case 0x81: return KEY_NUMERIC_3;
244 case 0x12: return KEY_NUMERIC_4;
245 case 0x22: return KEY_NUMERIC_5;
246 case 0x42: return KEY_NUMERIC_6;
247 case 0x82: return KEY_NUMERIC_7;
248 case 0x14: return KEY_NUMERIC_8;
249 case 0x24: return KEY_NUMERIC_9;
250 case 0x44: return KEY_NUMERIC_POUND;
251 case 0x84: return KEY_NUMERIC_STAR;
252 case 0x18: return KEY_ENTER;
253 case 0x28: return KEY_ESC;
254 case 0x48: return KEY_LEFT;
255 case 0x88: return KEY_RIGHT;
256 default: return special_keymap(scancode);
257 }
258}
259
260
261
262
263
264
265
266
267
268static unsigned short keymap_atcom(int scancode)
269{
270 switch (scancode) {
271 case 0x82: return KEY_NUMERIC_0;
272 case 0x11: return KEY_NUMERIC_1;
273 case 0x12: return KEY_NUMERIC_2;
274 case 0x14: return KEY_NUMERIC_3;
275 case 0x21: return KEY_NUMERIC_4;
276 case 0x22: return KEY_NUMERIC_5;
277 case 0x24: return KEY_NUMERIC_6;
278 case 0x41: return KEY_NUMERIC_7;
279 case 0x42: return KEY_NUMERIC_8;
280 case 0x44: return KEY_NUMERIC_9;
281 case 0x84: return KEY_NUMERIC_POUND;
282 case 0x81: return KEY_NUMERIC_STAR;
283 case 0x18: return KEY_ENTER;
284 case 0x28: return KEY_ESC;
285 case 0x48: return KEY_LEFT;
286 case 0x88: return KEY_RIGHT;
287 default: return special_keymap(scancode);
288 }
289}
290
291static unsigned short (*keymap)(int) = keymap_kip1000;
292
293
294
295
296
297static void report_key(struct cm109_dev *dev, int key)
298{
299 struct input_dev *idev = dev->idev;
300
301 if (dev->key_code >= 0) {
302
303 input_report_key(idev, dev->key_code, 0);
304 }
305
306 dev->key_code = key;
307 if (key >= 0) {
308
309 input_report_key(idev, key, 1);
310 }
311
312 input_sync(idev);
313}
314
315
316
317
318
319static void cm109_report_special(struct cm109_dev *dev)
320{
321 static const u8 autorelease = RECORD_MUTE | PLAYBACK_MUTE;
322 struct input_dev *idev = dev->idev;
323 u8 data = dev->irq_data->byte[HID_IR0];
324 unsigned short keycode;
325 int i;
326
327 for (i = 0; i < 4; i++) {
328 keycode = dev->keymap[0xff + BIT(i)];
329 if (keycode == KEY_RESERVED)
330 continue;
331
332 input_report_key(idev, keycode, data & BIT(i));
333 if (data & autorelease & BIT(i)) {
334 input_sync(idev);
335 input_report_key(idev, keycode, 0);
336 }
337 }
338 input_sync(idev);
339}
340
341
342
343
344
345static void cm109_submit_buzz_toggle(struct cm109_dev *dev)
346{
347 int error;
348
349 if (dev->buzzer_state)
350 dev->ctl_data->byte[HID_OR0] |= BUZZER_ON;
351 else
352 dev->ctl_data->byte[HID_OR0] &= ~BUZZER_ON;
353
354 error = usb_submit_urb(dev->urb_ctl, GFP_ATOMIC);
355 if (error)
356 dev_err(&dev->intf->dev,
357 "%s: usb_submit_urb (urb_ctl) failed %d\n",
358 __func__, error);
359}
360
361
362
363
364static void cm109_urb_irq_callback(struct urb *urb)
365{
366 struct cm109_dev *dev = urb->context;
367 const int status = urb->status;
368 int error;
369 unsigned long flags;
370
371 dev_dbg(&dev->intf->dev, "### URB IRQ: [0x%02x 0x%02x 0x%02x 0x%02x] keybit=0x%02x\n",
372 dev->irq_data->byte[0],
373 dev->irq_data->byte[1],
374 dev->irq_data->byte[2],
375 dev->irq_data->byte[3],
376 dev->keybit);
377
378 if (status) {
379 if (status == -ESHUTDOWN)
380 return;
381 dev_err_ratelimited(&dev->intf->dev, "%s: urb status %d\n",
382 __func__, status);
383 goto out;
384 }
385
386
387 cm109_report_special(dev);
388
389
390 if (dev->keybit == 0xf) {
391
392
393 if ((dev->gpi & 0xf0) == (dev->irq_data->byte[HID_IR1] & 0xf0))
394 goto out;
395
396 dev->gpi = dev->irq_data->byte[HID_IR1] & 0xf0;
397 dev->keybit = 0x1;
398 } else {
399 report_key(dev, dev->keymap[dev->irq_data->byte[HID_IR1]]);
400
401 dev->keybit <<= 1;
402 if (dev->keybit > 0x8)
403 dev->keybit = 0xf;
404 }
405
406 out:
407
408 spin_lock_irqsave(&dev->ctl_submit_lock, flags);
409
410 dev->irq_urb_pending = 0;
411
412 if (likely(!dev->shutdown)) {
413
414 if (dev->buzzer_state)
415 dev->ctl_data->byte[HID_OR0] |= BUZZER_ON;
416 else
417 dev->ctl_data->byte[HID_OR0] &= ~BUZZER_ON;
418
419 dev->ctl_data->byte[HID_OR1] = dev->keybit;
420 dev->ctl_data->byte[HID_OR2] = dev->keybit;
421
422 dev->buzzer_pending = 0;
423 dev->ctl_urb_pending = 1;
424
425 error = usb_submit_urb(dev->urb_ctl, GFP_ATOMIC);
426 if (error)
427 dev_err(&dev->intf->dev,
428 "%s: usb_submit_urb (urb_ctl) failed %d\n",
429 __func__, error);
430 }
431
432 spin_unlock_irqrestore(&dev->ctl_submit_lock, flags);
433}
434
435static void cm109_urb_ctl_callback(struct urb *urb)
436{
437 struct cm109_dev *dev = urb->context;
438 const int status = urb->status;
439 int error;
440 unsigned long flags;
441
442 dev_dbg(&dev->intf->dev, "### URB CTL: [0x%02x 0x%02x 0x%02x 0x%02x]\n",
443 dev->ctl_data->byte[0],
444 dev->ctl_data->byte[1],
445 dev->ctl_data->byte[2],
446 dev->ctl_data->byte[3]);
447
448 if (status) {
449 if (status == -ESHUTDOWN)
450 return;
451 dev_err_ratelimited(&dev->intf->dev, "%s: urb status %d\n",
452 __func__, status);
453 }
454
455 spin_lock_irqsave(&dev->ctl_submit_lock, flags);
456
457 dev->ctl_urb_pending = 0;
458
459 if (likely(!dev->shutdown)) {
460
461 if (dev->buzzer_pending || status) {
462 dev->buzzer_pending = 0;
463 dev->ctl_urb_pending = 1;
464 cm109_submit_buzz_toggle(dev);
465 } else if (likely(!dev->irq_urb_pending)) {
466
467 dev->irq_urb_pending = 1;
468 error = usb_submit_urb(dev->urb_irq, GFP_ATOMIC);
469 if (error)
470 dev_err(&dev->intf->dev,
471 "%s: usb_submit_urb (urb_irq) failed %d\n",
472 __func__, error);
473 }
474 }
475
476 spin_unlock_irqrestore(&dev->ctl_submit_lock, flags);
477}
478
479static void cm109_toggle_buzzer_async(struct cm109_dev *dev)
480{
481 unsigned long flags;
482
483 spin_lock_irqsave(&dev->ctl_submit_lock, flags);
484
485 if (dev->ctl_urb_pending) {
486
487 dev->buzzer_pending = 1;
488 } else {
489 dev->ctl_urb_pending = 1;
490 cm109_submit_buzz_toggle(dev);
491 }
492
493 spin_unlock_irqrestore(&dev->ctl_submit_lock, flags);
494}
495
496static void cm109_toggle_buzzer_sync(struct cm109_dev *dev, int on)
497{
498 int error;
499
500 if (on)
501 dev->ctl_data->byte[HID_OR0] |= BUZZER_ON;
502 else
503 dev->ctl_data->byte[HID_OR0] &= ~BUZZER_ON;
504
505 error = usb_control_msg(dev->udev,
506 usb_sndctrlpipe(dev->udev, 0),
507 dev->ctl_req->bRequest,
508 dev->ctl_req->bRequestType,
509 le16_to_cpu(dev->ctl_req->wValue),
510 le16_to_cpu(dev->ctl_req->wIndex),
511 dev->ctl_data,
512 USB_PKT_LEN, USB_CTRL_SET_TIMEOUT);
513 if (error < 0 && error != -EINTR)
514 dev_err(&dev->intf->dev, "%s: usb_control_msg() failed %d\n",
515 __func__, error);
516}
517
518static void cm109_stop_traffic(struct cm109_dev *dev)
519{
520 dev->shutdown = 1;
521
522
523
524 smp_wmb();
525
526 usb_kill_urb(dev->urb_ctl);
527 usb_kill_urb(dev->urb_irq);
528
529 cm109_toggle_buzzer_sync(dev, 0);
530
531 dev->shutdown = 0;
532 smp_wmb();
533}
534
535static void cm109_restore_state(struct cm109_dev *dev)
536{
537 if (dev->open) {
538
539
540
541
542 cm109_toggle_buzzer_async(dev);
543 }
544}
545
546
547
548
549
550static int cm109_input_open(struct input_dev *idev)
551{
552 struct cm109_dev *dev = input_get_drvdata(idev);
553 int error;
554
555 error = usb_autopm_get_interface(dev->intf);
556 if (error < 0) {
557 dev_err(&idev->dev, "%s - cannot autoresume, result %d\n",
558 __func__, error);
559 return error;
560 }
561
562 mutex_lock(&dev->pm_mutex);
563
564 dev->buzzer_state = 0;
565 dev->key_code = -1;
566 dev->keybit = 0xf;
567
568
569 dev->ctl_data->byte[HID_OR0] = HID_OR_GPO_BUZ_SPDIF;
570 dev->ctl_data->byte[HID_OR1] = dev->keybit;
571 dev->ctl_data->byte[HID_OR2] = dev->keybit;
572 dev->ctl_data->byte[HID_OR3] = 0x00;
573
574 error = usb_submit_urb(dev->urb_ctl, GFP_KERNEL);
575 if (error)
576 dev_err(&dev->intf->dev, "%s: usb_submit_urb (urb_ctl) failed %d\n",
577 __func__, error);
578 else
579 dev->open = 1;
580
581 mutex_unlock(&dev->pm_mutex);
582
583 if (error)
584 usb_autopm_put_interface(dev->intf);
585
586 return error;
587}
588
589static void cm109_input_close(struct input_dev *idev)
590{
591 struct cm109_dev *dev = input_get_drvdata(idev);
592
593 mutex_lock(&dev->pm_mutex);
594
595
596
597
598
599
600 cm109_stop_traffic(dev);
601 dev->open = 0;
602
603 mutex_unlock(&dev->pm_mutex);
604
605 usb_autopm_put_interface(dev->intf);
606}
607
608static int cm109_input_ev(struct input_dev *idev, unsigned int type,
609 unsigned int code, int value)
610{
611 struct cm109_dev *dev = input_get_drvdata(idev);
612
613 dev_dbg(&dev->intf->dev,
614 "input_ev: type=%u code=%u value=%d\n", type, code, value);
615
616 if (type != EV_SND)
617 return -EINVAL;
618
619 switch (code) {
620 case SND_TONE:
621 case SND_BELL:
622 dev->buzzer_state = !!value;
623 if (!dev->resetting)
624 cm109_toggle_buzzer_async(dev);
625 return 0;
626
627 default:
628 return -EINVAL;
629 }
630}
631
632
633
634
635
636
637struct driver_info {
638 char *name;
639};
640
641static const struct driver_info info_cm109 = {
642 .name = "CM109 USB driver",
643};
644
645enum {
646 VENDOR_ID = 0x0d8c,
647 PRODUCT_ID_CM109 = 0x000e,
648};
649
650
651static const struct usb_device_id cm109_usb_table[] = {
652 {
653 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
654 USB_DEVICE_ID_MATCH_INT_INFO,
655 .idVendor = VENDOR_ID,
656 .idProduct = PRODUCT_ID_CM109,
657 .bInterfaceClass = USB_CLASS_HID,
658 .bInterfaceSubClass = 0,
659 .bInterfaceProtocol = 0,
660 .driver_info = (kernel_ulong_t) &info_cm109
661 },
662
663 { }
664};
665
666static void cm109_usb_cleanup(struct cm109_dev *dev)
667{
668 kfree(dev->ctl_req);
669 if (dev->ctl_data)
670 usb_free_coherent(dev->udev, USB_PKT_LEN,
671 dev->ctl_data, dev->ctl_dma);
672 if (dev->irq_data)
673 usb_free_coherent(dev->udev, USB_PKT_LEN,
674 dev->irq_data, dev->irq_dma);
675
676 usb_free_urb(dev->urb_irq);
677 usb_free_urb(dev->urb_ctl);
678 kfree(dev);
679}
680
681static void cm109_usb_disconnect(struct usb_interface *interface)
682{
683 struct cm109_dev *dev = usb_get_intfdata(interface);
684
685 usb_set_intfdata(interface, NULL);
686 input_unregister_device(dev->idev);
687 cm109_usb_cleanup(dev);
688}
689
690static int cm109_usb_probe(struct usb_interface *intf,
691 const struct usb_device_id *id)
692{
693 struct usb_device *udev = interface_to_usbdev(intf);
694 struct driver_info *nfo = (struct driver_info *)id->driver_info;
695 struct usb_host_interface *interface;
696 struct usb_endpoint_descriptor *endpoint;
697 struct cm109_dev *dev;
698 struct input_dev *input_dev = NULL;
699 int ret, pipe, i;
700 int error = -ENOMEM;
701
702 interface = intf->cur_altsetting;
703
704 if (interface->desc.bNumEndpoints < 1)
705 return -ENODEV;
706
707 endpoint = &interface->endpoint[0].desc;
708
709 if (!usb_endpoint_is_int_in(endpoint))
710 return -ENODEV;
711
712 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
713 if (!dev)
714 return -ENOMEM;
715
716 spin_lock_init(&dev->ctl_submit_lock);
717 mutex_init(&dev->pm_mutex);
718
719 dev->udev = udev;
720 dev->intf = intf;
721
722 dev->idev = input_dev = input_allocate_device();
723 if (!input_dev)
724 goto err_out;
725
726
727 dev->irq_data = usb_alloc_coherent(udev, USB_PKT_LEN,
728 GFP_KERNEL, &dev->irq_dma);
729 if (!dev->irq_data)
730 goto err_out;
731
732 dev->ctl_data = usb_alloc_coherent(udev, USB_PKT_LEN,
733 GFP_KERNEL, &dev->ctl_dma);
734 if (!dev->ctl_data)
735 goto err_out;
736
737 dev->ctl_req = kmalloc(sizeof(*(dev->ctl_req)), GFP_KERNEL);
738 if (!dev->ctl_req)
739 goto err_out;
740
741
742 dev->urb_irq = usb_alloc_urb(0, GFP_KERNEL);
743 if (!dev->urb_irq)
744 goto err_out;
745
746 dev->urb_ctl = usb_alloc_urb(0, GFP_KERNEL);
747 if (!dev->urb_ctl)
748 goto err_out;
749
750
751 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
752 ret = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
753 if (ret != USB_PKT_LEN)
754 dev_err(&intf->dev, "invalid payload size %d, expected %d\n",
755 ret, USB_PKT_LEN);
756
757
758 usb_fill_int_urb(dev->urb_irq, udev, pipe, dev->irq_data,
759 USB_PKT_LEN,
760 cm109_urb_irq_callback, dev, endpoint->bInterval);
761 dev->urb_irq->transfer_dma = dev->irq_dma;
762 dev->urb_irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
763 dev->urb_irq->dev = udev;
764
765
766 dev->ctl_req->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE |
767 USB_DIR_OUT;
768 dev->ctl_req->bRequest = USB_REQ_SET_CONFIGURATION;
769 dev->ctl_req->wValue = cpu_to_le16(0x200);
770 dev->ctl_req->wIndex = cpu_to_le16(interface->desc.bInterfaceNumber);
771 dev->ctl_req->wLength = cpu_to_le16(USB_PKT_LEN);
772
773 usb_fill_control_urb(dev->urb_ctl, udev, usb_sndctrlpipe(udev, 0),
774 (void *)dev->ctl_req, dev->ctl_data, USB_PKT_LEN,
775 cm109_urb_ctl_callback, dev);
776 dev->urb_ctl->transfer_dma = dev->ctl_dma;
777 dev->urb_ctl->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
778 dev->urb_ctl->dev = udev;
779
780
781 usb_make_path(udev, dev->phys, sizeof(dev->phys));
782 strlcat(dev->phys, "/input0", sizeof(dev->phys));
783
784
785 input_dev->name = nfo->name;
786 input_dev->phys = dev->phys;
787 usb_to_input_id(udev, &input_dev->id);
788 input_dev->dev.parent = &intf->dev;
789
790 input_set_drvdata(input_dev, dev);
791 input_dev->open = cm109_input_open;
792 input_dev->close = cm109_input_close;
793 input_dev->event = cm109_input_ev;
794
795 input_dev->keycode = dev->keymap;
796 input_dev->keycodesize = sizeof(unsigned char);
797 input_dev->keycodemax = ARRAY_SIZE(dev->keymap);
798
799 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_SND);
800 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE);
801
802
803 for (i = 0; i < KEYMAP_SIZE; i++) {
804 unsigned short k = keymap(i);
805 dev->keymap[i] = k;
806 __set_bit(k, input_dev->keybit);
807 }
808 __clear_bit(KEY_RESERVED, input_dev->keybit);
809
810 error = input_register_device(dev->idev);
811 if (error)
812 goto err_out;
813
814 usb_set_intfdata(intf, dev);
815
816 return 0;
817
818 err_out:
819 input_free_device(input_dev);
820 cm109_usb_cleanup(dev);
821 return error;
822}
823
824static int cm109_usb_suspend(struct usb_interface *intf, pm_message_t message)
825{
826 struct cm109_dev *dev = usb_get_intfdata(intf);
827
828 dev_info(&intf->dev, "cm109: usb_suspend (event=%d)\n", message.event);
829
830 mutex_lock(&dev->pm_mutex);
831 cm109_stop_traffic(dev);
832 mutex_unlock(&dev->pm_mutex);
833
834 return 0;
835}
836
837static int cm109_usb_resume(struct usb_interface *intf)
838{
839 struct cm109_dev *dev = usb_get_intfdata(intf);
840
841 dev_info(&intf->dev, "cm109: usb_resume\n");
842
843 mutex_lock(&dev->pm_mutex);
844 cm109_restore_state(dev);
845 mutex_unlock(&dev->pm_mutex);
846
847 return 0;
848}
849
850static int cm109_usb_pre_reset(struct usb_interface *intf)
851{
852 struct cm109_dev *dev = usb_get_intfdata(intf);
853
854 mutex_lock(&dev->pm_mutex);
855
856
857
858
859
860 dev->resetting = 1;
861 smp_wmb();
862
863 cm109_stop_traffic(dev);
864
865 return 0;
866}
867
868static int cm109_usb_post_reset(struct usb_interface *intf)
869{
870 struct cm109_dev *dev = usb_get_intfdata(intf);
871
872 dev->resetting = 0;
873 smp_wmb();
874
875 cm109_restore_state(dev);
876
877 mutex_unlock(&dev->pm_mutex);
878
879 return 0;
880}
881
882static struct usb_driver cm109_driver = {
883 .name = "cm109",
884 .probe = cm109_usb_probe,
885 .disconnect = cm109_usb_disconnect,
886 .suspend = cm109_usb_suspend,
887 .resume = cm109_usb_resume,
888 .reset_resume = cm109_usb_resume,
889 .pre_reset = cm109_usb_pre_reset,
890 .post_reset = cm109_usb_post_reset,
891 .id_table = cm109_usb_table,
892 .supports_autosuspend = 1,
893};
894
895static int __init cm109_select_keymap(void)
896{
897
898 if (!strcasecmp(phone, "kip1000")) {
899 keymap = keymap_kip1000;
900 printk(KERN_INFO KBUILD_MODNAME ": "
901 "Keymap for Komunikate KIP1000 phone loaded\n");
902 } else if (!strcasecmp(phone, "gtalk")) {
903 keymap = keymap_gtalk;
904 printk(KERN_INFO KBUILD_MODNAME ": "
905 "Keymap for Genius G-talk phone loaded\n");
906 } else if (!strcasecmp(phone, "usbph01")) {
907 keymap = keymap_usbph01;
908 printk(KERN_INFO KBUILD_MODNAME ": "
909 "Keymap for Allied-Telesis Corega USBPH01 phone loaded\n");
910 } else if (!strcasecmp(phone, "atcom")) {
911 keymap = keymap_atcom;
912 printk(KERN_INFO KBUILD_MODNAME ": "
913 "Keymap for ATCom AU-100 phone loaded\n");
914 } else {
915 printk(KERN_ERR KBUILD_MODNAME ": "
916 "Unsupported phone: %s\n", phone);
917 return -EINVAL;
918 }
919
920 return 0;
921}
922
923static int __init cm109_init(void)
924{
925 int err;
926
927 err = cm109_select_keymap();
928 if (err)
929 return err;
930
931 err = usb_register(&cm109_driver);
932 if (err)
933 return err;
934
935 printk(KERN_INFO KBUILD_MODNAME ": "
936 DRIVER_DESC ": " DRIVER_VERSION " (C) " DRIVER_AUTHOR "\n");
937
938 return 0;
939}
940
941static void __exit cm109_exit(void)
942{
943 usb_deregister(&cm109_driver);
944}
945
946module_init(cm109_init);
947module_exit(cm109_exit);
948
949MODULE_DEVICE_TABLE(usb, cm109_usb_table);
950
951MODULE_AUTHOR(DRIVER_AUTHOR);
952MODULE_DESCRIPTION(DRIVER_DESC);
953MODULE_LICENSE("GPL");
954