mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCHv2 1/3] of: Add of_device_enable_and_register functions
@ 2014-11-03 12:31 Teresa Gámez
  2014-11-03 12:31 ` [PATCHv2 2/3] ARM: am335x: Add register of boot devices Teresa Gámez
  2014-11-03 12:31 ` [PATCHv2 3/3] ARM: am335x: phyCORE-AM335x: Create new dts for MLO Teresa Gámez
  0 siblings, 2 replies; 4+ messages in thread
From: Teresa Gámez @ 2014-11-03 12:31 UTC (permalink / raw)
  To: barebox

Function to enable and register a disabled device.
The devices can be registered using the
device node with of_device_enable_and_register() or
with the device node name/path by using the
of_device_enable_and_register_by_name() function.

Signed-off-by: Teresa Gámez <t.gamez@phytec.de>
---
v2:
- renamed functions

 drivers/of/platform.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 include/of.h          | 14 ++++++++++++++
 2 files changed, 57 insertions(+)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index c417cfd..92ef534 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -197,6 +197,49 @@ static struct device_d *of_platform_device_create(struct device_node *np,
 	return NULL;
 }
 
+/**
+ * of_device_enable_and_register - Enable and register device
+ * @np: pointer to node to enable create device for
+ *
+ * Returns pointer to created platform device, or NULL if a device was not
+ * registered. Unavailable devices will not get registered.
+ */
+struct device_d *of_device_enable_and_register(struct device_node *np)
+{
+	struct device_d *dev;
+
+	of_device_enable(np);
+
+	dev = of_platform_device_create(np, NULL);
+	if (!dev)
+		return NULL;
+
+	return dev;
+}
+EXPORT_SYMBOL(of_device_enable_and_register);
+
+/**
+ * of_device_enable_and_register_by_name - Enable and register device by name
+ * @name: name or path of the device node
+ *
+ * Returns pointer to created platform device, or NULL if a device was not
+ * registered. Unavailable devices will not get registered.
+ */
+struct device_d *of_device_enable_and_register_by_name(const char *name)
+{
+	struct device_node *node;
+
+	node = of_find_node_by_name(NULL, name);
+	if (!node)
+		node = of_find_node_by_path(name);
+
+	if (!node)
+		return NULL;
+
+	return of_device_enable_and_register(node);
+}
+EXPORT_SYMBOL(of_device_enable_and_register_by_name);
+
 #ifdef CONFIG_ARM_AMBA
 static struct device_d *of_amba_device_create(struct device_node *np)
 {
diff --git a/include/of.h b/include/of.h
index 29694a9..7b93c58 100644
--- a/include/of.h
+++ b/include/of.h
@@ -227,6 +227,8 @@ extern int of_platform_populate(struct device_node *root,
 				const struct of_device_id *matches,
 				struct device_d *parent);
 extern struct device_d *of_find_device_by_node(struct device_node *np);
+extern struct device_d *of_device_enable_and_register(struct device_node *np);
+extern struct device_d *of_device_enable_and_register_by_name(const char *name);
 
 struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node);
 int of_parse_partitions(struct cdev *cdev, struct device_node *node);
@@ -582,6 +584,18 @@ static inline struct device_d *of_find_device_by_node(struct device_node *np)
 {
 	return NULL;
 }
+
+static inline struct device_d *of_device_enable_and_register(
+				struct device_node *np)
+{
+	return NULL;
+}
+
+static inline struct device_d *of_device_enable_and_register_by_name(
+				const char *name)
+{
+	return NULL;
+}
 #endif
 
 #define for_each_node_by_name(dn, name) \
-- 
1.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCHv2 2/3] ARM: am335x: Add register of boot devices
  2014-11-03 12:31 [PATCHv2 1/3] of: Add of_device_enable_and_register functions Teresa Gámez
