X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Fgpio%2Fomap_gpio.c;h=651f6994e41a6a609add5c9eb82964212ae2b576;hb=1703fbefd9183fffd76f4744a73f5ca9daef6313;hp=cd960dc013f0f128be8d625aab83996e3863eb65;hpb=826d06dbdd0e29ab0d8bd76d1ca640e2dfdb076c;p=u-boot diff --git a/drivers/gpio/omap_gpio.c b/drivers/gpio/omap_gpio.c index cd960dc013..651f6994e4 100644 --- a/drivers/gpio/omap_gpio.c +++ b/drivers/gpio/omap_gpio.c @@ -1,9 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2009 Wind River Systems, Inc. * Tom Rix * - * SPDX-License-Identifier: GPL-2.0 - * * This work is derived from the linux 2.6.27 kernel source * To fetch, use the kernel repository * git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git @@ -23,7 +22,7 @@ #include #include #include -#include +#include #include DECLARE_GLOBAL_DATA_PTR; @@ -289,42 +288,54 @@ static int omap_gpio_probe(struct udevice *dev) struct gpio_bank *bank = dev_get_priv(dev); struct omap_gpio_platdata *plat = dev_get_platdata(dev); struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); + int banknum; + char name[18], *str; - uc_priv->bank_name = plat->port_name; + banknum = plat->bank_index; + sprintf(name, "GPIO%d_", banknum + 1); + str = strdup(name); + if (!str) + return -ENOMEM; + uc_priv->bank_name = str; uc_priv->gpio_count = GPIO_PER_BANK; bank->base = (void *)plat->base; - return 0; } +#if !CONFIG_IS_ENABLED(OF_CONTROL) static int omap_gpio_bind(struct udevice *dev) { - struct omap_gpio_platdata *plat = dev->platdata; + struct omap_gpio_platdata *plat = dev_get_platdata(dev); fdt_addr_t base_addr; if (plat) return 0; - base_addr = dev_get_addr(dev); + base_addr = devfdt_get_addr(dev); if (base_addr == FDT_ADDR_T_NONE) - return -ENODEV; + return -EINVAL; /* * 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. + * + * For example am33xx_gpio uses platform data rather than device tree. + * + * NOTE: DO NOT COPY this code if you are using device tree. */ plat = calloc(1, sizeof(*plat)); if (!plat) return -ENOMEM; plat->base = base_addr; - plat->port_name = fdt_get_name(gd->fdt_blob, dev->of_offset, NULL); + plat->port_name = fdt_get_name(gd->fdt_blob, dev_of_offset(dev), NULL); dev->platdata = plat; return 0; } +#endif static const struct udevice_id omap_gpio_ids[] = { { .compatible = "ti,omap3-gpio" }, @@ -333,14 +344,36 @@ static const struct udevice_id omap_gpio_ids[] = { { } }; +#if CONFIG_IS_ENABLED(OF_CONTROL) +static int omap_gpio_ofdata_to_platdata(struct udevice *dev) +{ + struct omap_gpio_platdata *plat = dev_get_platdata(dev); + fdt_addr_t addr; + + addr = devfdt_get_addr(dev); + if (addr == FDT_ADDR_T_NONE) + return -EINVAL; + + plat->base = addr; + return 0; +} +#endif + U_BOOT_DRIVER(gpio_omap) = { .name = "gpio_omap", .id = UCLASS_GPIO, +#if CONFIG_IS_ENABLED(OF_CONTROL) + .ofdata_to_platdata = of_match_ptr(omap_gpio_ofdata_to_platdata), + .bind = dm_scan_fdt_dev, + .platdata_auto_alloc_size = sizeof(struct omap_gpio_platdata), +#else + .bind = omap_gpio_bind, +#endif .ops = &gpio_omap_ops, .of_match = omap_gpio_ids, - .bind = omap_gpio_bind, .probe = omap_gpio_probe, .priv_auto_alloc_size = sizeof(struct gpio_bank), + .flags = DM_FLAG_PRE_RELOC, }; #endif /* CONFIG_DM_GPIO */