All of lore.kernel.org
 help / color / mirror / Atom feed
From: Justin Chen <justinpopo6@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: f.fainelli@gmail.com, rjui@broadcom.com, sbranden@broadcom.com,
	computersforpeace@gmail.com, gregory.0xf0@gmail.com,
	bcm-kernel-feedback-list@broadcom.com,
	linux-arm-kernel@lists.infradead.org,
	Justin Chen <justin.chen@broadcom.com>
Subject: [PATCH] bsp: add SoC device to brcmstb
Date: Thu, 25 Feb 2016 16:19:07 -0800	[thread overview]
Message-ID: <1456445947-9079-1-git-send-email-justinpopo6@gmail.com> (raw)

From: Justin Chen <justin.chen@broadcom.com>

Added SoC driver at drivers/soc/brcmstb/common.c. Added two
helper functions for getting family/product ID located at
include/linux/soc/brcmstb/brcmstb.h.

Assigned the values of soc_dev_attribute accordingly:
family = chip family id
soc_id = product id
revision = product revision

Signed-off-by: Justin Chen <justin.chen@broadcom.com>
---
 arch/arm/mach-bcm/Kconfig           |    1 +
 drivers/soc/brcmstb/common.c        |   68 +++++++++++++++++++++++++++++++++++
 include/linux/soc/brcmstb/brcmstb.h |    7 ++++
 3 files changed, 76 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-bcm/Kconfig b/arch/arm/mach-bcm/Kconfig
index 7ef1214..b95ea11 100644
--- a/arch/arm/mach-bcm/Kconfig
+++ b/arch/arm/mach-bcm/Kconfig
@@ -179,6 +179,7 @@ config ARCH_BRCMSTB
 	select ARCH_DMA_ADDR_T_64BIT if ARM_LPAE
 	select ARCH_WANT_OPTIONAL_GPIOLIB
 	select SOC_BRCMSTB
+	select SOC_BUS
 	help
 	  Say Y if you intend to run the kernel on a Broadcom ARM-based STB
 	  chipset.
diff --git a/drivers/soc/brcmstb/common.c b/drivers/soc/brcmstb/common.c
index c262c02..dd8cb42 100644
--- a/drivers/soc/brcmstb/common.c
+++ b/drivers/soc/brcmstb/common.c
@@ -12,10 +12,18 @@
  * GNU General Public License for more details.
  */
 
+#include <linux/io.h>
 #include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/slab.h>
+#include <linux/soc/brcmstb/brcmstb.h>
+#include <linux/sys_soc.h>
 
 #include <soc/brcmstb/common.h>
 
+static u32 family_id;
+static u32 product_id;
+
 static const struct of_device_id brcmstb_machine_match[] = {
 	{ .compatible = "brcm,brcmstb", },
 	{ }
@@ -31,3 +39,63 @@ bool soc_is_brcmstb(void)
 
 	return of_match_node(brcmstb_machine_match, root) != NULL;
 }
