udbg_scc.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * udbg for zilog scc ports as found on Apple PowerMacs
  3. *
  4. * Copyright (C) 2001-2005 PPC 64 Team, IBM Corp
  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/types.h>
  12. #include <asm/udbg.h>
  13. #include <asm/processor.h>
  14. #include <asm/io.h>
  15. #include <asm/prom.h>
  16. #include <asm/pmac_feature.h>
  17. extern u8 real_readb(volatile u8 __iomem *addr);
  18. extern void real_writeb(u8 data, volatile u8 __iomem *addr);
  19. #define SCC_TXRDY 4
  20. #define SCC_RXRDY 1
  21. static volatile u8 __iomem *sccc;
  22. static volatile u8 __iomem *sccd;
  23. static void udbg_scc_putc(char c)
  24. {
  25. if (sccc) {
  26. while ((in_8(sccc) & SCC_TXRDY) == 0)
  27. ;
  28. out_8(sccd, c);
  29. if (c == '\n')
  30. udbg_scc_putc('\r');
  31. }
  32. }
  33. static int udbg_scc_getc_poll(void)
  34. {
  35. if (sccc) {
  36. if ((in_8(sccc) & SCC_RXRDY) != 0)
  37. return in_8(sccd);
  38. else
  39. return -1;
  40. }
  41. return -1;
  42. }
  43. static int udbg_scc_getc(void)
  44. {
  45. if (sccc) {
  46. while ((in_8(sccc) & SCC_RXRDY) == 0)
  47. ;
  48. return in_8(sccd);
  49. }
  50. return -1;
  51. }
  52. static unsigned char scc_inittab[] = {
  53. 13, 0, /* set baud rate divisor */
  54. 12, 0,
  55. 14, 1, /* baud rate gen enable, src=rtxc */
  56. 11, 0x50, /* clocks = br gen */
  57. 5, 0xea, /* tx 8 bits, assert DTR & RTS */
  58. 4, 0x46, /* x16 clock, 1 stop */
  59. 3, 0xc1, /* rx enable, 8 bits */
  60. };
  61. void udbg_scc_init(int force_scc)
  62. {
  63. const u32 *reg;
  64. unsigned long addr;
  65. struct device_node *stdout = NULL, *escc = NULL, *macio = NULL;
  66. struct device_node *ch, *ch_def = NULL, *ch_a = NULL;
  67. const char *path;
  68. int i, x;
  69. escc = of_find_node_by_name(NULL, "escc");
  70. if (escc == NULL)
  71. goto bail;
  72. macio = of_get_parent(escc);
  73. if (macio == NULL)
  74. goto bail;
  75. path = of_get_property(of_chosen, "linux,stdout-path", NULL);
  76. if (path != NULL)
  77. stdout = of_find_node_by_path(path);
  78. for (ch = NULL; (ch = of_get_next_child(escc, ch)) != NULL;) {
  79. if (ch == stdout)
  80. ch_def = of_node_get(ch);
  81. if (strcmp(ch->name, "ch-a") == 0)
  82. ch_a = of_node_get(ch);
  83. }
  84. if (ch_def == NULL && !force_scc)
  85. goto bail;
  86. ch = ch_def ? ch_def : ch_a;
  87. /* Get address within mac-io ASIC */
  88. reg = of_get_property(escc, "reg", NULL);
  89. if (reg == NULL)
  90. goto bail;
  91. addr = reg[0];
  92. /* Get address of mac-io PCI itself */
  93. reg = of_get_property(macio, "assigned-addresses", NULL);
  94. if (reg == NULL)
  95. goto bail;
  96. addr += reg[2];
  97. /* Lock the serial port */
  98. pmac_call_feature(PMAC_FTR_SCC_ENABLE, ch,
  99. PMAC_SCC_ASYNC | PMAC_SCC_FLAG_XMON, 1);
  100. if (ch == ch_a)
  101. addr += 0x20;
  102. sccc = ioremap(addr & PAGE_MASK, PAGE_SIZE) ;
  103. sccc += addr & ~PAGE_MASK;
  104. sccd = sccc + 0x10;
  105. mb();
  106. for (i = 20000; i != 0; --i)
  107. x = in_8(sccc);
  108. out_8(sccc, 0x09); /* reset A or B side */
  109. out_8(sccc, 0xc0);
  110. /* If SCC was the OF output port, read the BRG value, else
  111. * Setup for 38400 or 57600 8N1 depending on the machine
  112. */
  113. if (ch_def != NULL) {
  114. out_8(sccc, 13);
  115. scc_inittab[1] = in_8(sccc);
  116. out_8(sccc, 12);
  117. scc_inittab[3] = in_8(sccc);
  118. } else if (of_machine_is_compatible("RackMac1,1")
  119. || of_machine_is_compatible("RackMac1,2")
  120. || of_machine_is_compatible("MacRISC4")) {
  121. /* Xserves and G5s default to 57600 */
  122. scc_inittab[1] = 0;
  123. scc_inittab[3] = 0;
  124. } else {
  125. /* Others default to 38400 */
  126. scc_inittab[1] = 0;
  127. scc_inittab[3] = 1;
  128. }
  129. for (i = 0; i < sizeof(scc_inittab); ++i)
  130. out_8(sccc, scc_inittab[i]);
  131. udbg_putc = udbg_scc_putc;
  132. udbg_getc = udbg_scc_getc;
  133. udbg_getc_poll = udbg_scc_getc_poll;
  134. udbg_puts("Hello World !\n");
  135. bail:
  136. of_node_put(macio);
  137. of_node_put(escc);
  138. of_node_put(stdout);
  139. of_node_put(ch_def);
  140. of_node_put(ch_a);
  141. }
  142. #ifdef CONFIG_PPC64
  143. static void udbg_real_scc_putc(char c)
  144. {
  145. while ((real_readb(sccc) & SCC_TXRDY) == 0)
  146. ;
  147. real_writeb(c, sccd);
  148. if (c == '\n')
  149. udbg_real_scc_putc('\r');
  150. }
  151. void __init udbg_init_pmac_realmode(void)
  152. {
  153. sccc = (volatile u8 __iomem *)0x80013020ul;
  154. sccd = (volatile u8 __iomem *)0x80013030ul;
  155. udbg_putc = udbg_real_scc_putc;
  156. udbg_getc = NULL;
  157. udbg_getc_poll = NULL;
  158. }
  159. #endif /* CONFIG_PPC64 */