Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright STMicroelectronics, 2007. |
| 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/device.h> |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 22 | #include <linux/amba/bus.h> |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 23 | #include <linux/platform_device.h> |
Russell King | 35b47a405 | 2011-11-28 10:48:02 +0000 | [diff] [blame] | 24 | #include <linux/io.h> |
Linus Walleij | 7c77852 | 2012-01-09 12:40:02 +0100 | [diff] [blame] | 25 | #include <linux/slab.h> |
| 26 | #include <linux/irq.h> |
| 27 | #include <linux/dma-mapping.h> |
Linus Walleij | f8635ab | 2013-01-05 00:29:31 +0100 | [diff] [blame] | 28 | #include <linux/irqchip.h> |
Linus Walleij | 4a31bd2 | 2012-01-11 13:52:34 +0100 | [diff] [blame] | 29 | #include <linux/platform_data/clk-nomadik.h> |
Linus Walleij | bb16bd9 | 2012-10-10 14:27:58 +0200 | [diff] [blame] | 30 | #include <linux/platform_data/pinctrl-nomadik.h> |
Linus Walleij | 1b54275 | 2013-01-05 01:00:59 +0100 | [diff] [blame] | 31 | #include <linux/pinctrl/machine.h> |
Linus Walleij | f8635ab | 2013-01-05 00:29:31 +0100 | [diff] [blame] | 32 | #include <linux/platform_data/clocksource-nomadik-mtu.h> |
| 33 | #include <linux/of_irq.h> |
Linus Walleij | 2ad6e39 | 2013-01-06 01:02:42 +0100 | [diff] [blame] | 34 | #include <linux/of_gpio.h> |
Linus Walleij | f8635ab | 2013-01-05 00:29:31 +0100 | [diff] [blame] | 35 | #include <linux/of_address.h> |
| 36 | #include <linux/of_platform.h> |
Linus Walleij | ba78520 | 2013-01-05 22:28:32 +0100 | [diff] [blame] | 37 | #include <linux/mtd/fsmc.h> |
Linus Walleij | 2ad6e39 | 2013-01-06 01:02:42 +0100 | [diff] [blame] | 38 | #include <linux/gpio.h> |
Linus Walleij | 4fd243c | 2013-01-06 01:47:29 +0100 | [diff] [blame] | 39 | #include <linux/amba/mmci.h> |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 40 | |
| 41 | #include <mach/hardware.h> |
| 42 | #include <mach/irqs.h> |
Linus Walleij | f8635ab | 2013-01-05 00:29:31 +0100 | [diff] [blame] | 43 | #include <asm/mach/arch.h> |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 44 | #include <asm/mach/map.h> |
Linus Walleij | f8635ab | 2013-01-05 00:29:31 +0100 | [diff] [blame] | 45 | #include <asm/mach/time.h> |
Linus Walleij | 27bda03 | 2013-01-05 10:38:57 +0100 | [diff] [blame] | 46 | #include <asm/mach-types.h> |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 47 | |
Alessandro Rubini | 0b260fd | 2009-07-02 15:29:43 +0100 | [diff] [blame] | 48 | #include <asm/cacheflush.h> |
| 49 | #include <asm/hardware/cache-l2x0.h> |
| 50 | |
Linus Walleij | 1b54275 | 2013-01-05 01:00:59 +0100 | [diff] [blame] | 51 | static unsigned long out_low[] = { PIN_OUTPUT_LOW }; |
| 52 | static unsigned long out_high[] = { PIN_OUTPUT_HIGH }; |
| 53 | static unsigned long in_nopull[] = { PIN_INPUT_NOPULL }; |
| 54 | static unsigned long in_pullup[] = { PIN_INPUT_PULLUP }; |
| 55 | |
| 56 | static struct pinctrl_map __initdata nhk8815_pinmap[] = { |
| 57 | PIN_MAP_MUX_GROUP_DEFAULT("uart0", "pinctrl-stn8815", "u0_a_1", "u0"), |
| 58 | PIN_MAP_MUX_GROUP_DEFAULT("uart1", "pinctrl-stn8815", "u1_a_1", "u1"), |
| 59 | /* Hog in MMC/SD card mux */ |
| 60 | PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-stn8815", "mmcsd_a_1", "mmcsd"), |
| 61 | /* MCCLK */ |
| 62 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO8_B10", out_low), |
| 63 | /* MCCMD */ |
| 64 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO9_A10", in_pullup), |
| 65 | /* MCCMDDIR */ |
| 66 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO10_C11", out_high), |
| 67 | /* MCDAT3-0 */ |
| 68 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO11_B11", in_pullup), |
| 69 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO12_A11", in_pullup), |
| 70 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO13_C12", in_pullup), |
| 71 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO14_B12", in_pullup), |
| 72 | /* MCDAT0DIR */ |
| 73 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO15_A12", out_high), |
| 74 | /* MCDAT31DIR */ |
| 75 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO16_C13", out_high), |
| 76 | /* MCMSFBCLK */ |
| 77 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO24_C15", in_pullup), |
| 78 | /* CD input GPIO */ |
| 79 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO111_H21", in_nopull), |
| 80 | /* CD bias drive */ |
| 81 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO112_J21", out_low), |
| 82 | /* I2C0 */ |
| 83 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO62_D3", in_pullup), |
| 84 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO63_D2", in_pullup), |
| 85 | /* I2C1 */ |
| 86 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO53_L4", in_pullup), |
| 87 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO54_L3", in_pullup), |
| 88 | /* I2C2 */ |
| 89 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO73_C21", in_pullup), |
| 90 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO74_C20", in_pullup), |
| 91 | }; |
| 92 | |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 93 | /* All SoC devices live in the same area (see hardware.h) */ |
| 94 | static struct map_desc nomadik_io_desc[] __initdata = { |
| 95 | { |
| 96 | .virtual = NOMADIK_IO_VIRTUAL, |
| 97 | .pfn = __phys_to_pfn(NOMADIK_IO_PHYSICAL), |
| 98 | .length = NOMADIK_IO_SIZE, |
| 99 | .type = MT_DEVICE, |
| 100 | } |
| 101 | /* static ram and secured ram may be added later */ |
| 102 | }; |
| 103 | |
Linus Walleij | 5f66d48 | 2013-01-06 02:25:20 +0100 | [diff] [blame^] | 104 | static void __init cpu8815_map_io(void) |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 105 | { |
| 106 | iotable_init(nomadik_io_desc, ARRAY_SIZE(nomadik_io_desc)); |
| 107 | } |
| 108 | |
Linus Walleij | 5f66d48 | 2013-01-06 02:25:20 +0100 | [diff] [blame^] | 109 | static void cpu8815_restart(char mode, const char *cmd) |
Russell King | 35b47a405 | 2011-11-28 10:48:02 +0000 | [diff] [blame] | 110 | { |
| 111 | void __iomem *src_rstsr = io_p2v(NOMADIK_SRC_BASE + 0x18); |
| 112 | |
| 113 | /* FIXME: use egpio when implemented */ |
| 114 | |
| 115 | /* Write anything to Reset status register */ |
| 116 | writel(1, src_rstsr); |
| 117 | } |
Linus Walleij | f8635ab | 2013-01-05 00:29:31 +0100 | [diff] [blame] | 118 | |
Linus Walleij | f8635ab | 2013-01-05 00:29:31 +0100 | [diff] [blame] | 119 | /* Initial value for SRC control register: all timers use MXTAL/8 source */ |
| 120 | #define SRC_CR_INIT_MASK 0x00007fff |
| 121 | #define SRC_CR_INIT_VAL 0x2aaa8000 |
| 122 | |
| 123 | static void __init cpu8815_timer_init_of(void) |
| 124 | { |
| 125 | struct device_node *mtu; |
| 126 | void __iomem *base; |
| 127 | int irq; |
| 128 | u32 src_cr; |
| 129 | |
| 130 | /* We need this to be up now */ |
| 131 | nomadik_clk_init(); |
| 132 | |
| 133 | mtu = of_find_node_by_path("/mtu0"); |
| 134 | if (!mtu) |
| 135 | return; |
| 136 | base = of_iomap(mtu, 0); |
| 137 | if (WARN_ON(!base)) |
| 138 | return; |
| 139 | irq = irq_of_parse_and_map(mtu, 0); |
| 140 | |
| 141 | pr_info("Remapped MTU @ %p, irq: %d\n", base, irq); |
| 142 | |
| 143 | /* Configure timer sources in "system reset controller" ctrl reg */ |
| 144 | src_cr = readl(base); |
| 145 | src_cr &= SRC_CR_INIT_MASK; |
| 146 | src_cr |= SRC_CR_INIT_VAL; |
| 147 | writel(src_cr, base); |
| 148 | |
| 149 | nmdk_timer_init(base, irq); |
| 150 | } |
| 151 | |
Linus Walleij | ba78520 | 2013-01-05 22:28:32 +0100 | [diff] [blame] | 152 | static struct fsmc_nand_timings cpu8815_nand_timings = { |
| 153 | .thiz = 0, |
| 154 | .thold = 0x10, |
| 155 | .twait = 0x0A, |
| 156 | .tset = 0, |
| 157 | }; |
| 158 | |
| 159 | static struct fsmc_nand_platform_data cpu8815_nand_data = { |
| 160 | .nand_timings = &cpu8815_nand_timings, |
| 161 | }; |
| 162 | |
Linus Walleij | 2ad6e39 | 2013-01-06 01:02:42 +0100 | [diff] [blame] | 163 | /* |
| 164 | * The SMSC911x IRQ is connected to a GPIO pin, but the driver expects |
| 165 | * to simply request an IRQ passed as a resource. So the GPIO pin needs |
| 166 | * to be requested by this hog and set as input. |
| 167 | */ |
| 168 | static int __init cpu8815_eth_init(void) |
| 169 | { |
| 170 | struct device_node *eth; |
| 171 | int gpio, irq, err; |
| 172 | |
| 173 | eth = of_find_node_by_path("/usb-s8815/ethernet-gpio"); |
| 174 | if (!eth) { |
| 175 | pr_info("could not find any ethernet GPIO\n"); |
| 176 | return 0; |
| 177 | } |
| 178 | gpio = of_get_gpio(eth, 0); |
| 179 | err = gpio_request(gpio, "eth_irq"); |
| 180 | if (err) { |
| 181 | pr_info("failed to request ethernet GPIO\n"); |
| 182 | return -ENODEV; |
| 183 | } |
| 184 | err = gpio_direction_input(gpio); |
| 185 | if (err) { |
| 186 | pr_info("failed to set ethernet GPIO as input\n"); |
| 187 | return -ENODEV; |
| 188 | } |
| 189 | irq = gpio_to_irq(gpio); |
| 190 | pr_info("enabled USB-S8815 ethernet GPIO %d, IRQ %d\n", gpio, irq); |
| 191 | return 0; |
| 192 | } |
| 193 | device_initcall(cpu8815_eth_init); |
| 194 | |
Linus Walleij | 4fd243c | 2013-01-06 01:47:29 +0100 | [diff] [blame] | 195 | /* |
| 196 | * TODO: |
| 197 | * cannot be set from device tree, convert to a proper DT |
| 198 | * binding. |
| 199 | */ |
| 200 | static struct mmci_platform_data mmcsd_plat_data = { |
| 201 | .ocr_mask = MMC_VDD_29_30, |
| 202 | }; |
| 203 | |
| 204 | /* |
| 205 | * This GPIO pin turns on a line that is used to detect card insertion |
| 206 | * on this board. |
| 207 | */ |
| 208 | static int __init cpu8815_mmcsd_init(void) |
| 209 | { |
| 210 | struct device_node *cdbias; |
| 211 | int gpio, err; |
| 212 | |
| 213 | cdbias = of_find_node_by_path("/usb-s8815/mmcsd-gpio"); |
| 214 | if (!cdbias) { |
| 215 | pr_info("could not find MMC/SD card detect bias node\n"); |
| 216 | return 0; |
| 217 | } |
| 218 | gpio = of_get_gpio(cdbias, 0); |
| 219 | if (gpio < 0) { |
| 220 | pr_info("could not obtain MMC/SD card detect bias GPIO\n"); |
| 221 | return 0; |
| 222 | } |
| 223 | err = gpio_request(gpio, "card detect bias"); |
| 224 | if (err) { |
| 225 | pr_info("failed to request card detect bias GPIO %d\n", gpio); |
| 226 | return -ENODEV; |
| 227 | } |
| 228 | err = gpio_direction_output(gpio, 0); |
| 229 | if (err){ |
| 230 | pr_info("failed to set GPIO %d as output, low\n", gpio); |
| 231 | return err; |
| 232 | } |
| 233 | pr_info("enabled USB-S8815 CD bias GPIO %d, low\n", gpio); |
| 234 | return 0; |
| 235 | } |
| 236 | device_initcall(cpu8815_mmcsd_init); |
| 237 | |
| 238 | |
Linus Walleij | f8635ab | 2013-01-05 00:29:31 +0100 | [diff] [blame] | 239 | /* These are mostly to get the right device names for the clock lookups */ |
| 240 | static struct of_dev_auxdata cpu8815_auxdata_lookup[] __initdata = { |
Linus Walleij | 6010d40 | 2013-01-05 23:10:09 +0100 | [diff] [blame] | 241 | OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO0_BASE, |
| 242 | "gpio.0", NULL), |
| 243 | OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO1_BASE, |
| 244 | "gpio.1", NULL), |
| 245 | OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO2_BASE, |
| 246 | "gpio.2", NULL), |
| 247 | OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO3_BASE, |
| 248 | "gpio.3", NULL), |
| 249 | OF_DEV_AUXDATA("stericsson,nmk-pinctrl-stn8815", 0, |
| 250 | "pinctrl-stn8815", NULL), |
Linus Walleij | f8635ab | 2013-01-05 00:29:31 +0100 | [diff] [blame] | 251 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART0_BASE, |
| 252 | "uart0", NULL), |
| 253 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART1_BASE, |
| 254 | "uart1", NULL), |
Linus Walleij | 27bda03 | 2013-01-05 10:38:57 +0100 | [diff] [blame] | 255 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_RNG_BASE, |
| 256 | "rng", NULL), |
| 257 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_RTC_BASE, |
| 258 | "rtc-pl031", NULL), |
Linus Walleij | ba78520 | 2013-01-05 22:28:32 +0100 | [diff] [blame] | 259 | OF_DEV_AUXDATA("stericsson,fsmc-nand", NOMADIK_FSMC_BASE, |
| 260 | "fsmc-nand", &cpu8815_nand_data), |
Linus Walleij | 4fd243c | 2013-01-06 01:47:29 +0100 | [diff] [blame] | 261 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_SDI_BASE, |
| 262 | "mmci", &mmcsd_plat_data), |
Linus Walleij | f8635ab | 2013-01-05 00:29:31 +0100 | [diff] [blame] | 263 | { /* sentinel */ }, |
| 264 | }; |
| 265 | |
| 266 | static void __init cpu8815_init_of(void) |
| 267 | { |
| 268 | #ifdef CONFIG_CACHE_L2X0 |
| 269 | /* At full speed latency must be >=2, so 0x249 in low bits */ |
| 270 | l2x0_of_init(0x00730249, 0xfe000fff); |
| 271 | #endif |
Linus Walleij | 6010d40 | 2013-01-05 23:10:09 +0100 | [diff] [blame] | 272 | pinctrl_register_mappings(nhk8815_pinmap, ARRAY_SIZE(nhk8815_pinmap)); |
Linus Walleij | f8635ab | 2013-01-05 00:29:31 +0100 | [diff] [blame] | 273 | of_platform_populate(NULL, of_default_bus_match_table, |
| 274 | cpu8815_auxdata_lookup, NULL); |
| 275 | } |
| 276 | |
| 277 | static const char * cpu8815_board_compat[] = { |
| 278 | "calaosystems,usb-s8815", |
| 279 | NULL, |
| 280 | }; |
| 281 | |
| 282 | DT_MACHINE_START(NOMADIK_DT, "Nomadik STn8815") |
| 283 | .map_io = cpu8815_map_io, |
| 284 | .init_irq = irqchip_init, |
| 285 | .init_time = cpu8815_timer_init_of, |
| 286 | .init_machine = cpu8815_init_of, |
| 287 | .restart = cpu8815_restart, |
| 288 | .dt_compat = cpu8815_board_compat, |
| 289 | MACHINE_END |