2 * Copyright (c) 2016 Oleksandr Tymoshenko <gonzo@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
34 #include <sys/kernel.h>
35 #include <sys/module.h>
39 #include <machine/bus.h>
40 #include <machine/resource.h>
42 #include <contrib/dev/acpica/include/acpi.h>
43 #include <contrib/dev/acpica/include/accommon.h>
45 #include <dev/acpica/acpivar.h>
46 #include <dev/iicbus/iiconf.h>
48 #include <dev/ichiic/ig4_reg.h>
49 #include <dev/ichiic/ig4_var.h>
51 static int ig4iic_acpi_probe(device_t dev);
52 static int ig4iic_acpi_attach(device_t dev);
53 static int ig4iic_acpi_detach(device_t dev);
55 static char *ig4iic_ids[] = {
69 ig4iic_acpi_probe(device_t dev)
75 sc = device_get_softc(dev);
76 if (acpi_disabled("ig4iic"))
78 rv = ACPI_ID_PROBE(device_get_parent(dev), dev, ig4iic_ids, &hid);
82 if (strcmp("AMDI0010", hid) == 0)
83 sc->access_intr_mask = 1;
84 device_set_desc(dev, "Designware I2C Controller");
89 ig4iic_acpi_attach(device_t dev)
94 sc = device_get_softc(dev);
97 /* All the HIDs matched are Atom SOCs. */
98 sc->version = IG4_ATOM;
100 sc->regs_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
101 &sc->regs_rid, RF_ACTIVE);
102 if (sc->regs_res == NULL) {
103 device_printf(dev, "unable to map registers\n");
104 ig4iic_acpi_detach(dev);
108 sc->intr_res = bus_alloc_resource_any(dev, SYS_RES_IRQ,
109 &sc->intr_rid, RF_SHAREABLE | RF_ACTIVE);
110 if (sc->intr_res == NULL) {
111 device_printf(dev, "unable to map interrupt\n");
112 ig4iic_acpi_detach(dev);
115 sc->platform_attached = 1;
117 error = ig4iic_attach(sc);
119 ig4iic_acpi_detach(dev);
125 ig4iic_acpi_detach(device_t dev)
127 ig4iic_softc_t *sc = device_get_softc(dev);
130 if (sc->platform_attached) {
131 error = ig4iic_detach(sc);
134 sc->platform_attached = 0;
138 bus_release_resource(dev, SYS_RES_IRQ,
139 sc->intr_rid, sc->intr_res);
143 bus_release_resource(dev, SYS_RES_MEMORY,
144 sc->regs_rid, sc->regs_res);
151 static device_method_t ig4iic_acpi_methods[] = {
152 /* Device interface */
153 DEVMETHOD(device_probe, ig4iic_acpi_probe),
154 DEVMETHOD(device_attach, ig4iic_acpi_attach),
155 DEVMETHOD(device_detach, ig4iic_acpi_detach),
157 /* iicbus interface */
158 DEVMETHOD(iicbus_transfer, ig4iic_transfer),
159 DEVMETHOD(iicbus_reset, ig4iic_reset),
160 DEVMETHOD(iicbus_callback, iicbus_null_callback),
165 static driver_t ig4iic_acpi_driver = {
168 sizeof(struct ig4iic_softc),
171 static devclass_t ig4iic_acpi_devclass;
172 DRIVER_MODULE(ig4iic_acpi, acpi, ig4iic_acpi_driver, ig4iic_acpi_devclass, 0, 0);
174 MODULE_DEPEND(ig4iic_acpi, acpi, 1, 1, 1);
175 MODULE_DEPEND(ig4iic_acpi, pci, 1, 1, 1);
176 MODULE_DEPEND(ig4iic_acpi, iicbus, IICBUS_MINVER, IICBUS_PREFVER, IICBUS_MAXVER);
177 MODULE_VERSION(ig4iic_acpi, 1);