[U-Boot] [PATCH 2/3] BeagleBoard: Added userbutton command

Joel A Fernandes agnel.joel at gmail.com
Tue Aug 16 04:36:53 CEST 2011


From: Jason Kridner <jkridner at beagleboard.org>

Based on commit f1099c7c43caf5bac3bf6a65aa266fade4747072
    Author: Greg Turner <gregturner at ti.com>
    Date:   Tue May 25 09:19:06 2010 -0500

    New u-boot command for status of USER button on BeagleBoard-xM

         Modified bootcmd to check the staus at boot time and set
	 filename of the boot script.

* Moved to a BeagleBoard specific file.
* Removed changes to default boot command from adding userbutton
  command.
* Made to handle pre-xM boards.
* Flipped polarity of the return value to avoid confusion.  Success (0)
  is when the button is pressed.  Failure (1) is when the button is NOT
  pressed.
* Used latest revision getting function.
* Used latest macros for board revision.
* Added xM-C revision definition (optional, since it was default)
* updated default configuration with UserButton functionality
  * Added a separate bootenv variable to load a user defined .txt file
  * Added an example, showing how a different environment file can be loaded with
    the user button pressed

Signed-off-by: Jason Kridner <jkridner at beagleboard.org>
Signed-off-by: Koen Kooi <koen at dominion.thruhere.net>
Signed-off-by: Joel A Fernandes <agnel.joel at gmail.com>
Cc: Greg Turner <gregturner at ti.com>
---
 board/ti/beagle/beagle.c       |   56 ++++++++++++++++++++++++++++++++++++++++
 include/configs/omap3_beagle.h |    7 ++++-
 2 files changed, 62 insertions(+), 1 deletions(-)

diff --git a/board/ti/beagle/beagle.c b/board/ti/beagle/beagle.c
index a958545..8dc8dfa 100644
--- a/board/ti/beagle/beagle.c
+++ b/board/ti/beagle/beagle.c
@@ -50,6 +50,7 @@ extern struct ehci_hccr *hccr;
 extern volatile struct ehci_hcor *hcor;
 #endif
 #include "beagle.h"
+#include <command.h>
 
 #define pr_debug(fmt, args...) debug(fmt, ##args)
 
@@ -446,3 +447,58 @@ int ehci_hcd_init(void)
 }
 
 #endif /* CONFIG_USB_EHCI */
+
+/*
+ * This command returns the status of the user button on beagle xM
+ * Input - none
+ * Returns - 	1 if button is held down
+ *		0 if button is not held down
+ */
+int do_userbutton (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+	int     button = 0;
+	int	gpio;
+
+	/*
+	 * pass address parameter as argv[0] (aka command name),
+	 * and all remaining args
+	 */
+	switch (get_board_revision()) {
+	case REVISION_AXBX:
+	case REVISION_CX:
+	case REVISION_C4:
+		gpio = 7;
+		break;
+	case REVISION_XM_A:
+	case REVISION_XM_B:
+	case REVISION_XM_C:
+	default:
+		gpio = 4;
+		break;
+	}
+	omap_request_gpio(gpio);
+	omap_set_gpio_direction(gpio, 1);
+	printf("The user button is currently ");
+	if(omap_get_gpio_datain(gpio))
+	{
+		button = 1;
+		printf("PRESSED.\n");
+	}
+	else
+	{
+		button = 0;
+		printf("NOT pressed.\n");
+	}
+
+	omap_free_gpio(gpio);
+
+	return !button;
+}
+
+/* -------------------------------------------------------------------- */
+
+U_BOOT_CMD(
+	userbutton, CONFIG_SYS_MAXARGS, 1,	do_userbutton,
+	"Return the status of the BeagleBoard USER button",
+	""
+);
diff --git a/include/configs/omap3_beagle.h b/include/configs/omap3_beagle.h
index c41d48e..a494f99 100644
--- a/include/configs/omap3_beagle.h
+++ b/include/configs/omap3_beagle.h
@@ -227,7 +227,8 @@
 		"omapdss.def_disp=${defaultdisplay} " \
 		"root=${nandroot} " \
 		"rootfstype=${nandrootfstype}\0" \
-	"loadbootenv=fatload mmc ${mmcdev} ${loadaddr} uEnv.txt\0" \
+	"bootenv=uEnv.txt\0" \
+	"loadbootenv=fatload mmc ${mmcdev} ${loadaddr} ${bootenv}\0" \
 	"importbootenv=echo Importing environment from mmc ...; " \
 		"env import -t $loadaddr $filesize\0" \
 	"loaduimage=fatload mmc ${mmcdev} ${loadaddr} uImage\0" \
@@ -241,8 +242,12 @@
 
 #define CONFIG_BOOTCOMMAND \
 	"if mmc rescan ${mmcdev}; then " \
+		"if userbutton; then " \
+			"setenv bootenv user.txt;" \
+		"fi;" \
 		"echo SD/MMC found on device ${mmcdev};" \
 		"if run loadbootenv; then " \
+			"echo Loaded environment from ${bootenv};" \
 			"run importbootenv;" \
 		"fi;" \
 		"if test -n $uenvcmd; then " \
-- 
1.7.1



More information about the U-Boot mailing list