media: replace bellow -> below
[deliverable/linux.git] / drivers / media / common / siano / smsir.c
CommitLineData
ebb6c22e
US
1/****************************************************************
2
3 Siano Mobile Silicon, Inc.
4 MDTV receiver kernel modules.
5 Copyright (C) 2006-2009, Uri Shkolnik
6
844a9e93
MCC
7 Copyright (c) 2010 - Mauro Carvalho Chehab
8 - Ported the driver to use rc-core
9 - IR raw event decoding is now done at rc-core
10 - Code almost re-written
11
ebb6c22e
US
12 This program is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
24
25 ****************************************************************/
26
27
5e022d1a
MCC
28#include "smscoreapi.h"
29
ebb6c22e
US
30#include <linux/types.h>
31#include <linux/input.h>
32
ebb6c22e
US
33#include "smsir.h"
34#include "sms-cards.h"
35
844a9e93 36#define MODULE_NAME "smsmdtv"
ebb6c22e 37
844a9e93 38void sms_ir_event(struct smscore_device_t *coredev, const char *buf, int len)
ebb6c22e 39{
ebb6c22e 40 int i;
844a9e93 41 const s32 *samples = (const void *)buf;
ebb6c22e 42
844a9e93 43 for (i = 0; i < len >> 2; i++) {
dc697984 44 DEFINE_IR_RAW_EVENT(ev);
ebb6c22e 45
844a9e93
MCC
46 ev.duration = abs(samples[i]) * 1000; /* Convert to ns */
47 ev.pulse = (samples[i] > 0) ? false : true;
ebb6c22e 48
d8b4b582 49 ir_raw_event_store(coredev->ir.dev, &ev);
ebb6c22e 50 }
d8b4b582 51 ir_raw_event_handle(coredev->ir.dev);
ebb6c22e
US
52}
53
54int sms_ir_init(struct smscore_device_t *coredev)
55{
d8b4b582 56 int err;
1722f3b3 57 int board_id = smscore_get_board_id(coredev);
d8b4b582 58 struct rc_dev *dev;
ebb6c22e 59
9b283e67 60 pr_debug("Allocating rc device\n");
d8b4b582 61 dev = rc_allocate_device();
5ed0a2c7 62 if (!dev)
ebb6c22e 63 return -ENOMEM;
ebb6c22e 64
ebb6c22e
US
65 coredev->ir.controller = 0; /* Todo: vega/nova SPI number */
66 coredev->ir.timeout = IR_DEFAULT_TIMEOUT;
9b283e67 67 pr_debug("IR port %d, timeout %d ms\n",
ebb6c22e
US
68 coredev->ir.controller, coredev->ir.timeout);
69
844a9e93
MCC
70 snprintf(coredev->ir.name, sizeof(coredev->ir.name),
71 "SMS IR (%s)", sms_get_board(board_id)->name);
1722f3b3
MCC
72
73 strlcpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
74 strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));
75
d8b4b582
DH
76 dev->input_name = coredev->ir.name;
77 dev->input_phys = coredev->ir.phys;
78 dev->dev.parent = coredev->device;
ebb6c22e 79
844a9e93 80#if 0
5a13e40b 81 /* TODO: properly initialize the parameters below */
d8b4b582
DH
82 dev->input_id.bustype = BUS_USB;
83 dev->input_id.version = 1;
84 dev->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
85 dev->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
844a9e93
MCC
86#endif
87
d8b4b582
DH
88 dev->priv = coredev;
89 dev->driver_type = RC_DRIVER_IR_RAW;
c5540fbb 90 dev->allowed_protocols = RC_BIT_ALL;
d8b4b582
DH
91 dev->map_name = sms_get_board(board_id)->rc_codes;
92 dev->driver_name = MODULE_NAME;
ebb6c22e 93
9b283e67
MCC
94 pr_debug("Input device (IR) %s is set for key events\n",
95 dev->input_name);
ebb6c22e 96
d8b4b582
DH
97 err = rc_register_device(dev);
98 if (err < 0) {
5ed0a2c7 99 pr_err("Failed to register device\n");
d8b4b582
DH
100 rc_free_device(dev);
101 return err;
ebb6c22e
US
102 }
103
d8b4b582 104 coredev->ir.dev = dev;
ebb6c22e
US
105 return 0;
106}
107
108void sms_ir_exit(struct smscore_device_t *coredev)
109{
6b281d83 110 rc_unregister_device(coredev->ir.dev);
ebb6c22e 111
9b283e67 112 pr_debug("\n");
ebb6c22e 113}
This page took 0.379746 seconds and 5 git commands to generate.