Commit bbcd9c53 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'for-v4.10' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply

Pull power supply and reset updates from Sebastian Reichel:

 - new driver for Intel PIIX4

 - lots of module autoload fixes

 - misc fixes

* tag 'for-v4.10' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply:
  power_supply: wm97xx_battery: use power_supply_get_drvdata
  wm8350_power: use permission-specific DEVICE_ATTR variants
  power: ipaq_micro_battery: fix alias
  power: supply: bq27xxx_battery: Fix register map for BQ27510 and BQ27520
  bq24190_charger: Fix PM runtime use for bq24190_battery_set_property
  power: supply: lp8788: remove an unneeded NULL check
  power: reset: zx-reboot: Fix module autoload
  power: reset: syscon-reboot-mode: Fix module autoload
  power: reset: at91-poweroff: Fix module autoload
  power: reset: at91-reset: Fix module autoload
  power: supply: axp288_fuel_gauge: Fix module autoload
  power: supply: max8997_charger: Fix module autoload
  power: supply: max17040: Change register transaction length from 8 bits to 16 bits
  power: supply: bq27xxx_battery: don't update poll_interval param if same
  power: supply: improve function-level documentation
  power: reset: Add Intel PIIX4 poweroff driver
parents ce38207f 6480af49
...@@ -682,7 +682,7 @@ static int wm97xx_probe(struct device *dev) ...@@ -682,7 +682,7 @@ static int wm97xx_probe(struct device *dev)
} }
platform_set_drvdata(wm->battery_dev, wm); platform_set_drvdata(wm->battery_dev, wm);
wm->battery_dev->dev.parent = dev; wm->battery_dev->dev.parent = dev;
wm->battery_dev->dev.platform_data = pdata; wm->battery_dev->dev.platform_data = pdata->batt_pdata;
ret = platform_device_add(wm->battery_dev); ret = platform_device_add(wm->battery_dev);
if (ret < 0) if (ret < 0)
goto batt_reg_err; goto batt_reg_err;
......
...@@ -104,6 +104,16 @@ config POWER_RESET_MSM ...@@ -104,6 +104,16 @@ config POWER_RESET_MSM
help help
Power off and restart support for Qualcomm boards. Power off and restart support for Qualcomm boards.
config POWER_RESET_PIIX4_POWEROFF
tristate "Intel PIIX4 power-off driver"
depends on PCI
depends on MIPS || COMPILE_TEST
help
This driver supports powering off a system using the Intel PIIX4
southbridge, for example the MIPS Malta development board. The
southbridge SOff state is entered in response to a request to
power off the system.
config POWER_RESET_LTC2952 config POWER_RESET_LTC2952
bool "LTC2952 PowerPath power-off driver" bool "LTC2952 PowerPath power-off driver"
depends on OF_GPIO depends on OF_GPIO
......
...@@ -10,6 +10,7 @@ obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o ...@@ -10,6 +10,7 @@ obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o
obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o
obj-$(CONFIG_POWER_RESET_IMX) += imx-snvs-poweroff.o obj-$(CONFIG_POWER_RESET_IMX) += imx-snvs-poweroff.o
obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o
obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) += piix4-poweroff.o
obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o
obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o
obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o
......
...@@ -169,6 +169,7 @@ static const struct of_device_id at91_poweroff_of_match[] = { ...@@ -169,6 +169,7 @@ static const struct of_device_id at91_poweroff_of_match[] = {
{ .compatible = "atmel,at91sam9x5-shdwc", }, { .compatible = "atmel,at91sam9x5-shdwc", },
{ /*sentinel*/ } { /*sentinel*/ }
}; };
MODULE_DEVICE_TABLE(of, at91_poweroff_of_match);
static struct platform_driver at91_poweroff_driver = { static struct platform_driver at91_poweroff_driver = {
.remove = __exit_p(at91_poweroff_remove), .remove = __exit_p(at91_poweroff_remove),
......
...@@ -175,6 +175,7 @@ static const struct of_device_id at91_reset_of_match[] = { ...@@ -175,6 +175,7 @@ static const struct of_device_id at91_reset_of_match[] = {
{ .compatible = "atmel,sama5d3-rstc", .data = sama5d3_restart }, { .compatible = "atmel,sama5d3-rstc", .data = sama5d3_restart },
{ /* sentinel */ } { /* sentinel */ }
}; };
MODULE_DEVICE_TABLE(of, at91_reset_of_match);
static struct notifier_block at91_restart_nb = { static struct notifier_block at91_restart_nb = {
.priority = 192, .priority = 192,
...@@ -242,6 +243,7 @@ static const struct platform_device_id at91_reset_plat_match[] = { ...@@ -242,6 +243,7 @@ static const struct platform_device_id at91_reset_plat_match[] = {
{ "at91-sam9g45-reset", (unsigned long)at91sam9g45_restart }, { "at91-sam9g45-reset", (unsigned long)at91sam9g45_restart },
{ /* sentinel */ } { /* sentinel */ }
}; };
MODULE_DEVICE_TABLE(platform, at91_reset_plat_match);
static struct platform_driver at91_reset_driver = { static struct platform_driver at91_reset_driver = {
.remove = __exit_p(at91_reset_remove), .remove = __exit_p(at91_reset_remove),
......
/*
* Copyright (C) 2016 Imagination Technologies
* Author: Paul Burton <paul.burton@imgtec.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*/
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/pm.h>
static struct pci_dev *pm_dev;
static resource_size_t io_offset;
enum piix4_pm_io_reg {
PIIX4_FUNC3IO_PMSTS = 0x00,
#define PIIX4_FUNC3IO_PMSTS_PWRBTN_STS BIT(8)
PIIX4_FUNC3IO_PMCNTRL = 0x04,
#define PIIX4_FUNC3IO_PMCNTRL_SUS_EN BIT(13)
#define PIIX4_FUNC3IO_PMCNTRL_SUS_TYP_SOFF (0x0 << 10)
};
#define PIIX4_SUSPEND_MAGIC 0x00120002
static const int piix4_pm_io_region = PCI_BRIDGE_RESOURCES;
static void piix4_poweroff(void)
{
int spec_devid;
u16 sts;
/* Ensure the power button status is clear */
while (1) {
sts = inw(io_offset + PIIX4_FUNC3IO_PMSTS);
if (!(sts & PIIX4_FUNC3IO_PMSTS_PWRBTN_STS))
break;
outw(sts, io_offset + PIIX4_FUNC3IO_PMSTS);
}
/* Enable entry to suspend */
outw(PIIX4_FUNC3IO_PMCNTRL_SUS_TYP_SOFF | PIIX4_FUNC3IO_PMCNTRL_SUS_EN,
io_offset + PIIX4_FUNC3IO_PMCNTRL);
/* If the special cycle occurs too soon this doesn't work... */
mdelay(10);
/*
* The PIIX4 will enter the suspend state only after seeing a special
* cycle with the correct magic data on the PCI bus. Generate that
* cycle now.
*/
spec_devid = PCI_DEVID(0, PCI_DEVFN(0x1f, 0x7));
pci_bus_write_config_dword(pm_dev->bus, spec_devid, 0,
PIIX4_SUSPEND_MAGIC);
/* Give the system some time to power down, then error */
mdelay(1000);
pr_emerg("Unable to poweroff system\n");
}
static int piix4_poweroff_probe(struct pci_dev *dev,
const struct pci_device_id *id)
{
int res;
if (pm_dev)
return -EINVAL;
/* Request access to the PIIX4 PM IO registers */
res = pci_request_region(dev, piix4_pm_io_region,
"PIIX4 PM IO registers");
if (res) {
dev_err(&dev->dev, "failed to request PM IO registers: %d\n",
res);
return res;
}
pm_dev = dev;
io_offset = pci_resource_start(dev, piix4_pm_io_region);
pm_power_off = piix4_poweroff;
return 0;
}
static void piix4_poweroff_remove(struct pci_dev *dev)
{
if (pm_power_off == piix4_poweroff)
pm_power_off = NULL;
pci_release_region(dev, piix4_pm_io_region);
pm_dev = NULL;
}
static const struct pci_device_id piix4_poweroff_ids[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) },
{ 0 },
};
static struct pci_driver piix4_poweroff_driver = {
.name = "piix4-poweroff",
.id_table = piix4_poweroff_ids,
.probe = piix4_poweroff_probe,
.remove = piix4_poweroff_remove,
};
module_pci_driver(piix4_poweroff_driver);
MODULE_AUTHOR("Paul Burton <paul.burton@imgtec.com>");
MODULE_LICENSE("GPL");
...@@ -74,6 +74,7 @@ static const struct of_device_id syscon_reboot_mode_of_match[] = { ...@@ -74,6 +74,7 @@ static const struct of_device_id syscon_reboot_mode_of_match[] = {
{ .compatible = "syscon-reboot-mode" }, { .compatible = "syscon-reboot-mode" },
{} {}
}; };
MODULE_DEVICE_TABLE(of, syscon_reboot_mode_of_match);
static struct platform_driver syscon_reboot_mode_driver = { static struct platform_driver syscon_reboot_mode_driver = {
.probe = syscon_reboot_mode_probe, .probe = syscon_reboot_mode_probe,
......
...@@ -72,6 +72,7 @@ static const struct of_device_id zx_reboot_of_match[] = { ...@@ -72,6 +72,7 @@ static const struct of_device_id zx_reboot_of_match[] = {
{ .compatible = "zte,sysctrl" }, { .compatible = "zte,sysctrl" },
{} {}
}; };
MODULE_DEVICE_TABLE(of, zx_reboot_of_match);
static struct platform_driver zx_reboot_driver = { static struct platform_driver zx_reboot_driver = {
.probe = zx_reboot_probe, .probe = zx_reboot_probe,
......
...@@ -1900,7 +1900,7 @@ static void ab8500_fg_low_bat_work(struct work_struct *work) ...@@ -1900,7 +1900,7 @@ static void ab8500_fg_low_bat_work(struct work_struct *work)
* ab8500_fg_battok_calc - calculate the bit pattern corresponding * ab8500_fg_battok_calc - calculate the bit pattern corresponding
* to the target voltage. * to the target voltage.
* @di: pointer to the ab8500_fg structure * @di: pointer to the ab8500_fg structure
* @target target voltage * @target: target voltage
* *
* Returns bit pattern closest to the target voltage * Returns bit pattern closest to the target voltage
* valid return values are 0-14. (0-BATT_OK_MAX_NR_INCREMENTS) * valid return values are 0-14. (0-BATT_OK_MAX_NR_INCREMENTS)
...@@ -2391,7 +2391,7 @@ static void ab8500_fg_external_power_changed(struct power_supply *psy) ...@@ -2391,7 +2391,7 @@ static void ab8500_fg_external_power_changed(struct power_supply *psy)
} }
/** /**
* abab8500_fg_reinit_work() - work to reset the FG algorithm * ab8500_fg_reinit_work() - work to reset the FG algorithm
* @work: pointer to the work_struct structure * @work: pointer to the work_struct structure
* *
* Used to reset the current battery capacity to be able to * Used to reset the current battery capacity to be able to
...@@ -2528,7 +2528,7 @@ static struct kobj_type ab8500_fg_ktype = { ...@@ -2528,7 +2528,7 @@ static struct kobj_type ab8500_fg_ktype = {
}; };
/** /**
* ab8500_chargalg_sysfs_exit() - de-init of sysfs entry * ab8500_fg_sysfs_exit() - de-init of sysfs entry
* @di: pointer to the struct ab8500_chargalg * @di: pointer to the struct ab8500_chargalg
* *
* This function removes the entry in sysfs. * This function removes the entry in sysfs.
...@@ -2539,7 +2539,7 @@ static void ab8500_fg_sysfs_exit(struct ab8500_fg *di) ...@@ -2539,7 +2539,7 @@ static void ab8500_fg_sysfs_exit(struct ab8500_fg *di)
} }
/** /**
* ab8500_chargalg_sysfs_init() - init of sysfs entry * ab8500_fg_sysfs_init() - init of sysfs entry
* @di: pointer to the struct ab8500_chargalg * @di: pointer to the struct ab8500_chargalg
* *
* This function adds an entry in sysfs. * This function adds an entry in sysfs.
......
...@@ -1120,6 +1120,7 @@ static const struct platform_device_id axp288_fg_id_table[] = { ...@@ -1120,6 +1120,7 @@ static const struct platform_device_id axp288_fg_id_table[] = {
{ .name = DEV_NAME }, { .name = DEV_NAME },
{}, {},
}; };
MODULE_DEVICE_TABLE(platform, axp288_fg_id_table);
static int axp288_fuel_gauge_remove(struct platform_device *pdev) static int axp288_fuel_gauge_remove(struct platform_device *pdev)
{ {
......
...@@ -1141,7 +1141,7 @@ static int bq24190_battery_set_property(struct power_supply *psy, ...@@ -1141,7 +1141,7 @@ static int bq24190_battery_set_property(struct power_supply *psy,
dev_dbg(bdi->dev, "prop: %d\n", psp); dev_dbg(bdi->dev, "prop: %d\n", psp);
pm_runtime_put_sync(bdi->dev); pm_runtime_get_sync(bdi->dev);
switch (psp) { switch (psp) {
case POWER_SUPPLY_PROP_ONLINE: case POWER_SUPPLY_PROP_ONLINE:
......
...@@ -164,6 +164,25 @@ static u8 bq27xxx_regs[][BQ27XXX_REG_MAX] = { ...@@ -164,6 +164,25 @@ static u8 bq27xxx_regs[][BQ27XXX_REG_MAX] = {
[BQ27XXX_REG_DCAP] = 0x3c, [BQ27XXX_REG_DCAP] = 0x3c,
[BQ27XXX_REG_AP] = INVALID_REG_ADDR, [BQ27XXX_REG_AP] = INVALID_REG_ADDR,
}, },
[BQ27510] = {
[BQ27XXX_REG_CTRL] = 0x00,
[BQ27XXX_REG_TEMP] = 0x06,
[BQ27XXX_REG_INT_TEMP] = 0x28,
[BQ27XXX_REG_VOLT] = 0x08,
[BQ27XXX_REG_AI] = 0x14,
[BQ27XXX_REG_FLAGS] = 0x0a,
[BQ27XXX_REG_TTE] = 0x16,
[BQ27XXX_REG_TTF] = INVALID_REG_ADDR,
[BQ27XXX_REG_TTES] = 0x1a,
[BQ27XXX_REG_TTECP] = INVALID_REG_ADDR,
[BQ27XXX_REG_NAC] = 0x0c,
[BQ27XXX_REG_FCC] = 0x12,
[BQ27XXX_REG_CYCT] = 0x1e,
[BQ27XXX_REG_AE] = INVALID_REG_ADDR,
[BQ27XXX_REG_SOC] = 0x20,
[BQ27XXX_REG_DCAP] = 0x2e,
[BQ27XXX_REG_AP] = INVALID_REG_ADDR,
},
[BQ27530] = { [BQ27530] = {
[BQ27XXX_REG_CTRL] = 0x00, [BQ27XXX_REG_CTRL] = 0x00,
[BQ27XXX_REG_TEMP] = 0x06, [BQ27XXX_REG_TEMP] = 0x06,
...@@ -302,6 +321,24 @@ static enum power_supply_property bq27500_battery_props[] = { ...@@ -302,6 +321,24 @@ static enum power_supply_property bq27500_battery_props[] = {
POWER_SUPPLY_PROP_MANUFACTURER, POWER_SUPPLY_PROP_MANUFACTURER,
}; };
static enum power_supply_property bq27510_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_CHARGE_FULL_DESIGN,
POWER_SUPPLY_PROP_CYCLE_COUNT,
POWER_SUPPLY_PROP_HEALTH,
POWER_SUPPLY_PROP_MANUFACTURER,
};
static enum power_supply_property bq27530_battery_props[] = { static enum power_supply_property bq27530_battery_props[] = {
POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_PRESENT, POWER_SUPPLY_PROP_PRESENT,
...@@ -385,6 +422,7 @@ static struct { ...@@ -385,6 +422,7 @@ static struct {
BQ27XXX_PROP(BQ27000, bq27000_battery_props), BQ27XXX_PROP(BQ27000, bq27000_battery_props),
BQ27XXX_PROP(BQ27010, bq27010_battery_props), BQ27XXX_PROP(BQ27010, bq27010_battery_props),
BQ27XXX_PROP(BQ27500, bq27500_battery_props), BQ27XXX_PROP(BQ27500, bq27500_battery_props),
BQ27XXX_PROP(BQ27510, bq27510_battery_props),
BQ27XXX_PROP(BQ27530, bq27530_battery_props), BQ27XXX_PROP(BQ27530, bq27530_battery_props),
BQ27XXX_PROP(BQ27541, bq27541_battery_props), BQ27XXX_PROP(BQ27541, bq27541_battery_props),
BQ27XXX_PROP(BQ27545, bq27545_battery_props), BQ27XXX_PROP(BQ27545, bq27545_battery_props),
...@@ -397,10 +435,11 @@ static LIST_HEAD(bq27xxx_battery_devices); ...@@ -397,10 +435,11 @@ static LIST_HEAD(bq27xxx_battery_devices);
static int poll_interval_param_set(const char *val, const struct kernel_param *kp) static int poll_interval_param_set(const char *val, const struct kernel_param *kp)
{ {
struct bq27xxx_device_info *di; struct bq27xxx_device_info *di;
unsigned int prev_val = *(unsigned int *) kp->arg;
int ret; int ret;
ret = param_set_uint(val, kp); ret = param_set_uint(val, kp);
if (ret < 0) if (ret < 0 || prev_val == *(unsigned int *) kp->arg)
return ret; return ret;
mutex_lock(&bq27xxx_list_lock); mutex_lock(&bq27xxx_list_lock);
...@@ -635,7 +674,8 @@ static int bq27xxx_battery_read_pwr_avg(struct bq27xxx_device_info *di) ...@@ -635,7 +674,8 @@ static int bq27xxx_battery_read_pwr_avg(struct bq27xxx_device_info *di)
*/ */
static bool bq27xxx_battery_overtemp(struct bq27xxx_device_info *di, u16 flags) static bool bq27xxx_battery_overtemp(struct bq27xxx_device_info *di, u16 flags)
{ {
if (di->chip == BQ27500 || di->chip == BQ27541 || di->chip == BQ27545) if (di->chip == BQ27500 || di->chip == BQ27510 ||
di->chip == BQ27541 || di->chip == BQ27545)
return flags & (BQ27XXX_FLAG_OTC | BQ27XXX_FLAG_OTD); return flags & (BQ27XXX_FLAG_OTC | BQ27XXX_FLAG_OTD);
if (di->chip == BQ27530 || di->chip == BQ27421) if (di->chip == BQ27530 || di->chip == BQ27421)
return flags & BQ27XXX_FLAG_OT; return flags & BQ27XXX_FLAG_OT;
......
...@@ -149,8 +149,8 @@ static const struct i2c_device_id bq27xxx_i2c_id_table[] = { ...@@ -149,8 +149,8 @@ static const struct i2c_device_id bq27xxx_i2c_id_table[] = {
{ "bq27200", BQ27000 }, { "bq27200", BQ27000 },
{ "bq27210", BQ27010 }, { "bq27210", BQ27010 },
{ "bq27500", BQ27500 }, { "bq27500", BQ27500 },
{ "bq27510", BQ27500 }, { "bq27510", BQ27510 },
{ "bq27520", BQ27500 }, { "bq27520", BQ27510 },
{ "bq27530", BQ27530 }, { "bq27530", BQ27530 },
{ "bq27531", BQ27530 }, { "bq27531", BQ27530 },
{ "bq27541", BQ27541 }, { "bq27541", BQ27541 },
......
...@@ -313,4 +313,4 @@ module_platform_driver(micro_batt_device_driver); ...@@ -313,4 +313,4 @@ module_platform_driver(micro_batt_device_driver);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("driver for iPAQ Atmel micro battery"); MODULE_DESCRIPTION("driver for iPAQ Atmel micro battery");
MODULE_ALIAS("platform:battery-ipaq-micro"); MODULE_ALIAS("platform:ipaq-micro-battery");
...@@ -384,9 +384,6 @@ static int lp8788_update_charger_params(struct platform_device *pdev, ...@@ -384,9 +384,6 @@ static int lp8788_update_charger_params(struct platform_device *pdev,
for (i = 0; i < pdata->num_chg_params; i++) { for (i = 0; i < pdata->num_chg_params; i++) {
param = pdata->chg_params + i; param = pdata->chg_params + i;
if (!param)
continue;
if (lp8788_is_valid_charger_register(param->addr)) { if (lp8788_is_valid_charger_register(param->addr)) {
ret = lp8788_write_byte(lp, param->addr, param->val); ret = lp8788_write_byte(lp, param->addr, param->val);
if (ret) if (ret)
......
...@@ -21,18 +21,13 @@ ...@@ -21,18 +21,13 @@
#include <linux/max17040_battery.h> #include <linux/max17040_battery.h>
#include <linux/slab.h> #include <linux/slab.h>
#define MAX17040_VCELL_MSB 0x02 #define MAX17040_VCELL 0x02
#define MAX17040_VCELL_LSB 0x03 #define MAX17040_SOC 0x04
#define MAX17040_SOC_MSB 0x04 #define MAX17040_MODE 0x06
#define MAX17040_SOC_LSB 0x05 #define MAX17040_VER 0x08
#define MAX17040_MODE_MSB 0x06 #define MAX17040_RCOMP 0x0C
#define MAX17040_MODE_LSB 0x07 #define MAX17040_CMD 0xFE
#define MAX17040_VER_MSB 0x08
#define MAX17040_VER_LSB 0x09
#define MAX17040_RCOMP_MSB 0x0C
#define MAX17040_RCOMP_LSB 0x0D
#define MAX17040_CMD_MSB 0xFE
#define MAX17040_CMD_LSB 0xFF
#define MAX17040_DELAY 1000 #define MAX17040_DELAY 1000
#define MAX17040_BATTERY_FULL 95 #define MAX17040_BATTERY_FULL 95
...@@ -78,11 +73,11 @@ static int max17040_get_property(struct power_supply *psy, ...@@ -78,11 +73,11 @@ static int max17040_get_property(struct power_supply *psy,
return 0; return 0;
} }
static int max17040_write_reg(struct i2c_client *client, int reg, u8 value) static int max17040_write_reg(struct i2c_client *client, int reg, u16 value)
{ {
int ret; int ret;
ret = i2c_smbus_write_byte_data(client, reg, value); ret = i2c_smbus_write_word_swapped(client, reg, value);
if (ret < 0) if (ret < 0)
dev_err(&client->dev, "%s: err %d\n", __func__, ret); dev_err(&client->dev, "%s: err %d\n", __func__, ret);
...@@ -94,7 +89,7 @@ static int max17040_read_reg(struct i2c_client *client, int reg) ...@@ -94,7 +89,7 @@ static int max17040_read_reg(struct i2c_client *client, int reg)
{ {
int ret; int ret;
ret = i2c_smbus_read_byte_data(client, reg); ret = i2c_smbus_read_word_swapped(client, reg);
if (ret < 0) if (ret < 0)
dev_err(&client->dev, "%s: err %d\n", __func__, ret); dev_err(&client->dev, "%s: err %d\n", __func__, ret);
...@@ -104,43 +99,36 @@ static int max17040_read_reg(struct i2c_client *client, int reg) ...@@ -104,43 +99,36 @@ static int max17040_read_reg(struct i2c_client *client, int reg)
static void max17040_reset(struct i2c_client *client) static void max17040_reset(struct i2c_client *client)
{ {
max17040_write_reg(client, MAX17040_CMD_MSB, 0x54); max17040_write_reg(client, MAX17040_CMD, 0x0054);
max17040_write_reg(client, MAX17040_CMD_LSB, 0x00);
} }
static void max17040_get_vcell(struct i2c_client *client) static void max17040_get_vcell(struct i2c_client *client)
{ {
struct max17040_chip *chip = i2c_get_clientdata(client); struct max17040_chip *chip = i2c_get_clientdata(client);
u8 msb; u16 vcell;
u8 lsb;
msb = max17040_read_reg(client, MAX17040_VCELL_MSB); vcell = max17040_read_reg(client, MAX17040_VCELL);
lsb = max17040_read_reg(client, MAX17040_VCELL_LSB);
chip->vcell = (msb << 4) + (lsb >> 4); chip->vcell = vcell;
} }
static void max17040_get_soc(struct i2c_client *client) static void max17040_get_soc(struct i2c_client *client)
{ {
struct max17040_chip *chip = i2c_get_clientdata(client); struct max17040_chip *chip = i2c_get_clientdata(client);
u8 msb; u16 soc;
u8 lsb;
msb = max17040_read_reg(client, MAX17040_SOC_MSB); soc = max17040_read_reg(client, MAX17040_SOC);
lsb = max17040_read_reg(client, MAX17040_SOC_LSB);
chip->soc = msb; chip->soc = (soc >> 8);
} }
static void max17040_get_version(struct i2c_client *client) static void max17040_get_version(struct i2c_client *client)
{ {
u8 msb; u16 version;
u8 lsb;
msb = max17040_read_reg(client, MAX17040_VER_MSB); version = max17040_read_reg(client, MAX17040_VER);
lsb = max17040_read_reg(client, MAX17040_VER_LSB);
dev_info(&client->dev, "MAX17040 Fuel-Gauge Ver %d%d\n", msb, lsb); dev_info(&client->dev, "MAX17040 Fuel-Gauge Ver 0x%x\n", version);
} }
static void max17040_get_online(struct i2c_client *client) static void max17040_get_online(struct i2c_client *client)
......
...@@ -184,6 +184,7 @@ static const struct platform_device_id max8997_battery_id[] = { ...@@ -184,6 +184,7 @@ static const struct platform_device_id max8997_battery_id[] = {
{ "max8997-battery", 0 }, { "max8997-battery", 0 },
{ } { }
}; };
MODULE_DEVICE_TABLE(platform, max8997_battery_id);
static struct platform_driver max8997_battery_driver = { static struct platform_driver max8997_battery_driver = {
.driver = { .driver = {
......
...@@ -413,7 +413,7 @@ static int power_supply_match_device_node(struct device *dev, const void *data) ...@@ -413,7 +413,7 @@ static int power_supply_match_device_node(struct device *dev, const void *data)
/** /**
* power_supply_get_by_phandle() - Search for a power supply and returns its ref * power_supply_get_by_phandle() - Search for a power supply and returns its ref
* @np: Pointer to device node holding phandle property * @np: Pointer to device node holding phandle property
* @phandle_name: Name of property holding a power supply name * @property: Name of property holding a power supply name
* *
* If power supply was found, it increases reference count for the * If power supply was found, it increases reference count for the
* internal power supply's device. The user should power_supply_put() * internal power supply's device. The user should power_supply_put()
...@@ -458,7 +458,7 @@ static void devm_power_supply_put(struct device *dev, void *res) ...@@ -458,7 +458,7 @@ static void devm_power_supply_put(struct device *dev, void *res)
* devm_power_supply_get_by_phandle() - Resource managed version of * devm_power_supply_get_by_phandle() - Resource managed version of
* power_supply_get_by_phandle() * power_supply_get_by_phandle()
* @dev: Pointer to device holding phandle property * @dev: Pointer to device holding phandle property
* @phandle_name: Name of property holding a power supply phandle * @property: Name of property holding a power supply phandle
* *
* Return: On success returns a reference to a power supply with * Return: On success returns a reference to a power supply with
* matching name equals to value under @property, NULL or ERR_PTR otherwise. * matching name equals to value under @property, NULL or ERR_PTR otherwise.
......
...@@ -182,7 +182,7 @@ static ssize_t charger_state_show(struct device *dev, ...@@ -182,7 +182,7 @@ static ssize_t charger_state_show(struct device *dev,
return sprintf(buf, "%s\n", charge); return sprintf(buf, "%s\n", charge);
} }
static DEVICE_ATTR(charger_state, 0444, charger_state_show, NULL); static DEVICE_ATTR_RO(charger_state);
static irqreturn_t wm8350_charger_handler(int irq, void *data) static irqreturn_t wm8350_charger_handler(int irq, void *data)
{ {
......
...@@ -30,8 +30,7 @@ static enum power_supply_property *prop; ...@@ -30,8 +30,7 @@ static enum power_supply_property *prop;
static unsigned long wm97xx_read_bat(struct power_supply *bat_ps) static unsigned long wm97xx_read_bat(struct power_supply *bat_ps)
{ {
struct wm97xx_pdata *wmdata = bat_ps->dev.parent->platform_data; struct wm97xx_batt_pdata *pdata = power_supply_get_drvdata(bat_ps);
struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
return wm97xx_read_aux_adc(dev_get_drvdata(bat_ps->dev.parent), return wm97xx_read_aux_adc(dev_get_drvdata(bat_ps->dev.parent),
pdata->batt_aux) * pdata->batt_mult / pdata->batt_aux) * pdata->batt_mult /
...@@ -40,8 +39,7 @@ static unsigned long wm97xx_read_bat(struct power_supply *bat_ps) ...@@ -40,8 +39,7 @@ static unsigned long wm97xx_read_bat(struct power_supply *bat_ps)
static unsigned long wm97xx_read_temp(struct power_supply *bat_ps) static unsigned long wm97xx_read_temp(struct power_supply *bat_ps)
{ {
struct wm97xx_pdata *wmdata = bat_ps->dev.parent->platform_data; struct wm97xx_batt_pdata *pdata = power_supply_get_drvdata(bat_ps);
struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
return wm97xx_read_aux_adc(dev_get_drvdata(bat_ps->dev.parent), return wm97xx_read_aux_adc(dev_get_drvdata(bat_ps->dev.parent),
pdata->temp_aux) * pdata->temp_mult / pdata->temp_aux) * pdata->temp_mult /
...@@ -52,8 +50,7 @@ static int wm97xx_bat_get_property(struct power_supply *bat_ps, ...@@ -52,8 +50,7 @@ static int wm97xx_bat_get_property(struct power_supply *bat_ps,
enum power_supply_property psp, enum power_supply_property psp,
union power_supply_propval *val) union power_supply_propval *val)
{ {
struct wm97xx_pdata *wmdata = bat_ps->dev.parent->platform_data; struct wm97xx_batt_pdata *pdata = power_supply_get_drvdata(bat_ps);
struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
switch (psp) { switch (psp) {
case POWER_SUPPLY_PROP_STATUS: case POWER_SUPPLY_PROP_STATUS:
...@@ -103,8 +100,7 @@ static void wm97xx_bat_external_power_changed(struct power_supply *bat_ps) ...@@ -103,8 +100,7 @@ static void wm97xx_bat_external_power_changed(struct power_supply *bat_ps)
static void wm97xx_bat_update(struct power_supply *bat_ps) static void wm97xx_bat_update(struct power_supply *bat_ps)
{ {
int old_status = bat_status; int old_status = bat_status;
struct wm97xx_pdata *wmdata = bat_ps->dev.parent->platform_data; struct wm97xx_batt_pdata *pdata = power_supply_get_drvdata(bat_ps);
struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
mutex_lock(&work_lock); mutex_lock(&work_lock);
...@@ -166,15 +162,15 @@ static int wm97xx_bat_probe(struct platform_device *dev) ...@@ -166,15 +162,15 @@ static int wm97xx_bat_probe(struct platform_device *dev)
int ret = 0; int ret = 0;
int props = 1; /* POWER_SUPPLY_PROP_PRESENT */ int props = 1; /* POWER_SUPPLY_PROP_PRESENT */
int i = 0; int i = 0;
struct wm97xx_pdata *wmdata = dev->dev.platform_data; struct wm97xx_batt_pdata *pdata = dev->dev.platform_data;
struct wm97xx_batt_pdata *pdata; struct power_supply_config cfg = {};
if (!wmdata) { if (!pdata) {
dev_err(&dev->dev, "No platform data supplied\n"); dev_err(&dev->dev, "No platform data supplied\n");
return -EINVAL; return -EINVAL;
} }
pdata = wmdata->batt_pdata; cfg.drv_data = pdata;
if (dev->id != -1) if (dev->id != -1)
return -EINVAL; return -EINVAL;
...@@ -243,7 +239,7 @@ static int wm97xx_bat_probe(struct platform_device *dev) ...@@ -243,7 +239,7 @@ static int wm97xx_bat_probe(struct platform_device *dev)
bat_psy_desc.properties = prop; bat_psy_desc.properties = prop;
bat_psy_desc.num_properties = props; bat_psy_desc.num_properties = props;
bat_psy = power_supply_register(&dev->dev, &bat_psy_desc, NULL); bat_psy = power_supply_register(&dev->dev, &bat_psy_desc, &cfg);
if (!IS_ERR(bat_psy)) { if (!IS_ERR(bat_psy)) {
schedule_work(&bat_work); schedule_work(&bat_work);
} else { } else {
...@@ -266,8 +262,7 @@ static int wm97xx_bat_probe(struct platform_device *dev) ...@@ -266,8 +262,7 @@ static int wm97xx_bat_probe(struct platform_device *dev)
static int wm97xx_bat_remove(struct platform_device *dev) static int wm97xx_bat_remove(struct platform_device *dev)
{ {
struct wm97xx_pdata *wmdata = dev->dev.platform_data; struct wm97xx_batt_pdata *pdata = dev->dev.platform_data;
struct wm97xx_batt_pdata *pdata = wmdata->batt_pdata;
if (pdata && gpio_is_valid(pdata->charge_gpio)) { if (pdata && gpio_is_valid(pdata->charge_gpio)) {
free_irq(gpio_to_irq(pdata->charge_gpio), dev); free_irq(gpio_to_irq(pdata->charge_gpio), dev);
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
enum bq27xxx_chip { enum bq27xxx_chip {
BQ27000 = 1, /* bq27000, bq27200 */ BQ27000 = 1, /* bq27000, bq27200 */
BQ27010, /* bq27010, bq27210 */ BQ27010, /* bq27010, bq27210 */
BQ27500, /* bq27500, bq27510, bq27520 */ BQ27500, /* bq27500 */
BQ27510, /* bq27510, bq27520 */
BQ27530, /* bq27530, bq27531 */ BQ27530, /* bq27530, bq27531 */
BQ27541, /* bq27541, bq27542, bq27546, bq27742 */ BQ27541, /* bq27541, bq27542, bq27546, bq27742 */
BQ27545, /* bq27545 */ BQ27545, /* bq27545 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment