39 #include <linux/module.h>
41 #include <linux/kernel.h>
43 #include <linux/slab.h>
44 #include <linux/videodev2.h>
53 #define S2255_VERSION "1.22.1"
54 #define FIRMWARE_FILE_NAME "f2255usb.bin"
57 #define S2255_DEF_JPEG_QUAL 50
61 #define S2255_VR_OUT 1
63 #define S2255_VR_FW 0x30
65 #define S2255_CONFIG_EP 2
67 #define S2255_DSP_BOOTTIME 800
69 #define S2255_LOAD_TIMEOUT (5000 + S2255_DSP_BOOTTIME)
70 #define S2255_DEF_BUFS 16
71 #define S2255_SETMODE_TIMEOUT 500
72 #define S2255_VIDSTATUS_TIMEOUT 350
73 #define S2255_MARKER_FRAME cpu_to_le32(0x2255DA4AL)
74 #define S2255_MARKER_RESPONSE cpu_to_le32(0x2255ACACL)
75 #define S2255_RESPONSE_SETMODE cpu_to_le32(0x01)
76 #define S2255_RESPONSE_FW cpu_to_le32(0x10)
77 #define S2255_RESPONSE_STATUS cpu_to_le32(0x20)
78 #define S2255_USB_XFER_SIZE (16 * 1024)
79 #define MAX_CHANNELS 4
82 #define SYS_FRAMES_MAXSIZE (720*288*2*2 + 4096)
83 #define DEF_USB_BLOCK S2255_USB_XFER_SIZE
84 #define LINE_SZ_4CIFS_NTSC 640
85 #define LINE_SZ_2CIFS_NTSC 640
86 #define LINE_SZ_1CIFS_NTSC 320
87 #define LINE_SZ_4CIFS_PAL 704
88 #define LINE_SZ_2CIFS_PAL 704
89 #define LINE_SZ_1CIFS_PAL 352
90 #define NUM_LINES_4CIFS_NTSC 240
91 #define NUM_LINES_2CIFS_NTSC 240
92 #define NUM_LINES_1CIFS_NTSC 240
93 #define NUM_LINES_4CIFS_PAL 288
94 #define NUM_LINES_2CIFS_PAL 288
95 #define NUM_LINES_1CIFS_PAL 288
96 #define LINE_SZ_DEF 640
97 #define NUM_LINES_DEF 240
101 #define FORMAT_NTSC 1
104 #define SCALE_4CIFS 1
105 #define SCALE_2CIFS 2
106 #define SCALE_1CIFS 3
108 #define SCALE_4CIFSI 4
110 #define COLOR_YUVPL 1
111 #define COLOR_YUVPK 2
115 #define MASK_COLOR 0x000000ff
116 #define MASK_JPG_QUALITY 0x0000ff00
117 #define MASK_INPUT_TYPE 0x000f0000
127 #define DEF_SCALE SCALE_4CIFS
128 #define DEF_COLOR COLOR_YUVPL
129 #define DEF_FDEC FDEC_1
131 #define DEF_CONTRAST 0x5c
132 #define DEF_SATURATION 0x80
136 #define IN_DATA_TOKEN cpu_to_le32(0x2255c0de)
137 #define CMD_2255 0xc2255000
138 #define CMD_SET_MODE cpu_to_le32((CMD_2255 | 0x10))
139 #define CMD_START cpu_to_le32((CMD_2255 | 0x20))
140 #define CMD_STOP cpu_to_le32((CMD_2255 | 0x30))
141 #define CMD_STATUS cpu_to_le32((CMD_2255 | 0x40))
158 #define S2255_READ_IDLE 0
159 #define S2255_READ_FRAME 1
175 #define DEF_MODEI_NTSC_CONT {FORMAT_NTSC, DEF_SCALE, DEF_COLOR, \
176 DEF_FDEC, DEF_BRIGHT, DEF_CONTRAST, DEF_SATURATION, \
177 DEF_HUE, 0, DEF_USB_BLOCK, 0}
185 #define S2255_FW_NOTLOADED 0
186 #define S2255_FW_LOADED_DSPWAIT 1
187 #define S2255_FW_SUCCESS 2
188 #define S2255_FW_FAILED 3
189 #define S2255_FW_DISCONNECTING 4
190 #define S2255_FW_MARKER cpu_to_le32(0x22552f2f)
192 #define S2255_READ_IDLE 0
193 #define S2255_READ_FRAME 1
303 #define S2255_CUR_USB_FWVER ((3 << 8) | 12)
305 #define S2255_CUR_DSP_FWVER 10104
307 #define S2255_MIN_DSP_STATUS 5
308 #define S2255_MIN_DSP_COLORFILTER 8
309 #define S2255_NORMS (V4L2_STD_PAL | V4L2_STD_NTSC)
337 #define S2255_V4L2_YC_ON 1
338 #define S2255_V4L2_YC_OFF 0
339 #define V4L2_CID_PRIVATE_COLORFILTER (V4L2_CID_PRIVATE_BASE + 0)
342 #define PREFIX_SIZE 512
345 static unsigned long G_chnmap[
MAX_CHANNELS] = {3, 2, 1, 0};
348 static int *s2255_debug = &
debug;
358 static void s2255_fwload_start(
struct s2255_dev *
dev,
int reset);
362 s32 buf_len,
int bOut);
365 #define S2255_DRIVER_NAME "s2255"
366 #define s2255_dev_err(dev, fmt, arg...) \
367 dev_err(dev, S2255_DRIVER_NAME " - " fmt, ##arg)
369 #define dprintk(level, fmt, arg...) \
371 if (*s2255_debug >= (level)) { \
372 printk(KERN_DEBUG S2255_DRIVER_NAME \
377 static struct usb_driver s2255_driver;
383 static int video_nr = -1;
386 static int jpeg_enable = 1;
398 #define USB_SENSORAY_VID 0x1943
406 #define BUFFER_TIMEOUT msecs_to_jiffies(400)
412 .name =
"4:2:2, planar, YUV422P",
417 .name =
"4:2:2, packed, YUYV",
422 .name =
"4:2:2, packed, UYVY",
469 static void planar422p_to_yuv_packed(
const unsigned char *
in,
479 pY = (
unsigned char *)in;
480 pCr = (
unsigned char *)in + height * width;
481 pCb = (
unsigned char *)in + height * width + (height * width / 2);
482 for (i = 0; i < size * 2; i += 4) {
493 s2255_vendor_req(dev, 0x40, 0x0000, 0x0001,
NULL, 0, 1);
495 s2255_vendor_req(dev, 0x50, 0x0000, 0x0000,
NULL, 0, 1);
497 s2255_vendor_req(dev, 0x10, 0x0000, 0x0000,
NULL, 0, 1);
503 static void s2255_timer(
unsigned long user_data)
506 dprintk(100,
"%s\n", __func__);
523 static void s2255_fwchunk_complete(
struct urb *
urb)
525 struct s2255_fw *data = urb->context;
526 struct usb_device *
udev = urb->dev;
528 dprintk(100,
"%s: udev %p urb %p", __func__, udev, urb);
530 dev_err(&udev->dev,
"URB failed with status %d\n", urb->status);
543 #define CHUNK_SIZE 512
550 data->
fw_size % CHUNK_SIZE : CHUNK_SIZE;
552 if (len < CHUNK_SIZE)
555 dprintk(100,
"completed len %d, loaded %d \n", len,
561 usb_fill_bulk_urb(data->
fw_urb, udev, usb_sndbulkpipe(udev, 2),
563 s2255_fwchunk_complete, data);
565 dev_err(&udev->dev,
"failed submit URB\n");
574 dprintk(100,
"%s: firmware upload complete\n", __func__);
585 unsigned long flags = 0;
588 if (list_empty(&dma_q->
active)) {
589 dprintk(1,
"No active queue to serve\n");
597 s2255_fillbuff(channel, buf, jpgsize);
599 dprintk(2,
"%s: [buf/i] [%p/%d]\n", __func__, buf, buf->
vb.i);
601 spin_unlock_irqrestore(&dev->
slock, flags);
609 if (-1 == formats[i].fourcc)
614 if (formats[i].fourcc == fourcc)
635 unsigned long last_frame;
640 if (last_frame != -1) {
642 (
const char *)channel->
buffer.frame[last_frame].lpvbits;
643 switch (buf->
fmt->fourcc) {
646 planar422p_to_yuv_packed((
const unsigned char *)tmpbuf,
652 memcpy(vbuf, tmpbuf, buf->
vb.width * buf->
vb.height);
656 buf->
vb.size = jpgsize;
661 buf->
vb.width * buf->
vb.height * 2);
672 dprintk(2,
"s2255fill at : Buffer 0x%08lx size= %d\n",
673 (
unsigned long)vbuf, pos);
692 *size = channel->
width * channel->
height * (channel->
fmt->depth >> 3);
697 if (*size * *count > vid_limit * 1024 * 1024)
698 *count = (
vid_limit * 1024 * 1024) / *size;
720 dprintk(4,
"%s, field=%d\n", __func__, field);
728 dprintk(4,
"invalid buffer prepare\n");
731 buf->
vb.size = w * h * (channel->
fmt->depth >> 3);
732 if (0 != buf->
vb.baddr && buf->
vb.bsize < buf->
vb.size) {
733 dprintk(4,
"invalid buffer prepare\n");
776 .buf_setup = buffer_setup,
777 .buf_prepare = buffer_prepare,
778 .buf_queue = buffer_queue,
779 .buf_release = buffer_release,
783 static int res_get(
struct s2255_fh *fh)
792 dprintk(1,
"s2255: res: get\n");
796 static int res_locked(
struct s2255_fh *fh)
801 static int res_check(
struct s2255_fh *fh)
807 static void res_free(
struct s2255_fh *fh)
815 static int vidioc_querymenu(
struct file *
file,
void *
priv,
818 static const char *colorfilter[] = {
825 const char **menu_items = colorfilter;
826 for (i = 0; i < qmenu->
index && menu_items[
i]; i++)
828 if (menu_items[i] ==
NULL || menu_items[i][0] ==
'\0')
831 sizeof(qmenu->
name));
837 static int vidioc_querycap(
struct file *file,
void *priv,
849 static int vidioc_enum_fmt_vid_cap(
struct file *file,
void *priv,
865 static int vidioc_g_fmt_vid_cap(
struct file *file,
void *priv,
874 f->
fmt.
pix.pixelformat = channel->
fmt->fourcc;
875 f->
fmt.
pix.bytesperline = f->
fmt.
pix.width * (channel->
fmt->depth >> 3);
880 static int vidioc_try_fmt_vid_cap(
struct file *file,
void *priv,
901 dprintk(50,
"%s NTSC: %d suggested width: %d, height: %d\n",
902 __func__, is_ntsc, f->
fmt.
pix.width, f->
fmt.
pix.height);
912 dprintk(1,
"unsupported field setting\n");
921 dprintk(1,
"unsupported field setting\n");
943 dprintk(1,
"unsupported field setting\n");
952 dprintk(1,
"unsupported field setting\n");
973 dprintk(50,
"%s: set width %d height %d field %d\n", __func__,
978 static int vidioc_s_fmt_vid_cap(
struct file *file,
void *priv,
988 ret = vidioc_try_fmt_vid_cap(file, fh, f);
1006 if (res_locked(fh)) {
1007 dprintk(1,
"%s: channel busy\n", __func__);
1019 if (channel->
cap_parm.capturemode &
1031 switch (channel->
fmt->fourcc) {
1040 mode.color |= (channel->
jc.quality << 8);
1055 else if (
mode.scale != channel->
mode.scale)
1057 else if (
mode.format != channel->
mode.format)
1060 (
void) s2255_set_mode(channel, &
mode);
1067 static int vidioc_reqbufs(
struct file *file,
void *priv,
1076 static int vidioc_querybuf(
struct file *file,
void *priv,
struct v4l2_buffer *
p)
1084 static int vidioc_qbuf(
struct file *file,
void *priv,
struct v4l2_buffer *
p)
1092 static int vidioc_dqbuf(
struct file *file,
void *priv,
struct v4l2_buffer *
p)
1101 static int s2255_write_config(
struct usb_device *udev,
unsigned char *pbuf,
1109 retval =
usb_bulk_msg(udev, pipe, pbuf, size, &done, 500);
1120 unsigned int mask_mult;
1126 switch (mode->
scale) {
1144 switch (mode->
scale) {
1162 outImageSize = linesPerFrame * pixelsPerLine;
1173 if (usbInSize & ~mask_mult)
1174 usbInSize = (usbInSize & mask_mult) + (DEF_USB_BLOCK);
1181 dev_info(dev,
"------------------------------------------------\n");
1185 dev_info(dev,
"------------------------------------------------\n");
1201 unsigned long chn_rev;
1202 struct s2255_dev *dev = to_s2255_dev(channel->
vdev.v4l2_dev);
1203 chn_rev = G_chnmap[channel->
idx];
1204 dprintk(3,
"%s channel: %d\n", __func__, channel->
idx);
1210 mode->
color |= (channel->
jc.quality << 8);
1217 if (buffer ==
NULL) {
1227 res = s2255_write_config(dev->
udev, (
unsigned char *)buffer, 512);
1229 s2255_print_cfg(dev, mode);
1242 channel->
mode.restart = 0;
1243 dprintk(1,
"%s chn %d, result: %d\n", __func__, channel->
idx, res);
1252 struct s2255_dev *dev = to_s2255_dev(channel->
vdev.v4l2_dev);
1253 chn_rev = G_chnmap[channel->
idx];
1254 dprintk(4,
"%s chan %d\n", __func__, channel->
idx);
1256 if (buffer ==
NULL) {
1266 res = s2255_write_config(dev->
udev, (
unsigned char *)buffer, 512);
1276 dprintk(4,
"%s, vid status %d\n", __func__, *pstatus);
1280 static int vidioc_streamon(
struct file *file,
void *priv,
enum v4l2_buf_type i)
1292 if (i != fh->
type) {
1307 channel->
buffer.frame[
j].cur_size = 0;
1311 s2255_start_acquire(channel);
1319 static int vidioc_streamoff(
struct file *file,
void *priv,
enum v4l2_buf_type i)
1327 if (i != fh->
type) {
1331 s2255_stop_acquire(fh->
channel);
1337 static int vidioc_s_std(
struct file *file,
void *priv,
v4l2_std_id *i)
1349 if (res_locked(fh)) {
1350 dprintk(1,
"can't change standard after started\n");
1356 dprintk(4,
"%s NTSC\n", __func__);
1364 dprintk(4,
"%s PAL\n", __func__);
1374 s2255_set_mode(fh->
channel, &mode);
1387 static int vidioc_enum_input(
struct file *file,
void *priv,
1394 if (inp->
index != 0)
1401 rc = s2255_cmd_status(fh->
channel, &status);
1402 dprintk(4,
"s2255_cmd_status rc: %d status %x\n", rc, status);
1404 inp->
status = (status & 0x01) ? 0
1420 static int vidioc_g_input(
struct file *file,
void *priv,
unsigned int *i)
1425 static int vidioc_s_input(
struct file *file,
void *priv,
unsigned int i)
1433 static int vidioc_queryctrl(
struct file *file,
void *priv,
1455 if ((dev->
pid == 0x2257) && (channel->
idx > 1))
1468 dprintk(4,
"%s, id %d\n", __func__, qc->
id);
1472 static int vidioc_g_ctrl(
struct file *file,
void *priv,
1494 if ((dev->
pid == 0x2257) && (channel->
idx > 1))
1501 dprintk(4,
"%s, id %d val %d\n", __func__, ctrl->
id, ctrl->
value);
1505 static int vidioc_s_ctrl(
struct file *file,
void *priv,
1510 struct s2255_dev *dev = to_s2255_dev(channel->
vdev.v4l2_dev);
1512 mode = channel->
mode;
1517 mode.bright = ctrl->
value;
1520 mode.contrast = ctrl->
value;
1523 mode.hue = ctrl->
value;
1526 mode.saturation = ctrl->
value;
1531 if ((dev->
pid == 0x2257) && (channel->
idx > 1))
1534 mode.color |= ((ctrl->
value ? 0 : 1) << 16);
1544 s2255_set_mode(fh->
channel, &mode);
1548 static int vidioc_g_jpegcomp(
struct file *file,
void *priv,
1558 static int vidioc_s_jpegcomp(
struct file *file,
void *priv,
1570 static int vidioc_g_parm(
struct file *file,
void *priv,
1574 __u32 def_num, def_dem;
1583 sp->
parm.
capture.timeperframe.denominator = def_dem;
1584 switch (channel->
mode.fdec) {
1587 sp->
parm.
capture.timeperframe.numerator = def_num;
1590 sp->
parm.
capture.timeperframe.numerator = def_num * 2;
1593 sp->
parm.
capture.timeperframe.numerator = def_num * 3;
1596 sp->
parm.
capture.timeperframe.numerator = def_num * 5;
1599 dprintk(4,
"%s capture mode, %d timeperframe %d/%d\n", __func__,
1606 static int vidioc_s_parm(
struct file *file,
void *priv,
1613 __u32 def_num, def_dem;
1616 mode = channel->
mode;
1619 != sp->
parm.
capture.capturemode && res_locked(fh))
1621 def_num = (mode.format ==
FORMAT_NTSC) ? 1001 : 1000;
1622 def_dem = (mode.format ==
FORMAT_NTSC) ? 30000 : 25000;
1623 if (def_dem != sp->
parm.
capture.timeperframe.denominator)
1624 sp->
parm.
capture.timeperframe.numerator = def_num;
1625 else if (sp->
parm.
capture.timeperframe.numerator <= def_num)
1626 sp->
parm.
capture.timeperframe.numerator = def_num;
1627 else if (sp->
parm.
capture.timeperframe.numerator <= (def_num * 2)) {
1628 sp->
parm.
capture.timeperframe.numerator = def_num * 2;
1630 }
else if (sp->
parm.
capture.timeperframe.numerator <= (def_num * 3)) {
1631 sp->
parm.
capture.timeperframe.numerator = def_num * 3;
1634 sp->
parm.
capture.timeperframe.numerator = def_num * 5;
1638 sp->
parm.
capture.timeperframe.denominator = def_dem;
1639 s2255_set_mode(channel, &mode);
1640 dprintk(4,
"%s capture mode, %d timeperframe %d/%d, fdec %d\n",
1648 static int vidioc_enum_frameintervals(
struct file *file,
void *priv,
1652 #define NUM_FRAME_ENUMS 4
1654 if (fe->
index < 0 || fe->
index >= NUM_FRAME_ENUMS)
1656 switch (fe->
width) {
1679 fe->
discrete.denominator = is_ntsc ? 30000 : 25000;
1680 fe->
discrete.numerator = (is_ntsc ? 1001 : 1000) * frm_dec[fe->
index];
1686 static int __s2255_open(
struct file *file)
1694 dprintk(1,
"s2255: open called (dev=%s)\n",
1695 video_device_node_name(vdev));
1702 "firmware load failed. retrying.\n");
1703 s2255_fwload_start(dev, 1);
1744 "please try again later\n",
1768 channel->
fmt = &formats[0];
1769 s2255_set_mode(channel, &channel->
mode);
1772 dprintk(1,
"%s: dev=%s type=%s\n", __func__,
1774 dprintk(2,
"%s: fh=0x%08lx, dev=0x%08lx, vidq=0x%08lx\n", __func__,
1775 (
unsigned long)fh, (
unsigned long)dev,
1776 (
unsigned long)&channel->
vidq);
1777 dprintk(4,
"%s: list_empty active=%d\n", __func__,
1778 list_empty(&channel->
vidq.active));
1788 static int s2255_open(
struct file *file)
1795 ret = __s2255_open(file);
1800 static unsigned int s2255_poll(
struct file *file,
1806 dprintk(100,
"%s\n", __func__);
1815 static void s2255_destroy(
struct s2255_dev *dev)
1818 s2255_board_shutdown(dev);
1830 s2255_reset_dsppower(dev);
1838 static int s2255_release(
struct file *file)
1848 if (res_check(fh)) {
1850 s2255_stop_acquire(fh->
channel);
1856 dprintk(1,
"%s (dev=%s)\n", __func__, video_device_node_name(vdev));
1861 static int s2255_mmap_v4l(
struct file *file,
struct vm_area_struct *vma)
1870 dprintk(4,
"%s, vma=0x%08lx\n", __func__, (
unsigned long)vma);
1875 dprintk(4,
"%s vma start=0x%08lx, size=%ld, ret=%d\n", __func__,
1884 .release = s2255_release,
1887 .mmap = s2255_mmap_v4l,
1917 static void s2255_video_device_release(
struct video_device *vdev)
1920 dprintk(4,
"%s, chnls: %d \n", __func__,
1929 .fops = &s2255_fops_v4l,
1930 .ioctl_ops = &s2255_ioctl_ops,
1931 .release = s2255_video_device_release,
1936 static int s2255_probe_v4l(
struct s2255_dev *dev)
1940 int cur_nr = video_nr;
1949 INIT_LIST_HEAD(&channel->
vidq.active);
1952 channel->
vdev =
template;
1955 video_set_drvdata(&channel->
vdev, channel);
1957 ret = video_register_device(&channel->
vdev,
1961 ret = video_register_device(&channel->
vdev,
1967 "failed to register video device!\n");
1972 video_device_node_name(&channel->
vdev));
2004 unsigned long copy_size;
2008 unsigned char *
pdata;
2010 dprintk(100,
"buffer to user\n");
2025 dprintk(4,
"found frame marker at offset:"
2026 " %d [%x %x]\n", jj, pdata[0],
2031 if (cc >= MAX_CHANNELS) {
2037 dev->
cc = G_chnmap[
cc];
2055 if (cc >= MAX_CHANNELS)
2058 switch (pdword[2]) {
2064 dprintk(5,
"setmode ready %d\n", cc);
2080 dprintk(5,
"got vidstatus %x chan %d\n",
2116 dprintk(1,
"s2255 frame buffer == NULL.%p %p %d %d",
2117 frm, dev, dev->
cc, idx);
2129 memcpy(pdest, psrc, copy_size);
2135 dprintk(2,
"****************[%d]Buffer[%d]full*************\n",
2140 if ((channel->
cur_frame == SYS_FRAMES) ||
2145 s2255_got_frame(channel, channel->
jpg_size);
2155 static void s2255_read_video_callback(
struct s2255_dev *dev,
2159 dprintk(50,
"callback read video \n");
2161 if (dev->
cc >= MAX_CHANNELS) {
2167 res = save_frame(dev, pipe_info);
2169 dprintk(4,
"s2255: read callback failed\n");
2171 dprintk(50,
"callback read video done\n");
2176 u16 Index,
u16 Value,
void *TransferBuffer,
2177 s32 TransferBufferLength,
int bOut)
2185 Value, Index, TransferBuffer,
2186 TransferBufferLength,
HZ * 5);
2190 Value, Index, TransferBuffer,
2191 TransferBufferLength,
HZ * 5);
2201 static int s2255_get_fx2fw(
struct s2255_dev *dev)
2205 unsigned char transBuffer[64];
2206 ret = s2255_vendor_req(dev,
S2255_VR_FW, 0, 0, transBuffer, 2,
2209 dprintk(2,
"get fw error: %x\n", ret);
2210 fw = transBuffer[0] + (transBuffer[1] << 8);
2211 dprintk(2,
"Get FW %x %x\n", transBuffer[0], transBuffer[1]);
2219 static int s2255_create_sys_buffers(
struct s2255_channel *channel)
2222 unsigned long reqsize;
2223 dprintk(1,
"create sys buffers\n");
2234 dprintk(1,
"valloc %p chan %d, idx %lu, pdata %p\n",
2235 &channel->
buffer.frame[i], channel->
idx, i,
2236 channel->
buffer.frame[i].lpvbits);
2237 channel->
buffer.frame[
i].size = reqsize;
2238 if (channel->
buffer.frame[i].lpvbits ==
NULL) {
2247 channel->
buffer.frame[
i].ulState = 0;
2248 channel->
buffer.frame[
i].cur_size = 0;
2256 static int s2255_release_sys_buffers(
struct s2255_channel *channel)
2259 dprintk(1,
"release sys buffers\n");
2261 if (channel->
buffer.frame[i].lpvbits) {
2263 channel->
buffer.frame[i].lpvbits);
2271 static int s2255_board_init(
struct s2255_dev *dev)
2277 dprintk(4,
"board init: %p", dev);
2278 memset(pipe, 0,
sizeof(*pipe));
2286 dprintk(1,
"out of memory!\n");
2290 fw_ver = s2255_get_fx2fw(dev);
2293 (fw_ver >> 8) & 0xff,
2302 channel->
mode = mode_def;
2303 if (dev->
pid == 0x2257 && j > 1)
2304 channel->
mode.color |= (1 << 16);
2308 channel->
fmt = &formats[0];
2309 channel->
mode.restart = 1;
2313 s2255_create_sys_buffers(channel);
2316 s2255_start_readpipe(dev);
2317 dprintk(1,
"%s: success\n", __func__);
2321 static int s2255_board_shutdown(
struct s2255_dev *dev)
2324 dprintk(1,
"%s: dev: %p", __func__, dev);
2327 if (dev->
channel[i].b_acquire)
2328 s2255_stop_acquire(&dev->
channel[i]);
2330 s2255_stop_readpipe(dev);
2332 s2255_release_sys_buffers(&dev->
channel[i]);
2338 static void read_pipe_completion(
struct urb *purb)
2344 pipe_info = purb->context;
2345 dprintk(100,
"%s: urb:%p, status %d\n", __func__, purb,
2347 if (pipe_info ==
NULL) {
2348 dev_err(&purb->dev->dev,
"no context!\n");
2352 dev = pipe_info->
dev;
2354 dev_err(&purb->dev->dev,
"no context!\n");
2357 status = purb->status;
2360 dprintk(2,
"%s: err shutdown\n", __func__);
2365 if (pipe_info->
state == 0) {
2366 dprintk(2,
"%s: exiting USB pipe", __func__);
2371 s2255_read_video_callback(dev, pipe_info);
2374 dprintk(1,
"%s: failed URB %d\n", __func__, status);
2383 read_pipe_completion, pipe_info);
2385 if (pipe_info->
state != 0) {
2387 dev_err(&dev->
udev->dev,
"error submitting urb\n");
2390 dprintk(2,
"%s :complete state 0\n", __func__);
2395 static int s2255_start_readpipe(
struct s2255_dev *dev)
2402 pipe_info->
state = 1;
2407 "ReadStream: Unable to alloc URB\n");
2415 read_pipe_completion, pipe_info);
2425 static int s2255_start_acquire(
struct s2255_channel *channel)
2429 unsigned long chn_rev;
2431 struct s2255_dev *dev = to_s2255_dev(channel->
vdev.v4l2_dev);
2432 chn_rev = G_chnmap[channel->
idx];
2434 if (buffer ==
NULL) {
2443 channel->
buffer.frame[
j].ulState = 0;
2444 channel->
buffer.frame[
j].cur_size = 0;
2451 res = s2255_write_config(dev->
udev, (
unsigned char *)buffer, 512);
2455 dprintk(2,
"start acquire exit[%d] %d \n", channel->
idx, res);
2460 static int s2255_stop_acquire(
struct s2255_channel *channel)
2464 unsigned long chn_rev;
2465 struct s2255_dev *dev = to_s2255_dev(channel->
vdev.v4l2_dev);
2466 chn_rev = G_chnmap[channel->
idx];
2468 if (buffer ==
NULL) {
2476 res = s2255_write_config(dev->
udev, (
unsigned char *)buffer, 512);
2481 dprintk(4,
"%s: chn %d, res %d\n", __func__, channel->
idx, res);
2485 static void s2255_stop_readpipe(
struct s2255_dev *dev)
2500 static void s2255_fwload_start(
struct s2255_dev *dev,
int reset)
2503 s2255_reset_dsppower(dev);
2507 dev->
fw_data->fw->data, CHUNK_SIZE);
2509 usb_fill_bulk_urb(dev->
fw_data->fw_urb, dev->
udev,
2510 usb_sndbulkpipe(dev->
udev, 2),
2512 CHUNK_SIZE, s2255_fwchunk_complete,
2522 struct usb_host_interface *iface_desc;
2536 dev->
pid =
id->idProduct;
2544 dev_err(&interface->dev,
"null usb device\n");
2548 dprintk(1,
"dev: %p, udev %p interface %p\n", dev,
2549 dev->
udev, interface);
2552 iface_desc = interface->cur_altsetting;
2553 dprintk(1,
"num endpoints %d\n", iface_desc->desc.bNumEndpoints);
2554 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++
i) {
2555 endpoint = &iface_desc->endpoint[
i].desc;
2556 if (!dev->
read_endpoint && usb_endpoint_is_bulk_in(endpoint)) {
2563 dev_err(&interface->dev,
"Could not find bulk-in endpoint\n");
2567 dev->
timer.function = s2255_timer;
2579 dev_err(&interface->dev,
"out of memory!\n");
2584 if (!dev->
fw_data->pfw_data) {
2585 dev_err(&interface->dev,
"out of memory!\n");
2595 fw_size = dev->
fw_data->fw->size;
2610 if (dev->
pid == 0x2257 &&
2617 retval = s2255_board_init(dev);
2619 goto errorBOARDINIT;
2621 s2255_fwload_start(dev, 0);
2623 retval = s2255_probe_v4l(dev);
2625 goto errorBOARDINIT;
2626 dev_info(&interface->dev,
"Sensoray 2255 detected\n");
2629 s2255_board_shutdown(dev);
2650 static void s2255_disconnect(
struct usb_interface *interface)
2652 struct s2255_dev *dev = to_s2255_dev(usb_get_intfdata(interface));
2669 dev->
channel[
i].vidstatus_ready = 1;
2674 dev_info(&interface->dev,
"%s\n", __func__);
2677 static struct usb_driver s2255_driver = {
2679 .probe = s2255_probe,
2680 .disconnect = s2255_disconnect,
2681 .id_table = s2255_table,