Commit 202ff7537558edfd759b400cfe9e56c56fc7868c
Committed by
Gerald Van Baren
1 parent
aadef0a1bc
Exists in
master
and in
54 other branches
fdt: Add polarity-aware gpio functions to fdtdec
Add get and set gpio functions to fdtdec that take into account the polarity field in fdtdec_gpio_state.flags. Signed-off-by: Sean Paul <seanpaul@chromium.org> Signed-off-by: Simon Glass <sjg@chromium.org>
Showing 2 changed files with 36 additions and 0 deletions Side-by-side Diff
include/fdtdec.h
... | ... | @@ -90,6 +90,22 @@ |
90 | 90 | #define fdt_gpio_isvalid(x) ((x)->gpio != FDT_GPIO_NONE) |
91 | 91 | |
92 | 92 | /** |
93 | + * Read the GPIO taking into account the polarity of the pin. | |
94 | + * | |
95 | + * @param gpio pointer to the decoded gpio | |
96 | + * @return value of the gpio if successful, < 0 if unsuccessful | |
97 | + */ | |
98 | +int fdtdec_get_gpio(struct fdt_gpio_state *gpio); | |
99 | + | |
100 | +/** | |
101 | + * Write the GPIO taking into account the polarity of the pin. | |
102 | + * | |
103 | + * @param gpio pointer to the decoded gpio | |
104 | + * @return 0 if successful | |
105 | + */ | |
106 | +int fdtdec_set_gpio(struct fdt_gpio_state *gpio, int val); | |
107 | + | |
108 | +/** | |
93 | 109 | * Find the next numbered alias for a peripheral. This is used to enumerate |
94 | 110 | * all the peripherals of a certain type. |
95 | 111 | * |
lib/fdtdec.c
... | ... | @@ -487,6 +487,26 @@ |
487 | 487 | return err == 1 ? 0 : err; |
488 | 488 | } |
489 | 489 | |
490 | +int fdtdec_get_gpio(struct fdt_gpio_state *gpio) | |
491 | +{ | |
492 | + int val; | |
493 | + | |
494 | + if (!fdt_gpio_isvalid(gpio)) | |
495 | + return -1; | |
496 | + | |
497 | + val = gpio_get_value(gpio->gpio); | |
498 | + return gpio->flags & FDT_GPIO_ACTIVE_LOW ? val ^ 1 : val; | |
499 | +} | |
500 | + | |
501 | +int fdtdec_set_gpio(struct fdt_gpio_state *gpio, int val) | |
502 | +{ | |
503 | + if (!fdt_gpio_isvalid(gpio)) | |
504 | + return -1; | |
505 | + | |
506 | + val = gpio->flags & FDT_GPIO_ACTIVE_LOW ? val ^ 1 : val; | |
507 | + return gpio_set_value(gpio->gpio, val); | |
508 | +} | |
509 | + | |
490 | 510 | int fdtdec_setup_gpio(struct fdt_gpio_state *gpio) |
491 | 511 | { |
492 | 512 | /* |