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