11.1Sjmcneill/* $NetBSD: sdhc_ahb.c,v 1.1 2026/01/09 22:54:30 jmcneill Exp $ */ 21.1Sjmcneill 31.1Sjmcneill/*- 41.1Sjmcneill * Copyright (c) 2024 Jared McNeill <jmcneill@invisible.ca> 51.1Sjmcneill * All rights reserved. 61.1Sjmcneill * 71.1Sjmcneill * Redistribution and use in source and binary forms, with or without 81.1Sjmcneill * modification, are permitted provided that the following conditions 91.1Sjmcneill * are met: 101.1Sjmcneill * 1. Redistributions of source code must retain the above copyright 111.1Sjmcneill * notice, this list of conditions and the following disclaimer. 121.1Sjmcneill * 2. Redistributions in binary form must reproduce the above copyright 131.1Sjmcneill * notice, this list of conditions and the following disclaimer in the 141.1Sjmcneill * documentation and/or other materials provided with the distribution. 151.1Sjmcneill * 161.1Sjmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 171.1Sjmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 181.1Sjmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 191.1Sjmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 201.1Sjmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 211.1Sjmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 221.1Sjmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 231.1Sjmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 241.1Sjmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 251.1Sjmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 261.1Sjmcneill * SUCH DAMAGE. 271.1Sjmcneill */ 281.1Sjmcneill 291.1Sjmcneill#include <sys/cdefs.h> 301.1Sjmcneill__KERNEL_RCSID(0, "$NetBSD: sdhc_ahb.c,v 1.1 2026/01/09 22:54:30 jmcneill Exp $"); 311.1Sjmcneill 321.1Sjmcneill#include <sys/param.h> 331.1Sjmcneill#include <sys/bus.h> 341.1Sjmcneill#include <sys/device.h> 351.1Sjmcneill#include <sys/systm.h> 361.1Sjmcneill 371.1Sjmcneill#include <dev/sdmmc/sdhcreg.h> 381.1Sjmcneill#include <dev/sdmmc/sdhcvar.h> 391.1Sjmcneill#include <dev/sdmmc/sdmmcvar.h> 401.1Sjmcneill 411.1Sjmcneill#include <machine/wii.h> 421.1Sjmcneill#include <machine/wiiu.h> 431.1Sjmcneill#include "ahb.h" 441.1Sjmcneill 451.1Sjmcneill#define SDHC_SIZE 0x200 461.1Sjmcneill 471.1Sjmcneillextern struct powerpc_bus_dma_tag wii_mem2_bus_dma_tag; 481.1Sjmcneill 491.1Sjmcneillstatic int sdhc_ahb_match(device_t, cfdata_t, void *); 501.1Sjmcneillstatic void sdhc_ahb_attach(device_t, device_t, void *); 511.1Sjmcneill 521.1Sjmcneillstruct sdhc_ahb_softc { 531.1Sjmcneill struct sdhc_softc sc_base; 541.1Sjmcneill struct sdhc_host *sc_host[1]; 551.1Sjmcneill}; 561.1Sjmcneill 571.1SjmcneillCFATTACH_DECL_NEW(sdhc_ahb, sizeof(struct sdhc_ahb_softc), 581.1Sjmcneill sdhc_ahb_match, sdhc_ahb_attach, NULL, NULL); 591.1Sjmcneill 601.1Sjmcneillstatic int 611.1Sjmcneillsdhc_ahb_match(device_t parent, cfdata_t cf, void *aux) 621.1Sjmcneill{ 631.1Sjmcneill struct ahb_attach_args *aaa = aux; 641.1Sjmcneill 651.1Sjmcneill return wiiu_native || aaa->aaa_irq < 32; 661.1Sjmcneill} 671.1Sjmcneill 681.1Sjmcneillstatic void 691.1Sjmcneillsdhc_ahb_attach(device_t parent, device_t self, void *aux) 701.1Sjmcneill{ 711.1Sjmcneill struct ahb_attach_args *aaa = aux; 721.1Sjmcneill struct sdhc_ahb_softc *sc = device_private(self); 731.1Sjmcneill bus_space_tag_t bst; 741.1Sjmcneill bus_space_handle_t bsh; 751.1Sjmcneill int error; 761.1Sjmcneill 771.1Sjmcneill sc->sc_base.sc_dev = self; 781.1Sjmcneill sc->sc_base.sc_host = sc->sc_host; 791.1Sjmcneill sc->sc_base.sc_dmat = &wii_mem2_bus_dma_tag; 801.1Sjmcneill sc->sc_base.sc_flags = SDHC_FLAG_SINGLE_POWER_WRITE | 811.1Sjmcneill SDHC_FLAG_32BIT_ACCESS | 821.1Sjmcneill SDHC_FLAG_USE_DMA; 831.1Sjmcneill sc->sc_base.sc_dma_align_mask = 0x1f; 841.1Sjmcneill if (wiiu_plat) { 851.1Sjmcneill sc->sc_base.sc_flags |= SDHC_FLAG_NO_PWR0; 861.1Sjmcneill } 871.1Sjmcneill 881.1Sjmcneill bst = aaa->aaa_bst; 891.1Sjmcneill if (bus_space_map(bst, aaa->aaa_addr, SDHC_SIZE, 0, &bsh)) { 901.1Sjmcneill aprint_error(": couldn't map registers\n"); 911.1Sjmcneill return; 921.1Sjmcneill } 931.1Sjmcneill 941.1Sjmcneill aprint_naive("\n"); 951.1Sjmcneill aprint_normal(": SDHC\n"); 961.1Sjmcneill 971.1Sjmcneill ahb_claim_device(self, 981.1Sjmcneill device_unit(self) == 0 ? IOPSD0EN : IOPSD1EN); 991.1Sjmcneill 1001.1Sjmcneill ahb_intr_establish(aaa->aaa_irq, IPL_SDMMC, sdhc_intr, 1011.1Sjmcneill &sc->sc_base, device_xname(self)); 1021.1Sjmcneill 1031.1Sjmcneill error = sdhc_host_found(&sc->sc_base, bst, bsh, SDHC_SIZE); 1041.1Sjmcneill if (error != 0) { 1051.1Sjmcneill aprint_error_dev(self, 1061.1Sjmcneill "couldn't initialize host, error = %d\n", error); 1071.1Sjmcneill } 1081.1Sjmcneill} 109