Allow for specifying (optional) pass number locator for devices at fdt.

This commit is contained in:
jmcneill 2017-04-26 01:51:52 +00:00
parent 9d6e151e19
commit b96c013d05
4 changed files with 58 additions and 22 deletions

View File

@ -1,5 +1,5 @@
#
# $NetBSD: TEGRA,v 1.17 2017/04/22 23:53:24 jmcneill Exp $
# $NetBSD: TEGRA,v 1.18 2017/04/26 01:51:52 jmcneill Exp $
#
# NVIDIA Tegra K1 (T124)
#
@ -42,28 +42,28 @@ fdt* at fdtbus?
# CPU frequency scaling
tegra124cpu* at fdt?
fclock* at fdt?
fregulator* at fdt?
fclock* at fdt? pass 4
fregulator* at fdt? pass 4
gpiokeys* at fdt?
# Interrupt controller
tegralic* at fdt? # LIC
gic* at fdt? # GIC
tegralic* at fdt? pass 1 # LIC
gic* at fdt? pass 1 # GIC
# Memory controller
tegramc* at fdt? # MC
tegramc* at fdt? pass 4 # MC
# FUSE controller
tegrafuse* at fdt? # FUSE
tegrafuse* at fdt? pass 4 # FUSE
# Power management controller
tegrapmc* at fdt? # PMC
tegrapmc* at fdt? pass 4 # PMC
# Clock and Reset controller
tegra124car* at fdt? # CAR
tegra124car* at fdt? pass 3 # CAR
# GPIO controller
tegragpio* at fdt? # GPIO
tegragpio* at fdt? pass 2 # GPIO
gpio* at gpiobus?
# Timers

View File

@ -1,4 +1,4 @@
/* $NetBSD: fdtbus.c,v 1.8 2017/04/16 12:24:57 jmcneill Exp $ */
/* $NetBSD: fdtbus.c,v 1.9 2017/04/26 01:51:52 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca>
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.8 2017/04/16 12:24:57 jmcneill Exp $");
__KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.9 2017/04/26 01:51:52 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -40,6 +40,8 @@ __KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.8 2017/04/16 12:24:57 jmcneill Exp $");
#include <dev/fdt/fdtvar.h>
#include "locators.h"
#define FDT_MAX_PATH 256
struct fdt_node {
@ -64,8 +66,9 @@ struct fdt_softc {
static int fdt_match(device_t, cfdata_t, void *);
static void fdt_attach(device_t, device_t, void *);
static int fdt_scan_submatch(device_t, cfdata_t, const int *, void *);
static void fdt_scan_bus(struct fdt_softc *);
static void fdt_scan(struct fdt_softc *);
static void fdt_scan(struct fdt_softc *, int);
static void fdt_add_node(struct fdt_node *);
static u_int fdt_get_order(int);
@ -159,17 +162,31 @@ fdt_attach(device_t parent, device_t self, void *aux)
if (OF_finddevice("/") != faa->faa_phandle)
return;
aprint_debug_dev(sc->sc_dev, " order phandle bus path\n");
aprint_debug_dev(sc->sc_dev, " ===== ======= === ====\n");
TAILQ_FOREACH(node, &fdt_nodes, n_nodes) {
char buf[FDT_MAX_PATH];
const char *path = buf;
if (!fdtbus_get_path(node->n_phandle, buf, sizeof(buf)))
path = node->n_name;
aprint_debug_dev(sc->sc_dev, " %04x 0x%04x %s %s\n",
node->n_order & 0xffff, node->n_phandle,
device_xname(node->n_bus), path);
}
/* Scan devices */
fdt_scan(sc);
for (int pass = 1; pass <= FDTCF_PASS_DEFAULT; pass++)
fdt_scan(sc, pass);
}
static void
fdt_init_attach_args(struct fdt_softc *sc, struct fdt_node *node,
struct fdt_attach_args *faa)
bool quiet, struct fdt_attach_args *faa)
{
*faa = sc->sc_faa;
faa->faa_phandle = node->n_phandle;
faa->faa_name = node->n_name;
faa->faa_quiet = quiet;
}
static void
@ -185,7 +202,7 @@ fdt_scan_bus(struct fdt_softc *sc)
if (node->n_dev != NULL)
continue;
fdt_init_attach_args(sc, node, &faa);
fdt_init_attach_args(sc, node, true, &faa);
/*
* Only attach busses to nodes where this driver is the best
@ -202,22 +219,37 @@ fdt_scan_bus(struct fdt_softc *sc)
}
}
static int
fdt_scan_submatch(device_t parent, cfdata_t cf, const int *locs, void *aux)
{
if (locs[FDTCF_PASS] != FDTCF_PASS_DEFAULT &&
locs[FDTCF_PASS] != cf->cf_loc[FDTCF_PASS])
return 0;
return config_stdsubmatch(parent, cf, locs, aux);
}
static void
fdt_scan(struct fdt_softc *sc)
fdt_scan(struct fdt_softc *sc, int pass)
{
struct fdt_node *node;
struct fdt_attach_args faa;
const int locs[FDTCF_NLOCS] = {
[FDTCF_PASS] = pass
};
bool quiet = pass != FDTCF_PASS_DEFAULT;
TAILQ_FOREACH(node, &fdt_nodes, n_nodes) {
if (node->n_dev != NULL)
continue;
fdt_init_attach_args(sc, node, &faa);
fdt_init_attach_args(sc, node, quiet, &faa);
/*
* Attach the device.
*/
node->n_dev = config_found(node->n_bus, &faa, fdt_print);
node->n_dev = config_found_sm_loc(node->n_bus, "fdt", locs,
&faa, fdt_print, fdt_scan_submatch);
}
}
@ -258,6 +290,9 @@ fdt_print(void *aux, const char *pnp)
char buf[FDT_MAX_PATH];
const char *name = buf;
if (faa->faa_quiet)
return QUIET;
/* Skip "not configured" for nodes w/o compatible property */
if (OF_getproplen(faa->faa_phandle, "compatible") <= 0)
return QUIET;

View File

@ -1,4 +1,4 @@
/* $NetBSD: fdtvar.h,v 1.12 2017/04/22 21:47:41 jmcneill Exp $ */
/* $NetBSD: fdtvar.h,v 1.13 2017/04/26 01:51:52 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca>
@ -45,6 +45,7 @@ struct fdt_attach_args {
bus_space_tag_t faa_a4x_bst;
bus_dma_tag_t faa_dmat;
int faa_phandle;
int faa_quiet;
};
/* flags for fdtbus_intr_establish */

View File

@ -1,4 +1,4 @@
# $NetBSD: files.fdt,v 1.10 2017/04/22 13:24:20 jmcneill Exp $
# $NetBSD: files.fdt,v 1.11 2017/04/26 01:51:52 jmcneill Exp $
include "external/bsd/libfdt/conf/files.libfdt"
@ -6,7 +6,7 @@ defflag opt_fdt.h FDT: libfdt, ofw_subr
define fdtbus { } : clk
device fdt { } : fdtbus
device fdt { [pass = 10] } : fdtbus
attach fdt at fdtbus
file dev/fdt/fdtbus.c fdt