integrator_ap.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /*
  2. * linux/arch/arm/mach-integrator/integrator_ap.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 as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/types.h>
  21. #include <linux/kernel.h>
  22. #include <linux/init.h>
  23. #include <linux/list.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/slab.h>
  26. #include <linux/string.h>
  27. #include <linux/sysdev.h>
  28. #include <linux/amba/bus.h>
  29. #include <linux/amba/kmi.h>
  30. #include <linux/io.h>
  31. #include <mach/hardware.h>
  32. #include <mach/platform.h>
  33. #include <asm/irq.h>
  34. #include <asm/setup.h>
  35. #include <asm/param.h> /* HZ */
  36. #include <asm/mach-types.h>
  37. #include <mach/lm.h>
  38. #include <asm/mach/arch.h>
  39. #include <asm/mach/flash.h>
  40. #include <asm/mach/irq.h>
  41. #include <asm/mach/map.h>
  42. #include <asm/mach/time.h>
  43. #include "common.h"
  44. /*
  45. * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
  46. * is the (PA >> 12).
  47. *
  48. * Setup a VA for the Integrator interrupt controller (for header #0,
  49. * just for now).
  50. */
  51. #define VA_IC_BASE IO_ADDRESS(INTEGRATOR_IC_BASE)
  52. #define VA_SC_BASE IO_ADDRESS(INTEGRATOR_SC_BASE)
  53. #define VA_EBI_BASE IO_ADDRESS(INTEGRATOR_EBI_BASE)
  54. #define VA_CMIC_BASE IO_ADDRESS(INTEGRATOR_HDR_BASE) + INTEGRATOR_HDR_IC_OFFSET
  55. /*
  56. * Logical Physical
  57. * e8000000 40000000 PCI memory PHYS_PCI_MEM_BASE (max 512M)
  58. * ec000000 61000000 PCI config space PHYS_PCI_CONFIG_BASE (max 16M)
  59. * ed000000 62000000 PCI V3 regs PHYS_PCI_V3_BASE (max 64k)
  60. * ee000000 60000000 PCI IO PHYS_PCI_IO_BASE (max 16M)
  61. * ef000000 Cache flush
  62. * f1000000 10000000 Core module registers
  63. * f1100000 11000000 System controller registers
  64. * f1200000 12000000 EBI registers
  65. * f1300000 13000000 Counter/Timer
  66. * f1400000 14000000 Interrupt controller
  67. * f1600000 16000000 UART 0
  68. * f1700000 17000000 UART 1
  69. * f1a00000 1a000000 Debug LEDs
  70. * f1b00000 1b000000 GPIO
  71. */
  72. static struct map_desc ap_io_desc[] __initdata = {
  73. {
  74. .virtual = IO_ADDRESS(INTEGRATOR_HDR_BASE),
  75. .pfn = __phys_to_pfn(INTEGRATOR_HDR_BASE),
  76. .length = SZ_4K,
  77. .type = MT_DEVICE
  78. }, {
  79. .virtual = IO_ADDRESS(INTEGRATOR_SC_BASE),
  80. .pfn = __phys_to_pfn(INTEGRATOR_SC_BASE),
  81. .length = SZ_4K,
  82. .type = MT_DEVICE
  83. }, {
  84. .virtual = IO_ADDRESS(INTEGRATOR_EBI_BASE),
  85. .pfn = __phys_to_pfn(INTEGRATOR_EBI_BASE),
  86. .length = SZ_4K,
  87. .type = MT_DEVICE
  88. }, {
  89. .virtual = IO_ADDRESS(INTEGRATOR_CT_BASE),
  90. .pfn = __phys_to_pfn(INTEGRATOR_CT_BASE),
  91. .length = SZ_4K,
  92. .type = MT_DEVICE
  93. }, {
  94. .virtual = IO_ADDRESS(INTEGRATOR_IC_BASE),
  95. .pfn = __phys_to_pfn(INTEGRATOR_IC_BASE),
  96. .length = SZ_4K,
  97. .type = MT_DEVICE
  98. }, {
  99. .virtual = IO_ADDRESS(INTEGRATOR_UART0_BASE),
  100. .pfn = __phys_to_pfn(INTEGRATOR_UART0_BASE),
  101. .length = SZ_4K,
  102. .type = MT_DEVICE
  103. }, {
  104. .virtual = IO_ADDRESS(INTEGRATOR_UART1_BASE),
  105. .pfn = __phys_to_pfn(INTEGRATOR_UART1_BASE),
  106. .length = SZ_4K,
  107. .type = MT_DEVICE
  108. }, {
  109. .virtual = IO_ADDRESS(INTEGRATOR_DBG_BASE),
  110. .pfn = __phys_to_pfn(INTEGRATOR_DBG_BASE),
  111. .length = SZ_4K,
  112. .type = MT_DEVICE
  113. }, {
  114. .virtual = IO_ADDRESS(INTEGRATOR_AP_GPIO_BASE),
  115. .pfn = __phys_to_pfn(INTEGRATOR_AP_GPIO_BASE),
  116. .length = SZ_4K,
  117. .type = MT_DEVICE
  118. }, {
  119. .virtual = PCI_MEMORY_VADDR,
  120. .pfn = __phys_to_pfn(PHYS_PCI_MEM_BASE),
  121. .length = SZ_16M,
  122. .type = MT_DEVICE
  123. }, {
  124. .virtual = PCI_CONFIG_VADDR,
  125. .pfn = __phys_to_pfn(PHYS_PCI_CONFIG_BASE),
  126. .length = SZ_16M,
  127. .type = MT_DEVICE
  128. }, {
  129. .virtual = PCI_V3_VADDR,
  130. .pfn = __phys_to_pfn(PHYS_PCI_V3_BASE),
  131. .length = SZ_64K,
  132. .type = MT_DEVICE
  133. }, {
  134. .virtual = PCI_IO_VADDR,
  135. .pfn = __phys_to_pfn(PHYS_PCI_IO_BASE),
  136. .length = SZ_64K,
  137. .type = MT_DEVICE
  138. }
  139. };
  140. static void __init ap_map_io(void)
  141. {
  142. iotable_init(ap_io_desc, ARRAY_SIZE(ap_io_desc));
  143. }
  144. #define INTEGRATOR_SC_VALID_INT 0x003fffff
  145. static void sc_mask_irq(unsigned int irq)
  146. {
  147. writel(1 << irq, VA_IC_BASE + IRQ_ENABLE_CLEAR);
  148. }
  149. static void sc_unmask_irq(unsigned int irq)
  150. {
  151. writel(1 << irq, VA_IC_BASE + IRQ_ENABLE_SET);
  152. }
  153. static struct irq_chip sc_chip = {
  154. .name = "SC",
  155. .ack = sc_mask_irq,
  156. .mask = sc_mask_irq,
  157. .unmask = sc_unmask_irq,
  158. };
  159. static void __init ap_init_irq(void)
  160. {
  161. unsigned int i;
  162. /* Disable all interrupts initially. */
  163. /* Do the core module ones */
  164. writel(-1, VA_CMIC_BASE + IRQ_ENABLE_CLEAR);
  165. /* do the header card stuff next */
  166. writel(-1, VA_IC_BASE + IRQ_ENABLE_CLEAR);
  167. writel(-1, VA_IC_BASE + FIQ_ENABLE_CLEAR);
  168. for (i = 0; i < NR_IRQS; i++) {
  169. if (((1 << i) & INTEGRATOR_SC_VALID_INT) != 0) {
  170. set_irq_chip(i, &sc_chip);
  171. set_irq_handler(i, handle_level_irq);
  172. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  173. }
  174. }
  175. }
  176. #ifdef CONFIG_PM
  177. static unsigned long ic_irq_enable;
  178. static int irq_suspend(struct sys_device *dev, pm_message_t state)
  179. {
  180. ic_irq_enable = readl(VA_IC_BASE + IRQ_ENABLE);
  181. return 0;
  182. }
  183. static int irq_resume(struct sys_device *dev)
  184. {
  185. /* disable all irq sources */
  186. writel(-1, VA_CMIC_BASE + IRQ_ENABLE_CLEAR);
  187. writel(-1, VA_IC_BASE + IRQ_ENABLE_CLEAR);
  188. writel(-1, VA_IC_BASE + FIQ_ENABLE_CLEAR);
  189. writel(ic_irq_enable, VA_IC_BASE + IRQ_ENABLE_SET);
  190. return 0;
  191. }
  192. #else
  193. #define irq_suspend NULL
  194. #define irq_resume NULL
  195. #endif
  196. static struct sysdev_class irq_class = {
  197. .name = "irq",
  198. .suspend = irq_suspend,
  199. .resume = irq_resume,
  200. };
  201. static struct sys_device irq_device = {
  202. .id = 0,
  203. .cls = &irq_class,
  204. };
  205. static int __init irq_init_sysfs(void)
  206. {
  207. int ret = sysdev_class_register(&irq_class);
  208. if (ret == 0)
  209. ret = sysdev_register(&irq_device);
  210. return ret;
  211. }
  212. device_initcall(irq_init_sysfs);
  213. /*
  214. * Flash handling.
  215. */
  216. #define SC_CTRLC (VA_SC_BASE + INTEGRATOR_SC_CTRLC_OFFSET)
  217. #define SC_CTRLS (VA_SC_BASE + INTEGRATOR_SC_CTRLS_OFFSET)
  218. #define EBI_CSR1 (VA_EBI_BASE + INTEGRATOR_EBI_CSR1_OFFSET)
  219. #define EBI_LOCK (VA_EBI_BASE + INTEGRATOR_EBI_LOCK_OFFSET)
  220. static int ap_flash_init(void)
  221. {
  222. u32 tmp;
  223. writel(INTEGRATOR_SC_CTRL_nFLVPPEN | INTEGRATOR_SC_CTRL_nFLWP, SC_CTRLC);
  224. tmp = readl(EBI_CSR1) | INTEGRATOR_EBI_WRITE_ENABLE;
  225. writel(tmp, EBI_CSR1);
  226. if (!(readl(EBI_CSR1) & INTEGRATOR_EBI_WRITE_ENABLE)) {
  227. writel(0xa05f, EBI_LOCK);
  228. writel(tmp, EBI_CSR1);
  229. writel(0, EBI_LOCK);
  230. }
  231. return 0;
  232. }
  233. static void ap_flash_exit(void)
  234. {
  235. u32 tmp;
  236. writel(INTEGRATOR_SC_CTRL_nFLVPPEN | INTEGRATOR_SC_CTRL_nFLWP, SC_CTRLC);
  237. tmp = readl(EBI_CSR1) & ~INTEGRATOR_EBI_WRITE_ENABLE;
  238. writel(tmp, EBI_CSR1);
  239. if (readl(EBI_CSR1) & INTEGRATOR_EBI_WRITE_ENABLE) {
  240. writel(0xa05f, EBI_LOCK);
  241. writel(tmp, EBI_CSR1);
  242. writel(0, EBI_LOCK);
  243. }
  244. }
  245. static void ap_flash_set_vpp(int on)
  246. {
  247. unsigned long reg = on ? SC_CTRLS : SC_CTRLC;
  248. writel(INTEGRATOR_SC_CTRL_nFLVPPEN, reg);
  249. }
  250. static struct flash_platform_data ap_flash_data = {
  251. .map_name = "cfi_probe",
  252. .width = 4,
  253. .init = ap_flash_init,
  254. .exit = ap_flash_exit,
  255. .set_vpp = ap_flash_set_vpp,
  256. };
  257. static struct resource cfi_flash_resource = {
  258. .start = INTEGRATOR_FLASH_BASE,
  259. .end = INTEGRATOR_FLASH_BASE + INTEGRATOR_FLASH_SIZE - 1,
  260. .flags = IORESOURCE_MEM,
  261. };
  262. static struct platform_device cfi_flash_device = {
  263. .name = "armflash",
  264. .id = 0,
  265. .dev = {
  266. .platform_data = &ap_flash_data,
  267. },
  268. .num_resources = 1,
  269. .resource = &cfi_flash_resource,
  270. };
  271. static void __init ap_init(void)
  272. {
  273. unsigned long sc_dec;
  274. int i;
  275. platform_device_register(&cfi_flash_device);
  276. sc_dec = readl(VA_SC_BASE + INTEGRATOR_SC_DEC_OFFSET);
  277. for (i = 0; i < 4; i++) {
  278. struct lm_device *lmdev;
  279. if ((sc_dec & (16 << i)) == 0)
  280. continue;
  281. lmdev = kzalloc(sizeof(struct lm_device), GFP_KERNEL);
  282. if (!lmdev)
  283. continue;
  284. lmdev->resource.start = 0xc0000000 + 0x10000000 * i;
  285. lmdev->resource.end = lmdev->resource.start + 0x0fffffff;
  286. lmdev->resource.flags = IORESOURCE_MEM;
  287. lmdev->irq = IRQ_AP_EXPINT0 + i;
  288. lmdev->id = i;
  289. lm_device_register(lmdev);
  290. }
  291. }
  292. static void __init ap_init_timer(void)
  293. {
  294. integrator_time_init(TICKS_PER_uSEC * 1000, 0);
  295. }
  296. static struct sys_timer ap_timer = {
  297. .init = ap_init_timer,
  298. };
  299. MACHINE_START(INTEGRATOR, "ARM-Integrator")
  300. /* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
  301. .phys_io = 0x16000000,
  302. .io_pg_offst = ((0xf1600000) >> 18) & 0xfffc,
  303. .boot_params = 0x00000100,
  304. .map_io = ap_map_io,
  305. .init_irq = ap_init_irq,
  306. .timer = &ap_timer,
  307. .init_machine = ap_init,
  308. MACHINE_END