コード例 #1
0
ファイル: eeprom.c プロジェクト: MarginC/kame
int
eeprom_attach(device_t dev, phandle_t node, bus_space_tag_t bt,
    bus_space_handle_t bh)
{
	struct timespec ts;
	struct idprom *idp;
	char *model;
	int error, i;
	u_int32_t h;

	if (OF_getprop_alloc(node, "model", 1, (void **)&model) == -1)
		panic("eeprom_attach: no model property");

	/* Our TOD clock year 0 is 1968 */
	if ((error = mk48txx_attach(dev, bt, bh, model, 1968)) != 0) {
		device_printf(dev, "Can't attach %s tod clock", model);
		free(model, M_OFWPROP);
		return (error);
	}
	/* XXX: register clock device */

	/* Get the host ID from the prom. */
	idp = (struct idprom *)((u_long)bh + IDPROM_OFFSET);
	h = bus_space_read_1(bt, bh, IDPROM_OFFSET +
	    offsetof(struct idprom, id_machine)) << 24;
	for (i = 0; i < 3; i++) {
		h |= bus_space_read_1(bt, bh, IDPROM_OFFSET +
		    offsetof(struct idprom, id_hostid[i])) << ((2 - i) * 8);
	}
	/* XXX: register host id */
	device_printf(dev, "hostid %x\n", (u_int)h);
	if (bootverbose) {
		mk48txx_gettime(dev, &ts);
		device_printf(dev, "current time: %ld.%09ld\n", (long)ts.tv_sec,
		    ts.tv_nsec);
	}

	return (0);
}
コード例 #2
0
ファイル: eeprom.c プロジェクト: JabirTech/Source
static int
eeprom_attach(device_t dev)
{
	struct mk48txx_softc *sc;
	struct timespec ts;
	int error, rid;

	sc = device_get_softc(dev);

	mtx_init(&sc->sc_mtx, "eeprom_mtx", NULL, MTX_DEF);

	rid = 0;
	sc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
	    RF_ACTIVE);
	if (sc->sc_res == NULL) {
		device_printf(dev, "cannot allocate resources\n");
		error = ENXIO;
		goto fail_mtx;
	}

	if ((sc->sc_model = ofw_bus_get_model(dev)) == NULL) {
		device_printf(dev, "cannot determine model\n");
		error = ENXIO;
		goto fail_res;
	}

	/* Our TOD clock year 0 is 1968. */
	sc->sc_year0 = 1968;
	/* Use default register read/write functions. */
	sc->sc_flag = 0;
	/*
	 * Generally, if the `eeprom' node has a `watchdog-enable' property
	 * this indicates that the watchdog part of the MK48T59 is usable,
	 * i.e. its RST pin is connected to the WDR input of the CPUs or
	 * something. The `eeprom' nodes of E250, E450 and the clock board
	 * variant in Exx00 have such properties. For E250 and E450 the
	 * watchdog just works, for Exx00 the delivery of the reset signal
	 * apparently has to be additionally enabled elsewhere...
	 * The OFW environment variable `watchdog-reboot?' is ignored for
	 * these watchdogs as they always trigger a system reset when they
	 * time out and can't be made to issue a break to the boot monitor
	 * instead.
	 */
	if (OF_getproplen(ofw_bus_get_node(dev), "watchdog-enable") != -1 &&
	    (strcmp(sparc64_model, "SUNW,Ultra-250") == 0 ||
	    strcmp(sparc64_model, "SUNW,Ultra-4") == 0))
		sc->sc_flag |= MK48TXX_WDOG_REGISTER | MK48TXX_WDOG_ENABLE_WDS;
	if ((error = mk48txx_attach(dev)) != 0) {
		device_printf(dev, "cannot attach time of day clock\n");
		goto fail_res;
	}

	if (bootverbose) {
		if (mk48txx_gettime(dev, &ts) != 0)
			device_printf(dev, "invalid time");
		else
			device_printf(dev, "current time: %ld.%09ld\n",
			    (long)ts.tv_sec, ts.tv_nsec);
	}

	return (0);

 fail_res:
	bus_release_resource(dev, SYS_RES_MEMORY, rid, sc->sc_res);
 fail_mtx:
	mtx_destroy(&sc->sc_mtx);

	return (error);
}