Commit 2bb98fc1 authored by Philipp Stanner's avatar Philipp Stanner Committed by Laurentiu Palcu

drm/imx/dcss: have all init functions use devres

dcss currently allocates and ioremaps quite a few resources in its probe
function's call graph. Devres now provides convenient functions which
perform the same task but do the cleanup automatically.

Port all memory allocations and ioremap() calls to the devres
counterparts.
Signed-off-by: default avatarPhilipp Stanner <pstanner@redhat.com>
Reviewed-by: default avatarLaurentiu Palcu <laurentiu.palcu@oss.nxp.com>
Signed-off-by: default avatarLaurentiu Palcu <laurentiu.palcu@oss.nxp.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240124111904.18261-4-pstanner@redhat.com
parent 90393c9b
...@@ -42,14 +42,13 @@ int dcss_blkctl_init(struct dcss_dev *dcss, unsigned long blkctl_base) ...@@ -42,14 +42,13 @@ int dcss_blkctl_init(struct dcss_dev *dcss, unsigned long blkctl_base)
{ {
struct dcss_blkctl *blkctl; struct dcss_blkctl *blkctl;
blkctl = kzalloc(sizeof(*blkctl), GFP_KERNEL); blkctl = devm_kzalloc(dcss->dev, sizeof(*blkctl), GFP_KERNEL);
if (!blkctl) if (!blkctl)
return -ENOMEM; return -ENOMEM;
blkctl->base_reg = ioremap(blkctl_base, SZ_4K); blkctl->base_reg = devm_ioremap(dcss->dev, blkctl_base, SZ_4K);
if (!blkctl->base_reg) { if (!blkctl->base_reg) {
dev_err(dcss->dev, "unable to remap BLK CTRL base\n"); dev_err(dcss->dev, "unable to remap BLK CTRL base\n");
kfree(blkctl);
return -ENOMEM; return -ENOMEM;
} }
...@@ -60,11 +59,3 @@ int dcss_blkctl_init(struct dcss_dev *dcss, unsigned long blkctl_base) ...@@ -60,11 +59,3 @@ int dcss_blkctl_init(struct dcss_dev *dcss, unsigned long blkctl_base)
return 0; return 0;
} }
void dcss_blkctl_exit(struct dcss_blkctl *blkctl)
{
if (blkctl->base_reg)
iounmap(blkctl->base_reg);
kfree(blkctl);
}
...@@ -202,7 +202,7 @@ int dcss_ctxld_init(struct dcss_dev *dcss, unsigned long ctxld_base) ...@@ -202,7 +202,7 @@ int dcss_ctxld_init(struct dcss_dev *dcss, unsigned long ctxld_base)
struct dcss_ctxld *ctxld; struct dcss_ctxld *ctxld;
int ret; int ret;
ctxld = kzalloc(sizeof(*ctxld), GFP_KERNEL); ctxld = devm_kzalloc(dcss->dev, sizeof(*ctxld), GFP_KERNEL);
if (!ctxld) if (!ctxld)
return -ENOMEM; return -ENOMEM;
...@@ -217,7 +217,7 @@ int dcss_ctxld_init(struct dcss_dev *dcss, unsigned long ctxld_base) ...@@ -217,7 +217,7 @@ int dcss_ctxld_init(struct dcss_dev *dcss, unsigned long ctxld_base)
goto err; goto err;
} }
ctxld->ctxld_reg = ioremap(ctxld_base, SZ_4K); ctxld->ctxld_reg = devm_ioremap(dcss->dev, ctxld_base, SZ_4K);
if (!ctxld->ctxld_reg) { if (!ctxld->ctxld_reg) {
dev_err(dcss->dev, "ctxld: unable to remap ctxld base\n"); dev_err(dcss->dev, "ctxld: unable to remap ctxld base\n");
ret = -ENOMEM; ret = -ENOMEM;
...@@ -226,18 +226,14 @@ int dcss_ctxld_init(struct dcss_dev *dcss, unsigned long ctxld_base) ...@@ -226,18 +226,14 @@ int dcss_ctxld_init(struct dcss_dev *dcss, unsigned long ctxld_base)
ret = dcss_ctxld_irq_config(ctxld, to_platform_device(dcss->dev)); ret = dcss_ctxld_irq_config(ctxld, to_platform_device(dcss->dev));
if (ret) if (ret)
goto err_irq; goto err;
dcss_ctxld_hw_cfg(ctxld); dcss_ctxld_hw_cfg(ctxld);
return 0; return 0;
err_irq:
iounmap(ctxld->ctxld_reg);
err: err:
dcss_ctxld_free_ctx(ctxld); dcss_ctxld_free_ctx(ctxld);
kfree(ctxld);
return ret; return ret;
} }
...@@ -246,11 +242,7 @@ void dcss_ctxld_exit(struct dcss_ctxld *ctxld) ...@@ -246,11 +242,7 @@ void dcss_ctxld_exit(struct dcss_ctxld *ctxld)
{ {
free_irq(ctxld->irq, ctxld); free_irq(ctxld->irq, ctxld);
if (ctxld->ctxld_reg)
iounmap(ctxld->ctxld_reg);
dcss_ctxld_free_ctx(ctxld); dcss_ctxld_free_ctx(ctxld);
kfree(ctxld);
} }
static int dcss_ctxld_enable_locked(struct dcss_ctxld *ctxld) static int dcss_ctxld_enable_locked(struct dcss_ctxld *ctxld)
......
...@@ -109,8 +109,6 @@ static int dcss_submodules_init(struct dcss_dev *dcss) ...@@ -109,8 +109,6 @@ static int dcss_submodules_init(struct dcss_dev *dcss)
dcss_ctxld_exit(dcss->ctxld); dcss_ctxld_exit(dcss->ctxld);
ctxld_err: ctxld_err:
dcss_blkctl_exit(dcss->blkctl);
dcss_clocks_disable(dcss); dcss_clocks_disable(dcss);
return ret; return ret;
...@@ -124,7 +122,6 @@ static void dcss_submodules_stop(struct dcss_dev *dcss) ...@@ -124,7 +122,6 @@ static void dcss_submodules_stop(struct dcss_dev *dcss)
dcss_ss_exit(dcss->ss); dcss_ss_exit(dcss->ss);
dcss_dtg_exit(dcss->dtg); dcss_dtg_exit(dcss->dtg);
dcss_ctxld_exit(dcss->ctxld); dcss_ctxld_exit(dcss->ctxld);
dcss_blkctl_exit(dcss->blkctl);
dcss_clocks_disable(dcss); dcss_clocks_disable(dcss);
} }
...@@ -190,7 +187,7 @@ struct dcss_dev *dcss_dev_create(struct device *dev, bool hdmi_output) ...@@ -190,7 +187,7 @@ struct dcss_dev *dcss_dev_create(struct device *dev, bool hdmi_output)
return ERR_PTR(-EBUSY); return ERR_PTR(-EBUSY);
} }
dcss = kzalloc(sizeof(*dcss), GFP_KERNEL); dcss = devm_kzalloc(dev, sizeof(*dcss), GFP_KERNEL);
if (!dcss) if (!dcss)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -201,7 +198,7 @@ struct dcss_dev *dcss_dev_create(struct device *dev, bool hdmi_output) ...@@ -201,7 +198,7 @@ struct dcss_dev *dcss_dev_create(struct device *dev, bool hdmi_output)
ret = dcss_clks_init(dcss); ret = dcss_clks_init(dcss);
if (ret) { if (ret) {
dev_err(dev, "clocks initialization failed\n"); dev_err(dev, "clocks initialization failed\n");
goto err; return ERR_PTR(ret);
} }
dcss->of_port = of_graph_get_port_by_id(dev->of_node, 0); dcss->of_port = of_graph_get_port_by_id(dev->of_node, 0);
...@@ -233,9 +230,6 @@ struct dcss_dev *dcss_dev_create(struct device *dev, bool hdmi_output) ...@@ -233,9 +230,6 @@ struct dcss_dev *dcss_dev_create(struct device *dev, bool hdmi_output)
clks_err: clks_err:
dcss_clks_release(dcss); dcss_clks_release(dcss);
err:
kfree(dcss);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
...@@ -253,8 +247,6 @@ void dcss_dev_destroy(struct dcss_dev *dcss) ...@@ -253,8 +247,6 @@ void dcss_dev_destroy(struct dcss_dev *dcss)
dcss_submodules_stop(dcss); dcss_submodules_stop(dcss);
dcss_clks_release(dcss); dcss_clks_release(dcss);
kfree(dcss);
} }
static int dcss_dev_suspend(struct device *dev) static int dcss_dev_suspend(struct device *dev)
......
...@@ -104,7 +104,6 @@ extern const struct dev_pm_ops dcss_dev_pm_ops; ...@@ -104,7 +104,6 @@ extern const struct dev_pm_ops dcss_dev_pm_ops;
/* BLKCTL */ /* BLKCTL */
int dcss_blkctl_init(struct dcss_dev *dcss, unsigned long blkctl_base); int dcss_blkctl_init(struct dcss_dev *dcss, unsigned long blkctl_base);
void dcss_blkctl_cfg(struct dcss_blkctl *blkctl); void dcss_blkctl_cfg(struct dcss_blkctl *blkctl);
void dcss_blkctl_exit(struct dcss_blkctl *blkctl);
/* CTXLD */ /* CTXLD */
int dcss_ctxld_init(struct dcss_dev *dcss, unsigned long ctxld_base); int dcss_ctxld_init(struct dcss_dev *dcss, unsigned long ctxld_base);
......
...@@ -135,7 +135,7 @@ static int dcss_dpr_ch_init_all(struct dcss_dpr *dpr, unsigned long dpr_base) ...@@ -135,7 +135,7 @@ static int dcss_dpr_ch_init_all(struct dcss_dpr *dpr, unsigned long dpr_base)
ch->base_ofs = dpr_base + i * 0x1000; ch->base_ofs = dpr_base + i * 0x1000;
ch->base_reg = ioremap(ch->base_ofs, SZ_4K); ch->base_reg = devm_ioremap(dpr->dev, ch->base_ofs, SZ_4K);
if (!ch->base_reg) { if (!ch->base_reg) {
dev_err(dpr->dev, "dpr: unable to remap ch %d base\n", dev_err(dpr->dev, "dpr: unable to remap ch %d base\n",
i); i);
...@@ -155,7 +155,7 @@ int dcss_dpr_init(struct dcss_dev *dcss, unsigned long dpr_base) ...@@ -155,7 +155,7 @@ int dcss_dpr_init(struct dcss_dev *dcss, unsigned long dpr_base)
{ {
struct dcss_dpr *dpr; struct dcss_dpr *dpr;
dpr = kzalloc(sizeof(*dpr), GFP_KERNEL); dpr = devm_kzalloc(dcss->dev, sizeof(*dpr), GFP_KERNEL);
if (!dpr) if (!dpr)
return -ENOMEM; return -ENOMEM;
...@@ -164,18 +164,8 @@ int dcss_dpr_init(struct dcss_dev *dcss, unsigned long dpr_base) ...@@ -164,18 +164,8 @@ int dcss_dpr_init(struct dcss_dev *dcss, unsigned long dpr_base)
dpr->ctxld = dcss->ctxld; dpr->ctxld = dcss->ctxld;
dpr->ctx_id = CTX_SB_HP; dpr->ctx_id = CTX_SB_HP;
if (dcss_dpr_ch_init_all(dpr, dpr_base)) { if (dcss_dpr_ch_init_all(dpr, dpr_base))
int i;
for (i = 0; i < 3; i++) {
if (dpr->ch[i].base_reg)
iounmap(dpr->ch[i].base_reg);
}
kfree(dpr);
return -ENOMEM; return -ENOMEM;
}
return 0; return 0;
} }
...@@ -189,12 +179,7 @@ void dcss_dpr_exit(struct dcss_dpr *dpr) ...@@ -189,12 +179,7 @@ void dcss_dpr_exit(struct dcss_dpr *dpr)
struct dcss_dpr_ch *ch = &dpr->ch[ch_no]; struct dcss_dpr_ch *ch = &dpr->ch[ch_no];
dcss_writel(0, ch->base_reg + DCSS_DPR_SYSTEM_CTRL0); dcss_writel(0, ch->base_reg + DCSS_DPR_SYSTEM_CTRL0);
if (ch->base_reg)
iounmap(ch->base_reg);
} }
kfree(dpr);
} }
static u32 dcss_dpr_x_pix_wide_adjust(struct dcss_dpr_ch *ch, u32 pix_wide, static u32 dcss_dpr_x_pix_wide_adjust(struct dcss_dpr_ch *ch, u32 pix_wide,
......
...@@ -51,15 +51,13 @@ static int dcss_drv_platform_probe(struct platform_device *pdev) ...@@ -51,15 +51,13 @@ static int dcss_drv_platform_probe(struct platform_device *pdev)
of_node_put(remote); of_node_put(remote);
mdrv = kzalloc(sizeof(*mdrv), GFP_KERNEL); mdrv = devm_kzalloc(dev, sizeof(*mdrv), GFP_KERNEL);
if (!mdrv) if (!mdrv)
return -ENOMEM; return -ENOMEM;
mdrv->dcss = dcss_dev_create(dev, hdmi_output); mdrv->dcss = dcss_dev_create(dev, hdmi_output);
if (IS_ERR(mdrv->dcss)) { if (IS_ERR(mdrv->dcss))
err = PTR_ERR(mdrv->dcss); return PTR_ERR(mdrv->dcss);
goto err;
}
dev_set_drvdata(dev, mdrv); dev_set_drvdata(dev, mdrv);
...@@ -75,8 +73,6 @@ static int dcss_drv_platform_probe(struct platform_device *pdev) ...@@ -75,8 +73,6 @@ static int dcss_drv_platform_probe(struct platform_device *pdev)
dcss_shutoff: dcss_shutoff:
dcss_dev_destroy(mdrv->dcss); dcss_dev_destroy(mdrv->dcss);
err:
kfree(mdrv);
return err; return err;
} }
...@@ -86,8 +82,6 @@ static void dcss_drv_platform_remove(struct platform_device *pdev) ...@@ -86,8 +82,6 @@ static void dcss_drv_platform_remove(struct platform_device *pdev)
dcss_kms_detach(mdrv->kms); dcss_kms_detach(mdrv->kms);
dcss_dev_destroy(mdrv->dcss); dcss_dev_destroy(mdrv->dcss);
kfree(mdrv);
} }
static void dcss_drv_platform_shutdown(struct platform_device *pdev) static void dcss_drv_platform_shutdown(struct platform_device *pdev)
......
...@@ -152,7 +152,7 @@ int dcss_dtg_init(struct dcss_dev *dcss, unsigned long dtg_base) ...@@ -152,7 +152,7 @@ int dcss_dtg_init(struct dcss_dev *dcss, unsigned long dtg_base)
int ret = 0; int ret = 0;
struct dcss_dtg *dtg; struct dcss_dtg *dtg;
dtg = kzalloc(sizeof(*dtg), GFP_KERNEL); dtg = devm_kzalloc(dcss->dev, sizeof(*dtg), GFP_KERNEL);
if (!dtg) if (!dtg)
return -ENOMEM; return -ENOMEM;
...@@ -160,11 +160,10 @@ int dcss_dtg_init(struct dcss_dev *dcss, unsigned long dtg_base) ...@@ -160,11 +160,10 @@ int dcss_dtg_init(struct dcss_dev *dcss, unsigned long dtg_base)
dtg->dev = dcss->dev; dtg->dev = dcss->dev;
dtg->ctxld = dcss->ctxld; dtg->ctxld = dcss->ctxld;
dtg->base_reg = ioremap(dtg_base, SZ_4K); dtg->base_reg = devm_ioremap(dtg->dev, dtg_base, SZ_4K);
if (!dtg->base_reg) { if (!dtg->base_reg) {
dev_err(dcss->dev, "dtg: unable to remap dtg base\n"); dev_err(dtg->dev, "dtg: unable to remap dtg base\n");
ret = -ENOMEM; return -ENOMEM;
goto err_ioremap;
} }
dtg->base_ofs = dtg_base; dtg->base_ofs = dtg_base;
...@@ -175,17 +174,7 @@ int dcss_dtg_init(struct dcss_dev *dcss, unsigned long dtg_base) ...@@ -175,17 +174,7 @@ int dcss_dtg_init(struct dcss_dev *dcss, unsigned long dtg_base)
dtg->control_status |= OVL_DATA_MODE | BLENDER_VIDEO_ALPHA_SEL | dtg->control_status |= OVL_DATA_MODE | BLENDER_VIDEO_ALPHA_SEL |
((dtg->alpha << DEFAULT_FG_ALPHA_POS) & DEFAULT_FG_ALPHA_MASK); ((dtg->alpha << DEFAULT_FG_ALPHA_POS) & DEFAULT_FG_ALPHA_MASK);
ret = dcss_dtg_irq_config(dtg, to_platform_device(dcss->dev)); ret = dcss_dtg_irq_config(dtg, to_platform_device(dtg->dev));
if (ret)
goto err_irq;
return 0;
err_irq:
iounmap(dtg->base_reg);
err_ioremap:
kfree(dtg);
return ret; return ret;
} }
...@@ -193,11 +182,6 @@ int dcss_dtg_init(struct dcss_dev *dcss, unsigned long dtg_base) ...@@ -193,11 +182,6 @@ int dcss_dtg_init(struct dcss_dev *dcss, unsigned long dtg_base)
void dcss_dtg_exit(struct dcss_dtg *dtg) void dcss_dtg_exit(struct dcss_dtg *dtg)
{ {
free_irq(dtg->ctxld_kick_irq, dtg); free_irq(dtg->ctxld_kick_irq, dtg);
if (dtg->base_reg)
iounmap(dtg->base_reg);
kfree(dtg);
} }
void dcss_dtg_sync_set(struct dcss_dtg *dtg, struct videomode *vm) void dcss_dtg_sync_set(struct dcss_dtg *dtg, struct videomode *vm)
......
...@@ -302,7 +302,7 @@ static int dcss_scaler_ch_init_all(struct dcss_scaler *scl, ...@@ -302,7 +302,7 @@ static int dcss_scaler_ch_init_all(struct dcss_scaler *scl,
ch->base_ofs = scaler_base + i * 0x400; ch->base_ofs = scaler_base + i * 0x400;
ch->base_reg = ioremap(ch->base_ofs, SZ_4K); ch->base_reg = devm_ioremap(scl->dev, ch->base_ofs, SZ_4K);
if (!ch->base_reg) { if (!ch->base_reg) {
dev_err(scl->dev, "scaler: unable to remap ch base\n"); dev_err(scl->dev, "scaler: unable to remap ch base\n");
return -ENOMEM; return -ENOMEM;
...@@ -318,7 +318,7 @@ int dcss_scaler_init(struct dcss_dev *dcss, unsigned long scaler_base) ...@@ -318,7 +318,7 @@ int dcss_scaler_init(struct dcss_dev *dcss, unsigned long scaler_base)
{ {
struct dcss_scaler *scaler; struct dcss_scaler *scaler;
scaler = kzalloc(sizeof(*scaler), GFP_KERNEL); scaler = devm_kzalloc(dcss->dev, sizeof(*scaler), GFP_KERNEL);
if (!scaler) if (!scaler)
return -ENOMEM; return -ENOMEM;
...@@ -327,18 +327,8 @@ int dcss_scaler_init(struct dcss_dev *dcss, unsigned long scaler_base) ...@@ -327,18 +327,8 @@ int dcss_scaler_init(struct dcss_dev *dcss, unsigned long scaler_base)
scaler->ctxld = dcss->ctxld; scaler->ctxld = dcss->ctxld;
scaler->ctx_id = CTX_SB_HP; scaler->ctx_id = CTX_SB_HP;
if (dcss_scaler_ch_init_all(scaler, scaler_base)) { if (dcss_scaler_ch_init_all(scaler, scaler_base))
int i;
for (i = 0; i < 3; i++) {
if (scaler->ch[i].base_reg)
iounmap(scaler->ch[i].base_reg);
}
kfree(scaler);
return -ENOMEM; return -ENOMEM;
}
return 0; return 0;
} }
...@@ -351,12 +341,7 @@ void dcss_scaler_exit(struct dcss_scaler *scl) ...@@ -351,12 +341,7 @@ void dcss_scaler_exit(struct dcss_scaler *scl)
struct dcss_scaler_ch *ch = &scl->ch[ch_no]; struct dcss_scaler_ch *ch = &scl->ch[ch_no];
dcss_writel(0, ch->base_reg + DCSS_SCALER_CTRL); dcss_writel(0, ch->base_reg + DCSS_SCALER_CTRL);
if (ch->base_reg)
iounmap(ch->base_reg);
} }
kfree(scl);
} }
void dcss_scaler_ch_enable(struct dcss_scaler *scl, int ch_num, bool en) void dcss_scaler_ch_enable(struct dcss_scaler *scl, int ch_num, bool en)
......
...@@ -83,7 +83,7 @@ int dcss_ss_init(struct dcss_dev *dcss, unsigned long ss_base) ...@@ -83,7 +83,7 @@ int dcss_ss_init(struct dcss_dev *dcss, unsigned long ss_base)
{ {
struct dcss_ss *ss; struct dcss_ss *ss;
ss = kzalloc(sizeof(*ss), GFP_KERNEL); ss = devm_kzalloc(dcss->dev, sizeof(*ss), GFP_KERNEL);
if (!ss) if (!ss)
return -ENOMEM; return -ENOMEM;
...@@ -91,10 +91,9 @@ int dcss_ss_init(struct dcss_dev *dcss, unsigned long ss_base) ...@@ -91,10 +91,9 @@ int dcss_ss_init(struct dcss_dev *dcss, unsigned long ss_base)
ss->dev = dcss->dev; ss->dev = dcss->dev;
ss->ctxld = dcss->ctxld; ss->ctxld = dcss->ctxld;
ss->base_reg = ioremap(ss_base, SZ_4K); ss->base_reg = devm_ioremap(ss->dev, ss_base, SZ_4K);
if (!ss->base_reg) { if (!ss->base_reg) {
dev_err(dcss->dev, "ss: unable to remap ss base\n"); dev_err(ss->dev, "ss: unable to remap ss base\n");
kfree(ss);
return -ENOMEM; return -ENOMEM;
} }
...@@ -108,11 +107,6 @@ void dcss_ss_exit(struct dcss_ss *ss) ...@@ -108,11 +107,6 @@ void dcss_ss_exit(struct dcss_ss *ss)
{ {
/* stop SS */ /* stop SS */
dcss_writel(0, ss->base_reg + DCSS_SS_SYS_CTRL); dcss_writel(0, ss->base_reg + DCSS_SS_SYS_CTRL);
if (ss->base_reg)
iounmap(ss->base_reg);
kfree(ss);
} }
void dcss_ss_subsam_set(struct dcss_ss *ss) void dcss_ss_subsam_set(struct dcss_ss *ss)
......
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