d2net_v2-setup.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /*
  2. * arch/arm/mach-kirkwood/d2net_v2-setup.c
  3. *
  4. * LaCie d2 Network Space 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/mtd/physmap.h>
  26. #include <linux/spi/flash.h>
  27. #include <linux/spi/spi.h>
  28. #include <linux/ata_platform.h>
  29. #include <linux/mv643xx_eth.h>
  30. #include <linux/i2c.h>
  31. #include <linux/i2c/at24.h>
  32. #include <linux/input.h>
  33. #include <linux/gpio.h>
  34. #include <linux/gpio_keys.h>
  35. #include <linux/leds.h>
  36. #include <asm/mach-types.h>
  37. #include <asm/mach/arch.h>
  38. #include <asm/mach/time.h>
  39. #include <mach/kirkwood.h>
  40. #include <mach/leds-ns2.h>
  41. #include <plat/time.h>
  42. #include "common.h"
  43. #include "mpp.h"
  44. /*****************************************************************************
  45. * 512KB SPI Flash on Boot Device
  46. ****************************************************************************/
  47. static struct mtd_partition d2net_v2_flash_parts[] = {
  48. {
  49. .name = "u-boot",
  50. .size = MTDPART_SIZ_FULL,
  51. .offset = 0,
  52. .mask_flags = MTD_WRITEABLE,
  53. },
  54. };
  55. static const struct flash_platform_data d2net_v2_flash = {
  56. .type = "mx25l4005a",
  57. .name = "spi_flash",
  58. .parts = d2net_v2_flash_parts,
  59. .nr_parts = ARRAY_SIZE(d2net_v2_flash_parts),
  60. };
  61. static struct spi_board_info __initdata d2net_v2_spi_slave_info[] = {
  62. {
  63. .modalias = "m25p80",
  64. .platform_data = &d2net_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 d2net_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 d2net_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 d2net_v2_sata_data = {
  98. .n_ports = 2,
  99. };
  100. #define D2NET_V2_GPIO_SATA0_POWER 16
  101. static void __init d2net_v2_sata_power_init(void)
  102. {
  103. int err;
  104. err = gpio_request(D2NET_V2_GPIO_SATA0_POWER, "SATA0 power");
  105. if (err == 0) {
  106. err = gpio_direction_output(D2NET_V2_GPIO_SATA0_POWER, 1);
  107. if (err)
  108. gpio_free(D2NET_V2_GPIO_SATA0_POWER);
  109. }
  110. if (err)
  111. pr_err("d2net_v2: failed to configure SATA0 power GPIO\n");
  112. }
  113. /*****************************************************************************
  114. * GPIO keys
  115. ****************************************************************************/
  116. #define D2NET_V2_GPIO_PUSH_BUTTON 34
  117. #define D2NET_V2_GPIO_POWER_SWITCH_ON 13
  118. #define D2NET_V2_GPIO_POWER_SWITCH_OFF 15
  119. #define D2NET_V2_SWITCH_POWER_ON 0x1
  120. #define D2NET_V2_SWITCH_POWER_OFF 0x2
  121. static struct gpio_keys_button d2net_v2_buttons[] = {
  122. [0] = {
  123. .type = EV_SW,
  124. .code = D2NET_V2_SWITCH_POWER_ON,
  125. .gpio = D2NET_V2_GPIO_POWER_SWITCH_ON,
  126. .desc = "Back power switch (on|auto)",
  127. .active_low = 0,
  128. },
  129. [1] = {
  130. .type = EV_SW,
  131. .code = D2NET_V2_SWITCH_POWER_OFF,
  132. .gpio = D2NET_V2_GPIO_POWER_SWITCH_OFF,
  133. .desc = "Back power switch (auto|off)",
  134. .active_low = 0,
  135. },
  136. [2] = {
  137. .code = KEY_POWER,
  138. .gpio = D2NET_V2_GPIO_PUSH_BUTTON,
  139. .desc = "Front Push Button",
  140. .active_low = 1,
  141. },
  142. };
  143. static struct gpio_keys_platform_data d2net_v2_button_data = {
  144. .buttons = d2net_v2_buttons,
  145. .nbuttons = ARRAY_SIZE(d2net_v2_buttons),
  146. };
  147. static struct platform_device d2net_v2_gpio_buttons = {
  148. .name = "gpio-keys",
  149. .id = -1,
  150. .dev = {
  151. .platform_data = &d2net_v2_button_data,
  152. },
  153. };
  154. /*****************************************************************************
  155. * GPIO LEDs
  156. ****************************************************************************/
  157. #define D2NET_V2_GPIO_RED_LED 12
  158. static struct gpio_led d2net_v2_gpio_led_pins[] = {
  159. {
  160. .name = "d2net_v2:red:fail",
  161. .gpio = D2NET_V2_GPIO_RED_LED,
  162. },
  163. };
  164. static struct gpio_led_platform_data d2net_v2_gpio_leds_data = {
  165. .num_leds = ARRAY_SIZE(d2net_v2_gpio_led_pins),
  166. .leds = d2net_v2_gpio_led_pins,
  167. };
  168. static struct platform_device d2net_v2_gpio_leds = {
  169. .name = "leds-gpio",
  170. .id = -1,
  171. .dev = {
  172. .platform_data = &d2net_v2_gpio_leds_data,
  173. },
  174. };
  175. /*****************************************************************************
  176. * Dual-GPIO CPLD LEDs
  177. ****************************************************************************/
  178. #define D2NET_V2_GPIO_BLUE_LED_SLOW 29
  179. #define D2NET_V2_GPIO_BLUE_LED_CMD 30
  180. static struct ns2_led d2net_v2_led_pins[] = {
  181. {
  182. .name = "d2net_v2:blue:sata",
  183. .cmd = D2NET_V2_GPIO_BLUE_LED_CMD,
  184. .slow = D2NET_V2_GPIO_BLUE_LED_SLOW,
  185. },
  186. };
  187. static struct ns2_led_platform_data d2net_v2_leds_data = {
  188. .num_leds = ARRAY_SIZE(d2net_v2_led_pins),
  189. .leds = d2net_v2_led_pins,
  190. };
  191. static struct platform_device d2net_v2_leds = {
  192. .name = "leds-ns2",
  193. .id = -1,
  194. .dev = {
  195. .platform_data = &d2net_v2_leds_data,
  196. },
  197. };
  198. /*****************************************************************************
  199. * Timer
  200. ****************************************************************************/
  201. static void d2net_v2_timer_init(void)
  202. {
  203. kirkwood_tclk = 166666667;
  204. orion_time_init(IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
  205. }
  206. struct sys_timer d2net_v2_timer = {
  207. .init = d2net_v2_timer_init,
  208. };
  209. /*****************************************************************************
  210. * General Setup
  211. ****************************************************************************/
  212. static unsigned int d2net_v2_mpp_config[] __initdata = {
  213. MPP0_SPI_SCn,
  214. MPP1_SPI_MOSI,
  215. MPP2_SPI_SCK,
  216. MPP3_SPI_MISO,
  217. MPP6_SYSRST_OUTn,
  218. MPP7_GPO, /* Request power-off */
  219. MPP8_TW0_SDA,
  220. MPP9_TW0_SCK,
  221. MPP10_UART0_TXD,
  222. MPP11_UART0_RXD,
  223. MPP12_GPO, /* Red led */
  224. MPP13_GPIO, /* Rear power switch (on|auto) */
  225. MPP14_GPIO, /* USB fuse */
  226. MPP15_GPIO, /* Rear power switch (auto|off) */
  227. MPP16_GPIO, /* SATA 0 power */
  228. MPP21_SATA0_ACTn,
  229. MPP24_GPIO, /* USB mode select */
  230. MPP26_GPIO, /* USB device vbus */
  231. MPP28_GPIO, /* USB enable host vbus */
  232. MPP29_GPIO, /* Blue led (slow register) */
  233. MPP30_GPIO, /* Blue led (command register) */
  234. MPP34_GPIO, /* Power button (1 = Released, 0 = Pushed) */
  235. MPP35_GPIO, /* Inhibit power-off */
  236. 0
  237. };
  238. #define D2NET_V2_GPIO_POWER_OFF 7
  239. static void d2net_v2_power_off(void)
  240. {
  241. gpio_set_value(D2NET_V2_GPIO_POWER_OFF, 1);
  242. }
  243. static void __init d2net_v2_init(void)
  244. {
  245. /*
  246. * Basic setup. Needs to be called early.
  247. */
  248. kirkwood_init();
  249. kirkwood_mpp_conf(d2net_v2_mpp_config);
  250. d2net_v2_sata_power_init();
  251. kirkwood_ehci_init();
  252. kirkwood_ge00_init(&d2net_v2_ge00_data);
  253. kirkwood_sata_init(&d2net_v2_sata_data);
  254. kirkwood_uart0_init();
  255. spi_register_board_info(d2net_v2_spi_slave_info,
  256. ARRAY_SIZE(d2net_v2_spi_slave_info));
  257. kirkwood_spi_init();
  258. kirkwood_i2c_init();
  259. i2c_register_board_info(0, d2net_v2_i2c_info,
  260. ARRAY_SIZE(d2net_v2_i2c_info));
  261. platform_device_register(&d2net_v2_leds);
  262. platform_device_register(&d2net_v2_gpio_leds);
  263. platform_device_register(&d2net_v2_gpio_buttons);
  264. if (gpio_request(D2NET_V2_GPIO_POWER_OFF, "power-off") == 0 &&
  265. gpio_direction_output(D2NET_V2_GPIO_POWER_OFF, 0) == 0)
  266. pm_power_off = d2net_v2_power_off;
  267. else
  268. pr_err("d2net_v2: failed to configure power-off GPIO\n");
  269. }
  270. MACHINE_START(D2NET_V2, "LaCie d2 Network v2")
  271. .phys_io = KIRKWOOD_REGS_PHYS_BASE,
  272. .io_pg_offst = ((KIRKWOOD_REGS_VIRT_BASE) >> 18) & 0xfffc,
  273. .boot_params = 0x00000100,
  274. .init_machine = d2net_v2_init,
  275. .map_io = kirkwood_map_io,
  276. .init_irq = kirkwood_init_irq,
  277. .timer = &d2net_v2_timer,
  278. MACHINE_END