3 * Holger Brunck, Keymile GmbH Hannover, holger.brunck@keymile.com
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #include <linux/ctype.h>
28 #include "../common/common.h"
30 static void i2c_write_start_seq(void)
33 dev = (struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C_OFFSET);
34 udelay(DELAY_ABORT_SEQ);
35 out_8(&dev->cr, (I2C_CR_MEN | I2C_CR_MSTA));
36 udelay(DELAY_ABORT_SEQ);
37 out_8(&dev->cr, (I2C_CR_MEN));
40 int i2c_make_abort(void)
43 dev = (struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C_OFFSET);
50 /* wait after each operation to finsh with a delay */
51 out_8(&dev->cr, (I2C_CR_MSTA));
52 udelay(DELAY_ABORT_SEQ);
53 out_8(&dev->cr, (I2C_CR_MEN | I2C_CR_MSTA));
54 udelay(DELAY_ABORT_SEQ);
55 dummy = in_8(&dev->dr);
56 udelay(DELAY_ABORT_SEQ);
57 last = in_8(&dev->dr);
61 * do read until the last bit is 1, but stop if the full eeprom is
64 while (((last & 0x01) != 0x01) &&
65 (nbr_read < CONFIG_SYS_IVM_EEPROM_MAX_LEN)) {
66 udelay(DELAY_ABORT_SEQ);
67 last = in_8(&dev->dr);
70 if ((last & 0x01) != 0x01)
72 if ((last != 0xff) || (nbr_read > 1))
73 printf("[INFO] i2c abort after %d bytes (0x%02x)\n",
75 udelay(DELAY_ABORT_SEQ);
76 out_8(&dev->cr, (I2C_CR_MEN));
77 udelay(DELAY_ABORT_SEQ);
78 /* clear status reg */
81 for (i = 0; i < 5; i++)
82 i2c_write_start_seq();
84 printf("[ERROR] i2c abort failed after %d bytes (0x%02x)\n",