Fabio Estevam | 1553a1e | 2008-11-12 15:38:39 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | */ |
| 18 | |
| 19 | #include <linux/types.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/clk.h> |
| 22 | #include <linux/irq.h> |
Magnus Lilja | 135cad3 | 2009-05-17 20:18:08 +0200 | [diff] [blame] | 23 | #include <linux/gpio.h> |
Magnus Lilja | 2b0c367 | 2009-05-18 18:46:33 +0200 | [diff] [blame] | 24 | #include <linux/smsc911x.h> |
| 25 | #include <linux/platform_device.h> |
Fabio Estevam | 1553a1e | 2008-11-12 15:38:39 +0100 | [diff] [blame] | 26 | |
| 27 | #include <mach/hardware.h> |
| 28 | #include <asm/mach-types.h> |
| 29 | #include <asm/mach/arch.h> |
| 30 | #include <asm/mach/time.h> |
| 31 | #include <asm/memory.h> |
| 32 | #include <asm/mach/map.h> |
| 33 | #include <mach/common.h> |
Alberto Panizzo | 11a332adf | 2010-03-23 19:46:57 +0100 | [diff] [blame] | 34 | #include <mach/board-mx31_3ds.h> |
Fabio Estevam | 1553a1e | 2008-11-12 15:38:39 +0100 | [diff] [blame] | 35 | #include <mach/imx-uart.h> |
| 36 | #include <mach/iomux-mx3.h> |
Alberto Panizzo | a1b67b9 | 2010-03-23 19:49:35 +0100 | [diff] [blame^] | 37 | #include <mach/mxc_nand.h> |
Fabio Estevam | 1553a1e | 2008-11-12 15:38:39 +0100 | [diff] [blame] | 38 | #include "devices.h" |
| 39 | |
| 40 | /*! |
Alberto Panizzo | 11a332adf | 2010-03-23 19:46:57 +0100 | [diff] [blame] | 41 | * @file mx31_3ds.c |
Fabio Estevam | 1553a1e | 2008-11-12 15:38:39 +0100 | [diff] [blame] | 42 | * |
| 43 | * @brief This file contains the board-specific initialization routines. |
| 44 | * |
| 45 | * @ingroup System |
| 46 | */ |
| 47 | |
Alberto Panizzo | 11a332adf | 2010-03-23 19:46:57 +0100 | [diff] [blame] | 48 | static int mx31_3ds_pins[] = { |
Magnus Lilja | 153fa1d | 2009-05-16 12:43:10 +0200 | [diff] [blame] | 49 | /* UART1 */ |
Valentin Longchamp | 63d97667 | 2009-01-28 15:13:53 +0100 | [diff] [blame] | 50 | MX31_PIN_CTS1__CTS1, |
| 51 | MX31_PIN_RTS1__RTS1, |
| 52 | MX31_PIN_TXD1__TXD1, |
Magnus Lilja | 135cad3 | 2009-05-17 20:18:08 +0200 | [diff] [blame] | 53 | MX31_PIN_RXD1__RXD1, |
| 54 | IOMUX_MODE(MX31_PIN_GPIO1_1, IOMUX_CONFIG_GPIO), |
Valentin Longchamp | 63d97667 | 2009-01-28 15:13:53 +0100 | [diff] [blame] | 55 | }; |
| 56 | |
Alberto Panizzo | a1b67b9 | 2010-03-23 19:49:35 +0100 | [diff] [blame^] | 57 | /* |
| 58 | * NAND Flash |
| 59 | */ |
| 60 | static struct mxc_nand_platform_data imx31_3ds_nand_flash_pdata = { |
| 61 | .width = 1, |
| 62 | .hw_ecc = 1, |
| 63 | #ifdef MACH_MX31_3DS_MXC_NAND_USE_BBT |
| 64 | .flash_bbt = 1, |
| 65 | #endif |
| 66 | }; |
| 67 | |
Magnus Lilja | 153fa1d | 2009-05-16 12:43:10 +0200 | [diff] [blame] | 68 | static struct imxuart_platform_data uart_pdata = { |
| 69 | .flags = IMXUART_HAVE_RTSCTS, |
| 70 | }; |
Fabio Estevam | 1553a1e | 2008-11-12 15:38:39 +0100 | [diff] [blame] | 71 | |
Magnus Lilja | 135cad3 | 2009-05-17 20:18:08 +0200 | [diff] [blame] | 72 | /* |
Magnus Lilja | 2b0c367 | 2009-05-18 18:46:33 +0200 | [diff] [blame] | 73 | * Support for the SMSC9217 on the Debug board. |
| 74 | */ |
| 75 | |
| 76 | static struct smsc911x_platform_config smsc911x_config = { |
| 77 | .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW, |
| 78 | .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL, |
| 79 | .flags = SMSC911X_USE_16BIT | SMSC911X_FORCE_INTERNAL_PHY, |
| 80 | .phy_interface = PHY_INTERFACE_MODE_MII, |
| 81 | }; |
| 82 | |
| 83 | static struct resource smsc911x_resources[] = { |
| 84 | { |
| 85 | .start = LAN9217_BASE_ADDR, |
| 86 | .end = LAN9217_BASE_ADDR + 0xff, |
| 87 | .flags = IORESOURCE_MEM, |
| 88 | }, { |
| 89 | .start = EXPIO_INT_ENET, |
| 90 | .end = EXPIO_INT_ENET, |
| 91 | .flags = IORESOURCE_IRQ, |
| 92 | }, |
| 93 | }; |
| 94 | |
| 95 | static struct platform_device smsc911x_device = { |
| 96 | .name = "smsc911x", |
| 97 | .id = -1, |
| 98 | .num_resources = ARRAY_SIZE(smsc911x_resources), |
| 99 | .resource = smsc911x_resources, |
| 100 | .dev = { |
| 101 | .platform_data = &smsc911x_config, |
| 102 | }, |
| 103 | }; |
| 104 | |
| 105 | /* |
Magnus Lilja | 135cad3 | 2009-05-17 20:18:08 +0200 | [diff] [blame] | 106 | * Routines for the CPLD on the debug board. It contains a CPLD handling |
| 107 | * LEDs, switches, interrupts for Ethernet. |
| 108 | */ |
| 109 | |
Alberto Panizzo | 11a332adf | 2010-03-23 19:46:57 +0100 | [diff] [blame] | 110 | static void mx31_3ds_expio_irq_handler(uint32_t irq, struct irq_desc *desc) |
Magnus Lilja | 135cad3 | 2009-05-17 20:18:08 +0200 | [diff] [blame] | 111 | { |
| 112 | uint32_t imr_val; |
| 113 | uint32_t int_valid; |
| 114 | uint32_t expio_irq; |
| 115 | |
| 116 | imr_val = __raw_readw(CPLD_INT_MASK_REG); |
| 117 | int_valid = __raw_readw(CPLD_INT_STATUS_REG) & ~imr_val; |
| 118 | |
| 119 | expio_irq = MXC_EXP_IO_BASE; |
| 120 | for (; int_valid != 0; int_valid >>= 1, expio_irq++) { |
| 121 | if ((int_valid & 1) == 0) |
| 122 | continue; |
| 123 | generic_handle_irq(expio_irq); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Disable an expio pin's interrupt by setting the bit in the imr. |
| 129 | * @param irq an expio virtual irq number |
| 130 | */ |
| 131 | static void expio_mask_irq(uint32_t irq) |
| 132 | { |
| 133 | uint16_t reg; |
| 134 | uint32_t expio = MXC_IRQ_TO_EXPIO(irq); |
| 135 | |
| 136 | /* mask the interrupt */ |
| 137 | reg = __raw_readw(CPLD_INT_MASK_REG); |
| 138 | reg |= 1 << expio; |
| 139 | __raw_writew(reg, CPLD_INT_MASK_REG); |
| 140 | } |
| 141 | |
| 142 | /* |
| 143 | * Acknowledge an expanded io pin's interrupt by clearing the bit in the isr. |
| 144 | * @param irq an expanded io virtual irq number |
| 145 | */ |
| 146 | static void expio_ack_irq(uint32_t irq) |
| 147 | { |
| 148 | uint32_t expio = MXC_IRQ_TO_EXPIO(irq); |
| 149 | |
| 150 | /* clear the interrupt status */ |
| 151 | __raw_writew(1 << expio, CPLD_INT_RESET_REG); |
| 152 | __raw_writew(0, CPLD_INT_RESET_REG); |
| 153 | /* mask the interrupt */ |
| 154 | expio_mask_irq(irq); |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | * Enable a expio pin's interrupt by clearing the bit in the imr. |
| 159 | * @param irq a expio virtual irq number |
| 160 | */ |
| 161 | static void expio_unmask_irq(uint32_t irq) |
| 162 | { |
| 163 | uint16_t reg; |
| 164 | uint32_t expio = MXC_IRQ_TO_EXPIO(irq); |
| 165 | |
| 166 | /* unmask the interrupt */ |
| 167 | reg = __raw_readw(CPLD_INT_MASK_REG); |
| 168 | reg &= ~(1 << expio); |
| 169 | __raw_writew(reg, CPLD_INT_MASK_REG); |
| 170 | } |
| 171 | |
| 172 | static struct irq_chip expio_irq_chip = { |
| 173 | .ack = expio_ack_irq, |
| 174 | .mask = expio_mask_irq, |
| 175 | .unmask = expio_unmask_irq, |
| 176 | }; |
| 177 | |
Alberto Panizzo | 11a332adf | 2010-03-23 19:46:57 +0100 | [diff] [blame] | 178 | static int __init mx31_3ds_init_expio(void) |
Magnus Lilja | 135cad3 | 2009-05-17 20:18:08 +0200 | [diff] [blame] | 179 | { |
| 180 | int i; |
| 181 | int ret; |
| 182 | |
| 183 | /* Check if there's a debug board connected */ |
| 184 | if ((__raw_readw(CPLD_MAGIC_NUMBER1_REG) != 0xAAAA) || |
| 185 | (__raw_readw(CPLD_MAGIC_NUMBER2_REG) != 0x5555) || |
| 186 | (__raw_readw(CPLD_MAGIC_NUMBER3_REG) != 0xCAFE)) { |
| 187 | /* No Debug board found */ |
| 188 | return -ENODEV; |
| 189 | } |
| 190 | |
Alberto Panizzo | 11a332adf | 2010-03-23 19:46:57 +0100 | [diff] [blame] | 191 | pr_info("i.MX31 3DS Debug board detected, rev = 0x%04X\n", |
Magnus Lilja | 135cad3 | 2009-05-17 20:18:08 +0200 | [diff] [blame] | 192 | __raw_readw(CPLD_CODE_VER_REG)); |
| 193 | |
| 194 | /* |
| 195 | * Configure INT line as GPIO input |
| 196 | */ |
| 197 | ret = gpio_request(IOMUX_TO_GPIO(MX31_PIN_GPIO1_1), "sms9217-irq"); |
| 198 | if (ret) |
| 199 | pr_warning("could not get LAN irq gpio\n"); |
| 200 | else |
| 201 | gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_GPIO1_1)); |
| 202 | |
| 203 | /* Disable the interrupts and clear the status */ |
| 204 | __raw_writew(0, CPLD_INT_MASK_REG); |
| 205 | __raw_writew(0xFFFF, CPLD_INT_RESET_REG); |
| 206 | __raw_writew(0, CPLD_INT_RESET_REG); |
| 207 | __raw_writew(0x1F, CPLD_INT_MASK_REG); |
| 208 | for (i = MXC_EXP_IO_BASE; |
| 209 | i < (MXC_EXP_IO_BASE + MXC_MAX_EXP_IO_LINES); |
| 210 | i++) { |
| 211 | set_irq_chip(i, &expio_irq_chip); |
| 212 | set_irq_handler(i, handle_level_irq); |
| 213 | set_irq_flags(i, IRQF_VALID); |
| 214 | } |
| 215 | set_irq_type(EXPIO_PARENT_INT, IRQ_TYPE_LEVEL_LOW); |
Alberto Panizzo | 11a332adf | 2010-03-23 19:46:57 +0100 | [diff] [blame] | 216 | set_irq_chained_handler(EXPIO_PARENT_INT, mx31_3ds_expio_irq_handler); |
Magnus Lilja | 135cad3 | 2009-05-17 20:18:08 +0200 | [diff] [blame] | 217 | |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | /* |
| 222 | * This structure defines the MX31 memory map. |
| 223 | */ |
Alberto Panizzo | 11a332adf | 2010-03-23 19:46:57 +0100 | [diff] [blame] | 224 | static struct map_desc mx31_3ds_io_desc[] __initdata = { |
Magnus Lilja | 135cad3 | 2009-05-17 20:18:08 +0200 | [diff] [blame] | 225 | { |
Uwe Kleine-König | f568dd7 | 2009-12-09 11:57:21 +0100 | [diff] [blame] | 226 | .virtual = MX31_CS5_BASE_ADDR_VIRT, |
| 227 | .pfn = __phys_to_pfn(MX31_CS5_BASE_ADDR), |
| 228 | .length = MX31_CS5_SIZE, |
Magnus Lilja | 135cad3 | 2009-05-17 20:18:08 +0200 | [diff] [blame] | 229 | .type = MT_DEVICE, |
| 230 | }, |
| 231 | }; |
| 232 | |
| 233 | /* |
| 234 | * Set up static virtual mappings. |
| 235 | */ |
Alberto Panizzo | 11a332adf | 2010-03-23 19:46:57 +0100 | [diff] [blame] | 236 | static void __init mx31_3ds_map_io(void) |
Magnus Lilja | 135cad3 | 2009-05-17 20:18:08 +0200 | [diff] [blame] | 237 | { |
| 238 | mx31_map_io(); |
Alberto Panizzo | 11a332adf | 2010-03-23 19:46:57 +0100 | [diff] [blame] | 239 | iotable_init(mx31_3ds_io_desc, ARRAY_SIZE(mx31_3ds_io_desc)); |
Magnus Lilja | 135cad3 | 2009-05-17 20:18:08 +0200 | [diff] [blame] | 240 | } |
| 241 | |
Fabio Estevam | 1553a1e | 2008-11-12 15:38:39 +0100 | [diff] [blame] | 242 | /*! |
Fabio Estevam | 1553a1e | 2008-11-12 15:38:39 +0100 | [diff] [blame] | 243 | * Board specific initialization. |
| 244 | */ |
| 245 | static void __init mxc_board_init(void) |
| 246 | { |
Alberto Panizzo | 11a332adf | 2010-03-23 19:46:57 +0100 | [diff] [blame] | 247 | mxc_iomux_setup_multiple_pins(mx31_3ds_pins, ARRAY_SIZE(mx31_3ds_pins), |
| 248 | "mx31_3ds"); |
Magnus Lilja | 153fa1d | 2009-05-16 12:43:10 +0200 | [diff] [blame] | 249 | |
| 250 | mxc_register_device(&mxc_uart_device0, &uart_pdata); |
Alberto Panizzo | a1b67b9 | 2010-03-23 19:49:35 +0100 | [diff] [blame^] | 251 | mxc_register_device(&mxc_nand_device, &imx31_3ds_nand_flash_pdata); |
Magnus Lilja | 135cad3 | 2009-05-17 20:18:08 +0200 | [diff] [blame] | 252 | |
Alberto Panizzo | 11a332adf | 2010-03-23 19:46:57 +0100 | [diff] [blame] | 253 | if (!mx31_3ds_init_expio()) |
Magnus Lilja | 2b0c367 | 2009-05-18 18:46:33 +0200 | [diff] [blame] | 254 | platform_device_register(&smsc911x_device); |
Fabio Estevam | 1553a1e | 2008-11-12 15:38:39 +0100 | [diff] [blame] | 255 | } |
| 256 | |
Alberto Panizzo | 11a332adf | 2010-03-23 19:46:57 +0100 | [diff] [blame] | 257 | static void __init mx31_3ds_timer_init(void) |
Fabio Estevam | 1553a1e | 2008-11-12 15:38:39 +0100 | [diff] [blame] | 258 | { |
Sascha Hauer | 30c730f | 2009-02-16 14:36:49 +0100 | [diff] [blame] | 259 | mx31_clocks_init(26000000); |
Fabio Estevam | 1553a1e | 2008-11-12 15:38:39 +0100 | [diff] [blame] | 260 | } |
| 261 | |
Alberto Panizzo | 11a332adf | 2010-03-23 19:46:57 +0100 | [diff] [blame] | 262 | static struct sys_timer mx31_3ds_timer = { |
| 263 | .init = mx31_3ds_timer_init, |
Fabio Estevam | 1553a1e | 2008-11-12 15:38:39 +0100 | [diff] [blame] | 264 | }; |
| 265 | |
| 266 | /* |
| 267 | * The following uses standard kernel macros defined in arch.h in order to |
Alberto Panizzo | 11a332adf | 2010-03-23 19:46:57 +0100 | [diff] [blame] | 268 | * initialize __mach_desc_MX31_3DS data structure. |
Fabio Estevam | 1553a1e | 2008-11-12 15:38:39 +0100 | [diff] [blame] | 269 | */ |
| 270 | MACHINE_START(MX31_3DS, "Freescale MX31PDK (3DS)") |
| 271 | /* Maintainer: Freescale Semiconductor, Inc. */ |
Uwe Kleine-König | f568dd7 | 2009-12-09 11:57:21 +0100 | [diff] [blame] | 272 | .phys_io = MX31_AIPS1_BASE_ADDR, |
Uwe Kleine-König | 321ed16 | 2009-12-10 10:41:26 +0100 | [diff] [blame] | 273 | .io_pg_offst = (MX31_AIPS1_BASE_ADDR_VIRT >> 18) & 0xfffc, |
Uwe Kleine-König | 3410123 | 2010-01-29 17:36:05 +0100 | [diff] [blame] | 274 | .boot_params = MX3x_PHYS_OFFSET + 0x100, |
Alberto Panizzo | 11a332adf | 2010-03-23 19:46:57 +0100 | [diff] [blame] | 275 | .map_io = mx31_3ds_map_io, |
Sascha Hauer | c5aa0ad | 2009-05-25 17:36:19 +0200 | [diff] [blame] | 276 | .init_irq = mx31_init_irq, |
Fabio Estevam | 1553a1e | 2008-11-12 15:38:39 +0100 | [diff] [blame] | 277 | .init_machine = mxc_board_init, |
Alberto Panizzo | 11a332adf | 2010-03-23 19:46:57 +0100 | [diff] [blame] | 278 | .timer = &mx31_3ds_timer, |
Fabio Estevam | 1553a1e | 2008-11-12 15:38:39 +0100 | [diff] [blame] | 279 | MACHINE_END |