1 /* $OpenBSD: ccp_fdt.c,v 1.2 2021/10/24 17:52:26 mpi Exp $ */
2 /*
3 * Copyright (c) 2018 David Gwynne <dlg@openbsd.org>
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/types.h>
19 #include <sys/systm.h>
20 #include <sys/device.h>
21 #include <sys/malloc.h>
22
23 #include <machine/bus.h>
24 #include <machine/fdt.h>
25
26 #include <dev/ofw/openfirm.h>
27 #include <dev/ofw/ofw_misc.h>
28 #include <dev/ofw/ofw_regulator.h>
29 #include <dev/ofw/fdt.h>
30
31 #include <dev/ic/ccpvar.h>
32
33 static int ccp_fdt_match(struct device *, void *, void *);
34 static void ccp_fdt_attach(struct device *, struct device *, void *);
35
36 const struct cfattach ccp_fdt_ca = {
37 sizeof(struct ccp_softc),
38 ccp_fdt_match,
39 ccp_fdt_attach
40 };
41
42 static int
ccp_fdt_match(struct device * parent,void * match,void * aux)43 ccp_fdt_match(struct device *parent, void *match, void *aux)
44 {
45 struct fdt_attach_args *faa = aux;
46
47 return OF_is_compatible(faa->fa_node, "amd,ccp-seattle-v1a");
48 }
49
50 static void
ccp_fdt_attach(struct device * parent,struct device * self,void * aux)51 ccp_fdt_attach(struct device *parent, struct device *self, void *aux)
52 {
53 struct ccp_softc *sc = (struct ccp_softc *)self;
54 struct fdt_attach_args *faa = aux;
55
56 if (faa->fa_nreg < 1) {
57 printf(": no registers\n");
58 return;
59 }
60
61 sc->sc_iot = faa->fa_iot;
62
63 if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr,
64 faa->fa_reg[0].size, 0, &sc->sc_ioh)) {
65 printf(": cannot map registers\n");
66 return;
67 }
68
69 ccp_attach(sc);
70 }
71