cx25821.h 11 KB

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