18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
28c2ecf20Sopenharmony_ci//
38c2ecf20Sopenharmony_ci// Copyright (c) 2012-2014 Samsung Electronics Co., Ltd
48c2ecf20Sopenharmony_ci//              http://www.samsung.com
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <linux/bug.h>
78c2ecf20Sopenharmony_ci#include <linux/err.h>
88c2ecf20Sopenharmony_ci#include <linux/gpio/consumer.h>
98c2ecf20Sopenharmony_ci#include <linux/slab.h>
108c2ecf20Sopenharmony_ci#include <linux/module.h>
118c2ecf20Sopenharmony_ci#include <linux/of.h>
128c2ecf20Sopenharmony_ci#include <linux/regmap.h>
138c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
148c2ecf20Sopenharmony_ci#include <linux/regulator/driver.h>
158c2ecf20Sopenharmony_ci#include <linux/regulator/machine.h>
168c2ecf20Sopenharmony_ci#include <linux/regulator/of_regulator.h>
178c2ecf20Sopenharmony_ci#include <linux/mfd/samsung/core.h>
188c2ecf20Sopenharmony_ci#include <linux/mfd/samsung/s2mps11.h>
198c2ecf20Sopenharmony_ci#include <linux/mfd/samsung/s2mps13.h>
208c2ecf20Sopenharmony_ci#include <linux/mfd/samsung/s2mps14.h>
218c2ecf20Sopenharmony_ci#include <linux/mfd/samsung/s2mps15.h>
228c2ecf20Sopenharmony_ci#include <linux/mfd/samsung/s2mpu02.h>
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/* The highest number of possible regulators for supported devices. */
258c2ecf20Sopenharmony_ci#define S2MPS_REGULATOR_MAX		S2MPS13_REGULATOR_MAX
268c2ecf20Sopenharmony_cistruct s2mps11_info {
278c2ecf20Sopenharmony_ci	int ramp_delay2;
288c2ecf20Sopenharmony_ci	int ramp_delay34;
298c2ecf20Sopenharmony_ci	int ramp_delay5;
308c2ecf20Sopenharmony_ci	int ramp_delay16;
318c2ecf20Sopenharmony_ci	int ramp_delay7810;
328c2ecf20Sopenharmony_ci	int ramp_delay9;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	enum sec_device_type dev_type;
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	/*
378c2ecf20Sopenharmony_ci	 * One bit for each S2MPS11/S2MPS13/S2MPS14/S2MPU02 regulator whether
388c2ecf20Sopenharmony_ci	 * the suspend mode was enabled.
398c2ecf20Sopenharmony_ci	 */
408c2ecf20Sopenharmony_ci	DECLARE_BITMAP(suspend_state, S2MPS_REGULATOR_MAX);
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	/*
438c2ecf20Sopenharmony_ci	 * Array (size: number of regulators) with GPIO-s for external
448c2ecf20Sopenharmony_ci	 * sleep control.
458c2ecf20Sopenharmony_ci	 */
468c2ecf20Sopenharmony_ci	struct gpio_desc **ext_control_gpiod;
478c2ecf20Sopenharmony_ci};
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistatic int get_ramp_delay(int ramp_delay)
508c2ecf20Sopenharmony_ci{
518c2ecf20Sopenharmony_ci	unsigned char cnt = 0;
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci	ramp_delay /= 6250;
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	while (true) {
568c2ecf20Sopenharmony_ci		ramp_delay = ramp_delay >> 1;
578c2ecf20Sopenharmony_ci		if (ramp_delay == 0)
588c2ecf20Sopenharmony_ci			break;
598c2ecf20Sopenharmony_ci		cnt++;
608c2ecf20Sopenharmony_ci	}
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	if (cnt > 3)
638c2ecf20Sopenharmony_ci		cnt = 3;
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	return cnt;
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistatic int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
698c2ecf20Sopenharmony_ci				   unsigned int old_selector,
708c2ecf20Sopenharmony_ci				   unsigned int new_selector)
718c2ecf20Sopenharmony_ci{
728c2ecf20Sopenharmony_ci	struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
738c2ecf20Sopenharmony_ci	int rdev_id = rdev_get_id(rdev);
748c2ecf20Sopenharmony_ci	unsigned int ramp_delay = 0;
758c2ecf20Sopenharmony_ci	int old_volt, new_volt;
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci	switch (rdev_id) {
788c2ecf20Sopenharmony_ci	case S2MPS11_BUCK2:
798c2ecf20Sopenharmony_ci		ramp_delay = s2mps11->ramp_delay2;
808c2ecf20Sopenharmony_ci		break;
818c2ecf20Sopenharmony_ci	case S2MPS11_BUCK3:
828c2ecf20Sopenharmony_ci	case S2MPS11_BUCK4:
838c2ecf20Sopenharmony_ci		ramp_delay = s2mps11->ramp_delay34;
848c2ecf20Sopenharmony_ci		break;
858c2ecf20Sopenharmony_ci	case S2MPS11_BUCK5:
868c2ecf20Sopenharmony_ci		ramp_delay = s2mps11->ramp_delay5;
878c2ecf20Sopenharmony_ci		break;
888c2ecf20Sopenharmony_ci	case S2MPS11_BUCK6:
898c2ecf20Sopenharmony_ci	case S2MPS11_BUCK1:
908c2ecf20Sopenharmony_ci		ramp_delay = s2mps11->ramp_delay16;
918c2ecf20Sopenharmony_ci		break;
928c2ecf20Sopenharmony_ci	case S2MPS11_BUCK7:
938c2ecf20Sopenharmony_ci	case S2MPS11_BUCK8:
948c2ecf20Sopenharmony_ci	case S2MPS11_BUCK10:
958c2ecf20Sopenharmony_ci		ramp_delay = s2mps11->ramp_delay7810;
968c2ecf20Sopenharmony_ci		break;
978c2ecf20Sopenharmony_ci	case S2MPS11_BUCK9:
988c2ecf20Sopenharmony_ci		ramp_delay = s2mps11->ramp_delay9;
998c2ecf20Sopenharmony_ci	}
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	if (ramp_delay == 0)
1028c2ecf20Sopenharmony_ci		ramp_delay = rdev->desc->ramp_delay;
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci	old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector);
1058c2ecf20Sopenharmony_ci	new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector);
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay);
1088c2ecf20Sopenharmony_ci}
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_cistatic int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
1118c2ecf20Sopenharmony_ci{
1128c2ecf20Sopenharmony_ci	struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
1138c2ecf20Sopenharmony_ci	unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK;
1148c2ecf20Sopenharmony_ci	unsigned int ramp_enable = 1, enable_shift = 0;
1158c2ecf20Sopenharmony_ci	int rdev_id = rdev_get_id(rdev);
1168c2ecf20Sopenharmony_ci	int ret;
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	switch (rdev_id) {
1198c2ecf20Sopenharmony_ci	case S2MPS11_BUCK1:
1208c2ecf20Sopenharmony_ci		if (ramp_delay > s2mps11->ramp_delay16)
1218c2ecf20Sopenharmony_ci			s2mps11->ramp_delay16 = ramp_delay;
1228c2ecf20Sopenharmony_ci		else
1238c2ecf20Sopenharmony_ci			ramp_delay = s2mps11->ramp_delay16;
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci		ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
1268c2ecf20Sopenharmony_ci		break;
1278c2ecf20Sopenharmony_ci	case S2MPS11_BUCK2:
1288c2ecf20Sopenharmony_ci		enable_shift = S2MPS11_BUCK2_RAMP_EN_SHIFT;
1298c2ecf20Sopenharmony_ci		if (!ramp_delay) {
1308c2ecf20Sopenharmony_ci			ramp_enable = 0;
1318c2ecf20Sopenharmony_ci			break;
1328c2ecf20Sopenharmony_ci		}
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci		s2mps11->ramp_delay2 = ramp_delay;
1358c2ecf20Sopenharmony_ci		ramp_shift = S2MPS11_BUCK2_RAMP_SHIFT;
1368c2ecf20Sopenharmony_ci		ramp_reg = S2MPS11_REG_RAMP;
1378c2ecf20Sopenharmony_ci		break;
1388c2ecf20Sopenharmony_ci	case S2MPS11_BUCK3:
1398c2ecf20Sopenharmony_ci		enable_shift = S2MPS11_BUCK3_RAMP_EN_SHIFT;
1408c2ecf20Sopenharmony_ci		if (!ramp_delay) {
1418c2ecf20Sopenharmony_ci			ramp_enable = 0;
1428c2ecf20Sopenharmony_ci			break;
1438c2ecf20Sopenharmony_ci		}
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci		if (ramp_delay > s2mps11->ramp_delay34)
1468c2ecf20Sopenharmony_ci			s2mps11->ramp_delay34 = ramp_delay;
1478c2ecf20Sopenharmony_ci		else
1488c2ecf20Sopenharmony_ci			ramp_delay = s2mps11->ramp_delay34;
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci		ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
1518c2ecf20Sopenharmony_ci		ramp_reg = S2MPS11_REG_RAMP;
1528c2ecf20Sopenharmony_ci		break;
1538c2ecf20Sopenharmony_ci	case S2MPS11_BUCK4:
1548c2ecf20Sopenharmony_ci		enable_shift = S2MPS11_BUCK4_RAMP_EN_SHIFT;
1558c2ecf20Sopenharmony_ci		if (!ramp_delay) {
1568c2ecf20Sopenharmony_ci			ramp_enable = 0;
1578c2ecf20Sopenharmony_ci			break;
1588c2ecf20Sopenharmony_ci		}
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci		if (ramp_delay > s2mps11->ramp_delay34)
1618c2ecf20Sopenharmony_ci			s2mps11->ramp_delay34 = ramp_delay;
1628c2ecf20Sopenharmony_ci		else
1638c2ecf20Sopenharmony_ci			ramp_delay = s2mps11->ramp_delay34;
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci		ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
1668c2ecf20Sopenharmony_ci		ramp_reg = S2MPS11_REG_RAMP;
1678c2ecf20Sopenharmony_ci		break;
1688c2ecf20Sopenharmony_ci	case S2MPS11_BUCK5:
1698c2ecf20Sopenharmony_ci		s2mps11->ramp_delay5 = ramp_delay;
1708c2ecf20Sopenharmony_ci		ramp_shift = S2MPS11_BUCK5_RAMP_SHIFT;
1718c2ecf20Sopenharmony_ci		break;
1728c2ecf20Sopenharmony_ci	case S2MPS11_BUCK6:
1738c2ecf20Sopenharmony_ci		enable_shift = S2MPS11_BUCK6_RAMP_EN_SHIFT;
1748c2ecf20Sopenharmony_ci		if (!ramp_delay) {
1758c2ecf20Sopenharmony_ci			ramp_enable = 0;
1768c2ecf20Sopenharmony_ci			break;
1778c2ecf20Sopenharmony_ci		}
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci		if (ramp_delay > s2mps11->ramp_delay16)
1808c2ecf20Sopenharmony_ci			s2mps11->ramp_delay16 = ramp_delay;
1818c2ecf20Sopenharmony_ci		else
1828c2ecf20Sopenharmony_ci			ramp_delay = s2mps11->ramp_delay16;
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci		ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
1858c2ecf20Sopenharmony_ci		break;
1868c2ecf20Sopenharmony_ci	case S2MPS11_BUCK7:
1878c2ecf20Sopenharmony_ci	case S2MPS11_BUCK8:
1888c2ecf20Sopenharmony_ci	case S2MPS11_BUCK10:
1898c2ecf20Sopenharmony_ci		if (ramp_delay > s2mps11->ramp_delay7810)
1908c2ecf20Sopenharmony_ci			s2mps11->ramp_delay7810 = ramp_delay;
1918c2ecf20Sopenharmony_ci		else
1928c2ecf20Sopenharmony_ci			ramp_delay = s2mps11->ramp_delay7810;
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci		ramp_shift = S2MPS11_BUCK7810_RAMP_SHIFT;
1958c2ecf20Sopenharmony_ci		break;
1968c2ecf20Sopenharmony_ci	case S2MPS11_BUCK9:
1978c2ecf20Sopenharmony_ci		s2mps11->ramp_delay9 = ramp_delay;
1988c2ecf20Sopenharmony_ci		ramp_shift = S2MPS11_BUCK9_RAMP_SHIFT;
1998c2ecf20Sopenharmony_ci		break;
2008c2ecf20Sopenharmony_ci	default:
2018c2ecf20Sopenharmony_ci		return 0;
2028c2ecf20Sopenharmony_ci	}
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci	if (!ramp_enable)
2058c2ecf20Sopenharmony_ci		goto ramp_disable;
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci	/* Ramp delay can be enabled/disabled only for buck[2346] */
2088c2ecf20Sopenharmony_ci	if ((rdev_id >= S2MPS11_BUCK2 && rdev_id <= S2MPS11_BUCK4) ||
2098c2ecf20Sopenharmony_ci	    rdev_id == S2MPS11_BUCK6)  {
2108c2ecf20Sopenharmony_ci		ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
2118c2ecf20Sopenharmony_ci					 1 << enable_shift, 1 << enable_shift);
2128c2ecf20Sopenharmony_ci		if (ret) {
2138c2ecf20Sopenharmony_ci			dev_err(&rdev->dev, "failed to enable ramp rate\n");
2148c2ecf20Sopenharmony_ci			return ret;
2158c2ecf20Sopenharmony_ci		}
2168c2ecf20Sopenharmony_ci	}
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci	ramp_val = get_ramp_delay(ramp_delay);
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci	return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift,
2218c2ecf20Sopenharmony_ci				  ramp_val << ramp_shift);
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ciramp_disable:
2248c2ecf20Sopenharmony_ci	return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
2258c2ecf20Sopenharmony_ci				  1 << enable_shift, 0);
2268c2ecf20Sopenharmony_ci}
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_cistatic int s2mps11_regulator_enable(struct regulator_dev *rdev)
2298c2ecf20Sopenharmony_ci{
2308c2ecf20Sopenharmony_ci	struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
2318c2ecf20Sopenharmony_ci	int rdev_id = rdev_get_id(rdev);
2328c2ecf20Sopenharmony_ci	unsigned int val;
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci	switch (s2mps11->dev_type) {
2358c2ecf20Sopenharmony_ci	case S2MPS11X:
2368c2ecf20Sopenharmony_ci		if (test_bit(rdev_id, s2mps11->suspend_state))
2378c2ecf20Sopenharmony_ci			val = S2MPS14_ENABLE_SUSPEND;
2388c2ecf20Sopenharmony_ci		else
2398c2ecf20Sopenharmony_ci			val = rdev->desc->enable_mask;
2408c2ecf20Sopenharmony_ci		break;
2418c2ecf20Sopenharmony_ci	case S2MPS13X:
2428c2ecf20Sopenharmony_ci	case S2MPS14X:
2438c2ecf20Sopenharmony_ci		if (test_bit(rdev_id, s2mps11->suspend_state))
2448c2ecf20Sopenharmony_ci			val = S2MPS14_ENABLE_SUSPEND;
2458c2ecf20Sopenharmony_ci		else if (s2mps11->ext_control_gpiod[rdev_id])
2468c2ecf20Sopenharmony_ci			val = S2MPS14_ENABLE_EXT_CONTROL;
2478c2ecf20Sopenharmony_ci		else
2488c2ecf20Sopenharmony_ci			val = rdev->desc->enable_mask;
2498c2ecf20Sopenharmony_ci		break;
2508c2ecf20Sopenharmony_ci	case S2MPU02:
2518c2ecf20Sopenharmony_ci		if (test_bit(rdev_id, s2mps11->suspend_state))
2528c2ecf20Sopenharmony_ci			val = S2MPU02_ENABLE_SUSPEND;
2538c2ecf20Sopenharmony_ci		else
2548c2ecf20Sopenharmony_ci			val = rdev->desc->enable_mask;
2558c2ecf20Sopenharmony_ci		break;
2568c2ecf20Sopenharmony_ci	default:
2578c2ecf20Sopenharmony_ci		return -EINVAL;
2588c2ecf20Sopenharmony_ci	}
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci	return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
2618c2ecf20Sopenharmony_ci			rdev->desc->enable_mask, val);
2628c2ecf20Sopenharmony_ci}
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_cistatic int s2mps11_regulator_set_suspend_disable(struct regulator_dev *rdev)
2658c2ecf20Sopenharmony_ci{
2668c2ecf20Sopenharmony_ci	int ret;
2678c2ecf20Sopenharmony_ci	unsigned int val, state;
2688c2ecf20Sopenharmony_ci	struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
2698c2ecf20Sopenharmony_ci	int rdev_id = rdev_get_id(rdev);
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci	/* Below LDO should be always on or does not support suspend mode. */
2728c2ecf20Sopenharmony_ci	switch (s2mps11->dev_type) {
2738c2ecf20Sopenharmony_ci	case S2MPS11X:
2748c2ecf20Sopenharmony_ci		switch (rdev_id) {
2758c2ecf20Sopenharmony_ci		case S2MPS11_LDO2:
2768c2ecf20Sopenharmony_ci		case S2MPS11_LDO36:
2778c2ecf20Sopenharmony_ci		case S2MPS11_LDO37:
2788c2ecf20Sopenharmony_ci		case S2MPS11_LDO38:
2798c2ecf20Sopenharmony_ci			return 0;
2808c2ecf20Sopenharmony_ci		default:
2818c2ecf20Sopenharmony_ci			state = S2MPS14_ENABLE_SUSPEND;
2828c2ecf20Sopenharmony_ci			break;
2838c2ecf20Sopenharmony_ci		}
2848c2ecf20Sopenharmony_ci		break;
2858c2ecf20Sopenharmony_ci	case S2MPS13X:
2868c2ecf20Sopenharmony_ci	case S2MPS14X:
2878c2ecf20Sopenharmony_ci		switch (rdev_id) {
2888c2ecf20Sopenharmony_ci		case S2MPS14_LDO3:
2898c2ecf20Sopenharmony_ci			return 0;
2908c2ecf20Sopenharmony_ci		default:
2918c2ecf20Sopenharmony_ci			state = S2MPS14_ENABLE_SUSPEND;
2928c2ecf20Sopenharmony_ci			break;
2938c2ecf20Sopenharmony_ci		}
2948c2ecf20Sopenharmony_ci		break;
2958c2ecf20Sopenharmony_ci	case S2MPU02:
2968c2ecf20Sopenharmony_ci		switch (rdev_id) {
2978c2ecf20Sopenharmony_ci		case S2MPU02_LDO13:
2988c2ecf20Sopenharmony_ci		case S2MPU02_LDO14:
2998c2ecf20Sopenharmony_ci		case S2MPU02_LDO15:
3008c2ecf20Sopenharmony_ci		case S2MPU02_LDO17:
3018c2ecf20Sopenharmony_ci		case S2MPU02_BUCK7:
3028c2ecf20Sopenharmony_ci			state = S2MPU02_DISABLE_SUSPEND;
3038c2ecf20Sopenharmony_ci			break;
3048c2ecf20Sopenharmony_ci		default:
3058c2ecf20Sopenharmony_ci			state = S2MPU02_ENABLE_SUSPEND;
3068c2ecf20Sopenharmony_ci			break;
3078c2ecf20Sopenharmony_ci		}
3088c2ecf20Sopenharmony_ci		break;
3098c2ecf20Sopenharmony_ci	default:
3108c2ecf20Sopenharmony_ci		return -EINVAL;
3118c2ecf20Sopenharmony_ci	}
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci	ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
3148c2ecf20Sopenharmony_ci	if (ret < 0)
3158c2ecf20Sopenharmony_ci		return ret;
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci	set_bit(rdev_id, s2mps11->suspend_state);
3188c2ecf20Sopenharmony_ci	/*
3198c2ecf20Sopenharmony_ci	 * Don't enable suspend mode if regulator is already disabled because
3208c2ecf20Sopenharmony_ci	 * this would effectively for a short time turn on the regulator after
3218c2ecf20Sopenharmony_ci	 * resuming.
3228c2ecf20Sopenharmony_ci	 * However we still want to toggle the suspend_state bit for regulator
3238c2ecf20Sopenharmony_ci	 * in case if it got enabled before suspending the system.
3248c2ecf20Sopenharmony_ci	 */
3258c2ecf20Sopenharmony_ci	if (!(val & rdev->desc->enable_mask))
3268c2ecf20Sopenharmony_ci		return 0;
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci	return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
3298c2ecf20Sopenharmony_ci				  rdev->desc->enable_mask, state);
3308c2ecf20Sopenharmony_ci}
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_cistatic const struct regulator_ops s2mps11_ldo_ops = {
3338c2ecf20Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear,
3348c2ecf20Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear,
3358c2ecf20Sopenharmony_ci	.is_enabled		= regulator_is_enabled_regmap,
3368c2ecf20Sopenharmony_ci	.enable			= s2mps11_regulator_enable,
3378c2ecf20Sopenharmony_ci	.disable		= regulator_disable_regmap,
3388c2ecf20Sopenharmony_ci	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
3398c2ecf20Sopenharmony_ci	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
3408c2ecf20Sopenharmony_ci	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
3418c2ecf20Sopenharmony_ci	.set_suspend_disable	= s2mps11_regulator_set_suspend_disable,
3428c2ecf20Sopenharmony_ci};
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_cistatic const struct regulator_ops s2mps11_buck_ops = {
3458c2ecf20Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear,
3468c2ecf20Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear,
3478c2ecf20Sopenharmony_ci	.is_enabled		= regulator_is_enabled_regmap,
3488c2ecf20Sopenharmony_ci	.enable			= s2mps11_regulator_enable,
3498c2ecf20Sopenharmony_ci	.disable		= regulator_disable_regmap,
3508c2ecf20Sopenharmony_ci	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
3518c2ecf20Sopenharmony_ci	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
3528c2ecf20Sopenharmony_ci	.set_voltage_time_sel	= s2mps11_regulator_set_voltage_time_sel,
3538c2ecf20Sopenharmony_ci	.set_ramp_delay		= s2mps11_set_ramp_delay,
3548c2ecf20Sopenharmony_ci	.set_suspend_disable	= s2mps11_regulator_set_suspend_disable,
3558c2ecf20Sopenharmony_ci};
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci#define regulator_desc_s2mps11_ldo(num, step) {		\
3588c2ecf20Sopenharmony_ci	.name		= "LDO"#num,			\
3598c2ecf20Sopenharmony_ci	.id		= S2MPS11_LDO##num,		\
3608c2ecf20Sopenharmony_ci	.ops		= &s2mps11_ldo_ops,		\
3618c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,		\
3628c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,			\
3638c2ecf20Sopenharmony_ci	.ramp_delay	= RAMP_DELAY_12_MVUS,		\
3648c2ecf20Sopenharmony_ci	.min_uV		= MIN_800_MV,			\
3658c2ecf20Sopenharmony_ci	.uV_step	= step,				\
3668c2ecf20Sopenharmony_ci	.n_voltages	= S2MPS11_LDO_N_VOLTAGES,	\
3678c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPS11_REG_L1CTRL + num - 1,	\
3688c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPS11_LDO_VSEL_MASK,	\
3698c2ecf20Sopenharmony_ci	.enable_reg	= S2MPS11_REG_L1CTRL + num - 1,	\
3708c2ecf20Sopenharmony_ci	.enable_mask	= S2MPS11_ENABLE_MASK		\
3718c2ecf20Sopenharmony_ci}
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci#define regulator_desc_s2mps11_buck1_4(num) {			\
3748c2ecf20Sopenharmony_ci	.name		= "BUCK"#num,				\
3758c2ecf20Sopenharmony_ci	.id		= S2MPS11_BUCK##num,			\
3768c2ecf20Sopenharmony_ci	.ops		= &s2mps11_buck_ops,			\
3778c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,			\
3788c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,				\
3798c2ecf20Sopenharmony_ci	.min_uV		= MIN_650_MV,				\
3808c2ecf20Sopenharmony_ci	.uV_step	= STEP_6_25_MV,				\
3818c2ecf20Sopenharmony_ci	.linear_min_sel	= 8,					\
3828c2ecf20Sopenharmony_ci	.n_voltages	= S2MPS11_BUCK12346_N_VOLTAGES,		\
3838c2ecf20Sopenharmony_ci	.ramp_delay	= S2MPS11_RAMP_DELAY,			\
3848c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPS11_REG_B1CTRL2 + (num - 1) * 2,	\
3858c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPS11_BUCK_VSEL_MASK,		\
3868c2ecf20Sopenharmony_ci	.enable_reg	= S2MPS11_REG_B1CTRL1 + (num - 1) * 2,	\
3878c2ecf20Sopenharmony_ci	.enable_mask	= S2MPS11_ENABLE_MASK			\
3888c2ecf20Sopenharmony_ci}
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci#define regulator_desc_s2mps11_buck5 {				\
3918c2ecf20Sopenharmony_ci	.name		= "BUCK5",				\
3928c2ecf20Sopenharmony_ci	.id		= S2MPS11_BUCK5,			\
3938c2ecf20Sopenharmony_ci	.ops		= &s2mps11_buck_ops,			\
3948c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,			\
3958c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,				\
3968c2ecf20Sopenharmony_ci	.min_uV		= MIN_650_MV,				\
3978c2ecf20Sopenharmony_ci	.uV_step	= STEP_6_25_MV,				\
3988c2ecf20Sopenharmony_ci	.linear_min_sel	= 8,					\
3998c2ecf20Sopenharmony_ci	.n_voltages	= S2MPS11_BUCK5_N_VOLTAGES,		\
4008c2ecf20Sopenharmony_ci	.ramp_delay	= S2MPS11_RAMP_DELAY,			\
4018c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPS11_REG_B5CTRL2,			\
4028c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPS11_BUCK_VSEL_MASK,		\
4038c2ecf20Sopenharmony_ci	.enable_reg	= S2MPS11_REG_B5CTRL1,			\
4048c2ecf20Sopenharmony_ci	.enable_mask	= S2MPS11_ENABLE_MASK			\
4058c2ecf20Sopenharmony_ci}
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_ci#define regulator_desc_s2mps11_buck67810(num, min, step, min_sel, voltages) {	\
4088c2ecf20Sopenharmony_ci	.name		= "BUCK"#num,				\
4098c2ecf20Sopenharmony_ci	.id		= S2MPS11_BUCK##num,			\
4108c2ecf20Sopenharmony_ci	.ops		= &s2mps11_buck_ops,			\
4118c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,			\
4128c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,				\
4138c2ecf20Sopenharmony_ci	.min_uV		= min,					\
4148c2ecf20Sopenharmony_ci	.uV_step	= step,					\
4158c2ecf20Sopenharmony_ci	.linear_min_sel	= min_sel,				\
4168c2ecf20Sopenharmony_ci	.n_voltages	= voltages,				\
4178c2ecf20Sopenharmony_ci	.ramp_delay	= S2MPS11_RAMP_DELAY,			\
4188c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPS11_REG_B6CTRL2 + (num - 6) * 2,	\
4198c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPS11_BUCK_VSEL_MASK,		\
4208c2ecf20Sopenharmony_ci	.enable_reg	= S2MPS11_REG_B6CTRL1 + (num - 6) * 2,	\
4218c2ecf20Sopenharmony_ci	.enable_mask	= S2MPS11_ENABLE_MASK			\
4228c2ecf20Sopenharmony_ci}
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci#define regulator_desc_s2mps11_buck9 {				\
4258c2ecf20Sopenharmony_ci	.name		= "BUCK9",				\
4268c2ecf20Sopenharmony_ci	.id		= S2MPS11_BUCK9,			\
4278c2ecf20Sopenharmony_ci	.ops		= &s2mps11_buck_ops,			\
4288c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,			\
4298c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,				\
4308c2ecf20Sopenharmony_ci	.min_uV		= MIN_3000_MV,				\
4318c2ecf20Sopenharmony_ci	.uV_step	= STEP_25_MV,				\
4328c2ecf20Sopenharmony_ci	.n_voltages	= S2MPS11_BUCK9_N_VOLTAGES,		\
4338c2ecf20Sopenharmony_ci	.ramp_delay	= S2MPS11_RAMP_DELAY,			\
4348c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPS11_REG_B9CTRL2,			\
4358c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPS11_BUCK9_VSEL_MASK,		\
4368c2ecf20Sopenharmony_ci	.enable_reg	= S2MPS11_REG_B9CTRL1,			\
4378c2ecf20Sopenharmony_ci	.enable_mask	= S2MPS11_ENABLE_MASK			\
4388c2ecf20Sopenharmony_ci}
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_cistatic const struct regulator_desc s2mps11_regulators[] = {
4418c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(1, STEP_25_MV),
4428c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(2, STEP_50_MV),
4438c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(3, STEP_50_MV),
4448c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(4, STEP_50_MV),
4458c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(5, STEP_50_MV),
4468c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(6, STEP_25_MV),
4478c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(7, STEP_50_MV),
4488c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(8, STEP_50_MV),
4498c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(9, STEP_50_MV),
4508c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(10, STEP_50_MV),
4518c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(11, STEP_25_MV),
4528c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(12, STEP_50_MV),
4538c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(13, STEP_50_MV),
4548c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(14, STEP_50_MV),
4558c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(15, STEP_50_MV),
4568c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(16, STEP_50_MV),
4578c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(17, STEP_50_MV),
4588c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(18, STEP_50_MV),
4598c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(19, STEP_50_MV),
4608c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(20, STEP_50_MV),
4618c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(21, STEP_50_MV),
4628c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(22, STEP_25_MV),
4638c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(23, STEP_25_MV),
4648c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(24, STEP_50_MV),
4658c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(25, STEP_50_MV),
4668c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(26, STEP_50_MV),
4678c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(27, STEP_25_MV),
4688c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(28, STEP_50_MV),
4698c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(29, STEP_50_MV),
4708c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(30, STEP_50_MV),
4718c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(31, STEP_50_MV),
4728c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(32, STEP_50_MV),
4738c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(33, STEP_50_MV),
4748c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(34, STEP_50_MV),
4758c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(35, STEP_25_MV),
4768c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(36, STEP_50_MV),
4778c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(37, STEP_50_MV),
4788c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_ldo(38, STEP_50_MV),
4798c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_buck1_4(1),
4808c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_buck1_4(2),
4818c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_buck1_4(3),
4828c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_buck1_4(4),
4838c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_buck5,
4848c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_buck67810(6, MIN_650_MV, STEP_6_25_MV, 8,
4858c2ecf20Sopenharmony_ci					 S2MPS11_BUCK12346_N_VOLTAGES),
4868c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_buck67810(7, MIN_750_MV, STEP_12_5_MV, 0,
4878c2ecf20Sopenharmony_ci					 S2MPS11_BUCK7810_N_VOLTAGES),
4888c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_buck67810(8, MIN_750_MV, STEP_12_5_MV, 0,
4898c2ecf20Sopenharmony_ci					 S2MPS11_BUCK7810_N_VOLTAGES),
4908c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_buck9,
4918c2ecf20Sopenharmony_ci	regulator_desc_s2mps11_buck67810(10, MIN_750_MV, STEP_12_5_MV, 0,
4928c2ecf20Sopenharmony_ci					 S2MPS11_BUCK7810_N_VOLTAGES),
4938c2ecf20Sopenharmony_ci};
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_cistatic const struct regulator_ops s2mps14_reg_ops;
4968c2ecf20Sopenharmony_ci
4978c2ecf20Sopenharmony_ci#define regulator_desc_s2mps13_ldo(num, min, step, min_sel) {	\
4988c2ecf20Sopenharmony_ci	.name		= "LDO"#num,				\
4998c2ecf20Sopenharmony_ci	.id		= S2MPS13_LDO##num,			\
5008c2ecf20Sopenharmony_ci	.ops		= &s2mps14_reg_ops,			\
5018c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,			\
5028c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,				\
5038c2ecf20Sopenharmony_ci	.min_uV		= min,					\
5048c2ecf20Sopenharmony_ci	.uV_step	= step,					\
5058c2ecf20Sopenharmony_ci	.linear_min_sel	= min_sel,				\
5068c2ecf20Sopenharmony_ci	.n_voltages	= S2MPS14_LDO_N_VOLTAGES,		\
5078c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPS13_REG_L1CTRL + num - 1,		\
5088c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPS14_LDO_VSEL_MASK,		\
5098c2ecf20Sopenharmony_ci	.enable_reg	= S2MPS13_REG_L1CTRL + num - 1,		\
5108c2ecf20Sopenharmony_ci	.enable_mask	= S2MPS14_ENABLE_MASK			\
5118c2ecf20Sopenharmony_ci}
5128c2ecf20Sopenharmony_ci
5138c2ecf20Sopenharmony_ci#define regulator_desc_s2mps13_buck(num, min, step, min_sel) {	\
5148c2ecf20Sopenharmony_ci	.name		= "BUCK"#num,				\
5158c2ecf20Sopenharmony_ci	.id		= S2MPS13_BUCK##num,			\
5168c2ecf20Sopenharmony_ci	.ops		= &s2mps14_reg_ops,			\
5178c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,			\
5188c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,				\
5198c2ecf20Sopenharmony_ci	.min_uV		= min,					\
5208c2ecf20Sopenharmony_ci	.uV_step	= step,					\
5218c2ecf20Sopenharmony_ci	.linear_min_sel	= min_sel,				\
5228c2ecf20Sopenharmony_ci	.n_voltages	= S2MPS14_BUCK_N_VOLTAGES,		\
5238c2ecf20Sopenharmony_ci	.ramp_delay	= S2MPS13_BUCK_RAMP_DELAY,		\
5248c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPS13_REG_B1OUT + (num - 1) * 2,	\
5258c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPS14_BUCK_VSEL_MASK,		\
5268c2ecf20Sopenharmony_ci	.enable_reg	= S2MPS13_REG_B1CTRL + (num - 1) * 2,	\
5278c2ecf20Sopenharmony_ci	.enable_mask	= S2MPS14_ENABLE_MASK			\
5288c2ecf20Sopenharmony_ci}
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_ci#define regulator_desc_s2mps13_buck7(num, min, step, min_sel) {	\
5318c2ecf20Sopenharmony_ci	.name		= "BUCK"#num,				\
5328c2ecf20Sopenharmony_ci	.id		= S2MPS13_BUCK##num,			\
5338c2ecf20Sopenharmony_ci	.ops		= &s2mps14_reg_ops,			\
5348c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,			\
5358c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,				\
5368c2ecf20Sopenharmony_ci	.min_uV		= min,					\
5378c2ecf20Sopenharmony_ci	.uV_step	= step,					\
5388c2ecf20Sopenharmony_ci	.linear_min_sel	= min_sel,				\
5398c2ecf20Sopenharmony_ci	.n_voltages	= S2MPS14_BUCK_N_VOLTAGES,		\
5408c2ecf20Sopenharmony_ci	.ramp_delay	= S2MPS13_BUCK_RAMP_DELAY,		\
5418c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPS13_REG_B1OUT + (num) * 2 - 1,	\
5428c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPS14_BUCK_VSEL_MASK,		\
5438c2ecf20Sopenharmony_ci	.enable_reg	= S2MPS13_REG_B1CTRL + (num - 1) * 2,	\
5448c2ecf20Sopenharmony_ci	.enable_mask	= S2MPS14_ENABLE_MASK			\
5458c2ecf20Sopenharmony_ci}
5468c2ecf20Sopenharmony_ci
5478c2ecf20Sopenharmony_ci#define regulator_desc_s2mps13_buck8_10(num, min, step, min_sel) {	\
5488c2ecf20Sopenharmony_ci	.name		= "BUCK"#num,				\
5498c2ecf20Sopenharmony_ci	.id		= S2MPS13_BUCK##num,			\
5508c2ecf20Sopenharmony_ci	.ops		= &s2mps14_reg_ops,			\
5518c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,			\
5528c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,				\
5538c2ecf20Sopenharmony_ci	.min_uV		= min,					\
5548c2ecf20Sopenharmony_ci	.uV_step	= step,					\
5558c2ecf20Sopenharmony_ci	.linear_min_sel	= min_sel,				\
5568c2ecf20Sopenharmony_ci	.n_voltages	= S2MPS14_BUCK_N_VOLTAGES,		\
5578c2ecf20Sopenharmony_ci	.ramp_delay	= S2MPS13_BUCK_RAMP_DELAY,		\
5588c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPS13_REG_B1OUT + (num) * 2 - 1,	\
5598c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPS14_BUCK_VSEL_MASK,		\
5608c2ecf20Sopenharmony_ci	.enable_reg	= S2MPS13_REG_B1CTRL + (num) * 2 - 1,	\
5618c2ecf20Sopenharmony_ci	.enable_mask	= S2MPS14_ENABLE_MASK			\
5628c2ecf20Sopenharmony_ci}
5638c2ecf20Sopenharmony_ci
5648c2ecf20Sopenharmony_cistatic const struct regulator_desc s2mps13_regulators[] = {
5658c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(1,  MIN_800_MV,  STEP_12_5_MV, 0x00),
5668c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(2,  MIN_1400_MV, STEP_50_MV,   0x0C),
5678c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(3,  MIN_1000_MV, STEP_25_MV,   0x08),
5688c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(4,  MIN_800_MV,  STEP_12_5_MV, 0x00),
5698c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(5,  MIN_800_MV,  STEP_12_5_MV, 0x00),
5708c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(6,  MIN_800_MV,  STEP_12_5_MV, 0x00),
5718c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(7,  MIN_1000_MV, STEP_25_MV,   0x08),
5728c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(8,  MIN_1000_MV, STEP_25_MV,   0x08),
5738c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(9,  MIN_1000_MV, STEP_25_MV,   0x08),
5748c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(10, MIN_1400_MV, STEP_50_MV,   0x0C),
5758c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(11, MIN_800_MV,  STEP_25_MV,   0x10),
5768c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(12, MIN_800_MV,  STEP_25_MV,   0x10),
5778c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(13, MIN_800_MV,  STEP_25_MV,   0x10),
5788c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(14, MIN_800_MV,  STEP_12_5_MV, 0x00),
5798c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(15, MIN_800_MV,  STEP_12_5_MV, 0x00),
5808c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(16, MIN_1400_MV, STEP_50_MV,   0x0C),
5818c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(17, MIN_1400_MV, STEP_50_MV,   0x0C),
5828c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(18, MIN_1000_MV, STEP_25_MV,   0x08),
5838c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(19, MIN_1000_MV, STEP_25_MV,   0x08),
5848c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(20, MIN_1400_MV, STEP_50_MV,   0x0C),
5858c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(21, MIN_1000_MV, STEP_25_MV,   0x08),
5868c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(22, MIN_1000_MV, STEP_25_MV,   0x08),
5878c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(23, MIN_800_MV,  STEP_12_5_MV, 0x00),
5888c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(24, MIN_800_MV,  STEP_12_5_MV, 0x00),
5898c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(25, MIN_1400_MV, STEP_50_MV,   0x0C),
5908c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(26, MIN_1400_MV, STEP_50_MV,   0x0C),
5918c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(27, MIN_1400_MV, STEP_50_MV,   0x0C),
5928c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(28, MIN_1000_MV, STEP_25_MV,   0x08),
5938c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(29, MIN_1400_MV, STEP_50_MV,   0x0C),
5948c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(30, MIN_1400_MV, STEP_50_MV,   0x0C),
5958c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(31, MIN_1000_MV, STEP_25_MV,   0x08),
5968c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(32, MIN_1000_MV, STEP_25_MV,   0x08),
5978c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(33, MIN_1400_MV, STEP_50_MV,   0x0C),
5988c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(34, MIN_1000_MV, STEP_25_MV,   0x08),
5998c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(35, MIN_1400_MV, STEP_50_MV,   0x0C),
6008c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(36, MIN_800_MV,  STEP_12_5_MV, 0x00),
6018c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(37, MIN_1000_MV, STEP_25_MV,   0x08),
6028c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(38, MIN_1400_MV, STEP_50_MV,   0x0C),
6038c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(39, MIN_1000_MV, STEP_25_MV,   0x08),
6048c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_ldo(40, MIN_1400_MV, STEP_50_MV,   0x0C),
6058c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_buck(1,  MIN_500_MV,  STEP_6_25_MV, 0x10),
6068c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_buck(2,  MIN_500_MV,  STEP_6_25_MV, 0x10),
6078c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_buck(3,  MIN_500_MV,  STEP_6_25_MV, 0x10),
6088c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_buck(4,  MIN_500_MV,  STEP_6_25_MV, 0x10),
6098c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_buck(5,  MIN_500_MV,  STEP_6_25_MV, 0x10),
6108c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_buck(6,  MIN_500_MV,  STEP_6_25_MV, 0x10),
6118c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_buck7(7,  MIN_500_MV,  STEP_6_25_MV, 0x10),
6128c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_buck8_10(8,  MIN_1000_MV, STEP_12_5_MV, 0x20),
6138c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_buck8_10(9,  MIN_1000_MV, STEP_12_5_MV, 0x20),
6148c2ecf20Sopenharmony_ci	regulator_desc_s2mps13_buck8_10(10, MIN_500_MV,  STEP_6_25_MV, 0x10),
6158c2ecf20Sopenharmony_ci};
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_cistatic const struct regulator_ops s2mps14_reg_ops = {
6188c2ecf20Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear,
6198c2ecf20Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear,
6208c2ecf20Sopenharmony_ci	.is_enabled		= regulator_is_enabled_regmap,
6218c2ecf20Sopenharmony_ci	.enable			= s2mps11_regulator_enable,
6228c2ecf20Sopenharmony_ci	.disable		= regulator_disable_regmap,
6238c2ecf20Sopenharmony_ci	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
6248c2ecf20Sopenharmony_ci	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
6258c2ecf20Sopenharmony_ci	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
6268c2ecf20Sopenharmony_ci	.set_suspend_disable	= s2mps11_regulator_set_suspend_disable,
6278c2ecf20Sopenharmony_ci};
6288c2ecf20Sopenharmony_ci
6298c2ecf20Sopenharmony_ci#define regulator_desc_s2mps14_ldo(num, min, step) {	\
6308c2ecf20Sopenharmony_ci	.name		= "LDO"#num,			\
6318c2ecf20Sopenharmony_ci	.id		= S2MPS14_LDO##num,		\
6328c2ecf20Sopenharmony_ci	.ops		= &s2mps14_reg_ops,		\
6338c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,		\
6348c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,			\
6358c2ecf20Sopenharmony_ci	.min_uV		= min,				\
6368c2ecf20Sopenharmony_ci	.uV_step	= step,				\
6378c2ecf20Sopenharmony_ci	.n_voltages	= S2MPS14_LDO_N_VOLTAGES,	\
6388c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPS14_REG_L1CTRL + num - 1,	\
6398c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPS14_LDO_VSEL_MASK,	\
6408c2ecf20Sopenharmony_ci	.enable_reg	= S2MPS14_REG_L1CTRL + num - 1,	\
6418c2ecf20Sopenharmony_ci	.enable_mask	= S2MPS14_ENABLE_MASK		\
6428c2ecf20Sopenharmony_ci}
6438c2ecf20Sopenharmony_ci
6448c2ecf20Sopenharmony_ci#define regulator_desc_s2mps14_buck(num, min, step, min_sel) {	\
6458c2ecf20Sopenharmony_ci	.name		= "BUCK"#num,				\
6468c2ecf20Sopenharmony_ci	.id		= S2MPS14_BUCK##num,			\
6478c2ecf20Sopenharmony_ci	.ops		= &s2mps14_reg_ops,			\
6488c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,			\
6498c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,				\
6508c2ecf20Sopenharmony_ci	.min_uV		= min,					\
6518c2ecf20Sopenharmony_ci	.uV_step	= step,					\
6528c2ecf20Sopenharmony_ci	.n_voltages	= S2MPS14_BUCK_N_VOLTAGES,		\
6538c2ecf20Sopenharmony_ci	.linear_min_sel = min_sel,				\
6548c2ecf20Sopenharmony_ci	.ramp_delay	= S2MPS14_BUCK_RAMP_DELAY,		\
6558c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPS14_REG_B1CTRL2 + (num - 1) * 2,	\
6568c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPS14_BUCK_VSEL_MASK,		\
6578c2ecf20Sopenharmony_ci	.enable_reg	= S2MPS14_REG_B1CTRL1 + (num - 1) * 2,	\
6588c2ecf20Sopenharmony_ci	.enable_mask	= S2MPS14_ENABLE_MASK			\
6598c2ecf20Sopenharmony_ci}
6608c2ecf20Sopenharmony_ci
6618c2ecf20Sopenharmony_cistatic const struct regulator_desc s2mps14_regulators[] = {
6628c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(1, MIN_800_MV, STEP_12_5_MV),
6638c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(2, MIN_800_MV, STEP_12_5_MV),
6648c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(3, MIN_800_MV, STEP_25_MV),
6658c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(4, MIN_800_MV, STEP_25_MV),
6668c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(5, MIN_800_MV, STEP_12_5_MV),
6678c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(6, MIN_800_MV, STEP_12_5_MV),
6688c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(7, MIN_800_MV, STEP_25_MV),
6698c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(8, MIN_1800_MV, STEP_25_MV),
6708c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(9, MIN_800_MV, STEP_12_5_MV),
6718c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(10, MIN_800_MV, STEP_12_5_MV),
6728c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(11, MIN_800_MV, STEP_25_MV),
6738c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(12, MIN_1800_MV, STEP_25_MV),
6748c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(13, MIN_1800_MV, STEP_25_MV),
6758c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(14, MIN_1800_MV, STEP_25_MV),
6768c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(15, MIN_1800_MV, STEP_25_MV),
6778c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(16, MIN_1800_MV, STEP_25_MV),
6788c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(17, MIN_1800_MV, STEP_25_MV),
6798c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(18, MIN_1800_MV, STEP_25_MV),
6808c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(19, MIN_800_MV, STEP_25_MV),
6818c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(20, MIN_800_MV, STEP_25_MV),
6828c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(21, MIN_800_MV, STEP_25_MV),
6838c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(22, MIN_800_MV, STEP_12_5_MV),
6848c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(23, MIN_800_MV, STEP_25_MV),
6858c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(24, MIN_1800_MV, STEP_25_MV),
6868c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_ldo(25, MIN_1800_MV, STEP_25_MV),
6878c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_buck(1, MIN_600_MV, STEP_6_25_MV,
6888c2ecf20Sopenharmony_ci				    S2MPS14_BUCK1235_START_SEL),
6898c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_buck(2, MIN_600_MV, STEP_6_25_MV,
6908c2ecf20Sopenharmony_ci				    S2MPS14_BUCK1235_START_SEL),
6918c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_buck(3, MIN_600_MV, STEP_6_25_MV,
6928c2ecf20Sopenharmony_ci				    S2MPS14_BUCK1235_START_SEL),
6938c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_buck(4, MIN_1400_MV, STEP_12_5_MV,
6948c2ecf20Sopenharmony_ci				    S2MPS14_BUCK4_START_SEL),
6958c2ecf20Sopenharmony_ci	regulator_desc_s2mps14_buck(5, MIN_600_MV, STEP_6_25_MV,
6968c2ecf20Sopenharmony_ci				    S2MPS14_BUCK1235_START_SEL),
6978c2ecf20Sopenharmony_ci};
6988c2ecf20Sopenharmony_ci
6998c2ecf20Sopenharmony_cistatic const struct regulator_ops s2mps15_reg_ldo_ops = {
7008c2ecf20Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear_range,
7018c2ecf20Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear_range,
7028c2ecf20Sopenharmony_ci	.is_enabled		= regulator_is_enabled_regmap,
7038c2ecf20Sopenharmony_ci	.enable			= regulator_enable_regmap,
7048c2ecf20Sopenharmony_ci	.disable		= regulator_disable_regmap,
7058c2ecf20Sopenharmony_ci	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
7068c2ecf20Sopenharmony_ci	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
7078c2ecf20Sopenharmony_ci};
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_cistatic const struct regulator_ops s2mps15_reg_buck_ops = {
7108c2ecf20Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear_range,
7118c2ecf20Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear_range,
7128c2ecf20Sopenharmony_ci	.is_enabled		= regulator_is_enabled_regmap,
7138c2ecf20Sopenharmony_ci	.enable			= regulator_enable_regmap,
7148c2ecf20Sopenharmony_ci	.disable		= regulator_disable_regmap,
7158c2ecf20Sopenharmony_ci	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
7168c2ecf20Sopenharmony_ci	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
7178c2ecf20Sopenharmony_ci	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
7188c2ecf20Sopenharmony_ci};
7198c2ecf20Sopenharmony_ci
7208c2ecf20Sopenharmony_ci#define regulator_desc_s2mps15_ldo(num, range) {	\
7218c2ecf20Sopenharmony_ci	.name		= "LDO"#num,			\
7228c2ecf20Sopenharmony_ci	.id		= S2MPS15_LDO##num,		\
7238c2ecf20Sopenharmony_ci	.ops		= &s2mps15_reg_ldo_ops,		\
7248c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,		\
7258c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,			\
7268c2ecf20Sopenharmony_ci	.linear_ranges	= range,			\
7278c2ecf20Sopenharmony_ci	.n_linear_ranges = ARRAY_SIZE(range),		\
7288c2ecf20Sopenharmony_ci	.n_voltages	= S2MPS15_LDO_N_VOLTAGES,	\
7298c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPS15_REG_L1CTRL + num - 1,	\
7308c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPS15_LDO_VSEL_MASK,	\
7318c2ecf20Sopenharmony_ci	.enable_reg	= S2MPS15_REG_L1CTRL + num - 1,	\
7328c2ecf20Sopenharmony_ci	.enable_mask	= S2MPS15_ENABLE_MASK		\
7338c2ecf20Sopenharmony_ci}
7348c2ecf20Sopenharmony_ci
7358c2ecf20Sopenharmony_ci#define regulator_desc_s2mps15_buck(num, range) {			\
7368c2ecf20Sopenharmony_ci	.name		= "BUCK"#num,					\
7378c2ecf20Sopenharmony_ci	.id		= S2MPS15_BUCK##num,				\
7388c2ecf20Sopenharmony_ci	.ops		= &s2mps15_reg_buck_ops,			\
7398c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,				\
7408c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,					\
7418c2ecf20Sopenharmony_ci	.linear_ranges	= range,					\
7428c2ecf20Sopenharmony_ci	.n_linear_ranges = ARRAY_SIZE(range),				\
7438c2ecf20Sopenharmony_ci	.ramp_delay	= 12500,					\
7448c2ecf20Sopenharmony_ci	.n_voltages	= S2MPS15_BUCK_N_VOLTAGES,			\
7458c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPS15_REG_B1CTRL2 + ((num - 1) * 2),	\
7468c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPS15_BUCK_VSEL_MASK,			\
7478c2ecf20Sopenharmony_ci	.enable_reg	= S2MPS15_REG_B1CTRL1 + ((num - 1) * 2),	\
7488c2ecf20Sopenharmony_ci	.enable_mask	= S2MPS15_ENABLE_MASK				\
7498c2ecf20Sopenharmony_ci}
7508c2ecf20Sopenharmony_ci
7518c2ecf20Sopenharmony_ci/* voltage range for s2mps15 LDO 3, 5, 15, 16, 18, 20, 23 and 27 */
7528c2ecf20Sopenharmony_cistatic const struct linear_range s2mps15_ldo_voltage_ranges1[] = {
7538c2ecf20Sopenharmony_ci	REGULATOR_LINEAR_RANGE(1000000, 0xc, 0x38, 25000),
7548c2ecf20Sopenharmony_ci};
7558c2ecf20Sopenharmony_ci
7568c2ecf20Sopenharmony_ci/* voltage range for s2mps15 LDO 2, 6, 14, 17, 19, 21, 24 and 25 */
7578c2ecf20Sopenharmony_cistatic const struct linear_range s2mps15_ldo_voltage_ranges2[] = {
7588c2ecf20Sopenharmony_ci	REGULATOR_LINEAR_RANGE(1800000, 0x0, 0x3f, 25000),
7598c2ecf20Sopenharmony_ci};
7608c2ecf20Sopenharmony_ci
7618c2ecf20Sopenharmony_ci/* voltage range for s2mps15 LDO 4, 11, 12, 13, 22 and 26 */
7628c2ecf20Sopenharmony_cistatic const struct linear_range s2mps15_ldo_voltage_ranges3[] = {
7638c2ecf20Sopenharmony_ci	REGULATOR_LINEAR_RANGE(700000, 0x0, 0x34, 12500),
7648c2ecf20Sopenharmony_ci};
7658c2ecf20Sopenharmony_ci
7668c2ecf20Sopenharmony_ci/* voltage range for s2mps15 LDO 7, 8, 9 and 10 */
7678c2ecf20Sopenharmony_cistatic const struct linear_range s2mps15_ldo_voltage_ranges4[] = {
7688c2ecf20Sopenharmony_ci	REGULATOR_LINEAR_RANGE(700000, 0x10, 0x20, 25000),
7698c2ecf20Sopenharmony_ci};
7708c2ecf20Sopenharmony_ci
7718c2ecf20Sopenharmony_ci/* voltage range for s2mps15 LDO 1 */
7728c2ecf20Sopenharmony_cistatic const struct linear_range s2mps15_ldo_voltage_ranges5[] = {
7738c2ecf20Sopenharmony_ci	REGULATOR_LINEAR_RANGE(500000, 0x0, 0x20, 12500),
7748c2ecf20Sopenharmony_ci};
7758c2ecf20Sopenharmony_ci
7768c2ecf20Sopenharmony_ci/* voltage range for s2mps15 BUCK 1, 2, 3, 4, 5, 6 and 7 */
7778c2ecf20Sopenharmony_cistatic const struct linear_range s2mps15_buck_voltage_ranges1[] = {
7788c2ecf20Sopenharmony_ci	REGULATOR_LINEAR_RANGE(500000, 0x20, 0xc0, 6250),
7798c2ecf20Sopenharmony_ci};
7808c2ecf20Sopenharmony_ci
7818c2ecf20Sopenharmony_ci/* voltage range for s2mps15 BUCK 8, 9 and 10 */
7828c2ecf20Sopenharmony_cistatic const struct linear_range s2mps15_buck_voltage_ranges2[] = {
7838c2ecf20Sopenharmony_ci	REGULATOR_LINEAR_RANGE(1000000, 0x20, 0x78, 12500),
7848c2ecf20Sopenharmony_ci};
7858c2ecf20Sopenharmony_ci
7868c2ecf20Sopenharmony_cistatic const struct regulator_desc s2mps15_regulators[] = {
7878c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(1, s2mps15_ldo_voltage_ranges5),
7888c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(2, s2mps15_ldo_voltage_ranges2),
7898c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(3, s2mps15_ldo_voltage_ranges1),
7908c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(4, s2mps15_ldo_voltage_ranges3),
7918c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(5, s2mps15_ldo_voltage_ranges1),
7928c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(6, s2mps15_ldo_voltage_ranges2),
7938c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(7, s2mps15_ldo_voltage_ranges4),
7948c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(8, s2mps15_ldo_voltage_ranges4),
7958c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(9, s2mps15_ldo_voltage_ranges4),
7968c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(10, s2mps15_ldo_voltage_ranges4),
7978c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(11, s2mps15_ldo_voltage_ranges3),
7988c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(12, s2mps15_ldo_voltage_ranges3),
7998c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(13, s2mps15_ldo_voltage_ranges3),
8008c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(14, s2mps15_ldo_voltage_ranges2),
8018c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(15, s2mps15_ldo_voltage_ranges1),
8028c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(16, s2mps15_ldo_voltage_ranges1),
8038c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(17, s2mps15_ldo_voltage_ranges2),
8048c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(18, s2mps15_ldo_voltage_ranges1),
8058c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(19, s2mps15_ldo_voltage_ranges2),
8068c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(20, s2mps15_ldo_voltage_ranges1),
8078c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(21, s2mps15_ldo_voltage_ranges2),
8088c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(22, s2mps15_ldo_voltage_ranges3),
8098c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(23, s2mps15_ldo_voltage_ranges1),
8108c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(24, s2mps15_ldo_voltage_ranges2),
8118c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(25, s2mps15_ldo_voltage_ranges2),
8128c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(26, s2mps15_ldo_voltage_ranges3),
8138c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_ldo(27, s2mps15_ldo_voltage_ranges1),
8148c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_buck(1, s2mps15_buck_voltage_ranges1),
8158c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_buck(2, s2mps15_buck_voltage_ranges1),
8168c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_buck(3, s2mps15_buck_voltage_ranges1),
8178c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_buck(4, s2mps15_buck_voltage_ranges1),
8188c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_buck(5, s2mps15_buck_voltage_ranges1),
8198c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_buck(6, s2mps15_buck_voltage_ranges1),
8208c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_buck(7, s2mps15_buck_voltage_ranges1),
8218c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_buck(8, s2mps15_buck_voltage_ranges2),
8228c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_buck(9, s2mps15_buck_voltage_ranges2),
8238c2ecf20Sopenharmony_ci	regulator_desc_s2mps15_buck(10, s2mps15_buck_voltage_ranges2),
8248c2ecf20Sopenharmony_ci};
8258c2ecf20Sopenharmony_ci
8268c2ecf20Sopenharmony_cistatic int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11,
8278c2ecf20Sopenharmony_ci		struct regulator_dev *rdev)
8288c2ecf20Sopenharmony_ci{
8298c2ecf20Sopenharmony_ci	return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
8308c2ecf20Sopenharmony_ci			rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL);
8318c2ecf20Sopenharmony_ci}
8328c2ecf20Sopenharmony_ci
8338c2ecf20Sopenharmony_cistatic void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
8348c2ecf20Sopenharmony_ci		struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
8358c2ecf20Sopenharmony_ci{
8368c2ecf20Sopenharmony_ci	struct gpio_desc **gpio = s2mps11->ext_control_gpiod;
8378c2ecf20Sopenharmony_ci	unsigned int i;
8388c2ecf20Sopenharmony_ci	unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11,
8398c2ecf20Sopenharmony_ci		S2MPS14_LDO12 };
8408c2ecf20Sopenharmony_ci
8418c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(valid_regulators); i++) {
8428c2ecf20Sopenharmony_ci		unsigned int reg = valid_regulators[i];
8438c2ecf20Sopenharmony_ci
8448c2ecf20Sopenharmony_ci		if (!rdata[reg].init_data || !rdata[reg].of_node)
8458c2ecf20Sopenharmony_ci			continue;
8468c2ecf20Sopenharmony_ci
8478c2ecf20Sopenharmony_ci		gpio[reg] = devm_fwnode_gpiod_get(&pdev->dev,
8488c2ecf20Sopenharmony_ci				of_fwnode_handle(rdata[reg].of_node),
8498c2ecf20Sopenharmony_ci				"samsung,ext-control",
8508c2ecf20Sopenharmony_ci				GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE,
8518c2ecf20Sopenharmony_ci				"s2mps11-regulator");
8528c2ecf20Sopenharmony_ci		if (PTR_ERR(gpio[reg]) == -ENOENT)
8538c2ecf20Sopenharmony_ci			gpio[reg] = NULL;
8548c2ecf20Sopenharmony_ci		else if (IS_ERR(gpio[reg])) {
8558c2ecf20Sopenharmony_ci			dev_err(&pdev->dev, "Failed to get control GPIO for %d/%s\n",
8568c2ecf20Sopenharmony_ci				reg, rdata[reg].name);
8578c2ecf20Sopenharmony_ci			gpio[reg] = NULL;
8588c2ecf20Sopenharmony_ci			continue;
8598c2ecf20Sopenharmony_ci		}
8608c2ecf20Sopenharmony_ci		if (gpio[reg])
8618c2ecf20Sopenharmony_ci			dev_dbg(&pdev->dev, "Using GPIO for ext-control over %d/%s\n",
8628c2ecf20Sopenharmony_ci				reg, rdata[reg].name);
8638c2ecf20Sopenharmony_ci	}
8648c2ecf20Sopenharmony_ci}
8658c2ecf20Sopenharmony_ci
8668c2ecf20Sopenharmony_cistatic int s2mps11_pmic_dt_parse(struct platform_device *pdev,
8678c2ecf20Sopenharmony_ci		struct of_regulator_match *rdata, struct s2mps11_info *s2mps11,
8688c2ecf20Sopenharmony_ci		unsigned int rdev_num)
8698c2ecf20Sopenharmony_ci{
8708c2ecf20Sopenharmony_ci	struct device_node *reg_np;
8718c2ecf20Sopenharmony_ci
8728c2ecf20Sopenharmony_ci	reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
8738c2ecf20Sopenharmony_ci	if (!reg_np) {
8748c2ecf20Sopenharmony_ci		dev_err(&pdev->dev, "could not find regulators sub-node\n");
8758c2ecf20Sopenharmony_ci		return -EINVAL;
8768c2ecf20Sopenharmony_ci	}
8778c2ecf20Sopenharmony_ci
8788c2ecf20Sopenharmony_ci	of_regulator_match(&pdev->dev, reg_np, rdata, rdev_num);
8798c2ecf20Sopenharmony_ci	if (s2mps11->dev_type == S2MPS14X)
8808c2ecf20Sopenharmony_ci		s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11);
8818c2ecf20Sopenharmony_ci
8828c2ecf20Sopenharmony_ci	of_node_put(reg_np);
8838c2ecf20Sopenharmony_ci
8848c2ecf20Sopenharmony_ci	return 0;
8858c2ecf20Sopenharmony_ci}
8868c2ecf20Sopenharmony_ci
8878c2ecf20Sopenharmony_cistatic int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
8888c2ecf20Sopenharmony_ci{
8898c2ecf20Sopenharmony_ci	unsigned int ramp_val, ramp_shift, ramp_reg;
8908c2ecf20Sopenharmony_ci	int rdev_id = rdev_get_id(rdev);
8918c2ecf20Sopenharmony_ci
8928c2ecf20Sopenharmony_ci	switch (rdev_id) {
8938c2ecf20Sopenharmony_ci	case S2MPU02_BUCK1:
8948c2ecf20Sopenharmony_ci		ramp_shift = S2MPU02_BUCK1_RAMP_SHIFT;
8958c2ecf20Sopenharmony_ci		break;
8968c2ecf20Sopenharmony_ci	case S2MPU02_BUCK2:
8978c2ecf20Sopenharmony_ci		ramp_shift = S2MPU02_BUCK2_RAMP_SHIFT;
8988c2ecf20Sopenharmony_ci		break;
8998c2ecf20Sopenharmony_ci	case S2MPU02_BUCK3:
9008c2ecf20Sopenharmony_ci		ramp_shift = S2MPU02_BUCK3_RAMP_SHIFT;
9018c2ecf20Sopenharmony_ci		break;
9028c2ecf20Sopenharmony_ci	case S2MPU02_BUCK4:
9038c2ecf20Sopenharmony_ci		ramp_shift = S2MPU02_BUCK4_RAMP_SHIFT;
9048c2ecf20Sopenharmony_ci		break;
9058c2ecf20Sopenharmony_ci	default:
9068c2ecf20Sopenharmony_ci		return 0;
9078c2ecf20Sopenharmony_ci	}
9088c2ecf20Sopenharmony_ci	ramp_reg = S2MPU02_REG_RAMP1;
9098c2ecf20Sopenharmony_ci	ramp_val = get_ramp_delay(ramp_delay);
9108c2ecf20Sopenharmony_ci
9118c2ecf20Sopenharmony_ci	return regmap_update_bits(rdev->regmap, ramp_reg,
9128c2ecf20Sopenharmony_ci				  S2MPU02_BUCK1234_RAMP_MASK << ramp_shift,
9138c2ecf20Sopenharmony_ci				  ramp_val << ramp_shift);
9148c2ecf20Sopenharmony_ci}
9158c2ecf20Sopenharmony_ci
9168c2ecf20Sopenharmony_cistatic const struct regulator_ops s2mpu02_ldo_ops = {
9178c2ecf20Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear,
9188c2ecf20Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear,
9198c2ecf20Sopenharmony_ci	.is_enabled		= regulator_is_enabled_regmap,
9208c2ecf20Sopenharmony_ci	.enable			= s2mps11_regulator_enable,
9218c2ecf20Sopenharmony_ci	.disable		= regulator_disable_regmap,
9228c2ecf20Sopenharmony_ci	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
9238c2ecf20Sopenharmony_ci	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
9248c2ecf20Sopenharmony_ci	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
9258c2ecf20Sopenharmony_ci	.set_suspend_disable	= s2mps11_regulator_set_suspend_disable,
9268c2ecf20Sopenharmony_ci};
9278c2ecf20Sopenharmony_ci
9288c2ecf20Sopenharmony_cistatic const struct regulator_ops s2mpu02_buck_ops = {
9298c2ecf20Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear,
9308c2ecf20Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear,
9318c2ecf20Sopenharmony_ci	.is_enabled		= regulator_is_enabled_regmap,
9328c2ecf20Sopenharmony_ci	.enable			= s2mps11_regulator_enable,
9338c2ecf20Sopenharmony_ci	.disable		= regulator_disable_regmap,
9348c2ecf20Sopenharmony_ci	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
9358c2ecf20Sopenharmony_ci	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
9368c2ecf20Sopenharmony_ci	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
9378c2ecf20Sopenharmony_ci	.set_suspend_disable	= s2mps11_regulator_set_suspend_disable,
9388c2ecf20Sopenharmony_ci	.set_ramp_delay		= s2mpu02_set_ramp_delay,
9398c2ecf20Sopenharmony_ci};
9408c2ecf20Sopenharmony_ci
9418c2ecf20Sopenharmony_ci#define regulator_desc_s2mpu02_ldo1(num) {		\
9428c2ecf20Sopenharmony_ci	.name		= "LDO"#num,			\
9438c2ecf20Sopenharmony_ci	.id		= S2MPU02_LDO##num,		\
9448c2ecf20Sopenharmony_ci	.ops		= &s2mpu02_ldo_ops,		\
9458c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,		\
9468c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,			\
9478c2ecf20Sopenharmony_ci	.min_uV		= S2MPU02_LDO_MIN_900MV,	\
9488c2ecf20Sopenharmony_ci	.uV_step	= S2MPU02_LDO_STEP_12_5MV,	\
9498c2ecf20Sopenharmony_ci	.linear_min_sel	= S2MPU02_LDO_GROUP1_START_SEL,	\
9508c2ecf20Sopenharmony_ci	.n_voltages	= S2MPU02_LDO_N_VOLTAGES,	\
9518c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPU02_REG_L1CTRL,		\
9528c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPU02_LDO_VSEL_MASK,	\
9538c2ecf20Sopenharmony_ci	.enable_reg	= S2MPU02_REG_L1CTRL,		\
9548c2ecf20Sopenharmony_ci	.enable_mask	= S2MPU02_ENABLE_MASK		\
9558c2ecf20Sopenharmony_ci}
9568c2ecf20Sopenharmony_ci#define regulator_desc_s2mpu02_ldo2(num) {		\
9578c2ecf20Sopenharmony_ci	.name		= "LDO"#num,			\
9588c2ecf20Sopenharmony_ci	.id		= S2MPU02_LDO##num,		\
9598c2ecf20Sopenharmony_ci	.ops		= &s2mpu02_ldo_ops,		\
9608c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,		\
9618c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,			\
9628c2ecf20Sopenharmony_ci	.min_uV		= S2MPU02_LDO_MIN_1050MV,	\
9638c2ecf20Sopenharmony_ci	.uV_step	= S2MPU02_LDO_STEP_25MV,	\
9648c2ecf20Sopenharmony_ci	.linear_min_sel	= S2MPU02_LDO_GROUP2_START_SEL,	\
9658c2ecf20Sopenharmony_ci	.n_voltages	= S2MPU02_LDO_N_VOLTAGES,	\
9668c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPU02_REG_L2CTRL1,		\
9678c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPU02_LDO_VSEL_MASK,	\
9688c2ecf20Sopenharmony_ci	.enable_reg	= S2MPU02_REG_L2CTRL1,		\
9698c2ecf20Sopenharmony_ci	.enable_mask	= S2MPU02_ENABLE_MASK		\
9708c2ecf20Sopenharmony_ci}
9718c2ecf20Sopenharmony_ci#define regulator_desc_s2mpu02_ldo3(num) {		\
9728c2ecf20Sopenharmony_ci	.name		= "LDO"#num,			\
9738c2ecf20Sopenharmony_ci	.id		= S2MPU02_LDO##num,		\
9748c2ecf20Sopenharmony_ci	.ops		= &s2mpu02_ldo_ops,		\
9758c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,		\
9768c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,			\
9778c2ecf20Sopenharmony_ci	.min_uV		= S2MPU02_LDO_MIN_900MV,	\
9788c2ecf20Sopenharmony_ci	.uV_step	= S2MPU02_LDO_STEP_12_5MV,	\
9798c2ecf20Sopenharmony_ci	.linear_min_sel	= S2MPU02_LDO_GROUP1_START_SEL,	\
9808c2ecf20Sopenharmony_ci	.n_voltages	= S2MPU02_LDO_N_VOLTAGES,	\
9818c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPU02_REG_L3CTRL + num - 3,	\
9828c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPU02_LDO_VSEL_MASK,	\
9838c2ecf20Sopenharmony_ci	.enable_reg	= S2MPU02_REG_L3CTRL + num - 3,	\
9848c2ecf20Sopenharmony_ci	.enable_mask	= S2MPU02_ENABLE_MASK		\
9858c2ecf20Sopenharmony_ci}
9868c2ecf20Sopenharmony_ci#define regulator_desc_s2mpu02_ldo4(num) {		\
9878c2ecf20Sopenharmony_ci	.name		= "LDO"#num,			\
9888c2ecf20Sopenharmony_ci	.id		= S2MPU02_LDO##num,		\
9898c2ecf20Sopenharmony_ci	.ops		= &s2mpu02_ldo_ops,		\
9908c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,		\
9918c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,			\
9928c2ecf20Sopenharmony_ci	.min_uV		= S2MPU02_LDO_MIN_1050MV,	\
9938c2ecf20Sopenharmony_ci	.uV_step	= S2MPU02_LDO_STEP_25MV,	\
9948c2ecf20Sopenharmony_ci	.linear_min_sel	= S2MPU02_LDO_GROUP2_START_SEL,	\
9958c2ecf20Sopenharmony_ci	.n_voltages	= S2MPU02_LDO_N_VOLTAGES,	\
9968c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPU02_REG_L3CTRL + num - 3,	\
9978c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPU02_LDO_VSEL_MASK,	\
9988c2ecf20Sopenharmony_ci	.enable_reg	= S2MPU02_REG_L3CTRL + num - 3,	\
9998c2ecf20Sopenharmony_ci	.enable_mask	= S2MPU02_ENABLE_MASK		\
10008c2ecf20Sopenharmony_ci}
10018c2ecf20Sopenharmony_ci#define regulator_desc_s2mpu02_ldo5(num) {		\
10028c2ecf20Sopenharmony_ci	.name		= "LDO"#num,			\
10038c2ecf20Sopenharmony_ci	.id		= S2MPU02_LDO##num,		\
10048c2ecf20Sopenharmony_ci	.ops		= &s2mpu02_ldo_ops,		\
10058c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,		\
10068c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,			\
10078c2ecf20Sopenharmony_ci	.min_uV		= S2MPU02_LDO_MIN_1600MV,	\
10088c2ecf20Sopenharmony_ci	.uV_step	= S2MPU02_LDO_STEP_50MV,	\
10098c2ecf20Sopenharmony_ci	.linear_min_sel	= S2MPU02_LDO_GROUP3_START_SEL,	\
10108c2ecf20Sopenharmony_ci	.n_voltages	= S2MPU02_LDO_N_VOLTAGES,	\
10118c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPU02_REG_L3CTRL + num - 3,	\
10128c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPU02_LDO_VSEL_MASK,	\
10138c2ecf20Sopenharmony_ci	.enable_reg	= S2MPU02_REG_L3CTRL + num - 3,	\
10148c2ecf20Sopenharmony_ci	.enable_mask	= S2MPU02_ENABLE_MASK		\
10158c2ecf20Sopenharmony_ci}
10168c2ecf20Sopenharmony_ci
10178c2ecf20Sopenharmony_ci#define regulator_desc_s2mpu02_buck1234(num) {			\
10188c2ecf20Sopenharmony_ci	.name		= "BUCK"#num,				\
10198c2ecf20Sopenharmony_ci	.id		= S2MPU02_BUCK##num,			\
10208c2ecf20Sopenharmony_ci	.ops		= &s2mpu02_buck_ops,			\
10218c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,			\
10228c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,				\
10238c2ecf20Sopenharmony_ci	.min_uV		= S2MPU02_BUCK1234_MIN_600MV,		\
10248c2ecf20Sopenharmony_ci	.uV_step	= S2MPU02_BUCK1234_STEP_6_25MV,		\
10258c2ecf20Sopenharmony_ci	.n_voltages	= S2MPU02_BUCK_N_VOLTAGES,		\
10268c2ecf20Sopenharmony_ci	.linear_min_sel = S2MPU02_BUCK1234_START_SEL,		\
10278c2ecf20Sopenharmony_ci	.ramp_delay	= S2MPU02_BUCK_RAMP_DELAY,		\
10288c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPU02_REG_B1CTRL2 + (num - 1) * 2,	\
10298c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPU02_BUCK_VSEL_MASK,		\
10308c2ecf20Sopenharmony_ci	.enable_reg	= S2MPU02_REG_B1CTRL1 + (num - 1) * 2,	\
10318c2ecf20Sopenharmony_ci	.enable_mask	= S2MPU02_ENABLE_MASK			\
10328c2ecf20Sopenharmony_ci}
10338c2ecf20Sopenharmony_ci#define regulator_desc_s2mpu02_buck5(num) {			\
10348c2ecf20Sopenharmony_ci	.name		= "BUCK"#num,				\
10358c2ecf20Sopenharmony_ci	.id		= S2MPU02_BUCK##num,			\
10368c2ecf20Sopenharmony_ci	.ops		= &s2mpu02_ldo_ops,			\
10378c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,			\
10388c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,				\
10398c2ecf20Sopenharmony_ci	.min_uV		= S2MPU02_BUCK5_MIN_1081_25MV,		\
10408c2ecf20Sopenharmony_ci	.uV_step	= S2MPU02_BUCK5_STEP_6_25MV,		\
10418c2ecf20Sopenharmony_ci	.n_voltages	= S2MPU02_BUCK_N_VOLTAGES,		\
10428c2ecf20Sopenharmony_ci	.linear_min_sel = S2MPU02_BUCK5_START_SEL,		\
10438c2ecf20Sopenharmony_ci	.ramp_delay	= S2MPU02_BUCK_RAMP_DELAY,		\
10448c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPU02_REG_B5CTRL2,			\
10458c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPU02_BUCK_VSEL_MASK,		\
10468c2ecf20Sopenharmony_ci	.enable_reg	= S2MPU02_REG_B5CTRL1,			\
10478c2ecf20Sopenharmony_ci	.enable_mask	= S2MPU02_ENABLE_MASK			\
10488c2ecf20Sopenharmony_ci}
10498c2ecf20Sopenharmony_ci#define regulator_desc_s2mpu02_buck6(num) {			\
10508c2ecf20Sopenharmony_ci	.name		= "BUCK"#num,				\
10518c2ecf20Sopenharmony_ci	.id		= S2MPU02_BUCK##num,			\
10528c2ecf20Sopenharmony_ci	.ops		= &s2mpu02_ldo_ops,			\
10538c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,			\
10548c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,				\
10558c2ecf20Sopenharmony_ci	.min_uV		= S2MPU02_BUCK6_MIN_1700MV,		\
10568c2ecf20Sopenharmony_ci	.uV_step	= S2MPU02_BUCK6_STEP_2_50MV,		\
10578c2ecf20Sopenharmony_ci	.n_voltages	= S2MPU02_BUCK_N_VOLTAGES,		\
10588c2ecf20Sopenharmony_ci	.linear_min_sel = S2MPU02_BUCK6_START_SEL,		\
10598c2ecf20Sopenharmony_ci	.ramp_delay	= S2MPU02_BUCK_RAMP_DELAY,		\
10608c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPU02_REG_B6CTRL2,			\
10618c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPU02_BUCK_VSEL_MASK,		\
10628c2ecf20Sopenharmony_ci	.enable_reg	= S2MPU02_REG_B6CTRL1,			\
10638c2ecf20Sopenharmony_ci	.enable_mask	= S2MPU02_ENABLE_MASK			\
10648c2ecf20Sopenharmony_ci}
10658c2ecf20Sopenharmony_ci#define regulator_desc_s2mpu02_buck7(num) {			\
10668c2ecf20Sopenharmony_ci	.name		= "BUCK"#num,				\
10678c2ecf20Sopenharmony_ci	.id		= S2MPU02_BUCK##num,			\
10688c2ecf20Sopenharmony_ci	.ops		= &s2mpu02_ldo_ops,			\
10698c2ecf20Sopenharmony_ci	.type		= REGULATOR_VOLTAGE,			\
10708c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,				\
10718c2ecf20Sopenharmony_ci	.min_uV		= S2MPU02_BUCK7_MIN_900MV,		\
10728c2ecf20Sopenharmony_ci	.uV_step	= S2MPU02_BUCK7_STEP_6_25MV,		\
10738c2ecf20Sopenharmony_ci	.n_voltages	= S2MPU02_BUCK_N_VOLTAGES,		\
10748c2ecf20Sopenharmony_ci	.linear_min_sel = S2MPU02_BUCK7_START_SEL,		\
10758c2ecf20Sopenharmony_ci	.ramp_delay	= S2MPU02_BUCK_RAMP_DELAY,		\
10768c2ecf20Sopenharmony_ci	.vsel_reg	= S2MPU02_REG_B7CTRL2,			\
10778c2ecf20Sopenharmony_ci	.vsel_mask	= S2MPU02_BUCK_VSEL_MASK,		\
10788c2ecf20Sopenharmony_ci	.enable_reg	= S2MPU02_REG_B7CTRL1,			\
10798c2ecf20Sopenharmony_ci	.enable_mask	= S2MPU02_ENABLE_MASK			\
10808c2ecf20Sopenharmony_ci}
10818c2ecf20Sopenharmony_ci
10828c2ecf20Sopenharmony_cistatic const struct regulator_desc s2mpu02_regulators[] = {
10838c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo1(1),
10848c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo2(2),
10858c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo4(3),
10868c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo5(4),
10878c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo4(5),
10888c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo3(6),
10898c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo3(7),
10908c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo4(8),
10918c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo5(9),
10928c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo3(10),
10938c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo4(11),
10948c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo5(12),
10958c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo5(13),
10968c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo5(14),
10978c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo5(15),
10988c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo5(16),
10998c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo4(17),
11008c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo5(18),
11018c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo3(19),
11028c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo4(20),
11038c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo5(21),
11048c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo5(22),
11058c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo5(23),
11068c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo4(24),
11078c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo5(25),
11088c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo4(26),
11098c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo5(27),
11108c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_ldo5(28),
11118c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_buck1234(1),
11128c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_buck1234(2),
11138c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_buck1234(3),
11148c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_buck1234(4),
11158c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_buck5(5),
11168c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_buck6(6),
11178c2ecf20Sopenharmony_ci	regulator_desc_s2mpu02_buck7(7),
11188c2ecf20Sopenharmony_ci};
11198c2ecf20Sopenharmony_ci
11208c2ecf20Sopenharmony_cistatic int s2mps11_pmic_probe(struct platform_device *pdev)
11218c2ecf20Sopenharmony_ci{
11228c2ecf20Sopenharmony_ci	struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
11238c2ecf20Sopenharmony_ci	struct sec_platform_data *pdata = NULL;
11248c2ecf20Sopenharmony_ci	struct of_regulator_match *rdata = NULL;
11258c2ecf20Sopenharmony_ci	struct regulator_config config = { };
11268c2ecf20Sopenharmony_ci	struct s2mps11_info *s2mps11;
11278c2ecf20Sopenharmony_ci	unsigned int rdev_num = 0;
11288c2ecf20Sopenharmony_ci	int i, ret = 0;
11298c2ecf20Sopenharmony_ci	const struct regulator_desc *regulators;
11308c2ecf20Sopenharmony_ci
11318c2ecf20Sopenharmony_ci	s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
11328c2ecf20Sopenharmony_ci				GFP_KERNEL);
11338c2ecf20Sopenharmony_ci	if (!s2mps11)
11348c2ecf20Sopenharmony_ci		return -ENOMEM;
11358c2ecf20Sopenharmony_ci
11368c2ecf20Sopenharmony_ci	s2mps11->dev_type = platform_get_device_id(pdev)->driver_data;
11378c2ecf20Sopenharmony_ci	switch (s2mps11->dev_type) {
11388c2ecf20Sopenharmony_ci	case S2MPS11X:
11398c2ecf20Sopenharmony_ci		rdev_num = ARRAY_SIZE(s2mps11_regulators);
11408c2ecf20Sopenharmony_ci		regulators = s2mps11_regulators;
11418c2ecf20Sopenharmony_ci		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps11_regulators));
11428c2ecf20Sopenharmony_ci		break;
11438c2ecf20Sopenharmony_ci	case S2MPS13X:
11448c2ecf20Sopenharmony_ci		rdev_num = ARRAY_SIZE(s2mps13_regulators);
11458c2ecf20Sopenharmony_ci		regulators = s2mps13_regulators;
11468c2ecf20Sopenharmony_ci		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps13_regulators));
11478c2ecf20Sopenharmony_ci		break;
11488c2ecf20Sopenharmony_ci	case S2MPS14X:
11498c2ecf20Sopenharmony_ci		rdev_num = ARRAY_SIZE(s2mps14_regulators);
11508c2ecf20Sopenharmony_ci		regulators = s2mps14_regulators;
11518c2ecf20Sopenharmony_ci		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps14_regulators));
11528c2ecf20Sopenharmony_ci		break;
11538c2ecf20Sopenharmony_ci	case S2MPS15X:
11548c2ecf20Sopenharmony_ci		rdev_num = ARRAY_SIZE(s2mps15_regulators);
11558c2ecf20Sopenharmony_ci		regulators = s2mps15_regulators;
11568c2ecf20Sopenharmony_ci		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps15_regulators));
11578c2ecf20Sopenharmony_ci		break;
11588c2ecf20Sopenharmony_ci	case S2MPU02:
11598c2ecf20Sopenharmony_ci		rdev_num = ARRAY_SIZE(s2mpu02_regulators);
11608c2ecf20Sopenharmony_ci		regulators = s2mpu02_regulators;
11618c2ecf20Sopenharmony_ci		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mpu02_regulators));
11628c2ecf20Sopenharmony_ci		break;
11638c2ecf20Sopenharmony_ci	default:
11648c2ecf20Sopenharmony_ci		dev_err(&pdev->dev, "Invalid device type: %u\n",
11658c2ecf20Sopenharmony_ci				    s2mps11->dev_type);
11668c2ecf20Sopenharmony_ci		return -EINVAL;
11678c2ecf20Sopenharmony_ci	}
11688c2ecf20Sopenharmony_ci
11698c2ecf20Sopenharmony_ci	s2mps11->ext_control_gpiod = devm_kcalloc(&pdev->dev, rdev_num,
11708c2ecf20Sopenharmony_ci			       sizeof(*s2mps11->ext_control_gpiod), GFP_KERNEL);
11718c2ecf20Sopenharmony_ci	if (!s2mps11->ext_control_gpiod)
11728c2ecf20Sopenharmony_ci		return -ENOMEM;
11738c2ecf20Sopenharmony_ci
11748c2ecf20Sopenharmony_ci	if (!iodev->dev->of_node) {
11758c2ecf20Sopenharmony_ci		if (iodev->pdata) {
11768c2ecf20Sopenharmony_ci			pdata = iodev->pdata;
11778c2ecf20Sopenharmony_ci			goto common_reg;
11788c2ecf20Sopenharmony_ci		} else {
11798c2ecf20Sopenharmony_ci			dev_err(pdev->dev.parent,
11808c2ecf20Sopenharmony_ci				"Platform data or DT node not supplied\n");
11818c2ecf20Sopenharmony_ci			return -ENODEV;
11828c2ecf20Sopenharmony_ci		}
11838c2ecf20Sopenharmony_ci	}
11848c2ecf20Sopenharmony_ci
11858c2ecf20Sopenharmony_ci	rdata = kcalloc(rdev_num, sizeof(*rdata), GFP_KERNEL);
11868c2ecf20Sopenharmony_ci	if (!rdata)
11878c2ecf20Sopenharmony_ci		return -ENOMEM;
11888c2ecf20Sopenharmony_ci
11898c2ecf20Sopenharmony_ci	for (i = 0; i < rdev_num; i++)
11908c2ecf20Sopenharmony_ci		rdata[i].name = regulators[i].name;
11918c2ecf20Sopenharmony_ci
11928c2ecf20Sopenharmony_ci	ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11, rdev_num);
11938c2ecf20Sopenharmony_ci	if (ret)
11948c2ecf20Sopenharmony_ci		goto out;
11958c2ecf20Sopenharmony_ci
11968c2ecf20Sopenharmony_cicommon_reg:
11978c2ecf20Sopenharmony_ci	platform_set_drvdata(pdev, s2mps11);
11988c2ecf20Sopenharmony_ci
11998c2ecf20Sopenharmony_ci	config.dev = &pdev->dev;
12008c2ecf20Sopenharmony_ci	config.regmap = iodev->regmap_pmic;
12018c2ecf20Sopenharmony_ci	config.driver_data = s2mps11;
12028c2ecf20Sopenharmony_ci	for (i = 0; i < rdev_num; i++) {
12038c2ecf20Sopenharmony_ci		struct regulator_dev *regulator;
12048c2ecf20Sopenharmony_ci
12058c2ecf20Sopenharmony_ci		if (pdata) {
12068c2ecf20Sopenharmony_ci			config.init_data = pdata->regulators[i].initdata;
12078c2ecf20Sopenharmony_ci			config.of_node = pdata->regulators[i].reg_node;
12088c2ecf20Sopenharmony_ci		} else {
12098c2ecf20Sopenharmony_ci			config.init_data = rdata[i].init_data;
12108c2ecf20Sopenharmony_ci			config.of_node = rdata[i].of_node;
12118c2ecf20Sopenharmony_ci		}
12128c2ecf20Sopenharmony_ci		config.ena_gpiod = s2mps11->ext_control_gpiod[i];
12138c2ecf20Sopenharmony_ci		/*
12148c2ecf20Sopenharmony_ci		 * Hand the GPIO descriptor management over to the regulator
12158c2ecf20Sopenharmony_ci		 * core, remove it from devres management.
12168c2ecf20Sopenharmony_ci		 */
12178c2ecf20Sopenharmony_ci		if (config.ena_gpiod)
12188c2ecf20Sopenharmony_ci			devm_gpiod_unhinge(&pdev->dev, config.ena_gpiod);
12198c2ecf20Sopenharmony_ci		regulator = devm_regulator_register(&pdev->dev,
12208c2ecf20Sopenharmony_ci						&regulators[i], &config);
12218c2ecf20Sopenharmony_ci		if (IS_ERR(regulator)) {
12228c2ecf20Sopenharmony_ci			ret = PTR_ERR(regulator);
12238c2ecf20Sopenharmony_ci			dev_err(&pdev->dev, "regulator init failed for %d\n",
12248c2ecf20Sopenharmony_ci				i);
12258c2ecf20Sopenharmony_ci			goto out;
12268c2ecf20Sopenharmony_ci		}
12278c2ecf20Sopenharmony_ci
12288c2ecf20Sopenharmony_ci		if (config.ena_gpiod) {
12298c2ecf20Sopenharmony_ci			ret = s2mps14_pmic_enable_ext_control(s2mps11,
12308c2ecf20Sopenharmony_ci					regulator);
12318c2ecf20Sopenharmony_ci			if (ret < 0) {
12328c2ecf20Sopenharmony_ci				dev_err(&pdev->dev,
12338c2ecf20Sopenharmony_ci						"failed to enable GPIO control over %s: %d\n",
12348c2ecf20Sopenharmony_ci						regulator->desc->name, ret);
12358c2ecf20Sopenharmony_ci				goto out;
12368c2ecf20Sopenharmony_ci			}
12378c2ecf20Sopenharmony_ci		}
12388c2ecf20Sopenharmony_ci	}
12398c2ecf20Sopenharmony_ci
12408c2ecf20Sopenharmony_ciout:
12418c2ecf20Sopenharmony_ci	kfree(rdata);
12428c2ecf20Sopenharmony_ci
12438c2ecf20Sopenharmony_ci	return ret;
12448c2ecf20Sopenharmony_ci}
12458c2ecf20Sopenharmony_ci
12468c2ecf20Sopenharmony_cistatic const struct platform_device_id s2mps11_pmic_id[] = {
12478c2ecf20Sopenharmony_ci	{ "s2mps11-regulator", S2MPS11X},
12488c2ecf20Sopenharmony_ci	{ "s2mps13-regulator", S2MPS13X},
12498c2ecf20Sopenharmony_ci	{ "s2mps14-regulator", S2MPS14X},
12508c2ecf20Sopenharmony_ci	{ "s2mps15-regulator", S2MPS15X},
12518c2ecf20Sopenharmony_ci	{ "s2mpu02-regulator", S2MPU02},
12528c2ecf20Sopenharmony_ci	{ },
12538c2ecf20Sopenharmony_ci};
12548c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(platform, s2mps11_pmic_id);
12558c2ecf20Sopenharmony_ci
12568c2ecf20Sopenharmony_cistatic struct platform_driver s2mps11_pmic_driver = {
12578c2ecf20Sopenharmony_ci	.driver = {
12588c2ecf20Sopenharmony_ci		.name = "s2mps11-pmic",
12598c2ecf20Sopenharmony_ci	},
12608c2ecf20Sopenharmony_ci	.probe = s2mps11_pmic_probe,
12618c2ecf20Sopenharmony_ci	.id_table = s2mps11_pmic_id,
12628c2ecf20Sopenharmony_ci};
12638c2ecf20Sopenharmony_ci
12648c2ecf20Sopenharmony_cimodule_platform_driver(s2mps11_pmic_driver);
12658c2ecf20Sopenharmony_ci
12668c2ecf20Sopenharmony_ci/* Module information */
12678c2ecf20Sopenharmony_ciMODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
12688c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Samsung S2MPS11/S2MPS14/S2MPS15/S2MPU02 Regulator Driver");
12698c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
1270