2015-08-27 05:56:43 +08:00
|
|
|
/* dw_i2c.h - header for Design Ware I2C operations */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Intel Corporation
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-08-27 05:56:43 +08:00
|
|
|
*/
|
2018-09-15 01:43:44 +08:00
|
|
|
#ifndef ZEPHYR_DRIVERS_I2C_I2C_DW_H_
|
|
|
|
#define ZEPHYR_DRIVERS_I2C_I2C_DW_H_
|
2015-08-27 05:56:43 +08:00
|
|
|
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/drivers/i2c.h>
|
2015-08-27 05:56:43 +08:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2020-03-20 03:46:21 +08:00
|
|
|
#define DT_DRV_COMPAT snps_designware_i2c
|
|
|
|
|
2021-01-19 18:46:43 +08:00
|
|
|
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(pcie)
|
2020-03-12 23:16:00 +08:00
|
|
|
BUILD_ASSERT(IS_ENABLED(CONFIG_PCIE), "DW I2C in DT needs CONFIG_PCIE");
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/drivers/pcie/pcie.h>
|
2019-05-17 06:33:09 +08:00
|
|
|
#endif
|
2015-08-27 05:56:43 +08:00
|
|
|
|
2023-09-08 19:21:00 +08:00
|
|
|
#if defined(CONFIG_RESET)
|
|
|
|
#include <zephyr/drivers/reset.h>
|
|
|
|
#endif
|
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-09-20 10:54:53 +08:00
|
|
|
#define I2C_DW_MAGIC_KEY 0x44570140
|
2015-08-27 05:56:43 +08:00
|
|
|
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
typedef void (*i2c_isr_cb_t)(const struct device *port);
|
2015-08-27 05:56:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
#define IC_ACTIVITY (1 << 0)
|
|
|
|
#define IC_ENABLE_BIT (1 << 0)
|
|
|
|
|
|
|
|
|
|
|
|
/* dev->state values from IC_DATA_CMD Data transfer mode settings (bit 8) */
|
2015-09-20 10:54:53 +08:00
|
|
|
#define I2C_DW_STATE_READY (0)
|
|
|
|
#define I2C_DW_CMD_SEND (1 << 0)
|
|
|
|
#define I2C_DW_CMD_RECV (1 << 1)
|
|
|
|
#define I2C_DW_CMD_ERROR (1 << 2)
|
2015-10-07 02:29:30 +08:00
|
|
|
#define I2C_DW_BUSY (1 << 3)
|
2015-08-27 05:56:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
#define DW_ENABLE_TX_INT_I2C_MASTER (DW_INTR_STAT_TX_OVER | \
|
|
|
|
DW_INTR_STAT_TX_EMPTY | \
|
|
|
|
DW_INTR_STAT_TX_ABRT | \
|
|
|
|
DW_INTR_STAT_STOP_DET)
|
|
|
|
#define DW_ENABLE_RX_INT_I2C_MASTER (DW_INTR_STAT_RX_UNDER | \
|
|
|
|
DW_INTR_STAT_RX_OVER | \
|
|
|
|
DW_INTR_STAT_RX_FULL | \
|
|
|
|
DW_INTR_STAT_STOP_DET)
|
|
|
|
|
|
|
|
#define DW_ENABLE_TX_INT_I2C_SLAVE (DW_INTR_STAT_RD_REQ | \
|
|
|
|
DW_INTR_STAT_TX_ABRT | \
|
|
|
|
DW_INTR_STAT_STOP_DET)
|
|
|
|
#define DW_ENABLE_RX_INT_I2C_SLAVE (DW_INTR_STAT_RX_FULL | \
|
|
|
|
DW_INTR_STAT_STOP_DET)
|
|
|
|
|
|
|
|
#define DW_DISABLE_ALL_I2C_INT 0x00000000
|
|
|
|
|
|
|
|
|
|
|
|
/* IC_CON Low count and high count default values */
|
|
|
|
/* TODO verify values for high and fast speed */
|
2017-04-08 06:29:49 +08:00
|
|
|
#define I2C_STD_HCNT (CONFIG_I2C_DW_CLOCK_SPEED * 4)
|
|
|
|
#define I2C_STD_LCNT (CONFIG_I2C_DW_CLOCK_SPEED * 5)
|
|
|
|
#define I2C_FS_HCNT ((CONFIG_I2C_DW_CLOCK_SPEED * 6) / 8)
|
|
|
|
#define I2C_FS_LCNT ((CONFIG_I2C_DW_CLOCK_SPEED * 7) / 8)
|
|
|
|
#define I2C_HS_HCNT ((CONFIG_I2C_DW_CLOCK_SPEED * 6) / 8)
|
|
|
|
#define I2C_HS_LCNT ((CONFIG_I2C_DW_CLOCK_SPEED * 7) / 8)
|
2015-08-27 05:56:43 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* DesignWare speed values don't directly translate from the Zephyr speed
|
|
|
|
* selections in include/i2c.h so here we do a little translation
|
|
|
|
*/
|
2015-09-20 10:54:53 +08:00
|
|
|
#define I2C_DW_SPEED_STANDARD 0x1
|
|
|
|
#define I2C_DW_SPEED_FAST 0x2
|
|
|
|
#define I2C_DW_SPEED_FAST_PLUS 0x2
|
|
|
|
#define I2C_DW_SPEED_HIGH 0x3
|
2015-08-27 05:56:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These values have been randomly selected. It would be good to test different
|
|
|
|
* watermark levels for performance capabilities
|
|
|
|
*/
|
2015-09-20 10:54:53 +08:00
|
|
|
#define I2C_DW_TX_WATERMARK 2
|
|
|
|
#define I2C_DW_RX_WATERMARK 7
|
2015-08-27 05:56:43 +08:00
|
|
|
|
|
|
|
|
2015-09-24 06:23:53 +08:00
|
|
|
struct i2c_dw_rom_config {
|
2020-06-27 07:45:04 +08:00
|
|
|
DEVICE_MMIO_ROM;
|
2015-08-27 05:56:43 +08:00
|
|
|
i2c_isr_cb_t config_func;
|
2020-05-28 00:26:57 +08:00
|
|
|
uint32_t bitrate;
|
2022-02-08 18:49:50 +08:00
|
|
|
|
|
|
|
#if defined(CONFIG_PINCTRL)
|
|
|
|
const struct pinctrl_dev_config *pcfg;
|
|
|
|
#endif
|
2023-09-08 19:21:00 +08:00
|
|
|
#if defined(CONFIG_RESET)
|
|
|
|
const struct reset_dt_spec reset;
|
|
|
|
#endif
|
2022-02-08 18:49:50 +08:00
|
|
|
|
2021-01-19 18:46:43 +08:00
|
|
|
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(pcie)
|
2022-11-11 16:36:44 +08:00
|
|
|
struct pcie_dev *pcie;
|
2019-05-17 06:33:09 +08:00
|
|
|
#endif /* I2C_DW_PCIE_ENABLED */
|
2023-12-21 15:03:10 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_I2C_DW_LPSS_DMA
|
|
|
|
const struct device *dma_dev;
|
|
|
|
#endif
|
2015-08-27 05:56:43 +08:00
|
|
|
};
|
|
|
|
|
2015-09-24 06:23:53 +08:00
|
|
|
struct i2c_dw_dev_config {
|
2020-06-27 07:45:04 +08:00
|
|
|
DEVICE_MMIO_RAM;
|
2016-12-07 08:57:41 +08:00
|
|
|
struct k_sem device_sync_sem;
|
2023-01-13 03:27:47 +08:00
|
|
|
struct k_mutex bus_mutex;
|
2020-05-28 00:26:57 +08:00
|
|
|
uint32_t app_config;
|
2015-08-27 05:56:43 +08:00
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
uint8_t *xfr_buf;
|
|
|
|
uint32_t xfr_len;
|
|
|
|
uint32_t rx_pending;
|
2015-08-27 05:56:43 +08:00
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
uint16_t hcnt;
|
|
|
|
uint16_t lcnt;
|
2016-01-29 04:53:34 +08:00
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
volatile uint8_t state; /* last direction of transfer */
|
|
|
|
uint8_t request_bytes;
|
|
|
|
uint8_t xfr_flags;
|
2016-01-29 04:53:34 +08:00
|
|
|
bool support_hs_mode;
|
2023-08-08 13:15:49 +08:00
|
|
|
#ifdef CONFIG_I2C_DW_LPSS_DMA
|
|
|
|
uintptr_t phy_addr;
|
|
|
|
uintptr_t base_addr;
|
|
|
|
/* For dma transfer */
|
|
|
|
bool xfr_status;
|
|
|
|
#endif
|
2022-02-07 00:32:20 +08:00
|
|
|
|
2022-05-24 01:15:02 +08:00
|
|
|
struct i2c_target_config *slave_cfg;
|
2015-08-27 05:56:43 +08:00
|
|
|
};
|
|
|
|
|
2021-03-04 17:11:00 +08:00
|
|
|
#define Z_REG_READ(__sz) sys_read##__sz
|
|
|
|
#define Z_REG_WRITE(__sz) sys_write##__sz
|
|
|
|
#define Z_REG_SET_BIT sys_set_bit
|
|
|
|
#define Z_REG_CLEAR_BIT sys_clear_bit
|
|
|
|
#define Z_REG_TEST_BIT sys_test_bit
|
|
|
|
|
|
|
|
#define DEFINE_MM_REG_READ(__reg, __off, __sz) \
|
|
|
|
static inline uint32_t read_##__reg(uint32_t addr) \
|
|
|
|
{ \
|
|
|
|
return Z_REG_READ(__sz)(addr + __off); \
|
|
|
|
}
|
|
|
|
#define DEFINE_MM_REG_WRITE(__reg, __off, __sz) \
|
|
|
|
static inline void write_##__reg(uint32_t data, uint32_t addr) \
|
|
|
|
{ \
|
|
|
|
Z_REG_WRITE(__sz)(data, addr + __off); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEFINE_SET_BIT_OP(__reg_bit, __reg_off, __bit) \
|
|
|
|
static inline void set_bit_##__reg_bit(uint32_t addr) \
|
|
|
|
{ \
|
|
|
|
Z_REG_SET_BIT(addr + __reg_off, __bit); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEFINE_CLEAR_BIT_OP(__reg_bit, __reg_off, __bit) \
|
|
|
|
static inline void clear_bit_##__reg_bit(uint32_t addr) \
|
|
|
|
{ \
|
|
|
|
Z_REG_CLEAR_BIT(addr + __reg_off, __bit); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEFINE_TEST_BIT_OP(__reg_bit, __reg_off, __bit) \
|
|
|
|
static inline int test_bit_##__reg_bit(uint32_t addr) \
|
|
|
|
{ \
|
|
|
|
return Z_REG_TEST_BIT(addr + __reg_off, __bit); \
|
|
|
|
}
|
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-09-15 01:43:44 +08:00
|
|
|
#endif /* ZEPHYR_DRIVERS_I2C_I2C_DW_H_ */
|