[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAPDyKFpAxkVgscMQpe2MZFCmNyaFq9YqiPQknLDf3CJ9zMdZ6g@mail.gmail.com>
Date: Tue, 11 Mar 2025 16:21:59 +0100
From: Ulf Hansson <ulf.hansson@...aro.org>
To: Michal Wilczynski <m.wilczynski@...sung.com>
Cc: robh@...nel.org, krzk+dt@...nel.org, conor+dt@...nel.org, drew@...7.com,
guoren@...nel.org, wefu@...hat.com, paul.walmsley@...ive.com,
palmer@...belt.com, aou@...s.berkeley.edu, alex@...ti.fr, jszhang@...nel.org,
m.szyprowski@...sung.com, linux-pm@...r.kernel.org,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-riscv@...ts.infradead.org
Subject: Re: [PATCH v7 4/5] pmdomain: thead: Add power-domain driver for TH1520
On Mon, 10 Mar 2025 at 10:02, Michal Wilczynski
<m.wilczynski@...sung.com> wrote:
>
> The T-Head TH1520 SoC contains multiple power islands that can be
> programmatically turned on and off using the AON (Always-On) protocol
> and a hardware mailbox [1]. The relevant mailbox driver has already been
> merged into the mainline kernel in commit 5d4d263e1c6b ("mailbox:
> Introduce support for T-head TH1520 Mailbox driver");
>
> Introduce a power-domain driver for the TH1520 SoC, which is using AON
> firmware protocol to communicate with E902 core through the hardware
> mailbox. This way it can send power on/off commands to the E902 core.
>
> The interaction with AUDIO power island e.g trying to turn it OFF proved
> to crash the firmware running on the E902 core. Introduce the workaround
> to disable interacting with the power island.
>
> Link: https://openbeagle.org/beaglev-ahead/beaglev-ahead/-/blob/main/docs/TH1520%20System%20User%20Manual.pdf [1]
>
> Signed-off-by: Michal Wilczynski <m.wilczynski@...sung.com>
> ---
[...]
> +
> +static int th1520_pd_probe(struct platform_device *pdev)
> +{
> + struct generic_pm_domain **domains;
> + struct genpd_onecell_data *pd_data;
> + struct th1520_aon_chan *aon_chan;
> + struct device *dev = &pdev->dev;
> + int i;
> +
> + aon_chan = th1520_aon_init(dev);
> + if (IS_ERR(aon_chan))
> + return dev_err_probe(dev, PTR_ERR(aon_chan),
> + "Failed to get AON channel\n");
> +
> + platform_set_drvdata(pdev, aon_chan);
> +
> + domains = devm_kcalloc(dev, ARRAY_SIZE(th1520_pd_ranges),
> + sizeof(*domains), GFP_KERNEL);
> + if (!domains)
> + return -ENOMEM;
> +
> + pd_data = devm_kzalloc(dev, sizeof(*pd_data), GFP_KERNEL);
> + if (!pd_data)
> + return -ENOMEM;
> +
> + for (i = 0; i < ARRAY_SIZE(th1520_pd_ranges); i++) {
> + struct th1520_power_domain *pd;
> +
> + if (th1520_pd_ranges[i].disabled)
> + continue;
> +
> + pd = th1520_add_pm_domain(dev, &th1520_pd_ranges[i]);
> + if (IS_ERR(pd))
> + return PTR_ERR(pd);
> +
> + pd->aon_chan = aon_chan;
> + domains[i] = &pd->genpd;
> + dev_dbg(dev, "added power domain %s\n", pd->genpd.name);
> + }
> +
> + pd_data->domains = domains;
> + pd_data->num_domains = ARRAY_SIZE(th1520_pd_ranges);
> + pd_data->xlate = th1520_pd_xlate;
> +
> + /*
> + * Initialize all power domains to off to ensure they start in a
> + * low-power state. This allows device drivers to manage power
> + * domains by turning them on or off as needed.
> + */
> + th1520_pd_init_all_off(domains, dev);
> +
> + return of_genpd_add_provider_onecell(dev->of_node, pd_data);
If this fails, we should clean-up properly, not just returning an error code.
> +}
> +
> +static void th1520_pd_remove(struct platform_device *pdev)
> +{
> + struct th1520_aon_chan *aon_chan = platform_get_drvdata(pdev);
> +
> + th1520_aon_deinit(aon_chan);
The genpd providers need to be cleaned-up here too.
Or, as I said before, if you think doing a proper clean-up is going to
be a problem (in most cases it is), we can also make this a
builtin_platform_driver() with "suppress_bind_attrs = true".
> +}
> +
> +static const struct of_device_id th1520_pd_match[] = {
> + { .compatible = "thead,th1520-aon" },
> + { /* Sentinel */ }
> +};
> +MODULE_DEVICE_TABLE(of, th1520_pd_match);
> +
> +static struct platform_driver th1520_pd_driver = {
> + .driver = {
> + .name = "th1520-pd",
> + .of_match_table = th1520_pd_match,
> + },
> + .probe = th1520_pd_probe,
> + .remove = th1520_pd_remove,
> +};
> +module_platform_driver(th1520_pd_driver);
> +
> +MODULE_AUTHOR("Michal Wilczynski <m.wilczynski@...sung.com>");
> +MODULE_DESCRIPTION("T-HEAD TH1520 SoC power domain controller");
> +MODULE_LICENSE("GPL");
> --
> 2.34.1
>
Kind regards
Uffe
Powered by blists - more mailing lists