Commit 2e1794b5 authored by Jean-Francois Moine's avatar Jean-Francois Moine Committed by Mauro Carvalho Chehab

V4L/DVB (12692): gspca - sunplus: Optimize code.

Signed-off-by: default avatarJean-Francois Moine <moinejf@free.fr>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 1f78a976
...@@ -32,22 +32,22 @@ MODULE_LICENSE("GPL"); ...@@ -32,22 +32,22 @@ MODULE_LICENSE("GPL");
struct sd { struct sd {
struct gspca_dev gspca_dev; /* !! must be the first item */ struct gspca_dev gspca_dev; /* !! must be the first item */
unsigned char brightness; u8 brightness;
unsigned char contrast; u8 contrast;
unsigned char colors; u8 colors;
unsigned char autogain; u8 autogain;
u8 quality; u8 quality;
#define QUALITY_MIN 70 #define QUALITY_MIN 70
#define QUALITY_MAX 95 #define QUALITY_MAX 95
#define QUALITY_DEF 85 #define QUALITY_DEF 85
char bridge; u8 bridge;
#define BRIDGE_SPCA504 0 #define BRIDGE_SPCA504 0
#define BRIDGE_SPCA504B 1 #define BRIDGE_SPCA504B 1
#define BRIDGE_SPCA504C 2 #define BRIDGE_SPCA504C 2
#define BRIDGE_SPCA533 3 #define BRIDGE_SPCA533 3
#define BRIDGE_SPCA536 4 #define BRIDGE_SPCA536 4
char subtype; u8 subtype;
#define AiptekMiniPenCam13 1 #define AiptekMiniPenCam13 1
#define LogitechClickSmart420 2 #define LogitechClickSmart420 2
#define LogitechClickSmart820 3 #define LogitechClickSmart820 3
...@@ -68,7 +68,6 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val); ...@@ -68,7 +68,6 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
static struct ctrl sd_ctrls[] = { static struct ctrl sd_ctrls[] = {
#define SD_BRIGHTNESS 0
{ {
{ {
.id = V4L2_CID_BRIGHTNESS, .id = V4L2_CID_BRIGHTNESS,
...@@ -77,12 +76,12 @@ static struct ctrl sd_ctrls[] = { ...@@ -77,12 +76,12 @@ static struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 0xff, .maximum = 0xff,
.step = 1, .step = 1,
.default_value = 0, #define BRIGHTNESS_DEF 0
.default_value = BRIGHTNESS_DEF,
}, },
.set = sd_setbrightness, .set = sd_setbrightness,
.get = sd_getbrightness, .get = sd_getbrightness,
}, },
#define SD_CONTRAST 1
{ {
{ {
.id = V4L2_CID_CONTRAST, .id = V4L2_CID_CONTRAST,
...@@ -91,12 +90,12 @@ static struct ctrl sd_ctrls[] = { ...@@ -91,12 +90,12 @@ static struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 0xff, .maximum = 0xff,
.step = 1, .step = 1,
.default_value = 0x20, #define CONTRAST_DEF 0x20
.default_value = CONTRAST_DEF,
}, },
.set = sd_setcontrast, .set = sd_setcontrast,
.get = sd_getcontrast, .get = sd_getcontrast,
}, },
#define SD_COLOR 2
{ {
{ {
.id = V4L2_CID_SATURATION, .id = V4L2_CID_SATURATION,
...@@ -105,12 +104,12 @@ static struct ctrl sd_ctrls[] = { ...@@ -105,12 +104,12 @@ static struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 0xff, .maximum = 0xff,
.step = 1, .step = 1,
.default_value = 0x1a, #define COLOR_DEF 0x1a
.default_value = COLOR_DEF,
}, },
.set = sd_setcolors, .set = sd_setcolors,
.get = sd_getcolors, .get = sd_getcolors,
}, },
#define SD_AUTOGAIN 3
{ {
{ {
.id = V4L2_CID_AUTOGAIN, .id = V4L2_CID_AUTOGAIN,
...@@ -119,7 +118,8 @@ static struct ctrl sd_ctrls[] = { ...@@ -119,7 +118,8 @@ static struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 1, .maximum = 1,
.step = 1, .step = 1,
.default_value = 1, #define AUTOGAIN_DEF 1
.default_value = AUTOGAIN_DEF,
}, },
.set = sd_setautogain, .set = sd_setautogain,
.get = sd_getautogain, .get = sd_getautogain,
...@@ -187,8 +187,14 @@ static const struct v4l2_pix_format vga_mode2[] = { ...@@ -187,8 +187,14 @@ static const struct v4l2_pix_format vga_mode2[] = {
#define SPCA536_OFFSET_DATA 4 #define SPCA536_OFFSET_DATA 4
#define SPCA536_OFFSET_FRAMSEQ 1 #define SPCA536_OFFSET_FRAMSEQ 1
struct cmd {
u8 req;
u16 val;
u16 idx;
};
/* Initialisation data for the Creative PC-CAM 600 */ /* Initialisation data for the Creative PC-CAM 600 */
static const __u16 spca504_pccam600_init_data[][3] = { static const struct cmd spca504_pccam600_init_data[] = {
/* {0xa0, 0x0000, 0x0503}, * capture mode */ /* {0xa0, 0x0000, 0x0503}, * capture mode */
{0x00, 0x0000, 0x2000}, {0x00, 0x0000, 0x2000},
{0x00, 0x0013, 0x2301}, {0x00, 0x0013, 0x2301},
...@@ -212,22 +218,20 @@ static const __u16 spca504_pccam600_init_data[][3] = { ...@@ -212,22 +218,20 @@ static const __u16 spca504_pccam600_init_data[][3] = {
{0x00, 0x0003, 0x2000}, {0x00, 0x0003, 0x2000},
{0x00, 0x0013, 0x2301}, {0x00, 0x0013, 0x2301},
{0x00, 0x0003, 0x2000}, {0x00, 0x0003, 0x2000},
{}
}; };
/* Creative PC-CAM 600 specific open data, sent before using the /* Creative PC-CAM 600 specific open data, sent before using the
* generic initialisation data from spca504_open_data. * generic initialisation data from spca504_open_data.
*/ */
static const __u16 spca504_pccam600_open_data[][3] = { static const struct cmd spca504_pccam600_open_data[] = {
{0x00, 0x0001, 0x2501}, {0x00, 0x0001, 0x2501},
{0x20, 0x0500, 0x0001}, /* snapshot mode */ {0x20, 0x0500, 0x0001}, /* snapshot mode */
{0x00, 0x0003, 0x2880}, {0x00, 0x0003, 0x2880},
{0x00, 0x0001, 0x2881}, {0x00, 0x0001, 0x2881},
{}
}; };
/* Initialisation data for the logitech clicksmart 420 */ /* Initialisation data for the logitech clicksmart 420 */
static const __u16 spca504A_clicksmart420_init_data[][3] = { static const struct cmd spca504A_clicksmart420_init_data[] = {
/* {0xa0, 0x0000, 0x0503}, * capture mode */ /* {0xa0, 0x0000, 0x0503}, * capture mode */
{0x00, 0x0000, 0x2000}, {0x00, 0x0000, 0x2000},
{0x00, 0x0013, 0x2301}, {0x00, 0x0013, 0x2301},
...@@ -244,7 +248,7 @@ static const __u16 spca504A_clicksmart420_init_data[][3] = { ...@@ -244,7 +248,7 @@ static const __u16 spca504A_clicksmart420_init_data[][3] = {
{0xb0, 0x0001, 0x0000}, {0xb0, 0x0001, 0x0000},
{0x0a1, 0x0080, 0x0001}, {0xa1, 0x0080, 0x0001},
{0x30, 0x0049, 0x0000}, {0x30, 0x0049, 0x0000},
{0x30, 0x0060, 0x0005}, {0x30, 0x0060, 0x0005},
{0x0c, 0x0004, 0x0000}, {0x0c, 0x0004, 0x0000},
...@@ -254,11 +258,10 @@ static const __u16 spca504A_clicksmart420_init_data[][3] = { ...@@ -254,11 +258,10 @@ static const __u16 spca504A_clicksmart420_init_data[][3] = {
{0x00, 0x0003, 0x2000}, {0x00, 0x0003, 0x2000},
{0x00, 0x0000, 0x2000}, {0x00, 0x0000, 0x2000},
{}
}; };
/* clicksmart 420 open data ? */ /* clicksmart 420 open data ? */
static const __u16 spca504A_clicksmart420_open_data[][3] = { static const struct cmd spca504A_clicksmart420_open_data[] = {
{0x00, 0x0001, 0x2501}, {0x00, 0x0001, 0x2501},
{0x20, 0x0502, 0x0000}, {0x20, 0x0502, 0x0000},
{0x06, 0x0000, 0x0000}, {0x06, 0x0000, 0x0000},
...@@ -402,10 +405,9 @@ static const __u16 spca504A_clicksmart420_open_data[][3] = { ...@@ -402,10 +405,9 @@ static const __u16 spca504A_clicksmart420_open_data[][3] = {
{0x00, 0x0028, 0x287f}, {0x00, 0x0028, 0x287f},
{0xa0, 0x0000, 0x0503}, {0xa0, 0x0000, 0x0503},
{}
}; };
static const __u8 qtable_creative_pccam[2][64] = { static const u8 qtable_creative_pccam[2][64] = {
{ /* Q-table Y-components */ { /* Q-table Y-components */
0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12, 0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12,
0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11, 0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11,
...@@ -430,7 +432,7 @@ static const __u8 qtable_creative_pccam[2][64] = { ...@@ -430,7 +432,7 @@ static const __u8 qtable_creative_pccam[2][64] = {
* except for one byte. Possibly a typo? * except for one byte. Possibly a typo?
* NWG: 18/05/2003. * NWG: 18/05/2003.
*/ */
static const __u8 qtable_spca504_default[2][64] = { static const u8 qtable_spca504_default[2][64] = {
{ /* Q-table Y-components */ { /* Q-table Y-components */
0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12, 0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12,
0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11, 0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11,
...@@ -454,9 +456,9 @@ static const __u8 qtable_spca504_default[2][64] = { ...@@ -454,9 +456,9 @@ static const __u8 qtable_spca504_default[2][64] = {
/* read <len> bytes to gspca_dev->usb_buf */ /* read <len> bytes to gspca_dev->usb_buf */
static void reg_r(struct gspca_dev *gspca_dev, static void reg_r(struct gspca_dev *gspca_dev,
__u16 req, u8 req,
__u16 index, u16 index,
__u16 len) u16 len)
{ {
#ifdef GSPCA_DEBUG #ifdef GSPCA_DEBUG
if (len > USB_BUF_SZ) { if (len > USB_BUF_SZ) {
...@@ -474,31 +476,26 @@ static void reg_r(struct gspca_dev *gspca_dev, ...@@ -474,31 +476,26 @@ static void reg_r(struct gspca_dev *gspca_dev,
500); 500);
} }
/* write <len> bytes from gspca_dev->usb_buf */ /* write one byte */
static void reg_w(struct gspca_dev *gspca_dev, static void reg_w_1(struct gspca_dev *gspca_dev,
__u16 req, u8 req,
__u16 value, u16 value,
__u16 index, u16 index,
__u16 len) u16 byte)
{ {
#ifdef GSPCA_DEBUG gspca_dev->usb_buf[0] = byte;
if (len > USB_BUF_SZ) {
err("reg_w: buffer overflow");
return;
}
#endif
usb_control_msg(gspca_dev->dev, usb_control_msg(gspca_dev->dev,
usb_sndctrlpipe(gspca_dev->dev, 0), usb_sndctrlpipe(gspca_dev->dev, 0),
req, req,
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
value, index, value, index,
len ? gspca_dev->usb_buf : NULL, len, gspca_dev->usb_buf, 1,
500); 500);
} }
/* write req / index / value */ /* write req / index / value */
static int reg_w_riv(struct usb_device *dev, static int reg_w_riv(struct usb_device *dev,
__u16 req, __u16 index, __u16 value) u8 req, u16 index, u16 value)
{ {
int ret; int ret;
...@@ -516,7 +513,7 @@ static int reg_w_riv(struct usb_device *dev, ...@@ -516,7 +513,7 @@ static int reg_w_riv(struct usb_device *dev,
/* read 1 byte */ /* read 1 byte */
static int reg_r_1(struct gspca_dev *gspca_dev, static int reg_r_1(struct gspca_dev *gspca_dev,
__u16 value) /* wValue */ u16 value) /* wValue */
{ {
int ret; int ret;
...@@ -537,9 +534,9 @@ static int reg_r_1(struct gspca_dev *gspca_dev, ...@@ -537,9 +534,9 @@ static int reg_r_1(struct gspca_dev *gspca_dev,
/* read 1 or 2 bytes - returns < 0 if error */ /* read 1 or 2 bytes - returns < 0 if error */
static int reg_r_12(struct gspca_dev *gspca_dev, static int reg_r_12(struct gspca_dev *gspca_dev,
__u16 req, /* bRequest */ u8 req, /* bRequest */
__u16 index, /* wIndex */ u16 index, /* wIndex */
__u16 length) /* wLength (1 or 2 only) */ u16 length) /* wLength (1 or 2 only) */
{ {
int ret; int ret;
...@@ -560,43 +557,40 @@ static int reg_r_12(struct gspca_dev *gspca_dev, ...@@ -560,43 +557,40 @@ static int reg_r_12(struct gspca_dev *gspca_dev,
} }
static int write_vector(struct gspca_dev *gspca_dev, static int write_vector(struct gspca_dev *gspca_dev,
const __u16 data[][3]) const struct cmd *data, int ncmds)
{ {
struct usb_device *dev = gspca_dev->dev; struct usb_device *dev = gspca_dev->dev;
int ret, i = 0; int ret;
while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) { while (--ncmds >= 0) {
ret = reg_w_riv(dev, data[i][0], data[i][2], data[i][1]); ret = reg_w_riv(dev, data->req, data->idx, data->val);
if (ret < 0) { if (ret < 0) {
PDEBUG(D_ERR, PDEBUG(D_ERR,
"Register write failed for 0x%x,0x%x,0x%x", "Register write failed for 0x%02x, 0x%04x, 0x%04x",
data[i][0], data[i][1], data[i][2]); data->req, data->val, data->idx);
return ret; return ret;
} }
i++; data++;
} }
return 0; return 0;
} }
static int spca50x_setup_qtable(struct gspca_dev *gspca_dev, static int spca50x_setup_qtable(struct gspca_dev *gspca_dev,
unsigned int request, const u8 qtable[2][64])
unsigned int ybase,
unsigned int cbase,
const __u8 qtable[2][64])
{ {
struct usb_device *dev = gspca_dev->dev; struct usb_device *dev = gspca_dev->dev;
int i, err; int i, err;
/* loop over y components */ /* loop over y components */
for (i = 0; i < 64; i++) { for (i = 0; i < 64; i++) {
err = reg_w_riv(dev, request, ybase + i, qtable[0][i]); err = reg_w_riv(dev, 0x00, 0x2800 + i, qtable[0][i]);
if (err < 0) if (err < 0)
return err; return err;
} }
/* loop over c components */ /* loop over c components */
for (i = 0; i < 64; i++) { for (i = 0; i < 64; i++) {
err = reg_w_riv(dev, request, cbase + i, qtable[1][i]); err = reg_w_riv(dev, 0x00, 0x2840 + i, qtable[1][i]);
if (err < 0) if (err < 0)
return err; return err;
} }
...@@ -604,34 +598,34 @@ static int spca50x_setup_qtable(struct gspca_dev *gspca_dev, ...@@ -604,34 +598,34 @@ static int spca50x_setup_qtable(struct gspca_dev *gspca_dev,
} }
static void spca504_acknowledged_command(struct gspca_dev *gspca_dev, static void spca504_acknowledged_command(struct gspca_dev *gspca_dev,
__u16 req, __u16 idx, __u16 val) u8 req, u16 idx, u16 val)
{ {
struct usb_device *dev = gspca_dev->dev; struct usb_device *dev = gspca_dev->dev;
__u8 notdone; int notdone;
reg_w_riv(dev, req, idx, val); reg_w_riv(dev, req, idx, val);
notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1); notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
reg_w_riv(dev, req, idx, val); reg_w_riv(dev, req, idx, val);
PDEBUG(D_FRAM, "before wait 0x%x", notdone); PDEBUG(D_FRAM, "before wait 0x%04x", notdone);
msleep(200); msleep(200);
notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1); notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
PDEBUG(D_FRAM, "after wait 0x%x", notdone); PDEBUG(D_FRAM, "after wait 0x%04x", notdone);
} }
static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev, static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev,
__u16 req, u8 req,
__u16 idx, __u16 val, __u8 stat, __u8 count) u16 idx, u16 val, u8 stat, u8 count)
{ {
struct usb_device *dev = gspca_dev->dev; struct usb_device *dev = gspca_dev->dev;
__u8 status; int status;
__u8 endcode; u8 endcode;
reg_w_riv(dev, req, idx, val); reg_w_riv(dev, req, idx, val);
status = reg_r_12(gspca_dev, 0x01, 0x0001, 1); status = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
endcode = stat; endcode = stat;
PDEBUG(D_FRAM, "Status 0x%x Need 0x%x", status, stat); PDEBUG(D_FRAM, "Status 0x%x Need 0x%04x", status, stat);
if (!count) if (!count)
return; return;
count = 200; count = 200;
...@@ -641,7 +635,7 @@ static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev, ...@@ -641,7 +635,7 @@ static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev,
/* reg_w_riv(dev, req, idx, val); */ /* reg_w_riv(dev, req, idx, val); */
status = reg_r_12(gspca_dev, 0x01, 0x0001, 1); status = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
if (status == endcode) { if (status == endcode) {
PDEBUG(D_FRAM, "status 0x%x after wait 0x%x", PDEBUG(D_FRAM, "status 0x%04x after wait %d",
status, 200 - count); status, 200 - count);
break; break;
} }
...@@ -668,8 +662,7 @@ static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev) ...@@ -668,8 +662,7 @@ static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev)
while (--count > 0) { while (--count > 0) {
reg_r(gspca_dev, 0x21, 1, 1); reg_r(gspca_dev, 0x21, 1, 1);
if (gspca_dev->usb_buf[0] != 0) { if (gspca_dev->usb_buf[0] != 0) {
gspca_dev->usb_buf[0] = 0; reg_w_1(gspca_dev, 0x21, 0, 1, 0);
reg_w(gspca_dev, 0x21, 0, 1, 1);
reg_r(gspca_dev, 0x21, 1, 1); reg_r(gspca_dev, 0x21, 1, 1);
spca504B_PollingDataReady(gspca_dev); spca504B_PollingDataReady(gspca_dev);
break; break;
...@@ -680,7 +673,7 @@ static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev) ...@@ -680,7 +673,7 @@ static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev)
static void spca50x_GetFirmware(struct gspca_dev *gspca_dev) static void spca50x_GetFirmware(struct gspca_dev *gspca_dev)
{ {
__u8 *data; u8 *data;
data = gspca_dev->usb_buf; data = gspca_dev->usb_buf;
reg_r(gspca_dev, 0x20, 0, 5); reg_r(gspca_dev, 0x20, 0, 5);
...@@ -694,41 +687,34 @@ static void spca504B_SetSizeType(struct gspca_dev *gspca_dev) ...@@ -694,41 +687,34 @@ static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
struct usb_device *dev = gspca_dev->dev; struct usb_device *dev = gspca_dev->dev;
__u8 Size; u8 Size;
__u8 Type;
int rc; int rc;
Size = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; Size = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
Type = 0;
switch (sd->bridge) { switch (sd->bridge) {
case BRIDGE_SPCA533: case BRIDGE_SPCA533:
reg_w(gspca_dev, 0x31, 0, 0, 0); reg_w_riv(dev, 0x31, 0, 0);
spca504B_WaitCmdStatus(gspca_dev); spca504B_WaitCmdStatus(gspca_dev);
rc = spca504B_PollingDataReady(gspca_dev); rc = spca504B_PollingDataReady(gspca_dev);
spca50x_GetFirmware(gspca_dev); spca50x_GetFirmware(gspca_dev);
gspca_dev->usb_buf[0] = 2; /* type */ reg_w_1(gspca_dev, 0x24, 0, 8, 2); /* type */
reg_w(gspca_dev, 0x24, 0, 8, 1);
reg_r(gspca_dev, 0x24, 8, 1); reg_r(gspca_dev, 0x24, 8, 1);
gspca_dev->usb_buf[0] = Size; reg_w_1(gspca_dev, 0x25, 0, 4, Size);
reg_w(gspca_dev, 0x25, 0, 4, 1);
reg_r(gspca_dev, 0x25, 4, 1); /* size */ reg_r(gspca_dev, 0x25, 4, 1); /* size */
rc = spca504B_PollingDataReady(gspca_dev); rc = spca504B_PollingDataReady(gspca_dev);
/* Init the cam width height with some values get on init ? */ /* Init the cam width height with some values get on init ? */
reg_w(gspca_dev, 0x31, 0, 4, 0); reg_w_riv(dev, 0x31, 0, 0x04);
spca504B_WaitCmdStatus(gspca_dev); spca504B_WaitCmdStatus(gspca_dev);
rc = spca504B_PollingDataReady(gspca_dev); rc = spca504B_PollingDataReady(gspca_dev);
break; break;
default: default:
/* case BRIDGE_SPCA504B: */ /* case BRIDGE_SPCA504B: */
/* case BRIDGE_SPCA536: */ /* case BRIDGE_SPCA536: */
gspca_dev->usb_buf[0] = Size; reg_w_1(gspca_dev, 0x25, 0, 4, Size);
reg_w(gspca_dev, 0x25, 0, 4, 1);
reg_r(gspca_dev, 0x25, 4, 1); /* size */ reg_r(gspca_dev, 0x25, 4, 1); /* size */
Type = 6; reg_w_1(gspca_dev, 0x27, 0, 0, 6);
gspca_dev->usb_buf[0] = Type;
reg_w(gspca_dev, 0x27, 0, 0, 1);
reg_r(gspca_dev, 0x27, 0, 1); /* type */ reg_r(gspca_dev, 0x27, 0, 1); /* type */
rc = spca504B_PollingDataReady(gspca_dev); rc = spca504B_PollingDataReady(gspca_dev);
break; break;
...@@ -768,17 +754,51 @@ static void spca504_wait_status(struct gspca_dev *gspca_dev) ...@@ -768,17 +754,51 @@ static void spca504_wait_status(struct gspca_dev *gspca_dev)
static void spca504B_setQtable(struct gspca_dev *gspca_dev) static void spca504B_setQtable(struct gspca_dev *gspca_dev)
{ {
gspca_dev->usb_buf[0] = 3; reg_w_1(gspca_dev, 0x26, 0, 0, 3);
reg_w(gspca_dev, 0x26, 0, 0, 1);
reg_r(gspca_dev, 0x26, 0, 1); reg_r(gspca_dev, 0x26, 0, 1);
spca504B_PollingDataReady(gspca_dev); spca504B_PollingDataReady(gspca_dev);
} }
static void sp5xx_initContBrigHueRegisters(struct gspca_dev *gspca_dev) static void setbrightness(struct gspca_dev *gspca_dev)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
struct usb_device *dev = gspca_dev->dev;
u16 reg;
reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f0 : 0x21a7;
reg_w_riv(dev, 0x00, reg, sd->brightness);
}
static void setcontrast(struct gspca_dev *gspca_dev)
{
struct sd *sd = (struct sd *) gspca_dev;
struct usb_device *dev = gspca_dev->dev;
u16 reg;
reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f1 : 0x21a8;
reg_w_riv(dev, 0x00, reg, sd->contrast);
}
static void setcolors(struct gspca_dev *gspca_dev)
{
struct sd *sd = (struct sd *) gspca_dev;
struct usb_device *dev = gspca_dev->dev;
u16 reg;
reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f6 : 0x21ae;
reg_w_riv(dev, 0x00, reg, sd->colors);
}
static void init_ctl_reg(struct gspca_dev *gspca_dev)
{
struct sd *sd = (struct sd *) gspca_dev;
struct usb_device *dev = gspca_dev->dev;
int pollreg = 1; int pollreg = 1;
setbrightness(gspca_dev);
setcontrast(gspca_dev);
setcolors(gspca_dev);
switch (sd->bridge) { switch (sd->bridge) {
case BRIDGE_SPCA504: case BRIDGE_SPCA504:
case BRIDGE_SPCA504C: case BRIDGE_SPCA504C:
...@@ -787,20 +807,14 @@ static void sp5xx_initContBrigHueRegisters(struct gspca_dev *gspca_dev) ...@@ -787,20 +807,14 @@ static void sp5xx_initContBrigHueRegisters(struct gspca_dev *gspca_dev)
default: default:
/* case BRIDGE_SPCA533: */ /* case BRIDGE_SPCA533: */
/* case BRIDGE_SPCA504B: */ /* case BRIDGE_SPCA504B: */
reg_w(gspca_dev, 0, 0, 0x21a7, 0); /* brightness */ reg_w_riv(dev, 0, 0x00, 0x21ad); /* hue */
reg_w(gspca_dev, 0, 0x20, 0x21a8, 0); /* contrast */ reg_w_riv(dev, 0, 0x01, 0x21ac); /* sat/hue */
reg_w(gspca_dev, 0, 0, 0x21ad, 0); /* hue */ reg_w_riv(dev, 0, 0x00, 0x21a3); /* gamma */
reg_w(gspca_dev, 0, 1, 0x21ac, 0); /* sat/hue */
reg_w(gspca_dev, 0, 0x20, 0x21ae, 0); /* saturation */
reg_w(gspca_dev, 0, 0, 0x21a3, 0); /* gamma */
break; break;
case BRIDGE_SPCA536: case BRIDGE_SPCA536:
reg_w(gspca_dev, 0, 0, 0x20f0, 0); reg_w_riv(dev, 0, 0x40, 0x20f5);
reg_w(gspca_dev, 0, 0x21, 0x20f1, 0); reg_w_riv(dev, 0, 0x01, 0x20f4);
reg_w(gspca_dev, 0, 0x40, 0x20f5, 0); reg_w_riv(dev, 0, 0x00, 0x2089);
reg_w(gspca_dev, 0, 1, 0x20f4, 0);
reg_w(gspca_dev, 0, 0x40, 0x20f6, 0);
reg_w(gspca_dev, 0, 0, 0x2089, 0);
break; break;
} }
if (pollreg) if (pollreg)
...@@ -855,9 +869,10 @@ static int sd_config(struct gspca_dev *gspca_dev, ...@@ -855,9 +869,10 @@ static int sd_config(struct gspca_dev *gspca_dev,
cam->nmodes = ARRAY_SIZE(vga_mode2); cam->nmodes = ARRAY_SIZE(vga_mode2);
break; break;
} }
sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; sd->brightness = BRIGHTNESS_DEF;
sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value; sd->contrast = CONTRAST_DEF;
sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value; sd->colors = COLOR_DEF;
sd->autogain = AUTOGAIN_DEF;
sd->quality = QUALITY_DEF; sd->quality = QUALITY_DEF;
return 0; return 0;
} }
...@@ -867,32 +882,29 @@ static int sd_init(struct gspca_dev *gspca_dev) ...@@ -867,32 +882,29 @@ static int sd_init(struct gspca_dev *gspca_dev)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
struct usb_device *dev = gspca_dev->dev; struct usb_device *dev = gspca_dev->dev;
int rc; int i, err_code;
__u8 i; u8 info[6];
__u8 info[6];
int err_code;
switch (sd->bridge) { switch (sd->bridge) {
case BRIDGE_SPCA504B: case BRIDGE_SPCA504B:
reg_w(gspca_dev, 0x1d, 0, 0, 0); reg_w_riv(dev, 0x1d, 0x00, 0);
reg_w(gspca_dev, 0, 1, 0x2306, 0); reg_w_riv(dev, 0, 0x01, 0x2306);
reg_w(gspca_dev, 0, 0, 0x0d04, 0); reg_w_riv(dev, 0, 0x00, 0x0d04);
reg_w(gspca_dev, 0, 0, 0x2000, 0); reg_w_riv(dev, 0, 0x00, 0x2000);
reg_w(gspca_dev, 0, 0x13, 0x2301, 0); reg_w_riv(dev, 0, 0x13, 0x2301);
reg_w(gspca_dev, 0, 0, 0x2306, 0); reg_w_riv(dev, 0, 0x00, 0x2306);
/* fall thru */ /* fall thru */
case BRIDGE_SPCA533: case BRIDGE_SPCA533:
rc = spca504B_PollingDataReady(gspca_dev); spca504B_PollingDataReady(gspca_dev);
spca50x_GetFirmware(gspca_dev); spca50x_GetFirmware(gspca_dev);
break; break;
case BRIDGE_SPCA536: case BRIDGE_SPCA536:
spca50x_GetFirmware(gspca_dev); spca50x_GetFirmware(gspca_dev);
reg_r(gspca_dev, 0x00, 0x5002, 1); reg_r(gspca_dev, 0x00, 0x5002, 1);
gspca_dev->usb_buf[0] = 0; reg_w_1(gspca_dev, 0x24, 0, 0, 0);
reg_w(gspca_dev, 0x24, 0, 0, 1);
reg_r(gspca_dev, 0x24, 0, 1); reg_r(gspca_dev, 0x24, 0, 1);
rc = spca504B_PollingDataReady(gspca_dev); spca504B_PollingDataReady(gspca_dev);
reg_w(gspca_dev, 0x34, 0, 0, 0); reg_w_riv(dev, 0x34, 0, 0);
spca504B_WaitCmdStatus(gspca_dev); spca504B_WaitCmdStatus(gspca_dev);
break; break;
case BRIDGE_SPCA504C: /* pccam600 */ case BRIDGE_SPCA504C: /* pccam600 */
...@@ -902,12 +914,13 @@ static int sd_init(struct gspca_dev *gspca_dev) ...@@ -902,12 +914,13 @@ static int sd_init(struct gspca_dev *gspca_dev)
spca504_wait_status(gspca_dev); spca504_wait_status(gspca_dev);
if (sd->subtype == LogitechClickSmart420) if (sd->subtype == LogitechClickSmart420)
write_vector(gspca_dev, write_vector(gspca_dev,
spca504A_clicksmart420_open_data); spca504A_clicksmart420_open_data,
ARRAY_SIZE(spca504A_clicksmart420_open_data));
else else
write_vector(gspca_dev, spca504_pccam600_open_data); write_vector(gspca_dev, spca504_pccam600_open_data,
ARRAY_SIZE(spca504_pccam600_open_data));
err_code = spca50x_setup_qtable(gspca_dev, err_code = spca50x_setup_qtable(gspca_dev,
0x00, 0x2800, qtable_creative_pccam);
0x2840, qtable_creative_pccam);
if (err_code < 0) { if (err_code < 0) {
PDEBUG(D_ERR|D_STREAM, "spca50x_setup_qtable failed"); PDEBUG(D_ERR|D_STREAM, "spca50x_setup_qtable failed");
return err_code; return err_code;
...@@ -945,8 +958,8 @@ static int sd_init(struct gspca_dev *gspca_dev) ...@@ -945,8 +958,8 @@ static int sd_init(struct gspca_dev *gspca_dev)
6, 0, 0x86, 1); */ 6, 0, 0x86, 1); */
/* spca504A_acknowledged_command (gspca_dev, 0x24, /* spca504A_acknowledged_command (gspca_dev, 0x24,
0, 0, 0x9D, 1); */ 0, 0, 0x9D, 1); */
reg_w_riv(dev, 0x0, 0x270c, 0x05); /* L92 sno1t.txt */ reg_w_riv(dev, 0x00, 0x270c, 0x05); /* L92 sno1t.txt */
reg_w_riv(dev, 0x0, 0x2310, 0x05); reg_w_riv(dev, 0x00, 0x2310, 0x05);
spca504A_acknowledged_command(gspca_dev, 0x01, spca504A_acknowledged_command(gspca_dev, 0x01,
0x0f, 0, 0xff, 0); 0x0f, 0, 0xff, 0);
} }
...@@ -954,8 +967,6 @@ static int sd_init(struct gspca_dev *gspca_dev) ...@@ -954,8 +967,6 @@ static int sd_init(struct gspca_dev *gspca_dev)
reg_w_riv(dev, 0, 0x2000, 0); reg_w_riv(dev, 0, 0x2000, 0);
reg_w_riv(dev, 0, 0x2883, 1); reg_w_riv(dev, 0, 0x2883, 1);
err_code = spca50x_setup_qtable(gspca_dev, err_code = spca50x_setup_qtable(gspca_dev,
0x00, 0x2800,
0x2840,
qtable_spca504_default); qtable_spca504_default);
if (err_code < 0) { if (err_code < 0) {
PDEBUG(D_ERR, "spca50x_setup_qtable failed"); PDEBUG(D_ERR, "spca50x_setup_qtable failed");
...@@ -970,10 +981,9 @@ static int sd_start(struct gspca_dev *gspca_dev) ...@@ -970,10 +981,9 @@ static int sd_start(struct gspca_dev *gspca_dev)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
struct usb_device *dev = gspca_dev->dev; struct usb_device *dev = gspca_dev->dev;
int rc;
int enable; int enable;
__u8 i; int i;
__u8 info[6]; u8 info[6];
/* create the JPEG header */ /* create the JPEG header */
sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL); sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
...@@ -991,17 +1001,20 @@ static int sd_start(struct gspca_dev *gspca_dev) ...@@ -991,17 +1001,20 @@ static int sd_start(struct gspca_dev *gspca_dev)
/* case BRIDGE_SPCA504B: */ /* case BRIDGE_SPCA504B: */
/* case BRIDGE_SPCA533: */ /* case BRIDGE_SPCA533: */
/* case BRIDGE_SPCA536: */ /* case BRIDGE_SPCA536: */
if (sd->subtype == MegapixV4 || switch (sd->subtype) {
sd->subtype == LogitechClickSmart820 || case MegapixV4:
sd->subtype == MegaImageVI) { case LogitechClickSmart820:
reg_w(gspca_dev, 0xf0, 0, 0, 0); case MegaImageVI:
reg_w_riv(dev, 0xf0, 0, 0);
spca504B_WaitCmdStatus(gspca_dev); spca504B_WaitCmdStatus(gspca_dev);
reg_r(gspca_dev, 0xf0, 4, 0); reg_r(gspca_dev, 0xf0, 4, 0);
spca504B_WaitCmdStatus(gspca_dev); spca504B_WaitCmdStatus(gspca_dev);
} else { break;
reg_w(gspca_dev, 0x31, 0, 4, 0); default:
reg_w_riv(dev, 0x31, 0, 0x04);
spca504B_WaitCmdStatus(gspca_dev); spca504B_WaitCmdStatus(gspca_dev);
rc = spca504B_PollingDataReady(gspca_dev); spca504B_PollingDataReady(gspca_dev);
break;
} }
break; break;
case BRIDGE_SPCA504: case BRIDGE_SPCA504:
...@@ -1035,15 +1048,17 @@ static int sd_start(struct gspca_dev *gspca_dev) ...@@ -1035,15 +1048,17 @@ static int sd_start(struct gspca_dev *gspca_dev)
spca504_acknowledged_command(gspca_dev, 0x24, 0, 0); spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
} }
spca504B_SetSizeType(gspca_dev); spca504B_SetSizeType(gspca_dev);
reg_w_riv(dev, 0x0, 0x270c, 0x05); /* L92 sno1t.txt */ reg_w_riv(dev, 0x00, 0x270c, 0x05); /* L92 sno1t.txt */
reg_w_riv(dev, 0x0, 0x2310, 0x05); reg_w_riv(dev, 0x00, 0x2310, 0x05);
break; break;
case BRIDGE_SPCA504C: case BRIDGE_SPCA504C:
if (sd->subtype == LogitechClickSmart420) { if (sd->subtype == LogitechClickSmart420) {
write_vector(gspca_dev, write_vector(gspca_dev,
spca504A_clicksmart420_init_data); spca504A_clicksmart420_init_data,
ARRAY_SIZE(spca504A_clicksmart420_init_data));
} else { } else {
write_vector(gspca_dev, spca504_pccam600_init_data); write_vector(gspca_dev, spca504_pccam600_init_data,
ARRAY_SIZE(spca504_pccam600_init_data));
} }
enable = (sd->autogain ? 0x04 : 0x01); enable = (sd->autogain ? 0x04 : 0x01);
reg_w_riv(dev, 0x0c, 0x0000, enable); /* auto exposure */ reg_w_riv(dev, 0x0c, 0x0000, enable); /* auto exposure */
...@@ -1055,7 +1070,7 @@ static int sd_start(struct gspca_dev *gspca_dev) ...@@ -1055,7 +1070,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
spca504B_SetSizeType(gspca_dev); spca504B_SetSizeType(gspca_dev);
break; break;
} }
sp5xx_initContBrigHueRegisters(gspca_dev); init_ctl_reg(gspca_dev);
return 0; return 0;
} }
...@@ -1069,7 +1084,7 @@ static void sd_stopN(struct gspca_dev *gspca_dev) ...@@ -1069,7 +1084,7 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
/* case BRIDGE_SPCA533: */ /* case BRIDGE_SPCA533: */
/* case BRIDGE_SPCA536: */ /* case BRIDGE_SPCA536: */
/* case BRIDGE_SPCA504B: */ /* case BRIDGE_SPCA504B: */
reg_w(gspca_dev, 0x31, 0, 0, 0); reg_w_riv(dev, 0x31, 0, 0);
spca504B_WaitCmdStatus(gspca_dev); spca504B_WaitCmdStatus(gspca_dev);
spca504B_PollingDataReady(gspca_dev); spca504B_PollingDataReady(gspca_dev);
break; break;
...@@ -1087,7 +1102,7 @@ static void sd_stopN(struct gspca_dev *gspca_dev) ...@@ -1087,7 +1102,7 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
0x0f, 0x00, 0xff, 1); 0x0f, 0x00, 0xff, 1);
} else { } else {
spca504_acknowledged_command(gspca_dev, 0x24, 0, 0); spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
reg_w_riv(dev, 0x01, 0x000f, 0x00); reg_w_riv(dev, 0x01, 0x000f, 0x0000);
} }
break; break;
} }
...@@ -1102,12 +1117,12 @@ static void sd_stop0(struct gspca_dev *gspca_dev) ...@@ -1102,12 +1117,12 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
static void sd_pkt_scan(struct gspca_dev *gspca_dev, static void sd_pkt_scan(struct gspca_dev *gspca_dev,
struct gspca_frame *frame, /* target */ struct gspca_frame *frame, /* target */
__u8 *data, /* isoc packet */ u8 *data, /* isoc packet */
int len) /* iso packet length */ int len) /* iso packet length */
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
int i, sof = 0; int i, sof = 0;
static unsigned char ffd9[] = {0xff, 0xd9}; static u8 ffd9[] = {0xff, 0xd9};
/* frames are jpeg 4.1.1 without 0xff escape */ /* frames are jpeg 4.1.1 without 0xff escape */
switch (sd->bridge) { switch (sd->bridge) {
...@@ -1195,63 +1210,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, ...@@ -1195,63 +1210,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len); gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
} }
static void setbrightness(struct gspca_dev *gspca_dev)
{
struct sd *sd = (struct sd *) gspca_dev;
struct usb_device *dev = gspca_dev->dev;
switch (sd->bridge) {
default:
/* case BRIDGE_SPCA533: */
/* case BRIDGE_SPCA504B: */
/* case BRIDGE_SPCA504: */
/* case BRIDGE_SPCA504C: */
reg_w_riv(dev, 0x0, 0x21a7, sd->brightness);
break;
case BRIDGE_SPCA536:
reg_w_riv(dev, 0x0, 0x20f0, sd->brightness);
break;
}
}
static void setcontrast(struct gspca_dev *gspca_dev)
{
struct sd *sd = (struct sd *) gspca_dev;
struct usb_device *dev = gspca_dev->dev;
switch (sd->bridge) {
default:
/* case BRIDGE_SPCA533: */
/* case BRIDGE_SPCA504B: */
/* case BRIDGE_SPCA504: */
/* case BRIDGE_SPCA504C: */
reg_w_riv(dev, 0x0, 0x21a8, sd->contrast);
break;
case BRIDGE_SPCA536:
reg_w_riv(dev, 0x0, 0x20f1, sd->contrast);
break;
}
}
static void setcolors(struct gspca_dev *gspca_dev)
{
struct sd *sd = (struct sd *) gspca_dev;
struct usb_device *dev = gspca_dev->dev;
switch (sd->bridge) {
default:
/* case BRIDGE_SPCA533: */
/* case BRIDGE_SPCA504B: */
/* case BRIDGE_SPCA504: */
/* case BRIDGE_SPCA504C: */
reg_w_riv(dev, 0x0, 0x21ae, sd->colors);
break;
case BRIDGE_SPCA536:
reg_w_riv(dev, 0x0, 0x20f6, sd->colors);
break;
}
}
static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment