diff mbox

[v3,2/2] soc: Add driver for Freescale Vybrid Platform

Message ID d27c4ba234cd298914676884a9604ea8472a17d0.1432290463.git.maitysanchayan@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sanchayan May 22, 2015, 10:51 a.m. UTC
This adds a SoC driver to be used by the Freescale Vybrid SoC's.
We create the "fsl" directory for holding the different Freescale
designs. Driver utilises syscon to get the various register values
needed. After this sysfs exposes some SoC specific properties as
below:

> cd /sys/devices/soc0
> ls
family     machine    power      revision   soc_id     subsystem  uevent
> cat family
Freescale Vybrid VF610
> cat machine
Freescale Vybrid
> cat revision
00000013
> cat soc_id
df6472a60c1c39d4

Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
---
 drivers/soc/Kconfig         |   1 +
 drivers/soc/Makefile        |   1 +
 drivers/soc/fsl/Kconfig     |   9 ++++
 drivers/soc/fsl/Makefile    |   1 +
 drivers/soc/fsl/soc-vf610.c | 113 ++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 125 insertions(+)
 create mode 100644 drivers/soc/fsl/Kconfig
 create mode 100644 drivers/soc/fsl/Makefile
 create mode 100644 drivers/soc/fsl/soc-vf610.c

Comments

