Commit 3dcc731a authored by Guennadi Liakhovetski's avatar Guennadi Liakhovetski Committed by Mauro Carvalho Chehab

[media] V4L: soc-camera: split a function into two

The soc_camera_power_set() function processes two cases: power on anf off.
These two cases don't share and common code, and the function is always
called with a constant power on / off argument. Splitting this function
into two removes a condition check, reduces indentation levels and makes
the code look cleaner.
Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent da83d9dc
...@@ -50,49 +50,52 @@ static LIST_HEAD(hosts); ...@@ -50,49 +50,52 @@ 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_set(struct soc_camera_device *icd, static int soc_camera_power_on(struct soc_camera_device *icd,
struct soc_camera_link *icl, struct soc_camera_link *icl)
int power_on)
{ {
int ret; int ret;
if (power_on) { ret = regulator_bulk_enable(icl->num_regulators,
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(icd->pdev, "Cannot enable regulators\n"); return ret;
return ret; }
}
if (icl->power) if (icl->power) {
ret = icl->power(icd->pdev, power_on); ret = icl->power(icd->pdev, 1);
if (ret < 0) { if (ret < 0) {
dev_err(icd->pdev, dev_err(icd->pdev,
"Platform failed to power-on the camera.\n"); "Platform failed to power-on the camera.\n");
regulator_bulk_disable(icl->num_regulators, regulator_bulk_disable(icl->num_regulators,
icl->regulators); icl->regulators);
return ret;
} }
} else { }
ret = 0;
if (icl->power) return ret;
ret = icl->power(icd->pdev, 0); }
static int soc_camera_power_off(struct soc_camera_device *icd,
struct soc_camera_link *icl)
{
int ret;
if (icl->power) {
ret = icl->power(icd->pdev, 0);
if (ret < 0) { if (ret < 0) {
dev_err(icd->pdev, dev_err(icd->pdev,
"Platform failed to power-off the camera.\n"); "Platform failed to power-off the camera.\n");
return ret; return ret;
} }
ret = regulator_bulk_disable(icl->num_regulators,
icl->regulators);
if (ret < 0) {
dev_err(icd->pdev, "Cannot disable regulators\n");
return ret;
}
} }
return 0; ret = regulator_bulk_disable(icl->num_regulators,
icl->regulators);
if (ret < 0)
dev_err(icd->pdev, "Cannot disable regulators\n");
return ret;
} }
const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc( const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc(
...@@ -502,7 +505,7 @@ static int soc_camera_open(struct file *file) ...@@ -502,7 +505,7 @@ static int soc_camera_open(struct file *file)
}, },
}; };
ret = soc_camera_power_set(icd, icl, 1); ret = soc_camera_power_on(icd, icl);
if (ret < 0) if (ret < 0)
goto epower; goto epower;
...@@ -556,7 +559,7 @@ static int soc_camera_open(struct file *file) ...@@ -556,7 +559,7 @@ static int soc_camera_open(struct file *file)
eresume: eresume:
ici->ops->remove(icd); ici->ops->remove(icd);
eiciadd: eiciadd:
soc_camera_power_set(icd, icl, 0); soc_camera_power_off(icd, icl);
epower: epower:
icd->use_count--; icd->use_count--;
module_put(ici->ops->owner); module_put(ici->ops->owner);
...@@ -580,7 +583,7 @@ static int soc_camera_close(struct file *file) ...@@ -580,7 +583,7 @@ static int soc_camera_close(struct file *file)
if (ici->ops->init_videobuf2) if (ici->ops->init_videobuf2)
vb2_queue_release(&icd->vb2_vidq); vb2_queue_release(&icd->vb2_vidq);
soc_camera_power_set(icd, icl, 0); soc_camera_power_off(icd, icl);
} }
if (icd->streamer == file) if (icd->streamer == file)
...@@ -1026,7 +1029,7 @@ static int soc_camera_probe(struct soc_camera_device *icd) ...@@ -1026,7 +1029,7 @@ static int soc_camera_probe(struct soc_camera_device *icd)
if (ret < 0) if (ret < 0)
goto ereg; goto ereg;
ret = soc_camera_power_set(icd, icl, 1); ret = soc_camera_power_on(icd, icl);
if (ret < 0) if (ret < 0)
goto epower; goto epower;
...@@ -1106,7 +1109,7 @@ static int soc_camera_probe(struct soc_camera_device *icd) ...@@ -1106,7 +1109,7 @@ static int soc_camera_probe(struct soc_camera_device *icd)
ici->ops->remove(icd); ici->ops->remove(icd);
soc_camera_power_set(icd, icl, 0); soc_camera_power_off(icd, icl);
mutex_unlock(&icd->video_lock); mutex_unlock(&icd->video_lock);
...@@ -1129,7 +1132,7 @@ static int soc_camera_probe(struct soc_camera_device *icd) ...@@ -1129,7 +1132,7 @@ static int soc_camera_probe(struct soc_camera_device *icd)
evdc: evdc:
ici->ops->remove(icd); ici->ops->remove(icd);
eadd: eadd:
soc_camera_power_set(icd, icl, 0); soc_camera_power_off(icd, icl);
epower: epower:
regulator_bulk_free(icl->num_regulators, icl->regulators); regulator_bulk_free(icl->num_regulators, icl->regulators);
ereg: ereg:
......
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