terastation_pro2-setup.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. /*
  2. * Buffalo Terastation Pro II/Live Board Setup
  3. *
  4. * Maintainer: Sylver Bruneau <sylver.bruneau@googlemail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/gpio.h>
  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/delay.h>
  18. #include <linux/mtd/physmap.h>
  19. #include <linux/mv643xx_eth.h>
  20. #include <linux/i2c.h>
  21. #include <linux/serial_reg.h>
  22. #include <asm/mach-types.h>
  23. #include <asm/mach/arch.h>
  24. #include <asm/mach/pci.h>
  25. #include "common.h"
  26. #include "mpp.h"
  27. #include "orion5x.h"
  28. /*****************************************************************************
  29. * Terastation Pro 2/Live Info
  30. ****************************************************************************/
  31. /*
  32. * Terastation Pro 2 hardware :
  33. * - Marvell 88F5281-D0
  34. * - Marvell 88SX6042 SATA controller (PCI)
  35. * - Marvell 88E1118 Gigabit Ethernet PHY
  36. * - 256KB NOR flash
  37. * - 128MB of DDR RAM
  38. * - PCIe port (not equipped)
  39. */
  40. /*
  41. * 256K NOR flash Device bus boot chip select
  42. */
  43. #define TSP2_NOR_BOOT_BASE 0xf4000000
  44. #define TSP2_NOR_BOOT_SIZE SZ_256K
  45. /*****************************************************************************
  46. * 256KB NOR Flash on BOOT Device
  47. ****************************************************************************/
  48. static struct physmap_flash_data tsp2_nor_flash_data = {
  49. .width = 1,
  50. };
  51. static struct resource tsp2_nor_flash_resource = {
  52. .flags = IORESOURCE_MEM,
  53. .start = TSP2_NOR_BOOT_BASE,
  54. .end = TSP2_NOR_BOOT_BASE + TSP2_NOR_BOOT_SIZE - 1,
  55. };
  56. static struct platform_device tsp2_nor_flash = {
  57. .name = "physmap-flash",
  58. .id = 0,
  59. .dev = {
  60. .platform_data = &tsp2_nor_flash_data,
  61. },
  62. .num_resources = 1,
  63. .resource = &tsp2_nor_flash_resource,
  64. };
  65. /*****************************************************************************
  66. * PCI
  67. ****************************************************************************/
  68. #define TSP2_PCI_SLOT0_OFFS 7
  69. #define TSP2_PCI_SLOT0_IRQ_PIN 11
  70. static void __init tsp2_pci_preinit(void)
  71. {
  72. int pin;
  73. /*
  74. * Configure PCI GPIO IRQ pins
  75. */
  76. pin = TSP2_PCI_SLOT0_IRQ_PIN;
  77. if (gpio_request(pin, "PCI Int1") == 0) {
  78. if (gpio_direction_input(pin) == 0) {
  79. irq_set_irq_type(gpio_to_irq(pin), IRQ_TYPE_LEVEL_LOW);
  80. } else {
  81. printk(KERN_ERR "tsp2_pci_preinit failed "
  82. "to set_irq_type pin %d\n", pin);
  83. gpio_free(pin);
  84. }
  85. } else {
  86. printk(KERN_ERR "tsp2_pci_preinit failed to "
  87. "gpio_request %d\n", pin);
  88. }
  89. }
  90. static int __init tsp2_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  91. {
  92. int irq;
  93. /*
  94. * Check for devices with hard-wired IRQs.
  95. */
  96. irq = orion5x_pci_map_irq(dev, slot, pin);
  97. if (irq != -1)
  98. return irq;
  99. /*
  100. * PCI IRQs are connected via GPIOs.
  101. */
  102. if (slot == TSP2_PCI_SLOT0_OFFS)
  103. return gpio_to_irq(TSP2_PCI_SLOT0_IRQ_PIN);
  104. return -1;
  105. }
  106. static struct hw_pci tsp2_pci __initdata = {
  107. .nr_controllers = 2,
  108. .preinit = tsp2_pci_preinit,
  109. .setup = orion5x_pci_sys_setup,
  110. .scan = orion5x_pci_sys_scan_bus,
  111. .map_irq = tsp2_pci_map_irq,
  112. };
  113. static int __init tsp2_pci_init(void)
  114. {
  115. if (machine_is_terastation_pro2())
  116. pci_common_init(&tsp2_pci);
  117. return 0;
  118. }
  119. subsys_initcall(tsp2_pci_init);
  120. /*****************************************************************************
  121. * Ethernet
  122. ****************************************************************************/
  123. static struct mv643xx_eth_platform_data tsp2_eth_data = {
  124. .phy_addr = 0,
  125. };
  126. /*****************************************************************************
  127. * RTC 5C372a on I2C bus
  128. ****************************************************************************/
  129. #define TSP2_RTC_GPIO 9
  130. static struct i2c_board_info __initdata tsp2_i2c_rtc = {
  131. I2C_BOARD_INFO("rs5c372a", 0x32),
  132. };
  133. /*****************************************************************************
  134. * Terastation Pro II specific power off method via UART1-attached
  135. * microcontroller
  136. ****************************************************************************/
  137. #define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
  138. static int tsp2_miconread(unsigned char *buf, int count)
  139. {
  140. int i;
  141. int timeout;
  142. for (i = 0; i < count; i++) {
  143. timeout = 10;
  144. while (!(readl(UART1_REG(LSR)) & UART_LSR_DR)) {
  145. if (--timeout == 0)
  146. break;
  147. udelay(1000);
  148. }
  149. if (timeout == 0)
  150. break;
  151. buf[i] = readl(UART1_REG(RX));
  152. }
  153. /* return read bytes */
  154. return i;
  155. }
  156. static int tsp2_miconwrite(const unsigned char *buf, int count)
  157. {
  158. int i = 0;
  159. while (count--) {
  160. while (!(readl(UART1_REG(LSR)) & UART_LSR_THRE))
  161. barrier();
  162. writel(buf[i++], UART1_REG(TX));
  163. }
  164. return 0;
  165. }
  166. static int tsp2_miconsend(const unsigned char *data, int count)
  167. {
  168. int i;
  169. unsigned char checksum = 0;
  170. unsigned char recv_buf[40];
  171. unsigned char send_buf[40];
  172. unsigned char correct_ack[3];
  173. int retry = 2;
  174. /* Generate checksum */
  175. for (i = 0; i < count; i++)
  176. checksum -= data[i];
  177. do {
  178. /* Send data */
  179. tsp2_miconwrite(data, count);
  180. /* send checksum */
  181. tsp2_miconwrite(&checksum, 1);
  182. if (tsp2_miconread(recv_buf, sizeof(recv_buf)) <= 3) {
  183. printk(KERN_ERR ">%s: receive failed.\n", __func__);
  184. /* send preamble to clear the receive buffer */
  185. memset(&send_buf, 0xff, sizeof(send_buf));
  186. tsp2_miconwrite(send_buf, sizeof(send_buf));
  187. /* make dummy reads */
  188. mdelay(100);
  189. tsp2_miconread(recv_buf, sizeof(recv_buf));
  190. } else {
  191. /* Generate expected ack */
  192. correct_ack[0] = 0x01;
  193. correct_ack[1] = data[1];
  194. correct_ack[2] = 0x00;
  195. /* checksum Check */
  196. if ((recv_buf[0] + recv_buf[1] + recv_buf[2] +
  197. recv_buf[3]) & 0xFF) {
  198. printk(KERN_ERR ">%s: Checksum Error : "
  199. "Received data[%02x, %02x, %02x, %02x]"
  200. "\n", __func__, recv_buf[0],
  201. recv_buf[1], recv_buf[2], recv_buf[3]);
  202. } else {
  203. /* Check Received Data */
  204. if (correct_ack[0] == recv_buf[0] &&
  205. correct_ack[1] == recv_buf[1] &&
  206. correct_ack[2] == recv_buf[2]) {
  207. /* Interval for next command */
  208. mdelay(10);
  209. /* Receive ACK */
  210. return 0;
  211. }
  212. }
  213. /* Received NAK or illegal Data */
  214. printk(KERN_ERR ">%s: Error : NAK or Illegal Data "
  215. "Received\n", __func__);
  216. }
  217. } while (retry--);
  218. /* Interval for next command */
  219. mdelay(10);
  220. return -1;
  221. }
  222. static void tsp2_power_off(void)
  223. {
  224. const unsigned char watchdogkill[] = {0x01, 0x35, 0x00};
  225. const unsigned char shutdownwait[] = {0x00, 0x0c};
  226. const unsigned char poweroff[] = {0x00, 0x06};
  227. /* 38400 baud divisor */
  228. const unsigned divisor = ((orion5x_tclk + (8 * 38400)) / (16 * 38400));
  229. pr_info("%s: triggering power-off...\n", __func__);
  230. /* hijack uart1 and reset into sane state (38400,8n1,even parity) */
  231. writel(0x83, UART1_REG(LCR));
  232. writel(divisor & 0xff, UART1_REG(DLL));
  233. writel((divisor >> 8) & 0xff, UART1_REG(DLM));
  234. writel(0x1b, UART1_REG(LCR));
  235. writel(0x00, UART1_REG(IER));
  236. writel(0x07, UART1_REG(FCR));
  237. writel(0x00, UART1_REG(MCR));
  238. /* Send the commands to shutdown the Terastation Pro II */
  239. tsp2_miconsend(watchdogkill, sizeof(watchdogkill)) ;
  240. tsp2_miconsend(shutdownwait, sizeof(shutdownwait)) ;
  241. tsp2_miconsend(poweroff, sizeof(poweroff));
  242. }
  243. /*****************************************************************************
  244. * General Setup
  245. ****************************************************************************/
  246. static unsigned int tsp2_mpp_modes[] __initdata = {
  247. MPP0_PCIE_RST_OUTn,
  248. MPP1_UNUSED,
  249. MPP2_UNUSED,
  250. MPP3_UNUSED,
  251. MPP4_NAND, /* BOOT NAND Flash REn */
  252. MPP5_NAND, /* BOOT NAND Flash WEn */
  253. MPP6_NAND, /* BOOT NAND Flash HREn[0] */
  254. MPP7_NAND, /* BOOT NAND Flash WEn[0] */
  255. MPP8_GPIO, /* MICON int */
  256. MPP9_GPIO, /* RTC int */
  257. MPP10_UNUSED,
  258. MPP11_GPIO, /* PCI Int A */
  259. MPP12_UNUSED,
  260. MPP13_GPIO, /* UPS on UART0 enable */
  261. MPP14_GPIO, /* UPS low battery detection */
  262. MPP15_UNUSED,
  263. MPP16_UART, /* UART1 RXD */
  264. MPP17_UART, /* UART1 TXD */
  265. MPP18_UART, /* UART1 CTSn */
  266. MPP19_UART, /* UART1 RTSn */
  267. 0,
  268. };
  269. static void __init tsp2_init(void)
  270. {
  271. /*
  272. * Setup basic Orion functions. Need to be called early.
  273. */
  274. orion5x_init();
  275. orion5x_mpp_conf(tsp2_mpp_modes);
  276. /*
  277. * Configure peripherals.
  278. */
  279. mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
  280. ORION_MBUS_DEVBUS_BOOT_ATTR,
  281. TSP2_NOR_BOOT_BASE,
  282. TSP2_NOR_BOOT_SIZE);
  283. platform_device_register(&tsp2_nor_flash);
  284. orion5x_ehci0_init();
  285. orion5x_eth_init(&tsp2_eth_data);
  286. orion5x_i2c_init();
  287. orion5x_uart0_init();
  288. orion5x_uart1_init();
  289. /* Get RTC IRQ and register the chip */
  290. if (gpio_request(TSP2_RTC_GPIO, "rtc") == 0) {
  291. if (gpio_direction_input(TSP2_RTC_GPIO) == 0)
  292. tsp2_i2c_rtc.irq = gpio_to_irq(TSP2_RTC_GPIO);
  293. else
  294. gpio_free(TSP2_RTC_GPIO);
  295. }
  296. if (tsp2_i2c_rtc.irq == 0)
  297. pr_warn("tsp2_init: failed to get RTC IRQ\n");
  298. i2c_register_board_info(0, &tsp2_i2c_rtc, 1);
  299. /* register Terastation Pro II specific power-off method */
  300. pm_power_off = tsp2_power_off;
  301. }
  302. MACHINE_START(TERASTATION_PRO2, "Buffalo Terastation Pro II/Live")
  303. /* Maintainer: Sylver Bruneau <sylver.bruneau@googlemail.com> */
  304. .atag_offset = 0x100,
  305. .nr_irqs = ORION5X_NR_IRQS,
  306. .init_machine = tsp2_init,
  307. .map_io = orion5x_map_io,
  308. .init_early = orion5x_init_early,
  309. .init_irq = orion5x_init_irq,
  310. .init_time = orion5x_timer_init,
  311. .fixup = tag_fixup_mem32,
  312. .restart = orion5x_restart,
  313. MACHINE_END