core.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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. #include <asm/arch/gpio.h>
  40. static DEFINE_SPINLOCK(ixp2000_slowport_lock);
  41. static unsigned long ixp2000_slowport_irq_flags;
  42. /*************************************************************************
  43. * Slowport access routines
  44. *************************************************************************/
  45. void ixp2000_acquire_slowport(struct slowport_cfg *new_cfg, struct slowport_cfg *old_cfg)
  46. {
  47. spin_lock_irqsave(&ixp2000_slowport_lock, ixp2000_slowport_irq_flags);
  48. old_cfg->CCR = *IXP2000_SLOWPORT_CCR;
  49. old_cfg->WTC = *IXP2000_SLOWPORT_WTC2;
  50. old_cfg->RTC = *IXP2000_SLOWPORT_RTC2;
  51. old_cfg->PCR = *IXP2000_SLOWPORT_PCR;
  52. old_cfg->ADC = *IXP2000_SLOWPORT_ADC;
  53. ixp2000_reg_write(IXP2000_SLOWPORT_CCR, new_cfg->CCR);
  54. ixp2000_reg_write(IXP2000_SLOWPORT_WTC2, new_cfg->WTC);
  55. ixp2000_reg_write(IXP2000_SLOWPORT_RTC2, new_cfg->RTC);
  56. ixp2000_reg_write(IXP2000_SLOWPORT_PCR, new_cfg->PCR);
  57. ixp2000_reg_write(IXP2000_SLOWPORT_ADC, new_cfg->ADC);
  58. }
  59. void ixp2000_release_slowport(struct slowport_cfg *old_cfg)
  60. {
  61. ixp2000_reg_write(IXP2000_SLOWPORT_CCR, old_cfg->CCR);
  62. ixp2000_reg_write(IXP2000_SLOWPORT_WTC2, old_cfg->WTC);
  63. ixp2000_reg_write(IXP2000_SLOWPORT_RTC2, old_cfg->RTC);
  64. ixp2000_reg_write(IXP2000_SLOWPORT_PCR, old_cfg->PCR);
  65. ixp2000_reg_write(IXP2000_SLOWPORT_ADC, old_cfg->ADC);
  66. spin_unlock_irqrestore(&ixp2000_slowport_lock,
  67. ixp2000_slowport_irq_flags);
  68. }
  69. /*************************************************************************
  70. * Chip specific mappings shared by all IXP2000 systems
  71. *************************************************************************/
  72. static struct map_desc ixp2000_io_desc[] __initdata = {
  73. {
  74. .virtual = IXP2000_CAP_VIRT_BASE,
  75. .physical = IXP2000_CAP_PHYS_BASE,
  76. .length = IXP2000_CAP_SIZE,
  77. .type = MT_DEVICE
  78. }, {
  79. .virtual = IXP2000_INTCTL_VIRT_BASE,
  80. .physical = IXP2000_INTCTL_PHYS_BASE,
  81. .length = IXP2000_INTCTL_SIZE,
  82. .type = MT_DEVICE
  83. }, {
  84. .virtual = IXP2000_PCI_CREG_VIRT_BASE,
  85. .physical = IXP2000_PCI_CREG_PHYS_BASE,
  86. .length = IXP2000_PCI_CREG_SIZE,
  87. .type = MT_DEVICE
  88. }, {
  89. .virtual = IXP2000_PCI_CSR_VIRT_BASE,
  90. .physical = IXP2000_PCI_CSR_PHYS_BASE,
  91. .length = IXP2000_PCI_CSR_SIZE,
  92. .type = MT_DEVICE
  93. }, {
  94. .virtual = IXP2000_MSF_VIRT_BASE,
  95. .physical = IXP2000_MSF_PHYS_BASE,
  96. .length = IXP2000_MSF_SIZE,
  97. .type = MT_DEVICE
  98. }, {
  99. .virtual = IXP2000_PCI_IO_VIRT_BASE,
  100. .physical = IXP2000_PCI_IO_PHYS_BASE,
  101. .length = IXP2000_PCI_IO_SIZE,
  102. .type = MT_DEVICE
  103. }, {
  104. .virtual = IXP2000_PCI_CFG0_VIRT_BASE,
  105. .physical = IXP2000_PCI_CFG0_PHYS_BASE,
  106. .length = IXP2000_PCI_CFG0_SIZE,
  107. .type = MT_DEVICE
  108. }, {
  109. .virtual = IXP2000_PCI_CFG1_VIRT_BASE,
  110. .physical = IXP2000_PCI_CFG1_PHYS_BASE,
  111. .length = IXP2000_PCI_CFG1_SIZE,
  112. .type = MT_DEVICE
  113. }
  114. };
  115. static struct uart_port ixp2000_serial_port = {
  116. .membase = (char *)(IXP2000_UART_VIRT_BASE + 3),
  117. .mapbase = IXP2000_UART_PHYS_BASE + 3,
  118. .irq = IRQ_IXP2000_UART,
  119. .flags = UPF_SKIP_TEST,
  120. .iotype = UPIO_MEM,
  121. .regshift = 2,
  122. .uartclk = 50000000,
  123. .line = 0,
  124. .type = PORT_XSCALE,
  125. .fifosize = 16
  126. };
  127. void __init ixp2000_map_io(void)
  128. {
  129. extern unsigned int processor_id;
  130. /*
  131. * On IXP2400 CPUs we need to use MT_IXP2000_DEVICE for
  132. * tweaking the PMDs so XCB=101. On IXP2800s we use the normal
  133. * PMD flags.
  134. */
  135. if ((processor_id & 0xfffffff0) == 0x69054190) {
  136. int i;
  137. printk(KERN_INFO "Enabling IXP2400 erratum #66 workaround\n");
  138. for(i=0;i<ARRAY_SIZE(ixp2000_io_desc);i++)
  139. ixp2000_io_desc[i].type = MT_IXP2000_DEVICE;
  140. }
  141. iotable_init(ixp2000_io_desc, ARRAY_SIZE(ixp2000_io_desc));
  142. early_serial_setup(&ixp2000_serial_port);
  143. /* Set slowport to 8-bit mode. */
  144. ixp2000_reg_write(IXP2000_SLOWPORT_FRM, 1);
  145. }
  146. /*************************************************************************
  147. * Timer-tick functions for IXP2000
  148. *************************************************************************/
  149. static unsigned ticks_per_jiffy;
  150. static unsigned ticks_per_usec;
  151. static unsigned next_jiffy_time;
  152. static volatile unsigned long *missing_jiffy_timer_csr;
  153. unsigned long ixp2000_gettimeoffset (void)
  154. {
  155. unsigned long offset;
  156. offset = next_jiffy_time - *missing_jiffy_timer_csr;
  157. return offset / ticks_per_usec;
  158. }
  159. static int ixp2000_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  160. {
  161. write_seqlock(&xtime_lock);
  162. /* clear timer 1 */
  163. ixp2000_reg_write(IXP2000_T1_CLR, 1);
  164. while ((next_jiffy_time - *missing_jiffy_timer_csr) > ticks_per_jiffy) {
  165. timer_tick(regs);
  166. next_jiffy_time -= ticks_per_jiffy;
  167. }
  168. write_sequnlock(&xtime_lock);
  169. return IRQ_HANDLED;
  170. }
  171. static struct irqaction ixp2000_timer_irq = {
  172. .name = "IXP2000 Timer Tick",
  173. .flags = SA_INTERRUPT | SA_TIMER,
  174. .handler = ixp2000_timer_interrupt,
  175. };
  176. void __init ixp2000_init_time(unsigned long tick_rate)
  177. {
  178. ticks_per_jiffy = (tick_rate + HZ/2) / HZ;
  179. ticks_per_usec = tick_rate / 1000000;
  180. /*
  181. * We use timer 1 as our timer interrupt.
  182. */
  183. ixp2000_reg_write(IXP2000_T1_CLR, 0);
  184. ixp2000_reg_write(IXP2000_T1_CLD, ticks_per_jiffy - 1);
  185. ixp2000_reg_write(IXP2000_T1_CTL, (1 << 7));
  186. /*
  187. * We use a second timer as a monotonic counter for tracking
  188. * missed jiffies. The IXP2000 has four timers, but if we're
  189. * on an A-step IXP2800, timer 2 and 3 don't work, so on those
  190. * chips we use timer 4. Timer 4 is the only timer that can
  191. * be used for the watchdog, so we use timer 2 if we're on a
  192. * non-buggy chip.
  193. */
  194. if ((*IXP2000_PRODUCT_ID & 0x001ffef0) == 0x00000000) {
  195. printk(KERN_INFO "Enabling IXP2800 erratum #25 workaround\n");
  196. ixp2000_reg_write(IXP2000_T4_CLR, 0);
  197. ixp2000_reg_write(IXP2000_T4_CLD, -1);
  198. ixp2000_reg_write(IXP2000_T4_CTL, (1 << 7));
  199. missing_jiffy_timer_csr = IXP2000_T4_CSR;
  200. } else {
  201. ixp2000_reg_write(IXP2000_T2_CLR, 0);
  202. ixp2000_reg_write(IXP2000_T2_CLD, -1);
  203. ixp2000_reg_write(IXP2000_T2_CTL, (1 << 7));
  204. missing_jiffy_timer_csr = IXP2000_T2_CSR;
  205. }
  206. next_jiffy_time = 0xffffffff;
  207. /* register for interrupt */
  208. setup_irq(IRQ_IXP2000_TIMER1, &ixp2000_timer_irq);
  209. }
  210. /*************************************************************************
  211. * GPIO helpers
  212. *************************************************************************/
  213. static unsigned long GPIO_IRQ_falling_edge;
  214. static unsigned long GPIO_IRQ_rising_edge;
  215. static unsigned long GPIO_IRQ_level_low;
  216. static unsigned long GPIO_IRQ_level_high;
  217. static void update_gpio_int_csrs(void)
  218. {
  219. ixp2000_reg_write(IXP2000_GPIO_FEDR, GPIO_IRQ_falling_edge);
  220. ixp2000_reg_write(IXP2000_GPIO_REDR, GPIO_IRQ_rising_edge);
  221. ixp2000_reg_write(IXP2000_GPIO_LSLR, GPIO_IRQ_level_low);
  222. ixp2000_reg_write(IXP2000_GPIO_LSHR, GPIO_IRQ_level_high);
  223. }
  224. void gpio_line_config(int line, int direction)
  225. {
  226. unsigned long flags;
  227. local_irq_save(flags);
  228. if (direction == GPIO_OUT) {
  229. irq_desc[line + IRQ_IXP2000_GPIO0].valid = 0;
  230. /* if it's an output, it ain't an interrupt anymore */
  231. GPIO_IRQ_falling_edge &= ~(1 << line);
  232. GPIO_IRQ_rising_edge &= ~(1 << line);
  233. GPIO_IRQ_level_low &= ~(1 << line);
  234. GPIO_IRQ_level_high &= ~(1 << line);
  235. update_gpio_int_csrs();
  236. ixp2000_reg_write(IXP2000_GPIO_PDSR, 1 << line);
  237. } else if (direction == GPIO_IN) {
  238. ixp2000_reg_write(IXP2000_GPIO_PDCR, 1 << line);
  239. }
  240. local_irq_restore(flags);
  241. }
  242. /*************************************************************************
  243. * IRQ handling IXP2000
  244. *************************************************************************/
  245. static void ixp2000_GPIO_irq_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
  246. {
  247. int i;
  248. unsigned long status = *IXP2000_GPIO_INST;
  249. for (i = 0; i <= 7; i++) {
  250. if (status & (1<<i)) {
  251. desc = irq_desc + i + IRQ_IXP2000_GPIO0;
  252. desc->handle(i + IRQ_IXP2000_GPIO0, desc, regs);
  253. }
  254. }
  255. }
  256. static int ixp2000_GPIO_irq_type(unsigned int irq, unsigned int type)
  257. {
  258. int line = irq - IRQ_IXP2000_GPIO0;
  259. /*
  260. * First, configure this GPIO line as an input.
  261. */
  262. ixp2000_reg_write(IXP2000_GPIO_PDCR, 1 << line);
  263. /*
  264. * Then, set the proper trigger type.
  265. */
  266. if (type & IRQT_FALLING)
  267. GPIO_IRQ_falling_edge |= 1 << line;
  268. else
  269. GPIO_IRQ_falling_edge &= ~(1 << line);
  270. if (type & IRQT_RISING)
  271. GPIO_IRQ_rising_edge |= 1 << line;
  272. else
  273. GPIO_IRQ_rising_edge &= ~(1 << line);
  274. if (type & IRQT_LOW)
  275. GPIO_IRQ_level_low |= 1 << line;
  276. else
  277. GPIO_IRQ_level_low &= ~(1 << line);
  278. if (type & IRQT_HIGH)
  279. GPIO_IRQ_level_high |= 1 << line;
  280. else
  281. GPIO_IRQ_level_high &= ~(1 << line);
  282. update_gpio_int_csrs();
  283. /*
  284. * Finally, mark the corresponding IRQ as valid.
  285. */
  286. irq_desc[irq].valid = 1;
  287. return 0;
  288. }
  289. static void ixp2000_GPIO_irq_mask_ack(unsigned int irq)
  290. {
  291. ixp2000_reg_write(IXP2000_GPIO_INCR, (1 << (irq - IRQ_IXP2000_GPIO0)));
  292. ixp2000_reg_write(IXP2000_GPIO_EDSR, (1 << (irq - IRQ_IXP2000_GPIO0)));
  293. ixp2000_reg_write(IXP2000_GPIO_LDSR, (1 << (irq - IRQ_IXP2000_GPIO0)));
  294. ixp2000_reg_write(IXP2000_GPIO_INST, (1 << (irq - IRQ_IXP2000_GPIO0)));
  295. }
  296. static void ixp2000_GPIO_irq_mask(unsigned int irq)
  297. {
  298. ixp2000_reg_write(IXP2000_GPIO_INCR, (1 << (irq - IRQ_IXP2000_GPIO0)));
  299. }
  300. static void ixp2000_GPIO_irq_unmask(unsigned int irq)
  301. {
  302. ixp2000_reg_write(IXP2000_GPIO_INSR, (1 << (irq - IRQ_IXP2000_GPIO0)));
  303. }
  304. static struct irqchip ixp2000_GPIO_irq_chip = {
  305. .type = ixp2000_GPIO_irq_type,
  306. .ack = ixp2000_GPIO_irq_mask_ack,
  307. .mask = ixp2000_GPIO_irq_mask,
  308. .unmask = ixp2000_GPIO_irq_unmask
  309. };
  310. static void ixp2000_pci_irq_mask(unsigned int irq)
  311. {
  312. unsigned long temp = *IXP2000_PCI_XSCALE_INT_ENABLE;
  313. if (irq == IRQ_IXP2000_PCIA)
  314. ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE, (temp & ~(1 << 26)));
  315. else if (irq == IRQ_IXP2000_PCIB)
  316. ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE, (temp & ~(1 << 27)));
  317. }
  318. static void ixp2000_pci_irq_unmask(unsigned int irq)
  319. {
  320. unsigned long temp = *IXP2000_PCI_XSCALE_INT_ENABLE;
  321. if (irq == IRQ_IXP2000_PCIA)
  322. ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE, (temp | (1 << 26)));
  323. else if (irq == IRQ_IXP2000_PCIB)
  324. ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE, (temp | (1 << 27)));
  325. }
  326. static struct irqchip ixp2000_pci_irq_chip = {
  327. .ack = ixp2000_pci_irq_mask,
  328. .mask = ixp2000_pci_irq_mask,
  329. .unmask = ixp2000_pci_irq_unmask
  330. };
  331. static void ixp2000_irq_mask(unsigned int irq)
  332. {
  333. ixp2000_reg_write(IXP2000_IRQ_ENABLE_CLR, (1 << irq));
  334. }
  335. static void ixp2000_irq_unmask(unsigned int irq)
  336. {
  337. ixp2000_reg_write(IXP2000_IRQ_ENABLE_SET, (1 << irq));
  338. }
  339. static struct irqchip ixp2000_irq_chip = {
  340. .ack = ixp2000_irq_mask,
  341. .mask = ixp2000_irq_mask,
  342. .unmask = ixp2000_irq_unmask
  343. };
  344. void __init ixp2000_init_irq(void)
  345. {
  346. int irq;
  347. /*
  348. * Mask all sources
  349. */
  350. ixp2000_reg_write(IXP2000_IRQ_ENABLE_CLR, 0xffffffff);
  351. ixp2000_reg_write(IXP2000_FIQ_ENABLE_CLR, 0xffffffff);
  352. /* clear all GPIO edge/level detects */
  353. ixp2000_reg_write(IXP2000_GPIO_REDR, 0);
  354. ixp2000_reg_write(IXP2000_GPIO_FEDR, 0);
  355. ixp2000_reg_write(IXP2000_GPIO_LSHR, 0);
  356. ixp2000_reg_write(IXP2000_GPIO_LSLR, 0);
  357. ixp2000_reg_write(IXP2000_GPIO_INCR, -1);
  358. /* clear PCI interrupt sources */
  359. ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE, 0);
  360. /*
  361. * Certain bits in the IRQ status register of the
  362. * IXP2000 are reserved. Instead of trying to map
  363. * things non 1:1 from bit position to IRQ number,
  364. * we mark the reserved IRQs as invalid. This makes
  365. * our mask/unmask code much simpler.
  366. */
  367. for (irq = IRQ_IXP2000_SOFT_INT; irq <= IRQ_IXP2000_THDB3; irq++) {
  368. if ((1 << irq) & IXP2000_VALID_IRQ_MASK) {
  369. set_irq_chip(irq, &ixp2000_irq_chip);
  370. set_irq_handler(irq, do_level_IRQ);
  371. set_irq_flags(irq, IRQF_VALID);
  372. } else set_irq_flags(irq, 0);
  373. }
  374. /*
  375. * GPIO IRQs are invalid until someone sets the interrupt mode
  376. * by calling set_irq_type().
  377. */
  378. for (irq = IRQ_IXP2000_GPIO0; irq <= IRQ_IXP2000_GPIO7; irq++) {
  379. set_irq_chip(irq, &ixp2000_GPIO_irq_chip);
  380. set_irq_handler(irq, do_level_IRQ);
  381. set_irq_flags(irq, 0);
  382. }
  383. set_irq_chained_handler(IRQ_IXP2000_GPIO, ixp2000_GPIO_irq_handler);
  384. /*
  385. * Enable PCI irqs. The actual PCI[AB] decoding is done in
  386. * entry-macro.S, so we don't need a chained handler for the
  387. * PCI interrupt source.
  388. */
  389. ixp2000_reg_write(IXP2000_IRQ_ENABLE_SET, (1 << IRQ_IXP2000_PCI));
  390. for (irq = IRQ_IXP2000_PCIA; irq <= IRQ_IXP2000_PCIB; irq++) {
  391. set_irq_chip(irq, &ixp2000_pci_irq_chip);
  392. set_irq_handler(irq, do_level_IRQ);
  393. set_irq_flags(irq, IRQF_VALID);
  394. }
  395. }