Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Syntek DV4000 (STK014) subdriver |
| 3 | * |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 4 | * Copyright (C) 2008 Jean-Francois Moine (http://moinejf.free.fr) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #define MODULE_NAME "stk014" |
| 22 | |
| 23 | #include "gspca.h" |
| 24 | #include "jpeg.h" |
| 25 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 26 | MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>"); |
| 27 | MODULE_DESCRIPTION("Syntek DV4000 (STK014) USB Camera Driver"); |
| 28 | MODULE_LICENSE("GPL"); |
| 29 | |
| 30 | /* specific webcam descriptor */ |
| 31 | struct sd { |
| 32 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
| 33 | |
| 34 | unsigned char brightness; |
| 35 | unsigned char contrast; |
| 36 | unsigned char colors; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 37 | unsigned char lightfreq; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | /* global parameters */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 41 | static int sd_quant = 7; /* <= 4 KO - 7: good (enough!) */ |
| 42 | |
| 43 | /* V4L2 controls supported by the driver */ |
| 44 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); |
| 45 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); |
| 46 | static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); |
| 47 | static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); |
| 48 | static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val); |
| 49 | static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 50 | static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val); |
| 51 | static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 52 | |
| 53 | static struct ctrl sd_ctrls[] = { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 54 | { |
| 55 | { |
| 56 | .id = V4L2_CID_BRIGHTNESS, |
| 57 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 58 | .name = "Brightness", |
| 59 | .minimum = 0, |
| 60 | .maximum = 255, |
| 61 | .step = 1, |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 62 | #define BRIGHTNESS_DEF 127 |
| 63 | .default_value = BRIGHTNESS_DEF, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 64 | }, |
| 65 | .set = sd_setbrightness, |
| 66 | .get = sd_getbrightness, |
| 67 | }, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 68 | { |
| 69 | { |
| 70 | .id = V4L2_CID_CONTRAST, |
| 71 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 72 | .name = "Contrast", |
| 73 | .minimum = 0, |
| 74 | .maximum = 255, |
| 75 | .step = 1, |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 76 | #define CONTRAST_DEF 127 |
| 77 | .default_value = CONTRAST_DEF, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 78 | }, |
| 79 | .set = sd_setcontrast, |
| 80 | .get = sd_getcontrast, |
| 81 | }, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 82 | { |
| 83 | { |
| 84 | .id = V4L2_CID_SATURATION, |
| 85 | .type = V4L2_CTRL_TYPE_INTEGER, |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 86 | .name = "Color", |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 87 | .minimum = 0, |
| 88 | .maximum = 255, |
| 89 | .step = 1, |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 90 | #define COLOR_DEF 127 |
| 91 | .default_value = COLOR_DEF, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 92 | }, |
| 93 | .set = sd_setcolors, |
| 94 | .get = sd_getcolors, |
| 95 | }, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 96 | { |
| 97 | { |
| 98 | .id = V4L2_CID_POWER_LINE_FREQUENCY, |
| 99 | .type = V4L2_CTRL_TYPE_MENU, |
| 100 | .name = "Light frequency filter", |
| 101 | .minimum = 1, |
| 102 | .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */ |
| 103 | .step = 1, |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 104 | #define FREQ_DEF 1 |
| 105 | .default_value = FREQ_DEF, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 106 | }, |
| 107 | .set = sd_setfreq, |
| 108 | .get = sd_getfreq, |
| 109 | }, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 110 | }; |
| 111 | |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 112 | static struct v4l2_pix_format vga_mode[] = { |
| 113 | {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 114 | .bytesperline = 320, |
| 115 | .sizeimage = 320 * 240 * 3 / 8 + 590, |
| 116 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 117 | .priv = 1}, |
| 118 | {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 119 | .bytesperline = 640, |
| 120 | .sizeimage = 640 * 480 * 3 / 8 + 590, |
| 121 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 122 | .priv = 0}, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | /* -- read a register -- */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 126 | static int reg_r(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 127 | __u16 index) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 128 | { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 129 | struct usb_device *dev = gspca_dev->dev; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 130 | int ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 131 | |
| 132 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), |
| 133 | 0x00, |
| 134 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 135 | 0x00, |
| 136 | index, |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 137 | gspca_dev->usb_buf, 1, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 138 | 500); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 139 | if (ret < 0) { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 140 | PDEBUG(D_ERR, "reg_r err %d", ret); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 141 | return ret; |
| 142 | } |
| 143 | return gspca_dev->usb_buf[0]; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /* -- write a register -- */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 147 | static int reg_w(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 148 | __u16 index, __u16 value) |
| 149 | { |
| 150 | struct usb_device *dev = gspca_dev->dev; |
| 151 | int ret; |
| 152 | |
| 153 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
| 154 | 0x01, |
| 155 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 156 | value, |
| 157 | index, |
| 158 | NULL, |
| 159 | 0, |
| 160 | 500); |
| 161 | if (ret < 0) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 162 | PDEBUG(D_ERR, "reg_w err %d", ret); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 163 | return ret; |
| 164 | } |
| 165 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 166 | /* -- get a bulk value (4 bytes) -- */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 167 | static int rcv_val(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 168 | int ads) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 169 | { |
| 170 | struct usb_device *dev = gspca_dev->dev; |
| 171 | int alen, ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 172 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 173 | reg_w(gspca_dev, 0x634, (ads >> 16) & 0xff); |
| 174 | reg_w(gspca_dev, 0x635, (ads >> 8) & 0xff); |
| 175 | reg_w(gspca_dev, 0x636, ads & 0xff); |
| 176 | reg_w(gspca_dev, 0x637, 0); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 177 | reg_w(gspca_dev, 0x638, 4); /* len & 0xff */ |
| 178 | reg_w(gspca_dev, 0x639, 0); /* len >> 8 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 179 | reg_w(gspca_dev, 0x63a, 0); |
| 180 | reg_w(gspca_dev, 0x63b, 0); |
| 181 | reg_w(gspca_dev, 0x630, 5); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 182 | ret = usb_bulk_msg(dev, |
| 183 | usb_rcvbulkpipe(dev, 5), |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 184 | gspca_dev->usb_buf, |
| 185 | 4, /* length */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 186 | &alen, |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 187 | 500); /* timeout in milliseconds */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 188 | return ret; |
| 189 | } |
| 190 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 191 | /* -- send a bulk value -- */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 192 | static int snd_val(struct gspca_dev *gspca_dev, |
| 193 | int ads, |
| 194 | unsigned int val) |
| 195 | { |
| 196 | struct usb_device *dev = gspca_dev->dev; |
| 197 | int alen, ret; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 198 | __u8 seq = 0; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 199 | |
| 200 | if (ads == 0x003f08) { |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 201 | ret = reg_r(gspca_dev, 0x0704); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 202 | if (ret < 0) |
| 203 | goto ko; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 204 | ret = reg_r(gspca_dev, 0x0705); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 205 | if (ret < 0) |
| 206 | goto ko; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 207 | seq = ret; /* keep the sequence number */ |
| 208 | ret = reg_r(gspca_dev, 0x0650); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 209 | if (ret < 0) |
| 210 | goto ko; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 211 | reg_w(gspca_dev, 0x654, seq); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 212 | } else { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 213 | reg_w(gspca_dev, 0x654, (ads >> 16) & 0xff); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 214 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 215 | reg_w(gspca_dev, 0x655, (ads >> 8) & 0xff); |
| 216 | reg_w(gspca_dev, 0x656, ads & 0xff); |
| 217 | reg_w(gspca_dev, 0x657, 0); |
| 218 | reg_w(gspca_dev, 0x658, 0x04); /* size */ |
| 219 | reg_w(gspca_dev, 0x659, 0); |
| 220 | reg_w(gspca_dev, 0x65a, 0); |
| 221 | reg_w(gspca_dev, 0x65b, 0); |
| 222 | reg_w(gspca_dev, 0x650, 5); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 223 | gspca_dev->usb_buf[0] = val >> 24; |
| 224 | gspca_dev->usb_buf[1] = val >> 16; |
| 225 | gspca_dev->usb_buf[2] = val >> 8; |
| 226 | gspca_dev->usb_buf[3] = val; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 227 | ret = usb_bulk_msg(dev, |
| 228 | usb_sndbulkpipe(dev, 6), |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 229 | gspca_dev->usb_buf, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 230 | 4, |
| 231 | &alen, |
| 232 | 500); /* timeout in milliseconds */ |
| 233 | if (ret < 0) |
| 234 | goto ko; |
| 235 | if (ads == 0x003f08) { |
| 236 | seq += 4; |
| 237 | seq &= 0x3f; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 238 | reg_w(gspca_dev, 0x705, seq); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 239 | } |
| 240 | return ret; |
| 241 | ko: |
| 242 | PDEBUG(D_ERR, "snd_val err %d", ret); |
| 243 | return ret; |
| 244 | } |
| 245 | |
| 246 | /* set a camera parameter */ |
| 247 | static int set_par(struct gspca_dev *gspca_dev, |
| 248 | int parval) |
| 249 | { |
| 250 | return snd_val(gspca_dev, 0x003f08, parval); |
| 251 | } |
| 252 | |
| 253 | static void setbrightness(struct gspca_dev *gspca_dev) |
| 254 | { |
| 255 | struct sd *sd = (struct sd *) gspca_dev; |
| 256 | int parval; |
| 257 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 258 | parval = 0x06000000 /* whiteness */ |
| 259 | + (sd->brightness << 16); |
| 260 | set_par(gspca_dev, parval); |
| 261 | } |
| 262 | |
| 263 | static void setcontrast(struct gspca_dev *gspca_dev) |
| 264 | { |
| 265 | struct sd *sd = (struct sd *) gspca_dev; |
| 266 | int parval; |
| 267 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 268 | parval = 0x07000000 /* contrast */ |
| 269 | + (sd->contrast << 16); |
| 270 | set_par(gspca_dev, parval); |
| 271 | } |
| 272 | |
| 273 | static void setcolors(struct gspca_dev *gspca_dev) |
| 274 | { |
| 275 | struct sd *sd = (struct sd *) gspca_dev; |
| 276 | int parval; |
| 277 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 278 | parval = 0x08000000 /* saturation */ |
| 279 | + (sd->colors << 16); |
| 280 | set_par(gspca_dev, parval); |
| 281 | } |
| 282 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 283 | static void setfreq(struct gspca_dev *gspca_dev) |
| 284 | { |
| 285 | struct sd *sd = (struct sd *) gspca_dev; |
| 286 | |
| 287 | set_par(gspca_dev, sd->lightfreq == 1 |
| 288 | ? 0x33640000 /* 50 Hz */ |
| 289 | : 0x33780000); /* 60 Hz */ |
| 290 | } |
| 291 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 292 | /* this function is called at probe time */ |
| 293 | static int sd_config(struct gspca_dev *gspca_dev, |
| 294 | const struct usb_device_id *id) |
| 295 | { |
| 296 | struct sd *sd = (struct sd *) gspca_dev; |
| 297 | struct cam *cam = &gspca_dev->cam; |
| 298 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 299 | cam->epaddr = 0x02; |
| 300 | gspca_dev->cam.cam_mode = vga_mode; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 301 | gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode); |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 302 | sd->brightness = BRIGHTNESS_DEF; |
| 303 | sd->contrast = CONTRAST_DEF; |
| 304 | sd->colors = COLOR_DEF; |
| 305 | sd->lightfreq = FREQ_DEF; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 306 | return 0; |
| 307 | } |
| 308 | |
| 309 | /* this function is called at open time */ |
| 310 | static int sd_open(struct gspca_dev *gspca_dev) |
| 311 | { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 312 | int ret; |
| 313 | |
| 314 | /* check if the device responds */ |
| 315 | usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 316 | ret = reg_r(gspca_dev, 0x0740); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 317 | if (ret < 0) |
| 318 | return ret; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 319 | if (ret != 0xff) { |
| 320 | PDEBUG(D_ERR|D_STREAM, "init reg: 0x%02x", ret); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 321 | return -1; |
| 322 | } |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | /* -- start the camera -- */ |
| 327 | static void sd_start(struct gspca_dev *gspca_dev) |
| 328 | { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 329 | int ret, value; |
| 330 | |
| 331 | /* work on alternate 1 */ |
| 332 | usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1); |
| 333 | |
| 334 | set_par(gspca_dev, 0x10000000); |
| 335 | set_par(gspca_dev, 0x00000000); |
| 336 | set_par(gspca_dev, 0x8002e001); |
| 337 | set_par(gspca_dev, 0x14000000); |
| 338 | if (gspca_dev->width > 320) |
| 339 | value = 0x8002e001; /* 640x480 */ |
| 340 | else |
| 341 | value = 0x4001f000; /* 320x240 */ |
| 342 | set_par(gspca_dev, value); |
| 343 | ret = usb_set_interface(gspca_dev->dev, |
| 344 | gspca_dev->iface, |
| 345 | gspca_dev->alt); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 346 | if (ret < 0) { |
| 347 | PDEBUG(D_ERR|D_STREAM, "set intf %d %d failed", |
| 348 | gspca_dev->iface, gspca_dev->alt); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 349 | goto out; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 350 | } |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 351 | ret = reg_r(gspca_dev, 0x0630); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 352 | if (ret < 0) |
| 353 | goto out; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 354 | rcv_val(gspca_dev, 0x000020); /* << (value ff ff ff ff) */ |
| 355 | ret = reg_r(gspca_dev, 0x0650); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 356 | if (ret < 0) |
| 357 | goto out; |
| 358 | snd_val(gspca_dev, 0x000020, 0xffffffff); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 359 | reg_w(gspca_dev, 0x0620, 0); |
| 360 | reg_w(gspca_dev, 0x0630, 0); |
| 361 | reg_w(gspca_dev, 0x0640, 0); |
| 362 | reg_w(gspca_dev, 0x0650, 0); |
| 363 | reg_w(gspca_dev, 0x0660, 0); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 364 | setbrightness(gspca_dev); /* whiteness */ |
| 365 | setcontrast(gspca_dev); /* contrast */ |
| 366 | setcolors(gspca_dev); /* saturation */ |
| 367 | set_par(gspca_dev, 0x09800000); /* Red ? */ |
| 368 | set_par(gspca_dev, 0x0a800000); /* Green ? */ |
| 369 | set_par(gspca_dev, 0x0b800000); /* Blue ? */ |
| 370 | set_par(gspca_dev, 0x0d030000); /* Gamma ? */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 371 | setfreq(gspca_dev); /* light frequency */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 372 | |
| 373 | /* start the video flow */ |
| 374 | set_par(gspca_dev, 0x01000000); |
| 375 | set_par(gspca_dev, 0x01000000); |
| 376 | PDEBUG(D_STREAM, "camera started alt: 0x%02x", gspca_dev->alt); |
| 377 | return; |
| 378 | out: |
| 379 | PDEBUG(D_ERR|D_STREAM, "camera start err %d", ret); |
| 380 | } |
| 381 | |
| 382 | static void sd_stopN(struct gspca_dev *gspca_dev) |
| 383 | { |
| 384 | struct usb_device *dev = gspca_dev->dev; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 385 | |
| 386 | set_par(gspca_dev, 0x02000000); |
| 387 | set_par(gspca_dev, 0x02000000); |
| 388 | usb_set_interface(dev, gspca_dev->iface, 1); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 389 | reg_r(gspca_dev, 0x0630); |
| 390 | rcv_val(gspca_dev, 0x000020); /* << (value ff ff ff ff) */ |
| 391 | reg_r(gspca_dev, 0x0650); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 392 | snd_val(gspca_dev, 0x000020, 0xffffffff); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 393 | reg_w(gspca_dev, 0x0620, 0); |
| 394 | reg_w(gspca_dev, 0x0630, 0); |
| 395 | reg_w(gspca_dev, 0x0640, 0); |
| 396 | reg_w(gspca_dev, 0x0650, 0); |
| 397 | reg_w(gspca_dev, 0x0660, 0); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 398 | PDEBUG(D_STREAM, "camera stopped"); |
| 399 | } |
| 400 | |
| 401 | static void sd_stop0(struct gspca_dev *gspca_dev) |
| 402 | { |
| 403 | } |
| 404 | |
| 405 | static void sd_close(struct gspca_dev *gspca_dev) |
| 406 | { |
| 407 | } |
| 408 | |
| 409 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, |
| 410 | struct gspca_frame *frame, /* target */ |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 411 | __u8 *data, /* isoc packet */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 412 | int len) /* iso packet length */ |
| 413 | { |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 414 | static unsigned char ffd9[] = {0xff, 0xd9}; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 415 | |
| 416 | /* a frame starts with: |
| 417 | * - 0xff 0xfe |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 418 | * - 0x08 0x00 - length (little endian ?!) |
| 419 | * - 4 bytes = size of whole frame (BE - including header) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 420 | * - 0x00 0x0c |
| 421 | * - 0xff 0xd8 |
| 422 | * - .. JPEG image with escape sequences (ff 00) |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 423 | * (without ending - ff d9) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 424 | */ |
| 425 | if (data[0] == 0xff && data[1] == 0xfe) { |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 426 | frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame, |
| 427 | ffd9, 2); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 428 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 429 | /* put the JPEG 411 header */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 430 | jpeg_put_header(gspca_dev, frame, sd_quant, 0x22); |
| 431 | |
| 432 | /* beginning of the frame */ |
| 433 | #define STKHDRSZ 12 |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 434 | gspca_frame_add(gspca_dev, INTER_PACKET, frame, |
| 435 | data + STKHDRSZ, len - STKHDRSZ); |
| 436 | #undef STKHDRSZ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 437 | return; |
| 438 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 439 | gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) |
| 443 | { |
| 444 | struct sd *sd = (struct sd *) gspca_dev; |
| 445 | |
| 446 | sd->brightness = val; |
| 447 | if (gspca_dev->streaming) |
| 448 | setbrightness(gspca_dev); |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) |
| 453 | { |
| 454 | struct sd *sd = (struct sd *) gspca_dev; |
| 455 | |
| 456 | *val = sd->brightness; |
| 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) |
| 461 | { |
| 462 | struct sd *sd = (struct sd *) gspca_dev; |
| 463 | |
| 464 | sd->contrast = val; |
| 465 | if (gspca_dev->streaming) |
| 466 | setcontrast(gspca_dev); |
| 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) |
| 471 | { |
| 472 | struct sd *sd = (struct sd *) gspca_dev; |
| 473 | |
| 474 | *val = sd->contrast; |
| 475 | return 0; |
| 476 | } |
| 477 | |
| 478 | static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val) |
| 479 | { |
| 480 | struct sd *sd = (struct sd *) gspca_dev; |
| 481 | |
| 482 | sd->colors = val; |
| 483 | if (gspca_dev->streaming) |
| 484 | setcolors(gspca_dev); |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val) |
| 489 | { |
| 490 | struct sd *sd = (struct sd *) gspca_dev; |
| 491 | |
| 492 | *val = sd->colors; |
| 493 | return 0; |
| 494 | } |
| 495 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 496 | static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val) |
| 497 | { |
| 498 | struct sd *sd = (struct sd *) gspca_dev; |
| 499 | |
| 500 | sd->lightfreq = val; |
| 501 | if (gspca_dev->streaming) |
| 502 | setfreq(gspca_dev); |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val) |
| 507 | { |
| 508 | struct sd *sd = (struct sd *) gspca_dev; |
| 509 | |
| 510 | *val = sd->lightfreq; |
| 511 | return 0; |
| 512 | } |
| 513 | |
| 514 | static int sd_querymenu(struct gspca_dev *gspca_dev, |
| 515 | struct v4l2_querymenu *menu) |
| 516 | { |
| 517 | switch (menu->id) { |
| 518 | case V4L2_CID_POWER_LINE_FREQUENCY: |
| 519 | switch (menu->index) { |
| 520 | case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */ |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 521 | strcpy((char *) menu->name, "50 Hz"); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 522 | return 0; |
| 523 | case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */ |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 524 | strcpy((char *) menu->name, "60 Hz"); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 525 | return 0; |
| 526 | } |
| 527 | break; |
| 528 | } |
| 529 | return -EINVAL; |
| 530 | } |
| 531 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 532 | /* sub-driver description */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 533 | static const struct sd_desc sd_desc = { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 534 | .name = MODULE_NAME, |
| 535 | .ctrls = sd_ctrls, |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 536 | .nctrls = ARRAY_SIZE(sd_ctrls), |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 537 | .config = sd_config, |
| 538 | .open = sd_open, |
| 539 | .start = sd_start, |
| 540 | .stopN = sd_stopN, |
| 541 | .stop0 = sd_stop0, |
| 542 | .close = sd_close, |
| 543 | .pkt_scan = sd_pkt_scan, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 544 | .querymenu = sd_querymenu, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 545 | }; |
| 546 | |
| 547 | /* -- module initialisation -- */ |
| 548 | #define DVNM(name) .driver_info = (kernel_ulong_t) name |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 549 | static const __devinitdata struct usb_device_id device_table[] = { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 550 | {USB_DEVICE(0x05e1, 0x0893), DVNM("Syntek DV4000")}, |
| 551 | {} |
| 552 | }; |
| 553 | MODULE_DEVICE_TABLE(usb, device_table); |
| 554 | |
| 555 | /* -- device connect -- */ |
| 556 | static int sd_probe(struct usb_interface *intf, |
| 557 | const struct usb_device_id *id) |
| 558 | { |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 559 | return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), |
| 560 | THIS_MODULE); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | static struct usb_driver sd_driver = { |
| 564 | .name = MODULE_NAME, |
| 565 | .id_table = device_table, |
| 566 | .probe = sd_probe, |
| 567 | .disconnect = gspca_disconnect, |
| 568 | }; |
| 569 | |
| 570 | /* -- module insert / remove -- */ |
| 571 | static int __init sd_mod_init(void) |
| 572 | { |
| 573 | if (usb_register(&sd_driver) < 0) |
| 574 | return -1; |
Jean-Francois Moine | 10b0e96 | 2008-07-22 05:35:10 -0300 | [diff] [blame] | 575 | info("registered"); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 576 | return 0; |
| 577 | } |
| 578 | static void __exit sd_mod_exit(void) |
| 579 | { |
| 580 | usb_deregister(&sd_driver); |
| 581 | info("deregistered"); |
| 582 | } |
| 583 | |
| 584 | module_init(sd_mod_init); |
| 585 | module_exit(sd_mod_exit); |
| 586 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 587 | module_param_named(quant, sd_quant, int, 0644); |
| 588 | MODULE_PARM_DESC(quant, "Quantization index (0..8)"); |