cx25821.h 15 KB

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