Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2009 |
| 4 | * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com. |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
Vipin KUMAR | 3f64acb | 2012-02-26 23:13:29 +0000 | [diff] [blame] | 7 | #ifndef __DW_I2C_H_ |
| 8 | #define __DW_I2C_H_ |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 9 | |
Simon Glass | 9b7af64 | 2020-01-23 11:48:06 -0700 | [diff] [blame] | 10 | #include <clk.h> |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 11 | #include <reset.h> |
| 12 | |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 13 | struct i2c_regs { |
Stefan Roese | 5a3a3a4 | 2016-04-21 08:19:37 +0200 | [diff] [blame] | 14 | u32 ic_con; /* 0x00 */ |
| 15 | u32 ic_tar; /* 0x04 */ |
| 16 | u32 ic_sar; /* 0x08 */ |
| 17 | u32 ic_hs_maddr; /* 0x0c */ |
| 18 | u32 ic_cmd_data; /* 0x10 */ |
| 19 | u32 ic_ss_scl_hcnt; /* 0x14 */ |
| 20 | u32 ic_ss_scl_lcnt; /* 0x18 */ |
| 21 | u32 ic_fs_scl_hcnt; /* 0x1c */ |
| 22 | u32 ic_fs_scl_lcnt; /* 0x20 */ |
| 23 | u32 ic_hs_scl_hcnt; /* 0x24 */ |
| 24 | u32 ic_hs_scl_lcnt; /* 0x28 */ |
| 25 | u32 ic_intr_stat; /* 0x2c */ |
| 26 | u32 ic_intr_mask; /* 0x30 */ |
| 27 | u32 ic_raw_intr_stat; /* 0x34 */ |
| 28 | u32 ic_rx_tl; /* 0x38 */ |
| 29 | u32 ic_tx_tl; /* 0x3c */ |
| 30 | u32 ic_clr_intr; /* 0x40 */ |
| 31 | u32 ic_clr_rx_under; /* 0x44 */ |
| 32 | u32 ic_clr_rx_over; /* 0x48 */ |
| 33 | u32 ic_clr_tx_over; /* 0x4c */ |
| 34 | u32 ic_clr_rd_req; /* 0x50 */ |
| 35 | u32 ic_clr_tx_abrt; /* 0x54 */ |
| 36 | u32 ic_clr_rx_done; /* 0x58 */ |
| 37 | u32 ic_clr_activity; /* 0x5c */ |
| 38 | u32 ic_clr_stop_det; /* 0x60 */ |
| 39 | u32 ic_clr_start_det; /* 0x64 */ |
| 40 | u32 ic_clr_gen_call; /* 0x68 */ |
| 41 | u32 ic_enable; /* 0x6c */ |
| 42 | u32 ic_status; /* 0x70 */ |
| 43 | u32 ic_txflr; /* 0x74 */ |
| 44 | u32 ic_rxflr; /* 0x78 */ |
| 45 | u32 ic_sda_hold; /* 0x7c */ |
| 46 | u32 ic_tx_abrt_source; /* 0x80 */ |
Simon Glass | 4bca051 | 2020-01-23 11:48:04 -0700 | [diff] [blame] | 47 | u32 slv_data_nak_only; |
| 48 | u32 dma_cr; |
| 49 | u32 dma_tdlr; |
| 50 | u32 dma_rdlr; |
| 51 | u32 sda_setup; |
| 52 | u32 ack_general_call; |
Stefan Roese | 5a3a3a4 | 2016-04-21 08:19:37 +0200 | [diff] [blame] | 53 | u32 ic_enable_status; /* 0x9c */ |
Simon Glass | 4bca051 | 2020-01-23 11:48:04 -0700 | [diff] [blame] | 54 | u32 fs_spklen; |
| 55 | u32 hs_spklen; |
| 56 | u32 clr_restart_det; |
| 57 | u8 reserved[0xf4 - 0xac]; |
| 58 | u32 comp_param1; /* 0xf4 */ |
| 59 | u32 comp_version; |
| 60 | u32 comp_type; |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 61 | }; |
| 62 | |
Simon Glass | 333dadd | 2020-01-23 11:48:09 -0700 | [diff] [blame] | 63 | #define IC_CLK 166666666 |
| 64 | #define NANO_TO_KILO 1000000 |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 65 | |
| 66 | /* High and low times in different speed modes (in ns) */ |
| 67 | #define MIN_SS_SCL_HIGHTIME 4000 |
Armando Visconti | 891a1c4 | 2012-12-06 00:04:18 +0000 | [diff] [blame] | 68 | #define MIN_SS_SCL_LOWTIME 4700 |
| 69 | #define MIN_FS_SCL_HIGHTIME 600 |
| 70 | #define MIN_FS_SCL_LOWTIME 1300 |
Simon Glass | 4564922 | 2020-01-23 11:48:23 -0700 | [diff] [blame^] | 71 | #define MIN_FP_SCL_HIGHTIME 260 |
| 72 | #define MIN_FP_SCL_LOWTIME 500 |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 73 | #define MIN_HS_SCL_HIGHTIME 60 |
| 74 | #define MIN_HS_SCL_LOWTIME 160 |
| 75 | |
| 76 | /* Worst case timeout for 1 byte is kept as 2ms */ |
| 77 | #define I2C_BYTE_TO (CONFIG_SYS_HZ/500) |
| 78 | #define I2C_STOPDET_TO (CONFIG_SYS_HZ/500) |
| 79 | #define I2C_BYTE_TO_BB (I2C_BYTE_TO * 16) |
| 80 | |
| 81 | /* i2c control register definitions */ |
| 82 | #define IC_CON_SD 0x0040 |
| 83 | #define IC_CON_RE 0x0020 |
| 84 | #define IC_CON_10BITADDRMASTER 0x0010 |
| 85 | #define IC_CON_10BITADDR_SLAVE 0x0008 |
| 86 | #define IC_CON_SPD_MSK 0x0006 |
| 87 | #define IC_CON_SPD_SS 0x0002 |
| 88 | #define IC_CON_SPD_FS 0x0004 |
| 89 | #define IC_CON_SPD_HS 0x0006 |
| 90 | #define IC_CON_MM 0x0001 |
| 91 | |
| 92 | /* i2c target address register definitions */ |
| 93 | #define TAR_ADDR 0x0050 |
| 94 | |
| 95 | /* i2c slave address register definitions */ |
| 96 | #define IC_SLAVE_ADDR 0x0002 |
| 97 | |
| 98 | /* i2c data buffer and command register definitions */ |
| 99 | #define IC_CMD 0x0100 |
Armando Visconti | 6bc6ef7 | 2012-12-06 00:04:16 +0000 | [diff] [blame] | 100 | #define IC_STOP 0x0200 |
Vipin KUMAR | fc9589f | 2010-01-15 19:15:44 +0530 | [diff] [blame] | 101 | |
| 102 | /* i2c interrupt status register definitions */ |
| 103 | #define IC_GEN_CALL 0x0800 |
| 104 | #define IC_START_DET 0x0400 |
| 105 | #define IC_STOP_DET 0x0200 |
| 106 | #define IC_ACTIVITY 0x0100 |
| 107 | #define IC_RX_DONE 0x0080 |
| 108 | #define IC_TX_ABRT 0x0040 |
| 109 | #define IC_RD_REQ 0x0020 |
| 110 | #define IC_TX_EMPTY 0x0010 |
| 111 | #define IC_TX_OVER 0x0008 |
| 112 | #define IC_RX_FULL 0x0004 |
| 113 | #define IC_RX_OVER 0x0002 |
| 114 | #define IC_RX_UNDER 0x0001 |
| 115 | |
| 116 | /* fifo threshold register definitions */ |
| 117 | #define IC_TL0 0x00 |
| 118 | #define IC_TL1 0x01 |
| 119 | #define IC_TL2 0x02 |
| 120 | #define IC_TL3 0x03 |
| 121 | #define IC_TL4 0x04 |
| 122 | #define IC_TL5 0x05 |
| 123 | #define IC_TL6 0x06 |
| 124 | #define IC_TL7 0x07 |
| 125 | #define IC_RX_TL IC_TL0 |
| 126 | #define IC_TX_TL IC_TL0 |
| 127 | |
| 128 | /* i2c enable register definitions */ |
| 129 | #define IC_ENABLE_0B 0x0001 |
| 130 | |
| 131 | /* i2c status register definitions */ |
| 132 | #define IC_STATUS_SA 0x0040 |
| 133 | #define IC_STATUS_MA 0x0020 |
| 134 | #define IC_STATUS_RFF 0x0010 |
| 135 | #define IC_STATUS_RFNE 0x0008 |
| 136 | #define IC_STATUS_TFE 0x0004 |
| 137 | #define IC_STATUS_TFNF 0x0002 |
| 138 | #define IC_STATUS_ACT 0x0001 |
| 139 | |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 140 | /** |
| 141 | * struct dw_scl_sda_cfg - I2C timing configuration |
| 142 | * |
Simon Glass | f5ef101 | 2020-01-23 11:48:07 -0700 | [diff] [blame] | 143 | * @has_high_speed: Support high speed (3.4Mbps) |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 144 | * @ss_hcnt: Standard speed high time in ns |
| 145 | * @fs_hcnt: Fast speed high time in ns |
| 146 | * @ss_lcnt: Standard speed low time in ns |
| 147 | * @fs_lcnt: Fast speed low time in ns |
| 148 | * @sda_hold: SDA hold time |
| 149 | */ |
| 150 | struct dw_scl_sda_cfg { |
Simon Glass | f5ef101 | 2020-01-23 11:48:07 -0700 | [diff] [blame] | 151 | bool has_high_speed; |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 152 | u32 ss_hcnt; |
| 153 | u32 fs_hcnt; |
| 154 | u32 ss_lcnt; |
| 155 | u32 fs_lcnt; |
| 156 | u32 sda_hold; |
| 157 | }; |
| 158 | |
Simon Glass | 9e5d174 | 2020-01-23 11:48:11 -0700 | [diff] [blame] | 159 | /** |
| 160 | * struct dw_i2c - private information for the bus |
| 161 | * |
| 162 | * @regs: Registers pointer |
| 163 | * @scl_sda_cfg: Deprecated information for x86 (should move to device tree) |
| 164 | * @resets: Resets for the I2C controller |
| 165 | * @scl_rise_time_ns: Configured SCL rise time in nanoseconds |
| 166 | * @scl_fall_time_ns: Configured SCL fall time in nanoseconds |
| 167 | * @sda_hold_time_ns: Configured SDA hold time in nanoseconds |
Simon Glass | c38e2b3 | 2020-01-23 11:48:15 -0700 | [diff] [blame] | 168 | * @has_spk_cnt: true if the spike-count register is present |
Simon Glass | 9e5d174 | 2020-01-23 11:48:11 -0700 | [diff] [blame] | 169 | * @clk: Clock input to the I2C controller |
| 170 | */ |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 171 | struct dw_i2c { |
| 172 | struct i2c_regs *regs; |
| 173 | struct dw_scl_sda_cfg *scl_sda_cfg; |
| 174 | struct reset_ctl_bulk resets; |
Simon Glass | 9e5d174 | 2020-01-23 11:48:11 -0700 | [diff] [blame] | 175 | u32 scl_rise_time_ns; |
| 176 | u32 scl_fall_time_ns; |
| 177 | u32 sda_hold_time_ns; |
Simon Glass | c38e2b3 | 2020-01-23 11:48:15 -0700 | [diff] [blame] | 178 | bool has_spk_cnt; |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 179 | #if CONFIG_IS_ENABLED(CLK) |
| 180 | struct clk clk; |
| 181 | #endif |
| 182 | }; |
| 183 | |
| 184 | extern const struct dm_i2c_ops designware_i2c_ops; |
| 185 | |
| 186 | int designware_i2c_probe(struct udevice *bus); |
| 187 | int designware_i2c_remove(struct udevice *dev); |
Simon Glass | 9e5d174 | 2020-01-23 11:48:11 -0700 | [diff] [blame] | 188 | int designware_i2c_ofdata_to_platdata(struct udevice *bus); |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 189 | |
Vipin KUMAR | 3f64acb | 2012-02-26 23:13:29 +0000 | [diff] [blame] | 190 | #endif /* __DW_I2C_H_ */ |