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> 29 #include <linux/of.h> 30 #include <linux/of_device.h> 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> 35 #include <linux/regulator/of_regulator.h> 36 #include <linux/gpio.h> 37 #include <linux/of_gpio.h> 38 #include <linux/i2c.h> 39 #include <linux/slab.h> 40 #include <linux/regmap.h> 41 42 /* Register definitions */ 43 #define MAX8973_VOUT 0x0 44 #define MAX8973_VOUT_DVS 0x1 45 #define MAX8973_CONTROL1 0x2 46 #define MAX8973_CONTROL2 0x3 47 #define MAX8973_CHIPID1 0x4 48 #define MAX8973_CHIPID2 0x5 49 50 #define MAX8973_MAX_VOUT_REG 2 51 52 /* MAX8973_VOUT */ 53 #define MAX8973_VOUT_ENABLE BIT(7) 54 #define MAX8973_VOUT_MASK 0x7F 55 56 /* MAX8973_VOUT_DVS */ 57 #define MAX8973_DVS_VOUT_MASK 0x7F 58 59 /* MAX8973_CONTROL1 */ 60 #define MAX8973_SNS_ENABLE BIT(7) 61 #define MAX8973_FPWM_EN_M BIT(6) 62 #define MAX8973_NFSR_ENABLE BIT(5) 63 #define MAX8973_AD_ENABLE BIT(4) 64 #define MAX8973_BIAS_ENABLE BIT(3) 65 #define MAX8973_FREQSHIFT_9PER BIT(2) 66 67 #define MAX8973_RAMP_12mV_PER_US 0x0 68 #define MAX8973_RAMP_25mV_PER_US 0x1 69 #define MAX8973_RAMP_50mV_PER_US 0x2 70 #define MAX8973_RAMP_200mV_PER_US 0x3 71 #define MAX8973_RAMP_MASK 0x3 72 73 /* MAX8973_CONTROL2 */ 74 #define MAX8973_WDTMR_ENABLE BIT(6) 75 #define MAX8973_DISCH_ENBABLE BIT(5) 76 #define MAX8973_FT_ENABLE BIT(4) 77 78 #define MAX8973_CKKADV_TRIP_DISABLE 0xC 79 #define MAX8973_CKKADV_TRIP_75mV_PER_US 0x0 80 #define MAX8973_CKKADV_TRIP_150mV_PER_US 0x4 81 #define MAX8973_CKKADV_TRIP_75mV_PER_US_HIST_DIS 0x8 82 #define MAX8973_CONTROL_CLKADV_TRIP_MASK 0x00030000 83 84 #define MAX8973_INDUCTOR_MIN_30_PER 0x0 85 #define MAX8973_INDUCTOR_NOMINAL 0x1 86 #define MAX8973_INDUCTOR_PLUS_30_PER 0x2 87 #define MAX8973_INDUCTOR_PLUS_60_PER 0x3 88 #define MAX8973_CONTROL_INDUCTOR_VALUE_MASK 0x00300000 89 90 #define MAX8973_MIN_VOLATGE 606250 91 #define MAX8973_MAX_VOLATGE 1400000 92 #define MAX8973_VOLATGE_STEP 6250 93 #define MAX8973_BUCK_N_VOLTAGE 0x80 94 95 enum device_id { 96 MAX8973, 97 MAX77621 98 }; 99 100 /* Maxim 8973 chip information */ 101 struct max8973_chip { 102 struct device *dev; 103 struct regulator_desc desc; 104 struct regmap *regmap; 105 bool enable_external_control; 106 int enable_gpio; 107 int dvs_gpio; 108 int lru_index[MAX8973_MAX_VOUT_REG]; 109 int curr_vout_val[MAX8973_MAX_VOUT_REG]; 110 int curr_vout_reg; 111 int curr_gpio_val; 112 struct regulator_ops ops; 113 enum device_id id; 114 }; 115 116 /* 117 * find_voltage_set_register: Find new voltage configuration register (VOUT). 118 * The finding of the new VOUT register will be based on the LRU mechanism. 119 * Each VOUT register will have different voltage configured . This 120 * Function will look if any of the VOUT register have requested voltage set 121 * or not. 122 * - If it is already there then it will make that register as most 123 * recently used and return as found so that caller need not to set 124 * the VOUT register but need to set the proper gpios to select this 125 * VOUT register. 126 * - If requested voltage is not found then it will use the least 127 * recently mechanism to get new VOUT register for new configuration 128 * and will return not_found so that caller need to set new VOUT 129 * register and then gpios (both). 130 */ 131 static bool find_voltage_set_register(struct max8973_chip *tps, 132 int req_vsel, int *vout_reg, int *gpio_val) 133 { 134 int i; 135 bool found = false; 136 int new_vout_reg = tps->lru_index[MAX8973_MAX_VOUT_REG - 1]; 137 int found_index = MAX8973_MAX_VOUT_REG - 1; 138 139 for (i = 0; i < MAX8973_MAX_VOUT_REG; ++i) { 140 if (tps->curr_vout_val[tps->lru_index[i]] == req_vsel) { 141 new_vout_reg = tps->lru_index[i]; 142 found_index = i; 143 found = true; 144 goto update_lru_index; 145 } 146 } 147 148 update_lru_index: 149 for (i = found_index; i > 0; i--) 150 tps->lru_index[i] = tps->lru_index[i - 1]; 151 152 tps->lru_index[0] = new_vout_reg; 153 *gpio_val = new_vout_reg; 154 *vout_reg = MAX8973_VOUT + new_vout_reg; 155 return found; 156 } 157 158 static int max8973_dcdc_get_voltage_sel(struct regulator_dev *rdev) 159 { 160 struct max8973_chip *max = rdev_get_drvdata(rdev); 161 unsigned int data; 162 int ret; 163 164 ret = regmap_read(max->regmap, max->curr_vout_reg, &data); 165 if (ret < 0) { 166 dev_err(max->dev, "register %d read failed, err = %d\n", 167 max->curr_vout_reg, ret); 168 return ret; 169 } 170 return data & MAX8973_VOUT_MASK; 171 } 172 173 static int max8973_dcdc_set_voltage_sel(struct regulator_dev *rdev, 174 unsigned vsel) 175 { 176 struct max8973_chip *max = rdev_get_drvdata(rdev); 177 int ret; 178 bool found = false; 179 int vout_reg = max->curr_vout_reg; 180 int gpio_val = max->curr_gpio_val; 181 182 /* 183 * If gpios are available to select the VOUT register then least 184 * recently used register for new configuration. 185 */ 186 if (gpio_is_valid(max->dvs_gpio)) 187 found = find_voltage_set_register(max, vsel, 188 &vout_reg, &gpio_val); 189 190 if (!found) { 191 ret = regmap_update_bits(max->regmap, vout_reg, 192 MAX8973_VOUT_MASK, vsel); 193 if (ret < 0) { 194 dev_err(max->dev, "register %d update failed, err %d\n", 195 vout_reg, ret); 196 return ret; 197 } 198 max->curr_vout_reg = vout_reg; 199 max->curr_vout_val[gpio_val] = vsel; 200 } 201 202 /* Select proper VOUT register vio gpios */ 203 if (gpio_is_valid(max->dvs_gpio)) { 204 gpio_set_value_cansleep(max->dvs_gpio, gpio_val & 0x1); 205 max->curr_gpio_val = gpio_val; 206 } 207 return 0; 208 } 209 210 static int max8973_dcdc_set_mode(struct regulator_dev *rdev, unsigned int mode) 211 { 212 struct max8973_chip *max = rdev_get_drvdata(rdev); 213 int ret; 214 int pwm; 215 216 /* Enable force PWM mode in FAST mode only. */ 217 switch (mode) { 218 case REGULATOR_MODE_FAST: 219 pwm = MAX8973_FPWM_EN_M; 220 break; 221 222 case REGULATOR_MODE_NORMAL: 223 pwm = 0; 224 break; 225 226 default: 227 return -EINVAL; 228 } 229 230 ret = regmap_update_bits(max->regmap, MAX8973_CONTROL1, 231 MAX8973_FPWM_EN_M, pwm); 232 if (ret < 0) 233 dev_err(max->dev, "register %d update failed, err %d\n", 234 MAX8973_CONTROL1, ret); 235 return ret; 236 } 237 238 static unsigned int max8973_dcdc_get_mode(struct regulator_dev *rdev) 239 { 240 struct max8973_chip *max = rdev_get_drvdata(rdev); 241 unsigned int data; 242 int ret; 243 244 ret = regmap_read(max->regmap, MAX8973_CONTROL1, &data); 245 if (ret < 0) { 246 dev_err(max->dev, "register %d read failed, err %d\n", 247 MAX8973_CONTROL1, ret); 248 return ret; 249 } 250 return (data & MAX8973_FPWM_EN_M) ? 251 REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL; 252 } 253 254 static int max8973_set_ramp_delay(struct regulator_dev *rdev, 255 int ramp_delay) 256 { 257 struct max8973_chip *max = rdev_get_drvdata(rdev); 258 unsigned int control; 259 int ret; 260 int ret_val; 261 262 /* Set ramp delay */ 263 if (ramp_delay < 25000) { 264 control = MAX8973_RAMP_12mV_PER_US; 265 ret_val = 12000; 266 } else if (ramp_delay < 50000) { 267 control = MAX8973_RAMP_25mV_PER_US; 268 ret_val = 25000; 269 } else if (ramp_delay < 200000) { 270 control = MAX8973_RAMP_50mV_PER_US; 271 ret_val = 50000; 272 } else { 273 control = MAX8973_RAMP_200mV_PER_US; 274 ret_val = 200000; 275 } 276 277 ret = regmap_update_bits(max->regmap, MAX8973_CONTROL1, 278 MAX8973_RAMP_MASK, control); 279 if (ret < 0) 280 dev_err(max->dev, "register %d update failed, %d", 281 MAX8973_CONTROL1, ret); 282 return ret; 283 } 284 285 static const struct regulator_ops max8973_dcdc_ops = { 286 .get_voltage_sel = max8973_dcdc_get_voltage_sel, 287 .set_voltage_sel = max8973_dcdc_set_voltage_sel, 288 .list_voltage = regulator_list_voltage_linear, 289 .set_mode = max8973_dcdc_set_mode, 290 .get_mode = max8973_dcdc_get_mode, 291 .set_voltage_time_sel = regulator_set_voltage_time_sel, 292 .set_ramp_delay = max8973_set_ramp_delay, 293 }; 294 295 static int max8973_init_dcdc(struct max8973_chip *max, 296 struct max8973_regulator_platform_data *pdata) 297 { 298 int ret; 299 uint8_t control1 = 0; 300 uint8_t control2 = 0; 301 unsigned int data; 302 303 ret = regmap_read(max->regmap, MAX8973_CONTROL1, &data); 304 if (ret < 0) { 305 dev_err(max->dev, "register %d read failed, err = %d", 306 MAX8973_CONTROL1, ret); 307 return ret; 308 } 309 control1 = data & MAX8973_RAMP_MASK; 310 switch (control1) { 311 case MAX8973_RAMP_12mV_PER_US: 312 max->desc.ramp_delay = 12000; 313 break; 314 case MAX8973_RAMP_25mV_PER_US: 315 max->desc.ramp_delay = 25000; 316 break; 317 case MAX8973_RAMP_50mV_PER_US: 318 max->desc.ramp_delay = 50000; 319 break; 320 case MAX8973_RAMP_200mV_PER_US: 321 max->desc.ramp_delay = 200000; 322 break; 323 } 324 325 if (pdata->control_flags & MAX8973_CONTROL_REMOTE_SENSE_ENABLE) 326 control1 |= MAX8973_SNS_ENABLE; 327 328 if (!(pdata->control_flags & MAX8973_CONTROL_FALLING_SLEW_RATE_ENABLE)) 329 control1 |= MAX8973_NFSR_ENABLE; 330 331 if (pdata->control_flags & MAX8973_CONTROL_OUTPUT_ACTIVE_DISCH_ENABLE) 332 control1 |= MAX8973_AD_ENABLE; 333 334 if (pdata->control_flags & MAX8973_CONTROL_BIAS_ENABLE) { 335 control1 |= MAX8973_BIAS_ENABLE; 336 max->desc.enable_time = 20; 337 } else { 338 max->desc.enable_time = 240; 339 } 340 341 if (pdata->control_flags & MAX8973_CONTROL_FREQ_SHIFT_9PER_ENABLE) 342 control1 |= MAX8973_FREQSHIFT_9PER; 343 344 if (!(pdata->control_flags & MAX8973_CONTROL_PULL_DOWN_ENABLE)) 345 control2 |= MAX8973_DISCH_ENBABLE; 346 347 /* Clock advance trip configuration */ 348 switch (pdata->control_flags & MAX8973_CONTROL_CLKADV_TRIP_MASK) { 349 case MAX8973_CONTROL_CLKADV_TRIP_DISABLED: 350 control2 |= MAX8973_CKKADV_TRIP_DISABLE; 351 break; 352 353 case MAX8973_CONTROL_CLKADV_TRIP_75mV_PER_US: 354 control2 |= MAX8973_CKKADV_TRIP_75mV_PER_US; 355 break; 356 357 case MAX8973_CONTROL_CLKADV_TRIP_150mV_PER_US: 358 control2 |= MAX8973_CKKADV_TRIP_150mV_PER_US; 359 break; 360 361 case MAX8973_CONTROL_CLKADV_TRIP_75mV_PER_US_HIST_DIS: 362 control2 |= MAX8973_CKKADV_TRIP_75mV_PER_US_HIST_DIS; 363 break; 364 } 365 366 /* Configure inductor value */ 367 switch (pdata->control_flags & MAX8973_CONTROL_INDUCTOR_VALUE_MASK) { 368 case MAX8973_CONTROL_INDUCTOR_VALUE_NOMINAL: 369 control2 |= MAX8973_INDUCTOR_NOMINAL; 370 break; 371 372 case MAX8973_CONTROL_INDUCTOR_VALUE_MINUS_30_PER: 373 control2 |= MAX8973_INDUCTOR_MIN_30_PER; 374 break; 375 376 case MAX8973_CONTROL_INDUCTOR_VALUE_PLUS_30_PER: 377 control2 |= MAX8973_INDUCTOR_PLUS_30_PER; 378 break; 379 380 case MAX8973_CONTROL_INDUCTOR_VALUE_PLUS_60_PER: 381 control2 |= MAX8973_INDUCTOR_PLUS_60_PER; 382 break; 383 } 384 385 ret = regmap_write(max->regmap, MAX8973_CONTROL1, control1); 386 if (ret < 0) { 387 dev_err(max->dev, "register %d write failed, err = %d", 388 MAX8973_CONTROL1, ret); 389 return ret; 390 } 391 392 ret = regmap_write(max->regmap, MAX8973_CONTROL2, control2); 393 if (ret < 0) { 394 dev_err(max->dev, "register %d write failed, err = %d", 395 MAX8973_CONTROL2, ret); 396 return ret; 397 } 398 399 /* If external control is enabled then disable EN bit */ 400 if (max->enable_external_control && (max->id == MAX8973)) { 401 ret = regmap_update_bits(max->regmap, MAX8973_VOUT, 402 MAX8973_VOUT_ENABLE, 0); 403 if (ret < 0) 404 dev_err(max->dev, "register %d update failed, err = %d", 405 MAX8973_VOUT, ret); 406 } 407 return ret; 408 } 409 410 static const struct regmap_config max8973_regmap_config = { 411 .reg_bits = 8, 412 .val_bits = 8, 413 .max_register = MAX8973_CHIPID2, 414 .cache_type = REGCACHE_RBTREE, 415 }; 416 417 static struct max8973_regulator_platform_data *max8973_parse_dt( 418 struct device *dev) 419 { 420 struct max8973_regulator_platform_data *pdata; 421 struct device_node *np = dev->of_node; 422 int ret; 423 u32 pval; 424 425 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 426 if (!pdata) 427 return NULL; 428 429 pdata->enable_ext_control = of_property_read_bool(np, 430 "maxim,externally-enable"); 431 pdata->enable_gpio = of_get_named_gpio(np, "maxim,enable-gpio", 0); 432 pdata->dvs_gpio = of_get_named_gpio(np, "maxim,dvs-gpio", 0); 433 434 ret = of_property_read_u32(np, "maxim,dvs-default-state", &pval); 435 if (!ret) 436 pdata->dvs_def_state = pval; 437 438 if (of_property_read_bool(np, "maxim,enable-remote-sense")) 439 pdata->control_flags |= MAX8973_CONTROL_REMOTE_SENSE_ENABLE; 440 441 if (of_property_read_bool(np, "maxim,enable-falling-slew-rate")) 442 pdata->control_flags |= 443 MAX8973_CONTROL_FALLING_SLEW_RATE_ENABLE; 444 445 if (of_property_read_bool(np, "maxim,enable-active-discharge")) 446 pdata->control_flags |= 447 MAX8973_CONTROL_OUTPUT_ACTIVE_DISCH_ENABLE; 448 449 if (of_property_read_bool(np, "maxim,enable-frequency-shift")) 450 pdata->control_flags |= MAX8973_CONTROL_FREQ_SHIFT_9PER_ENABLE; 451 452 if (of_property_read_bool(np, "maxim,enable-bias-control")) 453 pdata->control_flags |= MAX8973_CONTROL_BIAS_ENABLE; 454 455 return pdata; 456 } 457 458 static const struct of_device_id of_max8973_match_tbl[] = { 459 { .compatible = "maxim,max8973", .data = (void *)MAX8973, }, 460 { .compatible = "maxim,max77621", .data = (void *)MAX77621, }, 461 { }, 462 }; 463 MODULE_DEVICE_TABLE(of, of_max8973_match_tbl); 464 465 static int max8973_probe(struct i2c_client *client, 466 const struct i2c_device_id *id) 467 { 468 struct max8973_regulator_platform_data *pdata; 469 struct regulator_init_data *ridata; 470 struct regulator_config config = { }; 471 struct regulator_dev *rdev; 472 struct max8973_chip *max; 473 bool pdata_from_dt = false; 474 unsigned int chip_id; 475 int ret; 476 477 pdata = dev_get_platdata(&client->dev); 478 479 if (!pdata && client->dev.of_node) { 480 pdata = max8973_parse_dt(&client->dev); 481 pdata_from_dt = true; 482 } 483 484 if (!pdata) { 485 dev_err(&client->dev, "No Platform data"); 486 return -EIO; 487 } 488 489 if ((pdata->dvs_gpio == -EPROBE_DEFER) || 490 (pdata->enable_gpio == -EPROBE_DEFER)) 491 return -EPROBE_DEFER; 492 493 max = devm_kzalloc(&client->dev, sizeof(*max), GFP_KERNEL); 494 if (!max) 495 return -ENOMEM; 496 497 max->regmap = devm_regmap_init_i2c(client, &max8973_regmap_config); 498 if (IS_ERR(max->regmap)) { 499 ret = PTR_ERR(max->regmap); 500 dev_err(&client->dev, "regmap init failed, err %d\n", ret); 501 return ret; 502 } 503 504 if (client->dev.of_node) { 505 const struct of_device_id *match; 506 507 match = of_match_device(of_match_ptr(of_max8973_match_tbl), 508 &client->dev); 509 if (!match) 510 return -ENODATA; 511 max->id = (u32)((uintptr_t)match->data); 512 } else { 513 max->id = id->driver_data; 514 } 515 516 ret = regmap_read(max->regmap, MAX8973_CHIPID1, &chip_id); 517 if (ret < 0) { 518 dev_err(&client->dev, "register CHIPID1 read failed, %d", ret); 519 return ret; 520 } 521 522 dev_info(&client->dev, "CHIP-ID OTP: 0x%02x ID_M: 0x%02x\n", 523 (chip_id >> 4) & 0xF, (chip_id >> 1) & 0x7); 524 525 i2c_set_clientdata(client, max); 526 max->ops = max8973_dcdc_ops; 527 max->dev = &client->dev; 528 max->desc.name = id->name; 529 max->desc.id = 0; 530 max->desc.ops = &max->ops; 531 max->desc.type = REGULATOR_VOLTAGE; 532 max->desc.owner = THIS_MODULE; 533 max->desc.min_uV = MAX8973_MIN_VOLATGE; 534 max->desc.uV_step = MAX8973_VOLATGE_STEP; 535 max->desc.n_voltages = MAX8973_BUCK_N_VOLTAGE; 536 537 max->dvs_gpio = (pdata->dvs_gpio) ? pdata->dvs_gpio : -EINVAL; 538 max->enable_gpio = (pdata->enable_gpio) ? pdata->enable_gpio : -EINVAL; 539 max->enable_external_control = pdata->enable_ext_control; 540 max->curr_gpio_val = pdata->dvs_def_state; 541 max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state; 542 543 if (gpio_is_valid(max->enable_gpio)) 544 max->enable_external_control = true; 545 546 max->lru_index[0] = max->curr_vout_reg; 547 548 if (gpio_is_valid(max->dvs_gpio)) { 549 int gpio_flags; 550 int i; 551 552 gpio_flags = (pdata->dvs_def_state) ? 553 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; 554 ret = devm_gpio_request_one(&client->dev, max->dvs_gpio, 555 gpio_flags, "max8973-dvs"); 556 if (ret) { 557 dev_err(&client->dev, 558 "gpio_request for gpio %d failed, err = %d\n", 559 max->dvs_gpio, ret); 560 return ret; 561 } 562 563 /* 564 * Initialize the lru index with vout_reg id 565 * The index 0 will be most recently used and 566 * set with the max->curr_vout_reg */ 567 for (i = 0; i < MAX8973_MAX_VOUT_REG; ++i) 568 max->lru_index[i] = i; 569 max->lru_index[0] = max->curr_vout_reg; 570 max->lru_index[max->curr_vout_reg] = 0; 571 } 572 573 if (pdata_from_dt) 574 pdata->reg_init_data = of_get_regulator_init_data(&client->dev, 575 client->dev.of_node, &max->desc); 576 577 ridata = pdata->reg_init_data; 578 switch (max->id) { 579 case MAX8973: 580 if (!pdata->enable_ext_control) { 581 max->desc.enable_reg = MAX8973_VOUT; 582 max->desc.enable_mask = MAX8973_VOUT_ENABLE; 583 max->ops.enable = regulator_enable_regmap; 584 max->ops.disable = regulator_disable_regmap; 585 max->ops.is_enabled = regulator_is_enabled_regmap; 586 break; 587 } 588 589 if (gpio_is_valid(max->enable_gpio)) { 590 config.ena_gpio_flags = GPIOF_OUT_INIT_LOW; 591 if (ridata && (ridata->constraints.always_on || 592 ridata->constraints.boot_on)) 593 config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH; 594 config.ena_gpio = max->enable_gpio; 595 } 596 break; 597 598 case MAX77621: 599 if (gpio_is_valid(max->enable_gpio)) { 600 ret = devm_gpio_request_one(&client->dev, 601 max->enable_gpio, GPIOF_OUT_INIT_HIGH, 602 "max8973-en-gpio"); 603 if (ret) { 604 dev_err(&client->dev, 605 "gpio_request for gpio %d failed: %d\n", 606 max->enable_gpio, ret); 607 return ret; 608 } 609 } 610 611 max->desc.enable_reg = MAX8973_VOUT; 612 max->desc.enable_mask = MAX8973_VOUT_ENABLE; 613 max->ops.enable = regulator_enable_regmap; 614 max->ops.disable = regulator_disable_regmap; 615 max->ops.is_enabled = regulator_is_enabled_regmap; 616 break; 617 default: 618 break; 619 } 620 621 ret = max8973_init_dcdc(max, pdata); 622 if (ret < 0) { 623 dev_err(max->dev, "Max8973 Init failed, err = %d\n", ret); 624 return ret; 625 } 626 627 config.dev = &client->dev; 628 config.init_data = pdata->reg_init_data; 629 config.driver_data = max; 630 config.of_node = client->dev.of_node; 631 config.regmap = max->regmap; 632 633 /* Register the regulators */ 634 rdev = devm_regulator_register(&client->dev, &max->desc, &config); 635 if (IS_ERR(rdev)) { 636 ret = PTR_ERR(rdev); 637 dev_err(max->dev, "regulator register failed, err %d\n", ret); 638 return ret; 639 } 640 641 return 0; 642 } 643 644 static const struct i2c_device_id max8973_id[] = { 645 {.name = "max8973", .driver_data = MAX8973}, 646 {.name = "max77621", .driver_data = MAX77621}, 647 {}, 648 }; 649 MODULE_DEVICE_TABLE(i2c, max8973_id); 650 651 static struct i2c_driver max8973_i2c_driver = { 652 .driver = { 653 .name = "max8973", 654 .of_match_table = of_max8973_match_tbl, 655 .owner = THIS_MODULE, 656 }, 657 .probe = max8973_probe, 658 .id_table = max8973_id, 659 }; 660 661 static int __init max8973_init(void) 662 { 663 return i2c_add_driver(&max8973_i2c_driver); 664 } 665 subsys_initcall(max8973_init); 666 667 static void __exit max8973_cleanup(void) 668 { 669 i2c_del_driver(&max8973_i2c_driver); 670 } 671 module_exit(max8973_cleanup); 672 673 MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>"); 674 MODULE_DESCRIPTION("MAX8973 voltage regulator driver"); 675 MODULE_LICENSE("GPL v2"); 676