| .. | .. |
|---|
| 1 | 1 | /* |
|---|
| 2 | 2 | * Regulator driver for LP873X PMIC |
|---|
| 3 | 3 | * |
|---|
| 4 | | - * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/ |
|---|
| 4 | + * Copyright (C) 2016 Texas Instruments Incorporated - https://www.ti.com/ |
|---|
| 5 | 5 | * |
|---|
| 6 | 6 | * This program is free software; you can redistribute it and/or |
|---|
| 7 | 7 | * modify it under the terms of the GNU General Public License version 2 as |
|---|
| .. | .. |
|---|
| 39 | 39 | .ramp_delay = _delay, \ |
|---|
| 40 | 40 | .linear_ranges = _lr, \ |
|---|
| 41 | 41 | .n_linear_ranges = ARRAY_SIZE(_lr), \ |
|---|
| 42 | + .curr_table = lp873x_buck_uA, \ |
|---|
| 43 | + .n_current_limits = ARRAY_SIZE(lp873x_buck_uA), \ |
|---|
| 44 | + .csel_reg = (_cr), \ |
|---|
| 45 | + .csel_mask = LP873X_BUCK0_CTRL_2_BUCK0_ILIM,\ |
|---|
| 42 | 46 | }, \ |
|---|
| 43 | 47 | .ctrl2_reg = _cr, \ |
|---|
| 44 | 48 | } |
|---|
| .. | .. |
|---|
| 50 | 54 | |
|---|
| 51 | 55 | static const struct lp873x_regulator regulators[]; |
|---|
| 52 | 56 | |
|---|
| 53 | | -static const struct regulator_linear_range buck0_buck1_ranges[] = { |
|---|
| 57 | +static const struct linear_range buck0_buck1_ranges[] = { |
|---|
| 54 | 58 | REGULATOR_LINEAR_RANGE(0, 0x0, 0x13, 0), |
|---|
| 55 | 59 | REGULATOR_LINEAR_RANGE(700000, 0x14, 0x17, 10000), |
|---|
| 56 | 60 | REGULATOR_LINEAR_RANGE(735000, 0x18, 0x9d, 5000), |
|---|
| 57 | 61 | REGULATOR_LINEAR_RANGE(1420000, 0x9e, 0xff, 20000), |
|---|
| 58 | 62 | }; |
|---|
| 59 | 63 | |
|---|
| 60 | | -static const struct regulator_linear_range ldo0_ldo1_ranges[] = { |
|---|
| 64 | +static const struct linear_range ldo0_ldo1_ranges[] = { |
|---|
| 61 | 65 | REGULATOR_LINEAR_RANGE(800000, 0x0, 0x19, 100000), |
|---|
| 62 | 66 | }; |
|---|
| 63 | 67 | |
|---|
| 64 | | -static unsigned int lp873x_buck_ramp_delay[] = { |
|---|
| 68 | +static const unsigned int lp873x_buck_ramp_delay[] = { |
|---|
| 65 | 69 | 30000, 15000, 10000, 7500, 3800, 1900, 940, 470 |
|---|
| 66 | 70 | }; |
|---|
| 67 | 71 | |
|---|
| .. | .. |
|---|
| 108 | 112 | return 0; |
|---|
| 109 | 113 | } |
|---|
| 110 | 114 | |
|---|
| 111 | | -static int lp873x_buck_set_current_limit(struct regulator_dev *rdev, |
|---|
| 112 | | - int min_uA, int max_uA) |
|---|
| 113 | | -{ |
|---|
| 114 | | - int id = rdev_get_id(rdev); |
|---|
| 115 | | - struct lp873x *lp873 = rdev_get_drvdata(rdev); |
|---|
| 116 | | - int i; |
|---|
| 117 | | - |
|---|
| 118 | | - for (i = ARRAY_SIZE(lp873x_buck_uA) - 1; i >= 0; i--) { |
|---|
| 119 | | - if (lp873x_buck_uA[i] >= min_uA && |
|---|
| 120 | | - lp873x_buck_uA[i] <= max_uA) |
|---|
| 121 | | - return regmap_update_bits(lp873->regmap, |
|---|
| 122 | | - regulators[id].ctrl2_reg, |
|---|
| 123 | | - LP873X_BUCK0_CTRL_2_BUCK0_ILIM, |
|---|
| 124 | | - i << __ffs(LP873X_BUCK0_CTRL_2_BUCK0_ILIM)); |
|---|
| 125 | | - } |
|---|
| 126 | | - |
|---|
| 127 | | - return -EINVAL; |
|---|
| 128 | | -} |
|---|
| 129 | | - |
|---|
| 130 | | -static int lp873x_buck_get_current_limit(struct regulator_dev *rdev) |
|---|
| 131 | | -{ |
|---|
| 132 | | - int id = rdev_get_id(rdev); |
|---|
| 133 | | - struct lp873x *lp873 = rdev_get_drvdata(rdev); |
|---|
| 134 | | - int ret; |
|---|
| 135 | | - unsigned int val; |
|---|
| 136 | | - |
|---|
| 137 | | - ret = regmap_read(lp873->regmap, regulators[id].ctrl2_reg, &val); |
|---|
| 138 | | - if (ret) |
|---|
| 139 | | - return ret; |
|---|
| 140 | | - |
|---|
| 141 | | - val = (val & LP873X_BUCK0_CTRL_2_BUCK0_ILIM) >> |
|---|
| 142 | | - __ffs(LP873X_BUCK0_CTRL_2_BUCK0_ILIM); |
|---|
| 143 | | - |
|---|
| 144 | | - return (val < ARRAY_SIZE(lp873x_buck_uA)) ? |
|---|
| 145 | | - lp873x_buck_uA[val] : -EINVAL; |
|---|
| 146 | | -} |
|---|
| 147 | | - |
|---|
| 148 | 115 | /* Operations permitted on BUCK0, BUCK1 */ |
|---|
| 149 | | -static struct regulator_ops lp873x_buck01_ops = { |
|---|
| 116 | +static const struct regulator_ops lp873x_buck01_ops = { |
|---|
| 150 | 117 | .is_enabled = regulator_is_enabled_regmap, |
|---|
| 151 | 118 | .enable = regulator_enable_regmap, |
|---|
| 152 | 119 | .disable = regulator_disable_regmap, |
|---|
| .. | .. |
|---|
| 156 | 123 | .map_voltage = regulator_map_voltage_linear_range, |
|---|
| 157 | 124 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
|---|
| 158 | 125 | .set_ramp_delay = lp873x_buck_set_ramp_delay, |
|---|
| 159 | | - .set_current_limit = lp873x_buck_set_current_limit, |
|---|
| 160 | | - .get_current_limit = lp873x_buck_get_current_limit, |
|---|
| 126 | + .set_current_limit = regulator_set_current_limit_regmap, |
|---|
| 127 | + .get_current_limit = regulator_get_current_limit_regmap, |
|---|
| 161 | 128 | }; |
|---|
| 162 | 129 | |
|---|
| 163 | 130 | /* Operations permitted on LDO0 and LDO1 */ |
|---|
| 164 | | -static struct regulator_ops lp873x_ldo01_ops = { |
|---|
| 131 | +static const struct regulator_ops lp873x_ldo01_ops = { |
|---|
| 165 | 132 | .is_enabled = regulator_is_enabled_regmap, |
|---|
| 166 | 133 | .enable = regulator_enable_regmap, |
|---|
| 167 | 134 | .disable = regulator_disable_regmap, |
|---|