diff options
author | CHLin <CHLIN56@nuvoton.com> | 2019-06-13 11:01:18 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-07-24 05:50:26 +0000 |
commit | 26d7adb2fd72635cde56199b025c200a125dcb78 (patch) | |
tree | 0b6c70777fc40dea00884ada9ccfebaf9b8692ca /include/gpio_list.h | |
parent | b872f26ce6b97f62175c835871fbb7ead6b8455b (diff) | |
download | chrome-ec-26d7adb2fd72635cde56199b025c200a125dcb78.tar.gz |
IO_Expander: introduce the common interface of IO expander
Implement the common code to provide a friendly interface to control the
IOs of IO expander. It adopts a similar concept to GPIO.
1. Define the IO expander IO in gpio.inc by the format:
IOEX(name, EXPIN(ioex, port, offset), flags)
- name: the name of this IO pin
- EXPIN(ioex, port, offset)
- ioex: the IO expander port (defined in board.c) this IO
pin belongs to.
- port: the port number in the IO expander chip.
- offset: the bit offset in the port above.
- flags: the same as the flags of GPIO.
2. The following APIs are supported:
1. ioex_get_flags_by_mask
2. ioex_set_flags_by_mask
3. ioex_get_flags
4. ioex_set_flags
5. ioex_get_level
6. ioex_set_level
7. ioex_init
3. The following console commands are supported:
1. ioexget [IO_EXPANDER_PIN_NAME]
2. ioexset IO_EXPANDER_PIN_NAME 0/1
BRANCH=none
BUG=none
TEST=No error for "make buildall"
TEST=Apply this and related CLs, manually test each API, make sure each
function works correctly with IO expander chip (NCT3807/NCT3808.)
Change-Id: I79c9813abccc67d5554e2ceb5c119dcf549b7dce
Signed-off-by: CHLin <CHLIN56@nuvoton.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1657858
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Commit-Queue: CH Lin <chlin56@nuvoton.com>
Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: CH Lin <chlin56@nuvoton.com>
Diffstat (limited to 'include/gpio_list.h')
-rw-r--r-- | include/gpio_list.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/include/gpio_list.h b/include/gpio_list.h index 70d7bfc4b2..4fed0d60d6 100644 --- a/include/gpio_list.h +++ b/include/gpio_list.h @@ -52,3 +52,39 @@ const int gpio_ih_count = ARRAY_SIZE(gpio_irq_handlers); #define PIN(a, b...) static const int _pin_ ## a ## _ ## b \ __attribute__((unused, section(".unused"))) = __LINE__; #include "gpio.wrap" + +#include "ioexpander.h" +/* + * Define the IO expander IO in gpio.inc by the format: + * IOEX(name, EXPIN(ioex_port, port, offset), flags) + * - name: the name of this IO pin + * - EXPIN(ioex, port, offset) + * - ioex: the IO expander port (defined in board.c) this IO + * pin belongs to. + * - port: the port number in the IO expander chip. + * - offset: the bit offset in the port above. + * - flags: the same as the flags of GPIO. + * + */ +#define IOEX_EXPIN(ioex, port, index) (ioex), (port), BIT(index) + +#define IOEX(name, expin, flags) {#name, IOEX_##expin, flags}, + +/* IO expander signal list. */ +const struct ioex_info ioex_list[] = { + #include "gpio.wrap" +}; +BUILD_ASSERT(ARRAY_SIZE(ioex_list) == IOEX_COUNT); + +#define IOEX(name, expin, flags) expin + +/* The compiler will complain if we use the same name twice or the controller + * number declared is greater or equal to CONFIG_IO_EXPANDER_PORT_COUNT. + * The linker ignores anything that gets by. + */ +#define EXPIN(a, b, c...) \ + static const int _expin_ ## a ## _ ## b ## _ ## c \ + __attribute__((unused, section(".unused"))) = __LINE__; \ + BUILD_ASSERT(a < CONFIG_IO_EXPANDER_PORT_COUNT); + +#include "gpio.wrap" |