@@ -16,6 +16,7 @@
#include <linux/mbus.h>
#include <linux/module.h>
#include <linux/of_device.h>
+#include <linux/of_irq.h>
#include <linux/platform_device.h>
#include "ahci.h"
@@ -28,9 +29,15 @@
#define AHCI_WINDOW_BASE(win) (0x64 + ((win) << 4))
#define AHCI_WINDOW_SIZE(win) (0x68 + ((win) << 4))
+#define ICU_SATA0_ICU_ID 109
+#define ICU_SATA1_ICU_ID 107
+
struct ahci_mvebu_plat_data {
- int (*plat_config)(struct ahci_host_priv *hpriv);
+ int (*plat_config)(struct platform_device *pdev,
+ struct ahci_host_priv *hpriv);
unsigned int host_flags;
+ unsigned int resource_flags;
+ unsigned int port_irq[2];
};
static void ahci_mvebu_mbus_config(struct ahci_host_priv *hpriv,
@@ -67,7 +74,8 @@ static void ahci_mvebu_regret_option(struct ahci_host_priv *hpriv)
writel(0x80, hpriv->mmio + AHCI_VENDOR_SPECIFIC_0_DATA);
}
-static int ahci_mvebu_armada_380_config(struct ahci_host_priv *hpriv)
+static int ahci_mvebu_armada_380_config(struct platform_device *pdev,
+ struct ahci_host_priv *hpriv)
{
const struct mbus_dram_target_info *dram;
int rc = 0;
@@ -83,7 +91,8 @@ static int ahci_mvebu_armada_380_config(struct ahci_host_priv *hpriv)
return rc;
}
-static int ahci_mvebu_armada_3700_config(struct ahci_host_priv *hpriv)
+static int ahci_mvebu_armada_3700_config(struct platform_device *pdev,
+ struct ahci_host_priv *hpriv)
{
u32 reg;
@@ -96,8 +105,94 @@ static int ahci_mvebu_armada_3700_config(struct ahci_host_priv *hpriv)
return 0;
}
-static int ahci_mvebu_armada_8k_config(struct ahci_host_priv *hpriv)
+static int multi_irq_host_ack_armada8k(int irq, struct ata_port *ap)
{
+ struct ahci_host_priv *hpriv = ap->host->private_data;
+ void __iomem *mmio = hpriv->mmio;
+
+ writel(BIT(ap->port_no), mmio + HOST_IRQ_STAT);
+
+ return 0;
+}
+
+static int ahci_get_per_port_irq_armada8k(struct ata_host *host, int port)
+{
+ struct ahci_host_priv *hpriv = host->private_data;
+ struct ahci_mvebu_plat_data *pdata = hpriv->plat_data;
+
+ return pdata->port_irq[port];
+}
+
+static int ahci_mvebu_armada_8k_irq_backwards(struct ahci_host_priv *hpriv,
+ struct device *dev)
+{
+ struct device_node *np = of_irq_find_parent(dev->of_node);
+ struct ahci_mvebu_plat_data *pdata = hpriv->plat_data;
+ struct irq_data *irqd = irq_get_irq_data(pdata->port_irq[0]);
+ int host_irq = irqd ? irqd_to_hwirq(irqd) : 0;
+ int missing_irq = (host_irq == ICU_SATA1_ICU_ID) ?
+ ICU_SATA0_ICU_ID : ICU_SATA1_ICU_ID;
+ struct irq_fwspec fwspec = {
+ .fwnode = of_node_to_fwnode(np),
+ .param_count = 2,
+ .param = {missing_irq, IRQ_TYPE_LEVEL_HIGH},
+ };
+ int irq;
+
+ pdata->port_irq[1] = irq_create_fwspec_mapping(&fwspec);
+ hpriv->mask_port_map = GENMASK(1, 0);
+
+ if (missing_irq == ICU_SATA0_ICU_ID) {
+ irq = pdata->port_irq[0];
+ pdata->port_irq[0] = pdata->port_irq[1];
+ pdata->port_irq[1] = irq;
+ }
+
+ return 0;
+}
+
+static int ahci_mvebu_armada_8k_config(struct platform_device *pdev,
+ struct ahci_host_priv *hpriv)
+{
+ struct ahci_mvebu_plat_data *pdata = hpriv->plat_data;
+ struct device *dev = &pdev->dev;
+ struct device_node *child;
+ int port_irq, child_nodes, port = 0;
+
+ /* Get IRQs per port */
+ child_nodes = of_get_child_count(dev->of_node);
+ if (child_nodes) {
+ for_each_child_of_node(dev->of_node, child) {
+
+ port_irq = of_irq_get(child, 0);
+ if (!port_irq)
+ port_irq = -EINVAL;
+
+ if (port_irq < 0)
+ goto compat;
+
+ pdata->port_irq[port] = port_irq;
+ port++;
+ }
+
+ goto out;
+ }
+
+compat:
+ /* Backwards Compatibility Check */
+ port_irq = platform_get_irq(pdev, 0);
+ if (port_irq > 0) {
+ pdata->port_irq[0] = port_irq;
+ ahci_mvebu_armada_8k_irq_backwards(hpriv, dev);
+ } else {
+ dev_err(dev, "no irq\n");
+ return port_irq;
+ }
+
+out:
+ hpriv->flags |= AHCI_HFLAG_MULTI_MSI;
+ hpriv->get_irq_vector = ahci_get_per_port_irq_armada8k;
+
return 0;
}
@@ -167,7 +262,7 @@ static int ahci_mvebu_resume(struct platform_device *pdev)
struct ahci_host_priv *hpriv = host->private_data;
const struct ahci_mvebu_plat_data *pdata = hpriv->plat_data;
- pdata->plat_config(hpriv);
+ pdata->plat_config(pdev, hpriv);
return ahci_platform_resume_host(&pdev->dev);
}
@@ -189,15 +284,22 @@ static struct scsi_host_template ahci_platform_sht = {
static int ahci_mvebu_probe(struct platform_device *pdev)
{
- const struct ahci_mvebu_plat_data *pdata;
+ const struct ahci_mvebu_plat_data *pdata_plat;
+ struct ahci_mvebu_plat_data *pdata;
struct ahci_host_priv *hpriv;
int rc;
- pdata = of_device_get_match_data(&pdev->dev);
- if (!pdata)
+ pdata_plat = of_device_get_match_data(&pdev->dev);
+ if (!pdata_plat)
return -EINVAL;
- hpriv = ahci_platform_get_resources(pdev, 0);
+ pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+ if (!pdata)
+ return -ENOMEM;
+
+ memcpy(pdata, pdata_plat, sizeof(*pdata));
+
+ hpriv = ahci_platform_get_resources(pdev, pdata->resource_flags);
if (IS_ERR(hpriv))
return PTR_ERR(hpriv);
@@ -210,10 +312,13 @@ static int ahci_mvebu_probe(struct platform_device *pdev)
hpriv->stop_engine = ahci_mvebu_stop_engine;
- rc = pdata->plat_config(hpriv);
+ rc = pdata->plat_config(pdev, hpriv);
if (rc)
goto disable_resources;
+ if (pdata->resource_flags & AHCI_PLATFORM_ARMADA8K_QUIRK)
+ hpriv->multi_irq_host_ack = multi_irq_host_ack_armada8k;
+
rc = ahci_platform_init_host(pdev, hpriv, &ahci_mvebu_port_info,
&ahci_platform_sht);
if (rc)
@@ -237,6 +342,7 @@ static const struct ahci_mvebu_plat_data ahci_mvebu_armada_3700_plat_data = {
static const struct ahci_mvebu_plat_data ahci_mvebu_armada_8k_plat_data = {
.plat_config = ahci_mvebu_armada_8k_config,
+ .resource_flags = AHCI_PLATFORM_ARMADA8K_QUIRK,
};
static const struct of_device_id ahci_mvebu_of_match[] = {
@@ -464,6 +464,9 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,
if (!child_nodes)
hpriv->nports = 1;
+ if (!child_nodes && flags & AHCI_PLATFORM_ARMADA8K_QUIRK)
+ hpriv->nports = 2;
+
hpriv->phys = devm_kcalloc(dev, hpriv->nports, sizeof(*hpriv->phys), GFP_KERNEL);
if (!hpriv->phys) {
rc = -ENOMEM;
@@ -42,5 +42,6 @@ int ahci_platform_suspend(struct device *dev);
int ahci_platform_resume(struct device *dev);
#define AHCI_PLATFORM_GET_RESETS 0x01
+#define AHCI_PLATFORM_ARMADA8K_QUIRK 0x02
#endif /* _AHCI_PLATFORM_H */