summaryrefslogtreecommitdiff
path: root/board/servo_v4p1
diff options
context:
space:
mode:
authorSam Hurst <shurst@google.com>2020-06-01 10:53:18 -0700
committerCommit Bot <commit-bot@chromium.org>2020-06-09 22:36:04 +0000
commitcf2a457ac189e46c85e78c7adb46e3485ae14f5d (patch)
tree727ce8785ca30c1ca33d4f0d3122f9fed5f45437 /board/servo_v4p1
parent9f95ab8d1655d141dcceec18d6730c9d6451e4a9 (diff)
downloadchrome-ec-cf2a457ac189e46c85e78c7adb46e3485ae14f5d.tar.gz
servo_v4p1: Add TCA6416A and TCA6424A drivers
Add TCA6416A and TCA6424A IO Expander driver. BRANCH=none BUG=b:146793000 TEST=make -j buildall Signed-off-by: Sam Hurst <shurst@google.com> Change-Id: I498496bab9f1b874b502c2a1f704d1693a7c1cf5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2223822 Reviewed-by: Wai-Hong Tam <waihong@google.com>
Diffstat (limited to 'board/servo_v4p1')
-rw-r--r--board/servo_v4p1/build.mk2
-rw-r--r--board/servo_v4p1/tca6416a.c63
-rw-r--r--board/servo_v4p1/tca6416a.h66
-rw-r--r--board/servo_v4p1/tca6424a.c63
-rw-r--r--board/servo_v4p1/tca6424a.h69
5 files changed, 262 insertions, 1 deletions
diff --git a/board/servo_v4p1/build.mk b/board/servo_v4p1/build.mk
index a38a31279d..f08de907e1 100644
--- a/board/servo_v4p1/build.mk
+++ b/board/servo_v4p1/build.mk
@@ -14,6 +14,6 @@ CHIP_VARIANT:=stm32f07x
test-list-y=
# These files are compiled into RO and RW
-board-y=board.o
+board-y=board.o tca6416a.o tca6424a.o
all_deps=$(patsubst ro,,$(def_all_deps))
diff --git a/board/servo_v4p1/tca6416a.c b/board/servo_v4p1/tca6416a.c
new file mode 100644
index 0000000000..d776ad86fe
--- /dev/null
+++ b/board/servo_v4p1/tca6416a.c
@@ -0,0 +1,63 @@
+/* Copyright 2020 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.
+ */
+
+#include "i2c.h"
+#include "tca6416a.h"
+
+int tca6416a_write_bit(int port, enum tca6416a_bank bank, uint8_t bit, int val)
+{
+ int tmp;
+ int ret;
+
+ /* Read output port register */
+ ret = i2c_read8(port, TCA6416A_ADDR_FLAGS, bank, &tmp);
+ if (ret != EC_SUCCESS)
+ return ret;
+
+ if (val)
+ tmp |= BIT(bit);
+ else
+ tmp &= ~BIT(bit);
+
+ /* Write back modified output port register */
+ ret = i2c_write8(port, TCA6416A_ADDR_FLAGS, bank, tmp);
+ if (ret != EC_SUCCESS)
+ return ret;
+
+ return EC_SUCCESS;
+}
+
+int tca6416a_write_byte(int port, enum tca6416a_bank bank, uint8_t val)
+{
+ int ret;
+
+ ret = i2c_write8(port, TCA6416A_ADDR_FLAGS, bank, val);
+ if (ret != EC_SUCCESS)
+ return ret;
+
+ return EC_SUCCESS;
+}
+
+int tca6416a_read_byte(int port, enum tca6416a_bank bank)
+{
+ int tmp;
+
+ if (i2c_read8(port, TCA6416A_ADDR_FLAGS, bank, &tmp) != EC_SUCCESS)
+ return -1;
+
+ return tmp;
+}
+
+int tca6416a_read_bit(int port, enum tca6416a_bank bank, uint8_t bit)
+{
+ int tmp;
+ int mask = 1 << bit;
+
+ /* Read input port register */
+ if (i2c_read8(port, TCA6416A_ADDR_FLAGS, bank, &tmp) != EC_SUCCESS)
+ return -1;
+
+ return (tmp & mask) >> bit;
+}
diff --git a/board/servo_v4p1/tca6416a.h b/board/servo_v4p1/tca6416a.h
new file mode 100644
index 0000000000..5255059d99
--- /dev/null
+++ b/board/servo_v4p1/tca6416a.h
@@ -0,0 +1,66 @@
+/* Copyright 2020 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_TCA6416A_H
+#define __CROS_EC_IOEXPANDER_TCA6416A_H
+
+#include <stdint.h>
+
+#define TCA6416A_ADDR_FLAGS 0x21
+
+enum tca6416a_bank {
+ TCA6416A_IN_PORT_0 = 0x0,
+ TCA6416A_IN_PORT_1 = 0x1,
+ TCA6416A_OUT_PORT_0 = 0x2,
+ TCA6416A_OUT_PORT_1 = 0x3,
+ TCA6416A_DIR_PORT_0 = 0x6,
+ TCA6416A_DIR_PORT_1 = 0x7,
+};
+
+/*
+ * Set a bit in the supplied bank
+ *
+ * @param port The I2C port of TCA6416A.
+ * @param bank The bank the bit belongs to.
+ * @param bit The index of the bit to set.
+ * @param val The value to set.
+ *
+ * @return EC_SUCCESS, or EC_ERROR_* on error.
+ */
+int tca6416a_write_bit(int port,
+ enum tca6416a_bank bank, uint8_t bit, int val);
+
+/*
+ * Get a bit in the supplied bank
+ *
+ * @param port The I2C port of TCA6416A.
+ * @param bank The bank the bit belongs to.
+ * @param bit The index of the bit to get.
+ *
+ * @return bit value, or -1 on error.
+ */
+int tca6416a_read_bit(int port, enum tca6416a_bank bank, uint8_t bit);
+
+/*
+ * Write a byt to the supplied bank
+ *
+ * @param port The I2C port of TCA6416A.
+ * @param bank The bank to write the byte to.
+ *
+ * @return EC_SUCCESS, or EC_ERROR_* on error.
+ */
+int tca6416a_write_byte(int port, enum tca6416a_bank bank, uint8_t val);
+
+/*
+ * Read a byte in the supplied bank
+ *
+ * @param port The I2C port of TCA6416A.
+ * @param bank The bank to read byte from.
+ *
+ * @return byte value, or -1 on error.
+ */
+int tca6416a_read_byte(int port, enum tca6416a_bank bank);
+
+#endif /* __CROS_EC_IOEXPANDER_TCA6416A_H */
diff --git a/board/servo_v4p1/tca6424a.c b/board/servo_v4p1/tca6424a.c
new file mode 100644
index 0000000000..28c768b046
--- /dev/null
+++ b/board/servo_v4p1/tca6424a.c
@@ -0,0 +1,63 @@
+/* Copyright 2020 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.
+ */
+
+#include "i2c.h"
+#include "tca6424a.h"
+
+int tca6424a_write_bit(int port, enum tca6424a_bank bank, uint8_t bit, int val)
+{
+ int tmp;
+ int ret;
+
+ /* Read output port register */
+ ret = i2c_read8(port, TCA6424A_ADDR_FLAGS, bank, &tmp);
+ if (ret != EC_SUCCESS)
+ return ret;
+
+ if (val)
+ tmp |= BIT(bit);
+ else
+ tmp &= ~BIT(bit);
+
+ /* Write back modified output port register */
+ ret = i2c_write8(port, TCA6424A_ADDR_FLAGS, bank, tmp);
+ if (ret != EC_SUCCESS)
+ return ret;
+
+ return EC_SUCCESS;
+}
+
+int tca6424a_write_byte(int port, enum tca6424a_bank bank, uint8_t val)
+{
+ int ret;
+
+ ret = i2c_write8(port, TCA6424A_ADDR_FLAGS, bank, val);
+ if (ret != EC_SUCCESS)
+ return ret;
+
+ return EC_SUCCESS;
+}
+
+int tca6424a_read_byte(int port, enum tca6424a_bank bank)
+{
+ int tmp;
+
+ if (i2c_read8(port, TCA6424A_ADDR_FLAGS, bank, &tmp) != EC_SUCCESS)
+ return -1;
+
+ return tmp;
+}
+
+int tca6424a_read_bit(int port, enum tca6424a_bank bank, uint8_t bit)
+{
+ int tmp;
+ int mask = 1 << bit;
+
+ /* Read input port register */
+ if (i2c_read8(port, TCA6424A_ADDR_FLAGS, bank, &tmp) != EC_SUCCESS)
+ return -1;
+
+ return (tmp & mask) >> bit;
+}
diff --git a/board/servo_v4p1/tca6424a.h b/board/servo_v4p1/tca6424a.h
new file mode 100644
index 0000000000..80db7ebdba
--- /dev/null
+++ b/board/servo_v4p1/tca6424a.h
@@ -0,0 +1,69 @@
+/* Copyright 2020 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_TCA6424A_H
+#define __CROS_EC_IOEXPANDER_TCA6424A_H
+
+#include <stdint.h>
+
+#define TCA6424A_ADDR_FLAGS 0x23
+
+enum tca6424a_bank {
+ TCA6424A_IN_PORT_0 = 0x0,
+ TCA6424A_IN_PORT_1 = 0x1,
+ TCA6424A_IN_PORT_2 = 0x2,
+ TCA6424A_OUT_PORT_0 = 0x4,
+ TCA6424A_OUT_PORT_1 = 0x5,
+ TCA6424A_OUT_PORT_2 = 0x6,
+ TCA6424A_DIR_PORT_0 = 0xc,
+ TCA6424A_DIR_PORT_1 = 0xd,
+ TCA6424A_DIR_PORT_2 = 0xe,
+};
+
+/*
+ * Set a bit in the supplied bank
+ *
+ * @param port The I2C port of TCA6424A.
+ * @param bank The bank the bit belongs to.
+ * @param bit The index of the bit to set.
+ * @param val The value to set.
+ *
+ * @return EC_SUCCESS, or EC_ERROR_* on error.
+ */
+int tca6424a_write_bit(int port,
+ enum tca6424a_bank bank, uint8_t bit, int val);
+
+/*
+ * Get a bit in the supplied bank
+ *
+ * @param port The I2C port of TCA6424A.
+ * @param bank The bank the bit belongs to.
+ * @param bit The index of the bit to get.
+ *
+ * @return bit value, or -1 on error.
+ */
+int tca6424a_read_bit(int port, enum tca6424a_bank bank, uint8_t bit);
+
+/*
+ * Write a byt to the supplied bank
+ *
+ * @param port The I2C port of TCA6424A.
+ * @param bank The bank to write the byte to.
+ *
+ * @return EC_SUCCESS, or EC_ERROR_* on error.
+ */
+int tca6424a_write_byte(int port, enum tca6424a_bank bank, uint8_t val);
+
+/*
+ * Read a byte in the supplied bank
+ *
+ * @param port The I2C port of TCA6424A.
+ * @param bank The bank to read byte from.
+ *
+ * @return byte value, or -1 on error.
+ */
+int tca6424a_read_byte(int port, enum tca6424a_bank bank);
+
+#endif /* __CROS_EC_IOEXPANDER_TCA6424A_H */