From patchwork Fri Nov 24 14:40:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10074145 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D0EF360375 for ; Fri, 24 Nov 2017 14:41:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF6242A36B for ; Fri, 24 Nov 2017 14:41:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B36FD2A371; Fri, 24 Nov 2017 14:41:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 505682A36B for ; Fri, 24 Nov 2017 14:41:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753819AbdKXOlN (ORCPT ); Fri, 24 Nov 2017 09:41:13 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:42950 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753771AbdKXOlM (ORCPT ); Fri, 24 Nov 2017 09:41:12 -0500 Received: by mail-pl0-f65.google.com with SMTP id z3so4561987plh.9 for ; Fri, 24 Nov 2017 06:41:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AqIiFz3gh/6tEwNt7tfBLHrbboqge62mxo+IDO/6K8Q=; b=UQU/3pj5w45kYvA6ACvW4U1l0ioY4YjqvobomgFAsDkjemSEaK13JQjmAT4RQnC61d ZbJSciyqLuPbvnLxetW8NGaOobDEOAfxA3QJqO66fnKr/XtMka5ZSg+ublHqChxwZAlc H1PH6PSLCsbBCFo6VMCqXg6k9CSK6MPpwtjoQp5VG16g3Re7obqaP1EI/bo3MOJXv0H1 isFMoq11ft98Zgy3eAGDvoenXxurrN2hXbq+U6COnWvMcpcCqU47gFPJVFkXfQRqOTi4 usjJ7jEez/ArAfa1zsYAQnKXn21HqoXMowpHvhu4a8QIav9Aohj7zwqwxAriDe2ZFjCv QDJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AqIiFz3gh/6tEwNt7tfBLHrbboqge62mxo+IDO/6K8Q=; b=QLpmX9Nar63Pf+KnldCa4jjO3f+bNpVYTZO/DM7MACoyOW+UfjvalAbPLlW0RdUYCX k/1e/HyVh8TAgPrzSyJGFNsqnaAPGku1+1j2Yc97hOp0x9ByerYHIAbkluickWTN6/Dt pDg3b7y4k1eA1FqyPhL+jyVR4r1OjEgXEwIq0VGAtUkuozU5FTblSJQZgMP7smRCHIyc LdDu3zFgrOBGfjZwMx437LwinVl0jcwpg3uxg+wF4sIHcA4P1QDZzVqQGiwbPyku2Neh emNdgpOFsWsM9sUq9+5kg8zEoPmgkjiTQ02Xag2XsquJXHeA4yWbdNM8Z+DbMCVtqdyf oLpw== X-Gm-Message-State: AJaThX754IQxGTB9Y0XW1tYP8zXz3sys2p9EreskH7eC4dYZFLZs037j nmlVpBWSHDmCQYpy5UanUuAyUg== X-Google-Smtp-Source: AGs4zMblEuSxA6A5VfzjTbrQ0LvilKRrhtOJIm3tcWpi2IN6Xzo9jftYzCJvYGzWPU1J6bogFCyG/A== X-Received: by 10.84.143.70 with SMTP id 64mr11321619ply.277.1511534471538; Fri, 24 Nov 2017 06:41:11 -0800 (PST) Received: from localhost.localdomain ([240f:4:c2bc:1:b949:9c60:f832:e9c5]) by smtp.gmail.com with ESMTPSA id g9sm35616912pfk.0.2017.11.24.06.41.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Nov 2017 06:41:10 -0800 (PST) From: Akinobu Mita To: linux-media@vger.kernel.org Cc: Akinobu Mita , Jonathan Corbet , Sakari Ailus , Mauro Carvalho Chehab Subject: [PATCH] media: ov7670: add V4L2_CID_TEST_PATTERN control Date: Fri, 24 Nov 2017 23:40:45 +0900 Message-Id: <1511534445-30512-2-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511534445-30512-1-git-send-email-akinobu.mita@gmail.com> References: <1511534445-30512-1-git-send-email-akinobu.mita@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The ov7670 has the test pattern generator features. This makes use of it through V4L2_CID_TEST_PATTERN control. Cc: Jonathan Corbet Cc: Sakari Ailus Cc: Mauro Carvalho Chehab Signed-off-by: Akinobu Mita --- drivers/media/i2c/ov7670.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c index b61d88e..c6c32f6 100644 --- a/drivers/media/i2c/ov7670.c +++ b/drivers/media/i2c/ov7670.c @@ -163,6 +163,11 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)"); #define DBLV_X6 0x10 /* clock x6 */ #define DBLV_X8 0x11 /* clock x8 */ +#define REG_SCALING_XSC 0x70 /* Test pattern and horizontal scale factor */ +#define TEST_PATTTERN_0 0x80 +#define REG_SCALING_YSC 0x71 /* Test pattern and vertical scale factor */ +#define TEST_PATTTERN_1 0x80 + #define REG_REG76 0x76 /* OV's name */ #define R76_BLKPCOR 0x80 /* Black pixel correction enable */ #define R76_WHTPCOR 0x40 /* White pixel correction enable */ @@ -292,7 +297,8 @@ static struct regval_list ov7670_default_regs[] = { { REG_COM3, 0 }, { REG_COM14, 0 }, /* Mystery scaling numbers */ - { 0x70, 0x3a }, { 0x71, 0x35 }, + { REG_SCALING_XSC, 0x3a }, + { REG_SCALING_YSC, 0x35 }, { 0x72, 0x11 }, { 0x73, 0xf0 }, { 0xa2, 0x02 }, { REG_COM10, 0x0 }, @@ -568,6 +574,19 @@ static int ov7670_write(struct v4l2_subdev *sd, unsigned char reg, return ov7670_write_i2c(sd, reg, value); } +static int ov7670_update_bits(struct v4l2_subdev *sd, unsigned char reg, + unsigned char mask, unsigned char value) +{ + unsigned char orig; + int ret; + + ret = ov7670_read(sd, reg, &orig); + if (ret) + return ret; + + return ov7670_write(sd, reg, (orig & ~mask) | (value & mask)); +} + /* * Write a list of register settings; ff/ff stops the process. */ @@ -1470,6 +1489,25 @@ static int ov7670_s_autoexp(struct v4l2_subdev *sd, return ret; } +static const char * const ov7670_test_pattern_menu[] = { + "No test output", + "Shifting \"1\"", + "8-bar color bar", + "Fade to gray color bar", +}; + +static int ov7670_s_test_pattern(struct v4l2_subdev *sd, int value) +{ + int ret; + + ret = ov7670_update_bits(sd, REG_SCALING_XSC, TEST_PATTTERN_0, + value & BIT(0) ? TEST_PATTTERN_0 : 0); + if (ret) + return ret; + + return ov7670_update_bits(sd, REG_SCALING_YSC, TEST_PATTTERN_1, + value & BIT(1) ? TEST_PATTTERN_1 : 0); +} static int ov7670_g_volatile_ctrl(struct v4l2_ctrl *ctrl) { @@ -1516,6 +1554,8 @@ static int ov7670_s_ctrl(struct v4l2_ctrl *ctrl) return ov7670_s_exp(sd, info->exposure->val); } return ov7670_s_autoexp(sd, ctrl->val); + case V4L2_CID_TEST_PATTERN: + return ov7670_s_test_pattern(sd, ctrl->val); } return -EINVAL; } @@ -1770,6 +1810,10 @@ static int ov7670_probe(struct i2c_client *client, info->auto_exposure = v4l2_ctrl_new_std_menu(&info->hdl, &ov7670_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, V4L2_EXPOSURE_MANUAL, 0, V4L2_EXPOSURE_AUTO); + v4l2_ctrl_new_std_menu_items(&info->hdl, &ov7670_ctrl_ops, + V4L2_CID_TEST_PATTERN, + ARRAY_SIZE(ov7670_test_pattern_menu) - 1, 0, 0, + ov7670_test_pattern_menu); sd->ctrl_handler = &info->hdl; if (info->hdl.error) { ret = info->hdl.error;