soc-camera -> v4l2-device: possible API extension requirements
Subsystems (3)
Quoted 13 lines · Hans Verkuil
Quoted 11 lines
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_subdevpointer successfully, then it increases the module's refcount to prevent it from being unloaded. This is by design.
Quoted 6 lines
Quoted 3 lines
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.
It really, really is :-)
This is actually not something v4l-related. It's a consequence of the new i2c API.
Quoted 47 lines
Quoted 28 lines
Quoted 2 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,
Quoted 1 line
after the probing it is turned off again. Then it is turned on at
first
Quoted 8 lines
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,
Quoted 3 lines
turn it on" (action: master clock on)
2. "probing for device Y completed (un)successfully" (action: master
clock
Quoted 7 lines
off, if successful - create
/dev/videoY)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 abovebut
Quoted 1 line
I am not sure if this is desired.
Quoted 9 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;
Quoted 2 lines
With just an msleep(OUR_HARD_CODED_TIMEOUT_WE_BELIEVE_SHOULD_BE_ENOUGH_FOR_ALL)?:-)
As long as we load the modules first (and that's what this function does) this isn't an issue. But in the future we (that is, Jean Delvare and myself) want to allow udev to load the module for you. To properly implement this we need to listen to some notification from the kernel.
It will be complicated and in the few cases where this is supported (not in v4l AFAIK) there is indeed an msleep() like that :-)
This part is work-in-progress, so it can safely be ignored.
Quoted 10 lines
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/videoNdevices 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.
This shouldn't be a problem at all. The v4l2_subdev pointer is just that:
a pointer to a struct created by the (in this case) i2c client instance. As long as you don't call that module it's not doing anything (assuming it didn't spawn some background task, of course). Just you just don't call the inactive subdev until you need it.
Regards,
Hans
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG
RFC 1/1 soc-camera -> v4l2-device partial patch for review only
Below is the first draft version of the first part of the soc-camera -> v4l2-device for one configuration (platform, host, and device drivers). It converts soc-camera to a platform driver and moves i2c device registration from platform into soc_camera.c. Please have a look if I'm doing anything obviously wrong. Also notice, that this patch is based on an older vkernel, because that's all I have for this platform ATM. Next I'm going to convert other platforms / drivers currently in the mainline, and that will complete the first step of the conversion. So, soc_camera.[hc] hunks should not change any more. I'm keeping the two soc_camera_video_start() and soc_camera_video_stop() hooks from device drivers into soc-camera for this first step. When converting to v4l2-device automatic module loading will make them redundant too.
---
arch/arm/mach-mx3/pcm037.c +14 -8
@@ -122,15 +122,24 @@ static struct imxi2c_board_data pcm037_i2c_adap[] = { };/* Board I2C devices. */ -static struct soc_camera_link iclink[] = { +static struct i2c_board_info __initdata pcm037_i2c_devices[] = { { - .bus_id =0 ,/* Must match with the camera ID */ +I2C_BOARD_INFO ("mt9t031" ,0x5d ), }, }; -static struct i2c_board_info __initdata pcm037_i2c_devices[] = { +static struct soc_camera_link iclink[] = { { -I2C_BOARD_INFO ("mt9t031" ,0x5d ), + .bus_id =0 ,/* Must match with the camera ID */ + .board_info = &pcm037_i2c_devices[0 ], + .i2c_adapter_id =2 , + }, +}; + +static struct platform_device pcm037_camera = { + .name ="soc-camera-pdrv" , + .id =-1 , + .dev = { .platform_data = &iclink[0 ], }, };
@@ -270,6 +279,7 @@ static struct platform_device *devices[] __initdata = { &pcm037_flash, &pcm037_eth, &otg_udc_device, + &pcm037_camera, }; static const struct fb_videomode fb_modedb[] = {
@@ -342,10 +352,6 @@ static void __init mxc_board_init(void)/* I2C */ mxc_i2c_register_adapters (pcm037_i2c_adap,ARRAY_SIZE (pcm037_i2c_adap)); -/* Cameras and accompanying chips on I2C #2 */ -i2c_register_board_info (2 , pcm037_i2c_devices, -ARRAY_SIZE (pcm037_i2c_devices)); -/* Display Interface #3 */ mxc_iomux_mode (IOMUX_MODE (MX31_PIN_LD0 ,IOMUX_CONFIG_FUNC ));mxc_iomux_mode (IOMUX_MODE (MX31_PIN_LD1 ,IOMUX_CONFIG_FUNC ));
drivers/media/video/mt9t031.c +44 -33
219 lines not on this page · raw message
drivers/media/video/mx3_camera.c +15 -8
@@ -502,11 +502,14 @@ static int mx3_camera_add_device(struct soc_camera_device *icd) }mx3_camera_activate (mx3_cam, icd); - ret = icd->ops->init (icd); -if (ret <0 ) { -clk_disable (mx3_cam->clk); - goto einit; - } +if (icd->ops) { + ret = icd->ops->init (icd); +if (ret <0 ) { +clk_disable (mx3_cam->clk); + goto einit; + } + }else + ret =0 ; mx3_cam->icd = icd;
@@ -910,9 +913,10 @@ static int mx3_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt) camera_flags = icd->ops->query_bus_param (icd); common_flags =soc_camera_bus_param_compatible (camera_flags, bus_flags); +dev_dbg (&ici->dev,"Flags cam: 0x%lx host: 0x%lx common: 0x%lx\n" , + camera_flags, bus_flags, common_flags);if (!common_flags) { -dev_dbg (&ici->dev,"no common flags: camera %lx, host %lx\n" , - camera_flags, bus_flags); +dev_dbg (&ici->dev,"no common flags" );return -EINVAL ; }
@@ -965,8 +969,11 @@ static int mx3_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)SOCAM_DATAWIDTH_4 ; ret = icd->ops->set_bus_param (icd, common_flags); -if (ret <0 ) +if (ret <0 ) { +dev_dbg (&ici->dev,"camera set_bus_param(%x) returned %d\n" , + common_flags, ret);return ret; + }/* * So far only gated clock mode is supported. Add a line
drivers/media/video/soc_camera.c +173 -148
482 lines not on this page · raw message
include/media/soc_camera.h +9 -8
@@ -12,6 +12,7 @@#ifndef SOC_CAMERA_H #define SOC_CAMERA_H +#include <linux/i2c.h> #include <linux/mutex.h> #include <linux/pm.h> #include <linux/videodev2.h>
@@ -97,6 +98,8 @@ struct soc_camera_link {unsigned int gpio;/* Per camera SOCAM_SENSOR_* bus flags */ unsigned long flags; +int i2c_adapter_id; +struct i2c_board_info *board_info;/* Optional callbacks to power on or off and reset the sensor */ int (*power)(struct device *,int );int (*reset)(struct device *);
@@ -112,17 +115,15 @@ static inline struct soc_camera_host *to_soc_camera_host(struct device *dev) return container_of(dev, struct soc_camera_host, dev); } -extern int soc_camera_host_register (struct soc_camera_host *ici); -extern void soc_camera_host_unregister (struct soc_camera_host *ici); -extern int soc_camera_device_register (struct soc_camera_device *icd); -extern void soc_camera_device_unregister (struct soc_camera_device *icd); +int soc_camera_host_register (struct soc_camera_host *ici); +void soc_camera_host_unregister (struct soc_camera_host *ici); -extern int soc_camera_video_start (struct soc_camera_device *icd); -extern void soc_camera_video_stop (struct soc_camera_device *icd); +int soc_camera_video_start (struct soc_camera_device *icd); +void soc_camera_video_stop (struct soc_camera_device *icd); -extern const struct soc_camera_data_format *soc_camera_format_by_fourcc ( +const struct soc_camera_data_format *soc_camera_format_by_fourcc (struct soc_camera_device *icd,unsigned int fourcc); -extern const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc ( +const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc (struct soc_camera_device *icd,unsigned int fourcc);struct soc_camera_data_format {