diff mbox series

[V3,2/5] i2c: gpio: Add support on ACPI-based system

Message ID e0ed6dfa3dbf60b58ef4eaeb40ea46d2577a2834.1669359515.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 Nov. 25, 2022, 8:54 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 | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

Comments

Andy Shevchenko Nov. 25, 2022, 10:23 a.m. UTC | #1
On Fri, Nov 25, 2022 at 04:54:12PM +0800, Binbin Zhou wrote:
> Add support for the ACPI-based device registration, so that the driver
> can be also enabled through ACPI table.

...

> +/* get i2c-gpio props from DT or ACPI table */

Get

...

> -	if (np) {
> -		of_i2c_gpio_get_props(np, pdata);
> +	if (np || has_acpi_companion(dev)) {
> +		i2c_gpio_get_props(dev, pdata);

	if (dev_fwnode() {
		i2c_gpio_get_props(dev, pdata);

...

> +	{"LOON0005", 0}, /*LoongArch*/

", 0" part is redundant. Also missing spaces in the comment.
Binbin Zhou Nov. 28, 2022, 1:28 a.m. UTC | #2
在 2022/11/25 18:23, Andy Shevchenko 写道:
> On Fri, Nov 25, 2022 at 04:54:12PM +0800, Binbin Zhou wrote:
>> Add support for the ACPI-based device registration, so that the driver
>> can be also enabled through ACPI table.
> ...
>
>> +/* get i2c-gpio props from DT or ACPI table */
> Get
>
> ...
>
>> -	if (np) {
>> -		of_i2c_gpio_get_props(np, pdata);
>> +	if (np || has_acpi_companion(dev)) {
>> +		i2c_gpio_get_props(dev, pdata);
> 	if (dev_fwnode() {
> 		i2c_gpio_get_props(dev, pdata);
>
> ...
>
>> +	{"LOON0005", 0}, /*LoongArch*/
> ", 0" part is redundant. Also missing spaces in the comment.
>
Hi Andy:

Thanks for your review. I will fix them in the V4 patchset.

Binbin
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index 0e4385a9bcf7..652d1f39854e 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -300,22 +300,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 props from DT or ACPI table */
+static void i2c_gpio_get_props(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 +374,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 (np || has_acpi_companion(dev)) {
+		i2c_gpio_get_props(dev, pdata);
 	} else {
 		/*
 		 * If all platform data settings are zero it is OK
@@ -489,10 +490,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", 0}, /*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,