Commit 1bdee422 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] gspca-konica: convert to the control framework

Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent bfaab899
...@@ -50,107 +50,8 @@ struct sd { ...@@ -50,107 +50,8 @@ struct sd {
struct gspca_dev gspca_dev; /* !! must be the first item */ struct gspca_dev gspca_dev; /* !! must be the first item */
struct urb *last_data_urb; struct urb *last_data_urb;
u8 snapshot_pressed; u8 snapshot_pressed;
u8 brightness;
u8 contrast;
u8 saturation;
u8 whitebal;
u8 sharpness;
}; };
/* V4L2 controls supported by the driver */
static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setsaturation(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getsaturation(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setwhitebal(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getwhitebal(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
static const struct ctrl sd_ctrls[] = {
#define SD_BRIGHTNESS 0
{
{
.id = V4L2_CID_BRIGHTNESS,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "Brightness",
.minimum = 0,
.maximum = 9,
.step = 1,
#define BRIGHTNESS_DEFAULT 4
.default_value = BRIGHTNESS_DEFAULT,
.flags = 0,
},
.set = sd_setbrightness,
.get = sd_getbrightness,
},
#define SD_CONTRAST 1
{
{
.id = V4L2_CID_CONTRAST,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "Contrast",
.minimum = 0,
.maximum = 9,
.step = 4,
#define CONTRAST_DEFAULT 10
.default_value = CONTRAST_DEFAULT,
.flags = 0,
},
.set = sd_setcontrast,
.get = sd_getcontrast,
},
#define SD_SATURATION 2
{
{
.id = V4L2_CID_SATURATION,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "Saturation",
.minimum = 0,
.maximum = 9,
.step = 1,
#define SATURATION_DEFAULT 4
.default_value = SATURATION_DEFAULT,
.flags = 0,
},
.set = sd_setsaturation,
.get = sd_getsaturation,
},
#define SD_WHITEBAL 3
{
{
.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "White Balance",
.minimum = 0,
.maximum = 33,
.step = 1,
#define WHITEBAL_DEFAULT 25
.default_value = WHITEBAL_DEFAULT,
.flags = 0,
},
.set = sd_setwhitebal,
.get = sd_getwhitebal,
},
#define SD_SHARPNESS 4
{
{
.id = V4L2_CID_SHARPNESS,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "Sharpness",
.minimum = 0,
.maximum = 9,
.step = 1,
#define SHARPNESS_DEFAULT 4
.default_value = SHARPNESS_DEFAULT,
.flags = 0,
},
.set = sd_setsharpness,
.get = sd_getsharpness,
},
};
/* .priv is what goes to register 8 for this mode, known working values: /* .priv is what goes to register 8 for this mode, known working values:
0x00 -> 176x144, cropped 0x00 -> 176x144, cropped
...@@ -242,18 +143,10 @@ static void konica_stream_off(struct gspca_dev *gspca_dev) ...@@ -242,18 +143,10 @@ static void konica_stream_off(struct gspca_dev *gspca_dev)
static int sd_config(struct gspca_dev *gspca_dev, static int sd_config(struct gspca_dev *gspca_dev,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
struct sd *sd = (struct sd *) gspca_dev;
gspca_dev->cam.cam_mode = vga_mode; gspca_dev->cam.cam_mode = vga_mode;
gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode); gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode);
gspca_dev->cam.no_urb_create = 1; gspca_dev->cam.no_urb_create = 1;
sd->brightness = BRIGHTNESS_DEFAULT;
sd->contrast = CONTRAST_DEFAULT;
sd->saturation = SATURATION_DEFAULT;
sd->whitebal = WHITEBAL_DEFAULT;
sd->sharpness = SHARPNESS_DEFAULT;
return 0; return 0;
} }
...@@ -289,12 +182,6 @@ static int sd_start(struct gspca_dev *gspca_dev) ...@@ -289,12 +182,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize); packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
reg_w(gspca_dev, sd->brightness, BRIGHTNESS_REG);
reg_w(gspca_dev, sd->whitebal, WHITEBAL_REG);
reg_w(gspca_dev, sd->contrast, CONTRAST_REG);
reg_w(gspca_dev, sd->saturation, SATURATION_REG);
reg_w(gspca_dev, sd->sharpness, SHARPNESS_REG);
n = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; n = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
reg_w(gspca_dev, n, 0x08); reg_w(gspca_dev, n, 0x08);
...@@ -479,125 +366,82 @@ static void sd_isoc_irq(struct urb *urb) ...@@ -479,125 +366,82 @@ static void sd_isoc_irq(struct urb *urb)
pr_err("usb_submit_urb(status_urb) ret %d\n", st); pr_err("usb_submit_urb(status_urb) ret %d\n", st);
} }
static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct gspca_dev *gspca_dev =
container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
sd->brightness = val;
if (gspca_dev->streaming) {
konica_stream_off(gspca_dev);
reg_w(gspca_dev, sd->brightness, BRIGHTNESS_REG);
konica_stream_on(gspca_dev);
}
return 0; gspca_dev->usb_err = 0;
}
static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->brightness;
return 0;
}
static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) if (!gspca_dev->streaming)
{ return 0;
struct sd *sd = (struct sd *) gspca_dev;
sd->contrast = val; switch (ctrl->id) {
if (gspca_dev->streaming) { case V4L2_CID_BRIGHTNESS:
konica_stream_off(gspca_dev); konica_stream_off(gspca_dev);
reg_w(gspca_dev, sd->contrast, CONTRAST_REG); reg_w(gspca_dev, ctrl->val, BRIGHTNESS_REG);
konica_stream_on(gspca_dev); konica_stream_on(gspca_dev);
} break;
case V4L2_CID_CONTRAST:
return 0;
}
static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->contrast;
return 0;
}
static int sd_setsaturation(struct gspca_dev *gspca_dev, __s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->saturation = val;
if (gspca_dev->streaming) {
konica_stream_off(gspca_dev); konica_stream_off(gspca_dev);
reg_w(gspca_dev, sd->saturation, SATURATION_REG); reg_w(gspca_dev, ctrl->val, CONTRAST_REG);
konica_stream_on(gspca_dev); konica_stream_on(gspca_dev);
} break;
return 0; case V4L2_CID_SATURATION:
}
static int sd_getsaturation(struct gspca_dev *gspca_dev, __s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->saturation;
return 0;
}
static int sd_setwhitebal(struct gspca_dev *gspca_dev, __s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->whitebal = val;
if (gspca_dev->streaming) {
konica_stream_off(gspca_dev); konica_stream_off(gspca_dev);
reg_w(gspca_dev, sd->whitebal, WHITEBAL_REG); reg_w(gspca_dev, ctrl->val, SATURATION_REG);
konica_stream_on(gspca_dev); konica_stream_on(gspca_dev);
} break;
return 0; case V4L2_CID_WHITE_BALANCE_TEMPERATURE:
}
static int sd_getwhitebal(struct gspca_dev *gspca_dev, __s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->whitebal;
return 0;
}
static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->sharpness = val;
if (gspca_dev->streaming) {
konica_stream_off(gspca_dev); konica_stream_off(gspca_dev);
reg_w(gspca_dev, sd->sharpness, SHARPNESS_REG); reg_w(gspca_dev, ctrl->val, WHITEBAL_REG);
konica_stream_on(gspca_dev); konica_stream_on(gspca_dev);
break;
case V4L2_CID_SHARPNESS:
konica_stream_off(gspca_dev);
reg_w(gspca_dev, ctrl->val, SHARPNESS_REG);
konica_stream_on(gspca_dev);
break;
} }
return 0; return gspca_dev->usb_err;
} }
static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val) static const struct v4l2_ctrl_ops sd_ctrl_ops = {
{ .s_ctrl = sd_s_ctrl,
struct sd *sd = (struct sd *) gspca_dev; };
*val = sd->sharpness;
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, 5);
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_BRIGHTNESS, 0, 9, 1, 4);
/* Needs to be verified */
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_CONTRAST, 0, 9, 1, 4);
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_SATURATION, 0, 9, 1, 4);
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_WHITE_BALANCE_TEMPERATURE,
0, 33, 1, 25);
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_SHARPNESS, 0, 9, 1, 4);
if (hdl->error) {
pr_err("Could not initialize controls\n");
return hdl->error;
}
return 0; return 0;
} }
/* sub-driver description */ /* sub-driver description */
static const struct sd_desc sd_desc = { static const struct sd_desc sd_desc = {
.name = MODULE_NAME, .name = MODULE_NAME,
.ctrls = sd_ctrls,
.nctrls = ARRAY_SIZE(sd_ctrls),
.config = sd_config, .config = sd_config,
.init = sd_init, .init = sd_init,
.init_controls = sd_init_controls,
.start = sd_start, .start = sd_start,
.stopN = sd_stopN, .stopN = sd_stopN,
#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
......
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