Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1915843imu; Sat, 5 Jan 2019 09:48:01 -0800 (PST) X-Google-Smtp-Source: ALg8bN60YVPX1ooMsOmFn5zoTTXT0Kk3lFhceLsScKXrS9uIm61EeTx4YIfywZjVIBb/QvD3OUDu X-Received: by 2002:a17:902:380c:: with SMTP id l12mr53892922plc.326.1546710481570; Sat, 05 Jan 2019 09:48:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546710481; cv=none; d=google.com; s=arc-20160816; b=zLWO2t/AJSrGQWjfej/IDVLYaQGzsTHCgHpKOHMWAjLSGEjqhCg/BpfnYy4Zn73SRQ FeUY4ADAHh30O390IFJVRkme9TjwbVHEW0539mlm13xlNz2/J7B1jxrs9fygVVIogCRI lRSYOBIxPK14ocWQx2lSKG/gWGCVtbMwTlU32s9ucc5k0PDCsAP8+Qv79OK7xlyBuyLb SECaOEXcmaQdB1hOVzibZympUXAQ/7vgNo8fB+G+JMbX6Z4WBfUzF/smGwe1qF4GV9xZ KZ08JONP+V2ukAq5I2lVvkWYRWUDNrfzxJpHeZ3dsnvYZnUECR2/ruOPPjVkU84BXpvr KM5A== 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=brdUUO5sQqOKRHQY09XAJYOlWytGiFEtODGDYYwfDBE=; b=lFijnlqTbTu2G2s5GQmYa4PFCF68Xnj65rBsVvs+GBf1/IVXVb82GevRMjSbZHcGES tfSh5nWddU3DkWOtxuTulCyKu6Jhu2oiJP7Z4jzd3Uw0AV2G6rNdpmQbpVC8+fmFfogR 0cZD3WxxrNmVXx/5l/tpXVZF+W/PVJDcdvLECVJvMyq9FmWf0JdHUY+IygzUWo+CAJZE Mu6RLa3NWoCDRckJnp3hOSNUNLrFMxUhkAytkRM4P6UxtFeNWUC9CNIZmQRjvG+UGYtf 9ipP49R6GJpttL4WqeH8EN7NAjReLLsdA5WikezDZIBq5EpLQd9oT/A/Q9DDnTN1TO9S YaZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=C2M5wKYS; 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 h7si12944102pls.326.2019.01.05.09.47.46; Sat, 05 Jan 2019 09:48:01 -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=C2M5wKYS; 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 S1726426AbfAERqm (ORCPT + 99 others); Sat, 5 Jan 2019 12:46:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:34188 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726299AbfAERqm (ORCPT ); Sat, 5 Jan 2019 12:46:42 -0500 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (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 9FAD521871; Sat, 5 Jan 2019 17:46:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546710401; bh=tnspQe1zgh51q23x0ZskxmrKMCSVWl6A8hUR/wZzaNo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=C2M5wKYSAuTf1ze+iUPnJhXp/f7NY75umkekwPVP3Vr516E5I1yafL1TOezwVr50m Aglw2SNX69bb2NVLK99CryTuwjQzLpMdM33IYCrS+F1fkY02xRT7wC0CRZ4rO8hnUl PyVJm098n8d1XNq6qY+l+3/kbnUYFt79/6obpDNM= Date: Sat, 5 Jan 2019 17:46:36 +0000 From: Jonathan Cameron To: Anson Huang Cc: "knaack.h@gmx.de" , "lars@metafoo.de" , "pmeerw@pmeerw.net" , "rtresidd@electromag.com.au" , "linux-iio@vger.kernel.org" , "linux-kernel@vger.kernel.org" , dl-linux-imx Subject: Re: [PATCH V6] iio: magnetometer: mag3110: add vdd/vddio regulator operation support Message-ID: <20190105174636.4971accb@archlinux> In-Reply-To: <1545545266-6741-1-git-send-email-Anson.Huang@nxp.com> References: <1545545266-6741-1-git-send-email-Anson.Huang@nxp.com> X-Mailer: Claws Mail 3.17.3 (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 Sun, 23 Dec 2018 06:12:30 +0000 Anson Huang wrote: > The magnetometer's power supplies could be controllable on some platforms, > such as i.MX6Q-SABRESD board, the mag3110's power supplies are controlled > by a GPIO fixed regulator, need to make sure the regulators are enabled > before any communication with mag3110, this patch adds vdd/vddio regulator > operation support. > > Signed-off-by: Anson Huang Same comment on not combining the error handling. It's simply harder to read to save a few lines of code. Otherwise, looks fine, though I would ideally like an ack from Peter on this as it's his driver. If he's busy though I think this should be safe enough without. thanks, Jonathan > --- > ChangeLog since V5: > Make sure both vdd and vddio regulators are aquired before enabling any one of them. > --- > drivers/iio/magnetometer/mag3110.c | 88 ++++++++++++++++++++++++++++++++++---- > 1 file changed, 80 insertions(+), 8 deletions(-) > > diff --git a/drivers/iio/magnetometer/mag3110.c b/drivers/iio/magnetometer/mag3110.c > index f063355..f56a99a 100644 > --- a/drivers/iio/magnetometer/mag3110.c > +++ b/drivers/iio/magnetometer/mag3110.c > @@ -20,6 +20,7 @@ > #include > #include > #include > +#include > > #define MAG3110_STATUS 0x00 > #define MAG3110_OUT_X 0x01 /* MSB first */ > @@ -56,6 +57,8 @@ struct mag3110_data { > struct mutex lock; > u8 ctrl_reg1; > int sleep_val; > + struct regulator *vdd_reg; > + struct regulator *vddio_reg; > }; > > static int mag3110_request(struct mag3110_data *data) > @@ -469,17 +472,44 @@ static int mag3110_probe(struct i2c_client *client, > struct iio_dev *indio_dev; > int ret; > > - ret = i2c_smbus_read_byte_data(client, MAG3110_WHO_AM_I); > - if (ret < 0) > - return ret; > - if (ret != MAG3110_DEVICE_ID) > - return -ENODEV; > - > indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); > if (!indio_dev) > return -ENOMEM; > > data = iio_priv(indio_dev); > + > + data->vdd_reg = devm_regulator_get(&client->dev, "vdd"); > + data->vddio_reg = devm_regulator_get(&client->dev, "vddio"); > + if (IS_ERR(data->vdd_reg) || IS_ERR(data->vddio_reg)) { > + if (PTR_ERR(data->vdd_reg) == -EPROBE_DEFER || > + PTR_ERR(data->vddio_reg) == -EPROBE_DEFER) > + return -EPROBE_DEFER; > + > + dev_err(&client->dev, "failed to get VDD/VDDIO regulator!\n"); > + return IS_ERR(data->vdd_reg) ? > + PTR_ERR(data->vdd_reg) : PTR_ERR(data->vddio_reg); > + } > + > + ret = regulator_enable(data->vdd_reg); > + if (ret) { > + dev_err(&client->dev, "failed to enable VDD regulator!\n"); > + return ret; > + } > + > + ret = regulator_enable(data->vddio_reg); > + if (ret) { > + dev_err(&client->dev, "failed to enable VDDIO regulator!\n"); > + goto disable_regulator_vdd; > + } > + > + ret = i2c_smbus_read_byte_data(client, MAG3110_WHO_AM_I); > + if (ret < 0) > + goto disable_regulators; > + if (ret != MAG3110_DEVICE_ID) { > + ret = -ENODEV; > + goto disable_regulators; > + } > + > data->client = client; > mutex_init(&data->lock); > > @@ -499,7 +529,7 @@ static int mag3110_probe(struct i2c_client *client, > > ret = mag3110_change_config(data, MAG3110_CTRL_REG1, data->ctrl_reg1); > if (ret < 0) > - return ret; > + goto disable_regulators; > > ret = i2c_smbus_write_byte_data(client, MAG3110_CTRL_REG2, > MAG3110_CTRL_AUTO_MRST_EN); > @@ -520,16 +550,24 @@ static int mag3110_probe(struct i2c_client *client, > iio_triggered_buffer_cleanup(indio_dev); > standby_on_error: > mag3110_standby(iio_priv(indio_dev)); > +disable_regulators: > + regulator_disable(data->vddio_reg); > +disable_regulator_vdd: > + regulator_disable(data->vdd_reg); > + > return ret; > } > > static int mag3110_remove(struct i2c_client *client) > { > struct iio_dev *indio_dev = i2c_get_clientdata(client); > + struct mag3110_data *data = iio_priv(indio_dev); > > iio_device_unregister(indio_dev); > iio_triggered_buffer_cleanup(indio_dev); > mag3110_standby(iio_priv(indio_dev)); > + regulator_disable(data->vddio_reg); > + regulator_disable(data->vdd_reg); > > return 0; > } > @@ -537,14 +575,48 @@ static int mag3110_remove(struct i2c_client *client) > #ifdef CONFIG_PM_SLEEP > static int mag3110_suspend(struct device *dev) > { > - return mag3110_standby(iio_priv(i2c_get_clientdata( > + struct mag3110_data *data = iio_priv(i2c_get_clientdata( > + to_i2c_client(dev))); > + int ret; > + > + ret = mag3110_standby(iio_priv(i2c_get_clientdata( > to_i2c_client(dev)))); > + if (ret) > + return ret; > + > + ret = regulator_disable(data->vddio_reg); > + if (ret) { > + dev_err(dev, "failed to disable VDDIO regulator\n"); > + return ret; > + } > + > + ret = regulator_disable(data->vdd_reg); > + if (ret) { > + dev_err(dev, "failed to disable VDD regulator\n"); > + return ret; > + } > + > + return 0; > } > > static int mag3110_resume(struct device *dev) > { > struct mag3110_data *data = iio_priv(i2c_get_clientdata( > to_i2c_client(dev))); > + int ret; > + > + ret = regulator_enable(data->vdd_reg); > + if (ret) { > + dev_err(dev, "failed to enable VDD regulator\n"); > + return ret; > + } > + > + ret = regulator_enable(data->vddio_reg); > + if (ret) { > + dev_err(dev, "failed to enable VDDIO regulator\n"); > + regulator_disable(data->vdd_reg); > + return ret; > + } > > return i2c_smbus_write_byte_data(data->client, MAG3110_CTRL_REG1, > data->ctrl_reg1);