tsx1x-common.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include <linux/kernel.h>
  2. #include <linux/pci.h>
  3. #include <linux/platform_device.h>
  4. #include <linux/mtd/physmap.h>
  5. #include <linux/spi/flash.h>
  6. #include <linux/spi/spi.h>
  7. #include <linux/spi/orion_spi.h>
  8. #include <linux/serial_reg.h>
  9. #include <mach/kirkwood.h>
  10. #include "common.h"
  11. /*
  12. * QNAP TS-x1x Boards flash
  13. */
  14. /****************************************************************************
  15. * 16 MiB NOR flash. The struct mtd_partition is not in the same order as the
  16. * partitions on the device because we want to keep compatibility with
  17. * the QNAP firmware.
  18. * Layout as used by QNAP:
  19. * 0x00000000-0x00080000 : "U-Boot"
  20. * 0x00200000-0x00400000 : "Kernel"
  21. * 0x00400000-0x00d00000 : "RootFS"
  22. * 0x00d00000-0x01000000 : "RootFS2"
  23. * 0x00080000-0x000c0000 : "U-Boot Config"
  24. * 0x000c0000-0x00200000 : "NAS Config"
  25. *
  26. * We'll use "RootFS1" instead of "RootFS" to stay compatible with the layout
  27. * used by the QNAP TS-109/TS-209.
  28. *
  29. ***************************************************************************/
  30. struct mtd_partition qnap_tsx1x_partitions[] = {
  31. {
  32. .name = "U-Boot",
  33. .size = 0x00080000,
  34. .offset = 0,
  35. .mask_flags = MTD_WRITEABLE,
  36. }, {
  37. .name = "Kernel",
  38. .size = 0x00200000,
  39. .offset = 0x00200000,
  40. }, {
  41. .name = "RootFS1",
  42. .size = 0x00900000,
  43. .offset = 0x00400000,
  44. }, {
  45. .name = "RootFS2",
  46. .size = 0x00300000,
  47. .offset = 0x00d00000,
  48. }, {
  49. .name = "U-Boot Config",
  50. .size = 0x00040000,
  51. .offset = 0x00080000,
  52. }, {
  53. .name = "NAS Config",
  54. .size = 0x00140000,
  55. .offset = 0x000c0000,
  56. },
  57. };
  58. const struct flash_platform_data qnap_tsx1x_flash = {
  59. .type = "m25p128",
  60. .name = "spi_flash",
  61. .parts = qnap_tsx1x_partitions,
  62. .nr_parts = ARRAY_SIZE(qnap_tsx1x_partitions),
  63. };
  64. struct spi_board_info __initdata qnap_tsx1x_spi_slave_info[] = {
  65. {
  66. .modalias = "m25p80",
  67. .platform_data = &qnap_tsx1x_flash,
  68. .irq = -1,
  69. .max_speed_hz = 20000000,
  70. .bus_num = 0,
  71. .chip_select = 0,
  72. },
  73. };
  74. void __init qnap_tsx1x_register_flash(void)
  75. {
  76. spi_register_board_info(qnap_tsx1x_spi_slave_info,
  77. ARRAY_SIZE(qnap_tsx1x_spi_slave_info));
  78. kirkwood_spi_init();
  79. }
  80. /*****************************************************************************
  81. * QNAP TS-x1x specific power off method via UART1-attached PIC
  82. ****************************************************************************/
  83. #define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
  84. void qnap_tsx1x_power_off(void)
  85. {
  86. /* 19200 baud divisor */
  87. const unsigned divisor = ((kirkwood_tclk + (8 * 19200)) / (16 * 19200));
  88. pr_info("%s: triggering power-off...\n", __func__);
  89. /* hijack UART1 and reset into sane state (19200,8n1) */
  90. writel(0x83, UART1_REG(LCR));
  91. writel(divisor & 0xff, UART1_REG(DLL));
  92. writel((divisor >> 8) & 0xff, UART1_REG(DLM));
  93. writel(0x03, UART1_REG(LCR));
  94. writel(0x00, UART1_REG(IER));
  95. writel(0x00, UART1_REG(FCR));
  96. writel(0x00, UART1_REG(MCR));
  97. /* send the power-off command 'A' to PIC */
  98. writel('A', UART1_REG(TX));
  99. }