#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tegra_fuse.c,v 1.9 2021/01/27 03:10:19 thorpej Exp $");
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/device.h>
#include <sys/intr.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <arm/nvidia/tegra_reg.h>
#include <arm/nvidia/tegra_var.h>
#include <dev/fdt/fdtvar.h>
static int tegra_fuse_match(device_t, cfdata_t, void *);
static void tegra_fuse_attach(device_t, device_t, void *);
struct tegra_fuse_softc {
device_t sc_dev;
bus_space_tag_t sc_bst;
bus_space_handle_t sc_bsh;
struct clk *sc_clk;
struct fdtbus_reset *sc_rst;
};
static struct tegra_fuse_softc *fuse_softc = NULL;
CFATTACH_DECL_NEW(tegra_fuse, sizeof(struct tegra_fuse_softc),
tegra_fuse_match, tegra_fuse_attach, NULL, NULL);
static const struct device_compatible_entry compat_data[] = {
{ .compat = "nvidia,tegra210-efuse" },
{ .compat = "nvidia,tegra124-efuse" },
DEVICE_COMPAT_EOL
};
static int
tegra_fuse_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
tegra_fuse_attach(device_t parent, device_t self, void *aux)
{
struct tegra_fuse_softc * const sc = device_private(self);
struct fdt_attach_args * const faa = aux;
bus_addr_t addr;
bus_size_t size;
int error;
if (fdtbus_get_reg(faa->faa_phandle, 0, &addr, &size) != 0) {
aprint_error(": couldn't get registers\n");
return;
}
sc->sc_clk = fdtbus_clock_get(faa->faa_phandle, "fuse");
if (sc->sc_clk == NULL) {
aprint_error(": couldn't get clock fuse\n");
return;
}
sc->sc_rst = fdtbus_reset_get(faa->faa_phandle, "fuse");
if (sc->sc_rst == NULL) {
aprint_error(": couldn't get reset fuse\n");
return;
}
sc->sc_dev = self;
sc->sc_bst = faa->faa_bst;
error = bus_space_map(sc->sc_bst, addr, size, 0, &sc->sc_bsh);
if (error) {
aprint_error(": couldn't map %#" PRIxBUSADDR ": %d", addr, error);
return;
}
KASSERT(fuse_softc == NULL);
fuse_softc = sc;
aprint_naive("\n");
aprint_normal(": FUSE\n");
}
uint32_t
tegra_fuse_read(u_int offset)
{
bus_space_tag_t bst;
bus_space_handle_t bsh;
KASSERT(fuse_softc != NULL);
bst = fuse_softc->sc_bst;
bsh = fuse_softc->sc_bsh;
clk_enable(fuse_softc->sc_clk);
const uint32_t v = bus_space_read_4(bst, bsh, 0x100 + offset);
clk_disable(fuse_softc->sc_clk);
return v;
}