Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/
  4 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
  5 */
  6
  7#include <linux/console.h>
  8#include <linux/of.h>
  9#include <linux/module.h>
 10#include <linux/pm_runtime.h>
 11
 12#include <drm/drm_atomic.h>
 13#include <drm/drm_atomic_helper.h>
 14#include <drm/drm_client_setup.h>
 15#include <drm/drm_crtc.h>
 
 16#include <drm/drm_drv.h>
 17#include <drm/drm_fbdev_dma.h>
 18#include <drm/drm_gem_dma_helper.h>
 
 19#include <drm/drm_managed.h>
 20#include <drm/drm_module.h>
 21#include <drm/drm_probe_helper.h>
 22
 23#include "tidss_dispc.h"
 24#include "tidss_drv.h"
 25#include "tidss_kms.h"
 26#include "tidss_irq.h"
 27
 28/* Power management */
 29
 30int tidss_runtime_get(struct tidss_device *tidss)
 31{
 32	int r;
 33
 34	dev_dbg(tidss->dev, "%s\n", __func__);
 35
 36	r = pm_runtime_resume_and_get(tidss->dev);
 37	WARN_ON(r < 0);
 38	return r;
 39}
 40
 41void tidss_runtime_put(struct tidss_device *tidss)
 42{
 43	int r;
 44
 45	dev_dbg(tidss->dev, "%s\n", __func__);
 46
 47	pm_runtime_mark_last_busy(tidss->dev);
 48
 49	r = pm_runtime_put_autosuspend(tidss->dev);
 50	WARN_ON(r < 0);
 51}
 52
 53static int __maybe_unused tidss_pm_runtime_suspend(struct device *dev)
 54{
 55	struct tidss_device *tidss = dev_get_drvdata(dev);
 56
 57	dev_dbg(dev, "%s\n", __func__);
 58
 59	return dispc_runtime_suspend(tidss->dispc);
 60}
 61
 62static int __maybe_unused tidss_pm_runtime_resume(struct device *dev)
 63{
 64	struct tidss_device *tidss = dev_get_drvdata(dev);
 65	int r;
 66
 67	dev_dbg(dev, "%s\n", __func__);
 68
 69	r = dispc_runtime_resume(tidss->dispc);
 70	if (r)
 71		return r;
 72
 73	return 0;
 74}
 75
 76static int __maybe_unused tidss_suspend(struct device *dev)
 77{
 78	struct tidss_device *tidss = dev_get_drvdata(dev);
 79
 80	dev_dbg(dev, "%s\n", __func__);
 81
 82	return drm_mode_config_helper_suspend(&tidss->ddev);
 83}
 84
 85static int __maybe_unused tidss_resume(struct device *dev)
 86{
 87	struct tidss_device *tidss = dev_get_drvdata(dev);
 88
 89	dev_dbg(dev, "%s\n", __func__);
 90
 91	return drm_mode_config_helper_resume(&tidss->ddev);
 92}
 93
 94static __maybe_unused const struct dev_pm_ops tidss_pm_ops = {
 
 
 
 
 95	SET_SYSTEM_SLEEP_PM_OPS(tidss_suspend, tidss_resume)
 96	SET_RUNTIME_PM_OPS(tidss_pm_runtime_suspend, tidss_pm_runtime_resume, NULL)
 97};
 98
 
 
 99/* DRM device Information */
