[RFC,PATCH 1/7 v2] Add a common struct clk
Francesco VIRLINZI
francesco.virlinzi at st.com
Tue Jan 12 19:48:44 EST 2010
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
More information about the Linuxppc-dev
mailing list