mpsc.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * MPSC/UART driver for the Marvell mv64360, mv64460, ...
  3. *
  4. * Author: Mark A. Greer <mgreer@mvista.com>
  5. *
  6. * 2007 (c) MontaVista Software, Inc. This file is licensed under
  7. * the terms of the GNU General Public License version 2. This program
  8. * is licensed "as is" without any warranty of any kind, whether express
  9. * or implied.
  10. */
  11. #include <stdarg.h>
  12. #include <stddef.h>
  13. #include "types.h"
  14. #include "string.h"
  15. #include "stdio.h"
  16. #include "io.h"
  17. #include "ops.h"
  18. extern void udelay(long delay);
  19. #define MPSC_CHR_1 0x000c
  20. #define MPSC_CHR_2 0x0010
  21. #define MPSC_CHR_2_TA (1<<7)
  22. #define MPSC_CHR_2_TCS (1<<9)
  23. #define MPSC_CHR_2_RA (1<<23)
  24. #define MPSC_CHR_2_CRD (1<<25)
  25. #define MPSC_CHR_2_EH (1<<31)
  26. #define MPSC_CHR_4 0x0018
  27. #define MPSC_CHR_4_Z (1<<29)
  28. #define MPSC_CHR_5 0x001c
  29. #define MPSC_CHR_5_CTL1_INTR (1<<12)
  30. #define MPSC_CHR_5_CTL1_VALID (1<<15)
  31. #define MPSC_CHR_10 0x0030
  32. #define MPSC_INTR_CAUSE 0x0000
  33. #define MPSC_INTR_CAUSE_RCC (1<<6)
  34. #define MPSC_INTR_MASK 0x0080
  35. #define SDMA_SDCM 0x0008
  36. #define SDMA_SDCM_AR (1<<15)
  37. #define SDMA_SDCM_AT (1<<31)
  38. static volatile char *mpsc_base;
  39. static volatile char *mpscintr_base;
  40. static u32 chr1, chr2;
  41. static int mpsc_open(void)
  42. {
  43. chr1 = in_le32((u32 *)(mpsc_base + MPSC_CHR_1)) & 0x00ff0000;
  44. chr2 = in_le32((u32 *)(mpsc_base + MPSC_CHR_2)) & ~(MPSC_CHR_2_TA
  45. | MPSC_CHR_2_TCS | MPSC_CHR_2_RA | MPSC_CHR_2_CRD
  46. | MPSC_CHR_2_EH);
  47. out_le32((u32 *)(mpsc_base + MPSC_CHR_4), MPSC_CHR_4_Z);
  48. out_le32((u32 *)(mpsc_base + MPSC_CHR_5),
  49. MPSC_CHR_5_CTL1_INTR | MPSC_CHR_5_CTL1_VALID);
  50. out_le32((u32 *)(mpsc_base + MPSC_CHR_2), chr2 | MPSC_CHR_2_EH);
  51. return 0;
  52. }
  53. static void mpsc_putc(unsigned char c)
  54. {
  55. while (in_le32((u32 *)(mpsc_base + MPSC_CHR_2)) & MPSC_CHR_2_TCS);
  56. out_le32((u32 *)(mpsc_base + MPSC_CHR_1), chr1 | c);
  57. out_le32((u32 *)(mpsc_base + MPSC_CHR_2), chr2 | MPSC_CHR_2_TCS);
  58. }
  59. static unsigned char mpsc_getc(void)
  60. {
  61. u32 cause = 0;
  62. unsigned char c;
  63. while (!(cause & MPSC_INTR_CAUSE_RCC))
  64. cause = in_le32((u32 *)(mpscintr_base + MPSC_INTR_CAUSE));
  65. c = in_8((u8 *)(mpsc_base + MPSC_CHR_10 + 2));
  66. out_8((u8 *)(mpsc_base + MPSC_CHR_10 + 2), c);
  67. out_le32((u32 *)(mpscintr_base + MPSC_INTR_CAUSE),
  68. cause & ~MPSC_INTR_CAUSE_RCC);
  69. return c;
  70. }
  71. static u8 mpsc_tstc(void)
  72. {
  73. return (u8)((in_le32((u32 *)(mpscintr_base + MPSC_INTR_CAUSE))
  74. & MPSC_INTR_CAUSE_RCC) != 0);
  75. }
  76. static void mpsc_stop_dma(volatile char *sdma_base)
  77. {
  78. out_le32((u32 *)(mpsc_base + MPSC_CHR_2),MPSC_CHR_2_TA | MPSC_CHR_2_RA);
  79. out_le32((u32 *)(sdma_base + SDMA_SDCM), SDMA_SDCM_AR | SDMA_SDCM_AT);
  80. while ((in_le32((u32 *)(sdma_base + SDMA_SDCM))
  81. & (SDMA_SDCM_AR | SDMA_SDCM_AT)) != 0)
  82. udelay(100);
  83. }
  84. static volatile char *mpsc_get_virtreg_of_phandle(void *devp, char *prop)
  85. {
  86. void *v;
  87. int n;
  88. n = getprop(devp, prop, &v, sizeof(v));
  89. if (n != sizeof(v))
  90. goto err_out;
  91. devp = find_node_by_linuxphandle((u32)v);
  92. if (devp == NULL)
  93. goto err_out;
  94. n = getprop(devp, "virtual-reg", &v, sizeof(v));
  95. if (n == sizeof(v))
  96. return v;
  97. err_out:
  98. return NULL;
  99. }
  100. int mpsc_console_init(void *devp, struct serial_console_data *scdp)
  101. {
  102. void *v;
  103. int n, reg_set;
  104. volatile char *sdma_base;
  105. n = getprop(devp, "virtual-reg", &v, sizeof(v));
  106. if (n != sizeof(v))
  107. goto err_out;
  108. mpsc_base = v;
  109. sdma_base = mpsc_get_virtreg_of_phandle(devp, "sdma");
  110. if (sdma_base == NULL)
  111. goto err_out;
  112. mpscintr_base = mpsc_get_virtreg_of_phandle(devp, "mpscintr");
  113. if (mpscintr_base == NULL)
  114. goto err_out;
  115. n = getprop(devp, "block-index", &v, sizeof(v));
  116. if (n != sizeof(v))
  117. goto err_out;
  118. reg_set = (int)v;
  119. mpscintr_base += (reg_set == 0) ? 0x4 : 0xc;
  120. /* Make sure the mpsc ctlrs are shutdown */
  121. out_le32((u32 *)(mpscintr_base + MPSC_INTR_CAUSE), 0);
  122. out_le32((u32 *)(mpscintr_base + MPSC_INTR_CAUSE), 0);
  123. out_le32((u32 *)(mpscintr_base + MPSC_INTR_MASK), 0);
  124. out_le32((u32 *)(mpscintr_base + MPSC_INTR_MASK), 0);
  125. mpsc_stop_dma(sdma_base);
  126. scdp->open = mpsc_open;
  127. scdp->putc = mpsc_putc;
  128. scdp->getc = mpsc_getc;
  129. scdp->tstc = mpsc_tstc;
  130. scdp->close = NULL;
  131. return 0;
  132. err_out:
  133. return -1;
  134. }