From cc608470f3234f1696d26db6b569c942f86bd2ce Mon Sep 17 00:00:00 2001 From: dlg Date: Sat, 8 Apr 2023 02:32:38 +0000 Subject: [PATCH] try and cope with not having the firmware/boot loader init the hardware. more specifically, spin up the clocks and phy, and if the device tree has a "ports-implemented" property use it to initialise the AHCI_REG_PI register. this gets sata working on a banana pi bpi-r2 pro. help from jared mcneill ok jmatthew@ kettenis@ --- sys/dev/fdt/ahci_fdt.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/sys/dev/fdt/ahci_fdt.c b/sys/dev/fdt/ahci_fdt.c index aa9f20c1b28..c94eb68e1e6 100644 --- a/sys/dev/fdt/ahci_fdt.c +++ b/sys/dev/fdt/ahci_fdt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ahci_fdt.c,v 1.7 2022/05/25 03:03:58 dlg Exp $ */ +/* $OpenBSD: ahci_fdt.c,v 1.8 2023/04/08 02:32:38 dlg Exp $ */ /* * Copyright (c) 2013,2017 Patrick Wildt * @@ -30,6 +30,8 @@ #include #include +#include +#include #include int ahci_fdt_match(struct device *, void *, void *); @@ -63,6 +65,7 @@ ahci_fdt_attach(struct device *parent, struct device *self, void *aux) { struct ahci_softc *sc = (struct ahci_softc *) self; struct fdt_attach_args *faa = aux; + uint32_t pi; if (faa->fa_nreg < 1) return; @@ -82,11 +85,20 @@ ahci_fdt_attach(struct device *parent, struct device *self, void *aux) goto unmap; } + clock_set_assigned(faa->fa_node); + clock_enable_all(faa->fa_node); + phy_enable(faa->fa_node, "sata-phy"); + + bus_space_write_4(sc->sc_iot, sc->sc_ioh, 0x118, 1U << 22); + pi = OF_getpropint(faa->fa_node, "ports-implemented", 0x0); + if (pi != 0) + bus_space_write_4(sc->sc_iot, sc->sc_ioh, AHCI_REG_PI, pi); + printf(":"); if (ahci_attach(sc) != 0) { /* error printed by ahci_attach */ - goto irq; + goto irq; /* disable phy and clocks? */ } return; -- 2.20.1