xref: /openbsd/sys/dev/acpi/ccp_acpi.c (revision 4bdff4be)
1 /*	$OpenBSD: ccp_acpi.c,v 1.4 2022/04/06 18:59:27 naddy Exp $	*/
2 /*
3  * Copyright (c) 2019 Mark Kettenis
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 
21 #include <dev/acpi/acpireg.h>
22 #include <dev/acpi/acpivar.h>
23 #include <dev/acpi/acpidev.h>
24 #include <dev/acpi/amltypes.h>
25 #include <dev/acpi/dsdt.h>
26 
27 #include <dev/ic/ccpvar.h>
28 
29 struct ccp_acpi_softc {
30 	struct ccp_softc sc;
31 	struct acpi_softc *sc_acpi;
32 	struct aml_node *sc_node;
33 };
34 
35 int	ccp_acpi_match(struct device *, void *, void *);
36 void	ccp_acpi_attach(struct device *, struct device *, void *);
37 
38 const struct cfattach ccp_acpi_ca = {
39 	sizeof(struct ccp_acpi_softc), ccp_acpi_match, ccp_acpi_attach
40 };
41 
42 const char *ccp_hids[] = {
43 	"AMDI0C00",
44 	NULL
45 };
46 
47 int
48 ccp_acpi_match(struct device *parent, void *match, void *aux)
49 {
50 	struct acpi_attach_args *aaa = aux;
51 	struct cfdata *cf = match;
52 
53 	if (aaa->aaa_naddr < 1)
54 		return 0;
55 	return acpi_matchhids(aaa, ccp_hids, cf->cf_driver->cd_name);
56 }
57 
58 void
59 ccp_acpi_attach(struct device *parent, struct device *self, void *aux)
60 {
61 	struct ccp_acpi_softc *sc = (struct ccp_acpi_softc *)self;
62 	struct acpi_attach_args *aaa = aux;
63 
64 	sc->sc_acpi = (struct acpi_softc *)parent;
65 	sc->sc_node = aaa->aaa_node;
66 	printf(" %s", sc->sc_node->name);
67 
68 	printf(" addr 0x%llx/0x%llx", aaa->aaa_addr[0], aaa->aaa_size[0]);
69 
70 	sc->sc.sc_iot = aaa->aaa_bst[0];
71 	if (bus_space_map(sc->sc.sc_iot, aaa->aaa_addr[0], aaa->aaa_size[0],
72 	    0, &sc->sc.sc_ioh)) {
73 		printf(": can't map registers\n");
74 		return;
75 	}
76 
77 	ccp_attach(&sc->sc);
78 }
79