All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH u-boot 0/8] ufs: Sony Yoshino/Tama (MSM8998 / SDM845) UFS bring-up
@ 2026-10-04 19:22 ` Petr Hodina
  0 siblings, 0 replies; 26+ messages in thread
From: Petr Hodina via B4 Relay @ 2026-10-04 19:22 UTC (permalink / raw)
  To: u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	David Heidelberg, Marek Vasut, Padmarao Begari, Macpaul Lin,
	Julien Stephan, Kunihiko Hayashi, Shawn Lin, Jared McArthur,
	Michal Simek, Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata, Petr Hodina

This series brings up UFS on the Sony Xperia "Yoshino" (MSM8998) and
"Tama" (SDM845) families.

The work falls into four layers:

1. A small refactor that extends ufs_dev_desc with the product revision
   string and the UFS spec version (patch 1). No behaviour change.

2. A device-quirk infrastructure (patches 2-4) that lets us match
   per-device link / power-mode workarounds against manufacturer id,
   model and fw revision:

     - patch 2: generic ufs_fixups[] table and ufshcd_fixup_dev_quirks(),
       called from ufs_start() before power-mode negotiation
     - patch 3: UFS_DEVICE_QUIRK_EXTEND_SYNC_LENGTH for SK Hynix devices
       that need PA_TxHsG{1,2,3}SyncLength programmed to 0x48
     - patch 4: CONFIG_UFS_RESTRICT_TX_LANES build-time knob for boards
       with only a single reliable TX lane. Defaults to N so nothing
       else is affected.

3. The NO_PURGE quirk for devices that brick if issued PURGE / UNMAP
   (patches 5-7):

     - patch 5: refuse erase/UNMAP in the SCSI uclass when NO_PURGE
       is set on the underlying UFS device
     - patch 6: print device identification (vendor / model / rev /
       spec version) at probe so quirk matching is observable on the
       console
     - patch 7: a platform gate that auto-enables NO_PURGE on Sony
       Yoshino/Tama compatibles because per-UFS-chip rows can't see
       blank string descriptors on some affected boards.

4. Akatsuki DTS enablement (patch 8): re-enable the UFS controller node.

Background on NO_PURGE: on the affected Sony platforms the SCSI ERASE /
UNMAP / WRITE_BUFFER PURGE operation overwrites the bootloader region
and permanently bricks the device.

Based on the linux patches by Angelo:
https://github.com/kholk/kernel/commit/2e7a9ee1c91a016baa0b826a7752ec45663a0561

Tested on Sony XZ3 (akatsuki, SDM845) where U-Boot enumerates UFS LUN0
and exposes the GPT.

```
UFS Device Information (ufshc@1d84000)
  Manufacturer:    Samsung (0x01ce)
  Model:           (unset)
  Revision:        (unset)
  Spec Version:    0x0210
  Gear  - RX: 3, TX: 3
  Lane  - RX: 2, TX: 2
  Power - RX: 1, TX: 1, HS rate: 2
  Device Quirks:   0x00000001
  NO_PURGE Quirk:  Yes

...

=> scsi erase 0 1

scsi erase: device 0 block # 0, count 1 ... scsi_erase: erase not supported on this device
0 blocks erased: ERROR
=> 
```

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
Petr Hodina (8):
      ufs: read product revision and spec version into ufs_dev_desc
      ufs: add device-quirk infrastructure
      ufs: program extended HS sync length for SK Hynix devices
      ufs: add CONFIG_UFS_RESTRICT_TX_LANES
      scsi: ufs: refuse erase/UNMAP on NO_PURGE devices
      ufs: print device information at probe
      ufs: gate NO_PURGE on Sony Yoshino/Tama platform compatible
      arm: dts: qcom: akatsuki: re-enable the UFS controller node

 MAINTAINERS                                        |   1 +
 .../sdm845-sony-xperia-tama-akatsuki-u-boot.dtsi   |   9 +
 drivers/scsi/scsi.c                                |   5 +
 drivers/ufs/Kconfig                                |  14 ++
 drivers/ufs/ufs-uclass.c                           | 197 +++++++++++++++++++++
 drivers/ufs/ufs.h                                  |   7 +
 drivers/ufs/ufs_quirks.h                           |  94 ++++++++++
 drivers/ufs/unipro.h                               |   3 +
 include/scsi.h                                     |   5 +
 9 files changed, 335 insertions(+)
---
base-commit: ece349ade2973e220f524ce59e59711cc919263f
change-id: 20260611-b4-ufs-sony-794325f6f4af

Best regards,
--  
Petr Hodina <petr.hodina@protonmail.com>



^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH u-boot 0/8] ufs: Sony Yoshino/Tama (MSM8998 / SDM845) UFS bring-up
@ 2026-10-04 19:22 ` Petr Hodina
  0 siblings, 0 replies; 26+ messages in thread
From: Petr Hodina @ 2026-10-04 19:22 UTC (permalink / raw)
  To: u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	David Heidelberg, Marek Vasut, Padmarao Begari, Macpaul Lin,
	Julien Stephan, Kunihiko Hayashi, Shawn Lin, Jared McArthur,
	Michal Simek, Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata, Petr Hodina

This series brings up UFS on the Sony Xperia "Yoshino" (MSM8998) and
"Tama" (SDM845) families.

The work falls into four layers:

1. A small refactor that extends ufs_dev_desc with the product revision
   string and the UFS spec version (patch 1). No behaviour change.

2. A device-quirk infrastructure (patches 2-4) that lets us match
   per-device link / power-mode workarounds against manufacturer id,
   model and fw revision:

     - patch 2: generic ufs_fixups[] table and ufshcd_fixup_dev_quirks(),
       called from ufs_start() before power-mode negotiation
     - patch 3: UFS_DEVICE_QUIRK_EXTEND_SYNC_LENGTH for SK Hynix devices
       that need PA_TxHsG{1,2,3}SyncLength programmed to 0x48
     - patch 4: CONFIG_UFS_RESTRICT_TX_LANES build-time knob for boards
       with only a single reliable TX lane. Defaults to N so nothing
       else is affected.

3. The NO_PURGE quirk for devices that brick if issued PURGE / UNMAP
   (patches 5-7):

     - patch 5: refuse erase/UNMAP in the SCSI uclass when NO_PURGE
       is set on the underlying UFS device
     - patch 6: print device identification (vendor / model / rev /
       spec version) at probe so quirk matching is observable on the
       console
     - patch 7: a platform gate that auto-enables NO_PURGE on Sony
       Yoshino/Tama compatibles because per-UFS-chip rows can't see
       blank string descriptors on some affected boards.

4. Akatsuki DTS enablement (patch 8): re-enable the UFS controller node.

Background on NO_PURGE: on the affected Sony platforms the SCSI ERASE /
UNMAP / WRITE_BUFFER PURGE operation overwrites the bootloader region
and permanently bricks the device.

Based on the linux patches by Angelo:
https://github.com/kholk/kernel/commit/2e7a9ee1c91a016baa0b826a7752ec45663a0561

Tested on Sony XZ3 (akatsuki, SDM845) where U-Boot enumerates UFS LUN0
and exposes the GPT.

```
UFS Device Information (ufshc@1d84000)
  Manufacturer:    Samsung (0x01ce)
  Model:           (unset)
  Revision:        (unset)
  Spec Version:    0x0210
  Gear  - RX: 3, TX: 3
  Lane  - RX: 2, TX: 2
  Power - RX: 1, TX: 1, HS rate: 2
  Device Quirks:   0x00000001
  NO_PURGE Quirk:  Yes

...

=> scsi erase 0 1

scsi erase: device 0 block # 0, count 1 ... scsi_erase: erase not supported on this device
0 blocks erased: ERROR
=> 
```

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
Petr Hodina (8):
      ufs: read product revision and spec version into ufs_dev_desc
      ufs: add device-quirk infrastructure
      ufs: program extended HS sync length for SK Hynix devices
      ufs: add CONFIG_UFS_RESTRICT_TX_LANES
      scsi: ufs: refuse erase/UNMAP on NO_PURGE devices
      ufs: print device information at probe
      ufs: gate NO_PURGE on Sony Yoshino/Tama platform compatible
      arm: dts: qcom: akatsuki: re-enable the UFS controller node

 MAINTAINERS                                        |   1 +
 .../sdm845-sony-xperia-tama-akatsuki-u-boot.dtsi   |   9 +
 drivers/scsi/scsi.c                                |   5 +
 drivers/ufs/Kconfig                                |  14 ++
 drivers/ufs/ufs-uclass.c                           | 197 +++++++++++++++++++++
 drivers/ufs/ufs.h                                  |   7 +
 drivers/ufs/ufs_quirks.h                           |  94 ++++++++++
 drivers/ufs/unipro.h                               |   3 +
 include/scsi.h                                     |   5 +
 9 files changed, 335 insertions(+)
---
base-commit: ece349ade2973e220f524ce59e59711cc919263f
change-id: 20260611-b4-ufs-sony-794325f6f4af

Best regards,
--  
Petr Hodina <petr.hodina@protonmail.com>


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH u-boot 1/8] ufs: read product revision and spec version into ufs_dev_desc
  2026-10-04 19:22 ` Petr Hodina
@ 2026-10-04 19:22   ` Petr Hodina
  -1 siblings, 0 replies; 26+ messages in thread
From: Petr Hodina via B4 Relay @ 2026-10-04 19:22 UTC (permalink / raw)
  To: u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	David Heidelberg, Marek Vasut, Padmarao Begari, Macpaul Lin,
	Julien Stephan, Kunihiko Hayashi, Shawn Lin, Jared McArthur,
	Michal Simek, Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata, Petr Hodina

From: Petr Hodina <petr.hodina@protonmail.com>

Extend ufs_get_device_desc() to also fetch the device's product revision
string (PRDCT_REV) and the UFS spec version (SPEC_VER) into struct
ufs_dev_desc.

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
 drivers/ufs/ufs-uclass.c | 24 ++++++++++++++++++++++++
 drivers/ufs/ufs.h        |  5 +++++
 2 files changed, 29 insertions(+)

diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
index 6a51f337e47..56118a0ee46 100644
--- a/drivers/ufs/ufs-uclass.c
+++ b/drivers/ufs/ufs-uclass.c
@@ -1792,6 +1792,7 @@ static int ufs_get_device_desc(struct ufs_hba *hba,
 	int err;
 	size_t buff_len;
 	u8 model_index;
+	u8 revision_index;
 	u8 *desc_buf;
 
 	buff_len = max_t(size_t, hba->desc_size.dev_desc,
@@ -1816,7 +1817,11 @@ static int ufs_get_device_desc(struct ufs_hba *hba,
 	dev_desc->wmanufacturerid = desc_buf[DEVICE_DESC_PARAM_MANF_ID] << 8 |
 				     desc_buf[DEVICE_DESC_PARAM_MANF_ID + 1];
 
+	dev_desc->wspecversion = desc_buf[DEVICE_DESC_PARAM_SPEC_VER] << 8 |
+				  desc_buf[DEVICE_DESC_PARAM_SPEC_VER + 1];
+
 	model_index = desc_buf[DEVICE_DESC_PARAM_PRDCT_NAME];
+	revision_index = desc_buf[DEVICE_DESC_PARAM_PRDCT_REV];
 
 	/* Zero-pad entire buffer for string termination. */
 	memset(desc_buf, 0, buff_len);
@@ -1837,6 +1842,25 @@ static int ufs_get_device_desc(struct ufs_hba *hba,
 	/* Null terminate the model string */
 	dev_desc->model[MAX_MODEL_LEN] = '\0';
 
+	/* Zero-pad entire buffer for string termination. */
+	memset(desc_buf, 0, buff_len);
+
+	err = ufshcd_read_string_desc(hba, revision_index, desc_buf,
+				      QUERY_DESC_MAX_SIZE, true/*ASCII*/);
+	if (err) {
+		dev_err(hba->dev, "%s: Failed reading Product Revision. err = %d\n",
+			__func__, err);
+		goto out;
+	}
+
+	desc_buf[QUERY_DESC_MAX_SIZE] = '\0';
+	strlcpy(dev_desc->revision, (char *)(desc_buf + QUERY_DESC_HDR_SIZE),
+		min_t(u8, desc_buf[QUERY_DESC_LENGTH_OFFSET],
+		      MAX_REVISION_LEN));
+
+	/* Null terminate the revision string */
+	dev_desc->revision[MAX_REVISION_LEN] = '\0';
+
 out:
 	kfree(desc_buf);
 	return err;
diff --git a/drivers/ufs/ufs.h b/drivers/ufs/ufs.h
index 0f6c93fbce7..e3368a516e4 100644
--- a/drivers/ufs/ufs.h
+++ b/drivers/ufs/ufs.h
@@ -346,15 +346,20 @@ struct utp_upiu_rsp {
 };
 
 #define MAX_MODEL_LEN 16
+#define MAX_REVISION_LEN 4
 /**
  * ufs_dev_desc - ufs device details from the device descriptor
  *
  * @wmanufacturerid: card details
+ * @wspecversion: UFS spec version supported by the device
  * @model: card model
+ * @revision: card fw revision
  */
 struct ufs_dev_desc {
 	u16 wmanufacturerid;
+	u16 wspecversion;
 	char model[MAX_MODEL_LEN + 1];
+	char revision[MAX_REVISION_LEN + 1];
 };
 
 /* Device descriptor parameters offsets in bytes*/

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH u-boot 1/8] ufs: read product revision and spec version into ufs_dev_desc
@ 2026-10-04 19:22   ` Petr Hodina
  0 siblings, 0 replies; 26+ messages in thread
From: Petr Hodina @ 2026-10-04 19:22 UTC (permalink / raw)
  To: u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	David Heidelberg, Marek Vasut, Padmarao Begari, Macpaul Lin,
	Julien Stephan, Kunihiko Hayashi, Shawn Lin, Jared McArthur,
	Michal Simek, Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata, Petr Hodina

Extend ufs_get_device_desc() to also fetch the device's product revision
string (PRDCT_REV) and the UFS spec version (SPEC_VER) into struct
ufs_dev_desc.

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
 drivers/ufs/ufs-uclass.c | 24 ++++++++++++++++++++++++
 drivers/ufs/ufs.h        |  5 +++++
 2 files changed, 29 insertions(+)

diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
index 6a51f337e47..56118a0ee46 100644
--- a/drivers/ufs/ufs-uclass.c
+++ b/drivers/ufs/ufs-uclass.c
@@ -1792,6 +1792,7 @@ static int ufs_get_device_desc(struct ufs_hba *hba,
 	int err;
 	size_t buff_len;
 	u8 model_index;
+	u8 revision_index;
 	u8 *desc_buf;
 
 	buff_len = max_t(size_t, hba->desc_size.dev_desc,
@@ -1816,7 +1817,11 @@ static int ufs_get_device_desc(struct ufs_hba *hba,
 	dev_desc->wmanufacturerid = desc_buf[DEVICE_DESC_PARAM_MANF_ID] << 8 |
 				     desc_buf[DEVICE_DESC_PARAM_MANF_ID + 1];
 
+	dev_desc->wspecversion = desc_buf[DEVICE_DESC_PARAM_SPEC_VER] << 8 |
+				  desc_buf[DEVICE_DESC_PARAM_SPEC_VER + 1];
+
 	model_index = desc_buf[DEVICE_DESC_PARAM_PRDCT_NAME];
+	revision_index = desc_buf[DEVICE_DESC_PARAM_PRDCT_REV];
 
 	/* Zero-pad entire buffer for string termination. */
 	memset(desc_buf, 0, buff_len);
@@ -1837,6 +1842,25 @@ static int ufs_get_device_desc(struct ufs_hba *hba,
 	/* Null terminate the model string */
 	dev_desc->model[MAX_MODEL_LEN] = '\0';
 
+	/* Zero-pad entire buffer for string termination. */
+	memset(desc_buf, 0, buff_len);
+
+	err = ufshcd_read_string_desc(hba, revision_index, desc_buf,
+				      QUERY_DESC_MAX_SIZE, true/*ASCII*/);
+	if (err) {
+		dev_err(hba->dev, "%s: Failed reading Product Revision. err = %d\n",
+			__func__, err);
+		goto out;
+	}
+
+	desc_buf[QUERY_DESC_MAX_SIZE] = '\0';
+	strlcpy(dev_desc->revision, (char *)(desc_buf + QUERY_DESC_HDR_SIZE),
+		min_t(u8, desc_buf[QUERY_DESC_LENGTH_OFFSET],
+		      MAX_REVISION_LEN));
+
+	/* Null terminate the revision string */
+	dev_desc->revision[MAX_REVISION_LEN] = '\0';
+
 out:
 	kfree(desc_buf);
 	return err;
diff --git a/drivers/ufs/ufs.h b/drivers/ufs/ufs.h
index 0f6c93fbce7..e3368a516e4 100644
--- a/drivers/ufs/ufs.h
+++ b/drivers/ufs/ufs.h
@@ -346,15 +346,20 @@ struct utp_upiu_rsp {
 };
 
 #define MAX_MODEL_LEN 16
+#define MAX_REVISION_LEN 4
 /**
  * ufs_dev_desc - ufs device details from the device descriptor
  *
  * @wmanufacturerid: card details
+ * @wspecversion: UFS spec version supported by the device
  * @model: card model
+ * @revision: card fw revision
  */
 struct ufs_dev_desc {
 	u16 wmanufacturerid;
+	u16 wspecversion;
 	char model[MAX_MODEL_LEN + 1];
+	char revision[MAX_REVISION_LEN + 1];
 };
 
 /* Device descriptor parameters offsets in bytes*/

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH u-boot 2/8] ufs: add device-quirk infrastructure
  2026-10-04 19:22 ` Petr Hodina
@ 2026-10-04 19:22   ` Petr Hodina
  -1 siblings, 0 replies; 26+ messages in thread
From: Petr Hodina via B4 Relay @ 2026-10-04 19:22 UTC (permalink / raw)
  To: u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	David Heidelberg, Marek Vasut, Padmarao Begari, Macpaul Lin,
	Julien Stephan, Kunihiko Hayashi, Shawn Lin, Jared McArthur,
	Michal Simek, Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata, Petr Hodina

From: Petr Hodina <petr.hodina@protonmail.com>

Infrastructure (ufs_quirks.h):
 - struct ufs_dev_quirk plus UFS_FIX()/UFS_FIX_REVISION() helpers.
 - ufshcd_fixup_dev_quirks() applies the table (and sets NO_PURGE for
   devices older than UFS_PURGE_SPEC_VER) from ufs_start(), before power
   mode negotiation so link quirks take effect.
 - hba gains a dev_quirks field, distinct from the host controller
   quirks (hba->quirks).

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
 drivers/ufs/ufs-uclass.c | 52 +++++++++++++++++++++++++++++
 drivers/ufs/ufs.h        |  2 ++
 drivers/ufs/ufs_quirks.h | 87 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 141 insertions(+)

diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
index 56118a0ee46..05b95c510b4 100644
--- a/drivers/ufs/ufs-uclass.c
+++ b/drivers/ufs/ufs-uclass.c
@@ -29,6 +29,7 @@
 #include <linux/dma-mapping.h>
 
 #include "ufs.h"
+#include "ufs_quirks.h"
 
 #define UFSHCD_ENABLE_INTRS	(UTP_TRANSFER_REQ_COMPL |\
 				 UTP_TASK_REQ_COMPL |\
@@ -1866,6 +1867,54 @@ out:
 	return err;
 }
 
+/*
+ * UFS device quirk table. Entries are matched by manufacturer id, model and
+ * fw revision; UFS_ANY_VENDOR / UFS_ANY_MODEL / UFS_ANY_VER act as wildcards.
+ */
+static const struct ufs_dev_quirk ufs_fixups[] = {
+	/* Sony Yoshino/Tama: block PURGE/UNMAP to avoid bricking */
+	UFS_FIX_REVISION(UFS_VENDOR_SKHYNIX, UFS_MODEL_HYNIX_32GB,
+			 UFS_REVISION_HYNIX, UFS_DEVICE_QUIRK_NO_PURGE),
+	UFS_FIX_REVISION(UFS_VENDOR_SKHYNIX, UFS_MODEL_HYNIX_64GB,
+			 UFS_REVISION_HYNIX, UFS_DEVICE_QUIRK_NO_PURGE),
+	UFS_FIX_REVISION(UFS_VENDOR_SAMSUNG, UFS_MODEL_SAMSUNG_64GB,
+			 UFS_REVISION_SAMSUNG, UFS_DEVICE_QUIRK_NO_PURGE),
+	END_FIX
+};
+
+/**
+ * ufshcd_fixup_dev_quirks - apply device-specific quirks
+ *
+ * Sets hba->dev_quirks based on the UFS spec version and the per-device
+ * fixup table above.
+ */
+static void ufshcd_fixup_dev_quirks(struct ufs_hba *hba,
+				    struct ufs_dev_desc *dev_desc)
+{
+	const struct ufs_dev_quirk *f;
+
+	/*
+	 * Devices implementing an older UFS spec must not be issued PURGE /
+	 * UNMAP, doing so erases the bootloader on affected platforms.
+	 */
+	if (dev_desc->wspecversion < UFS_PURGE_SPEC_VER)
+		hba->dev_quirks |= UFS_DEVICE_QUIRK_NO_PURGE;
+
+	for (f = ufs_fixups; f->quirk; f++) {
+		if ((f->wmanufacturerid == dev_desc->wmanufacturerid ||
+		     f->wmanufacturerid == UFS_ANY_VENDOR) &&
+		    (str_prfx_equal(f->model, dev_desc->model) ||
+		     !strcmp(f->model, UFS_ANY_MODEL)) &&
+		    (str_prfx_equal(f->revision, dev_desc->revision) ||
+		     !strcmp(f->revision, UFS_ANY_VER)))
+			hba->dev_quirks |= f->quirk;
+	}
+
+	if (hba->dev_quirks)
+		dev_dbg(hba->dev, "%s: applied device quirks 0x%08x\n",
+			__func__, hba->dev_quirks);
+}
+
 struct ufs_ref_clk {
 	unsigned long freq_hz;
 	enum ufs_ref_clk_freq val;
@@ -2175,6 +2224,9 @@ static int ufs_start(struct ufs_hba *hba)
 		return ret;
 	}
 
+	/* Apply device-specific quirks before negotiating the power mode */
+	ufshcd_fixup_dev_quirks(hba, &card);
+
 	ufshcd_set_dev_ref_clk(hba);
 
 	if (ufshcd_get_max_pwr_mode(hba)) {
diff --git a/drivers/ufs/ufs.h b/drivers/ufs/ufs.h
index e3368a516e4..d4bcb7a1773 100644
--- a/drivers/ufs/ufs.h
+++ b/drivers/ufs/ufs.h
@@ -707,6 +707,8 @@ struct ufs_hba {
 	u32			version;
 	u32			intr_mask;
 	enum ufshcd_quirks	quirks;
+	/* UFS device (not host controller) quirks, see ufs_quirks.h */
+	u32			dev_quirks;
 
 	/* Virtual memory reference */
 	struct utp_transfer_cmd_desc *ucdl;
diff --git a/drivers/ufs/ufs_quirks.h b/drivers/ufs/ufs_quirks.h
new file mode 100644
index 00000000000..f5aa47722db
--- /dev/null
+++ b/drivers/ufs/ufs_quirks.h
@@ -0,0 +1,87 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * UFS device quirks
+ *
+ * Ported from the Linux kernel (include/ufs/ufs_quirks.h) and the
+ * Sony Yoshino/Tama downstream UFS quirks/hacks.
+ */
+#ifndef _UFS_QUIRKS_H
+#define _UFS_QUIRKS_H
+
+#include <linux/bitops.h>
+#include <linux/string.h>
+
+/* true if s1 (the fixup pattern) is a prefix of s2 (the device value) */
+static inline bool str_prfx_equal(const char *s1, const char *s2)
+{
+	return strncmp(s1, s2, strlen(s1)) == 0;
+}
+
+#define UFS_ANY_VENDOR		0xFFFF
+#define UFS_ANY_MODEL		"ANY_MODEL"
+#define UFS_ANY_VER		"ANY_VER"
+
+#define UFS_VENDOR_TOSHIBA	0x198
+#define UFS_VENDOR_SAMSUNG	0x1CE
+#define UFS_VENDOR_SKHYNIX	0x1AD
+#define UFS_VENDOR_MICRON	0x12C
+#define UFS_VENDOR_WDC		0x145
+
+/* UFS Samsung models */
+#define UFS_MODEL_SAMSUNG_64GB	"KLUDG4U1EA-B0C1"
+#define UFS_REVISION_SAMSUNG	"0100"
+
+/* UFS SK Hynix models */
+#define UFS_MODEL_HYNIX_32GB	"hB8aL1"
+#define UFS_MODEL_HYNIX_64GB	"hC8aL1"
+#define UFS_REVISION_HYNIX	"D001"
+
+/*
+ * Devices with a UFS spec version older than this must not be issued PURGE /
+ * UNMAP (secure erase) operations: on the Sony Yoshino/Tama platforms doing so
+ * erases the bootloader and permanently bricks the device.
+ */
+#define UFS_PURGE_SPEC_VER	0x210
+
+/**
+ * struct ufs_dev_quirk - ufs device quirk info
+ * @wmanufacturerid: card details (UFS_ANY_VENDOR matches any vendor)
+ * @model: card model (UFS_ANY_MODEL matches any model)
+ * @revision: card fw revision (UFS_ANY_VER matches any revision)
+ * @quirk: device quirk bitmask
+ */
+struct ufs_dev_quirk {
+	u16 wmanufacturerid;
+	const char *model;
+	const char *revision;
+	unsigned int quirk;
+};
+
+/* terminator for the fixup table */
+#define END_FIX { 0, NULL, NULL, 0 }
+
+/* add a quirk for any revision of a specific model */
+#define UFS_FIX(_vendor, _model, _quirk) {	\
+	.wmanufacturerid = (_vendor),		\
+	.model = (_model),			\
+	.revision = (UFS_ANY_VER),		\
+	.quirk = (_quirk),			\
+}
+
+/* add a quirk for a specific model and fw revision */
+#define UFS_FIX_REVISION(_vendor, _model, _revision, _quirk) {	\
+	.wmanufacturerid = (_vendor),				\
+	.model = (_model),					\
+	.revision = (_revision),				\
+	.quirk = (_quirk),					\
+}
+
+/*
+ * Some Sony UFS devices must not use the PURGE / UNMAP (secure erase)
+ * operation as it would erase the bootloader and permanently brick the
+ * device. This quirk disables PURGE-related functionality for affected
+ * devices.
+ */
+#define UFS_DEVICE_QUIRK_NO_PURGE		BIT(0)
+
+#endif /* _UFS_QUIRKS_H */

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH u-boot 2/8] ufs: add device-quirk infrastructure
@ 2026-10-04 19:22   ` Petr Hodina
  0 siblings, 0 replies; 26+ messages in thread
From: Petr Hodina @ 2026-10-04 19:22 UTC (permalink / raw)
  To: u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	David Heidelberg, Marek Vasut, Padmarao Begari, Macpaul Lin,
	Julien Stephan, Kunihiko Hayashi, Shawn Lin, Jared McArthur,
	Michal Simek, Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata, Petr Hodina

Infrastructure (ufs_quirks.h):
 - struct ufs_dev_quirk plus UFS_FIX()/UFS_FIX_REVISION() helpers.
 - ufshcd_fixup_dev_quirks() applies the table (and sets NO_PURGE for
   devices older than UFS_PURGE_SPEC_VER) from ufs_start(), before power
   mode negotiation so link quirks take effect.
 - hba gains a dev_quirks field, distinct from the host controller
   quirks (hba->quirks).

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
 drivers/ufs/ufs-uclass.c | 52 +++++++++++++++++++++++++++++
 drivers/ufs/ufs.h        |  2 ++
 drivers/ufs/ufs_quirks.h | 87 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 141 insertions(+)

diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
index 56118a0ee46..05b95c510b4 100644
--- a/drivers/ufs/ufs-uclass.c
+++ b/drivers/ufs/ufs-uclass.c
@@ -29,6 +29,7 @@
 #include <linux/dma-mapping.h>
 
 #include "ufs.h"
+#include "ufs_quirks.h"
 
 #define UFSHCD_ENABLE_INTRS	(UTP_TRANSFER_REQ_COMPL |\
 				 UTP_TASK_REQ_COMPL |\
@@ -1866,6 +1867,54 @@ out:
 	return err;
 }
 
+/*
+ * UFS device quirk table. Entries are matched by manufacturer id, model and
+ * fw revision; UFS_ANY_VENDOR / UFS_ANY_MODEL / UFS_ANY_VER act as wildcards.
+ */
+static const struct ufs_dev_quirk ufs_fixups[] = {
+	/* Sony Yoshino/Tama: block PURGE/UNMAP to avoid bricking */
+	UFS_FIX_REVISION(UFS_VENDOR_SKHYNIX, UFS_MODEL_HYNIX_32GB,
+			 UFS_REVISION_HYNIX, UFS_DEVICE_QUIRK_NO_PURGE),
+	UFS_FIX_REVISION(UFS_VENDOR_SKHYNIX, UFS_MODEL_HYNIX_64GB,
+			 UFS_REVISION_HYNIX, UFS_DEVICE_QUIRK_NO_PURGE),
+	UFS_FIX_REVISION(UFS_VENDOR_SAMSUNG, UFS_MODEL_SAMSUNG_64GB,
+			 UFS_REVISION_SAMSUNG, UFS_DEVICE_QUIRK_NO_PURGE),
+	END_FIX
+};
+
+/**
+ * ufshcd_fixup_dev_quirks - apply device-specific quirks
+ *
+ * Sets hba->dev_quirks based on the UFS spec version and the per-device
+ * fixup table above.
+ */
+static void ufshcd_fixup_dev_quirks(struct ufs_hba *hba,
+				    struct ufs_dev_desc *dev_desc)
+{
+	const struct ufs_dev_quirk *f;
+
+	/*
+	 * Devices implementing an older UFS spec must not be issued PURGE /
+	 * UNMAP, doing so erases the bootloader on affected platforms.
+	 */
+	if (dev_desc->wspecversion < UFS_PURGE_SPEC_VER)
+		hba->dev_quirks |= UFS_DEVICE_QUIRK_NO_PURGE;
+
+	for (f = ufs_fixups; f->quirk; f++) {
+		if ((f->wmanufacturerid == dev_desc->wmanufacturerid ||
+		     f->wmanufacturerid == UFS_ANY_VENDOR) &&
+		    (str_prfx_equal(f->model, dev_desc->model) ||
+		     !strcmp(f->model, UFS_ANY_MODEL)) &&
+		    (str_prfx_equal(f->revision, dev_desc->revision) ||
+		     !strcmp(f->revision, UFS_ANY_VER)))
+			hba->dev_quirks |= f->quirk;
+	}
+
+	if (hba->dev_quirks)
+		dev_dbg(hba->dev, "%s: applied device quirks 0x%08x\n",
+			__func__, hba->dev_quirks);
+}
+
 struct ufs_ref_clk {
 	unsigned long freq_hz;
 	enum ufs_ref_clk_freq val;
@@ -2175,6 +2224,9 @@ static int ufs_start(struct ufs_hba *hba)
 		return ret;
 	}
 
+	/* Apply device-specific quirks before negotiating the power mode */
+	ufshcd_fixup_dev_quirks(hba, &card);
+
 	ufshcd_set_dev_ref_clk(hba);
 
 	if (ufshcd_get_max_pwr_mode(hba)) {
diff --git a/drivers/ufs/ufs.h b/drivers/ufs/ufs.h
index e3368a516e4..d4bcb7a1773 100644
--- a/drivers/ufs/ufs.h
+++ b/drivers/ufs/ufs.h
@@ -707,6 +707,8 @@ struct ufs_hba {
 	u32			version;
 	u32			intr_mask;
 	enum ufshcd_quirks	quirks;
+	/* UFS device (not host controller) quirks, see ufs_quirks.h */
+	u32			dev_quirks;
 
 	/* Virtual memory reference */
 	struct utp_transfer_cmd_desc *ucdl;
diff --git a/drivers/ufs/ufs_quirks.h b/drivers/ufs/ufs_quirks.h
new file mode 100644
index 00000000000..f5aa47722db
--- /dev/null
+++ b/drivers/ufs/ufs_quirks.h
@@ -0,0 +1,87 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * UFS device quirks
+ *
+ * Ported from the Linux kernel (include/ufs/ufs_quirks.h) and the
+ * Sony Yoshino/Tama downstream UFS quirks/hacks.
+ */
+#ifndef _UFS_QUIRKS_H
+#define _UFS_QUIRKS_H
+
+#include <linux/bitops.h>
+#include <linux/string.h>
+
+/* true if s1 (the fixup pattern) is a prefix of s2 (the device value) */
+static inline bool str_prfx_equal(const char *s1, const char *s2)
+{
+	return strncmp(s1, s2, strlen(s1)) == 0;
+}
+
+#define UFS_ANY_VENDOR		0xFFFF
+#define UFS_ANY_MODEL		"ANY_MODEL"
+#define UFS_ANY_VER		"ANY_VER"
+
+#define UFS_VENDOR_TOSHIBA	0x198
+#define UFS_VENDOR_SAMSUNG	0x1CE
+#define UFS_VENDOR_SKHYNIX	0x1AD
+#define UFS_VENDOR_MICRON	0x12C
+#define UFS_VENDOR_WDC		0x145
+
+/* UFS Samsung models */
+#define UFS_MODEL_SAMSUNG_64GB	"KLUDG4U1EA-B0C1"
+#define UFS_REVISION_SAMSUNG	"0100"
+
+/* UFS SK Hynix models */
+#define UFS_MODEL_HYNIX_32GB	"hB8aL1"
+#define UFS_MODEL_HYNIX_64GB	"hC8aL1"
+#define UFS_REVISION_HYNIX	"D001"
+
+/*
+ * Devices with a UFS spec version older than this must not be issued PURGE /
+ * UNMAP (secure erase) operations: on the Sony Yoshino/Tama platforms doing so
+ * erases the bootloader and permanently bricks the device.
+ */
+#define UFS_PURGE_SPEC_VER	0x210
+
+/**
+ * struct ufs_dev_quirk - ufs device quirk info
+ * @wmanufacturerid: card details (UFS_ANY_VENDOR matches any vendor)
+ * @model: card model (UFS_ANY_MODEL matches any model)
+ * @revision: card fw revision (UFS_ANY_VER matches any revision)
+ * @quirk: device quirk bitmask
+ */
+struct ufs_dev_quirk {
+	u16 wmanufacturerid;
+	const char *model;
+	const char *revision;
+	unsigned int quirk;
+};
+
+/* terminator for the fixup table */
+#define END_FIX { 0, NULL, NULL, 0 }
+
+/* add a quirk for any revision of a specific model */
+#define UFS_FIX(_vendor, _model, _quirk) {	\
+	.wmanufacturerid = (_vendor),		\
+	.model = (_model),			\
+	.revision = (UFS_ANY_VER),		\
+	.quirk = (_quirk),			\
+}
+
+/* add a quirk for a specific model and fw revision */
+#define UFS_FIX_REVISION(_vendor, _model, _revision, _quirk) {	\
+	.wmanufacturerid = (_vendor),				\
+	.model = (_model),					\
+	.revision = (_revision),				\
+	.quirk = (_quirk),					\
+}
+
+/*
+ * Some Sony UFS devices must not use the PURGE / UNMAP (secure erase)
+ * operation as it would erase the bootloader and permanently brick the
+ * device. This quirk disables PURGE-related functionality for affected
+ * devices.
+ */
+#define UFS_DEVICE_QUIRK_NO_PURGE		BIT(0)
+
+#endif /* _UFS_QUIRKS_H */

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH u-boot 3/8] ufs: program extended HS sync length for SK Hynix devices
  2026-10-04 19:22 ` Petr Hodina
@ 2026-10-04 19:22   ` Petr Hodina
  -1 siblings, 0 replies; 26+ messages in thread
From: Petr Hodina via B4 Relay @ 2026-10-04 19:22 UTC (permalink / raw)
  To: u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	David Heidelberg, Marek Vasut, Padmarao Begari, Macpaul Lin,
	Julien Stephan, Kunihiko Hayashi, Shawn Lin, Jared McArthur,
	Michal Simek, Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata, Petr Hodina

From: Petr Hodina <petr.hodina@protonmail.com>

Add the UFS_DEVICE_QUIRK_EXTEND_SYNC_LENGTH bit. SK Hynix UFS devices
on the Sony Yoshino/Tama (MSM8998 / SDM845) family need
PA_TxHsG{1,2,3}SyncLength programmed to 0x48 before the power-mode
change for a reliable HS link; without it link bring-up fails or the
device falls back to a slow PWM mode.

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
 drivers/ufs/ufs-uclass.c | 9 +++++++++
 drivers/ufs/ufs_quirks.h | 7 +++++++
 drivers/ufs/unipro.h     | 3 +++
 3 files changed, 19 insertions(+)

diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
index 05b95c510b4..fdf62a69c02 100644
--- a/drivers/ufs/ufs-uclass.c
+++ b/drivers/ufs/ufs-uclass.c
@@ -1872,6 +1872,9 @@ out:
  * fw revision; UFS_ANY_VENDOR / UFS_ANY_MODEL / UFS_ANY_VER act as wildcards.
  */
 static const struct ufs_dev_quirk ufs_fixups[] = {
+	/* SK Hynix devices need an extended HS sync length */
+	UFS_FIX(UFS_VENDOR_SKHYNIX, UFS_ANY_MODEL,
+		UFS_DEVICE_QUIRK_EXTEND_SYNC_LENGTH),
 	/* Sony Yoshino/Tama: block PURGE/UNMAP to avoid bricking */
 	UFS_FIX_REVISION(UFS_VENDOR_SKHYNIX, UFS_MODEL_HYNIX_32GB,
 			 UFS_REVISION_HYNIX, UFS_DEVICE_QUIRK_NO_PURGE),
@@ -2108,6 +2111,12 @@ static int ufshcd_change_power_mode(struct ufs_hba *hba,
 		ufshcd_dme_set(hba, UIC_ARG_MIB(PA_HSSERIES),
 			       pwr_mode->hs_rate);
 
+	if (hba->dev_quirks & UFS_DEVICE_QUIRK_EXTEND_SYNC_LENGTH) {
+		ufshcd_dme_set(hba, UIC_ARG_MIB(PA_TxHsG1SyncLength), 0x48);
+		ufshcd_dme_set(hba, UIC_ARG_MIB(PA_TxHsG2SyncLength), 0x48);
+		ufshcd_dme_set(hba, UIC_ARG_MIB(PA_TxHsG3SyncLength), 0x48);
+	}
+
 	ret = ufshcd_uic_change_pwr_mode(hba, pwr_mode->pwr_rx << 4 |
 					 pwr_mode->pwr_tx);
 
diff --git a/drivers/ufs/ufs_quirks.h b/drivers/ufs/ufs_quirks.h
index f5aa47722db..822315cb06d 100644
--- a/drivers/ufs/ufs_quirks.h
+++ b/drivers/ufs/ufs_quirks.h
@@ -84,4 +84,11 @@ struct ufs_dev_quirk {
  */
 #define UFS_DEVICE_QUIRK_NO_PURGE		BIT(0)
 
+/*
+ * Some SK Hynix devices on Sony Yoshino/Tama need an extended HS sync length
+ * (PA_TxHsG{1,2,3}SyncLength) programmed before the power-mode change for a
+ * reliable HS link.
+ */
+#define UFS_DEVICE_QUIRK_EXTEND_SYNC_LENGTH	BIT(1)
+
 #endif /* _UFS_QUIRKS_H */
diff --git a/drivers/ufs/unipro.h b/drivers/ufs/unipro.h
index bde1490397c..4e163da0736 100644
--- a/drivers/ufs/unipro.h
+++ b/drivers/ufs/unipro.h
@@ -118,6 +118,9 @@
 #define PA_TXGEAR		0x1568
 #define PA_TXTERMINATION	0x1569
 #define PA_HSSERIES		0x156A
+#define PA_TxHsG1SyncLength	0x1552
+#define PA_TxHsG2SyncLength	0x1554
+#define PA_TxHsG3SyncLength	0x1556
 #define PA_LEGACYDPHYESCDL	0x1570
 #define PA_PWRMODE		0x1571
 #define PA_ACTIVERXDATALANES	0x1580

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH u-boot 3/8] ufs: program extended HS sync length for SK Hynix devices
@ 2026-10-04 19:22   ` Petr Hodina
  0 siblings, 0 replies; 26+ messages in thread
From: Petr Hodina @ 2026-10-04 19:22 UTC (permalink / raw)
  To: u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	David Heidelberg, Marek Vasut, Padmarao Begari, Macpaul Lin,
	Julien Stephan, Kunihiko Hayashi, Shawn Lin, Jared McArthur,
	Michal Simek, Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata, Petr Hodina

Add the UFS_DEVICE_QUIRK_EXTEND_SYNC_LENGTH bit. SK Hynix UFS devices
on the Sony Yoshino/Tama (MSM8998 / SDM845) family need
PA_TxHsG{1,2,3}SyncLength programmed to 0x48 before the power-mode
change for a reliable HS link; without it link bring-up fails or the
device falls back to a slow PWM mode.

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
 drivers/ufs/ufs-uclass.c | 9 +++++++++
 drivers/ufs/ufs_quirks.h | 7 +++++++
 drivers/ufs/unipro.h     | 3 +++
 3 files changed, 19 insertions(+)

diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
index 05b95c510b4..fdf62a69c02 100644
--- a/drivers/ufs/ufs-uclass.c
+++ b/drivers/ufs/ufs-uclass.c
@@ -1872,6 +1872,9 @@ out:
  * fw revision; UFS_ANY_VENDOR / UFS_ANY_MODEL / UFS_ANY_VER act as wildcards.
  */
 static const struct ufs_dev_quirk ufs_fixups[] = {
+	/* SK Hynix devices need an extended HS sync length */
+	UFS_FIX(UFS_VENDOR_SKHYNIX, UFS_ANY_MODEL,
+		UFS_DEVICE_QUIRK_EXTEND_SYNC_LENGTH),
 	/* Sony Yoshino/Tama: block PURGE/UNMAP to avoid bricking */
 	UFS_FIX_REVISION(UFS_VENDOR_SKHYNIX, UFS_MODEL_HYNIX_32GB,
 			 UFS_REVISION_HYNIX, UFS_DEVICE_QUIRK_NO_PURGE),
@@ -2108,6 +2111,12 @@ static int ufshcd_change_power_mode(struct ufs_hba *hba,
 		ufshcd_dme_set(hba, UIC_ARG_MIB(PA_HSSERIES),
 			       pwr_mode->hs_rate);
 
+	if (hba->dev_quirks & UFS_DEVICE_QUIRK_EXTEND_SYNC_LENGTH) {
+		ufshcd_dme_set(hba, UIC_ARG_MIB(PA_TxHsG1SyncLength), 0x48);
+		ufshcd_dme_set(hba, UIC_ARG_MIB(PA_TxHsG2SyncLength), 0x48);
+		ufshcd_dme_set(hba, UIC_ARG_MIB(PA_TxHsG3SyncLength), 0x48);
+	}
+
 	ret = ufshcd_uic_change_pwr_mode(hba, pwr_mode->pwr_rx << 4 |
 					 pwr_mode->pwr_tx);
 
diff --git a/drivers/ufs/ufs_quirks.h b/drivers/ufs/ufs_quirks.h
index f5aa47722db..822315cb06d 100644
--- a/drivers/ufs/ufs_quirks.h
+++ b/drivers/ufs/ufs_quirks.h
@@ -84,4 +84,11 @@ struct ufs_dev_quirk {
  */
 #define UFS_DEVICE_QUIRK_NO_PURGE		BIT(0)
 
+/*
+ * Some SK Hynix devices on Sony Yoshino/Tama need an extended HS sync length
+ * (PA_TxHsG{1,2,3}SyncLength) programmed before the power-mode change for a
+ * reliable HS link.
+ */
+#define UFS_DEVICE_QUIRK_EXTEND_SYNC_LENGTH	BIT(1)
+
 #endif /* _UFS_QUIRKS_H */
diff --git a/drivers/ufs/unipro.h b/drivers/ufs/unipro.h
index bde1490397c..4e163da0736 100644
--- a/drivers/ufs/unipro.h
+++ b/drivers/ufs/unipro.h
@@ -118,6 +118,9 @@
 #define PA_TXGEAR		0x1568
 #define PA_TXTERMINATION	0x1569
 #define PA_HSSERIES		0x156A
+#define PA_TxHsG1SyncLength	0x1552
+#define PA_TxHsG2SyncLength	0x1554
+#define PA_TxHsG3SyncLength	0x1556
 #define PA_LEGACYDPHYESCDL	0x1570
 #define PA_PWRMODE		0x1571
 #define PA_ACTIVERXDATALANES	0x1580

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH u-boot 4/8] ufs: add CONFIG_UFS_RESTRICT_TX_LANES
  2026-10-04 19:22 ` Petr Hodina
@ 2026-10-04 19:22   ` Petr Hodina
  -1 siblings, 0 replies; 26+ messages in thread
From: Petr Hodina via B4 Relay @ 2026-10-04 19:22 UTC (permalink / raw)
  To: u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	David Heidelberg, Marek Vasut, Padmarao Begari, Macpaul Lin,
	Julien Stephan, Kunihiko Hayashi, Shawn Lin, Jared McArthur,
	Michal Simek, Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata, Petr Hodina

From: Petr Hodina <petr.hodina@protonmail.com>

Add CONFIG_UFS_RESTRICT_TX_LANES, to restrict the amount
PA_AVAILTXDATALANES = 1 at the start of ufshcd_link_startup().

Some platforms (notably the Sony Yoshino/Tama families on MSM8998 /
SDM845) have only a single reliably-usable UFS TX lane.

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
 drivers/ufs/Kconfig      | 14 ++++++++++++++
 drivers/ufs/ufs-uclass.c | 13 +++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/drivers/ufs/Kconfig b/drivers/ufs/Kconfig
index 49472933de3..266e7180152 100644
--- a/drivers/ufs/Kconfig
+++ b/drivers/ufs/Kconfig
@@ -8,6 +8,20 @@ config UFS
 	  This selects support for Universal Flash Subsystem (UFS).
 	  Say Y here if you want UFS Support.
 
+config UFS_RESTRICT_TX_LANES
+	bool "Restrict the number of UFS TX lanes to 1"
+	depends on UFS
+	default n
+	help
+	  Say Y here to restrict the number of UFS TX lanes to 1. This saves
+	  power at the cost of write performance.
+
+	  This is useful (and on some devices required) for platforms such as
+	  the Sony Yoshino/Tama families where only a single TX lane is
+	  reliably usable.
+
+	  If unsure, say N.
+
 config UFS_AMD_VERSAL2
 	bool "AMD Versal Gen 2 UFS controller platform driver"
 	depends on UFS && ZYNQMP_FIRMWARE
diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
index fdf62a69c02..977ffebc21f 100644
--- a/drivers/ufs/ufs-uclass.c
+++ b/drivers/ufs/ufs-uclass.c
@@ -508,6 +508,19 @@ static int ufshcd_link_startup(struct ufs_hba *hba)
 	int ret;
 	int retries = DME_LINKSTARTUP_RETRIES;
 
+	if (IS_ENABLED(CONFIG_UFS_RESTRICT_TX_LANES)) {
+		/*
+		 * Restrict the number of available TX lanes to 1. This saves
+		 * power at the cost of write performance and is required on
+		 * some platforms (e.g. Sony Yoshino/Tama) where only a single
+		 * TX lane is reliably usable.
+		 */
+		ret = ufshcd_dme_set(hba, UIC_ARG_MIB(PA_AVAILTXDATALANES), 1);
+		if (ret)
+			dev_warn(hba->dev, "%s: failed to restrict TX lanes: %d\n",
+				 __func__, ret);
+	}
+
 	do {
 		ret = ufshcd_ops_link_startup_notify(hba, PRE_CHANGE);
 		if (ret)

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH u-boot 4/8] ufs: add CONFIG_UFS_RESTRICT_TX_LANES
@ 2026-10-04 19:22   ` Petr Hodina
  0 siblings, 0 replies; 26+ messages in thread
From: Petr Hodina @ 2026-10-04 19:22 UTC (permalink / raw)
  To: u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	David Heidelberg, Marek Vasut, Padmarao Begari, Macpaul Lin,
	Julien Stephan, Kunihiko Hayashi, Shawn Lin, Jared McArthur,
	Michal Simek, Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata, Petr Hodina

Add CONFIG_UFS_RESTRICT_TX_LANES, to restrict the amount
PA_AVAILTXDATALANES = 1 at the start of ufshcd_link_startup().

Some platforms (notably the Sony Yoshino/Tama families on MSM8998 /
SDM845) have only a single reliably-usable UFS TX lane.

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
 drivers/ufs/Kconfig      | 14 ++++++++++++++
 drivers/ufs/ufs-uclass.c | 13 +++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/drivers/ufs/Kconfig b/drivers/ufs/Kconfig
index 49472933de3..266e7180152 100644
--- a/drivers/ufs/Kconfig
+++ b/drivers/ufs/Kconfig
@@ -8,6 +8,20 @@ config UFS
 	  This selects support for Universal Flash Subsystem (UFS).
 	  Say Y here if you want UFS Support.
 
+config UFS_RESTRICT_TX_LANES
+	bool "Restrict the number of UFS TX lanes to 1"
+	depends on UFS
+	default n
+	help
+	  Say Y here to restrict the number of UFS TX lanes to 1. This saves
+	  power at the cost of write performance.
+
+	  This is useful (and on some devices required) for platforms such as
+	  the Sony Yoshino/Tama families where only a single TX lane is
+	  reliably usable.
+
+	  If unsure, say N.
+
 config UFS_AMD_VERSAL2
 	bool "AMD Versal Gen 2 UFS controller platform driver"
 	depends on UFS && ZYNQMP_FIRMWARE
diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
index fdf62a69c02..977ffebc21f 100644
--- a/drivers/ufs/ufs-uclass.c
+++ b/drivers/ufs/ufs-uclass.c
@@ -508,6 +508,19 @@ static int ufshcd_link_startup(struct ufs_hba *hba)
 	int ret;
 	int retries = DME_LINKSTARTUP_RETRIES;
 
+	if (IS_ENABLED(CONFIG_UFS_RESTRICT_TX_LANES)) {
+		/*
+		 * Restrict the number of available TX lanes to 1. This saves
+		 * power at the cost of write performance and is required on
+		 * some platforms (e.g. Sony Yoshino/Tama) where only a single
+		 * TX lane is reliably usable.
+		 */
+		ret = ufshcd_dme_set(hba, UIC_ARG_MIB(PA_AVAILTXDATALANES), 1);
+		if (ret)
+			dev_warn(hba->dev, "%s: failed to restrict TX lanes: %d\n",
+				 __func__, ret);
+	}
+
 	do {
 		ret = ufshcd_ops_link_startup_notify(hba, PRE_CHANGE);
 		if (ret)

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH u-boot 5/8] scsi: ufs: refuse erase/UNMAP on NO_PURGE devices
  2026-10-04 19:22 ` Petr Hodina
@ 2026-10-04 19:22   ` Petr Hodina
  -1 siblings, 0 replies; 26+ messages in thread
From: Petr Hodina via B4 Relay @ 2026-10-04 19:22 UTC (permalink / raw)
  To: u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	David Heidelberg, Marek Vasut, Padmarao Begari, Macpaul Lin,
	Julien Stephan, Kunihiko Hayashi, Shawn Lin, Jared McArthur,
	Michal Simek, Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata, Petr Hodina

From: Petr Hodina <petr.hodina@protonmail.com>

Enforce the UFS_DEVICE_QUIRK_NO_PURGE quirk on U-Boot's only path that
can reach a UFS device with a destructive UNMAP: the block-device erase
op (scsi_erase() -> SCSI_UNMAP). On Sony Yoshino/Tama a PURGE/UNMAP
erases the bootloader and permanently bricks the device.

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
 drivers/scsi/scsi.c      |  5 +++++
 drivers/ufs/ufs-uclass.c | 12 ++++++++++++
 include/scsi.h           |  5 +++++
 3 files changed, 22 insertions(+)

diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 50e7d749921..ba7834ea035 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -300,6 +300,11 @@ static ulong scsi_erase(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt)
 	lbaint_t start, blks, max_blks, blocks;
 	struct scsi_cmd *pccb = (struct scsi_cmd *)&tempccb;
 
+	if (uc_plat->no_erase) {
+		printf("%s: erase not supported on this device\n", __func__);
+		return 0;
+	}
+
 	/* Setup device */
 	pccb->target = block_dev->target;
 	pccb->lun = block_dev->lun;
diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
index 977ffebc21f..7dfba3ac1ac 100644
--- a/drivers/ufs/ufs-uclass.c
+++ b/drivers/ufs/ufs-uclass.c
@@ -2366,6 +2366,18 @@ int ufshcd_probe(struct udevice *ufs_dev, struct ufs_hba_ops *hba_ops)
 	if (err)
 		return err;
 
+	/*
+	 * Some devices must never receive a PURGE / UNMAP (secure erase): on
+	 * the affected platforms it erases the bootloader and permanently
+	 * bricks the device. Disable the SCSI erase op for the whole UFS
+	 * device in that case.
+	 */
+	if (hba->dev_quirks & UFS_DEVICE_QUIRK_NO_PURGE) {
+		scsi_plat->no_erase = true;
+		dev_info(hba->dev,
+			 "NO_PURGE quirk active: SCSI erase/UNMAP disabled\n");
+	}
+
 	return 0;
 }
 
diff --git a/include/scsi.h b/include/scsi.h
index 2520a8b8fe6..fc296285dd5 100644
--- a/include/scsi.h
+++ b/include/scsi.h
@@ -275,6 +275,11 @@ struct scsi_plat {
 	unsigned long max_lun;
 	unsigned long max_id;
 	unsigned long max_bytes_per_req;
+	/*
+	 * Set by the controller driver to forbid the erase (UNMAP) operation,
+	 * e.g. for UFS devices whose PURGE/UNMAP would erase the bootloader.
+	 */
+	bool no_erase;
 };
 
 /* Operations for SCSI */

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH u-boot 5/8] scsi: ufs: refuse erase/UNMAP on NO_PURGE devices
@ 2026-10-04 19:22   ` Petr Hodina
  0 siblings, 0 replies; 26+ messages in thread
From: Petr Hodina @ 2026-10-04 19:22 UTC (permalink / raw)
  To: u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	David Heidelberg, Marek Vasut, Padmarao Begari, Macpaul Lin,
	Julien Stephan, Kunihiko Hayashi, Shawn Lin, Jared McArthur,
	Michal Simek, Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata, Petr Hodina

Enforce the UFS_DEVICE_QUIRK_NO_PURGE quirk on U-Boot's only path that
can reach a UFS device with a destructive UNMAP: the block-device erase
op (scsi_erase() -> SCSI_UNMAP). On Sony Yoshino/Tama a PURGE/UNMAP
erases the bootloader and permanently bricks the device.

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
 drivers/scsi/scsi.c      |  5 +++++
 drivers/ufs/ufs-uclass.c | 12 ++++++++++++
 include/scsi.h           |  5 +++++
 3 files changed, 22 insertions(+)

diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 50e7d749921..ba7834ea035 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -300,6 +300,11 @@ static ulong scsi_erase(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt)
 	lbaint_t start, blks, max_blks, blocks;
 	struct scsi_cmd *pccb = (struct scsi_cmd *)&tempccb;
 
+	if (uc_plat->no_erase) {
+		printf("%s: erase not supported on this device\n", __func__);
+		return 0;
+	}
+
 	/* Setup device */
 	pccb->target = block_dev->target;
 	pccb->lun = block_dev->lun;
diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
index 977ffebc21f..7dfba3ac1ac 100644
--- a/drivers/ufs/ufs-uclass.c
+++ b/drivers/ufs/ufs-uclass.c
@@ -2366,6 +2366,18 @@ int ufshcd_probe(struct udevice *ufs_dev, struct ufs_hba_ops *hba_ops)
 	if (err)
 		return err;
 
+	/*
+	 * Some devices must never receive a PURGE / UNMAP (secure erase): on
+	 * the affected platforms it erases the bootloader and permanently
+	 * bricks the device. Disable the SCSI erase op for the whole UFS
+	 * device in that case.
+	 */
+	if (hba->dev_quirks & UFS_DEVICE_QUIRK_NO_PURGE) {
+		scsi_plat->no_erase = true;
+		dev_info(hba->dev,
+			 "NO_PURGE quirk active: SCSI erase/UNMAP disabled\n");
+	}
+
 	return 0;
 }
 
diff --git a/include/scsi.h b/include/scsi.h
index 2520a8b8fe6..fc296285dd5 100644
--- a/include/scsi.h
+++ b/include/scsi.h
@@ -275,6 +275,11 @@ struct scsi_plat {
 	unsigned long max_lun;
 	unsigned long max_id;
 	unsigned long max_bytes_per_req;
+	/*
+	 * Set by the controller driver to forbid the erase (UNMAP) operation,
+	 * e.g. for UFS devices whose PURGE/UNMAP would erase the bootloader.
+	 */
+	bool no_erase;
 };
 
 /* Operations for SCSI */

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH u-boot 6/8] ufs: print device information at probe
  2026-10-04 19:22 ` Petr Hodina
@ 2026-10-04 19:22   ` Petr Hodina
  -1 siblings, 0 replies; 26+ messages in thread
From: Petr Hodina via B4 Relay @ 2026-10-04 19:22 UTC (permalink / raw)
  To: u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	David Heidelberg, Marek Vasut, Padmarao Begari, Macpaul Lin,
	Julien Stephan, Kunihiko Hayashi, Shawn Lin, Jared McArthur,
	Michal Simek, Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata, Petr Hodina

From: Petr Hodina <petr.hodina@protonmail.com>

Dump the key UFS device properties (manufacturer, model, fw revision,
spec version, negotiated gear/lane/power, and the applied device quirks)
at the end of ufs_start().

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
 drivers/ufs/ufs-uclass.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
index 7dfba3ac1ac..3cc4fd6bde3 100644
--- a/drivers/ufs/ufs-uclass.c
+++ b/drivers/ufs/ufs-uclass.c
@@ -2218,6 +2218,58 @@ static void ufshcd_def_desc_sizes(struct ufs_hba *hba)
 	hba->desc_size.hlth_desc = QUERY_DESC_HEALTH_DEF_SIZE;
 }
 
+/* Map a JEDEC UFS manufacturer id to a human-readable vendor name */
+static const char *ufshcd_vendor_name(u16 mid)
+{
+	switch (mid) {
+	case UFS_VENDOR_TOSHIBA:	return "Toshiba/Kioxia";
+	case UFS_VENDOR_SAMSUNG:	return "Samsung";
+	case UFS_VENDOR_SKHYNIX:	return "SK Hynix";
+	case UFS_VENDOR_MICRON:		return "Micron";
+	case UFS_VENDOR_WDC:		return "Western Digital";
+	default:			return NULL;
+	}
+}
+
+static void ufshcd_rtrim(char *s)
+{
+	size_t n = strlen(s);
+
+	while (n && s[n - 1] == ' ')
+		s[--n] = '\0';
+}
+
+static void ufshcd_print_dev_info(struct ufs_hba *hba,
+				  struct ufs_dev_desc *card)
+{
+	const char *vendor = ufshcd_vendor_name(card->wmanufacturerid);
+
+	ufshcd_rtrim(card->model);
+	ufshcd_rtrim(card->revision);
+
+	printf("UFS Device Information (%s)\n", hba->dev->name);
+	if (vendor)
+		printf("  Manufacturer:    %s (0x%04x)\n", vendor,
+		       card->wmanufacturerid);
+	else
+		printf("  Manufacturer ID: 0x%04x\n", card->wmanufacturerid);
+	printf("  Model:           %s\n",
+	       card->model[0] ? card->model : "(unset)");
+	printf("  Revision:        %s\n",
+	       card->revision[0] ? card->revision : "(unset)");
+	printf("  Spec Version:    0x%04x\n", card->wspecversion);
+	printf("  Gear  - RX: %u, TX: %u\n",
+	       hba->pwr_info.gear_rx, hba->pwr_info.gear_tx);
+	printf("  Lane  - RX: %u, TX: %u\n",
+	       hba->pwr_info.lane_rx, hba->pwr_info.lane_tx);
+	printf("  Power - RX: %u, TX: %u, HS rate: %u\n",
+	       hba->pwr_info.pwr_rx, hba->pwr_info.pwr_tx,
+	       hba->pwr_info.hs_rate);
+	printf("  Device Quirks:   0x%08x\n", hba->dev_quirks);
+	printf("  NO_PURGE Quirk:  %s\n",
+	       (hba->dev_quirks & UFS_DEVICE_QUIRK_NO_PURGE) ? "Yes" : "No");
+}
+
 static int ufs_start(struct ufs_hba *hba)
 {
 	struct ufs_dev_desc card = {0};
@@ -2268,6 +2320,8 @@ static int ufs_start(struct ufs_hba *hba)
 		ufshcd_print_pwr_info(hba);
 	}
 
+	ufshcd_print_dev_info(hba, &card);
+
 	return 0;
 }
 

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH u-boot 6/8] ufs: print device information at probe
@ 2026-10-04 19:22   ` Petr Hodina
  0 siblings, 0 replies; 26+ messages in thread
From: Petr Hodina @ 2026-10-04 19:22 UTC (permalink / raw)
  To: u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	David Heidelberg, Marek Vasut, Padmarao Begari, Macpaul Lin,
	Julien Stephan, Kunihiko Hayashi, Shawn Lin, Jared McArthur,
	Michal Simek, Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata, Petr Hodina

Dump the key UFS device properties (manufacturer, model, fw revision,
spec version, negotiated gear/lane/power, and the applied device quirks)
at the end of ufs_start().

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
 drivers/ufs/ufs-uclass.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
index 7dfba3ac1ac..3cc4fd6bde3 100644
--- a/drivers/ufs/ufs-uclass.c
+++ b/drivers/ufs/ufs-uclass.c
@@ -2218,6 +2218,58 @@ static void ufshcd_def_desc_sizes(struct ufs_hba *hba)
 	hba->desc_size.hlth_desc = QUERY_DESC_HEALTH_DEF_SIZE;
 }
 
