1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2024 Pierre-Luc Drouin <pldrouin@pldrouin.net>
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 /*
29  * Vybrid Family Inter-Integrated Circuit (I2C)
30  * Originally based on Chapter 48, Vybrid Reference Manual, Rev. 5, 07/2013
31  * Currently based on Chapter 21, LX2160A Reference Manual, Rev. 1, 10/2021
32  *
33  * The current implementation is based on the original driver by Ruslan Bukin,
34  * later modified by Dawid Górecki, and split into FDT and ACPI drivers by Val
35  * Packett.
36  */
37 
38 #include "opt_acpi.h"
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/bus.h>
43 #include <sys/kernel.h>
44 #include <sys/module.h>
45 #include <sys/rman.h>
46 
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <contrib/dev/acpica/include/accommon.h>
49 
50 #include <dev/acpica/acpivar.h>
51 #include <dev/iicbus/iicbus.h>
52 #include <dev/iicbus/iiconf.h>
53 
54 #include <dev/iicbus/controller/vybrid/vf_i2c.h>
55 
56 static char *vf_i2c_ids[] = {
57 	"NXP0001",
58 	NULL
59 };
60 
61 static int
62 vf_i2c_acpi_probe(device_t dev)
63 {
64 	int rv;
65 
66 	if (acpi_disabled("vf_i2c"))
67 		return (ENXIO);
68 
69 	rv = ACPI_ID_PROBE(device_get_parent(dev), dev, vf_i2c_ids, NULL);
70 	if (rv > 0)
71 		return (rv);
72 
73 	device_set_desc(dev, VF_I2C_DEVSTR);
74 	return (BUS_PROBE_DEFAULT);
75 }
76 
77 static int
78 vf_i2c_acpi_attach(device_t dev)
79 {
80 	struct vf_i2c_softc *sc;
81 
82 	sc = device_get_softc(dev);
83 	sc->dev = dev;
84 	sc->hwtype = HW_VF610;
85 	sc->freq = 0;
86 
87 	return (vf_i2c_attach_common(dev));
88 }
89 
90 static device_method_t vf_i2c_acpi_methods[] = {
91 	/* Device interface */
92 	DEVMETHOD(device_probe,                 vf_i2c_acpi_probe),
93 	DEVMETHOD(device_attach,                vf_i2c_acpi_attach),
94 	DEVMETHOD_END
95 };
96 
97 DEFINE_CLASS_1(vf_i2c_acpi, vf_i2c_acpi_driver, vf_i2c_acpi_methods,
98 		sizeof(struct vf_i2c_softc), vf_i2c_driver);
99 
100 DRIVER_MODULE(vf_i2c_acpi, acpi, vf_i2c_acpi_driver, 0, 0);
101 DRIVER_MODULE(iicbus, vf_i2c_acpi, iicbus_driver, 0, 0);
102 DRIVER_MODULE(acpi_iicbus, vf_i2c_acpi, acpi_iicbus_driver, 0, 0);
103