blob: 3ef6e3d5ed6c6f6eb90fa177f6eccc20ee7a9c83 [file] [log] [blame]
Guennadi Liakhovetskiff5430d2012-12-04 07:42:15 -03001/*
2 * V4L2 clock service
3 *
4 * Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ATTENTION: This is a temporary API and it shall be replaced by the generic
11 * clock API, when the latter becomes widely available.
12 */
13
14#ifndef MEDIA_V4L2_CLK_H
15#define MEDIA_V4L2_CLK_H
16
17#include <linux/atomic.h>
Guennadi Liakhovetskicf326df2013-08-28 10:28:26 -030018#include <linux/export.h>
Guennadi Liakhovetskiff5430d2012-12-04 07:42:15 -030019#include <linux/list.h>
20#include <linux/mutex.h>
21
22struct module;
23struct device;
24
Guennadi Liakhovetski4f528af2015-02-01 08:12:33 -030025struct clk;
Guennadi Liakhovetskiff5430d2012-12-04 07:42:15 -030026struct v4l2_clk {
27 struct list_head list;
28 const struct v4l2_clk_ops *ops;
29 const char *dev_id;
Guennadi Liakhovetskiff5430d2012-12-04 07:42:15 -030030 int enable;
31 struct mutex lock; /* Protect the enable count */
32 atomic_t use_count;
Guennadi Liakhovetski4f528af2015-02-01 08:12:33 -030033 struct clk *clk;
Guennadi Liakhovetskiff5430d2012-12-04 07:42:15 -030034 void *priv;
35};
36
37struct v4l2_clk_ops {
38 struct module *owner;
39 int (*enable)(struct v4l2_clk *clk);
40 void (*disable)(struct v4l2_clk *clk);
41 unsigned long (*get_rate)(struct v4l2_clk *clk);
42 int (*set_rate)(struct v4l2_clk *clk, unsigned long);
43};
44
45struct v4l2_clk *v4l2_clk_register(const struct v4l2_clk_ops *ops,
46 const char *dev_name,
Guennadi Liakhovetskia37462b2015-01-31 20:21:32 -030047 void *priv);
Guennadi Liakhovetskiff5430d2012-12-04 07:42:15 -030048void v4l2_clk_unregister(struct v4l2_clk *clk);
49struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id);
50void v4l2_clk_put(struct v4l2_clk *clk);
51int v4l2_clk_enable(struct v4l2_clk *clk);
52void v4l2_clk_disable(struct v4l2_clk *clk);
53unsigned long v4l2_clk_get_rate(struct v4l2_clk *clk);
54int v4l2_clk_set_rate(struct v4l2_clk *clk, unsigned long rate);
55
Guennadi Liakhovetskicf326df2013-08-28 10:28:26 -030056struct module;
57
58struct v4l2_clk *__v4l2_clk_register_fixed(const char *dev_id,
Guennadi Liakhovetskia37462b2015-01-31 20:21:32 -030059 unsigned long rate, struct module *owner);
Guennadi Liakhovetskicf326df2013-08-28 10:28:26 -030060void v4l2_clk_unregister_fixed(struct v4l2_clk *clk);
61
62static inline struct v4l2_clk *v4l2_clk_register_fixed(const char *dev_id,
Guennadi Liakhovetskicf326df2013-08-28 10:28:26 -030063 unsigned long rate)
64{
Guennadi Liakhovetskia37462b2015-01-31 20:21:32 -030065 return __v4l2_clk_register_fixed(dev_id, rate, THIS_MODULE);
Guennadi Liakhovetskicf326df2013-08-28 10:28:26 -030066}
67
Guennadi Liakhovetski774cc4c2013-08-28 10:28:27 -030068#define v4l2_clk_name_i2c(name, size, adap, client) snprintf(name, size, \
69 "%d-%04x", adap, client)
70
Guennadi Liakhovetskiff5430d2012-12-04 07:42:15 -030071#endif