Commit 7b6e9dc7 authored by Binbin Zhou's avatar Binbin Zhou Committed by Wolfram Sang

i2c: gpio: Add support on ACPI-based system

Add support for the ACPI-based device registration, so that the driver
can be also enabled through ACPI table.
Signed-off-by: default avatarBinbin Zhou <zhoubinbin@loongson.cn>
Reviewed-by: default avatarAndy Shevchenko <andy@kernel.org>
Tested-by: default avatarPeibao Liu <liupeibao@loongson.cn>
Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
parent a4a1a78e
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_data/i2c-gpio.h> #include <linux/platform_data/i2c-gpio.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/property.h>
#include <linux/slab.h> #include <linux/slab.h>
struct i2c_gpio_private_data { struct i2c_gpio_private_data {
...@@ -300,22 +300,23 @@ static inline void i2c_gpio_fault_injector_init(struct platform_device *pdev) {} ...@@ -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) {} static inline void i2c_gpio_fault_injector_exit(struct platform_device *pdev) {}
#endif /* CONFIG_I2C_GPIO_FAULT_INJECTOR*/ #endif /* CONFIG_I2C_GPIO_FAULT_INJECTOR*/
static void of_i2c_gpio_get_props(struct device_node *np, /* Get i2c-gpio properties from DT or ACPI table */
struct i2c_gpio_platform_data *pdata) static void i2c_gpio_get_properties(struct device *dev,
struct i2c_gpio_platform_data *pdata)
{ {
u32 reg; 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->timeout = msecs_to_jiffies(reg);
pdata->sda_is_open_drain = 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 = 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 = 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, static struct gpio_desc *i2c_gpio_get_desc(struct device *dev,
...@@ -361,7 +362,7 @@ static int i2c_gpio_probe(struct platform_device *pdev) ...@@ -361,7 +362,7 @@ static int i2c_gpio_probe(struct platform_device *pdev)
struct i2c_algo_bit_data *bit_data; struct i2c_algo_bit_data *bit_data;
struct i2c_adapter *adap; struct i2c_adapter *adap;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node; struct fwnode_handle *fwnode = dev_fwnode(dev);
enum gpiod_flags gflags; enum gpiod_flags gflags;
int ret; int ret;
...@@ -373,8 +374,8 @@ static int i2c_gpio_probe(struct platform_device *pdev) ...@@ -373,8 +374,8 @@ static int i2c_gpio_probe(struct platform_device *pdev)
bit_data = &priv->bit_data; bit_data = &priv->bit_data;
pdata = &priv->pdata; pdata = &priv->pdata;
if (np) { if (fwnode) {
of_i2c_gpio_get_props(np, pdata); i2c_gpio_get_properties(dev, pdata);
} else { } else {
/* /*
* If all platform data settings are zero it is OK * If all platform data settings are zero it is OK
...@@ -435,7 +436,7 @@ static int i2c_gpio_probe(struct platform_device *pdev) ...@@ -435,7 +436,7 @@ static int i2c_gpio_probe(struct platform_device *pdev)
bit_data->data = priv; bit_data->data = priv;
adap->owner = THIS_MODULE; adap->owner = THIS_MODULE;
if (np) if (fwnode)
strscpy(adap->name, dev_name(dev), sizeof(adap->name)); strscpy(adap->name, dev_name(dev), sizeof(adap->name));
else else
snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id); snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id);
...@@ -443,7 +444,7 @@ static int i2c_gpio_probe(struct platform_device *pdev) ...@@ -443,7 +444,7 @@ static int i2c_gpio_probe(struct platform_device *pdev)
adap->algo_data = bit_data; adap->algo_data = bit_data;
adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
adap->dev.parent = dev; adap->dev.parent = dev;
adap->dev.of_node = np; device_set_node(&adap->dev, fwnode);
adap->nr = pdev->id; adap->nr = pdev->id;
ret = i2c_bit_add_numbered_bus(adap); ret = i2c_bit_add_numbered_bus(adap);
...@@ -489,10 +490,17 @@ static const struct of_device_id i2c_gpio_dt_ids[] = { ...@@ -489,10 +490,17 @@ static const struct of_device_id i2c_gpio_dt_ids[] = {
MODULE_DEVICE_TABLE(of, 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 = { static struct platform_driver i2c_gpio_driver = {
.driver = { .driver = {
.name = "i2c-gpio", .name = "i2c-gpio",
.of_match_table = i2c_gpio_dt_ids, .of_match_table = i2c_gpio_dt_ids,
.acpi_match_table = i2c_gpio_acpi_match,
}, },
.probe = i2c_gpio_probe, .probe = i2c_gpio_probe,
.remove = i2c_gpio_remove, .remove = i2c_gpio_remove,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment