1 /*
2  * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef _HARDWARE_STRUCTS_I2C_H
8 #define _HARDWARE_STRUCTS_I2C_H
9 
10 #include "hardware/address_mapped.h"
11 #include "hardware/regs/i2c.h"
12 
13 typedef struct {
14     io_rw_32 con;
15     io_rw_32 tar;
16     io_rw_32 sar;
17     uint32_t _pad0;
18     io_rw_32 data_cmd;
19     io_rw_32 ss_scl_hcnt;
20     io_rw_32 ss_scl_lcnt;
21     io_rw_32 fs_scl_hcnt;
22     io_rw_32 fs_scl_lcnt;
23     uint32_t _pad1[2];
24     io_rw_32 intr_stat;
25     io_rw_32 intr_mask;
26     io_rw_32 raw_intr_stat;
27     io_rw_32 rx_tl;
28     io_rw_32 tx_tl;
29     io_rw_32 clr_intr;
30     io_rw_32 clr_rx_under;
31     io_rw_32 clr_rx_over;
32     io_rw_32 clr_tx_over;
33     io_rw_32 clr_rd_req;
34     io_rw_32 clr_tx_abrt;
35     io_rw_32 clr_rx_done;
36     io_rw_32 clr_activity;
37     io_rw_32 clr_stop_det;
38     io_rw_32 clr_start_det;
39     io_rw_32 clr_gen_call;
40     io_rw_32 enable;
41     io_rw_32 status;
42     io_rw_32 txflr;
43     io_rw_32 rxflr;
44     io_rw_32 sda_hold;
45     io_rw_32 tx_abrt_source;
46     io_rw_32 slv_data_nack_only;
47     io_rw_32 dma_cr;
48     io_rw_32 dma_tdlr;
49     io_rw_32 dma_rdlr;
50     io_rw_32 sda_setup;
51     io_rw_32 ack_general_call;
52     io_rw_32 enable_status;
53     io_rw_32 fs_spklen;
54     uint32_t _pad2;
55     io_rw_32 clr_restart_det;
56 } i2c_hw_t;
57 
58 #define i2c0_hw ((i2c_hw_t *const)I2C0_BASE)
59 #define i2c1_hw ((i2c_hw_t *const)I2C1_BASE)
60 
61 // List of configuration constants for the Synopsys I2C hardware (you may see
62 // references to these in I2C register header; these are *fixed* values,
63 // set at hardware design time):
64 
65 // SLAVE_INTERFACE_TYPE .............. 0
66 // REG_TIMEOUT_WIDTH ................. 4
67 // REG_TIMEOUT_VALUE ................. 8
68 // IC_ULTRA_FAST_MODE ................ 0x0
69 // IC_UFM_TBUF_CNT_DEFAULT ........... 0x8
70 // IC_UFM_SCL_HIGH_COUNT ............. 0x0006
71 // IC_TX_TL .......................... 0x0
72 // IC_STOP_DET_IF_MASTER_ACTIVE ...... 0x0
73 // IC_SS_SCL_LOW_COUNT ............... 0x01d6
74 // IC_HAS_DMA ........................ 0x1
75 // IC_RX_FULL_GEN_NACK ............... 0x0
76 // IC_CLOCK_PERIOD ................... 100
77 // IC_EMPTYFIFO_HOLD_MASTER_EN ....... 1
78 // IC_SMBUS_ARP ...................... 0x0
79 // IC_FIRST_DATA_BYTE_STATUS ......... 0x1
80 // IC_INTR_IO ........................ 0x1
81 // IC_MASTER_MODE .................... 0x1
82 // IC_DEFAULT_ACK_GENERAL_CALL ....... 0x0
83 // IC_INTR_POL ....................... 0x1
84 // IC_OPTIONAL_SAR ................... 0x0
85 // IC_DEFAULT_TAR_SLAVE_ADDR ......... 0x055
86 // IC_DEFAULT_SLAVE_ADDR ............. 0x055
87 // IC_DEFAULT_HS_SPKLEN .............. 0x1
88 // IC_FS_SCL_HIGH_COUNT .............. 0x003c
89 // IC_HS_SCL_LOW_COUNT ............... 0x0010
90 // IC_DEVICE_ID_VALUE ................ 0x0
91 // IC_10BITADDR_MASTER ............... 0x0
92 // IC_CLK_FREQ_OPTIMIZATION .......... 0x0
93 // IC_DEFAULT_FS_SPKLEN .............. 0xf
94 // IC_ADD_ENCODED_PARAMS ............. 0x1
95 // IC_DEFAULT_SDA_HOLD ............... 0x000001
96 // IC_DEFAULT_SDA_SETUP .............. 0x64
97 // IC_AVOID_RX_FIFO_FLUSH_ON_TX_ABRT . 0x0
98 // SLVERR_RESP_EN .................... 0
99 // IC_RESTART_EN ..................... 0x1
100 // IC_TX_CMD_BLOCK ................... 0x1
101 // HC_REG_TIMEOUT_VALUE .............. 0
102 // IC_BUS_CLEAR_FEATURE .............. 0x1
103 // IC_CAP_LOADING .................... 100
104 // IC_HAS_ASYNC_FIFO ................. 0x0
105 // IC_FS_SCL_LOW_COUNT ............... 0x0082
106 // APB_DATA_WIDTH .................... 32
107 // IC_SDA_STUCK_TIMEOUT_DEFAULT ...... 0xffffffff
108 // IC_SLV_DATA_NACK_ONLY ............. 0x1
109 // IC_10BITADDR_SLAVE ................ 0x0
110 // IC_TX_BUFFER_DEPTH ................ 32
111 // IC_DEFAULT_UFM_SPKLEN ............. 0x1
112 // IC_CLK_TYPE ....................... 0x0
113 // IC_TX_CMD_BLOCK_DEFAULT ........... 0x0
114 // IC_SMBUS_UDID_MSB ................. 0x0
115 // IC_SMBUS_SUSPEND_ALERT ............ 0x0
116 // IC_HS_SCL_HIGH_COUNT .............. 0x0006
117 // IC_SLV_RESTART_DET_EN ............. 0x1
118 // IC_SMBUS .......................... 0x1
119 // IC_STAT_FOR_CLK_STRETCH ........... 0x1
120 // IC_MAX_SPEED_MODE ................. 0x2
121 // IC_OPTIONAL_SAR_DEFAULT ........... 0x0
122 // IC_PERSISTANT_SLV_ADDR_DEFAULT .... 0x0
123 // IC_USE_COUNTS ..................... 0x1
124 // IC_RX_BUFFER_DEPTH ................ 32
125 // IC_SCL_STUCK_TIMEOUT_DEFAULT ...... 0xffffffff
126 // IC_RX_FULL_HLD_BUS_EN ............. 0x1
127 // IC_SLAVE_DISABLE .................. 0x1
128 // IC_RX_TL .......................... 0x0
129 // IC_DEVICE_ID ...................... 0x0
130 // IC_HC_COUNT_VALUES ................ 0x0
131 // I2C_DYNAMIC_TAR_UPDATE ............ 1
132 // IC_SMBUS_CLK_LOW_MEXT_DEFAULT ..... 0xffffffff
133 // IC_SMBUS_CLK_LOW_SEXT_DEFAULT ..... 0xffffffff
134 // IC_HS_MASTER_CODE ................. 0x1
135 // IC_SMBUS_RST_IDLE_CNT_DEFAULT ..... 0xffff
136 // IC_UFM_SCL_LOW_COUNT .............. 0x0008
137 // IC_SMBUS_UDID_HC .................. 0x1
138 // IC_SMBUS_UDID_LSB_DEFAULT ......... 0xffffffff
139 // IC_SS_SCL_HIGH_COUNT .............. 0x0190
140 
141 #endif
142