Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * GSPCA sub driver for W996[78]CF JPEG USB Dual Mode Camera Chip. |
| 4 | * |
| 5 | * Copyright (C) 2009 Hans de Goede <hdegoede@redhat.com> |
| 6 | * |
| 7 | * This module is adapted from the in kernel v4l1 w9968cf driver: |
| 8 | * |
| 9 | * Copyright (C) 2002-2004 by Luca Risolia <luca.risolia@studio.unibo.it> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | /* Note this is not a stand alone driver, it gets included in ov519.c, this |
| 28 | is a bit of a hack, but it needs the driver code for a lot of different |
| 29 | ov sensors which is already present in ov519.c (the old v4l1 driver used |
| 30 | the ovchipcam framework). When we have the time we really should move |
| 31 | the sensor drivers to v4l2 sub drivers, and properly split of this |
| 32 | driver from ov519.c */ |
| 33 | |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 34 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 35 | |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 36 | #define W9968CF_I2C_BUS_DELAY 4 /* delay in us for I2C bit r/w operations */ |
| 37 | |
Jean-François Moine | 9a731a3 | 2010-06-04 05:26:42 -0300 | [diff] [blame] | 38 | #define Y_QUANTABLE (&sd->jpeg_hdr[JPEG_QT0_OFFSET]) |
| 39 | #define UV_QUANTABLE (&sd->jpeg_hdr[JPEG_QT1_OFFSET]) |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 40 | |
| 41 | static const struct v4l2_pix_format w9968cf_vga_mode[] = { |
| 42 | {160, 120, V4L2_PIX_FMT_UYVY, V4L2_FIELD_NONE, |
| 43 | .bytesperline = 160 * 2, |
| 44 | .sizeimage = 160 * 120 * 2, |
| 45 | .colorspace = V4L2_COLORSPACE_JPEG}, |
| 46 | {176, 144, V4L2_PIX_FMT_UYVY, V4L2_FIELD_NONE, |
| 47 | .bytesperline = 176 * 2, |
| 48 | .sizeimage = 176 * 144 * 2, |
| 49 | .colorspace = V4L2_COLORSPACE_JPEG}, |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 50 | {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 51 | .bytesperline = 320 * 2, |
| 52 | .sizeimage = 320 * 240 * 2, |
| 53 | .colorspace = V4L2_COLORSPACE_JPEG}, |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 54 | {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 55 | .bytesperline = 352 * 2, |
| 56 | .sizeimage = 352 * 288 * 2, |
| 57 | .colorspace = V4L2_COLORSPACE_JPEG}, |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 58 | {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 59 | .bytesperline = 640 * 2, |
| 60 | .sizeimage = 640 * 480 * 2, |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 61 | .colorspace = V4L2_COLORSPACE_JPEG}, |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 62 | }; |
| 63 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 64 | static void reg_w(struct sd *sd, u16 index, u16 value); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 65 | |
| 66 | /*-------------------------------------------------------------------------- |
| 67 | Write 64-bit data to the fast serial bus registers. |
| 68 | Return 0 on success, -1 otherwise. |
| 69 | --------------------------------------------------------------------------*/ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 70 | static void w9968cf_write_fsb(struct sd *sd, u16* data) |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 71 | { |
Jean-François Moine | 780e312 | 2010-10-19 04:29:10 -0300 | [diff] [blame] | 72 | struct usb_device *udev = sd->gspca_dev.dev; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 73 | u16 value; |
| 74 | int ret; |
| 75 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 76 | if (sd->gspca_dev.usb_err < 0) |
| 77 | return; |
| 78 | |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 79 | value = *data++; |
| 80 | memcpy(sd->gspca_dev.usb_buf, data, 6); |
| 81 | |
Wesley Post | f7c7ac4 | 2016-02-29 15:39:10 -0300 | [diff] [blame] | 82 | /* Avoid things going to fast for the bridge with a xhci host */ |
| 83 | udelay(150); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 84 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0, |
| 85 | USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE, |
| 86 | value, 0x06, sd->gspca_dev.usb_buf, 6, 500); |
| 87 | if (ret < 0) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 88 | pr_err("Write FSB registers failed (%d)\n", ret); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 89 | sd->gspca_dev.usb_err = ret; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 90 | } |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /*-------------------------------------------------------------------------- |
| 94 | Write data to the serial bus control register. |
| 95 | Return 0 on success, a negative number otherwise. |
| 96 | --------------------------------------------------------------------------*/ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 97 | static void w9968cf_write_sb(struct sd *sd, u16 value) |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 98 | { |
| 99 | int ret; |
| 100 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 101 | if (sd->gspca_dev.usb_err < 0) |
| 102 | return; |
| 103 | |
Wesley Post | f7c7ac4 | 2016-02-29 15:39:10 -0300 | [diff] [blame] | 104 | /* Avoid things going to fast for the bridge with a xhci host */ |
| 105 | udelay(150); |
| 106 | |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 107 | /* We don't use reg_w here, as that would cause all writes when |
| 108 | bitbanging i2c to be logged, making the logs impossible to read */ |
| 109 | ret = usb_control_msg(sd->gspca_dev.dev, |
| 110 | usb_sndctrlpipe(sd->gspca_dev.dev, 0), |
| 111 | 0, |
| 112 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 113 | value, 0x01, NULL, 0, 500); |
| 114 | |
| 115 | udelay(W9968CF_I2C_BUS_DELAY); |
| 116 | |
| 117 | if (ret < 0) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 118 | pr_err("Write SB reg [01] %04x failed\n", value); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 119 | sd->gspca_dev.usb_err = ret; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 120 | } |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /*-------------------------------------------------------------------------- |
| 124 | Read data from the serial bus control register. |
| 125 | Return 0 on success, a negative number otherwise. |
| 126 | --------------------------------------------------------------------------*/ |
| 127 | static int w9968cf_read_sb(struct sd *sd) |
| 128 | { |
| 129 | int ret; |
| 130 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 131 | if (sd->gspca_dev.usb_err < 0) |
| 132 | return -1; |
| 133 | |
Wesley Post | f7c7ac4 | 2016-02-29 15:39:10 -0300 | [diff] [blame] | 134 | /* Avoid things going to fast for the bridge with a xhci host */ |
| 135 | udelay(150); |
| 136 | |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 137 | /* We don't use reg_r here, as the w9968cf is special and has 16 |
| 138 | bit registers instead of 8 bit */ |
| 139 | ret = usb_control_msg(sd->gspca_dev.dev, |
| 140 | usb_rcvctrlpipe(sd->gspca_dev.dev, 0), |
| 141 | 1, |
| 142 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 143 | 0, 0x01, sd->gspca_dev.usb_buf, 2, 500); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 144 | if (ret >= 0) { |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 145 | ret = sd->gspca_dev.usb_buf[0] | |
| 146 | (sd->gspca_dev.usb_buf[1] << 8); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 147 | } else { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 148 | pr_err("Read SB reg [01] failed\n"); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 149 | sd->gspca_dev.usb_err = ret; |
| 150 | } |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 151 | |
| 152 | udelay(W9968CF_I2C_BUS_DELAY); |
| 153 | |
| 154 | return ret; |
| 155 | } |
| 156 | |
| 157 | /*-------------------------------------------------------------------------- |
| 158 | Upload quantization tables for the JPEG compression. |
| 159 | This function is called by w9968cf_start_transfer(). |
| 160 | Return 0 on success, a negative number otherwise. |
| 161 | --------------------------------------------------------------------------*/ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 162 | static void w9968cf_upload_quantizationtables(struct sd *sd) |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 163 | { |
| 164 | u16 a, b; |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 165 | int i, j; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 166 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 167 | reg_w(sd, 0x39, 0x0010); /* JPEG clock enable */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 168 | |
| 169 | for (i = 0, j = 0; i < 32; i++, j += 2) { |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 170 | a = Y_QUANTABLE[j] | ((unsigned)(Y_QUANTABLE[j + 1]) << 8); |
| 171 | b = UV_QUANTABLE[j] | ((unsigned)(UV_QUANTABLE[j + 1]) << 8); |
| 172 | reg_w(sd, 0x40 + i, a); |
| 173 | reg_w(sd, 0x60 + i, b); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 174 | } |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 175 | reg_w(sd, 0x39, 0x0012); /* JPEG encoder enable */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /**************************************************************************** |
| 179 | * Low-level I2C I/O functions. * |
| 180 | * The adapter supports the following I2C transfer functions: * |
| 181 | * i2c_adap_fastwrite_byte_data() (at 400 kHz bit frequency only) * |
| 182 | * i2c_adap_read_byte_data() * |
| 183 | * i2c_adap_read_byte() * |
| 184 | ****************************************************************************/ |
| 185 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 186 | static void w9968cf_smbus_start(struct sd *sd) |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 187 | { |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 188 | w9968cf_write_sb(sd, 0x0011); /* SDE=1, SDA=0, SCL=1 */ |
| 189 | w9968cf_write_sb(sd, 0x0010); /* SDE=1, SDA=0, SCL=0 */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 190 | } |
| 191 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 192 | static void w9968cf_smbus_stop(struct sd *sd) |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 193 | { |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 194 | w9968cf_write_sb(sd, 0x0010); /* SDE=1, SDA=0, SCL=0 */ |
| 195 | w9968cf_write_sb(sd, 0x0011); /* SDE=1, SDA=0, SCL=1 */ |
| 196 | w9968cf_write_sb(sd, 0x0013); /* SDE=1, SDA=1, SCL=1 */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 197 | } |
| 198 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 199 | static void w9968cf_smbus_write_byte(struct sd *sd, u8 v) |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 200 | { |
| 201 | u8 bit; |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 202 | int sda; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 203 | |
| 204 | for (bit = 0 ; bit < 8 ; bit++) { |
| 205 | sda = (v & 0x80) ? 2 : 0; |
| 206 | v <<= 1; |
| 207 | /* SDE=1, SDA=sda, SCL=0 */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 208 | w9968cf_write_sb(sd, 0x10 | sda); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 209 | /* SDE=1, SDA=sda, SCL=1 */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 210 | w9968cf_write_sb(sd, 0x11 | sda); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 211 | /* SDE=1, SDA=sda, SCL=0 */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 212 | w9968cf_write_sb(sd, 0x10 | sda); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 213 | } |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 214 | } |
| 215 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 216 | static void w9968cf_smbus_read_byte(struct sd *sd, u8 *v) |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 217 | { |
| 218 | u8 bit; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 219 | |
| 220 | /* No need to ensure SDA is high as we are always called after |
| 221 | read_ack which ends with SDA high */ |
| 222 | *v = 0; |
| 223 | for (bit = 0 ; bit < 8 ; bit++) { |
| 224 | *v <<= 1; |
| 225 | /* SDE=1, SDA=1, SCL=1 */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 226 | w9968cf_write_sb(sd, 0x0013); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 227 | *v |= (w9968cf_read_sb(sd) & 0x0008) ? 1 : 0; |
| 228 | /* SDE=1, SDA=1, SCL=0 */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 229 | w9968cf_write_sb(sd, 0x0012); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 230 | } |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 231 | } |
| 232 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 233 | static void w9968cf_smbus_write_nack(struct sd *sd) |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 234 | { |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 235 | /* No need to ensure SDA is high as we are always called after |
| 236 | read_byte which ends with SDA high */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 237 | w9968cf_write_sb(sd, 0x0013); /* SDE=1, SDA=1, SCL=1 */ |
| 238 | w9968cf_write_sb(sd, 0x0012); /* SDE=1, SDA=1, SCL=0 */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 239 | } |
| 240 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 241 | static void w9968cf_smbus_read_ack(struct sd *sd) |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 242 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 243 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 244 | int sda; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 245 | |
| 246 | /* Ensure SDA is high before raising clock to avoid a spurious stop */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 247 | w9968cf_write_sb(sd, 0x0012); /* SDE=1, SDA=1, SCL=0 */ |
| 248 | w9968cf_write_sb(sd, 0x0013); /* SDE=1, SDA=1, SCL=1 */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 249 | sda = w9968cf_read_sb(sd); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 250 | w9968cf_write_sb(sd, 0x0012); /* SDE=1, SDA=1, SCL=0 */ |
| 251 | if (sda >= 0 && (sda & 0x08)) { |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 252 | PDEBUG(D_USBI, "Did not receive i2c ACK"); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 253 | sd->gspca_dev.usb_err = -EIO; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 254 | } |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | /* SMBus protocol: S Addr Wr [A] Subaddr [A] Value [A] P */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 258 | static void w9968cf_i2c_w(struct sd *sd, u8 reg, u8 value) |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 259 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 260 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 261 | u16* data = (u16 *)sd->gspca_dev.usb_buf; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 262 | |
| 263 | data[0] = 0x082f | ((sd->sensor_addr & 0x80) ? 0x1500 : 0x0); |
| 264 | data[0] |= (sd->sensor_addr & 0x40) ? 0x4000 : 0x0; |
| 265 | data[1] = 0x2082 | ((sd->sensor_addr & 0x40) ? 0x0005 : 0x0); |
| 266 | data[1] |= (sd->sensor_addr & 0x20) ? 0x0150 : 0x0; |
| 267 | data[1] |= (sd->sensor_addr & 0x10) ? 0x5400 : 0x0; |
| 268 | data[2] = 0x8208 | ((sd->sensor_addr & 0x08) ? 0x0015 : 0x0); |
| 269 | data[2] |= (sd->sensor_addr & 0x04) ? 0x0540 : 0x0; |
| 270 | data[2] |= (sd->sensor_addr & 0x02) ? 0x5000 : 0x0; |
| 271 | data[3] = 0x1d20 | ((sd->sensor_addr & 0x02) ? 0x0001 : 0x0); |
| 272 | data[3] |= (sd->sensor_addr & 0x01) ? 0x0054 : 0x0; |
| 273 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 274 | w9968cf_write_fsb(sd, data); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 275 | |
| 276 | data[0] = 0x8208 | ((reg & 0x80) ? 0x0015 : 0x0); |
| 277 | data[0] |= (reg & 0x40) ? 0x0540 : 0x0; |
| 278 | data[0] |= (reg & 0x20) ? 0x5000 : 0x0; |
| 279 | data[1] = 0x0820 | ((reg & 0x20) ? 0x0001 : 0x0); |
| 280 | data[1] |= (reg & 0x10) ? 0x0054 : 0x0; |
| 281 | data[1] |= (reg & 0x08) ? 0x1500 : 0x0; |
| 282 | data[1] |= (reg & 0x04) ? 0x4000 : 0x0; |
| 283 | data[2] = 0x2082 | ((reg & 0x04) ? 0x0005 : 0x0); |
| 284 | data[2] |= (reg & 0x02) ? 0x0150 : 0x0; |
| 285 | data[2] |= (reg & 0x01) ? 0x5400 : 0x0; |
| 286 | data[3] = 0x001d; |
| 287 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 288 | w9968cf_write_fsb(sd, data); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 289 | |
| 290 | data[0] = 0x8208 | ((value & 0x80) ? 0x0015 : 0x0); |
| 291 | data[0] |= (value & 0x40) ? 0x0540 : 0x0; |
| 292 | data[0] |= (value & 0x20) ? 0x5000 : 0x0; |
| 293 | data[1] = 0x0820 | ((value & 0x20) ? 0x0001 : 0x0); |
| 294 | data[1] |= (value & 0x10) ? 0x0054 : 0x0; |
| 295 | data[1] |= (value & 0x08) ? 0x1500 : 0x0; |
| 296 | data[1] |= (value & 0x04) ? 0x4000 : 0x0; |
| 297 | data[2] = 0x2082 | ((value & 0x04) ? 0x0005 : 0x0); |
| 298 | data[2] |= (value & 0x02) ? 0x0150 : 0x0; |
| 299 | data[2] |= (value & 0x01) ? 0x5400 : 0x0; |
| 300 | data[3] = 0xfe1d; |
| 301 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 302 | w9968cf_write_fsb(sd, data); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 303 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 304 | PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | /* SMBus protocol: S Addr Wr [A] Subaddr [A] P S Addr+1 Rd [A] [Value] NA P */ |
| 308 | static int w9968cf_i2c_r(struct sd *sd, u8 reg) |
| 309 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 310 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 311 | int ret = 0; |
| 312 | u8 value; |
| 313 | |
| 314 | /* Fast serial bus data control disable */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 315 | w9968cf_write_sb(sd, 0x0013); /* don't change ! */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 316 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 317 | w9968cf_smbus_start(sd); |
| 318 | w9968cf_smbus_write_byte(sd, sd->sensor_addr); |
| 319 | w9968cf_smbus_read_ack(sd); |
| 320 | w9968cf_smbus_write_byte(sd, reg); |
| 321 | w9968cf_smbus_read_ack(sd); |
| 322 | w9968cf_smbus_stop(sd); |
| 323 | w9968cf_smbus_start(sd); |
| 324 | w9968cf_smbus_write_byte(sd, sd->sensor_addr + 1); |
| 325 | w9968cf_smbus_read_ack(sd); |
| 326 | w9968cf_smbus_read_byte(sd, &value); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 327 | /* signal we don't want to read anymore, the v4l1 driver used to |
| 328 | send an ack here which is very wrong! (and then fixed |
| 329 | the issues this gave by retrying reads) */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 330 | w9968cf_smbus_write_nack(sd); |
| 331 | w9968cf_smbus_stop(sd); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 332 | |
| 333 | /* Fast serial bus data control re-enable */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 334 | w9968cf_write_sb(sd, 0x0030); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 335 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 336 | if (sd->gspca_dev.usb_err >= 0) { |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 337 | ret = value; |
| 338 | PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value); |
| 339 | } else |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 340 | PERR("i2c read [0x%02x] failed", reg); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 341 | |
| 342 | return ret; |
| 343 | } |
| 344 | |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 345 | /*-------------------------------------------------------------------------- |
| 346 | Turn on the LED on some webcams. A beep should be heard too. |
| 347 | Return 0 on success, a negative number otherwise. |
| 348 | --------------------------------------------------------------------------*/ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 349 | static void w9968cf_configure(struct sd *sd) |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 350 | { |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 351 | reg_w(sd, 0x00, 0xff00); /* power-down */ |
| 352 | reg_w(sd, 0x00, 0xbf17); /* reset everything */ |
| 353 | reg_w(sd, 0x00, 0xbf10); /* normal operation */ |
| 354 | reg_w(sd, 0x01, 0x0010); /* serial bus, SDS high */ |
| 355 | reg_w(sd, 0x01, 0x0000); /* serial bus, SDS low */ |
| 356 | reg_w(sd, 0x01, 0x0010); /* ..high 'beep-beep' */ |
| 357 | reg_w(sd, 0x01, 0x0030); /* Set sda scl to FSB mode */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 358 | |
| 359 | sd->stopped = 1; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 360 | } |
| 361 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 362 | static void w9968cf_init(struct sd *sd) |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 363 | { |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 364 | unsigned long hw_bufsize = sd->sif ? (352 * 288 * 2) : (640 * 480 * 2), |
| 365 | y0 = 0x0000, |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 366 | u0 = y0 + hw_bufsize / 2, |
| 367 | v0 = u0 + hw_bufsize / 4, |
| 368 | y1 = v0 + hw_bufsize / 4, |
| 369 | u1 = y1 + hw_bufsize / 2, |
| 370 | v1 = u1 + hw_bufsize / 4; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 371 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 372 | reg_w(sd, 0x00, 0xff00); /* power off */ |
| 373 | reg_w(sd, 0x00, 0xbf10); /* power on */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 374 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 375 | reg_w(sd, 0x03, 0x405d); /* DRAM timings */ |
| 376 | reg_w(sd, 0x04, 0x0030); /* SDRAM timings */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 377 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 378 | reg_w(sd, 0x20, y0 & 0xffff); /* Y buf.0, low */ |
| 379 | reg_w(sd, 0x21, y0 >> 16); /* Y buf.0, high */ |
| 380 | reg_w(sd, 0x24, u0 & 0xffff); /* U buf.0, low */ |
| 381 | reg_w(sd, 0x25, u0 >> 16); /* U buf.0, high */ |
| 382 | reg_w(sd, 0x28, v0 & 0xffff); /* V buf.0, low */ |
| 383 | reg_w(sd, 0x29, v0 >> 16); /* V buf.0, high */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 384 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 385 | reg_w(sd, 0x22, y1 & 0xffff); /* Y buf.1, low */ |
| 386 | reg_w(sd, 0x23, y1 >> 16); /* Y buf.1, high */ |
| 387 | reg_w(sd, 0x26, u1 & 0xffff); /* U buf.1, low */ |
| 388 | reg_w(sd, 0x27, u1 >> 16); /* U buf.1, high */ |
| 389 | reg_w(sd, 0x2a, v1 & 0xffff); /* V buf.1, low */ |
| 390 | reg_w(sd, 0x2b, v1 >> 16); /* V buf.1, high */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 391 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 392 | reg_w(sd, 0x32, y1 & 0xffff); /* JPEG buf 0 low */ |
| 393 | reg_w(sd, 0x33, y1 >> 16); /* JPEG buf 0 high */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 394 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 395 | reg_w(sd, 0x34, y1 & 0xffff); /* JPEG buf 1 low */ |
| 396 | reg_w(sd, 0x35, y1 >> 16); /* JPEG bug 1 high */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 397 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 398 | reg_w(sd, 0x36, 0x0000);/* JPEG restart interval */ |
| 399 | reg_w(sd, 0x37, 0x0804);/*JPEG VLE FIFO threshold*/ |
| 400 | reg_w(sd, 0x38, 0x0000);/* disable hw up-scaling */ |
| 401 | reg_w(sd, 0x3f, 0x0000); /* JPEG/MCTL test data */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 402 | } |
| 403 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 404 | static void w9968cf_set_crop_window(struct sd *sd) |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 405 | { |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 406 | int start_cropx, start_cropy, x, y, fw, fh, cw, ch, |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 407 | max_width, max_height; |
| 408 | |
| 409 | if (sd->sif) { |
| 410 | max_width = 352; |
| 411 | max_height = 288; |
| 412 | } else { |
| 413 | max_width = 640; |
| 414 | max_height = 480; |
| 415 | } |
| 416 | |
| 417 | if (sd->sensor == SEN_OV7620) { |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 418 | /* |
| 419 | * Sigh, this is dependend on the clock / framerate changes |
| 420 | * made by the frequency control, sick. |
| 421 | * |
| 422 | * Note we cannot use v4l2_ctrl_g_ctrl here, as we get called |
| 423 | * from ov519.c:setfreq() with the ctrl lock held! |
| 424 | */ |
| 425 | if (sd->freq->val == 1) { |
Hans de Goede | 7399787 | 2009-10-19 06:47:03 -0300 | [diff] [blame] | 426 | start_cropx = 277; |
| 427 | start_cropy = 37; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 428 | } else { |
Hans de Goede | 7399787 | 2009-10-19 06:47:03 -0300 | [diff] [blame] | 429 | start_cropx = 105; |
| 430 | start_cropy = 37; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 431 | } |
| 432 | } else { |
| 433 | start_cropx = 320; |
| 434 | start_cropy = 35; |
| 435 | } |
| 436 | |
| 437 | /* Work around to avoid FP arithmetics */ |
| 438 | #define SC(x) ((x) << 10) |
| 439 | |
| 440 | /* Scaling factors */ |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 441 | fw = SC(sd->gspca_dev.pixfmt.width) / max_width; |
| 442 | fh = SC(sd->gspca_dev.pixfmt.height) / max_height; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 443 | |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 444 | cw = (fw >= fh) ? max_width : SC(sd->gspca_dev.pixfmt.width) / fh; |
| 445 | ch = (fw >= fh) ? SC(sd->gspca_dev.pixfmt.height) / fw : max_height; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 446 | |
| 447 | sd->sensor_width = max_width; |
| 448 | sd->sensor_height = max_height; |
| 449 | |
| 450 | x = (max_width - cw) / 2; |
| 451 | y = (max_height - ch) / 2; |
| 452 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 453 | reg_w(sd, 0x10, start_cropx + x); |
| 454 | reg_w(sd, 0x11, start_cropy + y); |
| 455 | reg_w(sd, 0x12, start_cropx + x + cw); |
| 456 | reg_w(sd, 0x13, start_cropy + y + ch); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 457 | } |
| 458 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 459 | static void w9968cf_mode_init_regs(struct sd *sd) |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 460 | { |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 461 | int val, vs_polarity, hs_polarity; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 462 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 463 | w9968cf_set_crop_window(sd); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 464 | |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 465 | reg_w(sd, 0x14, sd->gspca_dev.pixfmt.width); |
| 466 | reg_w(sd, 0x15, sd->gspca_dev.pixfmt.height); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 467 | |
| 468 | /* JPEG width & height */ |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 469 | reg_w(sd, 0x30, sd->gspca_dev.pixfmt.width); |
| 470 | reg_w(sd, 0x31, sd->gspca_dev.pixfmt.height); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 471 | |
| 472 | /* Y & UV frame buffer strides (in WORD) */ |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 473 | if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat == |
| 474 | V4L2_PIX_FMT_JPEG) { |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 475 | reg_w(sd, 0x2c, sd->gspca_dev.pixfmt.width / 2); |
| 476 | reg_w(sd, 0x2d, sd->gspca_dev.pixfmt.width / 4); |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 477 | } else |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 478 | reg_w(sd, 0x2c, sd->gspca_dev.pixfmt.width); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 479 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 480 | reg_w(sd, 0x00, 0xbf17); /* reset everything */ |
| 481 | reg_w(sd, 0x00, 0xbf10); /* normal operation */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 482 | |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 483 | /* Transfer size in WORDS (for UYVY format only) */ |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 484 | val = sd->gspca_dev.pixfmt.width * sd->gspca_dev.pixfmt.height; |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 485 | reg_w(sd, 0x3d, val & 0xffff); /* low bits */ |
| 486 | reg_w(sd, 0x3e, val >> 16); /* high bits */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 487 | |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 488 | if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat == |
| 489 | V4L2_PIX_FMT_JPEG) { |
| 490 | /* We may get called multiple times (usb isoc bw negotiat.) */ |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 491 | jpeg_define(sd->jpeg_hdr, sd->gspca_dev.pixfmt.height, |
| 492 | sd->gspca_dev.pixfmt.width, 0x22); /* JPEG 420 */ |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 493 | jpeg_set_qual(sd->jpeg_hdr, v4l2_ctrl_g_ctrl(sd->jpegqual)); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 494 | w9968cf_upload_quantizationtables(sd); |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 495 | v4l2_ctrl_grab(sd->jpegqual, true); |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 496 | } |
| 497 | |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 498 | /* Video Capture Control Register */ |
| 499 | if (sd->sensor == SEN_OV7620) { |
| 500 | /* Seems to work around a bug in the image sensor */ |
| 501 | vs_polarity = 1; |
| 502 | hs_polarity = 1; |
| 503 | } else { |
| 504 | vs_polarity = 1; |
| 505 | hs_polarity = 0; |
| 506 | } |
| 507 | |
| 508 | val = (vs_polarity << 12) | (hs_polarity << 11); |
| 509 | |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 510 | /* NOTE: We may not have enough memory to do double buffering while |
| 511 | doing compression (amount of memory differs per model cam). |
| 512 | So we use the second image buffer also as jpeg stream buffer |
| 513 | (see w9968cf_init), and disable double buffering. */ |
| 514 | if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat == |
| 515 | V4L2_PIX_FMT_JPEG) { |
| 516 | /* val |= 0x0002; YUV422P */ |
| 517 | val |= 0x0003; /* YUV420P */ |
| 518 | } else |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 519 | val |= 0x0080; /* Enable HW double buffering */ |
| 520 | |
| 521 | /* val |= 0x0020; enable clamping */ |
| 522 | /* val |= 0x0008; enable (1-2-1) filter */ |
| 523 | /* val |= 0x000c; enable (2-3-6-3-2) filter */ |
| 524 | |
| 525 | val |= 0x8000; /* capt. enable */ |
| 526 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 527 | reg_w(sd, 0x16, val); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 528 | |
| 529 | sd->gspca_dev.empty_packet = 0; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 530 | } |
| 531 | |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 532 | static void w9968cf_stop0(struct sd *sd) |
| 533 | { |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 534 | v4l2_ctrl_grab(sd->jpegqual, false); |
Jean-François Moine | d65174c | 2010-11-11 06:20:42 -0300 | [diff] [blame] | 535 | reg_w(sd, 0x39, 0x0000); /* disable JPEG encoder */ |
| 536 | reg_w(sd, 0x16, 0x0000); /* stop video capture */ |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /* The w9968cf docs say that a 0 sized packet means EOF (and also SOF |
| 540 | for the next frame). This seems to simply not be true when operating |
| 541 | in JPEG mode, in this case there may be empty packets within the |
| 542 | frame. So in JPEG mode use the JPEG SOI marker to detect SOF. |
| 543 | |
| 544 | Note to make things even more interesting the w9968cf sends *PLANAR* jpeg, |
| 545 | to be precise it sends: SOI, SOF, DRI, SOS, Y-data, SOS, U-data, SOS, |
| 546 | V-data, EOI. */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 547 | static void w9968cf_pkt_scan(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 548 | u8 *data, /* isoc packet */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 549 | int len) /* iso packet length */ |
| 550 | { |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 551 | struct sd *sd = (struct sd *) gspca_dev; |
| 552 | |
| 553 | if (w9968cf_vga_mode[gspca_dev->curr_mode].pixelformat == |
| 554 | V4L2_PIX_FMT_JPEG) { |
| 555 | if (len >= 2 && |
| 556 | data[0] == 0xff && |
| 557 | data[1] == 0xd8) { |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 558 | gspca_frame_add(gspca_dev, LAST_PACKET, |
Hans de Goede | 8394bcf | 2009-10-16 11:26:22 -0300 | [diff] [blame] | 559 | NULL, 0); |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 560 | gspca_frame_add(gspca_dev, FIRST_PACKET, |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 561 | sd->jpeg_hdr, JPEG_HDR_SZ); |
| 562 | /* Strip the ff d8, our own header (which adds |
| 563 | huffman and quantization tables) already has this */ |
| 564 | len -= 2; |
| 565 | data += 2; |
| 566 | } |
| 567 | } else { |
| 568 | /* In UYVY mode an empty packet signals EOF */ |
| 569 | if (gspca_dev->empty_packet) { |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 570 | gspca_frame_add(gspca_dev, LAST_PACKET, |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 571 | NULL, 0); |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 572 | gspca_frame_add(gspca_dev, FIRST_PACKET, |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 573 | NULL, 0); |
| 574 | gspca_dev->empty_packet = 0; |
| 575 | } |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 576 | } |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 577 | gspca_frame_add(gspca_dev, INTER_PACKET, data, len); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 578 | } |