1 /* $OpenBSD: omapid.c,v 1.3 2016/10/08 05:55:03 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/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 #include <dev/ofw/fdt.h> 31 32 /* registers */ 33 #define O4_ID_SIZE 0x1000 34 #define O4_FUSE_ID0 0x200 35 #define O4_ID_CODE 0x204 36 #define O4_FUSE_ID1 0x208 37 #define O4_FUSE_ID2 0x20C 38 #define O4_FUSE_ID3 0x210 39 #define O4_FUSE_PRODID0 0x214 40 #define O4_FUSE_PRODID1 0x218 41 42 43 struct omapid_softc { 44 struct device sc_dev; 45 bus_space_tag_t sc_iot; 46 bus_space_handle_t sc_ioh; 47 }; 48 49 struct omapid_softc *omapid_sc; 50 51 52 void omapid_attach(struct device *parent, struct device *self, void *args); 53 void omapid_wpending(int flags); 54 55 struct cfattach omapid_ca = { 56 sizeof (struct omapid_softc), NULL, omapid_attach 57 }; 58 59 struct cfdriver omapid_cd = { 60 NULL, "omapid", DV_DULL 61 }; 62 63 void amptimer_set_clockrate(int32_t new_frequency); /* XXX */ 64 65 void 66 omapid_attach(struct device *parent, struct device *self, void *args) 67 { 68 struct armv7_attach_args *aa = args; 69 struct omapid_softc *sc = (struct omapid_softc *) self; 70 uint32_t rev; 71 uint32_t newclockrate = 0; 72 char *board; 73 void *node; 74 75 sc->sc_iot = aa->aa_iot; 76 if (bus_space_map(sc->sc_iot, aa->aa_dev->mem[0].addr, 77 aa->aa_dev->mem[0].size, 0, &sc->sc_ioh)) 78 panic("omapid: bus_space_map failed!"); 79 80 omapid_sc = sc; 81 82 node = fdt_find_node("/"); 83 if (node == NULL) 84 panic("%s: could not get fdt root node", 85 sc->sc_dev.dv_xname); 86 87 board = "unknown"; 88 if (fdt_is_compatible(node, "ti,omap4")) { 89 rev = bus_space_read_4(sc->sc_iot, sc->sc_ioh, O4_ID_CODE); 90 switch ((rev >> 12) & 0xffff) { 91 case 0xB852: 92 case 0xB95C: 93 board = "omap4430"; 94 newclockrate = 400 * 1000 * 1000; 95 break; 96 case 0xB94E: 97 board = "omap4460"; 98 newclockrate = 350 * 1000 * 1000; 99 break; 100 } 101 } 102 printf(": %s\n", board); 103 if (newclockrate != 0) 104 amptimer_set_clockrate(newclockrate); 105 } 106