Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…t-watchdog into next

- misc cyclic infrastructure improvements (Rasmus)
- watchdog_reset cleanup (Rasmus)

CI: https://dev.azure.com/sr0718/u-boot/_build/results?buildId=369&view=results
  • Loading branch information
trini committed Jun 16, 2024
2 parents d8c213c + 85c4767 commit e242cd9
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 321 deletions.
108 changes: 0 additions & 108 deletions arch/m68k/cpu/mcf52x2/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,6 @@ int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
return 0;
};

#if defined(CONFIG_WATCHDOG)
void watchdog_reset(void)
{
mbar_writeShort(MCF_WTM_WSR, 0x5555);
mbar_writeShort(MCF_WTM_WSR, 0xAAAA);
}

int watchdog_disable(void)
{
mbar_writeShort(MCF_WTM_WCR, 0);
return (0);
}

int watchdog_init(void)
{
mbar_writeShort(MCF_WTM_WCR, MCF_WTM_WCR_EN);
return (0);
}
#endif /* #ifdef CONFIG_WATCHDOG */

#endif

#ifdef CONFIG_M5272
Expand Down Expand Up @@ -174,49 +154,6 @@ int print_cpuinfo(void)
};
#endif /* CONFIG_DISPLAY_CPUINFO */

#if defined(CONFIG_WATCHDOG)
/* Called by macro WATCHDOG_RESET */
void watchdog_reset(void)
{
wdog_t *wdt = (wdog_t *)(MMAP_WDOG);

out_be16(&wdt->wdog_wcr, 0);
}

int watchdog_disable(void)
{
wdog_t *wdt = (wdog_t *)(MMAP_WDOG);

/* reset watchdog counter */
out_be16(&wdt->wdog_wcr, 0);
/* disable watchdog interrupt */
out_be16(&wdt->wdog_wirr, 0);
/* disable watchdog timer */
out_be16(&wdt->wdog_wrrr, 0);

puts("WATCHDOG:disabled\n");
return (0);
}

int watchdog_init(void)
{
wdog_t *wdt = (wdog_t *)(MMAP_WDOG);

/* disable watchdog interrupt */
out_be16(&wdt->wdog_wirr, 0);

/* set timeout and enable watchdog */
out_be16(&wdt->wdog_wrrr,
(CONFIG_WATCHDOG_TIMEOUT_MSECS * CONFIG_SYS_HZ) / (32768 * 1000) - 1);

/* reset watchdog counter */
out_be16(&wdt->wdog_wcr, 0);

puts("WATCHDOG:enabled\n");
return (0);
}
#endif /* #ifdef CONFIG_WATCHDOG */

#endif /* #ifdef CONFIG_M5272 */

#ifdef CONFIG_M5275
Expand All @@ -243,51 +180,6 @@ int print_cpuinfo(void)
};
#endif /* CONFIG_DISPLAY_CPUINFO */

#if defined(CONFIG_WATCHDOG)
/* Called by macro WATCHDOG_RESET */
void watchdog_reset(void)
{
wdog_t *wdt = (wdog_t *)(MMAP_WDOG);

out_be16(&wdt->wsr, 0x5555);
out_be16(&wdt->wsr, 0xaaaa);
}

int watchdog_disable(void)
{
wdog_t *wdt = (wdog_t *)(MMAP_WDOG);

/* reset watchdog counter */
out_be16(&wdt->wsr, 0x5555);
out_be16(&wdt->wsr, 0xaaaa);

/* disable watchdog timer */
out_be16(&wdt->wcr, 0);

puts("WATCHDOG:disabled\n");
return (0);
}

int watchdog_init(void)
{
wdog_t *wdt = (wdog_t *)(MMAP_WDOG);

/* disable watchdog */
out_be16(&wdt->wcr, 0);

/* set timeout and enable watchdog */
out_be16(&wdt->wmr,
(CONFIG_WATCHDOG_TIMEOUT_MSECS * CONFIG_SYS_HZ) / (32768 * 1000) - 1);

/* reset watchdog counter */
out_be16(&wdt->wsr, 0x5555);
out_be16(&wdt->wsr, 0xaaaa);

puts("WATCHDOG:enabled\n");
return (0);
}
#endif /* #ifdef CONFIG_WATCHDOG */

#endif /* #ifdef CONFIG_M5275 */

#ifdef CONFIG_M5282
Expand Down
15 changes: 0 additions & 15 deletions arch/powerpc/cpu/mpc83xx/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,6 @@ unsigned long get_tbclk(void)
}
#endif

#if defined(CONFIG_WATCHDOG) && !defined(CONFIG_WDT)
void watchdog_reset (void)
{
int re_enable = disable_interrupts();

/* Reset the 83xx watchdog */
volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
immr->wdt.swsrr = 0x556c;
immr->wdt.swsrr = 0xaa39;

if (re_enable)
enable_interrupts();
}
#endif

/*
* Initializes on-chip MMC controllers.
* to override, implement board_mmc_init()
Expand Down
31 changes: 0 additions & 31 deletions arch/powerpc/cpu/mpc85xx/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,37 +349,6 @@ __weak unsigned long get_tbclk(void)
}


#ifndef CONFIG_WDT
#if defined(CONFIG_WATCHDOG)
#define WATCHDOG_MASK (TCR_WP(63) | TCR_WRC(3) | TCR_WIE)
void
init_85xx_watchdog(void)
{
mtspr(SPRN_TCR, (mfspr(SPRN_TCR) & ~WATCHDOG_MASK) |
TCR_WP(CFG_WATCHDOG_PRESC) | TCR_WRC(CFG_WATCHDOG_RC));
}

void
reset_85xx_watchdog(void)
{
/*
* Clear TSR(WIS) bit by writing 1
*/
mtspr(SPRN_TSR, TSR_WIS);
}

