blob: b8c5cad78537209b2409e687a4a5eb23b4c51b93 [file] [log] [blame]
Uri Shkolnikebb6c222009-04-05 06:01:37 -03001/****************************************************************
2
3 Siano Mobile Silicon, Inc.
4 MDTV receiver kernel modules.
5 Copyright (C) 2006-2009, Uri Shkolnik
6
Mauro Carvalho Chehab844a9e92010-08-01 17:19:29 -03007 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
Uri Shkolnikebb6c222009-04-05 06:01:37 -030012 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
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
Mauro Carvalho Chehab844a9e92010-08-01 17:19:29 -030035#define MODULE_NAME "smsmdtv"
Uri Shkolnikebb6c222009-04-05 06:01:37 -030036
37void sms_ir_event(struct smscore_device_t *coredev, const char *buf, int len)
38{
Mauro Carvalho Chehab844a9e92010-08-01 17:19:29 -030039 int i;
40 const s32 *samples = (const void *)buf;
Uri Shkolnikebb6c222009-04-05 06:01:37 -030041
Mauro Carvalho Chehab844a9e92010-08-01 17:19:29 -030042 for (i = 0; i < len >> 2; i++) {
Maxim Levitskydc697982010-10-24 23:05:29 -030043 DEFINE_IR_RAW_EVENT(ev);
Uri Shkolnikebb6c222009-04-05 06:01:37 -030044
Mauro Carvalho Chehab844a9e92010-08-01 17:19:29 -030045 ev.duration = abs(samples[i]) * 1000; /* Convert to ns */
46 ev.pulse = (samples[i] > 0) ? false : true;
47
David Härdemand8b4b582010-10-29 16:08:23 -030048 ir_raw_event_store(coredev->ir.dev, &ev);
Mauro Carvalho Chehab844a9e92010-08-01 17:19:29 -030049 }
David Härdemand8b4b582010-10-29 16:08:23 -030050 ir_raw_event_handle(coredev->ir.dev);
Uri Shkolnikebb6c222009-04-05 06:01:37 -030051}
52
53int sms_ir_init(struct smscore_device_t *coredev)
54{
David Härdemand8b4b582010-10-29 16:08:23 -030055 int err;
Mauro Carvalho Chehab1722f3b2010-08-01 15:30:50 -030056 int board_id = smscore_get_board_id(coredev);
David Härdemand8b4b582010-10-29 16:08:23 -030057 struct rc_dev *dev;
Uri Shkolnikebb6c222009-04-05 06:01:37 -030058
David Härdemand8b4b582010-10-29 16:08:23 -030059 sms_log("Allocating rc device");
60 dev = rc_allocate_device();
61 if (!dev) {
Uri Shkolnikebb6c222009-04-05 06:01:37 -030062 sms_err("Not enough memory");
63 return -ENOMEM;
64 }
65
Uri Shkolnikebb6c222009-04-05 06:01:37 -030066 coredev->ir.controller = 0; /* Todo: vega/nova SPI number */
67 coredev->ir.timeout = IR_DEFAULT_TIMEOUT;
Uri Shkolnik90f944a2009-05-14 16:32:12 -030068 sms_log("IR port %d, timeout %d ms",
Uri Shkolnikebb6c222009-04-05 06:01:37 -030069 coredev->ir.controller, coredev->ir.timeout);
70
Mauro Carvalho Chehab844a9e92010-08-01 17:19:29 -030071 snprintf(coredev->ir.name, sizeof(coredev->ir.name),
72 "SMS IR (%s)", sms_get_board(board_id)->name);
Mauro Carvalho Chehab1722f3b2010-08-01 15:30:50 -030073
74 strlcpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
75 strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));
76
David Härdemand8b4b582010-10-29 16:08:23 -030077 dev->input_name = coredev->ir.name;
78 dev->input_phys = coredev->ir.phys;
79 dev->dev.parent = coredev->device;
Uri Shkolnikebb6c222009-04-05 06:01:37 -030080
Mauro Carvalho Chehab844a9e92010-08-01 17:19:29 -030081#if 0
82 /* TODO: properly initialize the parameters bellow */
David Härdemand8b4b582010-10-29 16:08:23 -030083 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);
Mauro Carvalho Chehab844a9e92010-08-01 17:19:29 -030087#endif
88
David Härdemand8b4b582010-10-29 16:08:23 -030089 dev->priv = coredev;
90 dev->driver_type = RC_DRIVER_IR_RAW;
David Härdemanc003ab12012-10-11 19:11:54 -030091 dev->allowed_protos = RC_BIT_ALL;
David Härdemand8b4b582010-10-29 16:08:23 -030092 dev->map_name = sms_get_board(board_id)->rc_codes;
93 dev->driver_name = MODULE_NAME;
Uri Shkolnikebb6c222009-04-05 06:01:37 -030094
David Härdemand8b4b582010-10-29 16:08:23 -030095 sms_log("Input device (IR) %s is set for key events", dev->input_name);
Uri Shkolnikebb6c222009-04-05 06:01:37 -030096
David Härdemand8b4b582010-10-29 16:08:23 -030097 err = rc_register_device(dev);
98 if (err < 0) {
Uri Shkolnikebb6c222009-04-05 06:01:37 -030099 sms_err("Failed to register device");
David Härdemand8b4b582010-10-29 16:08:23 -0300100 rc_free_device(dev);
101 return err;
Uri Shkolnikebb6c222009-04-05 06:01:37 -0300102 }
103
David Härdemand8b4b582010-10-29 16:08:23 -0300104 coredev->ir.dev = dev;
Uri Shkolnikebb6c222009-04-05 06:01:37 -0300105 return 0;
106}
107
108void sms_ir_exit(struct smscore_device_t *coredev)
109{
David Härdemand8b4b582010-10-29 16:08:23 -0300110 if (coredev->ir.dev)
111 rc_unregister_device(coredev->ir.dev);
Uri Shkolnikebb6c222009-04-05 06:01:37 -0300112
Uri Shkolnik90f944a2009-05-14 16:32:12 -0300113 sms_log("");
Uri Shkolnikebb6c222009-04-05 06:01:37 -0300114}