Lines Matching +full:range +full:- +full:microamp

1 // SPDX-License-Identifier: GPL-2.0-only
14 #include <linux/mfd/rt5033-private.h>
33 struct regmap *regmap = charger->regmap; in rt5033_get_charger_state()
64 struct regmap *regmap = charger->regmap; in rt5033_get_charger_type()
86 struct regmap *regmap = charger->regmap; in rt5033_get_charger_current_limit()
102 struct regmap *regmap = charger->regmap; in rt5033_get_charger_const_voltage()
118 struct rt5033_charger_data *chg = charger->chg; in rt5033_init_const_charge()
124 if (chg->const_uvolt < RT5033_CHARGER_CONST_VOLTAGE_LIMIT_MIN || in rt5033_init_const_charge()
125 chg->const_uvolt > RT5033_CHARGER_CONST_VOLTAGE_LIMIT_MAX) { in rt5033_init_const_charge()
126 dev_err(charger->dev, in rt5033_init_const_charge()
127 "Value 'constant-charge-voltage-max-microvolt' out of range\n"); in rt5033_init_const_charge()
128 return -EINVAL; in rt5033_init_const_charge()
131 if (chg->const_uvolt == RT5033_CHARGER_CONST_VOLTAGE_LIMIT_MIN) in rt5033_init_const_charge()
133 else if (chg->const_uvolt == RT5033_CHARGER_CONST_VOLTAGE_LIMIT_MAX) in rt5033_init_const_charge()
136 val = chg->const_uvolt; in rt5033_init_const_charge()
137 val -= RT5033_CHARGER_CONST_VOLTAGE_LIMIT_MIN; in rt5033_init_const_charge()
142 ret = regmap_update_bits(charger->regmap, RT5033_REG_CHG_CTRL2, in rt5033_init_const_charge()
146 dev_err(charger->dev, "Failed regmap update\n"); in rt5033_init_const_charge()
147 return -EINVAL; in rt5033_init_const_charge()
151 if (chg->eoc_uamp < RT5033_CHARGER_EOC_MIN || in rt5033_init_const_charge()
152 chg->eoc_uamp > RT5033_CHARGER_EOC_MAX) { in rt5033_init_const_charge()
153 dev_err(charger->dev, in rt5033_init_const_charge()
154 "Value 'charge-term-current-microamp' out of range\n"); in rt5033_init_const_charge()
155 return -EINVAL; in rt5033_init_const_charge()
158 if (chg->eoc_uamp == RT5033_CHARGER_EOC_MIN) in rt5033_init_const_charge()
160 else if (chg->eoc_uamp == RT5033_CHARGER_EOC_MAX) in rt5033_init_const_charge()
163 val = chg->eoc_uamp; in rt5033_init_const_charge()
165 val -= RT5033_CHARGER_EOC_MIN; in rt5033_init_const_charge()
169 val -= RT5033_CHARGER_EOC_REF; in rt5033_init_const_charge()
177 ret = regmap_update_bits(charger->regmap, RT5033_REG_CHG_CTRL4, in rt5033_init_const_charge()
180 dev_err(charger->dev, "Failed regmap update\n"); in rt5033_init_const_charge()
181 return -EINVAL; in rt5033_init_const_charge()
189 struct rt5033_charger_data *chg = charger->chg; in rt5033_init_fast_charge()
195 ret = regmap_update_bits(charger->regmap, RT5033_REG_CHG_CTRL1, in rt5033_init_fast_charge()
198 dev_err(charger->dev, "Failed regmap update\n"); in rt5033_init_fast_charge()
199 return -EINVAL; in rt5033_init_fast_charge()
202 /* Set fast-charge mode charging current */ in rt5033_init_fast_charge()
203 if (chg->fast_uamp < RT5033_CHARGER_FAST_CURRENT_MIN || in rt5033_init_fast_charge()
204 chg->fast_uamp > RT5033_CHARGER_FAST_CURRENT_MAX) { in rt5033_init_fast_charge()
205 dev_err(charger->dev, in rt5033_init_fast_charge()
206 "Value 'constant-charge-current-max-microamp' out of range\n"); in rt5033_init_fast_charge()
207 return -EINVAL; in rt5033_init_fast_charge()
210 if (chg->fast_uamp == RT5033_CHARGER_FAST_CURRENT_MIN) in rt5033_init_fast_charge()
212 else if (chg->fast_uamp == RT5033_CHARGER_FAST_CURRENT_MAX) in rt5033_init_fast_charge()
215 val = chg->fast_uamp; in rt5033_init_fast_charge()
216 val -= RT5033_CHARGER_FAST_CURRENT_MIN; in rt5033_init_fast_charge()
221 ret = regmap_update_bits(charger->regmap, RT5033_REG_CHG_CTRL5, in rt5033_init_fast_charge()
225 dev_err(charger->dev, "Failed regmap update\n"); in rt5033_init_fast_charge()
226 return -EINVAL; in rt5033_init_fast_charge()
234 struct rt5033_charger_data *chg = charger->chg; in rt5033_init_pre_charge()
239 /* Set pre-charge threshold voltage */ in rt5033_init_pre_charge()
240 if (chg->pre_uvolt < RT5033_CHARGER_PRE_THRESHOLD_LIMIT_MIN || in rt5033_init_pre_charge()
241 chg->pre_uvolt > RT5033_CHARGER_PRE_THRESHOLD_LIMIT_MAX) { in rt5033_init_pre_charge()
242 dev_err(charger->dev, in rt5033_init_pre_charge()
243 "Value 'precharge-upper-limit-microvolt' out of range\n"); in rt5033_init_pre_charge()
244 return -EINVAL; in rt5033_init_pre_charge()
247 if (chg->pre_uvolt == RT5033_CHARGER_PRE_THRESHOLD_LIMIT_MIN) in rt5033_init_pre_charge()
249 else if (chg->pre_uvolt == RT5033_CHARGER_PRE_THRESHOLD_LIMIT_MAX) in rt5033_init_pre_charge()
252 val = chg->pre_uvolt; in rt5033_init_pre_charge()
253 val -= RT5033_CHARGER_PRE_THRESHOLD_LIMIT_MIN; in rt5033_init_pre_charge()
258 ret = regmap_update_bits(charger->regmap, RT5033_REG_CHG_CTRL5, in rt5033_init_pre_charge()
261 dev_err(charger->dev, "Failed regmap update\n"); in rt5033_init_pre_charge()
262 return -EINVAL; in rt5033_init_pre_charge()
265 /* Set pre-charge mode charging current */ in rt5033_init_pre_charge()
266 if (chg->pre_uamp < RT5033_CHARGER_PRE_CURRENT_LIMIT_MIN || in rt5033_init_pre_charge()
267 chg->pre_uamp > RT5033_CHARGER_PRE_CURRENT_LIMIT_MAX) { in rt5033_init_pre_charge()
268 dev_err(charger->dev, in rt5033_init_pre_charge()
269 "Value 'precharge-current-microamp' out of range\n"); in rt5033_init_pre_charge()
270 return -EINVAL; in rt5033_init_pre_charge()
273 if (chg->pre_uamp == RT5033_CHARGER_PRE_CURRENT_LIMIT_MIN) in rt5033_init_pre_charge()
275 else if (chg->pre_uamp == RT5033_CHARGER_PRE_CURRENT_LIMIT_MAX) in rt5033_init_pre_charge()
278 val = chg->pre_uamp; in rt5033_init_pre_charge()
279 val -= RT5033_CHARGER_PRE_CURRENT_LIMIT_MIN; in rt5033_init_pre_charge()
284 ret = regmap_update_bits(charger->regmap, RT5033_REG_CHG_CTRL4, in rt5033_init_pre_charge()
288 dev_err(charger->dev, "Failed regmap update\n"); in rt5033_init_pre_charge()
289 return -EINVAL; in rt5033_init_pre_charge()
300 ret = regmap_update_bits(charger->regmap, RT5033_REG_CHG_CTRL1, in rt5033_charger_reg_init()
303 dev_err(charger->dev, "Failed to enable charging termination.\n"); in rt5033_charger_reg_init()
304 return -EINVAL; in rt5033_charger_reg_init()
311 ret = regmap_update_bits(charger->regmap, RT5033_REG_CHG_CTRL4, in rt5033_charger_reg_init()
314 dev_err(charger->dev, "Failed to disable MIVR.\n"); in rt5033_charger_reg_init()
315 return -EINVAL; in rt5033_charger_reg_init()
351 val->intval = rt5033_get_charger_state(charger); in rt5033_charger_get_property()
354 val->intval = rt5033_get_charger_type(charger); in rt5033_charger_get_property()
357 val->intval = rt5033_get_charger_current_limit(charger); in rt5033_charger_get_property()
360 val->intval = rt5033_get_charger_const_voltage(charger); in rt5033_charger_get_property()
363 val->strval = RT5033_CHARGER_MODEL; in rt5033_charger_get_property()
366 val->strval = RT5033_MANUFACTURER; in rt5033_charger_get_property()
369 val->intval = (rt5033_get_charger_state(charger) == in rt5033_charger_get_property()
373 return -EINVAL; in rt5033_charger_get_property()
386 chg = devm_kzalloc(charger->dev, sizeof(*chg), GFP_KERNEL); in rt5033_charger_dt_init()
388 return ERR_PTR(-ENOMEM); in rt5033_charger_dt_init()
390 ret = power_supply_get_battery_info(charger->psy, &info); in rt5033_charger_dt_init()
392 return ERR_PTR(dev_err_probe(charger->dev, -EINVAL, in rt5033_charger_dt_init()
396 chg->pre_uamp = info->precharge_current_ua; in rt5033_charger_dt_init()
397 chg->fast_uamp = info->constant_charge_current_max_ua; in rt5033_charger_dt_init()
398 chg->eoc_uamp = info->charge_term_current_ua; in rt5033_charger_dt_init()
399 chg->pre_uvolt = info->precharge_voltage_max_uv; in rt5033_charger_dt_init()
400 chg->const_uvolt = info->constant_charge_voltage_max_uv; in rt5033_charger_dt_init()
406 .name = "rt5033-charger",
419 charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL); in rt5033_charger_probe()
421 return -ENOMEM; in rt5033_charger_probe()
424 charger->dev = &pdev->dev; in rt5033_charger_probe()
425 charger->regmap = dev_get_regmap(pdev->dev.parent, NULL); in rt5033_charger_probe()
427 psy_cfg.of_node = pdev->dev.of_node; in rt5033_charger_probe()
430 charger->psy = devm_power_supply_register(&pdev->dev, in rt5033_charger_probe()
433 if (IS_ERR(charger->psy)) in rt5033_charger_probe()
434 return dev_err_probe(&pdev->dev, PTR_ERR(charger->psy), in rt5033_charger_probe()
437 charger->chg = rt5033_charger_dt_init(charger); in rt5033_charger_probe()
438 if (IS_ERR_OR_NULL(charger->chg)) in rt5033_charger_probe()
439 return PTR_ERR(charger->chg); in rt5033_charger_probe()
449 { "rt5033-charger", },
455 { .compatible = "richtek,rt5033-charger", },
462 .name = "rt5033-charger",