Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3686265lfo; Mon, 23 May 2022 11:24:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZXIDRup47TQ+pAHjk2F9ybQwAtchvc4YWHeSeQ05WMMrLigNxdWIJysj0uLE8cMduG59v X-Received: by 2002:a62:1c50:0:b0:518:89bf:8b41 with SMTP id c77-20020a621c50000000b0051889bf8b41mr11303741pfc.60.1653330298664; Mon, 23 May 2022 11:24:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653330298; cv=none; d=google.com; s=arc-20160816; b=M17BMyh1Gdjb5Z2c416YQhU9zdSXCCziOSAd+IVNdSjTyYq2ZNzV3PEzenufze5qWP ksFiQIu3YcnPl1xnNb0fKCYa0hXZNHhxYb9AqYy3LTKVo0pambaV5mqyakYpRl3yKfdl wjImTPXAPk97pHsiICixJN4p70aLliT/ElfEVJ4aazo5yZlqvf0mUKQ0wX6JVS2vOEGr 8ljCsrr3t2uRHE2oKu9D6sSbSBn5I/gOdoV00opkpHhJUHCCDKjKDwcfM94kfVmlj95Z EuGmm5WWPBppOezPQ8NDqE270Q7WfN9DDNVZ/7Bwg47Sv5CSPVzWoOUhQC/NqBPNexmR nFiw== 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=Y6hTyWxvALgSndQqmiLi+9G4p6MJh+4j+g2xm+AL/rQ=; b=CkGo0pS7Zxz8A0vOu1v8tolg0dO9dF61X06V3MpnrGelVs+q/05fCodxqD1U/4fxBt FDHkdayP46t1JrsVZdTWqT5z2CAKAG34ja3MaXvzWA39TtuHO3sB8X/R1Q5U+wu3k2ZR 8G5NZqfCZ1B7ZXQ0y7dU8L2QGOxrEtnRhAZ+nSu2x1CLaRflIR27UjFtTnTVgtzpi1Uo sjqG9YMQ7Hd14MohosYcLmZmdS0XVDxRSVawK966j/zSRuT1h3DBP4G8nSj0eDN0/qe7 JGt7tkVGa+5uojvYxO/7WYZzVCjIade8RBZ0fTY1L9c4IfgKPsMmR1lmzFGRvIHEesI0 bIGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Fu1TwoaH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b21-20020a170902d31500b0015f4370afbdsi10702184plc.516.2022.05.23.11.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 11:24:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Fu1TwoaH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 09A631A29C9; Mon, 23 May 2022 11:24:54 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237012AbiEWSTi (ORCPT + 99 others); Mon, 23 May 2022 14:19:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245646AbiEWSSV (ORCPT ); Mon, 23 May 2022 14:18:21 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AB37532C4; Mon, 23 May 2022 10:57:04 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id p22so26857179lfo.10; Mon, 23 May 2022 10:57:04 -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=Y6hTyWxvALgSndQqmiLi+9G4p6MJh+4j+g2xm+AL/rQ=; b=Fu1TwoaH71RgsLqaTGIn/HgL6qa17UmpMWrT7+W1uGedTEO6N8eXEpuYqQUxBb+CwN rZZrB8FbohFtveKYHP9kDfVxOorwGzHB0F24zlHvpA/3tHZuZ9p+CadRMUsx2RwizC3I KBHiCcrqzjHd2FXzUNZbb0/DhRoXPIUxuRC1ADLxFblesPKPdIXAMX+SMxCKzrZ3K01R W2b79qIdMbAyYb7oix7yyZJ2SHou9ZVS4qKKz3bysqZxnYF2jRPSLFh7ipdvsGSxRaXo d1VvK72AY89uEfUTSLP7uDMsv3lNndDVblKqBO78AZvIGYjQfMcFAgCpRAP+1VdUJDdU tLTQ== 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=Y6hTyWxvALgSndQqmiLi+9G4p6MJh+4j+g2xm+AL/rQ=; b=aHtPUZRjbjDx9lLasX5PrMFxaXzvcnKNoPawRy1+eotJLlSHr8kBJVXJrIkH0LsHQp DKa/ZjXza9dNHhnVoo/OK5pHeoBs43OYPOaAkT8lIo9LMX2eMxA4bNB65L3NaM9tJxuO j1ktyTKB1L9A1Pl1DDsxSb+aL6285GETjdXWf0eT0Vd8BD/lRlqzFZXE1MfQoilhRHco Q6BYoWeAqB0Tqi8cqD1zo8SLMVAZiNu9R6vKfZndk49kG5mS6rwX8x8HhijpFNhD7S7w HY6GsPIdF64VVaqA6cyDqRuTRnkbMXyEIBEwzkw4WcORHAKVb2tyVnwVzGs/UOVP7WuF BFXQ== X-Gm-Message-State: AOAM530beW2gd3sMQ9STnGBFLfP8kphRbMkcV03shlkGnCGFEXdCOWtn ct8oItquUZkN9p0UnwTNp5PGPrLG75GIeg== X-Received: by 2002:a19:5f13:0:b0:477:b3a2:30b8 with SMTP id t19-20020a195f13000000b00477b3a230b8mr17035659lfb.683.1653328476133; Mon, 23 May 2022 10:54:36 -0700 (PDT) Received: from nergzd-desktop.localdomain ([194.39.226.133]) by smtp.gmail.com with ESMTPSA id x9-20020a056512078900b0047255d211f9sm2087743lfr.296.2022.05.23.10.54.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 10:54:35 -0700 (PDT) From: Markuss Broks To: linux-kernel@vger.kernel.org, jic23@kernel.org Cc: ~postmarketos/upstreaming@lists.sr.ht, phone-devel@vger.kernel.org, Markuss Broks , Konrad Dybcio , Marijn Suijten , AngeloGioacchino Del Regno , Song Qiang , 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 3/5] proximity: vl53l0x: Handle the VDD regulator Date: Mon, 23 May 2022 20:53:42 +0300 Message-Id: <20220523175344.5845-4-markuss.broks@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523175344.5845-1-markuss.broks@gmail.com> References: <20220523175344.5845-1-markuss.broks@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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..8581a873919f 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 = vl53l0x_power_on(data); + if (error) + return dev_err_probe(&client->dev, error, + "Failed to power on the chip\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"); + indio_dev->name = "vl53l0x"; indio_dev->info = &vl53l0x_info; indio_dev->channels = vl53l0x_channels; -- 2.36.1