0001
0002
0003
0004
0005
0006
0007 #include <linux/console.h>
0008 #include <linux/of_device.h>
0009 #include <linux/module.h>
0010 #include <linux/pm_runtime.h>
0011
0012 #include <drm/drm_atomic.h>
0013 #include <drm/drm_atomic_helper.h>
0014 #include <drm/drm_crtc.h>
0015 #include <drm/drm_crtc_helper.h>
0016 #include <drm/drm_drv.h>
0017 #include <drm/drm_fb_helper.h>
0018 #include <drm/drm_gem_cma_helper.h>
0019 #include <drm/drm_managed.h>
0020 #include <drm/drm_module.h>
0021 #include <drm/drm_probe_helper.h>
0022
0023 #include "tidss_dispc.h"
0024 #include "tidss_drv.h"
0025 #include "tidss_kms.h"
0026 #include "tidss_irq.h"
0027
0028
0029
0030 int tidss_runtime_get(struct tidss_device *tidss)
0031 {
0032 int r;
0033
0034 dev_dbg(tidss->dev, "%s\n", __func__);
0035
0036 r = pm_runtime_get_sync(tidss->dev);
0037 WARN_ON(r < 0);
0038 return r < 0 ? r : 0;
0039 }
0040
0041 void tidss_runtime_put(struct tidss_device *tidss)
0042 {
0043 int r;
0044
0045 dev_dbg(tidss->dev, "%s\n", __func__);
0046
0047 r = pm_runtime_put_sync(tidss->dev);
0048 WARN_ON(r < 0);
0049 }
0050
0051 static int __maybe_unused tidss_pm_runtime_suspend(struct device *dev)
0052 {
0053 struct tidss_device *tidss = dev_get_drvdata(dev);
0054
0055 dev_dbg(dev, "%s\n", __func__);
0056
0057 return dispc_runtime_suspend(tidss->dispc);
0058 }
0059
0060 static int __maybe_unused tidss_pm_runtime_resume(struct device *dev)
0061 {
0062 struct tidss_device *tidss = dev_get_drvdata(dev);
0063 int r;
0064
0065 dev_dbg(dev, "%s\n", __func__);
0066
0067 r = dispc_runtime_resume(tidss->dispc);
0068 if (r)
0069 return r;
0070
0071 return 0;
0072 }
0073
0074 static int __maybe_unused tidss_suspend(struct device *dev)
0075 {
0076 struct tidss_device *tidss = dev_get_drvdata(dev);
0077
0078 dev_dbg(dev, "%s\n", __func__);
0079
0080 return drm_mode_config_helper_suspend(&tidss->ddev);
0081 }
0082
0083 static int __maybe_unused tidss_resume(struct device *dev)
0084 {
0085 struct tidss_device *tidss = dev_get_drvdata(dev);
0086
0087 dev_dbg(dev, "%s\n", __func__);
0088
0089 return drm_mode_config_helper_resume(&tidss->ddev);
0090 }
0091
0092 static __maybe_unused const struct dev_pm_ops tidss_pm_ops = {
0093 SET_SYSTEM_SLEEP_PM_OPS(tidss_suspend, tidss_resume)
0094 SET_RUNTIME_PM_OPS(tidss_pm_runtime_suspend, tidss_pm_runtime_resume, NULL)
0095 };
0096
0097
0098
0099 static void tidss_release(struct drm_device *ddev)
0100 {
0101 drm_kms_helper_poll_fini(ddev);
0102 }
0103
0104 DEFINE_DRM_GEM_CMA_FOPS(tidss_fops);
0105
0106 static const struct drm_driver tidss_driver = {
0107 .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
0108 .fops = &tidss_fops,
0109 .release = tidss_release,
0110 DRM_GEM_CMA_DRIVER_OPS_VMAP,
0111 .name = "tidss",
0112 .desc = "TI Keystone DSS",
0113 .date = "20180215",
0114 .major = 1,
0115 .minor = 0,
0116 };
0117
0118 static int tidss_probe(struct platform_device *pdev)
0119 {
0120 struct device *dev = &pdev->dev;
0121 struct tidss_device *tidss;
0122 struct drm_device *ddev;
0123 int ret;
0124 int irq;
0125
0126 dev_dbg(dev, "%s\n", __func__);
0127
0128 tidss = devm_drm_dev_alloc(&pdev->dev, &tidss_driver,
0129 struct tidss_device, ddev);
0130 if (IS_ERR(tidss))
0131 return PTR_ERR(tidss);
0132
0133 ddev = &tidss->ddev;
0134
0135 tidss->dev = dev;
0136 tidss->feat = of_device_get_match_data(dev);
0137
0138 platform_set_drvdata(pdev, tidss);
0139
0140 ret = dispc_init(tidss);
0141 if (ret) {
0142 dev_err(dev, "failed to initialize dispc: %d\n", ret);
0143 return ret;
0144 }
0145
0146 pm_runtime_enable(dev);
0147
0148 #ifndef CONFIG_PM
0149
0150 dispc_runtime_resume(tidss->dispc);
0151 #endif
0152
0153 ret = tidss_modeset_init(tidss);
0154 if (ret < 0) {
0155 if (ret != -EPROBE_DEFER)
0156 dev_err(dev, "failed to init DRM/KMS (%d)\n", ret);
0157 goto err_runtime_suspend;
0158 }
0159
0160 irq = platform_get_irq(pdev, 0);
0161 if (irq < 0) {
0162 ret = irq;
0163 goto err_runtime_suspend;
0164 }
0165 tidss->irq = irq;
0166
0167 ret = tidss_irq_install(ddev, irq);
0168 if (ret) {
0169 dev_err(dev, "tidss_irq_install failed: %d\n", ret);
0170 goto err_runtime_suspend;
0171 }
0172
0173 drm_kms_helper_poll_init(ddev);
0174
0175 drm_mode_config_reset(ddev);
0176
0177 ret = drm_dev_register(ddev, 0);
0178 if (ret) {
0179 dev_err(dev, "failed to register DRM device\n");
0180 goto err_irq_uninstall;
0181 }
0182
0183 drm_fbdev_generic_setup(ddev, 32);
0184
0185 dev_dbg(dev, "%s done\n", __func__);
0186
0187 return 0;
0188
0189 err_irq_uninstall:
0190 tidss_irq_uninstall(ddev);
0191
0192 err_runtime_suspend:
0193 #ifndef CONFIG_PM
0194 dispc_runtime_suspend(tidss->dispc);
0195 #endif
0196 pm_runtime_disable(dev);
0197
0198 return ret;
0199 }
0200
0201 static int tidss_remove(struct platform_device *pdev)
0202 {
0203 struct device *dev = &pdev->dev;
0204 struct tidss_device *tidss = platform_get_drvdata(pdev);
0205 struct drm_device *ddev = &tidss->ddev;
0206
0207 dev_dbg(dev, "%s\n", __func__);
0208
0209 drm_dev_unregister(ddev);
0210
0211 drm_atomic_helper_shutdown(ddev);
0212
0213 tidss_irq_uninstall(ddev);
0214
0215 #ifndef CONFIG_PM
0216
0217 dispc_runtime_suspend(tidss->dispc);
0218 #endif
0219 pm_runtime_disable(dev);
0220
0221
0222 dispc_remove(tidss);
0223
0224 dev_dbg(dev, "%s done\n", __func__);
0225
0226 return 0;
0227 }
0228
0229 static void tidss_shutdown(struct platform_device *pdev)
0230 {
0231 drm_atomic_helper_shutdown(platform_get_drvdata(pdev));
0232 }
0233
0234 static const struct of_device_id tidss_of_table[] = {
0235 { .compatible = "ti,k2g-dss", .data = &dispc_k2g_feats, },
0236 { .compatible = "ti,am65x-dss", .data = &dispc_am65x_feats, },
0237 { .compatible = "ti,j721e-dss", .data = &dispc_j721e_feats, },
0238 { }
0239 };
0240
0241 MODULE_DEVICE_TABLE(of, tidss_of_table);
0242
0243 static struct platform_driver tidss_platform_driver = {
0244 .probe = tidss_probe,
0245 .remove = tidss_remove,
0246 .shutdown = tidss_shutdown,
0247 .driver = {
0248 .name = "tidss",
0249 .pm = pm_ptr(&tidss_pm_ops),
0250 .of_match_table = tidss_of_table,
0251 .suppress_bind_attrs = true,
0252 },
0253 };
0254
0255 drm_module_platform_driver(tidss_platform_driver);
0256
0257 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
0258 MODULE_DESCRIPTION("TI Keystone DSS Driver");
0259 MODULE_LICENSE("GPL v2");