Example #1
0
static void
mcclock_pnpbus_attach(device_t parent, device_t self, void *aux)
{
	struct mc146818_softc *sc = device_private(self);
	struct pnpbus_dev_attach_args *pna = aux;

	sc->sc_dev = self;
	sc->sc_bst = pna->pna_iot;
	if (pnpbus_io_map(&pna->pna_res, 0, &sc->sc_bst, &sc->sc_bsh)) {
		/* XXX should we panic instead? */
		aprint_error(": couldn't map clock I/O space\n");
		return;
	}

	if (pna->chipid == Dallas1585)
		have_ds1585 = 1;
	sc->sc_year0 = 1900;
	sc->sc_mcread = mcclock_pnpbus_read;
	sc->sc_mcwrite = mcclock_pnpbus_write;
	sc->sc_flag = MC146818_BCD;
	mc146818_attach(sc);

	aprint_normal("\n");

	(*sc->sc_mcwrite)(sc, MC_REGB, MC_REGB_24HR);
}
Example #2
0
void
tsrtc_attach(device_t parent, device_t self, void *aux)
{
	struct tsrtc_softc *tsc = device_private(self);
	struct mc146818_softc *sc = &tsc->sc_mc;
	struct tspld_attach_args *aa = aux;

	sc->sc_dev = self;
	tsc->sc_iot = aa->ta_iot;
	if (bus_space_map(tsc->sc_iot, TS7XXX_IO8_HWBASE + TS7XXX_RTCIDX,
	    1, 0, &tsc->sc_idxh))
		panic("tsrtc_attach: couldn't map clock I/O space");
	if (bus_space_map(tsc->sc_iot, TS7XXX_IO8_HWBASE + TS7XXX_RTCDAT,
	    1, 0, &tsc->sc_dath))
		panic("tsrtc_attach: couldn't map clock I/O space");

	sc->sc_year0 = 2000;
	sc->sc_mcread = tsrtc_read;
	sc->sc_mcwrite = tsrtc_write;
	sc->sc_flag = MC146818_BCD;
	mc146818_attach(sc);

	aprint_normal("\n");

	(*sc->sc_mcwrite)(sc, MC_REGB, MC_REGB_24HR);
}
static void
mcclock_isa_attach(device_t parent, device_t self, void *aux)
{
	struct mc146818_softc *sc = device_private(self);
	struct isa_attach_args *ia = aux;

	sc->sc_dev = self;
	sc->sc_bst = ia->ia_iot;
	if (bus_space_map(sc->sc_bst, ia->ia_io[0].ir_addr,
	    ia->ia_io[0].ir_size, 0, &sc->sc_bsh))
		panic("mcclock_isa_attach: couldn't map clock I/O space");

	sc->sc_year0 = ALGOR_YEAR_ZERO;
	sc->sc_flag = MC146818_NO_CENT_ADJUST;
	sc->sc_mcread = mcclock_isa_read;
	sc->sc_mcwrite = mcclock_isa_write;
	sc->sc_getcent = NULL;
	sc->sc_setcent = NULL;

	/*
	 * Turn interrupts off, just in case.  Need to leave the SQWE
	 * set, because that's the DRAM refresh signal on Rev. B boards.
	 */
	mcclock_isa_write(sc, MC_REGB, MC_REGB_SQWE | MC_REGB_BINARY |
	    MC_REGB_24HR);

	mc146818_attach(sc);

	aprint_normal("\n");
}
void
mcclock_attach(struct mc146818_softc *sc)
{

	sc->sc_year0 = 1900 + UNIX_YEAR_OFFSET;
	sc->sc_flag = 0;	/* BINARY, 24HR */

	mc146818_attach(sc);

	aprint_normal("\n");

	/* Turn interrupts off, just in case. */
	(*sc->sc_mcwrite)(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);

	mcclock_set_pcc_freq(sc);

	clockattach(mcclock_init, (void *)sc);
}
Example #5
0
void
mcclock_isa_attach(device_t parent, device_t self, void *aux)
{
	struct mc146818_softc *sc = device_private(self);
	struct isa_attach_args *ia = aux;

	sc->sc_dev = self;
	sc->sc_bst = ia->ia_iot;
	if (bus_space_map(sc->sc_bst, ia->ia_io[0].ir_addr,
		ia->ia_io[0].ir_size, 0, &sc->sc_bsh)) {
		aprint_error(": can't map registers!\n");
		return;
	}

	/*
	 * Select a 32KHz crystal, periodic interrupt every 1024 Hz.
	 * XXX: We disable periodic interrupts, so why set a rate?
	 */
	mcclock_isa_write(sc, MC_REGA, MC_BASE_32_KHz | MC_RATE_1024_Hz);

	/*
	 * 24 Hour clock, no interrupts please.
	 */
	mcclock_isa_write(sc, MC_REGB, MC_REGB_24HR);

	sc->sc_year0 = 1900;
	sc->sc_flag = 0;
	sc->sc_mcread = mcclock_isa_read;
	sc->sc_mcwrite = mcclock_isa_write;
#if 0
	/*
	 * XXX: perhaps on some systems we should manage the century byte?
	 * For now we don't worry about it.  (Ugly MD code.)
	 */
	sc->sc_getcent = mcclock_isa_getcent;
	sc->sc_setcent = mcclock_isa_setcent;
#endif
	mc146818_attach(sc);
	aprint_normal("\n");
}
Example #6
0
void
mcclock_isa_attach(device_t parent, device_t self, void *aux)
{
	struct mc146818_softc *sc = device_private(self);
	struct isa_attach_args *ia = aux;

	sc->sc_dev = self;
	sc->sc_bst = ia->ia_iot;
	if (bus_space_map(sc->sc_bst, ia->ia_io[0].ir_addr,
	    ia->ia_io[0].ir_size, 0, &sc->sc_bsh))
		panic("mcclock_isa_attach: couldn't map clock I/O space");

	sc->sc_year0 = 1980;
	sc->sc_mcread  = mc_isa_read;
	sc->sc_mcwrite = mc_isa_write;

	mc146818_attach(sc);

	aprint_normal("\n");

	/* Turn interrupts off, just in case. */
	mc_isa_write(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);
}
Example #7
0
File: rtc.c Project: MarginC/kame
static int
rtc_attach(device_t dev)
{
	struct timespec ts;
	struct mc146818_softc *sc;
	struct resource *res;
	int error, rid;

	sc = device_get_softc(dev);
	bzero(sc, sizeof(struct mc146818_softc));

	rid = 0;
	res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
	if (res == NULL) {
		device_printf(dev, "could not allocate resources\n");
		return (ENXIO);
	}
	sc->sc_bst = rman_get_bustag(res);
	sc->sc_bsh = rman_get_bushandle(res);

	/* The TOD clock year 0 is 0. */
	sc->sc_year0 = 0;
	/* Use default register read/write and century get/set functions. */
	sc->sc_flag = MC146818_NO_CENT_ADJUST;
	if ((error = mc146818_attach(dev)) != 0) {
		device_printf(dev, "cannot attach time of day clock\n");
		return (error);
	}

	if (bootverbose) {
		mc146818_gettime(dev, &ts);
		device_printf(dev, "current time: %ld.%09ld\n", (long)ts.tv_sec,
		    ts.tv_nsec);
        }

	return (0);
}
Example #8
0
static int
rtc_attach(device_t dev)
{
	struct timespec ts;
	struct mc146818_softc *sc;
	struct resource *res;
	int ebus, error, rid;

	sc = device_get_softc(dev);

	mtx_init(&sc->sc_mtx, "rtc_mtx", NULL, MTX_SPIN);

	ebus = 0;
	if (strcmp(device_get_name(device_get_parent(dev)), "ebus") == 0)
		ebus = 1;

	rid = 0;
	res = bus_alloc_resource_any(dev, ebus ? SYS_RES_MEMORY :
	    SYS_RES_IOPORT, &rid, RF_ACTIVE);
	if (res == NULL) {
		device_printf(dev, "cannot allocate resources\n");
		error = ENXIO;
		goto fail_mtx;
	}
	sc->sc_bst = rman_get_bustag(res);
	sc->sc_bsh = rman_get_bushandle(res);

	sc->sc_mcread = RTC_READ;
	sc->sc_mcwrite = RTC_WRITE;
	/* The TOD clock year 0 is 0. */
	sc->sc_year0 = 0;
	/*
	 * For ISA use the default century get/set functions, for EBus we
	 * provide our own versions.
	 */
	sc->sc_flag = MC146818_NO_CENT_ADJUST;
	if (ebus) {
		/*
		 * Make sure the CR is at the default location (also used
		 * by Solaris).
		 */
		RTC_WRITE(dev, MC_REGA, PC87317_APC);
		RTC_WRITE(dev, PC87317_APC_CADDR, PC87317_APC_CADDR_BANK1 |
		    PC87317_RTC_CR);
		RTC_WRITE(dev, MC_REGA, PC87317_COMMON);
		sc->sc_getcent = pc87317_getcent;
		sc->sc_setcent = pc87317_setcent;
	}
	if ((error = mc146818_attach(dev)) != 0) {
		device_printf(dev, "cannot attach time of day clock\n");
		goto fail_res;
	}

	if (bootverbose) {
		if (mc146818_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, ebus ? SYS_RES_MEMORY : SYS_RES_IOPORT, rid,
	    res);
 fail_mtx:
	mtx_destroy(&sc->sc_mtx);

	return (error);
}