mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/3] ARM: cfa10036: Load a different DTB depending on variants
@ 2012-12-12 14:10 Maxime Ripard
  2012-12-12 14:10 ` [PATCH 1/3] ARM: cfa10036: Add the AT24HC02 I2C EEPROM Maxime Ripard
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Maxime Ripard @ 2012-12-12 14:10 UTC (permalink / raw)
  To: barebox; +Cc: Brian Lilly

Hi,

The CFA-10036 is actually a module that can be plugged in an expansion board.

For now, there is only two of these expansion boards, the CFA-10037 and the
CFA-10049, with different features, muxing and so on.

So, at boot time, the cfa-10036 has to be aware that it runs on an expansion
board and if so, which expansion board it is currently plugged in, so that it
can load the right device tree.

This is done thanks to an eeprom found at the same address on the same bus on
the expansion boards, that holds the expansion board id, so we can know all of
this.

This patchset does exactly that. It first adds support for the AT24, and then
the needed bits to retrieve the board variants from the eeprom if any and load
the right DTB.

Thanks,
Maxime

Maxime Ripard (3):
  ARM: cfa10036: Add the AT24HC02 I2C EEPROM
  ARM: cfa10036: Retrieve the board variant from the AT24
  ARM: cfa10036: Use the board variant to load a different device tree

 arch/arm/boards/crystalfontz-cfa10036/Makefile     |    2 +-
 arch/arm/boards/crystalfontz-cfa10036/cfa10036.c   |   27 ++++++
 .../boards/crystalfontz-cfa10036/env/boot/mmc-ext3 |    4 +-
 arch/arm/boards/crystalfontz-cfa10036/hwdetect.c   |   97 ++++++++++++++++++++
 arch/arm/boards/crystalfontz-cfa10036/hwdetect.h   |   22 +++++
 arch/arm/configs/cfa10036_defconfig                |    3 +-
 arch/arm/mach-mxs/Kconfig                          |    3 +
 7 files changed, 154 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm/boards/crystalfontz-cfa10036/hwdetect.c
 create mode 100644 arch/arm/boards/crystalfontz-cfa10036/hwdetect.h

-- 
1.7.9.5


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

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

* [PATCH 1/3] ARM: cfa10036: Add the AT24HC02 I2C EEPROM
  2012-12-12 14:10 [PATCH 0/3] ARM: cfa10036: Load a different DTB depending on variants Maxime Ripard
@ 2012-12-12 14:10 ` Maxime Ripard
  2012-12-12 14:10 ` [PATCH 2/3] ARM: cfa10036: Retrieve the board variant from the AT24 Maxime Ripard
  2012-12-12 14:10 ` [PATCH 3/3] ARM: cfa10036: Use the board variant to load a different device tree Maxime Ripard
  2 siblings, 0 replies; 6+ messages in thread
From: Maxime Ripard @ 2012-12-12 14:10 UTC (permalink / raw)
  To: barebox; +Cc: Brian Lilly

This EEPROM is found on the expansion boards available for the 10036
module. Since we won't need to do anything fancy except reading/writing
from it, use bitbanging to communicate with it.

This EEPROM will hold mostly the board_id so that we can determine if
there is an expansion board plugged in and what expansion board it is.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
 arch/arm/boards/crystalfontz-cfa10036/cfa10036.c |   23 ++++++++++++++++++++++
 arch/arm/configs/cfa10036_defconfig              |    3 ++-
 arch/arm/mach-mxs/Kconfig                        |    3 +++
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c b/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
index 522d2d7..df0ead9 100644
--- a/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
+++ b/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
@@ -26,6 +26,10 @@
 #include <net.h>
 #include <sizes.h>
 
+#include <i2c/i2c.h>
+#include <i2c/i2c-gpio.h>
+#include <i2c/at24.h>
+
 #include <mach/clock.h>
 #include <mach/imx-regs.h>
 #include <mach/iomux-imx28.h>
