[Arm-dev] [PATCH v1 52/87] Juno / net: smsc911x add support for probing from ACPI

Thu Aug 13 13:18:49 UTC 2015
Vadim Lomovtsev <Vadim.Lomovtsev at caviumnetworks.com>

From: Graeme Gregory <graeme.gregory at linaro.org>

This is a standard platform device to resources are converted in the
ACPI core in the same fasion as DT resources. For the other DT
provided information there is _DSD for ACPI.

Signed-off-by: Graeme Gregory <graeme.gregory at linaro.org>
Signed-off-by: Vadim Lomovtsev <Vadim.Lomovtsev at caviumnetworks.com>
---
 drivers/net/ethernet/smsc/smsc911x.c | 38 ++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/drivers/net/ethernet/smsc/smsc911x.c b/drivers/net/ethernet/smsc/smsc911x.c
index 959aeea..9161f0a 100644
--- a/drivers/net/ethernet/smsc/smsc911x.c
+++ b/drivers/net/ethernet/smsc/smsc911x.c
@@ -31,6 +31,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/acpi.h>
 #include <linux/crc32.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
@@ -2412,9 +2413,36 @@ static inline int smsc911x_probe_config_dt(
 }
 #endif /* CONFIG_OF */
 
+#ifdef CONFIG_ACPI
+/* Configure some sensible defaults for ACPI mode */
+static int smsc911x_probe_config_acpi(struct smsc911x_platform_config *config,
+				    acpi_handle *ahandle)
+{
+	if (!ahandle)
+		return -ENOSYS;
+
+	config->phy_interface = PHY_INTERFACE_MODE_MII;
+
+	config->flags |= SMSC911X_USE_32BIT;
+
+	config->irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH;
+
+	config->irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL;
+
+	return 0;
+}
+#else
+static int smsc911x_probe_config_acpi(struct smsc911x_platform_config *config,
+				      acpi_handle *ahandle)
+{
+	return -ENOSYS;
+}
+#endif /* CONFIG_ACPI */
+
 static int smsc911x_drv_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
+	acpi_handle *ahandle = ACPI_HANDLE(&pdev->dev);
 	struct net_device *dev;
 	struct smsc911x_data *pdata;
 	struct smsc911x_platform_config *config = dev_get_platdata(&pdev->dev);
@@ -2479,6 +2507,9 @@ static int smsc911x_drv_probe(struct platform_device *pdev)
 	}
 
 	retval = smsc911x_probe_config_dt(&pdata->config, np);
+	if (retval)
+		retval = smsc911x_probe_config_acpi(&pdata->config, ahandle);
+
 	if (retval && config) {
 		/* copy config parameters across to pdata */
 		memcpy(&pdata->config, config, sizeof(pdata->config));
@@ -2654,6 +2685,12 @@ static const struct of_device_id smsc911x_dt_ids[] = {
 MODULE_DEVICE_TABLE(of, smsc911x_dt_ids);
 #endif
 
+static const struct acpi_device_id smsc911x_acpi_ids[] = {
+	{ "LNRO001B", },
+	{ "ARMH9118", },
+	{ }
+};
+
 static struct platform_driver smsc911x_driver = {
 	.probe = smsc911x_drv_probe,
 	.remove = smsc911x_drv_remove,
@@ -2661,6 +2698,7 @@ static struct platform_driver smsc911x_driver = {
 		.name	= SMSC_CHIPNAME,
 		.pm	= SMSC911X_PM_OPS,
 		.of_match_table = of_match_ptr(smsc911x_dt_ids),
+		.acpi_match_table = ACPI_PTR(smsc911x_acpi_ids),
 	},
 };
 
-- 
2.4.3