Lines Matching +full:ac +full:- +full:charger
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Battery and Power Management code for the Sharp SL-C7xx and SL-Cxx00
6 * Copyright (c) 2004-2005 Richard Purdie
17 #include <linux/apm-emulation.h>
25 #include <asm/mach-types.h>
27 #include "pxa2xx-regs.h"
28 #include "regs-rtc.h"
173 /* max1111 accepts channels from 0-3, however, in sharpsl_pm_pxa_read_max1111()
174 * it is encoded from 0-7 here in the code. in sharpsl_pm_pxa_read_max1111()
181 int i = sharpsl_pm.machinfo->bat_levels - 1; in get_percentage()
182 …int bl_status = sharpsl_pm.machinfo->backlight_get_status ? sharpsl_pm.machinfo->backlight_get_sta… in get_percentage()
186 …thresh = bl_status ? sharpsl_pm.machinfo->bat_levels_acin_bl : sharpsl_pm.machinfo->bat_levels_aci… in get_percentage()
188 …thresh = bl_status ? sharpsl_pm.machinfo->bat_levels_noac_bl : sharpsl_pm.machinfo->bat_levels_noa… in get_percentage()
191 i--; in get_percentage()
201 high_thresh = sharpsl_pm.machinfo->status_high_acin; in get_apm_status()
202 low_thresh = sharpsl_pm.machinfo->status_low_acin; in get_apm_status()
204 high_thresh = sharpsl_pm.machinfo->status_high_noac; in get_apm_status()
205 low_thresh = sharpsl_pm.machinfo->status_low_noac; in get_apm_status()
227 …sharpsl_pm.battstat.ac_status = (sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_ACIN) ? APM_AC_O… in sharpsl_battery_thread()
230 if (!sharpsl_pm.machinfo->batfull_irq && (sharpsl_pm.charge_mode == CHRG_ON) in sharpsl_battery_thread()
235 voltage = sharpsl_pm.machinfo->read_devdata(SHARPSL_BATT_VOLT); in sharpsl_battery_thread()
240 voltage = sharpsl_pm.machinfo->bat_levels_noac[0].voltage; in sharpsl_battery_thread()
288 dev_dbg(sharpsl_pm.dev, "Turning Charger On\n"); in sharpsl_charge_on()
298 dev_dbg(sharpsl_pm.dev, "Turning Charger Off\n"); in sharpsl_charge_off()
300 sharpsl_pm.machinfo->charge(0); in sharpsl_charge_off()
310 sharpsl_pm.machinfo->charge(0); in sharpsl_charge_error()
316 dev_dbg(sharpsl_pm.dev, "Toggling Charger at time: %lx\n", jiffies); in sharpsl_charge_toggle()
318 if (!sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_ACIN)) { in sharpsl_charge_toggle()
327 sharpsl_pm.machinfo->charge(0); in sharpsl_charge_toggle()
329 sharpsl_pm.machinfo->charge(1); in sharpsl_charge_toggle()
336 int acin = sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_ACIN); in sharpsl_ac_timer()
338 dev_dbg(sharpsl_pm.dev, "AC Status: %d\n", acin); in sharpsl_ac_timer()
365 if (!sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_ACIN)) { in sharpsl_chrg_full_timer()
366 dev_dbg(sharpsl_pm.dev, "Charge Full: AC removed - stop charging!\n"); in sharpsl_chrg_full_timer()
373 dev_dbg(sharpsl_pm.dev, "Charge Full: Interrupt generated too slowly - retry.\n"); in sharpsl_chrg_full_timer()
383 /* Can trigger at the same time as an AC status change so
390 /* delay until after any ac interrupt */ in sharpsl_chrg_full_isr()
400 if (!sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_LOCK)) { in sharpsl_fatal_isr()
405 if (!sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_FATAL)) { in sharpsl_fatal_isr()
442 for (i = 0; i < (SHARPSL_CNV_VALUE_NUM-1); i++) in sharpsl_average_value()
444 sharpsl_ad_index = SHARPSL_CNV_VALUE_NUM - 1; in sharpsl_average_value()
473 for (i = 3; i >= 0; i--) { in get_select_val()
496 sharpsl_pm.machinfo->measure_temp(1); in sharpsl_check_battery_temp()
498 buff[i] = sharpsl_pm.machinfo->read_devdata(SHARPSL_BATT_TEMP); in sharpsl_check_battery_temp()
499 sharpsl_pm.machinfo->measure_temp(0); in sharpsl_check_battery_temp()
505 if (val > sharpsl_pm.machinfo->charge_on_temp) { in sharpsl_check_battery_temp()
507 return -1; in sharpsl_check_battery_temp()
519 sharpsl_pm.machinfo->charge(0); in sharpsl_check_battery_voltage()
520 sharpsl_pm.machinfo->discharge(1); in sharpsl_check_battery_voltage()
523 if (sharpsl_pm.machinfo->discharge1) in sharpsl_check_battery_voltage()
524 sharpsl_pm.machinfo->discharge1(1); in sharpsl_check_battery_voltage()
528 buff[i] = sharpsl_pm.machinfo->read_devdata(SHARPSL_BATT_VOLT); in sharpsl_check_battery_voltage()
532 if (sharpsl_pm.machinfo->discharge1) in sharpsl_check_battery_voltage()
533 sharpsl_pm.machinfo->discharge1(0); in sharpsl_check_battery_voltage()
535 sharpsl_pm.machinfo->discharge(0); in sharpsl_check_battery_voltage()
540 if (val < sharpsl_pm.machinfo->charge_on_volt) in sharpsl_check_battery_voltage()
541 return -1; in sharpsl_check_battery_voltage()
552 buff[i] = sharpsl_pm.machinfo->read_devdata(SHARPSL_ACIN_VOLT); in sharpsl_ac_check()
557 dev_dbg(sharpsl_pm.dev, "AC Voltage: %d\n", temp); in sharpsl_ac_check()
559 …if ((temp > sharpsl_pm.machinfo->charge_acin_high) || (temp < sharpsl_pm.machinfo->charge_acin_low… in sharpsl_ac_check()
560 dev_err(sharpsl_pm.dev, "Error: AC check failed: voltage %d.\n", temp); in sharpsl_ac_check()
561 return -1; in sharpsl_ac_check()
598 /* not charging and AC-IN! */ in corgi_goto_sleep()
600 …if ((sharpsl_pm.flags & SHARPSL_DO_OFFLINE_CHRG) && (sharpsl_pm.machinfo->read_devdata(SHARPSL_STA… in corgi_goto_sleep()
601 dev_dbg(sharpsl_pm.dev, "Activating Offline Charger...\n"); in corgi_goto_sleep()
607 sharpsl_pm.machinfo->presuspend(); in corgi_goto_sleep()
612 …if ((sharpsl_pm.charge_mode == CHRG_ON) && ((alarm_enable && ((alarm_time - RCNR) > (SHARPSL_BATCH… in corgi_goto_sleep()
627 sharpsl_pm.machinfo->postsuspend(); in corgi_goto_sleep()
634 …if (!sharpsl_pm.machinfo->should_wakeup(!(sharpsl_pm.flags & SHARPSL_ALARM_ACTIVE) && alarm_enable… in corgi_enter_suspend()
645 dev_dbg(sharpsl_pm.dev, "User triggered wakeup in offline charger.\n"); in corgi_enter_suspend()
648 if ((!sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_LOCK)) || in corgi_enter_suspend()
649 (!sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_FATAL))) { in corgi_enter_suspend()
670 if (sharpsl_pm.machinfo->earlyresume) in corgi_pxa_pm_enter()
671 sharpsl_pm.machinfo->earlyresume(); in corgi_pxa_pm_enter()
680 dev_err(sharpsl_pm.dev, "Offline Charger: Error occurred.\n"); in sharpsl_off_charge_error()
681 sharpsl_pm.machinfo->charge(0); in sharpsl_off_charge_error()
689 * Return 1 - go straight to sleep
690 * Return 0 - sleep or wakeup depending on other factors
699 dev_dbg(sharpsl_pm.dev, "Offline Charger: Step 1\n"); in sharpsl_off_charge_battery()
701 /* AC Check */ in sharpsl_off_charge_battery()
707 sharpsl_pm.machinfo->charge(0); in sharpsl_off_charge_battery()
709 sharpsl_pm.machinfo->charge(1); in sharpsl_off_charge_battery()
722 dev_dbg(sharpsl_pm.dev, "Offline Charger: Step 2\n"); in sharpsl_off_charge_battery()
727 sharpsl_pm.machinfo->charge(0); in sharpsl_off_charge_battery()
729 sharpsl_pm.machinfo->charge(1); in sharpsl_off_charge_battery()
737 if (sharpsl_pm.machinfo->charger_wakeup()) in sharpsl_off_charge_battery()
740 if ((RCNR - time) > SHARPSL_WAIT_CO_TIME) in sharpsl_off_charge_battery()
742 if (sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_CHRGFULL)) { in sharpsl_off_charge_battery()
743 dev_dbg(sharpsl_pm.dev, "Offline Charger: Charge full occurred. Retrying to check\n"); in sharpsl_off_charge_battery()
745 sharpsl_pm.machinfo->charge(0); in sharpsl_off_charge_battery()
747 sharpsl_pm.machinfo->charge(1); in sharpsl_off_charge_battery()
753 dev_dbg(sharpsl_pm.dev, "Offline Charger: Step 3\n"); in sharpsl_off_charge_battery()
760 if (sharpsl_pm.machinfo->charger_wakeup()) in sharpsl_off_charge_battery()
763 if ((RCNR-time) > SHARPSL_WAIT_CO_TIME) { in sharpsl_off_charge_battery()
765 dev_dbg(sharpsl_pm.dev, "Offline Charger: Not charged sufficiently. Retrying.\n"); in sharpsl_off_charge_battery()
771 if (sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_CHRGFULL)) { in sharpsl_off_charge_battery()
772 dev_dbg(sharpsl_pm.dev, "Offline Charger: Charging complete.\n"); in sharpsl_off_charge_battery()
774 sharpsl_pm.machinfo->charge(0); in sharpsl_off_charge_battery()
802 info->ac_line_status = sharpsl_pm.battstat.ac_status; in sharpsl_apm_get_power_status()
805 info->battery_status = APM_BATTERY_STATUS_CHARGING; in sharpsl_apm_get_power_status()
807 info->battery_status = sharpsl_pm.battstat.mainbat_status; in sharpsl_apm_get_power_status()
809 info->battery_flag = (1 << info->battery_status); in sharpsl_apm_get_power_status()
810 info->battery_life = sharpsl_pm.battstat.mainbat_percent; in sharpsl_apm_get_power_status()
826 if (!pdev->dev.platform_data) in sharpsl_pm_probe()
827 return -EINVAL; in sharpsl_pm_probe()
829 sharpsl_pm.dev = &pdev->dev; in sharpsl_pm_probe()
830 sharpsl_pm.machinfo = pdev->dev.platform_data; in sharpsl_pm_probe()
838 led_trigger_register_simple("sharpsl-charge", &sharpsl_charge_led_trigger); in sharpsl_pm_probe()
840 sharpsl_pm.machinfo->init(); in sharpsl_pm_probe()
842 gpio_request(sharpsl_pm.machinfo->gpio_acin, "AC IN"); in sharpsl_pm_probe()
843 gpio_direction_input(sharpsl_pm.machinfo->gpio_acin); in sharpsl_pm_probe()
844 gpio_request(sharpsl_pm.machinfo->gpio_batfull, "Battery Full"); in sharpsl_pm_probe()
845 gpio_direction_input(sharpsl_pm.machinfo->gpio_batfull); in sharpsl_pm_probe()
846 gpio_request(sharpsl_pm.machinfo->gpio_batlock, "Battery Lock"); in sharpsl_pm_probe()
847 gpio_direction_input(sharpsl_pm.machinfo->gpio_batlock); in sharpsl_pm_probe()
850 irq = gpio_to_irq(sharpsl_pm.machinfo->gpio_acin); in sharpsl_pm_probe()
851 …if (request_irq(irq, sharpsl_ac_isr, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "AC Input Detect"… in sharpsl_pm_probe()
855 irq = gpio_to_irq(sharpsl_pm.machinfo->gpio_batlock); in sharpsl_pm_probe()
860 if (sharpsl_pm.machinfo->gpio_fatal) { in sharpsl_pm_probe()
861 irq = gpio_to_irq(sharpsl_pm.machinfo->gpio_fatal); in sharpsl_pm_probe()
867 if (sharpsl_pm.machinfo->batfull_irq) { in sharpsl_pm_probe()
869 irq = gpio_to_irq(sharpsl_pm.machinfo->gpio_batfull); in sharpsl_pm_probe()
875 ret = device_create_file(&pdev->dev, &dev_attr_battery_percentage); in sharpsl_pm_probe()
876 ret |= device_create_file(&pdev->dev, &dev_attr_battery_voltage); in sharpsl_pm_probe()
878 dev_warn(&pdev->dev, "Failed to register attributes (%d)\n", ret); in sharpsl_pm_probe()
895 device_remove_file(&pdev->dev, &dev_attr_battery_percentage); in sharpsl_pm_remove()
896 device_remove_file(&pdev->dev, &dev_attr_battery_voltage); in sharpsl_pm_remove()
900 free_irq(gpio_to_irq(sharpsl_pm.machinfo->gpio_acin), sharpsl_ac_isr); in sharpsl_pm_remove()
901 free_irq(gpio_to_irq(sharpsl_pm.machinfo->gpio_batlock), sharpsl_fatal_isr); in sharpsl_pm_remove()
903 if (sharpsl_pm.machinfo->gpio_fatal) in sharpsl_pm_remove()
904 free_irq(gpio_to_irq(sharpsl_pm.machinfo->gpio_fatal), sharpsl_fatal_isr); in sharpsl_pm_remove()
906 if (sharpsl_pm.machinfo->batfull_irq) in sharpsl_pm_remove()
907 free_irq(gpio_to_irq(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr); in sharpsl_pm_remove()
909 gpio_free(sharpsl_pm.machinfo->gpio_batlock); in sharpsl_pm_remove()
910 gpio_free(sharpsl_pm.machinfo->gpio_batfull); in sharpsl_pm_remove()
911 gpio_free(sharpsl_pm.machinfo->gpio_acin); in sharpsl_pm_remove()
913 if (sharpsl_pm.machinfo->exit) in sharpsl_pm_remove()
914 sharpsl_pm.machinfo->exit(); in sharpsl_pm_remove()
926 .name = "sharpsl-pm",