Re: [U-Boot] [PATCH V3] i2c: mxc: refactor i2c driver and support dm

2015-05-13 Thread Fan Peng
Hi, Simon

There may be something wrong in my side. I will fix the build errors and send 
out new version.

Thanks,
Peng.

-Original Message-
From: s...@google.com [mailto:s...@google.com] On Behalf Of Simon Glass
Sent: Wednesday, May 13, 2015 11:25 PM
To: Fan Peng-B51431
Cc: Stefano Babic; Heiko Schocher; Marek Va?ut; Nikita Kiryanov; U-Boot Mailing 
List
Subject: Re: [PATCH V3] i2c: mxc: refactor i2c driver and support dm

Hi,

On 12 May 2015 at 19:09, Fan Peng  wrote:
> Hi,
>
> Is there any further comments? Or this patch will be applied?

This gives build errors for me:

02: i2c: mxc: refactor i2c driver and support dm
   arm:  +   nitrogen6dl2g mx53smd ls1021atwr_nor_SECURE_BOOT
tqma6s_mba6_spi apf27 mx6sxsabresd_spl ls1021aqds_nor_lpuart nitrogen6s 
nitrogen6q ls1021aqds_ddr4_nor wandboard_solo ls1021aqds_nand ls1021atwr_nor 
novena riotboard mx6dlsabreauto nitrogen6dl titanium ls1021aqds_ddr4_nor_lpuart 
tqma6s_mba6_mmc mx25pdk ot1200_spl mx53ard nitrogen6q2g ls1021atwr_nor_lpuart 
wandboard_dl wandboard_quad mx6sxsabresd platinum_titanium m53evk woodburn_sd 
mx6dlsabresd ls1021aqds_sdcard mx6qsabrelite mx6sabresd_spl ls1021atwr_sdcard 
ls1021atwr_qspi vf610twr_nand tqma6q_mba6_mmc woodburn vf610twr usbarmory flea3 
ot1200 tbs2910 ls1021aqds_nor imx31_phycore_eet mx35pdk mx6slevk_spinor 
ls1021aqds_qspi cm_fx6 mx6qsabresd imx31_phycore nitrogen6s1g marsboard 
tqma6q_mba6_spi mx53evk aristainetos mx6slevk platinum_picon mx6qsabreauto 
mx53loco ls1021aqds_nor_SECURE_BOOT gwventana
+../drivers/i2c/mxc_i2c.c:524:11: error: missing binary operator
before token "ined"
+../drivers/i2c/mxc_i2c.c:581:2: error: expected ‘;’ before ‘}’ token
+make[2]: *** [drivers/i2c/mxc_i2c.o] Error 1
+make[1]: *** [drivers/i2c] Error 2
+../drivers/i2c/mxc_i2c.c:532:2: error: #error "architecture not supported"
+In file included from ../arch/arm/include/asm/imx-common/mxc_i2c.h:8:0,
+ from ../drivers/i2c/mxc_i2c.c:21:
w+../drivers/i2c/mxc_i2c.c: In function ‘bus_i2c_init’:
w+../drivers/i2c/mxc_i2c.c:580:3: warning: ‘return’ with a value, in
function returning void [enabled by default]
w+../drivers/i2c/mxc_i2c.c:577:2: warning: implicit declaration of
function ‘enable_i2c_clk’ [-Wimplicit-function-declaration]
w+../arch/arm/include/asm/imx-common/iomux-v3.h:175:0: warning:
"GPIO_PORTA" redefined [enabled by default]
w+In file included from ../drivers/i2c/mxc_i2c.c:19:0:
w+include/asm/arch/imx-regs.h:457:0: note: this is the location of the
previous definition
w+../arch/arm/include/asm/imx-common/iomux-v3.h:176:0: warning:
"GPIO_PORTB" redefined [enabled by default]
w+include/asm/arch/imx-regs.h:458:0: note: this is the location of the
previous definition
w+../arch/arm/include/asm/imx-common/iomux-v3.h:177:0: warning:
"GPIO_PORTC" redefined [enabled by default]
w+include/asm/arch/imx-regs.h:459:0: note: this is the location of the
previous definition
w+../arch/arm/include/asm/imx-common/iomux-v3.h:178:0: warning:
"GPIO_PORTD" redefined [enabled by default]
w+include/asm/arch/imx-regs.h:460:0: note: this is the location of the
previous definition
w+../arch/arm/include/asm/imx-common/iomux-v3.h:179:0: warning:
"GPIO_PORTE" redefined [enabled by default]
w+include/asm/arch/imx-regs.h:461:0: note: this is the location of the
previous definition
w+../arch/arm/include/asm/imx-common/iomux-v3.h:180:0: warning:
"GPIO_PORTF" redefined [enabled by default]
w+include/asm/arch/imx-regs.h:462:0: note: this is the location of the
previous definition


