^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * V4L2 clock service
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * ATTENTION: This is a temporary API and it shall be replaced by the generic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * clock API, when the latter becomes widely available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #ifndef MEDIA_V4L2_CLK_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define MEDIA_V4L2_CLK_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct module;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct v4l2_clk {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) const struct v4l2_clk_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) const char *dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) int enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct mutex lock; /* Protect the enable count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) atomic_t use_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct clk *clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) void *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct v4l2_clk_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct module *owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) int (*enable)(struct v4l2_clk *clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) void (*disable)(struct v4l2_clk *clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) unsigned long (*get_rate)(struct v4l2_clk *clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) int (*set_rate)(struct v4l2_clk *clk, unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct v4l2_clk *v4l2_clk_register(const struct v4l2_clk_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) const char *dev_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) void *priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) void v4l2_clk_unregister(struct v4l2_clk *clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) void v4l2_clk_put(struct v4l2_clk *clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) int v4l2_clk_enable(struct v4l2_clk *clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) void v4l2_clk_disable(struct v4l2_clk *clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) unsigned long v4l2_clk_get_rate(struct v4l2_clk *clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int v4l2_clk_set_rate(struct v4l2_clk *clk, unsigned long rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct module;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct v4l2_clk *__v4l2_clk_register_fixed(const char *dev_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) unsigned long rate, struct module *owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) void v4l2_clk_unregister_fixed(struct v4l2_clk *clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static inline struct v4l2_clk *v4l2_clk_register_fixed(const char *dev_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) unsigned long rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return __v4l2_clk_register_fixed(dev_id, rate, THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define V4L2_CLK_NAME_SIZE 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define v4l2_clk_name_i2c(name, size, adap, client) snprintf(name, size, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) "%d-%04x", adap, client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #define v4l2_clk_name_of(name, size, node) snprintf(name, size, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) "of-%pOF", node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #endif