aml8726_identsoc.c revision 280905
1/*- 2 * Copyright 2015 John Wehle <john@feith.com> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 */ 27 28/* 29 * Amlogic aml8726 SoC identification. 30 * 31 * The SoC identification is used by some of the drivers in order to 32 * handle hardware differences so the identification needs to happen 33 * early in the boot process (e.g. before SMP startup). 34 * 35 * It's expected that the register addresses for identifying the SoC 36 * are set in stone. 37 * 38 * Currently missing an entry for the aml8726-m and doesn't distinguish 39 * between the m801, m802, m805, s802, s805, and s812 which are all 40 * variations of the aml8726-m8. 41 */ 42 43#include <sys/cdefs.h> 44__FBSDID("$FreeBSD: head/sys/arm/amlogic/aml8726/aml8726_identsoc.c 280905 2015-03-31 11:50:46Z ganbold $"); 45 46#include <sys/param.h> 47#include <sys/systm.h> 48#include <sys/bus.h> 49#include <sys/clock.h> 50#include <sys/kernel.h> 51#include <sys/module.h> 52#include <sys/lock.h> 53#include <sys/mutex.h> 54#include <sys/resource.h> 55#include <sys/rman.h> 56 57#include <machine/bus.h> 58#include <machine/fdt.h> 59 60#include <arm/amlogic/aml8726/aml8726_soc.h> 61 62uint32_t aml8726_soc_hw_rev = 0xffffffff; 63uint32_t aml8726_soc_metal_rev = 0xffffffff; 64 65static const struct { 66 uint32_t hw_rev; 67 char *desc; 68} aml8726_soc_desc[] = { 69 { AML_SOC_HW_REV_M3, "aml8726-m3" }, 70 { AML_SOC_HW_REV_M6, "aml8726-m6" }, 71 { AML_SOC_HW_REV_M6TV, "aml8726-m6tv" }, 72 { AML_SOC_HW_REV_M6TVL, "aml8726-m6tvl" }, 73 { AML_SOC_HW_REV_M8, "aml8726-m8" }, 74 { AML_SOC_HW_REV_M8B, "aml8726-m8b" }, 75 { 0xff, NULL } 76}; 77 78static const struct { 79 uint32_t metal_rev; 80 char *desc; 81} aml8726_m8_soc_rev[] = { 82 { AML_SOC_M8_METAL_REV_A, "A" }, 83 { AML_SOC_M8_METAL_REV_M2_A, "MarkII A" }, 84 { AML_SOC_M8_METAL_REV_B, "B" }, 85 { AML_SOC_M8_METAL_REV_C, "C" }, 86 { 0xff, NULL } 87}; 88 89static void 90aml8726_identify_soc(void *dummy) 91{ 92 int err; 93 int i; 94 struct resource res; 95 96 memset(&res, 0, sizeof(res)); 97 98 res.r_bustag = fdtbus_bs_tag; 99 100 err = bus_space_map(res.r_bustag, AML_SOC_CBUS_BASE_ADDR, 0x100000, 101 0, &res.r_bushandle); 102 103 if (err) 104 panic("Could not allocate resource for SoC identification\n"); 105 106 aml8726_soc_hw_rev = bus_read_4(&res, AML_SOC_HW_REV_REG); 107 108 aml8726_soc_metal_rev = bus_read_4(&res, AML_SOC_METAL_REV_REG); 109 110 bus_space_unmap(res.r_bustag, res.r_bushandle, 0x100000); 111 112 for (i = 0; aml8726_soc_desc[i].desc; i++) 113 if (aml8726_soc_desc[i].hw_rev == aml8726_soc_hw_rev) 114 break; 115 116 if (aml8726_soc_desc[i].desc == NULL) 117 panic("Amlogic unknown aml8726 SoC %#x\n", aml8726_soc_hw_rev); 118 119 printf("Amlogic %s SoC", aml8726_soc_desc[i].desc); 120 121 if (aml8726_soc_hw_rev == AML_SOC_HW_REV_M8) { 122 for (i = 0; aml8726_m8_soc_rev[i].desc; i++) 123 if (aml8726_m8_soc_rev[i].metal_rev == 124 aml8726_soc_metal_rev) 125 break; 126 127 if (aml8726_m8_soc_rev[i].desc == NULL) 128 printf(", unknown rev %#x", aml8726_soc_metal_rev); 129 else 130 printf(", rev %s", aml8726_m8_soc_rev[i].desc); 131 } 132 133 printf("\n"); 134} 135 136SYSINIT(aml8726_identify_soc, SI_SUB_CPU, SI_ORDER_SECOND, 137 aml8726_identify_soc, NULL); 138