예제 #1
0
파일: nfc_mv.c 프로젝트: coyizumi/cs111
static int
mv_nand_attach(device_t dev)
{
	struct mv_nand_softc *sc;
	int err;

	sc = device_get_softc(dev);
	sc->res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->rid,
	    RF_ACTIVE);
	if (sc->res == NULL) {
		device_printf(dev, "could not allocate resources!\n");
		return (ENXIO);
	}

	sc->sc_tag = rman_get_bustag(sc->res);
	sc->sc_handle = rman_get_bushandle(sc->res);

	nand_init(&sc->nand_dev, dev, NAND_ECC_SOFT, 0, 0, NULL, NULL);

	err = nandbus_create(dev);

	return (err);
}
예제 #2
0
static int
nandsim_attach(device_t dev)
{
	struct nandsim_softc *sc;
	struct sim_ctrl_conf *params;
	struct sim_chip *chip;
	uint16_t *eccpos;
	int i, err;

	sc = device_get_softc(dev);
	params = &ctrls[device_get_unit(dev)];

	if (strlen(params->filename) == 0)
		snprintf(params->filename, FILENAME_SIZE, "ctrl%d.log",
		    params->num);

	nandsim_log_init(sc, params->filename);
	for (i = 0; i < params->num_cs; i++) {
		chip = params->chips[i];
		if (chip && chip->device_id != 0) {
			sc->chips[i] = nandsim_chip_init(sc, i, chip);
			if (chip->features & ONFI_FEAT_16BIT)
				sc->nand_dev.flags |= NAND_16_BIT;
		}
	}

	if (params->ecc_layout[0] != 0xffff)
		eccpos = params->ecc_layout;
	else
		eccpos = NULL;

	nand_init(&sc->nand_dev, dev, params->ecc, 0, 0, eccpos, "nandsim");

	err = nandbus_create(dev);

	return (err);
}
예제 #3
0
파일: nfc_rb.c 프로젝트: hmatyschok/MeshBSD
static int
rb_nand_attach(device_t dev)
{
	struct rb_nand_softc *sc;
	phandle_t node;
	uint32_t ale[2],cle[2],nce[2],rdy[2];
	u_long size,start;
	int err;

	sc = device_get_softc(dev);
	node = ofw_bus_get_node(dev);

	if (OF_getprop(node, "ale", ale, sizeof(ale)) <= 0) {
		return (ENXIO);
	}
	if (OF_getprop(node, "cle", cle, sizeof(cle)) <= 0) {
		return (ENXIO);
	}
	if (OF_getprop(node, "nce", nce, sizeof(nce)) <= 0) {
		return (ENXIO);
	}
	if (OF_getprop(node, "rdy", rdy, sizeof(rdy)) <= 0) {
		return (ENXIO);
	}

	if (ale[0] != cle[0] || ale[0] != nce[0] || ale[0] != rdy[0]) {
		device_printf(dev, "GPIO handles for signals must match.\n");
		return (ENXIO);
	}
	sc->sc_ale_pin = ale[1];
	sc->sc_cle_pin = cle[1];
	sc->sc_nce_pin = nce[1];
	sc->sc_rdy_pin = rdy[1];

	sc->sc_gpio = OF_device_from_xref(ale[0]);
	if (sc->sc_gpio == NULL) {
		device_printf(dev, "No GPIO resource found!\n");
		return (ENXIO);
	}

	sc->sc_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->rid,
	    RF_ACTIVE);
	if (sc->sc_mem == NULL) {
		device_printf(dev, "could not allocate resources!\n");
		return (ENXIO);
	}

	start = rman_get_start(sc->sc_mem);
	size = rman_get_size(sc->sc_mem);
	if (law_enable(OCP85XX_TGTIF_LBC, start, size) != 0) {
		bus_release_resource(dev, SYS_RES_MEMORY, sc->rid, sc->sc_mem);
		device_printf(dev, "could not allocate local address window.\n");
		return (ENXIO);
	}

	nand_init(&sc->nand_dev, dev, NAND_ECC_SOFT, 0, 0, NULL, NULL);

	err = nandbus_create(dev);

	return (err);
}