Regards,
Simon
>
> Regards,
> Peng.
>
> -Original Message-
> From: s...@google.com [mailto:s...@google.com] On Behalf Of Simon Glass
> Sent: Wednesday, May 06, 2015 4:56 AM
> To: Fan Peng-B51431
> Cc: Stefano Babic; Heiko Schocher; Marek Vašut; Nikita Kiryanov; 
> U-Boot Mailing List
> Subject: Re: [PATCH V3] i2c: mxc: refactor i2c driver and support dm
>
> On 27 April 2015 at 07:36, Peng Fan  wrote:
>>
>> 1. Introduce a new structure `struct mxc_i2c_bus`, this structure will
>>used for non-DM and DM.
>> 2. Remove `struct mxc_i2c_regs` structure, but use register offset to access
>>registers based on `base` entry of `struct mxc_i2c_bus`.
>> 3. Remove most `#ifdef I2C_QUIRK_REG`. Using driver_data to contain platform
>>flags. A new flag is introduced, I2C_QUIRK_FLAG.
>> 4. Most functions use `struct mxc_i2c_bus` as one of the parameters.
>>Make most functions common to DM and non-DM, try to avoid duplicated code.
>> 5. Support DM. Pinmux setting is still set by setup_i2c, but we do not
>>need bus_i2c_init for DM.
>> 6. struct i2c_parms and struct sram_data are removed.
>> 7. Remove bus_i2c_read bus_i2c_write prototype in header file. The frist
>>paramter of bus_i2c_init is modified to i2c index. Add new prototype
>>i2c_idle_bus and force_idle_bus. Since bus_i2c_init is not good for
>>DM I2C and pinctrl is missed, we use a weak function for i2c_idle_bus
>>for DM part.
>>Board file take the responsibility to implement thi

Re: [U-Boot] [PATCH V3] i2c: mxc: refactor i2c driver and support dm

2015-05-13 Thread Simon Glass
Hi,

On 12 May 2015 at 19:09, Fan Peng  wrote:
> Hi,
>
> Is there any further comments? Or this patch will be applied?

This gives build errors for me:

02: i2c: mxc: refactor i2c driver and support dm
   arm:  +   nitrogen6dl2g mx53smd ls1021atwr_nor_SECURE_BOOT
