Thread (17 messages) 17 messages, 4 authors, 2010-01-25

Re: [RFC,PATCH 1/7 v2] Add a common struct clk

From: Francesco VIRLINZI <hidden>
Date: 2010-01-12 09:19:12
Also in: linux-arm-kernel, lkml

Hi Jeremy
In November I already sent a proposal on
  a generic linux clk framework.
On that I would suggest:
+struct clk {
+	const struct clk_operations *ops;
   
            spinlock_t lock;
            const char *name;
            int id;
            unsigned long rate;
+};
+
+struct clk_operations {
   
                int (*init)(struc clk *);
+       int             (*enable)(struct clk *);
+       void            (*disable)(struct clk *);
+       unsigned long   (*get_rate)(struct clk *);
+       void            (*put)(struct clk *);
+       long            (*round_rate)(struct clk *, unsigned long);
+       int             (*set_rate)(struct clk *, unsigned long);
+       int             (*set_parent)(struct clk *, struct clk *);
+       struct clk*     (*get_parent)(struct clk *);
+};
   
+static inline int clk_enable(struct clk *clk)
+{
	unsigned long flags;
	int ret = 0;
+	if (clk->ops->enable) {
		spinlock_irq_save(&clk->lock, flags);
+		ret = clk->ops->enable(clk);
		spinlock_irq_restore(&clk->lock, flags);
	}
+	return 0;
+}

Something similar in the other function...
+
+static inline unsigned long clk_get_rate(struct clk *clk)
+{
+	if (clk->ops->get_rate)
+		return clk->ops->get_rate(clk);
   
	return clk->rate;
+}

   
Moreover if you support .set_parent and .get_parent  a .parent field in 
the struct clk
  is useful.

As

struct clk {
const struct clk_operations *ops;

     spinlock_t lock;
     const char *name;
     int id;
     unsigned long rate;
     struct clk *parent;
};

Regards
  Francesco
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help