3ds_debugboard.c 5.6 KB

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