xref: /openbsd/sys/dev/fdt/ipmi_fdt.c (revision 905646f0)
1 /*	$OpenBSD: ipmi_fdt.c,v 1.1 2020/03/29 09:31:11 kettenis 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 struct cfattach ipmi_fdt_ca = {
34 	sizeof (struct ipmi_softc), ipmi_fdt_match, ipmi_fdt_attach
35 };
36 
37 int
38 ipmi_fdt_match(struct device *parent, void *match, void *aux)
39 {
40 	struct fdt_attach_args *faa = aux;
41 
42 	return OF_is_compatible(faa->fa_node, "ipmi-kcs");
43 }
44 
45 void
46 ipmi_fdt_attach(struct device *parent, struct device *self, void *aux)
47 {
48 	struct ipmi_softc *sc = (struct ipmi_softc *)self;
49 	struct fdt_attach_args *faa = aux;
50 	struct ipmi_attach_args ia;
51 
52 	if (faa->fa_nreg < 1) {
53 		printf(": no registers\n");
54 		return;
55 	}
56 
57 	memset(&ia, 0, sizeof(ia));
58 	ia.iaa_memt = faa->fa_iot;
59 	ia.iaa_if_type = IPMI_IF_KCS;
60 	ia.iaa_if_rev = 0x20;
61 	ia.iaa_if_irq = -1;
62 	ia.iaa_if_irqlvl = 0;
63 	ia.iaa_if_iosize = OF_getpropint(faa->fa_node, "reg-size", 1);
64 	ia.iaa_if_iospacing = OF_getpropint(faa->fa_node, "reg-spacing", 1);
65 	ia.iaa_if_iobase = faa->fa_reg[0].addr;
66 	ia.iaa_if_iotype = 'm';
67 
68 	ipmi_attach_common(sc, &ia);
69 }
70