cx25821.h 12 KB

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