#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cdnsiic_fdt.c,v 1.3 2025/09/16 11:55:17 thorpej Exp $");
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/device.h>
#include <sys/intr.h>
#include <sys/systm.h>
#include <sys/time.h>
#include <sys/kmem.h>
#include <dev/i2c/i2cvar.h>
#include <dev/fdt/fdtvar.h>
#include <dev/ic/cdnsiicvar.h>
static const struct device_compatible_entry compat_data[] = {
{ .compat = "cdns,i2c-r1p10" },
{ .compat = "cdns,i2c-r1p14" },
DEVICE_COMPAT_EOL
};
static int
cdnsiic_fdt_match(device_t parent, cfdata_t cf, void *aux)
{
struct fdt_attach_args * const faa = aux;
return of_compatible_match(faa->faa_phandle, compat_data);
}
static void
cdnsiic_fdt_attach(device_t parent, device_t self, void *aux)
{
struct cdnsiic_softc * const sc = device_private(self);
struct fdt_attach_args * const faa = aux;
const int phandle = faa->faa_phandle;
bus_addr_t addr;
bus_size_t size;
int error;
if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
aprint_error(": couldn't get registers\n");
return;
}
sc->sc_pclk = fdtbus_clock_get_index(phandle, 0);
if (sc->sc_pclk == NULL || clk_enable(sc->sc_pclk) != 0) {
aprint_error(": couldn't enable pclk\n");
return;
}
if (of_getprop_uint32(phandle, "clock-frequency", &sc->sc_bus_freq))
sc->sc_bus_freq = 100000;
sc->sc_dev = self;
sc->sc_bst = faa->faa_bst;
if (bus_space_map(sc->sc_bst, addr, size, 0, &sc->sc_bsh) != 0) {
aprint_error(": couldn't map registers\n");
return;
}
error = cdnsiic_attach(sc);
if (error != 0) {
aprint_error_dev(self, "init failed, error = %d\n", error);
return;
}
iicbus_attach(self, &sc->sc_ic);
}
CFATTACH_DECL_NEW(cdnsiic_fdt, sizeof(struct cdnsiic_softc),
cdnsiic_fdt_match, cdnsiic_fdt_attach, NULL, NULL);