Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Mars-Semi MR97311A library |
| 3 | * Copyright (C) 2005 <bradlch@hotmail.com> |
| 4 | * |
| 5 | * V4L2 by Jean-Francois Moine <http://moinejf.free.fr> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | */ |
| 21 | |
| 22 | #define MODULE_NAME "mars" |
| 23 | |
| 24 | #include "gspca.h" |
| 25 | #include "jpeg.h" |
| 26 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 27 | MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); |
| 28 | MODULE_DESCRIPTION("GSPCA/Mars USB Camera Driver"); |
| 29 | MODULE_LICENSE("GPL"); |
| 30 | |
| 31 | /* specific webcam descriptor */ |
| 32 | struct sd { |
| 33 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 34 | |
| 35 | u8 brightness; |
| 36 | u8 colors; |
| 37 | u8 gamma; |
| 38 | u8 sharpness; |
Jean-Francois Moine | 71cb276 | 2009-03-03 05:33:41 -0300 | [diff] [blame] | 39 | u8 quality; |
Jean-Francois Moine | 77ac0ba | 2009-03-02 06:40:52 -0300 | [diff] [blame] | 40 | #define QUALITY_MIN 40 |
| 41 | #define QUALITY_MAX 70 |
| 42 | #define QUALITY_DEF 50 |
Jean-Francois Moine | 71cb276 | 2009-03-03 05:33:41 -0300 | [diff] [blame] | 43 | |
| 44 | u8 *jpeg_hdr; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | /* V4L2 controls supported by the driver */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 48 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); |
| 49 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); |
| 50 | static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val); |
| 51 | static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); |
| 52 | static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val); |
| 53 | static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val); |
| 54 | static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); |
| 55 | static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); |
| 56 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 57 | static struct ctrl sd_ctrls[] = { |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 58 | { |
| 59 | { |
| 60 | .id = V4L2_CID_BRIGHTNESS, |
| 61 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 62 | .name = "Brightness", |
| 63 | .minimum = 0, |
| 64 | .maximum = 30, |
| 65 | .step = 1, |
| 66 | #define BRIGHTNESS_DEF 15 |
| 67 | .default_value = BRIGHTNESS_DEF, |
| 68 | }, |
| 69 | .set = sd_setbrightness, |
| 70 | .get = sd_getbrightness, |
| 71 | }, |
| 72 | { |
| 73 | { |
| 74 | .id = V4L2_CID_SATURATION, |
| 75 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 76 | .name = "Color", |
Jean-Francois Moine | 253bae5 | 2009-02-28 08:09:24 -0300 | [diff] [blame] | 77 | .minimum = 1, |
| 78 | .maximum = 255, |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 79 | .step = 1, |
Jean-Francois Moine | 253bae5 | 2009-02-28 08:09:24 -0300 | [diff] [blame] | 80 | #define COLOR_DEF 200 |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 81 | .default_value = COLOR_DEF, |
| 82 | }, |
| 83 | .set = sd_setcolors, |
| 84 | .get = sd_getcolors, |
| 85 | }, |
| 86 | { |
| 87 | { |
| 88 | .id = V4L2_CID_GAMMA, |
| 89 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 90 | .name = "Gamma", |
| 91 | .minimum = 0, |
| 92 | .maximum = 3, |
| 93 | .step = 1, |
| 94 | #define GAMMA_DEF 1 |
| 95 | .default_value = GAMMA_DEF, |
| 96 | }, |
| 97 | .set = sd_setgamma, |
| 98 | .get = sd_getgamma, |
| 99 | }, |
| 100 | { |
| 101 | { |
| 102 | .id = V4L2_CID_SHARPNESS, |
| 103 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 104 | .name = "Sharpness", |
| 105 | .minimum = 0, |
| 106 | .maximum = 2, |
| 107 | .step = 1, |
| 108 | #define SHARPNESS_DEF 1 |
| 109 | .default_value = SHARPNESS_DEF, |
| 110 | }, |
| 111 | .set = sd_setsharpness, |
| 112 | .get = sd_getsharpness, |
| 113 | }, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 114 | }; |
| 115 | |
Jean-Francois Moine | cc611b8 | 2008-12-29 07:49:41 -0300 | [diff] [blame] | 116 | static const struct v4l2_pix_format vga_mode[] = { |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 117 | {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 118 | .bytesperline = 320, |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 119 | .sizeimage = 320 * 240 * 3 / 8 + 590, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 120 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 121 | .priv = 2}, |
| 122 | {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 123 | .bytesperline = 640, |
| 124 | .sizeimage = 640 * 480 * 3 / 8 + 590, |
| 125 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 126 | .priv = 1}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 127 | }; |
| 128 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 129 | static const __u8 mi_data[0x20] = { |
| 130 | /* 01 02 03 04 05 06 07 08 */ |
| 131 | 0x48, 0x22, 0x01, 0x47, 0x10, 0x00, 0x00, 0x00, |
| 132 | /* 09 0a 0b 0c 0d 0e 0f 10 */ |
| 133 | 0x00, 0x01, 0x30, 0x01, 0x30, 0x01, 0x30, 0x01, |
| 134 | /* 11 12 13 14 15 16 17 18 */ |
| 135 | 0x30, 0x00, 0x04, 0x00, 0x06, 0x01, 0xe2, 0x02, |
| 136 | /* 19 1a 1b 1c 1d 1e 1f 20 */ |
| 137 | 0x82, 0x00, 0x20, 0x17, 0x80, 0x08, 0x0c, 0x00 |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 138 | }; |
| 139 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 140 | /* write <len> bytes from gspca_dev->usb_buf */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 141 | static int reg_w(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 142 | int len) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 143 | { |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 144 | int alen, ret; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 145 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 146 | ret = usb_bulk_msg(gspca_dev->dev, |
| 147 | usb_sndbulkpipe(gspca_dev->dev, 4), |
| 148 | gspca_dev->usb_buf, |
| 149 | len, |
| 150 | &alen, |
| 151 | 500); /* timeout in milliseconds */ |
| 152 | if (ret < 0) |
| 153 | PDEBUG(D_ERR, "reg write [%02x] error %d", |
| 154 | gspca_dev->usb_buf[0], ret); |
| 155 | return ret; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 156 | } |
| 157 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 158 | static void mi_w(struct gspca_dev *gspca_dev, |
| 159 | u8 addr, |
| 160 | u8 value) |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 161 | { |
| 162 | gspca_dev->usb_buf[0] = 0x1f; |
| 163 | gspca_dev->usb_buf[1] = 0; /* control byte */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 164 | gspca_dev->usb_buf[2] = addr; |
| 165 | gspca_dev->usb_buf[3] = value; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 166 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 167 | reg_w(gspca_dev, 4); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /* this function is called at probe time */ |
| 171 | static int sd_config(struct gspca_dev *gspca_dev, |
| 172 | const struct usb_device_id *id) |
| 173 | { |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 174 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 175 | struct cam *cam; |
| 176 | |
| 177 | cam = &gspca_dev->cam; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 178 | cam->cam_mode = vga_mode; |
Julia Lawall | 8029712 | 2008-11-12 23:18:21 -0300 | [diff] [blame] | 179 | cam->nmodes = ARRAY_SIZE(vga_mode); |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 180 | sd->brightness = BRIGHTNESS_DEF; |
| 181 | sd->colors = COLOR_DEF; |
| 182 | sd->gamma = GAMMA_DEF; |
| 183 | sd->sharpness = SHARPNESS_DEF; |
Jean-Francois Moine | 77ac0ba | 2009-03-02 06:40:52 -0300 | [diff] [blame] | 184 | sd->quality = QUALITY_DEF; |
Jean-Francois Moine | 625deb3 | 2009-01-15 06:11:49 -0300 | [diff] [blame] | 185 | gspca_dev->nbalt = 9; /* use the altsetting 08 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 186 | return 0; |
| 187 | } |
| 188 | |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 189 | /* this function is called at probe and resume time */ |
| 190 | static int sd_init(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 191 | { |
| 192 | return 0; |
| 193 | } |
| 194 | |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 195 | static int sd_start(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 196 | { |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 197 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 198 | int err_code; |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 199 | u8 *data; |
Jean-Francois Moine | 253bae5 | 2009-02-28 08:09:24 -0300 | [diff] [blame] | 200 | int i; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 201 | |
Jean-Francois Moine | 71cb276 | 2009-03-03 05:33:41 -0300 | [diff] [blame] | 202 | /* create the JPEG header */ |
| 203 | sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL); |
| 204 | jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, |
| 205 | 0x21); /* JPEG 422 */ |
| 206 | jpeg_set_qual(sd->jpeg_hdr, sd->quality); |
| 207 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 208 | data = gspca_dev->usb_buf; |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 209 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 210 | data[0] = 0x01; /* address */ |
| 211 | data[1] = 0x01; |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 212 | err_code = reg_w(gspca_dev, 2); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 213 | if (err_code < 0) |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 214 | return err_code; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 215 | |
| 216 | /* |
| 217 | Initialize the MR97113 chip register |
| 218 | */ |
| 219 | data[0] = 0x00; /* address */ |
| 220 | data[1] = 0x0c | 0x01; /* reg 0 */ |
| 221 | data[2] = 0x01; /* reg 1 */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 222 | data[3] = gspca_dev->width / 8; /* h_size , reg 2 */ |
| 223 | data[4] = gspca_dev->height / 8; /* v_size , reg 3 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 224 | data[5] = 0x30; /* reg 4, MI, PAS5101 : |
| 225 | * 0x30 for 24mhz , 0x28 for 12mhz */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 226 | data[6] = 0x02; /* reg 5, H start - was 0x04 */ |
| 227 | data[7] = sd->gamma * 0x40; /* reg 0x06: gamma */ |
| 228 | data[8] = 0x01; /* reg 7, V start - was 0x03 */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 229 | /* if (h_size == 320 ) */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 230 | /* data[9]= 0x56; * reg 8, 24MHz, 2:1 scale down */ |
| 231 | /* else */ |
| 232 | data[9] = 0x52; /* reg 8, 24MHz, no scale down */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 233 | /*jfm: from win trace*/ |
| 234 | data[10] = 0x18; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 235 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 236 | err_code = reg_w(gspca_dev, 11); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 237 | if (err_code < 0) |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 238 | return err_code; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 239 | |
| 240 | data[0] = 0x23; /* address */ |
| 241 | data[1] = 0x09; /* reg 35, append frame header */ |
| 242 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 243 | err_code = reg_w(gspca_dev, 2); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 244 | if (err_code < 0) |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 245 | return err_code; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 246 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 247 | data[0] = 0x3c; /* address */ |
| 248 | /* if (gspca_dev->width == 1280) */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 249 | /* data[1] = 200; * reg 60, pc-cam frame size |
| 250 | * (unit: 4KB) 800KB */ |
| 251 | /* else */ |
| 252 | data[1] = 50; /* 50 reg 60, pc-cam frame size |
| 253 | * (unit: 4KB) 200KB */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 254 | err_code = reg_w(gspca_dev, 2); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 255 | if (err_code < 0) |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 256 | return err_code; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 257 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 258 | /* auto dark-gain */ |
| 259 | data[0] = 0x5e; /* address */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 260 | data[1] = 0; /* reg 94, Y Gain (auto) */ |
| 261 | /*jfm: from win trace*/ |
Jean-Francois Moine | 253bae5 | 2009-02-28 08:09:24 -0300 | [diff] [blame] | 262 | /* reg 0x5f/0x60 (LE) = saturation */ |
| 263 | /* h (60): xxxx x100 |
| 264 | * l (5f): xxxx x000 */ |
| 265 | data[2] = sd->colors << 3; |
| 266 | data[3] = ((sd->colors >> 2) & 0xf8) | 0x04; |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 267 | data[4] = sd->brightness; /* reg 0x61 = brightness */ |
| 268 | data[5] = 0x00; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 269 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 270 | err_code = reg_w(gspca_dev, 6); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 271 | if (err_code < 0) |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 272 | return err_code; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 273 | |
| 274 | data[0] = 0x67; |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 275 | /*jfm: from win trace*/ |
| 276 | data[1] = sd->sharpness * 4 + 3; |
| 277 | data[2] = 0x14; |
| 278 | err_code = reg_w(gspca_dev, 3); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 279 | if (err_code < 0) |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 280 | return err_code; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 281 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 282 | data[0] = 0x69; |
| 283 | data[1] = 0x2f; |
| 284 | data[2] = 0x28; |
| 285 | data[3] = 0x42; |
| 286 | err_code = reg_w(gspca_dev, 4); |
| 287 | if (err_code < 0) |
| 288 | return err_code; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 289 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 290 | data[0] = 0x63; |
| 291 | data[1] = 0x07; |
| 292 | err_code = reg_w(gspca_dev, 2); |
| 293 | /*jfm: win trace - many writes here to reg 0x64*/ |
| 294 | if (err_code < 0) |
| 295 | return err_code; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 296 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 297 | /* initialize the MI sensor */ |
| 298 | for (i = 0; i < sizeof mi_data; i++) |
| 299 | mi_w(gspca_dev, i + 1, mi_data[i]); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 300 | |
| 301 | data[0] = 0x00; |
| 302 | data[1] = 0x4d; /* ISOC transfering enable... */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 303 | reg_w(gspca_dev, 2); |
| 304 | return 0; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | static void sd_stopN(struct gspca_dev *gspca_dev) |
| 308 | { |
| 309 | int result; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 310 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 311 | gspca_dev->usb_buf[0] = 1; |
| 312 | gspca_dev->usb_buf[1] = 0; |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 313 | result = reg_w(gspca_dev, 2); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 314 | if (result < 0) |
| 315 | PDEBUG(D_ERR, "Camera Stop failed"); |
| 316 | } |
| 317 | |
Jean-Francois Moine | 71cb276 | 2009-03-03 05:33:41 -0300 | [diff] [blame] | 318 | static void sd_stop0(struct gspca_dev *gspca_dev) |
| 319 | { |
| 320 | struct sd *sd = (struct sd *) gspca_dev; |
| 321 | |
| 322 | kfree(sd->jpeg_hdr); |
| 323 | } |
| 324 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 325 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, |
| 326 | struct gspca_frame *frame, /* target */ |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 327 | __u8 *data, /* isoc packet */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 328 | int len) /* iso packet length */ |
| 329 | { |
Jean-Francois Moine | 71cb276 | 2009-03-03 05:33:41 -0300 | [diff] [blame] | 330 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 331 | int p; |
| 332 | |
| 333 | if (len < 6) { |
| 334 | /* gspca_dev->last_packet_type = DISCARD_PACKET; */ |
| 335 | return; |
| 336 | } |
| 337 | for (p = 0; p < len - 6; p++) { |
| 338 | if (data[0 + p] == 0xff |
| 339 | && data[1 + p] == 0xff |
| 340 | && data[2 + p] == 0x00 |
| 341 | && data[3 + p] == 0xff |
| 342 | && data[4 + p] == 0x96) { |
| 343 | if (data[5 + p] == 0x64 |
| 344 | || data[5 + p] == 0x65 |
| 345 | || data[5 + p] == 0x66 |
| 346 | || data[5 + p] == 0x67) { |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 347 | PDEBUG(D_PACK, "sof offset: %d len: %d", |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 348 | p, len); |
| 349 | frame = gspca_frame_add(gspca_dev, LAST_PACKET, |
Jean-Francois Moine | 0a32ef3 | 2009-01-08 16:30:58 -0300 | [diff] [blame] | 350 | frame, data, p); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 351 | |
| 352 | /* put the JPEG header */ |
Jean-Francois Moine | 71cb276 | 2009-03-03 05:33:41 -0300 | [diff] [blame] | 353 | gspca_frame_add(gspca_dev, FIRST_PACKET, frame, |
| 354 | sd->jpeg_hdr, JPEG_HDR_SZ); |
Jean-Francois Moine | 0a32ef3 | 2009-01-08 16:30:58 -0300 | [diff] [blame] | 355 | data += p + 16; |
| 356 | len -= p + 16; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 357 | break; |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len); |
| 362 | } |
| 363 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 364 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) |
| 365 | { |
| 366 | struct sd *sd = (struct sd *) gspca_dev; |
| 367 | |
| 368 | sd->brightness = val; |
| 369 | if (gspca_dev->streaming) { |
| 370 | gspca_dev->usb_buf[0] = 0x61; |
| 371 | gspca_dev->usb_buf[1] = val; |
| 372 | reg_w(gspca_dev, 2); |
| 373 | } |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) |
| 378 | { |
| 379 | struct sd *sd = (struct sd *) gspca_dev; |
| 380 | |
| 381 | *val = sd->brightness; |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val) |
| 386 | { |
| 387 | struct sd *sd = (struct sd *) gspca_dev; |
| 388 | |
| 389 | sd->colors = val; |
| 390 | if (gspca_dev->streaming) { |
Jean-Francois Moine | 253bae5 | 2009-02-28 08:09:24 -0300 | [diff] [blame] | 391 | |
| 392 | /* see sd_start */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 393 | gspca_dev->usb_buf[0] = 0x5f; |
Jean-Francois Moine | 253bae5 | 2009-02-28 08:09:24 -0300 | [diff] [blame] | 394 | gspca_dev->usb_buf[1] = sd->colors << 3; |
| 395 | gspca_dev->usb_buf[2] = ((sd->colors >> 2) & 0xf8) | 0x04; |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 396 | reg_w(gspca_dev, 3); |
| 397 | } |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val) |
| 402 | { |
| 403 | struct sd *sd = (struct sd *) gspca_dev; |
| 404 | |
| 405 | *val = sd->colors; |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val) |
| 410 | { |
| 411 | struct sd *sd = (struct sd *) gspca_dev; |
| 412 | |
| 413 | sd->gamma = val; |
| 414 | if (gspca_dev->streaming) { |
| 415 | gspca_dev->usb_buf[0] = 0x06; |
| 416 | gspca_dev->usb_buf[1] = val * 0x40; |
| 417 | reg_w(gspca_dev, 2); |
| 418 | } |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val) |
| 423 | { |
| 424 | struct sd *sd = (struct sd *) gspca_dev; |
| 425 | |
| 426 | *val = sd->gamma; |
| 427 | return 0; |
| 428 | } |
| 429 | |
| 430 | static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val) |
| 431 | { |
| 432 | struct sd *sd = (struct sd *) gspca_dev; |
| 433 | |
| 434 | sd->sharpness = val; |
| 435 | if (gspca_dev->streaming) { |
| 436 | gspca_dev->usb_buf[0] = 0x67; |
| 437 | gspca_dev->usb_buf[1] = val * 4 + 3; |
| 438 | reg_w(gspca_dev, 2); |
| 439 | } |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val) |
| 444 | { |
| 445 | struct sd *sd = (struct sd *) gspca_dev; |
| 446 | |
| 447 | *val = sd->sharpness; |
| 448 | return 0; |
| 449 | } |
| 450 | |
Jean-Francois Moine | 77ac0ba | 2009-03-02 06:40:52 -0300 | [diff] [blame] | 451 | static int sd_set_jcomp(struct gspca_dev *gspca_dev, |
| 452 | struct v4l2_jpegcompression *jcomp) |
| 453 | { |
| 454 | struct sd *sd = (struct sd *) gspca_dev; |
| 455 | |
| 456 | if (jcomp->quality < QUALITY_MIN) |
| 457 | sd->quality = QUALITY_MIN; |
| 458 | else if (jcomp->quality > QUALITY_MAX) |
| 459 | sd->quality = QUALITY_MAX; |
| 460 | else |
| 461 | sd->quality = jcomp->quality; |
| 462 | if (gspca_dev->streaming) |
| 463 | jpeg_set_qual(sd->jpeg_hdr, sd->quality); |
| 464 | return 0; |
| 465 | } |
| 466 | |
| 467 | static int sd_get_jcomp(struct gspca_dev *gspca_dev, |
| 468 | struct v4l2_jpegcompression *jcomp) |
| 469 | { |
| 470 | struct sd *sd = (struct sd *) gspca_dev; |
| 471 | |
| 472 | memset(jcomp, 0, sizeof *jcomp); |
| 473 | jcomp->quality = sd->quality; |
| 474 | jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT |
| 475 | | V4L2_JPEG_MARKER_DQT; |
| 476 | return 0; |
| 477 | } |
| 478 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 479 | /* sub-driver description */ |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 480 | static const struct sd_desc sd_desc = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 481 | .name = MODULE_NAME, |
| 482 | .ctrls = sd_ctrls, |
| 483 | .nctrls = ARRAY_SIZE(sd_ctrls), |
| 484 | .config = sd_config, |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 485 | .init = sd_init, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 486 | .start = sd_start, |
| 487 | .stopN = sd_stopN, |
Jean-Francois Moine | 71cb276 | 2009-03-03 05:33:41 -0300 | [diff] [blame] | 488 | .stop0 = sd_stop0, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 489 | .pkt_scan = sd_pkt_scan, |
Jean-Francois Moine | 77ac0ba | 2009-03-02 06:40:52 -0300 | [diff] [blame] | 490 | .get_jcomp = sd_get_jcomp, |
| 491 | .set_jcomp = sd_set_jcomp, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 492 | }; |
| 493 | |
| 494 | /* -- module initialisation -- */ |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 495 | static const __devinitdata struct usb_device_id device_table[] = { |
Jean-Francois Moine | 9d64fdb | 2008-07-25 08:53:03 -0300 | [diff] [blame] | 496 | {USB_DEVICE(0x093a, 0x050f)}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 497 | {} |
| 498 | }; |
| 499 | MODULE_DEVICE_TABLE(usb, device_table); |
| 500 | |
| 501 | /* -- device connect -- */ |
| 502 | static int sd_probe(struct usb_interface *intf, |
| 503 | const struct usb_device_id *id) |
| 504 | { |
| 505 | return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), |
| 506 | THIS_MODULE); |
| 507 | } |
| 508 | |
| 509 | static struct usb_driver sd_driver = { |
| 510 | .name = MODULE_NAME, |
| 511 | .id_table = device_table, |
| 512 | .probe = sd_probe, |
| 513 | .disconnect = gspca_disconnect, |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame] | 514 | #ifdef CONFIG_PM |
| 515 | .suspend = gspca_suspend, |
| 516 | .resume = gspca_resume, |
| 517 | #endif |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 518 | }; |
| 519 | |
| 520 | /* -- module insert / remove -- */ |
| 521 | static int __init sd_mod_init(void) |
| 522 | { |
Alexey Klimov | f69e952 | 2009-01-01 13:02:07 -0300 | [diff] [blame] | 523 | int ret; |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 524 | |
Alexey Klimov | f69e952 | 2009-01-01 13:02:07 -0300 | [diff] [blame] | 525 | ret = usb_register(&sd_driver); |
| 526 | if (ret < 0) |
Alexey Klimov | e6b1484 | 2009-01-01 13:04:58 -0300 | [diff] [blame] | 527 | return ret; |
Jean-Francois Moine | 10b0e96 | 2008-07-22 05:35:10 -0300 | [diff] [blame] | 528 | PDEBUG(D_PROBE, "registered"); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 529 | return 0; |
| 530 | } |
| 531 | static void __exit sd_mod_exit(void) |
| 532 | { |
| 533 | usb_deregister(&sd_driver); |
| 534 | PDEBUG(D_PROBE, "deregistered"); |
| 535 | } |
| 536 | |
| 537 | module_init(sd_mod_init); |
| 538 | module_exit(sd_mod_exit); |