cx25821.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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 cx25821_dev {
  199. struct list_head devlist;
  200. atomic_t refcount;
  201. struct v4l2_device v4l2_dev;
  202. /* pci stuff */
  203. struct pci_dev *pci;
  204. unsigned char pci_rev, pci_lat;
  205. int pci_bus, pci_slot;
  206. u32 base_io_addr;
  207. u32 __iomem *lmmio;
  208. u8 __iomem *bmmio;
  209. int pci_irqmask;
  210. int hwrevision;
  211. u32 clk_freq;
  212. /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
  213. struct cx25821_i2c i2c_bus[3];
  214. int nr;
  215. struct mutex lock;
  216. struct cx25821_channel channels[MAX_VID_CHANNEL_NUM];
  217. /* board details */
  218. unsigned int board;
  219. char name[32];
  220. /* Analog video */
  221. u32 resources;
  222. unsigned int input;
  223. v4l2_std_id tvnorm;
  224. unsigned short _max_num_decoders;
  225. /* Analog Audio Upstream */
  226. int _audio_is_running;
  227. int _audiopixel_format;
  228. int _is_first_audio_frame;
  229. int _audiofile_status;
  230. int _audio_lines_count;
  231. int _audioframe_count;
  232. int _audio_upstream_channel;
  233. int _last_index_irq; /* The last interrupt index processed. */
  234. __le32 *_risc_audio_jmp_addr;
  235. __le32 *_risc_virt_start_addr;
  236. __le32 *_risc_virt_addr;
  237. dma_addr_t _risc_phys_addr;
  238. dma_addr_t _risc_phys_start_addr;
  239. unsigned int _audiorisc_size;
  240. unsigned int _audiodata_buf_size;
  241. __le32 *_audiodata_buf_virt_addr;
  242. dma_addr_t _audiodata_buf_phys_addr;
  243. char *_audiofilename;
  244. /* V4l */
  245. spinlock_t slock;
  246. /* Video Upstream */
  247. int _line_size;
  248. int _prog_cnt;
  249. int _pixel_format;
  250. int _is_first_frame;
  251. int _is_running;
  252. int _file_status;
  253. int _lines_count;
  254. int _frame_count;
  255. int _channel_upstream_select;
  256. unsigned int _risc_size;
  257. __le32 *_dma_virt_start_addr;
  258. __le32 *_dma_virt_addr;
  259. dma_addr_t _dma_phys_addr;
  260. dma_addr_t _dma_phys_start_addr;
  261. unsigned int _data_buf_size;
  262. __le32 *_data_buf_virt_addr;
  263. dma_addr_t _data_buf_phys_addr;
  264. char *_filename;
  265. char *_defaultname;
  266. int _line_size_ch2;
  267. int _prog_cnt_ch2;
  268. int _pixel_format_ch2;
  269. int _is_first_frame_ch2;
  270. int _is_running_ch2;
  271. int _file_status_ch2;
  272. int _lines_count_ch2;
  273. int _frame_count_ch2;
  274. int _channel2_upstream_select;
  275. unsigned int _risc_size_ch2;
  276. __le32 *_dma_virt_start_addr_ch2;
  277. __le32 *_dma_virt_addr_ch2;
  278. dma_addr_t _dma_phys_addr_ch2;
  279. dma_addr_t _dma_phys_start_addr_ch2;
  280. unsigned int _data_buf_size_ch2;
  281. __le32 *_data_buf_virt_addr_ch2;
  282. dma_addr_t _data_buf_phys_addr_ch2;
  283. char *_filename_ch2;
  284. char *_defaultname_ch2;
  285. u32 upstream_riscbuf_size;
  286. u32 upstream_databuf_size;
  287. u32 upstream_riscbuf_size_ch2;
  288. u32 upstream_databuf_size_ch2;
  289. u32 audio_upstream_riscbuf_size;
  290. u32 audio_upstream_databuf_size;
  291. int _isNTSC;
  292. int _frame_index;
  293. int _audioframe_index;
  294. struct workqueue_struct *_irq_queues;
  295. struct work_struct _irq_work_entry;
  296. struct workqueue_struct *_irq_queues_ch2;
  297. struct work_struct _irq_work_entry_ch2;
  298. struct workqueue_struct *_irq_audio_queues;
  299. struct work_struct _audio_work_entry;
  300. char *input_filename;
  301. char *input_filename_ch2;
  302. int _frame_index_ch2;
  303. int _isNTSC_ch2;
  304. char *vid_stdname_ch2;
  305. int pixel_format_ch2;
  306. int channel_select_ch2;
  307. int command_ch2;
  308. char *input_audiofilename;
  309. char *vid_stdname;
  310. int pixel_format;
  311. int channel_select;
  312. int command;
  313. int channel_opened;
  314. };
  315. struct upstream_user_struct {
  316. char *input_filename;
  317. char *vid_stdname;
  318. int pixel_format;
  319. int channel_select;
  320. int command;
  321. };
  322. struct downstream_user_struct {
  323. char *vid_stdname;
  324. int pixel_format;
  325. int cif_resolution_enable;
  326. int cif_width;
  327. int decoder_select;
  328. int command;
  329. int reg_address;
  330. int reg_data;
  331. };
  332. extern struct upstream_user_struct *up_data;
  333. static inline struct cx25821_dev *get_cx25821(struct v4l2_device *v4l2_dev)
  334. {
  335. return container_of(v4l2_dev, struct cx25821_dev, v4l2_dev);
  336. }
  337. #define cx25821_call_all(dev, o, f, args...) \
  338. v4l2_device_call_all(&dev->v4l2_dev, 0, o, f, ##args)
  339. extern struct list_head cx25821_devlist;
  340. extern struct mutex cx25821_devlist_mutex;
  341. extern struct cx25821_board cx25821_boards[];
  342. extern struct cx25821_subid cx25821_subids[];
  343. #define SRAM_CH00 0 /* Video A */
  344. #define SRAM_CH01 1 /* Video B */
  345. #define SRAM_CH02 2 /* Video C */
  346. #define SRAM_CH03 3 /* Video D */
  347. #define SRAM_CH04 4 /* Video E */
  348. #define SRAM_CH05 5 /* Video F */
  349. #define SRAM_CH06 6 /* Video G */
  350. #define SRAM_CH07 7 /* Video H */
  351. #define SRAM_CH08 8 /* Audio A */
  352. #define SRAM_CH09 9 /* Video Upstream I */
  353. #define SRAM_CH10 10 /* Video Upstream J */
  354. #define SRAM_CH11 11 /* Audio Upstream AUD_CHANNEL_B */
  355. #define VID_UPSTREAM_SRAM_CHANNEL_I SRAM_CH09
  356. #define VID_UPSTREAM_SRAM_CHANNEL_J SRAM_CH10
  357. #define AUDIO_UPSTREAM_SRAM_CHANNEL_B SRAM_CH11
  358. struct sram_channel {
  359. char *name;
  360. u32 i;
  361. u32 cmds_start;
  362. u32 ctrl_start;
  363. u32 cdt;
  364. u32 fifo_start;
  365. u32 fifo_size;
  366. u32 ptr1_reg;
  367. u32 ptr2_reg;
  368. u32 cnt1_reg;
  369. u32 cnt2_reg;
  370. u32 int_msk;
  371. u32 int_stat;
  372. u32 int_mstat;
  373. u32 dma_ctl;
  374. u32 gpcnt_ctl;
  375. u32 gpcnt;
  376. u32 aud_length;
  377. u32 aud_cfg;
  378. u32 fld_aud_fifo_en;
  379. u32 fld_aud_risc_en;
  380. /* For Upstream Video */
  381. u32 vid_fmt_ctl;
  382. u32 vid_active_ctl1;
  383. u32 vid_active_ctl2;
  384. u32 vid_cdt_size;
  385. u32 vip_ctl;
  386. u32 pix_frmt;
  387. u32 jumponly;
  388. u32 irq_bit;
  389. };
  390. extern const struct sram_channel cx25821_sram_channels[];
  391. #define STATUS_SUCCESS 0
  392. #define STATUS_UNSUCCESSFUL -1
  393. #define cx_read(reg) readl(dev->lmmio + ((reg)>>2))
  394. #define cx_write(reg, value) writel((value), dev->lmmio + ((reg)>>2))
  395. #define cx_andor(reg, mask, value) \
  396. writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
  397. ((value) & (mask)), dev->lmmio+((reg)>>2))
  398. #define cx_set(reg, bit) cx_andor((reg), (bit), (bit))
  399. #define cx_clear(reg, bit) cx_andor((reg), (bit), 0)
  400. #define Set_GPIO_Bit(Bit) (1 << Bit)
  401. #define Clear_GPIO_Bit(Bit) (~(1 << Bit))
  402. #define CX25821_ERR(fmt, args...) \
  403. pr_err("(%d): " fmt, dev->board, ##args)
  404. #define CX25821_WARN(fmt, args...) \
  405. pr_warn("(%d): " fmt, dev->board, ##args)
  406. #define CX25821_INFO(fmt, args...) \
  407. pr_info("(%d): " fmt, dev->board, ##args)
  408. extern int cx25821_i2c_register(struct cx25821_i2c *bus);
  409. extern void cx25821_card_setup(struct cx25821_dev *dev);
  410. extern int cx25821_ir_init(struct cx25821_dev *dev);
  411. extern int cx25821_i2c_read(struct cx25821_i2c *bus, u16 reg_addr, int *value);
  412. extern int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value);
  413. extern int cx25821_i2c_unregister(struct cx25821_i2c *bus);
  414. extern void cx25821_gpio_init(struct cx25821_dev *dev);
  415. extern void cx25821_set_gpiopin_direction(struct cx25821_dev *dev,
  416. int pin_number, int pin_logic_value);
  417. extern int medusa_video_init(struct cx25821_dev *dev);
  418. extern int medusa_set_videostandard(struct cx25821_dev *dev);
  419. extern void medusa_set_resolution(struct cx25821_dev *dev, int width,
  420. int decoder_select);
  421. extern int medusa_set_brightness(struct cx25821_dev *dev, int brightness,
  422. int decoder);
  423. extern int medusa_set_contrast(struct cx25821_dev *dev, int contrast,
  424. int decoder);
  425. extern int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder);
  426. extern int medusa_set_saturation(struct cx25821_dev *dev, int saturation,
  427. int decoder);
  428. extern int cx25821_sram_channel_setup(struct cx25821_dev *dev,
  429. const struct sram_channel *ch, unsigned int bpl,
  430. u32 risc);
  431. extern int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
  432. struct scatterlist *sglist,
  433. unsigned int top_offset,
  434. unsigned int bottom_offset,
  435. unsigned int bpl,
  436. unsigned int padding, unsigned int lines);
  437. extern int cx25821_risc_databuffer_audio(struct pci_dev *pci,
  438. struct btcx_riscmem *risc,
  439. struct scatterlist *sglist,
  440. unsigned int bpl,
  441. unsigned int lines, unsigned int lpi);
  442. extern void cx25821_free_buffer(struct videobuf_queue *q,
  443. struct cx25821_buffer *buf);
  444. extern int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
  445. u32 reg, u32 mask, u32 value);
  446. extern void cx25821_sram_channel_dump(struct cx25821_dev *dev,
  447. const struct sram_channel *ch);
  448. extern void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
  449. const struct sram_channel *ch);
  450. extern struct cx25821_dev *cx25821_dev_get(struct pci_dev *pci);
  451. extern void cx25821_print_irqbits(char *name, char *tag, char **strings,
  452. int len, u32 bits, u32 mask);
  453. extern void cx25821_dev_unregister(struct cx25821_dev *dev);
  454. extern int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
  455. const struct sram_channel *ch,
  456. unsigned int bpl, u32 risc);
  457. extern int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev,
  458. int channel_select, int pixel_format);
  459. extern int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev,
  460. int channel_select, int pixel_format);
  461. extern int cx25821_audio_upstream_init(struct cx25821_dev *dev,
  462. int channel_select);
  463. extern void cx25821_free_mem_upstream_ch1(struct cx25821_dev *dev);
  464. extern void cx25821_free_mem_upstream_ch2(struct cx25821_dev *dev);
  465. extern void cx25821_free_mem_upstream_audio(struct cx25821_dev *dev);
  466. extern void cx25821_start_upstream_video_ch1(struct cx25821_dev *dev,
  467. struct upstream_user_struct
  468. *up_data);
  469. extern void cx25821_start_upstream_video_ch2(struct cx25821_dev *dev,
  470. struct upstream_user_struct
  471. *up_data);
  472. extern void cx25821_start_upstream_audio(struct cx25821_dev *dev,
  473. struct upstream_user_struct *up_data);
  474. extern void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev);
  475. extern void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev);
  476. extern void cx25821_stop_upstream_audio(struct cx25821_dev *dev);
  477. extern int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
  478. const struct sram_channel *ch,
  479. unsigned int bpl, u32 risc);
  480. extern void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel,
  481. u32 format);
  482. extern struct video_device *cx25821_vdev_init(struct cx25821_dev *dev,
  483. struct pci_dev *pci,
  484. const struct video_device *template,
  485. char *type);
  486. #endif