Skip to contentSkip to conversation

i2c: i2c-cros-ec-tunnel: Make the device acpi compatible

PATCH Applied Akshu Agrawal 5 participants 5 messages Nov 11, 2019 – Nov 12, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: i2c-cros-ec-tunnel: Make the device acpi compatible

Add ACPI entry and use device_property_read to get fw value which is common to both dtsi and acpi.

---
 drivers/i2c/busses/i2c-cros-ec-tunnel.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-cros-ec-tunnel.c +10 -5
index c551aa96a2e3..958161c71985 100644
@@ -3,6 +3,7 @@
 //
 // Copyright (C) 2013 Google, Inc.
 
+#include <linux/acpi.h>
 #include <linux/module.h>
 #include <linux/i2c.h>
 #include <linux/platform_data/cros_ec_commands.h>
@@ -240,7 +241,6 @@ static const struct i2c_algorithm ec_i2c_algorithm = {
 
 static int ec_i2c_probe(struct platform_device *pdev)
 {
-	struct device_node *np = pdev->dev.of_node;
 	struct cros_ec_device *ec = dev_get_drvdata(pdev->dev.parent);
 	struct device *dev = &pdev->dev;
 	struct ec_i2c_device *bus = NULL;
@@ -256,7 +256,7 @@ static int ec_i2c_probe(struct platform_device *pdev)
 	if (bus == NULL)
 		return -ENOMEM;
 
-	err = of_property_read_u32(np, "google,remote-bus", &remote_bus);
+	err = device_property_read_u32(dev, "google,remote-bus", &remote_bus);
 	if (err) {
 		dev_err(dev, "Couldn't read remote-bus property\n");
 		return err;
@@ -271,7 +271,7 @@ static int ec_i2c_probe(struct platform_device *pdev)
 	bus->adap.algo = &ec_i2c_algorithm;
 	bus->adap.algo_data = bus;
 	bus->adap.dev.parent = &pdev->dev;
-	bus->adap.dev.of_node = np;
+	bus->adap.dev.of_node = pdev->dev.of_node;
 	bus->adap.retries = I2C_MAX_RETRIES;
 
 	err = i2c_add_adapter(&bus->adap);
@@ -291,19 +291,24 @@ static int ec_i2c_remove(struct platform_device *dev)
 	return 0;
 }
 
-#ifdef CONFIG_OF
 static const struct of_device_id cros_ec_i2c_of_match[] = {
 	{ .compatible = "google,cros-ec-i2c-tunnel" },
 	{},
 };
 MODULE_DEVICE_TABLE(of, cros_ec_i2c_of_match);
-#endif
+
+static const struct acpi_device_id cros_ec_i2c_tunnel_acpi_id[] = {
+	{ "GOOG001A", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, cros_ec_i2c_tunnel_acpi_id);
 
 static struct platform_driver ec_i2c_tunnel_driver = {
 	.probe = ec_i2c_probe,
 	.remove = ec_i2c_remove,
 	.driver = {
 		.name = "cros-ec-i2c-tunnel",
+		.acpi_match_table = ACPI_PTR(cros_ec_i2c_tunnel_acpi_id),
 		.of_match_table = of_match_ptr(cros_ec_i2c_of_match),
 	},
 };
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 75 lines · Akshu Agrawal

Add ACPI entry and use device_property_read to get fw value which is common to both dtsi and acpi.

---
 drivers/i2c/busses/i2c-cros-ec-tunnel.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-cros-ec-tunnel.c +10 -6
index c551aa96a2e3..958161c71985 100644
@@ -3,6 +3,7 @@
 //
 // Copyright (C) 2013 Google, Inc.
 
+#include <linux/acpi.h>
 #include <linux/module.h>
 #include <linux/i2c.h>
 #include <linux/platform_data/cros_ec_commands.h>
@@ -240,7 +241,6 @@ static const struct i2c_algorithm ec_i2c_algorithm = {
 
 static int ec_i2c_probe(struct platform_device *pdev)
 {
-       struct device_node *np = pdev->dev.of_node;
        struct cros_ec_device *ec = dev_get_drvdata(pdev->dev.parent);
        struct device *dev = &pdev->dev;
        struct ec_i2c_device *bus = NULL;
@@ -256,7 +256,7 @@ static int ec_i2c_probe(struct platform_device *pdev)
        if (bus == NULL)
                return -ENOMEM;
 
-       err = of_property_read_u32(np, "google,remote-bus", &remote_bus);
+       err = device_property_read_u32(dev, "google,remote-bus", &remote_bus);
        if (err) {
                dev_err(dev, "Couldn't read remote-bus property\n");
                return err;
@@ -271,7 +271,7 @@ static int ec_i2c_probe(struct platform_device *pdev)
        bus->adap.algo = &ec_i2c_algorithm;
        bus->adap.algo_data = bus;
        bus->adap.dev.parent = &pdev->dev;
-       bus->adap.dev.of_node = np;
+       bus->adap.dev.of_node = pdev->dev.of_node;
        bus->adap.retries = I2C_MAX_RETRIES;
 
        err = i2c_add_adapter(&bus->adap);
@@ -291,19 +291,24 @@ static int ec_i2c_remove(struct platform_device *dev)
        return 0;
 }
 
-#ifdef CONFIG_OF
 static const struct of_device_id cros_ec_i2c_of_match[] = {
        { .compatible = "google,cros-ec-i2c-tunnel" },
        {},
 };
 MODULE_DEVICE_TABLE(of, cros_ec_i2c_of_match);
-#endif
+
+static const struct acpi_device_id cros_ec_i2c_tunnel_acpi_id[] = {
+       { "GOOG001A", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(acpi, cros_ec_i2c_tunnel_acpi_id);
 
 static struct platform_driver ec_i2c_tunnel_driver = {
        .probe = ec_i2c_probe,
        .remove = ec_i2c_remove,
        .driver = {
                .name = "cros-ec-i2c-tunnel",
+               .acpi_match_table = ACPI_PTR(cros_ec_i2c_tunnel_acpi_id),
                .of_match_table = of_match_ptr(cros_ec_i2c_of_match),
        },
 };
--
Quoted 2 lines

2.17.1

Reviewed-by on v1 1/1
#2 lore raw
In reply to Akshu Agrawal

Hi Akshu,

Thanks for sending this upstream and improve CrOS EC

Quoted 38 lines · Akshu Agrawal

Add ACPI entry and use device_property_read to get fw value which is common to both dtsi and acpi.

---
 drivers/i2c/busses/i2c-cros-ec-tunnel.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-cros-ec-tunnel.c +2 -2
index c551aa96a2e3..958161c71985 100644
@@ -3,6 +3,7 @@
 //
 // Copyright (C) 2013 Google, Inc.
 
+#include <linux/acpi.h>
 #include <linux/module.h>
 #include <linux/i2c.h>
 #include <linux/platform_data/cros_ec_commands.h>
@@ -240,7 +241,6 @@ static const struct i2c_algorithm ec_i2c_algorithm = {
 
 static int ec_i2c_probe(struct platform_device *pdev)
 {
-	struct device_node *np = pdev->dev.of_node;
 	struct cros_ec_device *ec = dev_get_drvdata(pdev->dev.parent);
 	struct device *dev = &pdev->dev;
 	struct ec_i2c_device *bus = NULL;
@@ -256,7 +256,7 @@ static int ec_i2c_probe(struct platform_device *pdev)
 	if (bus == NULL)
 		return -ENOMEM;
 
-	err = of_property_read_u32(np, "google,remote-bus", &remote_bus);
+	err = device_property_read_u32(dev, "google,remote-bus", &remote_bus);
 	if (err) {
 		dev_err(dev, "Couldn't read remote-bus property\n");
 		return err;

drivers/i2c/busses/i2c-cros-ec-tunnel.c static int ec_i2c_probe(struct platform_device *pdev) · line 274

Quoted 5 lines
drivers/i2c/busses/i2c-cros-ec-tunnel.c +1 -1
@@ -271,7 +271,7 @@ static int ec_i2c_probe(struct platform_device *pdev)
 	bus->adap.algo = &ec_i2c_algorithm;
 	bus->adap.algo_data = bus;
 	bus->adap.dev.parent = &pdev->dev;
-	bus->adap.dev.of_node = np;
+	bus->adap.dev.of_node = pdev->dev.of_node;

That change is not really needed/(related) but as np was only used here I'm fine with it.

Quoted 21 lines
drivers/i2c/busses/i2c-cros-ec-tunnel.c +6 -2
 	bus->adap.retries = I2C_MAX_RETRIES;
 
 	err = i2c_add_adapter(&bus->adap);
@@ -291,19 +291,24 @@ static int ec_i2c_remove(struct platform_device *dev)
 	return 0;
 }
 
-#ifdef CONFIG_OF
 static const struct of_device_id cros_ec_i2c_of_match[] = {
 	{ .compatible = "google,cros-ec-i2c-tunnel" },
 	{},
 };
 MODULE_DEVICE_TABLE(of, cros_ec_i2c_of_match);
-#endif
+
+static const struct acpi_device_id cros_ec_i2c_tunnel_acpi_id[] = {
+	{ "GOOG001A", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, cros_ec_i2c_tunnel_acpi_id);

drivers/i2c/busses/i2c-cros-ec-tunnel.c static int ec_i2c_remove(struct platform_device *dev) · line 314

Quoted 10 lines
drivers/i2c/busses/i2c-cros-ec-tunnel.c +1 -0
 
 static struct platform_driver ec_i2c_tunnel_driver = {
 	.probe = ec_i2c_probe,
 	.remove = ec_i2c_remove,
 	.driver = {
 		.name = "cros-ec-i2c-tunnel",
+		.acpi_match_table = ACPI_PTR(cros_ec_i2c_tunnel_acpi_id),
 		.of_match_table = of_match_ptr(cros_ec_i2c_of_match),
 	},
 };

Question: Is this supported on older firmwares or is only expected to work on newer ACPI-based devices?

Thanks,
Enric