cx25821.h 14 KB

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