2 * Copyright (c) 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.
16 struct drm_encoder *msm_dsi_get_encoder(struct msm_dsi *msm_dsi)
18 if (!msm_dsi || !msm_dsi->panel)
21 return (msm_dsi->panel_flags & MIPI_DSI_MODE_VIDEO) ?
22 msm_dsi->encoders[MSM_DSI_VIDEO_ENCODER_ID] :
23 msm_dsi->encoders[MSM_DSI_CMD_ENCODER_ID];
26 static void dsi_destroy(struct msm_dsi *msm_dsi)
31 msm_dsi_manager_unregister(msm_dsi);
33 msm_dsi_host_destroy(msm_dsi->host);
37 platform_set_drvdata(msm_dsi->pdev, NULL);
40 static struct msm_dsi *dsi_init(struct platform_device *pdev)
42 struct msm_dsi *msm_dsi = NULL;
46 dev_err(&pdev->dev, "no dsi device\n");
51 msm_dsi = devm_kzalloc(&pdev->dev, sizeof(*msm_dsi), GFP_KERNEL);
56 DBG("dsi probed=%p", msm_dsi);
59 platform_set_drvdata(pdev, msm_dsi);
62 ret = msm_dsi_host_init(msm_dsi);
66 /* Register to dsi manager */
67 ret = msm_dsi_manager_register(msm_dsi);
80 static int dsi_bind(struct device *dev, struct device *master, void *data)
82 struct drm_device *drm = dev_get_drvdata(master);
83 struct msm_drm_private *priv = drm->dev_private;
84 struct platform_device *pdev = to_platform_device(dev);
85 struct msm_dsi *msm_dsi;
88 msm_dsi = dsi_init(pdev);
90 return PTR_ERR(msm_dsi);
92 priv->dsi[msm_dsi->id] = msm_dsi;
97 static void dsi_unbind(struct device *dev, struct device *master,
100 struct drm_device *drm = dev_get_drvdata(master);
101 struct msm_drm_private *priv = drm->dev_private;
102 struct msm_dsi *msm_dsi = dev_get_drvdata(dev);
103 int id = msm_dsi->id;
106 dsi_destroy(msm_dsi);
107 priv->dsi[id] = NULL;
111 static const struct component_ops dsi_ops = {
113 .unbind = dsi_unbind,
116 static int dsi_dev_probe(struct platform_device *pdev)
118 return component_add(&pdev->dev, &dsi_ops);
121 static int dsi_dev_remove(struct platform_device *pdev)
124 component_del(&pdev->dev, &dsi_ops);
128 static const struct of_device_id dt_match[] = {
129 { .compatible = "qcom,mdss-dsi-ctrl" },
133 static struct platform_driver dsi_driver = {
134 .probe = dsi_dev_probe,
135 .remove = dsi_dev_remove,
138 .of_match_table = dt_match,
142 void __init msm_dsi_register(void)
145 platform_driver_register(&dsi_driver);
148 void __exit msm_dsi_unregister(void)
151 platform_driver_unregister(&dsi_driver);
154 int msm_dsi_modeset_init(struct msm_dsi *msm_dsi, struct drm_device *dev,
155 struct drm_encoder *encoders[MSM_DSI_ENCODER_NUM])
157 struct msm_drm_private *priv = dev->dev_private;
160 if (WARN_ON(!encoders[MSM_DSI_VIDEO_ENCODER_ID] ||
161 !encoders[MSM_DSI_CMD_ENCODER_ID]))
166 ret = msm_dsi_host_modeset_init(msm_dsi->host, dev);
168 dev_err(dev->dev, "failed to modeset init host: %d\n", ret);
172 msm_dsi->bridge = msm_dsi_manager_bridge_init(msm_dsi->id);
173 if (IS_ERR(msm_dsi->bridge)) {
174 ret = PTR_ERR(msm_dsi->bridge);
175 dev_err(dev->dev, "failed to create dsi bridge: %d\n", ret);
176 msm_dsi->bridge = NULL;
180 for (i = 0; i < MSM_DSI_ENCODER_NUM; i++) {
181 encoders[i]->bridge = msm_dsi->bridge;
182 msm_dsi->encoders[i] = encoders[i];
185 msm_dsi->connector = msm_dsi_manager_connector_init(msm_dsi->id);
186 if (IS_ERR(msm_dsi->connector)) {
187 ret = PTR_ERR(msm_dsi->connector);
188 dev_err(dev->dev, "failed to create dsi connector: %d\n", ret);
189 msm_dsi->connector = NULL;
193 priv->bridges[priv->num_bridges++] = msm_dsi->bridge;
194 priv->connectors[priv->num_connectors++] = msm_dsi->connector;
199 /* bridge/connector are normally destroyed by drm: */
200 if (msm_dsi->bridge) {
201 msm_dsi_manager_bridge_destroy(msm_dsi->bridge);
202 msm_dsi->bridge = NULL;
204 if (msm_dsi->connector) {
205 msm_dsi->connector->funcs->destroy(msm_dsi->connector);
206 msm_dsi->connector = NULL;