From patchwork Wed Dec 2 09:33:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Gerhold X-Patchwork-Id: 11945417 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, 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 DA448C64E8A for ; Wed, 2 Dec 2020 09:36:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 825D522202 for ; Wed, 2 Dec 2020 09:36:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387875AbgLBJgi (ORCPT ); Wed, 2 Dec 2020 04:36:38 -0500 Received: from mo4-p01-ob.smtp.rzone.de ([81.169.146.167]:25951 "EHLO mo4-p01-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387862AbgLBJgh (ORCPT ); Wed, 2 Dec 2020 04:36:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1606901625; s=strato-dkim-0002; d=gerhold.net; h=Message-Id:Date:Subject:Cc:To:From:X-RZG-CLASS-ID:X-RZG-AUTH:From: Subject:Sender; bh=+tabjWJ5R9tTtmp7BaWruIhTyrSUJG+kEDyYj1n7Eq0=; b=jValNypmsRujcmxnBrWqgPpst1SOeq5NM8DejlULL8OU/5/hou6+OUXgLn174svB2b 6s43IJki3FpL7hdRy6mz4y+u7P28yji3sOxXCCPwrncSsqrWEAnhPz0uqWvAGMsOtyOz DBT4lN9rVF9hBn28w8IrfwNYFKSOyslZeWkDiChyWC6sIkHxOLPvgt2yd3Ypq0wqgboI e0CW/tdGwsrHwpF6f33w3AZP0WWotINBD81hXU67wanSHdEA26AFcjcJS5FOHvoHKrHt RMM97d/RIUD48npDZXaTzwD+R9WZCjRds+j5153UNwzAxRfLpHYSdXctFzy92MXknmmW ZJ8w== X-RZG-AUTH: ":P3gBZUipdd93FF5ZZvYFPugejmSTVR2nRPhVORvLd4SsytBXS7IYBkLahKxB626NJkxR" X-RZG-CLASS-ID: mo00 Received: from localhost.localdomain by smtp.strato.de (RZmta 47.3.4 SBL|AUTH) with ESMTPSA id Z061efwB29XbVuV (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 2 Dec 2020 10:33:37 +0100 (CET) From: Stephan Gerhold To: Jonathan Cameron Cc: Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, "H . Nikolaus Schaller" , Linus Walleij , Stephan Gerhold Subject: [PATCH 1/4] dt-bindings: iio: magnetometer: bmc150: Document regulator supplies Date: Wed, 2 Dec 2020 10:33:19 +0100 Message-Id: <20201202093322.77114-1-stephan@gerhold.net> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org BMC150 needs VDD and VDDIO regulators that might need to be explicitly enabled. Document support for vdd/vddio-supply to implement this. Signed-off-by: Stephan Gerhold Reviewed-by: Linus Walleij Reviewed-by: Rob Herring --- .../bindings/iio/magnetometer/bosch,bmc150_magn.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/magnetometer/bosch,bmc150_magn.yaml b/Documentation/devicetree/bindings/iio/magnetometer/bosch,bmc150_magn.yaml index cdef7aeba708..2867ab6bf9b0 100644 --- a/Documentation/devicetree/bindings/iio/magnetometer/bosch,bmc150_magn.yaml +++ b/Documentation/devicetree/bindings/iio/magnetometer/bosch,bmc150_magn.yaml @@ -30,6 +30,9 @@ properties: reg: maxItems: 1 + vdd-supply: true + vddio-supply: true + interrupts: maxItems: 1 From patchwork Wed Dec 2 09:33:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Gerhold X-Patchwork-Id: 11945419 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 82E6EC64E7C for ; Wed, 2 Dec 2020 09:36:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 33D3522203 for ; Wed, 2 Dec 2020 09:36:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387862AbgLBJgi (ORCPT ); Wed, 2 Dec 2020 04:36:38 -0500 Received: from mo4-p02-ob.smtp.rzone.de ([85.215.255.81]:27568 "EHLO mo4-p02-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387860AbgLBJgi (ORCPT ); Wed, 2 Dec 2020 04:36:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1606901625; s=strato-dkim-0002; d=gerhold.net; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=1ePQH0/RVXsCzCLZhCC6D/7gY6cMj/NHBqH3xq8ktbo=; b=r8QPmuuFG4O2MMaQZrMUN6EXRUZwZH6j5XcBnIHApuZ7w+Ntd0p+7Gk110FNHxgZdA mFz9yQPf9QDCofOkQ+KmyKFWFniGfGdnnldDTk8WEAu4T44OPCNvSYk4JgHnwjRingAx zOvemTnVVjk9BuN3xdCY59nOhlivqXpnscXs4aiIXLN+ka1e+9MXJtUBkidMTHiHmEwr siTDOiPovI58F55u7l8qg1c7/BWOR2z6EhF4JEIHgOugLTw5+Ii0Gfer2Jzw0Wohl1Ho Q+65F75t1udN3dNQ0f4MCmgcYnZrzLjJ12L+d1GsN5v926aRtd62YYzDZAUD5XkXcKfc EM8w== X-RZG-AUTH: ":P3gBZUipdd93FF5ZZvYFPugejmSTVR2nRPhVORvLd4SsytBXS7IYBkLahKxB626NJkxR" X-RZG-CLASS-ID: mo00 Received: from localhost.localdomain by smtp.strato.de (RZmta 47.3.4 SBL|AUTH) with ESMTPSA id Z061efwB29XcVub (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 2 Dec 2020 10:33:38 +0100 (CET) From: Stephan Gerhold To: Jonathan Cameron Cc: Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, "H . Nikolaus Schaller" , Linus Walleij , Stephan Gerhold Subject: [PATCH 2/4] iio: magnetometer: bmc150: Add rudimentary regulator support Date: Wed, 2 Dec 2020 10:33:20 +0100 Message-Id: <20201202093322.77114-2-stephan@gerhold.net> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201202093322.77114-1-stephan@gerhold.net> References: <20201202093322.77114-1-stephan@gerhold.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org BMC150 needs VDD and VDDIO regulators that might need to be explicitly enabled. Add some rudimentary support to obtain and enable these regulators during probe() and disable them during remove() or on the error path. Signed-off-by: Stephan Gerhold Reviewed-by: Linus Walleij --- This is mostly copy-paste of 079c1c3f2082 ("iio: accel: bmc150-accel: Add rudimentary regulator support") from Linus Walleij but for the BMC150 magnetometer driver. --- drivers/iio/magnetometer/bmc150_magn.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c index fa09fcab620a..b2f3129e1b4f 100644 --- a/drivers/iio/magnetometer/bmc150_magn.c +++ b/drivers/iio/magnetometer/bmc150_magn.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "bmc150_magn.h" @@ -135,6 +136,7 @@ struct bmc150_magn_data { */ struct mutex mutex; struct regmap *regmap; + struct regulator_bulk_data regulators[2]; struct iio_mount_matrix orientation; /* 4 x 32 bits for x, y z, 4 bytes align, 64 bits timestamp */ s32 buffer[6]; @@ -692,12 +694,24 @@ static int bmc150_magn_init(struct bmc150_magn_data *data) int ret, chip_id; struct bmc150_magn_preset preset; + ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators), + data->regulators); + if (ret < 0) { + dev_err(data->dev, "Failed to enable regulators: %d\n", ret); + return ret; + } + /* + * 3ms power-on time according to datasheet, let's better + * be safe than sorry and set this delay to 5ms. + */ + msleep(5); + ret = bmc150_magn_set_power_mode(data, BMC150_MAGN_POWER_MODE_SUSPEND, false); if (ret < 0) { dev_err(data->dev, "Failed to bring up device from suspend mode\n"); - return ret; + goto err_regulator_disable; } ret = regmap_read(data->regmap, BMC150_MAGN_REG_CHIP_ID, &chip_id); @@ -752,6 +766,8 @@ static int bmc150_magn_init(struct bmc150_magn_data *data) err_poweroff: bmc150_magn_set_power_mode(data, BMC150_MAGN_POWER_MODE_SUSPEND, true); +err_regulator_disable: + regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators); return ret; } @@ -867,6 +883,13 @@ int bmc150_magn_probe(struct device *dev, struct regmap *regmap, data->irq = irq; data->dev = dev; + data->regulators[0].supply = "vdd"; + data->regulators[1].supply = "vddio"; + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->regulators), + data->regulators); + if (ret) + return dev_err_probe(dev, ret, "failed to get regulators\n"); + ret = iio_read_mount_matrix(dev, "mount-matrix", &data->orientation); if (ret) @@ -984,6 +1007,7 @@ int bmc150_magn_remove(struct device *dev) bmc150_magn_set_power_mode(data, BMC150_MAGN_POWER_MODE_SUSPEND, true); mutex_unlock(&data->mutex); + regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators); return 0; } EXPORT_SYMBOL(bmc150_magn_remove); From patchwork Wed Dec 2 09:33:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Gerhold X-Patchwork-Id: 11945413 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,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 B867DC64E8A for ; Wed, 2 Dec 2020 09:36:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5CF6B2222A for ; Wed, 2 Dec 2020 09:36:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387645AbgLBJgc (ORCPT ); Wed, 2 Dec 2020 04:36:32 -0500 Received: from mo4-p02-ob.smtp.rzone.de ([81.169.146.171]:28837 "EHLO mo4-p02-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728145AbgLBJgc (ORCPT ); Wed, 2 Dec 2020 04:36:32 -0500 X-Greylist: delayed 3422 seconds by postgrey-1.27 at vger.kernel.org; Wed, 02 Dec 2020 04:36:31 EST DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1606901620; s=strato-dkim-0002; d=gerhold.net; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=SG5xVAaGLAUccFX3LQt43sv4uywqw6E+YEUD++Uwcsc=; b=kmxJXywnRsrl+TnJeskU0TTrASPzmnoObUpI+rZHMvz9ruV5yjqJN+WYrSY+aYfa9v D1l8XjOmmSFUGh8HMcHdUs3JmWO30vjccFJhfVQXUc83faRlwHmUhlUvqOzNjU6OQpBh VhgPzsjnBJ225rDyVkrtfeAz6hAH7DfFbL0wkrDa55zIxhyde3cNcDBfIZEl9YQk5GcT eOaJcg+ZJH0MrEujfLxgl3UoN7+L2i9xQC6EgFsiVnjZXbWh27b0ocU1na4MJ264WCHq n3nvS94RU/DwcYYfJwkhxe/W7Ycv/XaEfQusUX2xcj2iKxeOLzl4+wI++kDLqlGQFnkT r8vw== X-RZG-AUTH: ":P3gBZUipdd93FF5ZZvYFPugejmSTVR2nRPhVORvLd4SsytBXS7IYBkLahKxB626NJkxR" X-RZG-CLASS-ID: mo00 Received: from localhost.localdomain by smtp.strato.de (RZmta 47.3.4 SBL|AUTH) with ESMTPSA id Z061efwB29XcVud (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 2 Dec 2020 10:33:38 +0100 (CET) From: Stephan Gerhold To: Jonathan Cameron Cc: Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, "H . Nikolaus Schaller" , Linus Walleij , Stephan Gerhold Subject: [PATCH 3/4] dt-bindings: iio: gyroscope: bmg160: Document regulator supplies Date: Wed, 2 Dec 2020 10:33:21 +0100 Message-Id: <20201202093322.77114-3-stephan@gerhold.net> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201202093322.77114-1-stephan@gerhold.net> References: <20201202093322.77114-1-stephan@gerhold.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org BMG160 needs VDD and VDDIO regulators that might need to be explicitly enabled. Document support for vdd/vddio-supply to implement this. Signed-off-by: Stephan Gerhold Reviewed-by: Linus Walleij Reviewed-by: Rob Herring --- .../devicetree/bindings/iio/gyroscope/bosch,bmg160.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/gyroscope/bosch,bmg160.yaml b/Documentation/devicetree/bindings/iio/gyroscope/bosch,bmg160.yaml index 0466483be6bb..b6bbc312a7cf 100644 --- a/Documentation/devicetree/bindings/iio/gyroscope/bosch,bmg160.yaml +++ b/Documentation/devicetree/bindings/iio/gyroscope/bosch,bmg160.yaml @@ -19,6 +19,9 @@ properties: reg: maxItems: 1 + vdd-supply: true + vddio-supply: true + interrupts: minItems: 1 description: From patchwork Wed Dec 2 09:33:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Gerhold X-Patchwork-Id: 11945415 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, 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 C9EE7C83012 for ; Wed, 2 Dec 2020 09:36:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6860422203 for ; Wed, 2 Dec 2020 09:36:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387700AbgLBJge (ORCPT ); Wed, 2 Dec 2020 04:36:34 -0500 Received: from mo4-p02-ob.smtp.rzone.de ([85.215.255.80]:8905 "EHLO mo4-p02-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728186AbgLBJgd (ORCPT ); Wed, 2 Dec 2020 04:36:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1606901620; s=strato-dkim-0002; d=gerhold.net; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=8AzvBxYHcbQK6J3mGTGm0CjFjQYtv52+YMdToRBbhW8=; b=hcJHInpzKmPtu5Io+B355PgyeEZKDsJUJQJmKMWDlXiRNl9DR4h/xNkWFo86FBFxLG tPC8Ki/2O10oTp2hBiDkSfjeFnIQkm0jZ3pOU+Va7EofMGrpQstSw0qhMNpm+E5oyIzj RDHxrpG8OZGZQBSmcBaP3Ir1CRj/RvI5JrMdxWClK+RI3dFszVZaGshVsuxnc8kXac84 76v+BJm+hL746m8e9YpMTbNU6s95rQK8vZw1wD7+fvO3WeV/iQ4YF++SPouJbm+yny8K aniM3y7VzjrNuw4D3Th27vvvTzeQlmyAyzMrKLlmGMtXS2UhXzqZ/aWwhZuaRoAtiaKH sMkQ== X-RZG-AUTH: ":P3gBZUipdd93FF5ZZvYFPugejmSTVR2nRPhVORvLd4SsytBXS7IYBkLahKxB626NJkxR" X-RZG-CLASS-ID: mo00 Received: from localhost.localdomain by smtp.strato.de (RZmta 47.3.4 SBL|AUTH) with ESMTPSA id Z061efwB29XdVue (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 2 Dec 2020 10:33:39 +0100 (CET) From: Stephan Gerhold To: Jonathan Cameron Cc: Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, "H . Nikolaus Schaller" , Linus Walleij , Stephan Gerhold Subject: [PATCH 4/4] iio: gyro: bmg160: Add rudimentary regulator support Date: Wed, 2 Dec 2020 10:33:22 +0100 Message-Id: <20201202093322.77114-4-stephan@gerhold.net> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201202093322.77114-1-stephan@gerhold.net> References: <20201202093322.77114-1-stephan@gerhold.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org BMG160 needs VDD and VDDIO regulators that might need to be explicitly enabled. Add some rudimentary support to obtain and enable these regulators during probe() and disable them during remove() or on the error path. Signed-off-by: Stephan Gerhold Reviewed-by: Linus Walleij --- drivers/iio/gyro/bmg160_core.c | 38 +++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/drivers/iio/gyro/bmg160_core.c b/drivers/iio/gyro/bmg160_core.c index 2d5015801a75..4baa4169c5a2 100644 --- a/drivers/iio/gyro/bmg160_core.c +++ b/drivers/iio/gyro/bmg160_core.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "bmg160.h" #define BMG160_IRQ_NAME "bmg160_event" @@ -92,6 +93,7 @@ struct bmg160_data { struct regmap *regmap; + struct regulator_bulk_data regulators[2]; struct iio_trigger *dready_trig; struct iio_trigger *motion_trig; struct iio_mount_matrix orientation; @@ -1077,14 +1079,28 @@ int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq, data->irq = irq; data->regmap = regmap; + data->regulators[0].supply = "vdd"; + data->regulators[1].supply = "vddio"; + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->regulators), + data->regulators); + if (ret) + return dev_err_probe(dev, ret, "Failed to get regulators\n"); + ret = iio_read_mount_matrix(dev, "mount-matrix", &data->orientation); if (ret) return ret; + ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators), + data->regulators); + if (ret < 0) { + dev_err(dev, "Failed to enable regulators: %d\n", ret); + return ret; + } + ret = bmg160_chip_init(data); if (ret < 0) - return ret; + goto err_regulator_disable; mutex_init(&data->mutex); @@ -1107,28 +1123,32 @@ int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq, BMG160_IRQ_NAME, indio_dev); if (ret) - return ret; + goto err_regulator_disable; data->dready_trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, indio_dev->id); - if (!data->dready_trig) - return -ENOMEM; + if (!data->dready_trig) { + ret = -ENOMEM; + goto err_regulator_disable; + } data->motion_trig = devm_iio_trigger_alloc(dev, "%s-any-motion-dev%d", indio_dev->name, indio_dev->id); - if (!data->motion_trig) - return -ENOMEM; + if (!data->motion_trig) { + ret = -ENOMEM; + goto err_regulator_disable; + } data->dready_trig->dev.parent = dev; data->dready_trig->ops = &bmg160_trigger_ops; iio_trigger_set_drvdata(data->dready_trig, indio_dev); ret = iio_trigger_register(data->dready_trig); if (ret) - return ret; + goto err_regulator_disable; data->motion_trig->dev.parent = dev; data->motion_trig->ops = &bmg160_trigger_ops; @@ -1174,6 +1194,8 @@ int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq, iio_trigger_unregister(data->dready_trig); if (data->motion_trig) iio_trigger_unregister(data->motion_trig); +err_regulator_disable: + regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators); return ret; } @@ -1200,6 +1222,8 @@ void bmg160_core_remove(struct device *dev) mutex_lock(&data->mutex); bmg160_set_mode(data, BMG160_MODE_DEEP_SUSPEND); mutex_unlock(&data->mutex); + + regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators); } EXPORT_SYMBOL_GPL(bmg160_core_remove);