Re: [PATCH 2/2] usb: ohci-pxa27x: add regulators for usb devices

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/18/2013 05:23 PM, Alan Stern wrote:
What happens to ext_regulator[0] if you fail to enable
ext_regulator[1]?  Does it remain permanently enabled?

It will be turned off when pxa27x_stop_hc is called.

Ah, I see.  You enable regulators only in pxa27x_start_hc() and disable
them only in pxa27x_stop_hc().  The second routine is always called
if the first one succeeds.

Which leads to the question: What happens to usb_regulator if
pxa27x_start_hc() returns early because of a failure in inf->init()?

That is something I missed; good catch. This would be a place to call
regulator_disable_all() (before exiting pxa27x_start_hc).
I'll go over the code again when I resubmit to make sure I covered
everything.


+static void ohci_regulator_put_all(struct pxa27x_ohci *ohci)
+{
+	int i;
+
+	for (i = 0; i < PXA_UHC_MAX_PORTNUM; i++) {
+		if (ohci->ext_regulator[i])
+			regulator_put(ohci->ext_regulator[i]);
+	}
+
+	/* usb regulator should be present if we get here */
+	regulator_put(ohci->usb_regulator);
+}

What happens if you call regulator_put() for an enabled regulator?

It'll remain enabled, but there's not much that can be done about this:
The problem with regulators is that there's no way to tell *why*
they're enabled. The same regulator can supply more than one device,
and thus be turned on by multiple drivers. Because of this there's no
way to tell if corrective measures should be taken before a
regulator_put.

A better question would be: What happens if you call
regulator_disable() after regulator_enable() fails?  Does this end up
not mattering?

Depends on the situation. There's a use_count for each regulator which
keeps track of enables(++)/disables(--). The regulator is disabled in
the actual hardware only when use_count == 0.
If nobody succesfully called regulator_enable() (use_count is 0) then
the kernel will warn that there's an unbalanced use of
regulator_enable/disable, and do nothing further with the regulator.
If use_count >= 1 not because of ohci-pxa27x, then we would be messing
with someone else's use of the regulator. From what I've seen, other
drivers don't make an attempt to protect against this possibility.

--
Regards,
Nikita.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux