From owner-svn-src-all@freebsd.org Thu Jan 16 20:19:20 2020 Return-Path: Delivered-To: svn-src-all@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 96FC51F47C0; Thu, 16 Jan 2020 20:19:20 +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 47zFsN3WW7z4XSR; Thu, 16 Jan 2020 20:19:20 +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 740D8250D6; Thu, 16 Jan 2020 20:19:20 +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 00GKJKnx095198; Thu, 16 Jan 2020 20:19:20 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 00GKJKMN095197; Thu, 16 Jan 2020 20:19:20 GMT (envelope-from manu@FreeBSD.org) Message-Id: <202001162019.00GKJKMN095197@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Thu, 16 Jan 2020 20:19:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r356802 - head/sys/arm/allwinner X-SVN-Group: head X-SVN-Commit-Author: manu X-SVN-Commit-Paths: head/sys/arm/allwinner X-SVN-Commit-Revision: 356802 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jan 2020 20:19:20 -0000 Author: manu Date: Thu Jan 16 20:19:20 2020 New Revision: 356802 URL: https://svnweb.freebsd.org/changeset/base/356802 Log: arm: allwinner: ahci: target-supply is optional The target-supply regulator is optional so don't fail if it's not present. While here disable the clock on detach. MFC after: 2 weeks X-MFC-With: 356600 Modified: head/sys/arm/allwinner/a10_ahci.c Modified: head/sys/arm/allwinner/a10_ahci.c ============================================================================== --- head/sys/arm/allwinner/a10_ahci.c Thu Jan 16 20:12:15 2020 (r356801) +++ head/sys/arm/allwinner/a10_ahci.c Thu Jan 16 20:19:20 2020 (r356802) @@ -122,6 +122,8 @@ __FBSDID("$FreeBSD$"); struct ahci_a10_softc { struct ahci_controller ahci_ctlr; regulator_t ahci_reg; + clk_t clk_pll; + clk_t clk_gate; }; static void inline @@ -303,11 +305,9 @@ ahci_a10_attach(device_t dev) int error; struct ahci_a10_softc *sc; struct ahci_controller *ctlr; - clk_t clk_pll, clk_gate; sc = device_get_softc(dev); ctlr = &sc->ahci_ctlr; - clk_pll = clk_gate = NULL; ctlr->quirks = AHCI_Q_NOPMP; ctlr->vendorid = 0; @@ -319,41 +319,38 @@ ahci_a10_attach(device_t dev) &ctlr->r_rid, RF_ACTIVE))) return (ENXIO); - /* Enable the regulator */ - error = regulator_get_by_ofw_property(dev, 0, "target-supply", - &sc->ahci_reg); - if (error != 0) { - device_printf(dev, "Cannot get regulator\n"); - goto fail; + /* Enable the (optional) regulator */ + if (regulator_get_by_ofw_property(dev, 0, "target-supply", + &sc->ahci_reg) == 0) { + error = regulator_enable(sc->ahci_reg); + if (error != 0) { + device_printf(dev, "Could not enable regulator\n"); + goto fail; + } } - error = regulator_enable(sc->ahci_reg); - if (error != 0) { - device_printf(dev, "Could not enable regulator\n"); - goto fail; - } /* Enable clocks */ - error = clk_get_by_ofw_index(dev, 0, 0, &clk_gate); + error = clk_get_by_ofw_index(dev, 0, 0, &sc->clk_gate); if (error != 0) { device_printf(dev, "Cannot get gate clock\n"); goto fail; } - error = clk_get_by_ofw_index(dev, 0, 1, &clk_pll); + error = clk_get_by_ofw_index(dev, 0, 1, &sc->clk_pll); if (error != 0) { device_printf(dev, "Cannot get PLL clock\n"); goto fail; } - error = clk_set_freq(clk_pll, PLL_FREQ, CLK_SET_ROUND_DOWN); + error = clk_set_freq(sc->clk_pll, PLL_FREQ, CLK_SET_ROUND_DOWN); if (error != 0) { device_printf(dev, "Cannot set PLL frequency\n"); goto fail; } - error = clk_enable(clk_pll); + error = clk_enable(sc->clk_pll); if (error != 0) { device_printf(dev, "Cannot enable PLL\n"); goto fail; } - error = clk_enable(clk_gate); + error = clk_enable(sc->clk_gate); if (error != 0) { device_printf(dev, "Cannot enable clk gate\n"); goto fail; @@ -378,12 +375,12 @@ ahci_a10_attach(device_t dev) return (ahci_attach(dev)); fail: - if (sc->ahci_reg != 0) + if (sc->ahci_reg != NULL) regulator_disable(sc->ahci_reg); - if (clk_gate != NULL) - clk_release(clk_gate); - if (clk_pll != NULL) - clk_release(clk_pll); + if (sc->clk_gate != NULL) + clk_release(sc->clk_gate); + if (sc->clk_pll != NULL) + clk_release(sc->clk_pll); bus_release_resource(dev, SYS_RES_MEMORY, ctlr->r_rid, ctlr->r_mem); return (error); } @@ -391,7 +388,19 @@ fail: static int ahci_a10_detach(device_t dev) { + struct ahci_a10_softc *sc; + struct ahci_controller *ctlr; + sc = device_get_softc(dev); + ctlr = &sc->ahci_ctlr; + + if (sc->ahci_reg != NULL) + regulator_disable(sc->ahci_reg); + if (sc->clk_gate != NULL) + clk_release(sc->clk_gate); + if (sc->clk_pll != NULL) + clk_release(sc->clk_pll); + bus_release_resource(dev, SYS_RES_MEMORY, ctlr->r_rid, ctlr->r_mem); return (ahci_detach(dev)); }