diff options
author | Tom Rini <trini@konsulko.com> | 2020-07-29 21:16:08 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-07-29 21:16:08 -0400 |
commit | 719f42190d5f0238cb01ef2ffba8af2285f7bc7a (patch) | |
tree | c789716a82ab552e0d0c1a9242fda7c41b04c238 /drivers | |
parent | 7cb2060b4e63a89c50739dc8a9fcd5d73f86f0be (diff) | |
parent | b9390ce51cb46f4b4acda320e7ea8e0bd120e4b8 (diff) |
Merge tag 'dm-pull-28jul20' of git://git.denx.de/u-boot-dm
Use binman instead of one of the Rockchip build scripts
Refactor to allow any arch to create SPI-flash images
New button uclass
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/Kconfig | 2 | ||||
-rw-r--r-- | drivers/Makefile | 1 | ||||
-rw-r--r-- | drivers/button/Kconfig | 21 | ||||
-rw-r--r-- | drivers/button/Makefile | 6 | ||||
-rw-r--r-- | drivers/button/button-gpio.c | 112 | ||||
-rw-r--r-- | drivers/button/button-uclass.c | 43 | ||||
-rw-r--r-- | drivers/gpio/mxs_gpio.c | 10 | ||||
-rw-r--r-- | drivers/mmc/mxsmmc.c | 10 | ||||
-rw-r--r-- | drivers/spi/mxs_spi.c | 10 |
9 files changed, 191 insertions, 24 deletions
diff --git a/drivers/Kconfig b/drivers/Kconfig index 7a839fa1aa..119e412849 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -16,6 +16,8 @@ source "drivers/block/Kconfig" source "drivers/bootcount/Kconfig" +source "drivers/button/Kconfig" + source "drivers/cache/Kconfig" source "drivers/clk/Kconfig" diff --git a/drivers/Makefile b/drivers/Makefile index afd159e903..2178871bfb 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0+ +obj-$(CONFIG_$(SPL_TPL_)BUTTON) += button/ obj-$(CONFIG_$(SPL_TPL_)CACHE) += cache/ obj-$(CONFIG_$(SPL_TPL_)CLK) += clk/ obj-$(CONFIG_$(SPL_TPL_)DM) += core/ diff --git a/drivers/button/Kconfig b/drivers/button/Kconfig new file mode 100644 index 0000000000..6b3ec7e55d --- /dev/null +++ b/drivers/button/Kconfig @@ -0,0 +1,21 @@ +menu "Button Support" + +config BUTTON + bool "Enable button support" + depends on DM + help + Many boards have buttons which can be used to change behaviour (reset, ...). + U-Boot provides a uclass API to implement this feature. Button drivers + can provide access to board-specific buttons. Use of the device tree + for configuration is encouraged. + +config BUTTON_GPIO + bool "Button gpio" + depends on BUTTON + help + Enable support for buttons which are connected to GPIO lines. These + GPIOs may be on the SoC or some other device which provides GPIOs. + The GPIO driver must used driver model. Buttons are configured using + the device tree. + +endmenu diff --git a/drivers/button/Makefile b/drivers/button/Makefile new file mode 100644 index 0000000000..fcc10ebe8d --- /dev/null +++ b/drivers/button/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com> + +obj-$(CONFIG_BUTTON) += button-uclass.o +obj-$(CONFIG_BUTTON_GPIO) += button-gpio.o diff --git a/drivers/button/button-gpio.c b/drivers/button/button-gpio.c new file mode 100644 index 0000000000..985ae7f5a7 --- /dev/null +++ b/drivers/button/button-gpio.c @@ -0,0 +1,112 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com> + */ + +#include <common.h> +#include <button.h> +#include <dm.h> +#include <dm/lists.h> +#include <dm/uclass-internal.h> +#include <log.h> +#include <asm/gpio.h> + +struct button_gpio_priv { + struct gpio_desc gpio; +}; + +static enum button_state_t button_gpio_get_state(struct udevice *dev) +{ + struct button_gpio_priv *priv = dev_get_priv(dev); + int ret; + + if (!dm_gpio_is_valid(&priv->gpio)) + return -EREMOTEIO; + ret = dm_gpio_get_value(&priv->gpio); + if (ret < 0) + return ret; + + return ret ? BUTTON_ON : BUTTON_OFF; +} + +static int button_gpio_probe(struct udevice *dev) +{ + struct button_uc_plat *uc_plat = dev_get_uclass_platdata(dev); + struct button_gpio_priv *priv = dev_get_priv(dev); + int ret; + + /* Ignore the top-level button node */ + if (!uc_plat->label) + return 0; + + ret = gpio_request_by_name(dev, "gpios", 0, &priv->gpio, GPIOD_IS_IN); + if (ret) + return ret; + + return 0; +} + +static int button_gpio_remove(struct udevice *dev) +{ + /* + * The GPIO driver may have already been removed. We will need to + * address this more generally. + */ + if (!IS_ENABLED(CONFIG_SANDBOX)) { + struct button_gpio_priv *priv = dev_get_priv(dev); + + if (dm_gpio_is_valid(&priv->gpio)) + dm_gpio_free(dev, &priv->gpio); + } + + return 0; +} + +static int button_gpio_bind(struct udevice *parent) +{ + struct udevice *dev; + ofnode node; + int ret; + + dev_for_each_subnode(node, parent) { + struct button_uc_plat *uc_plat; + const char *label; + + label = ofnode_read_string(node, "label"); + if (!label) { + debug("%s: node %s has no label\n", __func__, + ofnode_get_name(node)); + return -EINVAL; + } + ret = device_bind_driver_to_node(parent, "button_gpio", + ofnode_get_name(node), + node, &dev); + if (ret) + return ret; + uc_plat = dev_get_uclass_platdata(dev); + uc_plat->label = label; + } + + return 0; +} + +static const struct button_ops button_gpio_ops = { + .get_state = button_gpio_get_state, +}; + +static const struct udevice_id button_gpio_ids[] = { + { .compatible = "gpio-keys" }, + { .compatible = "gpio-keys-polled" }, + { } +}; + +U_BOOT_DRIVER(button_gpio) = { + .name = "button_gpio", + .id = UCLASS_BUTTON, + .of_match = button_gpio_ids, + .ops = &button_gpio_ops, + .priv_auto_alloc_size = sizeof(struct button_gpio_priv), + .bind = button_gpio_bind, + .probe = button_gpio_probe, + .remove = button_gpio_remove, +}; diff --git a/drivers/button/button-uclass.c b/drivers/button/button-uclass.c new file mode 100644 index 0000000000..1c742c265c --- /dev/null +++ b/drivers/button/button-uclass.c @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com> + * + * Based on led-uclass.c + */ + +#include <common.h> +#include <button.h> +#include <dm.h> +#include <dm/uclass-internal.h> + +int button_get_by_label(const char *label, struct udevice **devp) +{ + struct udevice *dev; + struct uclass *uc; + + uclass_id_foreach_dev(UCLASS_BUTTON, dev, uc) { + struct button_uc_plat *uc_plat = dev_get_uclass_platdata(dev); + + /* Ignore the top-level button node */ + if (uc_plat->label && !strcmp(label, uc_plat->label)) + return uclass_get_device_tail(dev, 0, devp); + } + + return -ENODEV; +} + +enum button_state_t button_get_state(struct udevice *dev) +{ + struct button_ops *ops = button_get_ops(dev); + + if (!ops->get_state) + return -ENOSYS; + + return ops->get_state(dev); +} + +UCLASS_DRIVER(button) = { + .id = UCLASS_BUTTON, + .name = "button", + .per_device_platdata_auto_alloc_size = sizeof(struct button_uc_plat), +}; diff --git a/drivers/gpio/mxs_gpio.c b/drivers/gpio/mxs_gpio.c index 2c16517e72..aaabb0216b 100644 --- a/drivers/gpio/mxs_gpio.c +++ b/drivers/gpio/mxs_gpio.c @@ -138,12 +138,6 @@ int name_to_gpio(const char *name) #include <asm/arch/gpio.h> #define MXS_MAX_GPIO_PER_BANK 32 -#ifdef CONFIG_MX28 -#define dtd_fsl_imx_gpio dtd_fsl_imx28_gpio -#else /* CONFIG_MX23 */ -#define dtd_fsl_imx_gpio dtd_fsl_imx23_gpio -#endif - DECLARE_GLOBAL_DATA_PTR; /* * According to i.MX28 Reference Manual: @@ -158,7 +152,7 @@ DECLARE_GLOBAL_DATA_PTR; struct mxs_gpio_platdata { #if CONFIG_IS_ENABLED(OF_PLATDATA) - struct dtd_fsl_imx_gpio dtplat; + struct dtd_fsl_imx23_gpio dtplat; #endif unsigned int bank; int gpio_ranges; @@ -247,7 +241,7 @@ static int mxs_gpio_probe(struct udevice *dev) char name[16], *str; #if CONFIG_IS_ENABLED(OF_PLATDATA) - struct dtd_fsl_imx_gpio *dtplat = &plat->dtplat; + struct dtd_fsl_imx23_gpio *dtplat = &plat->dtplat; priv->bank = (unsigned int)dtplat->reg[0]; uc_priv->gpio_count = dtplat->gpio_ranges[3]; #else diff --git a/drivers/mmc/mxsmmc.c b/drivers/mmc/mxsmmc.c index d48050ba8a..2b3a3a992c 100644 --- a/drivers/mmc/mxsmmc.c +++ b/drivers/mmc/mxsmmc.c @@ -52,15 +52,9 @@ struct mxsmmc_priv { #include <dm/read.h> #include <dt-structs.h> -#ifdef CONFIG_MX28 -#define dtd_fsl_imx_mmc dtd_fsl_imx28_mmc -#else /* CONFIG_MX23 */ -#define dtd_fsl_imx_mmc dtd_fsl_imx23_mmc -#endif - struct mxsmmc_platdata { #if CONFIG_IS_ENABLED(OF_PLATDATA) - struct dtd_fsl_imx_mmc dtplat; + struct dtd_fsl_imx23_mmc dtplat; #endif struct mmc_config cfg; struct mmc mmc; @@ -582,7 +576,7 @@ static int mxsmmc_probe(struct udevice *dev) debug("%s: probe\n", __func__); #if CONFIG_IS_ENABLED(OF_PLATDATA) - struct dtd_fsl_imx_mmc *dtplat = &plat->dtplat; + struct dtd_fsl_imx23_mmc *dtplat = &plat->dtplat; struct phandle_1_arg *p1a = &dtplat->clocks[0]; priv->buswidth = dtplat->bus_width; diff --git a/drivers/spi/mxs_spi.c b/drivers/spi/mxs_spi.c index 3c1af839c0..fb0af02be0 100644 --- a/drivers/spi/mxs_spi.c +++ b/drivers/spi/mxs_spi.c @@ -41,15 +41,9 @@ #define MXS_SSP_IMX23_CLKID_SSP0 33 #define MXS_SSP_IMX28_CLKID_SSP0 46 -#ifdef CONFIG_MX28 -#define dtd_fsl_imx_spi dtd_fsl_imx28_spi -#else /* CONFIG_MX23 */ -#define dtd_fsl_imx_spi dtd_fsl_imx23_spi -#endif - struct mxs_spi_platdata { #if CONFIG_IS_ENABLED(OF_PLATDATA) - struct dtd_fsl_imx_spi dtplat; + struct dtd_fsl_imx23_spi dtplat; #endif s32 frequency; /* Default clock frequency, -1 for none */ fdt_addr_t base; /* SPI IP block base address */ @@ -324,7 +318,7 @@ static int mxs_spi_probe(struct udevice *bus) debug("%s: probe\n", __func__); #if CONFIG_IS_ENABLED(OF_PLATDATA) - struct dtd_fsl_imx_spi *dtplat = &plat->dtplat; + struct dtd_fsl_imx23_spi *dtplat = &plat->dtplat; struct phandle_1_arg *p1a = &dtplat->clocks[0]; priv->regs = (struct mxs_ssp_regs *)dtplat->reg[0]; |