Lines Matching refs:di

134 static int ab8500_btemp_batctrl_volt_to_res(struct ab8500_btemp *di,  in ab8500_btemp_batctrl_volt_to_res()  argument
137 if (is_ab8500_1p1_or_earlier(di->parent)) { in ab8500_btemp_batctrl_volt_to_res()
158 static int ab8500_btemp_read_batctrl_voltage(struct ab8500_btemp *di) in ab8500_btemp_read_batctrl_voltage() argument
163 ret = iio_read_channel_processed(di->bat_ctrl, &vbtemp); in ab8500_btemp_read_batctrl_voltage()
165 dev_err(di->dev, in ab8500_btemp_read_batctrl_voltage()
181 static int ab8500_btemp_get_batctrl_res(struct ab8500_btemp *di) in ab8500_btemp_get_batctrl_res() argument
189 if (!di->fg) in ab8500_btemp_get_batctrl_res()
190 di->fg = ab8500_fg_get(); in ab8500_btemp_get_batctrl_res()
191 if (!di->fg) { in ab8500_btemp_get_batctrl_res()
192 dev_err(di->dev, "No fg found\n"); in ab8500_btemp_get_batctrl_res()
196 ret = ab8500_fg_inst_curr_start(di->fg); in ab8500_btemp_get_batctrl_res()
199 dev_err(di->dev, "Failed to start current measurement\n"); in ab8500_btemp_get_batctrl_res()
205 } while (!ab8500_fg_inst_curr_started(di->fg)); in ab8500_btemp_get_batctrl_res()
210 batctrl += ab8500_btemp_read_batctrl_voltage(di); in ab8500_btemp_get_batctrl_res()
213 } while (!ab8500_fg_inst_curr_done(di->fg)); in ab8500_btemp_get_batctrl_res()
216 ret = ab8500_fg_inst_curr_finalize(di->fg, &inst_curr); in ab8500_btemp_get_batctrl_res()
218 dev_err(di->dev, "Failed to finalize current measurement\n"); in ab8500_btemp_get_batctrl_res()
222 res = ab8500_btemp_batctrl_volt_to_res(di, batctrl, inst_curr); in ab8500_btemp_get_batctrl_res()
224 dev_dbg(di->dev, "%s batctrl: %d res: %d inst_curr: %d samples: %d\n", in ab8500_btemp_get_batctrl_res()
238 static int ab8500_btemp_id(struct ab8500_btemp *di) in ab8500_btemp_id() argument
240 struct power_supply_battery_info *bi = di->bm->bi; in ab8500_btemp_id()
243 di->curr_source = BTEMP_BATCTRL_CURR_SRC_7UA; in ab8500_btemp_id()
245 res = ab8500_btemp_get_batctrl_res(di); in ab8500_btemp_id()
247 dev_err(di->dev, "%s get batctrl res failed\n", __func__); in ab8500_btemp_id()
252 dev_info(di->dev, "Battery detected on BATCTRL (pin C3)" in ab8500_btemp_id()
257 dev_warn(di->dev, "Battery identified as unknown" in ab8500_btemp_id()
275 struct ab8500_btemp *di = container_of(work, in ab8500_btemp_periodic_work() local
281 if (!di->initialized) { in ab8500_btemp_periodic_work()
283 if (ab8500_btemp_id(di) < 0) in ab8500_btemp_periodic_work()
284 dev_warn(di->dev, "failed to identify the battery\n"); in ab8500_btemp_periodic_work()
288 ret = thermal_zone_get_temp(di->tz, &bat_temp); in ab8500_btemp_periodic_work()
290 dev_err(di->dev, "error reading temperature\n"); in ab8500_btemp_periodic_work()
304 if ((bat_temp == di->prev_bat_temp) || !di->initialized) { in ab8500_btemp_periodic_work()
305 if ((di->bat_temp != di->prev_bat_temp) || !di->initialized) { in ab8500_btemp_periodic_work()
306 di->initialized = true; in ab8500_btemp_periodic_work()
307 di->bat_temp = bat_temp; in ab8500_btemp_periodic_work()
308 power_supply_changed(di->btemp_psy); in ab8500_btemp_periodic_work()
310 } else if (bat_temp < di->prev_bat_temp) { in ab8500_btemp_periodic_work()
311 di->bat_temp--; in ab8500_btemp_periodic_work()
312 power_supply_changed(di->btemp_psy); in ab8500_btemp_periodic_work()
313 } else if (bat_temp > di->prev_bat_temp) { in ab8500_btemp_periodic_work()
314 di->bat_temp++; in ab8500_btemp_periodic_work()
315 power_supply_changed(di->btemp_psy); in ab8500_btemp_periodic_work()
317 di->prev_bat_temp = bat_temp; in ab8500_btemp_periodic_work()
319 if (di->events.ac_conn || di->events.usb_conn) in ab8500_btemp_periodic_work()
320 interval = di->bm->temp_interval_chg; in ab8500_btemp_periodic_work()
322 interval = di->bm->temp_interval_nochg; in ab8500_btemp_periodic_work()
325 queue_delayed_work(di->btemp_wq, in ab8500_btemp_periodic_work()
326 &di->btemp_periodic_work, in ab8500_btemp_periodic_work()
339 struct ab8500_btemp *di = _di; in ab8500_btemp_batctrlindb_handler() local
340 dev_err(di->dev, "Battery removal detected!\n"); in ab8500_btemp_batctrlindb_handler()
342 di->events.batt_rem = true; in ab8500_btemp_batctrlindb_handler()
343 power_supply_changed(di->btemp_psy); in ab8500_btemp_batctrlindb_handler()
357 struct ab8500_btemp *di = _di; in ab8500_btemp_templow_handler() local
359 if (is_ab8500_3p3_or_earlier(di->parent)) { in ab8500_btemp_templow_handler()
360 dev_dbg(di->dev, "Ignore false btemp low irq" in ab8500_btemp_templow_handler()
363 dev_crit(di->dev, "Battery temperature lower than -10deg c\n"); in ab8500_btemp_templow_handler()
365 di->events.btemp_low = true; in ab8500_btemp_templow_handler()
366 di->events.btemp_high = false; in ab8500_btemp_templow_handler()
367 di->events.btemp_medhigh = false; in ab8500_btemp_templow_handler()
368 di->events.btemp_lowmed = false; in ab8500_btemp_templow_handler()
369 power_supply_changed(di->btemp_psy); in ab8500_btemp_templow_handler()
384 struct ab8500_btemp *di = _di; in ab8500_btemp_temphigh_handler() local
386 dev_crit(di->dev, "Battery temperature is higher than MAX temp\n"); in ab8500_btemp_temphigh_handler()
388 di->events.btemp_high = true; in ab8500_btemp_temphigh_handler()
389 di->events.btemp_medhigh = false; in ab8500_btemp_temphigh_handler()
390 di->events.btemp_lowmed = false; in ab8500_btemp_temphigh_handler()
391 di->events.btemp_low = false; in ab8500_btemp_temphigh_handler()
392 power_supply_changed(di->btemp_psy); in ab8500_btemp_temphigh_handler()
406 struct ab8500_btemp *di = _di; in ab8500_btemp_lowmed_handler() local
408 dev_dbg(di->dev, "Battery temperature is between low and medium\n"); in ab8500_btemp_lowmed_handler()
410 di->events.btemp_lowmed = true; in ab8500_btemp_lowmed_handler()
411 di->events.btemp_medhigh = false; in ab8500_btemp_lowmed_handler()
412 di->events.btemp_high = false; in ab8500_btemp_lowmed_handler()
413 di->events.btemp_low = false; in ab8500_btemp_lowmed_handler()
414 power_supply_changed(di->btemp_psy); in ab8500_btemp_lowmed_handler()
428 struct ab8500_btemp *di = _di; in ab8500_btemp_medhigh_handler() local
430 dev_dbg(di->dev, "Battery temperature is between medium and high\n"); in ab8500_btemp_medhigh_handler()
432 di->events.btemp_medhigh = true; in ab8500_btemp_medhigh_handler()
433 di->events.btemp_lowmed = false; in ab8500_btemp_medhigh_handler()
434 di->events.btemp_high = false; in ab8500_btemp_medhigh_handler()
435 di->events.btemp_low = false; in ab8500_btemp_medhigh_handler()
436 power_supply_changed(di->btemp_psy); in ab8500_btemp_medhigh_handler()
449 static void ab8500_btemp_periodic(struct ab8500_btemp *di, in ab8500_btemp_periodic() argument
452 dev_dbg(di->dev, "Enable periodic temperature measurements: %d\n", in ab8500_btemp_periodic()
458 cancel_delayed_work_sync(&di->btemp_periodic_work); in ab8500_btemp_periodic()
461 queue_delayed_work(di->btemp_wq, &di->btemp_periodic_work, 0); in ab8500_btemp_periodic()
470 static int ab8500_btemp_get_temp(struct ab8500_btemp *di) in ab8500_btemp_get_temp() argument
478 if (is_ab8500_3p3_or_earlier(di->parent)) { in ab8500_btemp_get_temp()
479 temp = di->bat_temp * 10; in ab8500_btemp_get_temp()
481 if (di->events.btemp_low) { in ab8500_btemp_get_temp()
482 if (temp > di->btemp_ranges.btemp_low_limit) in ab8500_btemp_get_temp()
483 temp = di->btemp_ranges.btemp_low_limit * 10; in ab8500_btemp_get_temp()
485 temp = di->bat_temp * 10; in ab8500_btemp_get_temp()
486 } else if (di->events.btemp_high) { in ab8500_btemp_get_temp()
487 if (temp < di->btemp_ranges.btemp_high_limit) in ab8500_btemp_get_temp()
488 temp = di->btemp_ranges.btemp_high_limit * 10; in ab8500_btemp_get_temp()
490 temp = di->bat_temp * 10; in ab8500_btemp_get_temp()
491 } else if (di->events.btemp_lowmed) { in ab8500_btemp_get_temp()
492 if (temp > di->btemp_ranges.btemp_med_limit) in ab8500_btemp_get_temp()
493 temp = di->btemp_ranges.btemp_med_limit * 10; in ab8500_btemp_get_temp()
495 temp = di->bat_temp * 10; in ab8500_btemp_get_temp()
496 } else if (di->events.btemp_medhigh) { in ab8500_btemp_get_temp()
497 if (temp < di->btemp_ranges.btemp_med_limit) in ab8500_btemp_get_temp()
498 temp = di->btemp_ranges.btemp_med_limit * 10; in ab8500_btemp_get_temp()
500 temp = di->bat_temp * 10; in ab8500_btemp_get_temp()
502 temp = di->bat_temp * 10; in ab8500_btemp_get_temp()
525 struct ab8500_btemp *di = power_supply_get_drvdata(psy); in ab8500_btemp_get_property() local
530 if (di->events.batt_rem) in ab8500_btemp_get_property()
536 if (di->bm->bi) in ab8500_btemp_get_property()
537 val->intval = di->bm->bi->technology; in ab8500_btemp_get_property()
542 val->intval = ab8500_btemp_get_temp(di); in ab8500_btemp_get_property()
555 struct ab8500_btemp *di; in ab8500_btemp_get_ext_psy_data() local
560 di = power_supply_get_drvdata(psy); in ab8500_btemp_get_ext_psy_data()
583 if (!ret.intval && di->events.ac_conn) { in ab8500_btemp_get_ext_psy_data()
584 di->events.ac_conn = false; in ab8500_btemp_get_ext_psy_data()
587 else if (ret.intval && !di->events.ac_conn) { in ab8500_btemp_get_ext_psy_data()
588 di->events.ac_conn = true; in ab8500_btemp_get_ext_psy_data()
589 if (!di->events.usb_conn) in ab8500_btemp_get_ext_psy_data()
590 ab8500_btemp_periodic(di, true); in ab8500_btemp_get_ext_psy_data()
595 if (!ret.intval && di->events.usb_conn) { in ab8500_btemp_get_ext_psy_data()
596 di->events.usb_conn = false; in ab8500_btemp_get_ext_psy_data()
599 else if (ret.intval && !di->events.usb_conn) { in ab8500_btemp_get_ext_psy_data()
600 di->events.usb_conn = true; in ab8500_btemp_get_ext_psy_data()
601 if (!di->events.ac_conn) in ab8500_btemp_get_ext_psy_data()
602 ab8500_btemp_periodic(di, true); in ab8500_btemp_get_ext_psy_data()
627 struct ab8500_btemp *di = power_supply_get_drvdata(psy); in ab8500_btemp_external_power_changed() local
630 di->btemp_psy, ab8500_btemp_get_ext_psy_data); in ab8500_btemp_external_power_changed()
644 struct ab8500_btemp *di = dev_get_drvdata(dev); in ab8500_btemp_resume() local
646 ab8500_btemp_periodic(di, true); in ab8500_btemp_resume()
653 struct ab8500_btemp *di = dev_get_drvdata(dev); in ab8500_btemp_suspend() local
655 ab8500_btemp_periodic(di, false); in ab8500_btemp_suspend()
677 struct ab8500_btemp *di = dev_get_drvdata(dev); in ab8500_btemp_bind() local
680 di->btemp_wq = in ab8500_btemp_bind()
682 if (di->btemp_wq == NULL) { in ab8500_btemp_bind()
688 ab8500_btemp_periodic(di, true); in ab8500_btemp_bind()
696 struct ab8500_btemp *di = dev_get_drvdata(dev); in ab8500_btemp_unbind() local
699 destroy_workqueue(di->btemp_wq); in ab8500_btemp_unbind()
711 struct ab8500_btemp *di; in ab8500_btemp_probe() local
715 di = devm_kzalloc(dev, sizeof(*di), GFP_KERNEL); in ab8500_btemp_probe()
716 if (!di) in ab8500_btemp_probe()
719 di->bm = &ab8500_bm_data; in ab8500_btemp_probe()
722 di->dev = dev; in ab8500_btemp_probe()
723 di->parent = dev_get_drvdata(pdev->dev.parent); in ab8500_btemp_probe()
726 di->tz = thermal_zone_get_zone_by_name("battery-thermal"); in ab8500_btemp_probe()
727 if (IS_ERR(di->tz)) { in ab8500_btemp_probe()
728 ret = PTR_ERR(di->tz); in ab8500_btemp_probe()
738 di->bat_ctrl = devm_iio_channel_get(dev, "bat_ctrl"); in ab8500_btemp_probe()
739 if (IS_ERR(di->bat_ctrl)) { in ab8500_btemp_probe()
740 ret = dev_err_probe(dev, PTR_ERR(di->bat_ctrl), in ab8500_btemp_probe()
745 di->initialized = false; in ab8500_btemp_probe()
749 psy_cfg.drv_data = di; in ab8500_btemp_probe()
752 INIT_DEFERRABLE_WORK(&di->btemp_periodic_work, in ab8500_btemp_probe()
756 di->btemp_ranges.btemp_low_limit = BTEMP_THERMAL_LOW_LIMIT; in ab8500_btemp_probe()
757 di->btemp_ranges.btemp_med_limit = BTEMP_THERMAL_MED_LIMIT; in ab8500_btemp_probe()
768 di->btemp_ranges.btemp_high_limit = in ab8500_btemp_probe()
772 di->btemp_ranges.btemp_high_limit = in ab8500_btemp_probe()
776 di->btemp_ranges.btemp_high_limit = in ab8500_btemp_probe()
782 di->btemp_psy = devm_power_supply_register(dev, &ab8500_btemp_desc, in ab8500_btemp_probe()
784 if (IS_ERR(di->btemp_psy)) { in ab8500_btemp_probe()
786 return PTR_ERR(di->btemp_psy); in ab8500_btemp_probe()
798 ab8500_btemp_irq[i].name, di); in ab8500_btemp_probe()
809 platform_set_drvdata(pdev, di); in ab8500_btemp_probe()
811 list_add_tail(&di->node, &ab8500_btemp_list); in ab8500_btemp_probe()