1 // SPDX-License-Identifier: GPL-2.0+
4 * Holger Brunck, Keymile GmbH Hannover, holger.brunck@keymile.com
10 #include <linux/ctype.h>
11 #include "../common/common.h"
13 static void i2c_write_start_seq(void)
15 struct fsl_i2c_base *base;
16 base = (struct fsl_i2c_base *)(CONFIG_SYS_IMMR +
17 CONFIG_SYS_I2C_OFFSET);
18 udelay(DELAY_ABORT_SEQ);
19 out_8(&base->cr, (I2C_CR_MEN | I2C_CR_MSTA));
20 udelay(DELAY_ABORT_SEQ);
21 out_8(&base->cr, (I2C_CR_MEN));
24 int i2c_make_abort(void)
26 struct fsl_i2c_base *base;
27 base = (struct fsl_i2c_base *)(CONFIG_SYS_IMMR +
28 CONFIG_SYS_I2C_OFFSET);
34 /* wait after each operation to finsh with a delay */
35 out_8(&base->cr, (I2C_CR_MSTA));
36 udelay(DELAY_ABORT_SEQ);
37 out_8(&base->cr, (I2C_CR_MEN | I2C_CR_MSTA));
38 udelay(DELAY_ABORT_SEQ);
40 udelay(DELAY_ABORT_SEQ);
41 last = in_8(&base->dr);
45 * do read until the last bit is 1, but stop if the full eeprom is
48 while (((last & 0x01) != 0x01) &&
49 (nbr_read < CONFIG_SYS_IVM_EEPROM_MAX_LEN)) {
50 udelay(DELAY_ABORT_SEQ);
51 last = in_8(&base->dr);
54 if ((last & 0x01) != 0x01)
56 if ((last != 0xff) || (nbr_read > 1))
57 printf("[INFO] i2c abort after %d bytes (0x%02x)\n",
59 udelay(DELAY_ABORT_SEQ);
60 out_8(&base->cr, (I2C_CR_MEN));
61 udelay(DELAY_ABORT_SEQ);
62 /* clear status reg */
65 for (i = 0; i < 5; i++)
66 i2c_write_start_seq();
68 printf("[ERROR] i2c abort failed after %d bytes (0x%02x)\n",