summaryrefslogtreecommitdiff
path: root/drivers/i2c/iproc_i2c.h
blob: 8c3d84f62b6f660ff88b915dd00b50ace4aa7788 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/* SPDX-License-Identifier: GPL-2.0+ */
/*
 * Copyright (C) 2018 Broadcom
 *
 */

#ifndef __IPROC_I2C_H__
#define __IPROC_I2C_H__

/* Registers */
#define CCB_SMB_CFG_REG 0x0

#define CCB_SMB_CFG_RST_MASK                         0x80000000
#define CCB_SMB_CFG_RST_SHIFT                        31

#define CCB_SMB_CFG_SMBEN_MASK                       0x40000000
#define CCB_SMB_CFG_SMBEN_SHIFT                      30

#define CCB_SMB_CFG_BITBANGEN_MASK                   0x20000000
#define CCB_SMB_CFG_BITBANGEN_SHIFT                  29

#define CCB_SMB_CFG_EN_NIC_SMBADDR0_MASK             0x10000000
#define CCB_SMB_CFG_EN_NIC_SMBADDR0_SHIFT            28

#define CCB_SMB_CFG_PROMISCMODE_MASK                 0x08000000
#define CCB_SMB_CFG_PROMISCMODE_SHIFT                27

#define CCB_SMB_CFG_TSTMPCNTEN_MASK                  0x04000000
#define CCB_SMB_CFG_TSTMPCNTEN_SHIFT                 26

#define CCB_SMB_CFG_MSTRRTRYCNT_MASK                 0x000F0000
#define CCB_SMB_CFG_MSTRRTRYCNT_SHIFT                16

#define CCB_SMB_TIMGCFG_REG 0x4

#define CCB_SMB_TIMGCFG_MODE400_MASK                 0x80000000
#define CCB_SMB_TIMGCFG_MODE400_SHIFT                31

#define CCB_SMB_TIMGCFG_RNDSLVSTR_MASK               0x7F000000
#define CCB_SMB_TIMGCFG_RNDSLVSTR_SHIFT              24

#define CCB_SMB_TIMGCFG_PERSLVSTR_MASK               0x00FF0000
#define CCB_SMB_TIMGCFG_PERSLVSTR_SHIFT              16

#define CCB_SMB_TIMGCFG_IDLTIME_MASK                 0x0000FF00
#define CCB_SMB_TIMGCFG_IDLTIME_SHIFT                8

#define CCB_SMB_ADDR_REG 0x8

#define CCB_SMB_EN_NIC_SMBADDR3_MASK                 0x80000000
#define CCB_SMB_EN_NIC_SMBADDR3_SHIFT                31

#define CCB_SMB_NIC_SMBADDR3_MASK                    0x7F000000
#define CCB_SMB_NIC_SMBADDR3_SHIFT                   24

#define CCB_SMB_EN_NIC_SMBADDR2_MASK                 0x00800000
#define CCB_SMB_EN_NIC_SMBADDR2_SHIFT                23

#define CCB_SMB_NIC_SMBADDR2_MASK                    0x007F0000
#define CCB_SMB_NIC_SMBADDR2_SHIFT                   16

#define CCB_SMB_EN_NIC_SMBADDR1_MASK                 0x00008000
#define CCB_SMB_EN_NIC_SMBADDR1_SHIFT                15

#define CCB_SMB_NIC_SMBADDR1_MASK                    0x00007F00
#define CCB_SMB_NIC_SMBADDR1_SHIFT                   8

#define CCB_SMB_EN_NIC_SMBADDR0_MASK                 0x00000080
#define CCB_SMB_EN_NIC_SMBADDR0_SHIFT                7

#define CCB_SMB_NIC_SMBADDR0_MASK                    0x0000007F
#define CCB_SMB_NIC_SMBADDR0_SHIFT                   0

#define CCB_SMB_MSTRFIFOCTL_REG 0xC

#define CCB_SMB_MSTRRXFIFOFLSH_MASK                  0x80000000
#define CCB_SMB_MSTRRXFIFOFLSH_SHIFT                 31