void
watchdog_reset(void)
{
int re_enable = disable_interrupts();

reset_85xx_watchdog();
if (re_enable)
enable_interrupts();
}
#endif /* CONFIG_WATCHDOG */
#endif

/*
* Initializes on-chip MMC controllers.
* to override, implement board_mmc_init()
Expand Down
2 changes: 1 addition & 1 deletion arch/sh/cpu/sh4/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# (C) Copyright 2007
# Nobuhiro Iwamatsu <iwamatsu@nigauri.org>

obj-y = cpu.o interrupts.o watchdog.o cache.o
obj-y = cpu.o interrupts.o cache.o
10 changes: 10 additions & 0 deletions arch/sh/cpu/sh4/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
#include <net.h>
#include <netdev.h>
#include <asm/processor.h>
#include <asm/system.h>

void reset_cpu(void)
{
/* Address error with SR.BL=1 first. */
trigger_address_error();

while (1)
;
}

int checkcpu(void)
{
Expand Down
60 changes: 0 additions & 60 deletions arch/sh/cpu/sh4/watchdog.c

This file was deleted.

11 changes: 7 additions & 4 deletions board/Marvell/octeon_nic23/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void board_configure_qlms(void)
* read the incorrect device ID 0x9700 (reset value) instead of 0x9702
* (restored value).
*/
static void octeon_board_restore_pf(void *ctx)
static void octeon_board_restore_pf(struct cyclic_info *c)
{
union cvmx_spemx_flr_pf_stopreq stopreq;
static bool start_initialized[2] = {false, false};
Expand Down Expand Up @@ -357,10 +357,13 @@ int board_late_init(void)
board_configure_qlms();

/* Register cyclic function for PCIe FLR fixup */
cyclic = cyclic_register(octeon_board_restore_pf, 100,
"pcie_flr_fix", NULL);
if (!cyclic)
cyclic = calloc(1, sizeof(*cyclic));
if (cyclic) {
cyclic_register(cyclic, octeon_board_restore_pf, 100,
"pcie_flr_fix");
} else {
printf("Registering of cyclic function failed\n");
}

return 0;
}
Expand Down
12 changes: 5 additions & 7 deletions cmd/cyclic.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
#include <time.h>
#include <vsprintf.h>
#include <linux/delay.h>
#include <linux/kernel.h>

struct cyclic_demo_info {
struct cyclic_info cyclic;
uint delay_us;
};

static void cyclic_demo(void *ctx)
static void cyclic_demo(struct cyclic_info *c)
{
struct cyclic_demo_info *info = ctx;
struct cyclic_demo_info *info = container_of(c, struct cyclic_demo_info, cyclic);

/* Just a small dummy delay here */
udelay(info->delay_us);
Expand All @@ -32,7 +34,6 @@ static int do_cyclic_demo(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
struct cyclic_demo_info *info;
struct cyclic_info *cyclic;
uint time_ms;

if (argc < 3)
Expand All @@ -48,10 +49,7 @@ static int do_cyclic_demo(struct cmd_tbl *cmdtp, int flag, int argc,
info->delay_us = simple_strtoul(argv[2], NULL, 0);

/* Register demo cyclic function */
cyclic = cyclic_register(cyclic_demo, time_ms * 1000, "cyclic_demo",
info);
if (!cyclic)
printf("Registering of cyclic_demo failed\n");
cyclic_register(&info->cyclic, cyclic_demo, time_ms * 1000, "cyclic_demo");

printf("Registered function \"%s\" to be executed all %dms\n",
"cyclic_demo", time_ms);
Expand Down
24 changes: 6 additions & 18 deletions common/cyclic.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,22 @@ struct hlist_head *cyclic_get_list(void)
return (struct hlist_head *)&gd->cyclic_list;
}

struct cyclic_info *cyclic_register(cyclic_func_t func, uint64_t delay_us,
const char *name, void *ctx)
void cyclic_register(struct cyclic_info *cyclic, cyclic_func_t func,
uint64_t delay_us, const char *name)
{
struct cyclic_info *cyclic;

cyclic = calloc(1, sizeof(struct cyclic_info));
if (!cyclic) {
pr_debug("Memory allocation error\n");
return NULL;
}
memset(cyclic, 0, sizeof(*cyclic));

/* Store values in struct */
cyclic->func = func;
cyclic->ctx = ctx;
cyclic->name = strdup(name);
cyclic->name = name;
cyclic->delay_us = delay_us;
cyclic->start_time_us = timer_get_us();
hlist_add_head(&cyclic->list, cyclic_get_list());

return cyclic;
}

int cyclic_unregister(struct cyclic_info *cyclic)
void cyclic_unregister(struct cyclic_info *cyclic)
{
hlist_del(&cyclic->list);
free(cyclic);

return 0;
}

void cyclic_run(void)
Expand All @@ -76,7 +64,7 @@ void cyclic_run(void)
if (time_after_eq64(now, cyclic->next_call)) {
/* Call cyclic function and account it's cpu-time */
cyclic->next_call = now + cyclic->delay_us;
cyclic->func(cyclic->ctx);
cyclic->func(cyclic);
cyclic->run_cnt++;
cpu_time = timer_get_us() - now;
cyclic->cpu_time_us += cpu_time;
Expand Down
Loading

0 comments on commit e242cd9

Please sign in to comment.