From patchwork Mon Oct 9 17:48:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 731068 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFEE9CD6119 for ; Mon, 9 Oct 2023 17:48:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377059AbjJIRsr (ORCPT ); Mon, 9 Oct 2023 13:48:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377064AbjJIRsr (ORCPT ); Mon, 9 Oct 2023 13:48:47 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3263091 for ; Mon, 9 Oct 2023 10:48:45 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-505748580ceso6003553e87.3 for ; Mon, 09 Oct 2023 10:48:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696873723; x=1697478523; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/l++4rL4XecTw0084NzypTs/OyWZ9YQbmVr6dxqDns8=; b=gQcd0xBILs6wi1aIMZt9PavuNkWldB+hLXaRC/hP4leoxTS2/Cm/+oHqCLKFDQRaje u8zg6yQQE1RIi007+unJUmGj6EiCNr3IFtYsbT0s/UnsuE7TwZsFZ2IzQfYEQHyQ/Svv g8lwPr7gncqctbkHwe+/Y3TjmN6s3mbPrz5rOwyCM/YA3Zo48ll0nu7hiMQtT4hXzpaB NjhszWsO6KajAVYMxeh0fSykwup7MzPFxx0b/Nig3YsL6kkG296qD99Qu6NwZ7Kczh+0 YWz1dRAimoQ97jHqSTodnmY5hkLboOFtSl+sT1upntZL+R62mA5brpBeRpRynviIT2YI D+jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696873723; x=1697478523; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/l++4rL4XecTw0084NzypTs/OyWZ9YQbmVr6dxqDns8=; b=bvTlETU2UewdmyDizjktJ9OPf59WDlAC1MQllw36j8asVa271QZ/lEqqRx3om/s8Xp u0Tf0eAQc8hZmJtzbFW7x9/YeklWIIb7pP1o6Q7c1RZ5LZ+kkv6VvoKNrZqnCs3umjv/ 2ztf0UPejQOl/SRm1z1af8hqOZ+ViMGRQjDuqR/bvub6munYZVmDBcbObqIhUEDeKAfp KSczSzBB3Mz3e3T84kT8NI6WRXVNmjENyDLzjqo5MB9S23aZqzf+9l7NHy8en5w/Bmai SJdJa/4lJGV6k9a/w/QH8ywcb9YjrJRovyW0m79Yrt8araRST89ck4VhjNh+2nSHGpvZ W8Tg== X-Gm-Message-State: AOJu0YxUjAgZ5+JXvWq1VNYzRm0+HgHBRnQ86qk0x2SKSZDRb0vOZqs0 Fr033jZ6fa5iV1aTrl13fdQvvw== X-Google-Smtp-Source: AGHT+IFr+V//dps6ByBx5GuZ/rNQl7CcNW8Nb5WWC31PYVzPKhNmW+78kSg/S5Vqp/p2ljgU39nvNg== X-Received: by 2002:a05:6512:e96:b0:500:b3fe:916e with SMTP id bi22-20020a0565120e9600b00500b3fe916emr18247595lfb.2.1696873723425; Mon, 09 Oct 2023 10:48:43 -0700 (PDT) Received: from umbar.unikie.fi ([192.130.178.91]) by smtp.gmail.com with ESMTPSA id m23-20020ac24257000000b0050420eff124sm1495927lfl.152.2023.10.09.10.48.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 10:48:43 -0700 (PDT) From: Dmitry Baryshkov To: Rob Clark , Sean Paul , Abhinav Kumar , Marijn Suijten Cc: Stephen Boyd , David Airlie , Daniel Vetter , Bjorn Andersson , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org Subject: [PATCH v5 3/4] drm/msm/mdp4: move resource allocation to the _probe function Date: Mon, 9 Oct 2023 20:48:39 +0300 Message-Id: <20231009174840.2726861-4-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231009174840.2726861-1-dmitry.baryshkov@linaro.org> References: <20231009174840.2726861-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org 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 Reviewed-by: Rob Clark Signed-off-by: Dmitry Baryshkov --- drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c | 106 +++++++++++------------ 1 file changed, 51 insertions(+), 55 deletions(-) diff --git a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c index 807ca3961c5f..18735bbaf798 100644 --- a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c +++ b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c @@ -135,8 +135,6 @@ static void mdp4_destroy(struct msm_kms *kms) pm_runtime_disable(dev); mdp_kms_destroy(&mdp4_kms->base); - - kfree(mdp4_kms); } static const struct mdp_kms_funcs kms_funcs = { @@ -380,56 +378,27 @@ static int mdp4_kms_init(struct drm_device *dev) { struct platform_device *pdev = to_platform_device(dev->dev); struct msm_drm_private *priv = dev->dev_private; - struct mdp4_kms *mdp4_kms; + struct mdp4_kms *mdp4_kms = to_mdp4_kms(to_mdp_kms(priv->kms)); struct msm_kms *kms = NULL; struct msm_mmu *mmu; struct msm_gem_address_space *aspace; - int irq, ret; + int ret; u32 major, minor; unsigned long max_clk; /* TODO: Chips that aren't apq8064 have a 200 Mhz max_clk */ max_clk = 266667000; - mdp4_kms = kzalloc(sizeof(*mdp4_kms), GFP_KERNEL); - if (!mdp4_kms) { - DRM_DEV_ERROR(dev->dev, "failed to allocate kms\n"); - return -ENOMEM; - } - ret = mdp_kms_init(&mdp4_kms->base, &kms_funcs); if (ret) { DRM_DEV_ERROR(dev->dev, "failed to init kms\n"); goto fail; } - priv->kms = &mdp4_kms->base.base; kms = priv->kms; mdp4_kms->dev = dev; - mdp4_kms->mmio = msm_ioremap(pdev, NULL); - if (IS_ERR(mdp4_kms->mmio)) { - ret = PTR_ERR(mdp4_kms->mmio); - goto fail; - } - - irq = platform_get_irq(pdev, 0); - if (irq < 0) { - ret = irq; - goto fail; - } - - kms->irq = irq; - - /* NOTE: driver for this regulator still missing upstream.. use - * _get_exclusive() and ignore the error if it does not exist - * (and hope that the bootloader left it on for us) - */ - mdp4_kms->vdd = devm_regulator_get_exclusive(&pdev->dev, "vdd"); - if (IS_ERR(mdp4_kms->vdd)) - mdp4_kms->vdd = NULL; - if (mdp4_kms->vdd) { ret = regulator_enable(mdp4_kms->vdd); if (ret) { @@ -438,24 +407,6 @@ static int mdp4_kms_init(struct drm_device *dev) } } - mdp4_kms->clk = devm_clk_get(&pdev->dev, "core_clk"); - if (IS_ERR(mdp4_kms->clk)) { - DRM_DEV_ERROR(dev->dev, "failed to get core_clk\n"); - ret = PTR_ERR(mdp4_kms->clk); - goto fail; - } - - mdp4_kms->pclk = devm_clk_get(&pdev->dev, "iface_clk"); - if (IS_ERR(mdp4_kms->pclk)) - mdp4_kms->pclk = NULL; - - mdp4_kms->axi_clk = devm_clk_get(&pdev->dev, "bus_clk"); - if (IS_ERR(mdp4_kms->axi_clk)) { - DRM_DEV_ERROR(dev->dev, "failed to get axi_clk\n"); - ret = PTR_ERR(mdp4_kms->axi_clk); - goto fail; - } - clk_set_rate(mdp4_kms->clk, max_clk); read_mdp_hw_revision(mdp4_kms, &major, &minor); @@ -470,10 +421,9 @@ static int mdp4_kms_init(struct drm_device *dev) mdp4_kms->rev = minor; if (mdp4_kms->rev >= 2) { - mdp4_kms->lut_clk = devm_clk_get(&pdev->dev, "lut_clk"); - if (IS_ERR(mdp4_kms->lut_clk)) { + if (!mdp4_kms->lut_clk) { DRM_DEV_ERROR(dev->dev, "failed to get lut_clk\n"); - ret = PTR_ERR(mdp4_kms->lut_clk); + ret = -ENODEV; goto fail; } clk_set_rate(mdp4_kms->lut_clk, max_clk); @@ -557,7 +507,53 @@ static const struct dev_pm_ops mdp4_pm_ops = { static int mdp4_probe(struct platform_device *pdev) { - return msm_drv_probe(&pdev->dev, mdp4_kms_init, NULL); + struct device *dev = &pdev->dev; + struct mdp4_kms *mdp4_kms; + int irq; + + mdp4_kms = devm_kzalloc(dev, sizeof(*mdp4_kms), GFP_KERNEL); + if (!mdp4_kms) + return dev_err_probe(dev, -ENOMEM, "failed to allocate kms\n"); + + mdp4_kms->mmio = msm_ioremap(pdev, NULL); + if (IS_ERR(mdp4_kms->mmio)) + return PTR_ERR(mdp4_kms->mmio); + + irq = platform_get_irq(pdev, 0); + if (irq < 0) + return dev_err_probe(dev, irq, "failed to get irq\n"); + + mdp4_kms->base.base.irq = irq; + + /* NOTE: driver for this regulator still missing upstream.. use + * _get_exclusive() and ignore the error if it does not exist + * (and hope that the bootloader left it on for us) + */ + mdp4_kms->vdd = devm_regulator_get_exclusive(&pdev->dev, "vdd"); + if (IS_ERR(mdp4_kms->vdd)) + mdp4_kms->vdd = NULL; + + mdp4_kms->clk = devm_clk_get(&pdev->dev, "core_clk"); + if (IS_ERR(mdp4_kms->clk)) + return dev_err_probe(dev, PTR_ERR(mdp4_kms->clk), "failed to get core_clk\n"); + + mdp4_kms->pclk = devm_clk_get(&pdev->dev, "iface_clk"); + if (IS_ERR(mdp4_kms->pclk)) + mdp4_kms->pclk = NULL; + + mdp4_kms->axi_clk = devm_clk_get(&pdev->dev, "bus_clk"); + if (IS_ERR(mdp4_kms->axi_clk)) + return dev_err_probe(dev, PTR_ERR(mdp4_kms->axi_clk), "failed to get axi_clk\n"); + + /* + * This is required for revn >= 2. Handle errors here and let the kms + * init bail out if the clock is not provided. + */ + mdp4_kms->lut_clk = devm_clk_get_optional(&pdev->dev, "lut_clk"); + if (IS_ERR(mdp4_kms->lut_clk)) + return dev_err_probe(dev, PTR_ERR(mdp4_kms->lut_clk), "failed to get lut_clk\n"); + + return msm_drv_probe(&pdev->dev, mdp4_kms_init, &mdp4_kms->base.base); } static void mdp4_remove(struct platform_device *pdev)