100
101static void tidss_release(struct drm_device *ddev)
102{
103	drm_kms_helper_poll_fini(ddev);
104}
105
106DEFINE_DRM_GEM_DMA_FOPS(tidss_fops);
107
108static const struct drm_driver tidss_driver = {
109	.driver_features	= DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
110	.fops			= &tidss_fops,
111	.release		= tidss_release,
112	DRM_GEM_DMA_DRIVER_OPS_VMAP,
113	DRM_FBDEV_DMA_DRIVER_OPS,
114	.name			= "tidss",
115	.desc			= "TI Keystone DSS",
116	.date			= "20180215",
117	.major			= 1,
118	.minor			= 0,
 
 
 
 
 
119};
120
121static int tidss_probe(struct platform_device *pdev)
122{
123	struct device *dev = &pdev->dev;
124	struct tidss_device *tidss;
125	struct drm_device *ddev;
126	int ret;
127	int irq;
128
129	dev_dbg(dev, "%s\n", __func__);
130
131	tidss = devm_drm_dev_alloc(&pdev->dev, &tidss_driver,
132				   struct tidss_device, ddev);
133	if (IS_ERR(tidss))
134		return PTR_ERR(tidss);
135
136	ddev = &tidss->ddev;
137
138	tidss->dev = dev;
139	tidss->feat = of_device_get_match_data(dev);
140
141	platform_set_drvdata(pdev, tidss);
142
143	spin_lock_init(&tidss->wait_lock);
144
145	ret = dispc_init(tidss);
146	if (ret) {
147		dev_err(dev, "failed to initialize dispc: %d\n", ret);
148		return ret;
149	}
150
151	pm_runtime_enable(dev);
152
153	pm_runtime_set_autosuspend_delay(dev, 1000);
154	pm_runtime_use_autosuspend(dev);
155
156#ifndef CONFIG_PM
157	/* If we don't have PM, we need to call resume manually */
158	dispc_runtime_resume(tidss->dispc);
159#endif
160
161	ret = tidss_modeset_init(tidss);
162	if (ret < 0) {
163		if (ret != -EPROBE_DEFER)
164			dev_err(dev, "failed to init DRM/KMS (%d)\n", ret);
165		goto err_runtime_suspend;
166	}
167
168	irq = platform_get_irq(pdev, 0);
169	if (irq < 0) {
170		ret = irq;
171		goto err_runtime_suspend;
172	}
173	tidss->irq = irq;
174
175	ret = tidss_irq_install(ddev, irq);
176	if (ret) {
177		dev_err(dev, "tidss_irq_install failed: %d\n", ret);
178		goto err_runtime_suspend;
179	}
180
181	drm_kms_helper_poll_init(ddev);
182
183	drm_mode_config_reset(ddev);
184
185	ret = drm_dev_register(ddev, 0);
186	if (ret) {
187		dev_err(dev, "failed to register DRM device\n");
188		goto err_irq_uninstall;
189	}
190
191	drm_client_setup(ddev, NULL);
192
193	dev_dbg(dev, "%s done\n", __func__);
194
195	return 0;
196
197err_irq_uninstall:
198	tidss_irq_uninstall(ddev);
199
200err_runtime_suspend:
201#ifndef CONFIG_PM
202	dispc_runtime_suspend(tidss->dispc);
203#endif
204	pm_runtime_dont_use_autosuspend(dev);
205	pm_runtime_disable(dev);
206
207	return ret;
208}
209
210static void tidss_remove(struct platform_device *pdev)
211{
212	struct device *dev = &pdev->dev;
213	struct tidss_device *tidss = platform_get_drvdata(pdev);
214	struct drm_device *ddev = &tidss->ddev;
215
216	dev_dbg(dev, "%s\n", __func__);
217
218	drm_dev_unregister(ddev);
219
220	drm_atomic_helper_shutdown(ddev);
221
222	tidss_irq_uninstall(ddev);
223
224#ifndef CONFIG_PM
225	/* If we don't have PM, we need to call suspend manually */
226	dispc_runtime_suspend(tidss->dispc);
227#endif
228	pm_runtime_dont_use_autosuspend(dev);
229	pm_runtime_disable(dev);
230
231	/* devm allocated dispc goes away with the dev so mark it NULL */
232	dispc_remove(tidss);
233
234	dev_dbg(dev, "%s done\n", __func__);
 
 
235}
236
237static void tidss_shutdown(struct platform_device *pdev)
238{
239	drm_atomic_helper_shutdown(platform_get_drvdata(pdev));
240}
241
242static const struct of_device_id tidss_of_table[] = {
243	{ .compatible = "ti,k2g-dss", .data = &dispc_k2g_feats, },
244	{ .compatible = "ti,am625-dss", .data = &dispc_am625_feats, },
245	{ .compatible = "ti,am62a7-dss", .data = &dispc_am62a7_feats, },
246	{ .compatible = "ti,am65x-dss", .data = &dispc_am65x_feats, },
247	{ .compatible = "ti,j721e-dss", .data = &dispc_j721e_feats, },
248	{ }
249};
250
251MODULE_DEVICE_TABLE(of, tidss_of_table);
252
253static struct platform_driver tidss_platform_driver = {
254	.probe		= tidss_probe,
255	.remove		= tidss_remove,
256	.shutdown	= tidss_shutdown,
257	.driver		= {
258		.name	= "tidss",
259		.pm	= pm_ptr(&tidss_pm_ops),
 
 
260		.of_match_table = tidss_of_table,
261		.suppress_bind_attrs = true,
262	},
263};
264
265drm_module_platform_driver(tidss_platform_driver);
266
267MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
268MODULE_DESCRIPTION("TI Keystone DSS Driver");
269MODULE_LICENSE("GPL v2");
v5.9
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/
  4 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
  5 */
  6
  7#include <linux/console.h>
  8#include <linux/of_device.h>
  9#include <linux/module.h>
 10#include <linux/pm_runtime.h>
 11
 12#include <drm/drm_atomic.h>
 13#include <drm/drm_atomic_helper.h>
 
 14#include <drm/drm_crtc.h>
 15#include <drm/drm_crtc_helper.h>
 16#include <drm/drm_drv.h>
 17#include <drm/drm_fb_helper.h>
 18#include <drm/drm_gem_cma_helper.h>
 19#include <drm/drm_irq.h>
 20#include <drm/drm_managed.h>
 
 21#include <drm/drm_probe_helper.h>
 22
 23#include "tidss_dispc.h"
 24#include "tidss_drv.h"
 25#include "tidss_kms.h"
 26#include "tidss_irq.h"
 27
 28/* Power management */
 29
 30int tidss_runtime_get(struct tidss_device *tidss)
 31{
 32	int r;
 33
 34	dev_dbg(tidss->dev, "%s\n", __func__);
 35
 36	r = pm_runtime_get_sync(tidss->dev);
 37	WARN_ON(r < 0);
 38	return r < 0 ? r : 0;
 39}
 40
 41void tidss_runtime_put(struct tidss_device *tidss)
 42{
 43	int r;
 44
 45	dev_dbg(tidss->dev, "%s\n", __func__);
 46
 47	r = pm_runtime_put_sync(tidss->dev);
 
 
 48	WARN_ON(r < 0);
 49}
 50
 51static int __maybe_unused tidss_pm_runtime_suspend(struct device *dev)
 52{
 53	struct tidss_device *tidss = dev_get_drvdata(dev);
 54
 55	dev_dbg(dev, "%s\n", __func__);
 56
 57	return dispc_runtime_suspend(tidss->dispc);
 58}
 59
 60static int __maybe_unused tidss_pm_runtime_resume(struct device *dev)
 61{
 62	struct tidss_device *tidss = dev_get_drvdata(dev);
 63	int r;
 64
 65	dev_dbg(dev, "%s\n", __func__);
 66
 67	r = dispc_runtime_resume(tidss->dispc);
 68	if (r)
 69		return r;
 70
 71	return 0;
 72}
 73
 74static int __maybe_unused tidss_suspend(struct device *dev)
 75{
 76	struct tidss_device *tidss = dev_get_drvdata(dev);
 77
 78	dev_dbg(dev, "%s\n", __func__);
 79
 80	return drm_mode_config_helper_suspend(&tidss->ddev);
 81}
 82
 83static int __maybe_unused tidss_resume(struct device *dev)
 84{
 85	struct tidss_device *tidss = dev_get_drvdata(dev);
 86
 87	dev_dbg(dev, "%s\n", __func__);
 88
 89	return drm_mode_config_helper_resume(&tidss->ddev);
 90}
 91
 92#ifdef CONFIG_PM
 93
 94static const struct dev_pm_ops tidss_pm_ops = {
 95	.runtime_suspend = tidss_pm_runtime_suspend,
 96	.runtime_resume = tidss_pm_runtime_resume,
 97	SET_SYSTEM_SLEEP_PM_OPS(tidss_suspend, tidss_resume)
 
 98};
 99
