netspace_v2-setup.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /*
  2. * arch/arm/mach-kirkwood/netspace_v2-setup.c
  3. *
  4. * LaCie Network Space v2 board setup
  5. *
  6. * Copyright (C) 2009 Simon Guinot <sguinot@lacie.com>
  7. * Copyright (C) 2009 Benoît Canet <benoit.canet@gmail.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/init.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/mtd/physmap.h>
  27. #include <linux/spi/flash.h>
  28. #include <linux/spi/spi.h>
  29. #include <linux/ata_platform.h>
  30. #include <linux/mv643xx_eth.h>
  31. #include <linux/i2c.h>
  32. #include <linux/i2c/at24.h>
  33. #include <linux/input.h>
  34. #include <linux/gpio.h>
  35. #include <linux/gpio_keys.h>
  36. #include <linux/leds.h>
  37. #include <asm/mach-types.h>
  38. #include <asm/mach/arch.h>
  39. #include <asm/mach/time.h>
  40. #include <mach/kirkwood.h>
  41. #include <mach/leds-ns2.h>
  42. #include <plat/time.h>
  43. #include "common.h"
  44. #include "mpp.h"
  45. /*****************************************************************************
  46. * 512KB SPI Flash on Boot Device (MACRONIX MX25L4005)
  47. ****************************************************************************/
  48. static struct mtd_partition netspace_v2_flash_parts[] = {
  49. {
  50. .name = "u-boot",
  51. .size = MTDPART_SIZ_FULL,
  52. .offset = 0,
  53. .mask_flags = MTD_WRITEABLE, /* force read-only */
  54. },
  55. };
  56. static const struct flash_platform_data netspace_v2_flash = {
  57. .type = "mx25l4005a",
  58. .name = "spi_flash",
  59. .parts = netspace_v2_flash_parts,
  60. .nr_parts = ARRAY_SIZE(netspace_v2_flash_parts),
  61. };
  62. static struct spi_board_info __initdata netspace_v2_spi_slave_info[] = {
  63. {
  64. .modalias = "m25p80",
  65. .platform_data = &netspace_v2_flash,
  66. .irq = -1,
  67. .max_speed_hz = 20000000,
  68. .bus_num = 0,
  69. .chip_select = 0,
  70. },
  71. };
  72. /*****************************************************************************
  73. * Ethernet
  74. ****************************************************************************/
  75. static struct mv643xx_eth_platform_data netspace_v2_ge00_data = {
  76. .phy_addr = MV643XX_ETH_PHY_ADDR(8),
  77. };
  78. /*****************************************************************************
  79. * I2C devices
  80. ****************************************************************************/
  81. static struct at24_platform_data at24c04 = {
  82. .byte_len = SZ_4K / 8,
  83. .page_size = 16,
  84. };
  85. /*
  86. * i2c addr | chip | description
  87. * 0x50 | HT24LC04 | eeprom (512B)
  88. */
  89. static struct i2c_board_info __initdata netspace_v2_i2c_info[] = {
  90. {
  91. I2C_BOARD_INFO("24c04", 0x50),
  92. .platform_data = &at24c04,
  93. }
  94. };
  95. /*****************************************************************************
  96. * SATA
  97. ****************************************************************************/
  98. static struct mv_sata_platform_data netspace_v2_sata_data = {
  99. .n_ports = 2,
  100. };
  101. #define NETSPACE_V2_GPIO_SATA0_POWER 16
  102. #define NETSPACE_V2_GPIO_SATA1_POWER 17
  103. static void __init netspace_v2_sata_power_init(void)
  104. {
  105. int err;
  106. err = gpio_request(NETSPACE_V2_GPIO_SATA0_POWER, "SATA0 power");
  107. if (err == 0) {
  108. err = gpio_direction_output(NETSPACE_V2_GPIO_SATA0_POWER, 1);
  109. if (err)
  110. gpio_free(NETSPACE_V2_GPIO_SATA0_POWER);
  111. }
  112. if (err)
  113. pr_err("netspace_v2: failed to setup SATA0 power\n");
  114. if (machine_is_netspace_max_v2()) {
  115. err = gpio_request(NETSPACE_V2_GPIO_SATA1_POWER, "SATA1 power");
  116. if (err == 0) {
  117. err = gpio_direction_output(
  118. NETSPACE_V2_GPIO_SATA1_POWER, 1);
  119. if (err)
  120. gpio_free(NETSPACE_V2_GPIO_SATA1_POWER);
  121. }
  122. if (err)
  123. pr_err("netspace_v2: failed to setup SATA1 power\n");
  124. }
  125. }
  126. /*****************************************************************************
  127. * GPIO keys
  128. ****************************************************************************/
  129. #define NETSPACE_V2_PUSH_BUTTON 32
  130. static struct gpio_keys_button netspace_v2_buttons[] = {
  131. [0] = {
  132. .code = KEY_POWER,
  133. .gpio = NETSPACE_V2_PUSH_BUTTON,
  134. .desc = "Power push button",
  135. .active_low = 0,
  136. },
  137. };
  138. static struct gpio_keys_platform_data netspace_v2_button_data = {
  139. .buttons = netspace_v2_buttons,
  140. .nbuttons = ARRAY_SIZE(netspace_v2_buttons),
  141. };
  142. static struct platform_device netspace_v2_gpio_buttons = {
  143. .name = "gpio-keys",
  144. .id = -1,
  145. .dev = {
  146. .platform_data = &netspace_v2_button_data,
  147. },
  148. };
  149. /*****************************************************************************
  150. * GPIO LEDs
  151. ****************************************************************************/
  152. #define NETSPACE_V2_GPIO_RED_LED 12
  153. static struct gpio_led netspace_v2_gpio_led_pins[] = {
  154. {
  155. .name = "ns_v2:red:fail",
  156. .gpio = NETSPACE_V2_GPIO_RED_LED,
  157. },
  158. };
  159. static struct gpio_led_platform_data netspace_v2_gpio_leds_data = {
  160. .num_leds = ARRAY_SIZE(netspace_v2_gpio_led_pins),
  161. .leds = netspace_v2_gpio_led_pins,
  162. };
  163. static struct platform_device netspace_v2_gpio_leds = {
  164. .name = "leds-gpio",
  165. .id = -1,
  166. .dev = {
  167. .platform_data = &netspace_v2_gpio_leds_data,
  168. },
  169. };
  170. /*****************************************************************************
  171. * Dual-GPIO CPLD LEDs
  172. ****************************************************************************/
  173. #define NETSPACE_V2_GPIO_BLUE_LED_SLOW 29
  174. #define NETSPACE_V2_GPIO_BLUE_LED_CMD 30
  175. static struct ns2_led netspace_v2_led_pins[] = {
  176. {
  177. .name = "ns_v2:blue:sata",
  178. .cmd = NETSPACE_V2_GPIO_BLUE_LED_CMD,
  179. .slow = NETSPACE_V2_GPIO_BLUE_LED_SLOW,
  180. },
  181. };
  182. static struct ns2_led_platform_data netspace_v2_leds_data = {
  183. .num_leds = ARRAY_SIZE(netspace_v2_led_pins),
  184. .leds = netspace_v2_led_pins,
  185. };
  186. static struct platform_device netspace_v2_leds = {
  187. .name = "leds-ns2",
  188. .id = -1,
  189. .dev = {
  190. .platform_data = &netspace_v2_leds_data,
  191. },
  192. };
  193. /*****************************************************************************
  194. * Timer
  195. ****************************************************************************/
  196. static void netspace_v2_timer_init(void)
  197. {
  198. kirkwood_tclk = 166666667;
  199. orion_time_init(IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
  200. }
  201. struct sys_timer netspace_v2_timer = {
  202. .init = netspace_v2_timer_init,
  203. };
  204. /*****************************************************************************
  205. * General Setup
  206. ****************************************************************************/
  207. static unsigned int netspace_v2_mpp_config[] __initdata = {
  208. MPP0_SPI_SCn,
  209. MPP1_SPI_MOSI,
  210. MPP2_SPI_SCK,
  211. MPP3_SPI_MISO,
  212. MPP4_NF_IO6,
  213. MPP5_NF_IO7,
  214. MPP6_SYSRST_OUTn,
  215. MPP7_GPO, /* Fan speed (bit 1) */
  216. MPP8_TW0_SDA,
  217. MPP9_TW0_SCK,
  218. MPP10_UART0_TXD,
  219. MPP11_UART0_RXD,
  220. MPP12_GPO, /* Red led */
  221. MPP14_GPIO, /* USB fuse */
  222. MPP16_GPIO, /* SATA 0 power */
  223. MPP17_GPIO, /* SATA 1 power */
  224. MPP18_NF_IO0,
  225. MPP19_NF_IO1,
  226. MPP20_SATA1_ACTn,
  227. MPP21_SATA0_ACTn,
  228. MPP22_GPIO, /* Fan speed (bit 0) */
  229. MPP23_GPIO, /* Fan power */
  230. MPP24_GPIO, /* USB mode select */
  231. MPP25_GPIO, /* Fan rotation fail */
  232. MPP26_GPIO, /* USB device vbus */
  233. MPP28_GPIO, /* USB enable host vbus */
  234. MPP29_GPIO, /* Blue led (slow register) */
  235. MPP30_GPIO, /* Blue led (command register) */
  236. MPP31_GPIO, /* Board power off */
  237. MPP32_GPIO, /* Power button (0 = Released, 1 = Pushed) */
  238. MPP33_GPO, /* Fan speed (bit 2) */
  239. 0
  240. };
  241. #define NETSPACE_V2_GPIO_POWER_OFF 31
  242. static void netspace_v2_power_off(void)
  243. {
  244. gpio_set_value(NETSPACE_V2_GPIO_POWER_OFF, 1);
  245. }
  246. static void __init netspace_v2_init(void)
  247. {
  248. /*
  249. * Basic setup. Needs to be called early.
  250. */
  251. kirkwood_init();
  252. kirkwood_mpp_conf(netspace_v2_mpp_config);
  253. netspace_v2_sata_power_init();
  254. kirkwood_ehci_init();
  255. kirkwood_ge00_init(&netspace_v2_ge00_data);
  256. kirkwood_sata_init(&netspace_v2_sata_data);
  257. kirkwood_uart0_init();
  258. spi_register_board_info(netspace_v2_spi_slave_info,
  259. ARRAY_SIZE(netspace_v2_spi_slave_info));
  260. kirkwood_spi_init();
  261. kirkwood_i2c_init();
  262. i2c_register_board_info(0, netspace_v2_i2c_info,
  263. ARRAY_SIZE(netspace_v2_i2c_info));
  264. platform_device_register(&netspace_v2_leds);
  265. platform_device_register(&netspace_v2_gpio_leds);
  266. platform_device_register(&netspace_v2_gpio_buttons);
  267. if (gpio_request(NETSPACE_V2_GPIO_POWER_OFF, "power-off") == 0 &&
  268. gpio_direction_output(NETSPACE_V2_GPIO_POWER_OFF, 0) == 0)
  269. pm_power_off = netspace_v2_power_off;
  270. else
  271. pr_err("netspace_v2: failed to configure power-off GPIO\n");
  272. }
  273. #ifdef CONFIG_MACH_NETSPACE_V2
  274. MACHINE_START(NETSPACE_V2, "LaCie Network Space v2")
  275. .phys_io = KIRKWOOD_REGS_PHYS_BASE,
  276. .io_pg_offst = ((KIRKWOOD_REGS_VIRT_BASE) >> 18) & 0xfffc,
  277. .boot_params = 0x00000100,
  278. .init_machine = netspace_v2_init,
  279. .map_io = kirkwood_map_io,
  280. .init_irq = kirkwood_init_irq,
  281. .timer = &netspace_v2_timer,
  282. MACHINE_END
  283. #endif
  284. #ifdef CONFIG_MACH_INETSPACE_V2
  285. MACHINE_START(INETSPACE_V2, "LaCie Internet Space v2")
  286. .phys_io = KIRKWOOD_REGS_PHYS_BASE,
  287. .io_pg_offst = ((KIRKWOOD_REGS_VIRT_BASE) >> 18) & 0xfffc,
  288. .boot_params = 0x00000100,
  289. .init_machine = netspace_v2_init,
  290. .map_io = kirkwood_map_io,
  291. .init_irq = kirkwood_init_irq,
  292. .timer = &netspace_v2_timer,
  293. MACHINE_END
  294. #endif
  295. #ifdef CONFIG_MACH_NETSPACE_MAX_V2
  296. MACHINE_START(NETSPACE_MAX_V2, "LaCie Network Space Max v2")
  297. .phys_io = KIRKWOOD_REGS_PHYS_BASE,
  298. .io_pg_offst = ((KIRKWOOD_REGS_VIRT_BASE) >> 18) & 0xfffc,
  299. .boot_params = 0x00000100,
  300. .init_machine = netspace_v2_init,
  301. .map_io = kirkwood_map_io,
  302. .init_irq = kirkwood_init_irq,
  303. .timer = &netspace_v2_timer,
  304. MACHINE_END
  305. #endif