Re: [PATCH v2] hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

2014-09-02 Thread Bjorn Andersson
On Tue 02 Sep 10:28 PDT 2014, Jeffrey Hugo wrote:

> > diff --git a/drivers/hwspinlock/msm_hwspinlock.c 
> > b/drivers/hwspinlock/msm_hwspinlock.c
[..]
> > + * Copyright (c) 2013, The Linux Foundation. All rights reserved.
> 
> Should the copyright range be updated to include your changes which I 
> presume were authored in 2014?
> 

That would be expected by people on my side, will update.

[..]
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> 
> Could these be put in alphabetical order?  I vaguely recall a few 
> maintainers expressing this preference to avoid merge issues.
> 

I think we can clean some of them out at least, will have a look.

[..]
> > +static int msm_hwspinlock_probe(struct platform_device *pdev)
> > +{
[..]
> > +   match = of_match_device(msm_hwspinlock_of_match, >dev);
> > +   if (!match)
> > +   return -EINVAL;
> 
> This seems redundant.  It is my understanding that probe will only be 
> called for a matching device.  What are we attempting to accomplish here?
> 

Yeah, if anything it would catch static bugs.

And with the modification below I'll just drop it.

[..]
> > +   stride = (int)match->data;
> > +   for (i = 0, hwlock = >lock[0]; i < num_locks; i++, hwlock++)
> > +   hwlock->priv = iobase + i * stride;
> 
> I am not a fan of this method for determining the stride.  We already 
> have 0x4 and 0x80 in this driver, and will soon need 0x1000 for some of 
> the current chips (still listed as TCSR too).  The stride is completely 
> up to our hardware designers, and it seems like encoding stride in this 
> manner will require constant updates and maintenance.  I prefer 
> calculating stride by dividing the reg size by num_locks since that will 
> automatically adjust for whatever the hardware designers decide to use 
> next month.  If you wanted to, with the reg size calculation, you could 
> remove the "qcom,sfpb-mutex" since there is no functional difference 
> other than stride.  What are your thoughts?
> 

I was thinking about this before and with your addition of tcsr having
different strides on different platforms we could either make the compatibles
more specifc (e.g. include platform name) or encode the stride in some other
way.

As you say there's no real technical difference in how we interact with the
current sfpb and tcsr mutex registers, so I would say making the compatibles
more specifc doesn't add any value.

I'll update this and follow your recommendation.



When we started hacking on this we found it very confusing that the caf driver
for tcsr is called sfpb, so I will keep both compatibles for clarity...

Thanks for your input!

Regards,
Bjorn
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

2014-09-02 Thread Jeffrey Hugo

On 8/29/2014 5:14 PM, Bjorn Andersson wrote:

From: Kumar Gala 

Add driver for Qualcomm MSM Hardware Mutex block that exists on
newer Qualcomm SoCs.

Cc: Jeffrey Hugo 
Cc: Eric Holmberg 
Cc: Courtney Cavin 
Signed-off-by: Kumar Gala 
[bjorn: added pm_runtime calls, from Courtney,
added sfpb-mutex compatible,
updated DT binding documentation formatting]
Signed-off-by: Bjorn Andersson 
---

[...]

diff --git a/drivers/hwspinlock/msm_hwspinlock.c 
b/drivers/hwspinlock/msm_hwspinlock.c
new file mode 100644
index 000..9ddd020
--- /dev/null
+++ b/drivers/hwspinlock/msm_hwspinlock.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.


Should the copyright range be updated to include your changes which I 
presume were authored in 2014?



+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 


Could these be put in alphabetical order?  I vaguely recall a few 
maintainers expressing this preference to avoid merge issues.



+
+#include "hwspinlock_internal.h"
+
+#define SPINLOCK_ID_APPS_PROC  1
+#define BASE_ID0

[...]

+static int msm_hwspinlock_probe(struct platform_device *pdev)
+{
+   int ret, i, stride;
+   size_t array_size;
+   u32 num_locks;
+   struct hwspinlock_device *bank;
+   struct hwspinlock *hwlock;
+   struct resource *res;
+   void __iomem *iobase;
+   struct device_node *node = pdev->dev.of_node;
+   const struct of_device_id *match;
+
+   match = of_match_device(msm_hwspinlock_of_match, >dev);
+   if (!match)
+   return -EINVAL;


This seems redundant.  It is my understanding that probe will only be 
called for a matching device.  What are we attempting to accomplish here?



+
+   ret = of_property_read_u32(node, "qcom,num-locks", _locks);
+   if (ret || num_locks == 0)
+   return -ENODEV;
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mutex-base");
+   iobase = devm_ioremap_resource(>dev, res);
+   if (IS_ERR(iobase))
+   return PTR_ERR(iobase);
+
+   array_size = num_locks * sizeof(*hwlock);
+   bank = devm_kzalloc(>dev, sizeof(*bank) + array_size, GFP_KERNEL);
+   if (!bank)
+   return -ENOMEM;
+
+   platform_set_drvdata(pdev, bank);
+
+   stride = (int)match->data;
+   for (i = 0, hwlock = >lock[0]; i < num_locks; i++, hwlock++)
+   hwlock->priv = iobase + i * stride;


I am not a fan of this method for determining the stride.  We already 
have 0x4 and 0x80 in this driver, and will soon need 0x1000 for some of 
the current chips (still listed as TCSR too).  The stride is completely 
up to our hardware designers, and it seems like encoding stride in this 
manner will require constant updates and maintenance.  I prefer 
calculating stride by dividing the reg size by num_locks since that will 
automatically adjust for whatever the hardware designers decide to use 
next month.  If you wanted to, with the reg size calculation, you could 
remove the "qcom,sfpb-mutex" since there is no functional difference 
other than stride.  What are your thoughts?



+
+   pm_runtime_enable(>dev);
+
+   ret = hwspin_lock_register(bank, >dev, _hwspinlock_ops,
+   BASE_ID, num_locks);
+   if (ret)
+   pm_runtime_disable(>dev);
+
+   return ret;
+}

[...]


Jeffrey Hugo
--
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
hosted by The Linux Foundation.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

2014-09-02 Thread Jeffrey Hugo

On 8/29/2014 5:14 PM, Bjorn Andersson wrote:

From: Kumar Gala ga...@codeaurora.org

Add driver for Qualcomm MSM Hardware Mutex block that exists on
newer Qualcomm SoCs.

Cc: Jeffrey Hugo jh...@codeaurora.org
Cc: Eric Holmberg eholm...@codeaurora.org
Cc: Courtney Cavin courtney.ca...@sonymobile.com
Signed-off-by: Kumar Gala ga...@codeaurora.org
[bjorn: added pm_runtime calls, from Courtney,
added sfpb-mutex compatible,
updated DT binding documentation formatting]
Signed-off-by: Bjorn Andersson bjorn.anders...@sonymobile.com
---

[...]

diff --git a/drivers/hwspinlock/msm_hwspinlock.c 
b/drivers/hwspinlock/msm_hwspinlock.c
new file mode 100644
index 000..9ddd020
--- /dev/null
+++ b/drivers/hwspinlock/msm_hwspinlock.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.


Should the copyright range be updated to include your changes which I 
presume were authored in 2014?



+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/err.h
+#include linux/kernel.h
+#include linux/slab.h
+#include linux/device.h
+#include linux/module.h
+#include linux/platform_device.h
+#include linux/pm_runtime.h
+#include linux/of.h
+#include linux/of_address.h
+#include linux/of_device.h
+#include linux/hwspinlock.h
+#include linux/io.h


Could these be put in alphabetical order?  I vaguely recall a few 
maintainers expressing this preference to avoid merge issues.



+
+#include hwspinlock_internal.h
+
+#define SPINLOCK_ID_APPS_PROC  1
+#define BASE_ID0

[...]

+static int msm_hwspinlock_probe(struct platform_device *pdev)
+{
+   int ret, i, stride;
+   size_t array_size;
+   u32 num_locks;
+   struct hwspinlock_device *bank;
+   struct hwspinlock *hwlock;
+   struct resource *res;
+   void __iomem *iobase;
+   struct device_node *node = pdev-dev.of_node;
+   const struct of_device_id *match;
+
+   match = of_match_device(msm_hwspinlock_of_match, pdev-dev);
+   if (!match)
+   return -EINVAL;


This seems redundant.  It is my understanding that probe will only be 
called for a matching device.  What are we attempting to accomplish here?



+
+   ret = of_property_read_u32(node, qcom,num-locks, num_locks);
+   if (ret || num_locks == 0)
+   return -ENODEV;
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_MEM, mutex-base);
+   iobase = devm_ioremap_resource(pdev-dev, res);
+   if (IS_ERR(iobase))
+   return PTR_ERR(iobase);
+
+   array_size = num_locks * sizeof(*hwlock);
+   bank = devm_kzalloc(pdev-dev, sizeof(*bank) + array_size, GFP_KERNEL);
+   if (!bank)
+   return -ENOMEM;
+
+   platform_set_drvdata(pdev, bank);
+
+   stride = (int)match-data;
+   for (i = 0, hwlock = bank-lock[0]; i  num_locks; i++, hwlock++)
+   hwlock-priv = iobase + i * stride;


I am not a fan of this method for determining the stride.  We already 
have 0x4 and 0x80 in this driver, and will soon need 0x1000 for some of 
the current chips (still listed as TCSR too).  The stride is completely 
up to our hardware designers, and it seems like encoding stride in this 
manner will require constant updates and maintenance.  I prefer 
calculating stride by dividing the reg size by num_locks since that will 
automatically adjust for whatever the hardware designers decide to use 
next month.  If you wanted to, with the reg size calculation, you could 
remove the qcom,sfpb-mutex since there is no functional difference 
other than stride.  What are your thoughts?



+
+   pm_runtime_enable(pdev-dev);
+
+   ret = hwspin_lock_register(bank, pdev-dev, msm_hwspinlock_ops,
+   BASE_ID, num_locks);
+   if (ret)
+   pm_runtime_disable(pdev-dev);
+
+   return ret;
+}

