diff options
Diffstat (limited to 'drivers/media/video/gspca/vicam.c')
-rw-r--r-- | drivers/media/video/gspca/vicam.c | 68 |
1 files changed, 27 insertions, 41 deletions
diff --git a/drivers/media/video/gspca/vicam.c b/drivers/media/video/gspca/vicam.c index 15a30f7..b1a64b9 100644 --- a/drivers/media/video/gspca/vicam.c +++ b/drivers/media/video/gspca/vicam.c @@ -44,17 +44,10 @@ MODULE_DESCRIPTION("GSPCA ViCam USB Camera Driver"); MODULE_LICENSE("GPL"); MODULE_FIRMWARE(VICAM_FIRMWARE); -enum e_ctrl { - GAIN, - EXPOSURE, - NCTRL /* number of controls */ -}; - struct sd { struct gspca_dev gspca_dev; /* !! must be the first item */ struct work_struct work_struct; struct workqueue_struct *work_thread; - struct gspca_ctrl ctrls[NCTRL]; }; /* The vicam sensor has a resolution of 512 x 244, with I believe square @@ -86,31 +79,6 @@ static struct v4l2_pix_format vicam_mode[] = { .colorspace = V4L2_COLORSPACE_SRGB,}, }; -static const struct ctrl sd_ctrls[] = { -[GAIN] = { - { - .id = V4L2_CID_GAIN, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "Gain", - .minimum = 0, - .maximum = 255, - .step = 1, - .default_value = 200, - }, - }, -[EXPOSURE] = { - { - .id = V4L2_CID_EXPOSURE, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "Exposure", - .minimum = 0, - .maximum = 2047, - .step = 1, - .default_value = 256, - }, - }, -}; - static int vicam_control_msg(struct gspca_dev *gspca_dev, u8 request, u16 value, u16 index, u8 *data, u16 len) { @@ -146,12 +114,13 @@ static int vicam_set_camera_power(struct gspca_dev *gspca_dev, int state) */ static int vicam_read_frame(struct gspca_dev *gspca_dev, u8 *data, int size) { - struct sd *sd = (struct sd *)gspca_dev; int ret, unscaled_height, act_len = 0; u8 *req_data = gspca_dev->usb_buf; + s32 expo = v4l2_ctrl_g_ctrl(gspca_dev->exposure); + s32 gain = v4l2_ctrl_g_ctrl(gspca_dev->gain); memset(req_data, 0, 16); - req_data[0] = sd->ctrls[GAIN].val; + req_data[0] = gain; if (gspca_dev->width == 256) req_data[1] |= 0x01; /* low nibble x-scale */ if (gspca_dev->height <= 122) { @@ -167,9 +136,9 @@ static int vicam_read_frame(struct gspca_dev *gspca_dev, u8 *data, int size) else /* Up to 244 lines with req_data[3] == 0x08 */ req_data[3] = 0x08; /* vend? */ - if (sd->ctrls[EXPOSURE].val < 256) { + if (expo < 256) { /* Frame rate maxed out, use partial frame expo time */ - req_data[4] = 255 - sd->ctrls[EXPOSURE].val; + req_data[4] = 255 - expo; req_data[5] = 0x00; req_data[6] = 0x00; req_data[7] = 0x01; @@ -177,8 +146,8 @@ static int vicam_read_frame(struct gspca_dev *gspca_dev, u8 *data, int size) /* Modify frame rate */ req_data[4] = 0x00; req_data[5] = 0x00; - req_data[6] = sd->ctrls[EXPOSURE].val & 0xFF; - req_data[7] = sd->ctrls[EXPOSURE].val >> 8; + req_data[6] = expo & 0xFF; + req_data[7] = expo >> 8; } req_data[8] = ((244 - unscaled_height) / 2) & ~0x01; /* vstart */ /* bytes 9-15 do not seem to affect exposure or image quality */ @@ -260,7 +229,6 @@ static int sd_config(struct gspca_dev *gspca_dev, cam->bulk_size = 64; cam->cam_mode = vicam_mode; cam->nmodes = ARRAY_SIZE(vicam_mode); - cam->ctrls = sd->ctrls; INIT_WORK(&sd->work_struct, vicam_dostream); @@ -335,6 +303,24 @@ static void sd_stop0(struct gspca_dev *gspca_dev) vicam_set_camera_power(gspca_dev, 0); } +static int sd_init_controls(struct gspca_dev *gspca_dev) +{ + struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; + + gspca_dev->vdev.ctrl_handler = hdl; + v4l2_ctrl_handler_init(hdl, 2); + gspca_dev->exposure = v4l2_ctrl_new_std(hdl, NULL, + V4L2_CID_EXPOSURE, 0, 2047, 1, 256); + gspca_dev->gain = v4l2_ctrl_new_std(hdl, NULL, + V4L2_CID_GAIN, 0, 255, 1, 200); + + if (hdl->error) { + pr_err("Could not initialize controls\n"); + return hdl->error; + } + return 0; +} + /* Table of supported USB devices */ static const struct usb_device_id device_table[] = { {USB_DEVICE(0x04c1, 0x009d)}, @@ -347,10 +333,9 @@ MODULE_DEVICE_TABLE(usb, device_table); /* sub-driver description */ static const struct sd_desc sd_desc = { .name = MODULE_NAME, - .ctrls = sd_ctrls, - .nctrls = ARRAY_SIZE(sd_ctrls), .config = sd_config, .init = sd_init, + .init_controls = sd_init_controls, .start = sd_start, .stop0 = sd_stop0, }; @@ -373,6 +358,7 @@ static struct usb_driver sd_driver = { #ifdef CONFIG_PM .suspend = gspca_suspend, .resume = gspca_resume, + .reset_resume = gspca_resume, #endif }; |