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