Lines Matching +full:s2mps11 +full:- +full:pmic

1 // SPDX-License-Identifier: GPL-2.0+
3 // Copyright (c) 2012-2014 Samsung Electronics Co., Ltd
18 #include <linux/mfd/samsung/s2mps11.h>
37 * One bit for each S2MPS11/S2MPS13/S2MPS14/S2MPU02 regulator whether
43 * Array (size: number of regulators) with GPIO-s for external
72 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); in s2mps11_regulator_set_voltage_time_sel() local
79 ramp_delay = s2mps11->ramp_delay2; in s2mps11_regulator_set_voltage_time_sel()
83 ramp_delay = s2mps11->ramp_delay34; in s2mps11_regulator_set_voltage_time_sel()
86 ramp_delay = s2mps11->ramp_delay5; in s2mps11_regulator_set_voltage_time_sel()
90 ramp_delay = s2mps11->ramp_delay16; in s2mps11_regulator_set_voltage_time_sel()
95 ramp_delay = s2mps11->ramp_delay7810; in s2mps11_regulator_set_voltage_time_sel()
98 ramp_delay = s2mps11->ramp_delay9; in s2mps11_regulator_set_voltage_time_sel()
102 ramp_delay = rdev->desc->ramp_delay; in s2mps11_regulator_set_voltage_time_sel()
104 old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector); in s2mps11_regulator_set_voltage_time_sel()
105 new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector); in s2mps11_regulator_set_voltage_time_sel()
107 return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay); in s2mps11_regulator_set_voltage_time_sel()
112 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); in s2mps11_set_ramp_delay() local
120 if (ramp_delay > s2mps11->ramp_delay16) in s2mps11_set_ramp_delay()
121 s2mps11->ramp_delay16 = ramp_delay; in s2mps11_set_ramp_delay()
123 ramp_delay = s2mps11->ramp_delay16; in s2mps11_set_ramp_delay()
134 s2mps11->ramp_delay2 = ramp_delay; in s2mps11_set_ramp_delay()
145 if (ramp_delay > s2mps11->ramp_delay34) in s2mps11_set_ramp_delay()
146 s2mps11->ramp_delay34 = ramp_delay; in s2mps11_set_ramp_delay()
148 ramp_delay = s2mps11->ramp_delay34; in s2mps11_set_ramp_delay()
160 if (ramp_delay > s2mps11->ramp_delay34) in s2mps11_set_ramp_delay()
161 s2mps11->ramp_delay34 = ramp_delay; in s2mps11_set_ramp_delay()
163 ramp_delay = s2mps11->ramp_delay34; in s2mps11_set_ramp_delay()
169 s2mps11->ramp_delay5 = ramp_delay; in s2mps11_set_ramp_delay()
179 if (ramp_delay > s2mps11->ramp_delay16) in s2mps11_set_ramp_delay()
180 s2mps11->ramp_delay16 = ramp_delay; in s2mps11_set_ramp_delay()
182 ramp_delay = s2mps11->ramp_delay16; in s2mps11_set_ramp_delay()
189 if (ramp_delay > s2mps11->ramp_delay7810) in s2mps11_set_ramp_delay()
190 s2mps11->ramp_delay7810 = ramp_delay; in s2mps11_set_ramp_delay()
192 ramp_delay = s2mps11->ramp_delay7810; in s2mps11_set_ramp_delay()
197 s2mps11->ramp_delay9 = ramp_delay; in s2mps11_set_ramp_delay()
210 ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, in s2mps11_set_ramp_delay()
213 dev_err(&rdev->dev, "failed to enable ramp rate\n"); in s2mps11_set_ramp_delay()
220 return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift, in s2mps11_set_ramp_delay()
224 return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, in s2mps11_set_ramp_delay()
230 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); in s2mps11_regulator_enable() local
234 switch (s2mps11->dev_type) { in s2mps11_regulator_enable()
236 if (test_bit(rdev_id, s2mps11->suspend_state)) in s2mps11_regulator_enable()
239 val = rdev->desc->enable_mask; in s2mps11_regulator_enable()
243 if (test_bit(rdev_id, s2mps11->suspend_state)) in s2mps11_regulator_enable()
245 else if (s2mps11->ext_control_gpiod[rdev_id]) in s2mps11_regulator_enable()
248 val = rdev->desc->enable_mask; in s2mps11_regulator_enable()
251 if (test_bit(rdev_id, s2mps11->suspend_state)) in s2mps11_regulator_enable()
254 val = rdev->desc->enable_mask; in s2mps11_regulator_enable()
257 return -EINVAL; in s2mps11_regulator_enable()
260 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, in s2mps11_regulator_enable()
261 rdev->desc->enable_mask, val); in s2mps11_regulator_enable()
268 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); in s2mps11_regulator_set_suspend_disable() local
272 switch (s2mps11->dev_type) { in s2mps11_regulator_set_suspend_disable()
310 return -EINVAL; in s2mps11_regulator_set_suspend_disable()
313 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val); in s2mps11_regulator_set_suspend_disable()
317 set_bit(rdev_id, s2mps11->suspend_state); in s2mps11_regulator_set_suspend_disable()
325 if (!(val & rdev->desc->enable_mask)) in s2mps11_regulator_set_suspend_disable()
328 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, in s2mps11_regulator_set_suspend_disable()
329 rdev->desc->enable_mask, state); in s2mps11_regulator_set_suspend_disable()
367 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
369 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
384 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
386 .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
418 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
420 .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
507 .vsel_reg = S2MPS13_REG_L1CTRL + num - 1, \
509 .enable_reg = S2MPS13_REG_L1CTRL + num - 1, \
524 .vsel_reg = S2MPS13_REG_B1OUT + (num - 1) * 2, \
526 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
541 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
543 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
558 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
560 .enable_reg = S2MPS13_REG_B1CTRL + (num) * 2 - 1, \
638 .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
640 .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
655 .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
657 .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
729 .vsel_reg = S2MPS15_REG_L1CTRL + num - 1, \
731 .enable_reg = S2MPS15_REG_L1CTRL + num - 1, \
745 .vsel_reg = S2MPS15_REG_B1CTRL2 + ((num - 1) * 2), \
747 .enable_reg = S2MPS15_REG_B1CTRL1 + ((num - 1) * 2), \
826 static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11, in s2mps14_pmic_enable_ext_control() argument
829 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, in s2mps14_pmic_enable_ext_control()
830 rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL); in s2mps14_pmic_enable_ext_control()
834 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11) in s2mps14_pmic_dt_parse_ext_control_gpio() argument
836 struct gpio_desc **gpio = s2mps11->ext_control_gpiod; in s2mps14_pmic_dt_parse_ext_control_gpio()
847 gpio[reg] = devm_fwnode_gpiod_get(&pdev->dev, in s2mps14_pmic_dt_parse_ext_control_gpio()
849 "samsung,ext-control", in s2mps14_pmic_dt_parse_ext_control_gpio()
851 "s2mps11-regulator"); in s2mps14_pmic_dt_parse_ext_control_gpio()
852 if (PTR_ERR(gpio[reg]) == -ENOENT) in s2mps14_pmic_dt_parse_ext_control_gpio()
855 dev_err(&pdev->dev, "Failed to get control GPIO for %d/%s\n", in s2mps14_pmic_dt_parse_ext_control_gpio()
861 dev_dbg(&pdev->dev, "Using GPIO for ext-control over %d/%s\n", in s2mps14_pmic_dt_parse_ext_control_gpio()
867 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11, in s2mps11_pmic_dt_parse() argument
872 reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators"); in s2mps11_pmic_dt_parse()
874 dev_err(&pdev->dev, "could not find regulators sub-node\n"); in s2mps11_pmic_dt_parse()
875 return -EINVAL; in s2mps11_pmic_dt_parse()
878 of_regulator_match(&pdev->dev, reg_np, rdata, rdev_num); in s2mps11_pmic_dt_parse()
879 if (s2mps11->dev_type == S2MPS14X) in s2mps11_pmic_dt_parse()
880 s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11); in s2mps11_pmic_dt_parse()
911 return regmap_update_bits(rdev->regmap, ramp_reg, in s2mpu02_set_ramp_delay()
981 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
983 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
996 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
998 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
1011 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
1013 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
1028 .vsel_reg = S2MPU02_REG_B1CTRL2 + (num - 1) * 2, \
1030 .enable_reg = S2MPU02_REG_B1CTRL1 + (num - 1) * 2, \
1122 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); in s2mps11_pmic_probe()
1125 struct s2mps11_info *s2mps11; in s2mps11_pmic_probe() local
1130 s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info), in s2mps11_pmic_probe()
1132 if (!s2mps11) in s2mps11_pmic_probe()
1133 return -ENOMEM; in s2mps11_pmic_probe()
1135 s2mps11->dev_type = platform_get_device_id(pdev)->driver_data; in s2mps11_pmic_probe()
1136 switch (s2mps11->dev_type) { in s2mps11_pmic_probe()
1163 dev_err(&pdev->dev, "Invalid device type: %u\n", in s2mps11_pmic_probe()
1164 s2mps11->dev_type); in s2mps11_pmic_probe()
1165 return -EINVAL; in s2mps11_pmic_probe()
1168 s2mps11->ext_control_gpiod = devm_kcalloc(&pdev->dev, rdev_num, in s2mps11_pmic_probe()
1169 sizeof(*s2mps11->ext_control_gpiod), GFP_KERNEL); in s2mps11_pmic_probe()
1170 if (!s2mps11->ext_control_gpiod) in s2mps11_pmic_probe()
1171 return -ENOMEM; in s2mps11_pmic_probe()
1175 return -ENOMEM; in s2mps11_pmic_probe()
1180 ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11, rdev_num); in s2mps11_pmic_probe()
1184 platform_set_drvdata(pdev, s2mps11); in s2mps11_pmic_probe()
1186 config.dev = &pdev->dev; in s2mps11_pmic_probe()
1187 config.regmap = iodev->regmap_pmic; in s2mps11_pmic_probe()
1188 config.driver_data = s2mps11; in s2mps11_pmic_probe()
1194 config.ena_gpiod = s2mps11->ext_control_gpiod[i]; in s2mps11_pmic_probe()
1200 devm_gpiod_unhinge(&pdev->dev, config.ena_gpiod); in s2mps11_pmic_probe()
1201 regulator = devm_regulator_register(&pdev->dev, in s2mps11_pmic_probe()
1205 dev_err(&pdev->dev, "regulator init failed for %d\n", in s2mps11_pmic_probe()
1211 ret = s2mps14_pmic_enable_ext_control(s2mps11, in s2mps11_pmic_probe()
1214 dev_err(&pdev->dev, in s2mps11_pmic_probe()
1216 regulator->desc->name, ret); in s2mps11_pmic_probe()
1229 { "s2mps11-regulator", S2MPS11X},
1230 { "s2mps13-regulator", S2MPS13X},
1231 { "s2mps14-regulator", S2MPS14X},
1232 { "s2mps15-regulator", S2MPS15X},
1233 { "s2mpu02-regulator", S2MPU02},
1240 .name = "s2mps11-pmic",
1251 MODULE_DESCRIPTION("Samsung S2MPS11/S2MPS14/S2MPS15/S2MPU02 Regulator Driver");