core.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /*
  2. * arch/arm/mach-ixp2000/common.c
  3. *
  4. * Common routines used by all IXP2400/2800 based platforms.
  5. *
  6. * Author: Deepak Saxena <dsaxena@plexity.net>
  7. *
  8. * Copyright 2004 (C) MontaVista Software, Inc.
  9. *
  10. * Based on work Copyright (C) 2002-2003 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_core.h>
  26. #include <linux/mm.h>
  27. #include <asm/types.h>
  28. #include <asm/setup.h>
  29. #include <asm/memory.h>
  30. #include <asm/hardware.h>
  31. #include <asm/mach-types.h>
  32. #include <asm/irq.h>
  33. #include <asm/system.h>
  34. #include <asm/tlbflush.h>
  35. #include <asm/pgtable.h>
  36. #include <asm/mach/map.h>
  37. #include <asm/mach/time.h>
  38. #include <asm/mach/irq.h>
  39. static DEFINE_SPINLOCK(ixp2000_slowport_lock);
  40. static unsigned long ixp2000_slowport_irq_flags;
  41. /*************************************************************************
  42. * Slowport access routines
  43. *************************************************************************/
  44. void ixp2000_acquire_slowport(struct slowport_cfg *new_cfg, struct slowport_cfg *old_cfg)
  45. {
  46. spin_lock_irqsave(&ixp2000_slowport_lock, ixp2000_slowport_irq_flags);
  47. old_cfg->CCR = *IXP2000_SLOWPORT_CCR;
  48. old_cfg->WTC = *IXP2000_SLOWPORT_WTC2;
  49. old_cfg->RTC = *IXP2000_SLOWPORT_RTC2;
  50. old_cfg->PCR = *IXP2000_SLOWPORT_PCR;
  51. old_cfg->ADC = *IXP2000_SLOWPORT_ADC;
  52. ixp2000_reg_write(IXP2000_SLOWPORT_CCR, new_cfg->CCR);
  53. ixp2000_reg_write(IXP2000_SLOWPORT_WTC2, new_cfg->WTC);
  54. ixp2000_reg_write(IXP2000_SLOWPORT_RTC2, new_cfg->RTC);
  55. ixp2000_reg_write(IXP2000_SLOWPORT_PCR, new_cfg->PCR);
  56. ixp2000_reg_write(IXP2000_SLOWPORT_ADC, new_cfg->ADC);
  57. }
  58. void ixp2000_release_slowport(struct slowport_cfg *old_cfg)
  59. {
  60. ixp2000_reg_write(IXP2000_SLOWPORT_CCR, old_cfg->CCR);
  61. ixp2000_reg_write(IXP2000_SLOWPORT_WTC2, old_cfg->WTC);
  62. ixp2000_reg_write(IXP2000_SLOWPORT_RTC2, old_cfg->RTC);
  63. ixp2000_reg_write(IXP2000_SLOWPORT_PCR, old_cfg->PCR);
  64. ixp2000_reg_write(IXP2000_SLOWPORT_ADC, old_cfg->ADC);
  65. spin_unlock_irqrestore(&ixp2000_slowport_lock,
  66. ixp2000_slowport_irq_flags);
  67. }
  68. /*************************************************************************
  69. * Chip specific mappings shared by all IXP2000 systems
  70. *************************************************************************/
  71. static struct map_desc ixp2000_io_desc[] __initdata = {
  72. {
  73. .virtual = IXP2000_CAP_VIRT_BASE,
  74. .physical = IXP2000_CAP_PHYS_BASE,
  75. .length = IXP2000_CAP_SIZE,
  76. .type = MT_DEVICE
  77. }, {
  78. .virtual = IXP2000_INTCTL_VIRT_BASE,
  79. .physical = IXP2000_INTCTL_PHYS_BASE,
  80. .length = IXP2000_INTCTL_SIZE,
  81. .type = MT_DEVICE
  82. }, {
  83. .virtual = IXP2000_PCI_CREG_VIRT_BASE,
  84. .physical = IXP2000_PCI_CREG_PHYS_BASE,
  85. .length = IXP2000_PCI_CREG_SIZE,
  86. .type = MT_DEVICE
  87. }, {
  88. .virtual = IXP2000_PCI_CSR_VIRT_BASE,
  89. .physical = IXP2000_PCI_CSR_PHYS_BASE,
  90. .length = IXP2000_PCI_CSR_SIZE,
  91. .type = MT_DEVICE
  92. }, {
  93. .virtual = IXP2000_PCI_IO_VIRT_BASE,
  94. .physical = IXP2000_PCI_IO_PHYS_BASE,
  95. .length = IXP2000_PCI_IO_SIZE,
  96. .type = MT_DEVICE
  97. }, {
  98. .virtual = IXP2000_PCI_CFG0_VIRT_BASE,
  99. .physical = IXP2000_PCI_CFG0_PHYS_BASE,
  100. .length = IXP2000_PCI_CFG0_SIZE,
  101. .type = MT_DEVICE
  102. }, {
  103. .virtual = IXP2000_PCI_CFG1_VIRT_BASE,
  104. .physical = IXP2000_PCI_CFG1_PHYS_BASE,
  105. .length = IXP2000_PCI_CFG1_SIZE,
  106. .type = MT_DEVICE
  107. }
  108. };
  109. static struct uart_port ixp2000_serial_port = {
  110. .membase = (char *)(IXP2000_UART_VIRT_BASE + 3),
  111. .mapbase = IXP2000_UART_PHYS_BASE + 3,
  112. .irq = IRQ_IXP2000_UART,
  113. .flags = UPF_SKIP_TEST,
  114. .iotype = UPIO_MEM,
  115. .regshift = 2,
  116. .uartclk = 50000000,
  117. .line = 0,
  118. .type = PORT_XSCALE,
  119. .fifosize = 16
  120. };
  121. void __init ixp2000_map_io(void)
  122. {
  123. extern unsigned int processor_id;
  124. /*
  125. * On IXP2400 CPUs we need to use MT_IXP2000_DEVICE for
  126. * tweaking the PMDs so XCB=101. On IXP2800s we use the normal
  127. * PMD flags.
  128. */
  129. if ((processor_id & 0xfffffff0) == 0x69054190) {
  130. int i;
  131. printk(KERN_INFO "Enabling IXP2400 erratum #66 workaround\n");
  132. for(i=0;i<ARRAY_SIZE(ixp2000_io_desc);i++)
  133. ixp2000_io_desc[i].type = MT_IXP2000_DEVICE;
  134. }
  135. iotable_init(ixp2000_io_desc, ARRAY_SIZE(ixp2000_io_desc));
  136. early_serial_setup(&ixp2000_serial_port);
  137. /* Set slowport to 8-bit mode. */
  138. ixp2000_reg_write(IXP2000_SLOWPORT_FRM, 1);
  139. }
  140. /*************************************************************************
  141. * Timer-tick functions for IXP2000
  142. *************************************************************************/
  143. static unsigned ticks_per_jiffy;
  144. static unsigned ticks_per_usec;
  145. static unsigned next_jiffy_time;
  146. unsigned long ixp2000_gettimeoffset (void)
  147. {
  148. unsigned long offset;
  149. offset = next_jiffy_time - *IXP2000_T4_CSR;
  150. return offset / ticks_per_usec;
  151. }
  152. static int ixp2000_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  153. {
  154. write_seqlock(&xtime_lock);
  155. /* clear timer 1 */
  156. ixp2000_reg_write(IXP2000_T1_CLR, 1);
  157. while ((next_jiffy_time - *IXP2000_T4_CSR) > ticks_per_jiffy) {
  158. timer_tick(regs);
  159. next_jiffy_time -= ticks_per_jiffy;
  160. }
  161. write_sequnlock(&xtime_lock);
  162. return IRQ_HANDLED;
  163. }
  164. static struct irqaction ixp2000_timer_irq = {
  165. .name = "IXP2000 Timer Tick",
  166. .flags = SA_INTERRUPT,
  167. .handler = ixp2000_timer_interrupt
  168. };
  169. void __init ixp2000_init_time(unsigned long tick_rate)
  170. {
  171. ixp2000_reg_write(IXP2000_T1_CLR, 0);
  172. ixp2000_reg_write(IXP2000_T4_CLR, 0);
  173. ticks_per_jiffy = (tick_rate + HZ/2) / HZ;
  174. ticks_per_usec = tick_rate / 1000000;
  175. ixp2000_reg_write(IXP2000_T1_CLD, ticks_per_jiffy - 1);
  176. ixp2000_reg_write(IXP2000_T1_CTL, (1 << 7));
  177. /*
  178. * We use T4 as a monotonic counter to track missed jiffies
  179. */
  180. ixp2000_reg_write(IXP2000_T4_CLD, -1);
  181. ixp2000_reg_write(IXP2000_T4_CTL, (1 << 7));
  182. next_jiffy_time = 0xffffffff;
  183. /* register for interrupt */
  184. setup_irq(IRQ_IXP2000_TIMER1, &ixp2000_timer_irq);
  185. }
  186. /*************************************************************************
  187. * GPIO helpers
  188. *************************************************************************/
  189. static unsigned long GPIO_IRQ_rising_edge;
  190. static unsigned long GPIO_IRQ_falling_edge;
  191. static unsigned long GPIO_IRQ_level_low;
  192. static unsigned long GPIO_IRQ_level_high;
  193. void gpio_line_config(int line, int style)
  194. {
  195. unsigned long flags;
  196. local_irq_save(flags);
  197. if(style == GPIO_OUT) {
  198. /* if it's an output, it ain't an interrupt anymore */
  199. ixp2000_reg_write(IXP2000_GPIO_PDSR, (1 << line));
  200. GPIO_IRQ_falling_edge &= ~(1 << line);
  201. GPIO_IRQ_rising_edge &= ~(1 << line);
  202. GPIO_IRQ_level_low &= ~(1 << line);
  203. GPIO_IRQ_level_high &= ~(1 << line);
  204. ixp2000_reg_write(IXP2000_GPIO_FEDR, GPIO_IRQ_falling_edge);
  205. ixp2000_reg_write(IXP2000_GPIO_REDR, GPIO_IRQ_rising_edge);
  206. ixp2000_reg_write(IXP2000_GPIO_LSHR, GPIO_IRQ_level_high);
  207. ixp2000_reg_write(IXP2000_GPIO_LSLR, GPIO_IRQ_level_low);
  208. irq_desc[line+IRQ_IXP2000_GPIO0].valid = 0;
  209. } else if(style == GPIO_IN) {
  210. ixp2000_reg_write(IXP2000_GPIO_PDCR, (1 << line));
  211. }
  212. local_irq_restore(flags);
  213. }
  214. /*************************************************************************
  215. * IRQ handling IXP2000
  216. *************************************************************************/
  217. static void ixp2000_GPIO_irq_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
  218. {
  219. int i;
  220. unsigned long status = *IXP2000_GPIO_INST;
  221. for (i = 0; i <= 7; i++) {
  222. if (status & (1<<i)) {
  223. desc = irq_desc + i + IRQ_IXP2000_GPIO0;
  224. desc->handle(i + IRQ_IXP2000_GPIO0, desc, regs);
  225. }
  226. }
  227. }
  228. static void ixp2000_GPIO_irq_mask_ack(unsigned int irq)
  229. {
  230. ixp2000_reg_write(IXP2000_GPIO_INCR, (1 << (irq - IRQ_IXP2000_GPIO0)));
  231. ixp2000_reg_write(IXP2000_GPIO_INST, (1 << (irq - IRQ_IXP2000_GPIO0)));
  232. }
  233. static void ixp2000_GPIO_irq_mask(unsigned int irq)
  234. {
  235. ixp2000_reg_write(IXP2000_GPIO_INCR, (1 << (irq - IRQ_IXP2000_GPIO0)));
  236. }
  237. static void ixp2000_GPIO_irq_unmask(unsigned int irq)
  238. {
  239. ixp2000_reg_write(IXP2000_GPIO_INSR, (1 << (irq - IRQ_IXP2000_GPIO0)));
  240. }
  241. static struct irqchip ixp2000_GPIO_irq_chip = {
  242. .ack = ixp2000_GPIO_irq_mask_ack,
  243. .mask = ixp2000_GPIO_irq_mask,
  244. .unmask = ixp2000_GPIO_irq_unmask
  245. };
  246. static void ixp2000_pci_irq_mask(unsigned int irq)
  247. {
  248. unsigned long temp = *IXP2000_PCI_XSCALE_INT_ENABLE;
  249. if (irq == IRQ_IXP2000_PCIA)
  250. ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE, (temp & ~(1 << 26)));
  251. else if (irq == IRQ_IXP2000_PCIB)
  252. ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE, (temp & ~(1 << 27)));
  253. }
  254. static void ixp2000_pci_irq_unmask(unsigned int irq)
  255. {
  256. unsigned long temp = *IXP2000_PCI_XSCALE_INT_ENABLE;
  257. if (irq == IRQ_IXP2000_PCIA)
  258. ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE, (temp | (1 << 26)));
  259. else if (irq == IRQ_IXP2000_PCIB)
  260. ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE, (temp | (1 << 27)));
  261. }
  262. static struct irqchip ixp2000_pci_irq_chip = {
  263. .ack = ixp2000_pci_irq_mask,
  264. .mask = ixp2000_pci_irq_mask,
  265. .unmask = ixp2000_pci_irq_unmask
  266. };
  267. static void ixp2000_irq_mask(unsigned int irq)
  268. {
  269. ixp2000_reg_write(IXP2000_IRQ_ENABLE_CLR, (1 << irq));
  270. }
  271. static void ixp2000_irq_unmask(unsigned int irq)
  272. {
  273. ixp2000_reg_write(IXP2000_IRQ_ENABLE_SET, (1 << irq));
  274. }
  275. static struct irqchip ixp2000_irq_chip = {
  276. .ack = ixp2000_irq_mask,
  277. .mask = ixp2000_irq_mask,
  278. .unmask = ixp2000_irq_unmask
  279. };
  280. void __init ixp2000_init_irq(void)
  281. {
  282. int irq;
  283. /*
  284. * Mask all sources
  285. */
  286. ixp2000_reg_write(IXP2000_IRQ_ENABLE_CLR, 0xffffffff);
  287. ixp2000_reg_write(IXP2000_FIQ_ENABLE_CLR, 0xffffffff);
  288. /* clear all GPIO edge/level detects */
  289. ixp2000_reg_write(IXP2000_GPIO_REDR, 0);
  290. ixp2000_reg_write(IXP2000_GPIO_FEDR, 0);
  291. ixp2000_reg_write(IXP2000_GPIO_LSHR, 0);
  292. ixp2000_reg_write(IXP2000_GPIO_LSLR, 0);
  293. ixp2000_reg_write(IXP2000_GPIO_INCR, -1);
  294. /* clear PCI interrupt sources */
  295. ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE, 0);
  296. /*
  297. * Certain bits in the IRQ status register of the
  298. * IXP2000 are reserved. Instead of trying to map
  299. * things non 1:1 from bit position to IRQ number,
  300. * we mark the reserved IRQs as invalid. This makes
  301. * our mask/unmask code much simpler.
  302. */
  303. for (irq = IRQ_IXP2000_SOFT_INT; irq <= IRQ_IXP2000_THDB3; irq++) {
  304. if((1 << irq) & IXP2000_VALID_IRQ_MASK) {
  305. set_irq_chip(irq, &ixp2000_irq_chip);
  306. set_irq_handler(irq, do_level_IRQ);
  307. set_irq_flags(irq, IRQF_VALID);
  308. } else set_irq_flags(irq, 0);
  309. }
  310. /*
  311. * GPIO IRQs are invalid until someone sets the interrupt mode
  312. * by calling gpio_line_set();
  313. */
  314. for (irq = IRQ_IXP2000_GPIO0; irq <= IRQ_IXP2000_GPIO7; irq++) {
  315. set_irq_chip(irq, &ixp2000_GPIO_irq_chip);
  316. set_irq_handler(irq, do_level_IRQ);
  317. set_irq_flags(irq, 0);
  318. }
  319. set_irq_chained_handler(IRQ_IXP2000_GPIO, ixp2000_GPIO_irq_handler);
  320. /*
  321. * Enable PCI irqs. The actual PCI[AB] decoding is done in
  322. * entry-macro.S, so we don't need a chained handler for the
  323. * PCI interrupt source.
  324. */
  325. ixp2000_reg_write(IXP2000_IRQ_ENABLE_SET, (1 << IRQ_IXP2000_PCI));
  326. for (irq = IRQ_IXP2000_PCIA; irq <= IRQ_IXP2000_PCIB; irq++) {
  327. set_irq_chip(irq, &ixp2000_pci_irq_chip);
  328. set_irq_handler(irq, do_level_IRQ);
  329. set_irq_flags(irq, IRQF_VALID);
  330. }
  331. }