ts209-setup.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /*
  2. * QNAP TS-109/TS-209 Board Setup
  3. *
  4. * Maintainer: Byron Bradley <byron.bbradley@gmail.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/mtd/physmap.h>
  17. #include <linux/mtd/nand.h>
  18. #include <linux/mv643xx_eth.h>
  19. #include <linux/gpio_keys.h>
  20. #include <linux/input.h>
  21. #include <linux/i2c.h>
  22. #include <linux/serial_reg.h>
  23. #include <linux/ata_platform.h>
  24. #include <asm/mach-types.h>
  25. #include <asm/gpio.h>
  26. #include <asm/mach/arch.h>
  27. #include <asm/mach/pci.h>
  28. #include <asm/arch/orion.h>
  29. #include <asm/arch/platform.h>
  30. #include "common.h"
  31. #define QNAP_TS209_NOR_BOOT_BASE 0xf4000000
  32. #define QNAP_TS209_NOR_BOOT_SIZE SZ_8M
  33. /****************************************************************************
  34. * 8MiB 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. * existing QNAP firmware.
  37. *
  38. * Layout as used by QNAP:
  39. * [2] 0x00000000-0x00200000 : "Kernel"
  40. * [3] 0x00200000-0x00600000 : "RootFS1"
  41. * [4] 0x00600000-0x00700000 : "RootFS2"
  42. * [6] 0x00700000-0x00760000 : "NAS Config" (read-only)
  43. * [5] 0x00760000-0x00780000 : "U-Boot Config"
  44. * [1] 0x00780000-0x00800000 : "U-Boot" (read-only)
  45. ***************************************************************************/
  46. static struct mtd_partition qnap_ts209_partitions[] = {
  47. {
  48. .name = "U-Boot",
  49. .size = 0x00080000,
  50. .offset = 0x00780000,
  51. .mask_flags = MTD_WRITEABLE,
  52. }, {
  53. .name = "Kernel",
  54. .size = 0x00200000,
  55. .offset = 0,
  56. }, {
  57. .name = "RootFS1",
  58. .size = 0x00400000,
  59. .offset = 0x00200000,
  60. }, {
  61. .name = "RootFS2",
  62. .size = 0x00100000,
  63. .offset = 0x00600000,
  64. }, {
  65. .name = "U-Boot Config",
  66. .size = 0x00020000,
  67. .offset = 0x00760000,
  68. }, {
  69. .name = "NAS Config",
  70. .size = 0x00060000,
  71. .offset = 0x00700000,
  72. .mask_flags = MTD_WRITEABLE,
  73. }
  74. };
  75. static struct physmap_flash_data qnap_ts209_nor_flash_data = {
  76. .width = 1,
  77. .parts = qnap_ts209_partitions,
  78. .nr_parts = ARRAY_SIZE(qnap_ts209_partitions)
  79. };
  80. static struct resource qnap_ts209_nor_flash_resource = {
  81. .flags = IORESOURCE_MEM,
  82. .start = QNAP_TS209_NOR_BOOT_BASE,
  83. .end = QNAP_TS209_NOR_BOOT_BASE + QNAP_TS209_NOR_BOOT_SIZE - 1,
  84. };
  85. static struct platform_device qnap_ts209_nor_flash = {
  86. .name = "physmap-flash",
  87. .id = 0,
  88. .dev = { .platform_data = &qnap_ts209_nor_flash_data, },
  89. .resource = &qnap_ts209_nor_flash_resource,
  90. .num_resources = 1,
  91. };
  92. /*****************************************************************************
  93. * PCI
  94. ****************************************************************************/
  95. #define QNAP_TS209_PCI_SLOT0_OFFS 7
  96. #define QNAP_TS209_PCI_SLOT0_IRQ_PIN 6
  97. #define QNAP_TS209_PCI_SLOT1_IRQ_PIN 7
  98. void __init qnap_ts209_pci_preinit(void)
  99. {
  100. int pin;
  101. /*
  102. * Configure PCI GPIO IRQ pins
  103. */
  104. pin = QNAP_TS209_PCI_SLOT0_IRQ_PIN;
  105. if (gpio_request(pin, "PCI Int1") == 0) {
  106. if (gpio_direction_input(pin) == 0) {
  107. set_irq_type(gpio_to_irq(pin), IRQT_LOW);
  108. } else {
  109. printk(KERN_ERR "qnap_ts209_pci_preinit failed to "
  110. "set_irq_type pin %d\n", pin);
  111. gpio_free(pin);
  112. }
  113. } else {
  114. printk(KERN_ERR "qnap_ts209_pci_preinit failed to gpio_request "
  115. "%d\n", pin);
  116. }
  117. pin = QNAP_TS209_PCI_SLOT1_IRQ_PIN;
  118. if (gpio_request(pin, "PCI Int2") == 0) {
  119. if (gpio_direction_input(pin) == 0) {
  120. set_irq_type(gpio_to_irq(pin), IRQT_LOW);
  121. } else {
  122. printk(KERN_ERR "qnap_ts209_pci_preinit failed "
  123. "to set_irq_type pin %d\n", pin);
  124. gpio_free(pin);
  125. }
  126. } else {
  127. printk(KERN_ERR "qnap_ts209_pci_preinit failed to gpio_request "
  128. "%d\n", pin);
  129. }
  130. }
  131. static int __init qnap_ts209_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  132. {
  133. /*
  134. * PCIE IRQ is connected internally (not GPIO)
  135. */
  136. if (dev->bus->number == orion_pcie_local_bus_nr())
  137. return IRQ_ORION_PCIE0_INT;
  138. /*
  139. * PCI IRQs are connected via GPIOs
  140. */
  141. switch (slot - QNAP_TS209_PCI_SLOT0_OFFS) {
  142. case 0:
  143. return gpio_to_irq(QNAP_TS209_PCI_SLOT0_IRQ_PIN);
  144. case 1:
  145. return gpio_to_irq(QNAP_TS209_PCI_SLOT1_IRQ_PIN);
  146. default:
  147. return -1;
  148. }
  149. }
  150. static struct hw_pci qnap_ts209_pci __initdata = {
  151. .nr_controllers = 2,
  152. .preinit = qnap_ts209_pci_preinit,
  153. .swizzle = pci_std_swizzle,
  154. .setup = orion_pci_sys_setup,
  155. .scan = orion_pci_sys_scan_bus,
  156. .map_irq = qnap_ts209_pci_map_irq,
  157. };
  158. static int __init qnap_ts209_pci_init(void)
  159. {
  160. if (machine_is_ts_x09())
  161. pci_common_init(&qnap_ts209_pci);
  162. return 0;
  163. }
  164. subsys_initcall(qnap_ts209_pci_init);
  165. /*****************************************************************************
  166. * Ethernet
  167. ****************************************************************************/
  168. static struct mv643xx_eth_platform_data qnap_ts209_eth_data = {
  169. .phy_addr = 8,
  170. .force_phy_addr = 1,
  171. };
  172. /*****************************************************************************
  173. * RTC S35390A on I2C bus
  174. ****************************************************************************/
  175. static struct i2c_board_info __initdata qnap_ts209_i2c_rtc = {
  176. .driver_name = "rtc-s35390a",
  177. .addr = 0x30,
  178. };
  179. /****************************************************************************
  180. * GPIO Attached Keys
  181. * Power button is attached to the PIC microcontroller
  182. ****************************************************************************/
  183. #define QNAP_TS209_GPIO_KEY_MEDIA 1
  184. #define QNAP_TS209_GPIO_KEY_RESET 2
  185. static struct gpio_keys_button qnap_ts209_buttons[] = {
  186. {
  187. .code = KEY_RESTART,
  188. .gpio = QNAP_TS209_GPIO_KEY_MEDIA,
  189. .desc = "USB Copy Button",
  190. .active_low = 1,
  191. },
  192. {
  193. .code = KEY_POWER,
  194. .gpio = QNAP_TS209_GPIO_KEY_RESET,
  195. .desc = "Reset Button",
  196. .active_low = 1,
  197. }
  198. };
  199. static struct gpio_keys_platform_data qnap_ts209_button_data = {
  200. .buttons = qnap_ts209_buttons,
  201. .nbuttons = ARRAY_SIZE(qnap_ts209_buttons),
  202. };
  203. static struct platform_device qnap_ts209_button_device = {
  204. .name = "gpio-keys",
  205. .id = -1,
  206. .num_resources = 0,
  207. .dev = { .platform_data = &qnap_ts209_button_data, },
  208. };
  209. /*****************************************************************************
  210. * SATA
  211. ****************************************************************************/
  212. static struct mv_sata_platform_data qnap_ts209_sata_data = {
  213. .n_ports = 2,
  214. };
  215. /*****************************************************************************
  216. * General Setup
  217. ****************************************************************************/
  218. static struct platform_device *qnap_ts209_devices[] __initdata = {
  219. &qnap_ts209_nor_flash,
  220. &qnap_ts209_button_device,
  221. };
  222. /*
  223. * QNAP TS-[12]09 specific power off method via UART1-attached PIC
  224. */
  225. #define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
  226. static void qnap_ts209_power_off(void)
  227. {
  228. /* 19200 baud divisor */
  229. const unsigned divisor = ((ORION_TCLK + (8 * 19200)) / (16 * 19200));
  230. pr_info("%s: triggering power-off...\n", __func__);
  231. /* hijack uart1 and reset into sane state (19200,8n1) */
  232. orion_write(UART1_REG(LCR), 0x83);
  233. orion_write(UART1_REG(DLL), divisor & 0xff);
  234. orion_write(UART1_REG(DLM), (divisor >> 8) & 0xff);
  235. orion_write(UART1_REG(LCR), 0x03);
  236. orion_write(UART1_REG(IER), 0x00);
  237. orion_write(UART1_REG(FCR), 0x00);
  238. orion_write(UART1_REG(MCR), 0x00);
  239. /* send the power-off command 'A' to PIC */
  240. orion_write(UART1_REG(TX), 'A');
  241. }
  242. static void __init qnap_ts209_init(void)
  243. {
  244. /*
  245. * Setup basic Orion functions. Need to be called early.
  246. */
  247. orion_init();
  248. /*
  249. * Setup flash mapping
  250. */
  251. orion_setup_cpu_win(ORION_DEV_BOOT, QNAP_TS209_NOR_BOOT_BASE,
  252. QNAP_TS209_NOR_BOOT_SIZE, -1);
  253. /*
  254. * Open a special address decode windows for the PCIE WA.
  255. */
  256. orion_write(ORION_REGS_VIRT_BASE | 0x20074, ORION_PCIE_WA_PHYS_BASE);
  257. orion_write(ORION_REGS_VIRT_BASE | 0x20070, (0x7941 |
  258. (((ORION_PCIE_WA_SIZE >> 16) - 1)) << 16));
  259. /*
  260. * Setup Multiplexing Pins --
  261. * MPP[0] Reserved
  262. * MPP[1] USB copy button (0 active)
  263. * MPP[2] Load defaults button (0 active)
  264. * MPP[3] GPIO RTC
  265. * MPP[4-5] Reserved
  266. * MPP[6] PCI Int A
  267. * MPP[7] PCI Int B
  268. * MPP[8-11] Reserved
  269. * MPP[12] SATA 0 presence
  270. * MPP[13] SATA 1 presence
  271. * MPP[14] SATA 0 active
  272. * MPP[15] SATA 1 active
  273. * MPP[16] UART1 RXD
  274. * MPP[17] UART1 TXD
  275. * MPP[18] SW_RST (0 active)
  276. * MPP[19] Reserved
  277. * MPP[20] PCI clock 0
  278. * MPP[21] PCI clock 1
  279. * MPP[22] USB 0 over current
  280. * MPP[23-25] Reserved
  281. */
  282. orion_write(MPP_0_7_CTRL, 0x3);
  283. orion_write(MPP_8_15_CTRL, 0x55550000);
  284. orion_write(MPP_16_19_CTRL, 0x5500);
  285. orion_gpio_set_valid_pins(0x3cc0fff);
  286. /* register ts209 specific power-off method */
  287. pm_power_off = qnap_ts209_power_off;
  288. platform_add_devices(qnap_ts209_devices,
  289. ARRAY_SIZE(qnap_ts209_devices));
  290. i2c_register_board_info(0, &qnap_ts209_i2c_rtc, 1);
  291. orion_eth_init(&qnap_ts209_eth_data);
  292. orion_sata_init(&qnap_ts209_sata_data);
  293. }
  294. MACHINE_START(TS209, "QNAP TS-109/TS-209")
  295. /* Maintainer: Byron Bradley <byron.bbradley@gmail.com> */
  296. .phys_io = ORION_REGS_PHYS_BASE,
  297. .io_pg_offst = ((ORION_REGS_VIRT_BASE) >> 18) & 0xFFFC,
  298. .boot_params = 0x00000100,
  299. .init_machine = qnap_ts209_init,
  300. .map_io = orion_map_io,
  301. .init_irq = orion_init_irq,
  302. .timer = &orion_timer,
  303. MACHINE_END