@ 2014-11-03 12:31 ` Teresa Gámez
  2014-11-03 14:45   ` Sascha Hauer
  2014-11-03 12:31 ` [PATCHv2 3/3] ARM: am335x: phyCORE-AM335x: Create new dts for MLO Teresa Gámez
  1 sibling, 1 reply; 4+ messages in thread
From: Teresa Gámez @ 2014-11-03 12:31 UTC (permalink / raw)
  To: barebox

Add support for registering disabled boot devices from oftree.
Creating a device tree with all bootable devices disabled, makes
it possible to only enable and register the devices needed to
load the next stage bootloader.

Signed-off-by: Teresa Gámez <t.gamez@phytec.de>
---
v2:
- updated of funcion name

 arch/arm/mach-omap/am33xx_generic.c              | 31 ++++++++++++++++++++++++
 arch/arm/mach-omap/include/mach/am33xx-generic.h |  1 +
 2 files changed, 32 insertions(+)

diff --git a/arch/arm/mach-omap/am33xx_generic.c b/arch/arm/mach-omap/am33xx_generic.c
index f293134..b561575 100644
--- a/arch/arm/mach-omap/am33xx_generic.c
+++ b/arch/arm/mach-omap/am33xx_generic.c
@@ -428,3 +428,34 @@ void am335x_sdram_init(int ioctrl, const struct am33xx_cmd_control *cmd_ctrl,
 
 	am33xx_config_sdram(emif_regs);
 }
+
+int am33xx_of_register_bootdevice(void)
+{
+	struct device_d *dev;
+
+	switch (bootsource_get()) {
+	case BOOTSOURCE_MMC:
+		if (bootsource_get_instance() == 0)
+			dev = of_device_enable_and_register_by_name("mmc@48060000");
+		else
+			dev = of_device_enable_and_register_by_name("mmc@481d8000");
+		break;
+	case BOOTSOURCE_NAND:
+		dev = of_device_enable_and_register_by_name("gpmc@50000000");
+		break;
+	case BOOTSOURCE_SPI:
+		dev = of_device_enable_and_register_by_name("spi@48030000");
+		break;
+	default:
+		/* Use nand fallback */
+		dev = of_device_enable_and_register_by_name("gpmc@50000000");
+		break;
+	}
+
+	if (!dev) {
+		printf("Unable to register boot device\n");
+		return -ENODEV;
+	}
+
+	return 0;
+}
diff --git a/arch/arm/mach-omap/include/mach/am33xx-generic.h b/arch/arm/mach-omap/include/mach/am33xx-generic.h
index 6c85d51..7312061 100644
--- a/arch/arm/mach-omap/include/mach/am33xx-generic.h
+++ b/arch/arm/mach-omap/include/mach/am33xx-generic.h
@@ -33,5 +33,6 @@ void __noreturn am33xx_reset_cpu(unsigned long addr);
 void am33xx_enable_per_clocks(void);
 int am33xx_init(void);
 int am33xx_devices_init(void);
+int am33xx_of_register_bootdevice(void);
 
 #endif /* __MACH_AM33XX_GENERIC_H */
-- 
1.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCHv2 3/3] ARM: am335x: phyCORE-AM335x: Create new dts for MLO
  2014-11-03 12:31 [PATCHv2 1/3] of: Add of_device_enable_and_register functions Teresa Gámez
  2014-11-03 12:31 ` [PATCHv2 2/3] ARM: am335x: Add register of boot devices Teresa Gámez
@ 2014-11-03 12:31 ` Teresa Gámez
  1 sibling, 0 replies; 4+ messages in thread
From: Teresa Gámez @ 2014-11-03 12:31 UTC (permalink / raw)
  To: barebox

Use a mlo device tree with all bootable devices disabled.
The bootsource is checked in the board file and only the
needed device is enabled and registered.

Signed-off-by: Teresa Gámez <t.gamez@phytec.de>
---
 arch/arm/boards/phytec-phycore-am335x/board.c    |  3 +++
 arch/arm/boards/phytec-phycore-am335x/lowlevel.c |  3 ++-
 arch/arm/dts/Makefile                            |  2 +-
 arch/arm/dts/am335x-phytec-phycore-som-mlo.dts   | 28 ++++++++++++++++++++++++
 4 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm/dts/am335x-phytec-phycore-som-mlo.dts

diff --git a/arch/arm/boards/phytec-phycore-am335x/board.c b/arch/arm/boards/phytec-phycore-am335x/board.c
index 64e3904..a72cebd 100644
--- a/arch/arm/boards/phytec-phycore-am335x/board.c
+++ b/arch/arm/boards/phytec-phycore-am335x/board.c
@@ -83,6 +83,9 @@ static int pcm051_devices_init(void)
 		xloadslots, ARRAY_SIZE(xloadslots));
 	am33xx_bbu_nand_register_handler("nand", "/dev/nand0.barebox.bb");
 
+	if (IS_ENABLED(CONFIG_SHELL_NONE))
+		return am33xx_of_register_bootdevice();
+
 	return 0;
 }
 device_initcall(pcm051_devices_init);
diff --git a/arch/arm/boards/phytec-phycore-am335x/lowlevel.c b/arch/arm/boards/phytec-phycore-am335x/lowlevel.c
index 55cc667..5ab8b5b 100644
--- a/arch/arm/boards/phytec-phycore-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-phycore-am335x/lowlevel.c
@@ -118,6 +118,7 @@ struct pcm051_sdram_timings timings[] = {
 };
 
 extern char __dtb_am335x_phytec_phycore_som_start[];
+extern char __dtb_am335x_phytec_phycore_som_mlo_start[];
 extern char __dtb_am335x_phytec_phycore_som_no_spi_start[];
 
 /**
@@ -154,7 +155,7 @@ static noinline void pcm051_board_init(int sdram)
 	omap_uart_lowlevel_init((void *)AM33XX_UART0_BASE);
 	putc_ll('>');
 
-	fdt = __dtb_am335x_phytec_phycore_som_start - get_runtime_offset();
+	fdt = __dtb_am335x_phytec_phycore_som_mlo_start - get_runtime_offset();
 
 	am335x_barebox_entry(fdt);
 }
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index a9e9ee7..d8160fe 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -26,7 +26,7 @@ pbl-dtb-$(CONFIG_MACH_NVIDIA_JETSON) += tegra124-jetson-tk1.dtb.o
 pbl-dtb-$(CONFIG_MACH_PCA100) += imx27-phytec-phycard-s-rdk-bb.dtb.o
 pbl-dtb-$(CONFIG_MACH_PCAAXL3) += imx6q-phytec-pbaa03.dtb.o
 pbl-dtb-$(CONFIG_MACH_PCM038) += imx27-phytec-phycore-rdk.dtb.o
-pbl-dtb-$(CONFIG_MACH_PCM051) += am335x-phytec-phycore-som.dtb.o am335x-phytec-phycore-som-no-spi.dtb.o
+pbl-dtb-$(CONFIG_MACH_PCM051) += am335x-phytec-phycore-som.dtb.o am335x-phytec-phycore-som-no-spi.dtb.o am335x-phytec-phycore-som-mlo.dtb.o
 pbl-dtb-$(CONFIG_MACH_PFLA03) += am335x-phytec-phyflex.dtb.o
 pbl-dtb-$(CONFIG_MACH_PHYTEC_PFLA02) += imx6s-phytec-pbab01.dtb.o imx6dl-phytec-pbab01.dtb.o imx6q-phytec-pbab01.dtb.o
 pbl-dtb-$(CONFIG_MACH_PLATHOME_OPENBLOCKS_AX3) += armada-xp-openblocks-ax3-4-bb.dtb.o
diff --git a/arch/arm/dts/am335x-phytec-phycore-som-mlo.dts b/arch/arm/dts/am335x-phytec-phycore-som-mlo.dts
new file mode 100644
index 0000000..4117439
--- /dev/null
+++ b/arch/arm/dts/am335x-phytec-phycore-som-mlo.dts
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2014 Teresa Gámez <t.gamez@phytec.de> PHYTEC Messtechnik GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/dts-v1/;
+
+#include "am33xx.dtsi"
+#include "am335x-phytec-phycore-som.dtsi"
+
+/ {
+	model = "Phytec phyCORE AM335x";
+	compatible = "phytec,phycore-am335x-som", "ti,am33xx";
+};
+
+/* Keep all boosources disabled, we enable and register them
+ * later while booting.
+ */
+
+&mmc1 {
+	status = "disabled";
+};
+
+&gpmc {
+	status = "disabled";
+};
-- 
1.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCHv2 2/3] ARM: am335x: Add register of boot devices
  2014-11-03 12:31 ` [PATCHv2 2/3] ARM: am335x: Add register of boot devices Teresa Gámez
@ 2014-11-03 14:45   ` Sascha Hauer
  0 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2014-11-03 14:45 UTC (permalink / raw)
  To: Teresa Gámez; +Cc: barebox

On Mon, Nov 03, 2014 at 01:31:53PM +0100, Teresa Gámez wrote:
> Add support for registering disabled boot devices from oftree.
> Creating a device tree with all bootable devices disabled, makes
> it possible to only enable and register the devices needed to
> load the next stage bootloader.
> 
> Signed-off-by: Teresa Gámez <t.gamez@phytec.de>

Applied all, thanks

Sascha

> ---
> v2:
> - updated of funcion name
> 
>  arch/arm/mach-omap/am33xx_generic.c              | 31 ++++++++++++++++++++++++
>  arch/arm/mach-omap/include/mach/am33xx-generic.h |  1 +
>  2 files changed, 32 insertions(+)
> 
> diff --git a/arch/arm/mach-omap/am33xx_generic.c b/arch/arm/mach-omap/am33xx_generic.c
> index f293134..b561575 100644
> --- a/arch/arm/mach-omap/am33xx_generic.c
> +++ b/arch/arm/mach-omap/am33xx_generic.c
> @@ -428,3 +428,34 @@ void am335x_sdram_init(int ioctrl, const struct am33xx_cmd_control *cmd_ctrl,
>  
>  	am33xx_config_sdram(emif_regs);
>  }
> +
> +int am33xx_of_register_bootdevice(void)
> +{
> +	struct device_d *dev;
> +
> +	switch (bootsource_get()) {
> +	case BOOTSOURCE_MMC:
> +		if (bootsource_get_instance() == 0)
> +			dev = of_device_enable_and_register_by_name("mmc@48060000");
> +		else
> +			dev = of_device_enable_and_register_by_name("mmc@481d8000");
> +		break;
> +	case BOOTSOURCE_NAND:
> +		dev = of_device_enable_and_register_by_name("gpmc@50000000");
> +		break;
> +	case BOOTSOURCE_SPI:
> +		dev = of_device_enable_and_register_by_name("spi@48030000");
> +		break;
> +	default:
> +		/* Use nand fallback */
> +		dev = of_device_enable_and_register_by_name("gpmc@50000000");
> +		break;
> +	}
> +
> +	if (!dev) {
> +		printf("Unable to register boot device\n");
> +		return -ENODEV;
> +	}
> +
> +	return 0;
> +}
> diff --git a/arch/arm/mach-omap/include/mach/am33xx-generic.h b/arch/arm/mach-omap/include/mach/am33xx-generic.h
> index 6c85d51..7312061 100644
> --- a/arch/arm/mach-omap/include/mach/am33xx-generic.h
> +++ b/arch/arm/mach-omap/include/mach/am33xx-generic.h
> @@ -33,5 +33,6 @@ void __noreturn am33xx_reset_cpu(unsigned long addr);
>  void am33xx_enable_per_clocks(void);
>  int am33xx_init(void);
>  int am33xx_devices_init(void);
> +int am33xx_of_register_bootdevice(void);
>  
>  #endif /* __MACH_AM33XX_GENERIC_H */
> -- 
> 1.9.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-11-03 14:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-03 12:31 [PATCHv2 1/3] of: Add of_device_enable_and_register functions Teresa Gámez
2014-11-03 12:31 ` [PATCHv2 2/3] ARM: am335x: Add register of boot devices Teresa Gámez
2014-11-03 14:45   ` Sascha Hauer
2014-11-03 12:31 ` [PATCHv2 3/3] ARM: am335x: phyCORE-AM335x: Create new dts for MLO Teresa Gámez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox