board-dnskw.c 6.1 KB

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