@@ -58,6 +62,10 @@ static const uint32_t cfa10036_pads[] = {
 	SSP0_SCK | VE_3_3V | BITKEEPER(0),
 	/* MCI slot power control 1 = off */
 	PWM3_GPIO | VE_3_3V | GPIO_OUT | GPIO_VALUE(0),
+
+	/* i2c0 */
+	AUART0_TX_GPIO | VE_3_3V | PULLUP(1),
+	AUART0_RX_GPIO | VE_3_3V | PULLUP(1),
 };
 
 static struct mxs_mci_platform_data mci_pdata = {
@@ -67,6 +75,18 @@ static struct mxs_mci_platform_data mci_pdata = {
 	.f_max = 25000000,
 };
 
+static struct i2c_board_info cfa10036_i2c_devices[] = {
+	{
+		I2C_BOARD_INFO("24c02", 0x50)
+	},
+};
+
+static struct i2c_gpio_platform_data i2c_gpio_pdata = {
+	.sda_pin		= 3 * 32 + 1,
+	.scl_pin		= 3 * 32 + 0,
+	.udelay			= 5,		/* ~100 kHz */
+};
+
 static int cfa10036_mem_init(void)
 {
 	arm_add_mem_device("ram0", IMX_MEMORY_BASE, 128 * 1024 * 1024);
@@ -97,6 +117,9 @@ static int cfa10036_devices_init(void)
 	add_generic_device("ocotp", 0, NULL, IMX_OCOTP_BASE, SZ_8K,
 			   IORESOURCE_MEM, NULL);
 
+	i2c_register_board_info(0, cfa10036_i2c_devices, ARRAY_SIZE(cfa10036_i2c_devices));
+	add_generic_device_res("i2c-gpio", 0, NULL, 0, &i2c_gpio_pdata);
+
 	return 0;
 }
 device_initcall(cfa10036_devices_init);
diff --git a/arch/arm/configs/cfa10036_defconfig b/arch/arm/configs/cfa10036_defconfig
index 67a0e8f..c55d50d 100644
--- a/arch/arm/configs/cfa10036_defconfig
+++ b/arch/arm/configs/cfa10036_defconfig
@@ -11,7 +11,7 @@ CONFIG_LONGHELP=y
 CONFIG_HUSH_FANCY_PROMPT=y
 CONFIG_CMDLINE_EDITING=y
 CONFIG_AUTO_COMPLETE=y
-CONFIG_MENU=y
+CONFIG_CONSOLE_ACTIVATE_ALL=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
 CONFIG_DEFAULT_ENVIRONMENT_PATH="arch/arm/boards/crystalfontz-cfa10036/env"
 CONFIG_DEBUG_INFO=y
@@ -35,6 +35,7 @@ CONFIG_CMD_TIMEOUT=y
 CONFIG_CMD_PARTITION=y
 CONFIG_CMD_GPIO=y
 # CONFIG_SPI is not set
+CONFIG_I2C=y
 CONFIG_MCI=y
 CONFIG_MCI_STARTUP=y
 CONFIG_MCI_MXS=y
diff --git a/arch/arm/mach-mxs/Kconfig b/arch/arm/mach-mxs/Kconfig
index ff295f1..4e7e750 100644
--- a/arch/arm/mach-mxs/Kconfig
+++ b/arch/arm/mach-mxs/Kconfig
@@ -77,6 +77,9 @@ config MACH_MX28EVK
 config MACH_CFA10036
 	bool "cfa-10036"
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
+	select MXS_OCOTP
+	select I2C_GPIO
+	select EEPROM_AT24
 	help
 	  Say Y here if you are using the Crystalfontz CFA-10036 module
 
-- 
1.7.9.5


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

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

* [PATCH 2/3] ARM: cfa10036: Retrieve the board variant from the AT24
  2012-12-12 14:10 [PATCH 0/3] ARM: cfa10036: Load a different DTB depending on variants Maxime Ripard
  2012-12-12 14:10 ` [PATCH 1/3] ARM: cfa10036: Add the AT24HC02 I2C EEPROM Maxime Ripard
@ 2012-12-12 14:10 ` Maxime Ripard
  2012-12-12 16:07   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-12-12 20:52   ` Sascha Hauer
  2012-12-12 14:10 ` [PATCH 3/3] ARM: cfa10036: Use the board variant to load a different device tree Maxime Ripard
  2 siblings, 2 replies; 6+ messages in thread
From: Maxime Ripard @ 2012-12-12 14:10 UTC (permalink / raw)
  To: barebox; +Cc: Brian Lilly

The AT24 found on the expansion boards store the variant of the board it
is soldered onto.

That means that we are that way able to determine what expansion board
is currently plugged in if any. If we can't communicate with the EEPROM,
we just assume that only the CFA-10036 is there.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
 arch/arm/boards/crystalfontz-cfa10036/Makefile   |    2 +-
 arch/arm/boards/crystalfontz-cfa10036/cfa10036.c |    4 +
 arch/arm/boards/crystalfontz-cfa10036/hwdetect.c |   97 ++++++++++++++++++++++
 arch/arm/boards/crystalfontz-cfa10036/hwdetect.h |   22 +++++
 4 files changed, 124 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/boards/crystalfontz-cfa10036/hwdetect.c
 create mode 100644 arch/arm/boards/crystalfontz-cfa10036/hwdetect.h

diff --git a/arch/arm/boards/crystalfontz-cfa10036/Makefile b/arch/arm/boards/crystalfontz-cfa10036/Makefile
index 75f0020..7e8d5e2 100644
--- a/arch/arm/boards/crystalfontz-cfa10036/Makefile
+++ b/arch/arm/boards/crystalfontz-cfa10036/Makefile
@@ -1 +1 @@
-obj-y += cfa10036.o
+obj-y += cfa10036.o hwdetect.o
diff --git a/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c b/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
index df0ead9..b59dbab 100644
--- a/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
+++ b/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
@@ -42,6 +42,8 @@
 
 #include <generated/mach-types.h>
 
+#include "hwdetect.h"
+
 /* setup the CPU card internal signals */
 static const uint32_t cfa10036_pads[] = {
 	/* duart */
@@ -120,6 +122,8 @@ static int cfa10036_devices_init(void)
 	i2c_register_board_info(0, cfa10036_i2c_devices, ARRAY_SIZE(cfa10036_i2c_devices));
 	add_generic_device_res("i2c-gpio", 0, NULL, 0, &i2c_gpio_pdata);
 
+	cfa10036_detect_hw();
+
 	return 0;
 }
 device_initcall(cfa10036_devices_init);
diff --git a/arch/arm/boards/crystalfontz-cfa10036/hwdetect.c b/arch/arm/boards/crystalfontz-cfa10036/hwdetect.c
new file mode 100644
index 0000000..535a75f
--- /dev/null
+++ b/arch/arm/boards/crystalfontz-cfa10036/hwdetect.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2012 Free Electrons
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ *
+ */
+
+#include <common.h>
+
+#include <environment.h>
+#include <fcntl.h>
+#include <fs.h>
+#include <libbb.h>
+
+#include <asm/armlinux.h>
+
+enum board_type {
+	BOARD_ID_CFA10036 = 0,
+	BOARD_ID_CFA10037 = 1,
+	BOARD_ID_CFA10049 = 2,
+};
+
+struct cfa_eeprom_info {
+	u8 board_id;
+}__attribute__ ((packed));
+
+static int cfa10036_read_eeprom(const char *file, struct cfa_eeprom_info *info)
+{
+	int fd;
+	int ret;
+
+	fd = open(file, O_RDONLY);
+	if (fd < 0) {
+		ret = fd;
+		goto err;
+	}
+
+	ret = read_full(fd, info, sizeof(*info));
+	if (ret < 0)
+		goto err_open;
+
+	if (ret < sizeof(*info)) {
+		ret =  -EINVAL;
+		goto err_open;
+	}
+
+	ret = 0;
+
+err_open:
+	close(fd);
+err:
+	if (ret)
+		pr_err("can not read eeprom %s (%s)\n", file, strerror(ret));
+	return ret;
+}
+
+void cfa10036_detect_hw(void)
+{
+	enum board_type cfa_type;
+	struct cfa_eeprom_info info;
+	char *board_name;
+	int ret;
+
+	ret = cfa10036_read_eeprom("/dev/eeprom0", &info);
+	if (ret)
+		cfa_type = BOARD_ID_CFA10036;
+	else
+		cfa_type = info.board_id;
+
+	switch (cfa_type) {
+	case BOARD_ID_CFA10036:
+		board_name = "cfa10036";
+		break;
+	case BOARD_ID_CFA10037:
+		board_name = "cfa10037";
+		break;
+	case BOARD_ID_CFA10049:
+		board_name = "cfa10049";
+		break;
+	default:
+		pr_err("Board ID not supported\n");
+		return;
+	}
+
+	setenv("cfa_variant", board_name);
+	export("cfa_variant");
+	pr_info("Booting on a CFA10036 with %s\n", board_name);
+}
diff --git a/arch/arm/boards/crystalfontz-cfa10036/hwdetect.h b/arch/arm/boards/crystalfontz-cfa10036/hwdetect.h
new file mode 100644
index 0000000..2a5330e
--- /dev/null
+++ b/arch/arm/boards/crystalfontz-cfa10036/hwdetect.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2012 Free Electrons
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ *
+ */
+
+#ifndef __HWDETECT_H__
+#define __HWDETECT_H__
+
+void cfa10036_detect_hw(void);
+
+#endif /* __HWDETECT_H__ */
-- 
1.7.9.5


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

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

* [PATCH 3/3] ARM: cfa10036: Use the board variant to load a different device tree
  2012-12-12 14:10 [PATCH 0/3] ARM: cfa10036: Load a different DTB depending on variants Maxime Ripard
  2012-12-12 14:10 ` [PATCH 1/3] ARM: cfa10036: Add the AT24HC02 I2C EEPROM Maxime Ripard
  2012-12-12 14:10 ` [PATCH 2/3] ARM: cfa10036: Retrieve the board variant from the AT24 Maxime Ripard
@ 2012-12-12 14:10 ` Maxime Ripard
  2 siblings, 0 replies; 6+ messages in thread
From: Maxime Ripard @ 2012-12-12 14:10 UTC (permalink / raw)
  To: barebox; +Cc: Brian Lilly

The board variant found on the AT24 EEPROM holds the variant ID that we
can use to identify which expansion board we are running on and thus
which device tree to load and pass to the kernel.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
 .../boards/crystalfontz-cfa10036/env/boot/mmc-ext3 |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boards/crystalfontz-cfa10036/env/boot/mmc-ext3 b/arch/arm/boards/crystalfontz-cfa10036/env/boot/mmc-ext3
index b2325af..78177cf 100644
--- a/arch/arm/boards/crystalfontz-cfa10036/env/boot/mmc-ext3
+++ b/arch/arm/boards/crystalfontz-cfa10036/env/boot/mmc-ext3
@@ -5,6 +5,6 @@ if [ "$1" = menu ]; then
 	exit
 fi
 
-global.bootm.image="/mnt/disk0.1/zImage-cfa10036"
-global.bootm.oftree="/mnt/disk0.1/oftree-cfa10036"
+global.bootm.image="/mnt/disk0.1/zImage-${global.hostname}"
+global.bootm.oftree="/mnt/disk0.1/oftree-${cfa_variant}"
 global.linux.bootargs.dyn.root="root=/dev/mmcblk0p3 rootfstype=ext3 rootwait"
-- 
1.7.9.5


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

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

* Re: [PATCH 2/3] ARM: cfa10036: Retrieve the board variant from the AT24
  2012-12-12 14:10 ` [PATCH 2/3] ARM: cfa10036: Retrieve the board variant from the AT24 Maxime Ripard
@ 2012-12-12 16:07   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-12-12 20:52   ` Sascha Hauer
  1 sibling, 0 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-12-12 16:07 UTC (permalink / raw)
  To: Maxime Ripard; +Cc: barebox, Brian Lilly

On 15:10 Wed 12 Dec     , Maxime Ripard wrote:
> The AT24 found on the expansion boards store the variant of the board it
> is soldered onto.
> 
> That means that we are that way able to determine what expansion board
> is currently plugged in if any. If we can't communicate with the EEPROM,
> we just assume that only the CFA-10036 is there.
> 
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> ---
>  arch/arm/boards/crystalfontz-cfa10036/Makefile   |    2 +-
>  arch/arm/boards/crystalfontz-cfa10036/cfa10036.c |    4 +
>  arch/arm/boards/crystalfontz-cfa10036/hwdetect.c |   97 ++++++++++++++++++++++
>  arch/arm/boards/crystalfontz-cfa10036/hwdetect.h |   22 +++++
>  4 files changed, 124 insertions(+), 1 deletion(-)
>  create mode 100644 arch/arm/boards/crystalfontz-cfa10036/hwdetect.c
>  create mode 100644 arch/arm/boards/crystalfontz-cfa10036/hwdetect.h
> 
> diff --git a/arch/arm/boards/crystalfontz-cfa10036/Makefile b/arch/arm/boards/crystalfontz-cfa10036/Makefile
> index 75f0020..7e8d5e2 100644
> --- a/arch/arm/boards/crystalfontz-cfa10036/Makefile
> +++ b/arch/arm/boards/crystalfontz-cfa10036/Makefile
> @@ -1 +1 @@
> -obj-y += cfa10036.o
> +obj-y += cfa10036.o hwdetect.o
> diff --git a/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c b/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
> index df0ead9..b59dbab 100644
> --- a/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
> +++ b/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
> @@ -42,6 +42,8 @@
>  
>  #include <generated/mach-types.h>
>  
> +#include "hwdetect.h"
> +
>  /* setup the CPU card internal signals */
>  static const uint32_t cfa10036_pads[] = {
>  	/* duart */
> @@ -120,6 +122,8 @@ static int cfa10036_devices_init(void)
>  	i2c_register_board_info(0, cfa10036_i2c_devices, ARRAY_SIZE(cfa10036_i2c_devices));
>  	add_generic_device_res("i2c-gpio", 0, NULL, 0, &i2c_gpio_pdata);
>  
> +	cfa10036_detect_hw();
> +
>  	return 0;
>  }
>  device_initcall(cfa10036_devices_init);
> diff --git a/arch/arm/boards/crystalfontz-cfa10036/hwdetect.c b/arch/arm/boards/crystalfontz-cfa10036/hwdetect.c
> new file mode 100644
> index 0000000..535a75f
> --- /dev/null
> +++ b/arch/arm/boards/crystalfontz-cfa10036/hwdetect.c
> @@ -0,0 +1,97 @@
> +/*
> + * Copyright (C) 2012 Free Electrons
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + *
> + */
> +
> +#include <common.h>
> +
> +#include <environment.h>
> +#include <fcntl.h>
> +#include <fs.h>
> +#include <libbb.h>
> +
> +#include <asm/armlinux.h>
> +
> +enum board_type {
> +	BOARD_ID_CFA10036 = 0,
> +	BOARD_ID_CFA10037 = 1,
> +	BOARD_ID_CFA10049 = 2,
> +};
> +
> +struct cfa_eeprom_info {
> +	u8 board_id;
> +}__attribute__ ((packed));
> +
> +static int cfa10036_read_eeprom(const char *file, struct cfa_eeprom_info *info)
> +{
> +	int fd;
> +	int ret;
> +
> +	fd = open(file, O_RDONLY);
> +	if (fd < 0) {
> +		ret = fd;
> +		goto err;
> +	}
> +
> +	ret = read_full(fd, info, sizeof(*info));
> +	if (ret < 0)
> +		goto err_open;
> +
> +	if (ret < sizeof(*info)) {
> +		ret =  -EINVAL;
> +		goto err_open;
> +	}
> +
> +	ret = 0;
> +
> +err_open:
> +	close(fd);
> +err:
> +	if (ret)
> +		pr_err("can not read eeprom %s (%s)\n", file, strerror(ret));
> +	return ret;
> +}
> +
> +void cfa10036_detect_hw(void)
> +{
> +	enum board_type cfa_type;
> +	struct cfa_eeprom_info info;
> +	char *board_name;
> +	int ret;
> +
> +	ret = cfa10036_read_eeprom("/dev/eeprom0", &info);
> +	if (ret)
> +		cfa_type = BOARD_ID_CFA10036;
> +	else
> +		cfa_type = info.board_id;
> +
> +	switch (cfa_type) {
> +	case BOARD_ID_CFA10036:
> +		board_name = "cfa10036";
> +		break;
> +	case BOARD_ID_CFA10037:
> +		board_name = "cfa10037";
> +		break;
> +	case BOARD_ID_CFA10049:
> +		board_name = "cfa10049";
> +		break;
> +	default:
> +		pr_err("Board ID not supported\n");
create a device as done on sam9x5ek will be more nive


Best Regards,
J.

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

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

* Re: [PATCH 2/3] ARM: cfa10036: Retrieve the board variant from the AT24
  2012-12-12 14:10 ` [PATCH 2/3] ARM: cfa10036: Retrieve the board variant from the AT24 Maxime Ripard
  2012-12-12 16:07   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-12-12 20:52   ` Sascha Hauer
  1 sibling, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-12-12 20:52 UTC (permalink / raw)
  To: Maxime Ripard; +Cc: barebox, Brian Lilly

On Wed, Dec 12, 2012 at 03:10:55PM +0100, Maxime Ripard wrote:
> The AT24 found on the expansion boards store the variant of the board it
> is soldered onto.
> 
> That means that we are that way able to determine what expansion board
> is currently plugged in if any. If we can't communicate with the EEPROM,
> we just assume that only the CFA-10036 is there.
> 
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> ---
>  arch/arm/boards/crystalfontz-cfa10036/Makefile   |    2 +-
>  arch/arm/boards/crystalfontz-cfa10036/cfa10036.c |    4 +
>  arch/arm/boards/crystalfontz-cfa10036/hwdetect.c |   97 ++++++++++++++++++++++
>  arch/arm/boards/crystalfontz-cfa10036/hwdetect.h |   22 +++++
>  4 files changed, 124 insertions(+), 1 deletion(-)
>  create mode 100644 arch/arm/boards/crystalfontz-cfa10036/hwdetect.c
>  create mode 100644 arch/arm/boards/crystalfontz-cfa10036/hwdetect.h
> 
> diff --git a/arch/arm/boards/crystalfontz-cfa10036/Makefile b/arch/arm/boards/crystalfontz-cfa10036/Makefile
> index 75f0020..7e8d5e2 100644
> --- a/arch/arm/boards/crystalfontz-cfa10036/Makefile
> +++ b/arch/arm/boards/crystalfontz-cfa10036/Makefile
> @@ -1 +1 @@
> -obj-y += cfa10036.o
> +obj-y += cfa10036.o hwdetect.o
> diff --git a/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c b/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
> index df0ead9..b59dbab 100644
> --- a/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
> +++ b/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
> @@ -42,6 +42,8 @@
>  
>  #include <generated/mach-types.h>
>  
> +#include "hwdetect.h"
> +
>  /* setup the CPU card internal signals */
>  static const uint32_t cfa10036_pads[] = {
>  	/* duart */
> @@ -120,6 +122,8 @@ static int cfa10036_devices_init(void)
>  	i2c_register_board_info(0, cfa10036_i2c_devices, ARRAY_SIZE(cfa10036_i2c_devices));
>  	add_generic_device_res("i2c-gpio", 0, NULL, 0, &i2c_gpio_pdata);
>  
> +	cfa10036_detect_hw();
> +
>  	return 0;
>  }
>  device_initcall(cfa10036_devices_init);
> diff --git a/arch/arm/boards/crystalfontz-cfa10036/hwdetect.c b/arch/arm/boards/crystalfontz-cfa10036/hwdetect.c
> new file mode 100644
> index 0000000..535a75f
> --- /dev/null
> +++ b/arch/arm/boards/crystalfontz-cfa10036/hwdetect.c
> @@ -0,0 +1,97 @@
> +/*
> + * Copyright (C) 2012 Free Electrons
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + *
> + */
> +
> +#include <common.h>
> +
> +#include <environment.h>
> +#include <fcntl.h>
> +#include <fs.h>
> +#include <libbb.h>
> +
> +#include <asm/armlinux.h>
> +
> +enum board_type {
> +	BOARD_ID_CFA10036 = 0,
> +	BOARD_ID_CFA10037 = 1,
> +	BOARD_ID_CFA10049 = 2,
> +};
> +
> +struct cfa_eeprom_info {
> +	u8 board_id;
> +}__attribute__ ((packed));
> +
> +static int cfa10036_read_eeprom(const char *file, struct cfa_eeprom_info *info)
> +{
> +	int fd;
> +	int ret;
> +
> +	fd = open(file, O_RDONLY);
> +	if (fd < 0) {
> +		ret = fd;
> +		goto err;
> +	}
> +
> +	ret = read_full(fd, info, sizeof(*info));
> +	if (ret < 0)
> +		goto err_open;
> +
> +	if (ret < sizeof(*info)) {
> +		ret =  -EINVAL;
> +		goto err_open;
> +	}

This will never happen. read_full makes that sure.

> +
> +	ret = 0;
> +
> +err_open:
> +	close(fd);
> +err:
> +	if (ret)
> +		pr_err("can not read eeprom %s (%s)\n", file, strerror(ret));
> +	return ret;
> +}
> +
> +void cfa10036_detect_hw(void)
> +{
> +	enum board_type cfa_type;
> +	struct cfa_eeprom_info info;
> +	char *board_name;
> +	int ret;
> +
> +	ret = cfa10036_read_eeprom("/dev/eeprom0", &info);
> +	if (ret)
> +		cfa_type = BOARD_ID_CFA10036;
> +	else
> +		cfa_type = info.board_id;
> +
> +	switch (cfa_type) {
> +	case BOARD_ID_CFA10036:
> +		board_name = "cfa10036";
> +		break;
> +	case BOARD_ID_CFA10037:
> +		board_name = "cfa10037";
> +		break;
> +	case BOARD_ID_CFA10049:
> +		board_name = "cfa10049";
> +		break;
> +	default:
> +		pr_err("Board ID not supported\n");
> +		return;
> +	}
> +
> +	setenv("cfa_variant", board_name);
> +	export("cfa_variant");

I rather suggest:

	globalvar_add_simple("board.variant");
	setenv("global.board.variant", board_name);

(the name is debatable)

This way makes sure that the variable is available in every context
and shows up in 'devinfo global' which I think is a good place to
collect this kind of global information.

Additionally a:

BAREBOX_MAGICVAR_NAMED(global_board_variant, global.board.variant, "The board variant")

gives you the chance to describe the meaning of this variable.

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] 6+ messages in thread

end of thread, other threads:[~2012-12-12 20:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-12 14:10 [PATCH 0/3] ARM: cfa10036: Load a different DTB depending on variants Maxime Ripard
2012-12-12 14:10 ` [PATCH 1/3] ARM: cfa10036: Add the AT24HC02 I2C EEPROM Maxime Ripard
2012-12-12 14:10 ` [PATCH 2/3] ARM: cfa10036: Retrieve the board variant from the AT24 Maxime Ripard
2012-12-12 16:07   ` Jean-Christophe PLAGNIOL-VILLARD
2012-12-12 20:52   ` Sascha Hauer
2012-12-12 14:10 ` [PATCH 3/3] ARM: cfa10036: Use the board variant to load a different device tree Maxime Ripard

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