core.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /*
  2. * arch/arm/mach-ixp23xx/core.c
  3. *
  4. * Core routines for IXP23xx chips
  5. *
  6. * Author: Deepak Saxena <dsaxena@plexity.net>
  7. *
  8. * Copyright 2005 (c) MontaVista Software, Inc.
  9. *
  10. * Based on 2.4 code Copyright 2004 (c) Intel Corporation
  11. *
  12. * This file is licensed under the terms of the GNU General Public
  13. * License version 2. This program is licensed "as is" without any
  14. * warranty of any kind, whether express or implied.
  15. */
  16. #include <linux/config.h>
  17. #include <linux/kernel.h>
  18. #include <linux/init.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/sched.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/serial.h>
  23. #include <linux/tty.h>
  24. #include <linux/bitops.h>
  25. #include <linux/serial.h>
  26. #include <linux/serial_8250.h>
  27. #include <linux/serial_core.h>
  28. #include <linux/device.h>
  29. #include <linux/mm.h>
  30. #include <linux/time.h>
  31. #include <linux/timex.h>
  32. #include <asm/types.h>
  33. #include <asm/setup.h>
  34. #include <asm/memory.h>
  35. #include <asm/hardware.h>
  36. #include <asm/mach-types.h>
  37. #include <asm/irq.h>
  38. #include <asm/system.h>
  39. #include <asm/tlbflush.h>
  40. #include <asm/pgtable.h>
  41. #include <asm/mach/map.h>
  42. #include <asm/mach/time.h>
  43. #include <asm/mach/irq.h>
  44. #include <asm/mach/arch.h>
  45. /*************************************************************************
  46. * Chip specific mappings shared by all IXP23xx systems
  47. *************************************************************************/
  48. static struct map_desc ixp23xx_io_desc[] __initdata = {
  49. { /* XSI-CPP CSRs */
  50. .virtual = IXP23XX_XSI2CPP_CSR_VIRT,
  51. .pfn = __phys_to_pfn(IXP23XX_XSI2CPP_CSR_PHYS),
  52. .length = IXP23XX_XSI2CPP_CSR_SIZE,
  53. .type = MT_DEVICE,
  54. }, { /* Expansion Bus Config */
  55. .virtual = IXP23XX_EXP_CFG_VIRT,
  56. .pfn = __phys_to_pfn(IXP23XX_EXP_CFG_PHYS),
  57. .length = IXP23XX_EXP_CFG_SIZE,
  58. .type = MT_DEVICE,
  59. }, { /* UART, Interrupt ctrl, GPIO, timers, NPEs, MACS,.... */
  60. .virtual = IXP23XX_PERIPHERAL_VIRT,
  61. .pfn = __phys_to_pfn(IXP23XX_PERIPHERAL_PHYS),
  62. .length = IXP23XX_PERIPHERAL_SIZE,
  63. .type = MT_DEVICE,
  64. }, { /* CAP CSRs */
  65. .virtual = IXP23XX_CAP_CSR_VIRT,
  66. .pfn = __phys_to_pfn(IXP23XX_CAP_CSR_PHYS),
  67. .length = IXP23XX_CAP_CSR_SIZE,
  68. .type = MT_DEVICE,
  69. }, { /* MSF CSRs */
  70. .virtual = IXP23XX_MSF_CSR_VIRT,
  71. .pfn = __phys_to_pfn(IXP23XX_MSF_CSR_PHYS),
  72. .length = IXP23XX_MSF_CSR_SIZE,
  73. .type = MT_DEVICE,
  74. }, { /* PCI I/O Space */
  75. .virtual = IXP23XX_PCI_IO_VIRT,
  76. .pfn = __phys_to_pfn(IXP23XX_PCI_IO_PHYS),
  77. .length = IXP23XX_PCI_IO_SIZE,
  78. .type = MT_DEVICE,
  79. }, { /* PCI Config Space */
  80. .virtual = IXP23XX_PCI_CFG_VIRT,
  81. .pfn = __phys_to_pfn(IXP23XX_PCI_CFG_PHYS),
  82. .length = IXP23XX_PCI_CFG_SIZE,
  83. .type = MT_DEVICE,
  84. }, { /* PCI local CFG CSRs */
  85. .virtual = IXP23XX_PCI_CREG_VIRT,
  86. .pfn = __phys_to_pfn(IXP23XX_PCI_CREG_PHYS),
  87. .length = IXP23XX_PCI_CREG_SIZE,
  88. .type = MT_DEVICE,
  89. }, { /* PCI MEM Space */
  90. .virtual = IXP23XX_PCI_MEM_VIRT,
  91. .pfn = __phys_to_pfn(IXP23XX_PCI_MEM_PHYS),
  92. .length = IXP23XX_PCI_MEM_SIZE,
  93. .type = MT_DEVICE,
  94. }
  95. };
  96. void __init ixp23xx_map_io(void)
  97. {
  98. iotable_init(ixp23xx_io_desc, ARRAY_SIZE(ixp23xx_io_desc));
  99. }
  100. /***************************************************************************
  101. * IXP23xx Interrupt Handling
  102. ***************************************************************************/
  103. enum ixp23xx_irq_type {
  104. IXP23XX_IRQ_LEVEL, IXP23XX_IRQ_EDGE
  105. };
  106. static void ixp23xx_config_irq(unsigned int, enum ixp23xx_irq_type);
  107. static int ixp23xx_irq_set_type(unsigned int irq, unsigned int type)
  108. {
  109. int line = irq - IRQ_IXP23XX_GPIO6 + 6;
  110. u32 int_style;
  111. enum ixp23xx_irq_type irq_type;
  112. volatile u32 *int_reg;
  113. /*
  114. * Only GPIOs 6-15 are wired to interrupts on IXP23xx
  115. */
  116. if (line < 6 || line > 15)
  117. return -EINVAL;
  118. switch (type) {
  119. case IRQT_BOTHEDGE:
  120. int_style = IXP23XX_GPIO_STYLE_TRANSITIONAL;
  121. irq_type = IXP23XX_IRQ_EDGE;
  122. break;
  123. case IRQT_RISING:
  124. int_style = IXP23XX_GPIO_STYLE_RISING_EDGE;
  125. irq_type = IXP23XX_IRQ_EDGE;
  126. break;
  127. case IRQT_FALLING:
  128. int_style = IXP23XX_GPIO_STYLE_FALLING_EDGE;
  129. irq_type = IXP23XX_IRQ_EDGE;
  130. break;
  131. case IRQT_HIGH:
  132. int_style = IXP23XX_GPIO_STYLE_ACTIVE_HIGH;
  133. irq_type = IXP23XX_IRQ_LEVEL;
  134. break;
  135. case IRQT_LOW:
  136. int_style = IXP23XX_GPIO_STYLE_ACTIVE_LOW;
  137. irq_type = IXP23XX_IRQ_LEVEL;
  138. break;
  139. default:
  140. return -EINVAL;
  141. }
  142. ixp23xx_config_irq(irq, irq_type);
  143. if (line >= 8) { /* pins 8-15 */
  144. line -= 8;
  145. int_reg = (volatile u32 *)IXP23XX_GPIO_GPIT2R;
  146. } else { /* pins 0-7 */
  147. int_reg = (volatile u32 *)IXP23XX_GPIO_GPIT1R;
  148. }
  149. /*
  150. * Clear pending interrupts
  151. */
  152. *IXP23XX_GPIO_GPISR = (1 << line);
  153. /* Clear the style for the appropriate pin */
  154. *int_reg &= ~(IXP23XX_GPIO_STYLE_MASK <<
  155. (line * IXP23XX_GPIO_STYLE_SIZE));
  156. /* Set the new style */
  157. *int_reg |= (int_style << (line * IXP23XX_GPIO_STYLE_SIZE));
  158. return 0;
  159. }
  160. static void ixp23xx_irq_mask(unsigned int irq)
  161. {
  162. volatile unsigned long *intr_reg = IXP23XX_INTR_EN1 + (irq / 32);
  163. *intr_reg &= ~(1 << (irq % 32));
  164. }
  165. static void ixp23xx_irq_ack(unsigned int irq)
  166. {
  167. int line = irq - IRQ_IXP23XX_GPIO6 + 6;
  168. if ((line < 6) || (line > 15))
  169. return;
  170. *IXP23XX_GPIO_GPISR = (1 << line);
  171. }
  172. /*
  173. * Level triggered interrupts on GPIO lines can only be cleared when the
  174. * interrupt condition disappears.
  175. */
  176. static void ixp23xx_irq_level_unmask(unsigned int irq)
  177. {
  178. volatile unsigned long *intr_reg = IXP23XX_INTR_EN1 + (irq / 32);
  179. ixp23xx_irq_ack(irq);
  180. *intr_reg |= (1 << (irq % 32));
  181. }
  182. static void ixp23xx_irq_edge_unmask(unsigned int irq)
  183. {
  184. volatile unsigned long *intr_reg = IXP23XX_INTR_EN1 + (irq / 32);
  185. *intr_reg |= (1 << (irq % 32));
  186. }
  187. static struct irqchip ixp23xx_irq_level_chip = {
  188. .ack = ixp23xx_irq_mask,
  189. .mask = ixp23xx_irq_mask,
  190. .unmask = ixp23xx_irq_level_unmask,
  191. .set_type = ixp23xx_irq_set_type
  192. };
  193. static struct irqchip ixp23xx_irq_edge_chip = {
  194. .ack = ixp23xx_irq_ack,
  195. .mask = ixp23xx_irq_mask,
  196. .unmask = ixp23xx_irq_edge_unmask,
  197. .set_type = ixp23xx_irq_set_type
  198. };
  199. static void ixp23xx_pci_irq_mask(unsigned int irq)
  200. {
  201. *IXP23XX_PCI_XSCALE_INT_ENABLE &= ~(1 << (IRQ_IXP23XX_INTA + 27 - irq));
  202. }
  203. static void ixp23xx_pci_irq_unmask(unsigned int irq)
  204. {
  205. *IXP23XX_PCI_XSCALE_INT_ENABLE |= (1 << (IRQ_IXP23XX_INTA + 27 - irq));
  206. }
  207. /*
  208. * TODO: Should this just be done at ASM level?
  209. */
  210. static void pci_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
  211. {
  212. u32 pci_interrupt;
  213. unsigned int irqno;
  214. struct irqdesc *int_desc;
  215. pci_interrupt = *IXP23XX_PCI_XSCALE_INT_STATUS;
  216. desc->chip->ack(irq);
  217. /* See which PCI_INTA, or PCI_INTB interrupted */
  218. if (pci_interrupt & (1 << 26)) {
  219. irqno = IRQ_IXP23XX_INTB;
  220. } else if (pci_interrupt & (1 << 27)) {
  221. irqno = IRQ_IXP23XX_INTA;
  222. } else {
  223. BUG();
  224. }
  225. int_desc = irq_desc + irqno;
  226. int_desc->handle(irqno, int_desc, regs);
  227. desc->chip->unmask(irq);
  228. }
  229. static struct irqchip ixp23xx_pci_irq_chip = {
  230. .ack = ixp23xx_pci_irq_mask,
  231. .mask = ixp23xx_pci_irq_mask,
  232. .unmask = ixp23xx_pci_irq_unmask
  233. };
  234. static void ixp23xx_config_irq(unsigned int irq, enum ixp23xx_irq_type type)
  235. {
  236. switch (type) {
  237. case IXP23XX_IRQ_LEVEL:
  238. set_irq_chip(irq, &ixp23xx_irq_level_chip);
  239. set_irq_handler(irq, do_level_IRQ);
  240. break;
  241. case IXP23XX_IRQ_EDGE:
  242. set_irq_chip(irq, &ixp23xx_irq_edge_chip);
  243. set_irq_handler(irq, do_edge_IRQ);
  244. break;
  245. }
  246. set_irq_flags(irq, IRQF_VALID);
  247. }
  248. void __init ixp23xx_init_irq(void)
  249. {
  250. int irq;
  251. /* Route everything to IRQ */
  252. *IXP23XX_INTR_SEL1 = 0x0;
  253. *IXP23XX_INTR_SEL2 = 0x0;
  254. *IXP23XX_INTR_SEL3 = 0x0;
  255. *IXP23XX_INTR_SEL4 = 0x0;
  256. /* Mask all sources */
  257. *IXP23XX_INTR_EN1 = 0x0;
  258. *IXP23XX_INTR_EN2 = 0x0;
  259. *IXP23XX_INTR_EN3 = 0x0;
  260. *IXP23XX_INTR_EN4 = 0x0;
  261. /*
  262. * Configure all IRQs for level-sensitive operation
  263. */
  264. for (irq = 0; irq <= NUM_IXP23XX_RAW_IRQS; irq++) {
  265. ixp23xx_config_irq(irq, IXP23XX_IRQ_LEVEL);
  266. }
  267. for (irq = IRQ_IXP23XX_INTA; irq <= IRQ_IXP23XX_INTB; irq++) {
  268. set_irq_chip(irq, &ixp23xx_pci_irq_chip);
  269. set_irq_handler(irq, do_level_IRQ);
  270. set_irq_flags(irq, IRQF_VALID);
  271. }
  272. set_irq_chained_handler(IRQ_IXP23XX_PCI_INT_RPH, pci_handler);
  273. }
  274. /*************************************************************************
  275. * Timer-tick functions for IXP23xx
  276. *************************************************************************/
  277. #define CLOCK_TICKS_PER_USEC CLOCK_TICK_RATE / (USEC_PER_SEC)
  278. static unsigned long next_jiffy_time;
  279. static unsigned long
  280. ixp23xx_gettimeoffset(void)
  281. {
  282. unsigned long elapsed;
  283. elapsed = *IXP23XX_TIMER_CONT - (next_jiffy_time - LATCH);
  284. return elapsed / CLOCK_TICKS_PER_USEC;
  285. }
  286. static irqreturn_t
  287. ixp23xx_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  288. {
  289. /* Clear Pending Interrupt by writing '1' to it */
  290. *IXP23XX_TIMER_STATUS = IXP23XX_TIMER1_INT_PEND;
  291. while ((*IXP23XX_TIMER_CONT - next_jiffy_time) > LATCH) {
  292. timer_tick(regs);
  293. next_jiffy_time += LATCH;
  294. }
  295. return IRQ_HANDLED;
  296. }
  297. static struct irqaction ixp23xx_timer_irq = {
  298. .name = "IXP23xx Timer Tick",
  299. .handler = ixp23xx_timer_interrupt,
  300. .flags = SA_INTERRUPT | SA_TIMER,
  301. };
  302. void __init ixp23xx_init_timer(void)
  303. {
  304. /* Clear Pending Interrupt by writing '1' to it */
  305. *IXP23XX_TIMER_STATUS = IXP23XX_TIMER1_INT_PEND;
  306. /* Setup the Timer counter value */
  307. *IXP23XX_TIMER1_RELOAD =
  308. (LATCH & ~IXP23XX_TIMER_RELOAD_MASK) | IXP23XX_TIMER_ENABLE;
  309. *IXP23XX_TIMER_CONT = 0;
  310. next_jiffy_time = LATCH;
  311. /* Connect the interrupt handler and enable the interrupt */
  312. setup_irq(IRQ_IXP23XX_TIMER1, &ixp23xx_timer_irq);
  313. }
  314. struct sys_timer ixp23xx_timer = {
  315. .init = ixp23xx_init_timer,
  316. .offset = ixp23xx_gettimeoffset,
  317. };
  318. /*************************************************************************
  319. * IXP23xx Platform Initializaion
  320. *************************************************************************/
  321. static struct resource ixp23xx_uart_resources[] = {
  322. {
  323. .start = IXP23XX_UART1_PHYS,
  324. .end = IXP23XX_UART1_PHYS + 0x0fff,
  325. .flags = IORESOURCE_MEM
  326. }, {
  327. .start = IXP23XX_UART2_PHYS,
  328. .end = IXP23XX_UART2_PHYS + 0x0fff,
  329. .flags = IORESOURCE_MEM
  330. }
  331. };
  332. static struct plat_serial8250_port ixp23xx_uart_data[] = {
  333. {
  334. .mapbase = IXP23XX_UART1_PHYS,
  335. .membase = (char *)(IXP23XX_UART1_VIRT + 3),
  336. .irq = IRQ_IXP23XX_UART1,
  337. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
  338. .iotype = UPIO_MEM,
  339. .regshift = 2,
  340. .uartclk = IXP23XX_UART_XTAL,
  341. }, {
  342. .mapbase = IXP23XX_UART2_PHYS,
  343. .membase = (char *)(IXP23XX_UART2_VIRT + 3),
  344. .irq = IRQ_IXP23XX_UART2,
  345. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
  346. .iotype = UPIO_MEM,
  347. .regshift = 2,
  348. .uartclk = IXP23XX_UART_XTAL,
  349. },
  350. { },
  351. };
  352. static struct platform_device ixp23xx_uart = {
  353. .name = "serial8250",
  354. .id = 0,
  355. .dev.platform_data = ixp23xx_uart_data,
  356. .num_resources = 2,
  357. .resource = ixp23xx_uart_resources,
  358. };
  359. static struct platform_device *ixp23xx_devices[] __initdata = {
  360. &ixp23xx_uart,
  361. };
  362. void __init ixp23xx_sys_init(void)
  363. {
  364. platform_add_devices(ixp23xx_devices, ARRAY_SIZE(ixp23xx_devices));
  365. }