Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2387551imu; Sun, 13 Jan 2019 00:35:20 -0800 (PST) X-Google-Smtp-Source: ALg8bN63E7OYPpshX/O7P4/aBvlg6uMfGyJ2zwven2YP3mGKcgg2dAz/OZVYKKj0E/3ODMK/eozN X-Received: by 2002:a17:902:6acc:: with SMTP id i12mr18754659plt.148.1547368520691; Sun, 13 Jan 2019 00:35:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547368520; cv=none; d=google.com; s=arc-20160816; b=l+3KJ99BoqdOGZn6MHtogL4KRlmseOoQ1cbsllGMqNuf0ELMNNnEKoSAG/dlK7FSnk WqnKUaI5asFS/yu6OQV+c+La0G8A0hnOGSWlgJ6jtro0GLKudCjbLMo2JTUtzTJDajai pUjHRMLfVvAPP1g7LBfVcZ7VRYYu8oqrd6re6kpGe8GZZEIOfT1URhrGvp3d/OITvwMT du27kDEjXNNYk9mLaxtjiTWzoqldS0Rg2PvoY1hY7HL/D8vtlPuu8mkD0knpq4qhAsWb JmrZORL0AUuccQ2gRN/D1AQO6jSSScTyh5HcaxSyUux0Bh0h7I+mueDeVI74kd8W4c8/ zyuA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :dkim-signature; bh=0hup6Tw33mTfXoI5RwTAYoA+dCjtDU9gVwa0En5voEU=; b=OEdYyE5uBewA6kNN964VCb+Rufytx2haICNqoP6yPXm8X5ey1/lUvWOG+Pp/60Wj5d n9OWX+sxLtrGme1Upiq3SlSUqggqNTdm1d5SBm53XGsP+BAazCTiyCU0KjIUh+Gt2Lnk vXXsj5+4GroiWh8epVp23T2C2/cmWHg4+WPtFd3lVnowqXkkBD2jD769OC7+24XK4l96 LQNa3mq2TqRItuf+AwzkxxpkfH6REuAhuVYu1bnx2SuLlZFMKym4FX9TwKFTFAv5b+Zc rUuWuBOmr+E0pQTrQnkyQtBcIxTUUKehfk4M8ZUGSMWuTEsW45gUo3AGuVF46zBn72qK CnYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@posteo.de header.s=2017 header.b=NMtIUueP; 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=posteo.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g71si58357092pgc.419.2019.01.13.00.34.33; Sun, 13 Jan 2019 00:35:20 -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=@posteo.de header.s=2017 header.b=NMtIUueP; 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=posteo.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726524AbfAMIb3 (ORCPT + 99 others); Sun, 13 Jan 2019 03:31:29 -0500 Received: from mout02.posteo.de ([185.67.36.66]:42519 "EHLO mout02.posteo.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726172AbfAMIb3 (ORCPT ); Sun, 13 Jan 2019 03:31:29 -0500 Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 3EC83240102 for ; Sun, 13 Jan 2019 09:31:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1547368286; bh=ZITyX4zP5c0dVk/IIg0MA5gFaSYi/uhkQ//BE/ckFAQ=; h=Subject:To:Cc:From:Openpgp:Autocrypt:Date:From; b=NMtIUuePVeQhCpTsvOKGuH2R01e3TQnb9+ZWY7bmj/UtBW5TNur942bp+EjPRPdAX lhvlPa87JX8xjrA7YARt80RPrb2N1e6uIDGdFldTI8J24kWDFYpw2iAfmjCIw8gRS7 hUIvAzx9giCHdI8jFjYhQYa0QTaCo1RibGfU+GwGlZBPUup0VWPjg55C5gSO8R140T LRTnR3gyYEMLY4O2ZSGpwQbcTkl2tz0+lap8IH8yZnURY4GWC44QvGDhBfxIL1MhLy 3FJ2Wr26++xL42/q12Yy2K7W4x+XjpWviBBXE3Mc2NaFBJCT6yWHsrXamlz+5app+F wnXaCP7dqQfiA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 43cqZM1MZMz9rxH; Sun, 13 Jan 2019 09:31:23 +0100 (CET) Subject: Re: [PATCH V7 2/2] iio: accell: mma8452: add vdd/vddio regulator operation support To: Jonathan Cameron , Anson Huang Cc: "knaack.h@gmx.de" , "lars@metafoo.de" , "pmeerw@pmeerw.net" , "robh+dt@kernel.org" , "mark.rutland@arm.com" , "gustavo@embeddedor.com" , "gregkh@linuxfoundation.org" , Leonard Crestez , "rtresidd@electromag.com.au" , "linux-iio@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , dl-linux-imx References: <1546938556-26969-1-git-send-email-Anson.Huang@nxp.com> <1546938556-26969-2-git-send-email-Anson.Huang@nxp.com> <84c2971b-29d5-a0d0-c830-11504c381dd2@posteo.de> <4CB70D1B-06A6-4E34-B701-58E72B1AC9D9@nxp.com> <20190112191111.4909e254@archlinux> From: Martin Kepplinger Openpgp: preference=signencrypt Autocrypt: addr=martink@posteo.de; keydata= mQINBFULfZABEADRxJqDOYAHfrp1w8Egcv88qoru37k1x0Ugy8S6qYtKLAAt7boZW+q5gPv3 Sj2KjfkWA7gotXpASN21OIfE/puKGwhDLAySY1DGNMQ0gIVakUO0ji5GJPjeB9JlmN5hbA87 Si9k3yKQQfv7Cf9Lr1iZaV4A4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2plSvGyRJgJoj+pbiC UgYSujU0HH8gXVAbD+1pNgfXSg4hD/4qNFv91G8Et2DThur4wZJxAfAmHykmMxxQnJ/2+VA1 Ej+QrsU3sq93D8gJNEVVV96tcGrJv4ytyRLmt5fi35xEvdxgf7FiS3bQqp9rS6jL/lhz7qNw mR8c4pgMAdURioI8QnPlgSEfneH8KVCWoCc09kysjG1rmVh2dXpIQo3Shri/zhbWtVQepTLI D+VjnhdFPVXTixI1b4NW6h4aSkrip6ccyH/8WjsGqPQVX5yNSAJnoqjlpb3buVEU+EP9uvg/ RvNj6qFRbc+nfOBBgrUvhEr0aEOvFotExGvNjR5T9MewbGVnL4s0IlMYwZBD88ygm77CmQRg MbBzOP6HyiLOUmLBbfDXmHP0ChP3Oi34bm7OSPq9PyxcuMhr1hzWXQYsjqH6CtU0cNRjeIz/ bEt7TFPkP0uzJ4zLjX2BAJ9WJC2JGDWEMhtzg2kZaAS9jwCEAf7m8mP+RT64rSMztjKtmIQN vZicCb2MBQaC7vS7thkGhyQIlzN32iWeCHeydZnDPMEU9PP3PMsQHDAnZdXjc5Jfa2q9WOzG nCFhEis48yoFOobYJHR0viwuY4DIprx3Dq6I4+WVwuf6U6y579i+qDvOxiuFcClGgBmsmehF YSKzZPSgZYhCVZhzSpg4D+AVQEhxhGTSCXDSBIMpnW4GgdJdZGmBBobKqvHmgI95tw== Message-ID: <3540a0d9-b756-af00-65b8-c78ba669ebff@posteo.de> Date: Sun, 13 Jan 2019 09:31:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190112191111.4909e254@archlinux> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12.01.19 20:11, Jonathan Cameron wrote: > On Tue, 8 Jan 2019 14:48:48 +0000 > Anson Huang wrote: > >> Hi, Martin >> >> From Anson's iPhone 6 >> >> >>> 在 2019年1月8日,19:41,Martin Kepplinger 写道: >>> >>>> On 08.01.19 10:14, Anson Huang wrote: >>>> The accelerometer's power supply could be controllable on some >>>> platforms, such as i.MX6Q-SABRESD board, the mma8451's power supplies >>>> are controlled by a GPIO fixed regulator, need to make sure the >>>> regulators are enabled before any communication with mma8451, this >>>> patch adds vdd/vddio regulator operation support. >>>> >>>> Signed-off-by: Anson Huang >>>> Acked-by: Martin Kepplinger >>>> --- >>>> ChangeLog Since V6: >>>> - separate the error handling of regulators get to make code easy to read. >>>> --- >>>> drivers/iio/accel/mma8452.c | 105 ++++++++++++++++++++++++++++++++++---------- >>>> 1 file changed, 83 insertions(+), 22 deletions(-) >>>> >>>> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c >>>> index 421a0a8..3027811 100644 >>>> --- a/drivers/iio/accel/mma8452.c >>>> +++ b/drivers/iio/accel/mma8452.c >>>> @@ -31,6 +31,7 @@ >>>> #include >>>> #include >>>> #include >>>> +#include >>>> >>>> #define MMA8452_STATUS 0x00 >>>> #define MMA8452_STATUS_DRDY (BIT(2) | BIT(1) | BIT(0)) >>>> @@ -107,6 +108,8 @@ struct mma8452_data { >>>> u8 data_cfg; >>>> const struct mma_chip_info *chip_info; >>>> int sleep_val; >>>> + struct regulator *vdd_reg; >>>> + struct regulator *vddio_reg; >>>> }; >>>> >>>> /** >>>> @@ -1534,9 +1537,39 @@ static int mma8452_probe(struct i2c_client *client, >>>> mutex_init(&data->lock); >>>> data->chip_info = match->data; >>>> >>>> + data->vdd_reg = devm_regulator_get(&client->dev, "vdd"); >>>> + if (IS_ERR(data->vdd_reg)) { >>>> + if (PTR_ERR(data->vdd_reg) == -EPROBE_DEFER) >>>> + return -EPROBE_DEFER; >>>> + >>>> + dev_err(&client->dev, "failed to get VDD regulator!\n"); >>>> + return PTR_ERR(data->vdd_reg); >>>> + } >>>> + >>>> + data->vddio_reg = devm_regulator_get(&client->dev, "vddio"); >>>> + if (IS_ERR(data->vddio_reg)) { >>>> + if (PTR_ERR(data->vddio_reg) == -EPROBE_DEFER) >>>> + return -EPROBE_DEFER; >>>> + >>>> + dev_err(&client->dev, "failed to get VDDIO regulator!\n"); >>>> + return 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, MMA8452_WHO_AM_I); >>>> if (ret < 0) >>>> - return ret; >>>> + goto disable_regulators; >>>> >>>> switch (ret) { >>>> case MMA8451_DEVICE_ID: >>>> @@ -1549,7 +1582,8 @@ static int mma8452_probe(struct i2c_client *client, >>>> break; >>>> /* else: fall through */ >>>> default: >>>> - return -ENODEV; >>>> + ret = -ENODEV; >>>> + goto disable_regulators; >>>> } >>>> >>>> dev_info(&client->dev, "registering %s accelerometer; ID 0x%x\n", >>>> @@ -1566,13 +1600,13 @@ static int mma8452_probe(struct i2c_client *client, >>>> >>>> ret = mma8452_reset(client); >>>> if (ret < 0) >>>> - return ret; >>>> + goto disable_regulators; >>>> >>>> data->data_cfg = MMA8452_DATA_CFG_FS_2G; >>>> ret = i2c_smbus_write_byte_data(client, MMA8452_DATA_CFG, >>>> data->data_cfg); >>>> if (ret < 0) >>>> - return ret; >>>> + goto disable_regulators; >>>> >>>> /* >>>> * By default set transient threshold to max to avoid events if >>>> @@ -1581,7 +1615,7 @@ static int mma8452_probe(struct i2c_client *client, >>>> ret = i2c_smbus_write_byte_data(client, MMA8452_TRANSIENT_THS, >>>> MMA8452_TRANSIENT_THS_MASK); >>>> if (ret < 0) >>>> - return ret; >>>> + goto disable_regulators; >>>> >>>> if (client->irq) { >>>> int irq2; >>>> @@ -1595,7 +1629,7 @@ static int mma8452_probe(struct i2c_client *client, >>>> MMA8452_CTRL_REG5, >>>> data->chip_info->all_events); >>>> if (ret < 0) >>>> - return ret; >>>> + goto disable_regulators; >>>> >>>> dev_dbg(&client->dev, "using interrupt line INT1\n"); >>>> } >>>> @@ -1604,11 +1638,11 @@ static int mma8452_probe(struct i2c_client *client, >>>> MMA8452_CTRL_REG4, >>>> data->chip_info->enabled_events); >>>> if (ret < 0) >>>> - return ret; >>>> + goto disable_regulators; >>>> >>>> ret = mma8452_trigger_setup(indio_dev); >>>> if (ret < 0) >>>> - return ret; >>>> + goto disable_regulators; >>>> } >>>> >>>> data->ctrl_reg1 = MMA8452_CTRL_ACTIVE | >>>> @@ -1661,12 +1695,19 @@ static int mma8452_probe(struct i2c_client *client, >>>> trigger_cleanup: >>>> mma8452_trigger_cleanup(indio_dev); >>>> >>>> +disable_regulators: >>>> + regulator_disable(data->vddio_reg); >>>> + >>>> +disable_regulator_vdd: >>>> + regulator_disable(data->vdd_reg); >>>> + >>>> return ret; >>>> } >>>> >>>> static int mma8452_remove(struct i2c_client *client) >>>> { >>>> struct iio_dev *indio_dev = i2c_get_clientdata(client); >>>> + struct mma8452_data *data = iio_priv(indio_dev); >>>> >>>> iio_device_unregister(indio_dev); >>>> >>>> @@ -1678,6 +1719,9 @@ static int mma8452_remove(struct i2c_client *client) >>>> mma8452_trigger_cleanup(indio_dev); >>>> mma8452_standby(iio_priv(indio_dev)); >>>> >>>> + regulator_disable(data->vddio_reg); >>>> + regulator_disable(data->vdd_reg); >>>> + >>>> return 0; >>>> } >>>> >>>> @@ -1696,6 +1740,18 @@ static int mma8452_runtime_suspend(struct device *dev) >>>> return -EAGAIN; >>>> } >>>> >>>> + 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; >>>> } >>>> >>>> @@ -1705,9 +1761,22 @@ static int mma8452_runtime_resume(struct device *dev) >>>> struct mma8452_data *data = iio_priv(indio_dev); >>>> int ret, sleep_val; >>>> >>>> + 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; >>>> + } >>>> + >>>> ret = mma8452_active(data); >>>> if (ret < 0) >>>> - return ret; >>>> + goto runtime_resume_failed; >>>> >>>> ret = mma8452_get_odr_index(data); >>>> sleep_val = 1000 / mma8452_samp_freq[ret][0]; >>>> @@ -1717,25 +1786,17 @@ static int mma8452_runtime_resume(struct device *dev) >>>> msleep_interruptible(sleep_val); >>>> >>>> return 0; >>>> -} >>>> -#endif >>>> >>>> -#ifdef CONFIG_PM_SLEEP >>>> -static int mma8452_suspend(struct device *dev) >>>> -{ >>>> - return mma8452_standby(iio_priv(i2c_get_clientdata( >>>> - to_i2c_client(dev)))); >>>> -} >>>> +runtime_resume_failed: >>>> + regulator_disable(data->vddio_reg); >>>> + regulator_disable(data->vdd_reg); >>>> >>>> -static int mma8452_resume(struct device *dev) >>>> -{ >>>> - return mma8452_active(iio_priv(i2c_get_clientdata( >>>> - to_i2c_client(dev)))); >>>> + return ret; >>>> } >>>> #endif >>>> >>>> static const struct dev_pm_ops mma8452_pm_ops = { >>>> - SET_SYSTEM_SLEEP_PM_OPS(mma8452_suspend, mma8452_resume) >>>> + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) >>> >>> Just a quesion: Isn't it semantically a different change to replace >>> mma8452_suspend() and mma8452_resume()? If not, why is it needed here? >>> >>> other than that, lgtm. >> >> It is because with regulator operation added, before system suspend, driver is in runtime suspend already, the suspend/resume callback need to deal with regulator again including error handling etc., and also need to disable runtime pm and re-enable it etc., this introduces too many complicated code/logic, also, the things suspend/resume callback does are actually same as runtime suspend/ resume, so just using pm_runtime_force_suspend/resume can save these duplicated operations and make code easy/clean. >> > Anson, please wrap below 80 chars. Some of us have old old old > laptops, (though I admit I still have more than 80 chars ;) > > I 'think' Anson is correct that these end up running the same > code, but with considerably less complexity an this is > the reason the force functions exist. Often the runtime case > is very similar to the full pm case so you can avoid the whole > runtime resume then suspend dance by doing this. > > Anyhow I've applied it to the togreg branch of iio.git and pushed > it out as testing. Hopefully we haven't missed any corner > cases. > > Runtime PM always gives me a headache when I dig into exactly > what the various dances are that go on. > Alright. If not too late: Acked-by: Martin Kepplinger thanks, martin