1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
6 #include <linux/of_irq.h>
9 static irqreturn_t
edp_irq(int irq
, void *dev_id
)
11 struct msm_edp
*edp
= dev_id
;
14 return msm_edp_ctrl_irq(edp
->ctrl
);
17 static void edp_destroy(struct platform_device
*pdev
)
19 struct msm_edp
*edp
= platform_get_drvdata(pdev
);
25 msm_edp_ctrl_destroy(edp
->ctrl
);
29 platform_set_drvdata(pdev
, NULL
);
32 /* construct eDP at bind/probe time, grab all the resources. */
33 static struct msm_edp
*edp_init(struct platform_device
*pdev
)
35 struct msm_edp
*edp
= NULL
;
39 pr_err("no eDP device\n");
44 edp
= devm_kzalloc(&pdev
->dev
, sizeof(*edp
), GFP_KERNEL
);
49 DBG("eDP probed=%p", edp
);
52 platform_set_drvdata(pdev
, edp
);
54 ret
= msm_edp_ctrl_init(edp
);
67 static int edp_bind(struct device
*dev
, struct device
*master
, void *data
)
69 struct drm_device
*drm
= dev_get_drvdata(master
);
70 struct msm_drm_private
*priv
= drm
->dev_private
;
74 edp
= edp_init(to_platform_device(dev
));
82 static void edp_unbind(struct device
*dev
, struct device
*master
, void *data
)
84 struct drm_device
*drm
= dev_get_drvdata(master
);
85 struct msm_drm_private
*priv
= drm
->dev_private
;
89 edp_destroy(to_platform_device(dev
));
94 static const struct component_ops edp_ops
= {
99 static int edp_dev_probe(struct platform_device
*pdev
)
102 return component_add(&pdev
->dev
, &edp_ops
);
105 static int edp_dev_remove(struct platform_device
*pdev
)
108 component_del(&pdev
->dev
, &edp_ops
);
112 static const struct of_device_id dt_match
[] = {
113 { .compatible
= "qcom,mdss-edp" },
117 static struct platform_driver edp_driver
= {
118 .probe
= edp_dev_probe
,
119 .remove
= edp_dev_remove
,
122 .of_match_table
= dt_match
,
126 void __init
msm_edp_register(void)
129 platform_driver_register(&edp_driver
);
132 void __exit
msm_edp_unregister(void)
135 platform_driver_unregister(&edp_driver
);
138 /* Second part of initialization, the drm/kms level modeset_init */
139 int msm_edp_modeset_init(struct msm_edp
*edp
, struct drm_device
*dev
,
140 struct drm_encoder
*encoder
)
142 struct platform_device
*pdev
= edp
->pdev
;
143 struct msm_drm_private
*priv
= dev
->dev_private
;
146 edp
->encoder
= encoder
;
149 edp
->bridge
= msm_edp_bridge_init(edp
);
150 if (IS_ERR(edp
->bridge
)) {
151 ret
= PTR_ERR(edp
->bridge
);
152 DRM_DEV_ERROR(dev
->dev
, "failed to create eDP bridge: %d\n", ret
);
157 edp
->connector
= msm_edp_connector_init(edp
);
158 if (IS_ERR(edp
->connector
)) {
159 ret
= PTR_ERR(edp
->connector
);
160 DRM_DEV_ERROR(dev
->dev
, "failed to create eDP connector: %d\n", ret
);
161 edp
->connector
= NULL
;
165 edp
->irq
= irq_of_parse_and_map(pdev
->dev
.of_node
, 0);
168 DRM_DEV_ERROR(dev
->dev
, "failed to get IRQ: %d\n", ret
);
172 ret
= devm_request_irq(&pdev
->dev
, edp
->irq
,
173 edp_irq
, IRQF_TRIGGER_HIGH
| IRQF_ONESHOT
,
176 DRM_DEV_ERROR(dev
->dev
, "failed to request IRQ%u: %d\n",
181 ret
= drm_bridge_attach(encoder
, edp
->bridge
, NULL
);
185 priv
->bridges
[priv
->num_bridges
++] = edp
->bridge
;
186 priv
->connectors
[priv
->num_connectors
++] = edp
->connector
;
191 /* bridge/connector are normally destroyed by drm */
193 edp_bridge_destroy(edp
->bridge
);
196 if (edp
->connector
) {
197 edp
->connector
->funcs
->destroy(edp
->connector
);
198 edp
->connector
= NULL
;