netxbig_v2-setup.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. /*
  2. * arch/arm/mach-kirkwood/netxbig_v2-setup.c
  3. *
  4. * LaCie 2Big and 5Big Network v2 board setup
  5. *
  6. * Copyright (C) 2010 Simon Guinot <sguinot@lacie.com>
  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; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/ata_platform.h>
  26. #include <linux/mv643xx_eth.h>
  27. #include <linux/input.h>
  28. #include <linux/gpio.h>
  29. #include <linux/gpio_keys.h>
  30. #include <linux/leds.h>
  31. #include <asm/mach-types.h>
  32. #include <asm/mach/arch.h>
  33. #include <mach/kirkwood.h>
  34. #include <mach/leds-netxbig.h>
  35. #include "common.h"
  36. #include "mpp.h"
  37. #include "lacie_v2-common.h"
  38. /*****************************************************************************
  39. * Ethernet
  40. ****************************************************************************/
  41. static struct mv643xx_eth_platform_data netxbig_v2_ge00_data = {
  42. .phy_addr = MV643XX_ETH_PHY_ADDR(8),
  43. };
  44. static struct mv643xx_eth_platform_data netxbig_v2_ge01_data = {
  45. .phy_addr = MV643XX_ETH_PHY_ADDR(0),
  46. };
  47. /*****************************************************************************
  48. * SATA
  49. ****************************************************************************/
  50. static struct mv_sata_platform_data netxbig_v2_sata_data = {
  51. .n_ports = 2,
  52. };
  53. /*****************************************************************************
  54. * GPIO keys
  55. ****************************************************************************/
  56. #define NETXBIG_V2_GPIO_SWITCH_POWER_ON 13
  57. #define NETXBIG_V2_GPIO_SWITCH_POWER_OFF 15
  58. #define NETXBIG_V2_GPIO_FUNC_BUTTON 34
  59. #define NETXBIG_V2_SWITCH_POWER_ON 0x1
  60. #define NETXBIG_V2_SWITCH_POWER_OFF 0x2
  61. static struct gpio_keys_button netxbig_v2_buttons[] = {
  62. [0] = {
  63. .type = EV_SW,
  64. .code = NETXBIG_V2_SWITCH_POWER_ON,
  65. .gpio = NETXBIG_V2_GPIO_SWITCH_POWER_ON,
  66. .desc = "Back power switch (on|auto)",
  67. .active_low = 1,
  68. },
  69. [1] = {
  70. .type = EV_SW,
  71. .code = NETXBIG_V2_SWITCH_POWER_OFF,
  72. .gpio = NETXBIG_V2_GPIO_SWITCH_POWER_OFF,
  73. .desc = "Back power switch (auto|off)",
  74. .active_low = 1,
  75. },
  76. [2] = {
  77. .code = KEY_OPTION,
  78. .gpio = NETXBIG_V2_GPIO_FUNC_BUTTON,
  79. .desc = "Function button",
  80. .active_low = 1,
  81. },
  82. };
  83. static struct gpio_keys_platform_data netxbig_v2_button_data = {
  84. .buttons = netxbig_v2_buttons,
  85. .nbuttons = ARRAY_SIZE(netxbig_v2_buttons),
  86. };
  87. static struct platform_device netxbig_v2_gpio_buttons = {
  88. .name = "gpio-keys",
  89. .id = -1,
  90. .dev = {
  91. .platform_data = &netxbig_v2_button_data,
  92. },
  93. };
  94. /*****************************************************************************
  95. * GPIO extension LEDs
  96. ****************************************************************************/
  97. /*
  98. * The LEDs are controlled by a CPLD and can be configured through a GPIO
  99. * extension bus:
  100. *
  101. * - address register : bit [0-2] -> GPIO [47-49]
  102. * - data register : bit [0-2] -> GPIO [44-46]
  103. * - enable register : GPIO 29
  104. */
  105. static int netxbig_v2_gpio_ext_addr[] = { 47, 48, 49 };
  106. static int netxbig_v2_gpio_ext_data[] = { 44, 45, 46 };
  107. static struct netxbig_gpio_ext netxbig_v2_gpio_ext = {
  108. .addr = netxbig_v2_gpio_ext_addr,
  109. .num_addr = ARRAY_SIZE(netxbig_v2_gpio_ext_addr),
  110. .data = netxbig_v2_gpio_ext_data,
  111. .num_data = ARRAY_SIZE(netxbig_v2_gpio_ext_data),
  112. .enable = 29,
  113. };
  114. /*
  115. * Address register selection:
  116. *
  117. * addr | register
  118. * ----------------------------
  119. * 0 | front LED
  120. * 1 | front LED brightness
  121. * 2 | SATA LED brightness
  122. * 3 | SATA0 LED
  123. * 4 | SATA1 LED
  124. * 5 | SATA2 LED
  125. * 6 | SATA3 LED
  126. * 7 | SATA4 LED
  127. *
  128. * Data register configuration:
  129. *
  130. * data | LED brightness
  131. * -------------------------------------------------
  132. * 0 | min (off)
  133. * - | -
  134. * 7 | max
  135. *
  136. * data | front LED mode
  137. * -------------------------------------------------
  138. * 0 | fix off
  139. * 1 | fix blue on
  140. * 2 | fix red on
  141. * 3 | blink blue on=1 sec and blue off=1 sec
  142. * 4 | blink red on=1 sec and red off=1 sec
  143. * 5 | blink blue on=2.5 sec and red on=0.5 sec
  144. * 6 | blink blue on=1 sec and red on=1 sec
  145. * 7 | blink blue on=0.5 sec and blue off=2.5 sec
  146. *
  147. * data | SATA LED mode
  148. * -------------------------------------------------
  149. * 0 | fix off
  150. * 1 | SATA activity blink
  151. * 2 | fix red on
  152. * 3 | blink blue on=1 sec and blue off=1 sec
  153. * 4 | blink red on=1 sec and red off=1 sec
  154. * 5 | blink blue on=2.5 sec and red on=0.5 sec
  155. * 6 | blink blue on=1 sec and red on=1 sec
  156. * 7 | fix blue on
  157. */
  158. static int netxbig_v2_red_mled[NETXBIG_LED_MODE_NUM] = {
  159. [NETXBIG_LED_OFF] = 0,
  160. [NETXBIG_LED_ON] = 2,
  161. [NETXBIG_LED_SATA] = NETXBIG_LED_INVALID_MODE,
  162. [NETXBIG_LED_TIMER1] = 4,
  163. [NETXBIG_LED_TIMER2] = NETXBIG_LED_INVALID_MODE,
  164. };
  165. static int netxbig_v2_blue_pwr_mled[NETXBIG_LED_MODE_NUM] = {
  166. [NETXBIG_LED_OFF] = 0,
  167. [NETXBIG_LED_ON] = 1,
  168. [NETXBIG_LED_SATA] = NETXBIG_LED_INVALID_MODE,
  169. [NETXBIG_LED_TIMER1] = 3,
  170. [NETXBIG_LED_TIMER2] = 7,
  171. };
  172. static int netxbig_v2_blue_sata_mled[NETXBIG_LED_MODE_NUM] = {
  173. [NETXBIG_LED_OFF] = 0,
  174. [NETXBIG_LED_ON] = 7,
  175. [NETXBIG_LED_SATA] = 1,
  176. [NETXBIG_LED_TIMER1] = 3,
  177. [NETXBIG_LED_TIMER2] = NETXBIG_LED_INVALID_MODE,
  178. };
  179. static struct netxbig_led_timer netxbig_v2_led_timer[] = {
  180. [0] = {
  181. .delay_on = 500,
  182. .delay_off = 500,
  183. .mode = NETXBIG_LED_TIMER1,
  184. },
  185. [1] = {
  186. .delay_on = 500,
  187. .delay_off = 1000,
  188. .mode = NETXBIG_LED_TIMER2,
  189. },
  190. };
  191. #define NETXBIG_LED(_name, maddr, mval, baddr) \
  192. { .name = _name, \
  193. .mode_addr = maddr, \
  194. .mode_val = mval, \
  195. .bright_addr = baddr }
  196. static struct netxbig_led net2big_v2_leds_ctrl[] = {
  197. NETXBIG_LED("net2big-v2:blue:power", 0, netxbig_v2_blue_pwr_mled, 1),
  198. NETXBIG_LED("net2big-v2:red:power", 0, netxbig_v2_red_mled, 1),
  199. NETXBIG_LED("net2big-v2:blue:sata0", 3, netxbig_v2_blue_sata_mled, 2),
  200. NETXBIG_LED("net2big-v2:red:sata0", 3, netxbig_v2_red_mled, 2),
  201. NETXBIG_LED("net2big-v2:blue:sata1", 4, netxbig_v2_blue_sata_mled, 2),
  202. NETXBIG_LED("net2big-v2:red:sata1", 4, netxbig_v2_red_mled, 2),
  203. };
  204. static struct netxbig_led_platform_data net2big_v2_leds_data = {
  205. .gpio_ext = &netxbig_v2_gpio_ext,
  206. .timer = netxbig_v2_led_timer,
  207. .num_timer = ARRAY_SIZE(netxbig_v2_led_timer),
  208. .leds = net2big_v2_leds_ctrl,
  209. .num_leds = ARRAY_SIZE(net2big_v2_leds_ctrl),
  210. };
  211. static struct netxbig_led net5big_v2_leds_ctrl[] = {
  212. NETXBIG_LED("net5big-v2:blue:power", 0, netxbig_v2_blue_pwr_mled, 1),
  213. NETXBIG_LED("net5big-v2:red:power", 0, netxbig_v2_red_mled, 1),
  214. NETXBIG_LED("net5big-v2:blue:sata0", 3, netxbig_v2_blue_sata_mled, 2),
  215. NETXBIG_LED("net5big-v2:red:sata0", 3, netxbig_v2_red_mled, 2),
  216. NETXBIG_LED("net5big-v2:blue:sata1", 4, netxbig_v2_blue_sata_mled, 2),
  217. NETXBIG_LED("net5big-v2:red:sata1", 4, netxbig_v2_red_mled, 2),
  218. NETXBIG_LED("net5big-v2:blue:sata2", 5, netxbig_v2_blue_sata_mled, 2),
  219. NETXBIG_LED("net5big-v2:red:sata2", 5, netxbig_v2_red_mled, 2),
  220. NETXBIG_LED("net5big-v2:blue:sata3", 6, netxbig_v2_blue_sata_mled, 2),
  221. NETXBIG_LED("net5big-v2:red:sata3", 6, netxbig_v2_red_mled, 2),
  222. NETXBIG_LED("net5big-v2:blue:sata4", 7, netxbig_v2_blue_sata_mled, 2),
  223. NETXBIG_LED("net5big-v2:red:sata5", 7, netxbig_v2_red_mled, 2),
  224. };
  225. static struct netxbig_led_platform_data net5big_v2_leds_data = {
  226. .gpio_ext = &netxbig_v2_gpio_ext,
  227. .timer = netxbig_v2_led_timer,
  228. .num_timer = ARRAY_SIZE(netxbig_v2_led_timer),
  229. .leds = net5big_v2_leds_ctrl,
  230. .num_leds = ARRAY_SIZE(net5big_v2_leds_ctrl),
  231. };
  232. static struct platform_device netxbig_v2_leds = {
  233. .name = "leds-netxbig",
  234. .id = -1,
  235. .dev = {
  236. .platform_data = &net2big_v2_leds_data,
  237. },
  238. };
  239. /*****************************************************************************
  240. * General Setup
  241. ****************************************************************************/
  242. static unsigned int net2big_v2_mpp_config[] __initdata = {
  243. MPP0_SPI_SCn,
  244. MPP1_SPI_MOSI,
  245. MPP2_SPI_SCK,
  246. MPP3_SPI_MISO,
  247. MPP6_SYSRST_OUTn,
  248. MPP7_GPO, /* Request power-off */
  249. MPP8_TW0_SDA,
  250. MPP9_TW0_SCK,
  251. MPP10_UART0_TXD,
  252. MPP11_UART0_RXD,
  253. MPP13_GPIO, /* Rear power switch (on|auto) */
  254. MPP14_GPIO, /* USB fuse alarm */
  255. MPP15_GPIO, /* Rear power switch (auto|off) */
  256. MPP16_GPIO, /* SATA HDD1 power */
  257. MPP17_GPIO, /* SATA HDD2 power */
  258. MPP20_SATA1_ACTn,
  259. MPP21_SATA0_ACTn,
  260. MPP24_GPIO, /* USB mode select */
  261. MPP26_GPIO, /* USB device vbus */
  262. MPP28_GPIO, /* USB enable host vbus */
  263. MPP29_GPIO, /* GPIO extension ALE */
  264. MPP34_GPIO, /* Rear Push button */
  265. MPP35_GPIO, /* Inhibit switch power-off */
  266. MPP36_GPIO, /* SATA HDD1 presence */
  267. MPP37_GPIO, /* SATA HDD2 presence */
  268. MPP40_GPIO, /* eSATA presence */
  269. MPP44_GPIO, /* GPIO extension (data 0) */
  270. MPP45_GPIO, /* GPIO extension (data 1) */
  271. MPP46_GPIO, /* GPIO extension (data 2) */
  272. MPP47_GPIO, /* GPIO extension (addr 0) */
  273. MPP48_GPIO, /* GPIO extension (addr 1) */
  274. MPP49_GPIO, /* GPIO extension (addr 2) */
  275. 0
  276. };
  277. static unsigned int net5big_v2_mpp_config[] __initdata = {
  278. MPP0_SPI_SCn,
  279. MPP1_SPI_MOSI,
  280. MPP2_SPI_SCK,
  281. MPP3_SPI_MISO,
  282. MPP6_SYSRST_OUTn,
  283. MPP7_GPO, /* Request power-off */
  284. MPP8_TW0_SDA,
  285. MPP9_TW0_SCK,
  286. MPP10_UART0_TXD,
  287. MPP11_UART0_RXD,
  288. MPP13_GPIO, /* Rear power switch (on|auto) */
  289. MPP14_GPIO, /* USB fuse alarm */
  290. MPP15_GPIO, /* Rear power switch (auto|off) */
  291. MPP16_GPIO, /* SATA HDD1 power */
  292. MPP17_GPIO, /* SATA HDD2 power */
  293. MPP20_GE1_TXD0,
  294. MPP21_GE1_TXD1,
  295. MPP22_GE1_TXD2,
  296. MPP23_GE1_TXD3,
  297. MPP24_GE1_RXD0,
  298. MPP25_GE1_RXD1,
  299. MPP26_GE1_RXD2,
  300. MPP27_GE1_RXD3,
  301. MPP28_GPIO, /* USB enable host vbus */
  302. MPP29_GPIO, /* GPIO extension ALE */
  303. MPP30_GE1_RXCTL,
  304. MPP31_GE1_RXCLK,
  305. MPP32_GE1_TCLKOUT,
  306. MPP33_GE1_TXCTL,
  307. MPP34_GPIO, /* Rear Push button */
  308. MPP35_GPIO, /* Inhibit switch power-off */
  309. MPP36_GPIO, /* SATA HDD1 presence */
  310. MPP37_GPIO, /* SATA HDD2 presence */
  311. MPP38_GPIO, /* SATA HDD3 presence */
  312. MPP39_GPIO, /* SATA HDD4 presence */
  313. MPP40_GPIO, /* SATA HDD5 presence */
  314. MPP41_GPIO, /* SATA HDD3 power */
  315. MPP42_GPIO, /* SATA HDD4 power */
  316. MPP43_GPIO, /* SATA HDD5 power */
  317. MPP44_GPIO, /* GPIO extension (data 0) */
  318. MPP45_GPIO, /* GPIO extension (data 1) */
  319. MPP46_GPIO, /* GPIO extension (data 2) */
  320. MPP47_GPIO, /* GPIO extension (addr 0) */
  321. MPP48_GPIO, /* GPIO extension (addr 1) */
  322. MPP49_GPIO, /* GPIO extension (addr 2) */
  323. 0
  324. };
  325. #define NETXBIG_V2_GPIO_POWER_OFF 7
  326. static void netxbig_v2_power_off(void)
  327. {
  328. gpio_set_value(NETXBIG_V2_GPIO_POWER_OFF, 1);
  329. }
  330. static void __init netxbig_v2_init(void)
  331. {
  332. /*
  333. * Basic setup. Needs to be called early.
  334. */
  335. kirkwood_init();
  336. if (machine_is_net2big_v2())
  337. kirkwood_mpp_conf(net2big_v2_mpp_config);
  338. else
  339. kirkwood_mpp_conf(net5big_v2_mpp_config);
  340. if (machine_is_net2big_v2())
  341. lacie_v2_hdd_power_init(2);
  342. else
  343. lacie_v2_hdd_power_init(5);
  344. kirkwood_ehci_init();
  345. kirkwood_ge00_init(&netxbig_v2_ge00_data);
  346. if (machine_is_net5big_v2())
  347. kirkwood_ge01_init(&netxbig_v2_ge01_data);
  348. kirkwood_sata_init(&netxbig_v2_sata_data);
  349. kirkwood_uart0_init();
  350. lacie_v2_register_flash();
  351. lacie_v2_register_i2c_devices();
  352. if (machine_is_net5big_v2())
  353. netxbig_v2_leds.dev.platform_data = &net5big_v2_leds_data;
  354. platform_device_register(&netxbig_v2_leds);
  355. platform_device_register(&netxbig_v2_gpio_buttons);
  356. if (gpio_request(NETXBIG_V2_GPIO_POWER_OFF, "power-off") == 0 &&
  357. gpio_direction_output(NETXBIG_V2_GPIO_POWER_OFF, 0) == 0)
  358. pm_power_off = netxbig_v2_power_off;
  359. else
  360. pr_err("netxbig_v2: failed to configure power-off GPIO\n");
  361. }
  362. #ifdef CONFIG_MACH_NET2BIG_V2
  363. MACHINE_START(NET2BIG_V2, "LaCie 2Big Network v2")
  364. .atag_offset = 0x100,
  365. .init_machine = netxbig_v2_init,
  366. .map_io = kirkwood_map_io,
  367. .init_early = kirkwood_init_early,
  368. .init_irq = kirkwood_init_irq,
  369. .timer = &kirkwood_timer,
  370. .restart = kirkwood_restart,
  371. MACHINE_END
  372. #endif
  373. #ifdef CONFIG_MACH_NET5BIG_V2
  374. MACHINE_START(NET5BIG_V2, "LaCie 5Big Network v2")
  375. .atag_offset = 0x100,
  376. .init_machine = netxbig_v2_init,
  377. .map_io = kirkwood_map_io,
  378. .init_early = kirkwood_init_early,
  379. .init_irq = kirkwood_init_irq,
  380. .timer = &kirkwood_timer,
  381. .restart = kirkwood_restart,
  382. MACHINE_END
  383. #endif