xref: /openbmc/u-boot/include/i2c.h (revision 1f04521773dfcb9364b95efb3fb0870457a67ee8)
1*1f045217Swdenk /*
2*1f045217Swdenk  * (C) Copyright 2001
3*1f045217Swdenk  * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com.
4*1f045217Swdenk  *
5*1f045217Swdenk  * See file CREDITS for list of people who contributed to this
6*1f045217Swdenk  * project.
7*1f045217Swdenk  *
8*1f045217Swdenk  * This program is free software; you can redistribute it and/or
9*1f045217Swdenk  * modify it under the terms of the GNU General Public License as
10*1f045217Swdenk  * published by the Free Software Foundation; either version 2 of
11*1f045217Swdenk  * the License, or (at your option) any later version.
12*1f045217Swdenk  *
13*1f045217Swdenk  * This program is distributed in the hope that it will be useful,
14*1f045217Swdenk  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15*1f045217Swdenk  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*1f045217Swdenk  * GNU General Public License for more details.
17*1f045217Swdenk  *
18*1f045217Swdenk  * You should have received a copy of the GNU General Public License
19*1f045217Swdenk  * along with this program; if not, write to the Free Software
20*1f045217Swdenk  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21*1f045217Swdenk  * MA 02111-1307 USA
22*1f045217Swdenk  *
23*1f045217Swdenk  * The original I2C interface was
24*1f045217Swdenk  *   (C) 2000 by Paolo Scaffardi (arsenio@tin.it)
25*1f045217Swdenk  *   AIRVENT SAM s.p.a - RIMINI(ITALY)
26*1f045217Swdenk  * but has been changed substantially.
27*1f045217Swdenk  */
28*1f045217Swdenk 
29*1f045217Swdenk #ifndef _I2C_H_
30*1f045217Swdenk #define _I2C_H_
31*1f045217Swdenk 
32*1f045217Swdenk /*
33*1f045217Swdenk  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
34*1f045217Swdenk  *
35*1f045217Swdenk  * The implementation MUST NOT use static or global variables if the
36*1f045217Swdenk  * I2C routines are used to read SDRAM configuration information
37*1f045217Swdenk  * because this is done before the memories are initialized. Limited
38*1f045217Swdenk  * use of stack-based variables are OK (the initial stack size is
39*1f045217Swdenk  * limited).
40*1f045217Swdenk  *
41*1f045217Swdenk  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
42*1f045217Swdenk  */
43*1f045217Swdenk 
44*1f045217Swdenk /*
45*1f045217Swdenk  * Configuration items.
46*1f045217Swdenk  */
47*1f045217Swdenk #define I2C_RXTX_LEN	128	/* maximum tx/rx buffer length */
48*1f045217Swdenk 
49*1f045217Swdenk /*
50*1f045217Swdenk  * Initialization, must be called once on start up, may be called
51*1f045217Swdenk  * repeatedly to change the speed and slave addresses.
52*1f045217Swdenk  */
53*1f045217Swdenk void i2c_init(int speed, int slaveaddr);
54*1f045217Swdenk 
55*1f045217Swdenk /*
56*1f045217Swdenk  * Probe the given I2C chip address.  Returns 0 if a chip responded,
57*1f045217Swdenk  * not 0 on failure.
58*1f045217Swdenk  */
59*1f045217Swdenk int i2c_probe(uchar chip);
60*1f045217Swdenk 
61*1f045217Swdenk /*
62*1f045217Swdenk  * Read/Write interface:
63*1f045217Swdenk  *   chip:    I2C chip address, range 0..127
64*1f045217Swdenk  *   addr:    Memory (register) address within the chip
65*1f045217Swdenk  *   alen:    Number of bytes to use for addr (typically 1, 2 for larger
66*1f045217Swdenk  *              memories, 0 for register type devices with only one
67*1f045217Swdenk  *              register)
68*1f045217Swdenk  *   buffer:  Where to read/write the data
69*1f045217Swdenk  *   len:     How many bytes to read/write
70*1f045217Swdenk  *
71*1f045217Swdenk  *   Returns: 0 on success, not 0 on failure
72*1f045217Swdenk  */
73*1f045217Swdenk int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len);
74*1f045217Swdenk int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len);
75*1f045217Swdenk 
76*1f045217Swdenk /*
77*1f045217Swdenk  * Utility routines to read/write registers.
78*1f045217Swdenk  */
79*1f045217Swdenk uchar i2c_reg_read (uchar chip, uchar reg);
80*1f045217Swdenk void  i2c_reg_write(uchar chip, uchar reg, uchar val);
81*1f045217Swdenk 
82*1f045217Swdenk #endif	/* _I2C_H_ */
83