xref: /openbsd/sys/arch/armv7/omap/omapid.c (revision 9e6efb0a)
1 /* $OpenBSD: omapid.c,v 1.6 2024/05/13 01:15:50 jsg 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 
48 const struct cfattach	omapid_ca = {
49 	sizeof (struct omapid_softc), NULL, omapid_attach
50 };
51 
52 struct cfdriver omapid_cd = {
53 	NULL, "omapid", DV_DULL
54 };
55 
56 void amptimer_set_clockrate(int32_t new_frequency); /* XXX */
57 
58 void
59 omapid_attach(struct device *parent, struct device *self, void *args)
60 {
61 	struct armv7_attach_args *aa = args;
62 	struct omapid_softc *sc = (struct omapid_softc *) self;
63 	uint32_t rev;
64 	uint32_t newclockrate = 0;
65 	char *board;
66 	void *node;
67 
68 	sc->sc_iot = aa->aa_iot;
69 	if (bus_space_map(sc->sc_iot, aa->aa_dev->mem[0].addr,
70 	    aa->aa_dev->mem[0].size, 0, &sc->sc_ioh))
71 		panic("omapid: bus_space_map failed!");
72 
73 	omapid_sc = sc;
74 
75 	node = fdt_find_node("/");
76 	if (node == NULL)
77 		panic("%s: could not get fdt root node",
78 		    sc->sc_dev.dv_xname);
79 
80 	board = "unknown";
81 	if (fdt_is_compatible(node, "ti,omap4")) {
82 		rev = bus_space_read_4(sc->sc_iot, sc->sc_ioh, O4_ID_CODE);
83 		switch ((rev >> 12) & 0xffff) {
84 		case 0xB852:
85 		case 0xB95C:
86 			board = "omap4430";
87 			newclockrate = 400 * 1000 * 1000;
88 			break;
89 		case 0xB94E:
90 			board = "omap4460";
91 			newclockrate = 350 * 1000 * 1000;
92 			break;
93 		}
94 	}
95 	printf(": %s\n", board);
96 	if (newclockrate != 0)
97 		amptimer_set_clockrate(newclockrate);
98 }
99