Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2815807rwb; Fri, 9 Dec 2022 06:42:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf5GPPqfKhED2RC7hHdv7IDxmavefbkBta00lG65Gh6+VwIltwjtTV35DLsqKZZH0jryatYY X-Received: by 2002:a05:6a21:358c:b0:aa:3b85:1c2f with SMTP id az12-20020a056a21358c00b000aa3b851c2fmr8148011pzc.36.1670596934087; Fri, 09 Dec 2022 06:42:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670596934; cv=none; d=google.com; s=arc-20160816; b=hTMqjimxnnio21NrhQyRI/KnIRwl/Y5gqGffjth79jo1O9bw0Fef4+FM85DZH40XlJ NmybKPrn2bTR/hSaKtIpHDWjPt0z+Ua1IUF4VxcqZE4QIsQqZFV3LBHGqMPE+soqoWDZ qbOVuMXvkCGpS7xQMkxUVg/CToZssXGVKmWNA8ZlpKrvnv5bq3ufdJDhrLZ0A5MY6adL oxw/YLIrcE+RYrFmtfVLvlc7IkqGJmKJm8efsE/13YW0sFcZ8Y+zf9Oq6Ip8njGDIsgn R25dPU++m5wAdZKUNofkaSc0tBNf//Ipc1NSArnukyALZD2aP0AxezuR2+nDnJKC6kLQ QbXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=A09qABb0ead7LLA+4pGxEwf93dXTPbgLlbgE44UEqoI=; b=Z2yOfKH1kyYEXmjJMLEWCZ367MEM6x4T+dJWg2itUYx8Rce/nF4pGQvnEmT6vNYcxj fnntzJT3cJfcr69jB/ZYwLxpxRd97LZi4bJR4HcXwVRgqce97LVTSw3Sku6E+NKAN1Jc GxuW6V2SVkb/uNSAnqDz23uxOgHhD8my5E0jWQdn+rBEVtSODIYSFu2llm151mZFpoLt W8dnN2KjmHNqp3zW7aBjJyaGVfU//PUWB7k9jzSWwTMS5CwXdpVrg/M8ytd/GojcAFnV JFYN5VHwW2BFa+hx4YpG8myHWmj0Z3nNP3L0PkOqHJ5rU6vWACbwFC0vHJJqDpSXCfiv DhdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hcoeDm5B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i7-20020a6561a7000000b00470096ba718si1641441pgv.200.2022.12.09.06.42.03; Fri, 09 Dec 2022 06:42:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hcoeDm5B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229956AbiLIOiL (ORCPT + 75 others); Fri, 9 Dec 2022 09:38:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229910AbiLIOiF (ORCPT ); Fri, 9 Dec 2022 09:38:05 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2910522536; Fri, 9 Dec 2022 06:38:04 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id m4-20020a05600c3b0400b003d1cb516ce0so5900476wms.4; Fri, 09 Dec 2022 06:38:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=A09qABb0ead7LLA+4pGxEwf93dXTPbgLlbgE44UEqoI=; b=hcoeDm5BMAsucMZXIIyUFZqQpMkQdA6hKitiSo57m/EPBWs/+EItLpiWeMyx9PkNuc 4nadDV9bSHfJEhfg50MKuBCg5Q7eshOB8+/esaH3uMZlhU6/ZVjidsYdSd0k1UnDGMwH hM5jZ7AxG6HcFZZsCmiMLqocLhV5kjvMyzc9EvvU9dv//i6XUZnBR5OfbWyzjHYMuI9T W2qYS7vRsA4VXM2MfoFpeKbUoWuEjBcZVZuKYrUyQsK762Z9HX1UU1VFRfil5H2JilFL ef8A/0vdVUEXMbXoPh+I3KCTXl5/XVSFt7+qNgNyLh8Wm3N0P1ZqaXzLnA0Tv98Nx1m+ OLVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A09qABb0ead7LLA+4pGxEwf93dXTPbgLlbgE44UEqoI=; b=eSaahT4iYawMIYSdN+wxRMF5z2w2e2opq9NRCSsnv78W6+0rMI+8axdPxydj4XLADg V72DsctftnEfe7u4EUMvyKlmHi7IqEnshDQijE7gmMK4TLU9RUdExqtHmrV5cfts6ysw NBdZxrAcdH5aIUsYE1wT9TUBwMJjvq8RLE9brsz+RdBJkBnKr+a/7aA1HTGFtARHtgzR til3r/rBvistoZmAmwQ0ne5Ki048rq8ADKhXJagOj4wHEUhpPt6zgwgyUYoJV/bFRItt tWu3wU0eLgBDV7McX5qjTtDdtwn6XbWFXZX09qIksAbzMjTHw78pa/F/Wtgfx6SNVjyy imKA== X-Gm-Message-State: ANoB5pnh6rXFIDeGqpnlP861qmNGsyTu5DVVTBmDSIlw0UeJQjirmVfp atV04ZkcT5g1rGLbbUv84v8= X-Received: by 2002:a7b:c417:0:b0:3c6:e63e:8155 with SMTP id k23-20020a7bc417000000b003c6e63e8155mr5100647wmi.12.1670596682659; Fri, 09 Dec 2022 06:38:02 -0800 (PST) Received: from localhost.localdomain ([95.183.227.98]) by smtp.gmail.com with ESMTPSA id m31-20020a05600c3b1f00b003d1e3b1624dsm9645517wms.2.2022.12.09.06.38.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Dec 2022 06:38:02 -0800 (PST) From: Yassine Oudjana X-Google-Original-From: Yassine Oudjana To: Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Tianshu Qiu , Bingbu Cao Cc: Yassine Oudjana , Yassine Oudjana , Jacopo Mondi , Lee Jackson , Christophe JAILLET , Umang Jain , linux-media@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/3] media: i2c: ak7375: Add regulator management Date: Fri, 9 Dec 2022 17:37:41 +0300 Message-Id: <20221209143741.214242-4-y.oudjana@protonmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221209143741.214242-1-y.oudjana@protonmail.com> References: <20221209143741.214242-1-y.oudjana@protonmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yassine Oudjana Make the driver get needed regulators on probe and enable/disable them on runtime PM callbacks. Signed-off-by: Yassine Oudjana Tested-by: Umang Jain --- drivers/media/i2c/ak7375.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/media/i2c/ak7375.c b/drivers/media/i2c/ak7375.c index 1af9f698eecf..e7cec45bc271 100644 --- a/drivers/media/i2c/ak7375.c +++ b/drivers/media/i2c/ak7375.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -23,17 +24,29 @@ */ #define AK7375_CTRL_STEPS 64 #define AK7375_CTRL_DELAY_US 1000 +/* + * The vcm may take up 10 ms (tDELAY) to power on and start taking + * I2C messages. Based on AK7371 datasheet. + */ +#define AK7375_POWER_DELAY_US 10000 #define AK7375_REG_POSITION 0x0 #define AK7375_REG_CONT 0x2 #define AK7375_MODE_ACTIVE 0x0 #define AK7375_MODE_STANDBY 0x40 +static const char * const ak7375_supply_names[] = { + "vdd", + "vio", +}; + /* ak7375 device structure */ struct ak7375_device { struct v4l2_ctrl_handler ctrls_vcm; struct v4l2_subdev sd; struct v4l2_ctrl *focus; + struct regulator_bulk_data supplies[ARRAY_SIZE(ak7375_supply_names)]; + /* active or standby mode */ bool active; }; @@ -133,12 +146,24 @@ static int ak7375_probe(struct i2c_client *client) { struct ak7375_device *ak7375_dev; int ret; + unsigned int i; ak7375_dev = devm_kzalloc(&client->dev, sizeof(*ak7375_dev), GFP_KERNEL); if (!ak7375_dev) return -ENOMEM; + for (i = 0; i < ARRAY_SIZE(ak7375_supply_names); i++) + ak7375_dev->supplies[i].supply = ak7375_supply_names[i]; + + ret = devm_regulator_bulk_get(&client->dev, + ARRAY_SIZE(ak7375_supply_names), + ak7375_dev->supplies); + if (ret) { + dev_err_probe(&client->dev, ret, "Failed to get regulators\n"); + return ret; + } + v4l2_i2c_subdev_init(&ak7375_dev->sd, client, &ak7375_ops); ak7375_dev->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; ak7375_dev->sd.internal_ops = &ak7375_int_ops; @@ -208,6 +233,11 @@ static int __maybe_unused ak7375_vcm_suspend(struct device *dev) if (ret) dev_err(dev, "%s I2C failure: %d\n", __func__, ret); + ret = regulator_bulk_disable(ARRAY_SIZE(ak7375_supply_names), + ak7375_dev->supplies); + if (ret) + return ret; + ak7375_dev->active = false; return 0; @@ -228,6 +258,14 @@ static int __maybe_unused ak7375_vcm_resume(struct device *dev) if (ak7375_dev->active) return 0; + ret = regulator_bulk_enable(ARRAY_SIZE(ak7375_supply_names), + ak7375_dev->supplies); + if (ret) + return ret; + + /* Wait for vcm to become ready */ + usleep_range(AK7375_POWER_DELAY_US, AK7375_POWER_DELAY_US + 500); + ret = ak7375_i2c_write(ak7375_dev, AK7375_REG_CONT, AK7375_MODE_ACTIVE, 1); if (ret) { -- 2.38.1