1 /* $OpenBSD: prtc.c,v 1.2 2008/07/10 08:58:00 kettenis Exp $ */ 2 3 /* 4 * Copyright (c) 2008 Mark Kettenis 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /* 20 * Driver to get the time-of-day from the PROM for machines that don't 21 * have a hardware real-time clock, like the Enterprise 10000, 22 * Fire 12K and Fire 15K. 23 */ 24 25 #include <sys/param.h> 26 #include <sys/device.h> 27 #include <sys/malloc.h> 28 #include <sys/systm.h> 29 30 #include <machine/autoconf.h> 31 #include <machine/openfirm.h> 32 #include <machine/sparc64.h> 33 34 #include <dev/clock_subr.h> 35 36 extern todr_chip_handle_t todr_handle; 37 38 int prtc_match(struct device *, void *, void *); 39 void prtc_attach(struct device *, struct device *, void *); 40 41 struct cfattach prtc_ca = { 42 sizeof(struct device), prtc_match, prtc_attach 43 }; 44 45 struct cfdriver prtc_cd = { 46 NULL, "prtc", DV_DULL 47 }; 48 49 int prtc_gettime(todr_chip_handle_t, struct timeval *); 50 int prtc_settime(todr_chip_handle_t, struct timeval *); 51 52 int 53 prtc_match(struct device *parent, void *match, void *aux) 54 { 55 struct mainbus_attach_args *ma = aux; 56 57 if (strcmp(ma->ma_name, "prtc") == 0) 58 return (1); 59 60 return (0); 61 } 62 63 void 64 prtc_attach(struct device *parent, struct device *self, void *aux) 65 { 66 todr_chip_handle_t handle; 67 68 printf("\n"); 69 70 handle = malloc(sizeof(struct todr_chip_handle), M_DEVBUF, M_NOWAIT); 71 if (handle == NULL) 72 panic("couldn't allocate todr_handle"); 73 74 handle->cookie = self; 75 handle->todr_gettime = prtc_gettime; 76 handle->todr_settime = prtc_settime; 77 78 handle->bus_cookie = NULL; 79 handle->todr_setwen = NULL; 80 todr_handle = handle; 81 } 82 83 int 84 prtc_gettime(todr_chip_handle_t handle, struct timeval *tv) 85 { 86 u_int32_t tod = 0; 87 char buf[32]; 88 89 if (OF_getprop(findroot(), "name", buf, sizeof(buf)) > 0 && 90 strcmp(buf, "SUNW,SPARC-Enterprise") == 0) { 91 tv->tv_sec = prom_opl_get_tod(); 92 tv->tv_usec = 0; 93 return (0); 94 } 95 96 snprintf(buf, sizeof(buf), "h# %08x unix-gettod", &tod); 97 OF_interpret(buf, 0); 98 99 tv->tv_sec = tod; 100 tv->tv_usec = 0; 101 return (0); 102 } 103 104 int 105 prtc_settime(todr_chip_handle_t handle, struct timeval *tv) 106 { 107 return (0); 108 } 109