duration = curr - cm->charging_start_time;
if (duration > desc->charging_max_duration_ms) {
- dev_info(cm->dev, "Charging duration exceed %lldms",
+ dev_info(cm->dev, "Charging duration exceed %ums",
desc->charging_max_duration_ms);
uevent_notify(cm, "Discharging");
try_charger_enable(cm, false);
if (duration > desc->charging_max_duration_ms &&
is_ext_pwr_online(cm)) {
- dev_info(cm->dev, "DisCharging duration exceed %lldms",
+ dev_info(cm->dev, "DisCharging duration exceed %ums",
desc->discharging_max_duration_ms);
uevent_notify(cm, "Recharing");
try_charger_enable(cm, true);
return last_temp_status;
}
-/*
- * Charger driver platform data
- * To do : Should be transferred to DT.
- */
-
-static char *charger_stats[] = {
-#if defined(CONFIG_CHARGER_MAX77693)
- "max77693-charger",
-#endif
- NULL,
-};
-
-#define BATT_CHARGING_SOURCE_TA 2
-#define BATT_CHARGING_SOURCE_USB 3
-#define BATT_CHARGING_SOURCE_SLOW_TA 4
-#define BATT_CHARGING_SOURCE_FAST_TA 5
-#define BATT_CHARGING_SOURCE_MHL_TA 6
-
-struct charger_cable charger_cable_vinchg1[] = {
- {
- .extcon_name = "max77693-muic",
- .name = "USB",
- .min_uA = 475000,
- .max_uA = 475000 + 25000,
- }, {
- .extcon_name = "max77693-muic",
- .name = "TA",
- .min_uA = 650000,
- .max_uA = 650000 + 25000,
- }, {
- .extcon_name = "max77693-muic",
- .name = "Slow-charger",
- .min_uA = 650000,
- .max_uA = 650000 + 25000,
- }, {
- .extcon_name = "max77693-muic",
- .name = "Fast-charger",
- .min_uA = 650000,
- .max_uA = 650000 + 25000,
- }, {
- .extcon_name = "max77693-muic",
- .name = "MHL",
- .min_uA = 475000,
- .max_uA = 475000 + 25000,
- },
-};
-static struct charger_regulator regulators[] = {
- {
- .regulator_name = "vinchg1",
- .cables = charger_cable_vinchg1,
- .num_cables = ARRAY_SIZE(charger_cable_vinchg1),
- },
-};
-
-static struct charger_desc cm_drv_data = {
- .psy_name = "battery",
- .polling_mode = CM_POLL_EXTERNAL_POWER_ONLY,
- .polling_interval_ms = 30000,
- .fullbatt_vchkdrop_ms = 30000,
- .fullbatt_vchkdrop_uV = 150000,
- .fullbatt_uV = 0,
- .fullbatt_soc = 100,
- .fullbatt_full_capacity = 0,
-
- .battery_present = CM_CHARGER_STAT,
- .psy_charger_stat = charger_stats,
- .num_charger_regulators = 1,
- .psy_fuel_gauge = "max170xx_battery",
- .charger_regulators = regulators,
- .num_charger_regulators = ARRAY_SIZE(regulators),
-
- .measure_battery_temp = true,
-
- .charging_max_duration_ms = (6 * 60 * 60 * 1000), /* 6hr */
- .discharging_max_duration_ms = (1.5 * 60 * 60 * 1000),/* 1.5hr */
-};
-
#ifdef CONFIG_OF
static struct of_device_id charger_manager_match[] = {
{
.compatible = "charger-manager",
- .data = (void *)&cm_drv_data,
},
{},
};
+
+struct charger_desc *of_cm_parse_desc(struct device *dev)
+{
+ struct charger_desc *desc;
+ struct device_node *np = dev->of_node;
+ u32 poll_mode = CM_POLL_DISABLE;
+ u32 battery_stat = CM_NO_BATTERY;
+ int num_chgs;
+
+ desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
+ if (!desc)
+ return ERR_PTR(-ENOMEM);
+
+ of_property_read_string(np, "cm-name", &desc->psy_name);
+
+ of_property_read_u32(np, "cm-poll-mode", &poll_mode);
+ desc->polling_mode = poll_mode;
+
+ of_property_read_u32(np, "cm-poll-interval",
+ &desc->polling_interval_ms);
+
+ of_property_read_u32(np, "cm-fullbatt-vchkdrop-ms",
+ &desc->fullbatt_vchkdrop_ms);
+ of_property_read_u32(np, "cm-fullbatt-vchkdrop-volt",
+ &desc->fullbatt_vchkdrop_uV);
+ of_property_read_u32(np, "cm-fullbatt-voltage", &desc->fullbatt_uV);
+ of_property_read_u32(np, "cm-fullbatt-soc", &desc->fullbatt_soc);
+ of_property_read_u32(np, "cm-fullbatt-capacity",
+ &desc->fullbatt_full_capacity);
+
+ of_property_read_u32(np, "cm-battery-stat", &battery_stat);
+ desc->battery_present = battery_stat;
+
+ of_property_read_u32(np, "cm-battery-cold", &desc->temp_alert_min);
+ if (of_get_property(np, "cm-battery-cold-in-minus", NULL))
+ desc->temp_alert_min *= -1;
+ of_property_read_u32(np, "cm-battery-hot", &desc->temp_alert_max);
+ of_property_read_u32(np, "cm-battery-temp-diff",
+ &desc->temp_alert_diff);
+
+ /* chargers */
+ of_property_read_u32(np, "cm-num-chargers", &num_chgs);
+ if (num_chgs) {
+ /* Allocate empty bin at the tail of array */
+ desc->psy_charger_stat = devm_kzalloc(dev, sizeof(char *)
+ * (num_chgs + 1), GFP_KERNEL);
+ if (desc->psy_charger_stat) {
+ int i;
+ for (i = 0; i < num_chgs; i++)
+ of_property_read_string_index(np, "cm-chargers",
+ i, &desc->psy_charger_stat[i]);
+ } else {
+ return ERR_PTR(-ENOMEM);
+ }
+ }
+
+ of_property_read_string(np, "cm-fuel-gauge", &desc->psy_fuel_gauge);
+ if (of_get_property(np, "cm-battery-has-therm", NULL))
+ desc->measure_battery_temp = true;
+
+ of_property_read_u32(np, "cm-charging-max",
+ &desc->charging_max_duration_ms);
+ of_property_read_u32(np, "cm-discharging-max",
+ &desc->discharging_max_duration_ms);
+
+ /* battery charger regualtors */
+ desc->num_charger_regulators = of_get_child_count(np);
+ if (desc->num_charger_regulators) {
+ struct charger_regulator *chg_regs;
+ struct device_node *child;
+
+ chg_regs = devm_kzalloc(dev, sizeof(*chg_regs)
+ * desc->num_charger_regulators,
+ GFP_KERNEL);
+ if (!chg_regs)
+ return ERR_PTR(-ENOMEM);
+
+ desc->charger_regulators = chg_regs;
+
+ for_each_child_of_node(np, child) {
+ struct charger_cable *cables;
+ struct device_node *_child;
+
+ of_property_read_string(child, "cm-regulator-name",
+ &chg_regs->regulator_name);
+
+ /* charger cables */
+ chg_regs->num_cables = of_get_child_count(child);
+ if (chg_regs->num_cables) {
+ cables = devm_kzalloc(dev, sizeof(*cables)
+ * chg_regs->num_cables,
+ GFP_KERNEL);
+ if (!cables)
+ return ERR_PTR(-ENOMEM);
+
+ chg_regs->cables = cables;
+
+ for_each_child_of_node(child, _child) {
+ of_property_read_string(_child,
+ "cm-cable-name", &cables->name);
+ of_property_read_string(_child,
+ "cm-cable-extcon",
+ &cables->extcon_name);
+ of_property_read_u32(_child,
+ "cm-cable-min",
+ &cables->min_uA);
+ of_property_read_u32(_child,
+ "cm-cable-max",
+ &cables->max_uA);
+ cables++;
+ }
+ }
+ chg_regs++;
+ }
+ }
+ return desc;
+}
+#else
+#define charger_manager_match NULL
#endif
static inline struct charger_desc *cm_get_drv_data(
struct platform_device *pdev)
{
#ifdef CONFIG_OF
- if (pdev->dev.of_node) {
- const struct of_device_id *match;
- match = of_match_node(charger_manager_match,
- pdev->dev.of_node);
- if (!match)
- return NULL;
- return (struct charger_desc *)match->data;
- }
+ if (pdev->dev.of_node)
+ return of_cm_parse_desc(&pdev->dev);
#endif
return (struct charger_desc *)dev_get_platdata(&pdev->dev);
}