smipcie.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * SMI PCIe driver for DVBSky cards.
  4. *
  5. * Copyright (C) 2014 Max nibble <[email protected]>
  6. */
  7. #ifndef _SMI_PCIE_H_
  8. #define _SMI_PCIE_H_
  9. #include <linux/i2c.h>
  10. #include <linux/i2c-algo-bit.h>
  11. #include <linux/init.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/pci.h>
  16. #include <linux/dma-mapping.h>
  17. #include <linux/slab.h>
  18. #include <media/rc-core.h>
  19. #include <media/demux.h>
  20. #include <media/dmxdev.h>
  21. #include <media/dvb_demux.h>
  22. #include <media/dvb_frontend.h>
  23. #include <media/dvb_net.h>
  24. #include <media/dvbdev.h>
  25. /* -------- Register Base -------- */
  26. #define MSI_CONTROL_REG_BASE 0x0800
  27. #define SYSTEM_CONTROL_REG_BASE 0x0880
  28. #define PCIE_EP_DEBUG_REG_BASE 0x08C0
  29. #define IR_CONTROL_REG_BASE 0x0900
  30. #define I2C_A_CONTROL_REG_BASE 0x0940
  31. #define I2C_B_CONTROL_REG_BASE 0x0980
  32. #define ATV_PORTA_CONTROL_REG_BASE 0x09C0
  33. #define DTV_PORTA_CONTROL_REG_BASE 0x0A00
  34. #define AES_PORTA_CONTROL_REG_BASE 0x0A80
  35. #define DMA_PORTA_CONTROL_REG_BASE 0x0AC0
  36. #define ATV_PORTB_CONTROL_REG_BASE 0x0B00
  37. #define DTV_PORTB_CONTROL_REG_BASE 0x0B40
  38. #define AES_PORTB_CONTROL_REG_BASE 0x0BC0
  39. #define DMA_PORTB_CONTROL_REG_BASE 0x0C00
  40. #define UART_A_REGISTER_BASE 0x0C40
  41. #define UART_B_REGISTER_BASE 0x0C80
  42. #define GPS_CONTROL_REG_BASE 0x0CC0
  43. #define DMA_PORTC_CONTROL_REG_BASE 0x0D00
  44. #define DMA_PORTD_CONTROL_REG_BASE 0x0D00
  45. #define AES_RANDOM_DATA_BASE 0x0D80
  46. #define AES_KEY_IN_BASE 0x0D90
  47. #define RANDOM_DATA_LIB_BASE 0x0E00
  48. #define IR_DATA_BUFFER_BASE 0x0F00
  49. #define PORTA_TS_BUFFER_BASE 0x1000
  50. #define PORTA_I2S_BUFFER_BASE 0x1400
  51. #define PORTB_TS_BUFFER_BASE 0x1800
  52. #define PORTB_I2S_BUFFER_BASE 0x1C00
  53. /* -------- MSI control and state register -------- */
  54. #define MSI_DELAY_TIMER (MSI_CONTROL_REG_BASE + 0x00)
  55. #define MSI_INT_STATUS (MSI_CONTROL_REG_BASE + 0x08)
  56. #define MSI_INT_STATUS_CLR (MSI_CONTROL_REG_BASE + 0x0C)
  57. #define MSI_INT_STATUS_SET (MSI_CONTROL_REG_BASE + 0x10)
  58. #define MSI_INT_ENA (MSI_CONTROL_REG_BASE + 0x14)
  59. #define MSI_INT_ENA_CLR (MSI_CONTROL_REG_BASE + 0x18)
  60. #define MSI_INT_ENA_SET (MSI_CONTROL_REG_BASE + 0x1C)
  61. #define MSI_SOFT_RESET (MSI_CONTROL_REG_BASE + 0x20)
  62. #define MSI_CFG_SRC0 (MSI_CONTROL_REG_BASE + 0x24)
  63. /* -------- Hybird Controller System Control register -------- */
  64. #define MUX_MODE_CTRL (SYSTEM_CONTROL_REG_BASE + 0x00)
  65. #define rbPaMSMask 0x07
  66. #define rbPaMSDtvNoGpio 0x00 /*[2:0], DTV Simple mode */
  67. #define rbPaMSDtv4bitGpio 0x01 /*[2:0], DTV TS2 Serial mode)*/
  68. #define rbPaMSDtv7bitGpio 0x02 /*[2:0], DTV TS0 Serial mode*/
  69. #define rbPaMS8bitGpio 0x03 /*[2:0], GPIO mode selected;(8bit GPIO)*/
  70. #define rbPaMSAtv 0x04 /*[2:0], 3'b1xx: ATV mode select*/
  71. #define rbPbMSMask 0x38
  72. #define rbPbMSDtvNoGpio 0x00 /*[5:3], DTV Simple mode */
  73. #define rbPbMSDtv4bitGpio 0x08 /*[5:3], DTV TS2 Serial mode*/
  74. #define rbPbMSDtv7bitGpio 0x10 /*[5:3], DTV TS0 Serial mode*/
  75. #define rbPbMS8bitGpio 0x18 /*[5:3], GPIO mode selected;(8bit GPIO)*/
  76. #define rbPbMSAtv 0x20 /*[5:3], 3'b1xx: ATV mode select*/
  77. #define rbPaAESEN 0x40 /*[6], port A AES enable bit*/
  78. #define rbPbAESEN 0x80 /*[7], port B AES enable bit*/
  79. #define INTERNAL_RST (SYSTEM_CONTROL_REG_BASE + 0x04)
  80. #define PERIPHERAL_CTRL (SYSTEM_CONTROL_REG_BASE + 0x08)
  81. #define GPIO_0to7_CTRL (SYSTEM_CONTROL_REG_BASE + 0x0C)
  82. #define GPIO_8to15_CTRL (SYSTEM_CONTROL_REG_BASE + 0x10)
  83. #define GPIO_16to24_CTRL (SYSTEM_CONTROL_REG_BASE + 0x14)
  84. #define GPIO_INT_SRC_CFG (SYSTEM_CONTROL_REG_BASE + 0x18)
  85. #define SYS_BUF_STATUS (SYSTEM_CONTROL_REG_BASE + 0x1C)
  86. #define PCIE_IP_REG_ACS (SYSTEM_CONTROL_REG_BASE + 0x20)
  87. #define PCIE_IP_REG_ACS_ADDR (SYSTEM_CONTROL_REG_BASE + 0x24)
  88. #define PCIE_IP_REG_ACS_DATA (SYSTEM_CONTROL_REG_BASE + 0x28)
  89. /* -------- IR Control register -------- */
  90. #define IR_Init_Reg (IR_CONTROL_REG_BASE + 0x00)
  91. #define IR_Idle_Cnt_Low (IR_CONTROL_REG_BASE + 0x04)
  92. #define IR_Idle_Cnt_High (IR_CONTROL_REG_BASE + 0x05)
  93. #define IR_Unit_Cnt_Low (IR_CONTROL_REG_BASE + 0x06)
  94. #define IR_Unit_Cnt_High (IR_CONTROL_REG_BASE + 0x07)
  95. #define IR_Data_Cnt (IR_CONTROL_REG_BASE + 0x08)
  96. #define rbIRen 0x80
  97. #define rbIRhighidle 0x10
  98. #define rbIRlowidle 0x00
  99. #define rbIRVld 0x04
  100. /* -------- I2C A control and state register -------- */
  101. #define I2C_A_CTL_STATUS (I2C_A_CONTROL_REG_BASE + 0x00)
  102. #define I2C_A_ADDR (I2C_A_CONTROL_REG_BASE + 0x04)
  103. #define I2C_A_SW_CTL (I2C_A_CONTROL_REG_BASE + 0x08)
  104. #define I2C_A_TIME_OUT_CNT (I2C_A_CONTROL_REG_BASE + 0x0C)
  105. #define I2C_A_FIFO_STATUS (I2C_A_CONTROL_REG_BASE + 0x10)
  106. #define I2C_A_FS_EN (I2C_A_CONTROL_REG_BASE + 0x14)
  107. #define I2C_A_FIFO_DATA (I2C_A_CONTROL_REG_BASE + 0x20)
  108. /* -------- I2C B control and state register -------- */
  109. #define I2C_B_CTL_STATUS (I2C_B_CONTROL_REG_BASE + 0x00)
  110. #define I2C_B_ADDR (I2C_B_CONTROL_REG_BASE + 0x04)
  111. #define I2C_B_SW_CTL (I2C_B_CONTROL_REG_BASE + 0x08)
  112. #define I2C_B_TIME_OUT_CNT (I2C_B_CONTROL_REG_BASE + 0x0C)
  113. #define I2C_B_FIFO_STATUS (I2C_B_CONTROL_REG_BASE + 0x10)
  114. #define I2C_B_FS_EN (I2C_B_CONTROL_REG_BASE + 0x14)
  115. #define I2C_B_FIFO_DATA (I2C_B_CONTROL_REG_BASE + 0x20)
  116. #define VIDEO_CTRL_STATUS_A (ATV_PORTA_CONTROL_REG_BASE + 0x04)
  117. /* -------- Digital TV control register, Port A -------- */
  118. #define MPEG2_CTRL_A (DTV_PORTA_CONTROL_REG_BASE + 0x00)
  119. #define SERIAL_IN_ADDR_A (DTV_PORTA_CONTROL_REG_BASE + 0x4C)
  120. #define VLD_CNT_ADDR_A (DTV_PORTA_CONTROL_REG_BASE + 0x60)
  121. #define ERR_CNT_ADDR_A (DTV_PORTA_CONTROL_REG_BASE + 0x64)
  122. #define BRD_CNT_ADDR_A (DTV_PORTA_CONTROL_REG_BASE + 0x68)
  123. /* -------- DMA Control Register, Port A -------- */
  124. #define DMA_PORTA_CHAN0_ADDR_LOW (DMA_PORTA_CONTROL_REG_BASE + 0x00)
  125. #define DMA_PORTA_CHAN0_ADDR_HI (DMA_PORTA_CONTROL_REG_BASE + 0x04)
  126. #define DMA_PORTA_CHAN0_TRANS_STATE (DMA_PORTA_CONTROL_REG_BASE + 0x08)
  127. #define DMA_PORTA_CHAN0_CONTROL (DMA_PORTA_CONTROL_REG_BASE + 0x0C)
  128. #define DMA_PORTA_CHAN1_ADDR_LOW (DMA_PORTA_CONTROL_REG_BASE + 0x10)
  129. #define DMA_PORTA_CHAN1_ADDR_HI (DMA_PORTA_CONTROL_REG_BASE + 0x14)
  130. #define DMA_PORTA_CHAN1_TRANS_STATE (DMA_PORTA_CONTROL_REG_BASE + 0x18)
  131. #define DMA_PORTA_CHAN1_CONTROL (DMA_PORTA_CONTROL_REG_BASE + 0x1C)
  132. #define DMA_PORTA_MANAGEMENT (DMA_PORTA_CONTROL_REG_BASE + 0x20)
  133. #define VIDEO_CTRL_STATUS_B (ATV_PORTB_CONTROL_REG_BASE + 0x04)
  134. /* -------- Digital TV control register, Port B -------- */
  135. #define MPEG2_CTRL_B (DTV_PORTB_CONTROL_REG_BASE + 0x00)
  136. #define SERIAL_IN_ADDR_B (DTV_PORTB_CONTROL_REG_BASE + 0x4C)
  137. #define VLD_CNT_ADDR_B (DTV_PORTB_CONTROL_REG_BASE + 0x60)
  138. #define ERR_CNT_ADDR_B (DTV_PORTB_CONTROL_REG_BASE + 0x64)
  139. #define BRD_CNT_ADDR_B (DTV_PORTB_CONTROL_REG_BASE + 0x68)
  140. /* -------- AES control register, Port B -------- */
  141. #define AES_CTRL_B (AES_PORTB_CONTROL_REG_BASE + 0x00)
  142. #define AES_KEY_BASE_B (AES_PORTB_CONTROL_REG_BASE + 0x04)
  143. /* -------- DMA Control Register, Port B -------- */
  144. #define DMA_PORTB_CHAN0_ADDR_LOW (DMA_PORTB_CONTROL_REG_BASE + 0x00)
  145. #define DMA_PORTB_CHAN0_ADDR_HI (DMA_PORTB_CONTROL_REG_BASE + 0x04)
  146. #define DMA_PORTB_CHAN0_TRANS_STATE (DMA_PORTB_CONTROL_REG_BASE + 0x08)
  147. #define DMA_PORTB_CHAN0_CONTROL (DMA_PORTB_CONTROL_REG_BASE + 0x0C)
  148. #define DMA_PORTB_CHAN1_ADDR_LOW (DMA_PORTB_CONTROL_REG_BASE + 0x10)
  149. #define DMA_PORTB_CHAN1_ADDR_HI (DMA_PORTB_CONTROL_REG_BASE + 0x14)
  150. #define DMA_PORTB_CHAN1_TRANS_STATE (DMA_PORTB_CONTROL_REG_BASE + 0x18)
  151. #define DMA_PORTB_CHAN1_CONTROL (DMA_PORTB_CONTROL_REG_BASE + 0x1C)
  152. #define DMA_PORTB_MANAGEMENT (DMA_PORTB_CONTROL_REG_BASE + 0x20)
  153. #define DMA_TRANS_UNIT_188 (0x00000007)
  154. /* -------- Macro define of 24 interrupt resource --------*/
  155. #define DMA_A_CHAN0_DONE_INT (0x00000001)
  156. #define DMA_A_CHAN1_DONE_INT (0x00000002)
  157. #define DMA_B_CHAN0_DONE_INT (0x00000004)
  158. #define DMA_B_CHAN1_DONE_INT (0x00000008)
  159. #define DMA_C_CHAN0_DONE_INT (0x00000010)
  160. #define DMA_C_CHAN1_DONE_INT (0x00000020)
  161. #define DMA_D_CHAN0_DONE_INT (0x00000040)
  162. #define DMA_D_CHAN1_DONE_INT (0x00000080)
  163. #define DATA_BUF_OVERFLOW_INT (0x00000100)
  164. #define UART_0_X_INT (0x00000200)
  165. #define UART_1_X_INT (0x00000400)
  166. #define IR_X_INT (0x00000800)
  167. #define GPIO_0_INT (0x00001000)
  168. #define GPIO_1_INT (0x00002000)
  169. #define GPIO_2_INT (0x00004000)
  170. #define GPIO_3_INT (0x00008000)
  171. #define ALL_INT (0x0000FFFF)
  172. /* software I2C bit mask */
  173. #define SW_I2C_MSK_MODE 0x01
  174. #define SW_I2C_MSK_CLK_OUT 0x02
  175. #define SW_I2C_MSK_DAT_OUT 0x04
  176. #define SW_I2C_MSK_CLK_EN 0x08
  177. #define SW_I2C_MSK_DAT_EN 0x10
  178. #define SW_I2C_MSK_DAT_IN 0x40
  179. #define SW_I2C_MSK_CLK_IN 0x80
  180. #define SMI_VID 0x1ADE
  181. #define SMI_PID 0x3038
  182. #define SMI_TS_DMA_BUF_SIZE (1024 * 188)
  183. struct smi_cfg_info {
  184. #define SMI_DVBSKY_S952 0
  185. #define SMI_DVBSKY_S950 1
  186. #define SMI_DVBSKY_T9580 2
  187. #define SMI_DVBSKY_T982 3
  188. #define SMI_TECHNOTREND_S2_4200 4
  189. int type;
  190. char *name;
  191. #define SMI_TS_NULL 0
  192. #define SMI_TS_DMA_SINGLE 1
  193. #define SMI_TS_DMA_BOTH 3
  194. /* SMI_TS_NULL: not use;
  195. * SMI_TS_DMA_SINGLE: use DMA 0 only;
  196. * SMI_TS_DMA_BOTH:use DMA 0 and 1.*/
  197. int ts_0;
  198. int ts_1;
  199. #define DVBSKY_FE_NULL 0
  200. #define DVBSKY_FE_M88RS6000 1
  201. #define DVBSKY_FE_M88DS3103 2
  202. #define DVBSKY_FE_SIT2 3
  203. int fe_0;
  204. int fe_1;
  205. char *rc_map;
  206. };
  207. struct smi_rc {
  208. struct smi_dev *dev;
  209. struct rc_dev *rc_dev;
  210. char input_phys[64];
  211. char device_name[64];
  212. u8 irData[256];
  213. int users;
  214. };
  215. struct smi_port {
  216. struct smi_dev *dev;
  217. int idx;
  218. int enable;
  219. int fe_type;
  220. /* regs */
  221. u32 DMA_CHAN0_ADDR_LOW;
  222. u32 DMA_CHAN0_ADDR_HI;
  223. u32 DMA_CHAN0_TRANS_STATE;
  224. u32 DMA_CHAN0_CONTROL;
  225. u32 DMA_CHAN1_ADDR_LOW;
  226. u32 DMA_CHAN1_ADDR_HI;
  227. u32 DMA_CHAN1_TRANS_STATE;
  228. u32 DMA_CHAN1_CONTROL;
  229. u32 DMA_MANAGEMENT;
  230. /* dma */
  231. dma_addr_t dma_addr[2];
  232. u8 *cpu_addr[2];
  233. u32 _dmaInterruptCH0;
  234. u32 _dmaInterruptCH1;
  235. u32 _int_status;
  236. struct tasklet_struct tasklet;
  237. /* dvb */
  238. struct dmx_frontend hw_frontend;
  239. struct dmx_frontend mem_frontend;
  240. struct dmxdev dmxdev;
  241. struct dvb_adapter dvb_adapter;
  242. struct dvb_demux demux;
  243. struct dvb_net dvbnet;
  244. int users;
  245. struct dvb_frontend *fe;
  246. /* frontend i2c module */
  247. struct i2c_client *i2c_client_demod;
  248. struct i2c_client *i2c_client_tuner;
  249. };
  250. struct smi_dev {
  251. int nr;
  252. struct smi_cfg_info *info;
  253. /* pcie */
  254. struct pci_dev *pci_dev;
  255. u32 __iomem *lmmio;
  256. /* ts port */
  257. struct smi_port ts_port[2];
  258. /* i2c */
  259. struct i2c_adapter i2c_bus[2];
  260. struct i2c_algo_bit_data i2c_bit[2];
  261. /* ir */
  262. struct smi_rc ir;
  263. };
  264. #define smi_read(reg) readl(dev->lmmio + ((reg)>>2))
  265. #define smi_write(reg, value) writel((value), dev->lmmio + ((reg)>>2))
  266. #define smi_andor(reg, mask, value) \
  267. writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
  268. ((value) & (mask)), dev->lmmio+((reg)>>2))
  269. #define smi_set(reg, bit) smi_andor((reg), (bit), (bit))
  270. #define smi_clear(reg, bit) smi_andor((reg), (bit), 0)
  271. int smi_ir_irq(struct smi_rc *ir, u32 int_status);
  272. void smi_ir_start(struct smi_rc *ir);
  273. void smi_ir_exit(struct smi_dev *dev);
  274. int smi_ir_init(struct smi_dev *dev);
  275. #endif /* #ifndef _SMI_PCIE_H_ */