diff options
| author | mattis fjallstrom <mattis@acm.org> | 2015-01-22 16:04:02 -0800 |
|---|---|---|
| committer | mattis fjallstrom <mattis@acm.org> | 2015-01-22 16:04:02 -0800 |
| commit | c3cee153d8df64679bf0de3fc38d8f361437a492 (patch) | |
| tree | ee045c56dc30a1f3aa04c26ed5591fe23b524f25 | |
| parent | c4a8cecab6597381b0e82f7369e432d6a14530b7 (diff) | |
| download | olio-linux-3.10-c3cee153d8df64679bf0de3fc38d8f361437a492.tar.xz olio-linux-3.10-c3cee153d8df64679bf0de3fc38d8f361437a492.zip | |
Removed configuration that uses cpufreq and power management, minor cosmetic changes to the board file, fuel gauge code.
Change-Id: I9810991c51ae2aa640cda0bd1ec35815c5148e6b
| -rw-r--r-- | arch/arm/configs/omap3_h1_defconfig | 41 | ||||
| -rw-r--r-- | arch/arm/mach-omap2/board-omap3h1.c | 52 | ||||
| -rw-r--r-- | drivers/power/bq27x00_battery.c | 1228 |
3 files changed, 196 insertions, 1125 deletions
diff --git a/arch/arm/configs/omap3_h1_defconfig b/arch/arm/configs/omap3_h1_defconfig index 3ff7277be7f..0c4a8c2cf6a 100644 --- a/arch/arm/configs/omap3_h1_defconfig +++ b/arch/arm/configs/omap3_h1_defconfig @@ -464,34 +464,7 @@ CONFIG_AUTO_ZRELADDR=y # # CPU Frequency scaling # -CONFIG_CPU_FREQ=y -CONFIG_CPU_FREQ_TABLE=y -CONFIG_CPU_FREQ_GOV_COMMON=y -CONFIG_CPU_FREQ_STAT=y -# CONFIG_CPU_FREQ_STAT_DETAILS is not set -# CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE is not set -# CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE is not set -CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE=y -# CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND is not set -# CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE is not set -# CONFIG_CPU_FREQ_DEFAULT_GOV_INTERACTIVE is not set -# CONFIG_CPU_FREQ_GOV_PERFORMANCE is not set -# CONFIG_CPU_FREQ_GOV_POWERSAVE is not set -CONFIG_CPU_FREQ_GOV_USERSPACE=y -CONFIG_CPU_FREQ_GOV_ONDEMAND=y -CONFIG_CPU_FREQ_GOV_INTERACTIVE=y -# CONFIG_CPU_FREQ_GOV_CONSERVATIVE is not set -# CONFIG_GENERIC_CPUFREQ_CPU0 is not set - -# -# ARM CPU frequency scaling drivers -# -# CONFIG_ARM_EXYNOS4210_CPUFREQ is not set -# CONFIG_ARM_EXYNOS4X12_CPUFREQ is not set -# CONFIG_ARM_EXYNOS5250_CPUFREQ is not set -# CONFIG_ARM_EXYNOS5440_CPUFREQ is not set -# CONFIG_ARM_KIRKWOOD_CPUFREQ is not set -CONFIG_ARM_OMAP2PLUS_CPUFREQ=y +# CONFIG_CPU_FREQ is not set # CONFIG_CPU_IDLE is not set # CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED is not set @@ -2131,14 +2104,6 @@ CONFIG_STAGING=y # CONFIG_IIO_PERIODIC_RTC_TRIGGER is not set # CONFIG_IIO_GPIO_TRIGGER is not set # CONFIG_IIO_SYSFS_TRIGGER is not set - -# -# Inertial measurement units -# -CONFIG_INV_MPU_IIO=m -# CONFIG_INV_IIO_MPU3050_ACCEL_SLAVE_BMA250 is not set -# CONFIG_DTS_INV_MPU_IIO is not set -CONFIG_INV_TESTING=y # CONFIG_IIO_SIMPLE_DUMMY is not set # CONFIG_ZSMALLOC is not set # CONFIG_FT1000 is not set @@ -2282,6 +2247,10 @@ CONFIG_IIO_CONSUMERS_PER_TRIGGER=2 # CONFIG_ADIS16400 is not set # CONFIG_ADIS16480 is not set # CONFIG_INV_MPU6050_IIO is not set +CONFIG_INV_MPU_IIO=y +# CONFIG_INV_IIO_MPU3050_ACCEL_SLAVE_BMA250 is not set +# CONFIG_DTS_INV_MPU_IIO is not set +CONFIG_INV_KERNEL_3_10=y # # Light sensors diff --git a/arch/arm/mach-omap2/board-omap3h1.c b/arch/arm/mach-omap2/board-omap3h1.c index 9364dc4e709..df83b4dae6b 100644 --- a/arch/arm/mach-omap2/board-omap3h1.c +++ b/arch/arm/mach-omap2/board-omap3h1.c @@ -275,37 +275,42 @@ static struct tps65910_board omap3h1_tps65910_pdata = { }; static struct i2c_board_info __initdata omap3h1_i2c1_board_info[] = { - { - I2C_BOARD_INFO("tps65910", 0x2d), - .platform_data = &omap3h1_tps65910_pdata, - }, - { - I2C_BOARD_INFO("mpu6515", 0x68), - // This is needed for the interrupt wake. IH_GPIO_BASE changed in 3.10 kernel - //.irq = (IH_GPIO_BASE + MPUIRQ_GPIO), - .platform_data = &mpu_data, - }, - { - /* Backlight */ - I2C_BOARD_INFO("lm3530-led", 0x38), - .platform_data = &omap3h1_backlight_platform_data, - }, - { - I2C_BOARD_INFO("mXT224", 0x4a), - .platform_data = &mxt_data, - }, - { - I2C_BOARD_INFO("bq274xx", 0x55), - }, + { + I2C_BOARD_INFO("tps65910", 0x2d), + .platform_data = &omap3h1_tps65910_pdata, + }, + { + I2C_BOARD_INFO("mpu6515", 0x68), + // This is needed for the interrupt wake. IH_GPIO_BASE changed in 3.10 kernel + //.irq = (IH_GPIO_BASE + MPUIRQ_GPIO), + .platform_data = &mpu_data, + }, + { + /* Backlight */ + I2C_BOARD_INFO("lm3530-led", 0x38), + .platform_data = &omap3h1_backlight_platform_data, + }, + { + I2C_BOARD_INFO("mXT224", 0x4a), + .platform_data = &mxt_data, + }, + { + I2C_BOARD_INFO("bq274xx", 0x55), + }, }; +static struct i2c_board_info __initdata omap3h1_i2c3_board_info[] = { + +}; + + static int __init omap3_h1_i2c_init(void) { gpio_request_one(ATMEL_MXT_GPIO, GPIOF_IN, "atmel_mxt_ts CHG"); omap3h1_i2c1_board_info[3].irq = gpio_to_irq(ATMEL_MXT_GPIO); omap_register_i2c_bus(1, 400, omap3h1_i2c1_board_info, ARRAY_SIZE(omap3h1_i2c1_board_info)); - //omap_register_i2c_bus(3, 400, omap3h1_i2c3_board_info, ARRAY_SIZE(omap3h1_i2c3_board_info)); + omap_register_i2c_bus(3, 400, omap3h1_i2c3_board_info, ARRAY_SIZE(omap3h1_i2c3_board_info)); return 0; } @@ -357,6 +362,7 @@ static void __init omap3_h1_init(void) omap3_mux_init(board_mux, OMAP_PACKAGE_CBP); omap3_h1_i2c_init(); + omap_display_init(&omap3h1_dss_data); omap_serial_init(); omap_sdrc_init(NULL, NULL); diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c index 98fa8abcae7..26037ca7efb 100644 --- a/drivers/power/bq27x00_battery.c +++ b/drivers/power/bq27x00_battery.c @@ -22,10 +22,7 @@ * 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> @@ -44,215 +41,48 @@ #define DRIVER_VERSION "1.2.0" -#define INVALID_REG_ADDR 0xFF +#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 -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 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 */ -#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) +#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) -/* 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 */ +/* bq27425 register addresses are same as bq27x00 addresses minus 4 */ +#define BQ27425_REG_OFFSET 0x04 +#define BQ27425_REG_SOC 0x18 /* Register address plus offset */ -#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) +#define BQ27000_RS 20 /* Resistor sense */ +#define BQ27x00_POWER_CONSTANT (256 * 29200 / 1000) 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 { BQ27200, BQ27500, BQ27520, BQ274XX, BQ276XX, BQ2753X}; +enum bq27x00_chip { BQ27000, BQ27500, BQ27425}; struct bq27x00_reg_cache { int temperature; @@ -268,13 +98,6 @@ 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; @@ -291,15 +114,9 @@ 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 __initdata enum power_supply_property bq27x00_battery_props[] = { +static enum power_supply_property bq27x00_battery_props[] = { POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_PRESENT, POWER_SUPPLY_PROP_VOLTAGE_NOW, @@ -320,57 +137,7 @@ static __initdata enum power_supply_property bq27x00_battery_props[] = { POWER_SUPPLY_PROP_HEALTH, }; -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[] = { +static enum power_supply_property bq27425_battery_props[] = { POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_PRESENT, POWER_SUPPLY_PROP_VOLTAGE_NOW, @@ -382,31 +149,6 @@ static __initdata enum power_supply_property bq276xx_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; @@ -415,319 +157,48 @@ 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 bq27xxx_read(struct bq27x00_device_info *di, int reg_index, +static inline int bq27x00_read(struct bq27x00_device_info *di, u8 reg, bool 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; + if (di->chip == BQ27425) + return di->bus.read(di, reg - BQ27425_REG_OFFSET, single); + return di->bus.read(di, reg, single); } -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); -} /* - * It is assumed that the gauge is in unsealed mode when this function - * is called + * 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. */ -static int bq276xx_seal_enabled(struct bq27x00_device_info *di) -{ - 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) +static bool bq27xxx_is_chip_version_higher(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; + if (di->chip == BQ27425 || di->chip == BQ27500) + return true; + return false; } /* - * Return the battery State-of-Charge + * Return the battery Relative State-of-Charge * Or < 0 if something fails. */ -static int bq27x00_battery_read_soc(struct bq27x00_device_info *di) +static int bq27x00_battery_read_rsoc(struct bq27x00_device_info *di) { - int soc; + int rsoc; - soc = bq27xxx_read(di, BQ27XXX_REG_SOC, false); + 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); - if (soc < 0) + if (rsoc < 0) dev_dbg(di->dev, "error reading relative State-of-Charge\n"); - return soc; + return rsoc; } /* @@ -738,17 +209,17 @@ static int bq27x00_battery_read_charge(struct bq27x00_device_info *di, u8 reg) { int charge; - charge = bq27xxx_read(di, reg, false); + charge = bq27x00_read(di, reg, false); if (charge < 0) { dev_dbg(di->dev, "error reading charge register %02x: %d\n", reg, charge); return charge; } - if (di->chip == BQ27200) - charge = charge * 3570 / BQ27200_RS; - else + if (bq27xxx_is_chip_version_higher(di)) charge *= 1000; + else + charge = charge * 3570 / BQ27000_RS; return charge; } @@ -760,46 +231,49 @@ 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); - if (di->chip == BQ27200) { - flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, true); - if (flags >= 0 && (flags & BQ27200_FLAG_CI)) - return -ENODATA; - } + flags = bq27x00_read(di, BQ27x00_REG_FLAGS, !is_bq27500); + if (flags >= 0 && !is_higher && (flags & BQ27000_FLAG_CI)) + return -ENODATA; - return bq27x00_battery_read_charge(di, BQ27XXX_REG_NAC); + return bq27x00_battery_read_charge(di, BQ27x00_REG_NAC); } /* * Return the battery Last measured discharge in µAh * Or < 0 if something fails. */ -static inline int bq27x00_battery_read_fcc(struct bq27x00_device_info *di) +static inline int bq27x00_battery_read_lmd(struct bq27x00_device_info *di) { - return bq27x00_battery_read_charge(di, BQ27XXX_REG_FCC); + return bq27x00_battery_read_charge(di, BQ27x00_REG_LMD); } /* - * Return the Design Capacity in µAh + * Return the battery Initial last measured discharge in µAh * Or < 0 if something fails. */ -static int bq27x00_battery_read_dcap(struct bq27x00_device_info *di) +static int bq27x00_battery_read_ilmd(struct bq27x00_device_info *di) { - int dcap; + int ilmd; - dcap = bq27xxx_read(di, BQ27XXX_REG_DCAP, false); + if (bq27xxx_is_chip_version_higher(di)) + ilmd = bq27x00_read(di, BQ27500_REG_DCAP, false); + else + ilmd = bq27x00_read(di, BQ27000_REG_ILMD, true); - if (dcap < 0) { + if (ilmd < 0) { dev_dbg(di->dev, "error reading initial last measured discharge\n"); - return dcap; + return ilmd; } - if (di->chip == BQ27200) - dcap = dcap * 256 * 3570 / BQ27200_RS; + if (bq27xxx_is_chip_version_higher(di)) + ilmd *= 1000; else - dcap *= 1000; + ilmd = ilmd * 256 * 3570 / BQ27000_RS; - return dcap; + return ilmd; } /* @@ -810,16 +284,16 @@ static int bq27x00_battery_read_energy(struct bq27x00_device_info *di) { int ae; - ae = bq27xxx_read(di, BQ27XXX_REG_AE, false); + ae = bq27x00_read(di, BQ27x00_REG_AE, false); if (ae < 0) { dev_dbg(di->dev, "error reading available energy\n"); return ae; } - if (di->chip == BQ27200) - ae = ae * 29200 / BQ27200_RS; - else + if (di->chip == BQ27500) ae *= 1000; + else + ae = ae * 29200 / BQ27000_RS; return ae; } @@ -832,13 +306,13 @@ static int bq27x00_battery_read_temperature(struct bq27x00_device_info *di) { int temp; - temp = bq27xxx_read(di, BQ27XXX_REG_TEMP, false); + temp = bq27x00_read(di, BQ27x00_REG_TEMP, false); if (temp < 0) { dev_err(di->dev, "error reading temperature\n"); return temp; } - if (di->chip == BQ27200) + if (!bq27xxx_is_chip_version_higher(di)) temp = 5 * temp / 2; return temp; @@ -852,7 +326,7 @@ static int bq27x00_battery_read_cyct(struct bq27x00_device_info *di) { int cyct; - cyct = bq27xxx_read(di, BQ27XXX_REG_CYCT, false); + cyct = bq27x00_read(di, BQ27x00_REG_CYCT, false); if (cyct < 0) dev_err(di->dev, "error reading cycle count total\n"); @@ -867,7 +341,7 @@ static int bq27x00_battery_read_time(struct bq27x00_device_info *di, u8 reg) { int tval; - tval = bq27xxx_read(di, reg, false); + tval = bq27x00_read(di, reg, false); if (tval < 0) { dev_dbg(di->dev, "error reading time register %02x: %d\n", reg, tval); @@ -888,25 +362,17 @@ static int bq27x00_battery_read_pwr_avg(struct bq27x00_device_info *di, u8 reg) { int tval; - tval = bq27xxx_read(di, reg, false); + tval = bq27x00_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 == BQ27200) - return (tval * BQ27200_POWER_CONSTANT) / BQ27200_RS; - else + if (di->chip == BQ27500) 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 flags & BQ27XXX_FLAG_OTC; + return (tval * BQ27x00_POWER_CONSTANT) / BQ27000_RS; } /* @@ -915,25 +381,25 @@ static int overtemperature(struct bq27x00_device_info *di, u16 flags) */ static int bq27x00_battery_read_health(struct bq27x00_device_info *di) { - u16 tval; + int tval; - tval = bq27xxx_read(di, BQ27XXX_REG_FLAGS, false); + tval = bq27x00_read(di, BQ27x00_REG_FLAGS, false); if (tval < 0) { dev_err(di->dev, "error reading flag register:%d\n", tval); return tval; } - if ((di->chip == BQ27200)) { - if (tval & BQ27200_FLAG_EDV1) + if ((di->chip == BQ27500)) { + if (tval & BQ27500_FLAG_SOCF) 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 & BQ27XXX_FLAG_SOCF) + if (tval & BQ27000_FLAG_EDV1) tval = POWER_SUPPLY_HEALTH_DEAD; - else if (overtemperature(di, tval)) - tval = POWER_SUPPLY_HEALTH_OVERHEAT; else tval = POWER_SUPPLY_HEALTH_GOOD; return tval; @@ -945,14 +411,13 @@ 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_bq274xx = di->chip == BQ274XX; - bool is_bq276xx = di->chip == BQ276XX; + bool is_bq27425 = di->chip == BQ27425; - cache.flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, !is_bq27500); + cache.flags = bq27x00_read(di, BQ27x00_REG_FLAGS, !is_bq27500); if (cache.flags >= 0) { - if (is_bq27200 && (cache.flags & BQ27200_FLAG_CI)) { + if (!is_bq27500 && !is_bq27425 + && (cache.flags & BQ27000_FLAG_CI)) { dev_info(di->dev, "battery is not calibrated! ignoring capacity values\n"); cache.capacity = -ENODATA; cache.energy = -ENODATA; @@ -962,31 +427,31 @@ static void bq27x00_update(struct bq27x00_device_info *di) cache.charge_full = -ENODATA; cache.health = -ENODATA; } else { - cache.capacity = bq27x00_battery_read_soc(di); - if (!(is_bq274xx || is_bq276xx)) { + cache.capacity = bq27x00_battery_read_rsoc(di); + if (!is_bq27425) { cache.energy = bq27x00_battery_read_energy(di); cache.time_to_empty = bq27x00_battery_read_time(di, - BQ27XXX_REG_TTE); + BQ27x00_REG_TTE); cache.time_to_empty_avg = bq27x00_battery_read_time(di, - BQ27XXX_REG_TTECP); + BQ27x00_REG_TTECP); cache.time_to_full = bq27x00_battery_read_time(di, - BQ27XXX_REG_TTF); + BQ27x00_REG_TTF); } - cache.charge_full = bq27x00_battery_read_fcc(di); + cache.charge_full = bq27x00_battery_read_lmd(di); cache.health = bq27x00_battery_read_health(di); } cache.temperature = bq27x00_battery_read_temperature(di); - if (!is_bq274xx) + if (!is_bq27425) cache.cycle_count = bq27x00_battery_read_cyct(di); cache.power_avg = - bq27x00_battery_read_pwr_avg(di, BQ27XXX_POWER_AVG); + bq27x00_battery_read_pwr_avg(di, BQ27x00_POWER_AVG); /* We only have to read charge design full once */ if (di->charge_design_full <= 0) - di->charge_design_full = bq27x00_battery_read_dcap(di); + di->charge_design_full = bq27x00_battery_read_ilmd(di); } if (memcmp(&di->cache, &cache, sizeof(cache)) != 0) { @@ -997,131 +462,11 @@ 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) { @@ -1142,23 +487,23 @@ static int bq27x00_battery_current(struct bq27x00_device_info *di, int curr; int flags; - curr = bq27xxx_read(di, BQ27XXX_REG_AI, false); + curr = bq27x00_read(di, BQ27x00_REG_AI, false); if (curr < 0) { dev_err(di->dev, "error reading current\n"); return curr; } - if (di->chip == BQ27200) { - flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, false); - if (flags & BQ27200_FLAG_CHGS) { + 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) { dev_dbg(di->dev, "negative current!\n"); curr = -curr; } - val->intval = curr * 3570 / BQ27200_RS; - } else { - /* Other gauges return signed value */ - val->intval = (int)((s16)curr) * 1000; + val->intval = curr * 3570 / BQ27000_RS; } return 0; @@ -1169,22 +514,22 @@ static int bq27x00_battery_status(struct bq27x00_device_info *di, { int status; - if (di->chip == BQ27200) { - if (di->cache.flags & BQ27200_FLAG_FC) + 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) status = POWER_SUPPLY_STATUS_FULL; - else if (di->cache.flags & BQ27200_FLAG_CHGS) + else if (di->cache.flags & BQ27000_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; @@ -1197,21 +542,21 @@ static int bq27x00_battery_capacity_level(struct bq27x00_device_info *di, { int level; - if (di->chip == BQ27200) { - if (di->cache.flags & BQ27200_FLAG_FC) + if (bq27xxx_is_chip_version_higher(di)) { + if (di->cache.flags & BQ27500_FLAG_FC) level = POWER_SUPPLY_CAPACITY_LEVEL_FULL; - else if (di->cache.flags & BQ27200_FLAG_EDV1) + else if (di->cache.flags & BQ27500_FLAG_SOC1) level = POWER_SUPPLY_CAPACITY_LEVEL_LOW; - else if (di->cache.flags & BQ27200_FLAG_EDVF) + else if (di->cache.flags & BQ27500_FLAG_SOCF) level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL; else level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL; } else { - if (di->cache.flags & BQ27XXX_FLAG_FC) + if (di->cache.flags & BQ27000_FLAG_FC) level = POWER_SUPPLY_CAPACITY_LEVEL_FULL; - else if (di->cache.flags & BQ27XXX_FLAG_SOC1) + else if (di->cache.flags & BQ27000_FLAG_EDV1) level = POWER_SUPPLY_CAPACITY_LEVEL_LOW; - else if (di->cache.flags & BQ27XXX_FLAG_SOCF) + else if (di->cache.flags & BQ27000_FLAG_EDVF) level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL; else level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL; @@ -1231,7 +576,7 @@ static int bq27x00_battery_voltage(struct bq27x00_device_info *di, { int volt; - volt = bq27xxx_read(di, BQ27XXX_REG_VOLT, false); + volt = bq27x00_read(di, BQ27x00_REG_VOLT, false); if (volt < 0) { dev_err(di->dev, "error reading voltage\n"); return volt; @@ -1345,41 +690,17 @@ static void bq27x00_external_power_changed(struct power_supply *psy) schedule_delayed_work(&di->work, 0); } -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) +static int bq27x00_powersupply_init(struct bq27x00_device_info *di) { int ret; di->bat.type = POWER_SUPPLY_TYPE_BATTERY; - 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)); + if (di->chip == BQ27425) { + di->bat.properties = bq27425_battery_props; + di->bat.num_properties = ARRAY_SIZE(bq27425_battery_props); } else { - set_properties_array(di, bq27x00_battery_props, - ARRAY_SIZE(bq27x00_battery_props)); + di->bat.properties = bq27x00_battery_props; + di->bat.num_properties = ARRAY_SIZE(bq27x00_battery_props); } di->bat.get_property = bq27x00_battery_get_property; di->bat.external_power_changed = bq27x00_external_power_changed; @@ -1427,7 +748,7 @@ static void bq27x00_powersupply_unregister(struct bq27x00_device_info *di) static DEFINE_IDR(battery_id); static DEFINE_MUTEX(battery_mutex); -static int bq27xxx_read_i2c(struct bq27x00_device_info *di, u8 reg, bool single) +static int bq27x00_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]; @@ -1461,205 +782,20 @@ static int bq27xxx_read_i2c(struct bq27x00_device_info *di, u8 reg, bool single) return ret; } -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, +static int 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); - retval = idr_get_new(&battery_id, client, &num); + num = idr_alloc(&battery_id, client, 0, 0, GFP_KERNEL); mutex_unlock(&battery_mutex); - if (retval < 0) - return retval; + if (num < 0) + return num; name = kasprintf(GFP_KERNEL, "%s-%d", id->name, num); if (!name) { @@ -1679,52 +815,13 @@ static int __init bq27x00_battery_probe(struct i2c_client *client, di->dev = &client->dev; di->chip = id->driver_data; di->bat.name = name; - 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); + di->bus.read = &bq27x00_read_i2c; 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; @@ -1758,12 +855,9 @@ static int bq27x00_battery_remove(struct i2c_client *client) } static const struct i2c_device_id bq27x00_id[] = { - { "bq27200", BQ27200 }, + { "bq27200", BQ27000 }, /* bq27200 is same as bq27000, but with i2c */ { "bq27500", BQ27500 }, - { "bq27520", BQ27520 }, - { "bq274xx", BQ274XX }, - { "bq276xx", BQ276XX }, - { "bq2753x", BQ2753X }, + { "bq27425", BQ27425 }, {}, }; MODULE_DEVICE_TABLE(i2c, bq27x00_id); @@ -1777,7 +871,7 @@ static struct i2c_driver bq27x00_battery_driver = { .id_table = bq27x00_id, }; -static inline int __init bq27x00_battery_i2c_init(void) +static inline int bq27x00_battery_i2c_init(void) { int ret = i2c_add_driver(&bq27x00_battery_driver); if (ret) @@ -1786,7 +880,7 @@ static inline int __init bq27x00_battery_i2c_init(void) return ret; } -static inline void __exit bq27x00_battery_i2c_exit(void) +static inline void bq27x00_battery_i2c_exit(void) { i2c_del_driver(&bq27x00_battery_driver); } @@ -1835,7 +929,7 @@ static int bq27000_read_platform(struct bq27x00_device_info *di, u8 reg, return pdata->read(dev, reg); } -static int __devinit bq27000_battery_probe(struct platform_device *pdev) +static int bq27000_battery_probe(struct platform_device *pdev) { struct bq27x00_device_info *di; struct bq27000_platform_data *pdata = pdev->dev.platform_data; @@ -1860,7 +954,7 @@ static int __devinit bq27000_battery_probe(struct platform_device *pdev) platform_set_drvdata(pdev, di); di->dev = &pdev->dev; - di->chip = BQ27200; + di->chip = BQ27000; di->bat.name = pdata->name ?: dev_name(&pdev->dev); di->bus.read = &bq27000_read_platform; @@ -1872,25 +966,27 @@ static int __devinit bq27000_battery_probe(struct platform_device *pdev) return 0; err_free: + platform_set_drvdata(pdev, NULL); kfree(di); return ret; } -static int __devexit bq27000_battery_remove(struct platform_device *pdev) +static int 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 __initdata bq27000_battery_driver = { +static struct platform_driver bq27000_battery_driver = { .probe = bq27000_battery_probe, - .remove = __devexit_p(bq27000_battery_remove), + .remove = bq27000_battery_remove, .driver = { .name = "bq27000-battery", .owner = THIS_MODULE, @@ -1901,7 +997,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 BQ27200 platform driver\n"); + printk(KERN_ERR "Unable to register BQ27000 platform driver\n"); return ret; } |