From patchwork Mon Jun 17 05:55:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lowry Li (Arm Technology China)" X-Patchwork-Id: 10997985 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 754491395 for ; Mon, 17 Jun 2019 05:55:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B59628807 for ; Mon, 17 Jun 2019 05:55:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4947228802; Mon, 17 Jun 2019 05:55:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9C0EE28802 for ; Mon, 17 Jun 2019 05:55:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B7EE789149; Mon, 17 Jun 2019 05:55:54 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40074.outbound.protection.outlook.com [40.107.4.74]) by gabe.freedesktop.org (Postfix) with ESMTPS id A12D789149 for ; Mon, 17 Jun 2019 05:55:52 +0000 (UTC) Received: from VI1PR08MB5488.eurprd08.prod.outlook.com (52.133.246.150) by VI1PR08MB5293.eurprd08.prod.outlook.com (20.178.126.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1987.13; Mon, 17 Jun 2019 05:55:49 +0000 Received: from VI1PR08MB5488.eurprd08.prod.outlook.com ([fe80::e9f4:59c8:9be1:910b]) by VI1PR08MB5488.eurprd08.prod.outlook.com ([fe80::e9f4:59c8:9be1:910b%4]) with mapi id 15.20.1987.013; Mon, 17 Jun 2019 05:55:49 +0000 From: "Lowry Li (Arm Technology China)" To: Liviu Dudau , "james qian wang (Arm Technology China)" , "maarten.lankhorst@linux.intel.com" , "seanpaul@chromium.org" , "airlied@linux.ie" , Brian Starkey Subject: [PATCH] drm/komeda: Adds power management support Thread-Topic: [PATCH] drm/komeda: Adds power management support Thread-Index: AQHVJNFQETmVGDI6/06sk+Bd75NFbQ== Date: Mon, 17 Jun 2019 05:55:49 +0000 Message-ID: <1560750919-32255-1-git-send-email-lowry.li@arm.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [113.29.88.7] x-clientproxiedby: HK2PR06CA0010.apcprd06.prod.outlook.com (2603:1096:202:2e::22) To VI1PR08MB5488.eurprd08.prod.outlook.com (2603:10a6:803:137::22) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 1.9.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 39084433-8e5a-4c2d-46d7-08d6f2e8727b x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:VI1PR08MB5293; x-ms-traffictypediagnostic: VI1PR08MB5293: x-ms-exchange-purlcount: 2 nodisclaimer: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:91; x-forefront-prvs: 0071BFA85B x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(39850400004)(376002)(366004)(396003)(346002)(199004)(189003)(386003)(71200400001)(6506007)(486006)(102836004)(72206003)(36756003)(71190400001)(2501003)(14454004)(7736002)(316002)(305945005)(66066001)(3846002)(6116002)(476003)(73956011)(66446008)(64756008)(66946007)(66476007)(66556008)(25786009)(2616005)(50226002)(8936002)(2906002)(81156014)(81166006)(8676002)(110136005)(5660300002)(54906003)(14444005)(256004)(5024004)(6486002)(6436002)(4326008)(53936002)(6512007)(6306002)(26005)(186003)(52116002)(966005)(99286004)(86362001)(68736007)(6636002)(2201001)(478600001)(55236004); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR08MB5293; H:VI1PR08MB5488.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: wWCoB+9jDCeJVNVIB1p7dtn0sHUpJqJJ6x2AoW1Tsv0ezDU1HJkSffhlO5/ftM5xI+2yskbyHFiOvSWjjD0qZfEW7Ji0Q4Ob0tqsh6rd+CmKYwJv99sx+vpX7EK5h0PrwtryvTUvoxsrHkVTF5dOZYlQ+zdubDJhBK0YXSGBrLKVlnaEpbytDo9NVkmcOsnkt7MqA7ofyBxdh6i3keGcW0pcE84nCpnYCg9baFOcCFIZeqOiEA3Ypz95+zmKRo34EyBvUk3ISbSGp65eSPaALAXdouHdKDim0NbG9Vlq6XhFnatNHe3YkBvyx0peg3Z+ETquElCWwMqOGiwpbxdCVQ1hfi8QE9z0DfEAkHl+uTvDS2U+Dn5kBCBl8Si6VYEhs8kSSitUfDS/rgciV8mQiuO48UlypLfoOgu9acc0Se4= MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 39084433-8e5a-4c2d-46d7-08d6f2e8727b X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jun 2019 05:55:49.1023 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Lowry.Li@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB5293 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F0RuAXkwis8QJsOmnZcWpFM9eX2qUcTjMLxPgdRoyjQ=; b=in6l+JbAvWqQuDC0UhJrtrtRUsWVMOTGdckSmGRlD0GDL7iha5oWEPu+hdBjvRYrlT3dN34b6AeRZl9dAHBkny6caz7oa7dURnZ7hge+AI/jlCF4+x8Q2jtI82DBv8SPqwqEO8slfJyMipnq491r977c0iDM70FtJsXGDhMx9+I= X-Mailman-Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Lowry.Li@arm.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , "Jonathan Chai \(Arm Technology China\)" , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "Julien Yin \(Arm Technology China\)" , nd Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Adds runtime and system power management support in KMS kernel driver. Depends on: - https://patchwork.freedesktop.org/series/61650/ - https://patchwork.freedesktop.org/series/60083/ Signed-off-by: Lowry Li (Arm Technology China) --- drivers/gpu/drm/arm/display/komeda/komeda_crtc.c | 2 + drivers/gpu/drm/arm/display/komeda/komeda_dev.c | 30 +++++++++++++ drivers/gpu/drm/arm/display/komeda/komeda_dev.h | 2 + drivers/gpu/drm/arm/display/komeda/komeda_drv.c | 54 ++++++++++++++++++++++-- 4 files changed, 85 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c index 66c5e0d..1b4ea8a 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c @@ -257,6 +257,7 @@ void komeda_crtc_handle_event(struct komeda_crtc *kcrtc, komeda_crtc_atomic_enable(struct drm_crtc *crtc, struct drm_crtc_state *old) { + pm_runtime_get_sync(crtc->dev->dev); komeda_crtc_prepare(to_kcrtc(crtc)); drm_crtc_vblank_on(crtc); komeda_crtc_do_flush(crtc, old); @@ -330,6 +331,7 @@ void komeda_crtc_handle_event(struct komeda_crtc *kcrtc, drm_crtc_vblank_off(crtc); komeda_crtc_unprepare(kcrtc); + pm_runtime_put(crtc->dev->dev); } static void diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_dev.c b/drivers/gpu/drm/arm/display/komeda/komeda_dev.c index 405c64d..edd0943 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_dev.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_dev.c @@ -308,3 +308,33 @@ void komeda_dev_destroy(struct komeda_dev *mdev) devm_kfree(dev, mdev); } + +int komeda_dev_resume(struct komeda_dev *mdev) +{ + int ret = 0; + + if (mdev->iommu && mdev->funcs->connect_iommu) { + ret = mdev->funcs->connect_iommu(mdev); + if (ret < 0) { + DRM_ERROR("connect iommu failed.\n"); + return ret; + } + } + + return mdev->funcs->enable_irq(mdev); +} + +int komeda_dev_suspend(struct komeda_dev *mdev) +{ + int ret = 0; + + if (mdev->iommu && mdev->funcs->disconnect_iommu) { + ret = mdev->funcs->disconnect_iommu(mdev); + if (ret < 0) { + DRM_ERROR("disconnect iommu failed.\n"); + return ret; + } + } + + return mdev->funcs->disable_irq(mdev); +} diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_dev.h b/drivers/gpu/drm/arm/display/komeda/komeda_dev.h index d1c86b6..096f9f7 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_dev.h +++ b/drivers/gpu/drm/arm/display/komeda/komeda_dev.h @@ -207,4 +207,6 @@ struct komeda_dev { struct komeda_dev *dev_to_mdev(struct device *dev); +int komeda_dev_resume(struct komeda_dev *mdev); +int komeda_dev_suspend(struct komeda_dev *mdev); #endif /*_KOMEDA_DEV_H_*/ diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_drv.c b/drivers/gpu/drm/arm/display/komeda/komeda_drv.c index cfa5068..aa4cef1 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_drv.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_drv.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "komeda_dev.h" #include "komeda_kms.h" @@ -32,6 +33,9 @@ static void komeda_unbind(struct device *dev) return; komeda_kms_detach(mdrv->kms); + + pm_runtime_disable(dev); + komeda_dev_destroy(mdrv->mdev); dev_set_drvdata(dev, NULL); @@ -52,6 +56,9 @@ static int komeda_bind(struct device *dev) err = PTR_ERR(mdrv->mdev); goto free_mdrv; } + dev_set_drvdata(dev, mdrv); + + pm_runtime_enable(dev); mdrv->kms = komeda_kms_attach(mdrv->mdev); if (IS_ERR(mdrv->kms)) { @@ -59,11 +66,10 @@ static int komeda_bind(struct device *dev) goto destroy_mdev; } - dev_set_drvdata(dev, mdrv); - return 0; destroy_mdev: + pm_runtime_disable(dev); komeda_dev_destroy(mdrv->mdev); free_mdrv: @@ -134,13 +140,55 @@ static int komeda_platform_remove(struct platform_device *pdev) MODULE_DEVICE_TABLE(of, komeda_of_match); +static int komeda_rt_pm_suspend(struct device *dev) +{ + dev_info(dev, "%s\n", __func__); + return 0; +} + +static int komeda_rt_pm_resume(struct device *dev) +{ + dev_info(dev, "%s\n", __func__); + return 0; +} + +static int __maybe_unused komeda_pm_suspend(struct device *dev) +{ + struct komeda_drv *mdrv = dev_get_drvdata(dev); + struct drm_device *drm = &mdrv->kms->base; + int res; + + dev_info(dev, "%s\n", __func__); + res = drm_mode_config_helper_suspend(drm); + + komeda_dev_suspend(mdrv->mdev); + + return res; +} + +static int __maybe_unused komeda_pm_resume(struct device *dev) +{ + struct komeda_drv *mdrv = dev_get_drvdata(dev); + struct drm_device *drm = &mdrv->kms->base; + + dev_info(dev, "%s\n", __func__); + komeda_dev_resume(mdrv->mdev); + + return drm_mode_config_helper_resume(drm); +} + +static const struct dev_pm_ops komeda_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(komeda_pm_suspend, komeda_pm_resume) + SET_RUNTIME_PM_OPS(komeda_rt_pm_suspend, komeda_rt_pm_resume, NULL) +}; + static struct platform_driver komeda_platform_driver = { .probe = komeda_platform_probe, .remove = komeda_platform_remove, .driver = { .name = "komeda", .of_match_table = komeda_of_match, - .pm = NULL, + .pm = &komeda_pm_ops, }, };