smsir.c 2.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// SPDX-License-Identifier: GPL-2.0+
//
// Siano Mobile Silicon, Inc.
// MDTV receiver kernel modules.
// Copyright (C) 2006-2009, Uri Shkolnik
//
// 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
11 12


13 14
#include "smscoreapi.h"

15 16 17 18 19 20
#include <linux/types.h>
#include <linux/input.h>

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

21
#define MODULE_NAME "smsmdtv"
22

23
void sms_ir_event(struct smscore_device_t *coredev, const char *buf, int len)
24 25
{
	int i;
26
	const s32 *samples = (const void *)buf;
27

28
	for (i = 0; i < len >> 2; i++) {
29
		DEFINE_IR_RAW_EVENT(ev);
30

31 32
		ev.duration = abs(samples[i]) * 1000; /* Convert to ns */
		ev.pulse = (samples[i] > 0) ? false : true;
33

34
		ir_raw_event_store(coredev->ir.dev, &ev);
35
	}
36
	ir_raw_event_handle(coredev->ir.dev);
37 38 39 40
}

int sms_ir_init(struct smscore_device_t *coredev)
{
41
	int err;
42
	int board_id = smscore_get_board_id(coredev);
43
	struct rc_dev *dev;
44

45
	pr_debug("Allocating rc device\n");
46
	dev = rc_allocate_device(RC_DRIVER_IR_RAW);
47
	if (!dev)
48 49 50 51
		return -ENOMEM;

	coredev->ir.controller = 0;	/* Todo: vega/nova SPI number */
	coredev->ir.timeout = IR_DEFAULT_TIMEOUT;
52
	pr_debug("IR port %d, timeout %d ms\n",
53 54
			coredev->ir.controller, coredev->ir.timeout);

55 56
	snprintf(coredev->ir.name, sizeof(coredev->ir.name),
		 "SMS IR (%s)", sms_get_board(board_id)->name);
57 58 59 60

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

61
	dev->device_name = coredev->ir.name;
62 63
	dev->input_phys = coredev->ir.phys;
	dev->dev.parent = coredev->device;
64

65
#if 0
66
	/* TODO: properly initialize the parameters below */
67 68 69 70
	dev->input_id.bustype = BUS_USB;
	dev->input_id.version = 1;
	dev->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
	dev->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
71 72
#endif

73
	dev->priv = coredev;
74
	dev->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
75 76
	dev->map_name = sms_get_board(board_id)->rc_codes;
	dev->driver_name = MODULE_NAME;
77

78
	pr_debug("Input device (IR) %s is set for key events\n",
79
		 dev->device_name);
80

81 82
	err = rc_register_device(dev);
	if (err < 0) {
83
		pr_err("Failed to register device\n");
84 85
		rc_free_device(dev);
		return err;
86 87
	}

88
	coredev->ir.dev = dev;
89 90 91 92 93
	return 0;
}

void sms_ir_exit(struct smscore_device_t *coredev)
{
94
	rc_unregister_device(coredev->ir.dev);
95

96
	pr_debug("\n");
97
}