ts409-setup.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 <mach/orion5x.h>
  31. #include "common.h"
  32. #include "mpp.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. .swizzle = pci_std_swizzle,
  131. .setup = orion5x_pci_sys_setup,
  132. .scan = orion5x_pci_sys_scan_bus,
  133. .map_irq = qnap_ts409_pci_map_irq,
  134. };
  135. static int __init qnap_ts409_pci_init(void)
  136. {
  137. if (machine_is_ts409())
  138. pci_common_init(&qnap_ts409_pci);
  139. return 0;
  140. }
  141. subsys_initcall(qnap_ts409_pci_init);
  142. /*****************************************************************************
  143. * RTC S35390A on I2C bus
  144. ****************************************************************************/
  145. #define TS409_RTC_GPIO 10
  146. static struct i2c_board_info __initdata qnap_ts409_i2c_rtc = {
  147. I2C_BOARD_INFO("s35390a", 0x30),
  148. };
  149. /*****************************************************************************
  150. * LEDs attached to GPIO
  151. ****************************************************************************/
  152. static struct gpio_led ts409_led_pins[] = {
  153. {
  154. .name = "ts409:red:sata1",
  155. .gpio = 4,
  156. .active_low = 1,
  157. }, {
  158. .name = "ts409:red:sata2",
  159. .gpio = 5,
  160. .active_low = 1,
  161. }, {
  162. .name = "ts409:red:sata3",
  163. .gpio = 6,
  164. .active_low = 1,
  165. }, {
  166. .name = "ts409:red:sata4",
  167. .gpio = 7,
  168. .active_low = 1,
  169. },
  170. };
  171. static struct gpio_led_platform_data ts409_led_data = {
  172. .leds = ts409_led_pins,
  173. .num_leds = ARRAY_SIZE(ts409_led_pins),
  174. };
  175. static struct platform_device ts409_leds = {
  176. .name = "leds-gpio",
  177. .id = -1,
  178. .dev = {
  179. .platform_data = &ts409_led_data,
  180. },
  181. };
  182. /****************************************************************************
  183. * GPIO Attached Keys
  184. * Power button is attached to the PIC microcontroller
  185. ****************************************************************************/
  186. #define QNAP_TS409_GPIO_KEY_RESET 14
  187. #define QNAP_TS409_GPIO_KEY_MEDIA 15
  188. static struct gpio_keys_button qnap_ts409_buttons[] = {
  189. {
  190. .code = KEY_RESTART,
  191. .gpio = QNAP_TS409_GPIO_KEY_RESET,
  192. .desc = "Reset Button",
  193. .active_low = 1,
  194. }, {
  195. .code = KEY_COPY,
  196. .gpio = QNAP_TS409_GPIO_KEY_MEDIA,
  197. .desc = "USB Copy Button",
  198. .active_low = 1,
  199. },
  200. };
  201. static struct gpio_keys_platform_data qnap_ts409_button_data = {
  202. .buttons = qnap_ts409_buttons,
  203. .nbuttons = ARRAY_SIZE(qnap_ts409_buttons),
  204. };
  205. static struct platform_device qnap_ts409_button_device = {
  206. .name = "gpio-keys",
  207. .id = -1,
  208. .num_resources = 0,
  209. .dev = {
  210. .platform_data = &qnap_ts409_button_data,
  211. },
  212. };
  213. /*****************************************************************************
  214. * General Setup
  215. ****************************************************************************/
  216. static unsigned int ts409_mpp_modes[] __initdata = {
  217. MPP0_UNUSED,
  218. MPP1_UNUSED,
  219. MPP2_UNUSED,
  220. MPP3_UNUSED,
  221. MPP4_GPIO, /* HDD 1 status */
  222. MPP5_GPIO, /* HDD 2 status */
  223. MPP6_GPIO, /* HDD 3 status */
  224. MPP7_GPIO, /* HDD 4 status */
  225. MPP8_UNUSED,
  226. MPP9_UNUSED,
  227. MPP10_GPIO, /* RTC int */
  228. MPP11_UNUSED,
  229. MPP12_UNUSED,
  230. MPP13_UNUSED,
  231. MPP14_GPIO, /* SW_RST */
  232. MPP15_GPIO, /* USB copy button */
  233. MPP16_UART, /* UART1 RXD */
  234. MPP17_UART, /* UART1 TXD */
  235. MPP18_UNUSED,
  236. MPP19_UNUSED,
  237. 0,
  238. };
  239. static void __init qnap_ts409_init(void)
  240. {
  241. /*
  242. * Setup basic Orion functions. Need to be called early.
  243. */
  244. orion5x_init();
  245. orion5x_mpp_conf(ts409_mpp_modes);
  246. /*
  247. * Configure peripherals.
  248. */
  249. orion5x_setup_dev_boot_win(QNAP_TS409_NOR_BOOT_BASE,
  250. QNAP_TS409_NOR_BOOT_SIZE);
  251. platform_device_register(&qnap_ts409_nor_flash);
  252. orion5x_ehci0_init();
  253. qnap_tsx09_find_mac_addr(QNAP_TS409_NOR_BOOT_BASE +
  254. qnap_ts409_partitions[5].offset,
  255. qnap_ts409_partitions[5].size);
  256. orion5x_eth_init(&qnap_tsx09_eth_data);
  257. orion5x_i2c_init();
  258. orion5x_uart0_init();
  259. orion5x_uart1_init();
  260. platform_device_register(&qnap_ts409_button_device);
  261. /* Get RTC IRQ and register the chip */
  262. if (gpio_request(TS409_RTC_GPIO, "rtc") == 0) {
  263. if (gpio_direction_input(TS409_RTC_GPIO) == 0)
  264. qnap_ts409_i2c_rtc.irq = gpio_to_irq(TS409_RTC_GPIO);
  265. else
  266. gpio_free(TS409_RTC_GPIO);
  267. }
  268. if (qnap_ts409_i2c_rtc.irq == 0)
  269. pr_warning("qnap_ts409_init: failed to get RTC IRQ\n");
  270. i2c_register_board_info(0, &qnap_ts409_i2c_rtc, 1);
  271. platform_device_register(&ts409_leds);
  272. /* register tsx09 specific power-off method */
  273. pm_power_off = qnap_tsx09_power_off;
  274. }
  275. MACHINE_START(TS409, "QNAP TS-409")
  276. /* Maintainer: Sylver Bruneau <sylver.bruneau@gmail.com> */
  277. .atag_offset = 0x100,
  278. .init_machine = qnap_ts409_init,
  279. .map_io = orion5x_map_io,
  280. .init_early = orion5x_init_early,
  281. .init_irq = orion5x_init_irq,
  282. .timer = &orion5x_timer,
  283. .fixup = tag_fixup_mem32,
  284. .restart = orion5x_restart,
  285. MACHINE_END