netspace_v2-setup.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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 <plat/time.h>
  42. #include "common.h"
  43. #include "mpp.h"
  44. /*****************************************************************************
  45. * 512KB SPI Flash on Boot Device (MACRONIX MX25L4005)
  46. ****************************************************************************/
  47. static struct mtd_partition netspace_v2_flash_parts[] = {
  48. {
  49. .name = "u-boot",
  50. .size = MTDPART_SIZ_FULL,
  51. .offset = 0,
  52. .mask_flags = MTD_WRITEABLE, /* force read-only */
  53. },
  54. };
  55. static const struct flash_platform_data netspace_v2_flash = {
  56. .type = "mx25l4005a",
  57. .name = "spi_flash",
  58. .parts = netspace_v2_flash_parts,
  59. .nr_parts = ARRAY_SIZE(netspace_v2_flash_parts),
  60. };
  61. static struct spi_board_info __initdata netspace_v2_spi_slave_info[] = {
  62. {
  63. .modalias = "m25p80",
  64. .platform_data = &netspace_v2_flash,
  65. .irq = -1,
  66. .max_speed_hz = 20000000,
  67. .bus_num = 0,
  68. .chip_select = 0,
  69. },
  70. };
  71. /*****************************************************************************
  72. * Ethernet
  73. ****************************************************************************/
  74. static struct mv643xx_eth_platform_data netspace_v2_ge00_data = {
  75. .phy_addr = MV643XX_ETH_PHY_ADDR(8),
  76. };
  77. /*****************************************************************************
  78. * I2C devices
  79. ****************************************************************************/
  80. static struct at24_platform_data at24c04 = {
  81. .byte_len = SZ_4K / 8,
  82. .page_size = 16,
  83. };
  84. /*
  85. * i2c addr | chip | description
  86. * 0x50 | HT24LC04 | eeprom (512B)
  87. */
  88. static struct i2c_board_info __initdata netspace_v2_i2c_info[] = {
  89. {
  90. I2C_BOARD_INFO("24c04", 0x50),
  91. .platform_data = &at24c04,
  92. }
  93. };
  94. /*****************************************************************************
  95. * SATA
  96. ****************************************************************************/
  97. static struct mv_sata_platform_data netspace_v2_sata_data = {
  98. .n_ports = 2,
  99. };
  100. #define NETSPACE_V2_GPIO_SATA0_POWER 16
  101. #define NETSPACE_V2_GPIO_SATA1_POWER 17
  102. static void __init netspace_v2_sata_power_init(void)
  103. {
  104. int err;
  105. err = gpio_request(NETSPACE_V2_GPIO_SATA0_POWER, "SATA0 power");
  106. if (err == 0) {
  107. err = gpio_direction_output(NETSPACE_V2_GPIO_SATA0_POWER, 1);
  108. if (err)
  109. gpio_free(NETSPACE_V2_GPIO_SATA0_POWER);
  110. }
  111. if (err)
  112. pr_err("netspace_v2: failed to setup SATA0 power\n");
  113. }
  114. /*****************************************************************************
  115. * GPIO keys
  116. ****************************************************************************/
  117. #define NETSPACE_V2_PUSH_BUTTON 32
  118. static struct gpio_keys_button netspace_v2_buttons[] = {
  119. [0] = {
  120. .code = KEY_POWER,
  121. .gpio = NETSPACE_V2_PUSH_BUTTON,
  122. .desc = "Power push button",
  123. .active_low = 0,
  124. },
  125. };
  126. static struct gpio_keys_platform_data netspace_v2_button_data = {
  127. .buttons = netspace_v2_buttons,
  128. .nbuttons = ARRAY_SIZE(netspace_v2_buttons),
  129. };
  130. static struct platform_device netspace_v2_gpio_buttons = {
  131. .name = "gpio-keys",
  132. .id = -1,
  133. .dev = {
  134. .platform_data = &netspace_v2_button_data,
  135. },
  136. };
  137. /*****************************************************************************
  138. * GPIO LEDs
  139. ****************************************************************************/
  140. /*
  141. * The blue front LED is wired to a CPLD and can blink in relation with the
  142. * SATA activity.
  143. *
  144. * The following array detail the different LED registers and the combination
  145. * of their possible values:
  146. *
  147. * cmd_led | slow_led | /SATA active | LED state
  148. * | | |
  149. * 1 | 0 | x | off
  150. * - | 1 | x | on
  151. * 0 | 0 | 1 | on
  152. * 0 | 0 | 0 | blink (rate 300ms)
  153. */
  154. #define NETSPACE_V2_GPIO_RED_LED 12
  155. #define NETSPACE_V2_GPIO_BLUE_LED_SLOW 29
  156. #define NETSPACE_V2_GPIO_BLUE_LED_CMD 30
  157. static struct gpio_led netspace_v2_gpio_led_pins[] = {
  158. {
  159. .name = "ns_v2:red:fail",
  160. .gpio = NETSPACE_V2_GPIO_RED_LED,
  161. },
  162. };
  163. static struct gpio_led_platform_data netspace_v2_gpio_leds_data = {
  164. .num_leds = ARRAY_SIZE(netspace_v2_gpio_led_pins),
  165. .leds = netspace_v2_gpio_led_pins,
  166. };
  167. static struct platform_device netspace_v2_gpio_leds = {
  168. .name = "leds-gpio",
  169. .id = -1,
  170. .dev = {
  171. .platform_data = &netspace_v2_gpio_leds_data,
  172. },
  173. };
  174. static void __init netspace_v2_gpio_leds_init(void)
  175. {
  176. platform_device_register(&netspace_v2_gpio_leds);
  177. /*
  178. * Configure the front blue LED to blink in relation with the SATA
  179. * activity.
  180. */
  181. if (gpio_request(NETSPACE_V2_GPIO_BLUE_LED_SLOW,
  182. "SATA blue LED slow") != 0)
  183. return;
  184. if (gpio_direction_output(NETSPACE_V2_GPIO_BLUE_LED_SLOW, 0) != 0)
  185. goto err_free_1;
  186. if (gpio_request(NETSPACE_V2_GPIO_BLUE_LED_CMD,
  187. "SATA blue LED command") != 0)
  188. goto err_free_1;
  189. if (gpio_direction_output(NETSPACE_V2_GPIO_BLUE_LED_CMD, 0) != 0)
  190. goto err_free_2;
  191. return;
  192. err_free_2:
  193. gpio_free(NETSPACE_V2_GPIO_BLUE_LED_CMD);
  194. err_free_1:
  195. gpio_free(NETSPACE_V2_GPIO_BLUE_LED_SLOW);
  196. pr_err("netspace_v2: failed to configure SATA blue LED\n");
  197. }
  198. /*****************************************************************************
  199. * Timer
  200. ****************************************************************************/
  201. static void netspace_v2_timer_init(void)
  202. {
  203. kirkwood_tclk = 166666667;
  204. orion_time_init(IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
  205. }
  206. struct sys_timer netspace_v2_timer = {
  207. .init = netspace_v2_timer_init,
  208. };
  209. /*****************************************************************************
  210. * General Setup
  211. ****************************************************************************/
  212. static unsigned int netspace_v2_mpp_config[] __initdata = {
  213. MPP0_SPI_SCn,
  214. MPP1_SPI_MOSI,
  215. MPP2_SPI_SCK,
  216. MPP3_SPI_MISO,
  217. MPP4_NF_IO6,
  218. MPP5_NF_IO7,
  219. MPP6_SYSRST_OUTn,
  220. MPP8_TW_SDA,
  221. MPP9_TW_SCK,
  222. MPP10_UART0_TXD,
  223. MPP11_UART0_RXD,
  224. MPP12_GPO, /* Red led */
  225. MPP14_GPIO, /* USB fuse */
  226. MPP16_GPIO, /* SATA 0 power */
  227. MPP18_NF_IO0,
  228. MPP19_NF_IO1,
  229. MPP20_SATA1_ACTn,
  230. MPP21_SATA0_ACTn,
  231. MPP24_GPIO, /* USB mode select */
  232. MPP25_GPIO, /* Fan rotation fail */
  233. MPP26_GPIO, /* USB device vbus */
  234. MPP28_GPIO, /* USB enable host vbus */
  235. MPP29_GPIO, /* Blue led (slow register) */
  236. MPP30_GPIO, /* Blue led (command register) */
  237. MPP31_GPIO, /* Board power off */
  238. MPP32_GPIO, /* Power button (0 = Released, 1 = Pushed) */
  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. netspace_v2_gpio_leds_init();
  265. platform_device_register(&netspace_v2_gpio_buttons);
  266. if (gpio_request(NETSPACE_V2_GPIO_POWER_OFF, "power-off") == 0 &&
  267. gpio_direction_output(NETSPACE_V2_GPIO_POWER_OFF, 0) == 0)
  268. pm_power_off = netspace_v2_power_off;
  269. else
  270. pr_err("netspace_v2: failed to configure power-off GPIO\n");
  271. }
  272. MACHINE_START(NETSPACE_V2, "LaCie Network Space v2")
  273. .phys_io = KIRKWOOD_REGS_PHYS_BASE,
  274. .io_pg_offst = ((KIRKWOOD_REGS_VIRT_BASE) >> 18) & 0xfffc,
  275. .boot_params = 0x00000100,
  276. .init_machine = netspace_v2_init,
  277. .map_io = kirkwood_map_io,
  278. .init_irq = kirkwood_init_irq,
  279. .timer = &netspace_v2_timer,
  280. MACHINE_END