sun6i: Add sunxi_get_ss_bonding_id() function
[platform/kernel/u-boot.git] / arch / arm / cpu / armv7 / sunxi / cpu_info.c
1 /*
2  * (C) Copyright 2007-2011
3  * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
4  * Tom Cubie <tangliang@allwinnertech.com>
5  *
6  * SPDX-License-Identifier:     GPL-2.0+
7  */
8
9 #include <common.h>
10 #include <asm/io.h>
11 #include <asm/arch/cpu.h>
12 #include <asm/arch/clock.h>
13
14 #ifdef CONFIG_MACH_SUN6I
15 int sunxi_get_ss_bonding_id(void)
16 {
17         struct sunxi_ccm_reg * const ccm =
18                 (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
19         static int bonding_id = -1;
20
21         if (bonding_id != -1)
22                 return bonding_id;
23
24         /* Enable Security System */
25         setbits_le32(&ccm->ahb_reset0_cfg, 1 << AHB_RESET_OFFSET_SS);
26         setbits_le32(&ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_SS);
27
28         bonding_id = readl(SUNXI_SS_BASE);
29         bonding_id = (bonding_id >> 16) & 0x7;
30
31         /* Disable Security System again */
32         clrbits_le32(&ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_SS);
33         clrbits_le32(&ccm->ahb_reset0_cfg, 1 << AHB_RESET_OFFSET_SS);
34
35         return bonding_id;
36 }
37 #endif
38
39 #ifdef CONFIG_DISPLAY_CPUINFO
40 int print_cpuinfo(void)
41 {
42 #ifdef CONFIG_MACH_SUN4I
43         puts("CPU:   Allwinner A10 (SUN4I)\n");
44 #elif defined CONFIG_MACH_SUN5I
45         u32 val = readl(SUNXI_SID_BASE + 0x08);
46         switch ((val >> 12) & 0xf) {
47         case 0: puts("CPU:   Allwinner A12 (SUN5I)\n"); break;
48         case 3: puts("CPU:   Allwinner A13 (SUN5I)\n"); break;
49         case 7: puts("CPU:   Allwinner A10s (SUN5I)\n"); break;
50         default: puts("CPU:   Allwinner A1X (SUN5I)\n");
51         }
52 #elif defined CONFIG_MACH_SUN6I
53         switch (sunxi_get_ss_bonding_id()) {
54         case SUNXI_SS_BOND_ID_A31:
55                 puts("CPU:   Allwinner A31 (SUN6I)\n");
56                 break;
57         case SUNXI_SS_BOND_ID_A31S:
58                 puts("CPU:   Allwinner A31s (SUN6I)\n");
59                 break;
60         default:
61                 printf("CPU:   Allwinner A31? (SUN6I, id: %d)\n",
62                        sunxi_get_ss_bonding_id());
63         }
64 #elif defined CONFIG_MACH_SUN7I
65         puts("CPU:   Allwinner A20 (SUN7I)\n");
66 #elif defined CONFIG_MACH_SUN8I
67         puts("CPU:   Allwinner A23 (SUN8I)\n");
68 #else
69 #warning Please update cpu_info.c with correct CPU information
70         puts("CPU:   SUNXI Family\n");
71 #endif
72         return 0;
73 }
74 #endif