2741dba74aaa54733be1c7753809d97e0f20c6bb
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-shmobile / board-koelsch.c
1 /*
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
22 #include <linux/dma-mapping.h>
23 #include <linux/gpio.h>
24 #include <linux/gpio_keys.h>
25 #include <linux/input.h>
26 #include <linux/irq.h>
27 #include <linux/kernel.h>
28 #include <linux/leds.h>
29 #include <linux/phy.h>
30 #include <linux/pinctrl/machine.h>
31 #include <linux/platform_data/gpio-rcar.h>
32 #include <linux/platform_data/rcar-du.h>
33 #include <linux/platform_device.h>
34 #include <linux/sh_eth.h>
35 #include <mach/common.h>
36 #include <mach/irqs.h>
37 #include <mach/r8a7791.h>
38 #include <mach/rcar-gen2.h>
39 #include <asm/mach-types.h>
40 #include <asm/mach/arch.h>
41
42 /* DU */
43 static struct rcar_du_encoder_data koelsch_du_encoders[] = {
44         {
45                 .type = RCAR_DU_ENCODER_NONE,
46                 .output = RCAR_DU_OUTPUT_LVDS0,
47                 .connector.lvds.panel = {
48                         .width_mm = 210,
49                         .height_mm = 158,
50                         .mode = {
51                                 .clock = 65000,
52                                 .hdisplay = 1024,
53                                 .hsync_start = 1048,
54                                 .hsync_end = 1184,
55                                 .htotal = 1344,
56                                 .vdisplay = 768,
57                                 .vsync_start = 771,
58                                 .vsync_end = 777,
59                                 .vtotal = 806,
60                                 .flags = 0,
61                         },
62                 },
63         },
64 };
65
66 static const struct rcar_du_platform_data koelsch_du_pdata __initconst = {
67         .encoders = koelsch_du_encoders,
68         .num_encoders = ARRAY_SIZE(koelsch_du_encoders),
69 };
70
71 static const struct resource du_resources[] __initconst = {
72         DEFINE_RES_MEM(0xfeb00000, 0x40000),
73         DEFINE_RES_MEM_NAMED(0xfeb90000, 0x1c, "lvds.0"),
74         DEFINE_RES_IRQ(gic_spi(256)),
75         DEFINE_RES_IRQ(gic_spi(268)),
76 };
77
78 static void __init koelsch_add_du_device(void)
79 {
80         struct platform_device_info info = {
81                 .name = "rcar-du-r8a7791",
82                 .id = -1,
83                 .res = du_resources,
84                 .num_res = ARRAY_SIZE(du_resources),
85                 .data = &koelsch_du_pdata,
86                 .size_data = sizeof(koelsch_du_pdata),
87                 .dma_mask = DMA_BIT_MASK(32),
88         };
89
90         platform_device_register_full(&info);
91 }
92
93 /* Ether */
94 static const struct sh_eth_plat_data ether_pdata __initconst = {
95         .phy                    = 0x1,
96         .phy_irq                = irq_pin(0),
97         .edmac_endian           = EDMAC_LITTLE_ENDIAN,
98         .phy_interface          = PHY_INTERFACE_MODE_RMII,
99         .ether_link_active_low  = 1,
100 };
101
102 static const struct resource ether_resources[] __initconst = {
103         DEFINE_RES_MEM(0xee700000, 0x400),
104         DEFINE_RES_IRQ(gic_spi(162)),
105 };
106
107 /* LEDS */
108 static struct gpio_led koelsch_leds[] = {
109         {
110                 .name           = "led8",
111                 .gpio           = RCAR_GP_PIN(2, 21),
112                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
113         }, {
114                 .name           = "led7",
115                 .gpio           = RCAR_GP_PIN(2, 20),
116                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
117         }, {
118                 .name           = "led6",
119                 .gpio           = RCAR_GP_PIN(2, 19),
120                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
121         },
122 };
123
124 static const struct gpio_led_platform_data koelsch_leds_pdata __initconst = {
125         .leds           = koelsch_leds,
126         .num_leds       = ARRAY_SIZE(koelsch_leds),
127 };
128
129 /* GPIO KEY */
130 #define GPIO_KEY(c, g, d, ...) \
131         { .code = c, .gpio = g, .desc = d, .active_low = 1, \
132           .wakeup = 1, .debounce_interval = 20 }
133
134 static struct gpio_keys_button gpio_buttons[] = {
135         GPIO_KEY(KEY_4,         RCAR_GP_PIN(5, 3),      "SW2-pin4"),
136         GPIO_KEY(KEY_3,         RCAR_GP_PIN(5, 2),      "SW2-pin3"),
137         GPIO_KEY(KEY_2,         RCAR_GP_PIN(5, 1),      "SW2-pin2"),
138         GPIO_KEY(KEY_1,         RCAR_GP_PIN(5, 0),      "SW2-pin1"),
139         GPIO_KEY(KEY_G,         RCAR_GP_PIN(7, 6),      "SW36"),
140         GPIO_KEY(KEY_F,         RCAR_GP_PIN(7, 5),      "SW35"),
141         GPIO_KEY(KEY_E,         RCAR_GP_PIN(7, 4),      "SW34"),
142         GPIO_KEY(KEY_D,         RCAR_GP_PIN(7, 3),      "SW33"),
143         GPIO_KEY(KEY_C,         RCAR_GP_PIN(7, 2),      "SW32"),
144         GPIO_KEY(KEY_B,         RCAR_GP_PIN(7, 1),      "SW31"),
145         GPIO_KEY(KEY_A,         RCAR_GP_PIN(7, 0),      "SW30"),
146 };
147
148 static const struct gpio_keys_platform_data koelsch_keys_pdata __initconst = {
149         .buttons        = gpio_buttons,
150         .nbuttons       = ARRAY_SIZE(gpio_buttons),
151 };
152
153 /* SATA0 */
154 static const struct resource sata0_resources[] __initconst = {
155         DEFINE_RES_MEM(0xee300000, 0x2000),
156         DEFINE_RES_IRQ(gic_spi(105)),
157 };
158
159 static const struct platform_device_info sata0_info __initconst = {
160         .parent         = &platform_bus,
161         .name           = "sata-r8a7791",
162         .id             = 0,
163         .res            = sata0_resources,
164         .num_res        = ARRAY_SIZE(sata0_resources),
165         .dma_mask       = DMA_BIT_MASK(32),
166 };
167
168 /* I2C */
169 static const struct resource i2c_resources[] __initconst = {
170         /* I2C0 */
171         DEFINE_RES_MEM(0xE6508000, 0x40),
172         DEFINE_RES_IRQ(gic_spi(287)),
173         /* I2C1 */
174         DEFINE_RES_MEM(0xE6518000, 0x40),
175         DEFINE_RES_IRQ(gic_spi(288)),
176         /* I2C2 */
177         DEFINE_RES_MEM(0xE6530000, 0x40),
178         DEFINE_RES_IRQ(gic_spi(286)),
179         /* I2C3 */
180         DEFINE_RES_MEM(0xE6540000, 0x40),
181         DEFINE_RES_IRQ(gic_spi(290)),
182         /* I2C4 */
183         DEFINE_RES_MEM(0xE6520000, 0x40),
184         DEFINE_RES_IRQ(gic_spi(19)),
185         /* I2C5 */
186         DEFINE_RES_MEM(0xE6528000, 0x40),
187         DEFINE_RES_IRQ(gic_spi(20)),
188 };
189
190 static void __init koelsch_add_i2c(unsigned idx)
191 {
192         unsigned res_idx = idx * 2;
193
194         BUG_ON(res_idx >= ARRAY_SIZE(i2c_resources));
195
196         platform_device_register_simple("i2c-rcar_gen2", idx,
197                                         i2c_resources + res_idx, 2);
198 }
199
200 static const struct pinctrl_map koelsch_pinctrl_map[] = {
201         /* DU */
202         PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
203                                   "du_rgb666", "du"),
204         PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
205                                   "du_sync", "du"),
206         PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
207                                   "du_clk_out_0", "du"),
208         /* Ether */
209         PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
210                                   "eth_link", "eth"),
211         PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
212                                   "eth_mdio", "eth"),
213         PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
214                                   "eth_rmii", "eth"),
215         PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
216                                   "intc_irq0", "intc"),
217         /* SCIF0 (CN19: DEBUG SERIAL0) */
218         PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.6", "pfc-r8a7791",
219                                   "scif0_data_d", "scif0"),
220         /* SCIF1 (CN20: DEBUG SERIAL1) */
221         PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.7", "pfc-r8a7791",
222                                   "scif1_data_d", "scif1"),
223         /* I2C1 */
224         PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar_gen2.1", "pfc-r8a7791",
225                                   "i2c1_e", "i2c1"),
226         /* I2C2 */
227         PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar_gen2.2", "pfc-r8a7791",
228                                   "i2c2", "i2c2"),
229         /* I2C4 */
230         PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar_gen2.4", "pfc-r8a7791",
231                                   "i2c4_c", "i2c4"),
232 };
233
234 static void __init koelsch_add_standard_devices(void)
235 {
236         r8a7791_clock_init();
237         pinctrl_register_mappings(koelsch_pinctrl_map,
238                                   ARRAY_SIZE(koelsch_pinctrl_map));
239         r8a7791_pinmux_init();
240         r8a7791_add_standard_devices();
241         platform_device_register_resndata(&platform_bus, "r8a7791-ether", -1,
242                                           ether_resources,
243                                           ARRAY_SIZE(ether_resources),
244                                           &ether_pdata, sizeof(ether_pdata));
245         platform_device_register_data(&platform_bus, "leds-gpio", -1,
246                                       &koelsch_leds_pdata,
247                                       sizeof(koelsch_leds_pdata));
248         platform_device_register_data(&platform_bus, "gpio-keys", -1,
249                                       &koelsch_keys_pdata,
250                                       sizeof(koelsch_keys_pdata));
251
252         koelsch_add_du_device();
253
254         platform_device_register_full(&sata0_info);
255
256         koelsch_add_i2c(1);
257         koelsch_add_i2c(2);
258         koelsch_add_i2c(4);
259         koelsch_add_i2c(5);
260 }
261
262 /*
263  * Ether LEDs on the Koelsch board are named LINK and ACTIVE which corresponds
264  * to non-default 01 setting of the Micrel KSZ8041 PHY control register 1 bits
265  * 14-15. We have to set them back to 01 from the default 00 value each time
266  * the PHY is reset. It's also important because the PHY's LED0 signal is
267  * connected to SoC's ETH_LINK signal and in the PHY's default mode it will
268  * bounce on and off after each packet, which we apparently want to avoid.
269  */
270 static int koelsch_ksz8041_fixup(struct phy_device *phydev)
271 {
272         u16 phyctrl1 = phy_read(phydev, 0x1e);
273
274         phyctrl1 &= ~0xc000;
275         phyctrl1 |= 0x4000;
276         return phy_write(phydev, 0x1e, phyctrl1);
277 }
278
279 static void __init koelsch_init(void)
280 {
281         koelsch_add_standard_devices();
282
283         irq_set_irq_type(irq_pin(0), IRQ_TYPE_LEVEL_LOW);
284
285         if (IS_ENABLED(CONFIG_PHYLIB))
286                 phy_register_fixup_for_id("r8a7791-ether-ff:01",
287                                           koelsch_ksz8041_fixup);
288 }
289
290 static const char * const koelsch_boards_compat_dt[] __initconst = {
291         "renesas,koelsch",
292         NULL,
293 };
294
295 DT_MACHINE_START(KOELSCH_DT, "koelsch")
296         .smp            = smp_ops(r8a7791_smp_ops),
297         .init_early     = r8a7791_init_early,
298         .init_time      = rcar_gen2_timer_init,
299         .init_machine   = koelsch_init,
300         .init_late      = shmobile_init_late,
301         .dt_compat      = koelsch_boards_compat_dt,
302 MACHINE_END