diff mbox

[2/2,media] ov7670: Allow configuration of night mode

Message ID 1294697907-1714-3-git-send-email-rralcala@gmail.com (mailing list archive)
State RFC
Headers show

Commit Message

Roberto Rodriguez Alkala Jan. 10, 2011, 10:18 p.m. UTC
None
diff mbox

Patch

diff --git a/drivers/media/video/ov7670.c b/drivers/media/video/ov7670.c
index c881a64..cfe96e5 100644
--- a/drivers/media/video/ov7670.c
+++ b/drivers/media/video/ov7670.c
@@ -1255,6 +1255,36 @@  static int ov7670_s_gain(struct v4l2_subdev *sd, int value)
 }
 
 /*
+ * Get or Set Night Mode.
+ */
+static int ov7670_g_nightmode(struct v4l2_subdev *sd, __s32 *value)
+{
+	int ret;
+	unsigned char com11;
+
+	ret = ov7670_read(sd, REG_COM11, &com11);
+	*value = (com11 & COM11_NIGHT) != 0;
+	return ret;
+}
+
+static int ov7670_s_nightmode(struct v4l2_subdev *sd, int value)
+{
+	int ret;
+	unsigned char com11;
+
+	ret = ov7670_read(sd, REG_COM11, &com11);
+	if (ret == 0) {
+		if (value)
+			com11 |= COM11_NIGHT;
+		else
+			com11 &= ~COM11_NIGHT;
+		ret = ov7670_write(sd, REG_COM11, com11);
+	}
+	return ret;
+}
+
+
+/*
  * Tweak autogain.
  */
 static int ov7670_g_autogain(struct v4l2_subdev *sd, __s32 *value)
@@ -1382,6 +1412,8 @@  static int ov7670_queryctrl(struct v4l2_subdev *sd,
 		return v4l2_ctrl_query_fill(qc, 0, 65535, 1, 500);
 	case V4L2_CID_EXPOSURE_AUTO:
 		return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
+	case V4L2_CID_NIGHT_MODE:
+		return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
 	}
 	return -EINVAL;
 }
@@ -1409,6 +1441,8 @@  static int ov7670_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
 		return ov7670_g_exp(sd, &ctrl->value);
 	case V4L2_CID_EXPOSURE_AUTO:
 		return ov7670_g_autoexp(sd, &ctrl->value);
+	case V4L2_CID_NIGHT_MODE:
+		return ov7670_g_nightmode(sd, &ctrl->value);
 	}
 	return -EINVAL;
 }
@@ -1437,6 +1471,8 @@  static int ov7670_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
 	case V4L2_CID_EXPOSURE_AUTO:
 		return ov7670_s_autoexp(sd,
 				(enum v4l2_exposure_auto_type) ctrl->value);
+	case V4L2_CID_NIGHT_MODE:
+		return ov7670_s_nightmode(sd, ctrl->value);
 	}
 	return -EINVAL;
 }