xref: /openbmc/linux/drivers/gpu/drm/imx/dcss/dcss-drv.c (revision 6f2bde9b)
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 		goto dcss_shutoff;
70 	}
71 
72 	return 0;
73 
74 dcss_shutoff:
75 	dcss_dev_destroy(mdrv->dcss);
76 
77 err:
78 	kfree(mdrv);
79 	return err;
80 }
81 
82 static int dcss_drv_platform_remove(struct platform_device *pdev)
83 {
84 	struct dcss_drv *mdrv = dev_get_drvdata(&pdev->dev);
85 
86 	dcss_kms_detach(mdrv->kms);
87 	dcss_dev_destroy(mdrv->dcss);
88 
89 	kfree(mdrv);
90 
91 	return 0;
92 }
93 
94 static struct dcss_type_data dcss_types[] = {
95 	[DCSS_IMX8MQ] = {
96 		.name = "DCSS_IMX8MQ",
97 		.blkctl_ofs = 0x2F000,
98 		.ctxld_ofs = 0x23000,
99 		.dtg_ofs = 0x20000,
100 		.scaler_ofs = 0x1C000,
101 		.ss_ofs = 0x1B000,
102 		.dpr_ofs = 0x18000,
103 	},
104 };
105 
106 static const struct of_device_id dcss_of_match[] = {
107 	{ .compatible = "nxp,imx8mq-dcss", .data = &dcss_types[DCSS_IMX8MQ], },
108 	{},
109 };
110 
111 MODULE_DEVICE_TABLE(of, dcss_of_match);
112 
113 static struct platform_driver dcss_platform_driver = {
114 	.probe	= dcss_drv_platform_probe,
115 	.remove	= dcss_drv_platform_remove,
116 	.driver	= {
117 		.name = "imx-dcss",
118 		.of_match_table	= dcss_of_match,
119 		.pm = pm_ptr(&dcss_dev_pm_ops),
120 	},
121 };
122 
123 drm_module_platform_driver(dcss_platform_driver);
124 
125 MODULE_AUTHOR("Laurentiu Palcu <laurentiu.palcu@nxp.com>");
126 MODULE_DESCRIPTION("DCSS driver for i.MX8MQ");
127 MODULE_LICENSE("GPL v2");
128