[U-Boot] [PATCH v4 0/3] 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(-)

Abstracting dev_get_addr can improve drivers that want to get device's address.
Signed-off-by: Peng Fan Peng.Fan@freescale.com Acked-by: Igor Grinberg grinberg@compulab.co.il --- drivers/core/device.c | 12 ++++++++++++ include/dm/device.h | 10 ++++++++++ 2 files changed, 22 insertions(+)
diff --git a/drivers/core/device.c b/drivers/core/device.c index b73d3b8..73c3e07 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -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 diff --git a/include/dm/device.h b/include/dm/device.h index 81afa8c..7a48eb8 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -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

On 9 February 2015 at 23:46, Peng Fan Peng.Fan@freescale.com wrote:
Abstracting dev_get_addr can improve drivers that want to get device's address.
Signed-off-by: Peng Fan Peng.Fan@freescale.com Acked-by: Igor Grinberg grinberg@compulab.co.il
drivers/core/device.c | 12 ++++++++++++ include/dm/device.h | 10 ++++++++++ 2 files changed, 22 insertions(+)
Acked-by: Simon Glass sjg@chromium.org

On 10 February 2015 at 17:37, Simon Glass sjg@chromium.org wrote:
On 9 February 2015 at 23:46, Peng Fan Peng.Fan@freescale.com wrote:
Abstracting dev_get_addr can improve drivers that want to get device's address.
Signed-off-by: Peng Fan Peng.Fan@freescale.com Acked-by: Igor Grinberg grinberg@compulab.co.il
drivers/core/device.c | 12 ++++++++++++ include/dm/device.h | 10 ++++++++++ 2 files changed, 22 insertions(+)
Acked-by: Simon Glass sjg@chromium.org
Applied to u-boot-dm, thanks!

Add 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`.
Signed-off-by: Peng Fan Peng.Fan@freescale.com Acked-by: Igor Grinberg grinberg@compulab.co.il --- drivers/gpio/mxc_gpio.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c index 8bb9e39..c52dd19 100644 --- a/drivers/gpio/mxc_gpio.c +++ b/drivers/gpio/mxc_gpio.c @@ -23,6 +23,7 @@ enum mxc_gpio_direction { #define GPIO_PER_BANK 32
struct 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)

On 9 February 2015 at 23:46, Peng Fan Peng.Fan@freescale.com wrote:
Add 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`.
Signed-off-by: Peng Fan Peng.Fan@freescale.com Acked-by: Igor Grinberg grinberg@compulab.co.il
Acked-by: Simon Glass sjg@chromium.org

On 10 February 2015 at 17:37, Simon Glass sjg@chromium.org wrote:
On 9 February 2015 at 23:46, Peng Fan Peng.Fan@freescale.com wrote:
Add 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`.
Signed-off-by: Peng Fan Peng.Fan@freescale.com Acked-by: Igor Grinberg grinberg@compulab.co.il
Acked-by: Simon Glass sjg@chromium.org
Applied to u-boot-dm, thanks!

This 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.
Signed-off-by: Peng Fan Peng.Fan@freescale.com --- drivers/gpio/mxc_gpio.c | 81 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 17 deletions(-)
diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c index c52dd19..815407b 100644 --- a/drivers/gpio/mxc_gpio.c +++ b/drivers/gpio/mxc_gpio.c @@ -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

On 02/10/15 08:46, Peng Fan wrote:
This patch add DT support for mxc gpio driver.
There are one place using CONFIG_OF_CONTROL macro.
- 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:
- with DM, without DT
- with DM and DT
- 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.
Signed-off-by: Peng Fan Peng.Fan@freescale.com
Acked-by: Igor Grinberg grinberg@compulab.co.il

On 10 February 2015 at 00:46, Igor Grinberg grinberg@compulab.co.il wrote:
On 02/10/15 08:46, Peng Fan wrote:
This patch add DT support for mxc gpio driver.
There are one place using CONFIG_OF_CONTROL macro.
- 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:
- with DM, without DT
- with DM and DT
- 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.
Signed-off-by: Peng Fan Peng.Fan@freescale.com
Acked-by: Igor Grinberg grinberg@compulab.co.il
Acked-by: Simon Glass sjg@chromium.org

On 10 February 2015 at 17:37, Simon Glass sjg@chromium.org wrote:
On 10 February 2015 at 00:46, Igor Grinberg grinberg@compulab.co.il wrote:
On 02/10/15 08:46, Peng Fan wrote:
This patch add DT support for mxc gpio driver.
There are one place using CONFIG_OF_CONTROL macro.
- 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:
- with DM, without DT
- with DM and DT
- 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.
Signed-off-by: Peng Fan Peng.Fan@freescale.com
Acked-by: Igor Grinberg grinberg@compulab.co.il
Acked-by: Simon Glass sjg@chromium.org
Applied to u-boot-dm, thanks!
participants (3)
-
Igor Grinberg
-
Peng Fan
-
Simon Glass