xref: /openbmc/linux/arch/mips/cavium-octeon/executive/octeon-model.c (revision 597473720f4dc69749542bfcfed4a927a43d935e)
158f07778SDavid Daney /***********************license start***************
258f07778SDavid Daney  * Author: Cavium Networks
358f07778SDavid Daney  *
458f07778SDavid Daney  * Contact: support@caviumnetworks.com
558f07778SDavid Daney  * This file is part of the OCTEON SDK
658f07778SDavid Daney  *
715f68479SSteven J. Hill  * Copyright (c) 2003-2017 Cavium, Inc.
858f07778SDavid Daney  *
958f07778SDavid Daney  * This file is free software; you can redistribute it and/or modify
1058f07778SDavid Daney  * it under the terms of the GNU General Public License, Version 2, as
1158f07778SDavid Daney  * published by the Free Software Foundation.
1258f07778SDavid Daney  *
1358f07778SDavid Daney  * This file is distributed in the hope that it will be useful, but
1458f07778SDavid Daney  * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
1558f07778SDavid Daney  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
1658f07778SDavid Daney  * NONINFRINGEMENT.  See the GNU General Public License for more
1758f07778SDavid Daney  * details.
1858f07778SDavid Daney  *
1958f07778SDavid Daney  * You should have received a copy of the GNU General Public License
2058f07778SDavid Daney  * along with this file; if not, write to the Free Software
2158f07778SDavid Daney  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2258f07778SDavid Daney  * or visit http://www.gnu.org/licenses/.
2358f07778SDavid Daney  *
2458f07778SDavid Daney  * This file may also be available under a different license from Cavium.
2558f07778SDavid Daney  * Contact Cavium Networks for more information
2658f07778SDavid Daney  ***********************license end**************************************/
2758f07778SDavid Daney 
2858f07778SDavid Daney #include <asm/octeon/octeon.h>
2958f07778SDavid Daney 
30011f3c6cSAaro Koskinen enum octeon_feature_bits __octeon_feature_bits __read_mostly;
31011f3c6cSAaro Koskinen EXPORT_SYMBOL_GPL(__octeon_feature_bits);
32011f3c6cSAaro Koskinen 
3358f07778SDavid Daney /**
340f24017aSAaro Koskinen  * Read a byte of fuse data
350f24017aSAaro Koskinen  * @byte_addr:	 address to read
360f24017aSAaro Koskinen  *
370f24017aSAaro Koskinen  * Returns fuse value: 0 or 1
380f24017aSAaro Koskinen  */
cvmx_fuse_read_byte(int byte_addr)39da85e364SAaro Koskinen static uint8_t __init cvmx_fuse_read_byte(int byte_addr)
400f24017aSAaro Koskinen {
410f24017aSAaro Koskinen 	union cvmx_mio_fus_rcmd read_cmd;
420f24017aSAaro Koskinen 
430f24017aSAaro Koskinen 	read_cmd.u64 = 0;
440f24017aSAaro Koskinen 	read_cmd.s.addr = byte_addr;
450f24017aSAaro Koskinen 	read_cmd.s.pend = 1;
460f24017aSAaro Koskinen 	cvmx_write_csr(CVMX_MIO_FUS_RCMD, read_cmd.u64);
470f24017aSAaro Koskinen 	while ((read_cmd.u64 = cvmx_read_csr(CVMX_MIO_FUS_RCMD))
480f24017aSAaro Koskinen 	       && read_cmd.s.pend)
490f24017aSAaro Koskinen 		;
500f24017aSAaro Koskinen 	return read_cmd.s.dat;
510f24017aSAaro Koskinen }
520f24017aSAaro Koskinen 
5358f07778SDavid Daney /*
5458f07778SDavid Daney  * Version of octeon_model_get_string() that takes buffer as argument,
5558f07778SDavid Daney  * as running early in u-boot static/global variables don't work when
5658f07778SDavid Daney  * running from flash.
5758f07778SDavid Daney  */
octeon_model_get_string_buffer(uint32_t chip_id,char * buffer)58da85e364SAaro Koskinen static const char *__init octeon_model_get_string_buffer(uint32_t chip_id,
59da85e364SAaro Koskinen 							 char *buffer)
6058f07778SDavid Daney {
6158f07778SDavid Daney 	const char *family;
6258f07778SDavid Daney 	const char *core_model;
6358f07778SDavid Daney 	char pass[4];
6458f07778SDavid Daney 	int clock_mhz;
6558f07778SDavid Daney 	const char *suffix;
6658f07778SDavid Daney 	int num_cores;
6758f07778SDavid Daney 	union cvmx_mio_fus_dat2 fus_dat2;
6858f07778SDavid Daney 	union cvmx_mio_fus_dat3 fus_dat3;
6958f07778SDavid Daney 	char fuse_model[10];
7058f07778SDavid Daney 	uint32_t fuse_data = 0;
7115f68479SSteven J. Hill 	uint64_t l2d_fus3 = 0;
7258f07778SDavid Daney 
73182a6d1cSDavid Daney 	if (OCTEON_IS_MODEL(OCTEON_CN3XXX) || OCTEON_IS_MODEL(OCTEON_CN5XXX))
7415f68479SSteven J. Hill 		l2d_fus3 = (cvmx_read_csr(CVMX_L2D_FUS3) >> 34) & 0x3;
7558f07778SDavid Daney 	fus_dat2.u64 = cvmx_read_csr(CVMX_MIO_FUS_DAT2);
7658f07778SDavid Daney 	fus_dat3.u64 = cvmx_read_csr(CVMX_MIO_FUS_DAT3);
77182a6d1cSDavid Daney 	num_cores = cvmx_octeon_num_cores();
7858f07778SDavid Daney 
7925985edcSLucas De Marchi 	/* Make sure the non existent devices look disabled */
8058f07778SDavid Daney 	switch ((chip_id >> 8) & 0xff) {
8158f07778SDavid Daney 	case 6:		/* CN50XX */
8258f07778SDavid Daney 	case 2:		/* CN30XX */
8358f07778SDavid Daney 		fus_dat3.s.nodfa_dte = 1;
8458f07778SDavid Daney 		fus_dat3.s.nozip = 1;
8558f07778SDavid Daney 		break;
8658f07778SDavid Daney 	case 4:		/* CN57XX or CN56XX */
8758f07778SDavid Daney 		fus_dat3.s.nodfa_dte = 1;
8858f07778SDavid Daney 		break;
8958f07778SDavid Daney 	default:
9058f07778SDavid Daney 		break;
9158f07778SDavid Daney 	}
9258f07778SDavid Daney 
9358f07778SDavid Daney 	/* Make a guess at the suffix */
9458f07778SDavid Daney 	/* NSP = everything */
9558f07778SDavid Daney 	/* EXP = No crypto */
9658f07778SDavid Daney 	/* SCP = No DFA, No zip */
9758f07778SDavid Daney 	/* CP = No DFA, No crypto, No zip */
9858f07778SDavid Daney 	if (fus_dat3.s.nodfa_dte) {
9958f07778SDavid Daney 		if (fus_dat2.s.nocrypto)
10058f07778SDavid Daney 			suffix = "CP";
10158f07778SDavid Daney 		else
10258f07778SDavid Daney 			suffix = "SCP";
10358f07778SDavid Daney 	} else if (fus_dat2.s.nocrypto)
10458f07778SDavid Daney 		suffix = "EXP";
10558f07778SDavid Daney 	else
10658f07778SDavid Daney 		suffix = "NSP";
10758f07778SDavid Daney 
108011f3c6cSAaro Koskinen 	if (!fus_dat2.s.nocrypto)
109011f3c6cSAaro Koskinen 		__octeon_feature_bits |= OCTEON_HAS_CRYPTO;
110011f3c6cSAaro Koskinen 
11158f07778SDavid Daney 	/*
11258f07778SDavid Daney 	 * Assume pass number is encoded using <5:3><2:0>. Exceptions
11358f07778SDavid Daney 	 * will be fixed later.
11458f07778SDavid Daney 	 */
115751c9f68SDavid Daney 	sprintf(pass, "%d.%d", (int)((chip_id >> 3) & 7) + 1, (int)chip_id & 7);
11658f07778SDavid Daney 
11758f07778SDavid Daney 	/*
11858f07778SDavid Daney 	 * Use the number of cores to determine the last 2 digits of
11958f07778SDavid Daney 	 * the model number. There are some exceptions that are fixed
12058f07778SDavid Daney 	 * later.
12158f07778SDavid Daney 	 */
12258f07778SDavid Daney 	switch (num_cores) {
123182a6d1cSDavid Daney 	case 48:
124182a6d1cSDavid Daney 		core_model = "90";
125182a6d1cSDavid Daney 		break;
126182a6d1cSDavid Daney 	case 44:
127182a6d1cSDavid Daney 		core_model = "88";
128182a6d1cSDavid Daney 		break;
129182a6d1cSDavid Daney 	case 40:
130182a6d1cSDavid Daney 		core_model = "85";
131182a6d1cSDavid Daney 		break;
132751c9f68SDavid Daney 	case 32:
133751c9f68SDavid Daney 		core_model = "80";
134751c9f68SDavid Daney 		break;
135751c9f68SDavid Daney 	case 24:
136751c9f68SDavid Daney 		core_model = "70";
137751c9f68SDavid Daney 		break;
13858f07778SDavid Daney 	case 16:
13958f07778SDavid Daney 		core_model = "60";
14058f07778SDavid Daney 		break;
14158f07778SDavid Daney 	case 15:
14258f07778SDavid Daney 		core_model = "58";
14358f07778SDavid Daney 		break;
14458f07778SDavid Daney 	case 14:
14558f07778SDavid Daney 		core_model = "55";
14658f07778SDavid Daney 		break;
14758f07778SDavid Daney 	case 13:
14858f07778SDavid Daney 		core_model = "52";
14958f07778SDavid Daney 		break;
15058f07778SDavid Daney 	case 12:
15158f07778SDavid Daney 		core_model = "50";
15258f07778SDavid Daney 		break;
15358f07778SDavid Daney 	case 11:
15458f07778SDavid Daney 		core_model = "48";
15558f07778SDavid Daney 		break;
15658f07778SDavid Daney 	case 10:
15758f07778SDavid Daney 		core_model = "45";
15858f07778SDavid Daney 		break;
15958f07778SDavid Daney 	case 9:
16058f07778SDavid Daney 		core_model = "42";
16158f07778SDavid Daney 		break;
16258f07778SDavid Daney 	case 8:
16358f07778SDavid Daney 		core_model = "40";
16458f07778SDavid Daney 		break;
16558f07778SDavid Daney 	case 7:
16658f07778SDavid Daney 		core_model = "38";
16758f07778SDavid Daney 		break;
16858f07778SDavid Daney 	case 6:
16958f07778SDavid Daney 		core_model = "34";
17058f07778SDavid Daney 		break;
17158f07778SDavid Daney 	case 5:
17258f07778SDavid Daney 		core_model = "32";
17358f07778SDavid Daney 		break;
17458f07778SDavid Daney 	case 4:
17558f07778SDavid Daney 		core_model = "30";
17658f07778SDavid Daney 		break;
17758f07778SDavid Daney 	case 3:
17858f07778SDavid Daney 		core_model = "25";
17958f07778SDavid Daney 		break;
18058f07778SDavid Daney 	case 2:
18158f07778SDavid Daney 		core_model = "20";
18258f07778SDavid Daney 		break;
18358f07778SDavid Daney 	case 1:
18458f07778SDavid Daney 		core_model = "10";
18558f07778SDavid Daney 		break;
18658f07778SDavid Daney 	default:
18758f07778SDavid Daney 		core_model = "XX";
18858f07778SDavid Daney 		break;
18958f07778SDavid Daney 	}
19058f07778SDavid Daney 
19158f07778SDavid Daney 	/* Now figure out the family, the first two digits */
19258f07778SDavid Daney 	switch ((chip_id >> 8) & 0xff) {
19358f07778SDavid Daney 	case 0:		/* CN38XX, CN37XX or CN36XX */
19415f68479SSteven J. Hill 		if (l2d_fus3) {
19558f07778SDavid Daney 			/*
19658f07778SDavid Daney 			 * For some unknown reason, the 16 core one is
19758f07778SDavid Daney 			 * called 37 instead of 36.
19858f07778SDavid Daney 			 */
19958f07778SDavid Daney 			if (num_cores >= 16)
20058f07778SDavid Daney 				family = "37";
20158f07778SDavid Daney 			else
20258f07778SDavid Daney 				family = "36";
20358f07778SDavid Daney 		} else
20458f07778SDavid Daney 			family = "38";
20558f07778SDavid Daney 		/*
20658f07778SDavid Daney 		 * This series of chips didn't follow the standard
20758f07778SDavid Daney 		 * pass numbering.
20858f07778SDavid Daney 		 */
20958f07778SDavid Daney 		switch (chip_id & 0xf) {
21058f07778SDavid Daney 		case 0:
21158f07778SDavid Daney 			strcpy(pass, "1.X");
21258f07778SDavid Daney 			break;
21358f07778SDavid Daney 		case 1:
21458f07778SDavid Daney 			strcpy(pass, "2.X");
21558f07778SDavid Daney 			break;
21658f07778SDavid Daney 		case 3:
21758f07778SDavid Daney 			strcpy(pass, "3.X");
21858f07778SDavid Daney 			break;
21958f07778SDavid Daney 		default:
22058f07778SDavid Daney 			strcpy(pass, "X.X");
22158f07778SDavid Daney 			break;
22258f07778SDavid Daney 		}
22358f07778SDavid Daney 		break;
22458f07778SDavid Daney 	case 1:		/* CN31XX or CN3020 */
22515f68479SSteven J. Hill 		if ((chip_id & 0x10) || l2d_fus3)
22658f07778SDavid Daney 			family = "30";
22758f07778SDavid Daney 		else
22858f07778SDavid Daney 			family = "31";
22958f07778SDavid Daney 		/*
23058f07778SDavid Daney 		 * This series of chips didn't follow the standard
23158f07778SDavid Daney 		 * pass numbering.
23258f07778SDavid Daney 		 */
23358f07778SDavid Daney 		switch (chip_id & 0xf) {
23458f07778SDavid Daney 		case 0:
23558f07778SDavid Daney 			strcpy(pass, "1.0");
23658f07778SDavid Daney 			break;
23758f07778SDavid Daney 		case 2:
23858f07778SDavid Daney 			strcpy(pass, "1.1");
23958f07778SDavid Daney 			break;
24058f07778SDavid Daney 		default:
24158f07778SDavid Daney 			strcpy(pass, "X.X");
24258f07778SDavid Daney 			break;
24358f07778SDavid Daney 		}
24458f07778SDavid Daney 		break;
24558f07778SDavid Daney 	case 2:		/* CN3010 or CN3005 */
24658f07778SDavid Daney 		family = "30";
24758f07778SDavid Daney 		/* A chip with half cache is an 05 */
24815f68479SSteven J. Hill 		if (l2d_fus3)
24958f07778SDavid Daney 			core_model = "05";
25058f07778SDavid Daney 		/*
25158f07778SDavid Daney 		 * This series of chips didn't follow the standard
25258f07778SDavid Daney 		 * pass numbering.
25358f07778SDavid Daney 		 */
25458f07778SDavid Daney 		switch (chip_id & 0xf) {
25558f07778SDavid Daney 		case 0:
25658f07778SDavid Daney 			strcpy(pass, "1.0");
25758f07778SDavid Daney 			break;
25858f07778SDavid Daney 		case 2:
25958f07778SDavid Daney 			strcpy(pass, "1.1");
26058f07778SDavid Daney 			break;
26158f07778SDavid Daney 		default:
26258f07778SDavid Daney 			strcpy(pass, "X.X");
26358f07778SDavid Daney 			break;
26458f07778SDavid Daney 		}
26558f07778SDavid Daney 		break;
26658f07778SDavid Daney 	case 3:		/* CN58XX */
26758f07778SDavid Daney 		family = "58";
268751c9f68SDavid Daney 		/* Special case. 4 core, half cache (CP with half cache) */
26915f68479SSteven J. Hill 		if ((num_cores == 4) && l2d_fus3 && !strncmp(suffix, "CP", 2))
27058f07778SDavid Daney 			core_model = "29";
27158f07778SDavid Daney 
27258f07778SDavid Daney 		/* Pass 1 uses different encodings for pass numbers */
27358f07778SDavid Daney 		if ((chip_id & 0xFF) < 0x8) {
27458f07778SDavid Daney 			switch (chip_id & 0x3) {
27558f07778SDavid Daney 			case 0:
27658f07778SDavid Daney 				strcpy(pass, "1.0");
27758f07778SDavid Daney 				break;
27858f07778SDavid Daney 			case 1:
27958f07778SDavid Daney 				strcpy(pass, "1.1");
28058f07778SDavid Daney 				break;
28158f07778SDavid Daney 			case 3:
28258f07778SDavid Daney 				strcpy(pass, "1.2");
28358f07778SDavid Daney 				break;
28458f07778SDavid Daney 			default:
28558f07778SDavid Daney 				strcpy(pass, "1.X");
28658f07778SDavid Daney 				break;
28758f07778SDavid Daney 			}
28858f07778SDavid Daney 		}
28958f07778SDavid Daney 		break;
29058f07778SDavid Daney 	case 4:		/* CN57XX, CN56XX, CN55XX, CN54XX */
29158f07778SDavid Daney 		if (fus_dat2.cn56xx.raid_en) {
29215f68479SSteven J. Hill 			if (l2d_fus3)
29358f07778SDavid Daney 				family = "55";
29458f07778SDavid Daney 			else
29558f07778SDavid Daney 				family = "57";
29658f07778SDavid Daney 			if (fus_dat2.cn56xx.nocrypto)
29758f07778SDavid Daney 				suffix = "SP";
29858f07778SDavid Daney 			else
29958f07778SDavid Daney 				suffix = "SSP";
30058f07778SDavid Daney 		} else {
30158f07778SDavid Daney 			if (fus_dat2.cn56xx.nocrypto)
30258f07778SDavid Daney 				suffix = "CP";
30358f07778SDavid Daney 			else {
30458f07778SDavid Daney 				suffix = "NSP";
30558f07778SDavid Daney 				if (fus_dat3.s.nozip)
30658f07778SDavid Daney 					suffix = "SCP";
307751c9f68SDavid Daney 
308*2bb17713SAaro Koskinen 				if (fus_dat3.cn38xx.bar2_en)
309751c9f68SDavid Daney 					suffix = "NSPB2";
31058f07778SDavid Daney 			}
31115f68479SSteven J. Hill 			if (l2d_fus3)
31258f07778SDavid Daney 				family = "54";
31358f07778SDavid Daney 			else
31458f07778SDavid Daney 				family = "56";
31558f07778SDavid Daney 		}
31658f07778SDavid Daney 		break;
31758f07778SDavid Daney 	case 6:		/* CN50XX */
31858f07778SDavid Daney 		family = "50";
31958f07778SDavid Daney 		break;
32058f07778SDavid Daney 	case 7:		/* CN52XX */
32115f68479SSteven J. Hill 		if (l2d_fus3)
32258f07778SDavid Daney 			family = "51";
32358f07778SDavid Daney 		else
32458f07778SDavid Daney 			family = "52";
32558f07778SDavid Daney 		break;
326751c9f68SDavid Daney 	case 0x93:		/* CN61XX */
327751c9f68SDavid Daney 		family = "61";
328751c9f68SDavid Daney 		if (fus_dat2.cn61xx.nocrypto && fus_dat2.cn61xx.dorm_crypto)
329751c9f68SDavid Daney 			suffix = "AP";
330751c9f68SDavid Daney 		if (fus_dat2.cn61xx.nocrypto)
331751c9f68SDavid Daney 			suffix = "CP";
332751c9f68SDavid Daney 		else if (fus_dat2.cn61xx.dorm_crypto)
333751c9f68SDavid Daney 			suffix = "DAP";
334751c9f68SDavid Daney 		else if (fus_dat3.cn61xx.nozip)
335751c9f68SDavid Daney 			suffix = "SCP";
336751c9f68SDavid Daney 		break;
337751c9f68SDavid Daney 	case 0x90:		/* CN63XX */
338751c9f68SDavid Daney 		family = "63";
339751c9f68SDavid Daney 		if (fus_dat3.s.l2c_crip == 2)
340751c9f68SDavid Daney 			family = "62";
341751c9f68SDavid Daney 		if (num_cores == 6)	/* Other core counts match generic */
342751c9f68SDavid Daney 			core_model = "35";
343751c9f68SDavid Daney 		if (fus_dat2.cn63xx.nocrypto)
344751c9f68SDavid Daney 			suffix = "CP";
345751c9f68SDavid Daney 		else if (fus_dat2.cn63xx.dorm_crypto)
346751c9f68SDavid Daney 			suffix = "DAP";
347*2bb17713SAaro Koskinen 		else if (fus_dat3.cn61xx.nozip)
348751c9f68SDavid Daney 			suffix = "SCP";
349751c9f68SDavid Daney 		else
350751c9f68SDavid Daney 			suffix = "AAP";
351751c9f68SDavid Daney 		break;
352751c9f68SDavid Daney 	case 0x92:		/* CN66XX */
353751c9f68SDavid Daney 		family = "66";
354751c9f68SDavid Daney 		if (num_cores == 6)	/* Other core counts match generic */
355751c9f68SDavid Daney 			core_model = "35";
356751c9f68SDavid Daney 		if (fus_dat2.cn66xx.nocrypto && fus_dat2.cn66xx.dorm_crypto)
357751c9f68SDavid Daney 			suffix = "AP";
358751c9f68SDavid Daney 		if (fus_dat2.cn66xx.nocrypto)
359751c9f68SDavid Daney 			suffix = "CP";
360751c9f68SDavid Daney 		else if (fus_dat2.cn66xx.dorm_crypto)
361751c9f68SDavid Daney 			suffix = "DAP";
362*2bb17713SAaro Koskinen 		else if (fus_dat3.cn61xx.nozip)
363751c9f68SDavid Daney 			suffix = "SCP";
364751c9f68SDavid Daney 		else
365751c9f68SDavid Daney 			suffix = "AAP";
366751c9f68SDavid Daney 		break;
367751c9f68SDavid Daney 	case 0x91:		/* CN68XX */
368751c9f68SDavid Daney 		family = "68";
369*2bb17713SAaro Koskinen 		if (fus_dat2.cn68xx.nocrypto && fus_dat3.cn61xx.nozip)
370751c9f68SDavid Daney 			suffix = "CP";
371751c9f68SDavid Daney 		else if (fus_dat2.cn68xx.dorm_crypto)
372751c9f68SDavid Daney 			suffix = "DAP";
373*2bb17713SAaro Koskinen 		else if (fus_dat3.cn61xx.nozip)
374751c9f68SDavid Daney 			suffix = "SCP";
375751c9f68SDavid Daney 		else if (fus_dat2.cn68xx.nocrypto)
376751c9f68SDavid Daney 			suffix = "SP";
377751c9f68SDavid Daney 		else
378751c9f68SDavid Daney 			suffix = "AAP";
379751c9f68SDavid Daney 		break;
380182a6d1cSDavid Daney 	case 0x94:		/* CNF71XX */
381182a6d1cSDavid Daney 		family = "F71";
382*2bb17713SAaro Koskinen 		if (fus_dat3.cn61xx.nozip)
383182a6d1cSDavid Daney 			suffix = "SCP";
384182a6d1cSDavid Daney 		else
385182a6d1cSDavid Daney 			suffix = "AAP";
386182a6d1cSDavid Daney 		break;
387182a6d1cSDavid Daney 	case 0x95:		/* CN78XX */
388182a6d1cSDavid Daney 		if (num_cores == 6)	/* Other core counts match generic */
389182a6d1cSDavid Daney 			core_model = "35";
390182a6d1cSDavid Daney 		if (OCTEON_IS_MODEL(OCTEON_CN76XX))
391182a6d1cSDavid Daney 			family = "76";
392182a6d1cSDavid Daney 		else
393182a6d1cSDavid Daney 			family = "78";
394182a6d1cSDavid Daney 		if (fus_dat3.cn78xx.l2c_crip == 2)
395182a6d1cSDavid Daney 			family = "77";
396182a6d1cSDavid Daney 		if (fus_dat3.cn78xx.nozip
397182a6d1cSDavid Daney 		    && fus_dat3.cn78xx.nodfa_dte
398182a6d1cSDavid Daney 		    && fus_dat3.cn78xx.nohna_dte) {
399182a6d1cSDavid Daney 			if (fus_dat3.cn78xx.nozip &&
400182a6d1cSDavid Daney 				!fus_dat2.cn78xx.raid_en &&
401182a6d1cSDavid Daney 				fus_dat3.cn78xx.nohna_dte) {
402182a6d1cSDavid Daney 				suffix = "CP";
403182a6d1cSDavid Daney 			} else {
404182a6d1cSDavid Daney 				suffix = "SCP";
405182a6d1cSDavid Daney 			}
406182a6d1cSDavid Daney 		} else if (fus_dat2.cn78xx.raid_en == 0)
407182a6d1cSDavid Daney 			suffix = "HCP";
408182a6d1cSDavid Daney 		else
409182a6d1cSDavid Daney 			suffix = "AAP";
410182a6d1cSDavid Daney 		break;
411182a6d1cSDavid Daney 	case 0x96:		/* CN70XX */
412182a6d1cSDavid Daney 		family = "70";
413182a6d1cSDavid Daney 		if (cvmx_read_csr(CVMX_MIO_FUS_PDF) & (0x1ULL << 32))
414182a6d1cSDavid Daney 			family = "71";
415182a6d1cSDavid Daney 		if (fus_dat2.cn70xx.nocrypto)
416182a6d1cSDavid Daney 			suffix = "CP";
417182a6d1cSDavid Daney 		else if (fus_dat3.cn70xx.nodfa_dte)
418182a6d1cSDavid Daney 			suffix = "SCP";
419182a6d1cSDavid Daney 		else
420182a6d1cSDavid Daney 			suffix = "AAP";
421182a6d1cSDavid Daney 		break;
422182a6d1cSDavid Daney 	case 0x97:		/* CN73XX */
423182a6d1cSDavid Daney 		if (num_cores == 6)	/* Other core counts match generic */
424182a6d1cSDavid Daney 			core_model = "35";
425182a6d1cSDavid Daney 		family = "73";
426182a6d1cSDavid Daney 		if (fus_dat3.cn73xx.l2c_crip == 2)
427182a6d1cSDavid Daney 			family = "72";
428182a6d1cSDavid Daney 		if (fus_dat3.cn73xx.nozip
429182a6d1cSDavid Daney 				&& fus_dat3.cn73xx.nodfa_dte
430182a6d1cSDavid Daney 				&& fus_dat3.cn73xx.nohna_dte) {
431182a6d1cSDavid Daney 			if (!fus_dat2.cn73xx.raid_en)
432182a6d1cSDavid Daney 				suffix = "CP";
433182a6d1cSDavid Daney 			else
434182a6d1cSDavid Daney 				suffix = "SCP";
435182a6d1cSDavid Daney 		} else
436182a6d1cSDavid Daney 			suffix = "AAP";
437182a6d1cSDavid Daney 		break;
438182a6d1cSDavid Daney 	case 0x98:		/* CN75XX */
439182a6d1cSDavid Daney 		family = "F75";
440182a6d1cSDavid Daney 		if (fus_dat3.cn78xx.nozip
441182a6d1cSDavid Daney 		    && fus_dat3.cn78xx.nodfa_dte
442182a6d1cSDavid Daney 		    && fus_dat3.cn78xx.nohna_dte)
443182a6d1cSDavid Daney 			suffix = "SCP";
444182a6d1cSDavid Daney 		else
445182a6d1cSDavid Daney 			suffix = "AAP";
446182a6d1cSDavid Daney 		break;
44758f07778SDavid Daney 	default:
44858f07778SDavid Daney 		family = "XX";
44958f07778SDavid Daney 		core_model = "XX";
45058f07778SDavid Daney 		strcpy(pass, "X.X");
45158f07778SDavid Daney 		suffix = "XXX";
45258f07778SDavid Daney 		break;
45358f07778SDavid Daney 	}
45458f07778SDavid Daney 
45558f07778SDavid Daney 	clock_mhz = octeon_get_clock_rate() / 1000000;
45658f07778SDavid Daney 	if (family[0] != '3') {
457751c9f68SDavid Daney 		int fuse_base = 384 / 8;
458751c9f68SDavid Daney 		if (family[0] == '6')
459751c9f68SDavid Daney 			fuse_base = 832 / 8;
460751c9f68SDavid Daney 
46158f07778SDavid Daney 		/* Check for model in fuses, overrides normal decode */
46258f07778SDavid Daney 		/* This is _not_ valid for Octeon CN3XXX models */
463751c9f68SDavid Daney 		fuse_data |= cvmx_fuse_read_byte(fuse_base + 3);
46458f07778SDavid Daney 		fuse_data = fuse_data << 8;
465751c9f68SDavid Daney 		fuse_data |= cvmx_fuse_read_byte(fuse_base + 2);
46658f07778SDavid Daney 		fuse_data = fuse_data << 8;
467751c9f68SDavid Daney 		fuse_data |= cvmx_fuse_read_byte(fuse_base + 1);
46858f07778SDavid Daney 		fuse_data = fuse_data << 8;
469751c9f68SDavid Daney 		fuse_data |= cvmx_fuse_read_byte(fuse_base);
47058f07778SDavid Daney 		if (fuse_data & 0x7ffff) {
47158f07778SDavid Daney 			int model = fuse_data & 0x3fff;
47258f07778SDavid Daney 			int suffix = (fuse_data >> 14) & 0x1f;
47358f07778SDavid Daney 			if (suffix && model) {
474751c9f68SDavid Daney 				/* Have both number and suffix in fuses, so both */
475751c9f68SDavid Daney 				sprintf(fuse_model, "%d%c", model, 'A' + suffix - 1);
47658f07778SDavid Daney 				core_model = "";
47758f07778SDavid Daney 				family = fuse_model;
47858f07778SDavid Daney 			} else if (suffix && !model) {
479751c9f68SDavid Daney 				/* Only have suffix, so add suffix to 'normal' model number */
480751c9f68SDavid Daney 				sprintf(fuse_model, "%s%c", core_model, 'A' + suffix - 1);
48158f07778SDavid Daney 				core_model = fuse_model;
48258f07778SDavid Daney 			} else {
483751c9f68SDavid Daney 				/* Don't have suffix, so just use model from fuses */
48458f07778SDavid Daney 				sprintf(fuse_model, "%d", model);
48558f07778SDavid Daney 				core_model = "";
48658f07778SDavid Daney 				family = fuse_model;
48758f07778SDavid Daney 			}
48858f07778SDavid Daney 		}
48958f07778SDavid Daney 	}
490751c9f68SDavid Daney 	sprintf(buffer, "CN%s%sp%s-%d-%s", family, core_model, pass, clock_mhz, suffix);
49158f07778SDavid Daney 	return buffer;
49258f07778SDavid Daney }
493653e0528SAaro Koskinen 
494653e0528SAaro Koskinen /**
495653e0528SAaro Koskinen  * Given the chip processor ID from COP0, this function returns a
496653e0528SAaro Koskinen  * string representing the chip model number. The string is of the
497653e0528SAaro Koskinen  * form CNXXXXpX.X-FREQ-SUFFIX.
498653e0528SAaro Koskinen  * - XXXX = The chip model number
499653e0528SAaro Koskinen  * - X.X = Chip pass number
500653e0528SAaro Koskinen  * - FREQ = Current frequency in Mhz
501653e0528SAaro Koskinen  * - SUFFIX = NSP, EXP, SCP, SSP, or CP
502653e0528SAaro Koskinen  *
503653e0528SAaro Koskinen  * @chip_id: Chip ID
504653e0528SAaro Koskinen  *
505653e0528SAaro Koskinen  * Returns Model string
506653e0528SAaro Koskinen  */
octeon_model_get_string(uint32_t chip_id)507da85e364SAaro Koskinen const char *__init octeon_model_get_string(uint32_t chip_id)
508653e0528SAaro Koskinen {
509653e0528SAaro Koskinen 	static char buffer[32];
510653e0528SAaro Koskinen 	return octeon_model_get_string_buffer(chip_id, buffer);
511653e0528SAaro Koskinen }
512