ts209-setup.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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/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/mtd/physmap.h>
  18. #include <linux/mtd/rawnand.h>
  19. #include <linux/mv643xx_eth.h>
  20. #include <linux/gpio_keys.h>
  21. #include <linux/input.h>
  22. #include <linux/i2c.h>
  23. #include <linux/serial_reg.h>
  24. #include <linux/ata_platform.h>
  25. #include <asm/mach-types.h>
  26. #include <asm/mach/arch.h>
  27. #include <asm/mach/pci.h>
  28. #include "common.h"
  29. #include "mpp.h"
  30. #include "orion5x.h"
  31. #include "tsx09-common.h"
  32. #define QNAP_TS209_NOR_BOOT_BASE 0xf4000000
  33. #define QNAP_TS209_NOR_BOOT_SIZE SZ_8M
  34. /****************************************************************************
  35. * 8MiB NOR flash. The struct mtd_partition is not in the same order as the
  36. * partitions on the device because we want to keep compatibility with
  37. * existing QNAP firmware.
  38. *
  39. * Layout as used by QNAP:
  40. * [2] 0x00000000-0x00200000 : "Kernel"
  41. * [3] 0x00200000-0x00600000 : "RootFS1"
  42. * [4] 0x00600000-0x00700000 : "RootFS2"
  43. * [6] 0x00700000-0x00760000 : "NAS Config" (read-only)
  44. * [5] 0x00760000-0x00780000 : "U-Boot Config"
  45. * [1] 0x00780000-0x00800000 : "U-Boot" (read-only)
  46. ***************************************************************************/
  47. static struct mtd_partition qnap_ts209_partitions[] = {
  48. {
  49. .name = "U-Boot",
  50. .size = 0x00080000,
  51. .offset = 0x00780000,
  52. .mask_flags = MTD_WRITEABLE,
  53. }, {
  54. .name = "Kernel",
  55. .size = 0x00200000,
  56. .offset = 0,
  57. }, {
  58. .name = "RootFS1",
  59. .size = 0x00400000,
  60. .offset = 0x00200000,
  61. }, {
  62. .name = "RootFS2",
  63. .size = 0x00100000,
  64. .offset = 0x00600000,
  65. }, {
  66. .name = "U-Boot Config",
  67. .size = 0x00020000,
  68. .offset = 0x00760000,
  69. }, {
  70. .name = "NAS Config",
  71. .size = 0x00060000,
  72. .offset = 0x00700000,
  73. .mask_flags = MTD_WRITEABLE,
  74. },
  75. };
  76. static struct physmap_flash_data qnap_ts209_nor_flash_data = {
  77. .width = 1,
  78. .parts = qnap_ts209_partitions,
  79. .nr_parts = ARRAY_SIZE(qnap_ts209_partitions)
  80. };
  81. static struct resource qnap_ts209_nor_flash_resource = {
  82. .flags = IORESOURCE_MEM,
  83. .start = QNAP_TS209_NOR_BOOT_BASE,
  84. .end = QNAP_TS209_NOR_BOOT_BASE + QNAP_TS209_NOR_BOOT_SIZE - 1,
  85. };
  86. static struct platform_device qnap_ts209_nor_flash = {
  87. .name = "physmap-flash",
  88. .id = 0,
  89. .dev = {
  90. .platform_data = &qnap_ts209_nor_flash_data,
  91. },
  92. .resource = &qnap_ts209_nor_flash_resource,
  93. .num_resources = 1,
  94. };
  95. /*****************************************************************************
  96. * PCI
  97. ****************************************************************************/
  98. #define QNAP_TS209_PCI_SLOT0_OFFS 7
  99. #define QNAP_TS209_PCI_SLOT0_IRQ_PIN 6
  100. #define QNAP_TS209_PCI_SLOT1_IRQ_PIN 7
  101. static void __init qnap_ts209_pci_preinit(void)
  102. {
  103. int pin;
  104. /*
  105. * Configure PCI GPIO IRQ pins
  106. */
  107. pin = QNAP_TS209_PCI_SLOT0_IRQ_PIN;
  108. if (gpio_request(pin, "PCI Int1") == 0) {
  109. if (gpio_direction_input(pin) == 0) {
  110. irq_set_irq_type(gpio_to_irq(pin), IRQ_TYPE_LEVEL_LOW);
  111. } else {
  112. printk(KERN_ERR "qnap_ts209_pci_preinit failed to "
  113. "set_irq_type pin %d\n", pin);
  114. gpio_free(pin);
  115. }
  116. } else {
  117. printk(KERN_ERR "qnap_ts209_pci_preinit failed to gpio_request "
  118. "%d\n", pin);
  119. }
  120. pin = QNAP_TS209_PCI_SLOT1_IRQ_PIN;
  121. if (gpio_request(pin, "PCI Int2") == 0) {
  122. if (gpio_direction_input(pin) == 0) {
  123. irq_set_irq_type(gpio_to_irq(pin), IRQ_TYPE_LEVEL_LOW);
  124. } else {
  125. printk(KERN_ERR "qnap_ts209_pci_preinit failed "
  126. "to set_irq_type pin %d\n", pin);
  127. gpio_free(pin);
  128. }
  129. } else {
  130. printk(KERN_ERR "qnap_ts209_pci_preinit failed to gpio_request "
  131. "%d\n", pin);
  132. }
  133. }
  134. static int __init qnap_ts209_pci_map_irq(const struct pci_dev *dev, u8 slot,
  135. u8 pin)
  136. {
  137. int irq;
  138. /*
  139. * Check for devices with hard-wired IRQs.
  140. */
  141. irq = orion5x_pci_map_irq(dev, slot, pin);
  142. if (irq != -1)
  143. return irq;
  144. /*
  145. * PCI IRQs are connected via GPIOs.
  146. */
  147. switch (slot - QNAP_TS209_PCI_SLOT0_OFFS) {
  148. case 0:
  149. return gpio_to_irq(QNAP_TS209_PCI_SLOT0_IRQ_PIN);
  150. case 1:
  151. return gpio_to_irq(QNAP_TS209_PCI_SLOT1_IRQ_PIN);
  152. default:
  153. return -1;
  154. }
  155. }
  156. static struct hw_pci qnap_ts209_pci __initdata = {
  157. .nr_controllers = 2,
  158. .preinit = qnap_ts209_pci_preinit,
  159. .setup = orion5x_pci_sys_setup,
  160. .scan = orion5x_pci_sys_scan_bus,
  161. .map_irq = qnap_ts209_pci_map_irq,
  162. };
  163. static int __init qnap_ts209_pci_init(void)
  164. {
  165. if (machine_is_ts209())
  166. pci_common_init(&qnap_ts209_pci);
  167. return 0;
  168. }
  169. subsys_initcall(qnap_ts209_pci_init);
  170. /*****************************************************************************
  171. * RTC S35390A on I2C bus
  172. ****************************************************************************/
  173. #define TS209_RTC_GPIO 3
  174. static struct i2c_board_info __initdata qnap_ts209_i2c_rtc = {
  175. I2C_BOARD_INFO("s35390a", 0x30),
  176. .irq = 0,
  177. };
  178. /****************************************************************************
  179. * GPIO Attached Keys
  180. * Power button is attached to the PIC microcontroller
  181. ****************************************************************************/
  182. #define QNAP_TS209_GPIO_KEY_MEDIA 1
  183. #define QNAP_TS209_GPIO_KEY_RESET 2
  184. static struct gpio_keys_button qnap_ts209_buttons[] = {
  185. {
  186. .code = KEY_COPY,
  187. .gpio = QNAP_TS209_GPIO_KEY_MEDIA,
  188. .desc = "USB Copy Button",
  189. .active_low = 1,
  190. }, {
  191. .code = KEY_RESTART,
  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 = {
  206. .platform_data = &qnap_ts209_button_data,
  207. },
  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 unsigned int ts209_mpp_modes[] __initdata = {
  219. MPP0_UNUSED,
  220. MPP1_GPIO, /* USB copy button */
  221. MPP2_GPIO, /* Load defaults button */
  222. MPP3_GPIO, /* GPIO RTC */
  223. MPP4_UNUSED,
  224. MPP5_UNUSED,
  225. MPP6_GPIO, /* PCI Int A */
  226. MPP7_GPIO, /* PCI Int B */
  227. MPP8_UNUSED,
  228. MPP9_UNUSED,
  229. MPP10_UNUSED,
  230. MPP11_UNUSED,
  231. MPP12_SATA_LED, /* SATA 0 presence */
  232. MPP13_SATA_LED, /* SATA 1 presence */
  233. MPP14_SATA_LED, /* SATA 0 active */
  234. MPP15_SATA_LED, /* SATA 1 active */
  235. MPP16_UART, /* UART1 RXD */
  236. MPP17_UART, /* UART1 TXD */
  237. MPP18_GPIO, /* SW_RST */
  238. MPP19_UNUSED,
  239. 0,
  240. };
  241. static void __init qnap_ts209_init(void)
  242. {
  243. /*
  244. * Setup basic Orion functions. Need to be called early.
  245. */
  246. orion5x_init();
  247. orion5x_mpp_conf(ts209_mpp_modes);
  248. /*
  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. /*
  255. * Configure peripherals.
  256. */
  257. mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
  258. ORION_MBUS_DEVBUS_BOOT_ATTR,
  259. QNAP_TS209_NOR_BOOT_BASE,
  260. QNAP_TS209_NOR_BOOT_SIZE);
  261. platform_device_register(&qnap_ts209_nor_flash);
  262. orion5x_ehci0_init();
  263. orion5x_ehci1_init();
  264. qnap_tsx09_find_mac_addr(QNAP_TS209_NOR_BOOT_BASE +
  265. qnap_ts209_partitions[5].offset,
  266. qnap_ts209_partitions[5].size);
  267. orion5x_eth_init(&qnap_tsx09_eth_data);
  268. orion5x_i2c_init();
  269. orion5x_sata_init(&qnap_ts209_sata_data);
  270. orion5x_uart0_init();
  271. orion5x_uart1_init();
  272. orion5x_xor_init();
  273. platform_device_register(&qnap_ts209_button_device);
  274. /* Get RTC IRQ and register the chip */
  275. if (gpio_request(TS209_RTC_GPIO, "rtc") == 0) {
  276. if (gpio_direction_input(TS209_RTC_GPIO) == 0)
  277. qnap_ts209_i2c_rtc.irq = gpio_to_irq(TS209_RTC_GPIO);
  278. else
  279. gpio_free(TS209_RTC_GPIO);
  280. }
  281. if (qnap_ts209_i2c_rtc.irq == 0)
  282. pr_warn("qnap_ts209_init: failed to get RTC IRQ\n");
  283. i2c_register_board_info(0, &qnap_ts209_i2c_rtc, 1);
  284. /* register tsx09 specific power-off method */
  285. pm_power_off = qnap_tsx09_power_off;
  286. }
  287. MACHINE_START(TS209, "QNAP TS-109/TS-209")
  288. /* Maintainer: Byron Bradley <byron.bbradley@gmail.com> */
  289. .atag_offset = 0x100,
  290. .nr_irqs = ORION5X_NR_IRQS,
  291. .init_machine = qnap_ts209_init,
  292. .map_io = orion5x_map_io,
  293. .init_early = orion5x_init_early,
  294. .init_irq = orion5x_init_irq,
  295. .init_time = orion5x_timer_init,
  296. .fixup = tag_fixup_mem32,
  297. .restart = orion5x_restart,
  298. MACHINE_END