1 /*
2  * Copyright 2016-2021 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 
9 #ifndef I2C_H
10 #define I2C_H
11 
12 #include <lib/mmio.h>
13 
14 #define I2C_TIMEOUT	1000	/* ms */
15 
16 #define I2C_FD_CONSERV	0x7e
17 #define I2C_CR_DIS	(1 << 7)
18 #define I2C_CR_EN	(0 << 7)
19 #define I2C_CR_MA	(1 << 5)
20 #define I2C_CR_TX	(1 << 4)
21 #define I2C_CR_TX_NAK	(1 << 3)
22 #define I2C_CR_RSTA	(1 << 2)
23 #define I2C_SR_BB	(1 << 5)
24 #define I2C_SR_IDLE	(0 << 5)
25 #define I2C_SR_AL	(1 << 4)
26 #define I2C_SR_IF	(1 << 1)
27 #define I2C_SR_RX_NAK	(1 << 0)
28 #define I2C_SR_RST	(I2C_SR_AL | I2C_SR_IF)
29 
30 #define I2C_GLITCH_EN	0x8
31 
32 #define i2c_in(a)	mmio_read_8((uintptr_t)(a))
33 #define i2c_out(a, v)	mmio_write_8((uintptr_t)(a), (v))
34 
35 struct ls_i2c {
36 	unsigned char ad;	/* I2c Bus Address Register */
37 	unsigned char fd;	/* I2c Bus Frequency Dividor Register */
38 	unsigned char cr;	/* I2c Bus Control Register */
39 	unsigned char sr;	/* I2c Bus Status Register */
40 	unsigned char dr;	/* I2C Bus Data I/O Register */
41 	unsigned char ic;	/* I2C Bus Interrupt Config Register */
42 	unsigned char dbg;	/* I2C Bus Debug Register */
43 };
44 
45 void i2c_init(uintptr_t nxp_i2c_addr);
46 int i2c_read(unsigned char chip, int addr, int alen,
47 	     unsigned char *buf, int len);
48 int i2c_write(unsigned char chip, int addr, int alen,
49 	      const unsigned char *buf, int len);
50 int i2c_probe_chip(unsigned char chip);
51 
52 #endif /* I2C_H */
53