udbg_scc.c 3.6 KB

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