common.c 9.6 KB

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