Commit 499757a7 authored by Guennadi Liakhovetski's avatar Guennadi Liakhovetski Committed by Mauro Carvalho Chehab

V4L/DVB (12504): 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.

Cc: Paul Mundt <lethal@linux-sh.org>
Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski@gmx.de>
Acked-by: default avatarPaul Mundt <lethal@linux-sh.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 6ebd949a
...@@ -307,6 +307,9 @@ static int camera_set_capture(struct soc_camera_platform_info *info, ...@@ -307,6 +307,9 @@ static int camera_set_capture(struct soc_camera_platform_info *info,
return ret; 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 = { static struct soc_camera_platform_info camera_info = {
.iface = 0, .iface = 0,
.format_name = "UYVY", .format_name = "UYVY",
...@@ -320,6 +323,10 @@ static struct soc_camera_platform_info camera_info = { ...@@ -320,6 +323,10 @@ static struct soc_camera_platform_info camera_info = {
.bus_param = SOCAM_PCLK_SAMPLE_RISING | SOCAM_HSYNC_ACTIVE_HIGH | .bus_param = SOCAM_PCLK_SAMPLE_RISING | SOCAM_HSYNC_ACTIVE_HIGH |
SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_MASTER | SOCAM_DATAWIDTH_8, SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_MASTER | SOCAM_DATAWIDTH_8,
.set_capture = camera_set_capture, .set_capture = camera_set_capture,
.link = {
.add_device = ap325rxa_camera_add,
.del_device = ap325rxa_camera_del,
},
}; };
static struct platform_device camera_device = { static struct platform_device camera_device = {
...@@ -329,15 +336,20 @@ static struct platform_device camera_device = { ...@@ -329,15 +336,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) if (icl != &camera_info.link || camera_probe() <= 0)
platform_device_register(&camera_device); 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 */ #endif /* CONFIG_I2C */
static int ov7725_power(struct device *dev, int mode) static int ov7725_power(struct device *dev, int mode)
...@@ -417,12 +429,20 @@ static struct ov772x_camera_info ov7725_info = { ...@@ -417,12 +429,20 @@ static struct ov772x_camera_info ov7725_info = {
}, },
}; };
static struct platform_device ap325rxa_camera = { static struct platform_device ap325rxa_camera[] = {
{
.name = "soc-camera-pdrv", .name = "soc-camera-pdrv",
.id = 0, .id = 0,
.dev = { .dev = {
.platform_data = &ov7725_info.link, .platform_data = &ov7725_info.link,
}, },
}, {
.name = "soc-camera-pdrv",
.id = 1,
.dev = {
.platform_data = &camera_info.link,
},
},
}; };
static struct platform_device *ap325rxa_devices[] __initdata = { static struct platform_device *ap325rxa_devices[] __initdata = {
...@@ -432,7 +452,8 @@ static struct platform_device *ap325rxa_devices[] __initdata = { ...@@ -432,7 +452,8 @@ static struct platform_device *ap325rxa_devices[] __initdata = {
&ceu_device, &ceu_device,
&nand_flash_device, &nand_flash_device,
&sdcard_cn3_device, &sdcard_cn3_device,
&ap325rxa_camera, &ap325rxa_camera[0],
&ap325rxa_camera[1],
}; };
static struct spi_board_info ap325rxa_spi_devices[] = { static struct spi_board_info ap325rxa_spi_devices[] = {
......
...@@ -1165,45 +1165,76 @@ void soc_camera_video_stop(struct soc_camera_device *icd) ...@@ -1165,45 +1165,76 @@ void soc_camera_video_stop(struct soc_camera_device *icd)
} }
EXPORT_SYMBOL(soc_camera_video_stop); EXPORT_SYMBOL(soc_camera_video_stop);
static int __devinit soc_camera_pdrv_probe(struct platform_device *pdev) #ifdef CONFIG_I2C_BOARDINFO
static int soc_camera_init_i2c(struct platform_device *pdev,
struct soc_camera_link *icl)
{ {
struct soc_camera_link *icl = pdev->dev.platform_data;
struct i2c_adapter *adap;
struct i2c_client *client; struct i2c_client *client;
struct i2c_adapter *adap = i2c_get_adapter(icl->i2c_adapter_id);
int ret;
if (!icl)
return -EINVAL;
adap = i2c_get_adapter(icl->i2c_adapter_id);
if (!adap) { if (!adap) {
dev_warn(&pdev->dev, "Cannot get adapter #%d. No driver?\n", ret = -ENODEV;
dev_err(&pdev->dev, "Cannot get adapter #%d. No driver?\n",
icl->i2c_adapter_id); icl->i2c_adapter_id);
/* -ENODEV and -ENXIO do not produce an error on probe()... */ goto ei2cga;
return -ENOENT;
} }
icl->board_info->platform_data = icl; icl->board_info->platform_data = icl;
client = i2c_new_device(adap, icl->board_info); client = i2c_new_device(adap, icl->board_info);
if (!client) { if (!client) {
i2c_put_adapter(adap); ret = -ENOMEM;
return -ENOMEM; goto ei2cnd;
} }
platform_set_drvdata(pdev, client); platform_set_drvdata(pdev, client);
return 0; return 0;
ei2cnd:
i2c_put_adapter(adap);
ei2cga:
return ret;
} }
static int __devexit soc_camera_pdrv_remove(struct platform_device *pdev) static void soc_camera_free_i2c(struct platform_device *pdev)
{ {
struct i2c_client *client = platform_get_drvdata(pdev); struct i2c_client *client = platform_get_drvdata(pdev);
if (!client) if (!client)
return -ENODEV; return;
i2c_unregister_device(client); i2c_unregister_device(client);
i2c_put_adapter(client->adapter); i2c_put_adapter(client->adapter);
}
#else
#define soc_camera_init_i2c(d, icl) (-ENODEV)
#define soc_camera_free_i2c(d) do {} while (0)
#endif
static int __devinit soc_camera_pdrv_probe(struct platform_device *pdev)
{
struct soc_camera_link *icl = pdev->dev.platform_data;
if (!icl)
return -EINVAL;
if (icl->board_info)
return soc_camera_init_i2c(pdev, icl);
else if (!icl->add_device || !icl->del_device)
return -EINVAL;
/* &pdev->dev will become &icd->dev */
return icl->add_device(icl, &pdev->dev);
}
static int __devexit soc_camera_pdrv_remove(struct platform_device *pdev)
{
struct soc_camera_link *icl = pdev->dev.platform_data;
if (icl->board_info)
soc_camera_free_i2c(pdev);
else
icl->del_device(icl);
return 0; return 0;
} }
......
...@@ -102,6 +102,12 @@ struct soc_camera_link { ...@@ -102,6 +102,12 @@ struct soc_camera_link {
int i2c_adapter_id; int i2c_adapter_id;
struct i2c_board_info *board_info; struct i2c_board_info *board_info;
const char *module_name; 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 */ /* Optional callbacks to power on or off and reset the sensor */
int (*power)(struct device *, int); int (*power)(struct device *, int);
int (*reset)(struct device *); int (*reset)(struct device *);
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#define __SOC_CAMERA_H__ #define __SOC_CAMERA_H__
#include <linux/videodev2.h> #include <linux/videodev2.h>
#include <media/soc_camera.h>
struct soc_camera_platform_info { struct soc_camera_platform_info {
int iface; int iface;
...@@ -21,6 +22,7 @@ struct soc_camera_platform_info { ...@@ -21,6 +22,7 @@ struct soc_camera_platform_info {
unsigned long bus_param; unsigned long bus_param;
void (*power)(int); void (*power)(int);
int (*set_capture)(struct soc_camera_platform_info *info, int enable); int (*set_capture)(struct soc_camera_platform_info *info, int enable);
struct soc_camera_link link;
}; };
#endif /* __SOC_CAMERA_H__ */ #endif /* __SOC_CAMERA_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment