Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b014f94b authored by Jean-Francois Moine's avatar Jean-Francois Moine Committed by Mauro Carvalho Chehab
Browse files

V4L/DVB (13423): gspca - ov534: More ov772x changes from Max Thrun.

parent 189d92af
Loading
Loading
Loading
Loading
+197 −8
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@
 * https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/
 *
 * PS3 Eye camera enhanced by Richard Kaswy http://kaswy.free.fr
 * PS3 Eye camera, brightness, contrast, hue, AWB control added
 *	by Max Thrun <bear24rw@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
@@ -53,11 +55,16 @@ struct sd {
	__u32 last_pts;
	u16 last_fid;
	u8 frame_rate;

	u8 brightness;
	u8 contrast;
	u8 gain;
	u8 exposure;
	u8 redblc;
	u8 blueblc;
	u8 hue;
	u8 autogain;
	u8 awb;
	u8 sharpness;
	u8 hflip;
	u8 vflip;
@@ -84,8 +91,44 @@ static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val);
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 struct ctrl sd_ctrls_ov772x[] = {
    {
	{
		.id      = V4L2_CID_BRIGHTNESS,
		.type    = V4L2_CTRL_TYPE_INTEGER,
		.name    = "Brightness",
		.minimum = 0,
		.maximum = 255,
		.step    = 1,
#define BRIGHTNESS_DEF 20
		.default_value = BRIGHTNESS_DEF,
	},
	.set = sd_setbrightness,
	.get = sd_getbrightness,
    },
    {
	{
		.id      = V4L2_CID_CONTRAST,
		.type    = V4L2_CTRL_TYPE_INTEGER,
		.name    = "Contrast",
		.minimum = 0,
		.maximum = 255,
		.step    = 1,
#define CONTRAST_DEF 37
		.default_value = CONTRAST_DEF,
	},
	.set = sd_setcontrast,
	.get = sd_getcontrast,
    },
    {
	{
	    .id      = V4L2_CID_GAIN,
@@ -108,7 +151,7 @@ static struct ctrl sd_ctrls_ov772x[] = {
	    .minimum = 0,
	    .maximum = 255,
	    .step    = 1,
#define EXPO_DEF 255
#define EXPO_DEF 120
	    .default_value = EXPO_DEF,
	},
	.set = sd_setexposure,
@@ -142,6 +185,20 @@ static struct ctrl sd_ctrls_ov772x[] = {
	.set = sd_setblueblc,
	.get = sd_getblueblc,
    },
    {
	{
		.id      = V4L2_CID_HUE,
		.type    = V4L2_CTRL_TYPE_INTEGER,
		.name    = "Hue",
		.minimum = 0,
		.maximum = 255,
		.step    = 1,
#define HUE_DEF 143
		.default_value = HUE_DEF,
	},
	.set = sd_sethue,
	.get = sd_gethue,
    },
    {
	{
	    .id      = V4L2_CID_AUTOGAIN,
@@ -150,12 +207,26 @@ static struct ctrl sd_ctrls_ov772x[] = {
	    .minimum = 0,
	    .maximum = 1,
	    .step    = 1,
#define AUTOGAIN_DEF 1
#define AUTOGAIN_DEF 0
	    .default_value = AUTOGAIN_DEF,
	},
	.set = sd_setautogain,
	.get = sd_getautogain,
    },
    {
	{
		.id      = V4L2_CID_AUTO_WHITE_BALANCE,
		.type    = V4L2_CTRL_TYPE_BOOLEAN,
		.name    = "Auto White Balance",
		.minimum = 0,
		.maximum = 1,
		.step    = 1,
#define AWB_DEF 0
		.default_value = AWB_DEF,
	},
	.set = sd_setawb,
	.get = sd_getawb,
    },
    {
	{
	    .id      = V4L2_CID_SHARPNESS,
@@ -164,7 +235,7 @@ static struct ctrl sd_ctrls_ov772x[] = {
	    .minimum = 0,
	    .maximum = 63,
	    .step    = 1,
#define SHARPNESS_DEF 4
#define SHARPNESS_DEF 0
	    .default_value = SHARPNESS_DEF,
	},
	.set = sd_setsharpness,
@@ -206,7 +277,7 @@ static const struct v4l2_pix_format vga_yuyv_mode[] = {
	{320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
	 .bytesperline = 320 * 2,
	 .sizeimage = 320 * 240 * 2,
	 .colorspace = V4L2_COLORSPACE_JPEG,
	 .colorspace = V4L2_COLORSPACE_SRGB,
	 .priv = 1},
	{640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
	 .bytesperline = 640 * 2,
@@ -311,10 +382,10 @@ static const u8 sensor_init_ov772x[][2] = {
	{ 0x65, 0x20 },
	{ 0x11, 0x01 },
	{ 0x42, 0x7f },
	{ 0x63, 0xaa },		/* was e0 */
	{ 0x63, 0xaa },		/* AWB - was e0 */
	{ 0x64, 0xff },
	{ 0x66, 0x00 },
	{ 0x13, 0xf0 },
	{ 0x13, 0xf0 },		/* com8 */
	{ 0x0d, 0x41 },
	{ 0x0f, 0xc5 },
	{ 0x14, 0x11 },
@@ -327,7 +398,7 @@ static const u8 sensor_init_ov772x[][2] = {
	{ 0x2a, 0x00 },
	{ 0x2b, 0x00 },
	{ 0x6b, 0xaa },
	{ 0x13, 0xff },
	{ 0x13, 0xff },		/* AWB */

	{ 0x90, 0x05 },
	{ 0x91, 0x01 },
@@ -375,7 +446,7 @@ static const u8 sensor_init_ov772x[][2] = {
	{ 0x14, 0x41 },
	{ 0x0e, 0xcd },
	{ 0xac, 0xbf },
	{ 0x8e, 0x00 },
	{ 0x8e, 0x00 },		/* De-noise threshold */
	{ 0x0c, 0xd0 }
};
static const u8 bridge_start_ov772x_vga[][2] = {
@@ -397,6 +468,7 @@ static const u8 sensor_start_ov772x_vga[][2] = {
	{0x1a, 0xf0},
	{0x29, 0xa0},
	{0x2c, 0xf0},
	{0x65, 0x20},
};
static const u8 bridge_start_ov772x_qvga[][2] = {
	{0x1c, 0x00},
@@ -417,6 +489,7 @@ static const u8 sensor_start_ov772x_qvga[][2] = {
	{0x1a, 0x78},
	{0x29, 0x50},
	{0x2c, 0x78},
	{0x65, 0x2f},
};

static const u8 bridge_init_ov965x[][2] = {
@@ -1000,6 +1073,20 @@ static void ov534_set_frame_rate(struct gspca_dev *gspca_dev)
}

/* ov772x controls */
static void setbrightness(struct gspca_dev *gspca_dev)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sccb_reg_write(gspca_dev, 0x9B, sd->brightness);
}

static void setcontrast(struct gspca_dev *gspca_dev)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sccb_reg_write(gspca_dev, 0x9C, sd->contrast);
}

static void setgain(struct gspca_dev *gspca_dev)
{
	struct sd *sd = (struct sd *) gspca_dev;
@@ -1051,6 +1138,13 @@ static void setblueblc(struct gspca_dev *gspca_dev)
	sccb_reg_write(gspca_dev, 0x42, sd->blueblc);
}

static void sethue(struct gspca_dev *gspca_dev)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sccb_reg_write(gspca_dev, 0x01, sd->hue);
}

static void setautogain(struct gspca_dev *gspca_dev)
{
	struct sd *sd = (struct sd *) gspca_dev;
@@ -1066,6 +1160,16 @@ static void setautogain(struct gspca_dev *gspca_dev)
	}
}

static void setawb(struct gspca_dev *gspca_dev)
{
	struct sd *sd = (struct sd *) gspca_dev;

	if (sd->awb)
		sccb_reg_write(gspca_dev, 0x63, 0xe0);	/* AWB on */
	else
		sccb_reg_write(gspca_dev, 0x63, 0xaa);	/* AWB off */
}

static void setsharpness(struct gspca_dev *gspca_dev)
{
	struct sd *sd = (struct sd *) gspca_dev;
@@ -1124,11 +1228,20 @@ static int sd_config(struct gspca_dev *gspca_dev,
	}

	sd->frame_rate = 30;

	sd->brightness = BRIGHTNESS_DEF;
	sd->contrast = CONTRAST_DEF;
	sd->gain = GAIN_DEF;
	sd->exposure = EXPO_DEF;
	sd->redblc = RED_BALANCE_DEF;
	sd->blueblc = BLUE_BALANCE_DEF;
	sd->hue = HUE_DEF;
#if AUTOGAIN_DEF != 0
	sd->autogain = AUTOGAIN_DEF;
#endif
#if AWB_DEF != 0
	sd->awb = AWB_DEF
#endif
	sd->sharpness = SHARPNESS_DEF;
#if HFLIP_DEF != 0
	sd->hflip = HFLIP_DEF;
@@ -1219,10 +1332,14 @@ static int sd_start_ov772x(struct gspca_dev *gspca_dev)
	ov534_set_frame_rate(gspca_dev);

	setautogain(gspca_dev);
	setawb(gspca_dev);
	setgain(gspca_dev);
	setredblc(gspca_dev);
	setblueblc(gspca_dev);
	sethue(gspca_dev);
	setexposure(gspca_dev);
	setbrightness(gspca_dev);
	setcontrast(gspca_dev);
	setsharpness(gspca_dev);
	setvflip(gspca_dev);
	sethflip(gspca_dev);
@@ -1395,6 +1512,42 @@ static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
	return 0;
}

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)
		setcontrast(gspca_dev);
	return 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)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sd->contrast = val;
	if (gspca_dev->streaming)
		setcontrast(gspca_dev);
	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_setredblc(struct gspca_dev *gspca_dev, __s32 val)
{
	struct sd *sd = (struct sd *) gspca_dev;
@@ -1431,6 +1584,24 @@ static int sd_getblueblc(struct gspca_dev *gspca_dev, __s32 *val)
	return 0;
}

static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sd->hue = val;
	if (gspca_dev->streaming)
		sethue(gspca_dev);
	return 0;
}

static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	*val = sd->hue;
	return 0;
}

static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
{
	struct sd *sd = (struct sd *) gspca_dev;
@@ -1449,6 +1620,24 @@ static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
	return 0;
}

static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	sd->awb = val;
	if (gspca_dev->streaming)
		setawb(gspca_dev);
	return 0;
}

static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val)
{
	struct sd *sd = (struct sd *) gspca_dev;

	*val = sd->awb;
	return 0;
}

static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
{
	struct sd *sd = (struct sd *) gspca_dev;