forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/regulator/wm8350-regulator.c
....@@ -1,16 +1,11 @@
1
-/*
2
- * wm8350.c -- Voltage and current regulation for the Wolfson WM8350 PMIC
3
- *
4
- * Copyright 2007, 2008 Wolfson Microelectronics PLC.
5
- *
6
- * Author: Liam Girdwood
7
- * linux@wolfsonmicro.com
8
- *
9
- * This program is free software; you can redistribute it and/or modify it
10
- * under the terms of the GNU General Public License as published by the
11
- * Free Software Foundation; either version 2 of the License, or (at your
12
- * option) any later version.
13
- */
1
+// SPDX-License-Identifier: GPL-2.0+
2
+//
3
+// wm8350.c -- Voltage and current regulation for the Wolfson WM8350 PMIC
4
+//
5
+// Copyright 2007, 2008 Wolfson Microelectronics PLC.
6
+//
7
+// Author: Liam Girdwood
8
+// linux@wolfsonmicro.com
149
1510 #include <linux/module.h>
1611 #include <linux/moduleparam.h>
....@@ -28,7 +23,7 @@
2823 #define WM8350_DCDC_MAX_VSEL 0x66
2924
3025 /* Microamps */
31
-static const int isink_cur[] = {
26
+static const unsigned int isink_cur[] = {
3227 4,
3328 5,
3429 6,
....@@ -94,73 +89,6 @@
9489 187681,
9590 223191
9691 };
97
-
98
-static int get_isink_val(int min_uA, int max_uA, u16 *setting)
99
-{
100
- int i;
101
-
102
- for (i = 0; i < ARRAY_SIZE(isink_cur); i++) {
103
- if (min_uA <= isink_cur[i] && max_uA >= isink_cur[i]) {
104
- *setting = i;
105
- return 0;
106
- }
107
- }
108
- return -EINVAL;
109
-}
110
-
111
-static int wm8350_isink_set_current(struct regulator_dev *rdev, int min_uA,
112
- int max_uA)
113
-{
114
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
115
- int isink = rdev_get_id(rdev);
116
- u16 val, setting;
117
- int ret;
118
-
119
- ret = get_isink_val(min_uA, max_uA, &setting);
120
- if (ret != 0)
121
- return ret;
122
-
123
- switch (isink) {
124
- case WM8350_ISINK_A:
125
- val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) &
126
- ~WM8350_CS1_ISEL_MASK;
127
- wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_A,
128
- val | setting);
129
- break;
130
- case WM8350_ISINK_B:
131
- val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) &
132
- ~WM8350_CS1_ISEL_MASK;
133
- wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_B,
134
- val | setting);
135
- break;
136
- default:
137
- return -EINVAL;
138
- }
139
-
140
- return 0;
141
-}
142
-
143
-static int wm8350_isink_get_current(struct regulator_dev *rdev)
144
-{
145
- struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
146
- int isink = rdev_get_id(rdev);
147
- u16 val;
148
-
149
- switch (isink) {
150
- case WM8350_ISINK_A:
151
- val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) &
152
- WM8350_CS1_ISEL_MASK;
153
- break;
154
- case WM8350_ISINK_B:
155
- val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) &
156
- WM8350_CS1_ISEL_MASK;
157
- break;
158
- default:
159
- return 0;
160
- }
161
-
162
- return isink_cur[val];
163
-}
16492
16593 /* turn on ISINK followed by DCDC */
16694 static int wm8350_isink_enable(struct regulator_dev *rdev)
....@@ -542,7 +470,7 @@
542470 return 0;
543471 }
544472
545
-static const struct regulator_linear_range wm8350_ldo_ranges[] = {
473
+static const struct linear_range wm8350_ldo_ranges[] = {
546474 REGULATOR_LINEAR_RANGE(900000, 0, 15, 50000),
547475 REGULATOR_LINEAR_RANGE(1800000, 16, 31, 100000),
548476 };
....@@ -982,8 +910,8 @@
982910 };
983911
984912 static const struct regulator_ops wm8350_isink_ops = {
985
- .set_current_limit = wm8350_isink_set_current,
986
- .get_current_limit = wm8350_isink_get_current,
913
+ .set_current_limit = regulator_set_current_limit_regmap,
914
+ .get_current_limit = regulator_get_current_limit_regmap,
987915 .enable = wm8350_isink_enable,
988916 .disable = wm8350_isink_disable,
989917 .is_enabled = wm8350_isink_is_enabled,
....@@ -1138,6 +1066,10 @@
11381066 .irq = WM8350_IRQ_CS1,
11391067 .type = REGULATOR_CURRENT,
11401068 .owner = THIS_MODULE,
1069
+ .curr_table = isink_cur,
1070
+ .n_current_limits = ARRAY_SIZE(isink_cur),
1071
+ .csel_reg = WM8350_CURRENT_SINK_DRIVER_A,
1072
+ .csel_mask = WM8350_CS1_ISEL_MASK,
11411073 },
11421074 {
11431075 .name = "ISINKB",
....@@ -1146,6 +1078,10 @@
11461078 .irq = WM8350_IRQ_CS2,
11471079 .type = REGULATOR_CURRENT,
11481080 .owner = THIS_MODULE,
1081
+ .curr_table = isink_cur,
1082
+ .n_current_limits = ARRAY_SIZE(isink_cur),
1083
+ .csel_reg = WM8350_CURRENT_SINK_DRIVER_B,
1084
+ .csel_mask = WM8350_CS2_ISEL_MASK,
11491085 },
11501086 };
11511087
....@@ -1153,7 +1089,6 @@
11531089 {
11541090 struct regulator_dev *rdev = (struct regulator_dev *)data;
11551091
1156
- mutex_lock(&rdev->mutex);
11571092 if (irq == WM8350_IRQ_CS1 || irq == WM8350_IRQ_CS2)
11581093 regulator_notifier_call_chain(rdev,
11591094 REGULATOR_EVENT_REGULATION_OUT,
....@@ -1162,7 +1097,6 @@
11621097 regulator_notifier_call_chain(rdev,
11631098 REGULATOR_EVENT_UNDER_VOLTAGE,
11641099 NULL);
1165
- mutex_unlock(&rdev->mutex);
11661100
11671101 return IRQ_HANDLED;
11681102 }
....@@ -1280,11 +1214,11 @@
12801214 /**
12811215 * wm8350_register_led - Register a WM8350 LED output
12821216 *
1283
- * @param wm8350 The WM8350 device to configure.
1284
- * @param lednum LED device index to create.
1285
- * @param dcdc The DCDC to use for the LED.
1286
- * @param isink The ISINK to use for the LED.
1287
- * @param pdata Configuration for the LED.
1217
+ * @wm8350: The WM8350 device to configure.
1218
+ * @lednum: LED device index to create.
1219
+ * @dcdc: The DCDC to use for the LED.
1220
+ * @isink: The ISINK to use for the LED.
1221
+ * @pdata: Configuration for the LED.
12881222 *
12891223 * The WM8350 supports the use of an ISINK together with a DCDC to
12901224 * provide a power-efficient LED driver. This function registers the