3ds_debugboard.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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/irqdomain.h>
  15. #include <linux/io.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/gpio.h>
  18. #include <linux/module.h>
  19. #include <linux/smsc911x.h>
  20. #include <linux/regulator/machine.h>
  21. #include <linux/regulator/fixed.h>
  22. #include "3ds_debugboard.h"
  23. #include "hardware.h"
  24. /* LAN9217 ethernet base address */
  25. #define LAN9217_BASE_ADDR(n) (n + 0x0)
  26. /* External UART */
  27. #define UARTA_BASE_ADDR(n) (n + 0x8000)
  28. #define UARTB_BASE_ADDR(n) (n + 0x10000)
  29. #define BOARD_IO_ADDR(n) (n + 0x20000)
  30. /* LED switchs */
  31. #define LED_SWITCH_REG 0x00
  32. /* buttons */
  33. #define SWITCH_BUTTONS_REG 0x08
  34. /* status, interrupt */
  35. #define INTR_STATUS_REG 0x10
  36. #define INTR_MASK_REG 0x38
  37. #define INTR_RESET_REG 0x20
  38. /* magic word for debug CPLD */
  39. #define MAGIC_NUMBER1_REG 0x40
  40. #define MAGIC_NUMBER2_REG 0x48
  41. /* CPLD code version */
  42. #define CPLD_CODE_VER_REG 0x50
  43. /* magic word for debug CPLD */
  44. #define MAGIC_NUMBER3_REG 0x58
  45. /* module reset register*/
  46. #define MODULE_RESET_REG 0x60
  47. /* CPU ID and Personality ID */
  48. #define MCU_BOARD_ID_REG 0x68
  49. #define MXC_MAX_EXP_IO_LINES 16
  50. /* interrupts like external uart , external ethernet etc*/
  51. #define EXPIO_INT_ENET 0
  52. #define EXPIO_INT_XUART_A 1
  53. #define EXPIO_INT_XUART_B 2
  54. #define EXPIO_INT_BUTTON_A 3
  55. #define EXPIO_INT_BUTTON_B 4
  56. static void __iomem *brd_io;
  57. static struct irq_domain *domain;
  58. static struct resource smsc911x_resources[] = {
  59. {
  60. .flags = IORESOURCE_MEM,
  61. } , {
  62. .flags = IORESOURCE_IRQ,
  63. },
  64. };
  65. static struct smsc911x_platform_config smsc911x_config = {
  66. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  67. .flags = SMSC911X_USE_32BIT | SMSC911X_FORCE_INTERNAL_PHY,
  68. };
  69. static struct platform_device smsc_lan9217_device = {
  70. .name = "smsc911x",
  71. .id = -1,
  72. .dev = {
  73. .platform_data = &smsc911x_config,
  74. },
  75. .num_resources = ARRAY_SIZE(smsc911x_resources),
  76. .resource = smsc911x_resources,
  77. };
  78. static void mxc_expio_irq_handler(struct irq_desc *desc)
  79. {
  80. u32 imr_val;
  81. u32 int_valid;
  82. u32 expio_irq;
  83. /* irq = gpio irq number */
  84. desc->irq_data.chip->irq_mask(&desc->irq_data);
  85. imr_val = imx_readw(brd_io + INTR_MASK_REG);
  86. int_valid = imx_readw(brd_io + INTR_STATUS_REG) & ~imr_val;
  87. expio_irq = 0;
  88. for (; int_valid != 0; int_valid >>= 1, expio_irq++) {
  89. if ((int_valid & 1) == 0)
  90. continue;
  91. generic_handle_irq(irq_find_mapping(domain, expio_irq));
  92. }
  93. desc->irq_data.chip->irq_ack(&desc->irq_data);
  94. desc->irq_data.chip->irq_unmask(&desc->irq_data);
  95. }
  96. /*
  97. * Disable an expio pin's interrupt by setting the bit in the imr.
  98. * Irq is an expio virtual irq number
  99. */
  100. static void expio_mask_irq(struct irq_data *d)
  101. {
  102. u16 reg;
  103. u32 expio = d->hwirq;
  104. reg = imx_readw(brd_io + INTR_MASK_REG);
  105. reg |= (1 << expio);
  106. imx_writew(reg, brd_io + INTR_MASK_REG);
  107. }
  108. static void expio_ack_irq(struct irq_data *d)
  109. {
  110. u32 expio = d->hwirq;
  111. imx_writew(1 << expio, brd_io + INTR_RESET_REG);
  112. imx_writew(0, brd_io + INTR_RESET_REG);
  113. expio_mask_irq(d);
  114. }
  115. static void expio_unmask_irq(struct irq_data *d)
  116. {
  117. u16 reg;
  118. u32 expio = d->hwirq;
  119. reg = imx_readw(brd_io + INTR_MASK_REG);
  120. reg &= ~(1 << expio);
  121. imx_writew(reg, brd_io + INTR_MASK_REG);
  122. }
  123. static struct irq_chip expio_irq_chip = {
  124. .irq_ack = expio_ack_irq,
  125. .irq_mask = expio_mask_irq,
  126. .irq_unmask = expio_unmask_irq,
  127. };
  128. static struct regulator_consumer_supply dummy_supplies[] = {
  129. REGULATOR_SUPPLY("vdd33a", "smsc911x"),
  130. REGULATOR_SUPPLY("vddvario", "smsc911x"),
  131. };
  132. int __init mxc_expio_init(u32 base, u32 intr_gpio)
  133. {
  134. u32 p_irq = gpio_to_irq(intr_gpio);
  135. int irq_base;
  136. int i;
  137. brd_io = ioremap(BOARD_IO_ADDR(base), SZ_4K);
  138. if (brd_io == NULL)
  139. return -ENOMEM;
  140. if ((imx_readw(brd_io + MAGIC_NUMBER1_REG) != 0xAAAA) ||
  141. (imx_readw(brd_io + MAGIC_NUMBER2_REG) != 0x5555) ||
  142. (imx_readw(brd_io + MAGIC_NUMBER3_REG) != 0xCAFE)) {
  143. pr_info("3-Stack Debug board not detected\n");
  144. iounmap(brd_io);
  145. brd_io = NULL;
  146. return -ENODEV;
  147. }
  148. pr_info("3-Stack Debug board detected, rev = 0x%04X\n",
  149. readw(brd_io + CPLD_CODE_VER_REG));
  150. /*
  151. * Configure INT line as GPIO input
  152. */
  153. gpio_request(intr_gpio, "expio_pirq");
  154. gpio_direction_input(intr_gpio);
  155. /* disable the interrupt and clear the status */
  156. imx_writew(0, brd_io + INTR_MASK_REG);
  157. imx_writew(0xFFFF, brd_io + INTR_RESET_REG);
  158. imx_writew(0, brd_io + INTR_RESET_REG);
  159. imx_writew(0x1F, brd_io + INTR_MASK_REG);
  160. irq_base = irq_alloc_descs(-1, 0, MXC_MAX_EXP_IO_LINES, numa_node_id());
  161. WARN_ON(irq_base < 0);
  162. domain = irq_domain_add_legacy(NULL, MXC_MAX_EXP_IO_LINES, irq_base, 0,
  163. &irq_domain_simple_ops, NULL);
  164. WARN_ON(!domain);
  165. for (i = irq_base; i < irq_base + MXC_MAX_EXP_IO_LINES; i++) {
  166. irq_set_chip_and_handler(i, &expio_irq_chip, handle_level_irq);
  167. irq_clear_status_flags(i, IRQ_NOREQUEST);
  168. }
  169. irq_set_irq_type(p_irq, IRQF_TRIGGER_LOW);
  170. irq_set_chained_handler(p_irq, mxc_expio_irq_handler);
  171. /* Register Lan device on the debugboard */
  172. regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
  173. smsc911x_resources[0].start = LAN9217_BASE_ADDR(base);
  174. smsc911x_resources[0].end = LAN9217_BASE_ADDR(base) + 0x100 - 1;
  175. smsc911x_resources[1].start = irq_find_mapping(domain, EXPIO_INT_ENET);
  176. smsc911x_resources[1].end = irq_find_mapping(domain, EXPIO_INT_ENET);
  177. platform_device_register(&smsc_lan9217_device);
  178. return 0;
  179. }