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/kernel.h>
27 #include <linux/leds.h>
28 #include <linux/phy.h>
29 #include <linux/pinctrl/machine.h>
30 #include <linux/platform_data/gpio-rcar.h>
31 #include <linux/platform_data/rcar-du.h>
32 #include <linux/platform_device.h>
33 #include <linux/sh_eth.h>
34 #include <mach/common.h>
35 #include <mach/irqs.h>
36 #include <mach/r8a7791.h>
37 #include <mach/rcar-gen2.h>
38 #include <asm/mach-types.h>
39 #include <asm/mach/arch.h>
42 static struct rcar_du_encoder_data koelsch_du_encoders[] = {
44 .type = RCAR_DU_ENCODER_NONE,
45 .output = RCAR_DU_OUTPUT_LVDS0,
46 .connector.lvds.panel = {
65 static const struct rcar_du_platform_data koelsch_du_pdata __initconst = {
66 .encoders = koelsch_du_encoders,
67 .num_encoders = ARRAY_SIZE(koelsch_du_encoders),
70 static const struct resource du_resources[] __initconst = {
71 DEFINE_RES_MEM(0xfeb00000, 0x40000),
72 DEFINE_RES_MEM_NAMED(0xfeb90000, 0x1c, "lvds.0"),
73 DEFINE_RES_IRQ(gic_spi(256)),
74 DEFINE_RES_IRQ(gic_spi(268)),
77 static void __init koelsch_add_du_device(void)
79 struct platform_device_info info = {
80 .name = "rcar-du-r8a7791",
83 .num_res = ARRAY_SIZE(du_resources),
84 .data = &koelsch_du_pdata,
85 .size_data = sizeof(koelsch_du_pdata),
86 .dma_mask = DMA_BIT_MASK(32),
89 platform_device_register_full(&info);
93 static const struct sh_eth_plat_data ether_pdata __initconst = {
95 .edmac_endian = EDMAC_LITTLE_ENDIAN,
96 .phy_interface = PHY_INTERFACE_MODE_RMII,
97 .ether_link_active_low = 1,
100 static const struct resource ether_resources[] __initconst = {
101 DEFINE_RES_MEM(0xee700000, 0x400),
102 DEFINE_RES_IRQ(gic_spi(162)),
106 static struct gpio_led koelsch_leds[] = {
109 .gpio = RCAR_GP_PIN(2, 21),
110 .default_state = LEDS_GPIO_DEFSTATE_ON,
113 .gpio = RCAR_GP_PIN(2, 20),
114 .default_state = LEDS_GPIO_DEFSTATE_ON,
117 .gpio = RCAR_GP_PIN(2, 19),
118 .default_state = LEDS_GPIO_DEFSTATE_ON,
122 static const struct gpio_led_platform_data koelsch_leds_pdata __initconst = {
123 .leds = koelsch_leds,
124 .num_leds = ARRAY_SIZE(koelsch_leds),
128 #define GPIO_KEY(c, g, d, ...) \
129 { .code = c, .gpio = g, .desc = d, .active_low = 1, \
130 .wakeup = 1, .debounce_interval = 20 }
132 static struct gpio_keys_button gpio_buttons[] = {
133 GPIO_KEY(KEY_4, RCAR_GP_PIN(5, 3), "SW2-pin4"),
134 GPIO_KEY(KEY_3, RCAR_GP_PIN(5, 2), "SW2-pin3"),
135 GPIO_KEY(KEY_2, RCAR_GP_PIN(5, 1), "SW2-pin2"),
136 GPIO_KEY(KEY_1, RCAR_GP_PIN(5, 0), "SW2-pin1"),
137 GPIO_KEY(KEY_G, RCAR_GP_PIN(7, 6), "SW36"),
138 GPIO_KEY(KEY_F, RCAR_GP_PIN(7, 5), "SW35"),
139 GPIO_KEY(KEY_E, RCAR_GP_PIN(7, 4), "SW34"),
140 GPIO_KEY(KEY_D, RCAR_GP_PIN(7, 3), "SW33"),
141 GPIO_KEY(KEY_C, RCAR_GP_PIN(7, 2), "SW32"),
142 GPIO_KEY(KEY_B, RCAR_GP_PIN(7, 1), "SW31"),
143 GPIO_KEY(KEY_A, RCAR_GP_PIN(7, 0), "SW30"),
146 static const struct gpio_keys_platform_data koelsch_keys_pdata __initconst = {
147 .buttons = gpio_buttons,
148 .nbuttons = ARRAY_SIZE(gpio_buttons),
151 static const struct pinctrl_map koelsch_pinctrl_map[] = {
153 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
155 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
157 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
158 "du_clk_out_0", "du"),
160 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
162 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
164 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
166 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
167 "intc_irq0", "intc"),
168 /* SCIF0 (CN19: DEBUG SERIAL0) */
169 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.6", "pfc-r8a7791",
170 "scif0_data_d", "scif0"),
171 /* SCIF1 (CN20: DEBUG SERIAL1) */
172 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.7", "pfc-r8a7791",
173 "scif1_data_d", "scif1"),
176 static void __init koelsch_add_standard_devices(void)
178 r8a7791_clock_init();
179 pinctrl_register_mappings(koelsch_pinctrl_map,
180 ARRAY_SIZE(koelsch_pinctrl_map));
181 r8a7791_pinmux_init();
182 r8a7791_add_standard_devices();
183 platform_device_register_resndata(&platform_bus, "r8a7791-ether", -1,
185 ARRAY_SIZE(ether_resources),
186 ðer_pdata, sizeof(ether_pdata));
187 platform_device_register_data(&platform_bus, "leds-gpio", -1,
189 sizeof(koelsch_leds_pdata));
190 platform_device_register_data(&platform_bus, "gpio-keys", -1,
192 sizeof(koelsch_keys_pdata));
194 koelsch_add_du_device();
198 * Ether LEDs on the Koelsch board are named LINK and ACTIVE which corresponds
199 * to non-default 01 setting of the Micrel KSZ8041 PHY control register 1 bits
200 * 14-15. We have to set them back to 01 from the default 00 value each time
201 * the PHY is reset. It's also important because the PHY's LED0 signal is
202 * connected to SoC's ETH_LINK signal and in the PHY's default mode it will
203 * bounce on and off after each packet, which we apparently want to avoid.
205 static int koelsch_ksz8041_fixup(struct phy_device *phydev)
207 u16 phyctrl1 = phy_read(phydev, 0x1e);
211 return phy_write(phydev, 0x1e, phyctrl1);
214 static void __init koelsch_init(void)
216 koelsch_add_standard_devices();
218 if (IS_ENABLED(CONFIG_PHYLIB))
219 phy_register_fixup_for_id("r8a7791-ether-ff:01",
220 koelsch_ksz8041_fixup);
223 static const char * const koelsch_boards_compat_dt[] __initconst = {
228 DT_MACHINE_START(KOELSCH_DT, "koelsch")
229 .smp = smp_ops(r8a7791_smp_ops),
230 .init_early = r8a7791_init_early,
231 .init_time = rcar_gen2_timer_init,
232 .init_machine = koelsch_init,
233 .init_late = shmobile_init_late,
234 .dt_compat = koelsch_boards_compat_dt,