cx25821.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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 INPUT(nr) (&cx25821_boards[dev->board].input[nr])
  55. #define RESOURCE_VIDEO0 1
  56. #define RESOURCE_VIDEO1 2
  57. #define RESOURCE_VIDEO2 4
  58. #define RESOURCE_VIDEO3 8
  59. #define RESOURCE_VIDEO4 16
  60. #define RESOURCE_VIDEO5 32
  61. #define RESOURCE_VIDEO6 64
  62. #define RESOURCE_VIDEO7 128
  63. #define RESOURCE_VIDEO8 256
  64. #define RESOURCE_VIDEO9 512
  65. #define RESOURCE_VIDEO10 1024
  66. #define RESOURCE_VIDEO11 2048
  67. #define BUFFER_TIMEOUT (HZ) /* 0.5 seconds */
  68. #define UNKNOWN_BOARD 0
  69. #define CX25821_BOARD 1
  70. /* Currently supported by the driver */
  71. #define CX25821_NORMS (\
  72. V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_M_KR | \
  73. V4L2_STD_PAL_BG | V4L2_STD_PAL_DK | V4L2_STD_PAL_I | \
  74. V4L2_STD_PAL_M | V4L2_STD_PAL_N | V4L2_STD_PAL_H | \
  75. V4L2_STD_PAL_Nc)
  76. #define CX25821_BOARD_CONEXANT_ATHENA10 1
  77. #define MAX_VID_CHANNEL_NUM 12
  78. #define VID_CHANNEL_NUM 8
  79. #define CX25821_NR_INPUT 2
  80. struct cx25821_fmt {
  81. char *name;
  82. u32 fourcc; /* v4l2 format id */
  83. int depth;
  84. int flags;
  85. u32 cxformat;
  86. };
  87. struct cx25821_ctrl {
  88. struct v4l2_queryctrl v;
  89. u32 off;
  90. u32 reg;
  91. u32 mask;
  92. u32 shift;
  93. };
  94. struct cx25821_tvnorm {
  95. char *name;
  96. v4l2_std_id id;
  97. u32 cxiformat;
  98. u32 cxoformat;
  99. };
  100. struct cx25821_fh {
  101. struct cx25821_dev *dev;
  102. enum v4l2_priority prio;
  103. /* video capture */
  104. int channel_id;
  105. };
  106. enum cx25821_itype {
  107. CX25821_VMUX_COMPOSITE = 1,
  108. CX25821_VMUX_SVIDEO,
  109. CX25821_VMUX_DEBUG,
  110. };
  111. enum cx25821_src_sel_type {
  112. CX25821_SRC_SEL_EXT_656_VIDEO = 0,
  113. CX25821_SRC_SEL_PARALLEL_MPEG_VIDEO
  114. };
  115. /* buffer for one video frame */
  116. struct cx25821_buffer {
  117. /* common v4l buffer stuff -- must be first */
  118. struct videobuf_buffer vb;
  119. /* cx25821 specific */
  120. unsigned int bpl;
  121. struct btcx_riscmem risc;
  122. const struct cx25821_fmt *fmt;
  123. u32 count;
  124. };
  125. struct cx25821_input {
  126. enum cx25821_itype type;
  127. unsigned int vmux;
  128. u32 gpio0, gpio1, gpio2, gpio3;
  129. };
  130. enum port {
  131. CX25821_UNDEFINED = 0,
  132. CX25821_RAW,
  133. CX25821_264
  134. };
  135. struct cx25821_board {
  136. const char *name;
  137. enum port porta;
  138. enum port portb;
  139. enum port portc;
  140. u32 clk_freq;
  141. struct cx25821_input input[CX25821_NR_INPUT];
  142. };
  143. struct cx25821_i2c {
  144. struct cx25821_dev *dev;
  145. int nr;
  146. /* i2c i/o */
  147. struct i2c_adapter i2c_adap;
  148. struct i2c_client i2c_client;
  149. u32 i2c_rc;
  150. /* cx25821 registers used for raw addess */
  151. u32 i2c_period;
  152. u32 reg_ctrl;
  153. u32 reg_stat;
  154. u32 reg_addr;
  155. u32 reg_rdata;
  156. u32 reg_wdata;
  157. };
  158. struct cx25821_dmaqueue {
  159. struct list_head active;
  160. struct list_head queued;
  161. struct timer_list timeout;
  162. struct btcx_riscmem stopper;
  163. u32 count;
  164. };
  165. struct cx25821_data {
  166. struct cx25821_dev *dev;
  167. const struct sram_channel *channel;
  168. };
  169. struct cx25821_dev;
  170. struct cx25821_channel {
  171. unsigned id;
  172. struct cx25821_dev *dev;
  173. struct cx25821_fh *streaming_fh;
  174. struct v4l2_prio_state prio;
  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. };
  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. /* V4l */
  234. spinlock_t slock;
  235. /* Video Upstream */
  236. int _line_size;
  237. int _prog_cnt;
  238. int _pixel_format;
  239. int _is_first_frame;
  240. int _is_running;
  241. int _file_status;
  242. int _lines_count;
  243. int _frame_count;
  244. int _channel_upstream_select;
  245. unsigned int _risc_size;
  246. __le32 *_dma_virt_start_addr;
  247. __le32 *_dma_virt_addr;
  248. dma_addr_t _dma_phys_addr;
  249. dma_addr_t _dma_phys_start_addr;
  250. unsigned int _data_buf_size;
  251. __le32 *_data_buf_virt_addr;
  252. dma_addr_t _data_buf_phys_addr;
  253. char *_filename;
  254. char *_defaultname;
  255. int _line_size_ch2;
  256. int _prog_cnt_ch2;
  257. int _pixel_format_ch2;
  258. int _is_first_frame_ch2;
  259. int _is_running_ch2;
  260. int _file_status_ch2;
  261. int _lines_count_ch2;
  262. int _frame_count_ch2;
  263. int _channel2_upstream_select;
  264. unsigned int _risc_size_ch2;
  265. __le32 *_dma_virt_start_addr_ch2;
  266. __le32 *_dma_virt_addr_ch2;
  267. dma_addr_t _dma_phys_addr_ch2;
  268. dma_addr_t _dma_phys_start_addr_ch2;
  269. unsigned int _data_buf_size_ch2;
  270. __le32 *_data_buf_virt_addr_ch2;
  271. dma_addr_t _data_buf_phys_addr_ch2;
  272. char *_filename_ch2;
  273. char *_defaultname_ch2;
  274. u32 upstream_riscbuf_size;
  275. u32 upstream_databuf_size;
  276. u32 upstream_riscbuf_size_ch2;
  277. u32 upstream_databuf_size_ch2;
  278. u32 audio_upstream_riscbuf_size;
  279. u32 audio_upstream_databuf_size;
  280. int _isNTSC;
  281. int _frame_index;
  282. int _audioframe_index;
  283. struct workqueue_struct *_irq_queues;
  284. struct work_struct _irq_work_entry;
  285. struct workqueue_struct *_irq_queues_ch2;
  286. struct work_struct _irq_work_entry_ch2;
  287. struct workqueue_struct *_irq_audio_queues;
  288. struct work_struct _audio_work_entry;
  289. char *input_filename;
  290. char *input_filename_ch2;
  291. int _frame_index_ch2;
  292. int _isNTSC_ch2;
  293. char *vid_stdname_ch2;
  294. int pixel_format_ch2;
  295. int channel_select_ch2;
  296. int command_ch2;
  297. char *input_audiofilename;
  298. char *vid_stdname;
  299. int pixel_format;
  300. int channel_select;
  301. int command;
  302. int channel_opened;
  303. };
  304. struct upstream_user_struct {
  305. char *input_filename;
  306. char *vid_stdname;
  307. int pixel_format;
  308. int channel_select;
  309. int command;
  310. };
  311. struct downstream_user_struct {
  312. char *vid_stdname;
  313. int pixel_format;
  314. int cif_resolution_enable;
  315. int cif_width;
  316. int decoder_select;
  317. int command;
  318. int reg_address;
  319. int reg_data;
  320. };
  321. extern struct upstream_user_struct *up_data;
  322. static inline struct cx25821_dev *get_cx25821(struct v4l2_device *v4l2_dev)
  323. {
  324. return container_of(v4l2_dev, struct cx25821_dev, v4l2_dev);
  325. }
  326. #define cx25821_call_all(dev, o, f, args...) \
  327. v4l2_device_call_all(&dev->v4l2_dev, 0, o, f, ##args)
  328. extern struct cx25821_board cx25821_boards[];
  329. #define SRAM_CH00 0 /* Video A */
  330. #define SRAM_CH01 1 /* Video B */
  331. #define SRAM_CH02 2 /* Video C */
  332. #define SRAM_CH03 3 /* Video D */
  333. #define SRAM_CH04 4 /* Video E */
  334. #define SRAM_CH05 5 /* Video F */
  335. #define SRAM_CH06 6 /* Video G */
  336. #define SRAM_CH07 7 /* Video H */
  337. #define SRAM_CH08 8 /* Audio A */
  338. #define SRAM_CH09 9 /* Video Upstream I */
  339. #define SRAM_CH10 10 /* Video Upstream J */
  340. #define SRAM_CH11 11 /* Audio Upstream AUD_CHANNEL_B */
  341. #define VID_UPSTREAM_SRAM_CHANNEL_I SRAM_CH09
  342. #define VID_UPSTREAM_SRAM_CHANNEL_J SRAM_CH10
  343. #define AUDIO_UPSTREAM_SRAM_CHANNEL_B SRAM_CH11
  344. struct sram_channel {
  345. char *name;
  346. u32 i;
  347. u32 cmds_start;
  348. u32 ctrl_start;
  349. u32 cdt;
  350. u32 fifo_start;
  351. u32 fifo_size;
  352. u32 ptr1_reg;
  353. u32 ptr2_reg;
  354. u32 cnt1_reg;
  355. u32 cnt2_reg;
  356. u32 int_msk;
  357. u32 int_stat;
  358. u32 int_mstat;
  359. u32 dma_ctl;
  360. u32 gpcnt_ctl;
  361. u32 gpcnt;
  362. u32 aud_length;
  363. u32 aud_cfg;
  364. u32 fld_aud_fifo_en;
  365. u32 fld_aud_risc_en;
  366. /* For Upstream Video */
  367. u32 vid_fmt_ctl;
  368. u32 vid_active_ctl1;
  369. u32 vid_active_ctl2;
  370. u32 vid_cdt_size;
  371. u32 vip_ctl;
  372. u32 pix_frmt;
  373. u32 jumponly;
  374. u32 irq_bit;
  375. };
  376. extern const struct sram_channel cx25821_sram_channels[];
  377. #define cx_read(reg) readl(dev->lmmio + ((reg)>>2))
  378. #define cx_write(reg, value) writel((value), dev->lmmio + ((reg)>>2))
  379. #define cx_andor(reg, mask, value) \
  380. writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
  381. ((value) & (mask)), dev->lmmio+((reg)>>2))
  382. #define cx_set(reg, bit) cx_andor((reg), (bit), (bit))
  383. #define cx_clear(reg, bit) cx_andor((reg), (bit), 0)
  384. #define Set_GPIO_Bit(Bit) (1 << Bit)
  385. #define Clear_GPIO_Bit(Bit) (~(1 << Bit))
  386. #define CX25821_ERR(fmt, args...) \
  387. pr_err("(%d): " fmt, dev->board, ##args)
  388. #define CX25821_WARN(fmt, args...) \
  389. pr_warn("(%d): " fmt, dev->board, ##args)
  390. #define CX25821_INFO(fmt, args...) \
  391. pr_info("(%d): " fmt, dev->board, ##args)
  392. extern int cx25821_i2c_register(struct cx25821_i2c *bus);
  393. extern int cx25821_i2c_read(struct cx25821_i2c *bus, u16 reg_addr, int *value);
  394. extern int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value);
  395. extern int cx25821_i2c_unregister(struct cx25821_i2c *bus);
  396. extern void cx25821_gpio_init(struct cx25821_dev *dev);
  397. extern void cx25821_set_gpiopin_direction(struct cx25821_dev *dev,
  398. int pin_number, int pin_logic_value);
  399. extern int medusa_video_init(struct cx25821_dev *dev);
  400. extern int medusa_set_videostandard(struct cx25821_dev *dev);
  401. extern void medusa_set_resolution(struct cx25821_dev *dev, int width,
  402. int decoder_select);
  403. extern int medusa_set_brightness(struct cx25821_dev *dev, int brightness,
  404. int decoder);
  405. extern int medusa_set_contrast(struct cx25821_dev *dev, int contrast,
  406. int decoder);
  407. extern int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder);
  408. extern int medusa_set_saturation(struct cx25821_dev *dev, int saturation,
  409. int decoder);
  410. extern int cx25821_sram_channel_setup(struct cx25821_dev *dev,
  411. const struct sram_channel *ch, unsigned int bpl,
  412. u32 risc);
  413. extern int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
  414. struct scatterlist *sglist,
  415. unsigned int top_offset,
  416. unsigned int bottom_offset,
  417. unsigned int bpl,
  418. unsigned int padding, unsigned int lines);
  419. extern int cx25821_risc_databuffer_audio(struct pci_dev *pci,
  420. struct btcx_riscmem *risc,
  421. struct scatterlist *sglist,
  422. unsigned int bpl,
  423. unsigned int lines, unsigned int lpi);
  424. extern void cx25821_free_buffer(struct videobuf_queue *q,
  425. struct cx25821_buffer *buf);
  426. extern int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
  427. u32 reg, u32 mask, u32 value);
  428. extern void cx25821_sram_channel_dump(struct cx25821_dev *dev,
  429. const struct sram_channel *ch);
  430. extern void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
  431. const struct sram_channel *ch);
  432. extern struct cx25821_dev *cx25821_dev_get(struct pci_dev *pci);
  433. extern void cx25821_print_irqbits(char *name, char *tag, char **strings,
  434. int len, u32 bits, u32 mask);
  435. extern void cx25821_dev_unregister(struct cx25821_dev *dev);
  436. extern int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
  437. const struct sram_channel *ch,
  438. unsigned int bpl, u32 risc);
  439. extern int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev,
  440. int channel_select, int pixel_format);
  441. extern int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev,
  442. int channel_select, int pixel_format);
  443. extern int cx25821_audio_upstream_init(struct cx25821_dev *dev,
  444. int channel_select);
  445. extern void cx25821_free_mem_upstream_ch1(struct cx25821_dev *dev);
  446. extern void cx25821_free_mem_upstream_ch2(struct cx25821_dev *dev);
  447. extern void cx25821_free_mem_upstream_audio(struct cx25821_dev *dev);
  448. extern void cx25821_start_upstream_video_ch1(struct cx25821_dev *dev,
  449. struct upstream_user_struct
  450. *up_data);
  451. extern void cx25821_start_upstream_video_ch2(struct cx25821_dev *dev,
  452. struct upstream_user_struct
  453. *up_data);
  454. extern void cx25821_start_upstream_audio(struct cx25821_dev *dev,
  455. struct upstream_user_struct *up_data);
  456. extern void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev);
  457. extern void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev);
  458. extern void cx25821_stop_upstream_audio(struct cx25821_dev *dev);
  459. extern int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
  460. const struct sram_channel *ch,
  461. unsigned int bpl, u32 risc);
  462. extern void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel,
  463. u32 format);
  464. #endif