core.c 4.7 KB

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