1 /* $NetBSD: bcm2838_rng.c,v 1.1 2019/09/01 17:27:22 mlelstv Exp $ */ 2 3 /*- 4 * Copyright (c) 2019 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jared D. McNeill 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: bcm2838_rng.c,v 1.1 2019/09/01 17:27:22 mlelstv Exp $"); 34 35 #include <sys/param.h> 36 #include <sys/device.h> 37 38 #include <dev/ic/rng200var.h> 39 #include <dev/fdt/fdtvar.h> 40 41 struct bcm2838rng_softc { 42 device_t sc_dev; 43 struct rng200_softc sc_rng200; 44 }; 45 46 static int bcm2838rng_match(device_t, cfdata_t, void *); 47 static void bcm2838rng_attach(device_t, device_t, void *); 48 49 CFATTACH_DECL_NEW(bcm2838rng_fdt, sizeof(struct bcm2838rng_softc), 50 bcm2838rng_match, bcm2838rng_attach, NULL, NULL); 51 52 /* ARGSUSED */ 53 static int 54 bcm2838rng_match(device_t parent, cfdata_t match, void *aux) 55 { 56 const char * const compatible[] = { "brcm,bcm2838-rng200", NULL }; 57 struct fdt_attach_args * const faa = aux; 58 59 return of_match_compatible(faa->faa_phandle, compatible); 60 } 61 62 static void 63 bcm2838rng_attach(device_t parent, device_t self, void *aux) 64 { 65 struct bcm2838rng_softc *sc = device_private(self); 66 struct fdt_attach_args * const faa = aux; 67 bus_addr_t addr; 68 bus_size_t size; 69 bus_space_handle_t bsh; 70 int error; 71 72 sc->sc_dev = self; 73 74 error = fdtbus_get_reg(faa->faa_phandle, 0, &addr, &size); 75 if (error) { 76 aprint_error_dev(sc->sc_dev, ": couldn't get registers\n"); 77 return; 78 } 79 80 if (bus_space_map(faa->faa_bst, addr, size, 0, &bsh)) { 81 aprint_error_dev(sc->sc_dev, ": unable to map device\n"); 82 return; 83 } 84 85 aprint_naive("\n"); 86 aprint_normal(": Hardware RNG\n"); 87 88 sc->sc_rng200.sc_bst = faa->faa_bst; 89 sc->sc_rng200.sc_bsh = bsh; 90 sc->sc_rng200.sc_name = device_xname(sc->sc_dev); 91 rng200_attach(&sc->sc_rng200); 92 } 93