All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Gerlach <d-gerlach@ti.com>
To: u-boot@lists.denx.de
Subject: [PATCH v2 4/9] dm: soc: Introduce soc_ti_k3 driver for TI K3 SoCs
Date: Wed, 15 Jul 2020 23:39:59 -0500	[thread overview]
Message-ID: <20200716044004.6014-5-d-gerlach@ti.com> (raw)
In-Reply-To: <20200716044004.6014-1-d-gerlach@ti.com>

Introduce an soc_ti_k3_driver that allows identification and selection
of SoC specific data based on the JTAG ID register for device
identification, as described for AM65x[0] and J721E[1] devices.

[0] http://www.ti.com/lit/ug/spruid7e/spruid7e.pdf
[1] http://www.ti.com/lit/ug/spruil1a/spruil1a.pdf

Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
---
 drivers/soc/Kconfig     |   7 +++
 drivers/soc/Makefile    |   1 +
 drivers/soc/soc_ti_k3.c | 124 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 132 insertions(+)
 create mode 100644 drivers/soc/soc_ti_k3.c

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index e715dfd01712..864d00a88538 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -9,6 +9,13 @@ config SOC_DEVICE
 	  need different parameters or quirks enabled depending on the
 	  specific device variant in use.
 
+config SOC_DEVICE_TI_K3
+	depends on SOC_DEVICE
+	bool "Enable SoC Device ID driver for TI K3 SoCs"
+	help
+	  This allows Texas Instruments Keystone 3 SoCs to identify
+	  specifics about the SoC in use.
+
 source "drivers/soc/ti/Kconfig"
 
 endmenu
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 649e92b3906d..9ef20ca5066f 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -4,4 +4,5 @@
 
 obj-$(CONFIG_SOC_TI) += ti/
 obj-$(CONFIG_SOC_DEVICE) += soc-uclass.o
+obj-$(CONFIG_SOC_DEVICE_TI_K3) += soc_ti_k3.o
 obj-$(CONFIG_SANDBOX) += soc_sandbox.o
diff --git a/drivers/soc/soc_ti_k3.c b/drivers/soc/soc_ti_k3.c
new file mode 100644
index 000000000000..ae23ef747520
--- /dev/null
+++ b/drivers/soc/soc_ti_k3.c
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
+ *	Dave Gerlach <d-gerlach@ti.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <soc.h>
+
+#include <asm/io.h>
+
+#define AM65X			0xbb5a
+#define J721E			0xbb64
+
+#define REV_SR1_0		0
+#define REV_SR2_0		1
+
+#define JTAG_ID_VARIANT_SHIFT	28
+#define JTAG_ID_VARIANT_MASK	(0xf << 28)
+#define JTAG_ID_PARTNO_SHIFT	12
+#define JTAG_ID_PARTNO_MASK	(0xffff << 12)
+
+struct soc_ti_k3_platdata {
+	const char *family;
+	const char *revision;
+};
+
+static const char *get_family_string(u32 idreg)
+{
+	const char *family;
+	u32 soc;
+
+	soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
+
+	switch (soc) {
+	case AM65X:
+		family = "AM65X";
+		break;
+	case J721E:
+		family = "J721E";
+		break;
+	default:
+		family = "Unknown Silicon";
+	};
+
+	return family;
+}
+
+static const char *get_rev_string(u32 idreg)
+{
+	const char *revision;
+	u32 rev;
+
+	rev = (idreg & JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
+
+	switch (rev) {
+	case REV_SR1_0:
+		revision = "1.0";
+		break;
+	case REV_SR2_0:
+		revision = "2.0";
+		break;
+	default:
+		revision = "Unknown Revision";
+	};
+
+	return revision;
+}
+
+static int soc_ti_k3_get_family(struct udevice *dev, char *buf, int size)
+{
+	struct soc_ti_k3_platdata *plat = dev_get_platdata(dev);
+
+	snprintf(buf, size, "%s", plat->family);
+
+	return 0;
+}
+
+static int soc_ti_k3_get_revision(struct udevice *dev, char *buf, int size)
+{
+	struct soc_ti_k3_platdata *plat = dev_get_platdata(dev);
+
+	snprintf(buf, size, "SR%s", plat->revision);
+
+	return 0;
+}
+
+static const struct soc_ops soc_ti_k3_ops = {
+	.get_family = soc_ti_k3_get_family,
+	.get_revision = soc_ti_k3_get_revision,
+};
+
+int soc_ti_k3_probe(struct udevice *dev)
+{
+	struct soc_ti_k3_platdata *plat = dev_get_platdata(dev);
+	u32 idreg;
+	void *idreg_addr;
+
+	idreg_addr = dev_read_addr_ptr(dev);
+	if (!idreg_addr)
+		return -EINVAL;
+
+	idreg = readl(idreg_addr);
+
+	plat->family = get_family_string(idreg);
+	plat->revision = get_rev_string(idreg);
+
+	return 0;
+}
+
+static const struct udevice_id soc_ti_k3_ids[] = {
+	{ .compatible = "ti,am654-chipid" },
+	{ }
+};
+
+U_BOOT_DRIVER(soc_ti_k3) = {
+	.name           = "soc_ti_k3",
+	.id             = UCLASS_SOC,
+	.ops		= &soc_ti_k3_ops,
+	.of_match       = soc_ti_k3_ids,
+	.probe          = soc_ti_k3_probe,
+	.platdata_auto_alloc_size = sizeof(struct soc_ti_k3_platdata),
+};
-- 
2.20.1

  parent reply	other threads:[~2020-07-16  4:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-16  4:39 [PATCH v2 0/9] Introduce UCLASS_SOC Dave Gerlach
2020-07-16  4:39 ` [PATCH v2 1/9] doc: Add new doc for soc ID driver model Dave Gerlach
2020-07-17  1:58   ` Simon Glass
2020-07-16  4:39 ` [PATCH v2 2/9] dm: soc: Introduce UCLASS_SOC for SOC ID and attribute matching Dave Gerlach
2020-07-16  4:39 ` [PATCH v2 3/9] test: Add tests for SOC uclass Dave Gerlach
2020-07-16  4:39 ` Dave Gerlach [this message]
2020-07-16  4:40 ` [PATCH v2 5/9] arm: dts: k3-am65-wakeup: Introduce chipid node Dave Gerlach
2020-07-16  4:40 ` [PATCH v2 6/9] arm: dts: k3-j721e-mcu-wakeup: " Dave Gerlach
2020-07-16  4:40 ` [PATCH v2 7/9] configs: am65x_evm: Enable CONFIG_SOC_DEVICE and CONFIG_SOC_DEVICE_TI_K3 Dave Gerlach
2020-07-16  4:40 ` [PATCH v2 8/9] configs: j721e_evm: " Dave Gerlach
2020-07-16  4:40 ` [PATCH v2 9/9] arm: mach-k3: Use SOC driver for device identification Dave Gerlach
2020-07-16 14:54 ` [PATCH v2 0/9] Introduce UCLASS_SOC Grygorii Strashko

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=20200716044004.6014-5-d-gerlach@ti.com \
    --to=d-gerlach@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.