tqma6s_mba6_spi apf27 mx6sxsabresd_spl ls1021aqds_nor_lpuart
nitrogen6s nitrogen6q ls1021aqds_ddr4_nor wandboard_solo
ls1021aqds_nand ls1021atwr_nor novena riotboard mx6dlsabreauto
nitrogen6dl titanium ls1021aqds_ddr4_nor_lpuart tqma6s_mba6_mmc
mx25pdk ot1200_spl mx53ard nitrogen6q2g ls1021atwr_nor_lpuart
wandboard_dl wandboard_quad mx6sxsabresd platinum_titanium m53evk
woodburn_sd mx6dlsabresd ls1021aqds_sdcard mx6qsabrelite
mx6sabresd_spl ls1021atwr_sdcard ls1021atwr_qspi vf610twr_nand
tqma6q_mba6_mmc woodburn vf610twr usbarmory flea3 ot1200 tbs2910
ls1021aqds_nor imx31_phycore_eet mx35pdk mx6slevk_spinor
ls1021aqds_qspi cm_fx6 mx6qsabresd imx31_phycore nitrogen6s1g
marsboard tqma6q_mba6_spi mx53evk aristainetos mx6slevk platinum_picon
mx6qsabreauto mx53loco ls1021aqds_nor_SECURE_BOOT gwventana
+../drivers/i2c/mxc_i2c.c:524:11: error: missing binary operator
before token "ined"
+../drivers/i2c/mxc_i2c.c:581:2: error: expected ‘;’ before ‘}’ token
+make[2]: *** [drivers/i2c/mxc_i2c.o] Error 1
+make[1]: *** [drivers/i2c] Error 2
+../drivers/i2c/mxc_i2c.c:532:2: error: #error "architecture not supported"
+In file included from ../arch/arm/include/asm/imx-common/mxc_i2c.h:8:0,
+ from ../drivers/i2c/mxc_i2c.c:21:
w+../drivers/i2c/mxc_i2c.c: In function ‘bus_i2c_init’:
w+../drivers/i2c/mxc_i2c.c:580:3: warning: ‘return’ with a value, in
function returning void [enabled by default]
w+../drivers/i2c/mxc_i2c.c:577:2: warning: implicit declaration of
function ‘enable_i2c_clk’ [-Wimplicit-function-declaration]
w+../arch/arm/include/asm/imx-common/iomux-v3.h:175:0: warning:
"GPIO_PORTA" redefined [enabled by default]
w+In file included from ../drivers/i2c/mxc_i2c.c:19:0:
w+include/asm/arch/imx-regs.h:457:0: note: this is the location of the
previous definition
w+../arch/arm/include/asm/imx-common/iomux-v3.h:176:0: warning:
"GPIO_PORTB" redefined [enabled by default]
w+include/asm/arch/imx-regs.h:458:0: note: this is the location of the
previous definition
w+../arch/arm/include/asm/imx-common/iomux-v3.h:177:0: warning:
"GPIO_PORTC" redefined [enabled by default]
w+include/asm/arch/imx-regs.h:459:0: note: this is the location of the
previous definition
w+../arch/arm/include/asm/imx-common/iomux-v3.h:178:0: warning:
"GPIO_PORTD" redefined [enabled by default]
w+include/asm/arch/imx-regs.h:460:0: note: this is the location of the
previous definition
w+../arch/arm/include/asm/imx-common/iomux-v3.h:179:0: warning:
"GPIO_PORTE" redefined [enabled by default]
w+include/asm/arch/imx-regs.h:461:0: note: this is the location of the
previous definition
w+../arch/arm/include/asm/imx-common/iomux-v3.h:180:0: warning:
"GPIO_PORTF" redefined [enabled by default]
w+include/asm/arch/imx-regs.h:462:0: note: this is the location of the
previous definition


Regards,
Simon
>
> Regards,
> Peng.
>
> -Original Message-
> From: s...@google.com [mailto:s...@google.com] On Behalf Of Simon Glass
> Sent: Wednesday, May 06, 2015 4:56 AM
> To: Fan Peng-B51431
> Cc: Stefano Babic; Heiko Schocher; Marek Vašut; Nikita Kiryanov; U-Boot 
> Mailing List
> Subject: Re: [PATCH V3] i2c: mxc: refactor i2c driver and support dm
>
> On 27 April 2015 at 07:36, Peng Fan  wrote:
>>
>> 1. Introduce a new structure `struct mxc_i2c_bus`, this structure will
>>used for non-DM and DM.
>> 2. Remove `struct mxc_i2c_regs` structure, but use register offset to access
>>registers based on `base` entry of `struct mxc_i2c_bus`.
>> 3. Remove most `#ifdef I2C_QUIRK_REG`. Using driver_data to contain platform
>>flags. A new flag is introduced, I2C_QUIRK_FLAG.
>> 4. Most functions use `struct mxc_i2c_bus` as one of the parameters.
>>Make most functions common to DM and non-DM, try to avoid duplicated code.
>> 5. Support DM. Pinmux setting is still set by setup_i2c, but we do not
>>need bus_i2c_init for DM.
>> 6. struct i2c_parms and struct sram_data are removed.
>> 7. Remove bus_i2c_read bus_i2c_write prototype in header file. The frist
>>paramter of bus_i2c_init is modified to i2c index. Add new prototype
>>i2c_idle_bus and force_idle_bus. Since bus_i2c_init is not good for
>>DM I2C and pinctrl is missed, we use a weak function for i2c_idle_bus
>>for DM part.
>>Board file take the responsibility to implement this function, like this:
>>"
>>int i2c_idle_bus(struct mxc_i2c_bus *i2c_bus)
>>{
>>if (i2c_bus->index == 0)
>>force_idle_bus(i2c_pads_info0);
>>else if (i2c_bus->index == 1)
>>force_idle_bus(i2c_pads_info1);
>>else
>>xx
>>}
>>"
>>
>> Signed-off-by: Peng Fan 
>> ---
>>
>> Changes v3:
>>  1. remove bus_i2c_init for DM, introuduce

