All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Stanley <joel@jms.id.au>
To: Ryan Chen <ryan_chen@aspeedtech.com>, Jeremy Kerr <jk@ozlabs.org>,
	Andrew Jeffery <andrew@aj.id.au>
Cc: openbmc@lists.ozlabs.org
Subject: [PATCH u-boot aspeed-dev-v2019.04 7/7] cmd: Add FSI command
Date: Wed, 30 Oct 2019 17:02:25 +1030	[thread overview]
Message-ID: <20191030063225.11319-8-joel@jms.id.au> (raw)
In-Reply-To: <20191030063225.11319-1-joel@jms.id.au>

This allows a user to issue breaks, and read and write CFAM (remote FSI)
addresses.

The master to use on the command line can be selected from the probe
command.

 # fsi probe 0
 # fsi break

Signed-off-by: Joel Stanley <joel@jms.id.au>
---
 cmd/Kconfig  |   6 ++
 cmd/Makefile |   1 +
 cmd/fsi.c    | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 160 insertions(+)
 create mode 100644 cmd/fsi.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 68afd06b101e..221a07eed5a6 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -692,6 +692,12 @@ config CMD_FDC
 	help
 	  The 'fdtboot' command allows booting an image from a floppy disk.
 
+config CMD_FSI
+	bool "fsi - use FSI master"
+	depends on ASPEED_FSI
+	help
+	 The 'fsi' command allows use of the FSI master present in ASPEED SoCs
+
 config CMD_FLASH
 	bool "flinfo, erase, protect"
 	default y
diff --git a/cmd/Makefile b/cmd/Makefile
index 493f241f39d6..05bc0410d5d1 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -64,6 +64,7 @@ obj-$(CONFIG_CMD_FLASH) += flash.o
 obj-$(CONFIG_CMD_FPGA) += fpga.o
 obj-$(CONFIG_CMD_FPGAD) += fpgad.o
 obj-$(CONFIG_CMD_FS_GENERIC) += fs.o
+obj-$(CONFIG_CMD_FSI) += fsi.o
 obj-$(CONFIG_CMD_FUSE) += fuse.o
 obj-$(CONFIG_CMD_GETTIME) += gettime.o
 obj-$(CONFIG_CMD_GPIO) += gpio.o
