cx25821.h 15 KB

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