forked from Mirrors/opensbi
lib: utils/gpio: respect flag GPIO_FLAG_ACTIVE_LOW
"gpio-poweroff" and "gpio-restart" always set gpio to high to active the function, but some chips need a low signal to active. Fortunately, it can be achieved by setting GPIO_FLAG_ACTIVE_LOW for the gpio. Implement this flag support for the gpio library so the gpio reset can function well. Signed-off-by: Inochi Amaoto <inochiama@outlook.com> Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:

committed by
Anup Patel

parent
ae5ef1848d
commit
d962db2807
@@ -73,17 +73,26 @@ int gpio_direction_output(struct gpio_pin *gp, int value)
|
|||||||
if (!gp->chip->direction_output)
|
if (!gp->chip->direction_output)
|
||||||
return SBI_ENOSYS;
|
return SBI_ENOSYS;
|
||||||
|
|
||||||
|
if (gp->flags & GPIO_FLAG_ACTIVE_LOW)
|
||||||
|
value = value == 0 ? 1 : 0;
|
||||||
|
|
||||||
return gp->chip->direction_output(gp, value);
|
return gp->chip->direction_output(gp, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
int gpio_get(struct gpio_pin *gp)
|
int gpio_get(struct gpio_pin *gp)
|
||||||
{
|
{
|
||||||
|
int value;
|
||||||
|
|
||||||
if (!gp || !gp->chip || (gp->chip->ngpio <= gp->offset))
|
if (!gp || !gp->chip || (gp->chip->ngpio <= gp->offset))
|
||||||
return SBI_EINVAL;
|
return SBI_EINVAL;
|
||||||
if (!gp->chip->get)
|
if (!gp->chip->get)
|
||||||
return SBI_ENOSYS;
|
return SBI_ENOSYS;
|
||||||
|
|
||||||
return gp->chip->get(gp);
|
value = gp->chip->get(gp);
|
||||||
|
|
||||||
|
if (gp->flags & GPIO_FLAG_ACTIVE_LOW)
|
||||||
|
value = value == 0 ? 1 : 0;
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gpio_set(struct gpio_pin *gp, int value)
|
int gpio_set(struct gpio_pin *gp, int value)
|
||||||
@@ -93,6 +102,9 @@ int gpio_set(struct gpio_pin *gp, int value)
|
|||||||
if (!gp->chip->set)
|
if (!gp->chip->set)
|
||||||
return SBI_ENOSYS;
|
return SBI_ENOSYS;
|
||||||
|
|
||||||
|
if (gp->flags & GPIO_FLAG_ACTIVE_LOW)
|
||||||
|
value = value == 0 ? 1 : 0;
|
||||||
|
|
||||||
gp->chip->set(gp, value);
|
gp->chip->set(gp, value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user