From patchwork Thu Nov 19 09:13:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 11916889 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB27BC388F9 for ; Thu, 19 Nov 2020 09:14:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 471BE246D1 for ; Thu, 19 Nov 2020 09:14:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="C36Bx6kA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726292AbgKSJN7 (ORCPT ); Thu, 19 Nov 2020 04:13:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:39064 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726251AbgKSJN7 (ORCPT ); Thu, 19 Nov 2020 04:13:59 -0500 Received: from lore-desk.redhat.com (unknown [151.66.8.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B851D20679; Thu, 19 Nov 2020 09:13:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605777238; bh=bfCEQQJPf8vkeK4NqY63sz3J0KiTKTiBVoW0bylYY+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C36Bx6kA0EiCGd0/2EjNqUsEEQryaRilzIJ04lWvNFbo5UjPDIXps8LlWTIo53V5U vCeUxsz1syQgrhKUauk88nwq1mNvd5roWpSpAUBw1DGrlvssRX8BdcgUD5csJx9E5N Yd0xhDFkagT4wDijLYVTq75v34B8IJTgE2/jCrVE= From: Lorenzo Bianconi To: jic23@kernel.org Cc: lorenzo.bianconi@redhat.com, devicetree@vger.kernel.org, linux-iio@vger.kernel.org Subject: [PATCH 1/2] iio: humidity: hts221: add vdd voltage regulator Date: Thu, 19 Nov 2020 10:13:34 +0100 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Like all other ST sensors, hts221 devices have VDD power line. Introduce VDD voltage regulator to control it. Signed-off-by: Lorenzo Bianconi --- drivers/iio/humidity/hts221.h | 2 ++ drivers/iio/humidity/hts221_core.c | 39 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/drivers/iio/humidity/hts221.h b/drivers/iio/humidity/hts221.h index 721359e226cb..cf3d8d2dccd6 100644 --- a/drivers/iio/humidity/hts221.h +++ b/drivers/iio/humidity/hts221.h @@ -13,6 +13,7 @@ #define HTS221_DEV_NAME "hts221" #include +#include enum hts221_sensor_type { HTS221_SENSOR_H, @@ -29,6 +30,7 @@ struct hts221_hw { const char *name; struct device *dev; struct regmap *regmap; + struct regulator *vdd; struct iio_trigger *trig; int irq; diff --git a/drivers/iio/humidity/hts221_core.c b/drivers/iio/humidity/hts221_core.c index 16657789dc45..e1aa99dcf142 100644 --- a/drivers/iio/humidity/hts221_core.c +++ b/drivers/iio/humidity/hts221_core.c @@ -547,6 +547,37 @@ static const struct iio_info hts221_info = { static const unsigned long hts221_scan_masks[] = {0x3, 0x0}; +static int hts221_init_regulators(struct device *dev) +{ + struct iio_dev *iio_dev = dev_get_drvdata(dev); + struct hts221_hw *hw = iio_priv(iio_dev); + int err; + + hw->vdd = devm_regulator_get(dev, "vdd"); + if (IS_ERR(hw->vdd)) { + dev_err(dev, "failed to get vdd regulator: %ld\n", + PTR_ERR(hw->vdd)); + return PTR_ERR(hw->vdd); + } + + err = regulator_enable(hw->vdd); + if (err) { + dev_err(dev, "failed to enable vdd regulator: %d\n", err); + return err; + } + + msleep(50); + + return 0; +} + +static void hts221_chip_uninit(void *data) +{ + struct hts221_hw *hw = data; + + regulator_disable(hw->vdd); +} + int hts221_probe(struct device *dev, int irq, const char *name, struct regmap *regmap) { @@ -567,6 +598,14 @@ int hts221_probe(struct device *dev, int irq, const char *name, hw->irq = irq; hw->regmap = regmap; + err = hts221_init_regulators(dev); + if (err) + return err; + + err = devm_add_action_or_reset(dev, hts221_chip_uninit, hw); + if (err) + return err; + err = hts221_check_whoami(hw); if (err < 0) return err; From patchwork Thu Nov 19 09:13:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 11916891 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6352C2D0E4 for ; Thu, 19 Nov 2020 09:14:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 51B4920679 for ; Thu, 19 Nov 2020 09:14:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="ps6hGNrr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726621AbgKSJOB (ORCPT ); Thu, 19 Nov 2020 04:14:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:39094 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726251AbgKSJOB (ORCPT ); Thu, 19 Nov 2020 04:14:01 -0500 Received: from lore-desk.redhat.com (unknown [151.66.8.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 13CD6221F1; Thu, 19 Nov 2020 09:13:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605777241; bh=tfknIlNQ9OwoZap1SbWYKAIVoEIBaq9OGQk3lbsWs70=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ps6hGNrr4pjUiS1Vx6KWUt81esuqvdbAsZFU33xKb3gwBGGtlEVJEvIyYWOPhUhnz zfS4p+kY5uEUb8ZDmxZvo4kk8xf2ksOhsyR+bmP9uFpjANENhy1cVw+jM1pcIFgY0+ 5RjKscVnM9XpK5WcXxkxvmgT1B+7SgoOwufL2RKs= From: Lorenzo Bianconi To: jic23@kernel.org Cc: lorenzo.bianconi@redhat.com, devicetree@vger.kernel.org, linux-iio@vger.kernel.org Subject: [PATCH 2/2] dt-bindings: iio: humidity: hts221: introduce vdd regulator bindings Date: Thu, 19 Nov 2020 10:13:35 +0100 Message-Id: <5e8009b293f1d5160ecbcdd33e7332ba0192b96e.1605777052.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Signed-off-by: Lorenzo Bianconi --- Documentation/devicetree/bindings/iio/humidity/st,hts221.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/humidity/st,hts221.yaml b/Documentation/devicetree/bindings/iio/humidity/st,hts221.yaml index 396451c26728..53df083b3de6 100644 --- a/Documentation/devicetree/bindings/iio/humidity/st,hts221.yaml +++ b/Documentation/devicetree/bindings/iio/humidity/st,hts221.yaml @@ -26,6 +26,9 @@ properties: The interrupt/data ready line will be configured as open drain, which is useful if several sensors share the same interrupt line. + vdd-supply: + description: if defined provides VDD power to the sensor. + interrupts: maxItems: 1