This repository has been archived on 2025-06-06. You can view files and clone it, but cannot push or open issues or pull requests.
Files
android-g900/kernel-2.6.33/arch/arm/mach-pxa/g900/msm6280/msm6280_batt.c
2011-04-04 23:17:39 +06:00

275 lines
6.2 KiB
C
Executable File

/*
*
* Based on arch/arm/mach-pxa/htcblueangel/blueangel_dpram.c
* Autor: Angell Fear <angell@angellfear.ru>
* MSM6280 to PXA270 communication on Dual Port RAM for Toshiba G900
*
*/
#include <linux/module.h>
#include <linux/ioport.h>
#include <linux/init.h>
#include <linux/serial_reg.h>
#include <linux/circ_buf.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/irq.h>
#include <asm/io.h>
#include <asm/mach-types.h>
#include <mach/hardware.h>
#include <asm/irq.h>
#include <mach/pxa2xx-regs.h>
#include <asm/gpio.h>
#include <linux/types.h>
#include <linux/ctype.h>
#include <mach/g900-gpio.h>
#include <linux/pda_power.h>
#include "msm6280.h"
#include <linux/tty.h>
#include <linux/tty_flip.h>
#include <linux/serial_core.h>
int p_BATT_CAPACITY=50;
int p_AC_POWER=0;
#ifdef CONFIG_POWER_SUPPLY
#include <linux/power_supply.h>
static int g900_power_get_property(struct power_supply *psy,
enum power_supply_property prop,
union power_supply_propval *val)
{
int ret = 0;
switch (prop) {
case POWER_SUPPLY_PROP_CAPACITY:
val->intval = p_BATT_CAPACITY;
break;
case POWER_SUPPLY_PROP_TECHNOLOGY: /* All our batteries are Li-ions (right?)*/
val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
break;
case POWER_SUPPLY_PROP_STATUS:
if (p_AC_POWER > 0 && p_BATT_CAPACITY <= 99)
val->intval = POWER_SUPPLY_STATUS_CHARGING;
else if (p_AC_POWER == 1 && p_BATT_CAPACITY > 99)
val->intval = POWER_SUPPLY_STATUS_FULL;
else
val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
break;
case POWER_SUPPLY_PROP_ONLINE: /* either USB or AC */
if (psy->type == POWER_SUPPLY_TYPE_MAINS){ /* AC on/offline*/
if(p_AC_POWER==1){
val->intval = 1;
}else{
val->intval = 0;
}
}else if(psy->type == POWER_SUPPLY_TYPE_USB) { /* USB on/offline */
/*
40 USB detect IRQ
41 USB_P2_7(Client = 1, host =0(up 75,93) )
*/
val->intval =0 ;// (GPIO41_USB_MODE ? 1 : 0); /* TODO!!! */
}else
dvp("POWER_SUPPLY_PROP_ONLINE type = %d = %d \n",psy->type,val->intval);
break;
#define VOLTAGE_MIN 3635000 /* todo */
#define VOLTAGE_MAX 4158000 /* todo */
#define VOLTAGE_STEP ((VOLTAGE_MAX - VOLTAGE_MIN)/100)
/* case POWER_SUPPLY_PROP_BATT_VOL:
val->intval = (p_BATT_CAPACITY * VOLTAGE_STEP ) + VOLTAGE_MIN; //fake !!! percent math
break;
case POWER_SUPPLY_PROP_BATT_TEMP:
val->intval = 27; /// fake !!!
break;
*/
case POWER_SUPPLY_PROP_PRESENT:
val->intval = 0;
break;
case POWER_SUPPLY_PROP_HEALTH:
val->intval = 1;
break;
#if 0
case POWER_SUPPLY_PROP_VOLTAGE_MIN: /* lowest measured value in uV */
val->intval = VOLTAGE_MIN;
break;
case POWER_SUPPLY_PROP_VOLTAGE_MAX: /* highest measured value in uV */
val->intval = VOLTAGE_MAX;
break;
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
val->intval = (p_BATT_CAPACITY * VOLTAGE_STEP ) + VOLTAGE_MIN; /*mV*/ //fake !!! percent math
break;
#endif
default:
ret = -EINVAL;
}
return ret;
}
/* property for AC and USB */
static enum power_supply_property g900_power_line_props[] = {
POWER_SUPPLY_PROP_ONLINE,
};
/* main battery properties */
static enum power_supply_property g900_power_battery_props[] = {
POWER_SUPPLY_PROP_CAPACITY,
POWER_SUPPLY_PROP_TECHNOLOGY,
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_HEALTH,
/* POWER_SUPPLY_PROP_BATT_VOL,
POWER_SUPPLY_PROP_BATT_TEMP,
*/
#if 0
POWER_SUPPLY_PROP_VOLTAGE_MIN,
POWER_SUPPLY_PROP_VOLTAGE_MAX,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
#endif
};
static char *g900_power_supplied_to[] = {
"main-battery",
/* backup-battery could be added if we knew how to access info about it */
};
static struct power_supply g900_psy_ac = {
.name = "ac",
.type = POWER_SUPPLY_TYPE_MAINS,
.supplied_to = g900_power_supplied_to,
.num_supplicants = ARRAY_SIZE(g900_power_supplied_to),
.properties = g900_power_line_props,
.num_properties = ARRAY_SIZE(g900_power_line_props),
.get_property = g900_power_get_property,
};
static struct power_supply g900_psy_usb = {
.name = "usb",
.type = POWER_SUPPLY_TYPE_USB,
.supplied_to = g900_power_supplied_to,
.num_supplicants = ARRAY_SIZE(g900_power_supplied_to),
.properties = g900_power_line_props,
.num_properties = ARRAY_SIZE(g900_power_line_props),
.get_property = g900_power_get_property,
};
static struct power_supply g900_psy_battery = {
.name = "battery",
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = g900_power_battery_props,
.num_properties = ARRAY_SIZE(g900_power_battery_props),
.get_property = g900_power_get_property,
.use_for_apm = 1,
};
#endif
static struct platform_device *pdev;
void msm6280_batt_probe(void){
#ifdef CONFIG_POWER_SUPPLY
int ret;
dvp("batt_probe \n");
pdev = platform_device_register_simple("MSM6280_batt",
0, NULL, 0);
if (IS_ERR(pdev)) {
ret = PTR_ERR(pdev);
dvp("failed to register pdev ret=%d\n",ret);
return;
}
if (power_supply_register(&pdev->dev, &g900_psy_ac) != 0)
dev_err(&pdev->dev, "failed to register %s power supply\n",g900_psy_ac.name);
if (power_supply_register(&pdev->dev, &g900_psy_usb) != 0)
dev_err(&pdev->dev, "failed to register %s power supply\n",g900_psy_usb.name);
if (power_supply_register(&pdev->dev, &g900_psy_battery) != 0)
dev_err(&pdev->dev, "failed to register %s power supply\n",g900_psy_battery.name);
#endif
}
void msm6280_batt_remove(void){
#ifdef CONFIG_POWER_SUPPLY
power_supply_unregister(&g900_psy_ac);
power_supply_unregister(&g900_psy_usb);
power_supply_unregister(&g900_psy_battery);
#endif
}
#ifdef CONFIG_POWER_SUPPLY
void msm6280_battery(char *percent,int acpower)
{
int capacity = 0;
dvp("BATERY %s%% - POWER %d\n",percent,acpower);
capacity = percent[0]-'0';
if((percent[1]-'0') >=0 && (percent[1]-'0') <=9)
{
capacity=(capacity*10)+(percent[1]-'0');
if((percent[2]-'0') >=0 && (percent[2]-'0') <=9)
{
capacity=(capacity*10)+(percent[2]-'0');
}
}
if(p_BATT_CAPACITY != capacity)
{
p_BATT_CAPACITY = capacity;
}
if((acpower >= 0) && (p_AC_POWER != acpower))
{
p_AC_POWER = acpower;
power_supply_changed(&g900_psy_ac);
}
power_supply_changed(&g900_psy_battery);
dvp("BATERY %d%% - POWER %d\n",p_BATT_CAPACITY,p_AC_POWER);
}
#endif