Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1 | /* |
| 2 | * SPCA500 chip based cameras initialization data |
| 3 | * |
| 4 | * V4L2 by Jean-Francois Moine <http://moinejf.free.fr> |
| 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 |
| 19 | * |
| 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 "spca500" |
| 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/SPCA500 USB Camera Driver"); |
| 31 | MODULE_LICENSE("GPL"); |
| 32 | |
| 33 | /* specific webcam descriptor */ |
| 34 | struct sd { |
| 35 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
| 36 | |
Hans Verkuil | 9bf0c43 | 2012-05-16 07:29:00 -0300 | [diff] [blame^] | 37 | struct v4l2_ctrl *jpegqual; |
Jean-Francois Moine | 77ac0ba | 2009-03-02 06:40:52 -0300 | [diff] [blame] | 38 | #define QUALITY_MIN 70 |
| 39 | #define QUALITY_MAX 95 |
| 40 | #define QUALITY_DEF 85 |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 41 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 42 | char subtype; |
| 43 | #define AgfaCl20 0 |
| 44 | #define AiptekPocketDV 1 |
| 45 | #define BenqDC1016 2 |
| 46 | #define CreativePCCam300 3 |
| 47 | #define DLinkDSC350 4 |
| 48 | #define Gsmartmini 5 |
| 49 | #define IntelPocketPCCamera 6 |
| 50 | #define KodakEZ200 7 |
| 51 | #define LogitechClickSmart310 8 |
| 52 | #define LogitechClickSmart510 9 |
| 53 | #define LogitechTraveler 10 |
| 54 | #define MustekGsmart300 11 |
| 55 | #define Optimedia 12 |
| 56 | #define PalmPixDC85 13 |
| 57 | #define ToptroIndus 14 |
Jean-Francois Moine | 71cb276 | 2009-03-03 05:33:41 -0300 | [diff] [blame] | 58 | |
Jean-François Moine | 9a731a3 | 2010-06-04 05:26:42 -0300 | [diff] [blame] | 59 | u8 jpeg_hdr[JPEG_HDR_SZ]; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 60 | }; |
| 61 | |
Jean-Francois Moine | cc611b8 | 2008-12-29 07:49:41 -0300 | [diff] [blame] | 62 | static const struct v4l2_pix_format vga_mode[] = { |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 63 | {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 64 | .bytesperline = 320, |
| 65 | .sizeimage = 320 * 240 * 3 / 8 + 590, |
| 66 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 67 | .priv = 1}, |
| 68 | {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 69 | .bytesperline = 640, |
| 70 | .sizeimage = 640 * 480 * 3 / 8 + 590, |
| 71 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 72 | .priv = 0}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 73 | }; |
| 74 | |
Jean-Francois Moine | cc611b8 | 2008-12-29 07:49:41 -0300 | [diff] [blame] | 75 | static const struct v4l2_pix_format sif_mode[] = { |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 76 | {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 77 | .bytesperline = 176, |
| 78 | .sizeimage = 176 * 144 * 3 / 8 + 590, |
| 79 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 80 | .priv = 1}, |
| 81 | {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 82 | .bytesperline = 352, |
| 83 | .sizeimage = 352 * 288 * 3 / 8 + 590, |
| 84 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 85 | .priv = 0}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | /* Frame packet header offsets for the spca500 */ |
| 89 | #define SPCA500_OFFSET_PADDINGLB 2 |
| 90 | #define SPCA500_OFFSET_PADDINGHB 3 |
| 91 | #define SPCA500_OFFSET_MODE 4 |
| 92 | #define SPCA500_OFFSET_IMGWIDTH 5 |
| 93 | #define SPCA500_OFFSET_IMGHEIGHT 6 |
| 94 | #define SPCA500_OFFSET_IMGMODE 7 |
| 95 | #define SPCA500_OFFSET_QTBLINDEX 8 |
| 96 | #define SPCA500_OFFSET_FRAMSEQ 9 |
| 97 | #define SPCA500_OFFSET_CDSPINFO 10 |
| 98 | #define SPCA500_OFFSET_GPIO 11 |
| 99 | #define SPCA500_OFFSET_AUGPIO 12 |
| 100 | #define SPCA500_OFFSET_DATA 16 |
| 101 | |
| 102 | |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 103 | static const __u16 spca500_visual_defaults[][3] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 104 | {0x00, 0x0003, 0x816b}, /* SSI not active sync with vsync, |
| 105 | * hue (H byte) = 0, |
| 106 | * saturation/hue enable, |
| 107 | * brightness/contrast enable. |
| 108 | */ |
| 109 | {0x00, 0x0000, 0x8167}, /* brightness = 0 */ |
| 110 | {0x00, 0x0020, 0x8168}, /* contrast = 0 */ |
| 111 | {0x00, 0x0003, 0x816b}, /* SSI not active sync with vsync, |
| 112 | * hue (H byte) = 0, saturation/hue enable, |
| 113 | * brightness/contrast enable. |
| 114 | * was 0x0003, now 0x0000. |
| 115 | */ |
| 116 | {0x00, 0x0000, 0x816a}, /* hue (L byte) = 0 */ |
| 117 | {0x00, 0x0020, 0x8169}, /* saturation = 0x20 */ |
| 118 | {0x00, 0x0050, 0x8157}, /* edge gain high threshold */ |
| 119 | {0x00, 0x0030, 0x8158}, /* edge gain low threshold */ |
| 120 | {0x00, 0x0028, 0x8159}, /* edge bandwidth high threshold */ |
| 121 | {0x00, 0x000a, 0x815a}, /* edge bandwidth low threshold */ |
| 122 | {0x00, 0x0001, 0x8202}, /* clock rate compensation = 1/25 sec/frame */ |
| 123 | {0x0c, 0x0004, 0x0000}, |
| 124 | /* set interface */ |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 125 | {} |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 126 | }; |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 127 | static const __u16 Clicksmart510_defaults[][3] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 128 | {0x00, 0x00, 0x8211}, |
| 129 | {0x00, 0x01, 0x82c0}, |
| 130 | {0x00, 0x10, 0x82cb}, |
| 131 | {0x00, 0x0f, 0x800d}, |
| 132 | {0x00, 0x82, 0x8225}, |
| 133 | {0x00, 0x21, 0x8228}, |
| 134 | {0x00, 0x00, 0x8203}, |
| 135 | {0x00, 0x00, 0x8204}, |
| 136 | {0x00, 0x08, 0x8205}, |
| 137 | {0x00, 0xf8, 0x8206}, |
| 138 | {0x00, 0x28, 0x8207}, |
| 139 | {0x00, 0xa0, 0x8208}, |
| 140 | {0x00, 0x08, 0x824a}, |
| 141 | {0x00, 0x08, 0x8214}, |
| 142 | {0x00, 0x80, 0x82c1}, |
| 143 | {0x00, 0x00, 0x82c2}, |
| 144 | {0x00, 0x00, 0x82ca}, |
| 145 | {0x00, 0x80, 0x82c1}, |
| 146 | {0x00, 0x04, 0x82c2}, |
| 147 | {0x00, 0x00, 0x82ca}, |
| 148 | {0x00, 0xfc, 0x8100}, |
| 149 | {0x00, 0xfc, 0x8105}, |
| 150 | {0x00, 0x30, 0x8101}, |
| 151 | {0x00, 0x00, 0x8102}, |
| 152 | {0x00, 0x00, 0x8103}, |
| 153 | {0x00, 0x66, 0x8107}, |
| 154 | {0x00, 0x00, 0x816b}, |
| 155 | {0x00, 0x00, 0x8155}, |
| 156 | {0x00, 0x01, 0x8156}, |
| 157 | {0x00, 0x60, 0x8157}, |
| 158 | {0x00, 0x40, 0x8158}, |
| 159 | {0x00, 0x0a, 0x8159}, |
| 160 | {0x00, 0x06, 0x815a}, |
| 161 | {0x00, 0x00, 0x813f}, |
| 162 | {0x00, 0x00, 0x8200}, |
| 163 | {0x00, 0x19, 0x8201}, |
| 164 | {0x00, 0x00, 0x82c1}, |
| 165 | {0x00, 0xa0, 0x82c2}, |
| 166 | {0x00, 0x00, 0x82ca}, |
| 167 | {0x00, 0x00, 0x8117}, |
| 168 | {0x00, 0x00, 0x8118}, |
| 169 | {0x00, 0x65, 0x8119}, |
| 170 | {0x00, 0x00, 0x811a}, |
| 171 | {0x00, 0x00, 0x811b}, |
| 172 | {0x00, 0x55, 0x811c}, |
| 173 | {0x00, 0x65, 0x811d}, |
| 174 | {0x00, 0x55, 0x811e}, |
| 175 | {0x00, 0x16, 0x811f}, |
| 176 | {0x00, 0x19, 0x8120}, |
| 177 | {0x00, 0x80, 0x8103}, |
| 178 | {0x00, 0x83, 0x816b}, |
| 179 | {0x00, 0x25, 0x8168}, |
| 180 | {0x00, 0x01, 0x820f}, |
| 181 | {0x00, 0xff, 0x8115}, |
| 182 | {0x00, 0x48, 0x8116}, |
| 183 | {0x00, 0x50, 0x8151}, |
| 184 | {0x00, 0x40, 0x8152}, |
| 185 | {0x00, 0x78, 0x8153}, |
| 186 | {0x00, 0x40, 0x8154}, |
| 187 | {0x00, 0x00, 0x8167}, |
| 188 | {0x00, 0x20, 0x8168}, |
| 189 | {0x00, 0x00, 0x816a}, |
| 190 | {0x00, 0x03, 0x816b}, |
| 191 | {0x00, 0x20, 0x8169}, |
| 192 | {0x00, 0x60, 0x8157}, |
| 193 | {0x00, 0x00, 0x8190}, |
| 194 | {0x00, 0x00, 0x81a1}, |
| 195 | {0x00, 0x00, 0x81b2}, |
| 196 | {0x00, 0x27, 0x8191}, |
| 197 | {0x00, 0x27, 0x81a2}, |
| 198 | {0x00, 0x27, 0x81b3}, |
| 199 | {0x00, 0x4b, 0x8192}, |
| 200 | {0x00, 0x4b, 0x81a3}, |
| 201 | {0x00, 0x4b, 0x81b4}, |
| 202 | {0x00, 0x66, 0x8193}, |
| 203 | {0x00, 0x66, 0x81a4}, |
| 204 | {0x00, 0x66, 0x81b5}, |
| 205 | {0x00, 0x79, 0x8194}, |
| 206 | {0x00, 0x79, 0x81a5}, |
| 207 | {0x00, 0x79, 0x81b6}, |
| 208 | {0x00, 0x8a, 0x8195}, |
| 209 | {0x00, 0x8a, 0x81a6}, |
| 210 | {0x00, 0x8a, 0x81b7}, |
| 211 | {0x00, 0x9b, 0x8196}, |
| 212 | {0x00, 0x9b, 0x81a7}, |
| 213 | {0x00, 0x9b, 0x81b8}, |
| 214 | {0x00, 0xa6, 0x8197}, |
| 215 | {0x00, 0xa6, 0x81a8}, |
| 216 | {0x00, 0xa6, 0x81b9}, |
| 217 | {0x00, 0xb2, 0x8198}, |
| 218 | {0x00, 0xb2, 0x81a9}, |
| 219 | {0x00, 0xb2, 0x81ba}, |
| 220 | {0x00, 0xbe, 0x8199}, |
| 221 | {0x00, 0xbe, 0x81aa}, |
| 222 | {0x00, 0xbe, 0x81bb}, |
| 223 | {0x00, 0xc8, 0x819a}, |
| 224 | {0x00, 0xc8, 0x81ab}, |
| 225 | {0x00, 0xc8, 0x81bc}, |
| 226 | {0x00, 0xd2, 0x819b}, |
| 227 | {0x00, 0xd2, 0x81ac}, |
| 228 | {0x00, 0xd2, 0x81bd}, |
| 229 | {0x00, 0xdb, 0x819c}, |
| 230 | {0x00, 0xdb, 0x81ad}, |
| 231 | {0x00, 0xdb, 0x81be}, |
| 232 | {0x00, 0xe4, 0x819d}, |
| 233 | {0x00, 0xe4, 0x81ae}, |
| 234 | {0x00, 0xe4, 0x81bf}, |
| 235 | {0x00, 0xed, 0x819e}, |
| 236 | {0x00, 0xed, 0x81af}, |
| 237 | {0x00, 0xed, 0x81c0}, |
| 238 | {0x00, 0xf7, 0x819f}, |
| 239 | {0x00, 0xf7, 0x81b0}, |
| 240 | {0x00, 0xf7, 0x81c1}, |
| 241 | {0x00, 0xff, 0x81a0}, |
| 242 | {0x00, 0xff, 0x81b1}, |
| 243 | {0x00, 0xff, 0x81c2}, |
| 244 | {0x00, 0x03, 0x8156}, |
| 245 | {0x00, 0x00, 0x8211}, |
| 246 | {0x00, 0x20, 0x8168}, |
| 247 | {0x00, 0x01, 0x8202}, |
| 248 | {0x00, 0x30, 0x8101}, |
| 249 | {0x00, 0x00, 0x8111}, |
| 250 | {0x00, 0x00, 0x8112}, |
| 251 | {0x00, 0x00, 0x8113}, |
| 252 | {0x00, 0x00, 0x8114}, |
| 253 | {} |
| 254 | }; |
| 255 | |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 256 | static const __u8 qtable_creative_pccam[2][64] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 257 | { /* Q-table Y-components */ |
| 258 | 0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12, |
| 259 | 0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11, |
| 260 | 0x04, 0x04, 0x05, 0x07, 0x0c, 0x11, 0x15, 0x11, |
| 261 | 0x04, 0x05, 0x07, 0x09, 0x0f, 0x1a, 0x18, 0x13, |
| 262 | 0x05, 0x07, 0x0b, 0x11, 0x14, 0x21, 0x1f, 0x17, |
| 263 | 0x07, 0x0b, 0x11, 0x13, 0x18, 0x1f, 0x22, 0x1c, |
| 264 | 0x0f, 0x13, 0x17, 0x1a, 0x1f, 0x24, 0x24, 0x1e, |
| 265 | 0x16, 0x1c, 0x1d, 0x1d, 0x22, 0x1e, 0x1f, 0x1e}, |
| 266 | { /* Q-table C-components */ |
| 267 | 0x05, 0x05, 0x07, 0x0e, 0x1e, 0x1e, 0x1e, 0x1e, |
| 268 | 0x05, 0x06, 0x08, 0x14, 0x1e, 0x1e, 0x1e, 0x1e, |
| 269 | 0x07, 0x08, 0x11, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, |
| 270 | 0x0e, 0x14, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, |
| 271 | 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, |
| 272 | 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, |
| 273 | 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, |
| 274 | 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e} |
| 275 | }; |
| 276 | |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 277 | static const __u8 qtable_kodak_ez200[2][64] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 278 | { /* Q-table Y-components */ |
| 279 | 0x02, 0x01, 0x01, 0x02, 0x02, 0x04, 0x05, 0x06, |
| 280 | 0x01, 0x01, 0x01, 0x02, 0x03, 0x06, 0x06, 0x06, |
| 281 | 0x01, 0x01, 0x02, 0x02, 0x04, 0x06, 0x07, 0x06, |
| 282 | 0x01, 0x02, 0x02, 0x03, 0x05, 0x09, 0x08, 0x06, |
| 283 | 0x02, 0x02, 0x04, 0x06, 0x07, 0x0b, 0x0a, 0x08, |
| 284 | 0x02, 0x04, 0x06, 0x06, 0x08, 0x0a, 0x0b, 0x09, |
| 285 | 0x05, 0x06, 0x08, 0x09, 0x0a, 0x0c, 0x0c, 0x0a, |
| 286 | 0x07, 0x09, 0x0a, 0x0a, 0x0b, 0x0a, 0x0a, 0x0a}, |
| 287 | { /* Q-table C-components */ |
| 288 | 0x02, 0x02, 0x02, 0x05, 0x0a, 0x0a, 0x0a, 0x0a, |
| 289 | 0x02, 0x02, 0x03, 0x07, 0x0a, 0x0a, 0x0a, 0x0a, |
| 290 | 0x02, 0x03, 0x06, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, |
| 291 | 0x05, 0x07, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, |
| 292 | 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, |
| 293 | 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, |
| 294 | 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, |
| 295 | 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a} |
| 296 | }; |
| 297 | |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 298 | static const __u8 qtable_pocketdv[2][64] = { |
Jean-Francois Moine | 956e42d | 2008-07-01 10:03:42 -0300 | [diff] [blame] | 299 | { /* Q-table Y-components start registers 0x8800 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 300 | 0x06, 0x04, 0x04, 0x06, 0x0a, 0x10, 0x14, 0x18, |
| 301 | 0x05, 0x05, 0x06, 0x08, 0x0a, 0x17, 0x18, 0x16, |
| 302 | 0x06, 0x05, 0x06, 0x0a, 0x10, 0x17, 0x1c, 0x16, |
| 303 | 0x06, 0x07, 0x09, 0x0c, 0x14, 0x23, 0x20, 0x19, |
| 304 | 0x07, 0x09, 0x0f, 0x16, 0x1b, 0x2c, 0x29, 0x1f, |
| 305 | 0x0a, 0x0e, 0x16, 0x1a, 0x20, 0x2a, 0x2d, 0x25, |
| 306 | 0x14, 0x1a, 0x1f, 0x23, 0x29, 0x30, 0x30, 0x28, |
| 307 | 0x1d, 0x25, 0x26, 0x27, 0x2d, 0x28, 0x29, 0x28, |
| 308 | }, |
Jean-Francois Moine | 956e42d | 2008-07-01 10:03:42 -0300 | [diff] [blame] | 309 | { /* Q-table C-components start registers 0x8840 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 310 | 0x07, 0x07, 0x0a, 0x13, 0x28, 0x28, 0x28, 0x28, |
| 311 | 0x07, 0x08, 0x0a, 0x1a, 0x28, 0x28, 0x28, 0x28, |
| 312 | 0x0a, 0x0a, 0x16, 0x28, 0x28, 0x28, 0x28, 0x28, |
| 313 | 0x13, 0x1a, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, |
| 314 | 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, |
| 315 | 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, |
| 316 | 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, |
| 317 | 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28} |
| 318 | }; |
| 319 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 320 | /* read 'len' bytes to gspca_dev->usb_buf */ |
| 321 | static void reg_r(struct gspca_dev *gspca_dev, |
| 322 | __u16 index, |
| 323 | __u16 length) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 324 | { |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 325 | usb_control_msg(gspca_dev->dev, |
| 326 | usb_rcvctrlpipe(gspca_dev->dev, 0), |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 327 | 0, |
| 328 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 329 | 0, /* value */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 330 | index, gspca_dev->usb_buf, length, 500); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 331 | } |
| 332 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 333 | static int reg_w(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 334 | __u16 req, __u16 index, __u16 value) |
| 335 | { |
| 336 | int ret; |
| 337 | |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 338 | PDEBUG(D_USBO, "reg write: [0x%02x] = 0x%02x", index, value); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 339 | ret = usb_control_msg(gspca_dev->dev, |
| 340 | usb_sndctrlpipe(gspca_dev->dev, 0), |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 341 | req, |
Jean-Francois Moine | bf7f0b9 | 2008-07-03 11:09:12 -0300 | [diff] [blame] | 342 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 343 | value, index, NULL, 0, 500); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 344 | if (ret < 0) |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 345 | pr_err("reg write: error %d\n", ret); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 346 | return ret; |
| 347 | } |
| 348 | |
| 349 | /* returns: negative is error, pos or zero is data */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 350 | static int reg_r_12(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 351 | __u16 req, /* bRequest */ |
| 352 | __u16 index, /* wIndex */ |
| 353 | __u16 length) /* wLength (1 or 2 only) */ |
| 354 | { |
| 355 | int ret; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 356 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 357 | gspca_dev->usb_buf[1] = 0; |
| 358 | ret = usb_control_msg(gspca_dev->dev, |
| 359 | usb_rcvctrlpipe(gspca_dev->dev, 0), |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 360 | req, |
| 361 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 362 | 0, /* value */ |
| 363 | index, |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 364 | gspca_dev->usb_buf, length, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 365 | 500); /* timeout */ |
| 366 | if (ret < 0) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 367 | pr_err("reg_r_12 err %d\n", ret); |
Jean-François Moine | 0b65632 | 2010-09-13 05:19:58 -0300 | [diff] [blame] | 368 | return ret; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 369 | } |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 370 | return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0]; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | /* |
| 374 | * Simple function to wait for a given 8-bit value to be returned from |
| 375 | * a reg_read call. |
| 376 | * Returns: negative is error or timeout, zero is success. |
| 377 | */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 378 | static int reg_r_wait(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 379 | __u16 reg, __u16 index, __u16 value) |
| 380 | { |
| 381 | int ret, cnt = 20; |
| 382 | |
| 383 | while (--cnt > 0) { |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 384 | ret = reg_r_12(gspca_dev, reg, index, 1); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 385 | if (ret == value) |
| 386 | return 0; |
| 387 | msleep(50); |
| 388 | } |
| 389 | return -EIO; |
| 390 | } |
| 391 | |
| 392 | static int write_vector(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 393 | const __u16 data[][3]) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 394 | { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 395 | int ret, i = 0; |
| 396 | |
| 397 | while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) { |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 398 | ret = reg_w(gspca_dev, data[i][0], data[i][2], data[i][1]); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 399 | if (ret < 0) |
| 400 | return ret; |
| 401 | i++; |
| 402 | } |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | static int spca50x_setup_qtable(struct gspca_dev *gspca_dev, |
| 407 | unsigned int request, |
| 408 | unsigned int ybase, |
| 409 | unsigned int cbase, |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 410 | const __u8 qtable[2][64]) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 411 | { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 412 | int i, err; |
| 413 | |
| 414 | /* loop over y components */ |
| 415 | for (i = 0; i < 64; i++) { |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 416 | err = reg_w(gspca_dev, request, ybase + i, qtable[0][i]); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 417 | if (err < 0) |
| 418 | return err; |
| 419 | } |
| 420 | |
| 421 | /* loop over c components */ |
| 422 | for (i = 0; i < 64; i++) { |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 423 | err = reg_w(gspca_dev, request, cbase + i, qtable[1][i]); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 424 | if (err < 0) |
| 425 | return err; |
| 426 | } |
| 427 | return 0; |
| 428 | } |
| 429 | |
| 430 | static void spca500_ping310(struct gspca_dev *gspca_dev) |
| 431 | { |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 432 | reg_r(gspca_dev, 0x0d04, 2); |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 433 | PDEBUG(D_STREAM, "ClickSmart310 ping 0x0d04 0x%02x 0x%02x", |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 434 | gspca_dev->usb_buf[0], gspca_dev->usb_buf[1]); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | static void spca500_clksmart310_init(struct gspca_dev *gspca_dev) |
| 438 | { |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 439 | reg_r(gspca_dev, 0x0d05, 2); |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 440 | PDEBUG(D_STREAM, "ClickSmart310 init 0x0d05 0x%02x 0x%02x", |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 441 | gspca_dev->usb_buf[0], gspca_dev->usb_buf[1]); |
| 442 | reg_w(gspca_dev, 0x00, 0x8167, 0x5a); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 443 | spca500_ping310(gspca_dev); |
| 444 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 445 | reg_w(gspca_dev, 0x00, 0x8168, 0x22); |
| 446 | reg_w(gspca_dev, 0x00, 0x816a, 0xc0); |
| 447 | reg_w(gspca_dev, 0x00, 0x816b, 0x0b); |
| 448 | reg_w(gspca_dev, 0x00, 0x8169, 0x25); |
| 449 | reg_w(gspca_dev, 0x00, 0x8157, 0x5b); |
| 450 | reg_w(gspca_dev, 0x00, 0x8158, 0x5b); |
| 451 | reg_w(gspca_dev, 0x00, 0x813f, 0x03); |
| 452 | reg_w(gspca_dev, 0x00, 0x8151, 0x4a); |
| 453 | reg_w(gspca_dev, 0x00, 0x8153, 0x78); |
| 454 | reg_w(gspca_dev, 0x00, 0x0d01, 0x04); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 455 | /* 00 for adjust shutter */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 456 | reg_w(gspca_dev, 0x00, 0x0d02, 0x01); |
| 457 | reg_w(gspca_dev, 0x00, 0x8169, 0x25); |
| 458 | reg_w(gspca_dev, 0x00, 0x0d01, 0x02); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | static void spca500_setmode(struct gspca_dev *gspca_dev, |
| 462 | __u8 xmult, __u8 ymult) |
| 463 | { |
| 464 | int mode; |
| 465 | |
| 466 | /* set x multiplier */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 467 | reg_w(gspca_dev, 0, 0x8001, xmult); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 468 | |
| 469 | /* set y multiplier */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 470 | reg_w(gspca_dev, 0, 0x8002, ymult); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 471 | |
| 472 | /* use compressed mode, VGA, with mode specific subsample */ |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 473 | mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 474 | reg_w(gspca_dev, 0, 0x8003, mode << 4); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | static int spca500_full_reset(struct gspca_dev *gspca_dev) |
| 478 | { |
| 479 | int err; |
| 480 | |
| 481 | /* send the reset command */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 482 | err = reg_w(gspca_dev, 0xe0, 0x0001, 0x0000); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 483 | if (err < 0) |
| 484 | return err; |
| 485 | |
| 486 | /* wait for the reset to complete */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 487 | err = reg_r_wait(gspca_dev, 0x06, 0x0000, 0x0000); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 488 | if (err < 0) |
| 489 | return err; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 490 | err = reg_w(gspca_dev, 0xe0, 0x0000, 0x0000); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 491 | if (err < 0) |
| 492 | return err; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 493 | err = reg_r_wait(gspca_dev, 0x06, 0, 0); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 494 | if (err < 0) { |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 495 | PDEBUG(D_ERR, "reg_r_wait() failed"); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 496 | return err; |
| 497 | } |
| 498 | /* all ok */ |
| 499 | return 0; |
| 500 | } |
| 501 | |
| 502 | /* Synchro the Bridge with sensor */ |
| 503 | /* Maybe that will work on all spca500 chip */ |
| 504 | /* because i only own a clicksmart310 try for that chip */ |
| 505 | /* using spca50x_set_packet_size() cause an Ooops here */ |
| 506 | /* usb_set_interface from kernel 2.6.x clear all the urb stuff */ |
| 507 | /* up-port the same feature as in 2.4.x kernel */ |
| 508 | static int spca500_synch310(struct gspca_dev *gspca_dev) |
| 509 | { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 510 | if (usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0) < 0) { |
| 511 | PDEBUG(D_ERR, "Set packet size: set interface error"); |
| 512 | goto error; |
| 513 | } |
| 514 | spca500_ping310(gspca_dev); |
| 515 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 516 | reg_r(gspca_dev, 0x0d00, 1); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 517 | |
| 518 | /* need alt setting here */ |
| 519 | PDEBUG(D_PACK, "ClickSmart310 sync alt: %d", gspca_dev->alt); |
| 520 | |
| 521 | /* Windoze use pipe with altsetting 6 why 7 here */ |
| 522 | if (usb_set_interface(gspca_dev->dev, |
| 523 | gspca_dev->iface, |
| 524 | gspca_dev->alt) < 0) { |
| 525 | PDEBUG(D_ERR, "Set packet size: set interface error"); |
| 526 | goto error; |
| 527 | } |
| 528 | return 0; |
| 529 | error: |
| 530 | return -EBUSY; |
| 531 | } |
| 532 | |
| 533 | static void spca500_reinit(struct gspca_dev *gspca_dev) |
| 534 | { |
| 535 | int err; |
| 536 | __u8 Data; |
| 537 | |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 538 | /* some unknown command from Aiptek pocket dv and family300 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 539 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 540 | reg_w(gspca_dev, 0x00, 0x0d01, 0x01); |
| 541 | reg_w(gspca_dev, 0x00, 0x0d03, 0x00); |
| 542 | reg_w(gspca_dev, 0x00, 0x0d02, 0x01); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 543 | |
| 544 | /* enable drop packet */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 545 | reg_w(gspca_dev, 0x00, 0x850a, 0x0001); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 546 | |
| 547 | err = spca50x_setup_qtable(gspca_dev, 0x00, 0x8800, 0x8840, |
| 548 | qtable_pocketdv); |
| 549 | if (err < 0) |
| 550 | PDEBUG(D_ERR|D_STREAM, "spca50x_setup_qtable failed on init"); |
| 551 | |
| 552 | /* set qtable index */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 553 | reg_w(gspca_dev, 0x00, 0x8880, 2); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 554 | /* family cam Quicksmart stuff */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 555 | reg_w(gspca_dev, 0x00, 0x800a, 0x00); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 556 | /* Set agc transfer: synced between frames */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 557 | reg_w(gspca_dev, 0x00, 0x820f, 0x01); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 558 | /* Init SDRAM - needed for SDRAM access */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 559 | reg_w(gspca_dev, 0x00, 0x870a, 0x04); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 560 | /*Start init sequence or stream */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 561 | reg_w(gspca_dev, 0, 0x8003, 0x00); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 562 | /* switch to video camera mode */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 563 | reg_w(gspca_dev, 0x00, 0x8000, 0x0004); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 564 | msleep(2000); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 565 | if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0) { |
| 566 | reg_r(gspca_dev, 0x816b, 1); |
| 567 | Data = gspca_dev->usb_buf[0]; |
| 568 | reg_w(gspca_dev, 0x00, 0x816b, Data); |
| 569 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | /* this function is called at probe time */ |
| 573 | static int sd_config(struct gspca_dev *gspca_dev, |
| 574 | const struct usb_device_id *id) |
| 575 | { |
| 576 | struct sd *sd = (struct sd *) gspca_dev; |
| 577 | struct cam *cam; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 578 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 579 | cam = &gspca_dev->cam; |
Jean-Francois Moine | 9d64fdb | 2008-07-25 08:53:03 -0300 | [diff] [blame] | 580 | sd->subtype = id->driver_info; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 581 | if (sd->subtype != LogitechClickSmart310) { |
| 582 | cam->cam_mode = vga_mode; |
Julia Lawall | 8029712 | 2008-11-12 23:18:21 -0300 | [diff] [blame] | 583 | cam->nmodes = ARRAY_SIZE(vga_mode); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 584 | } else { |
| 585 | cam->cam_mode = sif_mode; |
Julia Lawall | 8029712 | 2008-11-12 23:18:21 -0300 | [diff] [blame] | 586 | cam->nmodes = ARRAY_SIZE(sif_mode); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 587 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 588 | return 0; |
| 589 | } |
| 590 | |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 591 | /* this function is called at probe and resume time */ |
| 592 | static int sd_init(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 593 | { |
| 594 | struct sd *sd = (struct sd *) gspca_dev; |
| 595 | |
| 596 | /* initialisation of spca500 based cameras is deferred */ |
| 597 | PDEBUG(D_STREAM, "SPCA500 init"); |
| 598 | if (sd->subtype == LogitechClickSmart310) |
| 599 | spca500_clksmart310_init(gspca_dev); |
| 600 | /* else |
| 601 | spca500_initialise(gspca_dev); */ |
| 602 | PDEBUG(D_STREAM, "SPCA500 init done"); |
| 603 | return 0; |
| 604 | } |
| 605 | |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 606 | static int sd_start(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 607 | { |
| 608 | struct sd *sd = (struct sd *) gspca_dev; |
| 609 | int err; |
| 610 | __u8 Data; |
| 611 | __u8 xmult, ymult; |
| 612 | |
Jean-Francois Moine | 71cb276 | 2009-03-03 05:33:41 -0300 | [diff] [blame] | 613 | /* create the JPEG header */ |
Jean-Francois Moine | 71cb276 | 2009-03-03 05:33:41 -0300 | [diff] [blame] | 614 | jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, |
| 615 | 0x22); /* JPEG 411 */ |
Hans Verkuil | 9bf0c43 | 2012-05-16 07:29:00 -0300 | [diff] [blame^] | 616 | jpeg_set_qual(sd->jpeg_hdr, v4l2_ctrl_g_ctrl(sd->jpegqual)); |
Jean-Francois Moine | 71cb276 | 2009-03-03 05:33:41 -0300 | [diff] [blame] | 617 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 618 | if (sd->subtype == LogitechClickSmart310) { |
| 619 | xmult = 0x16; |
| 620 | ymult = 0x12; |
| 621 | } else { |
| 622 | xmult = 0x28; |
| 623 | ymult = 0x1e; |
| 624 | } |
| 625 | |
| 626 | /* is there a sensor here ? */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 627 | reg_r(gspca_dev, 0x8a04, 1); |
| 628 | PDEBUG(D_STREAM, "Spca500 Sensor Address 0x%02x", |
| 629 | gspca_dev->usb_buf[0]); |
| 630 | PDEBUG(D_STREAM, "Spca500 curr_mode: %d Xmult: 0x%02x, Ymult: 0x%02x", |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 631 | gspca_dev->curr_mode, xmult, ymult); |
| 632 | |
| 633 | /* setup qtable */ |
| 634 | switch (sd->subtype) { |
| 635 | case LogitechClickSmart310: |
| 636 | spca500_setmode(gspca_dev, xmult, ymult); |
| 637 | |
| 638 | /* enable drop packet */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 639 | reg_w(gspca_dev, 0x00, 0x850a, 0x0001); |
| 640 | reg_w(gspca_dev, 0x00, 0x8880, 3); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 641 | err = spca50x_setup_qtable(gspca_dev, |
| 642 | 0x00, 0x8800, 0x8840, |
| 643 | qtable_creative_pccam); |
| 644 | if (err < 0) |
| 645 | PDEBUG(D_ERR, "spca50x_setup_qtable failed"); |
| 646 | /* Init SDRAM - needed for SDRAM access */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 647 | reg_w(gspca_dev, 0x00, 0x870a, 0x04); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 648 | |
| 649 | /* switch to video camera mode */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 650 | reg_w(gspca_dev, 0x00, 0x8000, 0x0004); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 651 | msleep(500); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 652 | if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0) |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 653 | PDEBUG(D_ERR, "reg_r_wait() failed"); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 654 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 655 | reg_r(gspca_dev, 0x816b, 1); |
| 656 | Data = gspca_dev->usb_buf[0]; |
| 657 | reg_w(gspca_dev, 0x00, 0x816b, Data); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 658 | |
| 659 | spca500_synch310(gspca_dev); |
| 660 | |
| 661 | write_vector(gspca_dev, spca500_visual_defaults); |
| 662 | spca500_setmode(gspca_dev, xmult, ymult); |
| 663 | /* enable drop packet */ |
Jean-Francois Moine | 48d7a89 | 2009-01-15 09:34:55 -0300 | [diff] [blame] | 664 | err = reg_w(gspca_dev, 0x00, 0x850a, 0x0001); |
| 665 | if (err < 0) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 666 | PDEBUG(D_ERR, "failed to enable drop packet"); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 667 | reg_w(gspca_dev, 0x00, 0x8880, 3); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 668 | err = spca50x_setup_qtable(gspca_dev, |
| 669 | 0x00, 0x8800, 0x8840, |
| 670 | qtable_creative_pccam); |
| 671 | if (err < 0) |
| 672 | PDEBUG(D_ERR, "spca50x_setup_qtable failed"); |
| 673 | |
| 674 | /* Init SDRAM - needed for SDRAM access */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 675 | reg_w(gspca_dev, 0x00, 0x870a, 0x04); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 676 | |
| 677 | /* switch to video camera mode */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 678 | reg_w(gspca_dev, 0x00, 0x8000, 0x0004); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 679 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 680 | if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0) |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 681 | PDEBUG(D_ERR, "reg_r_wait() failed"); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 682 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 683 | reg_r(gspca_dev, 0x816b, 1); |
| 684 | Data = gspca_dev->usb_buf[0]; |
| 685 | reg_w(gspca_dev, 0x00, 0x816b, Data); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 686 | break; |
| 687 | case CreativePCCam300: /* Creative PC-CAM 300 640x480 CCD */ |
| 688 | case IntelPocketPCCamera: /* FIXME: Temporary fix for |
| 689 | * Intel Pocket PC Camera |
| 690 | * - NWG (Sat 29th March 2003) */ |
| 691 | |
| 692 | /* do a full reset */ |
Jean-Francois Moine | 956e42d | 2008-07-01 10:03:42 -0300 | [diff] [blame] | 693 | err = spca500_full_reset(gspca_dev); |
| 694 | if (err < 0) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 695 | PDEBUG(D_ERR, "spca500_full_reset failed"); |
| 696 | |
| 697 | /* enable drop packet */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 698 | err = reg_w(gspca_dev, 0x00, 0x850a, 0x0001); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 699 | if (err < 0) |
| 700 | PDEBUG(D_ERR, "failed to enable drop packet"); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 701 | reg_w(gspca_dev, 0x00, 0x8880, 3); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 702 | err = spca50x_setup_qtable(gspca_dev, |
| 703 | 0x00, 0x8800, 0x8840, |
| 704 | qtable_creative_pccam); |
| 705 | if (err < 0) |
| 706 | PDEBUG(D_ERR, "spca50x_setup_qtable failed"); |
| 707 | |
| 708 | spca500_setmode(gspca_dev, xmult, ymult); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 709 | reg_w(gspca_dev, 0x20, 0x0001, 0x0004); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 710 | |
| 711 | /* switch to video camera mode */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 712 | reg_w(gspca_dev, 0x00, 0x8000, 0x0004); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 713 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 714 | if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0) |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 715 | PDEBUG(D_ERR, "reg_r_wait() failed"); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 716 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 717 | reg_r(gspca_dev, 0x816b, 1); |
| 718 | Data = gspca_dev->usb_buf[0]; |
| 719 | reg_w(gspca_dev, 0x00, 0x816b, Data); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 720 | |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 721 | /* write_vector(gspca_dev, spca500_visual_defaults); */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 722 | break; |
| 723 | case KodakEZ200: /* Kodak EZ200 */ |
| 724 | |
| 725 | /* do a full reset */ |
| 726 | err = spca500_full_reset(gspca_dev); |
| 727 | if (err < 0) |
| 728 | PDEBUG(D_ERR, "spca500_full_reset failed"); |
| 729 | /* enable drop packet */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 730 | reg_w(gspca_dev, 0x00, 0x850a, 0x0001); |
| 731 | reg_w(gspca_dev, 0x00, 0x8880, 0); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 732 | err = spca50x_setup_qtable(gspca_dev, |
| 733 | 0x00, 0x8800, 0x8840, |
| 734 | qtable_kodak_ez200); |
| 735 | if (err < 0) |
| 736 | PDEBUG(D_ERR, "spca50x_setup_qtable failed"); |
| 737 | spca500_setmode(gspca_dev, xmult, ymult); |
| 738 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 739 | reg_w(gspca_dev, 0x20, 0x0001, 0x0004); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 740 | |
| 741 | /* switch to video camera mode */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 742 | reg_w(gspca_dev, 0x00, 0x8000, 0x0004); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 743 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 744 | if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0) |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 745 | PDEBUG(D_ERR, "reg_r_wait() failed"); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 746 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 747 | reg_r(gspca_dev, 0x816b, 1); |
| 748 | Data = gspca_dev->usb_buf[0]; |
| 749 | reg_w(gspca_dev, 0x00, 0x816b, Data); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 750 | |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 751 | /* write_vector(gspca_dev, spca500_visual_defaults); */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 752 | break; |
| 753 | |
| 754 | case BenqDC1016: |
| 755 | case DLinkDSC350: /* FamilyCam 300 */ |
| 756 | case AiptekPocketDV: /* Aiptek PocketDV */ |
| 757 | case Gsmartmini: /*Mustek Gsmart Mini */ |
| 758 | case MustekGsmart300: /* Mustek Gsmart 300 */ |
| 759 | case PalmPixDC85: |
| 760 | case Optimedia: |
| 761 | case ToptroIndus: |
| 762 | case AgfaCl20: |
| 763 | spca500_reinit(gspca_dev); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 764 | reg_w(gspca_dev, 0x00, 0x0d01, 0x01); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 765 | /* enable drop packet */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 766 | reg_w(gspca_dev, 0x00, 0x850a, 0x0001); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 767 | |
| 768 | err = spca50x_setup_qtable(gspca_dev, |
| 769 | 0x00, 0x8800, 0x8840, qtable_pocketdv); |
| 770 | if (err < 0) |
| 771 | PDEBUG(D_ERR, "spca50x_setup_qtable failed"); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 772 | reg_w(gspca_dev, 0x00, 0x8880, 2); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 773 | |
| 774 | /* familycam Quicksmart pocketDV stuff */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 775 | reg_w(gspca_dev, 0x00, 0x800a, 0x00); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 776 | /* Set agc transfer: synced between frames */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 777 | reg_w(gspca_dev, 0x00, 0x820f, 0x01); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 778 | /* Init SDRAM - needed for SDRAM access */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 779 | reg_w(gspca_dev, 0x00, 0x870a, 0x04); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 780 | |
Jean-Francois Moine | 956e42d | 2008-07-01 10:03:42 -0300 | [diff] [blame] | 781 | spca500_setmode(gspca_dev, xmult, ymult); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 782 | /* switch to video camera mode */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 783 | reg_w(gspca_dev, 0x00, 0x8000, 0x0004); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 784 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 785 | reg_r_wait(gspca_dev, 0, 0x8000, 0x44); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 786 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 787 | reg_r(gspca_dev, 0x816b, 1); |
| 788 | Data = gspca_dev->usb_buf[0]; |
| 789 | reg_w(gspca_dev, 0x00, 0x816b, Data); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 790 | break; |
| 791 | case LogitechTraveler: |
| 792 | case LogitechClickSmart510: |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 793 | reg_w(gspca_dev, 0x02, 0x00, 0x00); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 794 | /* enable drop packet */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 795 | reg_w(gspca_dev, 0x00, 0x850a, 0x0001); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 796 | |
| 797 | err = spca50x_setup_qtable(gspca_dev, |
| 798 | 0x00, 0x8800, |
| 799 | 0x8840, qtable_creative_pccam); |
| 800 | if (err < 0) |
| 801 | PDEBUG(D_ERR, "spca50x_setup_qtable failed"); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 802 | reg_w(gspca_dev, 0x00, 0x8880, 3); |
| 803 | reg_w(gspca_dev, 0x00, 0x800a, 0x00); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 804 | /* Init SDRAM - needed for SDRAM access */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 805 | reg_w(gspca_dev, 0x00, 0x870a, 0x04); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 806 | |
| 807 | spca500_setmode(gspca_dev, xmult, ymult); |
| 808 | |
| 809 | /* switch to video camera mode */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 810 | reg_w(gspca_dev, 0x00, 0x8000, 0x0004); |
| 811 | reg_r_wait(gspca_dev, 0, 0x8000, 0x44); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 812 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 813 | reg_r(gspca_dev, 0x816b, 1); |
| 814 | Data = gspca_dev->usb_buf[0]; |
| 815 | reg_w(gspca_dev, 0x00, 0x816b, Data); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 816 | write_vector(gspca_dev, Clicksmart510_defaults); |
| 817 | break; |
| 818 | } |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 819 | return 0; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | static void sd_stopN(struct gspca_dev *gspca_dev) |
| 823 | { |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 824 | reg_w(gspca_dev, 0, 0x8003, 0x00); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 825 | |
| 826 | /* switch to video camera mode */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 827 | reg_w(gspca_dev, 0x00, 0x8000, 0x0004); |
| 828 | reg_r(gspca_dev, 0x8000, 1); |
| 829 | PDEBUG(D_STREAM, "stop SPCA500 done reg8000: 0x%2x", |
| 830 | gspca_dev->usb_buf[0]); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 831 | } |
| 832 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 833 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 834 | u8 *data, /* isoc packet */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 835 | int len) /* iso packet length */ |
| 836 | { |
| 837 | struct sd *sd = (struct sd *) gspca_dev; |
| 838 | int i; |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 839 | static __u8 ffd9[] = {0xff, 0xd9}; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 840 | |
| 841 | /* frames are jpeg 4.1.1 without 0xff escape */ |
| 842 | if (data[0] == 0xff) { |
| 843 | if (data[1] != 0x01) { /* drop packet */ |
| 844 | /* gspca_dev->last_packet_type = DISCARD_PACKET; */ |
| 845 | return; |
| 846 | } |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 847 | gspca_frame_add(gspca_dev, LAST_PACKET, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 848 | ffd9, 2); |
| 849 | |
| 850 | /* put the JPEG header in the new frame */ |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 851 | gspca_frame_add(gspca_dev, FIRST_PACKET, |
Jean-Francois Moine | 71cb276 | 2009-03-03 05:33:41 -0300 | [diff] [blame] | 852 | sd->jpeg_hdr, JPEG_HDR_SZ); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 853 | |
| 854 | data += SPCA500_OFFSET_DATA; |
| 855 | len -= SPCA500_OFFSET_DATA; |
| 856 | } else { |
| 857 | data += 1; |
| 858 | len -= 1; |
| 859 | } |
| 860 | |
| 861 | /* add 0x00 after 0xff */ |
Jean-Francois Moine | 59746e1 | 2009-04-23 14:33:00 -0300 | [diff] [blame] | 862 | i = 0; |
| 863 | do { |
| 864 | if (data[i] == 0xff) { |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 865 | gspca_frame_add(gspca_dev, INTER_PACKET, |
Jean-Francois Moine | 59746e1 | 2009-04-23 14:33:00 -0300 | [diff] [blame] | 866 | data, i + 1); |
| 867 | len -= i; |
| 868 | data += i; |
| 869 | *data = 0x00; |
| 870 | i = 0; |
| 871 | } |
| 872 | i++; |
| 873 | } while (i < len); |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 874 | gspca_frame_add(gspca_dev, INTER_PACKET, data, len); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 875 | } |
| 876 | |
Hans Verkuil | 9bf0c43 | 2012-05-16 07:29:00 -0300 | [diff] [blame^] | 877 | static void setbrightness(struct gspca_dev *gspca_dev, s32 val) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 878 | { |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 879 | reg_w(gspca_dev, 0x00, 0x8167, |
Hans Verkuil | 9bf0c43 | 2012-05-16 07:29:00 -0300 | [diff] [blame^] | 880 | (__u8) (val - 128)); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 881 | } |
| 882 | |
Hans Verkuil | 9bf0c43 | 2012-05-16 07:29:00 -0300 | [diff] [blame^] | 883 | static void setcontrast(struct gspca_dev *gspca_dev, s32 val) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 884 | { |
Hans Verkuil | 9bf0c43 | 2012-05-16 07:29:00 -0300 | [diff] [blame^] | 885 | reg_w(gspca_dev, 0x00, 0x8168, val); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 886 | } |
| 887 | |
Hans Verkuil | 9bf0c43 | 2012-05-16 07:29:00 -0300 | [diff] [blame^] | 888 | static void setcolors(struct gspca_dev *gspca_dev, s32 val) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 889 | { |
Hans Verkuil | 9bf0c43 | 2012-05-16 07:29:00 -0300 | [diff] [blame^] | 890 | reg_w(gspca_dev, 0x00, 0x8169, val); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 891 | } |
| 892 | |
Jean-Francois Moine | 77ac0ba | 2009-03-02 06:40:52 -0300 | [diff] [blame] | 893 | static int sd_set_jcomp(struct gspca_dev *gspca_dev, |
| 894 | struct v4l2_jpegcompression *jcomp) |
| 895 | { |
| 896 | struct sd *sd = (struct sd *) gspca_dev; |
| 897 | |
Hans Verkuil | 9bf0c43 | 2012-05-16 07:29:00 -0300 | [diff] [blame^] | 898 | v4l2_ctrl_s_ctrl(sd->jpegqual, jcomp->quality); |
Jean-Francois Moine | 77ac0ba | 2009-03-02 06:40:52 -0300 | [diff] [blame] | 899 | return 0; |
| 900 | } |
| 901 | |
| 902 | static int sd_get_jcomp(struct gspca_dev *gspca_dev, |
| 903 | struct v4l2_jpegcompression *jcomp) |
| 904 | { |
| 905 | struct sd *sd = (struct sd *) gspca_dev; |
| 906 | |
| 907 | memset(jcomp, 0, sizeof *jcomp); |
Hans Verkuil | 9bf0c43 | 2012-05-16 07:29:00 -0300 | [diff] [blame^] | 908 | jcomp->quality = v4l2_ctrl_g_ctrl(sd->jpegqual); |
Jean-Francois Moine | 77ac0ba | 2009-03-02 06:40:52 -0300 | [diff] [blame] | 909 | jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT |
| 910 | | V4L2_JPEG_MARKER_DQT; |
| 911 | return 0; |
| 912 | } |
| 913 | |
Hans Verkuil | 9bf0c43 | 2012-05-16 07:29:00 -0300 | [diff] [blame^] | 914 | static int sd_s_ctrl(struct v4l2_ctrl *ctrl) |
| 915 | { |
| 916 | struct gspca_dev *gspca_dev = |
| 917 | container_of(ctrl->handler, struct gspca_dev, ctrl_handler); |
| 918 | struct sd *sd = (struct sd *)gspca_dev; |
| 919 | |
| 920 | gspca_dev->usb_err = 0; |
| 921 | |
| 922 | if (!gspca_dev->streaming) |
| 923 | return 0; |
| 924 | |
| 925 | switch (ctrl->id) { |
| 926 | case V4L2_CID_BRIGHTNESS: |
| 927 | setbrightness(gspca_dev, ctrl->val); |
| 928 | break; |
| 929 | case V4L2_CID_CONTRAST: |
| 930 | setcontrast(gspca_dev, ctrl->val); |
| 931 | break; |
| 932 | case V4L2_CID_SATURATION: |
| 933 | setcolors(gspca_dev, ctrl->val); |
| 934 | break; |
| 935 | case V4L2_CID_JPEG_COMPRESSION_QUALITY: |
| 936 | jpeg_set_qual(sd->jpeg_hdr, ctrl->val); |
| 937 | break; |
| 938 | } |
| 939 | return gspca_dev->usb_err; |
| 940 | } |
| 941 | |
| 942 | static const struct v4l2_ctrl_ops sd_ctrl_ops = { |
| 943 | .s_ctrl = sd_s_ctrl, |
| 944 | }; |
| 945 | |
| 946 | static int sd_init_controls(struct gspca_dev *gspca_dev) |
| 947 | { |
| 948 | struct sd *sd = (struct sd *)gspca_dev; |
| 949 | struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; |
| 950 | |
| 951 | gspca_dev->vdev.ctrl_handler = hdl; |
| 952 | v4l2_ctrl_handler_init(hdl, 4); |
| 953 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 954 | V4L2_CID_BRIGHTNESS, 0, 255, 1, 127); |
| 955 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 956 | V4L2_CID_CONTRAST, 0, 63, 1, 31); |
| 957 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 958 | V4L2_CID_SATURATION, 0, 63, 1, 31); |
| 959 | sd->jpegqual = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 960 | V4L2_CID_JPEG_COMPRESSION_QUALITY, |
| 961 | QUALITY_MIN, QUALITY_MAX, 1, QUALITY_DEF); |
| 962 | |
| 963 | if (hdl->error) { |
| 964 | pr_err("Could not initialize controls\n"); |
| 965 | return hdl->error; |
| 966 | } |
| 967 | return 0; |
| 968 | } |
| 969 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 970 | /* sub-driver description */ |
Márton Németh | aabcdfb | 2010-01-05 12:39:02 -0300 | [diff] [blame] | 971 | static const struct sd_desc sd_desc = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 972 | .name = MODULE_NAME, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 973 | .config = sd_config, |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 974 | .init = sd_init, |
Hans Verkuil | 9bf0c43 | 2012-05-16 07:29:00 -0300 | [diff] [blame^] | 975 | .init_controls = sd_init_controls, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 976 | .start = sd_start, |
| 977 | .stopN = sd_stopN, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 978 | .pkt_scan = sd_pkt_scan, |
Jean-Francois Moine | 77ac0ba | 2009-03-02 06:40:52 -0300 | [diff] [blame] | 979 | .get_jcomp = sd_get_jcomp, |
| 980 | .set_jcomp = sd_set_jcomp, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 981 | }; |
| 982 | |
| 983 | /* -- module initialisation -- */ |
Jean-François Moine | 95c967c | 2011-01-13 05:20:29 -0300 | [diff] [blame] | 984 | static const struct usb_device_id device_table[] = { |
Jean-Francois Moine | 87581aa | 2008-07-26 14:30:01 -0300 | [diff] [blame] | 985 | {USB_DEVICE(0x040a, 0x0300), .driver_info = KodakEZ200}, |
| 986 | {USB_DEVICE(0x041e, 0x400a), .driver_info = CreativePCCam300}, |
| 987 | {USB_DEVICE(0x046d, 0x0890), .driver_info = LogitechTraveler}, |
| 988 | {USB_DEVICE(0x046d, 0x0900), .driver_info = LogitechClickSmart310}, |
| 989 | {USB_DEVICE(0x046d, 0x0901), .driver_info = LogitechClickSmart510}, |
| 990 | {USB_DEVICE(0x04a5, 0x300c), .driver_info = BenqDC1016}, |
| 991 | {USB_DEVICE(0x04fc, 0x7333), .driver_info = PalmPixDC85}, |
| 992 | {USB_DEVICE(0x055f, 0xc200), .driver_info = MustekGsmart300}, |
| 993 | {USB_DEVICE(0x055f, 0xc220), .driver_info = Gsmartmini}, |
| 994 | {USB_DEVICE(0x06bd, 0x0404), .driver_info = AgfaCl20}, |
| 995 | {USB_DEVICE(0x06be, 0x0800), .driver_info = Optimedia}, |
| 996 | {USB_DEVICE(0x084d, 0x0003), .driver_info = DLinkDSC350}, |
| 997 | {USB_DEVICE(0x08ca, 0x0103), .driver_info = AiptekPocketDV}, |
| 998 | {USB_DEVICE(0x2899, 0x012c), .driver_info = ToptroIndus}, |
| 999 | {USB_DEVICE(0x8086, 0x0630), .driver_info = IntelPocketPCCamera}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1000 | {} |
| 1001 | }; |
| 1002 | MODULE_DEVICE_TABLE(usb, device_table); |
| 1003 | |
| 1004 | /* -- device connect -- */ |
| 1005 | static int sd_probe(struct usb_interface *intf, |
| 1006 | const struct usb_device_id *id) |
| 1007 | { |
| 1008 | return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), |
| 1009 | THIS_MODULE); |
| 1010 | } |
| 1011 | |
| 1012 | static struct usb_driver sd_driver = { |
| 1013 | .name = MODULE_NAME, |
| 1014 | .id_table = device_table, |
| 1015 | .probe = sd_probe, |
| 1016 | .disconnect = gspca_disconnect, |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame] | 1017 | #ifdef CONFIG_PM |
| 1018 | .suspend = gspca_suspend, |
| 1019 | .resume = gspca_resume, |
| 1020 | #endif |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1021 | }; |
| 1022 | |
Greg Kroah-Hartman | ecb3b2b | 2011-11-18 09:46:12 -0800 | [diff] [blame] | 1023 | module_usb_driver(sd_driver); |