cobalt-driver.h 9.7 KB

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