Skip to contentSkip to conversation

soc-camera conversions

PATCH In review Guennadi Liakhovetski 6 participants 37 messages May 15, 2009 – Jun 9, 2009

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v2 cover soc-camera conversions

Hi all,

this is the next round of soc-camera conversions. Run-tested on i.MX31, PXA270, SH7722, compile-tested only for i.MX1. It should have been a "straight-forward" port of the previous version to a more current tree, but then I started converting soc_camera_platform, and things became a bit more complex... As a bonus, now soc-camera can handle not only i2c subdevices, and we can even drop the CONFIG_I2C dependency again. I'll also upload a comlpete stack somewhere a bit later, for example for those, wishing to test it on i.MX31, otherwise the series will not apply cleanly.

I'd like to push the first 8 of them asap, 9 and 10 will still have to be reworked

Paul, I put you on "cc" on all patches, because, unfortunately, several of them affect arch/sh. But I'll mention it explicitly in each such patch.

Have fun.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#1 lore raw

PATCH v2 1/10 soc-camera: prepare soc_camera_platform.c and its users for conversion

soc_camera_platform.c is only used by y SuperH ap325rxa board. This patch converts soc_camera_platform.c and its users for the soc-camera platform- device conversion and also extends soc-camera core to handle non-I2C cameras.

---

Paul, may I pull this one over v4l? These patches only touch video functionality. Then I would need your ack.

 arch/sh/boards/board-ap325rxa.c     |   43 ++++++++++++++++++------
 drivers/media/video/soc_camera.c    |   61 ++++++++++++++++++++++++++--------
 include/media/soc_camera.h          |    6 +++
 include/media/soc_camera_platform.h |    2 +
 4 files changed, 86 insertions(+), 26 deletions(-)
arch/sh/boards/board-ap325rxa.c +32 -11
index cd1fcc0..0a5f97b 100644
@@ -304,6 +304,9 @@ static int camera_set_capture(struct soc_camera_platform_info *info,
 	return ret;
 }
 
+static int ap325rxa_camera_add(struct soc_camera_link *icl, struct device *dev);
+static void ap325rxa_camera_del(struct soc_camera_link *icl);
+
 static struct soc_camera_platform_info camera_info = {
 	.iface = 0,
 	.format_name = "UYVY",
@@ -317,6 +320,10 @@ static struct soc_camera_platform_info camera_info = {
 	.bus_param = SOCAM_PCLK_SAMPLE_RISING | SOCAM_HSYNC_ACTIVE_HIGH |
 	SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_MASTER | SOCAM_DATAWIDTH_8,
 	.set_capture = camera_set_capture,
+	.link = {
+		.add_device	= ap325rxa_camera_add,
+		.del_device	= ap325rxa_camera_del,
+	},
 };
 
 static struct platform_device camera_device = {
@@ -326,15 +333,20 @@ static struct platform_device camera_device = {
 	},
 };
 
-static int __init camera_setup(void)
+static int ap325rxa_camera_add(struct soc_camera_link *icl,
+			       struct device *dev)
 {
-	if (camera_probe() > 0)
-		platform_device_register(&camera_device);
+	if (icl != &camera_info.link || camera_probe() <= 0)
+		return -ENODEV;
 
-	return 0;
+	return platform_device_register(&camera_device);
 }
-late_initcall(camera_setup);
 
+static void ap325rxa_camera_del(struct soc_camera_link *icl)
+{
+	if (icl == &camera_info.link)
+		platform_device_unregister(&camera_device);
+}
 #endif /* CONFIG_I2C */
 
 static int ov7725_power(struct device *dev, int mode)
@@ -414,11 +426,19 @@ static struct ov772x_camera_info ov7725_info = {
 	},
 };
 
