cx25821.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Driver for the Conexant CX25821 PCIe bridge
  4. *
  5. * Copyright (C) 2009 Conexant Systems Inc.
  6. * Authors <[email protected]>, <[email protected]>
  7. * Based on Steven Toth <[email protected]> cx23885 driver
  8. */
  9. #ifndef CX25821_H_
  10. #define CX25821_H_
  11. #include <linux/pci.h>
  12. #include <linux/i2c.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/delay.h>
  15. #include <linux/sched.h>
  16. #include <linux/kdev_t.h>
  17. #include <media/v4l2-common.h>
  18. #include <media/v4l2-device.h>
  19. #include <media/v4l2-ctrls.h>
  20. #include <media/videobuf2-v4l2.h>
  21. #include <media/videobuf2-dma-sg.h>
  22. #include "cx25821-reg.h"
  23. #include "cx25821-medusa-reg.h"
  24. #include "cx25821-sram.h"
  25. #include "cx25821-audio.h"
  26. #include <linux/mutex.h>
  27. #define UNSET (-1U)
  28. #define NO_SYNC_LINE (-1U)
  29. #define CX25821_MAXBOARDS 2
  30. #define LINE_SIZE_D1 1440
  31. /* Number of decoders and encoders */
  32. #define MAX_DECODERS 8
  33. #define MAX_ENCODERS 2
  34. #define QUAD_DECODERS 4
  35. #define MAX_CAMERAS 16
  36. /* Max number of inputs by card */
  37. #define MAX_CX25821_INPUT 8
  38. #define RESOURCE_VIDEO0 1
  39. #define RESOURCE_VIDEO1 2
  40. #define RESOURCE_VIDEO2 4
  41. #define RESOURCE_VIDEO3 8
  42. #define RESOURCE_VIDEO4 16
  43. #define RESOURCE_VIDEO5 32
  44. #define RESOURCE_VIDEO6 64
  45. #define RESOURCE_VIDEO7 128
  46. #define RESOURCE_VIDEO8 256
  47. #define RESOURCE_VIDEO9 512
  48. #define RESOURCE_VIDEO10 1024
  49. #define RESOURCE_VIDEO11 2048
  50. #define BUFFER_TIMEOUT (HZ) /* 0.5 seconds */
  51. #define UNKNOWN_BOARD 0
  52. #define CX25821_BOARD 1
  53. /* Currently supported by the driver */
  54. #define CX25821_NORMS (\
  55. V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_M_KR | \
  56. V4L2_STD_PAL_BG | V4L2_STD_PAL_DK | V4L2_STD_PAL_I | \
  57. V4L2_STD_PAL_M | V4L2_STD_PAL_N | V4L2_STD_PAL_H | \
  58. V4L2_STD_PAL_Nc)
  59. #define CX25821_BOARD_CONEXANT_ATHENA10 1
  60. #define MAX_VID_CHANNEL_NUM 12
  61. /*
  62. * Maximum capture-only channels. This can go away once video/audio output
  63. * is fully supported in this driver.
  64. */
  65. #define MAX_VID_CAP_CHANNEL_NUM 10
  66. #define VID_CHANNEL_NUM 8
  67. struct cx25821_fmt {
  68. u32 fourcc; /* v4l2 format id */
  69. int depth;
  70. int flags;
  71. u32 cxformat;
  72. };
  73. struct cx25821_tvnorm {
  74. char *name;
  75. v4l2_std_id id;
  76. u32 cxiformat;
  77. u32 cxoformat;
  78. };
  79. enum cx25821_src_sel_type {
  80. CX25821_SRC_SEL_EXT_656_VIDEO = 0,
  81. CX25821_SRC_SEL_PARALLEL_MPEG_VIDEO
  82. };
  83. struct cx25821_riscmem {
  84. unsigned int size;
  85. __le32 *cpu;
  86. __le32 *jmp;
  87. dma_addr_t dma;
  88. };
  89. /* buffer for one video frame */
  90. struct cx25821_buffer {
  91. /* common v4l buffer stuff -- must be first */
  92. struct vb2_v4l2_buffer vb;
  93. struct list_head queue;
  94. /* cx25821 specific */
  95. unsigned int bpl;
  96. struct cx25821_riscmem risc;
  97. const struct cx25821_fmt *fmt;
  98. };
  99. enum port {
  100. CX25821_UNDEFINED = 0,
  101. CX25821_RAW,
  102. CX25821_264
  103. };
  104. struct cx25821_board {
  105. const char *name;
  106. enum port porta;
  107. enum port portb;
  108. enum port portc;
  109. u32 clk_freq;
  110. };
  111. struct cx25821_i2c {
  112. struct cx25821_dev *dev;
  113. int nr;
  114. /* i2c i/o */
  115. struct i2c_adapter i2c_adap;
  116. struct i2c_client i2c_client;
  117. u32 i2c_rc;
  118. /* cx25821 registers used for raw address */
  119. u32 i2c_period;
  120. u32 reg_ctrl;
  121. u32 reg_stat;
  122. u32 reg_addr;
  123. u32 reg_rdata;
  124. u32 reg_wdata;
  125. };
  126. struct cx25821_dmaqueue {
  127. struct list_head active;
  128. u32 count;
  129. };
  130. struct cx25821_dev;
  131. struct cx25821_channel;
  132. struct cx25821_video_out_data {
  133. struct cx25821_channel *chan;
  134. int _line_size;
  135. int _prog_cnt;
  136. int _pixel_format;
  137. int _is_first_frame;
  138. int _is_running;
  139. int _file_status;
  140. int _lines_count;
  141. int _frame_count;
  142. unsigned int _risc_size;
  143. __le32 *_dma_virt_start_addr;
  144. __le32 *_dma_virt_addr;
  145. dma_addr_t _dma_phys_addr;
  146. dma_addr_t _dma_phys_start_addr;
  147. unsigned int _data_buf_size;
  148. __le32 *_data_buf_virt_addr;
  149. dma_addr_t _data_buf_phys_addr;
  150. u32 upstream_riscbuf_size;
  151. u32 upstream_databuf_size;
  152. int is_60hz;
  153. int _frame_index;
  154. int cur_frame_index;
  155. int curpos;
  156. wait_queue_head_t waitq;
  157. };
  158. struct cx25821_channel {
  159. unsigned id;
  160. struct cx25821_dev *dev;
  161. struct v4l2_ctrl_handler hdl;
  162. struct video_device vdev;
  163. struct cx25821_dmaqueue dma_vidq;
  164. struct vb2_queue vidq;
  165. const struct sram_channel *sram_channels;
  166. const struct cx25821_fmt *fmt;
  167. unsigned field;
  168. unsigned int width, height;
  169. int pixel_formats;
  170. int use_cif_resolution;
  171. int cif_width;
  172. /* video output data for the video output channel */
  173. struct cx25821_video_out_data *out;
  174. };
  175. struct snd_card;
  176. struct cx25821_dev {
  177. struct v4l2_device v4l2_dev;
  178. /* pci stuff */
  179. struct pci_dev *pci;
  180. unsigned char pci_rev, pci_lat;
  181. int pci_bus, pci_slot;
  182. u32 base_io_addr;
  183. u32 __iomem *lmmio;
  184. u8 __iomem *bmmio;
  185. int pci_irqmask;
  186. int hwrevision;
  187. /* used by cx25821-alsa */
  188. struct snd_card *card;
  189. u32 clk_freq;
  190. /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
  191. struct cx25821_i2c i2c_bus[3];
  192. int nr;
  193. struct mutex lock;
  194. struct cx25821_channel channels[MAX_VID_CHANNEL_NUM];
  195. /* board details */
  196. unsigned int board;
  197. char name[32];
  198. /* Analog video */
  199. unsigned int input;
  200. v4l2_std_id tvnorm;
  201. unsigned short _max_num_decoders;
  202. /* Analog Audio Upstream */
  203. int _audio_is_running;
  204. int _audiopixel_format;
  205. int _is_first_audio_frame;
  206. int _audiofile_status;
  207. int _audio_lines_count;
  208. int _audioframe_count;
  209. int _audio_upstream_channel;
  210. int _last_index_irq; /* The last interrupt index processed. */
  211. __le32 *_risc_audio_jmp_addr;
  212. __le32 *_risc_virt_start_addr;
  213. __le32 *_risc_virt_addr;
  214. dma_addr_t _risc_phys_addr;
  215. dma_addr_t _risc_phys_start_addr;
  216. unsigned int _audiorisc_size;
  217. unsigned int _audiodata_buf_size;
  218. __le32 *_audiodata_buf_virt_addr;
  219. dma_addr_t _audiodata_buf_phys_addr;
  220. char *_audiofilename;
  221. u32 audio_upstream_riscbuf_size;
  222. u32 audio_upstream_databuf_size;
  223. int _audioframe_index;
  224. struct work_struct _audio_work_entry;
  225. char *input_audiofilename;
  226. /* V4l */
  227. spinlock_t slock;
  228. /* Video Upstream */
  229. struct cx25821_video_out_data vid_out_data[2];
  230. };
  231. static inline struct cx25821_dev *get_cx25821(struct v4l2_device *v4l2_dev)
  232. {
  233. return container_of(v4l2_dev, struct cx25821_dev, v4l2_dev);
  234. }
  235. extern struct cx25821_board cx25821_boards[];
  236. #define SRAM_CH00 0 /* Video A */
  237. #define SRAM_CH01 1 /* Video B */
  238. #define SRAM_CH02 2 /* Video C */
  239. #define SRAM_CH03 3 /* Video D */
  240. #define SRAM_CH04 4 /* Video E */
  241. #define SRAM_CH05 5 /* Video F */
  242. #define SRAM_CH06 6 /* Video G */
  243. #define SRAM_CH07 7 /* Video H */
  244. #define SRAM_CH08 8 /* Audio A */
  245. #define SRAM_CH09 9 /* Video Upstream I */
  246. #define SRAM_CH10 10 /* Video Upstream J */
  247. #define SRAM_CH11 11 /* Audio Upstream AUD_CHANNEL_B */
  248. #define VID_UPSTREAM_SRAM_CHANNEL_I SRAM_CH09
  249. #define VID_UPSTREAM_SRAM_CHANNEL_J SRAM_CH10
  250. #define AUDIO_UPSTREAM_SRAM_CHANNEL_B SRAM_CH11
  251. struct sram_channel {
  252. char *name;
  253. u32 i;
  254. u32 cmds_start;
  255. u32 ctrl_start;
  256. u32 cdt;
  257. u32 fifo_start;
  258. u32 fifo_size;
  259. u32 ptr1_reg;
  260. u32 ptr2_reg;
  261. u32 cnt1_reg;
  262. u32 cnt2_reg;
  263. u32 int_msk;
  264. u32 int_stat;
  265. u32 int_mstat;
  266. u32 dma_ctl;
  267. u32 gpcnt_ctl;
  268. u32 gpcnt;
  269. u32 aud_length;
  270. u32 aud_cfg;
  271. u32 fld_aud_fifo_en;
  272. u32 fld_aud_risc_en;
  273. /* For Upstream Video */
  274. u32 vid_fmt_ctl;
  275. u32 vid_active_ctl1;
  276. u32 vid_active_ctl2;
  277. u32 vid_cdt_size;
  278. u32 vip_ctl;
  279. u32 pix_frmt;
  280. u32 jumponly;
  281. u32 irq_bit;
  282. };
  283. extern const struct sram_channel cx25821_sram_channels[];
  284. #define cx_read(reg) readl(dev->lmmio + ((reg)>>2))
  285. #define cx_write(reg, value) writel((value), dev->lmmio + ((reg)>>2))
  286. #define cx_andor(reg, mask, value) \
  287. writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
  288. ((value) & (mask)), dev->lmmio+((reg)>>2))
  289. #define cx_set(reg, bit) cx_andor((reg), (bit), (bit))
  290. #define cx_clear(reg, bit) cx_andor((reg), (bit), 0)
  291. #define Set_GPIO_Bit(Bit) (1 << Bit)
  292. #define Clear_GPIO_Bit(Bit) (~(1 << Bit))
  293. #define CX25821_ERR(fmt, args...) \
  294. pr_err("(%d): " fmt, dev->board, ##args)
  295. #define CX25821_WARN(fmt, args...) \
  296. pr_warn("(%d): " fmt, dev->board, ##args)
  297. #define CX25821_INFO(fmt, args...) \
  298. pr_info("(%d): " fmt, dev->board, ##args)
  299. extern int cx25821_i2c_register(struct cx25821_i2c *bus);
  300. extern int cx25821_i2c_read(struct cx25821_i2c *bus, u16 reg_addr, int *value);
  301. extern int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value);
  302. extern int cx25821_i2c_unregister(struct cx25821_i2c *bus);
  303. extern void cx25821_gpio_init(struct cx25821_dev *dev);
  304. extern void cx25821_set_gpiopin_direction(struct cx25821_dev *dev,
  305. int pin_number, int pin_logic_value);
  306. extern int medusa_video_init(struct cx25821_dev *dev);
  307. extern int medusa_set_videostandard(struct cx25821_dev *dev);
  308. extern void medusa_set_resolution(struct cx25821_dev *dev, int width,
  309. int decoder_select);
  310. extern int medusa_set_brightness(struct cx25821_dev *dev, int brightness,
  311. int decoder);
  312. extern int medusa_set_contrast(struct cx25821_dev *dev, int contrast,
  313. int decoder);
  314. extern int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder);
  315. extern int medusa_set_saturation(struct cx25821_dev *dev, int saturation,
  316. int decoder);
  317. extern int cx25821_sram_channel_setup(struct cx25821_dev *dev,
  318. const struct sram_channel *ch, unsigned int bpl,
  319. u32 risc);
  320. extern int cx25821_riscmem_alloc(struct pci_dev *pci,
  321. struct cx25821_riscmem *risc,
  322. unsigned int size);
  323. extern int cx25821_risc_buffer(struct pci_dev *pci, struct cx25821_riscmem *risc,
  324. struct scatterlist *sglist,
  325. unsigned int top_offset,
  326. unsigned int bottom_offset,
  327. unsigned int bpl,
  328. unsigned int padding, unsigned int lines);
  329. extern int cx25821_risc_databuffer_audio(struct pci_dev *pci,
  330. struct cx25821_riscmem *risc,
  331. struct scatterlist *sglist,
  332. unsigned int bpl,
  333. unsigned int lines, unsigned int lpi);
  334. extern void cx25821_free_buffer(struct cx25821_dev *dev,
  335. struct cx25821_buffer *buf);
  336. extern void cx25821_sram_channel_dump(struct cx25821_dev *dev,
  337. const struct sram_channel *ch);
  338. extern void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
  339. const struct sram_channel *ch);
  340. extern struct cx25821_dev *cx25821_dev_get(struct pci_dev *pci);
  341. extern void cx25821_print_irqbits(char *name, char *tag, char **strings,
  342. int len, u32 bits, u32 mask);
  343. extern void cx25821_dev_unregister(struct cx25821_dev *dev);
  344. extern int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
  345. const struct sram_channel *ch,
  346. unsigned int bpl, u32 risc);
  347. extern void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel,
  348. u32 format);
  349. #endif