27 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29 #define MODULE_NAME "jeilinj"
31 #include <linux/slab.h>
40 #define JEILINJ_CMD_TIMEOUT 500
41 #define JEILINJ_CMD_DELAY 160
42 #define JEILINJ_DATA_TIMEOUT 1000
45 #define JEILINJ_MAX_TRANSFER 0x200
46 #define FRAME_HEADER_LEN 0x10
47 #define FRAME_START 0xFFFFFFFF
54 #define CAMQUALITY_MIN 0
55 #define CAMQUALITY_MAX 97
67 #define QUALITY_MIN 35
68 #define QUALITY_MAX 85
69 #define QUALITY_DEF 85
83 .sizeimage = 320 * 240,
88 .sizeimage = 640 * 480,
107 usb_sndbulkpipe(gspca_dev->
dev, 3),
110 pr_err(
"command write [%02x] error %d\n",
111 gspca_dev->
usb_buf[0], retval);
117 static void jlj_read1(
struct gspca_dev *gspca_dev,
unsigned char response)
124 usb_rcvbulkpipe(gspca_dev->
dev, 0x84),
126 response = gspca_dev->
usb_buf[0];
128 pr_err(
"read command [%02x] error %d\n",
129 gspca_dev->
usb_buf[0], retval);
134 static void setfreq(
struct gspca_dev *gspca_dev,
s32 val)
136 u8 freq_commands[][2] = {
141 freq_commands[0][1] |= val >> 1;
143 jlj_write2(gspca_dev, freq_commands[0]);
144 jlj_write2(gspca_dev, freq_commands[1]);
147 static void setcamquality(
struct gspca_dev *gspca_dev,
s32 val)
149 u8 quality_commands[][2] = {
158 quality_commands[0][1] += camquality;
160 jlj_write2(gspca_dev, quality_commands[0]);
161 jlj_write2(gspca_dev, quality_commands[1]);
164 static void setautogain(
struct gspca_dev *gspca_dev,
s32 val)
166 u8 autogain_commands[][2] = {
171 autogain_commands[1][1] = val << 4;
173 jlj_write2(gspca_dev, autogain_commands[0]);
174 jlj_write2(gspca_dev, autogain_commands[1]);
177 static void setred(
struct gspca_dev *gspca_dev,
s32 val)
179 u8 setred_commands[][2] = {
184 setred_commands[1][1] =
val;
186 jlj_write2(gspca_dev, setred_commands[0]);
187 jlj_write2(gspca_dev, setred_commands[1]);
190 static void setgreen(
struct gspca_dev *gspca_dev,
s32 val)
192 u8 setgreen_commands[][2] = {
197 setgreen_commands[1][1] =
val;
199 jlj_write2(gspca_dev, setgreen_commands[0]);
200 jlj_write2(gspca_dev, setgreen_commands[1]);
203 static void setblue(
struct gspca_dev *gspca_dev,
s32 val)
205 u8 setblue_commands[][2] = {
210 setblue_commands[1][1] =
val;
212 jlj_write2(gspca_dev, setblue_commands[0]);
213 jlj_write2(gspca_dev, setblue_commands[1]);
216 static int jlj_start(
struct gspca_dev *gspca_dev)
219 int start_commands_size;
221 struct sd *
sd = (
struct sd *) gspca_dev;
223 {{0x71, 0x81}, 0, 0},
225 {{0x95, 0x70}, 1, 0},
226 {{0x71, 0x81 - gspca_dev->
curr_mode}, 0, 0},
228 {{0x95, 0x70}, 1, 0},
229 {{0x71, 0x00}, 0, 0},
231 {{0x95, 0x70}, 1, 0},
232 #define SPORTSCAM_DV15_CMD_SIZE 9
233 {{0x94, 0x02}, 0, 0},
234 {{0xde, 0x24}, 0, 0},
235 {{0x94, 0x02}, 0, 0},
236 {{0xdd, 0xf0}, 0, 0},
237 {{0x94, 0x02}, 0, 0},
238 {{0xe3, 0x2c}, 0, 0},
239 {{0x94, 0x02}, 0, 0},
240 {{0xe4, 0x00}, 0, 0},
241 {{0x94, 0x02}, 0, 0},
242 {{0xe5, 0x00}, 0, 0},
243 {{0x94, 0x02}, 0, 0},
244 {{0xe6, 0x2c}, 0, 0},
245 {{0x94, 0x03}, 0, 0},
256 start_commands_size =
ARRAY_SIZE(start_commands);
258 for (i = 0; i < start_commands_size; i++) {
259 jlj_write2(gspca_dev, start_commands[i].
instruction);
260 if (start_commands[i].
delay)
261 msleep(start_commands[i].delay);
263 jlj_read1(gspca_dev, response);
273 static void sd_pkt_scan(
struct gspca_dev *gspca_dev,
276 struct sd *sd = (
struct sd *) gspca_dev;
280 PDEBUG(D_STREAM,
"Got %d bytes out of %d for Block 0",
283 PDEBUG(D_PACK,
"bad length");
287 header_marker = ((
u32 *)data)[0];
299 PDEBUG(D_STREAM,
"%d blocks remaining for frame",
317 static int sd_config(
struct gspca_dev *gspca_dev,
321 struct sd *
dev = (
struct sd *) gspca_dev;
323 dev->
type =
id->driver_info;
334 static void sd_stopN(
struct gspca_dev *gspca_dev)
338 static u8 stop_commands[][2] = {
348 gspca_dev->
urb[0]->pipe,
349 gspca_dev->
urb[0]->transfer_buffer,
355 buf = gspca_dev->
urb[0]->transfer_buffer;
357 ((buf[i] != 0xff) || (buf[i+1] != 0xd9)))
365 for (i = 0; i <
ARRAY_SIZE(stop_commands); i++)
366 jlj_write2(gspca_dev, stop_commands[i]);
370 static int sd_init(
struct gspca_dev *gspca_dev)
376 static int sd_start(
struct gspca_dev *gspca_dev)
378 struct sd *
dev = (
struct sd *) gspca_dev;
384 PDEBUG(D_STREAM,
"Start streaming at %dx%d",
386 jlj_start(gspca_dev);
392 {USB_DEVICE(0x0979, 0x0280), .driver_info =
SAKAR_57379},
401 struct gspca_dev *gspca_dev =
403 struct sd *sd = (
struct sd *)gspca_dev;
412 setfreq(gspca_dev, ctrl->
val);
415 setred(gspca_dev, ctrl->
val);
418 setgreen(gspca_dev, ctrl->
val);
421 setblue(gspca_dev, ctrl->
val);
424 setautogain(gspca_dev, ctrl->
val);
428 setcamquality(gspca_dev, ctrl->
val);
438 static int sd_init_controls(
struct gspca_dev *gspca_dev)
440 struct sd *sd = (
struct sd *)gspca_dev;
446 .name =
"Automatic Gain (and Exposure)",
452 gspca_dev->
vdev.ctrl_handler = hdl;
470 pr_err(
"Could not initialize controls\n");
476 static int sd_set_jcomp(
struct gspca_dev *gspca_dev,
479 struct sd *sd = (
struct sd *) gspca_dev;
485 static int sd_get_jcomp(
struct gspca_dev *gspca_dev,
488 struct sd *sd = (
struct sd *) gspca_dev;
490 memset(jcomp, 0,
sizeof *jcomp);
499 static const struct sd_desc sd_desc_sakar_57379 = {
505 .pkt_scan = sd_pkt_scan,
509 static const struct sd_desc sd_desc_sportscam_dv15 = {
513 .init_controls = sd_init_controls,
516 .pkt_scan = sd_pkt_scan,
517 .get_jcomp = sd_get_jcomp,
518 .set_jcomp = sd_set_jcomp,
522 &sd_desc_sakar_57379,
523 &sd_desc_sportscam_dv15
531 sd_desc[id->driver_info],
536 static struct usb_driver sd_driver = {
538 .id_table = device_table,
542 .suspend = gspca_suspend,
543 .resume = gspca_resume,
544 .reset_resume = gspca_resume,