prtc.c revision 1.1
1/* $OpenBSD: prtc.c,v 1.1 2008/03/13 22:46:16 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 33#include <dev/clock_subr.h> 34 35extern todr_chip_handle_t todr_handle; 36 37int prtc_match(struct device *, void *, void *); 38void prtc_attach(struct device *, struct device *, void *); 39 40struct cfattach prtc_ca = { 41 sizeof(struct device), prtc_match, prtc_attach 42}; 43 44struct cfdriver prtc_cd = { 45 NULL, "prtc", DV_DULL 46}; 47 48int prtc_gettime(todr_chip_handle_t, struct timeval *); 49int prtc_settime(todr_chip_handle_t, struct timeval *); 50 51int 52prtc_match(struct device *parent, void *match, void *aux) 53{ 54 struct mainbus_attach_args *ma = aux; 55 56 if (strcmp(ma->ma_name, "prtc") == 0) 57 return (1); 58 59 return (0); 60} 61 62void 63prtc_attach(struct device *parent, struct device *self, void *aux) 64{ 65 todr_chip_handle_t handle; 66 67 printf("\n"); 68 69 handle = malloc(sizeof(struct todr_chip_handle), M_DEVBUF, M_NOWAIT); 70 if (handle == NULL) 71 panic("couldn't allocate todr_handle"); 72 73 handle->cookie = self; 74 handle->todr_gettime = prtc_gettime; 75 handle->todr_settime = prtc_settime; 76 77 handle->bus_cookie = NULL; 78 handle->todr_setwen = NULL; 79 todr_handle = handle; 80} 81 82int 83prtc_gettime(todr_chip_handle_t handle, struct timeval *tv) 84{ 85 char cmd[32]; 86 u_int32_t tod = 0; 87 88 snprintf(cmd, sizeof(cmd), "h# %08x unix-gettod", &tod); 89 OF_interpret(cmd, 0); 90 91 tv->tv_sec = tod; 92 tv->tv_usec = 0; 93 return (0); 94} 95 96int 97prtc_settime(todr_chip_handle_t handle, struct timeval *tv) 98{ 99 return (0); 100} 101