Hisashi Nakamura | 1f52c65 | 2013-09-04 12:46:49 +0900 | [diff] [blame] | 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 | |
Laurent Pinchart | 784c33a | 2013-12-07 02:17:44 +0100 | [diff] [blame] | 22 | #include <linux/dma-mapping.h> |
Magnus Damm | 721319d | 2013-10-08 12:40:08 +0900 | [diff] [blame] | 23 | #include <linux/gpio.h> |
| 24 | #include <linux/gpio_keys.h> |
| 25 | #include <linux/input.h> |
Hisashi Nakamura | 1f52c65 | 2013-09-04 12:46:49 +0900 | [diff] [blame] | 26 | #include <linux/kernel.h> |
Magnus Damm | 87a2934 | 2013-10-08 12:39:59 +0900 | [diff] [blame] | 27 | #include <linux/leds.h> |
Sergei Shtylyov | 974faba | 2013-12-08 23:52:44 +0300 | [diff] [blame] | 28 | #include <linux/phy.h> |
Magnus Damm | 85ef14d | 2013-11-20 16:41:48 +0900 | [diff] [blame] | 29 | #include <linux/pinctrl/machine.h> |
Magnus Damm | 87a2934 | 2013-10-08 12:39:59 +0900 | [diff] [blame] | 30 | #include <linux/platform_data/gpio-rcar.h> |
Laurent Pinchart | 784c33a | 2013-12-07 02:17:44 +0100 | [diff] [blame] | 31 | #include <linux/platform_data/rcar-du.h> |
Hisashi Nakamura | 1f52c65 | 2013-09-04 12:46:49 +0900 | [diff] [blame] | 32 | #include <linux/platform_device.h> |
Sergei Shtylyov | 974faba | 2013-12-08 23:52:44 +0300 | [diff] [blame] | 33 | #include <linux/sh_eth.h> |
Hisashi Nakamura | 1f52c65 | 2013-09-04 12:46:49 +0900 | [diff] [blame] | 34 | #include <mach/common.h> |
Laurent Pinchart | 784c33a | 2013-12-07 02:17:44 +0100 | [diff] [blame] | 35 | #include <mach/irqs.h> |
Hisashi Nakamura | 1f52c65 | 2013-09-04 12:46:49 +0900 | [diff] [blame] | 36 | #include <mach/r8a7791.h> |
Magnus Damm | f9c9eb7 | 2013-10-01 17:12:57 +0900 | [diff] [blame] | 37 | #include <mach/rcar-gen2.h> |
Hisashi Nakamura | 1f52c65 | 2013-09-04 12:46:49 +0900 | [diff] [blame] | 38 | #include <asm/mach-types.h> |
| 39 | #include <asm/mach/arch.h> |
| 40 | |
Laurent Pinchart | 784c33a | 2013-12-07 02:17:44 +0100 | [diff] [blame] | 41 | /* DU */ |
| 42 | static struct rcar_du_encoder_data koelsch_du_encoders[] = { |
| 43 | { |
| 44 | .type = RCAR_DU_ENCODER_NONE, |
| 45 | .output = RCAR_DU_OUTPUT_LVDS0, |
| 46 | .connector.lvds.panel = { |
| 47 | .width_mm = 210, |
| 48 | .height_mm = 158, |
| 49 | .mode = { |
| 50 | .clock = 65000, |
| 51 | .hdisplay = 1024, |
| 52 | .hsync_start = 1048, |
| 53 | .hsync_end = 1184, |
| 54 | .htotal = 1344, |
| 55 | .vdisplay = 768, |
| 56 | .vsync_start = 771, |
| 57 | .vsync_end = 777, |
| 58 | .vtotal = 806, |
| 59 | .flags = 0, |
| 60 | }, |
| 61 | }, |
| 62 | }, |
| 63 | }; |
| 64 | |
| 65 | static const struct rcar_du_platform_data koelsch_du_pdata __initconst = { |
| 66 | .encoders = koelsch_du_encoders, |
| 67 | .num_encoders = ARRAY_SIZE(koelsch_du_encoders), |
| 68 | }; |
| 69 | |
| 70 | static const struct resource du_resources[] __initconst = { |
| 71 | DEFINE_RES_MEM(0xfeb00000, 0x40000), |
| 72 | DEFINE_RES_MEM_NAMED(0xfeb90000, 0x1c, "lvds.0"), |
| 73 | DEFINE_RES_IRQ(gic_spi(256)), |
| 74 | DEFINE_RES_IRQ(gic_spi(268)), |
| 75 | }; |
| 76 | |
| 77 | static void __init koelsch_add_du_device(void) |
| 78 | { |
| 79 | struct platform_device_info info = { |
| 80 | .name = "rcar-du-r8a7791", |
| 81 | .id = -1, |
| 82 | .res = du_resources, |
| 83 | .num_res = ARRAY_SIZE(du_resources), |
| 84 | .data = &koelsch_du_pdata, |
| 85 | .size_data = sizeof(koelsch_du_pdata), |
| 86 | .dma_mask = DMA_BIT_MASK(32), |
| 87 | }; |
| 88 | |
| 89 | platform_device_register_full(&info); |
| 90 | } |
| 91 | |
Sergei Shtylyov | 974faba | 2013-12-08 23:52:44 +0300 | [diff] [blame] | 92 | /* Ether */ |
| 93 | static const struct sh_eth_plat_data ether_pdata __initconst = { |
| 94 | .phy = 0x1, |
| 95 | .edmac_endian = EDMAC_LITTLE_ENDIAN, |
| 96 | .phy_interface = PHY_INTERFACE_MODE_RMII, |
| 97 | .ether_link_active_low = 1, |
| 98 | }; |
| 99 | |
| 100 | static const struct resource ether_resources[] __initconst = { |
| 101 | DEFINE_RES_MEM(0xee700000, 0x400), |
| 102 | DEFINE_RES_IRQ(gic_spi(162)), |
| 103 | }; |
| 104 | |
Magnus Damm | 87a2934 | 2013-10-08 12:39:59 +0900 | [diff] [blame] | 105 | /* LEDS */ |
| 106 | static struct gpio_led koelsch_leds[] = { |
| 107 | { |
| 108 | .name = "led8", |
| 109 | .gpio = RCAR_GP_PIN(2, 21), |
| 110 | .default_state = LEDS_GPIO_DEFSTATE_ON, |
| 111 | }, { |
| 112 | .name = "led7", |
| 113 | .gpio = RCAR_GP_PIN(2, 20), |
| 114 | .default_state = LEDS_GPIO_DEFSTATE_ON, |
| 115 | }, { |
| 116 | .name = "led6", |
| 117 | .gpio = RCAR_GP_PIN(2, 19), |
| 118 | .default_state = LEDS_GPIO_DEFSTATE_ON, |
| 119 | }, |
| 120 | }; |
| 121 | |
| 122 | static const struct gpio_led_platform_data koelsch_leds_pdata __initconst = { |
| 123 | .leds = koelsch_leds, |
| 124 | .num_leds = ARRAY_SIZE(koelsch_leds), |
| 125 | }; |
| 126 | |
Magnus Damm | 721319d | 2013-10-08 12:40:08 +0900 | [diff] [blame] | 127 | /* GPIO KEY */ |
| 128 | #define GPIO_KEY(c, g, d, ...) \ |
Simon Horman | 478e2f9 | 2013-10-29 17:57:31 +0900 | [diff] [blame] | 129 | { .code = c, .gpio = g, .desc = d, .active_low = 1, \ |
Magnus Damm | e209456 | 2013-11-20 12:56:38 +0900 | [diff] [blame] | 130 | .wakeup = 1, .debounce_interval = 20 } |
Magnus Damm | 721319d | 2013-10-08 12:40:08 +0900 | [diff] [blame] | 131 | |
| 132 | static struct gpio_keys_button gpio_buttons[] = { |
| 133 | GPIO_KEY(KEY_4, RCAR_GP_PIN(5, 3), "SW2-pin4"), |
| 134 | GPIO_KEY(KEY_3, RCAR_GP_PIN(5, 2), "SW2-pin3"), |
| 135 | GPIO_KEY(KEY_2, RCAR_GP_PIN(5, 1), "SW2-pin2"), |
| 136 | GPIO_KEY(KEY_1, RCAR_GP_PIN(5, 0), "SW2-pin1"), |
Magnus Damm | 159a282 | 2013-11-20 13:00:10 +0900 | [diff] [blame] | 137 | GPIO_KEY(KEY_G, RCAR_GP_PIN(7, 6), "SW36"), |
| 138 | GPIO_KEY(KEY_F, RCAR_GP_PIN(7, 5), "SW35"), |
| 139 | GPIO_KEY(KEY_E, RCAR_GP_PIN(7, 4), "SW34"), |
| 140 | GPIO_KEY(KEY_D, RCAR_GP_PIN(7, 3), "SW33"), |
| 141 | GPIO_KEY(KEY_C, RCAR_GP_PIN(7, 2), "SW32"), |
| 142 | GPIO_KEY(KEY_B, RCAR_GP_PIN(7, 1), "SW31"), |
| 143 | GPIO_KEY(KEY_A, RCAR_GP_PIN(7, 0), "SW30"), |
Magnus Damm | 721319d | 2013-10-08 12:40:08 +0900 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | static const struct gpio_keys_platform_data koelsch_keys_pdata __initconst = { |
| 147 | .buttons = gpio_buttons, |
| 148 | .nbuttons = ARRAY_SIZE(gpio_buttons), |
| 149 | }; |
| 150 | |
Magnus Damm | 85ef14d | 2013-11-20 16:41:48 +0900 | [diff] [blame] | 151 | static const struct pinctrl_map koelsch_pinctrl_map[] = { |
Laurent Pinchart | 784c33a | 2013-12-07 02:17:44 +0100 | [diff] [blame] | 152 | /* DU */ |
| 153 | PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791", |
| 154 | "du_rgb666", "du"), |
| 155 | PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791", |
| 156 | "du_sync", "du"), |
| 157 | PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791", |
| 158 | "du_clk_out_0", "du"), |
Sergei Shtylyov | 974faba | 2013-12-08 23:52:44 +0300 | [diff] [blame] | 159 | /* Ether */ |
| 160 | PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791", |
| 161 | "eth_link", "eth"), |
| 162 | PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791", |
| 163 | "eth_mdio", "eth"), |
| 164 | PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791", |
| 165 | "eth_rmii", "eth"), |
| 166 | PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791", |
| 167 | "intc_irq0", "intc"), |
Magnus Damm | 85ef14d | 2013-11-20 16:41:48 +0900 | [diff] [blame] | 168 | /* SCIF0 (CN19: DEBUG SERIAL0) */ |
| 169 | PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.6", "pfc-r8a7791", |
| 170 | "scif0_data_d", "scif0"), |
| 171 | /* SCIF1 (CN20: DEBUG SERIAL1) */ |
| 172 | PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.7", "pfc-r8a7791", |
| 173 | "scif1_data_d", "scif1"), |
| 174 | }; |
| 175 | |
Hisashi Nakamura | 1f52c65 | 2013-09-04 12:46:49 +0900 | [diff] [blame] | 176 | static void __init koelsch_add_standard_devices(void) |
| 177 | { |
| 178 | r8a7791_clock_init(); |
Magnus Damm | 85ef14d | 2013-11-20 16:41:48 +0900 | [diff] [blame] | 179 | pinctrl_register_mappings(koelsch_pinctrl_map, |
| 180 | ARRAY_SIZE(koelsch_pinctrl_map)); |
Magnus Damm | 1a534ec | 2013-10-08 12:39:49 +0900 | [diff] [blame] | 181 | r8a7791_pinmux_init(); |
Magnus Damm | 0749bea | 2013-10-01 17:12:02 +0900 | [diff] [blame] | 182 | r8a7791_add_standard_devices(); |
Sergei Shtylyov | 974faba | 2013-12-08 23:52:44 +0300 | [diff] [blame] | 183 | platform_device_register_resndata(&platform_bus, "r8a7791-ether", -1, |
| 184 | ether_resources, |
| 185 | ARRAY_SIZE(ether_resources), |
| 186 | ðer_pdata, sizeof(ether_pdata)); |
Magnus Damm | 87a2934 | 2013-10-08 12:39:59 +0900 | [diff] [blame] | 187 | platform_device_register_data(&platform_bus, "leds-gpio", -1, |
| 188 | &koelsch_leds_pdata, |
| 189 | sizeof(koelsch_leds_pdata)); |
Magnus Damm | 721319d | 2013-10-08 12:40:08 +0900 | [diff] [blame] | 190 | platform_device_register_data(&platform_bus, "gpio-keys", -1, |
| 191 | &koelsch_keys_pdata, |
| 192 | sizeof(koelsch_keys_pdata)); |
Laurent Pinchart | 784c33a | 2013-12-07 02:17:44 +0100 | [diff] [blame] | 193 | |
| 194 | koelsch_add_du_device(); |
Hisashi Nakamura | 1f52c65 | 2013-09-04 12:46:49 +0900 | [diff] [blame] | 195 | } |
| 196 | |
Sergei Shtylyov | 974faba | 2013-12-08 23:52:44 +0300 | [diff] [blame] | 197 | /* |
| 198 | * Ether LEDs on the Koelsch board are named LINK and ACTIVE which corresponds |
| 199 | * to non-default 01 setting of the Micrel KSZ8041 PHY control register 1 bits |
| 200 | * 14-15. We have to set them back to 01 from the default 00 value each time |
| 201 | * the PHY is reset. It's also important because the PHY's LED0 signal is |
| 202 | * connected to SoC's ETH_LINK signal and in the PHY's default mode it will |
| 203 | * bounce on and off after each packet, which we apparently want to avoid. |
| 204 | */ |
| 205 | static int koelsch_ksz8041_fixup(struct phy_device *phydev) |
| 206 | { |
| 207 | u16 phyctrl1 = phy_read(phydev, 0x1e); |
| 208 | |
| 209 | phyctrl1 &= ~0xc000; |
| 210 | phyctrl1 |= 0x4000; |
| 211 | return phy_write(phydev, 0x1e, phyctrl1); |
| 212 | } |
| 213 | |
| 214 | static void __init koelsch_init(void) |
| 215 | { |
| 216 | koelsch_add_standard_devices(); |
| 217 | |
| 218 | if (IS_ENABLED(CONFIG_PHYLIB)) |
| 219 | phy_register_fixup_for_id("r8a7791-ether-ff:01", |
| 220 | koelsch_ksz8041_fixup); |
| 221 | } |
| 222 | |
Hisashi Nakamura | 1f52c65 | 2013-09-04 12:46:49 +0900 | [diff] [blame] | 223 | static const char * const koelsch_boards_compat_dt[] __initconst = { |
| 224 | "renesas,koelsch", |
| 225 | NULL, |
| 226 | }; |
| 227 | |
| 228 | DT_MACHINE_START(KOELSCH_DT, "koelsch") |
Magnus Damm | b6d5a1b | 2013-10-01 17:13:26 +0900 | [diff] [blame] | 229 | .smp = smp_ops(r8a7791_smp_ops), |
Hisashi Nakamura | 1f52c65 | 2013-09-04 12:46:49 +0900 | [diff] [blame] | 230 | .init_early = r8a7791_init_early, |
Magnus Damm | f9c9eb7 | 2013-10-01 17:12:57 +0900 | [diff] [blame] | 231 | .init_time = rcar_gen2_timer_init, |
Sergei Shtylyov | 974faba | 2013-12-08 23:52:44 +0300 | [diff] [blame] | 232 | .init_machine = koelsch_init, |
Magnus Damm | 6dc00ab | 2013-11-20 12:54:34 +0900 | [diff] [blame] | 233 | .init_late = shmobile_init_late, |
Hisashi Nakamura | 1f52c65 | 2013-09-04 12:46:49 +0900 | [diff] [blame] | 234 | .dt_compat = koelsch_boards_compat_dt, |
| 235 | MACHINE_END |