versatile.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Versatile board support using the device tree
  4. *
  5. * Copyright (C) 2010 Secret Lab Technologies Ltd.
  6. * Copyright (C) 2009 Jeremy Kerr <[email protected]>
  7. * Copyright (C) 2004 ARM Limited
  8. * Copyright (C) 2000 Deep Blue Solutions Ltd
  9. */
  10. #include <linux/init.h>
  11. #include <linux/io.h>
  12. #include <linux/of.h>
  13. #include <linux/of_address.h>
  14. #include <linux/of_irq.h>
  15. #include <linux/of_platform.h>
  16. #include <linux/slab.h>
  17. #include <linux/amba/bus.h>
  18. #include <linux/amba/mmci.h>
  19. #include <asm/mach-types.h>
  20. #include <asm/mach/arch.h>
  21. #include <asm/mach/map.h>
  22. /* macro to get at MMIO space when running virtually */
  23. #define IO_ADDRESS(x) (((x) & 0x0fffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
  24. #define __io_address(n) ((void __iomem __force *)IO_ADDRESS(n))
  25. /*
  26. * ------------------------------------------------------------------------
  27. * Versatile Registers
  28. * ------------------------------------------------------------------------
  29. */
  30. #define VERSATILE_SYS_PCICTL_OFFSET 0x44
  31. #define VERSATILE_SYS_MCI_OFFSET 0x48
  32. /*
  33. * VERSATILE peripheral addresses
  34. */
  35. #define VERSATILE_MMCI0_BASE 0x10005000 /* MMC interface */
  36. #define VERSATILE_MMCI1_BASE 0x1000B000 /* MMC Interface */
  37. #define VERSATILE_SCTL_BASE 0x101E0000 /* System controller */
  38. /*
  39. * System controller bit assignment
  40. */
  41. #define VERSATILE_REFCLK 0
  42. #define VERSATILE_TIMCLK 1
  43. #define VERSATILE_TIMER1_EnSel 15
  44. #define VERSATILE_TIMER2_EnSel 17
  45. #define VERSATILE_TIMER3_EnSel 19
  46. #define VERSATILE_TIMER4_EnSel 21
  47. static void __iomem *versatile_sys_base;
  48. unsigned int mmc_status(struct device *dev)
  49. {
  50. struct amba_device *adev = container_of(dev, struct amba_device, dev);
  51. u32 mask;
  52. if (adev->res.start == VERSATILE_MMCI0_BASE)
  53. mask = 1;
  54. else
  55. mask = 2;
  56. return readl(versatile_sys_base + VERSATILE_SYS_MCI_OFFSET) & mask;
  57. }
  58. static struct mmci_platform_data mmc0_plat_data = {
  59. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  60. .status = mmc_status,
  61. };
  62. static struct mmci_platform_data mmc1_plat_data = {
  63. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  64. .status = mmc_status,
  65. };
  66. /*
  67. * Lookup table for attaching a specific name and platform_data pointer to
  68. * devices as they get created by of_platform_populate(). Ideally this table
  69. * would not exist, but the current clock implementation depends on some devices
  70. * having a specific name.
  71. */
  72. struct of_dev_auxdata versatile_auxdata_lookup[] __initdata = {
  73. OF_DEV_AUXDATA("arm,primecell", VERSATILE_MMCI0_BASE, "fpga:05", &mmc0_plat_data),
  74. OF_DEV_AUXDATA("arm,primecell", VERSATILE_MMCI1_BASE, "fpga:0b", &mmc1_plat_data),
  75. {}
  76. };
  77. static struct map_desc versatile_io_desc[] __initdata __maybe_unused = {
  78. {
  79. .virtual = IO_ADDRESS(VERSATILE_SCTL_BASE),
  80. .pfn = __phys_to_pfn(VERSATILE_SCTL_BASE),
  81. .length = SZ_4K * 9,
  82. .type = MT_DEVICE
  83. }
  84. };
  85. static void __init versatile_map_io(void)
  86. {
  87. debug_ll_io_init();
  88. iotable_init(versatile_io_desc, ARRAY_SIZE(versatile_io_desc));
  89. }
  90. static void __init versatile_init_early(void)
  91. {
  92. u32 val;
  93. /*
  94. * set clock frequency:
  95. * VERSATILE_REFCLK is 32KHz
  96. * VERSATILE_TIMCLK is 1MHz
  97. */
  98. val = readl(__io_address(VERSATILE_SCTL_BASE));
  99. writel((VERSATILE_TIMCLK << VERSATILE_TIMER1_EnSel) |
  100. (VERSATILE_TIMCLK << VERSATILE_TIMER2_EnSel) |
  101. (VERSATILE_TIMCLK << VERSATILE_TIMER3_EnSel) |
  102. (VERSATILE_TIMCLK << VERSATILE_TIMER4_EnSel) | val,
  103. __io_address(VERSATILE_SCTL_BASE));
  104. }
  105. static void __init versatile_dt_pci_init(void)
  106. {
  107. u32 val;
  108. struct device_node *np;
  109. struct property *newprop;
  110. np = of_find_compatible_node(NULL, NULL, "arm,versatile-pci");
  111. if (!np)
  112. return;
  113. /* Check if PCI backplane is detected */
  114. val = readl(versatile_sys_base + VERSATILE_SYS_PCICTL_OFFSET);
  115. if (val & 1) {
  116. /*
  117. * Enable PCI accesses. Note that the documentaton is
  118. * inconsistent whether or not this is needed, but the old
  119. * driver had it so we will keep it.
  120. */
  121. writel(1, versatile_sys_base + VERSATILE_SYS_PCICTL_OFFSET);
  122. goto out_put_node;
  123. }
  124. newprop = kzalloc(sizeof(*newprop), GFP_KERNEL);
  125. if (!newprop)
  126. goto out_put_node;
  127. newprop->name = kstrdup("status", GFP_KERNEL);
  128. newprop->value = kstrdup("disabled", GFP_KERNEL);
  129. newprop->length = sizeof("disabled");
  130. of_update_property(np, newprop);
  131. pr_info("Not plugged into PCI backplane!\n");
  132. out_put_node:
  133. of_node_put(np);
  134. }
  135. static void __init versatile_dt_init(void)
  136. {
  137. struct device_node *np;
  138. np = of_find_compatible_node(NULL, NULL, "arm,core-module-versatile");
  139. if (np)
  140. versatile_sys_base = of_iomap(np, 0);
  141. WARN_ON(!versatile_sys_base);
  142. versatile_dt_pci_init();
  143. of_platform_default_populate(NULL, versatile_auxdata_lookup, NULL);
  144. }
  145. static const char *const versatile_dt_match[] __initconst = {
  146. "arm,versatile-ab",
  147. "arm,versatile-pb",
  148. NULL,
  149. };
  150. DT_MACHINE_START(VERSATILE_PB, "ARM-Versatile (Device Tree Support)")
  151. .map_io = versatile_map_io,
  152. .init_early = versatile_init_early,
  153. .init_machine = versatile_dt_init,
  154. .dt_compat = versatile_dt_match,
  155. MACHINE_END