2 * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <linux/of_irq.h>
17 static irqreturn_t
edp_irq(int irq
, void *dev_id
)
19 struct msm_edp
*edp
= dev_id
;
22 return msm_edp_ctrl_irq(edp
->ctrl
);
25 static void edp_destroy(struct platform_device
*pdev
)
27 struct msm_edp
*edp
= platform_get_drvdata(pdev
);
33 msm_edp_ctrl_destroy(edp
->ctrl
);
37 platform_set_drvdata(pdev
, NULL
);
40 /* construct eDP at bind/probe time, grab all the resources. */
41 static struct msm_edp
*edp_init(struct platform_device
*pdev
)
43 struct msm_edp
*edp
= NULL
;
47 pr_err("no eDP device\n");
52 edp
= devm_kzalloc(&pdev
->dev
, sizeof(*edp
), GFP_KERNEL
);
57 DBG("eDP probed=%p", edp
);
60 platform_set_drvdata(pdev
, edp
);
62 ret
= msm_edp_ctrl_init(edp
);
75 static int edp_bind(struct device
*dev
, struct device
*master
, void *data
)
77 struct drm_device
*drm
= dev_get_drvdata(master
);
78 struct msm_drm_private
*priv
= drm
->dev_private
;
82 edp
= edp_init(to_platform_device(dev
));
90 static void edp_unbind(struct device
*dev
, struct device
*master
, void *data
)
92 struct drm_device
*drm
= dev_get_drvdata(master
);
93 struct msm_drm_private
*priv
= drm
->dev_private
;
97 edp_destroy(to_platform_device(dev
));
102 static const struct component_ops edp_ops
= {
104 .unbind
= edp_unbind
,
107 static int edp_dev_probe(struct platform_device
*pdev
)
110 return component_add(&pdev
->dev
, &edp_ops
);
113 static int edp_dev_remove(struct platform_device
*pdev
)
116 component_del(&pdev
->dev
, &edp_ops
);
120 static const struct of_device_id dt_match
[] = {
121 { .compatible
= "qcom,mdss-edp" },
125 static struct platform_driver edp_driver
= {
126 .probe
= edp_dev_probe
,
127 .remove
= edp_dev_remove
,
130 .of_match_table
= dt_match
,
134 void __init
msm_edp_register(void)
137 platform_driver_register(&edp_driver
);
140 void __exit
msm_edp_unregister(void)
143 platform_driver_unregister(&edp_driver
);
146 /* Second part of initialization, the drm/kms level modeset_init */
147 int msm_edp_modeset_init(struct msm_edp
*edp
, struct drm_device
*dev
,
148 struct drm_encoder
*encoder
)
150 struct platform_device
*pdev
= edp
->pdev
;
151 struct msm_drm_private
*priv
= dev
->dev_private
;
154 edp
->encoder
= encoder
;
157 edp
->bridge
= msm_edp_bridge_init(edp
);
158 if (IS_ERR(edp
->bridge
)) {
159 ret
= PTR_ERR(edp
->bridge
);
160 DRM_DEV_ERROR(dev
->dev
, "failed to create eDP bridge: %d\n", ret
);
165 edp
->connector
= msm_edp_connector_init(edp
);
166 if (IS_ERR(edp
->connector
)) {
167 ret
= PTR_ERR(edp
->connector
);
168 DRM_DEV_ERROR(dev
->dev
, "failed to create eDP connector: %d\n", ret
);
169 edp
->connector
= NULL
;
173 edp
->irq
= irq_of_parse_and_map(pdev
->dev
.of_node
, 0);
176 DRM_DEV_ERROR(dev
->dev
, "failed to get IRQ: %d\n", ret
);
180 ret
= devm_request_irq(&pdev
->dev
, edp
->irq
,
181 edp_irq
, IRQF_TRIGGER_HIGH
| IRQF_ONESHOT
,
184 DRM_DEV_ERROR(dev
->dev
, "failed to request IRQ%u: %d\n",
189 encoder
->bridge
= edp
->bridge
;
191 priv
->bridges
[priv
->num_bridges
++] = edp
->bridge
;
192 priv
->connectors
[priv
->num_connectors
++] = edp
->connector
;
197 /* bridge/connector are normally destroyed by drm */
199 edp_bridge_destroy(edp
->bridge
);
202 if (edp
->connector
) {
203 edp
->connector
->funcs
->destroy(edp
->connector
);
204 edp
->connector
= NULL
;