+
+u32 brcmstb_get_family_id(void)
+{
+	return family_id;
+}
+
+u32 brcmstb_get_product_id(void)
+{
+	return product_id;
+}
+
+static const struct of_device_id sun_top_ctrl_match[] = {
+	{ .compatible = "brcm,brcmstb-sun-top-ctrl", },
+	{ }
+};
+
+static int __init brcmstb_soc_device_init(void)
+{
+	struct soc_device_attribute *soc_dev_attr;
+	struct soc_device *soc_dev;
+	struct device_node *sun_top_ctrl;
+	void __iomem *sun_top_ctrl_base;
+
+	sun_top_ctrl = of_find_matching_node(NULL, sun_top_ctrl_match);
+	if (!sun_top_ctrl)
+		return -ENODEV;
+
+	sun_top_ctrl_base = of_iomap(sun_top_ctrl, 0);
+	if (!sun_top_ctrl_base)
+		return -ENODEV;
+
+	family_id = readl(sun_top_ctrl_base);
+	product_id = readl(sun_top_ctrl_base + 0x4);
+
+	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+	if (!soc_dev_attr)
+		return -ENOMEM;
+
+	soc_dev_attr->family = kasprintf(GFP_KERNEL, "%x",
+					family_id >> 28 ?
+					family_id >> 16 : family_id >> 8);
+	soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%x",
+					product_id >> 28 ?
+					product_id >> 16 : product_id >> 8);
+	soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%c%d",
+				    (char)(((product_id & 0xff) >> 4) + 65),
+				     product_id & 0xf);
+
+	soc_dev = soc_device_register(soc_dev_attr);
+	if (IS_ERR(soc_dev)) {
+		kfree(soc_dev_attr->family);
+		kfree(soc_dev_attr->soc_id);
+		kfree(soc_dev_attr->revision);
+		kfree(soc_dev_attr);
+		return -1;
+	}
+
+	return 0;
+}
+arch_initcall(brcmstb_soc_device_init);
diff --git a/include/linux/soc/brcmstb/brcmstb.h b/include/linux/soc/brcmstb/brcmstb.h
index 337ce41..ac10b0c 100644
--- a/include/linux/soc/brcmstb/brcmstb.h
+++ b/include/linux/soc/brcmstb/brcmstb.h
@@ -7,4 +7,11 @@
  */
 void brcmstb_biuctrl_init(void);
 
+/*
+ * Helper functions for getting family or product id from the
+ * SoC driver.
+ */
+u32 brcmstb_get_family_id(void);
+u32 brcmstb_get_product_id(void);
+
 #endif /* __BRCMSTB_SOC_H */
-- 
1.7.1

WARNING: multiple messages have this Message-ID (diff)
From: justinpopo6@gmail.com (Justin Chen)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] bsp: add SoC device to brcmstb
Date: Thu, 25 Feb 2016 16:19:07 -0800	[thread overview]
Message-ID: <1456445947-9079-1-git-send-email-justinpopo6@gmail.com> (raw)

From: Justin Chen <justin.chen@broadcom.com>

Added SoC driver at drivers/soc/brcmstb/common.c. Added two
helper functions for getting family/product ID located at
include/linux/soc/brcmstb/brcmstb.h.

Assigned the values of soc_dev_attribute accordingly:
family = chip family id
soc_id = product id
revision = product revision

Signed-off-by: Justin Chen <justin.chen@broadcom.com>
---
 arch/arm/mach-bcm/Kconfig           |    1 +
 drivers/soc/brcmstb/common.c        |   68 +++++++++++++++++++++++++++++++++++
 include/linux/soc/brcmstb/brcmstb.h |    7 ++++
 3 files changed, 76 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-bcm/Kconfig b/arch/arm/mach-bcm/Kconfig
index 7ef1214..b95ea11 100644
--- a/arch/arm/mach-bcm/Kconfig
+++ b/arch/arm/mach-bcm/Kconfig
@@ -179,6 +179,7 @@ config ARCH_BRCMSTB
 	select ARCH_DMA_ADDR_T_64BIT if ARM_LPAE
 	select ARCH_WANT_OPTIONAL_GPIOLIB
 	select SOC_BRCMSTB
+	select SOC_BUS
 	help
 	  Say Y if you intend to run the kernel on a Broadcom ARM-based STB
 	  chipset.
diff --git a/drivers/soc/brcmstb/common.c b/drivers/soc/brcmstb/common.c
index c262c02..dd8cb42 100644
--- a/drivers/soc/brcmstb/common.c
+++ b/drivers/soc/brcmstb/common.c
@@ -12,10 +12,18 @@
  * GNU General Public License for more details.
  */
 
+#include <linux/io.h>
 #include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/slab.h>
+#include <linux/soc/brcmstb/brcmstb.h>
+#include <linux/sys_soc.h>
 
 #include <soc/brcmstb/common.h>
 
