From 16631aedb23bac40332549dcaed90c804271cc5b Mon Sep 17 00:00:00 2001 From: Jean-Francois Moine Date: Thu, 22 Jan 2009 14:56:42 -0300 Subject: [PATCH] V4L/DVB (10383): gspca - spca505: Cleanup and optimize code. Signed-off-by: Jean-Francois Moine Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/gspca/spca505.c | 429 ++++++++++++++-------------- 1 file changed, 208 insertions(+), 221 deletions(-) diff --git a/drivers/media/video/gspca/spca505.c b/drivers/media/video/gspca/spca505.c index 25e2bec9dc52..c99bf62614f3 100644 --- a/drivers/media/video/gspca/spca505.c +++ b/drivers/media/video/gspca/spca505.c @@ -31,9 +31,9 @@ MODULE_LICENSE("GPL"); struct sd { struct gspca_dev gspca_dev; /* !! must be the first item */ - unsigned char brightness; + u8 brightness; - char subtype; + u8 subtype; #define IntelPCCameraPro 0 #define Nxultra 1 }; @@ -43,7 +43,6 @@ static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); static struct ctrl sd_ctrls[] = { -#define SD_BRIGHTNESS 0 { { .id = V4L2_CID_BRIGHTNESS, @@ -52,7 +51,8 @@ static struct ctrl sd_ctrls[] = { .minimum = 0, .maximum = 255, .step = 1, - .default_value = 127, +#define BRIGHTNESS_DEF 127 + .default_value = BRIGHTNESS_DEF, }, .set = sd_setbrightness, .get = sd_getbrightness, @@ -104,227 +104,224 @@ static const struct v4l2_pix_format vga_mode[] = { /* * Data to initialize a SPCA505. Common to the CCD and external modes */ -static const __u16 spca505_init_data[][3] = { - /* line bmRequest,value,index */ - /* 1819 */ +static const u8 spca505_init_data[][3] = { + /* bmRequest,value,index */ {SPCA50X_REG_GLOBAL, SPCA50X_GMISC3_SAA7113RST, SPCA50X_GLOBAL_MISC3}, /* Sensor reset */ - /* 1822 */ {SPCA50X_REG_GLOBAL, 0x00, SPCA50X_GLOBAL_MISC3}, - /* 1825 */ {SPCA50X_REG_GLOBAL, 0x00, SPCA50X_GLOBAL_MISC1}, + {SPCA50X_REG_GLOBAL, 0x00, SPCA50X_GLOBAL_MISC3}, + {SPCA50X_REG_GLOBAL, 0x00, SPCA50X_GLOBAL_MISC1}, /* Block USB reset */ - /* 1828 */ {SPCA50X_REG_GLOBAL, SPCA50X_GMISC0_IDSEL, - SPCA50X_GLOBAL_MISC0}, + {SPCA50X_REG_GLOBAL, SPCA50X_GMISC0_IDSEL, SPCA50X_GLOBAL_MISC0}, - /* 1831 */ {0x5, 0x01, 0x10}, + {0x05, 0x01, 0x10}, /* Maybe power down some stuff */ - /* 1834 */ {0x5, 0x0f, 0x11}, + {0x05, 0x0f, 0x11}, /* Setup internal CCD ? */ - /* 1837 */ {0x6, 0x10, 0x08}, - /* 1840 */ {0x6, 0x00, 0x09}, - /* 1843 */ {0x6, 0x00, 0x0a}, - /* 1846 */ {0x6, 0x00, 0x0b}, - /* 1849 */ {0x6, 0x10, 0x0c}, - /* 1852 */ {0x6, 0x00, 0x0d}, - /* 1855 */ {0x6, 0x00, 0x0e}, - /* 1858 */ {0x6, 0x00, 0x0f}, - /* 1861 */ {0x6, 0x10, 0x10}, - /* 1864 */ {0x6, 0x02, 0x11}, - /* 1867 */ {0x6, 0x00, 0x12}, - /* 1870 */ {0x6, 0x04, 0x13}, - /* 1873 */ {0x6, 0x02, 0x14}, - /* 1876 */ {0x6, 0x8a, 0x51}, - /* 1879 */ {0x6, 0x40, 0x52}, - /* 1882 */ {0x6, 0xb6, 0x53}, - /* 1885 */ {0x6, 0x3d, 0x54}, + {0x06, 0x10, 0x08}, + {0x06, 0x00, 0x09}, + {0x06, 0x00, 0x0a}, + {0x06, 0x00, 0x0b}, + {0x06, 0x10, 0x0c}, + {0x06, 0x00, 0x0d}, + {0x06, 0x00, 0x0e}, + {0x06, 0x00, 0x0f}, + {0x06, 0x10, 0x10}, + {0x06, 0x02, 0x11}, + {0x06, 0x00, 0x12}, + {0x06, 0x04, 0x13}, + {0x06, 0x02, 0x14}, + {0x06, 0x8a, 0x51}, + {0x06, 0x40, 0x52}, + {0x06, 0xb6, 0x53}, + {0x06, 0x3d, 0x54}, {} }; /* * Data to initialize the camera using the internal CCD */ -static const __u16 spca505_open_data_ccd[][3] = { - /* line bmRequest,value,index */ +static const u8 spca505_open_data_ccd[][3] = { + /* bmRequest,value,index */ /* Internal CCD data set */ - /* 1891 */ {0x3, 0x04, 0x01}, + {0x03, 0x04, 0x01}, /* This could be a reset */ - /* 1894 */ {0x3, 0x00, 0x01}, + {0x03, 0x00, 0x01}, /* Setup compression and image registers. 0x6 and 0x7 seem to be related to H&V hold, and are resolution mode specific */ - /* 1897 */ {0x4, 0x10, 0x01}, + {0x04, 0x10, 0x01}, /* DIFF(0x50), was (0x10) */ - /* 1900 */ {0x4, 0x00, 0x04}, - /* 1903 */ {0x4, 0x00, 0x05}, - /* 1906 */ {0x4, 0x20, 0x06}, - /* 1909 */ {0x4, 0x20, 0x07}, + {0x04, 0x00, 0x04}, + {0x04, 0x00, 0x05}, + {0x04, 0x20, 0x06}, + {0x04, 0x20, 0x07}, - /* 1912 */ {0x8, 0x0a, 0x00}, + {0x08, 0x0a, 0x00}, /* DIFF (0x4a), was (0xa) */ - /* 1915 */ {0x5, 0x00, 0x10}, - /* 1918 */ {0x5, 0x00, 0x11}, - /* 1921 */ {0x5, 0x00, 0x00}, + {0x05, 0x00, 0x10}, + {0x05, 0x00, 0x11}, + {0x05, 0x00, 0x00}, /* DIFF not written */ - /* 1924 */ {0x5, 0x00, 0x01}, + {0x05, 0x00, 0x01}, /* DIFF not written */ - /* 1927 */ {0x5, 0x00, 0x02}, + {0x05, 0x00, 0x02}, /* DIFF not written */ - /* 1930 */ {0x5, 0x00, 0x03}, + {0x05, 0x00, 0x03}, /* DIFF not written */ - /* 1933 */ {0x5, 0x00, 0x04}, + {0x05, 0x00, 0x04}, /* DIFF not written */ - /* 1936 */ {0x5, 0x80, 0x05}, + {0x05, 0x80, 0x05}, /* DIFF not written */ - /* 1939 */ {0x5, 0xe0, 0x06}, + {0x05, 0xe0, 0x06}, /* DIFF not written */ - /* 1942 */ {0x5, 0x20, 0x07}, + {0x05, 0x20, 0x07}, /* DIFF not written */ - /* 1945 */ {0x5, 0xa0, 0x08}, + {0x05, 0xa0, 0x08}, /* DIFF not written */ - /* 1948 */ {0x5, 0x0, 0x12}, + {0x05, 0x0, 0x12}, /* DIFF not written */ - /* 1951 */ {0x5, 0x02, 0x0f}, + {0x05, 0x02, 0x0f}, /* DIFF not written */ - /* 1954 */ {0x5, 0x10, 0x46}, + {0x05, 0x10, 0x46}, /* DIFF not written */ - /* 1957 */ {0x5, 0x8, 0x4a}, + {0x05, 0x8, 0x4a}, /* DIFF not written */ - /* 1960 */ {0x3, 0x08, 0x03}, + {0x03, 0x08, 0x03}, /* DIFF (0x3,0x28,0x3) */ - /* 1963 */ {0x3, 0x08, 0x01}, - /* 1966 */ {0x3, 0x0c, 0x03}, + {0x03, 0x08, 0x01}, + {0x03, 0x0c, 0x03}, /* DIFF not written */ - /* 1969 */ {0x3, 0x21, 0x00}, + {0x03, 0x21, 0x00}, /* DIFF (0x39) */ /* Extra block copied from init to hopefully ensure CCD is in a sane state */ - /* 1837 */ {0x6, 0x10, 0x08}, - /* 1840 */ {0x6, 0x00, 0x09}, - /* 1843 */ {0x6, 0x00, 0x0a}, - /* 1846 */ {0x6, 0x00, 0x0b}, - /* 1849 */ {0x6, 0x10, 0x0c}, - /* 1852 */ {0x6, 0x00, 0x0d}, - /* 1855 */ {0x6, 0x00, 0x0e}, - /* 1858 */ {0x6, 0x00, 0x0f}, - /* 1861 */ {0x6, 0x10, 0x10}, - /* 1864 */ {0x6, 0x02, 0x11}, - /* 1867 */ {0x6, 0x00, 0x12}, - /* 1870 */ {0x6, 0x04, 0x13}, - /* 1873 */ {0x6, 0x02, 0x14}, - /* 1876 */ {0x6, 0x8a, 0x51}, - /* 1879 */ {0x6, 0x40, 0x52}, - /* 1882 */ {0x6, 0xb6, 0x53}, - /* 1885 */ {0x6, 0x3d, 0x54}, + {0x06, 0x10, 0x08}, + {0x06, 0x00, 0x09}, + {0x06, 0x00, 0x0a}, + {0x06, 0x00, 0x0b}, + {0x06, 0x10, 0x0c}, + {0x06, 0x00, 0x0d}, + {0x06, 0x00, 0x0e}, + {0x06, 0x00, 0x0f}, + {0x06, 0x10, 0x10}, + {0x06, 0x02, 0x11}, + {0x06, 0x00, 0x12}, + {0x06, 0x04, 0x13}, + {0x06, 0x02, 0x14}, + {0x06, 0x8a, 0x51}, + {0x06, 0x40, 0x52}, + {0x06, 0xb6, 0x53}, + {0x06, 0x3d, 0x54}, /* End of extra block */ - /* 1972 */ {0x6, 0x3f, 0x1}, + {0x06, 0x3f, 0x1}, /* Block skipped */ - /* 1975 */ {0x6, 0x10, 0x02}, - /* 1978 */ {0x6, 0x64, 0x07}, - /* 1981 */ {0x6, 0x10, 0x08}, - /* 1984 */ {0x6, 0x00, 0x09}, - /* 1987 */ {0x6, 0x00, 0x0a}, - /* 1990 */ {0x6, 0x00, 0x0b}, - /* 1993 */ {0x6, 0x10, 0x0c}, - /* 1996 */ {0x6, 0x00, 0x0d}, - /* 1999 */ {0x6, 0x00, 0x0e}, - /* 2002 */ {0x6, 0x00, 0x0f}, - /* 2005 */ {0x6, 0x10, 0x10}, - /* 2008 */ {0x6, 0x02, 0x11}, - /* 2011 */ {0x6, 0x00, 0x12}, - /* 2014 */ {0x6, 0x04, 0x13}, - /* 2017 */ {0x6, 0x02, 0x14}, - /* 2020 */ {0x6, 0x8a, 0x51}, - /* 2023 */ {0x6, 0x40, 0x52}, - /* 2026 */ {0x6, 0xb6, 0x53}, - /* 2029 */ {0x6, 0x3d, 0x54}, - /* 2032 */ {0x6, 0x60, 0x57}, - /* 2035 */ {0x6, 0x20, 0x58}, - /* 2038 */ {0x6, 0x15, 0x59}, - /* 2041 */ {0x6, 0x05, 0x5a}, - - /* 2044 */ {0x5, 0x01, 0xc0}, - /* 2047 */ {0x5, 0x10, 0xcb}, - /* 2050 */ {0x5, 0x80, 0xc1}, + {0x06, 0x10, 0x02}, + {0x06, 0x64, 0x07}, + {0x06, 0x10, 0x08}, + {0x06, 0x00, 0x09}, + {0x06, 0x00, 0x0a}, + {0x06, 0x00, 0x0b}, + {0x06, 0x10, 0x0c}, + {0x06, 0x00, 0x0d}, + {0x06, 0x00, 0x0e}, + {0x06, 0x00, 0x0f}, + {0x06, 0x10, 0x10}, + {0x06, 0x02, 0x11}, + {0x06, 0x00, 0x12}, + {0x06, 0x04, 0x13}, + {0x06, 0x02, 0x14}, + {0x06, 0x8a, 0x51}, + {0x06, 0x40, 0x52}, + {0x06, 0xb6, 0x53}, + {0x06, 0x3d, 0x54}, + {0x06, 0x60, 0x57}, + {0x06, 0x20, 0x58}, + {0x06, 0x15, 0x59}, + {0x06, 0x05, 0x5a}, + + {0x05, 0x01, 0xc0}, + {0x05, 0x10, 0xcb}, + {0x05, 0x80, 0xc1}, /* */ - /* 2053 */ {0x5, 0x0, 0xc2}, + {0x05, 0x0, 0xc2}, /* 4 was 0 */ - /* 2056 */ {0x5, 0x00, 0xca}, - /* 2059 */ {0x5, 0x80, 0xc1}, + {0x05, 0x00, 0xca}, + {0x05, 0x80, 0xc1}, /* */ - /* 2062 */ {0x5, 0x04, 0xc2}, - /* 2065 */ {0x5, 0x00, 0xca}, - /* 2068 */ {0x5, 0x0, 0xc1}, + {0x05, 0x04, 0xc2}, + {0x05, 0x00, 0xca}, + {0x05, 0x0, 0xc1}, /* */ - /* 2071 */ {0x5, 0x00, 0xc2}, - /* 2074 */ {0x5, 0x00, 0xca}, - /* 2077 */ {0x5, 0x40, 0xc1}, + {0x05, 0x00, 0xc2}, + {0x05, 0x00, 0xca}, + {0x05, 0x40, 0xc1}, /* */ - /* 2080 */ {0x5, 0x17, 0xc2}, - /* 2083 */ {0x5, 0x00, 0xca}, - /* 2086 */ {0x5, 0x80, 0xc1}, + {0x05, 0x17, 0xc2}, + {0x05, 0x00, 0xca}, + {0x05, 0x80, 0xc1}, /* */ - /* 2089 */ {0x5, 0x06, 0xc2}, - /* 2092 */ {0x5, 0x00, 0xca}, - /* 2095 */ {0x5, 0x80, 0xc1}, + {0x05, 0x06, 0xc2}, + {0x05, 0x00, 0xca}, + {0x05, 0x80, 0xc1}, /* */ - /* 2098 */ {0x5, 0x04, 0xc2}, - /* 2101 */ {0x5, 0x00, 0xca}, + {0x05, 0x04, 0xc2}, + {0x05, 0x00, 0xca}, - /* 2104 */ {0x3, 0x4c, 0x3}, - /* 2107 */ {0x3, 0x18, 0x1}, + {0x03, 0x4c, 0x3}, + {0x03, 0x18, 0x1}, - /* 2110 */ {0x6, 0x70, 0x51}, - /* 2113 */ {0x6, 0xbe, 0x53}, - /* 2116 */ {0x6, 0x71, 0x57}, - /* 2119 */ {0x6, 0x20, 0x58}, - /* 2122 */ {0x6, 0x05, 0x59}, - /* 2125 */ {0x6, 0x15, 0x5a}, + {0x06, 0x70, 0x51}, + {0x06, 0xbe, 0x53}, + {0x06, 0x71, 0x57}, + {0x06, 0x20, 0x58}, + {0x06, 0x05, 0x59}, + {0x06, 0x15, 0x5a}, - /* 2128 */ {0x4, 0x00, 0x08}, + {0x04, 0x00, 0x08}, /* Compress = OFF (0x1 to turn on) */ - /* 2131 */ {0x4, 0x12, 0x09}, - /* 2134 */ {0x4, 0x21, 0x0a}, - /* 2137 */ {0x4, 0x10, 0x0b}, - /* 2140 */ {0x4, 0x21, 0x0c}, - /* 2143 */ {0x4, 0x05, 0x00}, + {0x04, 0x12, 0x09}, + {0x04, 0x21, 0x0a}, + {0x04, 0x10, 0x0b}, + {0x04, 0x21, 0x0c}, + {0x04, 0x05, 0x00}, /* was 5 (Image Type ? ) */ - /* 2146 */ {0x4, 0x00, 0x01}, - - /* 2149 */ {0x6, 0x3f, 0x01}, - - /* 2152 */ {0x4, 0x00, 0x04}, - /* 2155 */ {0x4, 0x00, 0x05}, - /* 2158 */ {0x4, 0x40, 0x06}, - /* 2161 */ {0x4, 0x40, 0x07}, - - /* 2164 */ {0x6, 0x1c, 0x17}, - /* 2167 */ {0x6, 0xe2, 0x19}, - /* 2170 */ {0x6, 0x1c, 0x1b}, - /* 2173 */ {0x6, 0xe2, 0x1d}, - /* 2176 */ {0x6, 0xaa, 0x1f}, - /* 2179 */ {0x6, 0x70, 0x20}, - - /* 2182 */ {0x5, 0x01, 0x10}, - /* 2185 */ {0x5, 0x00, 0x11}, - /* 2188 */ {0x5, 0x01, 0x00}, - /* 2191 */ {0x5, 0x05, 0x01}, - /* 2194 */ {0x5, 0x00, 0xc1}, + {0x04, 0x00, 0x01}, + + {0x06, 0x3f, 0x01}, + + {0x04, 0x00, 0x04}, + {0x04, 0x00, 0x05}, + {0x04, 0x40, 0x06}, + {0x04, 0x40, 0x07}, + + {0x06, 0x1c, 0x17}, + {0x06, 0xe2, 0x19}, + {0x06, 0x1c, 0x1b}, + {0x06, 0xe2, 0x1d}, + {0x06, 0xaa, 0x1f}, + {0x06, 0x70, 0x20}, + + {0x05, 0x01, 0x10}, + {0x05, 0x00, 0x11}, + {0x05, 0x01, 0x00}, + {0x05, 0x05, 0x01}, + {0x05, 0x00, 0xc1}, /* */ - /* 2197 */ {0x5, 0x00, 0xc2}, - /* 2200 */ {0x5, 0x00, 0xca}, + {0x05, 0x00, 0xc2}, + {0x05, 0x00, 0xca}, - /* 2203 */ {0x6, 0x70, 0x51}, - /* 2206 */ {0x6, 0xbe, 0x53}, + {0x06, 0x70, 0x51}, + {0x06, 0xbe, 0x53}, {} }; /* - Made by Tomasz Zablocki (skalamandra@poczta.onet.pl) + * Made by Tomasz Zablocki (skalamandra@poczta.onet.pl) * SPCA505b chip based cameras initialization data - * */ /* jfm */ #define initial_brightness 0x7f /* 0x0(white)-0xff(black) */ @@ -332,7 +329,7 @@ static const __u16 spca505_open_data_ccd[][3] = { /* * Data to initialize a SPCA505. Common to the CCD and external modes */ -static const __u16 spca505b_init_data[][3] = { +static const u8 spca505b_init_data[][3] = { /* start */ {0x02, 0x00, 0x00}, /* init */ {0x02, 0x00, 0x01}, @@ -396,7 +393,7 @@ static const __u16 spca505b_init_data[][3] = { /* * Data to initialize the camera using the internal CCD */ -static const __u16 spca505b_open_data_ccd[][3] = { +static const u8 spca505b_open_data_ccd[][3] = { /* {0x02,0x00,0x00}, */ {0x03, 0x04, 0x01}, /* rst */ @@ -425,8 +422,8 @@ static const __u16 spca505b_open_data_ccd[][3] = { {0x05, 0x00, 0x11}, {0x05, 0x00, 0x12}, {0x05, 0x6f, 0x00}, - {0x05, initial_brightness >> 6, 0x00}, - {0x05, initial_brightness << 2, 0x01}, + {0x05, (u8) (initial_brightness >> 6), 0x00}, + {0x05, (u8) (initial_brightness << 2), 0x01}, {0x05, 0x00, 0x02}, {0x05, 0x01, 0x03}, {0x05, 0x00, 0x04}, @@ -436,7 +433,7 @@ static const __u16 spca505b_open_data_ccd[][3] = { {0x05, 0xa0, 0x08}, {0x05, 0x00, 0x12}, {0x05, 0x02, 0x0f}, - {0x05, 128, 0x14}, /* max exposure off (0=on) */ + {0x05, 0x80, 0x14}, /* max exposure off (0=on) */ {0x05, 0x01, 0xb0}, {0x05, 0x01, 0xbf}, {0x03, 0x02, 0x06}, @@ -559,27 +556,27 @@ static const __u16 spca505b_open_data_ccd[][3] = { {0x06, 0x5f, 0x1f}, {0x06, 0x32, 0x20}, - {0x05, initial_brightness >> 6, 0x00}, - {0x05, initial_brightness << 2, 0x01}, + {0x05, (u8) (initial_brightness >> 6), 0x00}, + {0x05, (u8) (initial_brightness << 2), 0x01}, {0x05, 0x06, 0xc1}, {0x05, 0x58, 0xc2}, - {0x05, 0x0, 0xca}, - {0x05, 0x0, 0x11}, + {0x05, 0x00, 0xca}, + {0x05, 0x00, 0x11}, {} }; static int reg_write(struct usb_device *dev, - __u16 reg, __u16 index, __u16 value) + u16 req, u16 index, u16 value) { int ret; ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - reg, + req, USB_TYPE_VENDOR | USB_RECIP_DEVICE, value, index, NULL, 0, 500); - PDEBUG(D_PACK, "reg write: 0x%02x,0x%02x:0x%02x, 0x%x", - reg, index, value, ret); + PDEBUG(D_USBO, "reg write: 0x%02x,0x%02x:0x%02x, %d", + req, index, value, ret); if (ret < 0) PDEBUG(D_ERR, "reg write: error %d", ret); return ret; @@ -587,42 +584,34 @@ static int reg_write(struct usb_device *dev, /* returns: negative is error, pos or zero is data */ static int reg_read(struct gspca_dev *gspca_dev, - __u16 reg, /* bRequest */ - __u16 index, /* wIndex */ - __u16 length) /* wLength (1 or 2 only) */ + u16 req, /* bRequest */ + u16 index) /* wIndex */ { int ret; - gspca_dev->usb_buf[1] = 0; ret = usb_control_msg(gspca_dev->dev, usb_rcvctrlpipe(gspca_dev->dev, 0), - reg, + req, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - (__u16) 0, /* value */ - (__u16) index, - gspca_dev->usb_buf, length, + 0, /* value */ + index, + gspca_dev->usb_buf, 2, 500); /* timeout */ - if (ret < 0) { - PDEBUG(D_ERR, "reg_read err %d", ret); - return -1; - } + if (ret < 0) + return ret; return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0]; } static int write_vector(struct gspca_dev *gspca_dev, - const __u16 data[][3]) + const u8 data[][3]) { struct usb_device *dev = gspca_dev->dev; int ret, i = 0; - while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) { + while (data[i][0] != 0) { ret = reg_write(dev, data[i][0], data[i][2], data[i][1]); - if (ret < 0) { - PDEBUG(D_ERR, - "Register write failed for 0x%x,0x%x,0x%x", - data[i][0], data[i][1], data[i][2]); + if (ret < 0) return ret; - } i++; } return 0; @@ -639,10 +628,10 @@ static int sd_config(struct gspca_dev *gspca_dev, cam->cam_mode = vga_mode; sd->subtype = id->driver_info; if (sd->subtype != IntelPCCameraPro) - cam->nmodes = sizeof vga_mode / sizeof vga_mode[0]; + cam->nmodes = ARRAY_SIZE(vga_mode); else /* no 640x480 for IntelPCCameraPro */ - cam->nmodes = sizeof vga_mode / sizeof vga_mode[0] - 1; - sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; + cam->nmodes = ARRAY_SIZE(vga_mode) - 1; + sd->brightness = BRIGHTNESS_DEF; if (sd->subtype == Nxultra) { if (write_vector(gspca_dev, spca505b_init_data)) @@ -660,30 +649,28 @@ static int sd_init(struct gspca_dev *gspca_dev) struct sd *sd = (struct sd *) gspca_dev; int ret; - PDEBUG(D_STREAM, "Initializing SPCA505"); if (sd->subtype == Nxultra) write_vector(gspca_dev, spca505b_open_data_ccd); else write_vector(gspca_dev, spca505_open_data_ccd); - ret = reg_read(gspca_dev, 6, 0x16, 2); + ret = reg_read(gspca_dev, 0x06, 0x16); if (ret < 0) { - PDEBUG(D_ERR|D_STREAM, - "register read failed for after vector read err = %d", + PDEBUG(D_ERR|D_CONF, + "register read failed err: %d", ret); - return -EIO; + return ret; } - PDEBUG(D_STREAM, - "After vector read returns : 0x%x should be 0x0101", - ret & 0xffff); - - ret = reg_write(gspca_dev->dev, 6, 0x16, 0x0a); - if (ret < 0) { - PDEBUG(D_ERR, "register write failed for (6,0xa,0x16) err=%d", - ret); - return -EIO; + if (ret != 0x0101) { + PDEBUG(D_ERR|D_CONF, + "After vector read returns 0x%04x should be 0x0101", + ret); } - reg_write(gspca_dev->dev, 5, 0xc2, 18); + + ret = reg_write(gspca_dev->dev, 0x06, 0x16, 0x0a); + if (ret < 0) + return ret; + reg_write(gspca_dev->dev, 0x05, 0xc2, 18); return 0; } @@ -749,15 +736,15 @@ static void sd_stop0(struct gspca_dev *gspca_dev) /* This maybe reset or power control */ reg_write(gspca_dev->dev, 0x03, 0x03, 0x20); - reg_write(gspca_dev->dev, 0x03, 0x01, 0x0); - reg_write(gspca_dev->dev, 0x03, 0x00, 0x1); - reg_write(gspca_dev->dev, 0x05, 0x10, 0x1); - reg_write(gspca_dev->dev, 0x05, 0x11, 0xf); + reg_write(gspca_dev->dev, 0x03, 0x01, 0x00); + reg_write(gspca_dev->dev, 0x03, 0x00, 0x01); + reg_write(gspca_dev->dev, 0x05, 0x10, 0x01); + reg_write(gspca_dev->dev, 0x05, 0x11, 0x0f); } static void sd_pkt_scan(struct gspca_dev *gspca_dev, struct gspca_frame *frame, /* target */ - __u8 *data, /* isoc packet */ + u8 *data, /* isoc packet */ int len) /* iso packet length */ { switch (data[0]) { @@ -770,7 +757,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, data, len); break; case 0xff: /* drop */ -/* gspca_dev->last_packet_type = DISCARD_PACKET; */ break; default: data += 1; @@ -784,10 +770,10 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, static void setbrightness(struct gspca_dev *gspca_dev) { struct sd *sd = (struct sd *) gspca_dev; + u8 brightness = sd->brightness; - __u8 brightness = sd->brightness; - reg_write(gspca_dev->dev, 5, 0x00, (255 - brightness) >> 6); - reg_write(gspca_dev->dev, 5, 0x01, (255 - brightness) << 2); + reg_write(gspca_dev->dev, 0x05, 0x00, (255 - brightness) >> 6); + reg_write(gspca_dev->dev, 0x05, 0x01, (255 - brightness) << 2); } @@ -854,6 +840,7 @@ static struct usb_driver sd_driver = { static int __init sd_mod_init(void) { int ret; + ret = usb_register(&sd_driver); if (ret < 0) return ret; -- 2.20.1