Re: [U-Boot] [PATCH V3] i2c: mxc: refactor i2c driver and support dm

2015-05-12 Thread Heiko Schocher

Hello Simon,

Am 13.05.2015 03:44, schrieb Simon Glass:

Hi,

On 12 May 2015 at 19:09, Fan Peng  wrote:


Hi,

Is there any further comments? Or this patch will be applied?



I can apply it if you like - Heiko what do you prefer?


Yes, please. Thanks.

bye,
Heiko


- Simon


Regards,
Peng.

-Original Message-
From: s...@google.com [mailto:s...@google.com] On Behalf Of Simon Glass
Sent: Wednesday, May 06, 2015 4:56 AM
To: Fan Peng-B51431
Cc: Stefano Babic; Heiko Schocher; Marek Vašut; Nikita Kiryanov; U-Boot Mailing 
List
Subject: Re: [PATCH V3] i2c: mxc: refactor i2c driver and support dm

On 27 April 2015 at 07:36, Peng Fan  wrote:


1. Introduce a new structure `struct mxc_i2c_bus`, this structure will
used for non-DM and DM.
2. Remove `struct mxc_i2c_regs` structure, but use register offset to access
registers based on `base` entry of `struct mxc_i2c_bus`.
3. Remove most `#ifdef I2C_QUIRK_REG`. Using driver_data to contain platform
flags. A new flag is introduced, I2C_QUIRK_FLAG.
4. Most functions use `struct mxc_i2c_bus` as one of the parameters.
Make most functions common to DM and non-DM, try to avoid duplicated code.
5. Support DM. Pinmux setting is still set by setup_i2c, but we do not
need bus_i2c_init for DM.
6. struct i2c_parms and struct sram_data are removed.
7. Remove bus_i2c_read bus_i2c_write prototype in header file. The frist
paramter of bus_i2c_init is modified to i2c index. Add new prototype
i2c_idle_bus and force_idle_bus. Since bus_i2c_init is not good for
DM I2C and pinctrl is missed, we use a weak function for i2c_idle_bus
for DM part.
Board file take the responsibility to implement this function, like this:
"
int i2c_idle_bus(struct mxc_i2c_bus *i2c_bus)
{
if (i2c_bus->index == 0)
force_idle_bus(i2c_pads_info0);
else if (i2c_bus->index == 1)
force_idle_bus(i2c_pads_info1);
else
xx
}
"

Signed-off-by: Peng Fan 
---

Changes v3:
  1. remove bus_i2c_init for DM, introuduce a weak function i2c_idle_bus.
  2. remove static return type for force_idle_bus, since we need to call
 it in i2c_idle_bus which may be implemented in board file. This does
 not hurt for non-DM.


Acked-by: Simon Glass 



Changes v2:
  1. Refactor driver, remove register access based on structure, but use
'base + offset'
  2. Introduce mxc_i2c_bus structure
  3. Introduce I2C_QUIRK_FLAG and remove most I2C_QUIRK_REG and use
 driver_data to contain the flags for different platforms  4. Avoid
duplicated code between DM and non-DM part  5. The function name
i2c_init_transfer is not changed.
  6. Remove bus_i2c_read/write prototype from header file  7. change
