cpu.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 2005-2006 Atmel Corporation
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. #include <asm/io.h>
  9. #include <asm/sections.h>
  10. #include <asm/sysreg.h>
  11. #include <asm/arch/clk.h>
  12. #include <asm/arch/hardware.h>
  13. #include "hsmc3.h"
  14. /* Sanity checks */
  15. #if (CONFIG_SYS_CLKDIV_CPU > CONFIG_SYS_CLKDIV_HSB) \
  16. || (CONFIG_SYS_CLKDIV_HSB > CONFIG_SYS_CLKDIV_PBA) \
  17. || (CONFIG_SYS_CLKDIV_HSB > CONFIG_SYS_CLKDIV_PBB)
  18. # error Constraint fCPU >= fHSB >= fPB{A,B} violated
  19. #endif
  20. #if defined(CONFIG_PLL) && ((CONFIG_SYS_PLL0_MUL < 1) || (CONFIG_SYS_PLL0_DIV < 1))
  21. # error Invalid PLL multiplier and/or divider
  22. #endif
  23. DECLARE_GLOBAL_DATA_PTR;
  24. int arch_cpu_init(void)
  25. {
  26. extern void _evba(void);
  27. gd->arch.cpu_hz = CONFIG_SYS_OSC0_HZ;
  28. /* TODO: Move somewhere else, but needs to be run before we
  29. * increase the clock frequency. */
  30. hsmc3_writel(MODE0, 0x00031103);
  31. hsmc3_writel(CYCLE0, 0x000c000d);
  32. hsmc3_writel(PULSE0, 0x0b0a0906);
  33. hsmc3_writel(SETUP0, 0x00010002);
  34. clk_init();
  35. /* Update the CPU speed according to the PLL configuration */
  36. gd->arch.cpu_hz = get_cpu_clk_rate();
  37. /* Set up the exception handler table and enable exceptions */
  38. sysreg_write(EVBA, (unsigned long)&_evba);
  39. asm volatile("csrf %0" : : "i"(SYSREG_EM_OFFSET));
  40. return 0;
  41. }
  42. void prepare_to_boot(void)
  43. {
  44. /* Flush both caches and the write buffer */
  45. asm volatile("cache %0[4], 010\n\t"
  46. "cache %0[0], 000\n\t"
  47. "sync 0" : : "r"(0) : "memory");
  48. }
  49. int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  50. {
  51. /* This will reset the CPU core, caches, MMU and all internal busses */
  52. __builtin_mtdr(8, 1 << 13); /* set DC:DBE */
  53. __builtin_mtdr(8, 1 << 30); /* set DC:RES */
  54. /* Flush the pipeline before we declare it a failure */
  55. asm volatile("sub pc, pc, -4");
  56. return -1;
  57. }