xref: /openbmc/linux/arch/mips/txx9/generic/mem_tx4927.c (revision e5451c8f8330e03ad3cfa16048b4daf961af434f)
122b1d707SAtsushi Nemoto /*
222b1d707SAtsushi Nemoto  * common tx4927 memory interface
322b1d707SAtsushi Nemoto  *
422b1d707SAtsushi Nemoto  * Author: MontaVista Software, Inc.
522b1d707SAtsushi Nemoto  *	   source@mvista.com
622b1d707SAtsushi Nemoto  *
722b1d707SAtsushi Nemoto  * Copyright 2001-2002 MontaVista Software Inc.
822b1d707SAtsushi Nemoto  *
922b1d707SAtsushi Nemoto  *  This program is free software; you can redistribute it and/or modify it
1022b1d707SAtsushi Nemoto  *  under the terms of the GNU General Public License as published by the
1122b1d707SAtsushi Nemoto  *  Free Software Foundation; either version 2 of the License, or (at your
1222b1d707SAtsushi Nemoto  *  option) any later version.
1322b1d707SAtsushi Nemoto  *
1422b1d707SAtsushi Nemoto  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
1522b1d707SAtsushi Nemoto  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1622b1d707SAtsushi Nemoto  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1722b1d707SAtsushi Nemoto  *  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1822b1d707SAtsushi Nemoto  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
1922b1d707SAtsushi Nemoto  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
2022b1d707SAtsushi Nemoto  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2122b1d707SAtsushi Nemoto  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
2222b1d707SAtsushi Nemoto  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
2322b1d707SAtsushi Nemoto  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2422b1d707SAtsushi Nemoto  *
2522b1d707SAtsushi Nemoto  *  You should have received a copy of the GNU General Public License along
2622b1d707SAtsushi Nemoto  *  with this program; if not, write to the Free Software Foundation, Inc.,
2722b1d707SAtsushi Nemoto  *  675 Mass Ave, Cambridge, MA 02139, USA.
2822b1d707SAtsushi Nemoto  */
2922b1d707SAtsushi Nemoto 
3022b1d707SAtsushi Nemoto #include <linux/init.h>
3122b1d707SAtsushi Nemoto #include <linux/types.h>
3222b1d707SAtsushi Nemoto #include <linux/io.h>
33*255033a9SAtsushi Nemoto #include <asm/txx9/tx4927.h>
3422b1d707SAtsushi Nemoto 
tx4927_process_sdccr(u64 __iomem * addr)35*255033a9SAtsushi Nemoto static unsigned int __init tx4927_process_sdccr(u64 __iomem *addr)
3622b1d707SAtsushi Nemoto {
3722b1d707SAtsushi Nemoto 	u64 val;
3822b1d707SAtsushi Nemoto 	unsigned int sdccr_ce;
3922b1d707SAtsushi Nemoto 	unsigned int sdccr_bs;
4022b1d707SAtsushi Nemoto 	unsigned int sdccr_rs;
4122b1d707SAtsushi Nemoto 	unsigned int sdccr_cs;
4222b1d707SAtsushi Nemoto 	unsigned int sdccr_mw;
4322b1d707SAtsushi Nemoto 	unsigned int bs = 0;
4422b1d707SAtsushi Nemoto 	unsigned int rs = 0;
4522b1d707SAtsushi Nemoto 	unsigned int cs = 0;
4622b1d707SAtsushi Nemoto 	unsigned int mw = 0;
4722b1d707SAtsushi Nemoto 
48*255033a9SAtsushi Nemoto 	val = __raw_readq(addr);
4922b1d707SAtsushi Nemoto 
5022b1d707SAtsushi Nemoto 	/* MVMCP -- need #defs for these bits masks */
5122b1d707SAtsushi Nemoto 	sdccr_ce = ((val & (1 << 10)) >> 10);
5222b1d707SAtsushi Nemoto 	sdccr_bs = ((val & (1 << 8)) >> 8);
5322b1d707SAtsushi Nemoto 	sdccr_rs = ((val & (3 << 5)) >> 5);
54*255033a9SAtsushi Nemoto 	sdccr_cs = ((val & (7 << 2)) >> 2);
5522b1d707SAtsushi Nemoto 	sdccr_mw = ((val & (1 << 0)) >> 0);
5622b1d707SAtsushi Nemoto 
5722b1d707SAtsushi Nemoto 	if (sdccr_ce) {
58*255033a9SAtsushi Nemoto 		bs = 2 << sdccr_bs;
59*255033a9SAtsushi Nemoto 		rs = 2048 << sdccr_rs;
60*255033a9SAtsushi Nemoto 		cs = 256 << sdccr_cs;
61*255033a9SAtsushi Nemoto 		mw = 8 >> sdccr_mw;
6222b1d707SAtsushi Nemoto 	}
6322b1d707SAtsushi Nemoto 
64*255033a9SAtsushi Nemoto 	return rs * cs * mw * bs;
6522b1d707SAtsushi Nemoto }
6622b1d707SAtsushi Nemoto 
tx4927_get_mem_size(void)6722b1d707SAtsushi Nemoto unsigned int __init tx4927_get_mem_size(void)
6822b1d707SAtsushi Nemoto {
69*255033a9SAtsushi Nemoto 	unsigned int total = 0;
70*255033a9SAtsushi Nemoto 	int i;
7122b1d707SAtsushi Nemoto 
72*255033a9SAtsushi Nemoto 	for (i = 0; i < ARRAY_SIZE(tx4927_sdramcptr->cr); i++)
73*255033a9SAtsushi Nemoto 		total += tx4927_process_sdccr(&tx4927_sdramcptr->cr[i]);
74*255033a9SAtsushi Nemoto 	return total;
7522b1d707SAtsushi Nemoto }
76