board-dnskw.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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/i2c.h>
  17. #include <linux/ata_platform.h>
  18. #include <linux/mv643xx_eth.h>
  19. #include <linux/of.h>
  20. #include <linux/gpio.h>
  21. #include <linux/input.h>
  22. #include <linux/gpio_keys.h>
  23. #include <linux/gpio-fan.h>
  24. #include <linux/leds.h>
  25. #include <asm/mach-types.h>
  26. #include <asm/mach/arch.h>
  27. #include <asm/mach/map.h>
  28. #include <mach/kirkwood.h>
  29. #include <mach/bridge-regs.h>
  30. #include "common.h"
  31. #include "mpp.h"
  32. static struct mv643xx_eth_platform_data dnskw_ge00_data = {
  33. .phy_addr = MV643XX_ETH_PHY_ADDR(8),
  34. };
  35. static struct mv_sata_platform_data dnskw_sata_data = {
  36. .n_ports = 2,
  37. };
  38. static unsigned int dnskw_mpp_config[] __initdata = {
  39. MPP13_UART1_TXD, /* Custom ... */
  40. MPP14_UART1_RXD, /* ... Controller (DNS-320 only) */
  41. MPP20_SATA1_ACTn, /* LED: White Right HDD */
  42. MPP21_SATA0_ACTn, /* LED: White Left HDD */
  43. MPP24_GPIO,
  44. MPP25_GPIO,
  45. MPP26_GPIO, /* LED: Power */
  46. MPP27_GPIO, /* LED: Red Right HDD */
  47. MPP28_GPIO, /* LED: Red Left HDD */
  48. MPP29_GPIO, /* LED: Red USB (DNS-325 only) */
  49. MPP30_GPIO,
  50. MPP31_GPIO,
  51. MPP32_GPIO,
  52. MPP33_GPO,
  53. MPP34_GPIO, /* Button: Front power */
  54. MPP35_GPIO, /* LED: Red USB (DNS-320 only) */
  55. MPP36_GPIO, /* Power: Turn off board */
  56. MPP37_GPIO, /* Power: Turn back on after power failure */
  57. MPP38_GPIO,
  58. MPP39_GPIO, /* Power: SATA0 */
  59. MPP40_GPIO, /* Power: SATA1 */
  60. MPP41_GPIO, /* SATA0 present */
  61. MPP42_GPIO, /* SATA1 present */
  62. MPP43_GPIO, /* LED: White USB */
  63. MPP44_GPIO, /* Fan: Tachometer Pin */
  64. MPP45_GPIO, /* Fan: high speed */
  65. MPP46_GPIO, /* Fan: low speed */
  66. MPP47_GPIO, /* Button: Back unmount */
  67. MPP48_GPIO, /* Button: Back reset */
  68. MPP49_GPIO, /* Temp Alarm (DNS-325) Pin of U5 (DNS-320) */
  69. 0
  70. };
  71. static struct gpio_led dns325_led_pins[] = {
  72. {
  73. .name = "dns325:white:power",
  74. .gpio = 26,
  75. .active_low = 1,
  76. .default_trigger = "default-on",
  77. },
  78. {
  79. .name = "dns325:white:usb",
  80. .gpio = 43,
  81. .active_low = 1,
  82. },
  83. {
  84. .name = "dns325:red:l_hdd",
  85. .gpio = 28,
  86. .active_low = 1,
  87. },
  88. {
  89. .name = "dns325:red:r_hdd",
  90. .gpio = 27,
  91. .active_low = 1,
  92. },
  93. {
  94. .name = "dns325:red:usb",
  95. .gpio = 29,
  96. .active_low = 1,
  97. },
  98. };
  99. static struct gpio_led_platform_data dns325_led_data = {
  100. .num_leds = ARRAY_SIZE(dns325_led_pins),
  101. .leds = dns325_led_pins,
  102. };
  103. static struct platform_device dns325_led_device = {
  104. .name = "leds-gpio",
  105. .id = -1,
  106. .dev = {
  107. .platform_data = &dns325_led_data,
  108. },
  109. };
  110. static struct gpio_led dns320_led_pins[] = {
  111. {
  112. .name = "dns320:blue:power",
  113. .gpio = 26,
  114. .active_low = 1,
  115. .default_trigger = "default-on",
  116. },
  117. {
  118. .name = "dns320:blue:usb",
  119. .gpio = 43,
  120. .active_low = 1,
  121. },
  122. {
  123. .name = "dns320:orange:l_hdd",
  124. .gpio = 28,
  125. .active_low = 1,
  126. },
  127. {
  128. .name = "dns320:orange:r_hdd",
  129. .gpio = 27,
  130. .active_low = 1,
  131. },
  132. {
  133. .name = "dns320:orange:usb",
  134. .gpio = 35,
  135. .active_low = 1,
  136. },
  137. };
  138. static struct gpio_led_platform_data dns320_led_data = {
  139. .num_leds = ARRAY_SIZE(dns320_led_pins),
  140. .leds = dns320_led_pins,
  141. };
  142. static struct platform_device dns320_led_device = {
  143. .name = "leds-gpio",
  144. .id = -1,
  145. .dev = {
  146. .platform_data = &dns320_led_data,
  147. },
  148. };
  149. static struct i2c_board_info dns325_i2c_board_info[] __initdata = {
  150. {
  151. I2C_BOARD_INFO("lm75", 0x48),
  152. },
  153. /* Something at 0x0c also */
  154. };
  155. static struct gpio_keys_button dnskw_button_pins[] = {
  156. {
  157. .code = KEY_POWER,
  158. .gpio = 34,
  159. .desc = "Power button",
  160. .active_low = 1,
  161. },
  162. {
  163. .code = KEY_EJECTCD,
  164. .gpio = 47,
  165. .desc = "USB unmount button",
  166. .active_low = 1,
  167. },
  168. {
  169. .code = KEY_RESTART,
  170. .gpio = 48,
  171. .desc = "Reset button",
  172. .active_low = 1,
  173. },
  174. };
  175. static struct gpio_keys_platform_data dnskw_button_data = {
  176. .buttons = dnskw_button_pins,
  177. .nbuttons = ARRAY_SIZE(dnskw_button_pins),
  178. };
  179. static struct platform_device dnskw_button_device = {
  180. .name = "gpio-keys",
  181. .id = -1,
  182. .num_resources = 0,
  183. .dev = {
  184. .platform_data = &dnskw_button_data,
  185. }
  186. };
  187. /* Fan: ADDA AD045HB-G73 40mm 6000rpm@5v */
  188. static struct gpio_fan_speed dnskw_fan_speed[] = {
  189. { 0, 0 },
  190. { 3000, 1 },
  191. { 6000, 2 },
  192. };
  193. static unsigned dnskw_fan_pins[] = {46, 45};
  194. static struct gpio_fan_platform_data dnskw_fan_data = {
  195. .num_ctrl = ARRAY_SIZE(dnskw_fan_pins),
  196. .ctrl = dnskw_fan_pins,
  197. .num_speed = ARRAY_SIZE(dnskw_fan_speed),
  198. .speed = dnskw_fan_speed,
  199. };
  200. static struct platform_device dnskw_fan_device = {
  201. .name = "gpio-fan",
  202. .id = -1,
  203. .dev = {
  204. .platform_data = &dnskw_fan_data,
  205. },
  206. };
  207. static void dnskw_power_off(void)
  208. {
  209. gpio_set_value(36, 1);
  210. }
  211. /* Register any GPIO for output and set the value */
  212. static void __init dnskw_gpio_register(unsigned gpio, char *name, int def)
  213. {
  214. if (gpio_request(gpio, name) == 0 &&
  215. gpio_direction_output(gpio, 0) == 0) {
  216. gpio_set_value(gpio, def);
  217. if (gpio_export(gpio, 0) != 0)
  218. pr_err("dnskw: Failed to export GPIO %s\n", name);
  219. } else
  220. pr_err("dnskw: Failed to register %s\n", name);
  221. }
  222. void __init dnskw_init(void)
  223. {
  224. kirkwood_mpp_conf(dnskw_mpp_config);
  225. kirkwood_ehci_init();
  226. kirkwood_ge00_init(&dnskw_ge00_data);
  227. kirkwood_sata_init(&dnskw_sata_data);
  228. kirkwood_i2c_init();
  229. platform_device_register(&dnskw_button_device);
  230. platform_device_register(&dnskw_fan_device);
  231. if (of_machine_is_compatible("dlink,dns-325")) {
  232. i2c_register_board_info(0, dns325_i2c_board_info,
  233. ARRAY_SIZE(dns325_i2c_board_info));
  234. platform_device_register(&dns325_led_device);
  235. } else if (of_machine_is_compatible("dlink,dns-320"))
  236. platform_device_register(&dns320_led_device);
  237. /* Register power-off GPIO. */
  238. if (gpio_request(36, "dnskw:power:off") == 0
  239. && gpio_direction_output(36, 0) == 0)
  240. pm_power_off = dnskw_power_off;
  241. else
  242. pr_err("dnskw: failed to configure power-off GPIO\n");
  243. /* Ensure power is supplied to both HDDs */
  244. dnskw_gpio_register(39, "dnskw:power:sata0", 1);
  245. dnskw_gpio_register(40, "dnskw:power:sata1", 1);
  246. /* Set NAS to turn back on after a power failure */
  247. dnskw_gpio_register(37, "dnskw:power:recover", 1);
  248. }