+/* Map a JEDEC UFS manufacturer id to a human-readable vendor name */
+static const char *ufshcd_vendor_name(u16 mid)
+{
+	switch (mid) {
+	case UFS_VENDOR_TOSHIBA:	return "Toshiba/Kioxia";
+	case UFS_VENDOR_SAMSUNG:	return "Samsung";
+	case UFS_VENDOR_SKHYNIX:	return "SK Hynix";
+	case UFS_VENDOR_MICRON:		return "Micron";
+	case UFS_VENDOR_WDC:		return "Western Digital";
+	default:			return NULL;
+	}
+}
+
+static void ufshcd_rtrim(char *s)
+{
+	size_t n = strlen(s);
+
+	while (n && s[n - 1] == ' ')
+		s[--n] = '\0';
+}
+
+static void ufshcd_print_dev_info(struct ufs_hba *hba,
+				  struct ufs_dev_desc *card)
+{
+	const char *vendor = ufshcd_vendor_name(card->wmanufacturerid);
+
+	ufshcd_rtrim(card->model);
+	ufshcd_rtrim(card->revision);
+
+	printf("UFS Device Information (%s)\n", hba->dev->name);
+	if (vendor)
+		printf("  Manufacturer:    %s (0x%04x)\n", vendor,
+		       card->wmanufacturerid);
+	else
+		printf("  Manufacturer ID: 0x%04x\n", card->wmanufacturerid);
+	printf("  Model:           %s\n",
+	       card->model[0] ? card->model : "(unset)");
+	printf("  Revision:        %s\n",
+	       card->revision[0] ? card->revision : "(unset)");
+	printf("  Spec Version:    0x%04x\n", card->wspecversion);
+	printf("  Gear  - RX: %u, TX: %u\n",
+	       hba->pwr_info.gear_rx, hba->pwr_info.gear_tx);
+	printf("  Lane  - RX: %u, TX: %u\n",
+	       hba->pwr_info.lane_rx, hba->pwr_info.lane_tx);
+	printf("  Power - RX: %u, TX: %u, HS rate: %u\n",
+	       hba->pwr_info.pwr_rx, hba->pwr_info.pwr_tx,
+	       hba->pwr_info.hs_rate);
+	printf("  Device Quirks:   0x%08x\n", hba->dev_quirks);
+	printf("  NO_PURGE Quirk:  %s\n",
+	       (hba->dev_quirks & UFS_DEVICE_QUIRK_NO_PURGE) ? "Yes" : "No");
+}
+
 static int ufs_start(struct ufs_hba *hba)
 {
 	struct ufs_dev_desc card = {0};
@@ -2268,6 +2320,8 @@ static int ufs_start(struct ufs_hba *hba)
 		ufshcd_print_pwr_info(hba);
 	}
 
