blob: e0406fd373906e4d43d53769a7d7cfa548b6f388 [file] [log] [blame]
Magnus Damm3cc828f2013-03-29 17:49:37 +09001/*
2 * Lager board support
3 *
4 * Copyright (C) 2013 Renesas Solutions Corp.
5 * Copyright (C) 2013 Magnus Damm
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
Simon Hormanc3842e42013-05-13 16:04:31 +090021#include <linux/gpio.h>
22#include <linux/gpio_keys.h>
23#include <linux/input.h>
Magnus Damm3cc828f2013-03-29 17:49:37 +090024#include <linux/interrupt.h>
Magnus Damm3cc828f2013-03-29 17:49:37 +090025#include <linux/kernel.h>
Simon Horman1034f4e2013-04-23 02:37:05 +000026#include <linux/leds.h>
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +020027#include <linux/mmc/host.h>
28#include <linux/mmc/sh_mmcif.h>
Laurent Pincharte3a28ac2013-04-08 11:36:22 +020029#include <linux/pinctrl/machine.h>
Simon Horman1034f4e2013-04-23 02:37:05 +000030#include <linux/platform_data/gpio-rcar.h>
Laurent Pinchartc75a5af2013-04-16 12:39:11 +020031#include <linux/platform_data/rcar-du.h>
Magnus Damm3cc828f2013-03-29 17:49:37 +090032#include <linux/platform_device.h>
Sergei Shtylyov48c8b962013-09-14 04:29:22 +040033#include <linux/phy.h>
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +020034#include <linux/regulator/fixed.h>
35#include <linux/regulator/machine.h>
Simon Horman4901e132013-08-06 16:50:10 +090036#include <linux/sh_eth.h>
Magnus Damm3cc828f2013-03-29 17:49:37 +090037#include <mach/common.h>
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +020038#include <mach/irqs.h>
Magnus Damm3cc828f2013-03-29 17:49:37 +090039#include <mach/r8a7790.h>
40#include <asm/mach-types.h>
41#include <asm/mach/arch.h>
42
Laurent Pinchartc75a5af2013-04-16 12:39:11 +020043/* DU */
44static struct rcar_du_encoder_data lager_du_encoders[] = {
45 {
46 .type = RCAR_DU_ENCODER_VGA,
47 .output = RCAR_DU_OUTPUT_DPAD0,
48 }, {
49 .type = RCAR_DU_ENCODER_NONE,
50 .output = RCAR_DU_OUTPUT_LVDS1,
51 .connector.lvds.panel = {
52 .width_mm = 210,
53 .height_mm = 158,
54 .mode = {
55 .clock = 65000,
56 .hdisplay = 1024,
57 .hsync_start = 1048,
58 .hsync_end = 1184,
59 .htotal = 1344,
60 .vdisplay = 768,
61 .vsync_start = 771,
62 .vsync_end = 777,
63 .vtotal = 806,
64 .flags = 0,
65 },
66 },
67 },
68};
69
70static const struct rcar_du_platform_data lager_du_pdata __initconst = {
71 .encoders = lager_du_encoders,
72 .num_encoders = ARRAY_SIZE(lager_du_encoders),
73};
74
75static const struct resource du_resources[] __initconst = {
76 DEFINE_RES_MEM(0xfeb00000, 0x70000),
77 DEFINE_RES_MEM_NAMED(0xfeb90000, 0x1c, "lvds.0"),
78 DEFINE_RES_MEM_NAMED(0xfeb94000, 0x1c, "lvds.1"),
79 DEFINE_RES_IRQ(gic_spi(256)),
80 DEFINE_RES_IRQ(gic_spi(268)),
81 DEFINE_RES_IRQ(gic_spi(269)),
82};
83
84static void __init lager_add_du_device(void)
85{
86 struct platform_device_info info = {
87 .name = "rcar-du-r8a7790",
88 .id = -1,
89 .res = du_resources,
90 .num_res = ARRAY_SIZE(du_resources),
Laurent Pinchart37bf8102013-08-22 17:55:08 +020091 .data = &lager_du_pdata,
92 .size_data = sizeof(lager_du_pdata),
Laurent Pinchartc75a5af2013-04-16 12:39:11 +020093 .dma_mask = DMA_BIT_MASK(32),
94 };
95
96 platform_device_register_full(&info);
97}
98
Simon Horman1034f4e2013-04-23 02:37:05 +000099/* LEDS */
100static struct gpio_led lager_leds[] = {
101 {
102 .name = "led8",
103 .gpio = RCAR_GP_PIN(5, 17),
104 .default_state = LEDS_GPIO_DEFSTATE_ON,
105 }, {
106 .name = "led7",
107 .gpio = RCAR_GP_PIN(4, 23),
108 .default_state = LEDS_GPIO_DEFSTATE_ON,
109 }, {
110 .name = "led6",
111 .gpio = RCAR_GP_PIN(4, 22),
112 .default_state = LEDS_GPIO_DEFSTATE_ON,
113 },
114};
115
Laurent Pinchart27113d62013-08-08 00:43:00 +0200116static const struct gpio_led_platform_data lager_leds_pdata __initconst = {
Simon Horman1034f4e2013-04-23 02:37:05 +0000117 .leds = lager_leds,
118 .num_leds = ARRAY_SIZE(lager_leds),
119};
120
Simon Hormanc3842e42013-05-13 16:04:31 +0900121/* GPIO KEY */
122#define GPIO_KEY(c, g, d, ...) \
123 { .code = c, .gpio = g, .desc = d, .active_low = 1 }
124
Simon Hormana6014692013-07-26 17:53:42 +0900125static struct gpio_keys_button gpio_buttons[] = {
Simon Hormanc3842e42013-05-13 16:04:31 +0900126 GPIO_KEY(KEY_4, RCAR_GP_PIN(1, 28), "SW2-pin4"),
127 GPIO_KEY(KEY_3, RCAR_GP_PIN(1, 26), "SW2-pin3"),
128 GPIO_KEY(KEY_2, RCAR_GP_PIN(1, 24), "SW2-pin2"),
129 GPIO_KEY(KEY_1, RCAR_GP_PIN(1, 14), "SW2-pin1"),
130};
131
Laurent Pinchart27113d62013-08-08 00:43:00 +0200132static const struct gpio_keys_platform_data lager_keys_pdata __initconst = {
Simon Hormanc3842e42013-05-13 16:04:31 +0900133 .buttons = gpio_buttons,
134 .nbuttons = ARRAY_SIZE(gpio_buttons),
135};
136
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +0200137/* Fixed 3.3V regulator to be used by MMCIF */
138static struct regulator_consumer_supply fixed3v3_power_consumers[] =
139{
140 REGULATOR_SUPPLY("vmmc", "sh_mmcif.1"),
141};
142
143/* MMCIF */
Laurent Pinchart27113d62013-08-08 00:43:00 +0200144static const struct sh_mmcif_plat_data mmcif1_pdata __initconst = {
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +0200145 .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE,
Guennadi Liakhovetskib77c6bc2013-07-10 21:21:17 +0200146 .clk_ctrl2_present = true,
147 .ccs_unsupported = true,
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +0200148};
149
Laurent Pinchart27113d62013-08-08 00:43:00 +0200150static const struct resource mmcif1_resources[] __initconst = {
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +0200151 DEFINE_RES_MEM_NAMED(0xee220000, 0x80, "MMCIF1"),
152 DEFINE_RES_IRQ(gic_spi(170)),
153};
154
Simon Horman4901e132013-08-06 16:50:10 +0900155/* Ether */
Laurent Pinchart27113d62013-08-08 00:43:00 +0200156static const struct sh_eth_plat_data ether_pdata __initconst = {
Simon Horman4901e132013-08-06 16:50:10 +0900157 .phy = 0x1,
158 .edmac_endian = EDMAC_LITTLE_ENDIAN,
Simon Horman4901e132013-08-06 16:50:10 +0900159 .phy_interface = PHY_INTERFACE_MODE_RMII,
160 .ether_link_active_low = 1,
161};
162
Laurent Pinchart27113d62013-08-08 00:43:00 +0200163static const struct resource ether_resources[] __initconst = {
Simon Horman4901e132013-08-06 16:50:10 +0900164 DEFINE_RES_MEM(0xee700000, 0x400),
165 DEFINE_RES_IRQ(gic_spi(162)),
166};
167
Laurent Pincharte3a28ac2013-04-08 11:36:22 +0200168static const struct pinctrl_map lager_pinctrl_map[] = {
Laurent Pinchartc75a5af2013-04-16 12:39:11 +0200169 /* DU (CN10: ARGB0, CN13: LVDS) */
170 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
171 "du_rgb666", "du"),
172 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
173 "du_sync_1", "du"),
174 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
175 "du_clk_out_0", "du"),
Laurent Pincharte3a28ac2013-04-08 11:36:22 +0200176 /* SCIF0 (CN19: DEBUG SERIAL0) */
177 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.6", "pfc-r8a7790",
178 "scif0_data", "scif0"),
179 /* SCIF1 (CN20: DEBUG SERIAL1) */
180 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.7", "pfc-r8a7790",
181 "scif1_data", "scif1"),
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +0200182 /* MMCIF1 */
183 PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.1", "pfc-r8a7790",
184 "mmc1_data8", "mmc1"),
185 PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.1", "pfc-r8a7790",
186 "mmc1_ctrl", "mmc1"),
Simon Horman4901e132013-08-06 16:50:10 +0900187 /* Ether */
188 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
189 "eth_link", "eth"),
190 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
191 "eth_mdio", "eth"),
192 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
193 "eth_rmii", "eth"),
194 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
195 "intc_irq0", "intc"),
Laurent Pincharte3a28ac2013-04-08 11:36:22 +0200196};
197
Magnus Damm3cc828f2013-03-29 17:49:37 +0900198static void __init lager_add_standard_devices(void)
199{
200 r8a7790_clock_init();
Laurent Pincharte3a28ac2013-04-08 11:36:22 +0200201
202 pinctrl_register_mappings(lager_pinctrl_map,
203 ARRAY_SIZE(lager_pinctrl_map));
204 r8a7790_pinmux_init();
205
Magnus Damm3cc828f2013-03-29 17:49:37 +0900206 r8a7790_add_standard_devices();
Simon Horman1034f4e2013-04-23 02:37:05 +0000207 platform_device_register_data(&platform_bus, "leds-gpio", -1,
208 &lager_leds_pdata,
209 sizeof(lager_leds_pdata));
Simon Hormanc3842e42013-05-13 16:04:31 +0900210 platform_device_register_data(&platform_bus, "gpio-keys", -1,
211 &lager_keys_pdata,
212 sizeof(lager_keys_pdata));
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +0200213 regulator_register_always_on(0, "fixed-3.3V", fixed3v3_power_consumers,
214 ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
215 platform_device_register_resndata(&platform_bus, "sh_mmcif", 1,
216 mmcif1_resources, ARRAY_SIZE(mmcif1_resources),
217 &mmcif1_pdata, sizeof(mmcif1_pdata));
Simon Horman4901e132013-08-06 16:50:10 +0900218
219 platform_device_register_resndata(&platform_bus, "r8a7790-ether", -1,
220 ether_resources,
221 ARRAY_SIZE(ether_resources),
222 &ether_pdata, sizeof(ether_pdata));
Laurent Pinchartc75a5af2013-04-16 12:39:11 +0200223
224 lager_add_du_device();
Magnus Damm3cc828f2013-03-29 17:49:37 +0900225}
226
Sergei Shtylyov48c8b962013-09-14 04:29:22 +0400227/*
228 * Ether LEDs on the Lager board are named LINK and ACTIVE which corresponds
229 * to non-default 01 setting of the Micrel KSZ8041 PHY control register 1 bits
230 * 14-15. We have to set them back to 01 from the default 00 value each time
231 * the PHY is reset. It's also important because the PHY's LED0 signal is
232 * connected to SoC's ETH_LINK signal and in the PHY's default mode it will
233 * bounce on and off after each packet, which we apparently want to avoid.
234 */
235static int lager_ksz8041_fixup(struct phy_device *phydev)
236{
237 u16 phyctrl1 = phy_read(phydev, 0x1e);
238
239 phyctrl1 &= ~0xc000;
240 phyctrl1 |= 0x4000;
241 return phy_write(phydev, 0x1e, phyctrl1);
242}
243
244static void __init lager_init(void)
245{
246 lager_add_standard_devices();
247
Simon Horman6802cdc52013-11-06 09:41:09 +0900248 if (IS_ENABLED(CONFIG_PHYLIB))
249 phy_register_fixup_for_id("r8a7790-ether-ff:01",
250 lager_ksz8041_fixup);
Sergei Shtylyov48c8b962013-09-14 04:29:22 +0400251}
252
Laurent Pinchart27113d62013-08-08 00:43:00 +0200253static const char * const lager_boards_compat_dt[] __initconst = {
Magnus Damm3cc828f2013-03-29 17:49:37 +0900254 "renesas,lager",
255 NULL,
256};
257
258DT_MACHINE_START(LAGER_DT, "lager")
Magnus Dammad09cb82013-08-29 08:22:07 +0900259 .smp = smp_ops(r8a7790_smp_ops),
Magnus Damm0efd7fa2013-08-08 07:27:01 +0900260 .init_early = r8a7790_init_early,
Magnus Damm50c517d2013-09-12 09:32:49 +0900261 .init_time = rcar_gen2_timer_init,
Sergei Shtylyov48c8b962013-09-14 04:29:22 +0400262 .init_machine = lager_init,
Magnus Damm3cc828f2013-03-29 17:49:37 +0900263 .dt_compat = lager_boards_compat_dt,
264MACHINE_END