100#endif /* CONFIG_PM */
101
102/* DRM device Information */
103
104static void tidss_release(struct drm_device *ddev)
105{
106	drm_kms_helper_poll_fini(ddev);
107}
108
109DEFINE_DRM_GEM_CMA_FOPS(tidss_fops);
110
111static struct drm_driver tidss_driver = {
112	.driver_features	= DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
113	.fops			= &tidss_fops,
114	.release		= tidss_release,
115	DRM_GEM_CMA_DRIVER_OPS_VMAP,
 
116	.name			= "tidss",
117	.desc			= "TI Keystone DSS",
118	.date			= "20180215",
119	.major			= 1,
120	.minor			= 0,
121
122	.irq_preinstall		= tidss_irq_preinstall,
123	.irq_postinstall	= tidss_irq_postinstall,
124	.irq_handler		= tidss_irq_handler,
125	.irq_uninstall		= tidss_irq_uninstall,
126};
127
128static int tidss_probe(struct platform_device *pdev)
129{
130	struct device *dev = &pdev->dev;
131	struct tidss_device *tidss;
132	struct drm_device *ddev;
133	int ret;
134	int irq;
135
136	dev_dbg(dev, "%s\n", __func__);
137
138	tidss = devm_drm_dev_alloc(&pdev->dev, &tidss_driver,
139				   struct tidss_device, ddev);
140	if (IS_ERR(tidss))
141		return PTR_ERR(tidss);
142
143	ddev = &tidss->ddev;
144
145	tidss->dev = dev;
146	tidss->feat = of_device_get_match_data(dev);
147
148	platform_set_drvdata(pdev, tidss);
149
 
 
150	ret = dispc_init(tidss);
151	if (ret) {
152		dev_err(dev, "failed to initialize dispc: %d\n", ret);
153		return ret;
154	}
155
156	pm_runtime_enable(dev);
157
 
 
 
158#ifndef CONFIG_PM
159	/* If we don't have PM, we need to call resume manually */
160	dispc_runtime_resume(tidss->dispc);
161#endif
162
163	ret = tidss_modeset_init(tidss);
164	if (ret < 0) {
165		if (ret != -EPROBE_DEFER)
166			dev_err(dev, "failed to init DRM/KMS (%d)\n", ret);
167		goto err_runtime_suspend;
168	}
169
170	irq = platform_get_irq(pdev, 0);
171	if (irq < 0) {
172		ret = irq;
173		goto err_runtime_suspend;
174	}
 
175
176	ret = drm_irq_install(ddev, irq);
177	if (ret) {
178		dev_err(dev, "drm_irq_install failed: %d\n", ret);
179		goto err_runtime_suspend;
180	}
181
182	drm_kms_helper_poll_init(ddev);
183
184	drm_mode_config_reset(ddev);
185
186	ret = drm_dev_register(ddev, 0);
187	if (ret) {
188		dev_err(dev, "failed to register DRM device\n");
189		goto err_irq_uninstall;
190	}
191
192	drm_fbdev_generic_setup(ddev, 32);
193
194	dev_dbg(dev, "%s done\n", __func__);
195
196	return 0;
197
198err_irq_uninstall:
199	drm_irq_uninstall(ddev);
200
201err_runtime_suspend:
202#ifndef CONFIG_PM
203	dispc_runtime_suspend(tidss->dispc);
204#endif
 
205	pm_runtime_disable(dev);
206
207	return ret;
208}
209
210static int tidss_remove(struct platform_device *pdev)
211{
212	struct device *dev = &pdev->dev;
213	struct tidss_device *tidss = platform_get_drvdata(pdev);
214	struct drm_device *ddev = &tidss->ddev;
215
216	dev_dbg(dev, "%s\n", __func__);
217
218	drm_dev_unregister(ddev);
219
220	drm_atomic_helper_shutdown(ddev);
221
222	drm_irq_uninstall(ddev);
223
224#ifndef CONFIG_PM
225	/* If we don't have PM, we need to call suspend manually */
226	dispc_runtime_suspend(tidss->dispc);
227#endif
 
228	pm_runtime_disable(dev);
229
230	/* devm allocated dispc goes away with the dev so mark it NULL */
231	dispc_remove(tidss);
232
233	dev_dbg(dev, "%s done\n", __func__);
234
235	return 0;
236}
237
238static void tidss_shutdown(struct platform_device *pdev)
239{
240	drm_atomic_helper_shutdown(platform_get_drvdata(pdev));
241}
242
243static const struct of_device_id tidss_of_table[] = {
244	{ .compatible = "ti,k2g-dss", .data = &dispc_k2g_feats, },
 
 
245	{ .compatible = "ti,am65x-dss", .data = &dispc_am65x_feats, },
246	{ .compatible = "ti,j721e-dss", .data = &dispc_j721e_feats, },
247	{ }
248};
249
250MODULE_DEVICE_TABLE(of, tidss_of_table);
251
252static struct platform_driver tidss_platform_driver = {
253	.probe		= tidss_probe,
254	.remove		= tidss_remove,
255	.shutdown	= tidss_shutdown,
256	.driver		= {
257		.name	= "tidss",
258#ifdef CONFIG_PM
259		.pm	= &tidss_pm_ops,
260#endif
261		.of_match_table = tidss_of_table,
262		.suppress_bind_attrs = true,
263	},
264};
265
266module_platform_driver(tidss_platform_driver);
267
268MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
269MODULE_DESCRIPTION("TI Keystone DSS Driver");
270MODULE_LICENSE("GPL v2");