From patchwork Tue May 17 03:16:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 67922 Delivered-To: patches@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1850562qge; Mon, 16 May 2016 20:16:26 -0700 (PDT) X-Received: by 10.66.25.236 with SMTP id f12mr16208551pag.35.1463454986759; Mon, 16 May 2016 20:16:26 -0700 (PDT) Return-Path: Received: from mail-pf0-x231.google.com (mail-pf0-x231.google.com. [2607:f8b0:400e:c00::231]) by mx.google.com with ESMTPS id f6si1170601pfb.141.2016.05.16.20.16.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 May 2016 20:16:26 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::231 as permitted sender) client-ip=2607:f8b0:400e:c00::231; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::231 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-pf0-x231.google.com with SMTP id c189so1718714pfb.3 for ; Mon, 16 May 2016 20:16:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=NNb2J/zYFTgIjIkFk0pIcSKmzgJy7oyNZEqX855lIaU=; b=TQm3M671vK+f5Mltp0SGP4UaFipqXP0aJeomuZ6075O7CngoXm6NGAKvKsLQyr8mF0 oVTBcLEP7ORMM0ZNrDC6jlPyg2TCMR0n65TkB9bihPOAo+eL3NBGdIPQ3zx3PPNA1YDd /BUeedLn/XA8eoXYyildFucnJftb/mzEfNwgI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=NNb2J/zYFTgIjIkFk0pIcSKmzgJy7oyNZEqX855lIaU=; b=aVgCt5/S0VQl3xcvdAE76X3UoveCCVx5gaNuXKFzG0lnSJ+7htOUtbJuYL/nu4+82N vDEjrMhlzy6iCcuwoqY9XgTEx99W6CGGFrN+qU3dP2+3MQGqACfqjt6y6BkU9s426FNZ PEJX5sRjWSwxNCVDZmctZFeklt2XpQs895c5qLYbOU0jX7b4e9SIUG8LHjfP2W0tG8zT NGKhIKaKEWDCpF5hoesH0w7+MvqoUsSDZ+OTMFslBGjYjqnl5mYah/lGmqhhz2kWKRIR VJP3E4VXRpc0VC15ON7rmcMYC66eaYwN24TOGodKtD9daT3Nt/2mPPHbBB3VEv8Twvin mlMQ== X-Gm-Message-State: AOPr4FUc2qxqOdWnTSoWNxvwXoSz3B7p6arQsteq2MNQSog72xdhRkaQaw3TzigBWNEt7rp2ZRY= X-Received: by 10.98.42.196 with SMTP id q187mr50886687pfq.140.1463454986434; Mon, 16 May 2016 20:16:26 -0700 (PDT) Return-Path: Received: from localhost.localdomain (c-73-67-244-238.hsd1.or.comcast.net. [73.67.244.238]) by smtp.gmail.com with ESMTPSA id v126sm483533pfv.92.2016.05.16.20.16.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 May 2016 20:16:25 -0700 (PDT) From: John Stultz To: Guodong Xu , Xinliang Liu Cc: John Stultz Subject: [PATCH] ADd suspend hooks to hisi_drm_drv.c Date: Mon, 16 May 2016 20:16:21 -0700 Message-Id: <1463454981-4287-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 This is really hacked up and is mostly stolen from the exynos drm and another driver as well. I also added a sysfs test interface that allows you to trigger it on and off w/o the suspend logic. That will have to be removed before this gets merged. Signed-off-by: John Stultz --- drivers/gpu/drm/hisilicon/hisi_drm_drv.c | 118 +++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) -- 1.9.1 diff --git a/drivers/gpu/drm/hisilicon/hisi_drm_drv.c b/drivers/gpu/drm/hisilicon/hisi_drm_drv.c index 76eb711..508643e 100644 --- a/drivers/gpu/drm/hisilicon/hisi_drm_drv.c +++ b/drivers/gpu/drm/hisilicon/hisi_drm_drv.c @@ -227,12 +227,124 @@ static const struct component_master_ops hisi_drm_ops = { .unbind = hisi_drm_unbind, }; +static int exynos_drm_suspend(struct drm_device *dev) +{ + struct drm_connector *connector; + + drm_modeset_lock_all(dev); + list_for_each_entry(connector, &dev->mode_config.connector_list, head) { + int old_dpms = connector->dpms; + + if (connector->funcs->dpms) + connector->funcs->dpms(connector, DRM_MODE_DPMS_OFF); + + /* Set the old mode back to the connector for resume */ + connector->dpms = old_dpms; + } + drm_modeset_unlock_all(dev); + + return 0; +} + +static int exynos_drm_resume(struct drm_device *dev) +{ + struct drm_connector *connector; + + /* reset all the states of crtc/plane/encoder/connector */ + drm_mode_config_reset(dev); + + /* init kms poll for handling hpd */ + drm_kms_helper_poll_init(dev); + + /* force detection after connectors init */ + (void)drm_helper_hpd_irq_event(dev); + + + drm_modeset_lock_all(dev); + list_for_each_entry(connector, &dev->mode_config.connector_list, head) { + if (connector->funcs->dpms) { + int dpms = connector->dpms; + + connector->dpms = DRM_MODE_DPMS_OFF; + connector->funcs->dpms(connector, dpms); + } + } + drm_modeset_unlock_all(dev); + + return 0; +} + +static int host1x_drm_suspend(struct device *dev) +{ + struct drm_device *drm = dev_get_drvdata(dev); + + drm_kms_helper_poll_disable(drm); + + exynos_drm_suspend(drm); + + return 0; +} + +static int host1x_drm_resume(struct device *dev) +{ + struct drm_device *drm = dev_get_drvdata(dev); + + exynos_drm_resume(drm); + + drm_kms_helper_poll_enable(drm); + + return 0; +} + +static SIMPLE_DEV_PM_OPS(host1x_drm_pm_ops, host1x_drm_suspend, + host1x_drm_resume); + +static ssize_t +sysfs_show_current_drmstate(struct device *dev, + struct device_attribute *attr, char *buf) +{ + ssize_t count = 0; + + count = snprintf(buf, PAGE_SIZE, "%s\n", "johntest"); + + return count; +} +static ssize_t sysfs_set_drmstate(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + ssize_t ret = count; + + if (count < 1) + return count; + + /* strip of \n: */ + if (buf[count-1] == '\n') + count--; + + if (!strncmp(buf, "off", count)) { + host1x_drm_suspend(dev); + } else if (!strncmp(buf, "on", count)) { + host1x_drm_resume(dev); + } else { + printk("JDB: dunno what that is..\n"); + } + + return ret; + +} +static DEVICE_ATTR(drm_test_state, 0644, sysfs_show_current_drmstate, + sysfs_set_drmstate); + static int hisi_drm_platform_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *node = dev->of_node; struct device_node *child_np; struct component_match *match = NULL; + int error; + + error = device_create_file(dev, &dev_attr_drm_test_state); of_platform_populate(node, NULL, NULL, dev); @@ -245,6 +357,10 @@ static int hisi_drm_platform_probe(struct platform_device *pdev) return component_master_add_with_match(dev, &hisi_drm_ops, match); + + + + return 0; } @@ -261,6 +377,7 @@ static const struct of_device_id hisi_drm_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, hisi_drm_dt_ids); + static struct platform_driver hisi_drm_platform_driver = { .probe = hisi_drm_platform_probe, .remove = hisi_drm_platform_remove, @@ -268,6 +385,7 @@ static struct platform_driver hisi_drm_platform_driver = { .owner = THIS_MODULE, .name = DRIVER_NAME, .of_match_table = hisi_drm_dt_ids, + .pm = &host1x_drm_pm_ops, }, };