xref: /OK3568_Linux_fs/u-boot/arch/arm/mach-sunxi/cpu_info.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * (C) Copyright 2007-2011
3*4882a593Smuzhiyun  * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
4*4882a593Smuzhiyun  * Tom Cubie <tangliang@allwinnertech.com>
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <common.h>
10*4882a593Smuzhiyun #include <asm/io.h>
11*4882a593Smuzhiyun #include <asm/arch/cpu.h>
12*4882a593Smuzhiyun #include <asm/arch/clock.h>
13*4882a593Smuzhiyun #include <axp_pmic.h>
14*4882a593Smuzhiyun #include <errno.h>
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #ifdef CONFIG_MACH_SUN6I
sunxi_get_ss_bonding_id(void)17*4882a593Smuzhiyun int sunxi_get_ss_bonding_id(void)
18*4882a593Smuzhiyun {
19*4882a593Smuzhiyun 	struct sunxi_ccm_reg * const ccm =
20*4882a593Smuzhiyun 		(struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
21*4882a593Smuzhiyun 	static int bonding_id = -1;
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun 	if (bonding_id != -1)
24*4882a593Smuzhiyun 		return bonding_id;
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun 	/* Enable Security System */
27*4882a593Smuzhiyun 	setbits_le32(&ccm->ahb_reset0_cfg, 1 << AHB_RESET_OFFSET_SS);
28*4882a593Smuzhiyun 	setbits_le32(&ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_SS);
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun 	bonding_id = readl(SUNXI_SS_BASE);
31*4882a593Smuzhiyun 	bonding_id = (bonding_id >> 16) & 0x7;
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun 	/* Disable Security System again */
34*4882a593Smuzhiyun 	clrbits_le32(&ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_SS);
35*4882a593Smuzhiyun 	clrbits_le32(&ccm->ahb_reset0_cfg, 1 << AHB_RESET_OFFSET_SS);
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun 	return bonding_id;
38*4882a593Smuzhiyun }
39*4882a593Smuzhiyun #endif
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun #ifdef CONFIG_MACH_SUN8I
sunxi_get_sram_id(void)42*4882a593Smuzhiyun uint sunxi_get_sram_id(void)
43*4882a593Smuzhiyun {
44*4882a593Smuzhiyun 	uint id;
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun 	/* Unlock sram info reg, read it, relock */
47*4882a593Smuzhiyun 	setbits_le32(SUNXI_SRAMC_BASE + 0x24, (1 << 15));
48*4882a593Smuzhiyun 	id = readl(SUNXI_SRAMC_BASE + 0x24) >> 16;
49*4882a593Smuzhiyun 	clrbits_le32(SUNXI_SRAMC_BASE + 0x24, (1 << 15));
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun 	return id;
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun #endif
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun #ifdef CONFIG_DISPLAY_CPUINFO
print_cpuinfo(void)56*4882a593Smuzhiyun int print_cpuinfo(void)
57*4882a593Smuzhiyun {
58*4882a593Smuzhiyun #ifdef CONFIG_MACH_SUN4I
59*4882a593Smuzhiyun 	puts("CPU:   Allwinner A10 (SUN4I)\n");
60*4882a593Smuzhiyun #elif defined CONFIG_MACH_SUN5I
61*4882a593Smuzhiyun 	u32 val = readl(SUNXI_SID_BASE + 0x08);
62*4882a593Smuzhiyun 	switch ((val >> 12) & 0xf) {
63*4882a593Smuzhiyun 	case 0: puts("CPU:   Allwinner A12 (SUN5I)\n"); break;
64*4882a593Smuzhiyun 	case 3: puts("CPU:   Allwinner A13 (SUN5I)\n"); break;
65*4882a593Smuzhiyun 	case 7: puts("CPU:   Allwinner A10s (SUN5I)\n"); break;
66*4882a593Smuzhiyun 	default: puts("CPU:   Allwinner A1X (SUN5I)\n");
67*4882a593Smuzhiyun 	}
68*4882a593Smuzhiyun #elif defined CONFIG_MACH_SUN6I
69*4882a593Smuzhiyun 	switch (sunxi_get_ss_bonding_id()) {
70*4882a593Smuzhiyun 	case SUNXI_SS_BOND_ID_A31:
71*4882a593Smuzhiyun 		puts("CPU:   Allwinner A31 (SUN6I)\n");
72*4882a593Smuzhiyun 		break;
73*4882a593Smuzhiyun 	case SUNXI_SS_BOND_ID_A31S:
74*4882a593Smuzhiyun 		puts("CPU:   Allwinner A31s (SUN6I)\n");
75*4882a593Smuzhiyun 		break;
76*4882a593Smuzhiyun 	default:
77*4882a593Smuzhiyun 		printf("CPU:   Allwinner A31? (SUN6I, id: %d)\n",
78*4882a593Smuzhiyun 		       sunxi_get_ss_bonding_id());
79*4882a593Smuzhiyun 	}
80*4882a593Smuzhiyun #elif defined CONFIG_MACH_SUN7I
81*4882a593Smuzhiyun 	puts("CPU:   Allwinner A20 (SUN7I)\n");
82*4882a593Smuzhiyun #elif defined CONFIG_MACH_SUN8I_A23
83*4882a593Smuzhiyun 	printf("CPU:   Allwinner A23 (SUN8I %04x)\n", sunxi_get_sram_id());
84*4882a593Smuzhiyun #elif defined CONFIG_MACH_SUN8I_A33
85*4882a593Smuzhiyun 	printf("CPU:   Allwinner A33 (SUN8I %04x)\n", sunxi_get_sram_id());
86*4882a593Smuzhiyun #elif defined CONFIG_MACH_SUN8I_A83T
87*4882a593Smuzhiyun 	printf("CPU:   Allwinner A83T (SUN8I %04x)\n", sunxi_get_sram_id());
88*4882a593Smuzhiyun #elif defined CONFIG_MACH_SUN8I_H3
89*4882a593Smuzhiyun 	printf("CPU:   Allwinner H3 (SUN8I %04x)\n", sunxi_get_sram_id());
90*4882a593Smuzhiyun #elif defined CONFIG_MACH_SUN8I_R40
91*4882a593Smuzhiyun 	printf("CPU:   Allwinner R40 (SUN8I %04x)\n", sunxi_get_sram_id());
92*4882a593Smuzhiyun #elif defined CONFIG_MACH_SUN8I_V3S
93*4882a593Smuzhiyun 	printf("CPU:   Allwinner V3s (SUN8I %04x)\n", sunxi_get_sram_id());
94*4882a593Smuzhiyun #elif defined CONFIG_MACH_SUN9I
95*4882a593Smuzhiyun 	puts("CPU:   Allwinner A80 (SUN9I)\n");
96*4882a593Smuzhiyun #elif defined CONFIG_MACH_SUN50I
97*4882a593Smuzhiyun 	puts("CPU:   Allwinner A64 (SUN50I)\n");
98*4882a593Smuzhiyun #elif defined CONFIG_MACH_SUN50I_H5
99*4882a593Smuzhiyun 	puts("CPU:   Allwinner H5 (SUN50I)\n");
100*4882a593Smuzhiyun #else
101*4882a593Smuzhiyun #warning Please update cpu_info.c with correct CPU information
102*4882a593Smuzhiyun 	puts("CPU:   SUNXI Family\n");
103*4882a593Smuzhiyun #endif
104*4882a593Smuzhiyun 	return 0;
105*4882a593Smuzhiyun }
106*4882a593Smuzhiyun #endif
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun #ifdef CONFIG_MACH_SUN8I_H3
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun #define SIDC_PRCTL 0x40
111*4882a593Smuzhiyun #define SIDC_RDKEY 0x60
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun #define SIDC_OP_LOCK 0xAC
114*4882a593Smuzhiyun 
sun8i_efuse_read(uint32_t offset)115*4882a593Smuzhiyun uint32_t sun8i_efuse_read(uint32_t offset)
116*4882a593Smuzhiyun {
117*4882a593Smuzhiyun 	uint32_t reg_val;
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun 	reg_val = readl(SUNXI_SIDC_BASE + SIDC_PRCTL);
120*4882a593Smuzhiyun 	reg_val &= ~(((0x1ff) << 16) | 0x3);
121*4882a593Smuzhiyun 	reg_val |= (offset << 16);
122*4882a593Smuzhiyun 	writel(reg_val, SUNXI_SIDC_BASE + SIDC_PRCTL);
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun 	reg_val &= ~(((0xff) << 8) | 0x3);
125*4882a593Smuzhiyun 	reg_val |= (SIDC_OP_LOCK << 8) | 0x2;
126*4882a593Smuzhiyun 	writel(reg_val, SUNXI_SIDC_BASE + SIDC_PRCTL);
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun 	while (readl(SUNXI_SIDC_BASE + SIDC_PRCTL) & 0x2);
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun 	reg_val &= ~(((0x1ff) << 16) | ((0xff) << 8) | 0x3);
131*4882a593Smuzhiyun 	writel(reg_val, SUNXI_SIDC_BASE + SIDC_PRCTL);
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun 	reg_val = readl(SUNXI_SIDC_BASE + SIDC_RDKEY);
134*4882a593Smuzhiyun 	return reg_val;
135*4882a593Smuzhiyun }
136*4882a593Smuzhiyun #endif
137*4882a593Smuzhiyun 
sunxi_get_sid(unsigned int * sid)138*4882a593Smuzhiyun int sunxi_get_sid(unsigned int *sid)
139*4882a593Smuzhiyun {
140*4882a593Smuzhiyun #ifdef CONFIG_AXP221_POWER
141*4882a593Smuzhiyun 	return axp_get_sid(sid);
142*4882a593Smuzhiyun #elif defined CONFIG_MACH_SUN8I_H3
143*4882a593Smuzhiyun 	/*
144*4882a593Smuzhiyun 	 * H3 SID controller has a bug, which makes the initial value of
145*4882a593Smuzhiyun 	 * SUNXI_SID_BASE at boot wrong.
146*4882a593Smuzhiyun 	 * Read the value directly from SID controller, in order to get
147*4882a593Smuzhiyun 	 * the correct value, and also refresh the wrong value at
148*4882a593Smuzhiyun 	 * SUNXI_SID_BASE.
149*4882a593Smuzhiyun 	 */
150*4882a593Smuzhiyun 	int i;
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun 	for (i = 0; i< 4; i++)
153*4882a593Smuzhiyun 		sid[i] = sun8i_efuse_read(i * 4);
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun 	return 0;
156*4882a593Smuzhiyun #elif defined SUNXI_SID_BASE
157*4882a593Smuzhiyun 	int i;
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	for (i = 0; i< 4; i++)
160*4882a593Smuzhiyun 		sid[i] = readl((ulong)SUNXI_SID_BASE + 4 * i);
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 	return 0;
163*4882a593Smuzhiyun #else
164*4882a593Smuzhiyun 	return -ENODEV;
165*4882a593Smuzhiyun #endif
166*4882a593Smuzhiyun }
167