mxm.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright 2012 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Ben Skeggs
  23. */
  24. #include <subdev/bios.h>
  25. #include <subdev/bios/bit.h>
  26. #include <subdev/bios/mxm.h>
  27. u16
  28. mxm_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr)
  29. {
  30. struct nvkm_subdev *subdev = &bios->subdev;
  31. struct bit_entry x;
  32. if (bit_entry(bios, 'x', &x)) {
  33. nvkm_debug(subdev, "BIT 'x' table not present\n");
  34. return 0x0000;
  35. }
  36. *ver = x.version;
  37. *hdr = x.length;
  38. if (*ver != 1 || *hdr < 3) {
  39. nvkm_warn(subdev, "BIT 'x' table %d/%d unknown\n", *ver, *hdr);
  40. return 0x0000;
  41. }
  42. return x.offset;
  43. }
  44. /* These map MXM v2.x digital connection values to the appropriate SOR/link,
  45. * hopefully they're correct for all boards within the same chipset...
  46. *
  47. * MXM v3.x VBIOS are nicer and provide pointers to these tables.
  48. */
  49. static u8 g84_sor_map[16] = {
  50. 0x00, 0x12, 0x22, 0x11, 0x32, 0x31, 0x11, 0x31,
  51. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  52. };
  53. static u8 g92_sor_map[16] = {
  54. 0x00, 0x12, 0x22, 0x11, 0x32, 0x31, 0x11, 0x31,
  55. 0x11, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  56. };
  57. static u8 g94_sor_map[16] = {
  58. 0x00, 0x14, 0x24, 0x11, 0x34, 0x31, 0x11, 0x31,
  59. 0x11, 0x31, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00
  60. };
  61. static u8 g98_sor_map[16] = {
  62. 0x00, 0x14, 0x12, 0x11, 0x00, 0x31, 0x11, 0x31,
  63. 0x11, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  64. };
  65. u8
  66. mxm_sor_map(struct nvkm_bios *bios, u8 conn)
  67. {
  68. struct nvkm_subdev *subdev = &bios->subdev;
  69. u8 ver, hdr;
  70. u16 mxm = mxm_table(bios, &ver, &hdr);
  71. if (mxm && hdr >= 6) {
  72. u16 map = nvbios_rd16(bios, mxm + 4);
  73. if (map) {
  74. ver = nvbios_rd08(bios, map);
  75. if (ver == 0x10 || ver == 0x11) {
  76. if (conn < nvbios_rd08(bios, map + 3)) {
  77. map += nvbios_rd08(bios, map + 1);
  78. map += conn;
  79. return nvbios_rd08(bios, map);
  80. }
  81. return 0x00;
  82. }
  83. nvkm_warn(subdev, "unknown sor map v%02x\n", ver);
  84. }
  85. }
  86. if (bios->version.chip == 0x84 || bios->version.chip == 0x86)
  87. return g84_sor_map[conn];
  88. if (bios->version.chip == 0x92)
  89. return g92_sor_map[conn];
  90. if (bios->version.chip == 0x94 || bios->version.chip == 0x96)
  91. return g94_sor_map[conn];
  92. if (bios->version.chip == 0x98)
  93. return g98_sor_map[conn];
  94. nvkm_warn(subdev, "missing sor map\n");
  95. return 0x00;
  96. }
  97. u8
  98. mxm_ddc_map(struct nvkm_bios *bios, u8 port)
  99. {
  100. struct nvkm_subdev *subdev = &bios->subdev;
  101. u8 ver, hdr;
  102. u16 mxm = mxm_table(bios, &ver, &hdr);
  103. if (mxm && hdr >= 8) {
  104. u16 map = nvbios_rd16(bios, mxm + 6);
  105. if (map) {
  106. ver = nvbios_rd08(bios, map);
  107. if (ver == 0x10) {
  108. if (port < nvbios_rd08(bios, map + 3)) {
  109. map += nvbios_rd08(bios, map + 1);
  110. map += port;
  111. return nvbios_rd08(bios, map);
  112. }
  113. return 0x00;
  114. }
  115. nvkm_warn(subdev, "unknown ddc map v%02x\n", ver);
  116. }
  117. }
  118. /* v2.x: directly write port as dcb i2cidx */
  119. return (port << 4) | port;
  120. }