-static struct platform_device ap325rxa_camera = {
-	.name	= "soc-camera-pdrv",
-	.id	= 0,
-	.dev	= {
-		.platform_data = &ov7725_info.link,
+static struct platform_device ap325rxa_camera[] = {
+	{
+		.name	= "soc-camera-pdrv",
+		.id	= 0,
+		.dev	= {
+			.platform_data = &ov7725_info.link,
+		},
+	}, {
+		.name	= "soc-camera-pdrv",
+		.id	= 1,
+		.dev	= {
+			.platform_data = &camera_info.link,
+		},
 	},
 };
 
@@ -429,7 +449,8 @@ static struct platform_device *ap325rxa_devices[] __initdata = {
 	&ceu_device,
 	&nand_flash_device,
 	&sdcard_cn3_device,
-	&ap325rxa_camera,
+	&ap325rxa_camera[0],
+	&ap325rxa_camera[1],
 };
 
 static struct spi_board_info ap325rxa_spi_devices[] = {
drivers/media/video/soc_camera.c +46 -15

91 lines not on this page · raw message

include/media/soc_camera.h +6 -0
index 23ecead..813e120 100644
@@ -102,6 +102,12 @@ struct soc_camera_link {
 	int i2c_adapter_id;
 	struct i2c_board_info *board_info;
 	const char *module_name;
+	/*
+	 * For non-I2C devices platform platform has to provide methods to
+	 * add a device to the system and to remove
+	 */
+	int (*add_device)(struct soc_camera_link *, struct device *);
+	void (*del_device)(struct soc_camera_link *);
 	/* Optional callbacks to power on or off and reset the sensor */
 	int (*power)(struct device *, int);
 	int (*reset)(struct device *);
include/media/soc_camera_platform.h +2 -0
index 1d092b4..af224de 100644
@@ -12,6 +12,7 @@
 #define __SOC_CAMERA_H__
 
 #include <linux/videodev2.h>
+#include <media/soc_camera.h>
 
 struct soc_camera_platform_info {
 	int iface;
@@ -21,6 +22,7 @@ struct soc_camera_platform_info {
 	unsigned long bus_param;
 	void (*power)(int);
 	int (*set_capture)(struct soc_camera_platform_info *info, int enable);
+	struct soc_camera_link link;
 };
 
 #endif /* __SOC_CAMERA_H__ */
Signature · 1 line
1.6.2.4
#2 lore raw

PATCH v2 2/10 ARM: convert pcm037 to the new platform-device soc-camera interface

In reply to Guennadi Liakhovetski

---

This is actually a completion to the other single patches I've sent earlier for various boards. As I said, pcm037 doesn't have all its outstanding patches in next yet, so, you'll need to collect them from trees / lists, or get them when I upload them.

 arch/arm/mach-mx3/pcm037.c |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)
arch/arm/mach-mx3/pcm037.c +18 -8
index bfa814d..af49f03 100644
@@ -293,9 +293,18 @@ static int pcm037_camera_power(struct device *dev, int on)
 	return 0;
 }
 
+static struct i2c_board_info pcm037_i2c_2_devices[] = {
+	{
+		I2C_BOARD_INFO("mt9t031", 0x5d),
+	},
+};
+
 static struct soc_camera_link iclink = {
-	.bus_id	= 0,			/* Must match with the camera ID */
-	.power = pcm037_camera_power,
+	.bus_id		= 0,		/* Must match with the camera ID */
+	.power		= pcm037_camera_power,
+	.board_info	= &pcm037_i2c_2_devices[0],
+	.i2c_adapter_id	= 2,
+	.module_name	= "mt9t031",
 };
 
 static struct i2c_board_info pcm037_i2c_devices[] = {
@@ -308,9 +317,10 @@ static struct i2c_board_info pcm037_i2c_devices[] = {
 	}
 };
 
-static struct i2c_board_info pcm037_i2c_2_devices[] = {
-	{
-		I2C_BOARD_INFO("mt9t031", 0x5d),
+static struct platform_device pcm037_camera = {
+	.name	= "soc-camera-pdrv",
+	.id	= 0,
+	.dev	= {
 		.platform_data = &iclink,
 	},
 };
@@ -390,6 +400,9 @@ static struct platform_device *devices[] __initdata = {
 	&pcm037_flash,
 	&pcm037_eth,
 	&pcm037_sram_device,
+#if defined(CONFIG_I2C_IMX) || defined(CONFIG_I2C_IMX_MODULE)
+	&pcm037_camera,
+#endif
 };
 
 static struct ipu_platform_data mx3_ipu_data = {
@@ -447,9 +460,6 @@ static void __init mxc_board_init(void)
 	i2c_register_board_info(1, pcm037_i2c_devices,
 			ARRAY_SIZE(pcm037_i2c_devices));
 
-	i2c_register_board_info(2, pcm037_i2c_2_devices,
-			ARRAY_SIZE(pcm037_i2c_2_devices));
-
 	mxc_register_device(&mxc_i2c_device1, &pcm037_i2c_1_data);
 	mxc_register_device(&mxc_i2c_device2, &pcm037_i2c_2_data);
 #endif
Signature · 1 line
1.6.2.4
maintainer
#3 lore raw

Re: [PATCH 02/10 v2] ARM: convert pcm037 to the new platform-device soc-camera interface

Quoted 7 lines · Guennadi Liakhovetski

---

This is actually a completion to the other single patches I've sent earlier for various boards. As I said, pcm037 doesn't have all its outstanding patches in next yet, so, you'll need to collect them from trees / lists, or get them when I upload them.

As I haven't got camera support for pcm037 in my tree yet, you can combine this with the patch which adds camera support. How are we going to sync this with the according changes to soc-camera?

Sascha

Quoted 67 lines
 arch/arm/mach-mx3/pcm037.c |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)
arch/arm/mach-mx3/pcm037.c +18 -8
index bfa814d..af49f03 100644
@@ -293,9 +293,18 @@ static int pcm037_camera_power(struct device *dev, int on)
 	return 0;
 }
 
+static struct i2c_board_info pcm037_i2c_2_devices[] = {
+	{
+		I2C_BOARD_INFO("mt9t031", 0x5d),
+	},
+};
+
 static struct soc_camera_link iclink = {
-	.bus_id	= 0,			/* Must match with the camera ID */
-	.power = pcm037_camera_power,
+	.bus_id		= 0,		/* Must match with the camera ID */
+	.power		= pcm037_camera_power,
+	.board_info	= &pcm037_i2c_2_devices[0],
+	.i2c_adapter_id	= 2,
+	.module_name	= "mt9t031",
 };
 
 static struct i2c_board_info pcm037_i2c_devices[] = {
@@ -308,9 +317,10 @@ static struct i2c_board_info pcm037_i2c_devices[] = {
 	}
 };
 
-static struct i2c_board_info pcm037_i2c_2_devices[] = {
-	{
-		I2C_BOARD_INFO("mt9t031", 0x5d),
+static struct platform_device pcm037_camera = {
+	.name	= "soc-camera-pdrv",
+	.id	= 0,
+	.dev	= {
 		.platform_data = &iclink,
 	},
 };
@@ -390,6 +400,9 @@ static struct platform_device *devices[] __initdata = {
 	&pcm037_flash,
 	&pcm037_eth,
 	&pcm037_sram_device,
+#if defined(CONFIG_I2C_IMX) || defined(CONFIG_I2C_IMX_MODULE)
+	&pcm037_camera,
+#endif
 };
 
 static struct ipu_platform_data mx3_ipu_data = {
@@ -447,9 +460,6 @@ static void __init mxc_board_init(void)
 	i2c_register_board_info(1, pcm037_i2c_devices,
 			ARRAY_SIZE(pcm037_i2c_devices));
 
-	i2c_register_board_info(2, pcm037_i2c_2_devices,
-			ARRAY_SIZE(pcm037_i2c_2_devices));
-
 	mxc_register_device(&mxc_i2c_device1, &pcm037_i2c_1_data);
 	mxc_register_device(&mxc_i2c_device2, &pcm037_i2c_2_data);
 #endif
Signature · 1 line
1.6.2.4
Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#4 lore raw

Re: [PATCH 02/10 v2] ARM: convert pcm037 to the new platform-device soc-camera interface

Quoted 11 lines · Sascha Hauer
Quoted 7 lines · Guennadi Liakhovetski

---

This is actually a completion to the other single patches I've sent earlier for various boards. As I said, pcm037 doesn't have all its outstanding patches in next yet, so, you'll need to collect them from trees / lists, or get them when I upload them.

As I haven't got camera support for pcm037 in my tree yet, you can combine this with the patch which adds camera support.

Hm, so, I will have to redo that:-(

Quoted 1 line

How are we going to sync this with the according changes to soc-camera?

As I already replied to Russell, there's just one requirement for _this_ patch - it has to go in after this one:

http://git.kernel.org/?p=linux/kernel/git/mchehab/linux-next.git;a=commit;h=2bda41a0e9d42cf977a99e8df4fd6e331bb4f50d

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

maintainer
#5 lore raw

Re: [PATCH 02/10 v2] ARM: convert pcm037 to the new platform-device soc-camera interface

Quoted 14 lines · Guennadi Liakhovetski
Quoted 11 lines · Sascha Hauer
Quoted 7 lines · Guennadi Liakhovetski

---

This is actually a completion to the other single patches I've sent earlier for various boards. As I said, pcm037 doesn't have all its outstanding patches in next yet, so, you'll need to collect them from trees / lists, or get them when I upload them.

As I haven't got camera support for pcm037 in my tree yet, you can combine this with the patch which adds camera support.

Quoted 8 lines

Hm, so, I will have to redo that:-(

Quoted 1 line

How are we going to sync this with the according changes to soc-camera?

As I already replied to Russell, there's just one requirement for _this_ patch - it has to go in after this one:

http://git.kernel.org/?p=linux/kernel/git/mchehab/linux-next.git;a=commit;h=2bda41a0e9d42cf977a99e8df4fd6e331bb4f50d

Ok, then Russell can pull my tree containing the camera patch for pcm037 and he will take care of the correct order, right?

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#6 lore raw

Re: [PATCH 02/10 v2] ARM: convert pcm037 to the new platform-device soc-camera interface

Quoted 19 lines · Sascha Hauer
Quoted 18 lines · Guennadi Liakhovetski
Quoted 11 lines · Sascha Hauer
Quoted 7 lines · Guennadi Liakhovetski

---

This is actually a completion to the other single patches I've sent earlier for various boards. As I said, pcm037 doesn't have all its outstanding patches in next yet, so, you'll need to collect them from trees / lists, or get them when I upload them.

As I haven't got camera support for pcm037 in my tree yet, you can combine this with the patch which adds camera support.

Hm, so, I will have to redo that:-(

Quoted 1 line

How are we going to sync this with the according changes to soc-camera?

Quoted 7 lines
Quoted 4 lines

As I already replied to Russell, there's just one requirement for _this_ patch - it has to go in after this one:

http://git.kernel.org/?p=linux/kernel/git/mchehab/linux-next.git;a=commit;h=2bda41a0e9d42cf977a99e8df4fd6e331bb4f50d

Ok, then Russell can pull my tree containing the camera patch for pcm037 and he will take care of the correct order, right?

It would be correct, yes, if your tree was completely on one side of the above patch. But if you apply patches as you have them in your tree, i.e., first add camera support, then convert to platform driver, then Russell would have to first pull the first part of your tree, then v4l, then the econd part of your tree... which, I think, wouldn't be fair to require from him:-) so, you either would have to send him two pull requests with a request to pull v4l inbetween, or merge the two patches.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#7 lore raw

PATCH 1/1 pcm037: add MT9T031 camera support

In reply to Sascha Hauer

From: Guennadi Liakhovetski <[email protected]>

Add support for the MT9T031 CMOS camera sensor from Aptina to the PCM037 board. Also add two I2C iomux pin definitions, needed for pcm037. Also remove now unneeded #ifdef CONFIG_I2C_IMX.

---

Quoted 4 lines · Sascha Hauer
Quoted 3 lines · Guennadi Liakhovetski

---

Quoted 8 lines
Quoted 4 lines

This is actually a completion to the other single patches I've sent earlier for various boards. As I said, pcm037 doesn't have all its outstanding patches in next yet, so, you'll need to collect them from trees / lists, or get them when I upload them.

As I haven't got camera support for pcm037 in my tree yet, you can combine this with the patch which adds camera support. How are we going to sync this with the according changes to soc-camera?

Two patches merged, based on your current mxc-master plus cherry-picked patches from v4l-dvb. Tested to build and run. As I said, it depends on

http://git.kernel.org/?p=linux/kernel/git/mchehab/linux-next.git;a=commitdiff;h=2bda41a0e9d42cf977a99e8df4fd6e331bb4f50d

from the v4l -next tree.

 arch/arm/mach-mx3/pcm037.c                 |  115 ++++++++++++++++++++++++---
 arch/arm/plat-mxc/include/mach/iomux-mx3.h |    2 +
 2 files changed, 104 insertions(+), 13 deletions(-)
arch/arm/mach-mx3/pcm037.c +102 -13
index c6f61a1..aae7fe7 100644
@@ -18,7 +18,7 @@
 
 #include <linux/types.h>
 #include <linux/init.h>
-
+#include <linux/dma-mapping.h>
 #include <linux/platform_device.h>
 #include <linux/mtd/physmap.h>
 #include <linux/mtd/plat-ram.h>
@@ -33,22 +33,23 @@
 #include <linux/irq.h>
 #include <linux/fsl_devices.h>
 
-#include <mach/hardware.h>
+#include <media/soc_camera.h>
+
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <asm/mach/time.h>
 #include <asm/mach/map.h>
+#include <mach/board-pcm037.h>
 #include <mach/common.h>
+#include <mach/hardware.h>
+#include <mach/i2c.h>
 #include <mach/imx-uart.h>
 #include <mach/iomux-mx3.h>
 #include <mach/ipu.h>
-#include <mach/board-pcm037.h>
+#include <mach/mmc.h>
+#include <mach/mx3_camera.h>
 #include <mach/mx3fb.h>
 #include <mach/mxc_nand.h>
-#include <mach/mmc.h>
-#ifdef CONFIG_I2C_IMX
-#include <mach/i2c.h>
-#endif
 
 #include "devices.h"
 
@@ -56,6 +57,8 @@ static unsigned int pcm037_pins[] = {
 	/* I2C */
 	MX31_PIN_CSPI2_MOSI__SCL,
 	MX31_PIN_CSPI2_MISO__SDA,
+	MX31_PIN_CSPI2_SS2__I2C3_SDA,
+	MX31_PIN_CSPI2_SCLK__I2C3_SCL,
 	/* SDHC1 */
 	MX31_PIN_SD1_DATA3__SD1_DATA3,
 	MX31_PIN_SD1_DATA2__SD1_DATA2,
@@ -120,6 +123,22 @@ static unsigned int pcm037_pins[] = {
 	MX31_PIN_D3_SPL__D3_SPL,
 	MX31_PIN_D3_CLS__D3_CLS,
 	MX31_PIN_LCS0__GPI03_23,
+	/* CSI */
+	IOMUX_MODE(MX31_PIN_CSI_D5, IOMUX_CONFIG_GPIO),
+	MX31_PIN_CSI_D6__CSI_D6,
+	MX31_PIN_CSI_D7__CSI_D7,
+	MX31_PIN_CSI_D8__CSI_D8,
+	MX31_PIN_CSI_D9__CSI_D9,
+	MX31_PIN_CSI_D10__CSI_D10,
+	MX31_PIN_CSI_D11__CSI_D11,
+	MX31_PIN_CSI_D12__CSI_D12,
+	MX31_PIN_CSI_D13__CSI_D13,
+	MX31_PIN_CSI_D14__CSI_D14,
+	MX31_PIN_CSI_D15__CSI_D15,
+	MX31_PIN_CSI_HSYNC__CSI_HSYNC,
+	MX31_PIN_CSI_MCLK__CSI_MCLK,
+	MX31_PIN_CSI_PIXCLK__CSI_PIXCLK,
+	MX31_PIN_CSI_VSYNC__CSI_VSYNC,
 };
 
 static struct physmap_flash_data pcm037_flash_data = {
@@ -250,19 +269,43 @@ static struct mxc_nand_platform_data pcm037_nand_board_info = {
 	.hw_ecc = 1,
 };
 
-#ifdef CONFIG_I2C_IMX
 static struct imxi2c_platform_data pcm037_i2c_1_data = {
 	.bitrate = 100000,
 };
 
+static struct imxi2c_platform_data pcm037_i2c_2_data = {
+	.bitrate = 20000,
+};
+
 static struct at24_platform_data board_eeprom = {
 	.byte_len = 4096,
 	.page_size = 32,
 	.flags = AT24_FLAG_ADDR16,
 };
 
+static int pcm037_camera_power(struct device *dev, int on)
+{
+	/* disable or enable the camera in X7 or X8 PCM970 connector */
+	gpio_set_value(IOMUX_TO_GPIO(MX31_PIN_CSI_D5), !on);
+	return 0;
+}
+
+static struct i2c_board_info pcm037_i2c_2_devices[] = {
+	{
+		I2C_BOARD_INFO("mt9t031", 0x5d),
+	},
+};
+
+static struct soc_camera_link iclink = {
+	.bus_id		= 0,		/* Must match with the camera ID */
+	.power		= pcm037_camera_power,
+	.board_info	= &pcm037_i2c_2_devices[0],
+	.i2c_adapter_id	= 2,
+	.module_name	= "mt9t031",
+};
+
 static struct i2c_board_info pcm037_i2c_devices[] = {
-       {
+	{
 		I2C_BOARD_INFO("at24", 0x52), /* E0=0, E1=1, E2=0 */
 		.platform_data = &board_eeprom,
 	}, {
@@ -270,7 +313,14 @@ static struct i2c_board_info pcm037_i2c_devices[] = {
 		.type = "pcf8563",
 	}
 };
-#endif
+
+static struct platform_device pcm037_camera = {
+	.name	= "soc-camera-pdrv",
+	.id	= 0,
+	.dev	= {
+		.platform_data = &iclink,
+	},
+};
 
 /* Not connected by default */
 #ifdef PCM970_SDHC_RW_SWITCH
@@ -334,9 +384,41 @@ static struct imxmmc_platform_data sdhc_pdata = {
 	.exit = pcm970_sdhc1_exit,
 };
 
+struct mx3_camera_pdata camera_pdata = {
+	.dma_dev	= &mx3_ipu.dev,
+	.flags		= MX3_CAMERA_DATAWIDTH_8 | MX3_CAMERA_DATAWIDTH_10,
+	.mclk_10khz	= 2000,
+};
+
+static int __init pcm037_camera_alloc_dma(const size_t buf_size)
+{
+	dma_addr_t dma_handle;
+	void *buf;
+	int dma;
+
+	if (buf_size < 2 * 1024 * 1024)
+		return -EINVAL;
+
+	buf = dma_alloc_coherent(NULL, buf_size, &dma_handle, GFP_KERNEL);
+	if (!buf) {
+		pr_err("%s: cannot allocate camera buffer-memory\n", __func__);
+		return -ENOMEM;
+	}
+
+	memset(buf, 0, buf_size);
+
+	dma = dma_declare_coherent_memory(&mx3_camera.dev,
+					dma_handle, dma_handle, buf_size,
+					DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE);
+
+	/* The way we call dma_declare_coherent_memory only a malloc can fail */
+	return dma & DMA_MEMORY_MAP ? 0 : -ENOMEM;
+}
+
 static struct platform_device *devices[] __initdata = {
 	&pcm037_flash,
 	&pcm037_sram_device,
+	&pcm037_camera,
 };
 
 static struct ipu_platform_data mx3_ipu_data = {
@@ -414,19 +496,26 @@ static void __init mxc_board_init(void)
 		platform_device_register(&pcm037_eth);
 	}
 
-
-#ifdef CONFIG_I2C_IMX
+	/* I2C adapters and devices */
 	i2c_register_board_info(1, pcm037_i2c_devices,
 			ARRAY_SIZE(pcm037_i2c_devices));
 
 	mxc_register_device(&mxc_i2c_device1, &pcm037_i2c_1_data);
-#endif
+	mxc_register_device(&mxc_i2c_device2, &pcm037_i2c_2_data);
+
 	mxc_register_device(&mxc_nand_device, &pcm037_nand_board_info);
 	mxc_register_device(&mxcsdhc_device0, &sdhc_pdata);
 	mxc_register_device(&mx3_ipu, &mx3_ipu_data);
 	mxc_register_device(&mx3_fb, &mx3fb_pdata);
 	if (!gpio_usbotg_hs_activate())
 		mxc_register_device(&mxc_otg_udc_device, &usb_pdata);
+
+	/* CSI */
+	/* Camera power: default - off */
+	gpio_direction_output(IOMUX_TO_GPIO(MX31_PIN_CSI_D5), 1);
+
+	if (!pcm037_camera_alloc_dma(4 * 1024 * 1024))
+		mxc_register_device(&mx3_camera, &camera_pdata);
 }
 
 static void __init pcm037_timer_init(void)
arch/arm/plat-mxc/include/mach/iomux-mx3.h +2 -0
index 27f8d1b..2eb182f 100644
@@ -602,6 +602,8 @@ enum iomux_pins {
 #define MX31_PIN_I2C_DAT__SDA		IOMUX_MODE(MX31_PIN_I2C_DAT, IOMUX_CONFIG_FUNC)
 #define MX31_PIN_DCD_DTE1__I2C2_SDA	IOMUX_MODE(MX31_PIN_DCD_DTE1, IOMUX_CONFIG_ALT2)
 #define MX31_PIN_RI_DTE1__I2C2_SCL	IOMUX_MODE(MX31_PIN_RI_DTE1, IOMUX_CONFIG_ALT2)
+#define MX31_PIN_CSPI2_SS2__I2C3_SDA	IOMUX_MODE(MX31_PIN_CSPI2_SS2, IOMUX_CONFIG_ALT1)
+#define MX31_PIN_CSPI2_SCLK__I2C3_SCL	IOMUX_MODE(MX31_PIN_CSPI2_SCLK, IOMUX_CONFIG_ALT1)
 #define MX31_PIN_CSI_D4__CSI_D4		IOMUX_MODE(MX31_PIN_CSI_D4, IOMUX_CONFIG_FUNC)
 #define MX31_PIN_CSI_D5__CSI_D5		IOMUX_MODE(MX31_PIN_CSI_D5, IOMUX_CONFIG_FUNC)
 #define MX31_PIN_CSI_D6__CSI_D6		IOMUX_MODE(MX31_PIN_CSI_D6, IOMUX_CONFIG_FUNC)
Signature · 1 line
1.6.2.4
#8 lore raw

PATCH v2 3/10 soc_camera_platform: pass device pointer from soc-camera core on .add_device()

In reply to Guennadi Liakhovetski

Add a struct device pointer to struct soc_camera_platform_info and let the user (ap325rxa) pass it down to soc_camera_platform.c in its .add_device() method.

---

Paul, another mixed one, should be quite easy to review though:-)

 arch/sh/boards/board-ap325rxa.c     |    2 ++
 include/media/soc_camera_platform.h |    3 +++
 2 files changed, 5 insertions(+), 0 deletions(-)
arch/sh/boards/board-ap325rxa.c +2 -0
index 0a5f97b..ac964e4 100644
@@ -339,6 +339,8 @@ static int ap325rxa_camera_add(struct soc_camera_link *icl,
 	if (icl != &camera_info.link || camera_probe() <= 0)
 		return -ENODEV;
 
+	camera_info.dev = dev;
+
 	return platform_device_register(&camera_device);
 }
 
include/media/soc_camera_platform.h +3 -0
index af224de..3e8f020 100644
@@ -14,6 +14,8 @@
 #include <linux/videodev2.h>
 #include <media/soc_camera.h>
 
+struct device;
+
 struct soc_camera_platform_info {
 	int iface;
 	char *format_name;
@@ -21,6 +23,7 @@ struct soc_camera_platform_info {
 	struct v4l2_pix_format format;
 	unsigned long bus_param;
 	void (*power)(int);
+	struct device *dev;
 	int (*set_capture)(struct soc_camera_platform_info *info, int enable);
 	struct soc_camera_link link;
 };
Signature · 1 line
1.6.2.4
#9 lore raw

PATCH v2 4/10 soc-camera: convert to platform device

In reply to Guennadi Liakhovetski

Convert soc-camera core and all drivers to platform device API. We already converted platforms to register a platform device for each soc-camera client, now we remove the compatibility code and switch completely to the new scheme. This is a preparatory step for the v4l2-subdev conversion.

---

Ok, here goes the first monster... But - all only under the v4l tree, no platform files.

 drivers/media/video/mt9m001.c              |  113 ++++----
 drivers/media/video/mt9m111.c              |  152 ++++++-----
 drivers/media/video/mt9t031.c              |  113 ++++----
 drivers/media/video/mt9v022.c              |  118 ++++----
 drivers/media/video/mx3_camera.c           |   27 ++-
 drivers/media/video/ov772x.c               |  155 ++++++-----
 drivers/media/video/pxa_camera.c           |   27 ++-
 drivers/media/video/sh_mobile_ceu_camera.c |   13 +-
 drivers/media/video/soc_camera.c           |  426 ++++++++++++++--------------
 drivers/media/video/soc_camera_platform.c  |   49 ++--
 drivers/media/video/tw9910.c               |  106 ++++---
 include/media/soc_camera.h                 |   27 +-
 include/media/soc_camera_platform.h        |    3 +-
 13 files changed, 689 insertions(+), 640 deletions(-)
drivers/media/video/mt9m001.c +53 -60
index 459c04c..b0f4ad5 100644
@@ -69,8 +69,6 @@ static const struct soc_camera_data_format mt9m001_monochrome_formats[] = {
 };
 
 struct mt9m001 {
-	struct i2c_client *client;
-	struct soc_camera_device icd;
 	int model;	/* V4L2_IDENT_MT9M001* codes from v4l2-chip-ident.h */
 	unsigned char autoexposure;
 };
@@ -111,11 +109,11 @@ static int reg_clear(struct i2c_client *client, const u8 reg,
 
 static int mt9m001_init(struct soc_camera_device *icd)
 {
-	struct i2c_client *client = to_i2c_client(icd->control);
-	struct soc_camera_link *icl = client->dev.platform_data;
+	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
+	struct soc_camera_link *icl = to_soc_camera_link(icd);
 	int ret;
 
-	dev_dbg(icd->vdev->parent, "%s\n", __func__);
+	dev_dbg(&icd->dev, "%s\n", __func__);
 
 	if (icl->power) {
 		ret = icl->power(&client->dev, 1);
@@ -147,8 +145,8 @@ static int mt9m001_init(struct soc_camera_device *icd)
 
 static int mt9m001_release(struct soc_camera_device *icd)
 {
-	struct i2c_client *client = to_i2c_client(icd->control);
-	struct soc_camera_link *icl = client->dev.platform_data;
+	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
+	struct soc_camera_link *icl = to_soc_camera_link(icd);
 
 	/* Disable the chip */
 	reg_write(client, MT9M001_OUTPUT_CONTROL, 0);
@@ -161,7 +159,7 @@ static int mt9m001_release(struct soc_camera_device *icd)
 
 static int mt9m001_start_capture(struct soc_camera_device *icd)
 {
-	struct i2c_client *client = to_i2c_client(icd->control);
+	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
 
 	/* Switch to master "normal" mode */
 	if (reg_write(client, MT9M001_OUTPUT_CONTROL, 2) < 0)
@@ -171,7 +169,7 @@ static int mt9m001_start_capture(struct soc_camera_device *icd)
 
 static int mt9m001_stop_capture(struct soc_camera_device *icd)
 {
-	struct i2c_client *client = to_i2c_client(icd->control);
+	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
 
 	/* Stop sensor readout */
 	if (reg_write(client, MT9M001_OUTPUT_CONTROL, 0) < 0)
@@ -182,8 +180,7 @@ static int mt9m001_stop_capture(struct soc_camera_device *icd)
 static int mt9m001_set_bus_param(struct soc_camera_device *icd,
 				 unsigned long flags)
 {
-	struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
-	struct soc_camera_link *icl = mt9m001->client->dev.platform_data;
+	struct soc_camera_link *icl = to_soc_camera_link(icd);
 	unsigned long width_flag = flags & SOCAM_DATAWIDTH_MASK;
 
 	/* Only one width bit may be set */
@@ -205,8 +202,7 @@ static int mt9m001_set_bus_param(struct soc_camera_device *icd,
 
 static unsigned long mt9m001_query_bus_param(struct soc_camera_device *icd)
 {
-	struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
-	struct soc_camera_link *icl = mt9m001->client->dev.platform_data;
+	struct soc_camera_link *icl = to_soc_camera_link(icd);
 	/* MT9M001 has all capture_format parameters fixed */
 	unsigned long flags = SOCAM_PCLK_SAMPLE_FALLING |
 		SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |
@@ -223,8 +219,8 @@ static unsigned long mt9m001_query_bus_param(struct soc_camera_device *icd)
 static int mt9m001_set_crop(struct soc_camera_device *icd,
 			    struct v4l2_rect *rect)
 {
-	struct i2c_client *client = to_i2c_client(icd->control);
-	struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
+	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
+	struct mt9m001 *mt9m001 = i2c_get_clientdata(client);
 	int ret;
 	const u16 hblank = 9, vblank = 25;
 
@@ -296,12 +292,13 @@ static int mt9m001_try_fmt(struct soc_camera_device *icd,
 static int mt9m001_get_chip_id(struct soc_camera_device *icd,
 			       struct v4l2_dbg_chip_ident *id)
 {
-	struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
+	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
+	struct mt9m001 *mt9m001 = i2c_get_clientdata(client);
 
 	if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
 		return -EINVAL;
 
-	if (id->match.addr != mt9m001->client->addr)
+	if (id->match.addr != client->addr)
 		return -ENODEV;
 
 	id->ident	= mt9m001->model;
@@ -314,7 +311,7 @@ static int mt9m001_get_chip_id(struct soc_camera_device *icd,
 static int mt9m001_get_register(struct soc_camera_device *icd,
 				struct v4l2_dbg_register *reg)
 {
-	struct i2c_client *client = to_i2c_client(icd->control);
+	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
 
 	if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff)
 		return -EINVAL;
@@ -334,7 +331,7 @@ static int mt9m001_get_register(struct soc_camera_device *icd,
 static int mt9m001_set_register(struct soc_camera_device *icd,
 				struct v4l2_dbg_register *reg)
 {
-	struct i2c_client *client = to_i2c_client(icd->control);
+	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
 
 	if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff)
 		return -EINVAL;
@@ -387,15 +384,11 @@ static const struct v4l2_queryctrl mt9m001_controls[] = {
 	}
 };
 
-static int mt9m001_video_probe(struct soc_camera_device *);
-static void mt9m001_video_remove(struct soc_camera_device *);
 static int mt9m001_get_control(struct soc_camera_device *, struct v4l2_control *);
 static int mt9m001_set_control(struct soc_camera_device *, struct v4l2_control *);
 
 static struct soc_camera_ops mt9m001_ops = {
 	.owner			= THIS_MODULE,
-	.probe			= mt9m001_video_probe,
-	.remove			= mt9m001_video_remove,
 	.init			= mt9m001_init,
 	.release		= mt9m001_release,
 	.start_capture		= mt9m001_start_capture,
@@ -418,8 +411,8 @@ static struct soc_camera_ops mt9m001_ops = {
 
 static int mt9m001_get_control(struct soc_camera_device *icd, struct v4l2_control *ctrl)
 {
-	struct i2c_client *client = to_i2c_client(icd->control);
-	struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
+	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
+	struct mt9m001 *mt9m001 = i2c_get_clientdata(client);
 	int data;
 
 	switch (ctrl->id) {
@@ -438,8 +431,8 @@ static int mt9m001_get_control(struct soc_camera_device *icd, struct v4l2_contro
 
 static int mt9m001_set_control(struct soc_camera_device *icd, struct v4l2_control *ctrl)
 {
-	struct i2c_client *client = to_i2c_client(icd->control);
-	struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
+	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
+	struct mt9m001 *mt9m001 = i2c_get_clientdata(client);
 	const struct v4l2_queryctrl *qctrl;
 	int data;
 
@@ -531,11 +524,11 @@ static int mt9m001_set_control(struct soc_camera_device *icd, struct v4l2_contro
 
 /* Interface active, can use i2c. If it fails, it can indeed mean, that
  * this wasn't our capture interface, so, we wait for the right one */
-static int mt9m001_video_probe(struct soc_camera_device *icd)
+static int mt9m001_video_probe(struct soc_camera_device *icd,
+			       struct i2c_client *client)
 {
-	struct i2c_client *client = to_i2c_client(icd->control);
-	struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
-	struct soc_camera_link *icl = client->dev.platform_data;
+	struct mt9m001 *mt9m001 = i2c_get_clientdata(client);
+	struct soc_camera_link *icl = to_soc_camera_link(icd);
 	s32 data;
 	int ret;
 	unsigned long flags;
@@ -546,6 +539,11 @@ static int mt9m001_video_probe(struct soc_camera_device *icd)
 	    to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
 		return -ENODEV;
 
+	/* Switch master clock on */
+	ret = soc_camera_video_start(icd, &client->dev);
+	if (ret)
+		return ret;
+
 	/* Enable the chip */
 	data = reg_write(client, MT9M001_CHIP_ENABLE, 1);
 	dev_dbg(&icd->dev, "write: %d\n", data);
@@ -553,6 +551,8 @@ static int mt9m001_video_probe(struct soc_camera_device *icd)
 	/* Read out the chip version register */
 	data = reg_read(client, MT9M001_CHIP_VERSION);
 
+	soc_camera_video_stop(icd);
+
 	/* must be 0x8411 or 0x8421 for colour sensor and 8431 for bw */
 	switch (data) {
 	case 0x8411:
@@ -565,10 +565,9 @@ static int mt9m001_video_probe(struct soc_camera_device *icd)
 		icd->formats = mt9m001_monochrome_formats;
 		break;
 	default:
-		ret = -ENODEV;
 		dev_err(&icd->dev,
 			"No MT9M001 chip detected, register read %x\n", data);
-		goto ei2c;
+		return -ENODEV;
 	}
 
 	icd->num_formats = 0;
@@ -594,26 +593,17 @@ static int mt9m001_video_probe(struct soc_camera_device *icd)
 	dev_info(&icd->dev, "Detected a MT9M001 chip ID %x (%s)\n", data,
 		 data == 0x8431 ? "C12STM" : "C12ST");
 
-	/* Now that we know the model, we can start video */
-	ret = soc_camera_video_start(icd);
-	if (ret)
-		goto eisis;
-
 	return 0;
-
-eisis:
-ei2c:
-	return ret;
 }
 
 static void mt9m001_video_remove(struct soc_camera_device *icd)
 {
-	struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
-	struct soc_camera_link *icl = mt9m001->client->dev.platform_data;
+	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
+	struct soc_camera_link *icl = to_soc_camera_link(icd);
 
-	dev_dbg(&icd->dev, "Video %x removed: %p, %p\n", mt9m001->client->addr,
+	dev_dbg(&icd->dev, "Video %x removed: %p, %p\n", client->addr,
 		icd->dev.parent, icd->vdev);
-	soc_camera_video_stop(icd);
+	icd->ops = NULL;
 	if (icl->free_bus)
 		icl->free_bus(icl);
 }
@@ -622,11 +612,17 @@ static int mt9m001_probe(struct i2c_client *client,
 			 const struct i2c_device_id *did)
 {
 	struct mt9m001 *mt9m001;
-	struct soc_camera_device *icd;
+	struct soc_camera_device *icd = client->dev.platform_data;
 	struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
-	struct soc_camera_link *icl = client->dev.platform_data;
+	struct soc_camera_link *icl;
 	int ret;
 
+	if (!icd) {
+		dev_err(&client->dev, "MT9M001: missing soc-camera data!\n");
+		return -EINVAL;
+	}
+
+	icl = to_soc_camera_link(icd);
 	if (!icl) {
 		dev_err(&client->dev, "MT9M001 driver needs platform data\n");
 		return -EINVAL;
@@ -642,13 +638,10 @@ static int mt9m001_probe(struct i2c_client *client,
 	if (!mt9m001)
 		return -ENOMEM;
 
-	mt9m001->client = client;
 	i2c_set_clientdata(client, mt9m001);
 
 	/* Second stage probe - when a capture adapter is there */
-	icd = &mt9m001->icd;
 	icd->ops	= &mt9m001_ops;
-	icd->control	= &client->dev;
 	icd->x_min	= 20;
 	icd->y_min	= 12;
 	icd->x_current	= 20;
@@ -658,27 +651,27 @@ static int mt9m001_probe(struct i2c_client *client,
 	icd->height_min	= 32;
 	icd->height_max	= 1024;
 	icd->y_skip_top	= 1;
-	icd->iface	= icl->bus_id;
 	/* Simulated autoexposure. If enabled, we calculate shutter width
 	 * ourselves in the driver based on vertical blanking and frame width */
 	mt9m001->autoexposure = 1;
 
-	ret = soc_camera_device_register(icd);
-	if (ret)
-		goto eisdr;
-
-	return 0;
+	ret = mt9m001_video_probe(icd, client);
+	if (ret) {
+		i2c_set_clientdata(client, NULL);
+		kfree(mt9m001);
+	}
 
-eisdr:
-	kfree(mt9m001);
 	return ret;
 }
 
 static int mt9m001_remove(struct i2c_client *client)
 {
 	struct mt9m001 *mt9m001 = i2c_get_clientdata(client);
+	struct soc_camera_device *icd = client->dev.platform_data;
 
-	soc_camera_device_unregister(&mt9m001->icd);
+	mt9m001_video_remove(icd);
+	i2c_set_clientdata(client, NULL);
+	client->driver = NULL;
 	kfree(mt9m001);
 
 	return 0;
drivers/media/video/mt9m111.c +81 -71

402 lines not on this page · raw message

drivers/media/video/mt9t031.c +54 -59

296 lines not on this page · raw message

drivers/media/video/mt9v022.c +59 -59

295 lines not on this page · raw message

drivers/media/video/mx3_camera.c +17 -10
index 4d47eeb..82873a7 100644
@@ -502,18 +502,19 @@ 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);
+	if (ret < 0)
 		goto einit;
-	}
 
 	mx3_cam->icd = icd;
 
+	dev_info(&icd->dev, "MX3 Camera driver attached to camera %d\n",
+		 icd->devnum);
+
+	return 0;
+
 einit:
+	clk_disable(mx3_cam->clk);
 ebusy:
-	if (!ret)
-		dev_info(&icd->dev, "MX3 Camera driver attached to camera %d\n",
-			 icd->devnum);
 
 	return ret;
 }
@@ -946,9 +947,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;
 	}
 
@@ -1001,8 +1003,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(%lx) returned %d\n",
+			common_flags, ret);
 		return ret;
+	}
 
 	/*
 	 * So far only gated clock mode is supported. Add a line
@@ -1126,8 +1131,9 @@ static int mx3_camera_probe(struct platform_device *pdev)
 	INIT_LIST_HEAD(&mx3_cam->capture);
 	spin_lock_init(&mx3_cam->lock);
 
-	base = ioremap(res->start, res->end - res->start + 1);
+	base = ioremap(res->start, resource_size(res));
 	if (!base) {
+		pr_err("Couldn't map %x@%x\n", resource_size(res), res->start);
 		err = -ENOMEM;
 		goto eioremap;
 	}
@@ -1214,3 +1220,4 @@ module_exit(mx3_camera_exit);
 MODULE_DESCRIPTION("i.MX3x SoC Camera Host driver");
 MODULE_AUTHOR("Guennadi Liakhovetski <[email protected]>");
 MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:" MX3_CAM_DRV_NAME);
drivers/media/video/ov772x.c +87 -68

424 lines not on this page · raw message

drivers/media/video/pxa_camera.c +17 -10
index 2da5eef..63964d0 100644
@@ -841,7 +841,8 @@ static void pxa_camera_init_videobuf(struct videobuf_queue *q,
 				sizeof(struct pxa_buffer), icd);
 }
 
-static u32 mclk_get_divisor(struct pxa_camera_dev *pcdev)
+static u32 mclk_get_divisor(struct platform_device *pdev,
+			    struct pxa_camera_dev *pcdev)
 {
 	unsigned long mclk = pcdev->mclk;
 	u32 div;
@@ -853,7 +854,7 @@ static u32 mclk_get_divisor(struct pxa_camera_dev *pcdev)
 	/* mclk <= ciclk / 4 (27.4.2) */
 	if (mclk > lcdclk / 4) {
 		mclk = lcdclk / 4;
-		dev_warn(pcdev->soc_host.dev, "Limiting master clock to %lu\n", mclk);
+		dev_warn(&pdev->dev, "Limiting master clock to %lu\n", mclk);
 	}
 
 	/* We verify mclk != 0, so if anyone breaks it, here comes their Oops */
@@ -863,8 +864,8 @@ static u32 mclk_get_divisor(struct pxa_camera_dev *pcdev)
 	if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN)
 		pcdev->mclk = lcdclk / (2 * (div + 1));
 
-	dev_dbg(pcdev->soc_host.dev, "LCD clock %luHz, target freq %luHz, "
-		"divisor %u\n", lcdclk, mclk, div);
+	dev_dbg(&pdev->dev, "LCD clock %luHz, target freq %luHz, divisor %u\n",
+		lcdclk, mclk, div);
 
 	return div;
 }
@@ -969,15 +970,20 @@ static int pxa_camera_add_device(struct soc_camera_device *icd)
 		goto ebusy;
 	}
 
-	dev_info(&icd->dev, "PXA Camera driver attached to camera %d\n",
-		 icd->devnum);
-
 	pxa_camera_activate(pcdev);
 	ret = icd->ops->init(icd);
+	if (ret < 0)
+		goto einit;
+
+	pcdev->icd = icd;
 
-	if (!ret)
-		pcdev->icd = icd;
+	dev_info(&icd->dev, "PXA Camera driver attached to camera %d\n",
+		 icd->devnum);
 
+	return 0;
+
+einit:
+	pxa_camera_deactivate(pcdev);
 ebusy:
 	return ret;
 }
@@ -1599,7 +1605,7 @@ static int pxa_camera_probe(struct platform_device *pdev)
 		pcdev->mclk = 20000000;
 	}
 
-	pcdev->mclk_divisor = mclk_get_divisor(pcdev);
+	pcdev->mclk_divisor = mclk_get_divisor(pdev, pcdev);
 
 	INIT_LIST_HEAD(&pcdev->capture);
 	spin_lock_init(&pcdev->lock);
@@ -1746,3 +1752,4 @@ module_exit(pxa_camera_exit);
 MODULE_DESCRIPTION("PXA27x SoC Camera Host driver");
 MODULE_AUTHOR("Guennadi Liakhovetski <[email protected]>");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:" PXA_CAM_DRV_NAME);
drivers/media/video/sh_mobile_ceu_camera.c +8 -5
index d369e84..ac9b467 100644
@@ -360,11 +360,13 @@ static int sh_mobile_ceu_add_device(struct soc_camera_device *icd)
 		 "SuperH Mobile CEU driver attached to camera %d\n",
 		 icd->devnum);
 
+	clk_enable(pcdev->clk);
+
 	ret = icd->ops->init(icd);
-	if (ret)
+	if (ret) {
+		clk_disable(pcdev->clk);
 		goto err;
-
-	clk_enable(pcdev->clk);
+	}
 
 	ceu_write(pcdev, CAPSR, 1 << 16); /* reset */
 	while (ceu_read(pcdev, CSTSR) & 1)
@@ -398,10 +400,10 @@ static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd)
 	}
 	spin_unlock_irqrestore(&pcdev->lock, flags);
 
-	clk_disable(pcdev->clk);
-
 	icd->ops->release(icd);
 
+	clk_disable(pcdev->clk);
+
 	dev_info(&icd->dev,
 		 "SuperH Mobile CEU driver detached from camera %d\n",
 		 icd->devnum);
@@ -948,3 +950,4 @@ module_exit(sh_mobile_ceu_exit);
 MODULE_DESCRIPTION("SuperH Mobile CEU driver");
 MODULE_AUTHOR("Magnus Damm");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:sh_mobile_ceu");
drivers/media/video/soc_camera.c +211 -215

646 lines not on this page · raw message

drivers/media/video/soc_camera_platform.c +27 -22

110 lines not on this page · raw message

drivers/media/video/tw9910.c +58 -48

280 lines not on this page · raw message

include/media/soc_camera.h +16 -11
index 813e120..d8b4256 100644
@@ -20,7 +20,6 @@
 struct soc_camera_device {
 	struct list_head list;
 	struct device dev;
-	struct device *control;
 	unsigned short width;		/* Current window */
 	unsigned short height;		/* sizes */
 	unsigned short x_min;		/* Camera capabilities */
@@ -131,17 +130,25 @@ static inline struct soc_camera_host *to_soc_camera_host(struct device *dev)
 	return dev_get_drvdata(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);
+static inline struct soc_camera_link *to_soc_camera_link(struct soc_camera_device *icd)
+{
+	return icd->dev.platform_data;
+}
 
-extern int soc_camera_video_start(struct soc_camera_device *icd);
-extern void soc_camera_video_stop(struct soc_camera_device *icd);
+static inline struct device *to_soc_camera_control(struct soc_camera_device *icd)
+{
+	return dev_get_drvdata(&icd->dev);
+}
 
-extern const struct soc_camera_data_format *soc_camera_format_by_fourcc(
+int soc_camera_host_register(struct soc_camera_host *ici);
+void soc_camera_host_unregister(struct soc_camera_host *ici);
+
+int soc_camera_video_start(struct soc_camera_device *icd, struct device *dev);
+void soc_camera_video_stop(struct soc_camera_device *icd);
+
+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 {
@@ -170,8 +177,6 @@ struct soc_camera_format_xlate {
 
 struct soc_camera_ops {
 	struct module *owner;
-	int (*probe)(struct soc_camera_device *);
-	void (*remove)(struct soc_camera_device *);
 	int (*suspend)(struct soc_camera_device *, pm_message_t state);
 	int (*resume)(struct soc_camera_device *);
 	int (*init)(struct soc_camera_device *);
include/media/soc_camera_platform.h +1 -2
index 3e8f020..b144f94 100644
@@ -18,11 +18,10 @@ struct device;
 
 struct soc_camera_platform_info {
 	int iface;
-	char *format_name;
+	const char *format_name;
 	unsigned long format_depth;
 	struct v4l2_pix_format format;
 	unsigned long bus_param;
-	void (*power)(int);
 	struct device *dev;
 	int (*set_capture)(struct soc_camera_platform_info *info, int enable);
 	struct soc_camera_link link;
Signature · 1 line
1.6.2.4
#10 lore raw

PATCH v2 5/10 sh: soc-camera updates

In reply to Guennadi Liakhovetski

Update ap325rxa to specify .bus_id in struct soc_camera_link explicitly, remove unused .iface from struct soc_camera_platform_info.

---

Paul, you certainly could take this one, as well as a couple others, but maybe easier to push them all together.

 arch/sh/boards/board-ap325rxa.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/sh/boards/board-ap325rxa.c +2 -1
index ac964e4..f644ad7 100644
@@ -308,7 +308,6 @@ static int ap325rxa_camera_add(struct soc_camera_link *icl, struct device *dev);
 static void ap325rxa_camera_del(struct soc_camera_link *icl);
 
 static struct soc_camera_platform_info camera_info = {
-	.iface = 0,
 	.format_name = "UYVY",
 	.format_depth = 16,
 	.format = {
@@ -321,6 +320,7 @@ static struct soc_camera_platform_info camera_info = {
 	SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_MASTER | SOCAM_DATAWIDTH_8,
 	.set_capture = camera_set_capture,
 	.link = {
+		.bus_id		= 0,
 		.add_device	= ap325rxa_camera_add,
 		.del_device	= ap325rxa_camera_del,
 	},
@@ -421,6 +421,7 @@ static struct ov772x_camera_info ov7725_info = {
 	.flags		= OV772X_FLAG_VFLIP | OV772X_FLAG_HFLIP,
 	.edgectrl	= OV772X_AUTO_EDGECTRL(0xf, 0),
 	.link = {
+		.bus_id		= 0,
 		.power		= ov7725_power,
 		.board_info	= &ap325rxa_i2c_camera[0],
 		.i2c_adapter_id	= 0,
Signature · 1 line
1.6.2.4
#11 lore raw

PATCH v2 6/10 soc-camera: remove unused .iface from struct soc_camera_platform_info

In reply to Guennadi Liakhovetski
---
 include/media/soc_camera_platform.h |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
include/media/soc_camera_platform.h +0 -1
index b144f94..bb70401 100644
@@ -17,7 +17,6 @@
 struct device;
 
 struct soc_camera_platform_info {
-	int iface;
 	const char *format_name;
 	unsigned long format_depth;
 	struct v4l2_pix_format format;
Signature · 1 line
1.6.2.4
#12 lore raw

PATCH v2 7/10 sh: prepare board-ap325rxa.c for v4l2-subdev conversion

In reply to Guennadi Liakhovetski

We will be registering and unregistering the soc_camera_platform platform device multiple times, therefore we need a .release() method and have to nullify the kobj.

---

Another one for "sh". Again have to synchronise.

 arch/sh/boards/board-ap325rxa.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
arch/sh/boards/board-ap325rxa.c +11 -2
index f644ad7..9329fe5 100644
@@ -323,13 +323,19 @@ static struct soc_camera_platform_info camera_info = {
 		.bus_id		= 0,
 		.add_device	= ap325rxa_camera_add,
 		.del_device	= ap325rxa_camera_del,
+		.module_name	= "soc_camera_platform",
 	},
 };
 
+static void dummy_release(struct device *dev)
+{
+}
+
 static struct platform_device camera_device = {
 	.name		= "soc_camera_platform",
 	.dev		= {
 		.platform_data	= &camera_info,
+		.release	= dummy_release,
 	},
 };
 
@@ -346,8 +352,11 @@ static int ap325rxa_camera_add(struct soc_camera_link *icl,
 
 static void ap325rxa_camera_del(struct soc_camera_link *icl)
 {
-	if (icl == &camera_info.link)
-		platform_device_unregister(&camera_device);
+	if (icl != &camera_info.link)
+		return;
+
+	platform_device_unregister(&camera_device);
+	memset(&migor_camera_device.dev.kobj, 0, sizeof(migor_camera_device.dev.kobj));
 }
 #endif /* CONFIG_I2C */
 
Signature · 1 line
1.6.2.4
#13 lore raw

PATCH v2 8/10 v4l2-subdev: add a v4l2_i2c_subdev_board() function

In reply to Guennadi Liakhovetski

Introduce a function similar to v4l2_i2c_new_subdev() but taking a pointer to a struct i2c_board_info as a parameter instead of a client type and an I2C address, and make v4l2_i2c_new_subdev() a wrapper around it.

---

Hans, renamed as you requested and updated to a (more) current state.

 drivers/media/video/v4l2-common.c |   30 +++++++++++++++++++-----------
 include/media/v4l2-common.h       |    5 +++++
 2 files changed, 24 insertions(+), 11 deletions(-)
drivers/media/video/v4l2-common.c +19 -11
index f576ef6..ab190aa 100644
@@ -758,30 +758,38 @@ void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
 }
 EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_init);
 
-
-
 /* Load an i2c sub-device. */
 struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
 		struct i2c_adapter *adapter,
 		const char *module_name, const char *client_type, u8 addr)
 {
-	struct v4l2_subdev *sd = NULL;
-	struct i2c_client *client;
 	struct i2c_board_info info;
 
-	BUG_ON(!v4l2_dev);
-
-	if (module_name)
-		request_module(module_name);
-
 	/* Setup the i2c board info with the device type and
 	   the device address. */
 	memset(&info, 0, sizeof(info));
 	strlcpy(info.type, client_type, sizeof(info.type));
 	info.addr = addr;
 
+	return v4l2_i2c_subdev_board(v4l2_dev, adapter, module_name, &info);
+}
+EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev);
+
+/* Load an i2c sub-device using provided struct i2c_board_info. */
+struct v4l2_subdev *v4l2_i2c_subdev_board(struct v4l2_device *v4l2_dev,
+		struct i2c_adapter *adapter,
+		const char *module_name, const struct i2c_board_info *info)
+{
+	struct v4l2_subdev *sd = NULL;
+	struct i2c_client *client;
+
+	BUG_ON(!v4l2_dev);
+
+	if (module_name)
+		request_module(module_name);
+
 	/* Create the i2c client */
-	client = i2c_new_device(adapter, &info);
+	client = i2c_new_device(adapter, info);
 	/* 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
@@ -808,7 +816,7 @@ error:
 		i2c_unregister_device(client);
 	return sd;
 }
-EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev);
+EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_board);
 
 /* Probe and load an i2c sub-device. */
 struct v4l2_subdev *v4l2_i2c_new_probed_subdev(struct v4l2_device *v4l2_dev,
include/media/v4l2-common.h +5 -0
index c48c24e..a67f5c3 100644
@@ -131,6 +131,7 @@ struct i2c_driver;
 struct i2c_adapter;
 struct i2c_client;
 struct i2c_device_id;
+struct i2c_board_info;
 struct v4l2_device;
 struct v4l2_subdev;
 struct v4l2_subdev_ops;
@@ -142,6 +143,10 @@ struct v4l2_subdev_ops;
 struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
 		struct i2c_adapter *adapter,
 		const char *module_name, const char *client_type, u8 addr);
+/* Same as above but uses user-provided struct i2c_board_info */
+struct v4l2_subdev *v4l2_i2c_subdev_board(struct v4l2_device *v4l2_dev,
+		struct i2c_adapter *adapter,
+		const char *module_name, const struct i2c_board_info *info);
 /* Probe and load an i2c module and return an initialized v4l2_subdev struct.
    Only call request_module if module_name != NULL.
    The client_type argument is the name of the chip that's on the adapter. */
Signature · 1 line
1.6.2.4
#14 lore raw

Re: [PATCH 08/10 v2] v4l2-subdev: add a v4l2_i2c_subdev_board() function

Quoted 9 lines · On Friday 15 May 2009 19:20:10 Guennadi Liakhovetski wrote:

Introduce a function similar to v4l2_i2c_new_subdev() but taking a pointer to a struct i2c_board_info as a parameter instead of a client type and an I2C address, and make v4l2_i2c_new_subdev() a wrapper around it.

---

Hans, renamed as you requested and updated to a (more) current state.

NAK. Not because it is a bad idea, but because you need to patch against the version in the v4l-dvb repo. The version in the kernel is missing a lot of the compatibility code which we unfortunately need to keep.

Any function passing the board_info will be valid for kernels >= 2.6.26 only.

I've been thinking of an alternative that is more 'compatibility' friendly:

The board info contains two fields that are really of interest: irq and the platform data. The core ops can be extended with a new .s_config function that receives the irq and a platform data pointer. If the new v4l2_i2c_subdev_board function is called, then .s_config is called automatically with the right parameters. This makes it possible to use v4l2_i2c_subdev_board with a i2c subdev that has to be backwards compatible (and so cannot rely on board_info). Instead that subdev will receive an s_config call with the needed info.

And v4l drivers that have to be backwards compatible and so cannot use v4l2_i2c_subdev_board can call s_config directly.

I agree, it is not elegant, but it is a fact of life that we need to stay backwards compatible. This new i2c API is only usable from 2.6.26 onwards, and that's simply too recent.

In my opinion doing it the way I proposed above will be a reasonable alternative that is also easy to remove when at some point in the future we stop supporting pre-2.6.26 kernels.

Regards,

Hans

Quoted 91 lines
 drivers/media/video/v4l2-common.c |   30 +++++++++++++++++++-----------
 include/media/v4l2-common.h       |    5 +++++
 2 files changed, 24 insertions(+), 11 deletions(-)
(quoted diff) +0 -0

b/drivers/media/video/v4l2-common.c index f576ef6..ab190aa 100644

drivers/media/video/v4l2-common.c +19 -11
@@ -758,30 +758,38 @@ void v4l2_i2c_subdev_init(struct v4l2_subdev *sd,
 struct i2c_client *client, }
 EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_init);
 
-
-
 /* Load an i2c sub-device. */
 struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
 		struct i2c_adapter *adapter,
 		const char *module_name, const char *client_type, u8 addr)
 {
-	struct v4l2_subdev *sd = NULL;
-	struct i2c_client *client;
 	struct i2c_board_info info;
 
-	BUG_ON(!v4l2_dev);
-
-	if (module_name)
-		request_module(module_name);
-
 	/* Setup the i2c board info with the device type and
 	   the device address. */
 	memset(&info, 0, sizeof(info));
 	strlcpy(info.type, client_type, sizeof(info.type));
 	info.addr = addr;
 
+	return v4l2_i2c_subdev_board(v4l2_dev, adapter, module_name, &info);
+}
+EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev);
+
+/* Load an i2c sub-device using provided struct i2c_board_info. */
+struct v4l2_subdev *v4l2_i2c_subdev_board(struct v4l2_device *v4l2_dev,
+		struct i2c_adapter *adapter,
+		const char *module_name, const struct i2c_board_info *info)
+{
+	struct v4l2_subdev *sd = NULL;
+	struct i2c_client *client;
+
+	BUG_ON(!v4l2_dev);
+
+	if (module_name)
+		request_module(module_name);
+
 	/* Create the i2c client */
-	client = i2c_new_device(adapter, &info);
+	client = i2c_new_device(adapter, info);
 	/* 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
@@ -808,7 +816,7 @@ error:
 		i2c_unregister_device(client);
 	return sd;
 }
-EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev);
+EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_board);
 
 /* Probe and load an i2c sub-device. */
 struct v4l2_subdev *v4l2_i2c_new_probed_subdev(struct v4l2_device

*v4l2_dev, diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h index c48c24e..a67f5c3 100644

include/media/v4l2-common.h +5 -0
@@ -131,6 +131,7 @@ struct i2c_driver;
 struct i2c_adapter;
 struct i2c_client;
 struct i2c_device_id;
+struct i2c_board_info;
 struct v4l2_device;
 struct v4l2_subdev;
 struct v4l2_subdev_ops;
@@ -142,6 +143,10 @@ struct v4l2_subdev_ops;
 struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
 		struct i2c_adapter *adapter,
 		const char *module_name, const char *client_type, u8 addr);
+/* Same as above but uses user-provided struct i2c_board_info */
+struct v4l2_subdev *v4l2_i2c_subdev_board(struct v4l2_device *v4l2_dev,
+		struct i2c_adapter *adapter,
+		const char *module_name, const struct i2c_board_info *info);
 /* Probe and load an i2c module and return an initialized v4l2_subdev

struct. Only call request_module if module_name != NULL.
The client_type argument is the name of the chip that's on the
adapter. */

Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG
#15 lore raw

Re: [PATCH 08/10 v2] v4l2-subdev: add a v4l2_i2c_subdev_board() function

Hi Hans,

Quoted 9 lines · Hans Verkuil
Quoted 8 lines · On Friday 15 May 2009 19:20:10 Guennadi Liakhovetski wrote:

Introduce a function similar to v4l2_i2c_new_subdev() but taking a pointer to a struct i2c_board_info as a parameter instead of a client type and an I2C address, and make v4l2_i2c_new_subdev() a wrapper around it.

---

Quoted 8 lines
Quoted 1 line

Hans, renamed as you requested and updated to a (more) current state.

NAK. Not because it is a bad idea, but because you need to patch against the version in the v4l-dvb repo. The version in the kernel is missing a lot of the compatibility code which we unfortunately need to keep.

Any function passing the board_info will be valid for kernels >= 2.6.26 only.

Here's a quote from your earlier email.

Quoted 7 lines · Hans Verkuil

The board_info struct didn't appear until 2.6.22, so that's certainly a cut-off point. Since the probe version of this call does not work on kernels < 2.6.26 the autoprobing mechanism is still used for those older kernels. I think it makes life much easier to require that everything that uses board_info needs kernel 2.6.26 at the minimum. I don't think that is an issue anyway for soc-camera. Unless there is a need to use soc-camera from v4l-dvb with kernels <2.6.26?

So, will this my patch build and work with >= 2.6.22 or not? I really would not like to consciously make code uglier now because of compatibility with < 2.6.26 to make it better some time later again.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#16 lore raw

Re: [PATCH 08/10 v2] v4l2-subdev: add a v4l2_i2c_subdev_board() function

Hi Hans and Guennadi,

Quoted 34 lines · ext Guennadi Liakhovetski

Hi Hans,

Quoted 9 lines · Hans Verkuil
Quoted 8 lines · On Friday 15 May 2009 19:20:10 Guennadi Liakhovetski wrote:

Introduce a function similar to v4l2_i2c_new_subdev() but taking a pointer to a struct i2c_board_info as a parameter instead of a client type and an I2C address, and make v4l2_i2c_new_subdev() a wrapper around it.

---

Quoted 8 lines
Quoted 1 line

Hans, renamed as you requested and updated to a (more) current state.

NAK. Not because it is a bad idea, but because you need to patch against the version in the v4l-dvb repo. The version in the kernel is missing a lot of the compatibility code which we unfortunately need to keep.

Any function passing the board_info will be valid for kernels >= 2.6.26 only.

Here's a quote from your earlier email.

Quoted 7 lines · Hans Verkuil

The board_info struct didn't appear until 2.6.22, so that's certainly a cut-off point. Since the probe version of this call does not work on kernels < 2.6.26 the autoprobing mechanism is still used for those older kernels. I think it makes life much easier to require that everything that uses board_info needs kernel 2.6.26 at the minimum. I don't think that is an issue anyway for soc-camera. Unless there is a need to use soc-camera from v4l-dvb with kernels <2.6.26?

Quoted 3 lines

So, will this my patch build and work with >= 2.6.22 or not? I really would not like to consciously make code uglier now because of compatibility with < 2.6.26 to make it better some time later again.

I've to agree with Guennadi, I believe newer code should not suffer because of compatibility code, at least if it is possible. I also agree with you that we must keep compatibility with older drivers.

What I propose it to have the mechanism of .s_config available only for LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26). Newer version can take advance of the new i2c api features.

This is slightly different from what Hans proposed. The difference here is that we do not force newer drivers to use a callback only because of backward compatibility.

Well, this is what I think of this problem, you may have a different point of view. What do you think?

Quoted 11 lines

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
Eduardo Valentin
#17 lore raw

RFC 1/1 v4l2_subdev i2c: Add i2c board info to v4l2_i2c_new_subdev

From: Eduardo Valentin <[email protected]>

Device drivers of v4l2_subdev devices may want to have i2c board info data. This patch adds an helper function to allow bridge drivers to pass board specific data to v4l2_subdev drivers.

For those drivers which need to support kernel versions bellow 2.6.26, a .s_config callback was added. The idea of this callback is to pass board configuration as well. In that case, the bridge driver should call the .s_config of subdevs manually.

Priority: normal

linux/drivers/media/video/v4l2-common.c +39 -13
diff -r 315bc4b65b4f -r 778e5e5ecc68 linux/drivers/media/video/v4l2-common.c
@@ -819,15 +819,16 @@
 
 
 /* Load an i2c sub-device. */
-struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
-		struct i2c_adapter *adapter,
-		const char *module_name, const char *client_type, u8 addr)
+static struct v4l2_subdev *__v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
+		struct i2c_adapter *adapter, const char *module_name,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
+		struct i2c_board_info *info)
+#else
+		u8 addr)
+#endif
 {
 	struct v4l2_subdev *sd = NULL;
 	struct i2c_client *client;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
-	struct i2c_board_info info;
-#endif
 
 	BUG_ON(!v4l2_dev);
 
@@ -835,14 +836,8 @@
 		request_module(module_name);
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
-	/* Setup the i2c board info with the device type and
-	   the device address. */
-	memset(&info, 0, sizeof(info));
-	strlcpy(info.type, client_type, sizeof(info.type));
-	info.addr = addr;
-
 	/* Create the i2c client */
-	client = i2c_new_device(adapter, &info);
+	client = i2c_new_device(adapter, info);
 #else
 	/* Legacy code: loading the module automatically
 	   probes and creates the i2c_client on the adapter.
@@ -877,8 +872,39 @@
 #endif
 	return sd;
 }
+
+struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
+		struct i2c_adapter *adapter,
+		const char *module_name, const char *client_type, u8 addr)
+{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
+	struct i2c_board_info info;
+
+	/* Setup the i2c board info with the device type and
+	   the device address. */
+	memset(&info, 0, sizeof(info));
+	strlcpy(info.type, client_type, sizeof(info.type));
+	info.addr = addr;
+
+	return __v4l2_i2c_new_subdev(v4l2_dev, adapter, module_name,
+					&info);
+#else
+	return __v4l2_i2c_new_subdev(v4l2_dev, adapter, module_name,
+					addr);
+#endif
+}
 EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev);
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
+struct v4l2_subdev *v4l2_i2c_new_subdev_board_info(struct v4l2_device *v4l2_dev,
+		struct i2c_adapter *adapter, const char *module_name,
+		struct i2c_board_info *i)
+{
+	return __v4l2_i2c_new_subdev(v4l2_dev, adapter, module_name, i);
+}
+EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev_board_info);
+#endif
+
 /* Probe and load an i2c sub-device. */
 struct v4l2_subdev *v4l2_i2c_new_probed_subdev(struct v4l2_device *v4l2_dev,
 	struct i2c_adapter *adapter,
linux/include/media/v4l2-common.h +8 -0
diff -r 315bc4b65b4f -r 778e5e5ecc68 linux/include/media/v4l2-common.h
@@ -130,6 +130,7 @@
 struct i2c_driver;
 struct i2c_adapter;
 struct i2c_client;
+struct i2c_board_info;
 struct i2c_device_id;
 struct v4l2_device;
 struct v4l2_subdev;
@@ -147,6 +148,13 @@
 struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
 		struct i2c_adapter *adapter,
 		const char *module_name, const char *client_type, u8 addr);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
+/* Same as v4l2_i2c_new_subdev, but with opportunity to pass i2c_board_info
+   to client device */
+struct v4l2_subdev *v4l2_i2c_new_subdev_board_info(struct v4l2_device *v4l2_dev,
+		struct i2c_adapter *adapter, const char *module_name,
+		struct i2c_board_info *i);
+#endif
 /* Probe and load an i2c module and return an initialized v4l2_subdev struct.
    Only call request_module if module_name != NULL.
    The client_type argument is the name of the chip that's on the adapter. */
linux/include/media/v4l2-subdev.h +1 -0
diff -r 315bc4b65b4f -r 778e5e5ecc68 linux/include/media/v4l2-subdev.h
@@ -96,6 +96,7 @@
 struct v4l2_subdev_core_ops {
 	int (*g_chip_ident)(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip);
 	int (*log_status)(struct v4l2_subdev *sd);
+	int (*s_config)(struct v4l2_subdev *sd, void *config_data);
 	int (*init)(struct v4l2_subdev *sd, u32 val);
 	int (*load_fw)(struct v4l2_subdev *sd);
 	int (*reset)(struct v4l2_subdev *sd, u32 val);
#18 lore raw

Re: [PATCH 08/10 v2] v4l2-subdev: add a v4l2_i2c_subdev_board() function

In reply to Eduardo Valentin
Quoted 37 lines · On Friday 22 May 2009 10:58:27 Eduardo Valentin wrote:

Hi Hans and Guennadi,

Quoted 34 lines · ext Guennadi Liakhovetski

Hi Hans,

Quoted 12 lines · Hans Verkuil
Quoted 10 lines · On Friday 15 May 2009 19:20:10 Guennadi Liakhovetski wrote:

Introduce a function similar to v4l2_i2c_new_subdev() but taking a pointer to a struct i2c_board_info as a parameter instead of a client type and an I2C address, and make v4l2_i2c_new_subdev() a wrapper around it.

---

Hans, renamed as you requested and updated to a (more) current state.

Quoted 7 lines

NAK. Not because it is a bad idea, but because you need to patch against the version in the v4l-dvb repo. The version in the kernel is missing a lot of the compatibility code which we unfortunately need to keep.

Any function passing the board_info will be valid for kernels >= 2.6.26 only.

Here's a quote from your earlier email.

Quoted 7 lines · Hans Verkuil

The board_info struct didn't appear until 2.6.22, so that's certainly a cut-off point. Since the probe version of this call does not work on kernels < 2.6.26 the autoprobing mechanism is still used for those older kernels. I think it makes life much easier to require that everything that uses board_info needs kernel 2.6.26 at the minimum. I don't think that is an issue anyway for soc-camera. Unless there is a need to use soc-camera from v4l-dvb with kernels <2.6.26?

Quoted 7 lines
Quoted 3 lines

So, will this my patch build and work with >= 2.6.22 or not? I really would not like to consciously make code uglier now because of compatibility with < 2.6.26 to make it better some time later again.

I've to agree with Guennadi, I believe newer code should not suffer because of compatibility code, at least if it is possible. I also agree with you that we must keep compatibility with older drivers.

Let there be no doubt about it: it's very unfortunate that we have to do this. I really hope that in, say, one year we can just drop support for kernels pre-2.6.26. But my proposal from the beginning of the year to drop support for kernels < 2.6.22 demonstrated that not everyone is happy about that.

A quick note for Guennadi: the i2c_board_info and the new i2c API has been available since 2.6.22, but for the subdev support in v4l2 I've decided not to use the new i2c API for kernels < 2.6.26 due to a serious i2c core kernel bug that wasn't fixed until 2.6.26 (probing for the existence of an i2c device at certain addresses can cause an oops). Strictly speaking it would be possible to support board_info from 2.6.22 onwards, but going that way makes it very messy with lots of #ifdefs. I want to keep the simple rule to only support the new i2c API for 2.6.26 onwards.

Quoted 10 lines

What I propose it to have the mechanism of .s_config available only for LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26). Newer version can take advance of the new i2c api features.

This is slightly different from what Hans proposed. The difference here is that we do not force newer drivers to use a callback only because of backward compatibility.

Well, this is what I think of this problem, you may have a different point of view. What do you think?

No, that's not going to work. None of the USB and PCI drivers use i2c_board_info since they all can run on older kernels as well. So all those drivers need an s_config ops that they can call. Now, embedded drivers usually have no need to support older kernels, so these can use i2c_board_info directly.

If you know that an i2c driver is only ever called using this new v4l2_i2c_new_subdev_board_info function (I prefer the shorter name v4l2_i2c_subdev_board() BTW), then you can choose to not implement s_config in that i2c driver.

But i2c drivers that have to support older kernels as well should use s_config.

Note that s_config also needs an 'int irq' argument besides the 'void *platform_data'. And that we should also add a v4l2_i2c_probed_subdev_board() call.

Regards,

Hans

Quoted 11 lines
Quoted 11 lines

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG
#19 lore raw

Re: [PATCH 08/10 v2] v4l2-subdev: add a v4l2_i2c_subdev_board() function

Quoted 8 lines · Hans Verkuil

A quick note for Guennadi: the i2c_board_info and the new i2c API has been available since 2.6.22, but for the subdev support in v4l2 I've decided not to use the new i2c API for kernels < 2.6.26 due to a serious i2c core kernel bug that wasn't fixed until 2.6.26 (probing for the existence of an i2c device at certain addresses can cause an oops). Strictly speaking it would be possible to support board_info from 2.6.22 onwards, but going that way makes it very messy with lots of #ifdefs. I want to keep the simple rule to only support the new i2c API for 2.6.26 onwards.

Hm, I am afraid, I do not understand.

My patch doesn't change any behaviour. It just adds one more way of calling the same function, which is already there, just with different parameters. All existing (or new) drivers can call v4l2_i2c_new_subdev() just like before - nothing changes for them. Only internally this function now will use its "struct i2c_board_info info" which it _already_ has, to call a new function - v4l2_i2c_subdev_board(). No change whatsoever! Drivers, that know _will_ work this way, e.g., if they don't care about _any_ other kernel versions, except for the one they are compiled for, can call that function - v4l2_i2c_subdev_board() directly. Are you concerned, that some drivers, that do want to work with older kernels, will switch to using this function and then fail for older kernels? Well, we can put the

EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_board);

line under an ifdef if you want, but even that I don't think is necessary, we just have to catch those careless drivers. Or am I missing something?

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#20 lore raw

Re: [PATCH 08/10 v2] v4l2-subdev: add a v4l2_i2c_subdev_board() function

Quoted 26 lines · On Friday 22 May 2009 14:16:13 Guennadi Liakhovetski wrote:
Quoted 9 lines · Hans Verkuil

A quick note for Guennadi: the i2c_board_info and the new i2c API has been available since 2.6.22, but for the subdev support in v4l2 I've decided not to use the new i2c API for kernels < 2.6.26 due to a serious i2c core kernel bug that wasn't fixed until 2.6.26 (probing for the existence of an i2c device at certain addresses can cause an oops). Strictly speaking it would be possible to support board_info from 2.6.22 onwards, but going that way makes it very messy with lots of #ifdefs. I want to keep the simple rule to only support the new i2c API for 2.6.26 onwards.

Hm, I am afraid, I do not understand.

My patch doesn't change any behaviour. It just adds one more way of calling the same function, which is already there, just with different parameters. All existing (or new) drivers can call v4l2_i2c_new_subdev() just like before - nothing changes for them. Only internally this function now will use its "struct i2c_board_info info" which it _already_ has, to call a new function - v4l2_i2c_subdev_board(). No change whatsoever! Drivers, that know _will_ work this way, e.g., if they don't care about _any_ other kernel versions, except for the one they are compiled for, can call that function - v4l2_i2c_subdev_board() directly. Are you concerned, that some drivers, that do want to work with older kernels, will switch to using this function and then fail for older kernels? Well, we can put the

Quoted 5 lines

EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_board);

line under an ifdef if you want, but even that I don't think is necessary, we just have to catch those careless drivers. Or am I missing something?

There are two 'missing somethings': the first is that you can have a v4l2 driver that uses v4l2_i2c_subdev_board, but the i2c driver that is loaded by that call can also by used by other drivers need to be backwards compatible with older kernels.

So the i2c driver cannot in general obtain the irq and platform_data from i2c_client during probe, since it won't be set during probe (actually, the irq field in i2c_client doesn't even exist on pre-2.6.22 kernels).

But if v4l2_i2c_subdev_board calls s_config explicitly, then this data can be passed to the i2c driver in a manner that works for all kernels.

The second 'something' is that I need something like s_config anyway for those drivers that cannot use this new v4l2_i2c_subdev_board because they have to compile for all kernels. Those drivers can call the existing functions, and then call s_config explicitly.

For the embedded platforms it really doesn't matter: there you just use i2c_board_info, and the only time s_config comes into play is when the i2c driver can also be used by bridge drivers that cannot use v4l2_i2c_subdev_board.

Regards,

Hans

Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG
#21 lore raw

Re: [PATCH 08/10 v2] v4l2-subdev: add a v4l2_i2c_subdev_board() function

Hi,

Quoted 50 lines · ext Hans Verkuil
Quoted 26 lines · On Friday 22 May 2009 14:16:13 Guennadi Liakhovetski wrote:
Quoted 9 lines · Hans Verkuil

A quick note for Guennadi: the i2c_board_info and the new i2c API has been available since 2.6.22, but for the subdev support in v4l2 I've decided not to use the new i2c API for kernels < 2.6.26 due to a serious i2c core kernel bug that wasn't fixed until 2.6.26 (probing for the existence of an i2c device at certain addresses can cause an oops). Strictly speaking it would be possible to support board_info from 2.6.22 onwards, but going that way makes it very messy with lots of #ifdefs. I want to keep the simple rule to only support the new i2c API for 2.6.26 onwards.

Hm, I am afraid, I do not understand.

My patch doesn't change any behaviour. It just adds one more way of calling the same function, which is already there, just with different parameters. All existing (or new) drivers can call v4l2_i2c_new_subdev() just like before - nothing changes for them. Only internally this function now will use its "struct i2c_board_info info" which it _already_ has, to call a new function - v4l2_i2c_subdev_board(). No change whatsoever! Drivers, that know _will_ work this way, e.g., if they don't care about _any_ other kernel versions, except for the one they are compiled for, can call that function - v4l2_i2c_subdev_board() directly. Are you concerned, that some drivers, that do want to work with older kernels, will switch to using this function and then fail for older kernels? Well, we can put the

Quoted 5 lines

EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_board);

line under an ifdef if you want, but even that I don't think is necessary, we just have to catch those careless drivers. Or am I missing something?

There are two 'missing somethings': the first is that you can have a v4l2 driver that uses v4l2_i2c_subdev_board, but the i2c driver that is loaded by that call can also by used by other drivers need to be backwards compatible with older kernels.

So the i2c driver cannot in general obtain the irq and platform_data from i2c_client during probe, since it won't be set during probe (actually, the irq field in i2c_client doesn't even exist on pre-2.6.22 kernels).

But if v4l2_i2c_subdev_board calls s_config explicitly, then this data can be passed to the i2c driver in a manner that works for all kernels.

The second 'something' is that I need something like s_config anyway for those drivers that cannot use this new v4l2_i2c_subdev_board because they have to compile for all kernels. Those drivers can call the existing functions, and then call s_config explicitly.

Quoted 4 lines

For the embedded platforms it really doesn't matter: there you just use i2c_board_info, and the only time s_config comes into play is when the i2c driver can also be used by bridge drivers that cannot use v4l2_i2c_subdev_board.

I think this is heading to other direction that I first understood. I don't see why one i2c driver which implements the new i2c api would not setup its irq and platform data other then during probe time. But let's assume that.

In that case, i2c drivers, even though they implement the new i2c api, should not receive the board specific info during probe, but should wait until s_config time.

That would work for all kernels, but then i2c drivers would not have opportunity to communicate with device during probe time and do silly checks there.

Why can not v4l2_i2c_subdev_board be able to pass i2c_board_info using normal i2c api if we are >= 2.6.26, and let s_config to bridge driver? Or even, call s_config only for < 2.6.26 kernels ?

In both cases, I still see that i2c drivers should be able to be configured both using normal i2c probes (with board data) or by using s_config.

Besides that, I think s_config can be passing a void *, something like:
+ int (*s_config)(struct v4l2_subdev *sd, void *config_data);

As in my last rfc patch. This way you don't need to care which board data need to be passed. We can even pass a i2c board info there. That should just be agreed between bridge and sub dev drivers.

Quoted 7 lines

Regards,

Hans

Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG
Signature · 1 line
Eduardo Valentin
#22 lore raw

Re: [PATCH 08/10 v2] v4l2-subdev: add a v4l2_i2c_subdev_board() function

Hi,

Quoted 46 lines · Valentin Eduardo (Nokia-D/Helsinki)

Hi,

Quoted 19 lines
Quoted 1 line

There are two 'missing somethings': the first is that you can have a v4l2 driver that uses v4l2_i2c_subdev_board, but the i2c driver that is loaded by that call can also by used by other drivers need to be backwards compatible with older kernels.

So the i2c driver cannot in general obtain the irq and platform_data from i2c_client during probe, since it won't be set during probe (actually, the irq field in i2c_client doesn't even exist on pre-2.6.22 kernels).

But if v4l2_i2c_subdev_board calls s_config explicitly, then this data can be passed to the i2c driver in a manner that works for all kernels.

The second 'something' is that I need something like s_config anyway for those drivers that cannot use this new v4l2_i2c_subdev_board because they have to compile for all kernels. Those drivers can call the existing functions, and then call s_config explicitly.

Quoted 4 lines

For the embedded platforms it really doesn't matter: there you just use i2c_board_info, and the only time s_config comes into play is when the i2c driver can also be used by bridge drivers that cannot use v4l2_i2c_subdev_board.

I think this is heading to other direction that I first understood. I don't see why one i2c driver which implements the new i2c api would not setup its irq and platform data other then during probe time. But let's assume that.

In that case, i2c drivers, even though they implement the new i2c api, should not receive the board specific info during probe, but should wait until s_config time.

That would work for all kernels, but then i2c drivers would not have opportunity to communicate with device during probe time and do silly checks there.

Why can not v4l2_i2c_subdev_board be able to pass i2c_board_info using normal i2c api if we are >= 2.6.26, and let s_config to bridge driver? Or even, call s_config only for < 2.6.26 kernels ?

In both cases, I still see that i2c drivers should be able to be configured both using normal i2c probes (with board data) or by using s_config.

Besides that, I think s_config can be passing a void *, something like:

(quoted diff) +1 -0
+	int (*s_config)(struct v4l2_subdev *sd, void *config_data);
Quoted 3 lines

As in my last rfc patch. This way you don't need to care which board data need to be passed. We can even pass a i2c board info there. That should just be agreed between bridge and sub dev drivers.

I think I understood your point. Maybe what you are trying to keep is the same v4l2 api so that can be used in all kernel versions. Based on that we cannot pass i2c_board_info as v4l2 api function (at least for now).

So, I think I'm sending a patch with this in mind. Which is:
* Addition of s_config(irq, platform_data) into core callbacks set:
+ int (*s_config)(struct v4l2_subdev *sd, int irq, void *platform_data);

* Addition of v4l2_i2c_new_subdev_board, which is basically the same
of v4l2_i2c_new_subdev, but with two additional parameters: irq and platform_data. This function will pass these data to i2c normal probe procedure (if we are >= 2.6.26), and will call s_config with these two additional parameters.

So, both older i2c version compatible and newer i2c version only drivers can call it. Is that what you were thinking?

I'm sending that patch as well in other email.

Quoted 11 lines
Quoted 8 lines

Regards,

Hans

Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG
Signature · 1 line
Eduardo Valentin
Signature · 1 line
Eduardo Valentin
#23 lore raw

PATCH 1/1 v4l2_subdev i2c: Add v4l2_i2c_new_subdev_board i2c helper function

Device drivers of v4l2_subdev devices may want to have board specific data. This patch adds an helper function to allow bridge drivers to pass board specific data to v4l2_subdev drivers.

For those drivers which need to support kernel versions bellow 2.6.26, a .s_config callback was added. The idea of this callback is to pass board configuration as well. In that case, subdev driver should set .s_config properly, because v4l2_i2c_new_subdev_board will call the .s_config directly. Of course, if we are >= 2.6.26, the same data will be passed through i2c board info as well.

Priority: normal

linux/drivers/media/video/v4l2-common.c +35 -2
diff -r 41d2c77ae71f -r 905a6501f2a4 linux/drivers/media/video/v4l2-common.c
@@ -819,9 +819,10 @@
 
 
 /* Load an i2c sub-device. */
-struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
+static struct v4l2_subdev *__v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
 		struct i2c_adapter *adapter,
-		const char *module_name, const char *client_type, u8 addr)
+		const char *module_name, const char *client_type, u8 addr,
+		int irq, void *platform_data)
 {
 	struct v4l2_subdev *sd = NULL;
 	struct i2c_client *client;
@@ -840,6 +841,8 @@
 	memset(&info, 0, sizeof(info));
 	strlcpy(info.type, client_type, sizeof(info.type));
 	info.addr = addr;
+	info.irq = irq;
+	info.platform_data = platform_data;
 
 	/* Create the i2c client */
 	client = i2c_new_device(adapter, &info);
@@ -877,8 +880,38 @@
 #endif
 	return sd;
 }
+
+struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
+		struct i2c_adapter *adapter,
+		const char *module_name, const char *client_type, u8 addr)
+{
+	return __v4l2_i2c_new_subdev(v4l2_dev, adapter, module_name,
+		client_type, addr, 0, NULL);
+}
 EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev);
 
+struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
+		struct i2c_adapter *adapter,
+		const char *module_name, const char *client_type, u8 addr,
+		int irq, void *platform_data)
+{
+	struct v4l2_subdev *sd;
+	int err = 0;
+
+	sd = __v4l2_i2c_new_subdev(v4l2_dev, adapter, module_name, client_type,
+					addr, irq, platform_data);
+
+	/*
+	 * We return errors from v4l2_subdev_call only if we have the callback
+	 * as the .s_config is not mandatory
+	 */
+	if (sd && sd->ops && sd->ops->core && sd->ops->core->s_config)
+		err = sd->ops->core->s_config(sd, irq, platform_data);
+
+	return err < 0 ? NULL : sd;
+}
+EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev_board);
+
 /* Probe and load an i2c sub-device. */
 struct v4l2_subdev *v4l2_i2c_new_probed_subdev(struct v4l2_device *v4l2_dev,
 	struct i2c_adapter *adapter,
linux/include/media/v4l2-common.h +8 -0
diff -r 41d2c77ae71f -r 905a6501f2a4 linux/include/media/v4l2-common.h
@@ -147,6 +147,14 @@
 struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
 		struct i2c_adapter *adapter,
 		const char *module_name, const char *client_type, u8 addr);
+/*
+ * Same as v4l2_i2c_new_subdev, but with the opportunity to configure
+ * subdevice with board specific data (irq and platform_data).
+ */
+struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
+		struct i2c_adapter *adapter,
+		const char *module_name, const char *client_type, u8 addr,
+		int irq, void *platform_data);
 /* Probe and load an i2c module and return an initialized v4l2_subdev struct.
    Only call request_module if module_name != NULL.
    The client_type argument is the name of the chip that's on the adapter. */
linux/include/media/v4l2-subdev.h +1 -0
diff -r 41d2c77ae71f -r 905a6501f2a4 linux/include/media/v4l2-subdev.h
@@ -96,6 +96,7 @@
 struct v4l2_subdev_core_ops {
 	int (*g_chip_ident)(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip);
 	int (*log_status)(struct v4l2_subdev *sd);
+	int (*s_config)(struct v4l2_subdev *sd, int irq, void *platform_data);
 	int (*init)(struct v4l2_subdev *sd, u32 val);
 	int (*load_fw)(struct v4l2_subdev *sd);
 	int (*reset)(struct v4l2_subdev *sd, u32 val);
#24 lore raw

RFC v2 9/10 v4l2-subdev: re-add s_standby to v4l2_subdev_core_ops

In reply to Guennadi Liakhovetski

NOT FOR SUBMISSION. Probably, another solution has to be found. soc-camera drivers need an .init() (marked as "don't use") and a .halt() methods.

---

Hans, you moved s_standby to tuner_ops, and init is not recommended for new drivers. Suggestions?

 include/media/v4l2-subdev.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
include/media/v4l2-subdev.h +1 -0
index 1785608..ba907be 100644
@@ -97,6 +97,7 @@ struct v4l2_subdev_core_ops {
 	int (*g_chip_ident)(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip);
 	int (*log_status)(struct v4l2_subdev *sd);
 	int (*init)(struct v4l2_subdev *sd, u32 val);
+	int (*s_standby)(struct v4l2_subdev *sd, u32 standby);
 	int (*load_fw)(struct v4l2_subdev *sd);
 	int (*reset)(struct v4l2_subdev *sd, u32 val);
 	int (*s_gpio)(struct v4l2_subdev *sd, u32 val);
Signature · 1 line
1.6.2.4
#25 lore raw

Re: [RFC 09/10 v2] v4l2-subdev: re-add s_standby to v4l2_subdev_core_ops

Quoted 9 lines · On Friday 15 May 2009 19:20:18 Guennadi Liakhovetski wrote:

NOT FOR SUBMISSION. Probably, another solution has to be found. soc-camera drivers need an .init() (marked as "don't use") and a .halt() methods.

---

Hans, you moved s_standby to tuner_ops, and init is not recommended for new drivers. Suggestions?

Usual question: why do you need an init and halt? What do they do? One valid use case for init is to pass config data to the driver. I am considering to make it possible to setup the board_info data instead for an i2c subdev, so one can use the platform data to pass such info to the subdev driver. The disadvantage is that it cannot be used for pre-2.6.26 kernels.

An alternative might be a s_config ops that serves a similar purpose.

I want to leave s_standby in the tuner_ops: it's currently only used together with a tuner. It's also poorly designed.

A new halt or standby core ops should be better designed and it should be clear what the relationship is to the suspend and resume i2c driver ops (see e.g. msp3400-driver.c).

Regards,

Hans

Quoted 15 lines
 include/media/v4l2-subdev.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
include/media/v4l2-subdev.h +1 -0
index 1785608..ba907be 100644
@@ -97,6 +97,7 @@ struct v4l2_subdev_core_ops {
 	int (*g_chip_ident)(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident
 *chip); int (*log_status)(struct v4l2_subdev *sd);
 	int (*init)(struct v4l2_subdev *sd, u32 val);
+	int (*s_standby)(struct v4l2_subdev *sd, u32 standby);
 	int (*load_fw)(struct v4l2_subdev *sd);
 	int (*reset)(struct v4l2_subdev *sd, u32 val);
 	int (*s_gpio)(struct v4l2_subdev *sd, u32 val);
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG
#26 lore raw

Re: [RFC 09/10 v2] v4l2-subdev: re-add s_standby to v4l2_subdev_core_ops

Quoted 5 lines · Hans Verkuil
Quoted 4 lines · On Friday 15 May 2009 19:20:18 Guennadi Liakhovetski wrote:

NOT FOR SUBMISSION. Probably, another solution has to be found. soc-camera drivers need an .init() (marked as "don't use") and a .halt() methods.

Quoted 7 lines
Quoted 5 lines

---

Hans, you moved s_standby to tuner_ops, and init is not recommended for new drivers. Suggestions?

Usual question: why do you need an init and halt? What do they do?

Hm, maybe you're right, I don't need them. init() was used in soc_camera drivers on first open() to possibly reset the chip and put it in some reasonably pre-defined low-power state. But we can do this at the end of probe(), which even would be more correct, because even the first open should not change chip's configuration. And halt() (was called release() originally) is called on last close(). And it seems you shouldn't really do this at all - the chip should preserve its configuration between open/close cycles. Am I right? Does anyone among cc'ed authors have any objections against this change? The actual disable should indeed migrate to some PM functions, if implemented.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#27 lore raw

Re: [RFC 09/10 v2] v4l2-subdev: re-add s_standby to v4l2_subdev_core_ops

Quoted 14 lines · On Friday 22 May 2009 16:23:36 Guennadi Liakhovetski wrote:
Quoted 5 lines · Hans Verkuil
Quoted 4 lines · On Friday 15 May 2009 19:20:18 Guennadi Liakhovetski wrote:

NOT FOR SUBMISSION. Probably, another solution has to be found. soc-camera drivers need an .init() (marked as "don't use") and a .halt() methods.

Quoted 7 lines
Quoted 5 lines

---

Hans, you moved s_standby to tuner_ops, and init is not recommended for new drivers. Suggestions?

Usual question: why do you need an init and halt? What do they do?

Quoted 8 lines

Hm, maybe you're right, I don't need them. init() was used in soc_camera drivers on first open() to possibly reset the chip and put it in some reasonably pre-defined low-power state. But we can do this at the end of probe(), which even would be more correct, because even the first open should not change chip's configuration. And halt() (was called release() originally) is called on last close(). And it seems you shouldn't really do this at all - the chip should preserve its configuration between open/close cycles. Am I right?

That's correct.

It's interesting to see that init/halt/reset/powersaving type functions are usually not needed. I know that there are still a few i2c drivers implementing init and reset, and I also know that those can be removed since they are not needed at all. I just need to find some time to do the actual removal. So whenever I see these functions I always get suspicious :-)

Regards,

Hans

Quoted 10 lines

Does anyone among cc'ed authors have any
objections against this change? The actual disable should indeed migrate to some PM functions, if implemented.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG
#28 lore raw

Re: [RFC 09/10 v2] v4l2-subdev: re-add s_standby to v4l2_subdev_core_ops

In reply to Guennadi Liakhovetski
Quoted 12 lines · Guennadi Liakhovetski
Quoted 1 line

Usual question: why do you need an init and halt? What do they do?

Hm, maybe you're right, I don't need them. init() was used in soc_camera drivers on first open() to possibly reset the chip and put it in some reasonably pre-defined low-power state. But we can do this at the end of probe(), which even would be more correct, because even the first open should not change chip's configuration. And halt() (was called release() originally) is called on last close(). And it seems you shouldn't really do this at all - the chip should preserve its configuration between open/close cycles. Am I right?

Quoted 2 lines

Does anyone among cc'ed authors have any objections against this change? The actual disable should indeed migrate to some PM functions, if implemented.

If I understand correctly, what was done before was that on last close, the sensor was disabled (through sensor->release() call). What will be done now is leave the sensor on.

On an embedded system, the power eaten by an active sensor is usually too much compared to the other components.

So, if there is a solution which enables, on last close, to power down the device (or put it in low power mode), in the new API, I'm OK, even if it's a new powersaving function. If there is no such function and there will be a gap (let's say kernel 2.6.31 to 2.6.35) where the sensor will be left activated all the time, then I'm against.

Let me be even more precise about a usecase :
- a user takes a picture with his smartphone
- the same user then uses his phone to call his girlfriend
- the girlfriend has a lot of things to say, it lasts for 1 hour
In that case, the sensor _has_ to be switched off.

Cheers.

--
Robert

#29 lore raw

Re: [RFC 09/10 v2] v4l2-subdev: re-add s_standby to v4l2_subdev_core_ops

Quoted 29 lines · Robert Jarzmik
Quoted 12 lines · Guennadi Liakhovetski
Quoted 1 line

Usual question: why do you need an init and halt? What do they do?

Hm, maybe you're right, I don't need them. init() was used in soc_camera drivers on first open() to possibly reset the chip and put it in some reasonably pre-defined low-power state. But we can do this at the end of probe(), which even would be more correct, because even the first open should not change chip's configuration. And halt() (was called release() originally) is called on last close(). And it seems you shouldn't really do this at all - the chip should preserve its configuration between open/close cycles. Am I right?

Quoted 2 lines

Does anyone among cc'ed authors have any objections against this change? The actual disable should indeed migrate to some PM functions, if implemented.

If I understand correctly, what was done before was that on last close, the sensor was disabled (through sensor->release() call). What will be done now is leave the sensor on.

On an embedded system, the power eaten by an active sensor is usually too much compared to the other components.

So, if there is a solution which enables, on last close, to power down the device (or put it in low power mode), in the new API, I'm OK, even if it's a new powersaving function. If there is no such function and there will be a gap (let's say kernel 2.6.31 to 2.6.35) where the sensor will be left activated all the time, then I'm against.

Quoted 5 lines

Let me be even more precise about a usecase :
- a user takes a picture with his smartphone
- the same user then uses his phone to call his girlfriend
- the girlfriend has a lot of things to say, it lasts for 1 hour
In that case, the sensor _has_ to be switched off.

Nice example, thanks! Ok, of course, we must not leave the poor girl with her boyfriend's flat battery:-)

I think we can put the camera to a low-power state in streamoff. But - not power it off! This has to be done from system's PM functions. What was there on linux-pm about managing power of single devices?...

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#30 lore raw

Re: [RFC 09/10 v2] v4l2-subdev: re-add s_standby to v4l2_subdev_core_ops

Quoted 8 lines · Guennadi Liakhovetski
Quoted 5 lines

Let me be even more precise about a usecase :
- a user takes a picture with his smartphone
- the same user then uses his phone to call his girlfriend
- the girlfriend has a lot of things to say, it lasts for 1 hour
In that case, the sensor _has_ to be switched off.

Nice example, thanks! Ok, of course, we must not leave the poor girl with her boyfriend's flat battery:-)

Dear, of course not, imagine what she would do to him ! :)

Quoted 2 lines

I think we can put the camera to a low-power state in streamoff. But - not power it off! This has to be done from system's PM functions.

That means, from a sensor POV, through icd->stop_capture().
For my single mt9m111, it's fine by me, as the mt9m111 does have a powersave mode. Yet I'm wondering if there are sensors without that capability, with only one control (ie. one GPIO line) to switch them on and off ...

Quoted 1 line

What was there on linux-pm about managing power of single devices?...

Reference ?

Cheers.

--
Robert

#31 lore raw

Re: [RFC 09/10 v2] v4l2-subdev: re-add s_standby to v4l2_subdev_core_ops

Quoted 8 lines · Robert Jarzmik
Quoted 2 lines · Guennadi Liakhovetski

I think we can put the camera to a low-power state in streamoff. But - not power it off! This has to be done from system's PM functions.

That means, from a sensor POV, through icd->stop_capture().
For my single mt9m111, it's fine by me, as the mt9m111 does have a powersave mode. Yet I'm wondering if there are sensors without that capability, with only one control (ie. one GPIO line) to switch them on and off ...

Doesn't this actually belong to PM? I begin to think that our whole ->power() handling might be a bit suboptimally placed and should migrate to pm, one might give it some thinking...

Quoted 2 lines
Quoted 1 line

What was there on linux-pm about managing power of single devices?...

Reference ?

I meant this thread

http://thread.gmane.org/gmane.linux.power-management.general/4655/focus=4670

as you see, it is not very fresh, and I have no idea what came out of it, have a look if you're interested.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#32 lore raw

PATCH v2 10/10 soc-camera: (partially) convert to v4l2-(sub)dev API

In reply to Guennadi Liakhovetski

Convert the soc-camera framework to use the v4l2-(sub)dev API. Start using v4l2-subdev operations. Only a part of the interface between the soc_camera core, soc_camera host drivers on one side and soc_camera device drivers on the other side is replaced so far. The rest of the interface will be replaced in incremental steps, and will require extensions and, possibly, modifications to the v4l2-subdev code.

---

Ok, this one depends on the previous, so, it currently cannot go in. We have to come up with a solution to the init/s_standby question from the previoud patch.

 drivers/media/video/mt9m001.c              |  171 +++++++--------
 drivers/media/video/mt9m111.c              |  324 ++++++++++++----------------
 drivers/media/video/mt9t031.c              |  178 +++++++--------
 drivers/media/video/mt9v022.c              |  173 ++++++---------
 drivers/media/video/mx1_camera.c           |   31 ++--
 drivers/media/video/mx3_camera.c           |   54 ++---
 drivers/media/video/ov772x.c               |  169 ++++++---------
 drivers/media/video/pxa_camera.c           |  107 +++++-----
 drivers/media/video/sh_mobile_ceu_camera.c |   45 ++---
 drivers/media/video/soc_camera.c           |  255 +++++++++++++---------
 drivers/media/video/soc_camera_platform.c  |  116 +++++------
 drivers/media/video/tw9910.c               |  151 ++++++--------
 include/media/soc_camera.h                 |   25 +--
 13 files changed, 806 insertions(+), 993 deletions(-)
drivers/media/video/mt9m001.c +75 -96
index b0f4ad5..fc42061 100644
@@ -13,13 +13,13 @@
 #include <linux/i2c.h>
 #include <linux/log2.h>
 
-#include <media/v4l2-common.h>
+#include <media/v4l2-subdev.h>
 #include <media/v4l2-chip-ident.h>
 #include <media/soc_camera.h>
 
 /* mt9m001 i2c address 0x5d
- * The platform has to define i2c_board_info
- * and call i2c_register_board_info() */
+ * The platform has to define ctruct i2c_board_info objects and link to them
+ * from struct soc_camera_link */
 
 /* mt9m001 selected register addresses */
 #define MT9M001_CHIP_VERSION		0x00
@@ -69,10 +69,16 @@ static const struct soc_camera_data_format mt9m001_monochrome_formats[] = {
 };
 
 struct mt9m001 {
+	struct v4l2_subdev subdev;
 	int model;	/* V4L2_IDENT_MT9M001* codes from v4l2-chip-ident.h */
 	unsigned char autoexposure;
 };
 
+static struct mt9m001 *to_mt9m001(const struct i2c_client *client)
+{
+	return container_of(i2c_get_clientdata(client), struct mt9m001, subdev);
+}
+
 static int reg_read(struct i2c_client *client, const u8 reg)
 {
 	s32 data = i2c_smbus_read_word_data(client, reg);
@@ -107,35 +113,21 @@ static int reg_clear(struct i2c_client *client, const u8 reg,
 	return reg_write(client, reg, ret & ~data);
 }
 
-static int mt9m001_init(struct soc_camera_device *icd)
+static int mt9m001_init(struct v4l2_subdev *sd, u32 val)
 {
-	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-	struct soc_camera_link *icl = to_soc_camera_link(icd);
+	struct i2c_client *client = sd->priv;
 	int ret;
 
-	dev_dbg(&icd->dev, "%s\n", __func__);
-
-	if (icl->power) {
-		ret = icl->power(&client->dev, 1);
-		if (ret < 0) {
-			dev_err(icd->vdev->parent,
-				"Platform failed to power-on the camera.\n");
-			return ret;
-		}
-	}
+	dev_dbg(&client->dev, "%s\n", __func__);
 
-	/* The camera could have been already on, we reset it additionally */
-	if (icl->reset)
-		ret = icl->reset(&client->dev);
-	else
-		ret = -ENODEV;
+	/*
+	 * We don't know, whether platform provides reset,
+	 * issue a soft reset too
+	 */
+	ret = reg_write(client, MT9M001_RESET, 1);
+	if (!ret)
+		ret = reg_write(client, MT9M001_RESET, 0);
 
-	if (ret < 0) {
-		/* Either no platform reset, or platform reset failed */
-		ret = reg_write(client, MT9M001_RESET, 1);
-		if (!ret)
-			ret = reg_write(client, MT9M001_RESET, 0);
-	}
 	/* Disable chip, synchronous option update */
 	if (!ret)
 		ret = reg_write(client, MT9M001_OUTPUT_CONTROL, 0);
@@ -143,36 +135,22 @@ static int mt9m001_init(struct soc_camera_device *icd)
 	return ret;
 }
 
-static int mt9m001_release(struct soc_camera_device *icd)
+static int mt9m001_s_standby(struct v4l2_subdev *sd, u32 standby)
 {
-	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-	struct soc_camera_link *icl = to_soc_camera_link(icd);
+	struct i2c_client *client = sd->priv;
 
 	/* Disable the chip */
 	reg_write(client, MT9M001_OUTPUT_CONTROL, 0);
 
-	if (icl->power)
-		icl->power(&client->dev, 0);
-
-	return 0;
-}
-
-static int mt9m001_start_capture(struct soc_camera_device *icd)
-{
-	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-
-	/* Switch to master "normal" mode */
-	if (reg_write(client, MT9M001_OUTPUT_CONTROL, 2) < 0)
-		return -EIO;
 	return 0;
 }
 
-static int mt9m001_stop_capture(struct soc_camera_device *icd)
+static int mt9m001_s_stream(struct v4l2_subdev *sd, int enable)
 {
-	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
+	struct i2c_client *client = sd->priv;
 
-	/* Stop sensor readout */
-	if (reg_write(client, MT9M001_OUTPUT_CONTROL, 0) < 0)
+	/* Switch to master "normal" mode or stop sensor readout */
+	if (reg_write(client, MT9M001_OUTPUT_CONTROL, enable ? 2 : 0) < 0)
 		return -EIO;
 	return 0;
 }
@@ -220,7 +198,7 @@ static int mt9m001_set_crop(struct soc_camera_device *icd,
 			    struct v4l2_rect *rect)
 {
 	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-	struct mt9m001 *mt9m001 = i2c_get_clientdata(client);
+	struct mt9m001 *mt9m001 = to_mt9m001(client);
 	int ret;
 	const u16 hblank = 9, vblank = 25;
 
@@ -257,9 +235,10 @@ static int mt9m001_set_crop(struct soc_camera_device *icd,
 	return ret;
 }
 
-static int mt9m001_set_fmt(struct soc_camera_device *icd,
-			   struct v4l2_format *f)
+static int mt9m001_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
 {
+	struct i2c_client *client = sd->priv;
+	struct soc_camera_device *icd = client->dev.platform_data;
 	struct v4l2_rect rect = {
 		.left	= icd->x_current,
 		.top	= icd->y_current,
@@ -271,9 +250,10 @@ static int mt9m001_set_fmt(struct soc_camera_device *icd,
 	return mt9m001_set_crop(icd, &rect);
 }
 
-static int mt9m001_try_fmt(struct soc_camera_device *icd,
-			   struct v4l2_format *f)
+static int mt9m001_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
 {
+	struct i2c_client *client = sd->priv;
+	struct soc_camera_device *icd = client->dev.platform_data;
 	struct v4l2_pix_format *pix = &f->fmt.pix;
 
 	if (pix->height < 32 + icd->y_skip_top)
@@ -289,11 +269,11 @@ static int mt9m001_try_fmt(struct soc_camera_device *icd,
 	return 0;
 }
 
-static int mt9m001_get_chip_id(struct soc_camera_device *icd,
-			       struct v4l2_dbg_chip_ident *id)
+static int mt9m001_g_chip_ident(struct v4l2_subdev *sd,
+				struct v4l2_dbg_chip_ident *id)
 {
-	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-	struct mt9m001 *mt9m001 = i2c_get_clientdata(client);
+	struct i2c_client *client = sd->priv;
+	struct mt9m001 *mt9m001 = to_mt9m001(client);
 
 	if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
 		return -EINVAL;
@@ -308,10 +288,10 @@ static int mt9m001_get_chip_id(struct soc_camera_device *icd,
 }
 
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-static int mt9m001_get_register(struct soc_camera_device *icd,
-				struct v4l2_dbg_register *reg)
+static int mt9m001_g_register(struct v4l2_subdev *sd,
+			      struct v4l2_dbg_register *reg)
 {
-	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
+	struct i2c_client *client = sd->priv;
 
 	if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff)
 		return -EINVAL;
@@ -328,10 +308,10 @@ static int mt9m001_get_register(struct soc_camera_device *icd,
 	return 0;
 }
 
-static int mt9m001_set_register(struct soc_camera_device *icd,
-				struct v4l2_dbg_register *reg)
+static int mt9m001_s_register(struct v4l2_subdev *sd,
+			      struct v4l2_dbg_register *reg)
 {
-	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
+	struct i2c_client *client = sd->priv;
 
 	if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff)
 		return -EINVAL;
@@ -384,35 +364,18 @@ static const struct v4l2_queryctrl mt9m001_controls[] = {
 	}
 };
 
-static int mt9m001_get_control(struct soc_camera_device *, struct v4l2_control *);
-static int mt9m001_set_control(struct soc_camera_device *, struct v4l2_control *);
-
 static struct soc_camera_ops mt9m001_ops = {
-	.owner			= THIS_MODULE,
-	.init			= mt9m001_init,
-	.release		= mt9m001_release,
-	.start_capture		= mt9m001_start_capture,
-	.stop_capture		= mt9m001_stop_capture,
 	.set_crop		= mt9m001_set_crop,
-	.set_fmt		= mt9m001_set_fmt,
-	.try_fmt		= mt9m001_try_fmt,
 	.set_bus_param		= mt9m001_set_bus_param,
 	.query_bus_param	= mt9m001_query_bus_param,
 	.controls		= mt9m001_controls,
 	.num_controls		= ARRAY_SIZE(mt9m001_controls),
-	.get_control		= mt9m001_get_control,
-	.set_control		= mt9m001_set_control,
-	.get_chip_id		= mt9m001_get_chip_id,
-#ifdef CONFIG_VIDEO_ADV_DEBUG
-	.get_register		= mt9m001_get_register,
-	.set_register		= mt9m001_set_register,
-#endif
 };
 
-static int mt9m001_get_control(struct soc_camera_device *icd, struct v4l2_control *ctrl)
+static int mt9m001_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
 {
-	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-	struct mt9m001 *mt9m001 = i2c_get_clientdata(client);
+	struct i2c_client *client = sd->priv;
+	struct mt9m001 *mt9m001 = to_mt9m001(client);
 	int data;
 
 	switch (ctrl->id) {
@@ -429,10 +392,11 @@ static int mt9m001_get_control(struct soc_camera_device *icd, struct v4l2_contro
 	return 0;
 }
 
-static int mt9m001_set_control(struct soc_camera_device *icd, struct v4l2_control *ctrl)
+static int mt9m001_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
 {
-	struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-	struct mt9m001 *mt9m001 = i2c_get_clientdata(client);
+	struct i2c_client *client = sd->priv;
+	struct mt9m001 *mt9m001 = to_mt9m001(client);
+	struct soc_camera_device *icd = client->dev.platform_data;
 	const struct v4l2_queryctrl *qctrl;
 	int data;
 
@@ -527,10 +491,9 @@ static int mt9m001_set_control(struct soc_camera_device *icd, struct v4l2_contro
 static int mt9m001_video_probe(struct soc_camera_device *icd,
 			       struct i2c_client *client)
 {
-	struct mt9m001 *mt9m001 = i2c_get_clientdata(client);
+	struct mt9m001 *mt9m001 = to_mt9m001(client);
 	struct soc_camera_link *icl = to_soc_camera_link(icd);
 	s32 data;
-	int ret;
 	unsigned long flags;
 
 	/* We must have a parent by now. And it cannot be a wrong one.
@@ -539,11 +502,6 @@ static int mt9m001_video_probe(struct soc_camera_device *icd,
 	    to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
 		return -ENODEV;
 
-	/* Switch master clock on */
-	ret = soc_camera_video_start(icd, &client->dev);
-	if (ret)
-		return ret;
-
 	/* Enable the chip */
 	data = reg_write(client, MT9M001_CHIP_ENABLE, 1);
 	dev_dbg(&icd->dev, "write: %d\n", data);
@@ -551,8 +509,6 @@ static int mt9m001_video_probe(struct soc_camera_device *icd,
 	/* Read out the chip version register */
 	data = reg_read(client, MT9M001_CHIP_VERSION);
 
-	soc_camera_video_stop(icd);
-
 	/* must be 0x8411 or 0x8421 for colour sensor and 8431 for bw */
 	switch (data) {
 	case 0x8411:
@@ -608,6 +564,29 @@ static void mt9m001_video_remove(struct soc_camera_device *icd)
 		icl->free_bus(icl);
 }
 
+static struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = {
+	.init		= mt9m001_init,
+	.s_standby	= mt9m001_s_standby,
+	.g_ctrl		= mt9m001_g_ctrl,
+	.s_ctrl		= mt9m001_s_ctrl,
+	.g_chip_ident	= mt9m001_g_chip_ident,
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+	.g_register	= mt9m001_g_register,
+	.s_register	= mt9m001_s_register,
+#endif
+};
+
+static struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = {
+	.s_stream	= mt9m001_s_stream,
+	.s_fmt		= mt9m001_s_fmt,
+	.try_fmt	= mt9m001_try_fmt,
+};
+
+static struct v4l2_subdev_ops mt9m001_subdev_ops = {
+	.core	= &mt9m001_subdev_core_ops,
+	.video	= &mt9m001_subdev_video_ops,
+};
+
 static int mt9m001_probe(struct i2c_client *client,
 			 const struct i2c_device_id *did)
 {
@@ -638,7 +617,7 @@ static int mt9m001_probe(struct i2c_client *client,
 	if (!mt9m001)
 		return -ENOMEM;
 
-	i2c_set_clientdata(client, mt9m001);
+	v4l2_i2c_subdev_init(&mt9m001->subdev, client, &mt9m001_subdev_ops);
 
 	/* Second stage probe - when a capture adapter is there */
 	icd->ops	= &mt9m001_ops;
@@ -666,7 +645,7 @@ static int mt9m001_probe(struct i2c_client *client,
 
 static int mt9m001_remove(struct i2c_client *client)
 {
-	struct mt9m001 *mt9m001 = i2c_get_clientdata(client);
+	struct mt9m001 *mt9m001 = to_mt9m001(client);
 	struct soc_camera_device *icd = client->dev.platform_data;
 
 	mt9m001_video_remove(icd);
drivers/media/video/mt9m111.c +136 -188

669 lines not on this page · raw message

drivers/media/video/mt9t031.c +84 -94

342 lines not on this page · raw message

drivers/media/video/mt9v022.c +71 -102

315 lines not on this page · raw message

drivers/media/video/mx1_camera.c +14 -17
index 2d07520..fc60266 100644
@@ -219,7 +219,7 @@ static int mx1_camera_setup_dma(struct mx1_camera_dev *pcdev)
 	int ret;
 
 	if (unlikely(!pcdev->active)) {
-		dev_err(pcdev->soc_host.dev, "DMA End IRQ with no active buffer\n");
+		dev_err(pcdev->icd->dev.parent, "DMA End IRQ with no active buffer\n");
 		return -EFAULT;
 	}
 
@@ -229,7 +229,7 @@ static int mx1_camera_setup_dma(struct mx1_camera_dev *pcdev)
 		vbuf->size, pcdev->res->start +
 		CSIRXR, DMA_MODE_READ);
 	if (unlikely(ret))
-		dev_err(pcdev->soc_host.dev, "Failed to setup DMA sg list\n");
+		dev_err(pcdev->icd->dev.parent, "Failed to setup DMA sg list\n");
 
 	return ret;
 }
@@ -338,14 +338,14 @@ static void mx1_camera_dma_irq(int channel, void *data)
 	imx_dma_disable(channel);
 
 	if (unlikely(!pcdev->active)) {
-		dev_err(pcdev->soc_host.dev, "DMA End IRQ with no active buffer\n");
+		dev_err(pcdev->icd->dev.parent, "DMA End IRQ with no active buffer\n");
 		goto out;
 	}
 
 	vb = &pcdev->active->vb;
 	buf = container_of(vb, struct mx1_buffer, vb);
 	WARN_ON(buf->inwork || list_empty(&vb->queue));
-	dev_dbg(pcdev->soc_host.dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
+	dev_dbg(pcdev->icd->dev.parent, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
 		vb, vb->baddr, vb->bsize);
 
 	mx1_camera_wakeup(pcdev, vb, buf);
@@ -366,7 +366,7 @@ static void mx1_camera_init_videobuf(struct videobuf_queue *q,
 	struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
 	struct mx1_camera_dev *pcdev = ici->priv;
 
-	videobuf_queue_dma_contig_init(q, &mx1_videobuf_ops, ici->dev,
+	videobuf_queue_dma_contig_init(q, &mx1_videobuf_ops, icd->dev.parent,
 					&pcdev->lock,
 					V4L2_BUF_TYPE_VIDEO_CAPTURE,
 					V4L2_FIELD_NONE,
@@ -385,7 +385,7 @@ static int mclk_get_divisor(struct mx1_camera_dev *pcdev)
 	 * they get a nice Oops */
 	div = (lcdclk + 2 * mclk - 1) / (2 * mclk) - 1;
 
-	dev_dbg(pcdev->soc_host.dev, "System clock %lukHz, target freq %dkHz, "
+	dev_dbg(pcdev->icd->dev.parent, "System clock %lukHz, target freq %dkHz, "
 		"divisor %lu\n", lcdclk / 1000, mclk / 1000, div);
 
 	return div;
@@ -395,7 +395,7 @@ static void mx1_camera_activate(struct mx1_camera_dev *pcdev)
 {
 	unsigned int csicr1 = CSICR1_EN;
 
-	dev_dbg(pcdev->soc_host.dev, "Activate device\n");
+	dev_dbg(pcdev->icd->dev.parent, "Activate device\n");
 
 	clk_enable(pcdev->clk);
 
@@ -411,7 +411,7 @@ static void mx1_camera_activate(struct mx1_camera_dev *pcdev)
 
 static void mx1_camera_deactivate(struct mx1_camera_dev *pcdev)
 {
-	dev_dbg(pcdev->soc_host.dev, "Deactivate device\n");
+	dev_dbg(pcdev->icd->dev.parent, "Deactivate device\n");
 
 	/* Disable all CSI interface */
 	__raw_writel(0x00, pcdev->base + CSICR1);
@@ -436,10 +436,8 @@ static int mx1_camera_add_device(struct soc_camera_device *icd)
 		 icd->devnum);
 
 	mx1_camera_activate(pcdev);
-	ret = icd->ops->init(icd);
 
-	if (!ret)
-		pcdev->icd = icd;
+	pcdev->icd = icd;
 
 ebusy:
 	return ret;
@@ -463,8 +461,6 @@ static void mx1_camera_remove_device(struct soc_camera_device *icd)
 	dev_info(&icd->dev, "MX1 Camera driver detached from camera %d\n",
 		 icd->devnum);
 
-	icd->ops->release(icd);
-
 	mx1_camera_deactivate(pcdev);
 
 	pcdev->icd = NULL;
@@ -550,11 +546,11 @@ static int mx1_camera_set_fmt(struct soc_camera_device *icd,
 
 	xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
 	if (!xlate) {
-		dev_warn(ici->dev, "Format %x not found\n", pix->pixelformat);
+		dev_warn(icd->dev.parent, "Format %x not found\n", pix->pixelformat);
 		return -EINVAL;
 	}
 
-	ret = icd->ops->set_fmt(icd, f);
+	ret = v4l2_device_call_until_err(&ici->v4l2_dev, 0, video, s_fmt, f);
 	if (!ret) {
 		icd->buswidth = xlate->buswidth;
 		icd->current_fmt = xlate->host_fmt;
@@ -566,10 +562,11 @@ static int mx1_camera_set_fmt(struct soc_camera_device *icd,
 static int mx1_camera_try_fmt(struct soc_camera_device *icd,
 			      struct v4l2_format *f)
 {
+	struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
 	/* TODO: limit to mx1 hardware capabilities */
 
 	/* limit to sensor capabilities */
-	return icd->ops->try_fmt(icd, f);
+	return v4l2_device_call_until_err(&ici->v4l2_dev, 0, video, try_fmt, f);
 }
 
 static int mx1_camera_reqbufs(struct soc_camera_file *icf,
@@ -741,7 +738,7 @@ static int __init mx1_camera_probe(struct platform_device *pdev)
 	pcdev->soc_host.drv_name	= DRIVER_NAME;
 	pcdev->soc_host.ops		= &mx1_soc_camera_host_ops;
 	pcdev->soc_host.priv		= pcdev;
-	pcdev->soc_host.dev		= &pdev->dev;
+	pcdev->soc_host.v4l2_dev.dev	= &pdev->dev;
 	pcdev->soc_host.nr		= pdev->id;
 	err = soc_camera_host_register(&pcdev->soc_host);
 	if (err)
drivers/media/video/mx3_camera.c +20 -34

176 lines not on this page · raw message

drivers/media/video/ov772x.c +68 -101

341 lines not on this page · raw message

drivers/media/video/pxa_camera.c +49 -58

362 lines not on this page · raw message

drivers/media/video/sh_mobile_ceu_camera.c +19 -26

138 lines not on this page · raw message

drivers/media/video/soc_camera.c +149 -106

222 lines not on this page · raw message

drivers/media/video/soc_camera_platform.c +52 -64

116 lines not on this page · raw message

drivers/media/video/tw9910.c +63 -88

151 lines not on this page · raw message

include/media/soc_camera.h +6 -19
index d8b4256..e104802 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.6.2.4

Part of the diff is not shown here. View the raw message.

#33 lore raw
In reply to Guennadi Liakhovetski
Quoted 10 lines · Guennadi Liakhovetski

Hi all,

this is the next round of soc-camera conversions. Run-tested on i.MX31, PXA270, SH7722, compile-tested only for i.MX1. It should have been a "straight-forward" port of the previous version to a more current tree, but then I started converting soc_camera_platform, and things became a bit more complex... As a bonus, now soc-camera can handle not only i2c subdevices, and we can even drop the CONFIG_I2C dependency again. I'll also upload a comlpete stack somewhere a bit later, for example for those, wishing to test it on i.MX31, otherwise the series will not apply cleanly.

All available at

http://download.open-technology.de/soc-camera/20090515/

As you can see from 0000-base it is still based on next of 20090507, i.e., 9 days ago:-( If you take a newer tree, some of those patches will already be there, so, I think, the easiest would be to base your tests on the same base.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#34 lore raw
In reply to Guennadi Liakhovetski
Quoted 9 lines · Guennadi Liakhovetski

this is the next round of soc-camera conversions. Run-tested on i.MX31, PXA270, SH7722, compile-tested only for i.MX1. It should have been a "straight-forward" port of the previous version to a more current tree, but then I started converting soc_camera_platform, and things became a bit more complex... As a bonus, now soc-camera can handle not only i2c subdevices, and we can even drop the CONFIG_I2C dependency again. I'll also upload a comlpete stack somewhere a bit later, for example for those, wishing to test it on i.MX31, otherwise the series will not apply cleanly.

Quoted 6 lines

I'd like to push the first 8 of them asap, 9 and 10 will still have to be reworked

Paul, I put you on "cc" on all patches, because, unfortunately, several of them affect arch/sh. But I'll mention it explicitly in each such patch.

Looks ok to me, there shouldn't be any problems with taking these all through the v4l tree. Feel free to add my Acked-by if you like. I guess we will find out in -next if there are any conflicts or not :-)

#35 lore raw
Quoted 13 lines · Paul Mundt
Quoted 12 lines · Guennadi Liakhovetski

this is the next round of soc-camera conversions. Run-tested on i.MX31, PXA270, SH7722, compile-tested only for i.MX1. It should have been a "straight-forward" port of the previous version to a more current tree, but then I started converting soc_camera_platform, and things became a bit more complex... As a bonus, now soc-camera can handle not only i2c subdevices, and we can even drop the CONFIG_I2C dependency again. I'll also upload a comlpete stack somewhere a bit later, for example for those, wishing to test it on i.MX31, otherwise the series will not apply cleanly.

I'd like to push the first 8 of them asap, 9 and 10 will still have to be reworked

Quoted 6 lines
Quoted 3 lines

Paul, I put you on "cc" on all patches, because, unfortunately, several of them affect arch/sh. But I'll mention it explicitly in each such patch.

Looks ok to me, there shouldn't be any problems with taking these all through the v4l tree. Feel free to add my Acked-by if you like. I guess we will find out in -next if there are any conflicts or not :-)

Yes, can do this, thanks, but first these 3 patches (including Magnus' ack) have to be applied to sh:
http://www.mail-archive.com/[email protected]/msg05223.html
which in turn depend on
http://www.mail-archive.com/[email protected]/msg04724.html
and the latter one is already in the next tree. Would you like me to also merge and pull the above three patches via v4l or would you be applying them yourself?

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#36 lore raw
Quoted 22 lines · Guennadi Liakhovetski
Quoted 13 lines · Paul Mundt
Quoted 12 lines · Guennadi Liakhovetski

this is the next round of soc-camera conversions. Run-tested on i.MX31, PXA270, SH7722, compile-tested only for i.MX1. It should have been a "straight-forward" port of the previous version to a more current tree, but then I started converting soc_camera_platform, and things became a bit more complex... As a bonus, now soc-camera can handle not only i2c subdevices, and we can even drop the CONFIG_I2C dependency again. I'll also upload a comlpete stack somewhere a bit later, for example for those, wishing to test it on i.MX31, otherwise the series will not apply cleanly.

I'd like to push the first 8 of them asap, 9 and 10 will still have to be reworked

Quoted 6 lines
Quoted 3 lines

Paul, I put you on "cc" on all patches, because, unfortunately, several of them affect arch/sh. But I'll mention it explicitly in each such patch.

Looks ok to me, there shouldn't be any problems with taking these all through the v4l tree. Feel free to add my Acked-by if you like. I guess we will find out in -next if there are any conflicts or not :-)

Quoted 9 lines

Yes, can do this, thanks, but first these 3 patches (including Magnus' ack) have to be applied to sh:
http://www.mail-archive.com/[email protected]/msg05223.html
which in turn depend on
http://www.mail-archive.com/[email protected]/msg04724.html
and the latter one is already in the next tree. Would you like me to also merge and pull the above three patches via v4l or would you be applying them yourself?

I can take care of them once the dependent patch is merged.