Lines Matching refs:chg
256 static int smbb_charger_attr_write(struct smbb_charger *chg, in smbb_charger_attr_write() argument
267 dev_err(chg->dev, "value out of range for %s [%u:%u]\n", in smbb_charger_attr_write()
273 rc = regmap_read(chg->regmap, in smbb_charger_attr_write()
274 chg->addr + prop->safe_reg, &wval); in smbb_charger_attr_write()
276 dev_err(chg->dev, in smbb_charger_attr_write()
285 dev_warn(chg->dev, in smbb_charger_attr_write()
294 rc = regmap_write(chg->regmap, chg->addr + prop->reg, wval); in smbb_charger_attr_write()
296 dev_err(chg->dev, "unable to update %s", prop->name); in smbb_charger_attr_write()
301 dev_warn(chg->dev, in smbb_charger_attr_write()
306 dev_dbg(chg->dev, "%s <= %d\n", prop->name, out); in smbb_charger_attr_write()
308 chg->attr[which] = out; in smbb_charger_attr_write()
313 static int smbb_charger_attr_read(struct smbb_charger *chg, in smbb_charger_attr_read() argument
322 rc = regmap_read(chg->regmap, chg->addr + prop->reg, &val); in smbb_charger_attr_read()
324 dev_err(chg->dev, "failed to read %s\n", prop->name); in smbb_charger_attr_read()
328 dev_dbg(chg->dev, "%s => %d\n", prop->name, val); in smbb_charger_attr_read()
330 chg->attr[which] = val; in smbb_charger_attr_read()
335 static int smbb_charger_attr_parse(struct smbb_charger *chg, in smbb_charger_attr_parse() argument
344 rc = of_property_read_u32(chg->dev->of_node, prop->name, &val); in smbb_charger_attr_parse()
346 rc = smbb_charger_attr_write(chg, which, val); in smbb_charger_attr_parse()
350 return smbb_charger_attr_read(chg, which); in smbb_charger_attr_parse()
353 static void smbb_set_line_flag(struct smbb_charger *chg, int irq, int flag) in smbb_set_line_flag() argument
360 dev_err(chg->dev, "failed to read irq line\n"); in smbb_set_line_flag()
364 mutex_lock(&chg->statlock); in smbb_set_line_flag()
366 chg->status |= flag; in smbb_set_line_flag()
368 chg->status &= ~flag; in smbb_set_line_flag()
369 mutex_unlock(&chg->statlock); in smbb_set_line_flag()
371 dev_dbg(chg->dev, "status = %03lx\n", chg->status); in smbb_set_line_flag()
376 struct smbb_charger *chg = _data; in smbb_usb_valid_handler() local
378 smbb_set_line_flag(chg, irq, STATUS_USBIN_VALID); in smbb_usb_valid_handler()
379 extcon_set_state_sync(chg->edev, EXTCON_USB, in smbb_usb_valid_handler()
380 chg->status & STATUS_USBIN_VALID); in smbb_usb_valid_handler()
381 power_supply_changed(chg->usb_psy); in smbb_usb_valid_handler()
388 struct smbb_charger *chg = _data; in smbb_dc_valid_handler() local
390 smbb_set_line_flag(chg, irq, STATUS_DCIN_VALID); in smbb_dc_valid_handler()
391 if (!chg->dc_disabled) in smbb_dc_valid_handler()
392 power_supply_changed(chg->dc_psy); in smbb_dc_valid_handler()
399 struct smbb_charger *chg = _data; in smbb_bat_temp_handler() local
403 rc = regmap_read(chg->regmap, chg->addr + SMBB_BAT_TEMP_STATUS, &val); in smbb_bat_temp_handler()
407 mutex_lock(&chg->statlock); in smbb_bat_temp_handler()
409 chg->status |= STATUS_BAT_OK; in smbb_bat_temp_handler()
411 chg->status &= ~STATUS_BAT_OK; in smbb_bat_temp_handler()
413 chg->status |= STATUS_BAT_HOT; in smbb_bat_temp_handler()
415 mutex_unlock(&chg->statlock); in smbb_bat_temp_handler()
417 power_supply_changed(chg->bat_psy); in smbb_bat_temp_handler()
423 struct smbb_charger *chg = _data; in smbb_bat_present_handler() local
425 smbb_set_line_flag(chg, irq, STATUS_BAT_PRESENT); in smbb_bat_present_handler()
426 power_supply_changed(chg->bat_psy); in smbb_bat_present_handler()
433 struct smbb_charger *chg = _data; in smbb_chg_done_handler() local
435 smbb_set_line_flag(chg, irq, STATUS_CHG_DONE); in smbb_chg_done_handler()
436 power_supply_changed(chg->bat_psy); in smbb_chg_done_handler()
443 struct smbb_charger *chg = _data; in smbb_chg_gone_handler() local
445 smbb_set_line_flag(chg, irq, STATUS_CHG_GONE); in smbb_chg_gone_handler()
446 power_supply_changed(chg->bat_psy); in smbb_chg_gone_handler()
447 power_supply_changed(chg->usb_psy); in smbb_chg_gone_handler()
448 if (!chg->dc_disabled) in smbb_chg_gone_handler()
449 power_supply_changed(chg->dc_psy); in smbb_chg_gone_handler()
456 struct smbb_charger *chg = _data; in smbb_chg_fast_handler() local
458 smbb_set_line_flag(chg, irq, STATUS_CHG_FAST); in smbb_chg_fast_handler()
459 power_supply_changed(chg->bat_psy); in smbb_chg_fast_handler()
466 struct smbb_charger *chg = _data; in smbb_chg_trkl_handler() local
468 smbb_set_line_flag(chg, irq, STATUS_CHG_TRKL); in smbb_chg_trkl_handler()
469 power_supply_changed(chg->bat_psy); in smbb_chg_trkl_handler()
492 struct smbb_charger *chg = power_supply_get_drvdata(psy); in smbb_usbin_get_property() local
497 mutex_lock(&chg->statlock); in smbb_usbin_get_property()
498 val->intval = !(chg->status & STATUS_CHG_GONE) && in smbb_usbin_get_property()
499 (chg->status & STATUS_USBIN_VALID); in smbb_usbin_get_property()
500 mutex_unlock(&chg->statlock); in smbb_usbin_get_property()
503 val->intval = chg->attr[ATTR_USBIN_IMAX]; in smbb_usbin_get_property()
520 struct smbb_charger *chg = power_supply_get_drvdata(psy); in smbb_usbin_set_property() local
525 rc = smbb_charger_attr_write(chg, ATTR_USBIN_IMAX, in smbb_usbin_set_property()
540 struct smbb_charger *chg = power_supply_get_drvdata(psy); in smbb_dcin_get_property() local
545 mutex_lock(&chg->statlock); in smbb_dcin_get_property()
546 val->intval = !(chg->status & STATUS_CHG_GONE) && in smbb_dcin_get_property()
547 (chg->status & STATUS_DCIN_VALID); in smbb_dcin_get_property()
548 mutex_unlock(&chg->statlock); in smbb_dcin_get_property()
551 val->intval = chg->attr[ATTR_DCIN_IMAX]; in smbb_dcin_get_property()
568 struct smbb_charger *chg = power_supply_get_drvdata(psy); in smbb_dcin_set_property() local
573 rc = smbb_charger_attr_write(chg, ATTR_DCIN_IMAX, in smbb_dcin_set_property()
594 struct smbb_charger *chg = power_supply_get_drvdata(psy); in smbb_battery_get_property() local
598 mutex_lock(&chg->statlock); in smbb_battery_get_property()
599 status = chg->status; in smbb_battery_get_property()
600 mutex_unlock(&chg->statlock); in smbb_battery_get_property()
637 val->intval = chg->attr[ATTR_BAT_IMAX]; in smbb_battery_get_property()
640 val->intval = chg->attr[ATTR_BAT_VMAX]; in smbb_battery_get_property()
664 struct smbb_charger *chg = power_supply_get_drvdata(psy); in smbb_battery_set_property() local
669 rc = smbb_charger_attr_write(chg, ATTR_BAT_IMAX, val->intval); in smbb_battery_set_property()
672 rc = smbb_charger_attr_write(chg, ATTR_BAT_VMAX, val->intval); in smbb_battery_set_property()
790 struct smbb_charger *chg = rdev_get_drvdata(rdev); in smbb_chg_otg_enable() local
793 rc = regmap_update_bits(chg->regmap, chg->addr + SMBB_USB_OTG_CTL, in smbb_chg_otg_enable()
796 dev_err(chg->dev, "failed to update OTG_CTL\n"); in smbb_chg_otg_enable()
802 struct smbb_charger *chg = rdev_get_drvdata(rdev); in smbb_chg_otg_disable() local
805 rc = regmap_update_bits(chg->regmap, chg->addr + SMBB_USB_OTG_CTL, in smbb_chg_otg_disable()
808 dev_err(chg->dev, "failed to update OTG_CTL\n"); in smbb_chg_otg_disable()
814 struct smbb_charger *chg = rdev_get_drvdata(rdev); in smbb_chg_otg_is_enabled() local
818 rc = regmap_read(chg->regmap, chg->addr + SMBB_USB_OTG_CTL, &value); in smbb_chg_otg_is_enabled()
820 dev_err(chg->dev, "failed to read OTG_CTL\n"); in smbb_chg_otg_is_enabled()
836 struct smbb_charger *chg; in smbb_charger_probe() local
840 chg = devm_kzalloc(&pdev->dev, sizeof(*chg), GFP_KERNEL); in smbb_charger_probe()
841 if (!chg) in smbb_charger_probe()
844 chg->dev = &pdev->dev; in smbb_charger_probe()
845 mutex_init(&chg->statlock); in smbb_charger_probe()
847 chg->regmap = dev_get_regmap(pdev->dev.parent, NULL); in smbb_charger_probe()
848 if (!chg->regmap) { in smbb_charger_probe()
853 rc = of_property_read_u32(pdev->dev.of_node, "reg", &chg->addr); in smbb_charger_probe()
859 rc = regmap_read(chg->regmap, chg->addr + SMBB_MISC_REV2, &chg->revision); in smbb_charger_probe()
865 chg->revision += 1; in smbb_charger_probe()
866 if (chg->revision != 2 && chg->revision != 3) { in smbb_charger_probe()
870 dev_info(&pdev->dev, "Initializing SMBB rev %u", chg->revision); in smbb_charger_probe()
872 chg->dc_disabled = of_property_read_bool(pdev->dev.of_node, "qcom,disable-dc"); in smbb_charger_probe()
875 rc = smbb_charger_attr_parse(chg, i); in smbb_charger_probe()
882 bat_cfg.drv_data = chg; in smbb_charger_probe()
884 chg->bat_psy = devm_power_supply_register(&pdev->dev, in smbb_charger_probe()
887 if (IS_ERR(chg->bat_psy)) { in smbb_charger_probe()
889 return PTR_ERR(chg->bat_psy); in smbb_charger_probe()
892 usb_cfg.drv_data = chg; in smbb_charger_probe()
895 chg->usb_psy = devm_power_supply_register(&pdev->dev, in smbb_charger_probe()
898 if (IS_ERR(chg->usb_psy)) { in smbb_charger_probe()
900 return PTR_ERR(chg->usb_psy); in smbb_charger_probe()
903 chg->edev = devm_extcon_dev_allocate(&pdev->dev, smbb_usb_extcon_cable); in smbb_charger_probe()
904 if (IS_ERR(chg->edev)) { in smbb_charger_probe()
909 rc = devm_extcon_dev_register(&pdev->dev, chg->edev); in smbb_charger_probe()
915 if (!chg->dc_disabled) { in smbb_charger_probe()
916 dc_cfg.drv_data = chg; in smbb_charger_probe()
919 chg->dc_psy = devm_power_supply_register(&pdev->dev, in smbb_charger_probe()
922 if (IS_ERR(chg->dc_psy)) { in smbb_charger_probe()
924 return PTR_ERR(chg->dc_psy); in smbb_charger_probe()
938 smbb_charger_irqs[i].handler(irq, chg); in smbb_charger_probe()
942 smbb_charger_irqs[i].name, chg); in smbb_charger_probe()
954 chg->otg_rdesc.id = -1; in smbb_charger_probe()
955 chg->otg_rdesc.name = "otg-vbus"; in smbb_charger_probe()
956 chg->otg_rdesc.ops = &smbb_chg_otg_ops; in smbb_charger_probe()
957 chg->otg_rdesc.owner = THIS_MODULE; in smbb_charger_probe()
958 chg->otg_rdesc.type = REGULATOR_VOLTAGE; in smbb_charger_probe()
959 chg->otg_rdesc.supply_name = "usb-otg-in"; in smbb_charger_probe()
960 chg->otg_rdesc.of_match = "otg-vbus"; in smbb_charger_probe()
963 config.driver_data = chg; in smbb_charger_probe()
965 chg->otg_reg = devm_regulator_register(&pdev->dev, &chg->otg_rdesc, in smbb_charger_probe()
967 if (IS_ERR(chg->otg_reg)) in smbb_charger_probe()
968 return PTR_ERR(chg->otg_reg); in smbb_charger_probe()
970 chg->jeita_ext_temp = of_property_read_bool(pdev->dev.of_node, in smbb_charger_probe()
974 rc = regmap_update_bits(chg->regmap, chg->addr + SMBB_BAT_BTC_CTRL, in smbb_charger_probe()
976 chg->jeita_ext_temp ? in smbb_charger_probe()
982 chg->jeita_ext_temp ? "JEITA extended" : "normal"); in smbb_charger_probe()
989 if (r->rev_mask & BIT(chg->revision)) in smbb_charger_probe()
992 rc = regmap_update_bits(chg->regmap, chg->addr + r->offset, in smbb_charger_probe()
1001 platform_set_drvdata(pdev, chg); in smbb_charger_probe()
1008 struct smbb_charger *chg; in smbb_charger_remove() local
1010 chg = platform_get_drvdata(pdev); in smbb_charger_remove()
1012 regmap_update_bits(chg->regmap, chg->addr + SMBB_CHG_CTRL, CTRL_EN, 0); in smbb_charger_remove()