| .. | .. |
|---|
| 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. |
|---|
| 20 | 5 | |
|---|
| 21 | 6 | #include <linux/err.h> |
|---|
| 22 | 7 | #include <linux/i2c.h> |
|---|
| .. | .. |
|---|
| 41 | 26 | .val_bits = 8, |
|---|
| 42 | 27 | }; |
|---|
| 43 | 28 | |
|---|
| 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 | | - |
|---|
| 48 | 29 | static const struct regulator_ops da9210_buck_ops = { |
|---|
| 49 | 30 | .enable = regulator_enable_regmap, |
|---|
| 50 | 31 | .disable = regulator_disable_regmap, |
|---|
| .. | .. |
|---|
| 52 | 33 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
|---|
| 53 | 34 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
|---|
| 54 | 35 | .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, |
|---|
| 57 | 38 | }; |
|---|
| 58 | 39 | |
|---|
| 59 | 40 | /* Default limits measured in millivolts and milliamps */ |
|---|
| .. | .. |
|---|
| 62 | 43 | #define DA9210_STEP_MV 10 |
|---|
| 63 | 44 | |
|---|
| 64 | 45 | /* 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[] = { |
|---|
| 66 | 47 | 1600000, 1800000, 2000000, 2200000, 2400000, 2600000, 2800000, 3000000, |
|---|
| 67 | 48 | 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000, 4600000 |
|---|
| 68 | 49 | }; |
|---|
| .. | .. |
|---|
| 80 | 61 | .enable_reg = DA9210_REG_BUCK_CONT, |
|---|
| 81 | 62 | .enable_mask = DA9210_BUCK_EN, |
|---|
| 82 | 63 | .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, |
|---|
| 83 | 68 | }; |
|---|
| 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 | | -} |
|---|
| 123 | 69 | |
|---|
| 124 | 70 | static irqreturn_t da9210_irq_handler(int irq, void *data) |
|---|
| 125 | 71 | { |
|---|
| .. | .. |
|---|
| 130 | 76 | error = regmap_read(chip->regmap, DA9210_REG_EVENT_B, &val); |
|---|
| 131 | 77 | if (error < 0) |
|---|
| 132 | 78 | goto error_i2c; |
|---|
| 133 | | - |
|---|
| 134 | | - mutex_lock(&chip->rdev->mutex); |
|---|
| 135 | 79 | |
|---|
| 136 | 80 | if (val & DA9210_E_OVCURR) { |
|---|
| 137 | 81 | regulator_notifier_call_chain(chip->rdev, |
|---|
| .. | .. |
|---|
| 157 | 101 | handled |= DA9210_E_VMAX; |
|---|
| 158 | 102 | } |
|---|
| 159 | 103 | |
|---|
| 160 | | - mutex_unlock(&chip->rdev->mutex); |
|---|
| 161 | | - |
|---|
| 162 | 104 | if (handled) { |
|---|
| 163 | 105 | /* Clear handled events */ |
|---|
| 164 | 106 | error = regmap_write(chip->regmap, DA9210_REG_EVENT_B, handled); |
|---|
| .. | .. |
|---|
| 179 | 121 | * I2C driver interface functions |
|---|
| 180 | 122 | */ |
|---|
| 181 | 123 | |
|---|
| 182 | | -static const struct of_device_id da9210_dt_ids[] = { |
|---|
| 124 | +static const struct of_device_id __maybe_unused da9210_dt_ids[] = { |
|---|
| 183 | 125 | { .compatible = "dlg,da9210", }, |
|---|
| 184 | 126 | { } |
|---|
| 185 | 127 | }; |
|---|
| 186 | 128 | MODULE_DEVICE_TABLE(of, da9210_dt_ids); |
|---|
| 187 | 129 | |
|---|
| 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) |
|---|
| 190 | 131 | { |
|---|
| 191 | 132 | struct da9210 *chip; |
|---|
| 192 | 133 | struct device *dev = &i2c->dev; |
|---|
| .. | .. |
|---|
| 282 | 223 | .name = "da9210", |
|---|
| 283 | 224 | .of_match_table = of_match_ptr(da9210_dt_ids), |
|---|
| 284 | 225 | }, |
|---|
| 285 | | - .probe = da9210_i2c_probe, |
|---|
| 226 | + .probe_new = da9210_i2c_probe, |
|---|
| 286 | 227 | .id_table = da9210_i2c_id, |
|---|
| 287 | 228 | }; |
|---|
| 288 | 229 | |
|---|