linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/2] Implement SoC bus support for Vybrid
@ 2015-05-26 11:36 Sanchayan Maity
  2015-05-26 11:36 ` [PATCH v4 1/2] ARM: dts: vfxxx: Add OCOTP and OCROM nodes Sanchayan Maity
  2015-05-26 11:36 ` [PATCH v4 2/2] soc: Add driver for Freescale Vybrid Platform Sanchayan Maity
  0 siblings, 2 replies; 9+ messages in thread
From: Sanchayan Maity @ 2015-05-26 11:36 UTC (permalink / raw)
  To: arnd, shawn.guo, kernel
  Cc: stefan, linux-arm-kernel, devicetree, linux-kernel, Sanchayan Maity

Hello,

This patchset implements SoC bus support for Freescale Vybrid platform,
implementing the following
https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-devices-soc
and is the third revision.

Version 3 of the patchset can be found here
http://www.spinics.net/lists/arm-kernel/msg420847.html

Version 2 of the patchset can be found here
http://www.spinics.net/lists/devicetree/msg80654.html

Version 1 of the patchset can be found here
http://www.spinics.net/lists/devicetree/msg80257.html

The RFC version can be found here
https://lkml.org/lkml/2015/5/11/13

Changes since v3:
- Instead of using the syscon_regmap_lookup_by_compatible function
  use a phandle in the device tree along with offsets specified in
  this phandle node and then read the offset along with the device
  node in the driver for reading from the required region.

Changes since v2:
- Implement the SoC bus code as a driver in drivers/soc
  by registering with fsl,mscm-cpucfg as per Arnd's feedback

Changes since v1:
- Sort the headers in alphabetical order

Changes since RFC:
- Use a DT entry for the ROM area while specifying it as syscon.

One question I had in comparison to the previous implementation is, the
previous patch also resulted in exposing the DT devices in the subdirectory
soc under soc0/ which happened due to the of_platform_populate call. With
the current implementation this does not happen anymore. I am not too
thorough on all this, but I guess that of_platform_populate needs to be
called early with the right arguments. With the current implementation is
it possible to get that soc0/soc directory exposed in any way? Am I missing
something trivial in all this?

I guess we are OK, even if the above cannot be achived with the current
implementation. The main aim of this exercise was to expose the SoC specific
attributes. However it did be nice, if it could still be done. Perhaps that
part of the implementation can go in later in a separate patch.

Arnd are you ok with this implementation?

Notes same since v1 and v2:
Currently the required information is more or less read across the whole
SoC, but I guess we cannot change that since these are the locations
with the required information.

