2021-03-19 18:29:35

by Cristian Ciocaltea

[permalink] [raw]
Subject: [PATCH 0/4] Add support for Actions Semi Owl soc info

This patchset adds a socinfo driver which provides information about
Actions Semi Owl SoCs to user space via sysfs: machine, family, soc_id,
serial_number.

Please note the serial number is currently available only for the S500
SoC variant.

This has been tested on the S500 SoC based RoseapplePi SBC.

Thanks,
Cristi

Cristian Ciocaltea (4):
dt-bindings: soc: actions: Add Actions Semi Owl socinfo binding
soc: actions: Add Actions Semi Owl socinfo driver
arm: dts: owl-s500: Add socinfo support
MAINTAINERS: Add entry for Actions Semi Owl socinfo binding

.../bindings/soc/actions/owl-socinfo.yaml | 71 ++++++++++
MAINTAINERS | 1 +
arch/arm/boot/dts/owl-s500.dtsi | 4 +-
drivers/soc/actions/Kconfig | 8 ++
drivers/soc/actions/Makefile | 1 +
drivers/soc/actions/owl-socinfo.c | 133 ++++++++++++++++++
6 files changed, 217 insertions(+), 1 deletion(-)
create mode 100644 Documentation/devicetree/bindings/soc/actions/owl-socinfo.yaml
create mode 100644 drivers/soc/actions/owl-socinfo.c

--
2.31.0


2021-03-19 18:30:12

by Cristian Ciocaltea

[permalink] [raw]
Subject: [PATCH 4/4] MAINTAINERS: Add entry for Actions Semi Owl socinfo binding

Add an entry for the Actions Semi Owl socinfo binding.

Signed-off-by: Cristian Ciocaltea <[email protected]>
---
MAINTAINERS | 1 +
1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 20b8e37ea34c..21d54ddcceb4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1533,6 +1533,7 @@ F: Documentation/devicetree/bindings/mmc/owl-mmc.yaml
F: Documentation/devicetree/bindings/net/actions,owl-emac.yaml
F: Documentation/devicetree/bindings/pinctrl/actions,*
F: Documentation/devicetree/bindings/power/actions,owl-sps.txt
+F: Documentation/devicetree/bindings/soc/actions/owl-socinfo.yaml
F: Documentation/devicetree/bindings/timer/actions,owl-timer.txt
F: arch/arm/boot/dts/owl-*
F: arch/arm/mach-actions/
--
2.31.0

2021-03-19 18:30:37

by Cristian Ciocaltea

[permalink] [raw]
Subject: [PATCH 1/4] dt-bindings: soc: actions: Add Actions Semi Owl socinfo binding

Add devicetree binding for the Actions Semi Owl SoCs info module.

Signed-off-by: Cristian Ciocaltea <[email protected]>
---
.../bindings/soc/actions/owl-socinfo.yaml | 71 +++++++++++++++++++
1 file changed, 71 insertions(+)
create mode 100644 Documentation/devicetree/bindings/soc/actions/owl-socinfo.yaml

diff --git a/Documentation/devicetree/bindings/soc/actions/owl-socinfo.yaml b/Documentation/devicetree/bindings/soc/actions/owl-socinfo.yaml
new file mode 100644
index 000000000000..3fcb1f584fdf
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/actions/owl-socinfo.yaml
@@ -0,0 +1,71 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/actions/owl-socinfo.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Actions Semi Owl SoC info module
+
+maintainers:
+ - Cristian Ciocaltea <[email protected]>
+
+description: |
+ Actions Semi Owl SoC info module provides access to various information
+ about the S500, S700 and S900 SoC variants, such as serial number or id.
+
+patternProperties:
+ "^soc(@[0-9a-f]+)?$":
+ type: object
+ properties:
+ compatible:
+ items:
+ - enum:
+ - actions,s500-soc
+ - actions,s700-soc
+ - actions,s900-soc
+ - const: simple-bus
+
+ "#address-cells":
+ enum: [1, 2]
+
+ "#size-cells":
+ enum: [1, 2]
+
+ ranges: true
+
+ actions,serial-number-addrs:
+ description: |
+ Contains the physical addresses in DDR memory where the two parts
+ of the serial number (low & high) can be read from.
+ This is currently supported only on the S500 SoC variant.
+ $ref: /schemas/types.yaml#/definitions/uint32-array
+ minItems: 2
+ maxItems: 2
+
+ required:
+ - compatible
+
+ additionalProperties:
+ type: object
+
+additionalProperties: true
+
+examples:
+ - |
+ / {
+ compatible = "roseapplepi,roseapplepi", "actions,s500";
+ model = "Roseapple Pi";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ soc {
+ compatible = "actions,s500-soc", "simple-bus";
+ #address-cells = <1>;
+ #size-cells = <1>;
+ ranges;
+ actions,serial-number-addrs = <0x800>, /* S/N Low */
+ <0x804>; /* S/N High */
+ };
+ };
+
+...
--
2.31.0

