Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2007-2011 |
| 4 | * Allwinner Technology Co., Ltd. <www.allwinnertech.com> |
| 5 | * Tom Cubie <tangliang@allwinnertech.com> |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 10 | #include <asm/io.h> |
| 11 | #include <asm/arch/cpu.h> |
Hans de Goede | 07be6d6 | 2014-11-15 22:55:53 +0100 | [diff] [blame] | 12 | #include <asm/arch/clock.h> |
Hans de Goede | d9ee84b | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 13 | #include <axp_pmic.h> |
Hans de Goede | 7bfe2bb | 2015-01-13 19:25:06 +0100 | [diff] [blame] | 14 | #include <errno.h> |
Hans de Goede | 07be6d6 | 2014-11-15 22:55:53 +0100 | [diff] [blame] | 15 | |
| 16 | #ifdef CONFIG_MACH_SUN6I |
| 17 | int 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 Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 40 | |
Hans de Goede | b83d933 | 2016-03-24 22:38:23 +0100 | [diff] [blame] | 41 | #ifdef CONFIG_MACH_SUN8I |
| 42 | uint 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 Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 55 | #ifdef CONFIG_DISPLAY_CPUINFO |
| 56 | int print_cpuinfo(void) |
| 57 | { |
Ian Campbell | 8f32aaa | 2014-10-24 21:20:47 +0100 | [diff] [blame] | 58 | #ifdef CONFIG_MACH_SUN4I |
Hans de Goede | 3ab9c23 | 2014-06-09 11:36:57 +0200 | [diff] [blame] | 59 | puts("CPU: Allwinner A10 (SUN4I)\n"); |
Icenowy Zheng | 8f2d1c0 | 2022-01-29 10:23:07 -0500 | [diff] [blame] | 60 | #elif defined CONFIG_MACH_SUNIV |
| 61 | puts("CPU: Allwinner F Series (SUNIV)\n"); |
Ian Campbell | 8f32aaa | 2014-10-24 21:20:47 +0100 | [diff] [blame] | 62 | #elif defined CONFIG_MACH_SUN5I |
Hans de Goede | 8c1c782 | 2014-06-09 11:36:58 +0200 | [diff] [blame] | 63 | u32 val = readl(SUNXI_SID_BASE + 0x08); |
| 64 | switch ((val >> 12) & 0xf) { |
| 65 | case 0: puts("CPU: Allwinner A12 (SUN5I)\n"); break; |
| 66 | case 3: puts("CPU: Allwinner A13 (SUN5I)\n"); break; |
| 67 | case 7: puts("CPU: Allwinner A10s (SUN5I)\n"); break; |
| 68 | default: puts("CPU: Allwinner A1X (SUN5I)\n"); |
| 69 | } |
Ian Campbell | 8f32aaa | 2014-10-24 21:20:47 +0100 | [diff] [blame] | 70 | #elif defined CONFIG_MACH_SUN6I |
Hans de Goede | 07be6d6 | 2014-11-15 22:55:53 +0100 | [diff] [blame] | 71 | switch (sunxi_get_ss_bonding_id()) { |
| 72 | case SUNXI_SS_BOND_ID_A31: |
| 73 | puts("CPU: Allwinner A31 (SUN6I)\n"); |
| 74 | break; |
| 75 | case SUNXI_SS_BOND_ID_A31S: |
| 76 | puts("CPU: Allwinner A31s (SUN6I)\n"); |
| 77 | break; |
| 78 | default: |
| 79 | printf("CPU: Allwinner A31? (SUN6I, id: %d)\n", |
| 80 | sunxi_get_ss_bonding_id()); |
| 81 | } |
Ian Campbell | 8f32aaa | 2014-10-24 21:20:47 +0100 | [diff] [blame] | 82 | #elif defined CONFIG_MACH_SUN7I |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 83 | puts("CPU: Allwinner A20 (SUN7I)\n"); |
Hans de Goede | f055ed6 | 2015-04-06 20:55:39 +0200 | [diff] [blame] | 84 | #elif defined CONFIG_MACH_SUN8I_A23 |
Hans de Goede | b83d933 | 2016-03-24 22:38:23 +0100 | [diff] [blame] | 85 | printf("CPU: Allwinner A23 (SUN8I %04x)\n", sunxi_get_sram_id()); |
Vishnu Patekar | 3702f14 | 2015-03-01 23:47:48 +0530 | [diff] [blame] | 86 | #elif defined CONFIG_MACH_SUN8I_A33 |
Hans de Goede | b83d933 | 2016-03-24 22:38:23 +0100 | [diff] [blame] | 87 | printf("CPU: Allwinner A33 (SUN8I %04x)\n", sunxi_get_sram_id()); |
| 88 | #elif defined CONFIG_MACH_SUN8I_A83T |
| 89 | printf("CPU: Allwinner A83T (SUN8I %04x)\n", sunxi_get_sram_id()); |
Jens Kuske | f977072 | 2015-11-17 15:12:58 +0100 | [diff] [blame] | 90 | #elif defined CONFIG_MACH_SUN8I_H3 |
Hans de Goede | b83d933 | 2016-03-24 22:38:23 +0100 | [diff] [blame] | 91 | printf("CPU: Allwinner H3 (SUN8I %04x)\n", sunxi_get_sram_id()); |
Chen-Yu Tsai | cc2605e | 2016-11-30 14:57:32 +0800 | [diff] [blame] | 92 | #elif defined CONFIG_MACH_SUN8I_R40 |
| 93 | printf("CPU: Allwinner R40 (SUN8I %04x)\n", sunxi_get_sram_id()); |
Icenowy Zheng | 52e6188 | 2017-04-08 15:30:12 +0800 | [diff] [blame] | 94 | #elif defined CONFIG_MACH_SUN8I_V3S |
| 95 | printf("CPU: Allwinner V3s (SUN8I %04x)\n", sunxi_get_sram_id()); |
Andre Przywara | 1987b0c | 2022-09-06 15:59:57 +0100 | [diff] [blame] | 96 | #elif defined CONFIG_MACH_SUN8I_R528 |
| 97 | puts("CPU: Allwinner R528 (SUN8I)\n"); |
Hans de Goede | 7bfe2bb | 2015-01-13 19:25:06 +0100 | [diff] [blame] | 98 | #elif defined CONFIG_MACH_SUN9I |
| 99 | puts("CPU: Allwinner A80 (SUN9I)\n"); |
Siarhei Siamashka | 26c50fb | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 100 | #elif defined CONFIG_MACH_SUN50I |
| 101 | puts("CPU: Allwinner A64 (SUN50I)\n"); |
Andre Przywara | 5611a2d | 2017-02-16 01:20:28 +0000 | [diff] [blame] | 102 | #elif defined CONFIG_MACH_SUN50I_H5 |
| 103 | puts("CPU: Allwinner H5 (SUN50I)\n"); |
Icenowy Zheng | 0c01b96 | 2018-07-21 16:20:31 +0800 | [diff] [blame] | 104 | #elif defined CONFIG_MACH_SUN50I_H6 |
| 105 | puts("CPU: Allwinner H6 (SUN50I)\n"); |
Jernej Skrabec | e638e05 | 2021-01-11 21:11:46 +0100 | [diff] [blame] | 106 | #elif defined CONFIG_MACH_SUN50I_H616 |
| 107 | puts("CPU: Allwinner H616 (SUN50I)\n"); |
Hans de Goede | 3ab9c23 | 2014-06-09 11:36:57 +0200 | [diff] [blame] | 108 | #else |
| 109 | #warning Please update cpu_info.c with correct CPU information |
| 110 | puts("CPU: SUNXI Family\n"); |
| 111 | #endif |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 112 | return 0; |
| 113 | } |
| 114 | #endif |
Hans de Goede | 11d7098 | 2014-11-26 00:04:24 +0100 | [diff] [blame] | 115 | |
Icenowy Zheng | 1c40fed | 2016-12-20 02:03:36 +0800 | [diff] [blame] | 116 | #ifdef CONFIG_MACH_SUN8I_H3 |
| 117 | |
| 118 | #define SIDC_PRCTL 0x40 |
| 119 | #define SIDC_RDKEY 0x60 |
| 120 | |
| 121 | #define SIDC_OP_LOCK 0xAC |
| 122 | |
| 123 | uint32_t sun8i_efuse_read(uint32_t offset) |
| 124 | { |
| 125 | uint32_t reg_val; |
| 126 | |
| 127 | reg_val = readl(SUNXI_SIDC_BASE + SIDC_PRCTL); |
| 128 | reg_val &= ~(((0x1ff) << 16) | 0x3); |
| 129 | reg_val |= (offset << 16); |
| 130 | writel(reg_val, SUNXI_SIDC_BASE + SIDC_PRCTL); |
| 131 | |
| 132 | reg_val &= ~(((0xff) << 8) | 0x3); |
| 133 | reg_val |= (SIDC_OP_LOCK << 8) | 0x2; |
| 134 | writel(reg_val, SUNXI_SIDC_BASE + SIDC_PRCTL); |
| 135 | |
| 136 | while (readl(SUNXI_SIDC_BASE + SIDC_PRCTL) & 0x2); |
| 137 | |
| 138 | reg_val &= ~(((0x1ff) << 16) | ((0xff) << 8) | 0x3); |
| 139 | writel(reg_val, SUNXI_SIDC_BASE + SIDC_PRCTL); |
| 140 | |
| 141 | reg_val = readl(SUNXI_SIDC_BASE + SIDC_RDKEY); |
| 142 | return reg_val; |
| 143 | } |
| 144 | #endif |
| 145 | |
Hans de Goede | 11d7098 | 2014-11-26 00:04:24 +0100 | [diff] [blame] | 146 | int sunxi_get_sid(unsigned int *sid) |
| 147 | { |
Hans de Goede | 11d7098 | 2014-11-26 00:04:24 +0100 | [diff] [blame] | 148 | #ifdef CONFIG_AXP221_POWER |
Hans de Goede | d9ee84b | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 149 | return axp_get_sid(sid); |
Icenowy Zheng | 1c40fed | 2016-12-20 02:03:36 +0800 | [diff] [blame] | 150 | #elif defined CONFIG_MACH_SUN8I_H3 |
| 151 | /* |
| 152 | * H3 SID controller has a bug, which makes the initial value of |
| 153 | * SUNXI_SID_BASE at boot wrong. |
| 154 | * Read the value directly from SID controller, in order to get |
| 155 | * the correct value, and also refresh the wrong value at |
| 156 | * SUNXI_SID_BASE. |
| 157 | */ |
| 158 | int i; |
| 159 | |
| 160 | for (i = 0; i< 4; i++) |
| 161 | sid[i] = sun8i_efuse_read(i * 4); |
| 162 | |
| 163 | return 0; |
Hans de Goede | 0d70914 | 2015-05-19 23:34:00 +0200 | [diff] [blame] | 164 | #elif defined SUNXI_SID_BASE |
Hans de Goede | 11d7098 | 2014-11-26 00:04:24 +0100 | [diff] [blame] | 165 | int i; |
| 166 | |
| 167 | for (i = 0; i< 4; i++) |
Alexander Graf | ee1d825 | 2016-03-29 17:29:09 +0200 | [diff] [blame] | 168 | sid[i] = readl((ulong)SUNXI_SID_BASE + 4 * i); |
Hans de Goede | 11d7098 | 2014-11-26 00:04:24 +0100 | [diff] [blame] | 169 | |
| 170 | return 0; |
Hans de Goede | 0d70914 | 2015-05-19 23:34:00 +0200 | [diff] [blame] | 171 | #else |
| 172 | return -ENODEV; |
Hans de Goede | 11d7098 | 2014-11-26 00:04:24 +0100 | [diff] [blame] | 173 | #endif |
| 174 | } |