From patchwork Wed Nov 1 17:20:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 740851 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 55FD5C4167D for ; Wed, 1 Nov 2023 17:20:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344639AbjKARU6 (ORCPT ); Wed, 1 Nov 2023 13:20:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344693AbjKARU5 (ORCPT ); Wed, 1 Nov 2023 13:20:57 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C42513A; Wed, 1 Nov 2023 10:20:25 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-99c3c8adb27so5743566b.1; Wed, 01 Nov 2023 10:20:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698859223; x=1699464023; 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=MES5GqV7TrvEk7NAdheCC8mL6C1jpFNBBuLO0wdyWF0=; b=XEqWZ+GTzlUj56YMsjGKZlADA+MwhnmiOQfjH63Ug/we8T7c2wAFKH6lqgLMHE80LO J7coDU2UsxflkyIcmMSBcHRAG6xx5ftz2ZoFinN5hQvblND8cdWseExVdIP5KpEG8M/s VCAyZVkfjPLERVcXkpBp3O4Q28w+oPNP3jvs0f6AZjfJLQ5vEz7kk5FeVshXTT1v1SyO UZbYB6ub/asXXEDaWSKvP6mTlUUcd5R2FX5wNnrkE29cNCS0CPdI7dbPfiJ6lKz0fLPs s4KPtCtH/uuG8GLHsE9pljJGzf7RA+B2n3mZAO9LRGt8+yKGIZP3PWYQiXUo8up62Wus tCAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698859223; x=1699464023; 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=MES5GqV7TrvEk7NAdheCC8mL6C1jpFNBBuLO0wdyWF0=; b=iX5NdM/beMkFpIeDD74csd37iAbcm70il4z1ARGWR9QSN279WZIoFpxa7SyFkO1zcR em8OFrvHnjT0fRRg6U1wFAWtVop8OVFS8rx+rEGNEAyDcynX0Xcm2+xaHVQLp3AWDEoJ NPc10DxYFXpqlZOXzRHy6ppYYHI7rFYq3d5K9pLVdhpYTqAleCYMHDUDPVpU4srIWrgQ /OD9bh9QwVuTGDUlWtMO2EXCPAsp5X2elbcJrTDFjQ97oZZjzMwm9jmGu7eHi4NfEvYa Q56UHt7Pkn3SPlLVZiSj8zRj+Cb8muWWpEukOcgKUt81nyKD4bGBh9rv71x0L7o25dFJ 9VxQ== X-Gm-Message-State: AOJu0Yw4P9wQlNb72E2dvGr+yy/afGPdVtlMjOXph+QxzS1nsxqROCYL YUxuCeymqJpi+coEiceajO4+mTsbZhU= X-Google-Smtp-Source: AGHT+IGz0MS81PMDRbPIhLnqVUjvRxWV5C5P9/qd8vePmVYHlptWcpeqp+orYnQX/HZMMyiyB1u7hw== X-Received: by 2002:a17:906:fe45:b0:9ad:e298:a5d with SMTP id wz5-20020a170906fe4500b009ade2980a5dmr3275899ejb.19.1698859223483; Wed, 01 Nov 2023 10:20:23 -0700 (PDT) Received: from localhost (p200300e41f3f4900f22f74fffe1f3a53.dip0.t-ipconnect.de. [2003:e4:1f3f:4900:f22f:74ff:fe1f:3a53]) by smtp.gmail.com with ESMTPSA id t24-20020a170906065800b009b2b47cd757sm167671ejb.9.2023.11.01.10.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 10:20:22 -0700 (PDT) From: Thierry Reding To: Hans de Goede , Helge Deller Cc: Robert Foss , Jon Hunter , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH v2 1/2] fbdev/simplefb: Support memory-region property Date: Wed, 1 Nov 2023 18:20:16 +0100 Message-ID: <20231101172017.3872242-2-thierry.reding@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231101172017.3872242-1-thierry.reding@gmail.com> References: <20231101172017.3872242-1-thierry.reding@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org From: Thierry Reding The simple-framebuffer bindings specify that the "memory-region" property can be used as an alternative to the "reg" property to define the framebuffer memory used by the display hardware. Implement support for this in the simplefb driver. Reviewed-by: Hans de Goede Signed-off-by: Thierry Reding --- drivers/video/fbdev/simplefb.c | 35 +++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c index 62f99f6fccd3..18025f34fde7 100644 --- a/drivers/video/fbdev/simplefb.c +++ b/drivers/video/fbdev/simplefb.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -121,12 +122,13 @@ struct simplefb_params { u32 height; u32 stride; struct simplefb_format *format; + struct resource memory; }; static int simplefb_parse_dt(struct platform_device *pdev, struct simplefb_params *params) { - struct device_node *np = pdev->dev.of_node; + struct device_node *np = pdev->dev.of_node, *mem; int ret; const char *format; int i; @@ -166,6 +168,23 @@ static int simplefb_parse_dt(struct platform_device *pdev, return -EINVAL; } + mem = of_parse_phandle(np, "memory-region", 0); + if (mem) { + ret = of_address_to_resource(mem, 0, ¶ms->memory); + if (ret < 0) { + dev_err(&pdev->dev, "failed to parse memory-region\n"); + of_node_put(mem); + return ret; + } + + if (of_property_present(np, "reg")) + dev_warn(&pdev->dev, "preferring \"memory-region\" over \"reg\" property\n"); + + of_node_put(mem); + } else { + memset(¶ms->memory, 0, sizeof(params->memory)); + } + return 0; } @@ -193,6 +212,8 @@ static int simplefb_parse_pd(struct platform_device *pdev, return -EINVAL; } + memset(¶ms->memory, 0, sizeof(params->memory)); + return 0; } @@ -431,10 +452,14 @@ static int simplefb_probe(struct platform_device *pdev) if (ret) return ret; - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) { - dev_err(&pdev->dev, "No memory resource\n"); - return -EINVAL; + if (params.memory.start == 0 && params.memory.end == 0) { + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(&pdev->dev, "No memory resource\n"); + return -EINVAL; + } + } else { + res = ¶ms.memory; } mem = request_mem_region(res->start, resource_size(res), "simplefb"); From patchwork Wed Nov 1 17:20:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 740240 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 CCC84C4332F for ; Wed, 1 Nov 2023 17:21:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344743AbjKARVD (ORCPT ); Wed, 1 Nov 2023 13:21:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344778AbjKARVB (ORCPT ); Wed, 1 Nov 2023 13:21:01 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1D1813E; Wed, 1 Nov 2023 10:20:26 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-98377c5d53eso6937666b.0; Wed, 01 Nov 2023 10:20:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698859225; x=1699464025; 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=YCWX20pm7NUxv4hyK070ttliGC4ogoFW2BX+CCQgl0k=; b=ENKqDS1ma7w4GONjM2BAmjXsmoo0O9fOOOLhT3DkDVb/kxfTyGigj/A/z3ZuFbslM+ dCoVo5gFmI+vbwNUkAEm0Rq216RcvrtqrL1iGfEH9SLPniYt2kEmBkEzIfwO1kNnmKoO oB0ShOzmB9lPznwFBJsuC69tUVPDhKOapAUA+UqWxtI7MRBJIsrochSKnU3zLeRIiJM6 YOGzw2JvsaiPgyw7gd1Mr5nOeBydSfROkiWZ7XJPvkL7eXgyHF2xI2GRh8BkisaLNc82 2m9qQqyx8RKILLHTcntZBOdlmi2wEXbjQBEOIotjwsNF3Gtm973twLUR1szcVBmHNiHP h7uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698859225; x=1699464025; 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=YCWX20pm7NUxv4hyK070ttliGC4ogoFW2BX+CCQgl0k=; b=N1byOcS5DlYEte74EvGuteQH/Z8jmQLXswI6fbbds4UK3ONVC7w1zCvFckw3F0ffhc WnIl0pP6VjtFGS2ioXm2O1II9ipskCpRPQDIwuFDNZZTZ1qTsn3YQFrYg6XATXw9kuHj 7IXa8zpm/1sGpggRZv8v30plWvVvFUaEMD3NQOQ6W0eDgH5bh9uTiymDMOny4nL86Fjd U6Jqc0z0HIPvo7cmxMDA7F8Y+WiK0RuF/Ko3zGJRh85e0ZSXhd125F+kD0d2lfDFKu3k BNtpqvoBCgik9qtBBgQEu15TK6o0dARqE51AF8C8Qtd8E7UsE+1lDzSyralQOukwo3qV GvhQ== X-Gm-Message-State: AOJu0YxlhH4kQPFEOqvi+WhSPxpN/Rnp4scFlzPLLp+uucAsPOkTyjpo Z6PuZl1AVDSvyngzIKPv31Sjto9hOp0= X-Google-Smtp-Source: AGHT+IELfHY0ppV6/oc/rv+QctOqXbA+B/dAZdJV4WnAElYHxcL5x8bScFtIyqNY3pUPUxYOY5G1GA== X-Received: by 2002:a17:907:6d16:b0:9be:d55a:81c3 with SMTP id sa22-20020a1709076d1600b009bed55a81c3mr2300010ejc.67.1698859225126; Wed, 01 Nov 2023 10:20:25 -0700 (PDT) Received: from localhost (p200300e41f3f4900f22f74fffe1f3a53.dip0.t-ipconnect.de. [2003:e4:1f3f:4900:f22f:74ff:fe1f:3a53]) by smtp.gmail.com with ESMTPSA id i18-20020a170906115200b009ad8acac02asm160956eja.172.2023.11.01.10.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 10:20:24 -0700 (PDT) From: Thierry Reding To: Hans de Goede , Helge Deller Cc: Robert Foss , Jon Hunter , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH v2 2/2] fbdev/simplefb: Add support for generic power-domains Date: Wed, 1 Nov 2023 18:20:17 +0100 Message-ID: <20231101172017.3872242-3-thierry.reding@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231101172017.3872242-1-thierry.reding@gmail.com> References: <20231101172017.3872242-1-thierry.reding@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org From: Thierry Reding The simple-framebuffer device tree bindings document the power-domains property, so make sure that simplefb supports it. This ensures that the power domains remain enabled as long as simplefb is active. v2: - remove unnecessary call to simplefb_detach_genpds() since that's already done automatically by devres - fix crash if power-domains property is missing in DT Signed-off-by: Thierry Reding --- drivers/video/fbdev/simplefb.c | 93 ++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c index 18025f34fde7..fe682af63827 100644 --- a/drivers/video/fbdev/simplefb.c +++ b/drivers/video/fbdev/simplefb.c @@ -25,6 +25,7 @@ #include #include #include +#include #include static const struct fb_fix_screeninfo simplefb_fix = { @@ -78,6 +79,11 @@ struct simplefb_par { unsigned int clk_count; struct clk **clks; #endif +#if defined CONFIG_OF && defined CONFIG_PM_GENERIC_DOMAINS + unsigned int num_genpds; + struct device **genpds; + struct device_link **genpd_links; +#endif #if defined CONFIG_OF && defined CONFIG_REGULATOR bool regulators_enabled; u32 regulator_count; @@ -432,6 +438,89 @@ static void simplefb_regulators_enable(struct simplefb_par *par, static void simplefb_regulators_destroy(struct simplefb_par *par) { } #endif +#if defined CONFIG_OF && defined CONFIG_PM_GENERIC_DOMAINS +static void simplefb_detach_genpds(void *res) +{ + struct simplefb_par *par = res; + unsigned int i = par->num_genpds; + + if (par->num_genpds <= 1) + return; + + while (i--) { + if (par->genpd_links[i]) + device_link_del(par->genpd_links[i]); + + if (!IS_ERR_OR_NULL(par->genpds[i])) + dev_pm_domain_detach(par->genpds[i], true); + } +} + +static int simplefb_attach_genpds(struct simplefb_par *par, + struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + unsigned int i; + int err; + + err = of_count_phandle_with_args(dev->of_node, "power-domains", + "#power-domain-cells"); + if (err < 0) { + dev_info(dev, "failed to parse power-domains: %d\n", err); + return err; + } + + par->num_genpds = err; + + /* + * Single power-domain devices are handled by the driver core, so + * nothing to do here. + */ + if (par->num_genpds <= 1) + return 0; + + par->genpds = devm_kcalloc(dev, par->num_genpds, sizeof(*par->genpds), + GFP_KERNEL); + if (!par->genpds) + return -ENOMEM; + + par->genpd_links = devm_kcalloc(dev, par->num_genpds, + sizeof(*par->genpd_links), + GFP_KERNEL); + if (!par->genpd_links) + return -ENOMEM; + + for (i = 0; i < par->num_genpds; i++) { + par->genpds[i] = dev_pm_domain_attach_by_id(dev, i); + if (IS_ERR(par->genpds[i])) { + err = PTR_ERR(par->genpds[i]); + if (err == -EPROBE_DEFER) { + simplefb_detach_genpds(par); + return err; + } + + dev_warn(dev, "failed to attach domain %u: %d\n", i, err); + continue; + } + + par->genpd_links[i] = device_link_add(dev, par->genpds[i], + DL_FLAG_STATELESS | + DL_FLAG_PM_RUNTIME | + DL_FLAG_RPM_ACTIVE); + if (!par->genpd_links[i]) + dev_warn(dev, "failed to link power-domain %u\n", i); + } + + return devm_add_action_or_reset(dev, simplefb_detach_genpds, par); +} +#else +static int simplefb_attach_genpds(struct simplefb_par *par, + struct platform_device *pdev) +{ + return 0; +} +#endif + static int simplefb_probe(struct platform_device *pdev) { int ret; @@ -518,6 +607,10 @@ static int simplefb_probe(struct platform_device *pdev) if (ret < 0) goto error_clocks; + ret = simplefb_attach_genpds(par, pdev); + if (ret < 0) + goto error_regulators; + simplefb_clocks_enable(par, pdev); simplefb_regulators_enable(par, pdev);