/*
* LPC32xx I2C interface driver
*
- * (C) Copyright 2014 DENX Software Engineering GmbH
+ * (C) Copyright 2014-2015 DENX Software Engineering GmbH
* Written-by: Albert ARIBAUD - 3ADEV <albert.aribaud@3adev.fr>
*
* SPDX-License-Identifier: GPL-2.0+
static struct lpc32xx_i2c_registers *lpc32xx_i2c[] = {
(struct lpc32xx_i2c_registers *)I2C1_BASE,
- (struct lpc32xx_i2c_registers *)I2C2_BASE
+ (struct lpc32xx_i2c_registers *)I2C2_BASE,
+ (struct lpc32xx_i2c_registers *)(USB_BASE + 0x300)
};
/* Set I2C bus speed */
if (speed == 0)
return -EINVAL;
- half_period = (105000000 / speed) / 2;
-
- if ((half_period > 255) || (half_period < 0))
- return -EINVAL;
+ /* OTG I2C clock source and CLK registers are different */
+ if (adap->hwadapnr == 2) {
+ half_period = (get_periph_clk_rate() / speed) / 2;
+ if (half_period > 0xFF)
+ return -EINVAL;
+ } else {
+ half_period = (get_hclk_clk_rate() / speed) / 2;
+ if (half_period > 0x3FF)
+ return -EINVAL;
+ }
writel(half_period, &lpc32xx_i2c[adap->hwadapnr]->clk_hi);
writel(half_period, &lpc32xx_i2c[adap->hwadapnr]->clk_lo);
/* soft reset (auto-clears) */
writel(LPC32XX_I2C_SOFT_RESET, &i2c->ctrl);
- /* set HI and LO periods for about 350 kHz */
+ /* set HI and LO periods for half of the default speed */
lpc32xx_i2c_set_bus_speed(adap, requested_speed);
}
*(data++) = readl(&i2c->rx);
}
}
+ /* wait for end of transation */
+ while (!((stat = readl(&i2c->stat)) & LPC32XX_I2C_STAT_TDI))
+ ;
+ /* clear end-of-transaction flag */
+ writel(1, &i2c->stat);
}
- /* wait for end of transation */
- while (!((stat = readl(&i2c->stat)) & LPC32XX_I2C_STAT_TDI))
- ;
- /* clear end-of-transaction flag */
- writel(1, &i2c->stat);
/* success */
return 0;
}
if (alen | length)
/* Address slave in write mode */
writel((dev<<1) | LPC32XX_I2C_TX_START, &i2c->tx);
+ else
+ return 0;
/* write address bytes */
while (alen) {
/* wait for transmit fifo not full */
CONFIG_SYS_I2C_LPC32XX_SPEED,
CONFIG_SYS_I2C_LPC32XX_SLAVE,
1)
+
+U_BOOT_I2C_ADAP_COMPLETE(lpc32xx_2, _i2c_init, NULL,
+ lpc32xx_i2c_read, lpc32xx_i2c_write,
+ lpc32xx_i2c_set_bus_speed,
+ 100000,
+ 0,
+ 2)