bus_i2c_init's first parameter to i2c index  8. Rename patch name,
since refactor non-DM part.

  arch/arm/imx-common/i2c-mxv7.c|   7 +-
  arch/arm/include/asm/imx-common/mxc_i2c.h |  38 +-
  drivers/i2c/mxc_i2c.c | 575 --
  3 files changed, 426 insertions(+), 194 deletions(-)





--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH V3] i2c: mxc: refactor i2c driver and support dm

2015-05-12 Thread Simon Glass
Hi,

On 12 May 2015 at 19:09, Fan Peng  wrote:
>
> Hi,
>
> Is there any further comments? Or this patch will be applied?
>

I can apply it if you like - Heiko what do you prefer?

- Simon

> Regards,
> Peng.
>
> -Original Message-
> From: s...@google.com [mailto:s...@google.com] On Behalf Of Simon Glass
> Sent: Wednesday, May 06, 2015 4:56 AM
> To: Fan Peng-B51431
> Cc: Stefano Babic; Heiko Schocher; Marek Vašut; Nikita Kiryanov; U-Boot 
> Mailing List
> Subject: Re: [PATCH V3] i2c: mxc: refactor i2c driver and support dm
>
> On 27 April 2015 at 07:36, Peng Fan  wrote:
> >
> > 1. Introduce a new structure `struct mxc_i2c_bus`, this structure will
> >used for non-DM and DM.
> > 2. Remove `struct mxc_i2c_regs` structure, but use register offset to access
> >registers based on `base` entry of `struct mxc_i2c_bus`.
> > 3. Remove most `#ifdef I2C_QUIRK_REG`. Using driver_data to contain platform
> >flags. A new flag is introduced, I2C_QUIRK_FLAG.
> > 4. Most functions use `struct mxc_i2c_bus` as one of the parameters.
> >Make most functions common to DM and non-DM, try to avoid duplicated 
> > code.
> > 5. Support DM. Pinmux setting is still set by setup_i2c, but we do not
> >need bus_i2c_init for DM.
> > 6. struct i2c_parms and struct sram_data are removed.
> > 7. Remove bus_i2c_read bus_i2c_write prototype in header file. The frist
> >paramter of bus_i2c_init is modified to i2c index. Add new prototype
> >i2c_idle_bus and force_idle_bus. Since bus_i2c_init is not good for
> >DM I2C and pinctrl is missed, we use a weak function for i2c_idle_bus
> >for DM part.
> >Board file take the responsibility to implement this function, like this:
> >"
> >int i2c_idle_bus(struct mxc_i2c_bus *i2c_bus)
> >{
> >if (i2c_bus->index == 0)
> >force_idle_bus(i2c_pads_info0);
> >else if (i2c_bus->index == 1)
> >force_idle_bus(i2c_pads_info1);
> >else
> >xx
> >}
> >"
> >
> > Signed-off-by: Peng Fan 
> > ---
> >
> > Changes v3:
> >  1. remove bus_i2c_init for DM, introuduce a weak function i2c_idle_bus.
> >  2. remove static return type for force_idle_bus, since we need to call
> > it in i2c_idle_bus which may be implemented in board file. This does
> > not hurt for non-DM.
>
> Acked-by: Simon Glass 
>
> >
> > Changes v2:
> >  1. Refactor driver, remove register access based on structure, but use
> >'base + offset'
> >  2. Introduce mxc_i2c_bus structure
> >  3. Introduce I2C_QUIRK_FLAG and remove most I2C_QUIRK_REG and use
> > driver_data to contain the flags for different platforms  4. Avoid
> > duplicated code between DM and non-DM part  5. The function name
> > i2c_init_transfer is not changed.
> >  6. Remove bus_i2c_read/write prototype from header file  7. change
> > bus_i2c_init's first parameter to i2c index  8. Rename patch name,
> > since refactor non-DM part.
> >
> >  arch/arm/imx-common/i2c-mxv7.c|   7 +-
> >  arch/arm/include/asm/imx-common/mxc_i2c.h |  38 +-
> >  drivers/i2c/mxc_i2c.c | 575 
> > --
> >  3 files changed, 426 insertions(+), 194 deletions(-)
> >
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH V3] i2c: mxc: refactor i2c driver and support dm

