ts209-setup.c 8.5 KB

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