cx25821.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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. void *alloc_ctx;
  207. u32 clk_freq;
  208. /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
  209. struct cx25821_i2c i2c_bus[3];
  210. int nr;
  211. struct mutex lock;
  212. struct cx25821_channel channels[MAX_VID_CHANNEL_NUM];
  213. /* board details */
  214. unsigned int board;
  215. char name[32];
  216. /* Analog video */
  217. unsigned int input;
  218. v4l2_std_id tvnorm;
  219. unsigned short _max_num_decoders;
  220. /* Analog Audio Upstream */
  221. int _audio_is_running;
  222. int _audiopixel_format;
  223. int _is_first_audio_frame;
  224. int _audiofile_status;
  225. int _audio_lines_count;
  226. int _audioframe_count;
  227. int _audio_upstream_channel;
  228. int _last_index_irq; /* The last interrupt index processed. */
  229. __le32 *_risc_audio_jmp_addr;
  230. __le32 *_risc_virt_start_addr;
  231. __le32 *_risc_virt_addr;
  232. dma_addr_t _risc_phys_addr;
  233. dma_addr_t _risc_phys_start_addr;
  234. unsigned int _audiorisc_size;
  235. unsigned int _audiodata_buf_size;
  236. __le32 *_audiodata_buf_virt_addr;
  237. dma_addr_t _audiodata_buf_phys_addr;
  238. char *_audiofilename;
  239. u32 audio_upstream_riscbuf_size;
  240. u32 audio_upstream_databuf_size;
  241. int _audioframe_index;
  242. struct workqueue_struct *_irq_audio_queues;
  243. struct work_struct _audio_work_entry;
  244. char *input_audiofilename;
  245. /* V4l */
  246. spinlock_t slock;
  247. /* Video Upstream */
  248. struct cx25821_video_out_data vid_out_data[2];
  249. };
  250. static inline struct cx25821_dev *get_cx25821(struct v4l2_device *v4l2_dev)
  251. {
  252. return container_of(v4l2_dev, struct cx25821_dev, v4l2_dev);
  253. }
  254. extern struct cx25821_board cx25821_boards[];
  255. #define SRAM_CH00 0 /* Video A */
  256. #define SRAM_CH01 1 /* Video B */
  257. #define SRAM_CH02 2 /* Video C */
  258. #define SRAM_CH03 3 /* Video D */
  259. #define SRAM_CH04 4 /* Video E */
  260. #define SRAM_CH05 5 /* Video F */
  261. #define SRAM_CH06 6 /* Video G */
  262. #define SRAM_CH07 7 /* Video H */
  263. #define SRAM_CH08 8 /* Audio A */
  264. #define SRAM_CH09 9 /* Video Upstream I */
  265. #define SRAM_CH10 10 /* Video Upstream J */
  266. #define SRAM_CH11 11 /* Audio Upstream AUD_CHANNEL_B */
  267. #define VID_UPSTREAM_SRAM_CHANNEL_I SRAM_CH09
  268. #define VID_UPSTREAM_SRAM_CHANNEL_J SRAM_CH10
  269. #define AUDIO_UPSTREAM_SRAM_CHANNEL_B SRAM_CH11
  270. struct sram_channel {
  271. char *name;
  272. u32 i;
  273. u32 cmds_start;
  274. u32 ctrl_start;
  275. u32 cdt;
  276. u32 fifo_start;
  277. u32 fifo_size;
  278. u32 ptr1_reg;
  279. u32 ptr2_reg;
  280. u32 cnt1_reg;
  281. u32 cnt2_reg;
  282. u32 int_msk;
  283. u32 int_stat;
  284. u32 int_mstat;
  285. u32 dma_ctl;
  286. u32 gpcnt_ctl;
  287. u32 gpcnt;
  288. u32 aud_length;
  289. u32 aud_cfg;
  290. u32 fld_aud_fifo_en;
  291. u32 fld_aud_risc_en;
  292. /* For Upstream Video */
  293. u32 vid_fmt_ctl;
  294. u32 vid_active_ctl1;
  295. u32 vid_active_ctl2;
  296. u32 vid_cdt_size;
  297. u32 vip_ctl;
  298. u32 pix_frmt;
  299. u32 jumponly;
  300. u32 irq_bit;
  301. };
  302. extern const struct sram_channel cx25821_sram_channels[];
  303. #define cx_read(reg) readl(dev->lmmio + ((reg)>>2))
  304. #define cx_write(reg, value) writel((value), dev->lmmio + ((reg)>>2))
  305. #define cx_andor(reg, mask, value) \
  306. writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
  307. ((value) & (mask)), dev->lmmio+((reg)>>2))
  308. #define cx_set(reg, bit) cx_andor((reg), (bit), (bit))
  309. #define cx_clear(reg, bit) cx_andor((reg), (bit), 0)
  310. #define Set_GPIO_Bit(Bit) (1 << Bit)
  311. #define Clear_GPIO_Bit(Bit) (~(1 << Bit))
  312. #define CX25821_ERR(fmt, args...) \
  313. pr_err("(%d): " fmt, dev->board, ##args)
  314. #define CX25821_WARN(fmt, args...) \
  315. pr_warn("(%d): " fmt, dev->board, ##args)
  316. #define CX25821_INFO(fmt, args...) \
  317. pr_info("(%d): " fmt, dev->board, ##args)
  318. extern int cx25821_i2c_register(struct cx25821_i2c *bus);
  319. extern int cx25821_i2c_read(struct cx25821_i2c *bus, u16 reg_addr, int *value);
  320. extern int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value);
  321. extern int cx25821_i2c_unregister(struct cx25821_i2c *bus);
  322. extern void cx25821_gpio_init(struct cx25821_dev *dev);
  323. extern void cx25821_set_gpiopin_direction(struct cx25821_dev *dev,
  324. int pin_number, int pin_logic_value);
  325. extern int medusa_video_init(struct cx25821_dev *dev);
  326. extern int medusa_set_videostandard(struct cx25821_dev *dev);
  327. extern void medusa_set_resolution(struct cx25821_dev *dev, int width,
  328. int decoder_select);
  329. extern int medusa_set_brightness(struct cx25821_dev *dev, int brightness,
  330. int decoder);
  331. extern int medusa_set_contrast(struct cx25821_dev *dev, int contrast,
  332. int decoder);
  333. extern int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder);
  334. extern int medusa_set_saturation(struct cx25821_dev *dev, int saturation,
  335. int decoder);
  336. extern int cx25821_sram_channel_setup(struct cx25821_dev *dev,
  337. const struct sram_channel *ch, unsigned int bpl,
  338. u32 risc);
  339. extern int cx25821_riscmem_alloc(struct pci_dev *pci,
  340. struct cx25821_riscmem *risc,
  341. unsigned int size);
  342. extern int cx25821_risc_buffer(struct pci_dev *pci, struct cx25821_riscmem *risc,
  343. struct scatterlist *sglist,
  344. unsigned int top_offset,
  345. unsigned int bottom_offset,
  346. unsigned int bpl,
  347. unsigned int padding, unsigned int lines);
  348. extern int cx25821_risc_databuffer_audio(struct pci_dev *pci,
  349. struct cx25821_riscmem *risc,
  350. struct scatterlist *sglist,
  351. unsigned int bpl,
  352. unsigned int lines, unsigned int lpi);
  353. extern void cx25821_free_buffer(struct cx25821_dev *dev,
  354. struct cx25821_buffer *buf);
  355. extern void cx25821_sram_channel_dump(struct cx25821_dev *dev,
  356. const struct sram_channel *ch);
  357. extern void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
  358. const struct sram_channel *ch);
  359. extern struct cx25821_dev *cx25821_dev_get(struct pci_dev *pci);
  360. extern void cx25821_print_irqbits(char *name, char *tag, char **strings,
  361. int len, u32 bits, u32 mask);
  362. extern void cx25821_dev_unregister(struct cx25821_dev *dev);
  363. extern int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
  364. const struct sram_channel *ch,
  365. unsigned int bpl, u32 risc);
  366. extern int cx25821_vidupstream_init(struct cx25821_channel *chan, int pixel_format);
  367. extern int cx25821_audio_upstream_init(struct cx25821_dev *dev,
  368. int channel_select);
  369. extern int cx25821_write_frame(struct cx25821_channel *chan,
  370. const char __user *data, size_t count);
  371. extern void cx25821_free_mem_upstream(struct cx25821_channel *chan);
  372. extern void cx25821_free_mem_upstream_audio(struct cx25821_dev *dev);
  373. extern void cx25821_stop_upstream_video(struct cx25821_channel *chan);
  374. extern void cx25821_stop_upstream_audio(struct cx25821_dev *dev);
  375. extern int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
  376. const struct sram_channel *ch,
  377. unsigned int bpl, u32 risc);
  378. extern void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel,
  379. u32 format);
  380. #endif