Commit cd829454 authored by Daniel Vetter's avatar Daniel Vetter

drm/aspeed: Use devm_drm_dev_alloc

As usual, we can drop the drm_dev_put() and need to embed the
drm_device. Since it's so few, also go right ahead and leave
drm_device->dev_private set to NULL, so that we always use the
container_of() upcast, which is faster anyway.
Acked-by: default avatarSam Ravnborg <sam@ravnborg.org>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
Cc: Joel Stanley <joel@jms.id.au>
Cc: Andrew Jeffery <andrew@aj.id.au>
Cc: linux-aspeed@lists.ozlabs.org
Cc: linux-arm-kernel@lists.infradead.org
Link: https://patchwork.freedesktop.org/patch/msgid/20200415074034.175360-56-daniel.vetter@ffwll.ch
parent e95d2f40
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <drm/drm_simple_kms_helper.h> #include <drm/drm_simple_kms_helper.h>
struct aspeed_gfx { struct aspeed_gfx {
struct drm_device drm;
void __iomem *base; void __iomem *base;
struct clk *clk; struct clk *clk;
struct reset_control *rst; struct reset_control *rst;
...@@ -13,6 +14,7 @@ struct aspeed_gfx { ...@@ -13,6 +14,7 @@ struct aspeed_gfx {
struct drm_simple_display_pipe pipe; struct drm_simple_display_pipe pipe;
struct drm_connector connector; struct drm_connector connector;
}; };
#define to_aspeed_gfx(x) container_of(x, struct aspeed_gfx, drm)
int aspeed_gfx_create_pipe(struct drm_device *drm); int aspeed_gfx_create_pipe(struct drm_device *drm);
int aspeed_gfx_create_output(struct drm_device *drm); int aspeed_gfx_create_output(struct drm_device *drm);
......
...@@ -231,7 +231,7 @@ static const uint32_t aspeed_gfx_formats[] = { ...@@ -231,7 +231,7 @@ static const uint32_t aspeed_gfx_formats[] = {
int aspeed_gfx_create_pipe(struct drm_device *drm) int aspeed_gfx_create_pipe(struct drm_device *drm)
{ {
struct aspeed_gfx *priv = drm->dev_private; struct aspeed_gfx *priv = to_aspeed_gfx(drm);
return drm_simple_display_pipe_init(drm, &priv->pipe, &aspeed_gfx_funcs, return drm_simple_display_pipe_init(drm, &priv->pipe, &aspeed_gfx_funcs,
aspeed_gfx_formats, aspeed_gfx_formats,
......
...@@ -77,7 +77,7 @@ static void aspeed_gfx_setup_mode_config(struct drm_device *drm) ...@@ -77,7 +77,7 @@ static void aspeed_gfx_setup_mode_config(struct drm_device *drm)
static irqreturn_t aspeed_gfx_irq_handler(int irq, void *data) static irqreturn_t aspeed_gfx_irq_handler(int irq, void *data)
{ {
struct drm_device *drm = data; struct drm_device *drm = data;
struct aspeed_gfx *priv = drm->dev_private; struct aspeed_gfx *priv = to_aspeed_gfx(drm);
u32 reg; u32 reg;
reg = readl(priv->base + CRT_CTRL1); reg = readl(priv->base + CRT_CTRL1);
...@@ -96,15 +96,10 @@ static irqreturn_t aspeed_gfx_irq_handler(int irq, void *data) ...@@ -96,15 +96,10 @@ static irqreturn_t aspeed_gfx_irq_handler(int irq, void *data)
static int aspeed_gfx_load(struct drm_device *drm) static int aspeed_gfx_load(struct drm_device *drm)
{ {
struct platform_device *pdev = to_platform_device(drm->dev); struct platform_device *pdev = to_platform_device(drm->dev);
struct aspeed_gfx *priv; struct aspeed_gfx *priv = to_aspeed_gfx(drm);
struct resource *res; struct resource *res;
int ret; int ret;
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
drm->dev_private = priv;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
priv->base = devm_ioremap_resource(drm->dev, res); priv->base = devm_ioremap_resource(drm->dev, res);
if (IS_ERR(priv->base)) if (IS_ERR(priv->base))
...@@ -187,8 +182,6 @@ static void aspeed_gfx_unload(struct drm_device *drm) ...@@ -187,8 +182,6 @@ static void aspeed_gfx_unload(struct drm_device *drm)
{ {
drm_kms_helper_poll_fini(drm); drm_kms_helper_poll_fini(drm);
drm_mode_config_cleanup(drm); drm_mode_config_cleanup(drm);
drm->dev_private = NULL;
} }
DEFINE_DRM_GEM_CMA_FOPS(fops); DEFINE_DRM_GEM_CMA_FOPS(fops);
...@@ -216,27 +209,26 @@ static const struct of_device_id aspeed_gfx_match[] = { ...@@ -216,27 +209,26 @@ static const struct of_device_id aspeed_gfx_match[] = {
static int aspeed_gfx_probe(struct platform_device *pdev) static int aspeed_gfx_probe(struct platform_device *pdev)
{ {
struct drm_device *drm; struct aspeed_gfx *priv;
int ret; int ret;
drm = drm_dev_alloc(&aspeed_gfx_driver, &pdev->dev); priv = devm_drm_dev_alloc(&pdev->dev, &aspeed_gfx_driver,
if (IS_ERR(drm)) struct aspeed_gfx, drm);
return PTR_ERR(drm); if (IS_ERR(priv))
return PTR_ERR(priv);
ret = aspeed_gfx_load(drm); ret = aspeed_gfx_load(&priv->drm);
if (ret) if (ret)
goto err_free; return ret;
ret = drm_dev_register(drm, 0); ret = drm_dev_register(&priv->drm, 0);
if (ret) if (ret)
goto err_unload; goto err_unload;
return 0; return 0;
err_unload: err_unload:
aspeed_gfx_unload(drm); aspeed_gfx_unload(&priv->drm);
err_free:
drm_dev_put(drm);
return ret; return ret;
} }
...@@ -247,7 +239,6 @@ static int aspeed_gfx_remove(struct platform_device *pdev) ...@@ -247,7 +239,6 @@ static int aspeed_gfx_remove(struct platform_device *pdev)
drm_dev_unregister(drm); drm_dev_unregister(drm);
aspeed_gfx_unload(drm); aspeed_gfx_unload(drm);
drm_dev_put(drm);
return 0; return 0;
} }
......
...@@ -28,7 +28,7 @@ static const struct drm_connector_funcs aspeed_gfx_connector_funcs = { ...@@ -28,7 +28,7 @@ static const struct drm_connector_funcs aspeed_gfx_connector_funcs = {
int aspeed_gfx_create_output(struct drm_device *drm) int aspeed_gfx_create_output(struct drm_device *drm)
{ {
struct aspeed_gfx *priv = drm->dev_private; struct aspeed_gfx *priv = to_aspeed_gfx(drm);
int ret; int ret;
priv->connector.dpms = DRM_MODE_DPMS_OFF; priv->connector.dpms = DRM_MODE_DPMS_OFF;
......
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