Commit 6b2d8fd9 authored by Jeffy Chen's avatar Jeffy Chen Committed by Heiko Stuebner

drm/bridge: analogix: Do not use device's drvdata

The driver that instantiates the bridge should own the drvdata, as all
driver model callbacks (probe, remove, shutdown, PM ops, etc.) are also
owned by its driver struct. Moreover, storing two different pointer
types in driver data depending on driver initialization status is barely
a good practice and in fact has led to many bugs in this driver.

Let's clean up this mess and change Analogix entry points to simply
accept some opaque struct pointer, adjusting their users at the same
time to avoid breaking the compilation.
Signed-off-by: default avatarTomasz Figa <tfiga@chromium.org>
Signed-off-by: default avatarJeffy Chen <jeffy.chen@rock-chips.com>
Signed-off-by: default avatarThierry Escande <thierry.escande@collabora.com>
Reviewed-by: default avatarAndrzej Hajda <a.hajda@samsung.com>
Reviewed-by: default avatarSean Paul <seanpaul@chromium.org>
Acked-by: default avatarJingoo Han <jingoohan1@gmail.com>
Acked-by: default avatarArchit Taneja <architt@codeaurora.org>
Signed-off-by: default avatarHeiko Stuebner <heiko@sntech.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20180110162348.22765-2-thierry.escande@collabora.com
parent ce91d373
...@@ -98,17 +98,15 @@ static int analogix_dp_detect_hpd(struct analogix_dp_device *dp) ...@@ -98,17 +98,15 @@ static int analogix_dp_detect_hpd(struct analogix_dp_device *dp)
return 0; return 0;
} }
int analogix_dp_psr_supported(struct device *dev) int analogix_dp_psr_supported(struct analogix_dp_device *dp)
{ {
struct analogix_dp_device *dp = dev_get_drvdata(dev);
return dp->psr_support; return dp->psr_support;
} }
EXPORT_SYMBOL_GPL(analogix_dp_psr_supported); EXPORT_SYMBOL_GPL(analogix_dp_psr_supported);
int analogix_dp_enable_psr(struct device *dev) int analogix_dp_enable_psr(struct analogix_dp_device *dp)
{ {
struct analogix_dp_device *dp = dev_get_drvdata(dev);
struct edp_vsc_psr psr_vsc; struct edp_vsc_psr psr_vsc;
if (!dp->psr_support) if (!dp->psr_support)
...@@ -129,9 +127,8 @@ int analogix_dp_enable_psr(struct device *dev) ...@@ -129,9 +127,8 @@ int analogix_dp_enable_psr(struct device *dev)
} }
EXPORT_SYMBOL_GPL(analogix_dp_enable_psr); EXPORT_SYMBOL_GPL(analogix_dp_enable_psr);
int analogix_dp_disable_psr(struct device *dev) int analogix_dp_disable_psr(struct analogix_dp_device *dp)
{ {
struct analogix_dp_device *dp = dev_get_drvdata(dev);
struct edp_vsc_psr psr_vsc; struct edp_vsc_psr psr_vsc;
int ret; int ret;
...@@ -1279,8 +1276,9 @@ static ssize_t analogix_dpaux_transfer(struct drm_dp_aux *aux, ...@@ -1279,8 +1276,9 @@ static ssize_t analogix_dpaux_transfer(struct drm_dp_aux *aux,
return analogix_dp_transfer(dp, msg); return analogix_dp_transfer(dp, msg);
} }
int analogix_dp_bind(struct device *dev, struct drm_device *drm_dev, struct analogix_dp_device *
struct analogix_dp_plat_data *plat_data) analogix_dp_bind(struct device *dev, struct drm_device *drm_dev,
struct analogix_dp_plat_data *plat_data)
{ {
struct platform_device *pdev = to_platform_device(dev); struct platform_device *pdev = to_platform_device(dev);
struct analogix_dp_device *dp; struct analogix_dp_device *dp;
...@@ -1290,14 +1288,12 @@ int analogix_dp_bind(struct device *dev, struct drm_device *drm_dev, ...@@ -1290,14 +1288,12 @@ int analogix_dp_bind(struct device *dev, struct drm_device *drm_dev,
if (!plat_data) { if (!plat_data) {
dev_err(dev, "Invalided input plat_data\n"); dev_err(dev, "Invalided input plat_data\n");
return -EINVAL; return ERR_PTR(-EINVAL);
} }
dp = devm_kzalloc(dev, sizeof(struct analogix_dp_device), GFP_KERNEL); dp = devm_kzalloc(dev, sizeof(struct analogix_dp_device), GFP_KERNEL);
if (!dp) if (!dp)
return -ENOMEM; return ERR_PTR(-ENOMEM);
dev_set_drvdata(dev, dp);
dp->dev = &pdev->dev; dp->dev = &pdev->dev;
dp->dpms_mode = DRM_MODE_DPMS_OFF; dp->dpms_mode = DRM_MODE_DPMS_OFF;
...@@ -1314,7 +1310,7 @@ int analogix_dp_bind(struct device *dev, struct drm_device *drm_dev, ...@@ -1314,7 +1310,7 @@ int analogix_dp_bind(struct device *dev, struct drm_device *drm_dev,
ret = analogix_dp_dt_parse_pdata(dp); ret = analogix_dp_dt_parse_pdata(dp);
if (ret) if (ret)
return ret; return ERR_PTR(ret);
dp->phy = devm_phy_get(dp->dev, "dp"); dp->phy = devm_phy_get(dp->dev, "dp");
if (IS_ERR(dp->phy)) { if (IS_ERR(dp->phy)) {
...@@ -1328,14 +1324,14 @@ int analogix_dp_bind(struct device *dev, struct drm_device *drm_dev, ...@@ -1328,14 +1324,14 @@ int analogix_dp_bind(struct device *dev, struct drm_device *drm_dev,
if (ret == -ENOSYS || ret == -ENODEV) if (ret == -ENOSYS || ret == -ENODEV)
dp->phy = NULL; dp->phy = NULL;
else else
return ret; return ERR_PTR(ret);
} }
} }
dp->clock = devm_clk_get(&pdev->dev, "dp"); dp->clock = devm_clk_get(&pdev->dev, "dp");
if (IS_ERR(dp->clock)) { if (IS_ERR(dp->clock)) {
dev_err(&pdev->dev, "failed to get clock\n"); dev_err(&pdev->dev, "failed to get clock\n");
return PTR_ERR(dp->clock); return ERR_CAST(dp->clock);
} }
clk_prepare_enable(dp->clock); clk_prepare_enable(dp->clock);
...@@ -1344,7 +1340,7 @@ int analogix_dp_bind(struct device *dev, struct drm_device *drm_dev, ...@@ -1344,7 +1340,7 @@ int analogix_dp_bind(struct device *dev, struct drm_device *drm_dev,
dp->reg_base = devm_ioremap_resource(&pdev->dev, res); dp->reg_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(dp->reg_base)) if (IS_ERR(dp->reg_base))
return PTR_ERR(dp->reg_base); return ERR_CAST(dp->reg_base);
dp->force_hpd = of_property_read_bool(dev->of_node, "force-hpd"); dp->force_hpd = of_property_read_bool(dev->of_node, "force-hpd");
...@@ -1365,7 +1361,7 @@ int analogix_dp_bind(struct device *dev, struct drm_device *drm_dev, ...@@ -1365,7 +1361,7 @@ int analogix_dp_bind(struct device *dev, struct drm_device *drm_dev,
"hpd_gpio"); "hpd_gpio");
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to get hpd gpio\n"); dev_err(&pdev->dev, "failed to get hpd gpio\n");
return ret; return ERR_PTR(ret);
} }
dp->irq = gpio_to_irq(dp->hpd_gpio); dp->irq = gpio_to_irq(dp->hpd_gpio);
irq_flags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING; irq_flags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING;
...@@ -1377,7 +1373,7 @@ int analogix_dp_bind(struct device *dev, struct drm_device *drm_dev, ...@@ -1377,7 +1373,7 @@ int analogix_dp_bind(struct device *dev, struct drm_device *drm_dev,
if (dp->irq == -ENXIO) { if (dp->irq == -ENXIO) {
dev_err(&pdev->dev, "failed to get irq\n"); dev_err(&pdev->dev, "failed to get irq\n");
return -ENODEV; return ERR_PTR(-ENODEV);
} }
pm_runtime_enable(dev); pm_runtime_enable(dev);
...@@ -1418,7 +1414,7 @@ int analogix_dp_bind(struct device *dev, struct drm_device *drm_dev, ...@@ -1418,7 +1414,7 @@ int analogix_dp_bind(struct device *dev, struct drm_device *drm_dev,
phy_power_off(dp->phy); phy_power_off(dp->phy);
pm_runtime_put(dev); pm_runtime_put(dev);
return 0; return dp;
err_disable_pm_runtime: err_disable_pm_runtime:
...@@ -1426,15 +1422,12 @@ int analogix_dp_bind(struct device *dev, struct drm_device *drm_dev, ...@@ -1426,15 +1422,12 @@ int analogix_dp_bind(struct device *dev, struct drm_device *drm_dev,
pm_runtime_put(dev); pm_runtime_put(dev);
pm_runtime_disable(dev); pm_runtime_disable(dev);
return ret; return ERR_PTR(ret);
} }
EXPORT_SYMBOL_GPL(analogix_dp_bind); EXPORT_SYMBOL_GPL(analogix_dp_bind);
void analogix_dp_unbind(struct device *dev, struct device *master, void analogix_dp_unbind(struct analogix_dp_device *dp)
void *data)
{ {
struct analogix_dp_device *dp = dev_get_drvdata(dev);
analogix_dp_bridge_disable(dp->bridge); analogix_dp_bridge_disable(dp->bridge);
dp->connector.funcs->destroy(&dp->connector); dp->connector.funcs->destroy(&dp->connector);
dp->encoder->funcs->destroy(dp->encoder); dp->encoder->funcs->destroy(dp->encoder);
...@@ -1447,16 +1440,14 @@ void analogix_dp_unbind(struct device *dev, struct device *master, ...@@ -1447,16 +1440,14 @@ void analogix_dp_unbind(struct device *dev, struct device *master,
} }
drm_dp_aux_unregister(&dp->aux); drm_dp_aux_unregister(&dp->aux);
pm_runtime_disable(dev); pm_runtime_disable(dp->dev);
clk_disable_unprepare(dp->clock); clk_disable_unprepare(dp->clock);
} }
EXPORT_SYMBOL_GPL(analogix_dp_unbind); EXPORT_SYMBOL_GPL(analogix_dp_unbind);
#ifdef CONFIG_PM #ifdef CONFIG_PM
int analogix_dp_suspend(struct device *dev) int analogix_dp_suspend(struct analogix_dp_device *dp)
{ {
struct analogix_dp_device *dp = dev_get_drvdata(dev);
clk_disable_unprepare(dp->clock); clk_disable_unprepare(dp->clock);
if (dp->plat_data->panel) { if (dp->plat_data->panel) {
...@@ -1468,9 +1459,8 @@ int analogix_dp_suspend(struct device *dev) ...@@ -1468,9 +1459,8 @@ int analogix_dp_suspend(struct device *dev)
} }
EXPORT_SYMBOL_GPL(analogix_dp_suspend); EXPORT_SYMBOL_GPL(analogix_dp_suspend);
int analogix_dp_resume(struct device *dev) int analogix_dp_resume(struct analogix_dp_device *dp)
{ {
struct analogix_dp_device *dp = dev_get_drvdata(dev);
int ret; int ret;
ret = clk_prepare_enable(dp->clock); ret = clk_prepare_enable(dp->clock);
......
...@@ -41,6 +41,7 @@ struct exynos_dp_device { ...@@ -41,6 +41,7 @@ struct exynos_dp_device {
struct device *dev; struct device *dev;
struct videomode vm; struct videomode vm;
struct analogix_dp_device *adp;
struct analogix_dp_plat_data plat_data; struct analogix_dp_plat_data plat_data;
}; };
...@@ -157,13 +158,6 @@ static int exynos_dp_bind(struct device *dev, struct device *master, void *data) ...@@ -157,13 +158,6 @@ static int exynos_dp_bind(struct device *dev, struct device *master, void *data)
struct drm_device *drm_dev = data; struct drm_device *drm_dev = data;
int ret; int ret;
/*
* Just like the probe function said, we don't need the
* device drvrate anymore, we should leave the charge to
* analogix dp driver, set the device drvdata to NULL.
*/
dev_set_drvdata(dev, NULL);
dp->dev = dev; dp->dev = dev;
dp->drm_dev = drm_dev; dp->drm_dev = drm_dev;
...@@ -190,13 +184,19 @@ static int exynos_dp_bind(struct device *dev, struct device *master, void *data) ...@@ -190,13 +184,19 @@ static int exynos_dp_bind(struct device *dev, struct device *master, void *data)
dp->plat_data.encoder = encoder; dp->plat_data.encoder = encoder;
return analogix_dp_bind(dev, dp->drm_dev, &dp->plat_data); dp->adp = analogix_dp_bind(dev, dp->drm_dev, &dp->plat_data);
if (IS_ERR(dp->adp))
return PTR_ERR(dp->adp);
return 0;
} }
static void exynos_dp_unbind(struct device *dev, struct device *master, static void exynos_dp_unbind(struct device *dev, struct device *master,
void *data) void *data)
{ {
return analogix_dp_unbind(dev, master, data); struct exynos_dp_device *dp = dev_get_drvdata(dev);
return analogix_dp_unbind(dp->adp);
} }
static const struct component_ops exynos_dp_ops = { static const struct component_ops exynos_dp_ops = {
...@@ -257,12 +257,16 @@ static int exynos_dp_remove(struct platform_device *pdev) ...@@ -257,12 +257,16 @@ static int exynos_dp_remove(struct platform_device *pdev)
#ifdef CONFIG_PM #ifdef CONFIG_PM
static int exynos_dp_suspend(struct device *dev) static int exynos_dp_suspend(struct device *dev)
{ {
return analogix_dp_suspend(dev); struct exynos_dp_device *dp = dev_get_drvdata(dev);
return analogix_dp_suspend(dp->adp);
} }
static int exynos_dp_resume(struct device *dev) static int exynos_dp_resume(struct device *dev)
{ {
return analogix_dp_resume(dev); struct exynos_dp_device *dp = dev_get_drvdata(dev);
return analogix_dp_resume(dp->adp);
} }
#endif #endif
......
...@@ -77,6 +77,7 @@ struct rockchip_dp_device { ...@@ -77,6 +77,7 @@ struct rockchip_dp_device {
const struct rockchip_dp_chip_data *data; const struct rockchip_dp_chip_data *data;
struct analogix_dp_device *adp;
struct analogix_dp_plat_data plat_data; struct analogix_dp_plat_data plat_data;
}; };
...@@ -84,7 +85,7 @@ static void analogix_dp_psr_set(struct drm_encoder *encoder, bool enabled) ...@@ -84,7 +85,7 @@ static void analogix_dp_psr_set(struct drm_encoder *encoder, bool enabled)
{ {
struct rockchip_dp_device *dp = to_dp(encoder); struct rockchip_dp_device *dp = to_dp(encoder);
if (!analogix_dp_psr_supported(dp->dev)) if (!analogix_dp_psr_supported(dp->adp))
return; return;
DRM_DEV_DEBUG(dp->dev, "%s PSR...\n", enabled ? "Entry" : "Exit"); DRM_DEV_DEBUG(dp->dev, "%s PSR...\n", enabled ? "Entry" : "Exit");
...@@ -114,9 +115,9 @@ static void analogix_dp_psr_work(struct work_struct *work) ...@@ -114,9 +115,9 @@ static void analogix_dp_psr_work(struct work_struct *work)
mutex_lock(&dp->psr_lock); mutex_lock(&dp->psr_lock);
if (dp->psr_state == EDP_VSC_PSR_STATE_ACTIVE) if (dp->psr_state == EDP_VSC_PSR_STATE_ACTIVE)
analogix_dp_enable_psr(dp->dev); analogix_dp_enable_psr(dp->adp);
else else
analogix_dp_disable_psr(dp->dev); analogix_dp_disable_psr(dp->adp);
mutex_unlock(&dp->psr_lock); mutex_unlock(&dp->psr_lock);
} }
...@@ -334,13 +335,6 @@ static int rockchip_dp_bind(struct device *dev, struct device *master, ...@@ -334,13 +335,6 @@ static int rockchip_dp_bind(struct device *dev, struct device *master,
struct drm_device *drm_dev = data; struct drm_device *drm_dev = data;
int ret; int ret;
/*
* Just like the probe function said, we don't need the
* device drvrate anymore, we should leave the charge to
* analogix dp driver, set the device drvdata to NULL.
*/
dev_set_drvdata(dev, NULL);
dp_data = of_device_get_match_data(dev); dp_data = of_device_get_match_data(dev);
if (!dp_data) if (!dp_data)
return -ENODEV; return -ENODEV;
...@@ -367,7 +361,11 @@ static int rockchip_dp_bind(struct device *dev, struct device *master, ...@@ -367,7 +361,11 @@ static int rockchip_dp_bind(struct device *dev, struct device *master,
rockchip_drm_psr_register(&dp->encoder, analogix_dp_psr_set); rockchip_drm_psr_register(&dp->encoder, analogix_dp_psr_set);
return analogix_dp_bind(dev, dp->drm_dev, &dp->plat_data); dp->adp = analogix_dp_bind(dev, dp->drm_dev, &dp->plat_data);
if (IS_ERR(dp->adp))
return PTR_ERR(dp->adp);
return 0;
} }
static void rockchip_dp_unbind(struct device *dev, struct device *master, static void rockchip_dp_unbind(struct device *dev, struct device *master,
...@@ -376,8 +374,7 @@ static void rockchip_dp_unbind(struct device *dev, struct device *master, ...@@ -376,8 +374,7 @@ static void rockchip_dp_unbind(struct device *dev, struct device *master,
struct rockchip_dp_device *dp = dev_get_drvdata(dev); struct rockchip_dp_device *dp = dev_get_drvdata(dev);
rockchip_drm_psr_unregister(&dp->encoder); rockchip_drm_psr_unregister(&dp->encoder);
analogix_dp_unbind(dp->adp);
analogix_dp_unbind(dev, master, data);
} }
static const struct component_ops rockchip_dp_component_ops = { static const struct component_ops rockchip_dp_component_ops = {
...@@ -407,11 +404,6 @@ static int rockchip_dp_probe(struct platform_device *pdev) ...@@ -407,11 +404,6 @@ static int rockchip_dp_probe(struct platform_device *pdev)
if (ret < 0) if (ret < 0)
return ret; return ret;
/*
* We just use the drvdata until driver run into component
* add function, and then we would set drvdata to null, so
* that analogix dp driver could take charge of the drvdata.
*/
platform_set_drvdata(pdev, dp); platform_set_drvdata(pdev, dp);
return component_add(dev, &rockchip_dp_component_ops); return component_add(dev, &rockchip_dp_component_ops);
...@@ -424,10 +416,26 @@ static int rockchip_dp_remove(struct platform_device *pdev) ...@@ -424,10 +416,26 @@ static int rockchip_dp_remove(struct platform_device *pdev)
return 0; return 0;
} }
#ifdef CONFIG_PM_SLEEP
static int rockchip_dp_suspend(struct device *dev)
{
struct rockchip_dp_device *dp = dev_get_drvdata(dev);
return analogix_dp_suspend(dp->adp);
}
static int rockchip_dp_resume(struct device *dev)
{
struct rockchip_dp_device *dp = dev_get_drvdata(dev);
return analogix_dp_resume(dp->adp);
}
#endif
static const struct dev_pm_ops rockchip_dp_pm_ops = { static const struct dev_pm_ops rockchip_dp_pm_ops = {
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
.suspend = analogix_dp_suspend, .suspend = rockchip_dp_suspend,
.resume_early = analogix_dp_resume, .resume_early = rockchip_dp_resume,
#endif #endif
}; };
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include <drm/drm_crtc.h> #include <drm/drm_crtc.h>
struct analogix_dp_device;
enum analogix_dp_devtype { enum analogix_dp_devtype {
EXYNOS_DP, EXYNOS_DP,
RK3288_DP, RK3288_DP,
...@@ -38,16 +40,17 @@ struct analogix_dp_plat_data { ...@@ -38,16 +40,17 @@ struct analogix_dp_plat_data {
struct drm_connector *); struct drm_connector *);
}; };
int analogix_dp_psr_supported(struct device *dev); int analogix_dp_psr_supported(struct analogix_dp_device *dp);
int analogix_dp_enable_psr(struct device *dev); int analogix_dp_enable_psr(struct analogix_dp_device *dp);
int analogix_dp_disable_psr(struct device *dev); int analogix_dp_disable_psr(struct analogix_dp_device *dp);
int analogix_dp_resume(struct device *dev); int analogix_dp_resume(struct analogix_dp_device *dp);
int analogix_dp_suspend(struct device *dev); int analogix_dp_suspend(struct analogix_dp_device *dp);
int analogix_dp_bind(struct device *dev, struct drm_device *drm_dev, struct analogix_dp_device *
struct analogix_dp_plat_data *plat_data); analogix_dp_bind(struct device *dev, struct drm_device *drm_dev,
void analogix_dp_unbind(struct device *dev, struct device *master, void *data); struct analogix_dp_plat_data *plat_data);
void analogix_dp_unbind(struct analogix_dp_device *dp);
int analogix_dp_start_crc(struct drm_connector *connector); int analogix_dp_start_crc(struct drm_connector *connector);
int analogix_dp_stop_crc(struct drm_connector *connector); int analogix_dp_stop_crc(struct drm_connector *connector);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment