/*
* Battery and Power Management code for the Sharp SL-C7xx and SL-Cxx00
* series of PDAs
*
* Copyright (c) 2004-2005 Richard Purdie
*
* Based on code written by Sharp for 2.4 kernels
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
#undef DEBUG
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/apm-emulation.h>
#include <linux/timer.h>
#include <linux/delay.h>
#include <linux/leds.h>
#include <linux/suspend.h>
#include <linux/gpio.h>
#include <asm/mach-types.h>
#include <mach/pm.h>
#include <mach/pxa2xx-regs.h>
#include <mach/regs-rtc.h>
#include <mach/sharpsl_pm.h>
/*
* Constants
*/
#define SHARPSL_CHARGE_ON_TIME_INTERVAL (msecs_to_jiffies(1*60*1000)) /* 1 min */
#define SHARPSL_CHARGE_FINISH_TIME (msecs_to_jiffies(10*60*1000)) /* 10 min */
#define SHARPSL_BATCHK_TIME (msecs_to_jiffies(15*1000)) /* 15 sec */
#define SHARPSL_BATCHK_TIME_SUSPEND (60*10) /* 10 min */
#define SHARPSL_WAIT_CO_TIME 15 /* 15 sec */
#define SHARPSL_WAIT_DISCHARGE_ON 100 /* 100 msec */
#define SHARPSL_CHECK_BATTERY_WAIT_TIME_TEMP 10 /* 10 msec */
#define SHARPSL_CHECK_BATTERY_WAIT_TIME_VOLT 10 /* 10 msec */
#define SHARPSL_CHECK_BATTERY_WAIT_TIME_ACIN 10 /* 10 msec */
#define SHARPSL_CHARGE_WAIT_TIME 15 /* 15 msec */
#define SHARPSL_CHARGE_CO_CHECK_TIME 5 /* 5 msec */
#define SHARPSL_CHARGE_RETRY_CNT 1 /* eqv. 10 min */
/*
* Prototypes
*/
#ifdef CONFIG_PM
static int sharpsl_off_charge_battery(void);
static int sharpsl_check_battery_voltage(void);
static int sharpsl_fatal_check(void);
#endif
static int sharpsl_check_battery_temp(void);
static int sharpsl_ac_check(void);
static int sharpsl_average_value(int ad);
static void sharpsl_average_clear(void);
static void sharpsl_charge_toggle(struct work_struct *private_);
static void sharpsl_battery_thread(struct work_struct *private_);
/*
* Variables
*/
struct sharpsl_pm_status sharpsl_pm;
static DECLARE_DELAYED_WORK(toggle_charger, sharpsl_charge_toggle);
static DECLARE_DELAYED_WORK(sharpsl_bat, sharpsl_battery_thread);
DEFINE_LED_TRIGGER(sharpsl_charge_led_trigger);
struct battery_thresh sharpsl_battery_levels_acin[] = {
{ 213, 100},
{ 212, 98},
{ 211, 95},
{ 210, 93},
{ 209, 90},
{ 208, 88},
{ 207, 85},
{ 206, 83},
{ 205, 80},
{ 204, 78},
{ 203, 75},
{ 202, 73},
{ 201, 70},
{ 200, 68},
{ 199, 65},
{ 198, 63},
{ 197, 60},
{ 196, 58},
{ 195, 55},
{ 194, 53},
{ 193, 50},
{ 192, 48},
{ 192, 45},
{ 191, 43},
{ 191, 40},
{ 190, 38},
{ 190, 35},
{ 189, 33},
{ 188, 30},
{ 187, 28},
{ 186, 25},
{ 185, 23},
{ 184, 20},
{ 183, 18},
{ 182, 15},
{ 181, 13},
{ 180, 10},
{ 179, 8},
{ 178, 5},
{ 0, 0},
};
struct battery_thresh sharpsl_battery_levels_noac[] = {
{ 213, 100},
{ 212, 98},
{ 211, 95},
{ 210, 93},
{ 209, 90},
{ 208, 88},
{ 207, 85},
{ 206, 83},
{ 205, 80},
{ 204, 78},
{ 203, 75},
{ 202, 73},
{ 201, 70},
{ 200, 68},
{ 199, 65},
{ 198, 63},
{ 197, 60},
{ 196, 58},
{ 195, 55},
{ 194, 53},
{ 193, 50},
{ 192, 48},
{ 191, 45},
{ 190, 43},
{ 189, 40},
{ 188, 38},
{ 187, 35},
{ 186, 33},
{ 185, 30},
{ 184, 28},
{ 183, 25},
{ 182, 23},
{ 181, 20},
{ 180, 18},
{ 179, 15},
{ 178