cf3c20ae |
1 | /* $OpenBSD: omapid.c,v 1.2 2013/11/06 19:03:07 syl 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/queue.h> |
21 | #include <sys/malloc.h> |
22 | #include <sys/device.h> |
23 | #include <sys/evcount.h> |
24 | #include <sys/socket.h> |
25 | #include <sys/timeout.h> |
26 | #include <machine/intr.h> |
27 | #include <machine/bus.h> |
28 | #include <armv7/armv7/armv7var.h> |
29 | |
30 | /* registers */ |
31 | #define O4_ID_SIZE 0x1000 |
32 | #define O4_FUSE_ID0 0x200 |
33 | #define O4_ID_CODE 0x204 |
34 | #define O4_FUSE_ID1 0x208 |
35 | #define O4_FUSE_ID2 0x20C |
36 | #define O4_FUSE_ID3 0x210 |
37 | #define O4_FUSE_PRODID0 0x214 |
38 | #define O4_FUSE_PRODID1 0x218 |
39 | |
40 | |
41 | struct omapid_softc { |
42 | struct device sc_dev; |
43 | bus_space_tag_t sc_iot; |
44 | bus_space_handle_t sc_ioh; |
45 | }; |
46 | |
47 | struct omapid_softc *omapid_sc; |
48 | |
49 | |
50 | void omapid_attach(struct device *parent, struct device *self, void *args); |
51 | void omapid_wpending(int flags); |
52 | |
53 | struct cfattach omapid_ca = { |
54 | sizeof (struct omapid_softc), NULL, omapid_attach |
55 | }; |
56 | |
57 | struct cfdriver omapid_cd = { |
58 | NULL, "omapid", DV_DULL |
59 | }; |
60 | |
61 | void amptimer_set_clockrate(int32_t new_frequency); /* XXX */ |
62 | |
63 | void |
64 | omapid_attach(struct device *parent, struct device *self, void *args) |
65 | { |
66 | struct armv7_attach_args *aa = args; |
67 | struct omapid_softc *sc = (struct omapid_softc *) self; |
68 | uint32_t rev; |
69 | uint32_t newclockrate = 0; |
70 | char *board; |
71 | |
72 | sc->sc_iot = aa->aa_iot; |
73 | if (bus_space_map(sc->sc_iot, aa->aa_dev->mem[0].addr, |
74 | aa->aa_dev->mem[0].size, 0, &sc->sc_ioh)) |
75 | panic("omapid: bus_space_map failed!"); |
76 | |
77 | omapid_sc = sc; |
78 | |
79 | board = "unknown"; |
80 | switch (board_id) { |
81 | case BOARD_ID_OMAP4_PANDA: |
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 | break; |
95 | default: |
96 | break; |
97 | } |
98 | printf(": %s\n", board); |
99 | if (newclockrate != 0) |
100 | amptimer_set_clockrate(newclockrate); |
101 | } |