summaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorMaxime Ripard <maxime.ripard@free-electrons.com>2012-12-13 11:26:44 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2012-12-14 08:36:36 +0100
commitd2c60a65a465d49e97f765c46e96aecc3efe164e (patch)
tree5fc5d5a98c7dab7f612c0dae39cbac3c3bf8da53 /arch
parent25fcfb2efa87a346e2ab83638a7985b516a7d7a2 (diff)
downloadbarebox-d2c60a65a465d49e97f765c46e96aecc3efe164e.tar.gz
barebox-d2c60a65a465d49e97f765c46e96aecc3efe164e.tar.xz
ARM: cfa10036: Retrieve the board variant from the AT24
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> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/boards/crystalfontz-cfa10036/Makefile2
-rw-r--r--arch/arm/boards/crystalfontz-cfa10036/cfa10036.c4
-rw-r--r--arch/arm/boards/crystalfontz-cfa10036/hwdetect.c96
-rw-r--r--arch/arm/boards/crystalfontz-cfa10036/hwdetect.h22
4 files changed, 123 insertions, 1 deletions
diff --git a/arch/arm/boards/crystalfontz-cfa10036/Makefile b/arch/arm/boards/crystalfontz-cfa10036/Makefile
index 75f0020c09..7e8d5e246e 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 df0ead914c..b59dbab4a6 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 0000000000..5eb3ca4cf7
--- /dev/null
+++ b/arch/arm/boards/crystalfontz-cfa10036/hwdetect.c
@@ -0,0 +1,96 @@
+/*
+ * 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 <globalvar.h>
+#include <libbb.h>
+#include <magicvar.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;
+
+ 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;
+ }
+
+ globalvar_add_simple("board.variant");
+ setenv("global.board.variant", board_name);
+ pr_info("Booting on a CFA10036 with %s\n", board_name);
+}
+
+BAREBOX_MAGICVAR_NAMED(global_board_variant, global.board.variant, "The board variant");
diff --git a/arch/arm/boards/crystalfontz-cfa10036/hwdetect.h b/arch/arm/boards/crystalfontz-cfa10036/hwdetect.h
new file mode 100644
index 0000000000..2a5330ea17
--- /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__ */