early_printk.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * arch/sh64/kernel/early_printk.c
  3. *
  4. * SH-5 Early SCIF console (cloned and hacked from sh implementation)
  5. *
  6. * Copyright (C) 2003, 2004 Paul Mundt <lethal@linux-sh.org>
  7. * Copyright (C) 2002 M. R. Brown <mrbrown@0xd6.org>
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file "COPYING" in the main directory of this archive
  11. * for more details.
  12. */
  13. #include <linux/console.h>
  14. #include <linux/tty.h>
  15. #include <linux/init.h>
  16. #include <asm/io.h>
  17. #include <asm/hardware.h>
  18. #define SCIF_BASE_ADDR 0x01030000
  19. #define SCIF_ADDR_SH5 PHYS_PERIPHERAL_BLOCK+SCIF_BASE_ADDR
  20. /*
  21. * Fixed virtual address where SCIF is mapped (should already be done
  22. * in arch/sh64/kernel/head.S!).
  23. */
  24. #define SCIF_REG 0xfa030000
  25. enum {
  26. SCIF_SCSMR2 = SCIF_REG + 0x00,
  27. SCIF_SCBRR2 = SCIF_REG + 0x04,
  28. SCIF_SCSCR2 = SCIF_REG + 0x08,
  29. SCIF_SCFTDR2 = SCIF_REG + 0x0c,
  30. SCIF_SCFSR2 = SCIF_REG + 0x10,
  31. SCIF_SCFRDR2 = SCIF_REG + 0x14,
  32. SCIF_SCFCR2 = SCIF_REG + 0x18,
  33. SCIF_SCFDR2 = SCIF_REG + 0x1c,
  34. SCIF_SCSPTR2 = SCIF_REG + 0x20,
  35. SCIF_SCLSR2 = SCIF_REG + 0x24,
  36. };
  37. static void sh_console_putc(int c)
  38. {
  39. while (!(ctrl_inw(SCIF_SCFSR2) & 0x20))
  40. cpu_relax();
  41. ctrl_outb(c, SCIF_SCFTDR2);
  42. ctrl_outw((ctrl_inw(SCIF_SCFSR2) & 0x9f), SCIF_SCFSR2);
  43. if (c == '\n')
  44. sh_console_putc('\r');
  45. }
  46. static void sh_console_flush(void)
  47. {
  48. ctrl_outw((ctrl_inw(SCIF_SCFSR2) & 0xbf), SCIF_SCFSR2);
  49. while (!(ctrl_inw(SCIF_SCFSR2) & 0x40))
  50. cpu_relax();
  51. ctrl_outw((ctrl_inw(SCIF_SCFSR2) & 0xbf), SCIF_SCFSR2);
  52. }
  53. static void sh_console_write(struct console *con, const char *s, unsigned count)
  54. {
  55. while (count-- > 0)
  56. sh_console_putc(*s++);
  57. sh_console_flush();
  58. }
  59. static int __init sh_console_setup(struct console *con, char *options)
  60. {
  61. con->cflag = CREAD | HUPCL | CLOCAL | B19200 | CS8;
  62. return 0;
  63. }
  64. static struct console sh_console = {
  65. .name = "scifcon",
  66. .write = sh_console_write,
  67. .setup = sh_console_setup,
  68. .flags = CON_PRINTBUFFER,
  69. .index = -1,
  70. };
  71. void __init enable_early_printk(void)
  72. {
  73. ctrl_outb(0x2a, SCIF_SCBRR2); /* 19200bps */
  74. ctrl_outw(0x04, SCIF_SCFCR2); /* Reset TFRST */
  75. ctrl_outw(0x10, SCIF_SCFCR2); /* TTRG0=1 */
  76. ctrl_outw(0, SCIF_SCSPTR2);
  77. ctrl_outw(0x60, SCIF_SCFSR2);
  78. ctrl_outw(0, SCIF_SCLSR2);
  79. ctrl_outw(0x30, SCIF_SCSCR2);
  80. register_console(&sh_console);
  81. }
  82. void disable_early_printk(void)
  83. {
  84. unregister_console(&sh_console);
  85. }