[U-Boot] [PATCH] OMAP3: BeagleBoard: Add expansion board auto detection

Dirk Behme dirk.behme at googlemail.com
Sun Nov 15 19:58:14 CET 2009


At BeagleBoard's expansion header various expansion boards can be attached.
To be able to auto detect these boards, it was agreed to put a serial EEPROM
at I2C bus 1 which contains some vendor and device specific information in it's
first four bytes.

Add logic to read the content of this serial EEPROM, set pin mux based on
this information and print the info found.

See

http://elinux.org/BeagleBoardPinMux#Expansion_boards

for details.

Signed-off-by: Dirk Behme <dirk.behme at googlemail.com>
---

Notes:

- This patch depends on OMAP3 I2C bus switch patch in I2C next

http://git.denx.de/?p=u-boot/u-boot-i2c.git;a=commit;h=5656176c23a91bcc88d020bee2be0d9d0c70ce3e

- This patch is intended to be applied in next merge window as soon as I2C next
  is merged.

- This patch is tested on BeagleBoard with and without TinCanTools Zippy expansion
  board attached.

- Could anybody additionally test it on Beagle *without* Zippy attached?
  It seems that i2c_probe() sometimes returns 0 even without Zippy (??).
  This results in scan of non-existent devices and some "timed out in xxx"
  message which can be ignored, but are annoying.

 board/ti/beagle/beagle.c |   74 +++++++++++++++++++++++++++++++++++++++++++++++
 board/ti/beagle/beagle.h |   31 +++++++++++++++++++
 2 files changed, 105 insertions(+)

Index: u-boot-main/board/ti/beagle/beagle.c
===================================================================
--- u-boot-main.orig/board/ti/beagle/beagle.c
+++ u-boot-main/board/ti/beagle/beagle.c
@@ -40,6 +40,12 @@
 
 static int beagle_revision_c;
 
+static struct {
+	unsigned int device_vendor;
+	unsigned char revision;
+	unsigned char content;
+} expansion_config;
+
 /*
  * Routine: board_init
  * Description: Early hardware init.
@@ -57,6 +63,66 @@ int board_init(void)
 	return 0;
 }
 
+#define EXPANSION_EEPROM_I2C_BUS		1
+#define EXPANSION_EEPROM_I2C_ADDRESS		0x50
+
+#define TINCANTOOLS_ZIPPY	0x01000100
+#define TINCANTOOLS_ZIPPY2	0x02000100
+#define TINCANTOOLS_TRAINER	0x03000100
+#define TINCANTOOLS_SHOWDOG	0x04000100
+
+/*
+ * Routine: print_expansion_config
+ * Description: Print info about board connected to expansion header.
+ *		It uses the information from scan_expansion(),
+ */
+void print_expansion_config(void) {
+
+	switch(expansion_config.device_vendor) {
+	case TINCANTOOLS_ZIPPY:
+		printf("TinCanTools Zippy ");
+		break;
+	case TINCANTOOLS_ZIPPY2:
+		printf("TinCanTools Zippy2 ");
+		break;
+	case TINCANTOOLS_TRAINER:
+		printf("TinCanTools Trainer ");
+		break;
+	case TINCANTOOLS_SHOWDOG:
+		printf("TinCanTools ShowDog ");
+		break;
+	default:
+		return;
+	}
+	printf("board, revision 0x%02x, content code 0x%02x, found\n",
+	       expansion_config.revision, expansion_config.content);
+}
+
+ /*
+ * Routine: scan_expansion
+ * Description: This function checks for expansion board connected to
+ *		Beagle's expansion header. This done by checking I2C
+ *		bus 1 for the availability of an AT24C01B serial EEPROM.
+ */
+void scan_expansion(void)
+{
+	/* Set pin mux and switch to I2C bus 1 */
+	MUX_I2C2();
+	i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
+
+	/* Check if expansion EEPROM is there*/
+	if(i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 0) {
+		/* EEPROM found, read configuration data */
+		i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1,
+			 (u8 *)&expansion_config, sizeof(expansion_config));
+	}
+
+	/* Switch back to default bus and pin mux */
+	i2c_set_bus_num(0);
+	MUX_I2C2_DEFAULT();
+}
+
+
 /*
  * Routine: beagle_get_revision
  * Description: Return the revision of the BeagleBoard this code is running on.
@@ -124,6 +190,14 @@ int misc_init_r(void)
 
 	dieid_num_r();
 
+	scan_expansion();
+
+	if (expansion_config.device_vendor == TINCANTOOLS_ZIPPY) {
+		MUX_ZIPPY();
+	}
+
+	print_expansion_config();
+
 	return 0;
 }
 
Index: u-boot-main/board/ti/beagle/beagle.h
===================================================================
--- u-boot-main.orig/board/ti/beagle/beagle.h
+++ u-boot-main/board/ti/beagle/beagle.h
@@ -381,4 +381,35 @@ const omap3_sysinfo sysinfo = {
 	MUX_VAL(CP(UART2_RTS),		(IDIS | PTD | DIS | M0)) /*UART2_RTS*/\
 	MUX_VAL(CP(UART2_TX),		(IDIS | PTD | DIS | M0)) /*UART2_TX*/
 
