2 * Koelsch board support
4 * Copyright (C) 2013 Renesas Electronics Corporation
5 * Copyright (C) 2013 Renesas Solutions Corp.
6 * Copyright (C) 2013 Magnus Damm
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <linux/dma-mapping.h>
23 #include <linux/gpio.h>
24 #include <linux/gpio_keys.h>
25 #include <linux/input.h>
26 #include <linux/irq.h>
27 #include <linux/kernel.h>
28 #include <linux/leds.h>
29 #include <linux/mfd/tmio.h>
30 #include <linux/mmc/host.h>
31 #include <linux/mmc/sh_mobile_sdhi.h>
32 #include <linux/mtd/mtd.h>
33 #include <linux/mtd/partitions.h>
34 #include <linux/phy.h>
35 #include <linux/pinctrl/machine.h>
36 #include <linux/platform_data/gpio-rcar.h>
37 #include <linux/platform_data/rcar-du.h>
38 #include <linux/platform_device.h>
39 #include <linux/regulator/driver.h>
40 #include <linux/regulator/fixed.h>
41 #include <linux/regulator/gpio-regulator.h>
42 #include <linux/regulator/machine.h>
43 #include <linux/sh_eth.h>
44 #include <linux/spi/flash.h>
45 #include <linux/spi/rspi.h>
46 #include <linux/spi/spi.h>
47 #include <mach/common.h>
48 #include <mach/irqs.h>
49 #include <mach/r8a7791.h>
50 #include <mach/rcar-gen2.h>
51 #include <asm/mach-types.h>
52 #include <asm/mach/arch.h>
55 static struct rcar_du_encoder_data koelsch_du_encoders[] = {
57 .type = RCAR_DU_ENCODER_NONE,
58 .output = RCAR_DU_OUTPUT_LVDS0,
59 .connector.lvds.panel = {
78 static const struct rcar_du_platform_data koelsch_du_pdata __initconst = {
79 .encoders = koelsch_du_encoders,
80 .num_encoders = ARRAY_SIZE(koelsch_du_encoders),
83 static const struct resource du_resources[] __initconst = {
84 DEFINE_RES_MEM(0xfeb00000, 0x40000),
85 DEFINE_RES_MEM_NAMED(0xfeb90000, 0x1c, "lvds.0"),
86 DEFINE_RES_IRQ(gic_spi(256)),
87 DEFINE_RES_IRQ(gic_spi(268)),
90 static void __init koelsch_add_du_device(void)
92 struct platform_device_info info = {
93 .name = "rcar-du-r8a7791",
96 .num_res = ARRAY_SIZE(du_resources),
97 .data = &koelsch_du_pdata,
98 .size_data = sizeof(koelsch_du_pdata),
99 .dma_mask = DMA_BIT_MASK(32),
102 platform_device_register_full(&info);
106 static const struct sh_eth_plat_data ether_pdata __initconst = {
108 .phy_irq = irq_pin(0),
109 .edmac_endian = EDMAC_LITTLE_ENDIAN,
110 .phy_interface = PHY_INTERFACE_MODE_RMII,
111 .ether_link_active_low = 1,
114 static const struct resource ether_resources[] __initconst = {
115 DEFINE_RES_MEM(0xee700000, 0x400),
116 DEFINE_RES_IRQ(gic_spi(162)),
120 static struct gpio_led koelsch_leds[] = {
123 .gpio = RCAR_GP_PIN(2, 21),
124 .default_state = LEDS_GPIO_DEFSTATE_ON,
127 .gpio = RCAR_GP_PIN(2, 20),
128 .default_state = LEDS_GPIO_DEFSTATE_ON,
131 .gpio = RCAR_GP_PIN(2, 19),
132 .default_state = LEDS_GPIO_DEFSTATE_ON,
136 static const struct gpio_led_platform_data koelsch_leds_pdata __initconst = {
137 .leds = koelsch_leds,
138 .num_leds = ARRAY_SIZE(koelsch_leds),
142 #define GPIO_KEY(c, g, d, ...) \
143 { .code = c, .gpio = g, .desc = d, .active_low = 1, \
144 .wakeup = 1, .debounce_interval = 20 }
146 static struct gpio_keys_button gpio_buttons[] = {
147 GPIO_KEY(KEY_4, RCAR_GP_PIN(5, 3), "SW2-pin4"),
148 GPIO_KEY(KEY_3, RCAR_GP_PIN(5, 2), "SW2-pin3"),
149 GPIO_KEY(KEY_2, RCAR_GP_PIN(5, 1), "SW2-pin2"),
150 GPIO_KEY(KEY_1, RCAR_GP_PIN(5, 0), "SW2-pin1"),
151 GPIO_KEY(KEY_G, RCAR_GP_PIN(7, 6), "SW36"),
152 GPIO_KEY(KEY_F, RCAR_GP_PIN(7, 5), "SW35"),
153 GPIO_KEY(KEY_E, RCAR_GP_PIN(7, 4), "SW34"),
154 GPIO_KEY(KEY_D, RCAR_GP_PIN(7, 3), "SW33"),
155 GPIO_KEY(KEY_C, RCAR_GP_PIN(7, 2), "SW32"),
156 GPIO_KEY(KEY_B, RCAR_GP_PIN(7, 1), "SW31"),
157 GPIO_KEY(KEY_A, RCAR_GP_PIN(7, 0), "SW30"),
160 static const struct gpio_keys_platform_data koelsch_keys_pdata __initconst = {
161 .buttons = gpio_buttons,
162 .nbuttons = ARRAY_SIZE(gpio_buttons),
166 static const struct resource qspi_resources[] __initconst = {
167 DEFINE_RES_MEM(0xe6b10000, 0x1000),
168 DEFINE_RES_IRQ_NAMED(gic_spi(184), "mux"),
171 static const struct rspi_plat_data qspi_pdata __initconst = {
175 /* SPI Flash memory (Spansion S25FL512SAGMFIG11 64 MiB) */
176 static struct mtd_partition spi_flash_part[] = {
179 .offset = 0x00000000,
181 .mask_flags = MTD_WRITEABLE,
185 .offset = MTDPART_OFS_APPEND,
187 .mask_flags = MTD_WRITEABLE,
191 .offset = MTDPART_OFS_APPEND,
192 .size = MTDPART_SIZ_FULL,
196 static const struct flash_platform_data spi_flash_data = {
198 .parts = spi_flash_part,
199 .nr_parts = ARRAY_SIZE(spi_flash_part),
203 static const struct spi_board_info spi_info[] __initconst = {
205 .modalias = "m25p80",
206 .platform_data = &spi_flash_data,
208 .max_speed_hz = 30000000,
215 static const struct resource sata0_resources[] __initconst = {
216 DEFINE_RES_MEM(0xee300000, 0x2000),
217 DEFINE_RES_IRQ(gic_spi(105)),
220 static const struct platform_device_info sata0_info __initconst = {
221 .parent = &platform_bus,
222 .name = "sata-r8a7791",
224 .res = sata0_resources,
225 .num_res = ARRAY_SIZE(sata0_resources),
226 .dma_mask = DMA_BIT_MASK(32),
230 static const struct resource i2c_resources[] __initconst = {
232 DEFINE_RES_MEM(0xE6508000, 0x40),
233 DEFINE_RES_IRQ(gic_spi(287)),
235 DEFINE_RES_MEM(0xE6518000, 0x40),
236 DEFINE_RES_IRQ(gic_spi(288)),
238 DEFINE_RES_MEM(0xE6530000, 0x40),
239 DEFINE_RES_IRQ(gic_spi(286)),
241 DEFINE_RES_MEM(0xE6540000, 0x40),
242 DEFINE_RES_IRQ(gic_spi(290)),
244 DEFINE_RES_MEM(0xE6520000, 0x40),
245 DEFINE_RES_IRQ(gic_spi(19)),
247 DEFINE_RES_MEM(0xE6528000, 0x40),
248 DEFINE_RES_IRQ(gic_spi(20)),
251 static void __init koelsch_add_i2c(unsigned idx)
253 unsigned res_idx = idx * 2;
255 BUG_ON(res_idx >= ARRAY_SIZE(i2c_resources));
257 platform_device_register_simple("i2c-rcar_gen2", idx,
258 i2c_resources + res_idx, 2);
261 #define SDHI_REGULATOR(idx, vdd_pin, vccq_pin) \
262 static struct regulator_consumer_supply vcc_sdhi##idx##_consumer = \
263 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi." #idx); \
265 static struct regulator_init_data vcc_sdhi##idx##_init_data = { \
267 .valid_ops_mask = REGULATOR_CHANGE_STATUS, \
269 .consumer_supplies = &vcc_sdhi##idx##_consumer, \
270 .num_consumer_supplies = 1, \
273 static const struct fixed_voltage_config vcc_sdhi##idx##_info __initconst = {\
274 .supply_name = "SDHI" #idx "Vcc", \
275 .microvolts = 3300000, \
278 .init_data = &vcc_sdhi##idx##_init_data, \
281 static struct regulator_consumer_supply vccq_sdhi##idx##_consumer = \
282 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi." #idx); \
284 static struct regulator_init_data vccq_sdhi##idx##_init_data = { \
286 .input_uV = 3300000, \
289 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | \
290 REGULATOR_CHANGE_STATUS, \
292 .consumer_supplies = &vccq_sdhi##idx##_consumer, \
293 .num_consumer_supplies = 1, \
296 static struct gpio vccq_sdhi##idx##_gpio = \
297 { vccq_pin, GPIOF_OUT_INIT_HIGH, "vccq-sdhi" #idx }; \
299 static struct gpio_regulator_state vccq_sdhi##idx##_states[] = { \
300 { .value = 1800000, .gpios = 0 }, \
301 { .value = 3300000, .gpios = 1 }, \
304 static const struct gpio_regulator_config vccq_sdhi##idx##_info __initconst = {\
305 .supply_name = "vqmmc", \
306 .gpios = &vccq_sdhi##idx##_gpio, \
308 .states = vccq_sdhi##idx##_states, \
309 .nr_states = ARRAY_SIZE(vccq_sdhi##idx##_states), \
310 .type = REGULATOR_VOLTAGE, \
311 .init_data = &vccq_sdhi##idx##_init_data, \
314 SDHI_REGULATOR(0, RCAR_GP_PIN(7, 17), RCAR_GP_PIN(2, 12));
315 SDHI_REGULATOR(1, RCAR_GP_PIN(7, 18), RCAR_GP_PIN(2, 13));
316 SDHI_REGULATOR(2, RCAR_GP_PIN(7, 19), RCAR_GP_PIN(2, 26));
319 static struct sh_mobile_sdhi_info sdhi0_info __initdata = {
320 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
321 MMC_CAP_POWER_OFF_CARD,
322 .tmio_caps2 = MMC_CAP2_NO_MULTI_READ,
323 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
326 static struct resource sdhi0_resources[] __initdata = {
327 DEFINE_RES_MEM(0xee100000, 0x200),
328 DEFINE_RES_IRQ(gic_spi(165)),
332 static struct sh_mobile_sdhi_info sdhi1_info __initdata = {
333 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
334 MMC_CAP_POWER_OFF_CARD,
335 .tmio_caps2 = MMC_CAP2_NO_MULTI_READ,
336 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
339 static struct resource sdhi1_resources[] __initdata = {
340 DEFINE_RES_MEM(0xee140000, 0x100),
341 DEFINE_RES_IRQ(gic_spi(167)),
345 static struct sh_mobile_sdhi_info sdhi2_info __initdata = {
346 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
347 MMC_CAP_POWER_OFF_CARD,
348 .tmio_caps2 = MMC_CAP2_NO_MULTI_READ,
349 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT |
350 TMIO_MMC_WRPROTECT_DISABLE,
353 static struct resource sdhi2_resources[] __initdata = {
354 DEFINE_RES_MEM(0xee160000, 0x100),
355 DEFINE_RES_IRQ(gic_spi(168)),
358 static const struct pinctrl_map koelsch_pinctrl_map[] = {
360 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
362 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
364 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
365 "du_clk_out_0", "du"),
367 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
369 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
371 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
373 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
374 "intc_irq0", "intc"),
376 PIN_MAP_MUX_GROUP_DEFAULT("qspi.0", "pfc-r8a7791",
377 "qspi_ctrl", "qspi"),
378 PIN_MAP_MUX_GROUP_DEFAULT("qspi.0", "pfc-r8a7791",
379 "qspi_data4", "qspi"),
380 /* SCIF0 (CN19: DEBUG SERIAL0) */
381 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.6", "pfc-r8a7791",
382 "scif0_data_d", "scif0"),
383 /* SCIF1 (CN20: DEBUG SERIAL1) */
384 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.7", "pfc-r8a7791",
385 "scif1_data_d", "scif1"),
387 PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar_gen2.1", "pfc-r8a7791",
390 PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar_gen2.2", "pfc-r8a7791",
393 PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar_gen2.4", "pfc-r8a7791",
396 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7791",
397 "sdhi0_data4", "sdhi0"),
398 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7791",
399 "sdhi0_ctrl", "sdhi0"),
400 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7791",
401 "sdhi0_cd", "sdhi0"),
402 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7791",
403 "sdhi0_wp", "sdhi0"),
405 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-r8a7791",
406 "sdhi1_data4", "sdhi1"),
407 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-r8a7791",
408 "sdhi1_ctrl", "sdhi1"),
409 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-r8a7791",
410 "sdhi1_cd", "sdhi1"),
411 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-r8a7791",
412 "sdhi1_wp", "sdhi1"),
414 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-r8a7791",
415 "sdhi2_data4", "sdhi2"),
416 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-r8a7791",
417 "sdhi2_ctrl", "sdhi2"),
418 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-r8a7791",
419 "sdhi2_cd", "sdhi2"),
422 static void __init koelsch_add_standard_devices(void)
424 r8a7791_clock_init();
425 pinctrl_register_mappings(koelsch_pinctrl_map,
426 ARRAY_SIZE(koelsch_pinctrl_map));
427 r8a7791_pinmux_init();
428 r8a7791_add_standard_devices();
429 platform_device_register_resndata(&platform_bus, "r8a7791-ether", -1,
431 ARRAY_SIZE(ether_resources),
432 ðer_pdata, sizeof(ether_pdata));
433 platform_device_register_data(&platform_bus, "leds-gpio", -1,
435 sizeof(koelsch_leds_pdata));
436 platform_device_register_data(&platform_bus, "gpio-keys", -1,
438 sizeof(koelsch_keys_pdata));
439 platform_device_register_resndata(&platform_bus, "qspi", 0,
441 ARRAY_SIZE(qspi_resources),
442 &qspi_pdata, sizeof(qspi_pdata));
443 spi_register_board_info(spi_info, ARRAY_SIZE(spi_info));
445 koelsch_add_du_device();
447 platform_device_register_full(&sata0_info);
454 platform_device_register_data(&platform_bus, "reg-fixed-voltage", 0,
455 &vcc_sdhi0_info, sizeof(struct fixed_voltage_config));
456 platform_device_register_data(&platform_bus, "reg-fixed-voltage", 1,
457 &vcc_sdhi1_info, sizeof(struct fixed_voltage_config));
458 platform_device_register_data(&platform_bus, "reg-fixed-voltage", 2,
459 &vcc_sdhi2_info, sizeof(struct fixed_voltage_config));
460 platform_device_register_data(&platform_bus, "gpio-regulator", 0,
461 &vccq_sdhi0_info, sizeof(struct gpio_regulator_config));
462 platform_device_register_data(&platform_bus, "gpio-regulator", 1,
463 &vccq_sdhi1_info, sizeof(struct gpio_regulator_config));
464 platform_device_register_data(&platform_bus, "gpio-regulator", 2,
465 &vccq_sdhi2_info, sizeof(struct gpio_regulator_config));
467 platform_device_register_resndata(&platform_bus, "sh_mobile_sdhi", 0,
468 sdhi0_resources, ARRAY_SIZE(sdhi0_resources),
469 &sdhi0_info, sizeof(struct sh_mobile_sdhi_info));
471 platform_device_register_resndata(&platform_bus, "sh_mobile_sdhi", 1,
472 sdhi1_resources, ARRAY_SIZE(sdhi1_resources),
473 &sdhi1_info, sizeof(struct sh_mobile_sdhi_info));
475 platform_device_register_resndata(&platform_bus, "sh_mobile_sdhi", 2,
476 sdhi2_resources, ARRAY_SIZE(sdhi2_resources),
477 &sdhi2_info, sizeof(struct sh_mobile_sdhi_info));
482 * Ether LEDs on the Koelsch board are named LINK and ACTIVE which corresponds
483 * to non-default 01 setting of the Micrel KSZ8041 PHY control register 1 bits
484 * 14-15. We have to set them back to 01 from the default 00 value each time
485 * the PHY is reset. It's also important because the PHY's LED0 signal is
486 * connected to SoC's ETH_LINK signal and in the PHY's default mode it will
487 * bounce on and off after each packet, which we apparently want to avoid.
489 static int koelsch_ksz8041_fixup(struct phy_device *phydev)
491 u16 phyctrl1 = phy_read(phydev, 0x1e);
495 return phy_write(phydev, 0x1e, phyctrl1);
498 static void __init koelsch_init(void)
500 koelsch_add_standard_devices();
502 irq_set_irq_type(irq_pin(0), IRQ_TYPE_LEVEL_LOW);
504 if (IS_ENABLED(CONFIG_PHYLIB))
505 phy_register_fixup_for_id("r8a7791-ether-ff:01",
506 koelsch_ksz8041_fixup);
509 static const char * const koelsch_boards_compat_dt[] __initconst = {
514 DT_MACHINE_START(KOELSCH_DT, "koelsch")
515 .smp = smp_ops(r8a7791_smp_ops),
516 .init_early = r8a7791_init_early,
517 .init_time = rcar_gen2_timer_init,
518 .init_machine = koelsch_init,
519 .init_late = shmobile_init_late,
520 .dt_compat = koelsch_boards_compat_dt,