Re: regulator_register() API

From: Mark Brown
Date: Tue Jun 09 2009 - 18:06:40 EST


On Tue, Jun 09, 2009 at 05:52:35PM +0200, Rodolfo Giometti wrote:

> Great! However this resolve one issue, the caller still needs to
> allocate a device struct by itsown. On the other hand, doing like
> led_classdev_register() does will resolve it also!

The regulator driver does not need to allocate a struct device. The
struct device that is passed in is for the chip as a whole and would
normally be something like the struct device for the I2C client. As
I say it's there mostly for the benefit of printk().

The regulator API returns a pointer to the class device that is
allocated and ensures that that class device is parented by the device
that was passed in.

> As you can see in this case I simply can do:
>
> /* Register the led devices */
> for (i = 0; i < 6; i++)
> if (pdata->led[i].name) {
> data->led[i].dev.name = pdata->led[i].name;

The code in, for example, the lp3971 driver looks pretty much the same
as this except instead of copying data into the struct it passes data
into the registration API.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/