#define CCB_SMB_MSTRTXFIFOFLSH_MASK                  0x40000000
#define CCB_SMB_MSTRTXFIFOFLSH_SHIFT                 30

#define CCB_SMB_MSTRRXPKTCNT_MASK                    0x007F0000
#define CCB_SMB_MSTRRXPKTCNT_SHIFT                   16

#define CCB_SMB_MSTRRXFIFOTHR_MASK                   0x00003F00
#define CCB_SMB_MSTRRXFIFOTHR_SHIFT                  8

#define CCB_SMB_SLVFIFOCTL_REG 0x10

#define CCB_SMB_SLVRXFIFOFLSH_MASK                   0x80000000
#define CCB_SMB_SLVRXFIFOFLSH_SHIFT                  31

#define CCB_SMB_SLVTXFIFOFLSH_MASK                   0x40000000
#define CCB_SMB_SLVTXFIFOFLSH_SHIFT                  30

#define CCB_SMB_SLVRXPKTCNT_MASK                     0x007F0000
#define CCB_SMB_SLVRXPKTCNT_SHIFT                    16

#define CCB_SMB_SLVRXFIFOTHR_MASK                    0x00003F00
#define CCB_SMB_SLVRXFIFOTHR_SHIFT                   8

#define CCB_SMB_BITBANGCTL_REG 0x14

#define CCB_SMB_SMBCLKIN_MASK                        0x80000000
#define CCB_SMB_SMBCLKIN_SHIFT                       31

#define CCB_SMB_SMBCLKOUTEN_MASK                     0x40000000
#define CCB_SMB_SMBCLKOUTEN_SHIFT                    30

#define CCB_SMB_SMBDATAIN_MASK                       0x20000000
#define CCB_SMB_SMBDATAIN_SHIFT                      29

#define CCB_SMB_SMBDATAOUTEN_MASK                    0x10000000
#define CCB_SMB_SMBDATAOUTEN_SHIFT                   28

#define CCB_SMB_MSTRCMD_REG 0x30

#define CCB_SMB_MSTRSTARTBUSYCMD_MASK                0x80000000
#define CCB_SMB_MSTRSTARTBUSYCMD_SHIFT               31

#define CCB_SMB_MSTRABORT_MASK                       0x40000000
#define CCB_SMB_MSTRABORT_SHIFT                      30

#define CCB_SMB_MSTRSTS_MASK                         0x0E000000
#define CCB_SMB_MSTRSTS_SHIFT                        25

#define CCB_SMB_MSTRSMBUSPROTO_MASK                  0x00001E00
#define CCB_SMB_MSTRSMBUSPROTO_SHIFT                 9

#define CCB_SMB_MSTRPEC_MASK                         0x00000100
#define CCB_SMB_MSTRPEC_SHIFT                        8

#define CCB_SMB_MSTRRDBYTECNT_MASK                   0x000000FF
#define CCB_SMB_MSTRRDBYTECNT_SHIFT                  0

#define CCB_SMB_SLVCMD_REG 0x34

#define CCB_SMB_SLVSTARTBUSYCMD_MASK                 0x80000000
#define CCB_SMB_SLVSTARTBUSYCMD_SHIFT                31

#define CCB_SMB_SLVABORT_MASK                        0x40000000
#define CCB_SMB_SLVABORT_SHIFT                       30

#define CCB_SMB_SLVSTS_MASK                          0x03800000
#define CCB_SMB_SLVSTS_SHIFT                         23

#define CCB_SMB_SLVPEC_MASK                          0x00000100
#define CCB_SMB_SLVPEC_SHIFT                         8

#define CCB_SMB_EVTEN_REG 0x38

#define CCB_SMB_MSTRRXFIFOFULLEN_MASK                0x80000000
#define CCB_SMB_MSTRRXFIFOFULLEN_SHIFT               31

#define CCB_SMB_MSTRRXFIFOTHRHITEN_MASK              0x40000000
#define CCB_SMB_MSTRRXFIFOTHRHITEN_SHIFT             30

#define CCB_SMB_MSTRRXEVTEN_MASK                     0x20000000
#define CCB_SMB_MSTRRXEVTEN_SHIFT                    29

