ARM: shmobile: mackerel: clk_round_rate() can return a zero to indicate an error
[deliverable/linux.git] / arch / arm / mach-shmobile / board-lager.c
CommitLineData
3cc828fd
MD
1/*
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
c3842e4f
SH
21#include <linux/gpio.h>
22#include <linux/gpio_keys.h>
23#include <linux/input.h>
3cc828fd 24#include <linux/interrupt.h>
3cc828fd 25#include <linux/kernel.h>
1034f4ee 26#include <linux/leds.h>
63d0539e
GL
27#include <linux/mmc/host.h>
28#include <linux/mmc/sh_mmcif.h>
e3a28ac2 29#include <linux/pinctrl/machine.h>
1034f4ee 30#include <linux/platform_data/gpio-rcar.h>
c75a5afa 31#include <linux/platform_data/rcar-du.h>
3cc828fd 32#include <linux/platform_device.h>
48c8b96f 33#include <linux/phy.h>
63d0539e
GL
34#include <linux/regulator/fixed.h>
35#include <linux/regulator/machine.h>
4901e136 36#include <linux/sh_eth.h>
3cc828fd 37#include <mach/common.h>
63d0539e 38#include <mach/irqs.h>
3cc828fd
MD
39#include <mach/r8a7790.h>
40#include <asm/mach-types.h>
41#include <asm/mach/arch.h>
42
c75a5afa
LP
43/* 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),
37bf8103
LP
91 .data = &lager_du_pdata,
92 .size_data = sizeof(lager_du_pdata),
c75a5afa
LP
93 .dma_mask = DMA_BIT_MASK(32),
94 };
95
96 platform_device_register_full(&info);
97}
98
1034f4ee
SH
99/* 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
27113d63 116static const struct gpio_led_platform_data lager_leds_pdata __initconst = {
1034f4ee
SH
117 .leds = lager_leds,
118 .num_leds = ARRAY_SIZE(lager_leds),
119};
120
c3842e4f
SH
121/* GPIO KEY */
122#define GPIO_KEY(c, g, d, ...) \
c9fd77d4 123 { .code = c, .gpio = g, .desc = d, .active_low = 1, \
e0554d90 124 .wakeup = 1, .debounce_interval = 20 }
c3842e4f 125
a6014693 126static struct gpio_keys_button gpio_buttons[] = {
c3842e4f
SH
127 GPIO_KEY(KEY_4, RCAR_GP_PIN(1, 28), "SW2-pin4"),
128 GPIO_KEY(KEY_3, RCAR_GP_PIN(1, 26), "SW2-pin3"),
129 GPIO_KEY(KEY_2, RCAR_GP_PIN(1, 24), "SW2-pin2"),
130 GPIO_KEY(KEY_1, RCAR_GP_PIN(1, 14), "SW2-pin1"),
131};
132
27113d63 133static const struct gpio_keys_platform_data lager_keys_pdata __initconst = {
c3842e4f
SH
134 .buttons = gpio_buttons,
135 .nbuttons = ARRAY_SIZE(gpio_buttons),
136};
137
63d0539e
GL
138/* Fixed 3.3V regulator to be used by MMCIF */
139static struct regulator_consumer_supply fixed3v3_power_consumers[] =
140{
141 REGULATOR_SUPPLY("vmmc", "sh_mmcif.1"),
142};
143
144/* MMCIF */
27113d63 145static const struct sh_mmcif_plat_data mmcif1_pdata __initconst = {
63d0539e 146 .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE,
b77c6bce
GL
147 .clk_ctrl2_present = true,
148 .ccs_unsupported = true,
63d0539e
GL
149};
150
27113d63 151static const struct resource mmcif1_resources[] __initconst = {
b7b42df6 152 DEFINE_RES_MEM(0xee220000, 0x80),
63d0539e
GL
153 DEFINE_RES_IRQ(gic_spi(170)),
154};
155
4901e136 156/* Ether */
27113d63 157static const struct sh_eth_plat_data ether_pdata __initconst = {
4901e136
SH
158 .phy = 0x1,
159 .edmac_endian = EDMAC_LITTLE_ENDIAN,
4901e136
SH
160 .phy_interface = PHY_INTERFACE_MODE_RMII,
161 .ether_link_active_low = 1,
162};
163
27113d63 164static const struct resource ether_resources[] __initconst = {
4901e136
SH
165 DEFINE_RES_MEM(0xee700000, 0x400),
166 DEFINE_RES_IRQ(gic_spi(162)),
167};
168
e3a28ac2 169static const struct pinctrl_map lager_pinctrl_map[] = {
c75a5afa
LP
170 /* DU (CN10: ARGB0, CN13: LVDS) */
171 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
172 "du_rgb666", "du"),
173 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
174 "du_sync_1", "du"),
175 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
176 "du_clk_out_0", "du"),
e3a28ac2
LP
177 /* SCIF0 (CN19: DEBUG SERIAL0) */
178 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.6", "pfc-r8a7790",
179 "scif0_data", "scif0"),
180 /* SCIF1 (CN20: DEBUG SERIAL1) */
181 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.7", "pfc-r8a7790",
182 "scif1_data", "scif1"),
63d0539e
GL
183 /* MMCIF1 */
184 PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.1", "pfc-r8a7790",
185 "mmc1_data8", "mmc1"),
186 PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.1", "pfc-r8a7790",
187 "mmc1_ctrl", "mmc1"),
4901e136
SH
188 /* Ether */
189 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
190 "eth_link", "eth"),
191 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
192 "eth_mdio", "eth"),
193 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
194 "eth_rmii", "eth"),
195 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
196 "intc_irq0", "intc"),
e3a28ac2
LP
197};
198
3cc828fd
MD
199static void __init lager_add_standard_devices(void)
200{
201 r8a7790_clock_init();
e3a28ac2
LP
202
203 pinctrl_register_mappings(lager_pinctrl_map,
204 ARRAY_SIZE(lager_pinctrl_map));
205 r8a7790_pinmux_init();
206
3cc828fd 207 r8a7790_add_standard_devices();
1034f4ee
SH
208 platform_device_register_data(&platform_bus, "leds-gpio", -1,
209 &lager_leds_pdata,
210 sizeof(lager_leds_pdata));
c3842e4f
SH
211 platform_device_register_data(&platform_bus, "gpio-keys", -1,
212 &lager_keys_pdata,
213 sizeof(lager_keys_pdata));
63d0539e
GL
214 regulator_register_always_on(0, "fixed-3.3V", fixed3v3_power_consumers,
215 ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
216 platform_device_register_resndata(&platform_bus, "sh_mmcif", 1,
217 mmcif1_resources, ARRAY_SIZE(mmcif1_resources),
218 &mmcif1_pdata, sizeof(mmcif1_pdata));
4901e136
SH
219
220 platform_device_register_resndata(&platform_bus, "r8a7790-ether", -1,
221 ether_resources,
222 ARRAY_SIZE(ether_resources),
223 &ether_pdata, sizeof(ether_pdata));
c75a5afa
LP
224
225 lager_add_du_device();
3cc828fd
MD
226}
227
48c8b96f
SS
228/*
229 * Ether LEDs on the Lager board are named LINK and ACTIVE which corresponds
230 * to non-default 01 setting of the Micrel KSZ8041 PHY control register 1 bits
231 * 14-15. We have to set them back to 01 from the default 00 value each time
232 * the PHY is reset. It's also important because the PHY's LED0 signal is
233 * connected to SoC's ETH_LINK signal and in the PHY's default mode it will
234 * bounce on and off after each packet, which we apparently want to avoid.
235 */
236static int lager_ksz8041_fixup(struct phy_device *phydev)
237{
238 u16 phyctrl1 = phy_read(phydev, 0x1e);
239
240 phyctrl1 &= ~0xc000;
241 phyctrl1 |= 0x4000;
242 return phy_write(phydev, 0x1e, phyctrl1);
243}
244
245static void __init lager_init(void)
246{
247 lager_add_standard_devices();
248
249 phy_register_fixup_for_id("r8a7790-ether-ff:01", lager_ksz8041_fixup);
250}
251
27113d63 252static const char * const lager_boards_compat_dt[] __initconst = {
3cc828fd
MD
253 "renesas,lager",
254 NULL,
255};
256
257DT_MACHINE_START(LAGER_DT, "lager")
ad09cb83 258 .smp = smp_ops(r8a7790_smp_ops),
0efd7faa 259 .init_early = r8a7790_init_early,
50c517d9 260 .init_time = rcar_gen2_timer_init,
48c8b96f 261 .init_machine = lager_init,
3fbbcbdf 262 .init_late = shmobile_init_late,
3cc828fd
MD
263 .dt_compat = lager_boards_compat_dt,
264MACHINE_END
This page took 0.065259 seconds and 5 git commands to generate.