2 * Koelsch board support
4 * Copyright (C) 2013 Renesas Electronics Corporation
5 * Copyright (C) 2013-2014 Renesas Solutions Corp.
6 * Copyright (C) 2013 Magnus Damm
7 * Copyright (C) 2014 Cogent Embedded, Inc.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <linux/dma-mapping.h>
24 #include <linux/gpio.h>
25 #include <linux/gpio_keys.h>
26 #include <linux/input.h>
27 #include <linux/irq.h>
28 #include <linux/kernel.h>
29 #include <linux/leds.h>
30 #include <linux/mfd/tmio.h>
31 #include <linux/mmc/host.h>
32 #include <linux/mmc/sh_mobile_sdhi.h>
33 #include <linux/mtd/mtd.h>
34 #include <linux/mtd/partitions.h>
35 #include <linux/phy.h>
36 #include <linux/pinctrl/machine.h>
37 #include <linux/platform_data/gpio-rcar.h>
38 #include <linux/platform_data/rcar-du.h>
39 #include <linux/platform_device.h>
40 #include <linux/regulator/driver.h>
41 #include <linux/regulator/fixed.h>
42 #include <linux/regulator/gpio-regulator.h>
43 #include <linux/regulator/machine.h>
44 #include <linux/sh_eth.h>
45 #include <linux/spi/flash.h>
46 #include <linux/spi/rspi.h>
47 #include <linux/spi/spi.h>
48 #include <mach/common.h>
49 #include <mach/irqs.h>
50 #include <mach/r8a7791.h>
51 #include <mach/rcar-gen2.h>
52 #include <asm/mach-types.h>
53 #include <asm/mach/arch.h>
56 static struct rcar_du_encoder_data koelsch_du_encoders[] = {
58 .type = RCAR_DU_ENCODER_NONE,
59 .output = RCAR_DU_OUTPUT_LVDS0,
60 .connector.lvds.panel = {
79 static const struct rcar_du_platform_data koelsch_du_pdata __initconst = {
80 .encoders = koelsch_du_encoders,
81 .num_encoders = ARRAY_SIZE(koelsch_du_encoders),
84 static const struct resource du_resources[] __initconst = {
85 DEFINE_RES_MEM(0xfeb00000, 0x40000),
86 DEFINE_RES_MEM_NAMED(0xfeb90000, 0x1c, "lvds.0"),
87 DEFINE_RES_IRQ(gic_spi(256)),
88 DEFINE_RES_IRQ(gic_spi(268)),
91 static void __init koelsch_add_du_device(void)
93 struct platform_device_info info = {
94 .name = "rcar-du-r8a7791",
97 .num_res = ARRAY_SIZE(du_resources),
98 .data = &koelsch_du_pdata,
99 .size_data = sizeof(koelsch_du_pdata),
100 .dma_mask = DMA_BIT_MASK(32),
103 platform_device_register_full(&info);
107 static const struct sh_eth_plat_data ether_pdata __initconst = {
109 .phy_irq = irq_pin(0),
110 .edmac_endian = EDMAC_LITTLE_ENDIAN,
111 .phy_interface = PHY_INTERFACE_MODE_RMII,
112 .ether_link_active_low = 1,
115 static const struct resource ether_resources[] __initconst = {
116 DEFINE_RES_MEM(0xee700000, 0x400),
117 DEFINE_RES_IRQ(gic_spi(162)),
120 static const struct platform_device_info ether_info __initconst = {
121 .parent = &platform_bus,
122 .name = "r8a7791-ether",
124 .res = ether_resources,
125 .num_res = ARRAY_SIZE(ether_resources),
126 .data = ðer_pdata,
127 .size_data = sizeof(ether_pdata),
128 .dma_mask = DMA_BIT_MASK(32),
132 static struct gpio_led koelsch_leds[] = {
135 .gpio = RCAR_GP_PIN(2, 21),
136 .default_state = LEDS_GPIO_DEFSTATE_ON,
139 .gpio = RCAR_GP_PIN(2, 20),
140 .default_state = LEDS_GPIO_DEFSTATE_ON,
143 .gpio = RCAR_GP_PIN(2, 19),
144 .default_state = LEDS_GPIO_DEFSTATE_ON,
148 static const struct gpio_led_platform_data koelsch_leds_pdata __initconst = {
149 .leds = koelsch_leds,
150 .num_leds = ARRAY_SIZE(koelsch_leds),
154 #define GPIO_KEY(c, g, d, ...) \
155 { .code = c, .gpio = g, .desc = d, .active_low = 1, \
156 .wakeup = 1, .debounce_interval = 20 }
158 static struct gpio_keys_button gpio_buttons[] = {
159 GPIO_KEY(KEY_4, RCAR_GP_PIN(5, 3), "SW2-pin4"),
160 GPIO_KEY(KEY_3, RCAR_GP_PIN(5, 2), "SW2-pin3"),
161 GPIO_KEY(KEY_2, RCAR_GP_PIN(5, 1), "SW2-pin2"),
162 GPIO_KEY(KEY_1, RCAR_GP_PIN(5, 0), "SW2-pin1"),
163 GPIO_KEY(KEY_G, RCAR_GP_PIN(7, 6), "SW36"),
164 GPIO_KEY(KEY_F, RCAR_GP_PIN(7, 5), "SW35"),
165 GPIO_KEY(KEY_E, RCAR_GP_PIN(7, 4), "SW34"),
166 GPIO_KEY(KEY_D, RCAR_GP_PIN(7, 3), "SW33"),
167 GPIO_KEY(KEY_C, RCAR_GP_PIN(7, 2), "SW32"),
168 GPIO_KEY(KEY_B, RCAR_GP_PIN(7, 1), "SW31"),
169 GPIO_KEY(KEY_A, RCAR_GP_PIN(7, 0), "SW30"),
172 static const struct gpio_keys_platform_data koelsch_keys_pdata __initconst = {
173 .buttons = gpio_buttons,
174 .nbuttons = ARRAY_SIZE(gpio_buttons),
178 static const struct resource qspi_resources[] __initconst = {
179 DEFINE_RES_MEM(0xe6b10000, 0x1000),
180 DEFINE_RES_IRQ_NAMED(gic_spi(184), "mux"),
183 static const struct rspi_plat_data qspi_pdata __initconst = {
187 /* SPI Flash memory (Spansion S25FL512SAGMFIG11 64 MiB) */
188 static struct mtd_partition spi_flash_part[] = {
191 .offset = 0x00000000,
193 .mask_flags = MTD_WRITEABLE,
197 .offset = MTDPART_OFS_APPEND,
199 .mask_flags = MTD_WRITEABLE,
203 .offset = MTDPART_OFS_APPEND,
204 .size = MTDPART_SIZ_FULL,
208 static const struct flash_platform_data spi_flash_data = {
210 .parts = spi_flash_part,
211 .nr_parts = ARRAY_SIZE(spi_flash_part),
215 static const struct spi_board_info spi_info[] __initconst = {
217 .modalias = "m25p80",
218 .platform_data = &spi_flash_data,
220 .max_speed_hz = 30000000,
227 static const struct resource sata0_resources[] __initconst = {
228 DEFINE_RES_MEM(0xee300000, 0x2000),
229 DEFINE_RES_IRQ(gic_spi(105)),
232 static const struct platform_device_info sata0_info __initconst = {
233 .parent = &platform_bus,
234 .name = "sata-r8a7791",
236 .res = sata0_resources,
237 .num_res = ARRAY_SIZE(sata0_resources),
238 .dma_mask = DMA_BIT_MASK(32),
242 static const struct resource i2c_resources[] __initconst = {
244 DEFINE_RES_MEM(0xE6508000, 0x40),
245 DEFINE_RES_IRQ(gic_spi(287)),
247 DEFINE_RES_MEM(0xE6518000, 0x40),
248 DEFINE_RES_IRQ(gic_spi(288)),
250 DEFINE_RES_MEM(0xE6530000, 0x40),
251 DEFINE_RES_IRQ(gic_spi(286)),
253 DEFINE_RES_MEM(0xE6540000, 0x40),
254 DEFINE_RES_IRQ(gic_spi(290)),
256 DEFINE_RES_MEM(0xE6520000, 0x40),
257 DEFINE_RES_IRQ(gic_spi(19)),
259 DEFINE_RES_MEM(0xE6528000, 0x40),
260 DEFINE_RES_IRQ(gic_spi(20)),
263 static void __init koelsch_add_i2c(unsigned idx)
265 unsigned res_idx = idx * 2;
267 BUG_ON(res_idx >= ARRAY_SIZE(i2c_resources));
269 platform_device_register_simple("i2c-rcar_gen2", idx,
270 i2c_resources + res_idx, 2);
273 #define SDHI_REGULATOR(idx, vdd_pin, vccq_pin) \
274 static struct regulator_consumer_supply vcc_sdhi##idx##_consumer = \
275 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi." #idx); \
277 static struct regulator_init_data vcc_sdhi##idx##_init_data = { \
279 .valid_ops_mask = REGULATOR_CHANGE_STATUS, \
281 .consumer_supplies = &vcc_sdhi##idx##_consumer, \
282 .num_consumer_supplies = 1, \
285 static const struct fixed_voltage_config vcc_sdhi##idx##_info __initconst = {\
286 .supply_name = "SDHI" #idx "Vcc", \
287 .microvolts = 3300000, \
290 .init_data = &vcc_sdhi##idx##_init_data, \
293 static struct regulator_consumer_supply vccq_sdhi##idx##_consumer = \
294 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi." #idx); \
296 static struct regulator_init_data vccq_sdhi##idx##_init_data = { \
298 .input_uV = 3300000, \
301 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | \
302 REGULATOR_CHANGE_STATUS, \
304 .consumer_supplies = &vccq_sdhi##idx##_consumer, \
305 .num_consumer_supplies = 1, \
308 static struct gpio vccq_sdhi##idx##_gpio = \
309 { vccq_pin, GPIOF_OUT_INIT_HIGH, "vccq-sdhi" #idx }; \
311 static struct gpio_regulator_state vccq_sdhi##idx##_states[] = { \
312 { .value = 1800000, .gpios = 0 }, \
313 { .value = 3300000, .gpios = 1 }, \
316 static const struct gpio_regulator_config vccq_sdhi##idx##_info __initconst = {\
317 .supply_name = "vqmmc", \
318 .gpios = &vccq_sdhi##idx##_gpio, \
320 .states = vccq_sdhi##idx##_states, \
321 .nr_states = ARRAY_SIZE(vccq_sdhi##idx##_states), \
322 .type = REGULATOR_VOLTAGE, \
323 .init_data = &vccq_sdhi##idx##_init_data, \
326 SDHI_REGULATOR(0, RCAR_GP_PIN(7, 17), RCAR_GP_PIN(2, 12));
327 SDHI_REGULATOR(1, RCAR_GP_PIN(7, 18), RCAR_GP_PIN(2, 13));
328 SDHI_REGULATOR(2, RCAR_GP_PIN(7, 19), RCAR_GP_PIN(2, 26));
331 static struct sh_mobile_sdhi_info sdhi0_info __initdata = {
332 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
333 MMC_CAP_POWER_OFF_CARD,
334 .tmio_caps2 = MMC_CAP2_NO_MULTI_READ,
335 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
338 static struct resource sdhi0_resources[] __initdata = {
339 DEFINE_RES_MEM(0xee100000, 0x200),
340 DEFINE_RES_IRQ(gic_spi(165)),
344 static struct sh_mobile_sdhi_info sdhi1_info __initdata = {
345 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
346 MMC_CAP_POWER_OFF_CARD,
347 .tmio_caps2 = MMC_CAP2_NO_MULTI_READ,
348 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
351 static struct resource sdhi1_resources[] __initdata = {
352 DEFINE_RES_MEM(0xee140000, 0x100),
353 DEFINE_RES_IRQ(gic_spi(167)),
357 static struct sh_mobile_sdhi_info sdhi2_info __initdata = {
358 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
359 MMC_CAP_POWER_OFF_CARD,
360 .tmio_caps2 = MMC_CAP2_NO_MULTI_READ,
361 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT |
362 TMIO_MMC_WRPROTECT_DISABLE,
365 static struct resource sdhi2_resources[] __initdata = {
366 DEFINE_RES_MEM(0xee160000, 0x100),
367 DEFINE_RES_IRQ(gic_spi(168)),
370 static const struct pinctrl_map koelsch_pinctrl_map[] = {
372 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
374 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
376 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
377 "du_clk_out_0", "du"),
379 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
381 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
383 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
385 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
386 "intc_irq0", "intc"),
388 PIN_MAP_MUX_GROUP_DEFAULT("qspi.0", "pfc-r8a7791",
389 "qspi_ctrl", "qspi"),
390 PIN_MAP_MUX_GROUP_DEFAULT("qspi.0", "pfc-r8a7791",
391 "qspi_data4", "qspi"),
392 /* SCIF0 (CN19: DEBUG SERIAL0) */
393 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.6", "pfc-r8a7791",
394 "scif0_data_d", "scif0"),
395 /* SCIF1 (CN20: DEBUG SERIAL1) */
396 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.7", "pfc-r8a7791",
397 "scif1_data_d", "scif1"),
399 PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar_gen2.1", "pfc-r8a7791",
402 PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar_gen2.2", "pfc-r8a7791",
405 PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar_gen2.4", "pfc-r8a7791",
408 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7791",
409 "sdhi0_data4", "sdhi0"),
410 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7791",
411 "sdhi0_ctrl", "sdhi0"),
412 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7791",
413 "sdhi0_cd", "sdhi0"),
414 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7791",
415 "sdhi0_wp", "sdhi0"),
417 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-r8a7791",
418 "sdhi1_data4", "sdhi1"),
419 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-r8a7791",
420 "sdhi1_ctrl", "sdhi1"),
421 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-r8a7791",
422 "sdhi1_cd", "sdhi1"),
423 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-r8a7791",
424 "sdhi1_wp", "sdhi1"),
426 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-r8a7791",
427 "sdhi2_data4", "sdhi2"),
428 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-r8a7791",
429 "sdhi2_ctrl", "sdhi2"),
430 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-r8a7791",
431 "sdhi2_cd", "sdhi2"),
434 static void __init koelsch_add_standard_devices(void)
436 r8a7791_clock_init();
437 pinctrl_register_mappings(koelsch_pinctrl_map,
438 ARRAY_SIZE(koelsch_pinctrl_map));
439 r8a7791_pinmux_init();
440 r8a7791_add_standard_devices();
441 platform_device_register_full(ðer_info);
442 platform_device_register_data(&platform_bus, "leds-gpio", -1,
444 sizeof(koelsch_leds_pdata));
445 platform_device_register_data(&platform_bus, "gpio-keys", -1,
447 sizeof(koelsch_keys_pdata));
448 platform_device_register_resndata(&platform_bus, "qspi", 0,
450 ARRAY_SIZE(qspi_resources),
451 &qspi_pdata, sizeof(qspi_pdata));
452 spi_register_board_info(spi_info, ARRAY_SIZE(spi_info));
454 koelsch_add_du_device();
456 platform_device_register_full(&sata0_info);
463 platform_device_register_data(&platform_bus, "reg-fixed-voltage", 0,
464 &vcc_sdhi0_info, sizeof(struct fixed_voltage_config));
465 platform_device_register_data(&platform_bus, "reg-fixed-voltage", 1,
466 &vcc_sdhi1_info, sizeof(struct fixed_voltage_config));
467 platform_device_register_data(&platform_bus, "reg-fixed-voltage", 2,
468 &vcc_sdhi2_info, sizeof(struct fixed_voltage_config));
469 platform_device_register_data(&platform_bus, "gpio-regulator", 0,
470 &vccq_sdhi0_info, sizeof(struct gpio_regulator_config));
471 platform_device_register_data(&platform_bus, "gpio-regulator", 1,
472 &vccq_sdhi1_info, sizeof(struct gpio_regulator_config));
473 platform_device_register_data(&platform_bus, "gpio-regulator", 2,
474 &vccq_sdhi2_info, sizeof(struct gpio_regulator_config));
476 platform_device_register_resndata(&platform_bus, "sh_mobile_sdhi", 0,
477 sdhi0_resources, ARRAY_SIZE(sdhi0_resources),
478 &sdhi0_info, sizeof(struct sh_mobile_sdhi_info));
480 platform_device_register_resndata(&platform_bus, "sh_mobile_sdhi", 1,
481 sdhi1_resources, ARRAY_SIZE(sdhi1_resources),
482 &sdhi1_info, sizeof(struct sh_mobile_sdhi_info));
484 platform_device_register_resndata(&platform_bus, "sh_mobile_sdhi", 2,
485 sdhi2_resources, ARRAY_SIZE(sdhi2_resources),
486 &sdhi2_info, sizeof(struct sh_mobile_sdhi_info));
491 * Ether LEDs on the Koelsch board are named LINK and ACTIVE which corresponds
492 * to non-default 01 setting of the Micrel KSZ8041 PHY control register 1 bits
493 * 14-15. We have to set them back to 01 from the default 00 value each time
494 * the PHY is reset. It's also important because the PHY's LED0 signal is
495 * connected to SoC's ETH_LINK signal and in the PHY's default mode it will
496 * bounce on and off after each packet, which we apparently want to avoid.
498 static int koelsch_ksz8041_fixup(struct phy_device *phydev)
500 u16 phyctrl1 = phy_read(phydev, 0x1e);
504 return phy_write(phydev, 0x1e, phyctrl1);
507 static void __init koelsch_init(void)
509 koelsch_add_standard_devices();
511 irq_set_irq_type(irq_pin(0), IRQ_TYPE_LEVEL_LOW);
513 if (IS_ENABLED(CONFIG_PHYLIB))
514 phy_register_fixup_for_id("r8a7791-ether-ff:01",
515 koelsch_ksz8041_fixup);
518 static const char * const koelsch_boards_compat_dt[] __initconst = {
523 DT_MACHINE_START(KOELSCH_DT, "koelsch")
524 .smp = smp_ops(r8a7791_smp_ops),
525 .init_early = r8a7791_init_early,
526 .init_time = rcar_gen2_timer_init,
527 .init_machine = koelsch_init,
528 .init_late = shmobile_init_late,
529 .dt_compat = koelsch_boards_compat_dt,