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