+#define MUX_I2C2() \
+	MUX_VAL(CP(I2C2_SCL),		(IEN  | PTU | EN  | M0)) /*I2C2_SCL*/\
+	MUX_VAL(CP(I2C2_SDA),		(IEN  | PTU | EN  | M0)) /*I2C2_SDA*/
+
+#define MUX_I2C2_DEFAULT() \
+	MUX_VAL(CP(I2C2_SCL),		(IEN  | PTU | EN  | M4)) /*GPIO_168*/\
+	MUX_VAL(CP(I2C2_SDA),		(IEN  | PTU | EN  | M4)) /*GPIO_183*/
+
+#define MUX_ZIPPY() \
+	MUX_VAL(CP(MMC2_CLK),		(IEN  | PTU | EN  | M0)) /*MMC2_CLK*/\
+	MUX_VAL(CP(MMC2_CMD),		(IEN  | PTU | EN  | M0)) /*MMC2_CMD*/\
+	MUX_VAL(CP(MMC2_DAT0),		(IEN  | PTU | EN  | M0)) /*MMC2_DAT0*/\
+	MUX_VAL(CP(MMC2_DAT1),		(IEN  | PTU | EN  | M0)) /*MMC2_DAT1*/\
+	MUX_VAL(CP(MMC2_DAT2),		(IEN  | PTU | EN  | M0)) /*MMC2_DAT2*/\
+	MUX_VAL(CP(MMC2_DAT3),		(IEN  | PTU | EN  | M0)) /*MMC2_DAT3*/\
+	MUX_VAL(CP(MMC2_DAT4),		(IEN  | PTU | EN  | M1)) /*MMC2_DIR_DAT0*/\
+	MUX_VAL(CP(MMC2_DAT5),		(IEN  | PTU | EN  | M1)) /*MMC2_DIR_DAT1*/\
+	MUX_VAL(CP(MMC2_DAT6),		(IEN  | PTU | EN  | M1)) /*MMC2_DIR_CMD*/\
+	MUX_VAL(CP(MMC2_DAT7),		(IEN  | PTU | EN  | M1)) /*MMC2_CLKIN*/\
+	MUX_VAL(CP(MCBSP1_CLKR),	(IEN  | PTU | EN  | M1)) /*MCSPI4_CLK*/\
+	MUX_VAL(CP(MCBSP1_FSR),		(IEN  | PTU | EN  | M4)) /*GPIO_157*/\
+	MUX_VAL(CP(MCBSP1_DX),		(IEN  | PTD | EN  | M1)) /*MCSPI4_SIMO*/\
+	MUX_VAL(CP(MCBSP1_DR),		(IEN  | PTD | DIS | M1)) /*MCSPI4_SOMI*/\
+	MUX_VAL(CP(MCBSP1_FSX),		(IEN  | PTD | EN  | M1)) /*MCSPI4_CS0*/ \
+	MUX_VAL(CP(MCBSP1_CLKX),	(IEN  | PTD | DIS | M4)) /*GPIO_162*/\
+	MUX_VAL(CP(I2C2_SCL),		(IEN  | PTU | EN  | M0)) /*I2C2_SCL*/\
+	MUX_VAL(CP(I2C2_SDA),		(IEN  | PTU | EN  | M0)) /*I2C2_SDA*/\
+	MUX_VAL(CP(MCBSP3_DX),		(IEN  | PTD | DIS | M4)) /*GPIO_140*/\
+	MUX_VAL(CP(MCBSP3_DR),		(IEN  | PTD | DIS | M4)) /*GPIO_142*/\
+	MUX_VAL(CP(MCBSP3_CLKX),	(IEN  | PTD | DIS | M4)) /*GPIO_141*/
+
 #endif


More information about the U-Boot mailing list