udbg_scc.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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/ppcdebug.h>
  14. #include <asm/processor.h>
  15. #include <asm/naca.h>
  16. #include <asm/uaccess.h>
  17. #include <asm/machdep.h>
  18. #include <asm/io.h>
  19. #include <asm/prom.h>
  20. #include <asm/pmac_feature.h>
  21. extern u8 real_readb(volatile u8 __iomem *addr);
  22. extern void real_writeb(u8 data, volatile u8 __iomem *addr);
  23. #define SCC_TXRDY 4
  24. #define SCC_RXRDY 1
  25. static volatile u8 __iomem *sccc;
  26. static volatile u8 __iomem *sccd;
  27. static void udbg_scc_putc(unsigned char c)
  28. {
  29. if (sccc) {
  30. while ((in_8(sccc) & SCC_TXRDY) == 0)
  31. ;
  32. out_8(sccd, c);
  33. if (c == '\n')
  34. udbg_scc_putc('\r');
  35. }
  36. }
  37. static int udbg_scc_getc_poll(void)
  38. {
  39. if (sccc) {
  40. if ((in_8(sccc) & SCC_RXRDY) != 0)
  41. return in_8(sccd);
  42. else
  43. return -1;
  44. }
  45. return -1;
  46. }
  47. static unsigned char udbg_scc_getc(void)
  48. {
  49. if (sccc) {
  50. while ((in_8(sccc) & SCC_RXRDY) == 0)
  51. ;
  52. return in_8(sccd);
  53. }
  54. return 0;
  55. }
  56. static unsigned char scc_inittab[] = {
  57. 13, 0, /* set baud rate divisor */
  58. 12, 0,
  59. 14, 1, /* baud rate gen enable, src=rtxc */
  60. 11, 0x50, /* clocks = br gen */
  61. 5, 0xea, /* tx 8 bits, assert DTR & RTS */
  62. 4, 0x46, /* x16 clock, 1 stop */
  63. 3, 0xc1, /* rx enable, 8 bits */
  64. };
  65. void udbg_init_scc(struct device_node *np)
  66. {
  67. u32 *reg;
  68. unsigned long addr;
  69. int i, x;
  70. if (np == NULL)
  71. np = of_find_node_by_name(NULL, "escc");
  72. if (np == NULL || np->parent == NULL)
  73. return;
  74. udbg_printf("found SCC...\n");
  75. /* Get address within mac-io ASIC */
  76. reg = (u32 *)get_property(np, "reg", NULL);
  77. if (reg == NULL)
  78. return;
  79. addr = reg[0];
  80. udbg_printf("local addr: %lx\n", addr);
  81. /* Get address of mac-io PCI itself */
  82. reg = (u32 *)get_property(np->parent, "assigned-addresses", NULL);
  83. if (reg == NULL)
  84. return;
  85. addr += reg[2];
  86. udbg_printf("final addr: %lx\n", addr);
  87. /* Setup for 57600 8N1 */
  88. addr += 0x20;
  89. sccc = (volatile u8 * __iomem) ioremap(addr & PAGE_MASK, PAGE_SIZE) ;
  90. sccc += addr & ~PAGE_MASK;
  91. sccd = sccc + 0x10;
  92. udbg_printf("ioremap result sccc: %p\n", sccc);
  93. mb();
  94. for (i = 20000; i != 0; --i)
  95. x = in_8(sccc);
  96. out_8(sccc, 0x09); /* reset A or B side */
  97. out_8(sccc, 0xc0);
  98. for (i = 0; i < sizeof(scc_inittab); ++i)
  99. out_8(sccc, scc_inittab[i]);
  100. ppc_md.udbg_putc = udbg_scc_putc;
  101. ppc_md.udbg_getc = udbg_scc_getc;
  102. ppc_md.udbg_getc_poll = udbg_scc_getc_poll;
  103. udbg_puts("Hello World !\n");
  104. }
  105. static void udbg_real_scc_putc(unsigned char c)
  106. {
  107. while ((real_readb(sccc) & SCC_TXRDY) == 0)
  108. ;
  109. real_writeb(c, sccd);
  110. if (c == '\n')
  111. udbg_real_scc_putc('\r');
  112. }
  113. void udbg_init_pmac_realmode(void)
  114. {
  115. sccc = (volatile u8 __iomem *)0x80013020ul;
  116. sccd = (volatile u8 __iomem *)0x80013030ul;
  117. ppc_md.udbg_putc = udbg_real_scc_putc;
  118. ppc_md.udbg_getc = NULL;
  119. ppc_md.udbg_getc_poll = NULL;
  120. }