From: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
To: Sebastian Reichel <sre@kernel.org>
Cc: "Mark Brown" <broonie@kernel.org>,
"Liam Girdwood" <lgirdwood@gmail.com>,
"Peter Ujfalusi" <peter.ujfalusi@ti.com>,
"Grygorii Strashko" <grygorii.strashko@ti.com>,
"Pali Rohár" <pali.rohar@gmail.com>,
"Jarkko Nikula" <jarkko.nikula@bitmer.com>,
"Tony Lindgren" <tony@atomide.com>,
"Lars-Peter Clausen" <lars@metafoo.de>,
linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org,
"Pavel Machek" <pavel@ucw.cz>,
"Aaro Koskinen" <aaro.koskinen@iki.fi>,
"Nishanth Menon" <nm@ti.com>,
merlijn@wizzup.org
Subject: Re: Nokia N900 - audio TPA6130A2 problems
Date: Tue, 22 Mar 2016 10:02:23 +0200 [thread overview]
Message-ID: <56F0FC0F.8000107@gmail.com> (raw)
In-Reply-To: <56F04CC7.1040403@gmail.com>
On 21.03.2016 21:34, Ivaylo Dimitrov wrote:
>
>
> On 21.03.2016 16:53, Sebastian Reichel wrote:
>> Hi Mark,
>>
>> On Mon, Mar 21, 2016 at 01:45:15PM +0000, Mark Brown wrote:
>>> On Mon, Mar 21, 2016 at 03:39:15PM +0200, Ivaylo Dimitrov wrote:
>>>> On 21.03.2016 13:45, Mark Brown wrote:
>>>
>>>>> No, if the voltage is variable we can't tell what the current
>>>>> constraints are without something telling us so we just don't vary the
>>>>> voltage until we're told to do this. If we immediately lower the
>>>>> voltage to the minimum supported voltage that's going to break things.
>>>
>>>> There are constraints set by the board DTS. Isn't it reasonable the
>>>> framework to set the voltage to minimum voltage from the dts if the
>>>> current
>>>> set one is bellow it?
>>>
>>> Yes, if it's out of bounds for the constraints we should bring it
>>> up/down to the minimum/maximum (when copying people into a thread it's a
>>> good idea to explain what the problem you are trying to solve is,
>>> especially if you're throwing around bodges).
>>
>> We have this regulator definition in omap3-n900.dts:
>>
>> &vmmc2 {
>> regulator-name = "V28_A";
>> regulator-min-microvolt = <2800000>;
>> regulator-max-microvolt = <3000000>;
>> regulator-always-on; /* due VIO leak to AIC34 VDDs */
>> };
>>
>> The regulator is enabled during probe, but the voltage is not
>> configured. The default reset voltage of the regulator is 2.6V.
>> So basically when the regulator is enabled, it uses a voltage,
>> which is out of the DT specified range.
>>
>> We also have a second problem: If the system has been rebooted from
>> Nokia's stock kernel the regulator is left in STANDBY mode. Since
>> the mode is not configured during probe, it results in different
>> problems. According to my understanding it can be fixed trivially
>> by adding
>>
>> &vmmc2 {
>> regulator-initial-mode = <2>;
>> };
>>
>
> doesn't work:
>
> "regulator-vmmc2: mapping for mode 2 not defined"
>
> twl-regulator is missing .of_map_mode function.
>
> Also, if we go that route, we should set the initial modes for all the
> regulators, not only vmmc2 (and not only for N900), as we don't really
> know what is the status of regulators at startup. I think a better
> approach is if regulator framework sets all always-on regulators to
> enabled, unless stated otherwise (which it already does iiuc).
>
> I think there is a bug in twl-regulator twl4030reg_enable() and/or
> twl4030reg_is_enabled() - the latter only checks if DEV_GRP is P1, but
> not for the actual state of the regulator (bits 3:0). Also, what looks
> suspicious to me is that all the regulators are put in P1 device group.
> Legacy board code spreads the regulators all over the groups, so maybe
> this is simply a regression compared to legacy boot.
>
This is what seems to work, I would like some comments from those who
are more experienced with twl4030 than me before posting a formal patch.
I borrowed the code from stock Nokia kernel.
diff --git a/drivers/regulator/twl-regulator.c
b/drivers/regulator/twl-regulator.c
index 955a6fb..3740df4 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
@@ -165,7 +165,7 @@ static int twl4030reg_is_enabled(struct
regulator_dev *rdev)
if (state < 0)
return state;
- return state & P1_GRP_4030;
+ return (state & 0x0f) != 0;
}
static int twl6030reg_is_enabled(struct regulator_dev *rdev)
@@ -188,11 +188,75 @@ static int twl6030reg_is_enabled(struct
regulator_dev *rdev)
return grp && (val == TWL6030_CFG_STATE_ON);
}
+static int twl4030_wait_pb_ready(void)
+{
+
+ int ret, timeout = 10;
+ u8 pb_state;
+
+ do {
+ ret = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &pb_state,
+ TWL4030_PM_MASTER_PB_CFG);
+ if (ret < 0)
+ return ret;
+
+ if (!(pb_state & 1))
+ return 0;
+
+ mdelay(1);
+ timeout--;
+
+ } while (timeout);
+
+ return -ETIMEDOUT;
+}
+
+static int twl4030_send_pb_msg(unsigned msg)
+{
+ u8 pb_state;
+ int ret;
+
+ /* save powerbus configuration */
+ ret = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &pb_state,
+ TWL4030_PM_MASTER_PB_CFG);
+ if (ret < 0)
+ return ret;
+
+ /* Enable I2C access to powerbus */
+ ret = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, pb_state | BIT(1),
+ TWL4030_PM_MASTER_PB_CFG);
+ if (ret < 0)
+ return ret;
+
+ ret = twl4030_wait_pb_ready();
+ if (ret < 0)
+ return ret;
+
+ ret = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, msg >> 8,
+ TWL4030_PM_MASTER_PB_WORD_MSB);
+ if (ret < 0)
+ return ret;
+
+ ret = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, msg & 0xff,
+ TWL4030_PM_MASTER_PB_WORD_LSB);
+ if (ret < 0)
+ return ret;
+
+ ret = twl4030_wait_pb_ready();
+ if (ret < 0)
+ return ret;
+
+ /* Restore powerbus configuration */
+ return twl_i2c_write_u8(TWL_MODULE_PM_MASTER, pb_state,
+ TWL_MODULE_PM_MASTER);
+}
+
static int twl4030reg_enable(struct regulator_dev *rdev)
{
struct twlreg_info *info = rdev_get_drvdata(rdev);
int grp;
int ret;
+ unsigned message;
grp = twlreg_grp(rdev);
if (grp < 0)
@@ -201,8 +265,12 @@ static int twl4030reg_enable(struct regulator_dev
*rdev)
grp |= P1_GRP_4030;
ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
+ if (ret < 0)
+ return ret;
- return ret;
+ message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE);
+
+ return twl4030_send_pb_msg(message);
}
static int twl6030reg_enable(struct regulator_dev *rdev)
@@ -324,13 +392,7 @@ static int twl4030reg_set_mode(struct regulator_dev
*rdev, unsigned mode)
if (!(status & (P3_GRP_4030 | P2_GRP_4030 | P1_GRP_4030)))
return -EACCES;
- status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
- message >> 8, TWL4030_PM_MASTER_PB_WORD_MSB);
- if (status < 0)
- return status;
-
- return twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
- message & 0xff, TWL4030_PM_MASTER_PB_WORD_LSB);
+ return twl4030_send_pb_msg(message);
}
static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
Regards,
Ivo
next prev parent reply other threads:[~2016-03-22 8:02 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-25 10:28 Nokia N900 - audio TPA6130A2 problems Pali Rohár
2015-07-25 10:28 ` Pali Rohár
2015-07-25 13:17 ` Lars-Peter Clausen
2015-08-01 10:18 ` Pali Rohár
2015-08-03 18:03 ` Jarkko Nikula
2015-08-03 18:17 ` Pali Rohár
2015-08-03 18:48 ` Jarkko Nikula
2015-08-03 18:55 ` Pali Rohár
2015-08-04 7:02 ` Peter Ujfalusi
2015-08-04 7:02 ` Peter Ujfalusi
2016-01-04 23:34 ` Pali Rohár
2016-03-06 15:23 ` Sebastian Reichel
2016-03-07 11:59 ` Pali Rohár
2016-03-08 6:45 ` Ivaylo Dimitrov
2016-03-12 12:39 ` Pali Rohár
2016-03-12 12:42 ` Pali Rohár
2016-03-14 9:59 ` Peter Ujfalusi
2016-03-14 9:59 ` Peter Ujfalusi
2016-03-14 17:05 ` Ivaylo Dimitrov
2016-03-16 13:33 ` Pali Rohár
2016-03-16 14:47 ` Sebastian Reichel
2016-03-16 18:21 ` Ivaylo Dimitrov
2016-03-16 18:32 ` Grygorii Strashko
2016-03-16 18:32 ` Grygorii Strashko
2016-03-16 19:50 ` Ivaylo Dimitrov
2016-03-17 0:49 ` Sebastian Reichel
2016-03-17 7:56 ` Ivaylo Dimitrov
2016-03-17 13:01 ` Pali Rohár
2016-03-17 13:11 ` Ivaylo Dimitrov
2016-03-17 13:33 ` Tony Lindgren
2016-03-17 13:50 ` Ivaylo Dimitrov
2016-03-17 14:32 ` Tony Lindgren
2016-03-17 14:58 ` Ivaylo Dimitrov
2016-03-17 7:53 ` Peter Ujfalusi
2016-03-17 7:53 ` Peter Ujfalusi
2016-03-17 17:26 ` Ivaylo Dimitrov
2016-03-18 10:33 ` Peter Ujfalusi
2016-03-18 10:33 ` Peter Ujfalusi
2016-03-18 13:13 ` Ивайло Димитров
2016-03-18 13:36 ` Sebastian Reichel
2016-03-18 13:45 ` Ivaylo Dimitrov
2016-03-18 15:04 ` Sebastian Reichel
2016-03-18 15:56 ` Ivaylo Dimitrov
2016-03-19 8:49 ` Ivaylo Dimitrov
2016-03-20 5:17 ` Sebastian Reichel
2016-03-20 19:43 ` Ivaylo Dimitrov
2016-03-21 0:04 ` Sebastian Reichel
2016-03-21 1:40 ` Sebastian Reichel
2016-03-21 12:03 ` Mark Brown
2016-03-21 11:45 ` Mark Brown
2016-03-21 13:39 ` Ivaylo Dimitrov
2016-03-21 13:45 ` Mark Brown
2016-03-21 14:53 ` Sebastian Reichel
2016-03-21 19:34 ` Ivaylo Dimitrov
2016-03-22 8:02 ` Ivaylo Dimitrov [this message]
2016-04-01 10:43 ` Race condition in TPA6130A2 (Was: Re: Nokia N900 - audio TPA6130A2 problems) Pali Rohár
2015-08-14 20:46 ` Nokia N900 - audio TPA6130A2 problems Pavel Machek
2015-08-14 20:54 ` Pali Rohár
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=56F0FC0F.8000107@gmail.com \
--to=ivo.g.dimitrov.75@gmail.com \
--cc=aaro.koskinen@iki.fi \
--cc=broonie@kernel.org \
--cc=grygorii.strashko@ti.com \
--cc=jarkko.nikula@bitmer.com \
--cc=lars@metafoo.de \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=merlijn@wizzup.org \
--cc=nm@ti.com \
--cc=pali.rohar@gmail.com \
--cc=pavel@ucw.cz \
--cc=peter.ujfalusi@ti.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.