From owner-svn-src-head@freebsd.org Thu Apr 16 16:00:22 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 883522C04BD; Thu, 16 Apr 2020 16:00:22 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4933pZ33ZKz4gJj; Thu, 16 Apr 2020 16:00:22 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 64421B44D; Thu, 16 Apr 2020 16:00:22 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 03GG0Mhu032184; Thu, 16 Apr 2020 16:00:22 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 03GG0L9p032181; Thu, 16 Apr 2020 16:00:21 GMT (envelope-from manu@FreeBSD.org) Message-Id: <202004161600.03GG0L9p032181@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Thu, 16 Apr 2020 16:00:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r360011 - in head/sys: arm/allwinner modules/allwinner modules/allwinner/aw_mmc X-SVN-Group: head X-SVN-Commit-Author: manu X-SVN-Commit-Paths: in head/sys: arm/allwinner modules/allwinner modules/allwinner/aw_mmc X-SVN-Commit-Revision: 360011 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Apr 2020 16:00:22 -0000 Author: manu Date: Thu Apr 16 16:00:21 2020 New Revision: 360011 URL: https://svnweb.freebsd.org/changeset/base/360011 Log: arm: allwinner: aw_mmc: Make it possible to unload the module While here, add a makefile in sys/modules/allwinner so it is built. Also add the PNP info so devmatch will load this module automatically. MFC after: 1 month Added: head/sys/modules/allwinner/aw_mmc/ head/sys/modules/allwinner/aw_mmc/Makefile (contents, props changed) Modified: head/sys/arm/allwinner/aw_mmc.c head/sys/modules/allwinner/Makefile Modified: head/sys/arm/allwinner/aw_mmc.c ============================================================================== --- head/sys/arm/allwinner/aw_mmc.c Thu Apr 16 15:59:23 2020 (r360010) +++ head/sys/arm/allwinner/aw_mmc.c Thu Apr 16 16:00:21 2020 (r360011) @@ -163,6 +163,7 @@ static int aw_mmc_probe(device_t); static int aw_mmc_attach(device_t); static int aw_mmc_detach(device_t); static int aw_mmc_setup_dma(struct aw_mmc_softc *); +static void aw_mmc_teardown_dma(struct aw_mmc_softc *sc); static int aw_mmc_reset(struct aw_mmc_softc *); static int aw_mmc_init(struct aw_mmc_softc *); static void aw_mmc_intr(void *); @@ -559,8 +560,46 @@ fail: static int aw_mmc_detach(device_t dev) { + struct aw_mmc_softc *sc; + device_t d; - return (EBUSY); + sc = device_get_softc(dev); + + clk_disable(sc->aw_clk_mmc); + clk_disable(sc->aw_clk_ahb); + hwreset_assert(sc->aw_rst_ahb); + + mmc_fdt_gpio_teardown(&sc->mmc_helper); + + callout_drain(&sc->aw_timeoutc); + + AW_MMC_LOCK(sc); + d = sc->child; + sc->child = NULL; + AW_MMC_UNLOCK(sc); + if (d != NULL) + device_delete_child(sc->aw_dev, d); + + aw_mmc_teardown_dma(sc); + + mtx_destroy(&sc->aw_mtx); + + bus_teardown_intr(dev, sc->aw_res[AW_MMC_IRQRES], sc->aw_intrhand); + bus_release_resources(dev, aw_mmc_res_spec, sc->aw_res); + +#ifdef MMCCAM + if (sc->sim != NULL) { + mtx_lock(&sc->sim_mtx); + xpt_bus_deregister(cam_sim_path(sc->sim)); + cam_sim_free(sc->sim, FALSE); + mtx_unlock(&sc->sim_mtx); + } + + if (sc->devq != NULL) + cam_simq_free(sc->devq); +#endif + + return (0); } static void @@ -635,6 +674,21 @@ aw_mmc_setup_dma(struct aw_mmc_softc *sc) } static void +aw_mmc_teardown_dma(struct aw_mmc_softc *sc) +{ + + bus_dmamap_unload(sc->aw_dma_tag, sc->aw_dma_map); + bus_dmamem_free(sc->aw_dma_tag, sc->aw_dma_desc, sc->aw_dma_map); + if (bus_dma_tag_destroy(sc->aw_dma_tag) != 0) + device_printf(sc->aw_dev, "Cannot destroy the dma tag\n"); + + bus_dmamap_unload(sc->aw_dma_buf_tag, sc->aw_dma_buf_map); + bus_dmamap_destroy(sc->aw_dma_buf_tag, sc->aw_dma_buf_map); + if (bus_dma_tag_destroy(sc->aw_dma_buf_tag) != 0) + device_printf(sc->aw_dev, "Cannot destroy the dma buf tag\n"); +} + +static void aw_dma_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int err) { int i; @@ -1519,3 +1573,4 @@ DRIVER_MODULE(aw_mmc, simplebus, aw_mmc_driver, aw_mmc #ifndef MMCCAM MMC_DECLARE_BRIDGE(aw_mmc); #endif +SIMPLEBUS_PNP_INFO(compat_data); Modified: head/sys/modules/allwinner/Makefile ============================================================================== --- head/sys/modules/allwinner/Makefile Thu Apr 16 15:59:23 2020 (r360010) +++ head/sys/modules/allwinner/Makefile Thu Apr 16 16:00:21 2020 (r360011) @@ -2,6 +2,7 @@ # Build modules specific to Allwinner. SUBDIR = \ + aw_mmc \ aw_pwm \ aw_rtc \ aw_rsb \ Added: head/sys/modules/allwinner/aw_mmc/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/modules/allwinner/aw_mmc/Makefile Thu Apr 16 16:00:21 2020 (r360011) @@ -0,0 +1,14 @@ +# $FreeBSD$ + +.PATH: ${SRCTOP}/sys/arm/allwinner + +KMOD= aw_mmc +SRCS= aw_mmc.c + +SRCS+= \ + bus_if.h \ + clknode_if.h \ + device_if.h \ + ofw_bus_if.h + +.include