From patchwork Sun Oct 13 12:50:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 11187391 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A328F112B for ; Sun, 13 Oct 2019 12:51:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 74EAA20882 for ; Sun, 13 Oct 2019 12:51:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C/sf3c72" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729106AbfJMMvs (ORCPT ); Sun, 13 Oct 2019 08:51:48 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:36397 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728349AbfJMMvr (ORCPT ); Sun, 13 Oct 2019 08:51:47 -0400 Received: by mail-lj1-f193.google.com with SMTP id v24so13989156ljj.3; Sun, 13 Oct 2019 05:51:46 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=GwH1bhab1sw1PLO/SmssRFS41RXLVtjgRKzNjNOiz3c=; b=C/sf3c72FataPDhCvthO6mKqTv1T1r0Z9RKTgU2c4C4c6IBlfElcNIA3uaM8WWhLO2 dInce+8yIlH+chanV7D/FoO6H4S2bQjR21ozfRnpgOMAphIEw0924rQmLlScEFAL1uPV 8gxi5puYlNVbBBvHuj5xhfLshHp5k/rHnrYVIuhty/PE2H05j17U4lNYwZP/SglDyLpy iMfuUNBgSPlsgMUcwa4L9xeuwgW2pzTDdYMUh1kqHbqNbGU8cSkmRQ21o7mQRPTuMs32 0VtRXnPD5jCpzrn0iItOFRSJ9TB/+v1Bx3m50FwG+Nvr+w3YQxeEgzM1YBk3yoHgTcW+ XrpQ== 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:mime-version:content-transfer-encoding; bh=GwH1bhab1sw1PLO/SmssRFS41RXLVtjgRKzNjNOiz3c=; b=UibLw7daK1w0mEUx+yEyyrzqkqZkczkoM1LzbPBjrBiavYZW+r+I98SgY2bvz+J4XZ ACx7Ypk1tVCZyr8ggmxaIHLSpjL1ZqmD5mtHQOBnSyREOC53dhg1MPrNtxQ8A4o9ArPT qvopynFX+kOj87QCwM1Suqm+Q9tgbcIs0aJXY/DRWlBQctdWsSrfMHM2tGrNt28ICMxp Uk5ySafZ1vdqebRPmG5uztBPdd6Es8pgsaB/5qTPuyqHkVZHCr/w1wqv/UdHH1DOCH5T HZyfkw9VrKZaETvxv5PvSgtb28N7okdBxmClQZ7Kl9c4SNR6tLDisRtUtBSjqWspLlCg 4EqQ== X-Gm-Message-State: APjAAAUMVRl85g7LYdJCPfIP2CerXLZpb/oIHuwthEQcIW1yHBycX/yE Nxrtgo10Ou81g4f4ebUi+34= X-Google-Smtp-Source: APXvYqwYcNYCXpVXtK9tV9Z7ZoW4hOROqnNBmQhbnAgpEKZd6iYn3NMKAqv6NMsz79UpTbFg3DcYYQ== X-Received: by 2002:a2e:9f08:: with SMTP id u8mr2272513ljk.124.1570971105258; Sun, 13 Oct 2019 05:51:45 -0700 (PDT) Received: from z50.gdansk-morena.vectranet.pl (109241207190.gdansk.vectranet.pl. [109.241.207.190]) by smtp.gmail.com with ESMTPSA id m18sm3327243lfb.73.2019.10.13.05.51.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Oct 2019 05:51:44 -0700 (PDT) From: Janusz Krzysztofik To: Sakari Ailus Cc: Mauro Carvalho Chehab , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Janusz Krzysztofik Subject: [PATCH 1/6] media: ov6650: Fix stored frame interval not in sync with hardware Date: Sun, 13 Oct 2019 14:50:45 +0200 Message-Id: <20191013125050.4153-2-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191013125050.4153-1-jmkrzyszt@gmail.com> References: <20191013125050.4153-1-jmkrzyszt@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The driver stores a frame interval value supposed to be in line with hardware state in a device private structure. Since the driver initial submission, the respective field of the structure has never been initialised on device probe. Moreover, if updated from .s_frame_interval(), a new value is stored before it is applied on hardware. If an error occurs during device update, the stored value may no longer reflect hardware state and consecutive calls to .g_frame_interval() may return incorrect information. Assuming a failed update of the device means its actual state hasn't changed, update the frame interval field of the device private structure with a new value only after it is successfully applied on hardware so it always reflects actual hardware state to the extent possible. Also, initialise the field with hardware default frame interval on device probe. Signed-off-by: Janusz Krzysztofik --- drivers/media/i2c/ov6650.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c index 16887049f0cd..f60aeb1f7813 100644 --- a/drivers/media/i2c/ov6650.c +++ b/drivers/media/i2c/ov6650.c @@ -130,6 +130,7 @@ #define CLKRC_24MHz 0xc0 #define CLKRC_DIV_MASK 0x3f #define GET_CLKRC_DIV(x) (((x) & CLKRC_DIV_MASK) + 1) +#define DEF_CLKRC 0x00 #define COMA_RESET BIT(7) #define COMA_QCIF BIT(5) @@ -783,19 +784,17 @@ static int ov6650_s_frame_interval(struct v4l2_subdev *sd, else if (div > GET_CLKRC_DIV(CLKRC_DIV_MASK)) div = GET_CLKRC_DIV(CLKRC_DIV_MASK); - /* - * Keep result to be used as tpf limit - * for subsequent clock divider calculations - */ - priv->tpf.numerator = div; - priv->tpf.denominator = FRAME_RATE_MAX; + tpf->numerator = div; + tpf->denominator = FRAME_RATE_MAX; - clkrc = to_clkrc(&priv->tpf, priv->pclk_limit, priv->pclk_max); + clkrc = to_clkrc(tpf, priv->pclk_limit, priv->pclk_max); ret = ov6650_reg_rmw(client, REG_CLKRC, clkrc, CLKRC_DIV_MASK); if (!ret) { - tpf->numerator = GET_CLKRC_DIV(clkrc); - tpf->denominator = FRAME_RATE_MAX; + priv->tpf.numerator = GET_CLKRC_DIV(clkrc); + priv->tpf.denominator = FRAME_RATE_MAX; + + *tpf = priv->tpf; } return ret; @@ -1038,6 +1037,10 @@ static int ov6650_probe(struct i2c_client *client, priv->rect.width = W_CIF; priv->rect.height = H_CIF; + /* Hardware default frame interval */ + priv->tpf.numerator = GET_CLKRC_DIV(DEF_CLKRC); + priv->tpf.denominator = FRAME_RATE_MAX; + priv->subdev.internal_ops = &ov6650_internal_ops; ret = v4l2_async_register_subdev(&priv->subdev); From patchwork Sun Oct 13 12:50:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 11187401 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 91BB514ED for ; Sun, 13 Oct 2019 12:52:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6FF9F2084D for ; Sun, 13 Oct 2019 12:52:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pooACeax" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729143AbfJMMvu (ORCPT ); Sun, 13 Oct 2019 08:51:50 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:42059 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729130AbfJMMvu (ORCPT ); Sun, 13 Oct 2019 08:51:50 -0400 Received: by mail-lf1-f68.google.com with SMTP id c195so9943205lfg.9; Sun, 13 Oct 2019 05:51:47 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=FZxFeCrxFGIcNgaEcgClIP7u+VMGwh8RhrVDPR5Zq0I=; b=pooACeax7mz1/0X5y6X0Ewndd0h99RtJrVFzzITjfRFomFGoUP4/L/x4kg9LdE9gN1 pNhLWhm6WKL/R6dBsNDs5yG7MDW4OKNDFp3KioEciSyg8fxddgTx9ncC4y1y+gp8kEqj zsS7WlbZ9IKiQFNnZDcQc7R180d1rKHamMKWIQoFsVgRyQOo97piWSMVOFKiJ2hRft34 sz1sCsVYuPdWCH4In7HXSde8VJcPQ8nBibqAGey/SHbgRDFmcz/XZTQKkbF3PGbeglAR d/VKdIG1zBY/veezFUX7f0+VMPBO80sdwUnGsYLu9bfvGydu6PQlVNP2+ocpVor7ueSg IwAQ== 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:mime-version:content-transfer-encoding; bh=FZxFeCrxFGIcNgaEcgClIP7u+VMGwh8RhrVDPR5Zq0I=; b=STgyhZ+8znyuig1duARPT9h7agcqkNGCJqjGADQywfGqONLSrb3/R8pAsku4y9MkYw UpaynCJ/43dAls8XNCtrBgE4BWez8U8DWfndLnhcX9+Wa+B9r9A4fURi0TYMTjjxUMO+ i54U7194qplVvZrL/gswwxnxloEQjufwnbDmxwNj6hnffjSDcvvDUMuHUcLKp+QPF+l6 m5rT2Mgepa6mw+iC/2y7V73V/keFKgEYs87xHwSxNol0uZlBTAwvuzT3bSgmAjzi5prY +GTYEh/CIFaG+L4God/NZoJUKYALV1YWmLaQ8sJIHbSXTb6EIim6QDFpXIPUos8/EUY6 BniQ== X-Gm-Message-State: APjAAAXbYj8kmHL6qkacsAP3byVFAehed6FY3smytHpp7LHU7ixMcgpQ /OzqIkOadazdIlGqulmwe8ARGcGH X-Google-Smtp-Source: APXvYqz9uFYOwjLL9FvQPo6/ra4IRVTRHcsbtllp799O5s/ms8pVqxBTg3zugJM+4NNeD1ugrc/B4w== X-Received: by 2002:a19:6a18:: with SMTP id u24mr14082419lfu.52.1570971106640; Sun, 13 Oct 2019 05:51:46 -0700 (PDT) Received: from z50.gdansk-morena.vectranet.pl (109241207190.gdansk.vectranet.pl. [109.241.207.190]) by smtp.gmail.com with ESMTPSA id m18sm3327243lfb.73.2019.10.13.05.51.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Oct 2019 05:51:46 -0700 (PDT) From: Janusz Krzysztofik To: Sakari Ailus Cc: Mauro Carvalho Chehab , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Janusz Krzysztofik Subject: [PATCH 2/6] media: ov6650: Drop obsolete .pclk_limit attribute Date: Sun, 13 Oct 2019 14:50:46 +0200 Message-Id: <20191013125050.4153-3-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191013125050.4153-1-jmkrzyszt@gmail.com> References: <20191013125050.4153-1-jmkrzyszt@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org That attribute used to be obtained from platform data by a soc_camera host interface and passed to the sensor driver for .s_mbus_fmt() video operation callback, later reused as .set_fmt() pad operation callback, to be able to limit frame rate. The driver stored that value in its private structure for further use from .g/s_parm(), later converted to g/s_frame_interval(). On conversion of the driver from soc_camera sensor to a standalone V4L2 subdevice by commit 23a52386fabe ("media: ov6650: convert to standalone v4l2 subdevice"), that attribute had been replaced by a constant and hardcoded to an arbitrarily chosen pixel clock limit. Drop it. Host interfaces can limit frame rate if needed by calling .s_frame_interval(). Signed-off-by: Janusz Krzysztofik --- drivers/media/i2c/ov6650.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c index f60aeb1f7813..a50244401491 100644 --- a/drivers/media/i2c/ov6650.c +++ b/drivers/media/i2c/ov6650.c @@ -197,7 +197,6 @@ struct ov6650 { struct v4l2_clk *clk; bool half_scale; /* scale down output by 2 */ struct v4l2_rect rect; /* sensor cropping window */ - unsigned long pclk_limit; /* from host */ unsigned long pclk_max; /* from resolution and format */ struct v4l2_fract tpf; /* as requested with s_frame_interval */ u32 code; @@ -546,8 +545,7 @@ static bool is_unscaled_ok(int width, int height, struct v4l2_rect *rect) return width > rect->width >> 1 || height > rect->height >> 1; } -static u8 to_clkrc(struct v4l2_fract *timeperframe, - unsigned long pclk_limit, unsigned long pclk_max) +static u8 to_clkrc(struct v4l2_fract *timeperframe, unsigned long pclk_max) { unsigned long pclk; @@ -557,9 +555,6 @@ static u8 to_clkrc(struct v4l2_fract *timeperframe, else pclk = pclk_max; - if (pclk_limit && pclk_limit < pclk) - pclk = pclk_limit; - return (pclk_max - 1) / pclk; } @@ -653,10 +648,9 @@ static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf) clkrc = CLKRC_12MHz; mclk = 12000000; - priv->pclk_limit = 1334000; dev_dbg(&client->dev, "using 12MHz input clock\n"); - clkrc |= to_clkrc(&priv->tpf, priv->pclk_limit, priv->pclk_max); + clkrc |= to_clkrc(&priv->tpf, priv->pclk_max); pclk = priv->pclk_max / GET_CLKRC_DIV(clkrc); dev_dbg(&client->dev, "pixel clock divider: %ld.%ld\n", @@ -756,7 +750,7 @@ static int ov6650_g_frame_interval(struct v4l2_subdev *sd, struct ov6650 *priv = to_ov6650(client); ival->interval.numerator = GET_CLKRC_DIV(to_clkrc(&priv->tpf, - priv->pclk_limit, priv->pclk_max)); + priv->pclk_max)); ival->interval.denominator = FRAME_RATE_MAX; dev_dbg(&client->dev, "Frame interval: %u/%u s\n", @@ -787,7 +781,7 @@ static int ov6650_s_frame_interval(struct v4l2_subdev *sd, tpf->numerator = div; tpf->denominator = FRAME_RATE_MAX; - clkrc = to_clkrc(tpf, priv->pclk_limit, priv->pclk_max); + clkrc = to_clkrc(tpf, priv->pclk_max); ret = ov6650_reg_rmw(client, REG_CLKRC, clkrc, CLKRC_DIV_MASK); if (!ret) { From patchwork Sun Oct 13 12:50:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 11187395 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D3FD6112B for ; Sun, 13 Oct 2019 12:52:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AA5F420869 for ; Sun, 13 Oct 2019 12:52:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MCEH99lM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729202AbfJMMvw (ORCPT ); Sun, 13 Oct 2019 08:51:52 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:37463 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728349AbfJMMvu (ORCPT ); Sun, 13 Oct 2019 08:51:50 -0400 Received: by mail-lf1-f66.google.com with SMTP id w67so9959056lff.4; Sun, 13 Oct 2019 05:51:48 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=jqZhIjSnGaQkCto65LI2ltagzMepKonmREX9kN29OzI=; b=MCEH99lMhnFs50GY5tA5FlYHtFeRCvWmbyyz8e8MusYGDwyijf4jpLoH2zKXE/RZlB myQPdSDfg82aOhlsyHiPBbuFSOyAm8f5hL0P5oK+r2cNnw90t1xANBt5e6XqUzRjX5FY fm7oO8VT17rsiLtHamC1LfFV+MSKh6nPGlOewZLdmBQVLMMoJ0/7hCpabCqdm7AiPYCO xj7R6mx7GqjGQhkGX7sMz6tsddvgeUVhOYR2W20NZ4fgGUksu9KKzRpNDuo/DBh0cdcg 3jP6K48q/ZqESAkFzvDBRE6Z5jfNphoLNtg2/9cWwfExB9ZAgOgkLcEWX+h4f1SSlb/W K/dA== 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:mime-version:content-transfer-encoding; bh=jqZhIjSnGaQkCto65LI2ltagzMepKonmREX9kN29OzI=; b=toLEpWnbVNHln7HfAMUmaMAHIEz4SxYAzv91rT28xX+C/5n8HX6fuiozuZSGFkH1vF YjSaqthZG88Ros1pLx010p2dyfmCfJR43UnF8xooGchD4JD7serdgmnYIfhqO6Ginabz MkRv05AdIDxqu4DHCVopYvq3LMiAxVnLrWNVYBV+UyGnNpE0uhAyDcHK/NKYJ/lsRg4G R9XqctywWCrqEIkXqPTn0tof9cwu0JpTqYWpDQvZGlNNN4alk3jtkDpBZs2MbS1Wyzea 3BQ/J7qVd6xVYn2UZTb9sG4DzQhatg7vtX+3Hvbw2rydG8zrofU0Rx1JZzVqr3NL4f9j rqaA== X-Gm-Message-State: APjAAAWDWKzSUWPikNEiAH3/e/dA4vnwkdL3KA19QqZSrZuRIlrn9Vhr IOlloB4tgi0ChcRCOGb+vx8= X-Google-Smtp-Source: APXvYqyxwDLf3f0ZqrDsWwDPE6BLC8VpoJvSBbJ1n3RMjNQ8rcK8iCDnxU1Sz/yqn1JVoxx2POf1ZA== X-Received: by 2002:ac2:5629:: with SMTP id b9mr15393804lff.32.1570971107842; Sun, 13 Oct 2019 05:51:47 -0700 (PDT) Received: from z50.gdansk-morena.vectranet.pl (109241207190.gdansk.vectranet.pl. [109.241.207.190]) by smtp.gmail.com with ESMTPSA id m18sm3327243lfb.73.2019.10.13.05.51.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Oct 2019 05:51:47 -0700 (PDT) From: Janusz Krzysztofik To: Sakari Ailus Cc: Mauro Carvalho Chehab , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Janusz Krzysztofik Subject: [PATCH 3/6] media: ov6650: Simplify clock divisor calculation Date: Sun, 13 Oct 2019 14:50:47 +0200 Message-Id: <20191013125050.4153-4-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191013125050.4153-1-jmkrzyszt@gmail.com> References: <20191013125050.4153-1-jmkrzyszt@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org As appears from an analysis of to_clkrc() helper code after its pclk_limit argument has been dropped, its result no longer depends on another argument - pclk_max. Moreover, assuming that a constant value of FRAME_RATE_MAX is always used as a denominator of the only significant argument left - a struct v4l2_fract, the result in fact depends only on the numerator value of that argument. As a further consequence, it no longer makes sense to recalculate frame intervals by converting them forth and back with a GET_CLKRC_DIV(to_clkrc(tpf)) construct. Drop use of GET_CLKRC_DIV() on results of to_clkrc() where possible - use the frame interval value directly. Furthermore, replace the to_clkrc() helper function with a simple macro and update its users to always use FRAME_RATE_MAX as frame interval denominator and pass only its numerator as an argument. Signed-off-by: Janusz Krzysztofik --- drivers/media/i2c/ov6650.c | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c index a50244401491..61ddd4ea4c26 100644 --- a/drivers/media/i2c/ov6650.c +++ b/drivers/media/i2c/ov6650.c @@ -545,18 +545,7 @@ static bool is_unscaled_ok(int width, int height, struct v4l2_rect *rect) return width > rect->width >> 1 || height > rect->height >> 1; } -static u8 to_clkrc(struct v4l2_fract *timeperframe, unsigned long pclk_max) -{ - unsigned long pclk; - - if (timeperframe->numerator && timeperframe->denominator) - pclk = pclk_max * timeperframe->denominator / - (FRAME_RATE_MAX * timeperframe->numerator); - else - pclk = pclk_max; - - return (pclk_max - 1) / pclk; -} +#define to_clkrc(div) ((div) - 1) /* set the format we will capture in */ static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf) @@ -650,7 +639,7 @@ static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf) mclk = 12000000; dev_dbg(&client->dev, "using 12MHz input clock\n"); - clkrc |= to_clkrc(&priv->tpf, priv->pclk_max); + clkrc |= to_clkrc(priv->tpf.numerator); pclk = priv->pclk_max / GET_CLKRC_DIV(clkrc); dev_dbg(&client->dev, "pixel clock divider: %ld.%ld\n", @@ -749,9 +738,7 @@ static int ov6650_g_frame_interval(struct v4l2_subdev *sd, struct i2c_client *client = v4l2_get_subdevdata(sd); struct ov6650 *priv = to_ov6650(client); - ival->interval.numerator = GET_CLKRC_DIV(to_clkrc(&priv->tpf, - priv->pclk_max)); - ival->interval.denominator = FRAME_RATE_MAX; + ival->interval = priv->tpf; dev_dbg(&client->dev, "Frame interval: %u/%u s\n", ival->interval.numerator, ival->interval.denominator); @@ -766,7 +753,6 @@ static int ov6650_s_frame_interval(struct v4l2_subdev *sd, struct ov6650 *priv = to_ov6650(client); struct v4l2_fract *tpf = &ival->interval; int div, ret; - u8 clkrc; if (tpf->numerator == 0 || tpf->denominator == 0) div = 1; /* Reset to full rate */ @@ -778,14 +764,9 @@ static int ov6650_s_frame_interval(struct v4l2_subdev *sd, else if (div > GET_CLKRC_DIV(CLKRC_DIV_MASK)) div = GET_CLKRC_DIV(CLKRC_DIV_MASK); - tpf->numerator = div; - tpf->denominator = FRAME_RATE_MAX; - - clkrc = to_clkrc(tpf, priv->pclk_max); - - ret = ov6650_reg_rmw(client, REG_CLKRC, clkrc, CLKRC_DIV_MASK); + ret = ov6650_reg_rmw(client, REG_CLKRC, to_clkrc(div), CLKRC_DIV_MASK); if (!ret) { - priv->tpf.numerator = GET_CLKRC_DIV(clkrc); + priv->tpf.numerator = div; priv->tpf.denominator = FRAME_RATE_MAX; *tpf = priv->tpf; From patchwork Sun Oct 13 12:50:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 11187399 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 50F68112B for ; Sun, 13 Oct 2019 12:52:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 311E12082F for ; Sun, 13 Oct 2019 12:52:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VV1QMnkZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729294AbfJMMwF (ORCPT ); Sun, 13 Oct 2019 08:52:05 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:43117 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729187AbfJMMvw (ORCPT ); Sun, 13 Oct 2019 08:51:52 -0400 Received: by mail-lj1-f195.google.com with SMTP id n14so13949444ljj.10; Sun, 13 Oct 2019 05:51:49 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=N5xwppzxLfD235nBWm/2lMus5/8Z/i+yMzV4wj9LsE4=; b=VV1QMnkZm/jSR163JgojCsqmbsoTL0r+24dV0TYzmuH85a/7PzgVyXdS+WGMo8S3rI zxl9zUy2vFcWgYSoX8j7nk51PSSUGZ4f1xM4FTP+OuBKtu3Rc8yGcGbhX0nK+LITod+m I4hy8cBdfQSLF4lqpq7mMHeekhc7b+WHRmWNJJGq9o4BmioWQFCWjOYQ07n47wEdHD9n NULXj71kKHVwCw6jmURC8ooqBH6dOgUCOgNVL1hWugH1McsLd14owdWwgfE89cNZ5ZUK FnW3KE2IUyXI3b4oIB1xEE+G8oeWluzjMMreMAeLObhytzgtFbcYw99/GKcK9652h7Ft 3ofA== 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:mime-version:content-transfer-encoding; bh=N5xwppzxLfD235nBWm/2lMus5/8Z/i+yMzV4wj9LsE4=; b=gnCgX57tJKSmiZhxlZc3vIuzxmOb5mh5/WbLXMC/BwKogFLF/TVr2CVk8COTpnE4Uh bI4Dbf7k/ZI4W70q3DAIGYz4cCJyVpo3tEf2FQL8RKq++D5SIe0LtQtkJagYP1rVZbBN mMNHqc3ybnQ7W9gB+cdGuH7H2swh98Juqu33bK/Koxkah5B5rOlQzYLHjpDzP0I07Pl8 lD973zRvxbdK4W3J2l/q1pro4OJfr26XMERONMVA1HYoC2UQjQqjUakwV5MSPyW/N0tW ZxQMEt0Z9E4FPKTPL+FuCDXx9cLAAtkWWu4vb3Y8aD9s0Qnt69AW6z1ja5pbHHvEUXGs FITA== X-Gm-Message-State: APjAAAVjq5ZsUJr0nla56XdIVrEyBqUmRBjzngVzZq99olQRg4zyZZIG AOwSIb/Ccot/ibaV3o0fvxQ= X-Google-Smtp-Source: APXvYqzXMz8SnBPIqokeFzd8nC9MNXRRuEHd2i6zONnC9nXuFWMjoh43nA50NaOh/HPRUev76wvT2A== X-Received: by 2002:a2e:207:: with SMTP id 7mr15412581ljc.248.1570971109117; Sun, 13 Oct 2019 05:51:49 -0700 (PDT) Received: from z50.gdansk-morena.vectranet.pl (109241207190.gdansk.vectranet.pl. [109.241.207.190]) by smtp.gmail.com with ESMTPSA id m18sm3327243lfb.73.2019.10.13.05.51.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Oct 2019 05:51:48 -0700 (PDT) From: Janusz Krzysztofik To: Sakari Ailus Cc: Mauro Carvalho Chehab , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Janusz Krzysztofik Subject: [PATCH 4/6] media: ov6650: Don't reapply pixel clock divisor on format change Date: Sun, 13 Oct 2019 14:50:48 +0200 Message-Id: <20191013125050.4153-5-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191013125050.4153-1-jmkrzyszt@gmail.com> References: <20191013125050.4153-1-jmkrzyszt@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org As calculation of pixel clock hardware divisor no longer depends on mbus format specific maximum pixel clock, there is no need to reapply the divisor on format change. Drop related code from ov6650_s_fmt() helper. Since a master clock hardware divisor, so far applied only together with the pixel clock divisor in a single operation, will no longer be applied from ov6650_s_fmt(), apply it, still using a hardcoded value for now, from ov6650_prog_dflt() helper so hardware is still initialised correctly on device probe. Signed-off-by: Janusz Krzysztofik --- drivers/media/i2c/ov6650.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c index 61ddd4ea4c26..e95ea132ef06 100644 --- a/drivers/media/i2c/ov6650.c +++ b/drivers/media/i2c/ov6650.c @@ -564,8 +564,7 @@ static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf) .r.height = mf->height << half_scale, }; u32 code = mf->code; - unsigned long mclk, pclk; - u8 coma_set = 0, coma_mask = 0, coml_set, coml_mask, clkrc; + u8 coma_set = 0, coma_mask = 0, coml_set, coml_mask; int ret; /* select color matrix configuration for given color encoding */ @@ -635,21 +634,9 @@ static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf) coma_mask |= COMA_QCIF; } - clkrc = CLKRC_12MHz; - mclk = 12000000; - dev_dbg(&client->dev, "using 12MHz input clock\n"); - - clkrc |= to_clkrc(priv->tpf.numerator); - - pclk = priv->pclk_max / GET_CLKRC_DIV(clkrc); - dev_dbg(&client->dev, "pixel clock divider: %ld.%ld\n", - mclk / pclk, 10 * mclk % pclk / pclk); - ret = ov6650_set_selection(sd, NULL, &sel); if (!ret) ret = ov6650_reg_rmw(client, REG_COMA, coma_set, coma_mask); - if (!ret) - ret = ov6650_reg_write(client, REG_CLKRC, clkrc); if (!ret) { priv->half_scale = half_scale; @@ -798,6 +785,8 @@ static int ov6650_prog_dflt(struct i2c_client *client) dev_dbg(&client->dev, "initializing\n"); ret = ov6650_reg_write(client, REG_COMA, 0); /* ~COMA_RESET */ + if (!ret) + ret = ov6650_reg_write(client, REG_CLKRC, CLKRC_12MHz); if (!ret) ret = ov6650_reg_rmw(client, REG_COMB, 0, COMB_BAND_FILTER); From patchwork Sun Oct 13 12:50:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 11187397 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 23ABD112B for ; Sun, 13 Oct 2019 12:52:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0433A2084D for ; Sun, 13 Oct 2019 12:52:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CTN2oK77" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729269AbfJMMwB (ORCPT ); Sun, 13 Oct 2019 08:52:01 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:36402 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729130AbfJMMvw (ORCPT ); Sun, 13 Oct 2019 08:51:52 -0400 Received: by mail-lj1-f194.google.com with SMTP id v24so13989241ljj.3; Sun, 13 Oct 2019 05:51:51 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=70J2v6uWAhiRGhg1LXaKeSs3P933eEPAxMOkaLLVTnY=; b=CTN2oK77tCXIp720Tnm8zkekHhQBJtobWchPYrfMyK/GFp7krlrQI3QPlGQQdMa8rQ yWEE5ax0nTomURXqRGy+yictEzflVUhQTLYeWQIjl8XGG1BMh0TwRHHQEOBkbnwAInuR jmncYHfrYCW79noHYBnbKD4TagFNatditDVTbPOWqLNHs3UntOSW9Lhv4czHTsfr4fN7 3bogGRaCfNNcGrvgQIFmGbDBVwOt3zmLSoeLvQeef9C+kwlUUc5SLuadjwGQcdsZsyCT MFO1qptRggyLm0lBTaO+XeNuB2+30uOYNXqfnpXJeVdpC/vy7fcpwE+P2xYvQBY0RFAf q5PA== 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:mime-version:content-transfer-encoding; bh=70J2v6uWAhiRGhg1LXaKeSs3P933eEPAxMOkaLLVTnY=; b=mEscd4FmiYY5ea2AGJqyeiQu8UPznQ6pVMdgF/v8XsZ/5pDnOrKIUkmJKsy59doz+a bm6XGIKwCZH7uCOp+voRrxtrF5Kz966FJX8gbmoNwd3zyd87NOAGwbfHCjpjwRVsjIb1 xy6W1KOoUSXsLRXkNKjoklihr0GPLoBLZlHS/RJDaLsh4RT47W4dJlFvJMzEhS+a5ovR VoSM4wdxmKi9CsLwB7YTTgtZ/CEDvnpMfgfU9x3iC5q2M6hSzcYmkEZI78DTq/+p4u75 B/6q5V0EKcaZZJf9I4+qLb0A8ehtCKrPV6w/KYjIQ4nBIMFtsvv1gwNN31nZ9UaT78M1 dhIw== X-Gm-Message-State: APjAAAXQt1da8p8VWCH9AcnrdR57XCc0jQU99rmkF/82dIa8/vYTyxvE Yx3JqinCoXQqJ8MeCytzPoc= X-Google-Smtp-Source: APXvYqyEk7Pf5/iDdl4rfqrTpep8lZSSS1xJoS2maMB+X6qF2Rtv9Y9Pa++ZBfEoDtLZk4YUWuEmmg== X-Received: by 2002:a2e:6101:: with SMTP id v1mr15628226ljb.122.1570971110374; Sun, 13 Oct 2019 05:51:50 -0700 (PDT) Received: from z50.gdansk-morena.vectranet.pl (109241207190.gdansk.vectranet.pl. [109.241.207.190]) by smtp.gmail.com with ESMTPSA id m18sm3327243lfb.73.2019.10.13.05.51.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Oct 2019 05:51:49 -0700 (PDT) From: Janusz Krzysztofik To: Sakari Ailus Cc: Mauro Carvalho Chehab , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Janusz Krzysztofik Subject: [PATCH 5/6] media: ov6650: Drop unused .pclk_max field Date: Sun, 13 Oct 2019 14:50:49 +0200 Message-Id: <20191013125050.4153-6-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191013125050.4153-1-jmkrzyszt@gmail.com> References: <20191013125050.4153-1-jmkrzyszt@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This field of the driver private structure is no longer used, drop it. Signed-off-by: Janusz Krzysztofik --- drivers/media/i2c/ov6650.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c index e95ea132ef06..f4723c0b5c70 100644 --- a/drivers/media/i2c/ov6650.c +++ b/drivers/media/i2c/ov6650.c @@ -197,7 +197,6 @@ struct ov6650 { struct v4l2_clk *clk; bool half_scale; /* scale down output by 2 */ struct v4l2_rect rect; /* sensor cropping window */ - unsigned long pclk_max; /* from resolution and format */ struct v4l2_fract tpf; /* as requested with s_frame_interval */ u32 code; }; @@ -618,17 +617,14 @@ static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf) code == MEDIA_BUS_FMT_SBGGR8_1X8) { coml_mask = COML_ONE_CHANNEL; coml_set = 0; - priv->pclk_max = 4000000; } else { coml_mask = 0; coml_set = COML_ONE_CHANNEL; - priv->pclk_max = 8000000; } if (half_scale) { dev_dbg(&client->dev, "max resolution: QCIF\n"); coma_set |= COMA_QCIF; - priv->pclk_max /= 2; } else { dev_dbg(&client->dev, "max resolution: CIF\n"); coma_mask |= COMA_QCIF; From patchwork Sun Oct 13 12:50:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 11187393 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3763614ED for ; Sun, 13 Oct 2019 12:51:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0F9AB2085B for ; Sun, 13 Oct 2019 12:51:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oswxuqjB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729235AbfJMMv4 (ORCPT ); Sun, 13 Oct 2019 08:51:56 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:46763 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729188AbfJMMvx (ORCPT ); Sun, 13 Oct 2019 08:51:53 -0400 Received: by mail-lf1-f67.google.com with SMTP id t8so9918764lfc.13; Sun, 13 Oct 2019 05:51:52 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=7xCq5J+OfyTULb+8V1WcTAauQxnh+VYppr0SjYzFpH8=; b=oswxuqjBzvBckACKPIK1IwNha2bWQzHzGSDOY3Z29T+jHXdjLuN0nWeaAHPh1VO6TL P7lOkvMo4Ci1kb57FogbNNsrXXYEsUgWoZXxuJqVDL4iFr22zEApS5isYaTNgJAaBjAU bkMy2gUwtAcbkUnn04Zb8k6y2LPwAqTxIoa4ZPjevty6ait+ZmzAOClX0J5dmOvEhl0L gBRwn+U7RYQt1voGewYQG/zP14zxYO2qFVOBRwnbcs90HbmpMAGOileth0Qpygnhl5QL VDVOdVnoVPQnPXdXrpPYHIBSyaAv/CDZP0tT4LgRg2tEg1/ySDTr5ruwXETox752RGTS kQTQ== 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:mime-version:content-transfer-encoding; bh=7xCq5J+OfyTULb+8V1WcTAauQxnh+VYppr0SjYzFpH8=; b=U9zykbAeirtD2Xvrn+hnc2NmRAtN26MKf47mjBYCk4P7glXNcxxYwiiNhgKohU0bl+ c9ACoqSsNtxmpAfV0X+vHMaN9Xr1Ivi1wjfx4AZJKUETVwpguEf3B/hnCgawqZxhS2nG k5kc8W0s1PT33iTTIbX9p7UH49ylTLUH9RRX2XtCjM172gSLLQPCYIXDzS0O4W1lrDcf 9XHRtUe/VM/uwyiRWNDgyTgV0D1jNpq26bAcfRZS+stK6ZqI/H9YccVJ7f131Hm07YQK NIw6TVRdUgOCc+l0ngKLmNFcsdBaDk2d/qX6zw9tOP15xPiN69lYQZ3Rc/VQMq3w1rqE 8iSA== X-Gm-Message-State: APjAAAVtPcZoFKx/x8GtBroUAU8HM0f9afZcaALuFWutPFwhZWvRf/VP rkIMpQtJ/Y8N74za4DXqUcw= X-Google-Smtp-Source: APXvYqyl4sKhCoSBzphYXAukd2baCSImv4MOnEM7J5VEaqwqvUSGrU6E5atg3VoIY0m6ERDptQqbmA== X-Received: by 2002:ac2:528f:: with SMTP id q15mr8769271lfm.25.1570971111538; Sun, 13 Oct 2019 05:51:51 -0700 (PDT) Received: from z50.gdansk-morena.vectranet.pl (109241207190.gdansk.vectranet.pl. [109.241.207.190]) by smtp.gmail.com with ESMTPSA id m18sm3327243lfb.73.2019.10.13.05.51.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Oct 2019 05:51:50 -0700 (PDT) From: Janusz Krzysztofik To: Sakari Ailus Cc: Mauro Carvalho Chehab , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Janusz Krzysztofik Subject: [PATCH 6/6] media: ov6650: Fix arbitrary selection of master clock rate Date: Sun, 13 Oct 2019 14:50:50 +0200 Message-Id: <20191013125050.4153-7-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191013125050.4153-1-jmkrzyszt@gmail.com> References: <20191013125050.4153-1-jmkrzyszt@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org A hardcoded 12 MHz master clock frequency has been assumed since conversion of the driver from soc_camera sensor to a standalone V4L2 subdevice by commit 23a52386fabe ("media: ov6650: convert to standalone v4l2 subdevice"). Fix it. Define a static table of supported master clock rates (fix misnamed symbol while being at it), then use v4l2_clk_get/set_rate() to obtain a clock rate matching one of those supported. On success, apply respective master clock hardware divisor provided by the matching element of the table. Signed-off-by: Janusz Krzysztofik --- drivers/media/i2c/ov6650.c | 64 ++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 6 deletions(-) diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c index f4723c0b5c70..13fd7c4699b2 100644 --- a/drivers/media/i2c/ov6650.c +++ b/drivers/media/i2c/ov6650.c @@ -124,7 +124,7 @@ #define DEF_AECH 0x4D -#define CLKRC_6MHz 0x00 +#define CLKRC_8MHz 0x00 #define CLKRC_12MHz 0x40 #define CLKRC_16MHz 0x80 #define CLKRC_24MHz 0xc0 @@ -201,6 +201,29 @@ struct ov6650 { u32 code; }; +struct ov6650_xclk { + unsigned long rate; + u8 clkrc; +}; + +static const struct ov6650_xclk ov6650_xclk[] = { +{ + .rate = 8000000, + .clkrc = CLKRC_8MHz, +}, +{ + .rate = 12000000, + .clkrc = CLKRC_12MHz, +}, +{ + .rate = 16000000, + .clkrc = CLKRC_16MHz, +}, +{ + .rate = 24000000, + .clkrc = CLKRC_24MHz, +}, +}; static u32 ov6650_codes[] = { MEDIA_BUS_FMT_YUYV8_2X8, @@ -774,7 +797,7 @@ static int ov6650_reset(struct i2c_client *client) } /* program default register values */ -static int ov6650_prog_dflt(struct i2c_client *client) +static int ov6650_prog_dflt(struct i2c_client *client, u8 clkrc) { int ret; @@ -782,7 +805,7 @@ static int ov6650_prog_dflt(struct i2c_client *client) ret = ov6650_reg_write(client, REG_COMA, 0); /* ~COMA_RESET */ if (!ret) - ret = ov6650_reg_write(client, REG_CLKRC, CLKRC_12MHz); + ret = ov6650_reg_write(client, REG_CLKRC, clkrc); if (!ret) ret = ov6650_reg_rmw(client, REG_COMB, 0, COMB_BAND_FILTER); @@ -793,8 +816,10 @@ static int ov6650_video_probe(struct v4l2_subdev *sd) { struct i2c_client *client = v4l2_get_subdevdata(sd); struct ov6650 *priv = to_ov6650(client); - u8 pidh, pidl, midh, midl; - int ret; + const struct ov6650_xclk *xclk; + unsigned long rate; + u8 pidh, pidl, midh, midl; + int i, ret; priv->clk = v4l2_clk_get(&client->dev, NULL); if (IS_ERR(priv->clk)) { @@ -803,6 +828,33 @@ static int ov6650_video_probe(struct v4l2_subdev *sd) return ret; } + rate = v4l2_clk_get_rate(priv->clk); + for (i = 0; rate && i < ARRAY_SIZE(ov6650_xclk); i++) { + if (rate != ov6650_xclk[i].rate) + continue; + + xclk = &ov6650_xclk[i]; + dev_info(&client->dev, "using host default clock rate %lukHz\n", + rate / 1000); + break; + } + for (i = 0; !xclk && i < ARRAY_SIZE(ov6650_xclk); i++) { + ret = v4l2_clk_set_rate(priv->clk, ov6650_xclk[i].rate); + if (ret || v4l2_clk_get_rate(priv->clk) != ov6650_xclk[i].rate) + continue; + + xclk = &ov6650_xclk[i]; + dev_info(&client->dev, "using negotiated clock rate %lukHz\n", + xclk->rate / 1000); + break; + } + if (!xclk) { + dev_err(&client->dev, "unable to get supported clock rate\n"); + if (!ret) + ret = -EINVAL; + goto eclkput; + } + ret = ov6650_s_power(sd, 1); if (ret < 0) goto eclkput; @@ -836,7 +888,7 @@ static int ov6650_video_probe(struct v4l2_subdev *sd) ret = ov6650_reset(client); if (!ret) - ret = ov6650_prog_dflt(client); + ret = ov6650_prog_dflt(client, xclk->clkrc); if (!ret) { struct v4l2_mbus_framefmt mf = ov6650_def_fmt;