Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp5132191ybx; Sun, 10 Nov 2019 07:34:59 -0800 (PST) X-Google-Smtp-Source: APXvYqyYdMCtYZG3eO4GQ0VkFu3ApttYKDlFvZGO7ZwOmRt5Mf2k1X79yz27XzBSN40iWXtOTAZb X-Received: by 2002:a17:906:4697:: with SMTP id a23mr18106427ejr.322.1573400099340; Sun, 10 Nov 2019 07:34:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573400099; cv=none; d=google.com; s=arc-20160816; b=x+pxEQUgMyUzMFCe31L2PV6M76mcad/O2DF4LX6VVAp2y9UP5QoqdD91dMuR2qXugr 7sBbg3n8VYB3VLoa4InaGnEmCZasehHRO38tuWJrX1H644zbVW74q4bjQn0NIbjkBJCI oRl6Fwah4KK5k0KLAvl8Hrbz3nP7tcWdDZ2BxrfInHQqJSTvR8jLH8c0Y/HchvOPx5Na +7j114zG+FrqkGYxcGybmjjkAMi3fqxBOfeIt9CeFppN/OmSSqCEXeJ/RZaKBMeodShQ ieHtUnoSP0RM/HuqFx8fdmciC910sHodW7rhkNt9BfHM8SrmgxgyNzAM9MPb2mYe+4K+ M+7w== 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=LX8KXL0q3RZ7ga5lA9eN+iTKVV5nSqerIBaOzuoKEXw=; b=OWC3r7DZ66mFhyRkwPJ6j+tdTeoDB8MvYsNOnzzTMAgQUu6gdy/QI8XfDqWN/44Cnq owQBCWurZ/eEoVgsNKptJQJ/bkijpOi6Lf948S8VqHWkT4OEXtwWjct1lXnwestd/9Vs Pjfy0AHdS9v/PrnoUFFuG3GpmDnfMYvWM2lu/xbmZ3AlTJou+hscAUv2yf+V/DQrHp6d cquAtV3yxQaOr1zinl//xunMxs3dL90aAsGpLRqAELYkTlAoGE8NuAzh6Z0F6lOtyOHG WWiCNzofVqJNJ44asYzNGaaAH0QGB+Zfkv8p5B0X5cV6xDJfE4XxCnF98MSNk+EZFDZT wWBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bztF040k; 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 e12si6889879ejr.39.2019.11.10.07.34.36; Sun, 10 Nov 2019 07:34:59 -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=bztF040k; 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 S1726923AbfKJPbW (ORCPT + 99 others); Sun, 10 Nov 2019 10:31:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:53642 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726653AbfKJPbV (ORCPT ); Sun, 10 Nov 2019 10:31:21 -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 F356E20818; Sun, 10 Nov 2019 15:31:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573399880; bh=UztXM8ShL4PmEpfWnj8q6bHUnpj2qjXDwcqfBgHkOGc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=bztF040k6mX36MiVWNW25Apy00yVe5wdd5PD0uy659MGncCqgGEyzQeB0snEXshUB AzmDfvMaQeC/Ts/yj3MywFLxAuygzL8zvtFSBtJkKk2GyrNCK4qpmbRTkq9SHudi/g RI7qs3kwjdvjndMpLO+1Q8EIIQ5iDq0VpYLK//rM= Date: Sun, 10 Nov 2019 15:31:14 +0000 From: Jonathan Cameron To: Stephan Gerhold Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Mark Rutland , Linus Walleij , Brian Masney , Jonathan Marek , Jean-Baptiste Maneyrol , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/2] iio: imu: mpu6050: Add support for vdd-supply regulator Message-ID: <20191110153114.687ce6fb@archlinux> In-Reply-To: <20191107184342.20361-2-stephan@gerhold.net> References: <20191107184342.20361-1-stephan@gerhold.net> <20191107184342.20361-2-stephan@gerhold.net> 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 Thu, 7 Nov 2019 19:43:42 +0100 Stephan Gerhold wrote: > MPU6050 has two power supply pins: VDD and VLOGIC, but the > mpu6050 driver only supports enabling one of them at the moment. > In some cases, they may need to be enabled separately. > > Add an additional "vdd-supply" that stays enabled for as long as > the driver is loaded. We cannot turn off the VDD regulator during > suspend as this would cause register settings (FSR, sampling rate, ...) > to be lost. > > Signed-off-by: Stephan Gerhold Looks good to me. Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to poke it. Thanks Jonathan > --- > Changes in v2: > - Keep "vdd-supply" enabled during suspend to prevent register > settings from getting lost. > - Revert convertion to bulk regulator API (does not work well > when regulators need to be enabled/disabled separately) > > v1: https://lore.kernel.org/linux-iio/20191106183536.123070-2-stephan@gerhold.net/ > --- > drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 43 +++++++++++++++++----- > drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 4 +- > 2 files changed, 37 insertions(+), 10 deletions(-) > > diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c > index 354030e9bed5..661a829478f5 100644 > --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c > +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c > @@ -1140,14 +1140,14 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st) > return result; > } > > -static int inv_mpu_core_enable_regulator(struct inv_mpu6050_state *st) > +static int inv_mpu_core_enable_regulator_vddio(struct inv_mpu6050_state *st) > { > int result; > > result = regulator_enable(st->vddio_supply); > if (result) { > dev_err(regmap_get_device(st->map), > - "Failed to enable regulator: %d\n", result); > + "Failed to enable vddio regulator: %d\n", result); > } else { > /* Give the device a little bit of time to start up. */ > usleep_range(35000, 70000); > @@ -1156,21 +1156,29 @@ static int inv_mpu_core_enable_regulator(struct inv_mpu6050_state *st) > return result; > } > > -static int inv_mpu_core_disable_regulator(struct inv_mpu6050_state *st) > +static int inv_mpu_core_disable_regulator_vddio(struct inv_mpu6050_state *st) > { > int result; > > result = regulator_disable(st->vddio_supply); > if (result) > dev_err(regmap_get_device(st->map), > - "Failed to disable regulator: %d\n", result); > + "Failed to disable vddio regulator: %d\n", result); > > return result; > } > > static void inv_mpu_core_disable_regulator_action(void *_data) > { > - inv_mpu_core_disable_regulator(_data); > + struct inv_mpu6050_state *st = _data; > + int result; > + > + result = regulator_disable(st->vdd_supply); > + if (result) > + dev_err(regmap_get_device(st->map), > + "Failed to disable vdd regulator: %d\n", result); > + > + inv_mpu_core_disable_regulator_vddio(st); > } > > int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, > @@ -1239,6 +1247,15 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, > return -EINVAL; > } > > + st->vdd_supply = devm_regulator_get(dev, "vdd"); > + if (IS_ERR(st->vdd_supply)) { > + if (PTR_ERR(st->vdd_supply) != -EPROBE_DEFER) > + dev_err(dev, "Failed to get vdd regulator %d\n", > + (int)PTR_ERR(st->vdd_supply)); > + > + return PTR_ERR(st->vdd_supply); > + } > + > st->vddio_supply = devm_regulator_get(dev, "vddio"); > if (IS_ERR(st->vddio_supply)) { > if (PTR_ERR(st->vddio_supply) != -EPROBE_DEFER) > @@ -1248,9 +1265,17 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, > return PTR_ERR(st->vddio_supply); > } > > - result = inv_mpu_core_enable_regulator(st); > - if (result) > + result = regulator_enable(st->vdd_supply); > + if (result) { > + dev_err(dev, "Failed to enable vdd regulator: %d\n", result); > return result; > + } > + > + result = inv_mpu_core_enable_regulator_vddio(st); > + if (result) { > + regulator_disable(st->vdd_supply); > + return result; > + } > > result = devm_add_action_or_reset(dev, inv_mpu_core_disable_regulator_action, > st); > @@ -1352,7 +1377,7 @@ static int inv_mpu_resume(struct device *dev) > int result; > > mutex_lock(&st->lock); > - result = inv_mpu_core_enable_regulator(st); > + result = inv_mpu_core_enable_regulator_vddio(st); > if (result) > goto out_unlock; > > @@ -1370,7 +1395,7 @@ static int inv_mpu_suspend(struct device *dev) > > mutex_lock(&st->lock); > result = inv_mpu6050_set_power_itg(st, false); > - inv_mpu_core_disable_regulator(st); > + inv_mpu_core_disable_regulator_vddio(st); > mutex_unlock(&st->lock); > > return result; > diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h > index 52fcf45050a5..4fcf683b9c63 100644 > --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h > +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h > @@ -130,7 +130,8 @@ struct inv_mpu6050_hw { > * @chip_period: chip internal period estimation (~1kHz). > * @it_timestamp: timestamp from previous interrupt. > * @data_timestamp: timestamp for next data sample. > - * @vddio_supply voltage regulator for the chip. > + * @vdd_supply: VDD voltage regulator for the chip. > + * @vddio_supply I/O voltage regulator for the chip. > * @magn_disabled: magnetometer disabled for backward compatibility reason. > * @magn_raw_to_gauss: coefficient to convert mag raw value to Gauss. > * @magn_orient: magnetometer sensor chip orientation if available. > @@ -154,6 +155,7 @@ struct inv_mpu6050_state { > s64 chip_period; > s64 it_timestamp; > s64 data_timestamp; > + struct regulator *vdd_supply; > struct regulator *vddio_supply; > bool magn_disabled; > s32 magn_raw_to_gauss[3];