net2big_v2-setup.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*
  2. * arch/arm/mach-kirkwood/net2big_v2-setup.c
  3. *
  4. * LaCie 2Big 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/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 <plat/time.h>
  41. #include "common.h"
  42. #include "mpp.h"
  43. /*****************************************************************************
  44. * 512KB SPI Flash on Boot Device (MACRONIX MX25L4005)
  45. ****************************************************************************/
  46. static struct mtd_partition net2big_v2_flash_parts[] = {
  47. {
  48. .name = "u-boot",
  49. .size = MTDPART_SIZ_FULL,
  50. .offset = 0,
  51. .mask_flags = MTD_WRITEABLE, /* force read-only */
  52. },
  53. };
  54. static const struct flash_platform_data net2big_v2_flash = {
  55. .type = "mx25l4005a",
  56. .name = "spi_flash",
  57. .parts = net2big_v2_flash_parts,
  58. .nr_parts = ARRAY_SIZE(net2big_v2_flash_parts),
  59. };
  60. static struct spi_board_info __initdata net2big_v2_spi_slave_info[] = {
  61. {
  62. .modalias = "m25p80",
  63. .platform_data = &net2big_v2_flash,
  64. .irq = -1,
  65. .max_speed_hz = 20000000,
  66. .bus_num = 0,
  67. .chip_select = 0,
  68. },
  69. };
  70. /*****************************************************************************
  71. * Ethernet
  72. ****************************************************************************/
  73. static struct mv643xx_eth_platform_data net2big_v2_ge00_data = {
  74. .phy_addr = MV643XX_ETH_PHY_ADDR(8),
  75. };
  76. /*****************************************************************************
  77. * I2C devices
  78. ****************************************************************************/
  79. static struct at24_platform_data at24c04 = {
  80. .byte_len = SZ_4K / 8,
  81. .page_size = 16,
  82. };
  83. /*
  84. * i2c addr | chip | description
  85. * 0x50 | HT24LC04 | eeprom (512B)
  86. */
  87. static struct i2c_board_info __initdata net2big_v2_i2c_info[] = {
  88. {
  89. I2C_BOARD_INFO("24c04", 0x50),
  90. .platform_data = &at24c04,
  91. }
  92. };
  93. /*****************************************************************************
  94. * SATA
  95. ****************************************************************************/
  96. static struct mv_sata_platform_data net2big_v2_sata_data = {
  97. .n_ports = 2,
  98. };
  99. static int __initdata net2big_v2_gpio_hdd_power[] = { 16, 17 };
  100. static void __init net2big_v2_sata_power_init(void)
  101. {
  102. int i;
  103. int err;
  104. /* Power up all hard disks. */
  105. for (i = 0; i < ARRAY_SIZE(net2big_v2_gpio_hdd_power); i++) {
  106. err = gpio_request(net2big_v2_gpio_hdd_power[i], NULL);
  107. if (err == 0) {
  108. err = gpio_direction_output(
  109. net2big_v2_gpio_hdd_power[i], 1);
  110. /* Free the HDD power GPIOs. This allow user-space to
  111. * configure them via the gpiolib sysfs interface. */
  112. gpio_free(net2big_v2_gpio_hdd_power[i]);
  113. }
  114. if (err)
  115. pr_err("net2big_v2: failed to power-up HDD%d\n", i + 1);
  116. }
  117. }
  118. /*****************************************************************************
  119. * GPIO keys
  120. ****************************************************************************/
  121. #define NET2BIG_V2_GPIO_SWITCH_POWER_ON 13
  122. #define NET2BIG_V2_GPIO_SWITCH_POWER_OFF 15
  123. #define NET2BIG_V2_GPIO_FUNC_BUTTON 34
  124. #define NET2BIG_V2_SWITCH_POWER_ON 0x1
  125. #define NET2BIG_V2_SWITCH_POWER_OFF 0x2
  126. static struct gpio_keys_button net2big_v2_buttons[] = {
  127. [0] = {
  128. .type = EV_SW,
  129. .code = NET2BIG_V2_SWITCH_POWER_ON,
  130. .gpio = NET2BIG_V2_GPIO_SWITCH_POWER_ON,
  131. .desc = "Back power switch (on|auto)",
  132. .active_low = 1,
  133. },
  134. [1] = {
  135. .type = EV_SW,
  136. .code = NET2BIG_V2_SWITCH_POWER_OFF,
  137. .gpio = NET2BIG_V2_GPIO_SWITCH_POWER_OFF,
  138. .desc = "Back power switch (auto|off)",
  139. .active_low = 1,
  140. },
  141. [2] = {
  142. .code = KEY_OPTION,
  143. .gpio = NET2BIG_V2_GPIO_FUNC_BUTTON,
  144. .desc = "Function button",
  145. .active_low = 1,
  146. },
  147. };
  148. static struct gpio_keys_platform_data net2big_v2_button_data = {
  149. .buttons = net2big_v2_buttons,
  150. .nbuttons = ARRAY_SIZE(net2big_v2_buttons),
  151. };
  152. static struct platform_device net2big_v2_gpio_buttons = {
  153. .name = "gpio-keys",
  154. .id = -1,
  155. .dev = {
  156. .platform_data = &net2big_v2_button_data,
  157. },
  158. };
  159. /*****************************************************************************
  160. * GPIO LEDs
  161. ****************************************************************************/
  162. /*
  163. * The LEDs are controlled by a CPLD and can be configured through a GPIO
  164. * extension bus:
  165. *
  166. * - address register : bit [0-2] -> GPIO [47-49]
  167. * - data register : bit [0-2] -> GPIO [44-46]
  168. * - enable register : GPIO 29
  169. *
  170. * Address register selection:
  171. *
  172. * addr | register
  173. * ----------------------------
  174. * 0 | front LED
  175. * 1 | front LED brightness
  176. * 2 | HDD LED brightness
  177. * 3 | HDD1 LED
  178. * 4 | HDD2 LED
  179. *
  180. * Data register configuration:
  181. *
  182. * data | LED brightness
  183. * -------------------------------------------------
  184. * 0 | min (off)
  185. * - | -
  186. * 7 | max
  187. *
  188. * data | front LED mode
  189. * -------------------------------------------------
  190. * 0 | fix off
  191. * 1 | fix blue on
  192. * 2 | fix red on
  193. * 3 | blink blue on=1 sec and blue off=1 sec
  194. * 4 | blink red on=1 sec and red off=1 sec
  195. * 5 | blink blue on=2.5 sec and red on=0.5 sec
  196. * 6 | blink blue on=1 sec and red on=1 sec
  197. * 7 | blink blue on=0.5 sec and blue off=2.5 sec
  198. *
  199. * data | HDD LED mode
  200. * -------------------------------------------------
  201. * 0 | fix blue on
  202. * 1 | SATA activity blink
  203. * 2 | fix red on
  204. * 3 | blink blue on=1 sec and blue off=1 sec
  205. * 4 | blink red on=1 sec and red off=1 sec
  206. * 5 | blink blue on=2.5 sec and red on=0.5 sec
  207. * 6 | blink blue on=1 sec and red on=1 sec
  208. * 7 | blink blue on=0.5 sec and blue off=2.5 sec
  209. */
  210. /*****************************************************************************
  211. * Timer
  212. ****************************************************************************/
  213. static void net2big_v2_timer_init(void)
  214. {
  215. kirkwood_tclk = 166666667;
  216. orion_time_init(IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
  217. }
  218. struct sys_timer net2big_v2_timer = {
  219. .init = net2big_v2_timer_init,
  220. };
  221. /*****************************************************************************
  222. * General Setup
  223. ****************************************************************************/
  224. static unsigned int net2big_v2_mpp_config[] __initdata = {
  225. MPP0_SPI_SCn,
  226. MPP1_SPI_MOSI,
  227. MPP2_SPI_SCK,
  228. MPP3_SPI_MISO,
  229. MPP6_SYSRST_OUTn,
  230. MPP7_GPO, /* Request power-off */
  231. MPP8_TW_SDA,
  232. MPP9_TW_SCK,
  233. MPP10_UART0_TXD,
  234. MPP11_UART0_RXD,
  235. MPP13_GPIO, /* Rear power switch (on|auto) */
  236. MPP14_GPIO, /* USB fuse alarm */
  237. MPP15_GPIO, /* Rear power switch (auto|off) */
  238. MPP16_GPIO, /* SATA HDD1 power */
  239. MPP17_GPIO, /* SATA HDD2 power */
  240. MPP20_SATA1_ACTn,
  241. MPP21_SATA0_ACTn,
  242. MPP24_GPIO, /* USB mode select */
  243. MPP26_GPIO, /* USB device vbus */
  244. MPP28_GPIO, /* USB enable host vbus */
  245. MPP29_GPIO, /* GPIO extension ALE */
  246. MPP34_GPIO, /* Rear Push button */
  247. MPP35_GPIO, /* Inhibit switch power-off */
  248. MPP36_GPIO, /* SATA HDD1 presence */
  249. MPP37_GPIO, /* SATA HDD2 presence */
  250. MPP40_GPIO, /* eSATA presence */
  251. MPP44_GPIO, /* GPIO extension (data 0) */
  252. MPP45_GPIO, /* GPIO extension (data 1) */
  253. MPP46_GPIO, /* GPIO extension (data 2) */
  254. MPP47_GPIO, /* GPIO extension (addr 0) */
  255. MPP48_GPIO, /* GPIO extension (addr 1) */
  256. MPP49_GPIO, /* GPIO extension (addr 2) */
  257. 0
  258. };
  259. #define NET2BIG_V2_GPIO_POWER_OFF 7
  260. static void net2big_v2_power_off(void)
  261. {
  262. gpio_set_value(NET2BIG_V2_GPIO_POWER_OFF, 1);
  263. }
  264. static void __init net2big_v2_init(void)
  265. {
  266. /*
  267. * Basic setup. Needs to be called early.
  268. */
  269. kirkwood_init();
  270. kirkwood_mpp_conf(net2big_v2_mpp_config);
  271. net2big_v2_sata_power_init();
  272. kirkwood_ehci_init();
  273. kirkwood_ge00_init(&net2big_v2_ge00_data);
  274. kirkwood_sata_init(&net2big_v2_sata_data);
  275. kirkwood_uart0_init();
  276. spi_register_board_info(net2big_v2_spi_slave_info,
  277. ARRAY_SIZE(net2big_v2_spi_slave_info));
  278. kirkwood_spi_init();
  279. kirkwood_i2c_init();
  280. i2c_register_board_info(0, net2big_v2_i2c_info,
  281. ARRAY_SIZE(net2big_v2_i2c_info));
  282. platform_device_register(&net2big_v2_gpio_buttons);
  283. if (gpio_request(NET2BIG_V2_GPIO_POWER_OFF, "power-off") == 0 &&
  284. gpio_direction_output(NET2BIG_V2_GPIO_POWER_OFF, 0) == 0)
  285. pm_power_off = net2big_v2_power_off;
  286. else
  287. pr_err("net2big_v2: failed to configure power-off GPIO\n");
  288. }
  289. MACHINE_START(NET2BIG_V2, "LaCie 2Big Network v2")
  290. .phys_io = KIRKWOOD_REGS_PHYS_BASE,
  291. .io_pg_offst = ((KIRKWOOD_REGS_VIRT_BASE) >> 18) & 0xfffc,
  292. .boot_params = 0x00000100,
  293. .init_machine = net2big_v2_init,
  294. .map_io = kirkwood_map_io,
  295. .init_irq = kirkwood_init_irq,
  296. .timer = &net2big_v2_timer,
  297. MACHINE_END