Arnd Bergmann May 22, 2015, 11:11 a.m. UTC | #1
On Friday 22 May 2015 16:21:54 Sanchayan Maity wrote:
> +#define OCOTP_CFG0_OFFSET      0x00000410
> +#define OCOTP_CFG1_OFFSET      0x00000420
> +#define MSCM_CPxCOUNT_OFFSET   0x0000002C
> +#define MSCM_CPxCFG1_OFFSET    0x00000014
> +#define ROM_REVISION_OFFSET    0x00000080
> +
> +static const struct of_device_id vf610_soc_bus_match[] = {
> +	{ .compatible = "fsl,vf610-mscm-cpucfg", },
> +	{ /* sentinel */ }
> +};
> +
> +static int __init vf610_soc_init(void)
> +{
> +	struct regmap *ocotp_regmap, *mscm_regmap, *rom_regmap;
> +	struct soc_device_attribute *soc_dev_attr;
> +	struct soc_device *soc_dev;
> +	struct device_node *np;
> +	char soc_type[] = "xx0";
> +	u32 cpxcount, cpxcfg1;
> +	u32 soc_id1, soc_id2, rom_rev;
> +	u64 soc_id;
> +	int ret;
> +
> +	np = of_find_matching_node(NULL, vf610_soc_bus_match);
> +	if (!np)
> +		return -ENODEV;
> +

Why not use module_platform_driver() and make this a probe function instead?

> +	ocotp_regmap = syscon_regmap_lookup_by_compatible("fsl,vf610-ocotp");
> +	if (IS_ERR(ocotp_regmap)) {
> +		pr_err("regmap lookup for octop failed\n");
> +		return PTR_ERR(ocotp_regmap);
> +	}
> +
> +	mscm_regmap = syscon_regmap_lookup_by_compatible("fsl,vf610-mscm-cpucfg");
> +	if (IS_ERR(mscm_regmap)) {
> +		pr_err("regmap lookup for mscm failed");
> +		return PTR_ERR(mscm_regmap);
> +	}
> +
> +	rom_regmap = syscon_regmap_lookup_by_compatible("fsl,vf610-ocrom");
> +	if (IS_ERR(rom_regmap)) {
> +		pr_err("regmap lookup for ocrom failed");
> +		return PTR_ERR(rom_regmap);
> +	}

Can you use syscon_regmap_lookup_by_phandle instead, and put the
phandles in the fsl,vf610-mscm-cpucfg node?

Also, I'd argue that the mscm should not be a syscon device at all,
but instead I'd use platform_get_resource()/devm_ioremap_resource()
to get an __iomem pointer.

	Arnd
Sanchayan May 22, 2015, 11:55 a.m. UTC | #2
Hello Arnd,

On 15-05-22 13:11:46, Arnd Bergmann wrote:
> On Friday 22 May 2015 16:21:54 Sanchayan Maity wrote:
> > +#define OCOTP_CFG0_OFFSET      0x00000410
> > +#define OCOTP_CFG1_OFFSET      0x00000420
> > +#define MSCM_CPxCOUNT_OFFSET   0x0000002C
> > +#define MSCM_CPxCFG1_OFFSET    0x00000014
> > +#define ROM_REVISION_OFFSET    0x00000080
> > +
> > +static const struct of_device_id vf610_soc_bus_match[] = {
> > +	{ .compatible = "fsl,vf610-mscm-cpucfg", },
> > +	{ /* sentinel */ }
> > +};
> > +
> > +static int __init vf610_soc_init(void)
> > +{
> > +	struct regmap *ocotp_regmap, *mscm_regmap, *rom_regmap;
> > +	struct soc_device_attribute *soc_dev_attr;
> > +	struct soc_device *soc_dev;
> > +	struct device_node *np;
> > +	char soc_type[] = "xx0";
> > +	u32 cpxcount, cpxcfg1;
> > +	u32 soc_id1, soc_id2, rom_rev;
> > +	u64 soc_id;
> > +	int ret;
> > +
> > +	np = of_find_matching_node(NULL, vf610_soc_bus_match);
> > +	if (!np)
> > +		return -ENODEV;
> > +
> 
> Why not use module_platform_driver() and make this a probe function instead?

Had done that but after having a look at the existing integrator and versatile
platform implementation, I changed it. Will switch to using that.

> 
> > +	ocotp_regmap = syscon_regmap_lookup_by_compatible("fsl,vf610-ocotp");
> > +	if (IS_ERR(ocotp_regmap)) {
> > +		pr_err("regmap lookup for octop failed\n");
> > +		return PTR_ERR(ocotp_regmap);
> > +	}
> > +
> > +	mscm_regmap = syscon_regmap_lookup_by_compatible("fsl,vf610-mscm-cpucfg");
> > +	if (IS_ERR(mscm_regmap)) {
> > +		pr_err("regmap lookup for mscm failed");
> > +		return PTR_ERR(mscm_regmap);
> > +	}
> > +
> > +	rom_regmap = syscon_regmap_lookup_by_compatible("fsl,vf610-ocrom");
> > +	if (IS_ERR(rom_regmap)) {
> > +		pr_err("regmap lookup for ocrom failed");
> > +		return PTR_ERR(rom_regmap);
> > +	}
> 
> Can you use syscon_regmap_lookup_by_phandle instead, and put the
> phandles in the fsl,vf610-mscm-cpucfg node?

Ok. Will do so.

- Sanchayan.

> 
> Also, I'd argue that the mscm should not be a syscon device at all,
> but instead I'd use platform_get_resource()/devm_ioremap_resource()
> to get an __iomem pointer.
> 
> 	Arnd
Stefan Agner May 22, 2015, 12:02 p.m. UTC | #3
On 2015-05-22 13:11, Arnd Bergmann wrote:
> On Friday 22 May 2015 16:21:54 Sanchayan Maity wrote:
>> +#define OCOTP_CFG0_OFFSET      0x00000410
>> +#define OCOTP_CFG1_OFFSET      0x00000420
>> +#define MSCM_CPxCOUNT_OFFSET   0x0000002C
>> +#define MSCM_CPxCFG1_OFFSET    0x00000014
>> +#define ROM_REVISION_OFFSET    0x00000080
>> +
>> +static const struct of_device_id vf610_soc_bus_match[] = {
>> +	{ .compatible = "fsl,vf610-mscm-cpucfg", },
>> +	{ /* sentinel */ }
>> +};
>> +
>> +static int __init vf610_soc_init(void)
>> +{
>> +	struct regmap *ocotp_regmap, *mscm_regmap, *rom_regmap;
>> +	struct soc_device_attribute *soc_dev_attr;
>> +	struct soc_device *soc_dev;
>> +	struct device_node *np;
>> +	char soc_type[] = "xx0";
>> +	u32 cpxcount, cpxcfg1;
>> +	u32 soc_id1, soc_id2, rom_rev;
>> +	u64 soc_id;
>> +	int ret;
>> +
>> +	np = of_find_matching_node(NULL, vf610_soc_bus_match);
>> +	if (!np)
>> +		return -ENODEV;
>> +
> 
> Why not use module_platform_driver() and make this a probe function instead?
> 
>> +	ocotp_regmap = syscon_regmap_lookup_by_compatible("fsl,vf610-ocotp");
>> +	if (IS_ERR(ocotp_regmap)) {
>> +		pr_err("regmap lookup for octop failed\n");
>> +		return PTR_ERR(ocotp_regmap);
>> +	}
>> +
>> +	mscm_regmap = syscon_regmap_lookup_by_compatible("fsl,vf610-mscm-cpucfg");
>> +	if (IS_ERR(mscm_regmap)) {
>> +		pr_err("regmap lookup for mscm failed");
>> +		return PTR_ERR(mscm_regmap);
>> +	}
>> +
>> +	rom_regmap = syscon_regmap_lookup_by_compatible("fsl,vf610-ocrom");
>> +	if (IS_ERR(rom_regmap)) {
>> +		pr_err("regmap lookup for ocrom failed");
>> +		return PTR_ERR(rom_regmap);
>> +	}
> 
> Can you use syscon_regmap_lookup_by_phandle instead, and put the
> phandles in the fsl,vf610-mscm-cpucfg node?

Hm, with that we would wire up hardware modules which does nothing has
to do with each other. We just happen to need a driver which collects
information accross the SoC. I'm not sure we should put the modules
required into the device tree.

I don't think its nice to have the compatible strings in the source
code, however it feels more appropriate than in the device tree, IMHO...

> Also, I'd argue that the mscm should not be a syscon device at all,
> but instead I'd use platform_get_resource()/devm_ioremap_resource()
> to get an __iomem pointer.

We need to have mscm-cpucfg to be syscon because we need to get the CPU
personality in the MSCM interrupt router driver (irq-vf610-mscm-ir.c). 

--
Stefan
Arnd Bergmann May 22, 2015, 1:20 p.m. UTC | #4
On Friday 22 May 2015 14:02:52 Stefan Agner wrote:
> > Can you use syscon_regmap_lookup_by_phandle instead, and put the
> > phandles in the fsl,vf610-mscm-cpucfg node?
> 
> Hm, with that we would wire up hardware modules which does nothing has
> to do with each other. We just happen to need a driver which collects
> information accross the SoC. I'm not sure we should put the modules
> required into the device tree.
> 
> I don't think its nice to have the compatible strings in the source
> code, however it feels more appropriate than in the device tree, IMHO...

I see. Another option would be to point directly to the registers
you need:

	ocotp-cfg0 = <&ocotp 0x10>;
	ocotp-cfg1 = <&ocotp 0x20>;
	rom-revision = <&rom 0x80>;

We don't yet have an abstraction to access a register from a syscon
reference like this, but you could either roll your own here, or 
add a generic abstraction.

> > Also, I'd argue that the mscm should not be a syscon device at all,
> > but instead I'd use platform_get_resource()/devm_ioremap_resource()
> > to get an __iomem pointer.
> 
> We need to have mscm-cpucfg to be syscon because we need to get the CPU
> personality in the MSCM interrupt router driver (irq-vf610-mscm-ir.c). 

It can be both at the same time now.

	Arnd
Sanchayan May 25, 2015, 10:17 a.m. UTC | #5
Hello Arnd,

On 15-05-22 15:20:00, Arnd Bergmann wrote:
> On Friday 22 May 2015 14:02:52 Stefan Agner wrote:
> > > Can you use syscon_regmap_lookup_by_phandle instead, and put the
> > > phandles in the fsl,vf610-mscm-cpucfg node?
> > 
> > Hm, with that we would wire up hardware modules which does nothing has
> > to do with each other. We just happen to need a driver which collects
> > information accross the SoC. I'm not sure we should put the modules
> > required into the device tree.
> > 
> > I don't think its nice to have the compatible strings in the source
> > code, however it feels more appropriate than in the device tree, IMHO...
> 
> I see. Another option would be to point directly to the registers
> you need:
> 
> 	ocotp-cfg0 = <&ocotp 0x10>;
> 	ocotp-cfg1 = <&ocotp 0x20>;
> 	rom-revision = <&rom 0x80>;
> 
> We don't yet have an abstraction to access a register from a syscon
> reference like this, but you could either roll your own here, or 
> add a generic abstraction.

Can you tell me a little about how can I start implementing it? I am not
clear on how to approach this.

> 
> > > Also, I'd argue that the mscm should not be a syscon device at all,
> > > but instead I'd use platform_get_resource()/devm_ioremap_resource()
> > > to get an __iomem pointer.
> > 
> > We need to have mscm-cpucfg to be syscon because we need to get the CPU
> > personality in the MSCM interrupt router driver (irq-vf610-mscm-ir.c). 
> 
> It can be both at the same time now.
> 
> 	Arnd

Regards,
Sanchayan.
diff mbox

Patch

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index d8bde82..8b4dd2b 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -1,5 +1,6 @@ 
 menu "SOC (System On Chip) specific Drivers"
 
+source "drivers/soc/fsl/Kconfig"
 source "drivers/soc/mediatek/Kconfig"
 source "drivers/soc/qcom/Kconfig"
 source "drivers/soc/ti/Kconfig"
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 70042b2..142676e 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -2,6 +2,7 @@ 
 # Makefile for the Linux Kernel SOC specific device drivers.
 #
 
+obj-$(CONFIG_SOC_VF610)         += fsl/
 obj-$(CONFIG_ARCH_MEDIATEK)	+= mediatek/
 obj-$(CONFIG_ARCH_QCOM)		+= qcom/
 obj-$(CONFIG_ARCH_TEGRA)	+= tegra/
diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig
new file mode 100644
index 0000000..d0ac671
--- /dev/null
+++ b/drivers/soc/fsl/Kconfig
@@ -0,0 +1,9 @@ 
+#
+# Freescale SoC drivers
+
+config SOC_VF610
+	   bool "SoC bus device for the Freescale Vybrid platform"
+	   select SOC_BUS
+	   help
+	     Include support for the SoC bus on the Freescale Vybrid platform
+		 providing some sysfs information about the module variant.
\ No newline at end of file
diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile
new file mode 100644
index 0000000..5fccbba
--- /dev/null
+++ b/drivers/soc/fsl/Makefile
@@ -0,0 +1 @@ 
+obj-$(CONFIG_SOC_VF610)		+= soc-vf610.o
diff --git a/drivers/soc/fsl/soc-vf610.c b/drivers/soc/fsl/soc-vf610.c
new file mode 100644
index 0000000..faeb567
--- /dev/null
+++ b/drivers/soc/fsl/soc-vf610.c
@@ -0,0 +1,113 @@ 
+/*
+ * Copyright 2015 Toradex AG
+ *
+ * Author: Sanchayan Maity <sanchayan.maity@toradex.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2, as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/regmap.h>
+#include <linux/random.h>
+#include <linux/slab.h>
+#include <linux/sys_soc.h>
+
+#define OCOTP_CFG0_OFFSET      0x00000410
+#define OCOTP_CFG1_OFFSET      0x00000420
+#define MSCM_CPxCOUNT_OFFSET   0x0000002C
+#define MSCM_CPxCFG1_OFFSET    0x00000014
+#define ROM_REVISION_OFFSET    0x00000080
+
+static const struct of_device_id vf610_soc_bus_match[] = {
+	{ .compatible = "fsl,vf610-mscm-cpucfg", },
+	{ /* sentinel */ }
+};
+
+static int __init vf610_soc_init(void)
+{
+	struct regmap *ocotp_regmap, *mscm_regmap, *rom_regmap;
+	struct soc_device_attribute *soc_dev_attr;
+	struct soc_device *soc_dev;
+	struct device_node *np;
+	char soc_type[] = "xx0";
+	u32 cpxcount, cpxcfg1;
+	u32 soc_id1, soc_id2, rom_rev;
+	u64 soc_id;
+	int ret;
+
+	np = of_find_matching_node(NULL, vf610_soc_bus_match);
+	if (!np)
+		return -ENODEV;
+
+	ocotp_regmap = syscon_regmap_lookup_by_compatible("fsl,vf610-ocotp");
+	if (IS_ERR(ocotp_regmap)) {
+		pr_err("regmap lookup for octop failed\n");
+		return PTR_ERR(ocotp_regmap);
+	}
+
+	mscm_regmap = syscon_regmap_lookup_by_compatible("fsl,vf610-mscm-cpucfg");
+	if (IS_ERR(mscm_regmap)) {
+		pr_err("regmap lookup for mscm failed");
+		return PTR_ERR(mscm_regmap);
+	}
+
+	rom_regmap = syscon_regmap_lookup_by_compatible("fsl,vf610-ocrom");
+	if (IS_ERR(rom_regmap)) {
+		pr_err("regmap lookup for ocrom failed");
+		return PTR_ERR(rom_regmap);
+	}
+
+	ret = regmap_read(ocotp_regmap, OCOTP_CFG0_OFFSET, &soc_id1);
+	if (ret)
+		return -ENODEV;
+
+	ret = regmap_read(ocotp_regmap, OCOTP_CFG1_OFFSET, &soc_id2);
+	if (ret)
+		return -ENODEV;
+
+	soc_id = (u64) soc_id1 << 32 | soc_id2;
+	add_device_randomness(&soc_id, sizeof(soc_id));
+
+	ret = regmap_read(mscm_regmap, MSCM_CPxCOUNT_OFFSET, &cpxcount);
+	if (ret)
+		return -ENODEV;
+
+	ret = regmap_read(mscm_regmap, MSCM_CPxCFG1_OFFSET, &cpxcfg1);
+	if (ret)
+		return -ENODEV;
+
+	soc_type[0] = cpxcount ? '6' : '5'; /* Dual Core => VF6x0 */
+	soc_type[1] = cpxcfg1 ? '1' : '0'; /* L2 Cache => VFx10 */
+
+	ret = regmap_read(rom_regmap, ROM_REVISION_OFFSET, &rom_rev);
+	if (ret)
+		return -ENODEV;
+
+	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+	if (!soc_dev_attr)
+		return -ENOMEM;
+
+	soc_dev_attr->machine = kasprintf(GFP_KERNEL, "Freescale Vybrid");
+	soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%016llx", soc_id);
+	soc_dev_attr->family = kasprintf(GFP_KERNEL, "Freescale Vybrid VF%s",
+								 soc_type);
+	soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%08x", rom_rev);
+
+	soc_dev = soc_device_register(soc_dev_attr);
+	if (IS_ERR(soc_dev)) {
+		kfree(soc_dev_attr->revision);
+		kfree(soc_dev_attr->family);
+		kfree(soc_dev_attr->soc_id);
+		kfree(soc_dev_attr->machine);
+		kfree(soc_dev_attr);
+		return -ENODEV;
+	}
+
+	return 0;
+}
+device_initcall(vf610_soc_init);