soc-camera -> v4l2-device: possible API extension requirements
Hi Guennadi,
Quoted 9 lines
Hi Hans,
I am doing the first step of the soc-camera integration with your v4l2-device API. As discussed on IRC, this first step changes the probing / releasing procedures in soc-camera to match v4l2-device expectations. While at it I came across a few points in your current API, which might need to be changed to be used with soc-camera, or maybe I just misunderstand something and you will be able to resolve my questions:
Quoted 7 lines
1. this can be kept, maybe, just it doesn't seem very comfortable to me:
the fact thatv4l2_i2c_new_subdev()relies on loading of the i2c driver for the subdevice. First, you put the call torequest_module()under #ifdef MODULE
which means, ifv4l2-common.cis compiled as a module, it will also assume that the i2c subdevice driver is a module, which doesn't have to be the case.
Ah, good catch. That's not right. The intention is to test whether module support is configured at all in the kernel, but I think that is CONFIG_MODULE or something like that. I'll change this.
Quoted 9 lines
Secondly, this means manual unloading and loading of the module at a later time will be impossible. No, I do not know why one would need this - apart from during development. But even the inability to do this during driver development already makes this questionable, IMHO. The only way I see possible so far, is, for example, if I have the pxa-camera driver and a sensor driver, then I can first unload the pxa-camera driver, which should cause
v4l2_device_unregister_subdev()to be called, then unload the sensor driver, then load the pxa-camera driver again, which should then auto-load the sensor driver.
In v4l devices these i2c devices are an integral part of the v4l device. It is not like the sensor i2c devices that are basically independent devices. Also, many i2c drivers used by v4l have internal state, so unloading them on the fly and reloading them later will in general not work.
If a v4l driver loads an i2c module and it can obtain a v4l2_subdev pointer successfully, then it increases the module's refcount to prevent it from being unloaded. This is by design.
Without autoprobing I also see no point in allowing an i2c module to be unloaded while in use. Reloading it won't re-attach it to the adapter anyway.
BTW, when developing I usually run 'make unload' from the top v4l-dvb directory. That will unload all v4l drivers.
Quoted 8 lines
2. In a comment you write to
v4l2_i2c_new_subdev():
/* Load an i2c sub-device. It assumes thati2c_get_adapdata(adapter)
returns thev4l2_deviceand thati2c_get_clientdata(client)returns thev4l2_subdev. */
I don't think this is possible with generic SoC i2c adapters. On soc-camera systems v4l2 subdevices are connected to generic i2c busses, so, you cannot require, that "i2c_get_adapdata(adapter)returns thev4l2_device."
Good point, I'll look at this. I don't think it is difficult to change, although I will probably wait until several pending driver conversions are merged. Then I can fix this in one sweep.
Quoted 17 lines
3. Currently soc-camera works in a way, that during probing of an i2c (sub)device, the Master Clock of the host camera interface is turned on, after the probing it is turned off again. Then it is turned on at first
open()and off at lastclose(). This should also be possible with the module autoloading inv4l2_i2c_new_subdev(), but this adds even more fragileness to the system.I think, a simple addition to the v4l2-device API could solve this problems and make the API more transparent:
1. "hi, I am driver X's probing routine, going to probe device Y, please, turn it on" (action: master clock on)
2. "probing for device Y completed (un)successfully" (action: master clock off, if successful - create
/dev/videoY)
Quoted 6 lines
3. "driver X is being unloaded, I am releasing device Y" (action: rip
/dev/videoY)We could agree on keeping
/dev/videoYeven when no sensor driver is present and just return-ENODEVonopen(), and thus simplify the above but I am not sure if this is desired.
I don't follow you. It is the adapter driver that controls which subdevs are loaded/probed, when they are loaded or unloaded and it can also decide when to start/stop the master clock. This new situation is different in that loading an i2c module will no longer work, the initiative has to come from the adapter/bridge/host/whatever driver who determines what has to be done based on platform board info.
Quoted 2 lines
I am sure I will have more questions or suggestions, I will keep posting to this thread as they appear.
Looking forward to this!
Regards,
Hans
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG
Quoted 6 lines · Hans Verkuil
In v4l devices these i2c devices are an integral part of the v4l device. It is not like the sensor i2c devices that are basically independent devices. Also, many i2c drivers used by v4l have internal state, so unloading them on the fly and reloading them later will in general not work.
Quoted 7 lines
If a v4l driver loads an i2c module and it can obtain a
v4l2_subdevpointer successfully, then it increases the module's refcount to prevent it from being unloaded. This is by design.Without autoprobing I also see no point in allowing an i2c module to be unloaded while in use. Reloading it won't re-attach it to the adapter anyway.
Yes, that's what I thought was the case, and that's also something that I am not quite convinced yet, that it is the best design for this situation.
Quoted 23 lines
Quoted 16 lines
3. Currently soc-camera works in a way, that during probing of an i2c (sub)device, the Master Clock of the host camera interface is turned on, after the probing it is turned off again. Then it is turned on at first
open()and off at lastclose(). This should also be possible with the module autoloading inv4l2_i2c_new_subdev(), but this adds even more fragileness to the system.I think, a simple addition to the v4l2-device API could solve this problems and make the API more transparent:
1. "hi, I am driver X's probing routine, going to probe device Y, please, turn it on" (action: master clock on)
2. "probing for device Y completed (un)successfully" (action: master clock off, if successful - create
/dev/videoY)Quoted 6 lines
3. "driver X is being unloaded, I am releasing device Y" (action: rip
/dev/videoY)We could agree on keeping
/dev/videoYeven when no sensor driver is present and just return-ENODEVonopen(), and thus simplify the above but I am not sure if this is desired.
Quoted 6 lines
I don't follow you. It is the adapter driver that controls which subdevs are loaded/probed, when they are loaded or unloaded and it can also decide when to start/stop the master clock. This new situation is different in that loading an i2c module will no longer work, the initiative has to come from the adapter/bridge/host/whatever driver who determines what has to be done based on platform board info.
Ok, but how are we going to address this your comment:
/* Note: it is possible in the future that c->driver is NULL if the driver is still being loaded. We need better support from the kernel so that we can easily wait for the load to finish. */ if (client == NULL || client->driver == NULL) return NULL;
With just an msleep(OUR_HARD_CODED_TIMEOUT_WE_BELIEVE_SHOULD_BE_ENOUGH_FOR_ALL)?:-)
Also one more point, that I don't see a problem currently with, but that we have to keep in mind: soc-camera is aiming at supporting several devices on one interface. E.g., there is a design, where two cameras are connected to a host, that actually is only supposed to support one camera at a time. So, they use some extra switching logic to activate one or another camera. In this case the platform registers two cameras, they are both probed - one after another, and that's also the reason, why the default state "all /dev/videoN devices are closed" must be - no fixed connection between a subdevice and a device. We actually have already discussed this before, I think, just something to keep an eye on.
Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
Quoted 11 lines · On Wednesday 18 March 2009 09:41:58 Hans Verkuil wrote:
Hi Guennadi,
Quoted 8 lines
2. In a comment you write to
v4l2_i2c_new_subdev():
/* Load an i2c sub-device. It assumes thati2c_get_adapdata(adapter)
returns thev4l2_deviceand thati2c_get_clientdata(client)returns thev4l2_subdev. */
I don't think this is possible with generic SoC i2c adapters. On soc-camera systems v4l2 subdevices are connected to generic i2c busses, so, you cannot require, that "i2c_get_adapdata(adapter)returns thev4l2_device."
Quoted 3 lines
Good point, I'll look at this. I don't think it is difficult to change, although I will probably wait until several pending driver conversions are merged. Then I can fix this in one sweep.
The fix for this is simple: just add an extra struct v4l2_device to v4l2_i2c_new_(probed_)device and let those functions use that instead of calling i2c_get_adapdata(). It's the only place where it is currently used.
But I'm going to postpone implementing this until all outstanding conversion trees are merged. However, you can just do it yourself while working on the soc-camera conversion.
Regards,
Hans
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG