ARM: imx: pass gpio than irq number into mxc_expio_init
[deliverable/linux.git] / arch / arm / plat-mxc / 3ds_debugboard.c
CommitLineData
fa94f8dc
JW
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
13#include <linux/interrupt.h>
14#include <linux/irq.h>
15#include <linux/io.h>
16#include <linux/platform_device.h>
17#include <linux/gpio.h>
18#include <linux/smsc911x.h>
33499df8
SH
19#include <linux/regulator/machine.h>
20#include <linux/regulator/fixed.h>
fa94f8dc
JW
21
22#include <mach/hardware.h>
23
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
30#define BOARD_IO_ADDR(n) (n + 0x20000)
31/* LED switchs */
32#define LED_SWITCH_REG 0x00
33/* buttons */
34#define SWITCH_BUTTONS_REG 0x08
35/* status, interrupt */
36#define INTR_STATUS_REG 0x10
37#define INTR_MASK_REG 0x38
38#define INTR_RESET_REG 0x20
39/* magic word for debug CPLD */
40#define MAGIC_NUMBER1_REG 0x40
41#define MAGIC_NUMBER2_REG 0x48
42/* CPLD code version */
43#define CPLD_CODE_VER_REG 0x50
44/* magic word for debug CPLD */
45#define MAGIC_NUMBER3_REG 0x58
46/* module reset register*/
47#define MODULE_RESET_REG 0x60
48/* CPU ID and Personality ID */
49#define MCU_BOARD_ID_REG 0x68
50
51#define MXC_IRQ_TO_EXPIO(irq) ((irq) - MXC_BOARD_IRQ_START)
fa94f8dc
JW
52
53#define MXC_EXP_IO_BASE (MXC_BOARD_IRQ_START)
54#define MXC_MAX_EXP_IO_LINES 16
55
56/* interrupts like external uart , external ethernet etc*/
57#define EXPIO_INT_ENET (MXC_BOARD_IRQ_START + 0)
58#define EXPIO_INT_XUART_A (MXC_BOARD_IRQ_START + 1)
59#define EXPIO_INT_XUART_B (MXC_BOARD_IRQ_START + 2)
60#define EXPIO_INT_BUTTON_A (MXC_BOARD_IRQ_START + 3)
61#define EXPIO_INT_BUTTON_B (MXC_BOARD_IRQ_START + 4)
62
63static void __iomem *brd_io;
fa94f8dc
JW
64
65static struct resource smsc911x_resources[] = {
66 {
67 .flags = IORESOURCE_MEM,
68 } , {
69 .start = EXPIO_INT_ENET,
70 .end = EXPIO_INT_ENET,
71 .flags = IORESOURCE_IRQ,
72 },
73};
74
75static struct smsc911x_platform_config smsc911x_config = {
76 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
77 .flags = SMSC911X_USE_32BIT | SMSC911X_FORCE_INTERNAL_PHY,
78};
79
80static struct platform_device smsc_lan9217_device = {
81 .name = "smsc911x",
f0df8754 82 .id = -1,
fa94f8dc
JW
83 .dev = {
84 .platform_data = &smsc911x_config,
85 },
86 .num_resources = ARRAY_SIZE(smsc911x_resources),
87 .resource = smsc911x_resources,
88};
89
90static void mxc_expio_irq_handler(u32 irq, struct irq_desc *desc)
91{
92 u32 imr_val;
93 u32 int_valid;
94 u32 expio_irq;
95
4d93579f
LB
96 /* irq = gpio irq number */
97 desc->irq_data.chip->irq_mask(&desc->irq_data);
fa94f8dc
JW
98
99 imr_val = __raw_readw(brd_io + INTR_MASK_REG);
100 int_valid = __raw_readw(brd_io + INTR_STATUS_REG) & ~imr_val;
101
102 expio_irq = MXC_BOARD_IRQ_START;
103 for (; int_valid != 0; int_valid >>= 1, expio_irq++) {
fa94f8dc
JW
104 if ((int_valid & 1) == 0)
105 continue;
eb2d7188 106 generic_handle_irq(expio_irq);
fa94f8dc
JW
107 }
108
4d93579f
LB
109 desc->irq_data.chip->irq_ack(&desc->irq_data);
110 desc->irq_data.chip->irq_unmask(&desc->irq_data);
fa94f8dc
JW
111}
112
113/*
114 * Disable an expio pin's interrupt by setting the bit in the imr.
115 * Irq is an expio virtual irq number
116 */
4d93579f 117static void expio_mask_irq(struct irq_data *d)
fa94f8dc
JW
118{
119 u16 reg;
4d93579f 120 u32 expio = MXC_IRQ_TO_EXPIO(d->irq);
fa94f8dc
JW
121
122 reg = __raw_readw(brd_io + INTR_MASK_REG);
123 reg |= (1 << expio);
124 __raw_writew(reg, brd_io + INTR_MASK_REG);
125}
126
4d93579f 127static void expio_ack_irq(struct irq_data *d)
fa94f8dc 128{
4d93579f 129 u32 expio = MXC_IRQ_TO_EXPIO(d->irq);
fa94f8dc
JW
130
131 __raw_writew(1 << expio, brd_io + INTR_RESET_REG);
132 __raw_writew(0, brd_io + INTR_RESET_REG);
4d93579f 133 expio_mask_irq(d);
fa94f8dc
JW
134}
135
4d93579f 136static void expio_unmask_irq(struct irq_data *d)
fa94f8dc
JW
137{
138 u16 reg;
4d93579f 139 u32 expio = MXC_IRQ_TO_EXPIO(d->irq);
fa94f8dc
JW
140
141 reg = __raw_readw(brd_io + INTR_MASK_REG);
142 reg &= ~(1 << expio);
143 __raw_writew(reg, brd_io + INTR_MASK_REG);
144}
145
146static struct irq_chip expio_irq_chip = {
4d93579f
LB
147 .irq_ack = expio_ack_irq,
148 .irq_mask = expio_mask_irq,
149 .irq_unmask = expio_unmask_irq,
fa94f8dc
JW
150};
151
33499df8
SH
152static struct regulator_consumer_supply dummy_supplies[] = {
153 REGULATOR_SUPPLY("vdd33a", "smsc911x"),
154 REGULATOR_SUPPLY("vddvario", "smsc911x"),
155};
156
ed4a7fb0 157int __init mxc_expio_init(u32 base, u32 intr_gpio)
fa94f8dc 158{
ed4a7fb0 159 u32 p_irq = gpio_to_irq(intr_gpio);
fa94f8dc
JW
160 int i;
161
162 brd_io = ioremap(BOARD_IO_ADDR(base), SZ_4K);
163 if (brd_io == NULL)
164 return -ENOMEM;
165
166 if ((__raw_readw(brd_io + MAGIC_NUMBER1_REG) != 0xAAAA) ||
167 (__raw_readw(brd_io + MAGIC_NUMBER2_REG) != 0x5555) ||
168 (__raw_readw(brd_io + MAGIC_NUMBER3_REG) != 0xCAFE)) {
169 pr_info("3-Stack Debug board not detected\n");
170 iounmap(brd_io);
171 brd_io = NULL;
172 return -ENODEV;
173 }
174
175 pr_info("3-Stack Debug board detected, rev = 0x%04X\n",
176 readw(brd_io + CPLD_CODE_VER_REG));
177
178 /*
179 * Configure INT line as GPIO input
180 */
ed4a7fb0
SG
181 gpio_request(intr_gpio, "expio_pirq");
182 gpio_direction_input(intr_gpio);
fa94f8dc
JW
183
184 /* disable the interrupt and clear the status */
185 __raw_writew(0, brd_io + INTR_MASK_REG);
186 __raw_writew(0xFFFF, brd_io + INTR_RESET_REG);
187 __raw_writew(0, brd_io + INTR_RESET_REG);
188 __raw_writew(0x1F, brd_io + INTR_MASK_REG);
189 for (i = MXC_EXP_IO_BASE;
190 i < (MXC_EXP_IO_BASE + MXC_MAX_EXP_IO_LINES); i++) {
f38c02f3 191 irq_set_chip_and_handler(i, &expio_irq_chip, handle_level_irq);
fa94f8dc
JW
192 set_irq_flags(i, IRQF_VALID);
193 }
6845664a
TG
194 irq_set_irq_type(p_irq, IRQF_TRIGGER_LOW);
195 irq_set_chained_handler(p_irq, mxc_expio_irq_handler);
fa94f8dc
JW
196
197 /* Register Lan device on the debugboard */
33499df8
SH
198 regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
199
fa94f8dc
JW
200 smsc911x_resources[0].start = LAN9217_BASE_ADDR(base);
201 smsc911x_resources[0].end = LAN9217_BASE_ADDR(base) + 0x100 - 1;
202 platform_device_register(&smsc_lan9217_device);
203
204 return 0;
205}
This page took 0.213013 seconds and 5 git commands to generate.