2015-05-12 Thread Fan Peng
Hi,

Is there any further comments? Or this patch will be applied?

Regards,
Peng.

-Original Message-
From: s...@google.com [mailto:s...@google.com] On Behalf Of Simon Glass
Sent: Wednesday, May 06, 2015 4:56 AM
To: Fan Peng-B51431
Cc: Stefano Babic; Heiko Schocher; Marek Vašut; Nikita Kiryanov; U-Boot Mailing 
List
Subject: Re: [PATCH V3] i2c: mxc: refactor i2c driver and support dm

On 27 April 2015 at 07:36, Peng Fan  wrote:
>
> 1. Introduce a new structure `struct mxc_i2c_bus`, this structure will
>used for non-DM and DM.
> 2. Remove `struct mxc_i2c_regs` structure, but use register offset to access
>registers based on `base` entry of `struct mxc_i2c_bus`.
> 3. Remove most `#ifdef I2C_QUIRK_REG`. Using driver_data to contain platform
>flags. A new flag is introduced, I2C_QUIRK_FLAG.
> 4. Most functions use `struct mxc_i2c_bus` as one of the parameters.
>Make most functions common to DM and non-DM, try to avoid duplicated code.
> 5. Support DM. Pinmux setting is still set by setup_i2c, but we do not
>need bus_i2c_init for DM.
> 6. struct i2c_parms and struct sram_data are removed.
> 7. Remove bus_i2c_read bus_i2c_write prototype in header file. The frist
>paramter of bus_i2c_init is modified to i2c index. Add new prototype
>i2c_idle_bus and force_idle_bus. Since bus_i2c_init is not good for
>DM I2C and pinctrl is missed, we use a weak function for i2c_idle_bus
>for DM part.
>Board file take the responsibility to implement this function, like this:
>"
>int i2c_idle_bus(struct mxc_i2c_bus *i2c_bus)
>{
>if (i2c_bus->index == 0)
>force_idle_bus(i2c_pads_info0);
>else if (i2c_bus->index == 1)
>force_idle_bus(i2c_pads_info1);
>else
>xx
>}
>"
>
> Signed-off-by: Peng Fan 
> ---
>
> Changes v3:
>  1. remove bus_i2c_init for DM, introuduce a weak function i2c_idle_bus.
>  2. remove static return type for force_idle_bus, since we need to call
> it in i2c_idle_bus which may be implemented in board file. This does
> not hurt for non-DM.

Acked-by: Simon Glass 

>
> Changes v2:
>  1. Refactor driver, remove register access based on structure, but use
>'base + offset'
>  2. Introduce mxc_i2c_bus structure
>  3. Introduce I2C_QUIRK_FLAG and remove most I2C_QUIRK_REG and use
> driver_data to contain the flags for different platforms  4. Avoid 
> duplicated code between DM and non-DM part  5. The function name 
> i2c_init_transfer is not changed.
>  6. Remove bus_i2c_read/write prototype from header file  7. change 
> bus_i2c_init's first parameter to i2c index  8. Rename patch name, 
> since refactor non-DM part.
>
>  arch/arm/imx-common/i2c-mxv7.c|   7 +-
>  arch/arm/include/asm/imx-common/mxc_i2c.h |  38 +-
>  drivers/i2c/mxc_i2c.c | 575 
> --
>  3 files changed, 426 insertions(+), 194 deletions(-)
>
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH V3] i2c: mxc: refactor i2c driver and support dm

