Lines Matching +full:s2mps11 +full:- +full:pmic
1 // SPDX-License-Identifier: GPL-2.0+
3 // Copyright (c) 2012-2014 Samsung Electronics Co., Ltd
19 #include <linux/mfd/samsung/s2mps11.h>
38 * One bit for each S2MPS11/S2MPS13/S2MPS14/S2MPU02 regulator whether
44 * Array (size: number of regulators) with GPIO-s for external
73 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); in s2mps11_regulator_set_voltage_time_sel() local
80 ramp_delay = s2mps11->ramp_delay2; in s2mps11_regulator_set_voltage_time_sel()
84 ramp_delay = s2mps11->ramp_delay34; in s2mps11_regulator_set_voltage_time_sel()
87 ramp_delay = s2mps11->ramp_delay5; in s2mps11_regulator_set_voltage_time_sel()
91 ramp_delay = s2mps11->ramp_delay16; in s2mps11_regulator_set_voltage_time_sel()
96 ramp_delay = s2mps11->ramp_delay7810; in s2mps11_regulator_set_voltage_time_sel()
99 ramp_delay = s2mps11->ramp_delay9; in s2mps11_regulator_set_voltage_time_sel()
103 ramp_delay = rdev->desc->ramp_delay; in s2mps11_regulator_set_voltage_time_sel()
105 old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector); in s2mps11_regulator_set_voltage_time_sel()
106 new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector); in s2mps11_regulator_set_voltage_time_sel()
108 return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay); in s2mps11_regulator_set_voltage_time_sel()
113 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); in s2mps11_set_ramp_delay() local
121 if (ramp_delay > s2mps11->ramp_delay16) in s2mps11_set_ramp_delay()
122 s2mps11->ramp_delay16 = ramp_delay; in s2mps11_set_ramp_delay()
124 ramp_delay = s2mps11->ramp_delay16; in s2mps11_set_ramp_delay()
135 s2mps11->ramp_delay2 = ramp_delay; in s2mps11_set_ramp_delay()
146 if (ramp_delay > s2mps11->ramp_delay34) in s2mps11_set_ramp_delay()
147 s2mps11->ramp_delay34 = ramp_delay; in s2mps11_set_ramp_delay()
149 ramp_delay = s2mps11->ramp_delay34; in s2mps11_set_ramp_delay()
161 if (ramp_delay > s2mps11->ramp_delay34) in s2mps11_set_ramp_delay()
162 s2mps11->ramp_delay34 = ramp_delay; in s2mps11_set_ramp_delay()
164 ramp_delay = s2mps11->ramp_delay34; in s2mps11_set_ramp_delay()
170 s2mps11->ramp_delay5 = ramp_delay; in s2mps11_set_ramp_delay()
180 if (ramp_delay > s2mps11->ramp_delay16) in s2mps11_set_ramp_delay()
181 s2mps11->ramp_delay16 = ramp_delay; in s2mps11_set_ramp_delay()
183 ramp_delay = s2mps11->ramp_delay16; in s2mps11_set_ramp_delay()
190 if (ramp_delay > s2mps11->ramp_delay7810) in s2mps11_set_ramp_delay()
191 s2mps11->ramp_delay7810 = ramp_delay; in s2mps11_set_ramp_delay()
193 ramp_delay = s2mps11->ramp_delay7810; in s2mps11_set_ramp_delay()
198 s2mps11->ramp_delay9 = ramp_delay; in s2mps11_set_ramp_delay()
211 ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, in s2mps11_set_ramp_delay()
214 dev_err(&rdev->dev, "failed to enable ramp rate\n"); in s2mps11_set_ramp_delay()
221 return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift, in s2mps11_set_ramp_delay()
225 return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, in s2mps11_set_ramp_delay()
231 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); in s2mps11_regulator_enable() local
235 switch (s2mps11->dev_type) { in s2mps11_regulator_enable()
237 if (test_bit(rdev_id, s2mps11->suspend_state)) in s2mps11_regulator_enable()
240 val = rdev->desc->enable_mask; in s2mps11_regulator_enable()
244 if (test_bit(rdev_id, s2mps11->suspend_state)) in s2mps11_regulator_enable()
246 else if (s2mps11->ext_control_gpiod[rdev_id]) in s2mps11_regulator_enable()
249 val = rdev->desc->enable_mask; in s2mps11_regulator_enable()
252 if (test_bit(rdev_id, s2mps11->suspend_state)) in s2mps11_regulator_enable()
255 val = rdev->desc->enable_mask; in s2mps11_regulator_enable()
258 return -EINVAL; in s2mps11_regulator_enable()
261 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, in s2mps11_regulator_enable()
262 rdev->desc->enable_mask, val); in s2mps11_regulator_enable()
269 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); in s2mps11_regulator_set_suspend_disable() local
273 switch (s2mps11->dev_type) { in s2mps11_regulator_set_suspend_disable()
311 return -EINVAL; in s2mps11_regulator_set_suspend_disable()
314 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val); in s2mps11_regulator_set_suspend_disable()
318 set_bit(rdev_id, s2mps11->suspend_state); in s2mps11_regulator_set_suspend_disable()
326 if (!(val & rdev->desc->enable_mask)) in s2mps11_regulator_set_suspend_disable()
329 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, in s2mps11_regulator_set_suspend_disable()
330 rdev->desc->enable_mask, state); in s2mps11_regulator_set_suspend_disable()
368 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
370 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
385 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
387 .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
419 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
421 .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
508 .vsel_reg = S2MPS13_REG_L1CTRL + num - 1, \
510 .enable_reg = S2MPS13_REG_L1CTRL + num - 1, \
525 .vsel_reg = S2MPS13_REG_B1OUT + (num - 1) * 2, \
527 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
542 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
544 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
559 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
561 .enable_reg = S2MPS13_REG_B1CTRL + (num) * 2 - 1, \
639 .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
641 .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
656 .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
658 .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
730 .vsel_reg = S2MPS15_REG_L1CTRL + num - 1, \
732 .enable_reg = S2MPS15_REG_L1CTRL + num - 1, \
746 .vsel_reg = S2MPS15_REG_B1CTRL2 + ((num - 1) * 2), \
748 .enable_reg = S2MPS15_REG_B1CTRL1 + ((num - 1) * 2), \
827 static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11, in s2mps14_pmic_enable_ext_control() argument
830 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, in s2mps14_pmic_enable_ext_control()
831 rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL); in s2mps14_pmic_enable_ext_control()
835 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11) in s2mps14_pmic_dt_parse_ext_control_gpio() argument
837 struct gpio_desc **gpio = s2mps11->ext_control_gpiod; in s2mps14_pmic_dt_parse_ext_control_gpio()
848 gpio[reg] = devm_fwnode_gpiod_get(&pdev->dev, in s2mps14_pmic_dt_parse_ext_control_gpio()
850 "samsung,ext-control", in s2mps14_pmic_dt_parse_ext_control_gpio()
852 "s2mps11-regulator"); in s2mps14_pmic_dt_parse_ext_control_gpio()
853 if (PTR_ERR(gpio[reg]) == -ENOENT) in s2mps14_pmic_dt_parse_ext_control_gpio()
856 dev_err(&pdev->dev, "Failed to get control GPIO for %d/%s\n", in s2mps14_pmic_dt_parse_ext_control_gpio()
862 dev_dbg(&pdev->dev, "Using GPIO for ext-control over %d/%s\n", in s2mps14_pmic_dt_parse_ext_control_gpio()
868 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11, in s2mps11_pmic_dt_parse() argument
873 reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators"); in s2mps11_pmic_dt_parse()
875 dev_err(&pdev->dev, "could not find regulators sub-node\n"); in s2mps11_pmic_dt_parse()
876 return -EINVAL; in s2mps11_pmic_dt_parse()
879 of_regulator_match(&pdev->dev, reg_np, rdata, rdev_num); in s2mps11_pmic_dt_parse()
880 if (s2mps11->dev_type == S2MPS14X) in s2mps11_pmic_dt_parse()
881 s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11); in s2mps11_pmic_dt_parse()
912 return regmap_update_bits(rdev->regmap, ramp_reg, in s2mpu02_set_ramp_delay()
982 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
984 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
997 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
999 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
1012 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
1014 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
1029 .vsel_reg = S2MPU02_REG_B1CTRL2 + (num - 1) * 2, \
1031 .enable_reg = S2MPU02_REG_B1CTRL1 + (num - 1) * 2, \
1123 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()
1176 return -ENOMEM; in s2mps11_pmic_probe()
1181 ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11, rdev_num); in s2mps11_pmic_probe()
1185 platform_set_drvdata(pdev, s2mps11); in s2mps11_pmic_probe()
1187 config.dev = &pdev->dev; in s2mps11_pmic_probe()
1188 config.regmap = iodev->regmap_pmic; in s2mps11_pmic_probe()
1189 config.driver_data = s2mps11; in s2mps11_pmic_probe()
1195 config.ena_gpiod = s2mps11->ext_control_gpiod[i]; in s2mps11_pmic_probe()
1201 devm_gpiod_unhinge(&pdev->dev, config.ena_gpiod); in s2mps11_pmic_probe()
1202 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()
1226 { "s2mps11-regulator", S2MPS11X},
1227 { "s2mps13-regulator", S2MPS13X},
1228 { "s2mps14-regulator", S2MPS14X},
1229 { "s2mps15-regulator", S2MPS15X},
1230 { "s2mpu02-regulator", S2MPU02},
1237 .name = "s2mps11-pmic",
1248 MODULE_DESCRIPTION("Samsung S2MPS11/S2MPS14/S2MPS15/S2MPU02 Regulator Driver");