Skip to contentSkip to conversation

Add Support for UFS subsystem for TI's J721e

PATCH New Faiz Abbas 3 participants 20 messages Sep 9, 2019 – Sep 11, 2019

Subsystems (2)
lore
Share & tools
lore

Faiz Abbas

author
#0 lore raw

cover Add Support for UFS subsystem for TI's J721e

The following patches add support for the Universal Flash Storage (UFS) subsystem and its implementation on TI's J721e platform.

The UFS Application Layer (UAP) uses SCSI SAM-4 command set for communication with the device. Therefore, the first 4 patches prepare the scsi layer for compatibility with UFS. Patch 9 also adds support for initializing and configuring the device from the U-boot command line.

The UFS Transport Protocol Layer (UTP) and UFS Interconnect Layer (UIC) are implemented with patch 5. This series only adds support for detect and read/write operations to the LUNs present in the remote device. Task Management operations and configuration of LUNs will be added in a future series.

Patches 6 through 10 add platform driver, device tree and config support for TI's J721E devices.

Log: https://pastebin.ubuntu.com/p/fTPZsxNjZM/

Tested on top of Lokesh's tree:
https://github.com/lokeshvutla/u-boot
Branch: j721e-full-boot

References:

[1] JESD220D UFS 3.0:
https://www.jedec.org/standards-documents/docs/jesd220c
[2] JESD223D UFS Host Controller Interface (UFSHCI) version 3.0:
https://www.jedec.org/standards-documents/docs/jesd223c

Faiz Abbas (10):
scsi: Simplify scsi_read()/_write()
scsi: Add max_bytes to scsi_platdata
scsi: Retry inquiry 3 times to overcome Unit Attention condition
scsi: Add dma direction member to command structure
ufs: Add Initial Support for UFS subsystem
ufs: Add Support for Cadence platform UFS driver
ufs: Add glue layer driver for TI J721E devices
arm: dts: k3-j721e-main: Add UFS nodes
cmd: Add Support for UFS commands
configs: j721e_evm_a72: Enable configs for UFS

 arch/arm/dts/k3-j721e-main.dtsi |   25 +
 cmd/Kconfig                     |    7 +
 cmd/Makefile                    |    2 +-
 cmd/ufs.c                       |   28 +
 configs/j721e_evm_a72_defconfig |    7 +-
 drivers/Kconfig                 |    2 +
 drivers/Makefile                |    1 +
 drivers/scsi/scsi.c             |   83 +-
 drivers/ufs/Kconfig             |   23 +
 drivers/ufs/Makefile            |    8 +
 drivers/ufs/cdns-platform.c     |  122 ++
 drivers/ufs/ti-j721e-ufs.c      |   75 ++
 drivers/ufs/ufs-uclass.c        |   16 +
 drivers/ufs/ufs.c               | 1973 +++++++++++++++++++++++++++++++
 drivers/ufs/ufs.h               |  918 ++++++++++++++
 drivers/ufs/unipro.h            |  270 +++++
 include/dm/uclass-id.h          |    1 +
 include/scsi.h                  |    4 +
 include/ufs.h                   |    7 +
 19 files changed, 3526 insertions(+), 46 deletions(-)
 create mode 100644 cmd/ufs.c
 create mode 100644 drivers/ufs/Kconfig
 create mode 100644 drivers/ufs/Makefile
 create mode 100644 drivers/ufs/cdns-platform.c
 create mode 100644 drivers/ufs/ti-j721e-ufs.c
 create mode 100644 drivers/ufs/ufs-uclass.c
 create mode 100644 drivers/ufs/ufs.c
 create mode 100644 drivers/ufs/ufs.h
 create mode 100644 drivers/ufs/unipro.h
 create mode 100644 include/ufs.h
Signature · 1 line
2.19.2
author
#1 lore raw

PATCH 1/10 scsi: Simplify scsi_read()/_write()

With no non-DM driver using scsi_read()/_write() APIs, remove the legacy implementations.

---
 drivers/scsi/scsi.c | 22 ----------------------
 1 file changed, 22 deletions(-)
drivers/scsi/scsi.c +0 -22
index 75900d8228..82a0bf7cc6 100644
@@ -140,20 +140,11 @@ static void scsi_setup_inquiry(struct scsi_cmd *pccb)
 	pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */
 }
 
-#ifdef CONFIG_BLK
 static ulong scsi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
 		       void *buffer)
