forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 072de836f53be56a70cecf70b43ae43b7ce17376
kernel/drivers/regulator/vexpress-regulator.c
....@@ -1,15 +1,6 @@
1
-/*
2
- * This program is free software; you can redistribute it and/or modify
3
- * it under the terms of the GNU General Public License version 2 as
4
- * published by the Free Software Foundation.
5
- *
6
- * This program is distributed in the hope that it will be useful,
7
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
8
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
- * GNU General Public License for more details.
10
- *
11
- * Copyright (C) 2012 ARM Limited
12
- */
1
+// SPDX-License-Identifier: GPL-2.0
2
+//
3
+// Copyright (C) 2012 ARM Limited
134
145 #define DRVNAME "vexpress-regulator"
156 #define pr_fmt(fmt) DRVNAME ": " fmt
....@@ -23,17 +14,10 @@
2314 #include <linux/regulator/of_regulator.h>
2415 #include <linux/vexpress.h>
2516
26
-struct vexpress_regulator {
27
- struct regulator_desc desc;
28
- struct regulator_dev *regdev;
29
- struct regmap *regmap;
30
-};
31
-
3217 static int vexpress_regulator_get_voltage(struct regulator_dev *regdev)
3318 {
34
- struct vexpress_regulator *reg = rdev_get_drvdata(regdev);
35
- u32 uV;
36
- int err = regmap_read(reg->regmap, 0, &uV);
19
+ unsigned int uV;
20
+ int err = regmap_read(regdev->regmap, 0, &uV);
3721
3822 return err ? err : uV;
3923 }
....@@ -41,62 +25,57 @@
4125 static int vexpress_regulator_set_voltage(struct regulator_dev *regdev,
4226 int min_uV, int max_uV, unsigned *selector)
4327 {
44
- struct vexpress_regulator *reg = rdev_get_drvdata(regdev);
45
-
46
- return regmap_write(reg->regmap, 0, min_uV);
28
+ return regmap_write(regdev->regmap, 0, min_uV);
4729 }
4830
49
-static struct regulator_ops vexpress_regulator_ops_ro = {
31
+static const struct regulator_ops vexpress_regulator_ops_ro = {
5032 .get_voltage = vexpress_regulator_get_voltage,
5133 };
5234
53
-static struct regulator_ops vexpress_regulator_ops = {
35
+static const struct regulator_ops vexpress_regulator_ops = {
5436 .get_voltage = vexpress_regulator_get_voltage,
5537 .set_voltage = vexpress_regulator_set_voltage,
5638 };
5739
5840 static int vexpress_regulator_probe(struct platform_device *pdev)
5941 {
60
- struct vexpress_regulator *reg;
42
+ struct regulator_desc *desc;
6143 struct regulator_init_data *init_data;
6244 struct regulator_config config = { };
45
+ struct regulator_dev *rdev;
46
+ struct regmap *regmap;
6347
64
- reg = devm_kzalloc(&pdev->dev, sizeof(*reg), GFP_KERNEL);
65
- if (!reg)
48
+ desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL);
49
+ if (!desc)
6650 return -ENOMEM;
6751
68
- reg->regmap = devm_regmap_init_vexpress_config(&pdev->dev);
69
- if (IS_ERR(reg->regmap))
70
- return PTR_ERR(reg->regmap);
52
+ regmap = devm_regmap_init_vexpress_config(&pdev->dev);
53
+ if (IS_ERR(regmap))
54
+ return PTR_ERR(regmap);
7155
72
- reg->desc.name = dev_name(&pdev->dev);
73
- reg->desc.type = REGULATOR_VOLTAGE;
74
- reg->desc.owner = THIS_MODULE;
75
- reg->desc.continuous_voltage_range = true;
56
+ desc->name = dev_name(&pdev->dev);
57
+ desc->type = REGULATOR_VOLTAGE;
58
+ desc->owner = THIS_MODULE;
59
+ desc->continuous_voltage_range = true;
7660
7761 init_data = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node,
78
- &reg->desc);
62
+ desc);
7963 if (!init_data)
8064 return -EINVAL;
8165
8266 init_data->constraints.apply_uV = 0;
8367 if (init_data->constraints.min_uV && init_data->constraints.max_uV)
84
- reg->desc.ops = &vexpress_regulator_ops;
68
+ desc->ops = &vexpress_regulator_ops;
8569 else
86
- reg->desc.ops = &vexpress_regulator_ops_ro;
70
+ desc->ops = &vexpress_regulator_ops_ro;
8771
72
+ config.regmap = regmap;
8873 config.dev = &pdev->dev;
8974 config.init_data = init_data;
90
- config.driver_data = reg;
9175 config.of_node = pdev->dev.of_node;
9276
93
- reg->regdev = devm_regulator_register(&pdev->dev, &reg->desc, &config);
94
- if (IS_ERR(reg->regdev))
95
- return PTR_ERR(reg->regdev);
96
-
97
- platform_set_drvdata(pdev, reg);
98
-
99
- return 0;
77
+ rdev = devm_regulator_register(&pdev->dev, desc, &config);
78
+ return PTR_ERR_OR_ZERO(rdev);
10079 }
10180
10281 static const struct of_device_id vexpress_regulator_of_match[] = {