Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2793201lqz; Wed, 3 Apr 2024 08:46:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU1uo0FBXneT+CtUvdLxCdVYiFOfUHttbGOAiRqqutytNm0v7hJme7sFFJFPicgcgaozfBTNXKRPrVeS58FpQG8ACix0niSuERQCZ4hUg== X-Google-Smtp-Source: AGHT+IGvs6RNXLX6HucAz2JGFixnZVg91L7dwWyA3tdtum1lE5PjQmAIkv4HIdnf2WIfJf1YQEeg X-Received: by 2002:a05:6a00:4295:b0:6ea:d004:33c9 with SMTP id bx21-20020a056a00429500b006ead00433c9mr16543542pfb.30.1712159162136; Wed, 03 Apr 2024 08:46:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712159162; cv=pass; d=google.com; s=arc-20160816; b=GAQlIUGORzRed2RviwXUX40ckqXvxOux8N8Y2BUGn9XHSM+4EhLhxRyBZojcwhfvhS WV7ScJYUbLnQx+jAZZPEiCFpKqJWOMRDblKfPZ9LtIFuYq1opU+L0hQLMJ5Ni4RHB3Cm Hzoz61i1U6l7/BxNqxGcR2iTJCLZMv8DqJqUVGLkeqrzX7caGW9U598a1SgEQbExziZ9 kq95yvkiQ5zaxbiwnhSWjCoHtiR3bnG2vDQC3egCCYrzg5EVQR+7K/gpcxPf4VCVpABm L0b8KJClAVlDxxNn8OImpkQCTW6+oQl0gV+yQkERsNVkHbtySBltcEpQjOYC26opQ8YZ xAxg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=A5kWwvdwdEyuxBlVEZzJFt3zU0Ewr3vkitT5UsHdd40=; fh=ng0FUFwPgHHqIHtWcUlLUSBs0e7fHIUGeuUhfcQSRgA=; b=u8tMOlCJU+/eJT01BuHDJHjIM4TCEotbhT3FbFFoDXS/bA1fr6yF2tdmNi9oAmRsyO ssMh39OP7mrSBkLwGKYzcPWRnZ2ceefG/PHgGogiXV9sxKUAOjRfex1lvA4KRDo+9Iy7 KDiEJ9Rj7y9wW8B72lreUdsN+Dqp8+Ult5WnrD8mNXFGe5jGrK+NzI5kbZr94rqXLVUh YzZYHy9D/D3yxawl+nCkSlnVP3nQa1LdYFre1eLIGsIUNE8OnOgxwH8JsENxVy1Geq83 PgDwy/QZpH8Ue1Rf5rd7ocJoF8W4ytWjCegs/XkvWiL+347/7ptboLySRBiWIijercsE Tn9w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@luigi311.com header.s=x header.b="ZaQU/yoN"; arc=pass (i=1 spf=pass spfdomain=luigi311.com dkim=pass dkdomain=luigi311.com); spf=pass (google.com: domain of linux-kernel+bounces-130064-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130064-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id k191-20020a636fc8000000b005dc892e61d3si13527007pgc.657.2024.04.03.08.46.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 08:46:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-130064-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=fail header.i=@luigi311.com header.s=x header.b="ZaQU/yoN"; arc=pass (i=1 spf=pass spfdomain=luigi311.com dkim=pass dkdomain=luigi311.com); spf=pass (google.com: domain of linux-kernel+bounces-130064-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130064-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 50249B2F468 for ; Wed, 3 Apr 2024 15:15:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DFE3014D442; Wed, 3 Apr 2024 15:13:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b="ZaQU/yoN" Received: from mail-108-mta12.mxroute.com (mail-108-mta12.mxroute.com [136.175.108.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5768A14D2A4 for ; Wed, 3 Apr 2024 15:13:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=136.175.108.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712157183; cv=none; b=Wlvkoy8La3Iekfjs7Jj8s6wDtM393IiysH+Yq9pzqIFeFN/6Fs3Nue8kFOqt0jibbjvfRZGUAEqGnhKoDS8vGcpVB6d7FQEpYpXp4ZJmNeCC8Mc7T6fc/3ps8VmnFNhxZKVTNttl3Lz2pQ/CB7G9ik3VXRCEQon7mlv0DYQcUdY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712157183; c=relaxed/simple; bh=4l25b11Fcd1ojpReo0LLvRhKMjS2oSzJM5BnhKrlM8g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bqcK4VaMkvznLjsW7aWTOFjW7VvuohCGBx3yQjjsE6xi0P0Tjgm5LeDWqyKJdHjAoAPbNEkotx/BRNvALLbqgZ2wcRlu6s52LnGUWvnZfOs5kaJ7/in6lSA9DSjUQzfepKTcD2pRA2xDZwM2wZ2dh2impqjrQN8YolewtRk20uA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com; spf=pass smtp.mailfrom=luigi311.com; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b=ZaQU/yoN; arc=none smtp.client-ip=136.175.108.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=luigi311.com Received: from filter006.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta12.mxroute.com (ZoneMTA) with ESMTPSA id 18ea4802bee0003bea.010 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 03 Apr 2024 15:07:27 +0000 X-Zone-Loop: 7d8c67663be121e59ed047c53e08703ccaeb9f648036 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=luigi311.com; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=A5kWwvdwdEyuxBlVEZzJFt3zU0Ewr3vkitT5UsHdd40=; b=ZaQU/yoNNdDLSIvxxZWLSxfUMO hXQ3Ap6+bxIXT+jh0T7KMm2VghvUK4genIWrJDlYoLHC4zECr6LeDeR5otNgshT87T6t/rDWMEVrm vI544FXrpmV9Z78UqiTbRvgsDVhibml8Kq3JZNQLOniO46xDZyvq5Nz092/viWAxL2YYApYra/k3c XSfMbdYe7ayojLfEp8ErAO1YUs/15z7IxEnFK0tA0+goDYci7o+reAQD9IcAB0uzAasYUUR9Zf1Pv +T+Rg22eJwhYz3IJt4l44ISDLgZ2ab5u0DLCkrYgokaFH73gYM8y9QBzPOJhMxjDeD2WJXPkOZMqG 6jrLJf/w==; From: git@luigi311.com To: linux-media@vger.kernel.org Cc: dave.stevenson@raspberrypi.com, jacopo.mondi@ideasonboard.com, mchehab@kernel.org, robh@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, sakari.ailus@linux.intel.com, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, pavel@ucw.cz, phone-devel@vger.kernel.org, Luis Garcia Subject: [PATCH v3 05/25] media: i2c: imx258: Add regulator control Date: Wed, 3 Apr 2024 09:03:34 -0600 Message-ID: <20240403150355.189229-6-git@luigi311.com> In-Reply-To: <20240403150355.189229-1-git@luigi311.com> References: <20240403150355.189229-1-git@luigi311.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Authenticated-Id: personal@luigi311.com From: Dave Stevenson The device tree bindings define the relevant regulators for the sensor, so update the driver to request the regulators and control them at the appropriate times. Signed-off-by: Dave Stevenson Signed-off-by: Luis Garcia --- drivers/media/i2c/imx258.c | 42 +++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index df7ed4716762..495eaada2945 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -507,6 +508,16 @@ static const char * const imx258_test_pattern_menu[] = { "Pseudorandom Sequence (PN9)", }; +/* regulator supplies */ +static const char * const imx258_supply_name[] = { + /* Supplies can be enabled in any order */ + "vana", /* Analog (2.8V) supply */ + "vdig", /* Digital Core (1.2V) supply */ + "vif", /* IF (1.8V) supply */ +}; + +#define IMX258_NUM_SUPPLIES ARRAY_SIZE(imx258_supply_name) + /* Configurations for supported link frequencies */ #define IMX258_LINK_FREQ_634MHZ 633600000ULL #define IMX258_LINK_FREQ_320MHZ 320000000ULL @@ -611,6 +622,7 @@ struct imx258 { struct mutex mutex; struct clk *clk; + struct regulator_bulk_data supplies[IMX258_NUM_SUPPLIES]; }; static inline struct imx258 *to_imx258(struct v4l2_subdev *_sd) @@ -995,9 +1007,19 @@ static int imx258_power_on(struct device *dev) struct imx258 *imx258 = to_imx258(sd); int ret; + ret = regulator_bulk_enable(IMX258_NUM_SUPPLIES, + imx258->supplies); + if (ret) { + dev_err(dev, "%s: failed to enable regulators\n", + __func__); + return ret; + } + ret = clk_prepare_enable(imx258->clk); - if (ret) + if (ret) { dev_err(dev, "failed to enable clock\n"); + regulator_bulk_disable(IMX258_NUM_SUPPLIES, imx258->supplies); + } return ret; } @@ -1008,6 +1030,7 @@ static int imx258_power_off(struct device *dev) struct imx258 *imx258 = to_imx258(sd); clk_disable_unprepare(imx258->clk); + regulator_bulk_disable(IMX258_NUM_SUPPLIES, imx258->supplies); return 0; } @@ -1220,6 +1243,18 @@ static void imx258_free_controls(struct imx258 *imx258) mutex_destroy(&imx258->mutex); } +static int imx258_get_regulators(struct imx258 *imx258, + struct i2c_client *client) +{ + unsigned int i; + + for (i = 0; i < IMX258_NUM_SUPPLIES; i++) + imx258->supplies[i].supply = imx258_supply_name[i]; + + return devm_regulator_bulk_get(&client->dev, + IMX258_NUM_SUPPLIES, imx258->supplies); +} + static int imx258_probe(struct i2c_client *client) { struct imx258 *imx258; @@ -1230,6 +1265,11 @@ static int imx258_probe(struct i2c_client *client) if (!imx258) return -ENOMEM; + ret = imx258_get_regulators(imx258, client); + if (ret) + return dev_err_probe(&client->dev, ret, + "failed to get regulators\n"); + imx258->clk = devm_clk_get_optional(&client->dev, NULL); if (IS_ERR(imx258->clk)) return dev_err_probe(&client->dev, PTR_ERR(imx258->clk), -- 2.42.0