coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
i2c_common.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef MTK_COMMON_I2C_H
4 #define MTK_COMMON_I2C_H
5 
6 #include <device/i2c.h>
7 
8 /* I2C DMA Registers */
21 };
22 
23 check_member(mt_i2c_dma_regs, dma_tx_len, 0x24);
24 
25 /* I2C Configuration */
26 enum {
28 };
29 
30 enum i2c_modes {
34 };
35 
36 enum {
49 };
50 
51 enum {
53  I2C_TRANS_AUX_LEN_MASK = (0x1f << 8),
54  I2C_CONTROL_MASK = (0x3f << 1)
55 };
56 
57 enum {
60 };
61 
62 /* Register mask */
63 enum {
64  I2C_HS_NACKERR = (1 << 2),
65  I2C_ACKERR = (1 << 1),
66  I2C_TRANSAC_COMP = (1 << 0),
67 };
68 
69 /* reset bits */
70 enum {
71  I2C_CLR_FLAG = 0x0,
72  I2C_SOFT_RST = 0x1,
74 };
75 
76 /* i2c control bits */
77 enum {
78  ASYNC_MODE = (1 << 9),
79  DMAACK_EN = (1 << 8),
80  ACK_ERR_DET_EN = (1 << 5),
81  DIR_CHG = (1 << 4),
82  CLK_EXT = (1 << 3),
83  DMA_EN = (1 << 2),
84  REPEATED_START_FLAG = (1 << 1),
85  STOP_FLAG = (0 << 1)
86 };
87 
88 /* I2C Status Code */
89 enum {
90  I2C_OK = 0x0000,
97 };
98 
110 };
111 
112 struct mtk_i2c {
117 };
118 
119 #define I2C_TIME_CLR_VALUE 0x0000
120 #define MAX_SAMPLE_CNT_DIV 8
121 #define MAX_STEP_CNT_DIV 64
122 #define MAX_HS_STEP_CNT_DIV 8
123 #define I2C_TIME_DEFAULT_VALUE 0x0083
124 #define I2C_STANDARD_MODE_BUFFER (1000 / 3)
125 #define I2C_FAST_MODE_BUFFER (300 / 3)
126 #define I2C_FAST_MODE_PLUS_BUFFER (20 / 3)
127 
128 /*
129  * struct i2c_spec_values:
130  * @min_low_ns: min LOW period of the SCL clock
131  * @min_su_sta_ns: min set-up time for a repeated START condition
132  * @max_hd_dat_ns: max data hold time
133  * @min_su_dat_ns: min data set-up time
134  */
140 };
141 
142 extern struct mtk_i2c mtk_i2c_bus_controller[];
143 const struct i2c_spec_values *mtk_i2c_get_spec(uint32_t speed);
145 
147  uint32_t check_speed,
148  uint32_t step_cnt,
149  uint32_t sample_cnt);
151  uint32_t target_speed,
152  uint32_t *timing_step_cnt,
153  uint32_t *timing_sample_cnt);
155 void mtk_i2c_config_timing(struct mt_i2c_regs *regs, struct mtk_i2c *bus_ctrl);
156 
157 #endif
int mtk_i2c_check_ac_timing(uint8_t bus, uint32_t clk_src, uint32_t check_speed, uint32_t step_cnt, uint32_t sample_cnt)
Definition: i2c.c:339
check_member(mt_i2c_dma_regs, dma_tx_len, 0x24)
struct mtk_i2c mtk_i2c_bus_controller[]
Definition: i2c.c:10
@ I2C_DMA_SKIP_CONFIG
Definition: i2c_common.h:44
@ I2C_DMA_START_EN
Definition: i2c_common.h:39
@ I2C_DMA_WARM_RST
Definition: i2c_common.h:46
@ I2C_DMA_INT_FLAG_NONE
Definition: i2c_common.h:40
@ I2C_DMA_HANDSHAKE_RST
Definition: i2c_common.h:48
@ I2C_DMA_HARD_RST
Definition: i2c_common.h:47
@ I2C_DMA_ASYNC_MODE
Definition: i2c_common.h:43
@ I2C_DMA_CON_TX
Definition: i2c_common.h:37
@ I2C_DMA_CLR_FLAG
Definition: i2c_common.h:41
@ I2C_DMA_FLUSH_FLAG
Definition: i2c_common.h:42
@ I2C_DMA_CON_RX
Definition: i2c_common.h:38
@ I2C_DMA_DIR_CHANGE
Definition: i2c_common.h:45
@ I2C_HS_DEFAULT_VALUE
Definition: i2c_common.h:27
const struct i2c_spec_values * mtk_i2c_get_spec(uint32_t speed)
Definition: i2c.c:45
i2c_modes
Definition: i2c_common.h:30
@ I2C_WRITE_READ_MODE
Definition: i2c_common.h:33
@ I2C_READ_MODE
Definition: i2c_common.h:32
@ I2C_WRITE_MODE
Definition: i2c_common.h:31
int mtk_i2c_calculate_speed(uint8_t bus, uint32_t clk_src, uint32_t target_speed, uint32_t *timing_step_cnt, uint32_t *timing_sample_cnt)
Definition: i2c.c:408
@ I2C_HANDSHAKE_RST
Definition: i2c_common.h:73
@ I2C_SOFT_RST
Definition: i2c_common.h:72
@ I2C_CLR_FLAG
Definition: i2c_common.h:71
@ I2C_TRANS_LEN_MASK
Definition: i2c_common.h:52
@ I2C_CONTROL_MASK
Definition: i2c_common.h:54
@ I2C_TRANS_AUX_LEN_MASK
Definition: i2c_common.h:53
@ I2C_APDMA_NOASYNC
Definition: i2c_common.h:58
@ I2C_APDMA_ASYNC
Definition: i2c_common.h:59
void mtk_i2c_speed_init(uint8_t bus, uint32_t speed)
Definition: i2c.c:494
@ I2C_HS_NACKERR
Definition: i2c_common.h:64
@ I2C_ACKERR
Definition: i2c_common.h:65
@ I2C_TRANSAC_COMP
Definition: i2c_common.h:66
@ I2C_TRANSFER_INVALID_ARGUMENT
Definition: i2c_common.h:96
@ I2C_SET_SPEED_FAIL_OVER_SPEED
Definition: i2c_common.h:91
@ I2C_TRANSFER_FAIL_TIMEOUT
Definition: i2c_common.h:95
@ I2C_TRANSFER_FAIL_ACKERR
Definition: i2c_common.h:94
@ I2C_TRANSFER_INVALID_LENGTH
Definition: i2c_common.h:92
@ I2C_TRANSFER_FAIL_HS_NACKERR
Definition: i2c_common.h:93
@ I2C_OK
Definition: i2c_common.h:90
void mtk_i2c_config_timing(struct mt_i2c_regs *regs, struct mtk_i2c *bus_ctrl)
Definition: i2c.c:40
@ ACK_ERR_DET_EN
Definition: i2c_common.h:80
@ DIR_CHG
Definition: i2c_common.h:81
@ DMAACK_EN
Definition: i2c_common.h:79
@ DMA_EN
Definition: i2c_common.h:83
@ CLK_EXT
Definition: i2c_common.h:82
@ REPEATED_START_FLAG
Definition: i2c_common.h:84
@ ASYNC_MODE
Definition: i2c_common.h:78
@ STOP_FLAG
Definition: i2c_common.h:85
void mtk_i2c_dump_more_info(struct mt_i2c_regs *regs)
Definition: i2c.c:35
unsigned int uint32_t
Definition: stdint.h:14
uint16_t u16
Definition: stdint.h:48
unsigned char uint8_t
Definition: stdint.h:8
Definition: device.h:76
uint32_t min_su_sta_ns
Definition: i2c_common.h:137
uint32_t min_low_ns
Definition: i2c_common.h:136
uint32_t max_hd_dat_ns
Definition: i2c_common.h:138
uint32_t min_su_dat_ns
Definition: i2c_common.h:139
uint32_t dma_en
Definition: i2c_common.h:12
uint32_t dma_rst
Definition: i2c_common.h:13
uint32_t dma_tx_len
Definition: i2c_common.h:19
uint32_t dma_int_flag
Definition: i2c_common.h:10
uint32_t dma_tx_mem_addr
Definition: i2c_common.h:17
uint32_t dma_flush
Definition: i2c_common.h:15
uint32_t dma_int_en
Definition: i2c_common.h:11
uint32_t dma_con
Definition: i2c_common.h:16
uint32_t reserved1
Definition: i2c_common.h:14
uint32_t dma_rx_mem_addr
Definition: i2c_common.h:18
uint32_t dma_rx_len
Definition: i2c_common.h:20
struct mt_i2c_dma_regs * i2c_dma_regs
Definition: i2c_common.h:114
struct mt_i2c_regs * i2c_regs
Definition: i2c_common.h:113
uint32_t mt_i2c_flag
Definition: i2c_common.h:116
struct mtk_i2c_ac_timing ac_timing
Definition: i2c_common.h:115