diff mbox series

[V5,1/4] i2c: gpio: Add support on ACPI-based system

Message ID 0a8a1dec27beea61935adb2a9c2d74e41c86e9b1.1670293176.git.zhoubinbin@loongson.cn
State Superseded
Headers show
Series i2c: ls2x: Add support for the Loongson-2K/LS7A I2C controller | expand

Commit Message

Binbin Zhou Dec. 6, 2022, 3:16 a.m. UTC
Add support for the ACPI-based device registration, so that the driver
can be also enabled through ACPI table.

Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
---
 drivers/i2c/busses/i2c-gpio.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

Comments

Andy Shevchenko Dec. 6, 2022, 3:13 p.m. UTC | #1
On Tue, Dec 06, 2022 at 11:16:54AM +0800, Binbin Zhou wrote:
> Add support for the ACPI-based device registration, so that the driver
> can be also enabled through ACPI table.

...

> -#include <linux/of.h>

Cool, but don't you need to add property.h?

Otherwise looks good to me.
Binbin Zhou Dec. 7, 2022, 7:10 a.m. UTC | #2
在 2022/12/6 23:13, Andy Shevchenko 写道:
> On Tue, Dec 06, 2022 at 11:16:54AM +0800, Binbin Zhou wrote:
>> Add support for the ACPI-based device registration, so that the driver
>> can be also enabled through ACPI table.
> ...
>
>> -#include <linux/of.h>
> Cool, but don't you need to add property.h?

Get it, I should have been more careful, maybe I'm still not very 
sensitive to header files.

Now I'm still basically judging based on whether I compile with errors 
or not.

Thanks.

Binbin

>
> Otherwise looks good to me.
>
Andy Shevchenko Dec. 12, 2022, 9:40 a.m. UTC | #3
On Wed, Dec 07, 2022 at 03:10:43PM +0800, Binbin Zhou wrote:
> 在 2022/12/6 23:13, Andy Shevchenko 写道:
> > On Tue, Dec 06, 2022 at 11:16:54AM +0800, Binbin Zhou wrote:

...

> > > -#include <linux/of.h>
> > Cool, but don't you need to add property.h?
> 
> Get it, I should have been more careful, maybe I'm still not very sensitive
> to header files.
> 
> Now I'm still basically judging based on whether I compile with errors or
> not.

You can generate the include tree by running `make includecheck`

The rule of thumb is to include what you are the direct user of.
With a few exceptions where we have the guarantees that one header
is always included by another (e.g. bits.h included by bitops.h).

> > Otherwise looks good to me.
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index 0e4385a9bcf7..7bec473cd6b1 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -13,7 +13,6 @@ 
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
-#include <linux/of.h>
 #include <linux/platform_data/i2c-gpio.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
@@ -300,22 +299,23 @@  static inline void i2c_gpio_fault_injector_init(struct platform_device *pdev) {}
 static inline void i2c_gpio_fault_injector_exit(struct platform_device *pdev) {}
 #endif /* CONFIG_I2C_GPIO_FAULT_INJECTOR*/
 
-static void of_i2c_gpio_get_props(struct device_node *np,
-				  struct i2c_gpio_platform_data *pdata)
+/* Get i2c-gpio properties from DT or ACPI table */
+static void i2c_gpio_get_properties(struct device *dev,
+				     struct i2c_gpio_platform_data *pdata)
 {
 	u32 reg;
 
-	of_property_read_u32(np, "i2c-gpio,delay-us", &pdata->udelay);
+	device_property_read_u32(dev, "i2c-gpio,delay-us", &pdata->udelay);
 
-	if (!of_property_read_u32(np, "i2c-gpio,timeout-ms", &reg))
+	if (!device_property_read_u32(dev, "i2c-gpio,timeout-ms", &reg))
 		pdata->timeout = msecs_to_jiffies(reg);
 
 	pdata->sda_is_open_drain =
-		of_property_read_bool(np, "i2c-gpio,sda-open-drain");
+		device_property_read_bool(dev, "i2c-gpio,sda-open-drain");
 	pdata->scl_is_open_drain =
-		of_property_read_bool(np, "i2c-gpio,scl-open-drain");
+		device_property_read_bool(dev, "i2c-gpio,scl-open-drain");
 	pdata->scl_is_output_only =
-		of_property_read_bool(np, "i2c-gpio,scl-output-only");
+		device_property_read_bool(dev, "i2c-gpio,scl-output-only");
 }
 
 static struct gpio_desc *i2c_gpio_get_desc(struct device *dev,
@@ -373,8 +373,8 @@  static int i2c_gpio_probe(struct platform_device *pdev)
 	bit_data = &priv->bit_data;
 	pdata = &priv->pdata;
 
-	if (np) {
-		of_i2c_gpio_get_props(np, pdata);
+	if (dev_fwnode(dev)) {
+		i2c_gpio_get_properties(dev, pdata);
 	} else {
 		/*
 		 * If all platform data settings are zero it is OK
@@ -489,10 +489,17 @@  static const struct of_device_id i2c_gpio_dt_ids[] = {
 
 MODULE_DEVICE_TABLE(of, i2c_gpio_dt_ids);
 
+static const struct acpi_device_id i2c_gpio_acpi_match[] = {
+	{ "LOON0005" }, /* LoongArch */
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, i2c_gpio_acpi_match);
+
 static struct platform_driver i2c_gpio_driver = {
 	.driver		= {
 		.name	= "i2c-gpio",
 		.of_match_table	= i2c_gpio_dt_ids,
+		.acpi_match_table = i2c_gpio_acpi_match,
 	},
 	.probe		= i2c_gpio_probe,
 	.remove		= i2c_gpio_remove,