1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * cobalt driver internal defines and structures
5 * Derived from cx18-driver.h
7 * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
11 #ifndef COBALT_DRIVER_H
12 #define COBALT_DRIVER_H
14 #include <linux/bitops.h>
15 #include <linux/module.h>
16 #include <linux/pci.h>
17 #include <linux/spinlock.h>
18 #include <linux/i2c.h>
19 #include <linux/list.h>
20 #include <linux/workqueue.h>
21 #include <linux/mutex.h>
23 #include <media/v4l2-common.h>
24 #include <media/v4l2-ioctl.h>
25 #include <media/v4l2-device.h>
26 #include <media/v4l2-fh.h>
27 #include <media/videobuf2-v4l2.h>
28 #include <media/videobuf2-dma-sg.h>
30 #include "m00233_video_measure_memmap_package.h"
31 #include "m00235_fdma_packer_memmap_package.h"
32 #include "m00389_cvi_memmap_package.h"
33 #include "m00460_evcnt_memmap_package.h"
34 #include "m00473_freewheel_memmap_package.h"
35 #include "m00479_clk_loss_detector_memmap_package.h"
36 #include "m00514_syncgen_flow_evcnt_memmap_package.h"
38 /* System device ID */
39 #define PCI_DEVICE_ID_COBALT 0x2732
41 /* Number of cobalt device nodes. */
42 #define COBALT_NUM_INPUTS 4
43 #define COBALT_NUM_NODES 6
45 /* Number of cobalt device streams. */
46 #define COBALT_NUM_STREAMS 12
48 #define COBALT_HSMA_IN_NODE 4
49 #define COBALT_HSMA_OUT_NODE 5
51 /* Cobalt audio streams */
52 #define COBALT_AUDIO_IN_STREAM 6
53 #define COBALT_AUDIO_OUT_STREAM 11
56 #define DMA_CHANNELS_MAX 16
59 #define I2C_CLIENTS_MAX 16
60 #define COBALT_NUM_ADAPTERS 5
62 #define COBALT_CLK 50000000
64 /* System status register */
65 #define COBALT_SYSSTAT_DIP0_MSK BIT(0)
66 #define COBALT_SYSSTAT_DIP1_MSK BIT(1)
67 #define COBALT_SYSSTAT_HSMA_PRSNTN_MSK BIT(2)
68 #define COBALT_SYSSTAT_FLASH_RDYBSYN_MSK BIT(3)
69 #define COBALT_SYSSTAT_VI0_5V_MSK BIT(4)
70 #define COBALT_SYSSTAT_VI0_INT1_MSK BIT(5)
71 #define COBALT_SYSSTAT_VI0_INT2_MSK BIT(6)
72 #define COBALT_SYSSTAT_VI0_LOST_DATA_MSK BIT(7)
73 #define COBALT_SYSSTAT_VI1_5V_MSK BIT(8)
74 #define COBALT_SYSSTAT_VI1_INT1_MSK BIT(9)
75 #define COBALT_SYSSTAT_VI1_INT2_MSK BIT(10)
76 #define COBALT_SYSSTAT_VI1_LOST_DATA_MSK BIT(11)
77 #define COBALT_SYSSTAT_VI2_5V_MSK BIT(12)
78 #define COBALT_SYSSTAT_VI2_INT1_MSK BIT(13)
79 #define COBALT_SYSSTAT_VI2_INT2_MSK BIT(14)
80 #define COBALT_SYSSTAT_VI2_LOST_DATA_MSK BIT(15)
81 #define COBALT_SYSSTAT_VI3_5V_MSK BIT(16)
82 #define COBALT_SYSSTAT_VI3_INT1_MSK BIT(17)
83 #define COBALT_SYSSTAT_VI3_INT2_MSK BIT(18)
84 #define COBALT_SYSSTAT_VI3_LOST_DATA_MSK BIT(19)
85 #define COBALT_SYSSTAT_VIHSMA_5V_MSK BIT(20)
86 #define COBALT_SYSSTAT_VIHSMA_INT1_MSK BIT(21)
87 #define COBALT_SYSSTAT_VIHSMA_INT2_MSK BIT(22)
88 #define COBALT_SYSSTAT_VIHSMA_LOST_DATA_MSK BIT(23)
89 #define COBALT_SYSSTAT_VOHSMA_INT1_MSK BIT(24)
90 #define COBALT_SYSSTAT_VOHSMA_PLL_LOCKED_MSK BIT(25)
91 #define COBALT_SYSSTAT_VOHSMA_LOST_DATA_MSK BIT(26)
92 #define COBALT_SYSSTAT_AUD_PLL_LOCKED_MSK BIT(28)
93 #define COBALT_SYSSTAT_AUD_IN_LOST_DATA_MSK BIT(29)
94 #define COBALT_SYSSTAT_AUD_OUT_LOST_DATA_MSK BIT(30)
95 #define COBALT_SYSSTAT_PCIE_SMBCLK_MSK BIT(31)
97 /* Cobalt memory map */
98 #define COBALT_I2C_0_BASE 0x0
99 #define COBALT_I2C_1_BASE 0x080
100 #define COBALT_I2C_2_BASE 0x100
101 #define COBALT_I2C_3_BASE 0x180
102 #define COBALT_I2C_HSMA_BASE 0x200
104 #define COBALT_SYS_CTRL_BASE 0x400
105 #define COBALT_SYS_CTRL_HSMA_TX_ENABLE_BIT 1
106 #define COBALT_SYS_CTRL_VIDEO_RX_RESETN_BIT(n) (4 + 4 * (n))
107 #define COBALT_SYS_CTRL_NRESET_TO_HDMI_BIT(n) (5 + 4 * (n))
108 #define COBALT_SYS_CTRL_HPD_TO_CONNECTOR_BIT(n) (6 + 4 * (n))
109 #define COBALT_SYS_CTRL_AUDIO_IPP_RESETN_BIT(n) (7 + 4 * (n))
110 #define COBALT_SYS_CTRL_PWRDN0_TO_HSMA_TX_BIT 24
111 #define COBALT_SYS_CTRL_VIDEO_TX_RESETN_BIT 25
112 #define COBALT_SYS_CTRL_AUDIO_OPP_RESETN_BIT 27
114 #define COBALT_SYS_STAT_BASE 0x500
115 #define COBALT_SYS_STAT_MASK (COBALT_SYS_STAT_BASE + 0x08)
116 #define COBALT_SYS_STAT_EDGE (COBALT_SYS_STAT_BASE + 0x0c)
118 #define COBALT_HDL_INFO_BASE 0x4800
119 #define COBALT_HDL_INFO_SIZE 0x200
121 #define COBALT_VID_BASE 0x10000
122 #define COBALT_VID_SIZE 0x1000
124 #define COBALT_CVI(cobalt, c) \
125 (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE)
126 #define COBALT_CVI_VMR(cobalt, c) \
127 (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x100)
128 #define COBALT_CVI_EVCNT(cobalt, c) \
129 (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x200)
130 #define COBALT_CVI_FREEWHEEL(cobalt, c) \
131 (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x300)
132 #define COBALT_CVI_CLK_LOSS(cobalt, c) \
133 (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x400)
134 #define COBALT_CVI_PACKER(cobalt, c) \
135 (cobalt->bar1 + COBALT_VID_BASE + (c) * COBALT_VID_SIZE + 0x500)
137 #define COBALT_TX_BASE(cobalt) (cobalt->bar1 + COBALT_VID_BASE + 0x5000)
139 #define DMA_INTERRUPT_STATUS_REG 0x08
141 #define COBALT_HDL_SEARCH_STR "** HDL version info **"
143 /* Cobalt CPU bus interface */
144 #define COBALT_BUS_BAR1_BASE 0x600
145 #define COBALT_BUS_SRAM_BASE 0x0
146 #define COBALT_BUS_CPLD_BASE 0x00600000
147 #define COBALT_BUS_FLASH_BASE 0x08000000
149 /* FDMA to PCIe packing */
150 #define COBALT_BYTES_PER_PIXEL_YUYV 2
151 #define COBALT_BYTES_PER_PIXEL_RGB24 3
152 #define COBALT_BYTES_PER_PIXEL_RGB32 4
155 extern int cobalt_debug
;
156 extern int cobalt_ignore_err
;
158 #define cobalt_err(fmt, arg...) v4l2_err(&cobalt->v4l2_dev, fmt, ## arg)
159 #define cobalt_warn(fmt, arg...) v4l2_warn(&cobalt->v4l2_dev, fmt, ## arg)
160 #define cobalt_info(fmt, arg...) v4l2_info(&cobalt->v4l2_dev, fmt, ## arg)
161 #define cobalt_dbg(level, fmt, arg...) \
162 v4l2_dbg(level, cobalt_debug, &cobalt->v4l2_dev, fmt, ## arg)
165 struct cobalt_i2c_regs
;
167 /* Per I2C bus private algo callback data */
168 struct cobalt_i2c_data
{
169 struct cobalt
*cobalt
;
170 struct cobalt_i2c_regs __iomem
*regs
;
173 struct pci_consistent_buffer
{
179 struct sg_dma_desc_info
{
183 void *last_desc_virt
;
187 #define COBALT_MAX_WIDTH 1920
188 #define COBALT_MAX_HEIGHT 1200
189 #define COBALT_MAX_BPP 3
190 #define COBALT_MAX_FRAMESZ \
191 (COBALT_MAX_WIDTH * COBALT_MAX_HEIGHT * COBALT_MAX_BPP)
193 #define NR_BUFS VIDEO_MAX_FRAME
195 #define COBALT_STREAM_FL_DMA_IRQ 0
196 #define COBALT_STREAM_FL_ADV_IRQ 1
198 struct cobalt_buffer
{
199 struct vb2_v4l2_buffer vb
;
200 struct list_head list
;
204 struct cobalt_buffer
*to_cobalt_buffer(struct vb2_v4l2_buffer
*vb2
)
206 return container_of(vb2
, struct cobalt_buffer
, vb
);
209 struct cobalt_stream
{
210 struct video_device vdev
;
212 struct list_head bufs
;
213 struct i2c_adapter
*i2c_adap
;
214 struct v4l2_subdev
*sd
;
217 struct v4l2_dv_timings timings
;
220 u32 width
, height
, bpp
;
231 unsigned dma_fifo_mask
;
232 unsigned adv_irq_mask
;
233 struct sg_dma_desc_info dma_desc_info
[NR_BUFS
];
237 bool enable_freewheel
;
238 unsigned skip_first_frames
;
243 struct cobalt
*cobalt
;
244 struct snd_cobalt_card
*alsa
;
247 struct snd_cobalt_card
;
249 /* Struct to hold info about cobalt cards */
252 struct pci_dev
*pci_dev
;
253 struct v4l2_device v4l2_dev
;
255 void __iomem
*bar0
, *bar1
;
261 struct cobalt_stream streams
[DMA_CHANNELS_MAX
];
262 struct i2c_adapter i2c_adap
[COBALT_NUM_ADAPTERS
];
263 struct cobalt_i2c_data i2c_data
[COBALT_NUM_ADAPTERS
];
268 struct workqueue_struct
*irq_work_queues
;
269 struct work_struct irq_work_queue
; /* work entry */
275 u32 irq_dma
[COBALT_NUM_STREAMS
];
281 int first_fifo_channel
;
284 char hdl_info
[COBALT_HDL_INFO_SIZE
];
287 struct mtd_info
*mtd
;
290 static inline struct cobalt
*to_cobalt(struct v4l2_device
*v4l2_dev
)
292 return container_of(v4l2_dev
, struct cobalt
, v4l2_dev
);
295 static inline void cobalt_write_bar0(struct cobalt
*cobalt
, u32 reg
, u32 val
)
297 iowrite32(val
, cobalt
->bar0
+ reg
);
300 static inline u32
cobalt_read_bar0(struct cobalt
*cobalt
, u32 reg
)
302 return ioread32(cobalt
->bar0
+ reg
);
305 static inline void cobalt_write_bar1(struct cobalt
*cobalt
, u32 reg
, u32 val
)
307 iowrite32(val
, cobalt
->bar1
+ reg
);
310 static inline u32
cobalt_read_bar1(struct cobalt
*cobalt
, u32 reg
)
312 return ioread32(cobalt
->bar1
+ reg
);
315 static inline u32
cobalt_g_sysctrl(struct cobalt
*cobalt
)
317 return cobalt_read_bar1(cobalt
, COBALT_SYS_CTRL_BASE
);
320 static inline void cobalt_s_bit_sysctrl(struct cobalt
*cobalt
,
323 u32 ctrl
= cobalt_read_bar1(cobalt
, COBALT_SYS_CTRL_BASE
);
325 cobalt_write_bar1(cobalt
, COBALT_SYS_CTRL_BASE
,
326 (ctrl
& ~(1UL << bit
)) | (val
<< bit
));
329 static inline u32
cobalt_g_sysstat(struct cobalt
*cobalt
)
331 return cobalt_read_bar1(cobalt
, COBALT_SYS_STAT_BASE
);
334 #define ADRS_REG (bar1 + COBALT_BUS_BAR1_BASE + 0)
335 #define LOWER_DATA (bar1 + COBALT_BUS_BAR1_BASE + 4)
336 #define UPPER_DATA (bar1 + COBALT_BUS_BAR1_BASE + 6)
338 static inline u32
cobalt_bus_read32(void __iomem
*bar1
, u32 bus_adrs
)
340 iowrite32(bus_adrs
, ADRS_REG
);
341 return ioread32(LOWER_DATA
);
344 static inline void cobalt_bus_write16(void __iomem
*bar1
,
345 u32 bus_adrs
, u16 data
)
347 iowrite32(bus_adrs
, ADRS_REG
);
349 iowrite16(data
, UPPER_DATA
);
351 iowrite16(data
, LOWER_DATA
);
354 static inline void cobalt_bus_write32(void __iomem
*bar1
,
355 u32 bus_adrs
, u16 data
)
357 iowrite32(bus_adrs
, ADRS_REG
);
359 iowrite32(data
, UPPER_DATA
);
361 iowrite32(data
, LOWER_DATA
);
364 /*==============Prototypes==================*/
366 void cobalt_pcie_status_show(struct cobalt
*cobalt
);