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.
19 #include <linux/dma-mapping.h>
20 #include <linux/gpio.h>
21 #include <linux/gpio_keys.h>
22 #include <linux/input.h>
23 #include <linux/irq.h>
24 #include <linux/kernel.h>
25 #include <linux/leds.h>
26 #include <linux/mfd/tmio.h>
27 #include <linux/mmc/host.h>
28 #include <linux/mmc/sh_mobile_sdhi.h>
29 #include <linux/mtd/mtd.h>
30 #include <linux/mtd/partitions.h>
31 #include <linux/phy.h>
32 #include <linux/pinctrl/machine.h>
33 #include <linux/platform_data/gpio-rcar.h>
34 #include <linux/platform_data/rcar-du.h>
35 #include <linux/platform_device.h>
36 #include <linux/regulator/driver.h>
37 #include <linux/regulator/fixed.h>
38 #include <linux/regulator/gpio-regulator.h>
39 #include <linux/regulator/machine.h>
40 #include <linux/sh_eth.h>
41 #include <linux/spi/flash.h>
42 #include <linux/spi/rspi.h>
43 #include <linux/spi/spi.h>
45 #include <asm/mach-types.h>
46 #include <asm/mach/arch.h>
51 #include "rcar-gen2.h"
54 static struct rcar_du_encoder_data koelsch_du_encoders[] = {
56 .type = RCAR_DU_ENCODER_NONE,
57 .output = RCAR_DU_OUTPUT_LVDS0,
58 .connector.lvds.panel = {
62 .pixelclock = 65000000,
76 static const struct rcar_du_platform_data koelsch_du_pdata __initconst = {
77 .encoders = koelsch_du_encoders,
78 .num_encoders = ARRAY_SIZE(koelsch_du_encoders),
81 static const struct resource du_resources[] __initconst = {
82 DEFINE_RES_MEM(0xfeb00000, 0x40000),
83 DEFINE_RES_MEM_NAMED(0xfeb90000, 0x1c, "lvds.0"),
84 DEFINE_RES_IRQ(gic_spi(256)),
85 DEFINE_RES_IRQ(gic_spi(268)),
88 static void __init koelsch_add_du_device(void)
90 struct platform_device_info info = {
91 .name = "rcar-du-r8a7791",
94 .num_res = ARRAY_SIZE(du_resources),
95 .data = &koelsch_du_pdata,
96 .size_data = sizeof(koelsch_du_pdata),
97 .dma_mask = DMA_BIT_MASK(32),
100 platform_device_register_full(&info);
104 static const struct sh_eth_plat_data ether_pdata __initconst = {
106 .phy_irq = irq_pin(0),
107 .edmac_endian = EDMAC_LITTLE_ENDIAN,
108 .phy_interface = PHY_INTERFACE_MODE_RMII,
109 .ether_link_active_low = 1,
112 static const struct resource ether_resources[] __initconst = {
113 DEFINE_RES_MEM(0xee700000, 0x400),
114 DEFINE_RES_IRQ(gic_spi(162)),
117 static const struct platform_device_info ether_info __initconst = {
118 .parent = &platform_bus,
119 .name = "r8a7791-ether",
121 .res = ether_resources,
122 .num_res = ARRAY_SIZE(ether_resources),
123 .data = ðer_pdata,
124 .size_data = sizeof(ether_pdata),
125 .dma_mask = DMA_BIT_MASK(32),
129 static struct gpio_led koelsch_leds[] = {
132 .gpio = RCAR_GP_PIN(2, 21),
133 .default_state = LEDS_GPIO_DEFSTATE_ON,
136 .gpio = RCAR_GP_PIN(2, 20),
137 .default_state = LEDS_GPIO_DEFSTATE_ON,
140 .gpio = RCAR_GP_PIN(2, 19),
141 .default_state = LEDS_GPIO_DEFSTATE_ON,
145 static const struct gpio_led_platform_data koelsch_leds_pdata __initconst = {
146 .leds = koelsch_leds,
147 .num_leds = ARRAY_SIZE(koelsch_leds),
151 #define GPIO_KEY(c, g, d, ...) \
152 { .code = c, .gpio = g, .desc = d, .active_low = 1, \
153 .wakeup = 1, .debounce_interval = 20 }
155 static struct gpio_keys_button gpio_buttons[] = {
156 GPIO_KEY(KEY_4, RCAR_GP_PIN(5, 3), "SW2-pin4"),
157 GPIO_KEY(KEY_3, RCAR_GP_PIN(5, 2), "SW2-pin3"),
158 GPIO_KEY(KEY_2, RCAR_GP_PIN(5, 1), "SW2-pin2"),
159 GPIO_KEY(KEY_1, RCAR_GP_PIN(5, 0), "SW2-pin1"),
160 GPIO_KEY(KEY_G, RCAR_GP_PIN(7, 6), "SW36"),
161 GPIO_KEY(KEY_F, RCAR_GP_PIN(7, 5), "SW35"),
162 GPIO_KEY(KEY_E, RCAR_GP_PIN(7, 4), "SW34"),
163 GPIO_KEY(KEY_D, RCAR_GP_PIN(7, 3), "SW33"),
164 GPIO_KEY(KEY_C, RCAR_GP_PIN(7, 2), "SW32"),
165 GPIO_KEY(KEY_B, RCAR_GP_PIN(7, 1), "SW31"),
166 GPIO_KEY(KEY_A, RCAR_GP_PIN(7, 0), "SW30"),
169 static const struct gpio_keys_platform_data koelsch_keys_pdata __initconst = {
170 .buttons = gpio_buttons,
171 .nbuttons = ARRAY_SIZE(gpio_buttons),
175 static const struct resource qspi_resources[] __initconst = {
176 DEFINE_RES_MEM(0xe6b10000, 0x1000),
177 DEFINE_RES_IRQ_NAMED(gic_spi(184), "mux"),
180 static const struct rspi_plat_data qspi_pdata __initconst = {
184 /* SPI Flash memory (Spansion S25FL512SAGMFIG11 64 MiB) */
185 static struct mtd_partition spi_flash_part[] = {
188 .offset = 0x00000000,
190 .mask_flags = MTD_WRITEABLE,
194 .offset = MTDPART_OFS_APPEND,
196 .mask_flags = MTD_WRITEABLE,
200 .offset = MTDPART_OFS_APPEND,
201 .size = MTDPART_SIZ_FULL,
205 static const struct flash_platform_data spi_flash_data = {
207 .parts = spi_flash_part,
208 .nr_parts = ARRAY_SIZE(spi_flash_part),
212 static const struct spi_board_info spi_info[] __initconst = {
214 .modalias = "m25p80",
215 .platform_data = &spi_flash_data,
216 .mode = SPI_MODE_0 | SPI_TX_QUAD | SPI_RX_QUAD,
217 .max_speed_hz = 30000000,
224 static const struct resource sata0_resources[] __initconst = {
225 DEFINE_RES_MEM(0xee300000, 0x2000),
226 DEFINE_RES_IRQ(gic_spi(105)),
229 static const struct platform_device_info sata0_info __initconst = {
230 .parent = &platform_bus,
231 .name = "sata-r8a7791",
233 .res = sata0_resources,
234 .num_res = ARRAY_SIZE(sata0_resources),
235 .dma_mask = DMA_BIT_MASK(32),
239 static const struct resource i2c_resources[] __initconst = {
241 DEFINE_RES_MEM(0xE6508000, 0x40),
242 DEFINE_RES_IRQ(gic_spi(287)),
244 DEFINE_RES_MEM(0xE6518000, 0x40),
245 DEFINE_RES_IRQ(gic_spi(288)),
247 DEFINE_RES_MEM(0xE6530000, 0x40),
248 DEFINE_RES_IRQ(gic_spi(286)),
250 DEFINE_RES_MEM(0xE6540000, 0x40),
251 DEFINE_RES_IRQ(gic_spi(290)),
253 DEFINE_RES_MEM(0xE6520000, 0x40),
254 DEFINE_RES_IRQ(gic_spi(19)),
256 DEFINE_RES_MEM(0xE6528000, 0x40),
257 DEFINE_RES_IRQ(gic_spi(20)),
260 static void __init koelsch_add_i2c(unsigned idx)
262 unsigned res_idx = idx * 2;
264 BUG_ON(res_idx >= ARRAY_SIZE(i2c_resources));
266 platform_device_register_simple("i2c-rcar_gen2", idx,
267 i2c_resources + res_idx, 2);
270 #define SDHI_REGULATOR(idx, vdd_pin, vccq_pin) \
271 static struct regulator_consumer_supply vcc_sdhi##idx##_consumer = \
272 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi." #idx); \
274 static struct regulator_init_data vcc_sdhi##idx##_init_data = { \
276 .valid_ops_mask = REGULATOR_CHANGE_STATUS, \
278 .consumer_supplies = &vcc_sdhi##idx##_consumer, \
279 .num_consumer_supplies = 1, \
282 static const struct fixed_voltage_config vcc_sdhi##idx##_info __initconst = {\
283 .supply_name = "SDHI" #idx "Vcc", \
284 .microvolts = 3300000, \
287 .init_data = &vcc_sdhi##idx##_init_data, \
290 static struct regulator_consumer_supply vccq_sdhi##idx##_consumer = \
291 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi." #idx); \
293 static struct regulator_init_data vccq_sdhi##idx##_init_data = { \
295 .input_uV = 3300000, \
298 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | \
299 REGULATOR_CHANGE_STATUS, \
301 .consumer_supplies = &vccq_sdhi##idx##_consumer, \
302 .num_consumer_supplies = 1, \
305 static struct gpio vccq_sdhi##idx##_gpio = \
306 { vccq_pin, GPIOF_OUT_INIT_HIGH, "vccq-sdhi" #idx }; \
308 static struct gpio_regulator_state vccq_sdhi##idx##_states[] = { \
309 { .value = 1800000, .gpios = 0 }, \
310 { .value = 3300000, .gpios = 1 }, \
313 static const struct gpio_regulator_config vccq_sdhi##idx##_info __initconst = {\
314 .supply_name = "vqmmc", \
315 .gpios = &vccq_sdhi##idx##_gpio, \
317 .states = vccq_sdhi##idx##_states, \
318 .nr_states = ARRAY_SIZE(vccq_sdhi##idx##_states), \
319 .type = REGULATOR_VOLTAGE, \
320 .init_data = &vccq_sdhi##idx##_init_data, \
323 SDHI_REGULATOR(0, RCAR_GP_PIN(7, 17), RCAR_GP_PIN(2, 12));
324 SDHI_REGULATOR(1, RCAR_GP_PIN(7, 18), RCAR_GP_PIN(2, 13));
325 SDHI_REGULATOR(2, RCAR_GP_PIN(7, 19), RCAR_GP_PIN(2, 26));
328 static struct sh_mobile_sdhi_info sdhi0_info __initdata = {
329 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
330 MMC_CAP_POWER_OFF_CARD,
331 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
334 static struct resource sdhi0_resources[] __initdata = {
335 DEFINE_RES_MEM(0xee100000, 0x200),
336 DEFINE_RES_IRQ(gic_spi(165)),
340 static struct sh_mobile_sdhi_info sdhi1_info __initdata = {
341 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
342 MMC_CAP_POWER_OFF_CARD,
343 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
346 static struct resource sdhi1_resources[] __initdata = {
347 DEFINE_RES_MEM(0xee140000, 0x100),
348 DEFINE_RES_IRQ(gic_spi(167)),
352 static struct sh_mobile_sdhi_info sdhi2_info __initdata = {
353 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
354 MMC_CAP_POWER_OFF_CARD,
355 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT |
356 TMIO_MMC_WRPROTECT_DISABLE,
359 static struct resource sdhi2_resources[] __initdata = {
360 DEFINE_RES_MEM(0xee160000, 0x100),
361 DEFINE_RES_IRQ(gic_spi(168)),
364 static const struct pinctrl_map koelsch_pinctrl_map[] = {
366 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
368 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
370 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
371 "du_clk_out_0", "du"),
373 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
375 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
377 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
379 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
380 "intc_irq0", "intc"),
382 PIN_MAP_MUX_GROUP_DEFAULT("qspi.0", "pfc-r8a7791",
383 "qspi_ctrl", "qspi"),
384 PIN_MAP_MUX_GROUP_DEFAULT("qspi.0", "pfc-r8a7791",
385 "qspi_data4", "qspi"),
386 /* SCIF0 (CN19: DEBUG SERIAL0) */
387 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.6", "pfc-r8a7791",
388 "scif0_data_d", "scif0"),
389 /* SCIF1 (CN20: DEBUG SERIAL1) */
390 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.7", "pfc-r8a7791",
391 "scif1_data_d", "scif1"),
393 PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar_gen2.1", "pfc-r8a7791",
396 PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar_gen2.2", "pfc-r8a7791",
399 PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar_gen2.4", "pfc-r8a7791",
402 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7791",
403 "sdhi0_data4", "sdhi0"),
404 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7791",
405 "sdhi0_ctrl", "sdhi0"),
406 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7791",
407 "sdhi0_cd", "sdhi0"),
408 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7791",
409 "sdhi0_wp", "sdhi0"),
411 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-r8a7791",
412 "sdhi1_data4", "sdhi1"),
413 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-r8a7791",
414 "sdhi1_ctrl", "sdhi1"),
415 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-r8a7791",
416 "sdhi1_cd", "sdhi1"),
417 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-r8a7791",
418 "sdhi1_wp", "sdhi1"),
420 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-r8a7791",
421 "sdhi2_data4", "sdhi2"),
422 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-r8a7791",
423 "sdhi2_ctrl", "sdhi2"),
424 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-r8a7791",
425 "sdhi2_cd", "sdhi2"),
428 static void __init koelsch_add_standard_devices(void)
430 r8a7791_clock_init();
431 pinctrl_register_mappings(koelsch_pinctrl_map,
432 ARRAY_SIZE(koelsch_pinctrl_map));
433 r8a7791_pinmux_init();
434 r8a7791_add_standard_devices();
435 platform_device_register_full(ðer_info);
436 platform_device_register_data(&platform_bus, "leds-gpio", -1,
438 sizeof(koelsch_leds_pdata));
439 platform_device_register_data(&platform_bus, "gpio-keys", -1,
441 sizeof(koelsch_keys_pdata));
442 platform_device_register_resndata(&platform_bus, "qspi", 0,
444 ARRAY_SIZE(qspi_resources),
445 &qspi_pdata, sizeof(qspi_pdata));
446 spi_register_board_info(spi_info, ARRAY_SIZE(spi_info));
448 koelsch_add_du_device();
450 platform_device_register_full(&sata0_info);
457 platform_device_register_data(&platform_bus, "reg-fixed-voltage", 0,
458 &vcc_sdhi0_info, sizeof(struct fixed_voltage_config));
459 platform_device_register_data(&platform_bus, "reg-fixed-voltage", 1,
460 &vcc_sdhi1_info, sizeof(struct fixed_voltage_config));
461 platform_device_register_data(&platform_bus, "reg-fixed-voltage", 2,
462 &vcc_sdhi2_info, sizeof(struct fixed_voltage_config));
463 platform_device_register_data(&platform_bus, "gpio-regulator", 0,
464 &vccq_sdhi0_info, sizeof(struct gpio_regulator_config));
465 platform_device_register_data(&platform_bus, "gpio-regulator", 1,
466 &vccq_sdhi1_info, sizeof(struct gpio_regulator_config));
467 platform_device_register_data(&platform_bus, "gpio-regulator", 2,
468 &vccq_sdhi2_info, sizeof(struct gpio_regulator_config));
470 platform_device_register_resndata(&platform_bus, "sh_mobile_sdhi", 0,
471 sdhi0_resources, ARRAY_SIZE(sdhi0_resources),
472 &sdhi0_info, sizeof(struct sh_mobile_sdhi_info));
474 platform_device_register_resndata(&platform_bus, "sh_mobile_sdhi", 1,
475 sdhi1_resources, ARRAY_SIZE(sdhi1_resources),
476 &sdhi1_info, sizeof(struct sh_mobile_sdhi_info));
478 platform_device_register_resndata(&platform_bus, "sh_mobile_sdhi", 2,
479 sdhi2_resources, ARRAY_SIZE(sdhi2_resources),
480 &sdhi2_info, sizeof(struct sh_mobile_sdhi_info));
485 * Ether LEDs on the Koelsch board are named LINK and ACTIVE which corresponds
486 * to non-default 01 setting of the Micrel KSZ8041 PHY control register 1 bits
487 * 14-15. We have to set them back to 01 from the default 00 value each time
488 * the PHY is reset. It's also important because the PHY's LED0 signal is
489 * connected to SoC's ETH_LINK signal and in the PHY's default mode it will
490 * bounce on and off after each packet, which we apparently want to avoid.
492 static int koelsch_ksz8041_fixup(struct phy_device *phydev)
494 u16 phyctrl1 = phy_read(phydev, 0x1e);
498 return phy_write(phydev, 0x1e, phyctrl1);
501 static void __init koelsch_init(void)
503 koelsch_add_standard_devices();
505 irq_set_irq_type(irq_pin(0), IRQ_TYPE_LEVEL_LOW);
507 if (IS_ENABLED(CONFIG_PHYLIB))
508 phy_register_fixup_for_id("r8a7791-ether-ff:01",
509 koelsch_ksz8041_fixup);
512 static const char * const koelsch_boards_compat_dt[] __initconst = {
517 DT_MACHINE_START(KOELSCH_DT, "koelsch")
518 .smp = smp_ops(r8a7791_smp_ops),
519 .init_early = shmobile_init_delay,
520 .init_time = rcar_gen2_timer_init,
521 .init_machine = koelsch_init,
522 .init_late = shmobile_init_late,
523 .reserve = rcar_gen2_reserve,
524 .dt_compat = koelsch_boards_compat_dt,