1 /* $NetBSD: pram.c,v 1.14 1997/08/11 22:53:50 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 if (0 == jClkNoMem) 133 timedata = 0; /* cause comparision of MacOS boottime */ 134 /* and PRAM time to fail */ 135 else 136 timedata = getPramTime(); 137 #if DEBUG 138 printf("time read from PRAM: 0x%lx\n", timedata); 139 printf("Date and time: %s\n",convtime(timedata)); 140 #endif 141 142 return(timedata); 143 } 144 145 void 146 pram_settime(unsigned long time) 147 { 148 if (0 == jClkNoMem) 149 return; 150 else 151 return setPramTime(time); 152 } 153 154 #ifndef MRG_ADB 155 /* 156 * These functions are defined here only if we are not using 157 * the MRG method of accessing the ADB/PRAM/RTC. 158 */ 159 160 extern int adbHardware; /* from newadb.c */ 161 162 /* 163 * getPramTime 164 * This function can be called regrardless of the machine 165 * type. It calls the correct hardware-specific code. 166 * (It's sort of redundant with the above, but it was 167 * added later.) 168 */ 169 unsigned long 170 getPramTime(void) 171 { 172 unsigned long time; 173 174 switch (adbHardware) { 175 case ADB_HW_II: /* access PRAM via VIA interface */ 176 time = (long)getPramTimeII(); 177 return time; 178 179 case ADB_HW_IISI: /* access PRAM via pseudo-adb functions */ 180 if (0 != adb_read_date_time(&time)) 181 return 0; 182 else 183 return time; 184 185 case ADB_HW_PB: /* don't know how to access this yet */ 186 return 0; 187 188 case ADB_HW_UNKNOWN: 189 default: 190 return 0; 191 } 192 } 193 194 /* 195 * setPramTime 196 * This function can be called regrardless of the machine 197 * type. It calls the correct hardware-specific code. 198 * (It's sort of redundant with the above, but it was 199 * added later.) 200 */ 201 void 202 setPramTime(unsigned long time) 203 { 204 switch (adbHardware) { 205 case ADB_HW_II: /* access PRAM via ADB interface */ 206 setPramTimeII(time); 207 return; 208 209 case ADB_HW_IISI: /* access PRAM via pseudo-adb functions */ 210 adb_set_date_time(time); 211 return; 212 213 case ADB_HW_PB: /* don't know how to access this yet */ 214 return; 215 216 case ADB_HW_UNKNOWN: 217 return; 218 } 219 } 220 221 #endif /* !MRG_ADB */ 222