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 | |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 23 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 24 | #define MODULE_NAME "mars" |
| 25 | |
| 26 | #include "gspca.h" |
| 27 | #include "jpeg.h" |
| 28 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 29 | MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); |
| 30 | MODULE_DESCRIPTION("GSPCA/Mars USB Camera Driver"); |
| 31 | MODULE_LICENSE("GPL"); |
| 32 | |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 33 | /* controls */ |
| 34 | enum e_ctrl { |
| 35 | BRIGHTNESS, |
| 36 | COLORS, |
| 37 | GAMMA, |
| 38 | SHARPNESS, |
Jean-François Moine | fba3980 | 2010-10-16 14:12:53 -0300 | [diff] [blame] | 39 | ILLUM_TOP, |
| 40 | ILLUM_BOT, |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 41 | NCTRLS /* number of controls */ |
| 42 | }; |
| 43 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 44 | /* specific webcam descriptor */ |
| 45 | struct sd { |
| 46 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 47 | |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 48 | struct gspca_ctrl ctrls[NCTRLS]; |
| 49 | |
Jean-Francois Moine | 71cb276 | 2009-03-03 05:33:41 -0300 | [diff] [blame] | 50 | u8 quality; |
Jean-Francois Moine | 77ac0ba | 2009-03-02 06:40:52 -0300 | [diff] [blame] | 51 | #define QUALITY_MIN 40 |
| 52 | #define QUALITY_MAX 70 |
| 53 | #define QUALITY_DEF 50 |
Jean-Francois Moine | 71cb276 | 2009-03-03 05:33:41 -0300 | [diff] [blame] | 54 | |
Jean-François Moine | 9a731a3 | 2010-06-04 05:26:42 -0300 | [diff] [blame] | 55 | u8 jpeg_hdr[JPEG_HDR_SZ]; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | /* V4L2 controls supported by the driver */ |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 59 | static void setbrightness(struct gspca_dev *gspca_dev); |
| 60 | static void setcolors(struct gspca_dev *gspca_dev); |
| 61 | static void setgamma(struct gspca_dev *gspca_dev); |
| 62 | static void setsharpness(struct gspca_dev *gspca_dev); |
Jean-François Moine | fba3980 | 2010-10-16 14:12:53 -0300 | [diff] [blame] | 63 | static int sd_setilluminator1(struct gspca_dev *gspca_dev, __s32 val); |
| 64 | static int sd_setilluminator2(struct gspca_dev *gspca_dev, __s32 val); |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 65 | |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 66 | static const struct ctrl sd_ctrls[NCTRLS] = { |
| 67 | [BRIGHTNESS] = { |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 68 | { |
| 69 | .id = V4L2_CID_BRIGHTNESS, |
| 70 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 71 | .name = "Brightness", |
| 72 | .minimum = 0, |
| 73 | .maximum = 30, |
| 74 | .step = 1, |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 75 | .default_value = 15, |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 76 | }, |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 77 | .set_control = setbrightness |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 78 | }, |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 79 | [COLORS] = { |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 80 | { |
| 81 | .id = V4L2_CID_SATURATION, |
| 82 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 83 | .name = "Color", |
Jean-Francois Moine | 253bae5 | 2009-02-28 08:09:24 -0300 | [diff] [blame] | 84 | .minimum = 1, |
| 85 | .maximum = 255, |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 86 | .step = 1, |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 87 | .default_value = 200, |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 88 | }, |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 89 | .set_control = setcolors |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 90 | }, |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 91 | [GAMMA] = { |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 92 | { |
| 93 | .id = V4L2_CID_GAMMA, |
| 94 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 95 | .name = "Gamma", |
| 96 | .minimum = 0, |
| 97 | .maximum = 3, |
| 98 | .step = 1, |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 99 | .default_value = 1, |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 100 | }, |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 101 | .set_control = setgamma |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 102 | }, |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 103 | [SHARPNESS] = { |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 104 | { |
| 105 | .id = V4L2_CID_SHARPNESS, |
| 106 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 107 | .name = "Sharpness", |
| 108 | .minimum = 0, |
| 109 | .maximum = 2, |
| 110 | .step = 1, |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 111 | .default_value = 1, |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 112 | }, |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 113 | .set_control = setsharpness |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 114 | }, |
Jean-François Moine | fba3980 | 2010-10-16 14:12:53 -0300 | [diff] [blame] | 115 | [ILLUM_TOP] = { |
| 116 | { |
| 117 | .id = V4L2_CID_ILLUMINATORS_1, |
| 118 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 119 | .name = "Top illuminator", |
| 120 | .minimum = 0, |
| 121 | .maximum = 1, |
| 122 | .step = 1, |
| 123 | .default_value = 0, |
| 124 | .flags = V4L2_CTRL_FLAG_UPDATE, |
| 125 | }, |
| 126 | .set = sd_setilluminator1 |
| 127 | }, |
| 128 | [ILLUM_BOT] = { |
| 129 | { |
| 130 | .id = V4L2_CID_ILLUMINATORS_2, |
| 131 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 132 | .name = "Bottom illuminator", |
| 133 | .minimum = 0, |
| 134 | .maximum = 1, |
| 135 | .step = 1, |
| 136 | .default_value = 0, |
| 137 | .flags = V4L2_CTRL_FLAG_UPDATE, |
| 138 | }, |
| 139 | .set = sd_setilluminator2 |
| 140 | }, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 141 | }; |
| 142 | |
Jean-Francois Moine | cc611b8 | 2008-12-29 07:49:41 -0300 | [diff] [blame] | 143 | static const struct v4l2_pix_format vga_mode[] = { |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 144 | {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 145 | .bytesperline = 320, |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 146 | .sizeimage = 320 * 240 * 3 / 8 + 590, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 147 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 148 | .priv = 2}, |
| 149 | {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 150 | .bytesperline = 640, |
| 151 | .sizeimage = 640 * 480 * 3 / 8 + 590, |
| 152 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 153 | .priv = 1}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 154 | }; |
| 155 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 156 | static const __u8 mi_data[0x20] = { |
| 157 | /* 01 02 03 04 05 06 07 08 */ |
| 158 | 0x48, 0x22, 0x01, 0x47, 0x10, 0x00, 0x00, 0x00, |
| 159 | /* 09 0a 0b 0c 0d 0e 0f 10 */ |
| 160 | 0x00, 0x01, 0x30, 0x01, 0x30, 0x01, 0x30, 0x01, |
| 161 | /* 11 12 13 14 15 16 17 18 */ |
| 162 | 0x30, 0x00, 0x04, 0x00, 0x06, 0x01, 0xe2, 0x02, |
| 163 | /* 19 1a 1b 1c 1d 1e 1f 20 */ |
| 164 | 0x82, 0x00, 0x20, 0x17, 0x80, 0x08, 0x0c, 0x00 |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 165 | }; |
| 166 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 167 | /* write <len> bytes from gspca_dev->usb_buf */ |
Jean-François Moine | d401549 | 2010-10-16 14:10:59 -0300 | [diff] [blame] | 168 | static void reg_w(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 169 | int len) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 170 | { |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 171 | int alen, ret; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 172 | |
Jean-François Moine | d401549 | 2010-10-16 14:10:59 -0300 | [diff] [blame] | 173 | if (gspca_dev->usb_err < 0) |
| 174 | return; |
| 175 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 176 | ret = usb_bulk_msg(gspca_dev->dev, |
| 177 | usb_sndbulkpipe(gspca_dev->dev, 4), |
| 178 | gspca_dev->usb_buf, |
| 179 | len, |
| 180 | &alen, |
| 181 | 500); /* timeout in milliseconds */ |
Jean-François Moine | d401549 | 2010-10-16 14:10:59 -0300 | [diff] [blame] | 182 | if (ret < 0) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 183 | pr_err("reg write [%02x] error %d\n", |
| 184 | gspca_dev->usb_buf[0], ret); |
Jean-François Moine | d401549 | 2010-10-16 14:10:59 -0300 | [diff] [blame] | 185 | gspca_dev->usb_err = ret; |
| 186 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 187 | } |
| 188 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 189 | static void mi_w(struct gspca_dev *gspca_dev, |
| 190 | u8 addr, |
| 191 | u8 value) |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 192 | { |
| 193 | gspca_dev->usb_buf[0] = 0x1f; |
| 194 | gspca_dev->usb_buf[1] = 0; /* control byte */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 195 | gspca_dev->usb_buf[2] = addr; |
| 196 | gspca_dev->usb_buf[3] = value; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 197 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 198 | reg_w(gspca_dev, 4); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 199 | } |
| 200 | |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 201 | static void setbrightness(struct gspca_dev *gspca_dev) |
| 202 | { |
| 203 | struct sd *sd = (struct sd *) gspca_dev; |
| 204 | |
| 205 | gspca_dev->usb_buf[0] = 0x61; |
| 206 | gspca_dev->usb_buf[1] = sd->ctrls[BRIGHTNESS].val; |
| 207 | reg_w(gspca_dev, 2); |
| 208 | } |
| 209 | |
| 210 | static void setcolors(struct gspca_dev *gspca_dev) |
| 211 | { |
| 212 | struct sd *sd = (struct sd *) gspca_dev; |
| 213 | s16 val; |
| 214 | |
| 215 | val = sd->ctrls[COLORS].val; |
| 216 | gspca_dev->usb_buf[0] = 0x5f; |
| 217 | gspca_dev->usb_buf[1] = val << 3; |
| 218 | gspca_dev->usb_buf[2] = ((val >> 2) & 0xf8) | 0x04; |
| 219 | reg_w(gspca_dev, 3); |
| 220 | } |
| 221 | |
| 222 | static void setgamma(struct gspca_dev *gspca_dev) |
| 223 | { |
| 224 | struct sd *sd = (struct sd *) gspca_dev; |
| 225 | |
| 226 | gspca_dev->usb_buf[0] = 0x06; |
| 227 | gspca_dev->usb_buf[1] = sd->ctrls[GAMMA].val * 0x40; |
| 228 | reg_w(gspca_dev, 2); |
| 229 | } |
| 230 | |
| 231 | static void setsharpness(struct gspca_dev *gspca_dev) |
| 232 | { |
| 233 | struct sd *sd = (struct sd *) gspca_dev; |
| 234 | |
| 235 | gspca_dev->usb_buf[0] = 0x67; |
| 236 | gspca_dev->usb_buf[1] = sd->ctrls[SHARPNESS].val * 4 + 3; |
| 237 | reg_w(gspca_dev, 2); |
| 238 | } |
| 239 | |
Jean-François Moine | fba3980 | 2010-10-16 14:12:53 -0300 | [diff] [blame] | 240 | static void setilluminators(struct gspca_dev *gspca_dev) |
| 241 | { |
| 242 | struct sd *sd = (struct sd *) gspca_dev; |
| 243 | |
| 244 | gspca_dev->usb_buf[0] = 0x22; |
| 245 | if (sd->ctrls[ILLUM_TOP].val) |
| 246 | gspca_dev->usb_buf[1] = 0x76; |
| 247 | else if (sd->ctrls[ILLUM_BOT].val) |
| 248 | gspca_dev->usb_buf[1] = 0x7a; |
| 249 | else |
| 250 | gspca_dev->usb_buf[1] = 0x7e; |
| 251 | reg_w(gspca_dev, 2); |
| 252 | } |
| 253 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 254 | /* this function is called at probe time */ |
| 255 | static int sd_config(struct gspca_dev *gspca_dev, |
| 256 | const struct usb_device_id *id) |
| 257 | { |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 258 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 259 | struct cam *cam; |
| 260 | |
| 261 | cam = &gspca_dev->cam; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 262 | cam->cam_mode = vga_mode; |
Julia Lawall | 8029712 | 2008-11-12 23:18:21 -0300 | [diff] [blame] | 263 | cam->nmodes = ARRAY_SIZE(vga_mode); |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 264 | cam->ctrls = sd->ctrls; |
Jean-Francois Moine | 77ac0ba | 2009-03-02 06:40:52 -0300 | [diff] [blame] | 265 | sd->quality = QUALITY_DEF; |
Jean-Francois Moine | 625deb3 | 2009-01-15 06:11:49 -0300 | [diff] [blame] | 266 | gspca_dev->nbalt = 9; /* use the altsetting 08 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 267 | return 0; |
| 268 | } |
| 269 | |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 270 | /* this function is called at probe and resume time */ |
| 271 | static int sd_init(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 272 | { |
Jean-François Moine | fba3980 | 2010-10-16 14:12:53 -0300 | [diff] [blame] | 273 | gspca_dev->ctrl_inac = (1 << ILLUM_TOP) | (1 << ILLUM_BOT); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 274 | return 0; |
| 275 | } |
| 276 | |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 277 | static int sd_start(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 278 | { |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 279 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 280 | u8 *data; |
Jean-Francois Moine | 253bae5 | 2009-02-28 08:09:24 -0300 | [diff] [blame] | 281 | int i; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 282 | |
Jean-Francois Moine | 71cb276 | 2009-03-03 05:33:41 -0300 | [diff] [blame] | 283 | /* create the JPEG header */ |
Jean-Francois Moine | 71cb276 | 2009-03-03 05:33:41 -0300 | [diff] [blame] | 284 | jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, |
| 285 | 0x21); /* JPEG 422 */ |
| 286 | jpeg_set_qual(sd->jpeg_hdr, sd->quality); |
| 287 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 288 | data = gspca_dev->usb_buf; |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 289 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 290 | data[0] = 0x01; /* address */ |
| 291 | data[1] = 0x01; |
Jean-François Moine | d401549 | 2010-10-16 14:10:59 -0300 | [diff] [blame] | 292 | reg_w(gspca_dev, 2); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 293 | |
| 294 | /* |
| 295 | Initialize the MR97113 chip register |
| 296 | */ |
| 297 | data[0] = 0x00; /* address */ |
| 298 | data[1] = 0x0c | 0x01; /* reg 0 */ |
| 299 | data[2] = 0x01; /* reg 1 */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 300 | data[3] = gspca_dev->width / 8; /* h_size , reg 2 */ |
| 301 | data[4] = gspca_dev->height / 8; /* v_size , reg 3 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 302 | data[5] = 0x30; /* reg 4, MI, PAS5101 : |
| 303 | * 0x30 for 24mhz , 0x28 for 12mhz */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 304 | data[6] = 0x02; /* reg 5, H start - was 0x04 */ |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 305 | data[7] = sd->ctrls[GAMMA].val * 0x40; /* reg 0x06: gamma */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 306 | data[8] = 0x01; /* reg 7, V start - was 0x03 */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 307 | /* if (h_size == 320 ) */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 308 | /* data[9]= 0x56; * reg 8, 24MHz, 2:1 scale down */ |
| 309 | /* else */ |
| 310 | data[9] = 0x52; /* reg 8, 24MHz, no scale down */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 311 | /*jfm: from win trace*/ |
| 312 | data[10] = 0x18; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 313 | |
Jean-François Moine | d401549 | 2010-10-16 14:10:59 -0300 | [diff] [blame] | 314 | reg_w(gspca_dev, 11); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 315 | |
| 316 | data[0] = 0x23; /* address */ |
| 317 | data[1] = 0x09; /* reg 35, append frame header */ |
| 318 | |
Jean-François Moine | d401549 | 2010-10-16 14:10:59 -0300 | [diff] [blame] | 319 | reg_w(gspca_dev, 2); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 320 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 321 | data[0] = 0x3c; /* address */ |
| 322 | /* if (gspca_dev->width == 1280) */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 323 | /* data[1] = 200; * reg 60, pc-cam frame size |
| 324 | * (unit: 4KB) 800KB */ |
| 325 | /* else */ |
| 326 | data[1] = 50; /* 50 reg 60, pc-cam frame size |
| 327 | * (unit: 4KB) 200KB */ |
Jean-François Moine | d401549 | 2010-10-16 14:10:59 -0300 | [diff] [blame] | 328 | reg_w(gspca_dev, 2); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 329 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 330 | /* auto dark-gain */ |
| 331 | data[0] = 0x5e; /* address */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 332 | data[1] = 0; /* reg 94, Y Gain (auto) */ |
| 333 | /*jfm: from win trace*/ |
Jean-Francois Moine | 253bae5 | 2009-02-28 08:09:24 -0300 | [diff] [blame] | 334 | /* reg 0x5f/0x60 (LE) = saturation */ |
| 335 | /* h (60): xxxx x100 |
| 336 | * l (5f): xxxx x000 */ |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 337 | data[2] = sd->ctrls[COLORS].val << 3; |
| 338 | data[3] = ((sd->ctrls[COLORS].val >> 2) & 0xf8) | 0x04; |
| 339 | data[4] = sd->ctrls[BRIGHTNESS].val; /* reg 0x61 = brightness */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 340 | data[5] = 0x00; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 341 | |
Jean-François Moine | d401549 | 2010-10-16 14:10:59 -0300 | [diff] [blame] | 342 | reg_w(gspca_dev, 6); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 343 | |
| 344 | data[0] = 0x67; |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 345 | /*jfm: from win trace*/ |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 346 | data[1] = sd->ctrls[SHARPNESS].val * 4 + 3; |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 347 | data[2] = 0x14; |
Jean-François Moine | d401549 | 2010-10-16 14:10:59 -0300 | [diff] [blame] | 348 | reg_w(gspca_dev, 3); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 349 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 350 | data[0] = 0x69; |
| 351 | data[1] = 0x2f; |
| 352 | data[2] = 0x28; |
| 353 | data[3] = 0x42; |
Jean-François Moine | d401549 | 2010-10-16 14:10:59 -0300 | [diff] [blame] | 354 | reg_w(gspca_dev, 4); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 355 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 356 | data[0] = 0x63; |
| 357 | data[1] = 0x07; |
Jean-François Moine | d401549 | 2010-10-16 14:10:59 -0300 | [diff] [blame] | 358 | reg_w(gspca_dev, 2); |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 359 | /*jfm: win trace - many writes here to reg 0x64*/ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 360 | |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 361 | /* initialize the MI sensor */ |
| 362 | for (i = 0; i < sizeof mi_data; i++) |
| 363 | mi_w(gspca_dev, i + 1, mi_data[i]); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 364 | |
| 365 | data[0] = 0x00; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 366 | data[1] = 0x4d; /* ISOC transferring enable... */ |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 367 | reg_w(gspca_dev, 2); |
Jean-François Moine | d401549 | 2010-10-16 14:10:59 -0300 | [diff] [blame] | 368 | |
Jean-François Moine | fba3980 | 2010-10-16 14:12:53 -0300 | [diff] [blame] | 369 | gspca_dev->ctrl_inac = 0; /* activate the illuminator controls */ |
Jean-François Moine | d401549 | 2010-10-16 14:10:59 -0300 | [diff] [blame] | 370 | return gspca_dev->usb_err; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | static void sd_stopN(struct gspca_dev *gspca_dev) |
| 374 | { |
Jean-François Moine | fba3980 | 2010-10-16 14:12:53 -0300 | [diff] [blame] | 375 | struct sd *sd = (struct sd *) gspca_dev; |
| 376 | |
| 377 | gspca_dev->ctrl_inac = (1 << ILLUM_TOP) | (1 << ILLUM_BOT); |
| 378 | if (sd->ctrls[ILLUM_TOP].val || sd->ctrls[ILLUM_BOT].val) { |
| 379 | sd->ctrls[ILLUM_TOP].val = 0; |
| 380 | sd->ctrls[ILLUM_BOT].val = 0; |
| 381 | setilluminators(gspca_dev); |
| 382 | msleep(20); |
| 383 | } |
| 384 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 385 | gspca_dev->usb_buf[0] = 1; |
| 386 | gspca_dev->usb_buf[1] = 0; |
Jean-François Moine | d401549 | 2010-10-16 14:10:59 -0300 | [diff] [blame] | 387 | reg_w(gspca_dev, 2); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 388 | } |
| 389 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 390 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 391 | u8 *data, /* isoc packet */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 392 | int len) /* iso packet length */ |
| 393 | { |
Jean-Francois Moine | 71cb276 | 2009-03-03 05:33:41 -0300 | [diff] [blame] | 394 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 395 | int p; |
| 396 | |
| 397 | if (len < 6) { |
| 398 | /* gspca_dev->last_packet_type = DISCARD_PACKET; */ |
| 399 | return; |
| 400 | } |
| 401 | for (p = 0; p < len - 6; p++) { |
| 402 | if (data[0 + p] == 0xff |
| 403 | && data[1 + p] == 0xff |
| 404 | && data[2 + p] == 0x00 |
| 405 | && data[3 + p] == 0xff |
| 406 | && data[4 + p] == 0x96) { |
| 407 | if (data[5 + p] == 0x64 |
| 408 | || data[5 + p] == 0x65 |
| 409 | || data[5 + p] == 0x66 |
| 410 | || data[5 + p] == 0x67) { |
Jean-Francois Moine | a0306bf | 2009-01-08 16:29:38 -0300 | [diff] [blame] | 411 | PDEBUG(D_PACK, "sof offset: %d len: %d", |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 412 | p, len); |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 413 | gspca_frame_add(gspca_dev, LAST_PACKET, |
| 414 | data, p); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 415 | |
| 416 | /* put the JPEG header */ |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 417 | gspca_frame_add(gspca_dev, FIRST_PACKET, |
Jean-Francois Moine | 71cb276 | 2009-03-03 05:33:41 -0300 | [diff] [blame] | 418 | sd->jpeg_hdr, JPEG_HDR_SZ); |
Jean-Francois Moine | 0a32ef3 | 2009-01-08 16:30:58 -0300 | [diff] [blame] | 419 | data += p + 16; |
| 420 | len -= p + 16; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 421 | break; |
| 422 | } |
| 423 | } |
| 424 | } |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 425 | gspca_frame_add(gspca_dev, INTER_PACKET, data, len); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 426 | } |
| 427 | |
Jean-François Moine | fba3980 | 2010-10-16 14:12:53 -0300 | [diff] [blame] | 428 | static int sd_setilluminator1(struct gspca_dev *gspca_dev, __s32 val) |
| 429 | { |
| 430 | struct sd *sd = (struct sd *) gspca_dev; |
| 431 | |
| 432 | /* only one illuminator may be on */ |
| 433 | sd->ctrls[ILLUM_TOP].val = val; |
| 434 | if (val) |
| 435 | sd->ctrls[ILLUM_BOT].val = 0; |
| 436 | setilluminators(gspca_dev); |
| 437 | return gspca_dev->usb_err; |
| 438 | } |
| 439 | |
| 440 | static int sd_setilluminator2(struct gspca_dev *gspca_dev, __s32 val) |
| 441 | { |
| 442 | struct sd *sd = (struct sd *) gspca_dev; |
| 443 | |
| 444 | /* only one illuminator may be on */ |
| 445 | sd->ctrls[ILLUM_BOT].val = val; |
| 446 | if (val) |
| 447 | sd->ctrls[ILLUM_TOP].val = 0; |
| 448 | setilluminators(gspca_dev); |
| 449 | return gspca_dev->usb_err; |
| 450 | } |
| 451 | |
Jean-Francois Moine | 77ac0ba | 2009-03-02 06:40:52 -0300 | [diff] [blame] | 452 | static int sd_set_jcomp(struct gspca_dev *gspca_dev, |
| 453 | struct v4l2_jpegcompression *jcomp) |
| 454 | { |
| 455 | struct sd *sd = (struct sd *) gspca_dev; |
| 456 | |
| 457 | if (jcomp->quality < QUALITY_MIN) |
| 458 | sd->quality = QUALITY_MIN; |
| 459 | else if (jcomp->quality > QUALITY_MAX) |
| 460 | sd->quality = QUALITY_MAX; |
| 461 | else |
| 462 | sd->quality = jcomp->quality; |
| 463 | if (gspca_dev->streaming) |
| 464 | jpeg_set_qual(sd->jpeg_hdr, sd->quality); |
| 465 | return 0; |
| 466 | } |
| 467 | |
| 468 | static int sd_get_jcomp(struct gspca_dev *gspca_dev, |
| 469 | struct v4l2_jpegcompression *jcomp) |
| 470 | { |
| 471 | struct sd *sd = (struct sd *) gspca_dev; |
| 472 | |
| 473 | memset(jcomp, 0, sizeof *jcomp); |
| 474 | jcomp->quality = sd->quality; |
| 475 | jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT |
| 476 | | V4L2_JPEG_MARKER_DQT; |
| 477 | return 0; |
| 478 | } |
| 479 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 480 | /* sub-driver description */ |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 481 | static const struct sd_desc sd_desc = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 482 | .name = MODULE_NAME, |
| 483 | .ctrls = sd_ctrls, |
Jean-François Moine | e3b4d2c | 2010-10-16 14:07:06 -0300 | [diff] [blame] | 484 | .nctrls = NCTRLS, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 485 | .config = sd_config, |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 486 | .init = sd_init, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 487 | .start = sd_start, |
| 488 | .stopN = sd_stopN, |
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-François Moine | 95c967c | 2011-01-13 05:20:29 -0300 | [diff] [blame] | 495 | static const 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 | { |
Jean-François Moine | 5482643 | 2010-09-13 04:53:03 -0300 | [diff] [blame] | 523 | return usb_register(&sd_driver); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 524 | } |
| 525 | static void __exit sd_mod_exit(void) |
| 526 | { |
| 527 | usb_deregister(&sd_driver); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | module_init(sd_mod_init); |
| 531 | module_exit(sd_mod_exit); |