forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 072de836f53be56a70cecf70b43ae43b7ce17376
kernel/drivers/regulator/lp8755.c
....@@ -1,14 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * LP8755 High Performance Power Management Unit : System Interface Driver
34 * (based on rev. 0.26)
45 * Copyright 2012 Texas Instruments
56 *
67 * Author: Daniel(Geon Si) Jeong <daniel.jeong@ti.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
11
- *
128 */
139
1410 #include <linux/module.h>
....@@ -53,53 +49,15 @@
5349 struct regulator_dev *rdev[LP8755_BUCK_MAX];
5450 };
5551
56
-/**
57
- *lp8755_read : read a single register value from lp8755.
58
- *@pchip : device to read from
59
- *@reg : register to read from
60
- *@val : pointer to store read value
61
- */
62
-static int lp8755_read(struct lp8755_chip *pchip, unsigned int reg,
63
- unsigned int *val)
64
-{
65
- return regmap_read(pchip->regmap, reg, val);
66
-}
67
-
68
-/**
69
- *lp8755_write : write a single register value to lp8755.
70
- *@pchip : device to write to
71
- *@reg : register to write to
72
- *@val : value to be written
73
- */
74
-static int lp8755_write(struct lp8755_chip *pchip, unsigned int reg,
75
- unsigned int val)
76
-{
77
- return regmap_write(pchip->regmap, reg, val);
78
-}
79
-
80
-/**
81
- *lp8755_update_bits : set the values of bit fields in lp8755 register.
82
- *@pchip : device to read from
83
- *@reg : register to update
84
- *@mask : bitmask to be changed
85
- *@val : value for bitmask
86
- */
87
-static int lp8755_update_bits(struct lp8755_chip *pchip, unsigned int reg,
88
- unsigned int mask, unsigned int val)
89
-{
90
- return regmap_update_bits(pchip->regmap, reg, mask, val);
91
-}
92
-
9352 static int lp8755_buck_enable_time(struct regulator_dev *rdev)
9453 {
9554 int ret;
9655 unsigned int regval;
9756 enum lp8755_bucks id = rdev_get_id(rdev);
98
- struct lp8755_chip *pchip = rdev_get_drvdata(rdev);
9957
100
- ret = lp8755_read(pchip, 0x12 + id, &regval);
58
+ ret = regmap_read(rdev->regmap, 0x12 + id, &regval);
10159 if (ret < 0) {
102
- dev_err(pchip->dev, "i2c access error %s\n", __func__);
60
+ dev_err(&rdev->dev, "i2c access error %s\n", __func__);
10361 return ret;
10462 }
10563 return (regval & 0xff) * 100;
....@@ -119,17 +77,17 @@
11977 break;
12078 case REGULATOR_MODE_NORMAL:
12179 /* enable automatic pwm/pfm mode */
122
- ret = lp8755_update_bits(pchip, 0x08 + id, 0x20, 0x00);
80
+ ret = regmap_update_bits(rdev->regmap, 0x08 + id, 0x20, 0x00);
12381 if (ret < 0)
12482 goto err_i2c;
12583 break;
12684 case REGULATOR_MODE_IDLE:
12785 /* enable automatic pwm/pfm/lppfm mode */
128
- ret = lp8755_update_bits(pchip, 0x08 + id, 0x20, 0x20);
86
+ ret = regmap_update_bits(rdev->regmap, 0x08 + id, 0x20, 0x20);
12987 if (ret < 0)
13088 goto err_i2c;
13189
132
- ret = lp8755_update_bits(pchip, 0x10, 0x01, 0x01);
90
+ ret = regmap_update_bits(rdev->regmap, 0x10, 0x01, 0x01);
13391 if (ret < 0)
13492 goto err_i2c;
13593 break;
....@@ -139,12 +97,12 @@
13997 regbval = (0x01 << id);
14098 }
14199
142
- ret = lp8755_update_bits(pchip, 0x06, 0x01 << id, regbval);
100
+ ret = regmap_update_bits(rdev->regmap, 0x06, 0x01 << id, regbval);
143101 if (ret < 0)
144102 goto err_i2c;
145103 return ret;
146104 err_i2c:
147
- dev_err(pchip->dev, "i2c access error %s\n", __func__);
105
+ dev_err(&rdev->dev, "i2c access error %s\n", __func__);
148106 return ret;
149107 }
150108
....@@ -153,9 +111,8 @@
153111 int ret;
154112 unsigned int regval;
155113 enum lp8755_bucks id = rdev_get_id(rdev);
156
- struct lp8755_chip *pchip = rdev_get_drvdata(rdev);
157114
158
- ret = lp8755_read(pchip, 0x06, &regval);
115
+ ret = regmap_read(rdev->regmap, 0x06, &regval);
159116 if (ret < 0)
160117 goto err_i2c;
161118
....@@ -163,7 +120,7 @@
163120 if (regval & (0x01 << id))
164121 return REGULATOR_MODE_FAST;
165122
166
- ret = lp8755_read(pchip, 0x08 + id, &regval);
123
+ ret = regmap_read(rdev->regmap, 0x08 + id, &regval);
167124 if (ret < 0)
168125 goto err_i2c;
169126
....@@ -175,7 +132,7 @@
175132 return REGULATOR_MODE_NORMAL;
176133
177134 err_i2c:
178
- dev_err(pchip->dev, "i2c access error %s\n", __func__);
135
+ dev_err(&rdev->dev, "i2c access error %s\n", __func__);
179136 return 0;
180137 }
181138
....@@ -184,7 +141,6 @@
184141 int ret;
185142 unsigned int regval = 0x00;
186143 enum lp8755_bucks id = rdev_get_id(rdev);
187
- struct lp8755_chip *pchip = rdev_get_drvdata(rdev);
188144
189145 /* uV/us */
190146 switch (ramp) {
....@@ -213,17 +169,17 @@
213169 regval = 0x00;
214170 break;
215171 default:
216
- dev_err(pchip->dev,
172
+ dev_err(&rdev->dev,
217173 "Not supported ramp value %d %s\n", ramp, __func__);
218174 return -EINVAL;
219175 }
220176
221
- ret = lp8755_update_bits(pchip, 0x07 + id, 0x07, regval);
177
+ ret = regmap_update_bits(rdev->regmap, 0x07 + id, 0x07, regval);
222178 if (ret < 0)
223179 goto err_i2c;
224180 return ret;
225181 err_i2c:
226
- dev_err(pchip->dev, "i2c access error %s\n", __func__);
182
+ dev_err(&rdev->dev, "i2c access error %s\n", __func__);
227183 return ret;
228184 }
229185
....@@ -282,7 +238,7 @@
282238 struct lp8755_platform_data *pdata = pchip->pdata;
283239
284240 /* read back muti-phase configuration */
285
- ret = lp8755_read(pchip, 0x3D, &regval);
241
+ ret = regmap_read(pchip->regmap, 0x3D, &regval);
286242 if (ret < 0)
287243 goto out_i2c_error;
288244 pchip->mphase = regval & 0x0F;
....@@ -315,7 +271,7 @@
315271 .vsel_mask = LP8755_BUCK_VOUT_M,\
316272 }
317273
318
-static struct regulator_desc lp8755_regulators[] = {
274
+static const struct regulator_desc lp8755_regulators[] = {
319275 lp8755_buck_desc(0),
320276 lp8755_buck_desc(1),
321277 lp8755_buck_desc(2),
....@@ -360,11 +316,11 @@
360316 struct lp8755_chip *pchip = data;
361317
362318 /* read flag0 register */
363
- ret = lp8755_read(pchip, 0x0D, &flag0);
319
+ ret = regmap_read(pchip->regmap, 0x0D, &flag0);
364320 if (ret < 0)
365321 goto err_i2c;
366322 /* clear flag register to pull up int. pin */
367
- ret = lp8755_write(pchip, 0x0D, 0x00);
323
+ ret = regmap_write(pchip->regmap, 0x0D, 0x00);
368324 if (ret < 0)
369325 goto err_i2c;
370326
....@@ -372,35 +328,38 @@
372328 for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++)
373329 if ((flag0 & (0x4 << icnt))
374330 && (pchip->irqmask & (0x04 << icnt))
375
- && (pchip->rdev[icnt] != NULL))
331
+ && (pchip->rdev[icnt] != NULL)) {
376332 regulator_notifier_call_chain(pchip->rdev[icnt],
377333 LP8755_EVENT_PWR_FAULT,
378334 NULL);
335
+ }
379336
380337 /* read flag1 register */
381
- ret = lp8755_read(pchip, 0x0E, &flag1);
338
+ ret = regmap_read(pchip->regmap, 0x0E, &flag1);
382339 if (ret < 0)
383340 goto err_i2c;
384341 /* clear flag register to pull up int. pin */
385
- ret = lp8755_write(pchip, 0x0E, 0x00);
342
+ ret = regmap_write(pchip->regmap, 0x0E, 0x00);
386343 if (ret < 0)
387344 goto err_i2c;
388345
389
- /* send OCP event to all regualtor devices */
346
+ /* send OCP event to all regulator devices */
390347 if ((flag1 & 0x01) && (pchip->irqmask & 0x01))
391348 for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++)
392
- if (pchip->rdev[icnt] != NULL)
349
+ if (pchip->rdev[icnt] != NULL) {
393350 regulator_notifier_call_chain(pchip->rdev[icnt],
394351 LP8755_EVENT_OCP,
395352 NULL);
353
+ }
396354
397
- /* send OVP event to all regualtor devices */
355
+ /* send OVP event to all regulator devices */
398356 if ((flag1 & 0x02) && (pchip->irqmask & 0x02))
399357 for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++)
400
- if (pchip->rdev[icnt] != NULL)
358
+ if (pchip->rdev[icnt] != NULL) {
401359 regulator_notifier_call_chain(pchip->rdev[icnt],
402360 LP8755_EVENT_OVP,
403361 NULL);
362
+ }
404363 return IRQ_HANDLED;
405364
406365 err_i2c:
....@@ -418,7 +377,7 @@
418377 return 0;
419378 }
420379
421
- ret = lp8755_read(pchip, 0x0F, &regval);
380
+ ret = regmap_read(pchip->regmap, 0x0F, &regval);
422381 if (ret < 0) {
423382 dev_err(pchip->dev, "i2c access error %s\n", __func__);
424383 return ret;
....@@ -497,7 +456,7 @@
497456 err:
498457 /* output disable */
499458 for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++)
500
- lp8755_write(pchip, icnt, 0x00);
459
+ regmap_write(pchip->regmap, icnt, 0x00);
501460
502461 return ret;
503462 }
....@@ -508,7 +467,7 @@
508467 struct lp8755_chip *pchip = i2c_get_clientdata(client);
509468
510469 for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++)
511
- lp8755_write(pchip, icnt, 0x00);
470
+ regmap_write(pchip->regmap, icnt, 0x00);
512471
513472 return 0;
514473 }