Lines Matching full:ir
3 * Driver for Amlogic Meson IR remote receiver
21 #define DRIVER_NAME "meson-ir"
54 /* Meson 6b uses REG1 to configure IR mode */
64 /* Meson 8b / GXBB use REG2 to configure IR mode */
97 * struct meson_ir_protocol - describe IR Protocol parameter
99 * @hw_protocol: select IR Protocol from IR Controller
104 * Some IR Protocol send the same data as repeat frame.
188 static void meson_ir_nec_handler(struct meson_ir *ir) in meson_ir_nec_handler() argument
194 regmap_read(ir->reg, IR_DEC_STATUS, &status); in meson_ir_nec_handler()
197 rc_repeat(ir->rc); in meson_ir_nec_handler()
199 regmap_read(ir->reg, IR_DEC_FRAME, &code); in meson_ir_nec_handler()
203 rc_keydown(ir->rc, proto, code, 0); in meson_ir_nec_handler()
207 static void meson_ir_hw_handler(struct meson_ir *ir) in meson_ir_hw_handler() argument
209 if (ir->rc->enabled_protocols & RC_PROTO_BIT_NEC) in meson_ir_hw_handler()
210 meson_ir_nec_handler(ir); in meson_ir_hw_handler()
215 struct meson_ir *ir = dev_id; in meson_ir_irq() local
219 spin_lock(&ir->lock); in meson_ir_irq()
221 regmap_read(ir->reg, IR_DEC_STATUS, &status); in meson_ir_irq()
223 if (ir->rc->driver_type == RC_DRIVER_IR_RAW) { in meson_ir_irq()
226 regmap_read(ir->reg, IR_DEC_REG1, &duration); in meson_ir_irq()
230 ir_raw_event_store_with_timeout(ir->rc, &rawir); in meson_ir_irq()
231 } else if (ir->rc->driver_type == RC_DRIVER_SCANCODE) { in meson_ir_irq()
233 meson_ir_hw_handler(ir); in meson_ir_irq()
236 spin_unlock(&ir->lock); in meson_ir_irq()
248 struct meson_ir *ir = dev->priv; in meson_ir_hw_decoder_init() local
266 spin_lock_irqsave(&ir->lock, flags); in meson_ir_hw_decoder_init()
269 regmap_read(ir->reg, IR_DEC_STATUS, ®val); in meson_ir_hw_decoder_init()
270 regmap_read(ir->reg, IR_DEC_FRAME, ®val); in meson_ir_hw_decoder_init()
272 /* Reset ir decoder and disable decoder */ in meson_ir_hw_decoder_init()
273 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_ENABLE, 0); in meson_ir_hw_decoder_init()
274 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_RESET, in meson_ir_hw_decoder_init()
279 regmap_update_bits(ir->reg, IR_DEC_REG0, IR_DEC_REG0_BASE_TIME, regval); in meson_ir_hw_decoder_init()
282 regmap_update_bits(ir->reg, IR_DEC_REG0, IR_DEC_REG0_FILTER, in meson_ir_hw_decoder_init()
287 regmap_update_bits(ir->reg, IR_DEC_REG2, IR_DEC_REG2_MODE, regval); in meson_ir_hw_decoder_init()
290 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_HOLD_CODE, in meson_ir_hw_decoder_init()
295 regmap_update_bits(ir->reg, IR_DEC_REG2, IR_DEC_REG2_BIT_ORDER, in meson_ir_hw_decoder_init()
299 regmap_update_bits(ir->reg, IR_DEC_REG2, IR_DEC_REG2_TICK_MODE, in meson_ir_hw_decoder_init()
308 regmap_update_bits(ir->reg, IR_DEC_REG2, IR_DEC_REG2_REPEAT_COUNTER, in meson_ir_hw_decoder_init()
311 regmap_update_bits(ir->reg, IR_DEC_REG2, IR_DEC_REG2_REPEAT_TIME, in meson_ir_hw_decoder_init()
314 regmap_update_bits(ir->reg, IR_DEC_REG2, IR_DEC_REG2_COMPARE_FRAME, in meson_ir_hw_decoder_init()
324 regmap_update_bits(ir->reg, IR_DEC_REG0, IR_DEC_REG0_FRAME_TIME_MAX, in meson_ir_hw_decoder_init()
329 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_FRAME_LEN, regval); in meson_ir_hw_decoder_init()
336 regmap_update_bits(ir->reg, IR_DEC_LDR_ACTIVE, IR_DEC_LDR_ACTIVE_MAX | in meson_ir_hw_decoder_init()
342 regmap_update_bits(ir->reg, IR_DEC_LDR_IDLE, in meson_ir_hw_decoder_init()
348 regmap_update_bits(ir->reg, IR_DEC_LDR_REPEAT, IR_DEC_LDR_REPEAT_MAX | in meson_ir_hw_decoder_init()
357 regmap_update_bits(ir->reg, IR_DEC_BIT_0, in meson_ir_hw_decoder_init()
366 regmap_update_bits(ir->reg, IR_DEC_STATUS, IR_DEC_STATUS_BIT_1_MAX | in meson_ir_hw_decoder_init()
370 regmap_update_bits(ir->reg, IR_DEC_STATUS, IR_DEC_STATUS_BIT_1_ENABLE, in meson_ir_hw_decoder_init()
380 regmap_update_bits(ir->reg, IR_DEC_DURATN2, in meson_ir_hw_decoder_init()
389 regmap_update_bits(ir->reg, IR_DEC_DURATN3, in meson_ir_hw_decoder_init()
392 /* Reset ir decoder and enable decode */ in meson_ir_hw_decoder_init()
393 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_RESET, in meson_ir_hw_decoder_init()
395 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_RESET, 0); in meson_ir_hw_decoder_init()
396 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_ENABLE, in meson_ir_hw_decoder_init()
399 spin_unlock_irqrestore(&ir->lock, flags); in meson_ir_hw_decoder_init()
409 struct meson_ir *ir = dev->priv; in meson_ir_sw_decoder_init() local
411 spin_lock_irqsave(&ir->lock, flags); in meson_ir_sw_decoder_init()
414 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_RESET, in meson_ir_sw_decoder_init()
416 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_RESET, 0); in meson_ir_sw_decoder_init()
419 if (of_device_is_compatible(dev->dev.of_node, "amlogic,meson6-ir")) in meson_ir_sw_decoder_init()
420 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_MODE, in meson_ir_sw_decoder_init()
424 regmap_update_bits(ir->reg, IR_DEC_REG2, IR_DEC_REG2_MODE, in meson_ir_sw_decoder_init()
429 regmap_update_bits(ir->reg, IR_DEC_REG0, IR_DEC_REG0_BASE_TIME, in meson_ir_sw_decoder_init()
433 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_IRQSEL, in meson_ir_sw_decoder_init()
436 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_ENABLE, in meson_ir_sw_decoder_init()
439 spin_unlock_irqrestore(&ir->lock, flags); in meson_ir_sw_decoder_init()
451 struct meson_ir *ir; in meson_ir_probe() local
454 ir = devm_kzalloc(dev, sizeof(struct meson_ir), GFP_KERNEL); in meson_ir_probe()
455 if (!ir) in meson_ir_probe()
462 ir->param = match_data; in meson_ir_probe()
468 meson_ir_regmap_config.max_register = ir->param->max_register; in meson_ir_probe()
469 ir->reg = devm_regmap_init_mmio(&pdev->dev, res_start, in meson_ir_probe()
471 if (IS_ERR(ir->reg)) in meson_ir_probe()
472 return PTR_ERR(ir->reg); in meson_ir_probe()
478 if (ir->param->support_hw_decoder) in meson_ir_probe()
479 ir->rc = devm_rc_allocate_device(&pdev->dev, in meson_ir_probe()
482 ir->rc = devm_rc_allocate_device(&pdev->dev, RC_DRIVER_IR_RAW); in meson_ir_probe()
484 if (!ir->rc) { in meson_ir_probe()
489 if (ir->rc->driver_type == RC_DRIVER_IR_RAW) { in meson_ir_probe()
490 ir->rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER; in meson_ir_probe()
491 ir->rc->rx_resolution = MESON_RAW_TRATE; in meson_ir_probe()
492 ir->rc->min_timeout = 1; in meson_ir_probe()
493 ir->rc->timeout = IR_DEFAULT_TIMEOUT; in meson_ir_probe()
494 ir->rc->max_timeout = 10 * IR_DEFAULT_TIMEOUT; in meson_ir_probe()
495 } else if (ir->rc->driver_type == RC_DRIVER_SCANCODE) { in meson_ir_probe()
496 ir->rc->allowed_protocols = RC_PROTO_BIT_NEC; in meson_ir_probe()
497 ir->rc->change_protocol = meson_ir_hw_decoder_init; in meson_ir_probe()
500 ir->rc->priv = ir; in meson_ir_probe()
501 ir->rc->device_name = DRIVER_NAME; in meson_ir_probe()
502 ir->rc->input_phys = DRIVER_NAME "/input0"; in meson_ir_probe()
503 ir->rc->input_id.bustype = BUS_HOST; in meson_ir_probe()
505 ir->rc->map_name = map_name ? map_name : RC_MAP_EMPTY; in meson_ir_probe()
506 ir->rc->driver_name = DRIVER_NAME; in meson_ir_probe()
508 spin_lock_init(&ir->lock); in meson_ir_probe()
509 platform_set_drvdata(pdev, ir); in meson_ir_probe()
511 ret = devm_rc_register_device(dev, ir->rc); in meson_ir_probe()
517 if (ir->rc->driver_type == RC_DRIVER_IR_RAW) in meson_ir_probe()
518 meson_ir_sw_decoder_init(ir->rc); in meson_ir_probe()
520 ret = devm_request_irq(dev, irq, meson_ir_irq, 0, "meson_ir", ir); in meson_ir_probe()
533 struct meson_ir *ir = platform_get_drvdata(pdev); in meson_ir_remove() local
537 spin_lock_irqsave(&ir->lock, flags); in meson_ir_remove()
538 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_ENABLE, 0); in meson_ir_remove()
539 spin_unlock_irqrestore(&ir->lock, flags); in meson_ir_remove()
546 struct meson_ir *ir = platform_get_drvdata(pdev); in meson_ir_shutdown() local
549 spin_lock_irqsave(&ir->lock, flags); in meson_ir_shutdown()
555 if (of_device_is_compatible(node, "amlogic,meson6-ir")) in meson_ir_shutdown()
556 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_MODE, in meson_ir_shutdown()
559 regmap_update_bits(ir->reg, IR_DEC_REG2, IR_DEC_REG2_MODE, in meson_ir_shutdown()
563 regmap_update_bits(ir->reg, IR_DEC_REG0, IR_DEC_REG0_BASE_TIME, in meson_ir_shutdown()
567 spin_unlock_irqrestore(&ir->lock, flags); in meson_ir_shutdown()
572 struct meson_ir *ir = dev_get_drvdata(dev); in meson_ir_resume() local
574 if (ir->param->support_hw_decoder) in meson_ir_resume()
575 meson_ir_hw_decoder_init(ir->rc, &ir->rc->enabled_protocols); in meson_ir_resume()
577 meson_ir_sw_decoder_init(ir->rc); in meson_ir_resume()
584 struct meson_ir *ir = dev_get_drvdata(dev); in meson_ir_suspend() local
587 spin_lock_irqsave(&ir->lock, flags); in meson_ir_suspend()
588 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_ENABLE, 0); in meson_ir_suspend()
589 spin_unlock_irqrestore(&ir->lock, flags); in meson_ir_suspend()
613 .compatible = "amlogic,meson6-ir",
616 .compatible = "amlogic,meson8b-ir",
619 .compatible = "amlogic,meson-gxbb-ir",
622 .compatible = "amlogic,meson-s4-ir",
642 MODULE_DESCRIPTION("Amlogic Meson IR remote receiver driver");