Linux Audio

Check our new training course

Loading...
v5.9
 1/* SPDX-License-Identifier: GPL-2.0-only */
 2/*
 3 * V4L2 clock service
 4 *
 5 * Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
 6 *
 
 
 
 
 7 * 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>
15#include <linux/export.h>
16#include <linux/list.h>
17#include <linux/mutex.h>
18
19struct module;
20struct device;
21
22struct clk;
23struct v4l2_clk {
24	struct list_head list;
25	const struct v4l2_clk_ops *ops;
26	const char *dev_id;
27	int enable;
28	struct mutex lock; /* Protect the enable count */
29	atomic_t use_count;
30	struct clk *clk;
31	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,
44				   void *priv);
45void 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
53struct module;
54
55struct v4l2_clk *__v4l2_clk_register_fixed(const char *dev_id,
56			unsigned long rate, struct module *owner);
57void v4l2_clk_unregister_fixed(struct v4l2_clk *clk);
58
59static inline struct v4l2_clk *v4l2_clk_register_fixed(const char *dev_id,
60							unsigned long rate)
61{
62	return __v4l2_clk_register_fixed(dev_id, rate, THIS_MODULE);
63}
64
65#define V4L2_CLK_NAME_SIZE 64
66
67#define v4l2_clk_name_i2c(name, size, adap, client) snprintf(name, size, \
68			  "%d-%04x", adap, client)
69
70#define v4l2_clk_name_of(name, size, node) snprintf(name, size, \
71			  "of-%pOF", node)
72
73#endif
v4.10.11
 
 1/*
 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>
18#include <linux/export.h>
19#include <linux/list.h>
20#include <linux/mutex.h>
21
22struct module;
23struct device;
24
25struct clk;
26struct v4l2_clk {
27	struct list_head list;
28	const struct v4l2_clk_ops *ops;
29	const char *dev_id;
30	int enable;
31	struct mutex lock; /* Protect the enable count */
32	atomic_t use_count;
33	struct clk *clk;
34	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,
47				   void *priv);
48void 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
56struct module;
57
58struct v4l2_clk *__v4l2_clk_register_fixed(const char *dev_id,
59			unsigned long rate, struct module *owner);
60void v4l2_clk_unregister_fixed(struct v4l2_clk *clk);
61
62static inline struct v4l2_clk *v4l2_clk_register_fixed(const char *dev_id,
63							unsigned long rate)
64{
65	return __v4l2_clk_register_fixed(dev_id, rate, THIS_MODULE);
66}
67
68#define V4L2_CLK_NAME_SIZE 64
69
70#define v4l2_clk_name_i2c(name, size, adap, client) snprintf(name, size, \
71			  "%d-%04x", adap, client)
72
73#define v4l2_clk_name_of(name, size, of_full_name) snprintf(name, size, \
74			  "of-%s", of_full_name)
75
76#endif