26 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28 #define MODULE_NAME "pac207"
30 #include <linux/input.h>
39 #define PAC207_CTRL_TIMEOUT 100
41 #define PAC207_BRIGHTNESS_MIN 0
42 #define PAC207_BRIGHTNESS_MAX 255
43 #define PAC207_BRIGHTNESS_DEFAULT 46
44 #define PAC207_BRIGHTNESS_REG 0x08
46 #define PAC207_EXPOSURE_MIN 3
47 #define PAC207_EXPOSURE_MAX 90
48 #define PAC207_EXPOSURE_DEFAULT 5
49 #define PAC207_EXPOSURE_REG 0x02
51 #define PAC207_GAIN_MIN 0
52 #define PAC207_GAIN_MAX 31
53 #define PAC207_GAIN_DEFAULT 7
54 #define PAC207_GAIN_REG 0x0e
56 #define PAC207_AUTOGAIN_DEADZONE 30
75 .sizeimage = (176 + 2) * 144,
83 .sizeimage = (352 + 2) * 288,
88 static const __u8 pac207_sensor_init[][8] = {
89 {0x10, 0x12, 0x0d, 0x12, 0x0c, 0x01, 0x29, 0x84},
90 {0x49, 0x64, 0x64, 0x64, 0x04, 0x10, 0xf0, 0x30},
91 {0x00, 0x00, 0x00, 0x70, 0xa0, 0xf8, 0x00, 0x00},
92 {0x32, 0x00, 0x96, 0x00, 0xa2, 0x02, 0xaf, 0x00},
98 struct usb_device *
udev = gspca_dev->
dev;
111 pr_err(
"Failed to write registers to index 0x%04X, error %d\n",
117 static void pac207_write_reg(
struct gspca_dev *gspca_dev,
u16 index,
u16 value)
119 struct usb_device *
udev = gspca_dev->
dev;
129 pr_err(
"Failed to write a register (index 0x%04X, value 0x%02X, error %d)\n",
135 static int pac207_read_reg(
struct gspca_dev *gspca_dev,
u16 index)
137 struct usb_device *
udev = gspca_dev->
dev;
148 pr_err(
"Failed to read a register (index 0x%04X, error %d)\n",
158 static int sd_config(
struct gspca_dev *gspca_dev,
164 idreg[0] = pac207_read_reg(gspca_dev, 0x0000);
165 idreg[1] = pac207_read_reg(gspca_dev, 0x0001);
166 idreg[0] = ((idreg[0] & 0x0f) << 4) | ((idreg[1] & 0xf0) >> 4);
167 idreg[1] = idreg[1] & 0x0f;
168 PDEBUG(D_PROBE,
"Pixart Sensor ID 0x%02X Chips ID 0x%02X",
171 if (idreg[0] != 0x27) {
172 PDEBUG(D_PROBE,
"Error invalid sensor ID!");
177 "Pixart PAC207BCA Image Processor and Control Chip detected"
180 cam = &gspca_dev->
cam;
188 static int sd_init(
struct gspca_dev *gspca_dev)
190 pac207_write_reg(gspca_dev, 0x41, 0x00);
194 pac207_write_reg(gspca_dev, 0x0f, 0x00);
199 static void setcontrol(
struct gspca_dev *gspca_dev,
u16 reg,
u16 val)
201 pac207_write_reg(gspca_dev, reg, val);
202 pac207_write_reg(gspca_dev, 0x13, 0x01);
203 pac207_write_reg(gspca_dev, 0x1c, 0x01);
208 struct gspca_dev *gspca_dev =
210 struct sd *
sd = (
struct sd *)gspca_dev;
237 gspca_dev->
gain->val);
250 static int sd_init_controls(
struct gspca_dev *gspca_dev)
252 struct sd *
sd = (
struct sd *) gspca_dev;
255 gspca_dev->
vdev.ctrl_handler = hdl;
273 pr_err(
"Could not initialize controls\n");
281 static int sd_start(
struct gspca_dev *gspca_dev)
283 struct sd *
sd = (
struct sd *) gspca_dev;
286 pac207_write_reg(gspca_dev, 0x0f, 0x10);
287 pac207_write_regs(gspca_dev, 0x0002, pac207_sensor_init[0], 8);
288 pac207_write_regs(gspca_dev, 0x000a, pac207_sensor_init[1], 8);
289 pac207_write_regs(gspca_dev, 0x0012, pac207_sensor_init[2], 8);
290 pac207_write_regs(gspca_dev, 0x0042, pac207_sensor_init[3], 8);
293 if (gspca_dev->
width == 176)
294 pac207_write_reg(gspca_dev, 0x4a, 0xff);
296 pac207_write_reg(gspca_dev, 0x4a, 0x30);
297 pac207_write_reg(gspca_dev, 0x4b, 0x00);
301 pac207_write_reg(gspca_dev, 0x0e,
303 pac207_write_reg(gspca_dev, 0x02,
307 if (gspca_dev->
width == 176) {
309 PDEBUG(D_STREAM,
"pac207_start mode 176x144");
311 PDEBUG(D_STREAM,
"pac207_start mode 352x288");
313 pac207_write_reg(gspca_dev, 0x41, mode);
315 pac207_write_reg(gspca_dev, 0x13, 0x01);
316 pac207_write_reg(gspca_dev, 0x1c, 0x01);
318 pac207_write_reg(gspca_dev, 0x40, 0x01);
326 static void sd_stopN(
struct gspca_dev *gspca_dev)
328 pac207_write_reg(gspca_dev, 0x40, 0x00);
329 pac207_write_reg(gspca_dev, 0x41, 0x00);
330 pac207_write_reg(gspca_dev, 0x0f, 0x00);
334 static void pac207_do_auto_gain(
struct gspca_dev *gspca_dev)
336 struct sd *
sd = (
struct sd *) gspca_dev;
349 static void sd_pkt_scan(
struct gspca_dev *gspca_dev,
353 struct sd *
sd = (
struct sd *) gspca_dev;
356 sof = pac_find_sof(&sd->
sof_read, data, len);
362 if (n >
sizeof pac_sof_marker)
363 n -=
sizeof pac_sof_marker;
396 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
397 static int sd_int_pkt_scan(
struct gspca_dev *gspca_dev,
403 if (len == 2 && data[0] == 0x5a && data[1] == 0x5a) {
404 input_report_key(gspca_dev->input_dev,
KEY_CAMERA, 1);
405 input_sync(gspca_dev->input_dev);
406 input_report_key(gspca_dev->input_dev,
KEY_CAMERA, 0);
407 input_sync(gspca_dev->input_dev);
416 static const struct sd_desc sd_desc = {
420 .init_controls = sd_init_controls,
423 .dq_callback = pac207_do_auto_gain,
424 .pkt_scan = sd_pkt_scan,
425 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
426 .int_pkt_scan = sd_int_pkt_scan,
432 {USB_DEVICE(0x041e, 0x4028)},
433 {USB_DEVICE(0x093a, 0x2460)},
434 {USB_DEVICE(0x093a, 0x2461)},
435 {USB_DEVICE(0x093a, 0x2463)},
436 {USB_DEVICE(0x093a, 0x2464)},
437 {USB_DEVICE(0x093a, 0x2468)},
438 {USB_DEVICE(0x093a, 0x2470)},
439 {USB_DEVICE(0x093a, 0x2471)},
440 {USB_DEVICE(0x093a, 0x2472)},
441 {USB_DEVICE(0x093a, 0x2474)},
442 {USB_DEVICE(0x093a, 0x2476)},
443 {USB_DEVICE(0x145f, 0x013a)},
444 {USB_DEVICE(0x2001, 0xf115)},
457 static struct usb_driver sd_driver = {
459 .id_table = device_table,
463 .suspend = gspca_suspend,
464 .resume = gspca_resume,
465 .reset_resume = gspca_resume,