cx25821.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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_buf_type type;
  103. u32 resources;
  104. enum v4l2_priority prio;
  105. /* video capture */
  106. const struct cx25821_fmt *fmt;
  107. unsigned int width, height;
  108. int channel_id;
  109. struct videobuf_queue vidq;
  110. };
  111. enum cx25821_itype {
  112. CX25821_VMUX_COMPOSITE = 1,
  113. CX25821_VMUX_SVIDEO,
  114. CX25821_VMUX_DEBUG,
  115. };
  116. enum cx25821_src_sel_type {
  117. CX25821_SRC_SEL_EXT_656_VIDEO = 0,
  118. CX25821_SRC_SEL_PARALLEL_MPEG_VIDEO
  119. };
  120. /* buffer for one video frame */
  121. struct cx25821_buffer {
  122. /* common v4l buffer stuff -- must be first */
  123. struct videobuf_buffer vb;
  124. /* cx25821 specific */
  125. unsigned int bpl;
  126. struct btcx_riscmem risc;
  127. const struct cx25821_fmt *fmt;
  128. u32 count;
  129. };
  130. struct cx25821_input {
  131. enum cx25821_itype type;
  132. unsigned int vmux;
  133. u32 gpio0, gpio1, gpio2, gpio3;
  134. };
  135. enum port {
  136. CX25821_UNDEFINED = 0,
  137. CX25821_RAW,
  138. CX25821_264
  139. };
  140. struct cx25821_board {
  141. const char *name;
  142. enum port porta;
  143. enum port portb;
  144. enum port portc;
  145. u32 clk_freq;
  146. struct cx25821_input input[CX25821_NR_INPUT];
  147. };
  148. struct cx25821_i2c {
  149. struct cx25821_dev *dev;
  150. int nr;
  151. /* i2c i/o */
  152. struct i2c_adapter i2c_adap;
  153. struct i2c_client i2c_client;
  154. u32 i2c_rc;
  155. /* cx25821 registers used for raw addess */
  156. u32 i2c_period;
  157. u32 reg_ctrl;
  158. u32 reg_stat;
  159. u32 reg_addr;
  160. u32 reg_rdata;
  161. u32 reg_wdata;
  162. };
  163. struct cx25821_dmaqueue {
  164. struct list_head active;
  165. struct list_head queued;
  166. struct timer_list timeout;
  167. struct btcx_riscmem stopper;
  168. u32 count;
  169. };
  170. struct cx25821_data {
  171. struct cx25821_dev *dev;
  172. const struct sram_channel *channel;
  173. };
  174. struct cx25821_dev;
  175. struct cx25821_channel {
  176. unsigned id;
  177. struct cx25821_dev *dev;
  178. struct v4l2_prio_state prio;
  179. struct v4l2_ctrl_handler hdl;
  180. struct cx25821_data timeout_data;
  181. struct video_device vdev;
  182. struct cx25821_dmaqueue vidq;
  183. const struct sram_channel *sram_channels;
  184. int resources;
  185. int pixel_formats;
  186. int use_cif_resolution;
  187. int cif_width;
  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. u32 resources;
  214. unsigned int input;
  215. v4l2_std_id tvnorm;
  216. unsigned short _max_num_decoders;
  217. /* Analog Audio Upstream */
  218. int _audio_is_running;
  219. int _audiopixel_format;
  220. int _is_first_audio_frame;
  221. int _audiofile_status;
  222. int _audio_lines_count;
  223. int _audioframe_count;
  224. int _audio_upstream_channel;
  225. int _last_index_irq; /* The last interrupt index processed. */
  226. __le32 *_risc_audio_jmp_addr;
  227. __le32 *_risc_virt_start_addr;
  228. __le32 *_risc_virt_addr;
  229. dma_addr_t _risc_phys_addr;
  230. dma_addr_t _risc_phys_start_addr;
  231. unsigned int _audiorisc_size;
  232. unsigned int _audiodata_buf_size;
  233. __le32 *_audiodata_buf_virt_addr;
  234. dma_addr_t _audiodata_buf_phys_addr;
  235. char *_audiofilename;
  236. /* V4l */
  237. spinlock_t slock;
  238. /* Video Upstream */
  239. int _line_size;
  240. int _prog_cnt;
  241. int _pixel_format;
  242. int _is_first_frame;
  243. int _is_running;
  244. int _file_status;
  245. int _lines_count;
  246. int _frame_count;
  247. int _channel_upstream_select;
  248. unsigned int _risc_size;
  249. __le32 *_dma_virt_start_addr;
  250. __le32 *_dma_virt_addr;
  251. dma_addr_t _dma_phys_addr;
  252. dma_addr_t _dma_phys_start_addr;
  253. unsigned int _data_buf_size;
  254. __le32 *_data_buf_virt_addr;
  255. dma_addr_t _data_buf_phys_addr;
  256. char *_filename;
  257. char *_defaultname;
  258. int _line_size_ch2;
  259. int _prog_cnt_ch2;
  260. int _pixel_format_ch2;
  261. int _is_first_frame_ch2;
  262. int _is_running_ch2;
  263. int _file_status_ch2;
  264. int _lines_count_ch2;
  265. int _frame_count_ch2;
  266. int _channel2_upstream_select;
  267. unsigned int _risc_size_ch2;
  268. __le32 *_dma_virt_start_addr_ch2;
  269. __le32 *_dma_virt_addr_ch2;
  270. dma_addr_t _dma_phys_addr_ch2;
  271. dma_addr_t _dma_phys_start_addr_ch2;
  272. unsigned int _data_buf_size_ch2;
  273. __le32 *_data_buf_virt_addr_ch2;
  274. dma_addr_t _data_buf_phys_addr_ch2;
  275. char *_filename_ch2;
  276. char *_defaultname_ch2;
  277. u32 upstream_riscbuf_size;
  278. u32 upstream_databuf_size;
  279. u32 upstream_riscbuf_size_ch2;
  280. u32 upstream_databuf_size_ch2;
  281. u32 audio_upstream_riscbuf_size;
  282. u32 audio_upstream_databuf_size;
  283. int _isNTSC;
  284. int _frame_index;
  285. int _audioframe_index;
  286. struct workqueue_struct *_irq_queues;
  287. struct work_struct _irq_work_entry;
  288. struct workqueue_struct *_irq_queues_ch2;
  289. struct work_struct _irq_work_entry_ch2;
  290. struct workqueue_struct *_irq_audio_queues;
  291. struct work_struct _audio_work_entry;
  292. char *input_filename;
  293. char *input_filename_ch2;
  294. int _frame_index_ch2;
  295. int _isNTSC_ch2;
  296. char *vid_stdname_ch2;
  297. int pixel_format_ch2;
  298. int channel_select_ch2;
  299. int command_ch2;
  300. char *input_audiofilename;
  301. char *vid_stdname;
  302. int pixel_format;
  303. int channel_select;
  304. int command;
  305. int channel_opened;
  306. };
  307. struct upstream_user_struct {
  308. char *input_filename;
  309. char *vid_stdname;
  310. int pixel_format;
  311. int channel_select;
  312. int command;
  313. };
  314. struct downstream_user_struct {
  315. char *vid_stdname;
  316. int pixel_format;
  317. int cif_resolution_enable;
  318. int cif_width;
  319. int decoder_select;
  320. int command;
  321. int reg_address;
  322. int reg_data;
  323. };
  324. extern struct upstream_user_struct *up_data;
  325. static inline struct cx25821_dev *get_cx25821(struct v4l2_device *v4l2_dev)
  326. {
  327. return container_of(v4l2_dev, struct cx25821_dev, v4l2_dev);
  328. }
  329. #define cx25821_call_all(dev, o, f, args...) \
  330. v4l2_device_call_all(&dev->v4l2_dev, 0, o, f, ##args)
  331. extern struct cx25821_board cx25821_boards[];
  332. #define SRAM_CH00 0 /* Video A */
  333. #define SRAM_CH01 1 /* Video B */
  334. #define SRAM_CH02 2 /* Video C */
  335. #define SRAM_CH03 3 /* Video D */
  336. #define SRAM_CH04 4 /* Video E */
  337. #define SRAM_CH05 5 /* Video F */
  338. #define SRAM_CH06 6 /* Video G */
  339. #define SRAM_CH07 7 /* Video H */
  340. #define SRAM_CH08 8 /* Audio A */
  341. #define SRAM_CH09 9 /* Video Upstream I */
  342. #define SRAM_CH10 10 /* Video Upstream J */
  343. #define SRAM_CH11 11 /* Audio Upstream AUD_CHANNEL_B */
  344. #define VID_UPSTREAM_SRAM_CHANNEL_I SRAM_CH09
  345. #define VID_UPSTREAM_SRAM_CHANNEL_J SRAM_CH10
  346. #define AUDIO_UPSTREAM_SRAM_CHANNEL_B SRAM_CH11
  347. struct sram_channel {
  348. char *name;
  349. u32 i;
  350. u32 cmds_start;
  351. u32 ctrl_start;
  352. u32 cdt;
  353. u32 fifo_start;
  354. u32 fifo_size;
  355. u32 ptr1_reg;
  356. u32 ptr2_reg;
  357. u32 cnt1_reg;
  358. u32 cnt2_reg;
  359. u32 int_msk;
  360. u32 int_stat;
  361. u32 int_mstat;
  362. u32 dma_ctl;
  363. u32 gpcnt_ctl;
  364. u32 gpcnt;
  365. u32 aud_length;
  366. u32 aud_cfg;
  367. u32 fld_aud_fifo_en;
  368. u32 fld_aud_risc_en;
  369. /* For Upstream Video */
  370. u32 vid_fmt_ctl;
  371. u32 vid_active_ctl1;
  372. u32 vid_active_ctl2;
  373. u32 vid_cdt_size;
  374. u32 vip_ctl;
  375. u32 pix_frmt;
  376. u32 jumponly;
  377. u32 irq_bit;
  378. };
  379. extern const struct sram_channel cx25821_sram_channels[];
  380. #define cx_read(reg) readl(dev->lmmio + ((reg)>>2))
  381. #define cx_write(reg, value) writel((value), dev->lmmio + ((reg)>>2))
  382. #define cx_andor(reg, mask, value) \
  383. writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
  384. ((value) & (mask)), dev->lmmio+((reg)>>2))
  385. #define cx_set(reg, bit) cx_andor((reg), (bit), (bit))
  386. #define cx_clear(reg, bit) cx_andor((reg), (bit), 0)
  387. #define Set_GPIO_Bit(Bit) (1 << Bit)
  388. #define Clear_GPIO_Bit(Bit) (~(1 << Bit))
  389. #define CX25821_ERR(fmt, args...) \
  390. pr_err("(%d): " fmt, dev->board, ##args)
  391. #define CX25821_WARN(fmt, args...) \
  392. pr_warn("(%d): " fmt, dev->board, ##args)
  393. #define CX25821_INFO(fmt, args...) \
  394. pr_info("(%d): " fmt, dev->board, ##args)
  395. extern int cx25821_i2c_register(struct cx25821_i2c *bus);
  396. extern int cx25821_i2c_read(struct cx25821_i2c *bus, u16 reg_addr, int *value);
  397. extern int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value);
  398. extern int cx25821_i2c_unregister(struct cx25821_i2c *bus);
  399. extern void cx25821_gpio_init(struct cx25821_dev *dev);
  400. extern void cx25821_set_gpiopin_direction(struct cx25821_dev *dev,
  401. int pin_number, int pin_logic_value);
  402. extern int medusa_video_init(struct cx25821_dev *dev);
  403. extern int medusa_set_videostandard(struct cx25821_dev *dev);
  404. extern void medusa_set_resolution(struct cx25821_dev *dev, int width,
  405. int decoder_select);
  406. extern int medusa_set_brightness(struct cx25821_dev *dev, int brightness,
  407. int decoder);
  408. extern int medusa_set_contrast(struct cx25821_dev *dev, int contrast,
  409. int decoder);
  410. extern int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder);
  411. extern int medusa_set_saturation(struct cx25821_dev *dev, int saturation,
  412. int decoder);
  413. extern int cx25821_sram_channel_setup(struct cx25821_dev *dev,
  414. const struct sram_channel *ch, unsigned int bpl,
  415. u32 risc);
  416. extern int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
  417. struct scatterlist *sglist,
  418. unsigned int top_offset,
  419. unsigned int bottom_offset,
  420. unsigned int bpl,
  421. unsigned int padding, unsigned int lines);
  422. extern int cx25821_risc_databuffer_audio(struct pci_dev *pci,
  423. struct btcx_riscmem *risc,
  424. struct scatterlist *sglist,
  425. unsigned int bpl,
  426. unsigned int lines, unsigned int lpi);
  427. extern void cx25821_free_buffer(struct videobuf_queue *q,
  428. struct cx25821_buffer *buf);
  429. extern int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
  430. u32 reg, u32 mask, u32 value);
  431. extern void cx25821_sram_channel_dump(struct cx25821_dev *dev,
  432. const struct sram_channel *ch);
  433. extern void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
  434. const struct sram_channel *ch);
  435. extern struct cx25821_dev *cx25821_dev_get(struct pci_dev *pci);
  436. extern void cx25821_print_irqbits(char *name, char *tag, char **strings,
  437. int len, u32 bits, u32 mask);
  438. extern void cx25821_dev_unregister(struct cx25821_dev *dev);
  439. extern int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
  440. const struct sram_channel *ch,
  441. unsigned int bpl, u32 risc);
  442. extern int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev,
  443. int channel_select, int pixel_format);
  444. extern int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev,
  445. int channel_select, int pixel_format);
  446. extern int cx25821_audio_upstream_init(struct cx25821_dev *dev,
  447. int channel_select);
  448. extern void cx25821_free_mem_upstream_ch1(struct cx25821_dev *dev);
  449. extern void cx25821_free_mem_upstream_ch2(struct cx25821_dev *dev);
  450. extern void cx25821_free_mem_upstream_audio(struct cx25821_dev *dev);
  451. extern void cx25821_start_upstream_video_ch1(struct cx25821_dev *dev,
  452. struct upstream_user_struct
  453. *up_data);
  454. extern void cx25821_start_upstream_video_ch2(struct cx25821_dev *dev,
  455. struct upstream_user_struct
  456. *up_data);
  457. extern void cx25821_start_upstream_audio(struct cx25821_dev *dev,
  458. struct upstream_user_struct *up_data);
  459. extern void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev);
  460. extern void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev);
  461. extern void cx25821_stop_upstream_audio(struct cx25821_dev *dev);
  462. extern int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
  463. const struct sram_channel *ch,
  464. unsigned int bpl, u32 risc);
  465. extern void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel,
  466. u32 format);
  467. #endif