+	ufshcd_print_dev_info(hba, &card);
+
 	return 0;
 }
 

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH u-boot 7/8] ufs: gate NO_PURGE on Sony Yoshino/Tama platform compatible
  2026-10-04 19:22 ` Petr Hodina
@ 2026-10-04 19:22   ` Petr Hodina
  -1 siblings, 0 replies; 26+ messages in thread
From: Petr Hodina via B4 Relay @ 2026-10-04 19:22 UTC (permalink / raw)
  To: u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	David Heidelberg, Marek Vasut, Padmarao Begari, Macpaul Lin,
	Julien Stephan, Kunihiko Hayashi, Shawn Lin, Jared McArthur,
	Michal Simek, Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata, Petr Hodina

From: Petr Hodina <petr.hodina@protonmail.com>

Apply NO_PURGE unconditionally on Sony Yoshino (msm8998) and Tama
(sdm845) phones, regardless of which UFS chip is fitted:

- Units across batches ship with a mix of Samsung, SK Hynix, and
  Toshiba UFS parts, so a single per-model quirk-table row can't
  cover the whole population.
- Those chips consistently leave iProductName and
  iProductRevisionLevel blank in the UFS device descriptor, which
  defeats the model/revision string match the quirk table relies on.
- The spec-version fallback (wspecversion < 0x210) has an off-by-one
  gap for these devices: they report UFS spec version 0x210 (UFS 2.1)
  exactly, which the strict "<" comparison doesn't catch.

