Skip to contentSkip to conversation

drivers: hwspinlock: add CSR atlas7 implementation

PATCH In review Barry Song 2 participants 9 messages May 19, 2015 – May 26, 2015

Subsystems (2)
lore
Share & tools
lore

Barry Song

author
#0 lore raw

PATCH v3 1/3 drivers: hwspinlock: add CSR atlas7 implementation

From: Wei Chen <[email protected]>

Add hwspinlock support for the CSR atlas7 SoC.

The Hardware Spinlock device on atlas7 provides hardware assistance for synchronization between the multiple processors in the system (dual Cortex-A7, CAN bus Cortex-M3 and audio DSP).

Cc Suman Anna <[email protected]>
Cc Bjorn Andersson <[email protected]>

---
-v3:
use #hwlock-cells and general hwspinlock dt-binding; drop relax();
drop num-spinlocks in dts;
re-order Kconfig and Makefile;
other codingstyle issues.
Thanks Suman, Bjorn and Ohad

 drivers/hwspinlock/Kconfig           |  12 ++++
 drivers/hwspinlock/Makefile          |   1 +
 drivers/hwspinlock/sirf_hwspinlock.c | 135 +++++++++++++++++++++++++++++++++++
 3 files changed, 148 insertions(+)
 create mode 100644 drivers/hwspinlock/sirf_hwspinlock.c
drivers/hwspinlock/Kconfig +12 -0
index b5b4f52..73a4016 100644
@@ -30,6 +30,18 @@ config HWSPINLOCK_QCOM
 
 	  If unsure, say N.
 
+config HWSPINLOCK_SIRF
+	tristate "SIRF Hardware Spinlock device"
+	depends on ARCH_SIRF
+	select HWSPINLOCK
+	help
+	  Say y here to support the SIRF Hardware Spinlock device, which
+	  provides a synchronisation mechanism for the various processors
+	  on the SoC.
+
+	  It's safe to say n here if you're not interested in SIRF hardware
+	  spinlock or just want a bare minimum kernel.
+
 config HSEM_U8500
 	tristate "STE Hardware Semaphore functionality"
 	depends on ARCH_U8500
drivers/hwspinlock/Makefile +1 -0
index 68f95d9..6b59cb5a 100644
@@ -5,4 +5,5 @@
 obj-$(CONFIG_HWSPINLOCK)		+= hwspinlock_core.o
 obj-$(CONFIG_HWSPINLOCK_OMAP)		+= omap_hwspinlock.o
 obj-$(CONFIG_HWSPINLOCK_QCOM)		+= qcom_hwspinlock.o
+obj-$(CONFIG_HWSPINLOCK_SIRF)		+= sirf_hwspinlock.o
 obj-$(CONFIG_HSEM_U8500)		+= u8500_hsem.o
drivers/hwspinlock/sirf_hwspinlock.c new file +135 -0

135 lines not on this page · raw message

Signature · 1 line
2.3.5
author
#1 lore raw

PATCH v3 2/3 Documentation: dt: add the CSR atlas7 hwspinlock bindings document

From: Wei Chen <[email protected]>

The Hardware Spinlock device on atlas7 provides hardware assistance for synchronization between the multiple processors in the system (dual Cortex-A7, CAN bus Cortex-M3 and audio DSP).
This patch adds the DT bindings information for this hwspinlock module.

Cc Suman Anna <[email protected]>
Cc Bjorn Andersson <[email protected]>
---
 .../devicetree/bindings/hwlock/sirf,hwspinlock.txt | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt
Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt new file +25 -0
new file mode 100644
index 0000000..cc6d351
@@ -0,0 +1,25 @@
+SIRF Hardware spinlock device Binding
+-----------------------------------------------
+
+Required properties :
+- compatible : shall contain only one of the following:
+	"sirf,hwspinlock"
+
+- reg : the register address of hwspinlock
+
+Please look at the generic hwlock binding for usage information for consumers,
+"Documentation/devicetree/bindings/hwlock/hwlock.txt"
+
+Example of hwlock provider:
+	hwlock {
+		compatible = "sirf,hwspinlock";
+		reg = <0x13240000 0x00010000>;
+		#hwlock-cells = <1>;
+	};
+
+Example of hwlock users:
+	node {
+		...
+		hwlocks = <&hwlock 2>;
+		...
+	};
Signature · 1 line
2.3.5
#2 lore raw

