From 560f9d8e02d70e31e18f4f09c83d904d5e4595b5 Mon Sep 17 00:00:00 2001
From: Joel A Fernandes <joelagnel@ti.com>
Date: Fri, 28 Oct 2011 16:21:15 +0530
Subject: [PATCH 1/3] ARM:omap:am335x: BeagleBone version detection and support for old boards

* Have different dev_cfg structures and setup functions for new, old
  beaglebone boards setup pin mux accordingly

* Fall back to older Bone boards if EEPROM reads are incorrect or empty

* Read version field of EEPROM config to call correct setup_beaglebone
  function according to board version

While at it, clean-up a bad comment style in existing code.

Signed-off-by: Steve Kipisz <s-kipisz2@ti.com>
Signed-off-by: Joel A Fernandes <joelagnel@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
---
 arch/arm/mach-omap2/board-am335xevm.c |   54 +++++++++++++++++++++++++-------
 1 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/arch/arm/mach-omap2/board-am335xevm.c b/arch/arm/mach-omap2/board-am335xevm.c
index c84857e..ee936e0 100644
--- a/arch/arm/mach-omap2/board-am335xevm.c
+++ b/arch/arm/mach-omap2/board-am335xevm.c
@@ -288,7 +288,7 @@ static struct omap_board_config_kernel am335x_evm_config[] __initdata = {
 struct am335x_evm_eeprom_config {
 	u32	header;
 	u8	name[8];
-	u32	version;
+	char	version[4];
 	u8	serial[12];
 	u8	opt[32];
 };
@@ -1224,8 +1224,8 @@ static struct evm_dev_cfg ip_phn_evm_dev_cfg[] = {
 	{NULL, 0, 0},
 };
 
-/* Beaglebone */
-static struct evm_dev_cfg beaglebone_dev_cfg[] = {
+/* Beaglebone < Rev A3 */
+static struct evm_dev_cfg beaglebone_old_dev_cfg[] = {
 	{rmii1_init,	DEV_ON_BASEBOARD, PROFILE_NONE},
 	{usb0_init,	DEV_ON_BASEBOARD, PROFILE_NONE},
 	{usb1_init,	DEV_ON_BASEBOARD, PROFILE_NONE},
@@ -1233,6 +1233,15 @@ static struct evm_dev_cfg beaglebone_dev_cfg[] = {
 	{NULL, 0, 0},
 };
 
+/* Beaglebone Rev A3 and after */
+static struct evm_dev_cfg beaglebone_dev_cfg[] = {
+	{mii1_init,	DEV_ON_BASEBOARD, PROFILE_NONE},
+	{usb0_init,	DEV_ON_BASEBOARD, PROFILE_NONE},
+	{usb1_init,	DEV_ON_BASEBOARD, PROFILE_NONE},
+	{mmc0_init,	DEV_ON_BASEBOARD, PROFILE_NONE},
+	{NULL, 0, 0},
+};
+
 static void setup_low_cost_evm(void)
 {
 	pr_info("The board is a AM335x Low Cost EVM.\n");
@@ -1282,19 +1291,32 @@ static void setup_ip_phone_evm(void)
 	_configure_device(IP_PHN_EVM, ip_phn_evm_dev_cfg, PROFILE_NONE);
 }
 
-static void setup_beaglebone(void)
+/* BeagleBone < Rev A3 */
+static void setup_beaglebone_old(void)
 {
-	pr_info("The board is a AM335x Beaglebone.\n");
+	pr_info("The board is a AM335x Beaglebone < Rev A3.\n");
 
-	/*Beagle Bone has Micro-SD slot which doesn't have Write Protect pin */
+	/* Beagle Bone has Micro-SD slot which doesn't have Write Protect pin */
 	am335x_mmc[0].gpio_wp = -EINVAL;
 
-	_configure_device(LOW_COST_EVM, beaglebone_dev_cfg, PROFILE_NONE);
+	_configure_device(LOW_COST_EVM, beaglebone_old_dev_cfg, PROFILE_NONE);
 
 	phy_register_fixup_for_uid(BBB_PHY_ID, BBB_PHY_MASK,
 					beaglebone_phy_fixup);
 }
 
+/* BeagleBone after Rev A3 */
+static void setup_beaglebone(void)
+{
+	pr_info("The board is a AM335x Beaglebone.\n");
+
+	/* Beagle Bone has Micro-SD slot which doesn't have Write Protect pin */
+	am335x_mmc[0].gpio_wp = -EINVAL;
+
+	_configure_device(LOW_COST_EVM, beaglebone_dev_cfg, PROFILE_NONE);
+}
+
+
 static void am335x_setup_daughter_board(struct memory_accessor *m, void *c)
 {
 	u8 tmp;
@@ -1353,11 +1375,18 @@ static void am335x_evm_setup(struct memory_accessor *mem_acc, void *context)
 		goto out;
 	}
 
-	snprintf(tmp, sizeof(config.name), "%s", config.name);
+	snprintf(tmp, sizeof(config.name) + 1, "%s", config.name);
 	pr_info("Board name: %s\n", tmp);
+	snprintf(tmp, sizeof(config.version) + 1, "%s", config.version);
+	pr_info("Board version: %s\n", tmp);
+
 	if (!strncmp("A335BONE", config.name, 8)) {
 		daughter_brd_detected = false;
-		setup_beaglebone();
+		if(!strncmp("00A1", config.version, 4) ||
+		   !strncmp("00A2", config.version, 4))
+			setup_beaglebone_old();
+		else
+			setup_beaglebone();
 	} else {
 		/* only 6 characters of options string used for now */
 		snprintf(tmp, 7, "%s", config.opt);
@@ -1384,12 +1413,13 @@ static void am335x_evm_setup(struct memory_accessor *mem_acc, void *context)
 out:
 	/*
 	 * If the EEPROM hasn't been programed or an incorrect header
-	 * or board name are read, assume this is a beaglebone board.
+	 * or board name are read, assume this is an old beaglebone board
+	 * (< Rev A3)
 	 */
 	pr_err("Could not detect any board, falling back to: "
-		"Beaglebone in profile 0 with no daughter card connected\n");
+		"Beaglebone (< Rev A3) with no daughter card connected\n");
 	daughter_brd_detected = false;
-	setup_beaglebone();
+	setup_beaglebone_old();
 
 	/* Initialize cpsw after board detection is completed as board
 	 * information is required for configuring phy address and hence
-- 
1.7.2.5

