From: <mar...@us...> - 2007-05-28 15:51:29
|
Revision: 1009 http://svn.sourceforge.net/hackndev/?rev=1009&view=rev Author: marex_z71 Date: 2007-05-28 08:51:28 -0700 (Mon, 28 May 2007) Log Message: ----------- PalmTC: touchscreen driver fixes, new battery framework support etc Modified Paths: -------------- linux4palm/linux/trunk/drivers/input/touchscreen/palmtc_ts.c Modified: linux4palm/linux/trunk/drivers/input/touchscreen/palmtc_ts.c =================================================================== --- linux4palm/linux/trunk/drivers/input/touchscreen/palmtc_ts.c 2007-05-28 15:50:47 UTC (rev 1008) +++ linux4palm/linux/trunk/drivers/input/touchscreen/palmtc_ts.c 2007-05-28 15:51:28 UTC (rev 1009) @@ -31,9 +31,8 @@ #include <linux/ctype.h> #include <linux/battery.h> #include <linux/leds.h> +#include <linux/apm-emulation.h> -#include <asm/apm.h> - #include <asm/arch/palmtc-gpio.h> #include <asm/arch/gpio.h> @@ -70,7 +69,7 @@ struct ucb1400_battery_dev bat; -#ifdef CONFIG_APM +#ifdef CONFIG_APM_EMULATION #define APM_MIN_INTERVAL 1000 struct ucb1400 *ucb_static_copy; struct mutex apm_mutex; @@ -82,17 +81,29 @@ static inline u16 ucb1400_reg_read(struct ucb1400 *ucb, u16 reg) { - return ucb->ac97->bus->ops->read(ucb->ac97, reg); + if (ucb->ac97) + return ucb->ac97->bus->ops->read(ucb->ac97, reg); + else + return -1; } static inline void ucb1400_reg_write(struct ucb1400 *ucb, u16 reg, u16 val) { - ucb->ac97->bus->ops->write(ucb->ac97, reg, val); + if (ucb->ac97) + ucb->ac97->bus->ops->write(ucb->ac97, reg, val); } static inline void ucb1400_adc_enable(struct ucb1400 *ucb) { - ucb1400_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA); + u16 val=0; + + ucb1400_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA); + val=ucb1400_reg_read(ucb, UCB_IE_RIS); + ucb1400_reg_write(ucb, UCB_IE_RIS, val | UCB_IE_ADC); + val=ucb1400_reg_read(ucb, UCB_IE_FAL); + ucb1400_reg_write(ucb, UCB_IE_FAL, val | UCB_IE_ADC); + +/* ucb1400_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA); */ } static unsigned int ucb1400_adc_read(struct ucb1400 *ucb, u16 adc_channel) @@ -119,7 +130,16 @@ static inline void ucb1400_adc_disable(struct ucb1400 *ucb) { - ucb1400_reg_write(ucb, UCB_ADC_CR, 0); + u16 val=0; + + val &= ~UCB_ADC_ENA; + ucb1400_reg_write(ucb, UCB_ADC_CR, val); + val=ucb1400_reg_read(ucb, UCB_IE_RIS); + ucb1400_reg_write(ucb, UCB_IE_RIS, val & (~UCB_IE_ADC)); + val=ucb1400_reg_read(ucb, UCB_IE_FAL); + ucb1400_reg_write(ucb, UCB_IE_FAL, val & (~UCB_IE_ADC)); +/* ucb1400_reg_write(ucb, UCB_ADC_CR, 0); +*/ } /* Switch to interrupt mode. */ @@ -338,12 +358,10 @@ */ if ((strlen(buf)>3) && strncmp(buf,"w",1)) { - printk("D'OH! - 1\n"); return -EINVAL; } if ((strlen(buf)>4) && !(strncmp(buf,"w",1))) { - printk("D'OH! - 2\n"); return -EINVAL; } if (!(isdigit(buf[1]))) @@ -426,6 +444,19 @@ } } +int ucb1400_battery_get_capacity(struct battery *b) +{ + if (bat.battery_registered){ + return (((ucb1400_battery_get_voltage(b)-ucb1400_battery_min_voltage(b)) + /(ucb1400_battery_max_voltage(b)-ucb1400_battery_min_voltage(b)))*100); + } + else{ + printk( "ucb1400_battery: cannot get capacity -> " + "battery driver unregistered\n"); + return 0; + } +} + int ucb1400_battery_get_status(struct battery *b) { int ac_connected = gpio_get_value(GPIO_NR_PALMTC_POWER_DETECT); @@ -446,16 +477,56 @@ return BATTERY_STATUS_DISCHARGING; } +int tmp; + +static void *ucb1400_battery_get_property(struct battery *b, enum battery_property bp) +{ + switch (bp) { + case BATTERY_PROP_VOLTAGE_MAX_DESIGN: + tmp = ucb1400_battery_max_voltage(b); + return &tmp; + case BATTERY_PROP_VOLTAGE_MIN_DESIGN: + tmp = ucb1400_battery_min_voltage(b); + return &tmp; + case BATTERY_PROP_CHARGE_FULL_DESIGN: + tmp = 100; + return &tmp; + case BATTERY_PROP_CHARGE_EMPTY_DESIGN: + tmp = 0; + return &tmp; + case BATTERY_PROP_CHARGE_NOW: + tmp = ucb1400_battery_get_capacity(b); + return &tmp; + case BATTERY_PROP_VOLTAGE_NOW: + tmp = ucb1400_battery_get_voltage(b); + return &tmp; + case BATTERY_PROP_STATUS: + tmp = ucb1400_battery_get_status(b); + return &tmp; + default: break; + }; + + return NULL; +} + +static enum battery_property ucb1400_battery_props[] = { + BATTERY_PROP_VOLTAGE_MAX_DESIGN, + BATTERY_PROP_VOLTAGE_MIN_DESIGN, + BATTERY_PROP_CHARGE_FULL_DESIGN, + BATTERY_PROP_CHARGE_EMPTY_DESIGN, + BATTERY_PROP_CHARGE_NOW, + BATTERY_PROP_VOLTAGE_NOW, + BATTERY_PROP_STATUS, +}; + struct battery ucb1400_battery = { - .name = "ucb1400_battery", - .id = "battery0", - .get_min_voltage = ucb1400_battery_min_voltage, - .get_max_voltage = ucb1400_battery_max_voltage, - .get_voltage = ucb1400_battery_get_voltage, - .get_status = ucb1400_battery_get_status, + .name = "ucb1400_battery", + .get_property = ucb1400_battery_get_property, + .properties = ucb1400_battery_props, + .num_properties = ARRAY_SIZE(ucb1400_battery_props), }; -#if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE) +#if defined(CONFIG_APM_EMULATION) || defined(CONFIG_APM_MODULE) static void ucb1400_get_power_status(struct apm_power_info *info) { struct ucb1400 *ucb=ucb_static_copy; @@ -835,7 +906,7 @@ /* register battery to APM layer */ bat.battery_registered = 0; - if(battery_class_register(&ucb1400_battery)) { + if(battery_register(NULL, &ucb1400_battery)) { printk(KERN_ERR "ucb1400_ts: could not register battery class\n"); } else { bat.battery_registered = 1; @@ -856,7 +927,7 @@ ucb_static_copy=ucb; //sorry for this, apm-power-function doesnt have a parm to pass dev... -#ifdef CONFIG_APM +#ifdef CONFIG_APM_EMULATION printk("PROBING BATTERY\n"); pwr_info.ac_line_status=APM_AC_UNKNOWN; pwr_info.battery_status=APM_BATTERY_STATUS_UNKNOWN; @@ -891,7 +962,7 @@ led_classdev_unregister(&ucb1400_gpio_vibra); led_classdev_unregister(&ucb1400_gpio_led); - battery_class_register(&ucb1400_battery); + battery_unregister(&ucb1400_battery); free_irq(ucb->irq, ucb); input_unregister_device(ucb->ts_idev); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |