[PATCH v7 10/23] scsi: ufs: mediatek: Handle misc host voltage regulators

Nicolas Frattaroli posted 23 patches 1 month ago
There is a newer version of this series
[PATCH v7 10/23] scsi: ufs: mediatek: Handle misc host voltage regulators
Posted by Nicolas Frattaroli 1 month ago
MediaTek SoCs handled by this driver contain a per-SoC specific set of
miscellaneous supplies. These feed parts of the UFS controller silicon
inside the SoC, as opposed to the UFS card.

Add the necessary driver code to acquire these supplies using the
regulator bulk API. They should be kept on during suspend, so enable
them when acquiring.

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
---
 drivers/ufs/host/ufs-mediatek.c | 37 ++++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
index 9b7d7e4ba4ba..3282b2d2d498 100644
--- a/drivers/ufs/host/ufs-mediatek.c
+++ b/drivers/ufs/host/ufs-mediatek.c
@@ -40,6 +40,8 @@ static void _ufs_mtk_clk_scale(struct ufs_hba *hba, bool scale_up);
 
 struct ufs_mtk_soc_data {
 	bool has_avdd09;
+	u8 num_reg_names;
+	const char *const *reg_names;
 };
 
 static const struct ufs_dev_quirk ufs_mtk_dev_fixups[] = {
@@ -1188,8 +1190,21 @@ static int ufs_mtk_get_supplies(struct ufs_mtk_host *host)
 {
 	struct device *dev = host->hba->dev;
 	const struct ufs_mtk_soc_data *data = of_device_get_match_data(dev);
+	int ret;
+
+	if (!data)
+		return 0;
+
+	if (data->num_reg_names) {
+		ret = devm_regulator_bulk_get_enable(dev, data->num_reg_names,
+						     data->reg_names);
+		if (ret) {
+			dev_err(dev, "Failed to get misc regulators: %pe\n", ERR_PTR(ret));
+			return ret;
+		}
+	}
 
-	if (!data || !data->has_avdd09)
+	if (!data->has_avdd09)
 		return 0;
 
 	host->reg_avdd09 = devm_regulator_get_optional(dev, "avdd09");
@@ -2331,14 +2346,30 @@ static const struct ufs_hba_variant_ops ufs_hba_mtk_vops = {
 	.config_scsi_dev     = ufs_mtk_config_scsi_dev,
 };
 
+static const char *const ufs_mtk_regs_avdd12_avdd18[] = {
+	"avdd12", "avdd18"
+};
+
+static const char *const ufs_mtk_regs_avdd12_ckbuf_avdd18[] = {
+	"avdd12", "avdd12-ckbuf", "avdd18"
+};
+
 static const struct ufs_mtk_soc_data mt8183_data = {
 	.has_avdd09 = true,
+	.reg_names = ufs_mtk_regs_avdd12_avdd18,
+	.num_reg_names = ARRAY_SIZE(ufs_mtk_regs_avdd12_avdd18),
+};
+
+static const struct ufs_mtk_soc_data mt8192_8195_data = {
+	.has_avdd09 = false,
+	.reg_names = ufs_mtk_regs_avdd12_ckbuf_avdd18,
+	.num_reg_names = ARRAY_SIZE(ufs_mtk_regs_avdd12_ckbuf_avdd18),
 };
 
 static const struct of_device_id ufs_mtk_of_match[] = {
 	{ .compatible = "mediatek,mt8183-ufshci", .data = &mt8183_data },
-	{ .compatible = "mediatek,mt8192-ufshci" },
-	{ .compatible = "mediatek,mt8195-ufshci" },
+	{ .compatible = "mediatek,mt8192-ufshci", .data = &mt8192_8195_data },
+	{ .compatible = "mediatek,mt8195-ufshci", .data = &mt8192_8195_data },
 	{},
 };
 MODULE_DEVICE_TABLE(of, ufs_mtk_of_match);

-- 
2.53.0
Re: [PATCH v7 10/23] scsi: ufs: mediatek: Handle misc host voltage regulators
Posted by Peter Wang (王信友) 3 weeks ago
On Mon, 2026-02-16 at 14:37 +0100, Nicolas Frattaroli wrote:
> MediaTek SoCs handled by this driver contain a per-SoC specific set
> of
> miscellaneous supplies. These feed parts of the UFS controller
> silicon
> inside the SoC, as opposed to the UFS card.
> 
> Add the necessary driver code to acquire these supplies using the
> regulator bulk API. They should be kept on during suspend, so enable
> them when acquiring.
> 
> Reviewed-by: AngeloGioacchino Del Regno
> <angelogioacchino.delregno@collabora.com>
> Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>

Reviewed-by: Peter Wang <peter.wang@mediatek.com>

Re: [PATCH v7 10/23] scsi: ufs: mediatek: Handle misc host voltage regulators
Posted by Peter Wang (王信友) 3 weeks, 1 day ago
On Mon, 2026-02-16 at 14:37 +0100, Nicolas Frattaroli wrote:
> @@ -1188,8 +1190,21 @@ static int ufs_mtk_get_supplies(struct
> ufs_mtk_host *host)
>  {
>  	struct device *dev = host->hba->dev;
>  	const struct ufs_mtk_soc_data *data =
> of_device_get_match_data(dev);
> +	int ret;
> +
> +	if (!data)
> +		return 0;
> +
> +	if (data->num_reg_names) {
> +		ret = devm_regulator_bulk_get_enable(dev, data-
> >num_reg_names,
> +						     data-
> >reg_names);

Hi Nicolas,

If these regulators are only acquired and enabled once,
why not just set regulator-always-on in the device tree?

Thanks
Peter

Re: [PATCH v7 10/23] scsi: ufs: mediatek: Handle misc host voltage regulators
Posted by Mark Brown 3 weeks, 1 day ago
On Tue, Feb 24, 2026 at 12:38:50PM +0000, Peter Wang (王信友) wrote:
> On Mon, 2026-02-16 at 14:37 +0100, Nicolas Frattaroli wrote:

> > +	if (data->num_reg_names) {
> > +		ret = devm_regulator_bulk_get_enable(dev, data-
> > >num_reg_names,
> > +						     data-
> > >reg_names);

> If these regulators are only acquired and enabled once,
> why not just set regulator-always-on in the device tree?

Drivers should request and enable any regulators they require, they
should not rely on boards happening to enable a supply for them.
Similarly the board should only impose constraints that come from the
system design, it should not assume that drivers will continue to behave
as they do.
Re: [PATCH v7 10/23] scsi: ufs: mediatek: Handle misc host voltage regulators
Posted by Peter Wang (王信友) 3 weeks ago
On Tue, 2026-02-24 at 12:48 +0000, Mark Brown wrote:
> Drivers should request and enable any regulators they require, they
> should not rely on boards happening to enable a supply for them.
> Similarly the board should only impose constraints that come from the
> system design, it should not assume that drivers will continue to
> behave
> as they do.


Hi Mark,

Thank you for your detailed explanation.

Peter

Re: [PATCH v7 10/23] scsi: ufs: mediatek: Handle misc host voltage regulators
Posted by AngeloGioacchino Del Regno 3 weeks, 1 day ago
Il 24/02/26 13:38, Peter Wang (王信友) ha scritto:
> On Mon, 2026-02-16 at 14:37 +0100, Nicolas Frattaroli wrote:
>> @@ -1188,8 +1190,21 @@ static int ufs_mtk_get_supplies(struct
>> ufs_mtk_host *host)
>>   {
>>   	struct device *dev = host->hba->dev;
>>   	const struct ufs_mtk_soc_data *data =
>> of_device_get_match_data(dev);
>> +	int ret;
>> +
>> +	if (!data)
>> +		return 0;
>> +
>> +	if (data->num_reg_names) {
>> +		ret = devm_regulator_bulk_get_enable(dev, data-
>>> num_reg_names,
>> +						     data-
>>> reg_names);
> 
> Hi Nicolas,
> 
> If these regulators are only acquired and enabled once,
> why not just set regulator-always-on in the device tree?
> 

Because:
  1. The UFS driver has to acquire the correct supplies regardless of them
     being on, guaranteeing both a readable power tree (sysfs/debugfs) and
     a correct hardware description in devicetree.
  2. A future update might get those regulators disabled during deep sleep

Regards,
Angelo

> Thanks
> Peter
> 

Re: [PATCH v7 10/23] scsi: ufs: mediatek: Handle misc host voltage regulators
Posted by Peter Wang (王信友) 3 weeks ago
On Tue, 2026-02-24 at 13:41 +0100, AngeloGioacchino Del Regno wrote
> 
> 
> Because:
>   1. The UFS driver has to acquire the correct supplies regardless of
> them
>      being on, guaranteeing both a readable power tree
> (sysfs/debugfs) and
>      a correct hardware description in devicetree.
>   2. A future update might get those regulators disabled during deep
> sleep
> 
> Regards,
> Angelo
> 

Hi Nicolas,

Okay, providing correct supplies and hardware descriptions is welcome,
but I am afraid these regulators cannot be disabled even when entering
deep sleep.

Thanks
Peter
>