diff options
| author | mattis fjallstrom <mattis@acm.org> | 2014-12-16 15:03:26 -0800 | 
|---|---|---|
| committer | mattis fjallstrom <mattis@acm.org> | 2014-12-16 15:03:26 -0800 | 
| commit | 9197dc43519131ccd3241af1f04351468d989fe9 (patch) | |
| tree | 467bed32c55d24994ed9e0896654d9c096be29d6 | |
| parent | c49660a6cce1cd8a2d316a28ed2e2e1d65ff7ec5 (diff) | |
| parent | 2ed3cc87d7a221b3e179917cbe38f340d27d8ab5 (diff) | |
| download | olio-linux-3.10-9197dc43519131ccd3241af1f04351468d989fe9.tar.xz olio-linux-3.10-9197dc43519131ccd3241af1f04351468d989fe9.zip | |
Merge branch 'master' of ssh://internal.oliodevices.com:29418/kernel/omap into android-3.10-bringup
| -rw-r--r-- | arch/arm/mach-omap2/board-omap3h1.c | 2 | ||||
| -rw-r--r-- | drivers/power/bq27x00_battery.c | 1228 | ||||
| -rw-r--r-- | drivers/video/omap2/displays/panel-ili9342.c | 72 | 
3 files changed, 1104 insertions, 198 deletions
| diff --git a/arch/arm/mach-omap2/board-omap3h1.c b/arch/arm/mach-omap2/board-omap3h1.c index 3cf58ab08e9..5c22de9d30f 100644 --- a/arch/arm/mach-omap2/board-omap3h1.c +++ b/arch/arm/mach-omap2/board-omap3h1.c @@ -161,7 +161,7 @@ static struct lm3530_platform_data omap3h1_backlight_platform_data = {  	//.als2_resistor_sel = LM3530_ALS_IMPD_Z,  	//.als_vmin = 730,	/* mV */  	//.als_vmax = 1020,	/* mV */ -	.brt_val = 0x40,	/* Max brightness */ +	.brt_val = 0x64,	/* initial brightness */  };  static struct mxt_platform_data mxt_data = { diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c index 26037ca7efb..98fa8abcae7 100644 --- a/drivers/power/bq27x00_battery.c +++ b/drivers/power/bq27x00_battery.c @@ -22,7 +22,10 @@   * Datasheets:   * http://focus.ti.com/docs/prod/folders/print/bq27000.html   * http://focus.ti.com/docs/prod/folders/print/bq27500.html + * http://www.ti.com/product/bq27411-g1 + * http://www.ti.com/product/bq27421-g1   * http://www.ti.com/product/bq27425-g1 + * http://www.ti.com/product/bq27441-g1   */  #include <linux/module.h> @@ -41,48 +44,215 @@  #define DRIVER_VERSION			"1.2.0" -#define BQ27x00_REG_TEMP		0x06 -#define BQ27x00_REG_VOLT		0x08 -#define BQ27x00_REG_AI			0x14 -#define BQ27x00_REG_FLAGS		0x0A -#define BQ27x00_REG_TTE			0x16 -#define BQ27x00_REG_TTF			0x18 -#define BQ27x00_REG_TTECP		0x26 -#define BQ27x00_REG_NAC			0x0C /* Nominal available capacity */ -#define BQ27x00_REG_LMD			0x12 /* Last measured discharge */ -#define BQ27x00_REG_CYCT		0x2A /* Cycle count total */ -#define BQ27x00_REG_AE			0x22 /* Available energy */ -#define BQ27x00_POWER_AVG		0x24 +#define INVALID_REG_ADDR		0xFF -#define BQ27000_REG_RSOC		0x0B /* Relative State-of-Charge */ -#define BQ27000_REG_ILMD		0x76 /* Initial last measured discharge */ -#define BQ27000_FLAG_EDVF		BIT(0) /* Final End-of-Discharge-Voltage flag */ -#define BQ27000_FLAG_EDV1		BIT(1) /* First End-of-Discharge-Voltage flag */ -#define BQ27000_FLAG_CI			BIT(4) /* Capacity Inaccurate flag */ -#define BQ27000_FLAG_FC			BIT(5) -#define BQ27000_FLAG_CHGS		BIT(7) /* Charge state flag */ +enum bq27xxx_reg_index { +	BQ27XXX_REG_CTRL = 0, +	BQ27XXX_REG_TEMP, +	BQ27XXX_REG_INT_TEMP, +	BQ27XXX_REG_VOLT, +	BQ27XXX_REG_AI, +	BQ27XXX_REG_FLAGS, +	BQ27XXX_REG_TTE, +	BQ27XXX_REG_TTF, +	BQ27XXX_REG_TTES, +	BQ27XXX_REG_TTECP, +	BQ27XXX_REG_NAC, +	BQ27XXX_REG_FCC, +	BQ27XXX_REG_CYCT, +	BQ27XXX_REG_AE, +	BQ27XXX_REG_SOC, +	BQ27XXX_REG_DCAP, +	BQ27XXX_POWER_AVG, +	NUM_REGS +}; + +/* bq27500 registers */ +static __initdata u8 bq27500_regs[NUM_REGS] = { +	0x00,	/* CONTROL	*/ +	0x06,	/* TEMP		*/ +	0xFF,	/* INT TEMP -NA	*/ +	0x08,	/* VOLT		*/ +	0x14,	/* AVG CURR	*/ +	0x0A,	/* FLAGS	*/ +	0x16,	/* TTE		*/ +	0x18,	/* TTF		*/ +	0x1c,	/* TTES		*/ +	0x26,	/* TTECP	*/ +	0x0C,	/* NAC		*/ +	0x12,	/* LMD(FCC)	*/ +	0x2A,	/* CYCT		*/ +	0x22,	/* AE		*/ +	0x2C,	/* SOC(RSOC)	*/ +	0x3C,	/* DCAP(ILMD)	*/ +	0x24,	/* AP		*/ +}; + +/* bq27520 registers */ +static __initdata u8 bq27520_regs[] = { +	0x00,	/* CONTROL	*/ +	0x06,	/* TEMP		*/ +	0xFF,	/* INT TEMP - NA*/ +	0x08,	/* VOLT		*/ +	0x14,	/* AVG CURR	*/ +	0x0A,	/* FLAGS	*/ +	0x16,	/* TTE		*/ +	0x18,	/* TTF		*/ +	0x1c,	/* TTES		*/ +	0x26,	/* TTECP	*/ +	0x0C,	/* NAC		*/ +	0x12,	/* LMD		*/ +	0xFF,	/* CYCT - NA	*/ +	0x22,	/* AE		*/ +	0x2C,	/* SOC(RSOC	*/ +	0xFF,	/* DCAP(ILMD) - NA */ +	0x24,	/* AP		*/ +}; + +/* bq2753x registers */ +static __initdata u8 bq2753x_regs[] = { +	0x00,	/* CONTROL	*/ +	0x06,	/* TEMP		*/ +	0xFF,	/* INT TEMP - NA*/ +	0x08,	/* VOLT		*/ +	0x14,	/* AVG CURR	*/ +	0x0A,	/* FLAGS	*/ +	0x16,	/* TTE		*/ +	0xFF,	/* TTF - NA	*/ +	0xFF,	/* TTES - NA	*/ +	0xFF,	/* TTECP - NA	*/ +	0x0C,	/* NAC		*/ +	0x12,	/* LMD(FCC)	*/ +	0x2A,	/* CYCT		*/ +	0xFF,	/* AE - NA	*/ +	0x2C,	/* SOC(RSOC)	*/ +	0xFF,	/* DCAP(ILMD) - NA */ +	0x24,	/* AP		*/ +}; + +/* bq27200 registers */ +static __initdata u8 bq27200_regs[NUM_REGS] = { +	0x00,	/* CONTROL	*/ +	0x06,	/* TEMP		*/ +	0xFF,	/* INT TEMP - NA	*/ +	0x08,	/* VOLT		*/ +	0x14,	/* AVG CURR	*/ +	0x0A,	/* FLAGS	*/ +	0x16,	/* TTE		*/ +	0x18,	/* TTF		*/ +	0x1c,	/* TTES		*/ +	0x26,	/* TTECP	*/ +	0x0C,	/* NAC		*/ +	0x12,	/* LMD(FCC)	*/ +	0x2A,	/* CYCT		*/ +	0x22,	/* AE		*/ +	0x0B,	/* SOC(RSOC)	*/ +	0x76,	/* DCAP(ILMD)	*/ +	0x24,	/* AP		*/ +}; + +/* bq274xx registers */ +static __initdata u8 bq274xx_regs[NUM_REGS] = { +	0x00,	/* CONTROL	*/ +	0x02,	/* TEMP		*/ +	0x1e,	/* INT TEMP	*/ +	0x04,	/* VOLT		*/ +	0x10,	/* AVG CURR	*/ +	0x06,	/* FLAGS	*/ +	0xFF,	/* TTE - NA	*/ +	0xFF,	/* TTF - NA	*/ +	0xFF,	/* TTES - NA	*/ +	0xFF,	/* TTECP - NA	*/ +	0x08,	/* NAC		*/ +	0x0E,	/* FCC		*/ +	0xFF,	/* CYCT - NA	*/ +	0xFF,	/* AE - NA	*/ +	0x1C,	/* SOC		*/ +	0x3C,	/* DCAP - NA	*/ +	0x18,	/* AP		*/ +}; + +/* bq276xx registers - same as bq274xx except CYCT */ +static __initdata u8 bq276xx_regs[NUM_REGS] = { +	0x00,	/* CONTROL	*/ +	0x02,	/* TEMP		*/ +	0x1e,	/* INT TEMP	*/ +	0x04,	/* VOLT		*/ +	0x10,	/* AVG CURR	*/ +	0x06,	/* FLAGS	*/ +	0xFF,	/* TTE - NA	*/ +	0xFF,	/* TTF - NA	*/ +	0xFF,	/* TTES - NA	*/ +	0xFF,	/* TTECP - NA	*/ +	0x08,	/* NAC		*/ +	0x0E,	/* FCC		*/ +	0x22,	/* CYCT		*/ +	0xFF,	/* AE - NA	*/ +	0x1C,	/* SOC		*/ +	0x3C,	/* DCAP - NA	*/ +	0x18,	/* AP		*/ +}; + +/* + * SBS Commands for DF access - these are pretty standard + * So, no need to go in the command array + */ +#define BLOCK_DATA_CLASS		0x3E +#define DATA_BLOCK			0x3F +#define BLOCK_DATA			0x40 +#define BLOCK_DATA_CHECKSUM		0x60 +#define BLOCK_DATA_CONTROL		0x61 + +/* bq274xx/bq276xx specific command information */ +#define BQ274XX_UNSEAL_KEY		0x80008000 +#define BQ274XX_SOFT_RESET		0x43 + +#define BQ274XX_FLAG_ITPOR				0x20 +#define BQ274XX_CTRL_STATUS_INITCOMP	0x80 -#define BQ27500_REG_SOC			0x2C -#define BQ27500_REG_DCAP		0x3C /* Design capacity */ -#define BQ27500_FLAG_DSC		BIT(0) -#define BQ27500_FLAG_SOCF		BIT(1) /* State-of-Charge threshold final */ -#define BQ27500_FLAG_SOC1		BIT(2) /* State-of-Charge threshold 1 */ -#define BQ27500_FLAG_FC			BIT(9) -#define BQ27500_FLAG_OTC		BIT(15) +#define BQ27XXX_FLAG_DSC		BIT(0) +#define BQ27XXX_FLAG_SOCF		BIT(1) /* State-of-Charge threshold final */ +#define BQ27XXX_FLAG_SOC1		BIT(2) /* State-of-Charge threshold 1 */ +#define BQ27XXX_FLAG_FC			BIT(9) +#define BQ27XXX_FLAG_OTD		BIT(14) +#define BQ27XXX_FLAG_OTC		BIT(15) -/* bq27425 register addresses are same as bq27x00 addresses minus 4 */ -#define BQ27425_REG_OFFSET		0x04 -#define BQ27425_REG_SOC			0x18 /* Register address plus offset */ +/* BQ27000 has different layout for Flags register */ +#define BQ27200_FLAG_EDVF		BIT(0) /* Final End-of-Discharge-Voltage flag */ +#define BQ27200_FLAG_EDV1		BIT(1) /* First End-of-Discharge-Voltage flag */ +#define BQ27200_FLAG_CI			BIT(4) /* Capacity Inaccurate flag */ +#define BQ27200_FLAG_FC			BIT(5) +#define BQ27200_FLAG_CHGS		BIT(7) /* Charge state flag */ -#define BQ27000_RS			20 /* Resistor sense */ -#define BQ27x00_POWER_CONSTANT		(256 * 29200 / 1000) +#define BQ27200_RS			20 /* Resistor sense */ +#define BQ27200_POWER_CONSTANT		(256 * 29200 / 1000) + +/* Subcommands of Control() */ +#define CONTROL_STATUS_SUBCMD		0x0000 +#define DEV_TYPE_SUBCMD			0x0001 +#define FW_VER_SUBCMD			0x0002 +#define DF_VER_SUBCMD			0x001F +#define RESET_SUBCMD			0x0041 +#define SET_CFGUPDATE_SUBCMD		0x0013 +#define SEAL_SUBCMD			0x0020 + +/* Location of SEAL enable bit in bq276xx DM */ +#define BQ276XX_OP_CFG_B_SUBCLASS	64 +#define BQ276XX_OP_CFG_B_OFFSET		2 +#define BQ276XX_OP_CFG_B_DEF_SEAL_BIT	(1 << 5)  struct bq27x00_device_info;  struct bq27x00_access_methods {  	int (*read)(struct bq27x00_device_info *di, u8 reg, bool single); +	int (*write)(struct bq27x00_device_info *di, u8 reg, int value, +			bool single); +	int (*blk_read)(struct bq27x00_device_info *di, u8 reg, u8 *data, +		u8 sz); +	int (*blk_write)(struct bq27x00_device_info *di, u8 reg, u8 *data, +		u8 sz);  }; -enum bq27x00_chip { BQ27000, BQ27500, BQ27425}; +enum bq27x00_chip { BQ27200, BQ27500, BQ27520, BQ274XX, BQ276XX, BQ2753X};  struct bq27x00_reg_cache {  	int temperature; @@ -98,6 +268,13 @@ struct bq27x00_reg_cache {  	int health;  }; +struct dm_reg { +	u8 subclass; +	u8 offset; +	u8 len; +	u32 data; +}; +  struct bq27x00_device_info {  	struct device 		*dev;  	int			id; @@ -114,9 +291,15 @@ struct bq27x00_device_info {  	struct bq27x00_access_methods bus;  	struct mutex lock; + +	int fw_ver; +	int df_ver; +	u8 regs[NUM_REGS]; +	struct dm_reg *dm_regs; +	u16 dm_regs_count;  }; -static enum power_supply_property bq27x00_battery_props[] = { +static __initdata enum power_supply_property bq27x00_battery_props[] = {  	POWER_SUPPLY_PROP_STATUS,  	POWER_SUPPLY_PROP_PRESENT,  	POWER_SUPPLY_PROP_VOLTAGE_NOW, @@ -137,7 +320,57 @@ static enum power_supply_property bq27x00_battery_props[] = {  	POWER_SUPPLY_PROP_HEALTH,  }; -static enum power_supply_property bq27425_battery_props[] = { +static __initdata enum power_supply_property bq27520_battery_props[] = { +	POWER_SUPPLY_PROP_STATUS, +	POWER_SUPPLY_PROP_PRESENT, +	POWER_SUPPLY_PROP_VOLTAGE_NOW, +	POWER_SUPPLY_PROP_CURRENT_NOW, +	POWER_SUPPLY_PROP_CAPACITY, +	POWER_SUPPLY_PROP_CAPACITY_LEVEL, +	POWER_SUPPLY_PROP_TEMP, +	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, +	POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, +	POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, +	POWER_SUPPLY_PROP_TECHNOLOGY, +	POWER_SUPPLY_PROP_CHARGE_FULL, +	POWER_SUPPLY_PROP_CHARGE_NOW, +	POWER_SUPPLY_PROP_ENERGY_NOW, +	POWER_SUPPLY_PROP_POWER_AVG, +	POWER_SUPPLY_PROP_HEALTH, +}; + +static __initdata enum power_supply_property bq2753x_battery_props[] = { +	POWER_SUPPLY_PROP_STATUS, +	POWER_SUPPLY_PROP_PRESENT, +	POWER_SUPPLY_PROP_VOLTAGE_NOW, +	POWER_SUPPLY_PROP_CURRENT_NOW, +	POWER_SUPPLY_PROP_CAPACITY, +	POWER_SUPPLY_PROP_CAPACITY_LEVEL, +	POWER_SUPPLY_PROP_TEMP, +	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, +	POWER_SUPPLY_PROP_TECHNOLOGY, +	POWER_SUPPLY_PROP_CHARGE_FULL, +	POWER_SUPPLY_PROP_CHARGE_NOW, +	POWER_SUPPLY_PROP_POWER_AVG, +	POWER_SUPPLY_PROP_HEALTH, +	POWER_SUPPLY_PROP_CYCLE_COUNT, +}; + +static __initdata enum power_supply_property bq274xx_battery_props[] = { +	POWER_SUPPLY_PROP_STATUS, +	POWER_SUPPLY_PROP_PRESENT, +	POWER_SUPPLY_PROP_VOLTAGE_NOW, +	POWER_SUPPLY_PROP_CURRENT_NOW, +	POWER_SUPPLY_PROP_CAPACITY, +	POWER_SUPPLY_PROP_CAPACITY_LEVEL, +	POWER_SUPPLY_PROP_TEMP, +	POWER_SUPPLY_PROP_TECHNOLOGY, +	POWER_SUPPLY_PROP_CHARGE_FULL, +	POWER_SUPPLY_PROP_CHARGE_NOW, +	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, +}; + +static __initdata enum power_supply_property bq276xx_battery_props[] = {  	POWER_SUPPLY_PROP_STATUS,  	POWER_SUPPLY_PROP_PRESENT,  	POWER_SUPPLY_PROP_VOLTAGE_NOW, @@ -149,6 +382,31 @@ static enum power_supply_property bq27425_battery_props[] = {  	POWER_SUPPLY_PROP_CHARGE_FULL,  	POWER_SUPPLY_PROP_CHARGE_NOW,  	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, +	POWER_SUPPLY_PROP_CYCLE_COUNT, +}; + +/* + * Ordering the parameters based on subclass and then offset will help in + * having fewer flash writes while updating. + * Customize these values and, if necessary, add more based on system needs. + */ +static struct dm_reg bq274xx_dm_regs[] = { +	{82, 0, 2, 1000},	/* Qmax */ +	{82, 5, 1, 0x81},	/* Load Select */ +	{82, 10, 2, 1340},	/* Design Capacity */ +	{82, 12, 2, 3700},	/* Design Energy */ +	{82, 16, 2, 3250},	/* Terminate Voltage */ +	{82, 27, 2, 110},	/* Taper rate */ +}; + +static struct dm_reg bq276xx_dm_regs[] = { +	{64, 2, 1, 0x2C},	/* Op Config B */ +	{82, 0, 2, 1000},	/* Qmax */ +	{82, 2, 1, 0x81},	/* Load Select */ +	{82, 3, 2, 1340},	/* Design Capacity */ +	{82, 5, 2, 3700},	/* Design Energy */ +	{82, 9, 2, 3250},	/* Terminate Voltage */ +	{82, 20, 2, 110},	/* Taper rate */  };  static unsigned int poll_interval = 360; @@ -157,48 +415,319 @@ MODULE_PARM_DESC(poll_interval, "battery poll interval in seconds - " \  				"0 disables polling");  /* + * Forward Declarations + */ +static int read_dm_block(struct bq27x00_device_info *di, u8 subclass, +	u8 offset, u8 *data); + + +/*   * Common code for BQ27x00 devices   */ -static inline int bq27x00_read(struct bq27x00_device_info *di, u8 reg, +static inline int bq27xxx_read(struct bq27x00_device_info *di, int reg_index,  		bool single)  { -	if (di->chip == BQ27425) -		return di->bus.read(di, reg - BQ27425_REG_OFFSET, single); -	return di->bus.read(di, reg, single); +	int val; + +	/* Reports 0 for invalid/missing registers */ +	if (!di || di->regs[reg_index] == INVALID_REG_ADDR) +		return 0; + +	val = di->bus.read(di, di->regs[reg_index], single); + +	return val;  } +static inline int bq27xxx_write(struct bq27x00_device_info *di, int reg_index, +		int value, bool single) +{ +	if (!di || di->regs[reg_index] == INVALID_REG_ADDR) +		return -1; + +	return di->bus.write(di, di->regs[reg_index], value, single); +} + +static int control_cmd_wr(struct bq27x00_device_info *di, u16 cmd) +{ +	dev_dbg(di->dev, "%s: cmd - %04x\n", __func__, cmd); + +	return di->bus.write(di, BQ27XXX_REG_CTRL, cmd, false); +} + +static int control_cmd_read(struct bq27x00_device_info *di, u16 cmd) +{ +	dev_dbg(di->dev, "%s: cmd - %04x\n", __func__, cmd); + +	di->bus.write(di, BQ27XXX_REG_CTRL, cmd, false); + +	msleep(5); + +	return di->bus.read(di, BQ27XXX_REG_CTRL, false); +}  /* - * Higher versions of the chip like BQ27425 and BQ27500 - * differ from BQ27000 and BQ27200 in calculation of certain - * parameters. Hence we need to check for the chip type. + * It is assumed that the gauge is in unsealed mode when this function + * is called   */ -static bool bq27xxx_is_chip_version_higher(struct bq27x00_device_info *di) +static int bq276xx_seal_enabled(struct bq27x00_device_info *di)  { -	if (di->chip == BQ27425 || di->chip == BQ27500) -		return true; -	return false; +	u8 buf[32]; +	u8 op_cfg_b; + +	if (!read_dm_block(di, BQ276XX_OP_CFG_B_SUBCLASS, +		BQ276XX_OP_CFG_B_OFFSET, buf)) { +		return 1; /* Err on the side of caution and try to seal */ +	} + +	op_cfg_b = buf[BQ276XX_OP_CFG_B_OFFSET & 0x1F]; + +	if (op_cfg_b & BQ276XX_OP_CFG_B_DEF_SEAL_BIT) +		return 1; + +	return 0; +} + +#define SEAL_UNSEAL_POLLING_RETRY_LIMIT	1000 + +static inline int sealed(struct bq27x00_device_info *di) +{ +	return control_cmd_read(di, CONTROL_STATUS_SUBCMD) & (1 << 13); +} + +static int unseal(struct bq27x00_device_info *di, u32 key) +{ +	int i = 0; + +	dev_dbg(di->dev, "%s: key - %08x\n", __func__, key); + +	if (!sealed(di)) +		goto out; + +	di->bus.write(di, BQ27XXX_REG_CTRL, key & 0xFFFF, false); +	msleep(5); +	di->bus.write(di, BQ27XXX_REG_CTRL, (key & 0xFFFF0000) >> 16, false); +	msleep(5); + +	while (i < SEAL_UNSEAL_POLLING_RETRY_LIMIT) { +		i++; +		if (!sealed(di)) +			break; +		msleep(10); +	} + +out: +	if (i == SEAL_UNSEAL_POLLING_RETRY_LIMIT) { +		dev_err(di->dev, "%s: failed\n", __func__); +		return 0; +	} else { +		return 1; +	} +} + +static int seal(struct bq27x00_device_info *di) +{ +	int i = 0; +	int is_sealed; + +	dev_dbg(di->dev, "%s:\n", __func__); + +	is_sealed = sealed(di); +	if (is_sealed) +		return is_sealed; + +	if (di->chip == BQ276XX && !bq276xx_seal_enabled(di)) { +		dev_dbg(di->dev, "%s: sealing is not enabled\n", __func__); +		return is_sealed; +	} + +	di->bus.write(di, BQ27XXX_REG_CTRL, SEAL_SUBCMD, false); + +	while (i < SEAL_UNSEAL_POLLING_RETRY_LIMIT) { +		i++; +		is_sealed = sealed(di); +		if (is_sealed) +			break; +		msleep(10); +	} + +	if (!is_sealed) +		dev_err(di->dev, "%s: failed\n", __func__); + +	return is_sealed; +} + +#define CFG_UPDATE_POLLING_RETRY_LIMIT 50 +static int enter_cfg_update_mode(struct bq27x00_device_info *di) +{ +	int i = 0; +	u16 flags; + +	dev_dbg(di->dev, "%s:\n", __func__); + +	if (!unseal(di, BQ274XX_UNSEAL_KEY)) +		return 0; + +	control_cmd_wr(di, SET_CFGUPDATE_SUBCMD); +	msleep(5); + +	while (i < CFG_UPDATE_POLLING_RETRY_LIMIT) { +		i++; +		flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, false); +		if (flags & (1 << 4)) +			break; +		msleep(100); +	} + +	if (i == CFG_UPDATE_POLLING_RETRY_LIMIT) { +		dev_err(di->dev, "%s: failed %04x\n", __func__, flags); +		return 0; +	} + +	return 1; +} + +static int exit_cfg_update_mode(struct bq27x00_device_info *di) +{ +	int i = 0; +	u16 flags; + +	dev_dbg(di->dev, "%s:\n", __func__); + +	control_cmd_wr(di, BQ274XX_SOFT_RESET); + +	while (i < CFG_UPDATE_POLLING_RETRY_LIMIT) { +		i++; +		flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, false); +		if (!(flags & (1 << 4))) +			break; +		msleep(100); +	} + +	if (i == CFG_UPDATE_POLLING_RETRY_LIMIT) { +		dev_err(di->dev, "%s: failed %04x\n", __func__, flags); +		return 0; +	} + +	if (seal(di)) +		return 1; +	else +		return 0; +} +static u8 checksum(u8 *data) +{ +	u16 sum = 0; +	int i; + +	for (i = 0; i < 32; i++) +		sum += data[i]; + +	sum &= 0xFF; + +	return 0xFF - sum; +} + +#ifdef DEBUG +static void print_buf(const char *msg, u8 *buf) +{ +	int i; + +	printk("\nbq: %s buf: ", msg); +	for (i = 0; i < 32; i++) +		printk("%02x ", buf[i]); + +	printk("\n"); +} +#else +#define print_buf(a, b) +#endif + +static int update_dm_block(struct bq27x00_device_info *di, u8 subclass, +	u8 offset, u8 *data) +{ +	u8 buf[32]; +	u8 cksum; +	u8 blk_offset = offset >> 5; + +	dev_dbg(di->dev, "%s: subclass %d offset %d\n", +		__func__, subclass, offset); + +	di->bus.write(di, BLOCK_DATA_CONTROL, 0, true); +	msleep(5); + +	di->bus.write(di, BLOCK_DATA_CLASS, subclass, true); +	msleep(5); + +	di->bus.write(di, DATA_BLOCK, blk_offset, true); +	msleep(5); + +	di->bus.blk_write(di, BLOCK_DATA, data, 32); +	msleep(5); +	print_buf(__func__, data); + +	cksum = checksum(data); +	di->bus.write(di, BLOCK_DATA_CHECKSUM, cksum, true); +	msleep(5); + +	/* Read back and compare to make sure write is successful */ +	di->bus.write(di, DATA_BLOCK, blk_offset, true); +	msleep(5); +	di->bus.blk_read(di, BLOCK_DATA, buf, 32); +	if (memcmp(data, buf, 32)) { +		dev_err(di->dev, "%s: error updating subclass %d offset %d\n", +			__func__, subclass, offset); +		return 0; +	} else { +		return 1; +	} +} + +static int read_dm_block(struct bq27x00_device_info *di, u8 subclass, +	u8 offset, u8 *data) +{ +	u8 cksum_calc, cksum; +	u8 blk_offset = offset >> 5; + +	dev_dbg(di->dev, "%s: subclass %d offset %d\n", +		__func__, subclass, offset); + +	di->bus.write(di, BLOCK_DATA_CONTROL, 0, true); +	msleep(5); + +	di->bus.write(di, BLOCK_DATA_CLASS, subclass, true); +	msleep(5); + +	di->bus.write(di, DATA_BLOCK, blk_offset, true); +	msleep(5); + +	di->bus.blk_read(di, BLOCK_DATA, data, 32); + +	cksum_calc = checksum(data); +	cksum = di->bus.read(di, BLOCK_DATA_CHECKSUM, true); +	if (cksum != cksum_calc) { +		dev_err(di->dev, "%s: error reading subclass %d offset %d\n", +			__func__, subclass, offset); +		return 0; +	} + +	print_buf(__func__, data); + +	return 1;  }  /* - * Return the battery Relative State-of-Charge + * Return the battery State-of-Charge   * Or < 0 if something fails.   */ -static int bq27x00_battery_read_rsoc(struct bq27x00_device_info *di) +static int bq27x00_battery_read_soc(struct bq27x00_device_info *di)  { -	int rsoc; +	int soc; -	if (di->chip == BQ27500) -		rsoc = bq27x00_read(di, BQ27500_REG_SOC, false); -	else if (di->chip == BQ27425) -		rsoc = bq27x00_read(di, BQ27425_REG_SOC, false); -	else -		rsoc = bq27x00_read(di, BQ27000_REG_RSOC, true); +	soc = bq27xxx_read(di, BQ27XXX_REG_SOC, false); -	if (rsoc < 0) +	if (soc < 0)  		dev_dbg(di->dev, "error reading relative State-of-Charge\n"); -	return rsoc; +	return soc;  }  /* @@ -209,17 +738,17 @@ static int bq27x00_battery_read_charge(struct bq27x00_device_info *di, u8 reg)  {  	int charge; -	charge = bq27x00_read(di, reg, false); +	charge = bq27xxx_read(di, reg, false);  	if (charge < 0) {  		dev_dbg(di->dev, "error reading charge register %02x: %d\n",  			reg, charge);  		return charge;  	} -	if (bq27xxx_is_chip_version_higher(di)) -		charge *= 1000; +	if (di->chip == BQ27200) +		charge = charge * 3570 / BQ27200_RS;  	else -		charge = charge * 3570 / BQ27000_RS; +		charge *= 1000;  	return charge;  } @@ -231,49 +760,46 @@ static int bq27x00_battery_read_charge(struct bq27x00_device_info *di, u8 reg)  static inline int bq27x00_battery_read_nac(struct bq27x00_device_info *di)  {  	int flags; -	bool is_bq27500 = di->chip == BQ27500; -	bool is_higher = bq27xxx_is_chip_version_higher(di); -	flags = bq27x00_read(di, BQ27x00_REG_FLAGS, !is_bq27500); -	if (flags >= 0 && !is_higher && (flags & BQ27000_FLAG_CI)) -		return -ENODATA; +	if (di->chip == BQ27200) { +		flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, true); +		if (flags >= 0 && (flags & BQ27200_FLAG_CI)) +			return -ENODATA; +	} -	return bq27x00_battery_read_charge(di, BQ27x00_REG_NAC); +	return bq27x00_battery_read_charge(di, BQ27XXX_REG_NAC);  }  /*   * Return the battery Last measured discharge in µAh   * Or < 0 if something fails.   */ -static inline int bq27x00_battery_read_lmd(struct bq27x00_device_info *di) +static inline int bq27x00_battery_read_fcc(struct bq27x00_device_info *di)  { -	return bq27x00_battery_read_charge(di, BQ27x00_REG_LMD); +	return bq27x00_battery_read_charge(di, BQ27XXX_REG_FCC);  }  /* - * Return the battery Initial last measured discharge in µAh + * Return the Design Capacity in µAh   * Or < 0 if something fails.   */ -static int bq27x00_battery_read_ilmd(struct bq27x00_device_info *di) +static int bq27x00_battery_read_dcap(struct bq27x00_device_info *di)  { -	int ilmd; +	int dcap; -	if (bq27xxx_is_chip_version_higher(di)) -		ilmd = bq27x00_read(di, BQ27500_REG_DCAP, false); -	else -		ilmd = bq27x00_read(di, BQ27000_REG_ILMD, true); +	dcap = bq27xxx_read(di, BQ27XXX_REG_DCAP, false); -	if (ilmd < 0) { +	if (dcap < 0) {  		dev_dbg(di->dev, "error reading initial last measured discharge\n"); -		return ilmd; +		return dcap;  	} -	if (bq27xxx_is_chip_version_higher(di)) -		ilmd *= 1000; +	if (di->chip == BQ27200) +		dcap = dcap * 256 * 3570 / BQ27200_RS;  	else -		ilmd = ilmd * 256 * 3570 / BQ27000_RS; +		dcap *= 1000; -	return ilmd; +	return dcap;  }  /* @@ -284,16 +810,16 @@ static int bq27x00_battery_read_energy(struct bq27x00_device_info *di)  {  	int ae; -	ae = bq27x00_read(di, BQ27x00_REG_AE, false); +	ae = bq27xxx_read(di, BQ27XXX_REG_AE, false);  	if (ae < 0) {  		dev_dbg(di->dev, "error reading available energy\n");  		return ae;  	} -	if (di->chip == BQ27500) -		ae *= 1000; +	if (di->chip == BQ27200) +		ae = ae * 29200 / BQ27200_RS;  	else -		ae = ae * 29200 / BQ27000_RS; +		ae *= 1000;  	return ae;  } @@ -306,13 +832,13 @@ static int bq27x00_battery_read_temperature(struct bq27x00_device_info *di)  {  	int temp; -	temp = bq27x00_read(di, BQ27x00_REG_TEMP, false); +	temp = bq27xxx_read(di, BQ27XXX_REG_TEMP, false);  	if (temp < 0) {  		dev_err(di->dev, "error reading temperature\n");  		return temp;  	} -	if (!bq27xxx_is_chip_version_higher(di)) +	if (di->chip == BQ27200)  		temp = 5 * temp / 2;  	return temp; @@ -326,7 +852,7 @@ static int bq27x00_battery_read_cyct(struct bq27x00_device_info *di)  {  	int cyct; -	cyct = bq27x00_read(di, BQ27x00_REG_CYCT, false); +	cyct = bq27xxx_read(di, BQ27XXX_REG_CYCT, false);  	if (cyct < 0)  		dev_err(di->dev, "error reading cycle count total\n"); @@ -341,7 +867,7 @@ static int bq27x00_battery_read_time(struct bq27x00_device_info *di, u8 reg)  {  	int tval; -	tval = bq27x00_read(di, reg, false); +	tval = bq27xxx_read(di, reg, false);  	if (tval < 0) {  		dev_dbg(di->dev, "error reading time register %02x: %d\n",  			reg, tval); @@ -362,17 +888,25 @@ static int bq27x00_battery_read_pwr_avg(struct bq27x00_device_info *di, u8 reg)  {  	int tval; -	tval = bq27x00_read(di, reg, false); +	tval = bq27xxx_read(di, reg, false);  	if (tval < 0) {  		dev_err(di->dev, "error reading power avg rgister  %02x: %d\n",  			reg, tval);  		return tval;  	} -	if (di->chip == BQ27500) +	if (di->chip == BQ27200) +		return (tval * BQ27200_POWER_CONSTANT) / BQ27200_RS; +	else  		return tval; +} + +static int overtemperature(struct bq27x00_device_info *di, u16 flags) +{ +	if (di->chip == BQ27520) +		return flags & (BQ27XXX_FLAG_OTC | BQ27XXX_FLAG_OTD);  	else -		return (tval * BQ27x00_POWER_CONSTANT) / BQ27000_RS; +		return flags & BQ27XXX_FLAG_OTC;  }  /* @@ -381,25 +915,25 @@ static int bq27x00_battery_read_pwr_avg(struct bq27x00_device_info *di, u8 reg)   */  static int bq27x00_battery_read_health(struct bq27x00_device_info *di)  { -	int tval; +	u16 tval; -	tval = bq27x00_read(di, BQ27x00_REG_FLAGS, false); +	tval = bq27xxx_read(di, BQ27XXX_REG_FLAGS, false);  	if (tval < 0) {  		dev_err(di->dev, "error reading flag register:%d\n", tval);  		return tval;  	} -	if ((di->chip == BQ27500)) { -		if (tval & BQ27500_FLAG_SOCF) +	if ((di->chip == BQ27200)) { +		if (tval & BQ27200_FLAG_EDV1)  			tval = POWER_SUPPLY_HEALTH_DEAD; -		else if (tval & BQ27500_FLAG_OTC) -			tval = POWER_SUPPLY_HEALTH_OVERHEAT;  		else  			tval = POWER_SUPPLY_HEALTH_GOOD;  		return tval;  	} else { -		if (tval & BQ27000_FLAG_EDV1) +		if (tval & BQ27XXX_FLAG_SOCF)  			tval = POWER_SUPPLY_HEALTH_DEAD; +		else if (overtemperature(di, tval)) +			tval = POWER_SUPPLY_HEALTH_OVERHEAT;  		else  			tval = POWER_SUPPLY_HEALTH_GOOD;  		return tval; @@ -411,13 +945,14 @@ static int bq27x00_battery_read_health(struct bq27x00_device_info *di)  static void bq27x00_update(struct bq27x00_device_info *di)  {  	struct bq27x00_reg_cache cache = {0, }; +	bool is_bq27200 = di->chip == BQ27200;  	bool is_bq27500 = di->chip == BQ27500; -	bool is_bq27425 = di->chip == BQ27425; +	bool is_bq274xx = di->chip == BQ274XX; +	bool is_bq276xx = di->chip == BQ276XX; -	cache.flags = bq27x00_read(di, BQ27x00_REG_FLAGS, !is_bq27500); +	cache.flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, !is_bq27500);  	if (cache.flags >= 0) { -		if (!is_bq27500 && !is_bq27425 -				&& (cache.flags & BQ27000_FLAG_CI)) { +		if (is_bq27200 && (cache.flags & BQ27200_FLAG_CI)) {  			dev_info(di->dev, "battery is not calibrated! ignoring capacity values\n");  			cache.capacity = -ENODATA;  			cache.energy = -ENODATA; @@ -427,31 +962,31 @@ static void bq27x00_update(struct bq27x00_device_info *di)  			cache.charge_full = -ENODATA;  			cache.health = -ENODATA;  		} else { -			cache.capacity = bq27x00_battery_read_rsoc(di); -			if (!is_bq27425) { +			cache.capacity = bq27x00_battery_read_soc(di); +			if (!(is_bq274xx || is_bq276xx)) {  				cache.energy = bq27x00_battery_read_energy(di);  				cache.time_to_empty =  					bq27x00_battery_read_time(di, -							BQ27x00_REG_TTE); +							BQ27XXX_REG_TTE);  				cache.time_to_empty_avg =  					bq27x00_battery_read_time(di, -							BQ27x00_REG_TTECP); +							BQ27XXX_REG_TTECP);  				cache.time_to_full =  					bq27x00_battery_read_time(di, -							BQ27x00_REG_TTF); +							BQ27XXX_REG_TTF);  			} -			cache.charge_full = bq27x00_battery_read_lmd(di); +			cache.charge_full = bq27x00_battery_read_fcc(di);  			cache.health = bq27x00_battery_read_health(di);  		}  		cache.temperature = bq27x00_battery_read_temperature(di); -		if (!is_bq27425) +		if (!is_bq274xx)  			cache.cycle_count = bq27x00_battery_read_cyct(di);  		cache.power_avg = -			bq27x00_battery_read_pwr_avg(di, BQ27x00_POWER_AVG); +			bq27x00_battery_read_pwr_avg(di, BQ27XXX_POWER_AVG);  		/* We only have to read charge design full once */  		if (di->charge_design_full <= 0) -			di->charge_design_full = bq27x00_battery_read_ilmd(di); +			di->charge_design_full = bq27x00_battery_read_dcap(di);  	}  	if (memcmp(&di->cache, &cache, sizeof(cache)) != 0) { @@ -462,11 +997,131 @@ static void bq27x00_update(struct bq27x00_device_info *di)  	di->last_update = jiffies;  } +static void copy_to_dm_buf_big_endian(struct bq27x00_device_info *di, +	u8 *buf, u8 offset, u8 sz, u32 val) +{ +	dev_dbg(di->dev, "%s: offset %d sz %d val %d\n", +		__func__, offset, sz, val); + +	switch (sz) { +	case 1: +		buf[offset] = (u8) val; +		break; +	case 2: +		put_unaligned_be16((u16) val, &buf[offset]); +		break; +	case 4: +		put_unaligned_be32(val, &buf[offset]); +		break; +	default: +		dev_err(di->dev, "%s: bad size for dm parameter - %d", +			__func__, sz); +		break; +	} +} + +static int rom_mode_gauge_init_completed(struct bq27x00_device_info *di) +{ +	dev_dbg(di->dev, "%s:\n", __func__); + +	return control_cmd_read(di, CONTROL_STATUS_SUBCMD) & +		BQ274XX_CTRL_STATUS_INITCOMP; +} + +static bool rom_mode_gauge_dm_initialized(struct bq27x00_device_info *di) +{ +	u16 flags; + +	flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, false); + +	dev_dbg(di->dev, "%s: flags - 0x%04x\n", __func__, flags); + +	if (flags & BQ274XX_FLAG_ITPOR) +		return false; +	else +		return true; +} + +#define INITCOMP_TIMEOUT_MS		10000 +static void rom_mode_gauge_dm_init(struct bq27x00_device_info *di) +{ +	int i; +	int timeout = INITCOMP_TIMEOUT_MS; +	u8 subclass, offset; +	u32 blk_number; +	u32 blk_number_prev = 0; +	u8 buf[32]; +	bool buf_valid = false; +	struct dm_reg *dm_reg; + +	dev_dbg(di->dev, "%s:\n", __func__); + +	while (!rom_mode_gauge_init_completed(di) && timeout > 0) { +		msleep(100); +		timeout -= 100; +	} + +	if (timeout <= 0) { +		dev_err(di->dev, "%s: INITCOMP not set after %d seconds\n", +			__func__, INITCOMP_TIMEOUT_MS/100); +		return; +	} + +	if (!di->dm_regs || !di->dm_regs_count) { +		dev_err(di->dev, "%s: Data not available for DM initialization\n", +			__func__); +		return; +	} + +	enter_cfg_update_mode(di); +	for (i = 0; i < di->dm_regs_count; i++) { +		dm_reg = &di->dm_regs[i]; +		subclass = dm_reg->subclass; +		offset = dm_reg->offset; + +		/* +		 * Create a composite block number to see if the subsequent +		 * register also belongs to the same 32 btye block in the DM +		 */ +		blk_number = subclass << 8; +		blk_number |= offset >> 5; + +		if (blk_number == blk_number_prev) { +			copy_to_dm_buf_big_endian(di, buf, offset, +				dm_reg->len, dm_reg->data); +		} else { + +			if (buf_valid) +				update_dm_block(di, blk_number_prev >> 8, +					(blk_number_prev << 5) & 0xFF , buf); +			else +				buf_valid = true; + +			read_dm_block(di, dm_reg->subclass, dm_reg->offset, +				buf); +			copy_to_dm_buf_big_endian(di, buf, offset, +				dm_reg->len, dm_reg->data); +		} +		blk_number_prev = blk_number; +	} + +	/* Last buffer to be written */ +	if (buf_valid) +		update_dm_block(di, subclass, offset, buf); + +	exit_cfg_update_mode(di); +} +  static void bq27x00_battery_poll(struct work_struct *work)  {  	struct bq27x00_device_info *di =  		container_of(work, struct bq27x00_device_info, work.work); +	if (((di->chip == BQ274XX) || (di->chip == BQ276XX)) && +		!rom_mode_gauge_dm_initialized(di)) { +		rom_mode_gauge_dm_init(di); +	} +  	bq27x00_update(di);  	if (poll_interval > 0) { @@ -487,23 +1142,23 @@ static int bq27x00_battery_current(struct bq27x00_device_info *di,  	int curr;  	int flags; -	curr = bq27x00_read(di, BQ27x00_REG_AI, false); +	curr = bq27xxx_read(di, BQ27XXX_REG_AI, false);  	if (curr < 0) {  		dev_err(di->dev, "error reading current\n");  		return curr;  	} -	if (bq27xxx_is_chip_version_higher(di)) { -		/* bq27500 returns signed value */ -		val->intval = (int)((s16)curr) * 1000; -	} else { -		flags = bq27x00_read(di, BQ27x00_REG_FLAGS, false); -		if (flags & BQ27000_FLAG_CHGS) { +	if (di->chip == BQ27200) { +		flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, false); +		if (flags & BQ27200_FLAG_CHGS) {  			dev_dbg(di->dev, "negative current!\n");  			curr = -curr;  		} -		val->intval = curr * 3570 / BQ27000_RS; +		val->intval = curr * 3570 / BQ27200_RS; +	} else { +		/* Other gauges return signed value */ +		val->intval = (int)((s16)curr) * 1000;  	}  	return 0; @@ -514,22 +1169,22 @@ static int bq27x00_battery_status(struct bq27x00_device_info *di,  {  	int status; -	if (bq27xxx_is_chip_version_higher(di)) { -		if (di->cache.flags & BQ27500_FLAG_FC) -			status = POWER_SUPPLY_STATUS_FULL; -		else if (di->cache.flags & BQ27500_FLAG_DSC) -			status = POWER_SUPPLY_STATUS_DISCHARGING; -		else -			status = POWER_SUPPLY_STATUS_CHARGING; -	} else { -		if (di->cache.flags & BQ27000_FLAG_FC) +	if (di->chip == BQ27200) { +		if (di->cache.flags & BQ27200_FLAG_FC)  			status = POWER_SUPPLY_STATUS_FULL; -		else if (di->cache.flags & BQ27000_FLAG_CHGS) +		else if (di->cache.flags & BQ27200_FLAG_CHGS)  			status = POWER_SUPPLY_STATUS_CHARGING;  		else if (power_supply_am_i_supplied(&di->bat))  			status = POWER_SUPPLY_STATUS_NOT_CHARGING;  		else  			status = POWER_SUPPLY_STATUS_DISCHARGING; +	} else { +		if (di->cache.flags & BQ27XXX_FLAG_FC) +			status = POWER_SUPPLY_STATUS_FULL; +		else if (di->cache.flags & BQ27XXX_FLAG_DSC) +			status = POWER_SUPPLY_STATUS_DISCHARGING; +		else +			status = POWER_SUPPLY_STATUS_CHARGING;  	}  	val->intval = status; @@ -542,21 +1197,21 @@ static int bq27x00_battery_capacity_level(struct bq27x00_device_info *di,  {  	int level; -	if (bq27xxx_is_chip_version_higher(di)) { -		if (di->cache.flags & BQ27500_FLAG_FC) +	if (di->chip == BQ27200) { +		if (di->cache.flags & BQ27200_FLAG_FC)  			level = POWER_SUPPLY_CAPACITY_LEVEL_FULL; -		else if (di->cache.flags & BQ27500_FLAG_SOC1) +		else if (di->cache.flags & BQ27200_FLAG_EDV1)  			level = POWER_SUPPLY_CAPACITY_LEVEL_LOW; -		else if (di->cache.flags & BQ27500_FLAG_SOCF) +		else if (di->cache.flags & BQ27200_FLAG_EDVF)  			level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;  		else  			level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;  	} else { -		if (di->cache.flags & BQ27000_FLAG_FC) +		if (di->cache.flags & BQ27XXX_FLAG_FC)  			level = POWER_SUPPLY_CAPACITY_LEVEL_FULL; -		else if (di->cache.flags & BQ27000_FLAG_EDV1) +		else if (di->cache.flags & BQ27XXX_FLAG_SOC1)  			level = POWER_SUPPLY_CAPACITY_LEVEL_LOW; -		else if (di->cache.flags & BQ27000_FLAG_EDVF) +		else if (di->cache.flags & BQ27XXX_FLAG_SOCF)  			level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;  		else  			level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL; @@ -576,7 +1231,7 @@ static int bq27x00_battery_voltage(struct bq27x00_device_info *di,  {  	int volt; -	volt = bq27x00_read(di, BQ27x00_REG_VOLT, false); +	volt = bq27xxx_read(di, BQ27XXX_REG_VOLT, false);  	if (volt < 0) {  		dev_err(di->dev, "error reading voltage\n");  		return volt; @@ -690,17 +1345,41 @@ static void bq27x00_external_power_changed(struct power_supply *psy)  	schedule_delayed_work(&di->work, 0);  } -static int bq27x00_powersupply_init(struct bq27x00_device_info *di) +static void __init set_properties_array(struct bq27x00_device_info *di, +	enum power_supply_property *props, int num_props) +{ +	int tot_sz = num_props * sizeof(enum power_supply_property); + +	di->bat.properties = devm_kzalloc(di->dev, tot_sz, GFP_KERNEL); + +	if (di->bat.properties) { +		memcpy(di->bat.properties, props, tot_sz); +		di->bat.num_properties = num_props; +	} else { +		di->bat.num_properties = 0; +	} +} + +static int __init bq27x00_powersupply_init(struct bq27x00_device_info *di)  {  	int ret;  	di->bat.type = POWER_SUPPLY_TYPE_BATTERY; -	if (di->chip == BQ27425) { -		di->bat.properties = bq27425_battery_props; -		di->bat.num_properties = ARRAY_SIZE(bq27425_battery_props); +	if (di->chip == BQ274XX) { +		set_properties_array(di, bq274xx_battery_props, +			ARRAY_SIZE(bq274xx_battery_props)); +	} else if (di->chip == BQ276XX) { +		set_properties_array(di, bq276xx_battery_props, +			ARRAY_SIZE(bq276xx_battery_props)); +	} else if (di->chip == BQ27520) { +		set_properties_array(di, bq27520_battery_props, +			ARRAY_SIZE(bq27520_battery_props)); +	} else if (di->chip == BQ2753X) { +		set_properties_array(di, bq2753x_battery_props, +			ARRAY_SIZE(bq2753x_battery_props));  	} else { -		di->bat.properties = bq27x00_battery_props; -		di->bat.num_properties = ARRAY_SIZE(bq27x00_battery_props); +		set_properties_array(di, bq27x00_battery_props, +			ARRAY_SIZE(bq27x00_battery_props));  	}  	di->bat.get_property = bq27x00_battery_get_property;  	di->bat.external_power_changed = bq27x00_external_power_changed; @@ -748,7 +1427,7 @@ static void bq27x00_powersupply_unregister(struct bq27x00_device_info *di)  static DEFINE_IDR(battery_id);  static DEFINE_MUTEX(battery_mutex); -static int bq27x00_read_i2c(struct bq27x00_device_info *di, u8 reg, bool single) +static int bq27xxx_read_i2c(struct bq27x00_device_info *di, u8 reg, bool single)  {  	struct i2c_client *client = to_i2c_client(di->dev);  	struct i2c_msg msg[2]; @@ -782,20 +1461,205 @@ static int bq27x00_read_i2c(struct bq27x00_device_info *di, u8 reg, bool single)  	return ret;  } -static int bq27x00_battery_probe(struct i2c_client *client, +static int bq27xxx_write_i2c(struct bq27x00_device_info *di, u8 reg, int value, bool single) +{ +	struct i2c_client *client = to_i2c_client(di->dev); +	struct i2c_msg msg; +	unsigned char data[4]; +	int ret; + +	if (!client->adapter) +		return -ENODEV; + +	data[0] = reg; +	if (single) { +		data[1] = (unsigned char)value; +		msg.len = 2; +	} else { +		put_unaligned_le16(value, &data[1]); +		msg.len = 3; +	} + +	msg.buf = data; +	msg.addr = client->addr; +	msg.flags = 0; + +	ret = i2c_transfer(client->adapter, &msg, 1); +	if (ret < 0) +		return ret; + +	return 0; +} + +static int bq27xxx_read_i2c_blk(struct bq27x00_device_info *di, u8 reg, +	u8 *data, u8 len) +{ +	struct i2c_client *client = to_i2c_client(di->dev); +	struct i2c_msg msg[2]; +	int ret; + +	if (!client->adapter) +		return -ENODEV; + +	msg[0].addr = client->addr; +	msg[0].flags = 0; +	msg[0].buf = ® +	msg[0].len = 1; + +	msg[1].addr = client->addr; +	msg[1].flags = I2C_M_RD; +	msg[1].buf = data; +	msg[1].len = len; + +	ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); +	if (ret < 0) +		return ret; + +	return ret; +} + +static int bq27xxx_write_i2c_blk(struct bq27x00_device_info *di, u8 reg, +	u8 *data, u8 sz) +{ +	struct i2c_client *client = to_i2c_client(di->dev); +	struct i2c_msg msg; +	int ret; +	u8 buf[33]; + +	if (!client->adapter) +		return -ENODEV; + +	buf[0] = reg; +	memcpy(&buf[1], data, sz); + +	msg.buf = buf; +	msg.addr = client->addr; +	msg.flags = 0; +	msg.len = sz + 1; + +	ret = i2c_transfer(client->adapter, &msg, 1); +	if (ret < 0) +		return ret; + +	return 0; +} + +static int bq27x00_battery_reset(struct bq27x00_device_info *di) +{ +	dev_info(di->dev, "Gas Gauge Reset\n"); + +	bq27xxx_write(di, BQ27XXX_REG_CTRL, RESET_SUBCMD, false); + +	msleep(10); + +	return bq27xxx_read(di, BQ27XXX_REG_CTRL, false); +} + +static int bq27x00_battery_read_fw_version(struct bq27x00_device_info *di) +{ +	bq27xxx_write(di, BQ27XXX_REG_CTRL, FW_VER_SUBCMD, false); + +	msleep(10); + +	return bq27xxx_read(di, BQ27XXX_REG_CTRL, false); +} + +static int bq27x00_battery_read_device_type(struct bq27x00_device_info *di) +{ +	bq27xxx_write(di, BQ27XXX_REG_CTRL, DEV_TYPE_SUBCMD, false); + +	msleep(10); + +	return bq27xxx_read(di, BQ27XXX_REG_CTRL, false); +} + +static int bq27x00_battery_read_dataflash_version(struct bq27x00_device_info *di) +{ +	bq27xxx_write(di, BQ27XXX_REG_CTRL, DF_VER_SUBCMD, false); + +	msleep(10); + +	return bq27xxx_read(di, BQ27XXX_REG_CTRL, false); +} + +static ssize_t show_firmware_version(struct device *dev, +		struct device_attribute *attr, char *buf) +{ +	struct bq27x00_device_info *di = dev_get_drvdata(dev); +	int ver; + +	ver = bq27x00_battery_read_fw_version(di); + +	return sprintf(buf, "%d\n", ver); +} + +static ssize_t show_dataflash_version(struct device *dev, +		struct device_attribute *attr, char *buf) +{ +	struct bq27x00_device_info *di = dev_get_drvdata(dev); +	int ver; + +	ver = bq27x00_battery_read_dataflash_version(di); + +	return sprintf(buf, "%d\n", ver); +} + +static ssize_t show_device_type(struct device *dev, +		struct device_attribute *attr, char *buf) +{ +	struct bq27x00_device_info *di = dev_get_drvdata(dev); +	int dev_type; + +	dev_type = bq27x00_battery_read_device_type(di); + +	return sprintf(buf, "%d\n", dev_type); +} + +static ssize_t show_reset(struct device *dev, +		struct device_attribute *attr, char *buf) +{ +	struct bq27x00_device_info *di = dev_get_drvdata(dev); + +	bq27x00_battery_reset(di); + +	return sprintf(buf, "okay\n"); +} + +static DEVICE_ATTR(fw_version, S_IRUGO, show_firmware_version, NULL); +static DEVICE_ATTR(df_version, S_IRUGO, show_dataflash_version, NULL); +static DEVICE_ATTR(device_type, S_IRUGO, show_device_type, NULL); +static DEVICE_ATTR(reset, S_IRUGO, show_reset, NULL); + +static struct attribute *bq27x00_attributes[] = { +	&dev_attr_fw_version.attr, +	&dev_attr_df_version.attr, +	&dev_attr_device_type.attr, +	&dev_attr_reset.attr, +	NULL +}; + +static const struct attribute_group bq27x00_attr_group = { +	.attrs = bq27x00_attributes, +}; + +static int __init bq27x00_battery_probe(struct i2c_client *client,  				 const struct i2c_device_id *id)  {  	char *name;  	struct bq27x00_device_info *di;  	int num;  	int retval = 0; +	u8 *regs;  	/* Get new ID for the new battery device */ +	retval = idr_pre_get(&battery_id, GFP_KERNEL); +	if (retval == 0) +		return -ENOMEM;  	mutex_lock(&battery_mutex); -	num = idr_alloc(&battery_id, client, 0, 0, GFP_KERNEL); +	retval = idr_get_new(&battery_id, client, &num);  	mutex_unlock(&battery_mutex); -	if (num < 0) -		return num; +	if (retval < 0) +		return retval;  	name = kasprintf(GFP_KERNEL, "%s-%d", id->name, num);  	if (!name) { @@ -815,13 +1679,52 @@ static int bq27x00_battery_probe(struct i2c_client *client,  	di->dev = &client->dev;  	di->chip = id->driver_data;  	di->bat.name = name; -	di->bus.read = &bq27x00_read_i2c; +	di->bus.read = &bq27xxx_read_i2c; +	di->bus.write = &bq27xxx_write_i2c; +	di->bus.blk_read = bq27xxx_read_i2c_blk; +	di->bus.blk_write = bq27xxx_write_i2c_blk; +	di->dm_regs = NULL; +	di->dm_regs_count = 0; + +	if (di->chip == BQ27200) +		regs = bq27200_regs; +	else if (di->chip == BQ27500) +		regs = bq27500_regs; +	else if (di->chip == BQ27520) +		regs = bq27520_regs; +	else if (di->chip == BQ2753X) +		regs = bq2753x_regs; +	else if (di->chip == BQ274XX) { +		regs = bq274xx_regs; +		di->dm_regs = bq274xx_dm_regs; +		di->dm_regs_count = ARRAY_SIZE(bq274xx_dm_regs); +	} else if (di->chip == BQ276XX) { +		/* commands are same as bq274xx, only DM is different */ +		regs = bq276xx_regs; +		di->dm_regs = bq276xx_dm_regs; +		di->dm_regs_count = ARRAY_SIZE(bq276xx_dm_regs); +	} else { +		dev_err(&client->dev, +			"Unexpected gas gague: %d\n", di->chip); +		regs = bq27520_regs; +	} + +	memcpy(di->regs, regs, NUM_REGS); + +	di->fw_ver = bq27x00_battery_read_fw_version(di); +	dev_info(&client->dev, "Gas Guage fw version is 0x%04x\n", di->fw_ver);  	retval = bq27x00_powersupply_init(di);  	if (retval)  		goto batt_failed_3; +	/* Schedule a polling after about 1 min */ +	schedule_delayed_work(&di->work, 60 * HZ); +  	i2c_set_clientdata(client, di); +	retval = sysfs_create_group(&client->dev.kobj, &bq27x00_attr_group); +	if (retval) +		dev_err(&client->dev, "could not create sysfs files\n");  	return 0; @@ -855,9 +1758,12 @@ static int bq27x00_battery_remove(struct i2c_client *client)  }  static const struct i2c_device_id bq27x00_id[] = { -	{ "bq27200", BQ27000 },	/* bq27200 is same as bq27000, but with i2c */ +	{ "bq27200", BQ27200 },  	{ "bq27500", BQ27500 }, -	{ "bq27425", BQ27425 }, +	{ "bq27520", BQ27520 }, +	{ "bq274xx", BQ274XX }, +	{ "bq276xx", BQ276XX }, +	{ "bq2753x", BQ2753X },  	{},  };  MODULE_DEVICE_TABLE(i2c, bq27x00_id); @@ -871,7 +1777,7 @@ static struct i2c_driver bq27x00_battery_driver = {  	.id_table = bq27x00_id,  }; -static inline int bq27x00_battery_i2c_init(void) +static inline int __init bq27x00_battery_i2c_init(void)  {  	int ret = i2c_add_driver(&bq27x00_battery_driver);  	if (ret) @@ -880,7 +1786,7 @@ static inline int bq27x00_battery_i2c_init(void)  	return ret;  } -static inline void bq27x00_battery_i2c_exit(void) +static inline void __exit bq27x00_battery_i2c_exit(void)  {  	i2c_del_driver(&bq27x00_battery_driver);  } @@ -929,7 +1835,7 @@ static int bq27000_read_platform(struct bq27x00_device_info *di, u8 reg,  	return pdata->read(dev, reg);  } -static int bq27000_battery_probe(struct platform_device *pdev) +static int __devinit bq27000_battery_probe(struct platform_device *pdev)  {  	struct bq27x00_device_info *di;  	struct bq27000_platform_data *pdata = pdev->dev.platform_data; @@ -954,7 +1860,7 @@ static int bq27000_battery_probe(struct platform_device *pdev)  	platform_set_drvdata(pdev, di);  	di->dev = &pdev->dev; -	di->chip = BQ27000; +	di->chip = BQ27200;  	di->bat.name = pdata->name ?: dev_name(&pdev->dev);  	di->bus.read = &bq27000_read_platform; @@ -966,27 +1872,25 @@ static int bq27000_battery_probe(struct platform_device *pdev)  	return 0;  err_free: -	platform_set_drvdata(pdev, NULL);  	kfree(di);  	return ret;  } -static int bq27000_battery_remove(struct platform_device *pdev) +static int __devexit bq27000_battery_remove(struct platform_device *pdev)  {  	struct bq27x00_device_info *di = platform_get_drvdata(pdev);  	bq27x00_powersupply_unregister(di); -	platform_set_drvdata(pdev, NULL);  	kfree(di);  	return 0;  } -static struct platform_driver bq27000_battery_driver = { +static struct platform_driver __initdata bq27000_battery_driver = {  	.probe	= bq27000_battery_probe, -	.remove = bq27000_battery_remove, +	.remove = __devexit_p(bq27000_battery_remove),  	.driver = {  		.name = "bq27000-battery",  		.owner = THIS_MODULE, @@ -997,7 +1901,7 @@ static inline int bq27x00_battery_platform_init(void)  {  	int ret = platform_driver_register(&bq27000_battery_driver);  	if (ret) -		printk(KERN_ERR "Unable to register BQ27000 platform driver\n"); +		printk(KERN_ERR "Unable to register BQ27200 platform driver\n");  	return ret;  } diff --git a/drivers/video/omap2/displays/panel-ili9342.c b/drivers/video/omap2/displays/panel-ili9342.c index a95c6bfcc86..fc44e24e0b6 100644 --- a/drivers/video/omap2/displays/panel-ili9342.c +++ b/drivers/video/omap2/displays/panel-ili9342.c @@ -336,7 +336,7 @@ static inline void ili9342_init_seq(struct spi_device *spi) {  	ili9342_write_cmd(spi, 0xB4); -	ili9342_write_data(spi, 0x02); +	ili9342_write_data(spi, 0x00);  	ili9342_write_cmd(spi, 0xC0);  	ili9342_write_data(spi, 0x16); @@ -346,7 +346,7 @@ static inline void ili9342_init_seq(struct spi_device *spi) {  	ili9342_write_data(spi, 0x01);  	ili9342_write_cmd(spi, 0xC5); -	ili9342_write_data(spi, 0xF0); +	ili9342_write_data(spi, 0xDB);  // RGB color mode @@ -359,40 +359,42 @@ static inline void ili9342_init_seq(struct spi_device *spi) {  	ili9342_write_data(spi, 0x1D);  	ili9342_write_data(spi, 0x04);  // GAMMA settings +	//ili9342_write_cmd(spi, 0x26); +	//ili9342_write_data(spi, 0x04); + +	ili9342_write_cmd(spi, 0xE0); +	ili9342_write_data(spi, 0x00);  //63 +	ili9342_write_data(spi, 0x1b);  //62 +	ili9342_write_data(spi, 0x22);  //61 +	ili9342_write_data(spi, 0x05);  //59 +	ili9342_write_data(spi, 0x13);  //57 +	ili9342_write_data(spi, 0x07);  //50 +	ili9342_write_data(spi, 0x4c);  //43 +	ili9342_write_data(spi, 0xa7);  //27 +	ili9342_write_data(spi, 0x5f);  //20 +	ili9342_write_data(spi, 0x05);  //13 +	ili9342_write_data(spi, 0x0b);  //06 +	ili9342_write_data(spi, 0x09);  //04 +	ili9342_write_data(spi, 0x32);  //02 +	ili9342_write_data(spi, 0x36);  //01 +	ili9342_write_data(spi, 0x0F);  //00 -//	ili9342_write_cmd(spi, 0xE0); -//	ili9342_write_data(spi, 0x00);  //00 -//	ili9342_write_data(spi, 0x0A);  //01 -//	ili9342_write_data(spi, 0x11);  //02 -//	ili9342_write_data(spi, 0x06);  //04 -//	ili9342_write_data(spi, 0x13);  //06 -//	ili9342_write_data(spi, 0x09);  //13 -//	ili9342_write_data(spi, 0x37);  //20 -//	ili9342_write_data(spi, 0x79);  //27 -//	ili9342_write_data(spi, 0x4A);  //43 -//	ili9342_write_data(spi, 0x09);  //50 -//	ili9342_write_data(spi, 0x0F);  //57 -//	ili9342_write_data(spi, 0x0B);  //59 -//	ili9342_write_data(spi, 0x19);  //61 -//	ili9342_write_data(spi, 0x1D);  //62 -//	ili9342_write_data(spi, 0x0F);  //63 -// -//	ili9342_write_cmd(spi, 0xE1); -//	ili9342_write_data(spi, 0x00);  //63 -//	ili9342_write_data(spi, 0x22);  //62 -//	ili9342_write_data(spi, 0x26);  //61 -//	ili9342_write_data(spi, 0x04);  //59 -//	ili9342_write_data(spi, 0x10);  //57 -//	ili9342_write_data(spi, 0x05);  //50 -//	ili9342_write_data(spi, 0x3B);  //43 -//	ili9342_write_data(spi, 0x34);  //26 -//	ili9342_write_data(spi, 0x49);  //20 -//	ili9342_write_data(spi, 0x06);  //13 -//	ili9342_write_data(spi, 0x0C);  //06 -//	ili9342_write_data(spi, 0x09);  //04 -//	ili9342_write_data(spi, 0x2e);  //02 -//	ili9342_write_data(spi, 0x35);  //01 -//	ili9342_write_data(spi, 0x0F);  //00 +	ili9342_write_cmd(spi, 0xE1); +	ili9342_write_data(spi, 0x00);  //00 +	ili9342_write_data(spi, 0x0c);  //01 +	ili9342_write_data(spi, 0x0d);  //02 +	ili9342_write_data(spi, 0x05);  //04 +	ili9342_write_data(spi, 0x11);  //06 +	ili9342_write_data(spi, 0x06);  //13 +	ili9342_write_data(spi, 0x30);  //20 +	ili9342_write_data(spi, 0x58);  //27 +	ili9342_write_data(spi, 0x44);  //43 +	ili9342_write_data(spi, 0x08);  //50 +	ili9342_write_data(spi, 0x14);  //57 +	ili9342_write_data(spi, 0x0c);  //59 +	ili9342_write_data(spi, 0x1e);  //61 +	ili9342_write_data(spi, 0x24);  //62 +	ili9342_write_data(spi, 0x0F);  //63  	ili9342_write_cmd(spi, 0x35);  	ili9342_write_data(spi, 0x00); |