2021-03-19 18:30:44

by Cristian Ciocaltea

[permalink] [raw]
Subject: [PATCH 3/4] arm: dts: owl-s500: Add socinfo support

Update soc node compatible property to enable support for the Actions
Semi Owl soc info driver.

Additionally provide memory addresses where the serial number parts are
accessible.

Signed-off-by: Cristian Ciocaltea <[email protected]>
---
arch/arm/boot/dts/owl-s500.dtsi | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/owl-s500.dtsi b/arch/arm/boot/dts/owl-s500.dtsi
index 739b4b9cec8c..07a165918de9 100644
--- a/arch/arm/boot/dts/owl-s500.dtsi
+++ b/arch/arm/boot/dts/owl-s500.dtsi
@@ -80,10 +80,12 @@ losc: losc {
};

soc {
- compatible = "simple-bus";
+ compatible = "actions,s500-soc", "simple-bus";
#address-cells = <1>;
#size-cells = <1>;
ranges;
+ actions,serial-number-addrs = <0x800>, /* S/N Low */
+ <0x804>; /* S/N High */

scu: scu@b0020000 {
compatible = "arm,cortex-a9-scu";
--
2.31.0

2021-03-19 18:31:36

by Cristian Ciocaltea

[permalink] [raw]
Subject: [PATCH 2/4] soc: actions: Add Actions Semi Owl socinfo driver

The driver provides information about the Action Semi Owl family of
SoCs (S500, S700 and S900) to user space via sysfs: machine, family,
soc_id, serial_number.

Note the serial number is currently provided only for the S500 SoC
variant.

Signed-off-by: Cristian Ciocaltea <[email protected]>
---
drivers/soc/actions/Kconfig | 8 ++
drivers/soc/actions/Makefile | 1 +
drivers/soc/actions/owl-socinfo.c | 133 ++++++++++++++++++++++++++++++
3 files changed, 142 insertions(+)
create mode 100644 drivers/soc/actions/owl-socinfo.c

diff --git a/drivers/soc/actions/Kconfig b/drivers/soc/actions/Kconfig
index 1aca2058a40c..15faade9282d 100644
--- a/drivers/soc/actions/Kconfig
+++ b/drivers/soc/actions/Kconfig
@@ -14,4 +14,12 @@ config OWL_PM_DOMAINS
power-gating on Actions Semiconductor S500, S700 and S900 SoCs.
If unsure, say 'n'.

+config OWL_SOCINFO
+ bool "Actions Semi Owl SoC info driver"
+ default ARCH_ACTIONS
+ select SOC_BUS
+ help
+ Say 'y' here to support the Action Semiconductor Owl socinfo
+ driver, providing information about the SoC to user space.
+
endif
diff --git a/drivers/soc/actions/Makefile b/drivers/soc/actions/Makefile
index 4db9e7b050e5..4b2591d3089f 100644
--- a/drivers/soc/actions/Makefile
+++ b/drivers/soc/actions/Makefile
@@ -2,3 +2,4 @@

obj-$(CONFIG_OWL_PM_DOMAINS_HELPER) += owl-sps-helper.o
obj-$(CONFIG_OWL_PM_DOMAINS) += owl-sps.o
+obj-$(CONFIG_OWL_SOCINFO) += owl-socinfo.o
diff --git a/drivers/soc/actions/owl-socinfo.c b/drivers/soc/actions/owl-socinfo.c
new file mode 100644
index 000000000000..2786c4fd261c
--- /dev/null
+++ b/drivers/soc/actions/owl-socinfo.c
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Actions Semi Owl SoC information driver
+ *
+ * Copyright (c) 2021 Cristian Ciocaltea <[email protected]>
+ */
+
+#include <linux/highmem.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/random.h>
+#include <linux/sys_soc.h>
+
+#include <asm/system_info.h>
+
+struct owl_soc_info {
+ char *name;
+ int (*get_system_serial)(struct device *dev);
+};
+
+static int __init owl_read_sn_from_mem(struct device *dev)
+{
+ int paddrs[2] = {0};
+ char *vaddr;
+ int ret;
+
+ ret = device_property_read_u32_array(dev,
+ "actions,serial-number-addrs",
+ paddrs, 2);
+ if (ret) {
+ dev_err(dev, "failed to read SoC S/N addresses: %d\n", ret);
+ return ret;
+ }
+
+ if (PHYS_PFN(paddrs[0]) != PHYS_PFN(paddrs[1])) {
+ dev_err(dev, "invalid SoC S/N addresses\n");
+ return -EINVAL;
+ }
+
+ vaddr = kmap_local_pfn(PHYS_PFN(paddrs[0]));
+
+ memcpy(&system_serial_low, vaddr + (paddrs[0] & (PAGE_SIZE - 1)),
+ sizeof(system_serial_low));
+ memcpy(&system_serial_high, vaddr + (paddrs[1] & (PAGE_SIZE - 1)),
+ sizeof(system_serial_high));
+
+ kunmap_local(vaddr);
+
+ return 0;
+}
+
+static int owl_socinfo_probe(struct platform_device *pdev)
+{
+ const struct owl_soc_info *soc_info;
+ struct soc_device_attribute *soc_dev_attr;
+ struct soc_device *soc_dev;
+ int ret;
+
+ soc_info = of_device_get_match_data(&pdev->dev);
+ if (!soc_info)
+ return -ENODEV;
+
+ soc_dev_attr = devm_kzalloc(&pdev->dev, sizeof(*soc_dev_attr),
+ GFP_KERNEL);
+ if (!soc_dev_attr)
+ return -ENOMEM;
+
+ ret = of_property_read_string(of_root, "model", &soc_dev_attr->machine);
+ if (ret)
+ return ret;
+
+ soc_dev_attr->family = "Actions Semi Owl";
+ soc_dev_attr->soc_id = soc_info->name;
+
+ if (soc_info->get_system_serial) {
+ ret = soc_info->get_system_serial(&pdev->dev);
+ if (!ret) {
+ soc_dev_attr->serial_number = devm_kasprintf(&pdev->dev,
+ GFP_KERNEL, "%08x%08x",
+ system_serial_high,
+ system_serial_low);
+ /* Feed the SoC unique data into entropy pool. */
+ add_device_randomness(soc_dev_attr->serial_number, 16);
+ }
+ }
+
+ soc_dev = soc_device_register(soc_dev_attr);
+ if (IS_ERR(soc_dev))
+ return dev_err_probe(&pdev->dev, PTR_ERR(soc_dev),
+ "failed to register soc device");
+
+ dev_info(soc_device_to_device(soc_dev),
+ "SoC: %s %s\n",
+ soc_dev_attr->family, soc_dev_attr->soc_id);
+
+ return 0;
+}
+
+static const struct owl_soc_info s500_soc_info = {
+ .name = "S500",
+ .get_system_serial = owl_read_sn_from_mem,
+};
+
+static const struct owl_soc_info s700_soc_info = {
+ .name = "S700",
+ /* FIXME: provide get_system_serial */
+};
+
+static const struct owl_soc_info s900_soc_info = {
+ .name = "S900",
+ /* FIXME: provide get_system_serial */
+};
+
+static const struct of_device_id owl_soc_of_match[] = {
+ { .compatible = "actions,s500-soc", .data = &s500_soc_info, },
+ { .compatible = "actions,s700-soc", .data = &s700_soc_info, },
+ { .compatible = "actions,s900-soc", .data = &s900_soc_info, },
+ { }
+};
+
+static struct platform_driver owl_socinfo_platform_driver = {
+ .probe = owl_socinfo_probe,
+ .driver = {
+ .name = "owl-socinfo",
+ .of_match_table = owl_soc_of_match,
+ },
+};
+
+static int __init owl_socinfo_init(void)
+{
+ return platform_driver_register(&owl_socinfo_platform_driver);
+}
+subsys_initcall(owl_socinfo_init);
--
2.31.0

2021-03-27 16:32:45

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH 1/4] dt-bindings: soc: actions: Add Actions Semi Owl socinfo binding

On Fri, Mar 19, 2021 at 08:27:59PM +0200, Cristian Ciocaltea wrote:
> Add devicetree binding for the Actions Semi Owl SoCs info module.
>
> Signed-off-by: Cristian Ciocaltea <[email protected]>
> ---
> .../bindings/soc/actions/owl-socinfo.yaml | 71 +++++++++++++++++++
> 1 file changed, 71 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/soc/actions/owl-socinfo.yaml
>
> diff --git a/Documentation/devicetree/bindings/soc/actions/owl-socinfo.yaml b/Documentation/devicetree/bindings/soc/actions/owl-socinfo.yaml
> new file mode 100644
> index 000000000000..3fcb1f584fdf
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/soc/actions/owl-socinfo.yaml
> @@ -0,0 +1,71 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/soc/actions/owl-socinfo.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Actions Semi Owl SoC info module
> +
> +maintainers:
> + - Cristian Ciocaltea <[email protected]>
> +
> +description: |
> + Actions Semi Owl SoC info module provides access to various information
> + about the S500, S700 and S900 SoC variants, such as serial number or id.
> +
> +patternProperties:
> + "^soc(@[0-9a-f]+)?$":

Make this a $nodename property.

> + type: object
> + properties:

And move this up to top-level.

You need a custom 'select' entry to exclude 'simple-bus'.

> + compatible:
> + items:
> + - enum:
> + - actions,s500-soc
> + - actions,s700-soc
> + - actions,s900-soc
> + - const: simple-bus
> +
> + "#address-cells":
> + enum: [1, 2]
> +
> + "#size-cells":
> + enum: [1, 2]
> +
> + ranges: true
> +
> + actions,serial-number-addrs:
> + description: |
> + Contains the physical addresses in DDR memory where the two parts
> + of the serial number (low & high) can be read from.
> + This is currently supported only on the S500 SoC variant.
> + $ref: /schemas/types.yaml#/definitions/uint32-array
> + minItems: 2
> + maxItems: 2

Humm, it doesn't really seem you have an actual device or bus here, but
are abusing DT to create your socinfo device.

As the only property is data in main memory, you should do a compatible
for that memory region and put it under reserved-memory. You need that
anyway to prevent the kernel from using the memory, right?

Rob

2021-03-29 22:25:16

by Cristian Ciocaltea

[permalink] [raw]
Subject: Re: [PATCH 1/4] dt-bindings: soc: actions: Add Actions Semi Owl socinfo binding

On Sat, Mar 27, 2021 at 10:30:06AM -0600, Rob Herring wrote:
> On Fri, Mar 19, 2021 at 08:27:59PM +0200, Cristian Ciocaltea wrote:
> > Add devicetree binding for the Actions Semi Owl SoCs info module.
> >
> > Signed-off-by: Cristian Ciocaltea <[email protected]>
> > ---
> > .../bindings/soc/actions/owl-socinfo.yaml | 71 +++++++++++++++++++

[...]

> > +
> > +patternProperties:
> > + "^soc(@[0-9a-f]+)?$":
>
> Make this a $nodename property.
>
> > + type: object
> > + properties:
>
> And move this up to top-level.
>
> You need a custom 'select' entry to exclude 'simple-bus'.

Indeed, I missed it..

> > + compatible:
> > + items:
> > + - enum:
> > + - actions,s500-soc
> > + - actions,s700-soc
> > + - actions,s900-soc
> > + - const: simple-bus
> > +
> > + "#address-cells":
> > + enum: [1, 2]
> > +
> > + "#size-cells":
> > + enum: [1, 2]
> > +
> > + ranges: true
> > +
> > + actions,serial-number-addrs:
> > + description: |
> > + Contains the physical addresses in DDR memory where the two parts
> > + of the serial number (low & high) can be read from.
> > + This is currently supported only on the S500 SoC variant.
> > + $ref: /schemas/types.yaml#/definitions/uint32-array
> > + minItems: 2
> > + maxItems: 2
>
> Humm, it doesn't really seem you have an actual device or bus here, but
> are abusing DT to create your socinfo device.
>
> As the only property is data in main memory, you should do a compatible
> for that memory region and put it under reserved-memory. You need that
> anyway to prevent the kernel from using the memory, right?

Right, this region should be exposed as reserved-memory. Will handle
it in the next revision.

> Rob

Thanks for the review,
Cristi