ARM: shmobile: Lager: add Micrel KSZ8041 PHY fixup
[platform/adaptation/renesas_rcar/renesas_kernel.git] / arch / arm / mach-shmobile / board-lager.c
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
21 #include <linux/gpio.h>
22 #include <linux/gpio_keys.h>
23 #include <linux/input.h>
24 #include <linux/interrupt.h>
25 #include <linux/kernel.h>
26 #include <linux/leds.h>
27 #include <linux/mmc/host.h>
28 #include <linux/mmc/sh_mmcif.h>
29 #include <linux/pinctrl/machine.h>
30 #include <linux/platform_data/gpio-rcar.h>
31 #include <linux/platform_device.h>
32 #include <linux/phy.h>
33 #include <linux/regulator/fixed.h>
34 #include <linux/regulator/machine.h>
35 #include <linux/sh_eth.h>
36 #include <mach/common.h>
37 #include <mach/irqs.h>
38 #include <mach/r8a7790.h>
39 #include <asm/mach-types.h>
40 #include <asm/mach/arch.h>
41
42 /* LEDS */
43 static struct gpio_led lager_leds[] = {
44         {
45                 .name           = "led8",
46                 .gpio           = RCAR_GP_PIN(5, 17),
47                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
48         }, {
49                 .name           = "led7",
50                 .gpio           = RCAR_GP_PIN(4, 23),
51                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
52         }, {
53                 .name           = "led6",
54                 .gpio           = RCAR_GP_PIN(4, 22),
55                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
56         },
57 };
58
59 static __initdata struct gpio_led_platform_data lager_leds_pdata = {
60         .leds           = lager_leds,
61         .num_leds       = ARRAY_SIZE(lager_leds),
62 };
63
64 /* GPIO KEY */
65 #define GPIO_KEY(c, g, d, ...) \
66         { .code = c, .gpio = g, .desc = d, .active_low = 1 }
67
68 static struct gpio_keys_button gpio_buttons[] = {
69         GPIO_KEY(KEY_4,         RCAR_GP_PIN(1, 28),     "SW2-pin4"),
70         GPIO_KEY(KEY_3,         RCAR_GP_PIN(1, 26),     "SW2-pin3"),
71         GPIO_KEY(KEY_2,         RCAR_GP_PIN(1, 24),     "SW2-pin2"),
72         GPIO_KEY(KEY_1,         RCAR_GP_PIN(1, 14),     "SW2-pin1"),
73 };
74
75 static __initdata struct gpio_keys_platform_data lager_keys_pdata = {
76         .buttons        = gpio_buttons,
77         .nbuttons       = ARRAY_SIZE(gpio_buttons),
78 };
79
80 /* Fixed 3.3V regulator to be used by MMCIF */
81 static struct regulator_consumer_supply fixed3v3_power_consumers[] =
82 {
83         REGULATOR_SUPPLY("vmmc", "sh_mmcif.1"),
84 };
85
86 /* MMCIF */
87 static struct sh_mmcif_plat_data mmcif1_pdata __initdata = {
88         .caps           = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE,
89 };
90
91 static struct resource mmcif1_resources[] __initdata = {
92         DEFINE_RES_MEM_NAMED(0xee220000, 0x80, "MMCIF1"),
93         DEFINE_RES_IRQ(gic_spi(170)),
94 };
95
96 /* Ether */
97 static struct sh_eth_plat_data ether_pdata __initdata = {
98         .phy                    = 0x1,
99         .edmac_endian           = EDMAC_LITTLE_ENDIAN,
100         .phy_interface          = PHY_INTERFACE_MODE_RMII,
101         .ether_link_active_low  = 1,
102 };
103
104 static struct resource ether_resources[] __initdata = {
105         DEFINE_RES_MEM(0xee700000, 0x400),
106         DEFINE_RES_IRQ(gic_spi(162)),
107 };
108
109 static const struct pinctrl_map lager_pinctrl_map[] = {
110         /* SCIF0 (CN19: DEBUG SERIAL0) */
111         PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.6", "pfc-r8a7790",
112                                   "scif0_data", "scif0"),
113         /* SCIF1 (CN20: DEBUG SERIAL1) */
114         PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.7", "pfc-r8a7790",
115                                   "scif1_data", "scif1"),
116         /* MMCIF1 */
117         PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.1", "pfc-r8a7790",
118                                   "mmc1_data8", "mmc1"),
119         PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.1", "pfc-r8a7790",
120                                   "mmc1_ctrl", "mmc1"),
121         /* Ether */
122         PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
123                                   "eth_link", "eth"),
124         PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
125                                   "eth_mdio", "eth"),
126         PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
127                                   "eth_rmii", "eth"),
128         PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
129                                   "intc_irq0", "intc"),
130 };
131
132 static void __init lager_add_standard_devices(void)
133 {
134         r8a7790_clock_init();
135
136         pinctrl_register_mappings(lager_pinctrl_map,
137                                   ARRAY_SIZE(lager_pinctrl_map));
138         r8a7790_pinmux_init();
139
140         r8a7790_add_standard_devices();
141         platform_device_register_data(&platform_bus, "leds-gpio", -1,
142                                       &lager_leds_pdata,
143                                       sizeof(lager_leds_pdata));
144         platform_device_register_data(&platform_bus, "gpio-keys", -1,
145                                       &lager_keys_pdata,
146                                       sizeof(lager_keys_pdata));
147         regulator_register_always_on(0, "fixed-3.3V", fixed3v3_power_consumers,
148                                      ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
149         platform_device_register_resndata(&platform_bus, "sh_mmcif", 1,
150                                           mmcif1_resources, ARRAY_SIZE(mmcif1_resources),
151                                           &mmcif1_pdata, sizeof(mmcif1_pdata));
152
153         platform_device_register_resndata(&platform_bus, "r8a7790-ether", -1,
154                                           ether_resources,
155                                           ARRAY_SIZE(ether_resources),
156                                           &ether_pdata, sizeof(ether_pdata));
157 }
158
159 /*
160  * Ether LEDs on the Lager board are named LINK and ACTIVE which corresponds
161  * to non-default 01 setting of the Micrel KSZ8041 PHY control register 1 bits
162  * 14-15. We have to set them back to 01 from the default 00 value each time
163  * the PHY is reset. It's also important because the PHY's LED0 signal is
164  * connected to SoC's ETH_LINK signal and in the PHY's default mode it will
165  * bounce on and off after each packet, which we apparently want to avoid.
166  */
167 static int lager_ksz8041_fixup(struct phy_device *phydev)
168 {
169         u16 phyctrl1 = phy_read(phydev, 0x1e);
170
171         phyctrl1 &= ~0xc000;
172         phyctrl1 |= 0x4000;
173         return phy_write(phydev, 0x1e, phyctrl1);
174 }
175
176 static void __init lager_init(void)
177 {
178         lager_add_standard_devices();
179
180         phy_register_fixup_for_id("r8a7790-ether-ff:01", lager_ksz8041_fixup);
181 }
182
183 static const char *lager_boards_compat_dt[] __initdata = {
184         "renesas,lager",
185         NULL,
186 };
187
188 DT_MACHINE_START(LAGER_DT, "lager")
189         .init_early     = r8a7790_init_delay,
190         .init_time      = r8a7790_timer_init,
191         .init_machine   = lager_init,
192         .dt_compat      = lager_boards_compat_dt,
193 MACHINE_END