Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 306320
b: refs/heads/master
c: dec9c51
h: refs/heads/master
v: v3
  • Loading branch information
Hans Verkuil authored and Mauro Carvalho Chehab committed May 14, 2012
1 parent 1e39f71 commit 439195c
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 712 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7135d88495b0043c0d61bd85408542dc0cb0bca0
refs/heads/master: dec9c51442b5a524c137b6f4a54ec109a197a65a
18 changes: 16 additions & 2 deletions trunk/drivers/media/video/gspca/stv06xx/stv06xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,17 @@ static int stv06xx_init(struct gspca_dev *gspca_dev)
return (err < 0) ? err : 0;
}

/* this function is called at probe time */
static int stv06xx_init_controls(struct gspca_dev *gspca_dev)
{
struct sd *sd = (struct sd *) gspca_dev;

PDEBUG(D_PROBE, "Initializing controls");

gspca_dev->vdev.ctrl_handler = &sd->ctrl_handler;
return sd->sensor->init_controls(sd);
}

/* Start the camera */
static int stv06xx_start(struct gspca_dev *gspca_dev)
{
Expand Down Expand Up @@ -512,6 +523,7 @@ static const struct sd_desc sd_desc = {
.name = MODULE_NAME,
.config = stv06xx_config,
.init = stv06xx_init,
.init_controls = stv06xx_init_controls,
.start = stv06xx_start,
.stopN = stv06xx_stopN,
.pkt_scan = stv06xx_pkt_scan,
Expand Down Expand Up @@ -594,11 +606,12 @@ static void sd_disconnect(struct usb_interface *intf)
{
struct gspca_dev *gspca_dev = usb_get_intfdata(intf);
struct sd *sd = (struct sd *) gspca_dev;
void *priv = sd->sensor_priv;
PDEBUG(D_PROBE, "Disconnecting the stv06xx device");

if (sd->sensor->disconnect)
sd->sensor->disconnect(sd);
sd->sensor = NULL;
gspca_disconnect(intf);
kfree(priv);
}

static struct usb_driver sd_driver = {
Expand All @@ -609,6 +622,7 @@ static struct usb_driver sd_driver = {
#ifdef CONFIG_PM
.suspend = gspca_suspend,
.resume = gspca_resume,
.reset_resume = gspca_resume,
#endif
};

Expand Down
3 changes: 3 additions & 0 deletions trunk/drivers/media/video/gspca/stv06xx/stv06xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ struct sd {
/* A pointer to the currently connected sensor */
const struct stv06xx_sensor *sensor;

/* Control handler */
struct v4l2_ctrl_handler ctrl_handler;

/* A pointer to the sd_desc struct */
struct sd_desc desc;

Expand Down
142 changes: 34 additions & 108 deletions trunk/drivers/media/video/gspca/stv06xx/stv06xx_hdcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,6 @@

#include "stv06xx_hdcs.h"

static const struct ctrl hdcs1x00_ctrl[] = {
{
{
.id = V4L2_CID_EXPOSURE,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "exposure",
.minimum = 0x00,
.maximum = 0xff,
.step = 0x1,
.default_value = HDCS_DEFAULT_EXPOSURE,
.flags = V4L2_CTRL_FLAG_SLIDER
},
.set = hdcs_set_exposure,
.get = hdcs_get_exposure
}, {
{
.id = V4L2_CID_GAIN,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "gain",
.minimum = 0x00,
.maximum = 0xff,
.step = 0x1,
.default_value = HDCS_DEFAULT_GAIN,
.flags = V4L2_CTRL_FLAG_SLIDER
},
.set = hdcs_set_gain,
.get = hdcs_get_gain
}
};

static struct v4l2_pix_format hdcs1x00_mode[] = {
{
HDCS_1X00_DEF_WIDTH,
Expand All @@ -76,36 +46,6 @@ static struct v4l2_pix_format hdcs1x00_mode[] = {
}
};

static const struct ctrl hdcs1020_ctrl[] = {
{
{
.id = V4L2_CID_EXPOSURE,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "exposure",
.minimum = 0x00,
.maximum = 0xffff,
.step = 0x1,
.default_value = HDCS_DEFAULT_EXPOSURE,
.flags = V4L2_CTRL_FLAG_SLIDER
},
.set = hdcs_set_exposure,
.get = hdcs_get_exposure
}, {
{
.id = V4L2_CID_GAIN,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "gain",
.minimum = 0x00,
.maximum = 0xff,
.step = 0x1,
.default_value = HDCS_DEFAULT_GAIN,
.flags = V4L2_CTRL_FLAG_SLIDER
},
.set = hdcs_set_gain,
.get = hdcs_get_gain
}
};

static struct v4l2_pix_format hdcs1020_mode[] = {
{
HDCS_1020_DEF_WIDTH,
Expand Down Expand Up @@ -150,7 +90,6 @@ struct hdcs {
} exp;

int psmp;
u8 exp_cache, gain_cache;
};

static int hdcs_reg_write_seq(struct sd *sd, u8 reg, u8 *vals, u8 len)
Expand Down Expand Up @@ -232,16 +171,6 @@ static int hdcs_reset(struct sd *sd)
return err;
}

static int hdcs_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
struct hdcs *hdcs = sd->sensor_priv;

*val = hdcs->exp_cache;

return 0;
}

static int hdcs_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
Expand All @@ -260,9 +189,6 @@ static int hdcs_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
int cycles, err;
u8 exp[14];

val &= 0xff;
hdcs->exp_cache = val;

cycles = val * HDCS_CLK_FREQ_MHZ * 257;

ct = hdcs->exp.cto + hdcs->psmp + (HDCS_ADC_START_SIG_DUR + 2);
Expand Down Expand Up @@ -336,12 +262,9 @@ static int hdcs_set_exposure(struct gspca_dev *gspca_dev, __s32 val)

static int hdcs_set_gains(struct sd *sd, u8 g)
{
struct hdcs *hdcs = sd->sensor_priv;
int err;
u8 gains[4];

hdcs->gain_cache = g;

/* the voltage gain Av = (1 + 19 * val / 127) * (1 + bit7) */
if (g > 127)
g = 0x80 | (g / 2);
Expand All @@ -352,17 +275,7 @@ static int hdcs_set_gains(struct sd *sd, u8 g)
gains[3] = g;

err = hdcs_reg_write_seq(sd, HDCS_ERECPGA, gains, 4);
return err;
}

static int hdcs_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
struct hdcs *hdcs = sd->sensor_priv;

*val = hdcs->gain_cache;

return 0;
return err;
}

static int hdcs_set_gain(struct gspca_dev *gspca_dev, __s32 val)
Expand Down Expand Up @@ -420,6 +333,38 @@ static int hdcs_set_size(struct sd *sd,
return err;
}

static int hdcs_s_ctrl(struct v4l2_ctrl *ctrl)
{
struct sd *sd = container_of(ctrl->handler, struct sd, ctrl_handler);
int err = -EINVAL;

switch (ctrl->id) {
case V4L2_CID_GAIN:
err = hdcs_set_gain(&sd->gspca_dev, ctrl->val);
break;
case V4L2_CID_EXPOSURE:
err = hdcs_set_exposure(&sd->gspca_dev, ctrl->val);
break;
}
return err;
}

static const struct v4l2_ctrl_ops hdcs_ctrl_ops = {
.s_ctrl = hdcs_s_ctrl,
};

static int hdcs_init_controls(struct sd *sd)
{
struct v4l2_ctrl_handler *hdl = &sd->ctrl_handler;

v4l2_ctrl_handler_init(hdl, 2);
v4l2_ctrl_new_std(hdl, &hdcs_ctrl_ops,
V4L2_CID_EXPOSURE, 0, 0xff, 1, HDCS_DEFAULT_EXPOSURE);
v4l2_ctrl_new_std(hdl, &hdcs_ctrl_ops,
V4L2_CID_GAIN, 0, 0xff, 1, HDCS_DEFAULT_GAIN);
return hdl->error;
}

static int hdcs_probe_1x00(struct sd *sd)
{
struct hdcs *hdcs;
Expand All @@ -434,8 +379,6 @@ static int hdcs_probe_1x00(struct sd *sd)

sd->gspca_dev.cam.cam_mode = hdcs1x00_mode;
sd->gspca_dev.cam.nmodes = ARRAY_SIZE(hdcs1x00_mode);
sd->desc.ctrls = hdcs1x00_ctrl;
sd->desc.nctrls = ARRAY_SIZE(hdcs1x00_ctrl);

hdcs = kmalloc(sizeof(struct hdcs), GFP_KERNEL);
if (!hdcs)
Expand Down Expand Up @@ -493,8 +436,6 @@ static int hdcs_probe_1020(struct sd *sd)

sd->gspca_dev.cam.cam_mode = hdcs1020_mode;
sd->gspca_dev.cam.nmodes = ARRAY_SIZE(hdcs1020_mode);
sd->desc.ctrls = hdcs1020_ctrl;
sd->desc.nctrls = ARRAY_SIZE(hdcs1020_ctrl);

hdcs = kmalloc(sizeof(struct hdcs), GFP_KERNEL);
if (!hdcs)
Expand Down Expand Up @@ -537,12 +478,6 @@ static int hdcs_stop(struct sd *sd)
return hdcs_set_state(sd, HDCS_STATE_SLEEP);
}

static void hdcs_disconnect(struct sd *sd)
{
PDEBUG(D_PROBE, "Disconnecting the sensor");
kfree(sd->sensor_priv);
}

static int hdcs_init(struct sd *sd)
{
struct hdcs *hdcs = sd->sensor_priv;
Expand Down Expand Up @@ -587,16 +522,7 @@ static int hdcs_init(struct sd *sd)
if (err < 0)
return err;

err = hdcs_set_gains(sd, HDCS_DEFAULT_GAIN);
if (err < 0)
return err;

err = hdcs_set_size(sd, hdcs->array.width, hdcs->array.height);
if (err < 0)
return err;

err = hdcs_set_exposure(&sd->gspca_dev, HDCS_DEFAULT_EXPOSURE);
return err;
return hdcs_set_size(sd, hdcs->array.width, hdcs->array.height);
}

static int hdcs_dump(struct sd *sd)
Expand Down
7 changes: 3 additions & 4 deletions trunk/drivers/media/video/gspca/stv06xx/stv06xx_hdcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,12 @@ static int hdcs_probe_1x00(struct sd *sd);
static int hdcs_probe_1020(struct sd *sd);
static int hdcs_start(struct sd *sd);
static int hdcs_init(struct sd *sd);
static int hdcs_init_controls(struct sd *sd);
static int hdcs_stop(struct sd *sd);
static int hdcs_dump(struct sd *sd);
static void hdcs_disconnect(struct sd *sd);

static int hdcs_get_exposure(struct gspca_dev *gspca_dev, __s32 *val);
static int hdcs_set_exposure(struct gspca_dev *gspca_dev, __s32 val);
static int hdcs_set_gain(struct gspca_dev *gspca_dev, __s32 val);
static int hdcs_get_gain(struct gspca_dev *gspca_dev, __s32 *val);

const struct stv06xx_sensor stv06xx_sensor_hdcs1x00 = {
.name = "HP HDCS-1000/1100",
Expand All @@ -152,10 +150,10 @@ const struct stv06xx_sensor stv06xx_sensor_hdcs1x00 = {
.max_packet_size = { 847 },

.init = hdcs_init,
.init_controls = hdcs_init_controls,
.probe = hdcs_probe_1x00,
.start = hdcs_start,
.stop = hdcs_stop,
.disconnect = hdcs_disconnect,
.dump = hdcs_dump,
};

Expand All @@ -171,6 +169,7 @@ const struct stv06xx_sensor stv06xx_sensor_hdcs1020 = {
.max_packet_size = { 847 },

.init = hdcs_init,
.init_controls = hdcs_init_controls,
.probe = hdcs_probe_1020,
.start = hdcs_start,
.stop = hdcs_stop,
Expand Down
Loading

0 comments on commit 439195c

Please sign in to comment.