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