blob: f20c10a18543973c3d5797d83e8ac4bae26c8708 [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>
Kuninori Morimotobe0647d2013-12-04 22:11:06 -080034#include <linux/regulator/driver.h>
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +020035#include <linux/regulator/fixed.h>
Kuninori Morimotobe0647d2013-12-04 22:11:06 -080036#include <linux/regulator/gpio-regulator.h>
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +020037#include <linux/regulator/machine.h>
Simon Horman4901e132013-08-06 16:50:10 +090038#include <linux/sh_eth.h>
Magnus Damm3cc828f2013-03-29 17:49:37 +090039#include <mach/common.h>
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +020040#include <mach/irqs.h>
Magnus Damm3cc828f2013-03-29 17:49:37 +090041#include <mach/r8a7790.h>
42#include <asm/mach-types.h>
43#include <asm/mach/arch.h>
Hiep Cao Minh24cf82f2013-10-22 11:21:12 +090044#include <linux/mtd/partitions.h>
45#include <linux/mtd/mtd.h>
46#include <linux/spi/flash.h>
47#include <linux/spi/rspi.h>
48#include <linux/spi/spi.h>
Magnus Damm3cc828f2013-03-29 17:49:37 +090049
Laurent Pinchartc75a5af2013-04-16 12:39:11 +020050/* DU */
51static struct rcar_du_encoder_data lager_du_encoders[] = {
52 {
53 .type = RCAR_DU_ENCODER_VGA,
54 .output = RCAR_DU_OUTPUT_DPAD0,
55 }, {
56 .type = RCAR_DU_ENCODER_NONE,
57 .output = RCAR_DU_OUTPUT_LVDS1,
58 .connector.lvds.panel = {
59 .width_mm = 210,
60 .height_mm = 158,
61 .mode = {
62 .clock = 65000,
63 .hdisplay = 1024,
64 .hsync_start = 1048,
65 .hsync_end = 1184,
66 .htotal = 1344,
67 .vdisplay = 768,
68 .vsync_start = 771,
69 .vsync_end = 777,
70 .vtotal = 806,
71 .flags = 0,
72 },
73 },
74 },
75};
76
77static const struct rcar_du_platform_data lager_du_pdata __initconst = {
78 .encoders = lager_du_encoders,
79 .num_encoders = ARRAY_SIZE(lager_du_encoders),
80};
81
82static const struct resource du_resources[] __initconst = {
83 DEFINE_RES_MEM(0xfeb00000, 0x70000),
84 DEFINE_RES_MEM_NAMED(0xfeb90000, 0x1c, "lvds.0"),
85 DEFINE_RES_MEM_NAMED(0xfeb94000, 0x1c, "lvds.1"),
86 DEFINE_RES_IRQ(gic_spi(256)),
87 DEFINE_RES_IRQ(gic_spi(268)),
88 DEFINE_RES_IRQ(gic_spi(269)),
89};
90
91static void __init lager_add_du_device(void)
92{
93 struct platform_device_info info = {
94 .name = "rcar-du-r8a7790",
95 .id = -1,
96 .res = du_resources,
97 .num_res = ARRAY_SIZE(du_resources),
Laurent Pinchart37bf8102013-08-22 17:55:08 +020098 .data = &lager_du_pdata,
99 .size_data = sizeof(lager_du_pdata),
Laurent Pinchartc75a5af2013-04-16 12:39:11 +0200100 .dma_mask = DMA_BIT_MASK(32),
101 };
102
103 platform_device_register_full(&info);
104}
105
Simon Horman1034f4e2013-04-23 02:37:05 +0000106/* LEDS */
107static struct gpio_led lager_leds[] = {
108 {
109 .name = "led8",
110 .gpio = RCAR_GP_PIN(5, 17),
111 .default_state = LEDS_GPIO_DEFSTATE_ON,
112 }, {
113 .name = "led7",
114 .gpio = RCAR_GP_PIN(4, 23),
115 .default_state = LEDS_GPIO_DEFSTATE_ON,
116 }, {
117 .name = "led6",
118 .gpio = RCAR_GP_PIN(4, 22),
119 .default_state = LEDS_GPIO_DEFSTATE_ON,
120 },
121};
122
Laurent Pinchart27113d62013-08-08 00:43:00 +0200123static const struct gpio_led_platform_data lager_leds_pdata __initconst = {
Simon Horman1034f4e2013-04-23 02:37:05 +0000124 .leds = lager_leds,
125 .num_leds = ARRAY_SIZE(lager_leds),
126};
127
Simon Hormanc3842e42013-05-13 16:04:31 +0900128/* GPIO KEY */
129#define GPIO_KEY(c, g, d, ...) \
Shinya Kuribayashic9fd77d2013-10-29 17:57:30 +0900130 { .code = c, .gpio = g, .desc = d, .active_low = 1, \
Shinya Kuribayashie0554d92013-11-14 07:40:26 +0900131 .wakeup = 1, .debounce_interval = 20 }
Simon Hormanc3842e42013-05-13 16:04:31 +0900132
Simon Hormana6014692013-07-26 17:53:42 +0900133static struct gpio_keys_button gpio_buttons[] = {
Simon Hormanc3842e42013-05-13 16:04:31 +0900134 GPIO_KEY(KEY_4, RCAR_GP_PIN(1, 28), "SW2-pin4"),
135 GPIO_KEY(KEY_3, RCAR_GP_PIN(1, 26), "SW2-pin3"),
136 GPIO_KEY(KEY_2, RCAR_GP_PIN(1, 24), "SW2-pin2"),
137 GPIO_KEY(KEY_1, RCAR_GP_PIN(1, 14), "SW2-pin1"),
138};
139
Laurent Pinchart27113d62013-08-08 00:43:00 +0200140static const struct gpio_keys_platform_data lager_keys_pdata __initconst = {
Simon Hormanc3842e42013-05-13 16:04:31 +0900141 .buttons = gpio_buttons,
142 .nbuttons = ARRAY_SIZE(gpio_buttons),
143};
144
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +0200145/* Fixed 3.3V regulator to be used by MMCIF */
146static struct regulator_consumer_supply fixed3v3_power_consumers[] =
147{
148 REGULATOR_SUPPLY("vmmc", "sh_mmcif.1"),
149};
150
Kuninori Morimotobe0647d2013-12-04 22:11:06 -0800151/*
152 * SDHI regulator macro
153 *
154 ** FIXME**
155 * Lager board vqmmc is provided via DA9063 PMIC chip,
156 * and we should use ${LINK}/drivers/mfd/da9063-* driver for it.
157 * but, it doesn't have regulator support at this point.
158 * It uses gpio-regulator for vqmmc as quick-hack.
159 */
160#define SDHI_REGULATOR(idx, vdd_pin, vccq_pin) \
161static struct regulator_consumer_supply vcc_sdhi##idx##_consumer = \
162 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi." #idx); \
163 \
164static struct regulator_init_data vcc_sdhi##idx##_init_data = { \
165 .constraints = { \
166 .valid_ops_mask = REGULATOR_CHANGE_STATUS, \
167 }, \
168 .consumer_supplies = &vcc_sdhi##idx##_consumer, \
169 .num_consumer_supplies = 1, \
170}; \
171 \
172static const struct fixed_voltage_config vcc_sdhi##idx##_info __initconst = {\
173 .supply_name = "SDHI" #idx "Vcc", \
174 .microvolts = 3300000, \
175 .gpio = vdd_pin, \
176 .enable_high = 1, \
177 .init_data = &vcc_sdhi##idx##_init_data, \
178}; \
179 \
180static struct regulator_consumer_supply vccq_sdhi##idx##_consumer = \
181 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi." #idx); \
182 \
183static struct regulator_init_data vccq_sdhi##idx##_init_data = { \
184 .constraints = { \
185 .input_uV = 3300000, \
186 .min_uV = 1800000, \
187 .max_uV = 3300000, \
188 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | \
189 REGULATOR_CHANGE_STATUS, \
190 }, \
191 .consumer_supplies = &vccq_sdhi##idx##_consumer, \
192 .num_consumer_supplies = 1, \
193}; \
194 \
195static struct gpio vccq_sdhi##idx##_gpio = \
196 { vccq_pin, GPIOF_OUT_INIT_HIGH, "vccq-sdhi" #idx }; \
197 \
198static struct gpio_regulator_state vccq_sdhi##idx##_states[] = { \
199 { .value = 1800000, .gpios = 0 }, \
200 { .value = 3300000, .gpios = 1 }, \
201}; \
202 \
203static const struct gpio_regulator_config vccq_sdhi##idx##_info __initconst = {\
204 .supply_name = "vqmmc", \
205 .gpios = &vccq_sdhi##idx##_gpio, \
206 .nr_gpios = 1, \
207 .states = vccq_sdhi##idx##_states, \
208 .nr_states = ARRAY_SIZE(vccq_sdhi##idx##_states), \
209 .type = REGULATOR_VOLTAGE, \
210 .init_data = &vccq_sdhi##idx##_init_data, \
211};
212
213SDHI_REGULATOR(0, RCAR_GP_PIN(5, 24), RCAR_GP_PIN(5, 29));
214SDHI_REGULATOR(2, RCAR_GP_PIN(5, 25), RCAR_GP_PIN(5, 30));
215
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +0200216/* MMCIF */
Laurent Pinchart27113d62013-08-08 00:43:00 +0200217static const struct sh_mmcif_plat_data mmcif1_pdata __initconst = {
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +0200218 .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE,
Guennadi Liakhovetskib77c6bc2013-07-10 21:21:17 +0200219 .clk_ctrl2_present = true,
220 .ccs_unsupported = true,
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +0200221};
222
Laurent Pinchart27113d62013-08-08 00:43:00 +0200223static const struct resource mmcif1_resources[] __initconst = {
Kuninori Morimotob7b42df2013-10-07 22:58:30 -0700224 DEFINE_RES_MEM(0xee220000, 0x80),
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +0200225 DEFINE_RES_IRQ(gic_spi(170)),
226};
227
Simon Horman4901e132013-08-06 16:50:10 +0900228/* Ether */
Laurent Pinchart27113d62013-08-08 00:43:00 +0200229static const struct sh_eth_plat_data ether_pdata __initconst = {
Simon Horman4901e132013-08-06 16:50:10 +0900230 .phy = 0x1,
231 .edmac_endian = EDMAC_LITTLE_ENDIAN,
Simon Horman4901e132013-08-06 16:50:10 +0900232 .phy_interface = PHY_INTERFACE_MODE_RMII,
233 .ether_link_active_low = 1,
234};
235
Laurent Pinchart27113d62013-08-08 00:43:00 +0200236static const struct resource ether_resources[] __initconst = {
Simon Horman4901e132013-08-06 16:50:10 +0900237 DEFINE_RES_MEM(0xee700000, 0x400),
238 DEFINE_RES_IRQ(gic_spi(162)),
239};
240
Hiep Cao Minh24cf82f2013-10-22 11:21:12 +0900241/* SPI Flash memory (Spansion S25FL512SAGMFIG11 64Mb) */
242static struct mtd_partition spi_flash_part[] = {
243 /* Reserved for user loader program, read-only */
244 {
245 .name = "loader",
246 .offset = 0,
247 .size = SZ_256K,
248 .mask_flags = MTD_WRITEABLE,
249 },
250 /* Reserved for user program, read-only */
251 {
252 .name = "user",
253 .offset = MTDPART_OFS_APPEND,
254 .size = SZ_4M,
255 .mask_flags = MTD_WRITEABLE,
256 },
257 /* All else is writable (e.g. JFFS2) */
258 {
259 .name = "flash",
260 .offset = MTDPART_OFS_APPEND,
261 .size = MTDPART_SIZ_FULL,
262 .mask_flags = 0,
263 },
264};
265
266static struct flash_platform_data spi_flash_data = {
267 .name = "m25p80",
268 .parts = spi_flash_part,
269 .nr_parts = ARRAY_SIZE(spi_flash_part),
270 .type = "s25fl512s",
271};
272
273static const struct rspi_plat_data qspi_pdata __initconst = {
274 .num_chipselect = 1,
275};
276
277static const struct spi_board_info spi_info[] __initconst = {
278 {
279 .modalias = "m25p80",
280 .platform_data = &spi_flash_data,
281 .mode = SPI_MODE_0,
282 .max_speed_hz = 30000000,
283 .bus_num = 0,
284 .chip_select = 0,
285 },
286};
287
288/* QSPI resource */
289static const struct resource qspi_resources[] __initconst = {
290 DEFINE_RES_MEM(0xe6b10000, 0x1000),
291 DEFINE_RES_IRQ(gic_spi(184)),
292};
293
Laurent Pincharte3a28ac2013-04-08 11:36:22 +0200294static const struct pinctrl_map lager_pinctrl_map[] = {
Laurent Pinchartc75a5af2013-04-16 12:39:11 +0200295 /* DU (CN10: ARGB0, CN13: LVDS) */
296 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
297 "du_rgb666", "du"),
298 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
299 "du_sync_1", "du"),
300 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
301 "du_clk_out_0", "du"),
Laurent Pincharte3a28ac2013-04-08 11:36:22 +0200302 /* SCIF0 (CN19: DEBUG SERIAL0) */
303 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.6", "pfc-r8a7790",
304 "scif0_data", "scif0"),
305 /* SCIF1 (CN20: DEBUG SERIAL1) */
306 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.7", "pfc-r8a7790",
307 "scif1_data", "scif1"),
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +0200308 /* MMCIF1 */
309 PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.1", "pfc-r8a7790",
310 "mmc1_data8", "mmc1"),
311 PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.1", "pfc-r8a7790",
312 "mmc1_ctrl", "mmc1"),
Simon Horman4901e132013-08-06 16:50:10 +0900313 /* Ether */
314 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
315 "eth_link", "eth"),
316 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
317 "eth_mdio", "eth"),
318 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
319 "eth_rmii", "eth"),
320 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
321 "intc_irq0", "intc"),
Laurent Pincharte3a28ac2013-04-08 11:36:22 +0200322};
323
Magnus Damm3cc828f2013-03-29 17:49:37 +0900324static void __init lager_add_standard_devices(void)
325{
Kuninori Morimotobe0647d2013-12-04 22:11:06 -0800326 int fixed_regulator_idx = 0;
327 int gpio_regulator_idx = 0;
328
Magnus Damm3cc828f2013-03-29 17:49:37 +0900329 r8a7790_clock_init();
Laurent Pincharte3a28ac2013-04-08 11:36:22 +0200330
331 pinctrl_register_mappings(lager_pinctrl_map,
332 ARRAY_SIZE(lager_pinctrl_map));
333 r8a7790_pinmux_init();
334
Magnus Damm3cc828f2013-03-29 17:49:37 +0900335 r8a7790_add_standard_devices();
Simon Horman1034f4e2013-04-23 02:37:05 +0000336 platform_device_register_data(&platform_bus, "leds-gpio", -1,
337 &lager_leds_pdata,
338 sizeof(lager_leds_pdata));
Simon Hormanc3842e42013-05-13 16:04:31 +0900339 platform_device_register_data(&platform_bus, "gpio-keys", -1,
340 &lager_keys_pdata,
341 sizeof(lager_keys_pdata));
Kuninori Morimotobe0647d2013-12-04 22:11:06 -0800342 regulator_register_always_on(fixed_regulator_idx++,
343 "fixed-3.3V", fixed3v3_power_consumers,
Guennadi Liakhovetski63d05392013-07-08 17:54:43 +0200344 ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
345 platform_device_register_resndata(&platform_bus, "sh_mmcif", 1,
346 mmcif1_resources, ARRAY_SIZE(mmcif1_resources),
347 &mmcif1_pdata, sizeof(mmcif1_pdata));
Simon Horman4901e132013-08-06 16:50:10 +0900348
349 platform_device_register_resndata(&platform_bus, "r8a7790-ether", -1,
350 ether_resources,
351 ARRAY_SIZE(ether_resources),
352 &ether_pdata, sizeof(ether_pdata));
Laurent Pinchartc75a5af2013-04-16 12:39:11 +0200353
354 lager_add_du_device();
Hiep Cao Minh24cf82f2013-10-22 11:21:12 +0900355
356 platform_device_register_resndata(&platform_bus, "qspi", 0,
357 qspi_resources,
358 ARRAY_SIZE(qspi_resources),
359 &qspi_pdata, sizeof(qspi_pdata));
360 spi_register_board_info(spi_info, ARRAY_SIZE(spi_info));
Kuninori Morimotobe0647d2013-12-04 22:11:06 -0800361
362 platform_device_register_data(&platform_bus, "reg-fixed-voltage", fixed_regulator_idx++,
363 &vcc_sdhi0_info, sizeof(struct fixed_voltage_config));
364 platform_device_register_data(&platform_bus, "reg-fixed-voltage", fixed_regulator_idx++,
365 &vcc_sdhi2_info, sizeof(struct fixed_voltage_config));
366
367 platform_device_register_data(&platform_bus, "gpio-regulator", gpio_regulator_idx++,
368 &vccq_sdhi0_info, sizeof(struct gpio_regulator_config));
369 platform_device_register_data(&platform_bus, "gpio-regulator", gpio_regulator_idx++,
370 &vccq_sdhi2_info, sizeof(struct gpio_regulator_config));
Magnus Damm3cc828f2013-03-29 17:49:37 +0900371}
372
Sergei Shtylyov48c8b962013-09-14 04:29:22 +0400373/*
374 * Ether LEDs on the Lager board are named LINK and ACTIVE which corresponds
375 * to non-default 01 setting of the Micrel KSZ8041 PHY control register 1 bits
376 * 14-15. We have to set them back to 01 from the default 00 value each time
377 * the PHY is reset. It's also important because the PHY's LED0 signal is
378 * connected to SoC's ETH_LINK signal and in the PHY's default mode it will
379 * bounce on and off after each packet, which we apparently want to avoid.
380 */
381static int lager_ksz8041_fixup(struct phy_device *phydev)
382{
383 u16 phyctrl1 = phy_read(phydev, 0x1e);
384
385 phyctrl1 &= ~0xc000;
386 phyctrl1 |= 0x4000;
387 return phy_write(phydev, 0x1e, phyctrl1);
388}
389
390static void __init lager_init(void)
391{
392 lager_add_standard_devices();
393
Simon Horman6802cdc52013-11-06 09:41:09 +0900394 if (IS_ENABLED(CONFIG_PHYLIB))
395 phy_register_fixup_for_id("r8a7790-ether-ff:01",
396 lager_ksz8041_fixup);
Sergei Shtylyov48c8b962013-09-14 04:29:22 +0400397}
398
Laurent Pinchart27113d62013-08-08 00:43:00 +0200399static const char * const lager_boards_compat_dt[] __initconst = {
Magnus Damm3cc828f2013-03-29 17:49:37 +0900400 "renesas,lager",
401 NULL,
402};
403
404DT_MACHINE_START(LAGER_DT, "lager")
Magnus Dammad09cb82013-08-29 08:22:07 +0900405 .smp = smp_ops(r8a7790_smp_ops),
Magnus Damm0efd7fa2013-08-08 07:27:01 +0900406 .init_early = r8a7790_init_early,
Magnus Damm50c517d2013-09-12 09:32:49 +0900407 .init_time = rcar_gen2_timer_init,
Sergei Shtylyov48c8b962013-09-14 04:29:22 +0400408 .init_machine = lager_init,
Magnus Damm3fbbcbd2013-11-20 09:02:31 +0900409 .init_late = shmobile_init_late,
Magnus Damm3cc828f2013-03-29 17:49:37 +0900410 .dt_compat = lager_boards_compat_dt,
411MACHINE_END