treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / gpu / drm / msm / edp / edp.c
blobad4e963ccd9b04aa324485e77adcf86d07e8e6d2
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
4 */
6 #include <linux/of_irq.h>
7 #include "edp.h"
9 static irqreturn_t edp_irq(int irq, void *dev_id)
11 struct msm_edp *edp = dev_id;
13 /* Process eDP irq */
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);
21 if (!edp)
22 return;
24 if (edp->ctrl) {
25 msm_edp_ctrl_destroy(edp->ctrl);
26 edp->ctrl = NULL;
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;
36 int ret;
38 if (!pdev) {
39 pr_err("no eDP device\n");
40 ret = -ENXIO;
41 goto fail;
44 edp = devm_kzalloc(&pdev->dev, sizeof(*edp), GFP_KERNEL);
45 if (!edp) {
46 ret = -ENOMEM;
47 goto fail;
49 DBG("eDP probed=%p", edp);
51 edp->pdev = pdev;
52 platform_set_drvdata(pdev, edp);
54 ret = msm_edp_ctrl_init(edp);
55 if (ret)
56 goto fail;
58 return edp;
60 fail:
61 if (edp)
62 edp_destroy(pdev);
64 return ERR_PTR(ret);
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;
71 struct msm_edp *edp;
73 DBG("");
74 edp = edp_init(to_platform_device(dev));
75 if (IS_ERR(edp))
76 return PTR_ERR(edp);
77 priv->edp = edp;
79 return 0;
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;
87 DBG("");
88 if (priv->edp) {
89 edp_destroy(to_platform_device(dev));
90 priv->edp = NULL;
94 static const struct component_ops edp_ops = {
95 .bind = edp_bind,
96 .unbind = edp_unbind,
99 static int edp_dev_probe(struct platform_device *pdev)
101 DBG("");
102 return component_add(&pdev->dev, &edp_ops);
105 static int edp_dev_remove(struct platform_device *pdev)
107 DBG("");
108 component_del(&pdev->dev, &edp_ops);
109 return 0;
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,
120 .driver = {
121 .name = "msm_edp",
122 .of_match_table = dt_match,
126 void __init msm_edp_register(void)
128 DBG("");
129 platform_driver_register(&edp_driver);
132 void __exit msm_edp_unregister(void)
134 DBG("");
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;
144 int ret;
146 edp->encoder = encoder;
147 edp->dev = dev;
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);
153 edp->bridge = NULL;
154 goto fail;
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;
162 goto fail;
165 edp->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
166 if (edp->irq < 0) {
167 ret = edp->irq;
168 DRM_DEV_ERROR(dev->dev, "failed to get IRQ: %d\n", ret);
169 goto fail;
172 ret = devm_request_irq(&pdev->dev, edp->irq,
173 edp_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
174 "edp_isr", edp);
175 if (ret < 0) {
176 DRM_DEV_ERROR(dev->dev, "failed to request IRQ%u: %d\n",
177 edp->irq, ret);
178 goto fail;
181 ret = drm_bridge_attach(encoder, edp->bridge, NULL);
182 if (ret)
183 goto fail;
185 priv->bridges[priv->num_bridges++] = edp->bridge;
186 priv->connectors[priv->num_connectors++] = edp->connector;
188 return 0;
190 fail:
191 /* bridge/connector are normally destroyed by drm */
192 if (edp->bridge) {
193 edp_bridge_destroy(edp->bridge);
194 edp->bridge = NULL;
196 if (edp->connector) {
197 edp->connector->funcs->destroy(edp->connector);
198 edp->connector = NULL;
201 return ret;