board-lager.c 5.8 KB

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