coresight: Remove atomic type from refcnt
[sfrench/cifs-2.6.git] / drivers / hwtracing / coresight / coresight-tpiu.c
index 7e69048ac9449db0202555d39ee35c660abbb5b3..29024f880fda7af029334d2a8e2588faeaa02c20 100644 (file)
@@ -58,6 +58,7 @@ struct tpiu_drvdata {
        void __iomem            *base;
        struct clk              *atclk;
        struct coresight_device *csdev;
+       spinlock_t              spinlock;
 };
 
 static void tpiu_enable_hw(struct csdev_access *csa)
@@ -72,8 +73,11 @@ static void tpiu_enable_hw(struct csdev_access *csa)
 static int tpiu_enable(struct coresight_device *csdev, enum cs_mode mode,
                       void *__unused)
 {
+       struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
+
+       guard(spinlock)(&drvdata->spinlock);
        tpiu_enable_hw(&csdev->access);
-       atomic_inc(&csdev->refcnt);
+       csdev->refcnt++;
        dev_dbg(&csdev->dev, "TPIU enabled\n");
        return 0;
 }
@@ -96,7 +100,11 @@ static void tpiu_disable_hw(struct csdev_access *csa)
 
 static int tpiu_disable(struct coresight_device *csdev)
 {
-       if (atomic_dec_return(&csdev->refcnt))
+       struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
+
+       guard(spinlock)(&drvdata->spinlock);
+       csdev->refcnt--;
+       if (csdev->refcnt)
                return -EBUSY;
 
        tpiu_disable_hw(&csdev->access);
@@ -132,6 +140,8 @@ static int tpiu_probe(struct amba_device *adev, const struct amba_id *id)
        if (!drvdata)
                return -ENOMEM;
 
+       spin_lock_init(&drvdata->spinlock);
+
        drvdata->atclk = devm_clk_get(&adev->dev, "atclk"); /* optional */
        if (!IS_ERR(drvdata->atclk)) {
                ret = clk_prepare_enable(drvdata->atclk);