1 /* $NetBSD: pram.c,v 1.16 1997/11/11 17:31:11 scottr Exp $ */ 2 3 /*- 4 * Copyright (C) 1993 Allen K. Briggs, Chris P. Caputo, 5 * Michael L. Finch, Bradley A. Grantham, and 6 * Lawrence A. Kesteloot 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by the Alice Group. 20 * 4. The names of the Alice Group or any of its members may not be used 21 * to endorse or promote products derived from this software without 22 * specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE ALICE GROUP ``AS IS'' AND ANY EXPRESS OR 25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27 * IN NO EVENT SHALL THE ALICE GROUP BE LIABLE FOR ANY DIRECT, INDIRECT, 28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 #include "opt_mrg_adb.h" 37 38 #include <sys/types.h> 39 #include <sys/param.h> 40 #ifdef DEBUG 41 #include <sys/systm.h> 42 #endif 43 #include <machine/viareg.h> 44 45 #include <mac68k/mac68k/pram.h> 46 #include <mac68k/mac68k/macrom.h> 47 #ifndef MRG_ADB 48 #include <mac68k/dev/adbvar.h> 49 #endif 50 51 #if DEBUG 52 static char *convtime(unsigned long t) 53 { 54 static long daypmon[] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; 55 static char *monstr[] = {"January","February","March","April","May","June", 56 "July","August","September","October","November","December" }; 57 static char s[200]; 58 long year,month,day,hour,minute,seconds,i,dayperyear; 59 60 year=1904; 61 month=0; /* Jan */ 62 day=1; 63 hour=0; 64 minute=0; 65 seconds=0; 66 67 if(t == 0xffffffff) 68 return("<time value is -1>"); 69 70 while (t > 0) 71 { 72 if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) 73 { 74 dayperyear=366; 75 daypmon[1]=29; 76 } 77 else 78 { 79 dayperyear=365; 80 daypmon[1]=28; 81 } 82 i=dayperyear*60*60*24; 83 if (t >= i) 84 { 85 t-=i; 86 year++; 87 continue; 88 } 89 i=daypmon[month]*60*60*24; 90 if (t >= i) 91 { 92 t-=i; 93 month++; 94 continue; 95 } 96 i=60*60*24; 97 if (t >= i) 98 { 99 t-=i; 100 day++; 101 continue; 102 } 103 i=60*60; 104 if (t >= i) 105 { 106 t-=i; 107 hour++; 108 continue; 109 } 110 i=60; 111 if (t >= i) 112 { 113 t-=i; 114 minute++; 115 continue; 116 } 117 seconds=t; 118 t=0; 119 } 120 121 sprintf(s,"%s %ld, %ld %ld:%ld:%ld",monstr[month],day,year,hour,minute,seconds); 122 123 return s; 124 } 125 #endif 126 127 unsigned long 128 pram_readtime(void) 129 { 130 unsigned long timedata; 131 132 #ifdef MRG_ADB 133 if (0 == jClkNoMem) 134 timedata = 0; /* cause comparision of MacOS boottime */ 135 /* and PRAM time to fail */ 136 else 137 #endif 138 timedata = getPramTime(); 139 #if DEBUG 140 printf("time read from PRAM: 0x%lx\n", timedata); 141 printf("Date and time: %s\n",convtime(timedata)); 142 #endif 143 144 return(timedata); 145 } 146 147 void 148 pram_settime(unsigned long time) 149 { 150 #ifdef MRG_ADB 151 if (0 == jClkNoMem) 152 return; 153 else 154 #endif 155 return setPramTime(time); 156 } 157 158 #ifndef MRG_ADB 159 /* 160 * These functions are defined here only if we are not using 161 * the MRG method of accessing the ADB/PRAM/RTC. 162 */ 163 164 extern int adbHardware; /* from adb_direct.c */ 165 166 /* 167 * getPramTime 168 * This function can be called regrardless of the machine 169 * type. It calls the correct hardware-specific code. 170 * (It's sort of redundant with the above, but it was 171 * added later.) 172 */ 173 unsigned long 174 getPramTime(void) 175 { 176 unsigned long time; 177 178 switch (adbHardware) { 179 case ADB_HW_II: /* access PRAM via VIA interface */ 180 time = (long)getPramTimeII(); 181 return time; 182 183 case ADB_HW_IISI: /* access PRAM via pseudo-adb functions */ 184 case ADB_HW_CUDA: 185 if (0 != adb_read_date_time(&time)) 186 return 0; 187 else 188 return time; 189 190 case ADB_HW_PB: /* don't know how to access this yet */ 191 return 0; 192 193 case ADB_HW_UNKNOWN: 194 default: 195 return 0; 196 } 197 } 198 199 /* 200 * setPramTime 201 * This function can be called regrardless of the machine 202 * type. It calls the correct hardware-specific code. 203 * (It's sort of redundant with the above, but it was 204 * added later.) 205 */ 206 void 207 setPramTime(unsigned long time) 208 { 209 switch (adbHardware) { 210 case ADB_HW_II: /* access PRAM via ADB interface */ 211 setPramTimeII(time); 212 return; 213 214 case ADB_HW_IISI: /* access PRAM via pseudo-adb functions */ 215 case ADB_HW_CUDA: 216 adb_set_date_time(time); 217 return; 218 219 case ADB_HW_PB: /* don't know how to access this yet */ 220 return; 221 222 case ADB_HW_UNKNOWN: 223 return; 224 } 225 } 226 227 #endif /* !MRG_ADB */ 228