For suspend/resume, we currently take an extra clock reference to
prevent the IPA clock from being shut down until a power management
suspend request arrives.  An atomic field in the IPA structure is
used to indicate whether this reference has been taken.

Instead, introduce a new flags bitmap in the IPA structure, and use
a single bit in that bitmap rather than the atomic to indicate
whether we have taken the special IPA clock reference.

Signed-off-by: Alex Elder <el...@linaro.org>
---
v2: New patch to use a bitmap bit rather than an atomic_t.

 drivers/net/ipa/ipa.h      | 14 ++++++++++++--
 drivers/net/ipa/ipa_main.c | 14 +++++++-------
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ipa/ipa.h b/drivers/net/ipa/ipa.h
index 407fee841a9a8..e02fe979b645b 100644
--- a/drivers/net/ipa/ipa.h
+++ b/drivers/net/ipa/ipa.h
@@ -27,15 +27,25 @@ struct ipa_clock;
 struct ipa_smp2p;
 struct ipa_interrupt;
 
+/**
+ * enum ipa_flag - IPA state flags
+ * @IPA_FLAG_CLOCK_HELD:       Whether IPA clock is held to prevent suspend
+ * @IPA_FLAG_COUNT:            Number of defined IPA flags
+ */
+enum ipa_flag {
+       IPA_FLAG_CLOCK_HELD,
+       IPA_FLAG_COUNT,         /* Last; not a flag */
+};
+
 /**
  * struct ipa - IPA information
  * @gsi:               Embedded GSI structure
+ * @flags:             Boolean state flags
  * @version:           IPA hardware version
  * @pdev:              Platform device
  * @modem_rproc:       Remoteproc handle for modem subsystem
  * @smp2p:             SMP2P information
  * @clock:             IPA clocking information
- * @suspend_ref:       Whether clock reference preventing suspend taken
  * @table_addr:                DMA address of filter/route table content
  * @table_virt:                Virtual address of filter/route table content
  * @interrupt:         IPA Interrupt information
@@ -70,6 +80,7 @@ struct ipa_interrupt;
  */
 struct ipa {
        struct gsi gsi;
+       DECLARE_BITMAP(flags, IPA_FLAG_COUNT);
        enum ipa_version version;
        struct platform_device *pdev;
        struct rproc *modem_rproc;
@@ -77,7 +88,6 @@ struct ipa {
        void *notifier;
        struct ipa_smp2p *smp2p;
        struct ipa_clock *clock;
-       atomic_t suspend_ref;
 
        dma_addr_t table_addr;
        __le64 *table_virt;
diff --git a/drivers/net/ipa/ipa_main.c b/drivers/net/ipa/ipa_main.c
index 1fdfec41e4421..409375b96eb8f 100644
--- a/drivers/net/ipa/ipa_main.c
+++ b/drivers/net/ipa/ipa_main.c
@@ -84,7 +84,7 @@ static void ipa_suspend_handler(struct ipa *ipa, enum 
ipa_irq_id irq_id)
         * endpoints will be resumed as a result.  This reference will
         * be dropped when we get a power management suspend request.
         */
-       if (!atomic_xchg(&ipa->suspend_ref, 1))
+       if (!test_and_set_bit(IPA_FLAG_CLOCK_HELD, ipa->flags))
                ipa_clock_get(ipa);
 
        /* Acknowledge/clear the suspend interrupt on all endpoints */
@@ -508,7 +508,7 @@ static int ipa_config(struct ipa *ipa, const struct 
ipa_data *data)
         * is held after initialization completes, and won't get dropped
         * unless/until a system suspend request arrives.
         */
-       atomic_set(&ipa->suspend_ref, 1);
+       __set_bit(IPA_FLAG_CLOCK_HELD, ipa->flags);
        ipa_clock_get(ipa);
 
        ipa_hardware_config(ipa);
@@ -544,7 +544,7 @@ static int ipa_config(struct ipa *ipa, const struct 
ipa_data *data)
 err_hardware_deconfig:
        ipa_hardware_deconfig(ipa);
        ipa_clock_put(ipa);
-       atomic_set(&ipa->suspend_ref, 0);
+       __clear_bit(IPA_FLAG_CLOCK_HELD, ipa->flags);
 
        return ret;
 }
@@ -562,7 +562,7 @@ static void ipa_deconfig(struct ipa *ipa)
        ipa_endpoint_deconfig(ipa);
        ipa_hardware_deconfig(ipa);
        ipa_clock_put(ipa);
-       atomic_set(&ipa->suspend_ref, 0);
+       __clear_bit(IPA_FLAG_CLOCK_HELD, ipa->flags);
 }
 
 static int ipa_firmware_load(struct device *dev)
@@ -777,7 +777,7 @@ static int ipa_probe(struct platform_device *pdev)
        dev_set_drvdata(dev, ipa);
        ipa->modem_rproc = rproc;
        ipa->clock = clock;
-       atomic_set(&ipa->suspend_ref, 0);
+       __clear_bit(IPA_FLAG_CLOCK_HELD, ipa->flags);
        ipa->wakeup_source = wakeup_source;
        ipa->version = data->version;
 
@@ -913,7 +913,7 @@ static int ipa_suspend(struct device *dev)
        struct ipa *ipa = dev_get_drvdata(dev);
 
        ipa_clock_put(ipa);
-       atomic_set(&ipa->suspend_ref, 0);
+       __clear_bit(IPA_FLAG_CLOCK_HELD, ipa->flags);
 
        return 0;
 }
@@ -933,7 +933,7 @@ static int ipa_resume(struct device *dev)
        /* This clock reference will keep the IPA out of suspend
         * until we get a power management suspend request.
         */
-       atomic_set(&ipa->suspend_ref, 1);
+       __set_bit(IPA_FLAG_CLOCK_HELD, ipa->flags);
        ipa_clock_get(ipa);
 
        return 0;
-- 
2.20.1

Reply via email to