blob: 8c3d84f62b6f660ff88b915dd00b50ace4aa7788 [file] [log] [blame]
Rayagonda Kokatanurd5dc36f2020-04-08 11:12:27 +05301/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright (C) 2018 Broadcom
4 *
5 */
6
7#ifndef __IPROC_I2C_H__
8#define __IPROC_I2C_H__
9
10/* Registers */
11#define CCB_SMB_CFG_REG 0x0
12
13#define CCB_SMB_CFG_RST_MASK 0x80000000
14#define CCB_SMB_CFG_RST_SHIFT 31
15
16#define CCB_SMB_CFG_SMBEN_MASK 0x40000000
17#define CCB_SMB_CFG_SMBEN_SHIFT 30
18
19#define CCB_SMB_CFG_BITBANGEN_MASK 0x20000000
20#define CCB_SMB_CFG_BITBANGEN_SHIFT 29
21
22#define CCB_SMB_CFG_EN_NIC_SMBADDR0_MASK 0x10000000
23#define CCB_SMB_CFG_EN_NIC_SMBADDR0_SHIFT 28
24
25#define CCB_SMB_CFG_PROMISCMODE_MASK 0x08000000
26#define CCB_SMB_CFG_PROMISCMODE_SHIFT 27
27
28#define CCB_SMB_CFG_TSTMPCNTEN_MASK 0x04000000
29#define CCB_SMB_CFG_TSTMPCNTEN_SHIFT 26
30
31#define CCB_SMB_CFG_MSTRRTRYCNT_MASK 0x000F0000
32#define CCB_SMB_CFG_MSTRRTRYCNT_SHIFT 16
33
34#define CCB_SMB_TIMGCFG_REG 0x4
35
36#define CCB_SMB_TIMGCFG_MODE400_MASK 0x80000000
37#define CCB_SMB_TIMGCFG_MODE400_SHIFT 31
38
39#define CCB_SMB_TIMGCFG_RNDSLVSTR_MASK 0x7F000000
40#define CCB_SMB_TIMGCFG_RNDSLVSTR_SHIFT 24
41
42#define CCB_SMB_TIMGCFG_PERSLVSTR_MASK 0x00FF0000
43#define CCB_SMB_TIMGCFG_PERSLVSTR_SHIFT 16
44
45#define CCB_SMB_TIMGCFG_IDLTIME_MASK 0x0000FF00
46#define CCB_SMB_TIMGCFG_IDLTIME_SHIFT 8
47
48#define CCB_SMB_ADDR_REG 0x8
49
50#define CCB_SMB_EN_NIC_SMBADDR3_MASK 0x80000000
51#define CCB_SMB_EN_NIC_SMBADDR3_SHIFT 31
52
53#define CCB_SMB_NIC_SMBADDR3_MASK 0x7F000000
54#define CCB_SMB_NIC_SMBADDR3_SHIFT 24
55
56#define CCB_SMB_EN_NIC_SMBADDR2_MASK 0x00800000
57#define CCB_SMB_EN_NIC_SMBADDR2_SHIFT 23
58
59#define CCB_SMB_NIC_SMBADDR2_MASK 0x007F0000
60#define CCB_SMB_NIC_SMBADDR2_SHIFT 16
61
62#define CCB_SMB_EN_NIC_SMBADDR1_MASK 0x00008000
63#define CCB_SMB_EN_NIC_SMBADDR1_SHIFT 15
64
65#define CCB_SMB_NIC_SMBADDR1_MASK 0x00007F00
66#define CCB_SMB_NIC_SMBADDR1_SHIFT 8
67
68#define CCB_SMB_EN_NIC_SMBADDR0_MASK 0x00000080
69#define CCB_SMB_EN_NIC_SMBADDR0_SHIFT 7
70
71#define CCB_SMB_NIC_SMBADDR0_MASK 0x0000007F
72#define CCB_SMB_NIC_SMBADDR0_SHIFT 0
73
74#define CCB_SMB_MSTRFIFOCTL_REG 0xC
75
76#define CCB_SMB_MSTRRXFIFOFLSH_MASK 0x80000000
77#define CCB_SMB_MSTRRXFIFOFLSH_SHIFT 31
78
79#define CCB_SMB_MSTRTXFIFOFLSH_MASK 0x40000000
80#define CCB_SMB_MSTRTXFIFOFLSH_SHIFT 30
81
82#define CCB_SMB_MSTRRXPKTCNT_MASK 0x007F0000
83#define CCB_SMB_MSTRRXPKTCNT_SHIFT 16
84
85#define CCB_SMB_MSTRRXFIFOTHR_MASK 0x00003F00
86#define CCB_SMB_MSTRRXFIFOTHR_SHIFT 8
87
88#define CCB_SMB_SLVFIFOCTL_REG 0x10
89
90#define CCB_SMB_SLVRXFIFOFLSH_MASK 0x80000000
91#define CCB_SMB_SLVRXFIFOFLSH_SHIFT 31
92
93#define CCB_SMB_SLVTXFIFOFLSH_MASK 0x40000000
94#define CCB_SMB_SLVTXFIFOFLSH_SHIFT 30
95
96#define CCB_SMB_SLVRXPKTCNT_MASK 0x007F0000
97#define CCB_SMB_SLVRXPKTCNT_SHIFT 16
98
99#define CCB_SMB_SLVRXFIFOTHR_MASK 0x00003F00
100#define CCB_SMB_SLVRXFIFOTHR_SHIFT 8
101
102#define CCB_SMB_BITBANGCTL_REG 0x14
103
104#define CCB_SMB_SMBCLKIN_MASK 0x80000000
105#define CCB_SMB_SMBCLKIN_SHIFT 31
106
107#define CCB_SMB_SMBCLKOUTEN_MASK 0x40000000
108#define CCB_SMB_SMBCLKOUTEN_SHIFT 30
109
110#define CCB_SMB_SMBDATAIN_MASK 0x20000000
111#define CCB_SMB_SMBDATAIN_SHIFT 29
112
113#define CCB_SMB_SMBDATAOUTEN_MASK 0x10000000
114#define CCB_SMB_SMBDATAOUTEN_SHIFT 28
115
116#define CCB_SMB_MSTRCMD_REG 0x30
117
118#define CCB_SMB_MSTRSTARTBUSYCMD_MASK 0x80000000
119#define CCB_SMB_MSTRSTARTBUSYCMD_SHIFT 31
120
121#define CCB_SMB_MSTRABORT_MASK 0x40000000
122#define CCB_SMB_MSTRABORT_SHIFT 30
123
124#define CCB_SMB_MSTRSTS_MASK 0x0E000000
125#define CCB_SMB_MSTRSTS_SHIFT 25
126
127#define CCB_SMB_MSTRSMBUSPROTO_MASK 0x00001E00
128#define CCB_SMB_MSTRSMBUSPROTO_SHIFT 9
129
130#define CCB_SMB_MSTRPEC_MASK 0x00000100
131#define CCB_SMB_MSTRPEC_SHIFT 8
132
133#define CCB_SMB_MSTRRDBYTECNT_MASK 0x000000FF
134#define CCB_SMB_MSTRRDBYTECNT_SHIFT 0
135
136#define CCB_SMB_SLVCMD_REG 0x34
137
138#define CCB_SMB_SLVSTARTBUSYCMD_MASK 0x80000000
139#define CCB_SMB_SLVSTARTBUSYCMD_SHIFT 31
140
141#define CCB_SMB_SLVABORT_MASK 0x40000000
142#define CCB_SMB_SLVABORT_SHIFT 30
143
144#define CCB_SMB_SLVSTS_MASK 0x03800000
145#define CCB_SMB_SLVSTS_SHIFT 23
146
147#define CCB_SMB_SLVPEC_MASK 0x00000100
148#define CCB_SMB_SLVPEC_SHIFT 8
149
150#define CCB_SMB_EVTEN_REG 0x38
151
152#define CCB_SMB_MSTRRXFIFOFULLEN_MASK 0x80000000
153#define CCB_SMB_MSTRRXFIFOFULLEN_SHIFT 31
154
155#define CCB_SMB_MSTRRXFIFOTHRHITEN_MASK 0x40000000
156#define CCB_SMB_MSTRRXFIFOTHRHITEN_SHIFT 30
157
158#define CCB_SMB_MSTRRXEVTEN_MASK 0x20000000
159#define CCB_SMB_MSTRRXEVTEN_SHIFT 29
160
161#define CCB_SMB_MSTRSTARTBUSYEN_MASK 0x10000000
162#define CCB_SMB_MSTRSTARTBUSYEN_SHIFT 28
163
164#define CCB_SMB_MSTRTXUNDEN_MASK 0x08000000
165#define CCB_SMB_MSTRTXUNDEN_SHIFT 27
166
167#define CCB_SMB_SLVRXFIFOFULLEN_MASK 0x04000000
168#define CCB_SMB_SLVRXFIFOFULLEN_SHIFT 26
169
170#define CCB_SMB_SLVRXFIFOTHRHITEN_MASK 0x02000000
171#define CCB_SMB_SLVRXFIFOTHRHITEN_SHIFT 25
172
173#define CCB_SMB_SLVRXEVTEN_MASK 0x01000000
174#define CCB_SMB_SLVRXEVTEN_SHIFT 24
175
176#define CCB_SMB_SLVSTARTBUSYEN_MASK 0x00800000
177#define CCB_SMB_SLVSTARTBUSYEN_SHIFT 23
178
179#define CCB_SMB_SLVTXUNDEN_MASK 0x00400000
180#define CCB_SMB_SLVTXUNDEN_SHIFT 22
181
182#define CCB_SMB_SLVRDEVTEN_MASK 0x00200000
183#define CCB_SMB_SLVRDEVTEN_SHIFT 21
184
185#define CCB_SMB_EVTSTS_REG 0x3C
186
187#define CCB_SMB_MSTRRXFIFOFULLSTS_MASK 0x80000000
188#define CCB_SMB_MSTRRXFIFOFULLSTS_SHIFT 31
189
190#define CCB_SMB_MSTRRXFIFOTHRHITSTS_MASK 0x40000000
191#define CCB_SMB_MSTRRXFIFOTHRHITSTS_SHIFT 30
192
193#define CCB_SMB_MSTRRXEVTSTS_MASK 0x20000000
194#define CCB_SMB_MSTRRXEVTSTS_SHIFT 29
195
196#define CCB_SMB_MSTRSTARTBUSYSTS_MASK 0x10000000
197#define CCB_SMB_MSTRSTARTBUSYSTS_SHIFT 28
198
199#define CCB_SMB_MSTRTXUNDSTS_MASK 0x08000000
200#define CCB_SMB_MSTRTXUNDSTS_SHIFT 27
201
202#define CCB_SMB_SLVRXFIFOFULLSTS_MASK 0x04000000
203#define CCB_SMB_SLVRXFIFOFULLSTS_SHIFT 26
204
205#define CCB_SMB_SLVRXFIFOTHRHITSTS_MASK 0x02000000
206#define CCB_SMB_SLVRXFIFOTHRHITSTS_SHIFT 25
207
208#define CCB_SMB_SLVRXEVTSTS_MASK 0x01000000
209#define CCB_SMB_SLVRXEVTSTS_SHIFT 24
210
211#define CCB_SMB_SLVSTARTBUSYSTS_MASK 0x00800000
212#define CCB_SMB_SLVSTARTBUSYSTS_SHIFT 23
213
214#define CCB_SMB_SLVTXUNDSTS_MASK 0x00400000
215#define CCB_SMB_SLVTXUNDSTS_SHIFT 22
216
217#define CCB_SMB_SLVRDEVTSTS_MASK 0x00200000
218#define CCB_SMB_SLVRDEVTSTS_SHIFT 21
219
220#define CCB_SMB_MSTRDATAWR_REG 0x40
221
222#define CCB_SMB_MSTRWRSTS_MASK 0x80000000
223#define CCB_SMB_MSTRWRSTS_SHIFT 31
224
225#define CCB_SMB_MSTRWRDATA_MASK 0x000000FF
226#define CCB_SMB_MSTRWRDATA_SHIFT 0
227
228#define CCB_SMB_MSTRDATARD_REG 0x44
229
230#define CCB_SMB_MSTRRDSTS_MASK 0xC0000000
231#define CCB_SMB_MSTRRDSTS_SHIFT 30
232
233#define CCB_SMB_MSTRRDPECERR_MASK 0x20000000
234#define CCB_SMB_MSTRRDPECERR_SHIFT 29
235
236#define CCB_SMB_MSTRRDDATA_MASK 0x000000FF
237#define CCB_SMB_MSTRRDDATA_SHIFT 0
238
239#define CCB_SMB_SLVDATAWR_REG 0x48
240
241#define CCB_SMB_SLVWRSTS_MASK 0x80000000
242#define CCB_SMB_SLVWRSTS_SHIFT 31
243
244#define CCB_SMB_SLVWRDATA_MASK 0x000000FF
245#define CCB_SMB_SLVWRDATA_SHIFT 0
246
247#define CCB_SMB_SLVDATARD_REG 0x4C
248
249#define CCB_SMB_SLVRDSTS_MASK 0xC0000000
250#define CCB_SMB_SLVRDSTS_SHIFT 30
251
252#define CCB_SMB_SLVRDERRSTS_MASK 0x30000000
253#define CCB_SMB_SLVRDERRSTS_SHIFT 28
254
255#define CCB_SMB_SLVRDDATA_MASK 0x000000FF
256#define CCB_SMB_SLVRDDATA_SHIFT 0
257
258/* --Registers-- */
259
260/* Transaction error codes defined in Master command register (0x30) */
261#define MSTR_STS_XACT_SUCCESS 0
262#define MSTR_STS_LOST_ARB 1
263#define MSTR_STS_NACK_FIRST_BYTE 2
264
265/* NACK on a byte other than
266 * the first byte
267 */
268#define MSTR_STS_NACK_NON_FIRST_BYTE 3
269
270#define MSTR_STS_TTIMEOUT_EXCEEDED 4
271#define MSTR_STS_TX_TLOW_MEXT_EXCEEDED 5
272#define MSTR_STS_RX_TLOW_MEXT_EXCEEDED 6
273
274/* SMBUS protocol values defined in register 0x30 */
275#define SMBUS_PROT_QUICK_CMD 0
276#define SMBUS_PROT_SEND_BYTE 1
277#define SMBUS_PROT_RECV_BYTE 2
278#define SMBUS_PROT_WR_BYTE 3
279#define SMBUS_PROT_RD_BYTE 4
280#define SMBUS_PROT_WR_WORD 5
281#define SMBUS_PROT_RD_WORD 6
282#define SMBUS_PROT_BLK_WR 7
283#define SMBUS_PROT_BLK_RD 8
284#define SMBUS_PROT_PROC_CALL 9
285#define SMBUS_PROT_BLK_WR_BLK_RD_PROC_CALL 10
286
287/* SMBUS Block speed mode */
288#define SMBUS_BLOCK_MODE_100 0
289#define SMBUS_BLOCK_MODE_400 1
290
291#define BUS_BUSY_COUNT 100000 /* Number can be changed later */
292#define IPROC_I2C_INVALID_ADDR 0xFF
293#define IPROC_SMB_MAX_RETRIES 35
294#define I2C_SMBUS_BLOCK_MAX 32
295#define GETREGFLDVAL(regval, mask, startbit) \
296 (((regval) & (mask)) >> (startbit))
297
298/* This enum will be used to notify the user of status of a data transfer
299 * request
300 */
301enum iproc_smb_error_code {
302 I2C_NO_ERR = 0,
303 I2C_TIMEOUT_ERR = 1,
304
305 /* Invalid parameter(s) passed to the driver */
306 I2C_INVALID_PARAM_ERR = 2,
307
308 /* The driver API was called before the present
309 * transfer was completed
310 */
311 I2C_OPER_IN_PROGRESS = 3,
312
313 /* Transfer aborted unexpectedly, for example a NACK
314 * received, before last byte was read/written
315 */
316 I2C_OPER_ABORT_ERR = 4,
317
318 /* Feature or function not supported
319 * (e.g., 10-bit addresses, or clock speeds
320 * other than 100KHz, 400KHz)
321 */
322 I2C_FUNC_NOT_SUPPORTED = 5,
323};
324
325/* Structure used to pass information to read/write functions. */
326struct iproc_xact_info {
327 unsigned char command;
328 unsigned char *data;
329 unsigned int size;
330 unsigned short flags; /* used for specifying PEC, 10-bit addresses */
331 unsigned char smb_proto; /* SMBus protocol */
332 unsigned int cmd_valid; /* true if command is valid else false */
333};
334
335#endif /* __IPROC_I2C_H__ */