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/phy.h>
30 #include <linux/pinctrl/machine.h>
31 #include <linux/platform_data/gpio-rcar.h>
32 #include <linux/platform_data/rcar-du.h>
33 #include <linux/platform_device.h>
34 #include <linux/sh_eth.h>
35 #include <mach/common.h>
36 #include <mach/irqs.h>
37 #include <mach/r8a7791.h>
38 #include <mach/rcar-gen2.h>
39 #include <asm/mach-types.h>
40 #include <asm/mach/arch.h>
43 static struct rcar_du_encoder_data koelsch_du_encoders[] = {
45 .type = RCAR_DU_ENCODER_NONE,
46 .output = RCAR_DU_OUTPUT_LVDS0,
47 .connector.lvds.panel = {
66 static const struct rcar_du_platform_data koelsch_du_pdata __initconst = {
67 .encoders = koelsch_du_encoders,
68 .num_encoders = ARRAY_SIZE(koelsch_du_encoders),
71 static const struct resource du_resources[] __initconst = {
72 DEFINE_RES_MEM(0xfeb00000, 0x40000),
73 DEFINE_RES_MEM_NAMED(0xfeb90000, 0x1c, "lvds.0"),
74 DEFINE_RES_IRQ(gic_spi(256)),
75 DEFINE_RES_IRQ(gic_spi(268)),
78 static void __init koelsch_add_du_device(void)
80 struct platform_device_info info = {
81 .name = "rcar-du-r8a7791",
84 .num_res = ARRAY_SIZE(du_resources),
85 .data = &koelsch_du_pdata,
86 .size_data = sizeof(koelsch_du_pdata),
87 .dma_mask = DMA_BIT_MASK(32),
90 platform_device_register_full(&info);
94 static const struct sh_eth_plat_data ether_pdata __initconst = {
96 .phy_irq = irq_pin(0),
97 .edmac_endian = EDMAC_LITTLE_ENDIAN,
98 .phy_interface = PHY_INTERFACE_MODE_RMII,
99 .ether_link_active_low = 1,
102 static const struct resource ether_resources[] __initconst = {
103 DEFINE_RES_MEM(0xee700000, 0x400),
104 DEFINE_RES_IRQ(gic_spi(162)),
108 static struct gpio_led koelsch_leds[] = {
111 .gpio = RCAR_GP_PIN(2, 21),
112 .default_state = LEDS_GPIO_DEFSTATE_ON,
115 .gpio = RCAR_GP_PIN(2, 20),
116 .default_state = LEDS_GPIO_DEFSTATE_ON,
119 .gpio = RCAR_GP_PIN(2, 19),
120 .default_state = LEDS_GPIO_DEFSTATE_ON,
124 static const struct gpio_led_platform_data koelsch_leds_pdata __initconst = {
125 .leds = koelsch_leds,
126 .num_leds = ARRAY_SIZE(koelsch_leds),
130 #define GPIO_KEY(c, g, d, ...) \
131 { .code = c, .gpio = g, .desc = d, .active_low = 1, \
132 .wakeup = 1, .debounce_interval = 20 }
134 static struct gpio_keys_button gpio_buttons[] = {
135 GPIO_KEY(KEY_4, RCAR_GP_PIN(5, 3), "SW2-pin4"),
136 GPIO_KEY(KEY_3, RCAR_GP_PIN(5, 2), "SW2-pin3"),
137 GPIO_KEY(KEY_2, RCAR_GP_PIN(5, 1), "SW2-pin2"),
138 GPIO_KEY(KEY_1, RCAR_GP_PIN(5, 0), "SW2-pin1"),
139 GPIO_KEY(KEY_G, RCAR_GP_PIN(7, 6), "SW36"),
140 GPIO_KEY(KEY_F, RCAR_GP_PIN(7, 5), "SW35"),
141 GPIO_KEY(KEY_E, RCAR_GP_PIN(7, 4), "SW34"),
142 GPIO_KEY(KEY_D, RCAR_GP_PIN(7, 3), "SW33"),
143 GPIO_KEY(KEY_C, RCAR_GP_PIN(7, 2), "SW32"),
144 GPIO_KEY(KEY_B, RCAR_GP_PIN(7, 1), "SW31"),
145 GPIO_KEY(KEY_A, RCAR_GP_PIN(7, 0), "SW30"),
148 static const struct gpio_keys_platform_data koelsch_keys_pdata __initconst = {
149 .buttons = gpio_buttons,
150 .nbuttons = ARRAY_SIZE(gpio_buttons),
154 static const struct resource sata0_resources[] __initconst = {
155 DEFINE_RES_MEM(0xee300000, 0x2000),
156 DEFINE_RES_IRQ(gic_spi(105)),
159 static const struct platform_device_info sata0_info __initconst = {
160 .parent = &platform_bus,
161 .name = "sata-r8a7791",
163 .res = sata0_resources,
164 .num_res = ARRAY_SIZE(sata0_resources),
165 .dma_mask = DMA_BIT_MASK(32),
169 static const struct resource i2c_resources[] __initconst = {
171 DEFINE_RES_MEM(0xE6508000, 0x40),
172 DEFINE_RES_IRQ(gic_spi(287)),
174 DEFINE_RES_MEM(0xE6518000, 0x40),
175 DEFINE_RES_IRQ(gic_spi(288)),
177 DEFINE_RES_MEM(0xE6530000, 0x40),
178 DEFINE_RES_IRQ(gic_spi(286)),
180 DEFINE_RES_MEM(0xE6540000, 0x40),
181 DEFINE_RES_IRQ(gic_spi(290)),
183 DEFINE_RES_MEM(0xE6520000, 0x40),
184 DEFINE_RES_IRQ(gic_spi(19)),
186 DEFINE_RES_MEM(0xE6528000, 0x40),
187 DEFINE_RES_IRQ(gic_spi(20)),
190 static void __init koelsch_add_i2c(unsigned idx)
192 unsigned res_idx = idx * 2;
194 BUG_ON(res_idx >= ARRAY_SIZE(i2c_resources));
196 platform_device_register_simple("i2c-rcar_gen2", idx,
197 i2c_resources + res_idx, 2);
200 static const struct pinctrl_map koelsch_pinctrl_map[] = {
202 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
204 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
206 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
207 "du_clk_out_0", "du"),
209 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
211 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
213 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
215 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
216 "intc_irq0", "intc"),
217 /* SCIF0 (CN19: DEBUG SERIAL0) */
218 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.6", "pfc-r8a7791",
219 "scif0_data_d", "scif0"),
220 /* SCIF1 (CN20: DEBUG SERIAL1) */
221 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.7", "pfc-r8a7791",
222 "scif1_data_d", "scif1"),
224 PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar_gen2.1", "pfc-r8a7791",
227 PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar_gen2.2", "pfc-r8a7791",
230 PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar_gen2.4", "pfc-r8a7791",
234 static void __init koelsch_add_standard_devices(void)
236 r8a7791_clock_init();
237 pinctrl_register_mappings(koelsch_pinctrl_map,
238 ARRAY_SIZE(koelsch_pinctrl_map));
239 r8a7791_pinmux_init();
240 r8a7791_add_standard_devices();
241 platform_device_register_resndata(&platform_bus, "r8a7791-ether", -1,
243 ARRAY_SIZE(ether_resources),
244 ðer_pdata, sizeof(ether_pdata));
245 platform_device_register_data(&platform_bus, "leds-gpio", -1,
247 sizeof(koelsch_leds_pdata));
248 platform_device_register_data(&platform_bus, "gpio-keys", -1,
250 sizeof(koelsch_keys_pdata));
252 koelsch_add_du_device();
254 platform_device_register_full(&sata0_info);
263 * Ether LEDs on the Koelsch board are named LINK and ACTIVE which corresponds
264 * to non-default 01 setting of the Micrel KSZ8041 PHY control register 1 bits
265 * 14-15. We have to set them back to 01 from the default 00 value each time
266 * the PHY is reset. It's also important because the PHY's LED0 signal is
267 * connected to SoC's ETH_LINK signal and in the PHY's default mode it will
268 * bounce on and off after each packet, which we apparently want to avoid.
270 static int koelsch_ksz8041_fixup(struct phy_device *phydev)
272 u16 phyctrl1 = phy_read(phydev, 0x1e);
276 return phy_write(phydev, 0x1e, phyctrl1);
279 static void __init koelsch_init(void)
281 koelsch_add_standard_devices();
283 irq_set_irq_type(irq_pin(0), IRQ_TYPE_LEVEL_LOW);
285 if (IS_ENABLED(CONFIG_PHYLIB))
286 phy_register_fixup_for_id("r8a7791-ether-ff:01",
287 koelsch_ksz8041_fixup);
290 static const char * const koelsch_boards_compat_dt[] __initconst = {
295 DT_MACHINE_START(KOELSCH_DT, "koelsch")
296 .smp = smp_ops(r8a7791_smp_ops),
297 .init_early = r8a7791_init_early,
298 .init_time = rcar_gen2_timer_init,
299 .init_machine = koelsch_init,
300 .init_late = shmobile_init_late,
301 .dt_compat = koelsch_boards_compat_dt,