26 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28 #include <linux/kernel.h>
29 #include <linux/module.h>
33 #include <linux/sched.h>
34 #include <linux/slab.h>
43 fit_dbg(
"%s: reg 0x%02x, val 0x%02x (ip/dp: %02x/%02x)",
44 __func__, reg, val, fintek->
cr_ip, fintek->
cr_dp);
57 fit_dbg(
"%s: reg 0x%02x, val 0x%02x (ip/dp: %02x/%02x)",
58 __func__, reg, val, fintek->
cr_ip, fintek->
cr_dp);
65 u8 tmp = fintek_cr_read(fintek, reg) |
val;
66 fintek_cr_write(fintek, tmp, reg);
72 u8 tmp = fintek_cr_read(fintek, reg) & ~val;
73 fintek_cr_write(fintek, tmp, reg);
77 static inline void fintek_config_mode_enable(
struct fintek_dev *fintek)
85 static inline void fintek_config_mode_disable(
struct fintek_dev *fintek)
94 static inline void fintek_select_logical_dev(
struct fintek_dev *fintek,
u8 ldev)
116 static void cir_dump_regs(
struct fintek_dev *fintek)
118 fintek_config_mode_enable(fintek);
122 pr_info(
" * CR CIR BASE ADDR: 0x%x\n",
125 pr_info(
" * CR CIR IRQ NUM: 0x%x\n",
128 fintek_config_mode_disable(fintek);
137 pr_info(
" * TX_CONTROL: 0x%x\n",
144 static int fintek_hw_detect(
struct fintek_dev *fintek)
147 u8 chip_major, chip_minor;
148 u8 vendor_major, vendor_minor;
149 u8 portsel, ir_class;
153 fintek_config_mode_enable(fintek);
157 if (portsel == 0xff) {
159 fintek_config_mode_disable(fintek);
162 fintek_config_mode_enable(fintek);
165 fit_dbg(
"portsel reg: 0x%02x", portsel);
168 fit_dbg(
"ir_class reg: 0x%02x", ir_class);
183 chip = chip_major << 8 | chip_minor;
187 vendor = vendor_major << 8 | vendor_minor;
192 fit_dbg(
"Read Fintek vendor ID from chip");
194 fintek_config_mode_disable(fintek);
204 if ((chip != 0x0408) && (chip != 0x0804))
209 spin_unlock_irqrestore(&fintek->
fintek_lock, flags);
214 static void fintek_cir_ldev_init(
struct fintek_dev *fintek)
226 fit_dbg(
"CIR initialized, base io address: 0x%lx, irq: %d (len: %d)",
231 static void fintek_enable_cir_irq(
struct fintek_dev *fintek)
236 static void fintek_cir_regs_init(
struct fintek_dev *fintek)
242 fintek_enable_cir_irq(fintek);
245 static void fintek_enable_wake(
struct fintek_dev *fintek)
247 fintek_config_mode_enable(fintek);
259 fintek_config_mode_disable(fintek);
294 static void fintek_process_rx_ir_data(
struct fintek_dev *fintek)
301 for (i = 0; i < fintek->
pkts; i++) {
302 sample = fintek->
buf[
i];
305 fintek->
cmd = sample;
313 fit_dbg(
"%s: rem: 0x%02x", __func__, fintek->
rem);
317 ir_raw_event_reset(fintek->
rdev);
320 fintek->
rem = fintek_cmdsize(fintek->
cmd, sample);
328 init_ir_raw_event(&rawir);
333 fit_dbg(
"Storing %s with duration %d",
334 rawir.pulse ?
"pulse" :
"space",
349 fit_dbg(
"Calling ir_raw_event_handle");
355 static void fintek_get_rx_ir_data(
struct fintek_dev *fintek,
u8 rx_irqs)
369 fit_dbg(
"%s: sample: 0x%02x", __func__, sample);
371 fintek->
buf[fintek->
pkts] = sample;
374 status = fintek_cir_reg_read(fintek,
CIR_STATUS);
377 }
while (status & rx_irqs);
379 fintek_process_rx_ir_data(fintek);
381 spin_unlock_irqrestore(&fintek->
fintek_lock, flags);
384 static void fintek_cir_log_irqs(
u8 status)
402 fintek_config_mode_enable(fintek);
404 fintek_config_mode_disable(fintek);
415 status = fintek_cir_reg_read(fintek,
CIR_STATUS);
418 fintek_cir_reg_write(fintek, CIR_STATUS_IRQ_MASK,
CIR_STATUS);
423 fintek_cir_log_irqs(status);
427 fintek_get_rx_ir_data(fintek, rx_irqs);
430 fintek_cir_reg_write(fintek, status,
CIR_STATUS);
436 static void fintek_enable_cir(
struct fintek_dev *fintek)
441 fintek_config_mode_enable(fintek);
447 fintek_config_mode_disable(fintek);
450 fintek_cir_reg_write(fintek, CIR_STATUS_IRQ_MASK,
CIR_STATUS);
453 fintek_enable_cir_irq(fintek);
456 static void fintek_disable_cir(
struct fintek_dev *fintek)
458 fintek_config_mode_enable(fintek);
464 fintek_config_mode_disable(fintek);
467 static int fintek_open(
struct rc_dev *
dev)
473 fintek_enable_cir(fintek);
474 spin_unlock_irqrestore(&fintek->
fintek_lock, flags);
479 static void fintek_close(
struct rc_dev *
dev)
485 fintek_disable_cir(fintek);
486 spin_unlock_irqrestore(&fintek->
fintek_lock, flags);
507 if (!pnp_port_valid(pdev, 0)) {
508 dev_err(&pdev->
dev,
"IR PNP Port not valid!\n");
512 if (!pnp_irq_valid(pdev, 0)) {
513 dev_err(&pdev->
dev,
"IR PNP IRQ not valid!\n");
517 fintek->
cir_addr = pnp_port_start(pdev, 0);
526 pnp_set_drvdata(pdev, fintek);
529 ret = fintek_hw_detect(fintek);
534 fintek_config_mode_enable(fintek);
535 fintek_cir_ldev_init(fintek);
536 fintek_config_mode_disable(fintek);
539 fintek_cir_regs_init(fintek);
545 rdev->
open = fintek_open;
546 rdev->
close = fintek_close;
553 rdev->
dev.parent = &pdev->
dev;
578 cir_dump_regs(fintek);
595 struct fintek_dev *fintek = pnp_get_drvdata(pdev);
600 fintek_disable_cir(fintek);
601 fintek_cir_reg_write(fintek, CIR_STATUS_IRQ_MASK,
CIR_STATUS);
603 fintek_enable_wake(fintek);
604 spin_unlock_irqrestore(&fintek->
fintek_lock, flags);
617 struct fintek_dev *fintek = pnp_get_drvdata(pdev);
620 fit_dbg(
"%s called", __func__);
625 fintek_cir_reg_write(fintek, CIR_STATUS_IRQ_MASK,
CIR_STATUS);
627 spin_unlock_irqrestore(&fintek->
fintek_lock, flags);
629 fintek_config_mode_enable(fintek);
635 fintek_config_mode_disable(fintek);
638 fintek_enable_wake(fintek);
643 static int fintek_resume(
struct pnp_dev *pdev)
646 struct fintek_dev *fintek = pnp_get_drvdata(pdev);
648 fit_dbg(
"%s called", __func__);
651 fintek_enable_cir_irq(fintek);
654 fintek_config_mode_enable(fintek);
658 fintek_config_mode_disable(fintek);
660 fintek_cir_regs_init(fintek);
665 static void fintek_shutdown(
struct pnp_dev *pdev)
667 struct fintek_dev *fintek = pnp_get_drvdata(pdev);
668 fintek_enable_wake(fintek);
678 .id_table = fintek_ids,
680 .probe = fintek_probe,
682 .suspend = fintek_suspend,
683 .resume = fintek_resume,
684 .shutdown = fintek_shutdown,