cx25821.h 15 KB

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