smipcie.h 12 KB

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