diff --git a/sys/arm/freescale/vybrid/files.vybrid b/sys/arm/freescale/vybrid/files.vybrid
--- a/sys/arm/freescale/vybrid/files.vybrid
+++ b/sys/arm/freescale/vybrid/files.vybrid
@@ -9,7 +9,6 @@
arm/freescale/vybrid/vf_dmamux.c standard
arm/freescale/vybrid/vf_port.c standard
arm/freescale/vybrid/vf_adc.c standard
-arm/freescale/vybrid/vf_i2c.c optional iicbus
arm/freescale/vybrid/vf_tcon.c optional vt
arm/freescale/vybrid/vf_dcu4.c optional vt
arm/freescale/vybrid/vf_nfc.c optional nand
diff --git a/sys/arm64/conf/std.imx b/sys/arm64/conf/std.imx
--- a/sys/arm64/conf/std.imx
+++ b/sys/arm64/conf/std.imx
@@ -7,6 +7,8 @@
# I2C
device vf_i2c # Freescale Vybrid I2C controller
+device vf_i2c_fdt # Freescale Vybrid I2C controller
+device vf_i2c_acpi # Freescale Vybrid I2C controller
device fsliic # Freescale iMX I2C controller
# Serial (COM) ports
diff --git a/sys/conf/files.arm64 b/sys/conf/files.arm64
--- a/sys/conf/files.arm64
+++ b/sys/conf/files.arm64
@@ -629,7 +629,9 @@
clean "tegra210_xusb.fw"
# NXP
-arm/freescale/vybrid/vf_i2c.c optional vf_i2c iicbus soc_nxp_ls
+dev/iicbus/controller/qoriq/vf_i2c.c optional vf_i2c iicbus soc_nxp_ls
+dev/iicbus/controller/qoriq/vf_i2c_acpi.c optional vf_i2c_acpi iicbus acpi soc_nxp_ls
+dev/iicbus/controller/qoriq/vf_i2c_fdt.c optional vf_i2c_fdt iicbus fdt soc_nxp_ls
arm64/qoriq/qoriq_dw_pci.c optional pci fdt soc_nxp_ls
arm64/qoriq/qoriq_gpio_pic.c optional gpio fdt soc_nxp_ls
arm64/qoriq/qoriq_therm.c optional pci fdt soc_nxp_ls
diff --git a/sys/dev/iicbus/controller/qoriq/vf_i2c.h b/sys/dev/iicbus/controller/qoriq/vf_i2c.h
new file mode 100644
--- /dev/null
+++ b/sys/dev/iicbus/controller/qoriq/vf_i2c.h
@@ -0,0 +1,60 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2014 Ruslan Bukin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Vybrid Family Inter-Integrated Circuit (I2C)
+ * Chapter 21, LX2160A Reference Manual, Rev. 1, 10/2021
+ */
+
+#ifndef __VF_I2C_H__
+#define __VF_I2C_H__
+
+#include
+
+#define VF_I2C_DEVSTR "Vybrid Family Inter-Integrated Circuit (I2C)"
+
+#define HW_MVF600 0x01
+#define HW_VF610 0x02
+
+struct i2c_softc {
+ struct resource *res[2];
+ bus_space_tag_t bst;
+ bus_space_handle_t bsh;
+ clk_t clock;
+ uint32_t freq;
+ device_t dev;
+ device_t iicbus;
+ struct mtx mutex;
+ uintptr_t hwtype;
+};
+
+extern driver_t vf_i2c_driver;
+
+device_attach_t vf_i2c_attach_common;
+
+#endif /* !__VF_I2C_H__ */
diff --git a/sys/arm/freescale/vybrid/vf_i2c.c b/sys/dev/iicbus/controller/qoriq/vf_i2c.c
rename from sys/arm/freescale/vybrid/vf_i2c.c
rename to sys/dev/iicbus/controller/qoriq/vf_i2c.c
--- a/sys/arm/freescale/vybrid/vf_i2c.c
+++ b/sys/dev/iicbus/controller/qoriq/vf_i2c.c
@@ -28,11 +28,7 @@
/*
* Vybrid Family Inter-Integrated Circuit (I2C)
- * Chapter 48, Vybrid Reference Manual, Rev. 5, 07/2013
- */
-
-/*
- * This driver is based on the I2C driver for i.MX
+ * Chapter 21, LX2160A Reference Manual, Rev. 1, 10/2021
*/
#include
@@ -51,17 +47,14 @@
#include "iicbus_if.h"
-#include
-#include
-#include
-
-#include
-
#include
#include
#include
-#include
+#include
+
+#define READ1(_sc, _reg) bus_space_read_1(_sc->bst, _sc->bsh, _reg)
+#define WRITE1(_sc, _reg, _val) bus_space_write_1(_sc->bst, _sc->bsh, _reg, _val)
#define I2C_IBAD 0x0 /* I2C Bus Address Register */
#define I2C_IBFD 0x1 /* I2C Bus Frequency Divider Register */
@@ -89,39 +82,28 @@
#ifdef DEBUG
#define vf_i2c_dbg(_sc, fmt, args...) \
device_printf((_sc)->dev, fmt, ##args)
+#ifdef DEBUG2
+#undef WRITE1
+#define WRITE1(_sc, _reg, _val) ({vf_i2c_dbg(_sc, "WRITE1 REG 0x%02X VAL 0x%02X\n",_reg,_val); bus_space_write_1(_sc->bst, _sc->bsh, _reg, _val);})
+#undef READ1
+#define READ1(_sc, _reg) ({uint32_t ret=bus_space_read_1(_sc->bst, _sc->bsh, _reg); vf_i2c_dbg(_sc, "READ1 REG 0x%02X RETURNS 0x%02X\n",_reg,ret); ret;})
+#endif
#else
#define vf_i2c_dbg(_sc, fmt, args...)
#endif
-#define HW_UNKNOWN 0x00
-#define HW_MVF600 0x01
-#define HW_VF610 0x02
-
static int i2c_repeated_start(device_t, u_char, int);
static int i2c_start(device_t, u_char, int);
static int i2c_stop(device_t);
static int i2c_reset(device_t, u_char, u_char, u_char *);
static int i2c_read(device_t, char *, int, int *, int, int);
static int i2c_write(device_t, const char *, int, int *, int);
-static phandle_t i2c_get_node(device_t, device_t);
struct i2c_div_type {
uint32_t reg_val;
uint32_t div;
};
-struct i2c_softc {
- struct resource *res[2];
- bus_space_tag_t bst;
- bus_space_handle_t bsh;
- clk_t clock;
- uint32_t freq;
- device_t dev;
- device_t iicbus;
- struct mtx mutex;
- uintptr_t hwtype;
-};
-
static struct resource_spec i2c_spec[] = {
{ SYS_RES_MEMORY, 0, RF_ACTIVE },
{ SYS_RES_IRQ, 0, RF_ACTIVE },
@@ -144,49 +126,12 @@
{ 0x3F, 3840 }, { 0x7B, 4096 }, { 0x7D, 5120 }, { 0x7E, 6144 },
};
-static const struct ofw_compat_data i2c_compat_data[] = {
- {"fsl,mvf600-i2c", HW_MVF600},
- {"fsl,vf610-i2c", HW_VF610},
- {NULL, HW_UNKNOWN}
-};
-
-static int
-i2c_probe(device_t dev)
+int
+vf_i2c_attach_common(device_t dev)
{
-
- if (!ofw_bus_status_okay(dev))
- return (ENXIO);
-
- if (!ofw_bus_search_compatible(dev, i2c_compat_data)->ocd_data)
- return (ENXIO);
-
- device_set_desc(dev, "Vybrid Family Inter-Integrated Circuit (I2C)");
- return (BUS_PROBE_DEFAULT);
-}
-
-static int
-i2c_attach(device_t dev)
-{
- struct i2c_softc *sc;
- phandle_t node;
+ struct i2c_softc *sc = device_get_softc(dev);
int error;
-
- sc = device_get_softc(dev);
- sc->dev = dev;
- sc->hwtype = ofw_bus_search_compatible(dev, i2c_compat_data)->ocd_data;
- node = ofw_bus_get_node(dev);
-
- error = clk_get_by_ofw_index(dev, node, 0, &sc->clock);
- if (error != 0) {
- sc->freq = 0;
- device_printf(dev, "Parent clock not found.\n");
- } else {
- if (OF_hasprop(node, "clock-frequency"))
- OF_getencprop(node, "clock-frequency", &sc->freq,
- sizeof(sc->freq));
- else
- sc->freq = 100000;
- }
+ vf_i2c_dbg(sc, "i2c attach common\n");
mtx_init(&sc->mutex, device_get_nameunit(dev), "I2C", MTX_DEF);
@@ -213,6 +158,16 @@
bus_generic_attach(dev);
+ if(sc->freq == 0) {
+ const uint8_t div_reg=READ1(sc, I2C_IBFD);
+
+ if(div_reg != 0x00) {
+ sc->freq = UINT32_MAX;
+ device_printf(dev, "Using existing bus frequency divider register value (0x%02X).\n", div_reg);
+
+ } else device_printf(dev, "Bus frequency divider value appears unset, defaulting to low I2C bus speed.\n");
+ }
+
return (0);
}
@@ -223,6 +178,9 @@
int error = 0;
sc = device_get_softc(dev);
+ vf_i2c_dbg(sc, "i2c detach\n");
+
+ if(sc->freq == 0) WRITE1(sc, I2C_IBFD, 0x00);
error = bus_generic_detach(dev);
if (error != 0) {
@@ -243,24 +201,6 @@
return (0);
}
-/* Wait for transfer interrupt flag */
-static int
-wait_for_iif(struct i2c_softc *sc)
-{
- int retry;
-
- retry = 1000;
- while (retry --) {
- if (READ1(sc, I2C_IBSR) & IBSR_IBIF) {
- WRITE1(sc, I2C_IBSR, IBSR_IBIF);
- return (IIC_NOERR);
- }
- DELAY(10);
- }
-
- return (IIC_ETIMEOUT);
-}
-
/* Wait for free bus */
static int
wait_for_nibb(struct i2c_softc *sc)
@@ -282,14 +222,22 @@
wait_for_icf(struct i2c_softc *sc)
{
int retry;
+ uint8_t ibsr;
+ vf_i2c_dbg(sc, "i2c wait for transfer complete + interrupt flag\n");
retry = 1000;
while (retry --) {
- if (READ1(sc, I2C_IBSR) & IBSR_TCF) {
- if (READ1(sc, I2C_IBSR) & IBSR_IBIF) {
- WRITE1(sc, I2C_IBSR, IBSR_IBIF);
- return (IIC_NOERR);
+ ibsr=READ1(sc, I2C_IBSR);
+
+ if (ibsr & IBSR_IBIF) {
+ WRITE1(sc, I2C_IBSR, IBSR_IBIF);
+
+ if(ibsr & IBSR_IBAL) {
+ WRITE1(sc, I2C_IBSR, IBSR_IBAL);
+ return (IIC_EBUSBSY);
}
+
+ if(ibsr & IBSR_TCF) return (IIC_NOERR);
}
DELAY(10);
}
@@ -300,6 +248,7 @@
static bool
tx_acked(struct i2c_softc *sc)
{
+ vf_i2c_dbg(sc, "i2c get ACK bit from last write\n");
return (READ1(sc, I2C_IBSR) & IBSR_RXAK) ? false : true;
@@ -318,30 +267,24 @@
mtx_lock(&sc->mutex);
- WRITE1(sc, I2C_IBAD, slave);
-
if ((READ1(sc, I2C_IBSR) & IBSR_IBB) == 0) {
+ vf_i2c_dbg(sc, "cant i2c repeat start: bus is no longer busy\n");
mtx_unlock(&sc->mutex);
return (IIC_EBUSERR);
}
- /* Set repeated start condition */
- DELAY(10);
-
reg = READ1(sc, I2C_IBCR);
reg |= (IBCR_RSTA | IBCR_IBIE);
WRITE1(sc, I2C_IBCR, reg);
- DELAY(10);
-
/* Write target address - LSB is R/W bit */
WRITE1(sc, I2C_IBDR, slave);
- error = wait_for_iif(sc);
+ error = wait_for_icf(sc);
if (!tx_acked(sc)) {
- vf_i2c_dbg(sc,
- "cant i2c start: missing ACK after slave addres\n");
+ mtx_unlock(&sc->mutex);
+ vf_i2c_dbg(sc, "cant i2c repeat start: missing ACK after slave address\n");
return (IIC_ENOACK);
}
@@ -366,27 +309,32 @@
mtx_lock(&sc->mutex);
- WRITE1(sc, I2C_IBAD, slave);
+ error = wait_for_nibb(sc);
+
+ /* Reset controller if bus still busy */
+ if (error == IIC_ETIMEOUT) {
+ WRITE1(sc, I2C_IBCR, IBCR_MDIS);
+ DELAY(1000);
+ WRITE1(sc, I2C_IBCR, IBCR_NOACK);
+ error = wait_for_nibb(sc);
+ }
- if (READ1(sc, I2C_IBSR) & IBSR_IBB) {
+ if (error != 0) {
mtx_unlock(&sc->mutex);
- vf_i2c_dbg(sc, "cant i2c start: IIC_EBUSBSY\n");
- return (IIC_EBUSERR);
+ vf_i2c_dbg(sc, "cant i2c start: %i\n", error);
+ return (error);
}
/* Set start condition */
- reg = (IBCR_MSSL | IBCR_NOACK | IBCR_IBIE);
+ reg = (IBCR_MSSL | IBCR_NOACK | IBCR_IBIE | IBCR_TXRX);
WRITE1(sc, I2C_IBCR, reg);
- DELAY(100);
-
- reg |= (IBCR_TXRX);
- WRITE1(sc, I2C_IBCR, reg);
+ WRITE1(sc, I2C_IBSR, IBSR_IBIF);
/* Write target address - LSB is R/W bit */
WRITE1(sc, I2C_IBDR, slave);
- error = wait_for_iif(sc);
+ error = wait_for_icf(sc);
if (error != 0) {
mtx_unlock(&sc->mutex);
vf_i2c_dbg(sc, "cant i2c start: iif error\n");
@@ -395,8 +343,7 @@
mtx_unlock(&sc->mutex);
if (!tx_acked(sc)) {
- vf_i2c_dbg(sc,
- "cant i2c start: missing QACK after slave addres\n");
+ vf_i2c_dbg(sc, "cant i2c start: missing ACK after slave address\n");
return (IIC_ENOACK);
}
@@ -414,81 +361,64 @@
mtx_lock(&sc->mutex);
- WRITE1(sc, I2C_IBCR, IBCR_NOACK | IBCR_IBIE);
+ if((READ1(sc, I2C_IBCR) & IBCR_MSSL) != 0) WRITE1(sc, I2C_IBCR, IBCR_NOACK | IBCR_IBIE);
- DELAY(100);
-
- /* Reset controller if bus still busy after STOP */
- if (wait_for_nibb(sc) == IIC_ETIMEOUT) {
- WRITE1(sc, I2C_IBCR, IBCR_MDIS);
- DELAY(1000);
- WRITE1(sc, I2C_IBCR, IBCR_NOACK);
- }
mtx_unlock(&sc->mutex);
return (IIC_NOERR);
}
-static uint32_t
-i2c_get_div_val(device_t dev)
+static void
+i2c_update_div_val(device_t dev)
{
- struct i2c_softc *sc;
- uint64_t clk_freq;
- int error, i;
+ struct i2c_softc *sc = device_get_softc(dev);
- sc = device_get_softc(dev);
+ if(sc->freq == UINT32_MAX) return;
+ uint8_t div_reg;
if (sc->hwtype == HW_MVF600)
- return 20;
+ div_reg=0x14;
- if (sc->freq == 0)
- return vf610_div_table[nitems(vf610_div_table) - 1].reg_val;
+ else if (sc->freq == 0)
+ div_reg=vf610_div_table[nitems(vf610_div_table) - 1].reg_val;
- error = clk_get_freq(sc->clock, &clk_freq);
- if (error != 0) {
- device_printf(dev, "Could not get parent clock frequency. "
- "Using default divider.\n");
- return vf610_div_table[nitems(vf610_div_table) - 1].reg_val;
- }
+ else {
+ uint64_t clk_freq;
+ int error, i;
+
+ error = clk_get_freq(sc->clock, &clk_freq);
- for (i = 0; i < nitems(vf610_div_table) - 1; i++)
- if ((clk_freq / vf610_div_table[i].div) <= sc->freq)
- break;
+ if (error != 0) {
+ device_printf(dev, "Could not get parent clock frequency. "
+ "Using default divider.\n");
+ div_reg = vf610_div_table[nitems(vf610_div_table) - 1].reg_val;
+
+ } else {
- return vf610_div_table[i].reg_val;
+ for (i = 0; i < nitems(vf610_div_table) - 1; i++)
+ if ((clk_freq / vf610_div_table[i].div) <= sc->freq)
+ break;
+ div_reg = vf610_div_table[i].reg_val;
+ }
+ }
+ WRITE1(sc, I2C_IBFD, div_reg);
}
static int
i2c_reset(device_t dev, u_char speed, u_char addr, u_char *oldadr)
{
struct i2c_softc *sc;
- uint32_t div;
sc = device_get_softc(dev);
- div = i2c_get_div_val(dev);
- vf_i2c_dbg(sc, "Div val: %02x\n", div);
vf_i2c_dbg(sc, "i2c reset\n");
- switch (speed) {
- case IIC_FAST:
- case IIC_SLOW:
- case IIC_UNKNOWN:
- case IIC_FASTEST:
- default:
- break;
- }
-
mtx_lock(&sc->mutex);
WRITE1(sc, I2C_IBCR, IBCR_MDIS);
- DELAY(1000);
-
- WRITE1(sc, I2C_IBFD, div);
+ i2c_update_div_val(dev);
WRITE1(sc, I2C_IBCR, 0x0); /* Enable i2c */
- DELAY(1000);
-
mtx_unlock(&sc->mutex);
return (IIC_NOERR);
@@ -509,37 +439,36 @@
mtx_lock(&sc->mutex);
if (len) {
+
if (len == 1)
- WRITE1(sc, I2C_IBCR, IBCR_IBIE | IBCR_MSSL | \
- IBCR_NOACK);
+ WRITE1(sc, I2C_IBCR, IBCR_IBIE | IBCR_MSSL | IBCR_NOACK);
else
WRITE1(sc, I2C_IBCR, IBCR_IBIE | IBCR_MSSL);
/* dummy read */
READ1(sc, I2C_IBDR);
- DELAY(1000);
- }
- while (*read < len) {
- error = wait_for_icf(sc);
- if (error != 0) {
- mtx_unlock(&sc->mutex);
- return (error);
- }
+ while (*read < len) {
+ error = wait_for_icf(sc);
+ if (error != 0) {
+ mtx_unlock(&sc->mutex);
+ return (error);
+ }
- if ((*read == len - 2) && last) {
- /* NO ACK on last byte */
- WRITE1(sc, I2C_IBCR, IBCR_IBIE | IBCR_MSSL | \
- IBCR_NOACK);
- }
+ if (last ) {
+ if (*read == len - 2) {
+ /* NO ACK on last byte */
+ WRITE1(sc, I2C_IBCR, IBCR_IBIE | IBCR_MSSL | IBCR_NOACK);
- if ((*read == len - 1) && last) {
- /* Transfer done, remove master bit */
- WRITE1(sc, I2C_IBCR, IBCR_IBIE | IBCR_NOACK);
- }
+ } else if (*read == len - 1) {
+ /* Transfer done, remove master bit */
+ WRITE1(sc, I2C_IBCR, IBCR_IBIE | IBCR_NOACK);
+ }
+ }
- *buf++ = READ1(sc, I2C_IBDR);
- (*read)++;
+ *buf++ = READ1(sc, I2C_IBDR);
+ (*read)++;
+ }
}
mtx_unlock(&sc->mutex);
@@ -562,7 +491,7 @@
while (*sent < len) {
WRITE1(sc, I2C_IBDR, *buf++);
- error = wait_for_iif(sc);
+ error = wait_for_icf(sc);
if (error != 0) {
mtx_unlock(&sc->mutex);
return (error);
@@ -580,20 +509,9 @@
return (IIC_NOERR);
}
-static phandle_t
-i2c_get_node(device_t bus, device_t dev)
-{
-
- return ofw_bus_get_node(bus);
-}
-
static device_method_t i2c_methods[] = {
- DEVMETHOD(device_probe, i2c_probe),
- DEVMETHOD(device_attach, i2c_attach),
DEVMETHOD(device_detach, i2c_detach),
- DEVMETHOD(ofw_bus_get_node, i2c_get_node),
-
DEVMETHOD(iicbus_callback, iicbus_null_callback),
DEVMETHOD(iicbus_repeated_start, i2c_repeated_start),
DEVMETHOD(iicbus_start, i2c_start),
@@ -605,7 +523,8 @@
{ 0, 0 }
};
-static DEFINE_CLASS_0(i2c, i2c_driver, i2c_methods, sizeof(struct i2c_softc));
-DRIVER_MODULE(vybrid_i2c, simplebus, i2c_driver, 0, 0);
-DRIVER_MODULE(iicbus, i2c, iicbus_driver, 0, 0);
-DRIVER_MODULE(ofw_iicbus, i2c, ofw_iicbus_driver, 0, 0);
+driver_t vf_i2c_driver = {
+ "i2c",
+ i2c_methods,
+ sizeof(struct i2c_softc),
+};
diff --git a/sys/dev/iicbus/controller/qoriq/vf_i2c_acpi.c b/sys/dev/iicbus/controller/qoriq/vf_i2c_acpi.c
new file mode 100644
--- /dev/null
+++ b/sys/dev/iicbus/controller/qoriq/vf_i2c_acpi.c
@@ -0,0 +1,108 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2014 Ruslan Bukin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Vybrid Family Inter-Integrated Circuit (I2C)
+ * Chapter 21, LX2160A Reference Manual, Rev. 1, 10/2021
+ */
+
+#include
+
+#include "opt_acpi.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+#include
+#include
+#include
+
+#include
+
+static char *vf_i2c_ids[] = {
+ "NXP0001",
+ NULL
+};
+
+static int
+i2c_acpi_probe(device_t dev)
+{
+ int rv;
+
+ if (acpi_disabled("vf_i2c"))
+ return (ENXIO);
+
+ rv = ACPI_ID_PROBE(device_get_parent(dev), dev, vf_i2c_ids, NULL);
+ if (rv > 0)
+ return (rv);
+
+ device_set_desc(dev, VF_I2C_DEVSTR);
+ return (BUS_PROBE_DEFAULT);
+}
+
+static int
+i2c_acpi_attach(device_t dev)
+{
+ struct i2c_softc *sc;
+
+ sc = device_get_softc(dev);
+ sc->dev = dev;
+ sc->hwtype = HW_VF610;
+ sc->freq = 0;
+
+ return (vf_i2c_attach_common(dev));
+}
+
+static device_method_t i2c_acpi_methods[] = {
+ DEVMETHOD(device_probe, i2c_acpi_probe),
+ DEVMETHOD(device_attach, i2c_acpi_attach),
+
+ DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
+ DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
+ DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
+ DEVMETHOD(bus_release_resource, bus_generic_release_resource),
+ DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
+ DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
+ DEVMETHOD(bus_adjust_resource, bus_generic_adjust_resource),
+
+ { 0, 0 }
+};
+
+DEFINE_CLASS_1(i2c, vf_i2c_acpi_driver, i2c_acpi_methods,
+ sizeof(struct i2c_softc), vf_i2c_driver);
+
+DRIVER_MODULE(i2c, acpi, vf_i2c_acpi_driver, 0, 0);
+DRIVER_MODULE(iicbus, i2c, iicbus_driver, 0, 0);
+DRIVER_MODULE(acpi_iicbus, i2c, acpi_iicbus_driver, 0, 0);
diff --git a/sys/dev/iicbus/controller/qoriq/vf_i2c_fdt.c b/sys/dev/iicbus/controller/qoriq/vf_i2c_fdt.c
new file mode 100644
--- /dev/null
+++ b/sys/dev/iicbus/controller/qoriq/vf_i2c_fdt.c
@@ -0,0 +1,120 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2014 Ruslan Bukin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Vybrid Family Inter-Integrated Circuit (I2C)
+ * Chapter 21, LX2160A Reference Manual, Rev. 1, 10/2021
+ */
+
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+
+#include
+
+#include
+
+static const struct ofw_compat_data i2c_compat_data[] = {
+ {"fsl,mvf600-i2c", HW_MVF600},
+ {"fsl,vf610-i2c", HW_VF610},
+ {NULL, }
+};
+
+static int
+i2c_fdt_probe(device_t dev)
+{
+
+ if (!ofw_bus_status_okay(dev))
+ return (ENXIO);
+
+ if (ofw_bus_search_compatible(dev, i2c_compat_data)->ocd_data == 0)
+ return (ENXIO);
+
+ device_set_desc(dev, VF_I2C_DEVSTR);
+ return (BUS_PROBE_DEFAULT);
+}
+
+static int
+i2c_fdt_attach(device_t dev)
+{
+ struct i2c_softc *sc;
+ phandle_t node;
+ int error;
+
+ sc = device_get_softc(dev);
+ sc->dev = dev;
+ sc->hwtype = ofw_bus_search_compatible(dev, i2c_compat_data)->ocd_data;
+ node = ofw_bus_get_node(dev);
+
+ error = clk_get_by_ofw_index(dev, node, 0, &sc->clock);
+ if (error != 0) {
+ sc->freq = 0;
+ device_printf(dev, "Parent clock not found.\n");
+
+ } else {
+ if (OF_hasprop(node, "clock-frequency"))
+ OF_getencprop(node, "clock-frequency", &sc->freq,
+ sizeof(sc->freq));
+ else
+ sc->freq = 100000;
+ }
+ return (vf_i2c_attach_common(dev));
+}
+
+static phandle_t
+i2c_get_node(device_t bus, device_t dev)
+{
+ return (ofw_bus_get_node(bus));
+}
+
+static device_method_t i2c_fdt_methods[] = {
+ DEVMETHOD(device_probe, i2c_fdt_probe),
+ DEVMETHOD(device_attach, i2c_fdt_attach),
+
+ DEVMETHOD(ofw_bus_get_node, i2c_get_node),
+
+ { 0, 0 }
+};
+
+DEFINE_CLASS_1(i2c, vf_i2c_fdt_driver, i2c_fdt_methods,
+ sizeof(struct i2c_softc), vf_i2c_driver);
+
+DRIVER_MODULE(i2c, simplebus, vf_i2c_fdt_driver, 0, 0);
+DRIVER_MODULE(iicbus, i2c, iicbus_driver, 0, 0);
+DRIVER_MODULE(ofw_iicbus, i2c, ofw_iicbus_driver, 0, 0);
+
diff --git a/sys/modules/Makefile b/sys/modules/Makefile
--- a/sys/modules/Makefile
+++ b/sys/modules/Makefile
@@ -219,6 +219,8 @@
linuxkpi_wlan \
${_lio} \
lpt \
+ ${_vf_i2c_acpi} \
+ ${_vf_i2c_fdt} \
${_mac_biba} \
${_mac_bsdextended} \
${_mac_ddb} \
@@ -682,6 +684,7 @@
_sff= sff
_em= em
_hyperv= hyperv
+_vf_i2c_fdt= vf_i2c_fdt
.if !empty(OPT_FDT)
_allwinner= allwinner
@@ -689,6 +692,7 @@
_enetc= enetc
_felix= felix
_rockchip= rockchip
+_vf_i2c_acpi= vf_i2c_acpi
.endif
.endif
diff --git a/sys/modules/vf_i2c_acpi/Makefile b/sys/modules/vf_i2c_acpi/Makefile
new file mode 100644
--- /dev/null
+++ b/sys/modules/vf_i2c_acpi/Makefile
@@ -0,0 +1,9 @@
+
+.PATH: ${SRCTOP}/sys/dev/iicbus/controller/qoriq
+
+KMOD= vf_i2c_acpi
+SRCS= vf_i2c_acpi.c vf_i2c.c vf_i2c.h
+SRCS+= acpi_if.h device_if.h bus_if.h pci_if.h mmcbr_if.h iicbus_if.h
+SRCS+= opt_acpi.h opt_mmccam.h opt_platform.h clknode_if.h ofw_bus_if.h
+
+.include
diff --git a/sys/modules/vf_i2c_fdt/Makefile b/sys/modules/vf_i2c_fdt/Makefile
new file mode 100644
--- /dev/null
+++ b/sys/modules/vf_i2c_fdt/Makefile
@@ -0,0 +1,9 @@
+
+.PATH: ${SRCTOP}/sys/dev/iicbus/controller/qoriq
+
+KMOD= vf_i2c_fdt
+SRCS= vf_i2c_fdt.c vf_i2c.c vf_i2c.h
+SRCS+= acpi_if.h device_if.h bus_if.h pci_if.h mmcbr_if.h iicbus_if.h
+SRCS+= opt_mmccam.h opt_platform.h clknode_if.h ofw_bus_if.h
+
+.include