162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 262306a36Sopenharmony_ci// 362306a36Sopenharmony_ci// max77686.c - Regulator driver for the Maxim 77686 462306a36Sopenharmony_ci// 562306a36Sopenharmony_ci// Copyright (C) 2012 Samsung Electronics 662306a36Sopenharmony_ci// Chiwoong Byun <woong.byun@samsung.com> 762306a36Sopenharmony_ci// Jonghwa Lee <jonghwa3.lee@samsung.com> 862306a36Sopenharmony_ci// 962306a36Sopenharmony_ci// This driver is based on max8997.c 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include <linux/kernel.h> 1262306a36Sopenharmony_ci#include <linux/bug.h> 1362306a36Sopenharmony_ci#include <linux/err.h> 1462306a36Sopenharmony_ci#include <linux/gpio/consumer.h> 1562306a36Sopenharmony_ci#include <linux/slab.h> 1662306a36Sopenharmony_ci#include <linux/platform_device.h> 1762306a36Sopenharmony_ci#include <linux/regulator/driver.h> 1862306a36Sopenharmony_ci#include <linux/regulator/machine.h> 1962306a36Sopenharmony_ci#include <linux/regulator/of_regulator.h> 2062306a36Sopenharmony_ci#include <linux/mfd/max77686.h> 2162306a36Sopenharmony_ci#include <linux/mfd/max77686-private.h> 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci#define MAX77686_LDO_MINUV 800000 2462306a36Sopenharmony_ci#define MAX77686_LDO_UVSTEP 50000 2562306a36Sopenharmony_ci#define MAX77686_LDO_LOW_MINUV 800000 2662306a36Sopenharmony_ci#define MAX77686_LDO_LOW_UVSTEP 25000 2762306a36Sopenharmony_ci#define MAX77686_BUCK_MINUV 750000 2862306a36Sopenharmony_ci#define MAX77686_BUCK_UVSTEP 50000 2962306a36Sopenharmony_ci#define MAX77686_BUCK_ENABLE_TIME 40 /* us */ 3062306a36Sopenharmony_ci#define MAX77686_DVS_ENABLE_TIME 22 /* us */ 3162306a36Sopenharmony_ci#define MAX77686_RAMP_DELAY 100000 /* uV/us */ 3262306a36Sopenharmony_ci#define MAX77686_DVS_RAMP_DELAY 27500 /* uV/us */ 3362306a36Sopenharmony_ci#define MAX77686_DVS_MINUV 600000 3462306a36Sopenharmony_ci#define MAX77686_DVS_UVSTEP 12500 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci/* 3762306a36Sopenharmony_ci * Value for configuring buck[89] and LDO{20,21,22} as GPIO control. 3862306a36Sopenharmony_ci * It is the same as 'off' for other regulators. 3962306a36Sopenharmony_ci */ 4062306a36Sopenharmony_ci#define MAX77686_GPIO_CONTROL 0x0 4162306a36Sopenharmony_ci/* 4262306a36Sopenharmony_ci * Values used for configuring LDOs and bucks. 4362306a36Sopenharmony_ci * Forcing low power mode: LDO1, 3-5, 9, 13, 17-26 4462306a36Sopenharmony_ci */ 4562306a36Sopenharmony_ci#define MAX77686_LDO_LOWPOWER 0x1 4662306a36Sopenharmony_ci/* 4762306a36Sopenharmony_ci * On/off controlled by PWRREQ: 4862306a36Sopenharmony_ci * - LDO2, 6-8, 10-12, 14-16 4962306a36Sopenharmony_ci * - buck[1234] 5062306a36Sopenharmony_ci */ 5162306a36Sopenharmony_ci#define MAX77686_OFF_PWRREQ 0x1 5262306a36Sopenharmony_ci/* Low power mode controlled by PWRREQ: All LDOs */ 5362306a36Sopenharmony_ci#define MAX77686_LDO_LOWPOWER_PWRREQ 0x2 5462306a36Sopenharmony_ci/* Forcing low power mode: buck[234] */ 5562306a36Sopenharmony_ci#define MAX77686_BUCK_LOWPOWER 0x2 5662306a36Sopenharmony_ci#define MAX77686_NORMAL 0x3 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci#define MAX77686_OPMODE_SHIFT 6 5962306a36Sopenharmony_ci#define MAX77686_OPMODE_BUCK234_SHIFT 4 6062306a36Sopenharmony_ci#define MAX77686_OPMODE_MASK 0x3 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci#define MAX77686_VSEL_MASK 0x3F 6362306a36Sopenharmony_ci#define MAX77686_DVS_VSEL_MASK 0xFF 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci#define MAX77686_RAMP_RATE_MASK 0xC0 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci#define MAX77686_REGULATORS MAX77686_REG_MAX 6862306a36Sopenharmony_ci#define MAX77686_LDOS 26 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_cistruct max77686_data { 7162306a36Sopenharmony_ci struct device *dev; 7262306a36Sopenharmony_ci DECLARE_BITMAP(gpio_enabled, MAX77686_REGULATORS); 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci /* Array indexed by regulator id */ 7562306a36Sopenharmony_ci unsigned int opmode[MAX77686_REGULATORS]; 7662306a36Sopenharmony_ci}; 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_cistatic unsigned int max77686_get_opmode_shift(int id) 7962306a36Sopenharmony_ci{ 8062306a36Sopenharmony_ci switch (id) { 8162306a36Sopenharmony_ci case MAX77686_BUCK1: 8262306a36Sopenharmony_ci case MAX77686_BUCK5 ... MAX77686_BUCK9: 8362306a36Sopenharmony_ci return 0; 8462306a36Sopenharmony_ci case MAX77686_BUCK2 ... MAX77686_BUCK4: 8562306a36Sopenharmony_ci return MAX77686_OPMODE_BUCK234_SHIFT; 8662306a36Sopenharmony_ci default: 8762306a36Sopenharmony_ci /* all LDOs */ 8862306a36Sopenharmony_ci return MAX77686_OPMODE_SHIFT; 8962306a36Sopenharmony_ci } 9062306a36Sopenharmony_ci} 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci/* 9362306a36Sopenharmony_ci * When regulator is configured for GPIO control then it 9462306a36Sopenharmony_ci * replaces "normal" mode. Any change from low power mode to normal 9562306a36Sopenharmony_ci * should actually change to GPIO control. 9662306a36Sopenharmony_ci * Map normal mode to proper value for such regulators. 9762306a36Sopenharmony_ci */ 9862306a36Sopenharmony_cistatic unsigned int max77686_map_normal_mode(struct max77686_data *max77686, 9962306a36Sopenharmony_ci int id) 10062306a36Sopenharmony_ci{ 10162306a36Sopenharmony_ci switch (id) { 10262306a36Sopenharmony_ci case MAX77686_BUCK8: 10362306a36Sopenharmony_ci case MAX77686_BUCK9: 10462306a36Sopenharmony_ci case MAX77686_LDO20 ... MAX77686_LDO22: 10562306a36Sopenharmony_ci if (test_bit(id, max77686->gpio_enabled)) 10662306a36Sopenharmony_ci return MAX77686_GPIO_CONTROL; 10762306a36Sopenharmony_ci } 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci return MAX77686_NORMAL; 11062306a36Sopenharmony_ci} 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci/* Some BUCKs and LDOs supports Normal[ON/OFF] mode during suspend */ 11362306a36Sopenharmony_cistatic int max77686_set_suspend_disable(struct regulator_dev *rdev) 11462306a36Sopenharmony_ci{ 11562306a36Sopenharmony_ci unsigned int val, shift; 11662306a36Sopenharmony_ci struct max77686_data *max77686 = rdev_get_drvdata(rdev); 11762306a36Sopenharmony_ci int ret, id = rdev_get_id(rdev); 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci shift = max77686_get_opmode_shift(id); 12062306a36Sopenharmony_ci val = MAX77686_OFF_PWRREQ; 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 12362306a36Sopenharmony_ci rdev->desc->enable_mask, val << shift); 12462306a36Sopenharmony_ci if (ret) 12562306a36Sopenharmony_ci return ret; 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci max77686->opmode[id] = val; 12862306a36Sopenharmony_ci return 0; 12962306a36Sopenharmony_ci} 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci/* Some LDOs supports [LPM/Normal]ON mode during suspend state */ 13262306a36Sopenharmony_cistatic int max77686_set_suspend_mode(struct regulator_dev *rdev, 13362306a36Sopenharmony_ci unsigned int mode) 13462306a36Sopenharmony_ci{ 13562306a36Sopenharmony_ci struct max77686_data *max77686 = rdev_get_drvdata(rdev); 13662306a36Sopenharmony_ci unsigned int val; 13762306a36Sopenharmony_ci int ret, id = rdev_get_id(rdev); 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ci /* BUCK[5-9] doesn't support this feature */ 14062306a36Sopenharmony_ci if (id >= MAX77686_BUCK5) 14162306a36Sopenharmony_ci return 0; 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci switch (mode) { 14462306a36Sopenharmony_ci case REGULATOR_MODE_IDLE: /* ON in LP Mode */ 14562306a36Sopenharmony_ci val = MAX77686_LDO_LOWPOWER_PWRREQ; 14662306a36Sopenharmony_ci break; 14762306a36Sopenharmony_ci case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ 14862306a36Sopenharmony_ci val = max77686_map_normal_mode(max77686, id); 14962306a36Sopenharmony_ci break; 15062306a36Sopenharmony_ci default: 15162306a36Sopenharmony_ci pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n", 15262306a36Sopenharmony_ci rdev->desc->name, mode); 15362306a36Sopenharmony_ci return -EINVAL; 15462306a36Sopenharmony_ci } 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 15762306a36Sopenharmony_ci rdev->desc->enable_mask, 15862306a36Sopenharmony_ci val << MAX77686_OPMODE_SHIFT); 15962306a36Sopenharmony_ci if (ret) 16062306a36Sopenharmony_ci return ret; 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci max77686->opmode[id] = val; 16362306a36Sopenharmony_ci return 0; 16462306a36Sopenharmony_ci} 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_ci/* Some LDOs supports LPM-ON/OFF/Normal-ON mode during suspend state */ 16762306a36Sopenharmony_cistatic int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev, 16862306a36Sopenharmony_ci unsigned int mode) 16962306a36Sopenharmony_ci{ 17062306a36Sopenharmony_ci unsigned int val; 17162306a36Sopenharmony_ci struct max77686_data *max77686 = rdev_get_drvdata(rdev); 17262306a36Sopenharmony_ci int ret, id = rdev_get_id(rdev); 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci switch (mode) { 17562306a36Sopenharmony_ci case REGULATOR_MODE_STANDBY: /* switch off */ 17662306a36Sopenharmony_ci val = MAX77686_OFF_PWRREQ; 17762306a36Sopenharmony_ci break; 17862306a36Sopenharmony_ci case REGULATOR_MODE_IDLE: /* ON in LP Mode */ 17962306a36Sopenharmony_ci val = MAX77686_LDO_LOWPOWER_PWRREQ; 18062306a36Sopenharmony_ci break; 18162306a36Sopenharmony_ci case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ 18262306a36Sopenharmony_ci val = max77686_map_normal_mode(max77686, id); 18362306a36Sopenharmony_ci break; 18462306a36Sopenharmony_ci default: 18562306a36Sopenharmony_ci pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n", 18662306a36Sopenharmony_ci rdev->desc->name, mode); 18762306a36Sopenharmony_ci return -EINVAL; 18862306a36Sopenharmony_ci } 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_ci ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 19162306a36Sopenharmony_ci rdev->desc->enable_mask, 19262306a36Sopenharmony_ci val << MAX77686_OPMODE_SHIFT); 19362306a36Sopenharmony_ci if (ret) 19462306a36Sopenharmony_ci return ret; 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ci max77686->opmode[id] = val; 19762306a36Sopenharmony_ci return 0; 19862306a36Sopenharmony_ci} 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_cistatic int max77686_enable(struct regulator_dev *rdev) 20162306a36Sopenharmony_ci{ 20262306a36Sopenharmony_ci struct max77686_data *max77686 = rdev_get_drvdata(rdev); 20362306a36Sopenharmony_ci unsigned int shift; 20462306a36Sopenharmony_ci int id = rdev_get_id(rdev); 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_ci shift = max77686_get_opmode_shift(id); 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ci if (max77686->opmode[id] == MAX77686_OFF_PWRREQ) 20962306a36Sopenharmony_ci max77686->opmode[id] = max77686_map_normal_mode(max77686, id); 21062306a36Sopenharmony_ci 21162306a36Sopenharmony_ci return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 21262306a36Sopenharmony_ci rdev->desc->enable_mask, 21362306a36Sopenharmony_ci max77686->opmode[id] << shift); 21462306a36Sopenharmony_ci} 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_cistatic int max77686_of_parse_cb(struct device_node *np, 21762306a36Sopenharmony_ci const struct regulator_desc *desc, 21862306a36Sopenharmony_ci struct regulator_config *config) 21962306a36Sopenharmony_ci{ 22062306a36Sopenharmony_ci struct max77686_data *max77686 = config->driver_data; 22162306a36Sopenharmony_ci int ret; 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ci switch (desc->id) { 22462306a36Sopenharmony_ci case MAX77686_BUCK8: 22562306a36Sopenharmony_ci case MAX77686_BUCK9: 22662306a36Sopenharmony_ci case MAX77686_LDO20 ... MAX77686_LDO22: 22762306a36Sopenharmony_ci config->ena_gpiod = fwnode_gpiod_get_index( 22862306a36Sopenharmony_ci of_fwnode_handle(np), 22962306a36Sopenharmony_ci "maxim,ena", 23062306a36Sopenharmony_ci 0, 23162306a36Sopenharmony_ci GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE, 23262306a36Sopenharmony_ci "max77686-regulator"); 23362306a36Sopenharmony_ci if (IS_ERR(config->ena_gpiod)) 23462306a36Sopenharmony_ci config->ena_gpiod = NULL; 23562306a36Sopenharmony_ci break; 23662306a36Sopenharmony_ci default: 23762306a36Sopenharmony_ci return 0; 23862306a36Sopenharmony_ci } 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_ci if (config->ena_gpiod) { 24162306a36Sopenharmony_ci set_bit(desc->id, max77686->gpio_enabled); 24262306a36Sopenharmony_ci 24362306a36Sopenharmony_ci ret = regmap_update_bits(config->regmap, desc->enable_reg, 24462306a36Sopenharmony_ci desc->enable_mask, 24562306a36Sopenharmony_ci MAX77686_GPIO_CONTROL); 24662306a36Sopenharmony_ci if (ret) { 24762306a36Sopenharmony_ci gpiod_put(config->ena_gpiod); 24862306a36Sopenharmony_ci config->ena_gpiod = NULL; 24962306a36Sopenharmony_ci } 25062306a36Sopenharmony_ci } 25162306a36Sopenharmony_ci 25262306a36Sopenharmony_ci return 0; 25362306a36Sopenharmony_ci} 25462306a36Sopenharmony_ci 25562306a36Sopenharmony_cistatic const unsigned int max77686_buck_dvs_ramp_table[] = { 25662306a36Sopenharmony_ci 13750, 27500, 55000, 100000 25762306a36Sopenharmony_ci}; 25862306a36Sopenharmony_ci 25962306a36Sopenharmony_cistatic const struct regulator_ops max77686_ops = { 26062306a36Sopenharmony_ci .list_voltage = regulator_list_voltage_linear, 26162306a36Sopenharmony_ci .map_voltage = regulator_map_voltage_linear, 26262306a36Sopenharmony_ci .is_enabled = regulator_is_enabled_regmap, 26362306a36Sopenharmony_ci .enable = max77686_enable, 26462306a36Sopenharmony_ci .disable = regulator_disable_regmap, 26562306a36Sopenharmony_ci .get_voltage_sel = regulator_get_voltage_sel_regmap, 26662306a36Sopenharmony_ci .set_voltage_sel = regulator_set_voltage_sel_regmap, 26762306a36Sopenharmony_ci .set_voltage_time_sel = regulator_set_voltage_time_sel, 26862306a36Sopenharmony_ci .set_suspend_mode = max77686_set_suspend_mode, 26962306a36Sopenharmony_ci}; 27062306a36Sopenharmony_ci 27162306a36Sopenharmony_cistatic const struct regulator_ops max77686_ldo_ops = { 27262306a36Sopenharmony_ci .list_voltage = regulator_list_voltage_linear, 27362306a36Sopenharmony_ci .map_voltage = regulator_map_voltage_linear, 27462306a36Sopenharmony_ci .is_enabled = regulator_is_enabled_regmap, 27562306a36Sopenharmony_ci .enable = max77686_enable, 27662306a36Sopenharmony_ci .disable = regulator_disable_regmap, 27762306a36Sopenharmony_ci .get_voltage_sel = regulator_get_voltage_sel_regmap, 27862306a36Sopenharmony_ci .set_voltage_sel = regulator_set_voltage_sel_regmap, 27962306a36Sopenharmony_ci .set_voltage_time_sel = regulator_set_voltage_time_sel, 28062306a36Sopenharmony_ci .set_suspend_mode = max77686_ldo_set_suspend_mode, 28162306a36Sopenharmony_ci .set_suspend_disable = max77686_set_suspend_disable, 28262306a36Sopenharmony_ci}; 28362306a36Sopenharmony_ci 28462306a36Sopenharmony_cistatic const struct regulator_ops max77686_buck1_ops = { 28562306a36Sopenharmony_ci .list_voltage = regulator_list_voltage_linear, 28662306a36Sopenharmony_ci .map_voltage = regulator_map_voltage_linear, 28762306a36Sopenharmony_ci .is_enabled = regulator_is_enabled_regmap, 28862306a36Sopenharmony_ci .enable = max77686_enable, 28962306a36Sopenharmony_ci .disable = regulator_disable_regmap, 29062306a36Sopenharmony_ci .get_voltage_sel = regulator_get_voltage_sel_regmap, 29162306a36Sopenharmony_ci .set_voltage_sel = regulator_set_voltage_sel_regmap, 29262306a36Sopenharmony_ci .set_voltage_time_sel = regulator_set_voltage_time_sel, 29362306a36Sopenharmony_ci .set_suspend_disable = max77686_set_suspend_disable, 29462306a36Sopenharmony_ci}; 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_cistatic const struct regulator_ops max77686_buck_dvs_ops = { 29762306a36Sopenharmony_ci .list_voltage = regulator_list_voltage_linear, 29862306a36Sopenharmony_ci .map_voltage = regulator_map_voltage_linear, 29962306a36Sopenharmony_ci .is_enabled = regulator_is_enabled_regmap, 30062306a36Sopenharmony_ci .enable = max77686_enable, 30162306a36Sopenharmony_ci .disable = regulator_disable_regmap, 30262306a36Sopenharmony_ci .get_voltage_sel = regulator_get_voltage_sel_regmap, 30362306a36Sopenharmony_ci .set_voltage_sel = regulator_set_voltage_sel_regmap, 30462306a36Sopenharmony_ci .set_voltage_time_sel = regulator_set_voltage_time_sel, 30562306a36Sopenharmony_ci .set_ramp_delay = regulator_set_ramp_delay_regmap, 30662306a36Sopenharmony_ci .set_suspend_disable = max77686_set_suspend_disable, 30762306a36Sopenharmony_ci}; 30862306a36Sopenharmony_ci 30962306a36Sopenharmony_ci#define regulator_desc_ldo(num) { \ 31062306a36Sopenharmony_ci .name = "LDO"#num, \ 31162306a36Sopenharmony_ci .of_match = of_match_ptr("LDO"#num), \ 31262306a36Sopenharmony_ci .regulators_node = of_match_ptr("voltage-regulators"), \ 31362306a36Sopenharmony_ci .of_parse_cb = max77686_of_parse_cb, \ 31462306a36Sopenharmony_ci .id = MAX77686_LDO##num, \ 31562306a36Sopenharmony_ci .ops = &max77686_ops, \ 31662306a36Sopenharmony_ci .type = REGULATOR_VOLTAGE, \ 31762306a36Sopenharmony_ci .owner = THIS_MODULE, \ 31862306a36Sopenharmony_ci .min_uV = MAX77686_LDO_MINUV, \ 31962306a36Sopenharmony_ci .uV_step = MAX77686_LDO_UVSTEP, \ 32062306a36Sopenharmony_ci .ramp_delay = MAX77686_RAMP_DELAY, \ 32162306a36Sopenharmony_ci .n_voltages = MAX77686_VSEL_MASK + 1, \ 32262306a36Sopenharmony_ci .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ 32362306a36Sopenharmony_ci .vsel_mask = MAX77686_VSEL_MASK, \ 32462306a36Sopenharmony_ci .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ 32562306a36Sopenharmony_ci .enable_mask = MAX77686_OPMODE_MASK \ 32662306a36Sopenharmony_ci << MAX77686_OPMODE_SHIFT, \ 32762306a36Sopenharmony_ci} 32862306a36Sopenharmony_ci#define regulator_desc_lpm_ldo(num) { \ 32962306a36Sopenharmony_ci .name = "LDO"#num, \ 33062306a36Sopenharmony_ci .of_match = of_match_ptr("LDO"#num), \ 33162306a36Sopenharmony_ci .regulators_node = of_match_ptr("voltage-regulators"), \ 33262306a36Sopenharmony_ci .id = MAX77686_LDO##num, \ 33362306a36Sopenharmony_ci .ops = &max77686_ldo_ops, \ 33462306a36Sopenharmony_ci .type = REGULATOR_VOLTAGE, \ 33562306a36Sopenharmony_ci .owner = THIS_MODULE, \ 33662306a36Sopenharmony_ci .min_uV = MAX77686_LDO_MINUV, \ 33762306a36Sopenharmony_ci .uV_step = MAX77686_LDO_UVSTEP, \ 33862306a36Sopenharmony_ci .ramp_delay = MAX77686_RAMP_DELAY, \ 33962306a36Sopenharmony_ci .n_voltages = MAX77686_VSEL_MASK + 1, \ 34062306a36Sopenharmony_ci .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ 34162306a36Sopenharmony_ci .vsel_mask = MAX77686_VSEL_MASK, \ 34262306a36Sopenharmony_ci .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ 34362306a36Sopenharmony_ci .enable_mask = MAX77686_OPMODE_MASK \ 34462306a36Sopenharmony_ci << MAX77686_OPMODE_SHIFT, \ 34562306a36Sopenharmony_ci} 34662306a36Sopenharmony_ci#define regulator_desc_ldo_low(num) { \ 34762306a36Sopenharmony_ci .name = "LDO"#num, \ 34862306a36Sopenharmony_ci .of_match = of_match_ptr("LDO"#num), \ 34962306a36Sopenharmony_ci .regulators_node = of_match_ptr("voltage-regulators"), \ 35062306a36Sopenharmony_ci .id = MAX77686_LDO##num, \ 35162306a36Sopenharmony_ci .ops = &max77686_ldo_ops, \ 35262306a36Sopenharmony_ci .type = REGULATOR_VOLTAGE, \ 35362306a36Sopenharmony_ci .owner = THIS_MODULE, \ 35462306a36Sopenharmony_ci .min_uV = MAX77686_LDO_LOW_MINUV, \ 35562306a36Sopenharmony_ci .uV_step = MAX77686_LDO_LOW_UVSTEP, \ 35662306a36Sopenharmony_ci .ramp_delay = MAX77686_RAMP_DELAY, \ 35762306a36Sopenharmony_ci .n_voltages = MAX77686_VSEL_MASK + 1, \ 35862306a36Sopenharmony_ci .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ 35962306a36Sopenharmony_ci .vsel_mask = MAX77686_VSEL_MASK, \ 36062306a36Sopenharmony_ci .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ 36162306a36Sopenharmony_ci .enable_mask = MAX77686_OPMODE_MASK \ 36262306a36Sopenharmony_ci << MAX77686_OPMODE_SHIFT, \ 36362306a36Sopenharmony_ci} 36462306a36Sopenharmony_ci#define regulator_desc_ldo1_low(num) { \ 36562306a36Sopenharmony_ci .name = "LDO"#num, \ 36662306a36Sopenharmony_ci .of_match = of_match_ptr("LDO"#num), \ 36762306a36Sopenharmony_ci .regulators_node = of_match_ptr("voltage-regulators"), \ 36862306a36Sopenharmony_ci .id = MAX77686_LDO##num, \ 36962306a36Sopenharmony_ci .ops = &max77686_ops, \ 37062306a36Sopenharmony_ci .type = REGULATOR_VOLTAGE, \ 37162306a36Sopenharmony_ci .owner = THIS_MODULE, \ 37262306a36Sopenharmony_ci .min_uV = MAX77686_LDO_LOW_MINUV, \ 37362306a36Sopenharmony_ci .uV_step = MAX77686_LDO_LOW_UVSTEP, \ 37462306a36Sopenharmony_ci .ramp_delay = MAX77686_RAMP_DELAY, \ 37562306a36Sopenharmony_ci .n_voltages = MAX77686_VSEL_MASK + 1, \ 37662306a36Sopenharmony_ci .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ 37762306a36Sopenharmony_ci .vsel_mask = MAX77686_VSEL_MASK, \ 37862306a36Sopenharmony_ci .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ 37962306a36Sopenharmony_ci .enable_mask = MAX77686_OPMODE_MASK \ 38062306a36Sopenharmony_ci << MAX77686_OPMODE_SHIFT, \ 38162306a36Sopenharmony_ci} 38262306a36Sopenharmony_ci#define regulator_desc_buck(num) { \ 38362306a36Sopenharmony_ci .name = "BUCK"#num, \ 38462306a36Sopenharmony_ci .of_match = of_match_ptr("BUCK"#num), \ 38562306a36Sopenharmony_ci .regulators_node = of_match_ptr("voltage-regulators"), \ 38662306a36Sopenharmony_ci .of_parse_cb = max77686_of_parse_cb, \ 38762306a36Sopenharmony_ci .id = MAX77686_BUCK##num, \ 38862306a36Sopenharmony_ci .ops = &max77686_ops, \ 38962306a36Sopenharmony_ci .type = REGULATOR_VOLTAGE, \ 39062306a36Sopenharmony_ci .owner = THIS_MODULE, \ 39162306a36Sopenharmony_ci .min_uV = MAX77686_BUCK_MINUV, \ 39262306a36Sopenharmony_ci .uV_step = MAX77686_BUCK_UVSTEP, \ 39362306a36Sopenharmony_ci .ramp_delay = MAX77686_RAMP_DELAY, \ 39462306a36Sopenharmony_ci .enable_time = MAX77686_BUCK_ENABLE_TIME, \ 39562306a36Sopenharmony_ci .n_voltages = MAX77686_VSEL_MASK + 1, \ 39662306a36Sopenharmony_ci .vsel_reg = MAX77686_REG_BUCK5OUT + (num - 5) * 2, \ 39762306a36Sopenharmony_ci .vsel_mask = MAX77686_VSEL_MASK, \ 39862306a36Sopenharmony_ci .enable_reg = MAX77686_REG_BUCK5CTRL + (num - 5) * 2, \ 39962306a36Sopenharmony_ci .enable_mask = MAX77686_OPMODE_MASK, \ 40062306a36Sopenharmony_ci} 40162306a36Sopenharmony_ci#define regulator_desc_buck1(num) { \ 40262306a36Sopenharmony_ci .name = "BUCK"#num, \ 40362306a36Sopenharmony_ci .of_match = of_match_ptr("BUCK"#num), \ 40462306a36Sopenharmony_ci .regulators_node = of_match_ptr("voltage-regulators"), \ 40562306a36Sopenharmony_ci .id = MAX77686_BUCK##num, \ 40662306a36Sopenharmony_ci .ops = &max77686_buck1_ops, \ 40762306a36Sopenharmony_ci .type = REGULATOR_VOLTAGE, \ 40862306a36Sopenharmony_ci .owner = THIS_MODULE, \ 40962306a36Sopenharmony_ci .min_uV = MAX77686_BUCK_MINUV, \ 41062306a36Sopenharmony_ci .uV_step = MAX77686_BUCK_UVSTEP, \ 41162306a36Sopenharmony_ci .ramp_delay = MAX77686_RAMP_DELAY, \ 41262306a36Sopenharmony_ci .enable_time = MAX77686_BUCK_ENABLE_TIME, \ 41362306a36Sopenharmony_ci .n_voltages = MAX77686_VSEL_MASK + 1, \ 41462306a36Sopenharmony_ci .vsel_reg = MAX77686_REG_BUCK1OUT, \ 41562306a36Sopenharmony_ci .vsel_mask = MAX77686_VSEL_MASK, \ 41662306a36Sopenharmony_ci .enable_reg = MAX77686_REG_BUCK1CTRL, \ 41762306a36Sopenharmony_ci .enable_mask = MAX77686_OPMODE_MASK, \ 41862306a36Sopenharmony_ci} 41962306a36Sopenharmony_ci#define regulator_desc_buck_dvs(num) { \ 42062306a36Sopenharmony_ci .name = "BUCK"#num, \ 42162306a36Sopenharmony_ci .of_match = of_match_ptr("BUCK"#num), \ 42262306a36Sopenharmony_ci .regulators_node = of_match_ptr("voltage-regulators"), \ 42362306a36Sopenharmony_ci .id = MAX77686_BUCK##num, \ 42462306a36Sopenharmony_ci .ops = &max77686_buck_dvs_ops, \ 42562306a36Sopenharmony_ci .type = REGULATOR_VOLTAGE, \ 42662306a36Sopenharmony_ci .owner = THIS_MODULE, \ 42762306a36Sopenharmony_ci .min_uV = MAX77686_DVS_MINUV, \ 42862306a36Sopenharmony_ci .uV_step = MAX77686_DVS_UVSTEP, \ 42962306a36Sopenharmony_ci .ramp_delay = MAX77686_DVS_RAMP_DELAY, \ 43062306a36Sopenharmony_ci .enable_time = MAX77686_DVS_ENABLE_TIME, \ 43162306a36Sopenharmony_ci .n_voltages = MAX77686_DVS_VSEL_MASK + 1, \ 43262306a36Sopenharmony_ci .vsel_reg = MAX77686_REG_BUCK2DVS1 + (num - 2) * 10, \ 43362306a36Sopenharmony_ci .vsel_mask = MAX77686_DVS_VSEL_MASK, \ 43462306a36Sopenharmony_ci .enable_reg = MAX77686_REG_BUCK2CTRL1 + (num - 2) * 10, \ 43562306a36Sopenharmony_ci .enable_mask = MAX77686_OPMODE_MASK \ 43662306a36Sopenharmony_ci << MAX77686_OPMODE_BUCK234_SHIFT, \ 43762306a36Sopenharmony_ci .ramp_reg = MAX77686_REG_BUCK2CTRL1 + (num - 2) * 10, \ 43862306a36Sopenharmony_ci .ramp_mask = MAX77686_RAMP_RATE_MASK, \ 43962306a36Sopenharmony_ci .ramp_delay_table = max77686_buck_dvs_ramp_table, \ 44062306a36Sopenharmony_ci .n_ramp_values = ARRAY_SIZE(max77686_buck_dvs_ramp_table), \ 44162306a36Sopenharmony_ci} 44262306a36Sopenharmony_ci 44362306a36Sopenharmony_cistatic const struct regulator_desc regulators[] = { 44462306a36Sopenharmony_ci regulator_desc_ldo1_low(1), 44562306a36Sopenharmony_ci regulator_desc_ldo_low(2), 44662306a36Sopenharmony_ci regulator_desc_ldo(3), 44762306a36Sopenharmony_ci regulator_desc_ldo(4), 44862306a36Sopenharmony_ci regulator_desc_ldo(5), 44962306a36Sopenharmony_ci regulator_desc_ldo_low(6), 45062306a36Sopenharmony_ci regulator_desc_ldo_low(7), 45162306a36Sopenharmony_ci regulator_desc_ldo_low(8), 45262306a36Sopenharmony_ci regulator_desc_ldo(9), 45362306a36Sopenharmony_ci regulator_desc_lpm_ldo(10), 45462306a36Sopenharmony_ci regulator_desc_lpm_ldo(11), 45562306a36Sopenharmony_ci regulator_desc_lpm_ldo(12), 45662306a36Sopenharmony_ci regulator_desc_ldo(13), 45762306a36Sopenharmony_ci regulator_desc_lpm_ldo(14), 45862306a36Sopenharmony_ci regulator_desc_ldo_low(15), 45962306a36Sopenharmony_ci regulator_desc_lpm_ldo(16), 46062306a36Sopenharmony_ci regulator_desc_ldo(17), 46162306a36Sopenharmony_ci regulator_desc_ldo(18), 46262306a36Sopenharmony_ci regulator_desc_ldo(19), 46362306a36Sopenharmony_ci regulator_desc_ldo(20), 46462306a36Sopenharmony_ci regulator_desc_ldo(21), 46562306a36Sopenharmony_ci regulator_desc_ldo(22), 46662306a36Sopenharmony_ci regulator_desc_ldo(23), 46762306a36Sopenharmony_ci regulator_desc_ldo(24), 46862306a36Sopenharmony_ci regulator_desc_ldo(25), 46962306a36Sopenharmony_ci regulator_desc_ldo(26), 47062306a36Sopenharmony_ci regulator_desc_buck1(1), 47162306a36Sopenharmony_ci regulator_desc_buck_dvs(2), 47262306a36Sopenharmony_ci regulator_desc_buck_dvs(3), 47362306a36Sopenharmony_ci regulator_desc_buck_dvs(4), 47462306a36Sopenharmony_ci regulator_desc_buck(5), 47562306a36Sopenharmony_ci regulator_desc_buck(6), 47662306a36Sopenharmony_ci regulator_desc_buck(7), 47762306a36Sopenharmony_ci regulator_desc_buck(8), 47862306a36Sopenharmony_ci regulator_desc_buck(9), 47962306a36Sopenharmony_ci}; 48062306a36Sopenharmony_ci 48162306a36Sopenharmony_cistatic int max77686_pmic_probe(struct platform_device *pdev) 48262306a36Sopenharmony_ci{ 48362306a36Sopenharmony_ci struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent); 48462306a36Sopenharmony_ci struct max77686_data *max77686; 48562306a36Sopenharmony_ci int i; 48662306a36Sopenharmony_ci struct regulator_config config = { }; 48762306a36Sopenharmony_ci 48862306a36Sopenharmony_ci dev_dbg(&pdev->dev, "%s\n", __func__); 48962306a36Sopenharmony_ci 49062306a36Sopenharmony_ci max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data), 49162306a36Sopenharmony_ci GFP_KERNEL); 49262306a36Sopenharmony_ci if (!max77686) 49362306a36Sopenharmony_ci return -ENOMEM; 49462306a36Sopenharmony_ci 49562306a36Sopenharmony_ci max77686->dev = &pdev->dev; 49662306a36Sopenharmony_ci config.dev = iodev->dev; 49762306a36Sopenharmony_ci config.regmap = iodev->regmap; 49862306a36Sopenharmony_ci config.driver_data = max77686; 49962306a36Sopenharmony_ci platform_set_drvdata(pdev, max77686); 50062306a36Sopenharmony_ci 50162306a36Sopenharmony_ci for (i = 0; i < MAX77686_REGULATORS; i++) { 50262306a36Sopenharmony_ci struct regulator_dev *rdev; 50362306a36Sopenharmony_ci int id = regulators[i].id; 50462306a36Sopenharmony_ci 50562306a36Sopenharmony_ci max77686->opmode[id] = MAX77686_NORMAL; 50662306a36Sopenharmony_ci rdev = devm_regulator_register(&pdev->dev, 50762306a36Sopenharmony_ci ®ulators[i], &config); 50862306a36Sopenharmony_ci if (IS_ERR(rdev)) { 50962306a36Sopenharmony_ci int ret = PTR_ERR(rdev); 51062306a36Sopenharmony_ci dev_err(&pdev->dev, 51162306a36Sopenharmony_ci "regulator init failed for %d: %d\n", i, ret); 51262306a36Sopenharmony_ci return ret; 51362306a36Sopenharmony_ci } 51462306a36Sopenharmony_ci } 51562306a36Sopenharmony_ci 51662306a36Sopenharmony_ci return 0; 51762306a36Sopenharmony_ci} 51862306a36Sopenharmony_ci 51962306a36Sopenharmony_cistatic const struct platform_device_id max77686_pmic_id[] = { 52062306a36Sopenharmony_ci {"max77686-pmic", 0}, 52162306a36Sopenharmony_ci { }, 52262306a36Sopenharmony_ci}; 52362306a36Sopenharmony_ciMODULE_DEVICE_TABLE(platform, max77686_pmic_id); 52462306a36Sopenharmony_ci 52562306a36Sopenharmony_cistatic struct platform_driver max77686_pmic_driver = { 52662306a36Sopenharmony_ci .driver = { 52762306a36Sopenharmony_ci .name = "max77686-pmic", 52862306a36Sopenharmony_ci .probe_type = PROBE_PREFER_ASYNCHRONOUS, 52962306a36Sopenharmony_ci }, 53062306a36Sopenharmony_ci .probe = max77686_pmic_probe, 53162306a36Sopenharmony_ci .id_table = max77686_pmic_id, 53262306a36Sopenharmony_ci}; 53362306a36Sopenharmony_ci 53462306a36Sopenharmony_cimodule_platform_driver(max77686_pmic_driver); 53562306a36Sopenharmony_ci 53662306a36Sopenharmony_ciMODULE_DESCRIPTION("MAXIM 77686 Regulator Driver"); 53762306a36Sopenharmony_ciMODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>"); 53862306a36Sopenharmony_ciMODULE_LICENSE("GPL"); 539