diff options
author | Tim Harvey <tharvey@gateworks.com> | 2016-05-24 11:03:50 -0700 |
---|---|---|
committer | Stefano Babic <sbabic@denx.de> | 2016-05-31 17:24:15 +0200 |
commit | efa7ed7236ee5bfab871f35ce70f3e3e1d39b4f6 (patch) | |
tree | 3c715c338a8dadc59bbeec9c09dcea5cc5220edb /board | |
parent | 6052b1c6f4fadee751dd7c90a4148943f65ab7b0 (diff) | |
download | u-boot-imx-efa7ed7236ee5bfab871f35ce70f3e3e1d39b4f6.zip u-boot-imx-efa7ed7236ee5bfab871f35ce70f3e3e1d39b4f6.tar.gz u-boot-imx-efa7ed7236ee5bfab871f35ce70f3e3e1d39b4f6.tar.bz2 |
imx: ventana: gsc: add gsc sleep command
The Gateworks System Controller on Ventana boards has the ability to
disable the board's primary power supply until the RTC hits a specific
time. When sleeping a button-down event on the GSC user pushbutton will
wake the board before it's wake time has been reached. This feature is
referred to as GSC sleep.
Add a command to invoke sleep mode for a specified number of seconds.
Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Diffstat (limited to 'board')
-rw-r--r-- | board/gateworks/gw_ventana/gsc.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/board/gateworks/gw_ventana/gsc.c b/board/gateworks/gw_ventana/gsc.c index 4f26bfd..2555824 100644 --- a/board/gateworks/gw_ventana/gsc.c +++ b/board/gateworks/gw_ventana/gsc.c @@ -160,6 +160,48 @@ int gsc_boot_wd_disable(void) } #ifdef CONFIG_CMD_GSC +static int do_gsc_sleep(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + unsigned char reg; + unsigned long secs = 0; + + if (argc < 2) + return CMD_RET_USAGE; + + secs = simple_strtoul(argv[1], NULL, 10); + printf("GSC Sleeping for %ld seconds\n", secs); + + i2c_set_bus_num(0); + reg = (secs >> 24) & 0xff; + if (gsc_i2c_write(GSC_SC_ADDR, 9, 1, ®, 1)) + goto error; + reg = (secs >> 16) & 0xff; + if (gsc_i2c_write(GSC_SC_ADDR, 8, 1, ®, 1)) + goto error; + reg = (secs >> 8) & 0xff; + if (gsc_i2c_write(GSC_SC_ADDR, 7, 1, ®, 1)) + goto error; + reg = secs & 0xff; + if (gsc_i2c_write(GSC_SC_ADDR, 6, 1, ®, 1)) + goto error; + if (gsc_i2c_read(GSC_SC_ADDR, GSC_SC_CTRL1, 1, ®, 1)) + goto error; + reg |= (1 << 2); + if (gsc_i2c_write(GSC_SC_ADDR, GSC_SC_CTRL1, 1, ®, 1)) + goto error; + reg &= ~(1 << 2); + reg |= 0x3; + if (gsc_i2c_write(GSC_SC_ADDR, GSC_SC_CTRL1, 1, ®, 1)) + goto error; + + return CMD_RET_SUCCESS; + +error: + printf("i2c error\n"); + return CMD_RET_FAILURE; +} + static int do_gsc_wd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { unsigned char reg; @@ -206,13 +248,15 @@ static int do_gsc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (strcasecmp(argv[1], "wd") == 0) return do_gsc_wd(cmdtp, flag, --argc, ++argv); + else if (strcasecmp(argv[1], "sleep") == 0) + return do_gsc_sleep(cmdtp, flag, --argc, ++argv); return CMD_RET_USAGE; } U_BOOT_CMD( gsc, 4, 1, do_gsc, "GSC configuration", - "[wd enable [30|60]]|[wd disable]\n" + "[wd enable [30|60]]|[wd disable]|[sleep <secs>]\n" ); #endif /* CONFIG_CMD_GSC */ |