mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Luca Lauro via B4 Relay <devnull+famlauro93l.gmail.com@kernel.org>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	 "open list:BAREBOX" <barebox@lists.infradead.org>
Cc: Luca Lauro <famlauro93l@gmail.com>
Subject: [PATCH v3 09/15] ata: ahci: add PCI AHCI and Marvell 9170 controller support
Date: Sun, 02 Aug 2026 15:16:25 +0200	[thread overview]
Message-ID: <20260802-rn102-rn104-series-v3-9-f7685a279fb5@gmail.com> (raw)
In-Reply-To: <20260802-rn102-rn104-series-v3-0-f7685a279fb5@gmail.com>

From: Luca Lauro <famlauro93l@gmail.com>

Barebox previously supported only memory-mapped AHCI controllers.
Some devices expose their AHCI controller through PCI BARs, such as the
Marvell 9170 controller found in Netgear RN102/RN104 NAS devices,
requiring a dedicated probing path and MMIO mapping.
This patch extends the barebox AHCI driver with full support for
PCI-based AHCI controllers, adding:

- A PCI probe path that enables AHCI initialization via
pci_enable_device(), pci_iomap() and ahci_add_host().

- A small device list to keep track of PCI AHCI instances.

Changes are based on the upstream Linux driver, with some adaptations.

Signed-off-by: Luca Lauro <famlauro93l@gmail.com>
---
 drivers/ata/ahci.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/ata/ahci.h |  1 +
 2 files changed, 55 insertions(+)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 819dc37b3e..0ac1a9dead 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -19,6 +19,7 @@
 #include <disks.h>
 #include <ata_drive.h>
 #include <linux/sizes.h>
+#include <linux/pci.h>
 #include <clock.h>
 
 #include "ahci.h"
@@ -47,6 +48,51 @@
 #define ahci_debug(ahci, fmt, arg...) \
 	dev_dbg(ahci->dev, fmt, ##arg)
 
+#ifndef PCI_VENDOR_ID_MARVELL_EXT
+#define PCI_VENDOR_ID_MARVELL_EXT 0x1b4b
+#endif
+
+static LIST_HEAD(ahci_devices);
+
+static const struct pci_device_id ahci_pci_tbl[] = {
+	{ PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x9170) },
+	{ 0, }
+};
+
+static int ahci_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+{
+	struct ahci_device *ahci;
+	void __iomem *mmio;
+	int ret;
+
+	dev_info(&pdev->dev, "ahci: PCI probe %04x:%04x rev %02x\n",
+			pdev->vendor, pdev->device, pdev->revision);
+
+	ret = pci_enable_device(pdev);
+	if (ret)
+		return ret;
+
+	pci_set_master(pdev);
+
+	mmio = pci_iomap(pdev, 5);
+	if (!mmio)
+		return -ENODEV;
+
+	ahci = xzalloc(sizeof(*ahci));
+	ahci->dev = &pdev->dev;
+	ahci->mmio_base = mmio;
+	pdev->dev.priv = ahci;
+
+	ret = ahci_add_host(ahci);
+	if (ret) {
+		free(ahci);
+		pdev->dev.priv = NULL;
+		return ret;
+	}
+
+	return 0;
+}
+
 struct ahci_cmd_hdr {
 	u32	opts;
 	u32	status;
@@ -635,6 +681,7 @@ int ahci_add_host(struct ahci_device *ahci)
 	tmp = ahci_ioread(ahci, HOST_CTL);
 
 	ahci->dev->detect = ahci_detect;
+	list_add(&ahci->list, &ahci_devices);
 
 	return 0;
 }
@@ -674,6 +721,13 @@ static __maybe_unused struct of_device_id ahci_dt_ids[] = {
 };
 MODULE_DEVICE_TABLE(of, ahci_dt_ids);
 
+static struct pci_driver ahci_pci_driver = {
+	.name = "ahci-pci",
+	.id_table = ahci_pci_tbl,
+	.probe = ahci_pci_probe,
+};
+device_pci_driver(ahci_pci_driver);
+
 static struct driver ahci_driver = {
 	.name   = "ahci",
 	.probe  = ahci_probe,
diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
index 196bde73c2..d2a19f4648 100644
--- a/drivers/ata/ahci.h
+++ b/drivers/ata/ahci.h
@@ -184,6 +184,7 @@ struct ahci_port {
 };
 
 struct ahci_device {
+	struct list_head list;
 	struct device		*dev;
 	struct ahci_port	ports[AHCI_MAX_PORTS];
 	u32			n_ports;

-- 
2.47.3





  parent reply	other threads:[~2026-08-02 13:17 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-02 13:16 [PATCH v3 00/15] ARM: mvebu: add Netgear RN102/RN104 support and related drivers Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 01/15] ARM: mvebu: add Netgear RN102 support Luca Lauro via B4 Relay
2026-08-03 12:53   ` Sascha Hauer
2026-08-03 13:43     ` Marco Felsch
2026-08-02 13:16 ` [PATCH v3 02/15] ARM: mvebu: enable RN102 in mvebu_defconfig Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 03/15] ARM: mvebu: improve Netgear RN104 support Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 04/15] ARM: mvebu: rename PUTC_LL to MVEBU_PUTC_LL Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 05/15] drivers: fan: add fan subsystem, core API and G76x fan controller driver Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 06/15] commands: add fan control command Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 07/15] usb: ehci: add Marvell EHCI host controller driver Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 08/15] usb: ehci: initialize periodic_queue_dma Luca Lauro via B4 Relay
2026-08-03 21:27   ` Sascha Hauer
2026-08-02 13:16 ` Luca Lauro via B4 Relay [this message]
2026-08-03 21:33   ` [PATCH v3 09/15] ata: ahci: add PCI AHCI and Marvell 9170 controller support Sascha Hauer
2026-08-02 13:16 ` [PATCH v3 10/15] ata: ahci: fix zero-length DMA handling Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 11/15] ata: ahci: add helper for ATA commands without data Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 12/15] ata: ahci: improve AHCI port bring-up sequence Luca Lauro via B4 Relay
2026-08-02 13:16 ` [PATCH v3 13/15] ata: ahci: add FLUSH EXT and STANDBY IMMEDIATE support during shutdown Luca Lauro via B4 Relay
2026-08-03 21:52   ` Sascha Hauer
2026-08-02 13:16 ` [PATCH v3 14/15] ata: ahci: add shutdown helpers for AHCI controllers Luca Lauro via B4 Relay
2026-08-03 21:55   ` Sascha Hauer
2026-08-02 13:16 ` [PATCH v3 15/15] ata: ahci: cleanup legacy code and remove unused paths Luca Lauro via B4 Relay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260802-rn102-rn104-series-v3-9-f7685a279fb5@gmail.com \
    --to=devnull+famlauro93l.gmail.com@kernel.org \
    --cc=barebox@lists.infradead.org \
    --cc=famlauro93l@gmail.com \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox