core.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*
  2. * linux/arch/arm/mach-aaec2000/core.c
  3. *
  4. * Code common to all AAEC-2000 machines
  5. *
  6. * Copyright (c) 2005 Nicolas Bellido Y Ortega
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/list.h>
  17. #include <linux/errno.h>
  18. #include <linux/dma-mapping.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/timex.h>
  21. #include <linux/signal.h>
  22. #include <linux/clk.h>
  23. #include <linux/gfp.h>
  24. #include <mach/hardware.h>
  25. #include <asm/irq.h>
  26. #include <asm/sizes.h>
  27. #include <asm/mach/flash.h>
  28. #include <asm/mach/irq.h>
  29. #include <asm/mach/time.h>
  30. #include <asm/mach/map.h>
  31. #include "core.h"
  32. /*
  33. * Common I/O mapping:
  34. *
  35. * Static virtual address mappings are as follow:
  36. *
  37. * 0xf8000000-0xf8001ffff: Devices connected to APB bus
  38. * 0xf8002000-0xf8003ffff: Devices connected to AHB bus
  39. *
  40. * Below 0xe8000000 is reserved for vm allocation.
  41. *
  42. * The machine specific code must provide the extra mapping beside the
  43. * default mapping provided here.
  44. */
  45. static struct map_desc standard_io_desc[] __initdata = {
  46. {
  47. .virtual = VIO_APB_BASE,
  48. .pfn = __phys_to_pfn(PIO_APB_BASE),
  49. .length = IO_APB_LENGTH,
  50. .type = MT_DEVICE
  51. }, {
  52. .virtual = VIO_AHB_BASE,
  53. .pfn = __phys_to_pfn(PIO_AHB_BASE),
  54. .length = IO_AHB_LENGTH,
  55. .type = MT_DEVICE
  56. }
  57. };
  58. void __init aaec2000_map_io(void)
  59. {
  60. iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
  61. }
  62. /*
  63. * Interrupt handling routines
  64. */
  65. static void aaec2000_int_ack(unsigned int irq)
  66. {
  67. IRQ_INTSR = 1 << irq;
  68. }
  69. static void aaec2000_int_mask(unsigned int irq)
  70. {
  71. IRQ_INTENC |= (1 << irq);
  72. }
  73. static void aaec2000_int_unmask(unsigned int irq)
  74. {
  75. IRQ_INTENS |= (1 << irq);
  76. }
  77. static struct irq_chip aaec2000_irq_chip = {
  78. .ack = aaec2000_int_ack,
  79. .mask = aaec2000_int_mask,
  80. .unmask = aaec2000_int_unmask,
  81. };
  82. void __init aaec2000_init_irq(void)
  83. {
  84. unsigned int i;
  85. for (i = 0; i < NR_IRQS; i++) {
  86. set_irq_handler(i, handle_level_irq);
  87. set_irq_chip(i, &aaec2000_irq_chip);
  88. set_irq_flags(i, IRQF_VALID);
  89. }
  90. /* Disable all interrupts */
  91. IRQ_INTENC = 0xffffffff;
  92. /* Clear any pending interrupts */
  93. IRQ_INTSR = IRQ_INTSR;
  94. }
  95. /*
  96. * Time keeping
  97. */
  98. /* IRQs are disabled before entering here from do_gettimeofday() */
  99. static unsigned long aaec2000_gettimeoffset(void)
  100. {
  101. unsigned long ticks_to_match, elapsed, usec;
  102. /* Get ticks before next timer match */
  103. ticks_to_match = TIMER1_LOAD - TIMER1_VAL;
  104. /* We need elapsed ticks since last match */
  105. elapsed = LATCH - ticks_to_match;
  106. /* Now, convert them to usec */
  107. usec = (unsigned long)(elapsed * (tick_nsec / 1000))/LATCH;
  108. return usec;
  109. }
  110. /* We enter here with IRQs enabled */
  111. static irqreturn_t
  112. aaec2000_timer_interrupt(int irq, void *dev_id)
  113. {
  114. /* TODO: Check timer accuracy */
  115. timer_tick();
  116. TIMER1_CLEAR = 1;
  117. return IRQ_HANDLED;
  118. }
  119. static struct irqaction aaec2000_timer_irq = {
  120. .name = "AAEC-2000 Timer Tick",
  121. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  122. .handler = aaec2000_timer_interrupt,
  123. };
  124. static void __init aaec2000_timer_init(void)
  125. {
  126. /* Disable timer 1 */
  127. TIMER1_CTRL = 0;
  128. /* We have somehow to generate a 100Hz clock.
  129. * We then use the 508KHz timer in periodic mode.
  130. */
  131. TIMER1_LOAD = LATCH;
  132. TIMER1_CLEAR = 1; /* Clear interrupt */
  133. setup_irq(INT_TMR1_OFL, &aaec2000_timer_irq);
  134. TIMER1_CTRL = TIMER_CTRL_ENABLE |
  135. TIMER_CTRL_PERIODIC |
  136. TIMER_CTRL_CLKSEL_508K;
  137. }
  138. struct sys_timer aaec2000_timer = {
  139. .init = aaec2000_timer_init,
  140. .offset = aaec2000_gettimeoffset,
  141. };
  142. static struct clcd_panel mach_clcd_panel;
  143. static int aaec2000_clcd_setup(struct clcd_fb *fb)
  144. {
  145. dma_addr_t dma;
  146. fb->panel = &mach_clcd_panel;
  147. fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, SZ_1M,
  148. &dma, GFP_KERNEL);
  149. if (!fb->fb.screen_base) {
  150. printk(KERN_ERR "CLCD: unable to map framebuffer\n");
  151. return -ENOMEM;
  152. }
  153. fb->fb.fix.smem_start = dma;
  154. fb->fb.fix.smem_len = SZ_1M;
  155. return 0;
  156. }
  157. static int aaec2000_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  158. {
  159. return dma_mmap_writecombine(&fb->dev->dev, vma,
  160. fb->fb.screen_base,
  161. fb->fb.fix.smem_start,
  162. fb->fb.fix.smem_len);
  163. }
  164. static void aaec2000_clcd_remove(struct clcd_fb *fb)
  165. {
  166. dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
  167. fb->fb.screen_base, fb->fb.fix.smem_start);
  168. }
  169. static struct clcd_board clcd_plat_data = {
  170. .name = "AAEC-2000",
  171. .check = clcdfb_check,
  172. .decode = clcdfb_decode,
  173. .setup = aaec2000_clcd_setup,
  174. .mmap = aaec2000_clcd_mmap,
  175. .remove = aaec2000_clcd_remove,
  176. };
  177. static struct amba_device clcd_device = {
  178. .dev = {
  179. .init_name = "mb:16",
  180. .coherent_dma_mask = ~0,
  181. .platform_data = &clcd_plat_data,
  182. },
  183. .res = {
  184. .start = AAEC_CLCD_PHYS,
  185. .end = AAEC_CLCD_PHYS + SZ_4K - 1,
  186. .flags = IORESOURCE_MEM,
  187. },
  188. .irq = { INT_LCD, NO_IRQ },
  189. .periphid = 0x41110,
  190. };
  191. static struct amba_device *amba_devs[] __initdata = {
  192. &clcd_device,
  193. };
  194. void clk_disable(struct clk *clk)
  195. {
  196. }
  197. int clk_set_rate(struct clk *clk, unsigned long rate)
  198. {
  199. return 0;
  200. }
  201. int clk_enable(struct clk *clk)
  202. {
  203. return 0;
  204. }
  205. struct clk *clk_get(struct device *dev, const char *id)
  206. {
  207. return dev && strcmp(dev_name(dev), "mb:16") == 0 ? NULL : ERR_PTR(-ENOENT);
  208. }
  209. void clk_put(struct clk *clk)
  210. {
  211. }
  212. void __init aaec2000_set_clcd_plat_data(struct aaec2000_clcd_info *clcd)
  213. {
  214. clcd_plat_data.enable = clcd->enable;
  215. clcd_plat_data.disable = clcd->disable;
  216. memcpy(&mach_clcd_panel, &clcd->panel, sizeof(struct clcd_panel));
  217. }
  218. static struct flash_platform_data aaec2000_flash_data = {
  219. .map_name = "cfi_probe",
  220. .width = 4,
  221. };
  222. static struct resource aaec2000_flash_resource = {
  223. .start = AAEC_FLASH_BASE,
  224. .end = AAEC_FLASH_BASE + AAEC_FLASH_SIZE,
  225. .flags = IORESOURCE_MEM,
  226. };
  227. static struct platform_device aaec2000_flash_device = {
  228. .name = "armflash",
  229. .id = 0,
  230. .dev = {
  231. .platform_data = &aaec2000_flash_data,
  232. },
  233. .num_resources = 1,
  234. .resource = &aaec2000_flash_resource,
  235. };
  236. static int __init aaec2000_init(void)
  237. {
  238. int i;
  239. for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  240. struct amba_device *d = amba_devs[i];
  241. amba_device_register(d, &iomem_resource);
  242. }
  243. platform_device_register(&aaec2000_flash_device);
  244. return 0;
  245. };
  246. arch_initcall(aaec2000_init);