From patchwork Fri Jun 21 07:57:29 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: 11008621 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 BFEC3924 for ; Fri, 21 Jun 2019 07:57:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0C81289A0 for ; Fri, 21 Jun 2019 07:57:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4C24289D6; Fri, 21 Jun 2019 07:57:36 +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 15508289A0 for ; Fri, 21 Jun 2019 07:57:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 884716E822; Fri, 21 Jun 2019 07:57:34 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70045.outbound.protection.outlook.com [40.107.7.45]) by gabe.freedesktop.org (Postfix) with ESMTPS id E49F86E822 for ; Fri, 21 Jun 2019 07:57:32 +0000 (UTC) Received: from VI1PR08MB5488.eurprd08.prod.outlook.com (52.133.246.150) by VI1PR08MB3023.eurprd08.prod.outlook.com (52.133.14.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1987.13; Fri, 21 Jun 2019 07:57:29 +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.014; Fri, 21 Jun 2019 07:57:29 +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 system power management support Thread-Topic: [PATCH] drm/komeda: Adds system power management support Thread-Index: AQHVKAb5akOYxhSrCEW6A4cmWHoQRw== Date: Fri, 21 Jun 2019 07:57:29 +0000 Message-ID: <1561103814-864-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: HK0PR01CA0041.apcprd01.prod.exchangelabs.com (2603:1096:203:3e::29) 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: 17f4a2fc-dab9-4cf4-169b-08d6f61e1ba0 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:VI1PR08MB3023; x-ms-traffictypediagnostic: VI1PR08MB3023: x-ms-exchange-purlcount: 3 nodisclaimer: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:568; x-forefront-prvs: 0075CB064E x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(376002)(396003)(366004)(346002)(39860400002)(189003)(199004)(5024004)(72206003)(8676002)(14454004)(66066001)(966005)(68736007)(186003)(50226002)(4326008)(476003)(5660300002)(86362001)(256004)(6486002)(53936002)(66946007)(6506007)(3846002)(6116002)(66476007)(14444005)(2616005)(6636002)(26005)(73956011)(25786009)(66446008)(2201001)(6512007)(6306002)(478600001)(8936002)(386003)(71200400001)(66556008)(99286004)(36756003)(102836004)(6436002)(64756008)(486006)(55236004)(2501003)(54906003)(81166006)(110136005)(316002)(2906002)(81156014)(52116002)(7736002)(305945005)(71190400001); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR08MB3023; H:VI1PR08MB5488.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A: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: 1qd4BYpRivS8Iton37F4nlpOCHn1rIgHqxfC3ZAlPMQdnMyHp7V+hAZa6jov48kkDjc4tcx03V71DGHQXpY4N8E66MDhYYwHz2Adt2HBS4ssYoiO2kWAmleM90X8gQgCXwWKb1g6vkH+Yi7I+X3OVKOtshgZySkHZaEJkhuRmhbixNisbt7LcLTmSBHSFz8BJfm3oGisPjalxQkmTZv341o7lhni601fkwa2SGBQ5+udcxWb1RRYGlDRLIsbLqgL3r6rMmT3j7vVWpPLryh2x98SL7wMbPlRU9MwnMtFdl3Q4Ek31ChFtFUepqXhf8Ol7b36CiL5MlgLfU9IouDSCoC24ipMal/cQKdGHYMJtmqMJ7eUsv+RCMoyGAFOcbdKFPF89hQ0qKflqutE6v/UeC2pCQ8hgHmjFpTUYUziwfk= MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 17f4a2fc-dab9-4cf4-169b-08d6f61e1ba0 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Jun 2019 07:57:29.4733 (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: VI1PR08MB3023 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=E+aIBM9xufH2iYkg6gzm2BgESEOFOgky7tsRsq0rYi8=; b=PvpVgocw6NX4NhT6iIFD9mkt4VFNf3onMpFKIcjSLJHK51KSh8kQTE+8NPQUwv0KlNeUpihl+3nUlVkD9oJt2f7B3q3CGR+fjiybw1Aki36ISD+qYk98QOFXZ1596eaFJOduNKjgHA6xOaafB4bcRBGwyKLqXiZoBOISPwXIHCo= 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 From: "Lowry Li (Arm Technology China)" Adds system power management support in KMS kernel driver. Depends on: - https://patchwork.freedesktop.org/series/61650/ - https://patchwork.freedesktop.org/series/60083/ - https://patchwork.freedesktop.org/series/61647/ Changes since v1: Since we have unified mclk/pclk/pipeline->aclk to one mclk, which will be turned on/off when crtc atomic enable/disable, removed runtime power management. Adds to disable the aclk when register access finished. Changes since v2: Removes run time get/put related flow. Signed-off-by: Lowry Li (Arm Technology China) --- drivers/gpu/drm/arm/display/komeda/komeda_crtc.c | 1 - drivers/gpu/drm/arm/display/komeda/komeda_dev.c | 63 +++++++++++++++++++++--- drivers/gpu/drm/arm/display/komeda/komeda_dev.h | 2 + drivers/gpu/drm/arm/display/komeda/komeda_drv.c | 35 +++++++++++-- 4 files changed, 91 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c index cafb445..d14e7f3 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c @@ -5,7 +5,6 @@ * */ #include -#include #include #include diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_dev.c b/drivers/gpu/drm/arm/display/komeda/komeda_dev.c index e1aa58e..c9837dc 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_dev.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_dev.c @@ -209,7 +209,7 @@ struct komeda_dev *komeda_dev_create(struct device *dev) product->product_id, MALIDP_CORE_ID_PRODUCT_ID(mdev->chip.core_id)); err = -ENODEV; - goto err_cleanup; + goto disable_clk; } DRM_INFO("Found ARM Mali-D%x version r%dp%d\n", @@ -222,19 +222,19 @@ struct komeda_dev *komeda_dev_create(struct device *dev) err = mdev->funcs->enum_resources(mdev); if (err) { DRM_ERROR("enumerate display resource failed.\n"); - goto err_cleanup; + goto disable_clk; } err = komeda_parse_dt(dev, mdev); if (err) { DRM_ERROR("parse device tree failed.\n"); - goto err_cleanup; + goto disable_clk; } err = komeda_assemble_pipelines(mdev); if (err) { DRM_ERROR("assemble display pipelines failed.\n"); - goto err_cleanup; + goto disable_clk; } dev->dma_parms = &mdev->dma_parms; @@ -247,11 +247,13 @@ struct komeda_dev *komeda_dev_create(struct device *dev) if (mdev->iommu && mdev->funcs->connect_iommu) { err = mdev->funcs->connect_iommu(mdev); if (err) { - mdev->iommu = NULL; - goto err_cleanup; + DRM_ERROR("connect iommu failed.\n"); + goto disable_clk; } } + clk_disable_unprepare(mdev->aclk); + err = sysfs_create_group(&dev->kobj, &komeda_sysfs_attr_group); if (err) { DRM_ERROR("create sysfs group failed.\n"); @@ -264,6 +266,8 @@ struct komeda_dev *komeda_dev_create(struct device *dev) return mdev; +disable_clk: + clk_disable_unprepare(mdev->aclk); err_cleanup: komeda_dev_destroy(mdev); return ERR_PTR(err); @@ -281,6 +285,9 @@ void komeda_dev_destroy(struct komeda_dev *mdev) debugfs_remove_recursive(mdev->debugfs_root); #endif + if (mdev->aclk) + clk_prepare_enable(mdev->aclk); + if (mdev->iommu && mdev->funcs->disconnect_iommu) mdev->funcs->disconnect_iommu(mdev); mdev->iommu = NULL; @@ -308,3 +315,47 @@ void komeda_dev_destroy(struct komeda_dev *mdev) devm_kfree(dev, mdev); } + +int komeda_dev_resume(struct komeda_dev *mdev) +{ + int ret = 0; + + clk_prepare_enable(mdev->aclk); + + if (mdev->iommu && mdev->funcs->connect_iommu) { + ret = mdev->funcs->connect_iommu(mdev); + if (ret < 0) { + DRM_ERROR("connect iommu failed.\n"); + goto disable_clk; + } + } + + ret = mdev->funcs->enable_irq(mdev); + +disable_clk: + clk_disable_unprepare(mdev->aclk); + + return ret; +} + +int komeda_dev_suspend(struct komeda_dev *mdev) +{ + int ret = 0; + + clk_prepare_enable(mdev->aclk); + + if (mdev->iommu && mdev->funcs->disconnect_iommu) { + ret = mdev->funcs->disconnect_iommu(mdev); + if (ret < 0) { + DRM_ERROR("disconnect iommu failed.\n"); + goto disable_clk; + } + } + + ret = mdev->funcs->disable_irq(mdev); + +disable_clk: + clk_disable_unprepare(mdev->aclk); + + return ret; +} 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..52b2a94 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_drv.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_drv.c @@ -32,6 +32,7 @@ static void komeda_unbind(struct device *dev) return; komeda_kms_detach(mdrv->kms); + komeda_dev_destroy(mdrv->mdev); dev_set_drvdata(dev, NULL); @@ -52,6 +53,7 @@ static int komeda_bind(struct device *dev) err = PTR_ERR(mdrv->mdev); goto free_mdrv; } + dev_set_drvdata(dev, mdrv); mdrv->kms = komeda_kms_attach(mdrv->mdev); if (IS_ERR(mdrv->kms)) { @@ -59,8 +61,6 @@ static int komeda_bind(struct device *dev) goto destroy_mdev; } - dev_set_drvdata(dev, mdrv); - return 0; destroy_mdev: @@ -134,13 +134,42 @@ static int komeda_platform_remove(struct platform_device *pdev) MODULE_DEVICE_TABLE(of, komeda_of_match); +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) +}; + 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, }, };