26 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28 #define MODULE_NAME "se401"
30 #define BULK_SIZE 4096
31 #define PACKET_SIZE 1024
32 #define READ_REQ_SIZE 64
33 #define MAX_MODES ((READ_REQ_SIZE - 6) / 4)
37 #define SE401_QUANT_FACT 8
39 #include <linux/input.h>
40 #include <linux/slab.h>
85 usb_sndctrlpipe(gspca_dev->
dev, 0), req,
87 value, 0,
NULL, 0, 1000);
90 pr_err(
"write req failed req %#04x val %#04x error %d\n",
104 pr_err(
"USB_BUF_SZ too small!!\n");
110 usb_rcvctrlpipe(gspca_dev->
dev, 0), req,
115 pr_err(
"read req failed req %#04x error %d\n",
121 static void se401_set_feature(
struct gspca_dev *gspca_dev,
130 usb_sndctrlpipe(gspca_dev->
dev, 0),
133 param, selector,
NULL, 0, 1000);
135 pr_err(
"set feature failed sel %#04x param %#04x error %d\n",
136 selector, param, err);
141 static int se401_get_feature(
struct gspca_dev *gspca_dev,
u16 selector)
149 pr_err(
"USB_BUF_SZ too small!!\n");
155 usb_rcvctrlpipe(gspca_dev->
dev, 0),
158 0, selector, gspca_dev->
usb_buf, 2, 1000);
160 pr_err(
"get feature failed sel %#04x error %d\n",
168 static void setbrightness(
struct gspca_dev *gspca_dev,
s32 val)
174 static void setgain(
struct gspca_dev *gspca_dev,
s32 val)
186 static void setexposure(
struct gspca_dev *gspca_dev,
s32 val,
s32 freq)
188 struct sd *
sd = (
struct sd *) gspca_dev;
189 int integration = val << 6;
190 u8 expose_h, expose_m, expose_l;
200 integration = integration - integration % 106667;
202 integration = integration - integration % 88889;
204 expose_h = (integration >> 16);
205 expose_m = (integration >> 8);
206 expose_l = integration;
216 static int sd_config(
struct gspca_dev *gspca_dev,
219 struct sd *sd = (
struct sd *)gspca_dev;
241 pr_err(
"Wrong descriptor type\n");
246 pr_err(
"Bayer format not supported!\n");
251 pr_info(
"ExtraFeatures: %d\n", cd[3]);
253 n = cd[4] | (cd[5] << 8);
255 pr_err(
"Too many frame sizes\n");
259 for (i = 0; i <
n ; i++) {
260 widths[
i] = cd[6 + i * 4 + 0] | (cd[6 + i * 4 + 1] << 8);
261 heights[
i] = cd[6 + i * 4 + 2] | (cd[6 + i * 4 + 3] << 8);
264 for (i = 0; i <
n ; i++) {
265 sd->
fmts[
i].width = widths[
i];
266 sd->
fmts[
i].height = heights[
i];
269 sd->
fmts[
i].priv = 1;
272 for (j = 0; j <
n; j++) {
273 if (widths[j] / 2 == widths[i] &&
274 heights[j] / 2 == heights[i]) {
275 sd->
fmts[
i].priv = 2;
281 for (j = 0; j <
n; j++) {
282 if (widths[j] / 4 == widths[i] &&
283 heights[j] / 4 == heights[i]) {
284 sd->
fmts[
i].priv = 4;
289 if (sd->
fmts[i].priv == 1) {
292 sd->
fmts[
i].bytesperline = widths[
i];
293 sd->
fmts[
i].sizeimage = widths[
i] * heights[
i];
294 pr_info(
"Frame size: %dx%d bayer\n",
295 widths[i], heights[i]);
299 sd->
fmts[
i].bytesperline = 0;
300 sd->
fmts[
i].sizeimage = widths[
i] * heights[
i] * 3;
301 pr_info(
"Frame size: %dx%d 1/%dth janggu\n",
302 widths[i], heights[i],
303 sd->
fmts[i].priv * sd->
fmts[i].priv);
323 static int sd_init(
struct gspca_dev *gspca_dev)
329 static int sd_isoc_init(
struct gspca_dev *gspca_dev)
337 static int sd_start(
struct gspca_dev *gspca_dev)
339 struct sd *sd = (
struct sd *)gspca_dev;
357 gspca_dev->
width * mult, 0);
359 gspca_dev->
height * mult, 0);
390 static void sd_stopN(
struct gspca_dev *gspca_dev)
397 static void sd_dq_callback(
struct gspca_dev *gspca_dev)
399 struct sd *sd = (
struct sd *)gspca_dev;
400 unsigned int ahrc, alrc;
401 int oldreset, adjust_dir;
435 }
else if (ahrc > 20) {
458 static void sd_complete_frame(
struct gspca_dev *gspca_dev,
u8 *
data,
int len)
460 struct sd *sd = (
struct sd *)gspca_dev;
480 static void sd_pkt_scan_janggu(
struct gspca_dev *gspca_dev,
u8 *data,
int len)
482 struct sd *sd = (
struct sd *)gspca_dev;
483 int imagesize = gspca_dev->
width * gspca_dev->
height;
510 info = (sd->
packet[0] & 0xc0) >> 6;
511 plen = ((bits + 47) >> 4) << 1;
514 pr_err(
"invalid packet len %d restarting stream\n",
519 pr_err(
"unknown frame info value restarting stream\n");
543 pr_err(
"frame size %d expected %d\n",
547 sd_complete_frame(gspca_dev, sd->
packet, plen);
566 static void sd_pkt_scan_bayer(
struct gspca_dev *gspca_dev,
u8 *data,
int len)
568 struct cam *cam = &gspca_dev->
cam;
576 if (gspca_dev->
image_len + len >= imagesize) {
577 sd_complete_frame(gspca_dev, data, len);
584 static void sd_pkt_scan(
struct gspca_dev *gspca_dev,
u8 *data,
int len)
586 int mult = gspca_dev->
cam.cam_mode[gspca_dev->
curr_mode].priv;
592 sd_pkt_scan_bayer(gspca_dev, data, len);
594 sd_pkt_scan_janggu(gspca_dev, data, len);
597 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
598 static int sd_int_pkt_scan(
struct gspca_dev *gspca_dev,
u8 *data,
int len)
600 struct sd *sd = (
struct sd *)gspca_dev;
615 input_report_key(gspca_dev->input_dev,
KEY_CAMERA, state);
616 input_sync(gspca_dev->input_dev);
626 struct gspca_dev *gspca_dev =
628 struct sd *sd = (
struct sd *)gspca_dev;
637 setbrightness(gspca_dev, ctrl->
val);
640 setgain(gspca_dev, ctrl->
val);
643 setexposure(gspca_dev, ctrl->
val, sd->
freq->val);
653 static int sd_init_controls(
struct gspca_dev *gspca_dev)
655 struct sd *sd = (
struct sd *)gspca_dev;
658 gspca_dev->
vdev.ctrl_handler = hdl;
673 pr_err(
"Could not initialize controls\n");
685 .init_controls = sd_init_controls,
686 .isoc_init = sd_isoc_init,
689 .dq_callback = sd_dq_callback,
690 .pkt_scan = sd_pkt_scan,
691 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
692 .int_pkt_scan = sd_int_pkt_scan,
698 {USB_DEVICE(0x03e8, 0x0004)},
699 {USB_DEVICE(0x0471, 0x030b)},
700 {USB_DEVICE(0x047d, 0x5001)},
701 {USB_DEVICE(0x047d, 0x5002)},
702 {USB_DEVICE(0x047d, 0x5003)},
725 static struct usb_driver sd_driver = {
727 .id_table = device_table,
731 .suspend = gspca_suspend,
732 .resume = gspca_resume,
733 .reset_resume = gspca_resume,
735 .pre_reset = sd_pre_reset,
736 .post_reset = sd_post_reset,