1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#ifndef __SOLO6X10_H
26#define __SOLO6X10_H
27
28#include <linux/pci.h>
29#include <linux/i2c.h>
30#include <linux/mutex.h>
31#include <linux/list.h>
32#include <linux/wait.h>
33#include <linux/stringify.h>
34#include <linux/io.h>
35#include <linux/atomic.h>
36#include <linux/slab.h>
37#include <linux/videodev2.h>
38
39#include <media/v4l2-dev.h>
40#include <media/v4l2-device.h>
41#include <media/v4l2-ctrls.h>
42#include <media/videobuf2-core.h>
43
44#include "solo6x10-regs.h"
45
46#ifndef PCI_VENDOR_ID_SOFTLOGIC
47#define PCI_VENDOR_ID_SOFTLOGIC 0x9413
48#define PCI_DEVICE_ID_SOLO6010 0x6010
49#define PCI_DEVICE_ID_SOLO6110 0x6110
50#endif
51
52#ifndef PCI_VENDOR_ID_BLUECHERRY
53#define PCI_VENDOR_ID_BLUECHERRY 0x1BB3
54
55#define PCI_DEVICE_ID_NEUSOLO_4 0x4304
56#define PCI_DEVICE_ID_NEUSOLO_9 0x4309
57#define PCI_DEVICE_ID_NEUSOLO_16 0x4310
58
59#define PCI_DEVICE_ID_BC_SOLO_4 0x4E04
60#define PCI_DEVICE_ID_BC_SOLO_9 0x4E09
61#define PCI_DEVICE_ID_BC_SOLO_16 0x4E10
62
63#define PCI_DEVICE_ID_BC_6110_4 0x5304
64#define PCI_DEVICE_ID_BC_6110_8 0x5308
65#define PCI_DEVICE_ID_BC_6110_16 0x5310
66#endif
67
68
69#define SOLO_DEV_6010 0
70#define SOLO_DEV_6110 1
71
72#define SOLO6X10_NAME "solo6x10"
73
74#define SOLO_MAX_CHANNELS 16
75
76#define SOLO6X10_VERSION "3.0.0"
77
78
79
80
81
82
83#define SOLO_I2C_ADAPTERS 2
84#define SOLO_I2C_TW 0
85#define SOLO_I2C_SAA 1
86
87
88#define SOLO_NR_P2M 4
89#define SOLO_NR_P2M_DESC 256
90#define SOLO_P2M_DESC_SIZE (SOLO_NR_P2M_DESC * 16)
91
92
93#define SOLO_ENC_MODE_CIF 2
94#define SOLO_ENC_MODE_HD1 1
95#define SOLO_ENC_MODE_D1 9
96
97#define SOLO_DEFAULT_GOP 30
98#define SOLO_DEFAULT_QP 3
99
100#ifndef V4L2_BUF_FLAG_MOTION_ON
101#define V4L2_BUF_FLAG_MOTION_ON 0x10000
102#define V4L2_BUF_FLAG_MOTION_DETECTED 0x20000
103#endif
104
105#define SOLO_CID_CUSTOM_BASE (V4L2_CID_USER_BASE | 0xf000)
106#define V4L2_CID_MOTION_MODE (SOLO_CID_CUSTOM_BASE+0)
107#define V4L2_CID_MOTION_THRESHOLD (SOLO_CID_CUSTOM_BASE+1)
108#define V4L2_CID_MOTION_TRACE (SOLO_CID_CUSTOM_BASE+2)
109#define V4L2_CID_OSD_TEXT (SOLO_CID_CUSTOM_BASE+3)
110
111
112
113
114
115
116
117
118
119
120
121
122
123#define SOLO_MOTION_SZ (45)
124struct solo_motion_thresholds {
125 __u16 thresholds[SOLO_MOTION_SZ][SOLO_MOTION_SZ];
126};
127
128#define SOLO_IOC_G_MOTION_THRESHOLDS _IOR('V', BASE_VIDIOC_PRIVATE+0, struct solo_motion_thresholds)
129#define SOLO_IOC_S_MOTION_THRESHOLDS _IOW('V', BASE_VIDIOC_PRIVATE+1, struct solo_motion_thresholds)
130
131enum SOLO_I2C_STATE {
132 IIC_STATE_IDLE,
133 IIC_STATE_START,
134 IIC_STATE_READ,
135 IIC_STATE_WRITE,
136 IIC_STATE_STOP
137};
138
139
140struct solo_p2m_desc {
141 u32 ctrl;
142 u32 cfg;
143 u32 dma_addr;
144 u32 ext_addr;
145};
146
147struct solo_p2m_dev {
148 struct mutex mutex;
149 struct completion completion;
150 int desc_count;
151 int desc_idx;
152 struct solo_p2m_desc *descs;
153 int error;
154};
155
156#define OSD_TEXT_MAX 44
157
158struct solo_vb2_buf {
159 struct vb2_buffer vb;
160 struct list_head list;
161};
162
163enum solo_enc_types {
164 SOLO_ENC_TYPE_STD,
165 SOLO_ENC_TYPE_EXT,
166};
167
168struct solo_enc_dev {
169 struct solo_dev *solo_dev;
170
171 struct v4l2_ctrl_handler hdl;
172 struct video_device *vfd;
173
174 struct mutex lock;
175 spinlock_t motion_lock;
176 u8 ch;
177 u8 mode, gop, qp, interlaced, interval;
178 u8 bw_weight;
179 u16 motion_thresh;
180 struct solo_motion_thresholds motion_thresholds;
181 bool motion_global;
182 bool motion_enabled;
183 u16 width;
184 u16 height;
185
186
187 char osd_text[OSD_TEXT_MAX + 1];
188 u8 osd_buf[SOLO_EOSD_EXT_SIZE_MAX]
189 __aligned(4);
190
191
192 unsigned char vop[64];
193 int vop_len;
194 unsigned char jpeg_header[1024];
195 int jpeg_len;
196
197 u32 fmt;
198 enum solo_enc_types type;
199 u32 sequence;
200 struct vb2_queue vidq;
201 struct list_head vidq_active;
202 int desc_count;
203 int desc_nelts;
204 struct solo_p2m_desc *desc_items;
205 dma_addr_t desc_dma;
206 spinlock_t av_lock;
207};
208
209
210struct solo_dev {
211
212 struct pci_dev *pdev;
213 int type;
214 unsigned int time_sync;
215 unsigned int usec_lsb;
216 unsigned int clock_mhz;
217 u8 __iomem *reg_base;
218 int nr_chans;
219 int nr_ext;
220 u32 irq_mask;
221 u32 motion_mask;
222 spinlock_t reg_io_lock;
223 struct v4l2_device v4l2_dev;
224
225
226 u8 tw2865, tw2864, tw2815;
227 u8 tw28_cnt;
228
229
230 struct i2c_adapter i2c_adap[SOLO_I2C_ADAPTERS];
231 enum SOLO_I2C_STATE i2c_state;
232 struct mutex i2c_mutex;
233 int i2c_id;
234 wait_queue_head_t i2c_wait;
235 struct i2c_msg *i2c_msg;
236 unsigned int i2c_msg_num;
237 unsigned int i2c_msg_ptr;
238
239
240 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
241 atomic_t p2m_count;
242 int p2m_jiffies;
243 unsigned int p2m_timeouts;
244
245
246 struct video_device *vfd;
247 unsigned int erasing;
248 unsigned int frame_blank;
249 u8 cur_disp_ch;
250 wait_queue_head_t disp_thread_wait;
251 struct v4l2_ctrl_handler disp_hdl;
252
253
254 struct solo_enc_dev *v4l2_enc[SOLO_MAX_CHANNELS];
255 u16 enc_bw_remain;
256
257 u8 enc_idx;
258
259
260 u32 video_type;
261 u16 video_hsize, video_vsize;
262 u16 vout_hstart, vout_vstart;
263 u16 vin_hstart, vin_vstart;
264 u8 fps;
265
266
267 spinlock_t jpeg_qp_lock;
268 u32 jpeg_qp[2];
269
270
271 struct snd_card *snd_card;
272 struct snd_pcm *snd_pcm;
273 atomic_t snd_users;
274 int g723_hw_idx;
275
276
277 struct device dev;
278 int sdram_size;
279 struct bin_attribute sdram_attr;
280 unsigned int sys_config;
281
282
283 struct task_struct *ring_thread;
284 wait_queue_head_t ring_thread_wait;
285
286
287 void *vh_buf;
288 dma_addr_t vh_dma;
289 int vh_size;
290
291
292 struct vb2_queue vidq;
293 struct vb2_alloc_ctx *alloc_ctx;
294 u32 sequence;
295 struct task_struct *kthread;
296 struct mutex lock;
297 spinlock_t slock;
298 int old_write;
299 struct list_head vidq_active;
300};
301
302static inline u32 solo_reg_read(struct solo_dev *solo_dev, int reg)
303{
304 unsigned long flags;
305 u32 ret;
306 u16 val;
307
308 spin_lock_irqsave(&solo_dev->reg_io_lock, flags);
309
310 ret = readl(solo_dev->reg_base + reg);
311 rmb();
312 pci_read_config_word(solo_dev->pdev, PCI_STATUS, &val);
313 rmb();
314
315 spin_unlock_irqrestore(&solo_dev->reg_io_lock, flags);
316
317 return ret;
318}
319
320static inline void solo_reg_write(struct solo_dev *solo_dev, int reg,
321 u32 data)
322{
323 unsigned long flags;
324 u16 val;
325
326 spin_lock_irqsave(&solo_dev->reg_io_lock, flags);
327
328 writel(data, solo_dev->reg_base + reg);
329 wmb();
330 pci_read_config_word(solo_dev->pdev, PCI_STATUS, &val);
331 rmb();
332
333 spin_unlock_irqrestore(&solo_dev->reg_io_lock, flags);
334}
335
336static inline void solo_irq_on(struct solo_dev *dev, u32 mask)
337{
338 dev->irq_mask |= mask;
339 solo_reg_write(dev, SOLO_IRQ_MASK, dev->irq_mask);
340}
341
342static inline void solo_irq_off(struct solo_dev *dev, u32 mask)
343{
344 dev->irq_mask &= ~mask;
345 solo_reg_write(dev, SOLO_IRQ_MASK, dev->irq_mask);
346}
347
348
349int solo_disp_init(struct solo_dev *solo_dev);
350void solo_disp_exit(struct solo_dev *solo_dev);
351
352int solo_gpio_init(struct solo_dev *solo_dev);
353void solo_gpio_exit(struct solo_dev *solo_dev);
354
355int solo_i2c_init(struct solo_dev *solo_dev);
356void solo_i2c_exit(struct solo_dev *solo_dev);
357
358int solo_p2m_init(struct solo_dev *solo_dev);
359void solo_p2m_exit(struct solo_dev *solo_dev);
360
361int solo_v4l2_init(struct solo_dev *solo_dev, unsigned nr);
362void solo_v4l2_exit(struct solo_dev *solo_dev);
363
364int solo_enc_init(struct solo_dev *solo_dev);
365void solo_enc_exit(struct solo_dev *solo_dev);
366
367int solo_enc_v4l2_init(struct solo_dev *solo_dev, unsigned nr);
368void solo_enc_v4l2_exit(struct solo_dev *solo_dev);
369
370int solo_g723_init(struct solo_dev *solo_dev);
371void solo_g723_exit(struct solo_dev *solo_dev);
372
373
374int solo_i2c_isr(struct solo_dev *solo_dev);
375void solo_p2m_isr(struct solo_dev *solo_dev, int id);
376void solo_p2m_error_isr(struct solo_dev *solo_dev);
377void solo_enc_v4l2_isr(struct solo_dev *solo_dev);
378void solo_g723_isr(struct solo_dev *solo_dev);
379void solo_motion_isr(struct solo_dev *solo_dev);
380void solo_video_in_isr(struct solo_dev *solo_dev);
381
382
383u8 solo_i2c_readbyte(struct solo_dev *solo_dev, int id, u8 addr, u8 off);
384void solo_i2c_writebyte(struct solo_dev *solo_dev, int id, u8 addr, u8 off,
385 u8 data);
386
387
388int solo_p2m_dma_t(struct solo_dev *solo_dev, int wr,
389 dma_addr_t dma_addr, u32 ext_addr, u32 size,
390 int repeat, u32 ext_size);
391int solo_p2m_dma(struct solo_dev *solo_dev, int wr,
392 void *sys_addr, u32 ext_addr, u32 size,
393 int repeat, u32 ext_size);
394void solo_p2m_fill_desc(struct solo_p2m_desc *desc, int wr,
395 dma_addr_t dma_addr, u32 ext_addr, u32 size,
396 int repeat, u32 ext_size);
397int solo_p2m_dma_desc(struct solo_dev *solo_dev,
398 struct solo_p2m_desc *desc, dma_addr_t desc_dma,
399 int desc_cnt);
400
401
402int solo_set_video_type(struct solo_dev *solo_dev, bool type);
403void solo_update_mode(struct solo_enc_dev *solo_enc);
404
405
406int solo_set_motion_threshold(struct solo_dev *solo_dev, u8 ch, u16 val);
407int solo_set_motion_block(struct solo_dev *solo_dev, u8 ch,
408 const struct solo_motion_thresholds *thresholds);
409#define SOLO_DEF_MOT_THRESH 0x0300
410
411
412int solo_osd_print(struct solo_enc_dev *solo_enc);
413
414
415unsigned int solo_eeprom_ewen(struct solo_dev *solo_dev, int w_en);
416unsigned short solo_eeprom_read(struct solo_dev *solo_dev, int loc);
417int solo_eeprom_write(struct solo_dev *solo_dev, int loc,
418 unsigned short data);
419
420
421void solo_s_jpeg_qp(struct solo_dev *solo_dev, unsigned int ch,
422 unsigned int qp);
423int solo_g_jpeg_qp(struct solo_dev *solo_dev, unsigned int ch);
424
425#define CHK_FLAGS(v, flags) (((v) & (flags)) == (flags))
426
427#endif
428