1*6e54367aSthorpej /* $NetBSD: sunxi_de2.c,v 1.2 2021/01/27 03:10:20 thorpej Exp $ */
210139ac9Sjmcneill
310139ac9Sjmcneill /*-
410139ac9Sjmcneill * Copyright (c) 2019 Jared McNeill <jmcneill@invisible.ca>
510139ac9Sjmcneill * All rights reserved.
610139ac9Sjmcneill *
710139ac9Sjmcneill * Redistribution and use in source and binary forms, with or without
810139ac9Sjmcneill * modification, are permitted provided that the following conditions
910139ac9Sjmcneill * are met:
1010139ac9Sjmcneill * 1. Redistributions of source code must retain the above copyright
1110139ac9Sjmcneill * notice, this list of conditions and the following disclaimer.
1210139ac9Sjmcneill * 2. Redistributions in binary form must reproduce the above copyright
1310139ac9Sjmcneill * notice, this list of conditions and the following disclaimer in the
1410139ac9Sjmcneill * documentation and/or other materials provided with the distribution.
1510139ac9Sjmcneill *
1610139ac9Sjmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1710139ac9Sjmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1810139ac9Sjmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1910139ac9Sjmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2010139ac9Sjmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2110139ac9Sjmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2210139ac9Sjmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2310139ac9Sjmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2410139ac9Sjmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2510139ac9Sjmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2610139ac9Sjmcneill * SUCH DAMAGE.
2710139ac9Sjmcneill */
2810139ac9Sjmcneill
2910139ac9Sjmcneill #include <sys/cdefs.h>
30*6e54367aSthorpej __KERNEL_RCSID(0, "$NetBSD: sunxi_de2.c,v 1.2 2021/01/27 03:10:20 thorpej Exp $");
3110139ac9Sjmcneill
3210139ac9Sjmcneill #include <sys/param.h>
3310139ac9Sjmcneill #include <sys/bus.h>
3410139ac9Sjmcneill #include <sys/cpu.h>
3510139ac9Sjmcneill #include <sys/device.h>
3610139ac9Sjmcneill #include <sys/kmem.h>
3710139ac9Sjmcneill
3810139ac9Sjmcneill #include <dev/fdt/fdtvar.h>
3910139ac9Sjmcneill
4010139ac9Sjmcneill #include <arm/sunxi/sunxi_sramc.h>
4110139ac9Sjmcneill
42*6e54367aSthorpej static const struct device_compatible_entry compat_data[] = {
43*6e54367aSthorpej { .compat = "allwinner,sun50i-a64-de2" },
44*6e54367aSthorpej DEVICE_COMPAT_EOL
4510139ac9Sjmcneill };
4610139ac9Sjmcneill
4710139ac9Sjmcneill static int
sunxi_de2_match(device_t parent,cfdata_t cf,void * aux)4810139ac9Sjmcneill sunxi_de2_match(device_t parent, cfdata_t cf, void *aux)
4910139ac9Sjmcneill {
5010139ac9Sjmcneill struct fdt_attach_args * const faa = aux;
5110139ac9Sjmcneill
52*6e54367aSthorpej return of_compatible_match(faa->faa_phandle, compat_data);
5310139ac9Sjmcneill }
5410139ac9Sjmcneill
5510139ac9Sjmcneill static void
sunxi_de2_attach(device_t parent,device_t self,void * aux)5610139ac9Sjmcneill sunxi_de2_attach(device_t parent, device_t self, void *aux)
5710139ac9Sjmcneill {
5810139ac9Sjmcneill struct fdt_attach_args * const faa = aux;
5910139ac9Sjmcneill const int phandle = faa->faa_phandle;
6010139ac9Sjmcneill
6110139ac9Sjmcneill if (sunxi_sramc_claim(phandle) != 0) {
6210139ac9Sjmcneill aprint_error(": cannot map SRAM to DE2\n");
6310139ac9Sjmcneill return;
6410139ac9Sjmcneill }
6510139ac9Sjmcneill
6610139ac9Sjmcneill aprint_naive("\n");
6710139ac9Sjmcneill aprint_normal(": DE2 Bus\n");
6810139ac9Sjmcneill
6910139ac9Sjmcneill fdt_add_bus(self, phandle, faa);
7010139ac9Sjmcneill }
7110139ac9Sjmcneill
7210139ac9Sjmcneill CFATTACH_DECL_NEW(sunxi_de2bus, 0, sunxi_de2_match, sunxi_de2_attach, NULL, NULL);
73