ts409-setup.c 8.2 KB

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