Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / regulator / vexpress-regulator.c
blob5d39663efcaad1d86fd4d83f9b0f3c2d12381d47
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // Copyright (C) 2012 ARM Limited
5 #define DRVNAME "vexpress-regulator"
6 #define pr_fmt(fmt) DRVNAME ": " fmt
8 #include <linux/device.h>
9 #include <linux/err.h>
10 #include <linux/module.h>
11 #include <linux/of_device.h>
12 #include <linux/regulator/driver.h>
13 #include <linux/regulator/machine.h>
14 #include <linux/regulator/of_regulator.h>
15 #include <linux/vexpress.h>
17 static int vexpress_regulator_get_voltage(struct regulator_dev *regdev)
19 unsigned int uV;
20 int err = regmap_read(regdev->regmap, 0, &uV);
22 return err ? err : uV;
25 static int vexpress_regulator_set_voltage(struct regulator_dev *regdev,
26 int min_uV, int max_uV, unsigned *selector)
28 return regmap_write(regdev->regmap, 0, min_uV);
31 static const struct regulator_ops vexpress_regulator_ops_ro = {
32 .get_voltage = vexpress_regulator_get_voltage,
35 static const struct regulator_ops vexpress_regulator_ops = {
36 .get_voltage = vexpress_regulator_get_voltage,
37 .set_voltage = vexpress_regulator_set_voltage,
40 static int vexpress_regulator_probe(struct platform_device *pdev)
42 struct regulator_desc *desc;
43 struct regulator_init_data *init_data;
44 struct regulator_config config = { };
45 struct regulator_dev *rdev;
46 struct regmap *regmap;
48 desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL);
49 if (!desc)
50 return -ENOMEM;
52 regmap = devm_regmap_init_vexpress_config(&pdev->dev);
53 if (IS_ERR(regmap))
54 return PTR_ERR(regmap);
56 desc->name = dev_name(&pdev->dev);
57 desc->type = REGULATOR_VOLTAGE;
58 desc->owner = THIS_MODULE;
59 desc->continuous_voltage_range = true;
61 init_data = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node,
62 desc);
63 if (!init_data)
64 return -EINVAL;
66 init_data->constraints.apply_uV = 0;
67 if (init_data->constraints.min_uV && init_data->constraints.max_uV)
68 desc->ops = &vexpress_regulator_ops;
69 else
70 desc->ops = &vexpress_regulator_ops_ro;
72 config.regmap = regmap;
73 config.dev = &pdev->dev;
74 config.init_data = init_data;
75 config.of_node = pdev->dev.of_node;
77 rdev = devm_regulator_register(&pdev->dev, desc, &config);
78 return PTR_ERR_OR_ZERO(rdev);
81 static const struct of_device_id vexpress_regulator_of_match[] = {
82 { .compatible = "arm,vexpress-volt", },
83 { }
85 MODULE_DEVICE_TABLE(of, vexpress_regulator_of_match);
87 static struct platform_driver vexpress_regulator_driver = {
88 .probe = vexpress_regulator_probe,
89 .driver = {
90 .name = DRVNAME,
91 .of_match_table = vexpress_regulator_of_match,
95 module_platform_driver(vexpress_regulator_driver);
97 MODULE_AUTHOR("Pawel Moll <pawel.moll@arm.com>");
98 MODULE_DESCRIPTION("Versatile Express regulator");
99 MODULE_LICENSE("GPL");
100 MODULE_ALIAS("platform:vexpress-regulator");