hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/regulator/hi655x-regulator.c
....@@ -1,16 +1,12 @@
1
-/*
2
- * Device driver for regulators in Hi655x IC
3
- *
4
- * Copyright (c) 2016 Hisilicon.
5
- *
6
- * Authors:
7
- * Chen Feng <puck.chen@hisilicon.com>
8
- * Fei Wang <w.f@huawei.com>
9
- *
10
- * This program is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License version 2 as
12
- * published by the Free Software Foundation.
13
- */
1
+// SPDX-License-Identifier: GPL-2.0
2
+//
3
+// Device driver for regulators in Hi655x IC
4
+//
5
+// Copyright (c) 2016 Hisilicon.
6
+//
7
+// Authors:
8
+// Chen Feng <puck.chen@hisilicon.com>
9
+// Fei Wang <w.f@huawei.com>
1410
1511 #include <linux/bitops.h>
1612 #include <linux/device.h>
....@@ -28,8 +24,6 @@
2824 struct hi655x_regulator {
2925 unsigned int disable_reg;
3026 unsigned int status_reg;
31
- unsigned int ctrl_regs;
32
- unsigned int ctrl_mask;
3327 struct regulator_desc rdesc;
3428 };
3529
....@@ -78,22 +72,18 @@
7872 static int hi655x_is_enabled(struct regulator_dev *rdev)
7973 {
8074 unsigned int value = 0;
81
-
82
- struct hi655x_regulator *regulator = rdev_get_drvdata(rdev);
75
+ const struct hi655x_regulator *regulator = rdev_get_drvdata(rdev);
8376
8477 regmap_read(rdev->regmap, regulator->status_reg, &value);
85
- return (value & BIT(regulator->ctrl_mask));
78
+ return (value & rdev->desc->enable_mask);
8679 }
8780
8881 static int hi655x_disable(struct regulator_dev *rdev)
8982 {
90
- int ret = 0;
83
+ const struct hi655x_regulator *regulator = rdev_get_drvdata(rdev);
9184
92
- struct hi655x_regulator *regulator = rdev_get_drvdata(rdev);
93
-
94
- ret = regmap_write(rdev->regmap, regulator->disable_reg,
95
- BIT(regulator->ctrl_mask));
96
- return ret;
85
+ return regmap_write(rdev->regmap, regulator->disable_reg,
86
+ rdev->desc->enable_mask);
9787 }
9888
9989 static const struct regulator_ops hi655x_regulator_ops = {
....@@ -133,7 +123,6 @@
133123 }, \
134124 .disable_reg = HI655X_BUS_ADDR(dreg), \
135125 .status_reg = HI655X_BUS_ADDR(sreg), \
136
- .ctrl_mask = cmask, \
137126 }
138127
139128 #define HI655X_LDO_LINEAR(_ID, vreg, vmask, ereg, dreg, \
....@@ -156,10 +145,9 @@
156145 }, \
157146 .disable_reg = HI655X_BUS_ADDR(dreg), \
158147 .status_reg = HI655X_BUS_ADDR(sreg), \
159
- .ctrl_mask = cmask, \
160148 }
161149
162
-static struct hi655x_regulator regulators[] = {
150
+static const struct hi655x_regulator regulators[] = {
163151 HI655X_LDO_LINEAR(LDO2, 0x72, 0x07, 0x29, 0x2a, 0x2b, 0x01,
164152 2500000, 8, 100000),
165153 HI655X_LDO(LDO7, 0x78, 0x07, 0x29, 0x2a, 0x2b, 0x06, ldo7_voltages),
....@@ -181,7 +169,6 @@
181169 static int hi655x_regulator_probe(struct platform_device *pdev)
182170 {
183171 unsigned int i;
184
- struct hi655x_regulator *regulator;
185172 struct hi655x_pmic *pmic;
186173 struct regulator_config config = { };
187174 struct regulator_dev *rdev;
....@@ -192,22 +179,17 @@
192179 return -ENODEV;
193180 }
194181
195
- regulator = devm_kzalloc(&pdev->dev, sizeof(*regulator), GFP_KERNEL);
196
- if (!regulator)
197
- return -ENOMEM;
198
-
199
- platform_set_drvdata(pdev, regulator);
200
-
201182 config.dev = pdev->dev.parent;
202183 config.regmap = pmic->regmap;
203
- config.driver_data = regulator;
204184 for (i = 0; i < ARRAY_SIZE(regulators); i++) {
185
+ config.driver_data = (void *) &regulators[i];
186
+
205187 rdev = devm_regulator_register(&pdev->dev,
206188 &regulators[i].rdesc,
207189 &config);
208190 if (IS_ERR(rdev)) {
209191 dev_err(&pdev->dev, "failed to register regulator %s\n",
210
- regulator->rdesc.name);
192
+ regulators[i].rdesc.name);
211193 return PTR_ERR(rdev);
212194 }
213195 }