xref: /freebsd/sys/dev/intel/spi_acpi.c (revision 66fd12cf4896eb08ad8e7a2627537f84ead84dd3)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2021 Val Packett <val@packett.cool>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #include "opt_acpi.h"
29 
30 #include <sys/cdefs.h>
31 #include <sys/param.h>
32 #include <sys/bus.h>
33 #include <sys/kernel.h>
34 #include <sys/module.h>
35 #include <sys/proc.h>
36 #include <sys/rman.h>
37 
38 #include <dev/intel/spi.h>
39 
40 #include "spibus_if.h"
41 
42 static const struct intelspi_acpi_device {
43 	const char *hid;
44 	enum intelspi_vers vers;
45 } intelspi_acpi_devices[] = {
46 	{ "80860F0E", SPI_BAYTRAIL },
47 	{ "8086228E", SPI_BRASWELL },
48 };
49 
50 static char *intelspi_ids[] = { "80860F0E", "8086228E", NULL };
51 
52 static int
53 intelspi_acpi_probe(device_t dev)
54 {
55 	struct intelspi_softc *sc = device_get_softc(dev);
56 	char *hid;
57 	int i;
58 
59 	if (acpi_disabled("spi"))
60 		return (ENXIO);
61 
62 	if (ACPI_ID_PROBE(device_get_parent(dev), dev, intelspi_ids, &hid) > 0)
63 		return (ENXIO);
64 
65 	for (i = 0; i < nitems(intelspi_acpi_devices); i++) {
66 		if (strcmp(intelspi_acpi_devices[i].hid, hid) == 0) {
67 			sc->sc_vers = intelspi_acpi_devices[i].vers;
68 			sc->sc_handle = acpi_get_handle(dev);
69 			device_set_desc(dev, intelspi_infos[sc->sc_vers].desc);
70 			return (BUS_PROBE_DEFAULT);
71 		}
72 	}
73 
74 	return (ENXIO);
75 }
76 
77 static int
78 intelspi_acpi_attach(device_t dev)
79 {
80 	struct intelspi_softc *sc = device_get_softc(dev);
81 
82 	sc->sc_mem_rid = 0;
83 	sc->sc_irq_rid = 0;
84 
85 	return (intelspi_attach(dev));
86 }
87 
88 static device_method_t intelspi_acpi_methods[] = {
89 	/* Device interface */
90 	DEVMETHOD(device_probe, intelspi_acpi_probe),
91 	DEVMETHOD(device_attach, intelspi_acpi_attach),
92 	DEVMETHOD(device_detach, intelspi_detach),
93 	DEVMETHOD(device_suspend, intelspi_suspend),
94 	DEVMETHOD(device_resume, intelspi_resume),
95 
96 	/* SPI interface */
97 	DEVMETHOD(spibus_transfer, intelspi_transfer),
98 
99 	DEVMETHOD_END
100 };
101 
102 static driver_t intelspi_acpi_driver = {
103 	"spi",
104 	intelspi_acpi_methods,
105 	sizeof(struct intelspi_softc),
106 };
107 
108 DRIVER_MODULE(intelspi, acpi, intelspi_acpi_driver, 0, 0);
109 MODULE_DEPEND(intelspi, acpi, 1, 1, 1);
110 MODULE_DEPEND(intelspi, spibus, 1, 1, 1);
111 ACPI_PNP_INFO(intelspi_ids);
112