ts409-setup.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * QNAP TS-409 Board Setup
  3. *
  4. * Maintainer: Sylver Bruneau <sylver.bruneau@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  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/gpio_keys.h>
  19. #include <linux/input.h>
  20. #include <linux/i2c.h>
  21. #include <linux/serial_reg.h>
  22. #include <asm/mach-types.h>
  23. #include <asm/gpio.h>
  24. #include <asm/mach/arch.h>
  25. #include <asm/mach/pci.h>
  26. #include <asm/arch/orion5x.h>
  27. #include "common.h"
  28. #include "mpp.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 compatability 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(struct pci_dev *dev, u8 slot, u8 pin)
  110. {
  111. int irq;
  112. /*
  113. * Check for devices with hard-wired IRQs.
  114. */
  115. irq = orion5x_pci_map_irq(dev, slot, pin);
  116. if (irq != -1)
  117. return irq;
  118. /*
  119. * PCI isn't used on the TS-409
  120. */
  121. return -1;
  122. }
  123. static struct hw_pci qnap_ts409_pci __initdata = {
  124. .nr_controllers = 2,
  125. .swizzle = pci_std_swizzle,
  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. * GPIO Attached Keys
  146. * Power button is attached to the PIC microcontroller
  147. ****************************************************************************/
  148. #define QNAP_TS409_GPIO_KEY_MEDIA 15
  149. static struct gpio_keys_button qnap_ts409_buttons[] = {
  150. {
  151. .code = KEY_RESTART,
  152. .gpio = QNAP_TS409_GPIO_KEY_MEDIA,
  153. .desc = "USB Copy Button",
  154. .active_low = 1,
  155. },
  156. };
  157. static struct gpio_keys_platform_data qnap_ts409_button_data = {
  158. .buttons = qnap_ts409_buttons,
  159. .nbuttons = ARRAY_SIZE(qnap_ts409_buttons),
  160. };
  161. static struct platform_device qnap_ts409_button_device = {
  162. .name = "gpio-keys",
  163. .id = -1,
  164. .num_resources = 0,
  165. .dev = {
  166. .platform_data = &qnap_ts409_button_data,
  167. },
  168. };
  169. /*****************************************************************************
  170. * General Setup
  171. ****************************************************************************/
  172. static struct orion5x_mpp_mode ts409_mpp_modes[] __initdata = {
  173. { 0, MPP_UNUSED },
  174. { 1, MPP_UNUSED },
  175. { 2, MPP_UNUSED },
  176. { 3, MPP_UNUSED },
  177. { 4, MPP_GPIO }, /* HDD 1 status */
  178. { 5, MPP_GPIO }, /* HDD 2 status */
  179. { 6, MPP_GPIO }, /* HDD 3 status */
  180. { 7, MPP_GPIO }, /* HDD 4 status */
  181. { 8, MPP_UNUSED },
  182. { 9, MPP_UNUSED },
  183. { 10, MPP_GPIO }, /* RTC int */
  184. { 11, MPP_UNUSED },
  185. { 12, MPP_UNUSED },
  186. { 13, MPP_UNUSED },
  187. { 14, MPP_GPIO }, /* SW_RST */
  188. { 15, MPP_GPIO }, /* USB copy button */
  189. { 16, MPP_UART }, /* UART1 RXD */
  190. { 17, MPP_UART }, /* UART1 TXD */
  191. { 18, MPP_UNUSED },
  192. { 19, MPP_UNUSED },
  193. { -1 },
  194. };
  195. static void __init qnap_ts409_init(void)
  196. {
  197. /*
  198. * Setup basic Orion functions. Need to be called early.
  199. */
  200. orion5x_init();
  201. orion5x_mpp_conf(ts409_mpp_modes);
  202. /*
  203. * Configure peripherals.
  204. */
  205. orion5x_ehci0_init();
  206. qnap_tsx09_find_mac_addr(QNAP_TS409_NOR_BOOT_BASE +
  207. qnap_ts409_partitions[5].offset,
  208. qnap_ts409_partitions[5].size);
  209. orion5x_eth_init(&qnap_tsx09_eth_data);
  210. orion5x_i2c_init();
  211. orion5x_uart0_init();
  212. orion5x_setup_dev_boot_win(QNAP_TS409_NOR_BOOT_BASE,
  213. QNAP_TS409_NOR_BOOT_SIZE);
  214. platform_device_register(&qnap_ts409_nor_flash);
  215. platform_device_register(&qnap_ts409_button_device);
  216. /* Get RTC IRQ and register the chip */
  217. if (gpio_request(TS409_RTC_GPIO, "rtc") == 0) {
  218. if (gpio_direction_input(TS409_RTC_GPIO) == 0)
  219. qnap_ts409_i2c_rtc.irq = gpio_to_irq(TS409_RTC_GPIO);
  220. else
  221. gpio_free(TS409_RTC_GPIO);
  222. }
  223. if (qnap_ts409_i2c_rtc.irq == 0)
  224. pr_warning("qnap_ts409_init: failed to get RTC IRQ\n");
  225. i2c_register_board_info(0, &qnap_ts409_i2c_rtc, 1);
  226. /* register tsx09 specific power-off method */
  227. pm_power_off = qnap_tsx09_power_off;
  228. }
  229. MACHINE_START(TS409, "QNAP TS-409")
  230. /* Maintainer: Sylver Bruneau <sylver.bruneau@gmail.com> */
  231. .phys_io = ORION5X_REGS_PHYS_BASE,
  232. .io_pg_offst = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
  233. .boot_params = 0x00000100,
  234. .init_machine = qnap_ts409_init,
  235. .map_io = orion5x_map_io,
  236. .init_irq = orion5x_init_irq,
  237. .timer = &orion5x_timer,
  238. .fixup = tag_fixup_mem32,
  239. MACHINE_END