/* detect hardware features */ static int fintek_hw_detect(struct fintek_dev *fintek) { unsigned long flags; u8 chip_major, chip_minor; u8 vendor_major, vendor_minor; u8 portsel, ir_class; u16 vendor; int ret = 0; fintek_config_mode_enable(fintek); /* Check if we're using config port 0x4e or 0x2e */ portsel = fintek_cr_read(fintek, GCR_CONFIG_PORT_SEL); if (portsel == 0xff) { fit_pr(KERN_INFO, "first portsel read was bunk, trying alt"); fintek_config_mode_disable(fintek); fintek->cr_ip = CR_INDEX_PORT2; fintek->cr_dp = CR_DATA_PORT2; fintek_config_mode_enable(fintek); portsel = fintek_cr_read(fintek, GCR_CONFIG_PORT_SEL); } fit_dbg("portsel reg: 0x%02x", portsel); ir_class = fintek_cir_reg_read(fintek, CIR_CR_CLASS); fit_dbg("ir_class reg: 0x%02x", ir_class); switch (ir_class) { case CLASS_RX_2TX: case CLASS_RX_1TX: fintek->hw_tx_capable = true; break; case CLASS_RX_ONLY: default: fintek->hw_tx_capable = false; break; } chip_major = fintek_cr_read(fintek, GCR_CHIP_ID_HI); chip_minor = fintek_cr_read(fintek, GCR_CHIP_ID_LO); vendor_major = fintek_cr_read(fintek, GCR_VENDOR_ID_HI); vendor_minor = fintek_cr_read(fintek, GCR_VENDOR_ID_LO); vendor = vendor_major << 8 | vendor_minor; if (vendor != VENDOR_ID_FINTEK) fit_pr(KERN_WARNING, "Unknown vendor ID: 0x%04x", vendor); else fit_dbg("Read Fintek vendor ID from chip"); fintek_config_mode_disable(fintek); spin_lock_irqsave(&fintek->fintek_lock, flags); fintek->chip_major = chip_major; fintek->chip_minor = chip_minor; fintek->chip_vendor = vendor; spin_unlock_irqrestore(&fintek->fintek_lock, flags); return ret; }
static void fintek_cir_log_irqs(u8 status) { fit_pr(KERN_INFO, "IRQ 0x%02x:%s%s%s%s%s", status, status & CIR_STATUS_IRQ_EN ? " IRQEN" : "", status & CIR_STATUS_TX_FINISH ? " TXF" : "", status & CIR_STATUS_TX_UNDERRUN ? " TXU" : "", status & CIR_STATUS_RX_TIMEOUT ? " RXTO" : "", status & CIR_STATUS_RX_RECEIVE ? " RXOK" : ""); }
/* Allocate memory, probe hardware, and initialize everything */ static int fintek_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id) { struct fintek_dev *fintek; struct rc_dev *rdev; int ret = -ENOMEM; fintek = kzalloc(sizeof(struct fintek_dev), GFP_KERNEL); if (!fintek) return ret; /* input device for IR remote (and tx) */ rdev = rc_allocate_device(); if (!rdev) goto exit_free_dev_rdev; ret = -ENODEV; /* validate pnp resources */ if (!pnp_port_valid(pdev, 0)) { dev_err(&pdev->dev, "IR PNP Port not valid!\n"); goto exit_free_dev_rdev; } if (!pnp_irq_valid(pdev, 0)) { dev_err(&pdev->dev, "IR PNP IRQ not valid!\n"); goto exit_free_dev_rdev; } fintek->cir_addr = pnp_port_start(pdev, 0); fintek->cir_irq = pnp_irq(pdev, 0); fintek->cir_port_len = pnp_port_len(pdev, 0); fintek->cr_ip = CR_INDEX_PORT; fintek->cr_dp = CR_DATA_PORT; spin_lock_init(&fintek->fintek_lock); pnp_set_drvdata(pdev, fintek); fintek->pdev = pdev; ret = fintek_hw_detect(fintek); if (ret) goto exit_free_dev_rdev; /* Initialize CIR & CIR Wake Logical Devices */ fintek_config_mode_enable(fintek); fintek_cir_ldev_init(fintek); fintek_config_mode_disable(fintek); /* Initialize CIR & CIR Wake Config Registers */ fintek_cir_regs_init(fintek); /* Set up the rc device */ rdev->priv = fintek; rdev->driver_type = RC_DRIVER_IR_RAW; rdev->allowed_protocols = RC_BIT_ALL; rdev->open = fintek_open; rdev->close = fintek_close; rdev->input_name = FINTEK_DESCRIPTION; rdev->input_phys = "fintek/cir0"; rdev->input_id.bustype = BUS_HOST; rdev->input_id.vendor = VENDOR_ID_FINTEK; rdev->input_id.product = fintek->chip_major; rdev->input_id.version = fintek->chip_minor; rdev->dev.parent = &pdev->dev; rdev->driver_name = FINTEK_DRIVER_NAME; rdev->map_name = RC_MAP_RC6_MCE; rdev->timeout = US_TO_NS(1000); /* rx resolution is hardwired to 50us atm, 1, 25, 100 also possible */ rdev->rx_resolution = US_TO_NS(CIR_SAMPLE_PERIOD); fintek->rdev = rdev; ret = -EBUSY; /* now claim resources */ if (!request_region(fintek->cir_addr, fintek->cir_port_len, FINTEK_DRIVER_NAME)) goto exit_free_dev_rdev; if (request_irq(fintek->cir_irq, fintek_cir_isr, IRQF_SHARED, FINTEK_DRIVER_NAME, (void *)fintek)) goto exit_free_cir_addr; ret = rc_register_device(rdev); if (ret) goto exit_free_irq; device_init_wakeup(&pdev->dev, true); fit_pr(KERN_NOTICE, "driver has been successfully loaded\n"); if (debug) cir_dump_regs(fintek); return 0; exit_free_irq: free_irq(fintek->cir_irq, fintek); exit_free_cir_addr: release_region(fintek->cir_addr, fintek->cir_port_len); exit_free_dev_rdev: rc_free_device(rdev); kfree(fintek); return ret; }