Lines Matching +full:ovp +full:- +full:enable
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (c) 2009-2010 Marvell International Ltd.
85 static int __set_charger(struct max8925_power_info *info, int enable) in __set_charger() argument
87 struct max8925_chip *chip = info->chip; in __set_charger()
88 if (enable) { in __set_charger()
89 /* enable charger in platform */ in __set_charger()
90 if (info->set_charger) in __set_charger()
91 info->set_charger(1); in __set_charger()
92 /* enable charger */ in __set_charger()
93 max8925_set_bits(info->gpm, MAX8925_CHG_CNTL1, 1 << 7, 0); in __set_charger()
96 max8925_set_bits(info->gpm, MAX8925_CHG_CNTL1, 1 << 7, 1 << 7); in __set_charger()
97 if (info->set_charger) in __set_charger()
98 info->set_charger(0); in __set_charger()
100 dev_dbg(chip->dev, "%s\n", (enable) ? "Enable charger" in __set_charger()
108 struct max8925_chip *chip = info->chip; in max8925_charger_handler()
110 switch (irq - chip->irq_base) { in max8925_charger_handler()
112 info->ac_online = 1; in max8925_charger_handler()
114 dev_dbg(chip->dev, "Adapter inserted\n"); in max8925_charger_handler()
117 info->ac_online = 0; in max8925_charger_handler()
119 dev_dbg(chip->dev, "Adapter removed\n"); in max8925_charger_handler()
123 dev_dbg(chip->dev, "Battery temperature is out of range\n"); in max8925_charger_handler()
126 dev_dbg(chip->dev, "Error detection\n"); in max8925_charger_handler()
131 dev_dbg(chip->dev, "Battery temperature is in range\n"); in max8925_charger_handler()
135 dev_info(chip->dev, "Sys power is too low\n"); in max8925_charger_handler()
138 dev_dbg(chip->dev, "Sys power is above low threshold\n"); in max8925_charger_handler()
142 dev_dbg(chip->dev, "Charging is done\n"); in max8925_charger_handler()
145 dev_dbg(chip->dev, "Charging in top-off mode\n"); in max8925_charger_handler()
149 dev_dbg(chip->dev, "Safe timer is expired\n"); in max8925_charger_handler()
153 dev_dbg(chip->dev, "Charger is reset\n"); in max8925_charger_handler()
183 return -EINVAL; in start_measure()
186 max8925_reg_write(info->adc, meas_cmd, 0); in start_measure()
187 max8925_bulk_read(info->adc, meas_reg, 2, buf); in start_measure()
197 struct max8925_power_info *info = dev_get_drvdata(psy->dev.parent); in max8925_ac_get_prop()
202 val->intval = info->ac_online; in max8925_ac_get_prop()
205 if (info->ac_online) { in max8925_ac_get_prop()
208 val->intval = ret * 2000; /* unit is uV */ in max8925_ac_get_prop()
212 ret = -ENODATA; in max8925_ac_get_prop()
215 ret = -ENODEV; in max8925_ac_get_prop()
231 struct max8925_power_info *info = dev_get_drvdata(psy->dev.parent); in max8925_usb_get_prop()
236 val->intval = info->usb_online; in max8925_usb_get_prop()
239 if (info->usb_online) { in max8925_usb_get_prop()
242 val->intval = ret * 2000; /* unit is uV */ in max8925_usb_get_prop()
246 ret = -ENODATA; in max8925_usb_get_prop()
249 ret = -ENODEV; in max8925_usb_get_prop()
265 struct max8925_power_info *info = dev_get_drvdata(psy->dev.parent); in max8925_bat_get_prop()
270 val->intval = info->bat_online; in max8925_bat_get_prop()
273 if (info->bat_online) { in max8925_bat_get_prop()
276 val->intval = ret * 2000; /* unit is uV */ in max8925_bat_get_prop()
281 ret = -ENODATA; in max8925_bat_get_prop()
284 if (info->bat_online) { in max8925_bat_get_prop()
288 ret = ((ret * 6250) - 3125) /* uA */; in max8925_bat_get_prop()
289 val->intval = 0; in max8925_bat_get_prop()
291 val->intval = ret; /* unit is mA */ in max8925_bat_get_prop()
296 ret = -ENODATA; in max8925_bat_get_prop()
299 if (!info->bat_online) { in max8925_bat_get_prop()
300 ret = -ENODATA; in max8925_bat_get_prop()
303 ret = max8925_reg_read(info->gpm, MAX8925_CHG_STATUS); in max8925_bat_get_prop()
307 val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST; in max8925_bat_get_prop()
311 val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE; in max8925_bat_get_prop()
314 val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE; in max8925_bat_get_prop()
320 if (!info->bat_online) { in max8925_bat_get_prop()
321 ret = -ENODATA; in max8925_bat_get_prop()
324 ret = max8925_reg_read(info->gpm, MAX8925_CHG_STATUS); in max8925_bat_get_prop()
325 if (info->usb_online || info->ac_online) { in max8925_bat_get_prop()
326 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in max8925_bat_get_prop()
328 val->intval = POWER_SUPPLY_STATUS_CHARGING; in max8925_bat_get_prop()
330 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in max8925_bat_get_prop()
334 ret = -ENODEV; in max8925_bat_get_prop()
349 .name = "max8925-ac",
357 .name = "max8925-usb",
365 .name = "max8925-battery",
374 ret = request_threaded_irq(chip->irq_base + _irq, NULL, \
378 dev_err(chip->dev, "Failed to request IRQ #%d: %d\n", \
387 REQUEST_IRQ(MAX8925_IRQ_VCHG_DC_OVP, "ac-ovp"); in max8925_init_charger()
388 if (!info->no_insert_detect) { in max8925_init_charger()
389 REQUEST_IRQ(MAX8925_IRQ_VCHG_DC_F, "ac-remove"); in max8925_init_charger()
390 REQUEST_IRQ(MAX8925_IRQ_VCHG_DC_R, "ac-insert"); in max8925_init_charger()
392 if (!info->no_temp_support) { in max8925_init_charger()
393 REQUEST_IRQ(MAX8925_IRQ_VCHG_THM_OK_R, "batt-temp-in-range"); in max8925_init_charger()
394 REQUEST_IRQ(MAX8925_IRQ_VCHG_THM_OK_F, "batt-temp-out-range"); in max8925_init_charger()
396 REQUEST_IRQ(MAX8925_IRQ_VCHG_SYSLOW_F, "vsys-high"); in max8925_init_charger()
397 REQUEST_IRQ(MAX8925_IRQ_VCHG_SYSLOW_R, "vsys-low"); in max8925_init_charger()
398 REQUEST_IRQ(MAX8925_IRQ_VCHG_RST, "charger-reset"); in max8925_init_charger()
399 REQUEST_IRQ(MAX8925_IRQ_VCHG_DONE, "charger-done"); in max8925_init_charger()
400 REQUEST_IRQ(MAX8925_IRQ_VCHG_TOPOFF, "charger-topoff"); in max8925_init_charger()
401 REQUEST_IRQ(MAX8925_IRQ_VCHG_TMR_FAULT, "charger-timer-expire"); in max8925_init_charger()
403 info->usb_online = 0; in max8925_init_charger()
404 info->bat_online = 0; in max8925_init_charger()
406 /* check for power - can miss interrupt at boot time */ in max8925_init_charger()
408 info->ac_online = 1; in max8925_init_charger()
410 info->ac_online = 0; in max8925_init_charger()
412 ret = max8925_reg_read(info->gpm, MAX8925_CHG_STATUS); in max8925_init_charger()
420 if (info->batt_detect) in max8925_init_charger()
421 info->bat_online = (ret & MAX8925_CHG_MBDET) ? 0 : 1; in max8925_init_charger()
423 info->bat_online = 1; in max8925_init_charger()
425 info->ac_online = 1; in max8925_init_charger()
427 info->ac_online = 0; in max8925_init_charger()
430 max8925_set_bits(info->gpm, MAX8925_CHG_CNTL1, 1 << 7, 1 << 7); in max8925_init_charger()
432 max8925_set_bits(info->gpm, MAX8925_CHG_CNTL1, 3 << 5, in max8925_init_charger()
433 info->topoff_threshold << 5); in max8925_init_charger()
435 max8925_set_bits(info->gpm, MAX8925_CHG_CNTL1, 7, info->fast_charge); in max8925_init_charger()
442 struct max8925_chip *chip = info->chip; in max8925_deinit_charger()
445 irq = chip->irq_base + MAX8925_IRQ_VCHG_DC_OVP; in max8925_deinit_charger()
446 for (; irq <= chip->irq_base + MAX8925_IRQ_VCHG_TMR_FAULT; irq++) in max8925_deinit_charger()
456 struct device_node *nproot = pdev->dev.parent->of_node; in max8925_power_dt_init()
466 return pdev->dev.platform_data; in max8925_power_dt_init()
470 dev_err(&pdev->dev, "failed to find charger node\n"); in max8925_power_dt_init()
474 pdata = devm_kzalloc(&pdev->dev, in max8925_power_dt_init()
480 of_property_read_u32(np, "topoff-threshold", &topoff_threshold); in max8925_power_dt_init()
481 of_property_read_u32(np, "batt-detect", &batt_detect); in max8925_power_dt_init()
482 of_property_read_u32(np, "fast-charge", &fast_charge); in max8925_power_dt_init()
483 of_property_read_u32(np, "no-insert-detect", &no_insert_detect); in max8925_power_dt_init()
484 of_property_read_u32(np, "no-temp-support", &no_temp_support); in max8925_power_dt_init()
486 pdata->batt_detect = batt_detect; in max8925_power_dt_init()
487 pdata->fast_charge = fast_charge; in max8925_power_dt_init()
488 pdata->topoff_threshold = topoff_threshold; in max8925_power_dt_init()
489 pdata->no_insert_detect = no_insert_detect; in max8925_power_dt_init()
490 pdata->no_temp_support = no_temp_support; in max8925_power_dt_init()
500 return pdev->dev.platform_data; in max8925_power_dt_init()
506 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); in max8925_power_probe()
513 dev_err(&pdev->dev, "platform data isn't assigned to " in max8925_power_probe()
515 return -EINVAL; in max8925_power_probe()
518 info = devm_kzalloc(&pdev->dev, sizeof(struct max8925_power_info), in max8925_power_probe()
521 return -ENOMEM; in max8925_power_probe()
522 info->chip = chip; in max8925_power_probe()
523 info->gpm = chip->i2c; in max8925_power_probe()
524 info->adc = chip->adc; in max8925_power_probe()
527 psy_cfg.supplied_to = pdata->supplied_to; in max8925_power_probe()
528 psy_cfg.num_supplicants = pdata->num_supplicants; in max8925_power_probe()
530 info->ac = devm_power_supply_register(&pdev->dev, &ac_desc, &psy_cfg); in max8925_power_probe()
531 if (IS_ERR(info->ac)) in max8925_power_probe()
532 return PTR_ERR(info->ac); in max8925_power_probe()
533 info->ac->dev.parent = &pdev->dev; in max8925_power_probe()
535 info->usb = devm_power_supply_register(&pdev->dev, &usb_desc, &psy_cfg); in max8925_power_probe()
536 if (IS_ERR(info->usb)) in max8925_power_probe()
537 return PTR_ERR(info->usb); in max8925_power_probe()
538 info->usb->dev.parent = &pdev->dev; in max8925_power_probe()
540 info->battery = devm_power_supply_register(&pdev->dev, &battery_desc, NULL); in max8925_power_probe()
541 if (IS_ERR(info->battery)) in max8925_power_probe()
542 return PTR_ERR(info->battery); in max8925_power_probe()
543 info->battery->dev.parent = &pdev->dev; in max8925_power_probe()
545 info->batt_detect = pdata->batt_detect; in max8925_power_probe()
546 info->topoff_threshold = pdata->topoff_threshold; in max8925_power_probe()
547 info->fast_charge = pdata->fast_charge; in max8925_power_probe()
548 info->set_charger = pdata->set_charger; in max8925_power_probe()
549 info->no_temp_support = pdata->no_temp_support; in max8925_power_probe()
550 info->no_insert_detect = pdata->no_insert_detect; in max8925_power_probe()
568 .name = "max8925-power",
576 MODULE_ALIAS("platform:max8925-power");