Linux Audio

Check our new training course

Loading...
v4.6
 
  1/*
  2 * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
  3 *
  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.
  7 *
  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.
 12 */
 13
 14#include <linux/of_irq.h>
 15#include "edp.h"
 16
 17static irqreturn_t edp_irq(int irq, void *dev_id)
 18{
 19	struct msm_edp *edp = dev_id;
 20
 21	/* Process eDP irq */
 22	return msm_edp_ctrl_irq(edp->ctrl);
 23}
 24
 25static void edp_destroy(struct platform_device *pdev)
 26{
 27	struct msm_edp *edp = platform_get_drvdata(pdev);
 28
 29	if (!edp)
 30		return;
 31
 32	if (edp->ctrl) {
 33		msm_edp_ctrl_destroy(edp->ctrl);
 34		edp->ctrl = NULL;
 35	}
 36
 37	platform_set_drvdata(pdev, NULL);
 38}
 39
 40/* construct eDP at bind/probe time, grab all the resources. */
 41static struct msm_edp *edp_init(struct platform_device *pdev)
 42{
 43	struct msm_edp *edp = NULL;
 44	int ret;
 45
 46	if (!pdev) {
 47		pr_err("no eDP device\n");
 48		ret = -ENXIO;
 49		goto fail;
 50	}
 51
 52	edp = devm_kzalloc(&pdev->dev, sizeof(*edp), GFP_KERNEL);
 53	if (!edp) {
 54		ret = -ENOMEM;
 55		goto fail;
 56	}
 57	DBG("eDP probed=%p", edp);
 58
 59	edp->pdev = pdev;
 60	platform_set_drvdata(pdev, edp);
 61
 62	ret = msm_edp_ctrl_init(edp);
 63	if (ret)
 64		goto fail;
 65
 66	return edp;
 67
 68fail:
 69	if (edp)
 70		edp_destroy(pdev);
 71
 72	return ERR_PTR(ret);
 73}
 74
 75static int edp_bind(struct device *dev, struct device *master, void *data)
 76{
 77	struct drm_device *drm = dev_get_drvdata(master);
 78	struct msm_drm_private *priv = drm->dev_private;
 79	struct msm_edp *edp;
 80
 81	DBG("");
 82	edp = edp_init(to_platform_device(dev));
 83	if (IS_ERR(edp))
 84		return PTR_ERR(edp);
 85	priv->edp = edp;
 86
 87	return 0;
 88}
 89
 90static void edp_unbind(struct device *dev, struct device *master, void *data)
 91{
 92	struct drm_device *drm = dev_get_drvdata(master);
 93	struct msm_drm_private *priv = drm->dev_private;
 94
 95	DBG("");
 96	if (priv->edp) {
 97		edp_destroy(to_platform_device(dev));
 98		priv->edp = NULL;
 99	}
100}
101
102static const struct component_ops edp_ops = {
103		.bind   = edp_bind,
104		.unbind = edp_unbind,
105};
106
107static int edp_dev_probe(struct platform_device *pdev)
108{
109	DBG("");
110	return component_add(&pdev->dev, &edp_ops);
111}
112
113static int edp_dev_remove(struct platform_device *pdev)
114{
115	DBG("");
116	component_del(&pdev->dev, &edp_ops);
117	return 0;
118}
119
120static const struct of_device_id dt_match[] = {
121	{ .compatible = "qcom,mdss-edp" },
122	{}
123};
124
125static 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,
131	},
132};
133
134void __init msm_edp_register(void)
135{
136	DBG("");
137	platform_driver_register(&edp_driver);
138}
139
140void __exit msm_edp_unregister(void)
141{
142	DBG("");
143	platform_driver_unregister(&edp_driver);
144}
145
146/* Second part of initialization, the drm/kms level modeset_init */
147int msm_edp_modeset_init(struct msm_edp *edp, struct drm_device *dev,
148				struct drm_encoder *encoder)
149{
150	struct platform_device *pdev = edp->pdev;
151	struct msm_drm_private *priv = dev->dev_private;
152	int ret;
153
154	edp->encoder = encoder;
155	edp->dev = dev;
156
157	edp->bridge = msm_edp_bridge_init(edp);
158	if (IS_ERR(edp->bridge)) {
159		ret = PTR_ERR(edp->bridge);
160		dev_err(dev->dev, "failed to create eDP bridge: %d\n", ret);
161		edp->bridge = NULL;
162		goto fail;
163	}
164
165	edp->connector = msm_edp_connector_init(edp);
166	if (IS_ERR(edp->connector)) {
167		ret = PTR_ERR(edp->connector);
168		dev_err(dev->dev, "failed to create eDP connector: %d\n", ret);
169		edp->connector = NULL;
170		goto fail;
171	}
172
173	edp->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
174	if (edp->irq < 0) {
175		ret = edp->irq;
176		dev_err(dev->dev, "failed to get IRQ: %d\n", ret);
177		goto fail;
178	}
179
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		dev_err(dev->dev, "failed to request IRQ%u: %d\n",
185				edp->irq, ret);
186		goto fail;
187	}
188
189	encoder->bridge = edp->bridge;
190
191	priv->bridges[priv->num_bridges++]       = edp->bridge;
192	priv->connectors[priv->num_connectors++] = edp->connector;
193
194	return 0;
195
196fail:
197	/* bridge/connector are normally destroyed by drm */
198	if (edp->bridge) {
199		edp_bridge_destroy(edp->bridge);
200		edp->bridge = NULL;
201	}
202	if (edp->connector) {
203		edp->connector->funcs->destroy(edp->connector);
204		edp->connector = NULL;
205	}
206
207	return ret;
208}
v5.4
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
 
 
 
 
 
 
 
 
 
  4 */
  5
  6#include <linux/of_irq.h>
  7#include "edp.h"
  8
  9static irqreturn_t edp_irq(int irq, void *dev_id)
 10{
 11	struct msm_edp *edp = dev_id;
 12
 13	/* Process eDP irq */
 14	return msm_edp_ctrl_irq(edp->ctrl);
 15}
 16
 17static void edp_destroy(struct platform_device *pdev)
 18{
 19	struct msm_edp *edp = platform_get_drvdata(pdev);
 20
 21	if (!edp)
 22		return;
 23
 24	if (edp->ctrl) {
 25		msm_edp_ctrl_destroy(edp->ctrl);
 26		edp->ctrl = NULL;
 27	}
 28
 29	platform_set_drvdata(pdev, NULL);
 30}
 31
 32/* construct eDP at bind/probe time, grab all the resources. */
 33static struct msm_edp *edp_init(struct platform_device *pdev)
 34{
 35	struct msm_edp *edp = NULL;
 36	int ret;
 37
 38	if (!pdev) {
 39		pr_err("no eDP device\n");
 40		ret = -ENXIO;
 41		goto fail;
 42	}
 43
 44	edp = devm_kzalloc(&pdev->dev, sizeof(*edp), GFP_KERNEL);
 45	if (!edp) {
 46		ret = -ENOMEM;
 47		goto fail;
 48	}
 49	DBG("eDP probed=%p", edp);
 50
 51	edp->pdev = pdev;
 52	platform_set_drvdata(pdev, edp);
 53
 54	ret = msm_edp_ctrl_init(edp);
 55	if (ret)
 56		goto fail;
 57
 58	return edp;
 59
 60fail:
 61	if (edp)
 62		edp_destroy(pdev);
 63
 64	return ERR_PTR(ret);
 65}
 66
 67static int edp_bind(struct device *dev, struct device *master, void *data)
 68{
 69	struct drm_device *drm = dev_get_drvdata(master);
 70	struct msm_drm_private *priv = drm->dev_private;
 71	struct msm_edp *edp;
 72
 73	DBG("");
 74	edp = edp_init(to_platform_device(dev));
 75	if (IS_ERR(edp))
 76		return PTR_ERR(edp);
 77	priv->edp = edp;
 78
 79	return 0;
 80}
 81
 82static void edp_unbind(struct device *dev, struct device *master, void *data)
 83{
 84	struct drm_device *drm = dev_get_drvdata(master);
 85	struct msm_drm_private *priv = drm->dev_private;
 86
 87	DBG("");
 88	if (priv->edp) {
 89		edp_destroy(to_platform_device(dev));
 90		priv->edp = NULL;
 91	}
 92}
 93
 94static const struct component_ops edp_ops = {
 95		.bind   = edp_bind,
 96		.unbind = edp_unbind,
 97};
 98
 99static int edp_dev_probe(struct platform_device *pdev)
