From patchwork Fri Sep 13 09:41:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 173744 Delivered-To: patches@linaro.org Received: by 2002:ac9:19ad:0:0:0:0:0 with SMTP id d45csp464705oce; Fri, 13 Sep 2019 02:41:13 -0700 (PDT) X-Received: by 2002:a2e:9081:: with SMTP id l1mr10353905ljg.33.1568367672916; Fri, 13 Sep 2019 02:41:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568367672; cv=none; d=google.com; s=arc-20160816; b=JnDoG6loA+Tyin6BbHrqjQyCTxZT3/imEIFohxQYQ9JtsWO4efKC+GrpFRkVTPzvrf 8zl+oKID+stV67IvRQTgpND7vQbBQd/AA0wzUHMTZWxJGhCzIS+RgTMlkUquVfniP4XG Flz7XB+n6/BIJYWXYGE9CRriF+ltXMlTwOxJmN0rY4XY5yCoVKPLYBd1q1ntBuEv/0ct gzkpq+Anbu1Kzwc11Nmg0jpIesxMSvMhtLWOOu6FnkRqCVPyiOWwoIrUo4N5TjoRqIdG GGvEl+jr+nFqcsiG6Wk2kZFNkT1HEzUeIxliCcMCcwOHW7k3kjrV39VBRzCgjevc1FTE u3OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=x+Ss15MNzRVyX67MkdlgMEH//XbsQfFeOYqwwe3OaKg=; b=lSO4lQqcJILsUwhtZBySbMpj+wbOAOKtDglq9TBAiuFCtC4SFsjhcgvMevcCr6/AXa Bl/dAqLQAnWQHfZ/HspCMbG9Hl7G+/N0ccOUkYGYZYcUXaKEyhXu3KKNz8OKJTvQPG0w WSuCr/qmtybXoMq3AZoC47JaR4dOeHqsWtH1c7oTB/3T9p323O+F0wKfSZ3+vKzXdPJw cvUwgDMLyYH0omooXxRbapGws6FrrzBdPNTesWcIDIpWud6ZnBptNU9FWVfIdoN4hbGq AJpjNQBWSXR0GydlWvD21B+B8e+0483fCTGKo8c7qq08N+thYxal+sau0ZoQb0bJxOFx oKyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="p/zm/sxh"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id g20sor13565016ljk.20.2019.09.13.02.41.12 for (Google Transport Security); Fri, 13 Sep 2019 02:41:12 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="p/zm/sxh"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=x+Ss15MNzRVyX67MkdlgMEH//XbsQfFeOYqwwe3OaKg=; b=p/zm/sxhH+yLyUYDxLlnKOtmXMLDat12pljG16ezcFFV2KVT9H7TvPLYzzcEKGU2iB Z+dzvPI+7dE3RFBNzp/y7eGYsldxMGXYmuG7IYacFQKsCM1ylejcxJGHxx2OTzbFfnkT BqdQwuGj5/CbTerzQCU6qZvWQBILgMVtCpoDN5XSDon6/bxtY6T7VRbAB7JtI/0NrYI6 Vn9J6utyHjJKTYBt7OlZ0x9CPXDc2P7gu27ihhbaJMBJ1/ZbbFN1neura7JTS7w8z6YL xggY00OLA/9jd0FpdjdpHR0JQJKZMFvVHzv3V7+rfkBuzAfIqSHeHFnQvC5xN7izRC4g jBpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=x+Ss15MNzRVyX67MkdlgMEH//XbsQfFeOYqwwe3OaKg=; b=mfoALrKkhCZ97k64ejgQJHMWM/QRCX0eep+jw7UFxu6X5qu0ue+2E5LmcupyxJo/g+ tY9RV1nubBE0N94PTDF4VunHjB6/AvyGLQyReB7lFlD77MfjxZQT+KBS4R+zcWnbzydD bqlk2NPH8wgd9z5x5vn01tY7Iy6NtYeFcdPPwpElmt7wbRRrxeshxhngEilLKs6P/Ch1 O+j10KkOL1QhxAUQQ9kLXOtqBUJBFHSryLlU0QOvpOYSYVkreJyFQGqMdf6VqlBXwlIz MCpAlYKBQ3zYD3mZ1NzKUhysjm1H8cAa9jkVxoXLC87JdI7YO9FosUSTrqrJemyNilyv KulA== X-Gm-Message-State: APjAAAU8PIkr9CMIiUmUD5cwdNeVuhqpmTXYYB/NP5JBX2AnKxYyKm5I lKMib/7nScBnc3Fd+RABduFzpzLt X-Google-Smtp-Source: APXvYqzJYGbaNDMizQgqIGnU19xD8dzBy4o+0P+OIYwEEFFswZEvh81y8WZHPl493WfWx8/7DXCddw== X-Received: by 2002:a2e:8e8c:: with SMTP id z12mr28888323ljk.204.1568367672562; Fri, 13 Sep 2019 02:41:12 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id t29sm116607lfb.85.2019.09.13.02.41.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2019 02:41:11 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Masahiro Yamada , Wolfram Sang Cc: Ulrich Hecht , Simon Horman , Niklas Soderlund , Geert Uytterhoeven , stable@vger.kernel.org Subject: [PATCH 2/3] mmc: tmio: Fixup runtime PM management during probe Date: Fri, 13 Sep 2019 11:41:09 +0200 Message-Id: <20190913094109.21192-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 The tmio_mmc_host_probe() calls pm_runtime_set_active() to update the runtime PM status of the device, as to make it reflect the current status of the HW. This works fine for most cases, but unfortunate not for all. Especially, there is a generic problem when the device has a genpd attached and that genpd have the ->start|stop() callbacks assigned. More precisely, if the driver calls pm_runtime_set_active() during ->probe(), genpd does not get to invoke the ->start() callback for it, which means the HW isn't really fully powered on. Furthermore, in the next phase, when the device becomes runtime suspended, genpd will invoke the ->stop() callback for it, potentially leading to usage count imbalance problems, depending on what's implemented behind the callbacks of course. To fix this problem, convert to call pm_runtime_get_sync() from tmio_mmc_host_probe() rather than pm_runtime_set_active(). Additionally, to avoid bumping usage counters and unnecessary re-initializing the HW the first time the tmio driver's ->runtime_resume() callback is called, introduce a state flag to keeping track of this. Cc: stable@vger.kernel.org Signed-off-by: Ulf Hansson --- drivers/mmc/host/tmio_mmc.h | 1 + drivers/mmc/host/tmio_mmc_core.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/mmc/host/tmio_mmc.h b/drivers/mmc/host/tmio_mmc.h index c5ba13fae399..2f0b092d6dcc 100644 --- a/drivers/mmc/host/tmio_mmc.h +++ b/drivers/mmc/host/tmio_mmc.h @@ -163,6 +163,7 @@ struct tmio_mmc_host { unsigned long last_req_ts; struct mutex ios_lock; /* protect set_ios() context */ bool native_hotplug; + bool runtime_synced; bool sdio_irq_enabled; /* Mandatory callback */ diff --git a/drivers/mmc/host/tmio_mmc_core.c b/drivers/mmc/host/tmio_mmc_core.c index 8b299c1f0069..32f9679ec42e 100644 --- a/drivers/mmc/host/tmio_mmc_core.c +++ b/drivers/mmc/host/tmio_mmc_core.c @@ -1248,20 +1248,22 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host) /* See if we also get DMA */ tmio_mmc_request_dma(_host, pdata); - pm_runtime_set_active(&pdev->dev); pm_runtime_set_autosuspend_delay(&pdev->dev, 50); pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_enable(&pdev->dev); + pm_runtime_get_sync(&pdev->dev); ret = mmc_add_host(mmc); if (ret) goto remove_host; dev_pm_qos_expose_latency_limit(&pdev->dev, 100); + pm_runtime_put(&pdev->dev); return 0; remove_host: + pm_runtime_put_noidle(&pdev->dev); tmio_mmc_host_remove(_host); return ret; } @@ -1330,6 +1332,11 @@ int tmio_mmc_host_runtime_resume(struct device *dev) { struct tmio_mmc_host *host = dev_get_drvdata(dev); + if (!host->runtime_synced) { + host->runtime_synced = true; + return 0; + } + tmio_mmc_clk_enable(host); tmio_mmc_hw_reset(host->mmc);