summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2013-01-13 16:51:57 +0000
committerrwatson <rwatson@FreeBSD.org>2013-01-13 16:51:57 +0000
commit121041d6012d5701a68cba36a535fcdd43ec5426 (patch)
tree958e777e8ff1bcc72641a1b32e7c7582ad9cd5c1
parent071be75e1503857eecbc19afd24d49846174b57d (diff)
downloadFreeBSD-src-121041d6012d5701a68cba36a535fcdd43ec5426.zip
FreeBSD-src-121041d6012d5701a68cba36a535fcdd43ec5426.tar.gz
Partially merge Perforce changeset 219942 to head:
Implement an FDT attachment for altera_avgen(4). Portions of the changeset updating DTS and device.hints will be merged separately. Sponsored by: DARPA, AFRL
-rw-r--r--sys/conf/files1
-rw-r--r--sys/dev/altera/avgen/altera_avgen_fdt.c75
2 files changed, 45 insertions, 31 deletions
diff --git a/sys/conf/files b/sys/conf/files
index 3da7697..a1bfbc7 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -638,6 +638,7 @@ dev/aic7xxx/aic7xxx_pci.c optional ahc pci
dev/alc/if_alc.c optional alc pci
dev/ale/if_ale.c optional ale pci
dev/altera/avgen/altera_avgen.c optional altera_avgen
+dev/altera/avgen/altera_avgen_fdt.c optional altera_avgen fdt
dev/altera/avgen/altera_avgen_nexus.c optional altera_avgen
dev/altera/sdcard/altera_sdcard.c optional altera_sdcard
dev/altera/sdcard/altera_sdcard_disk.c optional altera_sdcard
diff --git a/sys/dev/altera/avgen/altera_avgen_fdt.c b/sys/dev/altera/avgen/altera_avgen_fdt.c
index 38dd446..226d69e 100644
--- a/sys/dev/altera/avgen/altera_avgen_fdt.c
+++ b/sys/dev/altera/avgen/altera_avgen_fdt.c
@@ -51,22 +51,32 @@ __FBSDID("$FreeBSD$");
#include <vm/vm.h>
+#include <dev/fdt/fdt_common.h>
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+
#include <dev/altera/avgen/altera_avgen.h>
static int
-altera_avgen_nexus_probe(device_t dev)
+altera_avgen_fdt_probe(device_t dev)
{
- device_set_desc(dev, "Generic Altera Avalon device attachment");
- return (BUS_PROBE_DEFAULT);
+ if (ofw_bus_is_compatible(dev, "sri-cambridge,avgen")) {
+ device_set_desc(dev, "Generic Altera Avalon device attachment");
+ return (BUS_PROBE_DEFAULT);
+ }
+ return (ENXIO);
}
static int
-altera_avgen_nexus_attach(device_t dev)
+altera_avgen_fdt_attach(device_t dev)
{
struct altera_avgen_softc *sc;
- const char *str_fileio, *str_mmapio;
- const char *str_devname;
+ char *str_fileio, *str_mmapio;
+ char *str_devname;
+ phandle_t node;
+ pcell_t cell;
int devunit, error;
sc = device_get_softc(dev);
@@ -74,28 +84,25 @@ altera_avgen_nexus_attach(device_t dev)
sc->avg_unit = device_get_unit(dev);
/*
- * Query non-standard hints to find out what operations are permitted
- * on the device, and whether it is cached.
+ * Query driver-specific OpenFirmware properties to determine how to
+ * expose the device via /dev.
*/
str_fileio = NULL;
str_mmapio = NULL;
str_devname = NULL;
devunit = -1;
sc->avg_width = 1;
- error = resource_int_value(device_get_name(dev), device_get_unit(dev),
- ALTERA_AVALON_STR_WIDTH, &sc->avg_width);
- if (error != 0 && error != ENOENT) {
- device_printf(dev, "invalid %s\n", ALTERA_AVALON_STR_WIDTH);
- return (error);
- }
- (void)resource_string_value(device_get_name(dev),
- device_get_unit(dev), ALTERA_AVALON_STR_FILEIO, &str_fileio);
- (void)resource_string_value(device_get_name(dev),
- device_get_unit(dev), ALTERA_AVALON_STR_MMAPIO, &str_mmapio);
- (void)resource_string_value(device_get_name(dev),
- device_get_unit(dev), ALTERA_AVALON_STR_DEVNAME, &str_devname);
- (void)resource_int_value(device_get_name(dev), device_get_unit(dev),
- ALTERA_AVALON_STR_DEVUNIT, &devunit);
+ node = ofw_bus_get_node(dev);
+ if (OF_getprop(node, "sri-cambridge,width", &cell, sizeof(cell)) > 0)
+ sc->avg_width = cell;
+ (void)OF_getprop_alloc(node, "sri-cambridge,fileio", sizeof(char),
+ (void **)&str_fileio);
+ (void)OF_getprop_alloc(node, "sri-cambridge,mmapio", sizeof(char),
+ (void **)&str_mmapio);
+ (void)OF_getprop_alloc(node, "sri-cambridge,devname", sizeof(char),
+ (void **)&str_devname);
+ if (OF_getprop(node, "sri-cambridge,devunit", &cell, sizeof(cell)) > 0)
+ devunit = cell;
/* Memory allocation and checking. */
sc->avg_rid = 0;
@@ -110,11 +117,17 @@ altera_avgen_nexus_attach(device_t dev)
if (error != 0)
bus_release_resource(dev, SYS_RES_MEMORY, sc->avg_rid,
sc->avg_res);
+ if (str_fileio != NULL)
+ free(str_fileio, M_OFWPROP);
+ if (str_mmapio != NULL)
+ free(str_mmapio, M_OFWPROP);
+ if (str_devname != NULL)
+ free(str_devname, M_OFWPROP);
return (error);
}
static int
-altera_avgen_nexus_detach(device_t dev)
+altera_avgen_fdt_detach(device_t dev)
{
struct altera_avgen_softc *sc;
@@ -124,20 +137,20 @@ altera_avgen_nexus_detach(device_t dev)
return (0);
}
-static device_method_t altera_avgen_nexus_methods[] = {
- DEVMETHOD(device_probe, altera_avgen_nexus_probe),
- DEVMETHOD(device_attach, altera_avgen_nexus_attach),
- DEVMETHOD(device_detach, altera_avgen_nexus_detach),
+static device_method_t altera_avgen_fdt_methods[] = {
+ DEVMETHOD(device_probe, altera_avgen_fdt_probe),
+ DEVMETHOD(device_attach, altera_avgen_fdt_attach),
+ DEVMETHOD(device_detach, altera_avgen_fdt_detach),
{ 0, 0 }
};
-static driver_t altera_avgen_nexus_driver = {
+static driver_t altera_avgen_fdt_driver = {
"altera_avgen",
- altera_avgen_nexus_methods,
+ altera_avgen_fdt_methods,
sizeof(struct altera_avgen_softc),
};
static devclass_t altera_avgen_devclass;
-DRIVER_MODULE(avgen, nexus, altera_avgen_nexus_driver, altera_avgen_devclass,
- 0, 0);
+DRIVER_MODULE(avgen, simplebus, altera_avgen_fdt_driver,
+ altera_avgen_devclass, 0, 0);
OpenPOWER on IntegriCloud