Gate NO_PURGE on the DT root compatible instead, which is reliable
regardless of which UFS chip a given unit shipped with.

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
 drivers/ufs/ufs-uclass.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
index 3cc4fd6bde3..f88949bffd3 100644
--- a/drivers/ufs/ufs-uclass.c
+++ b/drivers/ufs/ufs-uclass.c
@@ -1880,6 +1880,35 @@ out:
 	return err;
 }
 
+/*
+ * Platforms whose bootloader / RPMB layout overlaps the UFS LUN0
+ * provisioning region and cannot tolerate UNMAP/PURGE.
+ * Any erase command issued against the boot LU bricks the device. The quirk
+ * has to apply regardless of which UFS supplier is fitted (Samsung, SK Hynix
+ * or Toshiba)
+ */
+static const char * const ufs_no_purge_platforms[] = {
+	/* Sony Yoshino (msm8998): XZ1 / XZ1 Compact / XZ Premium */
+	"sony,xperia-lilac",
+	"sony,xperia-maple",
+	"sony,xperia-poplar",
+	/* Sony Tama (sdm845): XZ2 / XZ2 Compact / XZ3 */
+	"sony,akari-row",
+	"sony,akatsuki-row",
+	"sony,apollo-row",
+	NULL,
+};
+
+static bool ufshcd_platform_needs_no_purge(void)
+{
+	const char * const *p;
+
+	for (p = ufs_no_purge_platforms; *p; p++)
+		if (of_machine_is_compatible(*p))
+			return true;
+	return false;
+}
+
 /*
  * UFS device quirk table. Entries are matched by manufacturer id, model and
  * fw revision; UFS_ANY_VENDOR / UFS_ANY_MODEL / UFS_ANY_VER act as wildcards.
@@ -1916,6 +1945,10 @@ static void ufshcd_fixup_dev_quirks(struct ufs_hba *hba,
 	if (dev_desc->wspecversion < UFS_PURGE_SPEC_VER)
 		hba->dev_quirks |= UFS_DEVICE_QUIRK_NO_PURGE;
 
+	/* Platform-driven NO_PURGE */
+	if (ufshcd_platform_needs_no_purge())
+		hba->dev_quirks |= UFS_DEVICE_QUIRK_NO_PURGE;
+
 	for (f = ufs_fixups; f->quirk; f++) {
 		if ((f->wmanufacturerid == dev_desc->wmanufacturerid ||
 		     f->wmanufacturerid == UFS_ANY_VENDOR) &&

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH u-boot 7/8] ufs: gate NO_PURGE on Sony Yoshino/Tama platform compatible
@ 2026-10-04 19:22   ` Petr Hodina
  0 siblings, 0 replies; 26+ messages in thread
From: Petr Hodina @ 2026-10-04 19:22 UTC (permalink / raw)
  To: u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	David Heidelberg, Marek Vasut, Padmarao Begari, Macpaul Lin,
	Julien Stephan, Kunihiko Hayashi, Shawn Lin, Jared McArthur,
	Michal Simek, Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata, Petr Hodina

Apply NO_PURGE unconditionally on Sony Yoshino (msm8998) and Tama
(sdm845) phones, regardless of which UFS chip is fitted:

- Units across batches ship with a mix of Samsung, SK Hynix, and
  Toshiba UFS parts, so a single per-model quirk-table row can't
  cover the whole population.
- Those chips consistently leave iProductName and
  iProductRevisionLevel blank in the UFS device descriptor, which
  defeats the model/revision string match the quirk table relies on.
- The spec-version fallback (wspecversion < 0x210) has an off-by-one
  gap for these devices: they report UFS spec version 0x210 (UFS 2.1)
  exactly, which the strict "<" comparison doesn't catch.

Gate NO_PURGE on the DT root compatible instead, which is reliable
regardless of which UFS chip a given unit shipped with.

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
 drivers/ufs/ufs-uclass.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
index 3cc4fd6bde3..f88949bffd3 100644
--- a/drivers/ufs/ufs-uclass.c
+++ b/drivers/ufs/ufs-uclass.c
@@ -1880,6 +1880,35 @@ out:
 	return err;
 }
 
+/*
+ * Platforms whose bootloader / RPMB layout overlaps the UFS LUN0
+ * provisioning region and cannot tolerate UNMAP/PURGE.
+ * Any erase command issued against the boot LU bricks the device. The quirk
+ * has to apply regardless of which UFS supplier is fitted (Samsung, SK Hynix
+ * or Toshiba)
+ */
+static const char * const ufs_no_purge_platforms[] = {
+	/* Sony Yoshino (msm8998): XZ1 / XZ1 Compact / XZ Premium */
+	"sony,xperia-lilac",
+	"sony,xperia-maple",
+	"sony,xperia-poplar",
+	/* Sony Tama (sdm845): XZ2 / XZ2 Compact / XZ3 */
+	"sony,akari-row",
+	"sony,akatsuki-row",
+	"sony,apollo-row",
+	NULL,
+};
+
+static bool ufshcd_platform_needs_no_purge(void)
+{
+	const char * const *p;
+
+	for (p = ufs_no_purge_platforms; *p; p++)
+		if (of_machine_is_compatible(*p))
+			return true;
+	return false;
+}
+
 /*
  * UFS device quirk table. Entries are matched by manufacturer id, model and
  * fw revision; UFS_ANY_VENDOR / UFS_ANY_MODEL / UFS_ANY_VER act as wildcards.
@@ -1916,6 +1945,10 @@ static void ufshcd_fixup_dev_quirks(struct ufs_hba *hba,
 	if (dev_desc->wspecversion < UFS_PURGE_SPEC_VER)
 		hba->dev_quirks |= UFS_DEVICE_QUIRK_NO_PURGE;
 
+	/* Platform-driven NO_PURGE */
+	if (ufshcd_platform_needs_no_purge())
+		hba->dev_quirks |= UFS_DEVICE_QUIRK_NO_PURGE;
+
 	for (f = ufs_fixups; f->quirk; f++) {
 		if ((f->wmanufacturerid == dev_desc->wmanufacturerid ||
 		     f->wmanufacturerid == UFS_ANY_VENDOR) &&

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH u-boot 8/8] arm: dts: qcom: akatsuki: re-enable the UFS controller node
  2026-10-04 19:22 ` Petr Hodina
@ 2026-10-04 19:22   ` Petr Hodina
  -1 siblings, 0 replies; 26+ messages in thread
From: Petr Hodina via B4 Relay @ 2026-10-04 19:22 UTC (permalink / raw)
  To: u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	David Heidelberg, Marek Vasut, Padmarao Begari, Macpaul Lin,
	Julien Stephan, Kunihiko Hayashi, Shawn Lin, Jared McArthur,
	Michal Simek, Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata, Petr Hodina

From: Petr Hodina <petr.hodina@protonmail.com>

Upstream Linux explicitly disables ufs_mem_hc/ufs_mem_phy for all Tama
devices (sdm845-sony-xperia-tama.dtsi):

    /* BIG WARNING! DO NOT TOUCH UFS, YOUR DEVICE WILL DIE! */
    &ufs_mem_hc { status = "disabled"; };
    &ufs_mem_phy { status = "disabled"; };

PURGE/UNMAP command issued to these devices' UFS erases the bootloader
and permanently bricks the device.

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
 MAINTAINERS                                               | 1 +
 arch/arm/dts/sdm845-sony-xperia-tama-akatsuki-u-boot.dtsi | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 45e9076de67..9d6aa8126b7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -687,6 +687,7 @@ R:	Sumit Garg <sumit.garg@kernel.org>
 L:	u-boot-qcom@groups.io
 S:	Maintained
 T:	git https://source.denx.de/u-boot/custodians/u-boot-snapdragon.git
+F:	arch/arm/dts/sdm845-sony-xperia-tama-akatsuki-u-boot.dtsi
 F:	configs/qcm6490_defconfig
 F:	configs/qcs9100_defconfig
 F:	drivers/*/*/pm8???-*
diff --git a/arch/arm/dts/sdm845-sony-xperia-tama-akatsuki-u-boot.dtsi b/arch/arm/dts/sdm845-sony-xperia-tama-akatsuki-u-boot.dtsi
new file mode 100644
index 00000000000..a6e7ba45e92
--- /dev/null
+++ b/arch/arm/dts/sdm845-sony-xperia-tama-akatsuki-u-boot.dtsi
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
+
+&ufs_mem_hc {
+	status = "okay";
+};
+
+&ufs_mem_phy {
+	status = "okay";
+};

-- 
2.55.0



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH u-boot 8/8] arm: dts: qcom: akatsuki: re-enable the UFS controller node
@ 2026-10-04 19:22   ` Petr Hodina
  0 siblings, 0 replies; 26+ messages in thread
From: Petr Hodina @ 2026-10-04 19:22 UTC (permalink / raw)
  To: u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	David Heidelberg, Marek Vasut, Padmarao Begari, Macpaul Lin,
	Julien Stephan, Kunihiko Hayashi, Shawn Lin, Jared McArthur,
	Michal Simek, Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata, Petr Hodina

Upstream Linux explicitly disables ufs_mem_hc/ufs_mem_phy for all Tama
devices (sdm845-sony-xperia-tama.dtsi):

    /* BIG WARNING! DO NOT TOUCH UFS, YOUR DEVICE WILL DIE! */
    &ufs_mem_hc { status = "disabled"; };
    &ufs_mem_phy { status = "disabled"; };

PURGE/UNMAP command issued to these devices' UFS erases the bootloader
and permanently bricks the device.

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
 MAINTAINERS                                               | 1 +
 arch/arm/dts/sdm845-sony-xperia-tama-akatsuki-u-boot.dtsi | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 45e9076de67..9d6aa8126b7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -687,6 +687,7 @@ R:	Sumit Garg <sumit.garg@kernel.org>
 L:	u-boot-qcom@groups.io
 S:	Maintained
 T:	git https://source.denx.de/u-boot/custodians/u-boot-snapdragon.git
+F:	arch/arm/dts/sdm845-sony-xperia-tama-akatsuki-u-boot.dtsi
 F:	configs/qcm6490_defconfig
 F:	configs/qcs9100_defconfig
 F:	drivers/*/*/pm8???-*
diff --git a/arch/arm/dts/sdm845-sony-xperia-tama-akatsuki-u-boot.dtsi b/arch/arm/dts/sdm845-sony-xperia-tama-akatsuki-u-boot.dtsi
new file mode 100644
index 00000000000..a6e7ba45e92
--- /dev/null
+++ b/arch/arm/dts/sdm845-sony-xperia-tama-akatsuki-u-boot.dtsi
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
+
+&ufs_mem_hc {
+	status = "okay";
+};
+
+&ufs_mem_phy {
+	status = "okay";
+};

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH u-boot 0/8] ufs: Sony Yoshino/Tama (MSM8998 / SDM845) UFS bring-up
  2026-10-04 19:22 ` Petr Hodina
                   ` (8 preceding siblings ...)
  (?)
