common.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * arch/arm/mach-mcs814x/common.c
  3. *
  4. * Core functions for Moschip MCS814x SoCs
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/io.h>
  13. #include <linux/gpio.h>
  14. #include <linux/of.h>
  15. #include <linux/of_address.h>
  16. #include <linux/reboot.h>
  17. #include <asm/setup.h>
  18. #include <asm/mach-types.h>
  19. #include <asm/mach/arch.h>
  20. #include <mach/mcs814x.h>
  21. #include <mach/cpu.h>
  22. #include <asm/pgtable.h>
  23. #include <asm/mach/map.h>
  24. void __iomem *mcs814x_sysdbg_base;
  25. static struct map_desc mcs814x_io_desc[] __initdata = {
  26. {
  27. .virtual = MCS814X_IO_BASE,
  28. .pfn = __phys_to_pfn(MCS814X_IO_START),
  29. .length = MCS814X_IO_SIZE,
  30. .type = MT_DEVICE
  31. },
  32. };
  33. struct cpu_mode {
  34. const char *name;
  35. int gpio_start;
  36. int gpio_end;
  37. };
  38. static const struct cpu_mode cpu_modes[] = {
  39. {
  40. .name = "I2S",
  41. .gpio_start = 4,
  42. .gpio_end = 8,
  43. },
  44. {
  45. .name = "UART",
  46. .gpio_start = 4,
  47. .gpio_end = 9,
  48. },
  49. {
  50. .name = "External MII",
  51. .gpio_start = 0,
  52. .gpio_end = 16,
  53. },
  54. {
  55. .name = "Normal",
  56. .gpio_start = -1,
  57. .gpio_end = -1,
  58. },
  59. };
  60. static void mcs814x_eth_hardware_filter_set(u8 value)
  61. {
  62. u32 reg;
  63. reg = readl_relaxed(MCS814X_VIRT_BASE + MCS814X_DBGLED);
  64. if (value)
  65. reg |= 0x80;
  66. else
  67. reg &= ~0x80;
  68. writel_relaxed(reg, MCS814X_VIRT_BASE + MCS814X_DBGLED);
  69. }
  70. static void mcs814x_eth_led_cfg_set(u8 cfg)
  71. {
  72. u32 reg;
  73. reg = readl_relaxed(mcs814x_sysdbg_base + SYSDBG_BS2);
  74. reg &= ~LED_CFG_MASK;
  75. reg |= cfg;
  76. writel_relaxed(reg, mcs814x_sysdbg_base + SYSDBG_BS2);
  77. }
  78. static void mcs814x_eth_buffer_shifting_set(u8 value)
  79. {
  80. u8 reg;
  81. reg = readb_relaxed(mcs814x_sysdbg_base + SYSDBG_SYSCTL_MAC);
  82. if (value)
  83. reg |= BUF_SHIFT_BIT;
  84. else
  85. reg &= ~BUF_SHIFT_BIT;
  86. writeb_relaxed(reg, mcs814x_sysdbg_base + SYSDBG_SYSCTL_MAC);
  87. }
  88. static struct of_device_id mcs814x_eth_ids[] __initdata = {
  89. { .compatible = "moschip,nuport-mac", },
  90. { /* sentinel */ },
  91. };
  92. /* Configure platform specific knobs based on ethernet device node
  93. * properties */
  94. static void mcs814x_eth_init(void)
  95. {
  96. struct device_node *np;
  97. const unsigned int *intspec;
  98. np = of_find_matching_node(NULL, mcs814x_eth_ids);
  99. if (!np)
  100. return;
  101. /* hardware filter must always be enabled */
  102. mcs814x_eth_hardware_filter_set(1);
  103. intspec = of_get_property(np, "nuport-mac,buffer-shifting", NULL);
  104. if (!intspec)
  105. mcs814x_eth_buffer_shifting_set(0);
  106. else
  107. mcs814x_eth_buffer_shifting_set(1);
  108. intspec = of_get_property(np, "nuport-mac,link-activity", NULL);
  109. if (intspec)
  110. mcs814x_eth_led_cfg_set(be32_to_cpup(intspec));
  111. of_node_put(np);
  112. }
  113. void __init mcs814x_init_machine(void)
  114. {
  115. u32 bs2, cpu_mode;
  116. int gpio;
  117. bs2 = readl_relaxed(mcs814x_sysdbg_base + SYSDBG_BS2);
  118. cpu_mode = (bs2 >> CPU_MODE_SHIFT) & CPU_MODE_MASK;
  119. pr_info("CPU mode: %s\n", cpu_modes[cpu_mode].name);
  120. /* request the gpios since the pins are muxed for functionnality */
  121. for (gpio = cpu_modes[cpu_mode].gpio_start;
  122. gpio == cpu_modes[cpu_mode].gpio_end; gpio++) {
  123. if (gpio != -1)
  124. gpio_request(gpio, cpu_modes[cpu_mode].name);
  125. }
  126. mcs814x_eth_init();
  127. }
  128. void __init mcs814x_map_io(void)
  129. {
  130. iotable_init(mcs814x_io_desc, ARRAY_SIZE(mcs814x_io_desc));
  131. mcs814x_sysdbg_base = ioremap(MCS814X_IO_START + MCS814X_SYSDBG,
  132. MCS814X_SYSDBG_SIZE);
  133. if (!mcs814x_sysdbg_base)
  134. panic("unable to remap sysdbg base");
  135. }
  136. void mcs814x_restart(enum reboot_mode mode, const char *cmd)
  137. {
  138. writel_relaxed(~(1 << 31), mcs814x_sysdbg_base);
  139. }