core.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * linux/arch/arm/mach-integrator/core.c
  3. *
  4. * Copyright (C) 2000-2003 Deep Blue Solutions Ltd
  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/types.h>
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/device.h>
  14. #include <linux/export.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/irq.h>
  18. #include <linux/memblock.h>
  19. #include <linux/sched.h>
  20. #include <linux/smp.h>
  21. #include <linux/amba/bus.h>
  22. #include <linux/amba/serial.h>
  23. #include <linux/io.h>
  24. #include <linux/stat.h>
  25. #include <linux/of.h>
  26. #include <linux/of_address.h>
  27. #include <mach/hardware.h>
  28. #include <mach/platform.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/mach/time.h>
  31. #include <asm/pgtable.h>
  32. #include "cm.h"
  33. #include "common.h"
  34. static DEFINE_RAW_SPINLOCK(cm_lock);
  35. static void __iomem *cm_base;
  36. /**
  37. * cm_get - get the value from the CM_CTRL register
  38. */
  39. u32 cm_get(void)
  40. {
  41. return readl(cm_base + INTEGRATOR_HDR_CTRL_OFFSET);
  42. }
  43. /**
  44. * cm_control - update the CM_CTRL register.
  45. * @mask: bits to change
  46. * @set: bits to set
  47. */
  48. void cm_control(u32 mask, u32 set)
  49. {
  50. unsigned long flags;
  51. u32 val;
  52. raw_spin_lock_irqsave(&cm_lock, flags);
  53. val = readl(cm_base + INTEGRATOR_HDR_CTRL_OFFSET) & ~mask;
  54. writel(val | set, cm_base + INTEGRATOR_HDR_CTRL_OFFSET);
  55. raw_spin_unlock_irqrestore(&cm_lock, flags);
  56. }
  57. static const char *integrator_arch_str(u32 id)
  58. {
  59. switch ((id >> 16) & 0xff) {
  60. case 0x00:
  61. return "ASB little-endian";
  62. case 0x01:
  63. return "AHB little-endian";
  64. case 0x03:
  65. return "AHB-Lite system bus, bi-endian";
  66. case 0x04:
  67. return "AHB";
  68. case 0x08:
  69. return "AHB system bus, ASB processor bus";
  70. default:
  71. return "Unknown";
  72. }
  73. }
  74. static const char *integrator_fpga_str(u32 id)
  75. {
  76. switch ((id >> 12) & 0xf) {
  77. case 0x01:
  78. return "XC4062";
  79. case 0x02:
  80. return "XC4085";
  81. case 0x03:
  82. return "XVC600";
  83. case 0x04:
  84. return "EPM7256AE (Altera PLD)";
  85. default:
  86. return "Unknown";
  87. }
  88. }
  89. void cm_clear_irqs(void)
  90. {
  91. /* disable core module IRQs */
  92. writel(0xffffffffU, cm_base + INTEGRATOR_HDR_IC_OFFSET +
  93. IRQ_ENABLE_CLEAR);
  94. }
  95. static const struct of_device_id cm_match[] = {
  96. { .compatible = "arm,core-module-integrator"},
  97. { },
  98. };
  99. void cm_init(void)
  100. {
  101. struct device_node *cm = of_find_matching_node(NULL, cm_match);
  102. u32 val;
  103. if (!cm) {
  104. pr_crit("no core module node found in device tree\n");
  105. return;
  106. }
  107. cm_base = of_iomap(cm, 0);
  108. if (!cm_base) {
  109. pr_crit("could not remap core module\n");
  110. return;
  111. }
  112. cm_clear_irqs();
  113. val = readl(cm_base + INTEGRATOR_HDR_ID_OFFSET);
  114. pr_info("Detected ARM core module:\n");
  115. pr_info(" Manufacturer: %02x\n", (val >> 24));
  116. pr_info(" Architecture: %s\n", integrator_arch_str(val));
  117. pr_info(" FPGA: %s\n", integrator_fpga_str(val));
  118. pr_info(" Build: %02x\n", (val >> 4) & 0xFF);
  119. pr_info(" Rev: %c\n", ('A' + (val & 0x03)));
  120. }
  121. /*
  122. * We need to stop things allocating the low memory; ideally we need a
  123. * better implementation of GFP_DMA which does not assume that DMA-able
  124. * memory starts at zero.
  125. */
  126. void __init integrator_reserve(void)
  127. {
  128. memblock_reserve(PHYS_OFFSET, __pa(swapper_pg_dir) - PHYS_OFFSET);
  129. }
  130. /*
  131. * To reset, we hit the on-board reset register in the system FPGA
  132. */
  133. void integrator_restart(enum reboot_mode mode, const char *cmd)
  134. {
  135. cm_control(CM_CTRL_RESET, CM_CTRL_RESET);
  136. }
  137. static u32 integrator_id;
  138. static ssize_t intcp_get_manf(struct device *dev,
  139. struct device_attribute *attr,
  140. char *buf)
  141. {
  142. return sprintf(buf, "%02x\n", integrator_id >> 24);
  143. }
  144. static struct device_attribute intcp_manf_attr =
  145. __ATTR(manufacturer, S_IRUGO, intcp_get_manf, NULL);
  146. static ssize_t intcp_get_arch(struct device *dev,
  147. struct device_attribute *attr,
  148. char *buf)
  149. {
  150. return sprintf(buf, "%s\n", integrator_arch_str(integrator_id));
  151. }
  152. static struct device_attribute intcp_arch_attr =
  153. __ATTR(architecture, S_IRUGO, intcp_get_arch, NULL);
  154. static ssize_t intcp_get_fpga(struct device *dev,
  155. struct device_attribute *attr,
  156. char *buf)
  157. {
  158. return sprintf(buf, "%s\n", integrator_fpga_str(integrator_id));
  159. }
  160. static struct device_attribute intcp_fpga_attr =
  161. __ATTR(fpga, S_IRUGO, intcp_get_fpga, NULL);
  162. static ssize_t intcp_get_build(struct device *dev,
  163. struct device_attribute *attr,
  164. char *buf)
  165. {
  166. return sprintf(buf, "%02x\n", (integrator_id >> 4) & 0xFF);
  167. }
  168. static struct device_attribute intcp_build_attr =
  169. __ATTR(build, S_IRUGO, intcp_get_build, NULL);
  170. void integrator_init_sysfs(struct device *parent, u32 id)
  171. {
  172. integrator_id = id;
  173. device_create_file(parent, &intcp_manf_attr);
  174. device_create_file(parent, &intcp_arch_attr);
  175. device_create_file(parent, &intcp_fpga_attr);
  176. device_create_file(parent, &intcp_build_attr);
  177. }