On Tue, Jan 15, 2013 at 04:35:46AM +0000, Kim, Milo wrote:

> +/**
> + * Balance enable_count of each GPIO and actual GPIO pin control.
> + * GPIO is enabled in case of initial use. (enable_count is 0)
> + * GPIO is disabled when it is not shared any more. (enable_count is 1)
> + */
> +static void _do_ena_gpio_ctrl(struct regulator_enable_gpio *pin,
> +                     struct regulator_dev *rdev, bool enable)
> +{
> +     if (enable) {
> +             /* Enable GPIO at initial use */
> +             if (pin->enable_count == 0)
> +                     gpio_set_value_cansleep(rdev->ena_gpio,
> +                                             !rdev->ena_gpio_invert);
> +
> +             rdev->ena_gpio_state = 1;

ena_gpio_state is redundant with this patch, we can just replace
references to it with pin->enable_count.

We'll also need a request count to keep track of how many regulators are
using the GPIO for use in cleanup.

> +     } else {
> +             rdev->ena_gpio_state = 0;
> +             if (pin->enable_count > 1) {
> +                     pin->enable_count--;
> +                     return;
> +             }
> +
> +             /* Disable GPIO if not used */
> +             if (pin->enable_count == 1) {
> +                     gpio_set_value_cansleep(rdev->ena_gpio,
> +                                             rdev->ena_gpio_invert);
> +                     pin->enable_count = 0;
> +             }

Ideally we should also check if we're trying to take the enable count
below zero and complain about that.

> +static void regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable)
> +{
> +     struct regulator_enable_gpio *pin;
> +
> +     list_for_each_entry(pin, &regulator_ena_gpio_list, list) {
> +             if (pin->gpio == rdev->ena_gpio) {
> +                     _do_ena_gpio_ctrl(pin, rdev, enable);
> +                     return;
> +             }
> +     }
> +}

This should return an error code as the users return errors, the GPIO
API won't give us errors but we can generate them internally.  It'd be
better to just add a pointer to the GPIO struct to the regulator_dev (in
place of the GPIO) so we don't need to scan through the list every time
we look for the GPIO.

Attachment: signature.asc
Description: Digital signature

Reply via email to