Commit 4ec10bac authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Mauro Carvalho Chehab

[media] soc-camera: Add and use soc_camera_power_[on|off]() helper functions

Instead of forcing all soc-camera drivers to go through the mid-layer to
handle power management, create soc_camera_power_[on|off]() functions
that can be called from the subdev .s_power() operation to manage
regulators and platform-specific power handling. This allows non
soc-camera hosts to use soc-camera-aware clients.
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
[g.liakhovetski@gmx.de: fix compile breakage]
Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 24592adc
...@@ -268,6 +268,14 @@ static int imx074_g_chip_ident(struct v4l2_subdev *sd, ...@@ -268,6 +268,14 @@ static int imx074_g_chip_ident(struct v4l2_subdev *sd,
return 0; return 0;
} }
static int imx074_s_power(struct v4l2_subdev *sd, int on)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
return soc_camera_set_power(&client->dev, icl, on);
}
static int imx074_g_mbus_config(struct v4l2_subdev *sd, static int imx074_g_mbus_config(struct v4l2_subdev *sd,
struct v4l2_mbus_config *cfg) struct v4l2_mbus_config *cfg)
{ {
...@@ -292,6 +300,7 @@ static struct v4l2_subdev_video_ops imx074_subdev_video_ops = { ...@@ -292,6 +300,7 @@ static struct v4l2_subdev_video_ops imx074_subdev_video_ops = {
static struct v4l2_subdev_core_ops imx074_subdev_core_ops = { static struct v4l2_subdev_core_ops imx074_subdev_core_ops = {
.g_chip_ident = imx074_g_chip_ident, .g_chip_ident = imx074_g_chip_ident,
.s_power = imx074_s_power,
}; };
static struct v4l2_subdev_ops imx074_subdev_ops = { static struct v4l2_subdev_ops imx074_subdev_ops = {
......
...@@ -377,6 +377,14 @@ static int mt9m001_s_register(struct v4l2_subdev *sd, ...@@ -377,6 +377,14 @@ static int mt9m001_s_register(struct v4l2_subdev *sd,
} }
#endif #endif
static int mt9m001_s_power(struct v4l2_subdev *sd, int on)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
return soc_camera_set_power(&client->dev, icl, on);
}
static int mt9m001_g_volatile_ctrl(struct v4l2_ctrl *ctrl) static int mt9m001_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
{ {
struct mt9m001 *mt9m001 = container_of(ctrl->handler, struct mt9m001 *mt9m001 = container_of(ctrl->handler,
...@@ -566,6 +574,7 @@ static struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = { ...@@ -566,6 +574,7 @@ static struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = {
.g_register = mt9m001_g_register, .g_register = mt9m001_g_register,
.s_register = mt9m001_s_register, .s_register = mt9m001_s_register,
#endif #endif
.s_power = mt9m001_s_power,
}; };
static int mt9m001_enum_fmt(struct v4l2_subdev *sd, unsigned int index, static int mt9m001_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
......
...@@ -831,10 +831,37 @@ static int mt9m111_video_probe(struct i2c_client *client) ...@@ -831,10 +831,37 @@ static int mt9m111_video_probe(struct i2c_client *client)
return v4l2_ctrl_handler_setup(&mt9m111->hdl); return v4l2_ctrl_handler_setup(&mt9m111->hdl);
} }
static int mt9m111_power_on(struct mt9m111 *mt9m111)
{
struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
int ret;
ret = soc_camera_power_on(&client->dev, icl);
if (ret < 0)
return ret;
ret = mt9m111_resume(mt9m111);
if (ret < 0) {
dev_err(&client->dev, "Failed to resume the sensor: %d\n", ret);
soc_camera_power_off(&client->dev, icl);
}
return ret;
}
static void mt9m111_power_off(struct mt9m111 *mt9m111)
{
struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
mt9m111_suspend(mt9m111);
soc_camera_power_off(&client->dev, icl);
}
static int mt9m111_s_power(struct v4l2_subdev *sd, int on) static int mt9m111_s_power(struct v4l2_subdev *sd, int on)
{ {
struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
struct i2c_client *client = v4l2_get_subdevdata(sd);
int ret = 0; int ret = 0;
mutex_lock(&mt9m111->power_lock); mutex_lock(&mt9m111->power_lock);
...@@ -844,23 +871,18 @@ static int mt9m111_s_power(struct v4l2_subdev *sd, int on) ...@@ -844,23 +871,18 @@ static int mt9m111_s_power(struct v4l2_subdev *sd, int on)
* update the power state. * update the power state.
*/ */
if (mt9m111->power_count == !on) { if (mt9m111->power_count == !on) {
if (on) { if (on)
ret = mt9m111_resume(mt9m111); ret = mt9m111_power_on(mt9m111);
if (ret) { else
dev_err(&client->dev, mt9m111_power_off(mt9m111);
"Failed to resume the sensor: %d\n", ret);
goto out;
}
} else {
mt9m111_suspend(mt9m111);
}
} }
/* Update the power count. */ if (!ret) {
mt9m111->power_count += on ? 1 : -1; /* Update the power count. */
WARN_ON(mt9m111->power_count < 0); mt9m111->power_count += on ? 1 : -1;
WARN_ON(mt9m111->power_count < 0);
}
out:
mutex_unlock(&mt9m111->power_lock); mutex_unlock(&mt9m111->power_lock);
return ret; return ret;
} }
......
...@@ -616,12 +616,19 @@ static struct device_type mt9t031_dev_type = { ...@@ -616,12 +616,19 @@ static struct device_type mt9t031_dev_type = {
static int mt9t031_s_power(struct v4l2_subdev *sd, int on) static int mt9t031_s_power(struct v4l2_subdev *sd, int on)
{ {
struct i2c_client *client = v4l2_get_subdevdata(sd); struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
struct video_device *vdev = soc_camera_i2c_to_vdev(client); struct video_device *vdev = soc_camera_i2c_to_vdev(client);
int ret;
if (on) if (on) {
ret = soc_camera_power_on(&client->dev, icl);
if (ret < 0)
return ret;
vdev->dev.type = &mt9t031_dev_type; vdev->dev.type = &mt9t031_dev_type;
else } else {
vdev->dev.type = NULL; vdev->dev.type = NULL;
soc_camera_power_off(&client->dev, icl);
}
return 0; return 0;
} }
......
...@@ -776,12 +776,21 @@ static int mt9t112_s_register(struct v4l2_subdev *sd, ...@@ -776,12 +776,21 @@ static int mt9t112_s_register(struct v4l2_subdev *sd,
} }
#endif #endif
static int mt9t112_s_power(struct v4l2_subdev *sd, int on)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
return soc_camera_set_power(&client->dev, icl, on);
}
static struct v4l2_subdev_core_ops mt9t112_subdev_core_ops = { static struct v4l2_subdev_core_ops mt9t112_subdev_core_ops = {
.g_chip_ident = mt9t112_g_chip_ident, .g_chip_ident = mt9t112_g_chip_ident,
#ifdef CONFIG_VIDEO_ADV_DEBUG #ifdef CONFIG_VIDEO_ADV_DEBUG
.g_register = mt9t112_g_register, .g_register = mt9t112_g_register,
.s_register = mt9t112_s_register, .s_register = mt9t112_s_register,
#endif #endif
.s_power = mt9t112_s_power,
}; };
......
...@@ -445,6 +445,14 @@ static int mt9v022_s_register(struct v4l2_subdev *sd, ...@@ -445,6 +445,14 @@ static int mt9v022_s_register(struct v4l2_subdev *sd,
} }
#endif #endif
static int mt9v022_s_power(struct v4l2_subdev *sd, int on)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
return soc_camera_set_power(&client->dev, icl, on);
}
static int mt9v022_g_volatile_ctrl(struct v4l2_ctrl *ctrl) static int mt9v022_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
{ {
struct mt9v022 *mt9v022 = container_of(ctrl->handler, struct mt9v022 *mt9v022 = container_of(ctrl->handler,
...@@ -664,6 +672,7 @@ static struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = { ...@@ -664,6 +672,7 @@ static struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = {
.g_register = mt9v022_g_register, .g_register = mt9v022_g_register,
.s_register = mt9v022_s_register, .s_register = mt9v022_s_register,
#endif #endif
.s_power = mt9v022_s_power,
}; };
static int mt9v022_enum_fmt(struct v4l2_subdev *sd, unsigned int index, static int mt9v022_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
......
...@@ -742,6 +742,14 @@ static int ov2640_s_register(struct v4l2_subdev *sd, ...@@ -742,6 +742,14 @@ static int ov2640_s_register(struct v4l2_subdev *sd,
} }
#endif #endif
static int ov2640_s_power(struct v4l2_subdev *sd, int on)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
return soc_camera_set_power(&client->dev, icl, on);
}
/* Select the nearest higher resolution for capture */ /* Select the nearest higher resolution for capture */
static const struct ov2640_win_size *ov2640_select_win(u32 *width, u32 *height) static const struct ov2640_win_size *ov2640_select_win(u32 *width, u32 *height)
{ {
...@@ -988,6 +996,7 @@ static struct v4l2_subdev_core_ops ov2640_subdev_core_ops = { ...@@ -988,6 +996,7 @@ static struct v4l2_subdev_core_ops ov2640_subdev_core_ops = {
.g_register = ov2640_g_register, .g_register = ov2640_g_register,
.s_register = ov2640_s_register, .s_register = ov2640_s_register,
#endif #endif
.s_power = ov2640_s_power,
}; };
static int ov2640_g_mbus_config(struct v4l2_subdev *sd, static int ov2640_g_mbus_config(struct v4l2_subdev *sd,
......
...@@ -933,13 +933,17 @@ static int ov5642_g_mbus_config(struct v4l2_subdev *sd, ...@@ -933,13 +933,17 @@ static int ov5642_g_mbus_config(struct v4l2_subdev *sd,
static int ov5642_s_power(struct v4l2_subdev *sd, int on) static int ov5642_s_power(struct v4l2_subdev *sd, int on)
{ {
struct i2c_client *client; struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
int ret; int ret;
if (!on) if (!on)
return 0; return soc_camera_power_off(&client->dev, icl);
ret = soc_camera_power_on(&client->dev, icl);
if (ret < 0)
return ret;
client = v4l2_get_subdevdata(sd);
ret = ov5642_write_array(client, ov5642_default_regs_init); ret = ov5642_write_array(client, ov5642_default_regs_init);
if (!ret) if (!ret)
ret = ov5642_set_resolution(sd); ret = ov5642_set_resolution(sd);
......
...@@ -432,6 +432,14 @@ static int ov6650_set_register(struct v4l2_subdev *sd, ...@@ -432,6 +432,14 @@ static int ov6650_set_register(struct v4l2_subdev *sd,
} }
#endif #endif
static int ov6650_s_power(struct v4l2_subdev *sd, int on)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
return soc_camera_set_power(&client->dev, icl, on);
}
static int ov6650_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) static int ov6650_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
{ {
struct i2c_client *client = v4l2_get_subdevdata(sd); struct i2c_client *client = v4l2_get_subdevdata(sd);
...@@ -866,6 +874,7 @@ static struct v4l2_subdev_core_ops ov6650_core_ops = { ...@@ -866,6 +874,7 @@ static struct v4l2_subdev_core_ops ov6650_core_ops = {
.g_register = ov6650_get_register, .g_register = ov6650_get_register,
.s_register = ov6650_set_register, .s_register = ov6650_set_register,
#endif #endif
.s_power = ov6650_s_power,
}; };
/* Request bus settings on camera side */ /* Request bus settings on camera side */
......
...@@ -683,6 +683,14 @@ static int ov772x_s_register(struct v4l2_subdev *sd, ...@@ -683,6 +683,14 @@ static int ov772x_s_register(struct v4l2_subdev *sd,
} }
#endif #endif
static int ov772x_s_power(struct v4l2_subdev *sd, int on)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
return soc_camera_set_power(&client->dev, icl, on);
}
static const struct ov772x_win_size *ov772x_select_win(u32 width, u32 height) static const struct ov772x_win_size *ov772x_select_win(u32 width, u32 height)
{ {
__u32 diff; __u32 diff;
...@@ -996,6 +1004,7 @@ static struct v4l2_subdev_core_ops ov772x_subdev_core_ops = { ...@@ -996,6 +1004,7 @@ static struct v4l2_subdev_core_ops ov772x_subdev_core_ops = {
.g_register = ov772x_g_register, .g_register = ov772x_g_register,
.s_register = ov772x_s_register, .s_register = ov772x_s_register,
#endif #endif
.s_power = ov772x_s_power,
}; };
static int ov772x_enum_fmt(struct v4l2_subdev *sd, unsigned int index, static int ov772x_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
......
...@@ -333,6 +333,14 @@ static int ov9640_set_register(struct v4l2_subdev *sd, ...@@ -333,6 +333,14 @@ static int ov9640_set_register(struct v4l2_subdev *sd,
} }
#endif #endif
static int ov9640_s_power(struct v4l2_subdev *sd, int on)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
return soc_camera_set_power(&client->dev, icl, on);
}
/* select nearest higher resolution for capture */ /* select nearest higher resolution for capture */
static void ov9640_res_roundup(u32 *width, u32 *height) static void ov9640_res_roundup(u32 *width, u32 *height)
{ {
...@@ -632,7 +640,7 @@ static struct v4l2_subdev_core_ops ov9640_core_ops = { ...@@ -632,7 +640,7 @@ static struct v4l2_subdev_core_ops ov9640_core_ops = {
.g_register = ov9640_get_register, .g_register = ov9640_get_register,
.s_register = ov9640_set_register, .s_register = ov9640_set_register,
#endif #endif
.s_power = ov9640_s_power,
}; };
/* Request bus settings on camera side */ /* Request bus settings on camera side */
......
...@@ -786,17 +786,27 @@ static int ov9740_g_chip_ident(struct v4l2_subdev *sd, ...@@ -786,17 +786,27 @@ static int ov9740_g_chip_ident(struct v4l2_subdev *sd,
static int ov9740_s_power(struct v4l2_subdev *sd, int on) static int ov9740_s_power(struct v4l2_subdev *sd, int on)
{ {
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
struct ov9740_priv *priv = to_ov9740(sd); struct ov9740_priv *priv = to_ov9740(sd);
int ret;
if (!priv->current_enable)
return 0;
if (on) { if (on) {
ov9740_s_fmt(sd, &priv->current_mf); ret = soc_camera_power_on(&client->dev, icl);
ov9740_s_stream(sd, priv->current_enable); if (ret < 0)
return ret;
if (priv->current_enable) {
ov9740_s_fmt(sd, &priv->current_mf);
ov9740_s_stream(sd, 1);
}
} else { } else {
ov9740_s_stream(sd, 0); if (priv->current_enable) {
priv->current_enable = true; ov9740_s_stream(sd, 0);
priv->current_enable = true;
}
soc_camera_power_off(&client->dev, icl);
} }
return 0; return 0;
......
...@@ -1180,6 +1180,14 @@ static int rj54n1_s_register(struct v4l2_subdev *sd, ...@@ -1180,6 +1180,14 @@ static int rj54n1_s_register(struct v4l2_subdev *sd,
} }
#endif #endif
static int rj54n1_s_power(struct v4l2_subdev *sd, int on)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
return soc_camera_set_power(&client->dev, icl, on);
}
static int rj54n1_s_ctrl(struct v4l2_ctrl *ctrl) static int rj54n1_s_ctrl(struct v4l2_ctrl *ctrl)
{ {
struct rj54n1 *rj54n1 = container_of(ctrl->handler, struct rj54n1, hdl); struct rj54n1 *rj54n1 = container_of(ctrl->handler, struct rj54n1, hdl);
...@@ -1230,6 +1238,7 @@ static struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = { ...@@ -1230,6 +1238,7 @@ static struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = {
.g_register = rj54n1_g_register, .g_register = rj54n1_g_register,
.s_register = rj54n1_s_register, .s_register = rj54n1_s_register,
#endif #endif
.s_power = rj54n1_s_power,
}; };
static int rj54n1_g_mbus_config(struct v4l2_subdev *sd, static int rj54n1_g_mbus_config(struct v4l2_subdev *sd,
......
...@@ -566,6 +566,14 @@ static int tw9910_s_register(struct v4l2_subdev *sd, ...@@ -566,6 +566,14 @@ static int tw9910_s_register(struct v4l2_subdev *sd,
} }
#endif #endif
static int tw9910_s_power(struct v4l2_subdev *sd, int on)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
return soc_camera_set_power(&client->dev, icl, on);
}
static int tw9910_set_frame(struct v4l2_subdev *sd, u32 *width, u32 *height) static int tw9910_set_frame(struct v4l2_subdev *sd, u32 *width, u32 *height)
{ {
struct i2c_client *client = v4l2_get_subdevdata(sd); struct i2c_client *client = v4l2_get_subdevdata(sd);
...@@ -814,6 +822,7 @@ static struct v4l2_subdev_core_ops tw9910_subdev_core_ops = { ...@@ -814,6 +822,7 @@ static struct v4l2_subdev_core_ops tw9910_subdev_core_ops = {
.g_register = tw9910_g_register, .g_register = tw9910_g_register,
.s_register = tw9910_s_register, .s_register = tw9910_s_register,
#endif #endif
.s_power = tw9910_s_power,
}; };
static int tw9910_enum_fmt(struct v4l2_subdev *sd, unsigned int index, static int tw9910_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
......
...@@ -50,72 +50,77 @@ static LIST_HEAD(hosts); ...@@ -50,72 +50,77 @@ static LIST_HEAD(hosts);
static LIST_HEAD(devices); static LIST_HEAD(devices);
static DEFINE_MUTEX(list_lock); /* Protects the list of hosts */ static DEFINE_MUTEX(list_lock); /* Protects the list of hosts */
static int soc_camera_power_on(struct soc_camera_device *icd, int soc_camera_power_on(struct device *dev, struct soc_camera_link *icl)
struct soc_camera_link *icl)
{ {
struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
int ret = regulator_bulk_enable(icl->num_regulators, int ret = regulator_bulk_enable(icl->num_regulators,
icl->regulators); icl->regulators);
if (ret < 0) { if (ret < 0) {
dev_err(icd->pdev, "Cannot enable regulators\n"); dev_err(dev, "Cannot enable regulators\n");
return ret; return ret;
} }
if (icl->power) { if (icl->power) {
ret = icl->power(icd->control, 1); ret = icl->power(dev, 1);
if (ret < 0) { if (ret < 0) {
dev_err(icd->pdev, dev_err(dev,
"Platform failed to power-on the camera.\n"); "Platform failed to power-on the camera.\n");
goto elinkpwr; regulator_bulk_disable(icl->num_regulators,
icl->regulators);
} }
} }
ret = v4l2_subdev_call(sd, core, s_power, 1);
if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
goto esdpwr;
return 0;
esdpwr:
if (icl->power)
icl->power(icd->control, 0);
elinkpwr:
regulator_bulk_disable(icl->num_regulators,
icl->regulators);
return ret; return ret;
} }
EXPORT_SYMBOL(soc_camera_power_on);
static int soc_camera_power_off(struct soc_camera_device *icd, int soc_camera_power_off(struct device *dev, struct soc_camera_link *icl)
struct soc_camera_link *icl)
{ {
struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
int ret = 0; int ret = 0;
int err; int err;
err = v4l2_subdev_call(sd, core, s_power, 0);
if (err < 0 && err != -ENOIOCTLCMD && err != -ENODEV) {
dev_err(icd->pdev, "Subdev failed to power-off the camera.\n");
ret = err;
}
if (icl->power) { if (icl->power) {
err = icl->power(icd->control, 0); err = icl->power(dev, 0);
if (err < 0) { if (err < 0) {
dev_err(icd->pdev, dev_err(dev,
"Platform failed to power-off the camera.\n"); "Platform failed to power-off the camera.\n");
ret = ret ? : err; ret = err;
} }
} }
err = regulator_bulk_disable(icl->num_regulators, err = regulator_bulk_disable(icl->num_regulators,
icl->regulators); icl->regulators);
if (err < 0) { if (err < 0) {
dev_err(icd->pdev, "Cannot disable regulators\n"); dev_err(dev, "Cannot disable regulators\n");
ret = ret ? : err; ret = ret ? : err;
} }
return ret; return ret;
} }
EXPORT_SYMBOL(soc_camera_power_off);
static int __soc_camera_power_on(struct soc_camera_device *icd)
{
struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
int ret;
ret = v4l2_subdev_call(sd, core, s_power, 1);
if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
return ret;
return 0;
}
static int __soc_camera_power_off(struct soc_camera_device *icd)
{
struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
int ret;
ret = v4l2_subdev_call(sd, core, s_power, 0);
if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
return ret;
return 0;
}
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_device *icd, unsigned int fourcc)
...@@ -551,7 +556,7 @@ static int soc_camera_open(struct file *file) ...@@ -551,7 +556,7 @@ static int soc_camera_open(struct file *file)
goto eiciadd; goto eiciadd;
} }
ret = soc_camera_power_on(icd, icl); ret = __soc_camera_power_on(icd);
if (ret < 0) if (ret < 0)
goto epower; goto epower;
...@@ -594,7 +599,7 @@ static int soc_camera_open(struct file *file) ...@@ -594,7 +599,7 @@ static int soc_camera_open(struct file *file)
esfmt: esfmt:
pm_runtime_disable(&icd->vdev->dev); pm_runtime_disable(&icd->vdev->dev);
eresume: eresume:
soc_camera_power_off(icd, icl); __soc_camera_power_off(icd);
epower: epower:
ici->ops->remove(icd); ici->ops->remove(icd);
eiciadd: eiciadd:
...@@ -614,8 +619,6 @@ static int soc_camera_close(struct file *file) ...@@ -614,8 +619,6 @@ static int soc_camera_close(struct file *file)
mutex_lock(&icd->video_lock); mutex_lock(&icd->video_lock);
icd->use_count--; icd->use_count--;
if (!icd->use_count) { if (!icd->use_count) {
struct soc_camera_link *icl = to_soc_camera_link(icd);
pm_runtime_suspend(&icd->vdev->dev); pm_runtime_suspend(&icd->vdev->dev);
pm_runtime_disable(&icd->vdev->dev); pm_runtime_disable(&icd->vdev->dev);
...@@ -623,7 +626,7 @@ static int soc_camera_close(struct file *file) ...@@ -623,7 +626,7 @@ static int soc_camera_close(struct file *file)
vb2_queue_release(&icd->vb2_vidq); vb2_queue_release(&icd->vb2_vidq);
ici->ops->remove(icd); ici->ops->remove(icd);
soc_camera_power_off(icd, icl); __soc_camera_power_off(icd);
} }
if (icd->streamer == file) if (icd->streamer == file)
...@@ -1088,8 +1091,14 @@ static int soc_camera_probe(struct soc_camera_device *icd) ...@@ -1088,8 +1091,14 @@ static int soc_camera_probe(struct soc_camera_device *icd)
* subdevice has not been initialised yet. We'll have to call it once * subdevice has not been initialised yet. We'll have to call it once
* again after initialisation, even though it shouldn't be needed, we * again after initialisation, even though it shouldn't be needed, we
* don't do any IO here. * don't do any IO here.
*
* The device pointer passed to soc_camera_power_on(), and ultimately to
* the platform callback, should be the subdev physical device. However,
* we have no way to retrieve a pointer to that device here. This isn't
* a real issue, as no platform currently uses the device pointer, and
* this soc_camera_power_on() call will be removed in the next commit.
*/ */
ret = soc_camera_power_on(icd, icl); ret = soc_camera_power_on(icd->pdev, icl);
if (ret < 0) if (ret < 0)
goto epower; goto epower;
...@@ -1162,7 +1171,7 @@ static int soc_camera_probe(struct soc_camera_device *icd) ...@@ -1162,7 +1171,7 @@ static int soc_camera_probe(struct soc_camera_device *icd)
ici->ops->remove(icd); ici->ops->remove(icd);
soc_camera_power_off(icd, icl); __soc_camera_power_off(icd);
mutex_unlock(&icd->video_lock); mutex_unlock(&icd->video_lock);
...@@ -1184,7 +1193,7 @@ static int soc_camera_probe(struct soc_camera_device *icd) ...@@ -1184,7 +1193,7 @@ static int soc_camera_probe(struct soc_camera_device *icd)
video_device_release(icd->vdev); video_device_release(icd->vdev);
icd->vdev = NULL; icd->vdev = NULL;
evdc: evdc:
soc_camera_power_off(icd, icl); __soc_camera_power_off(icd);
epower: epower:
ici->ops->remove(icd); ici->ops->remove(icd);
eadd: eadd:
......
...@@ -50,7 +50,16 @@ static int soc_camera_platform_fill_fmt(struct v4l2_subdev *sd, ...@@ -50,7 +50,16 @@ static int soc_camera_platform_fill_fmt(struct v4l2_subdev *sd,
return 0; return 0;
} }
static struct v4l2_subdev_core_ops platform_subdev_core_ops; static int soc_camera_platform_s_power(struct v4l2_subdev *sd, int on)
{
struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
return soc_camera_set_power(p->icd->control, p->icd->link, on);
}
static struct v4l2_subdev_core_ops platform_subdev_core_ops = {
.s_power = soc_camera_platform_s_power,
};
static int soc_camera_platform_enum_fmt(struct v4l2_subdev *sd, unsigned int index, static int soc_camera_platform_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
enum v4l2_mbus_pixelcode *code) enum v4l2_mbus_pixelcode *code)
......
...@@ -254,6 +254,16 @@ unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl, ...@@ -254,6 +254,16 @@ unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl,
unsigned long soc_camera_apply_board_flags(struct soc_camera_link *icl, unsigned long soc_camera_apply_board_flags(struct soc_camera_link *icl,
const struct v4l2_mbus_config *cfg); const struct v4l2_mbus_config *cfg);
int soc_camera_power_on(struct device *dev, struct soc_camera_link *icl);
int soc_camera_power_off(struct device *dev, struct soc_camera_link *icl);
static inline int soc_camera_set_power(struct device *dev,
struct soc_camera_link *icl, bool on)
{
return on ? soc_camera_power_on(dev, icl)
: soc_camera_power_off(dev, icl);
}
/* This is only temporary here - until v4l2-subdev begins to link to video_device */ /* This is only temporary here - until v4l2-subdev begins to link to video_device */
#include <linux/i2c.h> #include <linux/i2c.h>
static inline struct video_device *soc_camera_i2c_to_vdev(const struct i2c_client *client) static inline struct video_device *soc_camera_i2c_to_vdev(const struct i2c_client *client)
......
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