terastation_pro2-setup.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/pci.h>
  15. #include <linux/irq.h>
  16. #include <linux/delay.h>
  17. #include <linux/mtd/physmap.h>
  18. #include <linux/mv643xx_eth.h>
  19. #include <linux/i2c.h>
  20. #include <linux/serial_reg.h>
  21. #include <asm/mach-types.h>
  22. #include <asm/gpio.h>
  23. #include <asm/mach/arch.h>
  24. #include <asm/mach/pci.h>
  25. #include <mach/orion5x.h>
  26. #include "common.h"
  27. #include "mpp.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. 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. 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(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. .swizzle = pci_std_swizzle,
  110. .setup = orion5x_pci_sys_setup,
  111. .scan = orion5x_pci_sys_scan_bus,
  112. .map_irq = tsp2_pci_map_irq,
  113. };
  114. static int __init tsp2_pci_init(void)
  115. {
  116. if (machine_is_terastation_pro2())
  117. pci_common_init(&tsp2_pci);
  118. return 0;
  119. }
  120. subsys_initcall(tsp2_pci_init);
  121. /*****************************************************************************
  122. * Ethernet
  123. ****************************************************************************/
  124. static struct mv643xx_eth_platform_data tsp2_eth_data = {
  125. .phy_addr = 0,
  126. };
  127. /*****************************************************************************
  128. * RTC 5C372a on I2C bus
  129. ****************************************************************************/
  130. #define TSP2_RTC_GPIO 9
  131. static struct i2c_board_info __initdata tsp2_i2c_rtc = {
  132. I2C_BOARD_INFO("rs5c372a", 0x32),
  133. };
  134. /*****************************************************************************
  135. * Terastation Pro II specific power off method via UART1-attached
  136. * microcontroller
  137. ****************************************************************************/
  138. #define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
  139. static int tsp2_miconread(unsigned char *buf, int count)
  140. {
  141. int i;
  142. int timeout;
  143. for (i = 0; i < count; i++) {
  144. timeout = 10;
  145. while (!(readl(UART1_REG(LSR)) & UART_LSR_DR)) {
  146. if (--timeout == 0)
  147. break;
  148. udelay(1000);
  149. }
  150. if (timeout == 0)
  151. break;
  152. buf[i] = readl(UART1_REG(RX));
  153. }
  154. /* return read bytes */
  155. return i;
  156. }
  157. static int tsp2_miconwrite(const unsigned char *buf, int count)
  158. {
  159. int i = 0;
  160. while (count--) {
  161. while (!(readl(UART1_REG(LSR)) & UART_LSR_THRE))
  162. barrier();
  163. writel(buf[i++], UART1_REG(TX));
  164. }
  165. return 0;
  166. }
  167. static int tsp2_miconsend(const unsigned char *data, int count)
  168. {
  169. int i;
  170. unsigned char checksum = 0;
  171. unsigned char recv_buf[40];
  172. unsigned char send_buf[40];
  173. unsigned char correct_ack[3];
  174. int retry = 2;
  175. /* Generate checksum */
  176. for (i = 0; i < count; i++)
  177. checksum -= data[i];
  178. do {
  179. /* Send data */
  180. tsp2_miconwrite(data, count);
  181. /* send checksum */
  182. tsp2_miconwrite(&checksum, 1);
  183. if (tsp2_miconread(recv_buf, sizeof(recv_buf)) <= 3) {
  184. printk(KERN_ERR ">%s: receive failed.\n", __func__);
  185. /* send preamble to clear the receive buffer */
  186. memset(&send_buf, 0xff, sizeof(send_buf));
  187. tsp2_miconwrite(send_buf, sizeof(send_buf));
  188. /* make dummy reads */
  189. mdelay(100);
  190. tsp2_miconread(recv_buf, sizeof(recv_buf));
  191. } else {
  192. /* Generate expected ack */
  193. correct_ack[0] = 0x01;
  194. correct_ack[1] = data[1];
  195. correct_ack[2] = 0x00;
  196. /* checksum Check */
  197. if ((recv_buf[0] + recv_buf[1] + recv_buf[2] +
  198. recv_buf[3]) & 0xFF) {
  199. printk(KERN_ERR ">%s: Checksum Error : "
  200. "Received data[%02x, %02x, %02x, %02x]"
  201. "\n", __func__, recv_buf[0],
  202. recv_buf[1], recv_buf[2], recv_buf[3]);
  203. } else {
  204. /* Check Received Data */
  205. if (correct_ack[0] == recv_buf[0] &&
  206. correct_ack[1] == recv_buf[1] &&
  207. correct_ack[2] == recv_buf[2]) {
  208. /* Interval for next command */
  209. mdelay(10);
  210. /* Receive ACK */
  211. return 0;
  212. }
  213. }
  214. /* Received NAK or illegal Data */
  215. printk(KERN_ERR ">%s: Error : NAK or Illegal Data "
  216. "Received\n", __func__);
  217. }
  218. } while (retry--);
  219. /* Interval for next command */
  220. mdelay(10);
  221. return -1;
  222. }
  223. static void tsp2_power_off(void)
  224. {
  225. const unsigned char watchdogkill[] = {0x01, 0x35, 0x00};
  226. const unsigned char shutdownwait[] = {0x00, 0x0c};
  227. const unsigned char poweroff[] = {0x00, 0x06};
  228. /* 38400 baud divisor */
  229. const unsigned divisor = ((orion5x_tclk + (8 * 38400)) / (16 * 38400));
  230. pr_info("%s: triggering power-off...\n", __func__);
  231. /* hijack uart1 and reset into sane state (38400,8n1,even parity) */
  232. writel(0x83, UART1_REG(LCR));
  233. writel(divisor & 0xff, UART1_REG(DLL));
  234. writel((divisor >> 8) & 0xff, UART1_REG(DLM));
  235. writel(0x1b, UART1_REG(LCR));
  236. writel(0x00, UART1_REG(IER));
  237. writel(0x07, UART1_REG(FCR));
  238. writel(0x00, UART1_REG(MCR));
  239. /* Send the commands to shutdown the Terastation Pro II */
  240. tsp2_miconsend(watchdogkill, sizeof(watchdogkill)) ;
  241. tsp2_miconsend(shutdownwait, sizeof(shutdownwait)) ;
  242. tsp2_miconsend(poweroff, sizeof(poweroff));
  243. }
  244. /*****************************************************************************
  245. * General Setup
  246. ****************************************************************************/
  247. static struct orion5x_mpp_mode tsp2_mpp_modes[] __initdata = {
  248. { 0, MPP_PCIE_RST_OUTn },
  249. { 1, MPP_UNUSED },
  250. { 2, MPP_UNUSED },
  251. { 3, MPP_UNUSED },
  252. { 4, MPP_NAND }, /* BOOT NAND Flash REn */
  253. { 5, MPP_NAND }, /* BOOT NAND Flash WEn */
  254. { 6, MPP_NAND }, /* BOOT NAND Flash HREn[0] */
  255. { 7, MPP_NAND }, /* BOOT NAND Flash WEn[0] */
  256. { 8, MPP_GPIO }, /* MICON int */
  257. { 9, MPP_GPIO }, /* RTC int */
  258. { 10, MPP_UNUSED },
  259. { 11, MPP_GPIO }, /* PCI Int A */
  260. { 12, MPP_UNUSED },
  261. { 13, MPP_GPIO }, /* UPS on UART0 enable */
  262. { 14, MPP_GPIO }, /* UPS low battery detection */
  263. { 15, MPP_UNUSED },
  264. { 16, MPP_UART }, /* UART1 RXD */
  265. { 17, MPP_UART }, /* UART1 TXD */
  266. { 18, MPP_UART }, /* UART1 CTSn */
  267. { 19, MPP_UART }, /* UART1 RTSn */
  268. { -1 },
  269. };
  270. static void __init tsp2_init(void)
  271. {
  272. /*
  273. * Setup basic Orion functions. Need to be called early.
  274. */
  275. orion5x_init();
  276. orion5x_mpp_conf(tsp2_mpp_modes);
  277. /*
  278. * Configure peripherals.
  279. */
  280. orion5x_setup_dev_boot_win(TSP2_NOR_BOOT_BASE,
  281. TSP2_NOR_BOOT_SIZE);
  282. platform_device_register(&tsp2_nor_flash);
  283. orion5x_ehci0_init();
  284. orion5x_eth_init(&tsp2_eth_data);
  285. orion5x_i2c_init();
  286. orion5x_uart0_init();
  287. orion5x_uart1_init();
  288. /* Get RTC IRQ and register the chip */
  289. if (gpio_request(TSP2_RTC_GPIO, "rtc") == 0) {
  290. if (gpio_direction_input(TSP2_RTC_GPIO) == 0)
  291. tsp2_i2c_rtc.irq = gpio_to_irq(TSP2_RTC_GPIO);
  292. else
  293. gpio_free(TSP2_RTC_GPIO);
  294. }
  295. if (tsp2_i2c_rtc.irq == 0)
  296. pr_warning("tsp2_init: failed to get RTC IRQ\n");
  297. i2c_register_board_info(0, &tsp2_i2c_rtc, 1);
  298. /* register Terastation Pro II specific power-off method */
  299. pm_power_off = tsp2_power_off;
  300. }
  301. MACHINE_START(TERASTATION_PRO2, "Buffalo Terastation Pro II/Live")
  302. /* Maintainer: Sylver Bruneau <sylver.bruneau@googlemail.com> */
  303. .phys_io = ORION5X_REGS_PHYS_BASE,
  304. .io_pg_offst = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
  305. .boot_params = 0x00000100,
  306. .init_machine = tsp2_init,
  307. .map_io = orion5x_map_io,
  308. .init_irq = orion5x_init_irq,
  309. .timer = &orion5x_timer,
  310. .fixup = tag_fixup_mem32,
  311. MACHINE_END