common.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. /*
  2. * arch/arm/mach-ixp4xx/common.c
  3. *
  4. * Generic code shared across all IXP4XX platforms
  5. *
  6. * Maintainer: Deepak Saxena <dsaxena@plexity.net>
  7. *
  8. * Copyright 2002 (c) Intel Corporation
  9. * Copyright 2003-2004 (c) MontaVista, Software, Inc.
  10. *
  11. * This file is licensed under the terms of the GNU General Public
  12. * License version 2. This program is licensed "as is" without any
  13. * warranty of any kind, whether express or implied.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/mm.h>
  17. #include <linux/init.h>
  18. #include <linux/serial.h>
  19. #include <linux/sched.h>
  20. #include <linux/tty.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/serial_core.h>
  23. #include <linux/bootmem.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/bitops.h>
  26. #include <linux/time.h>
  27. #include <linux/timex.h>
  28. #include <linux/clocksource.h>
  29. #include <asm/hardware.h>
  30. #include <asm/uaccess.h>
  31. #include <asm/io.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/page.h>
  34. #include <asm/irq.h>
  35. #include <asm/mach/map.h>
  36. #include <asm/mach/irq.h>
  37. #include <asm/mach/time.h>
  38. /*************************************************************************
  39. * IXP4xx chipset I/O mapping
  40. *************************************************************************/
  41. static struct map_desc ixp4xx_io_desc[] __initdata = {
  42. { /* UART, Interrupt ctrl, GPIO, timers, NPEs, MACs, USB .... */
  43. .virtual = IXP4XX_PERIPHERAL_BASE_VIRT,
  44. .pfn = __phys_to_pfn(IXP4XX_PERIPHERAL_BASE_PHYS),
  45. .length = IXP4XX_PERIPHERAL_REGION_SIZE,
  46. .type = MT_DEVICE
  47. }, { /* Expansion Bus Config Registers */
  48. .virtual = IXP4XX_EXP_CFG_BASE_VIRT,
  49. .pfn = __phys_to_pfn(IXP4XX_EXP_CFG_BASE_PHYS),
  50. .length = IXP4XX_EXP_CFG_REGION_SIZE,
  51. .type = MT_DEVICE
  52. }, { /* PCI Registers */
  53. .virtual = IXP4XX_PCI_CFG_BASE_VIRT,
  54. .pfn = __phys_to_pfn(IXP4XX_PCI_CFG_BASE_PHYS),
  55. .length = IXP4XX_PCI_CFG_REGION_SIZE,
  56. .type = MT_DEVICE
  57. },
  58. #ifdef CONFIG_DEBUG_LL
  59. { /* Debug UART mapping */
  60. .virtual = IXP4XX_DEBUG_UART_BASE_VIRT,
  61. .pfn = __phys_to_pfn(IXP4XX_DEBUG_UART_BASE_PHYS),
  62. .length = IXP4XX_DEBUG_UART_REGION_SIZE,
  63. .type = MT_DEVICE
  64. }
  65. #endif
  66. };
  67. void __init ixp4xx_map_io(void)
  68. {
  69. iotable_init(ixp4xx_io_desc, ARRAY_SIZE(ixp4xx_io_desc));
  70. }
  71. /*************************************************************************
  72. * IXP4xx chipset IRQ handling
  73. *
  74. * TODO: GPIO IRQs should be marked invalid until the user of the IRQ
  75. * (be it PCI or something else) configures that GPIO line
  76. * as an IRQ.
  77. **************************************************************************/
  78. enum ixp4xx_irq_type {
  79. IXP4XX_IRQ_LEVEL, IXP4XX_IRQ_EDGE
  80. };
  81. /* Each bit represents an IRQ: 1: edge-triggered, 0: level triggered */
  82. static unsigned long long ixp4xx_irq_edge = 0;
  83. /*
  84. * IRQ -> GPIO mapping table
  85. */
  86. static signed char irq2gpio[32] = {
  87. -1, -1, -1, -1, -1, -1, 0, 1,
  88. -1, -1, -1, -1, -1, -1, -1, -1,
  89. -1, -1, -1, 2, 3, 4, 5, 6,
  90. 7, 8, 9, 10, 11, 12, -1, -1,
  91. };
  92. static int ixp4xx_set_irq_type(unsigned int irq, unsigned int type)
  93. {
  94. int line = irq2gpio[irq];
  95. u32 int_style;
  96. enum ixp4xx_irq_type irq_type;
  97. volatile u32 *int_reg;
  98. /*
  99. * Only for GPIO IRQs
  100. */
  101. if (line < 0)
  102. return -EINVAL;
  103. switch (type){
  104. case IRQT_BOTHEDGE:
  105. int_style = IXP4XX_GPIO_STYLE_TRANSITIONAL;
  106. irq_type = IXP4XX_IRQ_EDGE;
  107. break;
  108. case IRQT_RISING:
  109. int_style = IXP4XX_GPIO_STYLE_RISING_EDGE;
  110. irq_type = IXP4XX_IRQ_EDGE;
  111. break;
  112. case IRQT_FALLING:
  113. int_style = IXP4XX_GPIO_STYLE_FALLING_EDGE;
  114. irq_type = IXP4XX_IRQ_EDGE;
  115. break;
  116. case IRQT_HIGH:
  117. int_style = IXP4XX_GPIO_STYLE_ACTIVE_HIGH;
  118. irq_type = IXP4XX_IRQ_LEVEL;
  119. break;
  120. case IRQT_LOW:
  121. int_style = IXP4XX_GPIO_STYLE_ACTIVE_LOW;
  122. irq_type = IXP4XX_IRQ_LEVEL;
  123. break;
  124. default:
  125. return -EINVAL;
  126. }
  127. if (irq_type == IXP4XX_IRQ_EDGE)
  128. ixp4xx_irq_edge |= (1 << irq);
  129. else
  130. ixp4xx_irq_edge &= ~(1 << irq);
  131. if (line >= 8) { /* pins 8-15 */
  132. line -= 8;
  133. int_reg = IXP4XX_GPIO_GPIT2R;
  134. } else { /* pins 0-7 */
  135. int_reg = IXP4XX_GPIO_GPIT1R;
  136. }
  137. /* Clear the style for the appropriate pin */
  138. *int_reg &= ~(IXP4XX_GPIO_STYLE_CLEAR <<
  139. (line * IXP4XX_GPIO_STYLE_SIZE));
  140. *IXP4XX_GPIO_GPISR = (1 << line);
  141. /* Set the new style */
  142. *int_reg |= (int_style << (line * IXP4XX_GPIO_STYLE_SIZE));
  143. /* Configure the line as an input */
  144. gpio_line_config(line, IXP4XX_GPIO_IN);
  145. return 0;
  146. }
  147. static void ixp4xx_irq_mask(unsigned int irq)
  148. {
  149. if (cpu_is_ixp46x() && irq >= 32)
  150. *IXP4XX_ICMR2 &= ~(1 << (irq - 32));
  151. else
  152. *IXP4XX_ICMR &= ~(1 << irq);
  153. }
  154. static void ixp4xx_irq_ack(unsigned int irq)
  155. {
  156. int line = (irq < 32) ? irq2gpio[irq] : -1;
  157. if (line >= 0)
  158. *IXP4XX_GPIO_GPISR = (1 << line);
  159. }
  160. /*
  161. * Level triggered interrupts on GPIO lines can only be cleared when the
  162. * interrupt condition disappears.
  163. */
  164. static void ixp4xx_irq_unmask(unsigned int irq)
  165. {
  166. if (!(ixp4xx_irq_edge & (1 << irq)))
  167. ixp4xx_irq_ack(irq);
  168. if (cpu_is_ixp46x() && irq >= 32)
  169. *IXP4XX_ICMR2 |= (1 << (irq - 32));
  170. else
  171. *IXP4XX_ICMR |= (1 << irq);
  172. }
  173. static struct irq_chip ixp4xx_irq_chip = {
  174. .name = "IXP4xx",
  175. .ack = ixp4xx_irq_ack,
  176. .mask = ixp4xx_irq_mask,
  177. .unmask = ixp4xx_irq_unmask,
  178. .set_type = ixp4xx_set_irq_type,
  179. };
  180. void __init ixp4xx_init_irq(void)
  181. {
  182. int i = 0;
  183. /* Route all sources to IRQ instead of FIQ */
  184. *IXP4XX_ICLR = 0x0;
  185. /* Disable all interrupt */
  186. *IXP4XX_ICMR = 0x0;
  187. if (cpu_is_ixp46x()) {
  188. /* Route upper 32 sources to IRQ instead of FIQ */
  189. *IXP4XX_ICLR2 = 0x00;
  190. /* Disable upper 32 interrupts */
  191. *IXP4XX_ICMR2 = 0x00;
  192. }
  193. /* Default to all level triggered */
  194. for(i = 0; i < NR_IRQS; i++) {
  195. set_irq_chip(i, &ixp4xx_irq_chip);
  196. set_irq_handler(i, handle_level_irq);
  197. set_irq_flags(i, IRQF_VALID);
  198. }
  199. }
  200. /*************************************************************************
  201. * IXP4xx timer tick
  202. * We use OS timer1 on the CPU for the timer tick and the timestamp
  203. * counter as a source of real clock ticks to account for missed jiffies.
  204. *************************************************************************/
  205. static unsigned volatile last_jiffy_time;
  206. #define CLOCK_TICKS_PER_USEC ((CLOCK_TICK_RATE + USEC_PER_SEC/2) / USEC_PER_SEC)
  207. static irqreturn_t ixp4xx_timer_interrupt(int irq, void *dev_id)
  208. {
  209. write_seqlock(&xtime_lock);
  210. /* Clear Pending Interrupt by writing '1' to it */
  211. *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
  212. /*
  213. * Catch up with the real idea of time
  214. */
  215. while ((signed long)(*IXP4XX_OSTS - last_jiffy_time) >= LATCH) {
  216. timer_tick();
  217. last_jiffy_time += LATCH;
  218. }
  219. write_sequnlock(&xtime_lock);
  220. return IRQ_HANDLED;
  221. }
  222. static struct irqaction ixp4xx_timer_irq = {
  223. .name = "IXP4xx Timer Tick",
  224. .flags = IRQF_DISABLED | IRQF_TIMER,
  225. .handler = ixp4xx_timer_interrupt,
  226. };
  227. static void __init ixp4xx_timer_init(void)
  228. {
  229. /* Clear Pending Interrupt by writing '1' to it */
  230. *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
  231. /* Setup the Timer counter value */
  232. *IXP4XX_OSRT1 = (LATCH & ~IXP4XX_OST_RELOAD_MASK) | IXP4XX_OST_ENABLE;
  233. /* Reset time-stamp counter */
  234. *IXP4XX_OSTS = 0;
  235. last_jiffy_time = 0;
  236. /* Connect the interrupt handler and enable the interrupt */
  237. setup_irq(IRQ_IXP4XX_TIMER1, &ixp4xx_timer_irq);
  238. }
  239. struct sys_timer ixp4xx_timer = {
  240. .init = ixp4xx_timer_init,
  241. };
  242. static struct resource ixp46x_i2c_resources[] = {
  243. [0] = {
  244. .start = 0xc8011000,
  245. .end = 0xc801101c,
  246. .flags = IORESOURCE_MEM,
  247. },
  248. [1] = {
  249. .start = IRQ_IXP4XX_I2C,
  250. .end = IRQ_IXP4XX_I2C,
  251. .flags = IORESOURCE_IRQ
  252. }
  253. };
  254. /*
  255. * I2C controller. The IXP46x uses the same block as the IOP3xx, so
  256. * we just use the same device name.
  257. */
  258. static struct platform_device ixp46x_i2c_controller = {
  259. .name = "IOP3xx-I2C",
  260. .id = 0,
  261. .num_resources = 2,
  262. .resource = ixp46x_i2c_resources
  263. };
  264. static struct platform_device *ixp46x_devices[] __initdata = {
  265. &ixp46x_i2c_controller
  266. };
  267. unsigned long ixp4xx_exp_bus_size;
  268. EXPORT_SYMBOL(ixp4xx_exp_bus_size);
  269. void __init ixp4xx_sys_init(void)
  270. {
  271. ixp4xx_exp_bus_size = SZ_16M;
  272. if (cpu_is_ixp46x()) {
  273. int region;
  274. platform_add_devices(ixp46x_devices,
  275. ARRAY_SIZE(ixp46x_devices));
  276. for (region = 0; region < 7; region++) {
  277. if((*(IXP4XX_EXP_REG(0x4 * region)) & 0x200)) {
  278. ixp4xx_exp_bus_size = SZ_32M;
  279. break;
  280. }
  281. }
  282. }
  283. printk("IXP4xx: Using %luMiB expansion bus window size\n",
  284. ixp4xx_exp_bus_size >> 20);
  285. }
  286. cycle_t ixp4xx_get_cycles(void)
  287. {
  288. return *IXP4XX_OSTS;
  289. }
  290. static struct clocksource clocksource_ixp4xx = {
  291. .name = "OSTS",
  292. .rating = 200,
  293. .read = ixp4xx_get_cycles,
  294. .mask = CLOCKSOURCE_MASK(32),
  295. .shift = 20,
  296. .is_continuous = 1,
  297. };
  298. unsigned long ixp4xx_timer_freq = FREQ;
  299. static int __init ixp4xx_clocksource_init(void)
  300. {
  301. clocksource_ixp4xx.mult =
  302. clocksource_hz2mult(ixp4xx_timer_freq,
  303. clocksource_ixp4xx.shift);
  304. clocksource_register(&clocksource_ixp4xx);
  305. return 0;
  306. }
  307. device_initcall(ixp4xx_clocksource_init);