platform.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * ARC HSDK Platform support code
  3. *
  4. * Copyright (C) 2017 Synopsys, Inc. (www.synopsys.com)
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/smp.h>
  12. #include <asm/arcregs.h>
  13. #include <asm/io.h>
  14. #include <asm/mach_desc.h>
  15. #define ARC_CCM_UNUSED_ADDR 0x60000000
  16. static void __init hsdk_init_per_cpu(unsigned int cpu)
  17. {
  18. /*
  19. * By default ICCM is mapped to 0x7z while this area is used for
  20. * kernel virtual mappings, so move it to currently unused area.
  21. */
  22. if (cpuinfo_arc700[cpu].iccm.sz)
  23. write_aux_reg(ARC_REG_AUX_ICCM, ARC_CCM_UNUSED_ADDR);
  24. /*
  25. * By default DCCM is mapped to 0x8z while this area is used by kernel,
  26. * so move it to currently unused area.
  27. */
  28. if (cpuinfo_arc700[cpu].dccm.sz)
  29. write_aux_reg(ARC_REG_AUX_DCCM, ARC_CCM_UNUSED_ADDR);
  30. }
  31. #define ARC_PERIPHERAL_BASE 0xf0000000
  32. #define CREG_BASE (ARC_PERIPHERAL_BASE + 0x1000)
  33. #define CREG_PAE (CREG_BASE + 0x180)
  34. #define CREG_PAE_UPDATE (CREG_BASE + 0x194)
  35. #define CREG_CORE_IF_CLK_DIV (CREG_BASE + 0x4B8)
  36. #define CREG_CORE_IF_CLK_DIV_2 0x1
  37. #define CGU_BASE ARC_PERIPHERAL_BASE
  38. #define CGU_PLL_STATUS (ARC_PERIPHERAL_BASE + 0x4)
  39. #define CGU_PLL_CTRL (ARC_PERIPHERAL_BASE + 0x0)
  40. #define CGU_PLL_STATUS_LOCK BIT(0)
  41. #define CGU_PLL_STATUS_ERR BIT(1)
  42. #define CGU_PLL_CTRL_1GHZ 0x3A10
  43. #define HSDK_PLL_LOCK_TIMEOUT 500
  44. #define HSDK_PLL_LOCKED() \
  45. !!(ioread32((void __iomem *) CGU_PLL_STATUS) & CGU_PLL_STATUS_LOCK)
  46. #define HSDK_PLL_ERR() \
  47. !!(ioread32((void __iomem *) CGU_PLL_STATUS) & CGU_PLL_STATUS_ERR)
  48. static void __init hsdk_set_cpu_freq_1ghz(void)
  49. {
  50. u32 timeout = HSDK_PLL_LOCK_TIMEOUT;
  51. /*
  52. * As we set cpu clock which exceeds 500MHz, the divider for the interface
  53. * clock must be programmed to div-by-2.
  54. */
  55. iowrite32(CREG_CORE_IF_CLK_DIV_2, (void __iomem *) CREG_CORE_IF_CLK_DIV);
  56. /* Set cpu clock to 1GHz */
  57. iowrite32(CGU_PLL_CTRL_1GHZ, (void __iomem *) CGU_PLL_CTRL);
  58. while (!HSDK_PLL_LOCKED() && timeout--)
  59. cpu_relax();
  60. if (!HSDK_PLL_LOCKED() || HSDK_PLL_ERR())
  61. pr_err("Failed to setup CPU frequency to 1GHz!");
  62. }
  63. #define SDIO_BASE (ARC_PERIPHERAL_BASE + 0xA000)
  64. #define SDIO_UHS_REG_EXT (SDIO_BASE + 0x108)
  65. #define SDIO_UHS_REG_EXT_DIV_2 (2 << 30)
  66. static void __init hsdk_init_early(void)
  67. {
  68. /*
  69. * PAE remapping for DMA clients does not work due to an RTL bug, so
  70. * CREG_PAE register must be programmed to all zeroes, otherwise it
  71. * will cause problems with DMA to/from peripherals even if PAE40 is
  72. * not used.
  73. */
  74. /* Default is 1, which means "PAE offset = 4GByte" */
  75. writel_relaxed(0, (void __iomem *) CREG_PAE);
  76. /* Really apply settings made above */
  77. writel(1, (void __iomem *) CREG_PAE_UPDATE);
  78. /*
  79. * Switch SDIO external ciu clock divider from default div-by-8 to
  80. * minimum possible div-by-2.
  81. */
  82. iowrite32(SDIO_UHS_REG_EXT_DIV_2, (void __iomem *) SDIO_UHS_REG_EXT);
  83. /*
  84. * Setup CPU frequency to 1GHz.
  85. * TODO: remove it after smart hsdk pll driver will be introduced.
  86. */
  87. hsdk_set_cpu_freq_1ghz();
  88. }
  89. static const char *hsdk_compat[] __initconst = {
  90. "snps,hsdk",
  91. NULL,
  92. };
  93. MACHINE_START(SIMULATION, "hsdk")
  94. .dt_compat = hsdk_compat,
  95. .init_early = hsdk_init_early,
  96. .init_per_cpu = hsdk_init_per_cpu,
  97. MACHINE_END