1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2011
5 * Ben Gray <ben.r.gray@gmail.com>.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/module.h>
34 #include <sys/bus.h>
35 #include <sys/resource.h>
36 #include <sys/rman.h>
37 #include <sys/lock.h>
38 #include <sys/mutex.h>
39
40 #include <machine/bus.h>
41 #include <machine/cpu.h>
42 #include <machine/fdt.h>
43 #include <machine/resource.h>
44 #include <machine/intr.h>
45
46 #include <dev/fdt/simplebus.h>
47 #include <dev/fdt/fdt_common.h>
48 #include <dev/ofw/ofw_bus_subr.h>
49
50 #include <arm/ti/tivar.h>
51 #include <arm/ti/ti_cpuid.h>
52
53 #include <arm/ti/am335x/am335x_reg.h>
54
55 static uint32_t chip_revision = 0xffffffff;
56
57 /**
58 * ti_revision - Returns the revision number of the device
59 *
60 * Simply returns an identifier for the revision of the chip we are running
61 * on.
62 *
63 * RETURNS
64 * A 32-bit identifier for the current chip
65 */
66 uint32_t
ti_revision(void)67 ti_revision(void)
68 {
69 return chip_revision;
70 }
71
72 static void
am335x_get_revision(void)73 am335x_get_revision(void)
74 {
75 uint32_t dev_feature;
76 char cpu_last_char;
77 bus_space_handle_t bsh;
78 int major;
79 int minor;
80
81 bus_space_map(fdtbus_bs_tag, AM335X_CONTROL_BASE, AM335X_CONTROL_SIZE, 0, &bsh);
82 chip_revision = bus_space_read_4(fdtbus_bs_tag, bsh, AM335X_CONTROL_DEVICE_ID);
83 dev_feature = bus_space_read_4(fdtbus_bs_tag, bsh, AM335X_CONTROL_DEV_FEATURE);
84 bus_space_unmap(fdtbus_bs_tag, bsh, AM335X_CONTROL_SIZE);
85
86 switch (dev_feature) {
87 case 0x00FF0382:
88 cpu_last_char='2';
89 break;
90 case 0x20FF0382:
91 cpu_last_char='4';
92 break;
93 case 0x00FF0383:
94 cpu_last_char='6';
95 break;
96 case 0x00FE0383:
97 cpu_last_char='7';
98 break;
99 case 0x20FF0383:
100 cpu_last_char='8';
101 break;
102 case 0x20FE0383:
103 cpu_last_char='9';
104 break;
105 default:
106 cpu_last_char='x';
107 }
108
109 switch(AM335X_DEVREV(chip_revision)) {
110 case 0:
111 major = 1;
112 minor = 0;
113 break;
114 case 1:
115 major = 2;
116 minor = 0;
117 break;
118 case 2:
119 major = 2;
120 minor = 1;
121 break;
122 default:
123 major = 0;
124 minor = AM335X_DEVREV(chip_revision);
125 break;
126 }
127 printf("Texas Instruments AM335%c Processor, Revision ES%u.%u\n",
128 cpu_last_char, major, minor);
129 }
130
131 /**
132 * ti_cpu_ident - attempts to identify the chip we are running on
133 * @dummy: ignored
134 *
135 * This function is called before any of the driver are initialised, however
136 * the basic virt to phys maps have been setup in machdep.c so we can still
137 * access the required registers, we just have to use direct register reads
138 * and writes rather than going through the bus stuff.
139 *
140 *
141 */
142 static void
ti_cpu_ident(void * dummy)143 ti_cpu_ident(void *dummy)
144 {
145 if (!ti_soc_is_supported())
146 return;
147 switch(ti_chip()) {
148 case CHIP_AM335X:
149 am335x_get_revision();
150 break;
151 default:
152 panic("Unknown chip type, fixme!\n");
153 }
154 }
155
156 SYSINIT(ti_cpu_ident, SI_SUB_CPU, SI_ORDER_SECOND, ti_cpu_ident, NULL);
157