Skip to contentSkip to conversation

MMC/pxamci: workaround regulator framework bugs

PATCH In review Daniel Ribeiro 4 participants 9 messages Jun 26, 2009 – Jul 24, 2009 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 MMC/pxamci: workaround regulator framework bugs

The voltage regulator framework can't sanely deal with voltage regulators which are left enabled by the bootloader. We workaround this by forcing an enable()/disable() pair so it has a sane use_count.

---
 drivers/mmc/host/pxamci.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
drivers/mmc/host/pxamci.c +12 -0
index d7d7109..20fb3da 100644
@@ -80,6 +80,18 @@ static inline void pxamci_init_ocr(struct pxamci_host *host)
 	if (IS_ERR(host->vcc))
 		host->vcc = NULL;
 	else {
+		/*
+		 * When the bootloader leaves a supply active, it's
+		 * initialized with zero usecount ... and we can't
+		 * disable it without first enabling it.  Until the
+		 * framework is fixed, we need a workaround like this
+		 * (which is safe for MMC, but not in general).
+		 */
+		if (regulator_is_enabled(host->vcc) > 0) {
+			regulator_enable(host->vcc);
+			regulator_disable(host->vcc);
+		}
+
 		host->mmc->ocr_avail = mmc_regulator_get_ocrmask(host->vcc);
 		if (host->pdata && host->pdata->ocr_mask)
 			dev_warn(mmc_dev(host->mmc),
Signature · 4 lines
tg: (87da0bf..) mmc/workaround-regulator-bugs (depends on: mmc/pxamci-regulator-support)

-- 
Daniel Ribeiro
#1 lore raw
Quoted 3 lines · Daniel Ribeiro

The voltage regulator framework can't sanely deal with voltage regulators which are left enabled by the bootloader. We workaround this by forcing an enable()/disable() pair so it has a sane use_count.

Please write a commit message explaining what the actual situation is here. Ideally this would include some documentation for the MMC core explaining the requirements it has. The fact that you're trying to force the regulator off is a big warning sign for the more common non-exclusive consumers so you need to be clear about why this is required.

drivers/mmc/host/pxamci.c static inline void pxamci_init_ocr(struct pxamci_host *host) · line 88

Quoted 6 lines
drivers/mmc/host/pxamci.c +6 -0
+		/*
+		 * When the bootloader leaves a supply active, it's
+		 * initialized with zero usecount ... and we can't
+		 * disable it without first enabling it.  Until the
+		 * framework is fixed, we need a workaround like this
+		 * (which is safe for MMC, but not in general).

This also needs to explain the actual situation, especially the exclusivity reqirement of the MMC core. It might be worth providing a helper in the MMC core, everything is going to need to be updated to use exclusive get whenever someone implements it.

As discussed at some length the regulator API is not going to be changed in the way you demand. This is not something that it should be easy for standard consumers to do since for standard consumers it normally points out a programming error.

#2 lore raw

Em Sáb, 2009-06-27 às 01:48 +0100, Mark Brown escreveu:

Quoted 11 lines

drivers/mmc/host/pxamci.c static inline void pxamci_init_ocr(struct pxamci_host *host) · line 88

Quoted 6 lines
drivers/mmc/host/pxamci.c +6 -0
+		/*
+		 * When the bootloader leaves a supply active, it's
+		 * initialized with zero usecount ... and we can't
+		 * disable it without first enabling it.  Until the
+		 * framework is fixed, we need a workaround like this
+		 * (which is safe for MMC, but not in general).

This also needs to explain the actual situation, especially the exclusivity reqirement of the MMC core. It might be worth providing a helper in the MMC core, everything is going to need to be updated to use exclusive get whenever someone implements it.

Heh, this patch was copy-n-paste from twl code. I really can't put much time on this. :(

Quoted 4 lines

As discussed at some length the regulator API is not going to be changed in the way you demand. This is not something that it should be easy for standard consumers to do since for standard consumers it normally points out a programming error.

Ok, so I will "fix it" hacking the bootloader to power off the voltage regulator before giving control to kernel. Lets hope that the next developer that tries to use the regulator framework with a mmc card and stumbles on the "regulator already enabled" case has more time to fix it properly. :)

Signature · 1 line
Daniel Ribeiro
#3 lore raw
Quoted 20 lines · Daniel Ribeiro

Em Sáb, 2009-06-27 às 01:48 +0100, Mark Brown escreveu:

Quoted 10 lines

drivers/mmc/host/pxamci.c static inline void pxamci_init_ocr(struct pxamci_host *host) · line 88

Quoted 6 lines
drivers/mmc/host/pxamci.c +6 -0
+		/*
+		 * When the bootloader leaves a supply active, it's
+		 * initialized with zero usecount ... and we can't
+		 * disable it without first enabling it.  Until the
+		 * framework is fixed, we need a workaround like this
+		 * (which is safe for MMC, but not in general).

This also needs to explain the actual situation, especially the exclusivity reqirement of the MMC core. It might be worth providing a helper in the MMC core, everything is going to need to be updated to use exclusive get whenever someone implements it.

Heh, this patch was copy-n-paste from twl code. I really can't put much time on this. :(

Quoted 4 lines

As discussed at some length the regulator API is not going to be changed in the way you demand. This is not something that it should be easy for standard consumers to do since for standard consumers it normally points out a programming error.

Quoted 6 lines

Ok, so I will "fix it" hacking the bootloader to power off the voltage regulator before giving control to kernel. Lets hope that the next developer that tries to use the regulator framework with a mmc card and stumbles on the "regulator already enabled" case has more time to fix it properly. :)

This looks to be running into the same issue as clocks - where for power savings the clocks are assumed to be off as many as possible, leaving only those essential ones enabled, yet the assumption of the boot loader does this correctly is always a big problem, putting this into the kernel, however, is ugly.

#4 lore raw
Quoted 5 lines · Eric Miao

This looks to be running into the same issue as clocks - where for power savings the clocks are assumed to be off as many as possible, leaving only those essential ones enabled, yet the assumption of the boot loader does this correctly is always a big problem, putting this into the kernel, however, is ugly.

At the minute the regulator API actually copes pretty well with this - the only problem I'm aware of is with drivers like the MMC driver which require exclusive control of the regulator. With other drivers the core API can clean up after startup and the drivers never need to worry about fixing things up.

#5 lore raw
Quoted 3 lines · Mark Brown

At the minute the regulator API actually copes pretty well with this - the only problem I'm aware of is with drivers like the MMC driver which require exclusive control of the regulator.

Which is a fairly typical situation for power-aware drivers.

Which belies your claim that the regulator API "copes pretty well". It'd be more accurate to say "broken-as-designed", since you have rejected numerous attempts to fix this, yet not fixed it yourself.

Quoted 3 lines

With other drivers the core
API can clean up after startup and the drivers never need to worry about fixing things up.

MMC isn't particularly unusual. It's just the first place this type problem tends to come up. Expect more such problelms as folkl actually try to *use* the regulator framework.

#6 lore raw
Quoted 7 lines · David Brownell
Quoted 3 lines · Mark Brown

At the minute the regulator API actually copes pretty well with this - the only problem I'm aware of is with drivers like the MMC driver which require exclusive control of the regulator.

Which is a fairly typical situation for power-aware drivers.

As has been mentioned a number of times in previous discussions of this there is a very large class of devices which do not *require* any power control at all but which can usefully switch their supplies on and off.

Quoted 3 lines

Which belies your claim that the regulator API "copes pretty well". It'd be more accurate to say "broken-as-designed", since you have rejected numerous attempts to fix this, yet not fixed it yourself.

You've suggested variations of essentially one approach, forcing the regulator to be off while the use count is zero. In response to this you've not only been given explanations of the problems this causes but also several suggestions for alternative approaches such as adding a way to request exclusive use of the regulator or adding something in constraints to turn off the regulator at startup.

I have previously had to ask you to try to approach discussions on the regulator API in a more constructive fashion, please let me renew that request. Doing so would be much less time consuming and for that reason if nothing else would be very helpful in progressing things.

#7 lore raw
Quoted 7 lines · Mark Brown
Quoted 5 lines · David Brownell
Quoted 3 lines · Mark Brown

At the minute the regulator API actually copes pretty well with this - the only problem I'm aware of is with drivers like the MMC driver which require exclusive control of the regulator.

Quoted 5 lines
Quoted 1 line

Which is a fairly typical situation for power-aware drivers.

As has been mentioned a number of times in previous discussions of this there is a very large class of devices which do not *require* any power control at all but which can usefully switch their supplies on and off.

Which I never argued with. My comment was about their drivers.

Power-aware drivers may *require* that they can actually reduce system power consumption ... else what's the point? Likewise, switching voltages needs care, and sometimes ability to switch power on and off.

Quoted 6 lines
Quoted 3 lines

Which belies your claim that the regulator API "copes pretty well". It'd be more accurate to say "broken-as-designed", since you have rejected numerous attempts to fix this, yet not fixed it yourself.

You've suggested variations of essentially one approach, forcing the regulator to be off while the use count is zero.

For the record, that's simply not true. The patches I sent tried a variety of approaches, and I don't recall that ever being one of them ... since that is in fact a fair description of what needed to be FIXED. The property my patches shared was:

	/* that this simple idiom would finally work */
	if (regulator_is_enabled(r))
		regulator_disable(r);

It's *your* proposals which preserved the property that the above lines of code could fail (often rudely at boot time). Until just yesterday... when you posted

http://marc.info/?l=linux-kernel&m=124818844611060&w=2

which is intended to provide a new mechanism, the only way to ensure the above idiom can always work. It looks like that will work for $SUBJECT (MMC/SD drivers) and some similar cases.

Quoted 4 lines

I have previously had to ask you to try to approach discussions on the regulator API in a more constructive fashion, please let me renew that request. Doing so would be much less time consuming and for that reason if nothing else would be very helpful in progressing things.

I've previously had to ask you to respond to **what I said** not to something you merely imagined I had said. Don't pretend that you were blameless. Your approach was highly confrontational, and rejected many constructive suggestions. At one point you flamed me for disagreeing ... with the point *I* was making, as eventually became clear.

If you felt my responses were sufficiently non-constructive as to deserve a lecture on courtesy ... you ought to have considered your own participation. What you saw was a rising tide of frustration caused by (a) your refusal to address what I was actually saying,
(b) your falsely attributing statements and viewpoints to me, and
(c) rejecting around half a dozen patches to solve a problem, all of which were within (d) an ever-increasing number of constraints you grew with each new iteration. I had to try so many different approaches since nothing seemed to be getting through. The lack of constructive behavior was mostly on *your* part ... but when I finally called you on that, I got a lecture back!! Feh. I don't need to let such crap stand; but decided to wait until the anger went away.

So it's no surprise I would conclude the only solution was to wait for you to write a patch, which you would then accept. And you have now done that; thanks.

- Dave

#8 lore raw
Quoted 3 lines · David Brownell
	/* that this simple idiom would finally work */
	if (regulator_is_enabled(r))
		regulator_disable(r);

For the avoidance of future disappointment please note that an exclusive access request does not remove the reference counting on the regulator, it only changes the way in which it is intialised. This means that the above code is only guaranteed to cause the regulator to be disabled so long as the consumer never calls enable() twice without a matching disable(). It will, however, not return an error due to unbalanced enables and disables which I believe is your primary requirement here.

Quoted 3 lines

of which were within (d) an ever-increasing number of constraints you grew with each new iteration. I had to try so many different approaches since nothing seemed to be getting through. The lack

For clarity and in the hope that this helps to avoid future issues let me list the three major constraints in this area:

- The API supports shared regulators.
- Regulator enabling by software is reference counted.
- Changing the state of regulators before drivers have had a chance to take control of the devices is very disruptive to the system and needs to be avoided as a result.

Everything else flows from those, in conjunction with the standard considerations about making sure that any transitions are managed in as graceful a fashion as possible.

I'm leaving the rest of your mail because I don't think discussing that further here is going to get us anywhere.