diff --git a/cmd/fsi.c b/cmd/fsi.c
new file mode 100644
index 000000000000..7dacf7957961
--- /dev/null
+++ b/cmd/fsi.c
@@ -0,0 +1,153 @@
+#include <common.h>
+#include <command.h>
+#include <aspeed_fsi.h>
+#include <dm/device.h>
+#include <dm/uclass.h>
+
+struct fsi_master_aspeed *fsi;
+
+static void do_break(void)
+{
+	debug("%s\n", __func__);
+	aspeed_fsi_break(fsi, 0);
+}
+
+static void do_status(void)
+{
+	debug("%s\n", __func__);
+	aspeed_fsi_status(fsi);
+}
+
+static void do_getcfam(int argc, char *const argv[])
+{
+	int rc;
+	uint32_t addr, val;
+
+	if (argc != 3) {
+		printf("invalid arguments to getcfam\n");
+		return;
+	}
+
+	addr = simple_strtoul(argv[2], NULL, 16);
+
+	debug("%s %08x\n", __func__, addr);
+	rc = aspeed_fsi_read(fsi, 0, addr, &val, 4);
+	if (rc) {
+		printf("error reading: %d\n", rc);
+		return;
+	}
+
+	printf("0x%08x\n", be32_to_cpu(val));
+}
+
+static void do_putcfam(int argc, char *const argv[])
+{
+	int rc;
+	uint32_t addr, val;
+
+	if (argc != 4) {
+		printf("invalid arguments to putcfam\n");
+		return;
+	}
+
+	addr = simple_strtoul(argv[2], NULL, 16);
+	val = simple_strtoul(argv[3], NULL, 16);
+
+	debug("%s %08x %08x\n", __func__, addr, val);
+	rc = aspeed_fsi_write(fsi, 0, addr, &val, 4);
+	if (rc)
+		printf("error writing: %d\n", rc);
+}
+
+static void do_divisor(int argc, char *const argv[])
+{
+	int rc;
+	uint32_t val;
+
+	if (argc == 2) {
+		rc = aspeed_fsi_divisor(fsi, 0);
+		if (rc > 0)
+			printf("divsior: %d (%d MHz)\n", rc, rc * 166);
+	} else if (argc == 3) {
+		val = simple_strtoul(argv[2], NULL, 16);
+		rc = aspeed_fsi_divisor(fsi, val);
+	} else {
+		printf("invalid arguments to divisor\n");
+		return;
+	}
+
+	if (rc < 0)
+		printf("divisor error: %d\n", rc);
+}
+
+static struct fsi_master_aspeed *do_probe(int argc, char *const argv[])
+{
+	struct udevice *dev;
+	const char *devices[] = {"fsi@1e79b000", "fsi@1e79b100"};
+	int rc, id;
+
+	if (argc > 3) {
+		printf("invalid arguments to probe\n");
+		return NULL;
+	}
+
+	if (argc == 2)
+		id = 0;
+	else
+		id = simple_strtoul(argv[2], NULL, 10);
+
+	if (id > 1) {
+		printf("valid devices: 0, 1\n");
+		return NULL;
+	}
+
+	rc = uclass_get_device_by_name(UCLASS_MISC, devices[id], &dev);
+	if (rc) {
+		printf("fsi device %s not found\n", devices[id]);
+		return NULL;
+	}
+	return dev_get_priv(dev);
+}
+
+
+static int do_fsi(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+
+	if (!strcmp(argv[1], "probe")) {
+		fsi = do_probe(argc, argv);
+		return 0;
+	}
+
+	if (fsi == NULL) {
+		printf("Run probe first\n");
+		return -EINVAL;
+	}
+
+	if (!strcmp(argv[1], "break"))
+		do_break();
+	else if (!strcmp(argv[1], "status"))
+		do_status();
+	else if (!strncmp(argv[1], "put", 3))
+		do_putcfam(argc, argv);
+	else if (!strncmp(argv[1], "get", 3))
+		do_getcfam(argc, argv);
+	else if (!strncmp(argv[1], "div", 3))
+		do_divisor(argc, argv);
+
+	return 0;
+}
+
+static char fsi_help_text[] =
+	"fsi probe [<n>]\n"
+	"fsi break\n"
+	"fsi getcfam <addr>\n"
+	"fsi putcfam <addr> <value>\n"
+	"fsi divisor [<divisor>]\n"
+	"fsi status\n";
+
+U_BOOT_CMD(
+	fsi, 4, 1, do_fsi,
+	"IBM FSI commands",
+	fsi_help_text
+);
+
-- 
2.23.0

      parent reply	other threads:[~2019-10-30  6:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-30  6:32 [PATCH u-boot aspeed-dev-v2019.04 0/7] FSI driver for u-boot Joel Stanley
2019-10-30  6:32 ` [PATCH u-boot aspeed-dev-v2019.04 1/7] dt-bindings: Add FSI clock Joel Stanley
2019-10-30  6:32 ` [PATCH u-boot aspeed-dev-v2019.04 2/7] dts: ast2600: Add FSI description Joel Stanley
2019-10-30  6:32 ` [PATCH u-boot aspeed-dev-v2019.04 3/7] aspeed: pinctrl: Add FSI support Joel Stanley
2019-10-30  6:32 ` [PATCH u-boot aspeed-dev-v2019.04 4/7] aspeed: clock: Add FSI clock Joel Stanley
2019-10-30  6:32 ` [PATCH u-boot aspeed-dev-v2019.04 5/7] dts: ast2600-evb: Enable FSI masters Joel Stanley
2019-10-30  6:32 ` [PATCH u-boot aspeed-dev-v2019.04 6/7] Add FSI driver Joel Stanley
2019-10-30  6:32 ` Joel Stanley [this message]

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=20191030063225.11319-8-joel@jms.id.au \
    --to=joel@jms.id.au \
    --cc=andrew@aj.id.au \
    --cc=jk@ozlabs.org \
    --cc=openbmc@lists.ozlabs.org \
    --cc=ryan_chen@aspeedtech.com \
    /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.