ts409-setup.c 8.3 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/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/pci.h>
  18. #include <linux/irq.h>
  19. #include <linux/mtd/physmap.h>
  20. #include <linux/mv643xx_eth.h>
  21. #include <linux/leds.h>
  22. #include <linux/gpio_keys.h>
  23. #include <linux/input.h>
  24. #include <linux/i2c.h>
  25. #include <linux/serial_reg.h>
  26. #include <asm/mach-types.h>
  27. #include <asm/gpio.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 compatability 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(struct pci_dev *dev, u8 slot, u8 pin)
  114. {
  115. int irq;
  116. /*
  117. * Check for devices with hard-wired IRQs.
  118. */
  119. irq = orion5x_pci_map_irq(dev, slot, pin);
  120. if (irq != -1)
  121. return irq;
  122. /*
  123. * PCI isn't used on the TS-409
  124. */
  125. return -1;
  126. }
  127. static struct hw_pci qnap_ts409_pci __initdata = {
  128. .nr_controllers = 2,
  129. .swizzle = pci_std_swizzle,
  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 struct orion5x_mpp_mode ts409_mpp_modes[] __initdata = {
  216. { 0, MPP_UNUSED },
  217. { 1, MPP_UNUSED },
  218. { 2, MPP_UNUSED },
  219. { 3, MPP_UNUSED },
  220. { 4, MPP_GPIO }, /* HDD 1 status */
  221. { 5, MPP_GPIO }, /* HDD 2 status */
  222. { 6, MPP_GPIO }, /* HDD 3 status */
  223. { 7, MPP_GPIO }, /* HDD 4 status */
  224. { 8, MPP_UNUSED },
  225. { 9, MPP_UNUSED },
  226. { 10, MPP_GPIO }, /* RTC int */
  227. { 11, MPP_UNUSED },
  228. { 12, MPP_UNUSED },
  229. { 13, MPP_UNUSED },
  230. { 14, MPP_GPIO }, /* SW_RST */
  231. { 15, MPP_GPIO }, /* USB copy button */
  232. { 16, MPP_UART }, /* UART1 RXD */
  233. { 17, MPP_UART }, /* UART1 TXD */
  234. { 18, MPP_UNUSED },
  235. { 19, MPP_UNUSED },
  236. { -1 },
  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. orion5x_setup_dev_boot_win(QNAP_TS409_NOR_BOOT_BASE,
  249. QNAP_TS409_NOR_BOOT_SIZE);
  250. platform_device_register(&qnap_ts409_nor_flash);
  251. orion5x_ehci0_init();
  252. qnap_tsx09_find_mac_addr(QNAP_TS409_NOR_BOOT_BASE +
  253. qnap_ts409_partitions[5].offset,
  254. qnap_ts409_partitions[5].size);
  255. orion5x_eth_init(&qnap_tsx09_eth_data);
  256. orion5x_i2c_init();
  257. orion5x_uart0_init();
  258. orion5x_uart1_init();
  259. platform_device_register(&qnap_ts409_button_device);
  260. /* Get RTC IRQ and register the chip */
  261. if (gpio_request(TS409_RTC_GPIO, "rtc") == 0) {
  262. if (gpio_direction_input(TS409_RTC_GPIO) == 0)
  263. qnap_ts409_i2c_rtc.irq = gpio_to_irq(TS409_RTC_GPIO);
  264. else
  265. gpio_free(TS409_RTC_GPIO);
  266. }
  267. if (qnap_ts409_i2c_rtc.irq == 0)
  268. pr_warning("qnap_ts409_init: failed to get RTC IRQ\n");
  269. i2c_register_board_info(0, &qnap_ts409_i2c_rtc, 1);
  270. platform_device_register(&ts409_leds);
  271. /* register tsx09 specific power-off method */
  272. pm_power_off = qnap_tsx09_power_off;
  273. }
  274. MACHINE_START(TS409, "QNAP TS-409")
  275. /* Maintainer: Sylver Bruneau <sylver.bruneau@gmail.com> */
  276. .phys_io = ORION5X_REGS_PHYS_BASE,
  277. .io_pg_offst = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
  278. .boot_params = 0x00000100,
  279. .init_machine = qnap_ts409_init,
  280. .map_io = orion5x_map_io,
  281. .init_irq = orion5x_init_irq,
  282. .timer = &orion5x_timer,
  283. .fixup = tag_fixup_mem32,
  284. MACHINE_END