hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/regulator/da9210-regulator.c
....@@ -1,22 +1,7 @@
1
-/*
2
- * da9210-regulator.c - Regulator device driver for DA9210
3
- * Copyright (C) 2013 Dialog Semiconductor Ltd.
4
- *
5
- * This library is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU Library General Public
7
- * License as published by the Free Software Foundation; either
8
- * version 2 of the License, or (at your option) any later version.
9
- *
10
- * This library is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- * Library General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU Library General Public
16
- * License along with this library; if not, write to the
17
- * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18
- * Boston, MA 02110-1301, USA.
19
- */
1
+// SPDX-License-Identifier: GPL-2.0+
2
+//
3
+// da9210-regulator.c - Regulator device driver for DA9210
4
+// Copyright (C) 2013 Dialog Semiconductor Ltd.
205
216 #include <linux/err.h>
227 #include <linux/i2c.h>
....@@ -41,10 +26,6 @@
4126 .val_bits = 8,
4227 };
4328
44
-static int da9210_set_current_limit(struct regulator_dev *rdev, int min_uA,
45
- int max_uA);
46
-static int da9210_get_current_limit(struct regulator_dev *rdev);
47
-
4829 static const struct regulator_ops da9210_buck_ops = {
4930 .enable = regulator_enable_regmap,
5031 .disable = regulator_disable_regmap,
....@@ -52,8 +33,8 @@
5233 .set_voltage_sel = regulator_set_voltage_sel_regmap,
5334 .get_voltage_sel = regulator_get_voltage_sel_regmap,
5435 .list_voltage = regulator_list_voltage_linear,
55
- .set_current_limit = da9210_set_current_limit,
56
- .get_current_limit = da9210_get_current_limit,
36
+ .set_current_limit = regulator_set_current_limit_regmap,
37
+ .get_current_limit = regulator_get_current_limit_regmap,
5738 };
5839
5940 /* Default limits measured in millivolts and milliamps */
....@@ -62,7 +43,7 @@
6243 #define DA9210_STEP_MV 10
6344
6445 /* Current limits for buck (uA) indices corresponds with register values */
65
-static const int da9210_buck_limits[] = {
46
+static const unsigned int da9210_buck_limits[] = {
6647 1600000, 1800000, 2000000, 2200000, 2400000, 2600000, 2800000, 3000000,
6748 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000, 4600000
6849 };
....@@ -80,46 +61,11 @@
8061 .enable_reg = DA9210_REG_BUCK_CONT,
8162 .enable_mask = DA9210_BUCK_EN,
8263 .owner = THIS_MODULE,
64
+ .curr_table = da9210_buck_limits,
65
+ .n_current_limits = ARRAY_SIZE(da9210_buck_limits),
66
+ .csel_reg = DA9210_REG_BUCK_ILIM,
67
+ .csel_mask = DA9210_BUCK_ILIM_MASK,
8368 };
84
-
85
-static int da9210_set_current_limit(struct regulator_dev *rdev, int min_uA,
86
- int max_uA)
87
-{
88
- struct da9210 *chip = rdev_get_drvdata(rdev);
89
- unsigned int sel;
90
- int i;
91
-
92
- /* search for closest to maximum */
93
- for (i = ARRAY_SIZE(da9210_buck_limits)-1; i >= 0; i--) {
94
- if (min_uA <= da9210_buck_limits[i] &&
95
- max_uA >= da9210_buck_limits[i]) {
96
- sel = i;
97
- sel = sel << DA9210_BUCK_ILIM_SHIFT;
98
- return regmap_update_bits(chip->regmap,
99
- DA9210_REG_BUCK_ILIM,
100
- DA9210_BUCK_ILIM_MASK, sel);
101
- }
102
- }
103
-
104
- return -EINVAL;
105
-}
106
-
107
-static int da9210_get_current_limit(struct regulator_dev *rdev)
108
-{
109
- struct da9210 *chip = rdev_get_drvdata(rdev);
110
- unsigned int data;
111
- unsigned int sel;
112
- int ret;
113
-
114
- ret = regmap_read(chip->regmap, DA9210_REG_BUCK_ILIM, &data);
115
- if (ret < 0)
116
- return ret;
117
-
118
- /* select one of 16 values: 0000 (1600mA) to 1111 (4600mA) */
119
- sel = (data & DA9210_BUCK_ILIM_MASK) >> DA9210_BUCK_ILIM_SHIFT;
120
-
121
- return da9210_buck_limits[sel];
122
-}
12369
12470 static irqreturn_t da9210_irq_handler(int irq, void *data)
12571 {
....@@ -130,8 +76,6 @@
13076 error = regmap_read(chip->regmap, DA9210_REG_EVENT_B, &val);
13177 if (error < 0)
13278 goto error_i2c;
133
-
134
- mutex_lock(&chip->rdev->mutex);
13579
13680 if (val & DA9210_E_OVCURR) {
13781 regulator_notifier_call_chain(chip->rdev,
....@@ -157,8 +101,6 @@
157101 handled |= DA9210_E_VMAX;
158102 }
159103
160
- mutex_unlock(&chip->rdev->mutex);
161
-
162104 if (handled) {
163105 /* Clear handled events */
164106 error = regmap_write(chip->regmap, DA9210_REG_EVENT_B, handled);
....@@ -179,14 +121,13 @@
179121 * I2C driver interface functions
180122 */
181123
182
-static const struct of_device_id da9210_dt_ids[] = {
124
+static const struct of_device_id __maybe_unused da9210_dt_ids[] = {
183125 { .compatible = "dlg,da9210", },
184126 { }
185127 };
186128 MODULE_DEVICE_TABLE(of, da9210_dt_ids);
187129
188
-static int da9210_i2c_probe(struct i2c_client *i2c,
189
- const struct i2c_device_id *id)
130
+static int da9210_i2c_probe(struct i2c_client *i2c)
190131 {
191132 struct da9210 *chip;
192133 struct device *dev = &i2c->dev;
....@@ -282,7 +223,7 @@
282223 .name = "da9210",
283224 .of_match_table = of_match_ptr(da9210_dt_ids),
284225 },
285
- .probe = da9210_i2c_probe,
226
+ .probe_new = da9210_i2c_probe,
286227 .id_table = da9210_i2c_id,
287228 };
288229