STG4000VTG.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * linux/drivers/video/kyro/STG4000VTG.c
  3. *
  4. * Copyright (C) 2002 STMicroelectronics
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/types.h>
  11. #include <video/kyro.h>
  12. #include "STG4000Reg.h"
  13. #include "STG4000Interface.h"
  14. void DisableVGA(volatile STG4000REG __iomem *pSTGReg)
  15. {
  16. u32 tmp;
  17. volatile u32 count = 0, i;
  18. /* Reset the VGA registers */
  19. tmp = STG_READ_REG(SoftwareReset);
  20. CLEAR_BIT(8);
  21. STG_WRITE_REG(SoftwareReset, tmp);
  22. /* Just for Delay */
  23. for (i = 0; i < 1000; i++) {
  24. count++;
  25. }
  26. /* Pull-out the VGA registers from reset */
  27. tmp = STG_READ_REG(SoftwareReset);
  28. tmp |= SET_BIT(8);
  29. STG_WRITE_REG(SoftwareReset, tmp);
  30. }
  31. void StopVTG(volatile STG4000REG __iomem *pSTGReg)
  32. {
  33. u32 tmp = 0;
  34. /* Stop Ver and Hor Sync Generator */
  35. tmp = (STG_READ_REG(DACSyncCtrl)) | SET_BIT(0) | SET_BIT(2);
  36. CLEAR_BIT(31);
  37. STG_WRITE_REG(DACSyncCtrl, tmp);
  38. }
  39. void StartVTG(volatile STG4000REG __iomem *pSTGReg)
  40. {
  41. u32 tmp = 0;
  42. /* Start Ver and Hor Sync Generator */
  43. tmp = ((STG_READ_REG(DACSyncCtrl)) | SET_BIT(31));
  44. CLEAR_BIT(0);
  45. CLEAR_BIT(2);
  46. STG_WRITE_REG(DACSyncCtrl, tmp);
  47. }
  48. void SetupVTG(volatile STG4000REG __iomem *pSTGReg,
  49. const struct kyrofb_info * pTiming)
  50. {
  51. u32 tmp = 0;
  52. u32 margins = 0;
  53. u32 ulBorder;
  54. u32 xRes = pTiming->XRES;
  55. u32 yRes = pTiming->YRES;
  56. /* Horizontal */
  57. u32 HAddrTime, HRightBorder, HLeftBorder;
  58. u32 HBackPorcStrt, HFrontPorchStrt, HTotal,
  59. HLeftBorderStrt, HRightBorderStrt, HDisplayStrt;
  60. /* Vertical */
  61. u32 VDisplayStrt, VBottomBorder, VTopBorder;
  62. u32 VBackPorchStrt, VTotal, VTopBorderStrt,
  63. VFrontPorchStrt, VBottomBorderStrt, VAddrTime;
  64. /* Need to calculate the right border */
  65. if ((xRes == 640) && (yRes == 480)) {
  66. if ((pTiming->VFREQ == 60) || (pTiming->VFREQ == 72)) {
  67. margins = 8;
  68. }
  69. }
  70. /* Work out the Border */
  71. ulBorder =
  72. (pTiming->HTot -
  73. (pTiming->HST + (pTiming->HBP - margins) + xRes +
  74. (pTiming->HFP - margins))) >> 1;
  75. /* Border the same for Vertical and Horizontal */
  76. VBottomBorder = HLeftBorder = VTopBorder = HRightBorder = ulBorder;
  77. /************ Get Timing values for Horizontal ******************/
  78. HAddrTime = xRes;
  79. HBackPorcStrt = pTiming->HST;
  80. HTotal = pTiming->HTot;
  81. HDisplayStrt =
  82. pTiming->HST + (pTiming->HBP - margins) + HLeftBorder;
  83. HLeftBorderStrt = HDisplayStrt - HLeftBorder;
  84. HFrontPorchStrt =
  85. pTiming->HST + (pTiming->HBP - margins) + HLeftBorder +
  86. HAddrTime + HRightBorder;
  87. HRightBorderStrt = HFrontPorchStrt - HRightBorder;
  88. /************ Get Timing values for Vertical ******************/
  89. VAddrTime = yRes;
  90. VBackPorchStrt = pTiming->VST;
  91. VTotal = pTiming->VTot;
  92. VDisplayStrt =
  93. pTiming->VST + (pTiming->VBP - margins) + VTopBorder;
  94. VTopBorderStrt = VDisplayStrt - VTopBorder;
  95. VFrontPorchStrt =
  96. pTiming->VST + (pTiming->VBP - margins) + VTopBorder +
  97. VAddrTime + VBottomBorder;
  98. VBottomBorderStrt = VFrontPorchStrt - VBottomBorder;
  99. /* Set Hor Timing 1, 2, 3 */
  100. tmp = STG_READ_REG(DACHorTim1);
  101. CLEAR_BITS_FRM_TO(0, 11);
  102. CLEAR_BITS_FRM_TO(16, 27);
  103. tmp |= (HTotal) | (HBackPorcStrt << 16);
  104. STG_WRITE_REG(DACHorTim1, tmp);
  105. tmp = STG_READ_REG(DACHorTim2);
  106. CLEAR_BITS_FRM_TO(0, 11);
  107. CLEAR_BITS_FRM_TO(16, 27);
  108. tmp |= (HDisplayStrt << 16) | HLeftBorderStrt;
  109. STG_WRITE_REG(DACHorTim2, tmp);
  110. tmp = STG_READ_REG(DACHorTim3);
  111. CLEAR_BITS_FRM_TO(0, 11);
  112. CLEAR_BITS_FRM_TO(16, 27);
  113. tmp |= (HFrontPorchStrt << 16) | HRightBorderStrt;
  114. STG_WRITE_REG(DACHorTim3, tmp);
  115. /* Set Ver Timing 1, 2, 3 */
  116. tmp = STG_READ_REG(DACVerTim1);
  117. CLEAR_BITS_FRM_TO(0, 11);
  118. CLEAR_BITS_FRM_TO(16, 27);
  119. tmp |= (VBackPorchStrt << 16) | (VTotal);
  120. STG_WRITE_REG(DACVerTim1, tmp);
  121. tmp = STG_READ_REG(DACVerTim2);
  122. CLEAR_BITS_FRM_TO(0, 11);
  123. CLEAR_BITS_FRM_TO(16, 27);
  124. tmp |= (VDisplayStrt << 16) | VTopBorderStrt;
  125. STG_WRITE_REG(DACVerTim2, tmp);
  126. tmp = STG_READ_REG(DACVerTim3);
  127. CLEAR_BITS_FRM_TO(0, 11);
  128. CLEAR_BITS_FRM_TO(16, 27);
  129. tmp |= (VFrontPorchStrt << 16) | VBottomBorderStrt;
  130. STG_WRITE_REG(DACVerTim3, tmp);
  131. /* Set Verical and Horizontal Polarity */
  132. tmp = STG_READ_REG(DACSyncCtrl) | SET_BIT(3) | SET_BIT(1);
  133. if ((pTiming->HSP > 0) && (pTiming->VSP < 0)) { /* +hsync -vsync */
  134. tmp &= ~0x8;
  135. } else if ((pTiming->HSP < 0) && (pTiming->VSP > 0)) { /* -hsync +vsync */
  136. tmp &= ~0x2;
  137. } else if ((pTiming->HSP < 0) && (pTiming->VSP < 0)) { /* -hsync -vsync */
  138. tmp &= ~0xA;
  139. } else if ((pTiming->HSP > 0) && (pTiming->VSP > 0)) { /* +hsync -vsync */
  140. tmp &= ~0x0;
  141. }
  142. STG_WRITE_REG(DACSyncCtrl, tmp);
  143. }