From patchwork Thu Sep 27 15:38:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Martin X-Patchwork-Id: 1515031 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 44AD9DF266 for ; Thu, 27 Sep 2012 15:38:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755512Ab2I0Pis (ORCPT ); Thu, 27 Sep 2012 11:38:48 -0400 Received: from mail-wi0-f172.google.com ([209.85.212.172]:47267 "EHLO mail-wi0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755386Ab2I0Piq (ORCPT ); Thu, 27 Sep 2012 11:38:46 -0400 Received: by wibhq12 with SMTP id hq12so6427002wib.1 for ; Thu, 27 Sep 2012 08:38:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=DujkJubJmVZ6AEm8WaKAt9+A7oeD2qUMW3QnwQGbGl4=; b=Jiwc4c8W9zPBNQawnvYFRBxbsO/XlTBmj2EQXcwAoSavZkUFCPP3N9SwHhlUl3ShS9 jrG3ZMM0IkvC1P8jGdxyOYldGlFOTThoc2sicG48JGTx6jJ7yWGJl/E3so8rpo4IrolM htr0x4fmrtHREBZ8qNuoyNs+hIZNlkEAezU+9db69SRfNec0UcgeUyP0PX9AXVzLRmmC TH1GuUDXQAMYjIxKsKAU4DuK5Ytez9oOWZ/SbKw8FJe2KMd/XY0pSTq1+1e60uhxG0+a RpPyHdKFT8aHEfk3fPXOyPY6mkEV3B0oZaWcjfva+9hUSu3E1vGxfuFsqpxdmXuq27qX 2CeQ== Received: by 10.180.82.3 with SMTP id e3mr27210132wiy.14.1348760324864; Thu, 27 Sep 2012 08:38:44 -0700 (PDT) Received: from piscis.vsilicon.net (122.251.106.212.dynamic.jazztel.es. [212.106.251.122]) by mx.google.com with ESMTPS id eu4sm31740434wib.2.2012.09.27.08.38.42 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Sep 2012 08:38:44 -0700 (PDT) From: Javier Martin To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, hverkuil@xs4all.nl, rusty@rustcorp.com.au, dsd@laptop.org, mchehab@infradead.org, corbet@lwn.net, hdegoede@redhat.com, Javier Martin Subject: [PATCH v2 4/5] media: ov7670: add possibility to bypass pll for ov7675. Date: Thu, 27 Sep 2012 17:38:24 +0200 Message-Id: <1348760305-7481-5-git-send-email-javier.martin@vista-silicon.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1348760305-7481-1-git-send-email-javier.martin@vista-silicon.com> References: <1348760305-7481-1-git-send-email-javier.martin@vista-silicon.com> X-Gm-Message-State: ALoCoQlR2ECF2LZUazSmT+mia1Vl3I0ej/hH2t9XNbedqUnS+KvMQZZ5G7XUvTzzVe8monfcPeIj Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org For a frame rate of 30 fps a pixclk of 24MHz is needed. For those cases where the ov7670 has a clean 24MHz input (xvclk) the PLL can be bypassed. This will result in a value of clkrc of 1, which means that in practice pixclk = xvclk (input clock) Acked-by: Jonathan Corbet Signed-off-by: Javier Martin --- Changes since v1: - Added changelog. --- drivers/media/i2c/ov7670.c | 28 ++++++++++++++++++++++++++-- include/media/ov7670.h | 1 + 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c index cb62d08..559c23e 100644 --- a/drivers/media/i2c/ov7670.c +++ b/drivers/media/i2c/ov7670.c @@ -230,6 +230,7 @@ struct ov7670_info { int clock_speed; /* External clock speed (MHz) */ u8 clkrc; /* Clock divider value */ bool use_smbus; /* Use smbus I/O instead of I2C */ + bool pll_bypass; const struct ov7670_devtype *devtype; /* Device specifics */ }; @@ -755,7 +756,12 @@ static void ov7675_get_framerate(struct v4l2_subdev *sd, { struct ov7670_info *info = to_state(sd); u32 clkrc = info->clkrc; - u32 pll_factor = PLL_FACTOR; + int pll_factor; + + if (info->pll_bypass) + pll_factor = 1; + else + pll_factor = PLL_FACTOR; clkrc++; if (info->fmt->mbus_code == V4L2_MBUS_FMT_SBGGR8_1X8) @@ -771,7 +777,7 @@ static int ov7675_set_framerate(struct v4l2_subdev *sd, { struct ov7670_info *info = to_state(sd); u32 clkrc; - u32 pll_factor = PLL_FACTOR; + int pll_factor; int ret; /* @@ -781,6 +787,16 @@ static int ov7675_set_framerate(struct v4l2_subdev *sd, * pixclk = clock_speed / (clkrc + 1) * PLLfactor * */ + if (info->pll_bypass) { + pll_factor = 1; + ret = ov7670_write(sd, REG_DBLV, DBLV_BYPASS); + } else { + pll_factor = PLL_FACTOR; + ret = ov7670_write(sd, REG_DBLV, DBLV_X4); + } + if (ret < 0) + return ret; + if (tpf->numerator == 0 || tpf->denominator == 0) { clkrc = 0; } else { @@ -808,6 +824,7 @@ static int ov7675_set_framerate(struct v4l2_subdev *sd, ret = ov7670_write(sd, REG_CLKRC, info->clkrc); if (ret < 0) return ret; + return ov7670_write(sd, REG_DBLV, DBLV_X4); } @@ -1688,6 +1705,13 @@ static int ov7670_probe(struct i2c_client *client, if (config->clock_speed) info->clock_speed = config->clock_speed; + + /* + * It should be allowed for ov7670 too when it is migrated to + * the new frame rate formula. + */ + if (config->pll_bypass && id->driver_data != MODEL_OV7670) + info->pll_bypass = true; } /* Make sure it's an ov7670 */ diff --git a/include/media/ov7670.h b/include/media/ov7670.h index b133bc1..a68c8bb 100644 --- a/include/media/ov7670.h +++ b/include/media/ov7670.h @@ -15,6 +15,7 @@ struct ov7670_config { int min_height; /* Filter out smaller sizes */ int clock_speed; /* External clock speed (MHz) */ bool use_smbus; /* Use smbus I/O instead of I2C */ + bool pll_bypass; /* Choose whether to bypass the PLL */ }; #endif