1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/
7 #include <linux/console.h>
9 #include <linux/module.h>
10 #include <linux/pm_runtime.h>
12 #include <drm/drm_atomic.h>
13 #include <drm/drm_atomic_helper.h>
14 #include <drm/drm_crtc.h>
15 #include <drm/drm_drv.h>
16 #include <drm/drm_fbdev_dma.h>
17 #include <drm/drm_gem_dma_helper.h>
18 #include <drm/drm_managed.h>
19 #include <drm/drm_module.h>
20 #include <drm/drm_probe_helper.h>
22 #include "tidss_dispc.h"
23 #include "tidss_drv.h"
24 #include "tidss_kms.h"
25 #include "tidss_irq.h"
27 /* Power management */
29 int tidss_runtime_get(struct tidss_device *tidss)
33 dev_dbg(tidss->dev, "%s\n", __func__);
35 r = pm_runtime_get_sync(tidss->dev);
40 void tidss_runtime_put(struct tidss_device *tidss)
44 dev_dbg(tidss->dev, "%s\n", __func__);
46 r = pm_runtime_put_sync(tidss->dev);
50 static int __maybe_unused tidss_pm_runtime_suspend(struct device *dev)
52 struct tidss_device *tidss = dev_get_drvdata(dev);
54 dev_dbg(dev, "%s\n", __func__);
56 return dispc_runtime_suspend(tidss->dispc);
59 static int __maybe_unused tidss_pm_runtime_resume(struct device *dev)
61 struct tidss_device *tidss = dev_get_drvdata(dev);
64 dev_dbg(dev, "%s\n", __func__);
66 r = dispc_runtime_resume(tidss->dispc);
73 static int __maybe_unused tidss_suspend(struct device *dev)
75 struct tidss_device *tidss = dev_get_drvdata(dev);
77 dev_dbg(dev, "%s\n", __func__);
79 return drm_mode_config_helper_suspend(&tidss->ddev);
82 static int __maybe_unused tidss_resume(struct device *dev)
84 struct tidss_device *tidss = dev_get_drvdata(dev);
86 dev_dbg(dev, "%s\n", __func__);
88 return drm_mode_config_helper_resume(&tidss->ddev);
91 static __maybe_unused const struct dev_pm_ops tidss_pm_ops = {
92 SET_SYSTEM_SLEEP_PM_OPS(tidss_suspend, tidss_resume)
93 SET_RUNTIME_PM_OPS(tidss_pm_runtime_suspend, tidss_pm_runtime_resume, NULL)
96 /* DRM device Information */
98 static void tidss_release(struct drm_device *ddev)
100 drm_kms_helper_poll_fini(ddev);
103 DEFINE_DRM_GEM_DMA_FOPS(tidss_fops);
105 static const struct drm_driver tidss_driver = {
106 .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
108 .release = tidss_release,
109 DRM_GEM_DMA_DRIVER_OPS_VMAP,
111 .desc = "TI Keystone DSS",
117 static int tidss_probe(struct platform_device *pdev)
119 struct device *dev = &pdev->dev;
120 struct tidss_device *tidss;
121 struct drm_device *ddev;
125 dev_dbg(dev, "%s\n", __func__);
127 tidss = devm_drm_dev_alloc(&pdev->dev, &tidss_driver,
128 struct tidss_device, ddev);
130 return PTR_ERR(tidss);
135 tidss->feat = of_device_get_match_data(dev);
137 platform_set_drvdata(pdev, tidss);
139 ret = dispc_init(tidss);
141 dev_err(dev, "failed to initialize dispc: %d\n", ret);
145 pm_runtime_enable(dev);
148 /* If we don't have PM, we need to call resume manually */
149 dispc_runtime_resume(tidss->dispc);
152 ret = tidss_modeset_init(tidss);
154 if (ret != -EPROBE_DEFER)
155 dev_err(dev, "failed to init DRM/KMS (%d)\n", ret);
156 goto err_runtime_suspend;
159 irq = platform_get_irq(pdev, 0);
162 goto err_runtime_suspend;
166 ret = tidss_irq_install(ddev, irq);
168 dev_err(dev, "tidss_irq_install failed: %d\n", ret);
169 goto err_runtime_suspend;
172 drm_kms_helper_poll_init(ddev);
174 drm_mode_config_reset(ddev);
176 ret = drm_dev_register(ddev, 0);
178 dev_err(dev, "failed to register DRM device\n");
179 goto err_irq_uninstall;
182 drm_fbdev_dma_setup(ddev, 32);
184 dev_dbg(dev, "%s done\n", __func__);
189 tidss_irq_uninstall(ddev);
193 dispc_runtime_suspend(tidss->dispc);
195 pm_runtime_disable(dev);
200 static void tidss_remove(struct platform_device *pdev)
202 struct device *dev = &pdev->dev;
203 struct tidss_device *tidss = platform_get_drvdata(pdev);
204 struct drm_device *ddev = &tidss->ddev;
206 dev_dbg(dev, "%s\n", __func__);
208 drm_dev_unregister(ddev);
210 drm_atomic_helper_shutdown(ddev);
212 tidss_irq_uninstall(ddev);
215 /* If we don't have PM, we need to call suspend manually */
216 dispc_runtime_suspend(tidss->dispc);
218 pm_runtime_disable(dev);
220 /* devm allocated dispc goes away with the dev so mark it NULL */
223 dev_dbg(dev, "%s done\n", __func__);
226 static void tidss_shutdown(struct platform_device *pdev)
228 drm_atomic_helper_shutdown(platform_get_drvdata(pdev));
231 static const struct of_device_id tidss_of_table[] = {
232 { .compatible = "ti,k2g-dss", .data = &dispc_k2g_feats, },
233 { .compatible = "ti,am625-dss", .data = &dispc_am625_feats, },
234 { .compatible = "ti,am65x-dss", .data = &dispc_am65x_feats, },
235 { .compatible = "ti,j721e-dss", .data = &dispc_j721e_feats, },
239 MODULE_DEVICE_TABLE(of, tidss_of_table);
241 static struct platform_driver tidss_platform_driver = {
242 .probe = tidss_probe,
243 .remove_new = tidss_remove,
244 .shutdown = tidss_shutdown,
247 .pm = pm_ptr(&tidss_pm_ops),
248 .of_match_table = tidss_of_table,
249 .suppress_bind_attrs = true,
253 drm_module_platform_driver(tidss_platform_driver);
256 MODULE_DESCRIPTION("TI Keystone DSS Driver");
257 MODULE_LICENSE("GPL v2");