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,
"James Tai [戴志峰]" <james.tai@realtek.com>,
"Stanley Chang [昌育德]" <stanley_chang@realtek.com>,
"Edgar Lee" <cylee12@realtek.com>,
"Andreas Färber" <afaerber@suse.de>
Subject: [PATCH v2 02/29] soc: Add Realtek DHC chip info driver for RTD1195 and RTD1295
Date: Tue, 23 Jun 2020 04:50:39 +0200 [thread overview]
Message-ID: <20200623025106.31273-3-afaerber@suse.de> (raw)
In-Reply-To: <20200623025106.31273-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>
---
v1 -> v2:
* Added entry to MAINTAINERS
* Changed chip_id and chip_rev from u32 to u16, based on reg field definitions
* Added error return path for get_name for deferred probing, reordered code
MAINTAINERS | 1 +
drivers/soc/Kconfig | 1 +
drivers/soc/Makefile | 1 +
drivers/soc/realtek/Kconfig | 13 +++
drivers/soc/realtek/Makefile | 2 +
drivers/soc/realtek/chip.c | 181 +++++++++++++++++++++++++++++++++++
6 files changed, 199 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/MAINTAINERS b/MAINTAINERS
index 78adbc3cc101..ff0ee48fee6f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2311,6 +2311,7 @@ F: Documentation/devicetree/bindings/soc/realtek/
F: arch/arm/boot/dts/rtd*
F: arch/arm/mach-realtek/
F: arch/arm64/boot/dts/realtek/
+F: drivers/soc/realtek/
ARM/RENESAS ARM64 ARCHITECTURE
M: Geert Uytterhoeven <geert+renesas@glider.be>
diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index 425ab6f7e375..925647993119 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 36452bed86ef..cdcf00bbad10 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..c4650d512c91
--- /dev/null
+++ b/drivers/soc/realtek/chip.c
@@ -0,0 +1,181 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Realtek Digital Home Center System-on-Chip info
+ *
+ * Copyright (c) 2017-2020 Andreas Färber
+ */
+
+#include <linux/bitfield.h>
+#include <linux/io.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/sys_soc.h>
+
+#define REG_SB2_CHIP_ID 0x200
+#define REG_SB2_CHIP_INFO 0x204
+
+#define SB2_CHIP_ID_CHIP_ID GENMASK(15, 0)
+
+#define SB2_CHIP_INFO_REVISE_ID GENMASK(31, 16)
+
+struct dhc_soc_revision {
+ const char *name;
+ u16 chip_rev;
+};
+
+static const struct dhc_soc_revision rtd1195_revisions[] = {
+ { "A", 0x0000 },
+ { "B", 0x0001 },
+ { "C", 0x0002 },
+ { "D", 0x0003 },
+ { }
+};
+
+static const struct dhc_soc_revision rtd1295_revisions[] = {
+ { "A00", 0x0000 },
+ { "A01", 0x0001 },
+ { "B00", 0x0002 },
+ { "B01", 0x0003 },
+ { }
+};
+
+struct dhc_soc {
+ u16 chip_id;
+ const char *family;
+ const char *(*get_name)(struct device *dev, const struct dhc_soc *s);
+ const struct dhc_soc_revision *revisions;
+ const char *codename;
+};
+
+static const char *default_name(struct device *dev, const struct dhc_soc *s)
+{
+ return s->family;
+}
+
+static const struct dhc_soc dhc_soc_families[] = {
+ { 0x6329, "RTD1195", default_name, rtd1195_revisions, "Phoenix" },
+ { 0x6421, "RTD1295", default_name, rtd1295_revisions, "Kylin" },
+};
+
+static const struct dhc_soc *dhc_soc_by_chip_id(u16 chip_id)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(dhc_soc_families); i++) {
+ const struct dhc_soc *family = &dhc_soc_families[i];
+
+ if (family->chip_id == chip_id)
+ return family;
+ }
+ return NULL;
+}
+
+static const char *dhc_soc_rev(const struct dhc_soc *family, u16 chip_rev)
+{
+ if (family) {
+ const struct dhc_soc_revision *rev = family->revisions;
+
+ while (rev && rev->name) {
+ if (rev->chip_rev == chip_rev)
+ return rev->name;
+ rev++;
+ }
+ }
+ return "unknown";
+}
+
+static int dhc_soc_probe(struct platform_device *pdev)
+{
+ const struct dhc_soc *s;
+ struct soc_device_attribute *soc_dev_attr;
+ struct soc_device *soc_dev;
+ struct device_node *node;
+ struct regmap *regmap;
+ u16 chip_id, chip_rev;
+ unsigned int val;
+ int ret;
+
+ regmap = syscon_node_to_regmap(pdev->dev.of_node->parent);
+ if (IS_ERR(regmap))
+ return PTR_ERR(regmap);
+
+ ret = regmap_read(regmap, REG_SB2_CHIP_ID, &val);
+ if (ret)
+ return ret;
+ chip_id = FIELD_GET(SB2_CHIP_ID_CHIP_ID, val);
+
+ ret = regmap_read(regmap, REG_SB2_CHIP_INFO, &val);
+ if (ret)
+ return ret;
+ chip_rev = FIELD_GET(SB2_CHIP_INFO_REVISE_ID, val);
+
+ soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+ if (!soc_dev_attr)
+ return -ENOMEM;
+
+ node = of_find_node_by_path("/");
+ of_property_read_string(node, "model", &soc_dev_attr->machine);
+ of_node_put(node);
+
+ s = dhc_soc_by_chip_id(chip_id);
+
+ if (likely(s && s->get_name)) {
+ soc_dev_attr->soc_id = s->get_name(&pdev->dev, s);
+ if (IS_ERR(soc_dev_attr->soc_id))
+ return PTR_ERR(soc_dev_attr->soc_id);
+ } else
+ soc_dev_attr->soc_id = "unknown";
+
+ soc_dev_attr->revision = dhc_soc_rev(s, chip_rev);
+
+ soc_dev_attr->family = kasprintf(GFP_KERNEL, "Realtek %s",
+ (s && s->codename) ? s->codename :
+ ((s && s->family) ? s->family : "Digital Home Center"));
+
+ 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);
+
+ pr_info("%s %s (0x%04x) rev %s (0x%04x) detected\n",
+ soc_dev_attr->family, soc_dev_attr->soc_id, (u32)chip_id,
+ soc_dev_attr->revision, (u32)chip_rev);
+
+ return 0;
+}
+
+static int dhc_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 dhc_soc_dt_ids[] = {
+ { .compatible = "realtek,rtd1195-chip" },
+ { }
+};
+
+static struct platform_driver dhc_soc_driver = {
+ .probe = dhc_soc_probe,
+ .remove = dhc_soc_remove,
+ .driver = {
+ .name = "dhc-soc",
+ .of_match_table = dhc_soc_dt_ids,
+ },
+};
+module_platform_driver(dhc_soc_driver);
+
+MODULE_DESCRIPTION("Realtek DHC SoC identification driver");
+MODULE_LICENSE("GPL");
--
2.26.2
next prev parent reply other threads:[~2020-06-23 2:53 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-23 2:50 [PATCH v2 00/29] ARM: Realtek DHC SoC info Andreas Färber
2020-06-23 2:50 ` [PATCH v2 01/29] dt-bindings: soc: Add Realtek RTD1195 chip info binding Andreas Färber
2020-07-14 2:13 ` Rob Herring
2020-06-23 2:50 ` Andreas Färber [this message]
2020-07-10 7:55 ` [PATCH v2 02/29] soc: Add Realtek DHC chip info driver for RTD1195 and RTD1295 Stanley Chang[昌育德]
2020-06-23 2:50 ` [PATCH v2 03/29] arm64: dts: realtek: rtd129x: Add chip info node Andreas Färber
2020-07-10 7:56 ` Stanley Chang[昌育德]
2020-06-23 2:50 ` [PATCH v2 04/29] ARM: dts: rtd1195: " Andreas Färber
2020-07-10 7:57 ` Stanley Chang[昌育德]
2020-06-23 2:50 ` [PATCH v2 05/29] dt-bindings: soc: realtek: rtd1195-chip: Add iso-syscon property Andreas Färber
2020-07-14 2:13 ` Rob Herring
2020-06-23 2:50 ` [PATCH v2 06/29] soc: realtek: chip: Detect RTD1296 Andreas Färber
2020-07-10 7:58 ` Stanley Chang[昌育德]
2020-06-23 2:50 ` [PATCH v2 07/29] arm64: dts: realtek: rtd129x: Extend chip-info reg with CHIP_INFO1 Andreas Färber
2020-07-10 7:59 ` Stanley Chang[昌育德]
2020-06-23 2:50 ` [PATCH v2 08/29] soc: realtek: chip: Detect RTD1293 Andreas Färber
2020-06-23 2:50 ` [PATCH v2 09/29] soc: realtek: chip: Add RTD1395 info Andreas Färber
2020-07-10 8:01 ` Stanley Chang[昌育德]
2020-06-23 2:50 ` [PATCH v2 10/29] arm64: dts: realtek: rtd139x: Add chip info node Andreas Färber
2020-07-10 8:03 ` Stanley Chang[昌育德]
2020-06-23 2:50 ` [PATCH v2 11/29] soc: realtek: chip: Add RTD1619 info Andreas Färber
2020-07-10 8:02 ` Stanley Chang[昌育德]
2020-06-23 2:50 ` [PATCH v2 12/29] arm64: dts: realtek: rtd16xx: Add chip info node Andreas Färber
2020-07-10 8:02 ` Stanley Chang[昌育德]
2020-06-23 2:50 ` [PATCH v2 13/29] soc: realtek: chip: Add RTD1319 info Andreas Färber
2020-07-10 8:04 ` Stanley Chang[昌育德]
2020-06-23 2:50 ` [PATCH v2 14/29] soc: realtek: chip: Add RTD1319 revisions Andreas Färber
2020-07-10 8:04 ` Stanley Chang[昌育德]
2020-06-23 2:50 ` [PATCH v2 15/29] arm64: dts: realtek: rtd13xx: Add chip info node Andreas Färber
2020-07-10 8:06 ` Stanley Chang[昌育德]
2020-06-23 2:50 ` [PATCH v2 16/29] soc: realtek: chip: Detect RTD1392 Andreas Färber
2020-07-10 8:05 ` Stanley Chang[昌育德]
2020-06-23 2:50 ` [PATCH v2 17/29] dt-bindings: nvmem: Add Realtek RTD1195 eFuse Andreas Färber
2020-07-14 2:15 ` Rob Herring
2020-06-23 2:50 ` [PATCH v2 18/29] nvmem: Add Realtek DHC eFuse driver Andreas Färber
2020-06-23 9:32 ` Srinivas Kandagatla
2020-06-23 11:15 ` Andreas Färber
2020-07-20 9:31 ` Srinivas Kandagatla
2020-06-23 2:50 ` [PATCH v2 19/29] ARM: dts: rtd1195: Add eFuse node Andreas Färber
2020-06-23 2:50 ` [PATCH v2 20/29] arm64: dts: realtek: rtd129x: " Andreas Färber
2020-06-23 2:50 ` [PATCH v2 21/29] arm64: dts: realtek: rtd139x: " Andreas Färber
2020-06-23 2:50 ` [PATCH v2 22/29] arm64: dts: realtek: rtd16xx: " Andreas Färber
2020-06-23 2:51 ` [PATCH v2 23/29] arm64: dts: realtek: rtd13xx: " Andreas Färber
2020-06-23 2:51 ` [PATCH v2 24/29] dt-bindings: soc: realtek: rtd1195-chip: Allow nvmem-cells property Andreas Färber
2020-07-14 2:15 ` Rob Herring
2020-06-23 2:51 ` [PATCH v2 25/29] arm64: dts: realtek: rtd129x: Add eFuse package_id to chip-info Andreas Färber
2020-06-23 2:51 ` [PATCH v2 26/29] soc: realtek: chip: Detect RTD1294 Andreas Färber
2020-07-10 8:07 ` Stanley Chang[昌育德]
2020-06-23 2:51 ` [PATCH v2 27/29] nvmem: core: Grammar fixes for help text Andreas Färber
2020-06-23 9:30 ` Srinivas Kandagatla
2020-06-23 2:51 ` [PATCH v2 28/29] nvmem: core: Add nvmem_cell_read_u8() Andreas Färber
2020-06-23 9:30 ` Srinivas Kandagatla
2020-06-23 2:51 ` [PATCH v2 29/29] soc: realtek: chip: Adopt nvmem_cell_read_u8() helper 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=20200623025106.31273-3-afaerber@suse.de \
--to=afaerber@suse.de \
--cc=cylee12@realtek.com \
--cc=james.tai@realtek.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-realtek-soc@lists.infradead.org \
--cc=stanley_chang@realtek.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 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).