aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Baryshkov <dmitry.baryshkov@linaro.org>2022-02-26 21:13:18 +0300
committerDmitry Baryshkov <dmitry.baryshkov@linaro.org>2022-02-27 06:16:38 +0300
commit10a4409b524404c58a1d2ca0e6247e5a563eb018 (patch)
tree2cc13dd1fe17010f552783f0e9a3c9f8a2bf5949
parentafb4fb3ee15f2f6eb5243606c6df29d56a924131 (diff)
mfd: qcom-qca639x: switch to platform config data
Change qcom-qca639x to use platform config data, in preparation to supporting other devices. Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
-rw-r--r--drivers/mfd/qcom-qca639x.c74
1 files changed, 46 insertions, 28 deletions
diff --git a/drivers/mfd/qcom-qca639x.c b/drivers/mfd/qcom-qca639x.c
index b31e4b65bec5..22792561dbad 100644
--- a/drivers/mfd/qcom-qca639x.c
+++ b/drivers/mfd/qcom-qca639x.c
@@ -1,4 +1,5 @@
#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
@@ -6,15 +7,21 @@
#include <linux/pinctrl/devinfo.h>
#include <linux/platform_device.h>
#include <linux/pm_domain.h>
+#include <linux/property.h>
#include <linux/regulator/consumer.h>
#include <linux/slab.h>
-#define MAX_NUM_REGULATORS 8
-
-static struct vreg {
+struct vreg {
const char *name;
unsigned int load_uA;
-} vregs [MAX_NUM_REGULATORS] = {
+};
+
+struct qca_cfg_data {
+ const struct vreg *vregs;
+ size_t num_vregs;
+};
+
+static const struct vreg qca6390_vregs[] = {
/* 2.0 V */
{ "vddpcie2", 15000 },
{ "vddrfa3", 400000 },
@@ -32,19 +39,24 @@ static struct vreg {
{ "vddio", 20000 },
};
-struct qca639x_data {
- struct regulator_bulk_data regulators[MAX_NUM_REGULATORS];
+static const struct qca_cfg_data qca6390_cfg_data = {
+ .vregs = qca6390_vregs,
+ .num_vregs = ARRAY_SIZE(qca6390_vregs),
+};
+
+struct qca_data {
size_t num_vregs;
struct device *dev;
struct pinctrl_state *active_state;
struct generic_pm_domain pd;
+ struct regulator_bulk_data regulators[];
};
-#define domain_to_data(domain) container_of(domain, struct qca639x_data, pd)
+#define domain_to_data(domain) container_of(domain, struct qca_data, pd)
-static int qca639x_power_on(struct generic_pm_domain *domain)
+static int qca_power_on(struct generic_pm_domain *domain)
{
- struct qca639x_data *data = domain_to_data(domain);
+ struct qca_data *data = domain_to_data(domain);
int ret;
dev_warn(&domain->dev, "DUMMY POWER ON\n");
@@ -70,9 +82,9 @@ static int qca639x_power_on(struct generic_pm_domain *domain)
return 0;
}
-static int qca639x_power_off(struct generic_pm_domain *domain)
+static int qca_power_off(struct generic_pm_domain *domain)
{
- struct qca639x_data *data = domain_to_data(domain);
+ struct qca_data *data = domain_to_data(domain);
dev_warn(&domain->dev, "DUMMY POWER OFF\n");
@@ -82,21 +94,26 @@ static int qca639x_power_off(struct generic_pm_domain *domain)
return 0;
}
-static int qca639x_probe(struct platform_device *pdev)
+static int qca_probe(struct platform_device *pdev)
{
- struct qca639x_data *data;
+ const struct qca_cfg_data *cfg;
+ struct qca_data *data;
struct device *dev = &pdev->dev;
int i, ret;
+ cfg = device_get_match_data(&pdev->dev);
+ if (!cfg)
+ return -EINVAL;
+
if (!dev->pins || IS_ERR_OR_NULL(dev->pins->default_state))
return -EINVAL;
- data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+ data = devm_kzalloc(dev, struct_size(data, regulators, cfg->num_vregs), GFP_KERNEL);
if (!data)
return -ENOMEM;
data->dev = dev;
- data->num_vregs = ARRAY_SIZE(vregs);
+ data->num_vregs = cfg->num_vregs;
data->active_state = pinctrl_lookup_state(dev->pins->p, "active");
if (IS_ERR(data->active_state)) {
@@ -106,20 +123,20 @@ static int qca639x_probe(struct platform_device *pdev)
}
for (i = 0; i < data->num_vregs; i++)
- data->regulators[i].supply = vregs[i].name;
+ data->regulators[i].supply = cfg->vregs[i].name;
ret = devm_regulator_bulk_get(dev, data->num_vregs, data->regulators);
if (ret < 0)
return ret;
for (i = 0; i < data->num_vregs; i++) {
- ret = regulator_set_load(data->regulators[i].consumer, vregs[i].load_uA);
+ ret = regulator_set_load(data->regulators[i].consumer, cfg->vregs[i].load_uA);
if (ret)
return ret;
}
data->pd.name = dev_name(dev);
- data->pd.power_on = qca639x_power_on;
- data->pd.power_off = qca639x_power_off;
+ data->pd.power_on = qca_power_on;
+ data->pd.power_off = qca_power_off;
ret = pm_genpd_init(&data->pd, NULL, true);
if (ret < 0)
@@ -136,27 +153,28 @@ static int qca639x_probe(struct platform_device *pdev)
return 0;
}
-static int qca639x_remove(struct platform_device *pdev)
+static int qca_remove(struct platform_device *pdev)
{
- struct qca639x_data *data = platform_get_drvdata(pdev);
+ struct qca_data *data = platform_get_drvdata(pdev);
pm_genpd_remove(&data->pd);
return 0;
}
-static const struct of_device_id qca639x_of_match[] = {
- { .compatible = "qcom,qca639x" },
+static const struct of_device_id qca_of_match[] = {
+ { .compatible = "qcom,qca6390", .data = &qca6390_cfg_data },
+ { },
};
-static struct platform_driver qca639x_driver = {
- .probe = qca639x_probe,
- .remove = qca639x_remove,
+static struct platform_driver qca_driver = {
+ .probe = qca_probe,
+ .remove = qca_remove,
.driver = {
.name = "qca639x",
- .of_match_table = qca639x_of_match,
+ .of_match_table = qca_of_match,
},
};
-module_platform_driver(qca639x_driver);
+module_platform_driver(qca_driver);
MODULE_LICENSE("GPL v2");