[media] rc: ir-spi: add support for IR LEDs connected with SPI
The ir-spi is a simple device driver which supports the
connection between an IR LED and the MOSI line of an SPI device.
The driver, indeed, uses the SPI framework to stream the raw data
provided by userspace through a character device. The chardev is
handled by the LIRC framework and its functionality basically
provides:
- raw write: data to be sent to the SPI and then streamed to the
MOSI line;
- set frequency: sets the frequency whith which the data should
be sent;
- set length: sets the data length. This information is
optional, if the length is set, then userspace should send raw
data only with that length; while if the length is set to '0',
then the driver will figure out himself the length of the data
based on the length of the data written on the character
device.
The latter is not recommended, though, as the driver, at
any write, allocates and deallocates a buffer where the data
from userspace are stored.
The driver provides three feedback commands:
- get length: reads the length set and (as mentioned), if the
length is '0' it will be calculated at any write
- get frequency: the driver reports the frequency. If userpace
doesn't set the frequency, the driver will use a default value
of 38000Hz.
The character device is created under /dev/lircX name, where X is
and ID assigned by the LIRC framework.
Example of usage:
int fd, ret;
ssize_t n;
uint32_t val = 0;
fd = open("/dev/lirc0", O_RDWR);
if (fd < 0) {
fprintf(stderr, "unable to open the device\n");
return -1;
}
/* ioctl set frequency and length parameters */
val = 6430;
ret = ioctl(fd, LIRC_SET_LENGTH, &val);
if (ret < 0)
fprintf(stderr, "LIRC_SET_LENGTH failed\n");
val = 608000;
ret = ioctl(fd, LIRC_SET_FREQUENCY, &val);
if (ret < 0)
fprintf(stderr, "LIRC_SET_FREQUENCY failed\n");
/* read back length and frequency parameters */
ret = ioctl(fd, LIRC_GET_LENGTH, &val);
if (ret < 0)
fprintf(stderr, "LIRC_GET_LENGTH failed\n");
else
fprintf(stdout, "legnth = %u\n", val);
ret = ioctl(fd, LIRC_GET_FREQUENCY, &val);
if (ret < 0)
fprintf(stderr, "LIRC_GET_FREQUENCY failed\n");
else
fprintf(stdout, "frequency = %u\n", val);
/* write data to device */
n = write(fd, b, 6430);
if (n < 0) {
fprintf(stderr, "unable to write to the device\n");
ret = -1;
} else if (n != 6430) {
fprintf(stderr, "failed to write everything, wrote %ld instead\n", n);
ret = -1;
} else {
fprintf(stdout, "written all the %ld data\n", n);
}
close(fd);
The driver supports multi task access, but all the processes
which hold the driver should use the same length and frequency
parameters.
Change-Id: I323d7dd4a56d6dcf48f2c695293822eb04bdb85f
Signed-off-by: Andi Shyti <andi.shyti@samsung.com>