Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 1 | /* |
| 2 | * SQ930x subdriver |
| 3 | * |
| 4 | * Copyright (C) 2010 Jean-François Moine <http://moinejf.free.fr> |
| 5 | * Copyright (C) 2006 -2008 Gerard Klaver <gerard at gkall dot hobby dot nl> |
| 6 | * Copyright (C) 2007 Sam Revitch <samr7@cs.washington.edu> |
| 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 | |
| 23 | #define MODULE_NAME "sq930x" |
| 24 | |
| 25 | #include "gspca.h" |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 26 | |
| 27 | MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>\n" |
| 28 | "Gerard Klaver <gerard at gkall dot hobby dot nl\n" |
| 29 | "Sam Revitch <samr7@cs.washington.edu>"); |
| 30 | MODULE_DESCRIPTION("GSPCA/SQ930x USB Camera Driver"); |
| 31 | MODULE_LICENSE("GPL"); |
| 32 | |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 33 | /* Structure to hold all of our device specific stuff */ |
| 34 | struct sd { |
| 35 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
| 36 | |
| 37 | u16 expo; |
| 38 | u8 gain; |
| 39 | |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 40 | u8 do_ctrl; |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 41 | u8 gpio[2]; |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 42 | u8 sensor; |
Jean-François Moine | 11ce884 | 2010-07-26 06:39:40 -0300 | [diff] [blame] | 43 | u8 type; |
| 44 | #define Generic 0 |
| 45 | #define Creative_live_motion 1 |
| 46 | }; |
| 47 | enum sensors { |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 48 | SENSOR_ICX098BQ, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 49 | SENSOR_LZ24BP, |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 50 | SENSOR_MI0360, |
| 51 | SENSOR_MT9V111, |
| 52 | SENSOR_OV7660, |
| 53 | SENSOR_OV9630, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | static int sd_setexpo(struct gspca_dev *gspca_dev, __s32 val); |
| 57 | static int sd_getexpo(struct gspca_dev *gspca_dev, __s32 *val); |
| 58 | static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val); |
| 59 | static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val); |
| 60 | |
| 61 | static const struct ctrl sd_ctrls[] = { |
| 62 | { |
| 63 | { |
| 64 | .id = V4L2_CID_EXPOSURE, |
| 65 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 66 | .name = "Exposure", |
| 67 | .minimum = 0x0001, |
| 68 | .maximum = 0x0fff, |
| 69 | .step = 1, |
Jean-François Moine | d6f5bd6 | 2010-07-26 07:09:32 -0300 | [diff] [blame] | 70 | #define EXPO_DEF 0x0356 |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 71 | .default_value = EXPO_DEF, |
| 72 | }, |
| 73 | .set = sd_setexpo, |
| 74 | .get = sd_getexpo, |
| 75 | }, |
| 76 | { |
| 77 | { |
| 78 | .id = V4L2_CID_GAIN, |
| 79 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 80 | .name = "Gain", |
| 81 | .minimum = 0x01, |
| 82 | .maximum = 0xff, |
| 83 | .step = 1, |
Jean-François Moine | d6f5bd6 | 2010-07-26 07:09:32 -0300 | [diff] [blame] | 84 | #define GAIN_DEF 0x8d |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 85 | .default_value = GAIN_DEF, |
| 86 | }, |
| 87 | .set = sd_setgain, |
| 88 | .get = sd_getgain, |
| 89 | }, |
| 90 | }; |
| 91 | |
| 92 | static struct v4l2_pix_format vga_mode[] = { |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 93 | {320, 240, V4L2_PIX_FMT_SRGGB8, V4L2_FIELD_NONE, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 94 | .bytesperline = 320, |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 95 | .sizeimage = 320 * 240, |
| 96 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 97 | .priv = 0}, |
| 98 | {640, 480, V4L2_PIX_FMT_SRGGB8, V4L2_FIELD_NONE, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 99 | .bytesperline = 640, |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 100 | .sizeimage = 640 * 480, |
| 101 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 102 | .priv = 1}, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 103 | }; |
| 104 | |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 105 | /* sq930x registers */ |
| 106 | #define SQ930_CTRL_UCBUS_IO 0x0001 |
| 107 | #define SQ930_CTRL_I2C_IO 0x0002 |
| 108 | #define SQ930_CTRL_GPIO 0x0005 |
| 109 | #define SQ930_CTRL_CAP_START 0x0010 |
| 110 | #define SQ930_CTRL_CAP_STOP 0x0011 |
| 111 | #define SQ930_CTRL_SET_EXPOSURE 0x001d |
| 112 | #define SQ930_CTRL_RESET 0x001e |
| 113 | #define SQ930_CTRL_GET_DEV_INFO 0x001f |
| 114 | |
| 115 | /* gpio 1 (8..15) */ |
| 116 | #define SQ930_GPIO_DFL_I2C_SDA 0x0001 |
| 117 | #define SQ930_GPIO_DFL_I2C_SCL 0x0002 |
| 118 | #define SQ930_GPIO_RSTBAR 0x0004 |
| 119 | #define SQ930_GPIO_EXTRA1 0x0040 |
| 120 | #define SQ930_GPIO_EXTRA2 0x0080 |
| 121 | /* gpio 3 (24..31) */ |
| 122 | #define SQ930_GPIO_POWER 0x0200 |
| 123 | #define SQ930_GPIO_DFL_LED 0x1000 |
| 124 | |
| 125 | struct ucbus_write_cmd { |
| 126 | u16 bw_addr; |
| 127 | u8 bw_data; |
| 128 | }; |
| 129 | struct i2c_write_cmd { |
| 130 | u8 reg; |
| 131 | u16 val; |
| 132 | }; |
| 133 | |
| 134 | static const struct ucbus_write_cmd icx098bq_start_0[] = { |
| 135 | {0x0354, 0x00}, {0x03fa, 0x00}, {0xf800, 0x02}, {0xf801, 0xce}, |
| 136 | {0xf802, 0xc1}, {0xf804, 0x00}, {0xf808, 0x00}, {0xf809, 0x0e}, |
| 137 | {0xf80a, 0x01}, {0xf80b, 0xee}, {0xf807, 0x60}, {0xf80c, 0x02}, |
| 138 | {0xf80d, 0xf0}, {0xf80e, 0x03}, {0xf80f, 0x0a}, {0xf81c, 0x02}, |
| 139 | {0xf81d, 0xf0}, {0xf81e, 0x03}, {0xf81f, 0x0a}, {0xf83a, 0x00}, |
| 140 | {0xf83b, 0x10}, {0xf83c, 0x00}, {0xf83d, 0x4e}, {0xf810, 0x04}, |
| 141 | {0xf811, 0x00}, {0xf812, 0x02}, {0xf813, 0x10}, {0xf803, 0x00}, |
| 142 | {0xf814, 0x01}, {0xf815, 0x18}, {0xf816, 0x00}, {0xf817, 0x48}, |
| 143 | {0xf818, 0x00}, {0xf819, 0x25}, {0xf81a, 0x00}, {0xf81b, 0x3c}, |
| 144 | {0xf82f, 0x03}, {0xf820, 0xff}, {0xf821, 0x0d}, {0xf822, 0xff}, |
| 145 | {0xf823, 0x07}, {0xf824, 0xff}, {0xf825, 0x03}, {0xf826, 0xff}, |
| 146 | {0xf827, 0x06}, {0xf828, 0xff}, {0xf829, 0x03}, {0xf82a, 0xff}, |
| 147 | {0xf82b, 0x0c}, {0xf82c, 0xfd}, {0xf82d, 0x01}, {0xf82e, 0x00}, |
| 148 | {0xf830, 0x00}, {0xf831, 0x47}, {0xf832, 0x00}, {0xf833, 0x00}, |
| 149 | {0xf850, 0x00}, {0xf851, 0x00}, {0xf852, 0x00}, {0xf853, 0x24}, |
| 150 | {0xf854, 0x00}, {0xf855, 0x18}, {0xf856, 0x00}, {0xf857, 0x3c}, |
| 151 | {0xf858, 0x00}, {0xf859, 0x0c}, {0xf85a, 0x00}, {0xf85b, 0x30}, |
| 152 | {0xf85c, 0x00}, {0xf85d, 0x0c}, {0xf85e, 0x00}, {0xf85f, 0x30}, |
| 153 | {0xf860, 0x00}, {0xf861, 0x48}, {0xf862, 0x01}, {0xf863, 0xdc}, |
| 154 | {0xf864, 0xff}, {0xf865, 0x98}, {0xf866, 0xff}, {0xf867, 0xc0}, |
| 155 | {0xf868, 0xff}, {0xf869, 0x70}, {0xf86c, 0xff}, {0xf86d, 0x00}, |
| 156 | {0xf86a, 0xff}, {0xf86b, 0x48}, {0xf86e, 0xff}, {0xf86f, 0x00}, |
| 157 | {0xf870, 0x01}, {0xf871, 0xdb}, {0xf872, 0x01}, {0xf873, 0xfa}, |
| 158 | {0xf874, 0x01}, {0xf875, 0xdb}, {0xf876, 0x01}, {0xf877, 0xfa}, |
| 159 | {0xf878, 0x0f}, {0xf879, 0x0f}, {0xf87a, 0xff}, {0xf87b, 0xff}, |
| 160 | {0xf800, 0x03} |
| 161 | }; |
| 162 | static const struct ucbus_write_cmd icx098bq_start_1[] = { |
| 163 | {0xf5f0, 0x00}, {0xf5f1, 0xcd}, {0xf5f2, 0x80}, {0xf5f3, 0x80}, |
| 164 | {0xf5f4, 0xc0}, |
| 165 | {0xf5f0, 0x49}, {0xf5f1, 0xcd}, {0xf5f2, 0x80}, {0xf5f3, 0x80}, |
| 166 | {0xf5f4, 0xc0}, |
| 167 | {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00}, |
| 168 | {0xf5f9, 0x00} |
| 169 | }; |
| 170 | |
| 171 | static const struct ucbus_write_cmd icx098bq_start_2[] = { |
| 172 | {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x82}, {0xf806, 0x00}, |
| 173 | {0xf807, 0x7f}, {0xf800, 0x03}, |
| 174 | {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x40}, {0xf806, 0x00}, |
| 175 | {0xf807, 0x7f}, {0xf800, 0x03}, |
| 176 | {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0xcf}, {0xf806, 0xd0}, |
| 177 | {0xf807, 0x7f}, {0xf800, 0x03}, |
| 178 | {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x00}, {0xf806, 0x00}, |
| 179 | {0xf807, 0x7f}, {0xf800, 0x03} |
| 180 | }; |
| 181 | |
| 182 | static const struct ucbus_write_cmd lz24bp_start_0[] = { |
| 183 | {0x0354, 0x00}, {0x03fa, 0x00}, {0xf800, 0x02}, {0xf801, 0xbe}, |
| 184 | {0xf802, 0xc6}, {0xf804, 0x00}, {0xf808, 0x00}, {0xf809, 0x06}, |
| 185 | {0xf80a, 0x01}, {0xf80b, 0xfe}, {0xf807, 0x84}, {0xf80c, 0x02}, |
| 186 | {0xf80d, 0xf7}, {0xf80e, 0x03}, {0xf80f, 0x0b}, {0xf81c, 0x00}, |
| 187 | {0xf81d, 0x49}, {0xf81e, 0x03}, {0xf81f, 0x0b}, {0xf83a, 0x00}, |
| 188 | {0xf83b, 0x01}, {0xf83c, 0x00}, {0xf83d, 0x6b}, {0xf810, 0x03}, |
| 189 | {0xf811, 0x10}, {0xf812, 0x02}, {0xf813, 0x6f}, {0xf803, 0x00}, |
| 190 | {0xf814, 0x00}, {0xf815, 0x44}, {0xf816, 0x00}, {0xf817, 0x48}, |
| 191 | {0xf818, 0x00}, {0xf819, 0x25}, {0xf81a, 0x00}, {0xf81b, 0x3c}, |
| 192 | {0xf82f, 0x03}, {0xf820, 0xff}, {0xf821, 0x0d}, {0xf822, 0xff}, |
| 193 | {0xf823, 0x07}, {0xf824, 0xfd}, {0xf825, 0x07}, {0xf826, 0xf0}, |
| 194 | {0xf827, 0x0c}, {0xf828, 0xff}, {0xf829, 0x03}, {0xf82a, 0xff}, |
| 195 | {0xf82b, 0x0c}, {0xf82c, 0xfc}, {0xf82d, 0x01}, {0xf82e, 0x00}, |
| 196 | {0xf830, 0x00}, {0xf831, 0x47}, {0xf832, 0x00}, {0xf833, 0x00}, |
| 197 | {0xf850, 0x00}, {0xf851, 0x00}, {0xf852, 0x00}, {0xf853, 0x24}, |
| 198 | {0xf854, 0x00}, {0xf855, 0x0c}, {0xf856, 0x00}, {0xf857, 0x30}, |
| 199 | {0xf858, 0x00}, {0xf859, 0x18}, {0xf85a, 0x00}, {0xf85b, 0x3c}, |
| 200 | {0xf85c, 0x00}, {0xf85d, 0x18}, {0xf85e, 0x00}, {0xf85f, 0x3c}, |
| 201 | {0xf860, 0xff}, {0xf861, 0x37}, {0xf862, 0xff}, {0xf863, 0x1d}, |
| 202 | {0xf864, 0xff}, {0xf865, 0x98}, {0xf866, 0xff}, {0xf867, 0xc0}, |
| 203 | {0xf868, 0x00}, {0xf869, 0x37}, {0xf86c, 0x02}, {0xf86d, 0x1d}, |
| 204 | {0xf86a, 0x00}, {0xf86b, 0x37}, {0xf86e, 0x02}, {0xf86f, 0x1d}, |
| 205 | {0xf870, 0x01}, {0xf871, 0xc6}, {0xf872, 0x02}, {0xf873, 0x04}, |
| 206 | {0xf874, 0x01}, {0xf875, 0xc6}, {0xf876, 0x02}, {0xf877, 0x04}, |
| 207 | {0xf878, 0x0f}, {0xf879, 0x0f}, {0xf87a, 0xff}, {0xf87b, 0xff}, |
| 208 | {0xf800, 0x03} |
| 209 | }; |
| 210 | static const struct ucbus_write_cmd lz24bp_start_1_gen[] = { |
| 211 | {0xf5f0, 0x00}, {0xf5f1, 0xff}, {0xf5f2, 0x80}, {0xf5f3, 0x80}, |
| 212 | {0xf5f4, 0xb3}, |
| 213 | {0xf5f0, 0x40}, {0xf5f1, 0xff}, {0xf5f2, 0x80}, {0xf5f3, 0x80}, |
| 214 | {0xf5f4, 0xb3}, |
| 215 | {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00}, |
| 216 | {0xf5f9, 0x00} |
| 217 | }; |
| 218 | |
| 219 | static const struct ucbus_write_cmd lz24bp_start_1_clm[] = { |
| 220 | {0xf5f0, 0x00}, {0xf5f1, 0xff}, {0xf5f2, 0x88}, {0xf5f3, 0x88}, |
| 221 | {0xf5f4, 0xc0}, |
| 222 | {0xf5f0, 0x40}, {0xf5f1, 0xff}, {0xf5f2, 0x88}, {0xf5f3, 0x88}, |
| 223 | {0xf5f4, 0xc0}, |
| 224 | {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00}, |
| 225 | {0xf5f9, 0x00} |
| 226 | }; |
| 227 | |
| 228 | static const struct ucbus_write_cmd lz24bp_start_2[] = { |
| 229 | {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x80}, {0xf806, 0x00}, |
| 230 | {0xf807, 0x7f}, {0xf800, 0x03}, |
| 231 | {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x4e}, {0xf806, 0x00}, |
| 232 | {0xf807, 0x7f}, {0xf800, 0x03}, |
| 233 | {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0xc0}, {0xf806, 0x48}, |
| 234 | {0xf807, 0x7f}, {0xf800, 0x03}, |
| 235 | {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x00}, {0xf806, 0x00}, |
| 236 | {0xf807, 0x7f}, {0xf800, 0x03} |
| 237 | }; |
| 238 | |
| 239 | static const struct ucbus_write_cmd mi0360_start_0[] = { |
| 240 | {0x0354, 0x00}, {0x03fa, 0x00}, {0xf332, 0xcc}, {0xf333, 0xcc}, |
| 241 | {0xf334, 0xcc}, {0xf335, 0xcc}, {0xf33f, 0x00} |
| 242 | }; |
| 243 | static const struct i2c_write_cmd mi0360_init_23[] = { |
| 244 | {0x30, 0x0040}, /* reserved - def 0x0005 */ |
| 245 | {0x31, 0x0000}, /* reserved - def 0x002a */ |
| 246 | {0x34, 0x0100}, /* reserved - def 0x0100 */ |
| 247 | {0x3d, 0x068f}, /* reserved - def 0x068f */ |
| 248 | }; |
| 249 | static const struct i2c_write_cmd mi0360_init_24[] = { |
| 250 | {0x03, 0x01e5}, /* window height */ |
| 251 | {0x04, 0x0285}, /* window width */ |
| 252 | }; |
| 253 | static const struct i2c_write_cmd mi0360_init_25[] = { |
| 254 | {0x35, 0x0020}, /* global gain */ |
| 255 | {0x2b, 0x0020}, /* green1 gain */ |
| 256 | {0x2c, 0x002a}, /* blue gain */ |
| 257 | {0x2d, 0x0028}, /* red gain */ |
| 258 | {0x2e, 0x0020}, /* green2 gain */ |
| 259 | }; |
| 260 | static const struct ucbus_write_cmd mi0360_start_1[] = { |
| 261 | {0xf5f0, 0x11}, {0xf5f1, 0x99}, {0xf5f2, 0x80}, {0xf5f3, 0x80}, |
| 262 | {0xf5f4, 0xa6}, |
| 263 | {0xf5f0, 0x51}, {0xf5f1, 0x99}, {0xf5f2, 0x80}, {0xf5f3, 0x80}, |
| 264 | {0xf5f4, 0xa6}, |
| 265 | {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00}, |
| 266 | {0xf5f9, 0x00} |
| 267 | }; |
| 268 | static const struct i2c_write_cmd mi0360_start_2[] = { |
| 269 | {0x62, 0x041d}, /* reserved - def 0x0418 */ |
| 270 | }; |
| 271 | static const struct i2c_write_cmd mi0360_start_3[] = { |
| 272 | {0x05, 0x007b}, /* horiz blanking */ |
| 273 | }; |
| 274 | static const struct i2c_write_cmd mi0360_start_4[] = { |
| 275 | {0x05, 0x03f5}, /* horiz blanking */ |
| 276 | }; |
| 277 | |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 278 | static const struct i2c_write_cmd mt9v111_init_0[] = { |
Jean-François Moine | 1676e4a | 2010-07-06 05:14:57 -0300 | [diff] [blame] | 279 | {0x01, 0x0001}, /* select IFP/SOC registers */ |
| 280 | {0x06, 0x300c}, /* operating mode control */ |
| 281 | {0x08, 0xcc00}, /* output format control (RGB) */ |
| 282 | {0x01, 0x0004}, /* select core registers */ |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 283 | }; |
| 284 | static const struct i2c_write_cmd mt9v111_init_1[] = { |
Jean-François Moine | 1676e4a | 2010-07-06 05:14:57 -0300 | [diff] [blame] | 285 | {0x03, 0x01e5}, /* window height */ |
| 286 | {0x04, 0x0285}, /* window width */ |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 287 | }; |
| 288 | static const struct i2c_write_cmd mt9v111_init_2[] = { |
| 289 | {0x30, 0x7800}, |
| 290 | {0x31, 0x0000}, |
Jean-François Moine | 1676e4a | 2010-07-06 05:14:57 -0300 | [diff] [blame] | 291 | {0x07, 0x3002}, /* output control */ |
| 292 | {0x35, 0x0020}, /* global gain */ |
| 293 | {0x2b, 0x0020}, /* green1 gain */ |
| 294 | {0x2c, 0x0020}, /* blue gain */ |
| 295 | {0x2d, 0x0020}, /* red gain */ |
| 296 | {0x2e, 0x0020}, /* green2 gain */ |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 297 | }; |
| 298 | static const struct ucbus_write_cmd mt9v111_start_1[] = { |
| 299 | {0xf5f0, 0x11}, {0xf5f1, 0x96}, {0xf5f2, 0x80}, {0xf5f3, 0x80}, |
| 300 | {0xf5f4, 0xaa}, |
| 301 | {0xf5f0, 0x51}, {0xf5f1, 0x96}, {0xf5f2, 0x80}, {0xf5f3, 0x80}, |
| 302 | {0xf5f4, 0xaa}, |
| 303 | {0xf5fa, 0x00}, {0xf5f6, 0x0a}, {0xf5f7, 0x0a}, {0xf5f8, 0x0a}, |
| 304 | {0xf5f9, 0x0a} |
| 305 | }; |
| 306 | static const struct i2c_write_cmd mt9v111_init_3[] = { |
| 307 | {0x62, 0x0405}, |
| 308 | }; |
| 309 | static const struct i2c_write_cmd mt9v111_init_4[] = { |
Jean-François Moine | 585d488 | 2010-07-26 07:25:44 -0300 | [diff] [blame^] | 310 | /* {0x05, 0x00ce}, */ |
| 311 | {0x05, 0x005d}, /* horizontal blanking */ |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 312 | }; |
| 313 | |
| 314 | static const struct ucbus_write_cmd ov7660_start_0[] = { |
| 315 | {0x0354, 0x00}, {0x03fa, 0x00}, {0xf332, 0x00}, {0xf333, 0xc0}, |
| 316 | {0xf334, 0x39}, {0xf335, 0xe7}, {0xf33f, 0x03} |
| 317 | }; |
| 318 | |
| 319 | static const struct ucbus_write_cmd ov9630_start_0[] = { |
| 320 | {0x0354, 0x00}, {0x03fa, 0x00}, {0xf332, 0x00}, {0xf333, 0x00}, |
| 321 | {0xf334, 0x3e}, {0xf335, 0xf8}, {0xf33f, 0x03} |
| 322 | }; |
| 323 | |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 324 | static const struct cap_s { |
| 325 | u8 cc_sizeid; |
| 326 | u8 cc_bytes[32]; |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 327 | } capconfig[4][2] = { |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 328 | [SENSOR_ICX098BQ] = { |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 329 | {2, /* Bayer 320x240 */ |
| 330 | {0x05, 0x1f, 0x20, 0x0e, 0x00, 0x9f, 0x02, 0xee, |
| 331 | 0x01, 0x01, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8, |
| 332 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, |
| 333 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, |
| 334 | {4, /* Bayer 640x480 */ |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 335 | {0x01, 0x1f, 0x20, 0x0e, 0x00, 0x9f, 0x02, 0xee, |
| 336 | 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8, |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 337 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 338 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 339 | }, |
| 340 | [SENSOR_LZ24BP] = { |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 341 | {2, /* Bayer 320x240 */ |
| 342 | {0x05, 0x22, 0x20, 0x0e, 0x00, 0xa2, 0x02, 0xee, |
| 343 | 0x01, 0x01, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8, |
| 344 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 345 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, |
| 346 | {4, /* Bayer 640x480 */ |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 347 | {0x01, 0x22, 0x20, 0x0e, 0x00, 0xa2, 0x02, 0xee, |
| 348 | 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8, |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 349 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 350 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 351 | }, |
| 352 | [SENSOR_MI0360] = { |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 353 | {2, /* Bayer 320x240 */ |
| 354 | {0x05, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe1, |
| 355 | 0x01, 0x01, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8, |
| 356 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 357 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, |
| 358 | {4, /* Bayer 640x480 */ |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 359 | {0x01, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe1, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 360 | 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8, |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 361 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 362 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 363 | }, |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 364 | [SENSOR_MT9V111] = { |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 365 | {2, /* Bayer 320x240 */ |
| 366 | {0x05, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe1, |
| 367 | 0x01, 0x01, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8, |
| 368 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 369 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, |
| 370 | {4, /* Bayer 640x480 */ |
| 371 | {0x01, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe1, |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 372 | 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8, |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 373 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 374 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 375 | }, |
| 376 | }; |
| 377 | |
| 378 | struct sensor_s { |
| 379 | const char *name; |
| 380 | u8 i2c_addr; |
| 381 | u8 i2c_dum; |
| 382 | u8 gpio[5]; |
| 383 | u8 cmd_len; |
| 384 | const struct ucbus_write_cmd *cmd; |
| 385 | }; |
| 386 | |
| 387 | static const struct sensor_s sensor_tb[] = { |
| 388 | [SENSOR_ICX098BQ] = { |
| 389 | "icx098bp", |
| 390 | 0x00, 0x00, |
| 391 | {0, |
| 392 | SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL, |
| 393 | SQ930_GPIO_DFL_I2C_SDA, |
| 394 | 0, |
| 395 | SQ930_GPIO_RSTBAR |
| 396 | }, |
| 397 | 8, icx098bq_start_0 |
| 398 | }, |
| 399 | [SENSOR_LZ24BP] = { |
| 400 | "lz24bp", |
| 401 | 0x00, 0x00, |
| 402 | {0, |
| 403 | SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL, |
| 404 | SQ930_GPIO_DFL_I2C_SDA, |
| 405 | 0, |
| 406 | SQ930_GPIO_RSTBAR |
| 407 | }, |
| 408 | 8, lz24bp_start_0 |
| 409 | }, |
| 410 | [SENSOR_MI0360] = { |
| 411 | "mi0360", |
| 412 | 0x5d, 0x80, |
| 413 | {SQ930_GPIO_RSTBAR, |
| 414 | SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL, |
| 415 | SQ930_GPIO_DFL_I2C_SDA, |
| 416 | 0, |
| 417 | 0 |
| 418 | }, |
| 419 | 7, mi0360_start_0 |
| 420 | }, |
| 421 | [SENSOR_MT9V111] = { |
| 422 | "mt9v111", |
| 423 | 0x5c, 0x7f, |
| 424 | {SQ930_GPIO_RSTBAR, |
| 425 | SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL, |
| 426 | SQ930_GPIO_DFL_I2C_SDA, |
| 427 | 0, |
| 428 | 0 |
| 429 | }, |
| 430 | 7, mi0360_start_0 |
| 431 | }, |
| 432 | [SENSOR_OV7660] = { |
| 433 | "ov7660", |
| 434 | 0x21, 0x00, |
| 435 | {0, |
| 436 | SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL, |
| 437 | SQ930_GPIO_DFL_I2C_SDA, |
| 438 | 0, |
| 439 | SQ930_GPIO_RSTBAR |
| 440 | }, |
| 441 | 7, ov7660_start_0 |
| 442 | }, |
| 443 | [SENSOR_OV9630] = { |
| 444 | "ov9630", |
| 445 | 0x30, 0x00, |
| 446 | {0, |
| 447 | SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL, |
| 448 | SQ930_GPIO_DFL_I2C_SDA, |
| 449 | 0, |
| 450 | SQ930_GPIO_RSTBAR |
| 451 | }, |
| 452 | 7, ov9630_start_0 |
| 453 | }, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 454 | }; |
| 455 | |
| 456 | static void reg_r(struct gspca_dev *gspca_dev, |
| 457 | u16 value, int len) |
| 458 | { |
Jean-François Moine | 7d716a3 | 2010-06-24 04:57:12 -0300 | [diff] [blame] | 459 | int ret; |
| 460 | |
| 461 | if (gspca_dev->usb_err < 0) |
| 462 | return; |
| 463 | ret = usb_control_msg(gspca_dev->dev, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 464 | usb_rcvctrlpipe(gspca_dev->dev, 0), |
| 465 | 0x0c, |
| 466 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 467 | value, 0, gspca_dev->usb_buf, len, |
| 468 | 500); |
Jean-François Moine | 7d716a3 | 2010-06-24 04:57:12 -0300 | [diff] [blame] | 469 | if (ret < 0) { |
| 470 | PDEBUG(D_ERR, "reg_r %04x failed %d", value, ret); |
| 471 | gspca_dev->usb_err = ret; |
| 472 | } |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | static void reg_w(struct gspca_dev *gspca_dev, u16 value, u16 index) |
| 476 | { |
| 477 | int ret; |
| 478 | |
| 479 | if (gspca_dev->usb_err < 0) |
| 480 | return; |
| 481 | PDEBUG(D_USBO, "reg_w v: %04x i: %04x", value, index); |
| 482 | ret = usb_control_msg(gspca_dev->dev, |
| 483 | usb_sndctrlpipe(gspca_dev->dev, 0), |
| 484 | 0x0c, /* request */ |
| 485 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 486 | value, index, NULL, 0, |
| 487 | 500); |
| 488 | msleep(30); |
| 489 | if (ret < 0) { |
| 490 | PDEBUG(D_ERR, "reg_w %04x %04x failed %d", value, index, ret); |
| 491 | gspca_dev->usb_err = ret; |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | static void reg_wb(struct gspca_dev *gspca_dev, u16 value, u16 index, |
| 496 | const u8 *data, int len) |
| 497 | { |
| 498 | int ret; |
| 499 | |
| 500 | if (gspca_dev->usb_err < 0) |
| 501 | return; |
| 502 | PDEBUG(D_USBO, "reg_wb v: %04x i: %04x %02x...%02x", |
| 503 | value, index, *data, data[len - 1]); |
| 504 | memcpy(gspca_dev->usb_buf, data, len); |
| 505 | ret = usb_control_msg(gspca_dev->dev, |
| 506 | usb_sndctrlpipe(gspca_dev->dev, 0), |
| 507 | 0x0c, /* request */ |
| 508 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 509 | value, index, gspca_dev->usb_buf, len, |
| 510 | 1000); |
| 511 | msleep(30); |
| 512 | if (ret < 0) { |
| 513 | PDEBUG(D_ERR, "reg_wb %04x %04x failed %d", value, index, ret); |
| 514 | gspca_dev->usb_err = ret; |
| 515 | } |
| 516 | } |
| 517 | |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 518 | static void i2c_write(struct sd *sd, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 519 | const struct i2c_write_cmd *cmd, |
| 520 | int ncmds) |
| 521 | { |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 522 | struct gspca_dev *gspca_dev = &sd->gspca_dev; |
| 523 | const struct sensor_s *sensor; |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 524 | u16 val, idx; |
| 525 | u8 *buf; |
| 526 | int ret; |
| 527 | |
| 528 | if (gspca_dev->usb_err < 0) |
| 529 | return; |
| 530 | |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 531 | sensor = &sensor_tb[sd->sensor]; |
| 532 | |
| 533 | val = (sensor->i2c_addr << 8) | SQ930_CTRL_I2C_IO; |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 534 | idx = (cmd->val & 0xff00) | cmd->reg; |
| 535 | |
| 536 | buf = gspca_dev->usb_buf; |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 537 | *buf++ = sensor->i2c_dum; |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 538 | *buf++ = cmd->val; |
| 539 | |
| 540 | while (--ncmds > 0) { |
| 541 | cmd++; |
| 542 | *buf++ = cmd->reg; |
| 543 | *buf++ = cmd->val >> 8; |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 544 | *buf++ = sensor->i2c_dum; |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 545 | *buf++ = cmd->val; |
| 546 | } |
| 547 | |
| 548 | PDEBUG(D_USBO, "i2c_w v: %04x i: %04x %02x...%02x", |
| 549 | val, idx, gspca_dev->usb_buf[0], buf[-1]); |
| 550 | ret = usb_control_msg(gspca_dev->dev, |
| 551 | usb_sndctrlpipe(gspca_dev->dev, 0), |
| 552 | 0x0c, /* request */ |
| 553 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 554 | val, idx, |
| 555 | gspca_dev->usb_buf, buf - gspca_dev->usb_buf, |
| 556 | 500); |
| 557 | if (ret < 0) { |
| 558 | PDEBUG(D_ERR, "i2c_write failed %d", ret); |
| 559 | gspca_dev->usb_err = ret; |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | static void ucbus_write(struct gspca_dev *gspca_dev, |
| 564 | const struct ucbus_write_cmd *cmd, |
| 565 | int ncmds, |
| 566 | int batchsize) |
| 567 | { |
| 568 | u8 *buf; |
| 569 | u16 val, idx; |
| 570 | int len, ret; |
| 571 | |
| 572 | if (gspca_dev->usb_err < 0) |
| 573 | return; |
| 574 | |
| 575 | #ifdef GSPCA_DEBUG |
| 576 | if ((batchsize - 1) * 3 > USB_BUF_SZ) { |
| 577 | err("Bug: usb_buf overflow"); |
| 578 | gspca_dev->usb_err = -ENOMEM; |
| 579 | return; |
| 580 | } |
| 581 | #endif |
| 582 | |
| 583 | for (;;) { |
| 584 | len = ncmds; |
| 585 | if (len > batchsize) |
| 586 | len = batchsize; |
| 587 | ncmds -= len; |
| 588 | |
| 589 | val = (cmd->bw_addr << 8) | SQ930_CTRL_UCBUS_IO; |
| 590 | idx = (cmd->bw_data << 8) | (cmd->bw_addr >> 8); |
| 591 | |
| 592 | buf = gspca_dev->usb_buf; |
| 593 | while (--len > 0) { |
| 594 | cmd++; |
| 595 | *buf++ = cmd->bw_addr; |
| 596 | *buf++ = cmd->bw_addr >> 8; |
| 597 | *buf++ = cmd->bw_data; |
| 598 | } |
| 599 | if (buf != gspca_dev->usb_buf) |
| 600 | PDEBUG(D_USBO, "ucbus v: %04x i: %04x %02x...%02x", |
| 601 | val, idx, |
| 602 | gspca_dev->usb_buf[0], buf[-1]); |
| 603 | else |
| 604 | PDEBUG(D_USBO, "ucbus v: %04x i: %04x", |
| 605 | val, idx); |
| 606 | ret = usb_control_msg(gspca_dev->dev, |
| 607 | usb_sndctrlpipe(gspca_dev->dev, 0), |
| 608 | 0x0c, /* request */ |
| 609 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 610 | val, idx, |
| 611 | gspca_dev->usb_buf, buf - gspca_dev->usb_buf, |
| 612 | 500); |
| 613 | if (ret < 0) { |
| 614 | PDEBUG(D_ERR, "ucbus_write failed %d", ret); |
| 615 | gspca_dev->usb_err = ret; |
| 616 | return; |
| 617 | } |
| 618 | msleep(30); |
| 619 | if (ncmds <= 0) |
| 620 | break; |
| 621 | cmd++; |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | static void gpio_set(struct sd *sd, u16 val, u16 mask) |
| 626 | { |
| 627 | struct gspca_dev *gspca_dev = &sd->gspca_dev; |
| 628 | |
| 629 | if (mask & 0x00ff) { |
| 630 | sd->gpio[0] &= ~mask; |
| 631 | sd->gpio[0] |= val; |
| 632 | reg_w(gspca_dev, 0x0100 | SQ930_CTRL_GPIO, |
| 633 | ~sd->gpio[0] << 8); |
| 634 | } |
| 635 | mask >>= 8; |
| 636 | val >>= 8; |
| 637 | if (mask) { |
| 638 | sd->gpio[1] &= ~mask; |
| 639 | sd->gpio[1] |= val; |
| 640 | reg_w(gspca_dev, 0x0300 | SQ930_CTRL_GPIO, |
| 641 | ~sd->gpio[1] << 8); |
| 642 | } |
| 643 | } |
| 644 | |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 645 | static void gpio_init(struct sd *sd, |
| 646 | const u8 *gpio) |
| 647 | { |
| 648 | gpio_set(sd, *gpio++, 0x000f); |
| 649 | gpio_set(sd, *gpio++, 0x000f); |
| 650 | gpio_set(sd, *gpio++, 0x000f); |
| 651 | gpio_set(sd, *gpio++, 0x000f); |
| 652 | gpio_set(sd, *gpio, 0x000f); |
| 653 | } |
| 654 | |
| 655 | static void bridge_init(struct sd *sd) |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 656 | { |
| 657 | static const struct ucbus_write_cmd clkfreq_cmd = { |
| 658 | 0xf031, 0 /* SQ930_CLKFREQ_60MHZ */ |
| 659 | }; |
| 660 | |
| 661 | ucbus_write(&sd->gspca_dev, &clkfreq_cmd, 1, 1); |
| 662 | |
| 663 | gpio_set(sd, SQ930_GPIO_POWER, 0xff00); |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | static void cmos_probe(struct gspca_dev *gspca_dev) |
| 667 | { |
| 668 | struct sd *sd = (struct sd *) gspca_dev; |
| 669 | int i; |
| 670 | const struct sensor_s *sensor; |
| 671 | static const u8 probe_order[] = { |
| 672 | /* SENSOR_LZ24BP, (tested as ccd) */ |
| 673 | SENSOR_OV9630, |
| 674 | SENSOR_MI0360, |
| 675 | SENSOR_OV7660, |
| 676 | SENSOR_MT9V111, |
| 677 | }; |
| 678 | |
| 679 | for (i = 0; i < ARRAY_SIZE(probe_order); i++) { |
| 680 | sensor = &sensor_tb[probe_order[i]]; |
| 681 | ucbus_write(&sd->gspca_dev, sensor->cmd, sensor->cmd_len, 8); |
| 682 | gpio_init(sd, sensor->gpio); |
| 683 | msleep(100); |
| 684 | reg_r(gspca_dev, (sensor->i2c_addr << 8) | 0x001c, 1); |
| 685 | msleep(100); |
| 686 | if (gspca_dev->usb_buf[0] != 0) |
| 687 | break; |
| 688 | } |
| 689 | if (i >= ARRAY_SIZE(probe_order)) |
| 690 | PDEBUG(D_PROBE, "Unknown sensor"); |
| 691 | else |
| 692 | sd->sensor = probe_order[i]; |
| 693 | } |
| 694 | |
| 695 | static void mt9v111_init(struct gspca_dev *gspca_dev) |
| 696 | { |
| 697 | int i, nwait; |
| 698 | static const u8 cmd_001b[] = { |
| 699 | 0x00, 0x3b, 0xf6, 0x01, 0x03, 0x02, 0x00, 0x00, |
| 700 | 0x00, 0x00, 0x00 |
| 701 | }; |
| 702 | static const u8 cmd_011b[][7] = { |
| 703 | {0x10, 0x01, 0x66, 0x08, 0x00, 0x00, 0x00}, |
| 704 | {0x01, 0x00, 0x1a, 0x04, 0x00, 0x00, 0x00}, |
| 705 | {0x20, 0x00, 0x10, 0x04, 0x00, 0x00, 0x00}, |
| 706 | {0x02, 0x01, 0xae, 0x01, 0x00, 0x00, 0x00}, |
| 707 | }; |
| 708 | |
| 709 | reg_wb(gspca_dev, 0x001b, 0x0000, cmd_001b, sizeof cmd_001b); |
| 710 | for (i = 0; i < ARRAY_SIZE(cmd_011b); i++) { |
| 711 | reg_wb(gspca_dev, 0x001b, 0x0000, cmd_011b[i], |
| 712 | ARRAY_SIZE(cmd_011b[0])); |
| 713 | msleep(400); |
| 714 | nwait = 20; |
| 715 | for (;;) { |
| 716 | reg_r(gspca_dev, 0x031b, 1); |
| 717 | if (gspca_dev->usb_buf[0] == 0 |
| 718 | || gspca_dev->usb_err != 0) |
| 719 | break; |
| 720 | if (--nwait < 0) { |
| 721 | PDEBUG(D_PROBE, "mt9v111_init timeout"); |
| 722 | gspca_dev->usb_err = -ETIME; |
| 723 | return; |
| 724 | } |
| 725 | msleep(50); |
| 726 | } |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | static void global_init(struct sd *sd, int first_time) |
| 731 | { |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 732 | switch (sd->sensor) { |
| 733 | case SENSOR_ICX098BQ: |
| 734 | if (first_time) |
| 735 | ucbus_write(&sd->gspca_dev, |
| 736 | icx098bq_start_0, |
| 737 | 8, 8); |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 738 | gpio_init(sd, sensor_tb[sd->sensor].gpio); |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 739 | break; |
| 740 | case SENSOR_LZ24BP: |
| 741 | if (sd->type != Creative_live_motion) |
| 742 | gpio_set(sd, SQ930_GPIO_EXTRA1, 0x00ff); |
| 743 | else |
| 744 | gpio_set(sd, 0, 0x00ff); |
| 745 | msleep(50); |
| 746 | if (first_time) |
| 747 | ucbus_write(&sd->gspca_dev, |
| 748 | lz24bp_start_0, |
| 749 | 8, 8); |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 750 | gpio_init(sd, sensor_tb[sd->sensor].gpio); |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 751 | break; |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 752 | case SENSOR_MI0360: |
| 753 | if (first_time) |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 754 | ucbus_write(&sd->gspca_dev, |
| 755 | mi0360_start_0, |
| 756 | ARRAY_SIZE(mi0360_start_0), |
| 757 | 8); |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 758 | gpio_init(sd, sensor_tb[sd->sensor].gpio); |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 759 | gpio_set(sd, SQ930_GPIO_EXTRA2, SQ930_GPIO_EXTRA2); |
| 760 | break; |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 761 | default: |
| 762 | /* case SENSOR_MT9V111: */ |
| 763 | if (first_time) |
| 764 | mt9v111_init(&sd->gspca_dev); |
| 765 | else |
| 766 | gpio_init(sd, sensor_tb[sd->sensor].gpio); |
| 767 | break; |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 768 | } |
| 769 | } |
| 770 | |
| 771 | static void lz24bp_ppl(struct sd *sd, u16 ppl) |
| 772 | { |
| 773 | struct ucbus_write_cmd cmds[2] = { |
| 774 | {0xf810, ppl >> 8}, |
| 775 | {0xf811, ppl} |
| 776 | }; |
| 777 | |
| 778 | ucbus_write(&sd->gspca_dev, cmds, ARRAY_SIZE(cmds), 2); |
| 779 | } |
| 780 | |
| 781 | static void setexposure(struct gspca_dev *gspca_dev) |
| 782 | { |
| 783 | struct sd *sd = (struct sd *) gspca_dev; |
| 784 | int i, integclks, intstartclk, frameclks, min_frclk; |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 785 | const struct sensor_s *sensor; |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 786 | u16 cmd; |
| 787 | u8 buf[15]; |
| 788 | |
| 789 | integclks = sd->expo; |
| 790 | i = 0; |
| 791 | cmd = SQ930_CTRL_SET_EXPOSURE; |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 792 | |
| 793 | switch (sd->sensor) { |
| 794 | case SENSOR_ICX098BQ: /* ccd */ |
| 795 | case SENSOR_LZ24BP: |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 796 | min_frclk = sd->sensor == SENSOR_ICX098BQ ? 0x210 : 0x26f; |
| 797 | if (integclks >= min_frclk) { |
| 798 | intstartclk = 0; |
| 799 | frameclks = integclks; |
| 800 | } else { |
| 801 | intstartclk = min_frclk - integclks; |
| 802 | frameclks = min_frclk; |
| 803 | } |
| 804 | buf[i++] = intstartclk >> 8; |
| 805 | buf[i++] = intstartclk; |
| 806 | buf[i++] = frameclks >> 8; |
| 807 | buf[i++] = frameclks; |
| 808 | buf[i++] = sd->gain; |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 809 | break; |
| 810 | default: /* cmos */ |
| 811 | /* case SENSOR_MI0360: */ |
| 812 | /* case SENSOR_MT9V111: */ |
| 813 | cmd |= 0x0100; |
| 814 | sensor = &sensor_tb[sd->sensor]; |
| 815 | buf[i++] = sensor->i2c_addr; /* i2c_slave_addr */ |
| 816 | buf[i++] = 0x08; /* 2 * ni2c */ |
| 817 | buf[i++] = 0x09; /* reg = shutter width */ |
| 818 | buf[i++] = integclks >> 8; /* val H */ |
| 819 | buf[i++] = sensor->i2c_dum; |
| 820 | buf[i++] = integclks; /* val L */ |
| 821 | buf[i++] = 0x35; /* reg = global gain */ |
| 822 | buf[i++] = 0x00; /* val H */ |
| 823 | buf[i++] = sensor->i2c_dum; |
Jean-François Moine | b3c0af6 | 2010-07-26 06:58:18 -0300 | [diff] [blame] | 824 | buf[i++] = 0x80 + sd->gain / 2; /* val L */ |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 825 | buf[i++] = 0x00; |
| 826 | buf[i++] = 0x00; |
| 827 | buf[i++] = 0x00; |
| 828 | buf[i++] = 0x00; |
| 829 | buf[i++] = 0x83; |
| 830 | break; |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 831 | } |
| 832 | reg_wb(gspca_dev, cmd, 0, buf, i); |
| 833 | } |
| 834 | |
| 835 | /* This function is called at probe time just before sd_init */ |
| 836 | static int sd_config(struct gspca_dev *gspca_dev, |
| 837 | const struct usb_device_id *id) |
| 838 | { |
| 839 | struct sd *sd = (struct sd *) gspca_dev; |
| 840 | struct cam *cam = &gspca_dev->cam; |
| 841 | |
| 842 | sd->sensor = id->driver_info >> 8; |
| 843 | sd->type = id->driver_info; |
| 844 | |
| 845 | cam->cam_mode = vga_mode; |
| 846 | cam->nmodes = ARRAY_SIZE(vga_mode); |
| 847 | |
| 848 | cam->bulk = 1; |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 849 | |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 850 | sd->gain = GAIN_DEF; |
| 851 | sd->expo = EXPO_DEF; |
| 852 | |
| 853 | return 0; |
| 854 | } |
| 855 | |
| 856 | /* this function is called at probe and resume time */ |
| 857 | static int sd_init(struct gspca_dev *gspca_dev) |
| 858 | { |
| 859 | struct sd *sd = (struct sd *) gspca_dev; |
| 860 | |
| 861 | sd->gpio[0] = sd->gpio[1] = 0xff; /* force gpio rewrite */ |
| 862 | |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 863 | /*fixme: is this needed for icx098bp and mi0360? |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 864 | if (sd->sensor != SENSOR_LZ24BP) |
| 865 | reg_w(gspca_dev, SQ930_CTRL_RESET, 0x0000); |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 866 | */ |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 867 | |
| 868 | reg_r(gspca_dev, SQ930_CTRL_GET_DEV_INFO, 8); |
| 869 | /* it returns: |
| 870 | * 03 00 12 93 0b f6 c9 00 live! ultra |
| 871 | * 03 00 07 93 0b f6 ca 00 live! ultra for notebook |
| 872 | * 03 00 12 93 0b fe c8 00 Trust WB-3500T |
| 873 | * 02 00 06 93 0b fe c8 00 Joy-IT 318S |
| 874 | * 03 00 12 93 0b f6 cf 00 icam tracer - sensor icx098bq |
| 875 | * 02 00 12 93 0b fe cf 00 ProQ Motion Webcam |
| 876 | * |
| 877 | * byte |
| 878 | * 0: 02 = usb 1.0 (12Mbit) / 03 = usb2.0 (480Mbit) |
| 879 | * 1: 00 |
| 880 | * 2: 06 / 07 / 12 = mode webcam? firmware?? |
| 881 | * 3: 93 chip = 930b (930b or 930c) |
| 882 | * 4: 0b |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 883 | * 5: f6 = cdd (icx098bq, lz24bp) / fe or de = cmos (i2c) (other sensors) |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 884 | * 6: c8 / c9 / ca / cf = mode webcam?, sensor? webcam? |
| 885 | * 7: 00 |
| 886 | */ |
| 887 | PDEBUG(D_PROBE, "info: %02x %02x %02x %02x %02x %02x %02x %02x", |
| 888 | gspca_dev->usb_buf[0], |
| 889 | gspca_dev->usb_buf[1], |
| 890 | gspca_dev->usb_buf[2], |
| 891 | gspca_dev->usb_buf[3], |
| 892 | gspca_dev->usb_buf[4], |
| 893 | gspca_dev->usb_buf[5], |
| 894 | gspca_dev->usb_buf[6], |
| 895 | gspca_dev->usb_buf[7]); |
| 896 | |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 897 | bridge_init(sd); |
| 898 | |
| 899 | if (sd->sensor == SENSOR_MI0360) { |
| 900 | |
| 901 | /* no sensor probe for icam tracer */ |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 902 | if (gspca_dev->usb_buf[5] == 0xf6) /* if CMOS */ |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 903 | sd->sensor = SENSOR_ICX098BQ; |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 904 | else |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 905 | cmos_probe(gspca_dev); |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 906 | } |
| 907 | |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 908 | PDEBUG(D_PROBE, "Sensor %s", sensor_tb[sd->sensor].name); |
| 909 | |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 910 | global_init(sd, 1); |
| 911 | return gspca_dev->usb_err; |
| 912 | } |
| 913 | |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 914 | /* send the start/stop commands to the webcam */ |
| 915 | static void send_start(struct gspca_dev *gspca_dev) |
| 916 | { |
| 917 | struct sd *sd = (struct sd *) gspca_dev; |
| 918 | const struct cap_s *cap; |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 919 | int mode; |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 920 | |
| 921 | mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; |
| 922 | cap = &capconfig[sd->sensor][mode]; |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 923 | reg_wb(gspca_dev, 0x0900 | SQ930_CTRL_CAP_START, |
| 924 | 0x0a00 | cap->cc_sizeid, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 925 | cap->cc_bytes, 32); |
| 926 | }; |
| 927 | static void send_stop(struct gspca_dev *gspca_dev) |
| 928 | { |
| 929 | reg_w(gspca_dev, SQ930_CTRL_CAP_STOP, 0); |
| 930 | }; |
| 931 | |
| 932 | /* function called at start time before URB creation */ |
| 933 | static int sd_isoc_init(struct gspca_dev *gspca_dev) |
| 934 | { |
| 935 | struct sd *sd = (struct sd *) gspca_dev; |
| 936 | |
| 937 | gspca_dev->cam.bulk_nurbs = 1; /* there must be one URB only */ |
| 938 | sd->do_ctrl = 0; |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 939 | gspca_dev->cam.bulk_size = gspca_dev->width * gspca_dev->height + 8; |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 940 | return 0; |
| 941 | } |
| 942 | |
| 943 | /* start the capture */ |
| 944 | static int sd_start(struct gspca_dev *gspca_dev) |
| 945 | { |
| 946 | struct sd *sd = (struct sd *) gspca_dev; |
| 947 | int mode; |
| 948 | |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 949 | bridge_init(sd); |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 950 | global_init(sd, 0); |
| 951 | msleep(100); |
| 952 | |
| 953 | switch (sd->sensor) { |
| 954 | case SENSOR_ICX098BQ: |
| 955 | ucbus_write(gspca_dev, icx098bq_start_0, |
| 956 | ARRAY_SIZE(icx098bq_start_0), |
| 957 | 8); |
| 958 | ucbus_write(gspca_dev, icx098bq_start_1, |
| 959 | ARRAY_SIZE(icx098bq_start_1), |
| 960 | 5); |
| 961 | ucbus_write(gspca_dev, icx098bq_start_2, |
| 962 | ARRAY_SIZE(icx098bq_start_2), |
| 963 | 6); |
| 964 | msleep(50); |
| 965 | |
| 966 | /* 1st start */ |
| 967 | send_start(gspca_dev); |
| 968 | gpio_set(sd, SQ930_GPIO_EXTRA2 | SQ930_GPIO_RSTBAR, 0x00ff); |
| 969 | msleep(70); |
| 970 | reg_w(gspca_dev, SQ930_CTRL_CAP_STOP, 0x0000); |
| 971 | gpio_set(sd, 0x7f, 0x00ff); |
| 972 | |
| 973 | /* 2nd start */ |
| 974 | send_start(gspca_dev); |
| 975 | gpio_set(sd, SQ930_GPIO_EXTRA2 | SQ930_GPIO_RSTBAR, 0x00ff); |
| 976 | goto out; |
| 977 | case SENSOR_LZ24BP: |
| 978 | ucbus_write(gspca_dev, lz24bp_start_0, |
| 979 | ARRAY_SIZE(lz24bp_start_0), |
| 980 | 8); |
| 981 | if (sd->type != Creative_live_motion) |
| 982 | ucbus_write(gspca_dev, lz24bp_start_1_gen, |
| 983 | ARRAY_SIZE(lz24bp_start_1_gen), |
| 984 | 5); |
| 985 | else |
| 986 | ucbus_write(gspca_dev, lz24bp_start_1_clm, |
| 987 | ARRAY_SIZE(lz24bp_start_1_clm), |
| 988 | 5); |
| 989 | ucbus_write(gspca_dev, lz24bp_start_2, |
| 990 | ARRAY_SIZE(lz24bp_start_2), |
| 991 | 6); |
| 992 | mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 993 | lz24bp_ppl(sd, mode == 1 ? 0x0564 : 0x0310); |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 994 | msleep(10); |
| 995 | break; |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 996 | case SENSOR_MI0360: |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 997 | ucbus_write(gspca_dev, mi0360_start_0, |
| 998 | ARRAY_SIZE(mi0360_start_0), |
| 999 | 8); |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 1000 | i2c_write(sd, mi0360_init_23, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 1001 | ARRAY_SIZE(mi0360_init_23)); |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 1002 | i2c_write(sd, mi0360_init_24, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 1003 | ARRAY_SIZE(mi0360_init_24)); |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 1004 | i2c_write(sd, mi0360_init_25, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 1005 | ARRAY_SIZE(mi0360_init_25)); |
| 1006 | ucbus_write(gspca_dev, mi0360_start_1, |
| 1007 | ARRAY_SIZE(mi0360_start_1), |
| 1008 | 5); |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 1009 | i2c_write(sd, mi0360_start_2, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 1010 | ARRAY_SIZE(mi0360_start_2)); |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 1011 | i2c_write(sd, mi0360_start_3, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 1012 | ARRAY_SIZE(mi0360_start_3)); |
| 1013 | |
| 1014 | /* 1st start */ |
| 1015 | send_start(gspca_dev); |
| 1016 | msleep(60); |
| 1017 | reg_w(gspca_dev, SQ930_CTRL_CAP_STOP, 0x0000); |
| 1018 | |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 1019 | i2c_write(sd, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 1020 | mi0360_start_4, ARRAY_SIZE(mi0360_start_4)); |
| 1021 | break; |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 1022 | default: |
| 1023 | /* case SENSOR_MT9V111: */ |
| 1024 | ucbus_write(gspca_dev, mi0360_start_0, |
| 1025 | ARRAY_SIZE(mi0360_start_0), |
| 1026 | 8); |
| 1027 | i2c_write(sd, mt9v111_init_0, |
| 1028 | ARRAY_SIZE(mt9v111_init_0)); |
| 1029 | i2c_write(sd, mt9v111_init_1, |
| 1030 | ARRAY_SIZE(mt9v111_init_1)); |
| 1031 | i2c_write(sd, mt9v111_init_2, |
| 1032 | ARRAY_SIZE(mt9v111_init_2)); |
| 1033 | ucbus_write(gspca_dev, mt9v111_start_1, |
| 1034 | ARRAY_SIZE(mt9v111_start_1), |
Jean-François Moine | 4663117 | 2010-07-26 06:50:31 -0300 | [diff] [blame] | 1035 | 5); |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 1036 | i2c_write(sd, mt9v111_init_3, |
| 1037 | ARRAY_SIZE(mt9v111_init_3)); |
| 1038 | i2c_write(sd, mt9v111_init_4, |
| 1039 | ARRAY_SIZE(mt9v111_init_4)); |
| 1040 | break; |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | send_start(gspca_dev); |
| 1044 | out: |
| 1045 | msleep(1000); |
| 1046 | |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 1047 | if (sd->sensor == SENSOR_MT9V111) |
| 1048 | gpio_set(sd, SQ930_GPIO_DFL_LED, SQ930_GPIO_DFL_LED); |
| 1049 | |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 1050 | sd->do_ctrl = 1; /* set the exposure */ |
| 1051 | |
| 1052 | return gspca_dev->usb_err; |
| 1053 | } |
| 1054 | |
| 1055 | static void sd_stopN(struct gspca_dev *gspca_dev) |
| 1056 | { |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 1057 | struct sd *sd = (struct sd *) gspca_dev; |
| 1058 | |
| 1059 | if (sd->sensor == SENSOR_MT9V111) |
| 1060 | gpio_set(sd, 0, SQ930_GPIO_DFL_LED); |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 1061 | send_stop(gspca_dev); |
| 1062 | } |
| 1063 | |
| 1064 | /* function called when the application gets a new frame */ |
| 1065 | /* It sets the exposure if required and restart the bulk transfer. */ |
| 1066 | static void sd_dq_callback(struct gspca_dev *gspca_dev) |
| 1067 | { |
| 1068 | struct sd *sd = (struct sd *) gspca_dev; |
| 1069 | int ret; |
| 1070 | |
| 1071 | if (!sd->do_ctrl || gspca_dev->cam.bulk_nurbs != 0) |
| 1072 | return; |
| 1073 | sd->do_ctrl = 0; |
| 1074 | |
| 1075 | setexposure(gspca_dev); |
| 1076 | |
| 1077 | gspca_dev->cam.bulk_nurbs = 1; |
| 1078 | ret = usb_submit_urb(gspca_dev->urb[0], GFP_ATOMIC); |
| 1079 | if (ret < 0) |
| 1080 | PDEBUG(D_ERR|D_PACK, "sd_dq_callback() err %d", ret); |
| 1081 | |
| 1082 | /* wait a little time, otherwise the webcam crashes */ |
| 1083 | msleep(100); |
| 1084 | } |
| 1085 | |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 1086 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, |
| 1087 | u8 *data, /* isoc packet */ |
| 1088 | int len) /* iso packet length */ |
| 1089 | { |
| 1090 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 1091 | |
Jean-François Moine | 82d2c7a | 2010-07-26 07:23:00 -0300 | [diff] [blame] | 1092 | if (sd->do_ctrl) |
| 1093 | gspca_dev->cam.bulk_nurbs = 0; |
| 1094 | gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0); |
| 1095 | gspca_frame_add(gspca_dev, INTER_PACKET, data, len - 8); |
| 1096 | gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0); |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val) |
| 1100 | { |
| 1101 | struct sd *sd = (struct sd *) gspca_dev; |
| 1102 | |
| 1103 | sd->gain = val; |
| 1104 | if (gspca_dev->streaming) |
| 1105 | sd->do_ctrl = 1; |
| 1106 | return 0; |
| 1107 | } |
| 1108 | |
| 1109 | static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val) |
| 1110 | { |
| 1111 | struct sd *sd = (struct sd *) gspca_dev; |
| 1112 | |
| 1113 | *val = sd->gain; |
| 1114 | return 0; |
| 1115 | } |
| 1116 | static int sd_setexpo(struct gspca_dev *gspca_dev, __s32 val) |
| 1117 | { |
| 1118 | struct sd *sd = (struct sd *) gspca_dev; |
| 1119 | |
| 1120 | sd->expo = val; |
| 1121 | if (gspca_dev->streaming) |
| 1122 | sd->do_ctrl = 1; |
| 1123 | return 0; |
| 1124 | } |
| 1125 | |
| 1126 | static int sd_getexpo(struct gspca_dev *gspca_dev, __s32 *val) |
| 1127 | { |
| 1128 | struct sd *sd = (struct sd *) gspca_dev; |
| 1129 | |
| 1130 | *val = sd->expo; |
| 1131 | return 0; |
| 1132 | } |
| 1133 | |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 1134 | /* sub-driver description */ |
| 1135 | static const struct sd_desc sd_desc = { |
| 1136 | .name = MODULE_NAME, |
| 1137 | .ctrls = sd_ctrls, |
| 1138 | .nctrls = ARRAY_SIZE(sd_ctrls), |
| 1139 | .config = sd_config, |
| 1140 | .init = sd_init, |
| 1141 | .isoc_init = sd_isoc_init, |
| 1142 | .start = sd_start, |
| 1143 | .stopN = sd_stopN, |
| 1144 | .pkt_scan = sd_pkt_scan, |
| 1145 | .dq_callback = sd_dq_callback, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 1146 | }; |
| 1147 | |
| 1148 | /* Table of supported USB devices */ |
| 1149 | #define ST(sensor, type) \ |
| 1150 | .driver_info = (SENSOR_ ## sensor << 8) \ |
| 1151 | | (type) |
| 1152 | static const __devinitdata struct usb_device_id device_table[] = { |
| 1153 | {USB_DEVICE(0x041e, 0x4038), ST(MI0360, 0)}, |
| 1154 | {USB_DEVICE(0x041e, 0x403c), ST(LZ24BP, 0)}, |
| 1155 | {USB_DEVICE(0x041e, 0x403d), ST(LZ24BP, 0)}, |
| 1156 | {USB_DEVICE(0x041e, 0x4041), ST(LZ24BP, Creative_live_motion)}, |
Jean-François Moine | a68f723 | 2010-06-24 05:02:57 -0300 | [diff] [blame] | 1157 | {USB_DEVICE(0x2770, 0x930b), ST(MI0360, 0)}, |
Jean-François Moine | 618a864 | 2010-06-05 07:45:04 -0300 | [diff] [blame] | 1158 | {USB_DEVICE(0x2770, 0x930c), ST(MI0360, 0)}, |
| 1159 | {} |
| 1160 | }; |
| 1161 | MODULE_DEVICE_TABLE(usb, device_table); |
| 1162 | |
| 1163 | |
| 1164 | /* -- device connect -- */ |
| 1165 | static int sd_probe(struct usb_interface *intf, |
| 1166 | const struct usb_device_id *id) |
| 1167 | { |
| 1168 | return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), |
| 1169 | THIS_MODULE); |
| 1170 | } |
| 1171 | |
| 1172 | static struct usb_driver sd_driver = { |
| 1173 | .name = MODULE_NAME, |
| 1174 | .id_table = device_table, |
| 1175 | .probe = sd_probe, |
| 1176 | .disconnect = gspca_disconnect, |
| 1177 | #ifdef CONFIG_PM |
| 1178 | .suspend = gspca_suspend, |
| 1179 | .resume = gspca_resume, |
| 1180 | #endif |
| 1181 | }; |
| 1182 | |
| 1183 | /* -- module insert / remove -- */ |
| 1184 | static int __init sd_mod_init(void) |
| 1185 | { |
| 1186 | int ret; |
| 1187 | |
| 1188 | ret = usb_register(&sd_driver); |
| 1189 | if (ret < 0) |
| 1190 | return ret; |
| 1191 | info("registered"); |
| 1192 | return 0; |
| 1193 | } |
| 1194 | static void __exit sd_mod_exit(void) |
| 1195 | { |
| 1196 | usb_deregister(&sd_driver); |
| 1197 | info("deregistered"); |
| 1198 | } |
| 1199 | |
| 1200 | module_init(sd_mod_init); |
| 1201 | module_exit(sd_mod_exit); |