dm:gpio:mxc add DT support
Subsystems (2)
v4 cover dm:gpio:mxc add DT support
This patch set is to add DT support for mxc_gpio driver.
patch 1/3, a new dev_get_addr interface is abstracted to
improve driver who want to get device address.
patch 2/3, add a new bank_index entry in platdata to avoid plat - mxc_plat
pointer subtract usage.
patch 3/3, add compatible ids and implement bind function. Also commented
out U_BOOT_DEVICES and mxc_plat, since they are not needed if using DT.
This patch set was tested on mx6sxsabresd board with DM and DT support.
Changes v4:
1. add Igor's Acked-by for patch 1/3 and 2/3
2. According Simon's suggestion, using fdt_addr_t as the return type of dev_get_addr.
3. Merge the 1/4 and 2/4 of v3 into 1/3 of v4. Acording Ignor's advice, there is no need to split prototype into a single patch.
4. To patch 3/3, address Simon's comments, add TODO to using auto-alloc feature, add comments, fix return value.
5. rebase on dm/master branch
Changes v3:
1. split bank_index patch
2. abstract dev_get_addr for driver
Changes v2:
1. remove uneccessary #ifdef
2. add more stuff in commit log
3. include a new function mxc_get_gpio_addr to get register base. This function is different for DT and not DT, by #ifdef. If using one implementation for DT and not DT, final image will be big.
4. include a new entry in platdata, named bank_index. it can simplify DT support. To no DT, bank_index is static initilized; to DT, bank_index is get from device's req_seq.
Peng Fan (3):
dm: introduce dev_get_addr interface
dm:gpio:mxc add a bank_index entry in platdata
dm:gpio:mxc add DT support
drivers/core/device.c | 12 +++++++ drivers/gpio/mxc_gpio.c | 89 +++++++++++++++++++++++++++++++++++++++---------- include/dm/device.h | 10 ++++++ 3 files changed, 93 insertions(+), 18 deletions(-)
Signature · 1 line
1.8.4
PATCH v4 1/3 dm: introduce dev_get_addr interface
Abstracting dev_get_addr can improve drivers that want to get device's address.
--- drivers/core/device.c | 12 ++++++++++++ include/dm/device.h | 10 ++++++++++ 2 files changed, 22 insertions(+)
drivers/core/device.c +12 -0
@@ -449,3 +449,15 @@ enum uclass_id device_get_uclass_id(struct udevice *dev) {return dev->uclass->uc_drv->id; } + +#ifdef CONFIG_OF_CONTROL +fdt_addr_t dev_get_addr (struct udevice *dev) +{ +return fdtdec_get_addr (gd->fdt_blob, dev->of_offset,"reg" ); +} +#else +fdt_addr_t dev_get_addr (struct udevice *dev) +{ +return FDT_ADDR_T_NONE ; +} +#endif
include/dm/device.h +10 -0
@@ -12,6 +12,7 @@#define _DM_DEVICE_H#include <dm/uclass-id.h> +#include <fdtdec.h> #include <linker_lists.h> #include <linux/list.h>
@@ -351,4 +352,13 @@ int device_find_first_child(struct udevice *parent, struct udevice **devp);*/ int device_find_next_child (struct udevice **devp); +/** +* dev_get_addr() - Get the reg property of a device +* +* @dev: Pointer to a device +* +* @return addr +*/ +fdt_addr_t dev_get_addr (struct udevice *dev); +#endif
Signature · 1 line
1.8.4
PATCH v4 1/3 dm: introduce dev_get_addr interface
Quoted 9 lines · Peng Fan
Abstracting
dev_get_addrcan improve drivers that want to get device's address.Signed-off-by Peng Fan <[email protected]>Acked-by Igor Grinberg <[email protected]>--- drivers/core/device.c | 12 ++++++++++++ include/dm/device.h | 10 ++++++++++ 2 files changed, 22 insertions(+)
PATCH v4 1/3 dm: introduce dev_get_addr interface
Quoted 4 lines · Simon Glass
Quoted 3 lines · Peng Fan
Abstracting
dev_get_addrcan improve drivers that want to get device's address.
Quoted 8 lines
Quoted 6 lines
Signed-off-by Peng Fan <[email protected]>Acked-by Igor Grinberg <[email protected]>--- drivers/core/device.c | 12 ++++++++++++ include/dm/device.h | 10 ++++++++++ 2 files changed, 22 insertions(+)Acked-by Simon Glass <[email protected]>
Applied to u-boot-dm, thanks!
PATCH v4 2/3 dm:gpio:mxc add a bank_index entry in platdata
In reply to Peng FanAdd a new entry in platdata structure and intialize bank_index in mxc_plat array.
This new entry can avoid using plat - mxc_plat by using plat->bank_index.
--- drivers/gpio/mxc_gpio.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/gpio/mxc_gpio.c +9 -8
@@ -23,6 +23,7 @@ enum mxc_gpio_direction {#define GPIO_PER_BANK 32struct mxc_gpio_plat { +int bank_index;struct gpio_regs *regs; };
@@ -259,19 +260,19 @@ static const struct dm_gpio_ops gpio_mxc_ops = { };static const struct mxc_gpio_plat mxc_plat[] = { - { (struct gpio_regs *)GPIO1_BASE_ADDR }, - { (struct gpio_regs *)GPIO2_BASE_ADDR }, - { (struct gpio_regs *)GPIO3_BASE_ADDR }, + {0 , (struct gpio_regs *)GPIO1_BASE_ADDR }, + {1 , (struct gpio_regs *)GPIO2_BASE_ADDR }, + {2 , (struct gpio_regs *)GPIO3_BASE_ADDR }, #if defined(CONFIG_MX25) || defined(CONFIG_MX27) || defined(CONFIG_MX51) || \ defined(CONFIG_MX53) || defined(CONFIG_MX6) - { (struct gpio_regs *)GPIO4_BASE_ADDR }, + {3 , (struct gpio_regs *)GPIO4_BASE_ADDR }, #endif #if defined(CONFIG_MX27) || defined(CONFIG_MX53) || defined(CONFIG_MX6) - { (struct gpio_regs *)GPIO5_BASE_ADDR }, - { (struct gpio_regs *)GPIO6_BASE_ADDR }, + {4 , (struct gpio_regs *)GPIO5_BASE_ADDR }, + {5 , (struct gpio_regs *)GPIO6_BASE_ADDR }, #endif #if defined(CONFIG_MX53) || defined(CONFIG_MX6) - { (struct gpio_regs *)GPIO7_BASE_ADDR }, + {6 , (struct gpio_regs *)GPIO7_BASE_ADDR }, #endif };
@@ -283,7 +284,7 @@ static int mxc_gpio_probe(struct udevice *dev)int banknum;char name[18 ], *str; - banknum = plat - mxc_plat; + banknum = plat->bank_index;sprintf (name,"GPIO%d_" , banknum +1 ); str =strdup (name);if (!str)
Signature · 1 line
1.8.4
PATCH v4 2/3 dm:gpio:mxc add a bank_index entry in platdata
Quoted 7 lines · Peng Fan
Add a new entry in platdata structure and intialize
bank_indexinmxc_platarray.
This new entry can avoid usingplat - mxc_platby usingplat->bank_index.Signed-off-by Peng Fan <[email protected]>Acked-by Igor Grinberg <[email protected]>
PATCH v4 2/3 dm:gpio:mxc add a bank_index entry in platdata
Quoted 10 lines · Simon Glass
Quoted 7 lines · Peng Fan
Add a new entry in platdata structure and intialize
bank_indexinmxc_platarray.
This new entry can avoid usingplat - mxc_platby usingplat->bank_index.Signed-off-by Peng Fan <[email protected]>Acked-by Igor Grinberg <[email protected]>Acked-by Simon Glass <[email protected]>
Applied to u-boot-dm, thanks!
PATCH v4 3/3 dm:gpio:mxc add DT support
In reply to Peng FanThis patch add DT support for mxc gpio driver.
There are one place using CONFIG_OF_CONTROL macro.
1. The U_BOOT_DEVICES and mxc_plat array are complied out. To DT, platdata is alloced using calloc, so there is no need to use mxc_plat.
The following situations are tested, and all work fine:
1. with DM, without DT
2. with DM and DT
3. without DM
Since device tree has not been upstreamed, if want to test this patch. The followings need to be done.
+ pieces of code does not gpio_request when using gpio_direction_xxx and etc, need to request gpio.
+ move the gpio settings from board_early_init_f to board_init
+ define CONFIG_DM ,CONFIG_DM_GPIO and CONFIG_OF_CONTROL
+ Add device tree file and do related configuration in
make ARCH=arm menuconfig
These will be done in future patches by step.
--- drivers/gpio/mxc_gpio.c | 81 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 17 deletions(-)
drivers/gpio/mxc_gpio.c +64 -17
@@ -151,6 +151,9 @@ int gpio_direction_output(unsigned gpio, int value)#endif #ifdef CONFIG_DM_GPIO +#include <fdtdec.h> +DECLARE_GLOBAL_DATA_PTR ; +static int mxc_gpio_is_output (struct gpio_regs *regs,int offset) {u32 val;
@@ -259,23 +262,6 @@ static const struct dm_gpio_ops gpio_mxc_ops = { .get_function = mxc_gpio_get_function, }; -static const struct mxc_gpio_plat mxc_plat[] = { - {0 , (struct gpio_regs *)GPIO1_BASE_ADDR }, - {1 , (struct gpio_regs *)GPIO2_BASE_ADDR }, - {2 , (struct gpio_regs *)GPIO3_BASE_ADDR }, -#if defined(CONFIG_MX25) || defined(CONFIG_MX27) || defined(CONFIG_MX51) || \ - defined(CONFIG_MX53) || defined(CONFIG_MX6) - {3 , (struct gpio_regs *)GPIO4_BASE_ADDR }, -#endif -#if defined(CONFIG_MX27) || defined(CONFIG_MX53) || defined(CONFIG_MX6) - {4 , (struct gpio_regs *)GPIO5_BASE_ADDR }, - {5 , (struct gpio_regs *)GPIO6_BASE_ADDR }, -#endif -#if defined(CONFIG_MX53) || defined(CONFIG_MX6) - {6 , (struct gpio_regs *)GPIO7_BASE_ADDR }, -#endif -}; -static int mxc_gpio_probe (struct udevice *dev) {struct mxc_bank_info *bank =dev_get_priv (dev);
@@ -296,12 +282,72 @@ static int mxc_gpio_probe(struct udevice *dev)return 0 ; } +static int mxc_gpio_bind (struct udevice *dev) +{ +struct mxc_gpio_plat *plat = dev->platdata; +fdt_addr_t addr; + +/* +* If platdata already exsits, directly return. +* Actually only when DT is not supported, platdata +* is statically initialized in U_BOOT_DEVICES.Here +* will return. +*/ +if (plat) +return 0 ; + + addr =dev_get_addr (dev); +if (addr ==FDT_ADDR_T_NONE ) +return -ENODEV ; + +/* +* TODO: +* When every board is converted to driver model and DT is supported, +* this can be done by auto-alloc feature, but not using calloc +* to alloc memory for platdata. +*/ + plat =calloc (1 ,sizeof (*plat)); +if (!plat) +return -ENOMEM ; + + plat->regs = (struct gpio_regs *)addr; + plat->bank_index = dev->req_seq; + dev->platdata = plat; + +return 0 ; +} + +static const struct udevice_id mxc_gpio_ids[] = { + { .compatible ="fsl,imx35-gpio" }, + { } +}; +U_BOOT_DRIVER (gpio_mxc) = { .name ="gpio_mxc" , .id =UCLASS_GPIO , .ops = &gpio_mxc_ops, .probe = mxc_gpio_probe, .priv_auto_alloc_size =sizeof (struct mxc_bank_info ), + .of_match = mxc_gpio_ids, + .bind = mxc_gpio_bind, +}; + +#ifndef CONFIG_OF_CONTROL +static const struct mxc_gpio_plat mxc_plat[] = { + {0 , (struct gpio_regs *)GPIO1_BASE_ADDR }, + {1 , (struct gpio_regs *)GPIO2_BASE_ADDR }, + {2 , (struct gpio_regs *)GPIO3_BASE_ADDR }, +#if defined(CONFIG_MX25) || defined(CONFIG_MX27) || defined(CONFIG_MX51) || \ + defined(CONFIG_MX53) || defined(CONFIG_MX6) + {3 , (struct gpio_regs *)GPIO4_BASE_ADDR }, +#endif +#if defined(CONFIG_MX27) || defined(CONFIG_MX53) || defined(CONFIG_MX6) + {4 , (struct gpio_regs *)GPIO5_BASE_ADDR }, + {5 , (struct gpio_regs *)GPIO6_BASE_ADDR }, +#endif +#if defined(CONFIG_MX53) || defined(CONFIG_MX6) + {6 , (struct gpio_regs *)GPIO7_BASE_ADDR }, +#endif }; U_BOOT_DEVICES(mxc_gpios) = {
@@ -321,3 +367,4 @@ U_BOOT_DEVICES(mxc_gpios) = {#endif };#endif +#endif
Signature · 1 line
1.8.4
PATCH v4 3/3 dm:gpio:mxc add DT support
Quoted 20 lines · Peng Fan
This patch add DT support for mxc gpio driver.
There are one place using
CONFIG_OF_CONTROLmacro.
1. TheU_BOOT_DEVICESandmxc_platarray are complied out. To DT, platdata is alloced using calloc, so there is no need to usemxc_plat.The following situations are tested, and all work fine:
1. with DM, without DT
2. with DM and DT
3. without DM
Since device tree has not been upstreamed, if want to test this patch. The followings need to be done.
+ pieces of code does notgpio_requestwhen usinggpio_direction_xxxand etc, need to request gpio.
+ move the gpio settings fromboard_early_init_ftoboard_init
+ defineCONFIG_DM,CONFIG_DM_GPIO andCONFIG_OF_CONTROL
+ Add device tree file and do related configuration in
make ARCH=arm menuconfig
These will be done in future patches by step.
Quoted 1 line
Signed-off-by Peng Fan <[email protected]>
Signature · 2 lines
Regards, Igor.
PATCH v4 3/3 dm:gpio:mxc add DT support
Quoted 21 lines · Igor Grinberg
Quoted 20 lines · Peng Fan
This patch add DT support for mxc gpio driver.
There are one place using
CONFIG_OF_CONTROLmacro.
1. TheU_BOOT_DEVICESandmxc_platarray are complied out. To DT, platdata is alloced using calloc, so there is no need to usemxc_plat.The following situations are tested, and all work fine:
1. with DM, without DT
2. with DM and DT
3. without DM
Since device tree has not been upstreamed, if want to test this patch. The followings need to be done.
+ pieces of code does notgpio_requestwhen usinggpio_direction_xxxand etc, need to request gpio.
+ move the gpio settings fromboard_early_init_ftoboard_init
+ defineCONFIG_DM,CONFIG_DM_GPIO andCONFIG_OF_CONTROL
+ Add device tree file and do related configuration in
make ARCH=arm menuconfig
These will be done in future patches by step.
Quoted 3 lines
Quoted 1 line
Signed-off-by Peng Fan <[email protected]>Acked-by Igor Grinberg <[email protected]>
PATCH v4 3/3 dm:gpio:mxc add DT support
Quoted 22 lines · Simon Glass
Quoted 21 lines · Igor Grinberg
Quoted 20 lines · Peng Fan
This patch add DT support for mxc gpio driver.
There are one place using
CONFIG_OF_CONTROLmacro.
1. TheU_BOOT_DEVICESandmxc_platarray are complied out. To DT, platdata is alloced using calloc, so there is no need to usemxc_plat.The following situations are tested, and all work fine:
1. with DM, without DT
2. with DM and DT
3. without DM
Since device tree has not been upstreamed, if want to test this patch. The followings need to be done.
+ pieces of code does notgpio_requestwhen usinggpio_direction_xxxand etc, need to request gpio.
+ move the gpio settings fromboard_early_init_ftoboard_init
+ defineCONFIG_DM,CONFIG_DM_GPIO andCONFIG_OF_CONTROL
+ Add device tree file and do related configuration in
make ARCH=arm menuconfig
These will be done in future patches by step.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Peng Fan <[email protected]>Acked-by Igor Grinberg <[email protected]>Acked-by Simon Glass <[email protected]>
Applied to u-boot-dm, thanks!