#define CCB_SMB_MSTRSTARTBUSYEN_MASK                 0x10000000
#define CCB_SMB_MSTRSTARTBUSYEN_SHIFT                28

#define CCB_SMB_MSTRTXUNDEN_MASK                     0x08000000
#define CCB_SMB_MSTRTXUNDEN_SHIFT                    27

#define CCB_SMB_SLVRXFIFOFULLEN_MASK                 0x04000000
#define CCB_SMB_SLVRXFIFOFULLEN_SHIFT                26

#define CCB_SMB_SLVRXFIFOTHRHITEN_MASK               0x02000000
#define CCB_SMB_SLVRXFIFOTHRHITEN_SHIFT              25

#define CCB_SMB_SLVRXEVTEN_MASK                      0x01000000
#define CCB_SMB_SLVRXEVTEN_SHIFT                     24

#define CCB_SMB_SLVSTARTBUSYEN_MASK                  0x00800000
#define CCB_SMB_SLVSTARTBUSYEN_SHIFT                 23

#define CCB_SMB_SLVTXUNDEN_MASK                      0x00400000
#define CCB_SMB_SLVTXUNDEN_SHIFT                     22

#define CCB_SMB_SLVRDEVTEN_MASK                      0x00200000
#define CCB_SMB_SLVRDEVTEN_SHIFT                     21

#define CCB_SMB_EVTSTS_REG 0x3C

#define CCB_SMB_MSTRRXFIFOFULLSTS_MASK               0x80000000
#define CCB_SMB_MSTRRXFIFOFULLSTS_SHIFT              31

#define CCB_SMB_MSTRRXFIFOTHRHITSTS_MASK             0x40000000
#define CCB_SMB_MSTRRXFIFOTHRHITSTS_SHIFT            30

#define CCB_SMB_MSTRRXEVTSTS_MASK                    0x20000000
#define CCB_SMB_MSTRRXEVTSTS_SHIFT                   29

#define CCB_SMB_MSTRSTARTBUSYSTS_MASK                0x10000000
#define CCB_SMB_MSTRSTARTBUSYSTS_SHIFT               28

#define CCB_SMB_MSTRTXUNDSTS_MASK                    0x08000000
#define CCB_SMB_MSTRTXUNDSTS_SHIFT                   27

#define CCB_SMB_SLVRXFIFOFULLSTS_MASK                0x04000000
#define CCB_SMB_SLVRXFIFOFULLSTS_SHIFT               26

#define CCB_SMB_SLVRXFIFOTHRHITSTS_MASK              0x02000000
#define CCB_SMB_SLVRXFIFOTHRHITSTS_SHIFT             25

#define CCB_SMB_SLVRXEVTSTS_MASK                     0x01000000
#define CCB_SMB_SLVRXEVTSTS_SHIFT                    24

#define CCB_SMB_SLVSTARTBUSYSTS_MASK                 0x00800000
#define CCB_SMB_SLVSTARTBUSYSTS_SHIFT                23

#define CCB_SMB_SLVTXUNDSTS_MASK                     0x00400000
#define CCB_SMB_SLVTXUNDSTS_SHIFT                    22

#define CCB_SMB_SLVRDEVTSTS_MASK                     0x00200000
#define CCB_SMB_SLVRDEVTSTS_SHIFT                    21

#define CCB_SMB_MSTRDATAWR_REG 0x40

#define CCB_SMB_MSTRWRSTS_MASK                       0x80000000
#define CCB_SMB_MSTRWRSTS_SHIFT                      31

#define CCB_SMB_MSTRWRDATA_MASK                      0x000000FF
#define CCB_SMB_MSTRWRDATA_SHIFT                     0

#define CCB_SMB_MSTRDATARD_REG 0x44

#define CCB_SMB_MSTRRDSTS_MASK                       0xC0000000
#define CCB_SMB_MSTRRDSTS_SHIFT                      30

#define CCB_SMB_MSTRRDPECERR_MASK                    0x20000000
#define CCB_SMB_MSTRRDPECERR_SHIFT                   29

