static void xhci_dbc_set_state(struct xhci_dbc *dbc, enum dbc_state new_state)
{
+ if (dbc->state == new_state)
+ return;
+
+ switch (new_state) {
+ case DS_ENABLED:
+ /*
+ * DbC pm usage is 1 here, both when moved from disconnect or
+ * configured states, or when setting initial DbC enable state.
+ * Just enable pending put
+ */
+ dev_dbg(dbc->dev, "DbC set pending_rpm_put = 1\n");
+ dbc->pending_rpm_put = 1;
+ break;
+ case DS_CONNECTED:
+ if (dbc->pending_rpm_put)
+ /* DbC pm usage still 1, just remove pending put */
+ dbc->pending_rpm_put = 0;
+ else
+ /* DbC pm usage was put to 0, call get */
+ pm_runtime_get(dbc->dev);
+ break;
+ default:
+ break;
+ }
+
dbc->state_timestamp = jiffies;
dbc->state = new_state;
}
WARN_ON(!dbc);
- pm_runtime_get_sync(dbc->dev); /* note this was self.controller */
+ pm_runtime_get(dbc->dev);
spin_lock_irqsave(&dbc->lock, flags);
ret = xhci_do_dbc_start(dbc);
static void xhci_dbc_stop(struct xhci_dbc *dbc)
{
unsigned long flags;
+ bool need_rpm_put = false;
WARN_ON(!dbc);
spin_lock_irqsave(&dbc->lock, flags);
writel(0, &dbc->regs->control);
+
+ if (dbc->state == DS_CONNECTED || dbc->state == DS_CONFIGURED ||
+ dbc->pending_rpm_put)
+ need_rpm_put = true;
+
+ dbc->pending_rpm_put = 0;
+
xhci_dbc_set_state(dbc, DS_DISABLED);
spin_unlock_irqrestore(&dbc->lock, flags);
xhci_dbc_mem_cleanup(dbc);
- pm_runtime_put(dbc->dev); /* note, was self.controller */
+ if (need_rpm_put)
+ pm_runtime_put(dbc->dev);
}
static void
dev_info(dbc->dev, "DbC connected\n");
} else if (!(ctrl & DBC_CTRL_DBC_ENABLE)) {
dev_err(dbc->dev, "unexpected DbC disable, xHC reset?\n");
+ } else if (dbc->pending_rpm_put &&
+ time_is_before_jiffies(dbc->state_timestamp +
+ msecs_to_jiffies(DBC_AUTOSUSPEND_DELAY))) {
+ dbc->pending_rpm_put = 0;
+ dev_dbg(dbc->dev, "DbC Enabled state for 15 seconds, allow rpm suspend\n");
+ pm_runtime_put(dbc->dev);
}
return EVT_DONE;
if (dbc->state >= ARRAY_SIZE(dbc_state_strings))
return sysfs_emit(buf, "unknown\n");
+ if (dbc->resume_required)
+ return sysfs_emit(buf, "suspended\n");
+
return sysfs_emit(buf, "%s\n", dbc_state_strings[dbc->state]);
}
dbc = xhci->dbc;
if (sysfs_streq(buf, "enable")) {
+ pm_runtime_get_sync(dbc->dev);
+
mutex_lock(&dbc->enable_mutex);
+ /*
+ * DbC may already be enabled here if xhci was suspended with
+ * dbc->resume_required set, and resumed by pm_runtime_get_sync()
+ * above. In this case we end up calling xhci_dbc_start() twice,
+ * second time returns an error but is harmless
+ */
xhci_dbc_start(dbc);
+
mutex_unlock(&dbc->enable_mutex);
+ pm_runtime_put(dbc->dev);
} else if (sysfs_streq(buf, "disable")) {
mutex_lock(&dbc->enable_mutex);
+
+ dbc->resume_required = 0;
xhci_dbc_stop(dbc);
+
mutex_unlock(&dbc->enable_mutex);
} else {
return -EINVAL;