board-dnskw.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright 2012 (C), Jamie Lentin <jm@lentin.co.uk>
  3. *
  4. * arch/arm/mach-kirkwood/board-dnskw.c
  5. *
  6. * D-link DNS-320 & DNS-325 NAS Init for drivers not converted to
  7. * flattened device tree yet.
  8. *
  9. * This file is licensed under the terms of the GNU General Public
  10. * License version 2. This program is licensed "as is" without any
  11. * warranty of any kind, whether express or implied.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/ata_platform.h>
  17. #include <linux/mv643xx_eth.h>
  18. #include <linux/of.h>
  19. #include <linux/gpio.h>
  20. #include <linux/input.h>
  21. #include <linux/gpio_keys.h>
  22. #include <linux/gpio-fan.h>
  23. #include <linux/leds.h>
  24. #include <asm/mach-types.h>
  25. #include <asm/mach/arch.h>
  26. #include <asm/mach/map.h>
  27. #include <mach/kirkwood.h>
  28. #include <mach/bridge-regs.h>
  29. #include "common.h"
  30. #include "mpp.h"
  31. static struct mv643xx_eth_platform_data dnskw_ge00_data = {
  32. .phy_addr = MV643XX_ETH_PHY_ADDR(8),
  33. };
  34. static unsigned int dnskw_mpp_config[] __initdata = {
  35. MPP13_UART1_TXD, /* Custom ... */
  36. MPP14_UART1_RXD, /* ... Controller (DNS-320 only) */
  37. MPP20_SATA1_ACTn, /* LED: White Right HDD */
  38. MPP21_SATA0_ACTn, /* LED: White Left HDD */
  39. MPP24_GPIO,
  40. MPP25_GPIO,
  41. MPP26_GPIO, /* LED: Power */
  42. MPP27_GPIO, /* LED: Red Right HDD */
  43. MPP28_GPIO, /* LED: Red Left HDD */
  44. MPP29_GPIO, /* LED: Red USB (DNS-325 only) */
  45. MPP30_GPIO,
  46. MPP31_GPIO,
  47. MPP32_GPIO,
  48. MPP33_GPO,
  49. MPP34_GPIO, /* Button: Front power */
  50. MPP35_GPIO, /* LED: Red USB (DNS-320 only) */
  51. MPP36_GPIO, /* Power: Turn off board */
  52. MPP37_GPIO, /* Power: Turn back on after power failure */
  53. MPP38_GPIO,
  54. MPP39_GPIO, /* Power: SATA0 */
  55. MPP40_GPIO, /* Power: SATA1 */
  56. MPP41_GPIO, /* SATA0 present */
  57. MPP42_GPIO, /* SATA1 present */
  58. MPP43_GPIO, /* LED: White USB */
  59. MPP44_GPIO, /* Fan: Tachometer Pin */
  60. MPP45_GPIO, /* Fan: high speed */
  61. MPP46_GPIO, /* Fan: low speed */
  62. MPP47_GPIO, /* Button: Back unmount */
  63. MPP48_GPIO, /* Button: Back reset */
  64. MPP49_GPIO, /* Temp Alarm (DNS-325) Pin of U5 (DNS-320) */
  65. 0
  66. };
  67. static struct gpio_keys_button dnskw_button_pins[] = {
  68. {
  69. .code = KEY_POWER,
  70. .gpio = 34,
  71. .desc = "Power button",
  72. .active_low = 1,
  73. },
  74. {
  75. .code = KEY_EJECTCD,
  76. .gpio = 47,
  77. .desc = "USB unmount button",
  78. .active_low = 1,
  79. },
  80. {
  81. .code = KEY_RESTART,
  82. .gpio = 48,
  83. .desc = "Reset button",
  84. .active_low = 1,
  85. },
  86. };
  87. static struct gpio_keys_platform_data dnskw_button_data = {
  88. .buttons = dnskw_button_pins,
  89. .nbuttons = ARRAY_SIZE(dnskw_button_pins),
  90. };
  91. static struct platform_device dnskw_button_device = {
  92. .name = "gpio-keys",
  93. .id = -1,
  94. .num_resources = 0,
  95. .dev = {
  96. .platform_data = &dnskw_button_data,
  97. }
  98. };
  99. /* Fan: ADDA AD045HB-G73 40mm 6000rpm@5v */
  100. static struct gpio_fan_speed dnskw_fan_speed[] = {
  101. { 0, 0 },
  102. { 3000, 1 },
  103. { 6000, 2 },
  104. };
  105. static unsigned dnskw_fan_pins[] = {46, 45};
  106. static struct gpio_fan_platform_data dnskw_fan_data = {
  107. .num_ctrl = ARRAY_SIZE(dnskw_fan_pins),
  108. .ctrl = dnskw_fan_pins,
  109. .num_speed = ARRAY_SIZE(dnskw_fan_speed),
  110. .speed = dnskw_fan_speed,
  111. };
  112. static struct platform_device dnskw_fan_device = {
  113. .name = "gpio-fan",
  114. .id = -1,
  115. .dev = {
  116. .platform_data = &dnskw_fan_data,
  117. },
  118. };
  119. static void dnskw_power_off(void)
  120. {
  121. gpio_set_value(36, 1);
  122. }
  123. /* Register any GPIO for output and set the value */
  124. static void __init dnskw_gpio_register(unsigned gpio, char *name, int def)
  125. {
  126. if (gpio_request(gpio, name) == 0 &&
  127. gpio_direction_output(gpio, 0) == 0) {
  128. gpio_set_value(gpio, def);
  129. if (gpio_export(gpio, 0) != 0)
  130. pr_err("dnskw: Failed to export GPIO %s\n", name);
  131. } else
  132. pr_err("dnskw: Failed to register %s\n", name);
  133. }
  134. void __init dnskw_init(void)
  135. {
  136. kirkwood_mpp_conf(dnskw_mpp_config);
  137. kirkwood_ehci_init();
  138. kirkwood_ge00_init(&dnskw_ge00_data);
  139. platform_device_register(&dnskw_button_device);
  140. platform_device_register(&dnskw_fan_device);
  141. /* Register power-off GPIO. */
  142. if (gpio_request(36, "dnskw:power:off") == 0
  143. && gpio_direction_output(36, 0) == 0)
  144. pm_power_off = dnskw_power_off;
  145. else
  146. pr_err("dnskw: failed to configure power-off GPIO\n");
  147. /* Ensure power is supplied to both HDDs */
  148. dnskw_gpio_register(39, "dnskw:power:sata0", 1);
  149. dnskw_gpio_register(40, "dnskw:power:sata1", 1);
  150. /* Set NAS to turn back on after a power failure */
  151. dnskw_gpio_register(37, "dnskw:power:recover", 1);
  152. }