mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-12 05:06:39 +07:00
[media] sunplus: convert to the control framework
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
parent
74dec79714
commit
ed5cd6bbde
@ -34,15 +34,13 @@ 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 */
|
||||||
|
|
||||||
s8 brightness;
|
struct v4l2_ctrl *jpegqual;
|
||||||
u8 contrast;
|
|
||||||
u8 colors;
|
|
||||||
u8 autogain;
|
|
||||||
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
|
||||||
|
|
||||||
|
bool autogain;
|
||||||
|
|
||||||
u8 bridge;
|
u8 bridge;
|
||||||
#define BRIDGE_SPCA504 0
|
#define BRIDGE_SPCA504 0
|
||||||
#define BRIDGE_SPCA504B 1
|
#define BRIDGE_SPCA504B 1
|
||||||
@ -59,75 +57,6 @@ struct sd {
|
|||||||
u8 jpeg_hdr[JPEG_HDR_SZ];
|
u8 jpeg_hdr[JPEG_HDR_SZ];
|
||||||
};
|
};
|
||||||
|
|
||||||
/* 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_setcolors(struct gspca_dev *gspca_dev, __s32 val);
|
|
||||||
static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
|
|
||||||
static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
|
|
||||||
static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
|
|
||||||
|
|
||||||
static const struct ctrl sd_ctrls[] = {
|
|
||||||
{
|
|
||||||
{
|
|
||||||
.id = V4L2_CID_BRIGHTNESS,
|
|
||||||
.type = V4L2_CTRL_TYPE_INTEGER,
|
|
||||||
.name = "Brightness",
|
|
||||||
.minimum = -128,
|
|
||||||
.maximum = 127,
|
|
||||||
.step = 1,
|
|
||||||
#define BRIGHTNESS_DEF 0
|
|
||||||
.default_value = BRIGHTNESS_DEF,
|
|
||||||
},
|
|
||||||
.set = sd_setbrightness,
|
|
||||||
.get = sd_getbrightness,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
{
|
|
||||||
.id = V4L2_CID_CONTRAST,
|
|
||||||
.type = V4L2_CTRL_TYPE_INTEGER,
|
|
||||||
.name = "Contrast",
|
|
||||||
.minimum = 0,
|
|
||||||
.maximum = 0xff,
|
|
||||||
.step = 1,
|
|
||||||
#define CONTRAST_DEF 0x20
|
|
||||||
.default_value = CONTRAST_DEF,
|
|
||||||
},
|
|
||||||
.set = sd_setcontrast,
|
|
||||||
.get = sd_getcontrast,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
{
|
|
||||||
.id = V4L2_CID_SATURATION,
|
|
||||||
.type = V4L2_CTRL_TYPE_INTEGER,
|
|
||||||
.name = "Color",
|
|
||||||
.minimum = 0,
|
|
||||||
.maximum = 0xff,
|
|
||||||
.step = 1,
|
|
||||||
#define COLOR_DEF 0x1a
|
|
||||||
.default_value = COLOR_DEF,
|
|
||||||
},
|
|
||||||
.set = sd_setcolors,
|
|
||||||
.get = sd_getcolors,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
{
|
|
||||||
.id = V4L2_CID_AUTOGAIN,
|
|
||||||
.type = V4L2_CTRL_TYPE_BOOLEAN,
|
|
||||||
.name = "Auto Gain",
|
|
||||||
.minimum = 0,
|
|
||||||
.maximum = 1,
|
|
||||||
.step = 1,
|
|
||||||
#define AUTOGAIN_DEF 1
|
|
||||||
.default_value = AUTOGAIN_DEF,
|
|
||||||
},
|
|
||||||
.set = sd_setautogain,
|
|
||||||
.get = sd_getautogain,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct v4l2_pix_format vga_mode[] = {
|
static const struct v4l2_pix_format vga_mode[] = {
|
||||||
{320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
|
{320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
|
||||||
.bytesperline = 320,
|
.bytesperline = 320,
|
||||||
@ -597,31 +526,31 @@ static void spca504B_setQtable(struct gspca_dev *gspca_dev)
|
|||||||
spca504B_PollingDataReady(gspca_dev);
|
spca504B_PollingDataReady(gspca_dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setbrightness(struct gspca_dev *gspca_dev)
|
static void setbrightness(struct gspca_dev *gspca_dev, s32 val)
|
||||||
{
|
{
|
||||||
struct sd *sd = (struct sd *) gspca_dev;
|
struct sd *sd = (struct sd *) gspca_dev;
|
||||||
u16 reg;
|
u16 reg;
|
||||||
|
|
||||||
reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f0 : 0x21a7;
|
reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f0 : 0x21a7;
|
||||||
reg_w_riv(gspca_dev, 0x00, reg, sd->brightness);
|
reg_w_riv(gspca_dev, 0x00, reg, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setcontrast(struct gspca_dev *gspca_dev)
|
static void setcontrast(struct gspca_dev *gspca_dev, s32 val)
|
||||||
{
|
{
|
||||||
struct sd *sd = (struct sd *) gspca_dev;
|
struct sd *sd = (struct sd *) gspca_dev;
|
||||||
u16 reg;
|
u16 reg;
|
||||||
|
|
||||||
reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f1 : 0x21a8;
|
reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f1 : 0x21a8;
|
||||||
reg_w_riv(gspca_dev, 0x00, reg, sd->contrast);
|
reg_w_riv(gspca_dev, 0x00, reg, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setcolors(struct gspca_dev *gspca_dev)
|
static void setcolors(struct gspca_dev *gspca_dev, s32 val)
|
||||||
{
|
{
|
||||||
struct sd *sd = (struct sd *) gspca_dev;
|
struct sd *sd = (struct sd *) gspca_dev;
|
||||||
u16 reg;
|
u16 reg;
|
||||||
|
|
||||||
reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f6 : 0x21ae;
|
reg = sd->bridge == BRIDGE_SPCA536 ? 0x20f6 : 0x21ae;
|
||||||
reg_w_riv(gspca_dev, 0x00, reg, sd->colors);
|
reg_w_riv(gspca_dev, 0x00, reg, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_ctl_reg(struct gspca_dev *gspca_dev)
|
static void init_ctl_reg(struct gspca_dev *gspca_dev)
|
||||||
@ -629,9 +558,7 @@ static void init_ctl_reg(struct gspca_dev *gspca_dev)
|
|||||||
struct sd *sd = (struct sd *) gspca_dev;
|
struct sd *sd = (struct sd *) gspca_dev;
|
||||||
int pollreg = 1;
|
int pollreg = 1;
|
||||||
|
|
||||||
setbrightness(gspca_dev);
|
v4l2_ctrl_handler_setup(&gspca_dev->ctrl_handler);
|
||||||
setcontrast(gspca_dev);
|
|
||||||
setcolors(gspca_dev);
|
|
||||||
|
|
||||||
switch (sd->bridge) {
|
switch (sd->bridge) {
|
||||||
case BRIDGE_SPCA504:
|
case BRIDGE_SPCA504:
|
||||||
@ -704,11 +631,6 @@ 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 = BRIGHTNESS_DEF;
|
|
||||||
sd->contrast = CONTRAST_DEF;
|
|
||||||
sd->colors = COLOR_DEF;
|
|
||||||
sd->autogain = AUTOGAIN_DEF;
|
|
||||||
sd->quality = QUALITY_DEF;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -807,7 +729,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
|
|||||||
/* create the JPEG header */
|
/* create the JPEG header */
|
||||||
jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
|
jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
|
||||||
0x22); /* JPEG 411 */
|
0x22); /* JPEG 411 */
|
||||||
jpeg_set_qual(sd->jpeg_hdr, sd->quality);
|
jpeg_set_qual(sd->jpeg_hdr, v4l2_ctrl_g_ctrl(sd->jpegqual));
|
||||||
|
|
||||||
if (sd->bridge == BRIDGE_SPCA504B)
|
if (sd->bridge == BRIDGE_SPCA504B)
|
||||||
spca504B_setQtable(gspca_dev);
|
spca504B_setQtable(gspca_dev);
|
||||||
@ -1012,90 +934,13 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
|
|||||||
gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
|
gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
|
|
||||||
{
|
|
||||||
struct sd *sd = (struct sd *) gspca_dev;
|
|
||||||
|
|
||||||
sd->brightness = val;
|
|
||||||
if (gspca_dev->streaming)
|
|
||||||
setbrightness(gspca_dev);
|
|
||||||
return gspca_dev->usb_err;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
struct sd *sd = (struct sd *) gspca_dev;
|
|
||||||
|
|
||||||
sd->contrast = val;
|
|
||||||
if (gspca_dev->streaming)
|
|
||||||
setcontrast(gspca_dev);
|
|
||||||
return gspca_dev->usb_err;
|
|
||||||
}
|
|
||||||
|
|
||||||
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_setcolors(struct gspca_dev *gspca_dev, __s32 val)
|
|
||||||
{
|
|
||||||
struct sd *sd = (struct sd *) gspca_dev;
|
|
||||||
|
|
||||||
sd->colors = val;
|
|
||||||
if (gspca_dev->streaming)
|
|
||||||
setcolors(gspca_dev);
|
|
||||||
return gspca_dev->usb_err;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
|
|
||||||
{
|
|
||||||
struct sd *sd = (struct sd *) gspca_dev;
|
|
||||||
|
|
||||||
*val = sd->colors;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
|
|
||||||
{
|
|
||||||
struct sd *sd = (struct sd *) gspca_dev;
|
|
||||||
|
|
||||||
sd->autogain = val;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
|
|
||||||
{
|
|
||||||
struct sd *sd = (struct sd *) gspca_dev;
|
|
||||||
|
|
||||||
*val = sd->autogain;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int sd_set_jcomp(struct gspca_dev *gspca_dev,
|
static int sd_set_jcomp(struct gspca_dev *gspca_dev,
|
||||||
struct v4l2_jpegcompression *jcomp)
|
struct v4l2_jpegcompression *jcomp)
|
||||||
{
|
{
|
||||||
struct sd *sd = (struct sd *) gspca_dev;
|
struct sd *sd = (struct sd *) gspca_dev;
|
||||||
|
|
||||||
if (jcomp->quality < QUALITY_MIN)
|
v4l2_ctrl_s_ctrl(sd->jpegqual, jcomp->quality);
|
||||||
sd->quality = QUALITY_MIN;
|
return 0;
|
||||||
else if (jcomp->quality > QUALITY_MAX)
|
|
||||||
sd->quality = QUALITY_MAX;
|
|
||||||
else
|
|
||||||
sd->quality = jcomp->quality;
|
|
||||||
if (gspca_dev->streaming)
|
|
||||||
jpeg_set_qual(sd->jpeg_hdr, sd->quality);
|
|
||||||
return gspca_dev->usb_err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sd_get_jcomp(struct gspca_dev *gspca_dev,
|
static int sd_get_jcomp(struct gspca_dev *gspca_dev,
|
||||||
@ -1104,19 +949,79 @@ static int sd_get_jcomp(struct gspca_dev *gspca_dev,
|
|||||||
struct sd *sd = (struct sd *) gspca_dev;
|
struct sd *sd = (struct sd *) gspca_dev;
|
||||||
|
|
||||||
memset(jcomp, 0, sizeof *jcomp);
|
memset(jcomp, 0, sizeof *jcomp);
|
||||||
jcomp->quality = sd->quality;
|
jcomp->quality = v4l2_ctrl_g_ctrl(sd->jpegqual);
|
||||||
jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
|
jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
|
||||||
| V4L2_JPEG_MARKER_DQT;
|
| V4L2_JPEG_MARKER_DQT;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
|
||||||
|
{
|
||||||
|
struct gspca_dev *gspca_dev =
|
||||||
|
container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
|
||||||
|
struct sd *sd = (struct sd *)gspca_dev;
|
||||||
|
|
||||||
|
gspca_dev->usb_err = 0;
|
||||||
|
|
||||||
|
if (!gspca_dev->streaming)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
switch (ctrl->id) {
|
||||||
|
case V4L2_CID_BRIGHTNESS:
|
||||||
|
setbrightness(gspca_dev, ctrl->val);
|
||||||
|
break;
|
||||||
|
case V4L2_CID_CONTRAST:
|
||||||
|
setcontrast(gspca_dev, ctrl->val);
|
||||||
|
break;
|
||||||
|
case V4L2_CID_SATURATION:
|
||||||
|
setcolors(gspca_dev, ctrl->val);
|
||||||
|
break;
|
||||||
|
case V4L2_CID_AUTOGAIN:
|
||||||
|
sd->autogain = ctrl->val;
|
||||||
|
break;
|
||||||
|
case V4L2_CID_JPEG_COMPRESSION_QUALITY:
|
||||||
|
jpeg_set_qual(sd->jpeg_hdr, ctrl->val);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return gspca_dev->usb_err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct v4l2_ctrl_ops sd_ctrl_ops = {
|
||||||
|
.s_ctrl = sd_s_ctrl,
|
||||||
|
};
|
||||||
|
|
||||||
|
static int sd_init_controls(struct gspca_dev *gspca_dev)
|
||||||
|
{
|
||||||
|
struct sd *sd = (struct sd *)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, -128, 127, 1, 0);
|
||||||
|
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
|
||||||
|
V4L2_CID_CONTRAST, 0, 255, 1, 0x20);
|
||||||
|
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
|
||||||
|
V4L2_CID_SATURATION, 0, 255, 1, 0x1a);
|
||||||
|
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
|
||||||
|
V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
|
||||||
|
sd->jpegqual = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
|
||||||
|
V4L2_CID_JPEG_COMPRESSION_QUALITY,
|
||||||
|
QUALITY_MIN, QUALITY_MAX, 1, QUALITY_DEF);
|
||||||
|
|
||||||
|
if (hdl->error) {
|
||||||
|
pr_err("Could not initialize controls\n");
|
||||||
|
return hdl->error;
|
||||||
|
}
|
||||||
|
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,
|
||||||
.pkt_scan = sd_pkt_scan,
|
.pkt_scan = sd_pkt_scan,
|
||||||
|
Loading…
Reference in New Issue
Block a user