/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 20114* Ben Gray <[email protected]>.5* All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829#include <sys/param.h>30#include <sys/systm.h>31#include <sys/kernel.h>32#include <sys/module.h>33#include <sys/bus.h>34#include <sys/resource.h>35#include <sys/rman.h>36#include <sys/lock.h>37#include <sys/mutex.h>3839#include <machine/bus.h>40#include <machine/cpu.h>41#include <machine/fdt.h>42#include <machine/resource.h>43#include <machine/intr.h>4445#include <dev/fdt/simplebus.h>46#include <dev/fdt/fdt_common.h>47#include <dev/ofw/ofw_bus_subr.h>4849#include <arm/ti/tivar.h>50#include <arm/ti/ti_cpuid.h>5152#include <arm/ti/am335x/am335x_reg.h>5354static uint32_t chip_revision = 0xffffffff;5556/**57* ti_revision - Returns the revision number of the device58*59* Simply returns an identifier for the revision of the chip we are running60* on.61*62* RETURNS63* A 32-bit identifier for the current chip64*/65uint32_t66ti_revision(void)67{68return chip_revision;69}7071static void72am335x_get_revision(void)73{74uint32_t dev_feature;75char cpu_last_char;76bus_space_handle_t bsh;77int major;78int minor;7980bus_space_map(fdtbus_bs_tag, AM335X_CONTROL_BASE, AM335X_CONTROL_SIZE, 0, &bsh);81chip_revision = bus_space_read_4(fdtbus_bs_tag, bsh, AM335X_CONTROL_DEVICE_ID);82dev_feature = bus_space_read_4(fdtbus_bs_tag, bsh, AM335X_CONTROL_DEV_FEATURE);83bus_space_unmap(fdtbus_bs_tag, bsh, AM335X_CONTROL_SIZE);8485switch (dev_feature) {86case 0x00FF0382:87cpu_last_char='2';88break;89case 0x20FF0382:90cpu_last_char='4';91break;92case 0x00FF0383:93cpu_last_char='6';94break;95case 0x00FE0383:96cpu_last_char='7';97break;98case 0x20FF0383:99cpu_last_char='8';100break;101case 0x20FE0383:102cpu_last_char='9';103break;104default:105cpu_last_char='x';106}107108switch(AM335X_DEVREV(chip_revision)) {109case 0:110major = 1;111minor = 0;112break;113case 1:114major = 2;115minor = 0;116break;117case 2:118major = 2;119minor = 1;120break;121default:122major = 0;123minor = AM335X_DEVREV(chip_revision);124break;125}126printf("Texas Instruments AM335%c Processor, Revision ES%u.%u\n",127cpu_last_char, major, minor);128}129130/**131* ti_cpu_ident - attempts to identify the chip we are running on132* @dummy: ignored133*134* This function is called before any of the driver are initialised, however135* the basic virt to phys maps have been setup in machdep.c so we can still136* access the required registers, we just have to use direct register reads137* and writes rather than going through the bus stuff.138*139*140*/141static void142ti_cpu_ident(void *dummy)143{144if (!ti_soc_is_supported())145return;146switch(ti_chip()) {147case CHIP_AM335X:148am335x_get_revision();149break;150default:151panic("Unknown chip type, fixme!\n");152}153}154155SYSINIT(ti_cpu_ident, SI_SUB_CPU, SI_ORDER_SECOND, ti_cpu_ident, NULL);156157158