ath9k: merge a few bugfixes
[openwrt/openwrt.git] / package / lqtapi / src / tapi / tapi-input.c
1
2 #include <linux/tapi/tapi.h>
3
4 #include <linux/input.h>
5
6 static unsigned short tapi_keycodes[] = {
7 [0] = KEY_NUMERIC_0,
8 [1] = KEY_NUMERIC_1,
9 [2] = KEY_NUMERIC_2,
10 [3] = KEY_NUMERIC_3,
11 [4] = KEY_NUMERIC_4,
12 [5] = KEY_NUMERIC_5,
13 [6] = KEY_NUMERIC_6,
14 [7] = KEY_NUMERIC_7,
15 [8] = KEY_NUMERIC_8,
16 [9] = KEY_NUMERIC_9,
17 [10] = KEY_NUMERIC_STAR,
18 [11] = KEY_NUMERIC_POUND,
19 [12] = KEY_ENTER,
20 [13] = KEY_ESC,
21 };
22
23 static int tapi_input_event(struct input_dev *input, unsigned int type,
24 unsigned int code, int value)
25 {
26 struct tapi_device *tdev = dev_to_tapi(input->dev.parent);
27 struct tapi_port *port = input_get_drvdata(input);
28
29
30 if (type != EV_SND || code != SND_BELL)
31 return -EINVAL;
32
33 tapi_port_set_ring(tdev, port, value);
34
35 return 0;
36 }
37
38 void tapi_alloc_input(struct tapi_device *tdev, struct tapi_port *port)
39 {
40 struct input_dev *input;
41 int i;
42 char *phys;
43
44 input = input_allocate_device();
45
46 phys = kzalloc(sizeof("tapi/input000"), GFP_KERNEL);
47 sprintf(phys, "tapi/input%d", port->id);
48
49 input->name = "tapi";
50 input->phys = phys;
51 input->id.bustype = BUS_HOST;
52 input->dev.parent = &tdev->dev;
53 input->evbit[0] = BIT(EV_KEY) | BIT(EV_SND);
54 input->sndbit[0] = BIT(SND_BELL);
55
56 input->event = tapi_input_event;
57
58 input->keycodesize = sizeof(unsigned short);
59 input->keycodemax = ARRAY_SIZE(tapi_keycodes);
60 input->keycode = tapi_keycodes;
61
62 port->input = input;
63
64 for (i = 0; i < ARRAY_SIZE(tapi_keycodes); ++i)
65 __set_bit(tapi_keycodes[i], input->keybit);
66
67 input_set_drvdata(input, port);
68 input_register_device(input);
69 }
70
71 void tapi_report_event(struct tapi_device *tdev,
72 struct tapi_event *event)
73 {
74 unsigned short key_code;
75 struct input_dev *input;
76
77 if (!tdev || !tdev->ports)
78 return;
79
80 switch (event->type) {
81 case TAPI_EVENT_TYPE_HOOK:
82 if (event->hook.on)
83 key_code = KEY_ENTER;
84 else
85 key_code = KEY_ESC;
86 break;
87 case TAPI_EVENT_TYPE_DTMF:
88 key_code = tapi_keycodes[event->dtmf.code];
89 break;
90 default:
91 return;
92 }
93
94 input = tdev->ports[event->port].input;
95 input_report_key(input, key_code, 1);
96 input_sync(input);
97 input_report_key(input, key_code, 0);
98 input_sync(input);
99 }