blob: c0eabdf91d353648c109f0edf64bf822369fe3df [file] [log] [blame]
Ian Campbellcba69ee2014-05-05 11:52:26 +01001/*
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>
Hans de Goede10191ed2014-11-15 22:55:53 +010012#include <asm/arch/clock.h>
Hans de Goede6944aff2015-10-03 15:18:33 +020013#include <axp_pmic.h>
Hans de Goede1871a8c2015-01-13 19:25:06 +010014#include <errno.h>
Hans de Goede10191ed2014-11-15 22:55:53 +010015
16#ifdef CONFIG_MACH_SUN6I
17int sunxi_get_ss_bonding_id(void)
18{
19 struct sunxi_ccm_reg * const ccm =
20 (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
21 static int bonding_id = -1;
22
23 if (bonding_id != -1)
24 return bonding_id;
25
26 /* Enable Security System */
27 setbits_le32(&ccm->ahb_reset0_cfg, 1 << AHB_RESET_OFFSET_SS);
28 setbits_le32(&ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_SS);
29
30 bonding_id = readl(SUNXI_SS_BASE);
31 bonding_id = (bonding_id >> 16) & 0x7;
32
33 /* Disable Security System again */
34 clrbits_le32(&ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_SS);
35 clrbits_le32(&ccm->ahb_reset0_cfg, 1 << AHB_RESET_OFFSET_SS);
36
37 return bonding_id;
38}
39#endif
Ian Campbellcba69ee2014-05-05 11:52:26 +010040
Hans de Goedec74384c2016-03-24 22:38:23 +010041#ifdef CONFIG_MACH_SUN8I
42uint sunxi_get_sram_id(void)
43{
44 uint id;
45
46 /* Unlock sram info reg, read it, relock */
47 setbits_le32(SUNXI_SRAMC_BASE + 0x24, (1 << 15));
48 id = readl(SUNXI_SRAMC_BASE + 0x24) >> 16;
49 clrbits_le32(SUNXI_SRAMC_BASE + 0x24, (1 << 15));
50
51 return id;
52}
53#endif
54
Ian Campbellcba69ee2014-05-05 11:52:26 +010055#ifdef CONFIG_DISPLAY_CPUINFO
56int print_cpuinfo(void)
57{
Ian Campbelled41e622014-10-24 21:20:47 +010058#ifdef CONFIG_MACH_SUN4I
Hans de Goede745325a2014-06-09 11:36:57 +020059 puts("CPU: Allwinner A10 (SUN4I)\n");
Ian Campbelled41e622014-10-24 21:20:47 +010060#elif defined CONFIG_MACH_SUN5I
Hans de Goedef84269c2014-06-09 11:36:58 +020061 u32 val = readl(SUNXI_SID_BASE + 0x08);
62 switch ((val >> 12) & 0xf) {
63 case 0: puts("CPU: Allwinner A12 (SUN5I)\n"); break;
64 case 3: puts("CPU: Allwinner A13 (SUN5I)\n"); break;
65 case 7: puts("CPU: Allwinner A10s (SUN5I)\n"); break;
66 default: puts("CPU: Allwinner A1X (SUN5I)\n");
67 }
Ian Campbelled41e622014-10-24 21:20:47 +010068#elif defined CONFIG_MACH_SUN6I
Hans de Goede10191ed2014-11-15 22:55:53 +010069 switch (sunxi_get_ss_bonding_id()) {
70 case SUNXI_SS_BOND_ID_A31:
71 puts("CPU: Allwinner A31 (SUN6I)\n");
72 break;
73 case SUNXI_SS_BOND_ID_A31S:
74 puts("CPU: Allwinner A31s (SUN6I)\n");
75 break;
76 default:
77 printf("CPU: Allwinner A31? (SUN6I, id: %d)\n",
78 sunxi_get_ss_bonding_id());
79 }
Ian Campbelled41e622014-10-24 21:20:47 +010080#elif defined CONFIG_MACH_SUN7I
Ian Campbellcba69ee2014-05-05 11:52:26 +010081 puts("CPU: Allwinner A20 (SUN7I)\n");
Hans de Goede5e6bacd2015-04-06 20:55:39 +020082#elif defined CONFIG_MACH_SUN8I_A23
Hans de Goedec74384c2016-03-24 22:38:23 +010083 printf("CPU: Allwinner A23 (SUN8I %04x)\n", sunxi_get_sram_id());
Vishnu Patekar8c3dacf2015-03-01 23:47:48 +053084#elif defined CONFIG_MACH_SUN8I_A33
Hans de Goedec74384c2016-03-24 22:38:23 +010085 printf("CPU: Allwinner A33 (SUN8I %04x)\n", sunxi_get_sram_id());
86#elif defined CONFIG_MACH_SUN8I_A83T
87 printf("CPU: Allwinner A83T (SUN8I %04x)\n", sunxi_get_sram_id());
Jens Kuske1c27b7d2015-11-17 15:12:58 +010088#elif defined CONFIG_MACH_SUN8I_H3
Hans de Goedec74384c2016-03-24 22:38:23 +010089 printf("CPU: Allwinner H3 (SUN8I %04x)\n", sunxi_get_sram_id());
Hans de Goede1871a8c2015-01-13 19:25:06 +010090#elif defined CONFIG_MACH_SUN9I
91 puts("CPU: Allwinner A80 (SUN9I)\n");
Hans de Goede745325a2014-06-09 11:36:57 +020092#else
93#warning Please update cpu_info.c with correct CPU information
94 puts("CPU: SUNXI Family\n");
95#endif
Ian Campbellcba69ee2014-05-05 11:52:26 +010096 return 0;
97}
98#endif
Hans de Goedecac5b1c2014-11-26 00:04:24 +010099
100int sunxi_get_sid(unsigned int *sid)
101{
Hans de Goedecac5b1c2014-11-26 00:04:24 +0100102#ifdef CONFIG_AXP221_POWER
Hans de Goede6944aff2015-10-03 15:18:33 +0200103 return axp_get_sid(sid);
Hans de Goede813598e2015-05-19 23:34:00 +0200104#elif defined SUNXI_SID_BASE
Hans de Goedecac5b1c2014-11-26 00:04:24 +0100105 int i;
106
107 for (i = 0; i< 4; i++)
108 sid[i] = readl(SUNXI_SID_BASE + 4 * i);
109
110 return 0;
Hans de Goede813598e2015-05-19 23:34:00 +0200111#else
112 return -ENODEV;
Hans de Goedecac5b1c2014-11-26 00:04:24 +0100113#endif
114}