blob: 928045f4e70c00ebbfde1b37522ebfcc1283469f [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
25struct v4l2_clk {
26 struct list_head list;
27 const struct v4l2_clk_ops *ops;
28 const char *dev_id;
Guennadi Liakhovetskiff5430d2012-12-04 07:42:15 -030029 int enable;
30 struct mutex lock; /* Protect the enable count */
31 atomic_t use_count;
32 void *priv;
33};
34
35struct v4l2_clk_ops {
36 struct module *owner;
37 int (*enable)(struct v4l2_clk *clk);
38 void (*disable)(struct v4l2_clk *clk);
39 unsigned long (*get_rate)(struct v4l2_clk *clk);
40 int (*set_rate)(struct v4l2_clk *clk, unsigned long);
41};
42
43struct v4l2_clk *v4l2_clk_register(const struct v4l2_clk_ops *ops,
44 const char *dev_name,
Guennadi Liakhovetskia37462b2015-01-31 20:21:32 -030045 void *priv);
Guennadi Liakhovetskiff5430d2012-12-04 07:42:15 -030046void v4l2_clk_unregister(struct v4l2_clk *clk);
47struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id);
48void v4l2_clk_put(struct v4l2_clk *clk);
49int v4l2_clk_enable(struct v4l2_clk *clk);
50void v4l2_clk_disable(struct v4l2_clk *clk);
51unsigned long v4l2_clk_get_rate(struct v4l2_clk *clk);
52int v4l2_clk_set_rate(struct v4l2_clk *clk, unsigned long rate);
53
Guennadi Liakhovetskicf326df2013-08-28 10:28:26 -030054struct module;
55
56struct v4l2_clk *__v4l2_clk_register_fixed(const char *dev_id,
Guennadi Liakhovetskia37462b2015-01-31 20:21:32 -030057 unsigned long rate, struct module *owner);
Guennadi Liakhovetskicf326df2013-08-28 10:28:26 -030058void v4l2_clk_unregister_fixed(struct v4l2_clk *clk);
59
60static inline struct v4l2_clk *v4l2_clk_register_fixed(const char *dev_id,
Guennadi Liakhovetskicf326df2013-08-28 10:28:26 -030061 unsigned long rate)
62{
Guennadi Liakhovetskia37462b2015-01-31 20:21:32 -030063 return __v4l2_clk_register_fixed(dev_id, rate, THIS_MODULE);
Guennadi Liakhovetskicf326df2013-08-28 10:28:26 -030064}
65
Guennadi Liakhovetski774cc4c2013-08-28 10:28:27 -030066#define v4l2_clk_name_i2c(name, size, adap, client) snprintf(name, size, \
67 "%d-%04x", adap, client)
68
Guennadi Liakhovetskiff5430d2012-12-04 07:42:15 -030069#endif