ts209-setup.c 8.2 KB

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