Re: [U-Boot] [PATCH v3 09/12] dm: i2c: s3c24x0: adjust to dm-i2c api

2015-01-29 Thread Simon Glass
On 27 January 2015 at 08:38, Simon Glass s...@chromium.org wrote:
 On 27 January 2015 at 05:36, Przemyslaw Marczak p.marc...@samsung.com wrote:
 This commit adjusts the s3c24x0 driver to new i2c api
 based on driver-model. The driver supports standard
 and high-speed i2c as previous.

 Tested on Trats2, Odroid U3, Arndale, Odroid XU3

 Signed-off-by: Przemyslaw Marczak p.marc...@samsung.com
 Tested-by: Simon Glass s...@chromium.org
 Cc: Simon Glass s...@chromium.org
 Cc: Heiko Schocher h...@denx.de
 Cc: Minkyu Kang mk7.k...@samsung.com

 Retested on snow.

 Acked-by: Simon Glass s...@chromium.org

Applied to u-boot-dm, thanks!
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3 09/12] dm: i2c: s3c24x0: adjust to dm-i2c api

2015-01-27 Thread Przemyslaw Marczak
This commit adjusts the s3c24x0 driver to new i2c api
based on driver-model. The driver supports standard
and high-speed i2c as previous.

Tested on Trats2, Odroid U3, Arndale, Odroid XU3

Signed-off-by: Przemyslaw Marczak p.marc...@samsung.com
Tested-by: Simon Glass s...@chromium.org
Cc: Simon Glass s...@chromium.org
Cc: Heiko Schocher h...@denx.de
Cc: Minkyu Kang mk7.k...@samsung.com

---
Changes v2:
- use consistent return values on errors
- decrease transaction status timeout, because the previous one was too big

Changes v3:
- change of timeout move to new commit
- use pinmux hs mode flag
- remove unused code
---
 drivers/i2c/s3c24x0_i2c.c | 237 +-
 1 file changed, 194 insertions(+), 43 deletions(-)

diff --git a/drivers/i2c/s3c24x0_i2c.c b/drivers/i2c/s3c24x0_i2c.c
index 3129c7f..b4ee33f 100644
--- a/drivers/i2c/s3c24x0_i2c.c
+++ b/drivers/i2c/s3c24x0_i2c.c
@@ -9,8 +9,9 @@
  * as they seem to have the same I2C controller inside.
  * The different address mapping is handled by the s3c24xx.h files below.
  */
-
 #include common.h
+#include errno.h
+#include dm.h
 #include fdtdec.h
 #if (defined CONFIG_EXYNOS4 || defined CONFIG_EXYNOS5)
 #include asm/arch/clk.h
@@ -121,13 +122,23 @@
 #define CONFIG_MAX_I2C_NUM 1
 #endif
 
+DECLARE_GLOBAL_DATA_PTR;
+
 /*
  * For SPL boot some boards need i2c before SDRAM is initialised so force
  * variables to live in SRAM
  */
+#ifdef CONFIG_SYS_I2C
 static struct s3c24x0_i2c_bus i2c_bus[CONFIG_MAX_I2C_NUM]
__attribute__((section(.data)));
+#endif
+
+enum exynos_i2c_type {
+   EXYNOS_I2C_STD,
+   EXYNOS_I2C_HS,
+};
 
