All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean-Jacques Hiblot <jjhiblot@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 06/10] drivers: block: dwc_ahci: Implement a driver for Synopsys DWC sata device
Date: Fri, 7 Apr 2017 13:42:05 +0200	[thread overview]
Message-ID: <1491565329-20267-7-git-send-email-jjhiblot@ti.com> (raw)
In-Reply-To: <1491565329-20267-1-git-send-email-jjhiblot@ti.com>

From: Mugunthan V N <mugunthanvnm@ti.com>

Implement a sata driver for Synopsys DWC sata device based on
U-boot driver model.

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
---
 drivers/block/Kconfig    |  10 +++++
 drivers/block/Makefile   |   1 +
 drivers/block/dwc_ahci.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+)
 create mode 100644 drivers/block/dwc_ahci.c

diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 88e66e2..b3d35bd 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -48,4 +48,14 @@ config SATA_CEVA
 	  ZynqMP. Support up to 2 external devices. Complient with SATA 3.1 and
 	  AHCI 1.3 specifications with hot-plug detect feature.
 
+
+config DWC_AHCI
+	bool "Enable Synopsys DWC AHCI driver support"
+	select SCSI_AHCI
+	select GENERIC_PHY
+	depends on DM_SCSI
+	help
+	  Enable this driver to support Sata devices through
+	  Synopsys DWC AHCI module.
+
 endmenu
diff --git a/drivers/block/Makefile b/drivers/block/Makefile
index a72feec..cffe498 100644
--- a/drivers/block/Makefile
+++ b/drivers/block/Makefile
@@ -11,6 +11,7 @@ ifndef CONFIG_BLK
 obj-y += blk_legacy.o
 endif
 
+obj-$(CONFIG_DWC_AHCI) += dwc_ahci.o
 obj-$(CONFIG_AHCI) += ahci-uclass.o
 obj-$(CONFIG_DM_SCSI) += scsi-uclass.o
 obj-$(CONFIG_SCSI_AHCI) += ahci.o
