From patchwork Fri Jun 24 23:03:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tommaso Merciai X-Patchwork-Id: 585028 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13B33C433EF for ; Fri, 24 Jun 2022 23:03:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231725AbiFXXDj (ORCPT ); Fri, 24 Jun 2022 19:03:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231419AbiFXXDg (ORCPT ); Fri, 24 Jun 2022 19:03:36 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52AA187D6A for ; Fri, 24 Jun 2022 16:03:35 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id fi2so7505441ejb.9 for ; Fri, 24 Jun 2022 16:03:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AtZ/cIs6lq2eirM771Yk+JBARQCD5B0BoigyCmO2Az8=; b=Nslflgx+vC6wlDa38RA+REXLnTqEX5+bu6g9ShxBqsc+cFFvdjQ9T4GPzoyet4MDoJ vjxmrnleCvPcD1wlhC/HxPb9qrINaBBrNR8jh7djyIGY9uZVrSApbuKks43rlsfdrdqp sw0CY8OILmEVZ6L+S0OwjZIuZKWnioNgA/3QU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AtZ/cIs6lq2eirM771Yk+JBARQCD5B0BoigyCmO2Az8=; b=mCKxIgM57CjbdPjcXoF9Qc1U3TttppboOaK7UEJeQtGD0SIm1hHgNermY5X+DmCOvQ Wjc1dEeW0q+GxiqEKCGp06Lnp809TGUMXb6DnF1+LhxjmMjZd5sVxApjzCNWLC7eIvqd JjPGboK+Y23+s2LlajfNXPHSX7jtp/oD6sFdJAp0uctJl2zwuZKAU51aRxLr9QHmr4qL e6Tm5cRTt+uxVwqsnce31NDKWj5XlCtegCWTEZP6WDyhr7tsNwxX6fZ7XYLWhVQPvvbS LPt2b1xI225mr97It/4Xl8nScPbEvUJOoCq7fYuQawliYDcg9BjoaX/qjDDsjILxpZn9 f+OA== X-Gm-Message-State: AJIora+Rh7JEwYRQ9VWuWz+3m4Eo3hGu0TpoKJzIIL82TP3SoHwnY0FS gtcdqZf60+ez9P2qBbvRqFdktg== X-Google-Smtp-Source: AGRyM1tlrG2DIrP2a8KAibUba590k2twf2MsHXy9VNHXYbTtgBZ6tdw82kShPk057cNTiqdMRQOIVQ== X-Received: by 2002:a17:907:948f:b0:722:e90c:6bc9 with SMTP id dm15-20020a170907948f00b00722e90c6bc9mr1371123ejc.180.1656111813900; Fri, 24 Jun 2022 16:03:33 -0700 (PDT) Received: from tom-ThinkPad-T14s-Gen-2i.station (net-188-217-58-216.cust.vodafonedsl.it. [188.217.58.216]) by smtp.gmail.com with ESMTPSA id w1-20020aa7da41000000b004356a647d08sm2880291eds.94.2022.06.24.16.03.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jun 2022 16:03:33 -0700 (PDT) From: Tommaso Merciai Cc: linuxfancy@googlegroups.com, linux-amarula@amarulasolutions.com, quentin.schulz@theobroma-systems.com, Tommaso Merciai , Daniel Scally , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/7] media: ov5693: move hw cfg functions into ov5693_check_hwcfg Date: Sat, 25 Jun 2022 01:03:04 +0200 Message-Id: <20220624230307.3066530-5-tommaso.merciai@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220624230307.3066530-1-tommaso.merciai@amarulasolutions.com> References: <20220624230307.3066530-1-tommaso.merciai@amarulasolutions.com> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Move hw configuration functions into ov5693_check_hwcfg. This is done to separe the code that handle the hw cfg from probe in a clean way Signed-off-by: Tommaso Merciai --- drivers/media/i2c/ov5693.c | 53 +++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c index d2adc5513a21..d5a934ace597 100644 --- a/drivers/media/i2c/ov5693.c +++ b/drivers/media/i2c/ov5693.c @@ -1348,6 +1348,38 @@ static int ov5693_check_hwcfg(struct ov5693_device *ov5693) struct fwnode_handle *endpoint; unsigned int i; int ret; + u32 xvclk_rate; + + ov5693->xvclk = devm_clk_get(ov5693->dev, "xvclk"); + if (IS_ERR(ov5693->xvclk)) + return dev_err_probe(ov5693->dev, PTR_ERR(ov5693->xvclk), + "failed to get xvclk: %ld\n", + PTR_ERR(ov5693->xvclk)); + + if (ov5693->xvclk) { + xvclk_rate = clk_get_rate(ov5693->xvclk); + } else { + ret = fwnode_property_read_u32(fwnode, "clock-frequency", + &xvclk_rate); + + if (ret) { + dev_err(ov5693->dev, "can't get clock frequency"); + return ret; + } + } + + if (xvclk_rate != OV5693_XVCLK_FREQ) + dev_warn(ov5693->dev, "Found clk freq %u, expected %u\n", + xvclk_rate, OV5693_XVCLK_FREQ); + + ret = ov5693_configure_gpios(ov5693); + if (ret) + return ret; + + ret = ov5693_get_regulators(ov5693); + if (ret) + return dev_err_probe(ov5693->dev, ret, + "Error fetching regulators\n"); endpoint = fwnode_graph_get_next_endpoint(fwnode, NULL); if (!endpoint) @@ -1390,7 +1422,6 @@ static int ov5693_check_hwcfg(struct ov5693_device *ov5693) static int ov5693_probe(struct i2c_client *client) { struct ov5693_device *ov5693; - u32 xvclk_rate; int ret = 0; ov5693 = devm_kzalloc(&client->dev, sizeof(*ov5693), GFP_KERNEL); @@ -1408,26 +1439,6 @@ static int ov5693_probe(struct i2c_client *client) v4l2_i2c_subdev_init(&ov5693->sd, client, &ov5693_ops); - ov5693->xvclk = devm_clk_get(&client->dev, "xvclk"); - if (IS_ERR(ov5693->xvclk)) { - dev_err(&client->dev, "Error getting clock\n"); - return PTR_ERR(ov5693->xvclk); - } - - xvclk_rate = clk_get_rate(ov5693->xvclk); - if (xvclk_rate != OV5693_XVCLK_FREQ) - dev_warn(&client->dev, "Found clk freq %u, expected %u\n", - xvclk_rate, OV5693_XVCLK_FREQ); - - ret = ov5693_configure_gpios(ov5693); - if (ret) - return ret; - - ret = ov5693_get_regulators(ov5693); - if (ret) - return dev_err_probe(&client->dev, ret, - "Error fetching regulators\n"); - ov5693->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; ov5693->pad.flags = MEDIA_PAD_FL_SOURCE; ov5693->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;