There seem to be three options for the revision field:
- ROM revision (see https://community.freescale.com/docs/DOC-94802)
- ANADIG revision (ANADIG_DIGIPROC, as used for the i.MX SoC's)
- OCOTP revision

Some numbers:

Colibri VF61 1.1A (2N02G)
- 0x00000013
- 0x00610000
- 0x01000000
- 0x410000c8

Colibri VF61 V1.0B (1N02G)
- 0x00000011
- 0x00610000
- 0x01000000
- 0x410000c8

Colibri VF61 V1.0A (which is actually a VF600 SoC, no L2 cache, since
that was the only one we could buy back then, 1N02G printed on it)
- 0x00000011
- 0x00610000
- 0x01000000
- none...

Colibri VF50 V1.0A (1N02G)
- 0x00000011
- 0x00610000
- 0x01000000
- none...

Vybrid Tower Rev J (1N02G)
- 0x00000011
- 0x00610000
- 0x01000000
- 0x410000c8

The ROM revision differs the most, so we would like to go with the
revision information from the ROM register 0x80.

Sanchayan Maity (2):
  ARM: dts: vfxxx: Add OCOTP and OCROM nodes
  soc: Add driver for Freescale Vybrid Platform

 arch/arm/boot/dts/vfxxx.dtsi |  12 ++++
 drivers/soc/Kconfig          |   1 +
 drivers/soc/Makefile         |   1 +
 drivers/soc/fsl/Kconfig      |   9 +++
 drivers/soc/fsl/Makefile     |   1 +
 drivers/soc/fsl/soc-vf610.c  | 168 +++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 192 insertions(+)
 create mode 100644 drivers/soc/fsl/Kconfig
 create mode 100644 drivers/soc/fsl/Makefile
 create mode 100644 drivers/soc/fsl/soc-vf610.c

-- 
2.4.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v4 1/2] ARM: dts: vfxxx: Add OCOTP and OCROM nodes
  2015-05-26 11:36 [PATCH v4 0/2] Implement SoC bus support for Vybrid Sanchayan Maity
@ 2015-05-26 11:36 ` Sanchayan Maity
  2015-05-26 11:36 ` [PATCH v4 2/2] soc: Add driver for Freescale Vybrid Platform Sanchayan Maity
  1 sibling, 0 replies; 9+ messages in thread
From: Sanchayan Maity @ 2015-05-26 11:36 UTC (permalink / raw)
  To: arnd, shawn.guo, kernel
  Cc: stefan, linux-arm-kernel, devicetree, linux-kernel, Sanchayan Maity

Add a device tree node for the On-Chip One Time Programmable
Controller (OCOTP) and the On-Chip ROM.

Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
---
 arch/arm/boot/dts/vfxxx.dtsi | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/arm/boot/dts/vfxxx.dtsi b/arch/arm/boot/dts/vfxxx.dtsi
index 2f4b04d..ed9b6b8 100644
--- a/arch/arm/boot/dts/vfxxx.dtsi
+++ b/arch/arm/boot/dts/vfxxx.dtsi
@@ -56,6 +56,13 @@
 		compatible = "simple-bus";
 		interrupt-parent = <&mscm_ir>;
 		ranges;
+		ocotp-cfg = <&ocotp 0x410 0x420>;
+		rom-revision = <&ocrom 0x80>;
+
+		ocrom: ocrom {
+			compatible = "fsl,vf610-ocrom", "syscon";
+			reg = <0x00000000 0x18000>;
+		};
 
 		aips0: aips-bus@40000000 {
 			compatible = "fsl,aips-bus", "simple-bus";
@@ -403,6 +410,11 @@
 				status = "disabled";
 			};
 
+			ocotp: ocotp@400a5000 {
+				compatible = "fsl,vf610-ocotp", "syscon";
+				reg = <0x400a5000 0x1000>;
+			};
+
 			snvs0: snvs@400a7000 {
 			    compatible = "fsl,sec-v4.0-mon", "simple-bus";
 				#address-cells = <1>;
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v4 2/2] soc: Add driver for Freescale Vybrid Platform
  2015-05-26 11:36 [PATCH v4 0/2] Implement SoC bus support for Vybrid Sanchayan Maity
  2015-05-26 11:36 ` [PATCH v4 1/2] ARM: dts: vfxxx: Add OCOTP and OCROM nodes Sanchayan Maity
@ 2015-05-26 11:36 ` Sanchayan Maity
  2015-05-27  7:31   ` Paul Bolle
                     ` (2 more replies)
  1 sibling, 3 replies; 9+ messages in thread
From: Sanchayan Maity @ 2015-05-26 11:36 UTC (permalink / raw)
  To: arnd, shawn.guo, kernel
  Cc: stefan, linux-arm-kernel, devicetree, linux-kernel, Sanchayan Maity

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 | 168 ++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 180 insertions(+)
 create mode 100644 drivers/soc/fsl/Kconfig
 create mode 100644 drivers/soc/fsl/Makefile
 create mode 100644 drivers/soc/fsl/soc-vf610.c

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..6425cfb
--- /dev/null
+++ b/drivers/soc/fsl/soc-vf610.c
@@ -0,0 +1,168 @@
+/*
+ * 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 DRIVER_NAME "vf610-soc-bus"
+
+#define MSCM_CPxCOUNT_OFFSET   0x0000002C
+#define MSCM_CPxCFG1_OFFSET    0x00000014
+
+static struct soc_device_attribute *soc_dev_attr;
+static struct soc_device *soc_dev;
+
+static int vf610_soc_probe(struct platform_device *pdev)
+{
+	struct regmap *ocotp_regmap, *mscm_regmap, *rom_regmap;
+	struct device *dev = &pdev->dev;
+	struct device_node *node = pdev->dev.of_node;
+	struct device_node *soc_node;
+	struct of_phandle_args pargs;
+	char soc_type[] = "xx0";
+	u32 cfg0_offset, cfg1_offset, rom_rev_offset;
+	u32 soc_id1, soc_id2, rom_rev;
+	u32 cpxcount, cpxcfg1;
+	u64 soc_id;
+	int ret;
+
+	mscm_regmap = syscon_node_to_regmap(node);
+	if (IS_ERR(mscm_regmap)) {
+		dev_err(dev, "regmap lookup for mscm failed\n");
+		return PTR_ERR(mscm_regmap);
+	}
+
+	soc_node = of_find_node_by_path("/soc");
+
+	ret = of_parse_phandle_with_fixed_args(soc_node,
+					"ocotp-cfg", 2, 0, &pargs);
+	if (ret) {
+		dev_err(dev, "lookup failed for ocotp-cfg node %d\n", ret);
+		return ret;
+	}
+
+	ocotp_regmap = syscon_node_to_regmap(pargs.np);
+	if (IS_ERR(ocotp_regmap)) {
+		of_node_put(pargs.np);
+		dev_err(dev, "regmap lookup for ocotp failed\n");
+		return PTR_ERR(ocotp_regmap);
+	}
+
+	cfg0_offset = pargs.args[0];
+	cfg1_offset = pargs.args[1];
+	of_node_put(pargs.np);
+
+	ret = of_parse_phandle_with_fixed_args(soc_node,
+					"rom-revision", 1, 0, &pargs);
+	if (ret) {
+		dev_err(dev, "lookup failed for rom-revision node %d\n", ret);
+		return ret;
+	}
+
+	rom_regmap = syscon_node_to_regmap(pargs.np);
+	if (IS_ERR(rom_regmap)) {
+		of_node_put(pargs.np);
+		dev_err(dev, "regmap lookup for ocrom failed\n");
+		return PTR_ERR(rom_regmap);
+	}
+
+	rom_rev_offset = pargs.args[0];
+	of_node_put(pargs.np);
+
+	ret = regmap_read(ocotp_regmap, cfg0_offset, &soc_id1);
+	if (ret)
+		return -ENODEV;
+
+	ret = regmap_read(ocotp_regmap, 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_rev_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;
+}
+
+static int vf610_soc_remove(struct platform_device *pdev)
+{
+	if (soc_dev_attr) {
+		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);
+	}
+
+	if (soc_dev)
+		soc_device_unregister(soc_dev);
+
+	return 0;
+}
+
+static const struct of_device_id vf610_soc_bus_match[] = {
+	{ .compatible = "fsl,vf610-mscm-cpucfg", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, vf610_soc_bus_match);
+
+static struct platform_driver vf610_soc_driver = {
+	.probe          = vf610_soc_probe,
+	.remove         = vf610_soc_remove,
+	.driver         = {
+		.name   = DRIVER_NAME,
+		.of_match_table = vf610_soc_bus_match,
+	},
+};
+
+module_platform_driver(vf610_soc_driver);
+
+MODULE_DESCRIPTION("Freescale VF610 SoC bus driver");
+MODULE_LICENSE("GPL v2");
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v4 2/2] soc: Add driver for Freescale Vybrid Platform
  2015-05-26 11:36 ` [PATCH v4 2/2] soc: Add driver for Freescale Vybrid Platform Sanchayan Maity
@ 2015-05-27  7:31   ` Paul Bolle
  2015-05-27 13:07     ` maitysanchayan
  2015-05-27 17:47   ` Joachim Eastwood
  2015-05-27 21:42   ` Stefan Agner
  2 siblings, 1 reply; 9+ messages in thread
From: Paul Bolle @ 2015-05-27  7:31 UTC (permalink / raw)
  To: Sanchayan Maity
  Cc: arnd, shawn.guo, kernel, stefan, linux-arm-kernel, devicetree,
	linux-kernel

On Tue, 2015-05-26 at 17:06 +0530, Sanchayan Maity wrote:
> --- /dev/null
> +++ b/drivers/soc/fsl/Kconfig

> +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

(That review comment is courtesy of git.)

> --- /dev/null
> +++ b/drivers/soc/fsl/Makefile

> +obj-$(CONFIG_SOC_VF610)		+= soc-vf610.o

> --- /dev/null
> +++ b/drivers/soc/fsl/soc-vf610.c

> +MODULE_DEVICE_TABLE(of, vf610_soc_bus_match);

> +module_platform_driver(vf610_soc_driver);

(The series starting at https://lkml.org/lkml/2015/5/10/131 would allow
to use builtin_platform_driver() for built-in only code.)

> +MODULE_DESCRIPTION("Freescale VF610 SoC bus driver");
> +MODULE_LICENSE("GPL v2");

I think soc-vf610.o can only be built-in. But its code contains a few
module specific macros. Was it perhaps intended for SOC_VF610 to be
tristate?


Paul Bolle


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v4 2/2] soc: Add driver for Freescale Vybrid Platform
  2015-05-27  7:31   ` Paul Bolle
@ 2015-05-27 13:07     ` maitysanchayan
  2015-05-27 16:46       ` Paul Bolle
  2015-05-27 17:28       ` Andreas Färber
  0 siblings, 2 replies; 9+ messages in thread
From: maitysanchayan @ 2015-05-27 13:07 UTC (permalink / raw)
  To: Paul Bolle
  Cc: arnd, shawn.guo, kernel, stefan, linux-arm-kernel, devicetree,
	linux-kernel

Hello,

On 15-05-27 09:31:50, Paul Bolle wrote:
> On Tue, 2015-05-26 at 17:06 +0530, Sanchayan Maity wrote:
> > --- /dev/null
> > +++ b/drivers/soc/fsl/Kconfig
> 
> > +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
> 
> (That review comment is courtesy of git.)

Will fix it.

> 
> > --- /dev/null
> > +++ b/drivers/soc/fsl/Makefile
> 
> > +obj-$(CONFIG_SOC_VF610)		+= soc-vf610.o
> 
> > --- /dev/null
> > +++ b/drivers/soc/fsl/soc-vf610.c
> 
> > +MODULE_DEVICE_TABLE(of, vf610_soc_bus_match);
> 
> > +module_platform_driver(vf610_soc_driver);
> 
> (The series starting at https://lkml.org/lkml/2015/5/10/131 would allow
> to use builtin_platform_driver() for built-in only code.)

Thanks for bringing this to my attention. I am subscribed to the mailing
list however this skipped me.

> 
> > +MODULE_DESCRIPTION("Freescale VF610 SoC bus driver");
> > +MODULE_LICENSE("GPL v2");
> 
> I think soc-vf610.o can only be built-in. But its code contains a few
> module specific macros. Was it perhaps intended for SOC_VF610 to be
> tristate?

I too think that should be built-in. Did not have an intention of making
it tristate, however while using other drivers as references, the perhaps
unneccessary stuff crept in.

The MODULE_* references can be removed along with the corresponding header
file. However that series has not been merged yet, so I can't use builtin_*
yet?

@Arnd

Are you ok with the patch in general? I can take care of the above changes
and send a new version. And once the builtin_driver stuff gets merged, I
can send a minor patch to change this module one to builtin?

Regards,
Sanchayan.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v4 2/2] soc: Add driver for Freescale Vybrid Platform
  2015-05-27 13:07     ` maitysanchayan
@ 2015-05-27 16:46       ` Paul Bolle
  2015-05-27 17:28       ` Andreas Färber
  1 sibling, 0 replies; 9+ messages in thread
From: Paul Bolle @ 2015-05-27 16:46 UTC (permalink / raw)
  To: maitysanchayan
  Cc: arnd, shawn.guo, kernel, stefan, linux-arm-kernel, devicetree,
	linux-kernel

On Wed, 2015-05-27 at 18:37 +0530, maitysanchayan@gmail.com wrote:
> > > +module_platform_driver(vf610_soc_driver);
> > 
> > (The series starting at https://lkml.org/lkml/2015/5/10/131 would allow
> > to use builtin_platform_driver() for built-in only code.)
> 
> Thanks for bringing this to my attention. I am subscribed to the mailing
> list however this skipped me.

> However that series has not been merged yet, so I can't use builtin_*
> yet?

Correct.

If that series get merged, which is not certain at all, you might
consider changing this. Probably no one will notice if you don't.


Paul Bolle


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v4 2/2] soc: Add driver for Freescale Vybrid Platform
  2015-05-27 13:07     ` maitysanchayan
  2015-05-27 16:46       ` Paul Bolle
@ 2015-05-27 17:28       ` Andreas Färber
  1 sibling, 0 replies; 9+ messages in thread
From: Andreas Färber @ 2015-05-27 17:28 UTC (permalink / raw)
  To: maitysanchayan, Paul Bolle
  Cc: devicetree, arnd, linux-kernel, stefan, kernel, shawn.guo,
	linux-arm-kernel

Hi,

Am 27.05.2015 um 15:07 schrieb maitysanchayan@gmail.com:
> On 15-05-27 09:31:50, Paul Bolle wrote:
>> On Tue, 2015-05-26 at 17:06 +0530, Sanchayan Maity wrote:
>>> --- /dev/null
>>> +++ b/drivers/soc/fsl/Kconfig
>>
>>> +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
[...]
>>> --- /dev/null
>>> +++ b/drivers/soc/fsl/Makefile
>>
>>> +obj-$(CONFIG_SOC_VF610)		+= soc-vf610.o
>>
>>> --- /dev/null
>>> +++ b/drivers/soc/fsl/soc-vf610.c
>>
>>> +MODULE_DEVICE_TABLE(of, vf610_soc_bus_match);
>>
>>> +module_platform_driver(vf610_soc_driver);
>>
>> (The series starting at https://lkml.org/lkml/2015/5/10/131 would allow
>> to use builtin_platform_driver() for built-in only code.)
[...]
>>> +MODULE_DESCRIPTION("Freescale VF610 SoC bus driver");
>>> +MODULE_LICENSE("GPL v2");
>>
>> I think soc-vf610.o can only be built-in. But its code contains a few
>> module specific macros. Was it perhaps intended for SOC_VF610 to be
>> tristate?
> 
> I too think that should be built-in.

Why? For a generic distro kernel it'd be unfortunate to not allow
putting such a driver into an initrd, if needed early, or into the
rootfs otherwise.

Regards,
Andreas

> Did not have an intention of making
> it tristate, however while using other drivers as references, the perhaps
> unneccessary stuff crept in.
> 
> The MODULE_* references can be removed along with the corresponding header
> file. However that series has not been merged yet, so I can't use builtin_*
> yet?
[snip]

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
21284 (AG Nürnberg)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v4 2/2] soc: Add driver for Freescale Vybrid Platform
  2015-05-26 11:36 ` [PATCH v4 2/2] soc: Add driver for Freescale Vybrid Platform Sanchayan Maity
  2015-05-27  7:31   ` Paul Bolle
@ 2015-05-27 17:47   ` Joachim Eastwood
  2015-05-27 21:42   ` Stefan Agner
  2 siblings, 0 replies; 9+ messages in thread
From: Joachim Eastwood @ 2015-05-27 17:47 UTC (permalink / raw)
  To: Sanchayan Maity
  Cc: Arnd Bergmann, Shawn Guo, kernel, devicetree, linux-arm-kernel,
	Stefan Agner, linux-kernel

On 26 May 2015 at 13:36, Sanchayan Maity <maitysanchayan@gmail.com> wrote:
> 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>
> ---
[...]
> +static struct soc_device_attribute *soc_dev_attr;
> +static struct soc_device *soc_dev;

Now that this is a proper platform device consider putting these in a
struct and allocated it in probe to get rid of the global variables.

> +static int vf610_soc_probe(struct platform_device *pdev)
> +{
> +       struct regmap *ocotp_regmap, *mscm_regmap, *rom_regmap;
> +       struct device *dev = &pdev->dev;
> +       struct device_node *node = pdev->dev.of_node;
[...]
> +       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);

Since you now have a device pointer you can now uses all the devm_*
functions to allocate your memory.
There is also a devm_kasprintf function.

> +               return -ENODEV;
> +       }
> +
> +       return 0;
> +}
> +
> +static int vf610_soc_remove(struct platform_device *pdev)
> +{
> +       if (soc_dev_attr) {
> +               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);

With devm_* you can remove this stuff.

> +       }
> +
> +       if (soc_dev)
> +               soc_device_unregister(soc_dev);
> +
> +       return 0;
> +}


regards,
Joachim Eastwood

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v4 2/2] soc: Add driver for Freescale Vybrid Platform
  2015-05-26 11:36 ` [PATCH v4 2/2] soc: Add driver for Freescale Vybrid Platform Sanchayan Maity
  2015-05-27  7:31   ` Paul Bolle
  2015-05-27 17:47   ` Joachim Eastwood
@ 2015-05-27 21:42   ` Stefan Agner
  2 siblings, 0 replies; 9+ messages in thread
From: Stefan Agner @ 2015-05-27 21:42 UTC (permalink / raw)
  To: Sanchayan Maity, arnd
  Cc: shawn.guo, kernel, linux-arm-kernel, devicetree, linux-kernel

On 2015-05-26 13:36, Sanchayan Maity wrote:
> 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 | 168 ++++++++++++++++++++++++++++++++++++++++++++
>  5 files changed, 180 insertions(+)
>  create mode 100644 drivers/soc/fsl/Kconfig
>  create mode 100644 drivers/soc/fsl/Makefile
>  create mode 100644 drivers/soc/fsl/soc-vf610.c
> 
> 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..6425cfb
> --- /dev/null
> +++ b/drivers/soc/fsl/soc-vf610.c
> @@ -0,0 +1,168 @@
> +/*
> + * 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 DRIVER_NAME "vf610-soc-bus"
> +
> +#define MSCM_CPxCOUNT_OFFSET   0x0000002C
> +#define MSCM_CPxCFG1_OFFSET    0x00000014
> +
> +static struct soc_device_attribute *soc_dev_attr;
> +static struct soc_device *soc_dev;
> +
> +static int vf610_soc_probe(struct platform_device *pdev)
> +{
> +	struct regmap *ocotp_regmap, *mscm_regmap, *rom_regmap;
> +	struct device *dev = &pdev->dev;
> +	struct device_node *node = pdev->dev.of_node;
> +	struct device_node *soc_node;
> +	struct of_phandle_args pargs;
> +	char soc_type[] = "xx0";
> +	u32 cfg0_offset, cfg1_offset, rom_rev_offset;
> +	u32 soc_id1, soc_id2, rom_rev;
> +	u32 cpxcount, cpxcfg1;
> +	u64 soc_id;
> +	int ret;
> +
> +	mscm_regmap = syscon_node_to_regmap(node);
> +	if (IS_ERR(mscm_regmap)) {
> +		dev_err(dev, "regmap lookup for mscm failed\n");
> +		return PTR_ERR(mscm_regmap);
> +	}
> +
> +	soc_node = of_find_node_by_path("/soc");
> +
> +	ret = of_parse_phandle_with_fixed_args(soc_node,
> +					"ocotp-cfg", 2, 0, &pargs);
> +	if (ret) {
> +		dev_err(dev, "lookup failed for ocotp-cfg node %d\n", ret);
> +		return ret;
> +	}
> +
> +	ocotp_regmap = syscon_node_to_regmap(pargs.np);
> +	if (IS_ERR(ocotp_regmap)) {
> +		of_node_put(pargs.np);
> +		dev_err(dev, "regmap lookup for ocotp failed\n");
> +		return PTR_ERR(ocotp_regmap);
> +	}
> +
> +	cfg0_offset = pargs.args[0];
> +	cfg1_offset = pargs.args[1];
> +	of_node_put(pargs.np);
> +
> +	ret = of_parse_phandle_with_fixed_args(soc_node,
> +					"rom-revision", 1, 0, &pargs);
> +	if (ret) {
> +		dev_err(dev, "lookup failed for rom-revision node %d\n", ret);
> +		return ret;
> +	}
> +
> +	rom_regmap = syscon_node_to_regmap(pargs.np);
> +	if (IS_ERR(rom_regmap)) {
> +		of_node_put(pargs.np);
> +		dev_err(dev, "regmap lookup for ocrom failed\n");
> +		return PTR_ERR(rom_regmap);
> +	}
> +
> +	rom_rev_offset = pargs.args[0];
> +	of_node_put(pargs.np);
> +
> +	ret = regmap_read(ocotp_regmap, cfg0_offset, &soc_id1);
> +	if (ret)
> +		return -ENODEV;
> +
> +	ret = regmap_read(ocotp_regmap, 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_rev_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;
> +}
> +
> +static int vf610_soc_remove(struct platform_device *pdev)
> +{
> +	if (soc_dev_attr) {
> +		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);
> +	}
> +
> +	if (soc_dev)
> +		soc_device_unregister(soc_dev);
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id vf610_soc_bus_match[] = {
> +	{ .compatible = "fsl,vf610-mscm-cpucfg", },

IMHO that is a mix and match now. We still bind this driver to a
specific device, while we point directly to the registers from the SoC
level (in the device tree).

I'm not sure if the suggestion I made in v2 is acceptable: Couldn't we
add compatible nodes to the SoC level and bind this driver to the SoC
directly? I think if we point to the registers at SoC level, we should
also bind this driver to the SoC level. Of course, then we additionally
need to point to the mscm-cpucfg register to get the SoC type
information.

If we keep this driver bound to "fsl,vf610-mscm-cpucfg", then I think we
should also point from this node to the other nodes/registers...

Arnd, where did you meant to put the pointers?

--
Stefan

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-05-27 21:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-26 11:36 [PATCH v4 0/2] Implement SoC bus support for Vybrid Sanchayan Maity
2015-05-26 11:36 ` [PATCH v4 1/2] ARM: dts: vfxxx: Add OCOTP and OCROM nodes Sanchayan Maity
2015-05-26 11:36 ` [PATCH v4 2/2] soc: Add driver for Freescale Vybrid Platform Sanchayan Maity
2015-05-27  7:31   ` Paul Bolle
2015-05-27 13:07     ` maitysanchayan
2015-05-27 16:46       ` Paul Bolle
2015-05-27 17:28       ` Andreas Färber
2015-05-27 17:47   ` Joachim Eastwood
2015-05-27 21:42   ` Stefan Agner

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).