#define CCB_SMB_MSTRRDDATA_MASK                      0x000000FF
#define CCB_SMB_MSTRRDDATA_SHIFT                     0

#define CCB_SMB_SLVDATAWR_REG 0x48

#define CCB_SMB_SLVWRSTS_MASK                        0x80000000
#define CCB_SMB_SLVWRSTS_SHIFT                       31

#define CCB_SMB_SLVWRDATA_MASK                       0x000000FF
#define CCB_SMB_SLVWRDATA_SHIFT                      0

#define CCB_SMB_SLVDATARD_REG 0x4C

#define CCB_SMB_SLVRDSTS_MASK                        0xC0000000
#define CCB_SMB_SLVRDSTS_SHIFT                       30

#define CCB_SMB_SLVRDERRSTS_MASK                     0x30000000
#define CCB_SMB_SLVRDERRSTS_SHIFT                    28

#define CCB_SMB_SLVRDDATA_MASK                       0x000000FF
#define CCB_SMB_SLVRDDATA_SHIFT                      0

/* --Registers-- */

/* Transaction error codes defined in Master command register (0x30) */
#define MSTR_STS_XACT_SUCCESS          0
#define MSTR_STS_LOST_ARB              1
#define MSTR_STS_NACK_FIRST_BYTE       2

/* NACK on a byte other than
 * the first byte
 */
#define MSTR_STS_NACK_NON_FIRST_BYTE   3

#define MSTR_STS_TTIMEOUT_EXCEEDED     4
#define MSTR_STS_TX_TLOW_MEXT_EXCEEDED 5
#define MSTR_STS_RX_TLOW_MEXT_EXCEEDED 6

/* SMBUS protocol values defined in register 0x30 */
#define SMBUS_PROT_QUICK_CMD               0
#define SMBUS_PROT_SEND_BYTE               1
#define SMBUS_PROT_RECV_BYTE               2
#define SMBUS_PROT_WR_BYTE                 3
#define SMBUS_PROT_RD_BYTE                 4
#define SMBUS_PROT_WR_WORD                 5
#define SMBUS_PROT_RD_WORD                 6
#define SMBUS_PROT_BLK_WR                  7
#define SMBUS_PROT_BLK_RD                  8
#define SMBUS_PROT_PROC_CALL               9
#define SMBUS_PROT_BLK_WR_BLK_RD_PROC_CALL 10

/* SMBUS Block speed mode */
#define SMBUS_BLOCK_MODE_100		0
#define SMBUS_BLOCK_MODE_400		1

#define BUS_BUSY_COUNT         100000 /* Number can be changed later */
#define IPROC_I2C_INVALID_ADDR 0xFF
#define IPROC_SMB_MAX_RETRIES   35
#define I2C_SMBUS_BLOCK_MAX     32
#define GETREGFLDVAL(regval, mask, startbit) \
		    (((regval) & (mask)) >> (startbit))

/* This enum will be used to notify the user of status of a data transfer
 * request
 */
enum iproc_smb_error_code {
	I2C_NO_ERR = 0,
	I2C_TIMEOUT_ERR = 1,

	/* Invalid parameter(s) passed to the driver */
	I2C_INVALID_PARAM_ERR = 2,

	/* The driver API was called before the present
	 * transfer was completed
	 */
	I2C_OPER_IN_PROGRESS = 3,

	/* Transfer aborted unexpectedly, for example a NACK
	 * received, before last byte was read/written
	 */
	I2C_OPER_ABORT_ERR = 4,

	/* Feature or function not supported
	 * (e.g., 10-bit addresses, or clock speeds
	 * other than 100KHz, 400KHz)
	 */
	I2C_FUNC_NOT_SUPPORTED = 5,
};

/* Structure used to pass information to read/write functions. */
struct iproc_xact_info {
	unsigned char command;
	unsigned char *data;
	unsigned int size;
	unsigned short flags; /* used for specifying PEC, 10-bit addresses */
	unsigned char smb_proto; /* SMBus protocol */
	unsigned int cmd_valid; /* true if command is valid else false */
};

#endif /* __IPROC_I2C_H__ */