Re: [PATCH 2/3 v3] Documentation: dt: add the CSR atlas7 hwspinlock bindings document

Hi Barry,

Quoted 23 lines · Barry Song

From: Wei Chen <[email protected]>

The Hardware Spinlock device on atlas7 provides hardware assistance for synchronization between the multiple processors in the system (dual Cortex-A7, CAN bus Cortex-M3 and audio DSP).
This patch adds the DT bindings information for this hwspinlock module.

Cc Suman Anna <[email protected]>
Cc Bjorn Andersson <[email protected]>
---
 .../devicetree/bindings/hwlock/sirf,hwspinlock.txt | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt
Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt new file +0 -0
new file mode 100644
index 0000000..cc6d351

Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt line 8

Quoted 8 lines
Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt new file +8 -0
@@ -0,0 +1,25 @@
+SIRF Hardware spinlock device Binding
+-----------------------------------------------
+
+Required properties :
+- compatible : shall contain only one of the following:
+	"sirf,hwspinlock"
+
+- reg : the register address of hwspinlock

Also suggest to document the value to be used for #hwlock-cells, the generic hwlock binding does not mention that.

Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt line 12

Quoted 4 lines
Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt new file +4 -0
+
+Please look at the generic hwlock binding for usage information for consumers,
+"Documentation/devicetree/bindings/hwlock/hwlock.txt"
+

regards
Suman

author
#3 lore raw

Re: [PATCH 2/3 v3] Documentation: dt: add the CSR atlas7 hwspinlock bindings document

2015-05-23 6:44 GMT+08:00 Suman Anna <[email protected]>:

Quoted 29 lines

Hi Barry,

Quoted 26 lines · Barry Song

From: Wei Chen <[email protected]>

The Hardware Spinlock device on atlas7 provides hardware assistance for synchronization between the multiple processors in the system (dual Cortex-A7, CAN bus Cortex-M3 and audio DSP).
This patch adds the DT bindings information for this hwspinlock module.

Cc Suman Anna <[email protected]>
Cc Bjorn Andersson <bjorn-UYDU3/[email protected]>
---
 .../devicetree/bindings/hwlock/sirf,hwspinlock.txt | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt
Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt new file +3 -0
new file mode 100644
index 0000000..cc6d351
@@ -0,0 +1,25 @@
+SIRF Hardware spinlock device Binding
+-----------------------------------------------
+
Quoted 8 lines

Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt line 8

Quoted 5 lines
Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt new file +5 -0
+Required properties :
+- compatible : shall contain only one of the following:
+     "sirf,hwspinlock"
+
+- reg : the register address of hwspinlock

Also suggest to document the value to be used for #hwlock-cells, the generic hwlock binding does not mention that.

do you think whether we can put one line like?

#hwlock-cells : <1>, as required by generic hwspinlock binding.

Quoted 9 lines

Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt line 12

Quoted 5 lines
Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt new file +4 -0
+
+Please look at the generic hwlock binding for usage information for consumers,
+"Documentation/devicetree/bindings/hwlock/hwlock.txt"
+

regards
Suman

-barry
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

Re: [PATCH 2/3 v3] Documentation: dt: add the CSR atlas7 hwspinlock bindings document

Quoted 39 lines · Barry Song

2015-05-23 6:44 GMT+08:00 Suman Anna <[email protected]>:

Quoted 29 lines

Hi Barry,

Quoted 26 lines · Barry Song

From: Wei Chen <[email protected]>

The Hardware Spinlock device on atlas7 provides hardware assistance for synchronization between the multiple processors in the system (dual Cortex-A7, CAN bus Cortex-M3 and audio DSP).
This patch adds the DT bindings information for this hwspinlock module.

Cc Suman Anna <[email protected]>
Cc Bjorn Andersson <[email protected]>
---
 .../devicetree/bindings/hwlock/sirf,hwspinlock.txt | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt
Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt new file +3 -0
new file mode 100644
index 0000000..cc6d351
@@ -0,0 +1,25 @@
+SIRF Hardware spinlock device Binding
+-----------------------------------------------
+
Quoted 8 lines

Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt line 8

Quoted 5 lines
Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt new file +5 -0
+Required properties :
+- compatible : shall contain only one of the following:
+     "sirf,hwspinlock"
+
+- reg : the register address of hwspinlock

Also suggest to document the value to be used for #hwlock-cells, the generic hwlock binding does not mention that.

