xref: /openbsd/sys/arch/armv7/omap/omapid.c (revision f6aab3d8)
1 /* $OpenBSD: omapid.c,v 1.5 2021/10/24 17:52:27 mpi Exp $ */
2 /*
3  * Copyright (c) 2013 Dale Rahn <drahn@dalerahn.com>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include <sys/param.h>
19 #include <sys/systm.h>
20 #include <sys/device.h>
21 #include <machine/bus.h>
22 #include <armv7/armv7/armv7var.h>
23 
24 #include <dev/ofw/fdt.h>
25 
26 /* registers */
27 #define O4_ID_SIZE	0x1000
28 #define O4_FUSE_ID0	0x200
29 #define O4_ID_CODE	0x204
30 #define O4_FUSE_ID1	0x208
31 #define O4_FUSE_ID2	0x20C
32 #define O4_FUSE_ID3	0x210
33 #define O4_FUSE_PRODID0	0x214
34 #define O4_FUSE_PRODID1	0x218
35 
36 
37 struct omapid_softc {
38 	struct device		sc_dev;
39 	bus_space_tag_t		sc_iot;
40 	bus_space_handle_t	sc_ioh;
41 };
42 
43 struct omapid_softc *omapid_sc;
44 
45 
46 void omapid_attach(struct device *parent, struct device *self, void *args);
47 void omapid_wpending(int flags);
48 
49 const struct cfattach	omapid_ca = {
50 	sizeof (struct omapid_softc), NULL, omapid_attach
51 };
52 
53 struct cfdriver omapid_cd = {
54 	NULL, "omapid", DV_DULL
55 };
56 
57 void amptimer_set_clockrate(int32_t new_frequency); /* XXX */
58 
59 void
60 omapid_attach(struct device *parent, struct device *self, void *args)
61 {
62 	struct armv7_attach_args *aa = args;
63 	struct omapid_softc *sc = (struct omapid_softc *) self;
64 	uint32_t rev;
65 	uint32_t newclockrate = 0;
66 	char *board;
67 	void *node;
68 
69 	sc->sc_iot = aa->aa_iot;
70 	if (bus_space_map(sc->sc_iot, aa->aa_dev->mem[0].addr,
71 	    aa->aa_dev->mem[0].size, 0, &sc->sc_ioh))
72 		panic("omapid: bus_space_map failed!");
73 
74 	omapid_sc = sc;
75 
76 	node = fdt_find_node("/");
77 	if (node == NULL)
78 		panic("%s: could not get fdt root node",
79 		    sc->sc_dev.dv_xname);
80 
81 	board = "unknown";
82 	if (fdt_is_compatible(node, "ti,omap4")) {
83 		rev = bus_space_read_4(sc->sc_iot, sc->sc_ioh, O4_ID_CODE);
84 		switch ((rev >> 12) & 0xffff) {
85 		case 0xB852:
86 		case 0xB95C:
87 			board = "omap4430";
88 			newclockrate = 400 * 1000 * 1000;
89 			break;
90 		case 0xB94E:
91 			board = "omap4460";
92 			newclockrate = 350 * 1000 * 1000;
93 			break;
94 		}
95 	}
96 	printf(": %s\n", board);
97 	if (newclockrate != 0)
98 		amptimer_set_clockrate(newclockrate);
99 }
100