tsx1x-common.c 2.9 KB

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