xref: /openbmc/u-boot/include/i2c.h (revision 06d01dbe000057e5df4af0f113242f0eba716340)
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);
54*06d01dbeSwdenk #ifdef CFG_I2C_INIT_BOARD
55*06d01dbeSwdenk void i2c_init_board(void);
56*06d01dbeSwdenk #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 
851f045217Swdenk #endif	/* _I2C_H_ */
86