From 78fd05bd746f623de3150469a9f6f4e9531a17c4 Mon Sep 17 00:00:00 2001
From: Koen Kooi <koen@dominion.thruhere.net>
Date: Sun, 27 Nov 2011 14:53:56 +0100
Subject: [PATCH 21/21] beagleboard: add support for scanning loop-through expansionboards like the uLCD-lite

Signed-off-by: Koen Kooi <koen@dominion.thruhere.net>
---
 board/ti/beagle/beagle.c       |   30 ++++++++++++++++++++++++++----
 include/configs/omap3_beagle.h |    2 ++
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/board/ti/beagle/beagle.c b/board/ti/beagle/beagle.c
index 9c2e6d0..5ea50d1 100644
--- a/board/ti/beagle/beagle.c
+++ b/board/ti/beagle/beagle.c
@@ -74,6 +74,7 @@ extern volatile struct ehci_hcor *hcor;
 #define BBTOYS_WIFI			0x01000B00
 #define BBTOYS_VGA			0x02000B00
 #define BBTOYS_LCD			0x03000B00
+#define BBTOYS_ULCD			0x04000B00
 #define BEAGLE_NO_EEPROM		0xffffffff
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -209,18 +210,18 @@ void get_board_mem_timings(u32 *mcfg, u32 *ctrla, u32 *ctrlb, u32 *rfr_ctrl,
  *		bus 1 for the availability of an AT24C01B serial EEPROM.
  *		returns the device_vendor field from the EEPROM
  */
-unsigned int get_expansion_id(void)
+unsigned int get_expansion_id(int eeprom_address)
 {
 	i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
 
 	/* return BEAGLE_NO_EEPROM if eeprom doesn't respond */
-	if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
+	if (i2c_probe(eeprom_address) == 1) {
 		i2c_set_bus_num(TWL4030_I2C_BUS);
 		return BEAGLE_NO_EEPROM;
 	}
 
 	/* read configuration data */
-	i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
+	i2c_read(eeprom_address, 0, 1, (u8 *)&expansion_config,
 		 sizeof(expansion_config));
 
 	i2c_set_bus_num(TWL4030_I2C_BUS);
@@ -323,7 +324,7 @@ int misc_init_r(void)
 					TWL4030_PM_RECEIVER_DEV_GRP_P1);
 	}
 
-	switch (get_expansion_id()) {
+	switch (get_expansion_id(EXPANSION_EEPROM_I2C_ADDRESS)) {
 	case TINCANTOOLS_ZIPPY:
 		printf("Recognized Tincantools Zippy board (rev %d %s)\n",
 			expansion_config.revision,
@@ -402,6 +403,27 @@ int misc_init_r(void)
 	if (expansion_config.content == 1)
 		setenv(expansion_config.env_var, expansion_config.env_setting);
 
+	/* Scan 0x51 as well for loop-thru boards */
+	switch (get_expansion_id(EXPANSION_EEPROM_I2C_ADDRESS + 1)) {
+	case BBTOYS_ULCD:
+		printf("Recognized BeagleBoardToys uLCD-lite board\n");
+		setenv("buddy2", "bbtoys-ulcd");
+		setenv("defaultdisplay", "lcd");
+		setenv("uenvcmd", "i2c dev 1 ; i2c mw 40 00 00; i2c mw 40 04 80; i2c mw 40 0d 05; i2c mw 40 0d 15");
+		break;
+	case BEAGLE_NO_EEPROM:
+		printf("No EEPROM on expansion board\n");
+		setenv("buddy2", "none");
+		break;
+	default:
+		printf("Unrecognized expansion board: %x\n",
+			expansion_config.device_vendor);
+		setenv("buddy2", "unknown");
+	}
+
+	if (expansion_config.content == 1)
+		setenv(expansion_config.env_var, expansion_config.env_setting);
+
 	twl4030_power_init();
 	switch (get_board_revision()) {
 	case REVISION_XM_A:
diff --git a/include/configs/omap3_beagle.h b/include/configs/omap3_beagle.h
index 833f86a..1cc46dc 100644
--- a/include/configs/omap3_beagle.h
+++ b/include/configs/omap3_beagle.h
@@ -220,6 +220,7 @@
 	"console=ttyO2,115200n8\0" \
 	"mpurate=auto\0" \
 	"buddy=none "\
+	"buddy2=none "\
 	"optargs=\0" \
 	"camera=none\0" \
 	"vram=12M\0" \
@@ -236,6 +237,7 @@
 		"${optargs} " \
 		"mpurate=${mpurate} " \
 		"buddy=${buddy} "\
+		"buddy2=${buddy2} "\
 		"camera=${camera} "\
 		"vram=${vram} " \
 		"omapfb.mode=dvi:${dvimode} " \
-- 
1.7.2.5