+static u32 family_id;
+static u32 product_id;
+
 static const struct of_device_id brcmstb_machine_match[] = {
 	{ .compatible = "brcm,brcmstb", },
 	{ }
@@ -31,3 +39,63 @@ bool soc_is_brcmstb(void)
 
 	return of_match_node(brcmstb_machine_match, root) != NULL;
 }
+
+u32 brcmstb_get_family_id(void)
+{
+	return family_id;
+}
+
+u32 brcmstb_get_product_id(void)
+{
+	return product_id;
+}
+
+static const struct of_device_id sun_top_ctrl_match[] = {
+	{ .compatible = "brcm,brcmstb-sun-top-ctrl", },
+	{ }
+};
+
+static int __init brcmstb_soc_device_init(void)
+{
+	struct soc_device_attribute *soc_dev_attr;
+	struct soc_device *soc_dev;
+	struct device_node *sun_top_ctrl;
+	void __iomem *sun_top_ctrl_base;
+
+	sun_top_ctrl = of_find_matching_node(NULL, sun_top_ctrl_match);
+	if (!sun_top_ctrl)
+		return -ENODEV;
+
+	sun_top_ctrl_base = of_iomap(sun_top_ctrl, 0);
+	if (!sun_top_ctrl_base)
+		return -ENODEV;
+
+	family_id = readl(sun_top_ctrl_base);
+	product_id = readl(sun_top_ctrl_base + 0x4);
+
+	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+	if (!soc_dev_attr)
+		return -ENOMEM;
+
+	soc_dev_attr->family = kasprintf(GFP_KERNEL, "%x",
+					family_id >> 28 ?
+					family_id >> 16 : family_id >> 8);
+	soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%x",
+					product_id >> 28 ?
+					product_id >> 16 : product_id >> 8);
+	soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%c%d",
+				    (char)(((product_id & 0xff) >> 4) + 65),
+				     product_id & 0xf);
+
+	soc_dev = soc_device_register(soc_dev_attr);
+	if (IS_ERR(soc_dev)) {
+		kfree(soc_dev_attr->family);
+		kfree(soc_dev_attr->soc_id);
+		kfree(soc_dev_attr->revision);
+		kfree(soc_dev_attr);
+		return -1;
+	}
+
+	return 0;
+}
+arch_initcall(brcmstb_soc_device_init);
diff --git a/include/linux/soc/brcmstb/brcmstb.h b/include/linux/soc/brcmstb/brcmstb.h
index 337ce41..ac10b0c 100644
--- a/include/linux/soc/brcmstb/brcmstb.h
+++ b/include/linux/soc/brcmstb/brcmstb.h
@@ -7,4 +7,11 @@
  */
 void brcmstb_biuctrl_init(void);
 
+/*
+ * Helper functions for getting family or product id from the
+ * SoC driver.
+ */
+u32 brcmstb_get_family_id(void);
+u32 brcmstb_get_product_id(void);
+
 #endif /* __BRCMSTB_SOC_H */
-- 
1.7.1

             reply	other threads:[~2016-02-26  0:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-26  0:19 Justin Chen [this message]
2016-02-26  0:19 ` [PATCH] bsp: add SoC device to brcmstb Justin Chen
2016-02-26 13:58 ` Arnd Bergmann
2016-02-26 13:58   ` Arnd Bergmann
2016-02-26 18:36   ` Florian Fainelli
2016-02-26 18:36     ` Florian Fainelli
2016-02-26 20:32     ` Arnd Bergmann
2016-02-26 20:32       ` Arnd Bergmann

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=1456445947-9079-1-git-send-email-justinpopo6@gmail.com \
    --to=justinpopo6@gmail.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=computersforpeace@gmail.com \
    --cc=f.fainelli@gmail.com \
    --cc=gregory.0xf0@gmail.com \
    --cc=justin.chen@broadcom.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rjui@broadcom.com \
    --cc=sbranden@broadcom.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.