xref: /openbmc/linux/arch/sh/kernel/cpu/sh4/probe.c (revision 9b3a53ab76771e3669e50086c131e1574fe25847)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * arch/sh/kernel/cpu/sh4/probe.c
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * CPU Subtype Probing for SH-4.
51da177e4SLinus Torvalds  *
6e5723e0eSPaul Mundt  * Copyright (C) 2001 - 2006  Paul Mundt
71da177e4SLinus Torvalds  * Copyright (C) 2003  Richard Curnow
81da177e4SLinus Torvalds  *
91da177e4SLinus Torvalds  * This file is subject to the terms and conditions of the GNU General Public
101da177e4SLinus Torvalds  * License.  See the file "COPYING" in the main directory of this archive
111da177e4SLinus Torvalds  * for more details.
121da177e4SLinus Torvalds  */
131da177e4SLinus Torvalds 
141da177e4SLinus Torvalds #include <linux/init.h>
151da177e4SLinus Torvalds #include <asm/processor.h>
161da177e4SLinus Torvalds #include <asm/cache.h>
171da177e4SLinus Torvalds #include <asm/io.h>
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds int __init detect_cpu_and_cache_system(void)
201da177e4SLinus Torvalds {
211da177e4SLinus Torvalds 	unsigned long pvr, prr, cvr;
221da177e4SLinus Torvalds 	unsigned long size;
231da177e4SLinus Torvalds 
241da177e4SLinus Torvalds 	static unsigned long sizes[16] = {
251da177e4SLinus Torvalds 		[1] = (1 << 12),
261da177e4SLinus Torvalds 		[2] = (1 << 13),
271da177e4SLinus Torvalds 		[4] = (1 << 14),
281da177e4SLinus Torvalds 		[8] = (1 << 15),
291da177e4SLinus Torvalds 		[9] = (1 << 16)
301da177e4SLinus Torvalds 	};
311da177e4SLinus Torvalds 
3272c35543SPaul Mundt 	pvr = (ctrl_inl(CCN_PVR) >> 8) & 0xffffff;
331da177e4SLinus Torvalds 	prr = (ctrl_inl(CCN_PRR) >> 4) & 0xff;
341da177e4SLinus Torvalds 	cvr = (ctrl_inl(CCN_CVR));
351da177e4SLinus Torvalds 
361da177e4SLinus Torvalds 	/*
371da177e4SLinus Torvalds 	 * Setup some sane SH-4 defaults for the icache
381da177e4SLinus Torvalds 	 */
391da177e4SLinus Torvalds 	cpu_data->icache.way_incr	= (1 << 13);
401da177e4SLinus Torvalds 	cpu_data->icache.entry_shift	= 5;
411da177e4SLinus Torvalds 	cpu_data->icache.sets		= 256;
421da177e4SLinus Torvalds 	cpu_data->icache.ways		= 1;
431da177e4SLinus Torvalds 	cpu_data->icache.linesz		= L1_CACHE_BYTES;
441da177e4SLinus Torvalds 
451da177e4SLinus Torvalds 	/*
461da177e4SLinus Torvalds 	 * And again for the dcache ..
471da177e4SLinus Torvalds 	 */
481da177e4SLinus Torvalds 	cpu_data->dcache.way_incr	= (1 << 14);
491da177e4SLinus Torvalds 	cpu_data->dcache.entry_shift	= 5;
501da177e4SLinus Torvalds 	cpu_data->dcache.sets		= 512;
511da177e4SLinus Torvalds 	cpu_data->dcache.ways		= 1;
521da177e4SLinus Torvalds 	cpu_data->dcache.linesz		= L1_CACHE_BYTES;
531da177e4SLinus Torvalds 
541da177e4SLinus Torvalds 	/*
5572c35543SPaul Mundt 	 * Setup some generic flags we can probe
5672c35543SPaul Mundt 	 * (L2 and DSP detection only work on SH-4A)
5772c35543SPaul Mundt 	 */
5872c35543SPaul Mundt 	if (((pvr >> 16) & 0xff) == 0x10) {
5972c35543SPaul Mundt 		if ((cvr & 0x02000000) == 0)
6072c35543SPaul Mundt 			cpu_data->flags |= CPU_HAS_L2_CACHE;
6172c35543SPaul Mundt 		if ((cvr & 0x10000000) == 0)
6272c35543SPaul Mundt 			cpu_data->flags |= CPU_HAS_DSP;
6372c35543SPaul Mundt 
6472c35543SPaul Mundt 		cpu_data->flags |= CPU_HAS_LLSC;
6572c35543SPaul Mundt 	}
6672c35543SPaul Mundt 
6772c35543SPaul Mundt 	/* FPU detection works for everyone */
6872c35543SPaul Mundt 	if ((cvr & 0x20000000) == 1)
6972c35543SPaul Mundt 		cpu_data->flags |= CPU_HAS_FPU;
7072c35543SPaul Mundt 
7172c35543SPaul Mundt 	/* Mask off the upper chip ID */
7272c35543SPaul Mundt 	pvr &= 0xffff;
7372c35543SPaul Mundt 
7472c35543SPaul Mundt 	/*
751da177e4SLinus Torvalds 	 * Probe the underlying processor version/revision and
761da177e4SLinus Torvalds 	 * adjust cpu_data setup accordingly.
771da177e4SLinus Torvalds 	 */
781da177e4SLinus Torvalds 	switch (pvr) {
791da177e4SLinus Torvalds 	case 0x205:
801da177e4SLinus Torvalds 		cpu_data->type = CPU_SH7750;
81749cf486SPaul Mundt 		cpu_data->flags |= CPU_HAS_P2_FLUSH_BUG | CPU_HAS_FPU |
82*9b3a53abSStuart Menefy 				   CPU_HAS_PERF_COUNTER;
831da177e4SLinus Torvalds 		break;
841da177e4SLinus Torvalds 	case 0x206:
851da177e4SLinus Torvalds 		cpu_data->type = CPU_SH7750S;
86749cf486SPaul Mundt 		cpu_data->flags |= CPU_HAS_P2_FLUSH_BUG | CPU_HAS_FPU |
87*9b3a53abSStuart Menefy 				   CPU_HAS_PERF_COUNTER;
881da177e4SLinus Torvalds 		break;
891da177e4SLinus Torvalds 	case 0x1100:
901da177e4SLinus Torvalds 		cpu_data->type = CPU_SH7751;
91*9b3a53abSStuart Menefy 		cpu_data->flags |= CPU_HAS_FPU;
921da177e4SLinus Torvalds 		break;
931da177e4SLinus Torvalds 	case 0x2000:
941da177e4SLinus Torvalds 		cpu_data->type = CPU_SH73180;
951da177e4SLinus Torvalds 		cpu_data->icache.ways = 4;
961da177e4SLinus Torvalds 		cpu_data->dcache.ways = 4;
97315bb968SPaul Mundt 		cpu_data->flags |= CPU_HAS_LLSC;
981da177e4SLinus Torvalds 		break;
995b19c908SPaul Mundt 	case 0x2001:
1005b19c908SPaul Mundt 	case 0x2004:
1015b19c908SPaul Mundt 		cpu_data->type = CPU_SH7770;
1025b19c908SPaul Mundt 		cpu_data->icache.ways = 4;
1035b19c908SPaul Mundt 		cpu_data->dcache.ways = 4;
104749cf486SPaul Mundt 
105315bb968SPaul Mundt 		cpu_data->flags |= CPU_HAS_FPU | CPU_HAS_LLSC;
1065b19c908SPaul Mundt 		break;
1075b19c908SPaul Mundt 	case 0x2006:
1085b19c908SPaul Mundt 	case 0x200A:
1095b19c908SPaul Mundt 		if (prr == 0x61)
1105b19c908SPaul Mundt 			cpu_data->type = CPU_SH7781;
1115b19c908SPaul Mundt 		else
1125b19c908SPaul Mundt 			cpu_data->type = CPU_SH7780;
113749cf486SPaul Mundt 
1145b19c908SPaul Mundt 		cpu_data->icache.ways = 4;
1155b19c908SPaul Mundt 		cpu_data->dcache.ways = 4;
116749cf486SPaul Mundt 
117315bb968SPaul Mundt 		cpu_data->flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
118315bb968SPaul Mundt 				   CPU_HAS_LLSC;
1195b19c908SPaul Mundt 		break;
120e5723e0eSPaul Mundt 	case 0x3000:
121e5723e0eSPaul Mundt 	case 0x3003:
122e5723e0eSPaul Mundt 		cpu_data->type = CPU_SH7343;
123e5723e0eSPaul Mundt 		cpu_data->icache.ways = 4;
124e5723e0eSPaul Mundt 		cpu_data->dcache.ways = 4;
125315bb968SPaul Mundt 		cpu_data->flags |= CPU_HAS_LLSC;
126e5723e0eSPaul Mundt 		break;
1271da177e4SLinus Torvalds 	case 0x8000:
1281da177e4SLinus Torvalds 		cpu_data->type = CPU_ST40RA;
129*9b3a53abSStuart Menefy 		cpu_data->flags |= CPU_HAS_FPU;
1301da177e4SLinus Torvalds 		break;
1311da177e4SLinus Torvalds 	case 0x8100:
1321da177e4SLinus Torvalds 		cpu_data->type = CPU_ST40GX1;
133*9b3a53abSStuart Menefy 		cpu_data->flags |= CPU_HAS_FPU;
1341da177e4SLinus Torvalds 		break;
1351da177e4SLinus Torvalds 	case 0x700:
1361da177e4SLinus Torvalds 		cpu_data->type = CPU_SH4_501;
1371da177e4SLinus Torvalds 		cpu_data->icache.ways = 2;
1381da177e4SLinus Torvalds 		cpu_data->dcache.ways = 2;
1391da177e4SLinus Torvalds 		break;
1401da177e4SLinus Torvalds 	case 0x600:
1411da177e4SLinus Torvalds 		cpu_data->type = CPU_SH4_202;
1421da177e4SLinus Torvalds 		cpu_data->icache.ways = 2;
1431da177e4SLinus Torvalds 		cpu_data->dcache.ways = 2;
144*9b3a53abSStuart Menefy 		cpu_data->flags |= CPU_HAS_FPU;
1451da177e4SLinus Torvalds 		break;
1461da177e4SLinus Torvalds 	case 0x500 ... 0x501:
1471da177e4SLinus Torvalds 		switch (prr) {
14873388cc7SPaul Mundt 		case 0x10:
14973388cc7SPaul Mundt 			cpu_data->type = CPU_SH7750R;
15073388cc7SPaul Mundt 			break;
15173388cc7SPaul Mundt 		case 0x11:
15273388cc7SPaul Mundt 			cpu_data->type = CPU_SH7751R;
15373388cc7SPaul Mundt 			break;
15473388cc7SPaul Mundt 		case 0x50 ... 0x5f:
15573388cc7SPaul Mundt 			cpu_data->type = CPU_SH7760;
15673388cc7SPaul Mundt 			break;
1571da177e4SLinus Torvalds 		}
1581da177e4SLinus Torvalds 
1591da177e4SLinus Torvalds 		cpu_data->icache.ways = 2;
1601da177e4SLinus Torvalds 		cpu_data->dcache.ways = 2;
1611da177e4SLinus Torvalds 
162*9b3a53abSStuart Menefy 		cpu_data->flags |= CPU_HAS_FPU;
163749cf486SPaul Mundt 
1641da177e4SLinus Torvalds 		break;
1651da177e4SLinus Torvalds 	default:
1661da177e4SLinus Torvalds 		cpu_data->type = CPU_SH_NONE;
1671da177e4SLinus Torvalds 		break;
1681da177e4SLinus Torvalds 	}
1691da177e4SLinus Torvalds 
170b638d0b9SRichard Curnow #ifdef CONFIG_SH_DIRECT_MAPPED
171b638d0b9SRichard Curnow 	cpu_data->icache.ways = 1;
172b638d0b9SRichard Curnow 	cpu_data->dcache.ways = 1;
173b638d0b9SRichard Curnow #endif
174b638d0b9SRichard Curnow 
175*9b3a53abSStuart Menefy #ifdef CONFIG_CPU_HAS_PTEA
176*9b3a53abSStuart Menefy 	cpu_data->flags |= CPU_HAS_PTEA;
177*9b3a53abSStuart Menefy #endif
178*9b3a53abSStuart Menefy 
1791da177e4SLinus Torvalds 	/*
1801da177e4SLinus Torvalds 	 * On anything that's not a direct-mapped cache, look to the CVR
1811da177e4SLinus Torvalds 	 * for I/D-cache specifics.
1821da177e4SLinus Torvalds 	 */
1831da177e4SLinus Torvalds 	if (cpu_data->icache.ways > 1) {
1841da177e4SLinus Torvalds 		size = sizes[(cvr >> 20) & 0xf];
1851da177e4SLinus Torvalds 		cpu_data->icache.way_incr	= (size >> 1);
1861da177e4SLinus Torvalds 		cpu_data->icache.sets		= (size >> 6);
187d15f4560SPaul Mundt 
1881da177e4SLinus Torvalds 	}
1891da177e4SLinus Torvalds 
190d15f4560SPaul Mundt 	/* Setup the rest of the I-cache info */
191d15f4560SPaul Mundt 	cpu_data->icache.entry_mask = cpu_data->icache.way_incr -
192d15f4560SPaul Mundt 				      cpu_data->icache.linesz;
193d15f4560SPaul Mundt 
194b638d0b9SRichard Curnow 	cpu_data->icache.way_size = cpu_data->icache.sets *
195b638d0b9SRichard Curnow 				    cpu_data->icache.linesz;
196b638d0b9SRichard Curnow 
197d15f4560SPaul Mundt 	/* And the rest of the D-cache */
1981da177e4SLinus Torvalds 	if (cpu_data->dcache.ways > 1) {
1991da177e4SLinus Torvalds 		size = sizes[(cvr >> 16) & 0xf];
2001da177e4SLinus Torvalds 		cpu_data->dcache.way_incr	= (size >> 1);
2011da177e4SLinus Torvalds 		cpu_data->dcache.sets		= (size >> 6);
2021da177e4SLinus Torvalds 	}
2031da177e4SLinus Torvalds 
204d15f4560SPaul Mundt 	cpu_data->dcache.entry_mask = cpu_data->dcache.way_incr -
205d15f4560SPaul Mundt 				      cpu_data->dcache.linesz;
206d15f4560SPaul Mundt 
207b638d0b9SRichard Curnow 	cpu_data->dcache.way_size = cpu_data->dcache.sets *
208b638d0b9SRichard Curnow 				    cpu_data->dcache.linesz;
209b638d0b9SRichard Curnow 
21072c35543SPaul Mundt 	/*
21172c35543SPaul Mundt 	 * Setup the L2 cache desc
21272c35543SPaul Mundt 	 *
21372c35543SPaul Mundt 	 * SH-4A's have an optional PIPT L2.
21472c35543SPaul Mundt 	 */
21572c35543SPaul Mundt 	if (cpu_data->flags & CPU_HAS_L2_CACHE) {
21672c35543SPaul Mundt 		/*
21772c35543SPaul Mundt 		 * Size calculation is much more sensible
21872c35543SPaul Mundt 		 * than it is for the L1.
21972c35543SPaul Mundt 		 *
22072c35543SPaul Mundt 		 * Sizes are 128KB, 258KB, 512KB, and 1MB.
22172c35543SPaul Mundt 		 */
22272c35543SPaul Mundt 		size = (cvr & 0xf) << 17;
22372c35543SPaul Mundt 
22472c35543SPaul Mundt 		BUG_ON(!size);
22572c35543SPaul Mundt 
22672c35543SPaul Mundt 		cpu_data->scache.way_incr	= (1 << 16);
22772c35543SPaul Mundt 		cpu_data->scache.entry_shift	= 5;
22872c35543SPaul Mundt 		cpu_data->scache.ways		= 4;
22972c35543SPaul Mundt 		cpu_data->scache.linesz		= L1_CACHE_BYTES;
230d15f4560SPaul Mundt 		cpu_data->scache.entry_mask	=
231d15f4560SPaul Mundt 			(cpu_data->scache.way_incr - cpu_data->scache.linesz);
23272c35543SPaul Mundt 		cpu_data->scache.sets		= size /
23372c35543SPaul Mundt 			(cpu_data->scache.linesz * cpu_data->scache.ways);
234d15f4560SPaul Mundt 		cpu_data->scache.way_size	=
235d15f4560SPaul Mundt 			(cpu_data->scache.sets * cpu_data->scache.linesz);
23672c35543SPaul Mundt 	}
23772c35543SPaul Mundt 
2381da177e4SLinus Torvalds 	return 0;
2391da177e4SLinus Torvalds }
240