@ 2026-10-04 19:30 ` David Heidelberg
  -1 siblings, 0 replies; 26+ messages in thread
From: David Heidelberg @ 2026-10-04 19:30 UTC (permalink / raw)
  To: petr.hodina, u-boot, Sumit Garg, u-boot-qcom
  Cc: Neil Armstrong, Bhupesh Sharma, Neha Malcom Francis,
	Casey Connolly, Tom Rini, Angelo Gioacchino Del Regno,
	Marek Vasut, Padmarao Begari, Macpaul Lin, Julien Stephan,
	Kunihiko Hayashi, Shawn Lin, Jared McArthur, Michal Simek,
	Udit Kumar, Igor Belwon, Tuyen Dang, Alexey Charkov,
	Balaji Selvanathan, Simon Glass, Aswin Murugan, Bin Meng,
	Marek Vasut, David Lechner, Ilias Apalodimas, Kory Maincent,
	Peng Fan, Kuan-Wei Chiu, Janne Grunau, Julien Masson, Raymond Mao,
	Quentin Schulz, Philip Molloy, Jerome Forissier, Markus Niebel,
	Petr Pavlata

On 04/10/2026 21:22, Petr Hodina via B4 Relay wrote:
> This series brings up UFS on the Sony Xperia "Yoshino" (MSM8998) and
> "Tama" (SDM845) families.
> 
> The work falls into four layers:
> 
> 1. A small refactor that extends ufs_dev_desc with the product revision
>     string and the UFS spec version (patch 1). No behaviour change.
> 
> 2. A device-quirk infrastructure (patches 2-4) that lets us match
>     per-device link / power-mode workarounds against manufacturer id,
>     model and fw revision:
> 
>       - patch 2: generic ufs_fixups[] table and ufshcd_fixup_dev_quirks(),
>         called from ufs_start() before power-mode negotiation
>       - patch 3: UFS_DEVICE_QUIRK_EXTEND_SYNC_LENGTH for SK Hynix devices
>         that need PA_TxHsG{1,2,3}SyncLength programmed to 0x48
>       - patch 4: CONFIG_UFS_RESTRICT_TX_LANES build-time knob for boards
>         with only a single reliable TX lane. Defaults to N so nothing
>         else is affected.
> 
> 3. The NO_PURGE quirk for devices that brick if issued PURGE / UNMAP
>     (patches 5-7):
> 
>       - patch 5: refuse erase/UNMAP in the SCSI uclass when NO_PURGE
>         is set on the underlying UFS device
>       - patch 6: print device identification (vendor / model / rev /
>         spec version) at probe so quirk matching is observable on the
>         console
>       - patch 7: a platform gate that auto-enables NO_PURGE on Sony
>         Yoshino/Tama compatibles because per-UFS-chip rows can't see
>         blank string descriptors on some affected boards.
> 
> 4. Akatsuki DTS enablement (patch 8): re-enable the UFS controller node.
> 
> Background on NO_PURGE: on the affected Sony platforms the SCSI ERASE /
> UNMAP / WRITE_BUFFER PURGE operation overwrites the bootloader region
> and permanently bricks the device.
> 
> Based on the linux patches by Angelo:
> https://github.com/kholk/kernel/commit/2e7a9ee1c91a016baa0b826a7752ec45663a0561
> 
> Tested on Sony XZ3 (akatsuki, SDM845) where U-Boot enumerates UFS LUN0
> and exposes the GPT.
> 
> ```
> UFS Device Information (ufshc@1d84000)
>    Manufacturer:    Samsung (0x01ce)
>    Model:           (unset)
>    Revision:        (unset)
>    Spec Version:    0x0210
>    Gear  - RX: 3, TX: 3
>    Lane  - RX: 2, TX: 2
>    Power - RX: 1, TX: 1, HS rate: 2
>    Device Quirks:   0x00000001
>    NO_PURGE Quirk:  Yes
> 
> ...
> 
> => scsi erase 0 1
> 
> scsi erase: device 0 block # 0, count 1 ... scsi_erase: erase not supported on this device
> 0 blocks erased: ERROR
> =>
> ```
> 
Hi Petr,

very happy to see this series! So many Sony devices of this generation can be 
re-purposed but this was the main blocker.

 From sample of 25 people on today's workshop, there was one Xperia with this 
issues (and since we didn't had microSD, we couldn't install anything).

Series,

Acked-by: David Heidelberg <david@ixit.cz>

David

P.S. I assume when mainline kernel gets the fixes for their driver too, you'll 
revert the manual override in
` arm: dts: qcom: akatsuki: re-enable the UFS controller node`

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH u-boot 6/8] ufs: print device information at probe
  2026-10-04 19:22   ` Petr Hodina
  (?)
@ 2026-10-05  9:36   ` Neil Armstrong
  -1 siblings, 0 replies; 26+ messages in thread
From: Neil Armstrong @ 2026-10-05  9:36 UTC (permalink / raw)
  To: petr.hodina, u-boot, Sumit Garg, u-boot-qcom
  Cc: Bhupesh Sharma, Neha Malcom Francis, Casey Connolly, Tom Rini,
	Angelo Gioacchino Del Regno, David Heidelberg, Marek Vasut,
	Padmarao Begari, Macpaul Lin, Julien Stephan, Kunihiko Hayashi,
	Shawn Lin, Jared McArthur, Michal Simek, Udit Kumar, Igor Belwon,
	Tuyen Dang, Alexey Charkov, Balaji Selvanathan, Simon Glass,
	Aswin Murugan, Bin Meng, Marek Vasut, David Lechner,
	Ilias Apalodimas, Kory Maincent, Peng Fan, Kuan-Wei Chiu,
	Janne Grunau, Julien Masson, Raymond Mao, Quentin Schulz,
	Philip Molloy, Jerome Forissier, Markus Niebel, Petr Pavlata

Hi,

On 10/4/26 21:22, Petr Hodina via B4 Relay wrote:
> From: Petr Hodina <petr.hodina@protonmail.com>
> 
> Dump the key UFS device properties (manufacturer, model, fw revision,
> spec version, negotiated gear/lane/power, and the applied device quirks)
> at the end of ufs_start().

Can you add a Kconfig config to enable this ?

Thanks,
Neil

> 
> Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
> ---
>   drivers/ufs/ufs-uclass.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 54 insertions(+)
> 
> diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
> index 7dfba3ac1ac..3cc4fd6bde3 100644
> --- a/drivers/ufs/ufs-uclass.c
> +++ b/drivers/ufs/ufs-uclass.c
> @@ -2218,6 +2218,58 @@ static void ufshcd_def_desc_sizes(struct ufs_hba *hba)
>   	hba->desc_size.hlth_desc = QUERY_DESC_HEALTH_DEF_SIZE;
>   }
>   
> +/* Map a JEDEC UFS manufacturer id to a human-readable vendor name */
> +static const char *ufshcd_vendor_name(u16 mid)
> +{
> +	switch (mid) {
> +	case UFS_VENDOR_TOSHIBA:	return "Toshiba/Kioxia";
> +	case UFS_VENDOR_SAMSUNG:	return "Samsung";
> +	case UFS_VENDOR_SKHYNIX:	return "SK Hynix";
> +	case UFS_VENDOR_MICRON:		return "Micron";
> +	case UFS_VENDOR_WDC:		return "Western Digital";
> +	default:			return NULL;
> +	}
> +}
> +
> +static void ufshcd_rtrim(char *s)
> +{
> +	size_t n = strlen(s);
> +
> +	while (n && s[n - 1] == ' ')
> +		s[--n] = '\0';
> +}
> +
> +static void ufshcd_print_dev_info(struct ufs_hba *hba,
> +				  struct ufs_dev_desc *card)
> +{
> +	const char *vendor = ufshcd_vendor_name(card->wmanufacturerid);
> +
> +	ufshcd_rtrim(card->model);
> +	ufshcd_rtrim(card->revision);
> +
> +	printf("UFS Device Information (%s)\n", hba->dev->name);
> +	if (vendor)
> +		printf("  Manufacturer:    %s (0x%04x)\n", vendor,
> +		       card->wmanufacturerid);
> +	else
> +		printf("  Manufacturer ID: 0x%04x\n", card->wmanufacturerid);
> +	printf("  Model:           %s\n",
> +	       card->model[0] ? card->model : "(unset)");
> +	printf("  Revision:        %s\n",
> +	       card->revision[0] ? card->revision : "(unset)");
> +	printf("  Spec Version:    0x%04x\n", card->wspecversion);
> +	printf("  Gear  - RX: %u, TX: %u\n",
> +	       hba->pwr_info.gear_rx, hba->pwr_info.gear_tx);
> +	printf("  Lane  - RX: %u, TX: %u\n",
> +	       hba->pwr_info.lane_rx, hba->pwr_info.lane_tx);
> +	printf("  Power - RX: %u, TX: %u, HS rate: %u\n",
> +	       hba->pwr_info.pwr_rx, hba->pwr_info.pwr_tx,
> +	       hba->pwr_info.hs_rate);
> +	printf("  Device Quirks:   0x%08x\n", hba->dev_quirks);
> +	printf("  NO_PURGE Quirk:  %s\n",
> +	       (hba->dev_quirks & UFS_DEVICE_QUIRK_NO_PURGE) ? "Yes" : "No");
> +}
> +
>   static int ufs_start(struct ufs_hba *hba)
>   {
>   	struct ufs_dev_desc card = {0};
> @@ -2268,6 +2320,8 @@ static int ufs_start(struct ufs_hba *hba)
>   		ufshcd_print_pwr_info(hba);
>   	}
>   
> +	ufshcd_print_dev_info(hba, &card);
> +
>   	return 0;
>   }
>   
> 


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH u-boot 5/8] scsi: ufs: refuse erase/UNMAP on NO_PURGE devices
  2026-10-04 19:22   ` Petr Hodina
  (?)
