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