smsir.c 3.2 KB
Newer Older
1 2 3 4 5 6
/****************************************************************

 Siano Mobile Silicon, Inc.
 MDTV receiver kernel modules.
 Copyright (C) 2006-2009, Uri Shkolnik

7 8 9 10 11
 Copyright (c) 2010 - Mauro Carvalho Chehab
	- Ported the driver to use rc-core
	- IR raw event decoding is now done at rc-core
	- Code almost re-written

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.

 ****************************************************************/


#include <linux/types.h>
#include <linux/input.h>

#include "smscoreapi.h"
#include "smsir.h"
#include "sms-cards.h"

35
#define MODULE_NAME "smsmdtv"
36

37
void 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 46
		ev.duration = abs(samples[i]) * 1000; /* Convert to ns */
		ev.pulse = (samples[i] > 0) ? false : true;
47

48
		ir_raw_event_store(coredev->ir.input_dev, &ev);
49
	}
50
	ir_raw_event_handle(coredev->ir.input_dev);
51 52 53 54 55
}

int sms_ir_init(struct smscore_device_t *coredev)
{
	struct input_dev *input_dev;
56
	int board_id = smscore_get_board_id(coredev);
57

58
	sms_log("Allocating input device");
59 60 61 62 63 64 65 66 67 68
	input_dev = input_allocate_device();
	if (!input_dev)	{
		sms_err("Not enough memory");
		return -ENOMEM;
	}

	coredev->ir.input_dev = input_dev;

	coredev->ir.controller = 0;	/* Todo: vega/nova SPI number */
	coredev->ir.timeout = IR_DEFAULT_TIMEOUT;
69
	sms_log("IR port %d, timeout %d ms",
70 71
			coredev->ir.controller, coredev->ir.timeout);

72 73
	snprintf(coredev->ir.name, sizeof(coredev->ir.name),
		 "SMS IR (%s)", sms_get_board(board_id)->name);
74 75 76 77

	strlcpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
	strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));

78
	input_dev->name = coredev->ir.name;
79
	input_dev->phys = coredev->ir.phys;
80 81
	input_dev->dev.parent = coredev->device;

82 83 84 85 86 87 88 89 90 91 92
#if 0
	/* TODO: properly initialize the parameters bellow */
	input_dev->id.bustype = BUS_USB;
	input_dev->id.version = 1;
	input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
	input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
#endif

	coredev->ir.props.priv = coredev;
	coredev->ir.props.driver_type = RC_DRIVER_IR_RAW;
	coredev->ir.props.allowed_protos = IR_TYPE_ALL;
93

94
	sms_log("Input device (IR) %s is set for key events", input_dev->name);
95

96 97
	if (ir_input_register(input_dev, sms_get_board(board_id)->rc_codes,
			      &coredev->ir.props, MODULE_NAME)) {
98 99 100 101 102 103 104 105 106 107 108
		sms_err("Failed to register device");
		input_free_device(input_dev);
		return -EACCES;
	}

	return 0;
}

void sms_ir_exit(struct smscore_device_t *coredev)
{
	if (coredev->ir.input_dev)
109
		ir_input_unregister(coredev->ir.input_dev);
110

111
	sms_log("");
112
}