d2net-setup.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /*
  2. * arch/arm/mach-orion5x/d2net-setup.c
  3. *
  4. * LaCie d2Network and Big Disk Network NAS setup
  5. *
  6. * Copyright (C) 2009 Simon Guinot <sguinot@lacie.com>
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/pci.h>
  16. #include <linux/irq.h>
  17. #include <linux/mtd/physmap.h>
  18. #include <linux/mv643xx_eth.h>
  19. #include <linux/leds.h>
  20. #include <linux/gpio_keys.h>
  21. #include <linux/input.h>
  22. #include <linux/i2c.h>
  23. #include <linux/ata_platform.h>
  24. #include <linux/gpio.h>
  25. #include <asm/mach-types.h>
  26. #include <asm/mach/arch.h>
  27. #include <asm/mach/pci.h>
  28. #include <mach/orion5x.h>
  29. #include <plat/orion-gpio.h>
  30. #include "common.h"
  31. #include "mpp.h"
  32. /*****************************************************************************
  33. * LaCie d2 Network Info
  34. ****************************************************************************/
  35. /*
  36. * 512KB NOR flash Device bus boot chip select
  37. */
  38. #define D2NET_NOR_BOOT_BASE 0xfff80000
  39. #define D2NET_NOR_BOOT_SIZE SZ_512K
  40. /*****************************************************************************
  41. * 512KB NOR Flash on Boot Device
  42. ****************************************************************************/
  43. /*
  44. * TODO: Check write support on flash MX29LV400CBTC-70G
  45. */
  46. static struct mtd_partition d2net_partitions[] = {
  47. {
  48. .name = "Full512kb",
  49. .size = MTDPART_SIZ_FULL,
  50. .offset = 0,
  51. .mask_flags = MTD_WRITEABLE,
  52. },
  53. };
  54. static struct physmap_flash_data d2net_nor_flash_data = {
  55. .width = 1,
  56. .parts = d2net_partitions,
  57. .nr_parts = ARRAY_SIZE(d2net_partitions),
  58. };
  59. static struct resource d2net_nor_flash_resource = {
  60. .flags = IORESOURCE_MEM,
  61. .start = D2NET_NOR_BOOT_BASE,
  62. .end = D2NET_NOR_BOOT_BASE
  63. + D2NET_NOR_BOOT_SIZE - 1,
  64. };
  65. static struct platform_device d2net_nor_flash = {
  66. .name = "physmap-flash",
  67. .id = 0,
  68. .dev = {
  69. .platform_data = &d2net_nor_flash_data,
  70. },
  71. .num_resources = 1,
  72. .resource = &d2net_nor_flash_resource,
  73. };
  74. /*****************************************************************************
  75. * Ethernet
  76. ****************************************************************************/
  77. static struct mv643xx_eth_platform_data d2net_eth_data = {
  78. .phy_addr = MV643XX_ETH_PHY_ADDR(8),
  79. };
  80. /*****************************************************************************
  81. * I2C devices
  82. ****************************************************************************/
  83. /*
  84. * i2c addr | chip | description
  85. * 0x32 | Ricoh 5C372b | RTC
  86. * 0x3e | GMT G762 | PWM fan controller
  87. * 0x50 | HT24LC08 | eeprom (1kB)
  88. *
  89. * TODO: Add G762 support to the g760a driver.
  90. */
  91. static struct i2c_board_info __initdata d2net_i2c_devices[] = {
  92. {
  93. I2C_BOARD_INFO("rs5c372b", 0x32),
  94. }, {
  95. I2C_BOARD_INFO("24c08", 0x50),
  96. },
  97. };
  98. /*****************************************************************************
  99. * SATA
  100. ****************************************************************************/
  101. static struct mv_sata_platform_data d2net_sata_data = {
  102. .n_ports = 2,
  103. };
  104. #define D2NET_GPIO_SATA0_POWER 3
  105. #define D2NET_GPIO_SATA1_POWER 12
  106. static void __init d2net_sata_power_init(void)
  107. {
  108. int err;
  109. err = gpio_request(D2NET_GPIO_SATA0_POWER, "SATA0 power");
  110. if (err == 0) {
  111. err = gpio_direction_output(D2NET_GPIO_SATA0_POWER, 1);
  112. if (err)
  113. gpio_free(D2NET_GPIO_SATA0_POWER);
  114. }
  115. if (err)
  116. pr_err("d2net: failed to configure SATA0 power GPIO\n");
  117. err = gpio_request(D2NET_GPIO_SATA1_POWER, "SATA1 power");
  118. if (err == 0) {
  119. err = gpio_direction_output(D2NET_GPIO_SATA1_POWER, 1);
  120. if (err)
  121. gpio_free(D2NET_GPIO_SATA1_POWER);
  122. }
  123. if (err)
  124. pr_err("d2net: failed to configure SATA1 power GPIO\n");
  125. }
  126. /*****************************************************************************
  127. * GPIO LED's
  128. ****************************************************************************/
  129. /*
  130. * The blue front LED is wired to the CPLD and can blink in relation with the
  131. * SATA activity.
  132. *
  133. * The following array detail the different LED registers and the combination
  134. * of their possible values:
  135. *
  136. * led_off | blink_ctrl | SATA active | LED state
  137. * | | |
  138. * 1 | x | x | off
  139. * 0 | 0 | 0 | off
  140. * 0 | 1 | 0 | blink (rate 300ms)
  141. * 0 | x | 1 | on
  142. *
  143. * Notes: The blue and the red front LED's can't be on at the same time.
  144. * Red LED have priority.
  145. */
  146. #define D2NET_GPIO_RED_LED 6
  147. #define D2NET_GPIO_BLUE_LED_BLINK_CTRL 16
  148. #define D2NET_GPIO_BLUE_LED_OFF 23
  149. static struct gpio_led d2net_leds[] = {
  150. {
  151. .name = "d2net:blue:sata",
  152. .default_trigger = "default-on",
  153. .gpio = D2NET_GPIO_BLUE_LED_OFF,
  154. .active_low = 1,
  155. },
  156. {
  157. .name = "d2net:red:fail",
  158. .gpio = D2NET_GPIO_RED_LED,
  159. },
  160. };
  161. static struct gpio_led_platform_data d2net_led_data = {
  162. .num_leds = ARRAY_SIZE(d2net_leds),
  163. .leds = d2net_leds,
  164. };
  165. static struct platform_device d2net_gpio_leds = {
  166. .name = "leds-gpio",
  167. .id = -1,
  168. .dev = {
  169. .platform_data = &d2net_led_data,
  170. },
  171. };
  172. static void __init d2net_gpio_leds_init(void)
  173. {
  174. int err;
  175. /* Configure GPIO over MPP max number. */
  176. orion_gpio_set_valid(D2NET_GPIO_BLUE_LED_OFF, 1);
  177. /* Configure register blink_ctrl to allow SATA activity LED blinking. */
  178. err = gpio_request(D2NET_GPIO_BLUE_LED_BLINK_CTRL, "blue LED blink");
  179. if (err == 0) {
  180. err = gpio_direction_output(D2NET_GPIO_BLUE_LED_BLINK_CTRL, 1);
  181. if (err)
  182. gpio_free(D2NET_GPIO_BLUE_LED_BLINK_CTRL);
  183. }
  184. if (err)
  185. pr_err("d2net: failed to configure blue LED blink GPIO\n");
  186. platform_device_register(&d2net_gpio_leds);
  187. }
  188. /****************************************************************************
  189. * GPIO keys
  190. ****************************************************************************/
  191. #define D2NET_GPIO_PUSH_BUTTON 18
  192. #define D2NET_GPIO_POWER_SWITCH_ON 8
  193. #define D2NET_GPIO_POWER_SWITCH_OFF 9
  194. #define D2NET_SWITCH_POWER_ON 0x1
  195. #define D2NET_SWITCH_POWER_OFF 0x2
  196. static struct gpio_keys_button d2net_buttons[] = {
  197. {
  198. .type = EV_SW,
  199. .code = D2NET_SWITCH_POWER_OFF,
  200. .gpio = D2NET_GPIO_POWER_SWITCH_OFF,
  201. .desc = "Power rocker switch (auto|off)",
  202. .active_low = 0,
  203. },
  204. {
  205. .type = EV_SW,
  206. .code = D2NET_SWITCH_POWER_ON,
  207. .gpio = D2NET_GPIO_POWER_SWITCH_ON,
  208. .desc = "Power rocker switch (on|auto)",
  209. .active_low = 0,
  210. },
  211. {
  212. .type = EV_KEY,
  213. .code = KEY_POWER,
  214. .gpio = D2NET_GPIO_PUSH_BUTTON,
  215. .desc = "Front Push Button",
  216. .active_low = 0,
  217. },
  218. };
  219. static struct gpio_keys_platform_data d2net_button_data = {
  220. .buttons = d2net_buttons,
  221. .nbuttons = ARRAY_SIZE(d2net_buttons),
  222. };
  223. static struct platform_device d2net_gpio_buttons = {
  224. .name = "gpio-keys",
  225. .id = -1,
  226. .dev = {
  227. .platform_data = &d2net_button_data,
  228. },
  229. };
  230. /*****************************************************************************
  231. * General Setup
  232. ****************************************************************************/
  233. static unsigned int d2net_mpp_modes[] __initdata = {
  234. MPP0_GPIO, /* Board ID (bit 0) */
  235. MPP1_GPIO, /* Board ID (bit 1) */
  236. MPP2_GPIO, /* Board ID (bit 2) */
  237. MPP3_GPIO, /* SATA 0 power */
  238. MPP4_UNUSED,
  239. MPP5_GPIO, /* Fan fail detection */
  240. MPP6_GPIO, /* Red front LED */
  241. MPP7_UNUSED,
  242. MPP8_GPIO, /* Rear power switch (on|auto) */
  243. MPP9_GPIO, /* Rear power switch (auto|off) */
  244. MPP10_UNUSED,
  245. MPP11_UNUSED,
  246. MPP12_GPIO, /* SATA 1 power */
  247. MPP13_UNUSED,
  248. MPP14_SATA_LED, /* SATA 0 active */
  249. MPP15_SATA_LED, /* SATA 1 active */
  250. MPP16_GPIO, /* Blue front LED blink control */
  251. MPP17_UNUSED,
  252. MPP18_GPIO, /* Front button (0 = Released, 1 = Pushed ) */
  253. MPP19_UNUSED,
  254. 0,
  255. /* 22: USB port 1 fuse (0 = Fail, 1 = Ok) */
  256. /* 23: Blue front LED off */
  257. /* 24: Inhibit board power off (0 = Disabled, 1 = Enabled) */
  258. };
  259. #define D2NET_GPIO_INHIBIT_POWER_OFF 24
  260. static void __init d2net_init(void)
  261. {
  262. /*
  263. * Setup basic Orion functions. Need to be called early.
  264. */
  265. orion5x_init();
  266. orion5x_mpp_conf(d2net_mpp_modes);
  267. /*
  268. * Configure peripherals.
  269. */
  270. orion5x_ehci0_init();
  271. orion5x_eth_init(&d2net_eth_data);
  272. orion5x_i2c_init();
  273. orion5x_uart0_init();
  274. d2net_sata_power_init();
  275. orion5x_sata_init(&d2net_sata_data);
  276. orion5x_setup_dev_boot_win(D2NET_NOR_BOOT_BASE,
  277. D2NET_NOR_BOOT_SIZE);
  278. platform_device_register(&d2net_nor_flash);
  279. platform_device_register(&d2net_gpio_buttons);
  280. d2net_gpio_leds_init();
  281. pr_notice("d2net: Flash write are not yet supported.\n");
  282. i2c_register_board_info(0, d2net_i2c_devices,
  283. ARRAY_SIZE(d2net_i2c_devices));
  284. orion_gpio_set_valid(D2NET_GPIO_INHIBIT_POWER_OFF, 1);
  285. }
  286. /* Warning: LaCie use a wrong mach-type (0x20e=526) in their bootloader. */
  287. #ifdef CONFIG_MACH_D2NET
  288. MACHINE_START(D2NET, "LaCie d2 Network")
  289. .atag_offset = 0x100,
  290. .init_machine = d2net_init,
  291. .map_io = orion5x_map_io,
  292. .init_early = orion5x_init_early,
  293. .init_irq = orion5x_init_irq,
  294. .timer = &orion5x_timer,
  295. .fixup = tag_fixup_mem32,
  296. .restart = orion5x_restart,
  297. MACHINE_END
  298. #endif
  299. #ifdef CONFIG_MACH_BIGDISK
  300. MACHINE_START(BIGDISK, "LaCie Big Disk Network")
  301. .atag_offset = 0x100,
  302. .init_machine = d2net_init,
  303. .map_io = orion5x_map_io,
  304. .init_early = orion5x_init_early,
  305. .init_irq = orion5x_init_irq,
  306. .timer = &orion5x_timer,
  307. .fixup = tag_fixup_mem32,
  308. .restart = orion5x_restart,
  309. MACHINE_END
  310. #endif