Lines Matching +full:rx +full:- +full:enable

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2014 Alexsey Shestacov <wingrime@linux-sunxi.org>
8 * Based on sun5i-ir.c:
9 * Copyright (C) 2007-2012 Daniel Wang
18 #include <media/rc-core.h>
20 #define SUNXI_IR_DEV "sunxi-ir"
25 /* Global Enable */
27 /* RX block enable */
32 /* Rx Config */
37 /* Rx Data */
40 /* Rx Interrupt Enable */
42 /* Rx FIFO Overflow Interrupt Enable */
44 /* Rx Packet End Interrupt Enable */
46 /* Rx FIFO Data Available Interrupt Enable */
49 /* Rx FIFO available byte level */
52 /* Rx Interrupt Status */
54 /* Rx FIFO Overflow */
56 /* Rx Packet End */
58 /* Rx FIFO Data Available */
60 /* RX FIFO Get Available Counter */
61 #define REG_RXSTA_GET_AC(val) (((val) >> 8) & (ir->fifo_size * 2 - 1))
82 * struct sunxi_ir_quirks - Differences between SoC variants.
112 spin_lock(&ir->ir_lock); in sunxi_ir_irq()
114 status = readl(ir->base + SUNXI_IR_RXSTA_REG); in sunxi_ir_irq()
117 writel(status | REG_RXSTA_CLEARALL, ir->base + SUNXI_IR_RXSTA_REG); in sunxi_ir_irq()
123 rc = rc > ir->fifo_size ? ir->fifo_size : rc; in sunxi_ir_irq()
127 dt = readb(ir->base + SUNXI_IR_RXFIFO_REG); in sunxi_ir_irq()
130 ir->rc->rx_resolution; in sunxi_ir_irq()
131 ir_raw_event_store_with_filter(ir->rc, &rawir); in sunxi_ir_irq()
136 ir_raw_event_reset(ir->rc); in sunxi_ir_irq()
138 ir_raw_event_set_idle(ir->rc, true); in sunxi_ir_irq()
139 ir_raw_event_handle(ir->rc); in sunxi_ir_irq()
142 spin_unlock(&ir->ir_lock); in sunxi_ir_irq()
152 struct device *dev = &pdev->dev; in sunxi_ir_probe()
153 struct device_node *dn = dev->of_node; in sunxi_ir_probe()
161 return -ENOMEM; in sunxi_ir_probe()
163 quirks = of_device_get_match_data(&pdev->dev); in sunxi_ir_probe()
165 dev_err(&pdev->dev, "Failed to determine the quirks to use\n"); in sunxi_ir_probe()
166 return -ENODEV; in sunxi_ir_probe()
169 spin_lock_init(&ir->ir_lock); in sunxi_ir_probe()
171 ir->fifo_size = quirks->fifo_size; in sunxi_ir_probe()
174 ir->apb_clk = devm_clk_get(dev, "apb"); in sunxi_ir_probe()
175 if (IS_ERR(ir->apb_clk)) { in sunxi_ir_probe()
177 return PTR_ERR(ir->apb_clk); in sunxi_ir_probe()
179 ir->clk = devm_clk_get(dev, "ir"); in sunxi_ir_probe()
180 if (IS_ERR(ir->clk)) { in sunxi_ir_probe()
182 return PTR_ERR(ir->clk); in sunxi_ir_probe()
186 of_property_read_u32(dn, "clock-frequency", &b_clk_freq); in sunxi_ir_probe()
189 if (quirks->has_reset) { in sunxi_ir_probe()
190 ir->rst = devm_reset_control_get_exclusive(dev, NULL); in sunxi_ir_probe()
191 if (IS_ERR(ir->rst)) in sunxi_ir_probe()
192 return PTR_ERR(ir->rst); in sunxi_ir_probe()
193 ret = reset_control_deassert(ir->rst); in sunxi_ir_probe()
198 ret = clk_set_rate(ir->clk, b_clk_freq); in sunxi_ir_probe()
205 if (clk_prepare_enable(ir->apb_clk)) { in sunxi_ir_probe()
206 dev_err(dev, "try to enable apb_ir_clk failed\n"); in sunxi_ir_probe()
207 ret = -EINVAL; in sunxi_ir_probe()
211 if (clk_prepare_enable(ir->clk)) { in sunxi_ir_probe()
212 dev_err(dev, "try to enable ir_clk failed\n"); in sunxi_ir_probe()
213 ret = -EINVAL; in sunxi_ir_probe()
219 ir->base = devm_ioremap_resource(dev, res); in sunxi_ir_probe()
220 if (IS_ERR(ir->base)) { in sunxi_ir_probe()
221 ret = PTR_ERR(ir->base); in sunxi_ir_probe()
225 ir->rc = rc_allocate_device(RC_DRIVER_IR_RAW); in sunxi_ir_probe()
226 if (!ir->rc) { in sunxi_ir_probe()
228 ret = -ENOMEM; in sunxi_ir_probe()
232 ir->rc->priv = ir; in sunxi_ir_probe()
233 ir->rc->device_name = SUNXI_IR_DEV; in sunxi_ir_probe()
234 ir->rc->input_phys = "sunxi-ir/input0"; in sunxi_ir_probe()
235 ir->rc->input_id.bustype = BUS_HOST; in sunxi_ir_probe()
236 ir->rc->input_id.vendor = 0x0001; in sunxi_ir_probe()
237 ir->rc->input_id.product = 0x0001; in sunxi_ir_probe()
238 ir->rc->input_id.version = 0x0100; in sunxi_ir_probe()
239 ir->map_name = of_get_property(dn, "linux,rc-map-name", NULL); in sunxi_ir_probe()
240 ir->rc->map_name = ir->map_name ?: RC_MAP_EMPTY; in sunxi_ir_probe()
241 ir->rc->dev.parent = dev; in sunxi_ir_probe()
242 ir->rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER; in sunxi_ir_probe()
244 ir->rc->rx_resolution = (USEC_PER_SEC / (b_clk_freq / 64)); in sunxi_ir_probe()
245 ir->rc->timeout = MS_TO_US(SUNXI_IR_TIMEOUT); in sunxi_ir_probe()
246 ir->rc->driver_name = SUNXI_IR_DEV; in sunxi_ir_probe()
248 ret = rc_register_device(ir->rc); in sunxi_ir_probe()
257 ir->irq = platform_get_irq(pdev, 0); in sunxi_ir_probe()
258 if (ir->irq < 0) { in sunxi_ir_probe()
259 ret = ir->irq; in sunxi_ir_probe()
263 ret = devm_request_irq(dev, ir->irq, sunxi_ir_irq, 0, SUNXI_IR_DEV, ir); in sunxi_ir_probe()
269 /* Enable CIR Mode */ in sunxi_ir_probe()
270 writel(REG_CTL_MD, ir->base+SUNXI_IR_CTL_REG); in sunxi_ir_probe()
274 ir->base + SUNXI_IR_CIR_REG); in sunxi_ir_probe()
277 writel(REG_RXCTL_RPPI, ir->base + SUNXI_IR_RXCTL_REG); in sunxi_ir_probe()
279 /* Clear All Rx Interrupt Status */ in sunxi_ir_probe()
280 writel(REG_RXSTA_CLEARALL, ir->base + SUNXI_IR_RXSTA_REG); in sunxi_ir_probe()
283 * Enable IRQ on overflow, packet end, FIFO available with trigger in sunxi_ir_probe()
287 REG_RXINT_RAI_EN | REG_RXINT_RAL(ir->fifo_size / 2 - 1), in sunxi_ir_probe()
288 ir->base + SUNXI_IR_RXINT_REG); in sunxi_ir_probe()
290 /* Enable IR Module */ in sunxi_ir_probe()
291 tmp = readl(ir->base + SUNXI_IR_CTL_REG); in sunxi_ir_probe()
292 writel(tmp | REG_CTL_GEN | REG_CTL_RXEN, ir->base + SUNXI_IR_CTL_REG); in sunxi_ir_probe()
298 rc_free_device(ir->rc); in sunxi_ir_probe()
300 clk_disable_unprepare(ir->clk); in sunxi_ir_probe()
302 clk_disable_unprepare(ir->apb_clk); in sunxi_ir_probe()
304 reset_control_assert(ir->rst); in sunxi_ir_probe()
314 clk_disable_unprepare(ir->clk); in sunxi_ir_remove()
315 clk_disable_unprepare(ir->apb_clk); in sunxi_ir_remove()
316 reset_control_assert(ir->rst); in sunxi_ir_remove()
318 spin_lock_irqsave(&ir->ir_lock, flags); in sunxi_ir_remove()
320 writel(0, ir->base + SUNXI_IR_RXINT_REG); in sunxi_ir_remove()
321 /* clear All Rx Interrupt Status */ in sunxi_ir_remove()
322 writel(REG_RXSTA_CLEARALL, ir->base + SUNXI_IR_RXSTA_REG); in sunxi_ir_remove()
324 writel(0, ir->base + SUNXI_IR_CTL_REG); in sunxi_ir_remove()
325 spin_unlock_irqrestore(&ir->ir_lock, flags); in sunxi_ir_remove()
327 rc_unregister_device(ir->rc); in sunxi_ir_remove()
348 .compatible = "allwinner,sun4i-a10-ir",
352 .compatible = "allwinner,sun5i-a13-ir",
356 .compatible = "allwinner,sun6i-a31-ir",
375 MODULE_AUTHOR("Alexsey Shestacov <wingrime@linux-sunxi.org>");