Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2413534imu; Wed, 21 Nov 2018 11:13:53 -0800 (PST) X-Google-Smtp-Source: AFSGD/WdFhPYKB63HyqnSNFl+gXiQctyKZ4AClG5l+XpZzOUAAd5Y8EsVjImZHm/0hmYT3kptS1n X-Received: by 2002:a63:dc0c:: with SMTP id s12mr7185154pgg.398.1542827633206; Wed, 21 Nov 2018 11:13:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542827633; cv=none; d=google.com; s=arc-20160816; b=kra+JBNb34RggrK54I2acS0rJkKXsD4s6Rog+LUQOfVpbjxZIzMTF3de4KziQ1epUQ 7ep0dc1+zOnRAuxsEl0Kkl9JqjFgCVfzVczH3+oZzsEkomcHtPWz4Vqc1/7KKIQdEKvg nESQjJvWkLdaVpYJUxvHWIH2bZmjQo8jToKJwKScmMNZM0u0XOVGzXgXNWax7CrS8Gmw HS0utk/50FSqOQzp95avSeV+RsAh2Y5es0GkWsVaqvZXUsdjIsCzRm7EOgIjaRUj0u9q 4q4U7jhW8mpQexDTOAaw/yW3Dimm3MGEr0MM9zU7DP7e6UqfpBYpwhlKHbG2d+/2n3J3 H7jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=TC4iv9GmwSHsehFTeXbZMrcoHrnEKqBkOFvwBCjFgEg=; b=h0RxN5403tCRaWF2Dg6Jx3AFp5bhX31UkFptoFcM4W5LAxnwCaJqwafOiNfi7j4O+i 7iBkJzkS77/wBHeKncFBQ03G7/FmiJiBh83QTLVb8/pJgmzULyVTfybSuwd4Ym7wd93T LUNqJbQokS5ia8TtnxlJ1JXhK163ZDp0cI7LVeAprU90uBZwGOs1kYN92dhrJMSHCOKK NxO75795T4M+cwVLGcz24yT+dvIgvC17bhUiPAD0yBZbQrcrLMfrmTX8gZeDXMNrov1W ANn6774AzPhICXmbf2Tr9RyYVtsQx2PEFasD6dbAKbzR18dkT2tyulV0QmjR/mPezkNC V0Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="QxeWXAT/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 102si22546936plc.277.2018.11.21.11.13.38; Wed, 21 Nov 2018 11:13:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="QxeWXAT/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732967AbeKVEiJ (ORCPT + 99 others); Wed, 21 Nov 2018 23:38:09 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:38095 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732870AbeKVEh3 (ORCPT ); Wed, 21 Nov 2018 23:37:29 -0500 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20181121180206euoutp01b8e9212e75d0e019a80e80ed96f9304e~pNaQPM4IJ1022810228euoutp01B for ; Wed, 21 Nov 2018 18:02:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20181121180206euoutp01b8e9212e75d0e019a80e80ed96f9304e~pNaQPM4IJ1022810228euoutp01B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1542823326; bh=TC4iv9GmwSHsehFTeXbZMrcoHrnEKqBkOFvwBCjFgEg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QxeWXAT/PVQVYFbL6LC9XU8+LWZPTzgKGBoL530dShlA27jh2FsUsAQC9T/aOXmQW 67PxatvFYT+ixNndCcUqn+gTuyIZImIgaLbHw5AfX8JzxmQRPrfzWP94//5tAmRQHA rt8/yb0FFtPmaDGYwRPWvoxiww+J7p+LUT7cKgL0= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20181121180204eucas1p29f01fa667282f71e870be3b662344d1c~pNaPEsQ9i1318113181eucas1p2P; Wed, 21 Nov 2018 18:02:04 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id A9.B3.04806.C9D95FB5; Wed, 21 Nov 2018 18:02:04 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20181121180204eucas1p1c5891d498aa59c0e10dd3ba4727a4382~pNaOXcXWN3115831158eucas1p1T; Wed, 21 Nov 2018 18:02:04 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20181121180203eusmtrp205083d871e555b0038b775a845c138bb~pNaOH68rp0880408804eusmtrp26; Wed, 21 Nov 2018 18:02:03 +0000 (GMT) X-AuditID: cbfec7f5-367ff700000012c6-d6-5bf59d9c12be Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 4C.48.04284.B9D95FB5; Wed, 21 Nov 2018 18:02:03 +0000 (GMT) Received: from AMDC3778.DIGITAL.local (unknown [106.120.51.20]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20181121180202eusmtip2ee65eeaddffccee4e927d3dfba791f47~pNaNPk8pt1293112931eusmtip2W; Wed, 21 Nov 2018 18:02:02 +0000 (GMT) From: Lukasz Luba To: linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org Cc: tjakobi@math.uni-bielefeld.de, myungjoo.ham@samsung.com, kyungmin.park@samsung.com, cw00.choi@samsung.com, rjw@rjwysocki.net, len.brown@intel.com, pavel@ucw.cz, gregkh@linuxfoundation.org, keescook@chromium.org, anton@enomsg.org, ccross@android.com, tony.luck@intel.com, robh+dt@kernel.org, mark.rutland@arm.com, kgene@kernel.org, krzk@kernel.org, m.szyprowski@samsung.com, b.zolnierkie@samsung.com, Lukasz Luba Subject: [PATCH 3/6] devfreq: add support for suspend/resume of a devfreq device Date: Wed, 21 Nov 2018 19:01:38 +0100 Message-Id: <1542823301-23563-4-git-send-email-l.luba@partner.samsung.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1542823301-23563-1-git-send-email-l.luba@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0VSaWwMYRj2zezsTJdtxqJ91Zl1RCWKKL4gjiAdRFLXn/YHQ0eJ7padFkVi XN1uL02DNvQgPTNd2q5atbSitq2rt7tRokEUdaxWJE3ZMYt/z/u8z/O87/fmY0hDPxXE7DTH CRYzH2PU6jTOhp8tM3Jy+yJnDSROwreuBOPK7HIKX63sp/CT7+8onO9upvCxgnItfpBiwie7 P5C4paWCxk1HP9L4uTQWnz1VQ2BH92MKd7hytNiT5kY4u6WWwBfdL2hc9KSNwJ1HSrX4xb16 b8b9dgqfqHHTOLHsC4U/tnZplgLnvO6kOHueHXHnpDYNl3HyG+IKbrwnOIds03I3c+00d7nw MDfYQHO3em8QXNUjq4ZLr5IRV1r2g+Y8jvHh/hG6RVFCzM69gmXm4i26He+LU6ndrw37Hacv Iwl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WmqZsZGxjv8XUxcnJICJhING/oZOti 5OIQEljKKPF17ydmiISYxKR929khbGGJP9e6oIo+MUp8nvwTKMHBwSagJ7FjVSFIXERgOaPE /Z+z2UEcZoEHzBIdzzexgnQLCwRIvJ3ZBWazCKhKNKx5yghi8wp4Sazq6WOC2CAncfNcJ9hm TgFvic+rJoDVCAHVXJm3kHUCI98CRoZVjCKppcW56bnFhnrFibnFpXnpesn5uZsYgRG77djP zTsYL20MPsQowMGoxMOrEfk1Wog1say4MvcQowQHs5IIb0cUUIg3JbGyKrUoP76oNCe1+BCj KdBRE5mlRJPzgckkryTe0NTQ3MLS0NzY3NjMQkmc97xBZZSQQHpiSWp2ampBahFMHxMHp1QD 46z0npwZl9uePOU1eWHlpNnJ1firrIOraca5U99mBFevr/E7YHyGwXtOtkn3hZ3fVP2088oY Y7Z+v7WRrTg3Wu2FsdTLiect9M9fEZMXcaxTqBe1kd874f/CU5nLvys+dd+Zek7894xKBdU1 M600Vr3eYCMn99n+HNtXHScXe/PfW1f/+j/PSomlOCPRUIu5qDgRAEGu3tTuAgAA X-CMS-MailID: 20181121180204eucas1p1c5891d498aa59c0e10dd3ba4727a4382 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20181121180204eucas1p1c5891d498aa59c0e10dd3ba4727a4382 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20181121180204eucas1p1c5891d498aa59c0e10dd3ba4727a4382 References: <1542823301-23563-1-git-send-email-l.luba@partner.samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The patch adds support for handling suspend/resume process. It uses atomic variables to make sure no race condition affects the process. The patch draws on Tobias Jakobi's work posted ~2 years ago, who tried to solve issue with devfreq device's frequency during suspend/resume. During the discussion on LKML some corner cases and comments appeared related to the design. This patch address them keeping in mind suggestions from Chanwoo Choi. Suggested-by: Tobias Jakobi Suggested-by: Chanwoo Choi Signed-off-by: Lukasz Luba --- drivers/devfreq/devfreq.c | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index cf9c643..7e09de8 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -872,14 +872,33 @@ EXPORT_SYMBOL(devm_devfreq_remove_device); */ int devfreq_suspend_device(struct devfreq *devfreq) { - if (!devfreq) - return -EINVAL; + int ret; + unsigned long prev_freq; + u32 flags = 0; + + if (!devfreq) + return -EINVAL; + + if (devfreq->governor) { + ret = devfreq->governor->event_handler(devfreq, + DEVFREQ_GOV_SUSPEND, NULL); + if (ret) + return ret; + } - if (!devfreq->governor) - return 0; + if (devfreq->suspend_freq) { + if (atomic_inc_return(&devfreq->suspend_count) > 1) + return 0; - return devfreq->governor->event_handler(devfreq, - DEVFREQ_GOV_SUSPEND, NULL); + ret = devfreq_set_target(devfreq, devfreq->suspend_freq, + &prev_freq, flags); + if (ret) + return ret; + + devfreq->resume_freq = prev_freq; + } + + return 0; } EXPORT_SYMBOL(devfreq_suspend_device); @@ -893,9 +912,23 @@ EXPORT_SYMBOL(devfreq_suspend_device); */ int devfreq_resume_device(struct devfreq *devfreq) { + int ret; + unsigned long prev_freq; + u32 flags = 0; + if (!devfreq) return -EINVAL; + if (devfreq->suspend_freq) { + if (atomic_dec_return(&devfreq->suspend_count) >= 1) + return 0; + + ret = devfreq_set_target(devfreq, devfreq->resume_freq, + &prev_freq, flags); + if (ret) + return ret; + } + if (!devfreq->governor) return 0; -- 2.7.4