[UPSTREAM] Use new regulator API for pcf50633

Balaji Rao balajirrao at openmoko.org
Tue Oct 28 15:52:42 CET 2008


On Tue, Oct 28, 2008 at 02:31:34PM +0000, Mark Brown wrote:
> On Tue, Oct 28, 2008 at 07:37:53PM +0530, Balaji Rao wrote:
> 
> > The probe method creates the platform devices for the regulators. My
> > question is, can we be 100% sure that when the
> > platform_device_register returns, the regulators have been registered ?
> 
> You can't guarantee that the regulator driver is available at all and
> will ever get loaded.  :)

Yes, exaclty! Suppose we assume that the driver is compiled in, can we
guarantee that ? 

If the answer is a no, then what do you say about the current bitmap
approach used in this patch ? Is there anyway we can get rid of this ?

Here are the relevant parts of the patch.

@@ -2195,16 +2224,32 @@ static int pcf50633_probe(struct i2c_client *client, const struct i2c_device_id
 		apm_get_power_status = NULL;
 
 	pdata->pcf = pcf;
+
+	/* Create platform regulator devices from the platform data */
+	for (i = 0; i < __NUM_PCF50633_REGULATORS; i++) {
+		struct platform_device *pdev;
+
+		/* Reject regulators not used by anyone */
+		if (pdata->reg_init_data[i].num_consumer_supplies == 0) {
+			pcf->registered_regulators |= (1 << i);
+ 			continue;
+		}
+
+		pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
+		/* FIXME : Handle failure */
+
+		pdev->name = "pcf50633-regulator";
+		pdev->id = i;
+		pdev->dev.parent = &client->dev;
+		pdev->dev.platform_data = &pdata->reg_init_data[i];
+		pdev->dev.driver_data = pcf;
+
+		platform_device_register(pdev);
+	}
+

+void pcf50633_mark_regulator_registered(struct pcf50633_data *pcf, int regulator)
+{
+	pcf->registered_regulators |= (1 << regulator);
+
+	/* All regulators are registered ? */
+	if (pcf->registered_regulators != ((1 << __NUM_PCF50633_REGULATORS) - 1))
+		return;
+
+	/* if platform was interested, give him a chance to register
+	 * platform devices that switch power with us as the parent
+	 * at registration time -- ensures suspend / resume ordering
+	 */
+	if (pcf->pdata->attach_child_devices)
+		(pcf->pdata->attach_child_devices)(&pcf->client->dev);
+
+}
+

	- Balaji



More information about the openmoko-kernel mailing list