From a5ae2062252e697d38e53dbbeb91460252208914 Mon Sep 17 00:00:00 2001 From: Jean-Francois Moine Date: Fri, 4 Jul 2008 11:16:16 -0300 Subject: V4L/DVB (8195): gspca: Input buffer overwritten in spca561 + cleanup code. spca561: Input buffer may be changed on reg write. (all sd): Cleanup code, 'const' added. Signed-off-by: Jean-Francois Moine Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/gspca/spca500.c | 301 ++++++++++++++++++------------------ 1 file changed, 153 insertions(+), 148 deletions(-) (limited to 'drivers/media/video/gspca/spca500.c') diff --git a/drivers/media/video/gspca/spca500.c b/drivers/media/video/gspca/spca500.c index 1db5b33ad85e..3a42506830f8 100644 --- a/drivers/media/video/gspca/spca500.c +++ b/drivers/media/video/gspca/spca500.c @@ -24,8 +24,8 @@ #include "gspca.h" #include "jpeg.h" -#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 0) -static const char version[] = "2.1.0"; +#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 4) +static const char version[] = "2.1.4"; MODULE_AUTHOR("Michel Xhaard "); MODULE_DESCRIPTION("GSPCA/SPCA500 USB Camera Driver"); @@ -35,7 +35,7 @@ MODULE_LICENSE("GPL"); struct sd { struct gspca_dev gspca_dev; /* !! must be the first item */ - unsigned char packet[ISO_MAX_SIZE + 128]; + __u8 packet[ISO_MAX_SIZE + 128]; /* !! no more than 128 ff in an ISO packet */ unsigned char brightness; @@ -70,44 +70,44 @@ static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val); static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); static struct ctrl sd_ctrls[] = { -#define SD_BRIGHTNESS 0 { { .id = V4L2_CID_BRIGHTNESS, .type = V4L2_CTRL_TYPE_INTEGER, .name = "Brightness", .minimum = 0, - .maximum = 0xff, + .maximum = 255, .step = 1, - .default_value = 0x7f, +#define BRIGHTNESS_DEF 127 + .default_value = BRIGHTNESS_DEF, }, .set = sd_setbrightness, .get = sd_getbrightness, }, -#define SD_CONTRAST 1 { { .id = V4L2_CID_CONTRAST, .type = V4L2_CTRL_TYPE_INTEGER, .name = "Contrast", .minimum = 0, - .maximum = 255, + .maximum = 63, .step = 1, - .default_value = 127, +#define CONTRAST_DEF 31 + .default_value = CONTRAST_DEF, }, .set = sd_setcontrast, .get = sd_getcontrast, }, -#define SD_COLOR 2 { { .id = V4L2_CID_SATURATION, .type = V4L2_CTRL_TYPE_INTEGER, .name = "Color", .minimum = 0, - .maximum = 255, + .maximum = 63, .step = 1, - .default_value = 127, +#define COLOR_DEF 31 + .default_value = COLOR_DEF, }, .set = sd_setcolors, .get = sd_getcolors, @@ -139,7 +139,7 @@ static struct cam_mode sif_mode[] = { #define SPCA500_OFFSET_DATA 16 -static __u16 spca500_visual_defaults[][3] = { +static const __u16 spca500_visual_defaults[][3] = { {0x00, 0x0003, 0x816b}, /* SSI not active sync with vsync, * hue (H byte) = 0, * saturation/hue enable, @@ -161,10 +161,9 @@ static __u16 spca500_visual_defaults[][3] = { {0x00, 0x0001, 0x8202}, /* clock rate compensation = 1/25 sec/frame */ {0x0c, 0x0004, 0x0000}, /* set interface */ - - {0, 0, 0} + {} }; -static __u16 Clicksmart510_defaults[][3] = { +static const __u16 Clicksmart510_defaults[][3] = { {0x00, 0x00, 0x8211}, {0x00, 0x01, 0x82c0}, {0x00, 0x10, 0x82cb}, @@ -293,7 +292,7 @@ static __u16 Clicksmart510_defaults[][3] = { {} }; -static unsigned char qtable_creative_pccam[2][64] = { +static const __u8 qtable_creative_pccam[2][64] = { { /* Q-table Y-components */ 0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12, 0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11, @@ -314,7 +313,7 @@ static unsigned char qtable_creative_pccam[2][64] = { 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e} }; -static unsigned char qtable_kodak_ez200[2][64] = { +static const __u8 qtable_kodak_ez200[2][64] = { { /* Q-table Y-components */ 0x02, 0x01, 0x01, 0x02, 0x02, 0x04, 0x05, 0x06, 0x01, 0x01, 0x01, 0x02, 0x03, 0x06, 0x06, 0x06, @@ -335,7 +334,7 @@ static unsigned char qtable_kodak_ez200[2][64] = { 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a} }; -static unsigned char qtable_pocketdv[2][64] = { +static const __u8 qtable_pocketdv[2][64] = { { /* Q-table Y-components start registers 0x8800 */ 0x06, 0x04, 0x04, 0x06, 0x0a, 0x10, 0x14, 0x18, 0x05, 0x05, 0x06, 0x08, 0x0a, 0x17, 0x18, 0x16, @@ -357,7 +356,7 @@ static unsigned char qtable_pocketdv[2][64] = { 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28} }; -static void spca5xxRegRead(struct usb_device *dev, +static void reg_r(struct usb_device *dev, __u16 index, __u8 *buffer, __u16 length) { @@ -369,25 +368,24 @@ static void spca5xxRegRead(struct usb_device *dev, index, buffer, length, 500); } -static int reg_write(struct usb_device *dev, +static int reg_w(struct usb_device *dev, __u16 req, __u16 index, __u16 value) { int ret; + PDEBUG(D_USBO, "reg write: [0x%02x] = 0x%02x", index, value); ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), req, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, value, index, NULL, 0, 500); - PDEBUG(D_USBO, "reg write: [0x%02x] = 0x%02x, 0x%x", - index, value, ret); if (ret < 0) PDEBUG(D_ERR, "reg write: error %d", ret); return ret; } /* returns: negative is error, pos or zero is data */ -static int reg_read(struct usb_device *dev, +static int reg_r_12(struct usb_device *dev, __u16 req, /* bRequest */ __u16 index, /* wIndex */ __u16 length) /* wLength (1 or 2 only) */ @@ -405,7 +403,7 @@ static int reg_read(struct usb_device *dev, buf, length, 500); /* timeout */ if (ret < 0) { - PDEBUG(D_ERR, "reg_read err %d", ret); + PDEBUG(D_ERR, "reg_r_12 err %d", ret); return -1; } return (buf[1] << 8) + buf[0]; @@ -416,13 +414,13 @@ static int reg_read(struct usb_device *dev, * a reg_read call. * Returns: negative is error or timeout, zero is success. */ -static int reg_readwait(struct usb_device *dev, +static int reg_r_wait(struct usb_device *dev, __u16 reg, __u16 index, __u16 value) { int ret, cnt = 20; while (--cnt > 0) { - ret = reg_read(dev, reg, index, 1); + ret = reg_r_12(dev, reg, index, 1); if (ret == value) return 0; msleep(50); @@ -431,13 +429,13 @@ static int reg_readwait(struct usb_device *dev, } static int write_vector(struct gspca_dev *gspca_dev, - __u16 data[][3]) + const __u16 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) { - ret = reg_write(dev, data[i][0], data[i][2], data[i][1]); + ret = reg_w(dev, data[i][0], data[i][2], data[i][1]); if (ret < 0) return ret; i++; @@ -449,21 +447,21 @@ static int spca50x_setup_qtable(struct gspca_dev *gspca_dev, unsigned int request, unsigned int ybase, unsigned int cbase, - unsigned char qtable[2][64]) + const __u8 qtable[2][64]) { struct usb_device *dev = gspca_dev->dev; int i, err; /* loop over y components */ for (i = 0; i < 64; i++) { - err = reg_write(dev, request, ybase + i, qtable[0][i]); + err = reg_w(dev, request, ybase + i, qtable[0][i]); if (err < 0) return err; } /* loop over c components */ for (i = 0; i < 64; i++) { - err = reg_write(dev, request, cbase + i, qtable[1][i]); + err = reg_w(dev, request, cbase + i, qtable[1][i]); if (err < 0) return err; } @@ -474,8 +472,8 @@ static void spca500_ping310(struct gspca_dev *gspca_dev) { __u8 Data[2]; - spca5xxRegRead(gspca_dev->dev, 0x0d04, Data, 2); - PDEBUG(D_PACK, "ClickSmart310 ping 0x0d04 0x%02x 0x%02x", + reg_r(gspca_dev->dev, 0x0d04, Data, 2); + PDEBUG(D_STREAM, "ClickSmart310 ping 0x0d04 0x%02x 0x%02x", Data[0], Data[1]); } @@ -483,26 +481,26 @@ static void spca500_clksmart310_init(struct gspca_dev *gspca_dev) { __u8 Data[2]; - spca5xxRegRead(gspca_dev->dev, 0x0d05, Data, 2); - PDEBUG(D_PACK, "ClickSmart310 init 0x0d05 0x%02x 0x%02x", Data[0], - Data[1]); - reg_write(gspca_dev->dev, 0x00, 0x8167, 0x5a); + reg_r(gspca_dev->dev, 0x0d05, Data, 2); + PDEBUG(D_STREAM, "ClickSmart310 init 0x0d05 0x%02x 0x%02x", + Data[0], Data[1]); + reg_w(gspca_dev->dev, 0x00, 0x8167, 0x5a); spca500_ping310(gspca_dev); - reg_write(gspca_dev->dev, 0x00, 0x8168, 0x22); - reg_write(gspca_dev->dev, 0x00, 0x816a, 0xc0); - reg_write(gspca_dev->dev, 0x00, 0x816b, 0x0b); - reg_write(gspca_dev->dev, 0x00, 0x8169, 0x25); - reg_write(gspca_dev->dev, 0x00, 0x8157, 0x5b); - reg_write(gspca_dev->dev, 0x00, 0x8158, 0x5b); - reg_write(gspca_dev->dev, 0x00, 0x813f, 0x03); - reg_write(gspca_dev->dev, 0x00, 0x8151, 0x4a); - reg_write(gspca_dev->dev, 0x00, 0x8153, 0x78); - reg_write(gspca_dev->dev, 0x00, 0x0d01, 0x04); + reg_w(gspca_dev->dev, 0x00, 0x8168, 0x22); + reg_w(gspca_dev->dev, 0x00, 0x816a, 0xc0); + reg_w(gspca_dev->dev, 0x00, 0x816b, 0x0b); + reg_w(gspca_dev->dev, 0x00, 0x8169, 0x25); + reg_w(gspca_dev->dev, 0x00, 0x8157, 0x5b); + reg_w(gspca_dev->dev, 0x00, 0x8158, 0x5b); + reg_w(gspca_dev->dev, 0x00, 0x813f, 0x03); + reg_w(gspca_dev->dev, 0x00, 0x8151, 0x4a); + reg_w(gspca_dev->dev, 0x00, 0x8153, 0x78); + reg_w(gspca_dev->dev, 0x00, 0x0d01, 0x04); /* 00 for adjust shutter */ - reg_write(gspca_dev->dev, 0x00, 0x0d02, 0x01); - reg_write(gspca_dev->dev, 0x00, 0x8169, 0x25); - reg_write(gspca_dev->dev, 0x00, 0x0d01, 0x02); + reg_w(gspca_dev->dev, 0x00, 0x0d02, 0x01); + reg_w(gspca_dev->dev, 0x00, 0x8169, 0x25); + reg_w(gspca_dev->dev, 0x00, 0x0d01, 0x02); } static void spca500_setmode(struct gspca_dev *gspca_dev, @@ -511,14 +509,14 @@ static void spca500_setmode(struct gspca_dev *gspca_dev, int mode; /* set x multiplier */ - reg_write(gspca_dev->dev, 0, 0x8001, xmult); + reg_w(gspca_dev->dev, 0, 0x8001, xmult); /* set y multiplier */ - reg_write(gspca_dev->dev, 0, 0x8002, ymult); + reg_w(gspca_dev->dev, 0, 0x8002, ymult); /* use compressed mode, VGA, with mode specific subsample */ mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode; - reg_write(gspca_dev->dev, 0, 0x8003, mode << 4); + reg_w(gspca_dev->dev, 0, 0x8003, mode << 4); } static int spca500_full_reset(struct gspca_dev *gspca_dev) @@ -526,20 +524,20 @@ static int spca500_full_reset(struct gspca_dev *gspca_dev) int err; /* send the reset command */ - err = reg_write(gspca_dev->dev, 0xe0, 0x0001, 0x0000); + err = reg_w(gspca_dev->dev, 0xe0, 0x0001, 0x0000); if (err < 0) return err; /* wait for the reset to complete */ - err = reg_readwait(gspca_dev->dev, 0x06, 0x0000, 0x0000); + err = reg_r_wait(gspca_dev->dev, 0x06, 0x0000, 0x0000); if (err < 0) return err; - err = reg_write(gspca_dev->dev, 0xe0, 0x0000, 0x0000); + err = reg_w(gspca_dev->dev, 0xe0, 0x0000, 0x0000); if (err < 0) return err; - err = reg_readwait(gspca_dev->dev, 0x06, 0, 0); + err = reg_r_wait(gspca_dev->dev, 0x06, 0, 0); if (err < 0) { - PDEBUG(D_ERR, "reg_readwait() failed"); + PDEBUG(D_ERR, "reg_r_wait() failed"); return err; } /* all ok */ @@ -562,7 +560,7 @@ static int spca500_synch310(struct gspca_dev *gspca_dev) } spca500_ping310(gspca_dev); - spca5xxRegRead(gspca_dev->dev, 0x0d00, &Data, 1); + reg_r(gspca_dev->dev, 0x0d00, &Data, 1); /* need alt setting here */ PDEBUG(D_PACK, "ClickSmart310 sync alt: %d", gspca_dev->alt); @@ -586,12 +584,12 @@ static void spca500_reinit(struct gspca_dev *gspca_dev) /* some unknow command from Aiptek pocket dv and family300 */ - reg_write(gspca_dev->dev, 0x00, 0x0d01, 0x01); - reg_write(gspca_dev->dev, 0x00, 0x0d03, 0x00); - reg_write(gspca_dev->dev, 0x00, 0x0d02, 0x01); + reg_w(gspca_dev->dev, 0x00, 0x0d01, 0x01); + reg_w(gspca_dev->dev, 0x00, 0x0d03, 0x00); + reg_w(gspca_dev->dev, 0x00, 0x0d02, 0x01); /* enable drop packet */ - reg_write(gspca_dev->dev, 0x00, 0x850a, 0x0001); + reg_w(gspca_dev->dev, 0x00, 0x850a, 0x0001); err = spca50x_setup_qtable(gspca_dev, 0x00, 0x8800, 0x8840, qtable_pocketdv); @@ -599,22 +597,22 @@ static void spca500_reinit(struct gspca_dev *gspca_dev) PDEBUG(D_ERR|D_STREAM, "spca50x_setup_qtable failed on init"); /* set qtable index */ - reg_write(gspca_dev->dev, 0x00, 0x8880, 2); + reg_w(gspca_dev->dev, 0x00, 0x8880, 2); /* family cam Quicksmart stuff */ - reg_write(gspca_dev->dev, 0x00, 0x800a, 0x00); + reg_w(gspca_dev->dev, 0x00, 0x800a, 0x00); /* Set agc transfer: synced inbetween frames */ - reg_write(gspca_dev->dev, 0x00, 0x820f, 0x01); + reg_w(gspca_dev->dev, 0x00, 0x820f, 0x01); /* Init SDRAM - needed for SDRAM access */ - reg_write(gspca_dev->dev, 0x00, 0x870a, 0x04); + reg_w(gspca_dev->dev, 0x00, 0x870a, 0x04); /*Start init sequence or stream */ - reg_write(gspca_dev->dev, 0, 0x8003, 0x00); + reg_w(gspca_dev->dev, 0, 0x8003, 0x00); /* switch to video camera mode */ - reg_write(gspca_dev->dev, 0x00, 0x8000, 0x0004); + reg_w(gspca_dev->dev, 0x00, 0x8000, 0x0004); msleep(2000); - if (reg_readwait(gspca_dev->dev, 0, 0x8000, 0x44) != 0) - spca5xxRegRead(gspca_dev->dev, 0x816b, &Data, 1); - reg_write(gspca_dev->dev, 0x00, 0x816b, Data); + if (reg_r_wait(gspca_dev->dev, 0, 0x8000, 0x44) != 0) + reg_r(gspca_dev->dev, 0x816b, &Data, 1); + reg_w(gspca_dev->dev, 0x00, 0x816b, Data); } /* this function is called at probe time */ @@ -734,9 +732,9 @@ static int sd_config(struct gspca_dev *gspca_dev, cam->nmodes = sizeof sif_mode / sizeof sif_mode[0]; } sd->qindex = 5; - sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; - sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value; - sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value; + sd->brightness = BRIGHTNESS_DEF; + sd->contrast = CONTRAST_DEF; + sd->colors = COLOR_DEF; return 0; } @@ -771,7 +769,7 @@ static void sd_start(struct gspca_dev *gspca_dev) } /* is there a sensor here ? */ - spca5xxRegRead(gspca_dev->dev, 0x8a04, &Data, 1); + reg_r(gspca_dev->dev, 0x8a04, &Data, 1); PDEBUG(D_STREAM, "Spca500 Sensor Address 0x%02X", Data); PDEBUG(D_STREAM, "Spca500 curr_mode: %d Xmult: 0x%02X, Ymult: 0x%02X", gspca_dev->curr_mode, xmult, ymult); @@ -782,33 +780,33 @@ static void sd_start(struct gspca_dev *gspca_dev) spca500_setmode(gspca_dev, xmult, ymult); /* enable drop packet */ - reg_write(gspca_dev->dev, 0x00, 0x850a, 0x0001); - reg_write(gspca_dev->dev, 0x00, 0x8880, 3); + reg_w(gspca_dev->dev, 0x00, 0x850a, 0x0001); + reg_w(gspca_dev->dev, 0x00, 0x8880, 3); err = spca50x_setup_qtable(gspca_dev, 0x00, 0x8800, 0x8840, qtable_creative_pccam); if (err < 0) PDEBUG(D_ERR, "spca50x_setup_qtable failed"); /* Init SDRAM - needed for SDRAM access */ - reg_write(gspca_dev->dev, 0x00, 0x870a, 0x04); + reg_w(gspca_dev->dev, 0x00, 0x870a, 0x04); /* switch to video camera mode */ - reg_write(gspca_dev->dev, 0x00, 0x8000, 0x0004); + reg_w(gspca_dev->dev, 0x00, 0x8000, 0x0004); msleep(500); - if (reg_readwait(gspca_dev->dev, 0, 0x8000, 0x44) != 0) - PDEBUG(D_ERR, "reg_readwait() failed"); + if (reg_r_wait(gspca_dev->dev, 0, 0x8000, 0x44) != 0) + PDEBUG(D_ERR, "reg_r_wait() failed"); - spca5xxRegRead(gspca_dev->dev, 0x816b, &Data, 1); - reg_write(gspca_dev->dev, 0x00, 0x816b, Data); + reg_r(gspca_dev->dev, 0x816b, &Data, 1); + reg_w(gspca_dev->dev, 0x00, 0x816b, Data); spca500_synch310(gspca_dev); write_vector(gspca_dev, spca500_visual_defaults); spca500_setmode(gspca_dev, xmult, ymult); /* enable drop packet */ - reg_write(gspca_dev->dev, 0x00, 0x850a, 0x0001); + reg_w(gspca_dev->dev, 0x00, 0x850a, 0x0001); PDEBUG(D_ERR, "failed to enable drop packet"); - reg_write(gspca_dev->dev, 0x00, 0x8880, 3); + reg_w(gspca_dev->dev, 0x00, 0x8880, 3); err = spca50x_setup_qtable(gspca_dev, 0x00, 0x8800, 0x8840, qtable_creative_pccam); @@ -816,16 +814,16 @@ static void sd_start(struct gspca_dev *gspca_dev) PDEBUG(D_ERR, "spca50x_setup_qtable failed"); /* Init SDRAM - needed for SDRAM access */ - reg_write(gspca_dev->dev, 0x00, 0x870a, 0x04); + reg_w(gspca_dev->dev, 0x00, 0x870a, 0x04); /* switch to video camera mode */ - reg_write(gspca_dev->dev, 0x00, 0x8000, 0x0004); + reg_w(gspca_dev->dev, 0x00, 0x8000, 0x0004); - if (reg_readwait(gspca_dev->dev, 0, 0x8000, 0x44) != 0) - PDEBUG(D_ERR, "reg_readwait() failed"); + if (reg_r_wait(gspca_dev->dev, 0, 0x8000, 0x44) != 0) + PDEBUG(D_ERR, "reg_r_wait() failed"); - spca5xxRegRead(gspca_dev->dev, 0x816b, &Data, 1); - reg_write(gspca_dev->dev, 0x00, 0x816b, Data); + reg_r(gspca_dev->dev, 0x816b, &Data, 1); + reg_w(gspca_dev->dev, 0x00, 0x816b, Data); break; case CreativePCCam300: /* Creative PC-CAM 300 640x480 CCD */ case IntelPocketPCCamera: /* FIXME: Temporary fix for @@ -838,10 +836,10 @@ static void sd_start(struct gspca_dev *gspca_dev) PDEBUG(D_ERR, "spca500_full_reset failed"); /* enable drop packet */ - err = reg_write(gspca_dev->dev, 0x00, 0x850a, 0x0001); + err = reg_w(gspca_dev->dev, 0x00, 0x850a, 0x0001); if (err < 0) PDEBUG(D_ERR, "failed to enable drop packet"); - reg_write(gspca_dev->dev, 0x00, 0x8880, 3); + reg_w(gspca_dev->dev, 0x00, 0x8880, 3); err = spca50x_setup_qtable(gspca_dev, 0x00, 0x8800, 0x8840, qtable_creative_pccam); @@ -849,18 +847,18 @@ static void sd_start(struct gspca_dev *gspca_dev) PDEBUG(D_ERR, "spca50x_setup_qtable failed"); spca500_setmode(gspca_dev, xmult, ymult); - reg_write(gspca_dev->dev, 0x20, 0x0001, 0x0004); + reg_w(gspca_dev->dev, 0x20, 0x0001, 0x0004); /* switch to video camera mode */ - reg_write(gspca_dev->dev, 0x00, 0x8000, 0x0004); + reg_w(gspca_dev->dev, 0x00, 0x8000, 0x0004); - if (reg_readwait(gspca_dev->dev, 0, 0x8000, 0x44) != 0) - PDEBUG(D_ERR, "reg_readwait() failed"); + if (reg_r_wait(gspca_dev->dev, 0, 0x8000, 0x44) != 0) + PDEBUG(D_ERR, "reg_r_wait() failed"); - spca5xxRegRead(gspca_dev->dev, 0x816b, &Data, 1); - reg_write(gspca_dev->dev, 0x00, 0x816b, Data); + reg_r(gspca_dev->dev, 0x816b, &Data, 1); + reg_w(gspca_dev->dev, 0x00, 0x816b, Data); - /* write_vector(gspca_dev, spca500_visual_defaults); */ +/* write_vector(gspca_dev, spca500_visual_defaults); */ break; case KodakEZ200: /* Kodak EZ200 */ @@ -869,8 +867,8 @@ static void sd_start(struct gspca_dev *gspca_dev) if (err < 0) PDEBUG(D_ERR, "spca500_full_reset failed"); /* enable drop packet */ - reg_write(gspca_dev->dev, 0x00, 0x850a, 0x0001); - reg_write(gspca_dev->dev, 0x00, 0x8880, 0); + reg_w(gspca_dev->dev, 0x00, 0x850a, 0x0001); + reg_w(gspca_dev->dev, 0x00, 0x8880, 0); err = spca50x_setup_qtable(gspca_dev, 0x00, 0x8800, 0x8840, qtable_kodak_ez200); @@ -878,18 +876,18 @@ static void sd_start(struct gspca_dev *gspca_dev) PDEBUG(D_ERR, "spca50x_setup_qtable failed"); spca500_setmode(gspca_dev, xmult, ymult); - reg_write(gspca_dev->dev, 0x20, 0x0001, 0x0004); + reg_w(gspca_dev->dev, 0x20, 0x0001, 0x0004); /* switch to video camera mode */ - reg_write(gspca_dev->dev, 0x00, 0x8000, 0x0004); + reg_w(gspca_dev->dev, 0x00, 0x8000, 0x0004); - if (reg_readwait(gspca_dev->dev, 0, 0x8000, 0x44) != 0) - PDEBUG(D_ERR, "reg_readwait() failed"); + if (reg_r_wait(gspca_dev->dev, 0, 0x8000, 0x44) != 0) + PDEBUG(D_ERR, "reg_r_wait() failed"); - spca5xxRegRead(gspca_dev->dev, 0x816b, &Data, 1); - reg_write(gspca_dev->dev, 0x00, 0x816b, Data); + reg_r(gspca_dev->dev, 0x816b, &Data, 1); + reg_w(gspca_dev->dev, 0x00, 0x816b, Data); - /* write_vector(gspca_dev, spca500_visual_defaults); */ +/* write_vector(gspca_dev, spca500_visual_defaults); */ break; case BenqDC1016: @@ -902,56 +900,56 @@ static void sd_start(struct gspca_dev *gspca_dev) case ToptroIndus: case AgfaCl20: spca500_reinit(gspca_dev); - reg_write(gspca_dev->dev, 0x00, 0x0d01, 0x01); + reg_w(gspca_dev->dev, 0x00, 0x0d01, 0x01); /* enable drop packet */ - reg_write(gspca_dev->dev, 0x00, 0x850a, 0x0001); + reg_w(gspca_dev->dev, 0x00, 0x850a, 0x0001); err = spca50x_setup_qtable(gspca_dev, 0x00, 0x8800, 0x8840, qtable_pocketdv); if (err < 0) PDEBUG(D_ERR, "spca50x_setup_qtable failed"); - reg_write(gspca_dev->dev, 0x00, 0x8880, 2); + reg_w(gspca_dev->dev, 0x00, 0x8880, 2); /* familycam Quicksmart pocketDV stuff */ - reg_write(gspca_dev->dev, 0x00, 0x800a, 0x00); + reg_w(gspca_dev->dev, 0x00, 0x800a, 0x00); /* Set agc transfer: synced inbetween frames */ - reg_write(gspca_dev->dev, 0x00, 0x820f, 0x01); + reg_w(gspca_dev->dev, 0x00, 0x820f, 0x01); /* Init SDRAM - needed for SDRAM access */ - reg_write(gspca_dev->dev, 0x00, 0x870a, 0x04); + reg_w(gspca_dev->dev, 0x00, 0x870a, 0x04); spca500_setmode(gspca_dev, xmult, ymult); /* switch to video camera mode */ - reg_write(gspca_dev->dev, 0x00, 0x8000, 0x0004); + reg_w(gspca_dev->dev, 0x00, 0x8000, 0x0004); - reg_readwait(gspca_dev->dev, 0, 0x8000, 0x44); + reg_r_wait(gspca_dev->dev, 0, 0x8000, 0x44); - spca5xxRegRead(gspca_dev->dev, 0x816b, &Data, 1); - reg_write(gspca_dev->dev, 0x00, 0x816b, Data); + reg_r(gspca_dev->dev, 0x816b, &Data, 1); + reg_w(gspca_dev->dev, 0x00, 0x816b, Data); break; case LogitechTraveler: case LogitechClickSmart510: - reg_write(gspca_dev->dev, 0x02, 0x00, 0x00); + reg_w(gspca_dev->dev, 0x02, 0x00, 0x00); /* enable drop packet */ - reg_write(gspca_dev->dev, 0x00, 0x850a, 0x0001); + reg_w(gspca_dev->dev, 0x00, 0x850a, 0x0001); err = spca50x_setup_qtable(gspca_dev, 0x00, 0x8800, 0x8840, qtable_creative_pccam); if (err < 0) PDEBUG(D_ERR, "spca50x_setup_qtable failed"); - reg_write(gspca_dev->dev, 0x00, 0x8880, 3); - reg_write(gspca_dev->dev, 0x00, 0x800a, 0x00); + reg_w(gspca_dev->dev, 0x00, 0x8880, 3); + reg_w(gspca_dev->dev, 0x00, 0x800a, 0x00); /* Init SDRAM - needed for SDRAM access */ - reg_write(gspca_dev->dev, 0x00, 0x870a, 0x04); + reg_w(gspca_dev->dev, 0x00, 0x870a, 0x04); spca500_setmode(gspca_dev, xmult, ymult); /* switch to video camera mode */ - reg_write(gspca_dev->dev, 0x00, 0x8000, 0x0004); - reg_readwait(gspca_dev->dev, 0, 0x8000, 0x44); + reg_w(gspca_dev->dev, 0x00, 0x8000, 0x0004); + reg_r_wait(gspca_dev->dev, 0, 0x8000, 0x44); - spca5xxRegRead(gspca_dev->dev, 0x816b, &Data, 1); - reg_write(gspca_dev->dev, 0x00, 0x816b, Data); + reg_r(gspca_dev->dev, 0x816b, &Data, 1); + reg_w(gspca_dev->dev, 0x00, 0x816b, Data); write_vector(gspca_dev, Clicksmart510_defaults); break; } @@ -959,13 +957,13 @@ static void sd_start(struct gspca_dev *gspca_dev) static void sd_stopN(struct gspca_dev *gspca_dev) { - __u8 data = 0; + __u8 data; - reg_write(gspca_dev->dev, 0, 0x8003, 0x00); + reg_w(gspca_dev->dev, 0, 0x8003, 0x00); /* switch to video camera mode */ - reg_write(gspca_dev->dev, 0x00, 0x8000, 0x0004); - spca5xxRegRead(gspca_dev->dev, 0x8000, &data, 1); + reg_w(gspca_dev->dev, 0x00, 0x8000, 0x0004); + reg_r(gspca_dev->dev, 0x8000, &data, 1); PDEBUG(D_STREAM, "stop SPCA500 done reg8000: 0x%2x", data); } @@ -979,13 +977,13 @@ static void sd_close(struct gspca_dev *gspca_dev) static void sd_pkt_scan(struct gspca_dev *gspca_dev, struct gspca_frame *frame, /* target */ - unsigned char *data, /* isoc packet */ + __u8 *data, /* isoc packet */ int len) /* iso packet length */ { struct sd *sd = (struct sd *) gspca_dev; int i; - unsigned char *s, *d; - static unsigned char ffd9[] = {0xff, 0xd9}; + __u8 *s, *d; + static __u8 ffd9[] = {0xff, 0xd9}; /* frames are jpeg 4.1.1 without 0xff escape */ if (data[0] == 0xff) { @@ -997,9 +995,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, ffd9, 2); /* put the JPEG header in the new frame */ - jpeg_put_header(gspca_dev, frame, - ((struct sd *) gspca_dev)->qindex, - 0x22); + jpeg_put_header(gspca_dev, frame, sd->qindex, 0x22); data += SPCA500_OFFSET_DATA; len -= SPCA500_OFFSET_DATA; @@ -1031,43 +1027,52 @@ static void setbrightness(struct gspca_dev *gspca_dev) { struct sd *sd = (struct sd *) gspca_dev; - reg_write(gspca_dev->dev, 0x00, 0x8167, + reg_w(gspca_dev->dev, 0x00, 0x8167, (__u8) (sd->brightness - 128)); } static void getbrightness(struct gspca_dev *gspca_dev) { struct sd *sd = (struct sd *) gspca_dev; + int ret; - sd->brightness = reg_read(gspca_dev->dev, 0x00, 0x8167, 1) + 128; + ret = reg_r_12(gspca_dev->dev, 0x00, 0x8167, 1); + if (ret >= 0) + sd->brightness = ret + 128; } static void setcontrast(struct gspca_dev *gspca_dev) { struct sd *sd = (struct sd *) gspca_dev; - reg_write(gspca_dev->dev, 0x00, 0x8168, sd->contrast >> 2); + reg_w(gspca_dev->dev, 0x00, 0x8168, sd->contrast); } static void getcontrast(struct gspca_dev *gspca_dev) { struct sd *sd = (struct sd *) gspca_dev; + int ret; - sd->contrast = reg_read(gspca_dev->dev, 0x0, 0x8168, 1) << 2; + ret = reg_r_12(gspca_dev->dev, 0x0, 0x8168, 1); + if (ret >= 0) + sd->contrast = ret; } static void setcolors(struct gspca_dev *gspca_dev) { struct sd *sd = (struct sd *) gspca_dev; - reg_write(gspca_dev->dev, 0x00, 0x8169, sd->colors >> 2); + reg_w(gspca_dev->dev, 0x00, 0x8169, sd->colors); } static void getcolors(struct gspca_dev *gspca_dev) { struct sd *sd = (struct sd *) gspca_dev; + int ret; - sd->colors = reg_read(gspca_dev->dev, 0x0, 0x8169, 1) << 2; + ret = reg_r_12(gspca_dev->dev, 0x0, 0x8169, 1); + if (ret >= 0) + sd->colors = ret; } static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) @@ -1131,7 +1136,7 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val) static struct sd_desc sd_desc = { .name = MODULE_NAME, .ctrls = sd_ctrls, - .nctrls = sizeof sd_ctrls / sizeof sd_ctrls[0], + .nctrls = ARRAY_SIZE(sd_ctrls), .config = sd_config, .open = sd_open, .start = sd_start, @@ -1143,7 +1148,7 @@ static struct sd_desc sd_desc = { /* -- module initialisation -- */ #define DVNM(name) .driver_info = (kernel_ulong_t) name -static __devinitdata struct usb_device_id device_table[] = { +static const __devinitdata struct usb_device_id device_table[] = { {USB_DEVICE(0x040a, 0x0300), DVNM("Kodak EZ200")}, {USB_DEVICE(0x041e, 0x400a), DVNM("Creative PC-CAM 300")}, {USB_DEVICE(0x046d, 0x0890), DVNM("Logitech QuickCam traveler")}, -- cgit v1.2.2