linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Mylène Josserand" <mylene.josserand@collabora.com>
To: heiko@sntech.de, linux-arm-kernel@lists.infradead.org,
	mturquette@baylibre.com, sboyd@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org,
	linux-clk@vger.kernel.org, mylene.josserand@collabora.com,
	kernel@collabora.com, kever.yang@rock-chips.com,
	geert@linux-m68k.org
Subject: [PATCH v2 1/2] soc: rockchip: Register a soc_device to retrieve revision
Date: Wed,  1 Apr 2020 17:35:12 +0200	[thread overview]
Message-ID: <20200401153513.423683-2-mylene.josserand@collabora.com> (raw)
In-Reply-To: <20200401153513.423683-1-mylene.josserand@collabora.com>

Determine which revision of rk3288 by checking the HDMI version.
According to the Rockchip BSP kernel/u-boot, on rk3288w, the HDMI
revision equals 0x1A which is not the case for the rk3288.

As these SOC have some differences, this driver will help us
to know on which revision we are by using 'soc_device' registration
to be able to use 'soc_device_match' to detect rk3288/rk3288w.

Signed-off-by: Mylène Josserand <mylene.josserand@collabora.com>
---
 drivers/soc/rockchip/Makefile |   1 +
 drivers/soc/rockchip/rk3288.c | 125 ++++++++++++++++++++++++++++++++++
 2 files changed, 126 insertions(+)
 create mode 100644 drivers/soc/rockchip/rk3288.c

diff --git a/drivers/soc/rockchip/Makefile b/drivers/soc/rockchip/Makefile
index afca0a4c4b72..9dbf12913512 100644
--- a/drivers/soc/rockchip/Makefile
+++ b/drivers/soc/rockchip/Makefile
@@ -2,5 +2,6 @@
 #
 # Rockchip Soc drivers
 #
+obj-$(CONFIG_ARCH_ROCKCHIP) += rk3288.o
 obj-$(CONFIG_ROCKCHIP_GRF) += grf.o
 obj-$(CONFIG_ROCKCHIP_PM_DOMAINS) += pm_domains.o
diff --git a/drivers/soc/rockchip/rk3288.c b/drivers/soc/rockchip/rk3288.c
new file mode 100644
index 000000000000..83379ba2b31b
--- /dev/null
+++ b/drivers/soc/rockchip/rk3288.c
@@ -0,0 +1,125 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2020 Collabora Ltd
+ * Author: Mylene Josserand <mylene.josserand@collabora.com>
+ */
+
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/of_address.h>
+#include <linux/sys_soc.h>
+#include <linux/slab.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
+
+#define RK3288_HDMI_REV_REG	0x04
+#define RK3288W_HDMI_REV	0x1A
+
+enum rk3288_soc_rev {
+	RK3288_SOC_REV_NOT_DETECT,
+	RK3288_SOC_REV_RK3288,
+	RK3288_SOC_REV_RK3288W,
+};
+
+static int rk3288_revision(void)
+{
+	static int revision = RK3288_SOC_REV_NOT_DETECT;
+	struct device_node *dn;
+	void __iomem *hdmi_base;
+
+	if (revision != RK3288_SOC_REV_NOT_DETECT)
+		return revision;
+
+	dn = of_find_compatible_node(NULL, NULL, "rockchip,rk3288-dw-hdmi");
+	if (!dn) {
+		pr_err("%s: Couldn't find HDMI node\n", __func__);
+		return -EINVAL;
+	}
+
+	hdmi_base = of_iomap(dn, 0);
+	of_node_put(dn);
+
+	if (!hdmi_base) {
+		pr_err("%s: Couldn't map %pOF regs\n", __func__,
+		       hdmi_base);
+		return -ENXIO;
+	}
+
+	if (readl_relaxed(hdmi_base + RK3288_HDMI_REV_REG)
+	    == RK3288W_HDMI_REV)
+		revision = RK3288_SOC_REV_RK3288W;
+	else
+		revision = RK3288_SOC_REV_RK3288;
+
+	iounmap(hdmi_base);
+
+	return revision;
+}
+
+static const char *rk3288_socinfo_revision(u32 rev)
+{
+	const char *soc_rev;
+
+	switch (rev) {
+	case RK3288_SOC_REV_RK3288:
+		soc_rev = "RK3288";
+		break;
+
+	case RK3288_SOC_REV_RK3288W:
+		soc_rev = "RK3288w";
+		break;
+
+	case RK3288_SOC_REV_NOT_DETECT:
+		soc_rev = "";
+		break;
+
+	default:
+		soc_rev = "unknown";
+		break;
+	}
+
+	return kstrdup_const(soc_rev, GFP_KERNEL);
+}
+
+static const struct of_device_id rk3288_soc_match[] = {
+	{ .compatible = "rockchip,rk3288", },
+	{ }
+};
+
+static int __init rk3288_soc_init(void)
+{
+	struct soc_device_attribute *soc_dev_attr;
+	struct soc_device *soc_dev;
+	struct device_node *np;
+
+	np = of_find_matching_node(NULL, rk3288_soc_match);
+	if (!np)
+		return -ENODEV;
+
+	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+	if (!soc_dev_attr)
+		return -ENOMEM;
+
+	soc_dev_attr->family = "Rockchip";
+	soc_dev_attr->soc_id = "RK32xx";
+
+	np = of_find_node_by_path("/");
+	of_property_read_string(np, "model", &soc_dev_attr->machine);
+	of_node_put(np);
+
+	soc_dev_attr->revision = rk3288_socinfo_revision(rk3288_revision());
+
+	soc_dev = soc_device_register(soc_dev_attr);
+	if (IS_ERR(soc_dev)) {
+		kfree_const(soc_dev_attr->revision);
+		kfree_const(soc_dev_attr->soc_id);
+		kfree(soc_dev_attr);
+		return PTR_ERR(soc_dev);
+	}
+
+	dev_info(soc_device_to_device(soc_dev), "Rockchip %s %s detected\n",
+		 soc_dev_attr->soc_id, soc_dev_attr->revision);
+
+	return 0;
+}
+postcore_initcall(rk3288_soc_init);
-- 
2.25.1


  reply	other threads:[~2020-04-01 15:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-01 15:35 [PATCH v2 0/2] ARM: Add Rockchip rk3288w support Mylène Josserand
2020-04-01 15:35 ` Mylène Josserand [this message]
2020-04-01 16:34   ` [PATCH v2 1/2] soc: rockchip: Register a soc_device to retrieve revision Heiko Stübner
2020-04-02  6:31     ` Mylene Josserand
2020-04-02 11:45     ` Robin Murphy
2020-04-02 14:14       ` Heiko Stübner
2020-04-01 15:35 ` [PATCH v2 2/2] clk: rockchip: rk3288: Handle clock tree for rk3288w Mylène Josserand
2020-04-01 16:56   ` Geert Uytterhoeven
2020-04-02  6:35     ` Mylene Josserand

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=20200401153513.423683-2-mylene.josserand@collabora.com \
    --to=mylene.josserand@collabora.com \
    --cc=geert@linux-m68k.org \
    --cc=heiko@sntech.de \
    --cc=kernel@collabora.com \
    --cc=kever.yang@rock-chips.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@kernel.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).