solo6x10.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com
  3. * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #ifndef __SOLO6X10_H
  20. #define __SOLO6X10_H
  21. #include <linux/version.h>
  22. #include <linux/pci.h>
  23. #include <linux/i2c.h>
  24. #include <linux/semaphore.h>
  25. #include <linux/mutex.h>
  26. #include <linux/list.h>
  27. #include <linux/wait.h>
  28. #include <linux/delay.h>
  29. #include <asm/io.h>
  30. #include <asm/atomic.h>
  31. #include <linux/videodev2.h>
  32. #include <media/v4l2-dev.h>
  33. #include <media/videobuf-core.h>
  34. #include "registers.h"
  35. #ifndef PCI_VENDOR_ID_SOFTLOGIC
  36. #define PCI_VENDOR_ID_SOFTLOGIC 0x9413
  37. #define PCI_DEVICE_ID_SOLO6010 0x6010
  38. #define PCI_DEVICE_ID_SOLO6110 0x6110
  39. #endif
  40. #ifndef PCI_VENDOR_ID_BLUECHERRY
  41. #define PCI_VENDOR_ID_BLUECHERRY 0x1BB3
  42. /* Neugent Softlogic 6010 based cards */
  43. #define PCI_DEVICE_ID_NEUSOLO_4 0x4304
  44. #define PCI_DEVICE_ID_NEUSOLO_9 0x4309
  45. #define PCI_DEVICE_ID_NEUSOLO_16 0x4310
  46. /* Bluecherry Softlogic 6010 based cards */
  47. #define PCI_DEVICE_ID_BC_SOLO_4 0x4E04
  48. #define PCI_DEVICE_ID_BC_SOLO_9 0x4E09
  49. #define PCI_DEVICE_ID_BC_SOLO_16 0x4E10
  50. /* Bluecherry Softlogic 6110 based cards */
  51. #define PCI_DEVICE_ID_BC_6110_4 0x5304
  52. #define PCI_DEVICE_ID_BC_6110_8 0x5308
  53. #define PCI_DEVICE_ID_BC_6110_16 0x5310
  54. #endif /* Bluecherry */
  55. #define SOLO6X10_NAME "solo6x10"
  56. #define SOLO_MAX_CHANNELS 16
  57. /* Make sure these two match */
  58. #define SOLO6X10_VERSION "2.1.0"
  59. #define SOLO6X10_VER_MAJOR 2
  60. #define SOLO6X10_VER_MINOR 0
  61. #define SOLO6X10_VER_SUB 0
  62. #define SOLO6X10_VER_NUM \
  63. KERNEL_VERSION(SOLO6X10_VER_MAJOR, SOLO6X10_VER_MINOR, SOLO6X10_VER_SUB)
  64. #define FLAGS_6110 1
  65. /*
  66. * The SOLO6x10 actually has 8 i2c channels, but we only use 2.
  67. * 0 - Techwell chip(s)
  68. * 1 - SAA7128
  69. */
  70. #define SOLO_I2C_ADAPTERS 2
  71. #define SOLO_I2C_TW 0
  72. #define SOLO_I2C_SAA 1
  73. /* DMA Engine setup */
  74. #define SOLO_NR_P2M 4
  75. #define SOLO_NR_P2M_DESC 256
  76. /* MPEG and JPEG share the same interrupt and locks so they must be together
  77. * in the same dma channel. */
  78. #define SOLO_P2M_DMA_ID_MP4E 0
  79. #define SOLO_P2M_DMA_ID_JPEG 0
  80. #define SOLO_P2M_DMA_ID_MP4D 1
  81. #define SOLO_P2M_DMA_ID_G723D 1
  82. #define SOLO_P2M_DMA_ID_DISP 2
  83. #define SOLO_P2M_DMA_ID_OSG 2
  84. #define SOLO_P2M_DMA_ID_G723E 3
  85. #define SOLO_P2M_DMA_ID_VIN 3
  86. /* Encoder standard modes */
  87. #define SOLO_ENC_MODE_CIF 2
  88. #define SOLO_ENC_MODE_HD1 1
  89. #define SOLO_ENC_MODE_D1 9
  90. #define SOLO_DEFAULT_GOP 30
  91. #define SOLO_DEFAULT_QP 3
  92. /* There is 8MB memory available for solo to buffer MPEG4 frames.
  93. * This gives us 512 * 16kbyte queues. */
  94. #define SOLO_NR_RING_BUFS 512
  95. #define SOLO_CLOCK_MHZ 108
  96. #ifndef V4L2_BUF_FLAG_MOTION_ON
  97. #define V4L2_BUF_FLAG_MOTION_ON 0x0400
  98. #define V4L2_BUF_FLAG_MOTION_DETECTED 0x0800
  99. #endif
  100. #ifndef V4L2_CID_MOTION_ENABLE
  101. #define PRIVATE_CIDS
  102. #define V4L2_CID_MOTION_ENABLE (V4L2_CID_PRIVATE_BASE+0)
  103. #define V4L2_CID_MOTION_THRESHOLD (V4L2_CID_PRIVATE_BASE+1)
  104. #define V4L2_CID_MOTION_TRACE (V4L2_CID_PRIVATE_BASE+2)
  105. #endif
  106. enum SOLO_I2C_STATE {
  107. IIC_STATE_IDLE,
  108. IIC_STATE_START,
  109. IIC_STATE_READ,
  110. IIC_STATE_WRITE,
  111. IIC_STATE_STOP
  112. };
  113. struct p2m_desc {
  114. u32 ctrl;
  115. u32 ext;
  116. u32 ta;
  117. u32 fa;
  118. };
  119. struct solo_p2m_dev {
  120. struct mutex mutex;
  121. struct completion completion;
  122. int error;
  123. };
  124. #define OSD_TEXT_MAX 30
  125. enum solo_enc_types {
  126. SOLO_ENC_TYPE_STD,
  127. SOLO_ENC_TYPE_EXT,
  128. };
  129. struct solo_enc_dev {
  130. struct solo_dev *solo_dev;
  131. /* V4L2 Items */
  132. struct video_device *vfd;
  133. /* General accounting */
  134. wait_queue_head_t thread_wait;
  135. spinlock_t lock;
  136. atomic_t readers;
  137. u8 ch;
  138. u8 mode, gop, qp, interlaced, interval;
  139. u8 reset_gop;
  140. u8 bw_weight;
  141. u8 motion_detected;
  142. u16 motion_thresh;
  143. u16 width;
  144. u16 height;
  145. char osd_text[OSD_TEXT_MAX + 1];
  146. };
  147. struct solo_enc_buf {
  148. u8 vop;
  149. u8 ch;
  150. enum solo_enc_types type;
  151. u32 off;
  152. u32 size;
  153. u32 jpeg_off;
  154. u32 jpeg_size;
  155. struct timeval ts;
  156. };
  157. /* The SOLO6x10 PCI Device */
  158. struct solo_dev {
  159. /* General stuff */
  160. struct pci_dev *pdev;
  161. u8 __iomem *reg_base;
  162. int nr_chans;
  163. int nr_ext;
  164. u32 flags;
  165. u32 irq_mask;
  166. u32 motion_mask;
  167. spinlock_t reg_io_lock;
  168. /* tw28xx accounting */
  169. u8 tw2865, tw2864, tw2815;
  170. u8 tw28_cnt;
  171. /* i2c related items */
  172. struct i2c_adapter i2c_adap[SOLO_I2C_ADAPTERS];
  173. enum SOLO_I2C_STATE i2c_state;
  174. struct mutex i2c_mutex;
  175. int i2c_id;
  176. wait_queue_head_t i2c_wait;
  177. struct i2c_msg *i2c_msg;
  178. unsigned int i2c_msg_num;
  179. unsigned int i2c_msg_ptr;
  180. /* P2M DMA Engine */
  181. struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
  182. /* V4L2 Display items */
  183. struct video_device *vfd;
  184. unsigned int erasing;
  185. unsigned int frame_blank;
  186. u8 cur_disp_ch;
  187. wait_queue_head_t disp_thread_wait;
  188. /* V4L2 Encoder items */
  189. struct solo_enc_dev *v4l2_enc[SOLO_MAX_CHANNELS];
  190. u16 enc_bw_remain;
  191. /* IDX into hw mp4 encoder */
  192. u8 enc_idx;
  193. /* Our software ring of enc buf references */
  194. u16 enc_wr_idx;
  195. struct solo_enc_buf enc_buf[SOLO_NR_RING_BUFS];
  196. /* Current video settings */
  197. u32 video_type;
  198. u16 video_hsize, video_vsize;
  199. u16 vout_hstart, vout_vstart;
  200. u16 vin_hstart, vin_vstart;
  201. u8 fps;
  202. /* Audio components */
  203. struct snd_card *snd_card;
  204. struct snd_pcm *snd_pcm;
  205. atomic_t snd_users;
  206. int g723_hw_idx;
  207. };
  208. static inline u32 solo_reg_read(struct solo_dev *solo_dev, int reg)
  209. {
  210. unsigned long flags;
  211. u32 ret;
  212. u16 val;
  213. spin_lock_irqsave(&solo_dev->reg_io_lock, flags);
  214. ret = readl(solo_dev->reg_base + reg);
  215. rmb();
  216. pci_read_config_word(solo_dev->pdev, PCI_STATUS, &val);
  217. rmb();
  218. spin_unlock_irqrestore(&solo_dev->reg_io_lock, flags);
  219. return ret;
  220. }
  221. static inline void solo_reg_write(struct solo_dev *solo_dev, int reg, u32 data)
  222. {
  223. unsigned long flags;
  224. u16 val;
  225. spin_lock_irqsave(&solo_dev->reg_io_lock, flags);
  226. writel(data, solo_dev->reg_base + reg);
  227. wmb();
  228. pci_read_config_word(solo_dev->pdev, PCI_STATUS, &val);
  229. rmb();
  230. spin_unlock_irqrestore(&solo_dev->reg_io_lock, flags);
  231. }
  232. void solo_irq_on(struct solo_dev *solo_dev, u32 mask);
  233. void solo_irq_off(struct solo_dev *solo_dev, u32 mask);
  234. /* Init/exit routeines for subsystems */
  235. int solo_disp_init(struct solo_dev *solo_dev);
  236. void solo_disp_exit(struct solo_dev *solo_dev);
  237. int solo_gpio_init(struct solo_dev *solo_dev);
  238. void solo_gpio_exit(struct solo_dev *solo_dev);
  239. int solo_i2c_init(struct solo_dev *solo_dev);
  240. void solo_i2c_exit(struct solo_dev *solo_dev);
  241. int solo_p2m_init(struct solo_dev *solo_dev);
  242. void solo_p2m_exit(struct solo_dev *solo_dev);
  243. int solo_v4l2_init(struct solo_dev *solo_dev);
  244. void solo_v4l2_exit(struct solo_dev *solo_dev);
  245. int solo_enc_init(struct solo_dev *solo_dev);
  246. void solo_enc_exit(struct solo_dev *solo_dev);
  247. int solo_enc_v4l2_init(struct solo_dev *solo_dev);
  248. void solo_enc_v4l2_exit(struct solo_dev *solo_dev);
  249. int solo_g723_init(struct solo_dev *solo_dev);
  250. void solo_g723_exit(struct solo_dev *solo_dev);
  251. /* ISR's */
  252. int solo_i2c_isr(struct solo_dev *solo_dev);
  253. void solo_p2m_isr(struct solo_dev *solo_dev, int id);
  254. void solo_p2m_error_isr(struct solo_dev *solo_dev, u32 status);
  255. void solo_enc_v4l2_isr(struct solo_dev *solo_dev);
  256. void solo_g723_isr(struct solo_dev *solo_dev);
  257. void solo_motion_isr(struct solo_dev *solo_dev);
  258. void solo_video_in_isr(struct solo_dev *solo_dev);
  259. /* i2c read/write */
  260. u8 solo_i2c_readbyte(struct solo_dev *solo_dev, int id, u8 addr, u8 off);
  261. void solo_i2c_writebyte(struct solo_dev *solo_dev, int id, u8 addr, u8 off,
  262. u8 data);
  263. /* P2M DMA */
  264. int solo_p2m_dma_t(struct solo_dev *solo_dev, u8 id, int wr,
  265. dma_addr_t dma_addr, u32 ext_addr, u32 size);
  266. int solo_p2m_dma(struct solo_dev *solo_dev, u8 id, int wr,
  267. void *sys_addr, u32 ext_addr, u32 size);
  268. int solo_p2m_dma_sg(struct solo_dev *solo_dev, u8 id,
  269. struct p2m_desc *pdesc, int wr,
  270. struct scatterlist *sglist, u32 sg_off,
  271. u32 ext_addr, u32 size);
  272. void solo_p2m_push_desc(struct p2m_desc *desc, int wr, dma_addr_t dma_addr,
  273. u32 ext_addr, u32 size, int repeat, u32 ext_size);
  274. int solo_p2m_dma_desc(struct solo_dev *solo_dev, u8 id,
  275. struct p2m_desc *desc, int desc_count);
  276. /* Set the threshold for motion detection */
  277. void solo_set_motion_threshold(struct solo_dev *solo_dev, u8 ch, u16 val);
  278. #define SOLO_DEF_MOT_THRESH 0x0300
  279. /* Write text on OSD */
  280. int solo_osd_print(struct solo_enc_dev *solo_enc);
  281. #endif /* __SOLO6X10_H */