From: Pavel Machek <pavel@ucw.cz>
To: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
Cc: tony@atomide.com, lgirdwood@gmail.com, broonie@kernel.org,
sre@kernel.org, pali.rohar@gmail.com, linux-omap@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] regulator: twl: Make sure we have access to powerbus before trying to write to it
Date: Sun, 24 Apr 2016 18:10:02 +0200 [thread overview]
Message-ID: <20160424161002.GC8880@amd> (raw)
In-Reply-To: <1458980895-10240-2-git-send-email-ivo.g.dimitrov.75@gmail.com>
Hi!
> According to the TRM, we need to enable i2c access to powerbus before
> writing to it. Also, a new write to powerbus should not be attempted if
> there is a pending transfer. The current code does not implement that
> functionality and while there are no known problems caused by that, it is
> better to follow what TRM says.
>
> Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
> ---
> drivers/regulator/twl-regulator.c | 78 +++++++++++++++++++++++++++++++++++----
> 1 file changed, 70 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
> index 955a6fb..aad748b0 100644
> --- a/drivers/regulator/twl-regulator.c
> +++ b/drivers/regulator/twl-regulator.c
> @@ -21,7 +21,7 @@
> #include <linux/regulator/machine.h>
> #include <linux/regulator/of_regulator.h>
> #include <linux/i2c/twl.h>
> -
> +#include <linux/delay.h>
>
> /*
> * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a
> @@ -188,6 +188,74 @@ static int twl6030reg_is_enabled(struct regulator_dev *rdev)
> return grp && (val == TWL6030_CFG_STATE_ON);
> }
>
> +#define PB_I2C_BUSY BIT(0)
> +#define PB_I2C_BWEN BIT(1)
> +
> +/* Wait until buffer empty/ready to send a word on power bus. */
> +static int twl4030_wait_pb_ready(void)
> +{
> +
> + int ret;
> + int timeout = 10;
> + u8 val;
> +
Can we do this plain
while (timeout--) {
}...
? Also... if the bit is not immediately available, it will wait for
1msec. Would it make sense to have timeout = 1000 but wait only 10usec
each time or something?
Thanks,
Pavel
> + do {
> + ret = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &val,
> + TWL4030_PM_MASTER_PB_CFG);
> + if (ret < 0)
> + return ret;
> +
> + if (!(val & PB_I2C_BUSY))
> + return 0;
> +
> + mdelay(1);
> + timeout--;
> + } while (timeout);
> +
> + return -ETIMEDOUT;
> +}
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
next prev parent reply other threads:[~2016-04-24 16:10 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-26 8:28 [PATCH 0/3] regulator: twl: Fix regulator mode support Ivaylo Dimitrov
2016-03-26 8:28 ` [PATCH 1/3] regulator: twl: Make sure we have access to powerbus before trying to write to it Ivaylo Dimitrov
2016-04-05 22:26 ` Ivaylo Dimitrov
2016-04-06 6:06 ` [PATCH] regulator: twl: Fix a typo in twl4030_send_pb_msg Ivaylo Dimitrov
2016-04-24 16:10 ` Pavel Machek [this message]
2016-04-24 17:14 ` [PATCH 1/3] regulator: twl: Make sure we have access to powerbus before trying to write to it Ivaylo Dimitrov
2016-03-26 8:28 ` [PATCH 2/3] regulator: twl: Provide of_map_mode for twl4030 Ivaylo Dimitrov
2016-03-28 9:39 ` Mark Brown
[not found] ` <20160328093938.GA2350-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2016-04-04 18:57 ` [PATCH] " Ivaylo Dimitrov
2016-04-04 18:57 ` Ivaylo Dimitrov
2016-04-04 22:26 ` Mark Brown
2016-04-05 5:59 ` [PATCH v1] " Ivaylo Dimitrov
2016-04-07 17:57 ` Rob Herring
2016-04-08 15:49 ` Tony Lindgren
[not found] ` <20160408154907.GT16484-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-04-08 16:08 ` Sebastian Reichel
2016-04-08 16:08 ` Sebastian Reichel
2016-04-08 16:19 ` Tony Lindgren
2016-04-08 16:19 ` Tony Lindgren
[not found] ` <20160408161923.GW16484-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-04-08 17:54 ` Tony Lindgren
2016-04-08 17:54 ` Tony Lindgren
2016-03-26 8:28 ` [PATCH 3/3] regulator: twl: Regulator mode should not depend on regulator enabled state Ivaylo Dimitrov
2016-04-24 16:11 ` Pavel Machek
2016-04-24 17:01 ` Ivaylo Dimitrov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160424161002.GC8880@amd \
--to=pavel@ucw.cz \
--cc=broonie@kernel.org \
--cc=ivo.g.dimitrov.75@gmail.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=pali.rohar@gmail.com \
--cc=sre@kernel.org \
--cc=tony@atomide.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.