Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Pixart PAC7311 library |
| 3 | * Copyright (C) 2005 Thomas Kaiser thomas@kaiser-linux.li |
| 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 | |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 22 | /* Some documentation about various registers as determined by trial and error. |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 23 | |
| 24 | Register page 1: |
| 25 | |
| 26 | Address Description |
Hans de Goede | b053c1d | 2012-04-25 12:00:49 -0300 | [diff] [blame] | 27 | 0x08 Unknown compressor related, must always be 8 except when not |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 28 | in 640x480 resolution and page 4 reg 2 <= 3 then set it to 9 ! |
Hans de Goede | b053c1d | 2012-04-25 12:00:49 -0300 | [diff] [blame] | 29 | 0x1b Auto white balance related, bit 0 is AWB enable (inverted) |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 30 | bits 345 seem to toggle per color gains on/off (inverted) |
| 31 | 0x78 Global control, bit 6 controls the LED (inverted) |
Hans de Goede | b053c1d | 2012-04-25 12:00:49 -0300 | [diff] [blame] | 32 | 0x80 JPEG compression ratio ? Best not touched |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 33 | |
Hans de Goede | b053c1d | 2012-04-25 12:00:49 -0300 | [diff] [blame] | 34 | Register page 4: |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 35 | |
| 36 | Address Description |
| 37 | 0x02 Clock divider 2-63, fps =~ 60 / val. Must be a multiple of 3 on |
Hans de Goede | 038ec7c | 2008-09-03 17:12:18 -0300 | [diff] [blame] | 38 | the 7302, so one of 3, 6, 9, ..., except when between 6 and 12? |
Hans de Goede | b053c1d | 2012-04-25 12:00:49 -0300 | [diff] [blame] | 39 | 0x0f Master gain 1-245, low value = high gain |
| 40 | 0x10 Another gain 0-15, limited influence (1-2x gain I guess) |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 41 | 0x21 Bitfield: 0-1 unused, 2-3 vflip/hflip, 4-5 unknown, 6-7 unused |
Hans de Goede | b053c1d | 2012-04-25 12:00:49 -0300 | [diff] [blame] | 42 | 0x27 Seems to toggle various gains on / off, Setting bit 7 seems to |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 43 | completely disable the analog amplification block. Set to 0x68 |
| 44 | for max gain, 0x14 for minimal gain. |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 45 | */ |
| 46 | |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 47 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 48 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 49 | #define MODULE_NAME "pac7311" |
| 50 | |
Hans de Goede | 32ea3e4 | 2010-01-29 11:04:19 -0300 | [diff] [blame] | 51 | #include <linux/input.h> |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 52 | #include "gspca.h" |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 53 | /* Include pac common sof detection functions */ |
| 54 | #include "pac_common.h" |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 55 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 56 | MODULE_AUTHOR("Thomas Kaiser thomas@kaiser-linux.li"); |
| 57 | MODULE_DESCRIPTION("Pixart PAC7311"); |
| 58 | MODULE_LICENSE("GPL"); |
| 59 | |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 60 | enum e_ctrl { |
| 61 | CONTRAST, |
| 62 | GAIN, |
| 63 | EXPOSURE, |
| 64 | AUTOGAIN, |
| 65 | HFLIP, |
| 66 | VFLIP, |
| 67 | NCTRLS /* number of controls */ |
| 68 | }; |
| 69 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 70 | struct sd { |
| 71 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 72 | struct gspca_ctrl ctrls[NCTRLS]; |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 73 | |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 74 | u8 sof_read; |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 75 | u8 autogain_ignore_frames; |
| 76 | |
| 77 | atomic_t avg_lum; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | /* V4L2 controls supported by the driver */ |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 81 | static void setcontrast(struct gspca_dev *gspca_dev); |
| 82 | static void setgain(struct gspca_dev *gspca_dev); |
| 83 | static void setexposure(struct gspca_dev *gspca_dev); |
| 84 | static void setautogain(struct gspca_dev *gspca_dev); |
| 85 | static void sethvflip(struct gspca_dev *gspca_dev); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 86 | |
Marton Nemeth | 7e64dc4 | 2009-12-30 09:12:41 -0300 | [diff] [blame] | 87 | static const struct ctrl sd_ctrls[] = { |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 88 | [CONTRAST] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 89 | { |
| 90 | .id = V4L2_CID_CONTRAST, |
| 91 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 92 | .name = "Contrast", |
| 93 | .minimum = 0, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 94 | .maximum = 15, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 95 | .step = 1, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 96 | .default_value = 7, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 97 | }, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 98 | .set_control = setcontrast |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 99 | }, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 100 | [GAIN] = { |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 101 | { |
| 102 | .id = V4L2_CID_GAIN, |
| 103 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 104 | .name = "Gain", |
| 105 | .minimum = 0, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 106 | .maximum = 244, |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 107 | .step = 1, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 108 | .default_value = 122, |
| 109 | #define GAIN_KNEE 244 /* Gain seems to cause little noise on the 7311 */ |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 110 | }, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 111 | .set_control = setgain, |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 112 | }, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 113 | [EXPOSURE] = { |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 114 | { |
| 115 | .id = V4L2_CID_EXPOSURE, |
| 116 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 117 | .name = "Exposure", |
Hans de Goede | c894d26 | 2012-04-25 12:17:19 -0300 | [diff] [blame] | 118 | .minimum = 2, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 119 | .maximum = 63, |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 120 | .step = 1, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 121 | .default_value = 2, /* 30 fps */ |
Hans de Goede | c894d26 | 2012-04-25 12:17:19 -0300 | [diff] [blame] | 122 | #define EXPOSURE_KNEE 6 /* 10 fps */ |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 123 | }, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 124 | .set_control = setexposure, |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 125 | }, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 126 | [AUTOGAIN] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 127 | { |
| 128 | .id = V4L2_CID_AUTOGAIN, |
| 129 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 130 | .name = "Auto Gain", |
| 131 | .minimum = 0, |
| 132 | .maximum = 1, |
| 133 | .step = 1, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 134 | .default_value = 1, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 135 | }, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 136 | .set_control = setautogain, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 137 | }, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 138 | [HFLIP] = { |
Jean-Francois Moine | 41b4697 | 2008-09-03 16:47:58 -0300 | [diff] [blame] | 139 | { |
| 140 | .id = V4L2_CID_HFLIP, |
| 141 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 142 | .name = "Mirror", |
| 143 | .minimum = 0, |
| 144 | .maximum = 1, |
| 145 | .step = 1, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 146 | .default_value = 0, |
Jean-Francois Moine | 41b4697 | 2008-09-03 16:47:58 -0300 | [diff] [blame] | 147 | }, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 148 | .set_control = sethvflip, |
Jean-Francois Moine | 41b4697 | 2008-09-03 16:47:58 -0300 | [diff] [blame] | 149 | }, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 150 | [VFLIP] = { |
Jean-Francois Moine | 41b4697 | 2008-09-03 16:47:58 -0300 | [diff] [blame] | 151 | { |
| 152 | .id = V4L2_CID_VFLIP, |
| 153 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 154 | .name = "Vflip", |
| 155 | .minimum = 0, |
| 156 | .maximum = 1, |
| 157 | .step = 1, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 158 | .default_value = 0, |
Jean-Francois Moine | 41b4697 | 2008-09-03 16:47:58 -0300 | [diff] [blame] | 159 | }, |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 160 | .set_control = sethvflip, |
Jean-Francois Moine | 41b4697 | 2008-09-03 16:47:58 -0300 | [diff] [blame] | 161 | }, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 162 | }; |
| 163 | |
Jean-Francois Moine | cc611b8 | 2008-12-29 07:49:41 -0300 | [diff] [blame] | 164 | static const struct v4l2_pix_format vga_mode[] = { |
Jean-Francois Moine | f75c495 | 2008-09-03 16:47:35 -0300 | [diff] [blame] | 165 | {160, 120, V4L2_PIX_FMT_PJPG, V4L2_FIELD_NONE, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 166 | .bytesperline = 160, |
| 167 | .sizeimage = 160 * 120 * 3 / 8 + 590, |
| 168 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 169 | .priv = 2}, |
Jean-Francois Moine | f75c495 | 2008-09-03 16:47:35 -0300 | [diff] [blame] | 170 | {320, 240, V4L2_PIX_FMT_PJPG, V4L2_FIELD_NONE, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 171 | .bytesperline = 320, |
| 172 | .sizeimage = 320 * 240 * 3 / 8 + 590, |
| 173 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 174 | .priv = 1}, |
Jean-Francois Moine | f75c495 | 2008-09-03 16:47:35 -0300 | [diff] [blame] | 175 | {640, 480, V4L2_PIX_FMT_PJPG, V4L2_FIELD_NONE, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 176 | .bytesperline = 640, |
| 177 | .sizeimage = 640 * 480 * 3 / 8 + 590, |
| 178 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 179 | .priv = 0}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 180 | }; |
| 181 | |
Marton Nemeth | 5a2e8d9 | 2009-10-04 13:53:22 -0300 | [diff] [blame] | 182 | #define LOAD_PAGE4 254 |
| 183 | #define END_OF_SEQUENCE 0 |
| 184 | |
Hans de Goede | 271315a | 2008-09-03 17:12:19 -0300 | [diff] [blame] | 185 | static const __u8 init_7311[] = { |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 186 | 0x78, 0x40, /* Bit_0=start stream, Bit_6=LED */ |
| 187 | 0x78, 0x40, /* Bit_0=start stream, Bit_6=LED */ |
| 188 | 0x78, 0x44, /* Bit_0=start stream, Bit_6=LED */ |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 189 | 0xff, 0x04, |
| 190 | 0x27, 0x80, |
| 191 | 0x28, 0xca, |
| 192 | 0x29, 0x53, |
| 193 | 0x2a, 0x0e, |
| 194 | 0xff, 0x01, |
| 195 | 0x3e, 0x20, |
| 196 | }; |
| 197 | |
| 198 | static const __u8 start_7311[] = { |
| 199 | /* index, len, [value]* */ |
Jean-Francois Moine | 285a4f6 | 2008-09-03 16:47:33 -0300 | [diff] [blame] | 200 | 0xff, 1, 0x01, /* page 1 */ |
| 201 | 0x02, 43, 0x48, 0x0a, 0x40, 0x08, 0x00, 0x00, 0x08, 0x00, |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 202 | 0x06, 0xff, 0x11, 0xff, 0x5a, 0x30, 0x90, 0x4c, |
| 203 | 0x00, 0x07, 0x00, 0x0a, 0x10, 0x00, 0xa0, 0x10, |
| 204 | 0x02, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x01, 0x00, |
| 205 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 206 | 0x00, 0x00, 0x00, |
Jean-Francois Moine | 285a4f6 | 2008-09-03 16:47:33 -0300 | [diff] [blame] | 207 | 0x3e, 42, 0x00, 0x00, 0x78, 0x52, 0x4a, 0x52, 0x78, 0x6e, |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 208 | 0x48, 0x46, 0x48, 0x6e, 0x5f, 0x49, 0x42, 0x49, |
| 209 | 0x5f, 0x5f, 0x49, 0x42, 0x49, 0x5f, 0x6e, 0x48, |
| 210 | 0x46, 0x48, 0x6e, 0x78, 0x52, 0x4a, 0x52, 0x78, |
| 211 | 0x00, 0x00, 0x09, 0x1b, 0x34, 0x49, 0x5c, 0x9b, |
| 212 | 0xd0, 0xff, |
| 213 | 0x78, 6, 0x44, 0x00, 0xf2, 0x01, 0x01, 0x80, |
| 214 | 0x7f, 18, 0x2a, 0x1c, 0x00, 0xc8, 0x02, 0x58, 0x03, 0x84, |
| 215 | 0x12, 0x00, 0x1a, 0x04, 0x08, 0x0c, 0x10, 0x14, |
| 216 | 0x18, 0x20, |
| 217 | 0x96, 3, 0x01, 0x08, 0x04, |
| 218 | 0xa0, 4, 0x44, 0x44, 0x44, 0x04, |
| 219 | 0xf0, 13, 0x01, 0x00, 0x00, 0x00, 0x22, 0x00, 0x20, 0x00, |
| 220 | 0x3f, 0x00, 0x0a, 0x01, 0x00, |
Jean-Francois Moine | 285a4f6 | 2008-09-03 16:47:33 -0300 | [diff] [blame] | 221 | 0xff, 1, 0x04, /* page 4 */ |
Marton Nemeth | 5a2e8d9 | 2009-10-04 13:53:22 -0300 | [diff] [blame] | 222 | 0, LOAD_PAGE4, /* load the page 4 */ |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 223 | 0x11, 1, 0x01, |
Marton Nemeth | 5a2e8d9 | 2009-10-04 13:53:22 -0300 | [diff] [blame] | 224 | 0, END_OF_SEQUENCE /* end of sequence */ |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 225 | }; |
| 226 | |
Marton Nemeth | 1408b84 | 2009-11-02 08:13:21 -0300 | [diff] [blame] | 227 | #define SKIP 0xaa |
Marton Nemeth | ff75e99 | 2009-10-04 13:51:26 -0300 | [diff] [blame] | 228 | /* page 4 - the value SKIP says skip the index - see reg_w_page() */ |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 229 | static const __u8 page4_7311[] = { |
Marton Nemeth | ff75e99 | 2009-10-04 13:51:26 -0300 | [diff] [blame] | 230 | SKIP, SKIP, 0x04, 0x54, 0x07, 0x2b, 0x09, 0x0f, |
| 231 | 0x09, 0x00, SKIP, SKIP, 0x07, 0x00, 0x00, 0x62, |
| 232 | 0x08, SKIP, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 233 | 0x00, 0x00, 0x00, 0x03, 0xa0, 0x01, 0xf4, SKIP, |
| 234 | SKIP, 0x00, 0x08, SKIP, 0x03, SKIP, 0x00, 0x68, |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 235 | 0xca, 0x10, 0x06, 0x78, 0x00, 0x00, 0x00, 0x00, |
| 236 | 0x23, 0x28, 0x04, 0x11, 0x00, 0x00 |
| 237 | }; |
| 238 | |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 239 | static void reg_w_buf(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 240 | __u8 index, |
Jean-François Moine | 0aeb5ec | 2010-12-28 06:59:04 -0300 | [diff] [blame] | 241 | const u8 *buffer, int len) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 242 | { |
Marton Nemeth | 4f7309e | 2009-11-05 05:35:08 -0300 | [diff] [blame] | 243 | int ret; |
| 244 | |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 245 | if (gspca_dev->usb_err < 0) |
| 246 | return; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 247 | memcpy(gspca_dev->usb_buf, buffer, len); |
Marton Nemeth | 4f7309e | 2009-11-05 05:35:08 -0300 | [diff] [blame] | 248 | ret = usb_control_msg(gspca_dev->dev, |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 249 | usb_sndctrlpipe(gspca_dev->dev, 0), |
Jean-François Moine | a131713 | 2010-06-24 04:50:26 -0300 | [diff] [blame] | 250 | 0, /* request */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 251 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
Jean-Francois Moine | bf7f0b9 | 2008-07-03 11:09:12 -0300 | [diff] [blame] | 252 | 0, /* value */ |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 253 | index, gspca_dev->usb_buf, len, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 254 | 500); |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 255 | if (ret < 0) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 256 | pr_err("reg_w_buf() failed index 0x%02x, error %d\n", |
| 257 | index, ret); |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 258 | gspca_dev->usb_err = ret; |
| 259 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 260 | } |
| 261 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 262 | |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 263 | static void reg_w(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 264 | __u8 index, |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 265 | __u8 value) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 266 | { |
Marton Nemeth | 4f7309e | 2009-11-05 05:35:08 -0300 | [diff] [blame] | 267 | int ret; |
| 268 | |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 269 | if (gspca_dev->usb_err < 0) |
| 270 | return; |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 271 | gspca_dev->usb_buf[0] = value; |
Marton Nemeth | 4f7309e | 2009-11-05 05:35:08 -0300 | [diff] [blame] | 272 | ret = usb_control_msg(gspca_dev->dev, |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 273 | usb_sndctrlpipe(gspca_dev->dev, 0), |
Jean-Francois Moine | bf7f0b9 | 2008-07-03 11:09:12 -0300 | [diff] [blame] | 274 | 0, /* request */ |
| 275 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 276 | 0, index, gspca_dev->usb_buf, 1, |
Jean-Francois Moine | bf7f0b9 | 2008-07-03 11:09:12 -0300 | [diff] [blame] | 277 | 500); |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 278 | if (ret < 0) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 279 | pr_err("reg_w() failed index 0x%02x, value 0x%02x, error %d\n", |
| 280 | index, value, ret); |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 281 | gspca_dev->usb_err = ret; |
| 282 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 283 | } |
| 284 | |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 285 | static void reg_w_seq(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 286 | const __u8 *seq, int len) |
| 287 | { |
| 288 | while (--len >= 0) { |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 289 | reg_w(gspca_dev, seq[0], seq[1]); |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 290 | seq += 2; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | /* load the beginning of a page */ |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 295 | static void reg_w_page(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 296 | const __u8 *page, int len) |
| 297 | { |
| 298 | int index; |
Márton Németh | b1784b3 | 2009-11-07 05:52:02 -0300 | [diff] [blame] | 299 | int ret = 0; |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 300 | |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 301 | if (gspca_dev->usb_err < 0) |
| 302 | return; |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 303 | for (index = 0; index < len; index++) { |
Marton Nemeth | ff75e99 | 2009-10-04 13:51:26 -0300 | [diff] [blame] | 304 | if (page[index] == SKIP) /* skip this index */ |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 305 | continue; |
| 306 | gspca_dev->usb_buf[0] = page[index]; |
Marton Nemeth | 4f7309e | 2009-11-05 05:35:08 -0300 | [diff] [blame] | 307 | ret = usb_control_msg(gspca_dev->dev, |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 308 | usb_sndctrlpipe(gspca_dev->dev, 0), |
| 309 | 0, /* request */ |
| 310 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 311 | 0, index, gspca_dev->usb_buf, 1, |
| 312 | 500); |
Márton Németh | b1784b3 | 2009-11-07 05:52:02 -0300 | [diff] [blame] | 313 | if (ret < 0) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 314 | pr_err("reg_w_page() failed index 0x%02x, value 0x%02x, error %d\n", |
| 315 | index, page[index], ret); |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 316 | gspca_dev->usb_err = ret; |
Márton Németh | b1784b3 | 2009-11-07 05:52:02 -0300 | [diff] [blame] | 317 | break; |
| 318 | } |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | |
| 322 | /* output a variable sequence */ |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 323 | static void reg_w_var(struct gspca_dev *gspca_dev, |
Marton Nemeth | 1408b84 | 2009-11-02 08:13:21 -0300 | [diff] [blame] | 324 | const __u8 *seq, |
Marton Nemeth | 1408b84 | 2009-11-02 08:13:21 -0300 | [diff] [blame] | 325 | const __u8 *page4, unsigned int page4_len) |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 326 | { |
| 327 | int index, len; |
| 328 | |
| 329 | for (;;) { |
| 330 | index = *seq++; |
| 331 | len = *seq++; |
| 332 | switch (len) { |
Marton Nemeth | 5a2e8d9 | 2009-10-04 13:53:22 -0300 | [diff] [blame] | 333 | case END_OF_SEQUENCE: |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 334 | return; |
Marton Nemeth | 5a2e8d9 | 2009-10-04 13:53:22 -0300 | [diff] [blame] | 335 | case LOAD_PAGE4: |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 336 | reg_w_page(gspca_dev, page4, page4_len); |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 337 | break; |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 338 | default: |
Marton Nemeth | 24067bb | 2009-10-04 13:54:48 -0300 | [diff] [blame] | 339 | if (len > USB_BUF_SZ) { |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 340 | PDEBUG(D_ERR|D_STREAM, |
| 341 | "Incorrect variable sequence"); |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 342 | return; |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 343 | } |
| 344 | while (len > 0) { |
| 345 | if (len < 8) { |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 346 | reg_w_buf(gspca_dev, |
Márton Németh | b1784b3 | 2009-11-07 05:52:02 -0300 | [diff] [blame] | 347 | index, seq, len); |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 348 | seq += len; |
| 349 | break; |
| 350 | } |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 351 | reg_w_buf(gspca_dev, index, seq, 8); |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 352 | seq += 8; |
| 353 | index += 8; |
| 354 | len -= 8; |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | /* not reached */ |
| 359 | } |
| 360 | |
Marton Nemeth | 1408b84 | 2009-11-02 08:13:21 -0300 | [diff] [blame] | 361 | /* this function is called at probe time for pac7311 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 362 | static int sd_config(struct gspca_dev *gspca_dev, |
| 363 | const struct usb_device_id *id) |
| 364 | { |
| 365 | struct sd *sd = (struct sd *) gspca_dev; |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 366 | struct cam *cam = &gspca_dev->cam; |
Jean-Francois Moine | 49b57db | 2008-09-03 16:47:25 -0300 | [diff] [blame] | 367 | |
Marton Nemeth | 1408b84 | 2009-11-02 08:13:21 -0300 | [diff] [blame] | 368 | cam->cam_mode = vga_mode; |
| 369 | cam->nmodes = ARRAY_SIZE(vga_mode); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 370 | |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 371 | gspca_dev->cam.ctrls = sd->ctrls; |
| 372 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 373 | return 0; |
| 374 | } |
| 375 | |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 376 | static void setcontrast(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 377 | { |
| 378 | struct sd *sd = (struct sd *) gspca_dev; |
| 379 | |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 380 | reg_w(gspca_dev, 0xff, 0x04); |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 381 | reg_w(gspca_dev, 0x10, sd->ctrls[CONTRAST].val); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 382 | /* load registers to sensor (Bit 0, auto clear) */ |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 383 | reg_w(gspca_dev, 0x11, 0x01); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 384 | } |
| 385 | |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 386 | static void setgain(struct gspca_dev *gspca_dev) |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 387 | { |
| 388 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 389 | |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 390 | reg_w(gspca_dev, 0xff, 0x04); /* page 4 */ |
| 391 | reg_w(gspca_dev, 0x0e, 0x00); |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 392 | reg_w(gspca_dev, 0x0f, sd->ctrls[GAIN].max - sd->ctrls[GAIN].val + 1); |
Marton Nemeth | 1408b84 | 2009-11-02 08:13:21 -0300 | [diff] [blame] | 393 | |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 394 | /* load registers to sensor (Bit 0, auto clear) */ |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 395 | reg_w(gspca_dev, 0x11, 0x01); |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 396 | } |
| 397 | |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 398 | static void setexposure(struct gspca_dev *gspca_dev) |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 399 | { |
| 400 | struct sd *sd = (struct sd *) gspca_dev; |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 401 | |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 402 | reg_w(gspca_dev, 0xff, 0x04); /* page 4 */ |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 403 | reg_w(gspca_dev, 0x02, sd->ctrls[EXPOSURE].val); |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 404 | |
Hans de Goede | 51ae23d | 2012-04-18 06:12:57 -0300 | [diff] [blame] | 405 | /* load registers to sensor (Bit 0, auto clear) */ |
| 406 | reg_w(gspca_dev, 0x11, 0x01); |
| 407 | |
Marton Nemeth | 1408b84 | 2009-11-02 08:13:21 -0300 | [diff] [blame] | 408 | /* Page 1 register 8 must always be 0x08 except when not in |
Hans de Goede | b053c1d | 2012-04-25 12:00:49 -0300 | [diff] [blame] | 409 | 640x480 mode and page 4 reg 2 <= 3 then it must be 9 */ |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 410 | reg_w(gspca_dev, 0xff, 0x01); |
Marton Nemeth | 1408b84 | 2009-11-02 08:13:21 -0300 | [diff] [blame] | 411 | if (gspca_dev->cam.cam_mode[(int)gspca_dev->curr_mode].priv && |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 412 | sd->ctrls[EXPOSURE].val <= 3) { |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 413 | reg_w(gspca_dev, 0x08, 0x09); |
Márton Németh | b1784b3 | 2009-11-07 05:52:02 -0300 | [diff] [blame] | 414 | } else { |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 415 | reg_w(gspca_dev, 0x08, 0x08); |
Márton Németh | b1784b3 | 2009-11-07 05:52:02 -0300 | [diff] [blame] | 416 | } |
Marton Nemeth | 1408b84 | 2009-11-02 08:13:21 -0300 | [diff] [blame] | 417 | |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 418 | /* load registers to sensor (Bit 0, auto clear) */ |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 419 | reg_w(gspca_dev, 0x11, 0x01); |
Jean-Francois Moine | cebf3b6 | 2008-08-03 07:52:53 -0300 | [diff] [blame] | 420 | } |
| 421 | |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 422 | static void sethvflip(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 41b4697 | 2008-09-03 16:47:58 -0300 | [diff] [blame] | 423 | { |
| 424 | struct sd *sd = (struct sd *) gspca_dev; |
| 425 | __u8 data; |
| 426 | |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 427 | reg_w(gspca_dev, 0xff, 0x04); /* page 4 */ |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 428 | data = (sd->ctrls[HFLIP].val ? 0x04 : 0x00) | |
| 429 | (sd->ctrls[VFLIP].val ? 0x08 : 0x00); |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 430 | reg_w(gspca_dev, 0x21, data); |
| 431 | |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 432 | /* load registers to sensor (Bit 0, auto clear) */ |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 433 | reg_w(gspca_dev, 0x11, 0x01); |
Jean-Francois Moine | 41b4697 | 2008-09-03 16:47:58 -0300 | [diff] [blame] | 434 | } |
| 435 | |
Marton Nemeth | 1408b84 | 2009-11-02 08:13:21 -0300 | [diff] [blame] | 436 | /* this function is called at probe and resume time for pac7311 */ |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 437 | static int sd_init(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 438 | { |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 439 | reg_w_seq(gspca_dev, init_7311, sizeof(init_7311)/2); |
| 440 | return gspca_dev->usb_err; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 441 | } |
| 442 | |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 443 | static int sd_start(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 444 | { |
Jean-Francois Moine | e52a557 | 2008-09-03 16:47:21 -0300 | [diff] [blame] | 445 | struct sd *sd = (struct sd *) gspca_dev; |
| 446 | |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 447 | sd->sof_read = 0; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 448 | |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 449 | reg_w_var(gspca_dev, start_7311, |
Marton Nemeth | 1408b84 | 2009-11-02 08:13:21 -0300 | [diff] [blame] | 450 | page4_7311, sizeof(page4_7311)); |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 451 | setcontrast(gspca_dev); |
| 452 | setgain(gspca_dev); |
| 453 | setexposure(gspca_dev); |
| 454 | sethvflip(gspca_dev); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 455 | |
| 456 | /* set correct resolution */ |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 457 | switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) { |
Hans de Goede | b053c1d | 2012-04-25 12:00:49 -0300 | [diff] [blame] | 458 | case 2: /* 160x120 */ |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 459 | reg_w(gspca_dev, 0xff, 0x01); |
| 460 | reg_w(gspca_dev, 0x17, 0x20); |
| 461 | reg_w(gspca_dev, 0x87, 0x10); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 462 | break; |
Hans de Goede | b053c1d | 2012-04-25 12:00:49 -0300 | [diff] [blame] | 463 | case 1: /* 320x240 */ |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 464 | reg_w(gspca_dev, 0xff, 0x01); |
| 465 | reg_w(gspca_dev, 0x17, 0x30); |
| 466 | reg_w(gspca_dev, 0x87, 0x11); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 467 | break; |
| 468 | case 0: /* 640x480 */ |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 469 | reg_w(gspca_dev, 0xff, 0x01); |
| 470 | reg_w(gspca_dev, 0x17, 0x00); |
| 471 | reg_w(gspca_dev, 0x87, 0x12); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 472 | break; |
| 473 | } |
| 474 | |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 475 | sd->sof_read = 0; |
| 476 | sd->autogain_ignore_frames = 0; |
| 477 | atomic_set(&sd->avg_lum, -1); |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 478 | |
| 479 | /* start stream */ |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 480 | reg_w(gspca_dev, 0xff, 0x01); |
| 481 | reg_w(gspca_dev, 0x78, 0x05); |
Marton Nemeth | 1408b84 | 2009-11-02 08:13:21 -0300 | [diff] [blame] | 482 | |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 483 | return gspca_dev->usb_err; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | static void sd_stopN(struct gspca_dev *gspca_dev) |
| 487 | { |
Jean-Francois Moine | 14799f6 | 2010-01-13 15:28:22 -0300 | [diff] [blame] | 488 | reg_w(gspca_dev, 0xff, 0x04); |
| 489 | reg_w(gspca_dev, 0x27, 0x80); |
| 490 | reg_w(gspca_dev, 0x28, 0xca); |
| 491 | reg_w(gspca_dev, 0x29, 0x53); |
| 492 | reg_w(gspca_dev, 0x2a, 0x0e); |
| 493 | reg_w(gspca_dev, 0xff, 0x01); |
| 494 | reg_w(gspca_dev, 0x3e, 0x20); |
| 495 | reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */ |
| 496 | reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */ |
| 497 | reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 498 | } |
| 499 | |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 500 | #define WANT_REGULAR_AUTOGAIN |
| 501 | #include "autogain_functions.h" |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 502 | |
Jean-Francois Moine | cebf3b6 | 2008-08-03 07:52:53 -0300 | [diff] [blame] | 503 | static void do_autogain(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 504 | { |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 505 | struct sd *sd = (struct sd *) gspca_dev; |
| 506 | int avg_lum = atomic_read(&sd->avg_lum); |
Hans de Goede | 038ec7c | 2008-09-03 17:12:18 -0300 | [diff] [blame] | 507 | int desired_lum, deadzone; |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 508 | |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 509 | if (sd->ctrls[AUTOGAIN].val == 0 || avg_lum == -1) |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 510 | return; |
| 511 | |
Marton Nemeth | 1408b84 | 2009-11-02 08:13:21 -0300 | [diff] [blame] | 512 | desired_lum = 200; |
| 513 | deadzone = 20; |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 514 | |
| 515 | if (sd->autogain_ignore_frames > 0) |
| 516 | sd->autogain_ignore_frames--; |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 517 | else if (auto_gain_n_exposure(gspca_dev, avg_lum, desired_lum, |
Hans de Goede | 038ec7c | 2008-09-03 17:12:18 -0300 | [diff] [blame] | 518 | deadzone, GAIN_KNEE, EXPOSURE_KNEE)) |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 519 | sd->autogain_ignore_frames = PAC_AUTOGAIN_IGNORE_FRAMES; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 520 | } |
| 521 | |
Marton Nemeth | 56f6f55 | 2009-10-04 13:58:19 -0300 | [diff] [blame] | 522 | /* JPEG header, part 1 */ |
Marton Nemeth | cc409c0 | 2009-11-02 08:09:34 -0300 | [diff] [blame] | 523 | static const unsigned char pac_jpeg_header1[] = { |
Marton Nemeth | 56f6f55 | 2009-10-04 13:58:19 -0300 | [diff] [blame] | 524 | 0xff, 0xd8, /* SOI: Start of Image */ |
| 525 | |
| 526 | 0xff, 0xc0, /* SOF0: Start of Frame (Baseline DCT) */ |
| 527 | 0x00, 0x11, /* length = 17 bytes (including this length field) */ |
| 528 | 0x08 /* Precision: 8 */ |
| 529 | /* 2 bytes is placed here: number of image lines */ |
| 530 | /* 2 bytes is placed here: samples per line */ |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 531 | }; |
| 532 | |
Marton Nemeth | 56f6f55 | 2009-10-04 13:58:19 -0300 | [diff] [blame] | 533 | /* JPEG header, continued */ |
Marton Nemeth | cc409c0 | 2009-11-02 08:09:34 -0300 | [diff] [blame] | 534 | static const unsigned char pac_jpeg_header2[] = { |
Marton Nemeth | 56f6f55 | 2009-10-04 13:58:19 -0300 | [diff] [blame] | 535 | 0x03, /* Number of image components: 3 */ |
| 536 | 0x01, 0x21, 0x00, /* ID=1, Subsampling 1x1, Quantization table: 0 */ |
| 537 | 0x02, 0x11, 0x01, /* ID=2, Subsampling 2x1, Quantization table: 1 */ |
| 538 | 0x03, 0x11, 0x01, /* ID=3, Subsampling 2x1, Quantization table: 1 */ |
| 539 | |
| 540 | 0xff, 0xda, /* SOS: Start Of Scan */ |
| 541 | 0x00, 0x0c, /* length = 12 bytes (including this length field) */ |
| 542 | 0x03, /* number of components: 3 */ |
| 543 | 0x01, 0x00, /* selector 1, table 0x00 */ |
| 544 | 0x02, 0x11, /* selector 2, table 0x11 */ |
| 545 | 0x03, 0x11, /* selector 3, table 0x11 */ |
| 546 | 0x00, 0x3f, /* Spectral selection: 0 .. 63 */ |
| 547 | 0x00 /* Successive approximation: 0 */ |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 548 | }; |
| 549 | |
Marton Nemeth | cc409c0 | 2009-11-02 08:09:34 -0300 | [diff] [blame] | 550 | static void pac_start_frame(struct gspca_dev *gspca_dev, |
Marton Nemeth | cc409c0 | 2009-11-02 08:09:34 -0300 | [diff] [blame] | 551 | __u16 lines, __u16 samples_per_line) |
| 552 | { |
| 553 | unsigned char tmpbuf[4]; |
| 554 | |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 555 | gspca_frame_add(gspca_dev, FIRST_PACKET, |
Marton Nemeth | cc409c0 | 2009-11-02 08:09:34 -0300 | [diff] [blame] | 556 | pac_jpeg_header1, sizeof(pac_jpeg_header1)); |
| 557 | |
| 558 | tmpbuf[0] = lines >> 8; |
| 559 | tmpbuf[1] = lines & 0xff; |
| 560 | tmpbuf[2] = samples_per_line >> 8; |
| 561 | tmpbuf[3] = samples_per_line & 0xff; |
| 562 | |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 563 | gspca_frame_add(gspca_dev, INTER_PACKET, |
Marton Nemeth | cc409c0 | 2009-11-02 08:09:34 -0300 | [diff] [blame] | 564 | tmpbuf, sizeof(tmpbuf)); |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 565 | gspca_frame_add(gspca_dev, INTER_PACKET, |
Marton Nemeth | cc409c0 | 2009-11-02 08:09:34 -0300 | [diff] [blame] | 566 | pac_jpeg_header2, sizeof(pac_jpeg_header2)); |
| 567 | } |
| 568 | |
Jean-Francois Moine | e52a557 | 2008-09-03 16:47:21 -0300 | [diff] [blame] | 569 | /* this function is run at interrupt level */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 570 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 571 | u8 *data, /* isoc packet */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 572 | int len) /* iso packet length */ |
| 573 | { |
| 574 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-François Moine | b192ca9 | 2010-06-27 03:08:19 -0300 | [diff] [blame] | 575 | u8 *image; |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 576 | unsigned char *sof; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 577 | |
Marton Nemeth | a6b69e4 | 2009-11-02 08:05:51 -0300 | [diff] [blame] | 578 | sof = pac_find_sof(&sd->sof_read, data, len); |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 579 | if (sof) { |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 580 | int n, lum_offset, footer_length; |
Jean-Francois Moine | e52a557 | 2008-09-03 16:47:21 -0300 | [diff] [blame] | 581 | |
Marton Nemeth | 1408b84 | 2009-11-02 08:13:21 -0300 | [diff] [blame] | 582 | /* 6 bytes after the FF D9 EOF marker a number of lumination |
| 583 | bytes are send corresponding to different parts of the |
| 584 | image, the 14th and 15th byte after the EOF seem to |
| 585 | correspond to the center of the image */ |
| 586 | lum_offset = 24 + sizeof pac_sof_marker; |
| 587 | footer_length = 26; |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 588 | |
| 589 | /* Finish decoding current frame */ |
| 590 | n = (sof - data) - (footer_length + sizeof pac_sof_marker); |
| 591 | if (n < 0) { |
Jean-François Moine | b192ca9 | 2010-06-27 03:08:19 -0300 | [diff] [blame] | 592 | gspca_dev->image_len += n; |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 593 | n = 0; |
Jean-François Moine | b192ca9 | 2010-06-27 03:08:19 -0300 | [diff] [blame] | 594 | } else { |
| 595 | gspca_frame_add(gspca_dev, INTER_PACKET, data, n); |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 596 | } |
Jean-François Moine | f7059ea | 2010-07-06 04:32:27 -0300 | [diff] [blame] | 597 | image = gspca_dev->image; |
| 598 | if (image != NULL |
Jean-François Moine | b192ca9 | 2010-06-27 03:08:19 -0300 | [diff] [blame] | 599 | && image[gspca_dev->image_len - 2] == 0xff |
| 600 | && image[gspca_dev->image_len - 1] == 0xd9) |
| 601 | gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0); |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 602 | |
| 603 | n = sof - data; |
| 604 | len -= n; |
| 605 | data = sof; |
| 606 | |
| 607 | /* Get average lumination */ |
| 608 | if (gspca_dev->last_packet_type == LAST_PACKET && |
Hans de Goede | 038ec7c | 2008-09-03 17:12:18 -0300 | [diff] [blame] | 609 | n >= lum_offset) |
| 610 | atomic_set(&sd->avg_lum, data[-lum_offset] + |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 611 | data[-lum_offset + 1]); |
Hans de Goede | 038ec7c | 2008-09-03 17:12:18 -0300 | [diff] [blame] | 612 | else |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 613 | atomic_set(&sd->avg_lum, -1); |
Hans de Goede | 327c4ab | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 614 | |
| 615 | /* Start the new frame with the jpeg header */ |
Jean-François Moine | b192ca9 | 2010-06-27 03:08:19 -0300 | [diff] [blame] | 616 | pac_start_frame(gspca_dev, |
Marton Nemeth | 1408b84 | 2009-11-02 08:13:21 -0300 | [diff] [blame] | 617 | gspca_dev->height, gspca_dev->width); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 618 | } |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 619 | gspca_frame_add(gspca_dev, INTER_PACKET, data, len); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 620 | } |
| 621 | |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 622 | static void setautogain(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 623 | { |
| 624 | struct sd *sd = (struct sd *) gspca_dev; |
| 625 | |
Hans de Goede | a5340ce | 2012-04-27 11:40:28 -0300 | [diff] [blame^] | 626 | if (sd->ctrls[AUTOGAIN].val) { |
| 627 | sd->ctrls[EXPOSURE].val = 2; |
| 628 | sd->ctrls[GAIN].val = 122; |
Hans de Goede | 8a5b2e9 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 629 | if (gspca_dev->streaming) { |
| 630 | sd->autogain_ignore_frames = |
| 631 | PAC_AUTOGAIN_IGNORE_FRAMES; |
| 632 | setexposure(gspca_dev); |
| 633 | setgain(gspca_dev); |
| 634 | } |
| 635 | } |
Jean-Francois Moine | 41b4697 | 2008-09-03 16:47:58 -0300 | [diff] [blame] | 636 | } |
| 637 | |
Jean-François Moine | 2856643 | 2010-10-01 07:33:26 -0300 | [diff] [blame] | 638 | #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) |
Hans de Goede | 32ea3e4 | 2010-01-29 11:04:19 -0300 | [diff] [blame] | 639 | static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, |
| 640 | u8 *data, /* interrupt packet data */ |
| 641 | int len) /* interrupt packet length */ |
| 642 | { |
| 643 | int ret = -EINVAL; |
| 644 | u8 data0, data1; |
| 645 | |
| 646 | if (len == 2) { |
| 647 | data0 = data[0]; |
| 648 | data1 = data[1]; |
| 649 | if ((data0 == 0x00 && data1 == 0x11) || |
| 650 | (data0 == 0x22 && data1 == 0x33) || |
| 651 | (data0 == 0x44 && data1 == 0x55) || |
| 652 | (data0 == 0x66 && data1 == 0x77) || |
| 653 | (data0 == 0x88 && data1 == 0x99) || |
| 654 | (data0 == 0xaa && data1 == 0xbb) || |
| 655 | (data0 == 0xcc && data1 == 0xdd) || |
| 656 | (data0 == 0xee && data1 == 0xff)) { |
| 657 | input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1); |
| 658 | input_sync(gspca_dev->input_dev); |
| 659 | input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); |
| 660 | input_sync(gspca_dev->input_dev); |
| 661 | ret = 0; |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | return ret; |
| 666 | } |
| 667 | #endif |
| 668 | |
Márton Németh | aabcdfb | 2010-01-05 12:39:02 -0300 | [diff] [blame] | 669 | static const struct sd_desc sd_desc = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 670 | .name = MODULE_NAME, |
| 671 | .ctrls = sd_ctrls, |
| 672 | .nctrls = ARRAY_SIZE(sd_ctrls), |
| 673 | .config = sd_config, |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 674 | .init = sd_init, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 675 | .start = sd_start, |
| 676 | .stopN = sd_stopN, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 677 | .pkt_scan = sd_pkt_scan, |
Jean-Francois Moine | cebf3b6 | 2008-08-03 07:52:53 -0300 | [diff] [blame] | 678 | .dq_callback = do_autogain, |
Jean-François Moine | 2856643 | 2010-10-01 07:33:26 -0300 | [diff] [blame] | 679 | #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) |
Hans de Goede | 32ea3e4 | 2010-01-29 11:04:19 -0300 | [diff] [blame] | 680 | .int_pkt_scan = sd_int_pkt_scan, |
| 681 | #endif |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 682 | }; |
| 683 | |
| 684 | /* -- module initialisation -- */ |
Jean-François Moine | 95c967c | 2011-01-13 05:20:29 -0300 | [diff] [blame] | 685 | static const struct usb_device_id device_table[] = { |
Marton Nemeth | 1408b84 | 2009-11-02 08:13:21 -0300 | [diff] [blame] | 686 | {USB_DEVICE(0x093a, 0x2600)}, |
| 687 | {USB_DEVICE(0x093a, 0x2601)}, |
| 688 | {USB_DEVICE(0x093a, 0x2603)}, |
| 689 | {USB_DEVICE(0x093a, 0x2608)}, |
| 690 | {USB_DEVICE(0x093a, 0x260e)}, |
| 691 | {USB_DEVICE(0x093a, 0x260f)}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 692 | {} |
| 693 | }; |
| 694 | MODULE_DEVICE_TABLE(usb, device_table); |
| 695 | |
| 696 | /* -- device connect -- */ |
Jean-François Moine | 95c967c | 2011-01-13 05:20:29 -0300 | [diff] [blame] | 697 | static int sd_probe(struct usb_interface *intf, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 698 | const struct usb_device_id *id) |
| 699 | { |
| 700 | return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), |
| 701 | THIS_MODULE); |
| 702 | } |
| 703 | |
| 704 | static struct usb_driver sd_driver = { |
| 705 | .name = MODULE_NAME, |
| 706 | .id_table = device_table, |
| 707 | .probe = sd_probe, |
| 708 | .disconnect = gspca_disconnect, |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame] | 709 | #ifdef CONFIG_PM |
| 710 | .suspend = gspca_suspend, |
| 711 | .resume = gspca_resume, |
| 712 | #endif |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 713 | }; |
| 714 | |
Greg Kroah-Hartman | ecb3b2b | 2011-11-18 09:46:12 -0800 | [diff] [blame] | 715 | module_usb_driver(sd_driver); |