127127 * @regmap: pointer to driver regmap
128128 * @mains: power_supply instance for AC/DC power
129129 * @usb: power_supply instance for USB power
130- * @battery: power_supply instance for battery
131130 * @id: SMB charger ID
132131 * @mains_online: is AC/DC input connected
133132 * @usb_online: is USB input connected
@@ -140,7 +139,6 @@ struct smb347_charger {
140139 struct regmap * regmap ;
141140 struct power_supply * mains ;
142141 struct power_supply * usb ;
143- struct power_supply * battery ;
144142 unsigned int id ;
145143 bool mains_online ;
146144 bool usb_online ;
@@ -743,7 +741,10 @@ static irqreturn_t smb347_interrupt(int irq, void *data)
743741 */
744742 if (stat_c & STAT_C_CHARGER_ERROR ) {
745743 dev_err (smb -> dev , "charging stopped due to charger error\n" );
746- power_supply_changed (smb -> battery );
744+ if (smb -> pdata -> use_mains )
745+ power_supply_changed (smb -> mains );
746+ if (smb -> pdata -> use_usb )
747+ power_supply_changed (smb -> usb );
747748 handled = true;
748749 }
749750
@@ -753,8 +754,12 @@ static irqreturn_t smb347_interrupt(int irq, void *data)
753754 * disabled by the hardware.
754755 */
755756 if (irqstat_c & (IRQSTAT_C_TERMINATION_IRQ | IRQSTAT_C_TAPER_IRQ )) {
756- if (irqstat_c & IRQSTAT_C_TERMINATION_STAT )
757- power_supply_changed (smb -> battery );
757+ if (irqstat_c & IRQSTAT_C_TERMINATION_STAT ) {
758+ if (smb -> pdata -> use_mains )
759+ power_supply_changed (smb -> mains );
760+ if (smb -> pdata -> use_usb )
761+ power_supply_changed (smb -> usb );
762+ }
758763 dev_dbg (smb -> dev , "going to HW maintenance mode\n" );
759764 handled = true;
760765 }
@@ -768,7 +773,10 @@ static irqreturn_t smb347_interrupt(int irq, void *data)
768773
769774 if (irqstat_d & IRQSTAT_D_CHARGE_TIMEOUT_STAT )
770775 dev_warn (smb -> dev , "charging stopped due to timeout\n" );
771- power_supply_changed (smb -> battery );
776+ if (smb -> pdata -> use_mains )
777+ power_supply_changed (smb -> mains );
778+ if (smb -> pdata -> use_usb )
779+ power_supply_changed (smb -> usb );
772780 handled = true;
773781 }
774782
@@ -936,95 +944,19 @@ static int get_const_charge_voltage(struct smb347_charger *smb)
936944 return intval ;
937945}
938946
939- static int smb347_mains_get_property (struct power_supply * psy ,
940- enum power_supply_property prop ,
941- union power_supply_propval * val )
942- {
943- struct smb347_charger * smb = power_supply_get_drvdata (psy );
944- int ret ;
945-
946- switch (prop ) {
947- case POWER_SUPPLY_PROP_ONLINE :
948- val -> intval = smb -> mains_online ;
949- break ;
950-
951- case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE :
952- ret = get_const_charge_voltage (smb );
953- if (ret < 0 )
954- return ret ;
955- else
956- val -> intval = ret ;
957- break ;
958-
959- case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT :
960- ret = get_const_charge_current (smb );
961- if (ret < 0 )
962- return ret ;
963- else
964- val -> intval = ret ;
965- break ;
966-
967- default :
968- return - EINVAL ;
969- }
970-
971- return 0 ;
972- }
973-
974- static enum power_supply_property smb347_mains_properties [] = {
975- POWER_SUPPLY_PROP_ONLINE ,
976- POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT ,
977- POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE ,
978- };
979-
980- static int smb347_usb_get_property (struct power_supply * psy ,
981- enum power_supply_property prop ,
982- union power_supply_propval * val )
983- {
984- struct smb347_charger * smb = power_supply_get_drvdata (psy );
985- int ret ;
986-
987- switch (prop ) {
988- case POWER_SUPPLY_PROP_ONLINE :
989- val -> intval = smb -> usb_online ;
990- break ;
991-
992- case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE :
993- ret = get_const_charge_voltage (smb );
994- if (ret < 0 )
995- return ret ;
996- else
997- val -> intval = ret ;
998- break ;
999-
1000- case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT :
1001- ret = get_const_charge_current (smb );
1002- if (ret < 0 )
1003- return ret ;
1004- else
1005- val -> intval = ret ;
1006- break ;
1007-
1008- default :
1009- return - EINVAL ;
1010- }
1011-
1012- return 0 ;
1013- }
1014-
1015- static enum power_supply_property smb347_usb_properties [] = {
1016- POWER_SUPPLY_PROP_ONLINE ,
1017- POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT ,
1018- POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE ,
1019- };
1020-
1021- static int smb347_get_charging_status (struct smb347_charger * smb )
947+ static int smb347_get_charging_status (struct smb347_charger * smb ,
948+ struct power_supply * psy )
1022949{
1023950 int ret , status ;
1024951 unsigned int val ;
1025952
1026- if (!smb347_is_ps_online (smb ))
1027- return POWER_SUPPLY_STATUS_DISCHARGING ;
953+ if (psy -> desc -> type == POWER_SUPPLY_TYPE_USB ) {
954+ if (!smb -> usb_online )
955+ return POWER_SUPPLY_STATUS_DISCHARGING ;
956+ } else {
957+ if (!smb -> mains_online )
958+ return POWER_SUPPLY_STATUS_DISCHARGING ;
959+ }
1028960
1029961 ret = regmap_read (smb -> regmap , STAT_C , & val );
1030962 if (ret < 0 )
@@ -1063,29 +995,29 @@ static int smb347_get_charging_status(struct smb347_charger *smb)
1063995 return status ;
1064996}
1065997
1066- static int smb347_battery_get_property (struct power_supply * psy ,
1067- enum power_supply_property prop ,
1068- union power_supply_propval * val )
998+ static int smb347_get_property (struct power_supply * psy ,
999+ enum power_supply_property prop ,
1000+ union power_supply_propval * val )
10691001{
10701002 struct smb347_charger * smb = power_supply_get_drvdata (psy );
1071- const struct smb347_charger_platform_data * pdata = smb -> pdata ;
10721003 int ret ;
10731004
1074- ret = smb347_update_ps_status (smb );
1075- if (ret < 0 )
1076- return ret ;
1077-
10781005 switch (prop ) {
10791006 case POWER_SUPPLY_PROP_STATUS :
1080- ret = smb347_get_charging_status (smb );
1007+ ret = smb347_get_charging_status (smb , psy );
10811008 if (ret < 0 )
10821009 return ret ;
10831010 val -> intval = ret ;
10841011 break ;
10851012
10861013 case POWER_SUPPLY_PROP_CHARGE_TYPE :
1087- if (!smb347_is_ps_online (smb ))
1088- return - ENODATA ;
1014+ if (psy -> desc -> type == POWER_SUPPLY_TYPE_USB ) {
1015+ if (!smb -> usb_online )
1016+ return - ENODATA ;
1017+ } else {
1018+ if (!smb -> mains_online )
1019+ return - ENODATA ;
1020+ }
10891021
10901022 /*
10911023 * We handle trickle and pre-charging the same, and taper
@@ -1104,24 +1036,25 @@ static int smb347_battery_get_property(struct power_supply *psy,
11041036 }
11051037 break ;
11061038
1107- case POWER_SUPPLY_PROP_TECHNOLOGY :
1108- val -> intval = pdata -> battery_info .technology ;
1109- break ;
1110-
1111- case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN :
1112- val -> intval = pdata -> battery_info .voltage_min_design ;
1113- break ;
1114-
1115- case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN :
1116- val -> intval = pdata -> battery_info .voltage_max_design ;
1039+ case POWER_SUPPLY_PROP_ONLINE :
1040+ if (psy -> desc -> type == POWER_SUPPLY_TYPE_USB )
1041+ val -> intval = smb -> usb_online ;
1042+ else
1043+ val -> intval = smb -> mains_online ;
11171044 break ;
11181045
1119- case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN :
1120- val -> intval = pdata -> battery_info .charge_full_design ;
1046+ case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE :
1047+ ret = get_const_charge_voltage (smb );
1048+ if (ret < 0 )
1049+ return ret ;
1050+ val -> intval = ret ;
11211051 break ;
11221052
1123- case POWER_SUPPLY_PROP_MODEL_NAME :
1124- val -> strval = pdata -> battery_info .name ;
1053+ case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT :
1054+ ret = get_const_charge_current (smb );
1055+ if (ret < 0 )
1056+ return ret ;
1057+ val -> intval = ret ;
11251058 break ;
11261059
11271060 default :
@@ -1131,14 +1064,12 @@ static int smb347_battery_get_property(struct power_supply *psy,
11311064 return 0 ;
11321065}
11331066
1134- static enum power_supply_property smb347_battery_properties [] = {
1067+ static enum power_supply_property smb347_properties [] = {
11351068 POWER_SUPPLY_PROP_STATUS ,
11361069 POWER_SUPPLY_PROP_CHARGE_TYPE ,
1137- POWER_SUPPLY_PROP_TECHNOLOGY ,
1138- POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN ,
1139- POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN ,
1140- POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN ,
1141- POWER_SUPPLY_PROP_MODEL_NAME ,
1070+ POWER_SUPPLY_PROP_ONLINE ,
1071+ POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT ,
1072+ POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE ,
11421073};
11431074
11441075static bool smb347_volatile_reg (struct device * dev , unsigned int reg )
@@ -1308,32 +1239,23 @@ static const struct regmap_config smb347_regmap = {
13081239static const struct power_supply_desc smb347_mains_desc = {
13091240 .name = "smb347-mains" ,
13101241 .type = POWER_SUPPLY_TYPE_MAINS ,
1311- .get_property = smb347_mains_get_property ,
1312- .properties = smb347_mains_properties ,
1313- .num_properties = ARRAY_SIZE (smb347_mains_properties ),
1242+ .get_property = smb347_get_property ,
1243+ .properties = smb347_properties ,
1244+ .num_properties = ARRAY_SIZE (smb347_properties ),
13141245};
13151246
13161247static const struct power_supply_desc smb347_usb_desc = {
13171248 .name = "smb347-usb" ,
13181249 .type = POWER_SUPPLY_TYPE_USB ,
1319- .get_property = smb347_usb_get_property ,
1320- .properties = smb347_usb_properties ,
1321- .num_properties = ARRAY_SIZE (smb347_usb_properties ),
1322- };
1323-
1324- static const struct power_supply_desc smb347_battery_desc = {
1325- .name = "smb347-battery" ,
1326- .type = POWER_SUPPLY_TYPE_BATTERY ,
1327- .get_property = smb347_battery_get_property ,
1328- .properties = smb347_battery_properties ,
1329- .num_properties = ARRAY_SIZE (smb347_battery_properties ),
1250+ .get_property = smb347_get_property ,
1251+ .properties = smb347_properties ,
1252+ .num_properties = ARRAY_SIZE (smb347_properties ),
13301253};
13311254
13321255static int smb347_probe (struct i2c_client * client ,
13331256 const struct i2c_device_id * id )
13341257{
1335- static char * battery [] = { "smb347-battery" };
1336- struct power_supply_config mains_usb_cfg = {}, battery_cfg = {};
1258+ struct power_supply_config mains_usb_cfg = {};
13371259 struct device * dev = & client -> dev ;
13381260 struct smb347_charger * smb ;
13391261 int ret ;
@@ -1359,8 +1281,6 @@ static int smb347_probe(struct i2c_client *client,
13591281 if (IS_ERR (smb -> regmap ))
13601282 return PTR_ERR (smb -> regmap );
13611283
1362- mains_usb_cfg .supplied_to = battery ;
1363- mains_usb_cfg .num_supplicants = ARRAY_SIZE (battery );
13641284 mains_usb_cfg .drv_data = smb ;
13651285 mains_usb_cfg .of_node = dev -> of_node ;
13661286 if (smb -> pdata -> use_mains ) {
@@ -1377,12 +1297,6 @@ static int smb347_probe(struct i2c_client *client,
13771297 return PTR_ERR (smb -> usb );
13781298 }
13791299
1380- battery_cfg .drv_data = smb ;
1381- smb -> battery = devm_power_supply_register (dev , & smb347_battery_desc ,
1382- & battery_cfg );
1383- if (IS_ERR (smb -> battery ))
1384- return PTR_ERR (smb -> battery );
1385-
13861300 ret = smb347_get_battery_info (smb );
13871301 if (ret )
13881302 return ret ;
0 commit comments