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>
39 * One bit for each S2MPS11/S2MPS13/S2MPS14/S2MPU02 regulator whether
45 * Array (size: number of regulators) with GPIO-s for external
74 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); in s2mps11_regulator_set_voltage_time_sel() local
81 ramp_delay = s2mps11->ramp_delay2; in s2mps11_regulator_set_voltage_time_sel()
85 ramp_delay = s2mps11->ramp_delay34; in s2mps11_regulator_set_voltage_time_sel()
88 ramp_delay = s2mps11->ramp_delay5; in s2mps11_regulator_set_voltage_time_sel()
92 ramp_delay = s2mps11->ramp_delay16; in s2mps11_regulator_set_voltage_time_sel()
97 ramp_delay = s2mps11->ramp_delay7810; in s2mps11_regulator_set_voltage_time_sel()
100 ramp_delay = s2mps11->ramp_delay9; in s2mps11_regulator_set_voltage_time_sel()
104 ramp_delay = rdev->desc->ramp_delay; in s2mps11_regulator_set_voltage_time_sel()
106 old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector); in s2mps11_regulator_set_voltage_time_sel()
107 new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector); in s2mps11_regulator_set_voltage_time_sel()
109 return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay); in s2mps11_regulator_set_voltage_time_sel()
114 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); in s2mps11_set_ramp_delay() local
122 if (ramp_delay > s2mps11->ramp_delay16) in s2mps11_set_ramp_delay()
123 s2mps11->ramp_delay16 = ramp_delay; in s2mps11_set_ramp_delay()
125 ramp_delay = s2mps11->ramp_delay16; in s2mps11_set_ramp_delay()
136 s2mps11->ramp_delay2 = ramp_delay; in s2mps11_set_ramp_delay()
147 if (ramp_delay > s2mps11->ramp_delay34) in s2mps11_set_ramp_delay()
148 s2mps11->ramp_delay34 = ramp_delay; in s2mps11_set_ramp_delay()
150 ramp_delay = s2mps11->ramp_delay34; in s2mps11_set_ramp_delay()
162 if (ramp_delay > s2mps11->ramp_delay34) in s2mps11_set_ramp_delay()
163 s2mps11->ramp_delay34 = ramp_delay; in s2mps11_set_ramp_delay()
165 ramp_delay = s2mps11->ramp_delay34; in s2mps11_set_ramp_delay()
171 s2mps11->ramp_delay5 = ramp_delay; in s2mps11_set_ramp_delay()
181 if (ramp_delay > s2mps11->ramp_delay16) in s2mps11_set_ramp_delay()
182 s2mps11->ramp_delay16 = ramp_delay; in s2mps11_set_ramp_delay()
184 ramp_delay = s2mps11->ramp_delay16; in s2mps11_set_ramp_delay()
191 if (ramp_delay > s2mps11->ramp_delay7810) in s2mps11_set_ramp_delay()
192 s2mps11->ramp_delay7810 = ramp_delay; in s2mps11_set_ramp_delay()
194 ramp_delay = s2mps11->ramp_delay7810; in s2mps11_set_ramp_delay()
199 s2mps11->ramp_delay9 = ramp_delay; in s2mps11_set_ramp_delay()
212 ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, in s2mps11_set_ramp_delay()
215 dev_err(&rdev->dev, "failed to enable ramp rate\n"); in s2mps11_set_ramp_delay()
222 return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift, in s2mps11_set_ramp_delay()
226 return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, in s2mps11_set_ramp_delay()
232 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); in s2mps11_regulator_enable() local
236 switch (s2mps11->dev_type) { in s2mps11_regulator_enable()
238 if (test_bit(rdev_id, s2mps11->suspend_state)) in s2mps11_regulator_enable()
241 val = rdev->desc->enable_mask; in s2mps11_regulator_enable()
245 if (test_bit(rdev_id, s2mps11->suspend_state)) in s2mps11_regulator_enable()
247 else if (s2mps11->ext_control_gpiod[rdev_id]) in s2mps11_regulator_enable()
250 val = rdev->desc->enable_mask; in s2mps11_regulator_enable()
253 if (test_bit(rdev_id, s2mps11->suspend_state)) in s2mps11_regulator_enable()
256 val = rdev->desc->enable_mask; in s2mps11_regulator_enable()
259 val = rdev->desc->enable_mask; in s2mps11_regulator_enable()
262 return -EINVAL; in s2mps11_regulator_enable()
265 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, in s2mps11_regulator_enable()
266 rdev->desc->enable_mask, val); in s2mps11_regulator_enable()
273 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); in s2mps11_regulator_set_suspend_disable() local
277 switch (s2mps11->dev_type) { in s2mps11_regulator_set_suspend_disable()
315 return -EINVAL; in s2mps11_regulator_set_suspend_disable()
318 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val); in s2mps11_regulator_set_suspend_disable()
322 set_bit(rdev_id, s2mps11->suspend_state); in s2mps11_regulator_set_suspend_disable()
330 if (!(val & rdev->desc->enable_mask)) in s2mps11_regulator_set_suspend_disable()
333 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, in s2mps11_regulator_set_suspend_disable()
334 rdev->desc->enable_mask, state); in s2mps11_regulator_set_suspend_disable()
372 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
374 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
389 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
391 .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
423 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
425 .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
512 .vsel_reg = S2MPS13_REG_L1CTRL + num - 1, \
514 .enable_reg = S2MPS13_REG_L1CTRL + num - 1, \
529 .vsel_reg = S2MPS13_REG_B1OUT + (num - 1) * 2, \
531 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
546 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
548 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
563 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
565 .enable_reg = S2MPS13_REG_B1CTRL + (num) * 2 - 1, \
643 .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
645 .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
660 .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
662 .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
734 .vsel_reg = S2MPS15_REG_L1CTRL + num - 1, \
736 .enable_reg = S2MPS15_REG_L1CTRL + num - 1, \
750 .vsel_reg = S2MPS15_REG_B1CTRL2 + ((num - 1) * 2), \
752 .enable_reg = S2MPS15_REG_B1CTRL1 + ((num - 1) * 2), \
831 static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11, in s2mps14_pmic_enable_ext_control() argument
834 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, in s2mps14_pmic_enable_ext_control()
835 rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL); in s2mps14_pmic_enable_ext_control()
839 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11) in s2mps14_pmic_dt_parse_ext_control_gpio() argument
841 struct gpio_desc **gpio = s2mps11->ext_control_gpiod; in s2mps14_pmic_dt_parse_ext_control_gpio()
852 gpio[reg] = devm_fwnode_gpiod_get(&pdev->dev, in s2mps14_pmic_dt_parse_ext_control_gpio()
854 "samsung,ext-control", in s2mps14_pmic_dt_parse_ext_control_gpio()
856 "s2mps11-regulator"); in s2mps14_pmic_dt_parse_ext_control_gpio()
857 if (PTR_ERR(gpio[reg]) == -ENOENT) in s2mps14_pmic_dt_parse_ext_control_gpio()
860 dev_err(&pdev->dev, "Failed to get control GPIO for %d/%s\n", in s2mps14_pmic_dt_parse_ext_control_gpio()
866 dev_dbg(&pdev->dev, "Using GPIO for ext-control over %d/%s\n", in s2mps14_pmic_dt_parse_ext_control_gpio()
872 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11, in s2mps11_pmic_dt_parse() argument
877 reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators"); in s2mps11_pmic_dt_parse()
879 dev_err(&pdev->dev, "could not find regulators sub-node\n"); in s2mps11_pmic_dt_parse()
880 return -EINVAL; in s2mps11_pmic_dt_parse()
883 of_regulator_match(&pdev->dev, reg_np, rdata, rdev_num); in s2mps11_pmic_dt_parse()
884 if (s2mps11->dev_type == S2MPS14X) in s2mps11_pmic_dt_parse()
885 s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11); in s2mps11_pmic_dt_parse()
916 return regmap_update_bits(rdev->regmap, ramp_reg, in s2mpu02_set_ramp_delay()
986 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
988 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
1001 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
1003 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
1016 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
1018 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
1033 .vsel_reg = S2MPU02_REG_B1CTRL2 + (num - 1) * 2, \
1035 .enable_reg = S2MPU02_REG_B1CTRL1 + (num - 1) * 2, \
1186 /* LDOs 11-24 are used for CP. They aren't documented. */
1207 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); in s2mps11_pmic_probe()
1209 struct s2mps11_info *s2mps11; in s2mps11_pmic_probe() local
1214 s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info), in s2mps11_pmic_probe()
1216 if (!s2mps11) in s2mps11_pmic_probe()
1217 return -ENOMEM; in s2mps11_pmic_probe()
1219 s2mps11->dev_type = platform_get_device_id(pdev)->driver_data; in s2mps11_pmic_probe()
1220 switch (s2mps11->dev_type) { in s2mps11_pmic_probe()
1252 dev_err(&pdev->dev, "Invalid device type: %u\n", in s2mps11_pmic_probe()
1253 s2mps11->dev_type); in s2mps11_pmic_probe()
1254 return -EINVAL; in s2mps11_pmic_probe()
1257 s2mps11->ext_control_gpiod = devm_kcalloc(&pdev->dev, rdev_num, in s2mps11_pmic_probe()
1258 sizeof(*s2mps11->ext_control_gpiod), GFP_KERNEL); in s2mps11_pmic_probe()
1259 if (!s2mps11->ext_control_gpiod) in s2mps11_pmic_probe()
1260 return -ENOMEM; in s2mps11_pmic_probe()
1265 return -ENOMEM; in s2mps11_pmic_probe()
1270 ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11, rdev_num); in s2mps11_pmic_probe()
1274 platform_set_drvdata(pdev, s2mps11); in s2mps11_pmic_probe()
1276 config.dev = &pdev->dev; in s2mps11_pmic_probe()
1277 config.regmap = iodev->regmap_pmic; in s2mps11_pmic_probe()
1278 config.driver_data = s2mps11; in s2mps11_pmic_probe()
1284 config.ena_gpiod = s2mps11->ext_control_gpiod[i]; in s2mps11_pmic_probe()
1290 devm_gpiod_unhinge(&pdev->dev, config.ena_gpiod); in s2mps11_pmic_probe()
1291 regulator = devm_regulator_register(&pdev->dev, in s2mps11_pmic_probe()
1294 dev_err(&pdev->dev, "regulator init failed for %d\n", in s2mps11_pmic_probe()
1300 ret = s2mps14_pmic_enable_ext_control(s2mps11, in s2mps11_pmic_probe()
1303 dev_err(&pdev->dev, in s2mps11_pmic_probe()
1305 regulator->desc->name, ret); in s2mps11_pmic_probe()
1315 { "s2mps11-regulator", S2MPS11X},
1316 { "s2mps13-regulator", S2MPS13X},
1317 { "s2mps14-regulator", S2MPS14X},
1318 { "s2mps15-regulator", S2MPS15X},
1319 { "s2mpu02-regulator", S2MPU02},
1320 { "s2mpu05-regulator", S2MPU05},
1327 .name = "s2mps11-pmic",
1338 MODULE_DESCRIPTION("Samsung S2MPS11/14/15/S2MPU02/05 Regulator Driver");