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> |
| 34 | #include <linux/of_address.h> |
| 35 | #include <linux/of_platform.h> |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 36 | |
| 37 | #include <mach/hardware.h> |
| 38 | #include <mach/irqs.h> |
Linus Walleij | f8635ab | 2013-01-05 00:29:31 +0100 | [diff] [blame] | 39 | #include <asm/mach/arch.h> |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 40 | #include <asm/mach/map.h> |
Linus Walleij | f8635ab | 2013-01-05 00:29:31 +0100 | [diff] [blame] | 41 | #include <asm/mach/time.h> |
Linus Walleij | 27bda03 | 2013-01-05 10:38:57 +0100 | [diff] [blame^] | 42 | #include <asm/mach-types.h> |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 43 | |
Alessandro Rubini | 0b260fd | 2009-07-02 15:29:43 +0100 | [diff] [blame] | 44 | #include <asm/cacheflush.h> |
| 45 | #include <asm/hardware/cache-l2x0.h> |
| 46 | |
Linus Walleij | 61b3875 | 2011-11-28 12:20:53 +0100 | [diff] [blame] | 47 | #include "cpu-8815.h" |
Linus Walleij | ba327b1 | 2010-05-26 07:38:54 +0100 | [diff] [blame] | 48 | |
Linus Walleij | 056c78d | 2012-01-09 11:42:39 +0100 | [diff] [blame] | 49 | /* The 8815 has 4 GPIO blocks, let's register them immediately */ |
| 50 | static resource_size_t __initdata cpu8815_gpio_base[] = { |
| 51 | NOMADIK_GPIO0_BASE, |
| 52 | NOMADIK_GPIO1_BASE, |
| 53 | NOMADIK_GPIO2_BASE, |
| 54 | NOMADIK_GPIO3_BASE, |
| 55 | }; |
| 56 | |
| 57 | static struct platform_device * |
| 58 | cpu8815_add_gpio(int id, resource_size_t addr, int irq, |
| 59 | struct nmk_gpio_platform_data *pdata) |
| 60 | { |
| 61 | struct resource resources[] = { |
| 62 | { |
| 63 | .start = addr, |
| 64 | .end = addr + 127, |
| 65 | .flags = IORESOURCE_MEM, |
| 66 | }, |
| 67 | { |
| 68 | .start = irq, |
| 69 | .end = irq, |
| 70 | .flags = IORESOURCE_IRQ, |
| 71 | } |
| 72 | }; |
| 73 | |
| 74 | return platform_device_register_resndata(NULL, "gpio", id, |
| 75 | resources, ARRAY_SIZE(resources), |
| 76 | pdata, sizeof(*pdata)); |
| 77 | } |
| 78 | |
| 79 | void cpu8815_add_gpios(resource_size_t *base, int num, int irq, |
| 80 | struct nmk_gpio_platform_data *pdata) |
| 81 | { |
| 82 | int first = 0; |
| 83 | int i; |
| 84 | |
| 85 | for (i = 0; i < num; i++, first += 32, irq++) { |
| 86 | pdata->first_gpio = first; |
| 87 | pdata->first_irq = NOMADIK_GPIO_TO_IRQ(first); |
| 88 | pdata->num_gpio = 32; |
| 89 | |
| 90 | cpu8815_add_gpio(i, base[i], irq, pdata); |
| 91 | } |
| 92 | } |
| 93 | |
Linus Walleij | 1b54275 | 2013-01-05 01:00:59 +0100 | [diff] [blame] | 94 | static unsigned long out_low[] = { PIN_OUTPUT_LOW }; |
| 95 | static unsigned long out_high[] = { PIN_OUTPUT_HIGH }; |
| 96 | static unsigned long in_nopull[] = { PIN_INPUT_NOPULL }; |
| 97 | static unsigned long in_pullup[] = { PIN_INPUT_PULLUP }; |
| 98 | |
| 99 | static struct pinctrl_map __initdata nhk8815_pinmap[] = { |
| 100 | PIN_MAP_MUX_GROUP_DEFAULT("uart0", "pinctrl-stn8815", "u0_a_1", "u0"), |
| 101 | PIN_MAP_MUX_GROUP_DEFAULT("uart1", "pinctrl-stn8815", "u1_a_1", "u1"), |
| 102 | /* Hog in MMC/SD card mux */ |
| 103 | PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-stn8815", "mmcsd_a_1", "mmcsd"), |
| 104 | /* MCCLK */ |
| 105 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO8_B10", out_low), |
| 106 | /* MCCMD */ |
| 107 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO9_A10", in_pullup), |
| 108 | /* MCCMDDIR */ |
| 109 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO10_C11", out_high), |
| 110 | /* MCDAT3-0 */ |
| 111 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO11_B11", in_pullup), |
| 112 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO12_A11", in_pullup), |
| 113 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO13_C12", in_pullup), |
| 114 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO14_B12", in_pullup), |
| 115 | /* MCDAT0DIR */ |
| 116 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO15_A12", out_high), |
| 117 | /* MCDAT31DIR */ |
| 118 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO16_C13", out_high), |
| 119 | /* MCMSFBCLK */ |
| 120 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO24_C15", in_pullup), |
| 121 | /* CD input GPIO */ |
| 122 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO111_H21", in_nopull), |
| 123 | /* CD bias drive */ |
| 124 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO112_J21", out_low), |
| 125 | /* I2C0 */ |
| 126 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO62_D3", in_pullup), |
| 127 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO63_D2", in_pullup), |
| 128 | /* I2C1 */ |
| 129 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO53_L4", in_pullup), |
| 130 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO54_L3", in_pullup), |
| 131 | /* I2C2 */ |
| 132 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO73_C21", in_pullup), |
| 133 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO74_C20", in_pullup), |
| 134 | }; |
| 135 | |
Linus Walleij | 2601ccf | 2012-08-10 00:43:40 +0200 | [diff] [blame] | 136 | static inline void |
| 137 | cpu8815_add_pinctrl(struct device *parent, const char *name) |
| 138 | { |
| 139 | struct platform_device_info pdevinfo = { |
| 140 | .parent = parent, |
| 141 | .name = name, |
| 142 | .id = -1, |
| 143 | }; |
| 144 | |
Linus Walleij | 1b54275 | 2013-01-05 01:00:59 +0100 | [diff] [blame] | 145 | pinctrl_register_mappings(nhk8815_pinmap, ARRAY_SIZE(nhk8815_pinmap)); |
Linus Walleij | 2601ccf | 2012-08-10 00:43:40 +0200 | [diff] [blame] | 146 | platform_device_register_full(&pdevinfo); |
| 147 | } |
| 148 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 149 | static int __init cpu8815_init(void) |
| 150 | { |
Linus Walleij | 056c78d | 2012-01-09 11:42:39 +0100 | [diff] [blame] | 151 | struct nmk_gpio_platform_data pdata = { |
| 152 | /* No custom data yet */ |
| 153 | }; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 154 | |
Linus Walleij | 056c78d | 2012-01-09 11:42:39 +0100 | [diff] [blame] | 155 | cpu8815_add_gpios(cpu8815_gpio_base, ARRAY_SIZE(cpu8815_gpio_base), |
| 156 | IRQ_GPIO0, &pdata); |
Linus Walleij | 2601ccf | 2012-08-10 00:43:40 +0200 | [diff] [blame] | 157 | cpu8815_add_pinctrl(NULL, "pinctrl-stn8815"); |
Linus Walleij | 27bda03 | 2013-01-05 10:38:57 +0100 | [diff] [blame^] | 158 | if (machine_is_nomadik()) { |
| 159 | amba_apb_device_add(NULL, "rng", NOMADIK_RNG_BASE, SZ_4K, 0, 0, NULL, 0); |
| 160 | amba_apb_device_add(NULL, "rtc-pl031", NOMADIK_RTC_BASE, SZ_4K, IRQ_RTC_RTT, 0, NULL, 0); |
| 161 | } |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 162 | return 0; |
| 163 | } |
| 164 | arch_initcall(cpu8815_init); |
| 165 | |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 166 | /* All SoC devices live in the same area (see hardware.h) */ |
| 167 | static struct map_desc nomadik_io_desc[] __initdata = { |
| 168 | { |
| 169 | .virtual = NOMADIK_IO_VIRTUAL, |
| 170 | .pfn = __phys_to_pfn(NOMADIK_IO_PHYSICAL), |
| 171 | .length = NOMADIK_IO_SIZE, |
| 172 | .type = MT_DEVICE, |
| 173 | } |
| 174 | /* static ram and secured ram may be added later */ |
| 175 | }; |
| 176 | |
| 177 | void __init cpu8815_map_io(void) |
| 178 | { |
| 179 | iotable_init(nomadik_io_desc, ARRAY_SIZE(nomadik_io_desc)); |
| 180 | } |
| 181 | |
| 182 | void __init cpu8815_init_irq(void) |
| 183 | { |
| 184 | /* This modified VIC cell has two register blocks, at 0 and 0x20 */ |
| 185 | vic_init(io_p2v(NOMADIK_IC_BASE + 0x00), IRQ_VIC_START + 0, ~0, 0); |
| 186 | vic_init(io_p2v(NOMADIK_IC_BASE + 0x20), IRQ_VIC_START + 32, ~0, 0); |
Linus Walleij | ba327b1 | 2010-05-26 07:38:54 +0100 | [diff] [blame] | 187 | |
| 188 | /* |
| 189 | * Init clocks here so that they are available for system timer |
| 190 | * initialization. |
| 191 | */ |
Linus Walleij | 4a31bd2 | 2012-01-11 13:52:34 +0100 | [diff] [blame] | 192 | nomadik_clk_init(); |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /* |
| 196 | * This function is called from the board init ("init_machine"). |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 197 | */ |
| 198 | void __init cpu8815_platform_init(void) |
| 199 | { |
Alessandro Rubini | 0b260fd | 2009-07-02 15:29:43 +0100 | [diff] [blame] | 200 | #ifdef CONFIG_CACHE_L2X0 |
| 201 | /* At full speed latency must be >=2, so 0x249 in low bits */ |
| 202 | l2x0_init(io_p2v(NOMADIK_L2CC_BASE), 0x00730249, 0xfe000fff); |
| 203 | #endif |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 204 | return; |
| 205 | } |
Russell King | 35b47a405 | 2011-11-28 10:48:02 +0000 | [diff] [blame] | 206 | |
| 207 | void cpu8815_restart(char mode, const char *cmd) |
| 208 | { |
| 209 | void __iomem *src_rstsr = io_p2v(NOMADIK_SRC_BASE + 0x18); |
| 210 | |
| 211 | /* FIXME: use egpio when implemented */ |
| 212 | |
| 213 | /* Write anything to Reset status register */ |
| 214 | writel(1, src_rstsr); |
| 215 | } |
Linus Walleij | f8635ab | 2013-01-05 00:29:31 +0100 | [diff] [blame] | 216 | |
| 217 | #ifdef CONFIG_OF |
| 218 | |
| 219 | /* Initial value for SRC control register: all timers use MXTAL/8 source */ |
| 220 | #define SRC_CR_INIT_MASK 0x00007fff |
| 221 | #define SRC_CR_INIT_VAL 0x2aaa8000 |
| 222 | |
| 223 | static void __init cpu8815_timer_init_of(void) |
| 224 | { |
| 225 | struct device_node *mtu; |
| 226 | void __iomem *base; |
| 227 | int irq; |
| 228 | u32 src_cr; |
| 229 | |
| 230 | /* We need this to be up now */ |
| 231 | nomadik_clk_init(); |
| 232 | |
| 233 | mtu = of_find_node_by_path("/mtu0"); |
| 234 | if (!mtu) |
| 235 | return; |
| 236 | base = of_iomap(mtu, 0); |
| 237 | if (WARN_ON(!base)) |
| 238 | return; |
| 239 | irq = irq_of_parse_and_map(mtu, 0); |
| 240 | |
| 241 | pr_info("Remapped MTU @ %p, irq: %d\n", base, irq); |
| 242 | |
| 243 | /* Configure timer sources in "system reset controller" ctrl reg */ |
| 244 | src_cr = readl(base); |
| 245 | src_cr &= SRC_CR_INIT_MASK; |
| 246 | src_cr |= SRC_CR_INIT_VAL; |
| 247 | writel(src_cr, base); |
| 248 | |
| 249 | nmdk_timer_init(base, irq); |
| 250 | } |
| 251 | |
| 252 | /* These are mostly to get the right device names for the clock lookups */ |
| 253 | static struct of_dev_auxdata cpu8815_auxdata_lookup[] __initdata = { |
| 254 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART0_BASE, |
| 255 | "uart0", NULL), |
| 256 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART1_BASE, |
| 257 | "uart1", NULL), |
Linus Walleij | 27bda03 | 2013-01-05 10:38:57 +0100 | [diff] [blame^] | 258 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_RNG_BASE, |
| 259 | "rng", NULL), |
| 260 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_RTC_BASE, |
| 261 | "rtc-pl031", NULL), |
Linus Walleij | f8635ab | 2013-01-05 00:29:31 +0100 | [diff] [blame] | 262 | { /* sentinel */ }, |
| 263 | }; |
| 264 | |
| 265 | static void __init cpu8815_init_of(void) |
| 266 | { |
| 267 | #ifdef CONFIG_CACHE_L2X0 |
| 268 | /* At full speed latency must be >=2, so 0x249 in low bits */ |
| 269 | l2x0_of_init(0x00730249, 0xfe000fff); |
| 270 | #endif |
| 271 | of_platform_populate(NULL, of_default_bus_match_table, |
| 272 | cpu8815_auxdata_lookup, NULL); |
| 273 | } |
| 274 | |
| 275 | static const char * cpu8815_board_compat[] = { |
| 276 | "calaosystems,usb-s8815", |
| 277 | NULL, |
| 278 | }; |
| 279 | |
| 280 | DT_MACHINE_START(NOMADIK_DT, "Nomadik STn8815") |
| 281 | .map_io = cpu8815_map_io, |
| 282 | .init_irq = irqchip_init, |
| 283 | .init_time = cpu8815_timer_init_of, |
| 284 | .init_machine = cpu8815_init_of, |
| 285 | .restart = cpu8815_restart, |
| 286 | .dt_compat = cpu8815_board_compat, |
| 287 | MACHINE_END |
| 288 | |
| 289 | #endif |