]>
Commit | Line | Data |
---|---|---|
faa4fd2a BC |
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 | ||
20 | #ifndef __SOLO6010_H | |
21 | #define __SOLO6010_H | |
22 | ||
23 | #include <linux/version.h> | |
24 | #include <linux/pci.h> | |
25 | #include <linux/i2c.h> | |
26 | #include <linux/semaphore.h> | |
27 | #include <linux/mutex.h> | |
28 | #include <linux/list.h> | |
29 | #include <linux/wait.h> | |
f62de9be | 30 | #include <linux/delay.h> |
faa4fd2a BC |
31 | #include <asm/io.h> |
32 | #include <asm/atomic.h> | |
33 | ||
34 | #include <linux/videodev2.h> | |
35 | #include <media/v4l2-dev.h> | |
36 | #include <media/videobuf-core.h> | |
37 | ||
38 | #include "solo6010-registers.h" | |
39 | ||
40 | #ifndef PCI_VENDOR_ID_SOFTLOGIC | |
41 | #define PCI_VENDOR_ID_SOFTLOGIC 0x9413 | |
42 | #define PCI_DEVICE_ID_SOLO6010 0x6010 | |
43 | #endif | |
44 | ||
45 | #ifndef PCI_VENDOR_ID_BLUECHERRY | |
46 | #define PCI_VENDOR_ID_BLUECHERRY 0x1BB3 | |
47 | /* Neugent Softlogic 6010 based cards */ | |
48 | #define PCI_DEVICE_ID_NEUSOLO_4 0x4304 | |
49 | #define PCI_DEVICE_ID_NEUSOLO_9 0x4309 | |
50 | #define PCI_DEVICE_ID_NEUSOLO_16 0x4310 | |
f62de9be BC |
51 | /* Bluecherry Softlogic 6010 based cards */ |
52 | #define PCI_DEVICE_ID_BC_SOLO_4 0x4E04 | |
53 | #define PCI_DEVICE_ID_BC_SOLO_9 0x4E09 | |
54 | #define PCI_DEVICE_ID_BC_SOLO_16 0x4E10 | |
55 | /* Bluecherry Softlogic 6110 based cards */ | |
56 | #define PCI_DEVICE_ID_BC_6110_4 0x5304 | |
57 | #define PCI_DEVICE_ID_BC_6110_8 0x5308 | |
58 | #define PCI_DEVICE_ID_BC_6110_16 0x5310 | |
faa4fd2a BC |
59 | #endif /* Bluecherry */ |
60 | ||
61 | #define SOLO6010_NAME "solo6010" | |
62 | ||
63 | #define SOLO_MAX_CHANNELS 16 | |
64 | ||
65 | /* Make sure these two match */ | |
66 | #define SOLO6010_VERSION "2.0.0" | |
67 | #define SOLO6010_VER_MAJOR 2 | |
68 | #define SOLO6010_VER_MINOR 0 | |
69 | #define SOLO6010_VER_SUB 0 | |
70 | #define SOLO6010_VER_NUM \ | |
71 | KERNEL_VERSION(SOLO6010_VER_MAJOR, SOLO6010_VER_MINOR, SOLO6010_VER_SUB) | |
72 | ||
73 | /* | |
74 | * The SOLO6010 actually has 8 i2c channels, but we only use 2. | |
75 | * 0 - Techwell chip(s) | |
76 | * 1 - SAA7128 | |
77 | */ | |
78 | #define SOLO_I2C_ADAPTERS 2 | |
79 | #define SOLO_I2C_TW 0 | |
80 | #define SOLO_I2C_SAA 1 | |
81 | ||
82 | /* DMA Engine setup */ | |
83 | #define SOLO_NR_P2M 4 | |
84 | #define SOLO_NR_P2M_DESC 256 | |
faa4fd2a BC |
85 | /* MPEG and JPEG share the same interrupt and locks so they must be together |
86 | * in the same dma channel. */ | |
87 | #define SOLO_P2M_DMA_ID_MP4E 0 | |
88 | #define SOLO_P2M_DMA_ID_JPEG 0 | |
89 | #define SOLO_P2M_DMA_ID_MP4D 1 | |
90 | #define SOLO_P2M_DMA_ID_G723D 1 | |
91 | #define SOLO_P2M_DMA_ID_DISP 2 | |
92 | #define SOLO_P2M_DMA_ID_OSG 2 | |
93 | #define SOLO_P2M_DMA_ID_G723E 3 | |
94 | #define SOLO_P2M_DMA_ID_VIN 3 | |
95 | ||
96 | /* Encoder standard modes */ | |
97 | #define SOLO_ENC_MODE_CIF 2 | |
98 | #define SOLO_ENC_MODE_HD1 1 | |
99 | #define SOLO_ENC_MODE_D1 9 | |
100 | ||
101 | #define SOLO_DEFAULT_GOP 30 | |
102 | #define SOLO_DEFAULT_QP 3 | |
103 | ||
104 | /* There is 8MB memory available for solo to buffer MPEG4 frames. | |
105 | * This gives us 512 * 16kbyte queues. */ | |
106 | #define SOLO_NR_RING_BUFS 512 | |
107 | ||
108 | #define SOLO_CLOCK_MHZ 108 | |
109 | ||
110 | #ifndef V4L2_BUF_FLAG_MOTION_ON | |
111 | #define V4L2_BUF_FLAG_MOTION_ON 0x0400 | |
112 | #define V4L2_BUF_FLAG_MOTION_DETECTED 0x0800 | |
113 | #endif | |
114 | #ifndef V4L2_CID_MOTION_ENABLE | |
115 | #define PRIVATE_CIDS | |
116 | #define V4L2_CID_MOTION_ENABLE (V4L2_CID_PRIVATE_BASE+0) | |
117 | #define V4L2_CID_MOTION_THRESHOLD (V4L2_CID_PRIVATE_BASE+1) | |
118 | #define V4L2_CID_MOTION_TRACE (V4L2_CID_PRIVATE_BASE+2) | |
119 | #endif | |
120 | ||
121 | enum SOLO_I2C_STATE { | |
122 | IIC_STATE_IDLE, | |
123 | IIC_STATE_START, | |
124 | IIC_STATE_READ, | |
125 | IIC_STATE_WRITE, | |
126 | IIC_STATE_STOP | |
127 | }; | |
128 | ||
f62de9be BC |
129 | struct p2m_desc { |
130 | u32 ctrl; | |
131 | u32 ext; | |
132 | u32 ta; | |
133 | u32 fa; | |
134 | }; | |
135 | ||
faa4fd2a | 136 | struct solo_p2m_dev { |
f62de9be | 137 | struct mutex mutex; |
faa4fd2a BC |
138 | struct completion completion; |
139 | int error; | |
faa4fd2a BC |
140 | }; |
141 | ||
142 | #define OSD_TEXT_MAX 30 | |
143 | ||
144 | enum solo_enc_types { | |
145 | SOLO_ENC_TYPE_STD, | |
146 | SOLO_ENC_TYPE_EXT, | |
147 | }; | |
148 | ||
149 | struct solo_enc_dev { | |
150 | struct solo6010_dev *solo_dev; | |
151 | /* V4L2 Items */ | |
152 | struct video_device *vfd; | |
153 | /* General accounting */ | |
154 | wait_queue_head_t thread_wait; | |
155 | spinlock_t lock; | |
156 | atomic_t readers; | |
157 | u8 ch; | |
158 | u8 mode, gop, qp, interlaced, interval; | |
159 | u8 reset_gop; | |
160 | u8 bw_weight; | |
161 | u8 motion_detected; | |
162 | u16 motion_thresh; | |
163 | u16 width; | |
164 | u16 height; | |
165 | char osd_text[OSD_TEXT_MAX + 1]; | |
166 | }; | |
167 | ||
168 | struct solo_enc_buf { | |
169 | u8 vop; | |
170 | u8 ch; | |
171 | enum solo_enc_types type; | |
172 | u32 off; | |
173 | u32 size; | |
174 | u32 jpeg_off; | |
175 | u32 jpeg_size; | |
176 | struct timeval ts; | |
177 | }; | |
178 | ||
179 | /* The SOLO6010 PCI Device */ | |
180 | struct solo6010_dev { | |
181 | /* General stuff */ | |
182 | struct pci_dev *pdev; | |
183 | u8 __iomem *reg_base; | |
184 | int nr_chans; | |
185 | int nr_ext; | |
186 | u32 irq_mask; | |
187 | u32 motion_mask; | |
188 | spinlock_t reg_io_lock; | |
189 | ||
190 | /* tw28xx accounting */ | |
ee6351f5 | 191 | u8 tw2865, tw2864, tw2815; |
faa4fd2a BC |
192 | u8 tw28_cnt; |
193 | ||
194 | /* i2c related items */ | |
195 | struct i2c_adapter i2c_adap[SOLO_I2C_ADAPTERS]; | |
196 | enum SOLO_I2C_STATE i2c_state; | |
f62de9be | 197 | struct mutex i2c_mutex; |
faa4fd2a BC |
198 | int i2c_id; |
199 | wait_queue_head_t i2c_wait; | |
200 | struct i2c_msg *i2c_msg; | |
201 | unsigned int i2c_msg_num; | |
202 | unsigned int i2c_msg_ptr; | |
203 | ||
204 | /* P2M DMA Engine */ | |
205 | struct solo_p2m_dev p2m_dev[SOLO_NR_P2M]; | |
206 | ||
207 | /* V4L2 Display items */ | |
208 | struct video_device *vfd; | |
209 | unsigned int erasing; | |
210 | unsigned int frame_blank; | |
211 | u8 cur_disp_ch; | |
212 | wait_queue_head_t disp_thread_wait; | |
213 | ||
214 | /* V4L2 Encoder items */ | |
215 | struct solo_enc_dev *v4l2_enc[SOLO_MAX_CHANNELS]; | |
216 | u16 enc_bw_remain; | |
217 | /* IDX into hw mp4 encoder */ | |
218 | u8 enc_idx; | |
219 | /* Our software ring of enc buf references */ | |
220 | u16 enc_wr_idx; | |
221 | struct solo_enc_buf enc_buf[SOLO_NR_RING_BUFS]; | |
222 | ||
223 | /* Current video settings */ | |
224 | u32 video_type; | |
225 | u16 video_hsize, video_vsize; | |
226 | u16 vout_hstart, vout_vstart; | |
227 | u16 vin_hstart, vin_vstart; | |
228 | u8 fps; | |
229 | ||
230 | /* Audio components */ | |
231 | struct snd_card *snd_card; | |
232 | struct snd_pcm *snd_pcm; | |
233 | atomic_t snd_users; | |
234 | int g723_hw_idx; | |
235 | }; | |
236 | ||
237 | static inline u32 solo_reg_read(struct solo6010_dev *solo_dev, int reg) | |
238 | { | |
239 | unsigned long flags; | |
240 | u32 ret; | |
241 | u16 val; | |
242 | ||
243 | spin_lock_irqsave(&solo_dev->reg_io_lock, flags); | |
244 | ||
245 | ret = readl(solo_dev->reg_base + reg); | |
246 | rmb(); | |
247 | pci_read_config_word(solo_dev->pdev, PCI_STATUS, &val); | |
248 | rmb(); | |
249 | ||
250 | spin_unlock_irqrestore(&solo_dev->reg_io_lock, flags); | |
251 | ||
252 | return ret; | |
253 | } | |
254 | ||
255 | static inline void solo_reg_write(struct solo6010_dev *solo_dev, int reg, | |
256 | u32 data) | |
257 | { | |
258 | unsigned long flags; | |
259 | u16 val; | |
260 | ||
261 | spin_lock_irqsave(&solo_dev->reg_io_lock, flags); | |
262 | ||
263 | writel(data, solo_dev->reg_base + reg); | |
264 | wmb(); | |
265 | pci_read_config_word(solo_dev->pdev, PCI_STATUS, &val); | |
266 | rmb(); | |
267 | ||
268 | spin_unlock_irqrestore(&solo_dev->reg_io_lock, flags); | |
269 | } | |
270 | ||
271 | void solo6010_irq_on(struct solo6010_dev *solo_dev, u32 mask); | |
272 | void solo6010_irq_off(struct solo6010_dev *solo_dev, u32 mask); | |
273 | ||
274 | /* Init/exit routeines for subsystems */ | |
275 | int solo_disp_init(struct solo6010_dev *solo_dev); | |
276 | void solo_disp_exit(struct solo6010_dev *solo_dev); | |
277 | ||
278 | int solo_gpio_init(struct solo6010_dev *solo_dev); | |
279 | void solo_gpio_exit(struct solo6010_dev *solo_dev); | |
280 | ||
281 | int solo_i2c_init(struct solo6010_dev *solo_dev); | |
282 | void solo_i2c_exit(struct solo6010_dev *solo_dev); | |
283 | ||
284 | int solo_p2m_init(struct solo6010_dev *solo_dev); | |
285 | void solo_p2m_exit(struct solo6010_dev *solo_dev); | |
286 | ||
287 | int solo_v4l2_init(struct solo6010_dev *solo_dev); | |
288 | void solo_v4l2_exit(struct solo6010_dev *solo_dev); | |
289 | ||
290 | int solo_enc_init(struct solo6010_dev *solo_dev); | |
291 | void solo_enc_exit(struct solo6010_dev *solo_dev); | |
292 | ||
293 | int solo_enc_v4l2_init(struct solo6010_dev *solo_dev); | |
294 | void solo_enc_v4l2_exit(struct solo6010_dev *solo_dev); | |
295 | ||
296 | int solo_g723_init(struct solo6010_dev *solo_dev); | |
297 | void solo_g723_exit(struct solo6010_dev *solo_dev); | |
298 | ||
299 | /* ISR's */ | |
300 | int solo_i2c_isr(struct solo6010_dev *solo_dev); | |
301 | void solo_p2m_isr(struct solo6010_dev *solo_dev, int id); | |
302 | void solo_p2m_error_isr(struct solo6010_dev *solo_dev, u32 status); | |
303 | void solo_enc_v4l2_isr(struct solo6010_dev *solo_dev); | |
304 | void solo_g723_isr(struct solo6010_dev *solo_dev); | |
305 | void solo_motion_isr(struct solo6010_dev *solo_dev); | |
306 | void solo_video_in_isr(struct solo6010_dev *solo_dev); | |
307 | ||
308 | /* i2c read/write */ | |
309 | u8 solo_i2c_readbyte(struct solo6010_dev *solo_dev, int id, u8 addr, u8 off); | |
310 | void solo_i2c_writebyte(struct solo6010_dev *solo_dev, int id, u8 addr, u8 off, | |
311 | u8 data); | |
312 | ||
313 | /* P2M DMA */ | |
314 | int solo_p2m_dma_t(struct solo6010_dev *solo_dev, u8 id, int wr, | |
315 | dma_addr_t dma_addr, u32 ext_addr, u32 size); | |
316 | int solo_p2m_dma(struct solo6010_dev *solo_dev, u8 id, int wr, | |
317 | void *sys_addr, u32 ext_addr, u32 size); | |
f62de9be BC |
318 | int solo_p2m_dma_sg(struct solo6010_dev *solo_dev, u8 id, |
319 | struct p2m_desc *pdesc, int wr, | |
320 | struct scatterlist *sglist, u32 sg_off, | |
321 | u32 ext_addr, u32 size); | |
322 | void solo_p2m_push_desc(struct p2m_desc *desc, int wr, dma_addr_t dma_addr, | |
323 | u32 ext_addr, u32 size, int repeat, u32 ext_size); | |
324 | int solo_p2m_dma_desc(struct solo6010_dev *solo_dev, u8 id, | |
325 | struct p2m_desc *desc, int desc_count); | |
faa4fd2a BC |
326 | |
327 | /* Set the threshold for motion detection */ | |
328 | void solo_set_motion_threshold(struct solo6010_dev *solo_dev, u8 ch, u16 val); | |
329 | #define SOLO_DEF_MOT_THRESH 0x0300 | |
330 | ||
331 | /* Write text on OSD */ | |
332 | int solo_osd_print(struct solo_enc_dev *solo_enc); | |
333 | ||
334 | #endif /* __SOLO6010_H */ |