100{
101	DBG("");
102	return component_add(&pdev->dev, &edp_ops);
103}
104
105static int edp_dev_remove(struct platform_device *pdev)
106{
107	DBG("");
108	component_del(&pdev->dev, &edp_ops);
109	return 0;
110}
111
112static const struct of_device_id dt_match[] = {
113	{ .compatible = "qcom,mdss-edp" },
114	{}
115};
116
117static 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,
123	},
124};
125
126void __init msm_edp_register(void)
127{
128	DBG("");
129	platform_driver_register(&edp_driver);
130}
131
132void __exit msm_edp_unregister(void)
133{
134	DBG("");
135	platform_driver_unregister(&edp_driver);
136}
137
138/* Second part of initialization, the drm/kms level modeset_init */
139int msm_edp_modeset_init(struct msm_edp *edp, struct drm_device *dev,
140				struct drm_encoder *encoder)
141{
142	struct platform_device *pdev = edp->pdev;
143	struct msm_drm_private *priv = dev->dev_private;
144	int ret;
145
146	edp->encoder = encoder;
147	edp->dev = dev;
148
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;
155	}
156
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;
163	}
164
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;
170	}
171
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;
179	}
180
181	encoder->bridge = edp->bridge;
182
183	priv->bridges[priv->num_bridges++]       = edp->bridge;
184	priv->connectors[priv->num_connectors++] = edp->connector;
185
186	return 0;
187
188fail:
189	/* bridge/connector are normally destroyed by drm */
190	if (edp->bridge) {
191		edp_bridge_destroy(edp->bridge);
192		edp->bridge = NULL;
193	}
194	if (edp->connector) {
195		edp->connector->funcs->destroy(edp->connector);
196		edp->connector = NULL;
197	}
198
199	return ret;
200}