linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: linux-realtek-soc@lists.infradead.org
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, "Andreas Färber" <afaerber@suse.de>
Subject: [RFC 02/11] soc: Add Realtek chip info driver for RTD1195 and RTD1295
Date: Sun,  3 Nov 2019 02:36:36 +0100	[thread overview]
Message-ID: <20191103013645.9856-3-afaerber@suse.de> (raw)
In-Reply-To: <20191103013645.9856-1-afaerber@suse.de>

Add a soc bus driver to print chip model and revision details.

Revisions from downstream drivers/soc/realtek/rtd{119x,129x}/rtk_chip.c.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 Naming: What to call the family vs. soc_id?
 
 drivers/soc/Kconfig          |   1 +
 drivers/soc/Makefile         |   1 +
 drivers/soc/realtek/Kconfig  |  13 ++++
 drivers/soc/realtek/Makefile |   2 +
 drivers/soc/realtek/chip.c   | 164 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 181 insertions(+)
 create mode 100644 drivers/soc/realtek/Kconfig
 create mode 100644 drivers/soc/realtek/Makefile
 create mode 100644 drivers/soc/realtek/chip.c

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index 833e04a7835c..06ae9d97321c 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -11,6 +11,7 @@ source "drivers/soc/imx/Kconfig"
 source "drivers/soc/ixp4xx/Kconfig"
 source "drivers/soc/mediatek/Kconfig"
 source "drivers/soc/qcom/Kconfig"
+source "drivers/soc/realtek/Kconfig"
 source "drivers/soc/renesas/Kconfig"
 source "drivers/soc/rockchip/Kconfig"
 source "drivers/soc/samsung/Kconfig"
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 2ec355003524..1d55d838a342 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_SOC_XWAY)		+= lantiq/
 obj-y				+= mediatek/
 obj-y				+= amlogic/
 obj-y				+= qcom/
+obj-y				+= realtek/
 obj-y				+= renesas/
 obj-$(CONFIG_ARCH_ROCKCHIP)	+= rockchip/
 obj-$(CONFIG_SOC_SAMSUNG)	+= samsung/
