]>
Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
ff5430de GL |
2 | /* |
3 | * V4L2 clock service | |
4 | * | |
5 | * Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de> | |
6 | * | |
ff5430de GL |
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> | |
cf326dfe | 15 | #include <linux/export.h> |
ff5430de GL |
16 | #include <linux/list.h> |
17 | #include <linux/mutex.h> | |
18 | ||
19 | struct module; | |
20 | struct device; | |
21 | ||
4f528afc | 22 | struct clk; |
ff5430de GL |
23 | struct v4l2_clk { |
24 | struct list_head list; | |
25 | const struct v4l2_clk_ops *ops; | |
26 | const char *dev_id; | |
ff5430de GL |
27 | int enable; |
28 | struct mutex lock; /* Protect the enable count */ | |
29 | atomic_t use_count; | |
4f528afc | 30 | struct clk *clk; |
ff5430de GL |
31 | void *priv; |
32 | }; | |
33 | ||
34 | struct 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 | ||
42 | struct v4l2_clk *v4l2_clk_register(const struct v4l2_clk_ops *ops, | |
43 | const char *dev_name, | |
a37462b9 | 44 | void *priv); |
ff5430de GL |
45 | void v4l2_clk_unregister(struct v4l2_clk *clk); |
46 | struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id); | |
47 | void v4l2_clk_put(struct v4l2_clk *clk); | |
48 | int v4l2_clk_enable(struct v4l2_clk *clk); | |
49 | void v4l2_clk_disable(struct v4l2_clk *clk); | |
50 | unsigned long v4l2_clk_get_rate(struct v4l2_clk *clk); | |
51 | int v4l2_clk_set_rate(struct v4l2_clk *clk, unsigned long rate); | |
52 | ||
cf326dfe GL |
53 | struct module; |
54 | ||
55 | struct v4l2_clk *__v4l2_clk_register_fixed(const char *dev_id, | |
a37462b9 | 56 | unsigned long rate, struct module *owner); |
cf326dfe GL |
57 | void v4l2_clk_unregister_fixed(struct v4l2_clk *clk); |
58 | ||
59 | static inline struct v4l2_clk *v4l2_clk_register_fixed(const char *dev_id, | |
cf326dfe GL |
60 | unsigned long rate) |
61 | { | |
a37462b9 | 62 | return __v4l2_clk_register_fixed(dev_id, rate, THIS_MODULE); |
cf326dfe GL |
63 | } |
64 | ||
3d83078a JW |
65 | #define V4L2_CLK_NAME_SIZE 64 |
66 | ||
774cc4c2 GL |
67 | #define v4l2_clk_name_i2c(name, size, adap, client) snprintf(name, size, \ |
68 | "%d-%04x", adap, client) | |
69 | ||
68d9c47b RH |
70 | #define v4l2_clk_name_of(name, size, node) snprintf(name, size, \ |
71 | "of-%pOF", node) | |
ac2841f3 | 72 | |
ff5430de | 73 | #endif |