cx25821.h 12 KB

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