clockctl.c revision 1.1 1 1.1 manu /* $NetBSD: clockctl.c,v 1.1 2001/09/16 06:53:56 manu Exp $ */
2 1.1 manu
3 1.1 manu /*-
4 1.1 manu * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.1 manu * All rights reserved.
6 1.1 manu *
7 1.1 manu * This code is derived from software contributed to The NetBSD Foundation
8 1.1 manu * by Emmanuel Dreyfus.
9 1.1 manu *
10 1.1 manu * Redistribution and use in source and binary forms, with or without
11 1.1 manu * modification, are permitted provided that the following conditions
12 1.1 manu * are met:
13 1.1 manu * 1. Redistributions of source code must retain the above copyright
14 1.1 manu * notice, this list of conditions and the following disclaimer.
15 1.1 manu * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 manu * notice, this list of conditions and the following disclaimer in the
17 1.1 manu * documentation and/or other materials provided with the distribution.
18 1.1 manu * 3. The name of the author may not be used to endorse or promote products
19 1.1 manu * derived from this software without specific prior written permission.
20 1.1 manu *
21 1.1 manu * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 manu * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 manu * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 manu * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 manu * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 manu * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 manu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 manu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 manu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 manu * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 manu */
32 1.1 manu
33 1.1 manu #include <sys/param.h>
34 1.1 manu #include <sys/systm.h>
35 1.1 manu #include <sys/proc.h>
36 1.1 manu #include <sys/errno.h>
37 1.1 manu #include <sys/ioctl.h>
38 1.1 manu #include <sys/device.h>
39 1.1 manu #include <sys/time.h>
40 1.1 manu #include <sys/types.h>
41 1.1 manu #ifdef NTP
42 1.1 manu #include <sys/timex.h>
43 1.1 manu #endif /* NTP */
44 1.1 manu
45 1.1 manu #include <sys/clockctl.h>
46 1.1 manu
47 1.1 manu struct clockctl_softc {
48 1.1 manu struct device clockctl_dev;
49 1.1 manu };
50 1.1 manu
51 1.1 manu
52 1.1 manu void
53 1.1 manu clockctlattach(parent, self, aux)
54 1.1 manu struct device *self;
55 1.1 manu struct device *parent;
56 1.1 manu void *aux;
57 1.1 manu {
58 1.1 manu /* Nothing to set up before open is called */
59 1.1 manu return;
60 1.1 manu }
61 1.1 manu
62 1.1 manu int
63 1.1 manu clockctlopen(dev, flags, fmt, p)
64 1.1 manu dev_t dev;
65 1.1 manu int flags, fmt;
66 1.1 manu struct proc *p;
67 1.1 manu {
68 1.1 manu return 0;
69 1.1 manu }
70 1.1 manu
71 1.1 manu int
72 1.1 manu clockctlclose(dev, flags, fmt, p)
73 1.1 manu dev_t dev;
74 1.1 manu int flags, fmt;
75 1.1 manu struct proc *p;
76 1.1 manu {
77 1.1 manu return 0;
78 1.1 manu }
79 1.1 manu
80 1.1 manu int
81 1.1 manu clockctlioctl(dev, cmd, data, flags, p)
82 1.1 manu dev_t dev;
83 1.1 manu u_long cmd;
84 1.1 manu caddr_t data;
85 1.1 manu int flags;
86 1.1 manu struct proc *p;
87 1.1 manu {
88 1.1 manu int error = 0;
89 1.1 manu
90 1.1 manu switch (cmd) {
91 1.1 manu case CLOCKCTL_SETTIMEOFDAY: {
92 1.1 manu struct clockctl_settimeofday_args *args =
93 1.1 manu (struct clockctl_settimeofday_args *)&data;
94 1.1 manu
95 1.1 manu error = settimeofday1(&args->tv, &args->tzp, p);
96 1.1 manu if (error)
97 1.1 manu return (error);
98 1.1 manu break;
99 1.1 manu }
100 1.1 manu case CLOCKCTL_ADJTIME: {
101 1.1 manu struct clockctl_adjtime_args *args =
102 1.1 manu (struct clockctl_adjtime_args *)&data;
103 1.1 manu
104 1.1 manu error = adjtime1(&args->delta, &args->olddelta, p);
105 1.1 manu if (error)
106 1.1 manu return (error);
107 1.1 manu break;
108 1.1 manu }
109 1.1 manu case CLOCKCTL_CLOCK_SETTIME: {
110 1.1 manu struct clockctl_clock_settime_args *args =
111 1.1 manu (struct clockctl_clock_settime_args *)&data;
112 1.1 manu
113 1.1 manu error = clock_settime1(args->clock_id, &args->tp);
114 1.1 manu if (error)
115 1.1 manu return (error);
116 1.1 manu break;
117 1.1 manu }
118 1.1 manu #ifdef NTP
119 1.1 manu case CLOCKCTL_NTP_ADJTIME: {
120 1.1 manu struct clockctl_ntp_adjtime_args *args =
121 1.1 manu (struct clockctl_ntp_adjtime_args *)&data;
122 1.1 manu
123 1.1 manu (void*)ntp_adjtime1(&args->tp, &error);
124 1.1 manu return (error);
125 1.1 manu }
126 1.1 manu #endif /* NTP */
127 1.1 manu default:
128 1.1 manu error = EINVAL;
129 1.1 manu }
130 1.1 manu
131 1.1 manu return (error);
132 1.1 manu }
133 1.1 manu
134 1.1 manu
135