cx25821.h 16 KB

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