Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: supply: smb347-charger: Remove virtual smb347-battery

SMB347 is a charger and not a battery driver. Secondly, power-supply core
now supports monitored-battery. So the 'fake' battery doesn't do anything
useful for us, and thus, it should be removed.

Transfer smb347-battery functionality into smb347-mains and smb347-usb.

Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: David Heidelberg <david@ixit.cz>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

David Heidelberg and committed by
Sebastian Reichel
db14d3b4 de76fd29

+60 -146
+60 -146
drivers/power/supply/smb347-charger.c
··· 127 127 * @regmap: pointer to driver regmap 128 128 * @mains: power_supply instance for AC/DC power 129 129 * @usb: power_supply instance for USB power 130 - * @battery: power_supply instance for battery 131 130 * @id: SMB charger ID 132 131 * @mains_online: is AC/DC input connected 133 132 * @usb_online: is USB input connected ··· 139 140 struct regmap *regmap; 140 141 struct power_supply *mains; 141 142 struct power_supply *usb; 142 - struct power_supply *battery; 143 143 unsigned int id; 144 144 bool mains_online; 145 145 bool usb_online; ··· 741 743 */ 742 744 if (stat_c & STAT_C_CHARGER_ERROR) { 743 745 dev_err(smb->dev, "charging stopped due to charger error\n"); 744 - power_supply_changed(smb->battery); 746 + if (smb->pdata->use_mains) 747 + power_supply_changed(smb->mains); 748 + if (smb->pdata->use_usb) 749 + power_supply_changed(smb->usb); 745 750 handled = true; 746 751 } 747 752 ··· 754 753 * disabled by the hardware. 755 754 */ 756 755 if (irqstat_c & (IRQSTAT_C_TERMINATION_IRQ | IRQSTAT_C_TAPER_IRQ)) { 757 - if (irqstat_c & IRQSTAT_C_TERMINATION_STAT) 758 - power_supply_changed(smb->battery); 756 + if (irqstat_c & IRQSTAT_C_TERMINATION_STAT) { 757 + if (smb->pdata->use_mains) 758 + power_supply_changed(smb->mains); 759 + if (smb->pdata->use_usb) 760 + power_supply_changed(smb->usb); 761 + } 759 762 dev_dbg(smb->dev, "going to HW maintenance mode\n"); 760 763 handled = true; 761 764 } ··· 773 768 774 769 if (irqstat_d & IRQSTAT_D_CHARGE_TIMEOUT_STAT) 775 770 dev_warn(smb->dev, "charging stopped due to timeout\n"); 776 - power_supply_changed(smb->battery); 771 + if (smb->pdata->use_mains) 772 + power_supply_changed(smb->mains); 773 + if (smb->pdata->use_usb) 774 + power_supply_changed(smb->usb); 777 775 handled = true; 778 776 } 779 777 ··· 944 936 return intval; 945 937 } 946 938 947 - static int smb347_mains_get_property(struct power_supply *psy, 948 - enum power_supply_property prop, 949 - union power_supply_propval *val) 950 - { 951 - struct smb347_charger *smb = power_supply_get_drvdata(psy); 952 - int ret; 953 - 954 - switch (prop) { 955 - case POWER_SUPPLY_PROP_ONLINE: 956 - val->intval = smb->mains_online; 957 - break; 958 - 959 - case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: 960 - ret = get_const_charge_voltage(smb); 961 - if (ret < 0) 962 - return ret; 963 - else 964 - val->intval = ret; 965 - break; 966 - 967 - case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: 968 - ret = get_const_charge_current(smb); 969 - if (ret < 0) 970 - return ret; 971 - else 972 - val->intval = ret; 973 - break; 974 - 975 - default: 976 - return -EINVAL; 977 - } 978 - 979 - return 0; 980 - } 981 - 982 - static enum power_supply_property smb347_mains_properties[] = { 983 - POWER_SUPPLY_PROP_ONLINE, 984 - POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, 985 - POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, 986 - }; 987 - 988 - static int smb347_usb_get_property(struct power_supply *psy, 989 - enum power_supply_property prop, 990 - union power_supply_propval *val) 991 - { 992 - struct smb347_charger *smb = power_supply_get_drvdata(psy); 993 - int ret; 994 - 995 - switch (prop) { 996 - case POWER_SUPPLY_PROP_ONLINE: 997 - val->intval = smb->usb_online; 998 - break; 999 - 1000 - case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: 1001 - ret = get_const_charge_voltage(smb); 1002 - if (ret < 0) 1003 - return ret; 1004 - else 1005 - val->intval = ret; 1006 - break; 1007 - 1008 - case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: 1009 - ret = get_const_charge_current(smb); 1010 - if (ret < 0) 1011 - return ret; 1012 - else 1013 - val->intval = ret; 1014 - break; 1015 - 1016 - default: 1017 - return -EINVAL; 1018 - } 1019 - 1020 - return 0; 1021 - } 1022 - 1023 - static enum power_supply_property smb347_usb_properties[] = { 1024 - POWER_SUPPLY_PROP_ONLINE, 1025 - POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, 1026 - POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, 1027 - }; 1028 - 1029 - static int smb347_get_charging_status(struct smb347_charger *smb) 939 + static int smb347_get_charging_status(struct smb347_charger *smb, 940 + struct power_supply *psy) 1030 941 { 1031 942 int ret, status; 1032 943 unsigned int val; 1033 944 1034 - if (!smb347_is_ps_online(smb)) 1035 - return POWER_SUPPLY_STATUS_DISCHARGING; 945 + if (psy->desc->type == POWER_SUPPLY_TYPE_USB) { 946 + if (!smb->usb_online) 947 + return POWER_SUPPLY_STATUS_DISCHARGING; 948 + } else { 949 + if (!smb->mains_online) 950 + return POWER_SUPPLY_STATUS_DISCHARGING; 951 + } 1036 952 1037 953 ret = regmap_read(smb->regmap, STAT_C, &val); 1038 954 if (ret < 0) ··· 995 1063 return status; 996 1064 } 997 1065 998 - static int smb347_battery_get_property(struct power_supply *psy, 999 - enum power_supply_property prop, 1000 - union power_supply_propval *val) 1066 + static int smb347_get_property(struct power_supply *psy, 1067 + enum power_supply_property prop, 1068 + union power_supply_propval *val) 1001 1069 { 1002 1070 struct smb347_charger *smb = power_supply_get_drvdata(psy); 1003 - const struct smb347_charger_platform_data *pdata = smb->pdata; 1004 1071 int ret; 1005 - 1006 - ret = smb347_update_ps_status(smb); 1007 - if (ret < 0) 1008 - return ret; 1009 1072 1010 1073 switch (prop) { 1011 1074 case POWER_SUPPLY_PROP_STATUS: 1012 - ret = smb347_get_charging_status(smb); 1075 + ret = smb347_get_charging_status(smb, psy); 1013 1076 if (ret < 0) 1014 1077 return ret; 1015 1078 val->intval = ret; 1016 1079 break; 1017 1080 1018 1081 case POWER_SUPPLY_PROP_CHARGE_TYPE: 1019 - if (!smb347_is_ps_online(smb)) 1020 - return -ENODATA; 1082 + if (psy->desc->type == POWER_SUPPLY_TYPE_USB) { 1083 + if (!smb->usb_online) 1084 + return -ENODATA; 1085 + } else { 1086 + if (!smb->mains_online) 1087 + return -ENODATA; 1088 + } 1021 1089 1022 1090 /* 1023 1091 * We handle trickle and pre-charging the same, and taper ··· 1036 1104 } 1037 1105 break; 1038 1106 1039 - case POWER_SUPPLY_PROP_TECHNOLOGY: 1040 - val->intval = pdata->battery_info.technology; 1107 + case POWER_SUPPLY_PROP_ONLINE: 1108 + if (psy->desc->type == POWER_SUPPLY_TYPE_USB) 1109 + val->intval = smb->usb_online; 1110 + else 1111 + val->intval = smb->mains_online; 1041 1112 break; 1042 1113 1043 - case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: 1044 - val->intval = pdata->battery_info.voltage_min_design; 1114 + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: 1115 + ret = get_const_charge_voltage(smb); 1116 + if (ret < 0) 1117 + return ret; 1118 + val->intval = ret; 1045 1119 break; 1046 1120 1047 - case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: 1048 - val->intval = pdata->battery_info.voltage_max_design; 1049 - break; 1050 - 1051 - case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: 1052 - val->intval = pdata->battery_info.charge_full_design; 1053 - break; 1054 - 1055 - case POWER_SUPPLY_PROP_MODEL_NAME: 1056 - val->strval = pdata->battery_info.name; 1121 + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: 1122 + ret = get_const_charge_current(smb); 1123 + if (ret < 0) 1124 + return ret; 1125 + val->intval = ret; 1057 1126 break; 1058 1127 1059 1128 default: ··· 1064 1131 return 0; 1065 1132 } 1066 1133 1067 - static enum power_supply_property smb347_battery_properties[] = { 1134 + static enum power_supply_property smb347_properties[] = { 1068 1135 POWER_SUPPLY_PROP_STATUS, 1069 1136 POWER_SUPPLY_PROP_CHARGE_TYPE, 1070 - POWER_SUPPLY_PROP_TECHNOLOGY, 1071 - POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, 1072 - POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, 1073 - POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, 1074 - POWER_SUPPLY_PROP_MODEL_NAME, 1137 + POWER_SUPPLY_PROP_ONLINE, 1138 + POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, 1139 + POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, 1075 1140 }; 1076 1141 1077 1142 static bool smb347_volatile_reg(struct device *dev, unsigned int reg) ··· 1239 1308 static const struct power_supply_desc smb347_mains_desc = { 1240 1309 .name = "smb347-mains", 1241 1310 .type = POWER_SUPPLY_TYPE_MAINS, 1242 - .get_property = smb347_mains_get_property, 1243 - .properties = smb347_mains_properties, 1244 - .num_properties = ARRAY_SIZE(smb347_mains_properties), 1311 + .get_property = smb347_get_property, 1312 + .properties = smb347_properties, 1313 + .num_properties = ARRAY_SIZE(smb347_properties), 1245 1314 }; 1246 1315 1247 1316 static const struct power_supply_desc smb347_usb_desc = { 1248 1317 .name = "smb347-usb", 1249 1318 .type = POWER_SUPPLY_TYPE_USB, 1250 - .get_property = smb347_usb_get_property, 1251 - .properties = smb347_usb_properties, 1252 - .num_properties = ARRAY_SIZE(smb347_usb_properties), 1253 - }; 1254 - 1255 - static const struct power_supply_desc smb347_battery_desc = { 1256 - .name = "smb347-battery", 1257 - .type = POWER_SUPPLY_TYPE_BATTERY, 1258 - .get_property = smb347_battery_get_property, 1259 - .properties = smb347_battery_properties, 1260 - .num_properties = ARRAY_SIZE(smb347_battery_properties), 1319 + .get_property = smb347_get_property, 1320 + .properties = smb347_properties, 1321 + .num_properties = ARRAY_SIZE(smb347_properties), 1261 1322 }; 1262 1323 1263 1324 static int smb347_probe(struct i2c_client *client, 1264 1325 const struct i2c_device_id *id) 1265 1326 { 1266 - static char *battery[] = { "smb347-battery" }; 1267 - struct power_supply_config mains_usb_cfg = {}, battery_cfg = {}; 1327 + struct power_supply_config mains_usb_cfg = {}; 1268 1328 struct device *dev = &client->dev; 1269 1329 struct smb347_charger *smb; 1270 1330 int ret; ··· 1281 1359 if (IS_ERR(smb->regmap)) 1282 1360 return PTR_ERR(smb->regmap); 1283 1361 1284 - mains_usb_cfg.supplied_to = battery; 1285 - mains_usb_cfg.num_supplicants = ARRAY_SIZE(battery); 1286 1362 mains_usb_cfg.drv_data = smb; 1287 1363 mains_usb_cfg.of_node = dev->of_node; 1288 1364 if (smb->pdata->use_mains) { ··· 1296 1376 if (IS_ERR(smb->usb)) 1297 1377 return PTR_ERR(smb->usb); 1298 1378 } 1299 - 1300 - battery_cfg.drv_data = smb; 1301 - smb->battery = devm_power_supply_register(dev, &smb347_battery_desc, 1302 - &battery_cfg); 1303 - if (IS_ERR(smb->battery)) 1304 - return PTR_ERR(smb->battery); 1305 1379 1306 1380 ret = smb347_get_battery_info(smb); 1307 1381 if (ret)