core.c 11 KB

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