Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp9334073imu; Wed, 5 Dec 2018 03:08:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/U4JQRPC7J1s+3GvfurJWnsaZxNhGYq/wbx6PSzGgJD2K6mVJqpfB9qqwvcM0KTv+KqJGqh X-Received: by 2002:a63:dd15:: with SMTP id t21mr19333217pgg.347.1544008109544; Wed, 05 Dec 2018 03:08:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544008109; cv=none; d=google.com; s=arc-20160816; b=Q7V/Uo/hF8EA27Y5Feh8eGZpBpN6HU47rgpn9c+nkj9l3oXPM6EUAKBh27FHDjMBhI dzkU2p+Ak6N3LDEGT7CBs+iMOqSR3MdiKdxJHPEOqNTJ1aKuvRmRj+nBbcdwUW8KxjUN 9HQaspobXT2r1NlNNOUrTt01cv6tDNhTW/fKPJwvex1PXmkYQNeAEUKD7K7SNWw0UCtR kQUfPUu73OI+hHWkBTL/90Ba1uiMrSb/gAcVJ576R6WF8c+/fEI3vbHQc4fiTauu9fm5 Cf4vo/BTCn4gsTy4T1OlI0C04yv166p/uV7208dmRwNQudueYi3gdgDY4khDvF84F0LU NLXA== 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=RttaSuYsdrhZVNquhEdaCMsC9uRDqEtNN9PxfKoRjA4=; b=RYPcXrcqelWx432nZGMVJaQJzScgcjMJqAZVIuYzEokaWOVK37gTUekdGBlTgPgmOv L4IvyMqIdpK/Uzf03qfVJFuQjR8ZmX8o9yaN/AzuVFu3pCwQ8m8uBRUgxfZzVwFYdFha +wByK818MV6GAQdufitPj/8xHQPmZSI5PP7V11RyVXl0RrBH2i3EQ2O8e5XxOCxVhfjN 8QCed45JzeDUvWgogKk4eIY0Yes6e1A9pCm1EkEvHV5rFSUXvS5K+vwG7ThGvy8ievYz InP2SlvkzVvec5HGxjQ30Ors1SmEYi5ma/YE/hno5WyD4b4Kb87VAYi0n6/Mr4C9SRL6 sLiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=oz+LRLzT; 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 28si17410565pgz.593.2018.12.05.03.08.13; Wed, 05 Dec 2018 03:08:29 -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=oz+LRLzT; 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 S1727702AbeLELGx (ORCPT + 99 others); Wed, 5 Dec 2018 06:06:53 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:53284 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727447AbeLELGY (ORCPT ); Wed, 5 Dec 2018 06:06:24 -0500 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20181205110622euoutp0245b6e42ccb434da524eb6111aea8250d~taxR4KFM00210202102euoutp02W for ; Wed, 5 Dec 2018 11:06:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20181205110622euoutp0245b6e42ccb434da524eb6111aea8250d~taxR4KFM00210202102euoutp02W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1544007982; bh=RttaSuYsdrhZVNquhEdaCMsC9uRDqEtNN9PxfKoRjA4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oz+LRLzTFGqcJdBOL9+evNX/REFY0m8eFE6iEb2Lfi88gQEwDcGarM5Yug1iYFxGf STjgZSEmDbkxrFPmiCHUJk9vBmYopI9sSSDtlTWFmB+gmjrt5xD93kzzDzRnkXypnP WsxjMGNGq2415ZA3tXAXK62InvPa5XG1TAg4DIIw= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20181205110621eucas1p154269306679bdae7a4ebd38971834ead~taxQznU7X1455414554eucas1p1K; Wed, 5 Dec 2018 11:06:21 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 54.AB.04806.D21B70C5; Wed, 5 Dec 2018 11:06:21 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20181205110620eucas1p14de70dc092580b684a0304b5ce771605~taxQAL0V11457014570eucas1p1D; Wed, 5 Dec 2018 11:06:20 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20181205110620eusmtrp2a41be8a87e68ac1d977d5f549b9accb2~taxPwb_uB2749027490eusmtrp2i; Wed, 5 Dec 2018 11:06:20 +0000 (GMT) X-AuditID: cbfec7f5-79db79c0000012c6-4c-5c07b12da7d1 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id F3.72.04128.C21B70C5; Wed, 5 Dec 2018 11:06:20 +0000 (GMT) Received: from AMDC3778.DIGITAL.local (unknown [106.120.51.20]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20181205110619eusmtip1bf8b9d1eb7ba11c3e19d535702fb78e0~taxO0knQl2314923149eusmtip1U; Wed, 5 Dec 2018 11:06:19 +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 v3 2/5] devfreq: add support for suspend/resume of a devfreq device Date: Wed, 5 Dec 2018 12:05:53 +0100 Message-Id: <1544007956-28889-3-git-send-email-l.luba@partner.samsung.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544007956-28889-1-git-send-email-l.luba@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0VSfUyMcRz3e95rrj0u4yepdmiylQzbz4ox/njG1mz4A7fp0rOY7so9Snm9 pPQiL9U4b0Uvc65LLic5r72n0/t0JSyrlq4yFGKUezxn/vt8Py/f73fffRlcPkF6Mfs0B3mt RhWtoNyJivofLYGBZloZPHDKF1XdD0BmfRmJHpi/kcg+MUSi/NoWEiUXllHoZaYanesfwVFr 610aNZ8cpdFrnTe6kvsEQ+X9XSTqtF6j0HhWLUD61qcYKq19S6NiezuGepMMFHrbVOfsYesg UcqTWhqllnwi0WjbO2Id5CoeVZCcKc8EuKu6doI7f+4L4AofD2NcuTGd4p5dN9HcvaIT3FQ9 zVV9fIxxllenCe6sxQg4Q8l3mhsv99nisdM9NJKP3hfPa5etDXffay0qArEW3wSzqZfUgfF5 GYBhILsS9jWvyADujJw1AFha1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TkkBEwkTu16ytTF yMUhJLCUUeJR6wt2iISYxKR926FsYYk/17rYIIo+MUr8erKAuYuRg4NNQE9ix6pCkLiIwHJG ifs/Z7ODOMwCD5glOp5vYgXpFhYIljhw9TWYzSKgKjHl+n8mEJtXwEvi3YoHTBAb5CRunutk BrE5Bbwluv+vYwOxhYBqpvYvZ5rAyLeAkWEVo0hqaXFuem6xkV5xYm5xaV66XnJ+7iZGYMRu O/Zzyw7GrnfBhxgFOBiVeHglprDFCLEmlhVX5h5ilOBgVhLhXWHDHiPEm5JYWZValB9fVJqT WnyI0RToqInMUqLJ+cBkklcSb2hqaG5haWhubG5sZqEkznveoDJKSCA9sSQ1OzW1ILUIpo+J g1OqgZHLpfdQmKbpc46Ky1Me3rpsdKJoZeGdwiSelb+u3dix7f7bqhiTd73b7K4IHo3WiHZ9 GDRNXrLq2m9D045ty+4LtBw538vI7rHpgnGJ8WTJJinLpBP9oXuCDmekZ0xIX3WhxslU6mfm P1HWOO6b3EdM1x8+0cj57kSGzKJNDzdeKpHXnZtdmKHEUpyRaKjFXFScCABy7U1o7gIAAA== X-CMS-MailID: 20181205110620eucas1p14de70dc092580b684a0304b5ce771605 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20181205110620eucas1p14de70dc092580b684a0304b5ce771605 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20181205110620eucas1p14de70dc092580b684a0304b5ce771605 References: <1544007956-28889-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 prepares devfreq device for handling suspend/resume functionality. The new fields will store needed information during this process. Devfreq framework handles opp-suspend DT entry and there is no need of modyfications in the drivers code. It uses atomic variables to make sure no race condition affects the process. Suggested-by: Tobias Jakobi Suggested-by: Chanwoo Choi Signed-off-by: Lukasz Luba --- drivers/devfreq/devfreq.c | 47 +++++++++++++++++++++++++++++++++++++++++------ include/linux/devfreq.h | 7 +++++++ 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index a9fd61b..46517b6 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -316,6 +316,10 @@ static int devfreq_set_target(struct devfreq *devfreq, unsigned long new_freq, "Couldn't update frequency transition information.\n"); devfreq->previous_freq = new_freq; + + if (devfreq->suspend_freq) + devfreq->resume_freq = cur_freq; + return err; } @@ -667,6 +671,9 @@ struct devfreq *devfreq_add_device(struct device *dev, } devfreq->max_freq = devfreq->scaling_max_freq; + devfreq->suspend_freq = dev_pm_opp_get_suspend_opp_freq(dev); + atomic_set(&devfreq->suspend_count, 0); + dev_set_name(&devfreq->dev, "devfreq%d", atomic_inc_return(&devfreq_no)); err = device_register(&devfreq->dev); @@ -867,14 +874,28 @@ EXPORT_SYMBOL(devm_devfreq_remove_device); */ int devfreq_suspend_device(struct devfreq *devfreq) { + int ret; + if (!devfreq) return -EINVAL; - if (!devfreq->governor) + if (atomic_inc_return(&devfreq->suspend_count) > 1) return 0; - return devfreq->governor->event_handler(devfreq, - DEVFREQ_GOV_SUSPEND, NULL); + if (devfreq->governor) { + ret = devfreq->governor->event_handler(devfreq, + DEVFREQ_GOV_SUSPEND, NULL); + if (ret) + return ret; + } + + if (devfreq->suspend_freq) { + ret = devfreq_set_target(devfreq, devfreq->suspend_freq, 0); + if (ret) + return ret; + } + + return 0; } EXPORT_SYMBOL(devfreq_suspend_device); @@ -888,14 +909,28 @@ EXPORT_SYMBOL(devfreq_suspend_device); */ int devfreq_resume_device(struct devfreq *devfreq) { + int ret; + if (!devfreq) return -EINVAL; - if (!devfreq->governor) + if (atomic_dec_return(&devfreq->suspend_count) >= 1) return 0; - return devfreq->governor->event_handler(devfreq, - DEVFREQ_GOV_RESUME, NULL); + if (devfreq->resume_freq) { + ret = devfreq_set_target(devfreq, devfreq->resume_freq, 0); + if (ret) + return ret; + } + + if (devfreq->governor) { + ret = devfreq->governor->event_handler(devfreq, + DEVFREQ_GOV_RESUME, NULL); + if (ret) + return ret; + } + + return 0; } EXPORT_SYMBOL(devfreq_resume_device); diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index e4963b0..d985199 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -131,6 +131,9 @@ struct devfreq_dev_profile { * @scaling_min_freq: Limit minimum frequency requested by OPP interface * @scaling_max_freq: Limit maximum frequency requested by OPP interface * @stop_polling: devfreq polling status of a device. + * @suspend_freq: frequency of a device set during suspend phase. + * @resume_freq: frequency of a device set in resume phase. + * @suspend_count: suspend requests counter for a device. * @total_trans: Number of devfreq transitions * @trans_table: Statistics of devfreq transitions * @time_in_state: Statistics of devfreq states @@ -167,6 +170,10 @@ struct devfreq { unsigned long scaling_max_freq; bool stop_polling; + unsigned long suspend_freq; + unsigned long resume_freq; + atomic_t suspend_count; + /* information for device frequency transition */ unsigned int total_trans; unsigned int *trans_table; -- 2.7.4