STG4000Ramdac.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * linux/drivers/video/kyro/STG4000Ramdac.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/kernel.h>
  11. #include <linux/errno.h>
  12. #include <linux/types.h>
  13. #include <video/kyro.h>
  14. #include "STG4000Reg.h"
  15. #include "STG4000Interface.h"
  16. static u32 STG_PIXEL_BUS_WIDTH = 128; /* 128 bit bus width */
  17. static u32 REF_CLOCK = 14318;
  18. int InitialiseRamdac(volatile STG4000REG __iomem * pSTGReg,
  19. u32 displayDepth,
  20. u32 displayWidth,
  21. u32 displayHeight,
  22. s32 HSyncPolarity,
  23. s32 VSyncPolarity, u32 * pixelClock)
  24. {
  25. u32 tmp = 0;
  26. u32 F = 0, R = 0, P = 0;
  27. u32 stride = 0;
  28. u32 ulPdiv = 0;
  29. u32 physicalPixelDepth = 0;
  30. /* Make sure DAC is in Reset */
  31. tmp = STG_READ_REG(SoftwareReset);
  32. if (tmp & 0x1) {
  33. CLEAR_BIT(1);
  34. STG_WRITE_REG(SoftwareReset, tmp);
  35. }
  36. /* Set Pixel Format */
  37. tmp = STG_READ_REG(DACPixelFormat);
  38. CLEAR_BITS_FRM_TO(0, 2);
  39. /* Set LUT not used from 16bpp to 32 bpp ??? */
  40. CLEAR_BITS_FRM_TO(8, 9);
  41. switch (displayDepth) {
  42. case 16:
  43. {
  44. physicalPixelDepth = 16;
  45. tmp |= _16BPP;
  46. break;
  47. }
  48. case 32:
  49. {
  50. /* Set for 32 bits per pixel */
  51. physicalPixelDepth = 32;
  52. tmp |= _32BPP;
  53. break;
  54. }
  55. default:
  56. return -EINVAL;
  57. }
  58. STG_WRITE_REG(DACPixelFormat, tmp);
  59. /* Workout Bus transfer bandwidth according to pixel format */
  60. ulPdiv = STG_PIXEL_BUS_WIDTH / physicalPixelDepth;
  61. /* Get Screen Stride in pixels */
  62. stride = displayWidth;
  63. /* Set Primary size info */
  64. tmp = STG_READ_REG(DACPrimSize);
  65. CLEAR_BITS_FRM_TO(0, 10);
  66. CLEAR_BITS_FRM_TO(12, 31);
  67. tmp |=
  68. ((((displayHeight - 1) << 12) | (((displayWidth / ulPdiv) -
  69. 1) << 23))
  70. | (stride / ulPdiv));
  71. STG_WRITE_REG(DACPrimSize, tmp);
  72. /* Set Pixel Clock */
  73. *pixelClock = ProgramClock(REF_CLOCK, *pixelClock, &F, &R, &P);
  74. /* Set DAC PLL Mode */
  75. tmp = STG_READ_REG(DACPLLMode);
  76. CLEAR_BITS_FRM_TO(0, 15);
  77. /* tmp |= ((P-1) | ((F-2) << 2) | ((R-2) << 11)); */
  78. tmp |= ((P) | ((F - 2) << 2) | ((R - 2) << 11));
  79. STG_WRITE_REG(DACPLLMode, tmp);
  80. /* Set Prim Address */
  81. tmp = STG_READ_REG(DACPrimAddress);
  82. CLEAR_BITS_FRM_TO(0, 20);
  83. CLEAR_BITS_FRM_TO(20, 31);
  84. STG_WRITE_REG(DACPrimAddress, tmp);
  85. /* Set Cursor details with HW Cursor disabled */
  86. tmp = STG_READ_REG(DACCursorCtrl);
  87. tmp &= ~SET_BIT(31);
  88. STG_WRITE_REG(DACCursorCtrl, tmp);
  89. tmp = STG_READ_REG(DACCursorAddr);
  90. CLEAR_BITS_FRM_TO(0, 20);
  91. STG_WRITE_REG(DACCursorAddr, tmp);
  92. /* Set Video Window */
  93. tmp = STG_READ_REG(DACVidWinStart);
  94. CLEAR_BITS_FRM_TO(0, 10);
  95. CLEAR_BITS_FRM_TO(16, 26);
  96. STG_WRITE_REG(DACVidWinStart, tmp);
  97. tmp = STG_READ_REG(DACVidWinEnd);
  98. CLEAR_BITS_FRM_TO(0, 10);
  99. CLEAR_BITS_FRM_TO(16, 26);
  100. STG_WRITE_REG(DACVidWinEnd, tmp);
  101. /* Set DAC Border Color to default */
  102. tmp = STG_READ_REG(DACBorderColor);
  103. CLEAR_BITS_FRM_TO(0, 23);
  104. STG_WRITE_REG(DACBorderColor, tmp);
  105. /* Set Graphics and Overlay Burst Control */
  106. STG_WRITE_REG(DACBurstCtrl, 0x0404);
  107. /* Set CRC Trigger to default */
  108. tmp = STG_READ_REG(DACCrcTrigger);
  109. CLEAR_BIT(0);
  110. STG_WRITE_REG(DACCrcTrigger, tmp);
  111. /* Set Video Port Control to default */
  112. tmp = STG_READ_REG(DigVidPortCtrl);
  113. CLEAR_BIT(8);
  114. CLEAR_BITS_FRM_TO(16, 27);
  115. CLEAR_BITS_FRM_TO(1, 3);
  116. CLEAR_BITS_FRM_TO(10, 11);
  117. STG_WRITE_REG(DigVidPortCtrl, tmp);
  118. return 0;
  119. }
  120. /* Ramdac control, turning output to the screen on and off */
  121. void DisableRamdacOutput(volatile STG4000REG __iomem * pSTGReg)
  122. {
  123. u32 tmp;
  124. /* Disable DAC for Graphics Stream Control */
  125. tmp = (STG_READ_REG(DACStreamCtrl)) & ~SET_BIT(0);
  126. STG_WRITE_REG(DACStreamCtrl, tmp);
  127. }
  128. void EnableRamdacOutput(volatile STG4000REG __iomem * pSTGReg)
  129. {
  130. u32 tmp;
  131. /* Enable DAC for Graphics Stream Control */
  132. tmp = (STG_READ_REG(DACStreamCtrl)) | SET_BIT(0);
  133. STG_WRITE_REG(DACStreamCtrl, tmp);
  134. }