]> Git Repo - linux.git/blob - drivers/gpu/drm/imx/dcss/dcss-drv.c
Merge tag 'percpu-for-6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/dennis...
[linux.git] / drivers / gpu / drm / imx / dcss / dcss-drv.c
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
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
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
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
83 static void 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
93 static void dcss_drv_platform_shutdown(struct platform_device *pdev)
94 {
95         struct dcss_drv *mdrv = dev_get_drvdata(&pdev->dev);
96
97         dcss_kms_shutdown(mdrv->kms);
98 }
99
100 static struct dcss_type_data dcss_types[] = {
101         [DCSS_IMX8MQ] = {
102                 .name = "DCSS_IMX8MQ",
103                 .blkctl_ofs = 0x2F000,
104                 .ctxld_ofs = 0x23000,
105                 .dtg_ofs = 0x20000,
106                 .scaler_ofs = 0x1C000,
107                 .ss_ofs = 0x1B000,
108                 .dpr_ofs = 0x18000,
109         },
110 };
111
112 static const struct of_device_id dcss_of_match[] = {
113         { .compatible = "nxp,imx8mq-dcss", .data = &dcss_types[DCSS_IMX8MQ], },
114         {},
115 };
116
117 MODULE_DEVICE_TABLE(of, dcss_of_match);
118
119 static struct platform_driver dcss_platform_driver = {
120         .probe  = dcss_drv_platform_probe,
121         .remove_new = dcss_drv_platform_remove,
122         .shutdown = dcss_drv_platform_shutdown,
123         .driver = {
124                 .name = "imx-dcss",
125                 .of_match_table = dcss_of_match,
126                 .pm = pm_ptr(&dcss_dev_pm_ops),
127         },
128 };
129
130 drm_module_platform_driver(dcss_platform_driver);
131
132 MODULE_AUTHOR("Laurentiu Palcu <[email protected]>");
133 MODULE_DESCRIPTION("DCSS driver for i.MX8MQ");
134 MODULE_LICENSE("GPL v2");
This page took 0.043879 seconds and 4 git commands to generate.