1 /* $OpenBSD: ipmi_fdt.c,v 1.3 2024/10/09 00:38:26 jsg Exp $ */
2 /*
3 * Copyright (c) 2020 Mark Kettenis <kettenis@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/param.h>
19 #include <sys/systm.h>
20 #include <sys/device.h>
21
22 #include <machine/bus.h>
23 #include <machine/fdt.h>
24
25 #include <dev/ofw/openfirm.h>
26 #include <dev/ofw/fdt.h>
27
28 #include <dev/ipmivar.h>
29
30 int ipmi_fdt_match(struct device *, void *, void *);
31 void ipmi_fdt_attach(struct device *, struct device *, void *);
32
33 const struct cfattach ipmi_fdt_ca = {
34 sizeof (struct ipmi_softc), ipmi_fdt_match, ipmi_fdt_attach,
35 NULL, ipmi_activate
36 };
37
38 int
ipmi_fdt_match(struct device * parent,void * match,void * aux)39 ipmi_fdt_match(struct device *parent, void *match, void *aux)
40 {
41 struct fdt_attach_args *faa = aux;
42
43 return OF_is_compatible(faa->fa_node, "ipmi-kcs");
44 }
45
46 void
ipmi_fdt_attach(struct device * parent,struct device * self,void * aux)47 ipmi_fdt_attach(struct device *parent, struct device *self, void *aux)
48 {
49 struct ipmi_softc *sc = (struct ipmi_softc *)self;
50 struct fdt_attach_args *faa = aux;
51 struct ipmi_attach_args ia;
52
53 if (faa->fa_nreg < 1) {
54 printf(": no registers\n");
55 return;
56 }
57
58 memset(&ia, 0, sizeof(ia));
59 ia.iaa_memt = faa->fa_iot;
60 ia.iaa_if_type = IPMI_IF_KCS;
61 ia.iaa_if_rev = 0x20;
62 ia.iaa_if_irq = -1;
63 ia.iaa_if_irqlvl = 0;
64 ia.iaa_if_iosize = OF_getpropint(faa->fa_node, "reg-size", 1);
65 ia.iaa_if_iospacing = OF_getpropint(faa->fa_node, "reg-spacing", 1);
66 ia.iaa_if_iobase = faa->fa_reg[0].addr;
67 ia.iaa_if_iotype = 'm';
68
69 ipmi_attach_common(sc, &ia);
70 }
71