18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci Mantis PCI bridge driver 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci Copyright (C) Manu Abraham (abraham.manu@gmail.com) 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci*/ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/module.h> 108c2ecf20Sopenharmony_ci#include <linux/kernel.h> 118c2ecf20Sopenharmony_ci#include <linux/pci.h> 128c2ecf20Sopenharmony_ci#include <linux/slab.h> 138c2ecf20Sopenharmony_ci#include <asm/irq.h> 148c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 158c2ecf20Sopenharmony_ci#include <media/rc-map.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <media/dmxdev.h> 188c2ecf20Sopenharmony_ci#include <media/dvbdev.h> 198c2ecf20Sopenharmony_ci#include <media/dvb_demux.h> 208c2ecf20Sopenharmony_ci#include <media/dvb_frontend.h> 218c2ecf20Sopenharmony_ci#include <media/dvb_net.h> 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#include "mantis_common.h" 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#include "mantis_vp1033.h" 268c2ecf20Sopenharmony_ci#include "mantis_vp1034.h" 278c2ecf20Sopenharmony_ci#include "mantis_vp1041.h" 288c2ecf20Sopenharmony_ci#include "mantis_vp2033.h" 298c2ecf20Sopenharmony_ci#include "mantis_vp2040.h" 308c2ecf20Sopenharmony_ci#include "mantis_vp3030.h" 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#include "mantis_dma.h" 338c2ecf20Sopenharmony_ci#include "mantis_ca.h" 348c2ecf20Sopenharmony_ci#include "mantis_dvb.h" 358c2ecf20Sopenharmony_ci#include "mantis_uart.h" 368c2ecf20Sopenharmony_ci#include "mantis_ioc.h" 378c2ecf20Sopenharmony_ci#include "mantis_pci.h" 388c2ecf20Sopenharmony_ci#include "mantis_i2c.h" 398c2ecf20Sopenharmony_ci#include "mantis_reg.h" 408c2ecf20Sopenharmony_ci#include "mantis_input.h" 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_cistatic unsigned int verbose; 438c2ecf20Sopenharmony_cimodule_param(verbose, int, 0644); 448c2ecf20Sopenharmony_ciMODULE_PARM_DESC(verbose, "verbose startup messages, default is 0 (no)"); 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistatic int devs; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define DRIVER_NAME "Mantis" 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistatic char *label[10] = { 518c2ecf20Sopenharmony_ci "DMA", 528c2ecf20Sopenharmony_ci "IRQ-0", 538c2ecf20Sopenharmony_ci "IRQ-1", 548c2ecf20Sopenharmony_ci "OCERR", 558c2ecf20Sopenharmony_ci "PABRT", 568c2ecf20Sopenharmony_ci "RIPRR", 578c2ecf20Sopenharmony_ci "PPERR", 588c2ecf20Sopenharmony_ci "FTRGT", 598c2ecf20Sopenharmony_ci "RISCI", 608c2ecf20Sopenharmony_ci "RACK" 618c2ecf20Sopenharmony_ci}; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_cistatic irqreturn_t mantis_irq_handler(int irq, void *dev_id) 648c2ecf20Sopenharmony_ci{ 658c2ecf20Sopenharmony_ci u32 stat = 0, mask = 0; 668c2ecf20Sopenharmony_ci u32 rst_stat = 0, rst_mask = 0; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci struct mantis_pci *mantis; 698c2ecf20Sopenharmony_ci struct mantis_ca *ca; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci mantis = (struct mantis_pci *) dev_id; 728c2ecf20Sopenharmony_ci if (unlikely(!mantis)) 738c2ecf20Sopenharmony_ci return IRQ_NONE; 748c2ecf20Sopenharmony_ci ca = mantis->mantis_ca; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci stat = mmread(MANTIS_INT_STAT); 778c2ecf20Sopenharmony_ci mask = mmread(MANTIS_INT_MASK); 788c2ecf20Sopenharmony_ci if (!(stat & mask)) 798c2ecf20Sopenharmony_ci return IRQ_NONE; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci rst_mask = MANTIS_GPIF_WRACK | 828c2ecf20Sopenharmony_ci MANTIS_GPIF_OTHERR | 838c2ecf20Sopenharmony_ci MANTIS_SBUF_WSTO | 848c2ecf20Sopenharmony_ci MANTIS_GPIF_EXTIRQ; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci rst_stat = mmread(MANTIS_GPIF_STATUS); 878c2ecf20Sopenharmony_ci rst_stat &= rst_mask; 888c2ecf20Sopenharmony_ci mmwrite(rst_stat, MANTIS_GPIF_STATUS); 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci mantis->mantis_int_stat = stat; 918c2ecf20Sopenharmony_ci mantis->mantis_int_mask = mask; 928c2ecf20Sopenharmony_ci dprintk(MANTIS_DEBUG, 0, "\n-- Stat=<%02x> Mask=<%02x> --", stat, mask); 938c2ecf20Sopenharmony_ci if (stat & MANTIS_INT_RISCEN) { 948c2ecf20Sopenharmony_ci dprintk(MANTIS_DEBUG, 0, "<%s>", label[0]); 958c2ecf20Sopenharmony_ci } 968c2ecf20Sopenharmony_ci if (stat & MANTIS_INT_IRQ0) { 978c2ecf20Sopenharmony_ci dprintk(MANTIS_DEBUG, 0, "<%s>", label[1]); 988c2ecf20Sopenharmony_ci mantis->gpif_status = rst_stat; 998c2ecf20Sopenharmony_ci wake_up(&ca->hif_write_wq); 1008c2ecf20Sopenharmony_ci schedule_work(&ca->hif_evm_work); 1018c2ecf20Sopenharmony_ci } 1028c2ecf20Sopenharmony_ci if (stat & MANTIS_INT_IRQ1) { 1038c2ecf20Sopenharmony_ci dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]); 1048c2ecf20Sopenharmony_ci spin_lock(&mantis->intmask_lock); 1058c2ecf20Sopenharmony_ci mmwrite(mmread(MANTIS_INT_MASK) & ~MANTIS_INT_IRQ1, 1068c2ecf20Sopenharmony_ci MANTIS_INT_MASK); 1078c2ecf20Sopenharmony_ci spin_unlock(&mantis->intmask_lock); 1088c2ecf20Sopenharmony_ci schedule_work(&mantis->uart_work); 1098c2ecf20Sopenharmony_ci } 1108c2ecf20Sopenharmony_ci if (stat & MANTIS_INT_OCERR) { 1118c2ecf20Sopenharmony_ci dprintk(MANTIS_DEBUG, 0, "<%s>", label[3]); 1128c2ecf20Sopenharmony_ci } 1138c2ecf20Sopenharmony_ci if (stat & MANTIS_INT_PABORT) { 1148c2ecf20Sopenharmony_ci dprintk(MANTIS_DEBUG, 0, "<%s>", label[4]); 1158c2ecf20Sopenharmony_ci } 1168c2ecf20Sopenharmony_ci if (stat & MANTIS_INT_RIPERR) { 1178c2ecf20Sopenharmony_ci dprintk(MANTIS_DEBUG, 0, "<%s>", label[5]); 1188c2ecf20Sopenharmony_ci } 1198c2ecf20Sopenharmony_ci if (stat & MANTIS_INT_PPERR) { 1208c2ecf20Sopenharmony_ci dprintk(MANTIS_DEBUG, 0, "<%s>", label[6]); 1218c2ecf20Sopenharmony_ci } 1228c2ecf20Sopenharmony_ci if (stat & MANTIS_INT_FTRGT) { 1238c2ecf20Sopenharmony_ci dprintk(MANTIS_DEBUG, 0, "<%s>", label[7]); 1248c2ecf20Sopenharmony_ci } 1258c2ecf20Sopenharmony_ci if (stat & MANTIS_INT_RISCI) { 1268c2ecf20Sopenharmony_ci dprintk(MANTIS_DEBUG, 0, "<%s>", label[8]); 1278c2ecf20Sopenharmony_ci mantis->busy_block = (stat & MANTIS_INT_RISCSTAT) >> 28; 1288c2ecf20Sopenharmony_ci tasklet_schedule(&mantis->tasklet); 1298c2ecf20Sopenharmony_ci } 1308c2ecf20Sopenharmony_ci if (stat & MANTIS_INT_I2CDONE) { 1318c2ecf20Sopenharmony_ci dprintk(MANTIS_DEBUG, 0, "<%s>", label[9]); 1328c2ecf20Sopenharmony_ci wake_up(&mantis->i2c_wq); 1338c2ecf20Sopenharmony_ci } 1348c2ecf20Sopenharmony_ci mmwrite(stat, MANTIS_INT_STAT); 1358c2ecf20Sopenharmony_ci stat &= ~(MANTIS_INT_RISCEN | MANTIS_INT_I2CDONE | 1368c2ecf20Sopenharmony_ci MANTIS_INT_I2CRACK | MANTIS_INT_PCMCIA7 | 1378c2ecf20Sopenharmony_ci MANTIS_INT_PCMCIA6 | MANTIS_INT_PCMCIA5 | 1388c2ecf20Sopenharmony_ci MANTIS_INT_PCMCIA4 | MANTIS_INT_PCMCIA3 | 1398c2ecf20Sopenharmony_ci MANTIS_INT_PCMCIA2 | MANTIS_INT_PCMCIA1 | 1408c2ecf20Sopenharmony_ci MANTIS_INT_PCMCIA0 | MANTIS_INT_IRQ1 | 1418c2ecf20Sopenharmony_ci MANTIS_INT_IRQ0 | MANTIS_INT_OCERR | 1428c2ecf20Sopenharmony_ci MANTIS_INT_PABORT | MANTIS_INT_RIPERR | 1438c2ecf20Sopenharmony_ci MANTIS_INT_PPERR | MANTIS_INT_FTRGT | 1448c2ecf20Sopenharmony_ci MANTIS_INT_RISCI); 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci if (stat) 1478c2ecf20Sopenharmony_ci dprintk(MANTIS_DEBUG, 0, "<Unknown> Stat=<%02x> Mask=<%02x>", stat, mask); 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci dprintk(MANTIS_DEBUG, 0, "\n"); 1508c2ecf20Sopenharmony_ci return IRQ_HANDLED; 1518c2ecf20Sopenharmony_ci} 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_cistatic int mantis_pci_probe(struct pci_dev *pdev, 1548c2ecf20Sopenharmony_ci const struct pci_device_id *pci_id) 1558c2ecf20Sopenharmony_ci{ 1568c2ecf20Sopenharmony_ci struct mantis_pci_drvdata *drvdata; 1578c2ecf20Sopenharmony_ci struct mantis_pci *mantis; 1588c2ecf20Sopenharmony_ci struct mantis_hwconfig *config; 1598c2ecf20Sopenharmony_ci int err; 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci mantis = kzalloc(sizeof(*mantis), GFP_KERNEL); 1628c2ecf20Sopenharmony_ci if (!mantis) 1638c2ecf20Sopenharmony_ci return -ENOMEM; 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci drvdata = (void *)pci_id->driver_data; 1668c2ecf20Sopenharmony_ci mantis->num = devs; 1678c2ecf20Sopenharmony_ci mantis->verbose = verbose; 1688c2ecf20Sopenharmony_ci mantis->pdev = pdev; 1698c2ecf20Sopenharmony_ci config = drvdata->hwconfig; 1708c2ecf20Sopenharmony_ci config->irq_handler = &mantis_irq_handler; 1718c2ecf20Sopenharmony_ci mantis->hwconfig = config; 1728c2ecf20Sopenharmony_ci mantis->rc_map_name = drvdata->rc_map_name; 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci spin_lock_init(&mantis->intmask_lock); 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci err = mantis_pci_init(mantis); 1778c2ecf20Sopenharmony_ci if (err) { 1788c2ecf20Sopenharmony_ci dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err); 1798c2ecf20Sopenharmony_ci goto err_free_mantis; 1808c2ecf20Sopenharmony_ci } 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci err = mantis_stream_control(mantis, STREAM_TO_HIF); 1838c2ecf20Sopenharmony_ci if (err < 0) { 1848c2ecf20Sopenharmony_ci dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err); 1858c2ecf20Sopenharmony_ci goto err_pci_exit; 1868c2ecf20Sopenharmony_ci } 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci err = mantis_i2c_init(mantis); 1898c2ecf20Sopenharmony_ci if (err < 0) { 1908c2ecf20Sopenharmony_ci dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err); 1918c2ecf20Sopenharmony_ci goto err_pci_exit; 1928c2ecf20Sopenharmony_ci } 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci err = mantis_get_mac(mantis); 1958c2ecf20Sopenharmony_ci if (err < 0) { 1968c2ecf20Sopenharmony_ci dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err); 1978c2ecf20Sopenharmony_ci goto err_i2c_exit; 1988c2ecf20Sopenharmony_ci } 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci err = mantis_dma_init(mantis); 2018c2ecf20Sopenharmony_ci if (err < 0) { 2028c2ecf20Sopenharmony_ci dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err); 2038c2ecf20Sopenharmony_ci goto err_i2c_exit; 2048c2ecf20Sopenharmony_ci } 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci err = mantis_dvb_init(mantis); 2078c2ecf20Sopenharmony_ci if (err < 0) { 2088c2ecf20Sopenharmony_ci dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err); 2098c2ecf20Sopenharmony_ci goto err_dma_exit; 2108c2ecf20Sopenharmony_ci } 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci err = mantis_input_init(mantis); 2138c2ecf20Sopenharmony_ci if (err < 0) { 2148c2ecf20Sopenharmony_ci dprintk(MANTIS_ERROR, 1, 2158c2ecf20Sopenharmony_ci "ERROR: Mantis DVB initialization failed <%d>", err); 2168c2ecf20Sopenharmony_ci goto err_dvb_exit; 2178c2ecf20Sopenharmony_ci } 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci err = mantis_uart_init(mantis); 2208c2ecf20Sopenharmony_ci if (err < 0) { 2218c2ecf20Sopenharmony_ci dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err); 2228c2ecf20Sopenharmony_ci goto err_input_exit; 2238c2ecf20Sopenharmony_ci } 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci devs++; 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci return 0; 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_cierr_input_exit: 2308c2ecf20Sopenharmony_ci mantis_input_exit(mantis); 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_cierr_dvb_exit: 2338c2ecf20Sopenharmony_ci mantis_dvb_exit(mantis); 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_cierr_dma_exit: 2368c2ecf20Sopenharmony_ci mantis_dma_exit(mantis); 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_cierr_i2c_exit: 2398c2ecf20Sopenharmony_ci mantis_i2c_exit(mantis); 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_cierr_pci_exit: 2428c2ecf20Sopenharmony_ci mantis_pci_exit(mantis); 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_cierr_free_mantis: 2458c2ecf20Sopenharmony_ci kfree(mantis); 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci return err; 2488c2ecf20Sopenharmony_ci} 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_cistatic void mantis_pci_remove(struct pci_dev *pdev) 2518c2ecf20Sopenharmony_ci{ 2528c2ecf20Sopenharmony_ci struct mantis_pci *mantis = pci_get_drvdata(pdev); 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci if (mantis) { 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci mantis_uart_exit(mantis); 2578c2ecf20Sopenharmony_ci mantis_input_exit(mantis); 2588c2ecf20Sopenharmony_ci mantis_dvb_exit(mantis); 2598c2ecf20Sopenharmony_ci mantis_dma_exit(mantis); 2608c2ecf20Sopenharmony_ci mantis_i2c_exit(mantis); 2618c2ecf20Sopenharmony_ci mantis_pci_exit(mantis); 2628c2ecf20Sopenharmony_ci kfree(mantis); 2638c2ecf20Sopenharmony_ci } 2648c2ecf20Sopenharmony_ci return; 2658c2ecf20Sopenharmony_ci} 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_cistatic const struct pci_device_id mantis_pci_table[] = { 2688c2ecf20Sopenharmony_ci MAKE_ENTRY(TECHNISAT, CABLESTAR_HD2, &vp2040_config, 2698c2ecf20Sopenharmony_ci RC_MAP_TECHNISAT_TS35), 2708c2ecf20Sopenharmony_ci MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_10, &vp1041_config, 2718c2ecf20Sopenharmony_ci NULL), 2728c2ecf20Sopenharmony_ci MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_20, &vp1041_config, 2738c2ecf20Sopenharmony_ci NULL), 2748c2ecf20Sopenharmony_ci MAKE_ENTRY(TERRATEC, CINERGY_C, &vp2040_config, 2758c2ecf20Sopenharmony_ci RC_MAP_TERRATEC_CINERGY_C_PCI), 2768c2ecf20Sopenharmony_ci MAKE_ENTRY(TERRATEC, CINERGY_S2_PCI_HD, &vp1041_config, 2778c2ecf20Sopenharmony_ci RC_MAP_TERRATEC_CINERGY_S2_HD), 2788c2ecf20Sopenharmony_ci MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1033_DVB_S, &vp1033_config, 2798c2ecf20Sopenharmony_ci NULL), 2808c2ecf20Sopenharmony_ci MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1034_DVB_S, &vp1034_config, 2818c2ecf20Sopenharmony_ci NULL), 2828c2ecf20Sopenharmony_ci MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1041_DVB_S2, &vp1041_config, 2838c2ecf20Sopenharmony_ci RC_MAP_TWINHAN_DTV_CAB_CI), 2848c2ecf20Sopenharmony_ci MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2033_DVB_C, &vp2033_config, 2858c2ecf20Sopenharmony_ci RC_MAP_TWINHAN_DTV_CAB_CI), 2868c2ecf20Sopenharmony_ci MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2040_DVB_C, &vp2040_config, 2878c2ecf20Sopenharmony_ci NULL), 2888c2ecf20Sopenharmony_ci MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3030_DVB_T, &vp3030_config, 2898c2ecf20Sopenharmony_ci NULL), 2908c2ecf20Sopenharmony_ci { } 2918c2ecf20Sopenharmony_ci}; 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, mantis_pci_table); 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_cistatic struct pci_driver mantis_pci_driver = { 2968c2ecf20Sopenharmony_ci .name = DRIVER_NAME, 2978c2ecf20Sopenharmony_ci .id_table = mantis_pci_table, 2988c2ecf20Sopenharmony_ci .probe = mantis_pci_probe, 2998c2ecf20Sopenharmony_ci .remove = mantis_pci_remove, 3008c2ecf20Sopenharmony_ci}; 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_cimodule_pci_driver(mantis_pci_driver); 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("MANTIS driver"); 3058c2ecf20Sopenharmony_ciMODULE_AUTHOR("Manu Abraham"); 3068c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 307