| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Samsung SoC DP (Display Port) interface driver. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2012 Samsung Electronics Co., Ltd. |
|---|
| 5 | 6 | * Author: Jingoo Han <jg1.han@samsung.com> |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 8 | | - * under the terms of the GNU General Public License as published by the |
|---|
| 9 | | - * Free Software Foundation; either version 2 of the License, or (at your |
|---|
| 10 | | - * option) any later version. |
|---|
| 11 | 7 | */ |
|---|
| 12 | 8 | |
|---|
| 13 | | -#include <linux/module.h> |
|---|
| 14 | | -#include <linux/platform_device.h> |
|---|
| 15 | | -#include <linux/err.h> |
|---|
| 16 | 9 | #include <linux/clk.h> |
|---|
| 17 | | -#include <linux/of_graph.h> |
|---|
| 18 | 10 | #include <linux/component.h> |
|---|
| 11 | +#include <linux/err.h> |
|---|
| 12 | +#include <linux/module.h> |
|---|
| 13 | +#include <linux/of_graph.h> |
|---|
| 14 | +#include <linux/platform_device.h> |
|---|
| 19 | 15 | #include <linux/pm_runtime.h> |
|---|
| 20 | 16 | #include <video/of_display_timing.h> |
|---|
| 21 | 17 | #include <video/of_videomode.h> |
|---|
| 22 | 18 | #include <video/videomode.h> |
|---|
| 23 | 19 | |
|---|
| 24 | | -#include <drm/drmP.h> |
|---|
| 20 | +#include <drm/bridge/analogix_dp.h> |
|---|
| 21 | +#include <drm/drm_atomic_helper.h> |
|---|
| 22 | +#include <drm/drm_bridge.h> |
|---|
| 25 | 23 | #include <drm/drm_crtc.h> |
|---|
| 26 | | -#include <drm/drm_crtc_helper.h> |
|---|
| 27 | 24 | #include <drm/drm_of.h> |
|---|
| 28 | 25 | #include <drm/drm_panel.h> |
|---|
| 29 | | - |
|---|
| 30 | | -#include <drm/bridge/analogix_dp.h> |
|---|
| 26 | +#include <drm/drm_print.h> |
|---|
| 27 | +#include <drm/drm_probe_helper.h> |
|---|
| 28 | +#include <drm/drm_simple_kms_helper.h> |
|---|
| 31 | 29 | #include <drm/exynos_drm.h> |
|---|
| 32 | 30 | |
|---|
| 33 | 31 | #include "exynos_drm_crtc.h" |
|---|
| .. | .. |
|---|
| 82 | 80 | |
|---|
| 83 | 81 | mode = drm_mode_create(connector->dev); |
|---|
| 84 | 82 | if (!mode) { |
|---|
| 85 | | - DRM_ERROR("failed to create a new display mode.\n"); |
|---|
| 83 | + DRM_DEV_ERROR(dp->dev, |
|---|
| 84 | + "failed to create a new display mode.\n"); |
|---|
| 86 | 85 | return num_modes; |
|---|
| 87 | 86 | } |
|---|
| 88 | 87 | |
|---|
| .. | .. |
|---|
| 108 | 107 | |
|---|
| 109 | 108 | /* Pre-empt DP connector creation if there's a bridge */ |
|---|
| 110 | 109 | if (dp->ptn_bridge) { |
|---|
| 111 | | - ret = drm_bridge_attach(&dp->encoder, dp->ptn_bridge, bridge); |
|---|
| 110 | + ret = drm_bridge_attach(&dp->encoder, dp->ptn_bridge, bridge, |
|---|
| 111 | + 0); |
|---|
| 112 | 112 | if (ret) { |
|---|
| 113 | | - DRM_ERROR("Failed to attach bridge to drm\n"); |
|---|
| 114 | | - bridge->next = NULL; |
|---|
| 113 | + DRM_DEV_ERROR(dp->dev, |
|---|
| 114 | + "Failed to attach bridge to drm\n"); |
|---|
| 115 | 115 | return ret; |
|---|
| 116 | 116 | } |
|---|
| 117 | 117 | } |
|---|
| .. | .. |
|---|
| 136 | 136 | .disable = exynos_dp_nop, |
|---|
| 137 | 137 | }; |
|---|
| 138 | 138 | |
|---|
| 139 | | -static const struct drm_encoder_funcs exynos_dp_encoder_funcs = { |
|---|
| 140 | | - .destroy = drm_encoder_cleanup, |
|---|
| 141 | | -}; |
|---|
| 142 | | - |
|---|
| 143 | 139 | static int exynos_dp_dt_parse_panel(struct exynos_dp_device *dp) |
|---|
| 144 | 140 | { |
|---|
| 145 | 141 | int ret; |
|---|
| 146 | 142 | |
|---|
| 147 | 143 | ret = of_get_videomode(dp->dev->of_node, &dp->vm, OF_USE_NATIVE_MODE); |
|---|
| 148 | 144 | if (ret) { |
|---|
| 149 | | - DRM_ERROR("failed: of_get_videomode() : %d\n", ret); |
|---|
| 145 | + DRM_DEV_ERROR(dp->dev, |
|---|
| 146 | + "failed: of_get_videomode() : %d\n", ret); |
|---|
| 150 | 147 | return ret; |
|---|
| 151 | 148 | } |
|---|
| 152 | 149 | return 0; |
|---|
| .. | .. |
|---|
| 159 | 156 | struct drm_device *drm_dev = data; |
|---|
| 160 | 157 | int ret; |
|---|
| 161 | 158 | |
|---|
| 162 | | - dp->dev = dev; |
|---|
| 163 | 159 | dp->drm_dev = drm_dev; |
|---|
| 164 | | - |
|---|
| 165 | | - dp->plat_data.dev_type = EXYNOS_DP; |
|---|
| 166 | | - dp->plat_data.power_on_start = exynos_dp_poweron; |
|---|
| 167 | | - dp->plat_data.power_off = exynos_dp_poweroff; |
|---|
| 168 | | - dp->plat_data.attach = exynos_dp_bridge_attach; |
|---|
| 169 | | - dp->plat_data.get_modes = exynos_dp_get_modes; |
|---|
| 170 | 160 | |
|---|
| 171 | 161 | if (!dp->plat_data.panel && !dp->ptn_bridge) { |
|---|
| 172 | 162 | ret = exynos_dp_dt_parse_panel(dp); |
|---|
| .. | .. |
|---|
| 174 | 164 | return ret; |
|---|
| 175 | 165 | } |
|---|
| 176 | 166 | |
|---|
| 177 | | - drm_encoder_init(drm_dev, encoder, &exynos_dp_encoder_funcs, |
|---|
| 178 | | - DRM_MODE_ENCODER_TMDS, NULL); |
|---|
| 167 | + drm_simple_encoder_init(drm_dev, encoder, DRM_MODE_ENCODER_TMDS); |
|---|
| 179 | 168 | |
|---|
| 180 | 169 | drm_encoder_helper_add(encoder, &exynos_dp_encoder_helper_funcs); |
|---|
| 181 | 170 | |
|---|
| .. | .. |
|---|
| 185 | 174 | |
|---|
| 186 | 175 | dp->plat_data.encoder = encoder; |
|---|
| 187 | 176 | |
|---|
| 188 | | - dp->adp = analogix_dp_bind(dev, dp->drm_dev, &dp->plat_data); |
|---|
| 189 | | - if (IS_ERR(dp->adp)) { |
|---|
| 177 | + ret = analogix_dp_bind(dp->adp, dp->drm_dev); |
|---|
| 178 | + if (ret) |
|---|
| 190 | 179 | dp->encoder.funcs->destroy(&dp->encoder); |
|---|
| 191 | | - return PTR_ERR(dp->adp); |
|---|
| 192 | | - } |
|---|
| 193 | 180 | |
|---|
| 194 | | - return 0; |
|---|
| 181 | + return ret; |
|---|
| 195 | 182 | } |
|---|
| 196 | 183 | |
|---|
| 197 | 184 | static void exynos_dp_unbind(struct device *dev, struct device *master, |
|---|
| .. | .. |
|---|
| 222 | 209 | if (!dp) |
|---|
| 223 | 210 | return -ENOMEM; |
|---|
| 224 | 211 | |
|---|
| 212 | + dp->dev = dev; |
|---|
| 225 | 213 | /* |
|---|
| 226 | 214 | * We just use the drvdata until driver run into component |
|---|
| 227 | 215 | * add function, and then we would set drvdata to null, so |
|---|
| .. | .. |
|---|
| 247 | 235 | |
|---|
| 248 | 236 | /* The remote port can be either a panel or a bridge */ |
|---|
| 249 | 237 | dp->plat_data.panel = panel; |
|---|
| 238 | + dp->plat_data.dev_type = EXYNOS_DP; |
|---|
| 239 | + dp->plat_data.power_on_start = exynos_dp_poweron; |
|---|
| 240 | + dp->plat_data.power_off = exynos_dp_poweroff; |
|---|
| 241 | + dp->plat_data.attach = exynos_dp_bridge_attach; |
|---|
| 242 | + dp->plat_data.get_modes = exynos_dp_get_modes; |
|---|
| 250 | 243 | dp->plat_data.skip_connector = !!bridge; |
|---|
| 244 | + |
|---|
| 251 | 245 | dp->ptn_bridge = bridge; |
|---|
| 252 | 246 | |
|---|
| 253 | 247 | out: |
|---|
| 248 | + dp->adp = analogix_dp_probe(dev, &dp->plat_data); |
|---|
| 249 | + if (IS_ERR(dp->adp)) |
|---|
| 250 | + return PTR_ERR(dp->adp); |
|---|
| 251 | + |
|---|
| 254 | 252 | return component_add(&pdev->dev, &exynos_dp_ops); |
|---|
| 255 | 253 | } |
|---|
| 256 | 254 | |
|---|
| 257 | 255 | static int exynos_dp_remove(struct platform_device *pdev) |
|---|
| 258 | 256 | { |
|---|
| 257 | + struct exynos_dp_device *dp = platform_get_drvdata(pdev); |
|---|
| 258 | + |
|---|
| 259 | 259 | component_del(&pdev->dev, &exynos_dp_ops); |
|---|
| 260 | + analogix_dp_remove(dp->adp); |
|---|
| 260 | 261 | |
|---|
| 261 | 262 | return 0; |
|---|
| 262 | 263 | } |
|---|