continue;
}
+#ifdef CONFIG_DM_ETH
+ priv = dev_get_priv(dev);
+#else
priv = dev->priv;
+#endif
if (priv->flags & TSEC_SGMII)
continue;
#ifdef CONFIG_SPL_BUILD
+/* Define board data structure */
+static struct bd_info bdata __attribute__ ((section(".data")));
+
void spl_board_init(void)
{
#if defined(CONFIG_NXP_ESBC) && defined(CONFIG_FSL_LSCH2)
get_clocks();
preloader_console_init();
- spl_set_bd();
+ gd->bd = &bdata;
#ifdef CONFIG_SYS_I2C
#ifdef CONFIG_SPL_I2C_SUPPORT
int ret;
ret = uclass_get_device_by_driver(UCLASS_IRQ,
- DM_GET_DRIVER(arm_gic_v3_its), &dev);
+ DM_DRIVER_GET(arm_gic_v3_its), &dev);
if (ret) {
pr_err("%s: failed to get %s irq device\n", __func__,
- DM_GET_DRIVER(arm_gic_v3_its)->name);
+ DM_DRIVER_GET(arm_gic_v3_its)->name);
return ret;
}
int ret;
ret = uclass_get_device_by_driver(UCLASS_SYSCON,
- DM_GET_DRIVER(gic_lpi_syscon), &dev);
+ DM_DRIVER_GET(gic_lpi_syscon), &dev);
if (ret) {
pr_err("%s: failed to get %s syscon device\n", __func__,
- DM_GET_DRIVER(gic_lpi_syscon)->name);
+ DM_DRIVER_GET(gic_lpi_syscon)->name);
return ret;
}
regmap = syscon_get_regmap(dev);
if (!regmap) {
pr_err("%s: failed to regmap for %s syscon device\n", __func__,
- DM_GET_DRIVER(gic_lpi_syscon)->name);
+ DM_DRIVER_GET(gic_lpi_syscon)->name);
return -ENODEV;
}
priv->lpi_base = regmap->ranges[0].start;
int ast_get_clk(struct udevice **devp)
{
return uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(aspeed_ast2500_scu), devp);
+ DM_DRIVER_GET(aspeed_ast2500_scu), devp);
}
void *ast_get_scu(void)
{ ATMEL_BASE_PIOC, "PC" },
};
-U_BOOT_DEVICES(at91sam9260_gpios) = {
+U_BOOT_DRVINFOS(at91sam9260_gpios) = {
{ "atmel_at91rm9200_gpio", &at91sam9260_plat[0] },
{ "atmel_at91rm9200_gpio", &at91sam9260_plat[1] },
{ "atmel_at91rm9200_gpio", &at91sam9260_plat[2] },
{ ATMEL_BASE_PIOE, "PE" },
};
-U_BOOT_DEVICES(at91sam9260_gpios) = {
+U_BOOT_DRVINFOS(at91sam9260_gpios) = {
{ "atmel_at91rm9200_gpio", &at91sam9260_plat[0] },
{ "atmel_at91rm9200_gpio", &at91sam9260_plat[1] },
{ "atmel_at91rm9200_gpio", &at91sam9260_plat[2] },
board_gpio_init();
#if !CONFIG_IS_ENABLED(DM_SERIAL)
- NS16550_init((NS16550_t)(CONFIG_SYS_NS16550_COM1),
- CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
+ ns16550_init((struct ns16550 *)(CONFIG_SYS_NS16550_COM1),
+ CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
#endif
/*
* Fix Power and Emulation Management Register
void putc(char c)
{
if (c == '\n')
- NS16550_putc((NS16550_t)(CONFIG_SYS_NS16550_COM1), '\r');
+ ns16550_putc((struct ns16550 *)(CONFIG_SYS_NS16550_COM1), '\r');
- NS16550_putc((NS16550_t)(CONFIG_SYS_NS16550_COM1), c);
+ ns16550_putc((struct ns16550 *)(CONFIG_SYS_NS16550_COM1), c);
}
#endif /* CONFIG_SPL_LIBCOMMON_SUPPORT */
.fuse_word = 6,
};
-U_BOOT_DEVICE(imx6_thermal) = {
+U_BOOT_DRVINFO(imx6_thermal) = {
.name = "imx_thermal",
.plat = &imx6_thermal_plat,
};
.fuse_word = 3,
};
-U_BOOT_DEVICE(imx7_thermal) = {
+U_BOOT_DRVINFO(imx7_thermal) = {
.name = "imx_thermal",
.plat = &imx7_thermal_plat,
};
do_board_detect();
#if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
- ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(k3_avs),
+ ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs),
&dev);
if (ret)
printf("AVS init failed: %d\n", ret);
int ret;
ret = uclass_get_device_by_driver(UCLASS_FIRMWARE,
- DM_GET_DRIVER(ti_sci), &dev);
+ DM_DRIVER_GET(ti_sci), &dev);
if (ret)
panic("Failed to get SYSFW (%d)\n", ret);
do_board_detect();
#if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
- ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(k3_avs),
+ ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs),
&dev);
if (ret)
printf("AVS init failed: %d\n", ret);
* driver doesn't handle this.
*/
#ifndef CONFIG_DM_SERIAL
- NS16550_init((NS16550_t)(CONFIG_SYS_NS16550_COM2),
+ ns16550_init((struct ns16550 *)(CONFIG_SYS_NS16550_COM2),
CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
#endif
};
#endif
-U_BOOT_DEVICES(lpc32xx_uarts) = {
+U_BOOT_DRVINFOS(lpc32xx_uarts) = {
#if defined(CONFIG_LPC32XX_HSUART)
{ "lpc32xx_hsuart", &lpc32xx_hsuart[0], },
{ "lpc32xx_hsuart", &lpc32xx_hsuart[1], },
writel(ctrl, &clk->i2cclk_ctrl);
}
-U_BOOT_DEVICE(lpc32xx_gpios) = {
+U_BOOT_DRVINFO(lpc32xx_gpios) = {
.name = "gpio_lpc32xx"
};
int ret, i;
ret = uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(mtk_clk_apmixedsys), &dev);
+ DM_DRIVER_GET(mtk_clk_apmixedsys), &dev);
if (ret)
return ret;
/* setup mcu bus */
ret = uclass_get_device_by_driver(UCLASS_SYSCON,
- DM_GET_DRIVER(mtk_mcucfg), &dev);
+ DM_DRIVER_GET(mtk_mcucfg), &dev);
if (ret)
return ret;
int ret, i;
ret = uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(mtk_clk_apmixedsys), &dev);
+ DM_DRIVER_GET(mtk_clk_apmixedsys), &dev);
if (ret)
return ret;
# endif
};
-U_BOOT_DEVICES(am33xx_uarts) = {
+U_BOOT_DRVINFOS(am33xx_uarts) = {
{ "ns16550_serial", &am33xx_serial[0] },
# ifdef CONFIG_SYS_NS16550_COM2
{ "ns16550_serial", &am33xx_serial[1] },
{ I2C_BASE3, 100000, OMAP_I2C_REV_V2},
};
-U_BOOT_DEVICES(am33xx_i2c) = {
+U_BOOT_DRVINFOS(am33xx_i2c) = {
{ "i2c_omap", &am33xx_i2c[0] },
{ "i2c_omap", &am33xx_i2c[1] },
{ "i2c_omap", &am33xx_i2c[2] },
#endif
};
-U_BOOT_DEVICES(am33xx_gpios) = {
+U_BOOT_DRVINFOS(am33xx_gpios) = {
{ "gpio_omap", &am33xx_gpio[0] },
{ "gpio_omap", &am33xx_gpio[1] },
{ "gpio_omap", &am33xx_gpio[2] },
.pin_dir = MCSPI_PINDIR_D0_IN_D1_OUT,
};
-U_BOOT_DEVICE(am33xx_spi) = {
+U_BOOT_DRVINFO(am33xx_spi) = {
.name = "omap3_spi",
.plat = &omap3_spi_pdata,
};
},
};
-U_BOOT_DEVICES(am33xx_usbs) = {
+U_BOOT_DRVINFOS(am33xx_usbs) = {
#if CONFIG_AM335X_USB0_MODE == MUSB_PERIPHERAL
{ "ti-musb-peripheral", &usb0 },
#elif CONFIG_AM335X_USB0_MODE == MUSB_HOST
{ 5, OMAP34XX_GPIO6_BASE },
};
-U_BOOT_DEVICES(omap34xx_gpios) = {
+U_BOOT_DRVINFOS(omap34xx_gpios) = {
{ "gpio_omap", &omap34xx_gpio[0] },
{ "gpio_omap", &omap34xx_gpio[1] },
{ "gpio_omap", &omap34xx_gpio[2] },
/* retrieve the device */
#if CONFIG_IS_ENABLED(ROCKCHIP_EFUSE)
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(rockchip_efuse), &dev);
+ DM_DRIVER_GET(rockchip_efuse), &dev);
#elif CONFIG_IS_ENABLED(ROCKCHIP_OTP)
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(rockchip_otp), &dev);
+ DM_DRIVER_GET(rockchip_otp), &dev);
#endif
if (ret) {
debug("%s: could not find efuse device\n", __func__);
int rockchip_get_clk(struct udevice **devp)
{
return uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(rockchip_px30_cru), devp);
+ DM_DRIVER_GET(rockchip_px30_cru), devp);
}
void *rockchip_get_cru(void)
int rockchip_get_clk(struct udevice **devp)
{
return uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(rockchip_rk3036_cru), devp);
+ DM_DRIVER_GET(rockchip_rk3036_cru), devp);
}
void *rockchip_get_cru(void)
int rockchip_get_clk(struct udevice **devp)
{
return uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(rockchip_rk3128_cru), devp);
+ DM_DRIVER_GET(rockchip_rk3128_cru), devp);
}
void *rockchip_get_cru(void)
int rockchip_get_clk(struct udevice **devp)
{
return uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(rockchip_rk3188_cru), devp);
+ DM_DRIVER_GET(rockchip_rk3188_cru), devp);
}
void *rockchip_get_cru(void)
int rockchip_get_clk(struct udevice **devp)
{
return uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(rockchip_rk322x_cru), devp);
+ DM_DRIVER_GET(rockchip_rk322x_cru), devp);
}
void *rockchip_get_cru(void)
int rockchip_get_clk(struct udevice **devp)
{
return uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(rockchip_rk3288_cru), devp);
+ DM_DRIVER_GET(rockchip_rk3288_cru), devp);
}
void *rockchip_get_cru(void)
int rockchip_get_clk(struct udevice **devp)
{
return uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(rockchip_rk3308_cru), devp);
+ DM_DRIVER_GET(rockchip_rk3308_cru), devp);
}
void *rockchip_get_cru(void)
int rockchip_get_clk(struct udevice **devp)
{
return uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(rockchip_rk3328_cru), devp);
+ DM_DRIVER_GET(rockchip_rk3328_cru), devp);
}
void *rockchip_get_cru(void)
int rockchip_get_clk(struct udevice **devp)
{
return uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(rockchip_rk3368_cru), devp);
+ DM_DRIVER_GET(rockchip_rk3368_cru), devp);
}
void *rockchip_get_cru(void)
static int rockchip_get_cruclk(struct udevice **devp)
{
return uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(clk_rk3399), devp);
+ DM_DRIVER_GET(clk_rk3399), devp);
}
void *rockchip_get_cru(void)
static int rockchip_get_pmucruclk(struct udevice **devp)
{
return uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(rockchip_rk3399_pmuclk), devp);
+ DM_DRIVER_GET(rockchip_rk3399_pmuclk), devp);
}
void *rockchip_get_pmucru(void)
int rockchip_get_clk(struct udevice **devp)
{
return uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(clk_rv1108), devp);
+ DM_DRIVER_GET(clk_rv1108), devp);
}
void *rockchip_get_cru(void)
int ret;
ret = uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(socfpga_agilex_clk),
+ DM_DRIVER_GET(socfpga_agilex_clk),
&dev);
if (ret)
return 0;
int ret;
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stm32mp_bsec), &dev);
+ DM_DRIVER_GET(stm32mp_bsec), &dev);
if (ret || !dev) {
pr_debug("bsec driver not available\n");
return false;
int i, ret;
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stm32mp_bsec),
+ DM_DRIVER_GET(stm32mp_bsec),
&dev);
if (ret) {
pr_err("Can't find stm32mp_bsec driver\n");
pr_debug("%s: %x %lx\n", __func__, offset, *size);
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stpmic1_nvm),
+ DM_DRIVER_GET(stpmic1_nvm),
&dev);
if (ret)
return ret;
memset(data->pmic_part, 0, PMIC_SIZE);
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stpmic1_nvm),
+ DM_DRIVER_GET(stpmic1_nvm),
&dev);
if (ret)
return ret;
}
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stpmic1_nvm),
+ DM_DRIVER_GET(stpmic1_nvm),
&dev);
if (ret)
return ret;
u32 otp = 0;
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stm32mp_bsec),
+ DM_DRIVER_GET(stm32mp_bsec),
&dev);
if (!ret)
return 0;
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stm32mp_bsec),
+ DM_DRIVER_GET(stm32mp_bsec),
&dev);
if (ret)
return ret;
return 0;
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stm32mp_bsec),
+ DM_DRIVER_GET(stm32mp_bsec),
&dev);
if (ret)
return ret;
#include <syscon.h>
#include <asm/io.h>
#include <dm/device_compat.h>
+#include <dm/device-internal.h>
#include <linux/bitops.h>
#include <linux/err.h>
#include <power/pmic.h>
{
int children;
- children = pmic_bind_children(dev, dev->node, pwr_children_info);
+ children = pmic_bind_children(dev, dev_ofnode(dev), pwr_children_info);
if (!children)
dev_dbg(dev, "no child found\n");
}
uc_pdata->type = REGULATOR_TYPE_FIXED;
- dev->priv = (void *)*p;
+ dev_set_priv(dev, (void *)*p);
return 0;
}
.fcr = UART_FCR_DEFVAL,
};
-U_BOOT_DEVICE(ns16550_com1) = {
+U_BOOT_DRVINFO(ns16550_com1) = {
"ns16550_serial", &ns16550_com1_pdata
};
#endif
#ifdef CONFIG_SPL_BUILD
-U_BOOT_DEVICE(tegra_gpios) = {
+U_BOOT_DRVINFO(tegra_gpios) = {
"gpio_tegra"
};
#endif
/* The system bus must be initialized for access to the support card. */
ret = uclass_get_device_by_driver(UCLASS_SIMPLE_BUS,
- DM_GET_DRIVER(uniphier_system_bus_driver),
+ DM_DRIVER_GET(uniphier_system_bus_driver),
&dev);
if (ret)
return;
int i, ret;
ret = uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(zynq_clk), &dev);
+ DM_DRIVER_GET(zynq_clk), &dev);
if (ret)
return ret;
int i, ret;
ret = uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(zynq_clk), &dev);
+ DM_DRIVER_GET(zynq_clk), &dev);
if (ret)
return ret;
int ret;
ret = uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(zynq_clk), &dev);
+ DM_DRIVER_GET(zynq_clk), &dev);
if (ret)
return ret;
ddr ? "" : "2", chipmode & 0x01 ? 4 : 3,
chipmode & 0x02 ? "XTAL" : "CPLL");
- ret = uclass_get_device_by_driver(UCLASS_CLK, DM_GET_DRIVER(mt7628_clk),
+ ret = uclass_get_device_by_driver(UCLASS_CLK, DM_DRIVER_GET(mt7628_clk),
&clkdev);
if (ret)
return ret;
struct udevice *dev;
ret = uclass_get_device_by_driver(UCLASS_TIMER,
- DM_GET_DRIVER(sifive_clint), &dev);
+ DM_DRIVER_GET(sifive_clint), &dev);
if (ret)
return ret;
int os_spl_to_uboot(const char *fname)
{
+ struct sandbox_state *state = state_get_current();
+
+ printf("%s\n", __func__);
+ /* U-Boot will delete ram buffer after read: "--rm_memory"*/
+ state->ram_buf_rm = true;
return os_jump_to_file(fname);
}
if (os_parse_args(state, argc, argv))
return 1;
+ /* Remove old memory file if required */
+ if (state->ram_buf_rm && state->ram_buf_fname) {
+ os_unlink(state->ram_buf_fname);
+ state->write_ram_buf = false;
+ state->ram_buf_fname = NULL;
+ }
+
ret = sandbox_read_state(state, state->state_fname);
if (ret)
goto err;
}
}
- /* Remove old memory file if required */
- if (state->ram_buf_rm && state->ram_buf_fname)
- os_unlink(state->ram_buf_fname);
-
/* Delete this at the last moment so as not to upset gdb too much */
if (state->jumped_fname)
os_unlink(state->jumped_fname);
cros_ec: cros-ec {
reg = <0 0>;
- u-boot,dm-pre-reloc;
+ u-boot,dm-pre-proper;
compatible = "google,cros-ec-sandbox";
};
};
spi: spi@0 {
- u-boot,dm-pre-reloc;
+ u-boot,dm-pre-proper;
#address-cells = <1>;
#size-cells = <0>;
reg = <0 0>;
};
gpio_a: gpios@0 {
- u-boot,dm-pre-reloc;
+ u-boot,dm-pre-proper;
gpio-controller;
compatible = "sandbox,gpio";
#gpio-cells = <1>;
};
gpio_b: gpios@1 {
- u-boot,dm-pre-reloc;
+ u-boot,dm-pre-proper;
gpio-controller;
compatible = "sandbox,gpio";
#gpio-cells = <2>;
};
lcd {
- u-boot,dm-pre-reloc;
+ u-boot,dm-pre-proper;
compatible = "sandbox,lcd-sdl";
xres = <1366>;
yres = <768>;
spi@0 {
firmware_storage_spi: flash@0 {
- u-boot,dm-pre-reloc;
+ u-boot,dm-pre-proper;
reg = <0>;
compatible = "spansion,m25p16", "jedec,spi-nor";
spi-max-frequency = <40000000>;
stringarray = "one";
};
- spl-test4 {
- u-boot,dm-pre-reloc;
- compatible = "sandbox,spl-test.2";
- };
-
spl-test5 {
u-boot,dm-tpl;
compatible = "sandbox,spl-test";
};
tpm {
- u-boot,dm-pre-reloc;
compatible = "google,sandbox-tpm";
};
};
keyboard-controller {
- u-boot,dm-pre-reloc;
+ u-boot,dm-pre-proper;
};
};
--- /dev/null
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2020 Google LLC
+ */
+
+#ifndef __asn_i2c_h
+#define __asn_i2c_h
+
+struct sandbox_i2c_priv {
+ bool test_mode;
+};
+
+#endif /* __asn_i2c_h */
--- /dev/null
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2020 Google LLC
+ */
+
+#ifndef __asm_serial_h
+#define __asm_serial_h
+
+#include <dt-structs.h>
+
+struct sandbox_serial_plat {
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+ struct dtd_sandbox_serial dtplat;
+#endif
+ int colour; /* Text colour to use for output, -1 for none */
+};
+
+/**
+ * struct sandbox_serial_priv - Private data for this driver
+ *
+ * @buf: holds input characters available to be read by this driver
+ */
+struct sandbox_serial_priv {
+ struct membuff buf;
+ char serial_buf[16];
+ bool start_of_line;
+};
+
+#endif /* __asm_serial_h */
select SMP_AP_WORK
select INTEL_GMA_SWSMISCI
select ACPI_GNVS_EXTERNAL
+ select TPL_OF_PLATDATA_PARENT
imply ENABLE_MRC_CACHE
imply AHCI_PCI
imply SCSI
node = dev_ofnode(dev);
if (!ofnode_valid(node))
- return log_msg_ret("fsp-m settings", -ENOENT);
+ return log_msg_ret("node", -ENOENT);
+ node = ofnode_find_subnode(node, "fsp-m");
+ if (!ofnode_valid(node))
+ return log_msg_ret("fspm", -ENOENT);
ret = fsp_m_update_config_from_dtb(node, cfg);
if (ret)
#include <asm/io.h>
#include <asm/pci.h>
#include <asm/arch/acpi.h>
+#include <asm/arch/hostbridge.h>
#include <asm/arch/systemagent.h>
#include <dt-bindings/sound/nhlt.h>
#include <dm/acpi.h>
TOLUD = 0xbc,
};
-/**
- * struct apl_hostbridge_plat - platform data for hostbridge
- *
- * @dtplat: Platform data for of-platdata
- * @early_pads: Early pad data to set up, each (pad, cfg0, cfg1)
- * @early_pads_count: Number of pads to process
- * @pciex_region_size: BAR length in bytes
- * @bdf: Bus/device/function of hostbridge
- */
-struct apl_hostbridge_plat {
-#if CONFIG_IS_ENABLED(OF_PLATDATA)
- struct dtd_intel_apl_hostbridge dtplat;
-#endif
- u32 *early_pads;
- int early_pads_count;
- uint pciex_region_size;
- pci_dev_t bdf;
-};
-
+#if CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE)
static const struct nhlt_format_config dmic_1ch_formats[] = {
/* 48 KHz 16-bits per sample. */
{
.num_formats = ARRAY_SIZE(dmic_4ch_formats),
},
};
+#endif
static int apl_hostbridge_early_init_pinctrl(struct udevice *dev)
{
return acpi_copy_name(out_name, "RHUB");
}
-#ifdef CONFIG_GENERATE_ACPI_TABLE
+#if CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE)
static int apl_acpi_hb_write_tables(const struct udevice *dev,
struct acpi_ctx *ctx)
{
return 0;
}
-#endif
static int apl_acpi_setup_nhlt(const struct udevice *dev, struct acpi_ctx *ctx)
{
return log_msg_ret("channels", -EINVAL);
}
+#endif
static int apl_hostbridge_remove(struct udevice *dev)
{
struct acpi_ops apl_hostbridge_acpi_ops = {
.get_name = apl_acpi_hb_get_name,
-#ifdef CONFIG_GENERATE_ACPI_TABLE
+#if CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE)
.write_tables = apl_acpi_hb_write_tables,
-#endif
.setup_nhlt = apl_acpi_setup_nhlt,
+#endif
};
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
static const struct udevice_id apl_hostbridge_ids[] = {
{ .compatible = "intel,apl-hostbridge" },
{ }
};
+#endif
U_BOOT_DRIVER(intel_apl_hostbridge) = {
.name = "intel_apl_hostbridge",
.id = UCLASS_NORTHBRIDGE,
- .of_match = apl_hostbridge_ids,
+ .of_match = of_match_ptr(apl_hostbridge_ids),
.of_to_plat = apl_hostbridge_of_to_plat,
.probe = apl_hostbridge_probe,
.remove = apl_hostbridge_remove,
lgir_reg_num = find_unused_pmio_window();
if (lgir_reg_num < 0) {
- log_err("LPC: Cannot open IO window: %lx size %lx\n",
- bridge_base, size - bridged_size);
- log_err("No more IO windows\n");
-
+ if (spl_phase() > PHASE_TPL) {
+ log_err("LPC: Cannot open IO window: %lx size %lx\n",
+ bridge_base, size - bridged_size);
+ log_err("No more IO windows\n");
+ }
return -ENOSPC;
}
lgir_reg_offset = LPC_GENERIC_IO_RANGE(lgir_reg_num);
.inject_dsdt = southbridge_inject_dsdt,
};
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
static const struct udevice_id apl_lpc_ids[] = {
{ .compatible = "intel,apl-lpc" },
{ }
};
+#endif
/* All pads are LPC already configured by the hostbridge, so no probing here */
U_BOOT_DRIVER(intel_apl_lpc) = {
.name = "intel_apl_lpc",
.id = UCLASS_LPC,
- .of_match = apl_lpc_ids,
+ .of_match = of_match_ptr(apl_lpc_ids),
ACPI_OPS_PTR(&apl_lpc_acpi_ops)
};
.set_spi_protect = apl_set_spi_protect,
};
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
static const struct udevice_id apl_pch_ids[] = {
{ .compatible = "intel,apl-pch" },
{ }
};
+#endif
U_BOOT_DRIVER(intel_apl_pch) = {
.name = "intel_apl_pch",
.id = UCLASS_PCH,
- .of_match = apl_pch_ids,
+ .of_match = of_match_ptr(apl_pch_ids),
.ops = &apl_pch_ops,
};
#include <acpi/acpi_s3.h>
#include <asm/io.h>
#include <asm/pci.h>
+#include <asm/arch/pmc.h>
#include <linux/bitops.h>
#include <power/acpi_pmc.h>
CF9_GLB_RST = 1 << 20,
};
-struct apl_pmc_plat {
-#if CONFIG_IS_ENABLED(OF_PLATDATA)
- struct dtd_intel_apl_pmc dtplat;
-#endif
- pci_dev_t bdf;
-};
-
static int apl_pmc_fill_power_state(struct udevice *dev)
{
struct acpi_pmc_upriv *upriv = dev_get_uclass_priv(dev);
return 0;
}
-static struct acpi_pmc_ops apl_pmc_ops = {
+static const struct acpi_pmc_ops apl_pmc_ops = {
.init = apl_pmc_fill_power_state,
.prev_sleep_state = apl_prev_sleep_state,
.disable_tco = apl_disable_tco,
.global_reset_set_enable = apl_global_reset_set_enable,
};
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
static const struct udevice_id apl_pmc_ids[] = {
{ .compatible = "intel,apl-pmc" },
{ }
};
+#endif
U_BOOT_DRIVER(intel_apl_pmc) = {
.name = "intel_apl_pmc",
.id = UCLASS_ACPI_PMC,
- .of_match = apl_pmc_ids,
+ .of_match = of_match_ptr(apl_pmc_ids),
.of_to_plat = apl_pmc_ofdata_to_uc_plat,
.probe = apl_pmc_probe,
.ops = &apl_pmc_ops,
return spi_flash_std_probe(dev);
}
-/*
- * Manually set the parent of the SPI flash to SPI, since dtoc doesn't. We also
- * need to allocate the parent_plat since by the time this function is
- * called device_bind() has already gone past that step.
- */
-static int apl_flash_bind(struct udevice *dev)
-{
- if (CONFIG_IS_ENABLED(OF_PLATDATA) &&
- !CONFIG_IS_ENABLED(OF_PLATDATA_PARENT)) {
- struct dm_spi_slave_plat *plat;
- struct udevice *spi;
- int ret;
-
- ret = uclass_first_device_err(UCLASS_SPI, &spi);
- if (ret)
- return ret;
- dev->parent = spi;
-
- plat = calloc(sizeof(*plat), 1);
- if (!plat)
- return -ENOMEM;
- dev->parent_plat = plat;
- }
-
- return 0;
-}
-
static const struct dm_spi_flash_ops apl_flash_ops = {
.read = apl_flash_std_read,
};
.name = "winbond_w25q128fw",
.id = UCLASS_SPI_FLASH,
.of_match = apl_flash_ids,
- .bind = apl_flash_bind,
.probe = apl_flash_probe,
- .priv_auto = sizeof(struct spi_flash),
+ .priv_auto = sizeof(struct spi_nor),
.ops = &apl_flash_ops,
};
#include <asm/io.h>
#include <asm/pci.h>
#include <asm/lpss.h>
+#include <dm/device-internal.h>
+#include <asm/arch/uart.h>
/* Low-power Subsystem (LPSS) clock register */
enum {
* This driver uses its own compatible string but almost everything else from
* the standard ns16550 driver. This allows us to provide an of-platdata
* implementation, since the platdata produced by of-platdata does not match
- * struct ns16550_plat.
+ * struct apl_ns16550_plat.
*
* When running with of-platdata (generally TPL), the platdata is converted to
* something that ns16550 expects. When running withoutof-platdata (SPL, U-Boot
static int apl_ns16550_probe(struct udevice *dev)
{
- struct ns16550_plat *plat = dev_get_plat(dev);
+ struct apl_ns16550_plat *plat = dev_get_plat(dev);
if (!CONFIG_IS_ENABLED(PCI))
- apl_uart_init(plat->bdf, plat->base);
+ apl_uart_init(plat->ns16550.bdf, plat->ns16550.base);
return ns16550_serial_probe(dev);
}
static int apl_ns16550_of_to_plat(struct udevice *dev)
{
#if CONFIG_IS_ENABLED(OF_PLATDATA)
- struct dtd_intel_apl_ns16550 *dtplat = dev_get_plat(dev);
- struct ns16550_plat *plat;
+ struct dtd_intel_apl_ns16550 *dtplat;
+ struct apl_ns16550_plat *plat = dev_get_plat(dev);
+ struct ns16550_plat ns;
/*
- * Convert our plat to the ns16550's plat, so we can just use
- * that driver
+ * The device's plat uses struct apl_ns16550_plat which starts with the
+ * dtd struct, but the ns16550 driver expects it to be struct ns16550.
+ * Set up what that driver expects. Note that this means that the values
+ * cannot be read in this driver when using of-platdata.
+ *
+ * of-platdata so that it is not necessary to overwrite this.
*/
- plat = malloc(sizeof(*plat));
- if (!plat)
- return -ENOMEM;
- plat->base = dtplat->early_regs[0];
- plat->reg_width = 1;
- plat->reg_shift = dtplat->reg_shift;
- plat->reg_offset = 0;
- plat->clock = dtplat->clock_frequency;
- plat->fcr = UART_FCR_DEFVAL;
- plat->bdf = pci_ofplat_get_devfn(dtplat->reg[0]);
- dev->plat = plat;
+ dtplat = &plat->dtplat;
+ ns.base = dtplat->early_regs[0];
+ ns.reg_width = 1;
+ ns.reg_shift = dtplat->reg_shift;
+ ns.reg_offset = 0;
+ ns.clock = dtplat->clock_frequency;
+ ns.fcr = UART_FCR_DEFVAL;
+ ns.bdf = pci_ofplat_get_devfn(dtplat->reg[0]);
+ memcpy(plat, &ns, sizeof(ns));
#else
int ret;
return 0;
}
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
static const struct udevice_id apl_ns16550_serial_ids[] = {
{ .compatible = "intel,apl-ns16550" },
{ },
};
+#endif
U_BOOT_DRIVER(intel_apl_ns16550) = {
.name = "intel_apl_ns16550",
.id = UCLASS_SERIAL,
- .of_match = apl_ns16550_serial_ids,
- .plat_auto = sizeof(struct ns16550_plat),
- .priv_auto = sizeof(struct NS16550),
+ .of_match = of_match_ptr(apl_ns16550_serial_ids),
+ .plat_auto = sizeof(struct apl_ns16550_plat),
+ .priv_auto = sizeof(struct ns16550),
.ops = &ns16550_serial_ops,
.of_to_plat = apl_ns16550_of_to_plat,
.probe = apl_ns16550_probe,
#include <asm/processor-flags.h>
.code32
+.section .text_call64
.globl cpu_call64
cpu_call64:
/*
obj-y += fast_spi.o
obj-y += lpc.o
obj-y += lpss.o
-obj-$(CONFIG_INTEL_GENERIC_WIFI) += generic_wifi.o
+obj-$(CONFIG_$(SPL_)INTEL_GENERIC_WIFI) += generic_wifi.o
ifndef CONFIG_TARGET_EFI_APP
obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += microcode.o
ifndef CONFIG_$(SPL_)X86_64
#include <spl.h>
#include <asm/itss.h>
-struct itss_plat {
-#if CONFIG_IS_ENABLED(OF_PLATDATA)
- /* Put this first since driver model will copy the data here */
- struct dtd_intel_itss dtplat;
-#endif
-};
-
-/* struct pmc_route - Routing for PMC to GPIO */
-struct pmc_route {
- u32 pmc;
- u32 gpio;
-};
-
-struct itss_priv {
- struct pmc_route *route;
- uint route_count;
- u32 irq_snapshot[NUM_IPC_REGS];
-};
-
static int set_polarity(struct udevice *dev, uint irq, bool active_low)
{
u32 mask;
#endif
};
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
static const struct udevice_id itss_ids[] = {
{ .compatible = "intel,itss", .data = X86_IRQT_ITSS },
{ }
};
+#endif
U_BOOT_DRIVER(intel_itss) = {
.name = "intel_itss",
.id = UCLASS_IRQ,
- .of_match = itss_ids,
+ .of_match = of_match_ptr(itss_ids),
.ops = &itss_ops,
.bind = itss_bind,
.of_to_plat = itss_of_to_plat,
#include <log.h>
#include <p2sb.h>
#include <spl.h>
+#include <asm/p2sb.h>
#include <asm/pci.h>
#include <linux/bitops.h>
#define PCH_P2SB_E0 0xe0
#define HIDE_BIT BIT(0)
-struct p2sb_plat {
-#if CONFIG_IS_ENABLED(OF_PLATDATA)
- struct dtd_intel_p2sb dtplat;
-#endif
- ulong mmio_base;
- pci_dev_t bdf;
-};
-
/* PCI config space registers */
#define HPTC_OFFSET 0x60
#define HPTC_ADDR_ENABLE_BIT BIT(7)
return 0;
}
-struct p2sb_ops p2sb_ops = {
+static const struct p2sb_ops p2sb_ops = {
.set_hide = intel_p2sb_set_hide,
};
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
static const struct udevice_id p2sb_ids[] = {
{ .compatible = "intel,p2sb" },
{ }
};
+#endif
U_BOOT_DRIVER(intel_p2sb) = {
.name = "intel_p2sb",
.id = UCLASS_P2SB,
- .of_match = p2sb_ids,
+ .of_match = of_match_ptr(p2sb_ids),
.probe = p2sb_probe,
.remove = p2sb_remove,
.ops = &p2sb_ops,
{
const efi_guid_t guid = SBL_SERIAL_PORT_INFO_GUID;
struct sbl_serial_port_info *data;
- struct ns16550_plat *plat = dev->plat;
+ struct ns16550_plat *plat = dev_get_plat(dev);
if (!gd->arch.hob_list)
panic("hob list not found!");
.of_match = slimbootloader_serial_ids,
.of_to_plat = slimbootloader_serial_of_to_plat,
.plat_auto = sizeof(struct ns16550_plat),
- .priv_auto = sizeof(struct NS16550),
+ .priv_auto = sizeof(struct ns16550),
.probe = ns16550_serial_probe,
.ops = &ns16550_serial_ops,
};
}
#endif
+/* gcc 7.3 does not wwant to drop strings, so use #ifdef */
+#ifndef CONFIG_TPL_BUILD
static const char *const turbo_state_desc[] = {
[TURBO_UNKNOWN] = "unknown",
[TURBO_UNAVAILABLE] = "unavailable",
[TURBO_DISABLED] = "available but hidden",
[TURBO_ENABLED] = "available and visible"
};
+#endif
/*
* Determine the current state of Turbo and cache it for later.
}
set_global_turbo_state(turbo_state);
+#ifndef CONFIG_TPL_BUILD
debug("Turbo is %s\n", turbo_state_desc[turbo_state]);
+#endif
return turbo_state;
}
};
cpus {
- u-boot,dm-pre-reloc;
+ u-boot,dm-pre-proper;
#address-cells = <1>;
#size-cells = <0>;
cpu_0: cpu@0 {
- u-boot,dm-pre-reloc;
+ u-boot,dm-pre-proper;
+ u-boot,dm-spl;
device_type = "cpu";
compatible = "intel,apl-cpu";
reg = <0>;
*/
fsp_s: fsp-s {
};
+ fsp_m: fsp-m {
+ u-boot,dm-spl;
+ };
nhlt {
intel,dmic-channels = <4>;
};
punit@0,1 {
- u-boot,dm-pre-reloc;
+ u-boot,dm-pre-proper;
+ u-boot,dm-spl;
reg = <0x00000800 0 0 0 0>;
compatible = "intel,apl-punit";
};
gma@2,0 {
+ u-boot,dm-pre-proper;
reg = <0x00001000 0 0 0 0>;
compatible = "fsp-fb";
};
};
spi: fast-spi@d,2 {
- u-boot,dm-pre-reloc;
+ u-boot,dm-pre-proper;
+ u-boot,dm-spl;
reg = <0x02006a10 0 0 0 0>;
#address-cells = <1>;
#size-cells = <0>;
fwstore_spi: spi-flash@0 {
#size-cells = <1>;
#address-cells = <1>;
- u-boot,dm-pre-reloc;
+ u-boot,dm-pre-proper;
+ u-boot,dm-spl;
reg = <0>;
compatible = "winbond,w25q128fw",
"jedec,spi-nor";
#size-cells = <0>;
u-boot,dm-pre-reloc;
cros_ec: cros-ec {
- u-boot,dm-pre-reloc;
+ u-boot,dm-pre-proper;
compatible = "google,cros-ec-lpc";
reg = <0x204 1 0x200 1 0x880 0x80>;
PAD_CFG_NF(LPC_CLKRUNB, UP_20K, DEEP, NF1) /* LPC_CLKRUN_N */
PAD_CFG_NF(LPC_FRAMEB, NATIVE, DEEP, NF1) /* LPC_FRAME_N */
>;
+};
+&fsp_m {
fspm,package = <PACKAGE_BGA>;
fspm,profile = <PROFILE_LPDDR4_2400_24_22_22>;
fspm,memory-down = <MEMORY_DOWN_YES>;
/ {
rtc: rtc {
compatible = "motorola,mc146818";
- u-boot,dm-pre-reloc;
+ u-boot,dm-pre-proper;
reg = <0x70 2>;
};
};
/* This is needed by ACPI */
#define GPIO_NUM_PAD_CFG_REGS 2 /* DW0, DW1 */
+#ifndef __ASSEMBLY__
+
+#include <dt-structs.h>
+
+/**
+ * struct apl_gpio_plat - platform data for each device
+ *
+ * @dtplat: of-platdata data from C struct
+ */
+struct apl_gpio_plat {
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+ /* Put this first since driver model will copy the data here */
+ struct dtd_intel_apl_pinctrl dtplat;
+#endif
+};
+
+#endif /* __ASSEMBLY__ */
+
#endif /* _ASM_ARCH_GPIO_H_ */
--- /dev/null
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2020 Google LLC
+ */
+
+#ifndef _ASM_ARCH_HOSTBRIDGE_H_
+#define _ASM_ARCH_HOSTBRIDGE_H_
+
+/**
+ * struct apl_hostbridge_plat - platform data for hostbridge
+ *
+ * @dtplat: Platform data for of-platdata
+ * @early_pads: Early pad data to set up, each (pad, cfg0, cfg1)
+ * @early_pads_count: Number of pads to process
+ * @pciex_region_size: BAR length in bytes
+ * @bdf: Bus/device/function of hostbridge
+ */
+struct apl_hostbridge_plat {
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+ struct dtd_intel_apl_hostbridge dtplat;
+#endif
+ u32 *early_pads;
+ int early_pads_count;
+ uint pciex_region_size;
+ pci_dev_t bdf;
+};
+
+#endif /* _ASM_ARCH_HOSTBRIDGE_H_ */
--- /dev/null
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2020 Google LLC
+ */
+
+#ifndef ASM_ARCH_PMC_H
+#define ASM_ARCH_PMC_H
+
+struct apl_pmc_plat {
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+ struct dtd_intel_apl_pmc dtplat;
+#endif
+ pci_dev_t bdf;
+};
+
+#endif /* ASM_ARCH_PMC_H */
#ifndef _ASM_ARCH_UART_H
#define _ASM_ARCH_UART_H
+#include <ns16550.h>
+
+/**
+ * struct apl_ns16550_plat - platform data for the APL UART
+ *
+ * Note that when of-platdata is in use, apl_ns16550_of_to_plat() actually
+ * copies the ns16550_plat contents to the start of this struct, meaning that
+ * dtplat is no-longer valid. This is done so that the ns16550 driver can use
+ * dev_get_plat() without any offsets or adjustments.
+ */
+struct apl_ns16550_plat {
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+ struct dtd_intel_apl_ns16550 dtplat;
+#endif
+ struct ns16550_plat ns16550;
+};
+
/**
* apl_uart_init() - Set up the APL UART device and clock
*
* The UART won't actually work unless the GPIO settings are correct and the
* signals actually exit the SoC. See board_debug_uart_init() for that.
*/
-int apl_uart_init(pci_dev_t bdf, ulong base);
+void apl_uart_init(pci_dev_t bdf, ulong base);
#endif
#ifndef _ASM_ARCH_ITSS_H
#define _ASM_ARCH_ITSS_H
+#include <irq.h>
+
#define GPIO_IRQ_START 50
#define GPIO_IRQ_END ITSS_MAX_IRQ
/* ITSS Power reduction control */
#define PCR_ITSS_ITSSPRC 0x3300
+struct itss_plat {
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+ /* Put this first since driver model will copy the data here */
+ struct dtd_intel_itss dtplat;
+#endif
+};
+
+/* struct pmc_route - Routing for PMC to GPIO */
+struct pmc_route {
+ u32 pmc;
+ u32 gpio;
+};
+
+struct itss_priv {
+ struct pmc_route *route;
+ uint route_count;
+ u32 irq_snapshot[NUM_IPC_REGS];
+};
+
#endif /* _ASM_ARCH_ITSS_H */
--- /dev/null
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2020 Google LLC
+ */
+
+#ifndef ASM_P2SB_H
+#define ASM_P2SB_H
+
+/* Platform data for the P2SB */
+struct p2sb_plat {
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+ struct dtd_intel_p2sb dtplat;
+#endif
+ ulong mmio_base;
+ pci_dev_t bdf;
+};
+
+#endif /* ASM_P2SB_H */
/*
* Copyright (c) 2017 Intel Corporation
*/
-#ifndef _X86_ASM_PMU_IPC_H_
-#define _X86_ASM_PMU_IPC_H_
+#ifndef _X86_ASM_PMU_H_
+#define _X86_ASM_PMU_H_
int pmu_turn_power(unsigned int lss, bool on);
-#endif /* _X86_ASM_PMU_IPC_H_ */
+#endif /* _X86_ASM_PMU_H_ */
--- /dev/null
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2020 Google LLC
+ */
+#ifndef _X86_ASM_SYSRESET_H_
+#define _X86_ASM_SYSRESET_H_
+
+#include <dt-structs.h>
+
+struct x86_sysreset_plat {
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+ struct dtd_x86_reset dtplat;
+#endif
+
+ struct udevice *pch;
+};
+
+#endif /* _X86_ASM_SYSRESET_H_ */
* for devices, so the TPL BARs continue to be used. Once U-Boot starts it does
* the auto allocation (after relocation).
*/
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
static const struct udevice_id tpl_fake_pci_ids[] = {
{ .compatible = "pci-x86" },
{ }
};
+#endif
U_BOOT_DRIVER(pci_x86) = {
.name = "pci_x86",
.id = UCLASS_SIMPLE_BUS,
- .of_match = tpl_fake_pci_ids,
+ .of_match = of_match_ptr(tpl_fake_pci_ids),
};
#endif
bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
gd->bus_clk = bus_clk;
- NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
+ ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1,
bus_clk / 16 / CONFIG_BAUDRATE);
#ifdef CONFIG_SPL_MMC_BOOT
puts("\nSD boot...\n");
plat_ratio >>= 1;
gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
- NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
+ ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1,
gd->bus_clk / 16 / CONFIG_BAUDRATE);
puts("\nNAND boot... ");
void putc(char c)
{
if (c == '\n')
- NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, '\r');
+ ns16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, '\r');
- NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, c);
+ ns16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, c);
}
void puts(const char *str)
printf("Synology reset...");
udelay(50000);
- b_d = ns16550_calc_divisor((NS16550_t)CONFIG_SYS_NS16550_COM2,
- CONFIG_SYS_NS16550_CLK, 9600);
- NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM2, b_d);
- NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM2, SOFTWARE_REBOOT);
+ b_d = ns16550_calc_divisor((struct ns16550 *)CONFIG_SYS_NS16550_COM2,
+ CONFIG_SYS_NS16550_CLK, 9600);
+ ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM2, b_d);
+ ns16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM2,
+ SOFTWARE_REBOOT);
}
/* Support old kernels */
#endif
};
-U_BOOT_DEVICE(integrator_serials) = {
+U_BOOT_DRVINFO(integrator_serials) = {
.name = "serial_pl01x",
.plat = &serial_plat,
};
.clock = CONFIG_PL011_CLOCK,
};
-U_BOOT_DEVICE(total_compute_serials) = {
+U_BOOT_DRVINFO(total_compute_serials) = {
.name = "serial_pl01x",
.plat = &serial_plat,
};
.clock = CONFIG_PL011_CLOCK,
};
-U_BOOT_DEVICE(vexpress_serials) = {
+U_BOOT_DRVINFO(vexpress_serials) = {
.name = "serial_pl01x",
.plat = &serial_plat,
};
.base_addr = ATMEL_BASE_DBGU,
};
-U_BOOT_DEVICE(at91sam9260_serial) = {
+U_BOOT_DRVINFO(at91sam9260_serial) = {
.name = "serial_atmel",
.plat = &at91sam9260_serial_plat,
};
.base_addr = ATMEL_BASE_DBGU,
};
-U_BOOT_DEVICE(at91sam9260_serial) = {
+U_BOOT_DRVINFO(at91sam9260_serial) = {
.name = "serial_atmel",
.plat = &at91sam9260_serial_plat,
};
return 0;
}
-U_BOOT_DEVICE(sysreset) = {
+U_BOOT_DRVINFO(sysreset) = {
.name = "xtfpga_sysreset",
};
.packet_base = CONFIG_SYS_ETHOC_BUFFER_ADDR,
};
-U_BOOT_DEVICE(ethoc) = {
+U_BOOT_DRVINFO(ethoc) = {
.name = "ethoc",
.plat = ðoc_pdata,
};
.skip_init = true,
};
-U_BOOT_DEVICE(thunderx_serial0) = {
+U_BOOT_DRVINFO(thunderx_serial0) = {
.name = "serial_pl01x",
.plat = &serial0,
};
.skip_init = true,
};
-U_BOOT_DEVICE(thunderx_serial1) = {
+U_BOOT_DRVINFO(thunderx_serial1) = {
.name = "serial_pl01x",
.plat = &serial1,
};
.reg = (struct mxc_uart *)UART4_BASE,
};
-U_BOOT_DEVICE(cm_fx6_serial) = {
+U_BOOT_DRVINFO(cm_fx6_serial) = {
.name = "serial_mxc",
.plat = &cm_fx6_mxc_serial_plat,
};
.fcr = UART_FCR_DEFVAL,
};
-U_BOOT_DEVICE(omapl138_uart) = {
+U_BOOT_DRVINFO(omapl138_uart) = {
.name = "ns16550_serial",
.plat = &serial_pdata,
};
.name = "da830-mmc",
},
};
-U_BOOT_DEVICE(omapl138_mmc) = {
+U_BOOT_DRVINFO(omapl138_mmc) = {
.name = "ti_da830_mmc",
.plat = &mmc_plat,
};
int ret;
ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC,
- DM_GET_DRIVER(dwc2_udc_otg),
+ DM_DRIVER_GET(dwc2_udc_otg),
&dwc2_udc_otg);
if (!ret)
debug("dwc2_udc_otg init failed\n");
* but this value need to be consistent with board design
*/
ret = uclass_get_device_by_driver(UCLASS_PMIC,
- DM_GET_DRIVER(stm32mp_pwr_pmic),
+ DM_DRIVER_GET(stm32mp_pwr_pmic),
&pwr_dev);
if (!ret) {
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stm32mp_bsec),
+ DM_DRIVER_GET(stm32mp_bsec),
&dev);
if (ret) {
pr_err("Can't find stm32mp_bsec driver\n");
},
};
-U_BOOT_DEVICE(ls1012a_pfe0) = {
+U_BOOT_DRVINFO(ls1012a_pfe0) = {
.name = "pfe_eth",
.plat = &pfe_pdata0,
};
-U_BOOT_DEVICE(ls1012a_pfe1) = {
+U_BOOT_DRVINFO(ls1012a_pfe1) = {
.name = "pfe_eth",
.plat = &pfe_pdata1,
};
},
};
-U_BOOT_DEVICE(ls1012a_pfe0) = {
+U_BOOT_DRVINFO(ls1012a_pfe0) = {
.name = "pfe_eth",
.plat = &pfe_pdata0,
};
-U_BOOT_DEVICE(ls1012a_pfe1) = {
+U_BOOT_DRVINFO(ls1012a_pfe1) = {
.name = "pfe_eth",
.plat = &pfe_pdata1,
};
},
};
-U_BOOT_DEVICE(ls1012a_pfe0) = {
+U_BOOT_DRVINFO(ls1012a_pfe0) = {
.name = "pfe_eth",
.plat = &pfe_pdata0,
};
-U_BOOT_DEVICE(ls1012a_pfe1) = {
+U_BOOT_DRVINFO(ls1012a_pfe1) = {
.name = "pfe_eth",
.plat = &pfe_pdata1,
};
.type = TYPE_PL011,
};
-U_BOOT_DEVICE(nxp_serial0) = {
+U_BOOT_DRVINFO(nxp_serial0) = {
.name = "serial_pl01x",
.plat = &serial0,
};
.type = TYPE_PL011,
};
-U_BOOT_DEVICE(nxp_serial1) = {
+U_BOOT_DRVINFO(nxp_serial1) = {
.name = "serial_pl01x",
.plat = &serial1,
};
void board_init_f(ulong bootflag)
{
board_early_init_f();
- NS16550_init((NS16550_t)(CONFIG_SYS_IMMR + 0x4500),
+ ns16550_init((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500),
CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
puts("NAND boot... ");
timer_init();
return;
if (c == '\n')
- NS16550_putc((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), '\r');
+ ns16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), '\r');
- NS16550_putc((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), c);
+ ns16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), c);
}
#endif
void board_init_f(ulong bootflag)
{
board_early_init_f();
- NS16550_init((NS16550_t)(CONFIG_SYS_IMMR + 0x4500),
+ ns16550_init((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500),
CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
puts("NAND boot... ");
timer_init();
return;
if (c == '\n')
- NS16550_putc((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), '\r');
+ ns16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), '\r');
- NS16550_putc((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), c);
+ ns16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), c);
}
#endif /* CONFIG_NAND_SPL */
plat_ratio >>= 1;
gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
- NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
+ ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1,
gd->bus_clk / 16 / CONFIG_BAUDRATE);
#ifdef CONFIG_SPL_MMC_BOOT
plat_ratio >>= 1;
gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
- NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
- gd->bus_clk / 16 / CONFIG_BAUDRATE);
+ ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1,
+ gd->bus_clk / 16 / CONFIG_BAUDRATE);
puts("\nNAND boot... ");
void putc(char c)
{
if (c == '\n')
- NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, '\r');
+ ns16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, '\r');
- NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, c);
+ ns16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, c);
}
void puts(const char *str)
bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
gd->bus_clk = bus_clk;
- NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
+ ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1,
bus_clk / 16 / CONFIG_BAUDRATE);
#ifdef CONFIG_SPL_MMC_BOOT
puts("\nSD boot...\n");
plat_ratio >>= 1;
gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
- NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
- gd->bus_clk / 16 / CONFIG_BAUDRATE);
+ ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1,
+ gd->bus_clk / 16 / CONFIG_BAUDRATE);
puts("\nNAND boot... ");
void putc(char c)
{
if (c == '\n')
- NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, '\r');
+ ns16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, '\r');
- NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, c);
+ ns16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, c);
}
void puts(const char *str)
plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f;
ccb_clk = sys_clk * plat_ratio / 2;
- NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
+ ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1,
ccb_clk / 16 / CONFIG_BAUDRATE);
#if defined(CONFIG_SPL_MMC_BOOT)
plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f;
uart_clk = sys_clk * plat_ratio / 2;
- NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
+ ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1,
uart_clk / 16 / CONFIG_BAUDRATE);
relocate_code(CONFIG_SPL_RELOC_STACK, (gd_t *)CONFIG_SPL_GD_ADDR, 0x0);
plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f;
ccb_clk = sys_clk * plat_ratio / 2;
- NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
+ ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1,
ccb_clk / 16 / CONFIG_BAUDRATE);
#if defined(CONFIG_SPL_MMC_BOOT)
plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f;
ccb_clk = sys_clk * plat_ratio / 2;
- NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
+ ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1,
ccb_clk / 16 / CONFIG_BAUDRATE);
#if defined(CONFIG_SPL_MMC_BOOT)
plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f;
ccb_clk = sys_clk * plat_ratio / 2;
- NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
+ ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1,
ccb_clk / 16 / CONFIG_BAUDRATE);
puts("\nSD boot...\n");
.reg = (struct mxc_uart *)UART2_BASE,
};
-U_BOOT_DEVICE(ventana_serial) = {
+U_BOOT_DRVINFO(ventana_serial) = {
.name = "serial_mxc",
.plat = &ventana_mxc_serial_plat,
};
.inject_dsdt = chromeos_acpi_gpio_generate,
};
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
static const struct udevice_id coral_ids[] = {
{ .compatible = "google,coral" },
{ }
};
+#endif
U_BOOT_DRIVER(coral_drv) = {
.name = "coral",
.id = UCLASS_SYSINFO,
- .of_match = coral_ids,
+ .of_match = of_match_ptr(coral_ids),
ACPI_OPS_PTR(&coral_acpi_ops)
};
* setting up.
*/
ret = uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(clk_rk3399), &clk);
+ DM_DRIVER_GET(clk_rk3399), &clk);
if (ret) {
debug("%s: CLK init failed: %d\n", __func__, ret);
return ret;
};
-U_BOOT_DEVICES(hi6220_gpios) = {
+U_BOOT_DRVINFOS(hi6220_gpios) = {
{ "gpio_hi6220", &hi6220_gpio[0] },
{ "gpio_hi6220", &hi6220_gpio[1] },
{ "gpio_hi6220", &hi6220_gpio[2] },
.clock = 19200000
};
-U_BOOT_DEVICE(hikey_seriala) = {
+U_BOOT_DRVINFO(hikey_seriala) = {
.name = "serial_pl01x",
.plat = &serial_plat,
};
.clock = 19200000
};
-U_BOOT_DEVICE(hikey960_serial0) = {
+U_BOOT_DRVINFO(hikey960_serial0) = {
.name = "serial_pl01x",
.plat = &serial_plat,
};
.clock = 75000000,
};
-U_BOOT_DEVICE(poplar_serial) = {
+U_BOOT_DRVINFO(poplar_serial) = {
.name = "serial_pl01x",
.plat = &serial_plat,
};
.fcr = UART_FCR_DEFVAL,
};
-U_BOOT_DEVICE(igep_uart) = {
+U_BOOT_DRVINFO(igep_uart) = {
"ns16550_serial",
&igep_serial
};
.fcr = UART_FCR_DEFVAL,
};
-U_BOOT_DEVICE(sniper_serial) = {
+U_BOOT_DRVINFO(sniper_serial) = {
.name = "ns16550_serial",
.plat = &serial_omap_plat
};
{ I2C_BASE3, 400000, OMAP_I2C_REV_V1 },
};
-U_BOOT_DEVICES(rx51_i2c) = {
+U_BOOT_DRVINFOS(rx51_i2c) = {
{ "i2c_omap", &rx51_i2c[0] },
{ "i2c_omap", &rx51_i2c[1] },
{ "i2c_omap", &rx51_i2c[2] },
int ret;
ret = uclass_get_device_by_driver(UCLASS_PMIC,
- DM_GET_DRIVER(pmic_as3722), &dev);
+ DM_DRIVER_GET(pmic_as3722), &dev);
if (ret) {
debug("%s: Failed to find PMIC\n", __func__);
return ret;
int ret;
ret = uclass_get_device_by_driver(UCLASS_PMIC,
- DM_GET_DRIVER(pmic_as3722), &dev);
+ DM_DRIVER_GET(pmic_as3722), &dev);
if (ret) {
debug("%s: Failed to find PMIC\n", __func__);
return ret;
int ret;
ret = uclass_get_device_by_driver(UCLASS_SYSRESET,
- DM_GET_DRIVER(sysreset_renesas_ulcb),
+ DM_DRIVER_GET(sysreset_renesas_ulcb),
&dev);
if (ret)
return ret;
#if !CONFIG_IS_ENABLED(OF_PLATDATA)
/* Add a simple GPIO device */
-U_BOOT_DEVICE(gpio_sandbox) = {
+U_BOOT_DRVINFO(gpio_sandbox) = {
.name = "sandbox_gpio",
};
#endif
.base_addr = ATMEL_BASE_DBGU,
};
-U_BOOT_DEVICE(at91sam9260_serial) = {
+U_BOOT_DRVINFO(at91sam9260_serial) = {
.name = "serial_atmel",
.plat = &at91sam9260_serial_plat,
};
/* init OTP */
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(sifive_otp), &dev);
+ DM_DRIVER_GET(sifive_otp), &dev);
if (ret) {
debug("%s: could not find otp device\n", __func__);
return CMD_RET_USAGE;
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stm32mp_bsec),
+ DM_DRIVER_GET(stm32mp_bsec),
&dev);
ret = misc_read(dev, STM32_BSEC_OTP(BSEC_OTP_BOARD),
int ret;
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stm32mp_bsec),
+ DM_DRIVER_GET(stm32mp_bsec),
&dev);
if (ret)
return ret;
struct udevice *dev;
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stpmic1_nvm),
+ DM_DRIVER_GET(stpmic1_nvm),
&dev);
if (ret)
return ret;
u32 buck2;
ret = uclass_get_device_by_driver(UCLASS_PMIC,
- DM_GET_DRIVER(pmic_stpmic1), &dev);
+ DM_DRIVER_GET(pmic_stpmic1), &dev);
if (ret)
/* No PMIC on board */
return 0;
struct udevice *dev;
if (uclass_get_device_by_driver(UCLASS_PMIC,
- DM_GET_DRIVER(pmic_stpmic1), &dev))
+ DM_DRIVER_GET(pmic_stpmic1), &dev))
return;
/* update VDDCORE = BUCK1 */
int ret;
ret = uclass_get_device_by_driver(UCLASS_I2C_GENERIC,
- DM_GET_DRIVER(stusb160x),
+ DM_DRIVER_GET(stusb160x),
&dev);
if (ret < 0)
return ret;
/* display the STMicroelectronics board identification */
if (CONFIG_IS_ENABLED(CMD_STBOARD)) {
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stm32mp_bsec),
+ DM_DRIVER_GET(stm32mp_bsec),
&dev);
if (!ret)
ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
return ret;
ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC,
- DM_GET_DRIVER(dwc2_udc_otg),
+ DM_DRIVER_GET(dwc2_udc_otg),
&dwc2_udc_otg);
if (!ret)
debug("dwc2_udc_otg init failed\n");
* but this value need to be consistent with board design
*/
ret = uclass_get_device_by_driver(UCLASS_PMIC,
- DM_GET_DRIVER(stm32mp_pwr_pmic),
+ DM_DRIVER_GET(stm32mp_pwr_pmic),
&pwr_dev);
if (!ret && IS_ENABLED(CONFIG_DM_REGULATOR)) {
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stm32mp_bsec),
+ DM_DRIVER_GET(stm32mp_bsec),
&dev);
if (ret) {
pr_err("Can't find stm32mp_bsec driver\n");
struct udevice *dev;
/* configure IRQ line on EV1 for touchscreen before LCD reset */
- uclass_get_device_by_driver(UCLASS_NOP, DM_GET_DRIVER(goodix), &dev);
+ uclass_get_device_by_driver(UCLASS_NOP, DM_DRIVER_GET(goodix), &dev);
}
/* board dependent setup after realloc */
}
}
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stm32mp_bsec),
+ DM_DRIVER_GET(stm32mp_bsec),
&dev);
if (!ret)
.clock = 2700 * 1000,
};
-U_BOOT_DEVICE(stv09911_serials) = {
+U_BOOT_DRVINFO(stv09911_serials) = {
.name = "serial_pl01x",
.plat = &serial_plat,
};
/* Dummy fmeas device, just to be able to use standard clk_* api */
struct udevice fmeas = {
.name = "clk-fmeas",
- .node = ofnode_path("/clk-fmeas"),
};
+ dev_set_ofnode(&fmeas, ofnode_path("/clk-fmeas"));
ret = clk_get_by_name(&fmeas, name, &clk);
if (ret) {
.baudrate = CONFIG_BAUDRATE,
};
-U_BOOT_DEVICE(coldfire_serial) = {
+U_BOOT_DRVINFO(coldfire_serial) = {
.name = "serial_coldfire",
.plat = &mcf5307_serial_plat,
};
.priv_pdata = &am335_eth_data,
};
-U_BOOT_DEVICE(am335x_eth) = {
+U_BOOT_DRVINFO(am335x_eth) = {
.name = "eth_cpsw",
.plat = &cpsw_pdata,
};
.cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
};
-U_BOOT_DEVICE(am335x_mmc0) = {
+U_BOOT_DRVINFO(am335x_mmc0) = {
.name = "omap_hsmmc",
.plat = &am335x_mmc0_plat,
};
.cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
};
-U_BOOT_DEVICE(am335x_mmc1) = {
+U_BOOT_DRVINFO(am335x_mmc1) = {
.name = "omap_hsmmc",
.plat = &am335x_mmc1_plat,
};
#ifdef CONFIG_ESM_K3
if (board_ti_k3_is("J721EX-PM2-SOM")) {
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(k3_esm), &dev);
+ DM_DRIVER_GET(k3_esm), &dev);
if (ret)
printf("ESM init failed: %d\n", ret);
}
#ifdef CONFIG_ESM_PMIC
if (board_ti_k3_is("J721EX-PM2-SOM")) {
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(pmic_esm),
+ DM_DRIVER_GET(pmic_esm),
&dev);
if (ret)
printf("ESM PMIC init failed: %d\n", ret);
.fcr = UART_FCR_DEFVAL,
};
-U_BOOT_DEVICE(devkit8000_uart) = {
+U_BOOT_DRVINFO(devkit8000_uart) = {
"ns16550_serial",
&devkit8000_serial
};
int ret;
ret = uclass_get_device_by_driver(UCLASS_PMIC,
- DM_GET_DRIVER(pmic_as3722), &dev);
+ DM_DRIVER_GET(pmic_as3722), &dev);
if (ret) {
pr_err("failed to find AS3722 PMIC: %d\n", ret);
return ret;
int ret;
ret = uclass_get_device_by_driver(UCLASS_PMIC,
- DM_GET_DRIVER(pmic_as3722),
+ DM_DRIVER_GET(pmic_as3722),
&dev);
if (ret) {
debug("%s: Failed to find PMIC\n", __func__);
.use_dte = true,
};
-U_BOOT_DEVICE(mxc_serial) = {
+U_BOOT_DRVINFO(mxc_serial) = {
.name = "serial_mxc",
.plat = &mxc_serial_plat,
};
.use_dte = 1,
};
-U_BOOT_DEVICE(mxc_serial) = {
+U_BOOT_DRVINFO(mxc_serial) = {
.name = "serial_mxc",
.plat = &mxc_serial_plat,
};
.use_dte = true,
};
-U_BOOT_DEVICE(mxc_serial) = {
+U_BOOT_DRVINFO(mxc_serial) = {
.name = "serial_mxc",
.plat = &mxc_serial_plat,
};
.base = (struct pxa_mmc_regs *)MMC0_BASE,
};
-U_BOOT_DEVICE(pxa_mmcs) = {
+U_BOOT_DRVINFO(pxa_mmcs) = {
.name = "pxa_mmc",
.plat = &mmc_plat,
};
.baudrate = CONFIG_BAUDRATE,
};
-U_BOOT_DEVICE(pxa_serials) = {
+U_BOOT_DRVINFO(pxa_serials) = {
.name = "serial_pxa",
.plat = &serial_plat,
};
uc_pdata = dev_get_uclass_plat(dev);
/* Do not print if rproc is not probed */
- if (!(dev->flags & DM_FLAG_ACTIVATED))
+ if (!(dev_get_flags(dev) & DM_FLAG_ACTIVATED))
continue;
switch (uc_pdata->mem_type) {
Create boot binary having SPL binary in PBI format concatenated with
u-boot binary.
+config SPL_ALLOC_BD
+ bool "Allocate memory for bd_info"
+ default y if X86 || SANDBOX
+ help
+ Some boards don't allocate space for this in their board_init_f()
+ code. In this case U-Boot can allocate space for gd->bd in the
+ standard SPL flow (board_init_r()). Enable this option to support
+ this feature.
+
endmenu
config HANDOFF
binman_sym_declare(ulong, spl, size);
#endif
-/* Define board data structure */
-static struct bd_info bdata __attribute__ ((section(".data")));
-
/*
* Board-specific Platform code can reimplement show_boot_progress () if needed
*/
return 0;
}
-void spl_set_bd(void)
+int spl_alloc_bd(void)
{
/*
* NOTE: On some platforms (e.g. x86) bdata may be in flash and not
* writeable.
*/
- if (!gd->bd)
- gd->bd = &bdata;
+ if (!gd->bd) {
+ gd->bd = malloc(sizeof(*gd->bd));
+ if (!gd->bd)
+ return -ENOMEM;
+ }
+
+ return 0;
}
int spl_early_init(void)
debug(">>" SPL_TPL_PROMPT "board_init_r()\n");
- spl_set_bd();
-
#if defined(CONFIG_SYS_SPL_MALLOC_START)
mem_malloc_init(CONFIG_SYS_SPL_MALLOC_START,
CONFIG_SYS_SPL_MALLOC_SIZE);
if (spl_init())
hang();
}
+ if (IS_ENABLED(CONFIG_SPL_ALLOC_BD) && spl_alloc_bd()) {
+ puts("Cannot alloc bd\n");
+ hang();
+ }
#if !defined(CONFIG_PPC) && !defined(CONFIG_ARCH_MX6)
/*
* timer_init() does not exist on PPC systems. The timer is initialized
While plat is useful, a more flexible way of providing device data is
by using device tree. In U-Boot you should use this where possible. Avoid
-sending patches which make use of the U_BOOT_DEVICE() macro unless strictly
+sending patches which make use of the U_BOOT_DRVINFO() macro unless strictly
necessary.
With device tree we replace the above code with the following device tree
sides = <4>;
};
-This means that instead of having lots of U_BOOT_DEVICE() declarations in
+This means that instead of having lots of U_BOOT_DRVINFO() declarations in
the board file, we put these in the device tree. This approach allows a lot
more generality, since the same board file can support many types of boards
(e,g. with the same SoC) just by using different device trees. An added
U-Boot discovers devices using one of these two methods:
-- Scan the U_BOOT_DEVICE() definitions. U-Boot looks up the name specified
+- Scan the U_BOOT_DRVINFO() definitions. U-Boot looks up the name specified
by each, to find the appropriate U_BOOT_DRIVER() definition. In this case,
- there is no path by which driver_data may be provided, but the U_BOOT_DEVICE()
+ there is no path by which driver_data may be provided, but the U_BOOT_DRVINFO()
may provide plat.
- Scan through the device tree definitions. U-Boot looks at top-level
At this point all the devices are known, and bound to their drivers. There
is a 'struct udevice' allocated for all devices. However, nothing has been
activated (except for the root device). Each bound device that was created
-from a U_BOOT_DEVICE() declaration will hold the plat pointer specified
+from a U_BOOT_DRVINFO() declaration will hold the plat pointer specified
in that declaration. For a bound device created from the device tree,
plat will be NULL, but of_offset will be the offset of the device tree
node that caused the device to be created. The uclass is set correctly for
2. If plat_auto is non-zero, then the platform data space
is allocated. This is only useful for device tree operation, since
otherwise you would have to specific the platform data in the
- U_BOOT_DEVICE() declaration. The space is allocated for the device and
+ U_BOOT_DRVINFO() declaration. The space is allocated for the device and
zeroed. It will be accessible as dev->plat.
3. If the device's uclass specifies a non-zero per_device_auto,
do various calls like dev_read_u32(dev, ...) to access the node and store
the resulting information into dev->plat. After this point, the device
works the same way whether it was bound using a device tree node or
- U_BOOT_DEVICE() structure. In either case, the platform data is now stored
+ U_BOOT_DRVINFO() structure. In either case, the platform data is now stored
in the plat structure. Typically you will use the
plat_auto feature to specify the size of the platform data
structure, and U-Boot will automatically allocate and zero it for you before
4. The device memory is freed (platform data, private data, uclass data,
parent data).
- Note: Because the platform data for a U_BOOT_DEVICE() is defined with a
+ Note: Because the platform data for a U_BOOT_DRVINFO() is defined with a
static pointer, it is not de-allocated during the remove() method. For
a device instantiated using the device tree data, the platform data will
be dynamically allocated, and thus needs to be deallocated during the
before relocation. While with DM_FLAG_PRE_RELOC flag of the driver all
devices with the same driver are bound, which requires allocation a large
amount of memory. When device tree is not used, DM_FLAG_PRE_RELOC is the
-only way for statically declared devices via U_BOOT_DEVICE() to be bound
+only way for statically declared devices via U_BOOT_DRVINFO() to be bound
prior to relocation.
It is possible to limit this to specific relocation steps, by using
case the overhead of device tree access may be too great.
It is possible to create platform data manually by defining C structures
-for it, and reference that data in a U_BOOT_DEVICE() declaration. This
+for it, and reference that data in a U_BOOT_DRVINFO() declaration. This
bypasses the use of device tree completely, effectively creating a parallel
configuration mechanism. But it is an available option for SPL.
A new tool called 'dtoc' converts a device tree file either into a set of
struct declarations, one for each compatible node, and a set of
-U_BOOT_DEVICE() declarations along with the actual platform data for each
+U_BOOT_DRVINFO() declarations along with the actual platform data for each
device. As an example, consider this MMC node:
.. code-block:: none
.card_detect_delay = 0xc8,
};
- U_BOOT_DEVICE(dwmmc_at_ff0c0000) = {
+ U_BOOT_DRVINFO(dwmmc_at_ff0c0000) = {
.name = "rockchip_rk3288_dw_mshc",
.plat = &dtv_dwmmc_at_ff0c0000,
.plat_size = sizeof(dtv_dwmmc_at_ff0c0000),
.parent_idx = -1,
};
- void dm_populate_phandle_data(void) {
- }
-
The device is then instantiated at run-time and the platform data can be
accessed using:
therefore do nothing in such a driver.
Note that for the platform data to be matched with a driver, the 'name'
-property of the U_BOOT_DEVICE() declaration has to match a driver declared
+property of the U_BOOT_DRVINFO() declaration has to match a driver declared
via U_BOOT_DRIVER(). This effectively means that a U_BOOT_DRIVER() with a
'name' corresponding to the devicetree 'compatible' string (after converting
it to a valid name for C) is needed, so a dedicated driver is required for
each 'compatible' string.
-In order to make this a bit more flexible U_BOOT_DRIVER_ALIAS macro can be
+In order to make this a bit more flexible DM_DRIVER_ALIAS macro can be
used to declare an alias for a driver name, typically a 'compatible' string.
This macro produces no code, but it is by dtoc tool.
The parent_idx is the index of the parent driver_info structure within its
-linker list (instantiated by the U_BOOT_DEVICE() macro). This is used to support
-dev_get_parent(). The dm_populate_phandle_data() is included to allow for
-fix-ups required by dtoc. It is not currently used. The values in 'clocks' are
-the index of the driver_info for the target device followed by any phandle
-arguments. This is used to support device_get_by_driver_info_idx().
+linker list (instantiated by the U_BOOT_DRVINFO() macro). This is used to support
+dev_get_parent().
-During the build process dtoc parses both U_BOOT_DRIVER and U_BOOT_DRIVER_ALIAS
+During the build process dtoc parses both U_BOOT_DRIVER and DM_DRIVER_ALIAS
to build a list of valid driver names and driver aliases. If the 'compatible'
string used for a device does not not match a valid driver name, it will be
checked against the list of driver aliases in order to get the right driver
.plat_auto = sizeof(struct mmc_plat),
};
- U_BOOT_DRIVER_ALIAS(mmc_drv, vendor_mmc) /* matches compatible string */
+ DM_DRIVER_ALIAS(mmc_drv, vendor_mmc) /* matches compatible string */
Note that struct mmc_plat is defined in the C file, not in a header. This
is to avoid needing to include dt-structs.h in a header file. The idea is to
#if CONFIG_IS_ENABLED(OF_PLATDATA).
The dt-plat.c file contains the device declarations and is is built in
-spl/dt-plat.c. It additionally contains the definition of
-dm_populate_phandle_data() which is responsible of filling the phandle
-information by adding references to U_BOOT_DEVICE by using DM_GET_DEVICE
+spl/dt-plat.c.
+
+The dm_populate_phandle_data() function that was previous needed has now been
+removed, since dtoc can address the drivers directly from dt-plat.c and does
+not need to fix up things at runtime.
The pylibfdt Python module is used to access the devicetree.
.driver_plat_data = &mydriver_data;
};
- U_BOOT_DEVICE(proc_3_demo) = {
+ U_BOOT_DRVINFO(proc_3_demo) = {
.name = "sandbox_test_proc",
.plat = &proc_3_test,
};
Add the platform data [non-device-tree only]
--------------------------------------------
-Specify this data in a U_BOOT_DEVICE() declaration in your board file:
+Specify this data in a U_BOOT_DRVINFO() declaration in your board file:
.. code-block:: c
.deactivate_delay_us = ...
};
- U_BOOT_DEVICE(board_spi0) = {
+ U_BOOT_DRVINFO(board_spi0) = {
.name = "exynos_spi",
.plat = &platdata_spi0,
};
SYS_CFG_SATA_MSK, SYS_CFG_SATA_EN);
}
- ofnode_read_u32(dev->node, "ports-implemented", &hpriv->port_map);
+ ofnode_read_u32(dev_ofnode(dev), "ports-implemented",
+ &hpriv->port_map);
return 0;
}
{
int ret;
- if (!dev_of_valid(dev))
+ if (!dev_has_ofnode(dev))
return 0;
/* If this not in SPL and pre-reloc state, don't take any action. */
}
clk->enable_count = 0;
+
/* Store back pointer to clk from udevice */
- clk->dev->uclass_priv = clk;
+ /* FIXME: This is not allowed...should be allocated by driver model */
+ dev_set_uclass_priv(clk->dev, clk);
return 0;
}
bool clk_dev_binded(struct clk *clk)
{
- if (clk->dev && (clk->dev->flags & DM_FLAG_BOUND))
+ if (clk->dev && (dev_get_flags(clk->dev) & DM_FLAG_BOUND))
return true;
return false;
#include <common.h>
#include <clk-uclass.h>
#include <dm.h>
+#include <dm/device-internal.h>
#include <linux/clk-provider.h>
static ulong clk_fixed_rate_get_rate(struct clk *clk)
dev_read_u32_default(dev, "clock-frequency", 0);
#endif
/* Make fixed rate clock accessible from higher level struct clk */
- dev->uclass_priv = clk;
+ /* FIXME: This is not allowed */
+ dev_set_uclass_priv(dev, clk);
clk->dev = dev;
clk->enable_count = 0;
int ret;
ret = uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(stm32mp1_clock),
+ DM_DRIVER_GET(stm32mp1_clock),
&dev);
if (ret)
return ret;
int i, ret;
ret = uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(zynqmp_clk), &dev);
+ DM_DRIVER_GET(zynqmp_clk), &dev);
if (ret)
return ret;
int i, ret;
ret = uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(imx8_clk), &dev);
+ DM_DRIVER_GET(imx8_clk), &dev);
if (ret)
return ret;
switch (fdiv->flags & CLK_PARENT_MASK) {
case CLK_PARENT_APMIXED:
rate = mtk_clk_find_parent_rate(clk, fdiv->parent,
- DM_GET_DRIVER(mtk_clk_apmixedsys));
+ DM_DRIVER_GET(mtk_clk_apmixedsys));
break;
case CLK_PARENT_TOPCKGEN:
rate = mtk_clk_find_parent_rate(clk, fdiv->parent, NULL);
switch (gate->flags & CLK_PARENT_MASK) {
case CLK_PARENT_APMIXED:
return mtk_clk_find_parent_rate(clk, gate->parent,
- DM_GET_DRIVER(mtk_clk_apmixedsys));
+ DM_DRIVER_GET(mtk_clk_apmixedsys));
break;
case CLK_PARENT_TOPCKGEN:
return mtk_clk_find_parent_rate(clk, gate->parent,
- DM_GET_DRIVER(mtk_clk_topckgen));
+ DM_DRIVER_GET(mtk_clk_topckgen));
break;
default:
{
struct meson_clk *priv = dev_get_priv(dev);
- priv->map = syscon_node_to_regmap(dev_get_parent(dev)->node);
+ priv->map = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev)));
if (IS_ERR(priv->map))
return PTR_ERR(priv->map);
{
struct meson_clk *priv = dev_get_priv(dev);
- priv->map = syscon_node_to_regmap(dev_get_parent(dev)->node);
+ priv->map = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev)));
if (IS_ERR(priv->map))
return PTR_ERR(priv->map);
{
struct meson_clk *priv = dev_get_priv(dev);
- priv->map = syscon_node_to_regmap(dev_get_parent(dev)->node);
+ priv->map = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev)));
if (IS_ERR(priv->map))
return PTR_ERR(priv->map);
#include <asm/arch-rockchip/cru_px30.h>
#include <asm/arch-rockchip/hardware.h>
#include <asm/io.h>
+#include <dm/device-internal.h>
#include <dm/lists.h>
#include <dt-bindings/clock/px30-cru.h>
#include <linux/bitops.h>
glb_srst_fst);
priv->glb_srst_snd_value = offsetof(struct px30_cru,
glb_srst_snd);
- sys_child->priv = priv;
+ dev_set_priv(sys_child, priv);
}
#if CONFIG_IS_ENABLED(RESET_ROCKCHIP)
#include <asm/arch-rockchip/clock.h>
#include <asm/arch-rockchip/cru_rk3036.h>
#include <asm/arch-rockchip/hardware.h>
+#include <dm/device-internal.h>
#include <dm/lists.h>
#include <dt-bindings/clock/rk3036-cru.h>
#include <linux/delay.h>
cru_glb_srst_fst_value);
priv->glb_srst_snd_value = offsetof(struct rk3036_cru,
cru_glb_srst_snd_value);
- sys_child->priv = priv;
+ dev_set_priv(sys_child, priv);
}
#if CONFIG_IS_ENABLED(RESET_ROCKCHIP)
#include <asm/arch-rockchip/cru_rk3128.h>
#include <asm/arch-rockchip/hardware.h>
#include <bitfield.h>
+#include <dm/device-internal.h>
#include <dm/lists.h>
#include <dt-bindings/clock/rk3128-cru.h>
#include <linux/delay.h>
cru_glb_srst_fst_value);
priv->glb_srst_snd_value = offsetof(struct rk3128_cru,
cru_glb_srst_snd_value);
- sys_child->priv = priv;
+ dev_set_priv(sys_child, priv);
}
return 0;
cru_glb_srst_fst_value);
priv->glb_srst_snd_value = offsetof(struct rk3188_cru,
cru_glb_srst_snd_value);
- sys_child->priv = priv;
+ dev_set_priv(sys_child, priv);
}
#if CONFIG_IS_ENABLED(RESET_ROCKCHIP)
#include <asm/arch-rockchip/clock.h>
#include <asm/arch-rockchip/cru_rk322x.h>
#include <asm/arch-rockchip/hardware.h>
+#include <dm/device-internal.h>
#include <dm/lists.h>
#include <dt-bindings/clock/rk3228-cru.h>
#include <linux/bitops.h>
cru_glb_srst_fst_value);
priv->glb_srst_snd_value = offsetof(struct rk322x_cru,
cru_glb_srst_snd_value);
- sys_child->priv = priv;
+ dev_set_priv(sys_child, priv);
}
#if CONFIG_IS_ENABLED(RESET_ROCKCHIP)
cru_glb_srst_fst_value);
priv->glb_srst_snd_value = offsetof(struct rockchip_cru,
cru_glb_srst_snd_value);
- sys_child->priv = priv;
+ dev_set_priv(sys_child, priv);
}
#if CONFIG_IS_ENABLED(RESET_ROCKCHIP)
#include <asm/arch/cru_rk3308.h>
#include <asm/arch-rockchip/clock.h>
#include <asm/arch-rockchip/hardware.h>
+#include <dm/device-internal.h>
#include <dm/lists.h>
#include <dt-bindings/clock/rk3308-cru.h>
#include <linux/bitops.h>
glb_srst_fst);
priv->glb_srst_snd_value = offsetof(struct rk3308_cru,
glb_srst_snd);
- sys_child->priv = priv;
+ dev_set_priv(sys_child, priv);
}
#if CONFIG_IS_ENABLED(RESET_ROCKCHIP)
#include <asm/arch-rockchip/hardware.h>
#include <asm/arch-rockchip/grf_rk3328.h>
#include <asm/io.h>
+#include <dm/device-internal.h>
#include <dm/lists.h>
#include <dt-bindings/clock/rk3328-cru.h>
#include <linux/bitops.h>
glb_srst_fst_value);
priv->glb_srst_snd_value = offsetof(struct rk3328_cru,
glb_srst_snd_value);
- sys_child->priv = priv;
+ dev_set_priv(sys_child, priv);
}
#if CONFIG_IS_ENABLED(RESET_ROCKCHIP)
#include <asm/arch-rockchip/cru_rk3368.h>
#include <asm/arch-rockchip/hardware.h>
#include <asm/io.h>
+#include <dm/device-internal.h>
#include <dm/lists.h>
#include <dt-bindings/clock/rk3368-cru.h>
#include <linux/delay.h>
glb_srst_fst_val);
priv->glb_srst_snd_value = offsetof(struct rk3368_cru,
glb_srst_snd_val);
- sys_child->priv = priv;
+ dev_set_priv(sys_child, priv);
}
#if CONFIG_IS_ENABLED(RESET_ROCKCHIP)
#include <asm/arch-rockchip/clock.h>
#include <asm/arch-rockchip/cru.h>
#include <asm/arch-rockchip/hardware.h>
+#include <dm/device-internal.h>
#include <dm/lists.h>
#include <dt-bindings/clock/rk3399-cru.h>
#include <linux/bitops.h>
glb_srst_fst_value);
priv->glb_srst_snd_value = offsetof(struct rockchip_cru,
glb_srst_snd_value);
- sys_child->priv = priv;
+ dev_set_priv(sys_child, priv);
}
#if CONFIG_IS_ENABLED(RESET_ROCKCHIP)
#include <asm/arch-rockchip/clock.h>
#include <asm/arch-rockchip/cru_rv1108.h>
#include <asm/arch-rockchip/hardware.h>
+#include <dm/device-internal.h>
#include <dm/lists.h>
#include <dt-bindings/clock/rv1108-cru.h>
#include <linux/delay.h>
glb_srst_fst_val);
priv->glb_srst_snd_value = offsetof(struct rv1108_cru,
glb_srst_snd_val);
- sys_child->priv = priv;
+ dev_set_priv(sys_child, priv);
}
#if CONFIG_IS_ENABLED(RESET_ROCKCHIP)
int ret;
ret = uclass_get_device_by_driver(UCLASS_RESET,
- DM_GET_DRIVER(sifive_reset),
+ DM_DRIVER_GET(sifive_reset),
&dev);
if (ret) {
dev_err(dev, "Reset driver not found: %d\n", ret);
if (!dev)
return log_msg_ret("dev", -EINVAL);
- if (dev->flags & DM_FLAG_ACTIVATED)
+ if (dev_get_flags(dev) & DM_FLAG_ACTIVATED)
return log_msg_ret("active", -EINVAL);
- if (!(dev->flags & DM_FLAG_BOUND))
+ if (!(dev_get_flags(dev) & DM_FLAG_BOUND))
return log_msg_ret("not-bound", -EINVAL);
drv = dev->driver;
if (ret)
return log_msg_ret("child unbind", ret);
- if (dev->flags & DM_FLAG_ALLOC_PDATA) {
- free(dev->plat);
- dev->plat = NULL;
+ if (dev_get_flags(dev) & DM_FLAG_ALLOC_PDATA) {
+ free(dev_get_plat(dev));
+ dev_set_plat(dev, NULL);
}
- if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) {
- free(dev->uclass_plat);
- dev->uclass_plat = NULL;
+ if (dev_get_flags(dev) & DM_FLAG_ALLOC_UCLASS_PDATA) {
+ free(dev_get_uclass_plat(dev));
+ dev_set_uclass_plat(dev, NULL);
}
- if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) {
- free(dev->parent_plat);
- dev->parent_plat = NULL;
+ if (dev_get_flags(dev) & DM_FLAG_ALLOC_PARENT_PDATA) {
+ free(dev_get_parent_plat(dev));
+ dev_set_parent_plat(dev, NULL);
}
ret = uclass_unbind_device(dev);
if (ret)
devres_release_all(dev);
- if (dev->flags & DM_FLAG_NAME_ALLOCED)
+ if (dev_get_flags(dev) & DM_FLAG_NAME_ALLOCED)
free((char *)dev->name);
free(dev);
int size;
if (dev->driver->priv_auto) {
- free(dev->priv);
- dev->priv = NULL;
+ free(dev_get_priv(dev));
+ dev_set_priv(dev, NULL);
}
size = dev->uclass->uc_drv->per_device_auto;
if (size) {
- free(dev->uclass_priv);
- dev->uclass_priv = NULL;
+ free(dev_get_uclass_priv(dev));
+ dev_set_uclass_priv(dev, NULL);
}
if (dev->parent) {
size = dev->parent->driver->per_child_auto;
per_child_auto;
}
if (size) {
- free(dev->parent_priv);
- dev->parent_priv = NULL;
+ free(dev_get_parent_priv(dev));
+ dev_set_parent_priv(dev, NULL);
}
}
- dev->flags &= ~DM_FLAG_PLATDATA_VALID;
+ dev_bic_flags(dev, DM_FLAG_PLATDATA_VALID);
devres_release_probe(dev);
}
if (!dev)
return -EINVAL;
- if (!(dev->flags & DM_FLAG_ACTIVATED))
+ if (!(dev_get_flags(dev) & DM_FLAG_ACTIVATED))
return 0;
drv = dev->driver;
if (flags_remove(flags, drv->flags)) {
device_free(dev);
- dev->flags &= ~DM_FLAG_ACTIVATED;
+ dev_bic_flags(dev, DM_FLAG_ACTIVATED);
}
return ret;
struct uclass *uc;
int size, ret = 0;
bool auto_seq = true;
+ void *ptr;
if (devp)
*devp = NULL;
#ifdef CONFIG_DEVRES
INIT_LIST_HEAD(&dev->devres_head);
#endif
- dev->plat = plat;
+ dev_set_plat(dev, plat);
dev->driver_data = driver_data;
dev->name = name;
- dev->node = node;
+ dev_set_ofnode(dev, node);
dev->parent = parent;
dev->driver = drv;
dev->uclass = uc;
- dev->sqq = -1;
+ dev->seq_ = -1;
if (CONFIG_IS_ENABLED(DM_SEQ_ALIAS) &&
(uc->uc_drv->flags & DM_UC_FLAG_SEQ_ALIAS)) {
/*
if (CONFIG_IS_ENABLED(OF_CONTROL) &&
!CONFIG_IS_ENABLED(OF_PLATDATA)) {
if (uc->uc_drv->name && ofnode_valid(node)) {
- if (!dev_read_alias_seq(dev, &dev->sqq))
+ if (!dev_read_alias_seq(dev, &dev->seq_))
auto_seq = false;
}
}
}
if (auto_seq && !(uc->uc_drv->flags & DM_UC_FLAG_NO_AUTO_SEQ))
- dev->sqq = uclass_find_next_free_seq(uc);
+ dev->seq_ = uclass_find_next_free_seq(uc);
if (drv->plat_auto) {
bool alloc = !plat;
if (CONFIG_IS_ENABLED(OF_PLATDATA)) {
if (of_plat_size) {
- dev->flags |= DM_FLAG_OF_PLATDATA;
+ dev_or_flags(dev, DM_FLAG_OF_PLATDATA);
if (of_plat_size < drv->plat_auto)
alloc = true;
}
}
if (alloc) {
- dev->flags |= DM_FLAG_ALLOC_PDATA;
- dev->plat = calloc(1, drv->plat_auto);
- if (!dev->plat) {
+ dev_or_flags(dev, DM_FLAG_ALLOC_PDATA);
+ ptr = calloc(1, drv->plat_auto);
+ if (!ptr) {
ret = -ENOMEM;
goto fail_alloc1;
}
- if (CONFIG_IS_ENABLED(OF_PLATDATA) && plat) {
- memcpy(dev->plat, plat, of_plat_size);
- }
+ if (CONFIG_IS_ENABLED(OF_PLATDATA) && plat)
+ memcpy(ptr, plat, of_plat_size);
+ dev_set_plat(dev, ptr);
}
}
size = uc->uc_drv->per_device_plat_auto;
if (size) {
- dev->flags |= DM_FLAG_ALLOC_UCLASS_PDATA;
- dev->uclass_plat = calloc(1, size);
- if (!dev->uclass_plat) {
+ dev_or_flags(dev, DM_FLAG_ALLOC_UCLASS_PDATA);
+ ptr = calloc(1, size);
+ if (!ptr) {
ret = -ENOMEM;
goto fail_alloc2;
}
+ dev_set_uclass_plat(dev, ptr);
}
if (parent) {
size = parent->uclass->uc_drv->per_child_plat_auto;
}
if (size) {
- dev->flags |= DM_FLAG_ALLOC_PARENT_PDATA;
- dev->parent_plat = calloc(1, size);
- if (!dev->parent_plat) {
+ dev_or_flags(dev, DM_FLAG_ALLOC_PARENT_PDATA);
+ ptr = calloc(1, size);
+ if (!ptr) {
ret = -ENOMEM;
goto fail_alloc3;
}
+ dev_set_parent_plat(dev, ptr);
}
/* put dev into parent's successor list */
list_add_tail(&dev->sibling_node, &parent->child_head);
if (devp)
*devp = dev;
- dev->flags |= DM_FLAG_BOUND;
+ dev_or_flags(dev, DM_FLAG_BOUND);
return 0;
fail_uclass_bind:
if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) {
list_del(&dev->sibling_node);
- if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) {
- free(dev->parent_plat);
- dev->parent_plat = NULL;
+ if (dev_get_flags(dev) & DM_FLAG_ALLOC_PARENT_PDATA) {
+ free(dev_get_parent_plat(dev));
+ dev_set_parent_plat(dev, NULL);
}
}
fail_alloc3:
- if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) {
- free(dev->uclass_plat);
- dev->uclass_plat = NULL;
+ if (dev_get_flags(dev) & DM_FLAG_ALLOC_UCLASS_PDATA) {
+ free(dev_get_uclass_plat(dev));
+ dev_set_uclass_plat(dev, NULL);
}
fail_alloc2:
- if (dev->flags & DM_FLAG_ALLOC_PDATA) {
- free(dev->plat);
- dev->plat = NULL;
+ if (dev_get_flags(dev) & DM_FLAG_ALLOC_PDATA) {
+ free(dev_get_plat(dev));
+ dev_set_plat(dev, NULL);
}
fail_alloc1:
devres_release_all(dev);
return priv;
}
+/**
+ * device_alloc_priv() - Allocate priv/plat data required by the device
+ *
+ * @dev: Device to process
+ * @return 0 if OK, -ENOMEM if out of memory
+ */
+static int device_alloc_priv(struct udevice *dev)
+{
+ const struct driver *drv;
+ void *ptr;
+ int size;
+
+ drv = dev->driver;
+ assert(drv);
+
+ /* Allocate private data if requested and not reentered */
+ if (drv->priv_auto && !dev_get_priv(dev)) {
+ ptr = alloc_priv(drv->priv_auto, drv->flags);
+ if (!ptr)
+ return -ENOMEM;
+ dev_set_priv(dev, ptr);
+ }
+
+ /* Allocate private data if requested and not reentered */
+ size = dev->uclass->uc_drv->per_device_auto;
+ if (size && !dev_get_uclass_priv(dev)) {
+ ptr = alloc_priv(size, dev->uclass->uc_drv->flags);
+ if (!ptr)
+ return -ENOMEM;
+ dev_set_uclass_priv(dev, ptr);
+ }
+
+ /* Allocate parent data for this child */
+ if (dev->parent) {
+ size = dev->parent->driver->per_child_auto;
+ if (!size)
+ size = dev->parent->uclass->uc_drv->per_child_auto;
+ if (size && !dev_get_parent_priv(dev)) {
+ ptr = alloc_priv(size, drv->flags);
+ if (!ptr)
+ return -ENOMEM;
+ dev_set_parent_priv(dev, ptr);
+ }
+ }
+
+ return 0;
+}
+
int device_of_to_plat(struct udevice *dev)
{
const struct driver *drv;
- int size = 0;
int ret;
if (!dev)
return -EINVAL;
- if (dev->flags & DM_FLAG_PLATDATA_VALID)
+ if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID)
return 0;
/* Ensure all parents have ofdata */
* (e.g. PCI bridge devices). Test the flags again
* so that we don't mess up the device.
*/
- if (dev->flags & DM_FLAG_PLATDATA_VALID)
+ if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID)
return 0;
}
+ ret = device_alloc_priv(dev);
+ if (ret)
+ goto fail;
+
drv = dev->driver;
assert(drv);
- /* Allocate private data if requested and not reentered */
- if (drv->priv_auto && !dev->priv) {
- dev->priv = alloc_priv(drv->priv_auto, drv->flags);
- if (!dev->priv) {
- ret = -ENOMEM;
- goto fail;
- }
- }
- /* Allocate private data if requested and not reentered */
- size = dev->uclass->uc_drv->per_device_auto;
- if (size && !dev->uclass_priv) {
- dev->uclass_priv = alloc_priv(size,
- dev->uclass->uc_drv->flags);
- if (!dev->uclass_priv) {
- ret = -ENOMEM;
- goto fail;
- }
- }
-
- /* Allocate parent data for this child */
- if (dev->parent) {
- size = dev->parent->driver->per_child_auto;
- if (!size) {
- size = dev->parent->uclass->uc_drv->per_child_auto;
- }
- if (size && !dev->parent_priv) {
- dev->parent_priv = alloc_priv(size, drv->flags);
- if (!dev->parent_priv) {
- ret = -ENOMEM;
- goto fail;
- }
- }
- }
-
if (drv->of_to_plat &&
- (CONFIG_IS_ENABLED(OF_PLATDATA) || dev_has_of_node(dev))) {
+ (CONFIG_IS_ENABLED(OF_PLATDATA) || dev_has_ofnode(dev))) {
ret = drv->of_to_plat(dev);
if (ret)
goto fail;
}
- dev->flags |= DM_FLAG_PLATDATA_VALID;
+ dev_or_flags(dev, DM_FLAG_PLATDATA_VALID);
return 0;
fail:
if (!dev)
return -EINVAL;
- if (dev->flags & DM_FLAG_ACTIVATED)
+ if (dev_get_flags(dev) & DM_FLAG_ACTIVATED)
return 0;
drv = dev->driver;
* (e.g. PCI bridge devices). Test the flags again
* so that we don't mess up the device.
*/
- if (dev->flags & DM_FLAG_ACTIVATED)
+ if (dev_get_flags(dev) & DM_FLAG_ACTIVATED)
return 0;
}
- dev->flags |= DM_FLAG_ACTIVATED;
+ dev_or_flags(dev, DM_FLAG_ACTIVATED);
/*
* Process pinctrl for everything except the root device, and
}
/* Only handle devices that have a valid ofnode */
- if (dev_of_valid(dev)) {
+ if (dev_has_ofnode(dev)) {
/*
* Process 'assigned-{clocks/clock-parents/clock-rates}'
* properties
__func__, dev->name);
}
fail:
- dev->flags &= ~DM_FLAG_ACTIVATED;
+ dev_bic_flags(dev, DM_FLAG_ACTIVATED);
device_free(dev);
return NULL;
}
- return dev->plat;
+ return dev->plat_;
}
void *dev_get_parent_plat(const struct udevice *dev)
return NULL;
}
- return dev->parent_plat;
+ return dev->parent_plat_;
}
void *dev_get_uclass_plat(const struct udevice *dev)
return NULL;
}
- return dev->uclass_plat;
+ return dev->uclass_plat_;
}
void *dev_get_priv(const struct udevice *dev)
return NULL;
}
- return dev->priv;
+ return dev->priv_;
}
void *dev_get_uclass_priv(const struct udevice *dev)
return NULL;
}
- return dev->uclass_priv;
+ return dev->uclass_priv_;
}
void *dev_get_parent_priv(const struct udevice *dev)
return NULL;
}
- return dev->parent_priv;
+ return dev->parent_priv_;
}
static int device_get_device_tail(struct udevice *dev, int ret,
struct udevice *dev;
int ret;
- list_for_each_entry(uc, &gd->uclass_root, sibling_node) {
+ list_for_each_entry(uc, gd->uclass_root, sibling_node) {
ret = uclass_find_device_by_ofnode(uc->uc_drv->id, node,
&dev);
if (!ret || dev) {
*devp = NULL;
list_for_each_entry(dev, &parent->child_head, sibling_node) {
- if (dev->sqq == seq) {
+ if (dev->seq_ == seq) {
*devp = dev;
return 0;
}
void device_set_name_alloced(struct udevice *dev)
{
- dev->flags |= DM_FLAG_NAME_ALLOCED;
+ dev_or_flags(dev, DM_FLAG_NAME_ALLOCED);
}
int device_set_name(struct udevice *dev, const char *name)
return 0;
}
+void dev_set_priv(struct udevice *dev, void *priv)
+{
+ dev->priv_ = priv;
+}
+
+void dev_set_parent_priv(struct udevice *dev, void *parent_priv)
+{
+ dev->parent_priv_ = parent_priv;
+}
+
+void dev_set_uclass_priv(struct udevice *dev, void *uclass_priv)
+{
+ dev->uclass_priv_ = uclass_priv;
+}
+
+void dev_set_plat(struct udevice *dev, void *plat)
+{
+ dev->plat_ = plat;
+}
+
+void dev_set_parent_plat(struct udevice *dev, void *parent_plat)
+{
+ dev->parent_plat_ = parent_plat;
+}
+
+void dev_set_uclass_plat(struct udevice *dev, void *uclass_plat)
+{
+ dev->uclass_plat_ = uclass_plat;
+}
+
#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
bool device_is_compatible(const struct udevice *dev, const char *compat)
{
if (!of_live_active())
return -ENOSYS;
- list_for_each_entry(uc, &gd->uclass_root, sibling_node) {
+ list_for_each_entry(uc, gd->uclass_root, sibling_node) {
ret = uclass_find_device_by_ofnode(uc->uc_drv->id, node, &dev);
if (!ret)
break;
devres_log(dev, dr, "ADD");
assert_noisy(list_empty(&dr->entry));
- if (dev->flags & DM_FLAG_PLATDATA_VALID)
+ if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID)
dr->phase = DEVRES_PHASE_PROBE;
- else if (dev->flags & DM_FLAG_BOUND)
+ else if (dev_get_flags(dev) & DM_FLAG_BOUND)
dr->phase = DEVRES_PHASE_OFDATA;
else
dr->phase = DEVRES_PHASE_BIND;
{
int i, is_last;
struct udevice *child;
+ u32 flags = dev_get_flags(dev);
/* print the first 20 characters to not break the tree-format. */
- printf(" %-10.10s %3d [ %c ] %-20.20s ", dev->uclass->uc_drv->name,
+ printf(IS_ENABLED(CONFIG_SPL_BUILD) ? " %s %d [ %c ] %s " :
+ " %-10.10s %3d [ %c ] %-20.20s ", dev->uclass->uc_drv->name,
dev_get_uclass_index(dev, NULL),
- dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ', dev->driver->name);
+ flags & DM_FLAG_ACTIVATED ? '+' : ' ', dev->driver->name);
for (i = depth; i >= 0; i--) {
is_last = (last_flag >> i) & 1;
static void dm_display_line(struct udevice *dev, int index)
{
printf("%-3i %c %s @ %08lx", index,
- dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ',
+ dev_get_flags(dev) & DM_FLAG_ACTIVATED ? '*' : ' ',
dev->name, (ulong)map_to_sysmem(dev));
- if (dev->sqq != -1)
+ if (dev->seq_ != -1)
printf(", seq %d", dev_seq(dev));
puts("\n");
}
struct uclass_driver *lists_uclass_lookup(enum uclass_id id)
{
struct uclass_driver *uclass =
- ll_entry_start(struct uclass_driver, uclass);
- const int n_ents = ll_entry_count(struct uclass_driver, uclass);
+ ll_entry_start(struct uclass_driver, uclass_driver);
+ const int n_ents = ll_entry_count(struct uclass_driver, uclass_driver);
struct uclass_driver *entry;
for (entry = uclass; entry != uclass + n_ents; entry++) {
if (ret) {
dm_warn("Error binding driver '%s': %d\n", entry->name,
ret);
- return ret;
+ return log_msg_ret("bind", ret);
} else {
found = true;
if (devp)
{
/* The sentinel node has moved, so update things that point to it */
if (gd->dm_root) {
- new_gd->uclass_root.next->prev = &new_gd->uclass_root;
- new_gd->uclass_root.prev->next = &new_gd->uclass_root;
+ new_gd->uclass_root->next->prev = new_gd->uclass_root;
+ new_gd->uclass_root->prev->next = new_gd->uclass_root;
}
}
void fix_uclass(void)
{
struct uclass_driver *uclass =
- ll_entry_start(struct uclass_driver, uclass);
- const int n_ents = ll_entry_count(struct uclass_driver, uclass);
+ ll_entry_start(struct uclass_driver, uclass_driver);
+ const int n_ents = ll_entry_count(struct uclass_driver, uclass_driver);
struct uclass_driver *entry;
for (entry = uclass; entry != uclass + n_ents; entry++) {
dm_warn("Virtual root driver already exists!\n");
return -EINVAL;
}
- INIT_LIST_HEAD(&DM_UCLASS_ROOT_NON_CONST);
+ gd->uclass_root = &DM_UCLASS_ROOT_S_NON_CONST;
+ INIT_LIST_HEAD(DM_UCLASS_ROOT_NON_CONST);
if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC)) {
fix_drivers();
if (ret)
return ret;
if (CONFIG_IS_ENABLED(OF_CONTROL))
- DM_ROOT_NON_CONST->node = ofnode_root();
+ dev_set_ofnode(DM_ROOT_NON_CONST, ofnode_root());
ret = device_probe(DM_ROOT_NON_CONST);
if (ret)
return ret;
return 0;
}
-int dm_init_and_scan(bool pre_reloc_only)
+/**
+ * dm_scan() - Scan tables to bind devices
+ *
+ * Runs through the driver_info tables and binds the devices it finds. Then runs
+ * through the devicetree nodes. Finally calls dm_scan_other() to add any
+ * special devices
+ *
+ * @pre_reloc_only: If true, bind only nodes with special devicetree properties,
+ * or drivers with the DM_FLAG_PRE_RELOC flag. If false bind all drivers.
+ */
+static int dm_scan(bool pre_reloc_only)
{
int ret;
- if (CONFIG_IS_ENABLED(OF_PLATDATA))
- dm_populate_phandle_data();
-
- ret = dm_init(CONFIG_IS_ENABLED(OF_LIVE));
- if (ret) {
- debug("dm_init() failed: %d\n", ret);
- return ret;
- }
ret = dm_scan_plat(pre_reloc_only);
if (ret) {
debug("dm_scan_plat() failed: %d\n", ret);
- goto fail;
+ return ret;
}
if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) {
ret = dm_extended_scan(pre_reloc_only);
if (ret) {
debug("dm_extended_scan() failed: %d\n", ret);
- goto fail;
+ return ret;
}
}
ret = dm_scan_other(pre_reloc_only);
if (ret)
- goto fail;
+ return ret;
+
+ return 0;
+}
+
+int dm_init_and_scan(bool pre_reloc_only)
+{
+ int ret;
+
+ ret = dm_init(CONFIG_IS_ENABLED(OF_LIVE));
+ if (ret) {
+ debug("dm_init() failed: %d\n", ret);
+ return ret;
+ }
+ ret = dm_scan(pre_reloc_only);
+ if (ret) {
+ log_debug("dm_scan() failed: %d\n", ret);
+ return ret;
+ }
return 0;
-fail:
- return ret;
}
#ifdef CONFIG_ACPIGEN
#include <common.h>
#include <dm.h>
-
-struct simple_bus_plat {
- u32 base;
- u32 size;
- u32 target;
-};
+#include <dm/simple_bus.h>
fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr)
{
.per_device_plat_auto = sizeof(struct simple_bus_plat),
};
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
static const struct udevice_id generic_simple_bus_ids[] = {
{ .compatible = "simple-bus" },
{ .compatible = "simple-mfd" },
{ }
};
+#endif
U_BOOT_DRIVER(simple_bus) = {
.name = "simple_bus",
.id = UCLASS_SIMPLE_BUS,
- .of_match = generic_simple_bus_ids,
+ .of_match = of_match_ptr(generic_simple_bus_ids),
.flags = DM_FLAG_PRE_RELOC,
};
* node to the start of the list, or creating a linear array mapping
* id to node.
*/
- list_for_each_entry(uc, &gd->uclass_root, sibling_node) {
+ list_for_each_entry(uc, gd->uclass_root, sibling_node) {
if (uc->uc_drv->id == key)
return uc;
}
if (!uc)
return -ENOMEM;
if (uc_drv->priv_auto) {
- uc->priv = calloc(1, uc_drv->priv_auto);
- if (!uc->priv) {
+ void *ptr;
+
+ ptr = calloc(1, uc_drv->priv_auto);
+ if (!ptr) {
ret = -ENOMEM;
goto fail_mem;
}
+ uclass_set_priv(uc, ptr);
}
uc->uc_drv = uc_drv;
INIT_LIST_HEAD(&uc->sibling_node);
INIT_LIST_HEAD(&uc->dev_head);
- list_add(&uc->sibling_node, &DM_UCLASS_ROOT_NON_CONST);
+ list_add(&uc->sibling_node, DM_UCLASS_ROOT_NON_CONST);
if (uc_drv->init) {
ret = uc_drv->init(uc);
return 0;
fail:
if (uc_drv->priv_auto) {
- free(uc->priv);
- uc->priv = NULL;
+ free(uclass_get_priv(uc));
+ uclass_set_priv(uc, NULL);
}
list_del(&uc->sibling_node);
fail_mem:
uc_drv->destroy(uc);
list_del(&uc->sibling_node);
if (uc_drv->priv_auto)
- free(uc->priv);
+ free(uclass_get_priv(uc));
free(uc);
return 0;
return uc->uc_drv->name;
}
+void *uclass_get_priv(const struct uclass *uc)
+{
+ return uc->priv_;
+}
+
+void uclass_set_priv(struct uclass *uc, void *priv)
+{
+ uc->priv_ = priv;
+}
+
enum uclass_id uclass_get_by_name(const char *name)
{
int i;
/* Avoid conflict with existing devices */
list_for_each_entry(dev, &uc->dev_head, uclass_node) {
- if (dev->sqq > max)
- max = dev->sqq;
+ if (dev->seq_ > max)
+ max = dev->seq_;
}
/*
* At this point, max will be -1 if there are no existing aliases or
return ret;
uclass_foreach_dev(dev, uc) {
- log_debug(" - %d '%s'\n", dev->sqq, dev->name);
- if (dev->sqq == seq) {
+ log_debug(" - %d '%s'\n", dev->seq_, dev->name);
+ if (dev->seq_ == seq) {
*devp = dev;
log_debug(" - found\n");
return 0;
.ops = &fsl_mod_exp_ops,
};
-U_BOOT_DEVICE(fsl_rsa) = {
+U_BOOT_DRVINFO(fsl_rsa) = {
.name = "fsl_rsa_mod_exp",
};
.flags = DM_FLAG_PRE_RELOC,
};
-U_BOOT_DEVICE(mod_exp_sw) = {
+U_BOOT_DRVINFO(mod_exp_sw) = {
.name = "mod_exp_sw",
};
int sdram_mmr_init_full(struct udevice *dev)
{
- struct altera_sdram_plat *plat = dev->plat;
+ struct altera_sdram_plat *plat = dev_get_plat(dev);
struct altera_sdram_priv *priv = dev_get_priv(dev);
u32 i;
int ret;
static int altera_gen5_sdram_of_to_plat(struct udevice *dev)
{
- struct altera_gen5_sdram_plat *plat = dev->plat;
+ struct altera_gen5_sdram_plat *plat = dev_get_plat(dev);
plat->sdr = (struct socfpga_sdr *)devfdt_get_addr_index(dev, 0);
if (!plat->sdr)
{
int ret;
unsigned long sdram_size;
- struct altera_gen5_sdram_plat *plat = dev->plat;
+ struct altera_gen5_sdram_plat *plat = dev_get_plat(dev);
struct altera_gen5_sdram_priv *priv = dev_get_priv(dev);
struct socfpga_sdr_ctrl *sdr_ctrl = &plat->sdr->sdr_ctrl;
struct reset_ctl_bulk resets;
*/
int sdram_mmr_init_full(struct udevice *dev)
{
- struct altera_sdram_plat *plat = dev->plat;
+ struct altera_sdram_plat *plat = dev_get_plat(dev);
struct altera_sdram_priv *priv = dev_get_priv(dev);
u32 update_value, io48_value, ddrioctl;
u32 i;
static int altera_sdram_of_to_plat(struct udevice *dev)
{
- struct altera_sdram_plat *plat = dev->plat;
+ struct altera_sdram_plat *plat = dev_get_plat(dev);
fdt_addr_t addr;
addr = dev_read_addr_index(dev, 0);
.sides = 6.
};
-U_BOOT_DEVICE(demo0) = {
+U_BOOT_DRVINFO(demo0) = {
.name = "demo_shape_drv",
.plat = &red_square,
};
-U_BOOT_DEVICE(demo1) = {
+U_BOOT_DRVINFO(demo1) = {
.name = "demo_simple_drv",
.plat = &red_square,
};
-U_BOOT_DEVICE(demo2) = {
+U_BOOT_DRVINFO(demo2) = {
.name = "demo_shape_drv",
.plat = &green_triangle,
};
-U_BOOT_DEVICE(demo3) = {
+U_BOOT_DRVINFO(demo3) = {
.name = "demo_simple_drv",
.plat = &yellow_hexagon,
};
-U_BOOT_DEVICE(demo4) = {
+U_BOOT_DRVINFO(demo4) = {
.name = "demo_shape_drv",
.plat = &yellow_hexagon,
};
switch (protocol_id) {
case SCMI_PROTOCOL_ID_CLOCK:
if (IS_ENABLED(CONFIG_CLK_SCMI))
- drv = DM_GET_DRIVER(scmi_clock);
+ drv = DM_DRIVER_GET(scmi_clock);
break;
case SCMI_PROTOCOL_ID_RESET_DOMAIN:
if (IS_ENABLED(CONFIG_RESET_SCMI))
- drv = DM_GET_DRIVER(scmi_reset_domain);
+ drv = DM_DRIVER_GET(scmi_reset_domain);
break;
default:
break;
static int gpio_dwapb_probe(struct udevice *dev)
{
struct gpio_dev_priv *priv = dev_get_uclass_priv(dev);
- struct gpio_dwapb_plat *plat = dev->plat;
+ struct gpio_dwapb_plat *plat = dev_get_plat(dev);
if (!plat) {
/* Reset on parent device only */
for (uclass_first_device(UCLASS_NOP, &dev);
dev;
uclass_find_next_device(&dev)) {
- if (dev->driver == DM_GET_DRIVER(gpio_hog)) {
+ if (dev->driver == DM_DRIVER_GET(gpio_hog)) {
ret = device_probe(dev);
if (ret) {
printf("Failed to probe device %s err: %d\n",
if (!dev)
return -1;
- uc_priv = dev->uclass_priv;
+ uc_priv = dev_get_uclass_priv(dev);
return uc_priv->gpio_base + desc->offset;
}
{
struct gpio_bank *bank = dev_get_priv(dev);
struct hikey_gpio_plat *plat = dev_get_plat(dev);
- struct gpio_dev_priv *uc_priv = dev->uclass_priv;
+ struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
char name[18], *str;
sprintf(name, "GPIO%d_", plat->bank_index);
#include <fdtdec.h>
#include <asm/gpio.h>
#include <asm/io.h>
+#include <dm/device-internal.h>
#include <malloc.h>
enum imx_rgpio2p_direction {
static int imx_rgpio2p_bind(struct udevice *dev)
{
- struct imx_rgpio2p_plat *plat = dev->plat;
+ struct imx_rgpio2p_plat *plat = dev_get_plat(dev);
fdt_addr_t addr;
/*
* If plat already exsits, directly return.
* Actually only when DT is not supported, plat
- * is statically initialized in U_BOOT_DEVICES.Here
+ * is statically initialized in U_BOOT_DRVINFOS.Here
* will return.
*/
if (plat)
plat->regs = (struct gpio_regs *)addr;
plat->bank_index = dev_seq(dev);
- dev->plat = plat;
+ dev_set_plat(dev, plat);
return 0;
}
{ 5, (struct gpio_regs *)RGPIO2P_GPIO6_BASE_ADDR },
};
-U_BOOT_DEVICES(imx_rgpio2ps) = {
+U_BOOT_DRVINFOS(imx_rgpio2ps) = {
{ "imx_rgpio2p", &imx_plat[0] },
{ "imx_rgpio2p", &imx_plat[1] },
{ "imx_rgpio2p", &imx_plat[2] },
#endif
};
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
static const struct udevice_id intel_intel_gpio_ids[] = {
{ .compatible = "intel,gpio" },
{ }
};
+#endif
U_BOOT_DRIVER(intel_gpio) = {
.name = "intel_gpio",
.id = UCLASS_GPIO,
- .of_match = intel_intel_gpio_ids,
+ .of_match = of_match_ptr(intel_intel_gpio_ids),
.ops = &gpio_intel_ops,
.of_to_plat = intel_gpio_of_to_plat,
.probe = intel_gpio_probe,
static int lpc32xx_gpio_probe(struct udevice *dev)
{
struct lpc32xx_gpio_priv *gpio_priv = dev_get_priv(dev);
- struct gpio_dev_priv *uc_priv = dev->uclass_priv;
+ struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
if (dev_of_offset(dev) == -1) {
/* Tell the uclass how many GPIOs we have */
u32 i;
u32 reg[4];
- if (ofnode_read_bool(dev->node, "little-endian"))
+ if (ofnode_read_bool(dev_ofnode(dev), "little-endian"))
data->little_endian = true;
if (data->little_endian)
if (!str)
return -ENOMEM;
- if (ofnode_device_is_compatible(dev->node, "fsl,qoriq-gpio")) {
+ if (ofnode_device_is_compatible(dev_ofnode(dev), "fsl,qoriq-gpio")) {
unsigned long gpibe = data->addr + sizeof(struct ccsr_gpio)
- sizeof(u32);
*/
static int gpio_mediatek_bind(struct udevice *parent)
{
- struct mediatek_gpio_plat *plat = parent->plat;
+ struct mediatek_gpio_plat *plat = dev_get_plat(parent);
ofnode node;
int bank = 0;
int ret;
.bind = mxc_gpio_bind,
};
-U_BOOT_DRIVER_ALIAS(gpio_mxc, fsl_imx6q_gpio)
+DM_DRIVER_ALIAS(gpio_mxc, fsl_imx6q_gpio)
#if !CONFIG_IS_ENABLED(OF_CONTROL)
static const struct mxc_gpio_plat mxc_plat[] = {
#endif
};
-U_BOOT_DEVICES(mxc_gpios) = {
+U_BOOT_DRVINFOS(mxc_gpios) = {
{ "gpio_mxc", &mxc_plat[0] },
{ "gpio_mxc", &mxc_plat[1] },
{ "gpio_mxc", &mxc_plat[2] },
#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
static int mxs_of_to_plat(struct udevice *dev)
{
- struct mxs_gpio_plat *plat = dev->plat;
+ struct mxs_gpio_plat *plat = dev_get_plat(dev);
struct fdtdec_phandle_args args;
int node = dev_of_offset(dev);
int ret;
#endif
};
-U_BOOT_DRIVER_ALIAS(fsl_imx23_gpio, fsl_imx28_gpio)
+DM_DRIVER_ALIAS(fsl_imx23_gpio, fsl_imx28_gpio)
#endif /* DM_GPIO */
GPIO_CONST_GPIOS_MASK;
} else {
priv->base = dev_remap_addr(dev);
- uc_priv->gpio_count = ofnode_read_u32_default(dev->node,
+ uc_priv->gpio_count = ofnode_read_u32_default(dev_ofnode(dev),
"nr-gpios", 32);
}
#include <fdtdec.h>
#include <asm/gpio.h>
#include <asm/io.h>
+#include <dm/device-internal.h>
#include <linux/errno.h>
#include <malloc.h>
plat->base = base_addr;
plat->port_name = fdt_get_name(gd->fdt_blob, dev_of_offset(dev), NULL);
- dev->plat = plat;
+ dev_set_plat(dev, plat);
return 0;
}
static int gpio_exynos_probe(struct udevice *dev)
{
struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
- struct exynos_bank_info *priv = dev->priv;
- struct exynos_gpio_plat *plat = dev->plat;
+ struct exynos_bank_info *priv = dev_get_priv(dev);
+ struct exynos_gpio_plat *plat = dev_get_plat(dev);
/* Only child devices have ports */
if (!plat)
*/
static int gpio_exynos_bind(struct udevice *parent)
{
- struct exynos_gpio_plat *plat = parent->plat;
+ struct exynos_gpio_plat *plat = dev_get_plat(parent);
struct s5p_gpio_bank *bank, *base;
const void *blob = gd->fdt_blob;
int node;
#include <acpi/acpi_device.h>
#include <asm/gpio.h>
#include <dm/acpi.h>
+#include <dm/device-internal.h>
#include <dm/device_compat.h>
#include <dm/lists.h>
#include <dm/of.h>
{
struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
- if (!dev_of_valid(dev))
+ if (!dev_has_ofnode(dev))
/* Tell the uclass how many GPIOs we have */
uc_priv->gpio_count = CONFIG_SANDBOX_GPIO_COUNT;
- dev->priv = calloc(sizeof(struct gpio_state), uc_priv->gpio_count);
+ dev_set_priv(dev,
+ calloc(sizeof(struct gpio_state), uc_priv->gpio_count));
return 0;
}
static int gpio_sandbox_remove(struct udevice *dev)
{
- free(dev->priv);
+ free(dev_get_priv(dev));
return 0;
}
ACPI_OPS_PTR(&gpio_sandbox_acpi_ops)
};
-U_BOOT_DRIVER_ALIAS(sandbox_gpio, sandbox_gpio_alias)
+DM_DRIVER_ALIAS(sandbox_gpio, sandbox_gpio_alias)
/* pincontrol: used only to check GPIO pin configuration (pinmux command) */
{
struct sunxi_gpio_soc_data *soc_data =
(struct sunxi_gpio_soc_data *)dev_get_driver_data(parent);
- struct sunxi_gpio_plat *plat = parent->plat;
+ struct sunxi_gpio_plat *plat = dev_get_plat(parent);
struct sunxi_gpio_reg *ctlr;
int bank, ret;
static uint32_t *tegra186_gpio_reg(struct udevice *dev, uint32_t reg,
uint32_t gpio)
{
- struct tegra186_gpio_plat *plat = dev->plat;
+ struct tegra186_gpio_plat *plat = dev_get_plat(dev);
uint32_t index = (reg + (gpio * TEGRA186_GPIO_PER_GPIO_STRIDE)) / 4;
return &(plat->regs[index]);
*/
static int tegra186_gpio_bind(struct udevice *parent)
{
- struct tegra186_gpio_plat *parent_plat = parent->plat;
+ struct tegra186_gpio_plat *parent_plat = dev_get_plat(parent);
struct tegra186_gpio_ctlr_data *ctlr_data =
(struct tegra186_gpio_ctlr_data *)dev_get_driver_data(parent);
uint32_t *regs;
static int tegra186_gpio_probe(struct udevice *dev)
{
- struct tegra186_gpio_plat *plat = dev->plat;
+ struct tegra186_gpio_plat *plat = dev_get_plat(dev);
struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
/* Only child devices have ports */
static int gpio_tegra_probe(struct udevice *dev)
{
struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
- struct tegra_port_info *priv = dev->priv;
- struct tegra_gpio_plat *plat = dev->plat;
+ struct tegra_port_info *priv = dev_get_priv(dev);
+ struct tegra_gpio_plat *plat = dev_get_plat(dev);
/* Only child devices have ports */
if (!plat)
*/
static int gpio_tegra_bind(struct udevice *parent)
{
- struct tegra_gpio_plat *plat = parent->plat;
+ struct tegra_gpio_plat *plat = dev_get_plat(parent);
struct gpio_ctlr *ctlr;
int bank_count;
int bank;
{
char name[20];
- if (dev_of_valid(dev))
+ if (dev_has_ofnode(dev))
return 0;
sprintf(name, "i2c_designware#%u", dev_seq(dev));
int ret;
/* If no device-tree node, ignore this since we assume it isn't used */
- if (!dev_of_valid(dev))
+ if (!dev_has_ofnode(dev))
return 0;
ret = acpi_device_path(dev, path, sizeof(path));
#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
struct dm_i2c_chip *plat = dev_get_parent_plat(dev);
- if (!dev_of_valid(dev))
+ if (!dev_has_ofnode(dev))
return 0;
return i2c_chip_of_to_plat(dev, plat);
#else
.ops = &rockchip_i2c_ops,
};
-U_BOOT_DRIVER_ALIAS(rockchip_rk3066_i2c, rockchip_rk3288_i2c)
+DM_DRIVER_ALIAS(rockchip_rk3066_i2c, rockchip_rk3288_i2c)
#include <errno.h>
#include <i2c.h>
#include <log.h>
+#include <asm/i2c.h>
#include <asm/test.h>
#include <dm/acpi.h>
#include <dm/lists.h>
#include <dm/device-internal.h>
-struct sandbox_i2c_priv {
- bool test_mode;
-};
-
static int get_emul(struct udevice *dev, struct udevice **devp,
struct dm_i2c_ops **opsp)
{
can make requests to the BPMP. This driver is similar to an MFD
driver in the Linux kernel.
+config TEST_DRV
+ bool "Enable support for test drivers"
+ default y if SANDBOX
+ help
+ This enables drivers and uclasses that provides a way of testing the
+ operations of memory allocation and driver/uclass methods in driver
+ model. This should only be enabled for testing as it is not useful for
+ anything else.
+
config TWL4030_LED
bool "Enable TWL4030 LED controller"
help
obj-$(CONFIG_SYS_DPAA_QBMAN) += fsl_portals.o
obj-$(CONFIG_TEGRA186_BPMP) += tegra186_bpmp.o
obj-$(CONFIG_TEGRA_CAR) += tegra_car.o
+obj-$(CONFIG_TEST_DRV) += test_drv.o
obj-$(CONFIG_TWL4030_LED) += twl4030_led.o
obj-$(CONFIG_VEXPRESS_CONFIG) += vexpress_config.o
obj-$(CONFIG_WINBOND_W83627) += winbond_w83627.o
static int altera_sysid_read(struct udevice *dev,
int offset, void *buf, int size)
{
- struct altera_sysid_plat *plat = dev->plat;
+ struct altera_sysid_plat *plat = dev_get_plat(dev);
struct altera_sysid_regs *const regs = plat->regs;
u32 *sysid = buf;
int cros_ec_probe(struct udevice *dev)
{
- struct ec_state *ec = dev->priv;
- struct cros_ec_dev *cdev = dev->uclass_priv;
+ struct ec_state *ec = dev_get_priv(dev);
+ struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
struct udevice *keyb_dev;
ofnode node;
int err;
else
ret = -ENODEV;
} else {
- ret = select_fs_dev(dev->plat);
+ ret = select_fs_dev(dev_get_plat(dev));
}
if (ret)
if (ofnode_valid(fs_loader_node)) {
struct device_plat *plat;
- plat = dev->plat;
+ plat = dev_get_plat(dev);
if (!ofnode_read_u32_array(fs_loader_node,
"phandlepart",
phandlepart, 2)) {
{
#if CONFIG_IS_ENABLED(DM) && CONFIG_IS_ENABLED(BLK)
int ret;
- struct device_plat *plat = dev->plat;
+ struct device_plat *plat = dev_get_plat(dev);
if (plat->phandlepart.phandle) {
ofnode node = ofnode_get_by_phandle(plat->phandlepart.phandle);
if (!name)
continue;
- device_bind(dev, DM_GET_DRIVER(i2c_eeprom_partition), name,
+ device_bind(dev, DM_DRIVER_GET(i2c_eeprom_partition), name,
NULL, partition, NULL);
}
int p2sb_set_port_id(struct udevice *dev, int portid)
{
- struct udevice *ps2b;
struct p2sb_child_plat *pplat;
if (!CONFIG_IS_ENABLED(OF_PLATDATA))
return -ENOSYS;
- if (!CONFIG_IS_ENABLED(OF_PLATDATA_PARENT)) {
- uclass_find_first_device(UCLASS_P2SB, &ps2b);
- if (!ps2b)
- return -EDEADLK;
- dev->parent = ps2b;
-
- /*
- * We must allocate this, since when the device was bound it did
- * not have a parent.
- */
- dev->parent_plat = malloc(sizeof(*pplat));
- if (!dev->parent_plat)
- return -ENOMEM;
- }
pplat = dev_get_parent_plat(dev);
pplat->pid = portid;
/* retrieve the device */
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(rockchip_efuse), &dev);
+ DM_DRIVER_GET(rockchip_efuse), &dev);
if (ret) {
printf("%s: no misc-device found\n", __func__);
return 0;
#include <dm.h>
#include <dt-structs.h>
+static const struct udevice_id sandbox_spl_ids[] = {
+ { .compatible = "sandbox,spl-test", },
+ {} /* sentinel */
+};
+
U_BOOT_DRIVER(sandbox_spl_test) = {
.name = "sandbox_spl_test",
.id = UCLASS_MISC,
+ .of_match = sandbox_spl_ids,
.flags = DM_FLAG_PRE_RELOC,
};
switch (bank) {
case STM32MP_OTP_BANK:
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stm32mp_bsec),
+ DM_DRIVER_GET(stm32mp_bsec),
&dev);
if (ret)
return ret;
#ifdef CONFIG_PMIC_STPMIC1
case STM32MP_NVM_BANK:
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stpmic1_nvm),
+ DM_DRIVER_GET(stpmic1_nvm),
&dev);
if (ret)
return ret;
switch (bank) {
case STM32MP_OTP_BANK:
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stm32mp_bsec),
+ DM_DRIVER_GET(stm32mp_bsec),
&dev);
if (ret)
return ret;
#ifdef CONFIG_PMIC_STPMIC1
case STM32MP_NVM_BANK:
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stpmic1_nvm),
+ DM_DRIVER_GET(stpmic1_nvm),
&dev);
if (ret)
return ret;
switch (bank) {
case STM32MP_OTP_BANK:
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stm32mp_bsec),
+ DM_DRIVER_GET(stm32mp_bsec),
&dev);
if (ret)
return ret;
#ifdef CONFIG_PMIC_STPMIC1
case STM32MP_NVM_BANK:
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stpmic1_nvm),
+ DM_DRIVER_GET(stpmic1_nvm),
&dev);
if (ret)
return ret;
switch (bank) {
case STM32MP_OTP_BANK:
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stm32mp_bsec),
+ DM_DRIVER_GET(stm32mp_bsec),
&dev);
if (ret)
return ret;
#ifdef CONFIG_PMIC_STPMIC1
case STM32MP_NVM_BANK:
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(stpmic1_nvm),
+ DM_DRIVER_GET(stpmic1_nvm),
&dev);
if (ret)
return ret;
static int sandbox_swap_case_use_ea(const struct udevice *dev)
{
- return !!ofnode_get_property(dev->node, "use-ea", NULL);
+ return !!ofnode_get_property(dev_ofnode(dev), "use-ea", NULL);
}
/* Please keep these macros in sync with ea_regs below */
--- /dev/null
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2014 Google, Inc
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/test.h>
+
+/* Records the last testbus device that was removed */
+static struct udevice *testbus_removed;
+
+struct udevice *testbus_get_clear_removed(void)
+{
+ struct udevice *removed = testbus_removed;
+
+ testbus_removed = NULL;
+
+ return removed;
+}
+
+static int testbus_drv_probe(struct udevice *dev)
+{
+ if (!CONFIG_IS_ENABLED(OF_PLATDATA)) {
+ int ret;
+
+ ret = dm_scan_fdt_dev(dev);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int testbus_child_post_bind(struct udevice *dev)
+{
+ struct dm_test_parent_plat *plat;
+
+ plat = dev_get_parent_plat(dev);
+ plat->bind_flag = 1;
+ plat->uclass_bind_flag = 2;
+
+ return 0;
+}
+
+static int testbus_child_pre_probe(struct udevice *dev)
+{
+ struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev);
+
+ parent_data->flag += TEST_FLAG_CHILD_PROBED;
+
+ return 0;
+}
+
+static int testbus_child_pre_probe_uclass(struct udevice *dev)
+{
+ struct dm_test_priv *priv = dev_get_priv(dev);
+
+ priv->uclass_flag++;
+
+ return 0;
+}
+
+static int testbus_child_post_probe_uclass(struct udevice *dev)
+{
+ struct dm_test_priv *priv = dev_get_priv(dev);
+
+ priv->uclass_postp++;
+
+ return 0;
+}
+
+static int testbus_child_post_remove(struct udevice *dev)
+{
+ struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev);
+
+ parent_data->flag += TEST_FLAG_CHILD_REMOVED;
+ testbus_removed = dev;
+
+ return 0;
+}
+
+static const struct udevice_id testbus_ids[] = {
+ { .compatible = "denx,u-boot-test-bus", .data = DM_TEST_TYPE_FIRST },
+ { }
+};
+
+U_BOOT_DRIVER(testbus_drv) = {
+ .name = "testbus_drv",
+ .of_match = testbus_ids,
+ .id = UCLASS_TEST_BUS,
+ .probe = testbus_drv_probe,
+ .child_post_bind = testbus_child_post_bind,
+ .priv_auto = sizeof(struct dm_test_priv),
+ .plat_auto = sizeof(struct dm_test_pdata),
+ .per_child_auto = sizeof(struct dm_test_parent_data),
+ .per_child_plat_auto = sizeof(struct dm_test_parent_plat),
+ .child_pre_probe = testbus_child_pre_probe,
+ .child_post_remove = testbus_child_post_remove,
+};
+
+UCLASS_DRIVER(testbus) = {
+ .name = "testbus",
+ .id = UCLASS_TEST_BUS,
+ .flags = DM_UC_FLAG_SEQ_ALIAS,
+ .child_pre_probe = testbus_child_pre_probe_uclass,
+ .child_post_probe = testbus_child_post_probe_uclass,
+};
+
+static int testfdt_drv_ping(struct udevice *dev, int pingval, int *pingret)
+{
+ const struct dm_test_pdata *pdata = dev_get_plat(dev);
+ struct dm_test_priv *priv = dev_get_priv(dev);
+
+ *pingret = pingval + pdata->ping_add;
+ priv->ping_total += *pingret;
+
+ return 0;
+}
+
+static const struct test_ops test_ops = {
+ .ping = testfdt_drv_ping,
+};
+
+static int testfdt_of_to_plat(struct udevice *dev)
+{
+ struct dm_test_pdata *pdata = dev_get_plat(dev);
+
+ pdata->ping_add = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
+ "ping-add", -1);
+ pdata->base = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev),
+ "ping-expect");
+
+ return 0;
+}
+
+static int testfdt_drv_probe(struct udevice *dev)
+{
+ struct dm_test_priv *priv = dev_get_priv(dev);
+
+ priv->ping_total += DM_TEST_START_TOTAL;
+
+ /*
+ * If this device is on a bus, the uclass_flag will be set before
+ * calling this function. In the meantime the uclass_postp is
+ * initlized to a value -1. These are used respectively by
+ * dm_test_bus_child_pre_probe_uclass() and
+ * dm_test_bus_child_post_probe_uclass().
+ */
+ priv->uclass_total += priv->uclass_flag;
+ priv->uclass_postp = -1;
+
+ return 0;
+}
+
+static const struct udevice_id testfdt_ids[] = {
+ { .compatible = "denx,u-boot-fdt-test", .data = DM_TEST_TYPE_FIRST },
+ { .compatible = "google,another-fdt-test", .data = DM_TEST_TYPE_SECOND },
+ { }
+};
+
+U_BOOT_DRIVER(testfdt_drv) = {
+ .name = "testfdt_drv",
+ .of_match = testfdt_ids,
+ .id = UCLASS_TEST_FDT,
+ .of_to_plat = testfdt_of_to_plat,
+ .probe = testfdt_drv_probe,
+ .ops = &test_ops,
+ .priv_auto = sizeof(struct dm_test_priv),
+ .plat_auto = sizeof(struct dm_test_pdata),
+};
+
+static const struct udevice_id testfdt1_ids[] = {
+ { .compatible = "denx,u-boot-fdt-test1", .data = DM_TEST_TYPE_FIRST },
+ { }
+};
+
+U_BOOT_DRIVER(testfdt1_drv) = {
+ .name = "testfdt1_drv",
+ .of_match = testfdt1_ids,
+ .id = UCLASS_TEST_FDT,
+ .of_to_plat = testfdt_of_to_plat,
+ .probe = testfdt_drv_probe,
+ .ops = &test_ops,
+ .priv_auto = sizeof(struct dm_test_priv),
+ .plat_auto = sizeof(struct dm_test_pdata),
+ .flags = DM_FLAG_PRE_RELOC,
+};
+
+/* From here is the testfdt uclass code */
+int testfdt_ping(struct udevice *dev, int pingval, int *pingret)
+{
+ const struct test_ops *ops = device_get_ops(dev);
+
+ if (!ops->ping)
+ return -ENOSYS;
+
+ return ops->ping(dev, pingval, pingret);
+}
+
+UCLASS_DRIVER(testfdt) = {
+ .name = "testfdt",
+ .id = UCLASS_TEST_FDT,
+ .flags = DM_UC_FLAG_SEQ_ALIAS,
+};
+
+static const struct udevice_id testfdtm_ids[] = {
+ { .compatible = "denx,u-boot-fdtm-test" },
+ { }
+};
+
+U_BOOT_DRIVER(testfdtm_drv) = {
+ .name = "testfdtm_drv",
+ .of_match = testfdtm_ids,
+ .id = UCLASS_TEST_FDT_MANUAL,
+};
+
+UCLASS_DRIVER(testfdtm) = {
+ .name = "testfdtm",
+ .id = UCLASS_TEST_FDT_MANUAL,
+ .flags = DM_UC_FLAG_SEQ_ALIAS | DM_UC_FLAG_NO_AUTO_SEQ,
+};
if (!priv)
return -ENOMEM;
- dev->uclass_priv = priv;
+ dev_get_uclass_priv(dev) = priv;
priv->addr = ofnode_get_addr(args.node);
return dev_read_u32(dev, "arm,vexpress,site", &priv->site);
struct arm_pl180_mmc_plat *pdata = dev_get_plat(dev);
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
struct mmc *mmc = &pdata->mmc;
- struct pl180_mmc_host *host = dev->priv;
+ struct pl180_mmc_host *host = dev_get_priv(dev);
struct mmc_config *cfg = &pdata->cfg;
struct clk clk;
u32 bus_width;
static int dm_mmc_getcd(struct udevice *dev)
{
- struct pl180_mmc_host *host = dev->priv;
+ struct pl180_mmc_host *host = dev_get_priv(dev);
int value = 1;
if (dm_gpio_is_valid(&host->cd_gpio))
static int arm_pl180_mmc_of_to_plat(struct udevice *dev)
{
- struct pl180_mmc_host *host = dev->priv;
+ struct pl180_mmc_host *host = dev_get_priv(dev);
fdt_addr_t addr;
addr = dev_read_addr(dev);
.priv_auto = sizeof(struct fsl_esdhc_priv),
};
-U_BOOT_DRIVER_ALIAS(fsl_esdhc, fsl_imx6q_usdhc)
+DM_DRIVER_ALIAS(fsl_esdhc, fsl_imx6q_usdhc)
#endif
#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
static int mxsmmc_of_to_plat(struct udevice *bus)
{
- struct mxsmmc_plat *plat = bus->plat;
+ struct mxsmmc_plat *plat = dev_get_plat(bus);
u32 prop[2];
int ret;
.plat_auto = sizeof(struct mxsmmc_plat),
};
-U_BOOT_DRIVER_ALIAS(fsl_imx23_mmc, fsl_imx28_mmc)
+DM_DRIVER_ALIAS(fsl_imx23_mmc, fsl_imx28_mmc)
#endif /* CONFIG_DM_MMC */
#include <asm/arch/clock.h>
#include <asm/arch/csrs/csrs-mio_emm.h>
#include <asm/io.h>
+#include <dm/device-internal.h>
#include <power/regulator.h>
*/
static bool octeontx_mmc_get_valid(struct udevice *dev)
{
- const char *stat = ofnode_read_string(dev->node, "status");
+ const char *stat = ofnode_read_string(dev_ofnode(dev), "status");
if (!stat || !strncmp(stat, "ok", 2))
return true;
uint low, high;
char env_name[32];
int err;
- ofnode node = dev->node;
+ ofnode node = dev_ofnode(dev);
int bus_width = 1;
ulong new_max_freq;
debug("%s(%s)", __func__, dev->name);
slot->cfg.name = dev->name;
- slot->cfg.f_max = ofnode_read_s32_default(dev->node, "max-frequency",
+ slot->cfg.f_max = ofnode_read_s32_default(dev_ofnode(dev),
+ "max-frequency",
26000000);
snprintf(env_name, sizeof(env_name), "mmc_max_frequency%d",
slot->bus_id);
if (IS_ENABLED(CONFIG_ARCH_OCTEONTX2)) {
slot->hs400_tuning_block =
- ofnode_read_s32_default(dev->node,
+ ofnode_read_s32_default(dev_ofnode(dev),
"marvell,hs400-tuning-block",
-1);
debug("%s(%s): mmc HS400 tuning block: %d\n", __func__,
dev->name, slot->hs400_tuning_block);
slot->hs200_tap_adj =
- ofnode_read_s32_default(dev->node,
+ ofnode_read_s32_default(dev_ofnode(dev),
"marvell,hs200-tap-adjust", 0);
debug("%s(%s): hs200-tap-adjust: %d\n", __func__, dev->name,
slot->hs200_tap_adj);
slot->hs400_tap_adj =
- ofnode_read_s32_default(dev->node,
+ ofnode_read_s32_default(dev_ofnode(dev),
"marvell,hs400-tap-adjust", 0);
debug("%s(%s): hs400-tap-adjust: %d\n", __func__, dev->name,
slot->hs400_tap_adj);
}
- err = ofnode_read_u32_array(dev->node, "voltage-ranges", voltages, 2);
+ err = ofnode_read_u32_array(dev_ofnode(dev), "voltage-ranges",
+ voltages, 2);
if (err) {
slot->cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
} else {
host->dev = dev;
debug("%s(%s): Base address: %p\n", __func__, dev->name,
host->base_addr);
- if (!dev_has_of_node(dev)) {
+ if (!dev_has_ofnode(dev)) {
pr_err("%s: No device tree information found\n", __func__);
return -1;
}
- host->node = dev->node;
+ host->node = dev_ofnode(dev);
host->last_slotid = -1;
if (otx_is_platform(PLATFORM_ASIM))
host->is_asim = true;
if (otx_is_platform(PLATFORM_EMULATOR))
host->is_emul = true;
host->dma_wait_delay =
- ofnode_read_u32_default(dev->node, "marvell,dma-wait-delay", 1);
+ ofnode_read_u32_default(dev_ofnode(dev),
+ "marvell,dma-wait-delay", 1);
/* Force reset of eMMC */
writeq(0, host->base_addr + MIO_EMM_CFG());
debug("%s: Clearing MIO_EMM_CFG\n", __func__);
struct octeontx_mmc_host *host = dev_get_priv(dev_get_parent(dev));
struct octeontx_mmc_slot *slot;
struct mmc_uclass_priv *upriv;
- ofnode node = dev->node;
+ ofnode node = dev_ofnode(dev);
u32 bus_id;
char name[16];
int err;
}
slot = &host->slots[bus_id];
- dev->priv = slot;
+ dev_set_priv(dev, slot);
slot->host = host;
slot->bus_id = bus_id;
slot->dev = dev;
snprintf(name, sizeof(name), "octeontx-mmc%d", bus_id);
err = device_set_name(dev, name);
- if (!dev->uclass_priv) {
+ /* FIXME: This code should not be needed */
+ if (!dev_get_uclass_priv(dev)) {
debug("%s(%s): Allocating uclass priv\n", __func__,
dev->name);
upriv = calloc(1, sizeof(struct mmc_uclass_priv));
if (!upriv)
return -ENOMEM;
- dev->uclass_priv = upriv;
- dev->uclass->priv = upriv;
+
+ /*
+ * FIXME: This is not allowed
+ * dev_set_uclass_priv(dev, upriv);
+ * uclass_set_priv(dev->uclass, upriv);
+ */
} else {
- upriv = dev->uclass_priv;
+ upriv = dev_get_uclass_priv(dev);
}
upriv->mmc = &slot->mmc;
U_BOOT_DRIVER(octeontx_hsmmc_host) = {
.name = "octeontx_hsmmc_host",
+ /* FIXME: Why is this not UCLASS_MMC? */
.id = UCLASS_MISC,
.of_match = of_match_ptr(octeontx_hsmmc_host_ids),
.probe = octeontx_mmc_host_probe,
struct acpi_dp *dp;
int ret;
- if (!dev_of_valid(dev))
+ if (!dev_has_ofnode(dev))
return 0;
ret = gpio_get_acpi(&priv->cd_gpio, &gpio);
.plat_auto = sizeof(struct rockchip_mmc_plat),
};
-U_BOOT_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3328_dw_mshc)
-U_BOOT_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3368_dw_mshc)
+DM_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3328_dw_mshc)
+DM_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3368_dw_mshc)
#ifdef CONFIG_PWRSEQ
static int rockchip_dwmmc_pwrseq_set_power(struct udevice *dev, bool enable)
int ret;
ret = uclass_get_device_by_driver(UCLASS_MTD,
- DM_GET_DRIVER(arasan_nand), &dev);
+ DM_DRIVER_GET(arasan_nand), &dev);
if (ret && ret != -ENODEV)
pr_err("Failed to initialize %s. (error %d)\n", dev->name, ret);
}
int ret;
ret = uclass_get_device_by_driver(UCLASS_MTD,
- DM_GET_DRIVER(bcm63158_nand), &dev);
+ DM_DRIVER_GET(bcm63158_nand), &dev);
if (ret && ret != -ENODEV)
pr_err("Failed to initialize %s. (error %d)\n", dev->name,
ret);
int ret;
ret = uclass_get_device_by_driver(UCLASS_MTD,
- DM_GET_DRIVER(bcm6368_nand), &dev);
+ DM_DRIVER_GET(bcm6368_nand), &dev);
if (ret && ret != -ENODEV)
pr_err("Failed to initialize %s. (error %d)\n", dev->name,
ret);
int ret;
ret = uclass_get_device_by_driver(UCLASS_MTD,
- DM_GET_DRIVER(bcm68360_nand), &dev);
+ DM_DRIVER_GET(bcm68360_nand), &dev);
if (ret && ret != -ENODEV)
pr_err("Failed to initialize %s. (error %d)\n", dev->name,
ret);
int ret;
ret = uclass_get_device_by_driver(UCLASS_MTD,
- DM_GET_DRIVER(bcm6838_nand), &dev);
+ DM_DRIVER_GET(bcm6838_nand), &dev);
if (ret && ret != -ENODEV)
pr_err("Failed to initialize %s. (error %d)\n", dev->name,
ret);
int ret;
ret = uclass_get_device_by_driver(UCLASS_MTD,
- DM_GET_DRIVER(bcm6858_nand), &dev);
+ DM_DRIVER_GET(bcm6858_nand), &dev);
if (ret && ret != -ENODEV)
pr_err("Failed to initialize %s. (error %d)\n", dev->name,
ret);
int ret;
ret = uclass_get_device_by_driver(UCLASS_MTD,
- DM_GET_DRIVER(davinci_nand), &dev);
+ DM_DRIVER_GET(davinci_nand), &dev);
if (ret && ret != -ENODEV)
pr_err("Failed to initialize %s: %d\n", dev->name, ret);
}
int ret;
ret = uclass_get_device_by_driver(UCLASS_MTD,
- DM_GET_DRIVER(denali_nand_dt),
+ DM_DRIVER_GET(denali_nand_dt),
&dev);
if (ret && ret != -ENODEV)
pr_err("Failed to initialize Denali NAND controller. (error %d)\n",
int ret;
ret = uclass_get_device_by_driver(UCLASS_MTD,
- DM_GET_DRIVER(mxs_nand_dt),
+ DM_DRIVER_GET(mxs_nand_dt),
&dev);
if (ret && ret != -ENODEV)
pr_err("Failed to initialize MXS NAND controller. (error %d)\n",
static int octeontx_nfc_chips_init(struct octeontx_nfc *tn)
{
struct udevice *dev = tn->dev;
- ofnode node = dev->node;
+ ofnode node = dev_ofnode(dev);
ofnode nand_node;
int nr_chips = of_get_child_count(node);
int ret;
debug("%s: Performing deferred probing\n", __func__);
list_for_each_entry(pdev, &octeontx_pci_nand_deferred_devices, list) {
debug("%s: Probing %s\n", __func__, pdev->dev->name);
- pdev->dev->flags &= ~DM_FLAG_ACTIVATED;
+ dev_get_flags(pdev->dev) &= ~DM_FLAG_ACTIVATED;
rc = device_probe(pdev->dev);
if (rc && rc != -ENODEV) {
printf("%s: Error %d with deferred probe of %s\n",
if (IS_ENABLED(CONFIG_NAND_OCTEONTX_HW_ECC)) {
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(octeontx_pci_bchpf),
+ DM_DRIVER_GET(octeontx_pci_bchpf),
&dev);
if (ret && ret != -ENODEV) {
pr_err("Failed to initialize OcteonTX BCH PF controller. (error %d)\n",
ret);
}
ret = uclass_get_device_by_driver(UCLASS_MISC,
- DM_GET_DRIVER(octeontx_pci_bchvf),
+ DM_DRIVER_GET(octeontx_pci_bchvf),
&dev);
if (ret && ret != -ENODEV) {
pr_err("Failed to initialize OcteonTX BCH VF controller. (error %d)\n",
}
ret = uclass_get_device_by_driver(UCLASS_MTD,
- DM_GET_DRIVER(octeontx_pci_nand),
+ DM_DRIVER_GET(octeontx_pci_nand),
&dev);
if (ret && ret != -ENODEV)
pr_err("Failed to initialize OcteonTX NAND controller. (error %d)\n",
int ret;
ret = uclass_get_device_by_driver(UCLASS_MTD,
- DM_GET_DRIVER(pxa3xx_nand), &dev);
+ DM_DRIVER_GET(pxa3xx_nand), &dev);
if (ret && ret != -ENODEV) {
pr_err("Failed to initialize %s. (error %d)\n", dev->name,
ret);
int ret;
ret = uclass_get_device_by_driver(UCLASS_MTD,
- DM_GET_DRIVER(stm32_fmc2_nfc),
+ DM_DRIVER_GET(stm32_fmc2_nfc),
&dev);
if (ret && ret != -ENODEV)
pr_err("Failed to initialize STM32 FMC2 NFC controller. (error %d)\n",
int ret;
ret = uclass_get_device_by_driver(UCLASS_MTD,
- DM_GET_DRIVER(tegra_nand), &dev);
+ DM_DRIVER_GET(tegra_nand), &dev);
if (ret && ret != -ENODEV)
pr_err("Failed to initialize %s. (error %d)\n", dev->name,
ret);
int ret;
ret = uclass_get_device_by_driver(UCLASS_MTD,
- DM_GET_DRIVER(vf610_nfc_dt),
+ DM_DRIVER_GET(vf610_nfc_dt),
&dev);
if (ret && ret != -ENODEV)
pr_err("Failed to initialize NAND controller. (error %d)\n",
int ret;
ret = uclass_get_device_by_driver(UCLASS_MTD,
- DM_GET_DRIVER(zynq_nand), &dev);
+ DM_DRIVER_GET(zynq_nand), &dev);
if (ret && ret != -ENODEV)
pr_err("Failed to initialize %s. (error %d)\n", dev->name, ret);
}
return -ENOMEM;
sprintf(mtd->name, "spi-nand%d", spi_nand_idx++);
spinand->slave = slave;
- spinand_set_of_node(spinand, dev->node.np);
+ spinand_set_ofnode(spinand, dev_ofnode(dev));
#endif
ret = spinand_init(spinand);
.id = UCLASS_SPI_FLASH,
.name = "spi_flash",
.post_bind = spi_flash_post_bind,
- .per_device_auto = sizeof(struct spi_flash),
+ .per_device_auto = sizeof(struct spi_nor),
};
.of_match = spi_flash_std_ids,
.probe = spi_flash_std_probe,
.remove = spi_flash_std_remove,
- .priv_auto = sizeof(struct spi_flash),
+ .priv_auto = sizeof(struct spi_nor),
.ops = &spi_flash_std_ops,
};
-U_BOOT_DRIVER_ALIAS(jedec_spi_nor, spansion_m25p16)
+DM_DRIVER_ALIAS(jedec_spi_nor, spansion_m25p16)
#endif /* CONFIG_DM_SPI_FLASH */
#include <regmap.h>
#include <syscon.h>
#include <dm/device.h>
+#include <dm/device-internal.h>
#include <dm/device_compat.h>
#include <dm/read.h>
#include <dm/devres.h>
fields = devm_kmalloc(dev, num_fields * sizeof(*fields), __GFP_ZERO);
if (!fields)
return -ENOMEM;
- dev->priv = fields;
+ dev_set_priv(dev, fields);
mux_reg_masks = devm_kmalloc(dev, num_fields * 2 * sizeof(u32),
__GFP_ZERO);
for (uclass_first_device(UCLASS_ETH_PHY, &dev); dev;
uclass_next_device(&dev)) {
if (dev->parent == eth_dev) {
- uc_priv = (struct eth_phy_device_priv *)(dev->uclass_priv);
+ uc_priv = (struct eth_phy_device_priv *)(dev_get_uclass_priv(dev));
if (!uc_priv->mdio_bus)
uc_priv->mdio_bus = mdio_bus;
* phy_dev is shared and controlled by
* other eth controller
*/
- uc_priv = (struct eth_phy_device_priv *)(phy_dev->uclass_priv);
+ uc_priv = (struct eth_phy_device_priv *)(dev_get_uclass_priv(phy_dev));
if (uc_priv->mdio_bus)
printf("Get shared mii bus on %s\n", eth_dev->name);
else
struct fm_eth *fm_eth;
struct fsl_enet_mac *mac;
+#ifndef CONFIG_DM_ETH
fm_eth = (struct fm_eth *)dev->priv;
+#else
+ fm_eth = dev_get_priv(dev);
+#endif
mac = fm_eth->mac;
/* graceful stop the transmission of frames */
u16 offset_in;
int i;
+#ifndef CONFIG_DM_ETH
fm_eth = (struct fm_eth *)dev->priv;
+#else
+ fm_eth = dev_get_priv(dev);
+#endif
pram = fm_eth->tx_pram;
txbd = fm_eth->cur_txbd;
static int fm_eth_recv(struct udevice *dev, int flags, uchar **packetp)
#endif
{
- struct fm_eth *fm_eth = (struct fm_eth *)dev->priv;
- struct fm_port_bd *rxbd = fm_eth->cur_rxbd;
+ struct fm_eth *fm_eth;
+ struct fm_port_bd *rxbd;
u32 buf_lo, buf_hi;
u16 status, len;
int ret = -1;
u8 *data;
+#ifndef CONFIG_DM_ETH
+ fm_eth = (struct fm_eth *)dev->priv;
+#else
+ fm_eth = dev_get_priv(dev);
+#endif
+ rxbd = fm_eth->cur_rxbd;
status = muram_readw(&rxbd->status);
while (!(status & RxBD_EMPTY)) {
#ifdef CONFIG_DM_ETH
static int fm_eth_free_pkt(struct udevice *dev, uchar *packet, int length)
{
- struct fm_eth *fm_eth = (struct fm_eth *)dev->priv;
+ struct fm_eth *fm_eth = (struct fm_eth *)dev_get_priv(dev);
fm_eth->cur_rxbd = fm_eth_free_one(fm_eth, fm_eth->cur_rxbd);
{
const char *if_str;
- if_str = ofnode_read_string(dev->node, "phy-connection-type");
+ if_str = ofnode_read_string(dev_ofnode(dev), "phy-connection-type");
debug("MAC system interface mode %s\n", if_str);
return phy_get_interface_by_name(if_str);
char mac_name[11];
u32 fm, num;
- if (ofnode_read_u32(ofnode_get_parent(dev->node), "cell-index", &fm)) {
+ if (ofnode_read_u32(ofnode_get_parent(dev_ofnode(dev)), "cell-index", &fm)) {
printf("FMan node property cell-index missing\n");
return -EINVAL;
}
static int fm_eth_probe(struct udevice *dev)
{
- struct fm_eth *fm_eth = (struct fm_eth *)dev->priv;
+ struct fm_eth *fm_eth = (struct fm_eth *)dev_get_priv(dev);
struct ofnode_phandle_args args;
void *reg;
int ret, index;
* and some are not, use different naming scheme - enetc-N based on
* PCI function # and enetc#N based on interface count
*/
- if (ofnode_valid(dev->node))
+ if (ofnode_valid(dev_ofnode(dev)))
sprintf(name, "enetc-%u", PCI_FUNC(pci_get_devfn(dev)));
else
sprintf(name, "enetc#%u", eth_num_devices++);
mdio_register(&priv->imdio);
}
- if (!ofnode_valid(dev->node)) {
+ if (!ofnode_valid(dev_ofnode(dev))) {
enetc_dbg(dev, "no enetc ofnode found, skipping PCS set-up\n");
return;
}
- if_str = ofnode_read_string(dev->node, "phy-mode");
+ if_str = ofnode_read_string(dev_ofnode(dev), "phy-mode");
if (if_str)
priv->if_type = phy_get_interface_by_name(if_str);
else
{
struct enetc_priv *priv = dev_get_priv(dev);
- if (ofnode_valid(dev->node) && !ofnode_is_available(dev->node)) {
+ if (ofnode_valid(dev_ofnode(dev)) && !ofnode_is_available(dev_ofnode(dev))) {
enetc_dbg(dev, "interface disabled\n");
return -ENODEV;
}
* and some are not, use different naming scheme - enetc-N based on
* PCI function # and enetc#N based on interface count
*/
- if (ofnode_valid(dev->node))
+ if (ofnode_valid(dev_ofnode(dev)))
sprintf(name, "emdio-%u", PCI_FUNC(pci_get_devfn(dev)));
else
sprintf(name, "emdio#%u", eth_num_devices++);
static void fec_halt(struct udevice *dev)
{
- struct fec_info_dma *info = dev->priv;
+ struct fec_info_dma *info = dev_get_priv(dev);
volatile fecdma_t *fecp = (fecdma_t *)info->iobase;
int counter = 0xffff;
static int fec_init(struct udevice *dev)
{
- struct fec_info_dma *info = dev->priv;
+ struct fec_info_dma *info = dev_get_priv(dev);
volatile fecdma_t *fecp = (fecdma_t *)info->iobase;
int rval, i;
uchar enetaddr[6];
static int mcdmafec_send(struct udevice *dev, void *packet, int length)
{
- struct fec_info_dma *info = dev->priv;
+ struct fec_info_dma *info = dev_get_priv(dev);
cbd_t *p_tbd, *p_used_tbd;
u16 phy_status;
static int mcdmafec_recv(struct udevice *dev, int flags, uchar **packetp)
{
- struct fec_info_dma *info = dev->priv;
+ struct fec_info_dma *info = dev_get_priv(dev);
volatile fecdma_t *fecp = (fecdma_t *)info->iobase;
cbd_t *prbd = &info->rxbd[info->rx_idx];
*/
static int mcdmafec_probe(struct udevice *dev)
{
- struct fec_info_dma *info = dev->priv;
+ struct fec_info_dma *info = dev_get_priv(dev);
struct eth_pdata *pdata = dev_get_plat(dev);
int node = dev_of_offset(dev);
int retval;
#ifdef ET_DEBUG
static void dbg_fec_regs(struct udevice *dev)
{
- struct fec_info_s *info = dev->priv;
+ struct fec_info_s *info = dev_get_priv(dev);
volatile fec_t *fecp = (fec_t *)(info->iobase);
printf("=====\n");
int mcffec_init(struct udevice *dev)
{
- struct fec_info_s *info = dev->priv;
+ struct fec_info_s *info = dev_get_priv(dev);
volatile fec_t *fecp = (fec_t *) (info->iobase);
int rval, i;
uchar ea[6];
static int mcffec_send(struct udevice *dev, void *packet, int length)
{
- struct fec_info_s *info = dev->priv;
+ struct fec_info_s *info = dev_get_priv(dev);
volatile fec_t *fecp = (fec_t *)info->iobase;
int j, rc;
u16 phy_status;
static int mcffec_recv(struct udevice *dev, int flags, uchar **packetp)
{
- struct fec_info_s *info = dev->priv;
+ struct fec_info_s *info = dev_get_priv(dev);
volatile fec_t *fecp = (fec_t *)info->iobase;
int length = -1;
static void mcffec_halt(struct udevice *dev)
{
- struct fec_info_s *info = dev->priv;
+ struct fec_info_s *info = dev_get_priv(dev);
fec_reset(info);
fecpin_setclear(info, 0);
static int mcffec_probe(struct udevice *dev)
{
struct eth_pdata *pdata = dev_get_plat(dev);
- struct fec_info_s *info = dev->priv;
+ struct fec_info_s *info = dev_get_priv(dev);
int node = dev_of_offset(dev);
int retval, fec_idx;
const u32 *val;
/* retrieve from register structure */
dev = eth_get_dev();
+#ifdef CONFIG_DM_ETH
+ info = dev_get_priv(dev);
+#else
info = dev->priv;
+#endif
ep = (FEC_T *) info->miibase;
/* retrieve from register structure */
dev = eth_get_dev();
+#ifdef CONFIG_DM_ETH
+ info = dev_get_priv(dev);
+#else
info = dev->priv;
+#endif
fecp = (FEC_T *) info->miibase;
static int ipq4019_mdio_bind(struct udevice *dev)
{
- if (ofnode_valid(dev->node))
- device_set_name(dev, ofnode_get_name(dev->node));
+ if (ofnode_valid(dev_ofnode(dev)))
+ device_set_name(dev, ofnode_get_name(dev_ofnode(dev)));
return 0;
}
}
/* parent should be an I2C chip, grandparent should be an I2C bus */
- chip_node = ofnode_get_parent(dev->node);
+ chip_node = ofnode_get_parent(dev_ofnode(dev));
bus_node = ofnode_get_parent(chip_node);
err = uclass_get_device_by_ofnode(UCLASS_I2C, bus_node, &i2c_bus);
*/
static int mvmdio_bind(struct udevice *dev)
{
- if (ofnode_valid(dev->node))
- device_set_name(dev, ofnode_get_name(dev->node));
+ if (ofnode_valid(dev_ofnode(dev)))
+ device_set_name(dev, ofnode_get_name(dev_ofnode(dev)));
return 0;
}
int octeontx_smi_probe(struct udevice *dev)
{
- int ret, subnode, cnt = 0, node = dev->node.of_offset;
+ int ret, subnode, cnt = 0, node = dev_ofnode(dev).of_offset;
struct mii_dev *bus;
struct octeontx_smi_priv *priv;
pci_dev_t bdf = dm_pci_get_bdf(dev);
static int pfe_eth_send(struct udevice *dev, void *packet, int length)
{
- struct pfe_eth_dev *priv = (struct pfe_eth_dev *)dev->priv;
+ struct pfe_eth_dev *priv = (struct pfe_eth_dev *)dev_get_priv(dev);
int rc;
int i = 0;
{
struct eth_pdata *pdata = dev_get_plat(dev);
- return _sunxi_emac_eth_init(dev->priv, pdata->enetaddr);
+ return _sunxi_emac_eth_init(dev_get_priv(dev), pdata->enetaddr);
}
static int sunxi_emac_eth_send(struct udevice *dev, void *packet, int length)
static int tsec_mcast_addr(struct udevice *dev, const u8 *mcast_mac, int join)
#endif
{
- struct tsec_private *priv = (struct tsec_private *)dev->priv;
- struct tsec __iomem *regs = priv->regs;
+ struct tsec_private *priv;
+ struct tsec __iomem *regs;
u32 result, value;
u8 whichbit, whichreg;
+#ifndef CONFIG_DM_ETH
+ priv = (struct tsec_private *)dev->priv;
+#else
+ priv = dev_get_priv(dev);
+#endif
+ regs = priv->regs;
result = ether_crc(MAC_ADDR_LEN, mcast_mac);
whichbit = (result >> 24) & 0x1f; /* the 5 LSB = which bit to set */
whichreg = result >> 29; /* the 3 MSB = which reg to set it in */
static int tsec_send(struct udevice *dev, void *packet, int length)
#endif
{
- struct tsec_private *priv = (struct tsec_private *)dev->priv;
- struct tsec __iomem *regs = priv->regs;
+ struct tsec_private *priv;
+ struct tsec __iomem *regs;
int result = 0;
u16 status;
int i;
+#ifndef CONFIG_DM_ETH
+ priv = (struct tsec_private *)dev->priv;
+#else
+ priv = dev_get_priv(dev);
+#endif
+ regs = priv->regs;
/* Find an empty buffer descriptor */
for (i = 0;
in_be16(&priv->txbd[priv->tx_idx].status) & TXBD_READY;
#else
static int tsec_recv(struct udevice *dev, int flags, uchar **packetp)
{
- struct tsec_private *priv = (struct tsec_private *)dev->priv;
+ struct tsec_private *priv = (struct tsec_private *)dev_get_priv(dev);
struct tsec __iomem *regs = priv->regs;
int ret = -1;
static int tsec_free_pkt(struct udevice *dev, uchar *packet, int length)
{
- struct tsec_private *priv = (struct tsec_private *)dev->priv;
+ struct tsec_private *priv = (struct tsec_private *)dev_get_priv(dev);
u16 status;
out_be16(&priv->rxbd[priv->rx_idx].length, 0);
static void tsec_halt(struct udevice *dev)
#endif
{
- struct tsec_private *priv = (struct tsec_private *)dev->priv;
- struct tsec __iomem *regs = priv->regs;
+ struct tsec_private *priv;
+ struct tsec __iomem *regs;
+#ifndef CONFIG_DM_ETH
+ priv = (struct tsec_private *)dev->priv;
+#else
+ priv = dev_get_priv(dev);
+#endif
+ regs = priv->regs;
clrbits_be32(®s->dmactrl, DMACTRL_GRS | DMACTRL_GTS);
setbits_be32(®s->dmactrl, DMACTRL_GRS | DMACTRL_GTS);
static int tsec_init(struct udevice *dev)
#endif
{
- struct tsec_private *priv = (struct tsec_private *)dev->priv;
+ struct tsec_private *priv;
+ struct tsec __iomem *regs;
#ifdef CONFIG_DM_ETH
struct eth_pdata *pdata = dev_get_plat(dev);
#else
struct eth_device *pdata = dev;
#endif
- struct tsec __iomem *regs = priv->regs;
u32 tempval;
int ret;
+#ifndef CONFIG_DM_ETH
+ priv = (struct tsec_private *)dev->priv;
+#else
+ priv = dev_get_priv(dev);
+#endif
+ regs = priv->regs;
/* Make sure the controller is stopped */
tsec_halt(dev);
tsec_configure_serdes(priv);
#if defined(CONFIG_DM_ETH) && defined(CONFIG_DM_MDIO)
- if (ofnode_valid(ofnode_find_subnode(priv->dev->node, "fixed-link")))
+ if (ofnode_valid(ofnode_find_subnode(dev_ofnode(priv->dev),
+ "fixed-link")))
phydev = phy_connect(NULL, 0, priv->dev, priv->interface);
else
phydev = dm_eth_phy_connect(priv->dev);
int tsec_remove(struct udevice *dev)
{
- struct tsec_private *priv = dev->priv;
+ struct tsec_private *priv = dev_get_priv(dev);
free(priv->phydev);
mdio_unregister(priv->bus);
{
u32 length, first_read, reg, attempt = 0;
void *addr, *ack;
- struct xemaclite *emaclite = dev->priv;
+ struct xemaclite *emaclite = dev_get_priv(dev);
struct emaclite_regs *regs = emaclite->regs;
struct ethernet_hdr *eth;
struct ip_udp_hdr *ip;
static int sandbox_pci_emul_post_probe(struct udevice *dev)
{
- struct sandbox_pci_emul_priv *priv = dev->uclass->priv;
+ struct sandbox_pci_emul_priv *priv = uclass_get_priv(dev->uclass);
priv->dev_count++;
sandbox_set_enable_pci_map(true);
static int sandbox_pci_emul_pre_remove(struct udevice *dev)
{
- struct sandbox_pci_emul_priv *priv = dev->uclass->priv;
+ struct sandbox_pci_emul_priv *priv = uclass_get_priv(dev->uclass);
priv->dev_count--;
sandbox_set_enable_pci_map(priv->dev_count > 0);
int pci_auto_config_devices(struct udevice *bus)
{
- struct pci_controller *hose = bus->uclass_priv;
+ struct pci_controller *hose = dev_get_uclass_priv(bus);
struct pci_child_plat *pplat;
unsigned int sub_bus;
struct udevice *dev;
int ret;
debug("%s: device %s\n", __func__, dev->name);
- if (dev_of_valid(dev) &&
+ if (dev_has_ofnode(dev) &&
dev_read_bool(dev, "pci,no-autoconfig"))
continue;
ret = dm_pciauto_config_device(dev);
debug("%s, bus=%d/%s, parent=%s\n", __func__, dev_seq(bus), bus->name,
bus->parent->name);
- hose = bus->uclass_priv;
+ hose = dev_get_uclass_priv(bus);
/*
* Set the sequence number, if device_bind() doesn't. We want control
ret = uclass_get(UCLASS_PCI, &uc);
if (ret)
return ret;
- bus->sqq = uclass_find_next_free_seq(uc);
+ bus->seq_ = uclass_find_next_free_seq(uc);
}
/* For bridges, use the top-level PCI controller */
hose->bus = bus;
hose->first_busno = dev_seq(bus);
hose->last_busno = dev_seq(bus);
- if (dev_of_valid(bus)) {
+ if (dev_has_ofnode(bus)) {
hose->skip_auto_config_until_reloc =
dev_read_bool(bus,
"u-boot,skip-auto-config-until-reloc");
{
struct pci_child_plat *pplat;
- if (!dev_of_valid(dev))
+ if (!dev_has_ofnode(dev))
return 0;
pplat = dev_get_parent_plat(dev);
uint offset, ulong *valuep,
enum pci_size_t size)
{
- struct pci_controller *hose = bus->uclass_priv;
+ struct pci_controller *hose = dev_get_uclass_priv(bus);
return pci_bus_read_config(hose->ctlr, bdf, offset, valuep, size);
}
uint offset, ulong value,
enum pci_size_t size)
{
- struct pci_controller *hose = bus->uclass_priv;
+ struct pci_controller *hose = dev_get_uclass_priv(bus);
return pci_bus_write_config(hose->ctlr, bdf, offset, value, size);
}
ret = device_bind_driver_to_node(dev->parent,
"ti-serdes-am654-mux-clk",
- dev_read_name(dev), dev->node,
+ dev_read_name(dev), dev_ofnode(dev),
NULL);
if (ret) {
dev_err(dev, "%s: not able to bind clock driver\n", __func__);
irq = pcr_read32(dev, PAD_CFG1_OFFSET(pad_cfg_offset));
irq &= PAD_CFG1_IRQ_MASK;
if (!irq) {
- log_err("GPIO %u doesn't support APIC routing\n", cfg->pad);
+ if (spl_phase() > PHASE_TPL)
+ log_err("GPIO %u doesn't support APIC routing\n",
+ cfg->pad);
return -EPROTONOSUPPORT;
}
return config_value;
}
}
- log_err("Logical-to-Chipset mapping not found\n");
+ if (spl_phase() > PHASE_TPL)
+ log_err("Logical-to-Chipset mapping not found\n");
return -ENOENT;
}
struct intel_pinctrl_priv *priv = dev_get_priv(dev);
if (!comm) {
- log_err("Cannot find community for pid %d\n", pplat->pid);
+ if (spl_phase() > PHASE_TPL)
+ log_err("Cannot find community for pid %d\n",
+ pplat->pid);
return -EDOM;
}
priv->comm = comm;
#include <asm-generic/gpio.h>
#include <asm/intel_pinctrl_defs.h>
-/**
- * struct apl_gpio_plat - platform data for each device
- *
- * @dtplat: of-platdata data from C struct
- */
-struct apl_gpio_plat {
-#if CONFIG_IS_ENABLED(OF_PLATDATA)
- /* Put this first since driver model will copy the data here */
- struct dtd_intel_apl_pinctrl dtplat;
-#endif
-};
-
static const struct reset_mapping rst_map[] = {
{ .logical = PAD_CFG0_LOGICAL_RESET_PWROK, .chipset = 0U << 30 },
{ .logical = PAD_CFG0_LOGICAL_RESET_DEEP, .chipset = 1U << 30 },
* linker list (i.e. alphabetical order by driver name). So the GPIO
* device may well be bound before its parent (p2sb), and this call
* will fail if p2sb is not bound yet.
- *
*/
ret = p2sb_set_port_id(dev, plat->dtplat.intel_p2sb_port_id);
if (ret)
return intel_pinctrl_of_to_plat(dev, comm, 2);
}
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
static const struct udevice_id apl_gpio_ids[] = {
{ .compatible = "intel,apl-pinctrl"},
{ }
};
+#endif
U_BOOT_DRIVER(intel_apl_pinctrl) = {
.name = "intel_apl_pinctrl",
.id = UCLASS_PINCTRL,
- .of_match = apl_gpio_ids,
+ .of_match = of_match_ptr(apl_gpio_ids),
.probe = intel_pinctrl_probe,
.ops = &intel_pinctrl_ops,
#if !CONFIG_IS_ENABLED(OF_PLATDATA)
.flags = DM_FLAG_PRE_RELOC,
};
-U_BOOT_DRIVER_ALIAS(fsl_imx6q_iomuxc, fsl_imx6dl_iomuxc)
+DM_DRIVER_ALIAS(fsl_imx6q_iomuxc, fsl_imx6dl_iomuxc)
.ops = &mxs_pinctrl_ops,
};
-U_BOOT_DRIVER_ALIAS(fsl_imx23_pinctrl, fsl_imx28_pinctrl)
+DM_DRIVER_ALIAS(fsl_imx23_pinctrl, fsl_imx28_pinctrl)
.ops = &at91_pinctrl_ops,
};
-U_BOOT_DRIVER_ALIAS(atmel_sama5d3_pinctrl, atmel_at91rm9200_pinctrl)
+DM_DRIVER_ALIAS(atmel_sama5d3_pinctrl, atmel_at91rm9200_pinctrl)
#else
static int qe_io_of_to_plat(struct udevice *dev)
{
- struct qe_io_plat *plat = dev->plat;
+ struct qe_io_plat *plat = dev_get_plat(dev);
fdt_addr_t addr;
addr = dev_read_addr(dev);
*/
static int par_io_of_config_node(struct udevice *dev, ofnode pio)
{
- struct qe_io_plat *plat = dev->plat;
+ struct qe_io_plat *plat = dev_get_plat(dev);
qepio83xx_t *par_io = plat->base;
const unsigned int *pio_map;
int pio_map_len;
const struct single_fdt_pin_cfg *pins,
int size)
{
- struct single_pdata *pdata = dev->plat;
+ struct single_pdata *pdata = dev_get_plat(dev);
int count = size / sizeof(struct single_fdt_pin_cfg);
phys_addr_t n, reg;
u32 val;
const struct single_fdt_bits_cfg *pins,
int size)
{
- struct single_pdata *pdata = dev->plat;
+ struct single_pdata *pdata = dev_get_plat(dev);
int count = size / sizeof(struct single_fdt_bits_cfg);
phys_addr_t n, reg;
u32 val, mask;
fdt_addr_t addr;
u32 of_reg[2];
int res;
- struct single_pdata *pdata = dev->plat;
+ struct single_pdata *pdata = dev_get_plat(dev);
pdata->width =
dev_read_u32_default(dev, "pinctrl-single,register-width", 0);
ofnode node;
int ret;
- if (!dev_of_valid(dev))
+ if (!dev_has_ofnode(dev))
return 0;
dev_for_each_subnode(node, dev) {
* Some device which is logical like mmc.blk, do not have
* a valid ofnode.
*/
- if (!ofnode_valid(dev->node))
+ if (!dev_has_ofnode(dev))
return 0;
/*
* Try full-implemented pinctrl first.
UCLASS_DRIVER(pinctrl) = {
.id = UCLASS_PINCTRL,
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
.post_bind = pinctrl_post_bind,
+#endif
.flags = DM_UC_FLAG_SEQ_ALIAS,
.name = "pinctrl",
};
#include <common.h>
#include <dm.h>
#include <log.h>
+#include <spl.h>
#include <acpi/acpi_s3.h>
#ifdef CONFIG_X86
#include <asm/intel_pinctrl.h>
* are different and if they aren't, use the reset values.
*/
if (dw[0] == dw[1] || dw[1] == dw[2]) {
- log_info("PMC: Using default GPE route");
+ if (spl_phase() > PHASE_TPL)
+ log_info("PMC: Using default GPE route");
gpio_cfg = readl(upriv->gpe_cfg);
for (i = 0; i < upriv->gpe0_count; i++)
dw[i] = gpio_cfg >> gpe0_shift(upriv, i);
if (!priv->data)
return -EINVAL;
- priv->regmap_hhi = syscon_node_to_regmap(dev_get_parent(dev)->node);
+ priv->regmap_hhi = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev)));
if (IS_ERR(priv->regmap_hhi))
return PTR_ERR(priv->regmap_hhi);
- ret = ofnode_read_u32(dev->node, "amlogic,ao-sysctrl",
+ ret = ofnode_read_u32(dev_ofnode(dev), "amlogic,ao-sysctrl",
&ao_phandle);
if (ret)
return ret;
ofnode hhi_node;
int ret;
- priv->regmap_ao = syscon_node_to_regmap(dev_get_parent(dev)->node);
+ priv->regmap_ao = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev)));
if (IS_ERR(priv->regmap_ao))
return PTR_ERR(priv->regmap_ao);
- ret = ofnode_read_u32(dev->node, "amlogic,hhi-sysctrl",
+ ret = ofnode_read_u32(dev_ofnode(dev), "amlogic,hhi-sysctrl",
&hhi_phandle);
if (ret)
return ret;
.ops = &rk8xx_ops,
};
-U_BOOT_DRIVER_ALIAS(rockchip_rk805, rockchip_rk808)
+DM_DRIVER_ALIAS(rockchip_rk805, rockchip_rk808)
static int da9063_get_enable(struct udevice *dev)
{
- const struct da9063_priv *priv = dev->priv;
+ const struct da9063_priv *priv = dev_get_priv(dev);
const struct da9063_reg_info *info = priv->reg_info;
int ret;
static int da9063_set_enable(struct udevice *dev, bool enable)
{
- const struct da9063_priv *priv = dev->priv;
+ const struct da9063_priv *priv = dev_get_priv(dev);
const struct da9063_reg_info *info = priv->reg_info;
return pmic_clrsetbits(dev->parent, info->en_reg,
static int da9063_get_voltage(struct udevice *dev)
{
- const struct da9063_priv *priv = dev->priv;
+ const struct da9063_priv *priv = dev_get_priv(dev);
const struct da9063_reg_info *info = priv->reg_info;
int ret;
static int da9063_set_voltage(struct udevice *dev, int uV)
{
- const struct da9063_priv *priv = dev->priv;
+ const struct da9063_priv *priv = dev_get_priv(dev);
const struct da9063_reg_info *info = priv->reg_info;
uint sel;
static int ldo_get_mode(struct udevice *dev)
{
- const struct da9063_priv *priv = dev->priv;
+ const struct da9063_priv *priv = dev_get_priv(dev);
const struct da9063_reg_info *info = priv->reg_info;
int val;
static int ldo_set_mode(struct udevice *dev, int mode_id)
{
- const struct da9063_priv *priv = dev->priv;
+ const struct da9063_priv *priv = dev_get_priv(dev);
const struct da9063_reg_info *info = priv->reg_info;
const struct dm_regulator_mode *mode;
static int buck_get_mode(struct udevice *dev)
{
- const struct da9063_priv *priv = dev->priv;
+ const struct da9063_priv *priv = dev_get_priv(dev);
const struct da9063_reg_info *info = priv->reg_info;
int i;
int val;
static int buck_set_mode(struct udevice *dev, int mode_id)
{
- const struct da9063_priv *priv = dev->priv;
+ const struct da9063_priv *priv = dev_get_priv(dev);
const struct da9063_reg_info *info = priv->reg_info;
const struct dm_regulator_mode *mode;
static int buck_get_current_limit(struct udevice *dev)
{
- const struct da9063_priv *priv = dev->priv;
+ const struct da9063_priv *priv = dev_get_priv(dev);
const struct da9063_reg_info *info = priv->reg_info;
int val;
static int buck_set_current_limit(struct udevice *dev, int uA)
{
- const struct da9063_priv *priv = dev->priv;
+ const struct da9063_priv *priv = dev_get_priv(dev);
const struct da9063_reg_info *info = priv->reg_info;
int val;
static int da9063_ldo_probe(struct udevice *dev)
{
struct dm_regulator_uclass_plat *uc_pdata;
- struct da9063_priv *priv = dev->priv;
+ struct da9063_priv *priv = dev_get_priv(dev);
/* LDOs are named numerically in DT so can directly index */
if (dev->driver_data < 1 ||
static int da9063_buck_probe(struct udevice *dev)
{
struct dm_regulator_uclass_plat *uc_pdata;
- struct da9063_priv *priv = dev->priv;
+ struct da9063_priv *priv = dev_get_priv(dev);
int i;
/* Bucks have names rather than numbers so need to match with DT */
#include <syscon.h>
#include <linux/bitops.h>
#include <linux/ioport.h>
+#include <dm/device-internal.h>
#include <dm/read.h>
#ifdef CONFIG_MMC_OMAP36XX_PINS
#include <asm/arch/sys_proto.h>
{
int children;
- children = pmic_bind_children(dev, dev->node, pmic_children_info);
+ children = pmic_bind_children(dev, dev_ofnode(dev),
+ pmic_children_info);
if (!children)
debug("%s: %s - no child found\n", __func__, dev->name);
}
uc_pdata->type = REGULATOR_TYPE_OTHER;
- dev->priv = (void *)*p;
+ dev_set_priv(dev, (void *)*p);
return 0;
}
if (strcmp(cdev->driver->name, "fixed_rate_clock"))
continue;
- str = ofnode_read_string(cdev->node, "clock-output-names");
+ str = ofnode_read_string(dev_ofnode(cdev),
+ "clock-output-names");
if (!str)
continue;
if (!strcmp(str, "xtal")) {
err = uclass_get_device_by_ofnode(UCLASS_CLK,
- cdev->node,
+ dev_ofnode(cdev),
&cdev);
if (err) {
printf("%s%d: Failed to get xtal clk\n", __func__, i);
return -EINVAL;
}
- err = uclass_get_device_by_ofnode(UCLASS_CLK, cdev->node, &cdev);
+ err = uclass_get_device_by_ofnode(UCLASS_CLK,
+ dev_ofnode(cdev),
+ &cdev);
if (err) {
printf("%s%d: Failed to get clk controller\n", __func__, i);
return err;
/* See if we need to populate via fdt */
- if (!dev->plat) {
+ if (!dev_get_plat(dev)) {
#if CONFIG_IS_ENABLED(OF_CONTROL)
int node = dev_of_offset(dev);
const void *blob = gd->fdt_blob;
#endif
} else {
- struct dm_rproc_uclass_pdata *pdata = dev->plat;
+ struct dm_rproc_uclass_pdata *pdata = dev_get_plat(dev);
debug("'%s': using legacy data\n", dev->name);
if (pdata->name)
struct dm_rproc_uclass_pdata *uc_pdata,
const void *data)
{
- if (dev->flags & DM_FLAG_ACTIVATED)
+ if (dev_get_flags(dev) & DM_FLAG_ACTIVATED)
return 0;
return -EAGAIN;
.mem_type = RPROC_INTERNAL_MEMORY_MAPPED,
};
-U_BOOT_DEVICE(proc_3_demo) = {
+U_BOOT_DRVINFO(proc_3_demo) = {
.name = "sandbox_test_proc",
.plat = &proc_3_test,
};
/* get SCU base from clock device */
rc = uclass_get_device_by_driver(UCLASS_CLK,
- DM_GET_DRIVER(aspeed_ast2500_scu), &scu_dev);
+ DM_DRIVER_GET(aspeed_ast2500_scu), &scu_dev);
if (rc) {
debug("%s: clock device not found, rc=%d\n", __func__, rc);
return rc;
#include <regmap.h>
#include <reset-uclass.h>
#include <syscon.h>
+#include <dm/device-internal.h>
#include <linux/bitops.h>
#include <linux/err.h>
priv = malloc(sizeof(struct mediatek_reset_priv));
priv->regofs = regofs;
priv->nr_resets = num_regs * 32;
- rst_dev->priv = priv;
+ dev_set_priv(rst_dev, priv);
return 0;
}
#include <linux/bitops.h>
#include <linux/io.h>
#include <asm/arch-rockchip/hardware.h>
+#include <dm/device-internal.h>
#include <dm/lists.h>
/*
* Each reg has 16 bits reset signal for devices
priv = malloc(sizeof(struct rockchip_reset_priv));
priv->reset_reg_offset = reg_offset;
priv->reset_reg_num = reg_number;
- rst_dev->priv = priv;
+ dev_set_priv(rst_dev, priv);
return 0;
}
#include <reset-uclass.h>
#include <asm/io.h>
#include <dm/device_compat.h>
+#include <dm/device-internal.h>
#include <dm/lists.h>
#include <linux/bitops.h>
}
priv = malloc(sizeof(struct sifive_reset_priv));
priv->nr_reset = count;
- rst_dev->priv = priv;
+ dev_set_priv(rst_dev, priv);
return 0;
}
* Bind it to the node, too, so that it can get its base address.
*/
ret = device_bind_driver_to_node(dev, "socfpga_sysreset", "sysreset",
- dev->node, &sys_child);
+ dev_ofnode(dev), &sys_child);
if (ret)
debug("Warning: No sysreset driver: ret=%d\n", ret);
#include <malloc.h>
#include <reset-uclass.h>
#include <asm/io.h>
+#include <dm/device-internal.h>
#include <dm/lists.h>
#include <linux/bitops.h>
#include <linux/log2.h>
priv = malloc(sizeof(struct sunxi_reset_priv));
priv->count = count;
priv->desc = (const struct ccu_desc *)dev_get_driver_data(dev);
- rst_dev->priv = priv;
+ dev_set_priv(rst_dev, priv);
return 0;
}
.priv_auto = sizeof(struct emul_rtc),
};
-U_BOOT_DEVICE(rtc_emul) = {
+U_BOOT_DRVINFO(rtc_emul) = {
.name = "rtc_emul",
};
static int altera_jtaguart_putc(struct udevice *dev, const char ch)
{
- struct altera_jtaguart_plat *plat = dev->plat;
+ struct altera_jtaguart_plat *plat = dev_get_plat(dev);
struct altera_jtaguart_regs *const regs = plat->regs;
u32 st = readl(®s->control);
static int altera_jtaguart_pending(struct udevice *dev, bool input)
{
- struct altera_jtaguart_plat *plat = dev->plat;
+ struct altera_jtaguart_plat *plat = dev_get_plat(dev);
struct altera_jtaguart_regs *const regs = plat->regs;
u32 st = readl(®s->control);
static int altera_jtaguart_getc(struct udevice *dev)
{
- struct altera_jtaguart_plat *plat = dev->plat;
+ struct altera_jtaguart_plat *plat = dev_get_plat(dev);
struct altera_jtaguart_regs *const regs = plat->regs;
u32 val;
static int altera_jtaguart_probe(struct udevice *dev)
{
#ifdef CONFIG_ALTERA_JTAG_UART_BYPASS
- struct altera_jtaguart_plat *plat = dev->plat;
+ struct altera_jtaguart_plat *plat = dev_get_plat(dev);
struct altera_jtaguart_regs *const regs = plat->regs;
writel(ALTERA_JTAG_AC, ®s->control); /* clear AC flag */
static int altera_uart_setbrg(struct udevice *dev, int baudrate)
{
- struct altera_uart_plat *plat = dev->plat;
+ struct altera_uart_plat *plat = dev_get_plat(dev);
struct altera_uart_regs *const regs = plat->regs;
u32 div;
static int altera_uart_putc(struct udevice *dev, const char ch)
{
- struct altera_uart_plat *plat = dev->plat;
+ struct altera_uart_plat *plat = dev_get_plat(dev);
struct altera_uart_regs *const regs = plat->regs;
if (!(readl(®s->status) & ALTERA_UART_TRDY))
static int altera_uart_pending(struct udevice *dev, bool input)
{
- struct altera_uart_plat *plat = dev->plat;
+ struct altera_uart_plat *plat = dev_get_plat(dev);
struct altera_uart_regs *const regs = plat->regs;
u32 st = readl(®s->status);
static int altera_uart_getc(struct udevice *dev)
{
- struct altera_uart_plat *plat = dev->plat;
+ struct altera_uart_plat *plat = dev_get_plat(dev);
struct altera_uart_regs *const regs = plat->regs;
if (!(readl(®s->status) & ALTERA_UART_RRDY))
static int atmel_serial_probe(struct udevice *dev)
{
- struct atmel_serial_plat *plat = dev->plat;
+ struct atmel_serial_plat *plat = dev_get_plat(dev);
struct atmel_serial_priv *priv = dev_get_priv(dev);
int ret;
#if CONFIG_IS_ENABLED(OF_CONTROL)
#endif /* CONFIG_NS16550_DYNAMIC */
-static void ns16550_writeb(NS16550_t port, int offset, int value)
+static void ns16550_writeb(struct ns16550 *port, int offset, int value)
{
struct ns16550_plat *plat = port->plat;
unsigned char *addr;
serial_out_shift(addr, plat->reg_shift, value);
}
-static int ns16550_readb(NS16550_t port, int offset)
+static int ns16550_readb(struct ns16550 *port, int offset)
{
struct ns16550_plat *plat = port->plat;
unsigned char *addr;
return serial_in_shift(addr, plat->reg_shift);
}
-static u32 ns16550_getfcr(NS16550_t port)
+static u32 ns16550_getfcr(struct ns16550 *port)
{
struct ns16550_plat *plat = port->plat;
ns16550_readb(com_port, \
(unsigned char *)addr - (unsigned char *)com_port)
#else
-static u32 ns16550_getfcr(NS16550_t port)
+static u32 ns16550_getfcr(struct ns16550 *port)
{
return UART_FCR_DEFVAL;
}
#endif
-int ns16550_calc_divisor(NS16550_t port, int clock, int baudrate)
+int ns16550_calc_divisor(struct ns16550 *port, int clock, int baudrate)
{
const unsigned int mode_x_div = 16;
return DIV_ROUND_CLOSEST(clock, mode_x_div * baudrate);
}
-static void NS16550_setbrg(NS16550_t com_port, int baud_divisor)
+static void ns16550_setbrg(struct ns16550 *com_port, int baud_divisor)
{
/* to keep serial format, read lcr before writing BKSE */
int lcr_val = serial_in(&com_port->lcr) & ~UART_LCR_BKSE;
serial_out(lcr_val, &com_port->lcr);
}
-void NS16550_init(NS16550_t com_port, int baud_divisor)
+void ns16550_init(struct ns16550 *com_port, int baud_divisor)
{
#if (defined(CONFIG_SPL_BUILD) && \
(defined(CONFIG_OMAP34XX) || defined(CONFIG_OMAP44XX)))
if ((serial_in(&com_port->lsr) & (UART_LSR_TEMT | UART_LSR_THRE))
== UART_LSR_THRE) {
if (baud_divisor != -1)
- NS16550_setbrg(com_port, baud_divisor);
+ ns16550_setbrg(com_port, baud_divisor);
else {
// Re-use old baud rate divisor to flush transmit reg.
const int dll = serial_in(&com_port->dll);
const int dlm = serial_in(&com_port->dlm);
const int divisor = dll | (dlm << 8);
- NS16550_setbrg(com_port, divisor);
+ ns16550_setbrg(com_port, divisor);
}
serial_out(0, &com_port->mdr1);
}
/* initialize serial config to 8N1 before writing baudrate */
serial_out(UART_LCRVAL, &com_port->lcr);
if (baud_divisor != -1)
- NS16550_setbrg(com_port, baud_divisor);
+ ns16550_setbrg(com_port, baud_divisor);
#if defined(CONFIG_ARCH_OMAP2PLUS) || defined(CONFIG_SOC_DA8XX) || \
defined(CONFIG_OMAP_SERIAL)
/* /16 is proper to hit 115200 with 48MHz */
}
#ifndef CONFIG_NS16550_MIN_FUNCTIONS
-void NS16550_reinit(NS16550_t com_port, int baud_divisor)
+void ns16550_reinit(struct ns16550 *com_port, int baud_divisor)
{
serial_out(CONFIG_SYS_NS16550_IER, &com_port->ier);
- NS16550_setbrg(com_port, 0);
+ ns16550_setbrg(com_port, 0);
serial_out(UART_MCRVAL, &com_port->mcr);
serial_out(ns16550_getfcr(com_port), &com_port->fcr);
- NS16550_setbrg(com_port, baud_divisor);
+ ns16550_setbrg(com_port, baud_divisor);
}
#endif /* CONFIG_NS16550_MIN_FUNCTIONS */
-void NS16550_putc(NS16550_t com_port, char c)
+void ns16550_putc(struct ns16550 *com_port, char c)
{
while ((serial_in(&com_port->lsr) & UART_LSR_THRE) == 0)
;
}
#ifndef CONFIG_NS16550_MIN_FUNCTIONS
-char NS16550_getc(NS16550_t com_port)
+char ns16550_getc(struct ns16550 *com_port)
{
while ((serial_in(&com_port->lsr) & UART_LSR_DR) == 0) {
#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_USB_TTY)
return serial_in(&com_port->rbr);
}
-int NS16550_tstc(NS16550_t com_port)
+int ns16550_tstc(struct ns16550 *com_port)
{
return (serial_in(&com_port->lsr) & UART_LSR_DR) != 0;
}
static inline void _debug_uart_init(void)
{
- struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
+ struct ns16550 *com_port = (struct ns16550 *)CONFIG_DEBUG_UART_BASE;
int baud_divisor;
/*
serial_dout(&com_port->lcr, UART_LCRVAL);
}
-static inline int NS16550_read_baud_divisor(struct NS16550 *com_port)
+static inline int NS16550_read_baud_divisor(struct ns16550 *com_port)
{
int ret;
static inline void _debug_uart_putc(int ch)
{
- struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
+ struct ns16550 *com_port = (struct ns16550 *)CONFIG_DEBUG_UART_BASE;
while (!(serial_din(&com_port->lsr) & UART_LSR_THRE)) {
#ifdef CONFIG_DEBUG_UART_NS16550_CHECK_ENABLED
#if CONFIG_IS_ENABLED(DM_SERIAL)
static int ns16550_serial_putc(struct udevice *dev, const char ch)
{
- struct NS16550 *const com_port = dev_get_priv(dev);
+ struct ns16550 *const com_port = dev_get_priv(dev);
if (!(serial_in(&com_port->lsr) & UART_LSR_THRE))
return -EAGAIN;
static int ns16550_serial_pending(struct udevice *dev, bool input)
{
- struct NS16550 *const com_port = dev_get_priv(dev);
+ struct ns16550 *const com_port = dev_get_priv(dev);
if (input)
return (serial_in(&com_port->lsr) & UART_LSR_DR) ? 1 : 0;
static int ns16550_serial_getc(struct udevice *dev)
{
- struct NS16550 *const com_port = dev_get_priv(dev);
+ struct ns16550 *const com_port = dev_get_priv(dev);
if (!(serial_in(&com_port->lsr) & UART_LSR_DR))
return -EAGAIN;
static int ns16550_serial_setbrg(struct udevice *dev, int baudrate)
{
- struct NS16550 *const com_port = dev_get_priv(dev);
+ struct ns16550 *const com_port = dev_get_priv(dev);
struct ns16550_plat *plat = com_port->plat;
int clock_divisor;
clock_divisor = ns16550_calc_divisor(com_port, plat->clock, baudrate);
- NS16550_setbrg(com_port, clock_divisor);
+ ns16550_setbrg(com_port, clock_divisor);
return 0;
}
static int ns16550_serial_setconfig(struct udevice *dev, uint serial_config)
{
- struct NS16550 *const com_port = dev_get_priv(dev);
+ struct ns16550 *const com_port = dev_get_priv(dev);
int lcr_val = UART_LCR_WLS_8;
uint parity = SERIAL_GET_PARITY(serial_config);
uint bits = SERIAL_GET_BITS(serial_config);
static int ns16550_serial_getinfo(struct udevice *dev,
struct serial_device_info *info)
{
- struct NS16550 *const com_port = dev_get_priv(dev);
+ struct ns16550 *const com_port = dev_get_priv(dev);
struct ns16550_plat *plat = com_port->plat;
info->type = SERIAL_CHIP_16550_COMPATIBLE;
int ns16550_serial_probe(struct udevice *dev)
{
- struct ns16550_plat *plat = dev->plat;
- struct NS16550 *const com_port = dev_get_priv(dev);
+ struct ns16550_plat *plat = dev_get_plat(dev);
+ struct ns16550 *const com_port = dev_get_priv(dev);
struct reset_ctl_bulk reset_bulk;
fdt_addr_t addr;
int ret;
reset_deassert_bulk(&reset_bulk);
com_port->plat = dev_get_plat(dev);
- NS16550_init(com_port, -1);
+ ns16550_init(com_port, -1);
return 0;
}
#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
int ns16550_serial_of_to_plat(struct udevice *dev)
{
- struct ns16550_plat *plat = dev->plat;
+ struct ns16550_plat *plat = dev_get_plat(dev);
const u32 port_type = dev_get_driver_data(dev);
fdt_addr_t addr;
struct clk clk;
.of_to_plat = ns16550_serial_of_to_plat,
.plat_auto = sizeof(struct ns16550_plat),
#endif
- .priv_auto = sizeof(struct NS16550),
+ .priv_auto = sizeof(struct ns16550),
.probe = ns16550_serial_probe,
.ops = &ns16550_serial_ops,
#if !CONFIG_IS_ENABLED(OF_CONTROL)
#endif
};
-U_BOOT_DRIVER_ALIAS(ns16550_serial, rockchip_rk3328_uart)
-U_BOOT_DRIVER_ALIAS(ns16550_serial, rockchip_rk3368_uart)
-U_BOOT_DRIVER_ALIAS(ns16550_serial, ti_da830_uart)
+DM_DRIVER_ALIAS(ns16550_serial, rockchip_rk3328_uart)
+DM_DRIVER_ALIAS(ns16550_serial, rockchip_rk3368_uart)
+DM_DRIVER_ALIAS(ns16550_serial, ti_da830_uart)
#endif
#endif /* SERIAL_PRESENT */
#include <serial.h>
#include <video.h>
#include <linux/compiler.h>
+#include <asm/serial.h>
#include <asm/state.h>
DECLARE_GLOBAL_DATA_PTR;
-struct sandbox_serial_plat {
- int colour; /* Text colour to use for output, -1 for none */
-};
-
-/**
- * struct sandbox_serial_priv - Private data for this driver
- *
- * @buf: holds input characters available to be read by this driver
- */
-struct sandbox_serial_priv {
- struct membuff buf;
- char serial_buf[16];
- bool start_of_line;
-};
-
/**
* output_ansi_colour() - Output an ANSI colour code
*
static int sandbox_serial_remove(struct udevice *dev)
{
- struct sandbox_serial_plat *plat = dev->plat;
+ struct sandbox_serial_plat *plat = dev_get_plat(dev);
if (plat->colour != -1)
output_ansi_reset();
static int sandbox_serial_putc(struct udevice *dev, const char ch)
{
struct sandbox_serial_priv *priv = dev_get_priv(dev);
- struct sandbox_serial_plat *plat = dev->plat;
+ struct sandbox_serial_plat *plat = dev_get_plat(dev);
/* With of-platdata we don't real the colour correctly, so disable it */
if (!CONFIG_IS_ENABLED(OF_PLATDATA) && priv->start_of_line &&
static int sandbox_serial_of_to_plat(struct udevice *dev)
{
- struct sandbox_serial_plat *plat = dev->plat;
+ struct sandbox_serial_plat *plat = dev_get_plat(dev);
const char *colour;
int i;
.colour = -1,
};
-U_BOOT_DEVICE(serial_sandbox_non_fdt) = {
+U_BOOT_DRVINFO(serial_sandbox_non_fdt) = {
.name = "sandbox_serial",
.plat = &platdata_non_fdt,
};
#ifdef CONFIG_SERIAL_SEARCH_ALL
if (!uclass_get_device_by_seq(UCLASS_SERIAL, INDEX, &dev) ||
!uclass_get_device(UCLASS_SERIAL, INDEX, &dev)) {
- if (dev->flags & DM_FLAG_ACTIVATED) {
+ if (dev_get_flags(dev) & DM_FLAG_ACTIVATED) {
gd->cur_serial_dev = dev;
return;
}
static int arc_serial_setbrg(struct udevice *dev, int baudrate)
{
- struct arc_serial_plat *plat = dev->plat;
+ struct arc_serial_plat *plat = dev_get_plat(dev);
struct arc_serial_regs *const regs = plat->reg;
int arc_console_baud = gd->cpu_clk / (baudrate * 4) - 1;
static int arc_serial_putc(struct udevice *dev, const char c)
{
- struct arc_serial_plat *plat = dev->plat;
+ struct arc_serial_plat *plat = dev_get_plat(dev);
struct arc_serial_regs *const regs = plat->reg;
while (!(readb(®s->status) & UART_TXEMPTY))
static int arc_serial_pending(struct udevice *dev, bool input)
{
- struct arc_serial_plat *plat = dev->plat;
+ struct arc_serial_plat *plat = dev_get_plat(dev);
struct arc_serial_regs *const regs = plat->reg;
uint32_t status = readb(®s->status);
static int arc_serial_getc(struct udevice *dev)
{
- struct arc_serial_plat *plat = dev->plat;
+ struct arc_serial_plat *plat = dev_get_plat(dev);
struct arc_serial_regs *const regs = plat->reg;
while (!arc_serial_tstc(regs))
.name = "coreboot_uart",
.id = UCLASS_SERIAL,
.of_match = coreboot_serial_ids,
- .priv_auto = sizeof(struct NS16550),
+ .priv_auto = sizeof(struct ns16550),
.plat_auto = sizeof(struct ns16550_plat),
.of_to_plat = coreboot_of_to_plat,
.probe = ns16550_serial_probe,
.of_match = mid_serial_ids,
.of_to_plat = ns16550_serial_of_to_plat,
.plat_auto = sizeof(struct ns16550_plat),
- .priv_auto = sizeof(struct NS16550),
+ .priv_auto = sizeof(struct ns16550),
.probe = mid_serial_probe,
.ops = &ns16550_serial_ops,
};
static int linflex_serial_probe(struct udevice *dev)
{
- struct linflex_serial_plat *plat = dev->plat;
+ struct linflex_serial_plat *plat = dev_get_plat(dev);
struct linflex_serial_priv *priv = dev_get_priv(dev);
priv->lfuart = (struct linflex_fsl *)plat->base_addr;
static bool is_lpuart32(struct udevice *dev)
{
- struct lpuart_serial_plat *plat = dev->plat;
+ struct lpuart_serial_plat *plat = dev_get_plat(dev);
return plat->flags & LPUART_FLAG_REGMAP_32BIT_REG;
}
static int lpuart_serial_getc(struct udevice *dev)
{
- struct lpuart_serial_plat *plat = dev->plat;
+ struct lpuart_serial_plat *plat = dev_get_plat(dev);
if (is_lpuart32(dev))
return _lpuart32_serial_getc(plat);
static int lpuart_serial_putc(struct udevice *dev, const char c)
{
- struct lpuart_serial_plat *plat = dev->plat;
+ struct lpuart_serial_plat *plat = dev_get_plat(dev);
if (is_lpuart32(dev))
_lpuart32_serial_putc(plat, c);
static int lpuart_serial_pending(struct udevice *dev, bool input)
{
- struct lpuart_serial_plat *plat = dev->plat;
+ struct lpuart_serial_plat *plat = dev_get_plat(dev);
struct lpuart_fsl *reg = plat->reg;
struct lpuart_fsl_reg32 *reg32 = plat->reg;
u32 stat;
static int lpuart_serial_of_to_plat(struct udevice *dev)
{
- struct lpuart_serial_plat *plat = dev->plat;
+ struct lpuart_serial_plat *plat = dev_get_plat(dev);
const void *blob = gd->fdt_blob;
int node = dev_of_offset(dev);
fdt_addr_t addr;
static int coldfire_serial_probe(struct udevice *dev)
{
- struct coldfire_serial_plat *plat = dev->plat;
+ struct coldfire_serial_plat *plat = dev_get_plat(dev);
plat->port = dev_seq(dev);
static int coldfire_serial_putc(struct udevice *dev, const char ch)
{
- struct coldfire_serial_plat *plat = dev->plat;
+ struct coldfire_serial_plat *plat = dev_get_plat(dev);
uart_t *uart = (uart_t *)plat->base;
/* Wait for last character to go. */
static int coldfire_serial_getc(struct udevice *dev)
{
- struct coldfire_serial_plat *plat = dev->plat;
+ struct coldfire_serial_plat *plat = dev_get_plat(dev);
uart_t *uart = (uart_t *)(plat->base);
/* Wait for a character to arrive. */
int coldfire_serial_setbrg(struct udevice *dev, int baudrate)
{
- struct coldfire_serial_plat *plat = dev->plat;
+ struct coldfire_serial_plat *plat = dev_get_plat(dev);
uart_t *uart = (uart_t *)(plat->base);
mcf_serial_setbrg_common(uart, baudrate);
static int coldfire_serial_pending(struct udevice *dev, bool input)
{
- struct coldfire_serial_plat *plat = dev->plat;
+ struct coldfire_serial_plat *plat = dev_get_plat(dev);
uart_t *uart = (uart_t *)(plat->base);
if (input)
static int meson_serial_probe(struct udevice *dev)
{
- struct meson_serial_plat *plat = dev->plat;
+ struct meson_serial_plat *plat = dev_get_plat(dev);
struct meson_uart *const uart = plat->reg;
meson_serial_init(uart);
static void meson_serial_rx_error(struct udevice *dev)
{
- struct meson_serial_plat *plat = dev->plat;
+ struct meson_serial_plat *plat = dev_get_plat(dev);
struct meson_uart *const uart = plat->reg;
u32 val = readl(&uart->control);
static int meson_serial_getc(struct udevice *dev)
{
- struct meson_serial_plat *plat = dev->plat;
+ struct meson_serial_plat *plat = dev_get_plat(dev);
struct meson_uart *const uart = plat->reg;
uint32_t status = readl(&uart->status);
static int meson_serial_putc(struct udevice *dev, const char ch)
{
- struct meson_serial_plat *plat = dev->plat;
+ struct meson_serial_plat *plat = dev_get_plat(dev);
struct meson_uart *const uart = plat->reg;
if (readl(&uart->status) & AML_UART_TX_FULL)
static int meson_serial_pending(struct udevice *dev, bool input)
{
- struct meson_serial_plat *plat = dev->plat;
+ struct meson_serial_plat *plat = dev_get_plat(dev);
struct meson_uart *const uart = plat->reg;
uint32_t status = readl(&uart->status);
static int meson_serial_of_to_plat(struct udevice *dev)
{
- struct meson_serial_plat *plat = dev->plat;
+ struct meson_serial_plat *plat = dev_get_plat(dev);
fdt_addr_t addr;
addr = dev_read_addr(dev);
int mxc_serial_setbrg(struct udevice *dev, int baudrate)
{
- struct mxc_serial_plat *plat = dev->plat;
+ struct mxc_serial_plat *plat = dev_get_plat(dev);
u32 clk = imx_get_uartclk();
_mxc_serial_setbrg(plat->reg, clk, baudrate, plat->use_dte);
static int mxc_serial_probe(struct udevice *dev)
{
- struct mxc_serial_plat *plat = dev->plat;
+ struct mxc_serial_plat *plat = dev_get_plat(dev);
_mxc_serial_init(plat->reg, plat->use_dte);
static int mxc_serial_getc(struct udevice *dev)
{
- struct mxc_serial_plat *plat = dev->plat;
+ struct mxc_serial_plat *plat = dev_get_plat(dev);
struct mxc_uart *const uart = plat->reg;
if (readl(&uart->ts) & UTS_RXEMPTY)
static int mxc_serial_putc(struct udevice *dev, const char ch)
{
- struct mxc_serial_plat *plat = dev->plat;
+ struct mxc_serial_plat *plat = dev_get_plat(dev);
struct mxc_uart *const uart = plat->reg;
if (!(readl(&uart->ts) & UTS_TXEMPTY))
static int mxc_serial_pending(struct udevice *dev, bool input)
{
- struct mxc_serial_plat *plat = dev->plat;
+ struct mxc_serial_plat *plat = dev_get_plat(dev);
struct mxc_uart *const uart = plat->reg;
uint32_t sr2 = readl(&uart->sr2);
#if CONFIG_IS_ENABLED(OF_CONTROL)
static int mxc_serial_of_to_plat(struct udevice *dev)
{
- struct mxc_serial_plat *plat = dev->plat;
+ struct mxc_serial_plat *plat = dev_get_plat(dev);
fdt_addr_t addr;
addr = dev_read_addr(dev);
/* Note: The port number specified in the functions is 1 based.
* the array is 0 based.
*/
-static NS16550_t serial_ports[6] = {
+static struct ns16550 *serial_ports[6] = {
#ifdef CONFIG_SYS_NS16550_COM1
- (NS16550_t)CONFIG_SYS_NS16550_COM1,
+ (struct ns16550 *)CONFIG_SYS_NS16550_COM1,
#else
NULL,
#endif
#ifdef CONFIG_SYS_NS16550_COM2
- (NS16550_t)CONFIG_SYS_NS16550_COM2,
+ (struct ns16550 *)CONFIG_SYS_NS16550_COM2,
#else
NULL,
#endif
#ifdef CONFIG_SYS_NS16550_COM3
- (NS16550_t)CONFIG_SYS_NS16550_COM3,
+ (struct ns16550 *)CONFIG_SYS_NS16550_COM3,
#else
NULL,
#endif
#ifdef CONFIG_SYS_NS16550_COM4
- (NS16550_t)CONFIG_SYS_NS16550_COM4,
+ (struct ns16550 *)CONFIG_SYS_NS16550_COM4,
#else
NULL,
#endif
#ifdef CONFIG_SYS_NS16550_COM5
- (NS16550_t)CONFIG_SYS_NS16550_COM5,
+ (struct ns16550 *)CONFIG_SYS_NS16550_COM5,
#else
NULL,
#endif
#ifdef CONFIG_SYS_NS16550_COM6
- (NS16550_t)CONFIG_SYS_NS16550_COM6
+ (struct ns16550 *)CONFIG_SYS_NS16550_COM6
#else
NULL
#endif
int clock_divisor; \
clock_divisor = ns16550_calc_divisor(serial_ports[port-1], \
CONFIG_SYS_NS16550_CLK, gd->baudrate); \
- NS16550_init(serial_ports[port-1], clock_divisor); \
+ ns16550_init(serial_ports[port - 1], clock_divisor); \
return 0 ; \
} \
static void eserial##port##_setbrg(void) \
static void _serial_putc(const char c, const int port)
{
if (c == '\n')
- NS16550_putc(PORT, '\r');
+ ns16550_putc(PORT, '\r');
- NS16550_putc(PORT, c);
+ ns16550_putc(PORT, c);
}
static void _serial_puts(const char *s, const int port)
static int _serial_getc(const int port)
{
- return NS16550_getc(PORT);
+ return ns16550_getc(PORT);
}
static int _serial_tstc(const int port)
{
- return NS16550_tstc(PORT);
+ return ns16550_tstc(PORT);
}
static void _serial_setbrg(const int port)
clock_divisor = ns16550_calc_divisor(PORT, CONFIG_SYS_NS16550_CLK,
gd->baudrate);
- NS16550_reinit(PORT, clock_divisor);
+ ns16550_reinit(PORT, clock_divisor);
}
static inline void
static inline void _debug_uart_init(void)
{
- struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
+ struct ns16550 *com_port = (struct ns16550 *)CONFIG_DEBUG_UART_BASE;
int baud_divisor;
baud_divisor = ns16550_calc_divisor(com_port, CONFIG_DEBUG_UART_CLOCK,
static inline void _debug_uart_putc(int ch)
{
- struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
+ struct ns16550 *com_port = (struct ns16550 *)CONFIG_DEBUG_UART_BASE;
while (!(serial_din(&com_port->lsr) & UART_LSR_THRE))
;
#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
static int omap_serial_of_to_plat(struct udevice *dev)
{
- struct ns16550_plat *plat = dev->plat;
+ struct ns16550_plat *plat = dev_get_plat(dev);
fdt_addr_t addr;
struct clk clk;
int err;
.of_to_plat = omap_serial_of_to_plat,
.plat_auto = sizeof(struct ns16550_plat),
#endif
- .priv_auto = sizeof(struct NS16550),
+ .priv_auto = sizeof(struct ns16550),
.probe = ns16550_serial_probe,
.ops = &ns16550_serial_ops,
#if !CONFIG_IS_ENABLED(OF_CONTROL)
#ifdef CONFIG_DM_SERIAL
static int pxa_serial_probe(struct udevice *dev)
{
- struct pxa_serial_plat *plat = dev->plat;
+ struct pxa_serial_plat *plat = dev_get_plat(dev);
pxa_setbrg_common((struct pxa_uart_regs *)plat->base, plat->port,
plat->baudrate);
static int pxa_serial_putc(struct udevice *dev, const char ch)
{
- struct pxa_serial_plat *plat = dev->plat;
+ struct pxa_serial_plat *plat = dev_get_plat(dev);
struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base;
/* Wait for last character to go. */
static int pxa_serial_getc(struct udevice *dev)
{
- struct pxa_serial_plat *plat = dev->plat;
+ struct pxa_serial_plat *plat = dev_get_plat(dev);
struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base;
/* Wait for a character to arrive. */
int pxa_serial_setbrg(struct udevice *dev, int baudrate)
{
- struct pxa_serial_plat *plat = dev->plat;
+ struct pxa_serial_plat *plat = dev_get_plat(dev);
struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base;
int port = plat->port;
static int pxa_serial_pending(struct udevice *dev, bool input)
{
- struct pxa_serial_plat *plat = dev->plat;
+ struct pxa_serial_plat *plat = dev_get_plat(dev);
struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base;
if (input)
#include <ns16550.h>
#include <serial.h>
#include <asm/arch-rockchip/clock.h>
+#include <dm/device-internal.h>
#if defined(CONFIG_ROCKCHIP_RK3188)
struct rockchip_uart_plat {
plat->plat.reg_shift = plat->dtplat.reg_shift;
plat->plat.clock = plat->dtplat.clock_frequency;
plat->plat.fcr = UART_FCR_DEFVAL;
- dev->plat = &plat->plat;
+ dev_set_plat(dev, &plat->plat);
return ns16550_serial_probe(dev);
}
U_BOOT_DRIVER(rockchip_rk3188_uart) = {
.name = "rockchip_rk3188_uart",
.id = UCLASS_SERIAL,
- .priv_auto = sizeof(struct NS16550),
+ .priv_auto = sizeof(struct ns16550),
.plat_auto = sizeof(struct rockchip_uart_plat),
.probe = rockchip_serial_probe,
.ops = &ns16550_serial_ops,
U_BOOT_DRIVER(rockchip_rk3288_uart) = {
.name = "rockchip_rk3288_uart",
.id = UCLASS_SERIAL,
- .priv_auto = sizeof(struct NS16550),
+ .priv_auto = sizeof(struct ns16550),
.plat_auto = sizeof(struct rockchip_uart_plat),
.probe = rockchip_serial_probe,
.ops = &ns16550_serial_ops,
#ifndef CONFIG_SPL_BUILD
int s5p_serial_setbrg(struct udevice *dev, int baudrate)
{
- struct s5p_serial_plat *plat = dev->plat;
+ struct s5p_serial_plat *plat = dev_get_plat(dev);
struct s5p_uart *const uart = plat->reg;
u32 uclk;
static int s5p_serial_probe(struct udevice *dev)
{
- struct s5p_serial_plat *plat = dev->plat;
+ struct s5p_serial_plat *plat = dev_get_plat(dev);
struct s5p_uart *const uart = plat->reg;
s5p_serial_init(uart);
static int s5p_serial_getc(struct udevice *dev)
{
- struct s5p_serial_plat *plat = dev->plat;
+ struct s5p_serial_plat *plat = dev_get_plat(dev);
struct s5p_uart *const uart = plat->reg;
if (!(readl(&uart->ufstat) & RX_FIFO_COUNT_MASK))
static int s5p_serial_putc(struct udevice *dev, const char ch)
{
- struct s5p_serial_plat *plat = dev->plat;
+ struct s5p_serial_plat *plat = dev_get_plat(dev);
struct s5p_uart *const uart = plat->reg;
if (readl(&uart->ufstat) & TX_FIFO_FULL)
static int s5p_serial_pending(struct udevice *dev, bool input)
{
- struct s5p_serial_plat *plat = dev->plat;
+ struct s5p_serial_plat *plat = dev_get_plat(dev);
struct s5p_uart *const uart = plat->reg;
uint32_t ufstat = readl(&uart->ufstat);
static int s5p_serial_of_to_plat(struct udevice *dev)
{
- struct s5p_serial_plat *plat = dev->plat;
+ struct s5p_serial_plat *plat = dev_get_plat(dev);
fdt_addr_t addr;
addr = dev_read_addr(dev);
static int cadence_spi_write_speed(struct udevice *bus, uint hz)
{
- struct cadence_spi_plat *plat = bus->plat;
+ struct cadence_spi_plat *plat = dev_get_plat(bus);
struct cadence_spi_priv *priv = dev_get_priv(bus);
cadence_qspi_apb_config_baudrate_div(priv->regbase,
static int cadence_spi_set_speed(struct udevice *bus, uint hz)
{
- struct cadence_spi_plat *plat = bus->plat;
+ struct cadence_spi_plat *plat = dev_get_plat(bus);
struct cadence_spi_priv *priv = dev_get_priv(bus);
int err;
static int cadence_spi_probe(struct udevice *bus)
{
- struct cadence_spi_plat *plat = bus->plat;
+ struct cadence_spi_plat *plat = dev_get_plat(bus);
struct cadence_spi_priv *priv = dev_get_priv(bus);
struct clk clk;
int ret;
static int cadence_spi_set_mode(struct udevice *bus, uint mode)
{
- struct cadence_spi_plat *plat = bus->plat;
+ struct cadence_spi_plat *plat = dev_get_plat(bus);
struct cadence_spi_priv *priv = dev_get_priv(bus);
/* Disable QSPI */
const struct spi_mem_op *op)
{
struct udevice *bus = spi->dev->parent;
- struct cadence_spi_plat *plat = bus->plat;
+ struct cadence_spi_plat *plat = dev_get_plat(bus);
struct cadence_spi_priv *priv = dev_get_priv(bus);
void *base = priv->regbase;
int err = 0;
static int cadence_spi_of_to_plat(struct udevice *bus)
{
- struct cadence_spi_plat *plat = bus->plat;
+ struct cadence_spi_plat *plat = dev_get_plat(bus);
ofnode subnode;
plat->regbase = (void *)devfdt_get_addr_index(bus, 0);
static int coldfire_dspi_of_to_plat(struct udevice *bus)
{
fdt_addr_t addr;
- struct coldfire_spi_plat *plat = bus->plat;
+ struct coldfire_spi_plat *plat = dev_get_plat(bus);
const void *blob = gd->fdt_blob;
int node = dev_of_offset(bus);
int *ctar, len;
static int davinci_spi_probe(struct udevice *bus)
{
struct davinci_spi_slave *ds = dev_get_priv(bus);
- struct davinci_spi_plat *plat = bus->plat;
+ struct davinci_spi_plat *plat = dev_get_plat(bus);
ds->regs = plat->regs;
ds->num_cs = plat->num_cs;
#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
static int davinci_ofdata_to_platadata(struct udevice *bus)
{
- struct davinci_spi_plat *plat = bus->plat;
+ struct davinci_spi_plat *plat = dev_get_plat(bus);
fdt_addr_t addr;
addr = dev_read_addr(bus);
static int dw_spi_of_to_plat(struct udevice *bus)
{
- struct dw_spi_plat *plat = bus->plat;
+ struct dw_spi_plat *plat = dev_get_plat(bus);
plat->regs = dev_read_addr_ptr(bus);
if (!plat->regs)
static int dw_spi_set_speed(struct udevice *bus, uint speed)
{
- struct dw_spi_plat *plat = bus->plat;
+ struct dw_spi_plat *plat = dev_get_plat(bus);
struct dw_spi_priv *priv = dev_get_priv(bus);
u16 clk_div;
static int exynos_spi_of_to_plat(struct udevice *bus)
{
- struct exynos_spi_plat *plat = bus->plat;
+ struct exynos_spi_plat *plat = dev_get_plat(bus);
const void *blob = gd->fdt_blob;
int node = dev_of_offset(bus);
static int exynos_spi_set_speed(struct udevice *bus, uint speed)
{
- struct exynos_spi_plat *plat = bus->plat;
+ struct exynos_spi_plat *plat = dev_get_plat(bus);
struct exynos_spi_priv *priv = dev_get_priv(bus);
int ret;
return -EINVAL;
}
- ofnode_read_u32(dev->node, "fsl,spi-cs-sck-delay", &cs_sck_delay);
- ofnode_read_u32(dev->node, "fsl,spi-sck-cs-delay", &sck_cs_delay);
+ ofnode_read_u32(dev_ofnode(dev), "fsl,spi-cs-sck-delay",
+ &cs_sck_delay);
+ ofnode_read_u32(dev_ofnode(dev), "fsl,spi-sck-cs-delay",
+ &sck_cs_delay);
/* Set PCS to SCK delay scale values */
ns_delay_scale(&pcssck, &cssck, cs_sck_delay, priv->bus_clk);
struct dm_spi_bus *dm_spi_bus;
uint mcr_cfg_val;
- dm_spi_bus = bus->uclass_priv;
+ dm_spi_bus = dev_get_uclass_priv(bus);
/* cpu speical pin muxing configure */
cpu_dspi_port_conf();
static int fsl_dspi_of_to_plat(struct udevice *bus)
{
fdt_addr_t addr;
- struct fsl_dspi_plat *plat = bus->plat;
+ struct fsl_dspi_plat *plat = dev_get_plat(bus);
const void *blob = gd->fdt_blob;
int node = dev_of_offset(bus);
static int fsl_espi_of_to_plat(struct udevice *bus)
{
fdt_addr_t addr;
- struct fsl_espi_plat *plat = bus->plat;
+ struct fsl_espi_plat *plat = dev_get_plat(bus);
const void *blob = gd->fdt_blob;
int node = dev_of_offset(bus);
static int fsl_qspi_probe(struct udevice *bus)
{
- struct dm_spi_bus *dm_bus = bus->uclass_priv;
+ struct dm_spi_bus *dm_bus = dev_get_uclass_priv(bus);
struct fsl_qspi *q = dev_get_priv(bus);
const void *blob = gd->fdt_blob;
int node = dev_of_offset(bus);
#define debug_trace(x, args...)
#endif
-struct ich_spi_plat {
-#if CONFIG_IS_ENABLED(OF_PLATDATA)
- struct dtd_intel_fast_spi dtplat;
-#endif
- enum ich_version ich_version; /* Controller version, 7 or 9 */
- bool lockdown; /* lock down controller settings? */
- ulong mmio_base; /* Base of MMIO registers */
- pci_dev_t bdf; /* PCI address used by of-platdata */
- bool hwseq; /* Use hardware sequencing (not s/w) */
-};
-
static u8 ich_readb(struct ich_spi_priv *priv, int reg)
{
u8 value = readb(priv->base + reg);
struct udevice *pch; /* PCH, used to control SPI access */
};
+struct ich_spi_plat {
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+ struct dtd_intel_fast_spi dtplat;
+#endif
+ enum ich_version ich_version; /* Controller version, 7 or 9 */
+ bool lockdown; /* lock down controller settings? */
+ ulong mmio_base; /* Base of MMIO registers */
+ pci_dev_t bdf; /* PCI address used by of-platdata */
+ bool hwseq; /* Use hardware sequencing (not s/w) */
+};
+
#endif /* _ICH_H_ */
#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
static int mxs_of_to_plat(struct udevice *bus)
{
- struct mxs_spi_plat *plat = bus->plat;
+ struct mxs_spi_plat *plat = dev_get_plat(bus);
u32 prop[2];
int ret;
.probe = mxs_spi_probe,
};
-U_BOOT_DRIVER_ALIAS(fsl_imx23_spi, fsl_imx28_spi)
+DM_DRIVER_ALIAS(fsl_imx23_spi, fsl_imx28_spi)
#if !CONFIG_IS_ENABLED(OF_PLATDATA)
static int pl022_spi_of_to_plat(struct udevice *bus)
{
- struct pl022_spi_pdata *plat = bus->plat;
+ struct pl022_spi_pdata *plat = dev_get_plat(bus);
const void *fdt = gd->fdt_blob;
int node = dev_of_offset(bus);
struct clk clkdev;
static void spi_cs_activate(struct udevice *dev, uint cs)
{
struct udevice *bus = dev->parent;
- struct rockchip_spi_plat *plat = bus->plat;
+ struct rockchip_spi_plat *plat = dev_get_plat(bus);
struct rockchip_spi_priv *priv = dev_get_priv(bus);
struct rockchip_spi *regs = priv->regs;
static void spi_cs_deactivate(struct udevice *dev, uint cs)
{
struct udevice *bus = dev->parent;
- struct rockchip_spi_plat *plat = bus->plat;
+ struct rockchip_spi_plat *plat = dev_get_plat(bus);
struct rockchip_spi_priv *priv = dev_get_priv(bus);
struct rockchip_spi *regs = priv->regs;
#if CONFIG_IS_ENABLED(OF_PLATDATA)
static int conv_of_plat(struct udevice *dev)
{
- struct rockchip_spi_plat *plat = dev->plat;
+ struct rockchip_spi_plat *plat = dev_get_plat(dev);
struct dtd_rockchip_rk3288_spi *dtplat = &plat->of_plat;
struct rockchip_spi_priv *priv = dev_get_priv(dev);
int ret;
.probe = rockchip_spi_probe,
};
-U_BOOT_DRIVER_ALIAS(rockchip_rk3288_spi, rockchip_rk3368_spi)
+DM_DRIVER_ALIAS(rockchip_rk3288_spi, rockchip_rk3368_spi)
static int soft_spi_of_to_plat(struct udevice *dev)
{
- struct soft_spi_plat *plat = dev->plat;
+ struct soft_spi_plat *plat = dev_get_plat(dev);
const void *blob = gd->fdt_blob;
int node = dev_of_offset(dev);
static int soft_spi_probe(struct udevice *dev)
{
struct spi_slave *slave = dev_get_parent_priv(dev);
- struct soft_spi_plat *plat = dev->plat;
+ struct soft_spi_plat *plat = dev_get_plat(dev);
int cs_flags, clk_flags;
int ret;
{
struct dm_spi_slave_plat *plat = dev_get_parent_plat(dev);
- if (!dev_of_valid(dev))
+ if (!dev_has_ofnode(dev))
return 0;
return spi_slave_of_to_plat(dev, plat);
static int tegra114_spi_of_to_plat(struct udevice *bus)
{
- struct tegra_spi_plat *plat = bus->plat;
+ struct tegra_spi_plat *plat = dev_get_plat(bus);
plat->base = dev_read_addr(bus);
plat->periph_id = clock_decode_periph_id(bus);
static int tegra114_spi_set_speed(struct udevice *bus, uint speed)
{
- struct tegra_spi_plat *plat = bus->plat;
+ struct tegra_spi_plat *plat = dev_get_plat(bus);
struct tegra114_spi_priv *priv = dev_get_priv(bus);
if (speed > plat->frequency)
static int tegra20_sflash_of_to_plat(struct udevice *bus)
{
- struct tegra_spi_plat *plat = bus->plat;
+ struct tegra_spi_plat *plat = dev_get_plat(bus);
const void *blob = gd->fdt_blob;
int node = dev_of_offset(bus);
static int tegra20_sflash_set_speed(struct udevice *bus, uint speed)
{
- struct tegra_spi_plat *plat = bus->plat;
+ struct tegra_spi_plat *plat = dev_get_plat(bus);
struct tegra20_sflash_priv *priv = dev_get_priv(bus);
if (speed > plat->frequency)
static int tegra30_spi_of_to_plat(struct udevice *bus)
{
- struct tegra_spi_plat *plat = bus->plat;
+ struct tegra_spi_plat *plat = dev_get_plat(bus);
const void *blob = gd->fdt_blob;
int node = dev_of_offset(bus);
static int tegra30_spi_set_speed(struct udevice *bus, uint speed)
{
- struct tegra_spi_plat *plat = bus->plat;
+ struct tegra_spi_plat *plat = dev_get_plat(bus);
struct tegra30_spi_priv *priv = dev_get_priv(bus);
if (speed > plat->frequency)
static int tegra210_qspi_of_to_plat(struct udevice *bus)
{
- struct tegra_spi_plat *plat = bus->plat;
+ struct tegra_spi_plat *plat = dev_get_plat(bus);
plat->base = dev_read_addr(bus);
plat->periph_id = clock_decode_periph_id(bus);
static int tegra210_qspi_set_speed(struct udevice *bus, uint speed)
{
- struct tegra_spi_plat *plat = bus->plat;
+ struct tegra_spi_plat *plat = dev_get_plat(bus);
struct tegra210_qspi_priv *priv = dev_get_priv(bus);
if (speed > plat->frequency)
static void spi_cs_activate(struct udevice *dev)
{
struct udevice *bus = dev->parent;
- struct uniphier_spi_plat *plat = bus->plat;
+ struct uniphier_spi_plat *plat = dev_get_plat(bus);
struct uniphier_spi_priv *priv = dev_get_priv(bus);
ulong delay_us; /* The delay completed so far */
u32 val;
static void spi_cs_deactivate(struct udevice *dev)
{
struct udevice *bus = dev->parent;
- struct uniphier_spi_plat *plat = bus->plat;
+ struct uniphier_spi_plat *plat = dev_get_plat(bus);
struct uniphier_spi_priv *priv = dev_get_priv(bus);
u32 val;
static int uniphier_spi_set_speed(struct udevice *bus, uint speed)
{
- struct uniphier_spi_plat *plat = bus->plat;
+ struct uniphier_spi_plat *plat = dev_get_plat(bus);
struct uniphier_spi_priv *priv = dev_get_priv(bus);
u32 val, ckdiv;
static int uniphier_spi_of_to_plat(struct udevice *bus)
{
- struct uniphier_spi_plat *plat = bus->plat;
+ struct uniphier_spi_plat *plat = dev_get_plat(bus);
const void *blob = gd->fdt_blob;
int node = dev_of_offset(bus);
static int zynq_qspi_of_to_plat(struct udevice *bus)
{
- struct zynq_qspi_plat *plat = bus->plat;
+ struct zynq_qspi_plat *plat = dev_get_plat(bus);
const void *blob = gd->fdt_blob;
int node = dev_of_offset(bus);
static int zynq_qspi_set_speed(struct udevice *bus, uint speed)
{
- struct zynq_qspi_plat *plat = bus->plat;
+ struct zynq_qspi_plat *plat = dev_get_plat(bus);
struct zynq_qspi_priv *priv = dev_get_priv(bus);
struct zynq_qspi_regs *regs = priv->regs;
uint32_t confr;
static int zynq_spi_of_to_plat(struct udevice *bus)
{
- struct zynq_spi_plat *plat = bus->plat;
+ struct zynq_spi_plat *plat = dev_get_plat(bus);
const void *blob = gd->fdt_blob;
int node = dev_of_offset(bus);
static void spi_cs_activate(struct udevice *dev)
{
struct udevice *bus = dev->parent;
- struct zynq_spi_plat *plat = bus->plat;
+ struct zynq_spi_plat *plat = dev_get_plat(bus);
struct zynq_spi_priv *priv = dev_get_priv(bus);
struct zynq_spi_regs *regs = priv->regs;
u32 cr;
static void spi_cs_deactivate(struct udevice *dev)
{
struct udevice *bus = dev->parent;
- struct zynq_spi_plat *plat = bus->plat;
+ struct zynq_spi_plat *plat = dev_get_plat(bus);
struct zynq_spi_priv *priv = dev_get_priv(bus);
struct zynq_spi_regs *regs = priv->regs;
static int zynq_spi_set_speed(struct udevice *bus, uint speed)
{
- struct zynq_spi_plat *plat = bus->plat;
+ struct zynq_spi_plat *plat = dev_get_plat(bus);
struct zynq_spi_priv *priv = dev_get_priv(bus);
struct zynq_spi_regs *regs = priv->regs;
uint32_t confr;
static int zynqmp_qspi_of_to_plat(struct udevice *bus)
{
- struct zynqmp_qspi_plat *plat = bus->plat;
+ struct zynqmp_qspi_plat *plat = dev_get_plat(bus);
debug("%s\n", __func__);
void zynqmp_qspi_set_tapdelay(struct udevice *bus, u32 baudrateval)
{
- struct zynqmp_qspi_plat *plat = bus->plat;
+ struct zynqmp_qspi_plat *plat = dev_get_plat(bus);
struct zynqmp_qspi_priv *priv = dev_get_priv(bus);
struct zynqmp_qspi_regs *regs = priv->regs;
u32 tapdlybypass = 0, lpbkdlyadj = 0, datadlyadj = 0, clk_rate;
static int zynqmp_qspi_set_speed(struct udevice *bus, uint speed)
{
- struct zynqmp_qspi_plat *plat = bus->plat;
+ struct zynqmp_qspi_plat *plat = dev_get_plat(bus);
struct zynqmp_qspi_priv *priv = dev_get_priv(bus);
struct zynqmp_qspi_regs *regs = priv->regs;
u32 confr;
#include <common.h>
#include <command.h>
#include <cpu_func.h>
-#include <hang.h>
-#include <log.h>
-#include <sysreset.h>
#include <dm.h>
#include <errno.h>
+#include <hang.h>
+#include <log.h>
#include <regmap.h>
+#include <spl.h>
+#include <sysreset.h>
#include <dm/device-internal.h>
#include <dm/lists.h>
#include <dm/root.h>
mdelay(100);
/* Still no reset? Give up */
- log_err("System reset not supported on this platform\n");
+ if (spl_phase() <= PHASE_SPL)
+ log_err("no sysreset\n");
+ else
+ log_err("System reset not supported on this platform\n");
hang();
}
/*
* If we have a device tree, the device we created from platform data
- * (see the U_BOOT_DEVICE() declaration below) should not do anything.
+ * (see the U_BOOT_DRVINFO() declaration below) should not do anything.
* If we are that device, return an error.
*/
- if (state->fdt_fname && !dev_of_valid(dev))
+ if (state->fdt_fname && !dev_has_ofnode(dev))
return -ENODEV;
switch (type) {
#if !CONFIG_IS_ENABLED(OF_PLATDATA)
/* This is here in case we don't have a device tree */
-U_BOOT_DEVICE(sysreset_sandbox_non_fdt) = {
+U_BOOT_DRVINFO(sysreset_sandbox_non_fdt) = {
.name = "sysreset_sandbox",
};
#endif
#include <acpi/acpi_s3.h>
#include <asm/io.h>
#include <asm/processor.h>
-
-struct x86_sysreset_plat {
- struct udevice *pch;
-};
+#include <asm/sysreset.h>
/*
* Power down the machine by using the power management sleep control
const char *method;
debug("optee: looking for conduit method in DT.\n");
- method = ofnode_get_property(dev->node, "method", NULL);
+ method = ofnode_get_property(dev_ofnode(dev), "method", NULL);
if (!method) {
debug("optee: missing \"method\" property\n");
return ERR_PTR(-ENXIO);
static u64 atftmr_timer_get_count(struct udevice *dev)
{
- struct atftmr_timer_plat *plat = dev->plat;
+ struct atftmr_timer_plat *plat = dev_get_plat(dev);
struct atftmr_timer_regs *const regs = plat->regs;
u32 val;
val = readl(®s->t3_counter);
static int atftmr_timer_probe(struct udevice *dev)
{
- struct atftmr_timer_plat *plat = dev->plat;
+ struct atftmr_timer_plat *plat = dev_get_plat(dev);
struct atftmr_timer_regs *const regs = plat->regs;
u32 cr;
writel(0, ®s->t3_load);
static u64 altera_timer_get_count(struct udevice *dev)
{
- struct altera_timer_plat *plat = dev->plat;
+ struct altera_timer_plat *plat = dev_get_plat(dev);
struct altera_timer_regs *const regs = plat->regs;
u32 val;
static int altera_timer_probe(struct udevice *dev)
{
- struct altera_timer_plat *plat = dev->plat;
+ struct altera_timer_plat *plat = dev_get_plat(dev);
struct altera_timer_regs *const regs = plat->regs;
writel(0, ®s->status);
#include <dm.h>
#include <timer.h>
#include <asm/io.h>
+#include <dm/device-internal.h>
#include <linux/err.h>
/* mtime register */
static u64 andes_plmt_get_count(struct udevice *dev)
{
- return readq((void __iomem *)MTIME_REG(dev->priv));
+ return readq((void __iomem *)MTIME_REG(dev_get_priv(dev)));
}
static const struct timer_ops andes_plmt_ops = {
static int andes_plmt_probe(struct udevice *dev)
{
- dev->priv = dev_read_addr_ptr(dev);
- if (!dev->priv)
+ dev_set_priv(dev, dev_read_addr_ptr(dev));
+ if (!dev_get_priv(dev))
return -EINVAL;
return timer_timebase_fallback(dev);
static int mpc83xx_timer_probe(struct udevice *dev)
{
- struct timer_dev_priv *uc_priv = dev->uclass_priv;
+ struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
struct clk clock;
int ret;
};
/* This is here in case we don't have a device tree */
-U_BOOT_DEVICE(sandbox_timer_non_fdt) = {
+U_BOOT_DRVINFO(sandbox_timer_non_fdt) = {
.name = "sandbox_timer",
};
#include <dm.h>
#include <timer.h>
#include <asm/io.h>
+#include <dm/device-internal.h>
#include <linux/err.h>
/* mtime register */
static u64 sifive_clint_get_count(struct udevice *dev)
{
- return readq((void __iomem *)MTIME_REG(dev->priv));
+ return readq((void __iomem *)MTIME_REG(dev_get_priv(dev)));
}
static const struct timer_ops sifive_clint_ops = {
static int sifive_clint_probe(struct udevice *dev)
{
- dev->priv = dev_read_addr_ptr(dev);
- if (!dev->priv)
+ dev_set_priv(dev, dev_read_addr_ptr(dev));
+ if (!dev_get_priv(dev))
return -EINVAL;
return timer_timebase_fallback(dev);
unsigned long notrace timer_get_rate(struct udevice *dev)
{
- struct timer_dev_priv *uc_priv = dev->uclass_priv;
+ struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
return uc_priv->clock_rate;
}
ulong ret;
/* It is possible that a timer device has a null ofnode */
- if (!dev_of_valid(dev))
+ if (!dev_has_ofnode(dev))
return 0;
err = clk_get_by_index(dev, 0, &timer_clk);
.get_count = tsc_timer_get_count,
};
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
static const struct udevice_id tsc_timer_ids[] = {
{ .compatible = "x86,tsc-timer", },
{ }
};
+#endif
U_BOOT_DRIVER(x86_tsc_timer) = {
.name = "x86_tsc_timer",
.id = UCLASS_TIMER,
- .of_match = tsc_timer_ids,
+ .of_match = of_match_ptr(tsc_timer_ids),
.probe = tsc_timer_probe,
.ops = &tsc_timer_ops,
};
enum usb_dr_mode dr_mode;
int ret = 0;
- dr_mode = usb_get_dr_mode(dev->node);
+ dr_mode = usb_get_dr_mode(dev_ofnode(dev));
cdns->role = USB_ROLE_NONE;
/*
ofnode node;
int ret;
- node = ofnode_by_compatible(parent->node, "cdns,usb3");
+ node = ofnode_by_compatible(dev_ofnode(parent), "cdns,usb3");
if (!ofnode_valid(node)) {
ret = -ENODEV;
goto fail;
*/
hird_threshold = 12;
- dwc->hsphy_mode = usb_get_phy_mode(dev->node);
+ dwc->hsphy_mode = usb_get_phy_mode(dev_ofnode(dev));
dwc->has_lpm_erratum = dev_read_bool(dev,
"snps,has-lpm-erratum");
static int dwc3_generic_of_to_plat(struct udevice *dev)
{
struct dwc3_generic_plat *plat = dev_get_plat(dev);
- ofnode node = dev->node;
+ ofnode node = dev_ofnode(dev);
plat->base = dev_read_addr(dev);
ofnode node;
int ret;
- ofnode_for_each_subnode(node, parent->node) {
+ ofnode_for_each_subnode(node, dev_ofnode(parent)) {
const char *name = ofnode_get_name(node);
enum usb_dr_mode dr_mode;
struct udevice *dev;
while (child) {
enum usb_dr_mode dr_mode;
- dr_mode = usb_get_dr_mode(child->node);
+ dr_mode = usb_get_dr_mode(dev_ofnode(child));
device_find_next_child(&child);
if (ops && ops->select_dr_mode)
ops->select_dr_mode(dev, index, dr_mode);
}
#endif
- priv->otg_mode = usb_get_dr_mode(dev->node);
+ priv->otg_mode = usb_get_dr_mode(dev_ofnode(dev));
ret = dwc3_meson_g12a_usb_init(priv);
if (ret)
if (ret)
return ret;
- priv->otg_mode = usb_get_dr_mode(dev->node);
+ priv->otg_mode = usb_get_dr_mode(dev_ofnode(dev));
if (priv->otg_mode == USB_DR_MODE_PERIPHERAL)
priv->otg_phy_mode = USB_DR_MODE_PERIPHERAL;
void (*set_params)(struct dwc2_plat_otg_data *data);
int ret;
- if (usb_get_dr_mode(dev->node) != USB_DR_MODE_PERIPHERAL &&
- usb_get_dr_mode(dev->node) != USB_DR_MODE_OTG) {
+ if (usb_get_dr_mode(dev_ofnode(dev)) != USB_DR_MODE_PERIPHERAL &&
+ usb_get_dr_mode(dev_ofnode(dev)) != USB_DR_MODE_OTG) {
dev_dbg(dev, "Invalid mode\n");
return -ENODEV;
}
static int rndis_control_ack(struct udevice *net)
#endif
{
- struct ether_priv *priv = (struct ether_priv *)net->priv;
- struct eth_dev *dev = &priv->ethdev;
- int length;
- struct usb_request *resp = dev->stat_req;
+ struct ether_priv *priv;
+ struct eth_dev *dev;
+ int length;
+ struct usb_request *resp;
+
+#ifndef CONFIG_DM_ETH
+ priv = (struct ether_priv *)net->priv;
+#else
+ priv = dev_get_priv(net);
+#endif
+ dev = &priv->ethdev;
+ resp = dev->stat_req;
/* in case RNDIS calls this after disconnect */
if (!dev->status) {
/* Find snps,dwc3 node from subnode */
dwc3_node = ofnode_null();
- ofnode_for_each_subnode(node, dev->node) {
+ ofnode_for_each_subnode(node, dev_ofnode(dev)) {
if (ofnode_device_is_compatible(node, "snps,dwc3"))
dwc3_node = node;
}
int ret;
u32 reg[4];
- ret = ofnode_read_u32_array(dev->node, "reg", reg, ARRAY_SIZE(reg));
+ ret = ofnode_read_u32_array(dev_ofnode(dev), "reg", reg,
+ ARRAY_SIZE(reg));
if (ret) {
pr_err("unable to find st,stih407-dwc3 reg property(%d)\n", ret);
return ret;
ofnode node, dwc3_node;
/* Find snps,dwc3 node from subnode */
- ofnode_for_each_subnode(node, dev->node) {
+ ofnode_for_each_subnode(node, dev_ofnode(dev)) {
if (ofnode_device_is_compatible(node, "snps,dwc3"))
dwc3_node = node;
}
struct usb_plat *plat = dev_get_plat(dev);
enum usb_dr_mode dr_mode;
- dr_mode = usb_get_dr_mode(dev->node);
+ dr_mode = usb_get_dr_mode(dev_ofnode(dev));
switch (dr_mode) {
case USB_DR_MODE_HOST:
{
struct udevice *bus = udev->controller_dev;
struct dm_usb_ops *ops = usb_get_ops(bus);
- struct usb_uclass_priv *uc_priv = bus->uclass->priv;
+ struct usb_uclass_priv *uc_priv = uclass_get_priv(bus->uclass);
int err;
if (!ops->control)
if (ret)
return ret;
- uc_priv = uc->priv;
+ uc_priv = uclass_get_priv(uc);
uclass_foreach_dev(bus, uc) {
ret = device_remove(bus, DM_REMOVE_NORMAL);
if (ret)
return ret;
- uc_priv = uc->priv;
+ uc_priv = uclass_get_priv(uc);
uclass_foreach_dev(bus, uc) {
/* init low_level USB */
ofnode node;
u32 reg;
- if (!dev_has_of_node(hub))
+ if (!dev_has_ofnode(hub))
return ofnode_null();
/*
struct usb_dev_plat *plat = dev_get_parent_plat(dev);
int val;
- if (!dev_of_valid(dev))
+ if (!dev_has_ofnode(dev))
return 0;
/* We only support matching a few things */
writel(reg, &dwc3_reg->g_usb2phycfg[0]);
- dr_mode = usb_get_dr_mode(dev->node);
+ dr_mode = usb_get_dr_mode(dev_ofnode(dev));
if (dr_mode == USB_DR_MODE_UNKNOWN)
/* by default set dual role mode to HOST */
dr_mode = USB_DR_MODE_HOST;
mtu->ippc_base = ssusb->ippc_base;
mtu->mac_base = ssusb->mac_base;
mtu->ssusb = ssusb;
- mtu->max_speed = usb_get_maximum_speed(dev->node);
+ mtu->max_speed = usb_get_maximum_speed(dev_ofnode(dev));
mtu->force_vbus = dev_read_bool(dev, "mediatek,force-vbus");
ret = mtu3_hw_init(mtu);
return -ENODEV;
}
- ssusb->dr_mode = usb_get_dr_mode(child->node);
+ ssusb->dr_mode = usb_get_dr_mode(dev_ofnode(child));
if (ssusb->dr_mode == USB_DR_MODE_UNKNOWN ||
ssusb->dr_mode == USB_DR_MODE_OTG)
ofnode node;
int ret;
- node = ofnode_by_compatible(parent->node, "mediatek,ssusb");
+ node = ofnode_by_compatible(dev_ofnode(parent), "mediatek,ssusb");
if (!ofnode_valid(node))
return -ENODEV;
ofnode node;
int ret;
- ofnode_for_each_subnode(node, parent->node) {
+ ofnode_for_each_subnode(node, dev_ofnode(parent)) {
struct udevice *dev;
const char *name = ofnode_get_name(node);
enum usb_dr_mode dr_mode;
int ret;
ret = uclass_get_device_by_driver(UCLASS_DISPLAY,
- DM_GET_DRIVER(lg4573_lcd), &dev);
+ DM_DRIVER_GET(lg4573_lcd), &dev);
if (ret) {
printf("%s: Could not get lg4573 device\n", __func__);
return ret;
__func__);
return NULL;
}
- node = dev->node.of_offset;
+ node = dev_ofnode(dev).of_offset;
if (CONFIG_IS_ENABLED(OF_CONTROL)) {
ret = nx_display_parse_dt(dev, dp, plat);
rk_mipi_dsi_write(regs, VID_PKT_SIZE, 0x4b0);
/* Set dpi color coding depth 24 bit */
- timing_node = ofnode_find_subnode(dev->node, "display-timings");
+ timing_node = ofnode_find_subnode(dev_ofnode(dev), "display-timings");
node = ofnode_first_subnode(timing_node);
val = ofnode_read_u32_default(node, "bits-per-pixel", -1);
.flags = DM_FLAG_PRE_RELOC,
};
-U_BOOT_DEVICE(sunxi_de2) = {
+U_BOOT_DRVINFO(sunxi_de2) = {
.name = "sunxi_de2"
};
.priv_auto = sizeof(struct sunxi_dw_hdmi_priv),
};
-U_BOOT_DEVICE(sunxi_dw_hdmi) = {
+U_BOOT_DRVINFO(sunxi_dw_hdmi) = {
.name = "sunxi_dw_hdmi"
};
};
#ifdef CONFIG_MACH_SUN50I
-U_BOOT_DEVICE(sunxi_lcd) = {
+U_BOOT_DRVINFO(sunxi_lcd) = {
.name = "sunxi_lcd"
};
#endif
return 0;
/* Set up the video pointer, if this is the first device */
- uc_priv = dev->uclass->priv;
+ uc_priv = uclass_get_priv(dev->uclass);
if (!uc_priv->video_ptr)
uc_priv->video_ptr = gd->video_top;
former can add 3KB or more to a Thumb 2 Image.
This option enables generation of platform data from the device
- tree as C code. This code creates devices using U_BOOT_DEVICE()
+ tree as C code. This code creates devices using U_BOOT_DRVINFO()
declarations. The benefit is that it allows driver code to access
the platform data directly in C structures, avoidin the libfdt
overhead.
This option works by generating C structure declarations for each
- compatible string, then adding platform data and U_BOOT_DEVICE
+ compatible string, then adding platform data and U_BOOT_DRVINFO
declarations for each node. See of-plat.txt for more information.
config SPL_OF_PLATDATA_PARENT
former can add 3KB or more to a Thumb 2 Image.
This option enables generation of platform data from the device
- tree as C code. This code creates devices using U_BOOT_DEVICE()
+ tree as C code. This code creates devices using U_BOOT_DRVINFO()
declarations. The benefit is that it allows driver code to access
the platform data directly in C structures, avoidin the libfdt
overhead.
This option works by generating C structure declarations for each
- compatible string, then adding platform data and U_BOOT_DEVICE
+ compatible string, then adding platform data and U_BOOT_DRVINFO
declarations for each node. See of-plat.txt for more information.
config TPL_OF_PLATDATA_PARENT
DTB := arch/$(ARCH)/dts/$(DEVICE_TREE).dtb
endif
-$(obj)/dt-spl.dtb: $(DTB) $(objtree)/tools/fdtgrep FORCE
+$(obj)/dt-$(SPL_NAME).dtb: dts/dt.dtb $(objtree)/tools/fdtgrep FORCE
+ mkdir -p $(dir $@)
$(call if_changed,fdtgrep)
ifeq ($(CONFIG_OF_DTB_PROPS_REMOVE),y)
$(call if_changed,shipped)
endif
-targets += dt.dtb dt-spl.dtb
+targets += dt.dtb
$(DTB): arch-dtbs
$(Q)test -e $@ || ( \
obj-$(CONFIG_OF_EMBED) := dt.dtb.o
endif
-dtbs: $(obj)/dt.dtb $(obj)/dt-spl.dtb
+# Target for U-Boot proper
+dtbs: $(obj)/dt.dtb
@:
-clean-files := dt.dtb.S dt-spl.dtb.S
+# Target for SPL/TPL
+spl_dtbs: $(obj)/dt-$(SPL_NAME).dtb
+ @:
+
+clean-files := dt.dtb.S
# Let clean descend into dts directories
subdir- += ../arch/arm/dts ../arch/microblaze/dts ../arch/mips/dts ../arch/sandbox/dts ../arch/x86/dts ../arch/powerpc/dts ../arch/riscv/dts
/**
* @uclass_root: head of core tree
*/
- struct list_head uclass_root;
+ struct list_head uclass_root_s;
+ /**
+ * @uclass_root: pointer to head of core tree, if uclasses are in
+ * read-only memory and cannot be adjusted to use @uclass_root as a
+ * list head.
+ */
+ struct list_head *uclass_root;
# if CONFIG_IS_ENABLED(OF_PLATDATA)
/** @dm_driver_rt: Dynamic info about the driver */
struct driver_rt *dm_driver_rt;
}
#endif
+/**
+ * dev_set_priv() - Set the private data for a device
+ *
+ * This is normally handled by driver model, which automatically allocates
+ * private data when an 'auto' size if provided by the driver.
+ *
+ * Use this function to override normal operation for special situations, such
+ * as needing to allocate a variable amount of data.
+ *
+ * @dev Device to check
+ * @priv New private-data pointer
+ */
+void dev_set_priv(struct udevice *dev, void *priv);
+
+/**
+ * dev_set_parent_priv() - Set the parent-private data for a device
+ *
+ * This is normally handled by driver model, which automatically allocates
+ * parent-private data when an 'auto' size if provided by the driver.
+ *
+ * Use this function to override normal operation for special situations, such
+ * as needing to allocate a variable amount of data.
+ *
+ * @dev: Device to update
+ * @parent_priv: New parent-private data
+ */
+void dev_set_parent_priv(struct udevice *dev, void *parent_priv);
+
+/**
+ * dev_set_uclass_priv() - Set the uclass private data for a device
+ *
+ * This is normally handled by driver model, which automatically allocates
+ * uclass-private data when an 'auto' size if provided by the driver.
+ *
+ * Use this function to override normal operation for special situations, such
+ * as needing to allocate a variable amount of data.
+ *
+ * @dev: Device to update
+ * @uclass_priv: New uclass private data
+ */
+void dev_set_uclass_priv(struct udevice *dev, void *uclass_priv);
+
+/**
+ * dev_set_plat() - Set the platform data for a device
+ *
+ * This is normally handled by driver model, which automatically allocates
+ * platform data when an 'auto' size if provided by the driver.
+ *
+ * Use this function to override normal operation for special situations, such
+ * as needing to allocate a variable amount of data.
+ *
+ * @dev Device to check
+ * @plat New platform-data pointer
+ */
+void dev_set_plat(struct udevice *dev, void *priv);
+
+/**
+ * dev_set_parent_plat() - Set the parent platform data for a device
+ *
+ * This is normally handled by driver model, which automatically allocates
+ * parent platform data when an 'auto' size if provided by the driver.
+ *
+ * Use this function to override normal operation for special situations, such
+ * as needing to allocate a variable amount of data.
+ *
+ * @dev: Device to update
+ * @parent_plat: New parent platform data
+ */
+void dev_set_parent_plat(struct udevice *dev, void *parent_plat);
+
+/**
+ * dev_set_uclass_plat() - Set the uclass platform data for a device
+ *
+ * This is normally handled by driver model, which automatically allocates
+ * uclass platform data when an 'auto' size if provided by the driver.
+ *
+ * Use this function to override normal operation for special situations, such
+ * as needing to allocate a variable amount of data.
+ *
+ * @dev: Device to update
+ * @uclass_plat: New uclass platform data
+ */
+void dev_set_uclass_plat(struct udevice *dev, void *uclass_plat);
+
/**
* simple_bus_translate() - translate a bus address to a system address
*
/* Cast away any volatile pointer */
#define DM_ROOT_NON_CONST (((gd_t *)gd)->dm_root)
#define DM_UCLASS_ROOT_NON_CONST (((gd_t *)gd)->uclass_root)
+#define DM_UCLASS_ROOT_S_NON_CONST (((gd_t *)gd)->uclass_root_s)
/* device resource management */
#ifdef CONFIG_DEVRES
* particular port or peripheral (essentially a driver instance).
*
* A device will come into existence through a 'bind' call, either due to
- * a U_BOOT_DEVICE() macro (in which case plat is non-NULL) or a node
+ * a U_BOOT_DRVINFO() macro (in which case plat is non-NULL) or a node
* in the device tree (in which case of_offset is >= 0). In the latter case
* we translate the device tree information into plat in a function
* implemented by the driver of_to_plat method (called just before the
*
* @driver: The driver used by this device
* @name: Name of device, typically the FDT node name
- * @plat: Configuration data for this device
- * @parent_plat: The parent bus's configuration data for this device
- * @uclass_plat: The uclass's configuration data for this device
- * @node: Reference to device tree node for this device
+ * @plat_: Configuration data for this device (do not access outside driver
+ * model)
+ * @parent_plat_: The parent bus's configuration data for this device (do not
+ * access outside driver model)
+ * @uclass_plat_: The uclass's configuration data for this device (do not access
+ * outside driver model)
* @driver_data: Driver data word for the entry that matched this device with
* its driver
* @parent: Parent of this device, or NULL for the top level device
- * @priv: Private data for this device
+ * @priv_: Private data for this device (do not access outside driver model)
* @uclass: Pointer to uclass for this device
- * @uclass_priv: The uclass's private data for this device
- * @parent_priv: The parent's private data for this device
+ * @uclass_priv_: The uclass's private data for this device (do not access
+ * outside driver model)
+ * @parent_priv_: The parent's private data for this device (do not access
+ * outside driver model)
* @uclass_node: Used by uclass to link its devices
* @child_head: List of children of this device
* @sibling_node: Next device in list of all devices
- * @flags: Flags for this device DM_FLAG_...
- * @seq: Allocated sequence number for this device (-1 = none). This is set up
+ * @flags_: Flags for this device DM_FLAG_... (do not access outside driver
+ * model)
+ * @seq_: Allocated sequence number for this device (-1 = none). This is set up
* when the device is bound and is unique within the device's uclass. If the
* device has an alias in the devicetree then that is used to set the sequence
* number. Otherwise, the next available number is used. Sequence numbers are
- * used by certain commands that need device to be numbered (e.g. 'mmc dev')
+ * used by certain commands that need device to be numbered (e.g. 'mmc dev').
+ * (do not access outside driver model)
+ * @node_: Reference to device tree node for this device (do not access outside
+ * driver model)
* @devres_head: List of memory allocations associated with this device.
* When CONFIG_DEVRES is enabled, devm_kmalloc() and friends will
* add to this list. Memory so-allocated will be freed
struct udevice {
const struct driver *driver;
const char *name;
- void *plat;
- void *parent_plat;
- void *uclass_plat;
- ofnode node;
+ void *plat_;
+ void *parent_plat_;
+ void *uclass_plat_;
ulong driver_data;
struct udevice *parent;
- void *priv;
+ void *priv_;
struct uclass *uclass;
- void *uclass_priv;
- void *parent_priv;
+ void *uclass_priv_;
+ void *parent_priv_;
struct list_head uclass_node;
struct list_head child_head;
struct list_head sibling_node;
- uint32_t flags;
- int sqq;
+ u32 flags_;
+ int seq_;
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
+ ofnode node_;
+#endif
#ifdef CONFIG_DEVRES
struct list_head devres_head;
#endif
/* Returns the operations for a device */
#define device_get_ops(dev) (dev->driver->ops)
+static inline u32 dev_get_flags(const struct udevice *dev)
+{
+ return dev->flags_;
+}
+
+static inline void dev_or_flags(struct udevice *dev, u32 or)
+{
+ dev->flags_ |= or;
+}
+
+static inline void dev_bic_flags(struct udevice *dev, u32 bic)
+{
+ dev->flags_ &= ~bic;
+}
+
+/**
+ * dev_ofnode() - get the DT node reference associated with a udevice
+ *
+ * @dev: device to check
+ * @return reference of the the device's DT node
+ */
+static inline ofnode dev_ofnode(const struct udevice *dev)
+{
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
+ return dev->node_;
+#else
+ return ofnode_null();
+#endif
+}
+
/* Returns non-zero if the device is active (probed and not removed) */
-#define device_active(dev) ((dev)->flags & DM_FLAG_ACTIVATED)
+#define device_active(dev) (dev_get_flags(dev) & DM_FLAG_ACTIVATED)
static inline int dev_of_offset(const struct udevice *dev)
{
- return ofnode_to_offset(dev->node);
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
+ return ofnode_to_offset(dev_ofnode(dev));
+#else
+ return -1;
+#endif
}
-static inline bool dev_has_of_node(struct udevice *dev)
+static inline bool dev_has_ofnode(const struct udevice *dev)
{
- return ofnode_valid(dev->node);
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
+ return ofnode_valid(dev_ofnode(dev));
+#else
+ return false;
+#endif
+}
+
+static inline void dev_set_ofnode(struct udevice *dev, ofnode node)
+{
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
+ dev->node_ = node;
+#endif
}
static inline int dev_seq(const struct udevice *dev)
{
- return dev->sqq;
+ return dev->seq_;
}
/**
* platform data to be allocated in the device's ->plat pointer.
* This is typically only useful for device-tree-aware drivers (those with
* an of_match), since drivers which use plat will have the data
- * provided in the U_BOOT_DEVICE() instantiation.
+ * provided in the U_BOOT_DRVINFO() instantiation.
* @per_child_auto: Each device can hold private data owned by
* its parent. If required this will be automatically allocated if this
* value is non-zero.
ll_entry_declare(struct driver, __name, driver)
/* Get a pointer to a given driver */
-#define DM_GET_DRIVER(__name) \
+#define DM_DRIVER_GET(__name) \
ll_entry_get(struct driver, __name, driver)
/**
* produce no code but its information will be parsed by tools like
* dtoc
*/
-#define U_BOOT_DRIVER_ALIAS(__name, __alias)
+#define DM_DRIVER_ALIAS(__name, __alias)
/**
* dev_get_plat() - Get the platform data for a device
/**
* lists_bind_drivers() - search for and bind all drivers to parent
*
- * This searches the U_BOOT_DEVICE() structures and creates new devices for
+ * This searches the U_BOOT_DRVINFO() structures and creates new devices for
* each one. The devices will have @parent as their parent.
*
* @parent: parent device (root)
* is not feasible (e.g. serial driver in SPL where <8KB of SRAM is
* available). U-Boot's driver model uses device tree for configuration.
*
- * When of-platdata is in use, U_BOOT_DEVICE() cannot be used outside of the
+ * When of-platdata is in use, U_BOOT_DRVINFO() cannot be used outside of the
* dt-plat.c file created by dtoc
*/
-#if CONFIG_IS_ENABLED(OF_PLATDATA) && !defined(DT_PLATDATA_C)
-#define U_BOOT_DEVICE(__name) _Static_assert(false, \
- "Cannot use U_BOOT_DEVICE with of-platdata. Please use devicetree instead")
+#if CONFIG_IS_ENABLED(OF_PLATDATA) && !defined(DT_PLAT_C)
+#define U_BOOT_DRVINFO(__name) _Static_assert(false, \
+ "Cannot use U_BOOT_DRVINFO with of-platdata. Please use devicetree instead")
#else
-#define U_BOOT_DEVICE(__name) \
+#define U_BOOT_DRVINFO(__name) \
ll_entry_declare(struct driver_info, __name, driver_info)
#endif
/* Declare a list of devices. The argument is a driver_info[] array */
-#define U_BOOT_DEVICES(__name) \
+#define U_BOOT_DRVINFOS(__name) \
ll_entry_declare_list(struct driver_info, __name, driver_info)
/**
* Get a pointer to a given device info given its name
*
- * With the declaration U_BOOT_DEVICE(name), DM_GET_DEVICE(name) will return a
+ * With the declaration U_BOOT_DRVINFO(name), DM_DRVINFO_GET(name) will return a
* pointer to the struct driver_info created by that declaration.
*
* if OF_PLATDATA is enabled, from this it is possible to use the @dev member of
* struct driver_info to find the device pointer itself.
*
- * the naming seems sensible, but DM_GET_DEVICE() is a bit of misnomer, since it
- * finds the driver_info record, not the device.
- *
* @__name: Driver name (C identifier, not a string. E.g. gpio7_at_ff7e0000)
* @return struct driver_info * to the driver that created the device
*/
-#define DM_GET_DEVICE(__name) \
+#define DM_DRVINFO_GET(__name) \
ll_entry_get(struct driver_info, __name, driver_info)
-/**
- * dm_populate_phandle_data() - Populates phandle data in platda
- *
- * This populates phandle data with an U_BOOT_DEVICE entry get by
- * DM_GET_DEVICE. The implementation of this function will be done
- * by dtoc when parsing dtb.
- */
-void dm_populate_phandle_data(void);
#endif
* (C) Copyright 2018
*
- * Structure for use with U_BOOT_DEVICE for pl022 SPI devices or to use
+ * Structure for use with U_BOOT_DRVINFO for pl022 SPI devices or to use
* in of_to_plat.
*/
#if CONFIG_IS_ENABLED(OF_LIVE)
static inline const struct device_node *dev_np(const struct udevice *dev)
{
- return ofnode_to_np(dev->node);
+ return ofnode_to_np(dev_ofnode(dev));
}
#else
static inline const struct device_node *dev_np(const struct udevice *dev)
}
#endif
-/**
- * dev_ofnode() - get the DT node reference associated with a udevice
- *
- * @dev: device to check
- * @return reference of the the device's DT node
- */
-static inline ofnode dev_ofnode(const struct udevice *dev)
-{
- return dev->node;
-}
-
-static inline bool dev_of_valid(const struct udevice *dev)
-{
- return ofnode_valid(dev_ofnode(dev));
-}
-
#ifndef CONFIG_DM_DEV_READ_INLINE
/**
--- /dev/null
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2020 Google LLC
+ */
+
+#ifndef __DM_SIMPLE_BUS_H
+#define __DM_SIMPLE_BUS_H
+
+struct simple_bus_plat {
+ u32 base;
+ u32 size;
+ u32 target;
+};
+
+#endif
* @testdev: Test device
* @force_fail_alloc: Force all memory allocs to fail
* @skip_post_probe: Skip uclass post-probe processing
- * @removed: Used to keep track of a device that was removed
*/
struct dm_test_state {
struct udevice *root;
struct udevice *testdev;
int force_fail_alloc;
int skip_post_probe;
- struct udevice *removed;
};
/* Declare a new driver model test */
int font_size;
};
+/**
+ * struct dm_test_parent_plat - Used to track state in bus tests
+ *
+ * @count:
+ * @bind_flag: Indicates that the child post-bind method was called
+ * @uclass_bind_flag: Also indicates that the child post-bind method was called
+ */
+struct dm_test_parent_plat {
+ int count;
+ int bind_flag;
+ int uclass_bind_flag;
+};
+
+enum {
+ TEST_FLAG_CHILD_PROBED = 10,
+ TEST_FLAG_CHILD_REMOVED = -7,
+};
+
/* Declare ping methods for the drivers */
int test_ping(struct udevice *dev, int pingval, int *pingret);
int testfdt_ping(struct udevice *dev, int pingval, int *pingret);
#include <dm/ofnode.h>
+/**
+ * uclass_set_priv() - Set the private data for a uclass
+ *
+ * This is normally handled by driver model, which automatically allocates
+ * private data when an 'auto' size if provided by the uclass driver.
+ *
+ * Use this function to override normal operation for special situations, such
+ * as needing to allocate a variable amount of data.
+ *
+ * @uc Uclass to update
+ * @priv New private-data pointer
+ */
+void uclass_set_priv(struct uclass *uc, void *priv);
+
/**
* uclass_find_next_free_seq() - Get the next free sequence number
*
* There may be drivers for on-chip SoC GPIO banks, I2C GPIO expanders and
* PMIC IO lines, all made available in a unified way through the uclass.
*
- * @priv: Private data for this uclass
+ * @priv_: Private data for this uclass (do not access outside driver model)
* @uc_drv: The driver for the uclass itself, not to be confused with a
* 'struct driver'
* @dev_head: List of devices in this uclass (devices are attached to their
* @sibling_node: Next uclass in the linked list of uclasses
*/
struct uclass {
- void *priv;
+ void *priv_;
struct uclass_driver *uc_drv;
struct list_head dev_head;
struct list_head sibling_node;
/* Declare a new uclass_driver */
#define UCLASS_DRIVER(__name) \
- ll_entry_declare(struct uclass_driver, __name, uclass)
+ ll_entry_declare(struct uclass_driver, __name, uclass_driver)
+
+/**
+ * uclass_get_priv() - Get the private data for a uclass
+ *
+ * @uc Uclass to check
+ * @return private data, or NULL if none
+ */
+void *uclass_get_priv(const struct uclass *uc);
/**
* uclass_get() - Get a uclass based on an ID, creating it if needed
* uclass_get_device_by_driver() - Get a uclass device for a driver
*
* This searches the devices in the uclass for one that uses the given
- * driver. Use DM_GET_DRIVER(name) for the @drv argument, where 'name' is
+ * driver. Use DM_DRIVER_GET(name) for the @drv argument, where 'name' is
* the driver name - as used in U_BOOT_DRIVER(name).
*
* The device is probed to activate it ready for use.
};
#if IS_ENABLED(CONFIG_DM)
-static inline void mtd_set_of_node(struct mtd_info *mtd,
- const struct device_node *np)
+static inline void mtd_set_ofnode(struct mtd_info *mtd, ofnode node)
{
- mtd->dev->node.np = np;
+ dev_set_ofnode(mtd->dev, node);
}
-static inline const struct device_node *mtd_get_of_node(struct mtd_info *mtd)
+static inline const ofnode mtd_get_ofnode(struct mtd_info *mtd)
{
- return mtd->dev->node.np;
+ return dev_ofnode(mtd->dev);
}
#else
struct device_node;
return mtd_device_unregister(nand->mtd);
}
+#ifndef __UBOOT__
/**
* nanddev_set_of_node() - Attach a DT node to a NAND device
* @nand: NAND device
{
return mtd_get_of_node(nand->mtd);
}
+#else
+/**
+ * nanddev_set_of_node() - Attach a DT node to a NAND device
+ * @nand: NAND device
+ * @node: ofnode
+ *
+ * Attach a DT node to a NAND device.
+ */
+static inline void nanddev_set_ofnode(struct nand_device *nand, ofnode node)
+{
+ mtd_set_ofnode(nand->mtd, node);
+}
+#endif /* __UBOOT__ */
/**
* nanddev_offs_to_pos() - Convert an absolute NAND offset into a NAND position
/*
* TODO: Remove, once all users of spi_flash interface are moved to MTD
*
- * struct spi_flash {
+struct spi_flash {
* Defined below (keep this text to enable searching for spi_flash decl)
* }
*/
+#ifndef DT_PLAT_C
#define spi_flash spi_nor
+#endif
/**
* struct spi_nor - Structure for defining a the SPI NOR layer
u32 erase_size;
};
+#ifndef __UBOOT__
static inline void spi_nor_set_flash_node(struct spi_nor *nor,
const struct device_node *np)
{
{
return mtd_get_of_node(&nor->mtd);
}
+#endif /* __UBOOT__ */
/**
* struct spi_nor_hwcaps - Structure for describing the hardware capabilies
return &spinand->base;
}
+#ifndef __UBOOT__
/**
* spinand_set_of_node - Attach a DT node to a SPI NAND device
* @spinand: SPI NAND device
{
nanddev_set_of_node(&spinand->base, np);
}
+#else
+/**
+ * spinand_set_of_node - Attach a DT node to a SPI NAND device
+ * @spinand: SPI NAND device
+ * @node: ofnode
+ *
+ * Attach a DT node to a SPI NAND device.
+ */
+static inline void spinand_set_ofnode(struct spinand_device *spinand,
+ ofnode node)
+{
+ nanddev_set_ofnode(&spinand->base, node);
+}
+#endif /* __UBOOT__ */
int spinand_match_and_init(struct spinand_device *dev,
const struct spinand_info *table,
* will not allocate storage for arrays of size 0
*/
+#ifndef __ns16550_h
+#define __ns16550_h
+
#include <linux/types.h>
#ifdef CONFIG_DM_SERIAL
struct udevice;
-struct NS16550 {
+struct ns16550 {
UART_REG(rbr); /* 0 */
UART_REG(ier); /* 1 */
UART_REG(fcr); /* 2 */
#define dll rbr
#define dlm ier
-typedef struct NS16550 *NS16550_t;
-
/*
* These are the definitions for the FIFO Control Register
*/
/* useful defaults for LCR */
#define UART_LCR_8N1 0x03
-void NS16550_init(NS16550_t com_port, int baud_divisor);
-void NS16550_putc(NS16550_t com_port, char c);
-char NS16550_getc(NS16550_t com_port);
-int NS16550_tstc(NS16550_t com_port);
-void NS16550_reinit(NS16550_t com_port, int baud_divisor);
+void ns16550_init(struct ns16550 *com_port, int baud_divisor);
+void ns16550_putc(struct ns16550 *com_port, char c);
+char ns16550_getc(struct ns16550 *com_port);
+int ns16550_tstc(struct ns16550 *com_port);
+void ns16550_reinit(struct ns16550 *com_port, int baud_divisor);
/**
* ns16550_calc_divisor() - calculate the divisor given clock and baud rate
* @baudrate: Required baud rate
* @return baud rate divisor that should be used
*/
-int ns16550_calc_divisor(NS16550_t port, int clock, int baudrate);
+int ns16550_calc_divisor(struct ns16550 *port, int clock, int baudrate);
/**
* ns16550_serial_of_to_plat() - convert DT to platform data
* These should be used by the client driver for the driver's 'ops' member
*/
extern const struct dm_serial_ops ns16550_serial_ops;
+
+#endif /* __ns16550_h */
* If not overridden, it is weakly defined in common/spl/spl_mmc.c.
*/
int spl_mmc_boot_partition(const u32 boot_device);
-void spl_set_bd(void);
+
+/**
+ * spl_alloc_bd() - Allocate space for bd_info
+ *
+ * This sets up the gd->bd pointer by allocating memory for it
+ *
+ * @return 0 if OK, -ENOMEM if out of memory
+ */
+int spl_alloc_bd(void);
/**
* spl_set_header_raw_uboot() - Set up a standard SPL image structure
TEST_DEVRES_SIZE3 = 37,
};
+/**
+ * testbus_get_clear_removed() - Test function to obtain removed device
+ *
+ * This is used in testbus to find out which device was removed. Calling this
+ * function returns a pointer to the device and then clears it back to NULL, so
+ * that a future test can check it.
+ */
+struct udevice *testbus_get_clear_removed(void);
+
/**
* dm_test_main() - Run driver model tests
*
*/
static inline bool virtio_has_feature(struct udevice *vdev, unsigned int fbit)
{
- if (!(vdev->flags & DM_FLAG_BOUND))
+ if (!(dev_get_flags(vdev) & DM_FLAG_BOUND))
WARN_ON(true);
return __virtio_test_bit(vdev->parent, fbit);
putc('\r');
if (use_uart) {
- NS16550_t com_port = (NS16550_t)0x3f8;
+ struct ns16550 *com_port = (struct ns16550 *)0x3f8;
while ((inb((ulong)&com_port->lsr) & UART_LSR_THRE) == 0)
;
case UCLASS_ETH: {
struct efi_device_path_mac_addr *dp =
dp_fill(buf, dev->parent);
- struct eth_pdata *pdata = dev->plat;
+ struct eth_pdata *pdata = dev_get_plat(dev);
dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR;
#include <dm.h>
#include <errno.h>
#include <init.h>
+#include <spl.h>
#include <time.h>
#include <timer.h>
#include <watchdog.h>
}
ret = timer_get_count(gd->timer, &count);
- if (ret)
- panic("Could not read count from timer (err %d)\n", ret);
+ if (ret) {
+ if (spl_phase() > PHASE_TPL)
+ panic("Could not read count from timer (err %d)\n",
+ ret);
+ else
+ panic("no timer (err %d)\n", ret);
+ }
return count;
}
return NULL;
assert(uc);
- return uc->priv;
+ return uclass_get_priv(uc);
}
void eth_set_current_to_next(void)
struct eth_pdata *pdata;
if (eth_get_dev()) {
- pdata = eth_get_dev()->plat;
+ pdata = dev_get_plat(eth_get_dev());
return pdata->enetaddr;
}
if (!current || !device_active(current))
return -EINVAL;
- priv = current->uclass_priv;
+ priv = dev_get_uclass_priv(current);
priv->state = ETH_STATE_ACTIVE;
return 0;
if (!current || !device_active(current))
return;
- priv = current->uclass_priv;
+ priv = dev_get_uclass_priv(current);
priv->state = ETH_STATE_PASSIVE;
}
/* seq is valid since the device is active */
if (eth_get_ops(dev)->write_hwaddr && !eth_mac_skip(dev_seq(dev))) {
- pdata = dev->plat;
+ pdata = dev_get_plat(dev);
if (!is_valid_ethaddr(pdata->enetaddr)) {
printf("\nError: %s address %pM illegal value\n",
dev->name, pdata->enetaddr);
retval = uclass_find_device_by_seq(UCLASS_ETH, index, &dev);
if (!retval) {
- struct eth_pdata *pdata = dev->plat;
+ struct eth_pdata *pdata = dev_get_plat(dev);
switch (op) {
case env_op_create:
case env_op_overwrite:
ret = eth_get_ops(current)->start(current);
if (ret >= 0) {
struct eth_device_priv *priv =
- current->uclass_priv;
+ dev_get_uclass_priv(current);
priv->state = ETH_STATE_ACTIVE;
return 0;
return;
eth_get_ops(current)->stop(current);
- priv = current->uclass_priv;
+ priv = dev_get_uclass_priv(current);
if (priv)
priv->state = ETH_STATE_PASSIVE;
}
static int eth_post_probe(struct udevice *dev)
{
- struct eth_device_priv *priv = dev->uclass_priv;
- struct eth_pdata *pdata = dev->plat;
+ struct eth_device_priv *priv = dev_get_uclass_priv(dev);
+ struct eth_pdata *pdata = dev_get_plat(dev);
unsigned char env_enetaddr[ARP_HLEN];
char *source = "DT";
static int eth_pre_remove(struct udevice *dev)
{
- struct eth_pdata *pdata = dev->plat;
+ struct eth_pdata *pdata = dev_get_plat(dev);
eth_get_ops(dev)->stop(dev);
ofnode ch_node;
int err, first_err = 0;
- if (!ofnode_valid(mux->node)) {
+ if (!dev_has_ofnode(mux)) {
debug("%s: no mux node found, no child MDIO busses set up\n",
__func__);
return 0;
const char *dt_name;
/* set a custom name for the MDIO device, if present in DT */
- if (ofnode_valid(dev->node)) {
- dt_name = ofnode_read_string(dev->node, "device-name");
+ if (dev_has_ofnode(dev)) {
+ dt_name = dev_read_string(dev, "device-name");
if (dt_name) {
debug("renaming dev %s to %s\n", dev->name, dt_name);
device_set_name(dev, dt_name);
struct phy_device *phy;
int i;
- if (!ofnode_valid(ethdev->node)) {
+ if (!dev_has_ofnode(ethdev)) {
debug("%s: supplied eth dev has no DT node!\n", ethdev->name);
return NULL;
}
interface = PHY_INTERFACE_MODE_NONE;
for (i = 0; i < PHY_MODE_STR_CNT; i++) {
- if_str = ofnode_read_string(ethdev->node, phy_mode_str[i]);
+ if_str = dev_read_string(ethdev, phy_mode_str[i]);
if (if_str) {
interface = phy_get_interface_by_name(if_str);
break;
ifeq ($(CONFIG_TPL_BUILD),y)
SPL_BIN := u-boot-tpl
+SPL_NAME := tpl
else
SPL_BIN := u-boot-spl
+SPL_NAME := spl
endif
+export SPL_NAME
+
ifdef CONFIG_SPL_BUILD
SPL_ := SPL_
ifeq ($(CONFIG_TPL_BUILD),y)
u-boot-spl-init := $(head-y)
u-boot-spl-main := $(libs-y)
ifdef CONFIG_$(SPL_TPL_)OF_PLATDATA
-u-boot-spl-platdata := $(obj)/dts/dt-platdata.o
+u-boot-spl-platdata := $(obj)/dts/dt-plat.o
+u-boot-spl-platdata_c := $(patsubst %.o,%.c,$(u-boot-spl-platdata))
endif
# Linker Script
@bss_size_str=$(shell $(NM) $< | awk 'BEGIN {size = 0} /__bss_size/ {size = $$1} END {print "ibase=16; " toupper(size)}' | bc); \
dd if=/dev/zero of=$@ bs=1 count=$${bss_size_str} 2>/dev/null;
-$(obj)/$(SPL_BIN).dtb: dts/dt-spl.dtb FORCE
+$(obj)/$(SPL_BIN).dtb: $(obj)/dts/dt-$(SPL_NAME).dtb FORCE
$(call if_changed,copy)
pythonpath = PYTHONPATH=scripts/dtc/pylibfdt
-quiet_cmd_dtocc = DTOC C $@
-cmd_dtocc = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ platdata
+DTOC_ARGS := $(pythonpath) $(srctree)/tools/dtoc/dtoc \
+ -d $(obj)/$(SPL_BIN).dtb
-quiet_cmd_dtoch = DTOC H $@
-cmd_dtoch = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ struct
+quiet_cmd_dtoc = DTOC $@
+cmd_dtoc = $(DTOC_ARGS) -c $(obj)/dts -C include/generated all
quiet_cmd_plat = PLAT $@
cmd_plat = $(CC) $(c_flags) -c $< -o $(filter-out $(PHONY),$@)
-targets += $(obj)/dts/dt-platdata.o
-$(obj)/dts/dt-platdata.o: $(obj)/dts/dt-platdata.c \
+targets += $(u-boot-spl-platdata)
+
+$(obj)/dts/dt-%.o: $(obj)/dts/dt-%.c \
include/generated/dt-structs-gen.h prepare FORCE
$(call if_changed,plat)
dts_dir:
$(shell [ -d $(obj)/dts ] || mkdir -p $(obj)/dts)
-include/generated/dt-structs-gen.h: $(obj)/$(SPL_BIN).dtb dts_dir FORCE
- $(call if_changed,dtoch)
-
-$(obj)/dts/dt-platdata.c: $(obj)/$(SPL_BIN).dtb dts_dir FORCE
- $(call if_changed,dtocc)
+include/generated/dt-structs-gen.h $(u-boot-spl-platdata_c) &: \
+ $(obj)/$(SPL_BIN).dtb dts_dir FORCE
+ $(call if_changed,dtoc)
ifdef CONFIG_SAMSUNG
ifdef CONFIG_VAR_SIZE_SPL
PHONY += FORCE
FORCE:
-PHONY += dtbs
-dtbs:
- $(Q)$(MAKE) $(build)=dts dtbs
+$(obj)/dts/dt-$(SPL_NAME).dtb: dts/dt.dtb
+ $(Q)$(MAKE) $(build)=$(obj)/dts spl_dtbs
# Declare the contents of the .PHONY variable as phony. We keep that
# information in a variable so we can use it in if_changed and friends.
DECLARE_GLOBAL_DATA_PTR;
-struct dm_test_parent_plat {
- int count;
- int bind_flag;
- int uclass_bind_flag;
-};
-
-enum {
- FLAG_CHILD_PROBED = 10,
- FLAG_CHILD_REMOVED = -7,
-};
-
-static struct dm_test_state *test_state;
-
-static int testbus_drv_probe(struct udevice *dev)
-{
- return dm_scan_fdt_dev(dev);
-}
-
-static int testbus_child_post_bind(struct udevice *dev)
-{
- struct dm_test_parent_plat *plat;
-
- plat = dev_get_parent_plat(dev);
- plat->bind_flag = 1;
- plat->uclass_bind_flag = 2;
-
- return 0;
-}
-
-static int testbus_child_pre_probe(struct udevice *dev)
-{
- struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev);
-
- parent_data->flag += FLAG_CHILD_PROBED;
-
- return 0;
-}
-
-static int testbus_child_pre_probe_uclass(struct udevice *dev)
-{
- struct dm_test_priv *priv = dev_get_priv(dev);
-
- priv->uclass_flag++;
-
- return 0;
-}
-
-static int testbus_child_post_probe_uclass(struct udevice *dev)
-{
- struct dm_test_priv *priv = dev_get_priv(dev);
-
- priv->uclass_postp++;
-
- return 0;
-}
-
-static int testbus_child_post_remove(struct udevice *dev)
-{
- struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev);
- struct dm_test_state *dms = test_state;
-
- parent_data->flag += FLAG_CHILD_REMOVED;
- if (dms)
- dms->removed = dev;
-
- return 0;
-}
-
-static const struct udevice_id testbus_ids[] = {
- {
- .compatible = "denx,u-boot-test-bus",
- .data = DM_TEST_TYPE_FIRST },
- { }
-};
-
-U_BOOT_DRIVER(testbus_drv) = {
- .name = "testbus_drv",
- .of_match = testbus_ids,
- .id = UCLASS_TEST_BUS,
- .probe = testbus_drv_probe,
- .child_post_bind = testbus_child_post_bind,
- .priv_auto = sizeof(struct dm_test_priv),
- .plat_auto = sizeof(struct dm_test_pdata),
- .per_child_auto = sizeof(struct dm_test_parent_data),
- .per_child_plat_auto = sizeof(struct dm_test_parent_plat),
- .child_pre_probe = testbus_child_pre_probe,
- .child_post_remove = testbus_child_post_remove,
-};
-
-UCLASS_DRIVER(testbus) = {
- .name = "testbus",
- .id = UCLASS_TEST_BUS,
- .flags = DM_UC_FLAG_SEQ_ALIAS,
- .child_pre_probe = testbus_child_pre_probe_uclass,
- .child_post_probe = testbus_child_post_probe_uclass,
-};
-
/* Test that we can probe for children */
static int dm_test_bus_children(struct unit_test_state *uts)
{
ut_assertok(device_get_child(bus, 0, &dev));
ut_asserteq(-ENODEV, device_get_child(bus, 4, &dev));
ut_assertok(device_get_child_by_seq(bus, 5, &dev));
- ut_assert(dev->flags & DM_FLAG_ACTIVATED);
+ ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
ut_asserteq_str("c-test@5", dev->name);
/* Device with sequence number 0 should be accessible */
ut_asserteq(-ENODEV, device_find_child_by_seq(bus, -1, &dev));
ut_assertok(device_find_child_by_seq(bus, 0, &dev));
- ut_assert(!(dev->flags & DM_FLAG_ACTIVATED));
+ ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
ut_asserteq(0, device_find_child_by_seq(bus, 0, &dev));
ut_assertok(device_get_child_by_seq(bus, 0, &dev));
- ut_assert(dev->flags & DM_FLAG_ACTIVATED);
+ ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
ut_asserteq(0, device_find_child_by_seq(bus, 0, &dev));
/* There is no device with sequence number 2 */
ut_assert(node > 0);
ut_assertok(device_find_child_by_of_offset(bus, node, &dev));
ut_assertnonnull(dev);
- ut_assert(!(dev->flags & DM_FLAG_ACTIVATED));
+ ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
ut_assertok(device_get_child_by_of_offset(bus, node, &dev));
ut_assertnonnull(dev);
- ut_assert(dev->flags & DM_FLAG_ACTIVATED);
+ ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
return 0;
}
static int dm_test_bus_parent_ops(struct unit_test_state *uts)
{
struct dm_test_parent_data *parent_data;
- struct dm_test_state *dms = uts->priv;
struct udevice *bus, *dev;
struct uclass *uc;
- test_state = dms;
+ testbus_get_clear_removed();
ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
ut_assertok(uclass_get(UCLASS_TEST_FDT, &uc));
ut_assertok(device_probe(dev));
parent_data = dev_get_parent_priv(dev);
- ut_asserteq(FLAG_CHILD_PROBED, parent_data->flag);
+ ut_asserteq(TEST_FLAG_CHILD_PROBED, parent_data->flag);
}
uclass_foreach_dev(dev, uc) {
if (dev->parent != bus)
continue;
parent_data = dev_get_parent_priv(dev);
- ut_asserteq(FLAG_CHILD_PROBED, parent_data->flag);
+ ut_asserteq(TEST_FLAG_CHILD_PROBED, parent_data->flag);
ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
ut_asserteq_ptr(NULL, dev_get_parent_priv(dev));
- ut_asserteq_ptr(dms->removed, dev);
+ ut_asserteq_ptr(testbus_get_clear_removed(), dev);
}
- test_state = NULL;
return 0;
}
.ping_add = TEST_INTVAL_PRE_RELOC,
};
-U_BOOT_DEVICE(dm_test_info1) = {
+U_BOOT_DRVINFO(dm_test_info1) = {
.name = "test_drv",
.plat = &test_pdata[0],
};
-U_BOOT_DEVICE(dm_test_info2) = {
+U_BOOT_DRVINFO(dm_test_info2) = {
.name = "test_drv",
.plat = &test_pdata[1],
};
-U_BOOT_DEVICE(dm_test_info3) = {
+U_BOOT_DRVINFO(dm_test_info3) = {
.name = "test_drv",
.plat = &test_pdata[2],
};
* device with no children.
*/
ut_assert(dms->root);
- ut_asserteq(1, list_count_items(&gd->uclass_root));
+ ut_asserteq(1, list_count_items(gd->uclass_root));
ut_asserteq(0, list_count_items(&gd->dm_root->child_head));
ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_BIND]);
ut_assertok(dm_scan_plat(false));
/* We should have our test class now at least, plus more children */
- ut_assert(1 < list_count_items(&gd->uclass_root));
+ ut_assert(1 < list_count_items(gd->uclass_root));
ut_assert(0 < list_count_items(&gd->dm_root->child_head));
/* Our 3 dm_test_infox children should be bound to the test uclass */
/* No devices should be probed */
list_for_each_entry(dev, &gd->dm_root->child_head, sibling_node)
- ut_assert(!(dev->flags & DM_FLAG_ACTIVATED));
+ ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
/* Our test driver should have been bound 3 times */
ut_assert(dm_testdrv_op_count[DM_TEST_OP_BIND] == 3);
ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]);
/* The root device should not be activated until needed */
- ut_assert(dms->root->flags & DM_FLAG_ACTIVATED);
+ ut_assert(dev_get_flags(dms->root) & DM_FLAG_ACTIVATED);
/*
* We should be able to find the three test devices, and they should
for (i = 0; i < 3; i++) {
ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev));
ut_assert(dev);
- ut_assertf(!(dev->flags & DM_FLAG_ACTIVATED),
+ ut_assertf(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED),
"Driver %d/%s already activated", i, dev->name);
/* This should activate it */
ut_assertok(uclass_get_device(UCLASS_TEST, i, &dev));
ut_assert(dev);
- ut_assert(dev->flags & DM_FLAG_ACTIVATED);
+ ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
/* Activating a device should activate the root device */
if (!i)
- ut_assert(dms->root->flags & DM_FLAG_ACTIVATED);
+ ut_assert(dev_get_flags(dms->root) & DM_FLAG_ACTIVATED);
}
/*
ut_assert(priv);
ut_asserteq(expected_base_add, priv->base_add);
- pdata = dev->plat;
+ pdata = dev_get_plat(dev);
expected_base_add += pdata->ping_add;
}
for (i = 0; i < 3; i++) {
ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev));
ut_assert(dev);
- pdata = dev->plat;
+ pdata = dev_get_plat(dev);
ut_assert(pdata->ping_add == test_pdata[i].ping_add);
}
ut_assert(dev);
ut_assert(dm_testdrv_op_count[DM_TEST_OP_BIND]
== op_count[DM_TEST_OP_BIND] + 1);
- ut_assert(!dev->priv);
+ ut_assert(!dev_get_priv(dev));
/* Probe the device - it should fail allocating private data */
dms->force_fail_alloc = 1;
ut_assert(ret == -ENOMEM);
ut_assert(dm_testdrv_op_count[DM_TEST_OP_PROBE]
== op_count[DM_TEST_OP_PROBE] + 1);
- ut_assert(!dev->priv);
+ ut_assert(!dev_get_priv(dev));
/* Try again without the alloc failure */
dms->force_fail_alloc = 0;
ut_assertok(device_probe(dev));
ut_assert(dm_testdrv_op_count[DM_TEST_OP_PROBE]
== op_count[DM_TEST_OP_PROBE] + 2);
- ut_assert(dev->priv);
+ ut_assert(dev_get_priv(dev));
/* This should be device 3 in the uclass */
ut_assertok(uclass_find_device(UCLASS_TEST, 3, &test_dev));
/* Getting the child device should allocate plat / priv */
ut_assertok(testfdt_ping(dev, 10, &pingret));
- ut_assert(dev->priv);
- ut_assert(dev->plat);
+ ut_assert(dev_get_priv(dev));
+ ut_assert(dev_get_plat(dev));
expected = 10 + base;
ut_asserteq(expected, pingret);
ut_asserteq(expected, pingret);
/* Now check the ping_total */
- priv = dev->priv;
+ priv = dev_get_priv(dev);
ut_asserteq(DM_TEST_START_TOTAL + 10 + 20 + base * 2,
priv->ping_total);
base = test_pdata[i].ping_add;
debug("dev=%d, base=%d\n", i, base);
- ut_assert(!dm_check_operations(uts, dev, base, dev->priv));
+ ut_assert(!dm_check_operations(uts, dev, base, dev_get_priv(dev)));
}
return 0;
for (i = 0; i < 3; i++) {
ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev));
ut_assert(dev);
- ut_assertf(dev->flags & DM_FLAG_ACTIVATED,
+ ut_assertf(dev_get_flags(dev) & DM_FLAG_ACTIVATED,
"Driver %d/%s not activated", i, dev->name);
ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
- ut_assertf(!(dev->flags & DM_FLAG_ACTIVATED),
+ ut_assertf(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED),
"Driver %d/%s should have deactivated", i,
dev->name);
- ut_assert(!dev->priv);
+ ut_assert(!dev_get_priv(dev));
}
return 0;
ut_assertok(uclass_get(UCLASS_TEST, &uc));
ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_INIT]);
ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_DESTROY]);
- ut_assert(uc->priv);
+ ut_assert(uclass_get_priv(uc));
ut_assertok(uclass_destroy(uc));
ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_INIT]);
&driver_info_manual, &dev));
pdata = calloc(1, sizeof(*pdata));
pdata->ping_add = key + i;
- dev->plat = pdata;
+ dev_set_plat(dev, pdata);
if (child)
child[i] = dev;
}
*/
ut_asserteq(-ENODEV, device_find_first_inactive_child(parent,
UCLASS_TEST, &dev1));
- ut_assertok(device_bind(parent, DM_GET_DRIVER(test_drv),
+ ut_assertok(device_bind(parent, DM_DRIVER_GET(test_drv),
"test_child", 0, ofnode_null(), &dev1));
ut_assertok(device_find_first_inactive_child(parent, UCLASS_TEST,
struct udevice *dev;
struct uclass *uc;
- list_for_each_entry(uc, &gd->uclass_root, sibling_node) {
+ list_for_each_entry(uc, gd->uclass_root, sibling_node) {
list_for_each_entry(dev, &uc->dev_head, uclass_node) {
- if (dev->sqq == -1)
+ if (dev->seq_ == -1)
printf("Device '%s' has no seq (%d)\n",
- dev->name, dev->sqq);
- ut_assert(dev->sqq != -1);
+ dev->name, dev->seq_);
+ ut_assert(dev->seq_ != -1);
}
}
for (uclass_find_first_device(UCLASS_CPU, &dev);
dev;
uclass_find_next_device(&dev))
- ut_assert(dev->flags & DM_FLAG_ACTIVATED);
+ ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
ut_assertok(uclass_get_device_by_name(UCLASS_CPU, "cpu-test1", &dev));
ut_asserteq_ptr(cpu_get_current_dev(), dev);
ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x08, 0), &swap));
ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data);
- ut_assertok(dev_of_valid(swap));
+ ut_assertok(dev_has_ofnode(swap));
ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x0c, 0), &swap));
ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data);
- ut_assertok(dev_of_valid(swap));
+ ut_assertok(dev_has_ofnode(swap));
ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x10, 0), &swap));
ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data);
- ut_assertok(!dev_of_valid(swap));
+ ut_assertok(!dev_has_ofnode(swap));
return 0;
}
#include <log.h>
#include <malloc.h>
#include <asm/io.h>
+#include <dm/device-internal.h>
#include <dm/test.h>
#include <test/test.h>
#include <test/ut.h>
static int test_unbind(struct udevice *dev)
{
/* Private data should not be allocated */
- ut_assert(!dev->priv);
+ ut_assert(!dev_get_priv(dev));
dm_testdrv_op_count[DM_TEST_OP_UNBIND]++;
return 0;
dm_testdrv_op_count[DM_TEST_OP_PROBE]++;
if (!dms->force_fail_alloc)
- dev->priv = calloc(1, sizeof(struct dm_test_priv));
- if (!dev->priv)
+ dev_set_priv(dev, calloc(1, sizeof(struct dm_test_priv)));
+ if (!dev_get_priv(dev))
return -ENOMEM;
return 0;
DECLARE_GLOBAL_DATA_PTR;
-static int testfdt_drv_ping(struct udevice *dev, int pingval, int *pingret)
-{
- const struct dm_test_pdata *pdata = dev->plat;
- struct dm_test_priv *priv = dev_get_priv(dev);
-
- *pingret = pingval + pdata->ping_add;
- priv->ping_total += *pingret;
-
- return 0;
-}
-
-static const struct test_ops test_ops = {
- .ping = testfdt_drv_ping,
-};
-
-static int testfdt_of_to_plat(struct udevice *dev)
-{
- struct dm_test_pdata *pdata = dev_get_plat(dev);
-
- pdata->ping_add = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
- "ping-add", -1);
- pdata->base = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev),
- "ping-expect");
-
- return 0;
-}
-
-static int testfdt_drv_probe(struct udevice *dev)
-{
- struct dm_test_priv *priv = dev_get_priv(dev);
-
- priv->ping_total += DM_TEST_START_TOTAL;
-
- /*
- * If this device is on a bus, the uclass_flag will be set before
- * calling this function. In the meantime the uclass_postp is
- * initlized to a value -1. These are used respectively by
- * dm_test_bus_child_pre_probe_uclass() and
- * dm_test_bus_child_post_probe_uclass().
- */
- priv->uclass_total += priv->uclass_flag;
- priv->uclass_postp = -1;
-
- return 0;
-}
-
-static const struct udevice_id testfdt_ids[] = {
- {
- .compatible = "denx,u-boot-fdt-test",
- .data = DM_TEST_TYPE_FIRST },
- {
- .compatible = "google,another-fdt-test",
- .data = DM_TEST_TYPE_SECOND },
- { }
-};
-
-U_BOOT_DRIVER(testfdt_drv) = {
- .name = "testfdt_drv",
- .of_match = testfdt_ids,
- .id = UCLASS_TEST_FDT,
- .of_to_plat = testfdt_of_to_plat,
- .probe = testfdt_drv_probe,
- .ops = &test_ops,
- .priv_auto = sizeof(struct dm_test_priv),
- .plat_auto = sizeof(struct dm_test_pdata),
-};
-
-static const struct udevice_id testfdt1_ids[] = {
- {
- .compatible = "denx,u-boot-fdt-test1",
- .data = DM_TEST_TYPE_FIRST },
- { }
-};
-
-U_BOOT_DRIVER(testfdt1_drv) = {
- .name = "testfdt1_drv",
- .of_match = testfdt1_ids,
- .id = UCLASS_TEST_FDT,
- .of_to_plat = testfdt_of_to_plat,
- .probe = testfdt_drv_probe,
- .ops = &test_ops,
- .priv_auto = sizeof(struct dm_test_priv),
- .plat_auto = sizeof(struct dm_test_pdata),
- .flags = DM_FLAG_PRE_RELOC,
-};
-
-/* From here is the testfdt uclass code */
-int testfdt_ping(struct udevice *dev, int pingval, int *pingret)
-{
- const struct test_ops *ops = device_get_ops(dev);
-
- if (!ops->ping)
- return -ENOSYS;
-
- return ops->ping(dev, pingval, pingret);
-}
-
-UCLASS_DRIVER(testfdt) = {
- .name = "testfdt",
- .id = UCLASS_TEST_FDT,
- .flags = DM_UC_FLAG_SEQ_ALIAS,
-};
-
-static const struct udevice_id testfdtm_ids[] = {
- { .compatible = "denx,u-boot-fdtm-test" },
- { }
-};
-
-U_BOOT_DRIVER(testfdtm_drv) = {
- .name = "testfdtm_drv",
- .of_match = testfdtm_ids,
- .id = UCLASS_TEST_FDT_MANUAL,
-};
-
-UCLASS_DRIVER(testfdtm) = {
- .name = "testfdtm",
- .id = UCLASS_TEST_FDT_MANUAL,
- .flags = DM_UC_FLAG_SEQ_ALIAS | DM_UC_FLAG_NO_AUTO_SEQ,
-};
-
struct dm_testprobe_pdata {
int probe_err;
};
ret = uclass_find_device(UCLASS_TEST_FDT, i, &dev);
ut_assert(!ret);
ut_assert(!dev_get_priv(dev));
- ut_assert(dev->plat);
+ ut_assert(dev_get_plat(dev));
}
ut_assertok(dm_check_devices(uts, num_devices));
/* Check creating a device with an alias */
node = ofnode_path("/some-bus/c-test@1");
- ut_assertok(device_bind(dm_root(), DM_GET_DRIVER(testfdt_drv),
+ ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(testfdt_drv),
"c-test@1", NULL, node, &dev));
ut_asserteq(12, dev_seq(dev));
ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 12, &dev));
*
* So next available is 19
*/
- ut_assertok(device_bind(dm_root(), DM_GET_DRIVER(testfdt_drv),
+ ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(testfdt_drv),
"fred", NULL, ofnode_null(), &dev));
ut_asserteq(19, dev_seq(dev));
- ut_assertok(device_bind(dm_root(), DM_GET_DRIVER(testfdt_drv),
+ ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(testfdt_drv),
"fred2", NULL, ofnode_null(), &dev));
ut_asserteq(20, dev_seq(dev));
ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus));
count = 0;
device_foreach_child_of_to_plat(dev, bus) {
- ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID);
- ut_assert(!(dev->flags & DM_FLAG_ACTIVATED));
+ ut_assert(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID);
+ ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
count++;
}
ut_asserteq(3, count);
ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus));
count = 0;
device_foreach_child_probe(dev, bus) {
- ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID);
- ut_assert(dev->flags & DM_FLAG_ACTIVATED);
+ ut_assert(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID);
+ ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
count++;
}
ut_asserteq(3, count);
ut_assertok(uclass_find_first_device(UCLASS_I2C, &bus));
ut_assertnonnull(bus);
- ut_assert(!(bus->flags & DM_FLAG_PLATDATA_VALID));
+ ut_assert(!(dev_get_flags(bus) & DM_FLAG_PLATDATA_VALID));
ut_assertok(device_find_first_child(bus, &dev));
ut_assertnonnull(dev);
- ut_assert(!(dev->flags & DM_FLAG_PLATDATA_VALID));
+ ut_assert(!(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID));
/* read the child's ofdata which should cause the parent's to be read */
ut_assertok(device_of_to_plat(dev));
- ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID);
- ut_assert(bus->flags & DM_FLAG_PLATDATA_VALID);
+ ut_assert(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID);
+ ut_assert(dev_get_flags(bus) & DM_FLAG_PLATDATA_VALID);
- ut_assert(!(dev->flags & DM_FLAG_ACTIVATED));
- ut_assert(!(bus->flags & DM_FLAG_ACTIVATED));
+ ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
+ ut_assert(!(dev_get_flags(bus) & DM_FLAG_ACTIVATED));
return 0;
}
if (&prev->uclass_node != &uc->dev_head) {
struct dm_test_uclass_perdev_priv *prev_uc_priv
= dev_get_uclass_priv(prev);
- struct dm_test_pdata *pdata = prev->plat;
+ struct dm_test_pdata *pdata = dev_get_plat(prev);
ut_assert(pdata);
ut_assert(prev_uc_priv);
static int test_init(struct uclass *uc)
{
dm_testdrv_op_count[DM_TEST_OP_INIT]++;
- ut_assert(uc->priv);
+ ut_assert(uclass_get_priv(uc));
return 0;
}
ut_assertok(virtio_set_status(dev, VIRTIO_CONFIG_S_DRIVER_OK));
/* check the device can be successfully removed */
- dev->flags |= DM_FLAG_ACTIVATED;
+ dev_or_flags(dev, DM_FLAG_ACTIVATED);
ut_assertok(device_remove(bus, DM_REMOVE_ACTIVE_ALL));
return 0;
assert "u-boot,dm-spl" not in output
assert "u-boot,dm-tpl" not in output
- assert "spl-test4" in output
assert "spl-test5" not in output
assert "spl-test6" not in output
assert "spl-test7" in output
pid = os.fork()
if pid == 0:
try:
- stream = os.fdopen(c2pwrite, 'wb', 1)
+ stream = os.fdopen(c2pwrite, 'wb')
os.close(c2pread)
# Leave stderr and stdout open so we can see test noise
# Close stdin so that the child goes away if it decides to
os._exit(0)
else:
os.close(c2pwrite)
- stream = os.fdopen(c2pread, 'rb', 1)
+ stream = os.fdopen(c2pread, 'rb')
test = ProtocolTestCase(stream)
result.append(test)
return result
import collections
import copy
+from enum import IntEnum
import os
import re
import sys
from dtoc import fdt
from dtoc import fdt_util
+from dtoc import src_scan
+from dtoc.src_scan import conv_name_to_c
# When we see these properties we ignore them - i.e. do not create a structure
# member
STRUCT_PREFIX = 'dtd_'
VAL_PREFIX = 'dtv_'
+class Ftype(IntEnum):
+ SOURCE, HEADER = range(2)
+
+
+# This holds information about each type of output file dtoc can create
+# type: Type of file (Ftype)
+# fname: Filename excluding directory, e.g. 'dt-plat.c'
+# hdr_comment: Comment explaining the purpose of the file
+OutputFile = collections.namedtuple('OutputFile',
+ ['ftype', 'fname', 'method', 'hdr_comment'])
+
# This holds information about a property which includes phandles.
#
# max_args: integer: Maximum number or arguments that any phandle uses (int).
PhandleLink = collections.namedtuple('PhandleLink', ['var_node', 'dev_name'])
-def conv_name_to_c(name):
- """Convert a device-tree name to a C identifier
-
- This uses multiple replace() calls instead of re.sub() since it is faster
- (400ms for 1m calls versus 1000ms for the 're' version).
-
- Args:
- name (str): Name to convert
- Return:
- str: String containing the C version of this name
- """
- new = name.replace('@', '_at_')
- new = new.replace('-', '_')
- new = new.replace(',', '_')
- new = new.replace('.', '_')
- return new
-
def tab_to(num_tabs, line):
"""Append tabs to a line of text to reach a tab stop.
str: String representation of the value
"""
if ftype == fdt.Type.INT:
- return '%#x' % fdt_util.fdt32_to_cpu(value)
+ val = '%#x' % fdt_util.fdt32_to_cpu(value)
elif ftype == fdt.Type.BYTE:
char = value[0]
- return '%#x' % (ord(char) if isinstance(char, str) else char)
+ val = '%#x' % (ord(char) if isinstance(char, str) else char)
elif ftype == fdt.Type.STRING:
# Handle evil ACPI backslashes by adding another backslash before them.
# So "\\_SB.GPO0" in the device tree effectively stays like that in C
- return '"%s"' % value.replace('\\', '\\\\')
+ val = '"%s"' % value.replace('\\', '\\\\')
elif ftype == fdt.Type.BOOL:
- return 'true'
+ val = 'true'
else: # ftype == fdt.Type.INT64:
- return '%#x' % value
-
-def get_compat_name(node):
- """Get the node's list of compatible string as a C identifiers
-
- Args:
- node (fdt.Node): Node object to check
- Return:
- List of C identifiers for all the compatible strings
- """
- compat = node.props['compatible'].value
- if not isinstance(compat, list):
- compat = [compat]
- return [conv_name_to_c(c) for c in compat]
+ val = '%#x' % value
+ return val
-class DtbPlatdata(object):
+class DtbPlatdata():
"""Provide a means to convert device tree binary data to platform data
The output of this process is C structures which can be used in space-
code is not affordable.
Properties:
+ _scan: Scan object, for scanning and reporting on useful information
+ from the U-Boot source code
_fdt: Fdt object, referencing the device tree
_dtb_fname: Filename of the input device tree binary file
_valid_nodes: A list of Node object with compatible strings. The list
is ordered by conv_name_to_c(node.name)
_include_disabled: true to include nodes marked status = "disabled"
_outfile: The current output file (sys.stdout or a real file)
- _warning_disabled: true to disable warnings about driver names not found
_lines: Stashed list of output lines for outputting in the future
- _drivers: List of valid driver names found in drivers/
- _driver_aliases: Dict that holds aliases for driver names
- key: Driver alias declared with
- U_BOOT_DRIVER_ALIAS(driver_alias, driver_name)
- value: Driver name declared with U_BOOT_DRIVER(driver_name)
- _drivers_additional: List of additional drivers to use during scanning
+ _dirname: Directory to hold output files, or None for none (all files
+ go to stdout)
+ _struct_data (dict): OrderedDict of dtplat structures to output
+ key (str): Node name, as a C identifier
+ value: dict containing structure fields:
+ key (str): Field name
+ value: Prop object with field information
+ _basedir (str): Base directory of source tree
"""
- def __init__(self, dtb_fname, include_disabled, warning_disabled,
- drivers_additional=None):
+ def __init__(self, scan, dtb_fname, include_disabled):
+ self._scan = scan
self._fdt = None
self._dtb_fname = dtb_fname
self._valid_nodes = None
self._include_disabled = include_disabled
self._outfile = None
- self._warning_disabled = warning_disabled
self._lines = []
- self._drivers = []
- self._driver_aliases = {}
- self._drivers_additional = drivers_additional or []
+ self._dirnames = [None] * len(Ftype)
+ self._struct_data = collections.OrderedDict()
+ self._basedir = None
- def get_normalized_compat_name(self, node):
- """Get a node's normalized compat name
+ def setup_output_dirs(self, output_dirs):
+ """Set up the output directories
- Returns a valid driver name by retrieving node's list of compatible
- string as a C identifier and performing a check against _drivers
- and a lookup in driver_aliases printing a warning in case of failure.
+ This should be done before setup_output() is called
Args:
- node: Node object to check
- Return:
- Tuple:
- Driver name associated with the first compatible string
- List of C identifiers for all the other compatible strings
- (possibly empty)
- In case of no match found, the return will be the same as
- get_compat_name()
+ output_dirs (tuple of str):
+ Directory to use for C output files.
+ Use None to write files relative current directory
+ Directory to use for H output files.
+ Defaults to the C output dir
"""
- compat_list_c = get_compat_name(node)
-
- for compat_c in compat_list_c:
- if not compat_c in self._drivers:
- compat_c = self._driver_aliases.get(compat_c)
- if not compat_c:
- continue
-
- aliases_c = compat_list_c
- if compat_c in aliases_c:
- aliases_c.remove(compat_c)
- return compat_c, aliases_c
-
- if not self._warning_disabled:
- print('WARNING: the driver %s was not found in the driver list'
- % (compat_list_c[0]))
-
- return compat_list_c[0], compat_list_c[1:]
-
- def setup_output(self, fname):
+ def process_dir(ftype, dirname):
+ if dirname:
+ os.makedirs(dirname, exist_ok=True)
+ self._dirnames[ftype] = dirname
+
+ if output_dirs:
+ c_dirname = output_dirs[0]
+ h_dirname = output_dirs[1] if len(output_dirs) > 1 else c_dirname
+ process_dir(Ftype.SOURCE, c_dirname)
+ process_dir(Ftype.HEADER, h_dirname)
+
+ def setup_output(self, ftype, fname):
"""Set up the output destination
Once this is done, future calls to self.out() will output to this
- file.
+ file. The file used is as follows:
+
+ self._dirnames[ftype] is None: output to fname, or stdout if None
+ self._dirnames[ftype] is not None: output to fname in that directory
+
+ Calling this function multiple times will close the old file and open
+ the new one. If they are the same file, nothing happens and output will
+ continue to the same file.
Args:
- fname (str): Filename to send output to, or '-' for stdout
+ ftype (str): Type of file to create ('c' or 'h')
+ fname (str): Filename to send output to. If there is a directory in
+ self._dirnames for this file type, it will be put in that
+ directory
"""
- if fname == '-':
- self._outfile = sys.stdout
+ dirname = self._dirnames[ftype]
+ if dirname:
+ pathname = os.path.join(dirname, fname)
+ if self._outfile:
+ self._outfile.close()
+ self._outfile = open(pathname, 'w')
+ elif fname:
+ if not self._outfile:
+ self._outfile = open(fname, 'w')
else:
- self._outfile = open(fname, 'w')
+ self._outfile = sys.stdout
+
+ def finish_output(self):
+ """Finish outputing to a file
+
+ This closes the output file, if one is in use
+ """
+ if self._outfile != sys.stdout:
+ self._outfile.close()
def out(self, line):
"""Output a string to the output file
self._lines = []
return lines
- def out_header(self):
- """Output a message indicating that this is an auto-generated file"""
+ def out_header(self, outfile):
+ """Output a message indicating that this is an auto-generated file
+
+ Args:
+ outfile: OutputFile describing the file being generated
+ """
self.out('''/*
* DO NOT MODIFY
*
- * This file was generated by dtoc from a .dtb (device tree binary) file.
+ * %s.
+ * This was generated by dtoc from a .dtb (device tree binary) file.
*/
-''')
+''' % outfile.hdr_comment)
def get_phandle_argc(self, prop, node_name):
"""Check if a node contains phandles
return PhandleInfo(max_args, args)
return None
- def scan_driver(self, fname):
- """Scan a driver file to build a list of driver names and aliases
-
- This procedure will populate self._drivers and self._driver_aliases
-
- Args
- fname: Driver filename to scan
- """
- with open(fname, encoding='utf-8') as inf:
- try:
- buff = inf.read()
- except UnicodeDecodeError:
- # This seems to happen on older Python versions
- print("Skipping file '%s' due to unicode error" % fname)
- return
-
- # The following re will search for driver names declared as
- # U_BOOT_DRIVER(driver_name)
- drivers = re.findall('U_BOOT_DRIVER\((.*)\)', buff)
-
- for driver in drivers:
- self._drivers.append(driver)
-
- # The following re will search for driver aliases declared as
- # U_BOOT_DRIVER_ALIAS(alias, driver_name)
- driver_aliases = re.findall(
- 'U_BOOT_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)',
- buff)
-
- for alias in driver_aliases: # pragma: no cover
- if len(alias) != 2:
- continue
- self._driver_aliases[alias[1]] = alias[0]
-
- def scan_drivers(self):
- """Scan the driver folders to build a list of driver names and aliases
-
- This procedure will populate self._drivers and self._driver_aliases
-
- """
- basedir = sys.argv[0].replace('tools/dtoc/dtoc', '')
- if basedir == '':
- basedir = './'
- for (dirpath, _, filenames) in os.walk(basedir):
- for fname in filenames:
- if not fname.endswith('.c'):
- continue
- self.scan_driver(dirpath + '/' + fname)
-
- for fname in self._drivers_additional:
- if not isinstance(fname, str) or len(fname) == 0:
- continue
- if fname[0] == '/':
- self.scan_driver(fname)
- else:
- self.scan_driver(basedir + '/' + fname)
-
def scan_dtb(self):
"""Scan the device tree to obtain a tree of nodes and properties
This adds each node to self._valid_nodes.
Args:
- root: Root node for scan
- valid_nodes: List of Node objects to add to
+ root (Node): Root node for scan
+ valid_nodes (list of Node): List of Node objects to add to
"""
for node in root.subnodes:
if 'compatible' in node.props:
Once the widest property is determined, all other properties are
updated to match that width.
- Returns:
- dict containing structures:
- key (str): Node name, as a C identifier
- value: dict containing structure fields:
- key (str): Field name
- value: Prop object with field information
+ The results are written to self._struct_data
"""
- structs = collections.OrderedDict()
+ structs = self._struct_data
for node in self._valid_nodes:
- node_name, _ = self.get_normalized_compat_name(node)
+ node_name, _ = self._scan.get_normalized_compat_name(node)
fields = {}
# Get a list of all the valid properties in this node.
structs[node_name] = fields
for node in self._valid_nodes:
- node_name, _ = self.get_normalized_compat_name(node)
+ node_name, _ = self._scan.get_normalized_compat_name(node)
struct = structs[node_name]
for name, prop in node.props.items():
if name not in PROP_IGNORE_LIST and name[0] != '#':
prop.Widen(struct[name])
- return structs
-
def scan_phandles(self):
"""Figure out what phandles each node uses
pos += 1 + args
- def generate_structs(self, structs):
+ def generate_structs(self):
"""Generate struct defintions for the platform data
This writes out the body of a header file consisting of structure
definitions for node in self._valid_nodes. See the documentation in
doc/driver-model/of-plat.rst for more information.
-
- Args:
- structs: dict containing structures:
- key (str): Node name, as a C identifier
- value: dict containing structure fields:
- key (str): Field name
- value: Prop object with field information
-
"""
- self.out_header()
+ structs = self._struct_data
self.out('#include <stdbool.h>\n')
self.out('#include <linux/libfdt.h>\n')
self.out(';\n')
self.out('};\n')
- def output_node(self, node):
- """Output the C code for a node
+ def _output_list(self, node, prop):
+ """Output the C code for a devicetree property that holds a list
Args:
- node (fdt.Node): node to output
+ node (fdt.Node): Node to output
+ prop (fdt.Prop): Prop to output
"""
- def _output_list(node, prop):
- """Output the C code for a devicetree property that holds a list
-
- Args:
- node (fdt.Node): Node to output
- prop (fdt.Prop): Prop to output
- """
- self.buf('{')
- vals = []
- # For phandles, output a reference to the platform data
- # of the target node.
- info = self.get_phandle_argc(prop, node.name)
- if info:
- # Process the list as pairs of (phandle, id)
- pos = 0
- for args in info.args:
- phandle_cell = prop.value[pos]
- phandle = fdt_util.fdt32_to_cpu(phandle_cell)
- target_node = self._fdt.phandle_to_node[phandle]
- arg_values = []
- for i in range(args):
- arg_values.append(
- str(fdt_util.fdt32_to_cpu(prop.value[pos + 1 + i])))
- pos += 1 + args
- vals.append('\t{%d, {%s}}' % (target_node.idx,
- ', '.join(arg_values)))
- for val in vals:
- self.buf('\n\t\t%s,' % val)
- else:
- for val in prop.value:
- vals.append(get_value(prop.type, val))
+ self.buf('{')
+ vals = []
+ # For phandles, output a reference to the platform data
+ # of the target node.
+ info = self.get_phandle_argc(prop, node.name)
+ if info:
+ # Process the list as pairs of (phandle, id)
+ pos = 0
+ for args in info.args:
+ phandle_cell = prop.value[pos]
+ phandle = fdt_util.fdt32_to_cpu(phandle_cell)
+ target_node = self._fdt.phandle_to_node[phandle]
+ arg_values = []
+ for i in range(args):
+ arg_values.append(
+ str(fdt_util.fdt32_to_cpu(prop.value[pos + 1 + i])))
+ pos += 1 + args
+ vals.append('\t{%d, {%s}}' % (target_node.idx,
+ ', '.join(arg_values)))
+ for val in vals:
+ self.buf('\n\t\t%s,' % val)
+ else:
+ for val in prop.value:
+ vals.append(get_value(prop.type, val))
- # Put 8 values per line to avoid very long lines.
- for i in range(0, len(vals), 8):
- if i:
- self.buf(',\n\t\t')
- self.buf(', '.join(vals[i:i + 8]))
- self.buf('}')
+ # Put 8 values per line to avoid very long lines.
+ for i in range(0, len(vals), 8):
+ if i:
+ self.buf(',\n\t\t')
+ self.buf(', '.join(vals[i:i + 8]))
+ self.buf('}')
- struct_name, _ = self.get_normalized_compat_name(node)
- var_name = conv_name_to_c(node.name)
- self.buf('/* Node %s index %d */\n' % (node.path, node.idx))
- self.buf('static struct %s%s %s%s = {\n' %
- (STRUCT_PREFIX, struct_name, VAL_PREFIX, var_name))
- for pname in sorted(node.props):
- prop = node.props[pname]
- if pname in PROP_IGNORE_LIST or pname[0] == '#':
- continue
- member_name = conv_name_to_c(prop.name)
- self.buf('\t%s= ' % tab_to(3, '.' + member_name))
+ def _declare_device(self, var_name, struct_name, node_parent):
+ """Add a device declaration to the output
- # Special handling for lists
- if isinstance(prop.value, list):
- _output_list(node, prop)
- else:
- self.buf(get_value(prop.type, prop.value))
- self.buf(',\n')
- self.buf('};\n')
+ This declares a U_BOOT_DRVINFO() for the device being processed
- # Add a device declaration
- self.buf('U_BOOT_DEVICE(%s) = {\n' % var_name)
+ Args:
+ var_name (str): C name for the node
+ struct_name (str): Name for the dt struct associated with the node
+ node_parent (Node): Parent of the node (or None if none)
+ """
+ self.buf('U_BOOT_DRVINFO(%s) = {\n' % var_name)
self.buf('\t.name\t\t= "%s",\n' % struct_name)
self.buf('\t.plat\t= &%s%s,\n' % (VAL_PREFIX, var_name))
self.buf('\t.plat_size\t= sizeof(%s%s),\n' % (VAL_PREFIX, var_name))
idx = -1
- if node.parent and node.parent in self._valid_nodes:
- idx = node.parent.idx
+ if node_parent and node_parent in self._valid_nodes:
+ idx = node_parent.idx
self.buf('\t.parent_idx\t= %d,\n' % idx)
self.buf('};\n')
self.buf('\n')
+ def _output_prop(self, node, prop):
+ """Output a line containing the value of a struct member
+
+ Args:
+ node (Node): Node being output
+ prop (Prop): Prop object to output
+ """
+ if prop.name in PROP_IGNORE_LIST or prop.name[0] == '#':
+ return
+ member_name = conv_name_to_c(prop.name)
+ self.buf('\t%s= ' % tab_to(3, '.' + member_name))
+
+ # Special handling for lists
+ if isinstance(prop.value, list):
+ self._output_list(node, prop)
+ else:
+ self.buf(get_value(prop.type, prop.value))
+ self.buf(',\n')
+
+ def _output_values(self, var_name, struct_name, node):
+ """Output the definition of a device's struct values
+
+ Args:
+ var_name (str): C name for the node
+ struct_name (str): Name for the dt struct associated with the node
+ node (Node): Node being output
+ """
+ self.buf('static struct %s%s %s%s = {\n' %
+ (STRUCT_PREFIX, struct_name, VAL_PREFIX, var_name))
+ for pname in sorted(node.props):
+ self._output_prop(node, node.props[pname])
+ self.buf('};\n')
+
+ def output_node(self, node):
+ """Output the C code for a node
+
+ Args:
+ node (fdt.Node): node to output
+ """
+ struct_name, _ = self._scan.get_normalized_compat_name(node)
+ var_name = conv_name_to_c(node.name)
+ self.buf('/* Node %s index %d */\n' % (node.path, node.idx))
+
+ self._output_values(var_name, struct_name, node)
+ self._declare_device(var_name, struct_name, node.parent)
+
self.out(''.join(self.get_buf()))
- def generate_tables(self):
+ def generate_plat(self):
"""Generate device defintions for the platform data
This writes out C platform data initialisation data and
- U_BOOT_DEVICE() declarations for each valid node. Where a node has
+ U_BOOT_DRVINFO() declarations for each valid node. Where a node has
multiple compatible strings, a #define is used to make them equivalent.
See the documentation in doc/driver-model/of-plat.rst for more
information.
"""
- self.out_header()
- self.out('/* Allow use of U_BOOT_DEVICE() in this file */\n')
- self.out('#define DT_PLATDATA_C\n')
+ self.out('/* Allow use of U_BOOT_DRVINFO() in this file */\n')
+ self.out('#define DT_PLAT_C\n')
self.out('\n')
self.out('#include <common.h>\n')
self.out('#include <dm.h>\n')
self.out('#include <dt-structs.h>\n')
self.out('\n')
- nodes_to_output = list(self._valid_nodes)
-
- # Keep outputing nodes until there is none left
- while nodes_to_output:
- node = nodes_to_output[0]
- # Output all the node's dependencies first
- for req_node in node.phandles:
- if req_node in nodes_to_output:
- self.output_node(req_node)
- nodes_to_output.remove(req_node)
- self.output_node(node)
- nodes_to_output.remove(node)
- # Define dm_populate_phandle_data() which will add the linking between
- # nodes using DM_GET_DEVICE
- # dtv_dmc_at_xxx.clocks[0].node = DM_GET_DEVICE(clock_controller_at_xxx)
- self.buf('void dm_populate_phandle_data(void) {\n')
- self.buf('}\n')
+ for node in self._valid_nodes:
+ self.output_node(node)
self.out(''.join(self.get_buf()))
-def run_steps(args, dtb_file, include_disabled, output, warning_disabled=False,
- drivers_additional=None):
+
+# Types of output file we understand
+# key: Command used to generate this file
+# value: OutputFile for this command
+OUTPUT_FILES = {
+ 'struct':
+ OutputFile(Ftype.HEADER, 'dt-structs-gen.h',
+ DtbPlatdata.generate_structs,
+ 'Defines the structs used to hold devicetree data'),
+ 'platdata':
+ OutputFile(Ftype.SOURCE, 'dt-plat.c', DtbPlatdata.generate_plat,
+ 'Declares the U_BOOT_DRIVER() records and platform data'),
+ }
+
+
+def run_steps(args, dtb_file, include_disabled, output, output_dirs,
+ warning_disabled=False, drivers_additional=None, basedir=None):
"""Run all the steps of the dtoc tool
Args:
args (list): List of non-option arguments provided to the problem
dtb_file (str): Filename of dtb file to process
include_disabled (bool): True to include disabled nodes
- output (str): Name of output file
+ output (str): Name of output file (None for stdout)
+ output_dirs (tuple of str):
+ Directory to put C output files
+ Directory to put H output files
warning_disabled (bool): True to avoid showing warnings about missing
drivers
- _drivers_additional (list): List of additional drivers to use during
+ drivers_additional (list): List of additional drivers to use during
scanning
+ basedir (str): Base directory of U-Boot source code. Defaults to the
+ grandparent of this file's directory
Raises:
ValueError: if args has no command, or an unknown command
"""
if not args:
- raise ValueError('Please specify a command: struct, platdata')
+ raise ValueError('Please specify a command: struct, platdata, all')
+ if output and output_dirs and any(output_dirs):
+ raise ValueError('Must specify either output or output_dirs, not both')
- plat = DtbPlatdata(dtb_file, include_disabled, warning_disabled,
- drivers_additional)
- plat.scan_drivers()
+ scan = src_scan.Scanner(basedir, warning_disabled, drivers_additional)
+ plat = DtbPlatdata(scan, dtb_file, include_disabled)
+ scan.scan_drivers()
plat.scan_dtb()
plat.scan_tree()
plat.scan_reg_sizes()
- plat.setup_output(output)
- structs = plat.scan_structs()
+ plat.setup_output_dirs(output_dirs)
+ plat.scan_structs()
plat.scan_phandles()
- for cmd in args[0].split(','):
- if cmd == 'struct':
- plat.generate_structs(structs)
- elif cmd == 'platdata':
- plat.generate_tables()
- else:
- raise ValueError("Unknown command '%s': (use: struct, platdata)" %
- cmd)
+ cmds = args[0].split(',')
+ if 'all' in cmds:
+ cmds = sorted(OUTPUT_FILES.keys())
+ for cmd in cmds:
+ outfile = OUTPUT_FILES.get(cmd)
+ if not outfile:
+ raise ValueError("Unknown command '%s': (use: %s)" %
+ (cmd, ', '.join(sorted(OUTPUT_FILES.keys()))))
+ plat.setup_output(outfile.ftype,
+ outfile.fname if output_dirs else output)
+ plat.out_header(outfile)
+ outfile.method(plat)
+ plat.finish_output()
-U_BOOT_DRIVER_ALIAS(sandbox_gpio, sandbox_gpio_alias2)
+DM_DRIVER_ALIAS(sandbox_gpio, sandbox_gpio_alias2)
longbytearray = [09 0a 0b 0c 0d 0e 0f 10];
};
- spl-test4 {
- u-boot,dm-pre-reloc;
- compatible = "sandbox,spl-test.2";
- };
-
i2c@0 {
compatible = "sandbox,i2c-test";
u-boot,dm-pre-reloc;
C structures, normal C code can be used. This helps to reduce the size of the
compiled program.
-Dtoc produces two output files:
-
- dt-structs.h - contains struct definitions
- dt-platdata.c - contains data from the device tree using the struct
- definitions, as well as U-Boot driver definitions.
+Dtoc produces several output files - see OUTPUT_FILES in dtb_platdata.py
This tool is used in U-Boot to provide device tree data to SPL without
increasing the code size of SPL. This supports the CONFIG_SPL_OF_PLATDATA
from dtoc import dtb_platdata
from patman import test_util
-def run_tests(args):
+def run_tests(processes, args):
"""Run all the test we have for dtoc
Args:
+ processes: Number of processes to use to run tests (None=same as #CPUs)
args: List of positional args provided to dtoc. This can hold a test
name to execute (as in 'dtoc -t test_empty_file', for example)
"""
- import test_dtoc
+ from dtoc import test_src_scan
+ from dtoc import test_dtoc
result = unittest.TestResult()
sys.argv = [sys.argv[0]]
test_name = args and args[0] or None
- for module in (test_dtoc.TestDtoc,):
- if test_name:
- try:
- suite = unittest.TestLoader().loadTestsFromName(test_name, module)
- except AttributeError:
- continue
- else:
- suite = unittest.TestLoader().loadTestsFromTestCase(module)
- suite.run(result)
-
- print(result)
- for _, err in result.errors:
- print(err)
- for _, err in result.failures:
- print(err)
- if result.errors or result.failures:
- print('dtoc tests FAILED')
- return 1
- return 0
+
+ test_util.RunTestSuites(
+ result, debug=True, verbosity=1, test_preserve_dirs=False,
+ processes=processes, test_name=test_name, toolpath=[],
+ test_class_list=[test_dtoc.TestDtoc,test_src_scan.TestSrcScan])
+
+ return test_util.ReportResult('binman', test_name, result)
def RunTestCoverage():
"""Run the tests and check that we get 100% coverage"""
parser = OptionParser()
parser.add_option('-B', '--build-dir', type='string', default='b',
help='Directory containing the build output')
+parser.add_option('-c', '--c-output-dir', action='store',
+ help='Select output directory for C files')
+parser.add_option('-C', '--h-output-dir', action='store',
+ help='Select output directory for H files (defaults to --c-output-di)')
parser.add_option('-d', '--dtb-file', action='store',
help='Specify the .dtb input file')
parser.add_option('--include-disabled', action='store_true',
help='Include disabled nodes')
-parser.add_option('-o', '--output', action='store', default='-',
+parser.add_option('-o', '--output', action='store',
help='Select output filename')
parser.add_option('-P', '--processes', type=int,
help='set number of processes to use for running tests')
# Run our meagre tests
if options.test:
- ret_code = run_tests(args)
+ ret_code = run_tests(options.processes, args)
sys.exit(ret_code)
elif options.test_coverage:
else:
dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled,
- options.output)
+ options.output,
+ [options.c_output_dir, options.h_output_dir])
--- /dev/null
+#!/usr/bin/python
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2017 Google, Inc
+#
+
+"""Scanning of U-Boot source for drivers and structs
+
+This scans the source tree to find out things about all instances of
+U_BOOT_DRIVER(), UCLASS_DRIVER and all struct declarations in header files.
+
+See doc/driver-model/of-plat.rst for more informaiton
+"""
+
+import os
+import re
+import sys
+
+
+def conv_name_to_c(name):
+ """Convert a device-tree name to a C identifier
+
+ This uses multiple replace() calls instead of re.sub() since it is faster
+ (400ms for 1m calls versus 1000ms for the 're' version).
+
+ Args:
+ name (str): Name to convert
+ Return:
+ str: String containing the C version of this name
+ """
+ new = name.replace('@', '_at_')
+ new = new.replace('-', '_')
+ new = new.replace(',', '_')
+ new = new.replace('.', '_')
+ return new
+
+def get_compat_name(node):
+ """Get the node's list of compatible string as a C identifiers
+
+ Args:
+ node (fdt.Node): Node object to check
+ Return:
+ list of str: List of C identifiers for all the compatible strings
+ """
+ compat = node.props['compatible'].value
+ if not isinstance(compat, list):
+ compat = [compat]
+ return [conv_name_to_c(c) for c in compat]
+
+
+class Driver:
+ """Information about a driver in U-Boot
+
+ Attributes:
+ name: Name of driver. For U_BOOT_DRIVER(x) this is 'x'
+ """
+ def __init__(self, name):
+ self.name = name
+
+ def __eq__(self, other):
+ return self.name == other.name
+
+ def __repr__(self):
+ return "Driver(name='%s')" % self.name
+
+
+class Scanner:
+ """Scanning of the U-Boot source tree
+
+ Properties:
+ _basedir (str): Base directory of U-Boot source code. Defaults to the
+ grandparent of this file's directory
+ _drivers: Dict of valid driver names found in drivers/
+ key: Driver name
+ value: Driver for that driver
+ _driver_aliases: Dict that holds aliases for driver names
+ key: Driver alias declared with
+ DM_DRIVER_ALIAS(driver_alias, driver_name)
+ value: Driver name declared with U_BOOT_DRIVER(driver_name)
+ _warning_disabled: true to disable warnings about driver names not found
+ _drivers_additional (list or str): List of additional drivers to use
+ during scanning
+ """
+ def __init__(self, basedir, warning_disabled, drivers_additional):
+ """Set up a new Scanner
+ """
+ if not basedir:
+ basedir = sys.argv[0].replace('tools/dtoc/dtoc', '')
+ if basedir == '':
+ basedir = './'
+ self._basedir = basedir
+ self._drivers = {}
+ self._driver_aliases = {}
+ self._drivers_additional = drivers_additional or []
+ self._warning_disabled = warning_disabled
+
+ def get_normalized_compat_name(self, node):
+ """Get a node's normalized compat name
+
+ Returns a valid driver name by retrieving node's list of compatible
+ string as a C identifier and performing a check against _drivers
+ and a lookup in driver_aliases printing a warning in case of failure.
+
+ Args:
+ node (Node): Node object to check
+ Return:
+ Tuple:
+ Driver name associated with the first compatible string
+ List of C identifiers for all the other compatible strings
+ (possibly empty)
+ In case of no match found, the return will be the same as
+ get_compat_name()
+ """
+ compat_list_c = get_compat_name(node)
+
+ for compat_c in compat_list_c:
+ if not compat_c in self._drivers.keys():
+ compat_c = self._driver_aliases.get(compat_c)
+ if not compat_c:
+ continue
+
+ aliases_c = compat_list_c
+ if compat_c in aliases_c:
+ aliases_c.remove(compat_c)
+ return compat_c, aliases_c
+
+ if not self._warning_disabled:
+ print('WARNING: the driver %s was not found in the driver list'
+ % (compat_list_c[0]))
+
+ return compat_list_c[0], compat_list_c[1:]
+
+ def scan_driver(self, fname):
+ """Scan a driver file to build a list of driver names and aliases
+
+ This procedure will populate self._drivers and self._driver_aliases
+
+ Args
+ fname: Driver filename to scan
+ """
+ with open(fname, encoding='utf-8') as inf:
+ try:
+ buff = inf.read()
+ except UnicodeDecodeError:
+ # This seems to happen on older Python versions
+ print("Skipping file '%s' due to unicode error" % fname)
+ return
+
+ # The following re will search for driver names declared as
+ # U_BOOT_DRIVER(driver_name)
+ drivers = re.findall(r'U_BOOT_DRIVER\((.*)\)', buff)
+
+ for driver in drivers:
+ self._drivers[driver] = Driver(driver)
+
+ # The following re will search for driver aliases declared as
+ # DM_DRIVER_ALIAS(alias, driver_name)
+ driver_aliases = re.findall(
+ r'DM_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)',
+ buff)
+
+ for alias in driver_aliases: # pragma: no cover
+ if len(alias) != 2:
+ continue
+ self._driver_aliases[alias[1]] = alias[0]
+
+ def scan_drivers(self):
+ """Scan the driver folders to build a list of driver names and aliases
+
+ This procedure will populate self._drivers and self._driver_aliases
+ """
+ for (dirpath, _, filenames) in os.walk(self._basedir):
+ for fname in filenames:
+ if not fname.endswith('.c'):
+ continue
+ self.scan_driver(dirpath + '/' + fname)
+
+ for fname in self._drivers_additional:
+ if not isinstance(fname, str) or len(fname) == 0:
+ continue
+ if fname[0] == '/':
+ self.scan_driver(fname)
+ else:
+ self.scan_driver(self._basedir + '/' + fname)
"""
import collections
+import glob
import os
import struct
-import sys
-import tempfile
import unittest
-from dtoc import dtb_platdata
-from dtb_platdata import conv_name_to_c
-from dtb_platdata import get_compat_name
from dtb_platdata import get_value
from dtb_platdata import tab_to
+from dtoc import dtb_platdata
from dtoc import fdt
from dtoc import fdt_util
+from dtoc.src_scan import conv_name_to_c
+from dtoc.src_scan import get_compat_name
from patman import test_util
from patman import tools
-our_path = os.path.dirname(os.path.realpath(__file__))
+OUR_PATH = os.path.dirname(os.path.realpath(__file__))
HEADER = '''/*
* DO NOT MODIFY
*
- * This file was generated by dtoc from a .dtb (device tree binary) file.
+ * Defines the structs used to hold devicetree data.
+ * This was generated by dtoc from a .dtb (device tree binary) file.
*/
#include <stdbool.h>
C_HEADER = '''/*
* DO NOT MODIFY
*
- * This file was generated by dtoc from a .dtb (device tree binary) file.
+ * Declares the U_BOOT_DRIVER() records and platform data.
+ * This was generated by dtoc from a .dtb (device tree binary) file.
*/
-/* Allow use of U_BOOT_DEVICE() in this file */
-#define DT_PLATDATA_C
+/* Allow use of U_BOOT_DRVINFO() in this file */
+#define DT_PLAT_C
#include <common.h>
#include <dm.h>
#include <dt-structs.h>
'''
-C_EMPTY_POPULATE_PHANDLE_DATA = '''void dm_populate_phandle_data(void) {
-}
-'''
-
+# This is a test so is allowed to access private things in the module it is
+# testing
+# pylint: disable=W0212
def get_dtb_file(dts_fname, capture_stderr=False):
"""Compile a .dts file to a .dtb
Args:
- dts_fname: Filename of .dts file in the current directory
- capture_stderr: True to capture and discard stderr output
+ dts_fname (str): Filename of .dts file in the current directory
+ capture_stderr (bool): True to capture and discard stderr output
Returns:
- Filename of compiled file in output directory
+ str: Filename of compiled file in output directory
"""
- return fdt_util.EnsureCompiled(os.path.join(our_path, dts_fname),
+ return fdt_util.EnsureCompiled(os.path.join(OUR_PATH, dts_fname),
capture_stderr=capture_stderr)
@classmethod
def tearDownClass(cls):
- tools._RemoveOutputDir()
+ tools.FinaliseOutputDir()
- def _WritePythonString(self, fname, data):
+ @staticmethod
+ def _write_python_string(fname, data):
"""Write a string with tabs expanded as done in this Python file
Args:
- fname: Filename to write to
- data: Raw string to convert
+ fname (str): Filename to write to
+ data (str): Raw string to convert
"""
data = data.replace('\t', '\\t')
- with open(fname, 'w') as fd:
- fd.write(data)
+ with open(fname, 'w') as fout:
+ fout.write(data)
- def _CheckStrings(self, expected, actual):
+ def _check_strings(self, expected, actual):
"""Check that a string matches its expected value
If the strings do not match, they are written to the /tmp directory in
easy comparison and update of the tests.
Args:
- expected: Expected string
- actual: Actual string
+ expected (str): Expected string
+ actual (str): Actual string
"""
if expected != actual:
- self._WritePythonString('/tmp/binman.expected', expected)
- self._WritePythonString('/tmp/binman.actual', actual)
+ self._write_python_string('/tmp/binman.expected', expected)
+ self._write_python_string('/tmp/binman.actual', actual)
print('Failures written to /tmp/binman.{expected,actual}')
- self.assertEquals(expected, actual)
+ self.assertEqual(expected, actual)
+ @staticmethod
+ def run_test(args, dtb_file, output):
+ """Run a test using dtoc
- def run_test(self, args, dtb_file, output):
- dtb_platdata.run_steps(args, dtb_file, False, output, True)
+ Args:
+ args (list of str): List of arguments for dtoc
+ dtb_file (str): Filename of .dtb file
+ output (str): Filename of output file
+ """
+ dtb_platdata.run_steps(args, dtb_file, False, output, [], True)
def test_name(self):
"""Test conversion of device tree names to C identifiers"""
prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1', 'third'])
node = Node({'compatible': prop})
self.assertEqual((['rockchip_rk3399_sdhci_5_1',
- 'arasan_sdhci_5_1', 'third']),
+ 'arasan_sdhci_5_1', 'third']),
get_compat_name(node))
def test_empty_file(self):
self.run_test(['platdata'], dtb_file, output)
with open(output) as infile:
lines = infile.read().splitlines()
- self.assertEqual(C_HEADER.splitlines() + [''] +
- C_EMPTY_POPULATE_PHANDLE_DATA.splitlines(), lines)
+ self.assertEqual(C_HEADER.splitlines() + [''], lines)
- def test_simple(self):
- """Test output from some simple nodes with various types of data"""
- dtb_file = get_dtb_file('dtoc_test_simple.dts')
- output = tools.GetOutputFilename('output')
- self.run_test(['struct'], dtb_file, output)
- with open(output) as infile:
- data = infile.read()
- self._CheckStrings(HEADER + '''
+ struct_text = HEADER + '''
struct dtd_sandbox_i2c_test {
};
struct dtd_sandbox_pmic_test {
\tconst char *\tstringarray[3];
\tconst char *\tstringval;
};
-struct dtd_sandbox_spl_test_2 {
-};
-''', data)
+'''
- self.run_test(['platdata'], dtb_file, output)
- with open(output) as infile:
- data = infile.read()
- self._CheckStrings(C_HEADER + '''
+ platdata_text = C_HEADER + '''
/* Node /i2c@0 index 0 */
static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = {
};
-U_BOOT_DEVICE(i2c_at_0) = {
+U_BOOT_DRVINFO(i2c_at_0) = {
\t.name\t\t= "sandbox_i2c_test",
\t.plat\t= &dtv_i2c_at_0,
\t.plat_size\t= sizeof(dtv_i2c_at_0),
\t.low_power\t\t= true,
\t.reg\t\t\t= {0x9, 0x0},
};
-U_BOOT_DEVICE(pmic_at_9) = {
+U_BOOT_DRVINFO(pmic_at_9) = {
\t.name\t\t= "sandbox_pmic_test",
\t.plat\t= &dtv_pmic_at_9,
\t.plat_size\t= sizeof(dtv_pmic_at_9),
\t.stringarray\t\t= {"multi-word", "message", ""},
\t.stringval\t\t= "message",
};
-U_BOOT_DEVICE(spl_test) = {
+U_BOOT_DRVINFO(spl_test) = {
\t.name\t\t= "sandbox_spl_test",
\t.plat\t= &dtv_spl_test,
\t.plat_size\t= sizeof(dtv_spl_test),
\t.stringarray\t\t= {"another", "multi-word", "message"},
\t.stringval\t\t= "message2",
};
-U_BOOT_DEVICE(spl_test2) = {
+U_BOOT_DRVINFO(spl_test2) = {
\t.name\t\t= "sandbox_spl_test",
\t.plat\t= &dtv_spl_test2,
\t.plat_size\t= sizeof(dtv_spl_test2),
\t\t0x0},
\t.stringarray\t\t= {"one", "", ""},
};
-U_BOOT_DEVICE(spl_test3) = {
+U_BOOT_DRVINFO(spl_test3) = {
\t.name\t\t= "sandbox_spl_test",
\t.plat\t= &dtv_spl_test3,
\t.plat_size\t= sizeof(dtv_spl_test3),
\t.parent_idx\t= -1,
};
-/* Node /spl-test4 index 5 */
-static struct dtd_sandbox_spl_test_2 dtv_spl_test4 = {
-};
-U_BOOT_DEVICE(spl_test4) = {
-\t.name\t\t= "sandbox_spl_test_2",
-\t.plat\t= &dtv_spl_test4,
-\t.plat_size\t= sizeof(dtv_spl_test4),
-\t.parent_idx\t= -1,
-};
+'''
-''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
+ def test_simple(self):
+ """Test output from some simple nodes with various types of data"""
+ dtb_file = get_dtb_file('dtoc_test_simple.dts')
+ output = tools.GetOutputFilename('output')
+ self.run_test(['struct'], dtb_file, output)
+ with open(output) as infile:
+ data = infile.read()
+
+ self._check_strings(self.struct_text, data)
+
+ self.run_test(['platdata'], dtb_file, output)
+ with open(output) as infile:
+ data = infile.read()
+
+ self._check_strings(self.platdata_text, data)
+
+ # Try the 'all' command
+ self.run_test(['all'], dtb_file, output)
+ data = tools.ReadFile(output, binary=False)
+ self._check_strings(self.platdata_text + self.struct_text, data)
def test_driver_alias(self):
"""Test output from a device tree file with a driver alias"""
self.run_test(['struct'], dtb_file, output)
with open(output) as infile:
data = infile.read()
- self._CheckStrings(HEADER + '''
+ self._check_strings(HEADER + '''
struct dtd_sandbox_gpio {
\tconst char *\tgpio_bank_name;
\tbool\t\tgpio_controller;
self.run_test(['platdata'], dtb_file, output)
with open(output) as infile:
data = infile.read()
- self._CheckStrings(C_HEADER + '''
+ self._check_strings(C_HEADER + '''
/* Node /gpios@0 index 0 */
static struct dtd_sandbox_gpio dtv_gpios_at_0 = {
\t.gpio_bank_name\t\t= "a",
\t.gpio_controller\t= true,
\t.sandbox_gpio_count\t= 0x14,
};
-U_BOOT_DEVICE(gpios_at_0) = {
+U_BOOT_DRVINFO(gpios_at_0) = {
\t.name\t\t= "sandbox_gpio",
\t.plat\t= &dtv_gpios_at_0,
\t.plat_size\t= sizeof(dtv_gpios_at_0),
\t.parent_idx\t= -1,
};
-void dm_populate_phandle_data(void) {
-}
''', data)
def test_invalid_driver(self):
"""Test output from a device tree file with an invalid driver"""
dtb_file = get_dtb_file('dtoc_test_invalid_driver.dts')
output = tools.GetOutputFilename('output')
- with test_util.capture_sys_output() as (stdout, stderr):
- dtb_platdata.run_steps(['struct'], dtb_file, False, output)
+ with test_util.capture_sys_output() as _:
+ dtb_platdata.run_steps(['struct'], dtb_file, False, output, [])
with open(output) as infile:
data = infile.read()
- self._CheckStrings(HEADER + '''
+ self._check_strings(HEADER + '''
struct dtd_invalid {
};
''', data)
- with test_util.capture_sys_output() as (stdout, stderr):
- dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
+ with test_util.capture_sys_output() as _:
+ dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [])
with open(output) as infile:
data = infile.read()
- self._CheckStrings(C_HEADER + '''
+ self._check_strings(C_HEADER + '''
/* Node /spl-test index 0 */
static struct dtd_invalid dtv_spl_test = {
};
-U_BOOT_DEVICE(spl_test) = {
+U_BOOT_DRVINFO(spl_test) = {
\t.name\t\t= "invalid",
\t.plat\t= &dtv_spl_test,
\t.plat_size\t= sizeof(dtv_spl_test),
\t.parent_idx\t= -1,
};
-void dm_populate_phandle_data(void) {
-}
''', data)
def test_phandle(self):
self.run_test(['struct'], dtb_file, output)
with open(output) as infile:
data = infile.read()
- self._CheckStrings(HEADER + '''
+ self._check_strings(HEADER + '''
struct dtd_source {
\tstruct phandle_2_arg clocks[4];
};
self.run_test(['platdata'], dtb_file, output)
with open(output) as infile:
data = infile.read()
- self._CheckStrings(C_HEADER + '''
+ self._check_strings(C_HEADER + '''
/* Node /phandle2-target index 0 */
static struct dtd_target dtv_phandle2_target = {
\t.intval\t\t\t= 0x1,
};
-U_BOOT_DEVICE(phandle2_target) = {
+U_BOOT_DRVINFO(phandle2_target) = {
\t.name\t\t= "target",
\t.plat\t= &dtv_phandle2_target,
\t.plat_size\t= sizeof(dtv_phandle2_target),
static struct dtd_target dtv_phandle3_target = {
\t.intval\t\t\t= 0x2,
};
-U_BOOT_DEVICE(phandle3_target) = {
+U_BOOT_DRVINFO(phandle3_target) = {
\t.name\t\t= "target",
\t.plat\t= &dtv_phandle3_target,
\t.plat_size\t= sizeof(dtv_phandle3_target),
\t.parent_idx\t= -1,
};
-/* Node /phandle-target index 4 */
-static struct dtd_target dtv_phandle_target = {
-\t.intval\t\t\t= 0x0,
-};
-U_BOOT_DEVICE(phandle_target) = {
-\t.name\t\t= "target",
-\t.plat\t= &dtv_phandle_target,
-\t.plat_size\t= sizeof(dtv_phandle_target),
-\t.parent_idx\t= -1,
-};
-
/* Node /phandle-source index 2 */
static struct dtd_source dtv_phandle_source = {
\t.clocks\t\t\t= {
\t\t\t{1, {12, 13}},
\t\t\t{4, {}},},
};
-U_BOOT_DEVICE(phandle_source) = {
+U_BOOT_DRVINFO(phandle_source) = {
\t.name\t\t= "source",
\t.plat\t= &dtv_phandle_source,
\t.plat_size\t= sizeof(dtv_phandle_source),
\t.clocks\t\t\t= {
\t\t\t{4, {}},},
};
-U_BOOT_DEVICE(phandle_source2) = {
+U_BOOT_DRVINFO(phandle_source2) = {
\t.name\t\t= "source",
\t.plat\t= &dtv_phandle_source2,
\t.plat_size\t= sizeof(dtv_phandle_source2),
\t.parent_idx\t= -1,
};
-void dm_populate_phandle_data(void) {
-}
+/* Node /phandle-target index 4 */
+static struct dtd_target dtv_phandle_target = {
+\t.intval\t\t\t= 0x0,
+};
+U_BOOT_DRVINFO(phandle_target) = {
+\t.name\t\t= "target",
+\t.plat\t= &dtv_phandle_target,
+\t.plat_size\t= sizeof(dtv_phandle_target),
+\t.parent_idx\t= -1,
+};
+
''', data)
def test_phandle_single(self):
self.run_test(['struct'], dtb_file, output)
with open(output) as infile:
data = infile.read()
- self._CheckStrings(HEADER + '''
+ self._check_strings(HEADER + '''
struct dtd_source {
\tstruct phandle_0_arg clocks[1];
};
self.run_test(['platdata'], dtb_file, output)
with open(output) as infile:
data = infile.read()
- self._CheckStrings(C_HEADER + '''
-/* Node /phandle-target index 1 */
-static struct dtd_target dtv_phandle_target = {
-};
-U_BOOT_DEVICE(phandle_target) = {
-\t.name\t\t= "target",
-\t.plat\t= &dtv_phandle_target,
-\t.plat_size\t= sizeof(dtv_phandle_target),
-\t.parent_idx\t= -1,
-};
-
+ self._check_strings(C_HEADER + '''
/* Node /phandle-source2 index 0 */
static struct dtd_source dtv_phandle_source2 = {
\t.clocks\t\t\t= {
\t\t\t{1, {}},},
};
-U_BOOT_DEVICE(phandle_source2) = {
+U_BOOT_DRVINFO(phandle_source2) = {
\t.name\t\t= "source",
\t.plat\t= &dtv_phandle_source2,
\t.plat_size\t= sizeof(dtv_phandle_source2),
\t.parent_idx\t= -1,
};
-void dm_populate_phandle_data(void) {
-}
+/* Node /phandle-target index 1 */
+static struct dtd_target dtv_phandle_target = {
+};
+U_BOOT_DRVINFO(phandle_target) = {
+\t.name\t\t= "target",
+\t.plat\t= &dtv_phandle_target,
+\t.plat_size\t= sizeof(dtv_phandle_target),
+\t.parent_idx\t= -1,
+};
+
''', data)
def test_phandle_cd_gpio(self):
"""Test that phandle targets are generated when unsing cd-gpios"""
dtb_file = get_dtb_file('dtoc_test_phandle_cd_gpios.dts')
output = tools.GetOutputFilename('output')
- dtb_platdata.run_steps(['platdata'], dtb_file, False, output, True)
+ dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [], True)
with open(output) as infile:
data = infile.read()
- self._CheckStrings(C_HEADER + '''
+ self._check_strings(C_HEADER + '''
/* Node /phandle2-target index 0 */
static struct dtd_target dtv_phandle2_target = {
\t.intval\t\t\t= 0x1,
};
-U_BOOT_DEVICE(phandle2_target) = {
+U_BOOT_DRVINFO(phandle2_target) = {
\t.name\t\t= "target",
\t.plat\t= &dtv_phandle2_target,
\t.plat_size\t= sizeof(dtv_phandle2_target),
static struct dtd_target dtv_phandle3_target = {
\t.intval\t\t\t= 0x2,
};
-U_BOOT_DEVICE(phandle3_target) = {
+U_BOOT_DRVINFO(phandle3_target) = {
\t.name\t\t= "target",
\t.plat\t= &dtv_phandle3_target,
\t.plat_size\t= sizeof(dtv_phandle3_target),
\t.parent_idx\t= -1,
};
-/* Node /phandle-target index 4 */
-static struct dtd_target dtv_phandle_target = {
-\t.intval\t\t\t= 0x0,
-};
-U_BOOT_DEVICE(phandle_target) = {
-\t.name\t\t= "target",
-\t.plat\t= &dtv_phandle_target,
-\t.plat_size\t= sizeof(dtv_phandle_target),
-\t.parent_idx\t= -1,
-};
-
/* Node /phandle-source index 2 */
static struct dtd_source dtv_phandle_source = {
\t.cd_gpios\t\t= {
\t\t\t{1, {12, 13}},
\t\t\t{4, {}},},
};
-U_BOOT_DEVICE(phandle_source) = {
+U_BOOT_DRVINFO(phandle_source) = {
\t.name\t\t= "source",
\t.plat\t= &dtv_phandle_source,
\t.plat_size\t= sizeof(dtv_phandle_source),
\t.cd_gpios\t\t= {
\t\t\t{4, {}},},
};
-U_BOOT_DEVICE(phandle_source2) = {
+U_BOOT_DRVINFO(phandle_source2) = {
\t.name\t\t= "source",
\t.plat\t= &dtv_phandle_source2,
\t.plat_size\t= sizeof(dtv_phandle_source2),
\t.parent_idx\t= -1,
};
-void dm_populate_phandle_data(void) {
-}
+/* Node /phandle-target index 4 */
+static struct dtd_target dtv_phandle_target = {
+\t.intval\t\t\t= 0x0,
+};
+U_BOOT_DRVINFO(phandle_target) = {
+\t.name\t\t= "target",
+\t.plat\t= &dtv_phandle_target,
+\t.plat_size\t= sizeof(dtv_phandle_target),
+\t.parent_idx\t= -1,
+};
+
''', data)
def test_phandle_bad(self):
dtb_file = get_dtb_file('dtoc_test_phandle_bad.dts',
capture_stderr=True)
output = tools.GetOutputFilename('output')
- with self.assertRaises(ValueError) as e:
+ with self.assertRaises(ValueError) as exc:
self.run_test(['struct'], dtb_file, output)
self.assertIn("Cannot parse 'clocks' in node 'phandle-source'",
- str(e.exception))
+ str(exc.exception))
def test_phandle_bad2(self):
"""Test a phandle target missing its #*-cells property"""
dtb_file = get_dtb_file('dtoc_test_phandle_bad2.dts',
capture_stderr=True)
output = tools.GetOutputFilename('output')
- with self.assertRaises(ValueError) as e:
+ with self.assertRaises(ValueError) as exc:
self.run_test(['struct'], dtb_file, output)
self.assertIn("Node 'phandle-target' has no cells property",
- str(e.exception))
+ str(exc.exception))
def test_addresses64(self):
"""Test output from a node with a 'reg' property with na=2, ns=2"""
self.run_test(['struct'], dtb_file, output)
with open(output) as infile:
data = infile.read()
- self._CheckStrings(HEADER + '''
+ self._check_strings(HEADER + '''
struct dtd_test1 {
\tfdt64_t\t\treg[2];
};
self.run_test(['platdata'], dtb_file, output)
with open(output) as infile:
data = infile.read()
- self._CheckStrings(C_HEADER + '''
+ self._check_strings(C_HEADER + '''
/* Node /test1 index 0 */
static struct dtd_test1 dtv_test1 = {
\t.reg\t\t\t= {0x1234, 0x5678},
};
-U_BOOT_DEVICE(test1) = {
+U_BOOT_DRVINFO(test1) = {
\t.name\t\t= "test1",
\t.plat\t= &dtv_test1,
\t.plat_size\t= sizeof(dtv_test1),
static struct dtd_test2 dtv_test2 = {
\t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654},
};
-U_BOOT_DEVICE(test2) = {
+U_BOOT_DRVINFO(test2) = {
\t.name\t\t= "test2",
\t.plat\t= &dtv_test2,
\t.plat_size\t= sizeof(dtv_test2),
static struct dtd_test3 dtv_test3 = {
\t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654, 0x2, 0x3},
};
-U_BOOT_DEVICE(test3) = {
+U_BOOT_DRVINFO(test3) = {
\t.name\t\t= "test3",
\t.plat\t= &dtv_test3,
\t.plat_size\t= sizeof(dtv_test3),
\t.parent_idx\t= -1,
};
-''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
+''', data)
def test_addresses32(self):
"""Test output from a node with a 'reg' property with na=1, ns=1"""
self.run_test(['struct'], dtb_file, output)
with open(output) as infile:
data = infile.read()
- self._CheckStrings(HEADER + '''
+ self._check_strings(HEADER + '''
struct dtd_test1 {
\tfdt32_t\t\treg[2];
};
self.run_test(['platdata'], dtb_file, output)
with open(output) as infile:
data = infile.read()
- self._CheckStrings(C_HEADER + '''
+ self._check_strings(C_HEADER + '''
/* Node /test1 index 0 */
static struct dtd_test1 dtv_test1 = {
\t.reg\t\t\t= {0x1234, 0x5678},
};
-U_BOOT_DEVICE(test1) = {
+U_BOOT_DRVINFO(test1) = {
\t.name\t\t= "test1",
\t.plat\t= &dtv_test1,
\t.plat_size\t= sizeof(dtv_test1),
static struct dtd_test2 dtv_test2 = {
\t.reg\t\t\t= {0x12345678, 0x98765432, 0x2, 0x3},
};
-U_BOOT_DEVICE(test2) = {
+U_BOOT_DRVINFO(test2) = {
\t.name\t\t= "test2",
\t.plat\t= &dtv_test2,
\t.plat_size\t= sizeof(dtv_test2),
\t.parent_idx\t= -1,
};
-''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
+''', data)
def test_addresses64_32(self):
"""Test output from a node with a 'reg' property with na=2, ns=1"""
self.run_test(['struct'], dtb_file, output)
with open(output) as infile:
data = infile.read()
- self._CheckStrings(HEADER + '''
+ self._check_strings(HEADER + '''
struct dtd_test1 {
\tfdt64_t\t\treg[2];
};
self.run_test(['platdata'], dtb_file, output)
with open(output) as infile:
data = infile.read()
- self._CheckStrings(C_HEADER + '''
+ self._check_strings(C_HEADER + '''
/* Node /test1 index 0 */
static struct dtd_test1 dtv_test1 = {
\t.reg\t\t\t= {0x123400000000, 0x5678},
};
-U_BOOT_DEVICE(test1) = {
+U_BOOT_DRVINFO(test1) = {
\t.name\t\t= "test1",
\t.plat\t= &dtv_test1,
\t.plat_size\t= sizeof(dtv_test1),
static struct dtd_test2 dtv_test2 = {
\t.reg\t\t\t= {0x1234567890123456, 0x98765432},
};
-U_BOOT_DEVICE(test2) = {
+U_BOOT_DRVINFO(test2) = {
\t.name\t\t= "test2",
\t.plat\t= &dtv_test2,
\t.plat_size\t= sizeof(dtv_test2),
static struct dtd_test3 dtv_test3 = {
\t.reg\t\t\t= {0x1234567890123456, 0x98765432, 0x2, 0x3},
};
-U_BOOT_DEVICE(test3) = {
+U_BOOT_DRVINFO(test3) = {
\t.name\t\t= "test3",
\t.plat\t= &dtv_test3,
\t.plat_size\t= sizeof(dtv_test3),
\t.parent_idx\t= -1,
};
-''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
+''', data)
def test_addresses32_64(self):
"""Test output from a node with a 'reg' property with na=1, ns=2"""
self.run_test(['struct'], dtb_file, output)
with open(output) as infile:
data = infile.read()
- self._CheckStrings(HEADER + '''
+ self._check_strings(HEADER + '''
struct dtd_test1 {
\tfdt64_t\t\treg[2];
};
self.run_test(['platdata'], dtb_file, output)
with open(output) as infile:
data = infile.read()
- self._CheckStrings(C_HEADER + '''
+ self._check_strings(C_HEADER + '''
/* Node /test1 index 0 */
static struct dtd_test1 dtv_test1 = {
\t.reg\t\t\t= {0x1234, 0x567800000000},
};
-U_BOOT_DEVICE(test1) = {
+U_BOOT_DRVINFO(test1) = {
\t.name\t\t= "test1",
\t.plat\t= &dtv_test1,
\t.plat_size\t= sizeof(dtv_test1),
static struct dtd_test2 dtv_test2 = {
\t.reg\t\t\t= {0x12345678, 0x9876543210987654},
};
-U_BOOT_DEVICE(test2) = {
+U_BOOT_DRVINFO(test2) = {
\t.name\t\t= "test2",
\t.plat\t= &dtv_test2,
\t.plat_size\t= sizeof(dtv_test2),
static struct dtd_test3 dtv_test3 = {
\t.reg\t\t\t= {0x12345678, 0x9876543210987654, 0x2, 0x3},
};
-U_BOOT_DEVICE(test3) = {
+U_BOOT_DRVINFO(test3) = {
\t.name\t\t= "test3",
\t.plat\t= &dtv_test3,
\t.plat_size\t= sizeof(dtv_test3),
\t.parent_idx\t= -1,
};
-''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
+''', data)
def test_bad_reg(self):
"""Test that a reg property with an invalid type generates an error"""
# Capture stderr since dtc will emit warnings for this file
dtb_file = get_dtb_file('dtoc_test_bad_reg.dts', capture_stderr=True)
output = tools.GetOutputFilename('output')
- with self.assertRaises(ValueError) as e:
+ with self.assertRaises(ValueError) as exc:
self.run_test(['struct'], dtb_file, output)
self.assertIn("Node 'spl-test' reg property is not an int",
- str(e.exception))
+ str(exc.exception))
def test_bad_reg2(self):
"""Test that a reg property with an invalid cell count is detected"""
# Capture stderr since dtc will emit warnings for this file
dtb_file = get_dtb_file('dtoc_test_bad_reg2.dts', capture_stderr=True)
output = tools.GetOutputFilename('output')
- with self.assertRaises(ValueError) as e:
+ with self.assertRaises(ValueError) as exc:
self.run_test(['struct'], dtb_file, output)
- self.assertIn("Node 'spl-test' reg property has 3 cells which is not a multiple of na + ns = 1 + 1)",
- str(e.exception))
+ self.assertIn(
+ "Node 'spl-test' reg property has 3 cells which is not a multiple of na + ns = 1 + 1)",
+ str(exc.exception))
def test_add_prop(self):
"""Test that a subequent node can add a new property to a struct"""
self.run_test(['struct'], dtb_file, output)
with open(output) as infile:
data = infile.read()
- self._CheckStrings(HEADER + '''
+ self._check_strings(HEADER + '''
struct dtd_sandbox_spl_test {
\tfdt32_t\t\tintarray;
\tfdt32_t\t\tintval;
self.run_test(['platdata'], dtb_file, output)
with open(output) as infile:
data = infile.read()
- self._CheckStrings(C_HEADER + '''
+ self._check_strings(C_HEADER + '''
/* Node /spl-test index 0 */
static struct dtd_sandbox_spl_test dtv_spl_test = {
\t.intval\t\t\t= 0x1,
};
-U_BOOT_DEVICE(spl_test) = {
+U_BOOT_DRVINFO(spl_test) = {
\t.name\t\t= "sandbox_spl_test",
\t.plat\t= &dtv_spl_test,
\t.plat_size\t= sizeof(dtv_spl_test),
static struct dtd_sandbox_spl_test dtv_spl_test2 = {
\t.intarray\t\t= 0x5,
};
-U_BOOT_DEVICE(spl_test2) = {
+U_BOOT_DRVINFO(spl_test2) = {
\t.name\t\t= "sandbox_spl_test",
\t.plat\t= &dtv_spl_test2,
\t.plat_size\t= sizeof(dtv_spl_test2),
\t.parent_idx\t= -1,
};
-''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
+''', data)
- def testStdout(self):
+ def test_stdout(self):
"""Test output to stdout"""
dtb_file = get_dtb_file('dtoc_test_simple.dts')
- with test_util.capture_sys_output() as (stdout, stderr):
- self.run_test(['struct'], dtb_file, '-')
+ with test_util.capture_sys_output() as (stdout, _):
+ self.run_test(['struct'], dtb_file, None)
+ self._check_strings(self.struct_text, stdout.getvalue())
- def testNoCommand(self):
+ def test_multi_to_file(self):
+ """Test output of multiple pieces to a single file"""
+ dtb_file = get_dtb_file('dtoc_test_simple.dts')
+ output = tools.GetOutputFilename('output')
+ self.run_test(['all'], dtb_file, output)
+ data = tools.ReadFile(output, binary=False)
+ self._check_strings(self.platdata_text + self.struct_text, data)
+
+ def test_no_command(self):
"""Test running dtoc without a command"""
- with self.assertRaises(ValueError) as e:
+ with self.assertRaises(ValueError) as exc:
self.run_test([], '', '')
self.assertIn("Please specify a command: struct, platdata",
- str(e.exception))
+ str(exc.exception))
- def testBadCommand(self):
+ def test_bad_command(self):
"""Test running dtoc with an invalid command"""
dtb_file = get_dtb_file('dtoc_test_simple.dts')
output = tools.GetOutputFilename('output')
- with self.assertRaises(ValueError) as e:
+ with self.assertRaises(ValueError) as exc:
self.run_test(['invalid-cmd'], dtb_file, output)
- self.assertIn("Unknown command 'invalid-cmd': (use: struct, platdata)",
- str(e.exception))
-
- def testScanDrivers(self):
- """Test running dtoc with additional drivers to scan"""
- dtb_file = get_dtb_file('dtoc_test_simple.dts')
- output = tools.GetOutputFilename('output')
- with test_util.capture_sys_output() as (stdout, stderr):
- dtb_platdata.run_steps(['struct'], dtb_file, False, output, True,
- [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx'])
-
- def testUnicodeError(self):
- """Test running dtoc with an invalid unicode file
+ self.assertIn("Unknown command 'invalid-cmd': (use: platdata, struct)",
+ str(exc.exception))
+
+ def test_output_conflict(self):
+ """Test a conflict between and output dirs and output file"""
+ with self.assertRaises(ValueError) as exc:
+ dtb_platdata.run_steps(['all'], None, False, 'out', ['cdir'], True)
+ self.assertIn("Must specify either output or output_dirs, not both",
+ str(exc.exception))
+
+ def test_output_dirs(self):
+ """Test outputting files to a directory"""
+ # Remove the directory so that files from other tests are not there
+ tools._RemoveOutputDir()
+ tools.PrepareOutputDir(None)
- To be able to perform this test without adding a weird text file which
- would produce issues when using checkpatch.pl or patman, generate the
- file at runtime and then process it.
- """
+ # This should create the .dts and .dtb in the output directory
dtb_file = get_dtb_file('dtoc_test_simple.dts')
- output = tools.GetOutputFilename('output')
- driver_fn = '/tmp/' + next(tempfile._get_candidate_names())
- with open(driver_fn, 'wb+') as df:
- df.write(b'\x81')
-
- with test_util.capture_sys_output() as (stdout, stderr):
- dtb_platdata.run_steps(['struct'], dtb_file, False, output, True,
- [driver_fn])
+ outdir = tools.GetOutputDir()
+ fnames = glob.glob(outdir + '/*')
+ self.assertEqual(2, len(fnames))
+
+ dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], True)
+ fnames = glob.glob(outdir + '/*')
+ self.assertEqual(4, len(fnames))
+
+ leafs = set(os.path.basename(fname) for fname in fnames)
+ self.assertEqual(
+ {'dt-structs-gen.h', 'source.dts', 'dt-plat.c', 'source.dtb'},
+ leafs)
--- /dev/null
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2020 Google LLC
+#
+
+"""Tests for the src_scan module
+
+This includes unit tests for scanning of the source code
+"""
+
+import os
+import shutil
+import tempfile
+import unittest
+from unittest import mock
+
+from dtoc import src_scan
+from patman import test_util
+from patman import tools
+
+# This is a test so is allowed to access private things in the module it is
+# testing
+# pylint: disable=W0212
+
+class TestSrcScan(unittest.TestCase):
+ """Tests for src_scan"""
+ @classmethod
+ def setUpClass(cls):
+ tools.PrepareOutputDir(None)
+
+ @classmethod
+ def tearDownClass(cls):
+ tools.FinaliseOutputDir()
+
+ def test_simple(self):
+ """Simple test of scanning drivers"""
+ scan = src_scan.Scanner(None, True, None)
+ scan.scan_drivers()
+ self.assertIn('sandbox_gpio', scan._drivers)
+ self.assertIn('sandbox_gpio_alias', scan._driver_aliases)
+ self.assertEqual('sandbox_gpio',
+ scan._driver_aliases['sandbox_gpio_alias'])
+ self.assertNotIn('sandbox_gpio_alias2', scan._driver_aliases)
+
+ def test_additional(self):
+ """Test with additional drivers to scan"""
+ scan = src_scan.Scanner(
+ None, True, [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx'])
+ scan.scan_drivers()
+ self.assertIn('sandbox_gpio_alias2', scan._driver_aliases)
+ self.assertEqual('sandbox_gpio',
+ scan._driver_aliases['sandbox_gpio_alias2'])
+
+ def test_unicode_error(self):
+ """Test running dtoc with an invalid unicode file
+
+ To be able to perform this test without adding a weird text file which
+ would produce issues when using checkpatch.pl or patman, generate the
+ file at runtime and then process it.
+ """
+ driver_fn = '/tmp/' + next(tempfile._get_candidate_names())
+ with open(driver_fn, 'wb+') as fout:
+ fout.write(b'\x81')
+
+ scan = src_scan.Scanner(None, True, [driver_fn])
+ with test_util.capture_sys_output() as (stdout, _):
+ scan.scan_drivers()
+ self.assertRegex(stdout.getvalue(),
+ r"Skipping file '.*' due to unicode error\s*")
+
+ def test_driver(self):
+ """Test the Driver class"""
+ drv1 = src_scan.Driver('fred')
+ drv2 = src_scan.Driver('mary')
+ drv3 = src_scan.Driver('fred')
+ self.assertEqual("Driver(name='fred')", str(drv1))
+ self.assertEqual(drv1, drv3)
+ self.assertNotEqual(drv1, drv2)
+ self.assertNotEqual(drv2, drv3)
+
+ def test_scan_dirs(self):
+ """Test scanning of source directories"""
+ def add_file(fname):
+ pathname = os.path.join(indir, fname)
+ dirname = os.path.dirname(pathname)
+ os.makedirs(dirname, exist_ok=True)
+ tools.WriteFile(pathname, '', binary=False)
+ fname_list.append(pathname)
+
+ try:
+ indir = tempfile.mkdtemp(prefix='dtoc.')
+
+ fname_list = []
+ add_file('fname.c')
+ add_file('dir/fname2.c')
+
+ # Mock out scan_driver and check that it is called with the
+ # expected files
+ with mock.patch.object(src_scan.Scanner, "scan_driver") as mocked:
+ scan = src_scan.Scanner(indir, True, None)
+ scan.scan_drivers()
+ self.assertEqual(2, len(mocked.mock_calls))
+ self.assertEqual(mock.call(fname_list[0]),
+ mocked.mock_calls[0])
+ self.assertEqual(mock.call(fname_list[1]),
+ mocked.mock_calls[1])
+ finally:
+ shutil.rmtree(indir)
"""
return os.path.join(outdir, fname)
+def GetOutputDir():
+ """Return the current output directory
+
+ Returns:
+ str: The output directory
+ """
+ return outdir
+
def _FinaliseForTest():
"""Remove the output directory (for use by tests)"""
global outdir