Obsolete pow(4) and rtcalarm(8). Discussed in port-x68k@.
Probably the combination of pow(4) ioctl and rtcalarm(8) does not work for a long time, and nobody uses them. I'll rewrite a part about power switch handler as a new device.
This commit is contained in:
parent
fe59d7d5ac
commit
2ccb98927e
@ -1,10 +1,11 @@
|
||||
# $NetBSD: md.x68k,v 1.42 2008/12/20 13:20:58 isaki Exp $
|
||||
# $NetBSD: md.x68k,v 1.43 2011/11/19 12:27:42 isaki Exp $
|
||||
./dev/pow0 base-obsolete obsolete
|
||||
./dev/pow1 base-obsolete obsolete
|
||||
./usr/bin/bellctrl base-util-bin
|
||||
./usr/bin/loadfont base-util-bin
|
||||
./usr/bin/loadkmap base-util-bin
|
||||
./usr/bin/palette base-util-bin
|
||||
./usr/bin/rtcalarm base-util-bin
|
||||
./usr/bin/rtcalarm base-obsolete obsolete
|
||||
./usr/bin/tvctrl base-util-bin
|
||||
./usr/mdec/boot base-sysutil-bin
|
||||
./usr/mdec/fdboot_ufs base-sysutil-bin
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: md.x68k,v 1.58 2011/07/17 20:54:32 joerg Exp $
|
||||
# $NetBSD: md.x68k,v 1.59 2011/11/19 12:27:42 isaki Exp $
|
||||
./usr/include/ieeefp.h comp-c-include
|
||||
./usr/include/x68k comp-c-include
|
||||
./usr/include/x68k/_G_config.h comp-obsolete obsolete
|
||||
@ -46,7 +46,7 @@
|
||||
./usr/include/x68k/pci_machdep.h comp-obsolete obsolete
|
||||
./usr/include/x68k/pmap.h comp-c-include
|
||||
./usr/include/x68k/pmc.h comp-c-include
|
||||
./usr/include/x68k/powioctl.h comp-c-include
|
||||
./usr/include/x68k/powioctl.h comp-obsolete obsolete
|
||||
./usr/include/x68k/proc.h comp-c-include
|
||||
./usr/include/x68k/profile.h comp-c-include
|
||||
./usr/include/x68k/psl.h comp-c-include
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: mi,v 1.1355 2011/11/15 16:50:45 riz Exp $
|
||||
# $NetBSD: mi,v 1.1356 2011/11/19 12:27:42 isaki Exp $
|
||||
#
|
||||
# Note: don't delete entries from here - mark them as "obsolete" instead.
|
||||
#
|
||||
@ -1823,7 +1823,7 @@
|
||||
./usr/share/man/cat4/x68k/intro.0 man-sys-catman .cat
|
||||
./usr/share/man/cat4/x68k/mfp.0 man-sys-catman .cat
|
||||
./usr/share/man/cat4/x68k/neptune.0 man-sys-catman .cat
|
||||
./usr/share/man/cat4/x68k/pow.0 man-sys-catman .cat
|
||||
./usr/share/man/cat4/x68k/pow.0 man-obsolete obsolete
|
||||
./usr/share/man/cat4/x68k/vs.0 man-sys-catman .cat
|
||||
./usr/share/man/cat4/x86/amdpcib.0 man-sys-catman .cat
|
||||
./usr/share/man/cat4/x86/apic.0 man-sys-catman .cat
|
||||
@ -2942,7 +2942,7 @@
|
||||
./usr/share/man/cat8/x68k/memswitch.0 man-sysutil-catman .cat
|
||||
./usr/share/man/cat8/x68k/newdisk.0 man-sysutil-catman .cat
|
||||
./usr/share/man/cat8/x68k/poffd.0 man-obsolete obsolete
|
||||
./usr/share/man/cat8/x68k/rtcalarm.0 man-sysutil-catman .cat
|
||||
./usr/share/man/cat8/x68k/rtcalarm.0 man-obsolete obsolete
|
||||
./usr/share/man/cat8/x86_64/MAKEDEV.0 man-obsolete obsolete
|
||||
./usr/share/man/cat8/x86_64/makedev.0 man-obsolete obsolete
|
||||
./usr/share/man/cat8/xntpd.0 man-obsolete obsolete
|
||||
@ -4586,7 +4586,7 @@
|
||||
./usr/share/man/html4/x68k/intro.html man-sys-htmlman html
|
||||
./usr/share/man/html4/x68k/mfp.html man-sys-htmlman html
|
||||
./usr/share/man/html4/x68k/neptune.html man-sys-htmlman html
|
||||
./usr/share/man/html4/x68k/pow.html man-sys-htmlman html
|
||||
./usr/share/man/html4/x68k/pow.html man-obsolete obsolete
|
||||
./usr/share/man/html4/x68k/vs.html man-sys-htmlman html
|
||||
./usr/share/man/html4/x86/amdpcib.html man-sys-htmlman html
|
||||
./usr/share/man/html4/x86/apic.html man-sys-htmlman html
|
||||
@ -5483,7 +5483,7 @@
|
||||
./usr/share/man/html8/x68k/memswitch.html man-sysutil-htmlman html
|
||||
./usr/share/man/html8/x68k/newdisk.html man-sysutil-htmlman html
|
||||
./usr/share/man/html8/x68k/poffd.html man-obsolete obsolete
|
||||
./usr/share/man/html8/x68k/rtcalarm.html man-sysutil-htmlman html
|
||||
./usr/share/man/html8/x68k/rtcalarm.html man-obsolete obsolete
|
||||
./usr/share/man/html8/yp.html man-nis-htmlman html
|
||||
./usr/share/man/html8/ypbind.html man-nis-htmlman yp,html
|
||||
./usr/share/man/html8/ypinit.html man-nis-htmlman yp,html
|
||||
@ -7284,7 +7284,7 @@
|
||||
./usr/share/man/man4/x68k/intro.4 man-sys-man .man
|
||||
./usr/share/man/man4/x68k/mfp.4 man-sys-man .man
|
||||
./usr/share/man/man4/x68k/neptune.4 man-sys-man .man
|
||||
./usr/share/man/man4/x68k/pow.4 man-sys-man .man
|
||||
./usr/share/man/man4/x68k/pow.4 man-obsolete obsolete
|
||||
./usr/share/man/man4/x68k/vs.4 man-sys-man .man
|
||||
./usr/share/man/man4/x86/amdpcib.4 man-sys-man .man
|
||||
./usr/share/man/man4/x86/apic.4 man-sys-man .man
|
||||
@ -8403,7 +8403,7 @@
|
||||
./usr/share/man/man8/x68k/memswitch.8 man-sysutil-man .man
|
||||
./usr/share/man/man8/x68k/newdisk.8 man-sysutil-man .man
|
||||
./usr/share/man/man8/x68k/poffd.8 man-obsolete obsolete
|
||||
./usr/share/man/man8/x68k/rtcalarm.8 man-sysutil-man .man
|
||||
./usr/share/man/man8/x68k/rtcalarm.8 man-obsolete obsolete
|
||||
./usr/share/man/man8/x86_64/MAKEDEV.8 man-obsolete obsolete
|
||||
./usr/share/man/man8/x86_64/makedev.8 man-obsolete obsolete
|
||||
./usr/share/man/man8/xntpd.8 man-obsolete obsolete
|
||||
|
@ -1,6 +1,6 @@
|
||||
# $NetBSD: Makefile,v 1.7 2002/12/01 09:14:34 isaki Exp $
|
||||
# $NetBSD: Makefile,v 1.8 2011/11/19 12:27:43 isaki Exp $
|
||||
|
||||
MAN= bmd.4 intio.4 intro.4 mfp.4 neptune.4 pow.4 vs.4
|
||||
MAN= bmd.4 intio.4 intro.4 mfp.4 neptune.4 vs.4
|
||||
MANSUBDIR=/x68k
|
||||
|
||||
.include <bsd.man.mk>
|
||||
|
@ -1,172 +0,0 @@
|
||||
.\" $NetBSD: pow.4,v 1.14 2009/03/09 19:24:31 joerg Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1995 MINOURA Makoto.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" 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 Minoura Makoto.
|
||||
.\" 4. The name of the author may not be used to endorse or promote products
|
||||
.\" derived from this software without specific prior written permission
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
.\"
|
||||
.Dd December 20, 2008
|
||||
.Dt POW 4 x68k
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm pow
|
||||
.Nd X68k power switch device
|
||||
.Sh DESCRIPTION
|
||||
File
|
||||
.Pa /dev/pow0
|
||||
is a device used to access the x68k power switch / bootstrap information and
|
||||
the RTC alarm timer.
|
||||
The following operations are allowed using the
|
||||
.Xr ioctl 2
|
||||
system call:
|
||||
.Pp
|
||||
.Bl -tag -width POWIOCGPOWERINFO -compact -offset indent
|
||||
.It POWIOGPOWERINFO
|
||||
Get power switch status
|
||||
.It POWIOGALARMINFO
|
||||
Get RTC alarm timer status
|
||||
.It POWIOSALARMINFO
|
||||
Set RTC alarm timer
|
||||
.El
|
||||
.Pp
|
||||
Any power switch events are reported to
|
||||
.Xr powerd 8 .
|
||||
.Sh GETTING POWER SWITCH STATUS
|
||||
.Bd -literal -offset indent
|
||||
#include \*[Lt]sys/ioctl.h\*[Gt]
|
||||
#include \*[Lt]machine/powioctl.h\*[Gt]
|
||||
|
||||
ioctl (fd, POWIOCGPOWERINFO, \*[Am]powerinfo);
|
||||
struct x68k_powerinfo powerinfo;
|
||||
.Ed
|
||||
.Pp
|
||||
Returns the power switch status etc. in the following structure.
|
||||
.Bd -literal -offset indent
|
||||
struct x68k_powerinfo {
|
||||
int pow_switch_boottime;
|
||||
int pow_switch_current;
|
||||
time_t pow_boottime;
|
||||
unsigned int pow_bootcount;
|
||||
time_t pow_usedtotal;
|
||||
};
|
||||
.Ed
|
||||
.Pp
|
||||
The members of the structure mean:
|
||||
.Bl -hang
|
||||
.It pow_switch_boottime :
|
||||
The power switch status at the system start time.
|
||||
The status can be checked by testing for the following definitions
|
||||
with the logical
|
||||
.Dq and
|
||||
(\*[Am]):
|
||||
.Pp
|
||||
.Bl -tag -compact -width POW_EXTERNALSW
|
||||
.It POW_ALARMSW
|
||||
True if the system started by the RTC alarm timer
|
||||
.It POW_EXTERNALSW
|
||||
True if the EXPWON signal of the I/O slot is on
|
||||
.It POW_FRONTSW
|
||||
True if the front power switch is on
|
||||
.El
|
||||
.Pp
|
||||
EXPWON-related information is not tested.
|
||||
.It pow_switch_current :
|
||||
Current power switch status.
|
||||
See above.
|
||||
.It pow_boottime :
|
||||
The time when
|
||||
.Nx
|
||||
started.
|
||||
.It pow_bootcount , pow_usedtotal :
|
||||
Host's boot information from the system memory switch.
|
||||
Total usage in count (pow_bootcount) and second (pow_usedtotal).
|
||||
.El
|
||||
.Sh ACCESSING RTC ALARM TIMER
|
||||
.Ss Getting the alarm timer
|
||||
.Bd -literal -offset indent
|
||||
#include \*[Lt]sys/ioctl.h\*[Gt]
|
||||
#include \*[Lt]machine/powioctl.h\*[Gt]
|
||||
|
||||
ioctl (fd, POWIOCGALARMINFO, \*[Am]alarminfo);
|
||||
struct x68k_alarminfo alarminfo;
|
||||
.Ed
|
||||
.Pp
|
||||
Returns x68k's alarm timer information in the following structure.
|
||||
.Bd -literal -offset indent
|
||||
struct x68k_alarminfo {
|
||||
int al_enable;
|
||||
unsigned int al_ontime;
|
||||
int al_dowhat;
|
||||
time_t al_offtime;
|
||||
};
|
||||
.Ed
|
||||
.Pp
|
||||
The members mean:
|
||||
.Bl -hang
|
||||
.It al_enable :
|
||||
True if the alarm timer is enable.
|
||||
.It al_ontime :
|
||||
Internal expression of the alarm timer.
|
||||
See
|
||||
.Dq C Compiler PRO-68K Programmers' Manual
|
||||
Chapter 3 Section ALARMSET.
|
||||
.It al_dowhat :
|
||||
What to do when started by the alarm timer.
|
||||
See
|
||||
.Dq Programmers' manual .
|
||||
.It al_offtime :
|
||||
Display the time in seconds since the alarm is activated until
|
||||
the power is turned off (though the resolution is resolved to minutes).
|
||||
Be cautious when using IOCS and the like as these require minute
|
||||
time units.
|
||||
0 indicates an infinity.
|
||||
.El
|
||||
.Ss Setting the alarm timer
|
||||
.Bd -literal -offset indent
|
||||
ioctl (fd, POWIOCSALARMINFO, \*[Am]alarminfo);
|
||||
struct x68k_alarminfo alarminfo;
|
||||
.Ed
|
||||
.Pp
|
||||
Sets the alarm timer according to the argument
|
||||
.Ar alarminfo
|
||||
(see above).
|
||||
.Sh SEE ALSO
|
||||
.Xr ioctl 2 ,
|
||||
.Xr powerd 8 ,
|
||||
.Xr rtcalarm 8
|
||||
.Rs
|
||||
.%T C Compiler PRO-68K Programmers' Manual', Chapter 3 IOCS Calls, Section ALARMSET
|
||||
.%I Sharp
|
||||
.Re
|
||||
.Sh AUTHORS
|
||||
.An Minoura Makoto Aq minoura@flab.fujitsu.co.jp
|
||||
.Ss SPECIAL THANKS
|
||||
Liam Hahne Minn
|
||||
.Aq hahne@sail.t.u-tokyo.ac.jp
|
||||
.Sh BUGS
|
||||
The file
|
||||
.Pa /dev/pow0
|
||||
can only be opened by one process at a time.
|
@ -1,6 +1,6 @@
|
||||
# $NetBSD: Makefile,v 1.9 2008/12/20 13:20:58 isaki Exp $
|
||||
# $NetBSD: Makefile,v 1.10 2011/11/19 12:27:43 isaki Exp $
|
||||
|
||||
MAN= boot.8 loadbsd.8 newdisk.8 rtcalarm.8
|
||||
MAN= boot.8 loadbsd.8 newdisk.8
|
||||
MLINKS+=loadbsd.8 loadbsd.x.8
|
||||
MANSUBDIR=/x68k
|
||||
|
||||
|
@ -1,76 +0,0 @@
|
||||
.\" $NetBSD: rtcalarm.8,v 1.9 2009/03/09 19:24:32 joerg Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1995 MINOURA Makoto.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" 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 Minoura Makoto.
|
||||
.\" 4. The name of the author may not be used to endorse or promote products
|
||||
.\" derived from this software without specific prior written permission
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
.\"
|
||||
.Dd June 28, 1995
|
||||
.Dt RTCALARM 8 x68k
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm rtcalarm
|
||||
.Nd "Display or set x68k's RTC alarm timer"
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl w Ar day-of-the-week
|
||||
.Op Fl d Ar day-of-the-month
|
||||
.Bo
|
||||
.Op Fl m Ar minites
|
||||
|
|
||||
.Op Fl s Ar seconds
|
||||
.Bc
|
||||
.Op Fl c channel
|
||||
.Ar hh:mm
|
||||
.Nm
|
||||
off
|
||||
.Nm
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
displays or sets x68k's RTC alarm timer.
|
||||
.Pp
|
||||
The first form of
|
||||
.Nm
|
||||
sets the alarm timer to specified time and enables it.
|
||||
.Ar Day-of-the-week
|
||||
is a number from 0 to 6, which means Sunday, Monday,.. etc.
|
||||
.Pp
|
||||
If
|
||||
.Fl c
|
||||
is omitted, the alarm timer starts the x68k in computer mode.
|
||||
.Pp
|
||||
The second form disables the alarm timer.
|
||||
.Pp
|
||||
If no arguments are supplied (the third form),
|
||||
.Nm
|
||||
displays the current settings of the alarm timer.
|
||||
.Pp
|
||||
Note that setting the alarm timer is allowed only for the super user.
|
||||
.Sh SEE ALSO
|
||||
.Xr pow 4
|
||||
.Sh AUTHORS
|
||||
.Nm
|
||||
was written by MINOURA Makoto \*[Lt]minoura@flab.fujitsu.co.jp\*[Gt].
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: GENERIC,v 1.155 2011/03/17 13:26:51 tsutsui Exp $
|
||||
# $NetBSD: GENERIC,v 1.156 2011/11/19 12:27:43 isaki Exp $
|
||||
#
|
||||
# GENERIC machine description file
|
||||
#
|
||||
@ -22,7 +22,7 @@ include "arch/x68k/conf/std.x68k"
|
||||
|
||||
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
|
||||
|
||||
#ident "GENERIC-$Revision: 1.155 $"
|
||||
#ident "GENERIC-$Revision: 1.156 $"
|
||||
|
||||
maxusers 8
|
||||
|
||||
@ -252,7 +252,6 @@ kbd0 at mfp0 # standard keyboard
|
||||
ite0 at grf0 grfaddr 0 # internal terminal emulator
|
||||
options ITE_KERNEL_ATTR=4 # bold for kernel messages
|
||||
# see /sys/arch/x68k/dev/itevar.h
|
||||
pow0 at mfp0 # software power switch
|
||||
|
||||
## floppy disks
|
||||
fdc0 at intio0 addr 0xe94000 intr 96 dma 0 dmaintr 100 # floppy controller
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: INSTALL,v 1.91 2011/03/06 17:08:33 bouyer Exp $
|
||||
# $NetBSD: INSTALL,v 1.92 2011/11/19 12:27:43 isaki Exp $
|
||||
|
||||
#
|
||||
# INSTALL -- installation kernel.
|
||||
@ -8,7 +8,7 @@ include "arch/x68k/conf/std.x68k"
|
||||
|
||||
#options INCLUDE_CONFIG_FILE # embed config file in kernel binary
|
||||
|
||||
#ident "INSTALL-$Revision: 1.91 $"
|
||||
#ident "INSTALL-$Revision: 1.92 $"
|
||||
|
||||
makeoptions COPTS="-Os" # Optimise for space. Implies -O2
|
||||
|
||||
@ -223,7 +223,6 @@ kbd0 at mfp0 # standard keyboard
|
||||
ite0 at grf0 grfaddr 0 # internal terminal emulator
|
||||
options ITE_KERNEL_ATTR=4 # bold for kernel messages
|
||||
# see /sys/arch/x68k/dev/itevar.h
|
||||
#pow0 at mfp0 # software power switch
|
||||
|
||||
## floppy disks
|
||||
fdc0 at intio0 addr 0xe94000 intr 96 dma 0 dmaintr 100 # floppy controller
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: files.x68k,v 1.75 2011/11/15 12:23:22 tsutsui Exp $
|
||||
# $NetBSD: files.x68k,v 1.76 2011/11/19 12:27:43 isaki Exp $
|
||||
#
|
||||
# new style config file for x68k architecture
|
||||
#
|
||||
@ -96,10 +96,6 @@ device kbd: event
|
||||
attach kbd at mfp
|
||||
file arch/x68k/dev/kbd.c kbd needs-flag
|
||||
|
||||
device pow: sysmon_power, sysmon_taskq
|
||||
attach pow at mfp
|
||||
file arch/x68k/dev/pow.c pow
|
||||
|
||||
device rtc
|
||||
attach rtc at intio
|
||||
file arch/x68k/dev/rtclock.c rtc
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: majors.x68k,v 1.24 2011/06/30 20:09:38 wiz Exp $
|
||||
# $NetBSD: majors.x68k,v 1.25 2011/11/19 12:27:43 isaki Exp $
|
||||
#
|
||||
# Device majors for x68k
|
||||
#
|
||||
@ -29,7 +29,7 @@ device-major bpf char 22 bpfilter
|
||||
device-major sram char 23 sram
|
||||
|
||||
device-major tun char 31 tun
|
||||
device-major pow char 32 pow
|
||||
#obsolete pow char 32 pow
|
||||
device-major bell char 33 bell
|
||||
device-major ccd char 34 block 15 ccd
|
||||
device-major ss char 35 ss
|
||||
|
@ -1,337 +0,0 @@
|
||||
/* $NetBSD: pow.c,v 1.23 2009/01/18 04:48:53 isaki Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1995 MINOURA Makoto.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 Minoura Makoto.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Power switch device driver.
|
||||
* Useful for
|
||||
* 1. accessing boot information.
|
||||
* 2. looking at the front or external power switch.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: pow.c,v 1.23 2009/01/18 04:48:53 isaki Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/signalvar.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/bus.h>
|
||||
#include <sys/device.h>
|
||||
|
||||
#include <dev/sysmon/sysmonvar.h>
|
||||
#include <dev/sysmon/sysmon_taskq.h>
|
||||
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/powioctl.h>
|
||||
#include <x68k/dev/intiovar.h>
|
||||
#include <x68k/dev/mfp.h>
|
||||
#include <x68k/dev/powvar.h>
|
||||
#include <x68k/x68k/iodevice.h>
|
||||
|
||||
#define sramtop (IODEVbase->io_sram)
|
||||
#define rtc (IODEVbase->io_rtc)
|
||||
|
||||
extern struct cfdriver pow_cd;
|
||||
|
||||
static int pow_match(device_t, cfdata_t, void *);
|
||||
static void pow_attach(device_t, device_t, void *);
|
||||
static int powintr(void *);
|
||||
static int setalarm(struct x68k_alarminfo *);
|
||||
static void pow_pressed_event(void *);
|
||||
static void pow_check_switch(void *);
|
||||
|
||||
CFATTACH_DECL_NEW(pow, sizeof(struct pow_softc),
|
||||
pow_match, pow_attach, NULL, NULL);
|
||||
|
||||
static int pow_attached;
|
||||
|
||||
dev_type_open(powopen);
|
||||
dev_type_close(powclose);
|
||||
dev_type_ioctl(powioctl);
|
||||
|
||||
const struct cdevsw pow_cdevsw = {
|
||||
powopen, powclose, noread, nowrite, powioctl,
|
||||
nostop, notty, nopoll, nommap, nokqfilter,
|
||||
};
|
||||
|
||||
static int
|
||||
pow_match(device_t parent, cfdata_t cf, void *aux)
|
||||
{
|
||||
if (pow_attached)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
pow_attach(device_t parent, device_t self, void *aux)
|
||||
{
|
||||
struct pow_softc *sc = device_private(self);
|
||||
struct mfp_softc *mfp = device_private(parent);
|
||||
|
||||
sc->sw = ~mfp_get_gpip() & 7;
|
||||
/* disable mfp power switch interrupt */
|
||||
mfp_bit_clear_ierb(7);
|
||||
mfp_bit_clear_aer(7);
|
||||
|
||||
sc->status = POW_FREE;
|
||||
|
||||
if (sc->sw) {
|
||||
mfp_bit_set_aer(sc->sw);
|
||||
mfp_bit_set_ierb(sc->sw);
|
||||
}
|
||||
|
||||
sysmon_task_queue_init();
|
||||
sc->smpsw.smpsw_name = device_xname(self);
|
||||
sc->smpsw.smpsw_type = PSWITCH_TYPE_POWER;
|
||||
if (sysmon_pswitch_register(&sc->smpsw) != 0)
|
||||
panic("can't register with sysmon");
|
||||
|
||||
/* MFP interrupt #1 for ext, #2 for front power switch */
|
||||
if (intio_intr_establish(mfp->sc_intr + 1, "powext", powintr, sc) < 0)
|
||||
panic("%s: can't establish interrupt", device_xname(self));
|
||||
if (intio_intr_establish(mfp->sc_intr + 2, "powfrt", powintr, sc) < 0)
|
||||
panic("%s: can't establish interrupt", device_xname(self));
|
||||
|
||||
shutdownhook_establish(pow_check_switch, 0);
|
||||
|
||||
printf("\n");
|
||||
printf("%s: started by ", device_xname(self));
|
||||
if (sc->sw & POW_EXTERNALSW)
|
||||
printf("external power switch.\n");
|
||||
else if (sc->sw & POW_FRONTSW)
|
||||
printf("front power switch.\n");
|
||||
/* XXX: I don't know why POW_ALARMSW should not be checked */
|
||||
#if 0
|
||||
else if ((sc->sw & POW_ALARMSW) && sramtop[0x26] == 0)
|
||||
printf("RTC alarm.\n");
|
||||
else
|
||||
printf("???.\n");
|
||||
#else
|
||||
else
|
||||
printf("RTC alarm.\n");
|
||||
#endif
|
||||
|
||||
pow_attached = 1;
|
||||
}
|
||||
|
||||
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
powopen(dev_t dev, int flags, int mode, struct lwp *l)
|
||||
{
|
||||
struct pow_softc *sc;
|
||||
|
||||
sc = device_lookup_private(&pow_cd, minor(dev));
|
||||
if (sc == NULL)
|
||||
return ENXIO;
|
||||
|
||||
if (sc->status == POW_BUSY)
|
||||
return EBUSY;
|
||||
|
||||
if (sc->status == POW_FREE)
|
||||
sc->status = POW_BUSY;
|
||||
|
||||
sc->rw = (flags & (FREAD|FWRITE));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
powclose(dev_t dev, int flags, int mode, struct lwp *l)
|
||||
{
|
||||
struct pow_softc *sc;
|
||||
|
||||
sc = device_lookup_private(&pow_cd, minor(dev));
|
||||
if (sc == NULL)
|
||||
return ENXIO;
|
||||
|
||||
if (sc->status == POW_BUSY)
|
||||
sc->status = POW_FREE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define SRAMINT(offset) (*((volatile int *) (&sramtop[offset])))
|
||||
#define RTCWAIT DELAY(100)
|
||||
|
||||
static int
|
||||
setalarm(struct x68k_alarminfo *bp)
|
||||
{
|
||||
int s, ontime;
|
||||
|
||||
s = splclock();
|
||||
|
||||
intio_set_sysport_sramwp(0x31);
|
||||
if (bp->al_enable) {
|
||||
SRAMINT(0x1e) = bp->al_dowhat;
|
||||
SRAMINT(0x22) = bp->al_ontime;
|
||||
SRAMINT(0x14) = (bp->al_offtime / 60) - 1;
|
||||
sramtop[0x26] = 0;
|
||||
} else {
|
||||
sramtop[0x26] = 7;
|
||||
}
|
||||
intio_set_sysport_sramwp(0);
|
||||
|
||||
rtc.bank0.mode = 9;
|
||||
RTCWAIT;
|
||||
rtc.bank1.reset = 5;
|
||||
RTCWAIT;
|
||||
|
||||
if (bp->al_enable) {
|
||||
ontime = bp->al_ontime;
|
||||
if ((ontime & 0x0f) <= 9)
|
||||
rtc.bank1.al_min = ontime & 0x0f;
|
||||
RTCWAIT;
|
||||
ontime >>= 4;
|
||||
if ((ontime & 0x0f) <= 6)
|
||||
rtc.bank1.al_min10 = ontime & 0x0f;
|
||||
RTCWAIT;
|
||||
ontime >>= 4;
|
||||
if ((ontime & 0x0f) <= 9)
|
||||
rtc.bank1.al_hour = ontime & 0x0f;
|
||||
RTCWAIT;
|
||||
ontime >>= 4;
|
||||
if ((ontime & 0x0f) <= 2)
|
||||
rtc.bank1.al_hour10 = ontime & 0x0f;
|
||||
RTCWAIT;
|
||||
ontime >>= 4;
|
||||
if ((ontime & 0x0f) <= 9)
|
||||
rtc.bank1.al_day = ontime & 0x0f;
|
||||
RTCWAIT;
|
||||
ontime >>= 4;
|
||||
if ((ontime & 0x0f) <= 3)
|
||||
rtc.bank1.al_day10 = ontime & 0x0f;
|
||||
RTCWAIT;
|
||||
ontime >>= 4;
|
||||
if ((ontime & 0x0f) <= 6)
|
||||
rtc.bank1.al_week = ontime & 0x0f;
|
||||
RTCWAIT;
|
||||
rtc.bank1.clkout = 0;
|
||||
RTCWAIT;
|
||||
rtc.bank1.mode = 0x0c;
|
||||
} else {
|
||||
rtc.bank1.clkout = 7;
|
||||
RTCWAIT;
|
||||
rtc.bank1.mode = 0x08;
|
||||
}
|
||||
splx(s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
powioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
|
||||
{
|
||||
struct pow_softc *sc;
|
||||
|
||||
sc = device_lookup_private(&pow_cd, minor(dev));
|
||||
if (sc == NULL)
|
||||
return ENXIO;
|
||||
|
||||
switch (cmd) {
|
||||
case POWIOCGPOWERINFO:
|
||||
{
|
||||
struct x68k_powerinfo *bp = (void *)addr;
|
||||
if (!(sc->rw & FREAD))
|
||||
return EBADF;
|
||||
bp->pow_switch_boottime = sc->sw;
|
||||
bp->pow_switch_current = ~mfp_get_gpip() & 7;
|
||||
bp->pow_boottime = boottime.tv_sec;
|
||||
bp->pow_bootcount = SRAMINT(0x44);
|
||||
bp->pow_usedtotal = SRAMINT(0x40) * 60;
|
||||
}
|
||||
break;
|
||||
|
||||
case POWIOCGALARMINFO:
|
||||
{
|
||||
struct x68k_alarminfo *bp = (void *) addr;
|
||||
if (!(sc->rw & FREAD))
|
||||
return EBADF;
|
||||
bp->al_enable = (sramtop[0x26] == 0);
|
||||
bp->al_ontime = SRAMINT(0x22);
|
||||
bp->al_dowhat = SRAMINT(0x1e);
|
||||
bp->al_offtime = (SRAMINT(0x14) + 1) * 60;
|
||||
}
|
||||
break;
|
||||
|
||||
case POWIOCSALARMINFO:
|
||||
if (!(sc->rw & FWRITE))
|
||||
return EBADF;
|
||||
return setalarm ((void *) addr);
|
||||
|
||||
default:
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
powintr(void *arg)
|
||||
{
|
||||
struct pow_softc *sc = arg;
|
||||
int sw;
|
||||
|
||||
sw = ~mfp_get_gpip() & 6;
|
||||
mfp_bit_clear_aer(sw);
|
||||
mfp_bit_set_ierb(sw);
|
||||
|
||||
sysmon_task_queue_sched(0, pow_pressed_event, sc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
pow_pressed_event(void *arg)
|
||||
{
|
||||
struct pow_softc *sc = arg;
|
||||
|
||||
sysmon_pswitch_event(&sc->smpsw, PSWITCH_EVENT_PRESSED);
|
||||
}
|
||||
|
||||
static void
|
||||
pow_check_switch(void *dummy)
|
||||
{
|
||||
extern int power_switch_is_off;
|
||||
|
||||
if ((~mfp_get_gpip() & (POW_FRONTSW | POW_EXTERNALSW)) == 0)
|
||||
power_switch_is_off = 1;
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/* $NetBSD: powvar.h,v 1.4 2008/12/20 13:20:59 isaki Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1995 MINOURA Makoto.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 Minoura Makoto.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
enum pow_status {
|
||||
POW_FREE,
|
||||
POW_BUSY,
|
||||
POW_ANY,
|
||||
};
|
||||
|
||||
struct pow_softc {
|
||||
short status;
|
||||
short rw;
|
||||
int sw;
|
||||
struct sysmon_pswitch smpsw;
|
||||
};
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.35 2011/07/21 11:02:48 joerg Exp $
|
||||
# $NetBSD: Makefile,v 1.36 2011/11/19 12:27:44 isaki Exp $
|
||||
|
||||
INCSDIR= /usr/include/x68k
|
||||
|
||||
@ -16,7 +16,7 @@ INCS= ansi.h aout_machdep.h asm.h \
|
||||
lock.h limits.h \
|
||||
math.h mcontext.h mutex.h \
|
||||
opmbellio.h opmreg.h \
|
||||
param.h parioctl.h pcb.h pmap.h pmc.h powioctl.h proc.h \
|
||||
param.h parioctl.h pcb.h pmap.h pmc.h proc.h \
|
||||
profile.h psl.h pte.h ptrace.h \
|
||||
reg.h remote-sl.h rwlock.h \
|
||||
setjmp.h signal.h sram.h \
|
||||
|
@ -1,66 +0,0 @@
|
||||
/* $NetBSD: powioctl.h,v 1.4 2008/12/20 13:20:59 isaki Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1995 MINOURA Makoto.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 Minoura Makoto.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
/* Power switch device driver. */
|
||||
|
||||
#ifndef _X68K_POWIOCTL_H_
|
||||
#define _X68K_POWIOCTL_H_
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
enum x68k_powerswitch {
|
||||
POW_ALARMSW = 1,
|
||||
POW_EXTERNALSW = 2,
|
||||
POW_FRONTSW = 4,
|
||||
};
|
||||
|
||||
struct x68k_powerinfo {
|
||||
int pow_switch_boottime;
|
||||
int pow_switch_current;
|
||||
time_t pow_boottime;
|
||||
unsigned int pow_bootcount;
|
||||
time_t pow_usedtotal;
|
||||
};
|
||||
|
||||
struct x68k_alarminfo {
|
||||
int al_enable;
|
||||
unsigned int al_ontime;
|
||||
int al_dowhat;
|
||||
time_t al_offtime;
|
||||
};
|
||||
|
||||
#define POWIOCGPOWERINFO _IOR('p', 0, struct x68k_powerinfo)
|
||||
#define POWIOCGALARMINFO _IOR('p', 1, struct x68k_alarminfo)
|
||||
#define POWIOCSALARMINFO _IOW('p', 2, struct x68k_alarminfo)
|
||||
/* 3: POWIOCSSIGNAL is obsoleted */
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
# $NetBSD: Makefile,v 1.1 1996/05/05 12:17:17 oki Exp $
|
||||
# $NetBSD: Makefile,v 1.2 2011/11/19 12:27:44 isaki Exp $
|
||||
|
||||
SUBDIR+= loadfont loadkmap palette rtcalarm tvctrl bellctrl
|
||||
SUBDIR+= loadfont loadkmap palette tvctrl bellctrl
|
||||
|
||||
.include <bsd.subdir.mk>
|
||||
|
@ -1,6 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.7 2011/05/19 21:40:11 tsutsui Exp $
|
||||
|
||||
PROG=rtcalarm
|
||||
NOMAN=# defined
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,287 +0,0 @@
|
||||
/* $NetBSD: rtcalarm.c,v 1.11 2011/05/19 21:26:39 tsutsui Exp $ */
|
||||
/*
|
||||
* Copyright (c) 1995 MINOURA Makoto.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 Minoura Makoto.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
/* rtcalarm: X68k RTC alarm test program */
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define volatile
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <machine/powioctl.h>
|
||||
|
||||
static void usage(void) __attribute__((__noreturn__));
|
||||
static void showinfo(void);
|
||||
static char *numstr(unsigned int);
|
||||
static void showontime(unsigned int);
|
||||
static void disablealarm(void);
|
||||
static void setinfo(int, char **);
|
||||
static int strnum(const char *, size_t);
|
||||
|
||||
static const char *devicefile = "/dev/pow0"; /* default path */
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
if (argc == 1)
|
||||
showinfo();
|
||||
else if (argc == 2 && strcmp(argv[1], "off") == 0)
|
||||
disablealarm();
|
||||
else
|
||||
setinfo(argc, argv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Usage: %s [[-w day-of-the-week] [-d day-of-the-month]\n"
|
||||
" [-m minites] [-s seconds] [-c channel] HH:MM]\n",
|
||||
getprogname());
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
showinfo(void)
|
||||
{
|
||||
struct x68k_alarminfo alarminfo;
|
||||
int fd;
|
||||
|
||||
fd = open(devicefile, O_RDONLY);
|
||||
if (fd < 0)
|
||||
err(EXIT_FAILURE, "Opening %s", devicefile);
|
||||
|
||||
if (ioctl(fd, POWIOCGALARMINFO, &alarminfo) < 0)
|
||||
err(EXIT_FAILURE, "POWIOCGALARMINFO");
|
||||
close(fd);
|
||||
|
||||
if (alarminfo.al_enable) {
|
||||
showontime(alarminfo.al_ontime);
|
||||
if (alarminfo.al_dowhat == 0 || alarminfo.al_dowhat == -1)
|
||||
printf("Computer mode.\n");
|
||||
else if (alarminfo.al_dowhat >= 0x30 && alarminfo.al_dowhat <= 0x3b)
|
||||
printf("TV channel %d.\n", alarminfo.al_dowhat - 0x30 + 1);
|
||||
else if (alarminfo.al_dowhat < 0x40)
|
||||
printf("TV mode.\n");
|
||||
else
|
||||
printf("Computer mode. ADDR=%8.8x\n", alarminfo.al_dowhat);
|
||||
|
||||
if (alarminfo.al_offtime == 0)
|
||||
printf("Never shut down automatically.\n");
|
||||
else
|
||||
printf("Shut down in %d seconds (%d minutes).\n",
|
||||
(int)alarminfo.al_offtime,
|
||||
(int)alarminfo.al_offtime / 60);
|
||||
} else {
|
||||
printf("RTC alarm is disabled.\n");
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
numstr(unsigned int num)
|
||||
{
|
||||
static char buffer[4];
|
||||
|
||||
if ((num & 0xf0) == 0xf0)
|
||||
buffer[0] = 'x';
|
||||
else
|
||||
buffer[0] = ((num & 0xf0) >> 4) + '0';
|
||||
|
||||
if ((num & 0x0f) == 0x0f)
|
||||
buffer[1] = 'x';
|
||||
else
|
||||
buffer[1] = (num & 0x0f) + '0';
|
||||
|
||||
buffer[2] = 0;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
const char * const weekname[] = {
|
||||
"Sunday",
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday"
|
||||
};
|
||||
|
||||
static void
|
||||
showontime(unsigned int ontime)
|
||||
{
|
||||
|
||||
printf("At %s:", numstr((ontime & 0x0000ff00) >> 8));
|
||||
printf("%s ", numstr(ontime & 0x000000ff));
|
||||
|
||||
if ((ontime & 0x0fff0000) != 0x0fff0000) {
|
||||
if ((ontime & 0x0f000000) != 0x0f000000) {
|
||||
if ((ontime & 0x00ff0000) != 0x00ff0000)
|
||||
printf("on %s, %sth in every month, \n",
|
||||
weekname[(ontime & 0x0f000000) >> 24],
|
||||
numstr((ontime & 0x00ff0000) >> 16));
|
||||
else
|
||||
printf("on every %s, \n",
|
||||
weekname[(ontime & 0x0f000000) >> 24]);
|
||||
} else {
|
||||
printf("on %sth in every month, \n",
|
||||
numstr((ontime & 0x00ff0000) >> 16));
|
||||
}
|
||||
} else {
|
||||
printf("everyday.\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
disablealarm(void)
|
||||
{
|
||||
int fd;
|
||||
struct x68k_alarminfo alarminfo;
|
||||
|
||||
alarminfo.al_enable = 0;
|
||||
|
||||
fd = open(devicefile, O_WRONLY);
|
||||
if (fd < 0)
|
||||
err(EXIT_FAILURE, "Opening %s", devicefile);
|
||||
if (ioctl(fd, POWIOCSALARMINFO, &alarminfo) < 0)
|
||||
err(EXIT_FAILURE, "POWIOCSALARMINFO");
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static void
|
||||
setinfo(int argc, char **argv)
|
||||
{
|
||||
int ch;
|
||||
int week = 0x0f;
|
||||
int hour = 0xffff;
|
||||
int day = 0xff;
|
||||
int off_time = 0;
|
||||
int dowhat = 0;
|
||||
int fd;
|
||||
struct x68k_alarminfo alarminfo;
|
||||
|
||||
while ((ch = getopt(argc, argv, "w:d:m:s:c:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'w': /* day of the week */
|
||||
if ((week = strnum(optarg, 1)) < 0)
|
||||
usage();
|
||||
break;
|
||||
case 'd': /* day of the month */
|
||||
if ((day = strnum(optarg, 2)) < 0)
|
||||
usage();
|
||||
break;
|
||||
case 'm': /* for X minits */
|
||||
off_time = atoi(optarg);
|
||||
break;
|
||||
case 's': /* for X seconds */
|
||||
off_time = atoi(optarg) / 60;
|
||||
break;
|
||||
case 'c': /* channel */
|
||||
dowhat = atoi(optarg) + 0x30 - 1;
|
||||
if (dowhat < 0x30 || dowhat > 0x3b)
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (optind != argc - 1)
|
||||
usage();
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("week: %x, day:%x, for:%d, hour:%x\n",
|
||||
week, day, off_time, strnum(argv[optind], 5));
|
||||
#endif
|
||||
|
||||
hour = strnum(argv[optind], 5);
|
||||
if (hour < 0)
|
||||
usage();
|
||||
|
||||
alarminfo.al_enable = 1;
|
||||
alarminfo.al_ontime = (week << 24) | (day << 16) | hour;
|
||||
alarminfo.al_dowhat = dowhat;
|
||||
alarminfo.al_offtime = off_time * 60;
|
||||
|
||||
fd = open(devicefile, O_WRONLY);
|
||||
if (fd < 0)
|
||||
err(EXIT_FAILURE, "Opening %s", devicefile);
|
||||
if (ioctl(fd, POWIOCSALARMINFO, &alarminfo) < 0)
|
||||
err(EXIT_FAILURE, "POWIOCSALARMINFO");
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static int
|
||||
strnum(const char *str, size_t wid)
|
||||
{
|
||||
int r;
|
||||
|
||||
if (strlen(str) != wid)
|
||||
return -1;
|
||||
|
||||
if (str[0] >= '0' && str[0] <= '9')
|
||||
r = str[0] - '0';
|
||||
else
|
||||
r = 0xf;
|
||||
if (wid == 1)
|
||||
return r;
|
||||
|
||||
r <<= 4;
|
||||
if (str[1] >= '0' && str[1] <= '9')
|
||||
r += str[1] - '0';
|
||||
else
|
||||
r += 0xf;
|
||||
if (wid == 2)
|
||||
return r;
|
||||
|
||||
if (str[2] != ':')
|
||||
return -1;
|
||||
r <<= 4;
|
||||
if (str[3] >= '0' && str[3] <= '9')
|
||||
r += str[3] - '0';
|
||||
else
|
||||
r += 0xf;
|
||||
r <<= 4;
|
||||
if (str[4] >= '0' && str[4] <= '9')
|
||||
r += str[4] - '0';
|
||||
else
|
||||
r += 0xf;
|
||||
|
||||
return r;
|
||||
}
|
Loading…
Reference in New Issue
Block a user