1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2021 Val Packett <[email protected]>
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 const char *desc;
46 } intelspi_acpi_devices[] = {
47 { "80860F0E", SPI_BAYTRAIL, "Intel Bay Trail SPI Controller" },
48 { "8086228E", SPI_BRASWELL, "Intel Braswell SPI Controller" },
49 };
50
51 static char *intelspi_ids[] = { "80860F0E", "8086228E", NULL };
52
53 static int
intelspi_acpi_probe(device_t dev)54 intelspi_acpi_probe(device_t dev)
55 {
56 struct intelspi_softc *sc = device_get_softc(dev);
57 char *hid;
58 int i;
59
60 if (acpi_disabled("spi"))
61 return (ENXIO);
62
63 if (ACPI_ID_PROBE(device_get_parent(dev), dev, intelspi_ids, &hid) > 0)
64 return (ENXIO);
65
66 for (i = 0; i < nitems(intelspi_acpi_devices); i++) {
67 if (strcmp(intelspi_acpi_devices[i].hid, hid) == 0) {
68 sc->sc_vers = intelspi_acpi_devices[i].vers;
69 sc->sc_handle = acpi_get_handle(dev);
70 device_set_desc(dev, intelspi_acpi_devices[i].desc);
71 return (BUS_PROBE_DEFAULT);
72 }
73 }
74
75 return (ENXIO);
76 }
77
78 static int
intelspi_acpi_attach(device_t dev)79 intelspi_acpi_attach(device_t dev)
80 {
81 struct intelspi_softc *sc = device_get_softc(dev);
82
83 sc->sc_mem_rid = 0;
84 sc->sc_irq_rid = 0;
85
86 return (intelspi_attach(dev));
87 }
88
89 static device_method_t intelspi_acpi_methods[] = {
90 /* Device interface */
91 DEVMETHOD(device_probe, intelspi_acpi_probe),
92 DEVMETHOD(device_attach, intelspi_acpi_attach),
93 DEVMETHOD(device_detach, intelspi_detach),
94 DEVMETHOD(device_suspend, intelspi_suspend),
95 DEVMETHOD(device_resume, intelspi_resume),
96
97 /* Bus interface */
98 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
99 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
100 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
101 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
102 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
103 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
104 DEVMETHOD(bus_adjust_resource, bus_generic_adjust_resource),
105
106 /* SPI interface */
107 DEVMETHOD(spibus_transfer, intelspi_transfer),
108
109 DEVMETHOD_END
110 };
111
112 static driver_t intelspi_acpi_driver = {
113 "spi",
114 intelspi_acpi_methods,
115 sizeof(struct intelspi_softc),
116 };
117
118 DRIVER_MODULE(intelspi, acpi, intelspi_acpi_driver, 0, 0);
119 MODULE_DEPEND(intelspi, acpi, 1, 1, 1);
120 MODULE_DEPEND(intelspi, spibus, 1, 1, 1);
121 ACPI_PNP_INFO(intelspi_ids);
122