18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * sonix sn9c102 (bayer) library 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2009-2011 Jean-François Moine <http://moinejf.free.fr> 68c2ecf20Sopenharmony_ci * Copyright (C) 2003 2004 Michel Xhaard mxhaard@magic.fr 78c2ecf20Sopenharmony_ci * Add Pas106 Stefano Mozzi (C) 2004 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci/* Some documentation on known sonixb registers: 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ciReg Use 138c2ecf20Sopenharmony_cisn9c101 / sn9c102: 148c2ecf20Sopenharmony_ci0x10 high nibble red gain low nibble blue gain 158c2ecf20Sopenharmony_ci0x11 low nibble green gain 168c2ecf20Sopenharmony_cisn9c103: 178c2ecf20Sopenharmony_ci0x05 red gain 0-127 188c2ecf20Sopenharmony_ci0x06 blue gain 0-127 198c2ecf20Sopenharmony_ci0x07 green gain 0-127 208c2ecf20Sopenharmony_ciall: 218c2ecf20Sopenharmony_ci0x08-0x0f i2c / 3wire registers 228c2ecf20Sopenharmony_ci0x12 hstart 238c2ecf20Sopenharmony_ci0x13 vstart 248c2ecf20Sopenharmony_ci0x15 hsize (hsize = register-value * 16) 258c2ecf20Sopenharmony_ci0x16 vsize (vsize = register-value * 16) 268c2ecf20Sopenharmony_ci0x17 bit 0 toggle compression quality (according to sn9c102 driver) 278c2ecf20Sopenharmony_ci0x18 bit 7 enables compression, bit 4-5 set image down scaling: 288c2ecf20Sopenharmony_ci 00 scale 1, 01 scale 1/2, 10, scale 1/4 298c2ecf20Sopenharmony_ci0x19 high-nibble is sensor clock divider, changes exposure on sensors which 308c2ecf20Sopenharmony_ci use a clock generated by the bridge. Some sensors have their own clock. 318c2ecf20Sopenharmony_ci0x1c auto_exposure area (for avg_lum) startx (startx = register-value * 32) 328c2ecf20Sopenharmony_ci0x1d auto_exposure area (for avg_lum) starty (starty = register-value * 32) 338c2ecf20Sopenharmony_ci0x1e auto_exposure area (for avg_lum) stopx (hsize = (0x1e - 0x1c) * 32) 348c2ecf20Sopenharmony_ci0x1f auto_exposure area (for avg_lum) stopy (vsize = (0x1f - 0x1d) * 32) 358c2ecf20Sopenharmony_ci*/ 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#define MODULE_NAME "sonixb" 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#include <linux/input.h> 408c2ecf20Sopenharmony_ci#include "gspca.h" 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ciMODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>"); 438c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("GSPCA/SN9C102 USB Camera Driver"); 448c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci/* specific webcam descriptor */ 478c2ecf20Sopenharmony_cistruct sd { 488c2ecf20Sopenharmony_ci struct gspca_dev gspca_dev; /* !! must be the first item */ 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci struct v4l2_ctrl *brightness; 518c2ecf20Sopenharmony_ci struct v4l2_ctrl *plfreq; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci atomic_t avg_lum; 548c2ecf20Sopenharmony_ci int prev_avg_lum; 558c2ecf20Sopenharmony_ci int exposure_knee; 568c2ecf20Sopenharmony_ci int header_read; 578c2ecf20Sopenharmony_ci u8 header[12]; /* Header without sof marker */ 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci unsigned char autogain_ignore_frames; 608c2ecf20Sopenharmony_ci unsigned char frames_to_drop; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci __u8 bridge; /* Type of bridge */ 638c2ecf20Sopenharmony_ci#define BRIDGE_101 0 648c2ecf20Sopenharmony_ci#define BRIDGE_102 0 /* We make no difference between 101 and 102 */ 658c2ecf20Sopenharmony_ci#define BRIDGE_103 1 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci __u8 sensor; /* Type of image sensor chip */ 688c2ecf20Sopenharmony_ci#define SENSOR_HV7131D 0 698c2ecf20Sopenharmony_ci#define SENSOR_HV7131R 1 708c2ecf20Sopenharmony_ci#define SENSOR_OV6650 2 718c2ecf20Sopenharmony_ci#define SENSOR_OV7630 3 728c2ecf20Sopenharmony_ci#define SENSOR_PAS106 4 738c2ecf20Sopenharmony_ci#define SENSOR_PAS202 5 748c2ecf20Sopenharmony_ci#define SENSOR_TAS5110C 6 758c2ecf20Sopenharmony_ci#define SENSOR_TAS5110D 7 768c2ecf20Sopenharmony_ci#define SENSOR_TAS5130CXX 8 778c2ecf20Sopenharmony_ci __u8 reg11; 788c2ecf20Sopenharmony_ci}; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_citypedef const __u8 sensor_init_t[8]; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_cistruct sensor_data { 838c2ecf20Sopenharmony_ci const __u8 *bridge_init; 848c2ecf20Sopenharmony_ci sensor_init_t *sensor_init; 858c2ecf20Sopenharmony_ci int sensor_init_size; 868c2ecf20Sopenharmony_ci int flags; 878c2ecf20Sopenharmony_ci __u8 sensor_addr; 888c2ecf20Sopenharmony_ci}; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci/* sensor_data flags */ 918c2ecf20Sopenharmony_ci#define F_SIF 0x01 /* sif or vga */ 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci/* priv field of struct v4l2_pix_format flags (do not use low nibble!) */ 948c2ecf20Sopenharmony_ci#define MODE_RAW 0x10 /* raw bayer mode */ 958c2ecf20Sopenharmony_ci#define MODE_REDUCED_SIF 0x20 /* vga mode (320x240 / 160x120) on sif cam */ 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci#define COMP 0xc7 /* 0x87 //0x07 */ 988c2ecf20Sopenharmony_ci#define COMP1 0xc9 /* 0x89 //0x09 */ 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci#define MCK_INIT 0x63 1018c2ecf20Sopenharmony_ci#define MCK_INIT1 0x20 /*fixme: Bayer - 0x50 for JPEG ??*/ 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci#define SYS_CLK 0x04 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci#define SENS(bridge, sensor, _flags, _sensor_addr) \ 1068c2ecf20Sopenharmony_ci{ \ 1078c2ecf20Sopenharmony_ci .bridge_init = bridge, \ 1088c2ecf20Sopenharmony_ci .sensor_init = sensor, \ 1098c2ecf20Sopenharmony_ci .sensor_init_size = sizeof(sensor), \ 1108c2ecf20Sopenharmony_ci .flags = _flags, .sensor_addr = _sensor_addr \ 1118c2ecf20Sopenharmony_ci} 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci/* We calculate the autogain at the end of the transfer of a frame, at this 1148c2ecf20Sopenharmony_ci moment a frame with the old settings is being captured and transmitted. So 1158c2ecf20Sopenharmony_ci if we adjust the gain or exposure we must ignore at least the next frame for 1168c2ecf20Sopenharmony_ci the new settings to come into effect before doing any other adjustments. */ 1178c2ecf20Sopenharmony_ci#define AUTOGAIN_IGNORE_FRAMES 1 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_cistatic const struct v4l2_pix_format vga_mode[] = { 1208c2ecf20Sopenharmony_ci {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, 1218c2ecf20Sopenharmony_ci .bytesperline = 160, 1228c2ecf20Sopenharmony_ci .sizeimage = 160 * 120, 1238c2ecf20Sopenharmony_ci .colorspace = V4L2_COLORSPACE_SRGB, 1248c2ecf20Sopenharmony_ci .priv = 2 | MODE_RAW}, 1258c2ecf20Sopenharmony_ci {160, 120, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE, 1268c2ecf20Sopenharmony_ci .bytesperline = 160, 1278c2ecf20Sopenharmony_ci .sizeimage = 160 * 120 * 5 / 4, 1288c2ecf20Sopenharmony_ci .colorspace = V4L2_COLORSPACE_SRGB, 1298c2ecf20Sopenharmony_ci .priv = 2}, 1308c2ecf20Sopenharmony_ci {320, 240, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE, 1318c2ecf20Sopenharmony_ci .bytesperline = 320, 1328c2ecf20Sopenharmony_ci .sizeimage = 320 * 240 * 5 / 4, 1338c2ecf20Sopenharmony_ci .colorspace = V4L2_COLORSPACE_SRGB, 1348c2ecf20Sopenharmony_ci .priv = 1}, 1358c2ecf20Sopenharmony_ci {640, 480, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE, 1368c2ecf20Sopenharmony_ci .bytesperline = 640, 1378c2ecf20Sopenharmony_ci .sizeimage = 640 * 480 * 5 / 4, 1388c2ecf20Sopenharmony_ci .colorspace = V4L2_COLORSPACE_SRGB, 1398c2ecf20Sopenharmony_ci .priv = 0}, 1408c2ecf20Sopenharmony_ci}; 1418c2ecf20Sopenharmony_cistatic const struct v4l2_pix_format sif_mode[] = { 1428c2ecf20Sopenharmony_ci {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, 1438c2ecf20Sopenharmony_ci .bytesperline = 160, 1448c2ecf20Sopenharmony_ci .sizeimage = 160 * 120, 1458c2ecf20Sopenharmony_ci .colorspace = V4L2_COLORSPACE_SRGB, 1468c2ecf20Sopenharmony_ci .priv = 1 | MODE_RAW | MODE_REDUCED_SIF}, 1478c2ecf20Sopenharmony_ci {160, 120, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE, 1488c2ecf20Sopenharmony_ci .bytesperline = 160, 1498c2ecf20Sopenharmony_ci .sizeimage = 160 * 120 * 5 / 4, 1508c2ecf20Sopenharmony_ci .colorspace = V4L2_COLORSPACE_SRGB, 1518c2ecf20Sopenharmony_ci .priv = 1 | MODE_REDUCED_SIF}, 1528c2ecf20Sopenharmony_ci {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, 1538c2ecf20Sopenharmony_ci .bytesperline = 176, 1548c2ecf20Sopenharmony_ci .sizeimage = 176 * 144, 1558c2ecf20Sopenharmony_ci .colorspace = V4L2_COLORSPACE_SRGB, 1568c2ecf20Sopenharmony_ci .priv = 1 | MODE_RAW}, 1578c2ecf20Sopenharmony_ci {176, 144, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE, 1588c2ecf20Sopenharmony_ci .bytesperline = 176, 1598c2ecf20Sopenharmony_ci .sizeimage = 176 * 144 * 5 / 4, 1608c2ecf20Sopenharmony_ci .colorspace = V4L2_COLORSPACE_SRGB, 1618c2ecf20Sopenharmony_ci .priv = 1}, 1628c2ecf20Sopenharmony_ci {320, 240, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE, 1638c2ecf20Sopenharmony_ci .bytesperline = 320, 1648c2ecf20Sopenharmony_ci .sizeimage = 320 * 240 * 5 / 4, 1658c2ecf20Sopenharmony_ci .colorspace = V4L2_COLORSPACE_SRGB, 1668c2ecf20Sopenharmony_ci .priv = 0 | MODE_REDUCED_SIF}, 1678c2ecf20Sopenharmony_ci {352, 288, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE, 1688c2ecf20Sopenharmony_ci .bytesperline = 352, 1698c2ecf20Sopenharmony_ci .sizeimage = 352 * 288 * 5 / 4, 1708c2ecf20Sopenharmony_ci .colorspace = V4L2_COLORSPACE_SRGB, 1718c2ecf20Sopenharmony_ci .priv = 0}, 1728c2ecf20Sopenharmony_ci}; 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_cistatic const __u8 initHv7131d[] = { 1758c2ecf20Sopenharmony_ci 0x04, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00, 1768c2ecf20Sopenharmony_ci 0x00, 0x00, 1778c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0x02, 0x02, 0x00, 1788c2ecf20Sopenharmony_ci 0x28, 0x1e, 0x60, 0x8e, 0x42, 1798c2ecf20Sopenharmony_ci}; 1808c2ecf20Sopenharmony_cistatic const __u8 hv7131d_sensor_init[][8] = { 1818c2ecf20Sopenharmony_ci {0xa0, 0x11, 0x01, 0x04, 0x00, 0x00, 0x00, 0x17}, 1828c2ecf20Sopenharmony_ci {0xa0, 0x11, 0x02, 0x00, 0x00, 0x00, 0x00, 0x17}, 1838c2ecf20Sopenharmony_ci {0xa0, 0x11, 0x28, 0x00, 0x00, 0x00, 0x00, 0x17}, 1848c2ecf20Sopenharmony_ci {0xa0, 0x11, 0x30, 0x30, 0x00, 0x00, 0x00, 0x17}, /* reset level */ 1858c2ecf20Sopenharmony_ci {0xa0, 0x11, 0x34, 0x02, 0x00, 0x00, 0x00, 0x17}, /* pixel bias volt */ 1868c2ecf20Sopenharmony_ci}; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_cistatic const __u8 initHv7131r[] = { 1898c2ecf20Sopenharmony_ci 0x46, 0x77, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00, 1908c2ecf20Sopenharmony_ci 0x00, 0x00, 1918c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 1928c2ecf20Sopenharmony_ci 0x28, 0x1e, 0x60, 0x8a, 0x20, 1938c2ecf20Sopenharmony_ci}; 1948c2ecf20Sopenharmony_cistatic const __u8 hv7131r_sensor_init[][8] = { 1958c2ecf20Sopenharmony_ci {0xc0, 0x11, 0x31, 0x38, 0x2a, 0x2e, 0x00, 0x10}, 1968c2ecf20Sopenharmony_ci {0xa0, 0x11, 0x01, 0x08, 0x2a, 0x2e, 0x00, 0x10}, 1978c2ecf20Sopenharmony_ci {0xb0, 0x11, 0x20, 0x00, 0xd0, 0x2e, 0x00, 0x10}, 1988c2ecf20Sopenharmony_ci {0xc0, 0x11, 0x25, 0x03, 0x0e, 0x28, 0x00, 0x16}, 1998c2ecf20Sopenharmony_ci {0xa0, 0x11, 0x30, 0x10, 0x0e, 0x28, 0x00, 0x15}, 2008c2ecf20Sopenharmony_ci}; 2018c2ecf20Sopenharmony_cistatic const __u8 initOv6650[] = { 2028c2ecf20Sopenharmony_ci 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 2038c2ecf20Sopenharmony_ci 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 2048c2ecf20Sopenharmony_ci 0x00, 0x01, 0x01, 0x0a, 0x16, 0x12, 0x68, 0x8b, 2058c2ecf20Sopenharmony_ci 0x10, 2068c2ecf20Sopenharmony_ci}; 2078c2ecf20Sopenharmony_cistatic const __u8 ov6650_sensor_init[][8] = { 2088c2ecf20Sopenharmony_ci /* Bright, contrast, etc are set through SCBB interface. 2098c2ecf20Sopenharmony_ci * AVCAP on win2 do not send any data on this controls. */ 2108c2ecf20Sopenharmony_ci /* Anyway, some registers appears to alter bright and constrat */ 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci /* Reset sensor */ 2138c2ecf20Sopenharmony_ci {0xa0, 0x60, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, 2148c2ecf20Sopenharmony_ci /* Set clock register 0x11 low nibble is clock divider */ 2158c2ecf20Sopenharmony_ci {0xd0, 0x60, 0x11, 0xc0, 0x1b, 0x18, 0xc1, 0x10}, 2168c2ecf20Sopenharmony_ci /* Next some unknown stuff */ 2178c2ecf20Sopenharmony_ci {0xb0, 0x60, 0x15, 0x00, 0x02, 0x18, 0xc1, 0x10}, 2188c2ecf20Sopenharmony_ci/* {0xa0, 0x60, 0x1b, 0x01, 0x02, 0x18, 0xc1, 0x10}, 2198c2ecf20Sopenharmony_ci * THIS SET GREEN SCREEN 2208c2ecf20Sopenharmony_ci * (pixels could be innverted in decode kind of "brg", 2218c2ecf20Sopenharmony_ci * but blue wont be there. Avoid this data ... */ 2228c2ecf20Sopenharmony_ci {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10}, /* format out? */ 2238c2ecf20Sopenharmony_ci {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10}, 2248c2ecf20Sopenharmony_ci {0xa0, 0x60, 0x30, 0x3d, 0x0a, 0xd8, 0xa4, 0x10}, 2258c2ecf20Sopenharmony_ci /* Enable rgb brightness control */ 2268c2ecf20Sopenharmony_ci {0xa0, 0x60, 0x61, 0x08, 0x00, 0x00, 0x00, 0x10}, 2278c2ecf20Sopenharmony_ci /* HDG: Note windows uses the line below, which sets both register 0x60 2288c2ecf20Sopenharmony_ci and 0x61 I believe these registers of the ov6650 are identical as 2298c2ecf20Sopenharmony_ci those of the ov7630, because if this is true the windows settings 2308c2ecf20Sopenharmony_ci add a bit additional red gain and a lot additional blue gain, which 2318c2ecf20Sopenharmony_ci matches my findings that the windows settings make blue much too 2328c2ecf20Sopenharmony_ci blue and red a little too red. 2338c2ecf20Sopenharmony_ci {0xb0, 0x60, 0x60, 0x66, 0x68, 0xd8, 0xa4, 0x10}, */ 2348c2ecf20Sopenharmony_ci /* Some more unknown stuff */ 2358c2ecf20Sopenharmony_ci {0xa0, 0x60, 0x68, 0x04, 0x68, 0xd8, 0xa4, 0x10}, 2368c2ecf20Sopenharmony_ci {0xd0, 0x60, 0x17, 0x24, 0xd6, 0x04, 0x94, 0x10}, /* Clipreg */ 2378c2ecf20Sopenharmony_ci}; 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_cistatic const __u8 initOv7630[] = { 2408c2ecf20Sopenharmony_ci 0x04, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* r01 .. r08 */ 2418c2ecf20Sopenharmony_ci 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* r09 .. r10 */ 2428c2ecf20Sopenharmony_ci 0x00, 0x01, 0x01, 0x0a, /* r11 .. r14 */ 2438c2ecf20Sopenharmony_ci 0x28, 0x1e, /* H & V sizes r15 .. r16 */ 2448c2ecf20Sopenharmony_ci 0x68, 0x8f, MCK_INIT1, /* r17 .. r19 */ 2458c2ecf20Sopenharmony_ci}; 2468c2ecf20Sopenharmony_cistatic const __u8 ov7630_sensor_init[][8] = { 2478c2ecf20Sopenharmony_ci {0xa0, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, 2488c2ecf20Sopenharmony_ci {0xb0, 0x21, 0x01, 0x77, 0x3a, 0x00, 0x00, 0x10}, 2498c2ecf20Sopenharmony_ci/* {0xd0, 0x21, 0x12, 0x7c, 0x01, 0x80, 0x34, 0x10}, jfm */ 2508c2ecf20Sopenharmony_ci {0xd0, 0x21, 0x12, 0x5c, 0x00, 0x80, 0x34, 0x10}, /* jfm */ 2518c2ecf20Sopenharmony_ci {0xa0, 0x21, 0x1b, 0x04, 0x00, 0x80, 0x34, 0x10}, 2528c2ecf20Sopenharmony_ci {0xa0, 0x21, 0x20, 0x44, 0x00, 0x80, 0x34, 0x10}, 2538c2ecf20Sopenharmony_ci {0xa0, 0x21, 0x23, 0xee, 0x00, 0x80, 0x34, 0x10}, 2548c2ecf20Sopenharmony_ci {0xd0, 0x21, 0x26, 0xa0, 0x9a, 0xa0, 0x30, 0x10}, 2558c2ecf20Sopenharmony_ci {0xb0, 0x21, 0x2a, 0x80, 0x00, 0xa0, 0x30, 0x10}, 2568c2ecf20Sopenharmony_ci {0xb0, 0x21, 0x2f, 0x3d, 0x24, 0xa0, 0x30, 0x10}, 2578c2ecf20Sopenharmony_ci {0xa0, 0x21, 0x32, 0x86, 0x24, 0xa0, 0x30, 0x10}, 2588c2ecf20Sopenharmony_ci {0xb0, 0x21, 0x60, 0xa9, 0x4a, 0xa0, 0x30, 0x10}, 2598c2ecf20Sopenharmony_ci/* {0xb0, 0x21, 0x60, 0xa9, 0x42, 0xa0, 0x30, 0x10}, * jfm */ 2608c2ecf20Sopenharmony_ci {0xa0, 0x21, 0x65, 0x00, 0x42, 0xa0, 0x30, 0x10}, 2618c2ecf20Sopenharmony_ci {0xa0, 0x21, 0x69, 0x38, 0x42, 0xa0, 0x30, 0x10}, 2628c2ecf20Sopenharmony_ci {0xc0, 0x21, 0x6f, 0x88, 0x0b, 0x00, 0x30, 0x10}, 2638c2ecf20Sopenharmony_ci {0xc0, 0x21, 0x74, 0x21, 0x8e, 0x00, 0x30, 0x10}, 2648c2ecf20Sopenharmony_ci {0xa0, 0x21, 0x7d, 0xf7, 0x8e, 0x00, 0x30, 0x10}, 2658c2ecf20Sopenharmony_ci {0xd0, 0x21, 0x17, 0x1c, 0xbd, 0x06, 0xf6, 0x10}, 2668c2ecf20Sopenharmony_ci}; 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_cistatic const __u8 initPas106[] = { 2698c2ecf20Sopenharmony_ci 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x40, 0x00, 0x00, 0x00, 2708c2ecf20Sopenharmony_ci 0x00, 0x00, 2718c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 2728c2ecf20Sopenharmony_ci 0x16, 0x12, 0x24, COMP1, MCK_INIT1, 2738c2ecf20Sopenharmony_ci}; 2748c2ecf20Sopenharmony_ci/* compression 0x86 mckinit1 0x2b */ 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci/* "Known" PAS106B registers: 2778c2ecf20Sopenharmony_ci 0x02 clock divider 2788c2ecf20Sopenharmony_ci 0x03 Variable framerate bits 4-11 2798c2ecf20Sopenharmony_ci 0x04 Var framerate bits 0-3, one must leave the 4 msb's at 0 !! 2808c2ecf20Sopenharmony_ci The variable framerate control must never be set lower then 300, 2818c2ecf20Sopenharmony_ci which sets the framerate at 90 / reg02, otherwise vsync is lost. 2828c2ecf20Sopenharmony_ci 0x05 Shutter Time Line Offset, this can be used as an exposure control: 2838c2ecf20Sopenharmony_ci 0 = use full frame time, 255 = no exposure at all 2848c2ecf20Sopenharmony_ci Note this may never be larger then "var-framerate control" / 2 - 2. 2858c2ecf20Sopenharmony_ci When var-framerate control is < 514, no exposure is reached at the max 2868c2ecf20Sopenharmony_ci allowed value for the framerate control value, rather then at 255. 2878c2ecf20Sopenharmony_ci 0x06 Shutter Time Pixel Offset, like reg05 this influences exposure, but 2888c2ecf20Sopenharmony_ci only a very little bit, leave at 0xcd 2898c2ecf20Sopenharmony_ci 0x07 offset sign bit (bit0 1 > negative offset) 2908c2ecf20Sopenharmony_ci 0x08 offset 2918c2ecf20Sopenharmony_ci 0x09 Blue Gain 2928c2ecf20Sopenharmony_ci 0x0a Green1 Gain 2938c2ecf20Sopenharmony_ci 0x0b Green2 Gain 2948c2ecf20Sopenharmony_ci 0x0c Red Gain 2958c2ecf20Sopenharmony_ci 0x0e Global gain 2968c2ecf20Sopenharmony_ci 0x13 Write 1 to commit settings to sensor 2978c2ecf20Sopenharmony_ci*/ 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_cistatic const __u8 pas106_sensor_init[][8] = { 3008c2ecf20Sopenharmony_ci /* Pixel Clock Divider 6 */ 3018c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x14 }, 3028c2ecf20Sopenharmony_ci /* Frame Time MSB (also seen as 0x12) */ 3038c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x03, 0x13, 0x00, 0x00, 0x00, 0x14 }, 3048c2ecf20Sopenharmony_ci /* Frame Time LSB (also seen as 0x05) */ 3058c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x04, 0x06, 0x00, 0x00, 0x00, 0x14 }, 3068c2ecf20Sopenharmony_ci /* Shutter Time Line Offset (also seen as 0x6d) */ 3078c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x05, 0x65, 0x00, 0x00, 0x00, 0x14 }, 3088c2ecf20Sopenharmony_ci /* Shutter Time Pixel Offset (also seen as 0xb1) */ 3098c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x06, 0xcd, 0x00, 0x00, 0x00, 0x14 }, 3108c2ecf20Sopenharmony_ci /* Black Level Subtract Sign (also seen 0x00) */ 3118c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x07, 0xc1, 0x00, 0x00, 0x00, 0x14 }, 3128c2ecf20Sopenharmony_ci /* Black Level Subtract Level (also seen 0x01) */ 3138c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x08, 0x06, 0x00, 0x00, 0x00, 0x14 }, 3148c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x08, 0x06, 0x00, 0x00, 0x00, 0x14 }, 3158c2ecf20Sopenharmony_ci /* Color Gain B Pixel 5 a */ 3168c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x09, 0x05, 0x00, 0x00, 0x00, 0x14 }, 3178c2ecf20Sopenharmony_ci /* Color Gain G1 Pixel 1 5 */ 3188c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x0a, 0x04, 0x00, 0x00, 0x00, 0x14 }, 3198c2ecf20Sopenharmony_ci /* Color Gain G2 Pixel 1 0 5 */ 3208c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x0b, 0x04, 0x00, 0x00, 0x00, 0x14 }, 3218c2ecf20Sopenharmony_ci /* Color Gain R Pixel 3 1 */ 3228c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x0c, 0x05, 0x00, 0x00, 0x00, 0x14 }, 3238c2ecf20Sopenharmony_ci /* Color GainH Pixel */ 3248c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x14 }, 3258c2ecf20Sopenharmony_ci /* Global Gain */ 3268c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x0e, 0x0e, 0x00, 0x00, 0x00, 0x14 }, 3278c2ecf20Sopenharmony_ci /* Contrast */ 3288c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x14 }, 3298c2ecf20Sopenharmony_ci /* H&V synchro polarity */ 3308c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x10, 0x06, 0x00, 0x00, 0x00, 0x14 }, 3318c2ecf20Sopenharmony_ci /* ?default */ 3328c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x11, 0x06, 0x00, 0x00, 0x00, 0x14 }, 3338c2ecf20Sopenharmony_ci /* DAC scale */ 3348c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x12, 0x06, 0x00, 0x00, 0x00, 0x14 }, 3358c2ecf20Sopenharmony_ci /* ?default */ 3368c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x14, 0x02, 0x00, 0x00, 0x00, 0x14 }, 3378c2ecf20Sopenharmony_ci /* Validate Settings */ 3388c2ecf20Sopenharmony_ci { 0xa1, 0x40, 0x13, 0x01, 0x00, 0x00, 0x00, 0x14 }, 3398c2ecf20Sopenharmony_ci}; 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_cistatic const __u8 initPas202[] = { 3428c2ecf20Sopenharmony_ci 0x44, 0x44, 0x21, 0x30, 0x00, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x00, 3438c2ecf20Sopenharmony_ci 0x00, 0x00, 3448c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0x06, 0x03, 0x0a, 3458c2ecf20Sopenharmony_ci 0x28, 0x1e, 0x20, 0x89, 0x20, 3468c2ecf20Sopenharmony_ci}; 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci/* "Known" PAS202BCB registers: 3498c2ecf20Sopenharmony_ci 0x02 clock divider 3508c2ecf20Sopenharmony_ci 0x04 Variable framerate bits 6-11 (*) 3518c2ecf20Sopenharmony_ci 0x05 Var framerate bits 0-5, one must leave the 2 msb's at 0 !! 3528c2ecf20Sopenharmony_ci 0x07 Blue Gain 3538c2ecf20Sopenharmony_ci 0x08 Green Gain 3548c2ecf20Sopenharmony_ci 0x09 Red Gain 3558c2ecf20Sopenharmony_ci 0x0b offset sign bit (bit0 1 > negative offset) 3568c2ecf20Sopenharmony_ci 0x0c offset 3578c2ecf20Sopenharmony_ci 0x0e Unknown image is slightly brighter when bit 0 is 0, if reg0f is 0 too, 3588c2ecf20Sopenharmony_ci leave at 1 otherwise we get a jump in our exposure control 3598c2ecf20Sopenharmony_ci 0x0f Exposure 0-255, 0 = use full frame time, 255 = no exposure at all 3608c2ecf20Sopenharmony_ci 0x10 Master gain 0 - 31 3618c2ecf20Sopenharmony_ci 0x11 write 1 to apply changes 3628c2ecf20Sopenharmony_ci (*) The variable framerate control must never be set lower then 500 3638c2ecf20Sopenharmony_ci which sets the framerate at 30 / reg02, otherwise vsync is lost. 3648c2ecf20Sopenharmony_ci*/ 3658c2ecf20Sopenharmony_cistatic const __u8 pas202_sensor_init[][8] = { 3668c2ecf20Sopenharmony_ci /* Set the clock divider to 4 -> 30 / 4 = 7.5 fps, we would like 3678c2ecf20Sopenharmony_ci to set it lower, but for some reason the bridge starts missing 3688c2ecf20Sopenharmony_ci vsync's then */ 3698c2ecf20Sopenharmony_ci {0xa0, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x10}, 3708c2ecf20Sopenharmony_ci {0xd0, 0x40, 0x04, 0x07, 0x34, 0x00, 0x09, 0x10}, 3718c2ecf20Sopenharmony_ci {0xd0, 0x40, 0x08, 0x01, 0x00, 0x00, 0x01, 0x10}, 3728c2ecf20Sopenharmony_ci {0xd0, 0x40, 0x0c, 0x00, 0x0c, 0x01, 0x32, 0x10}, 3738c2ecf20Sopenharmony_ci {0xd0, 0x40, 0x10, 0x00, 0x01, 0x00, 0x63, 0x10}, 3748c2ecf20Sopenharmony_ci {0xa0, 0x40, 0x15, 0x70, 0x01, 0x00, 0x63, 0x10}, 3758c2ecf20Sopenharmony_ci {0xa0, 0x40, 0x18, 0x00, 0x01, 0x00, 0x63, 0x10}, 3768c2ecf20Sopenharmony_ci {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10}, 3778c2ecf20Sopenharmony_ci {0xa0, 0x40, 0x03, 0x56, 0x01, 0x00, 0x63, 0x10}, 3788c2ecf20Sopenharmony_ci {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10}, 3798c2ecf20Sopenharmony_ci}; 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_cistatic const __u8 initTas5110c[] = { 3828c2ecf20Sopenharmony_ci 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00, 3838c2ecf20Sopenharmony_ci 0x00, 0x00, 3848c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0x45, 0x09, 0x0a, 3858c2ecf20Sopenharmony_ci 0x16, 0x12, 0x60, 0x86, 0x2b, 3868c2ecf20Sopenharmony_ci}; 3878c2ecf20Sopenharmony_ci/* Same as above, except a different hstart */ 3888c2ecf20Sopenharmony_cistatic const __u8 initTas5110d[] = { 3898c2ecf20Sopenharmony_ci 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00, 3908c2ecf20Sopenharmony_ci 0x00, 0x00, 3918c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0x41, 0x09, 0x0a, 3928c2ecf20Sopenharmony_ci 0x16, 0x12, 0x60, 0x86, 0x2b, 3938c2ecf20Sopenharmony_ci}; 3948c2ecf20Sopenharmony_ci/* tas5110c is 3 wire, tas5110d is 2 wire (regular i2c) */ 3958c2ecf20Sopenharmony_cistatic const __u8 tas5110c_sensor_init[][8] = { 3968c2ecf20Sopenharmony_ci {0x30, 0x11, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10}, 3978c2ecf20Sopenharmony_ci {0x30, 0x11, 0x02, 0x20, 0xa9, 0x00, 0x00, 0x10}, 3988c2ecf20Sopenharmony_ci}; 3998c2ecf20Sopenharmony_ci/* Known TAS5110D registers 4008c2ecf20Sopenharmony_ci * reg02: gain, bit order reversed!! 0 == max gain, 255 == min gain 4018c2ecf20Sopenharmony_ci * reg03: bit3: vflip, bit4: ~hflip, bit7: ~gainboost (~ == inverted) 4028c2ecf20Sopenharmony_ci * Note: writing reg03 seems to only work when written together with 02 4038c2ecf20Sopenharmony_ci */ 4048c2ecf20Sopenharmony_cistatic const __u8 tas5110d_sensor_init[][8] = { 4058c2ecf20Sopenharmony_ci {0xa0, 0x61, 0x9a, 0xca, 0x00, 0x00, 0x00, 0x17}, /* reset */ 4068c2ecf20Sopenharmony_ci}; 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_cistatic const __u8 initTas5130[] = { 4098c2ecf20Sopenharmony_ci 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00, 4108c2ecf20Sopenharmony_ci 0x00, 0x00, 4118c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0x68, 0x0c, 0x0a, 4128c2ecf20Sopenharmony_ci 0x28, 0x1e, 0x60, COMP, MCK_INIT, 4138c2ecf20Sopenharmony_ci}; 4148c2ecf20Sopenharmony_cistatic const __u8 tas5130_sensor_init[][8] = { 4158c2ecf20Sopenharmony_ci/* {0x30, 0x11, 0x00, 0x40, 0x47, 0x00, 0x00, 0x10}, 4168c2ecf20Sopenharmony_ci * shutter 0x47 short exposure? */ 4178c2ecf20Sopenharmony_ci {0x30, 0x11, 0x00, 0x40, 0x01, 0x00, 0x00, 0x10}, 4188c2ecf20Sopenharmony_ci /* shutter 0x01 long exposure */ 4198c2ecf20Sopenharmony_ci {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10}, 4208c2ecf20Sopenharmony_ci}; 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_cistatic const struct sensor_data sensor_data[] = { 4238c2ecf20Sopenharmony_ci SENS(initHv7131d, hv7131d_sensor_init, 0, 0), 4248c2ecf20Sopenharmony_ci SENS(initHv7131r, hv7131r_sensor_init, 0, 0), 4258c2ecf20Sopenharmony_ci SENS(initOv6650, ov6650_sensor_init, F_SIF, 0x60), 4268c2ecf20Sopenharmony_ci SENS(initOv7630, ov7630_sensor_init, 0, 0x21), 4278c2ecf20Sopenharmony_ci SENS(initPas106, pas106_sensor_init, F_SIF, 0), 4288c2ecf20Sopenharmony_ci SENS(initPas202, pas202_sensor_init, 0, 0), 4298c2ecf20Sopenharmony_ci SENS(initTas5110c, tas5110c_sensor_init, F_SIF, 0), 4308c2ecf20Sopenharmony_ci SENS(initTas5110d, tas5110d_sensor_init, F_SIF, 0), 4318c2ecf20Sopenharmony_ci SENS(initTas5130, tas5130_sensor_init, 0, 0), 4328c2ecf20Sopenharmony_ci}; 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci/* get one byte in gspca_dev->usb_buf */ 4358c2ecf20Sopenharmony_cistatic void reg_r(struct gspca_dev *gspca_dev, 4368c2ecf20Sopenharmony_ci __u16 value) 4378c2ecf20Sopenharmony_ci{ 4388c2ecf20Sopenharmony_ci int res; 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci if (gspca_dev->usb_err < 0) 4418c2ecf20Sopenharmony_ci return; 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci res = usb_control_msg(gspca_dev->dev, 4448c2ecf20Sopenharmony_ci usb_rcvctrlpipe(gspca_dev->dev, 0), 4458c2ecf20Sopenharmony_ci 0, /* request */ 4468c2ecf20Sopenharmony_ci USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 4478c2ecf20Sopenharmony_ci value, 4488c2ecf20Sopenharmony_ci 0, /* index */ 4498c2ecf20Sopenharmony_ci gspca_dev->usb_buf, 1, 4508c2ecf20Sopenharmony_ci 500); 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_ci if (res < 0) { 4538c2ecf20Sopenharmony_ci dev_err(gspca_dev->v4l2_dev.dev, 4548c2ecf20Sopenharmony_ci "Error reading register %02x: %d\n", value, res); 4558c2ecf20Sopenharmony_ci gspca_dev->usb_err = res; 4568c2ecf20Sopenharmony_ci /* 4578c2ecf20Sopenharmony_ci * Make sure the result is zeroed to avoid uninitialized 4588c2ecf20Sopenharmony_ci * values. 4598c2ecf20Sopenharmony_ci */ 4608c2ecf20Sopenharmony_ci gspca_dev->usb_buf[0] = 0; 4618c2ecf20Sopenharmony_ci } 4628c2ecf20Sopenharmony_ci} 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_cistatic void reg_w(struct gspca_dev *gspca_dev, 4658c2ecf20Sopenharmony_ci __u16 value, 4668c2ecf20Sopenharmony_ci const __u8 *buffer, 4678c2ecf20Sopenharmony_ci int len) 4688c2ecf20Sopenharmony_ci{ 4698c2ecf20Sopenharmony_ci int res; 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci if (gspca_dev->usb_err < 0) 4728c2ecf20Sopenharmony_ci return; 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci memcpy(gspca_dev->usb_buf, buffer, len); 4758c2ecf20Sopenharmony_ci res = usb_control_msg(gspca_dev->dev, 4768c2ecf20Sopenharmony_ci usb_sndctrlpipe(gspca_dev->dev, 0), 4778c2ecf20Sopenharmony_ci 0x08, /* request */ 4788c2ecf20Sopenharmony_ci USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 4798c2ecf20Sopenharmony_ci value, 4808c2ecf20Sopenharmony_ci 0, /* index */ 4818c2ecf20Sopenharmony_ci gspca_dev->usb_buf, len, 4828c2ecf20Sopenharmony_ci 500); 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_ci if (res < 0) { 4858c2ecf20Sopenharmony_ci dev_err(gspca_dev->v4l2_dev.dev, 4868c2ecf20Sopenharmony_ci "Error writing register %02x: %d\n", value, res); 4878c2ecf20Sopenharmony_ci gspca_dev->usb_err = res; 4888c2ecf20Sopenharmony_ci } 4898c2ecf20Sopenharmony_ci} 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_cistatic void i2c_w(struct gspca_dev *gspca_dev, const u8 *buf) 4928c2ecf20Sopenharmony_ci{ 4938c2ecf20Sopenharmony_ci int retry = 60; 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ci if (gspca_dev->usb_err < 0) 4968c2ecf20Sopenharmony_ci return; 4978c2ecf20Sopenharmony_ci 4988c2ecf20Sopenharmony_ci /* is i2c ready */ 4998c2ecf20Sopenharmony_ci reg_w(gspca_dev, 0x08, buf, 8); 5008c2ecf20Sopenharmony_ci while (retry--) { 5018c2ecf20Sopenharmony_ci if (gspca_dev->usb_err < 0) 5028c2ecf20Sopenharmony_ci return; 5038c2ecf20Sopenharmony_ci msleep(1); 5048c2ecf20Sopenharmony_ci reg_r(gspca_dev, 0x08); 5058c2ecf20Sopenharmony_ci if (gspca_dev->usb_buf[0] & 0x04) { 5068c2ecf20Sopenharmony_ci if (gspca_dev->usb_buf[0] & 0x08) { 5078c2ecf20Sopenharmony_ci dev_err(gspca_dev->v4l2_dev.dev, 5088c2ecf20Sopenharmony_ci "i2c error writing %8ph\n", buf); 5098c2ecf20Sopenharmony_ci gspca_dev->usb_err = -EIO; 5108c2ecf20Sopenharmony_ci } 5118c2ecf20Sopenharmony_ci return; 5128c2ecf20Sopenharmony_ci } 5138c2ecf20Sopenharmony_ci } 5148c2ecf20Sopenharmony_ci 5158c2ecf20Sopenharmony_ci dev_err(gspca_dev->v4l2_dev.dev, "i2c write timeout\n"); 5168c2ecf20Sopenharmony_ci gspca_dev->usb_err = -EIO; 5178c2ecf20Sopenharmony_ci} 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_cistatic void i2c_w_vector(struct gspca_dev *gspca_dev, 5208c2ecf20Sopenharmony_ci const __u8 buffer[][8], int len) 5218c2ecf20Sopenharmony_ci{ 5228c2ecf20Sopenharmony_ci for (;;) { 5238c2ecf20Sopenharmony_ci if (gspca_dev->usb_err < 0) 5248c2ecf20Sopenharmony_ci return; 5258c2ecf20Sopenharmony_ci i2c_w(gspca_dev, *buffer); 5268c2ecf20Sopenharmony_ci len -= 8; 5278c2ecf20Sopenharmony_ci if (len <= 0) 5288c2ecf20Sopenharmony_ci break; 5298c2ecf20Sopenharmony_ci buffer++; 5308c2ecf20Sopenharmony_ci } 5318c2ecf20Sopenharmony_ci} 5328c2ecf20Sopenharmony_ci 5338c2ecf20Sopenharmony_cistatic void setbrightness(struct gspca_dev *gspca_dev) 5348c2ecf20Sopenharmony_ci{ 5358c2ecf20Sopenharmony_ci struct sd *sd = (struct sd *) gspca_dev; 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci switch (sd->sensor) { 5388c2ecf20Sopenharmony_ci case SENSOR_OV6650: 5398c2ecf20Sopenharmony_ci case SENSOR_OV7630: { 5408c2ecf20Sopenharmony_ci __u8 i2cOV[] = 5418c2ecf20Sopenharmony_ci {0xa0, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}; 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ci /* change reg 0x06 */ 5448c2ecf20Sopenharmony_ci i2cOV[1] = sensor_data[sd->sensor].sensor_addr; 5458c2ecf20Sopenharmony_ci i2cOV[3] = sd->brightness->val; 5468c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2cOV); 5478c2ecf20Sopenharmony_ci break; 5488c2ecf20Sopenharmony_ci } 5498c2ecf20Sopenharmony_ci case SENSOR_PAS106: 5508c2ecf20Sopenharmony_ci case SENSOR_PAS202: { 5518c2ecf20Sopenharmony_ci __u8 i2cpbright[] = 5528c2ecf20Sopenharmony_ci {0xb0, 0x40, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x16}; 5538c2ecf20Sopenharmony_ci __u8 i2cpdoit[] = 5548c2ecf20Sopenharmony_ci {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16}; 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ci /* PAS106 uses reg 7 and 8 instead of b and c */ 5578c2ecf20Sopenharmony_ci if (sd->sensor == SENSOR_PAS106) { 5588c2ecf20Sopenharmony_ci i2cpbright[2] = 7; 5598c2ecf20Sopenharmony_ci i2cpdoit[2] = 0x13; 5608c2ecf20Sopenharmony_ci } 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci if (sd->brightness->val < 127) { 5638c2ecf20Sopenharmony_ci /* change reg 0x0b, signreg */ 5648c2ecf20Sopenharmony_ci i2cpbright[3] = 0x01; 5658c2ecf20Sopenharmony_ci /* set reg 0x0c, offset */ 5668c2ecf20Sopenharmony_ci i2cpbright[4] = 127 - sd->brightness->val; 5678c2ecf20Sopenharmony_ci } else 5688c2ecf20Sopenharmony_ci i2cpbright[4] = sd->brightness->val - 127; 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2cpbright); 5718c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2cpdoit); 5728c2ecf20Sopenharmony_ci break; 5738c2ecf20Sopenharmony_ci } 5748c2ecf20Sopenharmony_ci default: 5758c2ecf20Sopenharmony_ci break; 5768c2ecf20Sopenharmony_ci } 5778c2ecf20Sopenharmony_ci} 5788c2ecf20Sopenharmony_ci 5798c2ecf20Sopenharmony_cistatic void setgain(struct gspca_dev *gspca_dev) 5808c2ecf20Sopenharmony_ci{ 5818c2ecf20Sopenharmony_ci struct sd *sd = (struct sd *) gspca_dev; 5828c2ecf20Sopenharmony_ci u8 gain = gspca_dev->gain->val; 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci switch (sd->sensor) { 5858c2ecf20Sopenharmony_ci case SENSOR_HV7131D: { 5868c2ecf20Sopenharmony_ci __u8 i2c[] = 5878c2ecf20Sopenharmony_ci {0xc0, 0x11, 0x31, 0x00, 0x00, 0x00, 0x00, 0x17}; 5888c2ecf20Sopenharmony_ci 5898c2ecf20Sopenharmony_ci i2c[3] = 0x3f - gain; 5908c2ecf20Sopenharmony_ci i2c[4] = 0x3f - gain; 5918c2ecf20Sopenharmony_ci i2c[5] = 0x3f - gain; 5928c2ecf20Sopenharmony_ci 5938c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2c); 5948c2ecf20Sopenharmony_ci break; 5958c2ecf20Sopenharmony_ci } 5968c2ecf20Sopenharmony_ci case SENSOR_TAS5110C: 5978c2ecf20Sopenharmony_ci case SENSOR_TAS5130CXX: { 5988c2ecf20Sopenharmony_ci __u8 i2c[] = 5998c2ecf20Sopenharmony_ci {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10}; 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci i2c[4] = 255 - gain; 6028c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2c); 6038c2ecf20Sopenharmony_ci break; 6048c2ecf20Sopenharmony_ci } 6058c2ecf20Sopenharmony_ci case SENSOR_TAS5110D: { 6068c2ecf20Sopenharmony_ci __u8 i2c[] = { 6078c2ecf20Sopenharmony_ci 0xb0, 0x61, 0x02, 0x00, 0x10, 0x00, 0x00, 0x17 }; 6088c2ecf20Sopenharmony_ci gain = 255 - gain; 6098c2ecf20Sopenharmony_ci /* The bits in the register are the wrong way around!! */ 6108c2ecf20Sopenharmony_ci i2c[3] |= (gain & 0x80) >> 7; 6118c2ecf20Sopenharmony_ci i2c[3] |= (gain & 0x40) >> 5; 6128c2ecf20Sopenharmony_ci i2c[3] |= (gain & 0x20) >> 3; 6138c2ecf20Sopenharmony_ci i2c[3] |= (gain & 0x10) >> 1; 6148c2ecf20Sopenharmony_ci i2c[3] |= (gain & 0x08) << 1; 6158c2ecf20Sopenharmony_ci i2c[3] |= (gain & 0x04) << 3; 6168c2ecf20Sopenharmony_ci i2c[3] |= (gain & 0x02) << 5; 6178c2ecf20Sopenharmony_ci i2c[3] |= (gain & 0x01) << 7; 6188c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2c); 6198c2ecf20Sopenharmony_ci break; 6208c2ecf20Sopenharmony_ci } 6218c2ecf20Sopenharmony_ci case SENSOR_OV6650: 6228c2ecf20Sopenharmony_ci case SENSOR_OV7630: { 6238c2ecf20Sopenharmony_ci __u8 i2c[] = {0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}; 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci /* 6268c2ecf20Sopenharmony_ci * The ov7630's gain is weird, at 32 the gain drops to the 6278c2ecf20Sopenharmony_ci * same level as at 16, so skip 32-47 (of the 0-63 scale). 6288c2ecf20Sopenharmony_ci */ 6298c2ecf20Sopenharmony_ci if (sd->sensor == SENSOR_OV7630 && gain >= 32) 6308c2ecf20Sopenharmony_ci gain += 16; 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci i2c[1] = sensor_data[sd->sensor].sensor_addr; 6338c2ecf20Sopenharmony_ci i2c[3] = gain; 6348c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2c); 6358c2ecf20Sopenharmony_ci break; 6368c2ecf20Sopenharmony_ci } 6378c2ecf20Sopenharmony_ci case SENSOR_PAS106: 6388c2ecf20Sopenharmony_ci case SENSOR_PAS202: { 6398c2ecf20Sopenharmony_ci __u8 i2cpgain[] = 6408c2ecf20Sopenharmony_ci {0xa0, 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x15}; 6418c2ecf20Sopenharmony_ci __u8 i2cpcolorgain[] = 6428c2ecf20Sopenharmony_ci {0xc0, 0x40, 0x07, 0x00, 0x00, 0x00, 0x00, 0x15}; 6438c2ecf20Sopenharmony_ci __u8 i2cpdoit[] = 6448c2ecf20Sopenharmony_ci {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16}; 6458c2ecf20Sopenharmony_ci 6468c2ecf20Sopenharmony_ci /* PAS106 uses different regs (and has split green gains) */ 6478c2ecf20Sopenharmony_ci if (sd->sensor == SENSOR_PAS106) { 6488c2ecf20Sopenharmony_ci i2cpgain[2] = 0x0e; 6498c2ecf20Sopenharmony_ci i2cpcolorgain[0] = 0xd0; 6508c2ecf20Sopenharmony_ci i2cpcolorgain[2] = 0x09; 6518c2ecf20Sopenharmony_ci i2cpdoit[2] = 0x13; 6528c2ecf20Sopenharmony_ci } 6538c2ecf20Sopenharmony_ci 6548c2ecf20Sopenharmony_ci i2cpgain[3] = gain; 6558c2ecf20Sopenharmony_ci i2cpcolorgain[3] = gain >> 1; 6568c2ecf20Sopenharmony_ci i2cpcolorgain[4] = gain >> 1; 6578c2ecf20Sopenharmony_ci i2cpcolorgain[5] = gain >> 1; 6588c2ecf20Sopenharmony_ci i2cpcolorgain[6] = gain >> 1; 6598c2ecf20Sopenharmony_ci 6608c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2cpgain); 6618c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2cpcolorgain); 6628c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2cpdoit); 6638c2ecf20Sopenharmony_ci break; 6648c2ecf20Sopenharmony_ci } 6658c2ecf20Sopenharmony_ci default: 6668c2ecf20Sopenharmony_ci if (sd->bridge == BRIDGE_103) { 6678c2ecf20Sopenharmony_ci u8 buf[3] = { gain, gain, gain }; /* R, G, B */ 6688c2ecf20Sopenharmony_ci reg_w(gspca_dev, 0x05, buf, 3); 6698c2ecf20Sopenharmony_ci } else { 6708c2ecf20Sopenharmony_ci u8 buf[2]; 6718c2ecf20Sopenharmony_ci buf[0] = gain << 4 | gain; /* Red and blue */ 6728c2ecf20Sopenharmony_ci buf[1] = gain; /* Green */ 6738c2ecf20Sopenharmony_ci reg_w(gspca_dev, 0x10, buf, 2); 6748c2ecf20Sopenharmony_ci } 6758c2ecf20Sopenharmony_ci } 6768c2ecf20Sopenharmony_ci} 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_cistatic void setexposure(struct gspca_dev *gspca_dev) 6798c2ecf20Sopenharmony_ci{ 6808c2ecf20Sopenharmony_ci struct sd *sd = (struct sd *) gspca_dev; 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci switch (sd->sensor) { 6838c2ecf20Sopenharmony_ci case SENSOR_HV7131D: { 6848c2ecf20Sopenharmony_ci /* Note the datasheet wrongly says line mode exposure uses reg 6858c2ecf20Sopenharmony_ci 0x26 and 0x27, testing has shown 0x25 + 0x26 */ 6868c2ecf20Sopenharmony_ci __u8 i2c[] = {0xc0, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x17}; 6878c2ecf20Sopenharmony_ci u16 reg = gspca_dev->exposure->val; 6888c2ecf20Sopenharmony_ci 6898c2ecf20Sopenharmony_ci i2c[3] = reg >> 8; 6908c2ecf20Sopenharmony_ci i2c[4] = reg & 0xff; 6918c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2c); 6928c2ecf20Sopenharmony_ci break; 6938c2ecf20Sopenharmony_ci } 6948c2ecf20Sopenharmony_ci case SENSOR_TAS5110C: 6958c2ecf20Sopenharmony_ci case SENSOR_TAS5110D: { 6968c2ecf20Sopenharmony_ci /* register 19's high nibble contains the sn9c10x clock divider 6978c2ecf20Sopenharmony_ci The high nibble configures the no fps according to the 6988c2ecf20Sopenharmony_ci formula: 60 / high_nibble. With a maximum of 30 fps */ 6998c2ecf20Sopenharmony_ci u8 reg = gspca_dev->exposure->val; 7008c2ecf20Sopenharmony_ci 7018c2ecf20Sopenharmony_ci reg = (reg << 4) | 0x0b; 7028c2ecf20Sopenharmony_ci reg_w(gspca_dev, 0x19, ®, 1); 7038c2ecf20Sopenharmony_ci break; 7048c2ecf20Sopenharmony_ci } 7058c2ecf20Sopenharmony_ci case SENSOR_OV6650: 7068c2ecf20Sopenharmony_ci case SENSOR_OV7630: { 7078c2ecf20Sopenharmony_ci /* The ov6650 / ov7630 have 2 registers which both influence 7088c2ecf20Sopenharmony_ci exposure, register 11, whose low nibble sets the nr off fps 7098c2ecf20Sopenharmony_ci according to: fps = 30 / (low_nibble + 1) 7108c2ecf20Sopenharmony_ci 7118c2ecf20Sopenharmony_ci The fps configures the maximum exposure setting, but it is 7128c2ecf20Sopenharmony_ci possible to use less exposure then what the fps maximum 7138c2ecf20Sopenharmony_ci allows by setting register 10. register 10 configures the 7148c2ecf20Sopenharmony_ci actual exposure as quotient of the full exposure, with 0 7158c2ecf20Sopenharmony_ci being no exposure at all (not very useful) and reg10_max 7168c2ecf20Sopenharmony_ci being max exposure possible at that framerate. 7178c2ecf20Sopenharmony_ci 7188c2ecf20Sopenharmony_ci The code maps our 0 - 510 ms exposure ctrl to these 2 7198c2ecf20Sopenharmony_ci registers, trying to keep fps as high as possible. 7208c2ecf20Sopenharmony_ci */ 7218c2ecf20Sopenharmony_ci __u8 i2c[] = {0xb0, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10}; 7228c2ecf20Sopenharmony_ci int reg10, reg11, reg10_max; 7238c2ecf20Sopenharmony_ci 7248c2ecf20Sopenharmony_ci /* ov6645 datasheet says reg10_max is 9a, but that uses 7258c2ecf20Sopenharmony_ci tline * 2 * reg10 as formula for calculating texpo, the 7268c2ecf20Sopenharmony_ci ov6650 probably uses the same formula as the 7730 which uses 7278c2ecf20Sopenharmony_ci tline * 4 * reg10, which explains why the reg10max we've 7288c2ecf20Sopenharmony_ci found experimentally for the ov6650 is exactly half that of 7298c2ecf20Sopenharmony_ci the ov6645. The ov7630 datasheet says the max is 0x41. */ 7308c2ecf20Sopenharmony_ci if (sd->sensor == SENSOR_OV6650) { 7318c2ecf20Sopenharmony_ci reg10_max = 0x4d; 7328c2ecf20Sopenharmony_ci i2c[4] = 0xc0; /* OV6650 needs non default vsync pol */ 7338c2ecf20Sopenharmony_ci } else 7348c2ecf20Sopenharmony_ci reg10_max = 0x41; 7358c2ecf20Sopenharmony_ci 7368c2ecf20Sopenharmony_ci reg11 = (15 * gspca_dev->exposure->val + 999) / 1000; 7378c2ecf20Sopenharmony_ci if (reg11 < 1) 7388c2ecf20Sopenharmony_ci reg11 = 1; 7398c2ecf20Sopenharmony_ci else if (reg11 > 16) 7408c2ecf20Sopenharmony_ci reg11 = 16; 7418c2ecf20Sopenharmony_ci 7428c2ecf20Sopenharmony_ci /* In 640x480, if the reg11 has less than 4, the image is 7438c2ecf20Sopenharmony_ci unstable (the bridge goes into a higher compression mode 7448c2ecf20Sopenharmony_ci which we have not reverse engineered yet). */ 7458c2ecf20Sopenharmony_ci if (gspca_dev->pixfmt.width == 640 && reg11 < 4) 7468c2ecf20Sopenharmony_ci reg11 = 4; 7478c2ecf20Sopenharmony_ci 7488c2ecf20Sopenharmony_ci /* frame exposure time in ms = 1000 * reg11 / 30 -> 7498c2ecf20Sopenharmony_ci reg10 = (gspca_dev->exposure->val / 2) * reg10_max 7508c2ecf20Sopenharmony_ci / (1000 * reg11 / 30) */ 7518c2ecf20Sopenharmony_ci reg10 = (gspca_dev->exposure->val * 15 * reg10_max) 7528c2ecf20Sopenharmony_ci / (1000 * reg11); 7538c2ecf20Sopenharmony_ci 7548c2ecf20Sopenharmony_ci /* Don't allow this to get below 10 when using autogain, the 7558c2ecf20Sopenharmony_ci steps become very large (relatively) when below 10 causing 7568c2ecf20Sopenharmony_ci the image to oscillate from much too dark, to much too bright 7578c2ecf20Sopenharmony_ci and back again. */ 7588c2ecf20Sopenharmony_ci if (gspca_dev->autogain->val && reg10 < 10) 7598c2ecf20Sopenharmony_ci reg10 = 10; 7608c2ecf20Sopenharmony_ci else if (reg10 > reg10_max) 7618c2ecf20Sopenharmony_ci reg10 = reg10_max; 7628c2ecf20Sopenharmony_ci 7638c2ecf20Sopenharmony_ci /* Write reg 10 and reg11 low nibble */ 7648c2ecf20Sopenharmony_ci i2c[1] = sensor_data[sd->sensor].sensor_addr; 7658c2ecf20Sopenharmony_ci i2c[3] = reg10; 7668c2ecf20Sopenharmony_ci i2c[4] |= reg11 - 1; 7678c2ecf20Sopenharmony_ci 7688c2ecf20Sopenharmony_ci /* If register 11 didn't change, don't change it */ 7698c2ecf20Sopenharmony_ci if (sd->reg11 == reg11) 7708c2ecf20Sopenharmony_ci i2c[0] = 0xa0; 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2c); 7738c2ecf20Sopenharmony_ci if (gspca_dev->usb_err == 0) 7748c2ecf20Sopenharmony_ci sd->reg11 = reg11; 7758c2ecf20Sopenharmony_ci break; 7768c2ecf20Sopenharmony_ci } 7778c2ecf20Sopenharmony_ci case SENSOR_PAS202: { 7788c2ecf20Sopenharmony_ci __u8 i2cpframerate[] = 7798c2ecf20Sopenharmony_ci {0xb0, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x16}; 7808c2ecf20Sopenharmony_ci __u8 i2cpexpo[] = 7818c2ecf20Sopenharmony_ci {0xa0, 0x40, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x16}; 7828c2ecf20Sopenharmony_ci const __u8 i2cpdoit[] = 7838c2ecf20Sopenharmony_ci {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16}; 7848c2ecf20Sopenharmony_ci int framerate_ctrl; 7858c2ecf20Sopenharmony_ci 7868c2ecf20Sopenharmony_ci /* The exposure knee for the autogain algorithm is 200 7878c2ecf20Sopenharmony_ci (100 ms / 10 fps on other sensors), for values below this 7888c2ecf20Sopenharmony_ci use the control for setting the partial frame expose time, 7898c2ecf20Sopenharmony_ci above that use variable framerate. This way we run at max 7908c2ecf20Sopenharmony_ci framerate (640x480@7.5 fps, 320x240@10fps) until the knee 7918c2ecf20Sopenharmony_ci is reached. Using the variable framerate control above 200 7928c2ecf20Sopenharmony_ci is better then playing around with both clockdiv + partial 7938c2ecf20Sopenharmony_ci frame exposure times (like we are doing with the ov chips), 7948c2ecf20Sopenharmony_ci as that sometimes leads to jumps in the exposure control, 7958c2ecf20Sopenharmony_ci which are bad for auto exposure. */ 7968c2ecf20Sopenharmony_ci if (gspca_dev->exposure->val < 200) { 7978c2ecf20Sopenharmony_ci i2cpexpo[3] = 255 - (gspca_dev->exposure->val * 255) 7988c2ecf20Sopenharmony_ci / 200; 7998c2ecf20Sopenharmony_ci framerate_ctrl = 500; 8008c2ecf20Sopenharmony_ci } else { 8018c2ecf20Sopenharmony_ci /* The PAS202's exposure control goes from 0 - 4095, 8028c2ecf20Sopenharmony_ci but anything below 500 causes vsync issues, so scale 8038c2ecf20Sopenharmony_ci our 200-1023 to 500-4095 */ 8048c2ecf20Sopenharmony_ci framerate_ctrl = (gspca_dev->exposure->val - 200) 8058c2ecf20Sopenharmony_ci * 1000 / 229 + 500; 8068c2ecf20Sopenharmony_ci } 8078c2ecf20Sopenharmony_ci 8088c2ecf20Sopenharmony_ci i2cpframerate[3] = framerate_ctrl >> 6; 8098c2ecf20Sopenharmony_ci i2cpframerate[4] = framerate_ctrl & 0x3f; 8108c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2cpframerate); 8118c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2cpexpo); 8128c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2cpdoit); 8138c2ecf20Sopenharmony_ci break; 8148c2ecf20Sopenharmony_ci } 8158c2ecf20Sopenharmony_ci case SENSOR_PAS106: { 8168c2ecf20Sopenharmony_ci __u8 i2cpframerate[] = 8178c2ecf20Sopenharmony_ci {0xb1, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x14}; 8188c2ecf20Sopenharmony_ci __u8 i2cpexpo[] = 8198c2ecf20Sopenharmony_ci {0xa1, 0x40, 0x05, 0x00, 0x00, 0x00, 0x00, 0x14}; 8208c2ecf20Sopenharmony_ci const __u8 i2cpdoit[] = 8218c2ecf20Sopenharmony_ci {0xa1, 0x40, 0x13, 0x01, 0x00, 0x00, 0x00, 0x14}; 8228c2ecf20Sopenharmony_ci int framerate_ctrl; 8238c2ecf20Sopenharmony_ci 8248c2ecf20Sopenharmony_ci /* For values below 150 use partial frame exposure, above 8258c2ecf20Sopenharmony_ci that use framerate ctrl */ 8268c2ecf20Sopenharmony_ci if (gspca_dev->exposure->val < 150) { 8278c2ecf20Sopenharmony_ci i2cpexpo[3] = 150 - gspca_dev->exposure->val; 8288c2ecf20Sopenharmony_ci framerate_ctrl = 300; 8298c2ecf20Sopenharmony_ci } else { 8308c2ecf20Sopenharmony_ci /* The PAS106's exposure control goes from 0 - 4095, 8318c2ecf20Sopenharmony_ci but anything below 300 causes vsync issues, so scale 8328c2ecf20Sopenharmony_ci our 150-1023 to 300-4095 */ 8338c2ecf20Sopenharmony_ci framerate_ctrl = (gspca_dev->exposure->val - 150) 8348c2ecf20Sopenharmony_ci * 1000 / 230 + 300; 8358c2ecf20Sopenharmony_ci } 8368c2ecf20Sopenharmony_ci 8378c2ecf20Sopenharmony_ci i2cpframerate[3] = framerate_ctrl >> 4; 8388c2ecf20Sopenharmony_ci i2cpframerate[4] = framerate_ctrl & 0x0f; 8398c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2cpframerate); 8408c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2cpexpo); 8418c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2cpdoit); 8428c2ecf20Sopenharmony_ci break; 8438c2ecf20Sopenharmony_ci } 8448c2ecf20Sopenharmony_ci default: 8458c2ecf20Sopenharmony_ci break; 8468c2ecf20Sopenharmony_ci } 8478c2ecf20Sopenharmony_ci} 8488c2ecf20Sopenharmony_ci 8498c2ecf20Sopenharmony_cistatic void setfreq(struct gspca_dev *gspca_dev) 8508c2ecf20Sopenharmony_ci{ 8518c2ecf20Sopenharmony_ci struct sd *sd = (struct sd *) gspca_dev; 8528c2ecf20Sopenharmony_ci 8538c2ecf20Sopenharmony_ci if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630) { 8548c2ecf20Sopenharmony_ci /* Framerate adjust register for artificial light 50 hz flicker 8558c2ecf20Sopenharmony_ci compensation, for the ov6650 this is identical to ov6630 8568c2ecf20Sopenharmony_ci 0x2b register, see ov6630 datasheet. 8578c2ecf20Sopenharmony_ci 0x4f / 0x8a -> (30 fps -> 25 fps), 0x00 -> no adjustment */ 8588c2ecf20Sopenharmony_ci __u8 i2c[] = {0xa0, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}; 8598c2ecf20Sopenharmony_ci switch (sd->plfreq->val) { 8608c2ecf20Sopenharmony_ci default: 8618c2ecf20Sopenharmony_ci/* case 0: * no filter*/ 8628c2ecf20Sopenharmony_ci/* case 2: * 60 hz */ 8638c2ecf20Sopenharmony_ci i2c[3] = 0; 8648c2ecf20Sopenharmony_ci break; 8658c2ecf20Sopenharmony_ci case 1: /* 50 hz */ 8668c2ecf20Sopenharmony_ci i2c[3] = (sd->sensor == SENSOR_OV6650) 8678c2ecf20Sopenharmony_ci ? 0x4f : 0x8a; 8688c2ecf20Sopenharmony_ci break; 8698c2ecf20Sopenharmony_ci } 8708c2ecf20Sopenharmony_ci i2c[1] = sensor_data[sd->sensor].sensor_addr; 8718c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2c); 8728c2ecf20Sopenharmony_ci } 8738c2ecf20Sopenharmony_ci} 8748c2ecf20Sopenharmony_ci 8758c2ecf20Sopenharmony_cistatic void do_autogain(struct gspca_dev *gspca_dev) 8768c2ecf20Sopenharmony_ci{ 8778c2ecf20Sopenharmony_ci struct sd *sd = (struct sd *) gspca_dev; 8788c2ecf20Sopenharmony_ci int deadzone, desired_avg_lum, avg_lum; 8798c2ecf20Sopenharmony_ci 8808c2ecf20Sopenharmony_ci avg_lum = atomic_read(&sd->avg_lum); 8818c2ecf20Sopenharmony_ci if (avg_lum == -1) 8828c2ecf20Sopenharmony_ci return; 8838c2ecf20Sopenharmony_ci 8848c2ecf20Sopenharmony_ci if (sd->autogain_ignore_frames > 0) { 8858c2ecf20Sopenharmony_ci sd->autogain_ignore_frames--; 8868c2ecf20Sopenharmony_ci return; 8878c2ecf20Sopenharmony_ci } 8888c2ecf20Sopenharmony_ci 8898c2ecf20Sopenharmony_ci /* SIF / VGA sensors have a different autoexposure area and thus 8908c2ecf20Sopenharmony_ci different avg_lum values for the same picture brightness */ 8918c2ecf20Sopenharmony_ci if (sensor_data[sd->sensor].flags & F_SIF) { 8928c2ecf20Sopenharmony_ci deadzone = 500; 8938c2ecf20Sopenharmony_ci /* SIF sensors tend to overexpose, so keep this small */ 8948c2ecf20Sopenharmony_ci desired_avg_lum = 5000; 8958c2ecf20Sopenharmony_ci } else { 8968c2ecf20Sopenharmony_ci deadzone = 1500; 8978c2ecf20Sopenharmony_ci desired_avg_lum = 13000; 8988c2ecf20Sopenharmony_ci } 8998c2ecf20Sopenharmony_ci 9008c2ecf20Sopenharmony_ci if (sd->brightness) 9018c2ecf20Sopenharmony_ci desired_avg_lum = sd->brightness->val * desired_avg_lum / 127; 9028c2ecf20Sopenharmony_ci 9038c2ecf20Sopenharmony_ci if (gspca_dev->exposure->maximum < 500) { 9048c2ecf20Sopenharmony_ci if (gspca_coarse_grained_expo_autogain(gspca_dev, avg_lum, 9058c2ecf20Sopenharmony_ci desired_avg_lum, deadzone)) 9068c2ecf20Sopenharmony_ci sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES; 9078c2ecf20Sopenharmony_ci } else { 9088c2ecf20Sopenharmony_ci int gain_knee = (s32)gspca_dev->gain->maximum * 9 / 10; 9098c2ecf20Sopenharmony_ci if (gspca_expo_autogain(gspca_dev, avg_lum, desired_avg_lum, 9108c2ecf20Sopenharmony_ci deadzone, gain_knee, sd->exposure_knee)) 9118c2ecf20Sopenharmony_ci sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES; 9128c2ecf20Sopenharmony_ci } 9138c2ecf20Sopenharmony_ci} 9148c2ecf20Sopenharmony_ci 9158c2ecf20Sopenharmony_ci/* this function is called at probe time */ 9168c2ecf20Sopenharmony_cistatic int sd_config(struct gspca_dev *gspca_dev, 9178c2ecf20Sopenharmony_ci const struct usb_device_id *id) 9188c2ecf20Sopenharmony_ci{ 9198c2ecf20Sopenharmony_ci struct sd *sd = (struct sd *) gspca_dev; 9208c2ecf20Sopenharmony_ci struct cam *cam; 9218c2ecf20Sopenharmony_ci 9228c2ecf20Sopenharmony_ci reg_r(gspca_dev, 0x00); 9238c2ecf20Sopenharmony_ci if (gspca_dev->usb_buf[0] != 0x10) 9248c2ecf20Sopenharmony_ci return -ENODEV; 9258c2ecf20Sopenharmony_ci 9268c2ecf20Sopenharmony_ci /* copy the webcam info from the device id */ 9278c2ecf20Sopenharmony_ci sd->sensor = id->driver_info >> 8; 9288c2ecf20Sopenharmony_ci sd->bridge = id->driver_info & 0xff; 9298c2ecf20Sopenharmony_ci 9308c2ecf20Sopenharmony_ci cam = &gspca_dev->cam; 9318c2ecf20Sopenharmony_ci if (!(sensor_data[sd->sensor].flags & F_SIF)) { 9328c2ecf20Sopenharmony_ci cam->cam_mode = vga_mode; 9338c2ecf20Sopenharmony_ci cam->nmodes = ARRAY_SIZE(vga_mode); 9348c2ecf20Sopenharmony_ci } else { 9358c2ecf20Sopenharmony_ci cam->cam_mode = sif_mode; 9368c2ecf20Sopenharmony_ci cam->nmodes = ARRAY_SIZE(sif_mode); 9378c2ecf20Sopenharmony_ci } 9388c2ecf20Sopenharmony_ci cam->npkt = 36; /* 36 packets per ISOC message */ 9398c2ecf20Sopenharmony_ci 9408c2ecf20Sopenharmony_ci return 0; 9418c2ecf20Sopenharmony_ci} 9428c2ecf20Sopenharmony_ci 9438c2ecf20Sopenharmony_ci/* this function is called at probe and resume time */ 9448c2ecf20Sopenharmony_cistatic int sd_init(struct gspca_dev *gspca_dev) 9458c2ecf20Sopenharmony_ci{ 9468c2ecf20Sopenharmony_ci const __u8 stop = 0x09; /* Disable stream turn of LED */ 9478c2ecf20Sopenharmony_ci 9488c2ecf20Sopenharmony_ci reg_w(gspca_dev, 0x01, &stop, 1); 9498c2ecf20Sopenharmony_ci 9508c2ecf20Sopenharmony_ci return gspca_dev->usb_err; 9518c2ecf20Sopenharmony_ci} 9528c2ecf20Sopenharmony_ci 9538c2ecf20Sopenharmony_cistatic int sd_s_ctrl(struct v4l2_ctrl *ctrl) 9548c2ecf20Sopenharmony_ci{ 9558c2ecf20Sopenharmony_ci struct gspca_dev *gspca_dev = 9568c2ecf20Sopenharmony_ci container_of(ctrl->handler, struct gspca_dev, ctrl_handler); 9578c2ecf20Sopenharmony_ci struct sd *sd = (struct sd *)gspca_dev; 9588c2ecf20Sopenharmony_ci 9598c2ecf20Sopenharmony_ci gspca_dev->usb_err = 0; 9608c2ecf20Sopenharmony_ci 9618c2ecf20Sopenharmony_ci if (ctrl->id == V4L2_CID_AUTOGAIN && ctrl->is_new && ctrl->val) { 9628c2ecf20Sopenharmony_ci /* when switching to autogain set defaults to make sure 9638c2ecf20Sopenharmony_ci we are on a valid point of the autogain gain / 9648c2ecf20Sopenharmony_ci exposure knee graph, and give this change time to 9658c2ecf20Sopenharmony_ci take effect before doing autogain. */ 9668c2ecf20Sopenharmony_ci gspca_dev->gain->val = gspca_dev->gain->default_value; 9678c2ecf20Sopenharmony_ci gspca_dev->exposure->val = gspca_dev->exposure->default_value; 9688c2ecf20Sopenharmony_ci sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES; 9698c2ecf20Sopenharmony_ci } 9708c2ecf20Sopenharmony_ci 9718c2ecf20Sopenharmony_ci if (!gspca_dev->streaming) 9728c2ecf20Sopenharmony_ci return 0; 9738c2ecf20Sopenharmony_ci 9748c2ecf20Sopenharmony_ci switch (ctrl->id) { 9758c2ecf20Sopenharmony_ci case V4L2_CID_BRIGHTNESS: 9768c2ecf20Sopenharmony_ci setbrightness(gspca_dev); 9778c2ecf20Sopenharmony_ci break; 9788c2ecf20Sopenharmony_ci case V4L2_CID_AUTOGAIN: 9798c2ecf20Sopenharmony_ci if (gspca_dev->exposure->is_new || (ctrl->is_new && ctrl->val)) 9808c2ecf20Sopenharmony_ci setexposure(gspca_dev); 9818c2ecf20Sopenharmony_ci if (gspca_dev->gain->is_new || (ctrl->is_new && ctrl->val)) 9828c2ecf20Sopenharmony_ci setgain(gspca_dev); 9838c2ecf20Sopenharmony_ci break; 9848c2ecf20Sopenharmony_ci case V4L2_CID_POWER_LINE_FREQUENCY: 9858c2ecf20Sopenharmony_ci setfreq(gspca_dev); 9868c2ecf20Sopenharmony_ci break; 9878c2ecf20Sopenharmony_ci default: 9888c2ecf20Sopenharmony_ci return -EINVAL; 9898c2ecf20Sopenharmony_ci } 9908c2ecf20Sopenharmony_ci return gspca_dev->usb_err; 9918c2ecf20Sopenharmony_ci} 9928c2ecf20Sopenharmony_ci 9938c2ecf20Sopenharmony_cistatic const struct v4l2_ctrl_ops sd_ctrl_ops = { 9948c2ecf20Sopenharmony_ci .s_ctrl = sd_s_ctrl, 9958c2ecf20Sopenharmony_ci}; 9968c2ecf20Sopenharmony_ci 9978c2ecf20Sopenharmony_ci/* this function is called at probe time */ 9988c2ecf20Sopenharmony_cistatic int sd_init_controls(struct gspca_dev *gspca_dev) 9998c2ecf20Sopenharmony_ci{ 10008c2ecf20Sopenharmony_ci struct sd *sd = (struct sd *) gspca_dev; 10018c2ecf20Sopenharmony_ci struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; 10028c2ecf20Sopenharmony_ci 10038c2ecf20Sopenharmony_ci gspca_dev->vdev.ctrl_handler = hdl; 10048c2ecf20Sopenharmony_ci v4l2_ctrl_handler_init(hdl, 5); 10058c2ecf20Sopenharmony_ci 10068c2ecf20Sopenharmony_ci if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630 || 10078c2ecf20Sopenharmony_ci sd->sensor == SENSOR_PAS106 || sd->sensor == SENSOR_PAS202) 10088c2ecf20Sopenharmony_ci sd->brightness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, 10098c2ecf20Sopenharmony_ci V4L2_CID_BRIGHTNESS, 0, 255, 1, 127); 10108c2ecf20Sopenharmony_ci 10118c2ecf20Sopenharmony_ci /* Gain range is sensor dependent */ 10128c2ecf20Sopenharmony_ci switch (sd->sensor) { 10138c2ecf20Sopenharmony_ci case SENSOR_OV6650: 10148c2ecf20Sopenharmony_ci case SENSOR_PAS106: 10158c2ecf20Sopenharmony_ci case SENSOR_PAS202: 10168c2ecf20Sopenharmony_ci gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, 10178c2ecf20Sopenharmony_ci V4L2_CID_GAIN, 0, 31, 1, 15); 10188c2ecf20Sopenharmony_ci break; 10198c2ecf20Sopenharmony_ci case SENSOR_OV7630: 10208c2ecf20Sopenharmony_ci gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, 10218c2ecf20Sopenharmony_ci V4L2_CID_GAIN, 0, 47, 1, 31); 10228c2ecf20Sopenharmony_ci break; 10238c2ecf20Sopenharmony_ci case SENSOR_HV7131D: 10248c2ecf20Sopenharmony_ci gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, 10258c2ecf20Sopenharmony_ci V4L2_CID_GAIN, 0, 63, 1, 31); 10268c2ecf20Sopenharmony_ci break; 10278c2ecf20Sopenharmony_ci case SENSOR_TAS5110C: 10288c2ecf20Sopenharmony_ci case SENSOR_TAS5110D: 10298c2ecf20Sopenharmony_ci case SENSOR_TAS5130CXX: 10308c2ecf20Sopenharmony_ci gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, 10318c2ecf20Sopenharmony_ci V4L2_CID_GAIN, 0, 255, 1, 127); 10328c2ecf20Sopenharmony_ci break; 10338c2ecf20Sopenharmony_ci default: 10348c2ecf20Sopenharmony_ci if (sd->bridge == BRIDGE_103) { 10358c2ecf20Sopenharmony_ci gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, 10368c2ecf20Sopenharmony_ci V4L2_CID_GAIN, 0, 127, 1, 63); 10378c2ecf20Sopenharmony_ci } else { 10388c2ecf20Sopenharmony_ci gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, 10398c2ecf20Sopenharmony_ci V4L2_CID_GAIN, 0, 15, 1, 7); 10408c2ecf20Sopenharmony_ci } 10418c2ecf20Sopenharmony_ci } 10428c2ecf20Sopenharmony_ci 10438c2ecf20Sopenharmony_ci /* Exposure range is sensor dependent, and not all have exposure */ 10448c2ecf20Sopenharmony_ci switch (sd->sensor) { 10458c2ecf20Sopenharmony_ci case SENSOR_HV7131D: 10468c2ecf20Sopenharmony_ci gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, 10478c2ecf20Sopenharmony_ci V4L2_CID_EXPOSURE, 0, 8191, 1, 482); 10488c2ecf20Sopenharmony_ci sd->exposure_knee = 964; 10498c2ecf20Sopenharmony_ci break; 10508c2ecf20Sopenharmony_ci case SENSOR_OV6650: 10518c2ecf20Sopenharmony_ci case SENSOR_OV7630: 10528c2ecf20Sopenharmony_ci case SENSOR_PAS106: 10538c2ecf20Sopenharmony_ci case SENSOR_PAS202: 10548c2ecf20Sopenharmony_ci gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, 10558c2ecf20Sopenharmony_ci V4L2_CID_EXPOSURE, 0, 1023, 1, 66); 10568c2ecf20Sopenharmony_ci sd->exposure_knee = 200; 10578c2ecf20Sopenharmony_ci break; 10588c2ecf20Sopenharmony_ci case SENSOR_TAS5110C: 10598c2ecf20Sopenharmony_ci case SENSOR_TAS5110D: 10608c2ecf20Sopenharmony_ci gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, 10618c2ecf20Sopenharmony_ci V4L2_CID_EXPOSURE, 2, 15, 1, 2); 10628c2ecf20Sopenharmony_ci break; 10638c2ecf20Sopenharmony_ci } 10648c2ecf20Sopenharmony_ci 10658c2ecf20Sopenharmony_ci if (gspca_dev->exposure) { 10668c2ecf20Sopenharmony_ci gspca_dev->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, 10678c2ecf20Sopenharmony_ci V4L2_CID_AUTOGAIN, 0, 1, 1, 1); 10688c2ecf20Sopenharmony_ci } 10698c2ecf20Sopenharmony_ci 10708c2ecf20Sopenharmony_ci if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630) 10718c2ecf20Sopenharmony_ci sd->plfreq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops, 10728c2ecf20Sopenharmony_ci V4L2_CID_POWER_LINE_FREQUENCY, 10738c2ecf20Sopenharmony_ci V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0, 10748c2ecf20Sopenharmony_ci V4L2_CID_POWER_LINE_FREQUENCY_DISABLED); 10758c2ecf20Sopenharmony_ci 10768c2ecf20Sopenharmony_ci if (hdl->error) { 10778c2ecf20Sopenharmony_ci pr_err("Could not initialize controls\n"); 10788c2ecf20Sopenharmony_ci return hdl->error; 10798c2ecf20Sopenharmony_ci } 10808c2ecf20Sopenharmony_ci 10818c2ecf20Sopenharmony_ci if (gspca_dev->autogain) 10828c2ecf20Sopenharmony_ci v4l2_ctrl_auto_cluster(3, &gspca_dev->autogain, 0, false); 10838c2ecf20Sopenharmony_ci 10848c2ecf20Sopenharmony_ci return 0; 10858c2ecf20Sopenharmony_ci} 10868c2ecf20Sopenharmony_ci 10878c2ecf20Sopenharmony_ci/* -- start the camera -- */ 10888c2ecf20Sopenharmony_cistatic int sd_start(struct gspca_dev *gspca_dev) 10898c2ecf20Sopenharmony_ci{ 10908c2ecf20Sopenharmony_ci struct sd *sd = (struct sd *) gspca_dev; 10918c2ecf20Sopenharmony_ci struct cam *cam = &gspca_dev->cam; 10928c2ecf20Sopenharmony_ci int i, mode; 10938c2ecf20Sopenharmony_ci __u8 regs[0x31]; 10948c2ecf20Sopenharmony_ci 10958c2ecf20Sopenharmony_ci mode = cam->cam_mode[gspca_dev->curr_mode].priv & 0x07; 10968c2ecf20Sopenharmony_ci /* Copy registers 0x01 - 0x19 from the template */ 10978c2ecf20Sopenharmony_ci memcpy(®s[0x01], sensor_data[sd->sensor].bridge_init, 0x19); 10988c2ecf20Sopenharmony_ci /* Set the mode */ 10998c2ecf20Sopenharmony_ci regs[0x18] |= mode << 4; 11008c2ecf20Sopenharmony_ci 11018c2ecf20Sopenharmony_ci /* Set bridge gain to 1.0 */ 11028c2ecf20Sopenharmony_ci if (sd->bridge == BRIDGE_103) { 11038c2ecf20Sopenharmony_ci regs[0x05] = 0x20; /* Red */ 11048c2ecf20Sopenharmony_ci regs[0x06] = 0x20; /* Green */ 11058c2ecf20Sopenharmony_ci regs[0x07] = 0x20; /* Blue */ 11068c2ecf20Sopenharmony_ci } else { 11078c2ecf20Sopenharmony_ci regs[0x10] = 0x00; /* Red and blue */ 11088c2ecf20Sopenharmony_ci regs[0x11] = 0x00; /* Green */ 11098c2ecf20Sopenharmony_ci } 11108c2ecf20Sopenharmony_ci 11118c2ecf20Sopenharmony_ci /* Setup pixel numbers and auto exposure window */ 11128c2ecf20Sopenharmony_ci if (sensor_data[sd->sensor].flags & F_SIF) { 11138c2ecf20Sopenharmony_ci regs[0x1a] = 0x14; /* HO_SIZE 640, makes no sense */ 11148c2ecf20Sopenharmony_ci regs[0x1b] = 0x0a; /* VO_SIZE 320, makes no sense */ 11158c2ecf20Sopenharmony_ci regs[0x1c] = 0x02; /* AE H-start 64 */ 11168c2ecf20Sopenharmony_ci regs[0x1d] = 0x02; /* AE V-start 64 */ 11178c2ecf20Sopenharmony_ci regs[0x1e] = 0x09; /* AE H-end 288 */ 11188c2ecf20Sopenharmony_ci regs[0x1f] = 0x07; /* AE V-end 224 */ 11198c2ecf20Sopenharmony_ci } else { 11208c2ecf20Sopenharmony_ci regs[0x1a] = 0x1d; /* HO_SIZE 960, makes no sense */ 11218c2ecf20Sopenharmony_ci regs[0x1b] = 0x10; /* VO_SIZE 512, makes no sense */ 11228c2ecf20Sopenharmony_ci regs[0x1c] = 0x05; /* AE H-start 160 */ 11238c2ecf20Sopenharmony_ci regs[0x1d] = 0x03; /* AE V-start 96 */ 11248c2ecf20Sopenharmony_ci regs[0x1e] = 0x0f; /* AE H-end 480 */ 11258c2ecf20Sopenharmony_ci regs[0x1f] = 0x0c; /* AE V-end 384 */ 11268c2ecf20Sopenharmony_ci } 11278c2ecf20Sopenharmony_ci 11288c2ecf20Sopenharmony_ci /* Setup the gamma table (only used with the sn9c103 bridge) */ 11298c2ecf20Sopenharmony_ci for (i = 0; i < 16; i++) 11308c2ecf20Sopenharmony_ci regs[0x20 + i] = i * 16; 11318c2ecf20Sopenharmony_ci regs[0x20 + i] = 255; 11328c2ecf20Sopenharmony_ci 11338c2ecf20Sopenharmony_ci /* Special cases where some regs depend on mode or bridge */ 11348c2ecf20Sopenharmony_ci switch (sd->sensor) { 11358c2ecf20Sopenharmony_ci case SENSOR_TAS5130CXX: 11368c2ecf20Sopenharmony_ci /* FIXME / TESTME 11378c2ecf20Sopenharmony_ci probably not mode specific at all most likely the upper 11388c2ecf20Sopenharmony_ci nibble of 0x19 is exposure (clock divider) just as with 11398c2ecf20Sopenharmony_ci the tas5110, we need someone to test this. */ 11408c2ecf20Sopenharmony_ci regs[0x19] = mode ? 0x23 : 0x43; 11418c2ecf20Sopenharmony_ci break; 11428c2ecf20Sopenharmony_ci case SENSOR_OV7630: 11438c2ecf20Sopenharmony_ci /* FIXME / TESTME for some reason with the 101/102 bridge the 11448c2ecf20Sopenharmony_ci clock is set to 12 Mhz (reg1 == 0x04), rather then 24. 11458c2ecf20Sopenharmony_ci Also the hstart needs to go from 1 to 2 when using a 103, 11468c2ecf20Sopenharmony_ci which is likely related. This does not seem right. */ 11478c2ecf20Sopenharmony_ci if (sd->bridge == BRIDGE_103) { 11488c2ecf20Sopenharmony_ci regs[0x01] = 0x44; /* Select 24 Mhz clock */ 11498c2ecf20Sopenharmony_ci regs[0x12] = 0x02; /* Set hstart to 2 */ 11508c2ecf20Sopenharmony_ci } 11518c2ecf20Sopenharmony_ci break; 11528c2ecf20Sopenharmony_ci case SENSOR_PAS202: 11538c2ecf20Sopenharmony_ci /* For some unknown reason we need to increase hstart by 1 on 11548c2ecf20Sopenharmony_ci the sn9c103, otherwise we get wrong colors (bayer shift). */ 11558c2ecf20Sopenharmony_ci if (sd->bridge == BRIDGE_103) 11568c2ecf20Sopenharmony_ci regs[0x12] += 1; 11578c2ecf20Sopenharmony_ci break; 11588c2ecf20Sopenharmony_ci } 11598c2ecf20Sopenharmony_ci /* Disable compression when the raw bayer format has been selected */ 11608c2ecf20Sopenharmony_ci if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW) 11618c2ecf20Sopenharmony_ci regs[0x18] &= ~0x80; 11628c2ecf20Sopenharmony_ci 11638c2ecf20Sopenharmony_ci /* Vga mode emulation on SIF sensor? */ 11648c2ecf20Sopenharmony_ci if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_REDUCED_SIF) { 11658c2ecf20Sopenharmony_ci regs[0x12] += 16; /* hstart adjust */ 11668c2ecf20Sopenharmony_ci regs[0x13] += 24; /* vstart adjust */ 11678c2ecf20Sopenharmony_ci regs[0x15] = 320 / 16; /* hsize */ 11688c2ecf20Sopenharmony_ci regs[0x16] = 240 / 16; /* vsize */ 11698c2ecf20Sopenharmony_ci } 11708c2ecf20Sopenharmony_ci 11718c2ecf20Sopenharmony_ci /* reg 0x01 bit 2 video transfert on */ 11728c2ecf20Sopenharmony_ci reg_w(gspca_dev, 0x01, ®s[0x01], 1); 11738c2ecf20Sopenharmony_ci /* reg 0x17 SensorClk enable inv Clk 0x60 */ 11748c2ecf20Sopenharmony_ci reg_w(gspca_dev, 0x17, ®s[0x17], 1); 11758c2ecf20Sopenharmony_ci /* Set the registers from the template */ 11768c2ecf20Sopenharmony_ci reg_w(gspca_dev, 0x01, ®s[0x01], 11778c2ecf20Sopenharmony_ci (sd->bridge == BRIDGE_103) ? 0x30 : 0x1f); 11788c2ecf20Sopenharmony_ci 11798c2ecf20Sopenharmony_ci /* Init the sensor */ 11808c2ecf20Sopenharmony_ci i2c_w_vector(gspca_dev, sensor_data[sd->sensor].sensor_init, 11818c2ecf20Sopenharmony_ci sensor_data[sd->sensor].sensor_init_size); 11828c2ecf20Sopenharmony_ci 11838c2ecf20Sopenharmony_ci /* Mode / bridge specific sensor setup */ 11848c2ecf20Sopenharmony_ci switch (sd->sensor) { 11858c2ecf20Sopenharmony_ci case SENSOR_PAS202: { 11868c2ecf20Sopenharmony_ci const __u8 i2cpclockdiv[] = 11878c2ecf20Sopenharmony_ci {0xa0, 0x40, 0x02, 0x03, 0x00, 0x00, 0x00, 0x10}; 11888c2ecf20Sopenharmony_ci /* clockdiv from 4 to 3 (7.5 -> 10 fps) when in low res mode */ 11898c2ecf20Sopenharmony_ci if (mode) 11908c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2cpclockdiv); 11918c2ecf20Sopenharmony_ci break; 11928c2ecf20Sopenharmony_ci } 11938c2ecf20Sopenharmony_ci case SENSOR_OV7630: 11948c2ecf20Sopenharmony_ci /* FIXME / TESTME We should be able to handle this identical 11958c2ecf20Sopenharmony_ci for the 101/102 and the 103 case */ 11968c2ecf20Sopenharmony_ci if (sd->bridge == BRIDGE_103) { 11978c2ecf20Sopenharmony_ci const __u8 i2c[] = { 0xa0, 0x21, 0x13, 11988c2ecf20Sopenharmony_ci 0x80, 0x00, 0x00, 0x00, 0x10 }; 11998c2ecf20Sopenharmony_ci i2c_w(gspca_dev, i2c); 12008c2ecf20Sopenharmony_ci } 12018c2ecf20Sopenharmony_ci break; 12028c2ecf20Sopenharmony_ci } 12038c2ecf20Sopenharmony_ci /* H_size V_size 0x28, 0x1e -> 640x480. 0x16, 0x12 -> 352x288 */ 12048c2ecf20Sopenharmony_ci reg_w(gspca_dev, 0x15, ®s[0x15], 2); 12058c2ecf20Sopenharmony_ci /* compression register */ 12068c2ecf20Sopenharmony_ci reg_w(gspca_dev, 0x18, ®s[0x18], 1); 12078c2ecf20Sopenharmony_ci /* H_start */ 12088c2ecf20Sopenharmony_ci reg_w(gspca_dev, 0x12, ®s[0x12], 1); 12098c2ecf20Sopenharmony_ci /* V_START */ 12108c2ecf20Sopenharmony_ci reg_w(gspca_dev, 0x13, ®s[0x13], 1); 12118c2ecf20Sopenharmony_ci /* reset 0x17 SensorClk enable inv Clk 0x60 */ 12128c2ecf20Sopenharmony_ci /*fixme: ov7630 [17]=68 8f (+20 if 102)*/ 12138c2ecf20Sopenharmony_ci reg_w(gspca_dev, 0x17, ®s[0x17], 1); 12148c2ecf20Sopenharmony_ci /*MCKSIZE ->3 */ /*fixme: not ov7630*/ 12158c2ecf20Sopenharmony_ci reg_w(gspca_dev, 0x19, ®s[0x19], 1); 12168c2ecf20Sopenharmony_ci /* AE_STRX AE_STRY AE_ENDX AE_ENDY */ 12178c2ecf20Sopenharmony_ci reg_w(gspca_dev, 0x1c, ®s[0x1c], 4); 12188c2ecf20Sopenharmony_ci /* Enable video transfert */ 12198c2ecf20Sopenharmony_ci reg_w(gspca_dev, 0x01, ®s[0x01], 1); 12208c2ecf20Sopenharmony_ci /* Compression */ 12218c2ecf20Sopenharmony_ci reg_w(gspca_dev, 0x18, ®s[0x18], 2); 12228c2ecf20Sopenharmony_ci msleep(20); 12238c2ecf20Sopenharmony_ci 12248c2ecf20Sopenharmony_ci sd->reg11 = -1; 12258c2ecf20Sopenharmony_ci 12268c2ecf20Sopenharmony_ci setgain(gspca_dev); 12278c2ecf20Sopenharmony_ci setbrightness(gspca_dev); 12288c2ecf20Sopenharmony_ci setexposure(gspca_dev); 12298c2ecf20Sopenharmony_ci setfreq(gspca_dev); 12308c2ecf20Sopenharmony_ci 12318c2ecf20Sopenharmony_ci sd->frames_to_drop = 0; 12328c2ecf20Sopenharmony_ci sd->autogain_ignore_frames = 0; 12338c2ecf20Sopenharmony_ci gspca_dev->exp_too_high_cnt = 0; 12348c2ecf20Sopenharmony_ci gspca_dev->exp_too_low_cnt = 0; 12358c2ecf20Sopenharmony_ci atomic_set(&sd->avg_lum, -1); 12368c2ecf20Sopenharmony_ci return gspca_dev->usb_err; 12378c2ecf20Sopenharmony_ci} 12388c2ecf20Sopenharmony_ci 12398c2ecf20Sopenharmony_cistatic void sd_stopN(struct gspca_dev *gspca_dev) 12408c2ecf20Sopenharmony_ci{ 12418c2ecf20Sopenharmony_ci sd_init(gspca_dev); 12428c2ecf20Sopenharmony_ci} 12438c2ecf20Sopenharmony_ci 12448c2ecf20Sopenharmony_cistatic u8* find_sof(struct gspca_dev *gspca_dev, u8 *data, int len) 12458c2ecf20Sopenharmony_ci{ 12468c2ecf20Sopenharmony_ci struct sd *sd = (struct sd *) gspca_dev; 12478c2ecf20Sopenharmony_ci int i, header_size = (sd->bridge == BRIDGE_103) ? 18 : 12; 12488c2ecf20Sopenharmony_ci 12498c2ecf20Sopenharmony_ci /* frames start with: 12508c2ecf20Sopenharmony_ci * ff ff 00 c4 c4 96 synchro 12518c2ecf20Sopenharmony_ci * 00 (unknown) 12528c2ecf20Sopenharmony_ci * xx (frame sequence / size / compression) 12538c2ecf20Sopenharmony_ci * (xx) (idem - extra byte for sn9c103) 12548c2ecf20Sopenharmony_ci * ll mm brightness sum inside auto exposure 12558c2ecf20Sopenharmony_ci * ll mm brightness sum outside auto exposure 12568c2ecf20Sopenharmony_ci * (xx xx xx xx xx) audio values for snc103 12578c2ecf20Sopenharmony_ci */ 12588c2ecf20Sopenharmony_ci for (i = 0; i < len; i++) { 12598c2ecf20Sopenharmony_ci switch (sd->header_read) { 12608c2ecf20Sopenharmony_ci case 0: 12618c2ecf20Sopenharmony_ci if (data[i] == 0xff) 12628c2ecf20Sopenharmony_ci sd->header_read++; 12638c2ecf20Sopenharmony_ci break; 12648c2ecf20Sopenharmony_ci case 1: 12658c2ecf20Sopenharmony_ci if (data[i] == 0xff) 12668c2ecf20Sopenharmony_ci sd->header_read++; 12678c2ecf20Sopenharmony_ci else 12688c2ecf20Sopenharmony_ci sd->header_read = 0; 12698c2ecf20Sopenharmony_ci break; 12708c2ecf20Sopenharmony_ci case 2: 12718c2ecf20Sopenharmony_ci if (data[i] == 0x00) 12728c2ecf20Sopenharmony_ci sd->header_read++; 12738c2ecf20Sopenharmony_ci else if (data[i] != 0xff) 12748c2ecf20Sopenharmony_ci sd->header_read = 0; 12758c2ecf20Sopenharmony_ci break; 12768c2ecf20Sopenharmony_ci case 3: 12778c2ecf20Sopenharmony_ci if (data[i] == 0xc4) 12788c2ecf20Sopenharmony_ci sd->header_read++; 12798c2ecf20Sopenharmony_ci else if (data[i] == 0xff) 12808c2ecf20Sopenharmony_ci sd->header_read = 1; 12818c2ecf20Sopenharmony_ci else 12828c2ecf20Sopenharmony_ci sd->header_read = 0; 12838c2ecf20Sopenharmony_ci break; 12848c2ecf20Sopenharmony_ci case 4: 12858c2ecf20Sopenharmony_ci if (data[i] == 0xc4) 12868c2ecf20Sopenharmony_ci sd->header_read++; 12878c2ecf20Sopenharmony_ci else if (data[i] == 0xff) 12888c2ecf20Sopenharmony_ci sd->header_read = 1; 12898c2ecf20Sopenharmony_ci else 12908c2ecf20Sopenharmony_ci sd->header_read = 0; 12918c2ecf20Sopenharmony_ci break; 12928c2ecf20Sopenharmony_ci case 5: 12938c2ecf20Sopenharmony_ci if (data[i] == 0x96) 12948c2ecf20Sopenharmony_ci sd->header_read++; 12958c2ecf20Sopenharmony_ci else if (data[i] == 0xff) 12968c2ecf20Sopenharmony_ci sd->header_read = 1; 12978c2ecf20Sopenharmony_ci else 12988c2ecf20Sopenharmony_ci sd->header_read = 0; 12998c2ecf20Sopenharmony_ci break; 13008c2ecf20Sopenharmony_ci default: 13018c2ecf20Sopenharmony_ci sd->header[sd->header_read - 6] = data[i]; 13028c2ecf20Sopenharmony_ci sd->header_read++; 13038c2ecf20Sopenharmony_ci if (sd->header_read == header_size) { 13048c2ecf20Sopenharmony_ci sd->header_read = 0; 13058c2ecf20Sopenharmony_ci return data + i + 1; 13068c2ecf20Sopenharmony_ci } 13078c2ecf20Sopenharmony_ci } 13088c2ecf20Sopenharmony_ci } 13098c2ecf20Sopenharmony_ci return NULL; 13108c2ecf20Sopenharmony_ci} 13118c2ecf20Sopenharmony_ci 13128c2ecf20Sopenharmony_cistatic void sd_pkt_scan(struct gspca_dev *gspca_dev, 13138c2ecf20Sopenharmony_ci u8 *data, /* isoc packet */ 13148c2ecf20Sopenharmony_ci int len) /* iso packet length */ 13158c2ecf20Sopenharmony_ci{ 13168c2ecf20Sopenharmony_ci int fr_h_sz = 0, lum_offset = 0, len_after_sof = 0; 13178c2ecf20Sopenharmony_ci struct sd *sd = (struct sd *) gspca_dev; 13188c2ecf20Sopenharmony_ci struct cam *cam = &gspca_dev->cam; 13198c2ecf20Sopenharmony_ci u8 *sof; 13208c2ecf20Sopenharmony_ci 13218c2ecf20Sopenharmony_ci sof = find_sof(gspca_dev, data, len); 13228c2ecf20Sopenharmony_ci if (sof) { 13238c2ecf20Sopenharmony_ci if (sd->bridge == BRIDGE_103) { 13248c2ecf20Sopenharmony_ci fr_h_sz = 18; 13258c2ecf20Sopenharmony_ci lum_offset = 3; 13268c2ecf20Sopenharmony_ci } else { 13278c2ecf20Sopenharmony_ci fr_h_sz = 12; 13288c2ecf20Sopenharmony_ci lum_offset = 2; 13298c2ecf20Sopenharmony_ci } 13308c2ecf20Sopenharmony_ci 13318c2ecf20Sopenharmony_ci len_after_sof = len - (sof - data); 13328c2ecf20Sopenharmony_ci len = (sof - data) - fr_h_sz; 13338c2ecf20Sopenharmony_ci if (len < 0) 13348c2ecf20Sopenharmony_ci len = 0; 13358c2ecf20Sopenharmony_ci } 13368c2ecf20Sopenharmony_ci 13378c2ecf20Sopenharmony_ci if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW) { 13388c2ecf20Sopenharmony_ci /* In raw mode we sometimes get some garbage after the frame 13398c2ecf20Sopenharmony_ci ignore this */ 13408c2ecf20Sopenharmony_ci int used; 13418c2ecf20Sopenharmony_ci int size = cam->cam_mode[gspca_dev->curr_mode].sizeimage; 13428c2ecf20Sopenharmony_ci 13438c2ecf20Sopenharmony_ci used = gspca_dev->image_len; 13448c2ecf20Sopenharmony_ci if (used + len > size) 13458c2ecf20Sopenharmony_ci len = size - used; 13468c2ecf20Sopenharmony_ci } 13478c2ecf20Sopenharmony_ci 13488c2ecf20Sopenharmony_ci gspca_frame_add(gspca_dev, INTER_PACKET, data, len); 13498c2ecf20Sopenharmony_ci 13508c2ecf20Sopenharmony_ci if (sof) { 13518c2ecf20Sopenharmony_ci int lum = sd->header[lum_offset] + 13528c2ecf20Sopenharmony_ci (sd->header[lum_offset + 1] << 8); 13538c2ecf20Sopenharmony_ci 13548c2ecf20Sopenharmony_ci /* When exposure changes midway a frame we 13558c2ecf20Sopenharmony_ci get a lum of 0 in this case drop 2 frames 13568c2ecf20Sopenharmony_ci as the frames directly after an exposure 13578c2ecf20Sopenharmony_ci change have an unstable image. Sometimes lum 13588c2ecf20Sopenharmony_ci *really* is 0 (cam used in low light with 13598c2ecf20Sopenharmony_ci low exposure setting), so do not drop frames 13608c2ecf20Sopenharmony_ci if the previous lum was 0 too. */ 13618c2ecf20Sopenharmony_ci if (lum == 0 && sd->prev_avg_lum != 0) { 13628c2ecf20Sopenharmony_ci lum = -1; 13638c2ecf20Sopenharmony_ci sd->frames_to_drop = 2; 13648c2ecf20Sopenharmony_ci sd->prev_avg_lum = 0; 13658c2ecf20Sopenharmony_ci } else 13668c2ecf20Sopenharmony_ci sd->prev_avg_lum = lum; 13678c2ecf20Sopenharmony_ci atomic_set(&sd->avg_lum, lum); 13688c2ecf20Sopenharmony_ci 13698c2ecf20Sopenharmony_ci if (sd->frames_to_drop) 13708c2ecf20Sopenharmony_ci sd->frames_to_drop--; 13718c2ecf20Sopenharmony_ci else 13728c2ecf20Sopenharmony_ci gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0); 13738c2ecf20Sopenharmony_ci 13748c2ecf20Sopenharmony_ci gspca_frame_add(gspca_dev, FIRST_PACKET, sof, len_after_sof); 13758c2ecf20Sopenharmony_ci } 13768c2ecf20Sopenharmony_ci} 13778c2ecf20Sopenharmony_ci 13788c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_INPUT) 13798c2ecf20Sopenharmony_cistatic int sd_int_pkt_scan(struct gspca_dev *gspca_dev, 13808c2ecf20Sopenharmony_ci u8 *data, /* interrupt packet data */ 13818c2ecf20Sopenharmony_ci int len) /* interrupt packet length */ 13828c2ecf20Sopenharmony_ci{ 13838c2ecf20Sopenharmony_ci int ret = -EINVAL; 13848c2ecf20Sopenharmony_ci 13858c2ecf20Sopenharmony_ci if (len == 1 && data[0] == 1) { 13868c2ecf20Sopenharmony_ci input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1); 13878c2ecf20Sopenharmony_ci input_sync(gspca_dev->input_dev); 13888c2ecf20Sopenharmony_ci input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); 13898c2ecf20Sopenharmony_ci input_sync(gspca_dev->input_dev); 13908c2ecf20Sopenharmony_ci ret = 0; 13918c2ecf20Sopenharmony_ci } 13928c2ecf20Sopenharmony_ci 13938c2ecf20Sopenharmony_ci return ret; 13948c2ecf20Sopenharmony_ci} 13958c2ecf20Sopenharmony_ci#endif 13968c2ecf20Sopenharmony_ci 13978c2ecf20Sopenharmony_ci/* sub-driver description */ 13988c2ecf20Sopenharmony_cistatic const struct sd_desc sd_desc = { 13998c2ecf20Sopenharmony_ci .name = MODULE_NAME, 14008c2ecf20Sopenharmony_ci .config = sd_config, 14018c2ecf20Sopenharmony_ci .init = sd_init, 14028c2ecf20Sopenharmony_ci .init_controls = sd_init_controls, 14038c2ecf20Sopenharmony_ci .start = sd_start, 14048c2ecf20Sopenharmony_ci .stopN = sd_stopN, 14058c2ecf20Sopenharmony_ci .pkt_scan = sd_pkt_scan, 14068c2ecf20Sopenharmony_ci .dq_callback = do_autogain, 14078c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_INPUT) 14088c2ecf20Sopenharmony_ci .int_pkt_scan = sd_int_pkt_scan, 14098c2ecf20Sopenharmony_ci#endif 14108c2ecf20Sopenharmony_ci}; 14118c2ecf20Sopenharmony_ci 14128c2ecf20Sopenharmony_ci/* -- module initialisation -- */ 14138c2ecf20Sopenharmony_ci#define SB(sensor, bridge) \ 14148c2ecf20Sopenharmony_ci .driver_info = (SENSOR_ ## sensor << 8) | BRIDGE_ ## bridge 14158c2ecf20Sopenharmony_ci 14168c2ecf20Sopenharmony_ci 14178c2ecf20Sopenharmony_cistatic const struct usb_device_id device_table[] = { 14188c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x6001), SB(TAS5110C, 102)}, /* TAS5110C1B */ 14198c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x6005), SB(TAS5110C, 101)}, /* TAS5110C1B */ 14208c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x6007), SB(TAS5110D, 101)}, /* TAS5110D */ 14218c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x6009), SB(PAS106, 101)}, 14228c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x600d), SB(PAS106, 101)}, 14238c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x6011), SB(OV6650, 101)}, 14248c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x6019), SB(OV7630, 101)}, 14258c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x6024), SB(TAS5130CXX, 102)}, 14268c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x6025), SB(TAS5130CXX, 102)}, 14278c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x6027), SB(OV7630, 101)}, /* Genius Eye 310 */ 14288c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x6028), SB(PAS202, 102)}, 14298c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x6029), SB(PAS106, 102)}, 14308c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x602a), SB(HV7131D, 102)}, 14318c2ecf20Sopenharmony_ci /* {USB_DEVICE(0x0c45, 0x602b), SB(MI0343, 102)}, */ 14328c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x602c), SB(OV7630, 102)}, 14338c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x602d), SB(HV7131R, 102)}, 14348c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x602e), SB(OV7630, 102)}, 14358c2ecf20Sopenharmony_ci /* {USB_DEVICE(0x0c45, 0x6030), SB(MI03XX, 102)}, */ /* MI0343 MI0360 MI0330 */ 14368c2ecf20Sopenharmony_ci /* {USB_DEVICE(0x0c45, 0x6082), SB(MI03XX, 103)}, */ /* MI0343 MI0360 */ 14378c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x6083), SB(HV7131D, 103)}, 14388c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x608c), SB(HV7131R, 103)}, 14398c2ecf20Sopenharmony_ci /* {USB_DEVICE(0x0c45, 0x608e), SB(CISVF10, 103)}, */ 14408c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x608f), SB(OV7630, 103)}, 14418c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x60a8), SB(PAS106, 103)}, 14428c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x60aa), SB(TAS5130CXX, 103)}, 14438c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x60af), SB(PAS202, 103)}, 14448c2ecf20Sopenharmony_ci {USB_DEVICE(0x0c45, 0x60b0), SB(OV7630, 103)}, 14458c2ecf20Sopenharmony_ci {} 14468c2ecf20Sopenharmony_ci}; 14478c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(usb, device_table); 14488c2ecf20Sopenharmony_ci 14498c2ecf20Sopenharmony_ci/* -- device connect -- */ 14508c2ecf20Sopenharmony_cistatic int sd_probe(struct usb_interface *intf, 14518c2ecf20Sopenharmony_ci const struct usb_device_id *id) 14528c2ecf20Sopenharmony_ci{ 14538c2ecf20Sopenharmony_ci return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), 14548c2ecf20Sopenharmony_ci THIS_MODULE); 14558c2ecf20Sopenharmony_ci} 14568c2ecf20Sopenharmony_ci 14578c2ecf20Sopenharmony_cistatic struct usb_driver sd_driver = { 14588c2ecf20Sopenharmony_ci .name = MODULE_NAME, 14598c2ecf20Sopenharmony_ci .id_table = device_table, 14608c2ecf20Sopenharmony_ci .probe = sd_probe, 14618c2ecf20Sopenharmony_ci .disconnect = gspca_disconnect, 14628c2ecf20Sopenharmony_ci#ifdef CONFIG_PM 14638c2ecf20Sopenharmony_ci .suspend = gspca_suspend, 14648c2ecf20Sopenharmony_ci .resume = gspca_resume, 14658c2ecf20Sopenharmony_ci .reset_resume = gspca_resume, 14668c2ecf20Sopenharmony_ci#endif 14678c2ecf20Sopenharmony_ci}; 14688c2ecf20Sopenharmony_ci 14698c2ecf20Sopenharmony_cimodule_usb_driver(sd_driver); 1470