blob: d9d21a43a834a4818171c79111baeb4ef2857f7b [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Guennadi Liakhovetskiff5430d2012-12-04 07:42:15 -03002/*
3 * V4L2 clock service
4 *
5 * Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
6 *
Guennadi Liakhovetskiff5430d2012-12-04 07:42:15 -03007 * ATTENTION: This is a temporary API and it shall be replaced by the generic
8 * clock API, when the latter becomes widely available.
9 */
10
11#ifndef MEDIA_V4L2_CLK_H
12#define MEDIA_V4L2_CLK_H
13
14#include <linux/atomic.h>
Guennadi Liakhovetskicf326df2013-08-28 10:28:26 -030015#include <linux/export.h>
Guennadi Liakhovetskiff5430d2012-12-04 07:42:15 -030016#include <linux/list.h>
17#include <linux/mutex.h>
18
19struct module;
20struct device;
21
Guennadi Liakhovetski4f528af2015-02-01 08:12:33 -030022struct clk;
Guennadi Liakhovetskiff5430d2012-12-04 07:42:15 -030023struct v4l2_clk {
24 struct list_head list;
25 const struct v4l2_clk_ops *ops;
26 const char *dev_id;
Guennadi Liakhovetskiff5430d2012-12-04 07:42:15 -030027 int enable;
28 struct mutex lock; /* Protect the enable count */
29 atomic_t use_count;
Guennadi Liakhovetski4f528af2015-02-01 08:12:33 -030030 struct clk *clk;
Guennadi Liakhovetskiff5430d2012-12-04 07:42:15 -030031 void *priv;
32};
33
34struct v4l2_clk_ops {
35 struct module *owner;
36 int (*enable)(struct v4l2_clk *clk);
37 void (*disable)(struct v4l2_clk *clk);
38 unsigned long (*get_rate)(struct v4l2_clk *clk);
39 int (*set_rate)(struct v4l2_clk *clk, unsigned long);
40};
41
42struct v4l2_clk *v4l2_clk_register(const struct v4l2_clk_ops *ops,
43 const char *dev_name,
Guennadi Liakhovetskia37462b2015-01-31 20:21:32 -030044 void *priv);
Guennadi Liakhovetskiff5430d2012-12-04 07:42:15 -030045void v4l2_clk_unregister(struct v4l2_clk *clk);
46struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id);
47void v4l2_clk_put(struct v4l2_clk *clk);
48int v4l2_clk_enable(struct v4l2_clk *clk);
49void v4l2_clk_disable(struct v4l2_clk *clk);
50unsigned long v4l2_clk_get_rate(struct v4l2_clk *clk);
51int v4l2_clk_set_rate(struct v4l2_clk *clk, unsigned long rate);
52
Guennadi Liakhovetskicf326df2013-08-28 10:28:26 -030053struct module;
54
55struct v4l2_clk *__v4l2_clk_register_fixed(const char *dev_id,
Guennadi Liakhovetskia37462b2015-01-31 20:21:32 -030056 unsigned long rate, struct module *owner);
Guennadi Liakhovetskicf326df2013-08-28 10:28:26 -030057void v4l2_clk_unregister_fixed(struct v4l2_clk *clk);
58
59static inline struct v4l2_clk *v4l2_clk_register_fixed(const char *dev_id,
Guennadi Liakhovetskicf326df2013-08-28 10:28:26 -030060 unsigned long rate)
61{
Guennadi Liakhovetskia37462b2015-01-31 20:21:32 -030062 return __v4l2_clk_register_fixed(dev_id, rate, THIS_MODULE);
Guennadi Liakhovetskicf326df2013-08-28 10:28:26 -030063}
64
Josh Wu3d830782015-10-28 07:48:54 -020065#define V4L2_CLK_NAME_SIZE 64
66
Guennadi Liakhovetski774cc4c22013-08-28 10:28:27 -030067#define v4l2_clk_name_i2c(name, size, adap, client) snprintf(name, size, \
68 "%d-%04x", adap, client)
69
Rob Herring68d9c472017-07-21 15:28:33 -040070#define v4l2_clk_name_of(name, size, node) snprintf(name, size, \
71 "of-%pOF", node)
Josh Wuac2841f2015-10-28 07:48:53 -020072
Guennadi Liakhovetskiff5430d2012-12-04 07:42:15 -030073#endif