gddr3.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright 2013 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 <bskeggs@redhat.com>
  23. * Roy Spliet <rspliet@eclipso.eu>
  24. */
  25. #include "ram.h"
  26. struct ramxlat {
  27. int id;
  28. u8 enc;
  29. };
  30. static inline int
  31. ramxlat(const struct ramxlat *xlat, int id)
  32. {
  33. while (xlat->id >= 0) {
  34. if (xlat->id == id)
  35. return xlat->enc;
  36. xlat++;
  37. }
  38. return -EINVAL;
  39. }
  40. static const struct ramxlat
  41. ramgddr3_cl_lo[] = {
  42. { 5, 5 }, { 7, 7 }, { 8, 0 }, { 9, 1 }, { 10, 2 }, { 11, 3 }, { 12, 8 },
  43. /* the below are mentioned in some, but not all, gddr3 docs */
  44. { 13, 9 }, { 14, 6 },
  45. /* XXX: Per Samsung docs, are these used? They overlap with Qimonda */
  46. /* { 4, 4 }, { 5, 5 }, { 6, 6 }, { 12, 8 }, { 13, 9 }, { 14, 10 },
  47. * { 15, 11 }, */
  48. { -1 }
  49. };
  50. static const struct ramxlat
  51. ramgddr3_cl_hi[] = {
  52. { 10, 2 }, { 11, 3 }, { 12, 4 }, { 13, 5 }, { 14, 6 }, { 15, 7 },
  53. { 16, 0 }, { 17, 1 },
  54. { -1 }
  55. };
  56. static const struct ramxlat
  57. ramgddr3_wr_lo[] = {
  58. { 5, 2 }, { 7, 4 }, { 8, 5 }, { 9, 6 }, { 10, 7 },
  59. { 11, 0 }, { 13 , 1 },
  60. /* the below are mentioned in some, but not all, gddr3 docs */
  61. { 4, 0 }, { 6, 3 }, { 12, 1 },
  62. { -1 }
  63. };
  64. int
  65. nvkm_gddr3_calc(struct nvkm_ram *ram)
  66. {
  67. int CL, WR, CWL, DLL = 0, ODT = 0, RON, hi;
  68. switch (ram->next->bios.timing_ver) {
  69. case 0x10:
  70. CWL = ram->next->bios.timing_10_CWL;
  71. CL = ram->next->bios.timing_10_CL;
  72. WR = ram->next->bios.timing_10_WR;
  73. DLL = !ram->next->bios.ramcfg_DLLoff;
  74. ODT = ram->next->bios.timing_10_ODT;
  75. RON = ram->next->bios.ramcfg_RON;
  76. break;
  77. case 0x20:
  78. CWL = (ram->next->bios.timing[1] & 0x00000f80) >> 7;
  79. CL = (ram->next->bios.timing[1] & 0x0000001f) >> 0;
  80. WR = (ram->next->bios.timing[2] & 0x007f0000) >> 16;
  81. /* XXX: Get these values from the VBIOS instead */
  82. DLL = !(ram->mr[1] & 0x1);
  83. RON = !(ram->mr[1] & 0x300) >> 8;
  84. break;
  85. default:
  86. return -ENOSYS;
  87. }
  88. if (ram->next->bios.timing_ver == 0x20 ||
  89. ram->next->bios.ramcfg_timing == 0xff) {
  90. ODT = (ram->mr[1] & 0xc) >> 2;
  91. }
  92. hi = ram->mr[2] & 0x1;
  93. CL = ramxlat(hi ? ramgddr3_cl_hi : ramgddr3_cl_lo, CL);
  94. WR = ramxlat(ramgddr3_wr_lo, WR);
  95. if (CL < 0 || CWL < 1 || CWL > 7 || WR < 0)
  96. return -EINVAL;
  97. ram->mr[0] &= ~0xf74;
  98. ram->mr[0] |= (CWL & 0x07) << 9;
  99. ram->mr[0] |= (CL & 0x07) << 4;
  100. ram->mr[0] |= (CL & 0x08) >> 1;
  101. ram->mr[1] &= ~0x3fc;
  102. ram->mr[1] |= (ODT & 0x03) << 2;
  103. ram->mr[1] |= (RON & 0x03) << 8;
  104. ram->mr[1] |= (WR & 0x03) << 4;
  105. ram->mr[1] |= (WR & 0x04) << 5;
  106. ram->mr[1] |= !DLL << 6;
  107. return 0;
  108. }