blob: de7cc64b1f3733823fa0b041ad7853ea73ba5c09 [file] [log] [blame]
Hisashi Nakamura1f52c652013-09-04 12:46:49 +09001/*
2 * Koelsch board support
3 *
4 * Copyright (C) 2013 Renesas Electronics Corporation
5 * Copyright (C) 2013 Renesas Solutions Corp.
6 * Copyright (C) 2013 Magnus Damm
7 *
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.
11 *
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.
16 *
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
20 */
21
Laurent Pinchart784c33a2013-12-07 02:17:44 +010022#include <linux/dma-mapping.h>
Magnus Damm721319d2013-10-08 12:40:08 +090023#include <linux/gpio.h>
24#include <linux/gpio_keys.h>
25#include <linux/input.h>
Hisashi Nakamura1f52c652013-09-04 12:46:49 +090026#include <linux/kernel.h>
Magnus Damm87a29342013-10-08 12:39:59 +090027#include <linux/leds.h>
Sergei Shtylyov974faba2013-12-08 23:52:44 +030028#include <linux/phy.h>
Magnus Damm85ef14d2013-11-20 16:41:48 +090029#include <linux/pinctrl/machine.h>
Magnus Damm87a29342013-10-08 12:39:59 +090030#include <linux/platform_data/gpio-rcar.h>
Laurent Pinchart784c33a2013-12-07 02:17:44 +010031#include <linux/platform_data/rcar-du.h>
Hisashi Nakamura1f52c652013-09-04 12:46:49 +090032#include <linux/platform_device.h>
Sergei Shtylyov974faba2013-12-08 23:52:44 +030033#include <linux/sh_eth.h>
Hisashi Nakamura1f52c652013-09-04 12:46:49 +090034#include <mach/common.h>
Laurent Pinchart784c33a2013-12-07 02:17:44 +010035#include <mach/irqs.h>
Hisashi Nakamura1f52c652013-09-04 12:46:49 +090036#include <mach/r8a7791.h>
Magnus Dammf9c9eb72013-10-01 17:12:57 +090037#include <mach/rcar-gen2.h>
Hisashi Nakamura1f52c652013-09-04 12:46:49 +090038#include <asm/mach-types.h>
39#include <asm/mach/arch.h>
40
Laurent Pinchart784c33a2013-12-07 02:17:44 +010041/* DU */
42static struct rcar_du_encoder_data koelsch_du_encoders[] = {
43 {
44 .type = RCAR_DU_ENCODER_NONE,
45 .output = RCAR_DU_OUTPUT_LVDS0,
46 .connector.lvds.panel = {
47 .width_mm = 210,
48 .height_mm = 158,
49 .mode = {
50 .clock = 65000,
51 .hdisplay = 1024,
52 .hsync_start = 1048,
53 .hsync_end = 1184,
54 .htotal = 1344,
55 .vdisplay = 768,
56 .vsync_start = 771,
57 .vsync_end = 777,
58 .vtotal = 806,
59 .flags = 0,
60 },
61 },
62 },
63};
64
65static const struct rcar_du_platform_data koelsch_du_pdata __initconst = {
66 .encoders = koelsch_du_encoders,
67 .num_encoders = ARRAY_SIZE(koelsch_du_encoders),
68};
69
70static 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)),
75};
76
77static void __init koelsch_add_du_device(void)
78{
79 struct platform_device_info info = {
80 .name = "rcar-du-r8a7791",
81 .id = -1,
82 .res = du_resources,
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),
87 };
88
89 platform_device_register_full(&info);
90}
91
Sergei Shtylyov974faba2013-12-08 23:52:44 +030092/* Ether */
93static const struct sh_eth_plat_data ether_pdata __initconst = {
94 .phy = 0x1,
95 .edmac_endian = EDMAC_LITTLE_ENDIAN,
96 .phy_interface = PHY_INTERFACE_MODE_RMII,
97 .ether_link_active_low = 1,
98};
99
100static const struct resource ether_resources[] __initconst = {
101 DEFINE_RES_MEM(0xee700000, 0x400),
102 DEFINE_RES_IRQ(gic_spi(162)),
103};
104
Magnus Damm87a29342013-10-08 12:39:59 +0900105/* LEDS */
106static struct gpio_led koelsch_leds[] = {
107 {
108 .name = "led8",
109 .gpio = RCAR_GP_PIN(2, 21),
110 .default_state = LEDS_GPIO_DEFSTATE_ON,
111 }, {
112 .name = "led7",
113 .gpio = RCAR_GP_PIN(2, 20),
114 .default_state = LEDS_GPIO_DEFSTATE_ON,
115 }, {
116 .name = "led6",
117 .gpio = RCAR_GP_PIN(2, 19),
118 .default_state = LEDS_GPIO_DEFSTATE_ON,
119 },
120};
121
122static const struct gpio_led_platform_data koelsch_leds_pdata __initconst = {
123 .leds = koelsch_leds,
124 .num_leds = ARRAY_SIZE(koelsch_leds),
125};
126
Magnus Damm721319d2013-10-08 12:40:08 +0900127/* GPIO KEY */
128#define GPIO_KEY(c, g, d, ...) \
Simon Horman478e2f92013-10-29 17:57:31 +0900129 { .code = c, .gpio = g, .desc = d, .active_low = 1, \
Magnus Damme2094562013-11-20 12:56:38 +0900130 .wakeup = 1, .debounce_interval = 20 }
Magnus Damm721319d2013-10-08 12:40:08 +0900131
132static 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"),
Magnus Damm159a2822013-11-20 13:00:10 +0900137 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"),
Magnus Damm721319d2013-10-08 12:40:08 +0900144};
145
146static const struct gpio_keys_platform_data koelsch_keys_pdata __initconst = {
147 .buttons = gpio_buttons,
148 .nbuttons = ARRAY_SIZE(gpio_buttons),
149};
150
Magnus Damm85ef14d2013-11-20 16:41:48 +0900151static const struct pinctrl_map koelsch_pinctrl_map[] = {
Laurent Pinchart784c33a2013-12-07 02:17:44 +0100152 /* DU */
153 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
154 "du_rgb666", "du"),
155 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
156 "du_sync", "du"),
157 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
158 "du_clk_out_0", "du"),
Sergei Shtylyov974faba2013-12-08 23:52:44 +0300159 /* Ether */
160 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
161 "eth_link", "eth"),
162 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
163 "eth_mdio", "eth"),
164 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
165 "eth_rmii", "eth"),
166 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
167 "intc_irq0", "intc"),
Magnus Damm85ef14d2013-11-20 16:41:48 +0900168 /* 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"),
174};
175
Hisashi Nakamura1f52c652013-09-04 12:46:49 +0900176static void __init koelsch_add_standard_devices(void)
177{
178 r8a7791_clock_init();
Magnus Damm85ef14d2013-11-20 16:41:48 +0900179 pinctrl_register_mappings(koelsch_pinctrl_map,
180 ARRAY_SIZE(koelsch_pinctrl_map));
Magnus Damm1a534ec2013-10-08 12:39:49 +0900181 r8a7791_pinmux_init();
Magnus Damm0749bea2013-10-01 17:12:02 +0900182 r8a7791_add_standard_devices();
Sergei Shtylyov974faba2013-12-08 23:52:44 +0300183 platform_device_register_resndata(&platform_bus, "r8a7791-ether", -1,
184 ether_resources,
185 ARRAY_SIZE(ether_resources),
186 &ether_pdata, sizeof(ether_pdata));
Magnus Damm87a29342013-10-08 12:39:59 +0900187 platform_device_register_data(&platform_bus, "leds-gpio", -1,
188 &koelsch_leds_pdata,
189 sizeof(koelsch_leds_pdata));
Magnus Damm721319d2013-10-08 12:40:08 +0900190 platform_device_register_data(&platform_bus, "gpio-keys", -1,
191 &koelsch_keys_pdata,
192 sizeof(koelsch_keys_pdata));
Laurent Pinchart784c33a2013-12-07 02:17:44 +0100193
194 koelsch_add_du_device();
Hisashi Nakamura1f52c652013-09-04 12:46:49 +0900195}
196
Sergei Shtylyov974faba2013-12-08 23:52:44 +0300197/*
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.
204 */
205static int koelsch_ksz8041_fixup(struct phy_device *phydev)
206{
207 u16 phyctrl1 = phy_read(phydev, 0x1e);
208
209 phyctrl1 &= ~0xc000;
210 phyctrl1 |= 0x4000;
211 return phy_write(phydev, 0x1e, phyctrl1);
212}
213
214static void __init koelsch_init(void)
215{
216 koelsch_add_standard_devices();
217
218 if (IS_ENABLED(CONFIG_PHYLIB))
219 phy_register_fixup_for_id("r8a7791-ether-ff:01",
220 koelsch_ksz8041_fixup);
221}
222
Hisashi Nakamura1f52c652013-09-04 12:46:49 +0900223static const char * const koelsch_boards_compat_dt[] __initconst = {
224 "renesas,koelsch",
225 NULL,
226};
227
228DT_MACHINE_START(KOELSCH_DT, "koelsch")
Magnus Dammb6d5a1b2013-10-01 17:13:26 +0900229 .smp = smp_ops(r8a7791_smp_ops),
Hisashi Nakamura1f52c652013-09-04 12:46:49 +0900230 .init_early = r8a7791_init_early,
Magnus Dammf9c9eb72013-10-01 17:12:57 +0900231 .init_time = rcar_gen2_timer_init,
Sergei Shtylyov974faba2013-12-08 23:52:44 +0300232 .init_machine = koelsch_init,
Magnus Damm6dc00ab2013-11-20 12:54:34 +0900233 .init_late = shmobile_init_late,
Hisashi Nakamura1f52c652013-09-04 12:46:49 +0900234 .dt_compat = koelsch_boards_compat_dt,
235MACHINE_END