2015-05-05 Thread Simon Glass
On 27 April 2015 at 07:36, Peng Fan  wrote:
>
> 1. Introduce a new structure `struct mxc_i2c_bus`, this structure will
>used for non-DM and DM.
> 2. Remove `struct mxc_i2c_regs` structure, but use register offset to access
>registers based on `base` entry of `struct mxc_i2c_bus`.
> 3. Remove most `#ifdef I2C_QUIRK_REG`. Using driver_data to contain platform
>flags. A new flag is introduced, I2C_QUIRK_FLAG.
> 4. Most functions use `struct mxc_i2c_bus` as one of the parameters.
>Make most functions common to DM and non-DM, try to avoid duplicated code.
> 5. Support DM. Pinmux setting is still set by setup_i2c, but we do not
>need bus_i2c_init for DM.
> 6. struct i2c_parms and struct sram_data are removed.
> 7. Remove bus_i2c_read bus_i2c_write prototype in header file. The frist
>paramter of bus_i2c_init is modified to i2c index. Add new prototype
>i2c_idle_bus and force_idle_bus. Since bus_i2c_init is not good for
>DM I2C and pinctrl is missed, we use a weak function for i2c_idle_bus
>for DM part.
>Board file take the responsibility to implement this function, like this:
>"
>int i2c_idle_bus(struct mxc_i2c_bus *i2c_bus)
>{
>if (i2c_bus->index == 0)
>force_idle_bus(i2c_pads_info0);
>else if (i2c_bus->index == 1)
>force_idle_bus(i2c_pads_info1);
>else
>xx
>}
>"
>
> Signed-off-by: Peng Fan 
> ---
>
> Changes v3:
>  1. remove bus_i2c_init for DM, introuduce a weak function i2c_idle_bus.
>  2. remove static return type for force_idle_bus, since we need to call
> it in i2c_idle_bus which may be implemented in board file. This does
> not hurt for non-DM.

Acked-by: Simon Glass 

>
> Changes v2:
>  1. Refactor driver, remove register access based on structure, but use
>'base + offset'
>  2. Introduce mxc_i2c_bus structure
>  3. Introduce I2C_QUIRK_FLAG and remove most I2C_QUIRK_REG and use
> driver_data to contain the flags for different platforms
>  4. Avoid duplicated code between DM and non-DM part
>  5. The function name i2c_init_transfer is not changed.
>  6. Remove bus_i2c_read/write prototype from header file
>  7. change bus_i2c_init's first parameter to i2c index
>  8. Rename patch name, since refactor non-DM part.
>
>  arch/arm/imx-common/i2c-mxv7.c|   7 +-
>  arch/arm/include/asm/imx-common/mxc_i2c.h |  38 +-
>  drivers/i2c/mxc_i2c.c | 575 
> --
>  3 files changed, 426 insertions(+), 194 deletions(-)
>
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH V3] i2c: mxc: refactor i2c driver and support dm

2015-04-27 Thread Peng Fan
1. Introduce a new structure `struct mxc_i2c_bus`, this structure will
   used for non-DM and DM.
2. Remove `struct mxc_i2c_regs` structure, but use register offset to access
   registers based on `base` entry of `struct mxc_i2c_bus`.
3. Remove most `#ifdef I2C_QUIRK_REG`. Using driver_data to contain platform
   flags. A new flag is introduced, I2C_QUIRK_FLAG.
4. Most functions use `struct mxc_i2c_bus` as one of the parameters.
   Make most functions common to DM and non-DM, try to avoid duplicated code.
5. Support DM. Pinmux setting is still set by setup_i2c, but we do not
   need bus_i2c_init for DM.
6. struct i2c_parms and struct sram_data are removed.
7. Remove bus_i2c_read bus_i2c_write prototype in header file. The frist
   paramter of bus_i2c_init is modified to i2c index. Add new prototype
   i2c_idle_bus and force_idle_bus. Since bus_i2c_init is not good for
   DM I2C and pinctrl is missed, we use a weak function for i2c_idle_bus
   for DM part.
   Board file take the responsibility to implement this function, like this:
   "
   int i2c_idle_bus(struct mxc_i2c_bus *i2c_bus)
   {
   if (i2c_bus->index == 0)
   force_idle_bus(i2c_pads_info0);
   else if (i2c_bus->index == 1)
   force_idle_bus(i2c_pads_info1);
   else
   xx
   }
   "

Signed-off-by: Peng Fan 
---

Changes v3:
 1. remove bus_i2c_init for DM, introuduce a weak function i2c_idle_bus.
 2. remove static return type for force_idle_bus, since we need to call
it in i2c_idle_bus which may be implemented in board file. This does
not hurt for non-DM.

