|
@@ -28,10 +28,13 @@
|
|
|
#include <linux/init.h>
|
|
|
#include <linux/kernel.h>
|
|
|
#include <linux/module.h>
|
|
|
+#include <linux/of.h>
|
|
|
+#include <linux/of_device.h>
|
|
|
#include <linux/platform_device.h>
|
|
|
#include <linux/regmap.h>
|
|
|
#include <linux/regulator/driver.h>
|
|
|
#include <linux/regulator/machine.h>
|
|
|
+#include <linux/regulator/of_regulator.h>
|
|
|
#include <linux/regulator/tps51632-regulator.h>
|
|
|
#include <linux/slab.h>
|
|
|
|
|
@@ -252,6 +255,49 @@ static const struct regmap_config tps51632_regmap_config = {
|
|
|
.cache_type = REGCACHE_RBTREE,
|
|
|
};
|
|
|
|
|
|
+#if defined(CONFIG_OF)
|
|
|
+static const struct of_device_id tps51632_of_match[] = {
|
|
|
+ { .compatible = "ti,tps51632",},
|
|
|
+ {},
|
|
|
+};
|
|
|
+MODULE_DEVICE_TABLE(of, tps51632_of_match);
|
|
|
+
|
|
|
+static struct tps51632_regulator_platform_data *
|
|
|
+ of_get_tps51632_platform_data(struct device *dev)
|
|
|
+{
|
|
|
+ struct tps51632_regulator_platform_data *pdata;
|
|
|
+ struct device_node *np = dev->of_node;
|
|
|
+
|
|
|
+ pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
|
|
|
+ if (!pdata) {
|
|
|
+ dev_err(dev, "Memory alloc failed for platform data\n");
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node);
|
|
|
+ if (!pdata->reg_init_data) {
|
|
|
+ dev_err(dev, "Not able to get OF regulator init data\n");
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ pdata->enable_pwm_dvfs =
|
|
|
+ of_property_read_bool(np, "ti,enable-pwm-dvfs");
|
|
|
+ pdata->dvfs_step_20mV = of_property_read_bool(np, "ti,dvfs-step-20mV");
|
|
|
+
|
|
|
+ pdata->base_voltage_uV = pdata->reg_init_data->constraints.min_uV ? :
|
|
|
+ TPS51632_MIN_VOLATGE;
|
|
|
+ pdata->max_voltage_uV = pdata->reg_init_data->constraints.max_uV ? :
|
|
|
+ TPS51632_MAX_VOLATGE;
|
|
|
+ return pdata;
|
|
|
+}
|
|
|
+#else
|
|
|
+static struct tps51632_regulator_platform_data *
|
|
|
+ of_get_tps51632_platform_data(struct device *dev)
|
|
|
+{
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
static int tps51632_probe(struct i2c_client *client,
|
|
|
const struct i2c_device_id *id)
|
|
|
{
|
|
@@ -261,7 +307,19 @@ static int tps51632_probe(struct i2c_client *client,
|
|
|
int ret;
|
|
|
struct regulator_config config = { };
|
|
|
|
|
|
+ if (client->dev.of_node) {
|
|
|
+ const struct of_device_id *match;
|
|
|
+ match = of_match_device(of_match_ptr(tps51632_of_match),
|
|
|
+ &client->dev);
|
|
|
+ if (!match) {
|
|
|
+ dev_err(&client->dev, "Error: No device match found\n");
|
|
|
+ return -ENODEV;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
pdata = client->dev.platform_data;
|
|
|
+ if (!pdata && client->dev.of_node)
|
|
|
+ pdata = of_get_tps51632_platform_data(&client->dev);
|
|
|
if (!pdata) {
|
|
|
dev_err(&client->dev, "No Platform data\n");
|
|
|
return -EINVAL;
|
|
@@ -350,6 +408,7 @@ static struct i2c_driver tps51632_i2c_driver = {
|
|
|
.driver = {
|
|
|
.name = "tps51632",
|
|
|
.owner = THIS_MODULE,
|
|
|
+ .of_match_table = of_match_ptr(tps51632_of_match),
|
|
|
},
|
|
|
.probe = tps51632_probe,
|
|
|
.remove = tps51632_remove,
|