Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] V4L: add CCF support to the v4l2_clk API

V4L2 clocks, e.g. used by camera sensors for their master clock, do not
have to be supplied by a different V4L2 driver, they can also be
supplied by an independent source. In this case the standart kernel
clock API should be used to handle such clocks. This patch adds support
for such cases.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Josh Wu <josh.wu@atmel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Guennadi Liakhovetski and committed by
Mauro Carvalho Chehab
4f528afc a37462b9

+47 -3
+45 -3
drivers/media/v4l2-core/v4l2-clk.c
··· 9 9 */ 10 10 11 11 #include <linux/atomic.h> 12 + #include <linux/clk.h> 12 13 #include <linux/device.h> 13 14 #include <linux/errno.h> 14 15 #include <linux/list.h> ··· 38 37 struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id) 39 38 { 40 39 struct v4l2_clk *clk; 40 + struct clk *ccf_clk = clk_get(dev, id); 41 + 42 + if (PTR_ERR(ccf_clk) == -EPROBE_DEFER) 43 + return ERR_PTR(-EPROBE_DEFER); 44 + 45 + if (!IS_ERR_OR_NULL(ccf_clk)) { 46 + clk = kzalloc(sizeof(*clk), GFP_KERNEL); 47 + if (!clk) { 48 + clk_put(ccf_clk); 49 + return ERR_PTR(-ENOMEM); 50 + } 51 + clk->clk = ccf_clk; 52 + 53 + return clk; 54 + } 41 55 42 56 mutex_lock(&clk_lock); 43 57 clk = v4l2_clk_find(dev_name(dev)); ··· 71 55 72 56 if (IS_ERR(clk)) 73 57 return; 58 + 59 + if (clk->clk) { 60 + clk_put(clk->clk); 61 + kfree(clk); 62 + return; 63 + } 74 64 75 65 mutex_lock(&clk_lock); 76 66 ··· 115 93 116 94 int v4l2_clk_enable(struct v4l2_clk *clk) 117 95 { 118 - int ret = v4l2_clk_lock_driver(clk); 96 + int ret; 119 97 98 + if (clk->clk) 99 + return clk_prepare_enable(clk->clk); 100 + 101 + ret = v4l2_clk_lock_driver(clk); 120 102 if (ret < 0) 121 103 return ret; 122 104 ··· 146 120 { 147 121 int enable; 148 122 123 + if (clk->clk) 124 + return clk_disable_unprepare(clk->clk); 125 + 149 126 mutex_lock(&clk->lock); 150 127 151 128 enable = --clk->enable; ··· 166 137 167 138 unsigned long v4l2_clk_get_rate(struct v4l2_clk *clk) 168 139 { 169 - int ret = v4l2_clk_lock_driver(clk); 140 + int ret; 170 141 142 + if (clk->clk) 143 + return clk_get_rate(clk->clk); 144 + 145 + ret = v4l2_clk_lock_driver(clk); 171 146 if (ret < 0) 172 147 return ret; 173 148 ··· 190 157 191 158 int v4l2_clk_set_rate(struct v4l2_clk *clk, unsigned long rate) 192 159 { 193 - int ret = v4l2_clk_lock_driver(clk); 160 + int ret; 161 + 162 + if (clk->clk) { 163 + long r = clk_round_rate(clk->clk, rate); 164 + if (r < 0) 165 + return r; 166 + return clk_set_rate(clk->clk, r); 167 + } 168 + 169 + ret = v4l2_clk_lock_driver(clk); 194 170 195 171 if (ret < 0) 196 172 return ret;
+2
include/media/v4l2-clk.h
··· 22 22 struct module; 23 23 struct device; 24 24 25 + struct clk; 25 26 struct v4l2_clk { 26 27 struct list_head list; 27 28 const struct v4l2_clk_ops *ops; ··· 30 29 int enable; 31 30 struct mutex lock; /* Protect the enable count */ 32 31 atomic_t use_count; 32 + struct clk *clk; 33 33 void *priv; 34 34 }; 35 35