ts409-setup.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * QNAP TS-409 Board Setup
  4. *
  5. * Maintainer: Sylver Bruneau <sylver.bruneau@gmail.com>
  6. *
  7. * Copyright (C) 2008 Sylver Bruneau <sylver.bruneau@gmail.com>
  8. * Copyright (C) 2008 Martin Michlmayr <tbm@cyrius.com>
  9. */
  10. #include <linux/gpio.h>
  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/mv643xx_eth.h>
  18. #include <linux/leds.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 <asm/mach-types.h>
  24. #include <asm/mach/arch.h>
  25. #include <asm/mach/pci.h>
  26. #include "common.h"
  27. #include "mpp.h"
  28. #include "orion5x.h"
  29. #include "tsx09-common.h"
  30. /*****************************************************************************
  31. * QNAP TS-409 Info
  32. ****************************************************************************/
  33. /*
  34. * QNAP TS-409 hardware :
  35. * - Marvell 88F5281-D0
  36. * - Marvell 88SX7042 SATA controller (PCIe)
  37. * - Marvell 88E1118 Gigabit Ethernet PHY
  38. * - RTC S35390A (@0x30) on I2C bus
  39. * - 8MB NOR flash
  40. * - 256MB of DDR-2 RAM
  41. */
  42. /*
  43. * 8MB NOR flash Device bus boot chip select
  44. */
  45. #define QNAP_TS409_NOR_BOOT_BASE 0xff800000
  46. #define QNAP_TS409_NOR_BOOT_SIZE SZ_8M
  47. /****************************************************************************
  48. * 8MiB NOR flash. The struct mtd_partition is not in the same order as the
  49. * partitions on the device because we want to keep compatibility with
  50. * existing QNAP firmware.
  51. *
  52. * Layout as used by QNAP:
  53. * [2] 0x00000000-0x00200000 : "Kernel"
  54. * [3] 0x00200000-0x00600000 : "RootFS1"
  55. * [4] 0x00600000-0x00700000 : "RootFS2"
  56. * [6] 0x00700000-0x00760000 : "NAS Config" (read-only)
  57. * [5] 0x00760000-0x00780000 : "U-Boot Config"
  58. * [1] 0x00780000-0x00800000 : "U-Boot" (read-only)
  59. ***************************************************************************/
  60. static struct mtd_partition qnap_ts409_partitions[] = {
  61. {
  62. .name = "U-Boot",
  63. .size = 0x00080000,
  64. .offset = 0x00780000,
  65. .mask_flags = MTD_WRITEABLE,
  66. }, {
  67. .name = "Kernel",
  68. .size = 0x00200000,
  69. .offset = 0,
  70. }, {
  71. .name = "RootFS1",
  72. .size = 0x00400000,
  73. .offset = 0x00200000,
  74. }, {
  75. .name = "RootFS2",
  76. .size = 0x00100000,
  77. .offset = 0x00600000,
  78. }, {
  79. .name = "U-Boot Config",
  80. .size = 0x00020000,
  81. .offset = 0x00760000,
  82. }, {
  83. .name = "NAS Config",
  84. .size = 0x00060000,
  85. .offset = 0x00700000,
  86. .mask_flags = MTD_WRITEABLE,
  87. },
  88. };
  89. static struct physmap_flash_data qnap_ts409_nor_flash_data = {
  90. .width = 1,
  91. .parts = qnap_ts409_partitions,
  92. .nr_parts = ARRAY_SIZE(qnap_ts409_partitions)
  93. };
  94. static struct resource qnap_ts409_nor_flash_resource = {
  95. .flags = IORESOURCE_MEM,
  96. .start = QNAP_TS409_NOR_BOOT_BASE,
  97. .end = QNAP_TS409_NOR_BOOT_BASE + QNAP_TS409_NOR_BOOT_SIZE - 1,
  98. };
  99. static struct platform_device qnap_ts409_nor_flash = {
  100. .name = "physmap-flash",
  101. .id = 0,
  102. .dev = { .platform_data = &qnap_ts409_nor_flash_data, },
  103. .num_resources = 1,
  104. .resource = &qnap_ts409_nor_flash_resource,
  105. };
  106. /*****************************************************************************
  107. * PCI
  108. ****************************************************************************/
  109. static int __init qnap_ts409_pci_map_irq(const struct pci_dev *dev, u8 slot,
  110. u8 pin)
  111. {
  112. int irq;
  113. /*
  114. * Check for devices with hard-wired IRQs.
  115. */
  116. irq = orion5x_pci_map_irq(dev, slot, pin);
  117. if (irq != -1)
  118. return irq;
  119. /*
  120. * PCI isn't used on the TS-409
  121. */
  122. return -1;
  123. }
  124. static struct hw_pci qnap_ts409_pci __initdata = {
  125. .nr_controllers = 2,
  126. .setup = orion5x_pci_sys_setup,
  127. .scan = orion5x_pci_sys_scan_bus,
  128. .map_irq = qnap_ts409_pci_map_irq,
  129. };
  130. static int __init qnap_ts409_pci_init(void)
  131. {
  132. if (machine_is_ts409())
  133. pci_common_init(&qnap_ts409_pci);
  134. return 0;
  135. }
  136. subsys_initcall(qnap_ts409_pci_init);
  137. /*****************************************************************************
  138. * RTC S35390A on I2C bus
  139. ****************************************************************************/
  140. #define TS409_RTC_GPIO 10
  141. static struct i2c_board_info __initdata qnap_ts409_i2c_rtc = {
  142. I2C_BOARD_INFO("s35390a", 0x30),
  143. };
  144. /*****************************************************************************
  145. * LEDs attached to GPIO
  146. ****************************************************************************/
  147. static struct gpio_led ts409_led_pins[] = {
  148. {
  149. .name = "ts409:red:sata1",
  150. .gpio = 4,
  151. .active_low = 1,
  152. }, {
  153. .name = "ts409:red:sata2",
  154. .gpio = 5,
  155. .active_low = 1,
  156. }, {
  157. .name = "ts409:red:sata3",
  158. .gpio = 6,
  159. .active_low = 1,
  160. }, {
  161. .name = "ts409:red:sata4",
  162. .gpio = 7,
  163. .active_low = 1,
  164. },
  165. };
  166. static struct gpio_led_platform_data ts409_led_data = {
  167. .leds = ts409_led_pins,
  168. .num_leds = ARRAY_SIZE(ts409_led_pins),
  169. };
  170. static struct platform_device ts409_leds = {
  171. .name = "leds-gpio",
  172. .id = -1,
  173. .dev = {
  174. .platform_data = &ts409_led_data,
  175. },
  176. };
  177. /****************************************************************************
  178. * GPIO Attached Keys
  179. * Power button is attached to the PIC microcontroller
  180. ****************************************************************************/
  181. #define QNAP_TS409_GPIO_KEY_RESET 14
  182. #define QNAP_TS409_GPIO_KEY_MEDIA 15
  183. static struct gpio_keys_button qnap_ts409_buttons[] = {
  184. {
  185. .code = KEY_RESTART,
  186. .gpio = QNAP_TS409_GPIO_KEY_RESET,
  187. .desc = "Reset Button",
  188. .active_low = 1,
  189. }, {
  190. .code = KEY_COPY,
  191. .gpio = QNAP_TS409_GPIO_KEY_MEDIA,
  192. .desc = "USB Copy Button",
  193. .active_low = 1,
  194. },
  195. };
  196. static struct gpio_keys_platform_data qnap_ts409_button_data = {
  197. .buttons = qnap_ts409_buttons,
  198. .nbuttons = ARRAY_SIZE(qnap_ts409_buttons),
  199. };
  200. static struct platform_device qnap_ts409_button_device = {
  201. .name = "gpio-keys",
  202. .id = -1,
  203. .num_resources = 0,
  204. .dev = {
  205. .platform_data = &qnap_ts409_button_data,
  206. },
  207. };
  208. /*****************************************************************************
  209. * General Setup
  210. ****************************************************************************/
  211. static unsigned int ts409_mpp_modes[] __initdata = {
  212. MPP0_UNUSED,
  213. MPP1_UNUSED,
  214. MPP2_UNUSED,
  215. MPP3_UNUSED,
  216. MPP4_GPIO, /* HDD 1 status */
  217. MPP5_GPIO, /* HDD 2 status */
  218. MPP6_GPIO, /* HDD 3 status */
  219. MPP7_GPIO, /* HDD 4 status */
  220. MPP8_UNUSED,
  221. MPP9_UNUSED,
  222. MPP10_GPIO, /* RTC int */
  223. MPP11_UNUSED,
  224. MPP12_UNUSED,
  225. MPP13_UNUSED,
  226. MPP14_GPIO, /* SW_RST */
  227. MPP15_GPIO, /* USB copy button */
  228. MPP16_UART, /* UART1 RXD */
  229. MPP17_UART, /* UART1 TXD */
  230. MPP18_UNUSED,
  231. MPP19_UNUSED,
  232. 0,
  233. };
  234. static void __init qnap_ts409_init(void)
  235. {
  236. /*
  237. * Setup basic Orion functions. Need to be called early.
  238. */
  239. orion5x_init();
  240. orion5x_mpp_conf(ts409_mpp_modes);
  241. /*
  242. * Configure peripherals.
  243. */
  244. mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
  245. ORION_MBUS_DEVBUS_BOOT_ATTR,
  246. QNAP_TS409_NOR_BOOT_BASE,
  247. QNAP_TS409_NOR_BOOT_SIZE);
  248. platform_device_register(&qnap_ts409_nor_flash);
  249. orion5x_ehci0_init();
  250. qnap_tsx09_find_mac_addr(QNAP_TS409_NOR_BOOT_BASE +
  251. qnap_ts409_partitions[5].offset,
  252. qnap_ts409_partitions[5].size);
  253. orion5x_eth_init(&qnap_tsx09_eth_data);
  254. orion5x_i2c_init();
  255. orion5x_uart0_init();
  256. orion5x_uart1_init();
  257. platform_device_register(&qnap_ts409_button_device);
  258. /* Get RTC IRQ and register the chip */
  259. if (gpio_request(TS409_RTC_GPIO, "rtc") == 0) {
  260. if (gpio_direction_input(TS409_RTC_GPIO) == 0)
  261. qnap_ts409_i2c_rtc.irq = gpio_to_irq(TS409_RTC_GPIO);
  262. else
  263. gpio_free(TS409_RTC_GPIO);
  264. }
  265. if (qnap_ts409_i2c_rtc.irq == 0)
  266. pr_warn("qnap_ts409_init: failed to get RTC IRQ\n");
  267. i2c_register_board_info(0, &qnap_ts409_i2c_rtc, 1);
  268. platform_device_register(&ts409_leds);
  269. /* register tsx09 specific power-off method */
  270. pm_power_off = qnap_tsx09_power_off;
  271. }
  272. MACHINE_START(TS409, "QNAP TS-409")
  273. /* Maintainer: Sylver Bruneau <sylver.bruneau@gmail.com> */
  274. .atag_offset = 0x100,
  275. .nr_irqs = ORION5X_NR_IRQS,
  276. .init_machine = qnap_ts409_init,
  277. .map_io = orion5x_map_io,
  278. .init_early = orion5x_init_early,
  279. .init_irq = orion5x_init_irq,
  280. .init_time = orion5x_timer_init,
  281. .fixup = tag_fixup_mem32,
  282. .restart = orion5x_restart,
  283. MACHINE_END