Reorganize MI intersil7170(4) TOD clock driver:

- make intersil7170_softc more generic and allocate it during autoconf(9)
  rather than MALLOC(9) in attachment
- put todr_chip_handle_t, year0 value, and the century adjustment flag
  into the intersil7170_softc
- change the attachment function to just take the softc like mk48txx(4)
- split sys/dev/ic/intersil7170.h into intersil7170reg.h and intersil7170var.h
- cleanup some macro

Untested on real sun4 machines, but no objection on port-sparc
(and port-sun3) in three days.
This commit is contained in:
tsutsui 2006-10-04 15:04:43 +00:00
parent 2f0f18be71
commit 2f49bc32a3
4 changed files with 141 additions and 97 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: oclock.c,v 1.13 2006/09/03 22:27:45 gdamore Exp $ */
/* $NetBSD: oclock.c,v 1.14 2006/10/04 15:04:43 tsutsui Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -44,7 +44,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: oclock.c,v 1.13 2006/09/03 22:27:45 gdamore Exp $");
__KERNEL_RCSID(0, "$NetBSD: oclock.c,v 1.14 2006/10/04 15:04:43 tsutsui Exp $");
#include "opt_sparc_arch.h"
@ -58,7 +58,8 @@ __KERNEL_RCSID(0, "$NetBSD: oclock.c,v 1.13 2006/09/03 22:27:45 gdamore Exp $");
#include <machine/autoconf.h>
#include <dev/clock_subr.h>
#include <dev/ic/intersil7170.h>
#include <dev/ic/intersil7170reg.h>
#include <dev/ic/intersil7170var.h>
/* Imported from clock.c: */
extern int oldclk;
@ -69,24 +70,20 @@ extern void (*timer_init)(void);
static int oclockmatch(struct device *, struct cfdata *, void *);
static void oclockattach(struct device *, struct device *, void *);
CFATTACH_DECL(oclock, sizeof(struct device),
CFATTACH_DECL(oclock, sizeof(struct intersil7170_softc),
oclockmatch, oclockattach, NULL, NULL);
#if defined(SUN4)
static bus_space_tag_t i7_bt;
static bus_space_handle_t i7_bh;
#define intersil_command(run, interrupt) \
(run | interrupt | INTERSIL_CMD_FREQ_32K | INTERSIL_CMD_24HR_MODE | \
INTERSIL_CMD_NORMAL_MODE)
#define intersil_disable() \
bus_space_write_1(i7_bt, i7_bh, INTERSIL_ICMD, \
INTERSIL_COMMAND(INTERSIL_CMD_RUN, INTERSIL_CMD_IDISABLE));
#define intersil_disable() \
bus_space_write_1(i7_bt, i7_bh, INTERSIL_ICMD, \
intersil_command(INTERSIL_CMD_RUN, INTERSIL_CMD_IDISABLE));
#define intersil_enable() \
bus_space_write_1(i7_bt, i7_bh, INTERSIL_ICMD, \
intersil_command(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE));
#define intersil_enable() \
bus_space_write_1(i7_bt, i7_bh, INTERSIL_ICMD, \
INTERSIL_COMMAND(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE));
#define intersil_clear() bus_space_read_1(i7_bt, i7_bh, INTERSIL_IINTR)
@ -129,22 +126,21 @@ oclockattach(struct device *parent, struct device *self, void *aux)
#if defined(SUN4)
union obio_attach_args *uoba = aux;
struct obio4_attach_args *oba = &uoba->uoba_oba4;
bus_space_tag_t bt = oba->oba_bustag;
bus_space_handle_t bh;
todr_chip_handle_t tch;
struct intersil7170_softc *sc = (void *)self;
oldclk = 1; /* we've got an oldie! */
if (bus_space_map(bt,
sc->sc_bst = oba->oba_bustag;
if (bus_space_map(sc->sc_bst,
oba->oba_paddr,
sizeof(struct intersil7170),
BUS_SPACE_MAP_LINEAR, /* flags */
&bh) != 0) {
&sc->sc_bsh) != 0) {
printf("%s: can't map register\n", self->dv_xname);
return;
}
i7_bt = bt;
i7_bh = bh;
i7_bt = sc->sc_bst;
i7_bh = sc->sc_bsh;
/*
* calibrate delay()
@ -154,8 +150,8 @@ oclockattach(struct device *parent, struct device *self, void *aux)
int ival;
/* Set to 1/100 second interval */
bus_space_write_1(bt, bh, INTERSIL_IINTR,
INTERSIL_INTER_CSECONDS);
bus_space_write_1(sc->sc_bst, sc->sc_bsh, INTERSIL_IINTR,
INTERSIL_INTER_CSECONDS);
/* enable clock */
intersil_enable();
@ -192,10 +188,11 @@ oclockattach(struct device *parent, struct device *self, void *aux)
intr_establish(10, 0, &level10, NULL);
/* Our TOD clock year 0 represents 1968 */
if ((tch = intersil7170_attach(bt, bh, 1968)) == NULL)
panic("Can't attach tod clock");
sc->sc_year0 = 1968;
intersil7170_attach(sc);
printf("\n");
todr_attach(tch);
todr_attach(&sc->sc_handle);
#endif /* SUN4 */
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: intersil7170.c,v 1.7 2006/09/07 05:09:29 gdamore Exp $ */
/* $NetBSD: intersil7170.c,v 1.8 2006/10/04 15:04:43 tsutsui Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
@ -40,56 +40,37 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: intersil7170.c,v 1.7 2006/09/07 05:09:29 gdamore Exp $");
__KERNEL_RCSID(0, "$NetBSD: intersil7170.c,v 1.8 2006/10/04 15:04:43 tsutsui Exp $");
#include <sys/param.h>
#include <sys/malloc.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/errno.h>
#include <machine/bus.h>
#include <dev/clock_subr.h>
#include <dev/ic/intersil7170.h>
#define intersil_command(run, interrupt) \
(run | interrupt | INTERSIL_CMD_FREQ_32K | INTERSIL_CMD_24HR_MODE | \
INTERSIL_CMD_NORMAL_MODE)
struct intersil7170_softc {
bus_space_tag_t sil_bt;
bus_space_handle_t sil_bh;
int sil_year0;
};
#include <dev/ic/intersil7170reg.h>
#include <dev/ic/intersil7170var.h>
int intersil7170_gettime_ymdhms(todr_chip_handle_t, struct clock_ymdhms *);
int intersil7170_settime_ymdhms(todr_chip_handle_t, struct clock_ymdhms *);
int intersil7170_auto_century_adjust = 1;
todr_chip_handle_t
intersil7170_attach(bus_space_tag_t bt, bus_space_handle_t bh, int year0)
void
intersil7170_attach(struct intersil7170_softc *sc)
{
todr_chip_handle_t handle;
struct intersil7170_softc *sil;
int sz;
printf(": intersil7170");
sz = ALIGN(sizeof(struct todr_chip_handle)) + sizeof(struct intersil7170);
handle = malloc(sz, M_DEVBUF, M_NOWAIT);
sil = (struct intersil7170_softc *)((u_long)handle +
ALIGN(sizeof(struct todr_chip_handle)));
handle->cookie = sil;
handle = &sc->sc_handle;
handle->cookie = sc;
handle->todr_gettime = NULL;
handle->todr_settime = NULL;
handle->todr_setwen = NULL;
handle->todr_gettime_ymdhms = intersil7170_gettime_ymdhms;
handle->todr_settime_ymdhms = intersil7170_settime_ymdhms;
sil->sil_bt = bt;
sil->sil_bh = bh;
sil->sil_year0 = year0;
return (handle);
handle->todr_setwen = NULL;
}
/*
@ -98,10 +79,10 @@ intersil7170_attach(bus_space_tag_t bt, bus_space_handle_t bh, int year0)
int
intersil7170_gettime_ymdhms(todr_chip_handle_t handle, struct clock_ymdhms *dt)
{
struct intersil7170_softc *sil = handle->cookie;
bus_space_tag_t bt = sil->sil_bt;
bus_space_handle_t bh = sil->sil_bh;
u_int8_t cmd;
struct intersil7170_softc *sc = handle->cookie;
bus_space_tag_t bt = sc->sc_bst;
bus_space_handle_t bh = sc->sc_bsh;
uint8_t cmd;
int year;
int s;
@ -109,11 +90,11 @@ intersil7170_gettime_ymdhms(todr_chip_handle_t handle, struct clock_ymdhms *dt)
s = splhigh();
/* Enable read (stop time) */
cmd = intersil_command(INTERSIL_CMD_STOP, INTERSIL_CMD_IENABLE);
cmd = INTERSIL_COMMAND(INTERSIL_CMD_STOP, INTERSIL_CMD_IENABLE);
bus_space_write_1(bt, bh, INTERSIL_ICMD, cmd);
/* The order of reading out the clock elements is important */
bus_space_read_1(bt, bh, INTERSIL_ICSEC); /* not used */
(void)bus_space_read_1(bt, bh, INTERSIL_ICSEC); /* not used */
dt->dt_hour = bus_space_read_1(bt, bh, INTERSIL_IHOUR);
dt->dt_min = bus_space_read_1(bt, bh, INTERSIL_IMIN);
dt->dt_sec = bus_space_read_1(bt, bh, INTERSIL_ISEC);
@ -123,17 +104,18 @@ intersil7170_gettime_ymdhms(todr_chip_handle_t handle, struct clock_ymdhms *dt)
dt->dt_wday = bus_space_read_1(bt, bh, INTERSIL_IDOW);
/* Done writing (time wears on) */
cmd = intersil_command(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE);
cmd = INTERSIL_COMMAND(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE);
bus_space_write_1(bt, bh, INTERSIL_ICMD, cmd);
splx(s);
year += sil->sil_year0;
if (year < 1970 && intersil7170_auto_century_adjust != 0)
year += sc->sc_year0;
if (year < POSIX_BASE_YEAR &&
(sc->sc_flag & INTERSIL7170_NO_CENT_ADJUST) == 0)
year += 100;
dt->dt_year = year;
return (0);
return 0;
}
/*
@ -142,22 +124,22 @@ intersil7170_gettime_ymdhms(todr_chip_handle_t handle, struct clock_ymdhms *dt)
int
intersil7170_settime_ymdhms(todr_chip_handle_t handle, struct clock_ymdhms *dt)
{
struct intersil7170_softc *sil = handle->cookie;
bus_space_tag_t bt = sil->sil_bt;
bus_space_handle_t bh = sil->sil_bh;
u_int8_t cmd;
struct intersil7170_softc *sc = handle->cookie;
bus_space_tag_t bt = sc->sc_bst;
bus_space_handle_t bh = sc->sc_bsh;
uint8_t cmd;
int year;
int s;
year = dt->dt_year - sil->sil_year0;
if (year > 99 && intersil7170_auto_century_adjust != 0)
year = dt->dt_year - sc->sc_year0;
if (year > 99 && (sc->sc_flag & INTERSIL7170_NO_CENT_ADJUST) == 0)
year -= 100;
/* No interrupts while we're fiddling with the chip */
s = splhigh();
/* Enable write (stop time) */
cmd = intersil_command(INTERSIL_CMD_STOP, INTERSIL_CMD_IENABLE);
cmd = INTERSIL_COMMAND(INTERSIL_CMD_STOP, INTERSIL_CMD_IENABLE);
bus_space_write_1(bt, bh, INTERSIL_ICMD, cmd);
/* The order of reading writing the clock elements is important */
@ -171,9 +153,9 @@ intersil7170_settime_ymdhms(todr_chip_handle_t handle, struct clock_ymdhms *dt)
bus_space_write_1(bt, bh, INTERSIL_IDOW, dt->dt_wday);
/* Done writing (time wears on) */
cmd = intersil_command(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE);
cmd = INTERSIL_COMMAND(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE);
bus_space_write_1(bt, bh, INTERSIL_ICMD, cmd);
splx(s);
return (0);
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: intersil7170.h,v 1.4 2000/11/11 11:18:07 pk Exp $ */
/* $NetBSD: intersil7170reg.h,v 1.1 2006/10/04 15:04:43 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -36,8 +36,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _INTERSIL7170_H
#define _INTERSIL7170_H
#ifndef _INTERSIL7170REG_H_
#define _INTERSIL7170REG_H_
/*
* Driver support for the intersil7170 used in sun[34]s to provide
@ -54,22 +54,22 @@
* manipulating the TOD.
*/
struct intersil_dt { /* from p. 7 of 10 */
u_int8_t dt_csec;
u_int8_t dt_hour;
u_int8_t dt_min;
u_int8_t dt_sec;
u_int8_t dt_month;
u_int8_t dt_day;
u_int8_t dt_year;
u_int8_t dt_dow;
};
struct intersil_dt { /* from p. 7 of 10 */
uint8_t dt_csec;
uint8_t dt_hour;
uint8_t dt_min;
uint8_t dt_sec;
uint8_t dt_month;
uint8_t dt_day;
uint8_t dt_year;
uint8_t dt_dow;
};
struct intersil7170 {
struct intersil_dt counters;
struct intersil_dt clk_ram; /* should be ok as both are word aligned */
u_int8_t clk_intr_reg;
u_int8_t clk_cmd_reg;
struct intersil_dt counters;
struct intersil_dt clk_ram; /* should be ok as both are word aligned */
uint8_t clk_intr_reg;
uint8_t clk_cmd_reg;
};
/* Indices to time-of-day clock registers */
@ -103,6 +103,10 @@ struct intersil7170 {
#define INTERSIL_CMD_TEST_MODE 0x20
#define INTERSIL_CMD_NORMAL_MODE 0x0
#define INTERSIL_COMMAND(run, interrupt) \
((run) | (interrupt) | INTERSIL_CMD_FREQ_32K | \
INTERSIL_CMD_24HR_MODE | INTERSIL_CMD_NORMAL_MODE)
/* bit assignments for interrupt register r/w, p 7 of 10 */
#define INTERSIL_INTER_ALARM 0x1 /* r/w */
@ -114,9 +118,7 @@ struct intersil7170 {
#define INTERSIL_INTER_DAYS 0x40 /* r/w */
#define INTERSIL_INTER_PENDING 0x80 /* read-only */
#define INTERSIL_INTER_BITS "\20\10PENDING\7DAYS\6HRS\5MIN\4SCDS\3DSEC\2CSEC\1ALARM"
#define INTERSIL_INTER_BITS \
"\20\10PENDING\7DAYS\6HRS\5MIN\4SCDS\3DSEC\2CSEC\1ALARM"
#ifndef sun3 /* XXX sun3 does not use MI driver, which needs bus_space(9) */
todr_chip_handle_t intersil7170_attach(bus_space_tag_t, bus_space_handle_t, int);
#endif
#endif /* _INTERSIL7170_H */
#endif /* _INTERSIL7170REG_H_ */

View File

@ -0,0 +1,63 @@
/* $NetBSD: intersil7170var.h,v 1.1 2006/10/04 15:04:43 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Adam Glass.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _INTERSIL7170VAR_H_
#define _INTERSIL7170VAR_H_
/*
* Driver support for the intersil7170 used in sun[34]s to provide
* real time clock and time-of-day support.
*/
struct intersil7170_softc {
struct device sc_dev;
bus_space_tag_t sc_bst; /* bus_space(9) tag */
bus_space_handle_t sc_bsh; /* bus_space(9) handle */
struct todr_chip_handle sc_handle; /* todr(9) handle */
u_int sc_year0; /* what year is represented on
the system by the chip's
year counter at 0 */
u_int sc_flag;
#define INTERSIL7170_NO_CENT_ADJUST 0x0001
};
/* common attach function */
void intersil7170_attach(struct intersil7170_softc *);
#endif /* _INTERSIL7170VAR_H_ */