From 4a60b0ecfe1337cc3acabdf789bdc53e1a549320 Mon Sep 17 00:00:00 2001 From: macallan Date: Wed, 26 Sep 2007 05:50:02 +0000 Subject: [PATCH] add mcclock_poweroff() --- sys/arch/sgimips/mace/files.mace | 4 +-- sys/arch/sgimips/mace/mcclock_mace.c | 42 ++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/sys/arch/sgimips/mace/files.mace b/sys/arch/sgimips/mace/files.mace index 1cb8af6e71d2..1c88796b0a5d 100644 --- a/sys/arch/sgimips/mace/files.mace +++ b/sys/arch/sgimips/mace/files.mace @@ -1,4 +1,4 @@ -# $NetBSD: files.mace,v 1.8 2007/04/13 03:39:44 jmcneill Exp $ +# $NetBSD: files.mace,v 1.9 2007/09/26 05:50:02 macallan Exp $ device mace {[offset = -1], [intr = -1], [intrmask = 0] } attach mace at mainbus @@ -16,7 +16,7 @@ file arch/sgimips/mace/macekbc.c macekbc device mcclock attach mcclock at mace with mcclock_mace -file arch/sgimips/mace/mcclock_mace.c mcclock_mace +file arch/sgimips/mace/mcclock_mace.c mcclock_mace needs-flag device mec: arp, ether, ifnet, mii attach mec at mace diff --git a/sys/arch/sgimips/mace/mcclock_mace.c b/sys/arch/sgimips/mace/mcclock_mace.c index 2f61ace1f191..e523c5269576 100644 --- a/sys/arch/sgimips/mace/mcclock_mace.c +++ b/sys/arch/sgimips/mace/mcclock_mace.c @@ -1,4 +1,4 @@ -/* $NetBSD: mcclock_mace.c,v 1.6 2007/07/24 14:41:29 pooka Exp $ */ +/* $NetBSD: mcclock_mace.c,v 1.7 2007/09/26 05:50:02 macallan Exp $ */ /* * Copyright (c) 2001 Antti Kantee. All Rights Reserved. @@ -65,7 +65,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mcclock_mace.c,v 1.6 2007/07/24 14:41:29 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mcclock_mace.c,v 1.7 2007/09/26 05:50:02 macallan Exp $"); #include #include @@ -91,6 +91,8 @@ struct mcclock_mace_softc { bus_space_handle_t sc_sh; }; +static struct mcclock_mace_softc *mace0 = NULL; + static int mcclock_mace_match(struct device *, struct cfdata *, void *); static void mcclock_mace_attach(struct device*, struct device *, void *); @@ -102,6 +104,9 @@ static int mcclock_mace_settime(struct todr_chip_handle *, unsigned int ds1687_read(void *arg, unsigned int addr); void ds1687_write(void *arg, unsigned int addr, unsigned int data); +void mcclock_poweroff(void); + + CFATTACH_DECL(mcclock_mace, sizeof(struct mcclock_mace_softc), mcclock_mace_match, mcclock_mace_attach, NULL, NULL); @@ -145,6 +150,7 @@ mcclock_mace_attach(struct device *parent, struct device *self, void *aux) sc->sc_todrch.todr_setwen = NULL; todr_attach(&sc->sc_todrch); + mace0 = sc; } /* @@ -231,3 +237,35 @@ mcclock_mace_settime(struct todr_chip_handle *todrch, return (0); } + +void +mcclock_poweroff() +{ + int s; + uint8_t a, xctl_a, xctl_b; + + if (mace0 == NULL) + return; + + s = splhigh(); + a = ds1687_read(mace0, DS1687_CONTROLA); + a &= ~DS1687_DV2; + a |= DS1687_DV1; + ds1687_write(mace0, DS1687_CONTROLA, a | DS1687_BANK1); + wbflush(); + + xctl_b = ds1687_read(mace0, DS1687_BANK1_XCTRL4B); + xctl_b |= DS1687_X4B_ABE | DS1687_X4B_KIE; + ds1687_write(mace0, DS1687_BANK1_XCTRL4B, xctl_b); + + xctl_a = ds1687_read(mace0, DS1687_BANK1_XCTRL4A); + xctl_a &= ~(DS1687_X4A_RCF | DS1687_X4A_WAF | DS1687_X4A_KF); + ds1687_write(mace0, DS1687_BANK1_XCTRL4A, xctl_a); + wbflush(); + + /* and down we go */ + ds1687_write(mace0, DS1687_BANK1_XCTRL4A, xctl_a | DS1687_X4A_PAB); + ds1687_write(mace0, DS1687_CONTROLA, a); + wbflush(); + while(1); +}