Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1 | /* |
| 2 | * ov534/ov772x gspca driver |
| 3 | * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it> |
Jim Paris | 0f7a50b | 2008-12-10 05:45:14 -0300 | [diff] [blame] | 4 | * Copyright (C) 2008 Jim Paris <jim@jtan.com> |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 5 | * |
| 6 | * Based on a prototype written by Mark Ferrell <majortrips@gmail.com> |
| 7 | * USB protocol reverse engineered by Jim Paris <jim@jtan.com> |
| 8 | * https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/ |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #define MODULE_NAME "ov534" |
| 26 | |
| 27 | #include "gspca.h" |
| 28 | |
| 29 | #define OV534_REG_ADDRESS 0xf1 /* ? */ |
| 30 | #define OV534_REG_SUBADDR 0xf2 |
| 31 | #define OV534_REG_WRITE 0xf3 |
| 32 | #define OV534_REG_READ 0xf4 |
| 33 | #define OV534_REG_OPERATION 0xf5 |
| 34 | #define OV534_REG_STATUS 0xf6 |
| 35 | |
| 36 | #define OV534_OP_WRITE_3 0x37 |
| 37 | #define OV534_OP_WRITE_2 0x33 |
| 38 | #define OV534_OP_READ_2 0xf9 |
| 39 | |
| 40 | #define CTRL_TIMEOUT 500 |
| 41 | |
| 42 | MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>"); |
| 43 | MODULE_DESCRIPTION("GSPCA/OV534 USB Camera Driver"); |
| 44 | MODULE_LICENSE("GPL"); |
| 45 | |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 46 | /* specific webcam descriptor */ |
| 47 | struct sd { |
| 48 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
Jean-Francois Moine | 8c25205 | 2008-12-04 05:06:08 -0300 | [diff] [blame] | 49 | __u32 last_pts; |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame^] | 50 | u16 last_fid; |
| 51 | u8 frame_rate; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | /* V4L2 controls supported by the driver */ |
| 55 | static struct ctrl sd_ctrls[] = { |
| 56 | }; |
| 57 | |
Jean-Francois Moine | cc611b8 | 2008-12-29 07:49:41 -0300 | [diff] [blame] | 58 | static const struct v4l2_pix_format vga_mode[] = { |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 59 | {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, |
| 60 | .bytesperline = 640 * 2, |
| 61 | .sizeimage = 640 * 480 * 2, |
| 62 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 63 | .priv = 0}, |
| 64 | }; |
| 65 | |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 66 | static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val) |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 67 | { |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 68 | struct usb_device *udev = gspca_dev->dev; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 69 | int ret; |
| 70 | |
Antonio Ospite | 9e1e7b0 | 2008-12-03 14:10:01 -0300 | [diff] [blame] | 71 | PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val); |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 72 | gspca_dev->usb_buf[0] = val; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 73 | ret = usb_control_msg(udev, |
| 74 | usb_sndctrlpipe(udev, 0), |
| 75 | 0x1, |
| 76 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 77 | 0x0, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 78 | if (ret < 0) |
| 79 | PDEBUG(D_ERR, "write failed"); |
| 80 | } |
| 81 | |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 82 | static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg) |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 83 | { |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 84 | struct usb_device *udev = gspca_dev->dev; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 85 | int ret; |
| 86 | |
| 87 | ret = usb_control_msg(udev, |
| 88 | usb_rcvctrlpipe(udev, 0), |
| 89 | 0x1, |
| 90 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 91 | 0x0, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT); |
| 92 | PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 93 | if (ret < 0) |
| 94 | PDEBUG(D_ERR, "read failed"); |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 95 | return gspca_dev->usb_buf[0]; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 96 | } |
| 97 | |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 98 | /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7. |
| 99 | * (direction and output)? */ |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 100 | static void ov534_set_led(struct gspca_dev *gspca_dev, int status) |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 101 | { |
Antonio Ospite | 9e1e7b0 | 2008-12-03 14:10:01 -0300 | [diff] [blame] | 102 | u8 data; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 103 | |
| 104 | PDEBUG(D_CONF, "led status: %d", status); |
| 105 | |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 106 | data = ov534_reg_read(gspca_dev, 0x21); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 107 | data |= 0x80; |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 108 | ov534_reg_write(gspca_dev, 0x21, data); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 109 | |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 110 | data = ov534_reg_read(gspca_dev, 0x23); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 111 | if (status) |
| 112 | data |= 0x80; |
| 113 | else |
| 114 | data &= ~(0x80); |
| 115 | |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 116 | ov534_reg_write(gspca_dev, 0x23, data); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 117 | } |
| 118 | |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 119 | static int sccb_check_status(struct gspca_dev *gspca_dev) |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 120 | { |
Antonio Ospite | 9e1e7b0 | 2008-12-03 14:10:01 -0300 | [diff] [blame] | 121 | u8 data; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 122 | int i; |
| 123 | |
| 124 | for (i = 0; i < 5; i++) { |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 125 | data = ov534_reg_read(gspca_dev, OV534_REG_STATUS); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 126 | |
Antonio Ospite | 9e1e7b0 | 2008-12-03 14:10:01 -0300 | [diff] [blame] | 127 | switch (data) { |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 128 | case 0x00: |
| 129 | return 1; |
| 130 | case 0x04: |
| 131 | return 0; |
| 132 | case 0x03: |
| 133 | break; |
| 134 | default: |
Jean-Francois Moine | f367b85 | 2008-12-28 06:51:37 -0300 | [diff] [blame] | 135 | PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5", |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 136 | data, i + 1); |
| 137 | } |
| 138 | } |
| 139 | return 0; |
| 140 | } |
| 141 | |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 142 | static void sccb_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val) |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 143 | { |
Antonio Ospite | 9e1e7b0 | 2008-12-03 14:10:01 -0300 | [diff] [blame] | 144 | PDEBUG(D_USBO, "reg: 0x%04x, val: 0x%02x", reg, val); |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 145 | ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg); |
| 146 | ov534_reg_write(gspca_dev, OV534_REG_WRITE, val); |
| 147 | ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 148 | |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 149 | if (!sccb_check_status(gspca_dev)) |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 150 | PDEBUG(D_ERR, "sccb_reg_write failed"); |
| 151 | } |
| 152 | |
Jean-Francois Moine | 1dc87b6 | 2008-12-14 05:50:24 -0300 | [diff] [blame] | 153 | #ifdef GSPCA_DEBUG |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 154 | static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg) |
Antonio Ospite | e6e4837 | 2008-12-14 05:48:07 -0300 | [diff] [blame] | 155 | { |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 156 | ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg); |
| 157 | ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2); |
| 158 | if (!sccb_check_status(gspca_dev)) |
Antonio Ospite | e6e4837 | 2008-12-14 05:48:07 -0300 | [diff] [blame] | 159 | PDEBUG(D_ERR, "sccb_reg_read failed 1"); |
| 160 | |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 161 | ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2); |
| 162 | if (!sccb_check_status(gspca_dev)) |
Antonio Ospite | e6e4837 | 2008-12-14 05:48:07 -0300 | [diff] [blame] | 163 | PDEBUG(D_ERR, "sccb_reg_read failed 2"); |
| 164 | |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 165 | return ov534_reg_read(gspca_dev, OV534_REG_READ); |
Antonio Ospite | e6e4837 | 2008-12-14 05:48:07 -0300 | [diff] [blame] | 166 | } |
Jean-Francois Moine | 1dc87b6 | 2008-12-14 05:50:24 -0300 | [diff] [blame] | 167 | #endif |
Antonio Ospite | e6e4837 | 2008-12-14 05:48:07 -0300 | [diff] [blame] | 168 | |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 169 | static const __u8 ov534_reg_initdata[][2] = { |
| 170 | { 0xe7, 0x3a }, |
| 171 | |
| 172 | { OV534_REG_ADDRESS, 0x42 }, /* select OV772x sensor */ |
| 173 | |
| 174 | { 0xc2, 0x0c }, |
| 175 | { 0x88, 0xf8 }, |
| 176 | { 0xc3, 0x69 }, |
| 177 | { 0x89, 0xff }, |
| 178 | { 0x76, 0x03 }, |
| 179 | { 0x92, 0x01 }, |
| 180 | { 0x93, 0x18 }, |
| 181 | { 0x94, 0x10 }, |
| 182 | { 0x95, 0x10 }, |
| 183 | { 0xe2, 0x00 }, |
| 184 | { 0xe7, 0x3e }, |
| 185 | |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 186 | { 0x96, 0x00 }, |
| 187 | |
| 188 | { 0x97, 0x20 }, |
| 189 | { 0x97, 0x20 }, |
| 190 | { 0x97, 0x20 }, |
| 191 | { 0x97, 0x0a }, |
| 192 | { 0x97, 0x3f }, |
| 193 | { 0x97, 0x4a }, |
| 194 | { 0x97, 0x20 }, |
| 195 | { 0x97, 0x15 }, |
| 196 | { 0x97, 0x0b }, |
| 197 | |
| 198 | { 0x8e, 0x40 }, |
| 199 | { 0x1f, 0x81 }, |
| 200 | { 0x34, 0x05 }, |
| 201 | { 0xe3, 0x04 }, |
| 202 | { 0x88, 0x00 }, |
| 203 | { 0x89, 0x00 }, |
| 204 | { 0x76, 0x00 }, |
| 205 | { 0xe7, 0x2e }, |
| 206 | { 0x31, 0xf9 }, |
| 207 | { 0x25, 0x42 }, |
| 208 | { 0x21, 0xf0 }, |
| 209 | |
| 210 | { 0x1c, 0x00 }, |
| 211 | { 0x1d, 0x40 }, |
Jim Paris | 0f7a50b | 2008-12-10 05:45:14 -0300 | [diff] [blame] | 212 | { 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */ |
| 213 | { 0x1d, 0x00 }, /* payload size */ |
Jim Paris | 5ea9c4d | 2008-12-04 04:36:14 -0300 | [diff] [blame] | 214 | { 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */ |
| 215 | { 0x1d, 0x58 }, /* frame size */ |
| 216 | { 0x1d, 0x00 }, /* frame size */ |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 217 | |
Jim Paris | c06eb61 | 2008-12-10 05:47:44 -0300 | [diff] [blame] | 218 | { 0x1c, 0x0a }, |
| 219 | { 0x1d, 0x08 }, /* turn on UVC header */ |
| 220 | { 0x1d, 0x0e }, /* .. */ |
| 221 | |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 222 | { 0x8d, 0x1c }, |
| 223 | { 0x8e, 0x80 }, |
| 224 | { 0xe5, 0x04 }, |
| 225 | |
| 226 | { 0xc0, 0x50 }, |
| 227 | { 0xc1, 0x3c }, |
| 228 | { 0xc2, 0x0c }, |
| 229 | }; |
| 230 | |
| 231 | static const __u8 ov772x_reg_initdata[][2] = { |
| 232 | { 0x12, 0x80 }, |
| 233 | { 0x11, 0x01 }, |
| 234 | |
| 235 | { 0x3d, 0x03 }, |
| 236 | { 0x17, 0x26 }, |
| 237 | { 0x18, 0xa0 }, |
| 238 | { 0x19, 0x07 }, |
| 239 | { 0x1a, 0xf0 }, |
| 240 | { 0x32, 0x00 }, |
| 241 | { 0x29, 0xa0 }, |
| 242 | { 0x2c, 0xf0 }, |
| 243 | { 0x65, 0x20 }, |
| 244 | { 0x11, 0x01 }, |
| 245 | { 0x42, 0x7f }, |
| 246 | { 0x63, 0xe0 }, |
| 247 | { 0x64, 0xff }, |
| 248 | { 0x66, 0x00 }, |
| 249 | { 0x13, 0xf0 }, |
| 250 | { 0x0d, 0x41 }, |
| 251 | { 0x0f, 0xc5 }, |
| 252 | { 0x14, 0x11 }, |
| 253 | |
| 254 | { 0x22, 0x7f }, |
| 255 | { 0x23, 0x03 }, |
| 256 | { 0x24, 0x40 }, |
| 257 | { 0x25, 0x30 }, |
| 258 | { 0x26, 0xa1 }, |
| 259 | { 0x2a, 0x00 }, |
| 260 | { 0x2b, 0x00 }, |
| 261 | { 0x6b, 0xaa }, |
| 262 | { 0x13, 0xff }, |
| 263 | |
| 264 | { 0x90, 0x05 }, |
| 265 | { 0x91, 0x01 }, |
| 266 | { 0x92, 0x03 }, |
| 267 | { 0x93, 0x00 }, |
| 268 | { 0x94, 0x60 }, |
| 269 | { 0x95, 0x3c }, |
| 270 | { 0x96, 0x24 }, |
| 271 | { 0x97, 0x1e }, |
| 272 | { 0x98, 0x62 }, |
| 273 | { 0x99, 0x80 }, |
| 274 | { 0x9a, 0x1e }, |
| 275 | { 0x9b, 0x08 }, |
| 276 | { 0x9c, 0x20 }, |
| 277 | { 0x9e, 0x81 }, |
| 278 | |
| 279 | { 0xa6, 0x04 }, |
| 280 | { 0x7e, 0x0c }, |
| 281 | { 0x7f, 0x16 }, |
| 282 | { 0x80, 0x2a }, |
| 283 | { 0x81, 0x4e }, |
| 284 | { 0x82, 0x61 }, |
| 285 | { 0x83, 0x6f }, |
| 286 | { 0x84, 0x7b }, |
| 287 | { 0x85, 0x86 }, |
| 288 | { 0x86, 0x8e }, |
| 289 | { 0x87, 0x97 }, |
| 290 | { 0x88, 0xa4 }, |
| 291 | { 0x89, 0xaf }, |
| 292 | { 0x8a, 0xc5 }, |
| 293 | { 0x8b, 0xd7 }, |
| 294 | { 0x8c, 0xe8 }, |
| 295 | { 0x8d, 0x20 }, |
| 296 | |
| 297 | { 0x0c, 0x90 }, |
| 298 | |
| 299 | { 0x2b, 0x00 }, |
| 300 | { 0x22, 0x7f }, |
| 301 | { 0x23, 0x03 }, |
| 302 | { 0x11, 0x01 }, |
| 303 | { 0x0c, 0xd0 }, |
| 304 | { 0x64, 0xff }, |
| 305 | { 0x0d, 0x41 }, |
| 306 | |
| 307 | { 0x14, 0x41 }, |
| 308 | { 0x0e, 0xcd }, |
| 309 | { 0xac, 0xbf }, |
| 310 | { 0x8e, 0x00 }, |
| 311 | { 0x0c, 0xd0 } |
| 312 | }; |
| 313 | |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 314 | /* set framerate */ |
| 315 | static void ov534_set_frame_rate(struct gspca_dev *gspca_dev) |
| 316 | { |
| 317 | struct sd *sd = (struct sd *) gspca_dev; |
| 318 | int fr = sd->frame_rate; |
| 319 | |
| 320 | switch (fr) { |
| 321 | case 50: |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 322 | sccb_reg_write(gspca_dev, 0x11, 0x01); |
| 323 | sccb_reg_write(gspca_dev, 0x0d, 0x41); |
| 324 | ov534_reg_write(gspca_dev, 0xe5, 0x02); |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 325 | break; |
| 326 | case 40: |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 327 | sccb_reg_write(gspca_dev, 0x11, 0x02); |
| 328 | sccb_reg_write(gspca_dev, 0x0d, 0xc1); |
| 329 | ov534_reg_write(gspca_dev, 0xe5, 0x04); |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 330 | break; |
| 331 | /* case 30: */ |
| 332 | default: |
| 333 | fr = 30; |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 334 | sccb_reg_write(gspca_dev, 0x11, 0x04); |
| 335 | sccb_reg_write(gspca_dev, 0x0d, 0x81); |
| 336 | ov534_reg_write(gspca_dev, 0xe5, 0x02); |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 337 | break; |
| 338 | case 15: |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 339 | sccb_reg_write(gspca_dev, 0x11, 0x03); |
| 340 | sccb_reg_write(gspca_dev, 0x0d, 0x41); |
| 341 | ov534_reg_write(gspca_dev, 0xe5, 0x04); |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 342 | break; |
| 343 | } |
| 344 | |
| 345 | sd->frame_rate = fr; |
| 346 | PDEBUG(D_PROBE, "frame_rate: %d", fr); |
| 347 | } |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 348 | |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 349 | /* setup method */ |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 350 | static void ov534_setup(struct gspca_dev *gspca_dev) |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 351 | { |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 352 | int i; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 353 | |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 354 | /* Initialize bridge chip */ |
| 355 | for (i = 0; i < ARRAY_SIZE(ov534_reg_initdata); i++) |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 356 | ov534_reg_write(gspca_dev, ov534_reg_initdata[i][0], |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 357 | ov534_reg_initdata[i][1]); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 358 | |
Antonio Ospite | e6e4837 | 2008-12-14 05:48:07 -0300 | [diff] [blame] | 359 | PDEBUG(D_PROBE, "sensor is ov%02x%02x", |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 360 | sccb_reg_read(gspca_dev, 0x0a), |
| 361 | sccb_reg_read(gspca_dev, 0x0b)); |
Antonio Ospite | e6e4837 | 2008-12-14 05:48:07 -0300 | [diff] [blame] | 362 | |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 363 | ov534_set_led(gspca_dev, 1); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 364 | |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 365 | /* Initialize sensor */ |
| 366 | for (i = 0; i < ARRAY_SIZE(ov772x_reg_initdata); i++) |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 367 | sccb_reg_write(gspca_dev, ov772x_reg_initdata[i][0], |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 368 | ov772x_reg_initdata[i][1]); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 369 | |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 370 | ov534_reg_write(gspca_dev, 0xe0, 0x09); |
| 371 | ov534_set_led(gspca_dev, 0); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | /* this function is called at probe time */ |
| 375 | static int sd_config(struct gspca_dev *gspca_dev, |
| 376 | const struct usb_device_id *id) |
| 377 | { |
| 378 | struct cam *cam; |
| 379 | |
| 380 | cam = &gspca_dev->cam; |
| 381 | |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 382 | cam->cam_mode = vga_mode; |
| 383 | cam->nmodes = ARRAY_SIZE(vga_mode); |
| 384 | |
Jim Paris | 0f7a50b | 2008-12-10 05:45:14 -0300 | [diff] [blame] | 385 | cam->bulk_size = 16384; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 386 | cam->bulk_nurbs = 2; |
| 387 | |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | /* this function is called at probe and resume time */ |
| 392 | static int sd_init(struct gspca_dev *gspca_dev) |
| 393 | { |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 394 | ov534_setup(gspca_dev); |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 395 | ov534_set_frame_rate(gspca_dev); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 396 | |
| 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | static int sd_start(struct gspca_dev *gspca_dev) |
| 401 | { |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 402 | /* start streaming data */ |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 403 | ov534_set_led(gspca_dev, 1); |
| 404 | ov534_reg_write(gspca_dev, 0xe0, 0x00); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 405 | |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | static void sd_stopN(struct gspca_dev *gspca_dev) |
| 410 | { |
| 411 | /* stop streaming data */ |
Jean-Francois Moine | 15f6486 | 2008-12-29 06:19:43 -0300 | [diff] [blame] | 412 | ov534_reg_write(gspca_dev, 0xe0, 0x09); |
| 413 | ov534_set_led(gspca_dev, 0); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 414 | } |
| 415 | |
Jim Paris | fb13922 | 2008-12-04 04:52:40 -0300 | [diff] [blame] | 416 | /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */ |
| 417 | #define UVC_STREAM_EOH (1 << 7) |
| 418 | #define UVC_STREAM_ERR (1 << 6) |
| 419 | #define UVC_STREAM_STI (1 << 5) |
| 420 | #define UVC_STREAM_RES (1 << 4) |
| 421 | #define UVC_STREAM_SCR (1 << 3) |
| 422 | #define UVC_STREAM_PTS (1 << 2) |
| 423 | #define UVC_STREAM_EOF (1 << 1) |
| 424 | #define UVC_STREAM_FID (1 << 0) |
| 425 | |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 426 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, struct gspca_frame *frame, |
| 427 | __u8 *data, int len) |
| 428 | { |
Jean-Francois Moine | 8c25205 | 2008-12-04 05:06:08 -0300 | [diff] [blame] | 429 | struct sd *sd = (struct sd *) gspca_dev; |
Jim Paris | fb13922 | 2008-12-04 04:52:40 -0300 | [diff] [blame] | 430 | __u32 this_pts; |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame^] | 431 | u16 this_fid; |
Jim Paris | 0f7a50b | 2008-12-10 05:45:14 -0300 | [diff] [blame] | 432 | int remaining_len = len; |
Jim Paris | 0f7a50b | 2008-12-10 05:45:14 -0300 | [diff] [blame] | 433 | |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame^] | 434 | do { |
| 435 | len = min(remaining_len, 2040); /*fixme: was 2048*/ |
Jim Paris | 0f7a50b | 2008-12-10 05:45:14 -0300 | [diff] [blame] | 436 | |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame^] | 437 | /* Payloads are prefixed with a UVC-style header. We |
| 438 | consider a frame to start when the FID toggles, or the PTS |
| 439 | changes. A frame ends when EOF is set, and we've received |
| 440 | the correct number of bytes. */ |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 441 | |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame^] | 442 | /* Verify UVC header. Header length is always 12 */ |
| 443 | if (data[0] != 12 || len < 12) { |
| 444 | PDEBUG(D_PACK, "bad header"); |
Jim Paris | fb13922 | 2008-12-04 04:52:40 -0300 | [diff] [blame] | 445 | goto discard; |
| 446 | } |
| 447 | |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame^] | 448 | /* Check errors */ |
| 449 | if (data[1] & UVC_STREAM_ERR) { |
| 450 | PDEBUG(D_PACK, "payload error"); |
| 451 | goto discard; |
Jean-Francois Moine | 3481c19 | 2009-03-19 06:05:06 -0300 | [diff] [blame] | 452 | } |
Jim Paris | fb13922 | 2008-12-04 04:52:40 -0300 | [diff] [blame] | 453 | |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame^] | 454 | /* Extract PTS and FID */ |
| 455 | if (!(data[1] & UVC_STREAM_PTS)) { |
| 456 | PDEBUG(D_PACK, "PTS not present"); |
| 457 | goto discard; |
| 458 | } |
| 459 | this_pts = (data[5] << 24) | (data[4] << 16) |
| 460 | | (data[3] << 8) | data[2]; |
| 461 | this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0; |
| 462 | |
| 463 | /* If PTS or FID has changed, start a new frame. */ |
| 464 | if (this_pts != sd->last_pts || this_fid != sd->last_fid) { |
| 465 | gspca_frame_add(gspca_dev, FIRST_PACKET, frame, |
| 466 | NULL, 0); |
| 467 | sd->last_pts = this_pts; |
| 468 | sd->last_fid = this_fid; |
| 469 | } |
| 470 | |
| 471 | /* Add the data from this payload */ |
| 472 | gspca_frame_add(gspca_dev, INTER_PACKET, frame, |
| 473 | data + 12, len - 12); |
| 474 | |
| 475 | /* If this packet is marked as EOF, end the frame */ |
| 476 | if (data[1] & UVC_STREAM_EOF) { |
| 477 | sd->last_pts = 0; |
| 478 | |
| 479 | if (frame->data_end - frame->data != |
| 480 | gspca_dev->width * gspca_dev->height * 2) { |
| 481 | PDEBUG(D_PACK, "short frame"); |
| 482 | goto discard; |
| 483 | } |
| 484 | |
| 485 | frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame, |
| 486 | NULL, 0); |
| 487 | } |
| 488 | |
| 489 | /* Done this payload */ |
| 490 | goto scan_next; |
Jim Paris | fb13922 | 2008-12-04 04:52:40 -0300 | [diff] [blame] | 491 | |
| 492 | discard: |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame^] | 493 | /* Discard data until a new frame starts. */ |
| 494 | gspca_frame_add(gspca_dev, DISCARD_PACKET, frame, NULL, 0); |
| 495 | |
| 496 | scan_next: |
| 497 | remaining_len -= len; |
| 498 | data += len; |
| 499 | } while (remaining_len > 0); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 500 | } |
| 501 | |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 502 | /* get stream parameters (framerate) */ |
Jean-Francois Moine | 5c1a15a | 2008-12-21 15:02:54 -0300 | [diff] [blame] | 503 | static int sd_get_streamparm(struct gspca_dev *gspca_dev, |
| 504 | struct v4l2_streamparm *parm) |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 505 | { |
| 506 | struct v4l2_captureparm *cp = &parm->parm.capture; |
| 507 | struct v4l2_fract *tpf = &cp->timeperframe; |
| 508 | struct sd *sd = (struct sd *) gspca_dev; |
| 509 | |
| 510 | if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 511 | return -EINVAL; |
| 512 | |
| 513 | cp->capability |= V4L2_CAP_TIMEPERFRAME; |
| 514 | tpf->numerator = 1; |
| 515 | tpf->denominator = sd->frame_rate; |
| 516 | |
| 517 | return 0; |
| 518 | } |
| 519 | |
| 520 | /* set stream parameters (framerate) */ |
Jean-Francois Moine | 5c1a15a | 2008-12-21 15:02:54 -0300 | [diff] [blame] | 521 | static int sd_set_streamparm(struct gspca_dev *gspca_dev, |
| 522 | struct v4l2_streamparm *parm) |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 523 | { |
| 524 | struct v4l2_captureparm *cp = &parm->parm.capture; |
| 525 | struct v4l2_fract *tpf = &cp->timeperframe; |
| 526 | struct sd *sd = (struct sd *) gspca_dev; |
| 527 | |
| 528 | if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 529 | return -EINVAL; |
| 530 | |
| 531 | /* Set requested framerate */ |
| 532 | sd->frame_rate = tpf->denominator / tpf->numerator; |
| 533 | ov534_set_frame_rate(gspca_dev); |
| 534 | |
| 535 | /* Return the actual framerate */ |
| 536 | tpf->numerator = 1; |
| 537 | tpf->denominator = sd->frame_rate; |
| 538 | |
| 539 | return 0; |
| 540 | } |
| 541 | |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 542 | /* sub-driver description */ |
| 543 | static const struct sd_desc sd_desc = { |
| 544 | .name = MODULE_NAME, |
| 545 | .ctrls = sd_ctrls, |
| 546 | .nctrls = ARRAY_SIZE(sd_ctrls), |
| 547 | .config = sd_config, |
| 548 | .init = sd_init, |
| 549 | .start = sd_start, |
| 550 | .stopN = sd_stopN, |
| 551 | .pkt_scan = sd_pkt_scan, |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 552 | .get_streamparm = sd_get_streamparm, |
| 553 | .set_streamparm = sd_set_streamparm, |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 554 | }; |
| 555 | |
| 556 | /* -- module initialisation -- */ |
| 557 | static const __devinitdata struct usb_device_id device_table[] = { |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 558 | {USB_DEVICE(0x1415, 0x2000)}, /* Sony HD Eye for PS3 (SLEH 00201) */ |
| 559 | {} |
| 560 | }; |
| 561 | |
| 562 | MODULE_DEVICE_TABLE(usb, device_table); |
| 563 | |
| 564 | /* -- device connect -- */ |
| 565 | static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 566 | { |
| 567 | return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), |
| 568 | THIS_MODULE); |
| 569 | } |
| 570 | |
| 571 | static struct usb_driver sd_driver = { |
| 572 | .name = MODULE_NAME, |
| 573 | .id_table = device_table, |
| 574 | .probe = sd_probe, |
| 575 | .disconnect = gspca_disconnect, |
| 576 | #ifdef CONFIG_PM |
| 577 | .suspend = gspca_suspend, |
| 578 | .resume = gspca_resume, |
| 579 | #endif |
| 580 | }; |
| 581 | |
| 582 | /* -- module insert / remove -- */ |
| 583 | static int __init sd_mod_init(void) |
| 584 | { |
Alexey Klimov | f69e952 | 2009-01-01 13:02:07 -0300 | [diff] [blame] | 585 | int ret; |
| 586 | ret = usb_register(&sd_driver); |
| 587 | if (ret < 0) |
Alexey Klimov | e6b1484 | 2009-01-01 13:04:58 -0300 | [diff] [blame] | 588 | return ret; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 589 | PDEBUG(D_PROBE, "registered"); |
| 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | static void __exit sd_mod_exit(void) |
| 594 | { |
| 595 | usb_deregister(&sd_driver); |
| 596 | PDEBUG(D_PROBE, "deregistered"); |
| 597 | } |
| 598 | |
| 599 | module_init(sd_mod_init); |
| 600 | module_exit(sd_mod_exit); |