xref: /openbmc/u-boot/drivers/i2c/omap24xx_i2c.h (revision 1a459660)
1938717ceSSteve Sakoman /*
2938717ceSSteve Sakoman  * (C) Copyright 2004-2010
3938717ceSSteve Sakoman  * Texas Instruments, <www.ti.com>
4938717ceSSteve Sakoman  *
5*1a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
6938717ceSSteve Sakoman  */
707cf5e20SNishanth Menon #ifndef _OMAP2PLUS_I2C_H_
807cf5e20SNishanth Menon #define _OMAP2PLUS_I2C_H_
9938717ceSSteve Sakoman 
10938717ceSSteve Sakoman /* I2C masks */
11938717ceSSteve Sakoman 
12938717ceSSteve Sakoman /* I2C Interrupt Enable Register (I2C_IE): */
13938717ceSSteve Sakoman #define I2C_IE_GC_IE	(1 << 5)
14938717ceSSteve Sakoman #define I2C_IE_XRDY_IE	(1 << 4) /* Transmit data ready interrupt enable */
15938717ceSSteve Sakoman #define I2C_IE_RRDY_IE	(1 << 3) /* Receive data ready interrupt enable */
16938717ceSSteve Sakoman #define I2C_IE_ARDY_IE	(1 << 2) /* Register access ready interrupt enable */
17938717ceSSteve Sakoman #define I2C_IE_NACK_IE	(1 << 1) /* No acknowledgment interrupt enable */
18938717ceSSteve Sakoman #define I2C_IE_AL_IE	(1 << 0) /* Arbitration lost interrupt enable */
19938717ceSSteve Sakoman 
20938717ceSSteve Sakoman /* I2C Status Register (I2C_STAT): */
21938717ceSSteve Sakoman 
22938717ceSSteve Sakoman #define I2C_STAT_SBD	(1 << 15) /* Single byte data */
23938717ceSSteve Sakoman #define I2C_STAT_BB	(1 << 12) /* Bus busy */
24938717ceSSteve Sakoman #define I2C_STAT_ROVR	(1 << 11) /* Receive overrun */
25938717ceSSteve Sakoman #define I2C_STAT_XUDF	(1 << 10) /* Transmit underflow */
26938717ceSSteve Sakoman #define I2C_STAT_AAS	(1 << 9)  /* Address as slave */
27938717ceSSteve Sakoman #define I2C_STAT_GC	(1 << 5)
28938717ceSSteve Sakoman #define I2C_STAT_XRDY	(1 << 4)  /* Transmit data ready */
29938717ceSSteve Sakoman #define I2C_STAT_RRDY	(1 << 3)  /* Receive data ready */
30938717ceSSteve Sakoman #define I2C_STAT_ARDY	(1 << 2)  /* Register access ready */
31938717ceSSteve Sakoman #define I2C_STAT_NACK	(1 << 1)  /* No acknowledgment interrupt enable */
32938717ceSSteve Sakoman #define I2C_STAT_AL	(1 << 0)  /* Arbitration lost interrupt enable */
33938717ceSSteve Sakoman 
34938717ceSSteve Sakoman /* I2C Interrupt Code Register (I2C_INTCODE): */
35938717ceSSteve Sakoman 
36938717ceSSteve Sakoman #define I2C_INTCODE_MASK	7
37938717ceSSteve Sakoman #define I2C_INTCODE_NONE	0
38938717ceSSteve Sakoman #define I2C_INTCODE_AL		1	/* Arbitration lost */
39938717ceSSteve Sakoman #define I2C_INTCODE_NAK		2	/* No acknowledgement/general call */
40938717ceSSteve Sakoman #define I2C_INTCODE_ARDY	3	/* Register access ready */
41938717ceSSteve Sakoman #define I2C_INTCODE_RRDY	4	/* Rcv data ready */
42938717ceSSteve Sakoman #define I2C_INTCODE_XRDY	5	/* Xmit data ready */
43938717ceSSteve Sakoman 
44938717ceSSteve Sakoman /* I2C Buffer Configuration Register (I2C_BUF): */
45938717ceSSteve Sakoman 
46938717ceSSteve Sakoman #define I2C_BUF_RDMA_EN		(1 << 15) /* Receive DMA channel enable */
47938717ceSSteve Sakoman #define I2C_BUF_XDMA_EN		(1 << 7)  /* Transmit DMA channel enable */
48938717ceSSteve Sakoman 
49938717ceSSteve Sakoman /* I2C Configuration Register (I2C_CON): */
50938717ceSSteve Sakoman 
51938717ceSSteve Sakoman #define I2C_CON_EN	(1 << 15)  /* I2C module enable */
52938717ceSSteve Sakoman #define I2C_CON_BE	(1 << 14)  /* Big endian mode */
53938717ceSSteve Sakoman #define I2C_CON_STB	(1 << 11)  /* Start byte mode (master mode only) */
54938717ceSSteve Sakoman #define I2C_CON_MST	(1 << 10)  /* Master/slave mode */
55938717ceSSteve Sakoman #define I2C_CON_TRX	(1 << 9)   /* Transmitter/receiver mode */
56938717ceSSteve Sakoman 				   /* (master mode only) */
57938717ceSSteve Sakoman #define I2C_CON_XA	(1 << 8)   /* Expand address */
58938717ceSSteve Sakoman #define I2C_CON_STP	(1 << 1)   /* Stop condition (master mode only) */
59938717ceSSteve Sakoman #define I2C_CON_STT	(1 << 0)   /* Start condition (master mode only) */
60938717ceSSteve Sakoman 
61938717ceSSteve Sakoman /* I2C System Test Register (I2C_SYSTEST): */
62938717ceSSteve Sakoman 
63938717ceSSteve Sakoman #define I2C_SYSTEST_ST_EN	(1 << 15) /* System test enable */
64938717ceSSteve Sakoman #define I2C_SYSTEST_FREE	(1 << 14) /* Free running mode, on brkpoint) */
65938717ceSSteve Sakoman #define I2C_SYSTEST_TMODE_MASK	(3 << 12) /* Test mode select */
66938717ceSSteve Sakoman #define I2C_SYSTEST_TMODE_SHIFT	(12)	  /* Test mode select */
67938717ceSSteve Sakoman #define I2C_SYSTEST_SCL_I	(1 << 3)  /* SCL line sense input value */
68938717ceSSteve Sakoman #define I2C_SYSTEST_SCL_O	(1 << 2)  /* SCL line drive output value */
69938717ceSSteve Sakoman #define I2C_SYSTEST_SDA_I	(1 << 1)  /* SDA line sense input value */
70938717ceSSteve Sakoman #define I2C_SYSTEST_SDA_O	(1 << 0)  /* SDA line drive output value */
71938717ceSSteve Sakoman 
72d708395dSSteve Sakoman /* I2C System Status Register (I2C_SYSS): */
73d708395dSSteve Sakoman 
74d708395dSSteve Sakoman #define I2C_SYSS_RDONE          (1 << 0)  /* Internel reset monitoring */
75d708395dSSteve Sakoman 
76938717ceSSteve Sakoman #define I2C_SCLL_SCLL		0
77938717ceSSteve Sakoman #define I2C_SCLL_SCLL_M		0xFF
78938717ceSSteve Sakoman #define I2C_SCLL_HSSCLL		8
79938717ceSSteve Sakoman #define I2C_SCLH_HSSCLL_M	0xFF
80938717ceSSteve Sakoman #define I2C_SCLH_SCLH		0
81938717ceSSteve Sakoman #define I2C_SCLH_SCLH_M		0xFF
82938717ceSSteve Sakoman #define I2C_SCLH_HSSCLH		8
83938717ceSSteve Sakoman #define I2C_SCLH_HSSCLH_M	0xFF
84938717ceSSteve Sakoman 
85938717ceSSteve Sakoman #define OMAP_I2C_STANDARD	100000
86938717ceSSteve Sakoman #define OMAP_I2C_FAST_MODE	400000
87938717ceSSteve Sakoman #define OMAP_I2C_HIGH_SPEED	3400000
88938717ceSSteve Sakoman 
89938717ceSSteve Sakoman #define SYSTEM_CLOCK_12		12000000
90938717ceSSteve Sakoman #define SYSTEM_CLOCK_13		13000000
91938717ceSSteve Sakoman #define SYSTEM_CLOCK_192	19200000
92938717ceSSteve Sakoman #define SYSTEM_CLOCK_96		96000000
93938717ceSSteve Sakoman 
94938717ceSSteve Sakoman /* Use the reference value of 96MHz if not explicitly set by the board */
95938717ceSSteve Sakoman #ifndef I2C_IP_CLK
96938717ceSSteve Sakoman #define I2C_IP_CLK		SYSTEM_CLOCK_96
97938717ceSSteve Sakoman #endif
98938717ceSSteve Sakoman 
99938717ceSSteve Sakoman /*
100938717ceSSteve Sakoman  * The reference minimum clock for high speed is 19.2MHz.
101938717ceSSteve Sakoman  * The linux 2.6.30 kernel uses this value.
102938717ceSSteve Sakoman  * The reference minimum clock for fast mode is 9.6MHz
103938717ceSSteve Sakoman  * The reference minimum clock for standard mode is 4MHz
104938717ceSSteve Sakoman  * In TRM, the value of 12MHz is used.
105938717ceSSteve Sakoman  */
106938717ceSSteve Sakoman #ifndef I2C_INTERNAL_SAMPLING_CLK
107938717ceSSteve Sakoman #define I2C_INTERNAL_SAMPLING_CLK	19200000
108938717ceSSteve Sakoman #endif
109938717ceSSteve Sakoman 
110938717ceSSteve Sakoman /*
111938717ceSSteve Sakoman  * The equation for the low and high time is
112938717ceSSteve Sakoman  * tlow = scll + scll_trim = (sampling clock * tlow_duty) / speed
113938717ceSSteve Sakoman  * thigh = sclh + sclh_trim = (sampling clock * (1 - tlow_duty)) / speed
114938717ceSSteve Sakoman  *
115938717ceSSteve Sakoman  * If the duty cycle is 50%
116938717ceSSteve Sakoman  *
117938717ceSSteve Sakoman  * tlow = scll + scll_trim = sampling clock / (2 * speed)
118938717ceSSteve Sakoman  * thigh = sclh + sclh_trim = sampling clock / (2 * speed)
119938717ceSSteve Sakoman  *
120938717ceSSteve Sakoman  * In TRM
121938717ceSSteve Sakoman  * scll_trim = 7
122938717ceSSteve Sakoman  * sclh_trim = 5
123938717ceSSteve Sakoman  *
124938717ceSSteve Sakoman  * The linux 2.6.30 kernel uses
125938717ceSSteve Sakoman  * scll_trim = 6
126938717ceSSteve Sakoman  * sclh_trim = 6
127938717ceSSteve Sakoman  *
128938717ceSSteve Sakoman  * These are the trim values for standard and fast speed
129938717ceSSteve Sakoman  */
130938717ceSSteve Sakoman #ifndef I2C_FASTSPEED_SCLL_TRIM
131938717ceSSteve Sakoman #define I2C_FASTSPEED_SCLL_TRIM		6
132938717ceSSteve Sakoman #endif
133938717ceSSteve Sakoman #ifndef I2C_FASTSPEED_SCLH_TRIM
134938717ceSSteve Sakoman #define I2C_FASTSPEED_SCLH_TRIM		6
135938717ceSSteve Sakoman #endif
136938717ceSSteve Sakoman 
137938717ceSSteve Sakoman /* These are the trim values for high speed */
138938717ceSSteve Sakoman #ifndef I2C_HIGHSPEED_PHASE_ONE_SCLL_TRIM
139938717ceSSteve Sakoman #define I2C_HIGHSPEED_PHASE_ONE_SCLL_TRIM	I2C_FASTSPEED_SCLL_TRIM
140938717ceSSteve Sakoman #endif
141938717ceSSteve Sakoman #ifndef I2C_HIGHSPEED_PHASE_ONE_SCLH_TRIM
142938717ceSSteve Sakoman #define I2C_HIGHSPEED_PHASE_ONE_SCLH_TRIM	I2C_FASTSPEED_SCLH_TRIM
143938717ceSSteve Sakoman #endif
144938717ceSSteve Sakoman #ifndef I2C_HIGHSPEED_PHASE_TWO_SCLL_TRIM
145938717ceSSteve Sakoman #define I2C_HIGHSPEED_PHASE_TWO_SCLL_TRIM	I2C_FASTSPEED_SCLL_TRIM
146938717ceSSteve Sakoman #endif
147938717ceSSteve Sakoman #ifndef I2C_HIGHSPEED_PHASE_TWO_SCLH_TRIM
148938717ceSSteve Sakoman #define I2C_HIGHSPEED_PHASE_TWO_SCLH_TRIM	I2C_FASTSPEED_SCLH_TRIM
149938717ceSSteve Sakoman #endif
150938717ceSSteve Sakoman 
151938717ceSSteve Sakoman #define I2C_PSC_MAX		0x0f
152938717ceSSteve Sakoman #define I2C_PSC_MIN		0x00
153938717ceSSteve Sakoman 
154938717ceSSteve Sakoman #endif /* _OMAP24XX_I2C_H_ */
155