Lines Matching +full:ir +full:- +full:spi +full:- +full:led
1 // SPDX-License-Identifier: GPL-2.0
2 // SPI driven IR LED device driver
15 #include <linux/spi/spi.h>
19 #include <media/rc-core.h>
21 #define IR_SPI_DRIVER_NAME "ir-spi"
35 struct spi_device *spi; member
44 struct ir_spi_data *idata = dev->priv; in ir_spi_tx()
53 periods = DIV_ROUND_CLOSEST(buffer[i] * idata->freq, 1000000); in ir_spi_tx()
56 return -EINVAL; in ir_spi_tx()
63 val = (i % 2) ? idata->space : idata->pulse; in ir_spi_tx()
65 idata->tx_buf[len++] = val; in ir_spi_tx()
70 xfer.speed_hz = idata->freq * 16; in ir_spi_tx()
71 xfer.len = len * sizeof(*idata->tx_buf); in ir_spi_tx()
72 xfer.tx_buf = idata->tx_buf; in ir_spi_tx()
74 ret = regulator_enable(idata->regulator); in ir_spi_tx()
78 ret = spi_sync_transfer(idata->spi, &xfer, 1); in ir_spi_tx()
80 dev_err(&idata->spi->dev, "unable to deliver the signal\n"); in ir_spi_tx()
82 regulator_disable(idata->regulator); in ir_spi_tx()
89 struct ir_spi_data *idata = dev->priv; in ir_spi_set_tx_carrier()
92 return -EINVAL; in ir_spi_set_tx_carrier()
94 idata->freq = carrier; in ir_spi_set_tx_carrier()
101 struct ir_spi_data *idata = dev->priv; in ir_spi_set_duty_cycle()
104 idata->pulse = GENMASK(bits, 0); in ir_spi_set_duty_cycle()
106 if (idata->negated) { in ir_spi_set_duty_cycle()
107 idata->pulse = ~idata->pulse; in ir_spi_set_duty_cycle()
108 idata->space = 0xffff; in ir_spi_set_duty_cycle()
110 idata->space = 0; in ir_spi_set_duty_cycle()
116 static int ir_spi_probe(struct spi_device *spi) in ir_spi_probe() argument
118 struct device *dev = &spi->dev; in ir_spi_probe()
125 return -ENOMEM; in ir_spi_probe()
127 idata->regulator = devm_regulator_get(dev, "irda_regulator"); in ir_spi_probe()
128 if (IS_ERR(idata->regulator)) in ir_spi_probe()
129 return PTR_ERR(idata->regulator); in ir_spi_probe()
131 idata->rc = devm_rc_allocate_device(&spi->dev, RC_DRIVER_IR_RAW_TX); in ir_spi_probe()
132 if (!idata->rc) in ir_spi_probe()
133 return -ENOMEM; in ir_spi_probe()
135 idata->rc->tx_ir = ir_spi_tx; in ir_spi_probe()
136 idata->rc->s_tx_carrier = ir_spi_set_tx_carrier; in ir_spi_probe()
137 idata->rc->s_tx_duty_cycle = ir_spi_set_duty_cycle; in ir_spi_probe()
138 idata->rc->device_name = "IR SPI"; in ir_spi_probe()
139 idata->rc->driver_name = IR_SPI_DRIVER_NAME; in ir_spi_probe()
140 idata->rc->priv = idata; in ir_spi_probe()
141 idata->spi = spi; in ir_spi_probe()
143 idata->negated = device_property_read_bool(dev, "led-active-low"); in ir_spi_probe()
144 ret = device_property_read_u8(dev, "duty-cycle", &dc); in ir_spi_probe()
150 * to be compatible with the rc->s_tx_duty_cycle function. in ir_spi_probe()
152 ir_spi_set_duty_cycle(idata->rc, dc); in ir_spi_probe()
154 idata->freq = IR_SPI_DEFAULT_FREQUENCY; in ir_spi_probe()
156 return devm_rc_register_device(dev, idata->rc); in ir_spi_probe()
160 { .compatible = "ir-spi-led" },
166 { "ir-spi-led" },
169 MODULE_DEVICE_TABLE(spi, ir_spi_ids);
182 MODULE_DESCRIPTION("SPI IR LED");