via_modesetting.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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_address(u32 addr)
  31. {
  32. DEBUG_MSG(KERN_DEBUG "via_set_primary_address(0x%08X)\n", addr);
  33. via_write_reg(VIACR, 0x0D, addr & 0xFF);
  34. via_write_reg(VIACR, 0x0C, (addr >> 8) & 0xFF);
  35. via_write_reg(VIACR, 0x34, (addr >> 16) & 0xFF);
  36. via_write_reg_mask(VIACR, 0x48, (addr >> 24) & 0x1F, 0x1F);
  37. }
  38. void via_set_secondary_address(u32 addr)
  39. {
  40. DEBUG_MSG(KERN_DEBUG "via_set_secondary_address(0x%08X)\n", addr);
  41. /* secondary display supports only quadword aligned memory */
  42. via_write_reg_mask(VIACR, 0x62, (addr >> 2) & 0xFE, 0xFE);
  43. via_write_reg(VIACR, 0x63, (addr >> 10) & 0xFF);
  44. via_write_reg(VIACR, 0x64, (addr >> 18) & 0xFF);
  45. via_write_reg_mask(VIACR, 0xA3, (addr >> 26) & 0x07, 0x07);
  46. }
  47. void via_set_primary_pitch(u32 pitch)
  48. {
  49. DEBUG_MSG(KERN_DEBUG "via_set_primary_pitch(0x%08X)\n", pitch);
  50. /* spec does not say that first adapter skips 3 bits but old
  51. * code did it and seems to be reasonable in analogy to 2nd adapter
  52. */
  53. pitch = pitch >> 3;
  54. via_write_reg(VIACR, 0x13, pitch & 0xFF);
  55. via_write_reg_mask(VIACR, 0x35, (pitch >> (8 - 5)) & 0xE0, 0xE0);
  56. }
  57. void via_set_secondary_pitch(u32 pitch)
  58. {
  59. DEBUG_MSG(KERN_DEBUG "via_set_secondary_pitch(0x%08X)\n", pitch);
  60. pitch = pitch >> 3;
  61. via_write_reg(VIACR, 0x66, pitch & 0xFF);
  62. via_write_reg_mask(VIACR, 0x67, (pitch >> 8) & 0x03, 0x03);
  63. via_write_reg_mask(VIACR, 0x71, (pitch >> (10 - 7)) & 0x80, 0x80);
  64. }
  65. void via_set_primary_color_depth(u8 depth)
  66. {
  67. u8 value;
  68. DEBUG_MSG(KERN_DEBUG "via_set_primary_color_depth(%d)\n", depth);
  69. switch (depth) {
  70. case 8:
  71. value = 0x00;
  72. break;
  73. case 15:
  74. value = 0x04;
  75. break;
  76. case 16:
  77. value = 0x14;
  78. break;
  79. case 24:
  80. value = 0x0C;
  81. break;
  82. case 30:
  83. value = 0x08;
  84. break;
  85. default:
  86. printk(KERN_WARNING "via_set_primary_color_depth: "
  87. "Unsupported depth: %d\n", depth);
  88. return;
  89. }
  90. via_write_reg_mask(VIASR, 0x15, value, 0x1C);
  91. }
  92. void via_set_secondary_color_depth(u8 depth)
  93. {
  94. u8 value;
  95. DEBUG_MSG(KERN_DEBUG "via_set_secondary_color_depth(%d)\n", depth);
  96. switch (depth) {
  97. case 8:
  98. value = 0x00;
  99. break;
  100. case 16:
  101. value = 0x40;
  102. break;
  103. case 24:
  104. value = 0xC0;
  105. break;
  106. case 30:
  107. value = 0x80;
  108. break;
  109. default:
  110. printk(KERN_WARNING "via_set_secondary_color_depth: "
  111. "Unsupported depth: %d\n", depth);
  112. return;
  113. }
  114. via_write_reg_mask(VIACR, 0x67, value, 0xC0);
  115. }