2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net>
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.
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.
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.
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/delay.h>
30 #include <linux/wait.h>
32 #include <asm/atomic.h>
34 #include <linux/videodev2.h>
35 #include <media/v4l2-dev.h>
36 #include <media/videobuf-core.h>
38 #include "solo6010-registers.h"
40 #ifndef PCI_VENDOR_ID_SOFTLOGIC
41 #define PCI_VENDOR_ID_SOFTLOGIC 0x9413
42 #define PCI_DEVICE_ID_SOLO6010 0x6010
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
51 /* Commell Softlogic 6010 based cards */
52 #define PCI_DEVICE_ID_COMMSOLO_4 0x4E04
53 #define PCI_DEVICE_ID_COMMSOLO_9 0x4E09
54 #define PCI_DEVICE_ID_COMMSOLO_16 0x4E10
55 #endif /* Bluecherry */
57 #define SOLO6010_NAME "solo6010"
59 #define SOLO_MAX_CHANNELS 16
61 /* Make sure these two match */
62 #define SOLO6010_VERSION "2.0.0"
63 #define SOLO6010_VER_MAJOR 2
64 #define SOLO6010_VER_MINOR 0
65 #define SOLO6010_VER_SUB 0
66 #define SOLO6010_VER_NUM \
67 KERNEL_VERSION(SOLO6010_VER_MAJOR, SOLO6010_VER_MINOR, SOLO6010_VER_SUB)
70 * The SOLO6010 actually has 8 i2c channels, but we only use 2.
71 * 0 - Techwell chip(s)
74 #define SOLO_I2C_ADAPTERS 2
76 #define SOLO_I2C_SAA 1
78 /* DMA Engine setup */
80 #define SOLO_NR_P2M_DESC 256
81 #define SOLO_P2M_DESC_SIZE (SOLO_NR_P2M_DESC * 16)
82 /* MPEG and JPEG share the same interrupt and locks so they must be together
83 * in the same dma channel. */
84 #define SOLO_P2M_DMA_ID_MP4E 0
85 #define SOLO_P2M_DMA_ID_JPEG 0
86 #define SOLO_P2M_DMA_ID_MP4D 1
87 #define SOLO_P2M_DMA_ID_G723D 1
88 #define SOLO_P2M_DMA_ID_DISP 2
89 #define SOLO_P2M_DMA_ID_OSG 2
90 #define SOLO_P2M_DMA_ID_G723E 3
91 #define SOLO_P2M_DMA_ID_VIN 3
93 /* Encoder standard modes */
94 #define SOLO_ENC_MODE_CIF 2
95 #define SOLO_ENC_MODE_HD1 1
96 #define SOLO_ENC_MODE_D1 9
98 #define SOLO_DEFAULT_GOP 30
99 #define SOLO_DEFAULT_QP 3
101 /* There is 8MB memory available for solo to buffer MPEG4 frames.
102 * This gives us 512 * 16kbyte queues. */
103 #define SOLO_NR_RING_BUFS 512
105 #define SOLO_CLOCK_MHZ 108
107 #ifndef V4L2_BUF_FLAG_MOTION_ON
108 #define V4L2_BUF_FLAG_MOTION_ON 0x0400
109 #define V4L2_BUF_FLAG_MOTION_DETECTED 0x0800
111 #ifndef V4L2_CID_MOTION_ENABLE
113 #define V4L2_CID_MOTION_ENABLE (V4L2_CID_PRIVATE_BASE+0)
114 #define V4L2_CID_MOTION_THRESHOLD (V4L2_CID_PRIVATE_BASE+1)
115 #define V4L2_CID_MOTION_TRACE (V4L2_CID_PRIVATE_BASE+2)
118 enum SOLO_I2C_STATE
{
126 struct solo_p2m_dev
{
127 struct semaphore sem
;
128 struct completion completion
;
130 u8 desc
[SOLO_P2M_DESC_SIZE
];
133 #define OSD_TEXT_MAX 30
135 enum solo_enc_types
{
140 struct solo_enc_dev
{
141 struct solo6010_dev
*solo_dev
;
143 struct video_device
*vfd
;
144 /* General accounting */
145 wait_queue_head_t thread_wait
;
149 u8 mode
, gop
, qp
, interlaced
, interval
;
156 char osd_text
[OSD_TEXT_MAX
+ 1];
159 struct solo_enc_buf
{
162 enum solo_enc_types type
;
170 /* The SOLO6010 PCI Device */
171 struct solo6010_dev
{
173 struct pci_dev
*pdev
;
174 u8 __iomem
*reg_base
;
179 spinlock_t reg_io_lock
;
181 /* tw28xx accounting */
182 u8 tw2865
, tw2864
, tw2815
;
185 /* i2c related items */
186 struct i2c_adapter i2c_adap
[SOLO_I2C_ADAPTERS
];
187 enum SOLO_I2C_STATE i2c_state
;
188 struct semaphore i2c_sem
;
190 wait_queue_head_t i2c_wait
;
191 struct i2c_msg
*i2c_msg
;
192 unsigned int i2c_msg_num
;
193 unsigned int i2c_msg_ptr
;
196 struct solo_p2m_dev p2m_dev
[SOLO_NR_P2M
];
198 /* V4L2 Display items */
199 struct video_device
*vfd
;
200 unsigned int erasing
;
201 unsigned int frame_blank
;
203 wait_queue_head_t disp_thread_wait
;
205 /* V4L2 Encoder items */
206 struct solo_enc_dev
*v4l2_enc
[SOLO_MAX_CHANNELS
];
208 /* IDX into hw mp4 encoder */
210 /* Our software ring of enc buf references */
212 struct solo_enc_buf enc_buf
[SOLO_NR_RING_BUFS
];
214 /* Current video settings */
216 u16 video_hsize
, video_vsize
;
217 u16 vout_hstart
, vout_vstart
;
218 u16 vin_hstart
, vin_vstart
;
221 /* Audio components */
222 struct snd_card
*snd_card
;
223 struct snd_pcm
*snd_pcm
;
228 static inline u32
solo_reg_read(struct solo6010_dev
*solo_dev
, int reg
)
234 spin_lock_irqsave(&solo_dev
->reg_io_lock
, flags
);
236 ret
= readl(solo_dev
->reg_base
+ reg
);
238 pci_read_config_word(solo_dev
->pdev
, PCI_STATUS
, &val
);
241 spin_unlock_irqrestore(&solo_dev
->reg_io_lock
, flags
);
246 static inline void solo_reg_write(struct solo6010_dev
*solo_dev
, int reg
,
252 spin_lock_irqsave(&solo_dev
->reg_io_lock
, flags
);
254 writel(data
, solo_dev
->reg_base
+ reg
);
256 pci_read_config_word(solo_dev
->pdev
, PCI_STATUS
, &val
);
259 spin_unlock_irqrestore(&solo_dev
->reg_io_lock
, flags
);
262 void solo6010_irq_on(struct solo6010_dev
*solo_dev
, u32 mask
);
263 void solo6010_irq_off(struct solo6010_dev
*solo_dev
, u32 mask
);
265 /* Init/exit routeines for subsystems */
266 int solo_disp_init(struct solo6010_dev
*solo_dev
);
267 void solo_disp_exit(struct solo6010_dev
*solo_dev
);
269 int solo_gpio_init(struct solo6010_dev
*solo_dev
);
270 void solo_gpio_exit(struct solo6010_dev
*solo_dev
);
272 int solo_i2c_init(struct solo6010_dev
*solo_dev
);
273 void solo_i2c_exit(struct solo6010_dev
*solo_dev
);
275 int solo_p2m_init(struct solo6010_dev
*solo_dev
);
276 void solo_p2m_exit(struct solo6010_dev
*solo_dev
);
278 int solo_v4l2_init(struct solo6010_dev
*solo_dev
);
279 void solo_v4l2_exit(struct solo6010_dev
*solo_dev
);
281 int solo_enc_init(struct solo6010_dev
*solo_dev
);
282 void solo_enc_exit(struct solo6010_dev
*solo_dev
);
284 int solo_enc_v4l2_init(struct solo6010_dev
*solo_dev
);
285 void solo_enc_v4l2_exit(struct solo6010_dev
*solo_dev
);
287 int solo_g723_init(struct solo6010_dev
*solo_dev
);
288 void solo_g723_exit(struct solo6010_dev
*solo_dev
);
291 int solo_i2c_isr(struct solo6010_dev
*solo_dev
);
292 void solo_p2m_isr(struct solo6010_dev
*solo_dev
, int id
);
293 void solo_p2m_error_isr(struct solo6010_dev
*solo_dev
, u32 status
);
294 void solo_enc_v4l2_isr(struct solo6010_dev
*solo_dev
);
295 void solo_g723_isr(struct solo6010_dev
*solo_dev
);
296 void solo_motion_isr(struct solo6010_dev
*solo_dev
);
297 void solo_video_in_isr(struct solo6010_dev
*solo_dev
);
300 u8
solo_i2c_readbyte(struct solo6010_dev
*solo_dev
, int id
, u8 addr
, u8 off
);
301 void solo_i2c_writebyte(struct solo6010_dev
*solo_dev
, int id
, u8 addr
, u8 off
,
305 int solo_p2m_dma_t(struct solo6010_dev
*solo_dev
, u8 id
, int wr
,
306 dma_addr_t dma_addr
, u32 ext_addr
, u32 size
);
307 int solo_p2m_dma(struct solo6010_dev
*solo_dev
, u8 id
, int wr
,
308 void *sys_addr
, u32 ext_addr
, u32 size
);
310 /* Set the threshold for motion detection */
311 void solo_set_motion_threshold(struct solo6010_dev
*solo_dev
, u8 ch
, u16 val
);
312 #define SOLO_DEF_MOT_THRESH 0x0300
314 /* Write text on OSD */
315 int solo_osd_print(struct solo_enc_dev
*solo_enc
);
317 #endif /* __SOLO6010_H */