Magnus Damm | f2aaf66 | 2010-02-05 11:15:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * G4EVM board support |
| 3 | * |
| 4 | * Copyright (C) 2010 Magnus Damm |
| 5 | * Copyright (C) 2008 Yoshihiro Shimoda |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/irq.h> |
| 24 | #include <linux/platform_device.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/mtd/mtd.h> |
| 27 | #include <linux/mtd/partitions.h> |
| 28 | #include <linux/mtd/physmap.h> |
NISHIMOTO Hiroki | aa18ef6 | 2010-02-12 08:11:18 +0000 | [diff] [blame] | 29 | #include <linux/usb/r8a66597.h> |
Magnus Damm | f2aaf66 | 2010-02-05 11:15:07 +0000 | [diff] [blame] | 30 | #include <linux/io.h> |
NISHIMOTO Hiroki | 6676a170 | 2010-02-23 10:55:10 +0000 | [diff] [blame] | 31 | #include <linux/input.h> |
| 32 | #include <linux/input/sh_keysc.h> |
Kuninori Morimoto | 819ee86 | 2010-03-29 06:31:36 +0000 | [diff] [blame^] | 33 | #include <linux/mfd/sh_mobile_sdhi.h> |
NISHIMOTO Hiroki | 276b4f6 | 2010-02-12 08:10:06 +0000 | [diff] [blame] | 34 | #include <linux/gpio.h> |
| 35 | #include <mach/sh7377.h> |
Magnus Damm | f2aaf66 | 2010-02-05 11:15:07 +0000 | [diff] [blame] | 36 | #include <mach/common.h> |
| 37 | #include <asm/mach-types.h> |
| 38 | #include <asm/mach/arch.h> |
| 39 | #include <asm/mach/map.h> |
| 40 | |
Kuninori Morimoto | 819ee86 | 2010-03-29 06:31:36 +0000 | [diff] [blame^] | 41 | /* |
| 42 | * SDHI |
| 43 | * |
| 44 | * SDHI0 : card detection is possible |
| 45 | * SDHI1 : card detection is impossible |
| 46 | * |
| 47 | * [G4-MAIN-BOARD] |
| 48 | * JP74 : short # DBG_2V8A for SDHI0 |
| 49 | * JP75 : NC # DBG_3V3A for SDHI0 |
| 50 | * JP76 : NC # DBG_3V3A_SD for SDHI0 |
| 51 | * JP77 : NC # 3V3A_SDIO for SDHI1 |
| 52 | * JP78 : short # DBG_2V8A for SDHI1 |
| 53 | * JP79 : NC # DBG_3V3A for SDHI1 |
| 54 | * JP80 : NC # DBG_3V3A_SD for SDHI1 |
| 55 | * |
| 56 | * [G4-CORE-BOARD] |
| 57 | * S32 : all off # to dissever from G3-CORE_DBG board |
| 58 | * S33 : all off # to dissever from G3-CORE_DBG board |
| 59 | * |
| 60 | * [G3-CORE_DBG-BOARD] |
| 61 | * S1 : all off # to dissever from G3-CORE_DBG board |
| 62 | * S3 : all off # to dissever from G3-CORE_DBG board |
| 63 | * S4 : all off # to dissever from G3-CORE_DBG board |
| 64 | */ |
| 65 | |
Magnus Damm | f2aaf66 | 2010-02-05 11:15:07 +0000 | [diff] [blame] | 66 | static struct mtd_partition nor_flash_partitions[] = { |
| 67 | { |
| 68 | .name = "loader", |
| 69 | .offset = 0x00000000, |
| 70 | .size = 512 * 1024, |
| 71 | }, |
| 72 | { |
| 73 | .name = "bootenv", |
| 74 | .offset = MTDPART_OFS_APPEND, |
| 75 | .size = 512 * 1024, |
| 76 | }, |
| 77 | { |
| 78 | .name = "kernel_ro", |
| 79 | .offset = MTDPART_OFS_APPEND, |
| 80 | .size = 8 * 1024 * 1024, |
| 81 | .mask_flags = MTD_WRITEABLE, |
| 82 | }, |
| 83 | { |
| 84 | .name = "kernel", |
| 85 | .offset = MTDPART_OFS_APPEND, |
| 86 | .size = 8 * 1024 * 1024, |
| 87 | }, |
| 88 | { |
| 89 | .name = "data", |
| 90 | .offset = MTDPART_OFS_APPEND, |
| 91 | .size = MTDPART_SIZ_FULL, |
| 92 | }, |
| 93 | }; |
| 94 | |
| 95 | static struct physmap_flash_data nor_flash_data = { |
| 96 | .width = 2, |
| 97 | .parts = nor_flash_partitions, |
| 98 | .nr_parts = ARRAY_SIZE(nor_flash_partitions), |
| 99 | }; |
| 100 | |
| 101 | static struct resource nor_flash_resources[] = { |
| 102 | [0] = { |
| 103 | .start = 0x00000000, |
| 104 | .end = 0x08000000 - 1, |
| 105 | .flags = IORESOURCE_MEM, |
| 106 | } |
| 107 | }; |
| 108 | |
| 109 | static struct platform_device nor_flash_device = { |
| 110 | .name = "physmap-flash", |
| 111 | .dev = { |
| 112 | .platform_data = &nor_flash_data, |
| 113 | }, |
| 114 | .num_resources = ARRAY_SIZE(nor_flash_resources), |
| 115 | .resource = nor_flash_resources, |
| 116 | }; |
| 117 | |
NISHIMOTO Hiroki | aa18ef6 | 2010-02-12 08:11:18 +0000 | [diff] [blame] | 118 | /* USBHS */ |
| 119 | void usb_host_port_power(int port, int power) |
| 120 | { |
| 121 | if (!power) /* only power-on supported for now */ |
| 122 | return; |
| 123 | |
| 124 | /* set VBOUT/PWEN and EXTLP0 in DVSTCTR */ |
| 125 | __raw_writew(__raw_readw(0xe6890008) | 0x600, 0xe6890008); |
| 126 | } |
| 127 | |
| 128 | static struct r8a66597_platdata usb_host_data = { |
| 129 | .on_chip = 1, |
| 130 | .port_power = usb_host_port_power, |
| 131 | }; |
| 132 | |
| 133 | static struct resource usb_host_resources[] = { |
| 134 | [0] = { |
| 135 | .name = "USBHS", |
| 136 | .start = 0xe6890000, |
| 137 | .end = 0xe68900e5, |
| 138 | .flags = IORESOURCE_MEM, |
| 139 | }, |
| 140 | [1] = { |
| 141 | .start = 65, |
| 142 | .end = 65, |
| 143 | .flags = IORESOURCE_IRQ, |
| 144 | }, |
| 145 | }; |
| 146 | |
| 147 | static struct platform_device usb_host_device = { |
| 148 | .name = "r8a66597_hcd", |
| 149 | .id = 0, |
| 150 | .dev = { |
| 151 | .platform_data = &usb_host_data, |
| 152 | .dma_mask = NULL, |
| 153 | .coherent_dma_mask = 0xffffffff, |
| 154 | }, |
| 155 | .num_resources = ARRAY_SIZE(usb_host_resources), |
| 156 | .resource = usb_host_resources, |
| 157 | }; |
Magnus Damm | f2aaf66 | 2010-02-05 11:15:07 +0000 | [diff] [blame] | 158 | |
NISHIMOTO Hiroki | 6676a170 | 2010-02-23 10:55:10 +0000 | [diff] [blame] | 159 | /* KEYSC */ |
| 160 | static struct sh_keysc_info keysc_info = { |
| 161 | .mode = SH_KEYSC_MODE_5, |
| 162 | .scan_timing = 3, |
| 163 | .delay = 100, |
| 164 | .keycodes = { |
| 165 | KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, |
| 166 | KEY_G, KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, |
| 167 | KEY_M, KEY_N, KEY_U, KEY_P, KEY_Q, KEY_R, |
| 168 | KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, KEY_X, |
| 169 | KEY_Y, KEY_Z, KEY_HOME, KEY_SLEEP, KEY_WAKEUP, KEY_COFFEE, |
| 170 | KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, |
| 171 | KEY_6, KEY_7, KEY_8, KEY_9, KEY_STOP, KEY_COMPUTER, |
| 172 | }, |
| 173 | }; |
| 174 | |
| 175 | static struct resource keysc_resources[] = { |
| 176 | [0] = { |
| 177 | .name = "KEYSC", |
| 178 | .start = 0xe61b0000, |
| 179 | .end = 0xe61b000f, |
| 180 | .flags = IORESOURCE_MEM, |
| 181 | }, |
| 182 | [1] = { |
| 183 | .start = 79, |
| 184 | .flags = IORESOURCE_IRQ, |
| 185 | }, |
| 186 | }; |
| 187 | |
| 188 | static struct platform_device keysc_device = { |
| 189 | .name = "sh_keysc", |
| 190 | .id = 0, /* keysc0 clock */ |
| 191 | .num_resources = ARRAY_SIZE(keysc_resources), |
| 192 | .resource = keysc_resources, |
| 193 | .dev = { |
| 194 | .platform_data = &keysc_info, |
| 195 | }, |
| 196 | }; |
| 197 | |
Kuninori Morimoto | 819ee86 | 2010-03-29 06:31:36 +0000 | [diff] [blame^] | 198 | /* SDHI */ |
| 199 | static struct resource sdhi0_resources[] = { |
| 200 | [0] = { |
| 201 | .name = "SDHI0", |
| 202 | .start = 0xe6d50000, |
| 203 | .end = 0xe6d501ff, |
| 204 | .flags = IORESOURCE_MEM, |
| 205 | }, |
| 206 | [1] = { |
| 207 | .start = 96, |
| 208 | .flags = IORESOURCE_IRQ, |
| 209 | }, |
| 210 | }; |
| 211 | |
| 212 | static struct platform_device sdhi0_device = { |
| 213 | .name = "sh_mobile_sdhi", |
| 214 | .num_resources = ARRAY_SIZE(sdhi0_resources), |
| 215 | .resource = sdhi0_resources, |
| 216 | .id = 0, |
| 217 | }; |
| 218 | |
| 219 | static struct resource sdhi1_resources[] = { |
| 220 | [0] = { |
| 221 | .name = "SDHI1", |
| 222 | .start = 0xe6d60000, |
| 223 | .end = 0xe6d601ff, |
| 224 | .flags = IORESOURCE_MEM, |
| 225 | }, |
| 226 | [1] = { |
| 227 | .start = 100, |
| 228 | .flags = IORESOURCE_IRQ, |
| 229 | }, |
| 230 | }; |
| 231 | |
| 232 | static struct platform_device sdhi1_device = { |
| 233 | .name = "sh_mobile_sdhi", |
| 234 | .num_resources = ARRAY_SIZE(sdhi1_resources), |
| 235 | .resource = sdhi1_resources, |
| 236 | .id = 1, |
| 237 | }; |
| 238 | |
Magnus Damm | f2aaf66 | 2010-02-05 11:15:07 +0000 | [diff] [blame] | 239 | static struct platform_device *g4evm_devices[] __initdata = { |
| 240 | &nor_flash_device, |
NISHIMOTO Hiroki | aa18ef6 | 2010-02-12 08:11:18 +0000 | [diff] [blame] | 241 | &usb_host_device, |
NISHIMOTO Hiroki | 6676a170 | 2010-02-23 10:55:10 +0000 | [diff] [blame] | 242 | &keysc_device, |
Kuninori Morimoto | 819ee86 | 2010-03-29 06:31:36 +0000 | [diff] [blame^] | 243 | &sdhi0_device, |
| 244 | &sdhi1_device, |
Magnus Damm | f2aaf66 | 2010-02-05 11:15:07 +0000 | [diff] [blame] | 245 | }; |
| 246 | |
| 247 | static struct map_desc g4evm_io_desc[] __initdata = { |
| 248 | /* create a 1:1 entity map for 0xe6xxxxxx |
| 249 | * used by CPGA, INTC and PFC. |
| 250 | */ |
| 251 | { |
| 252 | .virtual = 0xe6000000, |
| 253 | .pfn = __phys_to_pfn(0xe6000000), |
| 254 | .length = 256 << 20, |
| 255 | .type = MT_DEVICE_NONSHARED |
| 256 | }, |
| 257 | }; |
| 258 | |
| 259 | static void __init g4evm_map_io(void) |
| 260 | { |
| 261 | iotable_init(g4evm_io_desc, ARRAY_SIZE(g4evm_io_desc)); |
| 262 | |
Magnus Damm | 4ae04ac | 2010-02-08 11:02:54 +0000 | [diff] [blame] | 263 | /* setup early devices, clocks and console here as well */ |
Magnus Damm | f2aaf66 | 2010-02-05 11:15:07 +0000 | [diff] [blame] | 264 | sh7377_add_early_devices(); |
| 265 | sh7367_clock_init(); /* use g3 clocks for now */ |
Magnus Damm | 4ae04ac | 2010-02-08 11:02:54 +0000 | [diff] [blame] | 266 | shmobile_setup_console(); |
Magnus Damm | f2aaf66 | 2010-02-05 11:15:07 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Kuninori Morimoto | 819ee86 | 2010-03-29 06:31:36 +0000 | [diff] [blame^] | 269 | #define GPIO_SDHID0_D0 0xe60520fc |
| 270 | #define GPIO_SDHID0_D1 0xe60520fd |
| 271 | #define GPIO_SDHID0_D2 0xe60520fe |
| 272 | #define GPIO_SDHID0_D3 0xe60520ff |
| 273 | #define GPIO_SDHICMD0 0xe6052100 |
| 274 | |
| 275 | #define GPIO_SDHID1_D0 0xe6052103 |
| 276 | #define GPIO_SDHID1_D1 0xe6052104 |
| 277 | #define GPIO_SDHID1_D2 0xe6052105 |
| 278 | #define GPIO_SDHID1_D3 0xe6052106 |
| 279 | #define GPIO_SDHICMD1 0xe6052107 |
| 280 | |
| 281 | /* |
| 282 | * FIXME !! |
| 283 | * |
| 284 | * gpio_pull_up is quick_hack. |
| 285 | * |
| 286 | * current gpio frame work doesn't have |
| 287 | * the method to control only pull up/down/free. |
| 288 | * this function should be replaced by correct gpio function |
| 289 | */ |
| 290 | static void __init gpio_pull_up(u32 addr) |
| 291 | { |
| 292 | u8 data = __raw_readb(addr); |
| 293 | |
| 294 | data &= 0x0F; |
| 295 | data |= 0xC0; |
| 296 | __raw_writeb(data, addr); |
| 297 | } |
| 298 | |
Magnus Damm | f2aaf66 | 2010-02-05 11:15:07 +0000 | [diff] [blame] | 299 | static void __init g4evm_init(void) |
| 300 | { |
NISHIMOTO Hiroki | 276b4f6 | 2010-02-12 08:10:06 +0000 | [diff] [blame] | 301 | sh7377_pinmux_init(); |
| 302 | |
| 303 | /* Lit DS14 LED */ |
| 304 | gpio_request(GPIO_PORT109, NULL); |
| 305 | gpio_direction_output(GPIO_PORT109, 1); |
| 306 | gpio_export(GPIO_PORT109, 1); |
| 307 | |
| 308 | /* Lit DS15 LED */ |
| 309 | gpio_request(GPIO_PORT110, NULL); |
| 310 | gpio_direction_output(GPIO_PORT110, 1); |
| 311 | gpio_export(GPIO_PORT110, 1); |
| 312 | |
| 313 | /* Lit DS16 LED */ |
| 314 | gpio_request(GPIO_PORT112, NULL); |
| 315 | gpio_direction_output(GPIO_PORT112, 1); |
| 316 | gpio_export(GPIO_PORT112, 1); |
| 317 | |
| 318 | /* Lit DS17 LED */ |
| 319 | gpio_request(GPIO_PORT113, NULL); |
| 320 | gpio_direction_output(GPIO_PORT113, 1); |
| 321 | gpio_export(GPIO_PORT113, 1); |
| 322 | |
NISHIMOTO Hiroki | aa18ef6 | 2010-02-12 08:11:18 +0000 | [diff] [blame] | 323 | /* USBHS */ |
| 324 | gpio_request(GPIO_FN_VBUS_0, NULL); |
| 325 | gpio_request(GPIO_FN_PWEN, NULL); |
| 326 | gpio_request(GPIO_FN_OVCN, NULL); |
| 327 | gpio_request(GPIO_FN_OVCN2, NULL); |
| 328 | gpio_request(GPIO_FN_EXTLP, NULL); |
| 329 | gpio_request(GPIO_FN_IDIN, NULL); |
| 330 | |
| 331 | /* enable clock in SMSTPCR3 */ |
| 332 | __raw_writel(__raw_readl(0xe615013c) & ~(1 << 22), 0xe615013c); |
| 333 | |
| 334 | /* setup USB phy */ |
| 335 | __raw_writew(0x0200, 0xe605810a); /* USBCR1 */ |
| 336 | __raw_writew(0x00e0, 0xe60581c0); /* CPFCH */ |
| 337 | __raw_writew(0x6010, 0xe60581c6); /* CGPOSR */ |
| 338 | __raw_writew(0x8a0a, 0xe605810c); /* USBCR2 */ |
| 339 | |
NISHIMOTO Hiroki | 6676a170 | 2010-02-23 10:55:10 +0000 | [diff] [blame] | 340 | /* KEYSC @ CN31 */ |
| 341 | gpio_request(GPIO_FN_PORT60_KEYOUT5, NULL); |
| 342 | gpio_request(GPIO_FN_PORT61_KEYOUT4, NULL); |
| 343 | gpio_request(GPIO_FN_PORT62_KEYOUT3, NULL); |
| 344 | gpio_request(GPIO_FN_PORT63_KEYOUT2, NULL); |
| 345 | gpio_request(GPIO_FN_PORT64_KEYOUT1, NULL); |
| 346 | gpio_request(GPIO_FN_PORT65_KEYOUT0, NULL); |
| 347 | gpio_request(GPIO_FN_PORT66_KEYIN0_PU, NULL); |
| 348 | gpio_request(GPIO_FN_PORT67_KEYIN1_PU, NULL); |
| 349 | gpio_request(GPIO_FN_PORT68_KEYIN2_PU, NULL); |
| 350 | gpio_request(GPIO_FN_PORT69_KEYIN3_PU, NULL); |
| 351 | gpio_request(GPIO_FN_PORT70_KEYIN4_PU, NULL); |
| 352 | gpio_request(GPIO_FN_PORT71_KEYIN5_PU, NULL); |
| 353 | gpio_request(GPIO_FN_PORT72_KEYIN6_PU, NULL); |
| 354 | |
Kuninori Morimoto | 819ee86 | 2010-03-29 06:31:36 +0000 | [diff] [blame^] | 355 | /* SDHI0 */ |
| 356 | gpio_request(GPIO_FN_SDHICLK0, NULL); |
| 357 | gpio_request(GPIO_FN_SDHICD0, NULL); |
| 358 | gpio_request(GPIO_FN_SDHID0_0, NULL); |
| 359 | gpio_request(GPIO_FN_SDHID0_1, NULL); |
| 360 | gpio_request(GPIO_FN_SDHID0_2, NULL); |
| 361 | gpio_request(GPIO_FN_SDHID0_3, NULL); |
| 362 | gpio_request(GPIO_FN_SDHICMD0, NULL); |
| 363 | gpio_request(GPIO_FN_SDHIWP0, NULL); |
| 364 | gpio_pull_up(GPIO_SDHID0_D0); |
| 365 | gpio_pull_up(GPIO_SDHID0_D1); |
| 366 | gpio_pull_up(GPIO_SDHID0_D2); |
| 367 | gpio_pull_up(GPIO_SDHID0_D3); |
| 368 | gpio_pull_up(GPIO_SDHICMD0); |
| 369 | |
| 370 | /* SDHI1 */ |
| 371 | gpio_request(GPIO_FN_SDHICLK1, NULL); |
| 372 | gpio_request(GPIO_FN_SDHID1_0, NULL); |
| 373 | gpio_request(GPIO_FN_SDHID1_1, NULL); |
| 374 | gpio_request(GPIO_FN_SDHID1_2, NULL); |
| 375 | gpio_request(GPIO_FN_SDHID1_3, NULL); |
| 376 | gpio_request(GPIO_FN_SDHICMD1, NULL); |
| 377 | gpio_pull_up(GPIO_SDHID1_D0); |
| 378 | gpio_pull_up(GPIO_SDHID1_D1); |
| 379 | gpio_pull_up(GPIO_SDHID1_D2); |
| 380 | gpio_pull_up(GPIO_SDHID1_D3); |
| 381 | gpio_pull_up(GPIO_SDHICMD1); |
| 382 | |
Magnus Damm | f2aaf66 | 2010-02-05 11:15:07 +0000 | [diff] [blame] | 383 | sh7377_add_standard_devices(); |
| 384 | |
| 385 | platform_add_devices(g4evm_devices, ARRAY_SIZE(g4evm_devices)); |
| 386 | } |
| 387 | |
| 388 | MACHINE_START(G4EVM, "g4evm") |
| 389 | .phys_io = 0xe6000000, |
| 390 | .io_pg_offst = ((0xe6000000) >> 18) & 0xfffc, |
| 391 | .map_io = g4evm_map_io, |
| 392 | .init_irq = sh7377_init_irq, |
| 393 | .init_machine = g4evm_init, |
| 394 | .timer = &shmobile_timer, |
| 395 | MACHINE_END |