@ 2026-10-05  9:37   ` Neil Armstrong
  -1 siblings, 0 replies; 26+ messages in thread
From: Neil Armstrong @ 2026-10-05  9:37 UTC (permalink / raw)
  To: petr.hodina, u-boot, Sumit Garg, u-boot-qcom
  Cc: Bhupesh Sharma, Neha Malcom Francis, Casey Connolly, Tom Rini,
	Angelo Gioacchino Del Regno, David Heidelberg, Marek Vasut,
	Padmarao Begari, Macpaul Lin, Julien Stephan, Kunihiko Hayashi,
	Shawn Lin, Jared McArthur, Michal Simek, Udit Kumar, Igor Belwon,
	Tuyen Dang, Alexey Charkov, Balaji Selvanathan, Simon Glass,
	Aswin Murugan, Bin Meng, Marek Vasut, David Lechner,
	Ilias Apalodimas, Kory Maincent, Peng Fan, Kuan-Wei Chiu,
	Janne Grunau, Julien Masson, Raymond Mao, Quentin Schulz,
	Philip Molloy, Jerome Forissier, Markus Niebel, Petr Pavlata

Hi,

On 10/4/26 21:22, Petr Hodina via B4 Relay wrote:
> From: Petr Hodina <petr.hodina@protonmail.com>
> 
> Enforce the UFS_DEVICE_QUIRK_NO_PURGE quirk on U-Boot's only path that
> can reach a UFS device with a destructive UNMAP: the block-device erase
> op (scsi_erase() -> SCSI_UNMAP). On Sony Yoshino/Tama a PURGE/UNMAP
> erases the bootloader and permanently bricks the device.
> 
> Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
> ---
>   drivers/scsi/scsi.c      |  5 +++++
>   drivers/ufs/ufs-uclass.c | 12 ++++++++++++
>   include/scsi.h           |  5 +++++
>   3 files changed, 22 insertions(+)
> 
> diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
> index 50e7d749921..ba7834ea035 100644
> --- a/drivers/scsi/scsi.c
> +++ b/drivers/scsi/scsi.c
> @@ -300,6 +300,11 @@ static ulong scsi_erase(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt)
>   	lbaint_t start, blks, max_blks, blocks;
>   	struct scsi_cmd *pccb = (struct scsi_cmd *)&tempccb;
>   
> +	if (uc_plat->no_erase) {
> +		printf("%s: erase not supported on this device\n", __func__);
> +		return 0;
> +	}
> +
>   	/* Setup device */
>   	pccb->target = block_dev->target;
>   	pccb->lun = block_dev->lun;
> diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
> index 977ffebc21f..7dfba3ac1ac 100644
> --- a/drivers/ufs/ufs-uclass.c
> +++ b/drivers/ufs/ufs-uclass.c
> @@ -2366,6 +2366,18 @@ int ufshcd_probe(struct udevice *ufs_dev, struct ufs_hba_ops *hba_ops)
>   	if (err)
>   		return err;
>   
> +	/*
> +	 * Some devices must never receive a PURGE / UNMAP (secure erase): on
> +	 * the affected platforms it erases the bootloader and permanently
> +	 * bricks the device. Disable the SCSI erase op for the whole UFS
> +	 * device in that case.
> +	 */
> +	if (hba->dev_quirks & UFS_DEVICE_QUIRK_NO_PURGE) {
> +		scsi_plat->no_erase = true;
> +		dev_info(hba->dev,
> +			 "NO_PURGE quirk active: SCSI erase/UNMAP disabled\n");
> +	}
> +
>   	return 0;
>   }
>   
> diff --git a/include/scsi.h b/include/scsi.h
> index 2520a8b8fe6..fc296285dd5 100644
> --- a/include/scsi.h
> +++ b/include/scsi.h
> @@ -275,6 +275,11 @@ struct scsi_plat {
>   	unsigned long max_lun;
>   	unsigned long max_id;
>   	unsigned long max_bytes_per_req;
> +	/*
> +	 * Set by the controller driver to forbid the erase (UNMAP) operation,
> +	 * e.g. for UFS devices whose PURGE/UNMAP would erase the bootloader.
> +	 */
> +	bool no_erase;

To avoid proliferation of variables here, could you add a quirks variable instead and
move the no_erase into a SCSI quirk define.

Thanks,
Neil

>   };
>   
>   /* Operations for SCSI */
> 


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH u-boot 2/8] ufs: add device-quirk infrastructure
  2026-10-04 19:22   ` Petr Hodina
  (?)
@ 2026-10-05  9:40   ` Neil Armstrong
  2026-10-06 13:23     ` phodina
  -1 siblings, 1 reply; 26+ messages in thread
From: Neil Armstrong @ 2026-10-05  9:40 UTC (permalink / raw)
  To: petr.hodina, u-boot, Sumit Garg, u-boot-qcom
  Cc: Bhupesh Sharma, Neha Malcom Francis, Casey Connolly, Tom Rini,
	Angelo Gioacchino Del Regno, David Heidelberg, Marek Vasut,
	Padmarao Begari, Macpaul Lin, Julien Stephan, Kunihiko Hayashi,
	Shawn Lin, Jared McArthur, Michal Simek, Udit Kumar, Igor Belwon,
	Tuyen Dang, Alexey Charkov, Balaji Selvanathan, Simon Glass,
	Aswin Murugan, Bin Meng, Marek Vasut, David Lechner,
	Ilias Apalodimas, Kory Maincent, Peng Fan, Kuan-Wei Chiu,
	Janne Grunau, Julien Masson, Raymond Mao, Quentin Schulz,
	Philip Molloy, Jerome Forissier, Markus Niebel, Petr Pavlata

Hi,

On 10/4/26 21:22, Petr Hodina via B4 Relay wrote:
> From: Petr Hodina <petr.hodina@protonmail.com>
> 
> Infrastructure (ufs_quirks.h):
>   - struct ufs_dev_quirk plus UFS_FIX()/UFS_FIX_REVISION() helpers.
>   - ufshcd_fixup_dev_quirks() applies the table (and sets NO_PURGE for
>     devices older than UFS_PURGE_SPEC_VER) from ufs_start(), before power
>     mode negotiation so link quirks take effect.
>   - hba gains a dev_quirks field, distinct from the host controller
>     quirks (hba->quirks).

In patch 7 you set the quirk for the Sony Yoshino/Tama platforms, but
I'm not sure we need to add the quirk for those UFSs on other platforms.

Is this really needed for all platforms ?

Neil>
> Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
> ---
>   drivers/ufs/ufs-uclass.c | 52 +++++++++++++++++++++++++++++
>   drivers/ufs/ufs.h        |  2 ++
>   drivers/ufs/ufs_quirks.h | 87 ++++++++++++++++++++++++++++++++++++++++++++++++
>   3 files changed, 141 insertions(+)
> 
> diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
> index 56118a0ee46..05b95c510b4 100644
> --- a/drivers/ufs/ufs-uclass.c
> +++ b/drivers/ufs/ufs-uclass.c
> @@ -29,6 +29,7 @@
>   #include <linux/dma-mapping.h>
>   
>   #include "ufs.h"
> +#include "ufs_quirks.h"
>   
>   #define UFSHCD_ENABLE_INTRS	(UTP_TRANSFER_REQ_COMPL |\
>   				 UTP_TASK_REQ_COMPL |\
> @@ -1866,6 +1867,54 @@ out:
>   	return err;
>   }
>   
> +/*
> + * UFS device quirk table. Entries are matched by manufacturer id, model and
> + * fw revision; UFS_ANY_VENDOR / UFS_ANY_MODEL / UFS_ANY_VER act as wildcards.
> + */
> +static const struct ufs_dev_quirk ufs_fixups[] = {
> +	/* Sony Yoshino/Tama: block PURGE/UNMAP to avoid bricking */
> +	UFS_FIX_REVISION(UFS_VENDOR_SKHYNIX, UFS_MODEL_HYNIX_32GB,
> +			 UFS_REVISION_HYNIX, UFS_DEVICE_QUIRK_NO_PURGE),
> +	UFS_FIX_REVISION(UFS_VENDOR_SKHYNIX, UFS_MODEL_HYNIX_64GB,
> +			 UFS_REVISION_HYNIX, UFS_DEVICE_QUIRK_NO_PURGE),
> +	UFS_FIX_REVISION(UFS_VENDOR_SAMSUNG, UFS_MODEL_SAMSUNG_64GB,
> +			 UFS_REVISION_SAMSUNG, UFS_DEVICE_QUIRK_NO_PURGE),
> +	END_FIX
> +};
> +
> +/**
> + * ufshcd_fixup_dev_quirks - apply device-specific quirks
> + *
> + * Sets hba->dev_quirks based on the UFS spec version and the per-device
> + * fixup table above.
> + */
> +static void ufshcd_fixup_dev_quirks(struct ufs_hba *hba,
> +				    struct ufs_dev_desc *dev_desc)
> +{
> +	const struct ufs_dev_quirk *f;
> +
> +	/*
> +	 * Devices implementing an older UFS spec must not be issued PURGE /
> +	 * UNMAP, doing so erases the bootloader on affected platforms.
> +	 */
> +	if (dev_desc->wspecversion < UFS_PURGE_SPEC_VER)
> +		hba->dev_quirks |= UFS_DEVICE_QUIRK_NO_PURGE;
> +
> +	for (f = ufs_fixups; f->quirk; f++) {
> +		if ((f->wmanufacturerid == dev_desc->wmanufacturerid ||
> +		     f->wmanufacturerid == UFS_ANY_VENDOR) &&
> +		    (str_prfx_equal(f->model, dev_desc->model) ||
> +		     !strcmp(f->model, UFS_ANY_MODEL)) &&
> +		    (str_prfx_equal(f->revision, dev_desc->revision) ||
> +		     !strcmp(f->revision, UFS_ANY_VER)))
> +			hba->dev_quirks |= f->quirk;
> +	}
> +
> +	if (hba->dev_quirks)
> +		dev_dbg(hba->dev, "%s: applied device quirks 0x%08x\n",
> +			__func__, hba->dev_quirks);
> +}
> +
>   struct ufs_ref_clk {
>   	unsigned long freq_hz;
>   	enum ufs_ref_clk_freq val;
> @@ -2175,6 +2224,9 @@ static int ufs_start(struct ufs_hba *hba)
>   		return ret;
>   	}
>   
> +	/* Apply device-specific quirks before negotiating the power mode */
> +	ufshcd_fixup_dev_quirks(hba, &card);
> +
>   	ufshcd_set_dev_ref_clk(hba);
>   
>   	if (ufshcd_get_max_pwr_mode(hba)) {
> diff --git a/drivers/ufs/ufs.h b/drivers/ufs/ufs.h
> index e3368a516e4..d4bcb7a1773 100644
> --- a/drivers/ufs/ufs.h
> +++ b/drivers/ufs/ufs.h
> @@ -707,6 +707,8 @@ struct ufs_hba {
>   	u32			version;
>   	u32			intr_mask;
>   	enum ufshcd_quirks	quirks;
> +	/* UFS device (not host controller) quirks, see ufs_quirks.h */
> +	u32			dev_quirks;
>   
>   	/* Virtual memory reference */
>   	struct utp_transfer_cmd_desc *ucdl;
> diff --git a/drivers/ufs/ufs_quirks.h b/drivers/ufs/ufs_quirks.h
> new file mode 100644
> index 00000000000..f5aa47722db
> --- /dev/null
> +++ b/drivers/ufs/ufs_quirks.h
> @@ -0,0 +1,87 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +/*
> + * UFS device quirks
> + *
> + * Ported from the Linux kernel (include/ufs/ufs_quirks.h) and the
> + * Sony Yoshino/Tama downstream UFS quirks/hacks.
> + */
> +#ifndef _UFS_QUIRKS_H
> +#define _UFS_QUIRKS_H
> +
> +#include <linux/bitops.h>
> +#include <linux/string.h>
> +
> +/* true if s1 (the fixup pattern) is a prefix of s2 (the device value) */
> +static inline bool str_prfx_equal(const char *s1, const char *s2)
> +{
> +	return strncmp(s1, s2, strlen(s1)) == 0;
> +}
> +
> +#define UFS_ANY_VENDOR		0xFFFF
> +#define UFS_ANY_MODEL		"ANY_MODEL"
> +#define UFS_ANY_VER		"ANY_VER"
> +
> +#define UFS_VENDOR_TOSHIBA	0x198
> +#define UFS_VENDOR_SAMSUNG	0x1CE
> +#define UFS_VENDOR_SKHYNIX	0x1AD
> +#define UFS_VENDOR_MICRON	0x12C
> +#define UFS_VENDOR_WDC		0x145
> +
> +/* UFS Samsung models */
> +#define UFS_MODEL_SAMSUNG_64GB	"KLUDG4U1EA-B0C1"
> +#define UFS_REVISION_SAMSUNG	"0100"
> +
> +/* UFS SK Hynix models */
> +#define UFS_MODEL_HYNIX_32GB	"hB8aL1"
> +#define UFS_MODEL_HYNIX_64GB	"hC8aL1"
> +#define UFS_REVISION_HYNIX	"D001"
> +
> +/*
> + * Devices with a UFS spec version older than this must not be issued PURGE /
> + * UNMAP (secure erase) operations: on the Sony Yoshino/Tama platforms doing so
> + * erases the bootloader and permanently bricks the device.
> + */
> +#define UFS_PURGE_SPEC_VER	0x210
> +
> +/**
> + * struct ufs_dev_quirk - ufs device quirk info
> + * @wmanufacturerid: card details (UFS_ANY_VENDOR matches any vendor)
> + * @model: card model (UFS_ANY_MODEL matches any model)
> + * @revision: card fw revision (UFS_ANY_VER matches any revision)
> + * @quirk: device quirk bitmask
> + */
> +struct ufs_dev_quirk {
> +	u16 wmanufacturerid;
> +	const char *model;
> +	const char *revision;
> +	unsigned int quirk;
> +};
> +
> +/* terminator for the fixup table */
> +#define END_FIX { 0, NULL, NULL, 0 }
> +
> +/* add a quirk for any revision of a specific model */
> +#define UFS_FIX(_vendor, _model, _quirk) {	\
> +	.wmanufacturerid = (_vendor),		\
> +	.model = (_model),			\
> +	.revision = (UFS_ANY_VER),		\
> +	.quirk = (_quirk),			\
> +}
> +
> +/* add a quirk for a specific model and fw revision */
> +#define UFS_FIX_REVISION(_vendor, _model, _revision, _quirk) {	\
> +	.wmanufacturerid = (_vendor),				\
> +	.model = (_model),					\
> +	.revision = (_revision),				\
> +	.quirk = (_quirk),					\
> +}
> +
> +/*
> + * Some Sony UFS devices must not use the PURGE / UNMAP (secure erase)
> + * operation as it would erase the bootloader and permanently brick the
> + * device. This quirk disables PURGE-related functionality for affected
> + * devices.
> + */
> +#define UFS_DEVICE_QUIRK_NO_PURGE		BIT(0)
> +
> +#endif /* _UFS_QUIRKS_H */
> 


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH u-boot 4/8] ufs: add CONFIG_UFS_RESTRICT_TX_LANES
  2026-10-04 19:22   ` Petr Hodina
  (?)
@ 2026-10-05  9:41   ` Neil Armstrong
  -1 siblings, 0 replies; 26+ messages in thread
From: Neil Armstrong @ 2026-10-05  9:41 UTC (permalink / raw)
  To: petr.hodina, u-boot, Sumit Garg, u-boot-qcom
  Cc: Bhupesh Sharma, Neha Malcom Francis, Casey Connolly, Tom Rini,
	Angelo Gioacchino Del Regno, David Heidelberg, Marek Vasut,
	Padmarao Begari, Macpaul Lin, Julien Stephan, Kunihiko Hayashi,
	Shawn Lin, Jared McArthur, Michal Simek, Udit Kumar, Igor Belwon,
	Tuyen Dang, Alexey Charkov, Balaji Selvanathan, Simon Glass,
	Aswin Murugan, Bin Meng, Marek Vasut, David Lechner,
	Ilias Apalodimas, Kory Maincent, Peng Fan, Kuan-Wei Chiu,
	Janne Grunau, Julien Masson, Raymond Mao, Quentin Schulz,
	Philip Molloy, Jerome Forissier, Markus Niebel, Petr Pavlata

On 10/4/26 21:22, Petr Hodina via B4 Relay wrote:
> From: Petr Hodina <petr.hodina@protonmail.com>
> 
> Add CONFIG_UFS_RESTRICT_TX_LANES, to restrict the amount
> PA_AVAILTXDATALANES = 1 at the start of ufshcd_link_startup().
> 
> Some platforms (notably the Sony Yoshino/Tama families on MSM8998 /
> SDM845) have only a single reliably-usable UFS TX lane.