Quoted 3 lines

do you think whether we can put one line like?

#hwlock-cells : <1>, as required by generic hwspinlock binding.

The generic hwspinlock binding does not require a specific value, that is something determined by the individual platform implementation. So, something like "#hwlock-cells: Should be 1" is fine.

regards
Suman

Quoted 12 lines
Quoted 9 lines

Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt line 12

Quoted 5 lines
Documentation/devicetree/bindings/hwlock/sirf,hwspinlock.txt new file +4 -0
+
+Please look at the generic hwlock binding for usage information for consumers,
+"Documentation/devicetree/bindings/hwlock/hwlock.txt"
+

regards
Suman

-barry

author
#5 lore raw

PATCH v3 3/3 ARM: dts: atlas7: use general dt-binding for hwspinlock

In reply to Barry Song

From: Wei Chen <[email protected]>

This patch moves to use generic dt-binding for hwspinlock providers and clients.
add #hwlock-cells for the provider and hwlocks for clients.

Cc Suman Anna <[email protected]>
Cc Bjorn Andersson <[email protected]>
---
 arch/arm/boot/dts/atlas7.dtsi | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arm/boot/dts/atlas7.dtsi +3 -3
index a753178..66d3f0e 100644
@@ -84,17 +84,17 @@
 			#address-cells = <1>;
 			#size-cells = <1>;
 
