eprtc.c revision 1.1
1/*	$NetBSD: eprtc.c,v 1.1 2005/11/12 05:33:23 hamajima Exp $	*/
2
3/*
4 * Copyright (c) 2005 HAMAJIMA Katsuomi. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
29__KERNEL_RCSID(0, "$NetBSD: eprtc.c,v 1.1 2005/11/12 05:33:23 hamajima Exp $");
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/device.h>
35#include <dev/clock_subr.h>
36#include <machine/bus.h>
37#include <arm/ep93xx/ep93xxvar.h>
38#include <arm/ep93xx/epsocvar.h>
39#include <arm/ep93xx/eprtcreg.h>
40
41struct eprtc_softc {
42	struct device		sc_dev;
43	bus_space_tag_t		sc_iot;
44	bus_space_handle_t	sc_ioh;
45	struct todr_chip_handle	sc_todr;
46};
47
48static int eprtc_match(struct device *, struct cfdata *, void *);
49static void eprtc_attach(struct device *, struct device *, void *);
50
51CFATTACH_DECL(eprtc, sizeof(struct eprtc_softc),
52	      eprtc_match, eprtc_attach, NULL, NULL);
53
54static int eprtc_gettime(struct todr_chip_handle *,
55			    volatile struct timeval *);
56static int eprtc_settime(struct todr_chip_handle *,
57			    volatile struct timeval *);
58static int eprtc_getcal(struct todr_chip_handle *, int *);
59static int eprtc_setcal(struct todr_chip_handle *, int);
60
61static int
62eprtc_match(struct device *parent, struct cfdata *match, void *aux)
63{
64	return 1;
65}
66
67static void
68eprtc_attach(struct device *parent, struct device *self, void *aux)
69{
70	struct eprtc_softc *sc = (struct eprtc_softc*)self;
71	struct epsoc_attach_args *sa = aux;
72
73	printf("\n");
74	sc->sc_iot = sa->sa_iot;
75
76	if (bus_space_map(sa->sa_iot, sa->sa_addr,
77			  sa->sa_size, 0, &sc->sc_ioh)){
78		printf("%s: Cannot map registers", self->dv_xname);
79		return;
80	}
81
82	sc->sc_todr.cookie = sc;
83	sc->sc_todr.todr_gettime = eprtc_gettime;
84	sc->sc_todr.todr_settime = eprtc_settime;
85	sc->sc_todr.todr_getcal = eprtc_getcal;
86	sc->sc_todr.todr_setcal = eprtc_setcal;
87	sc->sc_todr.todr_setwen = NULL;
88	todr_attach(&sc->sc_todr);
89}
90
91static int
92eprtc_gettime(struct todr_chip_handle *ch, volatile struct timeval *tv)
93{
94	struct eprtc_softc *sc = ch->cookie;;
95
96	tv->tv_sec = bus_space_read_4(sc->sc_iot, sc->sc_ioh, EP93XX_RTC_Data);
97	tv->tv_usec = 0;
98	return 0;
99}
100
101static int
102eprtc_settime(struct todr_chip_handle *ch, volatile struct timeval *tv)
103{
104	struct eprtc_softc *sc = ch->cookie;;
105
106	bus_space_write_4(sc->sc_iot, sc->sc_ioh, EP93XX_RTC_Load, tv->tv_sec);
107	return 0;
108}
109
110static int
111eprtc_setcal(struct todr_chip_handle *ch, int cal)
112{
113	return (EOPNOTSUPP);
114}
115
116static int
117eprtc_getcal(struct todr_chip_handle *ch, int *cal)
118{
119	return (EOPNOTSUPP);
120}
121