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/types.h>
29#include <linux/input.h>
30
31#include "smscoreapi.h"
32#include "smsir.h"
33#include "sms-cards.h"
34
35#define MODULE_NAME "smsmdtv"
36
37void sms_ir_event(struct smscore_device_t *coredev, const char *buf, int len)
38{
39 int i;
40 const s32 *samples = (const void *)buf;
41
42 for (i = 0; i < len >> 2; i++) {
43 DEFINE_IR_RAW_EVENT(ev);
44
45 ev.duration = abs(samples[i]) * 1000;
46 ev.pulse = (samples[i] > 0) ? false : true;
47
48 ir_raw_event_store(coredev->ir.dev, &ev);
49 }
50 ir_raw_event_handle(coredev->ir.dev);
51}
52
53int sms_ir_init(struct smscore_device_t *coredev)
54{
55 int err;
56 int board_id = smscore_get_board_id(coredev);
57 struct rc_dev *dev;
58
59 sms_log("Allocating rc device");
60 dev = rc_allocate_device();
61 if (!dev) {
62 sms_err("Not enough memory");
63 return -ENOMEM;
64 }
65
66 coredev->ir.controller = 0;
67 coredev->ir.timeout = IR_DEFAULT_TIMEOUT;
68 sms_log("IR port %d, timeout %d ms",
69 coredev->ir.controller, coredev->ir.timeout);
70
71 snprintf(coredev->ir.name, sizeof(coredev->ir.name),
72 "SMS IR (%s)", sms_get_board(board_id)->name);
73
74 strlcpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
75 strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));
76
77 dev->input_name = coredev->ir.name;
78 dev->input_phys = coredev->ir.phys;
79 dev->dev.parent = coredev->device;
80
81#if 0
82
83 dev->input_id.bustype = BUS_USB;
84 dev->input_id.version = 1;
85 dev->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
86 dev->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
87#endif
88
89 dev->priv = coredev;
90 dev->driver_type = RC_DRIVER_IR_RAW;
91 dev->allowed_protos = RC_BIT_ALL;
92 dev->map_name = sms_get_board(board_id)->rc_codes;
93 dev->driver_name = MODULE_NAME;
94
95 sms_log("Input device (IR) %s is set for key events", dev->input_name);
96
97 err = rc_register_device(dev);
98 if (err < 0) {
99 sms_err("Failed to register device");
100 rc_free_device(dev);
101 return err;
102 }
103
104 coredev->ir.dev = dev;
105 return 0;
106}
107
108void sms_ir_exit(struct smscore_device_t *coredev)
109{
110 if (coredev->ir.dev)
111 rc_unregister_device(coredev->ir.dev);
112
113 sms_log("");
114}
115