gfrtc_fdt.c revision 1.2
11.2Sthorpej/* $NetBSD: gfrtc_fdt.c,v 1.2 2023/12/29 23:31:44 thorpej Exp $ */ 21.1Sskrll 31.1Sskrll/*- 41.1Sskrll * Copyright (c) 2023 The NetBSD Foundation, Inc. 51.1Sskrll * All rights reserved. 61.1Sskrll * 71.1Sskrll * This code is derived from software contributed to The NetBSD Foundation 81.1Sskrll * by Nick Hudson 91.1Sskrll * 101.1Sskrll * Redistribution and use in source and binary forms, with or without 111.1Sskrll * modification, are permitted provided that the following conditions 121.1Sskrll * are met: 131.1Sskrll * 1. Redistributions of source code must retain the above copyright 141.1Sskrll * notice, this list of conditions and the following disclaimer. 151.1Sskrll * 2. Redistributions in binary form must reproduce the above copyright 161.1Sskrll * notice, this list of conditions and the following disclaimer in the 171.1Sskrll * documentation and/or other materials provided with the distribution. 181.1Sskrll * 191.1Sskrll * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Sskrll * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Sskrll * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Sskrll * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Sskrll * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Sskrll * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Sskrll * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Sskrll * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Sskrll * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Sskrll * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Sskrll * POSSIBILITY OF SUCH DAMAGE. 301.1Sskrll */ 311.1Sskrll 321.1Sskrll#include <sys/cdefs.h> 331.2Sthorpej__KERNEL_RCSID(0, "$NetBSD: gfrtc_fdt.c,v 1.2 2023/12/29 23:31:44 thorpej Exp $"); 341.1Sskrll 351.1Sskrll#include <sys/param.h> 361.1Sskrll 371.1Sskrll#include <sys/bus.h> 381.1Sskrll#include <sys/device.h> 391.1Sskrll 401.1Sskrll#include <dev/fdt/fdtvar.h> 411.2Sthorpej#include <dev/goldfish/gfrtcvar.h> 421.1Sskrll 431.1Sskrll/* 441.1Sskrll * https://android.googlesource.com/platform/external/qemu/+/master/docs/GOLDFISH-VIRTUAL-HARDWARE.TXT 451.1Sskrll */ 461.1Sskrll 471.1Sskrllstatic const struct device_compatible_entry compat_data[] = { 481.1Sskrll { .compat = "google,goldfish-rtc" }, 491.1Sskrll DEVICE_COMPAT_EOL 501.1Sskrll}; 511.1Sskrll 521.1Sskrll 531.1Sskrllstatic int 541.1Sskrllgfrtc_fdt_match(device_t parent, cfdata_t cf, void *aux) 551.1Sskrll{ 561.1Sskrll struct fdt_attach_args * const faa = aux; 571.1Sskrll 581.1Sskrll return of_compatible_match(faa->faa_phandle, compat_data); 591.1Sskrll} 601.1Sskrll 611.1Sskrllstatic void 621.1Sskrllgfrtc_fdt_attach(device_t parent, device_t self, void *aux) 631.1Sskrll{ 641.2Sthorpej struct gfrtc_softc * const sc = device_private(self); 651.1Sskrll struct fdt_attach_args * const faa = aux; 661.1Sskrll const int phandle = faa->faa_phandle; 671.1Sskrll bus_addr_t addr; 681.1Sskrll bus_size_t size; 691.1Sskrll 701.1Sskrll if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) { 711.1Sskrll aprint_error(": couldn't get registers\n"); 721.1Sskrll return; 731.1Sskrll } 741.1Sskrll 751.1Sskrll sc->sc_dev = self; 761.1Sskrll sc->sc_bst = faa->faa_bst; 771.1Sskrll if (bus_space_map(sc->sc_bst, addr, size, 0, &sc->sc_bsh) != 0) { 781.1Sskrll aprint_error(": couldn't map registers\n"); 791.1Sskrll return; 801.1Sskrll } 811.1Sskrll 821.1Sskrll aprint_naive("\n"); 831.1Sskrll aprint_normal(": Google Goldfish RTC\n"); 841.1Sskrll 851.2Sthorpej gfrtc_attach(sc); 861.1Sskrll} 871.1Sskrll 881.2SthorpejCFATTACH_DECL_NEW(gfrtc_fdt, sizeof(struct gfrtc_softc), 891.1Sskrll gfrtc_fdt_match, gfrtc_fdt_attach, NULL, NULL); 90