h8.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright 2008-2011, IBM Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/of.h>
  11. #include <linux/io.h>
  12. #include "wsp.h"
  13. /*
  14. * The UART connection to the H8 is over ttyS1 which is just a 16550.
  15. * We assume that FW has it setup right and no one messes with it.
  16. */
  17. static u8 __iomem *h8;
  18. #define RBR 0 /* Receiver Buffer Register */
  19. #define THR 0 /* Transmitter Holding Register */
  20. #define LSR 5 /* Line Status Register */
  21. #define LSR_DR 0x01 /* LSR value for Data-Ready */
  22. #define LSR_THRE 0x20 /* LSR value for Transmitter-Holding-Register-Empty */
  23. static void wsp_h8_putc(int c)
  24. {
  25. u8 lsr;
  26. do {
  27. lsr = readb(h8 + LSR);
  28. } while ((lsr & LSR_THRE) != LSR_THRE);
  29. writeb(c, h8 + THR);
  30. }
  31. static int wsp_h8_getc(void)
  32. {
  33. u8 lsr;
  34. do {
  35. lsr = readb(h8 + LSR);
  36. } while ((lsr & LSR_DR) != LSR_DR);
  37. return readb(h8 + RBR);
  38. }
  39. static void wsp_h8_puts(const char *s, int sz)
  40. {
  41. int i;
  42. for (i = 0; i < sz; i++) {
  43. wsp_h8_putc(s[i]);
  44. /* no flow control so wait for echo */
  45. wsp_h8_getc();
  46. }
  47. wsp_h8_putc('\r');
  48. wsp_h8_putc('\n');
  49. }
  50. static void wsp_h8_terminal_cmd(const char *cmd, int sz)
  51. {
  52. hard_irq_disable();
  53. wsp_h8_puts(cmd, sz);
  54. /* should never return, but just in case */
  55. for (;;)
  56. continue;
  57. }
  58. void wsp_h8_restart(char *cmd)
  59. {
  60. static const char restart[] = "warm-reset";
  61. (void)cmd;
  62. wsp_h8_terminal_cmd(restart, sizeof(restart) - 1);
  63. }
  64. void wsp_h8_power_off(void)
  65. {
  66. static const char off[] = "power-off";
  67. wsp_h8_terminal_cmd(off, sizeof(off) - 1);
  68. }
  69. static void __iomem *wsp_h8_getaddr(void)
  70. {
  71. struct device_node *aliases;
  72. struct device_node *uart;
  73. struct property *path;
  74. void __iomem *va = NULL;
  75. /*
  76. * there is nothing in the devtree to tell us which is mapped
  77. * to the H8, but se know it is the second serial port.
  78. */
  79. aliases = of_find_node_by_path("/aliases");
  80. if (aliases == NULL)
  81. return NULL;
  82. path = of_find_property(aliases, "serial1", NULL);
  83. if (path == NULL)
  84. goto out;
  85. uart = of_find_node_by_path(path->value);
  86. if (uart == NULL)
  87. goto out;
  88. va = of_iomap(uart, 0);
  89. /* remove it so no one messes with it */
  90. of_detach_node(uart);
  91. of_node_put(uart);
  92. out:
  93. of_node_put(aliases);
  94. return va;
  95. }
  96. void __init wsp_setup_h8(void)
  97. {
  98. h8 = wsp_h8_getaddr();
  99. /* Devtree change? lets hard map it anyway */
  100. if (h8 == NULL) {
  101. pr_warn("UART to H8 could not be found");
  102. h8 = ioremap(0xffc0008000ULL, 0x100);
  103. }
  104. }