2003-02-07 09:41:57 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2003-02-07 09:41:57 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef _POWERMGMT_H_
|
|
|
|
#define _POWERMGMT_H_
|
|
|
|
|
2007-08-17 06:45:18 +00:00
|
|
|
#include <stdbool.h>
|
2010-09-03 07:03:07 +00:00
|
|
|
#include "config.h"
|
2007-08-17 06:45:18 +00:00
|
|
|
|
2003-02-07 09:41:57 +00:00
|
|
|
#define POWER_HISTORY_LEN 2*60 /* 2 hours of samples, one per minute */
|
|
|
|
|
2008-12-24 16:58:41 +00:00
|
|
|
enum charge_state_type
|
|
|
|
{
|
2009-01-11 10:07:22 +00:00
|
|
|
/* sorted by increasing charging current (do not change!) */
|
2008-12-21 18:10:36 +00:00
|
|
|
#if CONFIG_CHARGING >= CHARGING_MONITOR
|
2008-12-24 16:58:41 +00:00
|
|
|
CHARGE_STATE_DISABLED = -2, /* Disable charger use (safety measure) */
|
|
|
|
CHARGE_STATE_ERROR = -1, /* Some error occurred that should not allow
|
|
|
|
turning on the charger again by software
|
|
|
|
without user intervention (ie. replug) */
|
2008-12-21 18:10:36 +00:00
|
|
|
#endif
|
2007-08-12 19:49:03 +00:00
|
|
|
DISCHARGING = 0,
|
2008-12-21 18:10:36 +00:00
|
|
|
#if CONFIG_CHARGING >= CHARGING_MONITOR
|
2008-12-24 16:58:41 +00:00
|
|
|
TRICKLE, /* For NiCd, battery maintenence phase */
|
|
|
|
/* For LiIon, low-current precharge phase */
|
|
|
|
TOPOFF, /* For NiCd, waiting for dead zone */
|
2008-12-21 18:10:36 +00:00
|
|
|
/* For LiIon, constant voltage phase */
|
2008-12-24 16:58:41 +00:00
|
|
|
CHARGING, /* For NiCd, main charge phase */
|
|
|
|
/* For LiIon, constant current phase */
|
2008-12-21 18:10:36 +00:00
|
|
|
#endif
|
2008-12-24 16:58:41 +00:00
|
|
|
};
|
2007-08-12 19:49:03 +00:00
|
|
|
|
|
|
|
/* tells what the charger is doing */
|
2008-12-24 16:58:41 +00:00
|
|
|
extern enum charge_state_type charge_state;
|
2007-08-12 19:49:03 +00:00
|
|
|
|
2016-03-30 12:50:40 +00:00
|
|
|
#if CONFIG_CHARGING
|
2007-08-12 19:49:03 +00:00
|
|
|
/*
|
|
|
|
* Flag that the charger has been plugged in/removed: this is set for exactly
|
|
|
|
* one time through the power loop when the charger has been plugged in.
|
|
|
|
*/
|
2008-12-24 16:58:41 +00:00
|
|
|
enum charger_input_state_type
|
|
|
|
{
|
2008-12-21 18:10:36 +00:00
|
|
|
NO_CHARGER = 0, /* No charger is present */
|
|
|
|
CHARGER_UNPLUGGED, /* Transitional state during CHARGER=>NO_CHARGER */
|
|
|
|
CHARGER_PLUGGED, /* Transitional state during NO_CHARGER=>CHARGER */
|
|
|
|
CHARGER /* Charger is present */
|
2008-12-24 16:58:41 +00:00
|
|
|
};
|
2007-08-12 19:49:03 +00:00
|
|
|
|
|
|
|
/* tells the state of the charge input */
|
2008-12-24 16:58:41 +00:00
|
|
|
extern enum charger_input_state_type charger_input_state;
|
|
|
|
|
|
|
|
/* Power input status saved on the power thread each loop */
|
|
|
|
extern unsigned int power_thread_inputs;
|
|
|
|
|
|
|
|
#endif /* CONFIG_CHARGING */
|
|
|
|
|
|
|
|
#if CONFIG_CHARGING == CHARGING_TARGET
|
|
|
|
/* Include target-specific definitions */
|
|
|
|
#include "powermgmt-target.h"
|
2007-08-12 19:49:03 +00:00
|
|
|
#endif
|
|
|
|
|
2011-03-02 19:12:55 +00:00
|
|
|
/* Start up power management thread */
|
|
|
|
void powermgmt_init(void) INIT_ATTR;
|
|
|
|
|
2009-06-29 18:32:43 +00:00
|
|
|
/* Generic current values that are intentionally meaningless - config header
|
2010-03-16 17:13:25 +00:00
|
|
|
* should define proper numbers.*/
|
2020-09-28 19:03:21 +00:00
|
|
|
|
2008-12-24 16:58:41 +00:00
|
|
|
|
|
|
|
#ifndef CURRENT_BACKLIGHT
|
2009-06-29 21:40:03 +00:00
|
|
|
#define CURRENT_BACKLIGHT 5 /* additional current when backlight always on */
|
2007-07-14 14:46:52 +00:00
|
|
|
#endif
|
2008-12-24 16:58:41 +00:00
|
|
|
|
2009-06-29 19:08:03 +00:00
|
|
|
#if defined(HAVE_RECORDING) && !defined(CURRENT_RECORD)
|
2009-06-29 21:40:03 +00:00
|
|
|
#define CURRENT_RECORD 2 /* additional recording current */
|
2009-06-29 19:08:03 +00:00
|
|
|
#endif /* HAVE_RECORDING && !CURRENT_RECORD*/
|
2008-12-24 16:58:41 +00:00
|
|
|
|
|
|
|
#ifndef CURRENT_USB
|
2009-06-29 21:40:03 +00:00
|
|
|
#define CURRENT_USB 2 /* usual current in mA in USB mode */
|
2006-11-11 01:18:57 +00:00
|
|
|
#endif
|
2008-12-24 16:58:41 +00:00
|
|
|
|
2009-06-29 19:08:03 +00:00
|
|
|
#if defined(HAVE_REMOTE_LCD) && !defined(CURRENT_REMOTE)
|
2009-06-29 21:40:03 +00:00
|
|
|
#define CURRENT_REMOTE 2 /* additional current when remote connected */
|
2009-06-29 19:08:03 +00:00
|
|
|
#endif /* CURRENT_REMOTE && !HAVE_REMOTE_LCD */
|
2005-07-05 07:09:19 +00:00
|
|
|
|
2008-12-24 16:58:41 +00:00
|
|
|
#if CONFIG_CHARGING
|
|
|
|
#ifndef CURRENT_MAX_CHG
|
|
|
|
#define CURRENT_MAX_CHG 350 /* maximum charging current */
|
|
|
|
#endif
|
|
|
|
#endif /* CONFIG_CHARGING */
|
|
|
|
|
|
|
|
#ifdef CHARGING_DEBUG_FILE
|
|
|
|
#define POWERMGMT_DEBUG_STACK ((0x1000)/sizeof(long))
|
|
|
|
#else
|
|
|
|
#define POWERMGMT_DEBUG_STACK 0
|
|
|
|
#endif
|
2005-03-03 07:25:43 +00:00
|
|
|
|
2008-12-24 16:58:41 +00:00
|
|
|
#ifndef BATT_AVE_SAMPLES
|
|
|
|
/* slw filter constant unless otherwise specified */
|
|
|
|
#define BATT_AVE_SAMPLES 128
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef POWER_THREAD_STEP_TICKS
|
|
|
|
/* 2HZ sample rate unless otherwise specified */
|
|
|
|
#define POWER_THREAD_STEP_TICKS (HZ/2)
|
2008-12-21 18:10:36 +00:00
|
|
|
#endif
|
|
|
|
|
2003-02-07 09:41:57 +00:00
|
|
|
extern unsigned short power_history[POWER_HISTORY_LEN];
|
2007-08-17 06:45:18 +00:00
|
|
|
extern const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT];
|
|
|
|
extern const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT];
|
|
|
|
extern const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11];
|
|
|
|
#if CONFIG_CHARGING
|
|
|
|
extern const unsigned short percent_to_volt_charge[11];
|
|
|
|
#endif
|
2003-02-07 09:41:57 +00:00
|
|
|
|
2012-01-03 23:44:38 +00:00
|
|
|
/* Returns battery status, filtered for runtime estimation */
|
2006-11-11 01:18:57 +00:00
|
|
|
int battery_level(void); /* percent */
|
2003-02-07 09:41:57 +00:00
|
|
|
int battery_time(void); /* minutes */
|
2012-01-03 23:44:38 +00:00
|
|
|
int battery_voltage(void); /* filtered batt. voltage in millivolts */
|
|
|
|
|
|
|
|
/* Implemented by the target, unfiltered */
|
|
|
|
int _battery_level(void); /* percent */
|
|
|
|
int _battery_time(void); /* minutes */
|
|
|
|
int _battery_voltage(void); /* voltage in millivolts */
|
|
|
|
#if CONFIG_CHARGING >= CHARGING_TARGET
|
|
|
|
void powermgmt_init_target(void);
|
2012-01-07 22:32:52 +00:00
|
|
|
void charging_algorithm_close(void);
|
|
|
|
void charging_algorithm_step(void);
|
2012-01-03 23:44:38 +00:00
|
|
|
#endif
|
2006-01-25 18:29:56 +00:00
|
|
|
|
2008-12-24 16:58:41 +00:00
|
|
|
#ifdef HAVE_BATTERY_SWITCH
|
|
|
|
unsigned int input_millivolts(void); /* voltage that device is running from */
|
2009-01-11 10:07:22 +00:00
|
|
|
#endif /* HAVE_BATTERY_SWITCH */
|
2008-12-24 16:58:41 +00:00
|
|
|
|
2009-01-11 10:07:22 +00:00
|
|
|
#if defined(HAVE_BATTERY_SWITCH) || defined(HAVE_RESET_BATTERY_FILTER)
|
2008-12-21 18:10:36 +00:00
|
|
|
/* Set the filtered battery voltage (to adjust it before beginning a charge
|
2008-12-24 16:58:41 +00:00
|
|
|
* cycle for instance where old, loaded readings will likely be invalid).
|
|
|
|
* Also readjust when battery switch is opened or closed.
|
|
|
|
*/
|
|
|
|
void reset_battery_filter(int millivolts);
|
2009-01-11 10:07:22 +00:00
|
|
|
#endif /* HAVE_BATTERY_SWITCH || HAVE_RESET_BATTERY_FILTER */
|
|
|
|
|
2008-12-21 18:10:36 +00:00
|
|
|
|
2006-10-30 11:33:38 +00:00
|
|
|
/* read unfiltered battery info */
|
2007-08-15 23:57:27 +00:00
|
|
|
void battery_read_info(int *voltage, int *level);
|
2006-10-30 11:33:38 +00:00
|
|
|
|
2003-02-07 09:41:57 +00:00
|
|
|
/* Tells if the battery level is safe for disk writes */
|
|
|
|
bool battery_level_safe(void);
|
|
|
|
|
|
|
|
void set_poweroff_timeout(int timeout);
|
|
|
|
void set_battery_capacity(int capacity); /* set local battery capacity value */
|
2008-12-24 16:58:41 +00:00
|
|
|
int get_battery_capacity(void); /* get local battery capacity value */
|
|
|
|
void set_battery_type(int type); /* set local battery type */
|
2003-02-07 09:41:57 +00:00
|
|
|
|
2012-10-05 19:30:13 +00:00
|
|
|
void set_sleeptimer_duration(int minutes);
|
2003-02-07 09:41:57 +00:00
|
|
|
int get_sleep_timer(void);
|
2011-12-26 09:30:25 +00:00
|
|
|
void set_keypress_restarts_sleep_timer(bool enable);
|
2011-03-08 19:33:30 +00:00
|
|
|
void handle_auto_poweroff(void);
|
2003-10-17 14:49:00 +00:00
|
|
|
void set_car_adapter_mode(bool setting);
|
2004-06-22 07:16:31 +00:00
|
|
|
void reset_poweroff_timer(void);
|
2006-04-16 17:32:54 +00:00
|
|
|
void cancel_shutdown(void);
|
2005-02-06 09:57:57 +00:00
|
|
|
void shutdown_hw(void);
|
2005-09-14 09:08:26 +00:00
|
|
|
void sys_poweroff(void);
|
2008-12-21 18:10:36 +00:00
|
|
|
/* Returns true if the system should force shutdown for some reason -
|
|
|
|
* eg. low battery */
|
|
|
|
bool query_force_shutdown(void);
|
2008-04-20 18:28:25 +00:00
|
|
|
#ifdef HAVE_ACCESSORY_SUPPLY
|
|
|
|
void accessory_supply_set(bool);
|
|
|
|
#endif
|
2010-03-20 15:02:29 +00:00
|
|
|
#ifdef HAVE_LINEOUT_POWEROFF
|
|
|
|
void lineout_set(bool);
|
|
|
|
#endif
|
2008-12-21 18:10:36 +00:00
|
|
|
|
|
|
|
#endif /* _POWERMGMT_H_ */
|