public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH 06/10] ram: Add driver for K210 SRAM
Date: Tue, 29 Sep 2020 10:18:31 -0400	[thread overview]
Message-ID: <20200929141835.38435-7-seanga2@gmail.com> (raw)
In-Reply-To: <20200929141835.38435-1-seanga2@gmail.com>

This adds a driver to handle enabling the clock for the AI SRAM. This was
previously done in board_init, but it needs to happen before relocation
now. An alternative would be to move this to board_init_early_f, but by
doing it this way we can use clk_bulk.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

 MAINTAINERS            |  1 +
 drivers/ram/Kconfig    |  7 ++++++
 drivers/ram/Makefile   |  1 +
 drivers/ram/kendryte.c | 56 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 65 insertions(+)
 create mode 100644 drivers/ram/kendryte.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 7e46470c70..70e01e5e7a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -928,6 +928,7 @@ M:	Sean Anderson <seanga2@gmail.com>
 S:	Maintained
 F:	doc/device-tree-bindings/mfd/kendryte,k210-sysctl.txt
 F:	drivers/clk/kendryte/
+F:	drivers/ram/kendryte.c
 F:	include/kendryte/
 
 RNG
diff --git a/drivers/ram/Kconfig b/drivers/ram/Kconfig
index 7e6e981897..faeacdf014 100644
--- a/drivers/ram/Kconfig
+++ b/drivers/ram/Kconfig
@@ -73,6 +73,13 @@ config IMXRT_SDRAM
 	  to support external memories like sdram, psram & nand.
 	  This driver is for the sdram memory interface with the SEMC.
 
+config K210_SRAM
+	bool "Enable Kendryte K210 SRAM support"
+	depends on RAM
+	help
+	  The Kendryte K210 has three banks of SRAM. This driver does the
+	  necessary initialization.
+
 source "drivers/ram/rockchip/Kconfig"
 source "drivers/ram/sifive/Kconfig"
 source "drivers/ram/stm32mp1/Kconfig"
diff --git a/drivers/ram/Makefile b/drivers/ram/Makefile
index 769c9d6218..d36b955e00 100644
--- a/drivers/ram/Makefile
+++ b/drivers/ram/Makefile
@@ -19,3 +19,4 @@ obj-$(CONFIG_K3_J721E_DDRSS) += k3-j721e/
 obj-$(CONFIG_IMXRT_SDRAM) += imxrt_sdram.o
 
 obj-$(CONFIG_RAM_SIFIVE) += sifive/
+obj-$(CONFIG_K210_SRAM) += kendryte.o
diff --git a/drivers/ram/kendryte.c b/drivers/ram/kendryte.c
new file mode 100644
index 0000000000..50818bf005
--- /dev/null
+++ b/drivers/ram/kendryte.c
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Sean Anderson <seanga2@gmail.com>
+ */
+
+#include <common.h>
+#include <clk.h>
+#include <dm.h>
+#include <ram.h>
+
+static int k210_sram_probe(struct udevice *dev)
+{
+	int ret;
+	struct clk_bulk clocks;
+
+	/* Relocate as high as possible to leave more space to load payloads */
+	ret = fdtdec_setup_mem_size_base_highest();
+	if (ret)
+		return ret;
+
+	/* Enable ram bank clocks */
+	ret = clk_get_bulk(dev, &clocks);
+	if (ret)
+		return ret;
+
+	ret = clk_enable_bulk(&clocks);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int k210_sram_get_info(struct udevice *dev, struct ram_info *info)
+{
+	info->base = gd->ram_base;
+	info->size = gd->ram_size;
+
+	return 0;
+}
+
+static struct ram_ops k210_sram_ops = {
+	.get_info = k210_sram_get_info,
+};
+
+static const struct udevice_id k210_sram_ids[] = {
+	{ .compatible = "kendryte,k210-sram" },
+	{ }
+};
+
+U_BOOT_DRIVER(fu540_ddr) = {
+	.name = "k210_sram",
+	.id = UCLASS_RAM,
+	.of_match = k210_sram_ids,
+	.ops = &k210_sram_ops,
+	.probe = k210_sram_probe,
+};
-- 
2.28.0

  parent reply	other threads:[~2020-09-29 14:18 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-29 14:18 [PATCH 00/10] riscv: k210: Enable use of AI ram bank Sean Anderson
2020-09-29 14:18 ` [PATCH 01/10] clk: k210: Fix PLLs not being enabled Sean Anderson
2020-09-29 14:18 ` [PATCH 02/10] clk: Add support for the k210 clock driver pre-relocation Sean Anderson
2020-09-29 14:18 ` [PATCH 03/10] riscv: Enable some devices pre-relocation Sean Anderson
2020-09-29 14:18 ` [PATCH 04/10] lib: fdt: Add fdtdec_setup_mem_size_base_highest Sean Anderson
2020-10-12  3:34   ` Simon Glass
2020-09-29 14:18 ` [PATCH 05/10] test: Add a test for fdtdec_setup_mem_size_base et al Sean Anderson
2020-10-12  3:34   ` Simon Glass
2020-09-29 14:18 ` Sean Anderson [this message]
2020-10-07 13:26   ` [PATCH 06/10] ram: Add driver for K210 SRAM Simon Glass
2020-09-29 14:18 ` [PATCH 07/10] ram: sifive: Default to y only if compiling for fu540 Sean Anderson
2020-09-30  4:08   ` Pragnesh Patel
2020-09-29 14:18 ` [PATCH 08/10] riscv: Probe ram in dram_init Sean Anderson
2020-09-29 14:18 ` [PATCH 09/10] riscv: Enable AI ram on K210 Sean Anderson
2020-09-29 14:18 ` [PATCH 10/10] riscv: Don't reserve AI ram in k210 dts Sean Anderson
2020-09-29 15:03   ` Heinrich Schuchardt
2020-09-29 15:07     ` Sean Anderson

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=20200929141835.38435-7-seanga2@gmail.com \
    --to=seanga2@gmail.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