1 /* 2 * netup_unidvb.h 3 * 4 * Data type definitions for NetUP Universal Dual DVB-CI 5 * 6 * Copyright (C) 2014 NetUP Inc. 7 * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru> 8 * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru> 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 */ 20 21 #include <linux/pci.h> 22 #include <linux/i2c.h> 23 #include <linux/workqueue.h> 24 #include <media/v4l2-common.h> 25 #include <media/v4l2-device.h> 26 #include <media/videobuf2-dvb.h> 27 #include <media/dvb_ca_en50221.h> 28 29 #define NETUP_UNIDVB_NAME "netup_unidvb" 30 #define NETUP_UNIDVB_VERSION "0.0.1" 31 #define NETUP_VENDOR_ID 0x1b55 32 #define NETUP_PCI_DEV_REVISION 0x2 33 34 /* IRQ-related regisers */ 35 #define REG_ISR 0x4890 36 #define REG_ISR_MASKED 0x4892 37 #define REG_IMASK_SET 0x4894 38 #define REG_IMASK_CLEAR 0x4896 39 /* REG_ISR register bits */ 40 #define NETUP_UNIDVB_IRQ_SPI (1 << 0) 41 #define NETUP_UNIDVB_IRQ_I2C0 (1 << 1) 42 #define NETUP_UNIDVB_IRQ_I2C1 (1 << 2) 43 #define NETUP_UNIDVB_IRQ_FRA0 (1 << 4) 44 #define NETUP_UNIDVB_IRQ_FRA1 (1 << 5) 45 #define NETUP_UNIDVB_IRQ_FRB0 (1 << 6) 46 #define NETUP_UNIDVB_IRQ_FRB1 (1 << 7) 47 #define NETUP_UNIDVB_IRQ_DMA1 (1 << 8) 48 #define NETUP_UNIDVB_IRQ_DMA2 (1 << 9) 49 #define NETUP_UNIDVB_IRQ_CI (1 << 10) 50 #define NETUP_UNIDVB_IRQ_CAM0 (1 << 11) 51 #define NETUP_UNIDVB_IRQ_CAM1 (1 << 12) 52 53 /* NetUP Universal DVB card hardware revisions and it's PCI device id's: 54 * 1.3 - CXD2841ER demod, ASCOT2E and HORUS3A tuners 55 * 1.4 - CXD2854ER demod, HELENE tuner 56 */ 57 enum netup_hw_rev { 58 NETUP_HW_REV_1_3 = 0x18F6, 59 NETUP_HW_REV_1_4 = 0x18F7 60 }; 61 62 struct netup_dma { 63 u8 num; 64 spinlock_t lock; 65 struct netup_unidvb_dev *ndev; 66 struct netup_dma_regs __iomem *regs; 67 u32 ring_buffer_size; 68 u8 *addr_virt; 69 dma_addr_t addr_phys; 70 u64 addr_last; 71 u32 high_addr; 72 u32 data_offset; 73 u32 data_size; 74 struct list_head free_buffers; 75 struct work_struct work; 76 struct timer_list timeout; 77 }; 78 79 enum netup_i2c_state { 80 STATE_DONE, 81 STATE_WAIT, 82 STATE_WANT_READ, 83 STATE_WANT_WRITE, 84 STATE_ERROR 85 }; 86 87 struct netup_i2c_regs; 88 89 struct netup_i2c { 90 spinlock_t lock; 91 wait_queue_head_t wq; 92 struct i2c_adapter adap; 93 struct netup_unidvb_dev *dev; 94 struct netup_i2c_regs __iomem *regs; 95 struct i2c_msg *msg; 96 enum netup_i2c_state state; 97 u32 xmit_size; 98 }; 99 100 struct netup_ci_state { 101 struct dvb_ca_en50221 ca; 102 u8 __iomem *membase8_config; 103 u8 __iomem *membase8_io; 104 struct netup_unidvb_dev *dev; 105 int status; 106 int nr; 107 }; 108 109 struct netup_spi; 110 111 struct netup_unidvb_dev { 112 struct pci_dev *pci_dev; 113 int pci_bus; 114 int pci_slot; 115 int pci_func; 116 int board_num; 117 int old_fw; 118 u32 __iomem *lmmio0; 119 u8 __iomem *bmmio0; 120 u32 __iomem *lmmio1; 121 u8 __iomem *bmmio1; 122 u8 *dma_virt; 123 dma_addr_t dma_phys; 124 u32 dma_size; 125 struct vb2_dvb_frontends frontends[2]; 126 struct netup_i2c i2c[2]; 127 struct workqueue_struct *wq; 128 struct netup_dma dma[2]; 129 struct netup_ci_state ci[2]; 130 struct netup_spi *spi; 131 enum netup_hw_rev rev; 132 }; 133 134 int netup_i2c_register(struct netup_unidvb_dev *ndev); 135 void netup_i2c_unregister(struct netup_unidvb_dev *ndev); 136 irqreturn_t netup_ci_interrupt(struct netup_unidvb_dev *ndev); 137 irqreturn_t netup_i2c_interrupt(struct netup_i2c *i2c); 138 irqreturn_t netup_spi_interrupt(struct netup_spi *spi); 139 int netup_unidvb_ci_register(struct netup_unidvb_dev *dev, 140 int num, struct pci_dev *pci_dev); 141 void netup_unidvb_ci_unregister(struct netup_unidvb_dev *dev, int num); 142 int netup_spi_init(struct netup_unidvb_dev *ndev); 143 void netup_spi_release(struct netup_unidvb_dev *ndev); 144