--- zzzz-none-000/linux-3.10.107/drivers/power/max8998_charger.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/power/max8998_charger.c 2021-02-04 17:41:59.000000000 +0000 @@ -30,7 +30,7 @@ struct max8998_battery_data { struct device *dev; struct max8998_dev *iodev; - struct power_supply battery; + struct power_supply *battery; }; static enum power_supply_property max8998_battery_props[] = { @@ -43,8 +43,7 @@ enum power_supply_property psp, union power_supply_propval *val) { - struct max8998_battery_data *max8998 = container_of(psy, - struct max8998_battery_data, battery); + struct max8998_battery_data *max8998 = power_supply_get_drvdata(psy); struct i2c_client *i2c = max8998->iodev->i2c; int ret; u8 reg; @@ -75,10 +74,19 @@ return 0; } +static const struct power_supply_desc max8998_battery_desc = { + .name = "max8998_pmic", + .type = POWER_SUPPLY_TYPE_BATTERY, + .get_property = max8998_battery_get_property, + .properties = max8998_battery_props, + .num_properties = ARRAY_SIZE(max8998_battery_props), +}; + static int max8998_battery_probe(struct platform_device *pdev) { struct max8998_dev *iodev = dev_get_drvdata(pdev->dev.parent); struct max8998_platform_data *pdata = dev_get_platdata(iodev->dev); + struct power_supply_config psy_cfg = {}; struct max8998_battery_data *max8998; struct i2c_client *i2c; int ret = 0; @@ -109,8 +117,7 @@ "EOC value not set: leave it unchanged.\n"); } else { dev_err(max8998->dev, "Invalid EOC value\n"); - ret = -EINVAL; - goto err; + return -EINVAL; } /* Setup Charge Restart Level */ @@ -133,8 +140,7 @@ break; default: dev_err(max8998->dev, "Invalid Restart Level\n"); - ret = -EINVAL; - goto err; + return -EINVAL; } /* Setup Charge Full Timeout */ @@ -157,32 +163,20 @@ break; default: dev_err(max8998->dev, "Invalid Full Timeout value\n"); - ret = -EINVAL; - goto err; - } - - max8998->battery.name = "max8998_pmic"; - max8998->battery.type = POWER_SUPPLY_TYPE_BATTERY; - max8998->battery.get_property = max8998_battery_get_property; - max8998->battery.properties = max8998_battery_props; - max8998->battery.num_properties = ARRAY_SIZE(max8998_battery_props); - - ret = power_supply_register(max8998->dev, &max8998->battery); - if (ret) { - dev_err(max8998->dev, "failed: power supply register\n"); - goto err; + return -EINVAL; } - return 0; -err: - return ret; -} - -static int max8998_battery_remove(struct platform_device *pdev) -{ - struct max8998_battery_data *max8998 = platform_get_drvdata(pdev); + psy_cfg.drv_data = max8998; - power_supply_unregister(&max8998->battery); + max8998->battery = devm_power_supply_register(max8998->dev, + &max8998_battery_desc, + &psy_cfg); + if (IS_ERR(max8998->battery)) { + ret = PTR_ERR(max8998->battery); + dev_err(max8998->dev, "failed: power supply register: %d\n", + ret); + return ret; + } return 0; } @@ -195,10 +189,8 @@ static struct platform_driver max8998_battery_driver = { .driver = { .name = "max8998-battery", - .owner = THIS_MODULE, }, .probe = max8998_battery_probe, - .remove = max8998_battery_remove, .id_table = max8998_battery_id, };