
Hi Peng,
On 14 May 2015 at 04:03, Peng Fan Peng.Fan@freescale.com wrote:
- Introduce a new structure `struct mxc_i2c_bus`, this structure will used for non-DM and DM.
- Remove `struct mxc_i2c_regs` structure, but use register offset to access registers based on `base` entry of `struct mxc_i2c_bus`.
- Remove most `#ifdef I2C_QUIRK_REG`. Using driver_data to contain platform flags. A new flag is introduced, I2C_QUIRK_FLAG.
- 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.
- Support DM, but pinctrl is not included. Pinmux setting is still set by setup_i2c, but we do not need bus_i2c_init for DM.
- struct i2c_parms and struct sram_data are removed.
- 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_bus_idle. Since bus_i2c_init is not good for DM I2C and pinctrl is missed, we use a weak function for i2c_idle_bus. 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_bus_idle(i2c_pads_info0); else if (i2c_bus->index == 1) force_bus_idle(i2c_pads_info1); else xxxxxx } "
- Introduce a weak function, enable_i2c_clk
- Tested on an i.MX7 platform. Log info:
=> dm tree Class Probed Name
root [ + ] root_driver simple_bus [ ] |-- soc simple_bus [ ] | |-- aips-bus@30000000 simple_bus [ ] | | |-- anatop@30360000 simple_bus [ ] | | `-- snvs@30370000 simple_bus [ ] | |-- aips-bus@30400000 simple_bus [ ] | `-- aips-bus@30800000 i2c [ ] | |-- i2c@30a20000 i2c [ ] | `-- i2c@30a40000 simple_bus [ ] `-- regulators => i2c dev 0 Setting bus to 0 => i2c probe Valid chip addresses: 08 50 => i2c md 8 31 0031: 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
Signed-off-by: Peng Fan Peng.Fan@freescale.com Acked-by: Simon Glass sjg@chromium.org
Changes v4:
- fix build errors
- Introduce a weak function enable_i2c_clk.
- add Simon's Acked-by.
- Add test log in commit log.
I still get one build break here, fixed by the second commit:
02: i2c: mxc: refactor i2c driver and support dm arm: + apf27 +In file included from ../arch/arm/include/asm/imx-common/mxc_i2c.h:8:0, + from ../drivers/i2c/mxc_i2c.c:21: 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 03: imx: mx27 remove redundant macro arm: apf27 -In file included from ../arch/arm/include/asm/imx-common/mxc_i2c.h:8:0, - from ../drivers/i2c/mxc_i2c.c:21: 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
I'll apply them in the other order.
Changes v3:
- remove bus_i2c_init for DM, introuduce a weak function i2c_idle_bus.
- 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:
- Refactor driver, remove register access based on structure, but use
'base + offset'
- Introduce mxc_i2c_bus structure
- Introduce I2C_QUIRK_FLAG and remove most I2C_QUIRK_REG and use driver_data to contain the flags for different platforms
- Avoid duplicated code between DM and non-DM part
- The function name i2c_init_transfer is not changed.
- Remove bus_i2c_read/write prototype from header file
- change bus_i2c_init's first parameter to i2c index
- 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 | 581 ++++++++++++++++++++---------- 3 files changed, 433 insertions(+), 193 deletions(-)
[snip]
Applied to u-boot-dm, thanks!
Regards, Simon