dt-bindings: mtd: ingenic: Use standard ecc-engine property
[linux/fpc-iii.git] / drivers / gpu / drm / msm / edp / edp.c
blob6a63aba98a3073b3143cf34d37fc36f385cd5c89
1 /*
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>
15 #include "edp.h"
17 static irqreturn_t edp_irq(int irq, void *dev_id)
19 struct msm_edp *edp = dev_id;
21 /* Process eDP irq */
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);
29 if (!edp)
30 return;
32 if (edp->ctrl) {
33 msm_edp_ctrl_destroy(edp->ctrl);
34 edp->ctrl = NULL;
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;
44 int ret;
46 if (!pdev) {
47 pr_err("no eDP device\n");
48 ret = -ENXIO;
49 goto fail;
52 edp = devm_kzalloc(&pdev->dev, sizeof(*edp), GFP_KERNEL);
53 if (!edp) {
54 ret = -ENOMEM;
55 goto fail;
57 DBG("eDP probed=%p", edp);
59 edp->pdev = pdev;
60 platform_set_drvdata(pdev, edp);
62 ret = msm_edp_ctrl_init(edp);
63 if (ret)
64 goto fail;
66 return edp;
68 fail:
69 if (edp)
70 edp_destroy(pdev);
72 return ERR_PTR(ret);
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;
79 struct msm_edp *edp;
81 DBG("");
82 edp = edp_init(to_platform_device(dev));
83 if (IS_ERR(edp))
84 return PTR_ERR(edp);
85 priv->edp = edp;
87 return 0;
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;
95 DBG("");
96 if (priv->edp) {
97 edp_destroy(to_platform_device(dev));
98 priv->edp = NULL;
102 static const struct component_ops edp_ops = {
103 .bind = edp_bind,
104 .unbind = edp_unbind,
107 static int edp_dev_probe(struct platform_device *pdev)
109 DBG("");
110 return component_add(&pdev->dev, &edp_ops);
113 static int edp_dev_remove(struct platform_device *pdev)
115 DBG("");
116 component_del(&pdev->dev, &edp_ops);
117 return 0;
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,
128 .driver = {
129 .name = "msm_edp",
130 .of_match_table = dt_match,
134 void __init msm_edp_register(void)
136 DBG("");
137 platform_driver_register(&edp_driver);
140 void __exit msm_edp_unregister(void)
142 DBG("");
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;
152 int ret;
154 edp->encoder = encoder;
155 edp->dev = dev;
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);
161 edp->bridge = NULL;
162 goto fail;
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;
170 goto fail;
173 edp->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
174 if (edp->irq < 0) {
175 ret = edp->irq;
176 DRM_DEV_ERROR(dev->dev, "failed to get IRQ: %d\n", ret);
177 goto fail;
180 ret = devm_request_irq(&pdev->dev, edp->irq,
181 edp_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
182 "edp_isr", edp);
183 if (ret < 0) {
184 DRM_DEV_ERROR(dev->dev, "failed to request IRQ%u: %d\n",
185 edp->irq, ret);
186 goto fail;
189 encoder->bridge = edp->bridge;
191 priv->bridges[priv->num_bridges++] = edp->bridge;
192 priv->connectors[priv->num_connectors++] = edp->connector;
194 return 0;
196 fail:
197 /* bridge/connector are normally destroyed by drm */
198 if (edp->bridge) {
199 edp_bridge_destroy(edp->bridge);
200 edp->bridge = NULL;
202 if (edp->connector) {
203 edp->connector->funcs->destroy(edp->connector);
204 edp->connector = NULL;
207 return ret;