via_modesetting.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
  3. * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
  4. * Copyright 2010 Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public
  8. * License as published by the Free Software Foundation;
  9. * either version 2, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
  13. * the implied warranty of MERCHANTABILITY or FITNESS FOR
  14. * A PARTICULAR PURPOSE.See the GNU General Public License
  15. * for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc.,
  20. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. /*
  23. * basic modesetting functions
  24. */
  25. #include <linux/kernel.h>
  26. #include <linux/via-core.h>
  27. #include "via_modesetting.h"
  28. #include "share.h"
  29. #include "debug.h"
  30. void via_set_primary_timing(const struct via_display_timing *timing)
  31. {
  32. struct via_display_timing raw;
  33. raw.hor_total = timing->hor_total / 8 - 5;
  34. raw.hor_addr = timing->hor_addr / 8 - 1;
  35. raw.hor_blank_start = timing->hor_blank_start / 8 - 1;
  36. raw.hor_blank_end = timing->hor_blank_end / 8 - 1;
  37. raw.hor_sync_start = timing->hor_sync_start / 8;
  38. raw.hor_sync_end = timing->hor_sync_end / 8;
  39. raw.ver_total = timing->ver_total - 2;
  40. raw.ver_addr = timing->ver_addr - 1;
  41. raw.ver_blank_start = timing->ver_blank_start - 1;
  42. raw.ver_blank_end = timing->ver_blank_end - 1;
  43. raw.ver_sync_start = timing->ver_sync_start - 1;
  44. raw.ver_sync_end = timing->ver_sync_end - 1;
  45. /* unlock timing registers */
  46. via_write_reg_mask(VIACR, 0x11, 0x00, 0x80);
  47. via_write_reg(VIACR, 0x00, raw.hor_total & 0xFF);
  48. via_write_reg(VIACR, 0x01, raw.hor_addr & 0xFF);
  49. via_write_reg(VIACR, 0x02, raw.hor_blank_start & 0xFF);
  50. via_write_reg_mask(VIACR, 0x03, raw.hor_blank_end & 0x1F, 0x1F);
  51. via_write_reg(VIACR, 0x04, raw.hor_sync_start & 0xFF);
  52. via_write_reg_mask(VIACR, 0x05, (raw.hor_sync_end & 0x1F)
  53. | (raw.hor_blank_end << (7 - 5) & 0x80), 0x9F);
  54. via_write_reg(VIACR, 0x06, raw.ver_total & 0xFF);
  55. via_write_reg_mask(VIACR, 0x07, (raw.ver_total >> 8 & 0x01)
  56. | (raw.ver_addr >> (8 - 1) & 0x02)
  57. | (raw.ver_sync_start >> (8 - 2) & 0x04)
  58. | (raw.ver_blank_start >> (8 - 3) & 0x08)
  59. | (raw.ver_total >> (9 - 5) & 0x20)
  60. | (raw.ver_addr >> (9 - 6) & 0x40)
  61. | (raw.ver_sync_start >> (9 - 7) & 0x80), 0xEF);
  62. via_write_reg_mask(VIACR, 0x09, raw.ver_blank_start >> (9 - 5) & 0x20,
  63. 0x20);
  64. via_write_reg(VIACR, 0x10, raw.ver_sync_start & 0xFF);
  65. via_write_reg_mask(VIACR, 0x11, raw.ver_sync_end & 0x0F, 0x0F);
  66. via_write_reg(VIACR, 0x12, raw.ver_addr & 0xFF);
  67. via_write_reg(VIACR, 0x15, raw.ver_blank_start & 0xFF);
  68. via_write_reg(VIACR, 0x16, raw.ver_blank_end & 0xFF);
  69. via_write_reg_mask(VIACR, 0x33, (raw.hor_sync_start >> (8 - 4) & 0x10)
  70. | (raw.hor_blank_end >> (6 - 5) & 0x20), 0x30);
  71. via_write_reg_mask(VIACR, 0x35, (raw.ver_total >> 10 & 0x01)
  72. | (raw.ver_sync_start >> (10 - 1) & 0x02)
  73. | (raw.ver_addr >> (10 - 2) & 0x04)
  74. | (raw.ver_blank_start >> (10 - 3) & 0x08), 0x0F);
  75. via_write_reg_mask(VIACR, 0x36, raw.hor_total >> (8 - 3) & 0x08, 0x08);
  76. /* lock timing registers */
  77. via_write_reg_mask(VIACR, 0x11, 0x80, 0x80);
  78. /* reset timing control */
  79. via_write_reg_mask(VIACR, 0x17, 0x00, 0x80);
  80. via_write_reg_mask(VIACR, 0x17, 0x80, 0x80);
  81. }
  82. void via_set_secondary_timing(const struct via_display_timing *timing)
  83. {
  84. struct via_display_timing raw;
  85. raw.hor_total = timing->hor_total - 1;
  86. raw.hor_addr = timing->hor_addr - 1;
  87. raw.hor_blank_start = timing->hor_blank_start - 1;
  88. raw.hor_blank_end = timing->hor_blank_end - 1;
  89. raw.hor_sync_start = timing->hor_sync_start - 1;
  90. raw.hor_sync_end = timing->hor_sync_end - 1;
  91. raw.ver_total = timing->ver_total - 1;
  92. raw.ver_addr = timing->ver_addr - 1;
  93. raw.ver_blank_start = timing->ver_blank_start - 1;
  94. raw.ver_blank_end = timing->ver_blank_end - 1;
  95. raw.ver_sync_start = timing->ver_sync_start - 1;
  96. raw.ver_sync_end = timing->ver_sync_end - 1;
  97. via_write_reg(VIACR, 0x50, raw.hor_total & 0xFF);
  98. via_write_reg(VIACR, 0x51, raw.hor_addr & 0xFF);
  99. via_write_reg(VIACR, 0x52, raw.hor_blank_start & 0xFF);
  100. via_write_reg(VIACR, 0x53, raw.hor_blank_end & 0xFF);
  101. via_write_reg(VIACR, 0x54, (raw.hor_blank_start >> 8 & 0x07)
  102. | (raw.hor_blank_end >> (8 - 3) & 0x38)
  103. | (raw.hor_sync_start >> (8 - 6) & 0xC0));
  104. via_write_reg_mask(VIACR, 0x55, (raw.hor_total >> 8 & 0x0F)
  105. | (raw.hor_addr >> (8 - 4) & 0x70), 0x7F);
  106. via_write_reg(VIACR, 0x56, raw.hor_sync_start & 0xFF);
  107. via_write_reg(VIACR, 0x57, raw.hor_sync_end & 0xFF);
  108. via_write_reg(VIACR, 0x58, raw.ver_total & 0xFF);
  109. via_write_reg(VIACR, 0x59, raw.ver_addr & 0xFF);
  110. via_write_reg(VIACR, 0x5A, raw.ver_blank_start & 0xFF);
  111. via_write_reg(VIACR, 0x5B, raw.ver_blank_end & 0xFF);
  112. via_write_reg(VIACR, 0x5C, (raw.ver_blank_start >> 8 & 0x07)
  113. | (raw.ver_blank_end >> (8 - 3) & 0x38)
  114. | (raw.hor_sync_end >> (8 - 6) & 0x40)
  115. | (raw.hor_sync_start >> (10 - 7) & 0x80));
  116. via_write_reg(VIACR, 0x5D, (raw.ver_total >> 8 & 0x07)
  117. | (raw.ver_addr >> (8 - 3) & 0x38)
  118. | (raw.hor_blank_end >> (11 - 6) & 0x40)
  119. | (raw.hor_sync_start >> (11 - 7) & 0x80));
  120. via_write_reg(VIACR, 0x5E, raw.ver_sync_start & 0xFF);
  121. via_write_reg(VIACR, 0x5F, (raw.ver_sync_end & 0x1F)
  122. | (raw.ver_sync_start >> (8 - 5) & 0xE0));
  123. }
  124. void via_set_primary_address(u32 addr)
  125. {
  126. DEBUG_MSG(KERN_DEBUG "via_set_primary_address(0x%08X)\n", addr);
  127. via_write_reg(VIACR, 0x0D, addr & 0xFF);
  128. via_write_reg(VIACR, 0x0C, (addr >> 8) & 0xFF);
  129. via_write_reg(VIACR, 0x34, (addr >> 16) & 0xFF);
  130. via_write_reg_mask(VIACR, 0x48, (addr >> 24) & 0x1F, 0x1F);
  131. }
  132. void via_set_secondary_address(u32 addr)
  133. {
  134. DEBUG_MSG(KERN_DEBUG "via_set_secondary_address(0x%08X)\n", addr);
  135. /* secondary display supports only quadword aligned memory */
  136. via_write_reg_mask(VIACR, 0x62, (addr >> 2) & 0xFE, 0xFE);
  137. via_write_reg(VIACR, 0x63, (addr >> 10) & 0xFF);
  138. via_write_reg(VIACR, 0x64, (addr >> 18) & 0xFF);
  139. via_write_reg_mask(VIACR, 0xA3, (addr >> 26) & 0x07, 0x07);
  140. }
  141. void via_set_primary_pitch(u32 pitch)
  142. {
  143. DEBUG_MSG(KERN_DEBUG "via_set_primary_pitch(0x%08X)\n", pitch);
  144. /* spec does not say that first adapter skips 3 bits but old
  145. * code did it and seems to be reasonable in analogy to 2nd adapter
  146. */
  147. pitch = pitch >> 3;
  148. via_write_reg(VIACR, 0x13, pitch & 0xFF);
  149. via_write_reg_mask(VIACR, 0x35, (pitch >> (8 - 5)) & 0xE0, 0xE0);
  150. }
  151. void via_set_secondary_pitch(u32 pitch)
  152. {
  153. DEBUG_MSG(KERN_DEBUG "via_set_secondary_pitch(0x%08X)\n", pitch);
  154. pitch = pitch >> 3;
  155. via_write_reg(VIACR, 0x66, pitch & 0xFF);
  156. via_write_reg_mask(VIACR, 0x67, (pitch >> 8) & 0x03, 0x03);
  157. via_write_reg_mask(VIACR, 0x71, (pitch >> (10 - 7)) & 0x80, 0x80);
  158. }
  159. void via_set_primary_color_depth(u8 depth)
  160. {
  161. u8 value;
  162. DEBUG_MSG(KERN_DEBUG "via_set_primary_color_depth(%d)\n", depth);
  163. switch (depth) {
  164. case 8:
  165. value = 0x00;
  166. break;
  167. case 15:
  168. value = 0x04;
  169. break;
  170. case 16:
  171. value = 0x14;
  172. break;
  173. case 24:
  174. value = 0x0C;
  175. break;
  176. case 30:
  177. value = 0x08;
  178. break;
  179. default:
  180. printk(KERN_WARNING "via_set_primary_color_depth: "
  181. "Unsupported depth: %d\n", depth);
  182. return;
  183. }
  184. via_write_reg_mask(VIASR, 0x15, value, 0x1C);
  185. }
  186. void via_set_secondary_color_depth(u8 depth)
  187. {
  188. u8 value;
  189. DEBUG_MSG(KERN_DEBUG "via_set_secondary_color_depth(%d)\n", depth);
  190. switch (depth) {
  191. case 8:
  192. value = 0x00;
  193. break;
  194. case 16:
  195. value = 0x40;
  196. break;
  197. case 24:
  198. value = 0xC0;
  199. break;
  200. case 30:
  201. value = 0x80;
  202. break;
  203. default:
  204. printk(KERN_WARNING "via_set_secondary_color_depth: "
  205. "Unsupported depth: %d\n", depth);
  206. return;
  207. }
  208. via_write_reg_mask(VIACR, 0x67, value, 0xC0);
  209. }