0001
0002
0003
0004
0005
0006 #include "dsi.h"
0007 #include "dsi_cfg.h"
0008
0009 struct drm_encoder *msm_dsi_get_encoder(struct msm_dsi *msm_dsi)
0010 {
0011 if (!msm_dsi || !msm_dsi_device_connected(msm_dsi))
0012 return NULL;
0013
0014 return msm_dsi->encoder;
0015 }
0016
0017 bool msm_dsi_is_cmd_mode(struct msm_dsi *msm_dsi)
0018 {
0019 unsigned long host_flags = msm_dsi_host_get_mode_flags(msm_dsi->host);
0020
0021 return !(host_flags & MIPI_DSI_MODE_VIDEO);
0022 }
0023
0024 struct msm_display_dsc_config *msm_dsi_get_dsc_config(struct msm_dsi *msm_dsi)
0025 {
0026 return msm_dsi_host_get_dsc_config(msm_dsi->host);
0027 }
0028
0029 static int dsi_get_phy(struct msm_dsi *msm_dsi)
0030 {
0031 struct platform_device *pdev = msm_dsi->pdev;
0032 struct platform_device *phy_pdev;
0033 struct device_node *phy_node;
0034
0035 phy_node = of_parse_phandle(pdev->dev.of_node, "phys", 0);
0036 if (!phy_node) {
0037 DRM_DEV_ERROR(&pdev->dev, "cannot find phy device\n");
0038 return -ENXIO;
0039 }
0040
0041 phy_pdev = of_find_device_by_node(phy_node);
0042 if (phy_pdev) {
0043 msm_dsi->phy = platform_get_drvdata(phy_pdev);
0044 msm_dsi->phy_dev = &phy_pdev->dev;
0045 }
0046
0047 of_node_put(phy_node);
0048
0049 if (!phy_pdev) {
0050 DRM_DEV_ERROR(&pdev->dev, "%s: phy driver is not ready\n", __func__);
0051 return -EPROBE_DEFER;
0052 }
0053 if (!msm_dsi->phy) {
0054 put_device(&phy_pdev->dev);
0055 DRM_DEV_ERROR(&pdev->dev, "%s: phy driver is not ready\n", __func__);
0056 return -EPROBE_DEFER;
0057 }
0058
0059 return 0;
0060 }
0061
0062 static void dsi_destroy(struct msm_dsi *msm_dsi)
0063 {
0064 if (!msm_dsi)
0065 return;
0066
0067 msm_dsi_manager_unregister(msm_dsi);
0068
0069 if (msm_dsi->phy_dev) {
0070 put_device(msm_dsi->phy_dev);
0071 msm_dsi->phy = NULL;
0072 msm_dsi->phy_dev = NULL;
0073 }
0074
0075 if (msm_dsi->host) {
0076 msm_dsi_host_destroy(msm_dsi->host);
0077 msm_dsi->host = NULL;
0078 }
0079
0080 platform_set_drvdata(msm_dsi->pdev, NULL);
0081 }
0082
0083 static struct msm_dsi *dsi_init(struct platform_device *pdev)
0084 {
0085 struct msm_dsi *msm_dsi;
0086 int ret;
0087
0088 if (!pdev)
0089 return ERR_PTR(-ENXIO);
0090
0091 msm_dsi = devm_kzalloc(&pdev->dev, sizeof(*msm_dsi), GFP_KERNEL);
0092 if (!msm_dsi)
0093 return ERR_PTR(-ENOMEM);
0094 DBG("dsi probed=%p", msm_dsi);
0095
0096 msm_dsi->id = -1;
0097 msm_dsi->pdev = pdev;
0098 platform_set_drvdata(pdev, msm_dsi);
0099
0100
0101 ret = msm_dsi_host_init(msm_dsi);
0102 if (ret)
0103 goto destroy_dsi;
0104
0105
0106 ret = dsi_get_phy(msm_dsi);
0107 if (ret)
0108 goto destroy_dsi;
0109
0110
0111 ret = msm_dsi_manager_register(msm_dsi);
0112 if (ret)
0113 goto destroy_dsi;
0114
0115 return msm_dsi;
0116
0117 destroy_dsi:
0118 dsi_destroy(msm_dsi);
0119 return ERR_PTR(ret);
0120 }
0121
0122 static int dsi_bind(struct device *dev, struct device *master, void *data)
0123 {
0124 struct msm_drm_private *priv = dev_get_drvdata(master);
0125 struct msm_dsi *msm_dsi = dev_get_drvdata(dev);
0126
0127 priv->dsi[msm_dsi->id] = msm_dsi;
0128
0129 return 0;
0130 }
0131
0132 static void dsi_unbind(struct device *dev, struct device *master,
0133 void *data)
0134 {
0135 struct msm_drm_private *priv = dev_get_drvdata(master);
0136 struct msm_dsi *msm_dsi = dev_get_drvdata(dev);
0137
0138 priv->dsi[msm_dsi->id] = NULL;
0139 }
0140
0141 static const struct component_ops dsi_ops = {
0142 .bind = dsi_bind,
0143 .unbind = dsi_unbind,
0144 };
0145
0146 int dsi_dev_attach(struct platform_device *pdev)
0147 {
0148 return component_add(&pdev->dev, &dsi_ops);
0149 }
0150
0151 void dsi_dev_detach(struct platform_device *pdev)
0152 {
0153 component_del(&pdev->dev, &dsi_ops);
0154 }
0155
0156 static int dsi_dev_probe(struct platform_device *pdev)
0157 {
0158 struct msm_dsi *msm_dsi;
0159
0160 DBG("");
0161 msm_dsi = dsi_init(pdev);
0162 if (IS_ERR(msm_dsi)) {
0163
0164 if (PTR_ERR(msm_dsi) == -ENODEV)
0165 return 0;
0166 else
0167 return PTR_ERR(msm_dsi);
0168 }
0169
0170 return 0;
0171 }
0172
0173 static int dsi_dev_remove(struct platform_device *pdev)
0174 {
0175 struct msm_dsi *msm_dsi = platform_get_drvdata(pdev);
0176
0177 DBG("");
0178 dsi_destroy(msm_dsi);
0179
0180 return 0;
0181 }
0182
0183 static const struct of_device_id dt_match[] = {
0184 { .compatible = "qcom,mdss-dsi-ctrl", .data = NULL },
0185 { .compatible = "qcom,dsi-ctrl-6g-qcm2290", .data = &qcm2290_dsi_cfg_handler },
0186 {}
0187 };
0188
0189 static const struct dev_pm_ops dsi_pm_ops = {
0190 SET_RUNTIME_PM_OPS(msm_dsi_runtime_suspend, msm_dsi_runtime_resume, NULL)
0191 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
0192 pm_runtime_force_resume)
0193 };
0194
0195 static struct platform_driver dsi_driver = {
0196 .probe = dsi_dev_probe,
0197 .remove = dsi_dev_remove,
0198 .driver = {
0199 .name = "msm_dsi",
0200 .of_match_table = dt_match,
0201 .pm = &dsi_pm_ops,
0202 },
0203 };
0204
0205 void __init msm_dsi_register(void)
0206 {
0207 DBG("");
0208 msm_dsi_phy_driver_register();
0209 platform_driver_register(&dsi_driver);
0210 }
0211
0212 void __exit msm_dsi_unregister(void)
0213 {
0214 DBG("");
0215 msm_dsi_phy_driver_unregister();
0216 platform_driver_unregister(&dsi_driver);
0217 }
0218
0219 int msm_dsi_modeset_init(struct msm_dsi *msm_dsi, struct drm_device *dev,
0220 struct drm_encoder *encoder)
0221 {
0222 struct msm_drm_private *priv;
0223 struct drm_bridge *ext_bridge;
0224 int ret;
0225
0226 if (WARN_ON(!encoder) || WARN_ON(!msm_dsi) || WARN_ON(!dev))
0227 return -EINVAL;
0228
0229 priv = dev->dev_private;
0230 msm_dsi->dev = dev;
0231
0232 ret = msm_dsi_host_modeset_init(msm_dsi->host, dev);
0233 if (ret) {
0234 DRM_DEV_ERROR(dev->dev, "failed to modeset init host: %d\n", ret);
0235 goto fail;
0236 }
0237
0238 if (msm_dsi_is_bonded_dsi(msm_dsi) &&
0239 !msm_dsi_is_master_dsi(msm_dsi)) {
0240
0241
0242
0243
0244 return 0;
0245 }
0246
0247 msm_dsi->encoder = encoder;
0248
0249 msm_dsi->bridge = msm_dsi_manager_bridge_init(msm_dsi->id);
0250 if (IS_ERR(msm_dsi->bridge)) {
0251 ret = PTR_ERR(msm_dsi->bridge);
0252 DRM_DEV_ERROR(dev->dev, "failed to create dsi bridge: %d\n", ret);
0253 msm_dsi->bridge = NULL;
0254 goto fail;
0255 }
0256
0257
0258
0259
0260
0261
0262
0263 ext_bridge = msm_dsi_host_get_bridge(msm_dsi->host);
0264
0265 if (ext_bridge)
0266 msm_dsi->connector =
0267 msm_dsi_manager_ext_bridge_init(msm_dsi->id);
0268 else
0269 msm_dsi->connector =
0270 msm_dsi_manager_connector_init(msm_dsi->id);
0271
0272 if (IS_ERR(msm_dsi->connector)) {
0273 ret = PTR_ERR(msm_dsi->connector);
0274 DRM_DEV_ERROR(dev->dev,
0275 "failed to create dsi connector: %d\n", ret);
0276 msm_dsi->connector = NULL;
0277 goto fail;
0278 }
0279
0280 priv->bridges[priv->num_bridges++] = msm_dsi->bridge;
0281
0282 return 0;
0283 fail:
0284
0285 if (msm_dsi->bridge) {
0286 msm_dsi_manager_bridge_destroy(msm_dsi->bridge);
0287 msm_dsi->bridge = NULL;
0288 }
0289
0290
0291 if (msm_dsi->connector && !msm_dsi->external_bridge)
0292 msm_dsi->connector->funcs->destroy(msm_dsi->connector);
0293
0294 msm_dsi->connector = NULL;
0295
0296 return ret;
0297 }
0298
0299 void msm_dsi_snapshot(struct msm_disp_state *disp_state, struct msm_dsi *msm_dsi)
0300 {
0301 msm_dsi_host_snapshot(disp_state, msm_dsi->host);
0302 msm_dsi_phy_snapshot(disp_state, msm_dsi->phy);
0303 }
0304