/arch/arm/mach-kirkwood/netspace_v2-setup.c

https://bitbucket.org/sammyz/iscream_thunderc-2.6.35-rebase · C · 334 lines · 221 code · 45 blank · 68 comment · 11 complexity · b6211ff1d542dab6c716b39f235cc3e3 MD5 · raw file

  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:blue:sata",
  160. .default_trigger = "default-on",
  161. .gpio = NETSPACE_V2_GPIO_BLUE_LED_CMD,
  162. .active_low = 1,
  163. },
  164. {
  165. .name = "ns_v2:red:fail",
  166. .gpio = NETSPACE_V2_GPIO_RED_LED,
  167. },
  168. };
  169. static struct gpio_led_platform_data netspace_v2_gpio_leds_data = {
  170. .num_leds = ARRAY_SIZE(netspace_v2_gpio_led_pins),
  171. .leds = netspace_v2_gpio_led_pins,
  172. };
  173. static struct platform_device netspace_v2_gpio_leds = {
  174. .name = "leds-gpio",
  175. .id = -1,
  176. .dev = {
  177. .platform_data = &netspace_v2_gpio_leds_data,
  178. },
  179. };
  180. static void __init netspace_v2_gpio_leds_init(void)
  181. {
  182. int err;
  183. /* Configure register slow_led to allow SATA activity LED blinking */
  184. err = gpio_request(NETSPACE_V2_GPIO_BLUE_LED_SLOW, "blue LED slow");
  185. if (err == 0) {
  186. err = gpio_direction_output(NETSPACE_V2_GPIO_BLUE_LED_SLOW, 0);
  187. if (err)
  188. gpio_free(NETSPACE_V2_GPIO_BLUE_LED_SLOW);
  189. }
  190. if (err)
  191. pr_err("netspace_v2: failed to configure blue LED slow GPIO\n");
  192. platform_device_register(&netspace_v2_gpio_leds);
  193. }
  194. /*****************************************************************************
  195. * Timer
  196. ****************************************************************************/
  197. static void netspace_v2_timer_init(void)
  198. {
  199. kirkwood_tclk = 166666667;
  200. orion_time_init(IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
  201. }
  202. struct sys_timer netspace_v2_timer = {
  203. .init = netspace_v2_timer_init,
  204. };
  205. /*****************************************************************************
  206. * General Setup
  207. ****************************************************************************/
  208. static unsigned int netspace_v2_mpp_config[] __initdata = {
  209. MPP0_SPI_SCn,
  210. MPP1_SPI_MOSI,
  211. MPP2_SPI_SCK,
  212. MPP3_SPI_MISO,
  213. MPP4_NF_IO6,
  214. MPP5_NF_IO7,
  215. MPP6_SYSRST_OUTn,
  216. MPP8_TW_SDA,
  217. MPP9_TW_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. MPP18_NF_IO0,
  224. MPP19_NF_IO1,
  225. MPP20_SATA1_ACTn,
  226. MPP21_SATA0_ACTn,
  227. MPP24_GPIO, /* USB mode select */
  228. MPP25_GPIO, /* Fan rotation fail */
  229. MPP26_GPIO, /* USB device vbus */
  230. MPP28_GPIO, /* USB enable host vbus */
  231. MPP29_GPIO, /* Blue led (slow register) */
  232. MPP30_GPIO, /* Blue led (command register) */
  233. MPP31_GPIO, /* Board power off */
  234. MPP32_GPIO, /* Power button (0 = Released, 1 = Pushed) */
  235. 0
  236. };
  237. #define NETSPACE_V2_GPIO_POWER_OFF 31
  238. static void netspace_v2_power_off(void)
  239. {
  240. gpio_set_value(NETSPACE_V2_GPIO_POWER_OFF, 1);
  241. }
  242. static void __init netspace_v2_init(void)
  243. {
  244. /*
  245. * Basic setup. Needs to be called early.
  246. */
  247. kirkwood_init();
  248. kirkwood_mpp_conf(netspace_v2_mpp_config);
  249. netspace_v2_sata_power_init();
  250. kirkwood_ehci_init();
  251. kirkwood_ge00_init(&netspace_v2_ge00_data);
  252. kirkwood_sata_init(&netspace_v2_sata_data);
  253. kirkwood_uart0_init();
  254. spi_register_board_info(netspace_v2_spi_slave_info,
  255. ARRAY_SIZE(netspace_v2_spi_slave_info));
  256. kirkwood_spi_init();
  257. kirkwood_i2c_init();
  258. i2c_register_board_info(0, netspace_v2_i2c_info,
  259. ARRAY_SIZE(netspace_v2_i2c_info));
  260. netspace_v2_gpio_leds_init();
  261. platform_device_register(&netspace_v2_gpio_buttons);
  262. if (gpio_request(NETSPACE_V2_GPIO_POWER_OFF, "power-off") == 0 &&
  263. gpio_direction_output(NETSPACE_V2_GPIO_POWER_OFF, 0) == 0)
  264. pm_power_off = netspace_v2_power_off;
  265. else
  266. pr_err("netspace_v2: failed to configure power-off GPIO\n");
  267. }
  268. #ifdef CONFIG_MACH_NETSPACE_V2
  269. MACHINE_START(NETSPACE_V2, "LaCie Network Space v2")
  270. .phys_io = KIRKWOOD_REGS_PHYS_BASE,
  271. .io_pg_offst = ((KIRKWOOD_REGS_VIRT_BASE) >> 18) & 0xfffc,
  272. .boot_params = 0x00000100,
  273. .init_machine = netspace_v2_init,
  274. .map_io = kirkwood_map_io,
  275. .init_irq = kirkwood_init_irq,
  276. .timer = &netspace_v2_timer,
  277. MACHINE_END
  278. #endif
  279. #ifdef CONFIG_MACH_INETSPACE_V2
  280. MACHINE_START(INETSPACE_V2, "LaCie Internet Space v2")
  281. .phys_io = KIRKWOOD_REGS_PHYS_BASE,
  282. .io_pg_offst = ((KIRKWOOD_REGS_VIRT_BASE) >> 18) & 0xfffc,
  283. .boot_params = 0x00000100,
  284. .init_machine = netspace_v2_init,
  285. .map_io = kirkwood_map_io,
  286. .init_irq = kirkwood_init_irq,
  287. .timer = &netspace_v2_timer,
  288. MACHINE_END
  289. #endif