Home | History | Annotate | Line # | Download | only in fdt
amdccp_fdt.c revision 1.3
      1 /* $NetBSD: amdccp_fdt.c,v 1.3 2021/01/18 02:35:49 thorpej 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.3 2021/01/18 02:35:49 thorpej 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 
     42 struct amdccp_fdt_softc {
     43 	struct amdccp_softc sc_sc;
     44 };
     45 
     46 static int amdccp_fdt_match(device_t, cfdata_t, void *);
     47 static void amdccp_fdt_attach(device_t, device_t, void *);
     48 
     49 CFATTACH_DECL_NEW(amdccp_fdt, sizeof(struct amdccp_fdt_softc),
     50     amdccp_fdt_match, amdccp_fdt_attach, NULL, NULL);
     51 
     52 static const struct device_compatible_entry compat_data[] = {
     53 	{ .compat = "amd,ccp-seattle-v1a" },
     54 
     55 	{ 0 }
     56 };
     57 
     58 static int
     59 amdccp_fdt_match(device_t parent, cfdata_t cf, void *aux)
     60 {
     61 	const struct fdt_attach_args * const faa = aux;
     62 
     63 	return of_match_compat_data(faa->faa_phandle, compat_data);
     64 }
     65 
     66 static void
     67 amdccp_fdt_attach(device_t parent, device_t self, void *aux)
     68 {
     69 	struct amdccp_fdt_softc * const fsc = device_private(self);
     70 	struct amdccp_softc * const sc = &fsc->sc_sc;
     71 	const struct fdt_attach_args * const faa = aux;
     72 	const int phandle = faa->faa_phandle;
     73 	bus_addr_t addr;
     74 	bus_size_t size;
     75 
     76 	fsc->sc_sc.sc_dev = self;
     77 
     78 	if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
     79 		aprint_error(": couldn't get registers\n");
     80 		return;
     81 	}
     82 
     83 	sc->sc_bst = faa->faa_bst;
     84 	if (bus_space_map(sc->sc_bst, addr, size, 0, &sc->sc_bsh) != 0) {
     85 		aprint_error(": couldn't map registers\n");
     86 		return;
     87 	}
     88 
     89 	aprint_naive("\n");
     90 	aprint_normal(": AMD CCP\n");
     91 
     92 	amdccp_common_attach(sc);
     93 }
     94