-			hwspinlock {
+			hwlock: hwspinlock {
 				compatible = "sirf,hwspinlock";
 				reg = <0x13240000 0x00010000>;
-
-				num-spinlocks = <30>;
+				#hwlock-cells = <1>;
 			};
 
 			ns_m3_rproc@0 {
 				compatible = "sirf,ns2m30-rproc";
 				reg = <0x13240000 0x00010000>;
 				interrupts = <0 123 0>;
+				hwlocks = <&hwlock 0>, <&hwlock 1>;
 			};
 
 			ns_m3_rproc@1 {
Signature · 1 line
2.3.5
#6 lore raw
In reply to Barry Song

Hi Barry,

Quoted 66 lines · Barry Song

From: Wei Chen <[email protected]>

Add hwspinlock support for the CSR atlas7 SoC.

The Hardware Spinlock device on atlas7 provides hardware assistance for synchronization between the multiple processors in the system (dual Cortex-A7, CAN bus Cortex-M3 and audio DSP).

Cc Suman Anna <[email protected]>
Cc Bjorn Andersson <bjorn-UYDU3/[email protected]>

---
-v3:
use #hwlock-cells and general hwspinlock dt-binding; drop relax();
drop num-spinlocks in dts;
re-order Kconfig and Makefile;
other codingstyle issues.
Thanks Suman, Bjorn and Ohad

 drivers/hwspinlock/Kconfig           |  12 ++++
 drivers/hwspinlock/Makefile          |   1 +
 drivers/hwspinlock/sirf_hwspinlock.c | 135 +++++++++++++++++++++++++++++++++++
 3 files changed, 148 insertions(+)
 create mode 100644 drivers/hwspinlock/sirf_hwspinlock.c
drivers/hwspinlock/Kconfig +12 -0
index b5b4f52..73a4016 100644
@@ -30,6 +30,18 @@ config HWSPINLOCK_QCOM
 
 	  If unsure, say N.
 
+config HWSPINLOCK_SIRF
+	tristate "SIRF Hardware Spinlock device"
+	depends on ARCH_SIRF
+	select HWSPINLOCK
+	help
+	  Say y here to support the SIRF Hardware Spinlock device, which
+	  provides a synchronisation mechanism for the various processors
+	  on the SoC.
+
+	  It's safe to say n here if you're not interested in SIRF hardware
+	  spinlock or just want a bare minimum kernel.
+
 config HSEM_U8500
 	tristate "STE Hardware Semaphore functionality"
 	depends on ARCH_U8500
drivers/hwspinlock/Makefile +1 -0
index 68f95d9..6b59cb5a 100644
@@ -5,4 +5,5 @@
 obj-$(CONFIG_HWSPINLOCK)		+= hwspinlock_core.o
 obj-$(CONFIG_HWSPINLOCK_OMAP)		+= omap_hwspinlock.o
 obj-$(CONFIG_HWSPINLOCK_QCOM)		+= qcom_hwspinlock.o
+obj-$(CONFIG_HWSPINLOCK_SIRF)		+= sirf_hwspinlock.o
 obj-$(CONFIG_HSEM_U8500)		+= u8500_hsem.o
drivers/hwspinlock/sirf_hwspinlock.c new file +0 -0
new file mode 100644
index 0000000..e7e5ba6

drivers/hwspinlock/sirf_hwspinlock.c line 4

Quoted 4 lines
drivers/hwspinlock/sirf_hwspinlock.c new file +4 -0
@@ -0,0 +1,135 @@
+/*
+ * SIRF hardware spinlock driver
+ *
+ * Copyright (c) 2014 Cambridge Silicon Radio Limited, a CSR plc group company.

Not sure on this, but 2015 is here and now..

Quoted 59 lines
drivers/hwspinlock/sirf_hwspinlock.c new file +59 -0
+ *
+ * Licensed under GPLv2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/io.h>
+#include <linux/pm_runtime.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/hwspinlock.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+
+#include "hwspinlock_internal.h"
+
+struct sirf_hwspinlock {
+	void __iomem *io_base;
+	struct hwspinlock_device bank;
+};
+
+/* Number of Hardware Spinlocks*/
+#define	HW_SPINLOCK_NUMBER	30
+
+/* Hardware spinlock register offsets */
+#define HW_SPINLOCK_BASE	0x404
+#define HW_SPINLOCK_OFFSET(x)	(HW_SPINLOCK_BASE + 0x4 * (x))
+
+static int sirf_hwspinlock_trylock(struct hwspinlock *lock)
+{
+	void __iomem *lock_addr = lock->priv;
+
+	/* attempt to acquire the lock by reading value == 1 from it */
+	return !!readl(lock_addr);
+}
+
+static void sirf_hwspinlock_unlock(struct hwspinlock *lock)
+{
+	void __iomem *lock_addr = lock->priv;
+
+	/* release the lock by writing 0 to it */
+	writel(0, lock_addr);
+}
+
+static const struct hwspinlock_ops sirf_hwspinlock_ops = {
+	.trylock = sirf_hwspinlock_trylock,
+	.unlock = sirf_hwspinlock_unlock,
+};
+
+static int sirf_hwspinlock_probe(struct platform_device *pdev)
+{
+	struct sirf_hwspinlock *hwspin;
+	struct hwspinlock *hwlock;
+	int idx, ret;
+
+	if (!pdev->dev.of_node)
+		return -ENODEV;

drivers/hwspinlock/sirf_hwspinlock.c line 73

Quoted 10 lines
drivers/hwspinlock/sirf_hwspinlock.c new file +10 -0
+
+	hwspin = devm_kzalloc(&pdev->dev, sizeof(*hwspin) +
+			sizeof(*hwlock) * HW_SPINLOCK_NUMBER, GFP_KERNEL);
+	if (!hwspin)
+		return -ENOMEM;
+
+	/* retrieve io base */
+	hwspin->io_base = of_iomap(pdev->dev.of_node, 0);
+	if (!hwspin->io_base)
+		ret = -ENOMEM;

You are missing the bail out here.

drivers/hwspinlock/sirf_hwspinlock.c line 85

Quoted 12 lines
drivers/hwspinlock/sirf_hwspinlock.c new file +12 -0
+
+	for (idx = 0; idx < HW_SPINLOCK_NUMBER; idx++) {
+		hwlock = &hwspin->bank.lock[idx];
+		hwlock->priv = hwspin->io_base + HW_SPINLOCK_OFFSET(idx);
+	}
+
+	platform_set_drvdata(pdev, hwspin);
+
+	pm_runtime_enable(&pdev->dev);
+
+	ret = hwspin_lock_register(&hwspin->bank, &pdev->dev,
+				&sirf_hwspinlock_ops, 0, HW_SPINLOCK_NUMBER);

this is a checkpatch warning with the --strict option, not sure what convention Ohad is following though. Rest looks good.

regards
Suman
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#7 lore raw

2015-05-23 6:51 GMT+08:00 Suman Anna <[email protected]>:

Quoted 139 lines

Hi Barry,

Quoted 66 lines · Barry Song

From: Wei Chen <[email protected]>

Add hwspinlock support for the CSR atlas7 SoC.

The Hardware Spinlock device on atlas7 provides hardware assistance for synchronization between the multiple processors in the system (dual Cortex-A7, CAN bus Cortex-M3 and audio DSP).

Cc Suman Anna <[email protected]>
Cc Bjorn Andersson <bjorn-UYDU3/[email protected]>

---
-v3:
use #hwlock-cells and general hwspinlock dt-binding; drop relax();
drop num-spinlocks in dts;
re-order Kconfig and Makefile;
other codingstyle issues.
Thanks Suman, Bjorn and Ohad

 drivers/hwspinlock/Kconfig           |  12 ++++
 drivers/hwspinlock/Makefile          |   1 +
 drivers/hwspinlock/sirf_hwspinlock.c | 135 +++++++++++++++++++++++++++++++++++
 3 files changed, 148 insertions(+)
 create mode 100644 drivers/hwspinlock/sirf_hwspinlock.c
drivers/hwspinlock/Kconfig +12 -0
index b5b4f52..73a4016 100644
@@ -30,6 +30,18 @@ config HWSPINLOCK_QCOM
 
        If unsure, say N.
 
+config HWSPINLOCK_SIRF
+     tristate "SIRF Hardware Spinlock device"
+     depends on ARCH_SIRF
+     select HWSPINLOCK
+     help
+       Say y here to support the SIRF Hardware Spinlock device, which
+       provides a synchronisation mechanism for the various processors
+       on the SoC.
+
+       It's safe to say n here if you're not interested in SIRF hardware
+       spinlock or just want a bare minimum kernel.
+
 config HSEM_U8500
      tristate "STE Hardware Semaphore functionality"
      depends on ARCH_U8500
drivers/hwspinlock/Makefile +1 -0
index 68f95d9..6b59cb5a 100644
@@ -5,4 +5,5 @@
 obj-$(CONFIG_HWSPINLOCK)             += hwspinlock_core.o
 obj-$(CONFIG_HWSPINLOCK_OMAP)                += omap_hwspinlock.o
 obj-$(CONFIG_HWSPINLOCK_QCOM)                += qcom_hwspinlock.o
+obj-$(CONFIG_HWSPINLOCK_SIRF)                += sirf_hwspinlock.o
 obj-$(CONFIG_HSEM_U8500)             += u8500_hsem.o
drivers/hwspinlock/sirf_hwspinlock.c new file +0 -0
new file mode 100644
index 0000000..e7e5ba6

drivers/hwspinlock/sirf_hwspinlock.c line 4

Quoted 4 lines
drivers/hwspinlock/sirf_hwspinlock.c new file +4 -0
@@ -0,0 +1,135 @@
+/*
+ * SIRF hardware spinlock driver
+ *
+ * Copyright (c) 2014 Cambridge Silicon Radio Limited, a CSR plc group company.

Not sure on this, but 2015 is here and now..

Quoted 63 lines
drivers/hwspinlock/sirf_hwspinlock.c new file +63 -0
+ *
+ * Licensed under GPLv2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/io.h>
+#include <linux/pm_runtime.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/hwspinlock.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+
+#include "hwspinlock_internal.h"
+
+struct sirf_hwspinlock {
+     void __iomem *io_base;
+     struct hwspinlock_device bank;
+};
+
+/* Number of Hardware Spinlocks*/
+#define      HW_SPINLOCK_NUMBER      30
+
+/* Hardware spinlock register offsets */
+#define HW_SPINLOCK_BASE     0x404
+#define HW_SPINLOCK_OFFSET(x)        (HW_SPINLOCK_BASE + 0x4 * (x))
+
+static int sirf_hwspinlock_trylock(struct hwspinlock *lock)
+{
+     void __iomem *lock_addr = lock->priv;
+
+     /* attempt to acquire the lock by reading value == 1 from it */
+     return !!readl(lock_addr);
+}
+
+static void sirf_hwspinlock_unlock(struct hwspinlock *lock)
+{
+     void __iomem *lock_addr = lock->priv;
+
+     /* release the lock by writing 0 to it */
+     writel(0, lock_addr);
+}
+
+static const struct hwspinlock_ops sirf_hwspinlock_ops = {
+     .trylock = sirf_hwspinlock_trylock,
+     .unlock = sirf_hwspinlock_unlock,
+};
+
+static int sirf_hwspinlock_probe(struct platform_device *pdev)
+{
+     struct sirf_hwspinlock *hwspin;
+     struct hwspinlock *hwlock;
+     int idx, ret;
+
+     if (!pdev->dev.of_node)
+             return -ENODEV;
+
+     hwspin = devm_kzalloc(&pdev->dev, sizeof(*hwspin) +
+                     sizeof(*hwlock) * HW_SPINLOCK_NUMBER, GFP_KERNEL);
+     if (!hwspin)
Quoted 8 lines

drivers/hwspinlock/sirf_hwspinlock.c line 73

Quoted 6 lines
drivers/hwspinlock/sirf_hwspinlock.c new file +6 -0
+             return -ENOMEM;
+
+     /* retrieve io base */
+     hwspin->io_base = of_iomap(pdev->dev.of_node, 0);
+     if (!hwspin->io_base)
+             ret = -ENOMEM;

You are missing the bail out here.

real. it should be "return -ENOMEM"

Quoted 16 lines

drivers/hwspinlock/sirf_hwspinlock.c line 85

Quoted 13 lines
drivers/hwspinlock/sirf_hwspinlock.c new file +12 -0
+
+     for (idx = 0; idx < HW_SPINLOCK_NUMBER; idx++) {
+             hwlock = &hwspin->bank.lock[idx];
+             hwlock->priv = hwspin->io_base + HW_SPINLOCK_OFFSET(idx);
+     }
+
+     platform_set_drvdata(pdev, hwspin);
+
+     pm_runtime_enable(&pdev->dev);
+
+     ret = hwspin_lock_register(&hwspin->bank, &pdev->dev,
+                             &sirf_hwspinlock_ops, 0, HW_SPINLOCK_NUMBER);

this is a checkpatch warning with the --strict option, not sure what convention Ohad is following though. Rest looks good.

do you mean this CHECK?

CHECK: Alignment should match open parenthesis #87: FILE: drivers/hwspinlock/sirf_hwspinlock.c:87:
+ ret = hwspin_lock_register(&hwspin->bank, &pdev->dev,
+ &sirf_hwspinlock_ops, 0, HW_SPINLOCK_NUMBER);

Quoted 3 lines

regards
Suman

-barry
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw
Quoted 168 lines · Barry Song

2015-05-23 6:51 GMT+08:00 Suman Anna <[email protected]>:

Quoted 139 lines

Hi Barry,

Quoted 66 lines · Barry Song

From: Wei Chen <[email protected]>

Add hwspinlock support for the CSR atlas7 SoC.

The Hardware Spinlock device on atlas7 provides hardware assistance for synchronization between the multiple processors in the system (dual Cortex-A7, CAN bus Cortex-M3 and audio DSP).

Cc Suman Anna <[email protected]>
Cc Bjorn Andersson <[email protected]>

---
-v3:
use #hwlock-cells and general hwspinlock dt-binding; drop relax();
drop num-spinlocks in dts;
re-order Kconfig and Makefile;
other codingstyle issues.
Thanks Suman, Bjorn and Ohad

 drivers/hwspinlock/Kconfig           |  12 ++++
 drivers/hwspinlock/Makefile          |   1 +
 drivers/hwspinlock/sirf_hwspinlock.c | 135 +++++++++++++++++++++++++++++++++++
 3 files changed, 148 insertions(+)
 create mode 100644 drivers/hwspinlock/sirf_hwspinlock.c
drivers/hwspinlock/Kconfig +12 -0
index b5b4f52..73a4016 100644
@@ -30,6 +30,18 @@ config HWSPINLOCK_QCOM
 
        If unsure, say N.
 
+config HWSPINLOCK_SIRF
+     tristate "SIRF Hardware Spinlock device"
+     depends on ARCH_SIRF
+     select HWSPINLOCK
+     help
+       Say y here to support the SIRF Hardware Spinlock device, which
+       provides a synchronisation mechanism for the various processors
+       on the SoC.
+
+       It's safe to say n here if you're not interested in SIRF hardware
+       spinlock or just want a bare minimum kernel.
+
 config HSEM_U8500
      tristate "STE Hardware Semaphore functionality"
      depends on ARCH_U8500
drivers/hwspinlock/Makefile +1 -0
index 68f95d9..6b59cb5a 100644
@@ -5,4 +5,5 @@
 obj-$(CONFIG_HWSPINLOCK)             += hwspinlock_core.o
 obj-$(CONFIG_HWSPINLOCK_OMAP)                += omap_hwspinlock.o
 obj-$(CONFIG_HWSPINLOCK_QCOM)                += qcom_hwspinlock.o
+obj-$(CONFIG_HWSPINLOCK_SIRF)                += sirf_hwspinlock.o
 obj-$(CONFIG_HSEM_U8500)             += u8500_hsem.o
drivers/hwspinlock/sirf_hwspinlock.c new file +0 -0
new file mode 100644
index 0000000..e7e5ba6

drivers/hwspinlock/sirf_hwspinlock.c line 4

Quoted 4 lines
drivers/hwspinlock/sirf_hwspinlock.c new file +4 -0
@@ -0,0 +1,135 @@
+/*
+ * SIRF hardware spinlock driver
+ *
+ * Copyright (c) 2014 Cambridge Silicon Radio Limited, a CSR plc group company.

Not sure on this, but 2015 is here and now..

Quoted 63 lines
drivers/hwspinlock/sirf_hwspinlock.c new file +63 -0
+ *
+ * Licensed under GPLv2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/io.h>
+#include <linux/pm_runtime.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/hwspinlock.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+
+#include "hwspinlock_internal.h"
+
+struct sirf_hwspinlock {
+     void __iomem *io_base;
+     struct hwspinlock_device bank;
+};
+
+/* Number of Hardware Spinlocks*/
+#define      HW_SPINLOCK_NUMBER      30
+
+/* Hardware spinlock register offsets */
+#define HW_SPINLOCK_BASE     0x404
+#define HW_SPINLOCK_OFFSET(x)        (HW_SPINLOCK_BASE + 0x4 * (x))
+
+static int sirf_hwspinlock_trylock(struct hwspinlock *lock)
+{
+     void __iomem *lock_addr = lock->priv;
+
+     /* attempt to acquire the lock by reading value == 1 from it */
+     return !!readl(lock_addr);
+}
+
+static void sirf_hwspinlock_unlock(struct hwspinlock *lock)
+{
+     void __iomem *lock_addr = lock->priv;
+
+     /* release the lock by writing 0 to it */
+     writel(0, lock_addr);
+}
+
+static const struct hwspinlock_ops sirf_hwspinlock_ops = {
+     .trylock = sirf_hwspinlock_trylock,
+     .unlock = sirf_hwspinlock_unlock,
+};
+
+static int sirf_hwspinlock_probe(struct platform_device *pdev)
+{
+     struct sirf_hwspinlock *hwspin;
+     struct hwspinlock *hwlock;
+     int idx, ret;
+
+     if (!pdev->dev.of_node)
+             return -ENODEV;
+
+     hwspin = devm_kzalloc(&pdev->dev, sizeof(*hwspin) +
+                     sizeof(*hwlock) * HW_SPINLOCK_NUMBER, GFP_KERNEL);
+     if (!hwspin)
Quoted 8 lines

drivers/hwspinlock/sirf_hwspinlock.c line 73

Quoted 6 lines
drivers/hwspinlock/sirf_hwspinlock.c new file +6 -0
+             return -ENOMEM;
+
+     /* retrieve io base */
+     hwspin->io_base = of_iomap(pdev->dev.of_node, 0);
+     if (!hwspin->io_base)
+             ret = -ENOMEM;

You are missing the bail out here.

real. it should be "return -ENOMEM"

Quoted 16 lines

drivers/hwspinlock/sirf_hwspinlock.c line 85

Quoted 13 lines
drivers/hwspinlock/sirf_hwspinlock.c new file +12 -0
+
+     for (idx = 0; idx < HW_SPINLOCK_NUMBER; idx++) {
+             hwlock = &hwspin->bank.lock[idx];
+             hwlock->priv = hwspin->io_base + HW_SPINLOCK_OFFSET(idx);
+     }
+
+     platform_set_drvdata(pdev, hwspin);
+
+     pm_runtime_enable(&pdev->dev);
+
+     ret = hwspin_lock_register(&hwspin->bank, &pdev->dev,
+                             &sirf_hwspinlock_ops, 0, HW_SPINLOCK_NUMBER);

this is a checkpatch warning with the --strict option, not sure what convention Ohad is following though. Rest looks good.

Quoted 6 lines

do you mean this CHECK?

CHECK: Alignment should match open parenthesis #87: FILE: drivers/hwspinlock/sirf_hwspinlock.c:87:
+ ret = hwspin_lock_register(&hwspin->bank, &pdev->dev,
+ &sirf_hwspinlock_ops, 0, HW_SPINLOCK_NUMBER);

Yes.

regards
Suman