Skip to content

Commit

Permalink
[media] V4L: soc-camera: start removing struct soc_camera_device from…
Browse files Browse the repository at this point in the history
… client drivers

Remove most trivial uses of struct soc_camera_device from most client
drivers, abstracting some of them inside inline functions. Next steps
will eliminate remaining uses and modify inline functions to not use
struct soc_camera_device.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Guennadi Liakhovetski authored and Mauro Carvalho Chehab committed Nov 3, 2011
1 parent 09362ec commit 14178aa
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 286 deletions.
17 changes: 4 additions & 13 deletions drivers/media/video/imx074.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ static struct v4l2_subdev_ops imx074_subdev_ops = {
.video = &imx074_subdev_video_ops,
};

static int imx074_video_probe(struct soc_camera_device *icd,
struct i2c_client *client)
static int imx074_video_probe(struct i2c_client *client)
{
int ret;
u16 id;
Expand Down Expand Up @@ -409,17 +408,10 @@ static int imx074_probe(struct i2c_client *client,
const struct i2c_device_id *did)
{
struct imx074 *priv;
struct soc_camera_device *icd = client->dev.platform_data;
struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
struct soc_camera_link *icl;
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
int ret;

if (!icd) {
dev_err(&client->dev, "IMX074: missing soc-camera data!\n");
return -EINVAL;
}

icl = to_soc_camera_link(icd);
if (!icl) {
dev_err(&client->dev, "IMX074: missing platform data!\n");
return -EINVAL;
Expand All @@ -439,7 +431,7 @@ static int imx074_probe(struct i2c_client *client,

priv->fmt = &imx074_colour_fmts[0];

ret = imx074_video_probe(icd, client);
ret = imx074_video_probe(client);
if (ret < 0) {
kfree(priv);
return ret;
Expand All @@ -451,8 +443,7 @@ static int imx074_probe(struct i2c_client *client,
static int imx074_remove(struct i2c_client *client)
{
struct imx074 *priv = to_imx074(client);
struct soc_camera_device *icd = client->dev.platform_data;
struct soc_camera_link *icl = to_soc_camera_link(icd);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);

if (icl->free_bus)
icl->free_bus(icl);
Expand Down
39 changes: 11 additions & 28 deletions drivers/media/video/mt9m001.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ static int mt9m001_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)

/*
* The caller provides a supported format, as verified per
* call to icd->try_fmt()
* call to .try_mbus_fmt()
*/
if (!ret)
ret = reg_write(client, MT9M001_COLUMN_START, rect.left);
Expand Down Expand Up @@ -474,19 +474,14 @@ static int mt9m001_s_ctrl(struct v4l2_ctrl *ctrl)
* 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_link *icl,
struct i2c_client *client)
{
struct mt9m001 *mt9m001 = to_mt9m001(client);
struct soc_camera_link *icl = to_soc_camera_link(icd);
s32 data;
unsigned long flags;
int ret;

/* We must have a parent by now. And it cannot be a wrong one. */
BUG_ON(!icd->parent ||
to_soc_camera_host(icd->parent)->nr != icd->iface);

/* Enable the chip */
data = reg_write(client, MT9M001_CHIP_ENABLE, 1);
dev_dbg(&client->dev, "write: %d\n", data);
Expand Down Expand Up @@ -544,12 +539,8 @@ static int mt9m001_video_probe(struct soc_camera_device *icd,
return v4l2_ctrl_handler_setup(&mt9m001->hdl);
}

static void mt9m001_video_remove(struct soc_camera_device *icd)
static void mt9m001_video_remove(struct soc_camera_link *icl)
{
struct soc_camera_link *icl = to_soc_camera_link(icd);

dev_dbg(icd->pdev, "Video removed: %p, %p\n",
icd->parent, icd->vdev);
if (icl->free_bus)
icl->free_bus(icl);
}
Expand Down Expand Up @@ -594,8 +585,7 @@ static int mt9m001_g_mbus_config(struct v4l2_subdev *sd,
struct v4l2_mbus_config *cfg)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_device *icd = client->dev.platform_data;
struct soc_camera_link *icl = to_soc_camera_link(icd);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);

/* MT9M001 has all capture_format parameters fixed */
cfg->flags = V4L2_MBUS_PCLK_SAMPLE_FALLING |
Expand All @@ -610,9 +600,9 @@ static int mt9m001_g_mbus_config(struct v4l2_subdev *sd,
static int mt9m001_s_mbus_config(struct v4l2_subdev *sd,
const struct v4l2_mbus_config *cfg)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_device *icd = client->dev.platform_data;
struct soc_camera_link *icl = to_soc_camera_link(icd);
const struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_device *icd = soc_camera_from_i2c(client);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
/*
* Cannot use icd->current_fmt->host_fmt->bits_per_sample, because that
* is the number of bits, that the host has to sample, not the number of
Expand Down Expand Up @@ -658,17 +648,10 @@ static int mt9m001_probe(struct i2c_client *client,
const struct i2c_device_id *did)
{
struct mt9m001 *mt9m001;
struct soc_camera_device *icd = client->dev.platform_data;
struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
struct soc_camera_link *icl;
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
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;
Expand Down Expand Up @@ -716,7 +699,7 @@ static int mt9m001_probe(struct i2c_client *client,
mt9m001->rect.width = MT9M001_MAX_WIDTH;
mt9m001->rect.height = MT9M001_MAX_HEIGHT;

ret = mt9m001_video_probe(icd, client);
ret = mt9m001_video_probe(icl, client);
if (ret) {
v4l2_ctrl_handler_free(&mt9m001->hdl);
kfree(mt9m001);
Expand All @@ -728,11 +711,11 @@ static int mt9m001_probe(struct i2c_client *client,
static int mt9m001_remove(struct i2c_client *client)
{
struct mt9m001 *mt9m001 = to_mt9m001(client);
struct soc_camera_device *icd = client->dev.platform_data;
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);

v4l2_device_unregister_subdev(&mt9m001->subdev);
v4l2_ctrl_handler_free(&mt9m001->hdl);
mt9m001_video_remove(icd);
mt9m001_video_remove(icl);
kfree(mt9m001);

return 0;
Expand Down
24 changes: 5 additions & 19 deletions drivers/media/video/mt9m111.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,19 +784,12 @@ static int mt9m111_init(struct mt9m111 *mt9m111)
* 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 mt9m111_video_probe(struct soc_camera_device *icd,
struct i2c_client *client)
static int mt9m111_video_probe(struct i2c_client *client)
{
struct mt9m111 *mt9m111 = to_mt9m111(client);
s32 data;
int ret;

/* We must have a parent by now. And it cannot be a wrong one. */
BUG_ON(!icd->parent ||
to_soc_camera_host(icd->parent)->nr != icd->iface);

mt9m111->lastpage = -1;

data = reg_read(CHIP_VERSION);

switch (data) {
Expand Down Expand Up @@ -883,8 +876,7 @@ static int mt9m111_g_mbus_config(struct v4l2_subdev *sd,
struct v4l2_mbus_config *cfg)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_device *icd = client->dev.platform_data;
struct soc_camera_link *icl = to_soc_camera_link(icd);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);

cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING |
V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
Expand Down Expand Up @@ -915,17 +907,10 @@ static int mt9m111_probe(struct i2c_client *client,
const struct i2c_device_id *did)
{
struct mt9m111 *mt9m111;
struct soc_camera_device *icd = client->dev.platform_data;
struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
struct soc_camera_link *icl;
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
int ret;

if (!icd) {
dev_err(&client->dev, "mt9m111: soc-camera data missing!\n");
return -EINVAL;
}

icl = to_soc_camera_link(icd);
if (!icl) {
dev_err(&client->dev, "mt9m111: driver needs platform data\n");
return -EINVAL;
Expand Down Expand Up @@ -968,8 +953,9 @@ static int mt9m111_probe(struct i2c_client *client,
mt9m111->rect.width = MT9M111_MAX_WIDTH;
mt9m111->rect.height = MT9M111_MAX_HEIGHT;
mt9m111->fmt = &mt9m111_colour_fmts[0];
mt9m111->lastpage = -1;

ret = mt9m111_video_probe(icd, client);
ret = mt9m111_video_probe(client);
if (ret) {
v4l2_ctrl_handler_free(&mt9m111->hdl);
kfree(mt9m111);
Expand Down
22 changes: 8 additions & 14 deletions drivers/media/video/mt9t031.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ static int mt9t031_set_params(struct i2c_client *client,

/*
* The caller provides a supported format, as guaranteed by
* icd->try_fmt_cap(), soc_camera_s_crop() and soc_camera_cropcap()
* .try_mbus_fmt(), soc_camera_s_crop() and soc_camera_cropcap()
*/
if (ret >= 0)
ret = reg_write(client, MT9T031_COLUMN_START, rect->left);
Expand Down Expand Up @@ -573,8 +573,7 @@ static int mt9t031_runtime_suspend(struct device *dev)
static int mt9t031_runtime_resume(struct device *dev)
{
struct video_device *vdev = to_video_device(dev);
struct soc_camera_device *icd = dev_get_drvdata(vdev->parent);
struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
struct v4l2_subdev *sd = soc_camera_vdev_to_subdev(vdev);
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct mt9t031 *mt9t031 = to_mt9t031(client);

Expand Down Expand Up @@ -684,8 +683,7 @@ static int mt9t031_g_mbus_config(struct v4l2_subdev *sd,
struct v4l2_mbus_config *cfg)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_device *icd = client->dev.platform_data;
struct soc_camera_link *icl = to_soc_camera_link(icd);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);

cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING |
V4L2_MBUS_PCLK_SAMPLE_FALLING | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
Expand All @@ -700,8 +698,7 @@ static int mt9t031_s_mbus_config(struct v4l2_subdev *sd,
const struct v4l2_mbus_config *cfg)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_device *icd = client->dev.platform_data;
struct soc_camera_link *icl = to_soc_camera_link(icd);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);

if (soc_camera_apply_board_flags(icl, cfg) &
V4L2_MBUS_PCLK_SAMPLE_FALLING)
Expand Down Expand Up @@ -737,16 +734,13 @@ static int mt9t031_probe(struct i2c_client *client,
const struct i2c_device_id *did)
{
struct mt9t031 *mt9t031;
struct soc_camera_device *icd = client->dev.platform_data;
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
int ret;

if (icd) {
struct soc_camera_link *icl = to_soc_camera_link(icd);
if (!icl) {
dev_err(&client->dev, "MT9T031 driver needs platform data\n");
return -EINVAL;
}
if (!icl) {
dev_err(&client->dev, "MT9T031 driver needs platform data\n");
return -EINVAL;
}

if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) {
Expand Down
Loading

0 comments on commit 14178aa

Please sign in to comment.