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/ioexpander.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/ioexpander.h')
-rw-r--r-- | include/ioexpander.h | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/include/ioexpander.h b/include/ioexpander.h new file mode 100644 index 0000000000..2a31eb6aaa --- /dev/null +++ b/include/ioexpander.h @@ -0,0 +1,137 @@ +/* + * Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_IOEXPANDER_H +#define __CROS_EC_IOEXPANDER_H + +/* IO expander signal definition structure */ +struct ioex_info { + /* Signal name */ + const char *name; + + /* IO expander port number */ + uint16_t ioex; + + /* IO port number in IO expander */ + uint16_t port; + + /* Bitmask on that port (1 << N) */ + uint32_t mask; + + /* Flags - the same as the GPIO flags */ + uint32_t flags; +}; + +/* Signal information from board.c. Must match order from enum ioex_signal. */ +extern const struct ioex_info ioex_list[]; + +struct ioexpander_drv { + /* Initialize IO expander chip/driver */ + int (*init)(int ioex); + /* Get the current level of the IOEX pin */ + int (*get_level)(int ioex, int port, int mask, int *val); + /* Set the level of the IOEX pin */ + int (*set_level)(int ioex, int port, int mask, int val); + /* Get flags for the IOEX pin */ + int (*get_flags_by_mask)(int ioex, int port, int mask, int *flags); + /* Set flags for the IOEX pin */ + int (*set_flags_by_mask)(int ioex, int port, int mask, int flags); +}; + +struct ioexpander_config_t { + /* Physical I2C port connects to the IO expander chip. */ + int i2c_host_port; + /* I2C slave address */ + int i2c_slave_addr; + /* + * The extra variable used to store information which may be required + * by the IO expander chip. + */ + int chip_info; + /* + * Pointer to the specific IO expander chip's ops defined in + * the struct ioexpander_drv. + */ + const struct ioexpander_drv *drv; +}; + +extern struct ioexpander_config_t ioex_config[]; + +/* + * Get flags for the IOEX pin by mask + * + * @param ioex IO expander chip's port number + * @param port IO port in the IO expander chip + * @param mask Bitmask of the pin on the port above + * @param flags Pointer to the keep the flags read + * @return EC_SUCCESS if successful, non-zero if error. + */ +int ioex_get_flags_by_mask(int ioex, int port, int mask, int *flags); + +/* + * Set flags for the IOEX pin by mask + * + * @param ioex IO expander chip's port number + * @param port IO port in the IO expander chip + * @param mask Bitmask of the pin on the port above + * @param flags flags to set + * @return EC_SUCCESS if successful, non-zero if error. + */ +int ioex_set_flags_by_mask(int ioex, int port, int mask, int flags); + +/* + * Get flags for the IOEX signal + * + * @param signal IOEX signal to get flags for + * @param flags Pointer to the keep the flags read + * @return EC_SUCCESS if successful, non-zero if error. + */ +int ioex_get_flags(enum ioex_signal signal, int *flags); + +/* + * Set flags for the IOEX signal + * + * @param signal IOEX signal to set flags for + * @param flags New flags for the IOEX signal + * @return EC_SUCCESS if successful, non-zero if error. + */ +int ioex_set_flags(enum ioex_signal signal, int flags); + +/* + * Get the current level of the IOEX signal + * + * @param signal IOEX signal to get the level + * @param val Pointer to the keep the level read + * @return EC_SUCCESS if successful, non-zero if error. + */ +int ioex_get_level(enum ioex_signal signal, int *val); + +/* + * Set the level of the IOEX signal + * + * @param signal IOEX signal to set the level + * @param value New level for the IOEX signal + * @return EC_SUCCESS if successful, non-zero if error. + */ +int ioex_set_level(enum ioex_signal signal, int value); + +/* + * Initialize IO expander chip/driver + * + * @param ioex IO expander chip's port number + * @return EC_SUCCESS if successful, non-zero if error. + */ +int ioex_init(int ioex); + +/* + * Get the name for the IOEX signal + * + * @param signal IOEX signal to get the name + * @returns name of the given IOEX signal + */ +const char *ioex_get_name(enum ioex_signal signal); +#endif /* __CROS_EC_IOEXPANDER_H */ + |