コード例 #1
0
ファイル: mk48txx.c プロジェクト: Tommmster/netbsd-avr32
void
mk48txx_attach(struct mk48txx_softc *sc)
{
	todr_chip_handle_t handle;
	int i;

	aprint_normal(": %s", sc->sc_model);

	i = __arraycount(mk48txx_models);
	while (--i >= 0) {
		if (strcmp(sc->sc_model, mk48txx_models[i].name) == 0)
			break;
	}
	if (i < 0)
		panic("%s: unsupported model", __func__);

	sc->sc_nvramsz = mk48txx_models[i].nvramsz;
	sc->sc_clkoffset = mk48txx_models[i].clkoff;

	handle = &sc->sc_handle;
	handle->cookie = sc;
	handle->todr_gettime = NULL;
	handle->todr_settime = NULL;
	handle->todr_gettime_ymdhms = mk48txx_gettime_ymdhms;
	handle->todr_settime_ymdhms = mk48txx_settime_ymdhms;

	if (sc->sc_nvrd == NULL)
		sc->sc_nvrd = mk48txx_def_nvrd;
	if (sc->sc_nvwr == NULL)
		sc->sc_nvwr = mk48txx_def_nvwr;

	todr_attach(handle);
}
コード例 #2
0
ファイル: omap_rtc.c プロジェクト: lacombar/netbsd-alc
void
omaprtc_attach(struct device *parent, struct device *self, void *aux)
{
	struct omaprtc_softc *sc = (struct omaprtc_softc*)self;
	struct tipb_attach_args *tipb = aux;

	sc->sc_iot = tipb->tipb_iot;
	sc->sc_intr = tipb->tipb_intr;

	if (bus_space_map(tipb->tipb_iot, tipb->tipb_addr, tipb->tipb_size, 0,
			 &sc->sc_ioh))
		panic("%s: Cannot map registers", self->dv_xname);

	aprint_normal(": OMAP RTC\n");
	aprint_naive("\n");

	/*
	 * Start RTC (STOP_RTC=1 starts it, go figure), 24 hour mode,
	 * no autocompensation, no rounding, 32KHz clock enabled,
	 * cannot use split power, no test mode.
	 */

	bus_space_write_1(sc->sc_iot, sc->sc_ioh, RTC_CTRL_REG,
			  1 << STOP_RTC);

	sc->sc_todr.cookie = sc;
	sc->sc_todr.todr_gettime_ymdhms = omaprtc_gettime;
	sc->sc_todr.todr_settime_ymdhms = omaprtc_settime;
	todr_attach(&sc->sc_todr);
}
コード例 #3
0
ファイル: rtc.c プロジェクト: yazshel/netbsd-kernel
static void
xirtc_attach(device_t parent, device_t self, void *aux)
{
	struct smbus_attach_args *sa = aux;
	struct rtc_softc *sc = device_private(self);

	rtcfound = 1;
	the_rtc = sc;

	sc->sc_dev = self;
	sc->sc_smbus_chan = sa->sa_interface;
	sc->sc_smbus_addr = sa->sa_device;
	sc->sc_type = SMB_2BYTE_ADDR;	/* Two-byte register addresses on the Xicor */


	/* Set up MI todr(9) stuff */
	sc->sc_ct.cookie = sc;
	sc->sc_ct.todr_settime_ymdhms = xirtc_settime;
	sc->sc_ct.todr_gettime_ymdhms = xirtc_gettime;

	todr_attach(&sc->sc_ct);

	aprint_normal("\n");
	rtc_cal_timer();	/* XXX */
}
コード例 #4
0
void
msm6242b_attach(struct msm6242b_softc *sc)
{
	struct clock_ymdhms dt;

	todr_chip_handle_t handle;
	aprint_normal(": OKI MSM6242B\n");

	handle = &sc->sc_handle;
	handle->cookie = sc;
	handle->todr_gettime = NULL;
	handle->todr_settime = NULL;
	handle->todr_gettime_ymdhms = msm6242b_gettime_ymdhms;
	handle->todr_settime_ymdhms = msm6242b_settime_ymdhms;
	handle->todr_setwen = NULL;

	if (msm6242b_gettime_ymdhms(handle, &dt) != 0) {
		aprint_error_dev(sc->sc_dev, "RTC does not work correctly\n");
		return;
	}

#ifdef MSM6242B_DEBUG
	aprint_normal_dev(sc->sc_dev, "the time is %d %d %d %d %d %d\n",
	    dt.dt_year, dt.dt_mon, dt.dt_day, dt.dt_hour, dt.dt_min, dt.dt_sec);
#endif /* MSM6242B_DEBUG */
	todr_attach(handle);
}
コード例 #5
0
ファイル: pxa2x0_rtc.c プロジェクト: lacombar/netbsd-alc
static void
pxartc_attach(struct device *parent, struct device *self, void *aux)
{
	struct pxartc_softc *sc = (struct pxartc_softc *)self;
	struct pxaip_attach_args *pxa = aux;

	sc->sc_iot = pxa->pxa_iot;

	aprint_normal(": PXA2x0 Real-time Clock\n");

	if (bus_space_map(sc->sc_iot, PXA2X0_RTC_BASE, pxa->pxa_size, 0,
	    &sc->sc_ioh)) {
		aprint_error("%s: couldn't map registers\n",
		    sc->sc_dev.dv_xname);
		return;
	}

	if (pxa->pxa_size == PXA270_RTC_SIZE) {
		aprint_normal("%s: using wristwatch register\n",
		    sc->sc_dev.dv_xname);
		sc->sc_flags |= FLAG_WRISTWATCH;
	}

	sc->sc_todr.cookie = sc;
	sc->sc_todr.todr_gettime = pxartc_todr_gettime;
	sc->sc_todr.todr_settime = pxartc_todr_settime;
	sc->sc_todr.todr_setwen = NULL;

	todr_attach(&sc->sc_todr);
}
コード例 #6
0
/* ARGSUSED */
static void
wmrtc_attach(device_t parent, device_t self, void *aux)
{
	struct wmrtc_softc *sc = device_private(self);
	struct windermere_attach_args *aa = aux;

	aprint_naive("\n");
	aprint_normal("\n");

	sc->sc_dev = self;
	if (windermere_bus_space_subregion(aa->aa_iot, *aa->aa_ioh,
				aa->aa_offset, aa->aa_size, &sc->sc_ioh) != 0) {
		aprint_error_dev(self, "can't map registers\n");
		return;
	}
	sc->sc_iot = aa->aa_iot;

	/* XXXX: reset to compare registers */
	bus_space_write_4(sc->sc_iot, sc->sc_ioh, RTC_MRL, 0);
	bus_space_write_4(sc->sc_iot, sc->sc_ioh, RTC_MRH, 0);

	sc->sc_todr.cookie = sc;
	sc->sc_todr.todr_gettime = wmrtc_todr_gettime;
	sc->sc_todr.todr_settime = wmrtc_todr_settime;
	sc->sc_todr.todr_setwen = NULL;
	todr_attach(&sc->sc_todr);
}
コード例 #7
0
ファイル: rtclock.c プロジェクト: lacombar/netbsd-alc
static void
rtc_attach(device_t parent, device_t self, void *aux)
{
	struct rtc_softc *sc = device_private(self);
	struct intio_attach_args *ia = aux;
	int r;

	rtc_attached = 1;

	ia->ia_size = 0x20;
	r = intio_map_allocate_region(parent, ia, INTIO_MAP_ALLOCATE);
#ifdef DIAGNOSTIC
	if (r)
		panic("IO map for RTC corruption??");
#endif


	sc->sc_bst = ia->ia_bst;
	bus_space_map(sc->sc_bst, ia->ia_addr, 0x2000, 0, &sc->sc_bht);

	sc->sc_todr.cookie = sc;
	sc->sc_todr.todr_gettime_ymdhms = rtgettod;
	sc->sc_todr.todr_settime_ymdhms = rtsettod;
	todr_attach(&sc->sc_todr);

	aprint_normal(": RP5C15\n");
}
コード例 #8
0
ファイル: rtc.c プロジェクト: lacombar/netbsd-alc
static void
rtcattach(device_t parent, device_t self, void *aux)
{
	struct rtc_softc *sc = device_private(self);
	struct intio_attach_args *ia = aux;
	struct todr_chip_handle *todr_handle;
	bus_space_tag_t bst = ia->ia_bst;

	sc->sc_dev = self;
	if (bus_space_map(bst, ia->ia_iobase, INTIO_DEVSIZE, 0,
	    &sc->sc_bsh)) {
		aprint_error(": can't map registers\n");
		return;
	}

	aprint_normal("\n");

	sc->sc_bst = bst;

	todr_handle = &sc->sc_handle;
	todr_handle->cookie = sc;
	todr_handle->todr_gettime = NULL;
	todr_handle->todr_settime = NULL;
	todr_handle->todr_gettime_ymdhms = rtc_gettime_ymdhms;
	todr_handle->todr_settime_ymdhms = rtc_settime_ymdhms;
	todr_handle->todr_setwen = NULL;

	todr_attach(todr_handle);
}
コード例 #9
0
void
ricohrtc_attach(struct device *parent, struct device *self, void *arg)
{
	struct ricohrtc_softc *sc = (struct ricohrtc_softc *)self;
	struct i2c_attach_args *ia = arg;

	printf(": RICOH RS5C372[AB] Real-time Clock\n");

	sc->sc_tag = ia->ia_tag;
	sc->sc_address = ia->ia_addr;
	sc->sc_todr.cookie = sc;
	sc->sc_todr.todr_gettime = ricohrtc_gettime;
	sc->sc_todr.todr_settime = ricohrtc_settime;
	sc->sc_todr.todr_getcal = ricohrtc_getcal;
	sc->sc_todr.todr_setcal = ricohrtc_setcal;
	sc->sc_todr.todr_setwen = NULL;

#if 0
	todr_attach(&sc->sc_todr);
#else
	/* XXX */
	{
	extern todr_chip_handle_t todr_handle;
	todr_handle = &sc->sc_todr;
	}
#endif

	/* Initialize RTC */
	ricohrtc_reg_write(sc, RICOHRTC_CONTROL2, RICOHRTC_CONTROL2_24HRS);
	ricohrtc_reg_write(sc, RICOHRTC_CONTROL1, 0);
}
コード例 #10
0
ファイル: ds1743.c プロジェクト: lacombar/netbsd-alc
static void
dsrtcattach(struct device *parent, struct device *self, void *aux)
{
	struct dsrtc_softc *sc = (struct dsrtc_softc *)self;
	struct pbus_attach_args *paa = aux;

	ds1743found = 1;
	
	sc->sc_iot = paa->pb_bt;
	if (bus_space_map(sc->sc_iot, paa->pb_addr, DS_SIZE, 0, &sc->sc_ioh)) {
		printf(": can't map i/o space\n");
		return;
	}

	ds1743_unlock(sc, 0);	/* Make sure the clock is running */
	if ((ds1743_read(sc, DS_DAY) & DS_CTL_BF) == 0)
		printf(": lithium cell is dead, RTC unreliable");
	printf("\n");

#ifdef DEBUG
	{
		rtc_t rtc;
		dsrtc_read(sc, &rtc);
		printf("RTC: %d/%d/%02d%02d %d:%02d:%02d\n",
			rtc.rtc_mon, rtc.rtc_day, rtc.rtc_cen, rtc.rtc_year,
			rtc.rtc_hour, rtc.rtc_min, rtc.rtc_sec);
	}
#endif

	sc->sc_todr.todr_gettime_ymdhms = dsrtc_read;
	sc->sc_todr.todr_settime_ymdhms = dsrtc_write;
	sc->sc_todr.cookie = sc;
	todr_attach(&sc->sc_todr);
}
コード例 #11
0
static void
pcf8563rtc_attach(device_t parent, device_t self, void *aux)
{
	struct pcf8563rtc_softc *sc = device_private(self);
	struct i2c_attach_args *ia = aux;

	aprint_naive(": Real-time Clock\n");
	aprint_normal(": NXP PCF8563 Real-time Clock\n");

	sc->sc_dev = self;
	sc->sc_tag = ia->ia_tag;
	sc->sc_addr = ia->ia_addr;
	sc->sc_todr.cookie = sc;
	sc->sc_todr.todr_gettime_ymdhms = pcf8563rtc_gettime;
	sc->sc_todr.todr_settime_ymdhms = pcf8563rtc_settime;
	sc->sc_todr.todr_setwen = NULL;

	iic_acquire_bus(sc->sc_tag, I2C_F_POLL);
	iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, PCF8563_R_CS1, 0,
	    I2C_F_POLL);
	iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, PCF8563_R_CS2, 0,
	    I2C_F_POLL);
	iic_release_bus(sc->sc_tag, I2C_F_POLL);

	todr_attach(&sc->sc_todr);
}
コード例 #12
0
ファイル: exynos_rtc.c プロジェクト: ryo/netbsd-src
static void
exynos_rtc_attach(device_t parent, device_t self, void *aux)
{
	struct exynos_rtc_softc * const sc
		= kmem_zalloc(sizeof(*sc), KM_SLEEP);
	struct fdt_attach_args * const faa = aux;
	bus_addr_t addr;
	bus_size_t size;
	int error;

	if (fdtbus_get_reg(faa->faa_phandle, 0, &addr, &size) != 0) {
		aprint_error(": couldn't get registers\n");
		return;
	}

	aprint_normal(" @ 0x%08x", (uint)addr);
	sc->sc_dev = self;
	sc->sc_bst = faa->faa_bst;
	error = bus_space_map(sc->sc_bst, addr, size, 0, &sc->sc_bsh);
	if (error) {
		aprint_error(": couldn't map %#llx: %d",
			     (uint64_t)addr, error);
		return;
	}

	aprint_naive("\n");
	aprint_normal(": RTC\n");

	sc->sc_todr.todr_gettime = exynos_rtc_gettime;
	sc->sc_todr.todr_settime = exynos_rtc_settime;
	sc->sc_todr.cookie = sc;
	todr_attach(&sc->sc_todr);

}
コード例 #13
0
ファイル: rtc.c プロジェクト: lacombar/netbsd-alc
/*
 * NB: This code should probably be converted to a _true_ device, then this
 * initialization could happen in attach.  The printf could get fixed then,
 * too.
 */
