1*f57a76a7Sjmcneill /* $NetBSD: fdt_rtc.c,v 1.1 2017/04/22 13:24:20 jmcneill Exp $ */
2*f57a76a7Sjmcneill
3*f57a76a7Sjmcneill /*-
4*f57a76a7Sjmcneill * Copyright (c) 2017 Jared D. McNeill <jmcneill@invisible.ca>
5*f57a76a7Sjmcneill * All rights reserved.
6*f57a76a7Sjmcneill *
7*f57a76a7Sjmcneill * Redistribution and use in source and binary forms, with or without
8*f57a76a7Sjmcneill * modification, are permitted provided that the following conditions
9*f57a76a7Sjmcneill * are met:
10*f57a76a7Sjmcneill * 1. Redistributions of source code must retain the above copyright
11*f57a76a7Sjmcneill * notice, this list of conditions and the following disclaimer.
12*f57a76a7Sjmcneill * 2. Redistributions in binary form must reproduce the above copyright
13*f57a76a7Sjmcneill * notice, this list of conditions and the following disclaimer in the
14*f57a76a7Sjmcneill * documentation and/or other materials provided with the distribution.
15*f57a76a7Sjmcneill *
16*f57a76a7Sjmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17*f57a76a7Sjmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18*f57a76a7Sjmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19*f57a76a7Sjmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20*f57a76a7Sjmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21*f57a76a7Sjmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22*f57a76a7Sjmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23*f57a76a7Sjmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24*f57a76a7Sjmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*f57a76a7Sjmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*f57a76a7Sjmcneill * SUCH DAMAGE.
27*f57a76a7Sjmcneill */
28*f57a76a7Sjmcneill
29*f57a76a7Sjmcneill #include <sys/cdefs.h>
30*f57a76a7Sjmcneill __KERNEL_RCSID(0, "$NetBSD: fdt_rtc.c,v 1.1 2017/04/22 13:24:20 jmcneill Exp $");
31*f57a76a7Sjmcneill
32*f57a76a7Sjmcneill #include <sys/param.h>
33*f57a76a7Sjmcneill #include <sys/bus.h>
34*f57a76a7Sjmcneill #include <sys/kmem.h>
35*f57a76a7Sjmcneill
36*f57a76a7Sjmcneill #include <libfdt.h>
37*f57a76a7Sjmcneill #include <dev/fdt/fdtvar.h>
38*f57a76a7Sjmcneill
39*f57a76a7Sjmcneill int
fdtbus_todr_attach(device_t dev,int phandle,todr_chip_handle_t tch)40*f57a76a7Sjmcneill fdtbus_todr_attach(device_t dev, int phandle, todr_chip_handle_t tch)
41*f57a76a7Sjmcneill {
42*f57a76a7Sjmcneill const char *prop;
43*f57a76a7Sjmcneill
44*f57a76a7Sjmcneill /*
45*f57a76a7Sjmcneill * The kernel will only use the first device to register with
46*f57a76a7Sjmcneill * todr_attach. If we have an "rtc0" alias, ensure that it matches
47*f57a76a7Sjmcneill * this phandle and ignore all other RTC devices.
48*f57a76a7Sjmcneill */
49*f57a76a7Sjmcneill prop = fdt_get_alias(fdtbus_get_data(), "rtc0");
50*f57a76a7Sjmcneill if (prop != NULL && OF_finddevice(prop) != phandle) {
51*f57a76a7Sjmcneill device_printf(dev, "disabled\n");
52*f57a76a7Sjmcneill return EINVAL;
53*f57a76a7Sjmcneill }
54*f57a76a7Sjmcneill
55*f57a76a7Sjmcneill todr_attach(tch);
56*f57a76a7Sjmcneill
57*f57a76a7Sjmcneill return 0;
58*f57a76a7Sjmcneill }
59