Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5530515ybl; Sun, 22 Dec 2019 08:06:57 -0800 (PST) X-Google-Smtp-Source: APXvYqxCRzw+p7bwgki9pupWoeQQKoLQ1Z/9+7IoTNLv/g9b97GshOY4usDtXmDw7ksVP5El3dWH X-Received: by 2002:a05:6830:22e2:: with SMTP id t2mr28100567otc.129.1577030817543; Sun, 22 Dec 2019 08:06:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577030817; cv=none; d=google.com; s=arc-20160816; b=gA9Mw1gKoPb1Xt3Ta2C1Hi0/Tp0/epbIH+3qXCBqKsKb3lC6RbfnnqrlwyEED9DViF M5L2+inoLb2B7ogyBljeyjrc1q1vMMgP9cUJOpUBPklRr7UAU++D/OFEYzebWWYT+nS+ Y/6FeT9BaymHx9OxUAsmtWXMAd3jh0JKsP5g+1lW75K1CQiOSQCrqW7APVIKNn5OWLmA 4kiLGuGpZs/bOfM6ex/15tjddT/oS/XDyBt3IaLEIW/2zuU3SBhx3TEtAc7OybJd23fP HgM+gD4oEjfBz7Ekzn4Rxf1UystELv6xORFW3Ho13tTHrPH/4gB4MAelB8D2fwhJIOJC Jq0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=weeav39dM9eY63yvlY7jfohEDeWVaImW8vTN8Hu0S5s=; b=ka7W501fDYV3tuPFBCgj9IcEhpQ4aGUDAM3FYl/tsbALBoUBC9BK5ZkhVL0bTNp6Gw QOVL9/rNEGaZGEP+dsPSzTx7QMYphYz7O7INCDDrDhZK3QDGiq4XrA8qFG2SDg/f8qTC 8Le4Wz4MN6MX6l2/YkTevBtpgQ2hRR1XYQNITI+OZdbJB9H7gb7AS9GZ9f94Xmqj69Bo LXEj7qeznU3qkUoP5AOOEQfU0bcJayHU27JBOm/IJjKx2ymTAAOGe8sIOVpCjBDPmL5u rTRy8Wyx9neKVovtzA4Tt4hH31QOkfLlnwHyRCvuBVYpiigTAs9cP3OVfsB3piTjea73 zfKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="RhCO6G/M"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g2si9002114otn.117.2019.12.22.08.06.46; Sun, 22 Dec 2019 08:06:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="RhCO6G/M"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726190AbfLVQGJ (ORCPT + 99 others); Sun, 22 Dec 2019 11:06:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:49006 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725903AbfLVQGJ (ORCPT ); Sun, 22 Dec 2019 11:06:09 -0500 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (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 8FF262070A; Sun, 22 Dec 2019 16:06:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577030767; bh=Sl2yx+lIrkKRhlpPMiDC1rjSdFHftcpX7mfEQyeZ20I=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=RhCO6G/MA3S/IylOiCv75UeAaV3VxlWxDc469AEtXzrcsJ9/JS+kRl0a81BMCOtFd ba/9oua7Rci6Jcnl93sfy4SzPdm3wsnuA0PJZun+WGiDA5hlMUi2akK00cvDUD5U2e FV0vndPp7uscHyRBUhSC6IuJpKuTCaWFLqXLZzBE= Date: Sun, 22 Dec 2019 16:06:02 +0000 From: Jonathan Cameron To: Dan Robertson Cc: linux-iio@vger.kernel.org, Peter Meerwald-Stadler , Andy Shevchenko , devicetree@vger.kernel.org, Hartmut Knaack , Rob Herring , Mark Rutland , linux-kernel@vger.kernel.org, Randy Dunlap , Joe Perches , Linus Walleij Subject: Re: [PATCH v8 3/3] iio: (bma400) basic regulator support Message-ID: <20191222160602.0f889650@archlinux> In-Reply-To: <20191220160051.26321-4-dan@dlrobertson.com> References: <20191220160051.26321-1-dan@dlrobertson.com> <20191220160051.26321-4-dan@dlrobertson.com> X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 20 Dec 2019 16:00:51 +0000 Dan Robertson wrote: > Add support for the VDD and VDDIO regulators using the regulator > framework. > > Signed-off-by: Dan Robertson I tweaked a little bit below to drop the select for REGULATOR. That should be unnecessary. Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it. Thanks, Jonathan > --- > drivers/iio/accel/Kconfig | 1 + > drivers/iio/accel/bma400.h | 4 ++++ > drivers/iio/accel/bma400_core.c | 39 ++++++++++++++++++++++++++++----- > 3 files changed, 39 insertions(+), 5 deletions(-) > > diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig > index 670e60568033..9cfe9c790190 100644 > --- a/drivers/iio/accel/Kconfig > +++ b/drivers/iio/accel/Kconfig > @@ -116,6 +116,7 @@ config BMA400 > tristate "Bosch BMA400 3-Axis Accelerometer Driver" > select REGMAP > select BMA400_I2C if I2C > + select REGULATOR You shouldn't need to select REGULATOR. There are stub functions such that I believe this code should still work fine without it. This assumes the regulators are always on, but that is valid for some platforms. > help > Say Y here if you want to build a driver for the Bosch BMA400 > triaxial acceleration sensor. > diff --git a/drivers/iio/accel/bma400.h b/drivers/iio/accel/bma400.h > index 15c0e307d2c4..5ad10db9819f 100644 > --- a/drivers/iio/accel/bma400.h > +++ b/drivers/iio/accel/bma400.h > @@ -86,6 +86,10 @@ > #define BMA400_SCALE_MIN 38357 > #define BMA400_SCALE_MAX 306864 > > +#define BMA400_NUM_REGULATORS 2 > +#define BMA400_VDD_REGULATOR 0 > +#define BMA400_VDDIO_REGULATOR 1 > + > extern const struct regmap_config bma400_regmap_config; > > int bma400_probe(struct device *dev, struct regmap *regmap, const char *name); > diff --git a/drivers/iio/accel/bma400_core.c b/drivers/iio/accel/bma400_core.c > index e7ba01e79d2c..61eb676e46be 100644 > --- a/drivers/iio/accel/bma400_core.c > +++ b/drivers/iio/accel/bma400_core.c > @@ -19,6 +19,7 @@ > #include > #include > #include > +#include > > #include "bma400.h" > > @@ -53,6 +54,7 @@ struct bma400_sample_freq { > struct bma400_data { > struct device *dev; > struct regmap *regmap; > + struct regulator_bulk_data regulators[BMA400_NUM_REGULATORS]; > struct mutex mutex; /* data register lock */ > struct iio_mount_matrix orientation; > enum bma400_power_mode power_mode; > @@ -573,17 +575,38 @@ static int bma400_init(struct bma400_data *data) > goto out; > } > > + data->regulators[BMA400_VDD_REGULATOR].supply = "vdd"; > + data->regulators[BMA400_VDDIO_REGULATOR].supply = "vddio"; > + ret = devm_regulator_bulk_get(data->dev, > + ARRAY_SIZE(data->regulators), > + data->regulators); > + if (ret) { > + if (ret != -EPROBE_DEFER) > + dev_err(data->dev, > + "Failed to get regulators: %d\n", > + ret); > + > + goto out; > + } > + ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators), > + data->regulators); > + if (ret) { > + dev_err(data->dev, "Failed to enable regulators: %d\n", > + ret); > + goto out; > + } > + > ret = bma400_get_power_mode(data); > if (ret) { > dev_err(data->dev, "Failed to get the initial power-mode\n"); > - goto out; > + goto err_reg_disable; > } > > if (data->power_mode != POWER_MODE_NORMAL) { > ret = bma400_set_power_mode(data, POWER_MODE_NORMAL); > if (ret) { > dev_err(data->dev, "Failed to wake up the device\n"); > - goto out; > + goto err_reg_disable; > } > /* > * TODO: The datasheet waits 1500us here in the example, but > @@ -596,15 +619,15 @@ static int bma400_init(struct bma400_data *data) > > ret = bma400_get_accel_output_data_rate(data); > if (ret) > - goto out; > + goto err_reg_disable; > > ret = bma400_get_accel_oversampling_ratio(data); > if (ret) > - goto out; > + goto err_reg_disable; > > ret = bma400_get_accel_scale(data); > if (ret) > - goto out; > + goto err_reg_disable; > > /* > * Once the interrupt engine is supported we might use the > @@ -614,6 +637,9 @@ static int bma400_init(struct bma400_data *data) > */ > return regmap_write(data->regmap, BMA400_ACC_CONFIG2_REG, 0x00); > > +err_reg_disable: > + regulator_bulk_disable(ARRAY_SIZE(data->regulators), > + data->regulators); > out: > return ret; > } > @@ -809,6 +835,9 @@ int bma400_remove(struct device *dev) > ret = bma400_set_power_mode(data, POWER_MODE_SLEEP); > mutex_unlock(&data->mutex); > > + regulator_bulk_disable(ARRAY_SIZE(data->regulators), > + data->regulators); > + > iio_device_unregister(indio_dev); > > return ret; > >