cx25821.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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/videobuf-dma-sg.h>
  35. #include "btcx-risc.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. #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. /* buffer for one video frame */
  96. struct cx25821_buffer {
  97. /* common v4l buffer stuff -- must be first */
  98. struct videobuf_buffer vb;
  99. /* cx25821 specific */
  100. unsigned int bpl;
  101. struct btcx_riscmem risc;
  102. const struct cx25821_fmt *fmt;
  103. u32 count;
  104. };
  105. enum port {
  106. CX25821_UNDEFINED = 0,
  107. CX25821_RAW,
  108. CX25821_264
  109. };
  110. struct cx25821_board {
  111. const char *name;
  112. enum port porta;
  113. enum port portb;
  114. enum port portc;
  115. u32 clk_freq;
  116. };
  117. struct cx25821_i2c {
  118. struct cx25821_dev *dev;
  119. int nr;
  120. /* i2c i/o */
  121. struct i2c_adapter i2c_adap;
  122. struct i2c_client i2c_client;
  123. u32 i2c_rc;
  124. /* cx25821 registers used for raw addess */
  125. u32 i2c_period;
  126. u32 reg_ctrl;
  127. u32 reg_stat;
  128. u32 reg_addr;
  129. u32 reg_rdata;
  130. u32 reg_wdata;
  131. };
  132. struct cx25821_dmaqueue {
  133. struct list_head active;
  134. struct list_head queued;
  135. struct timer_list timeout;
  136. struct btcx_riscmem stopper;
  137. u32 count;
  138. };
  139. struct cx25821_data {
  140. struct cx25821_dev *dev;
  141. const struct sram_channel *channel;
  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_fh *streaming_fh;
  175. struct v4l2_ctrl_handler hdl;
  176. struct cx25821_data timeout_data;
  177. struct video_device vdev;
  178. struct cx25821_dmaqueue dma_vidq;
  179. struct videobuf_queue vidq;
  180. const struct sram_channel *sram_channels;
  181. const struct cx25821_fmt *fmt;
  182. unsigned int width, height;
  183. int pixel_formats;
  184. int use_cif_resolution;
  185. int cif_width;
  186. /* video output data for the video output channel */
  187. struct cx25821_video_out_data *out;
  188. };
  189. struct snd_card;
  190. struct cx25821_dev {
  191. struct v4l2_device v4l2_dev;
  192. /* pci stuff */
  193. struct pci_dev *pci;
  194. unsigned char pci_rev, pci_lat;
  195. int pci_bus, pci_slot;
  196. u32 base_io_addr;
  197. u32 __iomem *lmmio;
  198. u8 __iomem *bmmio;
  199. int pci_irqmask;
  200. int hwrevision;
  201. /* used by cx25821-alsa */
  202. struct snd_card *card;
  203. u32 clk_freq;
  204. /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
  205. struct cx25821_i2c i2c_bus[3];
  206. int nr;
  207. struct mutex lock;
  208. struct cx25821_channel channels[MAX_VID_CHANNEL_NUM];
  209. /* board details */
  210. unsigned int board;
  211. char name[32];
  212. /* Analog video */
  213. unsigned int input;
  214. v4l2_std_id tvnorm;
  215. unsigned short _max_num_decoders;
  216. /* Analog Audio Upstream */
  217. int _audio_is_running;
  218. int _audiopixel_format;
  219. int _is_first_audio_frame;
  220. int _audiofile_status;
  221. int _audio_lines_count;
  222. int _audioframe_count;
  223. int _audio_upstream_channel;
  224. int _last_index_irq; /* The last interrupt index processed. */
  225. __le32 *_risc_audio_jmp_addr;
  226. __le32 *_risc_virt_start_addr;
  227. __le32 *_risc_virt_addr;
  228. dma_addr_t _risc_phys_addr;
  229. dma_addr_t _risc_phys_start_addr;
  230. unsigned int _audiorisc_size;
  231. unsigned int _audiodata_buf_size;
  232. __le32 *_audiodata_buf_virt_addr;
  233. dma_addr_t _audiodata_buf_phys_addr;
  234. char *_audiofilename;
  235. u32 audio_upstream_riscbuf_size;
  236. u32 audio_upstream_databuf_size;
  237. int _audioframe_index;
  238. struct workqueue_struct *_irq_audio_queues;
  239. struct work_struct _audio_work_entry;
  240. char *input_audiofilename;
  241. /* V4l */
  242. spinlock_t slock;
  243. /* Video Upstream */
  244. struct cx25821_video_out_data vid_out_data[2];
  245. };
  246. static inline struct cx25821_dev *get_cx25821(struct v4l2_device *v4l2_dev)
  247. {
  248. return container_of(v4l2_dev, struct cx25821_dev, v4l2_dev);
  249. }
  250. extern struct cx25821_board cx25821_boards[];
  251. #define SRAM_CH00 0 /* Video A */
  252. #define SRAM_CH01 1 /* Video B */
  253. #define SRAM_CH02 2 /* Video C */
  254. #define SRAM_CH03 3 /* Video D */
  255. #define SRAM_CH04 4 /* Video E */
  256. #define SRAM_CH05 5 /* Video F */
  257. #define SRAM_CH06 6 /* Video G */
  258. #define SRAM_CH07 7 /* Video H */
  259. #define SRAM_CH08 8 /* Audio A */
  260. #define SRAM_CH09 9 /* Video Upstream I */
  261. #define SRAM_CH10 10 /* Video Upstream J */
  262. #define SRAM_CH11 11 /* Audio Upstream AUD_CHANNEL_B */
  263. #define VID_UPSTREAM_SRAM_CHANNEL_I SRAM_CH09
  264. #define VID_UPSTREAM_SRAM_CHANNEL_J SRAM_CH10
  265. #define AUDIO_UPSTREAM_SRAM_CHANNEL_B SRAM_CH11
  266. struct sram_channel {
  267. char *name;
  268. u32 i;
  269. u32 cmds_start;
  270. u32 ctrl_start;
  271. u32 cdt;
  272. u32 fifo_start;
  273. u32 fifo_size;
  274. u32 ptr1_reg;
  275. u32 ptr2_reg;
  276. u32 cnt1_reg;
  277. u32 cnt2_reg;
  278. u32 int_msk;
  279. u32 int_stat;
  280. u32 int_mstat;
  281. u32 dma_ctl;
  282. u32 gpcnt_ctl;
  283. u32 gpcnt;
  284. u32 aud_length;
  285. u32 aud_cfg;
  286. u32 fld_aud_fifo_en;
  287. u32 fld_aud_risc_en;
  288. /* For Upstream Video */
  289. u32 vid_fmt_ctl;
  290. u32 vid_active_ctl1;
  291. u32 vid_active_ctl2;
  292. u32 vid_cdt_size;
  293. u32 vip_ctl;
  294. u32 pix_frmt;
  295. u32 jumponly;
  296. u32 irq_bit;
  297. };
  298. extern const struct sram_channel cx25821_sram_channels[];
  299. #define cx_read(reg) readl(dev->lmmio + ((reg)>>2))
  300. #define cx_write(reg, value) writel((value), dev->lmmio + ((reg)>>2))
  301. #define cx_andor(reg, mask, value) \
  302. writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
  303. ((value) & (mask)), dev->lmmio+((reg)>>2))
  304. #define cx_set(reg, bit) cx_andor((reg), (bit), (bit))
  305. #define cx_clear(reg, bit) cx_andor((reg), (bit), 0)
  306. #define Set_GPIO_Bit(Bit) (1 << Bit)
  307. #define Clear_GPIO_Bit(Bit) (~(1 << Bit))
  308. #define CX25821_ERR(fmt, args...) \
  309. pr_err("(%d): " fmt, dev->board, ##args)
  310. #define CX25821_WARN(fmt, args...) \
  311. pr_warn("(%d): " fmt, dev->board, ##args)
  312. #define CX25821_INFO(fmt, args...) \
  313. pr_info("(%d): " fmt, dev->board, ##args)
  314. extern int cx25821_i2c_register(struct cx25821_i2c *bus);
  315. extern int cx25821_i2c_read(struct cx25821_i2c *bus, u16 reg_addr, int *value);
  316. extern int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value);
  317. extern int cx25821_i2c_unregister(struct cx25821_i2c *bus);
  318. extern void cx25821_gpio_init(struct cx25821_dev *dev);
  319. extern void cx25821_set_gpiopin_direction(struct cx25821_dev *dev,
  320. int pin_number, int pin_logic_value);
  321. extern int medusa_video_init(struct cx25821_dev *dev);
  322. extern int medusa_set_videostandard(struct cx25821_dev *dev);
  323. extern void medusa_set_resolution(struct cx25821_dev *dev, int width,
  324. int decoder_select);
  325. extern int medusa_set_brightness(struct cx25821_dev *dev, int brightness,
  326. int decoder);
  327. extern int medusa_set_contrast(struct cx25821_dev *dev, int contrast,
  328. int decoder);
  329. extern int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder);
  330. extern int medusa_set_saturation(struct cx25821_dev *dev, int saturation,
  331. int decoder);
  332. extern int cx25821_sram_channel_setup(struct cx25821_dev *dev,
  333. const struct sram_channel *ch, unsigned int bpl,
  334. u32 risc);
  335. extern int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_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 btcx_riscmem *risc,
  343. struct scatterlist *sglist,
  344. unsigned int bpl,
  345. unsigned int lines, unsigned int lpi);
  346. extern void cx25821_free_buffer(struct videobuf_queue *q,
  347. struct cx25821_buffer *buf);
  348. extern int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
  349. u32 reg, u32 mask, u32 value);
  350. extern void cx25821_sram_channel_dump(struct cx25821_dev *dev,
  351. const struct sram_channel *ch);
  352. extern void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
  353. const struct sram_channel *ch);
  354. extern struct cx25821_dev *cx25821_dev_get(struct pci_dev *pci);
  355. extern void cx25821_print_irqbits(char *name, char *tag, char **strings,
  356. int len, u32 bits, u32 mask);
  357. extern void cx25821_dev_unregister(struct cx25821_dev *dev);
  358. extern int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
  359. const struct sram_channel *ch,
  360. unsigned int bpl, u32 risc);
  361. extern int cx25821_vidupstream_init(struct cx25821_channel *chan, int pixel_format);
  362. extern int cx25821_audio_upstream_init(struct cx25821_dev *dev,
  363. int channel_select);
  364. extern int cx25821_write_frame(struct cx25821_channel *chan,
  365. const char __user *data, size_t count);
  366. extern void cx25821_free_mem_upstream(struct cx25821_channel *chan);
  367. extern void cx25821_free_mem_upstream_audio(struct cx25821_dev *dev);
  368. extern void cx25821_stop_upstream_video(struct cx25821_channel *chan);
  369. extern void cx25821_stop_upstream_audio(struct cx25821_dev *dev);
  370. extern int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
  371. const struct sram_channel *ch,
  372. unsigned int bpl, u32 risc);
  373. extern void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel,
  374. u32 format);
  375. #endif