From: <cri...@us...> - 2006-10-21 09:47:55
|
Revision: 640 http://svn.sourceforge.net/hackndev/?rev=640&view=rev Author: cristianop Date: 2006-10-21 02:47:47 -0700 (Sat, 21 Oct 2006) Log Message: ----------- palmtx: fixed battery support Modified Paths: -------------- linux4palm/linux/trunk/arch/arm/mach-pxa/palmtx/palmld_ac97.c linux4palm/linux/trunk/arch/arm/mach-pxa/palmtx/palmtx.c Modified: linux4palm/linux/trunk/arch/arm/mach-pxa/palmtx/palmld_ac97.c =================================================================== --- linux4palm/linux/trunk/arch/arm/mach-pxa/palmtx/palmld_ac97.c 2006-10-20 18:49:32 UTC (rev 639) +++ linux4palm/linux/trunk/arch/arm/mach-pxa/palmtx/palmld_ac97.c 2006-10-21 09:47:47 UTC (rev 640) @@ -6,14 +6,8 @@ * Based on palmld_ac97.c code from Alex Osborne * */ + -/* TODO: - - change DIG2_INIT to DIG2_BASE (useless to make an aasignment) - - fix battery code - - add battery charge - - suspend/resume (after having the TX ready for PM ...) -*/ - #include <linux/kernel.h> #include <linux/module.h> #include <linux/moduleparam.h> @@ -91,7 +85,8 @@ static ac97_t *ac97; -static unsigned long last_update = 0; +static int battery_registered = 0; +static unsigned long last_battery_update = 0; static int current_voltage; static int previous_voltage; static u16 d2base; @@ -283,8 +278,93 @@ return IRQ_HANDLED; } +/* battery */ +void palmld_battery_read_adc(int force) +{ + u16 reading; + + if(!force && ((last_battery_update + 10 *HZ) > jiffies)) + return; + + if(down_trylock(&battery_update_mutex)) + return; + + down(&digitiser_sem); + wm97xx_set_digitiser_power(WM97XX_PRP_DET_DIG); + // todo: check if reading is valid + reading = palmld_ac97_take_reading(WM97XX_ADCSEL_BMON); + wm97xx_set_digitiser_power(WM97XX_PRP_DET); + up(&digitiser_sem); + previous_voltage = current_voltage; + current_voltage = reading & 0xfff; + //printk("wm9712: battery -> %d\n", battery_voltage); + last_battery_update = jiffies; + + up(&battery_update_mutex); +} + +int palmld_battery_min_voltage(struct battery *b) +{ + return PALMTX_BAT_MIN_VOLTAGE; +} + + +int palmld_battery_max_voltage(struct battery *b) +{ + return PALMTX_BAT_MAX_VOLTAGE; /* mV */ +} + + + +// let's suppose AVDD=+3.3v so battV = intV * 3 * 0.80586 +// note: 0.80586 = 3.3/4095 +int palmld_battery_get_voltage(struct battery *b) +{ + if (battery_registered){ + palmld_battery_read_adc(0); + return current_voltage * 3 * 80586 / 100000; + } + else{ + printk("palmld_battery: cannot get voltage -> battery driver unuregistered\n"); + return 0; + } +} + + +int palmld_battery_get_status(struct battery *b) +{ + int ac_connected = 0; + + ac_connected = GET_GPIO(GPIO_NR_PALMTX_POWER_DETECT); + + if (current_voltage <= 0) + return BATTERY_STATUS_UNKNOWN; + + if (ac_connected){ + // TODO: ok maybe this is too stupid ... to be reviewed + if ( ( current_voltage > previous_voltage ) || (current_voltage <= PALMTX_BAT_MAX_VOLTAGE) ) + return BATTERY_STATUS_CHARGING; + return BATTERY_STATUS_NOT_CHARGING; + } + else + return BATTERY_STATUS_DISCHARGING; +} + + +struct battery palmtx_battery = { + .name = "palmtx-battery", + .id = "battery0", + .get_min_voltage = palmld_battery_min_voltage, + .get_max_voltage = palmld_battery_max_voltage, + .get_voltage = palmld_battery_get_voltage, + .get_status = palmld_battery_get_status, +}; + + + + static int __init palmld_ac97_probe(struct device *dev) { int err; @@ -347,6 +427,15 @@ palmld_ac97_input->id.bustype = BUS_HOST; input_register_device(palmld_ac97_input); + /* register battery */ + + if(battery_class_register(&palmtx_battery)) { + printk(KERN_ERR "palmld_ac97_probe: could not register battery class\n"); + } + else{ + battery_registered = 1; + } + /* setup work queue */ palmld_ac97_workqueue = create_workqueue(palmld_ac97_WORK_QUEUE_NAME); INIT_WORK(&palmld_ac97_irq_task, palmld_ac97_irq_work, dev); @@ -360,6 +449,7 @@ { // TODO: stop running tasks if any? + battery_class_unregister(&palmtx_battery); ac97 = NULL; input_unregister_device(palmld_ac97_input); return 0; Modified: linux4palm/linux/trunk/arch/arm/mach-pxa/palmtx/palmtx.c =================================================================== --- linux4palm/linux/trunk/arch/arm/mach-pxa/palmtx/palmtx.c 2006-10-20 18:49:32 UTC (rev 639) +++ linux4palm/linux/trunk/arch/arm/mach-pxa/palmtx/palmtx.c 2006-10-21 09:47:47 UTC (rev 640) @@ -146,43 +146,6 @@ }; -// static int palmtx_keypad_matrix[] = { -// /* row 0 */ -// KEY_POWER, -// KEY_F9, -// KEY_ENTER, -// /* row 1 */ -// KEY_F10, -// KEY_F11, -// KEY_F12, -// /* row 2 */ -// KEY_UP, -// -1, -// KEY_DOWN, -// /* row 3 */ -// KEY_RIGHT, -// -1, -// KEY_LEFT, -// }; - - -/* -static struct pxa27x_keypad_platform_data palmtx_keypad_data = { - .matrix = palmtx_keypad_matrix, - .rows = 4, - .cols = 3, -}; - -struct platform_device palmtx_keypad = { - .name = "pxa27x-keypad", - .id = -1, - .dev = { - .platform_data = &palmtx_keypad_data - }, -}; - -*/ - // backlight static struct pxapwmbl_platform_data palmtx_backlight_data = { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |