public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Vignesh Raghavendra <vigneshr@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 2/6] mtd: Add TI HyperBus Memory Controller driver
Date: Thu, 10 Oct 2019 11:22:03 +0530	[thread overview]
Message-ID: <20191010055207.26831-3-vigneshr@ti.com> (raw)
In-Reply-To: <20191010055207.26831-1-vigneshr@ti.com>

AM654/J721e has HyperBus Memory Controller that supports HyperFlash and
HyperRAM devices. It provides a memory mapped interface to interact with
these devices. Add a driver to support the same.
Driver calibrates the controller, setups up for MMIO access and probes
HyperFlash child node.

Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
---
v2: No change

 drivers/mtd/Kconfig      |   7 +++
 drivers/mtd/Makefile     |   1 +
 drivers/mtd/hbmc-am654.c | 105 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 113 insertions(+)
 create mode 100644 drivers/mtd/hbmc-am654.c

diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index 0050fb2b9bf1..37f379d47803 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -94,6 +94,13 @@ config RENESAS_RPC_HF
 	  This enables access to Hyperflash memory through the Renesas
 	  RCar Gen3 RPC controller.
 
+config HBMC_AM654
+	bool "HyperBus controller driver for AM65x SoC"
+	depends on SYSCON
+	help
+	 This is the driver for HyperBus controller on TI's AM65x and
+	 other SoCs
+
 source "drivers/mtd/nand/Kconfig"
 
 source "drivers/mtd/spi/Kconfig"
diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile
index 22ceda93c06d..293079d709aa 100644
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
@@ -18,5 +18,6 @@ obj-$(CONFIG_FLASH_PIC32) += pic32_flash.o
 obj-$(CONFIG_ST_SMI) += st_smi.o
 obj-$(CONFIG_STM32_FLASH) += stm32_flash.o
 obj-$(CONFIG_RENESAS_RPC_HF) += renesas_rpc_hf.o
+obj-$(CONFIG_HBMC_AM654) += hbmc-am654.o
 
 obj-y += nand/
diff --git a/drivers/mtd/hbmc-am654.c b/drivers/mtd/hbmc-am654.c
new file mode 100644
index 000000000000..5a560f1253ba
--- /dev/null
+++ b/drivers/mtd/hbmc-am654.c
@@ -0,0 +1,105 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+// Author: Vignesh Raghavendra <vigneshr@ti.com>
+
+#include <common.h>
+#include <asm/io.h>
+#include <dm.h>
+#include <regmap.h>
+#include <syscon.h>
+
+#define FSS_SYSC_REG	0x4
+
+#define HYPERBUS_CALIB_COUNT 25
+
+struct am654_hbmc_priv {
+	void __iomem *mmiobase;
+	bool calibrated;
+};
+
+/* Calibrate by looking for "QRY" string within the CFI space */
+static int am654_hyperbus_calibrate(struct udevice *dev)
+{
+	struct am654_hbmc_priv *priv = dev_get_priv(dev);
+	int count = HYPERBUS_CALIB_COUNT;
+	int pass_count = 0;
+	u16 qry[3];
+
+	if (priv->calibrated)
+		return 0;
+
+	writew(0xF0, priv->mmiobase);
+	writew(0x98, priv->mmiobase + 0xaa);
+
+	while (count--) {
+		qry[0] = readw(priv->mmiobase + 0x20);
+		qry[1] = readw(priv->mmiobase + 0x22);
+		qry[2] = readw(priv->mmiobase + 0x24);
+
+		if (qry[0] == 'Q' && qry[1] == 'R' && qry[2] == 'Y')
+			pass_count++;
+		else
+			pass_count = 0;
+		if (pass_count == 5)
+			break;
+	}
+	writew(0xF0, priv->mmiobase);
+	writew(0xFF, priv->mmiobase);
+
+	return pass_count == 5;
+}
+
+static int am654_select_hbmc(struct udevice *dev)
+{
+	struct regmap *regmap = syscon_get_regmap(dev_get_parent(dev));
+
+	return regmap_update_bits(regmap, FSS_SYSC_REG, 0x2, 0x2);
+}
+
+static int am654_hbmc_bind(struct udevice *dev)
+{
+	return dm_scan_fdt_dev(dev);
+}
+
+static int am654_hbmc_probe(struct udevice *dev)
+{
+	struct am654_hbmc_priv *priv = dev_get_priv(dev);
+	int ret;
+
+	priv->mmiobase = devfdt_remap_addr_index(dev, 1);
+	if (dev_read_bool(dev, "mux-controls")) {
+		ret = am654_select_hbmc(dev);
+		if (ret) {
+			dev_err(dev, "Failed to select HBMC mux\n");
+			return ret;
+		}
+	}
+
+	if (!priv->calibrated) {
+		ret = am654_hyperbus_calibrate(dev);
+		if (!ret) {
+			dev_err(dev, "Calibration Failed\n");
+			return -EIO;
+		}
+	}
+	priv->calibrated = true;
+
+	return 0;
+}
+
+static const struct udevice_id am654_hbmc_dt_ids[] = {
+	{
+		.compatible = "ti,am654-hbmc",
+	},
+	{ /* end of table */ }
+};
+
+U_BOOT_DRIVER(hbmc_am654) = {
+	.name	= "hbmc-am654",
+	.id	= UCLASS_MTD,
+	.of_match = am654_hbmc_dt_ids,
+	.probe = am654_hbmc_probe,
+	.bind = am654_hbmc_bind,
+	.priv_auto_alloc_size = sizeof(struct am654_hbmc_priv),
+};
-- 
2.23.0

  parent reply	other threads:[~2019-10-10  5:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-10  5:52 [U-Boot] [PATCH v2 0/6] J721e: Add HyperBus support Vignesh Raghavendra
2019-10-10  5:52 ` [U-Boot] [PATCH v2 1/6] mtd: cfi_flash: Use CONFIG_SYS_MONITOR_BASE only when defined Vignesh Raghavendra
2019-10-10  6:03   ` Stefan Roese
2019-10-10  5:52 ` Vignesh Raghavendra [this message]
2019-10-10  6:03   ` [U-Boot] [PATCH v2 2/6] mtd: Add TI HyperBus Memory Controller driver Stefan Roese
2019-10-10  5:52 ` [U-Boot] [PATCH v2 3/6] arm: dts: k3-j721e-mcu-wakeup: Add HyperBus Controller node Vignesh Raghavendra
2019-10-23  2:36   ` Stefan Roese
2019-10-23  8:02     ` Vignesh Raghavendra
2019-10-10  5:52 ` [U-Boot] [PATCH v2 4/6] arm: dts: k3-j721e-som-p0: Add HyperFlash node Vignesh Raghavendra
2019-10-10  5:52 ` [U-Boot] [PATCH v2 5/6] configs: j721e_evm.h: Define CONFIG_SYS_MAX_FLASH_BANKS_DETECT Vignesh Raghavendra
2019-10-10  5:52 ` [U-Boot] [PATCH v2 6/6] configs: j721e_evm_a72_defconfig: Add HBMC related configs Vignesh Raghavendra
2019-10-15  8:59 ` [U-Boot] [PATCH v2 0/6] J721e: Add HyperBus support Vignesh Raghavendra
2019-10-18 12:48   ` 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=20191010055207.26831-3-vigneshr@ti.com \
    --to=vigneshr@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox