The value from the "ports implemented" register should be kept in mind
when registering ports or detecting devices on them.

Signed-off-by: Denis Orlov <denorl2...@gmail.com>
---
 drivers/ata/ahci.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index f9056ff418..24098ada08 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -563,11 +563,15 @@ void ahci_info(struct device_d *dev)
 static int ahci_detect(struct device_d *dev)
 {
        struct ahci_device *ahci = dev->priv;
+       int n_ports = max_t(int, ahci->n_ports, fls(ahci->port_map));
        int i;
 
-       for (i = 0; i < ahci->n_ports; i++) {
+       for (i = 0; i < n_ports; i++) {
                struct ahci_port *ahci_port = &ahci->ports[i];
 
+               if (!(ahci->port_map & (1 << i)))
+                       continue;
+
                ata_port_detect(&ahci_port->ata);
        }
 
@@ -577,7 +581,7 @@ static int ahci_detect(struct device_d *dev)
 int ahci_add_host(struct ahci_device *ahci)
 {
        u32 tmp, cap_save;
-       int i, ret;
+       int n_ports, i, ret;
 
        ahci->host_flags = ATA_FLAG_SATA
                                | ATA_FLAG_NO_LEGACY
@@ -619,9 +623,14 @@ int ahci_add_host(struct ahci_device *ahci)
        ahci_debug(ahci, "cap 0x%x  port_map 0x%x  n_ports %d\n",
              ahci->cap, ahci->port_map, ahci->n_ports);
 
-       for (i = 0; i < ahci->n_ports; i++) {
+       n_ports = max_t(int, ahci->n_ports, fls(ahci->port_map));
+
+       for (i = 0; i < n_ports; i++) {
                struct ahci_port *ahci_port = &ahci->ports[i];
 
+               if (!(ahci->port_map & (1 << i)))
+                       continue;
+
                ahci_port->num = i;
                ahci_port->ahci = ahci;
                ahci_port->ata.dev = ahci->dev;
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

Reply via email to