core.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 <mach/hardware.h>
  26. #include <mach/platform.h>
  27. #include <mach/cm.h>
  28. #include <mach/irqs.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/mach/time.h>
  31. #include <asm/pgtable.h>
  32. #include "common.h"
  33. #ifdef CONFIG_ATAGS
  34. #define INTEGRATOR_RTC_IRQ { IRQ_RTCINT }
  35. #define INTEGRATOR_UART0_IRQ { IRQ_UARTINT0 }
  36. #define INTEGRATOR_UART1_IRQ { IRQ_UARTINT1 }
  37. #define KMI0_IRQ { IRQ_KMIINT0 }
  38. #define KMI1_IRQ { IRQ_KMIINT1 }
  39. static AMBA_APB_DEVICE(rtc, "rtc", 0,
  40. INTEGRATOR_RTC_BASE, INTEGRATOR_RTC_IRQ, NULL);
  41. static AMBA_APB_DEVICE(uart0, "uart0", 0,
  42. INTEGRATOR_UART0_BASE, INTEGRATOR_UART0_IRQ, NULL);
  43. static AMBA_APB_DEVICE(uart1, "uart1", 0,
  44. INTEGRATOR_UART1_BASE, INTEGRATOR_UART1_IRQ, NULL);
  45. static AMBA_APB_DEVICE(kmi0, "kmi0", 0, KMI0_BASE, KMI0_IRQ, NULL);
  46. static AMBA_APB_DEVICE(kmi1, "kmi1", 0, KMI1_BASE, KMI1_IRQ, NULL);
  47. static struct amba_device *amba_devs[] __initdata = {
  48. &rtc_device,
  49. &uart0_device,
  50. &uart1_device,
  51. &kmi0_device,
  52. &kmi1_device,
  53. };
  54. int __init integrator_init(bool is_cp)
  55. {
  56. int i;
  57. /*
  58. * The Integrator/AP lacks necessary AMBA PrimeCell IDs, so we need to
  59. * hard-code them. The Integator/CP and forward have proper cell IDs.
  60. * Else we leave them undefined to the bus driver can autoprobe them.
  61. */
  62. if (!is_cp && IS_ENABLED(CONFIG_ARCH_INTEGRATOR_AP)) {
  63. rtc_device.periphid = 0x00041030;
  64. uart0_device.periphid = 0x00041010;
  65. uart1_device.periphid = 0x00041010;
  66. kmi0_device.periphid = 0x00041050;
  67. kmi1_device.periphid = 0x00041050;
  68. uart0_device.dev.platform_data = &ap_uart_data;
  69. uart1_device.dev.platform_data = &ap_uart_data;
  70. }
  71. for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  72. struct amba_device *d = amba_devs[i];
  73. amba_device_register(d, &iomem_resource);
  74. }
  75. return 0;
  76. }
  77. #endif
  78. static DEFINE_RAW_SPINLOCK(cm_lock);
  79. /**
  80. * cm_control - update the CM_CTRL register.
  81. * @mask: bits to change
  82. * @set: bits to set
  83. */
  84. void cm_control(u32 mask, u32 set)
  85. {
  86. unsigned long flags;
  87. u32 val;
  88. raw_spin_lock_irqsave(&cm_lock, flags);
  89. val = readl(CM_CTRL) & ~mask;
  90. writel(val | set, CM_CTRL);
  91. raw_spin_unlock_irqrestore(&cm_lock, flags);
  92. }
  93. EXPORT_SYMBOL(cm_control);
  94. /*
  95. * We need to stop things allocating the low memory; ideally we need a
  96. * better implementation of GFP_DMA which does not assume that DMA-able
  97. * memory starts at zero.
  98. */
  99. void __init integrator_reserve(void)
  100. {
  101. memblock_reserve(PHYS_OFFSET, __pa(swapper_pg_dir) - PHYS_OFFSET);
  102. }
  103. /*
  104. * To reset, we hit the on-board reset register in the system FPGA
  105. */
  106. void integrator_restart(char mode, const char *cmd)
  107. {
  108. cm_control(CM_CTRL_RESET, CM_CTRL_RESET);
  109. }
  110. static u32 integrator_id;
  111. static ssize_t intcp_get_manf(struct device *dev,
  112. struct device_attribute *attr,
  113. char *buf)
  114. {
  115. return sprintf(buf, "%02x\n", integrator_id >> 24);
  116. }
  117. static struct device_attribute intcp_manf_attr =
  118. __ATTR(manufacturer, S_IRUGO, intcp_get_manf, NULL);
  119. static ssize_t intcp_get_arch(struct device *dev,
  120. struct device_attribute *attr,
  121. char *buf)
  122. {
  123. const char *arch;
  124. switch ((integrator_id >> 16) & 0xff) {
  125. case 0x00:
  126. arch = "ASB little-endian";
  127. break;
  128. case 0x01:
  129. arch = "AHB little-endian";
  130. break;
  131. case 0x03:
  132. arch = "AHB-Lite system bus, bi-endian";
  133. break;
  134. case 0x04:
  135. arch = "AHB";
  136. break;
  137. default:
  138. arch = "Unknown";
  139. break;
  140. }
  141. return sprintf(buf, "%s\n", arch);
  142. }
  143. static struct device_attribute intcp_arch_attr =
  144. __ATTR(architecture, S_IRUGO, intcp_get_arch, NULL);
  145. static ssize_t intcp_get_fpga(struct device *dev,
  146. struct device_attribute *attr,
  147. char *buf)
  148. {
  149. const char *fpga;
  150. switch ((integrator_id >> 12) & 0xf) {
  151. case 0x01:
  152. fpga = "XC4062";
  153. break;
  154. case 0x02:
  155. fpga = "XC4085";
  156. break;
  157. case 0x04:
  158. fpga = "EPM7256AE (Altera PLD)";
  159. break;
  160. default:
  161. fpga = "Unknown";
  162. break;
  163. }
  164. return sprintf(buf, "%s\n", fpga);
  165. }
  166. static struct device_attribute intcp_fpga_attr =
  167. __ATTR(fpga, S_IRUGO, intcp_get_fpga, NULL);
  168. static ssize_t intcp_get_build(struct device *dev,
  169. struct device_attribute *attr,
  170. char *buf)
  171. {
  172. return sprintf(buf, "%02x\n", (integrator_id >> 4) & 0xFF);
  173. }
  174. static struct device_attribute intcp_build_attr =
  175. __ATTR(build, S_IRUGO, intcp_get_build, NULL);
  176. void integrator_init_sysfs(struct device *parent, u32 id)
  177. {
  178. integrator_id = id;
  179. device_create_file(parent, &intcp_manf_attr);
  180. device_create_file(parent, &intcp_arch_attr);
  181. device_create_file(parent, &intcp_fpga_attr);
  182. device_create_file(parent, &intcp_build_attr);
  183. }