xref: /openbmc/linux/arch/sh/kernel/cpu/sh4/probe.c (revision c01f0f1a4a96eb3acc5850e18cc43f24366966d0)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * arch/sh/kernel/cpu/sh4/probe.c
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * CPU Subtype Probing for SH-4.
51da177e4SLinus Torvalds  *
626fad19dSPaul Mundt  * Copyright (C) 2001 - 2007  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 #include <linux/init.h>
1411c19656SPaul Mundt #include <linux/io.h>
151da177e4SLinus Torvalds #include <asm/processor.h>
161da177e4SLinus Torvalds #include <asm/cache.h>
171da177e4SLinus Torvalds 
181da177e4SLinus Torvalds int __init detect_cpu_and_cache_system(void)
191da177e4SLinus Torvalds {
201da177e4SLinus Torvalds 	unsigned long pvr, prr, cvr;
211da177e4SLinus Torvalds 	unsigned long size;
221da177e4SLinus Torvalds 
231da177e4SLinus Torvalds 	static unsigned long sizes[16] = {
241da177e4SLinus Torvalds 		[1] = (1 << 12),
251da177e4SLinus Torvalds 		[2] = (1 << 13),
261da177e4SLinus Torvalds 		[4] = (1 << 14),
271da177e4SLinus Torvalds 		[8] = (1 << 15),
281da177e4SLinus Torvalds 		[9] = (1 << 16)
291da177e4SLinus Torvalds 	};
301da177e4SLinus Torvalds 
3172c35543SPaul Mundt 	pvr = (ctrl_inl(CCN_PVR) >> 8) & 0xffffff;
321da177e4SLinus Torvalds 	prr = (ctrl_inl(CCN_PRR) >> 4) & 0xff;
331da177e4SLinus Torvalds 	cvr = (ctrl_inl(CCN_CVR));
341da177e4SLinus Torvalds 
351da177e4SLinus Torvalds 	/*
361da177e4SLinus Torvalds 	 * Setup some sane SH-4 defaults for the icache
371da177e4SLinus Torvalds 	 */
38cb7af21fSPaul Mundt 	boot_cpu_data.icache.way_incr		= (1 << 13);
39cb7af21fSPaul Mundt 	boot_cpu_data.icache.entry_shift	= 5;
40cb7af21fSPaul Mundt 	boot_cpu_data.icache.sets		= 256;
41cb7af21fSPaul Mundt 	boot_cpu_data.icache.ways		= 1;
42cb7af21fSPaul Mundt 	boot_cpu_data.icache.linesz		= L1_CACHE_BYTES;
431da177e4SLinus Torvalds 
441da177e4SLinus Torvalds 	/*
451da177e4SLinus Torvalds 	 * And again for the dcache ..
461da177e4SLinus Torvalds 	 */
47cb7af21fSPaul Mundt 	boot_cpu_data.dcache.way_incr		= (1 << 14);
48cb7af21fSPaul Mundt 	boot_cpu_data.dcache.entry_shift	= 5;
49cb7af21fSPaul Mundt 	boot_cpu_data.dcache.sets		= 512;
50cb7af21fSPaul Mundt 	boot_cpu_data.dcache.ways		= 1;
51cb7af21fSPaul Mundt 	boot_cpu_data.dcache.linesz		= L1_CACHE_BYTES;
521da177e4SLinus Torvalds 
53068f5914SPaul Mundt 	/* We don't know the chip cut */
54068f5914SPaul Mundt 	boot_cpu_data.cut_major = boot_cpu_data.cut_minor = -1;
55068f5914SPaul Mundt 
561da177e4SLinus Torvalds 	/*
5726fad19dSPaul Mundt 	 * Setup some generic flags we can probe on SH-4A parts
5872c35543SPaul Mundt 	 */
59068f5914SPaul Mundt 	if (((pvr >> 16) & 0xff) == 0x10) {
6072c35543SPaul Mundt 		if ((cvr & 0x10000000) == 0)
61cb7af21fSPaul Mundt 			boot_cpu_data.flags |= CPU_HAS_DSP;
6272c35543SPaul Mundt 
630bf8513eSPaul Mundt 		boot_cpu_data.flags |= CPU_HAS_LLSC | CPU_HAS_PERF_COUNTER;
64068f5914SPaul Mundt 		boot_cpu_data.cut_major = pvr & 0x7f;
650bf8513eSPaul Mundt 
660bf8513eSPaul Mundt 		boot_cpu_data.icache.ways = 4;
670bf8513eSPaul Mundt 		boot_cpu_data.dcache.ways = 4;
680bf8513eSPaul Mundt 	} else {
690bf8513eSPaul Mundt 		/* And some SH-4 defaults.. */
700bf8513eSPaul Mundt 		boot_cpu_data.flags |= CPU_HAS_PTEA;
7172c35543SPaul Mundt 	}
7272c35543SPaul Mundt 
7372c35543SPaul Mundt 	/* FPU detection works for everyone */
740bf8513eSPaul Mundt 	if ((cvr & 0x20000000))
75cb7af21fSPaul Mundt 		boot_cpu_data.flags |= CPU_HAS_FPU;
7672c35543SPaul Mundt 
7772c35543SPaul Mundt 	/* Mask off the upper chip ID */
7872c35543SPaul Mundt 	pvr &= 0xffff;
7972c35543SPaul Mundt 
8072c35543SPaul Mundt 	/*
811da177e4SLinus Torvalds 	 * Probe the underlying processor version/revision and
821da177e4SLinus Torvalds 	 * adjust cpu_data setup accordingly.
831da177e4SLinus Torvalds 	 */
841da177e4SLinus Torvalds 	switch (pvr) {
851da177e4SLinus Torvalds 	case 0x205:
86cb7af21fSPaul Mundt 		boot_cpu_data.type = CPU_SH7750;
870bf8513eSPaul Mundt 		boot_cpu_data.flags |= CPU_HAS_P2_FLUSH_BUG |
889b3a53abSStuart Menefy 				       CPU_HAS_PERF_COUNTER;
891da177e4SLinus Torvalds 		break;
901da177e4SLinus Torvalds 	case 0x206:
91cb7af21fSPaul Mundt 		boot_cpu_data.type = CPU_SH7750S;
920bf8513eSPaul Mundt 		boot_cpu_data.flags |= CPU_HAS_P2_FLUSH_BUG |
939b3a53abSStuart Menefy 				       CPU_HAS_PERF_COUNTER;
941da177e4SLinus Torvalds 		break;
951da177e4SLinus Torvalds 	case 0x1100:
96cb7af21fSPaul Mundt 		boot_cpu_data.type = CPU_SH7751;
971da177e4SLinus Torvalds 		break;
985b19c908SPaul Mundt 	case 0x2001:
995b19c908SPaul Mundt 	case 0x2004:
100cb7af21fSPaul Mundt 		boot_cpu_data.type = CPU_SH7770;
1015b19c908SPaul Mundt 		break;
1025b19c908SPaul Mundt 	case 0x2006:
1035b19c908SPaul Mundt 	case 0x200A:
1045b19c908SPaul Mundt 		if (prr == 0x61)
105cb7af21fSPaul Mundt 			boot_cpu_data.type = CPU_SH7781;
1067d740a06SYoshihiro Shimoda 		else if (prr == 0xa1)
1077d740a06SYoshihiro Shimoda 			boot_cpu_data.type = CPU_SH7763;
1085b19c908SPaul Mundt 		else
109cb7af21fSPaul Mundt 			boot_cpu_data.type = CPU_SH7780;
110749cf486SPaul Mundt 
1115b19c908SPaul Mundt 		break;
112e5723e0eSPaul Mundt 	case 0x3000:
113e5723e0eSPaul Mundt 	case 0x3003:
11441504c39SPaul Mundt 	case 0x3009:
115cb7af21fSPaul Mundt 		boot_cpu_data.type = CPU_SH7343;
116e5723e0eSPaul Mundt 		break;
11732351a28SPaul Mundt 	case 0x3004:
11832351a28SPaul Mundt 	case 0x3007:
119cb7af21fSPaul Mundt 		boot_cpu_data.type = CPU_SH7785;
12032351a28SPaul Mundt 		break;
12155ba99ebSKuninori Morimoto 	case 0x4004:
12255ba99ebSKuninori Morimoto 		boot_cpu_data.type = CPU_SH7786;
1230bf8513eSPaul Mundt 		boot_cpu_data.flags |= CPU_HAS_PTEAEX | CPU_HAS_L2_CACHE;
12455ba99ebSKuninori Morimoto 		break;
12541504c39SPaul Mundt 	case 0x3008:
126178dd0cdSPaul Mundt 		switch (prr) {
127178dd0cdSPaul Mundt 		case 0x50:
128b76baf4cSMagnus Damm 		case 0x51:
129178dd0cdSPaul Mundt 			boot_cpu_data.type = CPU_SH7723;
1300bf8513eSPaul Mundt 			boot_cpu_data.flags |= CPU_HAS_L2_CACHE;
131178dd0cdSPaul Mundt 			break;
132178dd0cdSPaul Mundt 		case 0x70:
1339109a30eSMagnus Damm 			boot_cpu_data.type = CPU_SH7366;
134178dd0cdSPaul Mundt 			break;
135178dd0cdSPaul Mundt 		case 0xa0:
136178dd0cdSPaul Mundt 		case 0xa1:
137178dd0cdSPaul Mundt 			boot_cpu_data.type = CPU_SH7722;
138178dd0cdSPaul Mundt 			break;
1399109a30eSMagnus Damm 		}
14041504c39SPaul Mundt 		break;
1410207a2efSKuninori Morimoto 	case 0x300b:
142*c01f0f1aSYoshihiro Shimoda 		switch (prr) {
143*c01f0f1aSYoshihiro Shimoda 		case 0x20:
144*c01f0f1aSYoshihiro Shimoda 			boot_cpu_data.type = CPU_SH7723;
1450bf8513eSPaul Mundt 			boot_cpu_data.flags |= CPU_HAS_L2_CACHE;
1460207a2efSKuninori Morimoto 			break;
147*c01f0f1aSYoshihiro Shimoda 		case 0x50:
148*c01f0f1aSYoshihiro Shimoda 			boot_cpu_data.type = CPU_SH7757;
149*c01f0f1aSYoshihiro Shimoda 			break;
150*c01f0f1aSYoshihiro Shimoda 		}
151*c01f0f1aSYoshihiro Shimoda 		break;
1522b1bd1acSPaul Mundt 	case 0x4000:	/* 1st cut */
1532b1bd1acSPaul Mundt 	case 0x4001:	/* 2nd cut */
154cb7af21fSPaul Mundt 		boot_cpu_data.type = CPU_SHX3;
1552b1bd1acSPaul Mundt 		break;
1561da177e4SLinus Torvalds 	case 0x700:
157cb7af21fSPaul Mundt 		boot_cpu_data.type = CPU_SH4_501;
158cb7af21fSPaul Mundt 		boot_cpu_data.icache.ways = 2;
159cb7af21fSPaul Mundt 		boot_cpu_data.dcache.ways = 2;
1601da177e4SLinus Torvalds 		break;
1611da177e4SLinus Torvalds 	case 0x600:
162cb7af21fSPaul Mundt 		boot_cpu_data.type = CPU_SH4_202;
163cb7af21fSPaul Mundt 		boot_cpu_data.icache.ways = 2;
164cb7af21fSPaul Mundt 		boot_cpu_data.dcache.ways = 2;
1651da177e4SLinus Torvalds 		break;
1661da177e4SLinus Torvalds 	case 0x500 ... 0x501:
1671da177e4SLinus Torvalds 		switch (prr) {
16873388cc7SPaul Mundt 		case 0x10:
169cb7af21fSPaul Mundt 			boot_cpu_data.type = CPU_SH7750R;
17073388cc7SPaul Mundt 			break;
17173388cc7SPaul Mundt 		case 0x11:
172cb7af21fSPaul Mundt 			boot_cpu_data.type = CPU_SH7751R;
17373388cc7SPaul Mundt 			break;
17473388cc7SPaul Mundt 		case 0x50 ... 0x5f:
175cb7af21fSPaul Mundt 			boot_cpu_data.type = CPU_SH7760;
17673388cc7SPaul Mundt 			break;
1771da177e4SLinus Torvalds 		}
1781da177e4SLinus Torvalds 
179cb7af21fSPaul Mundt 		boot_cpu_data.icache.ways = 2;
180cb7af21fSPaul Mundt 		boot_cpu_data.dcache.ways = 2;
1811da177e4SLinus Torvalds 
1821da177e4SLinus Torvalds 		break;
1831da177e4SLinus Torvalds 	default:
184cb7af21fSPaul Mundt 		boot_cpu_data.type = CPU_SH_NONE;
1851da177e4SLinus Torvalds 		break;
1861da177e4SLinus Torvalds 	}
1871da177e4SLinus Torvalds 
1881da177e4SLinus Torvalds 	/*
1891da177e4SLinus Torvalds 	 * On anything that's not a direct-mapped cache, look to the CVR
1901da177e4SLinus Torvalds 	 * for I/D-cache specifics.
1911da177e4SLinus Torvalds 	 */
192cb7af21fSPaul Mundt 	if (boot_cpu_data.icache.ways > 1) {
1931da177e4SLinus Torvalds 		size = sizes[(cvr >> 20) & 0xf];
194cb7af21fSPaul Mundt 		boot_cpu_data.icache.way_incr	= (size >> 1);
195cb7af21fSPaul Mundt 		boot_cpu_data.icache.sets	= (size >> 6);
196d15f4560SPaul Mundt 
1971da177e4SLinus Torvalds 	}
1981da177e4SLinus Torvalds 
199d15f4560SPaul Mundt 	/* And the rest of the D-cache */
200cb7af21fSPaul Mundt 	if (boot_cpu_data.dcache.ways > 1) {
2011da177e4SLinus Torvalds 		size = sizes[(cvr >> 16) & 0xf];
202cb7af21fSPaul Mundt 		boot_cpu_data.dcache.way_incr	= (size >> 1);
203cb7af21fSPaul Mundt 		boot_cpu_data.dcache.sets	= (size >> 6);
2041da177e4SLinus Torvalds 	}
2051da177e4SLinus Torvalds 
20672c35543SPaul Mundt 	/*
20772c35543SPaul Mundt 	 * SH-4A's have an optional PIPT L2.
20872c35543SPaul Mundt 	 */
209cb7af21fSPaul Mundt 	if (boot_cpu_data.flags & CPU_HAS_L2_CACHE) {
2107863d3f7SPaul Mundt 		/*
2117863d3f7SPaul Mundt 		 * Verify that it really has something hooked up, this
2127863d3f7SPaul Mundt 		 * is the safety net for CPUs that have optional L2
2137863d3f7SPaul Mundt 		 * support yet do not implement it.
2147863d3f7SPaul Mundt 		 */
2157863d3f7SPaul Mundt 		if ((cvr & 0xf) == 0)
2167863d3f7SPaul Mundt 			boot_cpu_data.flags &= ~CPU_HAS_L2_CACHE;
2177863d3f7SPaul Mundt 		else {
2187863d3f7SPaul Mundt 			/*
2197863d3f7SPaul Mundt 			 * Silicon and specifications have clearly never
2207863d3f7SPaul Mundt 			 * met..
2217863d3f7SPaul Mundt 			 */
222440fc172SPaul Mundt 			cvr ^= 0xf;
223440fc172SPaul Mundt 
22472c35543SPaul Mundt 			/*
22572c35543SPaul Mundt 			 * Size calculation is much more sensible
22672c35543SPaul Mundt 			 * than it is for the L1.
22772c35543SPaul Mundt 			 *
22872c35543SPaul Mundt 			 * Sizes are 128KB, 258KB, 512KB, and 1MB.
22972c35543SPaul Mundt 			 */
23072c35543SPaul Mundt 			size = (cvr & 0xf) << 17;
23172c35543SPaul Mundt 
232cb7af21fSPaul Mundt 			boot_cpu_data.scache.way_incr		= (1 << 16);
233cb7af21fSPaul Mundt 			boot_cpu_data.scache.entry_shift	= 5;
234cb7af21fSPaul Mundt 			boot_cpu_data.scache.ways		= 4;
235cb7af21fSPaul Mundt 			boot_cpu_data.scache.linesz		= L1_CACHE_BYTES;
23611c19656SPaul Mundt 
237cb7af21fSPaul Mundt 			boot_cpu_data.scache.entry_mask	=
238cb7af21fSPaul Mundt 				(boot_cpu_data.scache.way_incr -
239cb7af21fSPaul Mundt 				 boot_cpu_data.scache.linesz);
24011c19656SPaul Mundt 
241cb7af21fSPaul Mundt 			boot_cpu_data.scache.sets	= size /
242cb7af21fSPaul Mundt 				(boot_cpu_data.scache.linesz *
243cb7af21fSPaul Mundt 				 boot_cpu_data.scache.ways);
24411c19656SPaul Mundt 
245cb7af21fSPaul Mundt 			boot_cpu_data.scache.way_size	=
246cb7af21fSPaul Mundt 				(boot_cpu_data.scache.sets *
247cb7af21fSPaul Mundt 				 boot_cpu_data.scache.linesz);
24872c35543SPaul Mundt 		}
2497863d3f7SPaul Mundt 	}
25072c35543SPaul Mundt 
2511da177e4SLinus Torvalds 	return 0;
2521da177e4SLinus Torvalds }
253