board-a9m9750dev.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * arch/arm/mach-ns9xxx/board-a9m9750dev.c
  3. *
  4. * Copyright (C) 2006,2007 by Digi International Inc.
  5. * All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. */
  11. #include <linux/platform_device.h>
  12. #include <linux/serial_8250.h>
  13. #include <linux/irq.h>
  14. #include <asm/mach/map.h>
  15. #include <asm/gpio.h>
  16. #include <asm/arch-ns9xxx/board.h>
  17. #include <asm/arch-ns9xxx/regs-sys.h>
  18. #include <asm/arch-ns9xxx/regs-mem.h>
  19. #include <asm/arch-ns9xxx/regs-bbu.h>
  20. #include <asm/arch-ns9xxx/regs-board-a9m9750dev.h>
  21. #include "board-a9m9750dev.h"
  22. static struct map_desc board_a9m9750dev_io_desc[] __initdata = {
  23. { /* FPGA on CS0 */
  24. .virtual = io_p2v(NS9XXX_CSxSTAT_PHYS(0)),
  25. .pfn = __phys_to_pfn(NS9XXX_CSxSTAT_PHYS(0)),
  26. .length = NS9XXX_CS0STAT_LENGTH,
  27. .type = MT_DEVICE,
  28. },
  29. };
  30. void __init board_a9m9750dev_map_io(void)
  31. {
  32. iotable_init(board_a9m9750dev_io_desc,
  33. ARRAY_SIZE(board_a9m9750dev_io_desc));
  34. }
  35. static void a9m9750dev_fpga_ack_irq(unsigned int irq)
  36. {
  37. /* nothing */
  38. }
  39. static void a9m9750dev_fpga_mask_irq(unsigned int irq)
  40. {
  41. u8 ier;
  42. ier = __raw_readb(FPGA_IER);
  43. ier &= ~(1 << (irq - FPGA_IRQ(0)));
  44. __raw_writeb(ier, FPGA_IER);
  45. }
  46. static void a9m9750dev_fpga_maskack_irq(unsigned int irq)
  47. {
  48. a9m9750dev_fpga_mask_irq(irq);
  49. a9m9750dev_fpga_ack_irq(irq);
  50. }
  51. static void a9m9750dev_fpga_unmask_irq(unsigned int irq)
  52. {
  53. u8 ier;
  54. ier = __raw_readb(FPGA_IER);
  55. ier |= 1 << (irq - FPGA_IRQ(0));
  56. __raw_writeb(ier, FPGA_IER);
  57. }
  58. static struct irq_chip a9m9750dev_fpga_chip = {
  59. .ack = a9m9750dev_fpga_ack_irq,
  60. .mask = a9m9750dev_fpga_mask_irq,
  61. .mask_ack = a9m9750dev_fpga_maskack_irq,
  62. .unmask = a9m9750dev_fpga_unmask_irq,
  63. };
  64. static void a9m9750dev_fpga_demux_handler(unsigned int irq,
  65. struct irq_desc *desc)
  66. {
  67. u8 stat = __raw_readb(FPGA_ISR);
  68. desc->chip->mask_ack(irq);
  69. while (stat != 0) {
  70. int irqno = fls(stat) - 1;
  71. struct irq_desc *fpgadesc;
  72. stat &= ~(1 << irqno);
  73. fpgadesc = irq_desc + FPGA_IRQ(irqno);
  74. desc_handle_irq(FPGA_IRQ(irqno), fpgadesc);
  75. }
  76. desc->chip->unmask(irq);
  77. }
  78. void __init board_a9m9750dev_init_irq(void)
  79. {
  80. u32 eic;
  81. int i;
  82. if (gpio_request(11, "board a9m9750dev extirq2") == 0)
  83. ns9xxx_gpio_configure(11, 0, 1);
  84. else
  85. printk(KERN_ERR "%s: cannot get gpio 11 for IRQ_EXT2\n",
  86. __func__);
  87. for (i = FPGA_IRQ(0); i <= FPGA_IRQ(7); ++i) {
  88. set_irq_chip(i, &a9m9750dev_fpga_chip);
  89. set_irq_handler(i, handle_level_irq);
  90. set_irq_flags(i, IRQF_VALID);
  91. }
  92. /* IRQ_EXT2: level sensitive + active low */
  93. eic = __raw_readl(SYS_EIC(2));
  94. REGSET(eic, SYS_EIC, PLTY, AL);
  95. REGSET(eic, SYS_EIC, LVEDG, LEVEL);
  96. __raw_writel(eic, SYS_EIC(2));
  97. set_irq_chained_handler(IRQ_EXT2,
  98. a9m9750dev_fpga_demux_handler);
  99. }
  100. static struct plat_serial8250_port board_a9m9750dev_serial8250_port[] = {
  101. {
  102. .iobase = FPGA_UARTA_BASE,
  103. .membase = (unsigned char*)FPGA_UARTA_BASE,
  104. .mapbase = FPGA_UARTA_BASE,
  105. .irq = IRQ_FPGA_UARTA,
  106. .iotype = UPIO_MEM,
  107. .uartclk = 18432000,
  108. .regshift = 0,
  109. .flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ,
  110. }, {
  111. .iobase = FPGA_UARTB_BASE,
  112. .membase = (unsigned char*)FPGA_UARTB_BASE,
  113. .mapbase = FPGA_UARTB_BASE,
  114. .irq = IRQ_FPGA_UARTB,
  115. .iotype = UPIO_MEM,
  116. .uartclk = 18432000,
  117. .regshift = 0,
  118. .flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ,
  119. }, {
  120. .iobase = FPGA_UARTC_BASE,
  121. .membase = (unsigned char*)FPGA_UARTC_BASE,
  122. .mapbase = FPGA_UARTC_BASE,
  123. .irq = IRQ_FPGA_UARTC,
  124. .iotype = UPIO_MEM,
  125. .uartclk = 18432000,
  126. .regshift = 0,
  127. .flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ,
  128. }, {
  129. .iobase = FPGA_UARTD_BASE,
  130. .membase = (unsigned char*)FPGA_UARTD_BASE,
  131. .mapbase = FPGA_UARTD_BASE,
  132. .irq = IRQ_FPGA_UARTD,
  133. .iotype = UPIO_MEM,
  134. .uartclk = 18432000,
  135. .regshift = 0,
  136. .flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ,
  137. }, {
  138. /* end marker */
  139. },
  140. };
  141. static struct platform_device board_a9m9750dev_serial_device = {
  142. .name = "serial8250",
  143. .dev = {
  144. .platform_data = board_a9m9750dev_serial8250_port,
  145. },
  146. };
  147. static struct platform_device *board_a9m9750dev_devices[] __initdata = {
  148. &board_a9m9750dev_serial_device,
  149. };
  150. void __init board_a9m9750dev_init_machine(void)
  151. {
  152. u32 reg;
  153. /* setup static CS0: memory base ... */
  154. reg = __raw_readl(SYS_SMCSSMB(0));
  155. REGSETIM(reg, SYS_SMCSSMB, CSxB, NS9XXX_CSxSTAT_PHYS(0) >> 12);
  156. __raw_writel(reg, SYS_SMCSSMB(0));
  157. /* ... and mask */
  158. reg = __raw_readl(SYS_SMCSSMM(0));
  159. REGSETIM(reg, SYS_SMCSSMM, CSxM, 0xfffff);
  160. REGSET(reg, SYS_SMCSSMM, CSEx, EN);
  161. __raw_writel(reg, SYS_SMCSSMM(0));
  162. /* setup static CS0: memory configuration */
  163. reg = __raw_readl(MEM_SMC(0));
  164. REGSET(reg, MEM_SMC, PSMC, OFF);
  165. REGSET(reg, MEM_SMC, BSMC, OFF);
  166. REGSET(reg, MEM_SMC, EW, OFF);
  167. REGSET(reg, MEM_SMC, PB, 1);
  168. REGSET(reg, MEM_SMC, PC, AL);
  169. REGSET(reg, MEM_SMC, PM, DIS);
  170. REGSET(reg, MEM_SMC, MW, 8);
  171. __raw_writel(reg, MEM_SMC(0));
  172. /* setup static CS0: timing */
  173. __raw_writel(0x2, MEM_SMWED(0));
  174. __raw_writel(0x2, MEM_SMOED(0));
  175. __raw_writel(0x6, MEM_SMRD(0));
  176. __raw_writel(0x6, MEM_SMWD(0));
  177. platform_add_devices(board_a9m9750dev_devices,
  178. ARRAY_SIZE(board_a9m9750dev_devices));
  179. }