net2big-setup.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * arch/arm/mach-orion5x/net2big-setup.c
  4. *
  5. * LaCie 2Big Network NAS setup
  6. *
  7. * Copyright (C) 2009 Simon Guinot <sguinot@lacie.com>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/mtd/physmap.h>
  13. #include <linux/mv643xx_eth.h>
  14. #include <linux/leds.h>
  15. #include <linux/gpio_keys.h>
  16. #include <linux/input.h>
  17. #include <linux/i2c.h>
  18. #include <linux/ata_platform.h>
  19. #include <linux/gpio.h>
  20. #include <linux/gpio/machine.h>
  21. #include <linux/delay.h>
  22. #include <asm/mach-types.h>
  23. #include <asm/mach/arch.h>
  24. #include <plat/orion-gpio.h>
  25. #include "common.h"
  26. #include "mpp.h"
  27. #include "orion5x.h"
  28. /*****************************************************************************
  29. * LaCie 2Big Network Info
  30. ****************************************************************************/
  31. /*
  32. * 512KB NOR flash Device bus boot chip select
  33. */
  34. #define NET2BIG_NOR_BOOT_BASE 0xfff80000
  35. #define NET2BIG_NOR_BOOT_SIZE SZ_512K
  36. /*****************************************************************************
  37. * 512KB NOR Flash on Boot Device
  38. ****************************************************************************/
  39. /*
  40. * TODO: Check write support on flash MX29LV400CBTC-70G
  41. */
  42. static struct mtd_partition net2big_partitions[] = {
  43. {
  44. .name = "Full512kb",
  45. .size = MTDPART_SIZ_FULL,
  46. .offset = 0x00000000,
  47. .mask_flags = MTD_WRITEABLE,
  48. },
  49. };
  50. static struct physmap_flash_data net2big_nor_flash_data = {
  51. .width = 1,
  52. .parts = net2big_partitions,
  53. .nr_parts = ARRAY_SIZE(net2big_partitions),
  54. };
  55. static struct resource net2big_nor_flash_resource = {
  56. .flags = IORESOURCE_MEM,
  57. .start = NET2BIG_NOR_BOOT_BASE,
  58. .end = NET2BIG_NOR_BOOT_BASE
  59. + NET2BIG_NOR_BOOT_SIZE - 1,
  60. };
  61. static struct platform_device net2big_nor_flash = {
  62. .name = "physmap-flash",
  63. .id = 0,
  64. .dev = {
  65. .platform_data = &net2big_nor_flash_data,
  66. },
  67. .num_resources = 1,
  68. .resource = &net2big_nor_flash_resource,
  69. };
  70. /*****************************************************************************
  71. * Ethernet
  72. ****************************************************************************/
  73. static struct mv643xx_eth_platform_data net2big_eth_data = {
  74. .phy_addr = MV643XX_ETH_PHY_ADDR(8),
  75. };
  76. /*****************************************************************************
  77. * I2C devices
  78. ****************************************************************************/
  79. /*
  80. * i2c addr | chip | description
  81. * 0x32 | Ricoh 5C372b | RTC
  82. * 0x50 | HT24LC08 | eeprom (1kB)
  83. */
  84. static struct i2c_board_info __initdata net2big_i2c_devices[] = {
  85. {
  86. I2C_BOARD_INFO("rs5c372b", 0x32),
  87. }, {
  88. I2C_BOARD_INFO("24c08", 0x50),
  89. },
  90. };
  91. /*****************************************************************************
  92. * SATA
  93. ****************************************************************************/
  94. static struct mv_sata_platform_data net2big_sata_data = {
  95. .n_ports = 2,
  96. };
  97. #define NET2BIG_GPIO_SATA_POWER_REQ 19
  98. #define NET2BIG_GPIO_SATA0_POWER 23
  99. #define NET2BIG_GPIO_SATA1_POWER 25
  100. static void __init net2big_sata_power_init(void)
  101. {
  102. int err;
  103. /* Configure GPIOs over MPP max number. */
  104. orion_gpio_set_valid(NET2BIG_GPIO_SATA0_POWER, 1);
  105. orion_gpio_set_valid(NET2BIG_GPIO_SATA1_POWER, 1);
  106. err = gpio_request(NET2BIG_GPIO_SATA0_POWER, "SATA0 power status");
  107. if (err == 0) {
  108. err = gpio_direction_input(NET2BIG_GPIO_SATA0_POWER);
  109. if (err)
  110. gpio_free(NET2BIG_GPIO_SATA0_POWER);
  111. }
  112. if (err) {
  113. pr_err("net2big: failed to setup SATA0 power GPIO\n");
  114. return;
  115. }
  116. err = gpio_request(NET2BIG_GPIO_SATA1_POWER, "SATA1 power status");
  117. if (err == 0) {
  118. err = gpio_direction_input(NET2BIG_GPIO_SATA1_POWER);
  119. if (err)
  120. gpio_free(NET2BIG_GPIO_SATA1_POWER);
  121. }
  122. if (err) {
  123. pr_err("net2big: failed to setup SATA1 power GPIO\n");
  124. goto err_free_1;
  125. }
  126. err = gpio_request(NET2BIG_GPIO_SATA_POWER_REQ, "SATA power request");
  127. if (err == 0) {
  128. err = gpio_direction_output(NET2BIG_GPIO_SATA_POWER_REQ, 0);
  129. if (err)
  130. gpio_free(NET2BIG_GPIO_SATA_POWER_REQ);
  131. }
  132. if (err) {
  133. pr_err("net2big: failed to setup SATA power request GPIO\n");
  134. goto err_free_2;
  135. }
  136. if (gpio_get_value(NET2BIG_GPIO_SATA0_POWER) &&
  137. gpio_get_value(NET2BIG_GPIO_SATA1_POWER)) {
  138. return;
  139. }
  140. /*
  141. * SATA power up on both disk is done by pulling high the CPLD power
  142. * request line. The 300ms delay is related to the CPLD clock and is
  143. * needed to be sure that the CPLD has take into account the low line
  144. * status.
  145. */
  146. msleep(300);
  147. gpio_set_value(NET2BIG_GPIO_SATA_POWER_REQ, 1);
  148. pr_info("net2big: power up SATA hard disks\n");
  149. return;
  150. err_free_2:
  151. gpio_free(NET2BIG_GPIO_SATA1_POWER);
  152. err_free_1:
  153. gpio_free(NET2BIG_GPIO_SATA0_POWER);
  154. return;
  155. }
  156. /*****************************************************************************
  157. * GPIO LEDs
  158. ****************************************************************************/
  159. /*
  160. * The power front LEDs (blue and red) and SATA red LEDs are controlled via a
  161. * single GPIO line and are compatible with the leds-gpio driver.
  162. *
  163. * The SATA blue LEDs have some hardware blink capabilities which are detailed
  164. * in the following array:
  165. *
  166. * SATAx blue LED | SATAx activity | LED state
  167. * | |
  168. * 0 | 0 | blink (rate 300ms)
  169. * 1 | 0 | off
  170. * ? | 1 | on
  171. *
  172. * Notes: The blue and the red front LED's can't be on at the same time.
  173. * Blue LED have priority.
  174. */
  175. #define NET2BIG_GPIO_PWR_RED_LED 6
  176. #define NET2BIG_GPIO_PWR_BLUE_LED 16
  177. #define NET2BIG_GPIO_PWR_LED_BLINK_STOP 7
  178. #define NET2BIG_GPIO_SATA0_RED_LED 11
  179. #define NET2BIG_GPIO_SATA1_RED_LED 10
  180. #define NET2BIG_GPIO_SATA0_BLUE_LED 17
  181. #define NET2BIG_GPIO_SATA1_BLUE_LED 13
  182. static struct gpio_led net2big_leds[] = {
  183. {
  184. .name = "net2big:red:power",
  185. },
  186. {
  187. .name = "net2big:blue:power",
  188. },
  189. {
  190. .name = "net2big:red:sata0",
  191. },
  192. {
  193. .name = "net2big:red:sata1",
  194. },
  195. };
  196. static struct gpiod_lookup_table net2big_leds_gpio_table = {
  197. .dev_id = "leds-gpio",
  198. .table = {
  199. GPIO_LOOKUP_IDX("orion_gpio0", NET2BIG_GPIO_PWR_RED_LED, NULL,
  200. 0, GPIO_ACTIVE_HIGH),
  201. GPIO_LOOKUP_IDX("orion_gpio0", NET2BIG_GPIO_PWR_BLUE_LED, NULL,
  202. 1, GPIO_ACTIVE_HIGH),
  203. GPIO_LOOKUP_IDX("orion_gpio0", NET2BIG_GPIO_SATA0_RED_LED, NULL,
  204. 2, GPIO_ACTIVE_HIGH),
  205. GPIO_LOOKUP_IDX("orion_gpio0", NET2BIG_GPIO_SATA1_RED_LED, NULL,
  206. 3, GPIO_ACTIVE_HIGH),
  207. { },
  208. },
  209. };
  210. static struct gpio_led_platform_data net2big_led_data = {
  211. .num_leds = ARRAY_SIZE(net2big_leds),
  212. .leds = net2big_leds,
  213. };
  214. static struct platform_device net2big_gpio_leds = {
  215. .name = "leds-gpio",
  216. .id = -1,
  217. .dev = {
  218. .platform_data = &net2big_led_data,
  219. },
  220. };
  221. static void __init net2big_gpio_leds_init(void)
  222. {
  223. int err;
  224. /* Stop initial CPLD slow red/blue blinking on power LED. */
  225. err = gpio_request(NET2BIG_GPIO_PWR_LED_BLINK_STOP,
  226. "Power LED blink stop");
  227. if (err == 0) {
  228. err = gpio_direction_output(NET2BIG_GPIO_PWR_LED_BLINK_STOP, 1);
  229. if (err)
  230. gpio_free(NET2BIG_GPIO_PWR_LED_BLINK_STOP);
  231. }
  232. if (err)
  233. pr_err("net2big: failed to setup power LED blink GPIO\n");
  234. /*
  235. * Configure SATA0 and SATA1 blue LEDs to blink in relation with the
  236. * hard disk activity.
  237. */
  238. err = gpio_request(NET2BIG_GPIO_SATA0_BLUE_LED,
  239. "SATA0 blue LED control");
  240. if (err == 0) {
  241. err = gpio_direction_output(NET2BIG_GPIO_SATA0_BLUE_LED, 1);
  242. if (err)
  243. gpio_free(NET2BIG_GPIO_SATA0_BLUE_LED);
  244. }
  245. if (err)
  246. pr_err("net2big: failed to setup SATA0 blue LED GPIO\n");
  247. err = gpio_request(NET2BIG_GPIO_SATA1_BLUE_LED,
  248. "SATA1 blue LED control");
  249. if (err == 0) {
  250. err = gpio_direction_output(NET2BIG_GPIO_SATA1_BLUE_LED, 1);
  251. if (err)
  252. gpio_free(NET2BIG_GPIO_SATA1_BLUE_LED);
  253. }
  254. if (err)
  255. pr_err("net2big: failed to setup SATA1 blue LED GPIO\n");
  256. gpiod_add_lookup_table(&net2big_leds_gpio_table);
  257. platform_device_register(&net2big_gpio_leds);
  258. }
  259. /****************************************************************************
  260. * GPIO keys
  261. ****************************************************************************/
  262. #define NET2BIG_GPIO_PUSH_BUTTON 18
  263. #define NET2BIG_GPIO_POWER_SWITCH_ON 8
  264. #define NET2BIG_GPIO_POWER_SWITCH_OFF 9
  265. #define NET2BIG_SWITCH_POWER_ON 0x1
  266. #define NET2BIG_SWITCH_POWER_OFF 0x2
  267. static struct gpio_keys_button net2big_buttons[] = {
  268. {
  269. .type = EV_SW,
  270. .code = NET2BIG_SWITCH_POWER_OFF,
  271. .gpio = NET2BIG_GPIO_POWER_SWITCH_OFF,
  272. .desc = "Power rocker switch (auto|off)",
  273. .active_low = 0,
  274. },
  275. {
  276. .type = EV_SW,
  277. .code = NET2BIG_SWITCH_POWER_ON,
  278. .gpio = NET2BIG_GPIO_POWER_SWITCH_ON,
  279. .desc = "Power rocker switch (on|auto)",
  280. .active_low = 0,
  281. },
  282. {
  283. .type = EV_KEY,
  284. .code = KEY_POWER,
  285. .gpio = NET2BIG_GPIO_PUSH_BUTTON,
  286. .desc = "Front Push Button",
  287. .active_low = 0,
  288. },
  289. };
  290. static struct gpio_keys_platform_data net2big_button_data = {
  291. .buttons = net2big_buttons,
  292. .nbuttons = ARRAY_SIZE(net2big_buttons),
  293. };
  294. static struct platform_device net2big_gpio_buttons = {
  295. .name = "gpio-keys",
  296. .id = -1,
  297. .dev = {
  298. .platform_data = &net2big_button_data,
  299. },
  300. };
  301. /*****************************************************************************
  302. * General Setup
  303. ****************************************************************************/
  304. static unsigned int net2big_mpp_modes[] __initdata = {
  305. MPP0_GPIO, /* Raid mode (bit 0) */
  306. MPP1_GPIO, /* USB port 2 fuse (0 = Fail, 1 = Ok) */
  307. MPP2_GPIO, /* Raid mode (bit 1) */
  308. MPP3_GPIO, /* Board ID (bit 0) */
  309. MPP4_GPIO, /* Fan activity (0 = Off, 1 = On) */
  310. MPP5_GPIO, /* Fan fail detection */
  311. MPP6_GPIO, /* Red front LED (0 = Off, 1 = On) */
  312. MPP7_GPIO, /* Disable initial blinking on front LED */
  313. MPP8_GPIO, /* Rear power switch (on|auto) */
  314. MPP9_GPIO, /* Rear power switch (auto|off) */
  315. MPP10_GPIO, /* SATA 1 red LED (0 = Off, 1 = On) */
  316. MPP11_GPIO, /* SATA 0 red LED (0 = Off, 1 = On) */
  317. MPP12_GPIO, /* Board ID (bit 1) */
  318. MPP13_GPIO, /* SATA 1 blue LED blink control */
  319. MPP14_SATA_LED,
  320. MPP15_SATA_LED,
  321. MPP16_GPIO, /* Blue front LED control */
  322. MPP17_GPIO, /* SATA 0 blue LED blink control */
  323. MPP18_GPIO, /* Front button (0 = Released, 1 = Pushed ) */
  324. MPP19_GPIO, /* SATA{0,1} power On/Off request */
  325. 0,
  326. /* 22: USB port 1 fuse (0 = Fail, 1 = Ok) */
  327. /* 23: SATA 0 power status */
  328. /* 24: Board power off */
  329. /* 25: SATA 1 power status */
  330. };
  331. #define NET2BIG_GPIO_POWER_OFF 24
  332. static void net2big_power_off(void)
  333. {
  334. gpio_set_value(NET2BIG_GPIO_POWER_OFF, 1);
  335. }
  336. static void __init net2big_init(void)
  337. {
  338. /*
  339. * Setup basic Orion functions. Need to be called early.
  340. */
  341. orion5x_init();
  342. orion5x_mpp_conf(net2big_mpp_modes);
  343. /*
  344. * Configure peripherals.
  345. */
  346. orion5x_ehci0_init();
  347. orion5x_ehci1_init();
  348. orion5x_eth_init(&net2big_eth_data);
  349. orion5x_i2c_init();
  350. orion5x_uart0_init();
  351. orion5x_xor_init();
  352. net2big_sata_power_init();
  353. orion5x_sata_init(&net2big_sata_data);
  354. mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
  355. ORION_MBUS_DEVBUS_BOOT_ATTR,
  356. NET2BIG_NOR_BOOT_BASE,
  357. NET2BIG_NOR_BOOT_SIZE);
  358. platform_device_register(&net2big_nor_flash);
  359. platform_device_register(&net2big_gpio_buttons);
  360. net2big_gpio_leds_init();
  361. i2c_register_board_info(0, net2big_i2c_devices,
  362. ARRAY_SIZE(net2big_i2c_devices));
  363. orion_gpio_set_valid(NET2BIG_GPIO_POWER_OFF, 1);
  364. if (gpio_request(NET2BIG_GPIO_POWER_OFF, "power-off") == 0 &&
  365. gpio_direction_output(NET2BIG_GPIO_POWER_OFF, 0) == 0)
  366. register_platform_power_off(net2big_power_off);
  367. else
  368. pr_err("net2big: failed to configure power-off GPIO\n");
  369. pr_notice("net2big: Flash writing is not yet supported.\n");
  370. }
  371. /* Warning: LaCie use a wrong mach-type (0x20e=526) in their bootloader. */
  372. MACHINE_START(NET2BIG, "LaCie 2Big Network")
  373. .atag_offset = 0x100,
  374. .nr_irqs = ORION5X_NR_IRQS,
  375. .init_machine = net2big_init,
  376. .map_io = orion5x_map_io,
  377. .init_early = orion5x_init_early,
  378. .init_irq = orion5x_init_irq,
  379. .init_time = orion5x_timer_init,
  380. .fixup = tag_fixup_mem32,
  381. .restart = orion5x_restart,
  382. MACHINE_END