Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F101910371
D43746.id134083.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
23 KB
Referenced Files
None
Subscribers
None
D43746.id134083.diff
View Options
Index: sys/arm64/conf/std.nxp
===================================================================
--- sys/arm64/conf/std.nxp
+++ sys/arm64/conf/std.nxp
@@ -10,6 +10,9 @@
device pcf8563 # NXP Real-time clock/calendar
device tca64xx # NXP I2C gpio expander
device pcf85063 # NXP Real-time clock
+device lx2160a_i2c # NXP LX2160A-family I2C controller
+device lx2160a_i2c_acpi # NXP LX2160A-family I2C controller
+#device lx2160a_i2c_fdt # NXP LX2160A-family I2C controller (not to be included along with vf_i2c)
# Serial (COM) ports
device uart_ns8250 # ns8250-type UART driver
Index: sys/conf/files.arm64
===================================================================
--- sys/conf/files.arm64
+++ sys/conf/files.arm64
@@ -630,6 +630,9 @@
# NXP
arm/freescale/vybrid/vf_i2c.c optional vf_i2c iicbus soc_nxp_ls
+dev/iicbus/controller/qoriq/lx2160a_i2c.c optional lx2160a_i2c iicbus soc_nxp_ls
+dev/iicbus/controller/qoriq/lx2160a_i2c_acpi.c optional lx2160a_i2c_acpi iicbus acpi soc_nxp_ls
+dev/iicbus/controller/qoriq/lx2160a_i2c_fdt.c optional lx2160a_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
Index: sys/dev/iicbus/controller/qoriq/lx2160a_i2c.h
===================================================================
--- /dev/null
+++ sys/dev/iicbus/controller/qoriq/lx2160a_i2c.h
@@ -0,0 +1,58 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Pierre-Luc Drouin <pldrouin@pldrouin.net>
+ *
+ * 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.
+ */
+
+/*
+ * LX2160A Family Inter-Integrated Circuit (I2C)
+ * Chapter 21, LX2160A Reference Manual, Rev. 1, 10/2021
+ */
+
+/*
+ * This driver is based on the Vybrid I2C driver by Ruslan Bukin and on earlier
+ * work by Val Packett
+*/
+
+#ifndef __LX2160A_I2C_H__
+#define __LX2160A_I2C_H__
+
+#define LX2160A_I2C_DEVSTR "LX2160A Family Inter-Integrated Circuit (I2C)"
+
+#define HW_VF610 0x02
+
+struct i2c_softc {
+ struct resource *res[2];
+ bus_space_tag_t bst;
+ bus_space_handle_t bsh;
+ device_t dev;
+ device_t iicbus;
+ struct mtx mutex;
+};
+
+extern driver_t lx2160a_i2c_driver;
+
+device_attach_t lx2160a_i2c_attach_common;
+
+#endif /* !__LX2160A_I2C_H__ */
Index: sys/dev/iicbus/controller/qoriq/lx2160a_i2c.c
===================================================================
--- /dev/null
+++ sys/dev/iicbus/controller/qoriq/lx2160a_i2c.c
@@ -0,0 +1,456 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Pierre-Luc Drouin <pldrouin@pldrouin.net>
+ *
+ * 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.
+ */
+
+/*
+ * LX2160A Family Inter-Integrated Circuit (I2C)
+ * Chapter 21, LX2160A Reference Manual, Rev. 1, 10/2021
+ */
+
+/*
+ * This driver is based on the Vybrid I2C driver by Ruslan Bukin and on earlier
+ * work by Val Packett
+*/
+
+#include <sys/cdefs.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/malloc.h>
+#include <sys/rman.h>
+#include <sys/timeet.h>
+#include <sys/timetc.h>
+
+#include <dev/iicbus/iiconf.h>
+#include <dev/iicbus/iicbus.h>
+
+#include "iicbus_if.h"
+
+#include <machine/bus.h>
+#include <machine/cpu.h>
+#include <machine/intr.h>
+
+#include <dev/iicbus/controller/qoriq/lx2160a_i2c.h>
+
+#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 */
+#define I2C_IBCR 0x2 /* I2C Bus Control Register */
+#define IBCR_MDIS (1 << 7) /* Module disable. */
+#define IBCR_IBIE (1 << 6) /* I-Bus Interrupt Enable. */
+#define IBCR_MSSL (1 << 5) /* Master/Slave mode select. */
+#define IBCR_TXRX (1 << 4) /* Transmit/Receive mode select. */
+#define IBCR_NOACK (1 << 3) /* Data Acknowledge disable. */
+#define IBCR_RSTA (1 << 2) /* Repeat Start. */
+#define IBCR_DMAEN (1 << 1) /* DMA Enable. */
+#define I2C_IBSR 0x3 /* I2C Bus Status Register */
+#define IBSR_TCF (1 << 7) /* Transfer complete. */
+#define IBSR_IAAS (1 << 6) /* Addressed as a slave. */
+#define IBSR_IBB (1 << 5) /* Bus busy. */
+#define IBSR_IBAL (1 << 4) /* Arbitration Lost. */
+#define IBSR_SRW (1 << 2) /* Slave Read/Write. */
+#define IBSR_IBIF (1 << 1) /* I-Bus Interrupt Flag. */
+#define IBSR_RXAK (1 << 0) /* Received Acknowledge. */
+#define I2C_IBDR 0x4 /* I2C Bus Data I/O Register */
+#define I2C_IBIC 0x5 /* I2C Bus Interrupt Config Register */
+#define IBIC_BIIE (1 << 7) /* Bus Idle Interrupt Enable bit. */
+#define I2C_IBDBG 0x6 /* I2C Bus Debug Register */
+
+#ifdef DEBUG
+#define lx2160a_i2c_dbg(_sc, fmt, args...) \
+ device_printf((_sc)->dev, fmt, ##args)
+#ifdef DEBUG2
+#undef WRITE1
+#define WRITE1(_sc, _reg, _val) ({lx2160a_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); lx2160a_i2c_dbg(_sc, "READ1 REG 0x%02X RETURNS 0x%02X\n",_reg,ret); ret;})
+#endif
+#else
+#define lx2160a_i2c_dbg(_sc, fmt, args...)
+#endif
+
+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 struct resource_spec i2c_spec[] = {
+ { SYS_RES_MEMORY, 0, RF_ACTIVE },
+ { SYS_RES_IRQ, 0, RF_ACTIVE },
+ { -1, 0 }
+};
+
+int
+lx2160a_i2c_attach_common(device_t dev)
+{
+ struct i2c_softc *sc = device_get_softc(dev);
+ int error;
+ lx2160a_i2c_dbg(sc, "i2c attach common\n");
+
+ mtx_init(&sc->mutex, device_get_nameunit(dev), "I2C", MTX_DEF);
+
+ error = bus_alloc_resources(dev, i2c_spec, sc->res);
+ if (error != 0) {
+ mtx_destroy(&sc->mutex);
+ device_printf(dev, "could not allocate resources\n");
+ return (ENXIO);
+ }
+
+ /* Memory interface */
+ sc->bst = rman_get_bustag(sc->res[0]);
+ sc->bsh = rman_get_bushandle(sc->res[0]);
+
+ WRITE1(sc, I2C_IBIC, IBIC_BIIE);
+
+ sc->iicbus = device_add_child(dev, "iicbus", -1);
+ if (sc->iicbus == NULL) {
+ device_printf(dev, "could not add iicbus child");
+ mtx_destroy(&sc->mutex);
+ bus_release_resources(dev, i2c_spec, sc->res);
+ return (ENXIO);
+ }
+
+ bus_generic_attach(dev);
+
+ return (0);
+}
+
+static int
+i2c_detach(device_t dev)
+{
+ struct i2c_softc *sc;
+ int error = 0;
+
+ sc = device_get_softc(dev);
+ lx2160a_i2c_dbg(sc, "i2c detach\n");
+
+ error = bus_generic_detach(dev);
+ if (error != 0) {
+ device_printf(dev, "cannot detach child devices.\n");
+ return (error);
+ }
+
+ error = device_delete_child(dev, sc->iicbus);
+ if (error != 0) {
+ device_printf(dev, "could not delete iicbus child.\n");
+ return (error);
+ }
+
+ bus_release_resources(dev, i2c_spec, sc->res);
+
+ mtx_destroy(&sc->mutex);
+
+ return (0);
+}
+
+/* Wait for free bus */
+static int
+wait_for_nibb(struct i2c_softc *sc)
+{
+ int retry;
+
+ retry = 1000;
+ while (retry --) {
+ if ((READ1(sc, I2C_IBSR) & IBSR_IBB) == 0)
+ return (IIC_NOERR);
+ DELAY(10);
+ }
+
+ return (IIC_ETIMEOUT);
+}
+
+/* Wait for transfer complete+interrupt flag */
+static int
+wait_for_icf(struct i2c_softc *sc)
+{
+ int retry;
+ uint8_t ibsr;
+ lx2160a_i2c_dbg(sc, "i2c wait for transfer complete + interrupt flag\n");
+
+ retry = 1000;
+ while (retry --) {
+ 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);
+ }
+
+ return (IIC_ETIMEOUT);
+}
+/* Get ACK bit from last write */
+static bool
+tx_acked(struct i2c_softc *sc)
+{
+ lx2160a_i2c_dbg(sc, "i2c get ACK bit from last write\n");
+
+ return (READ1(sc, I2C_IBSR) & IBSR_RXAK) ? false : true;
+
+}
+
+static int
+i2c_repeated_start(device_t dev, u_char slave, int timeout)
+{
+ struct i2c_softc *sc;
+ int error;
+ int reg;
+
+ sc = device_get_softc(dev);
+
+ lx2160a_i2c_dbg(sc, "i2c repeated start\n");
+
+ mtx_lock(&sc->mutex);
+
+ if ((READ1(sc, I2C_IBSR) & IBSR_IBB) == 0) {
+ lx2160a_i2c_dbg(sc, "cant i2c repeat start: bus is no longer busy\n");
+ mtx_unlock(&sc->mutex);
+ return (IIC_EBUSERR);
+ }
+
+ reg = READ1(sc, I2C_IBCR);
+ reg |= (IBCR_RSTA | IBCR_IBIE);
+ WRITE1(sc, I2C_IBCR, reg);
+
+ /* Write target address - LSB is R/W bit */
+ WRITE1(sc, I2C_IBDR, slave);
+
+ error = wait_for_icf(sc);
+
+ if (!tx_acked(sc)) {
+ mtx_unlock(&sc->mutex);
+ lx2160a_i2c_dbg(sc, "cant i2c repeat start: missing ACK after slave address\n");
+ return (IIC_ENOACK);
+ }
+
+ mtx_unlock(&sc->mutex);
+
+ if (error != 0)
+ return (error);
+
+ return (IIC_NOERR);
+}
+
+static int
+i2c_start(device_t dev, u_char slave, int timeout)
+{
+ struct i2c_softc *sc;
+ int error;
+ int reg;
+
+ sc = device_get_softc(dev);
+
+ lx2160a_i2c_dbg(sc, "i2c start\n");
+
+ mtx_lock(&sc->mutex);
+
+ error = wait_for_nibb(sc);
+
+ if (error != 0) {
+ mtx_unlock(&sc->mutex);
+ lx2160a_i2c_dbg(sc, "cant i2c start: %i\n", error);
+ return (error);
+ }
+
+ /* Set start condition */
+ reg = (IBCR_MSSL | IBCR_NOACK | IBCR_IBIE | 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_icf(sc);
+ if (error != 0) {
+ mtx_unlock(&sc->mutex);
+ lx2160a_i2c_dbg(sc, "cant i2c start: iif error\n");
+ return (error);
+ }
+ mtx_unlock(&sc->mutex);
+
+ if (!tx_acked(sc)) {
+ lx2160a_i2c_dbg(sc, "cant i2c start: missing ACK after slave address\n");
+ return (IIC_ENOACK);
+ }
+
+ return (IIC_NOERR);
+}
+
+static int
+i2c_stop(device_t dev)
+{
+ struct i2c_softc *sc;
+
+ sc = device_get_softc(dev);
+
+ lx2160a_i2c_dbg(sc, "i2c stop\n");
+
+ mtx_lock(&sc->mutex);
+
+ if((READ1(sc, I2C_IBCR) & IBCR_MSSL) != 0) WRITE1(sc, I2C_IBCR, IBCR_NOACK | IBCR_IBIE);
+
+ mtx_unlock(&sc->mutex);
+
+ return (IIC_NOERR);
+}
+
+static int
+i2c_reset(device_t dev, u_char speed, u_char addr, u_char *oldadr)
+{
+ struct i2c_softc *sc;
+
+ sc = device_get_softc(dev);
+
+ lx2160a_i2c_dbg(sc, "i2c reset\n");
+
+ mtx_lock(&sc->mutex);
+ WRITE1(sc, I2C_IBCR, IBCR_MDIS);
+
+ WRITE1(sc, I2C_IBCR, 0x0); /* Enable i2c */
+
+ mtx_unlock(&sc->mutex);
+
+ return (IIC_NOERR);
+}
+
+static int
+i2c_read(device_t dev, char *buf, int len, int *read, int last, int delay)
+{
+ struct i2c_softc *sc;
+ int error;
+
+ sc = device_get_softc(dev);
+
+ lx2160a_i2c_dbg(sc, "i2c read\n");
+
+ *read = 0;
+
+ mtx_lock(&sc->mutex);
+
+ if (len) {
+
+ if (len == 1)
+ 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);
+
+ while (*read < len) {
+ error = wait_for_icf(sc);
+ if (error != 0) {
+ mtx_unlock(&sc->mutex);
+ return (error);
+ }
+
+ if (last ) {
+ if (*read == len - 2) {
+ /* NO ACK on last byte */
+ WRITE1(sc, I2C_IBCR, IBCR_IBIE | IBCR_MSSL | 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)++;
+ }
+ }
+ mtx_unlock(&sc->mutex);
+
+ return (IIC_NOERR);
+}
+
+static int
+i2c_write(device_t dev, const char *buf, int len, int *sent, int timeout)
+{
+ struct i2c_softc *sc;
+ int error;
+
+ sc = device_get_softc(dev);
+
+ lx2160a_i2c_dbg(sc, "i2c write\n");
+
+ *sent = 0;
+
+ mtx_lock(&sc->mutex);
+ while (*sent < len) {
+ WRITE1(sc, I2C_IBDR, *buf++);
+
+ error = wait_for_icf(sc);
+ if (error != 0) {
+ mtx_unlock(&sc->mutex);
+ return (error);
+ }
+
+ if (!tx_acked(sc) && (*sent = (len - 2)) ){
+ mtx_unlock(&sc->mutex);
+ lx2160a_i2c_dbg(sc, "no ACK on %d write\n", *sent);
+ return (IIC_ENOACK);
+ }
+
+ (*sent)++;
+ }
+ mtx_unlock(&sc->mutex);
+ return (IIC_NOERR);
+}
+
+static device_method_t i2c_methods[] = {
+ DEVMETHOD(device_detach, i2c_detach),
+
+ DEVMETHOD(iicbus_callback, iicbus_null_callback),
+ DEVMETHOD(iicbus_repeated_start, i2c_repeated_start),
+ DEVMETHOD(iicbus_start, i2c_start),
+ DEVMETHOD(iicbus_stop, i2c_stop),
+ DEVMETHOD(iicbus_reset, i2c_reset),
+ DEVMETHOD(iicbus_read, i2c_read),
+ DEVMETHOD(iicbus_write, i2c_write),
+ DEVMETHOD(iicbus_transfer, iicbus_transfer_gen),
+ { 0, 0 }
+};
+
+driver_t lx2160a_i2c_driver = {
+ "i2c",
+ i2c_methods,
+ sizeof(struct i2c_softc),
+};
Index: sys/dev/iicbus/controller/qoriq/lx2160a_i2c_acpi.c
===================================================================
--- /dev/null
+++ sys/dev/iicbus/controller/qoriq/lx2160a_i2c_acpi.c
@@ -0,0 +1,112 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Pierre-Luc Drouin <pldrouin@pldrouin.net>
+ *
+ * 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.
+ */
+
+/*
+ * LX2160A Family Inter-Integrated Circuit (I2C)
+ * Chapter 21, LX2160A Reference Manual, Rev. 1, 10/2021
+ */
+
+/*
+ * This driver is based on the Vybrid I2C driver by Ruslan Bukin and on earlier
+ * work by Val Packett
+*/
+
+#include <sys/cdefs.h>
+
+#include "opt_acpi.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/rman.h>
+
+#include <contrib/dev/acpica/include/acpi.h>
+#include <contrib/dev/acpica/include/accommon.h>
+
+#include <dev/acpica/acpivar.h>
+#include <dev/iicbus/iicbus.h>
+#include <dev/iicbus/iiconf.h>
+
+#include <dev/iicbus/controller/qoriq/lx2160a_i2c.h>
+
+static char *lx2160a_i2c_ids[] = {
+ "NXP0001",
+ NULL
+};
+
+static int
+i2c_acpi_probe(device_t dev)
+{
+ int rv;
+
+ if (acpi_disabled("lx2160a_i2c"))
+ return (ENXIO);
+
+ rv = ACPI_ID_PROBE(device_get_parent(dev), dev, lx2160a_i2c_ids, NULL);
+ if (rv > 0)
+ return (rv);
+
+ device_set_desc(dev, LX2160A_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;
+
+ return (lx2160a_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, lx2160a_i2c_acpi_driver, i2c_acpi_methods,
+ sizeof(struct i2c_softc), lx2160a_i2c_driver);
+
+DRIVER_MODULE(iicbus, lx2160a_i2c_acpi, iicbus_driver, 0, 0);
+DRIVER_MODULE(acpi_iicbus, lx2160a_i2c_acpi, acpi_iicbus_driver, 0, 0);
+DRIVER_MODULE(lx2160a_i2c_acpi, acpi, lx2160a_i2c_acpi_driver, 0, 0);
+MODULE_DEPEND(lx2160a_i2c_acpi, iicbus, IICBUS_MINVER, IICBUS_PREFVER, IICBUS_MAXVER);
+MODULE_VERSION(lx2160a_i2c_acpi, 1);
Index: sys/dev/iicbus/controller/qoriq/lx2160a_i2c_fdt.c
===================================================================
--- /dev/null
+++ sys/dev/iicbus/controller/qoriq/lx2160a_i2c_fdt.c
@@ -0,0 +1,107 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Pierre-Luc Drouin <pldrouin@pldrouin.net>
+ *
+ * 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.
+ */
+
+/*
+ * LX2160A Family Inter-Integrated Circuit (I2C)
+ * Chapter 21, LX2160A Reference Manual, Rev. 1, 10/2021
+ */
+
+/*
+ * This driver is based on the Vybrid I2C driver by Ruslan Bukin and on earlier
+ * work by Val Packett
+*/
+
+#include <sys/cdefs.h>
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/malloc.h>
+#include <sys/rman.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+
+#include <dev/iicbus/iicbus.h>
+
+#include <dev/iicbus/controller/qoriq/lx2160a_i2c.h>
+
+static const struct ofw_compat_data i2c_compat_data[] = {
+ {"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, LX2160A_I2C_DEVSTR);
+ return (BUS_PROBE_DEFAULT);
+}
+
+static int
+i2c_fdt_attach(device_t dev)
+{
+ struct i2c_softc *sc;
+
+ sc = device_get_softc(dev);
+ sc->dev = dev;
+ return (lx2160a_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, lx2160a_i2c_fdt_driver, i2c_fdt_methods,
+ sizeof(struct i2c_softc), lx2160a_i2c_driver);
+
+DRIVER_MODULE(lx2160a_i2c_fdt, simplebus, lx2160a_i2c_fdt_driver, 0, 0);
+DRIVER_MODULE(iicbus, lx2160a_i2c_fdt, iicbus_driver, 0, 0);
+DRIVER_MODULE(ofw_iicbus, lx2160a_i2c_fdt, ofw_iicbus_driver, 0, 0);
+MODULE_VERSION(lx2160a_i2c_fdt, 1);
+
Index: sys/modules/Makefile
===================================================================
--- sys/modules/Makefile
+++ sys/modules/Makefile
@@ -219,6 +219,8 @@
linuxkpi_wlan \
${_lio} \
lpt \
+ ${_lx2160a_i2c_acpi} \
+ ${_lx2160a_i2c_fdt} \
${_mac_biba} \
${_mac_bsdextended} \
${_mac_ddb} \
@@ -679,6 +681,7 @@
.if ${MACHINE_CPUARCH} == "aarch64"
_armv8crypto= armv8crypto
_dpaa2= dpaa2
+_lx2160a_i2c_acpi= lx2160a_i2c_acpi
_sff= sff
_em= em
_hyperv= hyperv
@@ -688,6 +691,7 @@
_dwwdt= dwwdt
_enetc= enetc
_felix= felix
+_lx2160a_i2c_fdt= lx2160a_i2c_fdt
_rockchip= rockchip
.endif
.endif
Index: sys/modules/lx2160a_i2c_acpi/Makefile
===================================================================
--- /dev/null
+++ sys/modules/lx2160a_i2c_acpi/Makefile
@@ -0,0 +1,9 @@
+
+.PATH: ${SRCTOP}/sys/dev/iicbus/controller/qoriq
+
+KMOD= lx2160a_i2c_acpi
+SRCS= lx2160a_i2c_acpi.c lx2160a_i2c.c lx2160a_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
+
+.include <bsd.kmod.mk>
Index: sys/modules/lx2160a_i2c_fdt/Makefile
===================================================================
--- /dev/null
+++ sys/modules/lx2160a_i2c_fdt/Makefile
@@ -0,0 +1,9 @@
+
+.PATH: ${SRCTOP}/sys/dev/iicbus/controller/qoriq
+
+KMOD= lx2160a_i2c_fdt
+SRCS= lx2160a_i2c_fdt.c lx2160a_i2c.c lx2160a_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 ofw_bus_if.h
+
+.include <bsd.kmod.mk>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 6, 12:30 PM (16 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
14486242
Default Alt Text
D43746.id134083.diff (23 KB)
Attached To
Mode
D43746: Adding Support for QorIQ LX2160A I2C Controller
Attached
Detach File
Event Timeline
Log In to Comment