Why can't this be a quirk set only on those platforms ?

Neil>
> Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
> ---
>   drivers/ufs/Kconfig      | 14 ++++++++++++++
>   drivers/ufs/ufs-uclass.c | 13 +++++++++++++
>   2 files changed, 27 insertions(+)
> 
> diff --git a/drivers/ufs/Kconfig b/drivers/ufs/Kconfig
> index 49472933de3..266e7180152 100644
> --- a/drivers/ufs/Kconfig
> +++ b/drivers/ufs/Kconfig
> @@ -8,6 +8,20 @@ config UFS
>   	  This selects support for Universal Flash Subsystem (UFS).
>   	  Say Y here if you want UFS Support.
>   
> +config UFS_RESTRICT_TX_LANES
> +	bool "Restrict the number of UFS TX lanes to 1"
> +	depends on UFS
> +	default n
> +	help
> +	  Say Y here to restrict the number of UFS TX lanes to 1. This saves
> +	  power at the cost of write performance.
> +
> +	  This is useful (and on some devices required) for platforms such as
> +	  the Sony Yoshino/Tama families where only a single TX lane is
> +	  reliably usable.
> +
> +	  If unsure, say N.
> +
>   config UFS_AMD_VERSAL2
>   	bool "AMD Versal Gen 2 UFS controller platform driver"
>   	depends on UFS && ZYNQMP_FIRMWARE
> diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c
> index fdf62a69c02..977ffebc21f 100644
> --- a/drivers/ufs/ufs-uclass.c
> +++ b/drivers/ufs/ufs-uclass.c
> @@ -508,6 +508,19 @@ static int ufshcd_link_startup(struct ufs_hba *hba)
>   	int ret;
>   	int retries = DME_LINKSTARTUP_RETRIES;
>   
> +	if (IS_ENABLED(CONFIG_UFS_RESTRICT_TX_LANES)) {
> +		/*
> +		 * Restrict the number of available TX lanes to 1. This saves
> +		 * power at the cost of write performance and is required on
> +		 * some platforms (e.g. Sony Yoshino/Tama) where only a single
> +		 * TX lane is reliably usable.
> +		 */
> +		ret = ufshcd_dme_set(hba, UIC_ARG_MIB(PA_AVAILTXDATALANES), 1);
> +		if (ret)
> +			dev_warn(hba->dev, "%s: failed to restrict TX lanes: %d\n",
> +				 __func__, ret);
> +	}
> +
>   	do {
>   		ret = ufshcd_ops_link_startup_notify(hba, PRE_CHANGE);
>   		if (ret)
> 


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH u-boot 2/8] ufs: add device-quirk infrastructure
  2026-10-05  9:40   ` Neil Armstrong
@ 2026-10-06 13:23     ` phodina
  2026-10-06 13:31       ` Neil Armstrong
  0 siblings, 1 reply; 26+ messages in thread
From: phodina @ 2026-10-06 13:23 UTC (permalink / raw)
  To: Neil Armstrong
  Cc: u-boot, Sumit Garg, u-boot-qcom, Bhupesh Sharma,
	Neha Malcom Francis, Casey Connolly, Tom Rini,
	Angelo Gioacchino Del Regno, David Heidelberg, Marek Vasut,
	Padmarao Begari, Macpaul Lin, Julien Stephan, Kunihiko Hayashi,
	Shawn Lin, Jared McArthur, Michal Simek, Udit Kumar, Igor Belwon,
	Tuyen Dang, Alexey Charkov, Balaji Selvanathan, Simon Glass,
	Aswin Murugan, Bin Meng, Marek Vasut, David Lechner,
	Ilias Apalodimas, Kory Maincent, Peng Fan, Kuan-Wei Chiu,
	Janne Grunau, Julien Masson, Raymond Mao, Quentin Schulz,
	Philip Molloy, Jerome Forissier, Markus Niebel, Petr Pavlata


On Monday, October 5th, 2026 at 11:40 AM, Neil Armstrong <neil.armstrong@linaro.org> wrote:

> Hi,
> 
> On 10/4/26 21:22, Petr Hodina via B4 Relay wrote:
> > From: Petr Hodina <petr.hodina@protonmail.com>
> >
> > Infrastructure (ufs_quirks.h):
> >   - struct ufs_dev_quirk plus UFS_FIX()/UFS_FIX_REVISION() helpers.
> >   - ufshcd_fixup_dev_quirks() applies the table (and sets NO_PURGE for
> >     devices older than UFS_PURGE_SPEC_VER) from ufs_start(), before power
> >     mode negotiation so link quirks take effect.
> >   - hba gains a dev_quirks field, distinct from the host controller
> >     quirks (hba->quirks).
> 
> In patch 7 you set the quirk for the Sony Yoshino/Tama platforms, but
> I'm not sure we need to add the quirk for those UFSs on other platforms.
> 
> Is this really needed for all platforms ?


This is more defensive approach to enable it for more platforms.

The reason is the device is a production unit with secure boot enabled.
Therefore I'm unable to provision again the device non-volatile storage.

Also there are no EDL loaders available unlike on some other platforms
so restoring the device is currently impossible.

Even with the loader just physically desoldering the UFS BGA chip, then
replacing it with a new programmed one with the dumped data and soldering
it to the board it would probably not be possible to boot as the RPMB block
would be missing the Authentication key only the manufacturer posses.

I'd assume this issue might be already fixed on newer platforms.
Would be great to compile a list of the platforms that definitely
need this fix.

Kind regards
Petr

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH u-boot 2/8] ufs: add device-quirk infrastructure
  2026-10-06 13:23     ` phodina
@ 2026-10-06 13:31       ` Neil Armstrong
  2026-10-06 13:39         ` phodina
  0 siblings, 1 reply; 26+ messages in thread
From: Neil Armstrong @ 2026-10-06 13:31 UTC (permalink / raw)
  To: phodina
  Cc: u-boot, Sumit Garg, u-boot-qcom, Bhupesh Sharma,
	Neha Malcom Francis, Casey Connolly, Tom Rini,
	Angelo Gioacchino Del Regno, David Heidelberg, Marek Vasut,
	Padmarao Begari, Macpaul Lin, Julien Stephan, Kunihiko Hayashi,
	Shawn Lin, Jared McArthur, Michal Simek, Udit Kumar, Igor Belwon,
	Tuyen Dang, Alexey Charkov, Balaji Selvanathan, Simon Glass,
	Aswin Murugan, Bin Meng, Marek Vasut, David Lechner,
	Ilias Apalodimas, Kory Maincent, Peng Fan, Kuan-Wei Chiu,
	Janne Grunau, Julien Masson, Raymond Mao, Quentin Schulz,
	Philip Molloy, Jerome Forissier, Markus Niebel, Petr Pavlata

On 10/6/26 15:23, phodina wrote:
> 
> On Monday, October 5th, 2026 at 11:40 AM, Neil Armstrong <neil.armstrong@linaro.org> wrote:
> 
>> Hi,
>>
>> On 10/4/26 21:22, Petr Hodina via B4 Relay wrote:
>>> From: Petr Hodina <petr.hodina@protonmail.com>
>>>
>>> Infrastructure (ufs_quirks.h):
>>>    - struct ufs_dev_quirk plus UFS_FIX()/UFS_FIX_REVISION() helpers.
>>>    - ufshcd_fixup_dev_quirks() applies the table (and sets NO_PURGE for
>>>      devices older than UFS_PURGE_SPEC_VER) from ufs_start(), before power
>>>      mode negotiation so link quirks take effect.
>>>    - hba gains a dev_quirks field, distinct from the host controller
>>>      quirks (hba->quirks).
>>
>> In patch 7 you set the quirk for the Sony Yoshino/Tama platforms, but
>> I'm not sure we need to add the quirk for those UFSs on other platforms.
>>
>> Is this really needed for all platforms ?
> 
> 
> This is more defensive approach to enable it for more platforms.
> 
> The reason is the device is a production unit with secure boot enabled.
> Therefore I'm unable to provision again the device non-volatile storage.
> 
> Also there are no EDL loaders available unlike on some other platforms
> so restoring the device is currently impossible.
> 
> Even with the loader just physically desoldering the UFS BGA chip, then
> replacing it with a new programmed one with the dumped data and soldering
> it to the board it would probably not be possible to boot as the RPMB block
> would be missing the Authentication key only the manufacturer posses.
> 
> I'd assume this issue might be already fixed on newer platforms.
> Would be great to compile a list of the platforms that definitely
> need this fix.

I'm aware of this issue, and I have a Sony sdm845 I'll love to reflash.

So I understand the defensive approach, but I was wondering if this same
change was sent to Linux ? I can't find one.

Neil

> 
> Kind regards
> Petr


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH u-boot 2/8] ufs: add device-quirk infrastructure
  2026-10-06 13:31       ` Neil Armstrong
@ 2026-10-06 13:39         ` phodina
  0 siblings, 0 replies; 26+ messages in thread
From: phodina @ 2026-10-06 13:39 UTC (permalink / raw)
  To: Neil Armstrong
  Cc: u-boot, Sumit Garg, u-boot-qcom, Bhupesh Sharma,
	Neha Malcom Francis, Casey Connolly, Tom Rini,
	Angelo Gioacchino Del Regno, David Heidelberg, Marek Vasut,
	Padmarao Begari, Macpaul Lin, Julien Stephan, Kunihiko Hayashi,
	Shawn Lin, Jared McArthur, Michal Simek, Udit Kumar, Igor Belwon,
	Tuyen Dang, Alexey Charkov, Balaji Selvanathan, Simon Glass,
	Aswin Murugan, Bin Meng, Marek Vasut, David Lechner,
	Ilias Apalodimas, Kory Maincent, Peng Fan, Kuan-Wei Chiu,
	Janne Grunau, Julien Masson, Raymond Mao, Quentin Schulz,
	Philip Molloy, Jerome Forissier, Markus Niebel, Petr Pavlata

On Tuesday, October 6th, 2026 at 3:31 PM, Neil Armstrong <neil.armstrong@linaro.org> wrote:

> On 10/6/26 15:23, phodina wrote:
> >
> > On Monday, October 5th, 2026 at 11:40 AM, Neil Armstrong <neil.armstrong@linaro.org> wrote:
> >
> >> Hi,
> >>
> >> On 10/4/26 21:22, Petr Hodina via B4 Relay wrote:
> >>> From: Petr Hodina <petr.hodina@protonmail.com>
> >>>
> >>> Infrastructure (ufs_quirks.h):
> >>>    - struct ufs_dev_quirk plus UFS_FIX()/UFS_FIX_REVISION() helpers.
> >>>    - ufshcd_fixup_dev_quirks() applies the table (and sets NO_PURGE for
> >>>      devices older than UFS_PURGE_SPEC_VER) from ufs_start(), before power
> >>>      mode negotiation so link quirks take effect.
> >>>    - hba gains a dev_quirks field, distinct from the host controller
> >>>      quirks (hba->quirks).
> >>
> >> In patch 7 you set the quirk for the Sony Yoshino/Tama platforms, but
> >> I'm not sure we need to add the quirk for those UFSs on other platforms.
> >>
> >> Is this really needed for all platforms ?
> >
> >
> > This is more defensive approach to enable it for more platforms.
> >
> > The reason is the device is a production unit with secure boot enabled.
> > Therefore I'm unable to provision again the device non-volatile storage.
> >
> > Also there are no EDL loaders available unlike on some other platforms
> > so restoring the device is currently impossible.
> >
> > Even with the loader just physically desoldering the UFS BGA chip, then
> > replacing it with a new programmed one with the dumped data and soldering
> > it to the board it would probably not be possible to boot as the RPMB block
> > would be missing the Authentication key only the manufacturer posses.
> >
> > I'd assume this issue might be already fixed on newer platforms.
> > Would be great to compile a list of the platforms that definitely
> > need this fix.
> 
> I'm aware of this issue, and I have a Sony sdm845 I'll love to reflash.
> 
> So I understand the defensive approach, but I was wondering if this same
> change was sent to Linux ? I can't find one.
> 
> Neil
> 

Okay now I get the question. Not yet. Still have some u-boot patches I want to upstream mainly the graphical menu and SPL version of u-boot for Qcom device to have one binary with runtime detection based on the SMEM.

Once that's done more than happy to push the kernel UFS patches for the kernel :)

Petr

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2026-10-06 14:33 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-04 19:22 [PATCH u-boot 0/8] ufs: Sony Yoshino/Tama (MSM8998 / SDM845) UFS bring-up Petr Hodina via B4 Relay
2026-10-04 19:22 ` Petr Hodina
2026-10-04 19:22 ` [PATCH u-boot 1/8] ufs: read product revision and spec version into ufs_dev_desc Petr Hodina via B4 Relay
2026-10-04 19:22   ` Petr Hodina
2026-10-04 19:22 ` [PATCH u-boot 2/8] ufs: add device-quirk infrastructure Petr Hodina via B4 Relay
2026-10-04 19:22   ` Petr Hodina
2026-10-05  9:40   ` Neil Armstrong
2026-10-06 13:23     ` phodina
2026-10-06 13:31       ` Neil Armstrong
2026-10-06 13:39         ` phodina
2026-10-04 19:22 ` [PATCH u-boot 3/8] ufs: program extended HS sync length for SK Hynix devices Petr Hodina via B4 Relay
2026-10-04 19:22   ` Petr Hodina
2026-10-04 19:22 ` [PATCH u-boot 4/8] ufs: add CONFIG_UFS_RESTRICT_TX_LANES Petr Hodina via B4 Relay
2026-10-04 19:22   ` Petr Hodina
2026-10-05  9:41   ` Neil Armstrong
2026-10-04 19:22 ` [PATCH u-boot 5/8] scsi: ufs: refuse erase/UNMAP on NO_PURGE devices Petr Hodina via B4 Relay
2026-10-04 19:22   ` Petr Hodina
2026-10-05  9:37   ` Neil Armstrong
2026-10-04 19:22 ` [PATCH u-boot 6/8] ufs: print device information at probe Petr Hodina via B4 Relay
2026-10-04 19:22   ` Petr Hodina
2026-10-05  9:36   ` Neil Armstrong
2026-10-04 19:22 ` [PATCH u-boot 7/8] ufs: gate NO_PURGE on Sony Yoshino/Tama platform compatible Petr Hodina via B4 Relay
2026-10-04 19:22   ` Petr Hodina
2026-10-04 19:22 ` [PATCH u-boot 8/8] arm: dts: qcom: akatsuki: re-enable the UFS controller node Petr Hodina via B4 Relay
2026-10-04 19:22   ` Petr Hodina
2026-10-04 19:30 ` [PATCH u-boot 0/8] ufs: Sony Yoshino/Tama (MSM8998 / SDM845) UFS bring-up David Heidelberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.