3ds_debugboard.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
  3. * Copyright (C) 2010 Jason Wang <jason77.wang@gmail.com>
  4. *
  5. * The code contained herein is licensed under the GNU General Public
  6. * License. You may obtain a copy of the GNU General Public License
  7. * Version 2 or later at the following locations:
  8. *
  9. * http://www.opensource.org/licenses/gpl-license.html
  10. * http://www.gnu.org/copyleft/gpl.html
  11. */
  12. #include <linux/interrupt.h>
  13. #include <linux/irq.h>
  14. #include <linux/io.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/gpio.h>
  17. #include <linux/smsc911x.h>
  18. #include <linux/regulator/machine.h>
  19. #include <linux/regulator/fixed.h>
  20. #include <mach/hardware.h>
  21. /* LAN9217 ethernet base address */
  22. #define LAN9217_BASE_ADDR(n) (n + 0x0)
  23. /* External UART */
  24. #define UARTA_BASE_ADDR(n) (n + 0x8000)
  25. #define UARTB_BASE_ADDR(n) (n + 0x10000)
  26. #define BOARD_IO_ADDR(n) (n + 0x20000)
  27. /* LED switchs */
  28. #define LED_SWITCH_REG 0x00
  29. /* buttons */
  30. #define SWITCH_BUTTONS_REG 0x08
  31. /* status, interrupt */
  32. #define INTR_STATUS_REG 0x10
  33. #define INTR_MASK_REG 0x38
  34. #define INTR_RESET_REG 0x20
  35. /* magic word for debug CPLD */
  36. #define MAGIC_NUMBER1_REG 0x40
  37. #define MAGIC_NUMBER2_REG 0x48
  38. /* CPLD code version */
  39. #define CPLD_CODE_VER_REG 0x50
  40. /* magic word for debug CPLD */
  41. #define MAGIC_NUMBER3_REG 0x58
  42. /* module reset register*/
  43. #define MODULE_RESET_REG 0x60
  44. /* CPU ID and Personality ID */
  45. #define MCU_BOARD_ID_REG 0x68
  46. #define MXC_IRQ_TO_EXPIO(irq) ((irq) - MXC_BOARD_IRQ_START)
  47. #define MXC_IRQ_TO_GPIO(irq) ((irq) - MXC_INTERNAL_IRQS)
  48. #define MXC_EXP_IO_BASE (MXC_BOARD_IRQ_START)
  49. #define MXC_MAX_EXP_IO_LINES 16
  50. /* interrupts like external uart , external ethernet etc*/
  51. #define EXPIO_INT_ENET (MXC_BOARD_IRQ_START + 0)
  52. #define EXPIO_INT_XUART_A (MXC_BOARD_IRQ_START + 1)
  53. #define EXPIO_INT_XUART_B (MXC_BOARD_IRQ_START + 2)
  54. #define EXPIO_INT_BUTTON_A (MXC_BOARD_IRQ_START + 3)
  55. #define EXPIO_INT_BUTTON_B (MXC_BOARD_IRQ_START + 4)
  56. static void __iomem *brd_io;
  57. static struct resource smsc911x_resources[] = {
  58. {
  59. .flags = IORESOURCE_MEM,
  60. } , {
  61. .start = EXPIO_INT_ENET,
  62. .end = EXPIO_INT_ENET,
  63. .flags = IORESOURCE_IRQ,
  64. },
  65. };
  66. static struct smsc911x_platform_config smsc911x_config = {
  67. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  68. .flags = SMSC911X_USE_32BIT | SMSC911X_FORCE_INTERNAL_PHY,
  69. };
  70. static struct platform_device smsc_lan9217_device = {
  71. .name = "smsc911x",
  72. .id = -1,
  73. .dev = {
  74. .platform_data = &smsc911x_config,
  75. },
  76. .num_resources = ARRAY_SIZE(smsc911x_resources),
  77. .resource = smsc911x_resources,
  78. };
  79. static void mxc_expio_irq_handler(u32 irq, struct irq_desc *desc)
  80. {
  81. u32 imr_val;
  82. u32 int_valid;
  83. u32 expio_irq;
  84. /* irq = gpio irq number */
  85. desc->irq_data.chip->irq_mask(&desc->irq_data);
  86. imr_val = __raw_readw(brd_io + INTR_MASK_REG);
  87. int_valid = __raw_readw(brd_io + INTR_STATUS_REG) & ~imr_val;
  88. expio_irq = MXC_BOARD_IRQ_START;
  89. for (; int_valid != 0; int_valid >>= 1, expio_irq++) {
  90. if ((int_valid & 1) == 0)
  91. continue;
  92. generic_handle_irq(expio_irq);
  93. }
  94. desc->irq_data.chip->irq_ack(&desc->irq_data);
  95. desc->irq_data.chip->irq_unmask(&desc->irq_data);
  96. }
  97. /*
  98. * Disable an expio pin's interrupt by setting the bit in the imr.
  99. * Irq is an expio virtual irq number
  100. */
  101. static void expio_mask_irq(struct irq_data *d)
  102. {
  103. u16 reg;
  104. u32 expio = MXC_IRQ_TO_EXPIO(d->irq);
  105. reg = __raw_readw(brd_io + INTR_MASK_REG);
  106. reg |= (1 << expio);
  107. __raw_writew(reg, brd_io + INTR_MASK_REG);
  108. }
  109. static void expio_ack_irq(struct irq_data *d)
  110. {
  111. u32 expio = MXC_IRQ_TO_EXPIO(d->irq);
  112. __raw_writew(1 << expio, brd_io + INTR_RESET_REG);
  113. __raw_writew(0, brd_io + INTR_RESET_REG);
  114. expio_mask_irq(d);
  115. }
  116. static void expio_unmask_irq(struct irq_data *d)
  117. {
  118. u16 reg;
  119. u32 expio = MXC_IRQ_TO_EXPIO(d->irq);
  120. reg = __raw_readw(brd_io + INTR_MASK_REG);
  121. reg &= ~(1 << expio);
  122. __raw_writew(reg, brd_io + INTR_MASK_REG);
  123. }
  124. static struct irq_chip expio_irq_chip = {
  125. .irq_ack = expio_ack_irq,
  126. .irq_mask = expio_mask_irq,
  127. .irq_unmask = expio_unmask_irq,
  128. };
  129. static struct regulator_consumer_supply dummy_supplies[] = {
  130. REGULATOR_SUPPLY("vdd33a", "smsc911x"),
  131. REGULATOR_SUPPLY("vddvario", "smsc911x"),
  132. };
  133. int __init mxc_expio_init(u32 base, u32 p_irq)
  134. {
  135. int i;
  136. brd_io = ioremap(BOARD_IO_ADDR(base), SZ_4K);
  137. if (brd_io == NULL)
  138. return -ENOMEM;
  139. if ((__raw_readw(brd_io + MAGIC_NUMBER1_REG) != 0xAAAA) ||
  140. (__raw_readw(brd_io + MAGIC_NUMBER2_REG) != 0x5555) ||
  141. (__raw_readw(brd_io + MAGIC_NUMBER3_REG) != 0xCAFE)) {
  142. pr_info("3-Stack Debug board not detected\n");
  143. iounmap(brd_io);
  144. brd_io = NULL;
  145. return -ENODEV;
  146. }
  147. pr_info("3-Stack Debug board detected, rev = 0x%04X\n",
  148. readw(brd_io + CPLD_CODE_VER_REG));
  149. /*
  150. * Configure INT line as GPIO input
  151. */
  152. gpio_request(MXC_IRQ_TO_GPIO(p_irq), "expio_pirq");
  153. gpio_direction_input(MXC_IRQ_TO_GPIO(p_irq));
  154. /* disable the interrupt and clear the status */
  155. __raw_writew(0, brd_io + INTR_MASK_REG);
  156. __raw_writew(0xFFFF, brd_io + INTR_RESET_REG);
  157. __raw_writew(0, brd_io + INTR_RESET_REG);
  158. __raw_writew(0x1F, brd_io + INTR_MASK_REG);
  159. for (i = MXC_EXP_IO_BASE;
  160. i < (MXC_EXP_IO_BASE + MXC_MAX_EXP_IO_LINES); i++) {
  161. irq_set_chip_and_handler(i, &expio_irq_chip, handle_level_irq);
  162. set_irq_flags(i, IRQF_VALID);
  163. }
  164. irq_set_irq_type(p_irq, IRQF_TRIGGER_LOW);
  165. irq_set_chained_handler(p_irq, mxc_expio_irq_handler);
  166. /* Register Lan device on the debugboard */
  167. regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
  168. smsc911x_resources[0].start = LAN9217_BASE_ADDR(base);
  169. smsc911x_resources[0].end = LAN9217_BASE_ADDR(base) + 0x100 - 1;
  170. platform_device_register(&smsc_lan9217_device);
  171. return 0;
  172. }