i2c: mxc: refactor i2c driver and support dm
Subsystems (3)
PATCH v4 1/2 i2c: mxc: refactor i2c driver and support dm
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, but pinctrl is not included. 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_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 }
"
8. Introduce a weak function, enable_i2c_clk
9. Tested on an i.MX7 platform. Log info:
=> dm tree
Class Probed Name
----------------------------------------
root [ + ] root_driver simple_bus [ ] |-- soc simple_bus [ ] | |-- aips-bus at 30000000 simple_bus [ ] | | |-- anatop at 30360000 simple_bus [ ] | | `-- snvs at 30370000 simple_bus [ ] | |-- aips-bus at 30400000 simple_bus [ ] | `-- aips-bus at 30800000 i2c [ ] | |-- i2c at 30a20000 i2c [ ] | `-- i2c at 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
---
Changes v4:
1. fix build errors
2. Introduce a weak function enable_i2c_clk.
3. add Simon's Acked-by.
4. Add test log in commit log.
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 | 581 ++++++++++++++++++++---------- 3 files changed, 433 insertions(+), 193 deletions(-)
arch/arm/imx-common/i2c-mxv7.c +4 -3
@@ -12,7 +12,7 @@#include <asm/imx-common/mxc_i2c.h> #include <watchdog.h> -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 ;
arch/arm/include/asm/imx-common/mxc_i2c.h +33 -5
@@ -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,uchar *buf, -int len); -int bus_i2c_write (void *base,uchar chip,uint addr,int alen, -const uchar *buf,int len); +int force_idle_bus (void *priv); +int i2c_idle_bus (struct mxc_i2c_bus *i2c_bus);#endif
drivers/i2c/mxc_i2c.c +396 -185
791 lines not on this page · raw message
Signature · 1 line
1.8.4
PATCH v4 2/2 imx: mx27 remove redundant macro
Use common macro in iomux-v3.h, remove redundant macro.
---
Changes v4:
New patch.
we include mxc_i2c.h in driver/i2c/mxc_i2c.c in patch 1/2. mxc_i2c.h includes iomux-v3.h.
Since iomux-v3.h have some macros which also exists in asm/arch-xx/imx-regs.h, this will introudce compile warnings such as "redefined macro".
Changes v3:
none
Changes v2:
none
arch/arm/cpu/arm926ejs/mx27/generic.c | 1 + arch/arm/include/asm/arch-mx27/imx-regs.h | 22 ---------------------- arch/arm/include/asm/imx-common/iomux-v3.h | 22 ++++++++++++++++------ board/armadeus/apf27/apf27.c | 1 + board/armadeus/apf27/fpga.c | 1 + board/logicpd/imx27lite/imx27lite.c | 1 + 6 files changed, 20 insertions(+), 28 deletions(-)
arch/arm/cpu/arm926ejs/mx27/generic.c +1 -0
@@ -12,6 +12,7 @@#include <asm/arch/imx-regs.h> #include <asm/arch/clock.h> #include <asm/arch/gpio.h> +#include <asm/imx-common/iomux-v3.h> #ifdef CONFIG_MXC_MMC #include <asm/arch/mxcmmc.h> #endif
arch/arm/include/asm/arch-mx27/imx-regs.h +0 -22
@@ -138,16 +138,6 @@ struct gpt_regs {u32 gpt_tstat; }; -/* -* GPIO Module and I/O Multiplexer -*/ -#define PORTA 0 -#define PORTB 1 -#define PORTC 2 -#define PORTD 3 -#define PORTE 4 -#define PORTF 5 -/* IIM Control Registers */ struct iim_regs {u32 iim_stat;
@@ -449,18 +439,6 @@ struct fuse_bank0_regs {#define GPIO5_BASE_ADDR 0x10015400#define GPIO6_BASE_ADDR 0x10015500 -#define GPIO_PIN_MASK 0x1f - -#define GPIO_PORT_SHIFT 5 -#define GPIO_PORT_MASK (0x7 << GPIO_PORT_SHIFT) - -#define GPIO_PORTA (PORTA << GPIO_PORT_SHIFT) -#define GPIO_PORTB (PORTB << GPIO_PORT_SHIFT) -#define GPIO_PORTC (PORTC << GPIO_PORT_SHIFT) -#define GPIO_PORTD (PORTD << GPIO_PORT_SHIFT) -#define GPIO_PORTE (PORTE << GPIO_PORT_SHIFT) -#define GPIO_PORTF (PORTF << GPIO_PORT_SHIFT) -#define GPIO_OUT (1 << 8)#define GPIO_IN (0 << 8)#define GPIO_PUEN (1 << 9)
arch/arm/include/asm/imx-common/iomux-v3.h +16 -6
@@ -169,15 +169,25 @@ typedef u64 iomux_v3_cfg_t;#define IOMUX_CONFIG_SION 0x10 +/* +* GPIO Module and I/O Multiplexer +*/ +#define PORTA 0 +#define PORTB 1 +#define PORTC 2 +#define PORTD 3 +#define PORTE 4 +#define PORTF 5 +#define GPIO_PIN_MASK 0x1f#define GPIO_PORT_SHIFT 5#define GPIO_PORT_MASK (0x7 << GPIO_PORT_SHIFT) -#define GPIO_PORTA (0 << GPIO_PORT_SHIFT) -#define GPIO_PORTB (1 << GPIO_PORT_SHIFT) -#define GPIO_PORTC (2 << GPIO_PORT_SHIFT) -#define GPIO_PORTD (3 << GPIO_PORT_SHIFT) -#define GPIO_PORTE (4 << GPIO_PORT_SHIFT) -#define GPIO_PORTF (5 << GPIO_PORT_SHIFT) +#define GPIO_PORTA (PORTA << GPIO_PORT_SHIFT) +#define GPIO_PORTB (PORTB << GPIO_PORT_SHIFT) +#define GPIO_PORTC (PORTC << GPIO_PORT_SHIFT) +#define GPIO_PORTD (PORTD << GPIO_PORT_SHIFT) +#define GPIO_PORTE (PORTE << GPIO_PORT_SHIFT) +#define GPIO_PORTF (PORTF << GPIO_PORT_SHIFT)void imx_iomux_v3_setup_pad (iomux_v3_cfg_t pad); void imx_iomux_v3_setup_multiple_pads(iomux_v3_cfg_t const *pad_list,
board/armadeus/apf27/apf27.c +1 -0
@@ -17,6 +17,7 @@#include <asm/arch/gpio.h> #include <asm/gpio.h> #include <asm/errno.h> +#include <asm/imx-common/iomux-v3.h> #include "apf27.h" #include "crc.h" #include "fpga.h"
board/armadeus/apf27/fpga.c +1 -0
@@ -13,6 +13,7 @@#include <asm/arch/imx-regs.h> #include <asm/gpio.h> +#include <asm/imx-common/iomux-v3.h> #include <asm/io.h> #include <command.h> #include <config.h>
board/logicpd/imx27lite/imx27lite.c +1 -0
@@ -10,6 +10,7 @@#include <asm/io.h> #include <asm/arch/imx-regs.h> #include <asm/gpio.h> +#include <asm/imx-common/iomux-v3.h> DECLARE_GLOBAL_DATA_PTR ;
Signature · 1 line
1.8.4
PATCH v4 2/2 imx: mx27 remove redundant macro
Quoted 19 lines · Peng Fan
Use common macro in
iomux-v3.h, remove redundant macro.Signed-off-by Peng Fan <[email protected]>---
Changes v4:
New patch.
we includemxc_i2c.hindriver/i2c/mxc_i2c.cin patch 1/2.mxc_i2c.hincludesiomux-v3.h.
Sinceiomux-v3.hhave some macros which also exists inasm/arch-xx/imx-regs.h, this will introudce compile warnings such as "redefined macro".Changes v3:
noneChanges v2:
none
Quoted 7 lines
arch/arm/cpu/arm926ejs/mx27/generic.c | 1 + arch/arm/include/asm/arch-mx27/imx-regs.h | 22 ---------------------- arch/arm/include/asm/imx-common/iomux-v3.h | 22 ++++++++++++++++------ board/armadeus/apf27/apf27.c | 1 + board/armadeus/apf27/fpga.c | 1 + board/logicpd/imx27lite/imx27lite.c | 1 + 6 files changed, 20 insertions(+), 28 deletions(-)
Applied to u-boot-dm, thanks!
Fabio Estevam
reviewerPATCH v4 2/2 imx: mx27 remove redundant macro
In reply to Peng FanHi Peng,
Quoted 1 line · Peng Fan
Use common macro in
iomux-v3.h, remove redundant macro.
This is a bit misleading.
mx27 iomux is not compatible to iomux-v3.h at all.
Regards,
Fabio Estevam
PATCH v4 2/2 imx: mx27 remove redundant macro
Hi,
Quoted 8 lines · Fabio Estevam
Hi Peng,
Quoted 1 line · Peng Fan
Use common macro in
iomux-v3.h, remove redundant macro.This is a bit misleading.
mx27 iomux is not compatible to
iomux-v3.hat all.
If you'd like to respin this patch I can accept it up until tomorrow morning, when I hope to send a pull request. If you would rather that I drop this patch, then I can drop both (since the other one depends on this one).
Regards,
Simon
PATCH v4 2/2 imx: mx27 remove redundant macro
Hi,
Quoted 10 lines · Simon Glass
Hi,
Quoted 7 lines · Fabio Estevam
Hi Peng,
Quoted 1 line · Peng Fan
Use common macro in
iomux-v3.h, remove redundant macro.This is a bit misleading.
mx27 iomux is not compatible to
iomux-v3.hat all.
Ok. I am not familiar with mx27. I'll move the GPIO_PORT[A,B,Cxxx] to gpio.h, but not in imx-regs.h for mx27.
Quoted 4 lines
If you'd like to respin this patch I can accept it up until tomorrow morning, when I hope to send a pull request. If you would rather that I drop this patch, then I can drop both (since the other one depends on this one).
I'll respin this patch. If this delays your PR, you can drop them first. I'll resend out patch v5 soon.
Quoted 3 lines
Regards,
Simon
Regards,
Peng.
PATCH v4 1/2 i2c: mxc: refactor i2c driver and support dm
In reply to Peng FanHi Peng,
Quoted 51 lines · Peng Fan
1. Introduce a new structure
struct mxc_i2c_bus, this structure will used for non-DM and DM.
2. Removestruct mxc_i2c_regsstructure, but use register offset to access registers based onbaseentry ofstruct mxc_i2c_bus.
3. Remove most#ifdef I2C_QUIRK_REG. Usingdriver_datato contain platform flags. A new flag is introduced,I2C_QUIRK_FLAG.
4. Most functions usestruct mxc_i2c_busas one of the parameters. Make most functions common to DM and non-DM, try to avoid duplicated code.
5. Support DM, but pinctrl is not included. Pinmux setting is still set bysetup_i2c, but we do not needbus_i2c_initfor DM.
6. structi2c_parmsand structsram_dataare removed.
7. Removebus_i2c_readbus_i2c_writeprototype in header file. The frist paramter ofbus_i2c_initis modified to i2c index. Add new prototypei2c_idle_busandforce_bus_idle. Sincebus_i2c_initis not good for DM I2C and pinctrl is missed, we use a weak function fori2c_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 } "8. Introduce a weak function,
enable_i2c_clk
9. Tested on an i.MX7 platform. Log info:
=> dm tree
Class Probed Name
----------------------------------------root [ + ] root_driver simple_bus [ ] |-- soc simple_bus [ ] | |-- aips-bus at 30000000 simple_bus [ ] | | |-- anatop at 30360000 simple_bus [ ] | | `-- snvs at 30370000 simple_bus [ ] | |-- aips-bus at 30400000 simple_bus [ ] | `-- aips-bus at 30800000 i2c [ ] | |-- i2c at 30a20000 i2c [ ] | `-- i2c at 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 08Signed-off-by Peng Fan <[email protected]>Acked-by Simon Glass <[email protected]>
Quoted 7 lines
---
Changes v4:
1. fix build errors
2. Introduce a weak functionenable_i2c_clk.
3. add Simon's Acked-by.
4. 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.
Quoted 19 lines
Changes v3:
1. removebus_i2c_initfor DM, introuduce a weak functioni2c_idle_bus.
2. remove static return type forforce_idle_bus, since we need to call it ini2c_idle_buswhich 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. Introducemxc_i2c_busstructure
3. IntroduceI2C_QUIRK_FLAGand remove mostI2C_QUIRK_REGand usedriver_datato contain the flags for different platforms
4. Avoid duplicated code between DM and non-DM part
5. The function namei2c_init_transferis 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.
Quoted 5 lines
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