tx4927_prom.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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/mm.h>
  33. #include <linux/sched.h>
  34. #include <linux/bootmem.h>
  35. #include <asm/addrspace.h>
  36. #include <asm/bootinfo.h>
  37. #include <asm/tx4927/tx4927.h>
  38. static unsigned int __init tx4927_process_sdccr(u64 * addr)
  39. {
  40. u64 val;
  41. unsigned int sdccr_ce;
  42. unsigned int sdccr_bs;
  43. unsigned int sdccr_rs;
  44. unsigned int sdccr_cs;
  45. unsigned int sdccr_mw;
  46. unsigned int bs = 0;
  47. unsigned int rs = 0;
  48. unsigned int cs = 0;
  49. unsigned int mw = 0;
  50. unsigned int msize = 0;
  51. val = (*((vu64 *) (addr)));
  52. /* MVMCP -- need #defs for these bits masks */
  53. sdccr_ce = ((val & (1 << 10)) >> 10);
  54. sdccr_bs = ((val & (1 << 8)) >> 8);
  55. sdccr_rs = ((val & (3 << 5)) >> 5);
  56. sdccr_cs = ((val & (3 << 2)) >> 2);
  57. sdccr_mw = ((val & (1 << 0)) >> 0);
  58. if (sdccr_ce) {
  59. switch (sdccr_bs) {
  60. case 0:{
  61. bs = 2;
  62. break;
  63. }
  64. case 1:{
  65. bs = 4;
  66. break;
  67. }
  68. }
  69. switch (sdccr_rs) {
  70. case 0:{
  71. rs = 2048;
  72. break;
  73. }
  74. case 1:{
  75. rs = 4096;
  76. break;
  77. }
  78. case 2:{
  79. rs = 8192;
  80. break;
  81. }
  82. case 3:{
  83. rs = 0;
  84. break;
  85. }
  86. }
  87. switch (sdccr_cs) {
  88. case 0:{
  89. cs = 256;
  90. break;
  91. }
  92. case 1:{
  93. cs = 512;
  94. break;
  95. }
  96. case 2:{
  97. cs = 1024;
  98. break;
  99. }
  100. case 3:{
  101. cs = 2048;
  102. break;
  103. }
  104. }
  105. switch (sdccr_mw) {
  106. case 0:{
  107. mw = 8;
  108. break;
  109. } /* 8 bytes = 64 bits */
  110. case 1:{
  111. mw = 4;
  112. break;
  113. } /* 4 bytes = 32 bits */
  114. }
  115. }
  116. /* bytes per chip MB per chip num chips */
  117. msize = (((rs * cs * mw) / (1024 * 1024)) * bs);
  118. return (msize);
  119. }
  120. unsigned int __init tx4927_get_mem_size(void)
  121. {
  122. unsigned int c0;
  123. unsigned int c1;
  124. unsigned int c2;
  125. unsigned int c3;
  126. unsigned int total;
  127. /* MVMCP -- need #defs for these registers */
  128. c0 = tx4927_process_sdccr((u64 *) 0xff1f8000);
  129. c1 = tx4927_process_sdccr((u64 *) 0xff1f8008);
  130. c2 = tx4927_process_sdccr((u64 *) 0xff1f8010);
  131. c3 = tx4927_process_sdccr((u64 *) 0xff1f8018);
  132. total = c0 + c1 + c2 + c3;
  133. return (total);
  134. }