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

From: Francesco VIRLINZI
Date: Tue Jan 12 2010 - 04:19:18 EST


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