+#ifdef CONFIG_SYS_I2C
 /**
  * Get a pointer to the given bus index
  *
@@ -147,6 +158,7 @@ static struct s3c24x0_i2c_bus *get_bus(unsigned int bus_idx)
debug(Undefined bus: %d\n, bus_idx);
return NULL;
 }
+#endif
 
 #if !(defined CONFIG_EXYNOS4 || defined CONFIG_EXYNOS5)
 static int GetI2CSDA(void)
@@ -251,6 +263,7 @@ static void ReadWriteByte(struct s3c24x0_i2c *i2c)
writel(readl(i2c-iiccon)  ~I2CCON_IRPND, i2c-iiccon);
 }
 
+#ifdef CONFIG_SYS_I2C
 static struct s3c24x0_i2c *get_base_i2c(int bus)
 {
 #ifdef CONFIG_EXYNOS4
@@ -267,6 +280,7 @@ static struct s3c24x0_i2c *get_base_i2c(int bus)
return s3c24x0_get_base_i2c();
 #endif
 }
+#endif
 
 static void i2c_ch_init(struct s3c24x0_i2c *i2c, int speed, int slaveadd)
 {
@@ -326,7 +340,7 @@ static int hsi2c_get_clk_details(struct s3c24x0_i2c_bus 
*i2c_bus)
return 0;
}
}
-   return -1;
+   return -EINVAL;
 }
 
 static void hsi2c_ch_init(struct s3c24x0_i2c_bus *i2c_bus)
@@ -398,18 +412,20 @@ static void exynos5_i2c_reset(struct s3c24x0_i2c_bus 
*i2c_bus)
hsi2c_ch_init(i2c_bus);
 }
 
+#ifdef CONFIG_SYS_I2C
 static void s3c24x0_i2c_init(struct i2c_adapter *adap, int speed, int slaveadd)
 {
struct s3c24x0_i2c *i2c;
struct s3c24x0_i2c_bus *bus;
-
 #if !(defined CONFIG_EXYNOS4 || defined CONFIG_EXYNOS5)
struct s3c24x0_gpio *gpio = s3c24x0_get_base_gpio();
 #endif
ulong start_time = get_timer(0);
 
-   /* By default i2c channel 0 is the current bus */
i2c = get_base_i2c(adap-hwadapnr);
+   bus = i2c_bus[adap-hwadapnr];
+   if (!bus)
+   return;
 
/*
 * In case the previous transfer is still going, wait to give it a
@@ -470,12 +486,13 @@ static void s3c24x0_i2c_init(struct i2c_adapter *adap, 
int speed, int slaveadd)
 #endif
}
 #endif /* #if !(defined CONFIG_EXYNOS4 || defined CONFIG_EXYNOS5) */
+
i2c_ch_init(i2c, speed, slaveadd);
 
-   bus = i2c_bus[adap-hwadapnr];
bus-active = true;
bus-regs = i2c;
 }
+#endif /* CONFIG_SYS_I2C */
 
 /*
  * Poll the appropriate bit of the fifo status register until the interface is
@@ -698,20 +715,27 @@ static int hsi2c_read(struct exynos5_hsi2c *i2c,
return rv;
 }
 
+#ifdef CONFIG_SYS_I2C
 static unsigned int s3c24x0_i2c_set_bus_speed(struct i2c_adapter *adap,
- unsigned int speed)
+ unsigned int speed)
+#else
+static int s3c24x0_i2c_set_bus_speed(struct udevice *dev, unsigned int speed)
+#endif
 {
struct s3c24x0_i2c_bus *i2c_bus;
 
+#ifdef CONFIG_SYS_I2C
i2c_bus = get_bus(adap-hwadapnr);
if (!i2c_bus)
-   return -1;
-
+   return -EFAULT;
+#else
+   i2c_bus = dev_get_priv(dev);
+#endif
i2c_bus-clock_frequency = speed;
 
if (i2c_bus-is_highspeed) {
if (hsi2c_get_clk_details(i2c_bus))
-   return -1;
+   return -EFAULT;
hsi2c_ch_init(i2c_bus);
} else {
i2c_ch_init(i2c_bus-regs, i2c_bus-clock_frequency,
@@ -721,17 +745,6 @@ static unsigned int s3c24x0_i2c_set_bus_speed(struct 
i2c_adapter *adap,
return 0;
 }
 
-#ifdef CONFIG_EXYNOS5
-static 

Re: [U-Boot] [PATCH v3 09/12] dm: i2c: s3c24x0: adjust to dm-i2c api

2015-01-27 Thread Simon Glass
On 27 January 2015 at 05:36, Przemyslaw Marczak p.marc...@samsung.com wrote:
 This commit adjusts the s3c24x0 driver to new i2c api
 based on driver-model. The driver supports standard
 and high-speed i2c as previous.

 Tested on Trats2, Odroid U3, Arndale, Odroid XU3

 Signed-off-by: Przemyslaw Marczak p.marc...@samsung.com
 Tested-by: Simon Glass s...@chromium.org
 Cc: Simon Glass s...@chromium.org
 Cc: Heiko Schocher h...@denx.de
 Cc: Minkyu Kang mk7.k...@samsung.com

Retested on snow.

Acked-by: Simon Glass s...@chromium.org
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot