mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/3] ARM: dts: AM335x: Add dummy i2c nodes
@ 2017-11-02 16:39 Daniel Schultz
  2017-11-02 16:39 ` [PATCH v2 2/3] common: oftree: Add autoenable functionality Daniel Schultz
  2017-11-02 16:39 ` [PATCH v2 3/3] ARM: phytec-som-am335x: Add autoenable Daniel Schultz
  0 siblings, 2 replies; 4+ messages in thread
From: Daniel Schultz @ 2017-11-02 16:39 UTC (permalink / raw)
  To: barebox

These i2c nodes are needed for autoenable of i2c clients, because
the autoenable API searches for device tree nodes to get the client
address.

Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
---
 arch/arm/dts/am335x-phytec-phycore-som.dtsi | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/arch/arm/dts/am335x-phytec-phycore-som.dtsi b/arch/arm/dts/am335x-phytec-phycore-som.dtsi
index dbc6424..cf2eef3 100644
--- a/arch/arm/dts/am335x-phytec-phycore-som.dtsi
+++ b/arch/arm/dts/am335x-phytec-phycore-som.dtsi
@@ -164,6 +164,20 @@
 		pagesize = <32>;
 		reg = <0x52>;
 	};
+
+	/* The following i2c nodes are for the autoenable */
+	i2c_tmp102: temp@4b {
+		compatible = "ti,tmp102";
+		reg = <0x4b>;
+		status = "disabled";
+	};
+
+	i2c_rtc: rtc@68 {
+		compatible = "rv4162";
+		reg = <0x68>;
+		status = "disabled";
+	};
+
 };
 
 &mmc1 {
-- 
2.7.4


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

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

* [PATCH v2 2/3] common: oftree: Add autoenable functionality
  2017-11-02 16:39 [PATCH v2 1/3] ARM: dts: AM335x: Add dummy i2c nodes Daniel Schultz
@ 2017-11-02 16:39 ` Daniel Schultz
  2017-11-03  8:47   ` Sascha Hauer
  2017-11-02 16:39 ` [PATCH v2 3/3] ARM: phytec-som-am335x: Add autoenable Daniel Schultz
  1 sibling, 1 reply; 4+ messages in thread
From: Daniel Schultz @ 2017-11-02 16:39 UTC (permalink / raw)
  To: barebox

This patch adds an API to automatically enable either hardware components
with existing device drivers or i2c clients. All functions take a device
tree path to find the hardware and will fix up the node status in the
kernel device tree, if it's accessible.

Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
---
Changes:
	v2: Moved from standalone file to oftree.c
	    Added of_device_is_available, if a driver is disabled
	    Added of_property_read_u32
	    Removed Kconfig
	    Added of_ prefix to function names
	    Renamed of_autoenable_i2c_by_path to of_autoenable_i2c_by_component

 common/oftree.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/of.h    | 14 +++++++++
 2 files changed, 106 insertions(+)

diff --git a/common/oftree.c b/common/oftree.c
index 09a4455..3b77a7e 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -11,6 +11,7 @@
 #include <getopt.h>
 #include <init.h>
 #include <boot.h>
+#include <i2c/i2c.h>
 
 #define MAX_LEVEL	32		/* how deeply nested we will go */
 
@@ -260,3 +261,94 @@ struct fdt_header *of_get_fixed_tree(struct device_node *node)
 
 	return fdt;
 }
+
+/**
+ * of_autoenable_device_by_path() - Autoenable a device by a device tree path
+ * @param path Device tree path up from the root to the device
+ * @return 0 on success, -enodev on failure. If no device found in the device
+ * tree.
+ *
+ * This function will search for a device and will enable it in the kernel
+ * device tree, if it exists and is loaded.
+ */
+int of_autoenable_device_by_path(char *path)
+{
+	struct device_d *device;
+	struct device_node *node;
+	int ret;
+
+	node = of_find_node_by_name(NULL, path);
+	if (!node)
+		node = of_find_node_by_path(path);
+
+	if (!node)
+		return -ENODEV;
+
+	device = of_find_device_by_node(node);
+	if (!device)
+		if (!of_device_is_available(node))
+			return -ENODEV;
+
+	ret = of_register_set_status_fixup(path, 1);
+	if (!ret)
+		printf("autoenabled %s\n", node->name);
+	return ret;
+}
+
+/**
+ * of_autoenable_i2c_by_component - Autoenable a i2c client by a device tree path
+ * @param path Device tree path up from the root to the i2c client
+ * @return 0 on success, -enodev on failure. If no i2c client found in the i2c
+ * device tree.
+ *
+ * This function will search for a i2c client, tries to write to the client and
+ * will enable it in the kernel device tree, if it exists and is accessible.
+ */
+int of_autoenable_i2c_by_component(char *path)
+{
+	struct device_node *node;
+	struct i2c_adapter *i2c_adapter;
+	struct i2c_msg msg;
+	char data[1] = {0x0};
+	int ret;
+	uint32_t addr;
+
+	if (!IS_ENABLED(CONFIG_I2C))
+		return -ENODEV;
+
+	node = of_find_node_by_name(NULL, path);
+	if (!node)
+		node = of_find_node_by_path(path);
+	if (!node)
+		return -ENODEV;
+	if (!node->parent)
+		return -ENODEV;
+
+	ret = of_property_read_u32(node, "reg", &addr);
+	if (ret)
+		return -ENODEV;
+
+	i2c_adapter = of_find_i2c_adapter_by_node(node->parent);
+	if (!i2c_adapter)
+		return -ENODEV;
+
+	msg.buf = data;
+	msg.addr = addr;
+	msg.len = 1;
+
+	/* Try to communicate with the i2c client */
+	ret = i2c_transfer(i2c_adapter, &msg, 1);
+	if (ret == -EREMOTEIO)
+		return -ENODEV;
+	if (ret < 1) {
+		printf("failed to autoenable i2c device on address 0x%x with %i\n",
+								addr, ret);
+		return ret;
+	}
+
+	ret = of_register_set_status_fixup(path, 1);
+	if (!ret)
+		printf("autoenabled i2c device %s\n", node->name);
+
+	return ret;
+}
diff --git a/include/of.h b/include/of.h
index 18a4232..9bdbbb5e 100644
--- a/include/of.h
+++ b/include/of.h
@@ -262,6 +262,8 @@ struct device_node *of_find_node_by_alias(struct device_node *root,
 		const char *alias);
 struct device_node *of_find_node_by_path_or_alias(struct device_node *root,
 		const char *str);
+int of_autoenable_device_by_path(char *path);
+int of_autoenable_i2c_by_component(char *path);
 #else
 static inline int of_parse_partitions(struct cdev *cdev,
 					  struct device_node *node)
@@ -664,6 +666,18 @@ static inline struct device_node *of_find_node_by_path_or_alias(
 {
 	return NULL;
 }
+
+static inline int of_autoenable_i2c_by_path(char *path)
+{
+	return -ENODEV;
+}
+
+static inline int of_autoenable_i2c_by_component(char *path)
+{
+	return -ENODEV;
+}
+
+
 #endif
 
 #define for_each_node_by_name(dn, name) \
-- 
2.7.4


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

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

* [PATCH v2 3/3] ARM: phytec-som-am335x: Add autoenable
  2017-11-02 16:39 [PATCH v2 1/3] ARM: dts: AM335x: Add dummy i2c nodes Daniel Schultz
  2017-11-02 16:39 ` [PATCH v2 2/3] common: oftree: Add autoenable functionality Daniel Schultz
@ 2017-11-02 16:39 ` Daniel Schultz
  1 sibling, 0 replies; 4+ messages in thread
From: Daniel Schultz @ 2017-11-02 16:39 UTC (permalink / raw)
  To: barebox

Add autoenable for components, which can be populated on an AM335x
phyCORE SoM.

Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
---
Changes:
	v2: Created Phytec AM335x Kconfig PHYTEC_SOM_AM335X_OF_AUTOENABLE
	    Changed function names

 arch/arm/boards/phytec-som-am335x/Kconfig | 13 +++++++++++++
 arch/arm/boards/phytec-som-am335x/board.c | 13 +++++++++++++
 arch/arm/mach-omap/Kconfig                |  2 ++
 3 files changed, 28 insertions(+)
 create mode 100644 arch/arm/boards/phytec-som-am335x/Kconfig

diff --git a/arch/arm/boards/phytec-som-am335x/Kconfig b/arch/arm/boards/phytec-som-am335x/Kconfig
new file mode 100644
index 0000000..52fa723
--- /dev/null
+++ b/arch/arm/boards/phytec-som-am335x/Kconfig
@@ -0,0 +1,13 @@
+
+if MACH_PHYTEC_SOM_AM335X
+
+config PHYTEC_SOM_AM335X_OF_AUTOENABLE
+	bool
+	prompt "Autoenable of components"
+	help
+	  Say Y to unlock an API for automatically enable either hardware
+	  components with existing device drivers or i2c clients. All functions
+	  take a device tree path to find the hardware and will fix up the node
+	  status in the kernel device tree, if it's accessible.
+
+endif
diff --git a/arch/arm/boards/phytec-som-am335x/board.c b/arch/arm/boards/phytec-som-am335x/board.c
index 9f74981..0e9bf5f 100644
--- a/arch/arm/boards/phytec-som-am335x/board.c
+++ b/arch/arm/boards/phytec-som-am335x/board.c
@@ -135,6 +135,19 @@ static int physom_devices_init(void)
 			}
 	}
 
+	if (IS_ENABLED(PHYTEC_SOM_AM335X_OF_AUTOENABLE)) {
+		/* Enable NAND */
+		of_autoenable_device_by_path("/ocp/gpmc@50000000");
+		/* Enable eMMC */
+		of_autoenable_device_by_path("/ocp/mmc@481d8000");
+		/* Enable SPI NOR */
+		of_autoenable_device_by_path("/ocp/spi@48030000/m25p80@0");
+
+		of_autoenable_i2c_by_component("/ocp/i2c@44e0b000/temp@4b");
+		of_autoenable_i2c_by_component("/ocp/i2c@44e0b000/eeprom@52");
+		of_autoenable_i2c_by_component("/ocp/i2c@44e0b000/rtc@68");
+	}
+
 	if (IS_ENABLED(CONFIG_SHELL_NONE))
 		return am33xx_of_register_bootdevice();
 
diff --git a/arch/arm/mach-omap/Kconfig b/arch/arm/mach-omap/Kconfig
index 9c41741..e8fc4b8 100644
--- a/arch/arm/mach-omap/Kconfig
+++ b/arch/arm/mach-omap/Kconfig
@@ -192,6 +192,8 @@ config MACH_VSCOM_BALTOS
 
 endif
 
+source arch/arm/boards/phytec-som-am335x/Kconfig
+
 choice
 	prompt "Select OMAP board"
 	depends on !OMAP_MULTI_BOARDS
-- 
2.7.4


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

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

* Re: [PATCH v2 2/3] common: oftree: Add autoenable functionality
  2017-11-02 16:39 ` [PATCH v2 2/3] common: oftree: Add autoenable functionality Daniel Schultz
@ 2017-11-03  8:47   ` Sascha Hauer
  0 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2017-11-03  8:47 UTC (permalink / raw)
  To: Daniel Schultz; +Cc: barebox

On Thu, Nov 02, 2017 at 05:39:41PM +0100, Daniel Schultz wrote:
> This patch adds an API to automatically enable either hardware components
> with existing device drivers or i2c clients. All functions take a device
> tree path to find the hardware and will fix up the node status in the
> kernel device tree, if it's accessible.
> 
> Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
> ---
> Changes:
> 	v2: Moved from standalone file to oftree.c
> 	    Added of_device_is_available, if a driver is disabled
> 	    Added of_property_read_u32
> 	    Removed Kconfig
> 	    Added of_ prefix to function names
> 	    Renamed of_autoenable_i2c_by_path to of_autoenable_i2c_by_component
> 
>  common/oftree.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  include/of.h    | 14 +++++++++
>  2 files changed, 106 insertions(+)
> 
> diff --git a/common/oftree.c b/common/oftree.c
> index 09a4455..3b77a7e 100644
> --- a/common/oftree.c
> +++ b/common/oftree.c
> @@ -11,6 +11,7 @@
>  #include <getopt.h>
>  #include <init.h>
>  #include <boot.h>
> +#include <i2c/i2c.h>
>  
>  #define MAX_LEVEL	32		/* how deeply nested we will go */
>  
> @@ -260,3 +261,94 @@ struct fdt_header *of_get_fixed_tree(struct device_node *node)
>  
>  	return fdt;
>  }
> +
> +/**
> + * of_autoenable_device_by_path() - Autoenable a device by a device tree path
> + * @param path Device tree path up from the root to the device
> + * @return 0 on success, -enodev on failure. If no device found in the device
> + * tree.
> + *
> + * This function will search for a device and will enable it in the kernel
> + * device tree, if it exists and is loaded.
> + */
> +int of_autoenable_device_by_path(char *path)
> +{
> +	struct device_d *device;
> +	struct device_node *node;
> +	int ret;
> +
> +	node = of_find_node_by_name(NULL, path);
> +	if (!node)
> +		node = of_find_node_by_path(path);
> +
> +	if (!node)
> +		return -ENODEV;
> +
> +	device = of_find_device_by_node(node);
> +	if (!device)
> +		if (!of_device_is_available(node))
> +			return -ENODEV;

Is the of_find_device_by_node(node) test still necessary? In which case?

Sascha

-- 
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:[~2017-11-03  8:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-02 16:39 [PATCH v2 1/3] ARM: dts: AM335x: Add dummy i2c nodes Daniel Schultz
2017-11-02 16:39 ` [PATCH v2 2/3] common: oftree: Add autoenable functionality Daniel Schultz
2017-11-03  8:47   ` Sascha Hauer
2017-11-02 16:39 ` [PATCH v2 3/3] ARM: phytec-som-am335x: Add autoenable Daniel Schultz

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