Home | History | Annotate | Line # | Download | only in dev
      1 /* $NetBSD: sdhc_hollywood.c,v 1.4 2025/02/15 15:49:44 jmcneill Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2024 Jared McNeill <jmcneill (at) invisible.ca>
      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 AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: sdhc_hollywood.c,v 1.4 2025/02/15 15:49:44 jmcneill Exp $");
     31 
     32 #include <sys/param.h>
     33 #include <sys/bus.h>
     34 #include <sys/device.h>
     35 #include <sys/systm.h>
     36 
     37 #include <dev/sdmmc/sdhcreg.h>
     38 #include <dev/sdmmc/sdhcvar.h>
     39 #include <dev/sdmmc/sdmmcvar.h>
     40 
     41 #include <machine/wii.h>
     42 #include "hollywood.h"
     43 
     44 #define SDHC_SIZE			0x200
     45 
     46 extern struct powerpc_bus_dma_tag wii_mem2_bus_dma_tag;
     47 
     48 static int	sdhc_hollywood_match(device_t, cfdata_t, void *);
     49 static void	sdhc_hollywood_attach(device_t, device_t, void *);
     50 
     51 struct sdhc_hollywood_softc {
     52 	struct sdhc_softc	sc_base;
     53 	struct sdhc_host	*sc_host[1];
     54 };
     55 
     56 CFATTACH_DECL_NEW(sdhc_hollywood, sizeof(struct sdhc_hollywood_softc),
     57 	sdhc_hollywood_match, sdhc_hollywood_attach, NULL, NULL);
     58 
     59 static int
     60 sdhc_hollywood_match(device_t parent, cfdata_t cf, void *aux)
     61 {
     62 	return 1;
     63 }
     64 
     65 static void
     66 sdhc_hollywood_attach(device_t parent, device_t self, void *aux)
     67 {
     68 	struct hollywood_attach_args *haa = aux;
     69 	struct sdhc_hollywood_softc *sc = device_private(self);
     70 	bus_space_tag_t bst;
     71 	bus_space_handle_t bsh;
     72 	int error;
     73 
     74 	sc->sc_base.sc_dev = self;
     75 	sc->sc_base.sc_host = sc->sc_host;
     76 	sc->sc_base.sc_dmat = &wii_mem2_bus_dma_tag;
     77 	sc->sc_base.sc_flags = SDHC_FLAG_SINGLE_POWER_WRITE |
     78 			       SDHC_FLAG_32BIT_ACCESS |
     79 			       SDHC_FLAG_USE_DMA;
     80 
     81 	bst = haa->haa_bst;
     82 	if (bus_space_map(bst, haa->haa_addr, SDHC_SIZE, 0, &bsh)) {
     83 		aprint_error(": couldn't map registers\n");
     84 		return;
     85 	}
     86 
     87 	aprint_naive("\n");
     88 	aprint_normal(": SDHC\n");
     89 
     90 	hollywood_claim_device(self,
     91 	    device_unit(self) == 0 ? IOPSD0EN : IOPSD1EN);
     92 
     93 	hollywood_intr_establish(haa->haa_irq, IPL_SDMMC, sdhc_intr,
     94 	    &sc->sc_base, device_xname(self));
     95 
     96 	error = sdhc_host_found(&sc->sc_base, bst, bsh, SDHC_SIZE);
     97 	if (error != 0) {
     98 		aprint_error_dev(self,
     99 		    "couldn't initialize host, error = %d\n", error);
    100 	}
    101 }
    102