1/* $NetBSD: amdccp_fdt.c,v 1.7 2022/12/18 15:50:32 reinoud Exp $ */ 2 3/* 4 * Copyright (c) 2018 Jonathan A. Kollasch 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> 30 31__KERNEL_RCSID(0, "$NetBSD: amdccp_fdt.c,v 1.7 2022/12/18 15:50:32 reinoud Exp $"); 32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/device.h> 36#include <sys/bus.h> 37 38#include <dev/fdt/fdtvar.h> 39 40#include <dev/ic/amdccpvar.h> 41 42struct amdccp_fdt_softc { 43 struct amdccp_softc sc_sc; 44}; 45 46static int amdccp_fdt_match(device_t, cfdata_t, void *); 47static void amdccp_fdt_attach(device_t, device_t, void *); 48 49CFATTACH_DECL_NEW(amdccp_fdt, sizeof(struct amdccp_fdt_softc), 50 amdccp_fdt_match, amdccp_fdt_attach, NULL, NULL); 51 52static const struct device_compatible_entry compat_data[] = { 53 { .compat = "amd,ccp-seattle-v1a" }, 54 DEVICE_COMPAT_EOL 55}; 56 57static int 58amdccp_fdt_match(device_t parent, cfdata_t cf, void *aux) 59{ 60 const struct fdt_attach_args * const faa = aux; 61 62 return of_compatible_match(faa->faa_phandle, compat_data); 63} 64 65static void 66amdccp_fdt_attach(device_t parent, device_t self, void *aux) 67{ 68 struct amdccp_fdt_softc * const fsc = device_private(self); 69 struct amdccp_softc * const sc = &fsc->sc_sc; 70 const struct fdt_attach_args * const faa = aux; 71 const int phandle = faa->faa_phandle; 72 bus_addr_t addr; 73 bus_size_t size; 74 75 fsc->sc_sc.sc_dev = self; 76 77 if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) { 78 aprint_error(": couldn't get registers\n"); 79 return; 80 } 81 82 sc->sc_bst = faa->faa_bst; 83 if (bus_space_map(sc->sc_bst, addr, size, 0, &sc->sc_bsh) != 0) { 84 aprint_error(": couldn't map registers\n"); 85 return; 86 } 87 88 aprint_naive("\n"); 89 aprint_normal(": AMD CCP\n"); 90 91 amdccp_common_attach(sc); 92 pmf_device_register(self, NULL, NULL); 93} 94