1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright 2019 NXP.
4 */
5
6 #include <linux/module.h>
7 #include <linux/kernel.h>
8 #include <linux/of.h>
9 #include <linux/platform_device.h>
10 #include <drm/drm_module.h>
11 #include <drm/drm_of.h>
12
13 #include "dcss-dev.h"
14 #include "dcss-kms.h"
15
16 struct dcss_drv {
17 struct dcss_dev *dcss;
18 struct dcss_kms_dev *kms;
19 };
20
dcss_drv_dev_to_dcss(struct device * dev)21 struct dcss_dev *dcss_drv_dev_to_dcss(struct device *dev)
22 {
23 struct dcss_drv *mdrv = dev_get_drvdata(dev);
24
25 return mdrv ? mdrv->dcss : NULL;
26 }
27
dcss_drv_dev_to_drm(struct device * dev)28 struct drm_device *dcss_drv_dev_to_drm(struct device *dev)
29 {
30 struct dcss_drv *mdrv = dev_get_drvdata(dev);
31
32 return mdrv ? &mdrv->kms->base : NULL;
33 }
34
dcss_drv_platform_probe(struct platform_device * pdev)35 static int dcss_drv_platform_probe(struct platform_device *pdev)
36 {
37 struct device *dev = &pdev->dev;
38 struct device_node *remote;
39 struct dcss_drv *mdrv;
40 int err = 0;
41 bool hdmi_output = true;
42
43 if (!dev->of_node)
44 return -ENODEV;
45
46 remote = of_graph_get_remote_node(dev->of_node, 0, 0);
47 if (!remote)
48 return -ENODEV;
49
50 hdmi_output = !of_device_is_compatible(remote, "fsl,imx8mq-nwl-dsi");
51
52 of_node_put(remote);
53
54 mdrv = kzalloc(sizeof(*mdrv), GFP_KERNEL);
55 if (!mdrv)
56 return -ENOMEM;
57
58 mdrv->dcss = dcss_dev_create(dev, hdmi_output);
59 if (IS_ERR(mdrv->dcss)) {
60 err = PTR_ERR(mdrv->dcss);
61 goto err;
62 }
63
64 dev_set_drvdata(dev, mdrv);
65
66 mdrv->kms = dcss_kms_attach(mdrv->dcss);
67 if (IS_ERR(mdrv->kms)) {
68 err = PTR_ERR(mdrv->kms);
69 dev_err_probe(dev, err, "Failed to initialize KMS\n");
70 goto dcss_shutoff;
71 }
72
73 return 0;
74
75 dcss_shutoff:
76 dcss_dev_destroy(mdrv->dcss);
77
78 err:
79 kfree(mdrv);
80 return err;
81 }
82
dcss_drv_platform_remove(struct platform_device * pdev)83 static int dcss_drv_platform_remove(struct platform_device *pdev)
84 {
85 struct dcss_drv *mdrv = dev_get_drvdata(&pdev->dev);
86
87 dcss_kms_detach(mdrv->kms);
88 dcss_dev_destroy(mdrv->dcss);
89
90 kfree(mdrv);
91
92 return 0;
93 }
94
95 static struct dcss_type_data dcss_types[] = {
96 [DCSS_IMX8MQ] = {
97 .name = "DCSS_IMX8MQ",
98 .blkctl_ofs = 0x2F000,
99 .ctxld_ofs = 0x23000,
100 .dtg_ofs = 0x20000,
101 .scaler_ofs = 0x1C000,
102 .ss_ofs = 0x1B000,
103 .dpr_ofs = 0x18000,
104 },
105 };
106
107 static const struct of_device_id dcss_of_match[] = {
108 { .compatible = "nxp,imx8mq-dcss", .data = &dcss_types[DCSS_IMX8MQ], },
109 {},
110 };
111
112 MODULE_DEVICE_TABLE(of, dcss_of_match);
113
114 static struct platform_driver dcss_platform_driver = {
115 .probe = dcss_drv_platform_probe,
116 .remove = dcss_drv_platform_remove,
117 .driver = {
118 .name = "imx-dcss",
119 .of_match_table = dcss_of_match,
120 .pm = pm_ptr(&dcss_dev_pm_ops),
121 },
122 };
123
124 drm_module_platform_driver(dcss_platform_driver);
125
126 MODULE_AUTHOR("Laurentiu Palcu <laurentiu.palcu@nxp.com>");
127 MODULE_DESCRIPTION("DCSS driver for i.MX8MQ");
128 MODULE_LICENSE("GPL v2");
129