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