board-koelsch.c 6.9 KB

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