Skip to content

Commit

Permalink
Merge git://git.denx.de/u-boot-dm
Browse files Browse the repository at this point in the history
  • Loading branch information
trini committed May 8, 2015
2 parents 57cc4e6 + a5e1bcd commit 02ffb58
Show file tree
Hide file tree
Showing 67 changed files with 1,743 additions and 649 deletions.
5 changes: 0 additions & 5 deletions arch/sandbox/cpu/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ void __udelay(unsigned long usec)
os_usleep(usec);
}

unsigned long __attribute__((no_instrument_function)) timer_get_us(void)
{
return os_get_nsec() / 1000;
}

int cleanup_before_linux(void)
{
return 0;
Expand Down
18 changes: 18 additions & 0 deletions arch/sandbox/cpu/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <asm/sections.h>
#include <asm/state.h>
#include <os.h>
#include <rtc_def.h>

/* Operating System Interface */

Expand Down Expand Up @@ -537,3 +538,20 @@ int os_jump_to_image(const void *dest, int size)

return unlink(fname);
}

void os_localtime(struct rtc_time *rt)
{
time_t t = time(NULL);
struct tm *tm;

tm = localtime(&t);
rt->tm_sec = tm->tm_sec;
rt->tm_min = tm->tm_min;
rt->tm_hour = tm->tm_hour;
rt->tm_mday = tm->tm_mday;
rt->tm_mon = tm->tm_mon + 1;
rt->tm_year = tm->tm_year + 1900;
rt->tm_wday = tm->tm_wday;
rt->tm_yday = tm->tm_yday;
rt->tm_isdst = tm->tm_isdst;
}
20 changes: 17 additions & 3 deletions arch/sandbox/cpu/start.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,33 @@ int sandbox_main_loop_init(void)
struct sandbox_state *state = state_get_current();

/* Execute command if required */
if (state->cmd) {
int retval;
if (state->cmd || state->run_distro_boot) {
int retval = 0;

cli_init();

retval = run_command_list(state->cmd, -1, 0);
if (state->cmd)
retval = run_command_list(state->cmd, -1, 0);

if (state->run_distro_boot)
retval = cli_simple_run_command("run distro_bootcmd",
0);

if (!state->interactive)
os_exit(retval);
}

return 0;
}

static int sandbox_cmdline_cb_boot(struct sandbox_state *state,
const char *arg)
{
state->run_distro_boot = true;
return 0;
}
SANDBOX_CMDLINE_OPT_SHORT(boot, 'b', 0, "Run distro boot commands");

static int sandbox_cmdline_cb_command(struct sandbox_state *state,
const char *arg)
{
Expand Down
12 changes: 11 additions & 1 deletion arch/sandbox/dts/sandbox.dts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

aliases {
eth5 = "/eth@90000000";
i2c0 = &i2c_0;
pci0 = &pci;
rtc0 = &rtc_0;
};

chosen {
Expand Down Expand Up @@ -90,7 +92,7 @@
num-gpios = <10>;
};

i2c@0 {
i2c_0: i2c@0 {
#address-cells = <1>;
#size-cells = <0>;
reg = <0 0>;
Expand All @@ -105,6 +107,14 @@
sandbox,size = <128>;
};
};

rtc_0: rtc@43 {
reg = <0x43>;
compatible = "sandbox-rtc";
emul {
compatible = "sandbox,i2c-rtc";
};
};
};

spi@0 {
Expand Down
2 changes: 2 additions & 0 deletions arch/sandbox/include/asm/eth.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@

void sandbox_eth_disable_response(int index, bool disable);

void sandbox_eth_skip_timeout(void);

#endif /* __ETH_H */
28 changes: 28 additions & 0 deletions arch/sandbox/include/asm/rtc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Simulate an I2C real time clock
*
* Copyright (c) 2015 Google, Inc
* Written by Simon Glass <[email protected]>
*
* SPDX-License-Identifier: GPL-2.0+
*/

#ifndef __asm_rtc_h
#define __asm_rtc_h

/* Register numbers in the sandbox RTC */
enum {
REG_SEC = 5,
REG_MIN,
REG_HOUR,
REG_MDAY,
REG_MON,
REG_YEAR,
REG_WDAY,

REG_RESET = 0x20,

REG_COUNT = 0x80,
};

#endif
1 change: 1 addition & 0 deletions arch/sandbox/include/asm/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct sandbox_spi_info {
struct sandbox_state {
const char *cmd; /* Command to execute */
bool interactive; /* Enable cmdline after execute */
bool run_distro_boot; /* Automatically run distro bootcommands */
const char *fdt_fname; /* Filename of FDT binary */
const char *parse_err; /* Error to report from parsing */
int argc; /* Program arguments */
Expand Down
39 changes: 39 additions & 0 deletions arch/sandbox/include/asm/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
#define SANDBOX_PCI_CLASS_CODE PCI_CLASS_CODE_COMM
#define SANDBOX_PCI_CLASS_SUB_CODE PCI_CLASS_SUB_CODE_COMM_SERIAL

/**
* sandbox_i2c_set_test_mode() - set test mode for running unit tests
*
* See sandbox_i2c_xfer() for the behaviour changes.
*
* @bus: sandbox I2C bus to adjust
* @test_mode: true to select test mode, false to run normally
*/
void sandbox_i2c_set_test_mode(struct udevice *bus, bool test_mode);

enum sandbox_i2c_eeprom_test_mode {
SIE_TEST_MODE_NONE,
/* Permits read/write of only one byte per I2C transaction */
Expand All @@ -28,4 +38,33 @@ void sandbox_i2c_eeprom_set_test_mode(struct udevice *dev,

void sandbox_i2c_eeprom_set_offset_len(struct udevice *dev, int offset_len);

/*
* sandbox_timer_add_offset()
*
* Allow tests to add to the time reported through lib/time.c functions
* offset: number of milliseconds to advance the system time
*/
void sandbox_timer_add_offset(unsigned long offset);

/**
* sandbox_i2c_rtc_set_offset() - set the time offset from system/base time
*
* @dev: RTC device to adjust
* @use_system_time: true to use system time, false to use @base_time
* @offset: RTC offset from current system/base time (-1 for no
* change)
* @return old value of RTC offset
*/
long sandbox_i2c_rtc_set_offset(struct udevice *dev, bool use_system_time,
int offset);

/**
* sandbox_i2c_rtc_get_set_base_time() - get and set the base time
*
* @dev: RTC device to adjust
* @base_time: New base system time (set to -1 for no change)
* @return old base time
*/
long sandbox_i2c_rtc_get_set_base_time(struct udevice *dev, long base_time);

#endif
11 changes: 10 additions & 1 deletion board/sandbox/sandbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cros_ec.h>
#include <dm.h>
#include <os.h>
#include <asm/test.h>
#include <asm/u-boot-sandbox.h>

/*
Expand All @@ -25,9 +26,17 @@ void flush_cache(unsigned long start, unsigned long size)
{
}

/* system timer offset in ms */
static unsigned long sandbox_timer_offset;

void sandbox_timer_add_offset(unsigned long offset)
{
sandbox_timer_offset += offset;
}

unsigned long timer_read_counter(void)
{
return os_get_nsec() / 1000;
return os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
}

int dram_init(void)
Expand Down
57 changes: 42 additions & 15 deletions common/cmd_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
#include <common.h>
#include <command.h>
#include <dm.h>
#include <rtc.h>
#include <i2c.h>

Expand All @@ -33,10 +34,18 @@ static int do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
struct rtc_time tm;
int rcode = 0;
int old_bus;
int old_bus __maybe_unused;

/* switch to correct I2C bus */
#ifdef CONFIG_SYS_I2C
#ifdef CONFIG_DM_I2C
struct udevice *dev;

rcode = uclass_get_device(UCLASS_RTC, 0, &dev);
if (rcode) {
printf("Cannot find RTC: err=%d\n", rcode);
return CMD_RET_FAILURE;
}
#elif defined(CONFIG_SYS_I2C)
old_bus = i2c_get_bus_num();
i2c_set_bus_num(CONFIG_SYS_RTC_BUS_NUM);
#else
Expand All @@ -48,32 +57,50 @@ static int do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
case 2: /* set date & time */
if (strcmp(argv[1],"reset") == 0) {
puts ("Reset RTC...\n");
rtc_reset ();
#ifdef CONFIG_DM_I2C
rcode = dm_rtc_reset(dev);
if (!rcode)
rcode = dm_rtc_set(dev, &default_tm);
#else
rtc_reset();
rcode = rtc_set(&default_tm);
#endif
if (rcode)
puts("## Failed to set date after RTC reset\n");
} else {
/* initialize tm with current time */
rcode = rtc_get (&tm);

if(!rcode) {
#ifdef CONFIG_DM_I2C
rcode = dm_rtc_get(dev, &tm);
#else
rcode = rtc_get(&tm);
#endif
if (!rcode) {
/* insert new date & time */
if (mk_date (argv[1], &tm) != 0) {
if (mk_date(argv[1], &tm) != 0) {
puts ("## Bad date format\n");
break;
}
/* and write to RTC */
rcode = rtc_set (&tm);
if(rcode)
puts("## Set date failed\n");
#ifdef CONFIG_DM_I2C
rcode = dm_rtc_set(dev, &tm);
#else
rcode = rtc_set(&tm);
#endif
if (rcode) {
printf("## Set date failed: err=%d\n",
rcode);
}
} else {
puts("## Get date failed\n");
}
}
/* FALL TROUGH */
case 1: /* get date & time */
rcode = rtc_get (&tm);

#ifdef CONFIG_DM_I2C
rcode = dm_rtc_get(dev, &tm);
#else
rcode = rtc_get(&tm);
#endif
if (rcode) {
puts("## Get date failed\n");
break;
Expand All @@ -93,11 +120,11 @@ static int do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
/* switch back to original I2C bus */
#ifdef CONFIG_SYS_I2C
i2c_set_bus_num(old_bus);
#else
#elif !defined(CONFIG_DM_I2C)
I2C_SET_BUS(old_bus);
#endif

return rcode;
return rcode ? CMD_RET_FAILURE : 0;
}

/*
Expand Down Expand Up @@ -201,7 +228,7 @@ int mk_date (const char *datestr, struct rtc_time *tmp)
tmp->tm_min = val;

/* calculate day of week */
GregorianDay (tmp);
rtc_calc_weekday(tmp);

return (0);
default:
Expand Down
2 changes: 1 addition & 1 deletion common/fdt_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ int fdt_setup_simplefb_node(void *fdt, int node, u64 base_address, u32 width,
if (ret < 0)
return ret;

snprintf(name, sizeof(name), "framebuffer@%llx", base_address);
snprintf(name, sizeof(name), "framebuffer@%" PRIx64, base_address);
ret = fdt_set_name(fdt, node, name);
if (ret < 0)
return ret;
Expand Down
2 changes: 1 addition & 1 deletion common/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ void genimg_print_time(time_t timestamp)
#ifndef USE_HOSTCC
struct rtc_time tm;

to_tm(timestamp, &tm);
rtc_to_tm(timestamp, &tm);
printf("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
tm.tm_year, tm.tm_mon, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
Expand Down
17 changes: 11 additions & 6 deletions common/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,13 +946,18 @@ static int usb_setup_descriptor(struct usb_device *dev, bool do_read)
* send 64-byte GET-DEVICE-DESCRIPTOR request. Since the descriptor is
* only 18 bytes long, this will terminate with a short packet. But if
* the maxpacket size is 8 or 16 the device may be waiting to transmit
* some more, or keeps on retransmitting the 8 byte header. */
* some more, or keeps on retransmitting the 8 byte header.
*/

dev->descriptor.bMaxPacketSize0 = 64; /* Start off at 64 bytes */
/* Default to 64 byte max packet size */
dev->maxpacketsize = PACKET_SIZE_64;
dev->epmaxpacketin[0] = 64;
dev->epmaxpacketout[0] = 64;
if (dev->speed == USB_SPEED_LOW) {
dev->descriptor.bMaxPacketSize0 = 8;
dev->maxpacketsize = PACKET_SIZE_8;
} else {
dev->descriptor.bMaxPacketSize0 = 64;
dev->maxpacketsize = PACKET_SIZE_64;
}
dev->epmaxpacketin[0] = dev->descriptor.bMaxPacketSize0;
dev->epmaxpacketout[0] = dev->descriptor.bMaxPacketSize0;

if (do_read) {
int err;
Expand Down
2 changes: 2 additions & 0 deletions configs/sandbox_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ CONFIG_TPM_TIS_SANDBOX=y
CONFIG_SOUND=y
CONFIG_CMD_SOUND=y
CONFIG_SOUND_SANDBOX=y
CONFIG_DM_RTC=y
CONFIG_CMD_UT_TIME=y
Loading

0 comments on commit 02ffb58

Please sign in to comment.