Changes v2:
 1. Refactor driver, remove register access based on structure, but use
   'base + offset'
 2. Introduce mxc_i2c_bus structure
 3. Introduce I2C_QUIRK_FLAG and remove most I2C_QUIRK_REG and use
driver_data to contain the flags for different platforms
 4. Avoid duplicated code between DM and non-DM part
 5. The function name i2c_init_transfer is not changed.
 6. Remove bus_i2c_read/write prototype from header file
 7. change bus_i2c_init's first parameter to i2c index
 8. Rename patch name, since refactor non-DM part.

 arch/arm/imx-common/i2c-mxv7.c|   7 +-
 arch/arm/include/asm/imx-common/mxc_i2c.h |  38 +-
 drivers/i2c/mxc_i2c.c | 575 --
 3 files changed, 426 insertions(+), 194 deletions(-)

diff --git a/arch/arm/imx-common/i2c-mxv7.c b/arch/arm/imx-common/i2c-mxv7.c
index 1a632e7..f3a5c3f 100644
--- a/arch/arm/imx-common/i2c-mxv7.c
+++ b/arch/arm/imx-common/i2c-mxv7.c
@@ -12,7 +12,7 @@
 #include 
 #include 
 
-static int force_idle_bus(void *priv)
+int force_idle_bus(void *priv)
 {
int i;
int sda, scl;
@@ -99,8 +99,9 @@ int setup_i2c(unsigned i2c_index, int speed, int slave_addr,
if (ret)
goto err_idle;
 
-   bus_i2c_init(i2c_bases[i2c_index], speed, slave_addr,
-   force_idle_bus, p);
+#ifndef CONFIG_DM_I2C
+   bus_i2c_init(i2c_index, speed, slave_addr, force_idle_bus, p);
+#endif
 
return 0;
 
diff --git a/arch/arm/include/asm/imx-common/mxc_i2c.h 
b/arch/arm/include/asm/imx-common/mxc_i2c.h
index af86163..355b25e 100644
--- a/arch/arm/include/asm/imx-common/mxc_i2c.h
+++ b/arch/arm/include/asm/imx-common/mxc_i2c.h
@@ -19,6 +19,36 @@ struct i2c_pads_info {
struct i2c_pin_ctrl sda;
 };
 
+/*
+ * Information about i2c controller
+ * struct mxc_i2c_bus - information about the i2c[x] bus
+ * @index: i2c bus index
+ * @base: Address of I2C bus controller
+ * @driver_data: Flags for different platforms, such as I2C_QUIRK_FLAG.
+ * @speed: Speed of I2C bus
+ * @pads_info: pinctrl info for this i2c bus, will be used when pinctrl is ok.
+ * The following two is only to be compatible with non-DM part.
+ * @idle_bus_fn: function to force bus idle
+ * @idle_bus_data: parameter for idle_bus_fun
+ */
+struct mxc_i2c_bus {
+   /*
+* board file can use this index to locate which i2c_pads_info is for
+* i2c_idle_bus. When pinmux is implement, this entry can be
+* discarded. Here we do not use dev->seq, because we do not want to
+* export device to board file.
+*/
+   int index;
+   ulong base;
+   ulong driver_data;
+   int speed;
+   struct i2c_pads_info *pads_info;
+#ifndef CONFIG_DM_I2C
+   int (*idle_bus_fn)(void *p);
+   void *idle_bus_data;
+#endif
+};
+
 #if defined(CONFIG_MX6QDL)
 #define I2C_PADS(name, scl_i2c, scl_gpio, scl_gp, sda_i2c, sda_gpio, sda_gp) \
struct i2c_pads_info mx6q_##name = {\
@@ -54,10 +84,8 @@ struct i2c_pads_info {
 
 int setup_i2c(unsigned i2c_index, int speed, int slave_addr,
  struct i2c_pads_info *p);
-void bus_i2c_init(void *base, int speed, int slave_addr,
+void bus_i2c_init(int index, int speed, int slave_addr,
int (*idle_bus_fn)(void *p), void *p);
-int bus_i2c_read(void *base, uchar chip, uint addr, int alen, uch