hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/regulator/pbias-regulator.c
....@@ -1,7 +1,7 @@
11 /*
22 * pbias-regulator.c
33 *
4
- * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
4
+ * Copyright (C) 2014 Texas Instruments Incorporated - https://www.ti.com/
55 * Author: Balaji T K <balajitk@ti.com>
66 *
77 * This program is free software; you can redistribute it and/or
....@@ -36,15 +36,6 @@
3636 char *name;
3737 const unsigned int *pbias_volt_table;
3838 int n_voltages;
39
-};
40
-
41
-struct pbias_regulator_data {
42
- struct regulator_desc desc;
43
- void __iomem *pbias_addr;
44
- struct regulator_dev *dev;
45
- struct regmap *syscon;
46
- const struct pbias_reg_info *info;
47
- int voltage;
4839 };
4940
5041 struct pbias_of_data {
....@@ -157,14 +148,13 @@
157148 static int pbias_regulator_probe(struct platform_device *pdev)
158149 {
159150 struct device_node *np = pdev->dev.of_node;
160
- struct pbias_regulator_data *drvdata;
161151 struct resource *res;
162152 struct regulator_config cfg = { };
153
+ struct regulator_desc *desc;
154
+ struct regulator_dev *rdev;
163155 struct regmap *syscon;
164156 const struct pbias_reg_info *info;
165
- int ret = 0;
166
- int count, idx, data_idx = 0;
167
- const struct of_device_id *match;
157
+ int ret, count, idx;
168158 const struct pbias_of_data *data;
169159 unsigned int offset;
170160
....@@ -173,19 +163,16 @@
173163 if (count < 0)
174164 return count;
175165
176
- drvdata = devm_kcalloc(&pdev->dev,
177
- count, sizeof(struct pbias_regulator_data),
178
- GFP_KERNEL);
179
- if (!drvdata)
166
+ desc = devm_kcalloc(&pdev->dev, count, sizeof(*desc), GFP_KERNEL);
167
+ if (!desc)
180168 return -ENOMEM;
181169
182170 syscon = syscon_regmap_lookup_by_phandle(np, "syscon");
183171 if (IS_ERR(syscon))
184172 return PTR_ERR(syscon);
185173
186
- match = of_match_device(of_match_ptr(pbias_of_match), &pdev->dev);
187
- if (match && match->data) {
188
- data = match->data;
174
+ data = of_device_get_match_data(&pdev->dev);
175
+ if (data) {
189176 offset = data->offset;
190177 } else {
191178 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
....@@ -200,7 +187,7 @@
200187 cfg.regmap = syscon;
201188 cfg.dev = &pdev->dev;
202189
203
- for (idx = 0; idx < PBIAS_NUM_REGS && data_idx < count; idx++) {
190
+ for (idx = 0; idx < PBIAS_NUM_REGS && count; idx++) {
204191 if (!pbias_matches[idx].init_data ||
205192 !pbias_matches[idx].of_node)
206193 continue;
....@@ -209,41 +196,35 @@
209196 if (!info)
210197 return -ENODEV;
211198
212
- drvdata[data_idx].syscon = syscon;
213
- drvdata[data_idx].info = info;
214
- drvdata[data_idx].desc.name = info->name;
215
- drvdata[data_idx].desc.owner = THIS_MODULE;
216
- drvdata[data_idx].desc.type = REGULATOR_VOLTAGE;
217
- drvdata[data_idx].desc.ops = &pbias_regulator_voltage_ops;
218
- drvdata[data_idx].desc.volt_table = info->pbias_volt_table;
219
- drvdata[data_idx].desc.n_voltages = info->n_voltages;
220
- drvdata[data_idx].desc.enable_time = info->enable_time;
221
- drvdata[data_idx].desc.vsel_reg = offset;
222
- drvdata[data_idx].desc.vsel_mask = info->vmode;
223
- drvdata[data_idx].desc.enable_reg = offset;
224
- drvdata[data_idx].desc.enable_mask = info->enable_mask;
225
- drvdata[data_idx].desc.enable_val = info->enable;
226
- drvdata[data_idx].desc.disable_val = info->disable_val;
199
+ desc->name = info->name;
200
+ desc->owner = THIS_MODULE;
201
+ desc->type = REGULATOR_VOLTAGE;
202
+ desc->ops = &pbias_regulator_voltage_ops;
203
+ desc->volt_table = info->pbias_volt_table;
204
+ desc->n_voltages = info->n_voltages;
205
+ desc->enable_time = info->enable_time;
206
+ desc->vsel_reg = offset;
207
+ desc->vsel_mask = info->vmode;
208
+ desc->enable_reg = offset;
209
+ desc->enable_mask = info->enable_mask;
210
+ desc->enable_val = info->enable;
211
+ desc->disable_val = info->disable_val;
227212
228213 cfg.init_data = pbias_matches[idx].init_data;
229
- cfg.driver_data = &drvdata[data_idx];
230214 cfg.of_node = pbias_matches[idx].of_node;
231215
232
- drvdata[data_idx].dev = devm_regulator_register(&pdev->dev,
233
- &drvdata[data_idx].desc, &cfg);
234
- if (IS_ERR(drvdata[data_idx].dev)) {
235
- ret = PTR_ERR(drvdata[data_idx].dev);
216
+ rdev = devm_regulator_register(&pdev->dev, desc, &cfg);
217
+ if (IS_ERR(rdev)) {
218
+ ret = PTR_ERR(rdev);
236219 dev_err(&pdev->dev,
237220 "Failed to register regulator: %d\n", ret);
238
- goto err_regulator;
221
+ return ret;
239222 }
240
- data_idx++;
223
+ desc++;
224
+ count--;
241225 }
242226
243
- platform_set_drvdata(pdev, drvdata);
244
-
245
-err_regulator:
246
- return ret;
227
+ return 0;
247228 }
248229
249230 static struct platform_driver pbias_regulator_driver = {