-#else
-static ulong scsi_read(struct blk_desc *block_dev, lbaint_t blknr,
-		       lbaint_t blkcnt, void *buffer)
-#endif
 {
-#ifdef CONFIG_BLK
 	struct blk_desc *block_dev = dev_get_uclass_platdata(dev);
 	struct udevice *bdev = dev->parent;
-#else
-	struct udevice *bdev = NULL;
-#endif
 	lbaint_t start, blks;
 	uintptr_t buf_addr;
 	unsigned short smallblks = 0;
@@ -216,20 +207,11 @@ static ulong scsi_read(struct blk_desc *block_dev, lbaint_t blknr,
 /* Almost the maximum amount of the scsi_ext command.. */
 #define SCSI_MAX_WRITE_BLK 0xFFFF
 
-#ifdef CONFIG_BLK
 static ulong scsi_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
 			const void *buffer)
-#else
-static ulong scsi_write(struct blk_desc *block_dev, lbaint_t blknr,
-			lbaint_t blkcnt, const void *buffer)
-#endif
 {
-#ifdef CONFIG_BLK
 	struct blk_desc *block_dev = dev_get_uclass_platdata(dev);
 	struct udevice *bdev = dev->parent;
-#else
-	struct udevice *bdev = NULL;
-#endif
 	lbaint_t start, blks;
 	uintptr_t buf_addr;
 	unsigned short smallblks;
@@ -449,10 +431,6 @@ static void scsi_init_dev_desc_priv(struct blk_desc *dev_desc)
 	dev_desc->product[0] = 0;
 	dev_desc->revision[0] = 0;
 	dev_desc->removable = false;
-#if !CONFIG_IS_ENABLED(BLK)
-	dev_desc->block_read = scsi_read;
-	dev_desc->block_write = scsi_write;
-#endif
 }
 
 #if !defined(CONFIG_DM_SCSI)
Signature · 1 line
2.19.2
author
#2 lore raw

PATCH 2/10 scsi: Add max_bytes to scsi_platdata

In reply to Faiz Abbas

Add max_platdata to scsi_platdata to enable the host driver to limit the number of bytes that can be read/written per request.

---
 drivers/scsi/scsi.c | 45 ++++++++++++++++++++++++++-------------------
 include/scsi.h      |  1 +
 2 files changed, 27 insertions(+), 19 deletions(-)
drivers/scsi/scsi.c +26 -19
index 82a0bf7cc6..fd1b4b776d 100644
@@ -44,7 +44,7 @@ static struct blk_desc scsi_dev_desc[CONFIG_SYS_SCSI_MAX_DEVICE];
 #endif
 
 /* almost the maximum amount of the scsi_ext command.. */
-#define SCSI_MAX_READ_BLK 0xFFFF
+#define SCSI_MAX_BLK 0xFFFF
 #define SCSI_LBA48_READ	0xFFFFFFF
 
 static void scsi_print_error(struct scsi_cmd *pccb)
@@ -145,7 +145,8 @@ static ulong scsi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
 {
 	struct blk_desc *block_dev = dev_get_uclass_platdata(dev);
 	struct udevice *bdev = dev->parent;
-	lbaint_t start, blks;
+	struct scsi_platdata *uc_plat = dev_get_uclass_platdata(bdev);
+	lbaint_t start, blks, max_blks;
 	uintptr_t buf_addr;
 	unsigned short smallblks = 0;
 	struct scsi_cmd *pccb = (struct scsi_cmd *)&tempccb;
@@ -156,6 +157,11 @@ static ulong scsi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
 	buf_addr = (unsigned long)buffer;
 	start = blknr;
 	blks = blkcnt;
+	if (uc_plat->max_bytes)
+		max_blks = uc_plat->max_bytes / block_dev->blksz;
+	else
+		max_blks = SCSI_MAX_BLK;
+
 	debug("\nscsi_read: dev %d startblk " LBAF
 	      ", blccnt " LBAF " buffer %lx\n",
 	      block_dev->devnum, start, blks, (unsigned long)buffer);
@@ -164,20 +170,19 @@ static ulong scsi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
 #ifdef CONFIG_SYS_64BIT_LBA
 		if (start > SCSI_LBA48_READ) {
 			unsigned long blocks;
-			blocks = min_t(lbaint_t, blks, SCSI_MAX_READ_BLK);
+			blocks = min_t(lbaint_t, blks, max_blks);
 			pccb->datalen = block_dev->blksz * blocks;
 			scsi_setup_read16(pccb, start, blocks);
 			start += blocks;
 			blks -= blocks;
 		} else
 #endif
-		if (blks > SCSI_MAX_READ_BLK) {
-			pccb->datalen = block_dev->blksz *
-				SCSI_MAX_READ_BLK;
-			smallblks = SCSI_MAX_READ_BLK;
+		if (blks > max_blks) {
+			pccb->datalen = block_dev->blksz * max_blks;
+			smallblks = max_blks;
 			scsi_setup_read_ext(pccb, start, smallblks);
-			start += SCSI_MAX_READ_BLK;
-			blks -= SCSI_MAX_READ_BLK;
+			start += max_blks;
+			blks -= max_blks;
 		} else {
 			pccb->datalen = block_dev->blksz * blks;
 			smallblks = (unsigned short)blks;
@@ -204,15 +209,13 @@ static ulong scsi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
  * scsi_write
  */
 
-/* Almost the maximum amount of the scsi_ext command.. */
-#define SCSI_MAX_WRITE_BLK 0xFFFF
-
 static ulong scsi_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
 			const void *buffer)
 {
 	struct blk_desc *block_dev = dev_get_uclass_platdata(dev);
 	struct udevice *bdev = dev->parent;
-	lbaint_t start, blks;
+	struct scsi_platdata *uc_plat = dev_get_uclass_priv(bdev);
+	lbaint_t start, blks, max_blks;
 	uintptr_t buf_addr;
 	unsigned short smallblks;
 	struct scsi_cmd *pccb = (struct scsi_cmd *)&tempccb;
@@ -223,17 +226,21 @@ static ulong scsi_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
 	buf_addr = (unsigned long)buffer;
 	start = blknr;
 	blks = blkcnt;
+	if (uc_plat->max_bytes)
+		max_blks = uc_plat->max_bytes / block_dev->blksz;
+	else
+		max_blks = SCSI_MAX_BLK;
+
 	debug("\n%s: dev %d startblk " LBAF ", blccnt " LBAF " buffer %lx\n",
 	      __func__, block_dev->devnum, start, blks, (unsigned long)buffer);
 	do {
 		pccb->pdata = (unsigned char *)buf_addr;
-		if (blks > SCSI_MAX_WRITE_BLK) {
-			pccb->datalen = (block_dev->blksz *
-					 SCSI_MAX_WRITE_BLK);
-			smallblks = SCSI_MAX_WRITE_BLK;
+		if (blks > SCSI_MAX_BLK) {
+			pccb->datalen = block_dev->blksz * max_blks;
+			smallblks = max_blks;
 			scsi_setup_write_ext(pccb, start, smallblks);
-			start += SCSI_MAX_WRITE_BLK;
-			blks -= SCSI_MAX_WRITE_BLK;
+			start += max_blks;
+			blks -= max_blks;
 		} else {
 			pccb->datalen = block_dev->blksz * blks;
 			smallblks = (unsigned short)blks;
include/scsi.h +1 -0
index 81ab43c842..076bdbc6a0 100644
@@ -168,6 +168,7 @@ struct scsi_platdata {
 	unsigned long base;
 	unsigned long max_lun;
 	unsigned long max_id;
+	unsigned long max_bytes;
 };
 
 /* Operations for SCSI */
Signature · 1 line
2.19.2
#3 lore raw

PATCH 2/10 scsi: Add max_bytes to scsi_platdata

include/scsi.h struct scsi_platdata { · line 171

Quoted 9 lines · Faiz Abbas
include/scsi.h +1 -0
index 81ab43c842..076bdbc6a0 100644
@@ -168,6 +168,7 @@ struct scsi_platdata {
 	unsigned long base;
 	unsigned long max_lun;
 	unsigned long max_id;
+	unsigned long max_bytes;

Please add description of the new field. Also, could the name be bit more specific like max_bytes_per_req?

Signature · 2 lines
Regards
Vignesh
author
#4 lore raw

PATCH 2/10 scsi: Add max_bytes to scsi_platdata

Vignesh,

Quoted 16 lines · Vignesh Raghavendra

include/scsi.h struct scsi_platdata { · line 171

Quoted 9 lines · Faiz Abbas
include/scsi.h +1 -0
index 81ab43c842..076bdbc6a0 100644
@@ -168,6 +168,7 @@ struct scsi_platdata {
 	unsigned long base;
 	unsigned long max_lun;
 	unsigned long max_id;
+	unsigned long max_bytes;

Please add description of the new field. Also, could the name be bit more specific like max_bytes_per_req?

Sounds good.

Thanks,
Faiz

author
#5 lore raw

PATCH 3/10 scsi: Retry inquiry 3 times to overcome Unit Attention condition

In reply to Faiz Abbas

The UFS SCSI device LUNs are observed to return failure the first time a unit ready inquiry is sent and pass on the second try. Send this inquiry 3 times to make sure device is ready.

---
 drivers/scsi/scsi.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/scsi/scsi.c +9 -3
index fd1b4b776d..7b7d388557 100644
@@ -478,6 +478,7 @@ static int scsi_detect_dev(struct udevice *dev, int target, int lun,
 	lbaint_t capacity;
 	unsigned long blksz;
 	struct scsi_cmd *pccb = (struct scsi_cmd *)&tempccb;
+	int count, err;
 
 	pccb->target = target;
 	pccb->lun = lun;
@@ -513,9 +514,14 @@ static int scsi_detect_dev(struct udevice *dev, int target, int lun,
 	dev_desc->target = pccb->target;
 	dev_desc->lun = pccb->lun;
 
-	pccb->datalen = 0;
-	scsi_setup_test_unit_ready(pccb);
-	if (scsi_exec(dev, pccb)) {
+	for (count = 0; count < 3; count++) {
+		pccb->datalen = 0;
+		scsi_setup_test_unit_ready(pccb);
+		err = scsi_exec(dev, pccb);
+		if (!err)
+			break;
+	}
+	if (err) {
 		if (dev_desc->removable) {
 			dev_desc->type = perq;
 			goto removable;
Signature · 1 line
2.19.2
author
#6 lore raw

PATCH 4/10 scsi: Add dma direction member to command structure

In reply to Faiz Abbas

Some SCSI devices like UFS use DMA for executing scsi commands and hence need to know the direction of transfer of the dma. Add a dma_dir element to the command structure to facilitate this.

---
 drivers/scsi/scsi.c | 4 ++++
 include/scsi.h      | 3 +++
 2 files changed, 7 insertions(+)
drivers/scsi/scsi.c +4 -0
index 7b7d388557..719e0fbfe6 100644
@@ -167,6 +167,7 @@ static ulong scsi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
 	      block_dev->devnum, start, blks, (unsigned long)buffer);
 	do {
 		pccb->pdata = (unsigned char *)buf_addr;
+		pccb->dma_dir = DMA_FROM_DEVICE;
 #ifdef CONFIG_SYS_64BIT_LBA
 		if (start > SCSI_LBA48_READ) {
 			unsigned long blocks;
@@ -235,6 +236,7 @@ static ulong scsi_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
 	      __func__, block_dev->devnum, start, blks, (unsigned long)buffer);
 	do {
 		pccb->pdata = (unsigned char *)buf_addr;
+		pccb->dma_dir = DMA_TO_DEVICE;
 		if (blks > SCSI_MAX_BLK) {
 			pccb->datalen = block_dev->blksz * max_blks;
 			smallblks = max_blks;
@@ -382,6 +384,7 @@ static int scsi_read_capacity(struct udevice *dev, struct scsi_cmd *pccb,
 	pccb->msgout[0] = SCSI_IDENTIFY; /* NOT USED */
 
 	pccb->datalen = 16;
+	pccb->dma_dir = DMA_FROM_DEVICE;
 	if (scsi_exec(dev, pccb))
 		return 1;
 
@@ -484,6 +487,7 @@ static int scsi_detect_dev(struct udevice *dev, int target, int lun,
 	pccb->lun = lun;
 	pccb->pdata = (unsigned char *)&tempbuff;
 	pccb->datalen = 512;
+	pccb->dma_dir = DMA_FROM_DEVICE;
 	scsi_setup_inquiry(pccb);
 	if (scsi_exec(dev, pccb)) {
 		if (pccb->contr_stat == SCSI_SEL_TIME_OUT) {
include/scsi.h +3 -0
index 076bdbc6a0..7bb2d3ac0f 100644
@@ -6,6 +6,8 @@
  #ifndef _SCSI_H
  #define _SCSI_H
 
+#include <linux/dma-direction.h>
+
 struct scsi_cmd {
 	unsigned char		cmd[16];					/* command				   */
 	/* for request sense */
@@ -26,6 +28,7 @@ struct scsi_cmd {
 	unsigned long		trans_bytes;			/* tranfered bytes		*/
 
 	unsigned int		priv;
+	enum dma_data_direction	dma_dir;
 };
 
 /*-----------------------------------------------------------
Signature · 1 line
2.19.2
author
#7 lore raw

PATCH 5/10 ufs: Add Initial Support for UFS subsystem

In reply to Faiz Abbas

Add Support for UFS Host Controller Interface (UFSHCI) for communicating with Universal Flash Storage (UFS) devices. The steps to initialize the host controller interface are the following:

- Initiate the Host Controller Initialization process by writing to the Host controller enable register.
- Configure the Host Controller base address registers by allocating a host memory space and related data structures.
- Unipro link startup procedure
- Check for connected device
- Configure UFS host controller to process requests

Also register this host controller as a SCSI host controller.

---
 MAINTAINERS              |    5 +
 drivers/Kconfig          |    2 +
 drivers/Makefile         |    1 +
 drivers/ufs/Kconfig      |    9 +
 drivers/ufs/Makefile     |    6 +
 drivers/ufs/ufs-uclass.c |   16 +
 drivers/ufs/ufs.c        | 1973 ++++++++++++++++++++++++++++++++++++++
 drivers/ufs/ufs.h        |  918 ++++++++++++++++++
 drivers/ufs/unipro.h     |  270 ++++++
 include/dm/uclass-id.h   |    1 +
 include/ufs.h            |    7 +
 11 files changed, 3208 insertions(+)
 create mode 100644 drivers/ufs/Kconfig
 create mode 100644 drivers/ufs/Makefile
 create mode 100644 drivers/ufs/ufs-uclass.c
 create mode 100644 drivers/ufs/ufs.c
 create mode 100644 drivers/ufs/ufs.h
 create mode 100644 drivers/ufs/unipro.h
 create mode 100644 include/ufs.h
MAINTAINERS +5 -0
index 36625795a4..ed3a4c352c 100644
@@ -772,6 +772,11 @@ S:	Maintained
 T:	git git://git.denx.de/u-boot-ubi.git
 F:	drivers/mtd/ubi/
 
+UFS
+M:	Faiz Abbas <[email protected]>
+S:	Maintained
+F:	drivers/ufs/
+
 USB
 M:	Marek Vasut <[email protected]>
 S:	Maintained
drivers/Kconfig +2 -0
index 96ff4f566a..61bbe88d6c 100644
@@ -118,6 +118,8 @@ source "drivers/tpm/Kconfig"
 
 source "drivers/usb/Kconfig"
 
+source "drivers/ufs/Kconfig"
+
 source "drivers/video/Kconfig"
 
 source "drivers/virtio/Kconfig"
drivers/Makefile +1 -0
index 6635dabd2c..2794bef18a 100644
@@ -111,6 +111,7 @@ obj-y += soc/
 obj-y += thermal/
 obj-$(CONFIG_TEE) += tee/
 obj-y += axi/
+obj-y += ufs/
 obj-$(CONFIG_W1) += w1/
 obj-$(CONFIG_W1_EEPROM) += w1-eeprom/
 
drivers/ufs/Kconfig new file +9 -0
new file mode 100644
index 0000000000..538aad8cd9
@@ -0,0 +1,9 @@
+menu "UFS Host Controller Support"
+
+config UFS
+	bool "Support UFS controllers"
+	select DM_SCSI
+	help
+	  This selects support for Universal Flash Subsystem (UFS).
+	  Say Y here if you want UFS Support.
+endmenu
drivers/ufs/Makefile new file +6 -0
new file mode 100644
index 0000000000..b8df759f66
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com
+#
+
+obj-$(CONFIG_UFS) += ufs.o ufs-uclass.o
drivers/ufs/ufs-uclass.c new file +16 -0
new file mode 100644
index 0000000000..920bfa64e1
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0
+/**
+ * ufs-uclass.c - Universal Flash Subsystem (UFS) Uclass driver
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com
+ */
+
+#include <common.h>
+#include "ufs.h"
+#include <dm.h>
+
+UCLASS_DRIVER(ufs) = {
+	.id	= UCLASS_UFS,
+	.name	= "ufs",
+	.per_device_auto_alloc_size = sizeof(struct ufs_hba),
+};
drivers/ufs/ufs.c new file +1973 -0

1,973 lines not on this page · raw message

drivers/ufs/ufs.h new file +918 -0

918 lines not on this page · raw message

drivers/ufs/unipro.h new file +270 -0

52 lines not on this page · raw message

include/dm/uclass-id.h +1 -0
index 09e0ad5391..a606b8c41b 100644

Lines of this file are not shown. View the raw message.

include/ufs.h new file +7 -0
new file mode 100644
index 0000000000..2245838b3c

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.19.2

Part of the diff is not shown here. View the raw message.

#8 lore raw

PATCH 5/10 ufs: Add Initial Support for UFS subsystem

Quoted 4 lines · Faiz Abbas

Add Support for UFS Host Controller Interface (UFSHCI) for communicating with Universal Flash Storage (UFS) devices. The steps to initialize the host controller interface are the following:

Quoted 8 lines

- Initiate the Host Controller Initialization process by writing to the Host controller enable register.
- Configure the Host Controller base address registers by allocating a host memory space and related data structures.
- Unipro link startup procedure
- Check for connected device
- Configure UFS host controller to process requests

I am guessing code is derived from Linux kernel? Could you add kernel version from which this code is borrowed from?

Quoted 13 lines

Also register this host controller as a SCSI host controller.

---
 MAINTAINERS              |    5 +
 drivers/Kconfig          |    2 +
 drivers/Makefile         |    1 +
 drivers/ufs/Kconfig      |    9 +
 drivers/ufs/Makefile     |    6 +
 drivers/ufs/ufs-uclass.c |   16 +
 drivers/ufs/ufs.c        | 1973 ++++++++++++++++++++++++++++++++++++++
 drivers/ufs/ufs.h        |  918 ++++++++++++++++++
 drivers/ufs/unipro.h     |  270 ++++++

Should UFS reside under SCSI framework given that UFS follows SAM? driver/scsi/ufs?

Regards
Vignesh

Quoted 58 lines
 include/dm/uclass-id.h   |    1 +
 include/ufs.h            |    7 +
 11 files changed, 3208 insertions(+)
 create mode 100644 drivers/ufs/Kconfig
 create mode 100644 drivers/ufs/Makefile
 create mode 100644 drivers/ufs/ufs-uclass.c
 create mode 100644 drivers/ufs/ufs.c
 create mode 100644 drivers/ufs/ufs.h
 create mode 100644 drivers/ufs/unipro.h
 create mode 100644 include/ufs.h
MAINTAINERS +5 -0
index 36625795a4..ed3a4c352c 100644
@@ -772,6 +772,11 @@ S:	Maintained
 T:	git git://git.denx.de/u-boot-ubi.git
 F:	drivers/mtd/ubi/
 
+UFS
+M:	Faiz Abbas <[email protected]>
+S:	Maintained
+F:	drivers/ufs/
+
 USB
 M:	Marek Vasut <[email protected]>
 S:	Maintained
drivers/Kconfig +2 -0
index 96ff4f566a..61bbe88d6c 100644
@@ -118,6 +118,8 @@ source "drivers/tpm/Kconfig"
 
 source "drivers/usb/Kconfig"
 
+source "drivers/ufs/Kconfig"
+
 source "drivers/video/Kconfig"
 
 source "drivers/virtio/Kconfig"
drivers/Makefile +1 -0
index 6635dabd2c..2794bef18a 100644
@@ -111,6 +111,7 @@ obj-y += soc/
 obj-y += thermal/
 obj-$(CONFIG_TEE) += tee/
 obj-y += axi/
+obj-y += ufs/
 obj-$(CONFIG_W1) += w1/
 obj-$(CONFIG_W1_EEPROM) += w1-eeprom/
 
drivers/ufs/Kconfig new file +0 -0
new file mode 100644
index 0000000000..538aad8cd9

drivers/ufs/Kconfig line 5

Quoted 5 lines
drivers/ufs/Kconfig new file +5 -0
@@ -0,0 +1,9 @@
+menu "UFS Host Controller Support"
+
+config UFS
+	bool "Support UFS controllers"
+	select DM_SCSI

DM_SCSI has further dependencies, so its preferred not to use select

depends on DM_SCSI

Also if this is moved under drivers/scsi/ then this Kconfig file can be sourced conditionally

Quoted 38 lines
drivers/ufs/Kconfig new file +4 -0
+	help
+	  This selects support for Universal Flash Subsystem (UFS).
+	  Say Y here if you want UFS Support.
+endmenu
drivers/ufs/Makefile new file +6 -0
new file mode 100644
index 0000000000..b8df759f66
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com
+#
+
+obj-$(CONFIG_UFS) += ufs.o ufs-uclass.o
drivers/ufs/ufs-uclass.c new file +16 -0
new file mode 100644
index 0000000000..920bfa64e1
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0
+/**
+ * ufs-uclass.c - Universal Flash Subsystem (UFS) Uclass driver
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com
+ */
+
+#include <common.h>
+#include "ufs.h"
+#include <dm.h>
+
+UCLASS_DRIVER(ufs) = {
+	.id	= UCLASS_UFS,
+	.name	= "ufs",
+	.per_device_auto_alloc_size = sizeof(struct ufs_hba),
+};

[...]

include/dm/uclass-id.h enum uclass_id { · line 99

Quoted 10 lines
drivers/ufs/ufs-uclass.c new file +1 -0
+#endif /* _UNIPRO_H_ */
include/dm/uclass-id.h +1 -0
index 09e0ad5391..a606b8c41b 100644
@@ -96,6 +96,7 @@ enum uclass_id {
 	UCLASS_THERMAL,		/* Thermal sensor */
 	UCLASS_TIMER,		/* Timer device */
 	UCLASS_TPM,		/* Trusted Platform Module TIS interface */
+	UCLASS_UFS,		/* Universale Flash Storage */

s/Universale/Universal

Quoted 9 lines
include/dm/uclass-id.h +0 -0
 	UCLASS_USB,		/* USB bus */
 	UCLASS_USB_DEV_GENERIC,	/* USB generic device */
 	UCLASS_USB_HUB,		/* USB hub */
include/ufs.h new file +0 -0
new file mode 100644
index 0000000000..2245838b3c

include/ufs.h line 5

Quoted 5 lines
include/ufs.h new file +5 -0
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+#ifndef _UFS_H
+#define _UFS_H
+
+int ufs_probe(void);

This is fine, but you may want to provide helper to initialize a single instance of controller so that we don't end up in a situation like MMC where all the instances are initialized always.
Probably modify ufs_probe() to take an int arg that indicates instance to be probed and -1 to probe all instances.
Irrespective of this, please add API documentation before the function declaration

include/ufs.h line 6

Quoted 1 line
include/ufs.h new file +1 -0
+int ufs_scsi_bind(struct udevice *scsi_dev, struct udevice **devp);

Please document the API

Quoted 2 lines
include/ufs.h new file +1 -0
+#endif
Signature · 2 lines
Regards
Vignesh
author
#9 lore raw

PATCH 5/10 ufs: Add Initial Support for UFS subsystem

Hi Vignesh,

Quoted 16 lines · Vignesh Raghavendra
Quoted 4 lines · Faiz Abbas

Add Support for UFS Host Controller Interface (UFSHCI) for communicating with Universal Flash Storage (UFS) devices. The steps to initialize the host controller interface are the following:

Quoted 8 lines

- Initiate the Host Controller Initialization process by writing to the Host controller enable register.
- Configure the Host Controller base address registers by allocating a host memory space and related data structures.
- Unipro link startup procedure
- Check for connected device
- Configure UFS host controller to process requests

Quoted 2 lines

I am guessing code is derived from Linux kernel? Could you add kernel version from which this code is borrowed from?

I did write that in the ufs.c file description. Will also add it here.

Quoted 15 lines
Quoted 4 lines

Also register this host controller as a SCSI host controller.

Quoted 10 lines
---
 MAINTAINERS              |    5 +
 drivers/Kconfig          |    2 +
 drivers/Makefile         |    1 +
 drivers/ufs/Kconfig      |    9 +
 drivers/ufs/Makefile     |    6 +
 drivers/ufs/ufs-uclass.c |   16 +
 drivers/ufs/ufs.c        | 1973 ++++++++++++++++++++++++++++++++++++++
 drivers/ufs/ufs.h        |  918 ++++++++++++++++++
 drivers/ufs/unipro.h     |  270 ++++++
Quoted 2 lines

Should UFS reside under SCSI framework given that UFS follows SAM? driver/scsi/ufs?

Other scsi implementations (like ahci) have their own folders so I'm just following that convention.

Quoted 141 lines

Regards
Vignesh

Quoted 58 lines
 include/dm/uclass-id.h   |    1 +
 include/ufs.h            |    7 +
 11 files changed, 3208 insertions(+)
 create mode 100644 drivers/ufs/Kconfig
 create mode 100644 drivers/ufs/Makefile
 create mode 100644 drivers/ufs/ufs-uclass.c
 create mode 100644 drivers/ufs/ufs.c
 create mode 100644 drivers/ufs/ufs.h
 create mode 100644 drivers/ufs/unipro.h
 create mode 100644 include/ufs.h
MAINTAINERS +5 -0
index 36625795a4..ed3a4c352c 100644
@@ -772,6 +772,11 @@ S:	Maintained
 T:	git git://git.denx.de/u-boot-ubi.git
 F:	drivers/mtd/ubi/
 
+UFS
+M:	Faiz Abbas <[email protected]>
+S:	Maintained
+F:	drivers/ufs/
+
 USB
 M:	Marek Vasut <[email protected]>
 S:	Maintained
drivers/Kconfig +2 -0
index 96ff4f566a..61bbe88d6c 100644
@@ -118,6 +118,8 @@ source "drivers/tpm/Kconfig"
 
 source "drivers/usb/Kconfig"
 
+source "drivers/ufs/Kconfig"
+
 source "drivers/video/Kconfig"
 
 source "drivers/virtio/Kconfig"
drivers/Makefile +1 -0
index 6635dabd2c..2794bef18a 100644
@@ -111,6 +111,7 @@ obj-y += soc/
 obj-y += thermal/
 obj-$(CONFIG_TEE) += tee/
 obj-y += axi/
+obj-y += ufs/
 obj-$(CONFIG_W1) += w1/
 obj-$(CONFIG_W1_EEPROM) += w1-eeprom/
 
drivers/ufs/Kconfig new file +0 -0
new file mode 100644
index 0000000000..538aad8cd9

drivers/ufs/Kconfig line 5

Quoted 5 lines
drivers/ufs/Kconfig new file +5 -0
@@ -0,0 +1,9 @@
+menu "UFS Host Controller Support"
+
+config UFS
+	bool "Support UFS controllers"
+	select DM_SCSI

DM_SCSI has further dependencies, so its preferred not to use select

depends on DM_SCSI

Also if this is moved under drivers/scsi/ then this Kconfig file can be sourced conditionally

Quoted 38 lines
drivers/ufs/Kconfig new file +4 -0
+	help
+	  This selects support for Universal Flash Subsystem (UFS).
+	  Say Y here if you want UFS Support.
+endmenu
drivers/ufs/Makefile new file +6 -0
new file mode 100644
index 0000000000..b8df759f66
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com
+#
+
+obj-$(CONFIG_UFS) += ufs.o ufs-uclass.o
drivers/ufs/ufs-uclass.c new file +16 -0
new file mode 100644
index 0000000000..920bfa64e1
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0
+/**
+ * ufs-uclass.c - Universal Flash Subsystem (UFS) Uclass driver
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com
+ */
+
+#include <common.h>
+#include "ufs.h"
+#include <dm.h>
+
+UCLASS_DRIVER(ufs) = {
+	.id	= UCLASS_UFS,
+	.name	= "ufs",
+	.per_device_auto_alloc_size = sizeof(struct ufs_hba),
+};

[...]

include/dm/uclass-id.h enum uclass_id { · line 99

Quoted 10 lines
drivers/ufs/ufs-uclass.c new file +1 -0
+#endif /* _UNIPRO_H_ */
include/dm/uclass-id.h +1 -0
index 09e0ad5391..a606b8c41b 100644
@@ -96,6 +96,7 @@ enum uclass_id {
 	UCLASS_THERMAL,		/* Thermal sensor */
 	UCLASS_TIMER,		/* Timer device */
 	UCLASS_TPM,		/* Trusted Platform Module TIS interface */
+	UCLASS_UFS,		/* Universale Flash Storage */

s/Universale/Universal

Quoted 12 lines
include/dm/uclass-id.h +0 -0
 	UCLASS_USB,		/* USB bus */
 	UCLASS_USB_DEV_GENERIC,	/* USB generic device */
 	UCLASS_USB_HUB,		/* USB hub */
include/ufs.h new file +3 -0
new file mode 100644
index 0000000000..2245838b3c
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+#ifndef _UFS_H
+#define _UFS_H
Quoted 8 lines

include/ufs.h line 5

Quoted 2 lines
include/ufs.h new file +2 -0
+
+int ufs_probe(void);

This is fine, but you may want to provide helper to initialize a single instance of controller so that we don't end up in a situation like MMC where all the instances are initialized always.
Probably modify ufs_probe() to take an int arg that indicates instance to be probed and -1 to probe all instances.

Makes sense. Will modify the API.

Quoted 6 lines

Irrespective of this, please add API documentation before the function declaration

include/ufs.h line 6

Quoted 1 line
include/ufs.h new file +1 -0
+int ufs_scsi_bind(struct udevice *scsi_dev, struct udevice **devp);

Please document the API

Ok.

Thanks,
Faiz

author
#10 lore raw

PATCH 6/10 ufs: Add Support for Cadence platform UFS driver

In reply to Faiz Abbas

Add Support for the platform driver for the Cadence device present on TI's J721e device.

---
 drivers/ufs/Kconfig         |   8 +++
 drivers/ufs/Makefile        |   1 +
 drivers/ufs/cdns-platform.c | 122 ++++++++++++++++++++++++++++++++++++
 3 files changed, 131 insertions(+)
 create mode 100644 drivers/ufs/cdns-platform.c
drivers/ufs/Kconfig +8 -0
index 538aad8cd9..a320b4561f 100644
@@ -6,4 +6,12 @@ config UFS
 	help
 	  This selects support for Universal Flash Subsystem (UFS).
 	  Say Y here if you want UFS Support.
+
+config CADENCE_UFS
+	bool "Cadence platform driver for UFS"
+	depends on UFS
+        help
+	  This selects the platform driver for the Cadence UFS host
+	  controller present on present TI's J721e devices.
+
 endmenu
drivers/ufs/Makefile +1 -0
index b8df759f66..9262bd6cd0 100644
@@ -4,3 +4,4 @@
 #
 
 obj-$(CONFIG_UFS) += ufs.o ufs-uclass.o
+obj-$(CONFIG_CADENCE_UFS) += cdns-platform.o
drivers/ufs/cdns-platform.c new file +122 -0

122 lines not on this page · raw message

Signature · 1 line
2.19.2
author
#11 lore raw

PATCH 7/10 ufs: Add glue layer driver for TI J721E devices

In reply to Faiz Abbas

Add glue layer driver for the controller present on TI's J721E devices.

---
 drivers/ufs/Kconfig        |  6 +++
 drivers/ufs/Makefile       |  1 +
 drivers/ufs/ti-j721e-ufs.c | 75 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+)
 create mode 100644 drivers/ufs/ti-j721e-ufs.c
drivers/ufs/Kconfig +6 -0
index a320b4561f..4875e9448e 100644
@@ -14,4 +14,10 @@ config CADENCE_UFS
 	  This selects the platform driver for the Cadence UFS host
 	  controller present on present TI's J721e devices.
 
+config TI_J721E_UFS
+	bool "Glue Layer driver for UFS on TI J721E devices"
+	help
+	  This selects the glue layer driver for Cadence controller
+	  present on TI's J721E devices.
+
 endmenu
drivers/ufs/Makefile +1 -0
index 9262bd6cd0..62ed016608 100644
@@ -5,3 +5,4 @@
 
 obj-$(CONFIG_UFS) += ufs.o ufs-uclass.o
 obj-$(CONFIG_CADENCE_UFS) += cdns-platform.o
+obj-$(CONFIG_TI_J721E_UFS) += ti-j721e-ufs.o
drivers/ufs/ti-j721e-ufs.c new file +75 -0

75 lines not on this page · raw message

Signature · 1 line
2.19.2
#12 lore raw

PATCH 7/10 ufs: Add glue layer driver for TI J721E devices

Quoted 40 lines · Faiz Abbas

Add glue layer driver for the controller present on TI's J721E devices.

---
 drivers/ufs/Kconfig        |  6 +++
 drivers/ufs/Makefile       |  1 +
 drivers/ufs/ti-j721e-ufs.c | 75 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+)
 create mode 100644 drivers/ufs/ti-j721e-ufs.c
drivers/ufs/Kconfig +6 -0
index a320b4561f..4875e9448e 100644
@@ -14,4 +14,10 @@ config CADENCE_UFS
 	  This selects the platform driver for the Cadence UFS host
 	  controller present on present TI's J721e devices.
 
+config TI_J721E_UFS
+	bool "Glue Layer driver for UFS on TI J721E devices"
+	help
+	  This selects the glue layer driver for Cadence controller
+	  present on TI's J721E devices.
+
 endmenu
drivers/ufs/Makefile +1 -0
index 9262bd6cd0..62ed016608 100644
@@ -5,3 +5,4 @@
 
 obj-$(CONFIG_UFS) += ufs.o ufs-uclass.o
 obj-$(CONFIG_CADENCE_UFS) += cdns-platform.o
+obj-$(CONFIG_TI_J721E_UFS) += ti-j721e-ufs.o
drivers/ufs/ti-j721e-ufs.c new file +0 -0
new file mode 100644
index 0000000000..249d3796c0

drivers/ufs/ti-j721e-ufs.c line 9

Quoted 9 lines
drivers/ufs/ti-j721e-ufs.c new file +9 -0
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ */
+
+#include <clk.h>
+#include <common.h>
+#include <dm/device.h>
+#include <dm/read.h>

#include <dm.h>

should be sufficient instead of two includes.

Quoted 17 lines
drivers/ufs/ti-j721e-ufs.c new file +17 -0
+#include <power-domain.h>
+#include <regmap.h>
+
+#define UFS_SS_CTRL             0x4
+#define UFS_SS_RST_N_PCS        BIT(0)
+#define UFS_SS_CLK_26MHZ        BIT(4)
+
+static int ti_j721e_ufs_probe(struct udevice *dev)
+{
+	struct power_domain ufs_pwrdmn;
+	struct regmap *map;
+	unsigned int clock;
+	struct clk clk;
+	u32 reg = 0;
+	int ret;
+
+	ret = power_domain_get(dev, &ufs_pwrdmn);

drivers/ufs/ti-j721e-ufs.c line 36

Quoted 10 lines
drivers/ufs/ti-j721e-ufs.c new file +10 -0
+	if (ret) {
+		dev_err(dev, "failed to get power domain %d\n", ret);
+		return ret;
+	}
+
+	ret = power_domain_on(&ufs_pwrdmn);
+	if (ret) {
+		dev_err(dev, "Power domain on failed\n");
+		return ret;
+	}

Core takes care of enabling power domain before calling probe. So this can be dropped

drivers/ufs/ti-j721e-ufs.c line 41

Quoted 5 lines
drivers/ufs/ti-j721e-ufs.c new file +5 -0
+
+	ret = regmap_init_mem(dev_ofnode(dev), &map);
+	if (ret)
+		return ret;
+

I think regmap is an overkill here.. We are just accessing a single register and within dedicated wrapper space. Just use regular IO accessors.

Quoted 8 lines
drivers/ufs/ti-j721e-ufs.c new file +8 -0
+	ret = clk_get_by_index(dev, 0, &clk);
+	if (ret) {
+		dev_err(dev, "failed to get M-PHY clock\n");
+		return ret;
+	}
+
+	clock = clk_get_rate(&clk);
+	if (IS_ERR_VALUE(clock)) {

drivers/ufs/ti-j721e-ufs.c line 59

Quoted 10 lines
drivers/ufs/ti-j721e-ufs.c new file +10 -0
+		dev_err(dev, "failed to get rate\n");
+		return ret;
+	}
+
+	if (clock == 26000000)
+		reg |= UFS_SS_CLK_26MHZ;
+	/* Take UFS slave device out of reset */
+	reg |= UFS_SS_RST_N_PCS;
+	regmap_write(map, UFS_SS_CTRL, reg);
+

To be safe, put the slave back to reset before jumping to kernel so that card does not see any glitches when kernel is doing any re-initialization of clocks etc.
This can be done in driver remove callback (and needs DM_FLAG_OS_PREPARE flag to be set in driver declaration)

Quoted 17 lines
drivers/ufs/ti-j721e-ufs.c new file +16 -0
+	return dm_scan_fdt_dev(dev);
+}
+
+static const struct udevice_id ti_j721e_ufs_ids[] = {
+	{
+		.compatible = "ti,j721e-ufs",
+	},
+	{},
+};
+
+U_BOOT_DRIVER(ti_j721e_ufs) = {
+	.name			= "ti-j721e-ufs",
+	.id			= UCLASS_UFS,
+	.of_match		= ti_j721e_ufs_ids,
+	.probe			= ti_j721e_ufs_probe,
+};
Signature · 2 lines
Regards
Vignesh
author
#13 lore raw

PATCH 7/10 ufs: Add glue layer driver for TI J721E devices

Vignesh,

Quoted 55 lines · Vignesh Raghavendra
Quoted 40 lines · Faiz Abbas

Add glue layer driver for the controller present on TI's J721E devices.

---
 drivers/ufs/Kconfig        |  6 +++
 drivers/ufs/Makefile       |  1 +
 drivers/ufs/ti-j721e-ufs.c | 75 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+)
 create mode 100644 drivers/ufs/ti-j721e-ufs.c
drivers/ufs/Kconfig +6 -0
index a320b4561f..4875e9448e 100644
@@ -14,4 +14,10 @@ config CADENCE_UFS
 	  This selects the platform driver for the Cadence UFS host
 	  controller present on present TI's J721e devices.
 
+config TI_J721E_UFS
+	bool "Glue Layer driver for UFS on TI J721E devices"
+	help
+	  This selects the glue layer driver for Cadence controller
+	  present on TI's J721E devices.
+
 endmenu
drivers/ufs/Makefile +1 -0
index 9262bd6cd0..62ed016608 100644
@@ -5,3 +5,4 @@
 
 obj-$(CONFIG_UFS) += ufs.o ufs-uclass.o
 obj-$(CONFIG_CADENCE_UFS) += cdns-platform.o
+obj-$(CONFIG_TI_J721E_UFS) += ti-j721e-ufs.o
drivers/ufs/ti-j721e-ufs.c new file +0 -0
new file mode 100644
index 0000000000..249d3796c0

drivers/ufs/ti-j721e-ufs.c line 9

Quoted 9 lines
drivers/ufs/ti-j721e-ufs.c new file +9 -0
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ */
+
+#include <clk.h>
+#include <common.h>
+#include <dm/device.h>
+#include <dm/read.h>

#include <dm.h>

Quoted 1 line

should be sufficient instead of two includes.

Replaced it.

Quoted 23 lines
Quoted 23 lines
drivers/ufs/ti-j721e-ufs.c new file +22 -0
+#include <power-domain.h>
+#include <regmap.h>
+
+#define UFS_SS_CTRL             0x4
+#define UFS_SS_RST_N_PCS        BIT(0)
+#define UFS_SS_CLK_26MHZ        BIT(4)
+
+static int ti_j721e_ufs_probe(struct udevice *dev)
+{
+	struct power_domain ufs_pwrdmn;
+	struct regmap *map;
+	unsigned int clock;
+	struct clk clk;
+	u32 reg = 0;
+	int ret;
+
+	ret = power_domain_get(dev, &ufs_pwrdmn);
+	if (ret) {
+		dev_err(dev, "failed to get power domain %d\n", ret);
+		return ret;
+	}
+
Quoted 8 lines

drivers/ufs/ti-j721e-ufs.c line 36

Quoted 5 lines
drivers/ufs/ti-j721e-ufs.c new file +5 -0
+	ret = power_domain_on(&ufs_pwrdmn);
+	if (ret) {
+		dev_err(dev, "Power domain on failed\n");
+		return ret;
+	}

Core takes care of enabling power domain before calling probe. So this can be dropped

Ok.

Quoted 10 lines

drivers/ufs/ti-j721e-ufs.c line 41

Quoted 6 lines
drivers/ufs/ti-j721e-ufs.c new file +5 -0
+
+	ret = regmap_init_mem(dev_ofnode(dev), &map);
+	if (ret)
+		return ret;
+

I think regmap is an overkill here.. We are just accessing a single register and within dedicated wrapper space. Just use regular IO accessors.

Ok. Going back to writel/readl calls.

Quoted 19 lines
Quoted 19 lines
drivers/ufs/ti-j721e-ufs.c new file +16 -0
+	ret = clk_get_by_index(dev, 0, &clk);
+	if (ret) {
+		dev_err(dev, "failed to get M-PHY clock\n");
+		return ret;
+	}
+
+	clock = clk_get_rate(&clk);
+	if (IS_ERR_VALUE(clock)) {
+		dev_err(dev, "failed to get rate\n");
+		return ret;
+	}
+
+	if (clock == 26000000)
+		reg |= UFS_SS_CLK_26MHZ;
+	/* Take UFS slave device out of reset */
+	reg |= UFS_SS_RST_N_PCS;
Quoted 8 lines

drivers/ufs/ti-j721e-ufs.c line 59

Quoted 2 lines
drivers/ufs/ti-j721e-ufs.c new file +2 -0
+	regmap_write(map, UFS_SS_CTRL, reg);
+

To be safe, put the slave back to reset before jumping to kernel so that card does not see any glitches when kernel is doing any re-initialization of clocks etc.
This can be done in driver remove callback (and needs DM_FLAG_OS_PREPARE flag to be set in driver declaration)

Implemented this for v2. Thanks.

Regards,
Faiz

author
#14 lore raw

PATCH 8/10 arm: dts: k3-j721e-main: Add UFS nodes

In reply to Faiz Abbas

Add TI UFS glue layer and Cadence UFS Host controller DT nodes.

---
 arch/arm/dts/k3-j721e-main.dtsi | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
arch/arm/dts/k3-j721e-main.dtsi +25 -0
index 3445784293..23a7cb9d3a 100644
@@ -228,4 +228,29 @@
 		ti,trm-icp = <0x8>;
 		dma-coherent;
 	};
+
+	ufs_wrapper: ufs-wrapper at 4e80000 {
+		compatible = "ti,j721e-ufs";
+		reg = <0x0 0x4e80000 0x0 0x100>;
+		power-domains = <&k3_pds 277 TI_SCI_PD_EXCLUSIVE>;
+		clocks = <&k3_clks 277 1>;
+		assigned-clocks = <&k3_clks 277 1>;
+		assigned-clock-parents = <&k3_clks 277 4>;
+		ranges;
+		#address-cells = <2>;
+		#size-cells = <2>;
+
+		ufs at 4e84000 {
+			compatible = "cdns,ufshc-m31-16nm", "jedec,ufs-2.0";
+			reg = <0x0 0x4e84000 0x0 0x10000>;
+			interrupts = <GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>;
+			power-domains = <&k3_pds 277 TI_SCI_PD_EXCLUSIVE>;
+			freq-table-hz = <0 0>, <0 0>;
+			clocks = <&k3_clks 277 0>, <&k3_clks 277 1>;
+			clock-names = "core_clk", "phy_clk";
+			assigned-clocks = <&k3_clks 277 1>;
+			assigned-clock-parents = <&k3_clks 277 4>;
+			dma-coherent;
+		};
+	};
 };
Signature · 1 line
2.19.2
author
#15 lore raw

PATCH 9/10 cmd: Add Support for UFS commands

In reply to Faiz Abbas

Add Support for commands to initialize and configure UFS devices.

TODO: Add Support for commands to resize and reconfigure LUNs

---
 cmd/Kconfig  |  7 +++++++
 cmd/Makefile |  2 +-
 cmd/ufs.c    | 28 ++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 cmd/ufs.c
cmd/Kconfig +7 -0
index 0badcb3fe0..e0c78c6b52 100644
@@ -1070,6 +1070,13 @@ config CMD_TSI148
 	  This provides various sub-commands to initialise and configure the
 	  Turndra tsi148 device. See the command help for full details.
 
+config CMD_UFS
+	bool "Enable UFS - Universal Flash Subsystem commands"
+	depends on UFS
+	help
+	  "This provides commands to initialise and configure universal flash
+	   subsystem commands"
+
 config CMD_UNIVERSE
 	bool "universe - Command to set up the Turndra Universe controller"
 	help
cmd/Makefile +1 -1
index f982564ab9..dc7869a35a 100644
@@ -143,7 +143,7 @@ obj-$(CONFIG_CMD_UNZIP) += unzip.o
 obj-$(CONFIG_CMD_VIRTIO) += virtio.o
 obj-$(CONFIG_CMD_WDT) += wdt.o
 obj-$(CONFIG_CMD_LZMADEC) += lzmadec.o
-
+obj-$(CONFIG_CMD_UFS) += ufs.o
 obj-$(CONFIG_CMD_USB) += usb.o disk.o
 obj-$(CONFIG_CMD_FASTBOOT) += fastboot.o
 obj-$(CONFIG_CMD_FS_UUID) += fs_uuid.o
cmd/ufs.c new file +28 -0
new file mode 100644
index 0000000000..7e5bbf97d9
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0+
+/**
+ * ufs.c - UFS specific U-boot commands
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com
+ *
+ */
+#include <common.h>
+#include <command.h>
+#include <ufs.h>
+
+static int do_ufs(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	if (argc >= 2) {
+		if (!strcmp(argv[1], "init")) {
+			ufs_probe();
+
+			return CMD_RET_SUCCESS;
+		}
+	}
+
+	return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(ufs, 2, 1, do_ufs,
+	   "UFS  sub system",
+	   "init - init UFS subsystem\n"
+);
Signature · 1 line
2.19.2
author
#16 lore raw

PATCH 10/10 configs: j721e_evm_a72: Enable configs for UFS

In reply to Faiz Abbas

Enable SCSI and UFS related configs.

---
 configs/j721e_evm_a72_defconfig | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
configs/j721e_evm_a72_defconfig +6 -1
index 237dc6b601..4c7d1173b4 100644
@@ -36,11 +36,12 @@ CONFIG_CMD_ASKENV=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_REMOTEPROC=y
 CONFIG_CMD_SF=y
+CONFIG_CMD_UFS=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_CMD_TIME=y
 CONFIG_CMD_EXT4_WRITE=y
 # CONFIG_ISO_PARTITION is not set
-# CONFIG_EFI_PARTITION is not set
+# CONFIG_SPL_PARTITION_UUIDS is not set
 CONFIG_OF_CONTROL=y
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="k3-j721e-common-proc-board"
@@ -76,6 +77,7 @@ CONFIG_TI_SCI_POWER_DOMAIN=y
 CONFIG_K3_SYSTEM_CONTROLLER=y
 CONFIG_DM_RESET=y
 CONFIG_RESET_TI_SCI=y
+CONFIG_SCSI=y
 CONFIG_DM_SERIAL=y
 CONFIG_SPI=y
 CONFIG_DM_SPI=y
@@ -83,4 +85,7 @@ CONFIG_CADENCE_QSPI=y
 CONFIG_SYSRESET=y
 CONFIG_SPL_SYSRESET=y
 CONFIG_SYSRESET_TI_SCI=y
+CONFIG_UFS=y
+CONFIG_CADENCE_UFS=y
+CONFIG_TI_J721E_UFS=y
 CONFIG_OF_LIBFDT_OVERLAY=y
Signature · 1 line
2.19.2
#17 lore raw

cover Add Support for UFS subsystem for TI's J721e

In reply to Faiz Abbas
Quoted 64 lines · Faiz Abbas

The following patches add support for the Universal Flash Storage (UFS) subsystem and its implementation on TI's J721e platform.

The UFS Application Layer (UAP) uses SCSI SAM-4 command set for communication with the device. Therefore, the first 4 patches prepare the scsi layer for compatibility with UFS. Patch 9 also adds support for initializing and configuring the device from the U-boot command line.

The UFS Transport Protocol Layer (UTP) and UFS Interconnect Layer (UIC) are implemented with patch 5. This series only adds support for detect and read/write operations to the LUNs present in the remote device. Task Management operations and configuration of LUNs will be added in a future series.

Patches 6 through 10 add platform driver, device tree and config support for TI's J721E devices.

Log: https://pastebin.ubuntu.com/p/fTPZsxNjZM/

Tested on top of Lokesh's tree:
https://github.com/lokeshvutla/u-boot
Branch: j721e-full-boot

References:

[1] JESD220D UFS 3.0:
https://www.jedec.org/standards-documents/docs/jesd220c
[2] JESD223D UFS Host Controller Interface (UFSHCI) version 3.0:
https://www.jedec.org/standards-documents/docs/jesd223c

Faiz Abbas (10):
scsi: Simplify scsi_read()/_write()
scsi: Add max_bytes to scsi_platdata
scsi: Retry inquiry 3 times to overcome Unit Attention condition
scsi: Add dma direction member to command structure
ufs: Add Initial Support for UFS subsystem
ufs: Add Support for Cadence platform UFS driver
ufs: Add glue layer driver for TI J721E devices
arm: dts: k3-j721e-main: Add UFS nodes
cmd: Add Support for UFS commands
configs: j721e_evm_a72: Enable configs for UFS

 arch/arm/dts/k3-j721e-main.dtsi |   25 +
 cmd/Kconfig                     |    7 +
 cmd/Makefile                    |    2 +-
 cmd/ufs.c                       |   28 +
 configs/j721e_evm_a72_defconfig |    7 +-
 drivers/Kconfig                 |    2 +
 drivers/Makefile                |    1 +
 drivers/scsi/scsi.c             |   83 +-
 drivers/ufs/Kconfig             |   23 +
 drivers/ufs/Makefile            |    8 +
 drivers/ufs/cdns-platform.c     |  122 ++
 drivers/ufs/ti-j721e-ufs.c      |   75 ++
 drivers/ufs/ufs-uclass.c        |   16 +
 drivers/ufs/ufs.c               | 1973 +++++++++++++++++++++++++++++++
 drivers/ufs/ufs.h               |  918 ++++++++++++++
 drivers/ufs/unipro.h            |  270 +++++
 include/dm/uclass-id.h          |    1 +
 include/scsi.h                  |    4 +
 include/ufs.h                   |    7 +
 19 files changed, 3526 insertions(+), 46 deletions(-)
 create mode 100644 cmd/ufs.c
 create mode 100644 drivers/ufs/Kconfig
Quoted 8 lines
 create mode 100644 drivers/ufs/Makefile
 create mode 100644 drivers/ufs/cdns-platform.c
 create mode 100644 drivers/ufs/ti-j721e-ufs.c
 create mode 100644 drivers/ufs/ufs-uclass.c
 create mode 100644 drivers/ufs/ufs.c
 create mode 100644 drivers/ufs/ufs.h
 create mode 100644 drivers/ufs/unipro.h
 create mode 100644 include/ufs.h

I'm glad to see this support coming, it's something we need. Would you be willing to list yourself as the maintainer in the top-level MAINTAINER file for drivers/ufs at least? Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190909/85647c9d/attachment.sig>
author
#18 lore raw

cover Add Support for UFS subsystem for TI's J721e

Hi Tom,

Quoted 74 lines · Tom Rini
Quoted 64 lines · Faiz Abbas

The following patches add support for the Universal Flash Storage (UFS) subsystem and its implementation on TI's J721e platform.

The UFS Application Layer (UAP) uses SCSI SAM-4 command set for communication with the device. Therefore, the first 4 patches prepare the scsi layer for compatibility with UFS. Patch 9 also adds support for initializing and configuring the device from the U-boot command line.

The UFS Transport Protocol Layer (UTP) and UFS Interconnect Layer (UIC) are implemented with patch 5. This series only adds support for detect and read/write operations to the LUNs present in the remote device. Task Management operations and configuration of LUNs will be added in a future series.

Patches 6 through 10 add platform driver, device tree and config support for TI's J721E devices.

Log: https://pastebin.ubuntu.com/p/fTPZsxNjZM/

Tested on top of Lokesh's tree:
https://github.com/lokeshvutla/u-boot
Branch: j721e-full-boot

References:

[1] JESD220D UFS 3.0:
https://www.jedec.org/standards-documents/docs/jesd220c
[2] JESD223D UFS Host Controller Interface (UFSHCI) version 3.0:
https://www.jedec.org/standards-documents/docs/jesd223c

Faiz Abbas (10):
scsi: Simplify scsi_read()/_write()
scsi: Add max_bytes to scsi_platdata
scsi: Retry inquiry 3 times to overcome Unit Attention condition
scsi: Add dma direction member to command structure
ufs: Add Initial Support for UFS subsystem
ufs: Add Support for Cadence platform UFS driver
ufs: Add glue layer driver for TI J721E devices
arm: dts: k3-j721e-main: Add UFS nodes
cmd: Add Support for UFS commands
configs: j721e_evm_a72: Enable configs for UFS

 arch/arm/dts/k3-j721e-main.dtsi |   25 +
 cmd/Kconfig                     |    7 +
 cmd/Makefile                    |    2 +-
 cmd/ufs.c                       |   28 +
 configs/j721e_evm_a72_defconfig |    7 +-
 drivers/Kconfig                 |    2 +
 drivers/Makefile                |    1 +
 drivers/scsi/scsi.c             |   83 +-
 drivers/ufs/Kconfig             |   23 +
 drivers/ufs/Makefile            |    8 +
 drivers/ufs/cdns-platform.c     |  122 ++
 drivers/ufs/ti-j721e-ufs.c      |   75 ++
 drivers/ufs/ufs-uclass.c        |   16 +
 drivers/ufs/ufs.c               | 1973 +++++++++++++++++++++++++++++++
 drivers/ufs/ufs.h               |  918 ++++++++++++++
 drivers/ufs/unipro.h            |  270 +++++
 include/dm/uclass-id.h          |    1 +
 include/scsi.h                  |    4 +
 include/ufs.h                   |    7 +
 19 files changed, 3526 insertions(+), 46 deletions(-)
 create mode 100644 cmd/ufs.c
 create mode 100644 drivers/ufs/Kconfig
Quoted 8 lines
 create mode 100644 drivers/ufs/Makefile
 create mode 100644 drivers/ufs/cdns-platform.c
 create mode 100644 drivers/ufs/ti-j721e-ufs.c
 create mode 100644 drivers/ufs/ufs-uclass.c
 create mode 100644 drivers/ufs/ufs.c
 create mode 100644 drivers/ufs/ufs.h
 create mode 100644 drivers/ufs/unipro.h
 create mode 100644 include/ufs.h
Quoted 4 lines

I'm glad to see this support coming, it's something we need. Would you be willing to list yourself as the maintainer in the top-level MAINTAINER file for drivers/ufs at least? Thanks!

I did add to the MAINTAINER file in patch 5. Was that supposed to be a separate patch?

Thanks,
Faiz

#19 lore raw

cover Add Support for UFS subsystem for TI's J721e

Quoted 77 lines · Faiz Abbas

Hi Tom,

Quoted 74 lines · Tom Rini
Quoted 72 lines · Faiz Abbas

The following patches add support for the Universal Flash Storage (UFS) subsystem and its implementation on TI's J721e platform.

The UFS Application Layer (UAP) uses SCSI SAM-4 command set for communication with the device. Therefore, the first 4 patches prepare the scsi layer for compatibility with UFS. Patch 9 also adds support for initializing and configuring the device from the U-boot command line.

The UFS Transport Protocol Layer (UTP) and UFS Interconnect Layer (UIC) are implemented with patch 5. This series only adds support for detect and read/write operations to the LUNs present in the remote device. Task Management operations and configuration of LUNs will be added in a future series.

Patches 6 through 10 add platform driver, device tree and config support for TI's J721E devices.

Log: https://pastebin.ubuntu.com/p/fTPZsxNjZM/

Tested on top of Lokesh's tree:
https://github.com/lokeshvutla/u-boot
Branch: j721e-full-boot

References:

[1] JESD220D UFS 3.0:
https://www.jedec.org/standards-documents/docs/jesd220c
[2] JESD223D UFS Host Controller Interface (UFSHCI) version 3.0:
https://www.jedec.org/standards-documents/docs/jesd223c

Faiz Abbas (10):
scsi: Simplify scsi_read()/_write()
scsi: Add max_bytes to scsi_platdata
scsi: Retry inquiry 3 times to overcome Unit Attention condition
scsi: Add dma direction member to command structure
ufs: Add Initial Support for UFS subsystem
ufs: Add Support for Cadence platform UFS driver
ufs: Add glue layer driver for TI J721E devices
arm: dts: k3-j721e-main: Add UFS nodes
cmd: Add Support for UFS commands
configs: j721e_evm_a72: Enable configs for UFS

 arch/arm/dts/k3-j721e-main.dtsi |   25 +
 cmd/Kconfig                     |    7 +
 cmd/Makefile                    |    2 +-
 cmd/ufs.c                       |   28 +
 configs/j721e_evm_a72_defconfig |    7 +-
 drivers/Kconfig                 |    2 +
 drivers/Makefile                |    1 +
 drivers/scsi/scsi.c             |   83 +-
 drivers/ufs/Kconfig             |   23 +
 drivers/ufs/Makefile            |    8 +
 drivers/ufs/cdns-platform.c     |  122 ++
 drivers/ufs/ti-j721e-ufs.c      |   75 ++
 drivers/ufs/ufs-uclass.c        |   16 +
 drivers/ufs/ufs.c               | 1973 +++++++++++++++++++++++++++++++
 drivers/ufs/ufs.h               |  918 ++++++++++++++
 drivers/ufs/unipro.h            |  270 +++++
 include/dm/uclass-id.h          |    1 +
 include/scsi.h                  |    4 +
 include/ufs.h                   |    7 +
 19 files changed, 3526 insertions(+), 46 deletions(-)
 create mode 100644 cmd/ufs.c
 create mode 100644 drivers/ufs/Kconfig
 create mode 100644 drivers/ufs/Makefile
 create mode 100644 drivers/ufs/cdns-platform.c
 create mode 100644 drivers/ufs/ti-j721e-ufs.c
 create mode 100644 drivers/ufs/ufs-uclass.c
 create mode 100644 drivers/ufs/ufs.c
 create mode 100644 drivers/ufs/ufs.h
 create mode 100644 drivers/ufs/unipro.h
 create mode 100644 include/ufs.h
Quoted 7 lines
Quoted 4 lines

I'm glad to see this support coming, it's something we need. Would you be willing to list yourself as the maintainer in the top-level MAINTAINER file for drivers/ufs at least? Thanks!

I did add to the MAINTAINER file in patch 5. Was that supposed to be a separate patch?

Ah, funny enough it's not in the diffstat here :) Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190909/06a57da4/attachment.sig>