kona.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (C) 2013 Broadcom Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation version 2.
  7. *
  8. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  9. * kind, whether express or implied; without even the implied warranty
  10. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/of_address.h>
  14. #include <asm/io.h>
  15. #include "kona.h"
  16. static void __iomem *watchdog_base;
  17. void bcm_kona_setup_restart(void)
  18. {
  19. struct device_node *np_wdog;
  20. /*
  21. * The assumption is that whoever calls bcm_kona_setup_restart()
  22. * also needs a Kona Watchdog Timer entry in Device Tree, i.e. we
  23. * report an error if the DT entry is missing.
  24. */
  25. np_wdog = of_find_compatible_node(NULL, NULL, "brcm,kona-wdt");
  26. if (!np_wdog) {
  27. pr_err("brcm,kona-wdt not found in DT, reboot disabled\n");
  28. return;
  29. }
  30. watchdog_base = of_iomap(np_wdog, 0);
  31. WARN(!watchdog_base, "failed to map watchdog base");
  32. of_node_put(np_wdog);
  33. }
  34. #define SECWDOG_OFFSET 0x00000000
  35. #define SECWDOG_RESERVED_MASK 0xE2000000
  36. #define SECWDOG_WD_LOAD_FLAG_MASK 0x10000000
  37. #define SECWDOG_EN_MASK 0x08000000
  38. #define SECWDOG_SRSTEN_MASK 0x04000000
  39. #define SECWDOG_CLKS_SHIFT 20
  40. #define SECWDOG_LOCK_SHIFT 0
  41. void bcm_kona_restart(enum reboot_mode mode, const char *cmd)
  42. {
  43. uint32_t val;
  44. if (!watchdog_base)
  45. panic("Watchdog not mapped. Reboot failed.\n");
  46. /* Enable watchdog2 with very short timeout. */
  47. val = readl(watchdog_base + SECWDOG_OFFSET);
  48. val &= SECWDOG_RESERVED_MASK | SECWDOG_WD_LOAD_FLAG_MASK;
  49. val |= SECWDOG_EN_MASK | SECWDOG_SRSTEN_MASK |
  50. (0x8 << SECWDOG_CLKS_SHIFT) |
  51. (0x8 << SECWDOG_LOCK_SHIFT);
  52. writel(val, watchdog_base + SECWDOG_OFFSET);
  53. while (1)
  54. ;
  55. }