a10_ahci: grab the target-supply regulator and enable it

This regulator is marked regulator-boot-on, but it will get shutdown if it's
not actually used/enabled by a driver. This should fix sata on the
cubieboard{1,2}.

Reported by:	Ray White @ UWaterloo
Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D23112
This commit is contained in:
Kyle Evans 2020-01-10 14:09:59 +00:00
parent 92dfc0fc1d
commit 3898f9bdb3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=356600

View File

@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
#include <dev/ahci/ahci.h>
#include <dev/extres/clk/clk.h>
#include <dev/extres/regulator/regulator.h>
/*
* Allwinner a1x/a2x/a8x SATA attachment. This is just the AHCI register
@ -118,6 +119,11 @@ __FBSDID("$FreeBSD$");
#define PLL_FREQ 100000000
struct ahci_a10_softc {
struct ahci_controller ahci_ctlr;
regulator_t ahci_reg;
};
static void inline
ahci_set(struct resource *m, bus_size_t off, uint32_t set)
{
@ -295,10 +301,12 @@ static int
ahci_a10_attach(device_t dev)
{
int error;
struct ahci_a10_softc *sc;
struct ahci_controller *ctlr;
clk_t clk_pll, clk_gate;
ctlr = device_get_softc(dev);
sc = device_get_softc(dev);
ctlr = &sc->ahci_ctlr;
clk_pll = clk_gate = NULL;
ctlr->quirks = AHCI_Q_NOPMP;
@ -311,6 +319,19 @@ 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;
}
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);
if (error != 0) {
@ -357,6 +378,8 @@ ahci_a10_attach(device_t dev)
return (ahci_attach(dev));
fail:
if (sc->ahci_reg != 0)
regulator_disable(sc->ahci_reg);
if (clk_gate != NULL)
clk_release(clk_gate);
if (clk_pll != NULL)
@ -388,7 +411,7 @@ static device_method_t ahci_ata_methods[] = {
static driver_t ahci_ata_driver = {
"ahci",
ahci_ata_methods,
sizeof(struct ahci_controller)
sizeof(struct ahci_a10_softc)
};
DRIVER_MODULE(a10_ahci, simplebus, ahci_ata_driver, ahci_devclass, 0, 0);