2008-09-29 17:59:36 +08:00
|
|
|
/*
|
|
|
|
* Fujifilm Finepix subdriver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Frank Zago
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MODULE_NAME "finepix"
|
|
|
|
|
|
|
|
#include "gspca.h"
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Frank Zago <frank@zago.net>");
|
|
|
|
MODULE_DESCRIPTION("Fujifilm FinePix USB V4L2 driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
/* Default timeout, in ms */
|
2009-03-26 16:06:50 +08:00
|
|
|
#define FPIX_TIMEOUT 250
|
2008-09-29 17:59:36 +08:00
|
|
|
|
|
|
|
/* Maximum transfer size to use. The windows driver reads by chunks of
|
|
|
|
* 0x2000 bytes, so do the same. Note: reading more seems to work
|
|
|
|
* too. */
|
|
|
|
#define FPIX_MAX_TRANSFER 0x2000
|
|
|
|
|
|
|
|
/* Structure to hold all of our device specific stuff */
|
|
|
|
struct usb_fpix {
|
|
|
|
struct gspca_dev gspca_dev; /* !! must be the first item */
|
|
|
|
|
2009-03-26 16:06:50 +08:00
|
|
|
struct work_struct work_struct;
|
|
|
|
struct workqueue_struct *work_thread;
|
2008-09-29 17:59:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Delay after which claim the next frame. If the delay is too small,
|
|
|
|
* the camera will return old frames. On the 4800Z, 20ms is bad, 25ms
|
2009-03-26 16:06:50 +08:00
|
|
|
* will fail every 4 or 5 frames, but 30ms is perfect. On the A210,
|
|
|
|
* 30ms is bad while 35ms is perfect. */
|
|
|
|
#define NEXT_FRAME_DELAY 35
|
2008-09-29 17:59:36 +08:00
|
|
|
|
|
|
|
/* These cameras only support 320x200. */
|
2008-12-29 18:49:41 +08:00
|
|
|
static const struct v4l2_pix_format fpix_mode[1] = {
|
2008-09-29 17:59:36 +08:00
|
|
|
{ 320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
|
|
|
|
.bytesperline = 320,
|
|
|
|
.sizeimage = 320 * 240 * 3 / 8 + 590,
|
|
|
|
.colorspace = V4L2_COLORSPACE_SRGB,
|
|
|
|
.priv = 0}
|
|
|
|
};
|
|
|
|
|
2009-03-26 16:06:50 +08:00
|
|
|
/* send a command to the webcam */
|
|
|
|
static int command(struct gspca_dev *gspca_dev,
|
|
|
|
int order) /* 0: reset, 1: frame request */
|
2008-09-29 17:59:36 +08:00
|
|
|
{
|
2009-03-26 16:06:50 +08:00
|
|
|
static u8 order_values[2][12] = {
|
|
|
|
{0xc6, 0, 0, 0, 0, 0, 0, 0, 0x20, 0, 0, 0}, /* reset */
|
|
|
|
{0xd3, 0, 0, 0, 0, 0, 0, 0x01, 0, 0, 0, 0}, /* fr req */
|
|
|
|
};
|
2008-09-29 17:59:36 +08:00
|
|
|
|
2009-03-26 16:06:50 +08:00
|
|
|
memcpy(gspca_dev->usb_buf, order_values[order], 12);
|
|
|
|
return usb_control_msg(gspca_dev->dev,
|
|
|
|
usb_sndctrlpipe(gspca_dev->dev, 0),
|
|
|
|
USB_REQ_GET_STATUS,
|
|
|
|
USB_DIR_OUT | USB_TYPE_CLASS |
|
|
|
|
USB_RECIP_INTERFACE, 0, 0, gspca_dev->usb_buf,
|
|
|
|
12, FPIX_TIMEOUT);
|
2008-09-29 17:59:36 +08:00
|
|
|
}
|
|
|
|
|
2009-03-26 16:06:50 +08:00
|
|
|
/* workqueue */
|
|
|
|
static void dostream(struct work_struct *work)
|
2008-09-29 17:59:36 +08:00
|
|
|
{
|
2009-03-26 16:06:50 +08:00
|
|
|
struct usb_fpix *dev = container_of(work, struct usb_fpix, work_struct);
|
|
|
|
struct gspca_dev *gspca_dev = &dev->gspca_dev;
|
|
|
|
struct urb *urb = gspca_dev->urb[0];
|
|
|
|
u8 *data = urb->transfer_buffer;
|
|
|
|
struct gspca_frame *frame;
|
|
|
|
int ret = 0;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
/* synchronize with the main driver */
|
|
|
|
mutex_lock(&gspca_dev->usb_lock);
|
|
|
|
mutex_unlock(&gspca_dev->usb_lock);
|
|
|
|
PDEBUG(D_STREAM, "dostream started");
|
|
|
|
|
|
|
|
/* loop reading a frame */
|
|
|
|
again:
|
|
|
|
while (gspca_dev->present && gspca_dev->streaming) {
|
|
|
|
|
|
|
|
/* request a frame */
|
|
|
|
mutex_lock(&gspca_dev->usb_lock);
|
|
|
|
ret = command(gspca_dev, 1);
|
|
|
|
mutex_unlock(&gspca_dev->usb_lock);
|
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
if (!gspca_dev->present || !gspca_dev->streaming)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* the frame comes in parts */
|
|
|
|
for (;;) {
|
|
|
|
ret = usb_bulk_msg(gspca_dev->dev,
|
|
|
|
urb->pipe,
|
|
|
|
data,
|
|
|
|
FPIX_MAX_TRANSFER,
|
|
|
|
&len, FPIX_TIMEOUT);
|
|
|
|
if (ret < 0) {
|
|
|
|
/* Most of the time we get a timeout
|
|
|
|
* error. Just restart. */
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
if (!gspca_dev->present || !gspca_dev->streaming)
|
|
|
|
goto out;
|
|
|
|
frame = gspca_get_i_frame(&dev->gspca_dev);
|
|
|
|
if (frame == NULL)
|
|
|
|
gspca_dev->last_packet_type = DISCARD_PACKET;
|
|
|
|
|
|
|
|
if (len < FPIX_MAX_TRANSFER ||
|
|
|
|
(data[len - 2] == 0xff &&
|
|
|
|
data[len - 1] == 0xd9)) {
|
|
|
|
|
|
|
|
/* If the result is less than what was asked
|
|
|
|
* for, then it's the end of the
|
|
|
|
* frame. Sometimes the jpeg is not complete,
|
|
|
|
* but there's nothing we can do. We also end
|
|
|
|
* here if the the jpeg ends right at the end
|
|
|
|
* of the frame. */
|
|
|
|
if (frame)
|
|
|
|
frame = gspca_frame_add(gspca_dev,
|
|
|
|
LAST_PACKET,
|
|
|
|
frame,
|
|
|
|
data, len);
|
|
|
|
break;
|
|
|
|
}
|
2008-09-29 17:59:36 +08:00
|
|
|
|
|
|
|
/* got a partial image */
|
2008-09-30 14:55:33 +08:00
|
|
|
if (frame)
|
|
|
|
gspca_frame_add(gspca_dev,
|
|
|
|
gspca_dev->last_packet_type
|
2009-03-26 16:06:50 +08:00
|
|
|
== LAST_PACKET
|
2008-09-30 14:55:33 +08:00
|
|
|
? FIRST_PACKET : INTER_PACKET,
|
2009-03-26 16:06:50 +08:00
|
|
|
frame, data, len);
|
2008-09-29 17:59:36 +08:00
|
|
|
}
|
|
|
|
|
2009-03-26 16:06:50 +08:00
|
|
|
/* We must wait before trying reading the next
|
|
|
|
* frame. If we don't, or if the delay is too short,
|
|
|
|
* the camera will disconnect. */
|
|
|
|
msleep(NEXT_FRAME_DELAY);
|
2008-09-29 17:59:36 +08:00
|
|
|
}
|
|
|
|
|
2009-03-26 16:06:50 +08:00
|
|
|
out:
|
|
|
|
PDEBUG(D_STREAM, "dostream stopped");
|
2008-09-29 17:59:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this function is called at probe time */
|
|
|
|
static int sd_config(struct gspca_dev *gspca_dev,
|
|
|
|
const struct usb_device_id *id)
|
|
|
|
{
|
2009-03-26 16:06:50 +08:00
|
|
|
struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
|
2008-09-29 17:59:36 +08:00
|
|
|
struct cam *cam = &gspca_dev->cam;
|
|
|
|
|
|
|
|
cam->cam_mode = fpix_mode;
|
|
|
|
cam->nmodes = 1;
|
|
|
|
cam->bulk_size = FPIX_MAX_TRANSFER;
|
|
|
|
|
2009-03-26 16:06:50 +08:00
|
|
|
INIT_WORK(&dev->work_struct, dostream);
|
2008-09-29 17:59:36 +08:00
|
|
|
|
2009-03-26 16:06:50 +08:00
|
|
|
return 0;
|
2008-09-29 17:59:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this function is called at probe and resume time */
|
|
|
|
static int sd_init(struct gspca_dev *gspca_dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-26 16:06:50 +08:00
|
|
|
/* start the camera */
|
2008-09-29 17:59:36 +08:00
|
|
|
static int sd_start(struct gspca_dev *gspca_dev)
|
|
|
|
{
|
|
|
|
struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
|
2009-03-26 16:06:50 +08:00
|
|
|
int ret, len;
|
2008-09-29 17:59:36 +08:00
|
|
|
|
|
|
|
/* Init the device */
|
2009-03-26 16:06:50 +08:00
|
|
|
ret = command(gspca_dev, 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
PDEBUG(D_STREAM, "init failed %d", ret);
|
|
|
|
return ret;
|
2008-09-29 17:59:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the result of the command. Ignore the result, for it
|
|
|
|
* varies with the device. */
|
|
|
|
ret = usb_bulk_msg(gspca_dev->dev,
|
2008-12-31 19:13:46 +08:00
|
|
|
gspca_dev->urb[0]->pipe,
|
2009-03-26 16:06:50 +08:00
|
|
|
gspca_dev->urb[0]->transfer_buffer,
|
|
|
|
FPIX_MAX_TRANSFER, &len,
|
2008-09-29 17:59:36 +08:00
|
|
|
FPIX_TIMEOUT);
|
2009-03-26 16:06:50 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
PDEBUG(D_STREAM, "usb_bulk_msg failed %d", ret);
|
|
|
|
return ret;
|
2008-09-29 17:59:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Request a frame, but don't read it */
|
2009-03-26 16:06:50 +08:00
|
|
|
ret = command(gspca_dev, 1);
|
|
|
|
if (ret < 0) {
|
|
|
|
PDEBUG(D_STREAM, "frame request failed %d", ret);
|
|
|
|
return ret;
|
2008-09-29 17:59:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Again, reset bulk in endpoint */
|
2008-12-31 19:13:46 +08:00
|
|
|
usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe);
|
2008-09-29 17:59:36 +08:00
|
|
|
|
2009-03-26 16:06:50 +08:00
|
|
|
/* Start the workqueue function to do the streaming */
|
|
|
|
dev->work_thread = create_singlethread_workqueue(MODULE_NAME);
|
|
|
|
queue_work(dev->work_thread, &dev->work_struct);
|
2008-09-29 17:59:36 +08:00
|
|
|
|
|
|
|
return 0;
|
2009-03-26 16:06:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* called on streamoff with alt==0 and on disconnect */
|
|
|
|
/* the usb_lock is held at entry - restore on exit */
|
|
|
|
static void sd_stop0(struct gspca_dev *gspca_dev)
|
|
|
|
{
|
|
|
|
struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
|
2008-09-29 17:59:36 +08:00
|
|
|
|
2009-03-26 16:06:50 +08:00
|
|
|
/* wait for the work queue to terminate */
|
|
|
|
mutex_unlock(&gspca_dev->usb_lock);
|
|
|
|
destroy_workqueue(dev->work_thread);
|
|
|
|
mutex_lock(&gspca_dev->usb_lock);
|
|
|
|
dev->work_thread = NULL;
|
2008-09-29 17:59:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Table of supported USB devices */
|
|
|
|
static const __devinitdata struct usb_device_id device_table[] = {
|
|
|
|
{USB_DEVICE(0x04cb, 0x0104)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x0109)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x010b)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x010f)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x0111)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x0113)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x0115)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x0117)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x0119)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x011b)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x011d)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x0121)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x0123)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x0125)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x0127)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x0129)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x012b)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x012d)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x012f)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x0131)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x013b)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x013d)},
|
|
|
|
{USB_DEVICE(0x04cb, 0x013f)},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(usb, device_table);
|
|
|
|
|
|
|
|
/* sub-driver description */
|
|
|
|
static const struct sd_desc sd_desc = {
|
2009-03-26 16:06:50 +08:00
|
|
|
.name = MODULE_NAME,
|
2008-09-29 17:59:36 +08:00
|
|
|
.config = sd_config,
|
2009-03-26 16:06:50 +08:00
|
|
|
.init = sd_init,
|
|
|
|
.start = sd_start,
|
|
|
|
.stop0 = sd_stop0,
|
2008-09-29 17:59:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* -- device connect -- */
|
|
|
|
static int sd_probe(struct usb_interface *intf,
|
|
|
|
const struct usb_device_id *id)
|
|
|
|
{
|
|
|
|
return gspca_dev_probe(intf, id,
|
|
|
|
&sd_desc,
|
|
|
|
sizeof(struct usb_fpix),
|
|
|
|
THIS_MODULE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct usb_driver sd_driver = {
|
2009-03-26 16:06:50 +08:00
|
|
|
.name = MODULE_NAME,
|
|
|
|
.id_table = device_table,
|
|
|
|
.probe = sd_probe,
|
2008-09-29 17:59:36 +08:00
|
|
|
.disconnect = gspca_disconnect,
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
.suspend = gspca_suspend,
|
2009-03-26 16:06:50 +08:00
|
|
|
.resume = gspca_resume,
|
2008-09-29 17:59:36 +08:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/* -- module insert / remove -- */
|
|
|
|
static int __init sd_mod_init(void)
|
|
|
|
{
|
2009-01-02 00:02:07 +08:00
|
|
|
int ret;
|
2009-03-26 16:06:50 +08:00
|
|
|
|
2009-01-02 00:02:07 +08:00
|
|
|
ret = usb_register(&sd_driver);
|
|
|
|
if (ret < 0)
|
2009-01-02 00:04:58 +08:00
|
|
|
return ret;
|
2008-09-29 17:59:36 +08:00
|
|
|
PDEBUG(D_PROBE, "registered");
|
|
|
|
return 0;
|
|
|
|
}
|
2009-03-26 16:06:50 +08:00
|
|
|
|
2008-09-29 17:59:36 +08:00
|
|
|
static void __exit sd_mod_exit(void)
|
|
|
|
{
|
|
|
|
usb_deregister(&sd_driver);
|
|
|
|
PDEBUG(D_PROBE, "deregistered");
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(sd_mod_init);
|
|
|
|
module_exit(sd_mod_exit);
|