blob: 3b407d2bede86b5a0c57666a539cff7cfa0ea766 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Vipin KUMAR2403f8f2010-01-15 19:15:44 +05302/*
3 * (C) Copyright 2009
4 * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com.
Vipin KUMAR2403f8f2010-01-15 19:15:44 +05305 */
6
Vipin KUMAR031ed2f2012-02-26 23:13:29 +00007#ifndef __DW_I2C_H_
8#define __DW_I2C_H_
Vipin KUMAR2403f8f2010-01-15 19:15:44 +05309
Simon Glass457df232019-12-06 21:41:40 -070010#include <reset.h>
11
Vipin KUMAR2403f8f2010-01-15 19:15:44 +053012struct i2c_regs {
Stefan Roesee2098282016-04-21 08:19:37 +020013 u32 ic_con; /* 0x00 */
14 u32 ic_tar; /* 0x04 */
15 u32 ic_sar; /* 0x08 */
16 u32 ic_hs_maddr; /* 0x0c */
17 u32 ic_cmd_data; /* 0x10 */
18 u32 ic_ss_scl_hcnt; /* 0x14 */
19 u32 ic_ss_scl_lcnt; /* 0x18 */
20 u32 ic_fs_scl_hcnt; /* 0x1c */
21 u32 ic_fs_scl_lcnt; /* 0x20 */
22 u32 ic_hs_scl_hcnt; /* 0x24 */
23 u32 ic_hs_scl_lcnt; /* 0x28 */
24 u32 ic_intr_stat; /* 0x2c */
25 u32 ic_intr_mask; /* 0x30 */
26 u32 ic_raw_intr_stat; /* 0x34 */
27 u32 ic_rx_tl; /* 0x38 */
28 u32 ic_tx_tl; /* 0x3c */
29 u32 ic_clr_intr; /* 0x40 */
30 u32 ic_clr_rx_under; /* 0x44 */
31 u32 ic_clr_rx_over; /* 0x48 */
32 u32 ic_clr_tx_over; /* 0x4c */
33 u32 ic_clr_rd_req; /* 0x50 */
34 u32 ic_clr_tx_abrt; /* 0x54 */
35 u32 ic_clr_rx_done; /* 0x58 */
36 u32 ic_clr_activity; /* 0x5c */
37 u32 ic_clr_stop_det; /* 0x60 */
38 u32 ic_clr_start_det; /* 0x64 */
39 u32 ic_clr_gen_call; /* 0x68 */
40 u32 ic_enable; /* 0x6c */
41 u32 ic_status; /* 0x70 */
42 u32 ic_txflr; /* 0x74 */
43 u32 ic_rxflr; /* 0x78 */
44 u32 ic_sda_hold; /* 0x7c */
45 u32 ic_tx_abrt_source; /* 0x80 */
Simon Glass0fd05c92020-01-23 11:48:04 -070046 u32 slv_data_nak_only;
47 u32 dma_cr;
48 u32 dma_tdlr;
49 u32 dma_rdlr;
50 u32 sda_setup;
51 u32 ack_general_call;
Stefan Roesee2098282016-04-21 08:19:37 +020052 u32 ic_enable_status; /* 0x9c */
Simon Glass0fd05c92020-01-23 11:48:04 -070053 u32 fs_spklen;
54 u32 hs_spklen;
55 u32 clr_restart_det;
56 u8 reserved[0xf4 - 0xac];
57 u32 comp_param1; /* 0xf4 */
58 u32 comp_version;
59 u32 comp_type;
Vipin KUMAR2403f8f2010-01-15 19:15:44 +053060};
61
Armando Viscontid40d9142012-12-06 00:04:19 +000062#if !defined(IC_CLK)
Vipin KUMAR2403f8f2010-01-15 19:15:44 +053063#define IC_CLK 166
Armando Viscontid40d9142012-12-06 00:04:19 +000064#endif
Vipin KUMAR2403f8f2010-01-15 19:15:44 +053065#define NANO_TO_MICRO 1000
66
67/* High and low times in different speed modes (in ns) */
68#define MIN_SS_SCL_HIGHTIME 4000
Armando Viscontiea31b7a2012-12-06 00:04:18 +000069#define MIN_SS_SCL_LOWTIME 4700
70#define MIN_FS_SCL_HIGHTIME 600
71#define MIN_FS_SCL_LOWTIME 1300
Vipin KUMAR2403f8f2010-01-15 19:15:44 +053072#define MIN_HS_SCL_HIGHTIME 60
73#define MIN_HS_SCL_LOWTIME 160
74
75/* Worst case timeout for 1 byte is kept as 2ms */
76#define I2C_BYTE_TO (CONFIG_SYS_HZ/500)
77#define I2C_STOPDET_TO (CONFIG_SYS_HZ/500)
78#define I2C_BYTE_TO_BB (I2C_BYTE_TO * 16)
79
80/* i2c control register definitions */
81#define IC_CON_SD 0x0040
82#define IC_CON_RE 0x0020
83#define IC_CON_10BITADDRMASTER 0x0010
84#define IC_CON_10BITADDR_SLAVE 0x0008
85#define IC_CON_SPD_MSK 0x0006
86#define IC_CON_SPD_SS 0x0002
87#define IC_CON_SPD_FS 0x0004
88#define IC_CON_SPD_HS 0x0006
89#define IC_CON_MM 0x0001
90
91/* i2c target address register definitions */
92#define TAR_ADDR 0x0050
93
94/* i2c slave address register definitions */
95#define IC_SLAVE_ADDR 0x0002
96
97/* i2c data buffer and command register definitions */
98#define IC_CMD 0x0100
Armando Visconti491739b2012-12-06 00:04:16 +000099#define IC_STOP 0x0200
Vipin KUMAR2403f8f2010-01-15 19:15:44 +0530100
101/* i2c interrupt status register definitions */
102#define IC_GEN_CALL 0x0800
103#define IC_START_DET 0x0400
104#define IC_STOP_DET 0x0200
105#define IC_ACTIVITY 0x0100
106#define IC_RX_DONE 0x0080
107#define IC_TX_ABRT 0x0040
108#define IC_RD_REQ 0x0020
109#define IC_TX_EMPTY 0x0010
110#define IC_TX_OVER 0x0008
111#define IC_RX_FULL 0x0004
112#define IC_RX_OVER 0x0002
113#define IC_RX_UNDER 0x0001
114
115/* fifo threshold register definitions */
116#define IC_TL0 0x00
117#define IC_TL1 0x01
118#define IC_TL2 0x02
119#define IC_TL3 0x03
120#define IC_TL4 0x04
121#define IC_TL5 0x05
122#define IC_TL6 0x06
123#define IC_TL7 0x07
124#define IC_RX_TL IC_TL0
125#define IC_TX_TL IC_TL0
126
127/* i2c enable register definitions */
128#define IC_ENABLE_0B 0x0001
129
130/* i2c status register definitions */
131#define IC_STATUS_SA 0x0040
132#define IC_STATUS_MA 0x0020
133#define IC_STATUS_RFF 0x0010
134#define IC_STATUS_RFNE 0x0008
135#define IC_STATUS_TFE 0x0004
136#define IC_STATUS_TFNF 0x0002
137#define IC_STATUS_ACT 0x0001
138
139/* Speed Selection */
140#define IC_SPEED_MODE_STANDARD 1
141#define IC_SPEED_MODE_FAST 2
142#define IC_SPEED_MODE_MAX 3
143
144#define I2C_MAX_SPEED 3400000
145#define I2C_FAST_SPEED 400000
146#define I2C_STANDARD_SPEED 100000
147
Simon Glass457df232019-12-06 21:41:40 -0700148/**
149 * struct dw_scl_sda_cfg - I2C timing configuration
150 *
151 * @has_max_speed: Support maximum speed (1Mbps)
152 * @ss_hcnt: Standard speed high time in ns
153 * @fs_hcnt: Fast speed high time in ns
154 * @ss_lcnt: Standard speed low time in ns
155 * @fs_lcnt: Fast speed low time in ns
156 * @sda_hold: SDA hold time
157 */
158struct dw_scl_sda_cfg {
159 bool has_max_speed;
160 u32 ss_hcnt;
161 u32 fs_hcnt;
162 u32 ss_lcnt;
163 u32 fs_lcnt;
164 u32 sda_hold;
165};
166
167struct dw_i2c {
168 struct i2c_regs *regs;
169 struct dw_scl_sda_cfg *scl_sda_cfg;
170 struct reset_ctl_bulk resets;
171#if CONFIG_IS_ENABLED(CLK)
172 struct clk clk;
173#endif
174};
175
176extern const struct dm_i2c_ops designware_i2c_ops;
177
178int designware_i2c_probe(struct udevice *bus);
179int designware_i2c_remove(struct udevice *dev);
180
Vipin KUMAR031ed2f2012-02-26 23:13:29 +0000181#endif /* __DW_I2C_H_ */