diff options
Diffstat (limited to 'drivers/power')
| -rw-r--r-- | drivers/power/bq27x00_battery.c | 119 | 
1 files changed, 118 insertions, 1 deletions
| diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c index c10f48b20c8..8c1546b7d37 100644 --- a/drivers/power/bq27x00_battery.c +++ b/drivers/power/bq27x00_battery.c @@ -43,8 +43,22 @@  #include <asm/unaligned.h>  #include <linux/wakelock.h> +#include <linux/device.h>  #include <linux/power/bq27x00_battery.h> +#ifdef CONFIG_OLIO_TS81001 +#include "../staging/triune/ts81001.h" +#endif /* CONFIG_OLIO_TS81001 */ + + +#ifdef OLIODEBUG +#define do { olio_debug(format, ...) printk("OLIO %s: ", __FUNCTION__);	\ +		printk(format, ##__VA_ARGS__); } while(0) +#else +#define olio_debug(format, ...)  +#endif + +  #define DRIVER_VERSION			"1.2.0"  #define INVALID_REG_ADDR		0xFF @@ -1170,8 +1184,50 @@ static int bq27x00_battery_current(struct bq27x00_device_info *di,  	return 0;  } +#ifdef CONFIG_OLIO_TS81001 + +static int bq27x00_charger_status(struct bq27x00_device_info *di) { +	struct device * bq = di->dev; +	struct bq27x00_platform_data * pdata = bq->platform_data; +	struct ts81001 * ts81001; +	ts81001_state_t state; + +	olio_debug("entered\n"); + +	ts81001 = (struct ts81001 *) i2c_get_clientdata (pdata->charger_i2c);	 +	 +	if (ts81001 == NULL) { +		olio_debug("Couldn't find charger struct!"); +		return -EINVAL; +	} + +	olio_debug("Got client data for dev %s\n", dev_name(ts81001->dev)); + +	state = ts81001->ops->get_status(ts81001); + +	olio_debug("Got status\n");	 + +	switch (state)  +	{ +	case NOT_CHARGING: +		olio_debug("exiting, DISCHARGING\n"); +		return POWER_SUPPLY_STATUS_DISCHARGING; +	case PRECHARGE: +	case CHARGING_1C: +	case TOPOFF: +		olio_debug("exiting, CHARGING\n"); +		return POWER_SUPPLY_STATUS_CHARGING; +	default: +		olio_debug("Couldn't read status from ts81001 charger.\n"); +		olio_debug("exiting, EINVAL\n"); +		return -EINVAL; +	} +} + +#endif +  static int bq27x00_battery_status(struct bq27x00_device_info *di, -	union power_supply_propval *val) +				  union power_supply_propval *val)  {  	int status; @@ -1187,10 +1243,15 @@ static int bq27x00_battery_status(struct bq27x00_device_info *di,  	} else {  		if (di->cache.flags & BQ27XXX_FLAG_FC)  			status = POWER_SUPPLY_STATUS_FULL; +#ifdef CONFIG_OLIO_TS81001 +		else  +			status = bq27x00_charger_status (di); +#else  		else if (di->cache.flags & BQ27XXX_FLAG_DSC)  			status = POWER_SUPPLY_STATUS_DISCHARGING;  		else  			status = POWER_SUPPLY_STATUS_CHARGING; +#endif /* CONFIG_OLIO_TS81001 */  	}  	val->intval = status; @@ -1681,15 +1742,67 @@ static const struct attribute_group bq27x00_attr_group = {  	.attrs = bq27x00_attributes,  }; +#ifdef CONFIG_OLIO_TS81001 + +/*************************************************************************** + * bq27x00_set_platform_data - act on basic platform data + *  + * We get the name of the charger passed in through the platform data + * structure. Now we need to find the device that it corresponds to, and  + * it's i2c_client structure.  + *  + * Returns: + */ + +static int bq27x00_set_platform_data (struct bq27x00_platform_data * pdata) { +	int retval = 0; + +	olio_debug("entered\n"); + +	pdata->charger_device =  +		bus_find_device_by_name(&i2c_bus_type, +					NULL, +					pdata->charger_name); +	if (pdata->charger_device == NULL) { +		olio_debug("couldn't find charger device by name (name=%s)\n", +			    pdata->charger_name); +		retval = -ENXIO; +	} +	else {  /* device found */ +		pdata->charger_i2c = i2c_verify_client(pdata->charger_device); + +		if (pdata->charger_i2c == NULL) { +			olio_debug("couldn't find i2c_client for device name=%s\n", +				    pdata->charger_name); +			retval = -ENXIO; +		} +	} +	 +	olio_debug("exiting\n"); +		 +	return retval; +} + +#endif /* CONFIG_OLIO_TS81001 */ +  static int __init bq27x00_battery_probe(struct i2c_client *client,  				 const struct i2c_device_id *id)  {  	char *name;  	struct bq27x00_device_info *di; +	struct bq27x00_platform_data *pdata; +	  	int num;  	int retval = 0;  	u8 *regs; +#ifdef CONFIG_OLIO_TS81001 +	pdata = client->dev.platform_data; +	retval = bq27x00_set_platform_data (pdata); +	if (retval < 0)  +		return -EPROBE_DEFER; +#endif /* CONFIG_OLIO_TS81001 */ +  	/* Get new ID for the new battery device */  	retval = idr_pre_get(&battery_id, GFP_KERNEL);  	if (retval == 0) @@ -1988,3 +2101,7 @@ module_exit(bq27x00_battery_exit);  MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");  MODULE_DESCRIPTION("BQ27x00 battery monitor driver");  MODULE_LICENSE("GPL"); + +#ifdef OLIODEBUG +#undef OLIODEBUG +#endif |