From 4f051824b5c2a6bf8d3114c772676977fb95969a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 24 Feb 2016 09:14:48 -0700 Subject: timer: Support tracing fully A few of the functions in the timer uclass are not marked with 'notrace'. Fix this so that tracing can be used with CONFIG_TRACE. Signed-off-by: Simon Glass --- drivers/timer/timer-uclass.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c index 83d1a35e062..382c0f2bd15 100644 --- a/drivers/timer/timer-uclass.c +++ b/drivers/timer/timer-uclass.c @@ -22,7 +22,7 @@ DECLARE_GLOBAL_DATA_PTR; * tick, and no timer interrupt. */ -int timer_get_count(struct udevice *dev, u64 *count) +int notrace timer_get_count(struct udevice *dev, u64 *count) { const struct timer_ops *ops = device_get_ops(dev); @@ -32,9 +32,9 @@ int timer_get_count(struct udevice *dev, u64 *count) return ops->get_count(dev, count); } -unsigned long timer_get_rate(struct udevice *dev) +unsigned long notrace timer_get_rate(struct udevice *dev) { - struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev); + struct timer_dev_priv *uc_priv = dev->uclass_priv; return uc_priv->clock_rate; } -- cgit v1.3.1 From c95fec31928d7e2596364ee1d226b52ffd7793f2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 24 Feb 2016 09:14:49 -0700 Subject: timer: Provide an early timer In some cases the timer must be accessible before driver model is active. Examples include when using CONFIG_TRACE to trace U-Boot's execution before driver model is set up. Enable this option to use an early timer. These functions must be supported by your timer driver: timer_early_get_count() and timer_early_get_rate(). Signed-off-by: Simon Glass --- drivers/timer/Kconfig | 10 ++++++++++ include/timer.h | 21 +++++++++++++++++++++ lib/time.c | 28 +++++++++++++++++++++------- 3 files changed, 52 insertions(+), 7 deletions(-) (limited to 'drivers') diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig index ff65a731def..cb18f12fc99 100644 --- a/drivers/timer/Kconfig +++ b/drivers/timer/Kconfig @@ -9,6 +9,16 @@ config TIMER will be used. The timer is usually a 32 bits free-running up counter. There may be no real tick, and no timer interrupt. +config TIMER_EARLY + bool "Allow timer to be used early in U-Boot" + depends on TIMER + help + In some cases the timer must be accessible before driver model is + active. Examples include when using CONFIG_TRACE to trace U-Boot's + execution before driver model is set up. Enable this option to + use an early timer. These functions must be supported by your timer + driver: timer_early_get_count() and timer_early_get_rate(). + config ALTERA_TIMER bool "Altera timer support" depends on TIMER diff --git a/include/timer.h b/include/timer.h index f14725cc280..dcc803c392a 100644 --- a/include/timer.h +++ b/include/timer.h @@ -67,4 +67,25 @@ struct timer_dev_priv { unsigned long clock_rate; }; +/** + * timer_early_get_count() - Implement timer_get_count() before driver model + * + * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return + * the current timer value before the proper driver model timer is ready. + * It should be implemented by one of the timer values. This is mostly useful + * for tracing. + */ +u64 timer_early_get_count(void); + +/** + * timer_early_get_rate() - Get the timer rate before driver model + * + * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return + * the current timer rate in Hz before the proper driver model timer is ready. + * It should be implemented by one of the timer values. This is mostly useful + * for tracing. This corresponds to the clock_rate value in struct + * timer_dev_priv. + */ +unsigned long timer_early_get_rate(void); + #endif /* _TIMER_H_ */ diff --git a/lib/time.c b/lib/time.c index e9f6861b984..f37150fddc1 100644 --- a/lib/time.c +++ b/lib/time.c @@ -43,11 +43,17 @@ extern unsigned long __weak timer_read_counter(void); #ifdef CONFIG_TIMER ulong notrace get_tbclk(void) { - int ret; + if (!gd->timer) { +#ifdef CONFIG_TIMER_EARLY + return timer_early_get_rate(); +#else + int ret; - ret = dm_timer_init(); - if (ret) - return ret; + ret = dm_timer_init(); + if (ret) + return ret; +#endif + } return timer_get_rate(gd->timer); } @@ -57,9 +63,17 @@ uint64_t notrace get_ticks(void) u64 count; int ret; - ret = dm_timer_init(); - if (ret) - return ret; + if (!gd->timer) { +#ifdef CONFIG_TIMER_EARLY + return timer_early_get_count(); +#else + int ret; + + ret = dm_timer_init(); + if (ret) + return ret; +#endif + } ret = timer_get_count(gd->timer, &count); if (ret) -- cgit v1.3.1 From 01476eaf07514412cb9d8da6ddaf623d6b14d008 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 24 Feb 2016 09:14:51 -0700 Subject: sandbox: timer: Support the early timer Add support for the early timer so we can use tracing with sandbox again. Signed-off-by: Simon Glass --- drivers/timer/sandbox_timer.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/timer/sandbox_timer.c b/drivers/timer/sandbox_timer.c index a8da9363494..6a6411afeb3 100644 --- a/drivers/timer/sandbox_timer.c +++ b/drivers/timer/sandbox_timer.c @@ -10,6 +10,8 @@ #include #include +#define SANDBOX_TIMER_RATE 1000000 + /* system timer offset in ms */ static unsigned long sandbox_timer_offset; @@ -18,9 +20,19 @@ void sandbox_timer_add_offset(unsigned long offset) sandbox_timer_offset += offset; } -static int sandbox_timer_get_count(struct udevice *dev, u64 *count) +u64 notrace timer_early_get_count(void) +{ + return os_get_nsec() / 1000 + sandbox_timer_offset * 1000; +} + +unsigned long notrace timer_early_get_rate(void) +{ + return SANDBOX_TIMER_RATE; +} + +static notrace int sandbox_timer_get_count(struct udevice *dev, u64 *count) { - *count = os_get_nsec() / 1000 + sandbox_timer_offset * 1000; + *count = timer_early_get_count(); return 0; } @@ -30,7 +42,7 @@ static int sandbox_timer_probe(struct udevice *dev) struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev); if (!uc_priv->clock_rate) - uc_priv->clock_rate = 1000000; + uc_priv->clock_rate = SANDBOX_TIMER_RATE; return 0; } -- cgit v1.3.1 From 20f655da11cdddfeb0814197f9b3c71d4d297061 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 24 Feb 2016 09:14:54 -0700 Subject: sandbox: spi: Add more debugging to SPI emulation Add a little more debugging to help when things go wrong. Signed-off-by: Simon Glass Reviewed-by: Jagan Teki Tested-by: Jagan Teki --- drivers/mtd/spi/sandbox.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/spi/sandbox.c b/drivers/mtd/spi/sandbox.c index 895604d7367..ec07be71a1c 100644 --- a/drivers/mtd/spi/sandbox.c +++ b/drivers/mtd/spi/sandbox.c @@ -142,13 +142,15 @@ static int sandbox_sf_probe(struct udevice *dev) if (bus->seq < CONFIG_SANDBOX_SPI_MAX_BUS) spec = state->spi[bus->seq][cs].spec; if (!spec) { + debug("%s: No spec found for bus %d, cs %d\n", + __func__, bus->seq, cs); ret = -ENOENT; goto error; } file = strchr(spec, ':'); if (!file) { - printf("sandbox_sf: unable to parse file\n"); + printf("%s: unable to parse file\n", __func__); ret = -EINVAL; goto error; } @@ -174,7 +176,7 @@ static int sandbox_sf_probe(struct udevice *dev) break; } if (!data->name) { - printf("sandbox_sf: unknown flash '%*s'\n", (int)idname_len, + printf("%s: unknown flash '%*s'\n", __func__, (int)idname_len, spec); ret = -EINVAL; goto error; @@ -186,7 +188,7 @@ static int sandbox_sf_probe(struct udevice *dev) sbsf->fd = os_open(pdata->filename, 02); if (sbsf->fd == -1) { free(sbsf); - printf("sandbox_sf: unable to open file '%s'\n", + printf("%s: unable to open file '%s'\n", __func__, pdata->filename); ret = -EIO; goto error; @@ -553,6 +555,9 @@ static int sandbox_cmdline_cb_spi_sf(struct sandbox_state *state, * yet. Perhaps we can figure something out. */ state->spi[bus][cs].spec = spec; + debug("%s: Setting up spec '%s' for bus %ld, cs %ld\n", __func__, + spec, bus, cs); + return 0; } SANDBOX_CMDLINE_OPT(spi_sf, 1, "connect a SPI flash: :::"); @@ -671,6 +676,8 @@ int dm_scan_other(bool pre_reloc_only) __func__, busnum, cs); return ret; } + debug("%s: Setting up spec '%s' for bus %d, cs %d\n", + __func__, spec, busnum, cs); } } } -- cgit v1.3.1 From ffe276d27a538ca410d697126c562a1ce0ac8bbc Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 24 Feb 2016 09:14:55 -0700 Subject: sandbox: spi: Remove an incorrect free() We must not free data that is managed by driver mode. Remove this line, which is a hangover from the pre-driver-model code. This fixes a problem where 'sf probe' crashes U-Boot if the backing file for the SPI flash cannot be found. Signed-off-by: Simon Glass Reviewed-by: Jagan Teki Tested-by: Jagan Teki Reviewed-by: Tom Rini --- drivers/mtd/spi/sandbox.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/spi/sandbox.c b/drivers/mtd/spi/sandbox.c index ec07be71a1c..53470b90ce8 100644 --- a/drivers/mtd/spi/sandbox.c +++ b/drivers/mtd/spi/sandbox.c @@ -187,7 +187,6 @@ static int sandbox_sf_probe(struct udevice *dev) sbsf->fd = os_open(pdata->filename, 02); if (sbsf->fd == -1) { - free(sbsf); printf("%s: unable to open file '%s'\n", __func__, pdata->filename); ret = -EIO; -- cgit v1.3.1 From 0badb23d110c886cf25550325f36ce1eba1eb5e2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 24 Feb 2016 09:14:56 -0700 Subject: spi: Correct two error return values When an error number is provided we should use it, not change it. This fixes the SPI and SPI flash tests. One of these is long-standing. The other seems to have been introduced by commit 1e90d9fd (sf: Move read_id code to sf_ops). Signed-off-by: Simon Glass Fixes: 1e90d9fd (sf: Move read_id code to sf_ops) Reviewed-by: Jagan Teki Tested-by: Jagan Teki --- drivers/mtd/spi/sf_probe.c | 4 +--- drivers/mtd/spi/spi_flash.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index daa1d5b249e..7b296378d2b 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -42,10 +42,8 @@ static int spi_flash_probe_slave(struct spi_flash *flash) } ret = spi_flash_scan(flash); - if (ret) { - ret = -EINVAL; + if (ret) goto err_read_id; - } #ifdef CONFIG_SPI_FLASH_MTD ret = spi_flash_mtd_register(flash); diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 3c365d5e9ad..2ae2e3c8c9a 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -989,7 +989,7 @@ int spi_flash_scan(struct spi_flash *flash) ret = spi_flash_cmd(spi, CMD_READ_ID, idcode, sizeof(idcode)); if (ret) { printf("SF: Failed to get idcodes\n"); - return -EINVAL; + return ret; } #ifdef DEBUG -- cgit v1.3.1 From 6796704b0dfb4f98cb4a026988e9739884812b5c Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Wed, 17 Feb 2016 23:14:47 -0800 Subject: pci: Fix compiler warnings in dm_pciauto_setup_device() Fix the following compiler warnings when DEBUG is on. warning: 'bar_res' may be used uninitialized in this function. drivers/pci/pci_auto.c:101:21: if (!enum_only && pciauto_region_allocate(bar_res, bar_size, ^ Signed-off-by: Bin Meng Reviewed-by: Simon Glass --- drivers/pci/pci_auto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/pci/pci_auto.c b/drivers/pci/pci_auto.c index 88bc416c616..ee9a854bda4 100644 --- a/drivers/pci/pci_auto.c +++ b/drivers/pci/pci_auto.c @@ -30,7 +30,7 @@ void dm_pciauto_setup_device(struct udevice *dev, int bars_num, u8 header_type; int rom_addr; pci_addr_t bar_value; - struct pci_region *bar_res; + struct pci_region *bar_res = NULL; int found_mem64 = 0; u16 class; -- cgit v1.3.1