diff --git a/drivers/soc/realtek/Kconfig b/drivers/soc/realtek/Kconfig
new file mode 100644
index 000000000000..be75c1889c61
--- /dev/null
+++ b/drivers/soc/realtek/Kconfig
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+if ARCH_REALTEK || COMPILE_TEST
+
+config REALTEK_SOC
+	tristate "Realtek chip info"
+	default ARCH_REALTEK
+	select SOC_BUS
+	help
+	  Say 'y' here to enable support for SoC info on Realtek RTD1195 and
+	  RTD1295 SoC families.
+	  If unsure, say 'n'.
+
+endif
diff --git a/drivers/soc/realtek/Makefile b/drivers/soc/realtek/Makefile
new file mode 100644
index 000000000000..49900273905b
--- /dev/null
+++ b/drivers/soc/realtek/Makefile
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+obj-$(CONFIG_REALTEK_SOC) += chip.o
diff --git a/drivers/soc/realtek/chip.c b/drivers/soc/realtek/chip.c
new file mode 100644
index 000000000000..9d13422e9936
--- /dev/null
+++ b/drivers/soc/realtek/chip.c
@@ -0,0 +1,164 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Realtek System-on-Chip info
+ *
+ * Copyright (c) 2017-2019 Andreas Färber
+ */
+
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/sys_soc.h>
+
+#define REG_CHIP_ID	0x0
+#define REG_CHIP_REV	0x4
+
+struct rtd_soc_revision {
+	const char *name;
+	u32 chip_rev;
+};
+
+static const struct rtd_soc_revision rtd1195_revisions[] = {
+	{ "A", 0x00000000 },
+	{ "B", 0x00010000 },
+	{ "C", 0x00020000 },
+	{ "D", 0x00030000 },
+	{ }
+};
+
+static const struct rtd_soc_revision rtd1295_revisions[] = {
+	{ "A00", 0x00000000 },
+	{ "A01", 0x00010000 },
+	{ "B00", 0x00020000 },
+	{ "B01", 0x00030000 },
+	{ }
+};
+
+struct rtd_soc {
+	u32 chip_id;
+	const char *family;
+	const char *(*get_name)(struct device *dev, const struct rtd_soc *s);
+	const struct rtd_soc_revision *revisions;
+	const char *codename;
+};
+
+static const char *default_name(struct device *dev, const struct rtd_soc *s)
+{
+	return s->family;
+}
+
+static const struct rtd_soc rtd_soc_families[] = {
+	{ 0x00006329, "RTD1195", default_name, rtd1195_revisions, "Phoenix" },
+	{ 0x00006421, "RTD1295", default_name, rtd1295_revisions, "Kylin" },
+};
+
+static const struct rtd_soc *rtd_soc_by_chip_id(u32 chip_id)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(rtd_soc_families); i++) {
+		const struct rtd_soc *family = &rtd_soc_families[i];
+
+		if (family->chip_id == chip_id)
+			return family;
+	}
+	return NULL;
+}
+
+static const char *rtd_soc_rev(const struct rtd_soc *family, u32 chip_rev)
+{
+	if (family) {
+		const struct rtd_soc_revision *rev = family->revisions;
+
+		while (rev && rev->name) {
+			if (rev->chip_rev == chip_rev)
+				return rev->name;
+			rev++;
+		}
+	}
+	return "unknown";
+}
+
+static int rtd_soc_probe(struct platform_device *pdev)
+{
+	const struct rtd_soc *s;
+	struct soc_device_attribute *soc_dev_attr;
+	struct soc_device *soc_dev;
+	struct device_node *node;
+	void __iomem *base;
+	u32 chip_id, chip_rev;
+
+	base = of_iomap(pdev->dev.of_node, 0);
+	if (!base)
+		return -ENODEV;
+
+	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+	if (!soc_dev_attr)
+		return -ENOMEM;
+
+	chip_id  = readl_relaxed(base + REG_CHIP_ID);
+	chip_rev = readl_relaxed(base + REG_CHIP_REV);
+
+	node = of_find_node_by_path("/");
+	of_property_read_string(node, "model", &soc_dev_attr->machine);
+	of_node_put(node);
+
+	s = rtd_soc_by_chip_id(chip_id);
+
+	soc_dev_attr->family = kasprintf(GFP_KERNEL, "Realtek %s",
+		(s && s->codename) ? s->codename :
+		((s && s->family) ? s->family : "Digital Home Center"));
+
+	if (likely(s && s->get_name))
+		soc_dev_attr->soc_id = s->get_name(&pdev->dev, s);
+	else
+		soc_dev_attr->soc_id = "unknown";
+
+	soc_dev_attr->revision = rtd_soc_rev(s, chip_rev);
+
+	soc_dev = soc_device_register(soc_dev_attr);
+	if (IS_ERR(soc_dev)) {
+		kfree(soc_dev_attr->family);
+		kfree(soc_dev_attr);
+		return PTR_ERR(soc_dev);
+	}
+
+	platform_set_drvdata(pdev, soc_dev);
+
+	dev_info(soc_device_to_device(soc_dev),
+		"%s %s (0x%08x) rev %s (0x%08x) detected\n",
+		soc_dev_attr->family, soc_dev_attr->soc_id, chip_id,
+		soc_dev_attr->revision, chip_rev);
+
+	return 0;
+}
+
+static int rtd_soc_remove(struct platform_device *pdev)
+{
+	struct soc_device *soc_dev = platform_get_drvdata(pdev);
+
+	soc_device_unregister(soc_dev);
+
+	return 0;
+}
+
+static const struct of_device_id rtd_soc_dt_ids[] = {
+	 { .compatible = "realtek,rtd1195-chip" },
+	 { }
+};
+
+static struct platform_driver rtd_soc_driver = {
+	.probe = rtd_soc_probe,
+	.remove = rtd_soc_remove,
+	.driver = {
+		.name = "rtd1195-soc",
+		.of_match_table	= rtd_soc_dt_ids,
+	},
+};
+module_platform_driver(rtd_soc_driver);
+
+MODULE_DESCRIPTION("Realtek SoC identification");
+MODULE_LICENSE("GPL");
-- 
2.16.4


  parent reply	other threads:[~2019-11-03  1:37 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-03  1:36 [RFC 00/11] ARM: Realtek RTD1195/RTD1295 SoC info Andreas Färber
2019-11-03  1:36 ` [RFC 01/11] dt-bindings: soc: Add Realtek RTD1195 chip info binding Andreas Färber
2019-11-06  4:41   ` Rob Herring
2019-11-03  1:36 ` Andreas Färber [this message]
2019-11-03  1:45   ` [RFC 02/11] soc: Add Realtek chip info driver for RTD1195 and RTD1295 Andreas Färber
2019-11-11  4:56   ` [PATCH] base: soc: Export soc_device_to_device() helper Andreas Färber
2019-11-11  5:27     ` Greg Kroah-Hartman
2019-11-11  5:42       ` Andreas Färber
2019-11-11  6:40         ` Greg Kroah-Hartman
2019-11-11 20:10           ` Andreas Färber
2019-11-12  0:29             ` Andreas Färber
2019-11-12  5:23             ` Greg Kroah-Hartman
2019-11-12  7:29               ` Uwe Kleine-König
2019-11-12 10:47                 ` Sense of soc bus? (was: [PATCH] base: soc: Export soc_device_to_device() helper) Andreas Färber
2019-11-14 22:09                   ` Rob Herring
2019-11-15 11:15                     ` Andreas Färber
2019-11-15 11:49                     ` Andreas Färber
2019-11-15  8:52                   ` Neil Armstrong
2019-11-15  8:58                     ` Geert Uytterhoeven
2019-11-15 12:00                       ` Andreas Färber
2019-11-15 12:34                         ` Geert Uytterhoeven
2019-11-18 15:55                           ` Tony Lindgren
2019-11-12 10:48                 ` [PATCH] base: soc: Export soc_device_to_device() helper Lee Jones
2020-01-02 14:29   ` [RFC 02/11] soc: Add Realtek chip info driver for RTD1195 and RTD1295 James Tai
2020-01-02 14:39     ` Andreas Färber
2020-01-02 15:02       ` James Tai
2020-01-03  5:07     ` Stanley Chang[昌育德]
2019-11-03  1:36 ` [RFC 03/11] arm64: dts: realtek: rtd129x: Add chip info node Andreas Färber
2020-01-02 14:32   ` James Tai
2020-01-03  5:07     ` Stanley Chang[昌育德]
2020-01-02 14:33   ` James Tai
2020-01-02 14:34   ` James Tai
2019-11-03  1:36 ` [RFC 04/11] ARM: dts: rtd1195: " Andreas Färber
2019-11-03  1:36 ` [RFC 05/11] dt-bindings: soc: realtek: rtd1195-chip: Extend reg property Andreas Färber
2019-11-06  4:46   ` Rob Herring
2019-11-06  8:42     ` Andreas Färber
2019-11-03  1:36 ` [RFC 06/11] soc: realtek: chip: Detect RTD1296 Andreas Färber
2020-01-02 14:35   ` James Tai
2019-11-03  1:36 ` [RFC 07/11] arm64: dts: realtek: rtd129x: Extend chip-info reg with CHIP_INFO1 Andreas Färber
2019-11-03  1:36 ` [RFC 08/11] soc: realtek: chip: Detect RTD1293 Andreas Färber
2019-11-03  1:36 ` [RFC 09/11] dt-bindings: soc: realtek: rtd1195-chip: Extend reg node again Andreas Färber
2019-11-03  1:36 ` [RFC 10/11] soc: realtek: chip: Detect RTD1294 Andreas Färber
2019-11-03  1:36 ` [RFC 11/11] arm64: dts: realtek: rtd129x: Extend chip-info reg with efuse Andreas Färber
2019-11-07  7:16 ` [RFC 00/11] ARM: Realtek RTD1195/RTD1295 SoC info Andreas Färber

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=20191103013645.9856-3-afaerber@suse.de \
    --to=afaerber@suse.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-realtek-soc@lists.infradead.org \
    /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;
as well as URLs for NNTP newsgroup(s).