Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 1 | /* |
| 2 | * max8973-regulator.c -- Maxim max8973 |
| 3 | * |
| 4 | * Regulator driver for MAXIM 8973 DC-DC step-down switching regulator. |
| 5 | * |
| 6 | * Copyright (c) 2012, NVIDIA Corporation. |
| 7 | * |
| 8 | * Author: Laxman Dewangan <ldewangan@nvidia.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation version 2. |
| 13 | * |
| 14 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, |
| 15 | * whether express or implied; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 22 | * 02111-1307, USA |
| 23 | */ |
| 24 | |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/err.h> |
Guennadi Liakhovetski | 42dc302 | 2013-06-24 12:50:16 +0200 | [diff] [blame] | 29 | #include <linux/of.h> |
Laxman Dewangan | 0f7d6ec | 2015-06-09 19:17:53 +0530 | [diff] [blame] | 30 | #include <linux/of_device.h> |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 31 | #include <linux/platform_device.h> |
| 32 | #include <linux/regulator/driver.h> |
| 33 | #include <linux/regulator/machine.h> |
| 34 | #include <linux/regulator/max8973-regulator.h> |
Guennadi Liakhovetski | 42dc302 | 2013-06-24 12:50:16 +0200 | [diff] [blame] | 35 | #include <linux/regulator/of_regulator.h> |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 36 | #include <linux/gpio.h> |
Laxman Dewangan | c2ffa97 | 2015-04-23 16:10:23 +0530 | [diff] [blame] | 37 | #include <linux/of_gpio.h> |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 38 | #include <linux/i2c.h> |
| 39 | #include <linux/slab.h> |
| 40 | #include <linux/regmap.h> |
Laxman Dewangan | d2d5437b | 2016-04-13 15:29:45 +0530 | [diff] [blame] | 41 | #include <linux/thermal.h> |
| 42 | #include <linux/irq.h> |
| 43 | #include <linux/interrupt.h> |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 44 | |
| 45 | /* Register definitions */ |
| 46 | #define MAX8973_VOUT 0x0 |
| 47 | #define MAX8973_VOUT_DVS 0x1 |
| 48 | #define MAX8973_CONTROL1 0x2 |
| 49 | #define MAX8973_CONTROL2 0x3 |
| 50 | #define MAX8973_CHIPID1 0x4 |
| 51 | #define MAX8973_CHIPID2 0x5 |
| 52 | |
| 53 | #define MAX8973_MAX_VOUT_REG 2 |
| 54 | |
| 55 | /* MAX8973_VOUT */ |
| 56 | #define MAX8973_VOUT_ENABLE BIT(7) |
| 57 | #define MAX8973_VOUT_MASK 0x7F |
| 58 | |
| 59 | /* MAX8973_VOUT_DVS */ |
| 60 | #define MAX8973_DVS_VOUT_MASK 0x7F |
| 61 | |
| 62 | /* MAX8973_CONTROL1 */ |
| 63 | #define MAX8973_SNS_ENABLE BIT(7) |
| 64 | #define MAX8973_FPWM_EN_M BIT(6) |
| 65 | #define MAX8973_NFSR_ENABLE BIT(5) |
| 66 | #define MAX8973_AD_ENABLE BIT(4) |
| 67 | #define MAX8973_BIAS_ENABLE BIT(3) |
| 68 | #define MAX8973_FREQSHIFT_9PER BIT(2) |
| 69 | |
| 70 | #define MAX8973_RAMP_12mV_PER_US 0x0 |
| 71 | #define MAX8973_RAMP_25mV_PER_US 0x1 |
| 72 | #define MAX8973_RAMP_50mV_PER_US 0x2 |
| 73 | #define MAX8973_RAMP_200mV_PER_US 0x3 |
Laxman Dewangan | 3064c1f | 2015-06-09 19:17:52 +0530 | [diff] [blame] | 74 | #define MAX8973_RAMP_MASK 0x3 |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 75 | |
| 76 | /* MAX8973_CONTROL2 */ |
| 77 | #define MAX8973_WDTMR_ENABLE BIT(6) |
| 78 | #define MAX8973_DISCH_ENBABLE BIT(5) |
| 79 | #define MAX8973_FT_ENABLE BIT(4) |
Laxman Dewangan | d2d5437b | 2016-04-13 15:29:45 +0530 | [diff] [blame] | 80 | #define MAX77621_T_JUNCTION_120 BIT(7) |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 81 | |
Laxman Dewangan | ffaab99 | 2015-07-01 18:31:44 +0530 | [diff] [blame] | 82 | #define MAX8973_CKKADV_TRIP_MASK 0xC |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 83 | #define MAX8973_CKKADV_TRIP_DISABLE 0xC |
| 84 | #define MAX8973_CKKADV_TRIP_75mV_PER_US 0x0 |
| 85 | #define MAX8973_CKKADV_TRIP_150mV_PER_US 0x4 |
| 86 | #define MAX8973_CKKADV_TRIP_75mV_PER_US_HIST_DIS 0x8 |
| 87 | #define MAX8973_CONTROL_CLKADV_TRIP_MASK 0x00030000 |
| 88 | |
| 89 | #define MAX8973_INDUCTOR_MIN_30_PER 0x0 |
| 90 | #define MAX8973_INDUCTOR_NOMINAL 0x1 |
| 91 | #define MAX8973_INDUCTOR_PLUS_30_PER 0x2 |
| 92 | #define MAX8973_INDUCTOR_PLUS_60_PER 0x3 |
| 93 | #define MAX8973_CONTROL_INDUCTOR_VALUE_MASK 0x00300000 |
| 94 | |
| 95 | #define MAX8973_MIN_VOLATGE 606250 |
| 96 | #define MAX8973_MAX_VOLATGE 1400000 |
| 97 | #define MAX8973_VOLATGE_STEP 6250 |
| 98 | #define MAX8973_BUCK_N_VOLTAGE 0x80 |
| 99 | |
Laxman Dewangan | d2d5437b | 2016-04-13 15:29:45 +0530 | [diff] [blame] | 100 | #define MAX77621_CHIPID_TJINT_S BIT(0) |
| 101 | |
| 102 | #define MAX77621_NORMAL_OPERATING_TEMP 100000 |
| 103 | #define MAX77621_TJINT_WARNING_TEMP_120 120000 |
| 104 | #define MAX77621_TJINT_WARNING_TEMP_140 140000 |
| 105 | |
Laxman Dewangan | 0f7d6ec | 2015-06-09 19:17:53 +0530 | [diff] [blame] | 106 | enum device_id { |
| 107 | MAX8973, |
| 108 | MAX77621 |
| 109 | }; |
| 110 | |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 111 | /* Maxim 8973 chip information */ |
| 112 | struct max8973_chip { |
| 113 | struct device *dev; |
| 114 | struct regulator_desc desc; |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 115 | struct regmap *regmap; |
| 116 | bool enable_external_control; |
Laxman Dewangan | 69eb098 | 2015-04-23 16:10:24 +0530 | [diff] [blame] | 117 | int enable_gpio; |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 118 | int dvs_gpio; |
| 119 | int lru_index[MAX8973_MAX_VOUT_REG]; |
| 120 | int curr_vout_val[MAX8973_MAX_VOUT_REG]; |
| 121 | int curr_vout_reg; |
| 122 | int curr_gpio_val; |
Guennadi Liakhovetski | db892ff | 2013-06-21 08:30:22 +0200 | [diff] [blame] | 123 | struct regulator_ops ops; |
Laxman Dewangan | 0f7d6ec | 2015-06-09 19:17:53 +0530 | [diff] [blame] | 124 | enum device_id id; |
Laxman Dewangan | d2d5437b | 2016-04-13 15:29:45 +0530 | [diff] [blame] | 125 | int junction_temp_warning; |
| 126 | int irq; |
| 127 | struct thermal_zone_device *tz_device; |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | /* |
| 131 | * find_voltage_set_register: Find new voltage configuration register (VOUT). |
| 132 | * The finding of the new VOUT register will be based on the LRU mechanism. |
| 133 | * Each VOUT register will have different voltage configured . This |
| 134 | * Function will look if any of the VOUT register have requested voltage set |
| 135 | * or not. |
| 136 | * - If it is already there then it will make that register as most |
| 137 | * recently used and return as found so that caller need not to set |
| 138 | * the VOUT register but need to set the proper gpios to select this |
| 139 | * VOUT register. |
| 140 | * - If requested voltage is not found then it will use the least |
| 141 | * recently mechanism to get new VOUT register for new configuration |
| 142 | * and will return not_found so that caller need to set new VOUT |
| 143 | * register and then gpios (both). |
| 144 | */ |
| 145 | static bool find_voltage_set_register(struct max8973_chip *tps, |
| 146 | int req_vsel, int *vout_reg, int *gpio_val) |
| 147 | { |
| 148 | int i; |
| 149 | bool found = false; |
| 150 | int new_vout_reg = tps->lru_index[MAX8973_MAX_VOUT_REG - 1]; |
| 151 | int found_index = MAX8973_MAX_VOUT_REG - 1; |
| 152 | |
| 153 | for (i = 0; i < MAX8973_MAX_VOUT_REG; ++i) { |
| 154 | if (tps->curr_vout_val[tps->lru_index[i]] == req_vsel) { |
| 155 | new_vout_reg = tps->lru_index[i]; |
| 156 | found_index = i; |
| 157 | found = true; |
| 158 | goto update_lru_index; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | update_lru_index: |
| 163 | for (i = found_index; i > 0; i--) |
| 164 | tps->lru_index[i] = tps->lru_index[i - 1]; |
| 165 | |
| 166 | tps->lru_index[0] = new_vout_reg; |
| 167 | *gpio_val = new_vout_reg; |
| 168 | *vout_reg = MAX8973_VOUT + new_vout_reg; |
| 169 | return found; |
| 170 | } |
| 171 | |
| 172 | static int max8973_dcdc_get_voltage_sel(struct regulator_dev *rdev) |
| 173 | { |
| 174 | struct max8973_chip *max = rdev_get_drvdata(rdev); |
| 175 | unsigned int data; |
| 176 | int ret; |
| 177 | |
| 178 | ret = regmap_read(max->regmap, max->curr_vout_reg, &data); |
| 179 | if (ret < 0) { |
| 180 | dev_err(max->dev, "register %d read failed, err = %d\n", |
| 181 | max->curr_vout_reg, ret); |
| 182 | return ret; |
| 183 | } |
| 184 | return data & MAX8973_VOUT_MASK; |
| 185 | } |
| 186 | |
| 187 | static int max8973_dcdc_set_voltage_sel(struct regulator_dev *rdev, |
| 188 | unsigned vsel) |
| 189 | { |
| 190 | struct max8973_chip *max = rdev_get_drvdata(rdev); |
| 191 | int ret; |
| 192 | bool found = false; |
| 193 | int vout_reg = max->curr_vout_reg; |
| 194 | int gpio_val = max->curr_gpio_val; |
| 195 | |
| 196 | /* |
| 197 | * If gpios are available to select the VOUT register then least |
| 198 | * recently used register for new configuration. |
| 199 | */ |
Laxman Dewangan | fa5f509 | 2015-05-06 18:20:10 +0530 | [diff] [blame] | 200 | if (gpio_is_valid(max->dvs_gpio)) |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 201 | found = find_voltage_set_register(max, vsel, |
| 202 | &vout_reg, &gpio_val); |
| 203 | |
| 204 | if (!found) { |
| 205 | ret = regmap_update_bits(max->regmap, vout_reg, |
| 206 | MAX8973_VOUT_MASK, vsel); |
| 207 | if (ret < 0) { |
| 208 | dev_err(max->dev, "register %d update failed, err %d\n", |
| 209 | vout_reg, ret); |
| 210 | return ret; |
| 211 | } |
| 212 | max->curr_vout_reg = vout_reg; |
| 213 | max->curr_vout_val[gpio_val] = vsel; |
| 214 | } |
| 215 | |
| 216 | /* Select proper VOUT register vio gpios */ |
Laxman Dewangan | fa5f509 | 2015-05-06 18:20:10 +0530 | [diff] [blame] | 217 | if (gpio_is_valid(max->dvs_gpio)) { |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 218 | gpio_set_value_cansleep(max->dvs_gpio, gpio_val & 0x1); |
| 219 | max->curr_gpio_val = gpio_val; |
| 220 | } |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | static int max8973_dcdc_set_mode(struct regulator_dev *rdev, unsigned int mode) |
| 225 | { |
| 226 | struct max8973_chip *max = rdev_get_drvdata(rdev); |
| 227 | int ret; |
| 228 | int pwm; |
| 229 | |
| 230 | /* Enable force PWM mode in FAST mode only. */ |
| 231 | switch (mode) { |
| 232 | case REGULATOR_MODE_FAST: |
| 233 | pwm = MAX8973_FPWM_EN_M; |
| 234 | break; |
| 235 | |
| 236 | case REGULATOR_MODE_NORMAL: |
| 237 | pwm = 0; |
| 238 | break; |
| 239 | |
| 240 | default: |
| 241 | return -EINVAL; |
| 242 | } |
| 243 | |
| 244 | ret = regmap_update_bits(max->regmap, MAX8973_CONTROL1, |
| 245 | MAX8973_FPWM_EN_M, pwm); |
| 246 | if (ret < 0) |
| 247 | dev_err(max->dev, "register %d update failed, err %d\n", |
| 248 | MAX8973_CONTROL1, ret); |
| 249 | return ret; |
| 250 | } |
| 251 | |
| 252 | static unsigned int max8973_dcdc_get_mode(struct regulator_dev *rdev) |
| 253 | { |
| 254 | struct max8973_chip *max = rdev_get_drvdata(rdev); |
| 255 | unsigned int data; |
| 256 | int ret; |
| 257 | |
| 258 | ret = regmap_read(max->regmap, MAX8973_CONTROL1, &data); |
| 259 | if (ret < 0) { |
| 260 | dev_err(max->dev, "register %d read failed, err %d\n", |
| 261 | MAX8973_CONTROL1, ret); |
| 262 | return ret; |
| 263 | } |
| 264 | return (data & MAX8973_FPWM_EN_M) ? |
| 265 | REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL; |
| 266 | } |
| 267 | |
Laxman Dewangan | 3064c1f | 2015-06-09 19:17:52 +0530 | [diff] [blame] | 268 | static int max8973_set_ramp_delay(struct regulator_dev *rdev, |
| 269 | int ramp_delay) |
| 270 | { |
| 271 | struct max8973_chip *max = rdev_get_drvdata(rdev); |
| 272 | unsigned int control; |
| 273 | int ret; |
Laxman Dewangan | 3064c1f | 2015-06-09 19:17:52 +0530 | [diff] [blame] | 274 | |
| 275 | /* Set ramp delay */ |
Axel Lin | d0abd6f | 2016-05-29 19:20:03 +0800 | [diff] [blame] | 276 | if (ramp_delay <= 12000) |
Laxman Dewangan | 3064c1f | 2015-06-09 19:17:52 +0530 | [diff] [blame] | 277 | control = MAX8973_RAMP_12mV_PER_US; |
Axel Lin | d0abd6f | 2016-05-29 19:20:03 +0800 | [diff] [blame] | 278 | else if (ramp_delay <= 25000) |
Laxman Dewangan | 3064c1f | 2015-06-09 19:17:52 +0530 | [diff] [blame] | 279 | control = MAX8973_RAMP_25mV_PER_US; |
Axel Lin | d0abd6f | 2016-05-29 19:20:03 +0800 | [diff] [blame] | 280 | else if (ramp_delay <= 50000) |
Laxman Dewangan | 3064c1f | 2015-06-09 19:17:52 +0530 | [diff] [blame] | 281 | control = MAX8973_RAMP_50mV_PER_US; |
Axel Lin | d0abd6f | 2016-05-29 19:20:03 +0800 | [diff] [blame] | 282 | else if (ramp_delay <= 200000) |
Laxman Dewangan | 3064c1f | 2015-06-09 19:17:52 +0530 | [diff] [blame] | 283 | control = MAX8973_RAMP_200mV_PER_US; |
Axel Lin | d0abd6f | 2016-05-29 19:20:03 +0800 | [diff] [blame] | 284 | else |
| 285 | return -EINVAL; |
Laxman Dewangan | 3064c1f | 2015-06-09 19:17:52 +0530 | [diff] [blame] | 286 | |
| 287 | ret = regmap_update_bits(max->regmap, MAX8973_CONTROL1, |
| 288 | MAX8973_RAMP_MASK, control); |
| 289 | if (ret < 0) |
| 290 | dev_err(max->dev, "register %d update failed, %d", |
| 291 | MAX8973_CONTROL1, ret); |
| 292 | return ret; |
| 293 | } |
| 294 | |
Laxman Dewangan | ffaab99 | 2015-07-01 18:31:44 +0530 | [diff] [blame] | 295 | static int max8973_set_current_limit(struct regulator_dev *rdev, |
| 296 | int min_ua, int max_ua) |
| 297 | { |
| 298 | struct max8973_chip *max = rdev_get_drvdata(rdev); |
| 299 | unsigned int val; |
| 300 | int ret; |
| 301 | |
| 302 | if (max_ua <= 9000000) |
| 303 | val = MAX8973_CKKADV_TRIP_75mV_PER_US; |
| 304 | else if (max_ua <= 12000000) |
| 305 | val = MAX8973_CKKADV_TRIP_150mV_PER_US; |
| 306 | else |
| 307 | val = MAX8973_CKKADV_TRIP_DISABLE; |
| 308 | |
| 309 | ret = regmap_update_bits(max->regmap, MAX8973_CONTROL2, |
| 310 | MAX8973_CKKADV_TRIP_MASK, val); |
| 311 | if (ret < 0) { |
| 312 | dev_err(max->dev, "register %d update failed: %d\n", |
| 313 | MAX8973_CONTROL2, ret); |
| 314 | return ret; |
| 315 | } |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | static int max8973_get_current_limit(struct regulator_dev *rdev) |
| 320 | { |
| 321 | struct max8973_chip *max = rdev_get_drvdata(rdev); |
| 322 | unsigned int control2; |
| 323 | int ret; |
| 324 | |
| 325 | ret = regmap_read(max->regmap, MAX8973_CONTROL2, &control2); |
| 326 | if (ret < 0) { |
| 327 | dev_err(max->dev, "register %d read failed: %d\n", |
| 328 | MAX8973_CONTROL2, ret); |
| 329 | return ret; |
| 330 | } |
| 331 | switch (control2 & MAX8973_CKKADV_TRIP_MASK) { |
| 332 | case MAX8973_CKKADV_TRIP_DISABLE: |
| 333 | return 15000000; |
| 334 | case MAX8973_CKKADV_TRIP_150mV_PER_US: |
| 335 | return 12000000; |
| 336 | case MAX8973_CKKADV_TRIP_75mV_PER_US: |
| 337 | return 9000000; |
| 338 | default: |
| 339 | break; |
| 340 | } |
| 341 | return 9000000; |
| 342 | } |
| 343 | |
Guennadi Liakhovetski | db892ff | 2013-06-21 08:30:22 +0200 | [diff] [blame] | 344 | static const struct regulator_ops max8973_dcdc_ops = { |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 345 | .get_voltage_sel = max8973_dcdc_get_voltage_sel, |
| 346 | .set_voltage_sel = max8973_dcdc_set_voltage_sel, |
| 347 | .list_voltage = regulator_list_voltage_linear, |
| 348 | .set_mode = max8973_dcdc_set_mode, |
| 349 | .get_mode = max8973_dcdc_get_mode, |
Laxman Dewangan | 3064c1f | 2015-06-09 19:17:52 +0530 | [diff] [blame] | 350 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
| 351 | .set_ramp_delay = max8973_set_ramp_delay, |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 352 | }; |
| 353 | |
Greg Kroah-Hartman | 3d68dfe | 2012-12-21 13:26:06 -0800 | [diff] [blame] | 354 | static int max8973_init_dcdc(struct max8973_chip *max, |
| 355 | struct max8973_regulator_platform_data *pdata) |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 356 | { |
| 357 | int ret; |
| 358 | uint8_t control1 = 0; |
| 359 | uint8_t control2 = 0; |
Laxman Dewangan | 3064c1f | 2015-06-09 19:17:52 +0530 | [diff] [blame] | 360 | unsigned int data; |
| 361 | |
| 362 | ret = regmap_read(max->regmap, MAX8973_CONTROL1, &data); |
| 363 | if (ret < 0) { |
| 364 | dev_err(max->dev, "register %d read failed, err = %d", |
| 365 | MAX8973_CONTROL1, ret); |
| 366 | return ret; |
| 367 | } |
| 368 | control1 = data & MAX8973_RAMP_MASK; |
| 369 | switch (control1) { |
| 370 | case MAX8973_RAMP_12mV_PER_US: |
| 371 | max->desc.ramp_delay = 12000; |
| 372 | break; |
| 373 | case MAX8973_RAMP_25mV_PER_US: |
Axel Lin | 366604e | 2015-06-10 18:52:11 +0800 | [diff] [blame] | 374 | max->desc.ramp_delay = 25000; |
Laxman Dewangan | 3064c1f | 2015-06-09 19:17:52 +0530 | [diff] [blame] | 375 | break; |
| 376 | case MAX8973_RAMP_50mV_PER_US: |
| 377 | max->desc.ramp_delay = 50000; |
| 378 | break; |
| 379 | case MAX8973_RAMP_200mV_PER_US: |
| 380 | max->desc.ramp_delay = 200000; |
| 381 | break; |
| 382 | } |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 383 | |
| 384 | if (pdata->control_flags & MAX8973_CONTROL_REMOTE_SENSE_ENABLE) |
| 385 | control1 |= MAX8973_SNS_ENABLE; |
| 386 | |
| 387 | if (!(pdata->control_flags & MAX8973_CONTROL_FALLING_SLEW_RATE_ENABLE)) |
| 388 | control1 |= MAX8973_NFSR_ENABLE; |
| 389 | |
| 390 | if (pdata->control_flags & MAX8973_CONTROL_OUTPUT_ACTIVE_DISCH_ENABLE) |
| 391 | control1 |= MAX8973_AD_ENABLE; |
| 392 | |
Laxman Dewangan | dcd9ec6 | 2015-04-23 16:10:22 +0530 | [diff] [blame] | 393 | if (pdata->control_flags & MAX8973_CONTROL_BIAS_ENABLE) { |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 394 | control1 |= MAX8973_BIAS_ENABLE; |
Laxman Dewangan | dcd9ec6 | 2015-04-23 16:10:22 +0530 | [diff] [blame] | 395 | max->desc.enable_time = 20; |
| 396 | } else { |
| 397 | max->desc.enable_time = 240; |
| 398 | } |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 399 | |
| 400 | if (pdata->control_flags & MAX8973_CONTROL_FREQ_SHIFT_9PER_ENABLE) |
| 401 | control1 |= MAX8973_FREQSHIFT_9PER; |
| 402 | |
Laxman Dewangan | d2d5437b | 2016-04-13 15:29:45 +0530 | [diff] [blame] | 403 | if ((pdata->junction_temp_warning == MAX77621_TJINT_WARNING_TEMP_120) && |
| 404 | (max->id == MAX77621)) |
| 405 | control2 |= MAX77621_T_JUNCTION_120; |
| 406 | |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 407 | if (!(pdata->control_flags & MAX8973_CONTROL_PULL_DOWN_ENABLE)) |
| 408 | control2 |= MAX8973_DISCH_ENBABLE; |
| 409 | |
| 410 | /* Clock advance trip configuration */ |
| 411 | switch (pdata->control_flags & MAX8973_CONTROL_CLKADV_TRIP_MASK) { |
| 412 | case MAX8973_CONTROL_CLKADV_TRIP_DISABLED: |
| 413 | control2 |= MAX8973_CKKADV_TRIP_DISABLE; |
| 414 | break; |
| 415 | |
| 416 | case MAX8973_CONTROL_CLKADV_TRIP_75mV_PER_US: |
| 417 | control2 |= MAX8973_CKKADV_TRIP_75mV_PER_US; |
| 418 | break; |
| 419 | |
| 420 | case MAX8973_CONTROL_CLKADV_TRIP_150mV_PER_US: |
| 421 | control2 |= MAX8973_CKKADV_TRIP_150mV_PER_US; |
| 422 | break; |
| 423 | |
| 424 | case MAX8973_CONTROL_CLKADV_TRIP_75mV_PER_US_HIST_DIS: |
| 425 | control2 |= MAX8973_CKKADV_TRIP_75mV_PER_US_HIST_DIS; |
| 426 | break; |
| 427 | } |
| 428 | |
| 429 | /* Configure inductor value */ |
| 430 | switch (pdata->control_flags & MAX8973_CONTROL_INDUCTOR_VALUE_MASK) { |
| 431 | case MAX8973_CONTROL_INDUCTOR_VALUE_NOMINAL: |
| 432 | control2 |= MAX8973_INDUCTOR_NOMINAL; |
| 433 | break; |
| 434 | |
| 435 | case MAX8973_CONTROL_INDUCTOR_VALUE_MINUS_30_PER: |
| 436 | control2 |= MAX8973_INDUCTOR_MIN_30_PER; |
| 437 | break; |
| 438 | |
| 439 | case MAX8973_CONTROL_INDUCTOR_VALUE_PLUS_30_PER: |
| 440 | control2 |= MAX8973_INDUCTOR_PLUS_30_PER; |
| 441 | break; |
| 442 | |
| 443 | case MAX8973_CONTROL_INDUCTOR_VALUE_PLUS_60_PER: |
| 444 | control2 |= MAX8973_INDUCTOR_PLUS_60_PER; |
| 445 | break; |
| 446 | } |
| 447 | |
| 448 | ret = regmap_write(max->regmap, MAX8973_CONTROL1, control1); |
| 449 | if (ret < 0) { |
| 450 | dev_err(max->dev, "register %d write failed, err = %d", |
| 451 | MAX8973_CONTROL1, ret); |
| 452 | return ret; |
| 453 | } |
| 454 | |
| 455 | ret = regmap_write(max->regmap, MAX8973_CONTROL2, control2); |
| 456 | if (ret < 0) { |
| 457 | dev_err(max->dev, "register %d write failed, err = %d", |
| 458 | MAX8973_CONTROL2, ret); |
| 459 | return ret; |
| 460 | } |
| 461 | |
| 462 | /* If external control is enabled then disable EN bit */ |
Laxman Dewangan | 0f7d6ec | 2015-06-09 19:17:53 +0530 | [diff] [blame] | 463 | if (max->enable_external_control && (max->id == MAX8973)) { |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 464 | ret = regmap_update_bits(max->regmap, MAX8973_VOUT, |
| 465 | MAX8973_VOUT_ENABLE, 0); |
| 466 | if (ret < 0) |
| 467 | dev_err(max->dev, "register %d update failed, err = %d", |
| 468 | MAX8973_VOUT, ret); |
| 469 | } |
| 470 | return ret; |
| 471 | } |
| 472 | |
Laxman Dewangan | d2d5437b | 2016-04-13 15:29:45 +0530 | [diff] [blame] | 473 | static int max8973_thermal_read_temp(void *data, int *temp) |
| 474 | { |
| 475 | struct max8973_chip *mchip = data; |
| 476 | unsigned int val; |
| 477 | int ret; |
| 478 | |
| 479 | ret = regmap_read(mchip->regmap, MAX8973_CHIPID1, &val); |
| 480 | if (ret < 0) { |
| 481 | dev_err(mchip->dev, "Failed to read register CHIPID1, %d", ret); |
| 482 | return ret; |
| 483 | } |
| 484 | |
| 485 | /* +1 degC to trigger cool devive */ |
| 486 | if (val & MAX77621_CHIPID_TJINT_S) |
| 487 | *temp = mchip->junction_temp_warning + 1000; |
| 488 | else |
| 489 | *temp = MAX77621_NORMAL_OPERATING_TEMP; |
| 490 | |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | static irqreturn_t max8973_thermal_irq(int irq, void *data) |
| 495 | { |
| 496 | struct max8973_chip *mchip = data; |
| 497 | |
Srinivas Pandruvada | 0e70f46 | 2016-08-26 16:21:16 -0700 | [diff] [blame] | 498 | thermal_zone_device_update(mchip->tz_device, |
| 499 | THERMAL_EVENT_UNSPECIFIED); |
Laxman Dewangan | d2d5437b | 2016-04-13 15:29:45 +0530 | [diff] [blame] | 500 | |
| 501 | return IRQ_HANDLED; |
| 502 | } |
| 503 | |
| 504 | static const struct thermal_zone_of_device_ops max77621_tz_ops = { |
| 505 | .get_temp = max8973_thermal_read_temp, |
| 506 | }; |
| 507 | |
| 508 | static int max8973_thermal_init(struct max8973_chip *mchip) |
| 509 | { |
| 510 | struct thermal_zone_device *tzd; |
| 511 | struct irq_data *irq_data; |
| 512 | unsigned long irq_flags = 0; |
| 513 | int ret; |
| 514 | |
| 515 | if (mchip->id != MAX77621) |
| 516 | return 0; |
| 517 | |
| 518 | tzd = devm_thermal_zone_of_sensor_register(mchip->dev, 0, mchip, |
| 519 | &max77621_tz_ops); |
| 520 | if (IS_ERR(tzd)) { |
| 521 | ret = PTR_ERR(tzd); |
| 522 | dev_err(mchip->dev, "Failed to register thermal sensor: %d\n", |
| 523 | ret); |
| 524 | return ret; |
| 525 | } |
| 526 | |
| 527 | if (mchip->irq <= 0) |
| 528 | return 0; |
| 529 | |
| 530 | irq_data = irq_get_irq_data(mchip->irq); |
| 531 | if (irq_data) |
| 532 | irq_flags = irqd_get_trigger_type(irq_data); |
| 533 | |
| 534 | ret = devm_request_threaded_irq(mchip->dev, mchip->irq, NULL, |
| 535 | max8973_thermal_irq, |
| 536 | IRQF_ONESHOT | IRQF_SHARED | irq_flags, |
| 537 | dev_name(mchip->dev), mchip); |
| 538 | if (ret < 0) { |
| 539 | dev_err(mchip->dev, "Failed to request irq %d, %d\n", |
| 540 | mchip->irq, ret); |
| 541 | return ret; |
| 542 | } |
| 543 | |
| 544 | return 0; |
| 545 | } |
| 546 | |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 547 | static const struct regmap_config max8973_regmap_config = { |
| 548 | .reg_bits = 8, |
| 549 | .val_bits = 8, |
| 550 | .max_register = MAX8973_CHIPID2, |
| 551 | .cache_type = REGCACHE_RBTREE, |
| 552 | }; |
| 553 | |
Laxman Dewangan | c2ffa97 | 2015-04-23 16:10:23 +0530 | [diff] [blame] | 554 | static struct max8973_regulator_platform_data *max8973_parse_dt( |
| 555 | struct device *dev) |
| 556 | { |
| 557 | struct max8973_regulator_platform_data *pdata; |
| 558 | struct device_node *np = dev->of_node; |
| 559 | int ret; |
| 560 | u32 pval; |
Laxman Dewangan | 3692db3 | 2015-07-01 18:31:43 +0530 | [diff] [blame] | 561 | bool etr_enable; |
| 562 | bool etr_sensitivity_high; |
Laxman Dewangan | c2ffa97 | 2015-04-23 16:10:23 +0530 | [diff] [blame] | 563 | |
| 564 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
| 565 | if (!pdata) |
| 566 | return NULL; |
| 567 | |
| 568 | pdata->enable_ext_control = of_property_read_bool(np, |
| 569 | "maxim,externally-enable"); |
Laxman Dewangan | 69eb098 | 2015-04-23 16:10:24 +0530 | [diff] [blame] | 570 | pdata->enable_gpio = of_get_named_gpio(np, "maxim,enable-gpio", 0); |
Laxman Dewangan | c2ffa97 | 2015-04-23 16:10:23 +0530 | [diff] [blame] | 571 | pdata->dvs_gpio = of_get_named_gpio(np, "maxim,dvs-gpio", 0); |
| 572 | |
| 573 | ret = of_property_read_u32(np, "maxim,dvs-default-state", &pval); |
| 574 | if (!ret) |
| 575 | pdata->dvs_def_state = pval; |
| 576 | |
| 577 | if (of_property_read_bool(np, "maxim,enable-remote-sense")) |
| 578 | pdata->control_flags |= MAX8973_CONTROL_REMOTE_SENSE_ENABLE; |
| 579 | |
| 580 | if (of_property_read_bool(np, "maxim,enable-falling-slew-rate")) |
| 581 | pdata->control_flags |= |
| 582 | MAX8973_CONTROL_FALLING_SLEW_RATE_ENABLE; |
| 583 | |
| 584 | if (of_property_read_bool(np, "maxim,enable-active-discharge")) |
| 585 | pdata->control_flags |= |
| 586 | MAX8973_CONTROL_OUTPUT_ACTIVE_DISCH_ENABLE; |
| 587 | |
| 588 | if (of_property_read_bool(np, "maxim,enable-frequency-shift")) |
| 589 | pdata->control_flags |= MAX8973_CONTROL_FREQ_SHIFT_9PER_ENABLE; |
| 590 | |
| 591 | if (of_property_read_bool(np, "maxim,enable-bias-control")) |
Laxman Dewangan | 127e106 | 2015-07-01 18:31:42 +0530 | [diff] [blame] | 592 | pdata->control_flags |= MAX8973_CONTROL_BIAS_ENABLE; |
Laxman Dewangan | c2ffa97 | 2015-04-23 16:10:23 +0530 | [diff] [blame] | 593 | |
Laxman Dewangan | 3692db3 | 2015-07-01 18:31:43 +0530 | [diff] [blame] | 594 | etr_enable = of_property_read_bool(np, "maxim,enable-etr"); |
| 595 | etr_sensitivity_high = of_property_read_bool(np, |
| 596 | "maxim,enable-high-etr-sensitivity"); |
| 597 | if (etr_sensitivity_high) |
| 598 | etr_enable = true; |
| 599 | |
| 600 | if (etr_enable) { |
| 601 | if (etr_sensitivity_high) |
| 602 | pdata->control_flags |= |
| 603 | MAX8973_CONTROL_CLKADV_TRIP_75mV_PER_US; |
| 604 | else |
| 605 | pdata->control_flags |= |
| 606 | MAX8973_CONTROL_CLKADV_TRIP_150mV_PER_US; |
| 607 | } else { |
| 608 | pdata->control_flags |= MAX8973_CONTROL_CLKADV_TRIP_DISABLED; |
| 609 | } |
| 610 | |
Laxman Dewangan | d2d5437b | 2016-04-13 15:29:45 +0530 | [diff] [blame] | 611 | pdata->junction_temp_warning = MAX77621_TJINT_WARNING_TEMP_140; |
| 612 | ret = of_property_read_u32(np, "junction-warn-millicelsius", &pval); |
| 613 | if (!ret && (pval <= MAX77621_TJINT_WARNING_TEMP_120)) |
| 614 | pdata->junction_temp_warning = MAX77621_TJINT_WARNING_TEMP_120; |
| 615 | |
Laxman Dewangan | c2ffa97 | 2015-04-23 16:10:23 +0530 | [diff] [blame] | 616 | return pdata; |
| 617 | } |
| 618 | |
Laxman Dewangan | 0f7d6ec | 2015-06-09 19:17:53 +0530 | [diff] [blame] | 619 | static const struct of_device_id of_max8973_match_tbl[] = { |
| 620 | { .compatible = "maxim,max8973", .data = (void *)MAX8973, }, |
| 621 | { .compatible = "maxim,max77621", .data = (void *)MAX77621, }, |
| 622 | { }, |
| 623 | }; |
| 624 | MODULE_DEVICE_TABLE(of, of_max8973_match_tbl); |
| 625 | |
Greg Kroah-Hartman | 3d68dfe | 2012-12-21 13:26:06 -0800 | [diff] [blame] | 626 | static int max8973_probe(struct i2c_client *client, |
| 627 | const struct i2c_device_id *id) |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 628 | { |
| 629 | struct max8973_regulator_platform_data *pdata; |
Laxman Dewangan | 69eb098 | 2015-04-23 16:10:24 +0530 | [diff] [blame] | 630 | struct regulator_init_data *ridata; |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 631 | struct regulator_config config = { }; |
| 632 | struct regulator_dev *rdev; |
| 633 | struct max8973_chip *max; |
Laxman Dewangan | c2ffa97 | 2015-04-23 16:10:23 +0530 | [diff] [blame] | 634 | bool pdata_from_dt = false; |
Laxman Dewangan | 0f7d6ec | 2015-06-09 19:17:53 +0530 | [diff] [blame] | 635 | unsigned int chip_id; |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 636 | int ret; |
| 637 | |
Jingoo Han | dff91d0 | 2013-07-30 17:20:47 +0900 | [diff] [blame] | 638 | pdata = dev_get_platdata(&client->dev); |
Guennadi Liakhovetski | 42dc302 | 2013-06-24 12:50:16 +0200 | [diff] [blame] | 639 | |
Laxman Dewangan | c2ffa97 | 2015-04-23 16:10:23 +0530 | [diff] [blame] | 640 | if (!pdata && client->dev.of_node) { |
| 641 | pdata = max8973_parse_dt(&client->dev); |
| 642 | pdata_from_dt = true; |
| 643 | } |
| 644 | |
| 645 | if (!pdata) { |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 646 | dev_err(&client->dev, "No Platform data"); |
| 647 | return -EIO; |
| 648 | } |
| 649 | |
Laxman Dewangan | 69eb098 | 2015-04-23 16:10:24 +0530 | [diff] [blame] | 650 | if ((pdata->dvs_gpio == -EPROBE_DEFER) || |
| 651 | (pdata->enable_gpio == -EPROBE_DEFER)) |
Laxman Dewangan | c2ffa97 | 2015-04-23 16:10:23 +0530 | [diff] [blame] | 652 | return -EPROBE_DEFER; |
| 653 | |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 654 | max = devm_kzalloc(&client->dev, sizeof(*max), GFP_KERNEL); |
Sachin Kamat | 21024de | 2014-02-18 16:11:00 +0530 | [diff] [blame] | 655 | if (!max) |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 656 | return -ENOMEM; |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 657 | |
| 658 | max->regmap = devm_regmap_init_i2c(client, &max8973_regmap_config); |
| 659 | if (IS_ERR(max->regmap)) { |
| 660 | ret = PTR_ERR(max->regmap); |
| 661 | dev_err(&client->dev, "regmap init failed, err %d\n", ret); |
| 662 | return ret; |
| 663 | } |
| 664 | |
Laxman Dewangan | 0f7d6ec | 2015-06-09 19:17:53 +0530 | [diff] [blame] | 665 | if (client->dev.of_node) { |
| 666 | const struct of_device_id *match; |
| 667 | |
| 668 | match = of_match_device(of_match_ptr(of_max8973_match_tbl), |
| 669 | &client->dev); |
| 670 | if (!match) |
| 671 | return -ENODATA; |
| 672 | max->id = (u32)((uintptr_t)match->data); |
| 673 | } else { |
| 674 | max->id = id->driver_data; |
| 675 | } |
| 676 | |
| 677 | ret = regmap_read(max->regmap, MAX8973_CHIPID1, &chip_id); |
| 678 | if (ret < 0) { |
| 679 | dev_err(&client->dev, "register CHIPID1 read failed, %d", ret); |
| 680 | return ret; |
| 681 | } |
| 682 | |
| 683 | dev_info(&client->dev, "CHIP-ID OTP: 0x%02x ID_M: 0x%02x\n", |
| 684 | (chip_id >> 4) & 0xF, (chip_id >> 1) & 0x7); |
| 685 | |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 686 | i2c_set_clientdata(client, max); |
Guennadi Liakhovetski | db892ff | 2013-06-21 08:30:22 +0200 | [diff] [blame] | 687 | max->ops = max8973_dcdc_ops; |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 688 | max->dev = &client->dev; |
| 689 | max->desc.name = id->name; |
| 690 | max->desc.id = 0; |
Guennadi Liakhovetski | db892ff | 2013-06-21 08:30:22 +0200 | [diff] [blame] | 691 | max->desc.ops = &max->ops; |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 692 | max->desc.type = REGULATOR_VOLTAGE; |
| 693 | max->desc.owner = THIS_MODULE; |
| 694 | max->desc.min_uV = MAX8973_MIN_VOLATGE; |
| 695 | max->desc.uV_step = MAX8973_VOLATGE_STEP; |
| 696 | max->desc.n_voltages = MAX8973_BUCK_N_VOLTAGE; |
| 697 | |
Laxman Dewangan | 69eb098 | 2015-04-23 16:10:24 +0530 | [diff] [blame] | 698 | max->dvs_gpio = (pdata->dvs_gpio) ? pdata->dvs_gpio : -EINVAL; |
| 699 | max->enable_gpio = (pdata->enable_gpio) ? pdata->enable_gpio : -EINVAL; |
| 700 | max->enable_external_control = pdata->enable_ext_control; |
| 701 | max->curr_gpio_val = pdata->dvs_def_state; |
| 702 | max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state; |
Laxman Dewangan | d2d5437b | 2016-04-13 15:29:45 +0530 | [diff] [blame] | 703 | max->junction_temp_warning = pdata->junction_temp_warning; |
Laxman Dewangan | 69eb098 | 2015-04-23 16:10:24 +0530 | [diff] [blame] | 704 | |
| 705 | if (gpio_is_valid(max->enable_gpio)) |
| 706 | max->enable_external_control = true; |
| 707 | |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 708 | max->lru_index[0] = max->curr_vout_reg; |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 709 | |
| 710 | if (gpio_is_valid(max->dvs_gpio)) { |
| 711 | int gpio_flags; |
| 712 | int i; |
| 713 | |
| 714 | gpio_flags = (pdata->dvs_def_state) ? |
| 715 | GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; |
| 716 | ret = devm_gpio_request_one(&client->dev, max->dvs_gpio, |
| 717 | gpio_flags, "max8973-dvs"); |
| 718 | if (ret) { |
| 719 | dev_err(&client->dev, |
| 720 | "gpio_request for gpio %d failed, err = %d\n", |
| 721 | max->dvs_gpio, ret); |
| 722 | return ret; |
| 723 | } |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 724 | |
| 725 | /* |
| 726 | * Initialize the lru index with vout_reg id |
| 727 | * The index 0 will be most recently used and |
| 728 | * set with the max->curr_vout_reg */ |
| 729 | for (i = 0; i < MAX8973_MAX_VOUT_REG; ++i) |
| 730 | max->lru_index[i] = i; |
| 731 | max->lru_index[0] = max->curr_vout_reg; |
| 732 | max->lru_index[max->curr_vout_reg] = 0; |
Mikko Perttunen | b10c7f3 | 2015-07-28 11:34:11 +0300 | [diff] [blame] | 733 | } else { |
| 734 | /* |
| 735 | * If there is no DVS GPIO, the VOUT register |
| 736 | * address is fixed. |
| 737 | */ |
| 738 | max->ops.set_voltage_sel = regulator_set_voltage_sel_regmap; |
| 739 | max->ops.get_voltage_sel = regulator_get_voltage_sel_regmap; |
| 740 | max->desc.vsel_reg = max->curr_vout_reg; |
| 741 | max->desc.vsel_mask = MAX8973_VOUT_MASK; |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 742 | } |
| 743 | |
Laxman Dewangan | c2ffa97 | 2015-04-23 16:10:23 +0530 | [diff] [blame] | 744 | if (pdata_from_dt) |
| 745 | pdata->reg_init_data = of_get_regulator_init_data(&client->dev, |
| 746 | client->dev.of_node, &max->desc); |
| 747 | |
Laxman Dewangan | 0f7d6ec | 2015-06-09 19:17:53 +0530 | [diff] [blame] | 748 | ridata = pdata->reg_init_data; |
| 749 | switch (max->id) { |
| 750 | case MAX8973: |
| 751 | if (!pdata->enable_ext_control) { |
| 752 | max->desc.enable_reg = MAX8973_VOUT; |
| 753 | max->desc.enable_mask = MAX8973_VOUT_ENABLE; |
| 754 | max->ops.enable = regulator_enable_regmap; |
| 755 | max->ops.disable = regulator_disable_regmap; |
| 756 | max->ops.is_enabled = regulator_is_enabled_regmap; |
| 757 | break; |
| 758 | } |
| 759 | |
| 760 | if (gpio_is_valid(max->enable_gpio)) { |
| 761 | config.ena_gpio_flags = GPIOF_OUT_INIT_LOW; |
| 762 | if (ridata && (ridata->constraints.always_on || |
| 763 | ridata->constraints.boot_on)) |
| 764 | config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH; |
| 765 | config.ena_gpio = max->enable_gpio; |
| 766 | } |
| 767 | break; |
| 768 | |
| 769 | case MAX77621: |
| 770 | if (gpio_is_valid(max->enable_gpio)) { |
| 771 | ret = devm_gpio_request_one(&client->dev, |
| 772 | max->enable_gpio, GPIOF_OUT_INIT_HIGH, |
| 773 | "max8973-en-gpio"); |
| 774 | if (ret) { |
| 775 | dev_err(&client->dev, |
| 776 | "gpio_request for gpio %d failed: %d\n", |
| 777 | max->enable_gpio, ret); |
| 778 | return ret; |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | max->desc.enable_reg = MAX8973_VOUT; |
| 783 | max->desc.enable_mask = MAX8973_VOUT_ENABLE; |
| 784 | max->ops.enable = regulator_enable_regmap; |
| 785 | max->ops.disable = regulator_disable_regmap; |
| 786 | max->ops.is_enabled = regulator_is_enabled_regmap; |
Laxman Dewangan | ffaab99 | 2015-07-01 18:31:44 +0530 | [diff] [blame] | 787 | max->ops.set_current_limit = max8973_set_current_limit; |
| 788 | max->ops.get_current_limit = max8973_get_current_limit; |
Laxman Dewangan | 0f7d6ec | 2015-06-09 19:17:53 +0530 | [diff] [blame] | 789 | break; |
| 790 | default: |
| 791 | break; |
| 792 | } |
| 793 | |
Laxman Dewangan | c2ffa97 | 2015-04-23 16:10:23 +0530 | [diff] [blame] | 794 | ret = max8973_init_dcdc(max, pdata); |
| 795 | if (ret < 0) { |
| 796 | dev_err(max->dev, "Max8973 Init failed, err = %d\n", ret); |
| 797 | return ret; |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | config.dev = &client->dev; |
Laxman Dewangan | c2ffa97 | 2015-04-23 16:10:23 +0530 | [diff] [blame] | 801 | config.init_data = pdata->reg_init_data; |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 802 | config.driver_data = max; |
| 803 | config.of_node = client->dev.of_node; |
| 804 | config.regmap = max->regmap; |
| 805 | |
| 806 | /* Register the regulators */ |
Sachin Kamat | 8d581fd | 2013-09-04 11:08:00 +0530 | [diff] [blame] | 807 | rdev = devm_regulator_register(&client->dev, &max->desc, &config); |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 808 | if (IS_ERR(rdev)) { |
| 809 | ret = PTR_ERR(rdev); |
| 810 | dev_err(max->dev, "regulator register failed, err %d\n", ret); |
| 811 | return ret; |
| 812 | } |
| 813 | |
Laxman Dewangan | d2d5437b | 2016-04-13 15:29:45 +0530 | [diff] [blame] | 814 | max8973_thermal_init(max); |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 815 | return 0; |
| 816 | } |
| 817 | |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 818 | static const struct i2c_device_id max8973_id[] = { |
Laxman Dewangan | 0f7d6ec | 2015-06-09 19:17:53 +0530 | [diff] [blame] | 819 | {.name = "max8973", .driver_data = MAX8973}, |
| 820 | {.name = "max77621", .driver_data = MAX77621}, |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 821 | {}, |
| 822 | }; |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 823 | MODULE_DEVICE_TABLE(i2c, max8973_id); |
| 824 | |
| 825 | static struct i2c_driver max8973_i2c_driver = { |
| 826 | .driver = { |
| 827 | .name = "max8973", |
Laxman Dewangan | 0f7d6ec | 2015-06-09 19:17:53 +0530 | [diff] [blame] | 828 | .of_match_table = of_max8973_match_tbl, |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 829 | }, |
| 830 | .probe = max8973_probe, |
Laxman Dewangan | 5928f53 | 2012-11-19 06:58:29 +0530 | [diff] [blame] | 831 | .id_table = max8973_id, |
| 832 | }; |
| 833 | |
| 834 | static int __init max8973_init(void) |
| 835 | { |
| 836 | return i2c_add_driver(&max8973_i2c_driver); |
| 837 | } |
| 838 | subsys_initcall(max8973_init); |
| 839 | |
| 840 | static void __exit max8973_cleanup(void) |
| 841 | { |
| 842 | i2c_del_driver(&max8973_i2c_driver); |
| 843 | } |
| 844 | module_exit(max8973_cleanup); |
| 845 | |
| 846 | MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>"); |
| 847 | MODULE_DESCRIPTION("MAX8973 voltage regulator driver"); |
| 848 | MODULE_LICENSE("GPL v2"); |