static int sharpsl_check_battery_voltage(void) { int val, i, buff[5]; /* disable charge, enable discharge */ CHARGE_OFF(); DISCHARGE_ON(); mdelay(SHARPSL_WAIT_DISCHARGE_ON); if (sharpsl_pm.machinfo->discharge1) sharpsl_pm.machinfo->discharge1(1); /* Check battery voltage */ for (i=0; i<5; i++) { buff[i] = sharpsl_read_main_battery(); mdelay(SHARPSL_CHECK_BATTERY_WAIT_TIME_VOLT); } if (sharpsl_pm.machinfo->discharge1) sharpsl_pm.machinfo->discharge1(0); DISCHARGE_OFF(); val = get_select_val(buff); dev_dbg(sharpsl_pm.dev, "Battery Voltage: %d\n", val); if (val < SHARPSL_CHARGE_ON_VOLT) return -1; return 0; }
static int sharpsl_off_charge_error(void) { dev_err(sharpsl_pm.dev, "Offline Charger: Error occured.\n"); CHARGE_OFF(); CHARGE_LED_ERR(); sharpsl_pm.charge_mode = CHRG_ERROR; return 1; }
static void sharpsl_charge_off(void) { dev_dbg(sharpsl_pm.dev, "Turning Charger Off\n"); CHARGE_OFF(); CHARGE_LED_OFF(); sharpsl_pm.charge_mode = CHRG_OFF; schedule_work(&sharpsl_bat); }
void led_state_machine() { uint16_t xval =0; uint16_t yval =0; TOUCH_VAL(&xval, &yval); if(oven_status==Oven_Idle) { if(!((xval + yval)==0)) // Timeout for touch { reset_idle_timer(); } else { if(count_down_time_idle(&idle_timer)) { LCD_BLIGHT_OUTPUT &= ~LCD_BLIGHT; LED_ANI_ON(); CHARGE_OFF(); } } } if(oven_status==Oven_Alarm) { if(check_for_lead_profile()) { if((get_reflow_time_minutes()*60 + get_reflow_time_seconds())>90) { BUZZER_ON(); } else BUZZER_OFF(); } else { if((get_reflow_time_minutes()*60 + get_reflow_time_seconds())>80) { BUZZER_ON(); } else BUZZER_OFF(); } } }
static void sharpsl_charge_toggle(void *private_) { dev_dbg(sharpsl_pm.dev, "Toogling Charger at time: %lx\n", jiffies); if (STATUS_AC_IN() == 0) { sharpsl_charge_off(); return; } else if ((sharpsl_check_battery_temp() < 0) || (sharpsl_ac_check() < 0)) { sharpsl_charge_error(); return; } CHARGE_LED_ON(); CHARGE_OFF(); mdelay(SHARPSL_CHARGE_WAIT_TIME); CHARGE_ON(); sharpsl_pm.charge_start_time = jiffies; }
/* * Check for fatal battery errors * Fatal returns -1 */ static int sharpsl_fatal_check(void) { int buff[5], temp, i, acin; dev_dbg(sharpsl_pm.dev, "sharpsl_fatal_check entered\n"); /* Check AC-Adapter */ acin = STATUS_AC_IN(); if (acin && (sharpsl_pm.charge_mode == CHRG_ON)) { CHARGE_OFF(); udelay(100); DISCHARGE_ON(); /* enable discharge */ mdelay(SHARPSL_WAIT_DISCHARGE_ON); } if (sharpsl_pm.machinfo->discharge1) sharpsl_pm.machinfo->discharge1(1); /* Check battery : check inserting battery ? */ for (i=0; i<5; i++) { buff[i] = sharpsl_read_main_battery(); mdelay(SHARPSL_CHECK_BATTERY_WAIT_TIME_VOLT); } if (sharpsl_pm.machinfo->discharge1) sharpsl_pm.machinfo->discharge1(0); if (acin && (sharpsl_pm.charge_mode == CHRG_ON)) { udelay(100); CHARGE_ON(); DISCHARGE_OFF(); } temp = get_select_val(buff); dev_dbg(sharpsl_pm.dev, "sharpsl_fatal_check: acin: %d, discharge voltage: %d, no discharge: %d\n", acin, temp, sharpsl_read_main_battery()); if ((acin && (temp < SHARPSL_FATAL_ACIN_VOLT)) || (!acin && (temp < SHARPSL_FATAL_NOACIN_VOLT))) return -1; return 0; }
/* * Charging Control while suspended * Return 1 - go straight to sleep * Return 0 - sleep or wakeup depending on other factors */ static int sharpsl_off_charge_battery(void) { int time; dev_dbg(sharpsl_pm.dev, "Charge Mode: %d\n", sharpsl_pm.charge_mode); if (sharpsl_pm.charge_mode == CHRG_OFF) { dev_dbg(sharpsl_pm.dev, "Offline Charger: Step 1\n"); /* AC Check */ if ((sharpsl_ac_check() < 0) || (sharpsl_check_battery_temp() < 0)) return sharpsl_off_charge_error(); /* Start Charging */ CHARGE_LED_ON(); CHARGE_OFF(); mdelay(SHARPSL_CHARGE_WAIT_TIME); CHARGE_ON(); sharpsl_pm.charge_mode = CHRG_ON; sharpsl_pm.full_count = 0; return 1; } else if (sharpsl_pm.charge_mode != CHRG_ON) { return 1; } if (sharpsl_pm.full_count == 0) { int time; dev_dbg(sharpsl_pm.dev, "Offline Charger: Step 2\n"); if ((sharpsl_check_battery_temp() < 0) || (sharpsl_check_battery_voltage() < 0)) return sharpsl_off_charge_error(); CHARGE_OFF(); mdelay(SHARPSL_CHARGE_WAIT_TIME); CHARGE_ON(); sharpsl_pm.charge_mode = CHRG_ON; mdelay(SHARPSL_CHARGE_CO_CHECK_TIME); time = RCNR; while(1) { /* Check if any wakeup event had occured */ if (sharpsl_pm.machinfo->charger_wakeup() != 0) return 0; /* Check for timeout */ if ((RCNR - time) > SHARPSL_WAIT_CO_TIME) return 1; if (STATUS_CHRG_FULL()) { dev_dbg(sharpsl_pm.dev, "Offline Charger: Charge full occured. Retrying to check\n"); sharpsl_pm.full_count++; CHARGE_OFF(); mdelay(SHARPSL_CHARGE_WAIT_TIME); CHARGE_ON(); return 1; } } } dev_dbg(sharpsl_pm.dev, "Offline Charger: Step 3\n"); mdelay(SHARPSL_CHARGE_CO_CHECK_TIME); time = RCNR; while(1) { /* Check if any wakeup event had occured */ if (sharpsl_pm.machinfo->charger_wakeup() != 0) return 0; /* Check for timeout */ if ((RCNR-time) > SHARPSL_WAIT_CO_TIME) { if (sharpsl_pm.full_count > SHARPSL_CHARGE_RETRY_CNT) { dev_dbg(sharpsl_pm.dev, "Offline Charger: Not charged sufficiently. Retrying.\n"); sharpsl_pm.full_count = 0; } sharpsl_pm.full_count++; return 1; } if (STATUS_CHRG_FULL()) { dev_dbg(sharpsl_pm.dev, "Offline Charger: Charging complete.\n"); CHARGE_LED_OFF(); CHARGE_OFF(); sharpsl_pm.charge_mode = CHRG_DONE; return 1; } } }
static void sharpsl_charge_error(void) { CHARGE_LED_ERR(); CHARGE_OFF(); sharpsl_pm.charge_mode = CHRG_ERROR; }