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