void
rtc_init(void)
{
	static struct todr_chip_handle tch;
	u_char val;
	
	scr2 = (u_int *)IIOV(NEXT_P_SCR2);
	val = rtc_read(RTC_STATUS);
	new_clock = (val & RTC_NEW_CLOCK) ? 1 : 0;

	printf("Looks like a %s clock chip.\n",
			(new_clock?
					"MCS1850 (new style)":
					"MC68HC68T1 (old style)"));

#ifdef RTC_DEBUG
	rtc_print();
#endif

	if (new_clock) {
		tch.todr_gettime = gettime_new;
		tch.todr_settime = settime_new;
		tch.todr_gettime_ymdhms = NULL;
		tch.todr_settime_ymdhms = NULL;
	} else {
		tch.todr_gettime_ymdhms = gettime_old;
		tch.todr_settime_ymdhms = settime_old;
		tch.todr_gettime = NULL;
		tch.todr_settime = NULL;
	}
	tch.todr_setwen = NULL;

	todr_attach(&tch);
}
コード例 #14
0
ファイル: pcf8583.c プロジェクト: MarginC/kame
void
pcfrtc_attach(struct device *parent, struct device *self, void *aux)
{
	struct pcfrtc_softc *sc = (struct pcfrtc_softc *)self;
	struct i2c_attach_args *ia = aux;
	uint8_t cmdbuf[1], csr;

	sc->sc_tag = ia->ia_tag;
	sc->sc_address = ia->ia_addr;

	aprint_naive(": Real-time Clock/NVRAM\n");
	aprint_normal(": PCF8583 Real-time Clock/NVRAM\n");

	cmdbuf[0] = PCF8583_REG_CSR;
	if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address,
	    cmdbuf, 1, &csr, 1, 0) != 0) {
		aprint_error("%s: unable to read CSR\n", sc->sc_dev.dv_xname);
		return;
	}
	aprint_normal("%s: ", sc->sc_dev.dv_xname);
	switch (csr & PCF8583_CSR_FN_MASK) {
	case PCF8583_CSR_FN_32768HZ:
		aprint_normal(" 32.768 kHz clock");
		break;

	case PCF8583_CSR_FN_50HZ:
		aprint_normal(" 50 Hz clock");
		break;

	case PCF8583_CSR_FN_EVENT:
		aprint_normal(" event counter");
		break;

	case PCF8583_CSR_FN_TEST:
		aprint_normal(" test mode");
		break;
	}
	if (csr & PCF8583_CSR_STOP)
		aprint_normal(", stopped");
	if (csr & PCF8583_CSR_ALARMENABLE)
		aprint_normal(", alarm enabled");
	aprint_normal("\n");

	sc->sc_open = 0;

	sc->sc_todr.cookie = sc;
	sc->sc_todr.todr_gettime = pcfrtc_gettime;
	sc->sc_todr.todr_settime = pcfrtc_settime;
	sc->sc_todr.todr_getcal = pcfrtc_getcal;
	sc->sc_todr.todr_setcal = pcfrtc_setcal;
	sc->sc_todr.todr_setwen = NULL;

	todr_attach(&sc->sc_todr);
}
コード例 #15
0
void
mcclock_attach(struct mcclock_softc *sc, const struct mcclock_busfns *busfns)
{

	printf(": mc146818 or compatible");

	sc->sc_busfns = busfns;

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

	clockattach(sc->sc_dev, &mcclock_clockfns);

	sc->sc_todr.todr_gettime = mcclock_get;
	sc->sc_todr.todr_settime = mcclock_set;
	sc->sc_todr.cookie = sc;
	todr_attach(&sc->sc_todr);
}
コード例 #16
0
ファイル: clock_ebus.c プロジェクト: ryo/netbsd-src
static void
eclock_ebus_attach(device_t parent, device_t self, void *aux)
{
    struct eclock_softc *sc = device_private(self);
    struct ebus_attach_args *ia = aux;

    sc->sc_dev = self;
    sc->sc_dp = (struct _Tc *)ia->ia_vaddr;

    /* NB: We are chopping our 64bit free-running down to 32bits */
    sc->sc_tc.tc_get_timecount = eclock_counter;
    sc->sc_tc.tc_poll_pps = 0;
    sc->sc_tc.tc_counter_mask = 0xffffffff;
    sc->sc_tc.tc_frequency = 10 * 1000 * 1000; /* 10 MHz */
    sc->sc_tc.tc_name = "eclock"; /* BUGBUG is it unique per instance?? */
    sc->sc_tc.tc_quality = 2000; /* uhu? */
    sc->sc_tc.tc_priv = sc;
    sc->sc_tc.tc_next = NULL;

#if DEBUG
    printf(" virt=%p ", (void *)sc->sc_dp);
#endif
    printf(": eMIPS clock\n");

    /* Turn interrupts off, just in case. */
    sc->sc_dp->Control &= ~(TCCT_INT_ENABLE|TCCT_INTERRUPT);

    ebus_intr_establish(parent, (void *)ia->ia_cookie, IPL_CLOCK,
                        eclock_ebus_intr, sc);

#ifdef EVCNT_COUNTERS
    evcnt_attach_dynamic(&clock_intr_evcnt, EVCNT_TYPE_INTR, NULL,
                         device_xname(self), "intr");
#endif

    clockdev = self;
    memset(&sc->sc_todr, 0, sizeof sc->sc_todr);
    sc->sc_todr.cookie = sc;
    sc->sc_todr.todr_gettime = eclock_gettime;
    sc->sc_todr.todr_settime = eclock_settime;
    todr_attach(&sc->sc_todr);

    tc_init(&sc->sc_tc);
}
コード例 #17
0
ファイル: imxsnvs.c プロジェクト: ryo/netbsd-src
/* ARGSUSED */
int
imxsnvs_attach_common(device_t parent __unused, device_t self,
                      bus_space_tag_t iot, paddr_t iobase, size_t size,
                      int intr __unused, int flags __unused)
{
	struct imxsnvs_softc *sc;
	uint32_t v1, v2;

	sc = device_private(self);
	sc->sc_dev = self;
	sc->sc_iot = iot;

	aprint_naive("\n");
	aprint_normal(": Secure Non-Volatile Storage\n");
	if (bus_space_map(sc->sc_iot, iobase, size, 0,
	    &sc->sc_ioh)) {
		aprint_error_dev(self, "Cannot map registers\n");
		return 1;
	}

	v1 = SNVS_READ(sc, SNVS_HPVIDR1);
	v2 = SNVS_READ(sc, SNVS_HPVIDR2);
	aprint_verbose_dev(self, "id=0x%llx, ver=%lld.%lld, ip_era=0x%llx, "
	    "intg_opt=0x%llx, eco_rev=0x%llx, config_opt=0x%llx\n",
	    __SHIFTOUT(v1, SNVS_HPVIDR1_IP_ID),
	    __SHIFTOUT(v1, SNVS_HPVIDR1_MAJOR_REV),
	    __SHIFTOUT(v1, SNVS_HPVIDR1_MINOR_REV),
	    __SHIFTOUT(v2, SNVS_HPVIDR2_IP_ERA),
	    __SHIFTOUT(v2, SNVS_HPVIDR2_INTG_OPT),
	    __SHIFTOUT(v2, SNVS_HPVIDR2_ECO_REV),
	    __SHIFTOUT(v2, SNVS_HPVIDR2_CONFIG_OPT));

	if (imxsnvs_rtc_enable(sc) != 0) {
		aprint_error_dev(self, "cannot enable RTC\n");
		return 1;
	}

	sc->sc_todr.todr_gettime = imxsnvs_gettime;
	sc->sc_todr.todr_settime = imxsnvs_settime;
	sc->sc_todr.cookie = sc;
	todr_attach(&sc->sc_todr);

	return 0;
}
コード例 #18
0
static void
pcf8563rtc_attach(device_t parent, device_t self, void *aux)
{
	struct pcf8563rtc_softc *sc = device_private(self);
	struct i2c_attach_args *ia = aux;

	aprint_naive(": Real-time Clock\n");
	aprint_normal(": NXP PCF8563 Real-time Clock\n");

	sc->sc_dev = self;
	sc->sc_tag = ia->ia_tag;
	sc->sc_addr = ia->ia_addr;
	sc->sc_todr.cookie = sc;
	sc->sc_todr.todr_gettime_ymdhms = pcf8563rtc_gettime;
	sc->sc_todr.todr_settime_ymdhms = pcf8563rtc_settime;
	sc->sc_todr.todr_setwen = NULL;

	todr_attach(&sc->sc_todr);
}
コード例 #19
0
ファイル: m41st84.c プロジェクト: Tommmster/netbsd-avr32
static void
strtc_attach(device_t parent, device_t self, void *arg)
{
	struct strtc_softc *sc = device_private(self);
	struct i2c_attach_args *ia = arg;

	aprint_naive(": Real-time Clock/NVRAM\n");
	aprint_normal(": M41ST84 Real-time Clock/NVRAM\n");

	sc->sc_tag = ia->ia_tag;
	sc->sc_address = ia->ia_addr;
	sc->sc_dev = self;
	sc->sc_open = 0;
	sc->sc_todr.cookie = sc;
	sc->sc_todr.todr_gettime = strtc_gettime;
	sc->sc_todr.todr_settime = strtc_settime;
	sc->sc_todr.todr_setwen = NULL;

	todr_attach(&sc->sc_todr);
}
コード例 #20
0
ファイル: vrtc.c プロジェクト: ryo/netbsd-src
void
vrtc_attach(device_t parent, device_t self, void *aux)
{
	todr_chip_handle_t handle;

	printf("\n");

	handle = malloc(sizeof(struct todr_chip_handle), M_DEVBUF,M_NOWAIT);
	if (handle == NULL)
		panic("couldn't allocate todr_handle");

	handle->cookie = self;
	handle->todr_gettime = vrtc_gettime;
	handle->todr_settime = vrtc_settime;

	handle->bus_cookie = NULL;
	handle->todr_setwen = NULL;

	todr_attach(handle);
}
コード例 #21
0
ファイル: eprtc.c プロジェクト: lacombar/netbsd-alc
static void
eprtc_attach(struct device *parent, struct device *self, void *aux)
{
	struct eprtc_softc *sc = (struct eprtc_softc*)self;
	struct epsoc_attach_args *sa = aux;

	printf("\n");
	sc->sc_iot = sa->sa_iot;

	if (bus_space_map(sa->sa_iot, sa->sa_addr,
			  sa->sa_size, 0, &sc->sc_ioh)){
		printf("%s: Cannot map registers", self->dv_xname);
		return;
	}

	sc->sc_todr.cookie = sc;
	sc->sc_todr.todr_gettime = eprtc_gettime;
	sc->sc_todr.todr_settime = eprtc_settime;
	sc->sc_todr.todr_setwen = NULL;
	todr_attach(&sc->sc_todr);
}
コード例 #22
0
void
m41t00_attach(device_t parent, device_t self, void *aux)
{
	struct m41t00_softc *sc = device_private(self);
	struct i2c_attach_args *ia = aux;

	sc->sc_tag = ia->ia_tag;
	sc->sc_address = ia->ia_addr;
	sc->sc_dev = self;

	aprint_naive(": Real-time Clock\n");
	aprint_normal(": M41T00 Real-time Clock\n");

	sc->sc_open = 0;
	sc->sc_todr.cookie = sc;
	sc->sc_todr.todr_gettime = m41t00_gettime;
	sc->sc_todr.todr_settime = m41t00_settime;
	sc->sc_todr.todr_setwen = NULL;

	todr_attach(&sc->sc_todr);
}
コード例 #23
0
ファイル: ac100.c プロジェクト: ryo/netbsd-src
static void
ac100_attach(device_t parent, device_t self, void *aux)
{
    struct ac100_softc *sc = device_private(self);
    struct i2c_attach_args *ia = aux;

    sc->sc_dev = self;
    sc->sc_i2c = ia->ia_tag;
    sc->sc_addr = ia->ia_addr;

    aprint_naive("\n");
    aprint_normal(": CODEC/RTC\n");

    iic_acquire_bus(sc->sc_i2c, 0);
    ac100_write(sc, AC100_RTC_CTRL_REG, AC100_RTC_CTRL_12H_24H_MODE);
    iic_release_bus(sc->sc_i2c, 0);

    sc->sc_todr.todr_gettime_ymdhms = ac100_rtc_gettime;
    sc->sc_todr.todr_settime_ymdhms = ac100_rtc_settime;
    sc->sc_todr.cookie = sc;
    todr_attach(&sc->sc_todr);
}
コード例 #24
0
ファイル: tod.c プロジェクト: lacombar/netbsd-alc
static void 
tod_attach(struct mm58167_softc *sc)
{
	todr_chip_handle_t	tch;

	/* Call the IC attach code. */
	sc->mm58167_msec_xxx = MM58167REG_MSEC_XXX;
	sc->mm58167_csec = MM58167REG_CSEC;
	sc->mm58167_sec = MM58167REG_SEC;
	sc->mm58167_min = MM58167REG_MIN;
	sc->mm58167_hour = MM58167REG_HOUR;
	sc->mm58167_wday = MM58167REG_WDAY;
	sc->mm58167_day = MM58167REG_DAY;
	sc->mm58167_mon = MM58167REG_MON;
	sc->mm58167_status = MM58167REG_STATUS;
	sc->mm58167_go = MM58167REG_GO;
	if ((tch = mm58167_attach(sc)) == NULL)
		panic("%s: can't attach ic", __func__);

	todr_attach(tch);
	aprint_normal("\n");
}
コード例 #25
0
void
rs5c313_attach(struct rs5c313_softc *sc)
{
	device_t self = sc->sc_dev;
	const char *model;

	switch (sc->sc_model) {
	case MODEL_5C313:
		model = "5C313";
		sc->sc_ctrl[0] = CTRL_24H;
		sc->sc_ctrl[1] = CTRL2_NTEST;
		break;

	case MODEL_5C316:
		model = "5C316";
		sc->sc_ctrl[0] = 0;
		sc->sc_ctrl[1] = CTRL2_24H|CTRL2_NTEST;
		break;
	
	default:
		aprint_error("unknown model (%d)\n", sc->sc_model);
		return;
	}

	aprint_naive("\n");
	aprint_normal(": RICOH %s real time clock\n", model);

	sc->sc_todr.cookie = sc;
	sc->sc_todr.todr_gettime_ymdhms = rs5c313_todr_gettime_ymdhms;
	sc->sc_todr.todr_settime_ymdhms = rs5c313_todr_settime_ymdhms;

	if (rs5c313_init(sc) != 0) {
		aprint_error_dev(self, "init failed\n");
		return;
	}

	todr_attach(&sc->sc_todr);
}
コード例 #26
0
ファイル: rs5c372.c プロジェクト: Tommmster/netbsd-avr32
static void
rs5c372rtc_attach(device_t parent, device_t self, void *arg)
{
	struct rs5c372rtc_softc *sc = device_private(self);
	struct i2c_attach_args *ia = arg;

	aprint_naive(": Real-time Clock\n");
	aprint_normal(": RICOH RS5C372[AB] Real-time Clock\n");

	sc->sc_tag = ia->ia_tag;
	sc->sc_address = ia->ia_addr;
	sc->sc_dev = self;
	sc->sc_todr.cookie = sc;
	sc->sc_todr.todr_gettime = rs5c372rtc_gettime;
	sc->sc_todr.todr_settime = rs5c372rtc_settime;
	sc->sc_todr.todr_setwen = NULL;

	todr_attach(&sc->sc_todr);

	/* Initialize RTC */
	rs5c372rtc_reg_write(sc, RS5C372_CONTROL2, RS5C372_CONTROL2_24HRS);
	rs5c372rtc_reg_write(sc, RS5C372_CONTROL1, 0);
}
コード例 #27
0
void
mcclock_mace_attach(device_t parent, device_t self, void *aux)
{
	struct mcclock_mace_softc *sc = device_private(self);
	struct mace_attach_args *maa = aux;

	sc->sc_dev = self;
	sc->sc_st = maa->maa_st;
	/* XXX should be bus_space_map() */
	if (bus_space_subregion(maa->maa_st, maa->maa_sh,
	    maa->maa_offset, 0, &sc->sc_sh))
		panic("mcclock_mace_attach: couldn't map");

	/*
	 * We want a fixed format: 24-hour, BCD data, so just force the
	 * RTC to this mode; if there was junk there we'll be able to
	 * fix things up later when we discover the time read back is
	 * no good.
	 */
	ds1687_write(sc, DS1687_CONTROLA, DS1687_DV1 | DS1687_BANK1);
	ds1687_write(sc, DS1687_CONTROLB, DS1687_24HRS);

	/* XXXrkb: init kickstart/wakeup stuff */

	if (!(ds1687_read(sc, DS1687_CONTROLD) & DS1687_VRT))
		printf(": lithium cell is dead, RTC unreliable");

	printf("\n");

	sc->sc_todrch.cookie = sc;
	sc->sc_todrch.todr_gettime_ymdhms = mcclock_mace_gettime_ymdhms;
	sc->sc_todrch.todr_settime_ymdhms = mcclock_mace_settime_ymdhms;
	sc->sc_todrch.todr_setwen = NULL;

	todr_attach(&sc->sc_todrch);
	mace0 = sc;
}
コード例 #28
0
static void
dsclock_attach(device_t parent, device_t self, void *aux)
{
	struct dsclock_softc *sc = device_private(self);
	struct mainbus_attach_args *ma = aux;
	int err;

	aprint_normal("\n");

	sc->sc_rtct = SGIMIPS_BUS_SPACE_HPC;
	if ((err = bus_space_map(sc->sc_rtct, ma->ma_addr, 0x1ffff,
	    BUS_SPACE_MAP_LINEAR, &sc->sc_rtch)) != 0) {
		aprint_error_dev(self,
		    "unable to map RTC registers, error = %d\n", err);
		return;
	}

	sc->sc_todrch.cookie = sc;
	sc->sc_todrch.todr_gettime_ymdhms = dsclock_gettime_ymdhms;
	sc->sc_todrch.todr_settime_ymdhms = dsclock_settime_ymdhms;
	sc->sc_todrch.todr_setwen = NULL;

	todr_attach(&sc->sc_todrch);
}
コード例 #29
0
ファイル: pmu.c プロジェクト: ycui1984/netbsd-src
static void
pmu_attach(device_t parent, device_t self, void *aux)
{
	struct confargs *ca = aux;
	struct pmu_softc *sc = device_private(self);
#if notyet
	struct i2cbus_attach_args iba;
#endif
	uint32_t regs[16];
	int irq = ca->ca_intr[0];
	int node, extint_node, root_node;
	int nbat = 1, i, pmnode;
	int type = IST_EDGE;
	uint8_t cmd[2] = {2, 0};
	uint8_t resp[16];
	char name[256];

	extint_node = of_getnode_byname(OF_parent(ca->ca_node), "extint-gpio1");
	if (extint_node) {

		OF_getprop(extint_node, "interrupts", &irq, 4);
		type = IST_LEVEL;
	}

	aprint_normal(" irq %d: ", irq);

	sc->sc_dev = self;
	sc->sc_node = ca->ca_node;
	sc->sc_memt = ca->ca_tag;

	root_node = OF_finddevice("/");

	sc->sc_error = 0;
	sc->sc_autopoll = 0;
	sc->sc_pending_eject = 0;
	sc->sc_brightness = sc->sc_brightness_wanted = 0x80;
	sc->sc_volume = sc->sc_volume_wanted = 0x80;
	sc->sc_flags = 0;
	sc->sc_callback = NULL;
	sc->sc_lid_closed = 0;

	if (bus_space_map(sc->sc_memt, ca->ca_reg[0] + ca->ca_baseaddr,
	    ca->ca_reg[1], 0, &sc->sc_memh) != 0) {
		aprint_error_dev(self, "unable to map registers\n");
		return;
	}
	sc->sc_ih = intr_establish(irq, type, IPL_TTY, pmu_intr, sc);

	pmu_init(sc);

	sc->sc_pmu_ops.cookie = sc;
	sc->sc_pmu_ops.do_command = pmu_send;
	sc->sc_pmu_ops.register_callback = pmu_register_callback;

	if (pmu0 == NULL)
		pmu0 = sc;

	pmu_send(sc, PMU_SYSTEM_READY, 1, cmd, 16, resp);

	/* check what kind of PMU we're talking to */
	if (pmu_send(sc, PMU_GET_VERSION, 0, cmd, 16, resp) > 1)
		aprint_normal(" rev. %d", resp[1]);
	aprint_normal("\n");

	node = OF_child(sc->sc_node);

	while (node != 0) {

		if (OF_getprop(node, "name", name, 256) == 0)
			goto next;

		if (strncmp(name, "pmu-i2c", 8) == 0) {
			aprint_normal_dev(self, "initializing IIC bus\n");
			goto next;
		}
		if (strncmp(name, "adb", 4) == 0) {
			aprint_normal_dev(self, "initializing ADB\n");
			sc->sc_adbops.cookie = sc;
			sc->sc_adbops.send = pmu_adb_send;
			sc->sc_adbops.poll = pmu_adb_poll;
			sc->sc_adbops.autopoll = pmu_autopoll;
			sc->sc_adbops.set_handler = pmu_adb_set_handler;
#if NNADB > 0
			config_found_ia(self, "adb_bus", &sc->sc_adbops,
			    nadb_print);
#endif
			goto next;
		}
		if (strncmp(name, "rtc", 4) == 0) {

			aprint_normal_dev(self, "initializing RTC\n");
			sc->sc_todr.todr_gettime = pmu_todr_get;
			sc->sc_todr.todr_settime = pmu_todr_set;
			sc->sc_todr.cookie = sc;
			todr_attach(&sc->sc_todr);
			goto next;
		}
		if (strncmp(name, "battery", 8) == 0)
			goto next;

		aprint_normal_dev(self, "%s not configured\n", name);
next:
		node = OF_peer(node);
	}

	if (OF_finddevice("/bandit/ohare") != -1) {
		aprint_normal_dev(self, "enabling ohare backlight control\n");
		sc->sc_flags |= PMU_HAS_BACKLIGHT_CONTROL;
		cmd[0] = 0;
		cmd[1] = 0;
		memset(resp, 0, 6);
		if (pmu_send(sc, PMU_READ_BRIGHTNESS, 1, cmd, 16, resp) > 1) {
			sc->sc_brightness_wanted = resp[1];
			pmu_update_brightness(sc);
		}
	}

	/* attach batteries */
	if (of_compatible(root_node, has_legacy_battery) != -1) {

		pmu_attach_legacy_battery(sc);
	} else if (of_compatible(root_node, has_two_smart_batteries) != -1) {

		pmu_attach_smart_battery(sc, 0);
		pmu_attach_smart_battery(sc, 1);
	} else {

		/* check how many batteries we have */
		pmnode = of_getnode_byname(ca->ca_node, "power-mgt");
		if (pmnode == -1)
			goto bat_done;
		if (OF_getprop(pmnode, "prim-info", regs, sizeof(regs)) < 24)
			goto bat_done;
		nbat = regs[6] >> 16;
		for (i = 0; i < nbat; i++)
			pmu_attach_smart_battery(sc, i);
	}
bat_done:

#if notyet
	memset(&iba, 0, sizeof(iba));
	iba.iba_tag = &sc->sc_i2c;
	sc->sc_i2c.ic_cookie = sc;
	sc->sc_i2c.ic_acquire_bus = pmu_i2c_acquire_bus;
	sc->sc_i2c.ic_release_bus = pmu_i2c_release_bus;
	sc->sc_i2c.ic_send_start = NULL;
	sc->sc_i2c.ic_send_stop = NULL;
	sc->sc_i2c.ic_initiate_xfer = NULL;
	sc->sc_i2c.ic_read_byte = NULL;
	sc->sc_i2c.ic_write_byte = NULL;
	sc->sc_i2c.ic_exec = pmu_i2c_exec;
	config_found_ia(sc->sc_dev, "i2cbus", &iba, iicbus_print);
#endif
	
	if (kthread_create(PRI_NONE, 0, NULL, pmu_thread, sc, &sc->sc_thread,
	    "%s", "pmu") != 0) {
		aprint_error_dev(self, "unable to create event kthread\n");
	}

	sc->sc_lidswitch.smpsw_name = "Lid switch";
	sc->sc_lidswitch.smpsw_type = PSWITCH_TYPE_LID;
	if (sysmon_pswitch_register(&sc->sc_lidswitch) != 0)
		aprint_error_dev(self,
		    "unable to register lid switch with sysmon\n");
}
コード例 #30
0
ファイル: cuda.c プロジェクト: lacombar/netbsd-alc
static void
cuda_attach(device_t parent, device_t dev, void *aux)
{
	struct confargs *ca = aux;
	struct cuda_softc *sc = device_private(dev);
	struct i2cbus_attach_args iba;
	static struct cuda_attach_args caa;
	int irq = ca->ca_intr[0];
	int node, i, child;
	char name[32];

	sc->sc_dev = dev;
	node = of_getnode_byname(OF_parent(ca->ca_node), "extint-gpio1");
	if (node)
		OF_getprop(node, "interrupts", &irq, 4);

	printf(" irq %d: ", irq);

	sc->sc_node = ca->ca_node;
	sc->sc_memt = ca->ca_tag;

	sc->sc_sent = 0;
	sc->sc_received = 0;
	sc->sc_waiting = 0;
	sc->sc_polling = 0;
	sc->sc_state = CUDA_NOTREADY;
	sc->sc_error = 0;
	sc->sc_i2c_read_len = 0;

	if (bus_space_map(sc->sc_memt, ca->ca_reg[0] + ca->ca_baseaddr,
	    ca->ca_reg[1], 0, &sc->sc_memh) != 0) {

		printf("%s: unable to map registers\n", dev->dv_xname);
		return;
	}
	sc->sc_ih = intr_establish(irq, IST_EDGE, IPL_TTY, cuda_intr, sc);
	printf("\n");

	for (i = 0; i < 16; i++) {
		sc->sc_handlers[i].handler = NULL;
		sc->sc_handlers[i].cookie = NULL;
	}

	cuda_init(sc);

	/* now attach children */
	config_interrupts(dev, cuda_final);
	cuda_set_handler(sc, CUDA_ERROR, cuda_error_handler, sc);
	cuda_set_handler(sc, CUDA_PSEUDO, cuda_todr_handler, sc);

	child = OF_child(ca->ca_node);
	while (child != 0) {

		if (OF_getprop(child, "name", name, 32) == 0)
			continue;
		if (strncmp(name, "adb", 4) == 0) {

			cuda_set_handler(sc, CUDA_ADB, cuda_adb_handler, sc);
			sc->sc_adbops.cookie = sc;
			sc->sc_adbops.send = cuda_adb_send;
			sc->sc_adbops.poll = cuda_adb_poll;
			sc->sc_adbops.autopoll = cuda_autopoll;
			sc->sc_adbops.set_handler = cuda_adb_set_handler;
			config_found_ia(dev, "adb_bus", &sc->sc_adbops,
			    nadb_print);
		} else if (strncmp(name, "rtc", 4) == 0) {

			sc->sc_todr.todr_gettime = cuda_todr_get;
			sc->sc_todr.todr_settime = cuda_todr_set;
			sc->sc_todr.cookie = sc;
			todr_attach(&sc->sc_todr);
		} 
		child = OF_peer(child);
	}

	caa.cookie = sc;
	caa.set_handler = cuda_set_handler;
	caa.send = cuda_send;
	caa.poll = cuda_poll;
#if notyet
	config_found(dev, &caa, cuda_print);
#endif
	mutex_init(&sc->sc_buslock, MUTEX_DEFAULT, IPL_NONE);
	iba.iba_tag = &sc->sc_i2c;
	sc->sc_i2c.ic_cookie = sc;
	sc->sc_i2c.ic_acquire_bus = cuda_i2c_acquire_bus;
	sc->sc_i2c.ic_release_bus = cuda_i2c_release_bus;
	sc->sc_i2c.ic_send_start = NULL;
	sc->sc_i2c.ic_send_stop = NULL;
	sc->sc_i2c.ic_initiate_xfer = NULL;
	sc->sc_i2c.ic_read_byte = NULL;
	sc->sc_i2c.ic_write_byte = NULL;
	sc->sc_i2c.ic_exec = cuda_i2c_exec;
	config_found_ia(sc->sc_dev, "i2cbus", &iba, iicbus_print);

	if (cuda0 == NULL)
		cuda0 = &caa;
}