Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1 | /* |
| 2 | * sonix sn9c102 (bayer) library |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3 | * |
Jean-François Moine | 75b79ff | 2011-03-13 16:07:25 -0300 | [diff] [blame] | 4 | * Copyright (C) 2009-2011 Jean-François Moine <http://moinejf.free.fr> |
| 5 | * Copyright (C) 2003 2004 Michel Xhaard mxhaard@magic.fr |
| 6 | * Add Pas106 Stefano Mozzi (C) 2004 |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
| 22 | |
Hans de Goede | 9362773 | 2008-09-04 16:20:12 -0300 | [diff] [blame] | 23 | /* Some documentation on known sonixb registers: |
| 24 | |
| 25 | Reg Use |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 26 | sn9c101 / sn9c102: |
Hans de Goede | 9362773 | 2008-09-04 16:20:12 -0300 | [diff] [blame] | 27 | 0x10 high nibble red gain low nibble blue gain |
| 28 | 0x11 low nibble green gain |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 29 | sn9c103: |
| 30 | 0x05 red gain 0-127 |
| 31 | 0x06 blue gain 0-127 |
| 32 | 0x07 green gain 0-127 |
| 33 | all: |
| 34 | 0x08-0x0f i2c / 3wire registers |
Hans de Goede | 9362773 | 2008-09-04 16:20:12 -0300 | [diff] [blame] | 35 | 0x12 hstart |
| 36 | 0x13 vstart |
| 37 | 0x15 hsize (hsize = register-value * 16) |
| 38 | 0x16 vsize (vsize = register-value * 16) |
| 39 | 0x17 bit 0 toggle compression quality (according to sn9c102 driver) |
| 40 | 0x18 bit 7 enables compression, bit 4-5 set image down scaling: |
| 41 | 00 scale 1, 01 scale 1/2, 10, scale 1/4 |
| 42 | 0x19 high-nibble is sensor clock divider, changes exposure on sensors which |
| 43 | use a clock generated by the bridge. Some sensors have their own clock. |
| 44 | 0x1c auto_exposure area (for avg_lum) startx (startx = register-value * 32) |
| 45 | 0x1d auto_exposure area (for avg_lum) starty (starty = register-value * 32) |
| 46 | 0x1e auto_exposure area (for avg_lum) stopx (hsize = (0x1e - 0x1c) * 32) |
| 47 | 0x1f auto_exposure area (for avg_lum) stopy (vsize = (0x1f - 0x1d) * 32) |
| 48 | */ |
| 49 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 50 | #define MODULE_NAME "sonixb" |
| 51 | |
Hans de Goede | f65e93d | 2010-01-31 10:35:15 -0300 | [diff] [blame] | 52 | #include <linux/input.h> |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 53 | #include "gspca.h" |
| 54 | |
Jean-François Moine | 75b79ff | 2011-03-13 16:07:25 -0300 | [diff] [blame] | 55 | MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>"); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 56 | MODULE_DESCRIPTION("GSPCA/SN9C102 USB Camera Driver"); |
| 57 | MODULE_LICENSE("GPL"); |
| 58 | |
| 59 | /* specific webcam descriptor */ |
| 60 | struct sd { |
| 61 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
Jean-François Moine | f51a8ca | 2011-03-13 15:04:11 -0300 | [diff] [blame] | 62 | |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 63 | struct v4l2_ctrl *brightness; |
| 64 | struct v4l2_ctrl *plfreq; |
Jean-François Moine | f51a8ca | 2011-03-13 15:04:11 -0300 | [diff] [blame] | 65 | |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 66 | atomic_t avg_lum; |
Hans de Goede | bf2a220 | 2008-09-04 16:22:56 -0300 | [diff] [blame] | 67 | int prev_avg_lum; |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 68 | int exposure_knee; |
Hans de Goede | 2b3e284 | 2010-12-12 08:55:04 -0300 | [diff] [blame] | 69 | int header_read; |
| 70 | u8 header[12]; /* Header without sof marker */ |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 71 | |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 72 | unsigned char autogain_ignore_frames; |
Hans de Goede | 6af492e | 2008-07-22 07:09:33 -0300 | [diff] [blame] | 73 | unsigned char frames_to_drop; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 74 | |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 75 | __u8 bridge; /* Type of bridge */ |
| 76 | #define BRIDGE_101 0 |
| 77 | #define BRIDGE_102 0 /* We make no difference between 101 and 102 */ |
| 78 | #define BRIDGE_103 1 |
| 79 | |
| 80 | __u8 sensor; /* Type of image sensor chip */ |
Hans de Goede | 00765f1 | 2010-12-12 15:55:03 -0300 | [diff] [blame] | 81 | #define SENSOR_HV7131D 0 |
| 82 | #define SENSOR_HV7131R 1 |
| 83 | #define SENSOR_OV6650 2 |
| 84 | #define SENSOR_OV7630 3 |
| 85 | #define SENSOR_PAS106 4 |
| 86 | #define SENSOR_PAS202 5 |
| 87 | #define SENSOR_TAS5110C 6 |
| 88 | #define SENSOR_TAS5110D 7 |
| 89 | #define SENSOR_TAS5130CXX 8 |
Hans de Goede | 6af492e | 2008-07-22 07:09:33 -0300 | [diff] [blame] | 90 | __u8 reg11; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 91 | }; |
| 92 | |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 93 | typedef const __u8 sensor_init_t[8]; |
| 94 | |
| 95 | struct sensor_data { |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 96 | const __u8 *bridge_init; |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 97 | sensor_init_t *sensor_init; |
| 98 | int sensor_init_size; |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 99 | int flags; |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 100 | __u8 sensor_addr; |
| 101 | }; |
| 102 | |
| 103 | /* sensor_data flags */ |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 104 | #define F_SIF 0x01 /* sif or vga */ |
Hans de Goede | c437d65 | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 105 | |
| 106 | /* priv field of struct v4l2_pix_format flags (do not use low nibble!) */ |
| 107 | #define MODE_RAW 0x10 /* raw bayer mode */ |
Hans de Goede | 9362773 | 2008-09-04 16:20:12 -0300 | [diff] [blame] | 108 | #define MODE_REDUCED_SIF 0x20 /* vga mode (320x240 / 160x120) on sif cam */ |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 109 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 110 | #define COMP 0xc7 /* 0x87 //0x07 */ |
| 111 | #define COMP1 0xc9 /* 0x89 //0x09 */ |
| 112 | |
| 113 | #define MCK_INIT 0x63 |
| 114 | #define MCK_INIT1 0x20 /*fixme: Bayer - 0x50 for JPEG ??*/ |
| 115 | |
| 116 | #define SYS_CLK 0x04 |
| 117 | |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 118 | #define SENS(bridge, sensor, _flags, _sensor_addr) \ |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 119 | { \ |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 120 | .bridge_init = bridge, \ |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 121 | .sensor_init = sensor, \ |
| 122 | .sensor_init_size = sizeof(sensor), \ |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 123 | .flags = _flags, .sensor_addr = _sensor_addr \ |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 124 | } |
| 125 | |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 126 | /* We calculate the autogain at the end of the transfer of a frame, at this |
Hans de Goede | 26984b0 | 2010-02-01 13:18:37 -0300 | [diff] [blame] | 127 | moment a frame with the old settings is being captured and transmitted. So |
| 128 | if we adjust the gain or exposure we must ignore atleast the next frame for |
| 129 | the new settings to come into effect before doing any other adjustments. */ |
| 130 | #define AUTOGAIN_IGNORE_FRAMES 1 |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 131 | |
Jean-Francois Moine | cc611b8 | 2008-12-29 07:49:41 -0300 | [diff] [blame] | 132 | static const struct v4l2_pix_format vga_mode[] = { |
Hans de Goede | c437d65 | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 133 | {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, |
| 134 | .bytesperline = 160, |
Mauro Carvalho Chehab | 2389b36 | 2008-08-06 20:13:46 -0300 | [diff] [blame] | 135 | .sizeimage = 160 * 120, |
Hans de Goede | c437d65 | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 136 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 137 | .priv = 2 | MODE_RAW}, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 138 | {160, 120, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE, |
| 139 | .bytesperline = 160, |
Hans de Goede | 5c51518d | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 140 | .sizeimage = 160 * 120 * 5 / 4, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 141 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 142 | .priv = 2}, |
| 143 | {320, 240, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE, |
| 144 | .bytesperline = 320, |
Hans de Goede | 5c51518d | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 145 | .sizeimage = 320 * 240 * 5 / 4, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 146 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 147 | .priv = 1}, |
| 148 | {640, 480, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE, |
| 149 | .bytesperline = 640, |
Hans de Goede | 5c51518d | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 150 | .sizeimage = 640 * 480 * 5 / 4, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 151 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 152 | .priv = 0}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 153 | }; |
Jean-Francois Moine | cc611b8 | 2008-12-29 07:49:41 -0300 | [diff] [blame] | 154 | static const struct v4l2_pix_format sif_mode[] = { |
Hans de Goede | 9362773 | 2008-09-04 16:20:12 -0300 | [diff] [blame] | 155 | {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, |
| 156 | .bytesperline = 160, |
| 157 | .sizeimage = 160 * 120, |
| 158 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 159 | .priv = 1 | MODE_RAW | MODE_REDUCED_SIF}, |
| 160 | {160, 120, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE, |
| 161 | .bytesperline = 160, |
| 162 | .sizeimage = 160 * 120 * 5 / 4, |
| 163 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 164 | .priv = 1 | MODE_REDUCED_SIF}, |
Hans de Goede | c437d65 | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 165 | {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, |
| 166 | .bytesperline = 176, |
Mauro Carvalho Chehab | 2389b36 | 2008-08-06 20:13:46 -0300 | [diff] [blame] | 167 | .sizeimage = 176 * 144, |
Hans de Goede | c437d65 | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 168 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 169 | .priv = 1 | MODE_RAW}, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 170 | {176, 144, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE, |
| 171 | .bytesperline = 176, |
Hans de Goede | 5c51518d | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 172 | .sizeimage = 176 * 144 * 5 / 4, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 173 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 174 | .priv = 1}, |
Hans de Goede | 9362773 | 2008-09-04 16:20:12 -0300 | [diff] [blame] | 175 | {320, 240, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE, |
| 176 | .bytesperline = 320, |
| 177 | .sizeimage = 320 * 240 * 5 / 4, |
| 178 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 179 | .priv = 0 | MODE_REDUCED_SIF}, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 180 | {352, 288, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE, |
| 181 | .bytesperline = 352, |
Hans de Goede | 5c51518d | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 182 | .sizeimage = 352 * 288 * 5 / 4, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 183 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 184 | .priv = 0}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 185 | }; |
| 186 | |
Hans de Goede | 00765f1 | 2010-12-12 15:55:03 -0300 | [diff] [blame] | 187 | static const __u8 initHv7131d[] = { |
| 188 | 0x04, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00, |
| 189 | 0x00, 0x00, |
| 190 | 0x00, 0x00, 0x00, 0x02, 0x02, 0x00, |
| 191 | 0x28, 0x1e, 0x60, 0x8e, 0x42, |
Hans de Goede | 00765f1 | 2010-12-12 15:55:03 -0300 | [diff] [blame] | 192 | }; |
| 193 | static const __u8 hv7131d_sensor_init[][8] = { |
| 194 | {0xa0, 0x11, 0x01, 0x04, 0x00, 0x00, 0x00, 0x17}, |
| 195 | {0xa0, 0x11, 0x02, 0x00, 0x00, 0x00, 0x00, 0x17}, |
| 196 | {0xa0, 0x11, 0x28, 0x00, 0x00, 0x00, 0x00, 0x17}, |
| 197 | {0xa0, 0x11, 0x30, 0x30, 0x00, 0x00, 0x00, 0x17}, /* reset level */ |
| 198 | {0xa0, 0x11, 0x34, 0x02, 0x00, 0x00, 0x00, 0x17}, /* pixel bias volt */ |
| 199 | }; |
| 200 | |
| 201 | static const __u8 initHv7131r[] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 202 | 0x46, 0x77, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00, |
| 203 | 0x00, 0x00, |
Hans de Goede | c437d65 | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 204 | 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 205 | 0x28, 0x1e, 0x60, 0x8a, 0x20, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 206 | }; |
Hans de Goede | 00765f1 | 2010-12-12 15:55:03 -0300 | [diff] [blame] | 207 | static const __u8 hv7131r_sensor_init[][8] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 208 | {0xc0, 0x11, 0x31, 0x38, 0x2a, 0x2e, 0x00, 0x10}, |
| 209 | {0xa0, 0x11, 0x01, 0x08, 0x2a, 0x2e, 0x00, 0x10}, |
| 210 | {0xb0, 0x11, 0x20, 0x00, 0xd0, 0x2e, 0x00, 0x10}, |
| 211 | {0xc0, 0x11, 0x25, 0x03, 0x0e, 0x28, 0x00, 0x16}, |
| 212 | {0xa0, 0x11, 0x30, 0x10, 0x0e, 0x28, 0x00, 0x15}, |
| 213 | }; |
| 214 | static const __u8 initOv6650[] = { |
| 215 | 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, |
| 216 | 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Hans de Goede | c437d65 | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 217 | 0x00, 0x01, 0x01, 0x0a, 0x16, 0x12, 0x68, 0x8b, |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 218 | 0x10, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 219 | }; |
Jean-François Moine | 780e312 | 2010-10-19 04:29:10 -0300 | [diff] [blame] | 220 | static const __u8 ov6650_sensor_init[][8] = { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 221 | /* Bright, contrast, etc are set through SCBB interface. |
Jean-François Moine | 780e312 | 2010-10-19 04:29:10 -0300 | [diff] [blame] | 222 | * AVCAP on win2 do not send any data on this controls. */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 223 | /* Anyway, some registers appears to alter bright and constrat */ |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 224 | |
| 225 | /* Reset sensor */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 226 | {0xa0, 0x60, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 227 | /* Set clock register 0x11 low nibble is clock divider */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 228 | {0xd0, 0x60, 0x11, 0xc0, 0x1b, 0x18, 0xc1, 0x10}, |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 229 | /* Next some unknown stuff */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 230 | {0xb0, 0x60, 0x15, 0x00, 0x02, 0x18, 0xc1, 0x10}, |
| 231 | /* {0xa0, 0x60, 0x1b, 0x01, 0x02, 0x18, 0xc1, 0x10}, |
| 232 | * THIS SET GREEN SCREEN |
| 233 | * (pixels could be innverted in decode kind of "brg", |
| 234 | * but blue wont be there. Avoid this data ... */ |
| 235 | {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10}, /* format out? */ |
| 236 | {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10}, |
Jean-François Moine | 1d00d6c | 2010-10-29 13:58:22 -0300 | [diff] [blame] | 237 | {0xa0, 0x60, 0x30, 0x3d, 0x0a, 0xd8, 0xa4, 0x10}, |
Hans de Goede | 722103e | 2008-07-17 10:24:47 -0300 | [diff] [blame] | 238 | /* Enable rgb brightness control */ |
| 239 | {0xa0, 0x60, 0x61, 0x08, 0x00, 0x00, 0x00, 0x10}, |
| 240 | /* HDG: Note windows uses the line below, which sets both register 0x60 |
| 241 | and 0x61 I believe these registers of the ov6650 are identical as |
| 242 | those of the ov7630, because if this is true the windows settings |
| 243 | add a bit additional red gain and a lot additional blue gain, which |
| 244 | matches my findings that the windows settings make blue much too |
| 245 | blue and red a little too red. |
| 246 | {0xb0, 0x60, 0x60, 0x66, 0x68, 0xd8, 0xa4, 0x10}, */ |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 247 | /* Some more unknown stuff */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 248 | {0xa0, 0x60, 0x68, 0x04, 0x68, 0xd8, 0xa4, 0x10}, |
| 249 | {0xd0, 0x60, 0x17, 0x24, 0xd6, 0x04, 0x94, 0x10}, /* Clipreg */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 250 | }; |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 251 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 252 | static const __u8 initOv7630[] = { |
| 253 | 0x04, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* r01 .. r08 */ |
| 254 | 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* r09 .. r10 */ |
Hans de Goede | c437d65 | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 255 | 0x00, 0x01, 0x01, 0x0a, /* r11 .. r14 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 256 | 0x28, 0x1e, /* H & V sizes r15 .. r16 */ |
Andoni Zubimendi | 51fc8e3 | 2008-07-10 11:12:24 -0300 | [diff] [blame] | 257 | 0x68, 0x8f, MCK_INIT1, /* r17 .. r19 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 258 | }; |
Hans de Goede | 6af492e | 2008-07-22 07:09:33 -0300 | [diff] [blame] | 259 | static const __u8 ov7630_sensor_init[][8] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 260 | {0xa0, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, |
| 261 | {0xb0, 0x21, 0x01, 0x77, 0x3a, 0x00, 0x00, 0x10}, |
| 262 | /* {0xd0, 0x21, 0x12, 0x7c, 0x01, 0x80, 0x34, 0x10}, jfm */ |
Hans de Goede | 4c77590 | 2011-01-07 07:29:24 -0300 | [diff] [blame] | 263 | {0xd0, 0x21, 0x12, 0x5c, 0x00, 0x80, 0x34, 0x10}, /* jfm */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 264 | {0xa0, 0x21, 0x1b, 0x04, 0x00, 0x80, 0x34, 0x10}, |
| 265 | {0xa0, 0x21, 0x20, 0x44, 0x00, 0x80, 0x34, 0x10}, |
| 266 | {0xa0, 0x21, 0x23, 0xee, 0x00, 0x80, 0x34, 0x10}, |
| 267 | {0xd0, 0x21, 0x26, 0xa0, 0x9a, 0xa0, 0x30, 0x10}, |
| 268 | {0xb0, 0x21, 0x2a, 0x80, 0x00, 0xa0, 0x30, 0x10}, |
| 269 | {0xb0, 0x21, 0x2f, 0x3d, 0x24, 0xa0, 0x30, 0x10}, |
| 270 | {0xa0, 0x21, 0x32, 0x86, 0x24, 0xa0, 0x30, 0x10}, |
Andoni Zubimendi | 794af52 | 2008-07-16 08:33:14 -0300 | [diff] [blame] | 271 | {0xb0, 0x21, 0x60, 0xa9, 0x4a, 0xa0, 0x30, 0x10}, |
| 272 | /* {0xb0, 0x21, 0x60, 0xa9, 0x42, 0xa0, 0x30, 0x10}, * jfm */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 273 | {0xa0, 0x21, 0x65, 0x00, 0x42, 0xa0, 0x30, 0x10}, |
| 274 | {0xa0, 0x21, 0x69, 0x38, 0x42, 0xa0, 0x30, 0x10}, |
| 275 | {0xc0, 0x21, 0x6f, 0x88, 0x0b, 0x00, 0x30, 0x10}, |
| 276 | {0xc0, 0x21, 0x74, 0x21, 0x8e, 0x00, 0x30, 0x10}, |
| 277 | {0xa0, 0x21, 0x7d, 0xf7, 0x8e, 0x00, 0x30, 0x10}, |
| 278 | {0xd0, 0x21, 0x17, 0x1c, 0xbd, 0x06, 0xf6, 0x10}, |
| 279 | }; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 280 | |
| 281 | static const __u8 initPas106[] = { |
| 282 | 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x40, 0x00, 0x00, 0x00, |
| 283 | 0x00, 0x00, |
Hans de Goede | c437d65 | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 284 | 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 285 | 0x16, 0x12, 0x24, COMP1, MCK_INIT1, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 286 | }; |
| 287 | /* compression 0x86 mckinit1 0x2b */ |
Hans de Goede | 421763e | 2010-02-10 18:57:40 -0300 | [diff] [blame] | 288 | |
| 289 | /* "Known" PAS106B registers: |
| 290 | 0x02 clock divider |
| 291 | 0x03 Variable framerate bits 4-11 |
| 292 | 0x04 Var framerate bits 0-3, one must leave the 4 msb's at 0 !! |
| 293 | The variable framerate control must never be set lower then 300, |
| 294 | which sets the framerate at 90 / reg02, otherwise vsync is lost. |
| 295 | 0x05 Shutter Time Line Offset, this can be used as an exposure control: |
| 296 | 0 = use full frame time, 255 = no exposure at all |
| 297 | Note this may never be larger then "var-framerate control" / 2 - 2. |
| 298 | When var-framerate control is < 514, no exposure is reached at the max |
| 299 | allowed value for the framerate control value, rather then at 255. |
| 300 | 0x06 Shutter Time Pixel Offset, like reg05 this influences exposure, but |
| 301 | only a very little bit, leave at 0xcd |
| 302 | 0x07 offset sign bit (bit0 1 > negative offset) |
| 303 | 0x08 offset |
| 304 | 0x09 Blue Gain |
| 305 | 0x0a Green1 Gain |
| 306 | 0x0b Green2 Gain |
| 307 | 0x0c Red Gain |
| 308 | 0x0e Global gain |
| 309 | 0x13 Write 1 to commit settings to sensor |
| 310 | */ |
| 311 | |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 312 | static const __u8 pas106_sensor_init[][8] = { |
| 313 | /* Pixel Clock Divider 6 */ |
| 314 | { 0xa1, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x14 }, |
| 315 | /* Frame Time MSB (also seen as 0x12) */ |
| 316 | { 0xa1, 0x40, 0x03, 0x13, 0x00, 0x00, 0x00, 0x14 }, |
| 317 | /* Frame Time LSB (also seen as 0x05) */ |
| 318 | { 0xa1, 0x40, 0x04, 0x06, 0x00, 0x00, 0x00, 0x14 }, |
| 319 | /* Shutter Time Line Offset (also seen as 0x6d) */ |
| 320 | { 0xa1, 0x40, 0x05, 0x65, 0x00, 0x00, 0x00, 0x14 }, |
| 321 | /* Shutter Time Pixel Offset (also seen as 0xb1) */ |
| 322 | { 0xa1, 0x40, 0x06, 0xcd, 0x00, 0x00, 0x00, 0x14 }, |
| 323 | /* Black Level Subtract Sign (also seen 0x00) */ |
| 324 | { 0xa1, 0x40, 0x07, 0xc1, 0x00, 0x00, 0x00, 0x14 }, |
| 325 | /* Black Level Subtract Level (also seen 0x01) */ |
| 326 | { 0xa1, 0x40, 0x08, 0x06, 0x00, 0x00, 0x00, 0x14 }, |
| 327 | { 0xa1, 0x40, 0x08, 0x06, 0x00, 0x00, 0x00, 0x14 }, |
| 328 | /* Color Gain B Pixel 5 a */ |
| 329 | { 0xa1, 0x40, 0x09, 0x05, 0x00, 0x00, 0x00, 0x14 }, |
| 330 | /* Color Gain G1 Pixel 1 5 */ |
| 331 | { 0xa1, 0x40, 0x0a, 0x04, 0x00, 0x00, 0x00, 0x14 }, |
| 332 | /* Color Gain G2 Pixel 1 0 5 */ |
| 333 | { 0xa1, 0x40, 0x0b, 0x04, 0x00, 0x00, 0x00, 0x14 }, |
| 334 | /* Color Gain R Pixel 3 1 */ |
| 335 | { 0xa1, 0x40, 0x0c, 0x05, 0x00, 0x00, 0x00, 0x14 }, |
| 336 | /* Color GainH Pixel */ |
| 337 | { 0xa1, 0x40, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x14 }, |
| 338 | /* Global Gain */ |
| 339 | { 0xa1, 0x40, 0x0e, 0x0e, 0x00, 0x00, 0x00, 0x14 }, |
| 340 | /* Contrast */ |
| 341 | { 0xa1, 0x40, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x14 }, |
| 342 | /* H&V synchro polarity */ |
| 343 | { 0xa1, 0x40, 0x10, 0x06, 0x00, 0x00, 0x00, 0x14 }, |
| 344 | /* ?default */ |
| 345 | { 0xa1, 0x40, 0x11, 0x06, 0x00, 0x00, 0x00, 0x14 }, |
| 346 | /* DAC scale */ |
| 347 | { 0xa1, 0x40, 0x12, 0x06, 0x00, 0x00, 0x00, 0x14 }, |
| 348 | /* ?default */ |
| 349 | { 0xa1, 0x40, 0x14, 0x02, 0x00, 0x00, 0x00, 0x14 }, |
| 350 | /* Validate Settings */ |
| 351 | { 0xa1, 0x40, 0x13, 0x01, 0x00, 0x00, 0x00, 0x14 }, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 352 | }; |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 353 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 354 | static const __u8 initPas202[] = { |
| 355 | 0x44, 0x44, 0x21, 0x30, 0x00, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x00, |
| 356 | 0x00, 0x00, |
Hans de Goede | c437d65 | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 357 | 0x00, 0x00, 0x00, 0x06, 0x03, 0x0a, |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 358 | 0x28, 0x1e, 0x20, 0x89, 0x20, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 359 | }; |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 360 | |
| 361 | /* "Known" PAS202BCB registers: |
| 362 | 0x02 clock divider |
| 363 | 0x04 Variable framerate bits 6-11 (*) |
| 364 | 0x05 Var framerate bits 0-5, one must leave the 2 msb's at 0 !! |
| 365 | 0x07 Blue Gain |
| 366 | 0x08 Green Gain |
| 367 | 0x09 Red Gain |
| 368 | 0x0b offset sign bit (bit0 1 > negative offset) |
| 369 | 0x0c offset |
| 370 | 0x0e Unknown image is slightly brighter when bit 0 is 0, if reg0f is 0 too, |
| 371 | leave at 1 otherwise we get a jump in our exposure control |
| 372 | 0x0f Exposure 0-255, 0 = use full frame time, 255 = no exposure at all |
| 373 | 0x10 Master gain 0 - 31 |
| 374 | 0x11 write 1 to apply changes |
| 375 | (*) The variable framerate control must never be set lower then 500 |
| 376 | which sets the framerate at 30 / reg02, otherwise vsync is lost. |
| 377 | */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 378 | static const __u8 pas202_sensor_init[][8] = { |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 379 | /* Set the clock divider to 4 -> 30 / 4 = 7.5 fps, we would like |
| 380 | to set it lower, but for some reason the bridge starts missing |
| 381 | vsync's then */ |
| 382 | {0xa0, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x10}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 383 | {0xd0, 0x40, 0x04, 0x07, 0x34, 0x00, 0x09, 0x10}, |
| 384 | {0xd0, 0x40, 0x08, 0x01, 0x00, 0x00, 0x01, 0x10}, |
Jean-François Moine | 1d00d6c | 2010-10-29 13:58:22 -0300 | [diff] [blame] | 385 | {0xd0, 0x40, 0x0c, 0x00, 0x0c, 0x01, 0x32, 0x10}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 386 | {0xd0, 0x40, 0x10, 0x00, 0x01, 0x00, 0x63, 0x10}, |
| 387 | {0xa0, 0x40, 0x15, 0x70, 0x01, 0x00, 0x63, 0x10}, |
| 388 | {0xa0, 0x40, 0x18, 0x00, 0x01, 0x00, 0x63, 0x10}, |
| 389 | {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10}, |
| 390 | {0xa0, 0x40, 0x03, 0x56, 0x01, 0x00, 0x63, 0x10}, |
| 391 | {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 392 | }; |
| 393 | |
Hans de Goede | b10af3f | 2010-01-10 19:31:34 -0300 | [diff] [blame] | 394 | static const __u8 initTas5110c[] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 395 | 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00, |
| 396 | 0x00, 0x00, |
Hans de Goede | 4efcfa0 | 2010-02-01 07:48:17 -0300 | [diff] [blame] | 397 | 0x00, 0x00, 0x00, 0x45, 0x09, 0x0a, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 398 | 0x16, 0x12, 0x60, 0x86, 0x2b, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 399 | }; |
Hans de Goede | b10af3f | 2010-01-10 19:31:34 -0300 | [diff] [blame] | 400 | /* Same as above, except a different hstart */ |
| 401 | static const __u8 initTas5110d[] = { |
| 402 | 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00, |
| 403 | 0x00, 0x00, |
Hans de Goede | 4efcfa0 | 2010-02-01 07:48:17 -0300 | [diff] [blame] | 404 | 0x00, 0x00, 0x00, 0x41, 0x09, 0x0a, |
Hans de Goede | b10af3f | 2010-01-10 19:31:34 -0300 | [diff] [blame] | 405 | 0x16, 0x12, 0x60, 0x86, 0x2b, |
Hans de Goede | b10af3f | 2010-01-10 19:31:34 -0300 | [diff] [blame] | 406 | }; |
Hans de Goede | 0d0d7ef | 2011-01-06 07:55:20 -0300 | [diff] [blame] | 407 | /* tas5110c is 3 wire, tas5110d is 2 wire (regular i2c) */ |
| 408 | static const __u8 tas5110c_sensor_init[][8] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 409 | {0x30, 0x11, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10}, |
| 410 | {0x30, 0x11, 0x02, 0x20, 0xa9, 0x00, 0x00, 0x10}, |
Hans de Goede | 0d0d7ef | 2011-01-06 07:55:20 -0300 | [diff] [blame] | 411 | }; |
| 412 | /* Known TAS5110D registers |
| 413 | * reg02: gain, bit order reversed!! 0 == max gain, 255 == min gain |
| 414 | * reg03: bit3: vflip, bit4: ~hflip, bit7: ~gainboost (~ == inverted) |
| 415 | * Note: writing reg03 seems to only work when written together with 02 |
| 416 | */ |
| 417 | static const __u8 tas5110d_sensor_init[][8] = { |
| 418 | {0xa0, 0x61, 0x9a, 0xca, 0x00, 0x00, 0x00, 0x17}, /* reset */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 419 | }; |
| 420 | |
| 421 | static const __u8 initTas5130[] = { |
| 422 | 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00, |
| 423 | 0x00, 0x00, |
Hans de Goede | 4efcfa0 | 2010-02-01 07:48:17 -0300 | [diff] [blame] | 424 | 0x00, 0x00, 0x00, 0x68, 0x0c, 0x0a, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 425 | 0x28, 0x1e, 0x60, COMP, MCK_INIT, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 426 | }; |
| 427 | static const __u8 tas5130_sensor_init[][8] = { |
Jean-François Moine | 780e312 | 2010-10-19 04:29:10 -0300 | [diff] [blame] | 428 | /* {0x30, 0x11, 0x00, 0x40, 0x47, 0x00, 0x00, 0x10}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 429 | * shutter 0x47 short exposure? */ |
| 430 | {0x30, 0x11, 0x00, 0x40, 0x01, 0x00, 0x00, 0x10}, |
| 431 | /* shutter 0x01 long exposure */ |
| 432 | {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10}, |
| 433 | }; |
| 434 | |
Jean-François Moine | 75b79ff | 2011-03-13 16:07:25 -0300 | [diff] [blame] | 435 | static const struct sensor_data sensor_data[] = { |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 436 | SENS(initHv7131d, hv7131d_sensor_init, 0, 0), |
| 437 | SENS(initHv7131r, hv7131r_sensor_init, 0, 0), |
| 438 | SENS(initOv6650, ov6650_sensor_init, F_SIF, 0x60), |
| 439 | SENS(initOv7630, ov7630_sensor_init, 0, 0x21), |
| 440 | SENS(initPas106, pas106_sensor_init, F_SIF, 0), |
| 441 | SENS(initPas202, pas202_sensor_init, 0, 0), |
| 442 | SENS(initTas5110c, tas5110c_sensor_init, F_SIF, 0), |
| 443 | SENS(initTas5110d, tas5110d_sensor_init, F_SIF, 0), |
| 444 | SENS(initTas5130, tas5130_sensor_init, 0, 0), |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 445 | }; |
| 446 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 447 | /* get one byte in gspca_dev->usb_buf */ |
| 448 | static void reg_r(struct gspca_dev *gspca_dev, |
| 449 | __u16 value) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 450 | { |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 451 | int res; |
| 452 | |
| 453 | if (gspca_dev->usb_err < 0) |
| 454 | return; |
| 455 | |
| 456 | res = usb_control_msg(gspca_dev->dev, |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 457 | usb_rcvctrlpipe(gspca_dev->dev, 0), |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 458 | 0, /* request */ |
| 459 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, |
| 460 | value, |
| 461 | 0, /* index */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 462 | gspca_dev->usb_buf, 1, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 463 | 500); |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 464 | |
| 465 | if (res < 0) { |
| 466 | dev_err(gspca_dev->v4l2_dev.dev, |
| 467 | "Error reading register %02x: %d\n", value, res); |
| 468 | gspca_dev->usb_err = res; |
| 469 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 470 | } |
| 471 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 472 | static void reg_w(struct gspca_dev *gspca_dev, |
| 473 | __u16 value, |
| 474 | const __u8 *buffer, |
| 475 | int len) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 476 | { |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 477 | int res; |
| 478 | |
| 479 | if (gspca_dev->usb_err < 0) |
Hans de Goede | 0d2a722 | 2008-07-03 08:15:22 -0300 | [diff] [blame] | 480 | return; |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 481 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 482 | memcpy(gspca_dev->usb_buf, buffer, len); |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 483 | res = usb_control_msg(gspca_dev->dev, |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 484 | usb_sndctrlpipe(gspca_dev->dev, 0), |
| 485 | 0x08, /* request */ |
| 486 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, |
| 487 | value, |
| 488 | 0, /* index */ |
| 489 | gspca_dev->usb_buf, len, |
| 490 | 500); |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 491 | |
| 492 | if (res < 0) { |
| 493 | dev_err(gspca_dev->v4l2_dev.dev, |
| 494 | "Error writing register %02x: %d\n", value, res); |
| 495 | gspca_dev->usb_err = res; |
| 496 | } |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 497 | } |
| 498 | |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 499 | static void i2c_w(struct gspca_dev *gspca_dev, const __u8 *buffer) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 500 | { |
| 501 | int retry = 60; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 502 | |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 503 | if (gspca_dev->usb_err < 0) |
| 504 | return; |
| 505 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 506 | /* is i2c ready */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 507 | reg_w(gspca_dev, 0x08, buffer, 8); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 508 | while (retry--) { |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 509 | if (gspca_dev->usb_err < 0) |
| 510 | return; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 511 | msleep(10); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 512 | reg_r(gspca_dev, 0x08); |
Andoni Zubimendi | b7474cf9 | 2008-07-16 08:40:30 -0300 | [diff] [blame] | 513 | if (gspca_dev->usb_buf[0] & 0x04) { |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 514 | if (gspca_dev->usb_buf[0] & 0x08) { |
| 515 | dev_err(gspca_dev->v4l2_dev.dev, |
| 516 | "i2c write error\n"); |
| 517 | gspca_dev->usb_err = -EIO; |
| 518 | } |
| 519 | return; |
Andoni Zubimendi | b7474cf9 | 2008-07-16 08:40:30 -0300 | [diff] [blame] | 520 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 521 | } |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 522 | |
| 523 | dev_err(gspca_dev->v4l2_dev.dev, "i2c write timeout\n"); |
| 524 | gspca_dev->usb_err = -EIO; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 525 | } |
| 526 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 527 | static void i2c_w_vector(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 528 | const __u8 buffer[][8], int len) |
| 529 | { |
| 530 | for (;;) { |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 531 | if (gspca_dev->usb_err < 0) |
| 532 | return; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 533 | reg_w(gspca_dev, 0x08, *buffer, 8); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 534 | len -= 8; |
| 535 | if (len <= 0) |
| 536 | break; |
| 537 | buffer++; |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | static void setbrightness(struct gspca_dev *gspca_dev) |
| 542 | { |
| 543 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 544 | |
| 545 | switch (sd->sensor) { |
Hans de Goede | a975a52 | 2008-07-16 15:29:11 -0300 | [diff] [blame] | 546 | case SENSOR_OV6650: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 547 | case SENSOR_OV7630: { |
| 548 | __u8 i2cOV[] = |
Hans de Goede | a975a52 | 2008-07-16 15:29:11 -0300 | [diff] [blame] | 549 | {0xa0, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 550 | |
| 551 | /* change reg 0x06 */ |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 552 | i2cOV[1] = sensor_data[sd->sensor].sensor_addr; |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 553 | i2cOV[3] = sd->brightness->val; |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 554 | i2c_w(gspca_dev, i2cOV); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 555 | break; |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 556 | } |
Hans de Goede | 421763e | 2010-02-10 18:57:40 -0300 | [diff] [blame] | 557 | case SENSOR_PAS106: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 558 | case SENSOR_PAS202: { |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 559 | __u8 i2cpbright[] = |
| 560 | {0xb0, 0x40, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x16}; |
Hans de Goede | 421763e | 2010-02-10 18:57:40 -0300 | [diff] [blame] | 561 | __u8 i2cpdoit[] = |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 562 | {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16}; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 563 | |
Hans de Goede | 421763e | 2010-02-10 18:57:40 -0300 | [diff] [blame] | 564 | /* PAS106 uses reg 7 and 8 instead of b and c */ |
| 565 | if (sd->sensor == SENSOR_PAS106) { |
| 566 | i2cpbright[2] = 7; |
| 567 | i2cpdoit[2] = 0x13; |
| 568 | } |
| 569 | |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 570 | if (sd->brightness->val < 127) { |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 571 | /* change reg 0x0b, signreg */ |
| 572 | i2cpbright[3] = 0x01; |
| 573 | /* set reg 0x0c, offset */ |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 574 | i2cpbright[4] = 127 - sd->brightness->val; |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 575 | } else |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 576 | i2cpbright[4] = sd->brightness->val - 127; |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 577 | |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 578 | i2c_w(gspca_dev, i2cpbright); |
| 579 | i2c_w(gspca_dev, i2cpdoit); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 580 | break; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 581 | } |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 582 | default: |
| 583 | break; |
| 584 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 585 | } |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 586 | |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 587 | static void setgain(struct gspca_dev *gspca_dev) |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 588 | { |
| 589 | struct sd *sd = (struct sd *) gspca_dev; |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 590 | u8 gain = gspca_dev->gain->val; |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 591 | |
| 592 | switch (sd->sensor) { |
Hans de Goede | 00765f1 | 2010-12-12 15:55:03 -0300 | [diff] [blame] | 593 | case SENSOR_HV7131D: { |
| 594 | __u8 i2c[] = |
| 595 | {0xc0, 0x11, 0x31, 0x00, 0x00, 0x00, 0x00, 0x17}; |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 596 | |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 597 | i2c[3] = 0x3f - gain; |
| 598 | i2c[4] = 0x3f - gain; |
| 599 | i2c[5] = 0x3f - gain; |
Hans de Goede | 00765f1 | 2010-12-12 15:55:03 -0300 | [diff] [blame] | 600 | |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 601 | i2c_w(gspca_dev, i2c); |
Hans de Goede | 00765f1 | 2010-12-12 15:55:03 -0300 | [diff] [blame] | 602 | break; |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 603 | } |
Hans de Goede | 4e17cd2 | 2011-01-06 10:58:53 -0300 | [diff] [blame] | 604 | case SENSOR_TAS5110C: |
| 605 | case SENSOR_TAS5130CXX: { |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 606 | __u8 i2c[] = |
| 607 | {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10}; |
| 608 | |
Hans de Goede | a975a52 | 2008-07-16 15:29:11 -0300 | [diff] [blame] | 609 | i2c[4] = 255 - gain; |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 610 | i2c_w(gspca_dev, i2c); |
Andoni Zubimendi | 51fc8e3 | 2008-07-10 11:12:24 -0300 | [diff] [blame] | 611 | break; |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 612 | } |
Hans de Goede | 0d0d7ef | 2011-01-06 07:55:20 -0300 | [diff] [blame] | 613 | case SENSOR_TAS5110D: { |
| 614 | __u8 i2c[] = { |
| 615 | 0xb0, 0x61, 0x02, 0x00, 0x10, 0x00, 0x00, 0x17 }; |
| 616 | gain = 255 - gain; |
| 617 | /* The bits in the register are the wrong way around!! */ |
| 618 | i2c[3] |= (gain & 0x80) >> 7; |
| 619 | i2c[3] |= (gain & 0x40) >> 5; |
| 620 | i2c[3] |= (gain & 0x20) >> 3; |
| 621 | i2c[3] |= (gain & 0x10) >> 1; |
| 622 | i2c[3] |= (gain & 0x08) << 1; |
| 623 | i2c[3] |= (gain & 0x04) << 3; |
| 624 | i2c[3] |= (gain & 0x02) << 5; |
| 625 | i2c[3] |= (gain & 0x01) << 7; |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 626 | i2c_w(gspca_dev, i2c); |
Hans de Goede | 0d0d7ef | 2011-01-06 07:55:20 -0300 | [diff] [blame] | 627 | break; |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 628 | } |
Hans de Goede | a975a52 | 2008-07-16 15:29:11 -0300 | [diff] [blame] | 629 | case SENSOR_OV6650: |
Hans de Goede | 6af492e | 2008-07-22 07:09:33 -0300 | [diff] [blame] | 630 | case SENSOR_OV7630: { |
Hans de Goede | a975a52 | 2008-07-16 15:29:11 -0300 | [diff] [blame] | 631 | __u8 i2c[] = {0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}; |
Andoni Zubimendi | 794af52 | 2008-07-16 08:33:14 -0300 | [diff] [blame] | 632 | |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 633 | i2c[1] = sensor_data[sd->sensor].sensor_addr; |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 634 | i2c[3] = gain; |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 635 | i2c_w(gspca_dev, i2c); |
Andoni Zubimendi | 794af52 | 2008-07-16 08:33:14 -0300 | [diff] [blame] | 636 | break; |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 637 | } |
Hans de Goede | 421763e | 2010-02-10 18:57:40 -0300 | [diff] [blame] | 638 | case SENSOR_PAS106: |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 639 | case SENSOR_PAS202: { |
| 640 | __u8 i2cpgain[] = |
Hans de Goede | 421763e | 2010-02-10 18:57:40 -0300 | [diff] [blame] | 641 | {0xa0, 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x15}; |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 642 | __u8 i2cpcolorgain[] = |
| 643 | {0xc0, 0x40, 0x07, 0x00, 0x00, 0x00, 0x00, 0x15}; |
Hans de Goede | 421763e | 2010-02-10 18:57:40 -0300 | [diff] [blame] | 644 | __u8 i2cpdoit[] = |
| 645 | {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16}; |
| 646 | |
| 647 | /* PAS106 uses different regs (and has split green gains) */ |
| 648 | if (sd->sensor == SENSOR_PAS106) { |
| 649 | i2cpgain[2] = 0x0e; |
| 650 | i2cpcolorgain[0] = 0xd0; |
| 651 | i2cpcolorgain[2] = 0x09; |
| 652 | i2cpdoit[2] = 0x13; |
| 653 | } |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 654 | |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 655 | i2cpgain[3] = gain; |
| 656 | i2cpcolorgain[3] = gain >> 1; |
| 657 | i2cpcolorgain[4] = gain >> 1; |
| 658 | i2cpcolorgain[5] = gain >> 1; |
| 659 | i2cpcolorgain[6] = gain >> 1; |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 660 | |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 661 | i2c_w(gspca_dev, i2cpgain); |
| 662 | i2c_w(gspca_dev, i2cpcolorgain); |
| 663 | i2c_w(gspca_dev, i2cpdoit); |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 664 | break; |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 665 | } |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 666 | default: |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 667 | if (sd->bridge == BRIDGE_103) { |
| 668 | u8 buf[3] = { gain, gain, gain }; /* R, G, B */ |
| 669 | reg_w(gspca_dev, 0x05, buf, 3); |
| 670 | } else { |
| 671 | u8 buf[2]; |
| 672 | buf[0] = gain << 4 | gain; /* Red and blue */ |
| 673 | buf[1] = gain; /* Green */ |
| 674 | reg_w(gspca_dev, 0x10, buf, 2); |
| 675 | } |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 676 | } |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | static void setexposure(struct gspca_dev *gspca_dev) |
| 680 | { |
| 681 | struct sd *sd = (struct sd *) gspca_dev; |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 682 | |
| 683 | switch (sd->sensor) { |
Hans de Goede | 00765f1 | 2010-12-12 15:55:03 -0300 | [diff] [blame] | 684 | case SENSOR_HV7131D: { |
| 685 | /* Note the datasheet wrongly says line mode exposure uses reg |
| 686 | 0x26 and 0x27, testing has shown 0x25 + 0x26 */ |
| 687 | __u8 i2c[] = {0xc0, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x17}; |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 688 | u16 reg = gspca_dev->exposure->val; |
Jean-François Moine | f51a8ca | 2011-03-13 15:04:11 -0300 | [diff] [blame] | 689 | |
Hans de Goede | 00765f1 | 2010-12-12 15:55:03 -0300 | [diff] [blame] | 690 | i2c[3] = reg >> 8; |
| 691 | i2c[4] = reg & 0xff; |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 692 | i2c_w(gspca_dev, i2c); |
Hans de Goede | 00765f1 | 2010-12-12 15:55:03 -0300 | [diff] [blame] | 693 | break; |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 694 | } |
Hans de Goede | b10af3f | 2010-01-10 19:31:34 -0300 | [diff] [blame] | 695 | case SENSOR_TAS5110C: |
| 696 | case SENSOR_TAS5110D: { |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 697 | /* register 19's high nibble contains the sn9c10x clock divider |
| 698 | The high nibble configures the no fps according to the |
| 699 | formula: 60 / high_nibble. With a maximum of 30 fps */ |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 700 | u8 reg = gspca_dev->exposure->val; |
Jean-François Moine | f51a8ca | 2011-03-13 15:04:11 -0300 | [diff] [blame] | 701 | |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 702 | reg = (reg << 4) | 0x0b; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 703 | reg_w(gspca_dev, 0x19, ®, 1); |
Andoni Zubimendi | 51fc8e3 | 2008-07-10 11:12:24 -0300 | [diff] [blame] | 704 | break; |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 705 | } |
Hans de Goede | a975a52 | 2008-07-16 15:29:11 -0300 | [diff] [blame] | 706 | case SENSOR_OV6650: |
Hans de Goede | 6af492e | 2008-07-22 07:09:33 -0300 | [diff] [blame] | 707 | case SENSOR_OV7630: { |
Hans de Goede | a975a52 | 2008-07-16 15:29:11 -0300 | [diff] [blame] | 708 | /* The ov6650 / ov7630 have 2 registers which both influence |
| 709 | exposure, register 11, whose low nibble sets the nr off fps |
Hans de Goede | f4d5202 | 2008-07-15 09:36:42 -0300 | [diff] [blame] | 710 | according to: fps = 30 / (low_nibble + 1) |
| 711 | |
| 712 | The fps configures the maximum exposure setting, but it is |
| 713 | possible to use less exposure then what the fps maximum |
| 714 | allows by setting register 10. register 10 configures the |
| 715 | actual exposure as quotient of the full exposure, with 0 |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 716 | being no exposure at all (not very useful) and reg10_max |
Hans de Goede | f4d5202 | 2008-07-15 09:36:42 -0300 | [diff] [blame] | 717 | being max exposure possible at that framerate. |
| 718 | |
| 719 | The code maps our 0 - 510 ms exposure ctrl to these 2 |
| 720 | registers, trying to keep fps as high as possible. |
| 721 | */ |
Hans de Goede | 6af492e | 2008-07-22 07:09:33 -0300 | [diff] [blame] | 722 | __u8 i2c[] = {0xb0, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10}; |
| 723 | int reg10, reg11, reg10_max; |
| 724 | |
Hans de Goede | 66f3582 | 2008-07-16 10:16:28 -0300 | [diff] [blame] | 725 | /* ov6645 datasheet says reg10_max is 9a, but that uses |
| 726 | tline * 2 * reg10 as formula for calculating texpo, the |
| 727 | ov6650 probably uses the same formula as the 7730 which uses |
| 728 | tline * 4 * reg10, which explains why the reg10max we've |
| 729 | found experimentally for the ov6650 is exactly half that of |
Hans de Goede | a975a52 | 2008-07-16 15:29:11 -0300 | [diff] [blame] | 730 | the ov6645. The ov7630 datasheet says the max is 0x41. */ |
Hans de Goede | 6af492e | 2008-07-22 07:09:33 -0300 | [diff] [blame] | 731 | if (sd->sensor == SENSOR_OV6650) { |
| 732 | reg10_max = 0x4d; |
| 733 | i2c[4] = 0xc0; /* OV6650 needs non default vsync pol */ |
| 734 | } else |
| 735 | reg10_max = 0x41; |
Hans de Goede | f4d5202 | 2008-07-15 09:36:42 -0300 | [diff] [blame] | 736 | |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 737 | reg11 = (15 * gspca_dev->exposure->val + 999) / 1000; |
Hans de Goede | f4d5202 | 2008-07-15 09:36:42 -0300 | [diff] [blame] | 738 | if (reg11 < 1) |
| 739 | reg11 = 1; |
| 740 | else if (reg11 > 16) |
| 741 | reg11 = 16; |
| 742 | |
Hans de Goede | 10bb753 | 2010-02-04 06:10:55 -0300 | [diff] [blame] | 743 | /* In 640x480, if the reg11 has less than 4, the image is |
| 744 | unstable (the bridge goes into a higher compression mode |
| 745 | which we have not reverse engineered yet). */ |
| 746 | if (gspca_dev->width == 640 && reg11 < 4) |
| 747 | reg11 = 4; |
Hans de Goede | e2ad2a5 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 748 | |
Hans de Goede | f4d5202 | 2008-07-15 09:36:42 -0300 | [diff] [blame] | 749 | /* frame exposure time in ms = 1000 * reg11 / 30 -> |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 750 | reg10 = (gspca_dev->exposure->val / 2) * reg10_max |
Jean-François Moine | f51a8ca | 2011-03-13 15:04:11 -0300 | [diff] [blame] | 751 | / (1000 * reg11 / 30) */ |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 752 | reg10 = (gspca_dev->exposure->val * 15 * reg10_max) |
Jean-François Moine | f51a8ca | 2011-03-13 15:04:11 -0300 | [diff] [blame] | 753 | / (1000 * reg11); |
Hans de Goede | a975a52 | 2008-07-16 15:29:11 -0300 | [diff] [blame] | 754 | |
| 755 | /* Don't allow this to get below 10 when using autogain, the |
| 756 | steps become very large (relatively) when below 10 causing |
| 757 | the image to oscilate from much too dark, to much too bright |
| 758 | and back again. */ |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 759 | if (gspca_dev->autogain->val && reg10 < 10) |
Hans de Goede | a975a52 | 2008-07-16 15:29:11 -0300 | [diff] [blame] | 760 | reg10 = 10; |
Hans de Goede | f4d5202 | 2008-07-15 09:36:42 -0300 | [diff] [blame] | 761 | else if (reg10 > reg10_max) |
| 762 | reg10 = reg10_max; |
| 763 | |
| 764 | /* Write reg 10 and reg11 low nibble */ |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 765 | i2c[1] = sensor_data[sd->sensor].sensor_addr; |
Andoni Zubimendi | 794af52 | 2008-07-16 08:33:14 -0300 | [diff] [blame] | 766 | i2c[3] = reg10; |
| 767 | i2c[4] |= reg11 - 1; |
Hans de Goede | 6af492e | 2008-07-22 07:09:33 -0300 | [diff] [blame] | 768 | |
| 769 | /* If register 11 didn't change, don't change it */ |
Jean-François Moine | 780e312 | 2010-10-19 04:29:10 -0300 | [diff] [blame] | 770 | if (sd->reg11 == reg11) |
Hans de Goede | 6af492e | 2008-07-22 07:09:33 -0300 | [diff] [blame] | 771 | i2c[0] = 0xa0; |
| 772 | |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 773 | i2c_w(gspca_dev, i2c); |
| 774 | if (gspca_dev->usb_err == 0) |
Hans de Goede | 6af492e | 2008-07-22 07:09:33 -0300 | [diff] [blame] | 775 | sd->reg11 = reg11; |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 776 | break; |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 777 | } |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 778 | case SENSOR_PAS202: { |
| 779 | __u8 i2cpframerate[] = |
| 780 | {0xb0, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x16}; |
| 781 | __u8 i2cpexpo[] = |
| 782 | {0xa0, 0x40, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x16}; |
| 783 | const __u8 i2cpdoit[] = |
| 784 | {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16}; |
| 785 | int framerate_ctrl; |
| 786 | |
| 787 | /* The exposure knee for the autogain algorithm is 200 |
| 788 | (100 ms / 10 fps on other sensors), for values below this |
| 789 | use the control for setting the partial frame expose time, |
| 790 | above that use variable framerate. This way we run at max |
| 791 | framerate (640x480@7.5 fps, 320x240@10fps) until the knee |
| 792 | is reached. Using the variable framerate control above 200 |
| 793 | is better then playing around with both clockdiv + partial |
| 794 | frame exposure times (like we are doing with the ov chips), |
| 795 | as that sometimes leads to jumps in the exposure control, |
| 796 | which are bad for auto exposure. */ |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 797 | if (gspca_dev->exposure->val < 200) { |
| 798 | i2cpexpo[3] = 255 - (gspca_dev->exposure->val * 255) |
Jean-François Moine | f51a8ca | 2011-03-13 15:04:11 -0300 | [diff] [blame] | 799 | / 200; |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 800 | framerate_ctrl = 500; |
| 801 | } else { |
| 802 | /* The PAS202's exposure control goes from 0 - 4095, |
| 803 | but anything below 500 causes vsync issues, so scale |
| 804 | our 200-1023 to 500-4095 */ |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 805 | framerate_ctrl = (gspca_dev->exposure->val - 200) |
Jean-François Moine | f51a8ca | 2011-03-13 15:04:11 -0300 | [diff] [blame] | 806 | * 1000 / 229 + 500; |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | i2cpframerate[3] = framerate_ctrl >> 6; |
| 810 | i2cpframerate[4] = framerate_ctrl & 0x3f; |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 811 | i2c_w(gspca_dev, i2cpframerate); |
| 812 | i2c_w(gspca_dev, i2cpexpo); |
| 813 | i2c_w(gspca_dev, i2cpdoit); |
Andoni Zubimendi | 794af52 | 2008-07-16 08:33:14 -0300 | [diff] [blame] | 814 | break; |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 815 | } |
Hans de Goede | 421763e | 2010-02-10 18:57:40 -0300 | [diff] [blame] | 816 | case SENSOR_PAS106: { |
| 817 | __u8 i2cpframerate[] = |
| 818 | {0xb1, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x14}; |
| 819 | __u8 i2cpexpo[] = |
| 820 | {0xa1, 0x40, 0x05, 0x00, 0x00, 0x00, 0x00, 0x14}; |
| 821 | const __u8 i2cpdoit[] = |
| 822 | {0xa1, 0x40, 0x13, 0x01, 0x00, 0x00, 0x00, 0x14}; |
| 823 | int framerate_ctrl; |
| 824 | |
| 825 | /* For values below 150 use partial frame exposure, above |
| 826 | that use framerate ctrl */ |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 827 | if (gspca_dev->exposure->val < 150) { |
| 828 | i2cpexpo[3] = 150 - gspca_dev->exposure->val; |
Hans de Goede | 421763e | 2010-02-10 18:57:40 -0300 | [diff] [blame] | 829 | framerate_ctrl = 300; |
| 830 | } else { |
| 831 | /* The PAS106's exposure control goes from 0 - 4095, |
| 832 | but anything below 300 causes vsync issues, so scale |
| 833 | our 150-1023 to 300-4095 */ |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 834 | framerate_ctrl = (gspca_dev->exposure->val - 150) |
Jean-François Moine | f51a8ca | 2011-03-13 15:04:11 -0300 | [diff] [blame] | 835 | * 1000 / 230 + 300; |
Hans de Goede | 421763e | 2010-02-10 18:57:40 -0300 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | i2cpframerate[3] = framerate_ctrl >> 4; |
| 839 | i2cpframerate[4] = framerate_ctrl & 0x0f; |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 840 | i2c_w(gspca_dev, i2cpframerate); |
| 841 | i2c_w(gspca_dev, i2cpexpo); |
| 842 | i2c_w(gspca_dev, i2cpdoit); |
Hans de Goede | 421763e | 2010-02-10 18:57:40 -0300 | [diff] [blame] | 843 | break; |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 844 | } |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 845 | default: |
| 846 | break; |
| 847 | } |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 848 | } |
| 849 | |
Hans de Goede | 66f3582 | 2008-07-16 10:16:28 -0300 | [diff] [blame] | 850 | static void setfreq(struct gspca_dev *gspca_dev) |
| 851 | { |
| 852 | struct sd *sd = (struct sd *) gspca_dev; |
| 853 | |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 854 | if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630) { |
Hans de Goede | 66f3582 | 2008-07-16 10:16:28 -0300 | [diff] [blame] | 855 | /* Framerate adjust register for artificial light 50 hz flicker |
Hans de Goede | 6af492e | 2008-07-22 07:09:33 -0300 | [diff] [blame] | 856 | compensation, for the ov6650 this is identical to ov6630 |
| 857 | 0x2b register, see ov6630 datasheet. |
| 858 | 0x4f / 0x8a -> (30 fps -> 25 fps), 0x00 -> no adjustment */ |
Andoni Zubimendi | d87616f | 2008-07-17 05:35:52 -0300 | [diff] [blame] | 859 | __u8 i2c[] = {0xa0, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}; |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 860 | switch (sd->plfreq->val) { |
Hans de Goede | 66f3582 | 2008-07-16 10:16:28 -0300 | [diff] [blame] | 861 | default: |
| 862 | /* case 0: * no filter*/ |
| 863 | /* case 2: * 60 hz */ |
| 864 | i2c[3] = 0; |
| 865 | break; |
| 866 | case 1: /* 50 hz */ |
Hans de Goede | 722103e | 2008-07-17 10:24:47 -0300 | [diff] [blame] | 867 | i2c[3] = (sd->sensor == SENSOR_OV6650) |
| 868 | ? 0x4f : 0x8a; |
Hans de Goede | 66f3582 | 2008-07-16 10:16:28 -0300 | [diff] [blame] | 869 | break; |
| 870 | } |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 871 | i2c[1] = sensor_data[sd->sensor].sensor_addr; |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 872 | i2c_w(gspca_dev, i2c); |
Hans de Goede | 66f3582 | 2008-07-16 10:16:28 -0300 | [diff] [blame] | 873 | } |
| 874 | } |
| 875 | |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 876 | static void do_autogain(struct gspca_dev *gspca_dev) |
| 877 | { |
| 878 | struct sd *sd = (struct sd *) gspca_dev; |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 879 | int deadzone, desired_avg_lum, avg_lum; |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 880 | |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 881 | avg_lum = atomic_read(&sd->avg_lum); |
| 882 | if (avg_lum == -1) |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 883 | return; |
| 884 | |
Hans de Goede | 26984b0 | 2010-02-01 13:18:37 -0300 | [diff] [blame] | 885 | if (sd->autogain_ignore_frames > 0) { |
| 886 | sd->autogain_ignore_frames--; |
| 887 | return; |
| 888 | } |
| 889 | |
Hans de Goede | 5017c7b | 2008-10-22 04:59:29 -0300 | [diff] [blame] | 890 | /* SIF / VGA sensors have a different autoexposure area and thus |
| 891 | different avg_lum values for the same picture brightness */ |
| 892 | if (sensor_data[sd->sensor].flags & F_SIF) { |
Hans de Goede | 26984b0 | 2010-02-01 13:18:37 -0300 | [diff] [blame] | 893 | deadzone = 500; |
| 894 | /* SIF sensors tend to overexpose, so keep this small */ |
| 895 | desired_avg_lum = 5000; |
Hans de Goede | 5017c7b | 2008-10-22 04:59:29 -0300 | [diff] [blame] | 896 | } else { |
Hans de Goede | 26984b0 | 2010-02-01 13:18:37 -0300 | [diff] [blame] | 897 | deadzone = 1500; |
Hans de Goede | f913c00 | 2011-01-05 16:01:16 -0300 | [diff] [blame] | 898 | desired_avg_lum = 13000; |
Hans de Goede | 5017c7b | 2008-10-22 04:59:29 -0300 | [diff] [blame] | 899 | } |
| 900 | |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 901 | if (sd->brightness) |
| 902 | desired_avg_lum = sd->brightness->val * desired_avg_lum / 127; |
Hans de Goede | 26984b0 | 2010-02-01 13:18:37 -0300 | [diff] [blame] | 903 | |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 904 | if (gspca_dev->exposure->maximum < 500) { |
| 905 | if (gspca_coarse_grained_expo_autogain(gspca_dev, avg_lum, |
| 906 | desired_avg_lum, deadzone)) |
| 907 | sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES; |
| 908 | } else { |
| 909 | int gain_knee = gspca_dev->gain->maximum * 9 / 10; |
| 910 | if (gspca_expo_autogain(gspca_dev, avg_lum, desired_avg_lum, |
| 911 | deadzone, gain_knee, sd->exposure_knee)) |
| 912 | sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES; |
Hans de Goede | a975a52 | 2008-07-16 15:29:11 -0300 | [diff] [blame] | 913 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | /* this function is called at probe time */ |
| 917 | static int sd_config(struct gspca_dev *gspca_dev, |
| 918 | const struct usb_device_id *id) |
| 919 | { |
| 920 | struct sd *sd = (struct sd *) gspca_dev; |
| 921 | struct cam *cam; |
Hans de Goede | 65f3339 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 922 | |
| 923 | reg_r(gspca_dev, 0x00); |
| 924 | if (gspca_dev->usb_buf[0] != 0x10) |
| 925 | return -ENODEV; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 926 | |
Jean-Francois Moine | 5da162e | 2008-07-26 14:17:23 -0300 | [diff] [blame] | 927 | /* copy the webcam info from the device id */ |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 928 | sd->sensor = id->driver_info >> 8; |
| 929 | sd->bridge = id->driver_info & 0xff; |
Jean-François Moine | f51a8ca | 2011-03-13 15:04:11 -0300 | [diff] [blame] | 930 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 931 | cam = &gspca_dev->cam; |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 932 | if (!(sensor_data[sd->sensor].flags & F_SIF)) { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 933 | cam->cam_mode = vga_mode; |
Andoni Zubimendi | 51fc8e3 | 2008-07-10 11:12:24 -0300 | [diff] [blame] | 934 | cam->nmodes = ARRAY_SIZE(vga_mode); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 935 | } else { |
| 936 | cam->cam_mode = sif_mode; |
Andoni Zubimendi | 51fc8e3 | 2008-07-10 11:12:24 -0300 | [diff] [blame] | 937 | cam->nmodes = ARRAY_SIZE(sif_mode); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 938 | } |
Jean-Francois Moine | 49cb6b0 | 2009-04-25 13:29:01 -0300 | [diff] [blame] | 939 | cam->npkt = 36; /* 36 packets per ISOC message */ |
| 940 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 941 | return 0; |
| 942 | } |
| 943 | |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 944 | /* this function is called at probe and resume time */ |
| 945 | static int sd_init(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 946 | { |
Hans de Goede | 271315a | 2008-09-03 17:12:19 -0300 | [diff] [blame] | 947 | const __u8 stop = 0x09; /* Disable stream turn of LED */ |
| 948 | |
| 949 | reg_w(gspca_dev, 0x01, &stop, 1); |
| 950 | |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 951 | return gspca_dev->usb_err; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 952 | } |
| 953 | |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 954 | static int sd_s_ctrl(struct v4l2_ctrl *ctrl) |
| 955 | { |
| 956 | struct gspca_dev *gspca_dev = |
| 957 | container_of(ctrl->handler, struct gspca_dev, ctrl_handler); |
| 958 | struct sd *sd = (struct sd *)gspca_dev; |
| 959 | |
| 960 | gspca_dev->usb_err = 0; |
| 961 | |
| 962 | if (ctrl->id == V4L2_CID_AUTOGAIN && ctrl->is_new && ctrl->val) { |
| 963 | /* when switching to autogain set defaults to make sure |
| 964 | we are on a valid point of the autogain gain / |
| 965 | exposure knee graph, and give this change time to |
| 966 | take effect before doing autogain. */ |
| 967 | gspca_dev->gain->val = gspca_dev->gain->default_value; |
| 968 | gspca_dev->exposure->val = gspca_dev->exposure->default_value; |
| 969 | sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES; |
| 970 | } |
| 971 | |
| 972 | if (!gspca_dev->streaming) |
| 973 | return 0; |
| 974 | |
| 975 | switch (ctrl->id) { |
| 976 | case V4L2_CID_BRIGHTNESS: |
| 977 | setbrightness(gspca_dev); |
| 978 | break; |
| 979 | case V4L2_CID_AUTOGAIN: |
| 980 | if (gspca_dev->exposure->is_new || (ctrl->is_new && ctrl->val)) |
| 981 | setexposure(gspca_dev); |
| 982 | if (gspca_dev->gain->is_new || (ctrl->is_new && ctrl->val)) |
| 983 | setgain(gspca_dev); |
| 984 | break; |
| 985 | case V4L2_CID_POWER_LINE_FREQUENCY: |
| 986 | setfreq(gspca_dev); |
| 987 | break; |
| 988 | default: |
| 989 | return -EINVAL; |
| 990 | } |
| 991 | return gspca_dev->usb_err; |
| 992 | } |
| 993 | |
| 994 | static const struct v4l2_ctrl_ops sd_ctrl_ops = { |
| 995 | .s_ctrl = sd_s_ctrl, |
| 996 | }; |
| 997 | |
| 998 | /* this function is called at probe time */ |
| 999 | static int sd_init_controls(struct gspca_dev *gspca_dev) |
| 1000 | { |
| 1001 | struct sd *sd = (struct sd *) gspca_dev; |
| 1002 | struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; |
| 1003 | |
| 1004 | gspca_dev->vdev.ctrl_handler = hdl; |
| 1005 | v4l2_ctrl_handler_init(hdl, 5); |
| 1006 | |
| 1007 | if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630 || |
| 1008 | sd->sensor == SENSOR_PAS106 || sd->sensor == SENSOR_PAS202) |
| 1009 | sd->brightness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 1010 | V4L2_CID_BRIGHTNESS, 0, 255, 1, 127); |
| 1011 | |
| 1012 | /* Gain range is sensor dependent */ |
| 1013 | switch (sd->sensor) { |
| 1014 | case SENSOR_OV6650: |
| 1015 | case SENSOR_PAS106: |
| 1016 | case SENSOR_PAS202: |
| 1017 | gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 1018 | V4L2_CID_GAIN, 0, 31, 1, 15); |
| 1019 | break; |
| 1020 | case SENSOR_HV7131D: |
| 1021 | case SENSOR_OV7630: |
| 1022 | gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 1023 | V4L2_CID_GAIN, 0, 63, 1, 31); |
| 1024 | break; |
| 1025 | case SENSOR_TAS5110C: |
| 1026 | case SENSOR_TAS5110D: |
| 1027 | case SENSOR_TAS5130CXX: |
| 1028 | gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 1029 | V4L2_CID_GAIN, 0, 255, 1, 127); |
| 1030 | break; |
| 1031 | default: |
| 1032 | if (sd->bridge == BRIDGE_103) { |
| 1033 | gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 1034 | V4L2_CID_GAIN, 0, 127, 1, 63); |
| 1035 | } else { |
| 1036 | gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 1037 | V4L2_CID_GAIN, 0, 15, 1, 7); |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | /* Exposure range is sensor dependent, and not all have exposure */ |
| 1042 | switch (sd->sensor) { |
| 1043 | case SENSOR_HV7131D: |
| 1044 | gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 1045 | V4L2_CID_EXPOSURE, 0, 8191, 1, 482); |
| 1046 | sd->exposure_knee = 964; |
| 1047 | break; |
| 1048 | case SENSOR_OV6650: |
| 1049 | case SENSOR_OV7630: |
| 1050 | case SENSOR_PAS106: |
| 1051 | case SENSOR_PAS202: |
| 1052 | gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 1053 | V4L2_CID_EXPOSURE, 0, 1023, 1, 66); |
| 1054 | sd->exposure_knee = 200; |
| 1055 | break; |
| 1056 | case SENSOR_TAS5110C: |
| 1057 | case SENSOR_TAS5110D: |
| 1058 | gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 1059 | V4L2_CID_EXPOSURE, 2, 15, 1, 2); |
| 1060 | break; |
| 1061 | } |
| 1062 | |
| 1063 | if (gspca_dev->exposure) { |
| 1064 | gspca_dev->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 1065 | V4L2_CID_AUTOGAIN, 0, 1, 1, 1); |
| 1066 | } |
| 1067 | |
| 1068 | if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630) |
| 1069 | sd->plfreq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops, |
| 1070 | V4L2_CID_POWER_LINE_FREQUENCY, |
| 1071 | V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0, |
| 1072 | V4L2_CID_POWER_LINE_FREQUENCY_DISABLED); |
| 1073 | |
| 1074 | if (hdl->error) { |
| 1075 | pr_err("Could not initialize controls\n"); |
| 1076 | return hdl->error; |
| 1077 | } |
| 1078 | |
| 1079 | if (gspca_dev->autogain) |
| 1080 | v4l2_ctrl_auto_cluster(3, &gspca_dev->autogain, 0, false); |
| 1081 | |
| 1082 | return 0; |
| 1083 | } |
| 1084 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1085 | /* -- start the camera -- */ |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 1086 | static int sd_start(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1087 | { |
| 1088 | struct sd *sd = (struct sd *) gspca_dev; |
Hans de Goede | 9362773 | 2008-09-04 16:20:12 -0300 | [diff] [blame] | 1089 | struct cam *cam = &gspca_dev->cam; |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1090 | int i, mode; |
| 1091 | __u8 regs[0x31]; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1092 | |
Hans de Goede | 9362773 | 2008-09-04 16:20:12 -0300 | [diff] [blame] | 1093 | mode = cam->cam_mode[gspca_dev->curr_mode].priv & 0x07; |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1094 | /* Copy registers 0x01 - 0x19 from the template */ |
| 1095 | memcpy(®s[0x01], sensor_data[sd->sensor].bridge_init, 0x19); |
| 1096 | /* Set the mode */ |
| 1097 | regs[0x18] |= mode << 4; |
| 1098 | |
| 1099 | /* Set bridge gain to 1.0 */ |
| 1100 | if (sd->bridge == BRIDGE_103) { |
| 1101 | regs[0x05] = 0x20; /* Red */ |
| 1102 | regs[0x06] = 0x20; /* Green */ |
| 1103 | regs[0x07] = 0x20; /* Blue */ |
| 1104 | } else { |
| 1105 | regs[0x10] = 0x00; /* Red and blue */ |
| 1106 | regs[0x11] = 0x00; /* Green */ |
| 1107 | } |
| 1108 | |
| 1109 | /* Setup pixel numbers and auto exposure window */ |
| 1110 | if (sensor_data[sd->sensor].flags & F_SIF) { |
| 1111 | regs[0x1a] = 0x14; /* HO_SIZE 640, makes no sense */ |
| 1112 | regs[0x1b] = 0x0a; /* VO_SIZE 320, makes no sense */ |
| 1113 | regs[0x1c] = 0x02; /* AE H-start 64 */ |
| 1114 | regs[0x1d] = 0x02; /* AE V-start 64 */ |
| 1115 | regs[0x1e] = 0x09; /* AE H-end 288 */ |
| 1116 | regs[0x1f] = 0x07; /* AE V-end 224 */ |
| 1117 | } else { |
| 1118 | regs[0x1a] = 0x1d; /* HO_SIZE 960, makes no sense */ |
| 1119 | regs[0x1b] = 0x10; /* VO_SIZE 512, makes no sense */ |
Hans de Goede | f913c00 | 2011-01-05 16:01:16 -0300 | [diff] [blame] | 1120 | regs[0x1c] = 0x05; /* AE H-start 160 */ |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1121 | regs[0x1d] = 0x03; /* AE V-start 96 */ |
| 1122 | regs[0x1e] = 0x0f; /* AE H-end 480 */ |
| 1123 | regs[0x1f] = 0x0c; /* AE V-end 384 */ |
| 1124 | } |
| 1125 | |
| 1126 | /* Setup the gamma table (only used with the sn9c103 bridge) */ |
| 1127 | for (i = 0; i < 16; i++) |
| 1128 | regs[0x20 + i] = i * 16; |
| 1129 | regs[0x20 + i] = 255; |
| 1130 | |
| 1131 | /* Special cases where some regs depend on mode or bridge */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1132 | switch (sd->sensor) { |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 1133 | case SENSOR_TAS5130CXX: |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1134 | /* FIXME / TESTME |
| 1135 | probably not mode specific at all most likely the upper |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 1136 | nibble of 0x19 is exposure (clock divider) just as with |
| 1137 | the tas5110, we need someone to test this. */ |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1138 | regs[0x19] = mode ? 0x23 : 0x43; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1139 | break; |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1140 | case SENSOR_OV7630: |
| 1141 | /* FIXME / TESTME for some reason with the 101/102 bridge the |
| 1142 | clock is set to 12 Mhz (reg1 == 0x04), rather then 24. |
| 1143 | Also the hstart needs to go from 1 to 2 when using a 103, |
| 1144 | which is likely related. This does not seem right. */ |
| 1145 | if (sd->bridge == BRIDGE_103) { |
| 1146 | regs[0x01] = 0x44; /* Select 24 Mhz clock */ |
| 1147 | regs[0x12] = 0x02; /* Set hstart to 2 */ |
| 1148 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1149 | } |
Hans de Goede | c437d65 | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 1150 | /* Disable compression when the raw bayer format has been selected */ |
Hans de Goede | 9362773 | 2008-09-04 16:20:12 -0300 | [diff] [blame] | 1151 | if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW) |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1152 | regs[0x18] &= ~0x80; |
Hans de Goede | 9362773 | 2008-09-04 16:20:12 -0300 | [diff] [blame] | 1153 | |
| 1154 | /* Vga mode emulation on SIF sensor? */ |
| 1155 | if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_REDUCED_SIF) { |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1156 | regs[0x12] += 16; /* hstart adjust */ |
| 1157 | regs[0x13] += 24; /* vstart adjust */ |
| 1158 | regs[0x15] = 320 / 16; /* hsize */ |
| 1159 | regs[0x16] = 240 / 16; /* vsize */ |
Hans de Goede | 9362773 | 2008-09-04 16:20:12 -0300 | [diff] [blame] | 1160 | } |
Hans de Goede | 6af492e | 2008-07-22 07:09:33 -0300 | [diff] [blame] | 1161 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1162 | /* reg 0x01 bit 2 video transfert on */ |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1163 | reg_w(gspca_dev, 0x01, ®s[0x01], 1); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1164 | /* reg 0x17 SensorClk enable inv Clk 0x60 */ |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1165 | reg_w(gspca_dev, 0x17, ®s[0x17], 1); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1166 | /* Set the registers from the template */ |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1167 | reg_w(gspca_dev, 0x01, ®s[0x01], |
| 1168 | (sd->bridge == BRIDGE_103) ? 0x30 : 0x1f); |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 1169 | |
| 1170 | /* Init the sensor */ |
| 1171 | i2c_w_vector(gspca_dev, sensor_data[sd->sensor].sensor_init, |
| 1172 | sensor_data[sd->sensor].sensor_init_size); |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 1173 | |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1174 | /* Mode / bridge specific sensor setup */ |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 1175 | switch (sd->sensor) { |
| 1176 | case SENSOR_PAS202: { |
| 1177 | const __u8 i2cpclockdiv[] = |
| 1178 | {0xa0, 0x40, 0x02, 0x03, 0x00, 0x00, 0x00, 0x10}; |
| 1179 | /* clockdiv from 4 to 3 (7.5 -> 10 fps) when in low res mode */ |
| 1180 | if (mode) |
| 1181 | i2c_w(gspca_dev, i2cpclockdiv); |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1182 | break; |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 1183 | } |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1184 | case SENSOR_OV7630: |
| 1185 | /* FIXME / TESTME We should be able to handle this identical |
| 1186 | for the 101/102 and the 103 case */ |
| 1187 | if (sd->bridge == BRIDGE_103) { |
| 1188 | const __u8 i2c[] = { 0xa0, 0x21, 0x13, |
| 1189 | 0x80, 0x00, 0x00, 0x00, 0x10 }; |
| 1190 | i2c_w(gspca_dev, i2c); |
| 1191 | } |
| 1192 | break; |
Hans de Goede | 82e839c | 2010-02-03 14:37:30 -0300 | [diff] [blame] | 1193 | } |
Hans de Goede | 3647fea | 2008-07-15 05:36:30 -0300 | [diff] [blame] | 1194 | /* H_size V_size 0x28, 0x1e -> 640x480. 0x16, 0x12 -> 352x288 */ |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1195 | reg_w(gspca_dev, 0x15, ®s[0x15], 2); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1196 | /* compression register */ |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1197 | reg_w(gspca_dev, 0x18, ®s[0x18], 1); |
Andoni Zubimendi | 794af52 | 2008-07-16 08:33:14 -0300 | [diff] [blame] | 1198 | /* H_start */ |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1199 | reg_w(gspca_dev, 0x12, ®s[0x12], 1); |
Andoni Zubimendi | 794af52 | 2008-07-16 08:33:14 -0300 | [diff] [blame] | 1200 | /* V_START */ |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1201 | reg_w(gspca_dev, 0x13, ®s[0x13], 1); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1202 | /* reset 0x17 SensorClk enable inv Clk 0x60 */ |
| 1203 | /*fixme: ov7630 [17]=68 8f (+20 if 102)*/ |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1204 | reg_w(gspca_dev, 0x17, ®s[0x17], 1); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1205 | /*MCKSIZE ->3 */ /*fixme: not ov7630*/ |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1206 | reg_w(gspca_dev, 0x19, ®s[0x19], 1); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1207 | /* AE_STRX AE_STRY AE_ENDX AE_ENDY */ |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1208 | reg_w(gspca_dev, 0x1c, ®s[0x1c], 4); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1209 | /* Enable video transfert */ |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1210 | reg_w(gspca_dev, 0x01, ®s[0x01], 1); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1211 | /* Compression */ |
Hans de Goede | 0a76cb8 | 2011-01-05 13:55:43 -0300 | [diff] [blame] | 1212 | reg_w(gspca_dev, 0x18, ®s[0x18], 2); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1213 | msleep(20); |
| 1214 | |
Hans de Goede | 6af492e | 2008-07-22 07:09:33 -0300 | [diff] [blame] | 1215 | sd->reg11 = -1; |
| 1216 | |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 1217 | setgain(gspca_dev); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1218 | setbrightness(gspca_dev); |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 1219 | setexposure(gspca_dev); |
Hans de Goede | 66f3582 | 2008-07-16 10:16:28 -0300 | [diff] [blame] | 1220 | setfreq(gspca_dev); |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 1221 | |
Hans de Goede | 6af492e | 2008-07-22 07:09:33 -0300 | [diff] [blame] | 1222 | sd->frames_to_drop = 0; |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 1223 | sd->autogain_ignore_frames = 0; |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 1224 | gspca_dev->exp_too_high_cnt = 0; |
| 1225 | gspca_dev->exp_too_low_cnt = 0; |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 1226 | atomic_set(&sd->avg_lum, -1); |
Hans de Goede | 4848ea7 | 2012-05-14 15:21:25 -0300 | [diff] [blame] | 1227 | return gspca_dev->usb_err; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | static void sd_stopN(struct gspca_dev *gspca_dev) |
| 1231 | { |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 1232 | sd_init(gspca_dev); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1233 | } |
| 1234 | |
Hans de Goede | 2b3e284 | 2010-12-12 08:55:04 -0300 | [diff] [blame] | 1235 | static u8* find_sof(struct gspca_dev *gspca_dev, u8 *data, int len) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1236 | { |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 1237 | struct sd *sd = (struct sd *) gspca_dev; |
Hans de Goede | 2b3e284 | 2010-12-12 08:55:04 -0300 | [diff] [blame] | 1238 | int i, header_size = (sd->bridge == BRIDGE_103) ? 18 : 12; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1239 | |
Hans de Goede | c36260ee | 2008-07-16 09:56:07 -0300 | [diff] [blame] | 1240 | /* frames start with: |
| 1241 | * ff ff 00 c4 c4 96 synchro |
| 1242 | * 00 (unknown) |
| 1243 | * xx (frame sequence / size / compression) |
| 1244 | * (xx) (idem - extra byte for sn9c103) |
| 1245 | * ll mm brightness sum inside auto exposure |
| 1246 | * ll mm brightness sum outside auto exposure |
| 1247 | * (xx xx xx xx xx) audio values for snc103 |
| 1248 | */ |
Hans de Goede | 2b3e284 | 2010-12-12 08:55:04 -0300 | [diff] [blame] | 1249 | for (i = 0; i < len; i++) { |
| 1250 | switch (sd->header_read) { |
| 1251 | case 0: |
| 1252 | if (data[i] == 0xff) |
| 1253 | sd->header_read++; |
| 1254 | break; |
| 1255 | case 1: |
| 1256 | if (data[i] == 0xff) |
| 1257 | sd->header_read++; |
| 1258 | else |
| 1259 | sd->header_read = 0; |
| 1260 | break; |
| 1261 | case 2: |
| 1262 | if (data[i] == 0x00) |
| 1263 | sd->header_read++; |
| 1264 | else if (data[i] != 0xff) |
| 1265 | sd->header_read = 0; |
| 1266 | break; |
| 1267 | case 3: |
| 1268 | if (data[i] == 0xc4) |
| 1269 | sd->header_read++; |
| 1270 | else if (data[i] == 0xff) |
| 1271 | sd->header_read = 1; |
| 1272 | else |
| 1273 | sd->header_read = 0; |
| 1274 | break; |
| 1275 | case 4: |
| 1276 | if (data[i] == 0xc4) |
| 1277 | sd->header_read++; |
| 1278 | else if (data[i] == 0xff) |
| 1279 | sd->header_read = 1; |
| 1280 | else |
| 1281 | sd->header_read = 0; |
| 1282 | break; |
| 1283 | case 5: |
| 1284 | if (data[i] == 0x96) |
| 1285 | sd->header_read++; |
| 1286 | else if (data[i] == 0xff) |
| 1287 | sd->header_read = 1; |
| 1288 | else |
| 1289 | sd->header_read = 0; |
| 1290 | break; |
| 1291 | default: |
| 1292 | sd->header[sd->header_read - 6] = data[i]; |
| 1293 | sd->header_read++; |
| 1294 | if (sd->header_read == header_size) { |
| 1295 | sd->header_read = 0; |
| 1296 | return data + i + 1; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1297 | } |
| 1298 | } |
| 1299 | } |
Hans de Goede | 2b3e284 | 2010-12-12 08:55:04 -0300 | [diff] [blame] | 1300 | return NULL; |
| 1301 | } |
| 1302 | |
| 1303 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, |
| 1304 | u8 *data, /* isoc packet */ |
| 1305 | int len) /* iso packet length */ |
| 1306 | { |
| 1307 | int fr_h_sz = 0, lum_offset = 0, len_after_sof = 0; |
| 1308 | struct sd *sd = (struct sd *) gspca_dev; |
| 1309 | struct cam *cam = &gspca_dev->cam; |
| 1310 | u8 *sof; |
| 1311 | |
| 1312 | sof = find_sof(gspca_dev, data, len); |
| 1313 | if (sof) { |
| 1314 | if (sd->bridge == BRIDGE_103) { |
| 1315 | fr_h_sz = 18; |
| 1316 | lum_offset = 3; |
| 1317 | } else { |
| 1318 | fr_h_sz = 12; |
| 1319 | lum_offset = 2; |
| 1320 | } |
| 1321 | |
| 1322 | len_after_sof = len - (sof - data); |
| 1323 | len = (sof - data) - fr_h_sz; |
| 1324 | if (len < 0) |
| 1325 | len = 0; |
| 1326 | } |
Hans de Goede | c437d65 | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 1327 | |
| 1328 | if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW) { |
| 1329 | /* In raw mode we sometimes get some garbage after the frame |
| 1330 | ignore this */ |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 1331 | int used; |
Hans de Goede | c437d65 | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 1332 | int size = cam->cam_mode[gspca_dev->curr_mode].sizeimage; |
| 1333 | |
Jean-François Moine | b192ca9 | 2010-06-27 03:08:19 -0300 | [diff] [blame] | 1334 | used = gspca_dev->image_len; |
Hans de Goede | c437d65 | 2008-09-03 17:12:22 -0300 | [diff] [blame] | 1335 | if (used + len > size) |
| 1336 | len = size - used; |
| 1337 | } |
| 1338 | |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 1339 | gspca_frame_add(gspca_dev, INTER_PACKET, data, len); |
Hans de Goede | 2b3e284 | 2010-12-12 08:55:04 -0300 | [diff] [blame] | 1340 | |
| 1341 | if (sof) { |
| 1342 | int lum = sd->header[lum_offset] + |
| 1343 | (sd->header[lum_offset + 1] << 8); |
| 1344 | |
| 1345 | /* When exposure changes midway a frame we |
| 1346 | get a lum of 0 in this case drop 2 frames |
| 1347 | as the frames directly after an exposure |
| 1348 | change have an unstable image. Sometimes lum |
| 1349 | *really* is 0 (cam used in low light with |
| 1350 | low exposure setting), so do not drop frames |
| 1351 | if the previous lum was 0 too. */ |
| 1352 | if (lum == 0 && sd->prev_avg_lum != 0) { |
| 1353 | lum = -1; |
| 1354 | sd->frames_to_drop = 2; |
| 1355 | sd->prev_avg_lum = 0; |
| 1356 | } else |
| 1357 | sd->prev_avg_lum = lum; |
| 1358 | atomic_set(&sd->avg_lum, lum); |
| 1359 | |
| 1360 | if (sd->frames_to_drop) |
| 1361 | sd->frames_to_drop--; |
| 1362 | else |
| 1363 | gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0); |
| 1364 | |
| 1365 | gspca_frame_add(gspca_dev, FIRST_PACKET, sof, len_after_sof); |
| 1366 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1367 | } |
| 1368 | |
Hans de Goede | 66f3582 | 2008-07-16 10:16:28 -0300 | [diff] [blame] | 1369 | static int sd_querymenu(struct gspca_dev *gspca_dev, |
| 1370 | struct v4l2_querymenu *menu) |
| 1371 | { |
| 1372 | switch (menu->id) { |
| 1373 | case V4L2_CID_POWER_LINE_FREQUENCY: |
| 1374 | switch (menu->index) { |
| 1375 | case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */ |
| 1376 | strcpy((char *) menu->name, "NoFliker"); |
| 1377 | return 0; |
| 1378 | case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */ |
| 1379 | strcpy((char *) menu->name, "50 Hz"); |
| 1380 | return 0; |
| 1381 | case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */ |
| 1382 | strcpy((char *) menu->name, "60 Hz"); |
| 1383 | return 0; |
| 1384 | } |
| 1385 | break; |
| 1386 | } |
| 1387 | return -EINVAL; |
| 1388 | } |
| 1389 | |
Jean-François Moine | 2856643 | 2010-10-01 07:33:26 -0300 | [diff] [blame] | 1390 | #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) |
Hans de Goede | f65e93d | 2010-01-31 10:35:15 -0300 | [diff] [blame] | 1391 | static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, |
| 1392 | u8 *data, /* interrupt packet data */ |
| 1393 | int len) /* interrupt packet length */ |
| 1394 | { |
| 1395 | int ret = -EINVAL; |
| 1396 | |
| 1397 | if (len == 1 && data[0] == 1) { |
| 1398 | input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1); |
| 1399 | input_sync(gspca_dev->input_dev); |
| 1400 | input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); |
| 1401 | input_sync(gspca_dev->input_dev); |
| 1402 | ret = 0; |
| 1403 | } |
| 1404 | |
| 1405 | return ret; |
| 1406 | } |
| 1407 | #endif |
| 1408 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1409 | /* sub-driver description */ |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 1410 | static const struct sd_desc sd_desc = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1411 | .name = MODULE_NAME, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1412 | .config = sd_config, |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 1413 | .init = sd_init, |
Hans de Goede | 9153ac3 | 2012-05-15 04:23:55 -0300 | [diff] [blame^] | 1414 | .init_controls = sd_init_controls, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1415 | .start = sd_start, |
| 1416 | .stopN = sd_stopN, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1417 | .pkt_scan = sd_pkt_scan, |
Hans de Goede | 66f3582 | 2008-07-16 10:16:28 -0300 | [diff] [blame] | 1418 | .querymenu = sd_querymenu, |
Hans de Goede | e2ad2a5 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1419 | .dq_callback = do_autogain, |
Jean-François Moine | 2856643 | 2010-10-01 07:33:26 -0300 | [diff] [blame] | 1420 | #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) |
Hans de Goede | f65e93d | 2010-01-31 10:35:15 -0300 | [diff] [blame] | 1421 | .int_pkt_scan = sd_int_pkt_scan, |
| 1422 | #endif |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1423 | }; |
| 1424 | |
| 1425 | /* -- module initialisation -- */ |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 1426 | #define SB(sensor, bridge) \ |
| 1427 | .driver_info = (SENSOR_ ## sensor << 8) | BRIDGE_ ## bridge |
| 1428 | |
Hans de Goede | e2ad2a5 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1429 | |
Jean-François Moine | 95c967c | 2011-01-13 05:20:29 -0300 | [diff] [blame] | 1430 | static const struct usb_device_id device_table[] = { |
Hans de Goede | b10af3f | 2010-01-10 19:31:34 -0300 | [diff] [blame] | 1431 | {USB_DEVICE(0x0c45, 0x6001), SB(TAS5110C, 102)}, /* TAS5110C1B */ |
| 1432 | {USB_DEVICE(0x0c45, 0x6005), SB(TAS5110C, 101)}, /* TAS5110C1B */ |
Hans de Goede | b10af3f | 2010-01-10 19:31:34 -0300 | [diff] [blame] | 1433 | {USB_DEVICE(0x0c45, 0x6007), SB(TAS5110D, 101)}, /* TAS5110D */ |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 1434 | {USB_DEVICE(0x0c45, 0x6009), SB(PAS106, 101)}, |
| 1435 | {USB_DEVICE(0x0c45, 0x600d), SB(PAS106, 101)}, |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 1436 | {USB_DEVICE(0x0c45, 0x6011), SB(OV6650, 101)}, |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 1437 | {USB_DEVICE(0x0c45, 0x6019), SB(OV7630, 101)}, |
Hans de Goede | 69ffd25 | 2011-01-06 11:56:30 -0300 | [diff] [blame] | 1438 | #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 1439 | {USB_DEVICE(0x0c45, 0x6024), SB(TAS5130CXX, 102)}, |
| 1440 | {USB_DEVICE(0x0c45, 0x6025), SB(TAS5130CXX, 102)}, |
Hans de Goede | 0e4b91c | 2010-02-10 20:29:43 -0300 | [diff] [blame] | 1441 | #endif |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 1442 | {USB_DEVICE(0x0c45, 0x6028), SB(PAS202, 102)}, |
| 1443 | {USB_DEVICE(0x0c45, 0x6029), SB(PAS106, 102)}, |
Hans de Goede | 00765f1 | 2010-12-12 15:55:03 -0300 | [diff] [blame] | 1444 | {USB_DEVICE(0x0c45, 0x602a), SB(HV7131D, 102)}, |
| 1445 | /* {USB_DEVICE(0x0c45, 0x602b), SB(MI0343, 102)}, */ |
Jean-Francois Moine | 29fbdf3 | 2008-11-07 04:53:28 -0300 | [diff] [blame] | 1446 | {USB_DEVICE(0x0c45, 0x602c), SB(OV7630, 102)}, |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 1447 | {USB_DEVICE(0x0c45, 0x602d), SB(HV7131R, 102)}, |
Hans de Goede | f45f06b | 2008-09-03 17:12:21 -0300 | [diff] [blame] | 1448 | {USB_DEVICE(0x0c45, 0x602e), SB(OV7630, 102)}, |
Hans de Goede | 69ffd25 | 2011-01-06 11:56:30 -0300 | [diff] [blame] | 1449 | /* {USB_DEVICE(0x0c45, 0x6030), SB(MI03XX, 102)}, */ /* MI0343 MI0360 MI0330 */ |
| 1450 | /* {USB_DEVICE(0x0c45, 0x6082), SB(MI03XX, 103)}, */ /* MI0343 MI0360 */ |
| 1451 | {USB_DEVICE(0x0c45, 0x6083), SB(HV7131D, 103)}, |
| 1452 | {USB_DEVICE(0x0c45, 0x608c), SB(HV7131R, 103)}, |
| 1453 | /* {USB_DEVICE(0x0c45, 0x608e), SB(CISVF10, 103)}, */ |
Hans de Goede | 4cce165 | 2008-09-04 16:22:57 -0300 | [diff] [blame] | 1454 | {USB_DEVICE(0x0c45, 0x608f), SB(OV7630, 103)}, |
Hans de Goede | 69ffd25 | 2011-01-06 11:56:30 -0300 | [diff] [blame] | 1455 | {USB_DEVICE(0x0c45, 0x60a8), SB(PAS106, 103)}, |
| 1456 | {USB_DEVICE(0x0c45, 0x60aa), SB(TAS5130CXX, 103)}, |
Hans de Goede | 4cce165 | 2008-09-04 16:22:57 -0300 | [diff] [blame] | 1457 | {USB_DEVICE(0x0c45, 0x60af), SB(PAS202, 103)}, |
Hans de Goede | 4cce165 | 2008-09-04 16:22:57 -0300 | [diff] [blame] | 1458 | {USB_DEVICE(0x0c45, 0x60b0), SB(OV7630, 103)}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1459 | {} |
| 1460 | }; |
| 1461 | MODULE_DEVICE_TABLE(usb, device_table); |
| 1462 | |
| 1463 | /* -- device connect -- */ |
Jean-François Moine | 95c967c | 2011-01-13 05:20:29 -0300 | [diff] [blame] | 1464 | static int sd_probe(struct usb_interface *intf, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1465 | const struct usb_device_id *id) |
| 1466 | { |
| 1467 | return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), |
| 1468 | THIS_MODULE); |
| 1469 | } |
| 1470 | |
| 1471 | static struct usb_driver sd_driver = { |
| 1472 | .name = MODULE_NAME, |
| 1473 | .id_table = device_table, |
| 1474 | .probe = sd_probe, |
| 1475 | .disconnect = gspca_disconnect, |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame] | 1476 | #ifdef CONFIG_PM |
| 1477 | .suspend = gspca_suspend, |
| 1478 | .resume = gspca_resume, |
| 1479 | #endif |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1480 | }; |
| 1481 | |
Greg Kroah-Hartman | ecb3b2b | 2011-11-18 09:46:12 -0800 | [diff] [blame] | 1482 | module_usb_driver(sd_driver); |