Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp403883iob; Fri, 13 May 2022 04:25:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5R2YS6DENk4dRilI5TGl4r9HkJzw4E7zd0m19n3h6AIpmrvoe8ZRS3q8lOJvPw8q1sqJB X-Received: by 2002:a17:907:3d91:b0:6f5:2b6a:ef55 with SMTP id he17-20020a1709073d9100b006f52b6aef55mr3921027ejc.352.1652441130776; Fri, 13 May 2022 04:25:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652441130; cv=none; d=google.com; s=arc-20160816; b=PIlCGUc4E/VHnerCLuwuJ/zq6XQiNO8TkzmpQ+vLNDRTnCFRqXaMtaK/GiSQ+dflJb Y1gV6iLN4ELulXc+wMZw5252PlofneSTb5u9gGBcX6dhds+po6QpdsuRZ0dsLzrYt3As oXE33A/M83U2iHQb9OQ4fhz45zIXmKWFuH6ZR7faf69Kt6y2dm+Hr7e5R8QgX/UvgkUz XAAKJSymckIbjeG18td9Qb22m9YkeKNgWpiXDZLjw9xEMdJLwVNF0CHY2r/Hh8mWG9uk AiFKkCxQW7roiyYme41Yawg6PFX7dNvWXOeel/Tgkn3p1iaBQhZ4QvEiYBDu1Nsl2/yu M7Tw== 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=Rn+hZ1SORWL9uzL+yqm22z/NAwpZAv/juhns1YUGhh8=; b=xPe/qmHX2euljys16JaLz7FwmzdiIfRDdb0eOEUaxtCL5bX75pFGYrp/7RdmDOU1mm 6Qnvu4cEySEKt+BhBLglQMw1X0i6Mibt0/hJDRoAXduuWLOSVn9Kesw8sr5GnMMhqLIe ZscMPM28l83nEHZ9d4kupygLoryabUftUJV03IpcLptqumlMkgJqomnJtuTsB+5UOXHw Vd3T55sCPcCvAMK5apQmHLqW2QiWDVw1/6iG9VlkkRQeDW+6nYIWKVJA/t/ZOpEtauuP Lg2lYHdK7pKW66LR01VCl3K1NWiBrnFn0PxYaljEDTTGd27PCuYwaL3aC3M0uqnKCJXm frOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="ajU/1Ksl"; 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 o5-20020a170906974500b006effb96ba86si1988403ejy.625.2022.05.13.04.25.04; Fri, 13 May 2022 04:25:30 -0700 (PDT) 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="ajU/1Ksl"; 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 S1353040AbiELLIe (ORCPT + 99 others); Thu, 12 May 2022 07:08:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352975AbiELLIa (ORCPT ); Thu, 12 May 2022 07:08:30 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23F795AA66; Thu, 12 May 2022 04:08:16 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id d15so8413239lfk.5; Thu, 12 May 2022 04:08:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rn+hZ1SORWL9uzL+yqm22z/NAwpZAv/juhns1YUGhh8=; b=ajU/1KslDh5E/JvduAifp/STGz5uzWKx00qJ8v53ttzKhbo9OG3iAW8XCQ+nAxTqzd ObDea9lIRsmxwKOXsIMP66Yn6U+ir+TM4Sw9TWaHTHVkfxN4BC5L0PI6JPVUKV1Z6oKf a/fIv2yTNeSqMgk8CNEBbkqEag6f2sa4BV5zj5LT9gQ+mzqJcz1p597Op10gRczAymH6 7bA3+DYGB8baVyqOGzlnSTNSmmHa9aex1za0ujck3B1c5QkN5C3c8K7kJKwEbOta4KAt Abxlk3XfUP5hAusIpx3qweO7sZcvk8jQI/6RscwjcXixXBqEMX1YQ1BiARkaC51R9IcK lZhA== 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=Rn+hZ1SORWL9uzL+yqm22z/NAwpZAv/juhns1YUGhh8=; b=pxVqao5/5kNTe2oa7d2Z/2lQMytftfMZ2ZNM8x48Lep40OwkrSOlKRqNZ2jVFKpUrr YqoMHPwYjHQduGoJFvpRRsr8mb9FcUSyQveM+g0AOiBFOXmOWtkZA4ZvWcqdKK+L+cMH oolwuKAgrL+SxCkW+OAmY9QrOrkPO52DiE0vtmXCiBSUreQ496XBMnXaFLAKem6MwN1I 9bAbkt6NxUam0Po2Ut78j93D3C0zeKseu4PQcFcFDU46+Fhm/A3n7W+JnPPIB+l8A4u3 2xU+/RgQEMAJUUWxU9r3Kbyaqz7qd+YcD06jfovJRoKAiHrZAkMqTCybYehqgq+C89Iu mkuQ== X-Gm-Message-State: AOAM532nEYgIZqF9LuM6KyMOJj9ZdzFpsY8EYo0AAFkxyKvawI8pBlv9 oi7Hzfei9UPq3cBrGH1gHn05j/MKBiexqA== X-Received: by 2002:a05:6512:3d1d:b0:472:625d:b21e with SMTP id d29-20020a0565123d1d00b00472625db21emr23991992lfv.366.1652353695101; Thu, 12 May 2022 04:08:15 -0700 (PDT) Received: from nergzd-desktop.localdomain ([194.39.226.133]) by smtp.gmail.com with ESMTPSA id i25-20020a056512007900b004725b99d2fdsm734883lfo.164.2022.05.12.04.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 04:08:14 -0700 (PDT) From: Markuss Broks To: linux-kernel@vger.kernel.org Cc: ~postmarketos/upstreaming@lists.sr.ht, phone-devel@vger.kernel.org, Markuss Broks , Konrad Dybcio , Marijn Suijten , AngeloGioacchino Del Regno , Song Qiang , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v3 3/5] proximity: vl53l0x: Handle the VDD regulator Date: Thu, 12 May 2022 14:07:55 +0300 Message-Id: <20220512110757.5297-4-markuss.broks@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220512110757.5297-1-markuss.broks@gmail.com> References: <20220512110757.5297-1-markuss.broks@gmail.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,T_SCC_BODY_TEXT_LINE 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 Handle the regulator supplying the VDD pin of VL53L0X. Signed-off-by: Markuss Broks --- drivers/iio/proximity/vl53l0x-i2c.c | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/iio/proximity/vl53l0x-i2c.c b/drivers/iio/proximity/vl53l0x-i2c.c index 12a3e2eff464..d8523e3981e8 100644 --- a/drivers/iio/proximity/vl53l0x-i2c.c +++ b/drivers/iio/proximity/vl53l0x-i2c.c @@ -43,6 +43,7 @@ struct vl53l0x_data { struct i2c_client *client; struct completion completion; + struct regulator *vdd_supply; }; static irqreturn_t vl53l0x_handle_irq(int irq, void *priv) @@ -192,10 +193,31 @@ static const struct iio_info vl53l0x_info = { .read_raw = vl53l0x_read_raw, }; +static void vl53l0x_power_off(void *_data) +{ + struct vl53l0x_data *data = _data; + + regulator_disable(data->vdd_supply); +} + +static int vl53l0x_power_on(struct vl53l0x_data *data) +{ + int ret; + + ret = regulator_enable(data->vdd_supply); + if (ret) + return ret; + + usleep_range(3200, 5000); + + return 0; +} + static int vl53l0x_probe(struct i2c_client *client) { struct vl53l0x_data *data; struct iio_dev *indio_dev; + int error; indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); if (!indio_dev) @@ -210,6 +232,21 @@ static int vl53l0x_probe(struct i2c_client *client) I2C_FUNC_SMBUS_BYTE_DATA)) return -EOPNOTSUPP; + data->vdd_supply = devm_regulator_get_optional(&client->dev, "vdd"); + if (IS_ERR(data->vdd_supply)) + return dev_err_probe(&client->dev, PTR_ERR(data->vdd_supply), + "Unable to get VDD regulator\n"); + + error = devm_add_action_or_reset(&client->dev, vl53l0x_power_off, data); + if (error) + return dev_err_probe(&client->dev, error, + "Failed to install poweroff action\n"); + + error = vl53l0x_power_on(data); + if (error) + return dev_err_probe(&client->dev, error, + "Failed to power on the chip\n"); + indio_dev->name = "vl53l0x"; indio_dev->info = &vl53l0x_info; indio_dev->channels = vl53l0x_channels; -- 2.36.1