Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-nomadik/board-8815nhk.c |
| 3 | * |
| 4 | * Copyright (C) STMicroelectronics |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2, as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * NHK15 board specifc driver definition |
| 11 | */ |
| 12 | #include <linux/types.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/amba/bus.h> |
Alessandro Rubini | 725b1f9 | 2009-07-02 15:29:32 +0100 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/gpio.h> |
Alessandro Rubini | 6323471 | 2009-07-29 18:51:56 +0200 | [diff] [blame] | 19 | #include <linux/mtd/mtd.h> |
| 20 | #include <linux/mtd/nand.h> |
Alessandro Rubini | c1558b5 | 2009-09-20 23:28:24 +0200 | [diff] [blame^] | 21 | #include <linux/mtd/onenand.h> |
Alessandro Rubini | 6323471 | 2009-07-29 18:51:56 +0200 | [diff] [blame] | 22 | #include <linux/mtd/partitions.h> |
| 23 | #include <linux/io.h> |
| 24 | #include <asm/sizes.h> |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 25 | #include <asm/mach-types.h> |
| 26 | #include <asm/mach/arch.h> |
| 27 | #include <asm/mach/irq.h> |
Alessandro Rubini | 8b85e7c | 2009-07-24 13:30:04 +0200 | [diff] [blame] | 28 | #include <asm/mach/flash.h> |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 29 | #include <mach/setup.h> |
Alessandro Rubini | 6323471 | 2009-07-29 18:51:56 +0200 | [diff] [blame] | 30 | #include <mach/nand.h> |
| 31 | #include <mach/fsmc.h> |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 32 | #include "clock.h" |
| 33 | |
Alessandro Rubini | 6323471 | 2009-07-29 18:51:56 +0200 | [diff] [blame] | 34 | /* These adresses span 16MB, so use three individual pages */ |
| 35 | static struct resource nhk8815_nand_resources[] = { |
| 36 | { |
| 37 | .name = "nand_addr", |
| 38 | .start = NAND_IO_ADDR, |
| 39 | .end = NAND_IO_ADDR + 0xfff, |
| 40 | .flags = IORESOURCE_MEM, |
| 41 | }, { |
| 42 | .name = "nand_cmd", |
| 43 | .start = NAND_IO_CMD, |
| 44 | .end = NAND_IO_CMD + 0xfff, |
| 45 | .flags = IORESOURCE_MEM, |
| 46 | }, { |
| 47 | .name = "nand_data", |
| 48 | .start = NAND_IO_DATA, |
| 49 | .end = NAND_IO_DATA + 0xfff, |
| 50 | .flags = IORESOURCE_MEM, |
| 51 | } |
| 52 | }; |
| 53 | |
| 54 | static int nhk8815_nand_init(void) |
| 55 | { |
| 56 | /* FSMC setup for nand chip select (8-bit nand in 8815NHK) */ |
| 57 | writel(0x0000000E, FSMC_PCR(0)); |
| 58 | writel(0x000D0A00, FSMC_PMEM(0)); |
| 59 | writel(0x00100A00, FSMC_PATT(0)); |
| 60 | |
| 61 | /* enable access to the chip select area */ |
| 62 | writel(readl(FSMC_PCR(0)) | 0x04, FSMC_PCR(0)); |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | * These partitions are the same as those used in the 2.6.20 release |
| 69 | * shipped by the vendor; the first two partitions are mandated |
| 70 | * by the boot ROM, and the bootloader area is somehow oversized... |
| 71 | */ |
| 72 | static struct mtd_partition nhk8815_partitions[] = { |
| 73 | { |
| 74 | .name = "X-Loader(NAND)", |
| 75 | .offset = 0, |
| 76 | .size = SZ_256K, |
| 77 | }, { |
| 78 | .name = "MemInit(NAND)", |
| 79 | .offset = MTDPART_OFS_APPEND, |
| 80 | .size = SZ_256K, |
| 81 | }, { |
| 82 | .name = "BootLoader(NAND)", |
| 83 | .offset = MTDPART_OFS_APPEND, |
| 84 | .size = SZ_2M, |
| 85 | }, { |
| 86 | .name = "Kernel zImage(NAND)", |
| 87 | .offset = MTDPART_OFS_APPEND, |
| 88 | .size = 3 * SZ_1M, |
| 89 | }, { |
| 90 | .name = "Root Filesystem(NAND)", |
| 91 | .offset = MTDPART_OFS_APPEND, |
| 92 | .size = 22 * SZ_1M, |
| 93 | }, { |
| 94 | .name = "User Filesystem(NAND)", |
| 95 | .offset = MTDPART_OFS_APPEND, |
| 96 | .size = MTDPART_SIZ_FULL, |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | static struct nomadik_nand_platform_data nhk8815_nand_data = { |
| 101 | .parts = nhk8815_partitions, |
| 102 | .nparts = ARRAY_SIZE(nhk8815_partitions), |
| 103 | .options = NAND_COPYBACK | NAND_CACHEPRG | NAND_NO_PADDING \ |
| 104 | | NAND_NO_READRDY | NAND_NO_AUTOINCR, |
| 105 | .init = nhk8815_nand_init, |
| 106 | }; |
| 107 | |
| 108 | static struct platform_device nhk8815_nand_device = { |
| 109 | .name = "nomadik_nand", |
| 110 | .dev = { |
| 111 | .platform_data = &nhk8815_nand_data, |
| 112 | }, |
| 113 | .resource = nhk8815_nand_resources, |
| 114 | .num_resources = ARRAY_SIZE(nhk8815_nand_resources), |
| 115 | }; |
| 116 | |
Alessandro Rubini | 8b85e7c | 2009-07-24 13:30:04 +0200 | [diff] [blame] | 117 | /* These are the partitions for the OneNand device, different from above */ |
| 118 | static struct mtd_partition nhk8815_onenand_partitions[] = { |
| 119 | { |
| 120 | .name = "X-Loader(OneNAND)", |
| 121 | .offset = 0, |
| 122 | .size = SZ_256K, |
| 123 | }, { |
| 124 | .name = "MemInit(OneNAND)", |
| 125 | .offset = MTDPART_OFS_APPEND, |
| 126 | .size = SZ_256K, |
| 127 | }, { |
| 128 | .name = "BootLoader(OneNAND)", |
| 129 | .offset = MTDPART_OFS_APPEND, |
| 130 | .size = SZ_2M-SZ_256K, |
| 131 | }, { |
| 132 | .name = "SysImage(OneNAND)", |
| 133 | .offset = MTDPART_OFS_APPEND, |
| 134 | .size = 4 * SZ_1M, |
| 135 | }, { |
| 136 | .name = "Root Filesystem(OneNAND)", |
| 137 | .offset = MTDPART_OFS_APPEND, |
| 138 | .size = 22 * SZ_1M, |
| 139 | }, { |
| 140 | .name = "User Filesystem(OneNAND)", |
| 141 | .offset = MTDPART_OFS_APPEND, |
| 142 | .size = MTDPART_SIZ_FULL, |
| 143 | } |
| 144 | }; |
| 145 | |
Alessandro Rubini | c1558b5 | 2009-09-20 23:28:24 +0200 | [diff] [blame^] | 146 | static struct onenand_platform_data nhk8815_onenand_data = { |
Alessandro Rubini | 8b85e7c | 2009-07-24 13:30:04 +0200 | [diff] [blame] | 147 | .parts = nhk8815_onenand_partitions, |
| 148 | .nr_parts = ARRAY_SIZE(nhk8815_onenand_partitions), |
| 149 | }; |
| 150 | |
| 151 | static struct resource nhk8815_onenand_resource[] = { |
| 152 | { |
| 153 | .start = 0x30000000, |
| 154 | .end = 0x30000000 + SZ_128K - 1, |
| 155 | .flags = IORESOURCE_MEM, |
| 156 | }, |
| 157 | }; |
| 158 | |
| 159 | static struct platform_device nhk8815_onenand_device = { |
Alessandro Rubini | c1558b5 | 2009-09-20 23:28:24 +0200 | [diff] [blame^] | 160 | .name = "onenand-flash", |
Alessandro Rubini | 8b85e7c | 2009-07-24 13:30:04 +0200 | [diff] [blame] | 161 | .id = -1, |
| 162 | .dev = { |
| 163 | .platform_data = &nhk8815_onenand_data, |
| 164 | }, |
| 165 | .resource = nhk8815_onenand_resource, |
| 166 | .num_resources = ARRAY_SIZE(nhk8815_onenand_resource), |
| 167 | }; |
| 168 | |
| 169 | static void __init nhk8815_onenand_init(void) |
| 170 | { |
Alessandro Rubini | c1558b5 | 2009-09-20 23:28:24 +0200 | [diff] [blame^] | 171 | #ifdef CONFIG_MTD_ONENAND |
Alessandro Rubini | 8b85e7c | 2009-07-24 13:30:04 +0200 | [diff] [blame] | 172 | /* Set up SMCS0 for OneNand */ |
Alessandro Rubini | c1558b5 | 2009-09-20 23:28:24 +0200 | [diff] [blame^] | 173 | writel(0x000030db, FSMC_BCR(0)); |
| 174 | writel(0x02100551, FSMC_BTR(0)); |
Alessandro Rubini | 8b85e7c | 2009-07-24 13:30:04 +0200 | [diff] [blame] | 175 | #endif |
| 176 | } |
Alessandro Rubini | 6323471 | 2009-07-29 18:51:56 +0200 | [diff] [blame] | 177 | |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 178 | #define __MEM_4K_RESOURCE(x) \ |
| 179 | .res = {.start = (x), .end = (x) + SZ_4K - 1, .flags = IORESOURCE_MEM} |
| 180 | |
| 181 | static struct amba_device uart0_device = { |
| 182 | .dev = { .init_name = "uart0" }, |
| 183 | __MEM_4K_RESOURCE(NOMADIK_UART0_BASE), |
| 184 | .irq = {IRQ_UART0, NO_IRQ}, |
| 185 | }; |
| 186 | |
| 187 | static struct amba_device uart1_device = { |
| 188 | .dev = { .init_name = "uart1" }, |
| 189 | __MEM_4K_RESOURCE(NOMADIK_UART1_BASE), |
| 190 | .irq = {IRQ_UART1, NO_IRQ}, |
| 191 | }; |
| 192 | |
| 193 | static struct amba_device *amba_devs[] __initdata = { |
| 194 | &uart0_device, |
| 195 | &uart1_device, |
| 196 | }; |
| 197 | |
| 198 | /* We have a fixed clock alone, by now */ |
| 199 | static struct clk nhk8815_clk_48 = { |
| 200 | .rate = 48*1000*1000, |
| 201 | }; |
| 202 | |
Alessandro Rubini | 725b1f9 | 2009-07-02 15:29:32 +0100 | [diff] [blame] | 203 | static struct resource nhk8815_eth_resources[] = { |
| 204 | { |
| 205 | .name = "smc91x-regs", |
| 206 | .start = 0x34000000 + 0x300, |
| 207 | .end = 0x34000000 + SZ_64K - 1, |
| 208 | .flags = IORESOURCE_MEM, |
| 209 | }, { |
| 210 | .start = NOMADIK_GPIO_TO_IRQ(115), |
| 211 | .end = NOMADIK_GPIO_TO_IRQ(115), |
| 212 | .flags = IORESOURCE_IRQ | IRQF_TRIGGER_RISING, |
| 213 | } |
| 214 | }; |
| 215 | |
| 216 | static struct platform_device nhk8815_eth_device = { |
| 217 | .name = "smc91x", |
| 218 | .resource = nhk8815_eth_resources, |
| 219 | .num_resources = ARRAY_SIZE(nhk8815_eth_resources), |
| 220 | }; |
| 221 | |
| 222 | static int __init nhk8815_eth_init(void) |
| 223 | { |
| 224 | int gpio_nr = 115; /* hardwired in the board */ |
| 225 | int err; |
| 226 | |
| 227 | err = gpio_request(gpio_nr, "eth_irq"); |
| 228 | if (!err) err = nmk_gpio_set_mode(gpio_nr, NMK_GPIO_ALT_GPIO); |
| 229 | if (!err) err = gpio_direction_input(gpio_nr); |
| 230 | if (err) |
| 231 | pr_err("Error %i in %s\n", err, __func__); |
| 232 | return err; |
| 233 | } |
| 234 | device_initcall(nhk8815_eth_init); |
| 235 | |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 236 | static struct platform_device *nhk8815_platform_devices[] __initdata = { |
Alessandro Rubini | 6323471 | 2009-07-29 18:51:56 +0200 | [diff] [blame] | 237 | &nhk8815_nand_device, |
Alessandro Rubini | 8b85e7c | 2009-07-24 13:30:04 +0200 | [diff] [blame] | 238 | &nhk8815_onenand_device, |
Alessandro Rubini | 725b1f9 | 2009-07-02 15:29:32 +0100 | [diff] [blame] | 239 | &nhk8815_eth_device, |
| 240 | /* will add more devices */ |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 241 | }; |
| 242 | |
| 243 | static void __init nhk8815_platform_init(void) |
| 244 | { |
| 245 | int i; |
| 246 | |
| 247 | cpu8815_platform_init(); |
Alessandro Rubini | 8b85e7c | 2009-07-24 13:30:04 +0200 | [diff] [blame] | 248 | nhk8815_onenand_init(); |
Alessandro Rubini | 28ad94e | 2009-07-02 19:06:47 +0100 | [diff] [blame] | 249 | platform_add_devices(nhk8815_platform_devices, |
| 250 | ARRAY_SIZE(nhk8815_platform_devices)); |
| 251 | |
| 252 | for (i = 0; i < ARRAY_SIZE(amba_devs); i++) { |
| 253 | nmdk_clk_create(&nhk8815_clk_48, amba_devs[i]->dev.init_name); |
| 254 | amba_device_register(amba_devs[i], &iomem_resource); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | MACHINE_START(NOMADIK, "NHK8815") |
| 259 | /* Maintainer: ST MicroElectronics */ |
| 260 | .phys_io = NOMADIK_UART0_BASE, |
| 261 | .io_pg_offst = (IO_ADDRESS(NOMADIK_UART0_BASE) >> 18) & 0xfffc, |
| 262 | .boot_params = 0x100, |
| 263 | .map_io = cpu8815_map_io, |
| 264 | .init_irq = cpu8815_init_irq, |
| 265 | .timer = &nomadik_timer, |
| 266 | .init_machine = nhk8815_platform_init, |
| 267 | MACHINE_END |