[PATCH v2 04/14] clk: at91: clk-main: factorize irq handling

2015-10-12 Thread Alexandre Belloni
The three different irq handlers are doing the same thing, factorize their
code in a generic irq handler.

Signed-off-by: Alexandre Belloni 
---
 drivers/clk/at91/clk-main.c | 144 +++-
 1 file changed, 63 insertions(+), 81 deletions(-)

diff --git a/drivers/clk/at91/clk-main.c b/drivers/clk/at91/clk-main.c
index c1f119748bdc..5841eb958f83 100644
--- a/drivers/clk/at91/clk-main.c
+++ b/drivers/clk/at91/clk-main.c
@@ -34,25 +34,28 @@
 
 #define MOR_KEY_MASK   (0xff << 16)
 
-struct clk_main_osc {
+struct clk_main {
struct clk_hw hw;
struct regmap *regmap;
unsigned int irq;
wait_queue_head_t wait;
 };
 
-#define to_clk_main_osc(hw) container_of(hw, struct clk_main_osc, hw)
+#define to_clk_main(hw) container_of(hw, struct clk_main, hw)
+
+struct clk_main_osc {
+   struct clk_main base;
+};
+
+#define to_clk_main_osc(hw) container_of(hw, struct clk_main_osc, base.hw)
 
 struct clk_main_rc_osc {
-   struct clk_hw hw;
-   struct regmap *regmap;
-   unsigned int irq;
-   wait_queue_head_t wait;
+   struct clk_main base;
unsigned long frequency;
unsigned long accuracy;
 };
 
-#define to_clk_main_rc_osc(hw) container_of(hw, struct clk_main_rc_osc, hw)
+#define to_clk_main_rc_osc(hw) container_of(hw, struct clk_main_rc_osc, 
base.hw)
 
 struct clk_rm9200_main {
struct clk_hw hw;
@@ -62,21 +65,20 @@ struct clk_rm9200_main {
 #define to_clk_rm9200_main(hw) container_of(hw, struct clk_rm9200_main, hw)
 
 struct clk_sam9x5_main {
-   struct clk_hw hw;
-   struct regmap *regmap;
-   unsigned int irq;
-   wait_queue_head_t wait;
+   struct clk_main base;
u8 parent;
 };
 
-#define to_clk_sam9x5_main(hw) container_of(hw, struct clk_sam9x5_main, hw)
+#define to_clk_sam9x5_main(hw) container_of(hw, struct clk_sam9x5_main, 
base.hw)
 
-static irqreturn_t clk_main_osc_irq_handler(int irq, void *dev_id)
+/* Generic structure */
+
+static irqreturn_t clk_main_irq_handler(int irq, void *dev_id)
 {
-   struct clk_main_osc *osc = dev_id;
+   struct clk_main *clkmain = dev_id;
 
-   wake_up(>wait);
-   disable_irq_nosync(osc->irq);
+   wake_up(>wait);
+   disable_irq_nosync(clkmain->irq);
 
return IRQ_HANDLED;
 }
@@ -93,7 +95,7 @@ static inline bool clk_main_osc_ready(struct regmap *regmap)
 static int clk_main_osc_prepare(struct clk_hw *hw)
 {
struct clk_main_osc *osc = to_clk_main_osc(hw);
-   struct regmap *regmap = osc->regmap;
+   struct regmap *regmap = osc->base.regmap;
u32 tmp;
 
regmap_read(regmap, AT91_CKGR_MOR, );
@@ -108,8 +110,8 @@ static int clk_main_osc_prepare(struct clk_hw *hw)
}
 
while (!clk_main_osc_ready(regmap)) {
-   enable_irq(osc->irq);
-   wait_event(osc->wait,
+   enable_irq(osc->base.irq);
+   wait_event(osc->base.wait,
   clk_main_osc_ready(regmap));
}
 
@@ -119,7 +121,7 @@ static int clk_main_osc_prepare(struct clk_hw *hw)
 static void clk_main_osc_unprepare(struct clk_hw *hw)
 {
struct clk_main_osc *osc = to_clk_main_osc(hw);
-   struct regmap *regmap = osc->regmap;
+   struct regmap *regmap = osc->base.regmap;
u32 tmp;
 
regmap_read(regmap, AT91_CKGR_MOR, );
@@ -136,7 +138,7 @@ static void clk_main_osc_unprepare(struct clk_hw *hw)
 static int clk_main_osc_is_prepared(struct clk_hw *hw)
 {
struct clk_main_osc *osc = to_clk_main_osc(hw);
-   struct regmap *regmap = osc->regmap;
+   struct regmap *regmap = osc->base.regmap;
u32 tmp, status;
 
regmap_read(regmap, AT91_CKGR_MOR, );
@@ -179,14 +181,14 @@ at91_clk_register_main_osc(struct regmap *regmap,
init.num_parents = 1;
init.flags = CLK_IGNORE_UNUSED;
 
-   osc->hw.init = 
-   osc->regmap = regmap;
-   osc->irq = irq;
+   osc->base.hw.init = 
+   osc->base.regmap = regmap;
+   osc->base.irq = irq;
 
-   init_waitqueue_head(>wait);
-   irq_set_status_flags(osc->irq, IRQ_NOAUTOEN);
-   ret = request_irq(osc->irq, clk_main_osc_irq_handler,
- IRQF_TRIGGER_HIGH, name, osc);
+   init_waitqueue_head(>base.wait);
+   irq_set_status_flags(irq, IRQ_NOAUTOEN);
+   ret = request_irq(irq, clk_main_irq_handler,
+ IRQF_TRIGGER_HIGH, name, >base);
if (ret) {
kfree(osc);
return ERR_PTR(ret);
@@ -198,7 +200,7 @@ at91_clk_register_main_osc(struct regmap *regmap,
   AT91_PMC_MOSCEN,
   AT91_PMC_OSCBYPASS | AT91_PMC_KEY);
 
-   clk = clk_register(NULL, >hw);
+   clk = clk_register(NULL, >base.hw);
if (IS_ERR(clk)) {
free_irq(irq, osc);
kfree(osc);
@@ -237,16 +239,6 @@ static void __init of_at91rm9200_clk_main_osc_setup(struct 
device_node 

[PATCH v2 04/14] clk: at91: clk-main: factorize irq handling

2015-10-12 Thread Alexandre Belloni
The three different irq handlers are doing the same thing, factorize their
code in a generic irq handler.

Signed-off-by: Alexandre Belloni 
---
 drivers/clk/at91/clk-main.c | 144 +++-
 1 file changed, 63 insertions(+), 81 deletions(-)

diff --git a/drivers/clk/at91/clk-main.c b/drivers/clk/at91/clk-main.c
index c1f119748bdc..5841eb958f83 100644
--- a/drivers/clk/at91/clk-main.c
+++ b/drivers/clk/at91/clk-main.c
@@ -34,25 +34,28 @@
 
 #define MOR_KEY_MASK   (0xff << 16)
 
-struct clk_main_osc {
+struct clk_main {
struct clk_hw hw;
struct regmap *regmap;
unsigned int irq;
wait_queue_head_t wait;
 };
 
-#define to_clk_main_osc(hw) container_of(hw, struct clk_main_osc, hw)
+#define to_clk_main(hw) container_of(hw, struct clk_main, hw)
+
+struct clk_main_osc {
+   struct clk_main base;
+};
+
+#define to_clk_main_osc(hw) container_of(hw, struct clk_main_osc, base.hw)
 
 struct clk_main_rc_osc {
-   struct clk_hw hw;
-   struct regmap *regmap;
-   unsigned int irq;
-   wait_queue_head_t wait;
+   struct clk_main base;
unsigned long frequency;
unsigned long accuracy;
 };
 
-#define to_clk_main_rc_osc(hw) container_of(hw, struct clk_main_rc_osc, hw)
+#define to_clk_main_rc_osc(hw) container_of(hw, struct clk_main_rc_osc, 
base.hw)
 
 struct clk_rm9200_main {
struct clk_hw hw;
@@ -62,21 +65,20 @@ struct clk_rm9200_main {
 #define to_clk_rm9200_main(hw) container_of(hw, struct clk_rm9200_main, hw)
 
 struct clk_sam9x5_main {
-   struct clk_hw hw;
-   struct regmap *regmap;
-   unsigned int irq;
-   wait_queue_head_t wait;
+   struct clk_main base;
u8 parent;
 };
 
-#define to_clk_sam9x5_main(hw) container_of(hw, struct clk_sam9x5_main, hw)
+#define to_clk_sam9x5_main(hw) container_of(hw, struct clk_sam9x5_main, 
base.hw)
 
-static irqreturn_t clk_main_osc_irq_handler(int irq, void *dev_id)
+/* Generic structure */
+
+static irqreturn_t clk_main_irq_handler(int irq, void *dev_id)
 {
-   struct clk_main_osc *osc = dev_id;
+   struct clk_main *clkmain = dev_id;
 
-   wake_up(>wait);
-   disable_irq_nosync(osc->irq);
+   wake_up(>wait);
+   disable_irq_nosync(clkmain->irq);
 
return IRQ_HANDLED;
 }
@@ -93,7 +95,7 @@ static inline bool clk_main_osc_ready(struct regmap *regmap)
 static int clk_main_osc_prepare(struct clk_hw *hw)
 {
struct clk_main_osc *osc = to_clk_main_osc(hw);
-   struct regmap *regmap = osc->regmap;
+   struct regmap *regmap = osc->base.regmap;
u32 tmp;
 
regmap_read(regmap, AT91_CKGR_MOR, );
@@ -108,8 +110,8 @@ static int clk_main_osc_prepare(struct clk_hw *hw)
}
 
while (!clk_main_osc_ready(regmap)) {
-   enable_irq(osc->irq);
-   wait_event(osc->wait,
+   enable_irq(osc->base.irq);
+   wait_event(osc->base.wait,
   clk_main_osc_ready(regmap));
}
 
@@ -119,7 +121,7 @@ static int clk_main_osc_prepare(struct clk_hw *hw)
 static void clk_main_osc_unprepare(struct clk_hw *hw)
 {
struct clk_main_osc *osc = to_clk_main_osc(hw);
-   struct regmap *regmap = osc->regmap;
+   struct regmap *regmap = osc->base.regmap;
u32 tmp;
 
regmap_read(regmap, AT91_CKGR_MOR, );
@@ -136,7 +138,7 @@ static void clk_main_osc_unprepare(struct clk_hw *hw)
 static int clk_main_osc_is_prepared(struct clk_hw *hw)
 {
struct clk_main_osc *osc = to_clk_main_osc(hw);
-   struct regmap *regmap = osc->regmap;
+   struct regmap *regmap = osc->base.regmap;
u32 tmp, status;
 
regmap_read(regmap, AT91_CKGR_MOR, );
@@ -179,14 +181,14 @@ at91_clk_register_main_osc(struct regmap *regmap,
init.num_parents = 1;
init.flags = CLK_IGNORE_UNUSED;
 
-   osc->hw.init = 
-   osc->regmap = regmap;
-   osc->irq = irq;
+   osc->base.hw.init = 
+   osc->base.regmap = regmap;
+   osc->base.irq = irq;
 
-   init_waitqueue_head(>wait);
-   irq_set_status_flags(osc->irq, IRQ_NOAUTOEN);
-   ret = request_irq(osc->irq, clk_main_osc_irq_handler,
- IRQF_TRIGGER_HIGH, name, osc);
+   init_waitqueue_head(>base.wait);
+   irq_set_status_flags(irq, IRQ_NOAUTOEN);
+   ret = request_irq(irq, clk_main_irq_handler,
+ IRQF_TRIGGER_HIGH, name, >base);
if (ret) {
kfree(osc);
return ERR_PTR(ret);
@@ -198,7 +200,7 @@ at91_clk_register_main_osc(struct regmap *regmap,
   AT91_PMC_MOSCEN,
   AT91_PMC_OSCBYPASS | AT91_PMC_KEY);
 
-   clk = clk_register(NULL, >hw);
+   clk = clk_register(NULL, >base.hw);
if (IS_ERR(clk)) {
free_irq(irq, osc);
kfree(osc);
@@ -237,16 +239,6 @@ static void __init