xref: /openbmc/u-boot/include/i2c.h (revision bb99ad6d8257bf828f150d40f507b30d80a4a7ae)
11f045217Swdenk /*
21f045217Swdenk  * (C) Copyright 2001
31f045217Swdenk  * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com.
41f045217Swdenk  *
51f045217Swdenk  * See file CREDITS for list of people who contributed to this
61f045217Swdenk  * project.
71f045217Swdenk  *
81f045217Swdenk  * This program is free software; you can redistribute it and/or
91f045217Swdenk  * modify it under the terms of the GNU General Public License as
101f045217Swdenk  * published by the Free Software Foundation; either version 2 of
111f045217Swdenk  * the License, or (at your option) any later version.
121f045217Swdenk  *
131f045217Swdenk  * This program is distributed in the hope that it will be useful,
141f045217Swdenk  * but WITHOUT ANY WARRANTY; without even the implied warranty of
151f045217Swdenk  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
161f045217Swdenk  * GNU General Public License for more details.
171f045217Swdenk  *
181f045217Swdenk  * You should have received a copy of the GNU General Public License
191f045217Swdenk  * along with this program; if not, write to the Free Software
201f045217Swdenk  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
211f045217Swdenk  * MA 02111-1307 USA
221f045217Swdenk  *
231f045217Swdenk  * The original I2C interface was
241f045217Swdenk  *   (C) 2000 by Paolo Scaffardi (arsenio@tin.it)
251f045217Swdenk  *   AIRVENT SAM s.p.a - RIMINI(ITALY)
261f045217Swdenk  * but has been changed substantially.
271f045217Swdenk  */
281f045217Swdenk 
291f045217Swdenk #ifndef _I2C_H_
301f045217Swdenk #define _I2C_H_
311f045217Swdenk 
321f045217Swdenk /*
331f045217Swdenk  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
341f045217Swdenk  *
351f045217Swdenk  * The implementation MUST NOT use static or global variables if the
361f045217Swdenk  * I2C routines are used to read SDRAM configuration information
371f045217Swdenk  * because this is done before the memories are initialized. Limited
381f045217Swdenk  * use of stack-based variables are OK (the initial stack size is
391f045217Swdenk  * limited).
401f045217Swdenk  *
411f045217Swdenk  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
421f045217Swdenk  */
431f045217Swdenk 
441f045217Swdenk /*
451f045217Swdenk  * Configuration items.
461f045217Swdenk  */
471f045217Swdenk #define I2C_RXTX_LEN	128	/* maximum tx/rx buffer length */
481f045217Swdenk 
491f045217Swdenk /*
501f045217Swdenk  * Initialization, must be called once on start up, may be called
511f045217Swdenk  * repeatedly to change the speed and slave addresses.
521f045217Swdenk  */
531f045217Swdenk void i2c_init(int speed, int slaveaddr);
5406d01dbeSwdenk #ifdef CFG_I2C_INIT_BOARD
5506d01dbeSwdenk void i2c_init_board(void);
5606d01dbeSwdenk #endif
571f045217Swdenk 
581f045217Swdenk /*
591f045217Swdenk  * Probe the given I2C chip address.  Returns 0 if a chip responded,
601f045217Swdenk  * not 0 on failure.
611f045217Swdenk  */
621f045217Swdenk int i2c_probe(uchar chip);
631f045217Swdenk 
641f045217Swdenk /*
651f045217Swdenk  * Read/Write interface:
661f045217Swdenk  *   chip:    I2C chip address, range 0..127
671f045217Swdenk  *   addr:    Memory (register) address within the chip
681f045217Swdenk  *   alen:    Number of bytes to use for addr (typically 1, 2 for larger
691f045217Swdenk  *              memories, 0 for register type devices with only one
701f045217Swdenk  *              register)
711f045217Swdenk  *   buffer:  Where to read/write the data
721f045217Swdenk  *   len:     How many bytes to read/write
731f045217Swdenk  *
741f045217Swdenk  *   Returns: 0 on success, not 0 on failure
751f045217Swdenk  */
761f045217Swdenk int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len);
771f045217Swdenk int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len);
781f045217Swdenk 
791f045217Swdenk /*
801f045217Swdenk  * Utility routines to read/write registers.
811f045217Swdenk  */
821f045217Swdenk uchar i2c_reg_read (uchar chip, uchar reg);
831f045217Swdenk void  i2c_reg_write(uchar chip, uchar reg, uchar val);
841f045217Swdenk 
85*bb99ad6dSBen Warren /*
86*bb99ad6dSBen Warren  * Functions for setting the current I2C bus and its speed
87*bb99ad6dSBen Warren  */
88*bb99ad6dSBen Warren 
89*bb99ad6dSBen Warren /*
90*bb99ad6dSBen Warren  * i2c_set_bus_num:
91*bb99ad6dSBen Warren  *
92*bb99ad6dSBen Warren  *  Change the active I2C bus.  Subsequent read/write calls will
93*bb99ad6dSBen Warren  *  go to this one.
94*bb99ad6dSBen Warren  *
95*bb99ad6dSBen Warren  * 	bus - bus index, zero based
96*bb99ad6dSBen Warren  *
97*bb99ad6dSBen Warren  * 	Returns: 0 on success, not 0 on failure
98*bb99ad6dSBen Warren  *
99*bb99ad6dSBen Warren  */
100*bb99ad6dSBen Warren int		i2c_set_bus_num(uchar bus);
101*bb99ad6dSBen Warren 
102*bb99ad6dSBen Warren /*
103*bb99ad6dSBen Warren  * i2c_get_bus_num:
104*bb99ad6dSBen Warren  *
105*bb99ad6dSBen Warren  *  Returns index of currently active I2C bus.  Zero-based.
106*bb99ad6dSBen Warren  */
107*bb99ad6dSBen Warren 
108*bb99ad6dSBen Warren uchar	i2c_get_bus_num(void);
109*bb99ad6dSBen Warren 
110*bb99ad6dSBen Warren /*
111*bb99ad6dSBen Warren  * i2c_set_bus_speed:
112*bb99ad6dSBen Warren  *
113*bb99ad6dSBen Warren  *  Change the speed of the active I2C bus
114*bb99ad6dSBen Warren  *
115*bb99ad6dSBen Warren  * 	speed - bus speed in Hz
116*bb99ad6dSBen Warren  *
117*bb99ad6dSBen Warren  * 	Returns: 0 on success, not 0 on failure
118*bb99ad6dSBen Warren  *
119*bb99ad6dSBen Warren  */
120*bb99ad6dSBen Warren int		i2c_set_bus_speed(int);
121*bb99ad6dSBen Warren 
122*bb99ad6dSBen Warren /*
123*bb99ad6dSBen Warren  * i2c_get_bus_speed:
124*bb99ad6dSBen Warren  *
125*bb99ad6dSBen Warren  *  Returns speed of currently active I2C bus in Hz
126*bb99ad6dSBen Warren  */
127*bb99ad6dSBen Warren 
128*bb99ad6dSBen Warren int		i2c_get_bus_speed(void);
129*bb99ad6dSBen Warren 
1301f045217Swdenk #endif	/* _I2C_H_ */
131