integrator_ap.c 8.7 KB

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