diff --git a/drivers/block/dwc_ahci.c b/drivers/block/dwc_ahci.c
new file mode 100644
index 0000000..bf44946
--- /dev/null
+++ b/drivers/block/dwc_ahci.c
@@ -0,0 +1,100 @@
+/*
+ * DWC SATA platform driver
+ *
+ * (C) Copyright 2016
+ *     Texas Instruments Incorporated, <www.ti.com>
+ *
+ * Author: Mugunthan V N <mugunthanvnm@ti.com>
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <ahci.h>
+#include <scsi.h>
+#include <sata.h>
+#include <asm/arch/sata.h>
+#include <asm/io.h>
+#include <generic-phy.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct dwc_ahci_priv {
+	void *base;
+	void *wrapper_base;
+};
+
+static int dwc_ahci_ofdata_to_platdata(struct udevice *dev)
+{
+	struct dwc_ahci_priv *priv = dev_get_priv(dev);
+	struct scsi_platdata *plat = dev_get_platdata(dev);
+	fdt_addr_t addr;
+
+	plat->max_id = fdtdec_get_uint(gd->fdt_blob, dev->of_offset, "max-id",
+				       CONFIG_SYS_SCSI_MAX_SCSI_ID);
+	plat->max_lun = fdtdec_get_uint(gd->fdt_blob, dev->of_offset,
+					"max-lun", CONFIG_SYS_SCSI_MAX_LUN);
+
+	priv->base = map_physmem(dev_get_addr(dev), sizeof(void *),
+				 MAP_NOCACHE);
+
+	addr = dev_get_addr_index(dev, 1);
+	if (addr != FDT_ADDR_T_NONE) {
+		priv->wrapper_base = map_physmem(addr, sizeof(void *),
+						 MAP_NOCACHE);
+	} else {
+		priv->wrapper_base = NULL;
+	}
+
+	return 0;
+}
+
+static int dwc_ahci_probe(struct udevice *dev)
+{
+	struct dwc_ahci_priv *priv = dev_get_priv(dev);
+	int ret;
+	struct generic_phy *phy = dm_generic_phy_get(dev, "phys");
+
+	if (IS_ERR(phy)) {
+		error("can't get the phy from DT\n");
+		return PTR_ERR(phy);
+	}
+
+	ret = generic_phy_init(phy);
+	if (ret) {
+		error("unable to initialize the sata phy\n");
+		return ret;
+	}
+
+	ret = generic_phy_power_on(phy);
+	if (ret) {
+		error("unable to power on the sata phy\n");
+		return ret;
+	}
+
+	if (priv->wrapper_base) {
+		u32 val = TI_SATA_IDLE_NO | TI_SATA_STANDBY_NO;
+
+		/* Enable SATA module, No Idle, No Standby */
+		writel(val, priv->wrapper_base + TI_SATA_SYSCONFIG);
+	}
+
+	return ahci_init(priv->base);
+}
+
+static const struct udevice_id dwc_ahci_ids[] = {
+	{ .compatible = "snps,dwc-ahci" },
+	{ }
+};
+
+U_BOOT_DRIVER(dwc_ahci) = {
+	.name	= "dwc_ahci",
+	.id	= UCLASS_SCSI,
+	.of_match = dwc_ahci_ids,
+	.ofdata_to_platdata = dwc_ahci_ofdata_to_platdata,
+	.probe	= dwc_ahci_probe,
+	.priv_auto_alloc_size = sizeof(struct dwc_ahci_priv),
+	.platdata_auto_alloc_size = sizeof(struct scsi_platdata),
+	.flags = DM_FLAG_ALLOC_PRIV_DMA,
+};
-- 
1.9.1

  parent reply	other threads:[~2017-04-07 11:42 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-07 11:41 [U-Boot] [PATCH v2 00/10] OMAP: Move SATA to use block driver model Jean-Jacques Hiblot
2017-04-07 11:42 ` [U-Boot] [PATCH v2 01/10] arm: omap: sata: move enable sata clocks to enable_basic_clocks() Jean-Jacques Hiblot
2017-04-15 16:07   ` Simon Glass
2017-04-07 11:42 ` [U-Boot] [PATCH v2 02/10] arm: omap: sata: compile out board-level sata code when CONFIG_DM_SCSI is defined Jean-Jacques Hiblot
2017-04-09  1:13   ` Tom Rini
2017-04-15 16:07     ` Simon Glass
2017-04-07 11:42 ` [U-Boot] [PATCH v2 03/10] drivers: phy: add generic PHY framework Jean-Jacques Hiblot
2017-04-09  1:13   ` Tom Rini
2017-04-09 19:27   ` Simon Glass
2017-04-13 14:17     ` Jean-Jacques Hiblot
2017-04-14 10:36       ` Simon Glass
2017-04-14 11:12         ` Jean-Jacques Hiblot
2017-04-07 11:42 ` [U-Boot] [PATCH v2 04/10] drivers: phy: add PIPE3 phy driver Jean-Jacques Hiblot
2017-04-09  1:13   ` Tom Rini
2017-04-09 19:27   ` Simon Glass
2017-04-07 11:42 ` [U-Boot] [PATCH v2 05/10] dra7: dtsi: mark ocp2scp bus compatible with "simple-bus" Jean-Jacques Hiblot
2017-04-09  1:13   ` Tom Rini
2017-04-13 14:18     ` Jean-Jacques Hiblot
2017-04-07 11:42 ` Jean-Jacques Hiblot [this message]
2017-04-09  1:13   ` [U-Boot] [PATCH v2 06/10] drivers: block: dwc_ahci: Implement a driver for Synopsys DWC sata device Tom Rini
2017-04-09 19:27   ` Simon Glass
2017-04-07 11:42 ` [U-Boot] [PATCH v2 07/10] scsi: make the LUN a parameter of scsi_detect_dev() Jean-Jacques Hiblot
2017-04-09  1:13   ` Tom Rini
2017-04-09 19:27   ` Simon Glass
2017-04-15 16:07     ` Simon Glass
2017-04-07 11:42 ` [U-Boot] [PATCH v2 08/10] scsi: move the partition initialization out of the scsi detection Jean-Jacques Hiblot
2017-04-09  1:13   ` Tom Rini
2017-04-09 19:27   ` Simon Glass
2017-04-15 16:07     ` Simon Glass
2017-04-07 11:42 ` [U-Boot] [PATCH v2 09/10] dm: scsi: fix divide-by-0 error in scsi_scan() Jean-Jacques Hiblot
2017-04-09  1:13   ` Tom Rini
2017-04-09 19:27   ` Simon Glass
2017-04-15 16:07     ` Simon Glass
2017-04-07 11:42 ` [U-Boot] [PATCH v2 10/10] defconfig: dra7xx_evm: enable CONFIG_BLK and disk driver model for SCSI Jean-Jacques Hiblot
2017-04-09  1:14   ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1491565329-20267-7-git-send-email-jjhiblot@ti.com \
    --to=jjhiblot@ti.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.