via_modesetting.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 display_timing *timing)
  31. {
  32. struct 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. }
  79. void via_set_secondary_timing(const struct display_timing *timing)
  80. {
  81. struct display_timing raw;
  82. raw.hor_total = timing->hor_total - 1;
  83. raw.hor_addr = timing->hor_addr - 1;
  84. raw.hor_blank_start = timing->hor_blank_start - 1;
  85. raw.hor_blank_end = timing->hor_blank_end - 1;
  86. raw.hor_sync_start = timing->hor_sync_start - 1;
  87. raw.hor_sync_end = timing->hor_sync_end - 1;
  88. raw.ver_total = timing->ver_total - 1;
  89. raw.ver_addr = timing->ver_addr - 1;
  90. raw.ver_blank_start = timing->ver_blank_start - 1;
  91. raw.ver_blank_end = timing->ver_blank_end - 1;
  92. raw.ver_sync_start = timing->ver_sync_start - 1;
  93. raw.ver_sync_end = timing->ver_sync_end - 1;
  94. via_write_reg(VIACR, 0x50, raw.hor_total & 0xFF);
  95. via_write_reg(VIACR, 0x51, raw.hor_addr & 0xFF);
  96. via_write_reg(VIACR, 0x52, raw.hor_blank_start & 0xFF);
  97. via_write_reg(VIACR, 0x53, raw.hor_blank_end & 0xFF);
  98. via_write_reg(VIACR, 0x54, (raw.hor_blank_start >> 8 & 0x07)
  99. | (raw.hor_blank_end >> (8 - 3) & 0x38)
  100. | (raw.hor_sync_start >> (8 - 6) & 0xC0));
  101. via_write_reg_mask(VIACR, 0x55, (raw.hor_total >> 8 & 0x0F)
  102. | (raw.hor_addr >> (8 - 4) & 0x70), 0x7F);
  103. via_write_reg(VIACR, 0x56, raw.hor_sync_start & 0xFF);
  104. via_write_reg(VIACR, 0x57, raw.hor_sync_end & 0xFF);
  105. via_write_reg(VIACR, 0x58, raw.ver_total & 0xFF);
  106. via_write_reg(VIACR, 0x59, raw.ver_addr & 0xFF);
  107. via_write_reg(VIACR, 0x5A, raw.ver_blank_start & 0xFF);
  108. via_write_reg(VIACR, 0x5B, raw.ver_blank_end & 0xFF);
  109. via_write_reg(VIACR, 0x5C, (raw.ver_blank_start >> 8 & 0x07)
  110. | (raw.ver_blank_end >> (8 - 3) & 0x38)
  111. | (raw.hor_sync_end >> (8 - 6) & 0x40)
  112. | (raw.hor_sync_start >> (10 - 7) & 0x80));
  113. via_write_reg(VIACR, 0x5D, (raw.ver_total >> 8 & 0x07)
  114. | (raw.ver_addr >> (8 - 3) & 0x38)
  115. | (raw.hor_blank_end >> (11 - 6) & 0x40)
  116. | (raw.hor_sync_start >> (11 - 7) & 0x80));
  117. via_write_reg(VIACR, 0x5E, raw.ver_sync_start & 0xFF);
  118. via_write_reg(VIACR, 0x5F, (raw.ver_sync_end & 0x1F)
  119. | (raw.ver_sync_start >> (8 - 5) & 0xE0));
  120. }
  121. void via_set_primary_address(u32 addr)
  122. {
  123. DEBUG_MSG(KERN_DEBUG "via_set_primary_address(0x%08X)\n", addr);
  124. via_write_reg(VIACR, 0x0D, addr & 0xFF);
  125. via_write_reg(VIACR, 0x0C, (addr >> 8) & 0xFF);
  126. via_write_reg(VIACR, 0x34, (addr >> 16) & 0xFF);
  127. via_write_reg_mask(VIACR, 0x48, (addr >> 24) & 0x1F, 0x1F);
  128. }
  129. void via_set_secondary_address(u32 addr)
  130. {
  131. DEBUG_MSG(KERN_DEBUG "via_set_secondary_address(0x%08X)\n", addr);
  132. /* secondary display supports only quadword aligned memory */
  133. via_write_reg_mask(VIACR, 0x62, (addr >> 2) & 0xFE, 0xFE);
  134. via_write_reg(VIACR, 0x63, (addr >> 10) & 0xFF);
  135. via_write_reg(VIACR, 0x64, (addr >> 18) & 0xFF);
  136. via_write_reg_mask(VIACR, 0xA3, (addr >> 26) & 0x07, 0x07);
  137. }
  138. void via_set_primary_pitch(u32 pitch)
  139. {
  140. DEBUG_MSG(KERN_DEBUG "via_set_primary_pitch(0x%08X)\n", pitch);
  141. /* spec does not say that first adapter skips 3 bits but old
  142. * code did it and seems to be reasonable in analogy to 2nd adapter
  143. */
  144. pitch = pitch >> 3;
  145. via_write_reg(VIACR, 0x13, pitch & 0xFF);
  146. via_write_reg_mask(VIACR, 0x35, (pitch >> (8 - 5)) & 0xE0, 0xE0);
  147. }
  148. void via_set_secondary_pitch(u32 pitch)
  149. {
  150. DEBUG_MSG(KERN_DEBUG "via_set_secondary_pitch(0x%08X)\n", pitch);
  151. pitch = pitch >> 3;
  152. via_write_reg(VIACR, 0x66, pitch & 0xFF);
  153. via_write_reg_mask(VIACR, 0x67, (pitch >> 8) & 0x03, 0x03);
  154. via_write_reg_mask(VIACR, 0x71, (pitch >> (10 - 7)) & 0x80, 0x80);
  155. }
  156. void via_set_primary_color_depth(u8 depth)
  157. {
  158. u8 value;
  159. DEBUG_MSG(KERN_DEBUG "via_set_primary_color_depth(%d)\n", depth);
  160. switch (depth) {
  161. case 8:
  162. value = 0x00;
  163. break;
  164. case 15:
  165. value = 0x04;
  166. break;
  167. case 16:
  168. value = 0x14;
  169. break;
  170. case 24:
  171. value = 0x0C;
  172. break;
  173. case 30:
  174. value = 0x08;
  175. break;
  176. default:
  177. printk(KERN_WARNING "via_set_primary_color_depth: "
  178. "Unsupported depth: %d\n", depth);
  179. return;
  180. }
  181. via_write_reg_mask(VIASR, 0x15, value, 0x1C);
  182. }
  183. void via_set_secondary_color_depth(u8 depth)
  184. {
  185. u8 value;
  186. DEBUG_MSG(KERN_DEBUG "via_set_secondary_color_depth(%d)\n", depth);
  187. switch (depth) {
  188. case 8:
  189. value = 0x00;
  190. break;
  191. case 16:
  192. value = 0x40;
  193. break;
  194. case 24:
  195. value = 0xC0;
  196. break;
  197. case 30:
  198. value = 0x80;
  199. break;
  200. default:
  201. printk(KERN_WARNING "via_set_secondary_color_depth: "
  202. "Unsupported depth: %d\n", depth);
  203. return;
  204. }
  205. via_write_reg_mask(VIACR, 0x67, value, 0xC0);
  206. }