cobalt-driver.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. /*
  2. * cobalt driver internal defines and structures
  3. *
  4. * Derived from cx18-driver.h
  5. *
  6. * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
  7. * All rights reserved.
  8. *
  9. * This program is free software; you may redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; version 2 of the License.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  17. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  18. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. #ifndef COBALT_DRIVER_H
  23. #define COBALT_DRIVER_H
  24. #include <linux/module.h>
  25. #include <linux/pci.h>
  26. #include <linux/spinlock.h>
  27. #include <linux/i2c.h>
  28. #include <linux/list.h>
  29. #include <linux/workqueue.h>
  30. #include <linux/mutex.h>
  31. #include <media/v4l2-common.h>
  32. #include <media/v4l2-ioctl.h>
  33. #include <media/v4l2-device.h>
  34. #include <media/v4l2-fh.h>
  35. #include <media/videobuf2-v4l2.h>
  36. #include <media/videobuf2-dma-sg.h>
  37. #include "m00233_video_measure_memmap_package.h"
  38. #include "m00235_fdma_packer_memmap_package.h"
  39. #include "m00389_cvi_memmap_package.h"
  40. #include "m00460_evcnt_memmap_package.h"
  41. #include "m00473_freewheel_memmap_package.h"
  42. #include "m00479_clk_loss_detector_memmap_package.h"
  43. #include "m00514_syncgen_flow_evcnt_memmap_package.h"
  44. /* System device ID */
  45. #define PCI_DEVICE_ID_COBALT 0x2732
  46. /* Number of cobalt device nodes. */
  47. #define COBALT_NUM_INPUTS 4
  48. #define COBALT_NUM_NODES 6
  49. /* Number of cobalt device streams. */
  50. #define COBALT_NUM_STREAMS 12
  51. #define COBALT_HSMA_IN_NODE 4
  52. #define COBALT_HSMA_OUT_NODE 5
  53. /* Cobalt audio streams */
  54. #define COBALT_AUDIO_IN_STREAM 6
  55. #define COBALT_AUDIO_OUT_STREAM 11
  56. /* DMA stuff */
  57. #define DMA_CHANNELS_MAX 16
  58. /* i2c stuff */
  59. #define I2C_CLIENTS_MAX 16
  60. #define COBALT_NUM_ADAPTERS 5
  61. #define COBALT_CLK 50000000
  62. /* System status register */
  63. #define COBALT_SYSSTAT_DIP0_MSK (1 << 0)
  64. #define COBALT_SYSSTAT_DIP1_MSK (1 << 1)
  65. #define COBALT_SYSSTAT_HSMA_PRSNTN_MSK (1 << 2)
  66. #define COBALT_SYSSTAT_FLASH_RDYBSYN_MSK (1 << 3)
  67. #define COBALT_SYSSTAT_VI0_5V_MSK (1 << 4)
  68. #define COBALT_SYSSTAT_VI0_INT1_MSK (1 << 5)
  69. #define COBALT_SYSSTAT_VI0_INT2_MSK (1 << 6)
  70. #define COBALT_SYSSTAT_VI0_LOST_DATA_MSK (1 << 7)
  71. #define COBALT_SYSSTAT_VI1_5V_MSK (1 << 8)
  72. #define COBALT_SYSSTAT_VI1_INT1_MSK (1 << 9)
  73. #define COBALT_SYSSTAT_VI1_INT2_MSK (1 << 10)
  74. #define COBALT_SYSSTAT_VI1_LOST_DATA_MSK (1 << 11)
  75. #define COBALT_SYSSTAT_VI2_5V_MSK (1 << 12)
  76. #define COBALT_SYSSTAT_VI2_INT1_MSK (1 << 13)
  77. #define COBALT_SYSSTAT_VI2_INT2_MSK (1 << 14)
  78. #define COBALT_SYSSTAT_VI2_LOST_DATA_MSK (1 << 15)
  79. #define COBALT_SYSSTAT_VI3_5V_MSK (1 << 16)
  80. #define COBALT_SYSSTAT_VI3_INT1_MSK (1 << 17)
  81. #define COBALT_SYSSTAT_VI3_INT2_MSK (1 << 18)
  82. #define COBALT_SYSSTAT_VI3_LOST_DATA_MSK (1 << 19)
  83. #define COBALT_SYSSTAT_VIHSMA_5V_MSK (1 << 20)
  84. #define COBALT_SYSSTAT_VIHSMA_INT1_MSK (1 << 21)
  85. #define COBALT_SYSSTAT_VIHSMA_INT2_MSK (1 << 22)
  86. #define COBALT_SYSSTAT_VIHSMA_LOST_DATA_MSK (1 << 23)
  87. #define COBALT_SYSSTAT_VOHSMA_INT1_MSK (1 << 24)
  88. #define COBALT_SYSSTAT_VOHSMA_PLL_LOCKED_MSK (1 << 25)
  89. #define COBALT_SYSSTAT_VOHSMA_LOST_DATA_MSK (1 << 26)
  90. #define COBALT_SYSSTAT_AUD_PLL_LOCKED_MSK (1 << 28)
  91. #define COBALT_SYSSTAT_AUD_IN_LOST_DATA_MSK (1 << 29)
  92. #define COBALT_SYSSTAT_AUD_OUT_LOST_DATA_MSK (1 << 30)
  93. #define COBALT_SYSSTAT_PCIE_SMBCLK_MSK (1 << 31)
  94. /* Cobalt memory map */
  95. #define COBALT_I2C_0_BASE 0x0
  96. #define COBALT_I2C_1_BASE 0x080
  97. #define COBALT_I2C_2_BASE 0x100
  98. #define COBALT_I2C_3_BASE 0x180
  99. #define COBALT_I2C_HSMA_BASE 0x200
  100. #define COBALT_SYS_CTRL_BASE 0x400
  101. #define COBALT_SYS_CTRL_HSMA_TX_ENABLE_BIT 1
  102. #define COBALT_SYS_CTRL_VIDEO_RX_RESETN_BIT(n) (4 + 4 * (n))
  103. #define COBALT_SYS_CTRL_NRESET_TO_HDMI_BIT(n) (5 + 4 * (n))
  104. #define COBALT_SYS_CTRL_HPD_TO_CONNECTOR_BIT(n) (6 + 4 * (n))
  105. #define COBALT_SYS_CTRL_AUDIO_IPP_RESETN_BIT(n) (7 + 4 * (n))
  106. #define COBALT_SYS_CTRL_PWRDN0_TO_HSMA_TX_BIT 24
  107. #define COBALT_SYS_CTRL_VIDEO_TX_RESETN_BIT 25
  108. #define COBALT_SYS_CTRL_AUDIO_OPP_RESETN_BIT 27
  109. #define COBALT_SYS_STAT_BASE 0x500
  110. #define COBALT_SYS_STAT_MASK (COBALT_SYS_STAT_BASE + 0x08)
  111. #define COBALT_SYS_STAT_EDGE (COBALT_SYS_STAT_BASE + 0x0c)
  112. #define COBALT_HDL_INFO_BASE 0x4800
  113. #define COBALT_HDL_INFO_SIZE 0x200
  114. #define COBALT_VID_BASE 0x10000
  115. #define COBALT_VID_SIZE 0x1000
  116. #define COBALT_CVI(cobalt, c) \
  117. (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE)
  118. #define COBALT_CVI_VMR(cobalt, c) \
  119. (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x100)
  120. #define COBALT_CVI_EVCNT(cobalt, c) \
  121. (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x200)
  122. #define COBALT_CVI_FREEWHEEL(cobalt, c) \
  123. (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x300)
  124. #define COBALT_CVI_CLK_LOSS(cobalt, c) \
  125. (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x400)
  126. #define COBALT_CVI_PACKER(cobalt, c) \
  127. (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x500)
  128. #define COBALT_TX_BASE(cobalt) (cobalt->bar1 + COBALT_VID_BASE + 0x5000)
  129. #define DMA_INTERRUPT_STATUS_REG 0x08
  130. #define COBALT_HDL_SEARCH_STR "** HDL version info **"
  131. /* Cobalt CPU bus interface */
  132. #define COBALT_BUS_BAR1_BASE 0x600
  133. #define COBALT_BUS_SRAM_BASE 0x0
  134. #define COBALT_BUS_CPLD_BASE 0x00600000
  135. #define COBALT_BUS_FLASH_BASE 0x08000000
  136. /* FDMA to PCIe packing */
  137. #define COBALT_BYTES_PER_PIXEL_YUYV 2
  138. #define COBALT_BYTES_PER_PIXEL_RGB24 3
  139. #define COBALT_BYTES_PER_PIXEL_RGB32 4
  140. /* debugging */
  141. extern int cobalt_debug;
  142. extern int cobalt_ignore_err;
  143. #define cobalt_err(fmt, arg...) v4l2_err(&cobalt->v4l2_dev, fmt, ## arg)
  144. #define cobalt_warn(fmt, arg...) v4l2_warn(&cobalt->v4l2_dev, fmt, ## arg)
  145. #define cobalt_info(fmt, arg...) v4l2_info(&cobalt->v4l2_dev, fmt, ## arg)
  146. #define cobalt_dbg(level, fmt, arg...) \
  147. v4l2_dbg(level, cobalt_debug, &cobalt->v4l2_dev, fmt, ## arg)
  148. struct cobalt;
  149. struct cobalt_i2c_regs;
  150. /* Per I2C bus private algo callback data */
  151. struct cobalt_i2c_data {
  152. struct cobalt *cobalt;
  153. struct cobalt_i2c_regs __iomem *regs;
  154. };
  155. struct pci_consistent_buffer {
  156. void *virt;
  157. dma_addr_t bus;
  158. size_t bytes;
  159. };
  160. struct sg_dma_desc_info {
  161. void *virt;
  162. dma_addr_t bus;
  163. unsigned size;
  164. void *last_desc_virt;
  165. struct device *dev;
  166. };
  167. #define COBALT_MAX_WIDTH 1920
  168. #define COBALT_MAX_HEIGHT 1200
  169. #define COBALT_MAX_BPP 3
  170. #define COBALT_MAX_FRAMESZ \
  171. (COBALT_MAX_WIDTH * COBALT_MAX_HEIGHT * COBALT_MAX_BPP)
  172. #define NR_BUFS VIDEO_MAX_FRAME
  173. #define COBALT_STREAM_FL_DMA_IRQ 0
  174. #define COBALT_STREAM_FL_ADV_IRQ 1
  175. struct cobalt_buffer {
  176. struct vb2_v4l2_buffer vb;
  177. struct list_head list;
  178. };
  179. static inline
  180. struct cobalt_buffer *to_cobalt_buffer(struct vb2_v4l2_buffer *vb2)
  181. {
  182. return container_of(vb2, struct cobalt_buffer, vb);
  183. }
  184. struct cobalt_stream {
  185. struct video_device vdev;
  186. struct vb2_queue q;
  187. struct list_head bufs;
  188. struct i2c_adapter *i2c_adap;
  189. struct v4l2_subdev *sd;
  190. struct mutex lock;
  191. spinlock_t irqlock;
  192. struct v4l2_dv_timings timings;
  193. u32 input;
  194. u32 pad_source;
  195. u32 width, height, bpp;
  196. u32 stride;
  197. u32 pixfmt;
  198. u32 sequence;
  199. u32 colorspace;
  200. u32 xfer_func;
  201. u32 ycbcr_enc;
  202. u32 quantization;
  203. u8 dma_channel;
  204. int video_channel;
  205. unsigned dma_fifo_mask;
  206. unsigned adv_irq_mask;
  207. struct sg_dma_desc_info dma_desc_info[NR_BUFS];
  208. unsigned long flags;
  209. bool unstable_frame;
  210. bool enable_cvi;
  211. bool enable_freewheel;
  212. unsigned skip_first_frames;
  213. bool is_output;
  214. bool is_audio;
  215. bool is_dummy;
  216. struct cobalt *cobalt;
  217. struct snd_cobalt_card *alsa;
  218. };
  219. struct snd_cobalt_card;
  220. /* Struct to hold info about cobalt cards */
  221. struct cobalt {
  222. int instance;
  223. struct pci_dev *pci_dev;
  224. struct v4l2_device v4l2_dev;
  225. void *alloc_ctx;
  226. void __iomem *bar0, *bar1;
  227. u8 card_rev;
  228. u16 device_id;
  229. /* device nodes */
  230. struct cobalt_stream streams[DMA_CHANNELS_MAX];
  231. struct i2c_adapter i2c_adap[COBALT_NUM_ADAPTERS];
  232. struct cobalt_i2c_data i2c_data[COBALT_NUM_ADAPTERS];
  233. bool have_hsma_rx;
  234. bool have_hsma_tx;
  235. /* irq */
  236. struct workqueue_struct *irq_work_queues;
  237. struct work_struct irq_work_queue; /* work entry */
  238. /* irq counters */
  239. u32 irq_adv1;
  240. u32 irq_adv2;
  241. u32 irq_advout;
  242. u32 irq_dma_tot;
  243. u32 irq_dma[COBALT_NUM_STREAMS];
  244. u32 irq_none;
  245. u32 irq_full_fifo;
  246. bool msi_enabled;
  247. /* omnitek dma */
  248. int dma_channels;
  249. int first_fifo_channel;
  250. bool pci_32_bit;
  251. char hdl_info[COBALT_HDL_INFO_SIZE];
  252. /* NOR flash */
  253. struct mtd_info *mtd;
  254. };
  255. static inline struct cobalt *to_cobalt(struct v4l2_device *v4l2_dev)
  256. {
  257. return container_of(v4l2_dev, struct cobalt, v4l2_dev);
  258. }
  259. static inline void cobalt_write_bar0(struct cobalt *cobalt, u32 reg, u32 val)
  260. {
  261. iowrite32(val, cobalt->bar0 + reg);
  262. }
  263. static inline u32 cobalt_read_bar0(struct cobalt *cobalt, u32 reg)
  264. {
  265. return ioread32(cobalt->bar0 + reg);
  266. }
  267. static inline void cobalt_write_bar1(struct cobalt *cobalt, u32 reg, u32 val)
  268. {
  269. iowrite32(val, cobalt->bar1 + reg);
  270. }
  271. static inline u32 cobalt_read_bar1(struct cobalt *cobalt, u32 reg)
  272. {
  273. return ioread32(cobalt->bar1 + reg);
  274. }
  275. static inline u32 cobalt_g_sysctrl(struct cobalt *cobalt)
  276. {
  277. return cobalt_read_bar1(cobalt, COBALT_SYS_CTRL_BASE);
  278. }
  279. static inline void cobalt_s_bit_sysctrl(struct cobalt *cobalt,
  280. int bit, int val)
  281. {
  282. u32 ctrl = cobalt_read_bar1(cobalt, COBALT_SYS_CTRL_BASE);
  283. cobalt_write_bar1(cobalt, COBALT_SYS_CTRL_BASE,
  284. (ctrl & ~(1UL << bit)) | (val << bit));
  285. }
  286. static inline u32 cobalt_g_sysstat(struct cobalt *cobalt)
  287. {
  288. return cobalt_read_bar1(cobalt, COBALT_SYS_STAT_BASE);
  289. }
  290. #define ADRS_REG (bar1 + COBALT_BUS_BAR1_BASE + 0)
  291. #define LOWER_DATA (bar1 + COBALT_BUS_BAR1_BASE + 4)
  292. #define UPPER_DATA (bar1 + COBALT_BUS_BAR1_BASE + 6)
  293. static inline u32 cobalt_bus_read32(void __iomem *bar1, u32 bus_adrs)
  294. {
  295. iowrite32(bus_adrs, ADRS_REG);
  296. return ioread32(LOWER_DATA);
  297. }
  298. static inline void cobalt_bus_write16(void __iomem *bar1,
  299. u32 bus_adrs, u16 data)
  300. {
  301. iowrite32(bus_adrs, ADRS_REG);
  302. if (bus_adrs & 2)
  303. iowrite16(data, UPPER_DATA);
  304. else
  305. iowrite16(data, LOWER_DATA);
  306. }
  307. static inline void cobalt_bus_write32(void __iomem *bar1,
  308. u32 bus_adrs, u16 data)
  309. {
  310. iowrite32(bus_adrs, ADRS_REG);
  311. if (bus_adrs & 2)
  312. iowrite32(data, UPPER_DATA);
  313. else
  314. iowrite32(data, LOWER_DATA);
  315. }
  316. /*==============Prototypes==================*/
  317. void cobalt_pcie_status_show(struct cobalt *cobalt);
  318. #endif