[...]


Jeffrey Hugo
--
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
hosted by The Linux Foundation.

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

2014-09-02 Thread Bjorn Andersson
On Tue 02 Sep 10:28 PDT 2014, Jeffrey Hugo wrote:

  diff --git a/drivers/hwspinlock/msm_hwspinlock.c 
  b/drivers/hwspinlock/msm_hwspinlock.c
[..]
  + * Copyright (c) 2013, The Linux Foundation. All rights reserved.
 
 Should the copyright range be updated to include your changes which I 
 presume were authored in 2014?
 

That would be expected by people on my side, will update.

[..]
  +
  +#include linux/err.h
  +#include linux/kernel.h
  +#include linux/slab.h
  +#include linux/device.h
  +#include linux/module.h
  +#include linux/platform_device.h
  +#include linux/pm_runtime.h
  +#include linux/of.h
  +#include linux/of_address.h
  +#include linux/of_device.h
  +#include linux/hwspinlock.h
  +#include linux/io.h
 
 Could these be put in alphabetical order?  I vaguely recall a few 
 maintainers expressing this preference to avoid merge issues.
 

I think we can clean some of them out at least, will have a look.

[..]
  +static int msm_hwspinlock_probe(struct platform_device *pdev)
  +{
[..]
  +   match = of_match_device(msm_hwspinlock_of_match, pdev-dev);
  +   if (!match)
  +   return -EINVAL;
 
 This seems redundant.  It is my understanding that probe will only be 
 called for a matching device.  What are we attempting to accomplish here?
 

Yeah, if anything it would catch static bugs.

And with the modification below I'll just drop it.

[..]
  +   stride = (int)match-data;
  +   for (i = 0, hwlock = bank-lock[0]; i  num_locks; i++, hwlock++)
  +   hwlock-priv = iobase + i * stride;
 
 I am not a fan of this method for determining the stride.  We already 
 have 0x4 and 0x80 in this driver, and will soon need 0x1000 for some of 
 the current chips (still listed as TCSR too).  The stride is completely 
 up to our hardware designers, and it seems like encoding stride in this 
 manner will require constant updates and maintenance.  I prefer 
 calculating stride by dividing the reg size by num_locks since that will 
 automatically adjust for whatever the hardware designers decide to use 
 next month.  If you wanted to, with the reg size calculation, you could 
 remove the qcom,sfpb-mutex since there is no functional difference 
 other than stride.  What are your thoughts?
 

I was thinking about this before and with your addition of tcsr having
different strides on different platforms we could either make the compatibles
more specifc (e.g. include platform name) or encode the stride in some other
way.

As you say there's no real technical difference in how we interact with the
current sfpb and tcsr mutex registers, so I would say making the compatibles
more specifc doesn't add any value.

I'll update this and follow your recommendation.



When we started hacking on this we found it very confusing that the caf driver
for tcsr is called sfpb, so I will keep both compatibles for clarity...

Thanks for your input!

Regards,
Bjorn
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

2014-08-29 Thread Courtney Cavin
On Sat, Aug 30, 2014 at 02:14:07AM +0200, Stephen Boyd wrote:
> On 08/29/14 16:41, Courtney Cavin wrote:
> > On Sat, Aug 30, 2014 at 01:14:23AM +0200, Bjorn Andersson wrote:
> >> From: Kumar Gala 
> >>
> >> Add driver for Qualcomm MSM Hardware Mutex block that exists on
> >> newer Qualcomm SoCs.
> >>
> >> Cc: Jeffrey Hugo 
> >> Cc: Eric Holmberg 
> >> Cc: Courtney Cavin 
> >> Signed-off-by: Kumar Gala 
> >> [bjorn: added pm_runtime calls, from Courtney,
> >>added sfpb-mutex compatible,
> >>updated DT binding documentation formatting]
> >> Signed-off-by: Bjorn Andersson 
> >> ---
> > [...]
> >> diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig
> >> index 3612cb5..2cd39e2 100644
> >> --- a/drivers/hwspinlock/Kconfig
> >> +++ b/drivers/hwspinlock/Kconfig
> >> @@ -8,6 +8,17 @@ config HWSPINLOCK
> >>  
> >>  menu "Hardware Spinlock drivers"
> >>  
> >> +config HWSPINLOCK_MSM
> >> +  tristate "MSM Hardware Spinlock device"
> >> +  depends on ARCH_QCOM
> > This should also depend on OF, as it won't compile or work without it.
> 
> Doesn't ARCH_QCOM imply OF? ARCH_MULTIPLATFORM has a select USE_OF.

Hrm.  Apparently.

-Courtney
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

2014-08-29 Thread Stephen Boyd
On 08/29/14 16:41, Courtney Cavin wrote:
> On Sat, Aug 30, 2014 at 01:14:23AM +0200, Bjorn Andersson wrote:
>> From: Kumar Gala 
>>
>> Add driver for Qualcomm MSM Hardware Mutex block that exists on
>> newer Qualcomm SoCs.
>>
>> Cc: Jeffrey Hugo 
>> Cc: Eric Holmberg 
>> Cc: Courtney Cavin 
>> Signed-off-by: Kumar Gala 
>> [bjorn: added pm_runtime calls, from Courtney,
>>  added sfpb-mutex compatible,
>>  updated DT binding documentation formatting]
>> Signed-off-by: Bjorn Andersson 
>> ---
> [...]
>> diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig
>> index 3612cb5..2cd39e2 100644
>> --- a/drivers/hwspinlock/Kconfig
>> +++ b/drivers/hwspinlock/Kconfig
>> @@ -8,6 +8,17 @@ config HWSPINLOCK
>>  
>>  menu "Hardware Spinlock drivers"
>>  
>> +config HWSPINLOCK_MSM
>> +tristate "MSM Hardware Spinlock device"
>> +depends on ARCH_QCOM
> This should also depend on OF, as it won't compile or work without it.

Doesn't ARCH_QCOM imply OF? ARCH_MULTIPLATFORM has a select USE_OF.

>
>> +select HWSPINLOCK
>> +help
>> +  Say y here to support the MSM Hardware Mutex functionality, which
>> +  provides a synchronisation mechanism for the various processors on
>> +  the SoC.
>> +
>> +  If unsure, say N.
>> +
>>

Maybe MSM should be changed to qcom? Just a thought.

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

2014-08-29 Thread Courtney Cavin
On Sat, Aug 30, 2014 at 01:14:23AM +0200, Bjorn Andersson wrote:
> From: Kumar Gala 
> 
> Add driver for Qualcomm MSM Hardware Mutex block that exists on
> newer Qualcomm SoCs.
> 
> Cc: Jeffrey Hugo 
> Cc: Eric Holmberg 
> Cc: Courtney Cavin 
> Signed-off-by: Kumar Gala 
> [bjorn: added pm_runtime calls, from Courtney,
>   added sfpb-mutex compatible,
>   updated DT binding documentation formatting]
> Signed-off-by: Bjorn Andersson 
> ---
[...]
> diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig
> index 3612cb5..2cd39e2 100644
> --- a/drivers/hwspinlock/Kconfig
> +++ b/drivers/hwspinlock/Kconfig
> @@ -8,6 +8,17 @@ config HWSPINLOCK
>  
>  menu "Hardware Spinlock drivers"
>  
> +config HWSPINLOCK_MSM
> + tristate "MSM Hardware Spinlock device"
> + depends on ARCH_QCOM

This should also depend on OF, as it won't compile or work without it.

> + select HWSPINLOCK
> + help
> +   Say y here to support the MSM Hardware Mutex functionality, which
> +   provides a synchronisation mechanism for the various processors on
> +   the SoC.
> +
> +   If unsure, say N.
> +
>  config HWSPINLOCK_OMAP
>   tristate "OMAP Hardware Spinlock device"
>   depends on ARCH_OMAP4 || SOC_OMAP5 || SOC_DRA7XX || SOC_AM33XX || 
> SOC_AM43XX
[...]
> +static const struct of_device_id msm_hwspinlock_of_match[] = {
> + { .compatible = "qcom,sfpb-mutex", .data = (void *)0x4 },
> + { .compatible = "qcom,tcsr-mutex", .data = (void *)0x80 },
> + { },
> +};

MODULE_DEVICE_TABLE(of, msm_hwspinlock_of_match); ?

[...]
> +static struct platform_driver msm_hwspinlock_driver = {
> + .probe  = msm_hwspinlock_probe,
> + .remove = msm_hwspinlock_remove,
> + .driver = {
> + .name   = "msm_hwspinlock",
> + .owner  = THIS_MODULE,

No need, as:

#define platform_driver_register(drv) \
__platform_driver_register(drv, THIS_MODULE)
extern int __platform_driver_register(struct platform_driver *,
struct module *);

> + .of_match_table = msm_hwspinlock_of_match,
> + },
> +};

Otherwise, looks fine.

-Courtney
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

2014-08-29 Thread Bjorn Andersson
From: Kumar Gala 

Add driver for Qualcomm MSM Hardware Mutex block that exists on
newer Qualcomm SoCs.

Cc: Jeffrey Hugo 
Cc: Eric Holmberg 
Cc: Courtney Cavin 
Signed-off-by: Kumar Gala 
[bjorn: added pm_runtime calls, from Courtney,
added sfpb-mutex compatible,
updated DT binding documentation formatting]
Signed-off-by: Bjorn Andersson 
---

We need this driver to add support for the shared memory manager, so I'm
reviving Kumars patch from a year ago, with some additional sprinkles on top.

Changes since v1:
 - Added the pm_runtime calls needed to be able to boot a kernel with
   pm_runtime and this driver, patch from Courtney.
 - Added sfpb-mutex compatible, for re-use of the driver in family A platforms.
 - Updated formatting of DT binding documentation, while adding the extra
   compatible.
 - Dropped Stephen Boyds Reviewed-by due to these changes.

 .../devicetree/bindings/hwlock/msm-hwspinlock.txt  |  35 +
 drivers/hwspinlock/Kconfig |  11 ++
 drivers/hwspinlock/Makefile|   1 +
 drivers/hwspinlock/msm_hwspinlock.c| 155 +
 4 files changed, 202 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwlock/msm-hwspinlock.txt
 create mode 100644 drivers/hwspinlock/msm_hwspinlock.c

diff --git a/Documentation/devicetree/bindings/hwlock/msm-hwspinlock.txt 
b/Documentation/devicetree/bindings/hwlock/msm-hwspinlock.txt
new file mode 100644
index 000..65d9ab0
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwlock/msm-hwspinlock.txt
@@ -0,0 +1,35 @@
+Qualcomm MSM Hardware Mutex Block:
+
+The hardware block provides mutexes utilized between different processors
+on the SoC as part of the communication protocol used by these processors.
+
+- compatible:
+   Usage: required
+   Value type: 
+   Definition: must be one of:
+   "qcom,sfpb-mutex",
+   "qcom,tcsr-mutex"
+
+- reg:
+   Usage: required
+   Value type: 
+   Definition: base address and size of the mutex registers
+
+- reg-names:
+   Usage: required
+   Value type: 
+   Definition: must be "mutex-base"
+
+- qcom,num-locks:
+   Usage: required
+   Value type: 
+   Definition: the number of locks/mutex available in this block
+
+Example:
+
+   hwlock@fd484000 {
+   compatible = "qcom,tcsr-mutex";
+   reg = <0xfd484000 0x1000>;
+   reg-names = "mutex-base";
+   qcom,num-locks = <32>;
+   };
diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig
index 3612cb5..2cd39e2 100644
--- a/drivers/hwspinlock/Kconfig
+++ b/drivers/hwspinlock/Kconfig
@@ -8,6 +8,17 @@ config HWSPINLOCK
 
 menu "Hardware Spinlock drivers"
 
+config HWSPINLOCK_MSM
+   tristate "MSM Hardware Spinlock device"
+   depends on ARCH_QCOM
+   select HWSPINLOCK
+   help
+ Say y here to support the MSM Hardware Mutex functionality, which
+ provides a synchronisation mechanism for the various processors on
+ the SoC.
+
+ If unsure, say N.
+
 config HWSPINLOCK_OMAP
tristate "OMAP Hardware Spinlock device"
depends on ARCH_OMAP4 || SOC_OMAP5 || SOC_DRA7XX || SOC_AM33XX || 
SOC_AM43XX
diff --git a/drivers/hwspinlock/Makefile b/drivers/hwspinlock/Makefile
index 93eb64b..4074c56 100644
--- a/drivers/hwspinlock/Makefile
+++ b/drivers/hwspinlock/Makefile
@@ -3,5 +3,6 @@
 #
 
 obj-$(CONFIG_HWSPINLOCK)   += hwspinlock_core.o
+obj-$(CONFIG_HWSPINLOCK_MSM)   += msm_hwspinlock.o
 obj-$(CONFIG_HWSPINLOCK_OMAP)  += omap_hwspinlock.o
 obj-$(CONFIG_HSEM_U8500)   += u8500_hsem.o
diff --git a/drivers/hwspinlock/msm_hwspinlock.c 
b/drivers/hwspinlock/msm_hwspinlock.c
new file mode 100644
index 000..9ddd020
--- /dev/null
+++ b/drivers/hwspinlock/msm_hwspinlock.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hwspinlock_internal.h"
+
+#define SPINLOCK_ID_APPS_PROC  1
+#define BASE_ID0
+
+static int msm_hwspinlock_trylock(struct hwspinlock *lock)
+{
+   void __iomem *lock_addr = lock->priv;
+
+   writel_relaxed(SPINLOCK_ID_APPS_PROC, lock_addr);
+
+   return readl_relaxed(lock_addr) == SPINLOCK_ID_APPS_PROC;
+}
+
+static void msm_hwspinlock_unlock(struct 

[PATCH v2] hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

2014-08-29 Thread Bjorn Andersson
From: Kumar Gala ga...@codeaurora.org

Add driver for Qualcomm MSM Hardware Mutex block that exists on
newer Qualcomm SoCs.

Cc: Jeffrey Hugo jh...@codeaurora.org
Cc: Eric Holmberg eholm...@codeaurora.org
Cc: Courtney Cavin courtney.ca...@sonymobile.com
Signed-off-by: Kumar Gala ga...@codeaurora.org
[bjorn: added pm_runtime calls, from Courtney,
added sfpb-mutex compatible,
updated DT binding documentation formatting]
Signed-off-by: Bjorn Andersson bjorn.anders...@sonymobile.com
---

We need this driver to add support for the shared memory manager, so I'm
reviving Kumars patch from a year ago, with some additional sprinkles on top.

Changes since v1:
 - Added the pm_runtime calls needed to be able to boot a kernel with
   pm_runtime and this driver, patch from Courtney.
 - Added sfpb-mutex compatible, for re-use of the driver in family A platforms.
 - Updated formatting of DT binding documentation, while adding the extra
   compatible.
 - Dropped Stephen Boyds Reviewed-by due to these changes.

 .../devicetree/bindings/hwlock/msm-hwspinlock.txt  |  35 +
 drivers/hwspinlock/Kconfig |  11 ++
 drivers/hwspinlock/Makefile|   1 +
 drivers/hwspinlock/msm_hwspinlock.c| 155 +
 4 files changed, 202 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwlock/msm-hwspinlock.txt
 create mode 100644 drivers/hwspinlock/msm_hwspinlock.c

diff --git a/Documentation/devicetree/bindings/hwlock/msm-hwspinlock.txt 
b/Documentation/devicetree/bindings/hwlock/msm-hwspinlock.txt
new file mode 100644
index 000..65d9ab0
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwlock/msm-hwspinlock.txt
@@ -0,0 +1,35 @@
+Qualcomm MSM Hardware Mutex Block:
+
+The hardware block provides mutexes utilized between different processors
+on the SoC as part of the communication protocol used by these processors.
+
+- compatible:
+   Usage: required
+   Value type: string
+   Definition: must be one of:
+   qcom,sfpb-mutex,
+   qcom,tcsr-mutex
+
+- reg:
+   Usage: required
+   Value type: prop-encoded-array
+   Definition: base address and size of the mutex registers
+
+- reg-names:
+   Usage: required
+   Value type: string
+   Definition: must be mutex-base
+
+- qcom,num-locks:
+   Usage: required
+   Value type: u32
+   Definition: the number of locks/mutex available in this block
+
+Example:
+
+   hwlock@fd484000 {
+   compatible = qcom,tcsr-mutex;
+   reg = 0xfd484000 0x1000;
+   reg-names = mutex-base;
+   qcom,num-locks = 32;
+   };
diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig
index 3612cb5..2cd39e2 100644
--- a/drivers/hwspinlock/Kconfig
+++ b/drivers/hwspinlock/Kconfig
@@ -8,6 +8,17 @@ config HWSPINLOCK
 
 menu Hardware Spinlock drivers
 
+config HWSPINLOCK_MSM
+   tristate MSM Hardware Spinlock device
+   depends on ARCH_QCOM
+   select HWSPINLOCK
+   help
+ Say y here to support the MSM Hardware Mutex functionality, which
+ provides a synchronisation mechanism for the various processors on
+ the SoC.
+
+ If unsure, say N.
+
 config HWSPINLOCK_OMAP
tristate OMAP Hardware Spinlock device
depends on ARCH_OMAP4 || SOC_OMAP5 || SOC_DRA7XX || SOC_AM33XX || 
SOC_AM43XX
diff --git a/drivers/hwspinlock/Makefile b/drivers/hwspinlock/Makefile
index 93eb64b..4074c56 100644
--- a/drivers/hwspinlock/Makefile
+++ b/drivers/hwspinlock/Makefile
@@ -3,5 +3,6 @@
 #
 
 obj-$(CONFIG_HWSPINLOCK)   += hwspinlock_core.o
+obj-$(CONFIG_HWSPINLOCK_MSM)   += msm_hwspinlock.o
 obj-$(CONFIG_HWSPINLOCK_OMAP)  += omap_hwspinlock.o
 obj-$(CONFIG_HSEM_U8500)   += u8500_hsem.o
diff --git a/drivers/hwspinlock/msm_hwspinlock.c 
b/drivers/hwspinlock/msm_hwspinlock.c
new file mode 100644
index 000..9ddd020
--- /dev/null
+++ b/drivers/hwspinlock/msm_hwspinlock.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/err.h
+#include linux/kernel.h
+#include linux/slab.h
+#include linux/device.h
+#include linux/module.h
+#include linux/platform_device.h
+#include linux/pm_runtime.h
+#include linux/of.h
+#include linux/of_address.h
+#include linux/of_device.h
+#include linux/hwspinlock.h
+#include linux/io.h
+
+#include hwspinlock_internal.h
+
+#define SPINLOCK_ID_APPS_PROC  1

Re: [PATCH v2] hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

2014-08-29 Thread Courtney Cavin
On Sat, Aug 30, 2014 at 01:14:23AM +0200, Bjorn Andersson wrote:
 From: Kumar Gala ga...@codeaurora.org
 
 Add driver for Qualcomm MSM Hardware Mutex block that exists on
 newer Qualcomm SoCs.
 
 Cc: Jeffrey Hugo jh...@codeaurora.org
 Cc: Eric Holmberg eholm...@codeaurora.org
 Cc: Courtney Cavin courtney.ca...@sonymobile.com
 Signed-off-by: Kumar Gala ga...@codeaurora.org
 [bjorn: added pm_runtime calls, from Courtney,
   added sfpb-mutex compatible,
   updated DT binding documentation formatting]
 Signed-off-by: Bjorn Andersson bjorn.anders...@sonymobile.com
 ---
[...]
 diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig
 index 3612cb5..2cd39e2 100644
 --- a/drivers/hwspinlock/Kconfig
 +++ b/drivers/hwspinlock/Kconfig
 @@ -8,6 +8,17 @@ config HWSPINLOCK
  
  menu Hardware Spinlock drivers
  
 +config HWSPINLOCK_MSM
 + tristate MSM Hardware Spinlock device
 + depends on ARCH_QCOM

This should also depend on OF, as it won't compile or work without it.

 + select HWSPINLOCK
 + help
 +   Say y here to support the MSM Hardware Mutex functionality, which
 +   provides a synchronisation mechanism for the various processors on
 +   the SoC.
 +
 +   If unsure, say N.
 +
  config HWSPINLOCK_OMAP
   tristate OMAP Hardware Spinlock device
   depends on ARCH_OMAP4 || SOC_OMAP5 || SOC_DRA7XX || SOC_AM33XX || 
 SOC_AM43XX
[...]
 +static const struct of_device_id msm_hwspinlock_of_match[] = {
 + { .compatible = qcom,sfpb-mutex, .data = (void *)0x4 },
 + { .compatible = qcom,tcsr-mutex, .data = (void *)0x80 },
 + { },
 +};

MODULE_DEVICE_TABLE(of, msm_hwspinlock_of_match); ?

[...]
 +static struct platform_driver msm_hwspinlock_driver = {
 + .probe  = msm_hwspinlock_probe,
 + .remove = msm_hwspinlock_remove,
 + .driver = {
 + .name   = msm_hwspinlock,
 + .owner  = THIS_MODULE,

No need, as:

#define platform_driver_register(drv) \
__platform_driver_register(drv, THIS_MODULE)
extern int __platform_driver_register(struct platform_driver *,
struct module *);

 + .of_match_table = msm_hwspinlock_of_match,
 + },
 +};

Otherwise, looks fine.

-Courtney
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

2014-08-29 Thread Stephen Boyd
On 08/29/14 16:41, Courtney Cavin wrote:
 On Sat, Aug 30, 2014 at 01:14:23AM +0200, Bjorn Andersson wrote:
 From: Kumar Gala ga...@codeaurora.org

 Add driver for Qualcomm MSM Hardware Mutex block that exists on
 newer Qualcomm SoCs.

 Cc: Jeffrey Hugo jh...@codeaurora.org
 Cc: Eric Holmberg eholm...@codeaurora.org
 Cc: Courtney Cavin courtney.ca...@sonymobile.com
 Signed-off-by: Kumar Gala ga...@codeaurora.org
 [bjorn: added pm_runtime calls, from Courtney,
  added sfpb-mutex compatible,
  updated DT binding documentation formatting]
 Signed-off-by: Bjorn Andersson bjorn.anders...@sonymobile.com
 ---
 [...]
 diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig
 index 3612cb5..2cd39e2 100644
 --- a/drivers/hwspinlock/Kconfig
 +++ b/drivers/hwspinlock/Kconfig
 @@ -8,6 +8,17 @@ config HWSPINLOCK
  
  menu Hardware Spinlock drivers
  
 +config HWSPINLOCK_MSM
 +tristate MSM Hardware Spinlock device
 +depends on ARCH_QCOM
 This should also depend on OF, as it won't compile or work without it.

Doesn't ARCH_QCOM imply OF? ARCH_MULTIPLATFORM has a select USE_OF.


 +select HWSPINLOCK
 +help
 +  Say y here to support the MSM Hardware Mutex functionality, which
 +  provides a synchronisation mechanism for the various processors on
 +  the SoC.
 +
 +  If unsure, say N.
 +


Maybe MSM should be changed to qcom? Just a thought.

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

2014-08-29 Thread Courtney Cavin
On Sat, Aug 30, 2014 at 02:14:07AM +0200, Stephen Boyd wrote:
 On 08/29/14 16:41, Courtney Cavin wrote:
  On Sat, Aug 30, 2014 at 01:14:23AM +0200, Bjorn Andersson wrote:
  From: Kumar Gala ga...@codeaurora.org
 
  Add driver for Qualcomm MSM Hardware Mutex block that exists on
  newer Qualcomm SoCs.
 
  Cc: Jeffrey Hugo jh...@codeaurora.org
  Cc: Eric Holmberg eholm...@codeaurora.org
  Cc: Courtney Cavin courtney.ca...@sonymobile.com
  Signed-off-by: Kumar Gala ga...@codeaurora.org
  [bjorn: added pm_runtime calls, from Courtney,
 added sfpb-mutex compatible,
 updated DT binding documentation formatting]
  Signed-off-by: Bjorn Andersson bjorn.anders...@sonymobile.com
  ---
  [...]
  diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig
  index 3612cb5..2cd39e2 100644
  --- a/drivers/hwspinlock/Kconfig
  +++ b/drivers/hwspinlock/Kconfig
  @@ -8,6 +8,17 @@ config HWSPINLOCK
   
   menu Hardware Spinlock drivers
   
  +config HWSPINLOCK_MSM
  +  tristate MSM Hardware Spinlock device
  +  depends on ARCH_QCOM
  This should also depend on OF, as it won't compile or work without it.
 
 Doesn't ARCH_QCOM imply OF? ARCH_MULTIPLATFORM has a select USE_OF.

Hrm.  Apparently.

-Courtney
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

2013-08-13 Thread Jeffrey Hugo

On 8/12/2013 10:35 AM, Stephen Boyd wrote:

On 07/29/13 15:00, Kumar Gala wrote:

diff --git a/drivers/hwspinlock/msm_hwspinlock.c 
b/drivers/hwspinlock/msm_hwspinlock.c
new file mode 100644
index 000..dbd9a69
--- /dev/null
+++ b/drivers/hwspinlock/msm_hwspinlock.c
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hwspinlock_internal.h"
+
+#define SPINLOCK_ID_APPS_PROC  1


Is this id only for the apps processor? What about hexagon? Does it need
a different number?


Yes, hexagon would need a different id based on what job that particular 
hexagon processor is doing.  I'm not currently aware of a hexagon 
usecase, but I believe modifying the DT binding in the future would 
cover the usecase if it comes up.





+#define BASE_ID0
+
+static int msm_hwspinlock_trylock(struct hwspinlock *lock)
+{
+   void __iomem *lock_addr = lock->priv;
+
+   writel_relaxed(SPINLOCK_ID_APPS_PROC, lock_addr);
+   smp_mb();
+   return readl_relaxed(lock_addr) == SPINLOCK_ID_APPS_PROC;
+}
+
+static void msm_hwspinlock_unlock(struct hwspinlock *lock)
+{
+   int lock_owner;


This should probably be u32 to be explicit about the size of the register.


+   void __iomem *lock_addr = lock->priv;
+
+   lock_owner = readl_relaxed(lock_addr);
+   if (lock_owner != SPINLOCK_ID_APPS_PROC) {
+   pr_err("%s: spinlock not owned by Apps (actual owner is %d)\n",


Maybe you should just say "spinlock not owned by us (actual owner is
%d)" so that this driver is agnostic to the processor it runs on?


+   __func__, lock_owner);
+   }
+
+   writel_relaxed(0, lock_addr);
+   smp_mb();
+}






Jeffrey Hugo
--
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
hosted by The Linux Foundation.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

2013-08-13 Thread Jeffrey Hugo

On 8/12/2013 10:35 AM, Stephen Boyd wrote:

On 07/29/13 15:00, Kumar Gala wrote:

diff --git a/drivers/hwspinlock/msm_hwspinlock.c 
b/drivers/hwspinlock/msm_hwspinlock.c
new file mode 100644
index 000..dbd9a69
--- /dev/null
+++ b/drivers/hwspinlock/msm_hwspinlock.c
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/err.h
+#include linux/kernel.h
+#include linux/slab.h
+#include linux/device.h
+#include linux/module.h
+#include linux/platform_device.h
+#include linux/of.h
+#include linux/of_address.h
+#include linux/of_device.h
+#include linux/hwspinlock.h
+#include linux/io.h
+
+#include hwspinlock_internal.h
+
+#define SPINLOCK_ID_APPS_PROC  1


Is this id only for the apps processor? What about hexagon? Does it need
a different number?


Yes, hexagon would need a different id based on what job that particular 
hexagon processor is doing.  I'm not currently aware of a hexagon 
usecase, but I believe modifying the DT binding in the future would 
cover the usecase if it comes up.





+#define BASE_ID0
+
+static int msm_hwspinlock_trylock(struct hwspinlock *lock)
+{
+   void __iomem *lock_addr = lock-priv;
+
+   writel_relaxed(SPINLOCK_ID_APPS_PROC, lock_addr);
+   smp_mb();
+   return readl_relaxed(lock_addr) == SPINLOCK_ID_APPS_PROC;
+}
+
+static void msm_hwspinlock_unlock(struct hwspinlock *lock)
+{
+   int lock_owner;


This should probably be u32 to be explicit about the size of the register.


+   void __iomem *lock_addr = lock-priv;
+
+   lock_owner = readl_relaxed(lock_addr);
+   if (lock_owner != SPINLOCK_ID_APPS_PROC) {
+   pr_err(%s: spinlock not owned by Apps (actual owner is %d)\n,


Maybe you should just say spinlock not owned by us (actual owner is
%d) so that this driver is agnostic to the processor it runs on?


+   __func__, lock_owner);
+   }
+
+   writel_relaxed(0, lock_addr);
+   smp_mb();
+}






Jeffrey Hugo
--
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
hosted by The Linux Foundation.

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

2013-08-12 Thread Stephen Boyd
On 07/29/13 15:00, Kumar Gala wrote:
> diff --git a/drivers/hwspinlock/msm_hwspinlock.c 
> b/drivers/hwspinlock/msm_hwspinlock.c
> new file mode 100644
> index 000..dbd9a69
> --- /dev/null
> +++ b/drivers/hwspinlock/msm_hwspinlock.c
> @@ -0,0 +1,150 @@
> +/*
> + * Copyright (c) 2013, The Linux Foundation. All rights reserved.
> + *
> + * This software is licensed under the terms of the GNU General Public
> + * License version 2, as published by the Free Software Foundation, and
> + * may be copied, distributed, and modified under those terms.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "hwspinlock_internal.h"
> +
> +#define SPINLOCK_ID_APPS_PROC1

Is this id only for the apps processor? What about hexagon? Does it need
a different number?

> +#define BASE_ID  0
> +
> +static int msm_hwspinlock_trylock(struct hwspinlock *lock)
> +{
> + void __iomem *lock_addr = lock->priv;
> +
> + writel_relaxed(SPINLOCK_ID_APPS_PROC, lock_addr);
> + smp_mb();
> + return readl_relaxed(lock_addr) == SPINLOCK_ID_APPS_PROC;
> +}
> +
> +static void msm_hwspinlock_unlock(struct hwspinlock *lock)
> +{
> + int lock_owner;

This should probably be u32 to be explicit about the size of the register.

> + void __iomem *lock_addr = lock->priv;
> +
> + lock_owner = readl_relaxed(lock_addr);
> + if (lock_owner != SPINLOCK_ID_APPS_PROC) {
> + pr_err("%s: spinlock not owned by Apps (actual owner is %d)\n",

Maybe you should just say "spinlock not owned by us (actual owner is
%d)" so that this driver is agnostic to the processor it runs on?

> + __func__, lock_owner);
> + }
> +
> + writel_relaxed(0, lock_addr);
> + smp_mb();
> +}
>

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

2013-08-12 Thread Stephen Boyd
On 07/29/13 15:00, Kumar Gala wrote:
 diff --git a/drivers/hwspinlock/msm_hwspinlock.c 
 b/drivers/hwspinlock/msm_hwspinlock.c
 new file mode 100644
 index 000..dbd9a69
 --- /dev/null
 +++ b/drivers/hwspinlock/msm_hwspinlock.c
 @@ -0,0 +1,150 @@
 +/*
 + * Copyright (c) 2013, The Linux Foundation. All rights reserved.
 + *
 + * This software is licensed under the terms of the GNU General Public
 + * License version 2, as published by the Free Software Foundation, and
 + * may be copied, distributed, and modified under those terms.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + */
 +
 +#include linux/err.h
 +#include linux/kernel.h
 +#include linux/slab.h
 +#include linux/device.h
 +#include linux/module.h
 +#include linux/platform_device.h
 +#include linux/of.h
 +#include linux/of_address.h
 +#include linux/of_device.h
 +#include linux/hwspinlock.h
 +#include linux/io.h
 +
 +#include hwspinlock_internal.h
 +
 +#define SPINLOCK_ID_APPS_PROC1

Is this id only for the apps processor? What about hexagon? Does it need
a different number?

 +#define BASE_ID  0
 +
 +static int msm_hwspinlock_trylock(struct hwspinlock *lock)
 +{
 + void __iomem *lock_addr = lock-priv;
 +
 + writel_relaxed(SPINLOCK_ID_APPS_PROC, lock_addr);
 + smp_mb();
 + return readl_relaxed(lock_addr) == SPINLOCK_ID_APPS_PROC;
 +}
 +
 +static void msm_hwspinlock_unlock(struct hwspinlock *lock)
 +{
 + int lock_owner;

This should probably be u32 to be explicit about the size of the register.

 + void __iomem *lock_addr = lock-priv;
 +
 + lock_owner = readl_relaxed(lock_addr);
 + if (lock_owner != SPINLOCK_ID_APPS_PROC) {
 + pr_err(%s: spinlock not owned by Apps (actual owner is %d)\n,

Maybe you should just say spinlock not owned by us (actual owner is
%d) so that this driver is agnostic to the processor it runs on?

 + __func__, lock_owner);
 + }
 +
 + writel_relaxed(0, lock_addr);
 + smp_mb();
 +}


-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

2013-07-29 Thread Kumar Gala
Add driver for Qualcomm MSM Hardware Mutex block that exists on newer MSM
SoC (MSM8974, etc).

CC: Jeffrey Hugo 
CC: Eric Holmberg 
Signed-off-by: Kumar Gala 
---
v2:
* Fixed init of stride
* Dealt with a number of comments from Stephen Boyd:
  - use of  instead of 
  - declaring msm_hwspinlock_of_match once & as const
  - drop unneccessary () in an if statement
  - style cleanup to have devm_kzalloc on one line

TODO:
* feedback from Ohad on device tree binding location & hw-mutex name
* comments from Eric/Jeff on use of mb() 

 .../devicetree/bindings/arm/msm/tcsr-mutex.txt |  20 +++
 drivers/hwspinlock/Kconfig |  11 ++
 drivers/hwspinlock/Makefile|   1 +
 drivers/hwspinlock/msm_hwspinlock.c| 150 +
 4 files changed, 182 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt
 create mode 100644 drivers/hwspinlock/msm_hwspinlock.c

diff --git a/Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt 
b/Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt
new file mode 100644
index 000..ddd6889
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt
@@ -0,0 +1,20 @@
+Qualcomm MSM Hardware Mutex Block:
+
+The hardware block provides mutexes utilized between different processors
+on the SoC as part of the communication protocol used by these processors.
+
+Required properties:
+- compatible: should be "qcom,tcsr-mutex"
+- reg: Should contain registers location and length of mutex registers
+- reg-names:
+   "mutex-base"  - string to identify mutex registers
+- qcom,num-locks: the number of locks/mutexes supported
+
+Example:
+
+   qcom,tcsr-mutex@fd484000 {
+   compatible = "qcom,tcsr-mutex";
+   reg = <0xfd484000 0x1000>;
+   reg-names = "mutex-base";
+   qcom,num-locks = <32>;
+   };
diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig
index 70637d2..192e939 100644
--- a/drivers/hwspinlock/Kconfig
+++ b/drivers/hwspinlock/Kconfig
@@ -8,6 +8,17 @@ config HWSPINLOCK
 
 menu "Hardware Spinlock drivers"
 
+config HWSPINLOCK_MSM
+   tristate "MSM Hardware Spinlock device"
+   depends on ARCH_MSM
+   select HWSPINLOCK
+   help
+ Say y here to support the MSM Hardware Mutex functionality, which
+ provides a synchronisation mechanism for the various processors on
+ the SoC.
+
+ If unsure, say N.
+
 config HWSPINLOCK_OMAP
tristate "OMAP Hardware Spinlock device"
depends on ARCH_OMAP4 || SOC_OMAP5
diff --git a/drivers/hwspinlock/Makefile b/drivers/hwspinlock/Makefile
index 93eb64b..4074c56 100644
--- a/drivers/hwspinlock/Makefile
+++ b/drivers/hwspinlock/Makefile
@@ -3,5 +3,6 @@
 #
 
 obj-$(CONFIG_HWSPINLOCK)   += hwspinlock_core.o
+obj-$(CONFIG_HWSPINLOCK_MSM)   += msm_hwspinlock.o
 obj-$(CONFIG_HWSPINLOCK_OMAP)  += omap_hwspinlock.o
 obj-$(CONFIG_HSEM_U8500)   += u8500_hsem.o
diff --git a/drivers/hwspinlock/msm_hwspinlock.c 
b/drivers/hwspinlock/msm_hwspinlock.c
new file mode 100644
index 000..dbd9a69
--- /dev/null
+++ b/drivers/hwspinlock/msm_hwspinlock.c
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hwspinlock_internal.h"
+
+#define SPINLOCK_ID_APPS_PROC  1
+#define BASE_ID0
+
+static int msm_hwspinlock_trylock(struct hwspinlock *lock)
+{
+   void __iomem *lock_addr = lock->priv;
+
+   writel_relaxed(SPINLOCK_ID_APPS_PROC, lock_addr);
+   smp_mb();
+   return readl_relaxed(lock_addr) == SPINLOCK_ID_APPS_PROC;
+}
+
+static void msm_hwspinlock_unlock(struct hwspinlock *lock)
+{
+   int lock_owner;
+   void __iomem *lock_addr = lock->priv;
+
+   lock_owner = readl_relaxed(lock_addr);
+   if (lock_owner != SPINLOCK_ID_APPS_PROC) {
+   pr_err("%s: spinlock not owned by Apps (actual owner is %d)\n",
+   __func__, lock_owner);
+   }
+
+   writel_relaxed(0, lock_addr);
+   smp_mb();
+}
+
+static const struct hwspinlock_ops msm_hwspinlock_ops = {
+   .trylock= msm_hwspinlock_trylock,
+   .unlock = msm_hwspinlock_unlock,
+};
+
+static const struct of_device_id msm_hwspinlock_of_match[] = {
+   {
+   

[PATCH v2] hwspinlock/msm: Add support for Qualcomm MSM HW Mutex block

2013-07-29 Thread Kumar Gala
Add driver for Qualcomm MSM Hardware Mutex block that exists on newer MSM
SoC (MSM8974, etc).

CC: Jeffrey Hugo jh...@codeaurora.org
CC: Eric Holmberg eholm...@codeaurora.org
Signed-off-by: Kumar Gala ga...@codeaurora.org
---
v2:
* Fixed init of stride
* Dealt with a number of comments from Stephen Boyd:
  - use of linux/io.h instead of asm/io.h
  - declaring msm_hwspinlock_of_match once  as const
  - drop unneccessary () in an if statement
  - style cleanup to have devm_kzalloc on one line

TODO:
* feedback from Ohad on device tree binding location  hw-mutex name
* comments from Eric/Jeff on use of mb() 

 .../devicetree/bindings/arm/msm/tcsr-mutex.txt |  20 +++
 drivers/hwspinlock/Kconfig |  11 ++
 drivers/hwspinlock/Makefile|   1 +
 drivers/hwspinlock/msm_hwspinlock.c| 150 +
 4 files changed, 182 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt
 create mode 100644 drivers/hwspinlock/msm_hwspinlock.c

diff --git a/Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt 
b/Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt
new file mode 100644
index 000..ddd6889
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/msm/tcsr-mutex.txt
@@ -0,0 +1,20 @@
+Qualcomm MSM Hardware Mutex Block:
+
+The hardware block provides mutexes utilized between different processors
+on the SoC as part of the communication protocol used by these processors.
+
+Required properties:
+- compatible: should be qcom,tcsr-mutex
+- reg: Should contain registers location and length of mutex registers
+- reg-names:
+   mutex-base  - string to identify mutex registers
+- qcom,num-locks: the number of locks/mutexes supported
+
+Example:
+
+   qcom,tcsr-mutex@fd484000 {
+   compatible = qcom,tcsr-mutex;
+   reg = 0xfd484000 0x1000;
+   reg-names = mutex-base;
+   qcom,num-locks = 32;
+   };
diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig
index 70637d2..192e939 100644
--- a/drivers/hwspinlock/Kconfig
+++ b/drivers/hwspinlock/Kconfig
@@ -8,6 +8,17 @@ config HWSPINLOCK
 
 menu Hardware Spinlock drivers
 
+config HWSPINLOCK_MSM
+   tristate MSM Hardware Spinlock device
+   depends on ARCH_MSM
+   select HWSPINLOCK
+   help
+ Say y here to support the MSM Hardware Mutex functionality, which
+ provides a synchronisation mechanism for the various processors on
+ the SoC.
+
+ If unsure, say N.
+
 config HWSPINLOCK_OMAP
tristate OMAP Hardware Spinlock device
depends on ARCH_OMAP4 || SOC_OMAP5
diff --git a/drivers/hwspinlock/Makefile b/drivers/hwspinlock/Makefile
index 93eb64b..4074c56 100644
--- a/drivers/hwspinlock/Makefile
+++ b/drivers/hwspinlock/Makefile
@@ -3,5 +3,6 @@
 #
 
 obj-$(CONFIG_HWSPINLOCK)   += hwspinlock_core.o
+obj-$(CONFIG_HWSPINLOCK_MSM)   += msm_hwspinlock.o
 obj-$(CONFIG_HWSPINLOCK_OMAP)  += omap_hwspinlock.o
 obj-$(CONFIG_HSEM_U8500)   += u8500_hsem.o
diff --git a/drivers/hwspinlock/msm_hwspinlock.c 
b/drivers/hwspinlock/msm_hwspinlock.c
new file mode 100644
index 000..dbd9a69
--- /dev/null
+++ b/drivers/hwspinlock/msm_hwspinlock.c
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/err.h
+#include linux/kernel.h
+#include linux/slab.h
+#include linux/device.h
+#include linux/module.h
+#include linux/platform_device.h
+#include linux/of.h
+#include linux/of_address.h
+#include linux/of_device.h
+#include linux/hwspinlock.h
+#include linux/io.h
+
+#include hwspinlock_internal.h
+
+#define SPINLOCK_ID_APPS_PROC  1
+#define BASE_ID0
+
+static int msm_hwspinlock_trylock(struct hwspinlock *lock)
+{
+   void __iomem *lock_addr = lock-priv;
+
+   writel_relaxed(SPINLOCK_ID_APPS_PROC, lock_addr);
+   smp_mb();
+   return readl_relaxed(lock_addr) == SPINLOCK_ID_APPS_PROC;
+}
+
+static void msm_hwspinlock_unlock(struct hwspinlock *lock)
+{
+   int lock_owner;
+   void __iomem *lock_addr = lock-priv;
+
+   lock_owner = readl_relaxed(lock_addr);
+   if (lock_owner != SPINLOCK_ID_APPS_PROC) {
+   pr_err(%s: spinlock not owned by Apps (actual owner is %d)\n,
+   __func__, lock_owner);
+   }
+
+   writel_relaxed(0, lock_addr);
+   smp_mb();
+}
+
+static const struct hwspinlock_ops