i2c: mxc: refactor i2c driver and support dm
Subsystems (3)
PATCH v5 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 v5:
none
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 v5 2/2 imx: mx27 move GPIO_PORTx to gpio.h
These GPIO_PORTx macros should be in gpio.h, but not in imx-regs.h.
Also, imx-regs.h and iomux-v3.h has same macro defintion for GPIO_PORTx, and both of them are included in mxc_i2c.c(include mxc_i2c.h). This will incur build warnings with macro redefinition.
Since iomux-v3.h is not compatible with mx27, we can not simply include iomux-v3.h for mx27, so move the GPIO_PORTx to gpio.h to fix the build warning.
---
Changes v5:
Take Fabio's suggestion.
Since iomux-v3.h is not compatible with mx27, we can not directly include iomux-v3.h for mx27. Move the GPIO_PORTx to gpio.h which should be not in imx-regs.h.
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/include/asm/arch-mx27/gpio.h | 20 ++++++++++++++++++++ arch/arm/include/asm/arch-mx27/imx-regs.h | 22 ---------------------- 2 files changed, 20 insertions(+), 22 deletions(-)
arch/arm/include/asm/arch-mx27/gpio.h +20 -0
@@ -36,4 +36,24 @@ struct gpio_port_regs { struct gpio_regs port[6]; }; +/* +* 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 (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) +#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)
Signature · 1 line
1.8.4
PATCH v5 1/2 i2c: mxc: refactor i2c driver and support dm
In reply to Peng FanQuoted 80 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]>---
Changes v5:
noneChanges 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.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 4 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(-)
Applied to u-boot-dm, take 2, thanks!
PATCH v5 2/2 imx: mx27 move GPIO_PORTx to gpio.h
In reply to Peng FanQuoted 30 lines · Peng Fan
These
GPIO_PORTxmacros should be ingpio.h, but not inimx-regs.h.Also,
imx-regs.handiomux-v3.hhas same macro defintion forGPIO_PORTx, and both of them are included inmxc_i2c.c(include mxc_i2c.h). This will incur build warnings with macro redefinition.Since
iomux-v3.his not compatible with mx27, we can not simply includeiomux-v3.hfor mx27, so move theGPIO_PORTxtogpio.hto fix the build warning.Signed-off-by Peng Fan <[email protected]>---
Changes v5:
Take Fabio's suggestion.
Sinceiomux-v3.his not compatible with mx27, we can not directly includeiomux-v3.hfor mx27. Move theGPIO_PORTxtogpio.hwhich should be not inimx-regs.h.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:
none
Quoted 6 lines
Changes v2:
nonearch/arm/include/asm/arch-mx27/gpio.h | 20 ++++++++++++++++++++ arch/arm/include/asm/arch-mx27/imx-regs.h | 22 ---------------------- 2 files changed, 20 insertions(+), 22 deletions(-)
Applied to u-boot-dm, take 2, thanks!