d2net-setup.c 9.7 KB

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