[U-Boot] [PATCH V3+] I2C: mxc_i2c rework

Heiko Schocher hs at denx.de
Thu Jul 14 11:04:39 CEST 2011


Hello Marek,

Marek Vasut wrote:
> Rewrite the mxc_i2c driver.
>  * This version is much closer to Linux implementation.
>  * Fixes IPG_PERCLK being incorrectly used as clock source
>  * Fixes behaviour of the driver on iMX51
>  * Clean up coding style a bit ;-)
> 
> Based on commit: e39428d53d080ad2615b772d7f99d2a70c2aaab2
> Date:   Mon Jun 21 09:27:05 2010 +0200
> i2c-imx: do not allow interruptions when waiting for I2C to complete
> 
> Signed-off-by: Marek Vasut <marek.vasut at gmail.com>
> ---
>  drivers/i2c/mxc_i2c.c |  424 +++++++++++++++++++++++++++++++++----------------
>  1 files changed, 290 insertions(+), 134 deletions(-)
> 
> V2: Convert register access to struct mxc_i2c_regs.
> 
> V3: Update licensing info
> 
> V3+: Add commit ID into commit message

checkpatch says:

ERROR: trailing statements should be on next line
#143: FILE: drivers/i2c/mxc_i2c.c:130:
+               for (i = 0; i2c_clk_div[i][0] < div; i++);

total: 1 errors, 0 warnings, 526 lines checked

Can you fix this?

> diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c
> index 89d1973..03e2448 100644
> --- a/drivers/i2c/mxc_i2c.c
> +++ b/drivers/i2c/mxc_i2c.c
[...]
> @@ -68,218 +78,364 @@
>  #endif
>  
>  #define I2C_MAX_TIMEOUT		10000
> -#define I2C_MAX_RETRIES		3
>  
> -static u16 div[] = { 30, 32, 36, 42, 48, 52, 60, 72, 80, 88, 104, 128, 144,
> -	             160, 192, 240, 288, 320, 384, 480, 576, 640, 768, 960,
> -	             1152, 1280, 1536, 1920, 2304, 2560, 3072, 3840};
> +static u16 i2c_clk_div[50][2] = {
> +	{ 22,	0x20 }, { 24,	0x21 }, { 26,	0x22 }, { 28,	0x23 },
> +	{ 30,	0x00 }, { 32,	0x24 }, { 36,	0x25 }, { 40,	0x26 },
> +	{ 42,	0x03 }, { 44,	0x27 }, { 48,	0x28 }, { 52,	0x05 },
> +	{ 56,	0x29 }, { 60,	0x06 }, { 64,	0x2A }, { 72,	0x2B },
> +	{ 80,	0x2C }, { 88,	0x09 }, { 96,	0x2D }, { 104,	0x0A },
> +	{ 112,	0x2E }, { 128,	0x2F }, { 144,	0x0C }, { 160,	0x30 },
> +	{ 192,	0x31 }, { 224,	0x32 }, { 240,	0x0F }, { 256,	0x33 },
> +	{ 288,	0x10 }, { 320,	0x34 }, { 384,	0x35 }, { 448,	0x36 },
> +	{ 480,	0x13 }, { 512,	0x37 }, { 576,	0x14 }, { 640,	0x38 },
> +	{ 768,	0x39 }, { 896,	0x3A }, { 960,	0x17 }, { 1024,	0x3B },
> +	{ 1152,	0x18 }, { 1280,	0x3C }, { 1536,	0x3D }, { 1792,	0x3E },
> +	{ 1920,	0x1B }, { 2048,	0x3F }, { 2304,	0x1C }, { 2560,	0x1D },
> +	{ 3072,	0x1E }, { 3840,	0x1F }
> +};
> +
> +static u8 clk_idx;
>  
> -static inline void i2c_reset(void)
> -{
> -	writew(0, I2C_BASE + I2CR);	/* Reset module */
> -	writew(0, I2C_BASE + I2SR);
> -	writew(I2CR_IEN, I2C_BASE + I2CR);
> -}
> -
> -void i2c_init(int speed, int unused)
> +/*
> + * Calculate and set proper clock divider
> + *
> + * FIXME: remove #ifdefs !
> + */

As Stefano just posted a patch for this, see here:

http://patchwork.ozlabs.org/patch/104642/

Can you fix this please?

Thanks!

> +static void i2c_imx_set_clk(unsigned int rate)
>  {
> -	int freq;
> +	struct mxc_i2c_regs *i2c_regs = (struct mxc_i2c_regs *)I2C_BASE;
> +	unsigned int i2c_clk_rate;
> +	unsigned int div;
>  	int i;
>  
> +	/* Divider value calculation */
>  #if defined(CONFIG_MX31)
>  	struct clock_control_regs *sc_regs =
>  		(struct clock_control_regs *)CCM_BASE;
>  
> -	freq = mx31_get_ipg_clk();
> +	i2c_clk_rate = mx31_get_ipg_clk();
>  	/* start the required I2C clock */
>  	writel(readl(&sc_regs->cgr0) | (3 << I2C_CLK_OFFSET),
>  		&sc_regs->cgr0);
>  #else
> -	freq = mxc_get_clock(MXC_IPG_PERCLK);
> +	i2c_clk_rate = mxc_get_clock(MXC_IPG_CLK);
>  #endif
[...]

bye,
Heiko
-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany


More information about the U-Boot mailing list