Skip to content

Commit 3c74682

Browse files
lumagrobclark
authored andcommitted
drm/msm/mdp4: move resource allocation to the _probe function
To let the probe function bail early if any of the resources is unavailable, move resource allocattion from kms_init directly to the probe callback. While we are at it, replace irq_of_parse_and_map() with platform_get_irq(). Reviewed-by: Abhinav Kumar <quic_abhinavk@quicinc.com> Reviewed-by: Rob Clark <robdclark@gmail.com> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org> Patchwork: https://patchwork.freedesktop.org/patch/561628/ Signed-off-by: Rob Clark <robdclark@chromium.org>
1 parent c53a1ae commit 3c74682

1 file changed

Lines changed: 51 additions & 55 deletions

File tree

drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c

Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ static void mdp4_destroy(struct msm_kms *kms)
135135
pm_runtime_disable(dev);
136136

137137
mdp_kms_destroy(&mdp4_kms->base);
138-
139-
kfree(mdp4_kms);
140138
}
141139

142140
static const struct mdp_kms_funcs kms_funcs = {
@@ -380,56 +378,27 @@ static int mdp4_kms_init(struct drm_device *dev)
380378
{
381379
struct platform_device *pdev = to_platform_device(dev->dev);
382380
struct msm_drm_private *priv = dev->dev_private;
383-
struct mdp4_kms *mdp4_kms;
381+
struct mdp4_kms *mdp4_kms = to_mdp4_kms(to_mdp_kms(priv->kms));
384382
struct msm_kms *kms = NULL;
385383
struct msm_mmu *mmu;
386384
struct msm_gem_address_space *aspace;
387-
int irq, ret;
385+
int ret;
388386
u32 major, minor;
389387
unsigned long max_clk;
390388

391389
/* TODO: Chips that aren't apq8064 have a 200 Mhz max_clk */
392390
max_clk = 266667000;
393391

394-
mdp4_kms = kzalloc(sizeof(*mdp4_kms), GFP_KERNEL);
395-
if (!mdp4_kms) {
396-
DRM_DEV_ERROR(dev->dev, "failed to allocate kms\n");
397-
return -ENOMEM;
398-
}
399-
400392
ret = mdp_kms_init(&mdp4_kms->base, &kms_funcs);
401393
if (ret) {
402394
DRM_DEV_ERROR(dev->dev, "failed to init kms\n");
403395
goto fail;
404396
}
405397

406-
priv->kms = &mdp4_kms->base.base;
407398
kms = priv->kms;
408399

409400
mdp4_kms->dev = dev;
410401

411-
mdp4_kms->mmio = msm_ioremap(pdev, NULL);
412-
if (IS_ERR(mdp4_kms->mmio)) {
413-
ret = PTR_ERR(mdp4_kms->mmio);
414-
goto fail;
415-
}
416-
417-
irq = platform_get_irq(pdev, 0);
418-
if (irq < 0) {
419-
ret = irq;
420-
goto fail;
421-
}
422-
423-
kms->irq = irq;
424-
425-
/* NOTE: driver for this regulator still missing upstream.. use
426-
* _get_exclusive() and ignore the error if it does not exist
427-
* (and hope that the bootloader left it on for us)
428-
*/
429-
mdp4_kms->vdd = devm_regulator_get_exclusive(&pdev->dev, "vdd");
430-
if (IS_ERR(mdp4_kms->vdd))
431-
mdp4_kms->vdd = NULL;
432-
433402
if (mdp4_kms->vdd) {
434403
ret = regulator_enable(mdp4_kms->vdd);
435404
if (ret) {
@@ -438,24 +407,6 @@ static int mdp4_kms_init(struct drm_device *dev)
438407
}
439408
}
440409

441-
mdp4_kms->clk = devm_clk_get(&pdev->dev, "core_clk");
442-
if (IS_ERR(mdp4_kms->clk)) {
443-
DRM_DEV_ERROR(dev->dev, "failed to get core_clk\n");
444-
ret = PTR_ERR(mdp4_kms->clk);
445-
goto fail;
446-
}
447-
448-
mdp4_kms->pclk = devm_clk_get(&pdev->dev, "iface_clk");
449-
if (IS_ERR(mdp4_kms->pclk))
450-
mdp4_kms->pclk = NULL;
451-
452-
mdp4_kms->axi_clk = devm_clk_get(&pdev->dev, "bus_clk");
453-
if (IS_ERR(mdp4_kms->axi_clk)) {
454-
DRM_DEV_ERROR(dev->dev, "failed to get axi_clk\n");
455-
ret = PTR_ERR(mdp4_kms->axi_clk);
456-
goto fail;
457-
}
458-
459410
clk_set_rate(mdp4_kms->clk, max_clk);
460411

461412
read_mdp_hw_revision(mdp4_kms, &major, &minor);
@@ -470,10 +421,9 @@ static int mdp4_kms_init(struct drm_device *dev)
470421
mdp4_kms->rev = minor;
471422

472423
if (mdp4_kms->rev >= 2) {
473-
mdp4_kms->lut_clk = devm_clk_get(&pdev->dev, "lut_clk");
474-
if (IS_ERR(mdp4_kms->lut_clk)) {
424+
if (!mdp4_kms->lut_clk) {
475425
DRM_DEV_ERROR(dev->dev, "failed to get lut_clk\n");
476-
ret = PTR_ERR(mdp4_kms->lut_clk);
426+
ret = -ENODEV;
477427
goto fail;
478428
}
479429
clk_set_rate(mdp4_kms->lut_clk, max_clk);
@@ -557,7 +507,53 @@ static const struct dev_pm_ops mdp4_pm_ops = {
557507

558508
static int mdp4_probe(struct platform_device *pdev)
559509
{
560-
return msm_drv_probe(&pdev->dev, mdp4_kms_init, NULL);
510+
struct device *dev = &pdev->dev;
511+
struct mdp4_kms *mdp4_kms;
512+
int irq;
513+
514+
mdp4_kms = devm_kzalloc(dev, sizeof(*mdp4_kms), GFP_KERNEL);
515+
if (!mdp4_kms)
516+
return dev_err_probe(dev, -ENOMEM, "failed to allocate kms\n");
517+
518+
mdp4_kms->mmio = msm_ioremap(pdev, NULL);
519+
if (IS_ERR(mdp4_kms->mmio))
520+
return PTR_ERR(mdp4_kms->mmio);
521+
522+
irq = platform_get_irq(pdev, 0);
523+
if (irq < 0)
524+
return dev_err_probe(dev, irq, "failed to get irq\n");
525+
526+
mdp4_kms->base.base.irq = irq;
527+
528+
/* NOTE: driver for this regulator still missing upstream.. use
529+
* _get_exclusive() and ignore the error if it does not exist
530+
* (and hope that the bootloader left it on for us)
531+
*/
532+
mdp4_kms->vdd = devm_regulator_get_exclusive(&pdev->dev, "vdd");
533+
if (IS_ERR(mdp4_kms->vdd))
534+
mdp4_kms->vdd = NULL;
535+
536+
mdp4_kms->clk = devm_clk_get(&pdev->dev, "core_clk");
537+
if (IS_ERR(mdp4_kms->clk))
538+
return dev_err_probe(dev, PTR_ERR(mdp4_kms->clk), "failed to get core_clk\n");
539+
540+
mdp4_kms->pclk = devm_clk_get(&pdev->dev, "iface_clk");
541+
if (IS_ERR(mdp4_kms->pclk))
542+
mdp4_kms->pclk = NULL;
543+
544+
mdp4_kms->axi_clk = devm_clk_get(&pdev->dev, "bus_clk");
545+
if (IS_ERR(mdp4_kms->axi_clk))
546+
return dev_err_probe(dev, PTR_ERR(mdp4_kms->axi_clk), "failed to get axi_clk\n");
547+
548+
/*
549+
* This is required for revn >= 2. Handle errors here and let the kms
550+
* init bail out if the clock is not provided.
551+
*/
552+
mdp4_kms->lut_clk = devm_clk_get_optional(&pdev->dev, "lut_clk");
553+
if (IS_ERR(mdp4_kms->lut_clk))
554+
return dev_err_probe(dev, PTR_ERR(mdp4_kms->lut_clk), "failed to get lut_clk\n");
555+
556+
return msm_drv_probe(&pdev->dev, mdp4_kms_init, &mdp4_kms->base.base);
561557
}
562558

563559
static int mdp4_remove(struct platform_device *pdev)

0 commit comments

Comments
 (0)