ts219-setup.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. *
  3. * QNAP TS-119/TS-219 Turbo NAS Board Setup
  4. *
  5. * Copyright (C) 2009 Martin Michlmayr <tbm@cyrius.com>
  6. * Copyright (C) 2008 Byron Bradley <byron.bbradley@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/mtd/physmap.h>
  17. #include <linux/spi/flash.h>
  18. #include <linux/spi/spi.h>
  19. #include <linux/spi/orion_spi.h>
  20. #include <linux/i2c.h>
  21. #include <linux/mv643xx_eth.h>
  22. #include <linux/ata_platform.h>
  23. #include <linux/gpio_keys.h>
  24. #include <linux/input.h>
  25. #include <linux/timex.h>
  26. #include <linux/serial_reg.h>
  27. #include <linux/pci.h>
  28. #include <asm/mach-types.h>
  29. #include <asm/mach/arch.h>
  30. #include <mach/kirkwood.h>
  31. #include "common.h"
  32. #include "mpp.h"
  33. /****************************************************************************
  34. * 16 MiB NOR flash. The struct mtd_partition is not in the same order as the
  35. * partitions on the device because we want to keep compatability with
  36. * the QNAP firmware.
  37. * Layout as used by QNAP:
  38. * 0x00000000-0x00080000 : "U-Boot"
  39. * 0x00200000-0x00400000 : "Kernel"
  40. * 0x00400000-0x00d00000 : "RootFS"
  41. * 0x00d00000-0x01000000 : "RootFS2"
  42. * 0x00080000-0x000c0000 : "U-Boot Config"
  43. * 0x000c0000-0x00200000 : "NAS Config"
  44. *
  45. * We'll use "RootFS1" instead of "RootFS" to stay compatible with the layout
  46. * used by the QNAP TS-109/TS-209.
  47. *
  48. ***************************************************************************/
  49. static struct mtd_partition qnap_ts219_partitions[] = {
  50. {
  51. .name = "U-Boot",
  52. .size = 0x00080000,
  53. .offset = 0,
  54. .mask_flags = MTD_WRITEABLE,
  55. }, {
  56. .name = "Kernel",
  57. .size = 0x00200000,
  58. .offset = 0x00200000,
  59. }, {
  60. .name = "RootFS1",
  61. .size = 0x00900000,
  62. .offset = 0x00400000,
  63. }, {
  64. .name = "RootFS2",
  65. .size = 0x00300000,
  66. .offset = 0x00d00000,
  67. }, {
  68. .name = "U-Boot Config",
  69. .size = 0x00040000,
  70. .offset = 0x00080000,
  71. }, {
  72. .name = "NAS Config",
  73. .size = 0x00140000,
  74. .offset = 0x000c0000,
  75. },
  76. };
  77. static const struct flash_platform_data qnap_ts219_flash = {
  78. .type = "m25p128",
  79. .name = "spi_flash",
  80. .parts = qnap_ts219_partitions,
  81. .nr_parts = ARRAY_SIZE(qnap_ts219_partitions),
  82. };
  83. static struct spi_board_info __initdata qnap_ts219_spi_slave_info[] = {
  84. {
  85. .modalias = "m25p80",
  86. .platform_data = &qnap_ts219_flash,
  87. .irq = -1,
  88. .max_speed_hz = 20000000,
  89. .bus_num = 0,
  90. .chip_select = 0,
  91. },
  92. };
  93. static struct i2c_board_info __initdata qnap_ts219_i2c_rtc = {
  94. I2C_BOARD_INFO("s35390a", 0x30),
  95. };
  96. static struct mv643xx_eth_platform_data qnap_ts219_ge00_data = {
  97. .phy_addr = MV643XX_ETH_PHY_ADDR(8),
  98. };
  99. static struct mv_sata_platform_data qnap_ts219_sata_data = {
  100. .n_ports = 2,
  101. };
  102. static struct gpio_keys_button qnap_ts219_buttons[] = {
  103. {
  104. .code = KEY_COPY,
  105. .gpio = 15,
  106. .desc = "USB Copy",
  107. .active_low = 1,
  108. },
  109. {
  110. .code = KEY_RESTART,
  111. .gpio = 16,
  112. .desc = "Reset",
  113. .active_low = 1,
  114. },
  115. };
  116. static struct gpio_keys_platform_data qnap_ts219_button_data = {
  117. .buttons = qnap_ts219_buttons,
  118. .nbuttons = ARRAY_SIZE(qnap_ts219_buttons),
  119. };
  120. static struct platform_device qnap_ts219_button_device = {
  121. .name = "gpio-keys",
  122. .id = -1,
  123. .num_resources = 0,
  124. .dev = {
  125. .platform_data = &qnap_ts219_button_data,
  126. }
  127. };
  128. static unsigned int qnap_ts219_mpp_config[] __initdata = {
  129. MPP0_SPI_SCn,
  130. MPP1_SPI_MOSI,
  131. MPP2_SPI_SCK,
  132. MPP3_SPI_MISO,
  133. MPP4_SATA1_ACTn,
  134. MPP5_SATA0_ACTn,
  135. MPP8_TW_SDA,
  136. MPP9_TW_SCK,
  137. MPP10_UART0_TXD,
  138. MPP11_UART0_RXD,
  139. MPP13_UART1_TXD, /* PIC controller */
  140. MPP14_UART1_RXD, /* PIC controller */
  141. MPP15_GPIO, /* USB Copy button */
  142. MPP16_GPIO, /* Reset button */
  143. 0
  144. };
  145. /*****************************************************************************
  146. * QNAP TS-x19 specific power off method via UART1-attached PIC
  147. ****************************************************************************/
  148. #define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
  149. void qnap_ts219_power_off(void)
  150. {
  151. /* 19200 baud divisor */
  152. const unsigned divisor = ((kirkwood_tclk + (8 * 19200)) / (16 * 19200));
  153. pr_info("%s: triggering power-off...\n", __func__);
  154. /* hijack UART1 and reset into sane state (19200,8n1) */
  155. writel(0x83, UART1_REG(LCR));
  156. writel(divisor & 0xff, UART1_REG(DLL));
  157. writel((divisor >> 8) & 0xff, UART1_REG(DLM));
  158. writel(0x03, UART1_REG(LCR));
  159. writel(0x00, UART1_REG(IER));
  160. writel(0x00, UART1_REG(FCR));
  161. writel(0x00, UART1_REG(MCR));
  162. /* send the power-off command 'A' to PIC */
  163. writel('A', UART1_REG(TX));
  164. }
  165. static void __init qnap_ts219_init(void)
  166. {
  167. /*
  168. * Basic setup. Needs to be called early.
  169. */
  170. kirkwood_init();
  171. kirkwood_mpp_conf(qnap_ts219_mpp_config);
  172. kirkwood_uart0_init();
  173. kirkwood_uart1_init(); /* A PIC controller is connected here. */
  174. spi_register_board_info(qnap_ts219_spi_slave_info,
  175. ARRAY_SIZE(qnap_ts219_spi_slave_info));
  176. kirkwood_spi_init();
  177. kirkwood_i2c_init();
  178. i2c_register_board_info(0, &qnap_ts219_i2c_rtc, 1);
  179. kirkwood_ge00_init(&qnap_ts219_ge00_data);
  180. kirkwood_sata_init(&qnap_ts219_sata_data);
  181. kirkwood_ehci_init();
  182. platform_device_register(&qnap_ts219_button_device);
  183. pm_power_off = qnap_ts219_power_off;
  184. }
  185. static int __init ts219_pci_init(void)
  186. {
  187. if (machine_is_ts219())
  188. kirkwood_pcie_init();
  189. return 0;
  190. }
  191. subsys_initcall(ts219_pci_init);
  192. MACHINE_START(TS219, "QNAP TS-119/TS-219")
  193. /* Maintainer: Martin Michlmayr <tbm@cyrius.com> */
  194. .phys_io = KIRKWOOD_REGS_PHYS_BASE,
  195. .io_pg_offst = ((KIRKWOOD_REGS_VIRT_BASE) >> 18) & 0xfffc,
  196. .boot_params = 0x00000100,
  197. .init_machine = qnap_ts219_init,
  198. .map_io = kirkwood_map_io,
  199. .init_irq = kirkwood_init_irq,
  200. .timer = &kirkwood_timer,
  201. MACHINE_END