aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video
diff options
context:
space:
mode:
authorJean-Francois Moine <moinejf@free.fr>2009-02-02 04:33:31 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-03-30 11:42:37 -0400
commit49796e4059b40032f3dba0fa5ad559ef4b977e89 (patch)
tree85bfa9951c766aea07c260f0aa809b4febab2f2d /drivers/media/video
parent8d538699e761be7b1ad431273919034806132806 (diff)
V4L/DVB (10432): gspca - vc032x: Cleanup source, optimize and check i2c_write.
Signed-off-by: Jean-Francois Moine <moinejf@free.fr> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video')
-rw-r--r--drivers/media/video/gspca/vc032x.c93
1 files changed, 37 insertions, 56 deletions
diff --git a/drivers/media/video/gspca/vc032x.c b/drivers/media/video/gspca/vc032x.c
index be1507ac0262..f8d535ce9081 100644
--- a/drivers/media/video/gspca/vc032x.c
+++ b/drivers/media/video/gspca/vc032x.c
@@ -1927,44 +1927,40 @@ static void reg_w(struct usb_device *dev,
1927 500); 1927 500);
1928} 1928}
1929 1929
1930static void read_sensor_register(struct gspca_dev *gspca_dev, 1930static u16 read_sensor_register(struct gspca_dev *gspca_dev,
1931 __u16 address, __u16 *value) 1931 u16 address)
1932{ 1932{
1933 struct usb_device *dev = gspca_dev->dev; 1933 struct usb_device *dev = gspca_dev->dev;
1934 __u8 ldata, mdata, hdata; 1934 __u8 ldata, mdata, hdata;
1935 int retry = 50; 1935 int retry = 50;
1936 1936
1937 *value = 0;
1938
1939 reg_r(gspca_dev, 0xa1, 0xb33f, 1); 1937 reg_r(gspca_dev, 0xa1, 0xb33f, 1);
1940 /*PDEBUG(D_PROBE, " I2c Bus Busy Wait 0x%02X ", tmpvalue); */
1941 if (!(gspca_dev->usb_buf[0] & 0x02)) { 1938 if (!(gspca_dev->usb_buf[0] & 0x02)) {
1942 PDEBUG(D_ERR, "I2c Bus Busy Wait %d", 1939 PDEBUG(D_ERR, "I2c Bus Busy Wait %02x",
1943 gspca_dev->usb_buf[0] & 0x02); 1940 gspca_dev->usb_buf[0]);
1944 return; 1941 return 0;
1945 } 1942 }
1946 reg_w(dev, 0xa0, address, 0xb33a); 1943 reg_w(dev, 0xa0, address, 0xb33a);
1947 reg_w(dev, 0xa0, 0x02, 0xb339); 1944 reg_w(dev, 0xa0, 0x02, 0xb339);
1948 1945
1949 reg_r(gspca_dev, 0xa1, 0xb33b, 1); 1946 do {
1950 while (retry-- && gspca_dev->usb_buf[0]) { 1947 msleep(8);
1951 reg_r(gspca_dev, 0xa1, 0xb33b, 1); 1948 reg_r(gspca_dev, 0xa1, 0xb33b, 1);
1952/* PDEBUG(D_PROBE, "Read again 0xb33b %d", tmpvalue); */ 1949 } while (retry-- && gspca_dev->usb_buf[0]);
1953 msleep(1); 1950
1954 }
1955 reg_r(gspca_dev, 0xa1, 0xb33e, 1); 1951 reg_r(gspca_dev, 0xa1, 0xb33e, 1);
1956 ldata = gspca_dev->usb_buf[0]; 1952 ldata = gspca_dev->usb_buf[0];
1957 reg_r(gspca_dev, 0xa1, 0xb33d, 1); 1953 reg_r(gspca_dev, 0xa1, 0xb33d, 1);
1958 mdata = gspca_dev->usb_buf[0]; 1954 mdata = gspca_dev->usb_buf[0];
1959 reg_r(gspca_dev, 0xa1, 0xb33c, 1); 1955 reg_r(gspca_dev, 0xa1, 0xb33c, 1);
1960 hdata = gspca_dev->usb_buf[0]; 1956 hdata = gspca_dev->usb_buf[0];
1961 PDEBUG(D_PROBE, "Read Sensor %02x%02x %02x", 1957 if (hdata != 0 && mdata != 0 && ldata != 0)
1962 hdata, mdata, ldata); 1958 PDEBUG(D_PROBE, "Read Sensor %02x%02x %02x",
1959 hdata, mdata, ldata);
1963 reg_r(gspca_dev, 0xa1, 0xb334, 1); 1960 reg_r(gspca_dev, 0xa1, 0xb334, 1);
1964 if (gspca_dev->usb_buf[0] == 0x02) 1961 if (gspca_dev->usb_buf[0] == 0x02)
1965 *value = (hdata << 8) + mdata; 1962 return (hdata << 8) + mdata;
1966 else 1963 return hdata;
1967 *value = hdata;
1968} 1964}
1969 1965
1970static int vc032x_probe_sensor(struct gspca_dev *gspca_dev) 1966static int vc032x_probe_sensor(struct gspca_dev *gspca_dev)
@@ -1985,7 +1981,7 @@ static int vc032x_probe_sensor(struct gspca_dev *gspca_dev)
1985 reg_w(dev, 0xa0, 0x0c, 0xb309); 1981 reg_w(dev, 0xa0, 0x0c, 0xb309);
1986 reg_w(dev, 0xa0, ptsensor_info->I2cAdd, 0xb335); 1982 reg_w(dev, 0xa0, ptsensor_info->I2cAdd, 0xb335);
1987 reg_w(dev, 0xa0, ptsensor_info->op, 0xb301); 1983 reg_w(dev, 0xa0, ptsensor_info->op, 0xb301);
1988 read_sensor_register(gspca_dev, ptsensor_info->IdAdd, &value); 1984 value = read_sensor_register(gspca_dev, ptsensor_info->IdAdd);
1989 if (value == ptsensor_info->VpId) 1985 if (value == ptsensor_info->VpId)
1990 return ptsensor_info->sensorId; 1986 return ptsensor_info->sensorId;
1991 1987
@@ -1997,13 +1993,16 @@ static int vc032x_probe_sensor(struct gspca_dev *gspca_dev)
1997 return -1; 1993 return -1;
1998} 1994}
1999 1995
2000static __u8 i2c_write(struct gspca_dev *gspca_dev, 1996static void i2c_write(struct gspca_dev *gspca_dev,
2001 __u8 reg, const __u8 *val, __u8 size) 1997 __u8 reg, const __u8 *val, __u8 size)
2002{ 1998{
2003 struct usb_device *dev = gspca_dev->dev; 1999 struct usb_device *dev = gspca_dev->dev;
2000 int retry;
2004 2001
2002#ifdef GSPCA_DEBUG
2005 if (size > 3 || size < 1) 2003 if (size > 3 || size < 1)
2006 return -EINVAL; 2004 return;
2005#endif
2007 reg_r(gspca_dev, 0xa1, 0xb33f, 1); 2006 reg_r(gspca_dev, 0xa1, 0xb33f, 1);
2008 reg_w(dev, 0xa0, size, 0xb334); 2007 reg_w(dev, 0xa0, size, 0xb334);
2009 reg_w(dev, 0xa0, reg, 0xb33a); 2008 reg_w(dev, 0xa0, reg, 0xb33a);
@@ -2015,18 +2014,23 @@ static __u8 i2c_write(struct gspca_dev *gspca_dev,
2015 reg_w(dev, 0xa0, val[0], 0xb336); 2014 reg_w(dev, 0xa0, val[0], 0xb336);
2016 reg_w(dev, 0xa0, val[1], 0xb337); 2015 reg_w(dev, 0xa0, val[1], 0xb337);
2017 break; 2016 break;
2018 case 3: 2017 default:
2018/* case 3: */
2019 reg_w(dev, 0xa0, val[0], 0xb336); 2019 reg_w(dev, 0xa0, val[0], 0xb336);
2020 reg_w(dev, 0xa0, val[1], 0xb337); 2020 reg_w(dev, 0xa0, val[1], 0xb337);
2021 reg_w(dev, 0xa0, val[2], 0xb338); 2021 reg_w(dev, 0xa0, val[2], 0xb338);
2022 break; 2022 break;
2023 default:
2024 reg_w(dev, 0xa0, 0x01, 0xb334);
2025 return -EINVAL;
2026 } 2023 }
2027 reg_w(dev, 0xa0, 0x01, 0xb339); 2024 reg_w(dev, 0xa0, 0x01, 0xb339);
2028 reg_r(gspca_dev, 0xa1, 0xb33b, 1); 2025 retry = 4;
2029 return gspca_dev->usb_buf[0] == 0; 2026 do {
2027 reg_r(gspca_dev, 0xa1, 0xb33b, 1);
2028 if (gspca_dev->usb_buf[0] == 0)
2029 break;
2030 msleep(20);
2031 } while (--retry > 0);
2032 if (retry <= 0)
2033 PDEBUG(D_ERR, "i2c_write failed");
2030} 2034}
2031 2035
2032static void put_tab_to_reg(struct gspca_dev *gspca_dev, 2036static void put_tab_to_reg(struct gspca_dev *gspca_dev,
@@ -2051,7 +2055,7 @@ static void usb_exchange(struct gspca_dev *gspca_dev,
2051 return; 2055 return;
2052 case 0xcc: /* normal write */ 2056 case 0xcc: /* normal write */
2053 reg_w(dev, 0xa0, data[i][2], 2057 reg_w(dev, 0xa0, data[i][2],
2054 ((data[i][0])<<8) | data[i][1]); 2058 (data[i][0]) << 8 | data[i][1]);
2055 break; 2059 break;
2056 case 0xaa: /* i2c op */ 2060 case 0xaa: /* i2c op */
2057 i2c_write(gspca_dev, data[i][1], &data[i][2], 1); 2061 i2c_write(gspca_dev, data[i][1], &data[i][2], 1);
@@ -2068,11 +2072,6 @@ static void usb_exchange(struct gspca_dev *gspca_dev,
2068 /*not reached*/ 2072 /*not reached*/
2069} 2073}
2070 2074
2071/*
2072 "GammaT"=hex:04,17,31,4f,6a,83,99,ad,bf,ce,da,e5,ee,f5,fb,ff,ff
2073 "MatrixT"=hex:60,f9,e5,e7,50,05,f3,e6,66
2074 */
2075
2076static void vc0321_reset(struct gspca_dev *gspca_dev) 2075static void vc0321_reset(struct gspca_dev *gspca_dev)
2077{ 2076{
2078 reg_w(gspca_dev->dev, 0xa0, 0x00, 0xb04d); 2077 reg_w(gspca_dev->dev, 0xa0, 0x00, 0xb04d);
@@ -2176,7 +2175,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
2176 return 0; 2175 return 0;
2177} 2176}
2178 2177
2179/* this function is called at probe and time */ 2178/* this function is called at probe and resume time */
2180static int sd_init(struct gspca_dev *gspca_dev) 2179static int sd_init(struct gspca_dev *gspca_dev)
2181{ 2180{
2182 return 0; 2181 return 0;
@@ -2332,27 +2331,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
2332 put_tab_to_reg(gspca_dev, GammaT, 17, 0xb85b); 2331 put_tab_to_reg(gspca_dev, GammaT, 17, 0xb85b);
2333 put_tab_to_reg(gspca_dev, GammaT, 17, 0xb86c); 2332 put_tab_to_reg(gspca_dev, GammaT, 17, 0xb86c);
2334 put_tab_to_reg(gspca_dev, MatrixT, 9, 0xb82c); 2333 put_tab_to_reg(gspca_dev, MatrixT, 9, 0xb82c);
2335 /* Seem SHARPNESS */ 2334
2336 /*
2337 reg_w(gspca_dev->dev, 0xa0, 0x80, 0xb80a);
2338 reg_w(gspca_dev->dev, 0xa0, 0xff, 0xb80b);
2339 reg_w(gspca_dev->dev, 0xa0, 0xff, 0xb80e);
2340 */
2341 /* all 0x40 ??? do nothing
2342 reg_w(gspca_dev->dev, 0xa0, 0x40, 0xb822);
2343 reg_w(gspca_dev->dev, 0xa0, 0x40, 0xb823);
2344 reg_w(gspca_dev->dev, 0xa0, 0x40, 0xb824);
2345 */
2346 /* Only works for HV7131R ??
2347 reg_r (gspca_dev, 0xa1, 0xb881, 1);
2348 reg_w(gspca_dev->dev, 0xa0, 0xfe01, 0xb881);
2349 reg_w(gspca_dev->dev, 0xa0, 0x79, 0xb801);
2350 */
2351 /* only hv7131r et ov7660
2352 reg_w(gspca_dev->dev, 0xa0, 0x20, 0xb827);
2353 reg_w(gspca_dev->dev, 0xa0, 0xff, 0xb826); * ISP_GAIN 80
2354 reg_w(gspca_dev->dev, 0xa0, 0x23, 0xb800); * ISP CTRL_BAS
2355 */
2356 /* set the led on 0x0892 0x0896 */ 2335 /* set the led on 0x0892 0x0896 */
2357 if (sd->sensor != SENSOR_PO1200) { 2336 if (sd->sensor != SENSOR_PO1200) {
2358 reg_w(gspca_dev->dev, 0x89, 0xffff, 0xfdff); 2337 reg_w(gspca_dev->dev, 0x89, 0xffff, 0xfdff);
@@ -2502,7 +2481,8 @@ static int sd_querymenu(struct gspca_dev *gspca_dev,
2502 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */ 2481 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
2503 strcpy((char *) menu->name, "50 Hz"); 2482 strcpy((char *) menu->name, "50 Hz");
2504 return 0; 2483 return 0;
2505 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */ 2484 default:
2485/* case 2: * V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
2506 strcpy((char *) menu->name, "60 Hz"); 2486 strcpy((char *) menu->name, "60 Hz");
2507 return 0; 2487 return 0;
2508 } 2488 }
@@ -2565,6 +2545,7 @@ static struct usb_driver sd_driver = {
2565static int __init sd_mod_init(void) 2545static int __init sd_mod_init(void)
2566{ 2546{
2567 int ret; 2547 int ret;
2548
2568 ret = usb_register(&sd_driver); 2549 ret = usb_register(&sd_driver);
2569 if (ret < 0) 2550 if (ret < 0)
2570 return ret; 2551 return ret;