^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2007-2009 PetaLogix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2007 John Williams <john.williams@petalogix.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * License. See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/cpuinfo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/pvr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) const struct cpu_ver_key cpu_ver_lookup[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /* These key value are as per MBV field in PVR0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) {"5.00.a", 0x01},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) {"5.00.b", 0x02},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) {"5.00.c", 0x03},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) {"6.00.a", 0x04},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {"6.00.b", 0x06},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {"7.00.a", 0x05},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {"7.00.b", 0x07},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {"7.10.a", 0x08},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {"7.10.b", 0x09},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {"7.10.c", 0x0a},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {"7.10.d", 0x0b},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) {"7.20.a", 0x0c},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {"7.20.b", 0x0d},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {"7.20.c", 0x0e},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {"7.20.d", 0x0f},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {"7.30.a", 0x10},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {"7.30.b", 0x11},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {"8.00.a", 0x12},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {"8.00.b", 0x13},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {"8.10.a", 0x14},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {"8.20.a", 0x15},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {"8.20.b", 0x16},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {"8.30.a", 0x17},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {"8.40.a", 0x18},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {"8.40.b", 0x19},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {"8.50.a", 0x1a},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {"8.50.b", 0x1c},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {"8.50.c", 0x1e},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {"9.0", 0x1b},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {"9.1", 0x1d},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {"9.2", 0x1f},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {"9.3", 0x20},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {"9.4", 0x21},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {"9.5", 0x22},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {"9.6", 0x23},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {"10.0", 0x24},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {"11.0", 0x25},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {NULL, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * FIXME Not sure if the actual key is defined by Xilinx in the PVR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) const struct family_string_key family_string_lookup[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {"virtex2", 0x4},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {"virtex2pro", 0x5},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {"spartan3", 0x6},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {"virtex4", 0x7},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {"virtex5", 0x8},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {"spartan3e", 0x9},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {"spartan3a", 0xa},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {"spartan3an", 0xb},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {"spartan3adsp", 0xc},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {"spartan6", 0xd},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {"virtex6", 0xe},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) {"virtex7", 0xf},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* FIXME There is no key code defined for spartan2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {"spartan2", 0xf0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {"kintex7", 0x10},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {"artix7", 0x11},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {"zynq7000", 0x12},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {"UltraScale Virtex", 0x13},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {"UltraScale Kintex", 0x14},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {"UltraScale+ Zynq", 0x15},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {"UltraScale+ Virtex", 0x16},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {"UltraScale+ Kintex", 0x17},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {"Spartan7", 0x18},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {NULL, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct cpuinfo cpuinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static struct device_node *cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) void __init setup_cpuinfo(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) cpu = of_get_cpu_node(0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (!cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) pr_err("You don't have cpu or are missing cpu reg property!!!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) pr_info("%s: initialising\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) switch (cpu_has_pvr()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) pr_warn("%s: No PVR support. Using static CPU info from FDT\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) set_cpuinfo_static(&cpuinfo, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* FIXME I found weird behavior with MB 7.00.a/b 7.10.a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * please do not use FULL PVR with MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) pr_info("%s: Using full CPU PVR support\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) set_cpuinfo_static(&cpuinfo, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) set_cpuinfo_pvr_full(&cpuinfo, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) pr_warn("%s: Unsupported PVR setting\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) set_cpuinfo_static(&cpuinfo, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (cpuinfo.mmu_privins)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) pr_warn("%s: Stream instructions enabled"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) " - USERSPACE CAN LOCK THIS KERNEL!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) of_node_put(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) void __init setup_cpuinfo_clk(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct clk *clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) clk = of_clk_get(cpu, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (IS_ERR(clk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) pr_err("ERROR: CPU CCF input clock not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /* take timebase-frequency from DTS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) cpuinfo.cpu_clock_freq = fcpu(cpu, "timebase-frequency");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) cpuinfo.cpu_clock_freq = clk_get_rate(clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (!cpuinfo.cpu_clock_freq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) pr_err("ERROR: CPU clock frequency not setup\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }