[RFD] use-counting V4L2 clocks

Guennadi Liakhovetski
2013-09-12T19:14:37Z

Hi all

We've got a broken driver in 3.11 and in 3.12-rc and we don't have a clear
way to properly fix it. The problem has been originally reported and
discussed in [1], a patch-set to fix the problem has been proposed in [2],
which actually lead to the topic of this mail - whether or not calls to
v4l2_clk_enable() and v4l2_clk_disable(), or respectively to s_power(1)
and s_power(0) subdevice core operations should be balanced. Currently
they aren't in em28xx driver, and the V4L2 clock API throws warnings on
attempts to disable already disabled clock. Patch [3] attempted to fix
that. So, the question is - whether to enforce balanced power on / off
calls, or to remove the warning.

Let's try to have a look at other examples in the kernel:

1. runtime PM: pm_runtime_get*() / pm_runtime_put*() only work, if
balanced, but no warning is issued, if the balance is broken, AFAICS.

2. clock API: clk_enable() / clk_disable() in drivers/clk/clk.c have to be
balanced and a warning is issued, if clk_disable() is called for an
already disabled clock.

3. regulator API: regulator_enable() / regulator_disable() have to be
balanced. A warning is issued if regulator_disable() is called for a
disabled regulator.

So, I think, our V4L2 clock enable / disable calls should be balanced, and
to enforce that a warning is helpful. Other opinions?

Thanks
Guennadi

[1] http://thread.gmane.org/gmane.linux.drivers.video-input-infrastructure/68028
[2] http://thread.gmane.org/gmane.linux.drivers.video-input-infrastructure/68510
[3] http://thread.gmane.org/gmane.linux.drivers.video-input-infrastructure/68864