summaryrefslogtreecommitdiff
path: root/include/i2c.h
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2022-09-21 14:08:36 -0700
committerTom Hughes <tomhughes@chromium.org>2022-09-22 12:59:38 -0700
commitc453fd704268ef72de871b0c5ac7a989de662334 (patch)
treefcf6ce5810f9ff9e3c8cce434812dd75492269ed /include/i2c.h
parent6c1587ca70f558b4f96b3f0b18ad8b027d3ba99d (diff)
parent28712dae9d7ed1e694f7622cc083afa71090d4d5 (diff)
downloadchrome-ec-firmware-fpmcu-dartmonkey-release.tar.gz
Merge remote-tracking branch cros/main into firmware-fpmcu-dartmonkey-releasefirmware-fpmcu-dartmonkey-release
Generated by: ./util/update_release_branch.py --board dartmonkey --relevant_paths_file ./util/fingerprint-relevant-paths.txt firmware-fpmcu-dartmonkey-release Relevant changes: git log --oneline 6c1587ca70..28712dae9d -- board/nocturne_fp board/dartmonkey common/fpsensor docs/fingerprint driver/fingerprint util/getversion.sh ded9307b79 util/getversion.sh: Fix version when not in a git repo 956055e692 board: change Google USB vendor info 71b2ef709d Update license boilerplate text in source code files 33e11afda0 Revert "fpsensor: Build fpsensor source file with C++" c8d0360723 fpsensor: Build fpsensor source file with C++ bc113abd53 fpsensor: Fix g++ compiler error 150a58a0dc fpsensor: Fix fp_set_sensor_mode return type b33b5ce85b fpsensor: Remove nested designators for C++ compatibility 2e864b2539 tree-wide: const-ify argv for console commands 56d8b360f9 test: Add test for get ikm failure when seed not set 3a3d6c3690 test: Add test for fpsensor trivial key failure 233e6bbd08 fpsensor_crypto: Abstract calls to hmac_SHA256 0a041b285b docs/fingerprint: Typo correction c03fab67e2 docs/fingerprint: Fix the path of fputils.py 0b5d4baf5a util/getversion.sh: Fix empty file list handling 6e128fe760 FPMCU dev board environment with Satlab 3eb29b6aa5 builtin: Move ssize_t to sys/types.h 345d62ebd1 docs/fingerprint: Update power numbers for latest dartmonkey release c25ffdb316 common: Conditionally support printf %l and %i modifiers 9a3c514b45 test: Add a test to check if the debugger is connected 54e603413f Move standard library tests to their own file 43fa6b4bf8 docs/fingerprint: Update power numbers for latest bloonchipper release 25536f9a84 driver/fingerprint/fpc/bep/fpc_sensor_spi.c: Format with clang-format 4face99efd driver/fingerprint/fpc/libfp/fpc_sensor_pal.h: Format with clang-format 738de2b575 trng: Rename rand to trng_rand 14b8270edd docs/fingerprint: Update dragonclaw power numbers 0b268f93d1 driver/fingerprint/fpc/libfp/fpc_private.c: Format with clang-format f80da163f2 driver/fingerprint/fpc/libfp/fpc_private.h: Format with clang-format a0751778f4 board/nocturne_fp/ro_workarounds.c: Format with clang-format 5e9c85c9b1 driver/fingerprint/fpc/libfp/fpc_sensor_pal.c: Format with clang-format c1f9dd3cf8 driver/fingerprint/fpc/libfp/fpc_bio_algorithm.h: Format with clang-format eb1e1bed8d driver/fingerprint/fpc/libfp/fpc1145_private.h: Format with clang-format 6e7b611821 driver/fingerprint/fpc/bep/fpc_bio_algorithm.h: Format with clang-format e0589cd5e2 driver/fingerprint/fpc/bep/fpc1035_private.h: Format with clang-format 58f0246dbe board/nocturne_fp/board_ro.c: Format with clang-format 7905e556a0 common/fpsensor/fpsensor_crypto.c: Format with clang-format 21289d170c driver/fingerprint/fpc/bep/fpc1025_private.h: Format with clang-format 98a20f937e common/fpsensor/fpsensor_state.c: Format with clang-format a2d255d8af common/fpsensor/fpsensor.c: Format with clang-format 84e53a65da board/nocturne_fp/board.h: Format with clang-format 73055eeb3f driver/fingerprint/fpc/bep/fpc_private.c: Format with clang-format 0f7b5cb509 common/fpsensor/fpsensor_private.h: Format with clang-format 1ceade6e65 driver/fingerprint/fpc/bep/fpc_private.h: Format with clang-format dca9d74321 Revert "trng: Rename rand to trng_rand" a6b0b3554f trng: Rename rand to trng_rand 28d0b75b70 third_party/boringssl: Remove unused header BRANCH=None BUG=b:244387210 b:242720240 b:215613183 b:242720910 b:236386294 BUG=b:234181908 b:244781166 b:234781655 b:234143158 b:234181908 BUG=b:237344361 b:236025198 b:234181908 b:180945056 chromium:1098010 BUG=b:246424843 b:234181908 b:131913998 TEST=`make -j buildall` TEST=./util/run_device_tests.py --board dartmonkey Test "aes": PASSED Test "cec": PASSED Test "cortexm_fpu": PASSED Test "crc": PASSED Test "flash_physical": PASSED Test "flash_write_protect": PASSED Test "fpsensor_hw": PASSED Test "fpsensor_spi_ro": PASSED Test "fpsensor_spi_rw": PASSED Test "fpsensor_uart_ro": PASSED Test "fpsensor_uart_rw": PASSED Test "mpu_ro": PASSED Test "mpu_rw": PASSED Test "mutex": PASSED Test "pingpong": PASSED Test "printf": PASSED Test "queue": PASSED Test "rollback_region0": PASSED Test "rollback_region1": PASSED Test "rollback_entropy": PASSED Test "rtc": PASSED Test "sha256": PASSED Test "sha256_unrolled": PASSED Test "static_if": PASSED Test "stdlib": PASSED Test "system_is_locked_wp_on": PASSED Test "system_is_locked_wp_off": PASSED Test "timer_dos": PASSED Test "utils": PASSED Test "utils_str": PASSED Test "panic_data_dartmonkey_v2.0.2887": PASSED Test "panic_data_nocturne_fp_v2.2.64": PASSED Test "panic_data_nami_fp_v2.2.144": PASSED Force-Relevant-Builds: all Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I2c312583a709fedae8fe11d92c22328c3b634bc7
Diffstat (limited to 'include/i2c.h')
-rw-r--r--include/i2c.h201
1 files changed, 78 insertions, 123 deletions
diff --git a/include/i2c.h b/include/i2c.h
index c799b9599d..4da9306abb 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -1,4 +1,4 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -34,15 +34,15 @@
* used here and in motion_sense to give specific meaning to the
* address that is pertinent to its use.
*/
-#define I2C_ADDR_MASK 0x03FF
-#define I2C_FLAG_PEC BIT(13)
-#define I2C_FLAG_BIG_ENDIAN BIT(14)
+#define I2C_ADDR_MASK 0x03FF
+#define I2C_FLAG_PEC BIT(13)
+#define I2C_FLAG_BIG_ENDIAN BIT(14)
/* BIT(15) SPI_FLAG - used in motion_sense to overload address */
-#define I2C_FLAG_ADDR_IS_SPI BIT(15)
+#define I2C_FLAG_ADDR_IS_SPI BIT(15)
-#define I2C_STRIP_FLAGS(addr_flags) ((addr_flags) & I2C_ADDR_MASK)
-#define I2C_USE_PEC(addr_flags) ((addr_flags) & I2C_FLAG_PEC)
-#define I2C_IS_BIG_ENDIAN(addr_flags) ((addr_flags) & I2C_FLAG_BIG_ENDIAN)
+#define I2C_STRIP_FLAGS(addr_flags) ((addr_flags)&I2C_ADDR_MASK)
+#define I2C_USE_PEC(addr_flags) ((addr_flags)&I2C_FLAG_PEC)
+#define I2C_IS_BIG_ENDIAN(addr_flags) ((addr_flags)&I2C_FLAG_BIG_ENDIAN)
/*
* All 7-bit addresses in the following formats
@@ -51,8 +51,8 @@
* are reserved for various purposes. Valid 7-bit client adderesses start at
* 0x08 and end at 0x77 inclusive.
*/
-#define I2C_FIRST_VALID_ADDR 0x08
-#define I2C_LAST_VALID_ADDR 0x77
+#define I2C_FIRST_VALID_ADDR 0x08
+#define I2C_LAST_VALID_ADDR 0x77
/*
* Max data size for a version 3 request/response packet. This is
@@ -67,7 +67,7 @@
#define I2C_RESPONSE_HEADER_SIZE 2
/* This port allows changing speed at runtime */
-#define I2C_PORT_FLAG_DYNAMIC_SPEED BIT(0)
+#define I2C_PORT_FLAG_DYNAMIC_SPEED BIT(0)
/*
* Supported I2C CLK frequencies.
@@ -85,13 +85,10 @@ enum i2c_freq {
* MASK_SET will OR the mask into the old value
* MASK_CLR will AND the ~mask from the old value
*/
-enum mask_update_action {
- MASK_CLR,
- MASK_SET
-};
+enum mask_update_action { MASK_CLR, MASK_SET };
struct i2c_info_t {
- uint16_t port; /* Physical port for device */
+ uint16_t port; /* Physical port for device */
uint16_t addr_flags;
};
@@ -99,17 +96,16 @@ struct i2c_port_t; /* forward declaration */
struct i2c_drv {
int (*xfer)(const struct i2c_port_t *i2c_port,
- const uint16_t addr_flags,
- const uint8_t *out, int out_size,
+ const uint16_t addr_flags, const uint8_t *out, int out_size,
uint8_t *in, int in_size, int flags);
};
/* Data structure to define I2C port configuration. */
struct i2c_port_t {
- int port; /* Port */
+ int port; /* Port */
#ifndef CONFIG_ZEPHYR
- const char *name; /* Port name */
- int kbps; /* Speed in kbps */
+ const char *name; /* Port name */
+ int kbps; /* Speed in kbps */
enum gpio_signal scl; /* Port SCL GPIO line */
enum gpio_signal sda; /* Port SDA GPIO line */
#endif /* CONFIG_ZEPHYR */
@@ -118,7 +114,7 @@ struct i2c_port_t {
int (*passthru_allowed)(const struct i2c_port_t *port,
uint16_t addr_flags);
const struct i2c_drv *drv;
- uint16_t flags; /* I2C_PORT_FLAG_* flags */
+ uint16_t flags; /* I2C_PORT_FLAG_* flags */
};
extern const struct i2c_port_t i2c_ports[];
@@ -126,27 +122,25 @@ extern const unsigned int i2c_ports_used;
#ifdef CONFIG_CMD_I2C_STRESS_TEST
struct i2c_test_reg_info {
- int read_reg; /* Read register (WHO_AM_I, DEV_ID, MAN_ID) */
- int read_val; /* Expected val (WHO_AM_I, DEV_ID, MAN_ID) */
- int write_reg; /* Read/Write reg which doesn't impact the system */
+ int read_reg; /* Read register (WHO_AM_I, DEV_ID, MAN_ID) */
+ int read_val; /* Expected val (WHO_AM_I, DEV_ID, MAN_ID) */
+ int write_reg; /* Read/Write reg which doesn't impact the system */
};
struct i2c_test_results {
- int read_success; /* Successful read count */
- int read_fail; /* Read fail count */
+ int read_success; /* Successful read count */
+ int read_fail; /* Read fail count */
int write_success; /* Successful write count */
- int write_fail; /* Write fail count */
+ int write_fail; /* Write fail count */
};
/* Data structure to define I2C test configuration. */
struct i2c_stress_test_dev {
struct i2c_test_reg_info reg_info;
struct i2c_test_results test_results;
- int (*i2c_read)(const int port,
- const uint16_t addr_flags,
+ int (*i2c_read)(const int port, const uint16_t addr_flags,
const int reg, int *data);
- int (*i2c_write)(const int port,
- const uint16_t addr_flags,
+ int (*i2c_write)(const int port, const uint16_t addr_flags,
const int reg, int data);
int (*i2c_read_dev)(const int reg, int *data);
int (*i2c_write_dev)(const int reg, int data);
@@ -166,15 +160,15 @@ extern const int i2c_test_dev_used;
* Data structure to define I2C Parameters for a command
*/
struct i2c_cmd_desc_t {
- uint8_t port; /* I2C port */
- uint16_t addr_flags; /* Peripheral address and flags */
- uint8_t cmd; /* command, only valid on write operations */
+ uint8_t port; /* I2C port */
+ uint16_t addr_flags; /* Peripheral address and flags */
+ uint8_t cmd; /* command, only valid on write operations */
};
/* Flags for i2c_xfer_unlocked() */
-#define I2C_XFER_START BIT(0) /* Start smbus session from idle state */
-#define I2C_XFER_STOP BIT(1) /* Terminate smbus session with stop bit */
-#define I2C_XFER_SINGLE (I2C_XFER_START | I2C_XFER_STOP) /* One transaction */
+#define I2C_XFER_START BIT(0) /* Start smbus session from idle state */
+#define I2C_XFER_STOP BIT(1) /* Terminate smbus session with stop bit */
+#define I2C_XFER_SINGLE (I2C_XFER_START | I2C_XFER_STOP) /* One transaction */
/**
* Transmit one block of raw data, then receive one block of raw data. However,
@@ -190,10 +184,8 @@ struct i2c_cmd_desc_t {
* @param in_size Number of bytes to receive
* @return EC_SUCCESS, or non-zero if error.
*/
-int i2c_xfer(const int port,
- const uint16_t addr_flags,
- const uint8_t *out, int out_size,
- uint8_t *in, int in_size);
+int i2c_xfer(const int port, const uint16_t addr_flags, const uint8_t *out,
+ int out_size, uint8_t *in, int in_size);
/**
* Same as i2c_xfer, but the bus is not implicitly locked. It must be called
@@ -201,10 +193,9 @@ int i2c_xfer(const int port,
*
* @param flags Flags (see I2C_XFER_* above)
*/
-int i2c_xfer_unlocked(const int port,
- const uint16_t addr_flags,
- const uint8_t *out, int out_size,
- uint8_t *in, int in_size, int flags);
+int i2c_xfer_unlocked(const int port, const uint16_t addr_flags,
+ const uint8_t *out, int out_size, uint8_t *in,
+ int in_size, int flags);
#define I2C_LINE_SCL_HIGH BIT(0)
#define I2C_LINE_SDA_HIGH BIT(1)
@@ -305,54 +296,46 @@ void i2c_set_timeout(int port, uint32_t timeout);
* <addr_flags>, at the specified 8-bit <offset> in the peripheral's address
* space.
*/
-int i2c_read32(const int port,
- const uint16_t addr_flags,
- int offset, int *data);
+int i2c_read32(const int port, const uint16_t addr_flags, int offset,
+ int *data);
/**
* Write a 32-bit register to the peripheral at 7-bit peripheral address
* <addr_flags>, at the specified 8-bit <offset> in the peripheral's address
* space.
*/
-int i2c_write32(const int port,
- const uint16_t addr_flags,
- int offset, int data);
+int i2c_write32(const int port, const uint16_t addr_flags, int offset,
+ int data);
/**
* Read a 16-bit register from the peripheral at 7-bit peripheral address
* <addr_flags>, at the specified 8-bit <offset> in the peripheral's address
* space.
*/
-int i2c_read16(const int port,
- const uint16_t addr_flags,
- int offset, int *data);
+int i2c_read16(const int port, const uint16_t addr_flags, int offset,
+ int *data);
/**
* Write a 16-bit register to the peripheral at 7-bit peripheral address
* <addr_flags>, at the specified 8-bit <offset> in the peripheral's address
* space.
*/
-int i2c_write16(const int port,
- const uint16_t addr_flags,
- int offset, int data);
+int i2c_write16(const int port, const uint16_t addr_flags, int offset,
+ int data);
/**
* Read an 8-bit register from the peripheral at 7-bit peripheral address
* <addr_flags>, at the specified 8-bit <offset> in the peripheral's address
* space.
*/
-int i2c_read8(const int port,
- const uint16_t addr_flags,
- int offset, int *data);
+int i2c_read8(const int port, const uint16_t addr_flags, int offset, int *data);
/**
* Write an 8-bit register to the peripheral at 7-bit peripheral address
* <addr_flags>, at the specified 8-bit <offset> in the peripheral's address
* space.
*/
-int i2c_write8(const int port,
- const uint16_t addr_flags,
- int offset, int data);
+int i2c_write8(const int port, const uint16_t addr_flags, int offset, int data);
/**
* Read, modify, write an i2c register to the peripheral at 7-bit peripheral
@@ -362,17 +345,11 @@ int i2c_write8(const int port,
* is the same as the original value of the register, the write will not be
* performed.
*/
-int i2c_update8(const int port,
- const uint16_t addr_flags,
- const int offset,
- const uint8_t mask,
- const enum mask_update_action action);
+int i2c_update8(const int port, const uint16_t addr_flags, const int offset,
+ const uint8_t mask, const enum mask_update_action action);
-int i2c_update16(const int port,
- const uint16_t addr_flags,
- const int offset,
- const uint16_t mask,
- const enum mask_update_action action);
+int i2c_update16(const int port, const uint16_t addr_flags, const int offset,
+ const uint16_t mask, const enum mask_update_action action);
/**
* Read, modify, write field of an i2c register to the peripheral at 7-bit
@@ -383,48 +360,40 @@ int i2c_update16(const int port,
* new value is not the same as the original value, the new value will be
* written back out to the device, otherwise no write will be performed.
*/
-int i2c_field_update8(const int port,
- const uint16_t addr_flags,
- const int offset,
- const uint8_t field_mask,
+int i2c_field_update8(const int port, const uint16_t addr_flags,
+ const int offset, const uint8_t field_mask,
const uint8_t set_value);
-int i2c_field_update16(const int port,
- const uint16_t addr_flags,
- const int offset,
- const uint16_t field_mask,
+int i2c_field_update16(const int port, const uint16_t addr_flags,
+ const int offset, const uint16_t field_mask,
const uint16_t set_value);
/**
* Read one or two bytes data from the peripheral at 7-bit peripheral address
* <addr_flags>, at 16-bit <offset> in the peripheral's address space.
*/
-int i2c_read_offset16(const int port,
- const uint16_t addr_flags,
+int i2c_read_offset16(const int port, const uint16_t addr_flags,
uint16_t offset, int *data, int len);
/**
* Write one or two bytes data to the peripheral at 7-bit peripheral address
* <addr_flags>, at 16-bit <offset> in the peripheral's address space.
*/
-int i2c_write_offset16(const int port,
- const uint16_t addr_flags,
+int i2c_write_offset16(const int port, const uint16_t addr_flags,
uint16_t offset, int data, int len);
/**
* Read <len> bytes block data from the peripheral at 7-bit peripheral address
* * <addr_flags>, at 16-bit <offset> in the peripheral's address space.
*/
-int i2c_read_offset16_block(const int port,
- const uint16_t addr_flags,
+int i2c_read_offset16_block(const int port, const uint16_t addr_flags,
uint16_t offset, uint8_t *data, int len);
/**
* Write <len> bytes block data to the peripheral at 7-bit peripheral address
* <addr_flags>, at 16-bit <offset> in the peripheral's address space.
*/
-int i2c_write_offset16_block(const int port,
- const uint16_t addr_flags,
+int i2c_write_offset16_block(const int port, const uint16_t addr_flags,
uint16_t offset, const uint8_t *data, int len);
/**
@@ -448,9 +417,8 @@ int i2c_unwedge(int port);
*
* <len> : the max length of receiving buffer
*/
-int i2c_read_sized_block(const int port,
- const uint16_t addr_flags,
- int offset, uint8_t *data, int max_len, int *read_len);
+int i2c_read_sized_block(const int port, const uint16_t addr_flags, int offset,
+ uint8_t *data, int max_len, int *read_len);
/**
* Read ascii string using smbus read block protocol.
@@ -462,27 +430,24 @@ int i2c_read_sized_block(const int port,
* terminating 0. Similar to strlcpy, the terminating null is
* always written into the output buffer.
*/
-int i2c_read_string(const int port,
- const uint16_t addr_flags,
- int offset, uint8_t *data, int len);
+int i2c_read_string(const int port, const uint16_t addr_flags, int offset,
+ uint8_t *data, int len);
/**
* Read a data block of <len> 8-bit transfers from the peripheral at 7-bit
* peripheral address <addr_flags>, at the specified 8-bit <offset> in the
* peripheral's address space.
*/
-int i2c_read_block(const int port,
- const uint16_t addr_flags,
- int offset, uint8_t *data, int len);
+int i2c_read_block(const int port, const uint16_t addr_flags, int offset,
+ uint8_t *data, int len);
/**
* Write a data block of <len> 8-bit transfers to the peripheral at 7-bit
* peripheral address <addr_flags>, at the specified 8-bit <offset> in the
* peripheral's address space.
*/
-int i2c_write_block(const int port,
- const uint16_t addr_flags,
- int offset, const uint8_t *data, int len);
+int i2c_write_block(const int port, const uint16_t addr_flags, int offset,
+ const uint8_t *data, int len);
/**
* Convert port number to controller number, for multi-port controllers.
@@ -548,8 +513,7 @@ int board_is_i2c_port_powered(int port);
* @param addr_flags: Peripheral device address
*
*/
-void i2c_start_xfer_notify(const int port,
- const uint16_t addr_flags);
+void i2c_start_xfer_notify(const int port, const uint16_t addr_flags);
/**
* Function to allow board to take any action after an i2c transaction on a
@@ -560,8 +524,7 @@ void i2c_start_xfer_notify(const int port,
* @param addr_flags: Peripheral device address
*
*/
-void i2c_end_xfer_notify(const int port,
- const uint16_t addr_flags);
+void i2c_end_xfer_notify(const int port, const uint16_t addr_flags);
/**
* Defined in common/i2c_trace.c, used by i2c controller to notify tracing
@@ -575,9 +538,9 @@ void i2c_end_xfer_notify(const int port,
* @param in_size: size of data read
* @param ret: return of i2c transaction (EC_SUCCESS or otherwise on failure)
*/
-void i2c_trace_notify(int port, uint16_t addr_flags,
- const uint8_t *out_data, size_t out_size,
- const uint8_t *in_data, size_t in_size, int ret);
+void i2c_trace_notify(int port, uint16_t addr_flags, const uint8_t *out_data,
+ size_t out_size, const uint8_t *in_data, size_t in_size,
+ int ret);
/**
* Convert an enum i2c_freq constant to numeric frequency in kHz.
@@ -622,18 +585,10 @@ enum i2c_freq i2c_get_freq(int port);
/* Find the matching port in i2c_ports[] table. */
const struct i2c_port_t *get_i2c_port(const int port);
-/**
- * @brief Get soc's i2c port number where i2c device is connected to.
- *
- * This function translate a i2c port enum value (enum-name property listed in
- * named-i2c-ports) to soc's i2c port. Devices which are connected to the
- * same port of soc should have the same number.
- *
- * @param enum_port i2c port enum value.
- * @return i2c port of soc used in mutex_lock().
- * -1 if physical port is not defined or i2c port number is out of
- * port_mutex space.
- */
-int i2c_get_physical_port(int enum_port);
+#ifdef CONFIG_ZTEST
+int i2c_port_is_locked(int port);
+#endif
+
+__test_only void i2c_passthru_protect_reset(void);
-#endif /* __CROS_EC_I2C_H */
+#endif /* __CROS_EC_I2C_H */