mem_tx4927.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * linux/arch/mips/tx4927/common/tx4927_prom.c
  3. *
  4. * common tx4927 memory interface
  5. *
  6. * Author: MontaVista Software, Inc.
  7. * source@mvista.com
  8. *
  9. * Copyright 2001-2002 MontaVista Software Inc.
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. *
  16. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  19. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  21. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  22. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  24. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  25. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. * You should have received a copy of the GNU General Public License along
  28. * with this program; if not, write to the Free Software Foundation, Inc.,
  29. * 675 Mass Ave, Cambridge, MA 02139, USA.
  30. */
  31. #include <linux/init.h>
  32. #include <linux/types.h>
  33. #include <linux/io.h>
  34. static unsigned int __init tx4927_process_sdccr(unsigned long addr)
  35. {
  36. u64 val;
  37. unsigned int sdccr_ce;
  38. unsigned int sdccr_bs;
  39. unsigned int sdccr_rs;
  40. unsigned int sdccr_cs;
  41. unsigned int sdccr_mw;
  42. unsigned int bs = 0;
  43. unsigned int rs = 0;
  44. unsigned int cs = 0;
  45. unsigned int mw = 0;
  46. unsigned int msize = 0;
  47. val = __raw_readq((void __iomem *)addr);
  48. /* MVMCP -- need #defs for these bits masks */
  49. sdccr_ce = ((val & (1 << 10)) >> 10);
  50. sdccr_bs = ((val & (1 << 8)) >> 8);
  51. sdccr_rs = ((val & (3 << 5)) >> 5);
  52. sdccr_cs = ((val & (3 << 2)) >> 2);
  53. sdccr_mw = ((val & (1 << 0)) >> 0);
  54. if (sdccr_ce) {
  55. switch (sdccr_bs) {
  56. case 0:{
  57. bs = 2;
  58. break;
  59. }
  60. case 1:{
  61. bs = 4;
  62. break;
  63. }
  64. }
  65. switch (sdccr_rs) {
  66. case 0:{
  67. rs = 2048;
  68. break;
  69. }
  70. case 1:{
  71. rs = 4096;
  72. break;
  73. }
  74. case 2:{
  75. rs = 8192;
  76. break;
  77. }
  78. case 3:{
  79. rs = 0;
  80. break;
  81. }
  82. }
  83. switch (sdccr_cs) {
  84. case 0:{
  85. cs = 256;
  86. break;
  87. }
  88. case 1:{
  89. cs = 512;
  90. break;
  91. }
  92. case 2:{
  93. cs = 1024;
  94. break;
  95. }
  96. case 3:{
  97. cs = 2048;
  98. break;
  99. }
  100. }
  101. switch (sdccr_mw) {
  102. case 0:{
  103. mw = 8;
  104. break;
  105. } /* 8 bytes = 64 bits */
  106. case 1:{
  107. mw = 4;
  108. break;
  109. } /* 4 bytes = 32 bits */
  110. }
  111. }
  112. /* bytes per chip MB per chip num chips */
  113. msize = (((rs * cs * mw) / (1024 * 1024)) * bs);
  114. return (msize);
  115. }
  116. unsigned int __init tx4927_get_mem_size(void)
  117. {
  118. unsigned int c0;
  119. unsigned int c1;
  120. unsigned int c2;
  121. unsigned int c3;
  122. unsigned int total;
  123. /* MVMCP -- need #defs for these registers */
  124. c0 = tx4927_process_sdccr(0xff1f8000);
  125. c1 = tx4927_process_sdccr(0xff1f8008);
  126. c2 = tx4927_process_sdccr(0xff1f8010);
  127. c3 = tx4927_process_sdccr(0xff1f8018);
  128. total = c0 + c1 + c2 + c3;
  129. return (total);
  130. }