summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Vasut <marex@denx.de>2014-10-20 00:23:41 +0200
committerHeiko Schocher <hs@denx.de>2014-10-29 08:55:46 +0100
commit1fa96e80ecd5d0daeb7c76b9ceb447b442894177 (patch)
tree27da15270dcd225706cb79b1d033874226e5f50c
parent9536099d5083cb2c9657cf5c13e22a01567dbd2d (diff)
downloadblackbird-obmc-uboot-1fa96e80ecd5d0daeb7c76b9ceb447b442894177.tar.gz
blackbird-obmc-uboot-1fa96e80ecd5d0daeb7c76b9ceb447b442894177.zip
i2c: mxs: Add basic support for i2c framework
This patch just converts the function prototypes used throughout this driver to match those of the i2c framework. There is so far no functional change. This patch does not do the deeper integration of the framework bits. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Stefano Babic <sbabic@denx.de> Cc: Heiko Schocher <hs@denx.de>
-rw-r--r--drivers/i2c/Makefile2
-rw-r--r--drivers/i2c/mxs_i2c.c49
-rw-r--r--include/configs/mxs.h3
3 files changed, 32 insertions, 22 deletions
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index 416ea4f2c8..3191680ca2 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -8,7 +8,6 @@
obj-$(CONFIG_BFIN_TWI_I2C) += bfin-twi_i2c.o
obj-$(CONFIG_DW_I2C) += designware_i2c.o
obj-$(CONFIG_I2C_MV) += mv_i2c.o
-obj-$(CONFIG_I2C_MXS) += mxs_i2c.o
obj-$(CONFIG_PCA9564_I2C) += pca9564_i2c.o
obj-$(CONFIG_TSI108_I2C) += tsi108_i2c.o
obj-$(CONFIG_U8500_I2C) += u8500_i2c.o
@@ -21,6 +20,7 @@ obj-$(CONFIG_SYS_I2C_IHS) += ihs_i2c.o
obj-$(CONFIG_SYS_I2C_KONA) += kona_i2c.o
obj-$(CONFIG_SYS_I2C_MVTWSI) += mvtwsi.o
obj-$(CONFIG_SYS_I2C_MXC) += mxc_i2c.o
+obj-$(CONFIG_SYS_I2C_MXS) += mxs_i2c.o
obj-$(CONFIG_SYS_I2C_OMAP24XX) += omap24xx_i2c.o
obj-$(CONFIG_SYS_I2C_OMAP34XX) += omap24xx_i2c.o
obj-$(CONFIG_SYS_I2C_PPC4XX) += ppc4xx_i2c.o
diff --git a/drivers/i2c/mxs_i2c.c b/drivers/i2c/mxs_i2c.c
index cc313a6937..9594008a9d 100644
--- a/drivers/i2c/mxs_i2c.c
+++ b/drivers/i2c/mxs_i2c.c
@@ -29,11 +29,25 @@ static struct mxs_i2c_regs *mxs_i2c_get_base(struct i2c_adapter *adap)
return (struct mxs_i2c_regs *)MXS_I2C0_BASE;
}
+static unsigned int mxs_i2c_get_bus_speed(void)
+{
+ struct mxs_i2c_regs *i2c_regs = mxs_i2c_get_base(NULL);
+ uint32_t clk = mxc_get_clock(MXC_XTAL_CLK);
+ uint32_t timing0;
+
+ timing0 = readl(&i2c_regs->hw_i2c_timing0);
+ /*
+ * This is a reverse version of the algorithm presented in
+ * i2c_set_bus_speed(). Please refer there for details.
+ */
+ return clk / ((((timing0 >> 16) - 3) * 2) + 38);
+}
+
static void mxs_i2c_reset(void)
{
struct mxs_i2c_regs *i2c_regs = mxs_i2c_get_base(NULL);
int ret;
- int speed = i2c_get_bus_speed();
+ int speed = mxs_i2c_get_bus_speed();
ret = mxs_reset_block(&i2c_regs->hw_i2c_ctrl0_reg);
if (ret) {
@@ -165,7 +179,9 @@ err:
return 1;
}
-int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len)
+static int mxs_i2c_if_read(struct i2c_adapter *adap, uint8_t chip,
+ uint addr, int alen, uint8_t *buffer,
+ int len)
{
struct mxs_i2c_regs *i2c_regs = mxs_i2c_get_base(NULL);
uint32_t tmp = 0;
@@ -214,7 +230,9 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len)
return 0;
}
-int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
+static int mxs_i2c_if_write(struct i2c_adapter *adap, uint8_t chip,
+ uint addr, int alen, uint8_t *buffer,
+ int len)
{
int ret;
ret = mxs_i2c_write(chip, addr, alen, buffer, len, 1);
@@ -230,7 +248,7 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
return ret;
}
-int i2c_probe(uchar chip)
+static int mxs_i2c_probe(struct i2c_adapter *adap, uint8_t chip)
{
int ret;
ret = mxs_i2c_write(chip, 0, 1, NULL, 0, 1);
@@ -240,7 +258,7 @@ int i2c_probe(uchar chip)
return ret;
}
-int i2c_set_bus_speed(unsigned int speed)
+static uint mxs_i2c_set_bus_speed(struct i2c_adapter *adap, uint speed)
{
struct mxs_i2c_regs *i2c_regs = mxs_i2c_get_base(NULL);
/*
@@ -281,24 +299,15 @@ int i2c_set_bus_speed(unsigned int speed)
return 0;
}
-unsigned int i2c_get_bus_speed(void)
-{
- struct mxs_i2c_regs *i2c_regs = mxs_i2c_get_base(NULL);
- uint32_t clk = mxc_get_clock(MXC_XTAL_CLK);
- uint32_t timing0;
-
- timing0 = readl(&i2c_regs->hw_i2c_timing0);
- /*
- * This is a reverse version of the algorithm presented in
- * i2c_set_bus_speed(). Please refer there for details.
- */
- return clk / ((((timing0 >> 16) - 3) * 2) + 38);
-}
-
-void i2c_init(int speed, int slaveadd)
+static void mxs_i2c_init(struct i2c_adapter *adap, int speed, int slaveaddr)
{
mxs_i2c_reset();
i2c_set_bus_speed(speed);
return;
}
+
+U_BOOT_I2C_ADAP_COMPLETE(mxs0, mxs_i2c_init, mxs_i2c_probe,
+ mxs_i2c_if_read, mxs_i2c_if_write,
+ mxs_i2c_set_bus_speed,
+ CONFIG_SYS_I2C_SPEED, 0, 0)
diff --git a/include/configs/mxs.h b/include/configs/mxs.h
index eb96fc17f3..dea8227aeb 100644
--- a/include/configs/mxs.h
+++ b/include/configs/mxs.h
@@ -148,7 +148,8 @@
/* I2C */
#ifdef CONFIG_CMD_I2C
-#define CONFIG_I2C_MXS
+#define CONFIG_SYS_I2C
+#define CONFIG_SYS_I2C_MXS
#define CONFIG_HARD_I2C
#ifndef CONFIG_SYS_I2C_SPEED
#define CONFIG_SYS_I2C_SPEED 400000
OpenPOWER on IntegriCloud