diff options
author | Guennadi Liakhovetski <g.liakhovetski@gmx.de> | 2011-09-05 11:33:21 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-11-03 16:28:44 -0400 |
commit | 3dcc731a93679d75a1f90a969b34aa9d7acd1cbf (patch) | |
tree | 1210662011df8633dfbc822cbf50dcf8f447badc /drivers/media/video/soc_camera.c | |
parent | da83d9dc0ac18ffb07b5b344e237005a0ba08089 (diff) |
[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: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/soc_camera.c')
-rw-r--r-- | drivers/media/video/soc_camera.c | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c index 8d5c421a803c..d3eeb08be321 100644 --- a/drivers/media/video/soc_camera.c +++ b/drivers/media/video/soc_camera.c | |||
@@ -50,49 +50,52 @@ static LIST_HEAD(hosts); | |||
50 | static LIST_HEAD(devices); | 50 | static LIST_HEAD(devices); |
51 | static DEFINE_MUTEX(list_lock); /* Protects the list of hosts */ | 51 | static DEFINE_MUTEX(list_lock); /* Protects the list of hosts */ |
52 | 52 | ||
53 | static int soc_camera_power_set(struct soc_camera_device *icd, | 53 | static int soc_camera_power_on(struct soc_camera_device *icd, |
54 | struct soc_camera_link *icl, | 54 | struct soc_camera_link *icl) |
55 | int power_on) | ||
56 | { | 55 | { |
57 | int ret; | 56 | int ret; |
58 | 57 | ||
59 | if (power_on) { | 58 | ret = regulator_bulk_enable(icl->num_regulators, |
60 | ret = regulator_bulk_enable(icl->num_regulators, | 59 | icl->regulators); |
61 | icl->regulators); | 60 | if (ret < 0) { |
62 | if (ret < 0) { | 61 | dev_err(icd->pdev, "Cannot enable regulators\n"); |
63 | dev_err(icd->pdev, "Cannot enable regulators\n"); | 62 | return ret; |
64 | return ret; | 63 | } |
65 | } | ||
66 | 64 | ||
67 | if (icl->power) | 65 | if (icl->power) { |
68 | ret = icl->power(icd->pdev, power_on); | 66 | ret = icl->power(icd->pdev, 1); |
69 | if (ret < 0) { | 67 | if (ret < 0) { |
70 | dev_err(icd->pdev, | 68 | dev_err(icd->pdev, |
71 | "Platform failed to power-on the camera.\n"); | 69 | "Platform failed to power-on the camera.\n"); |
72 | 70 | ||
73 | regulator_bulk_disable(icl->num_regulators, | 71 | regulator_bulk_disable(icl->num_regulators, |
74 | icl->regulators); | 72 | icl->regulators); |
75 | return ret; | ||
76 | } | 73 | } |
77 | } else { | 74 | } |
78 | ret = 0; | 75 | |
79 | if (icl->power) | 76 | return ret; |
80 | ret = icl->power(icd->pdev, 0); | 77 | } |
78 | |||
79 | static int soc_camera_power_off(struct soc_camera_device *icd, | ||
80 | struct soc_camera_link *icl) | ||
81 | { | ||
82 | int ret; | ||
83 | |||
84 | if (icl->power) { | ||
85 | ret = icl->power(icd->pdev, 0); | ||
81 | if (ret < 0) { | 86 | if (ret < 0) { |
82 | dev_err(icd->pdev, | 87 | dev_err(icd->pdev, |
83 | "Platform failed to power-off the camera.\n"); | 88 | "Platform failed to power-off the camera.\n"); |
84 | return ret; | 89 | return ret; |
85 | } | 90 | } |
86 | |||
87 | ret = regulator_bulk_disable(icl->num_regulators, | ||
88 | icl->regulators); | ||
89 | if (ret < 0) { | ||
90 | dev_err(icd->pdev, "Cannot disable regulators\n"); | ||
91 | return ret; | ||
92 | } | ||
93 | } | 91 | } |
94 | 92 | ||
95 | return 0; | 93 | ret = regulator_bulk_disable(icl->num_regulators, |
94 | icl->regulators); | ||
95 | if (ret < 0) | ||
96 | dev_err(icd->pdev, "Cannot disable regulators\n"); | ||
97 | |||
98 | return ret; | ||
96 | } | 99 | } |
97 | 100 | ||
98 | const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc( | 101 | const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc( |
@@ -502,7 +505,7 @@ static int soc_camera_open(struct file *file) | |||
502 | }, | 505 | }, |
503 | }; | 506 | }; |
504 | 507 | ||
505 | ret = soc_camera_power_set(icd, icl, 1); | 508 | ret = soc_camera_power_on(icd, icl); |
506 | if (ret < 0) | 509 | if (ret < 0) |
507 | goto epower; | 510 | goto epower; |
508 | 511 | ||
@@ -556,7 +559,7 @@ esfmt: | |||
556 | eresume: | 559 | eresume: |
557 | ici->ops->remove(icd); | 560 | ici->ops->remove(icd); |
558 | eiciadd: | 561 | eiciadd: |
559 | soc_camera_power_set(icd, icl, 0); | 562 | soc_camera_power_off(icd, icl); |
560 | epower: | 563 | epower: |
561 | icd->use_count--; | 564 | icd->use_count--; |
562 | module_put(ici->ops->owner); | 565 | module_put(ici->ops->owner); |
@@ -580,7 +583,7 @@ static int soc_camera_close(struct file *file) | |||
580 | if (ici->ops->init_videobuf2) | 583 | if (ici->ops->init_videobuf2) |
581 | vb2_queue_release(&icd->vb2_vidq); | 584 | vb2_queue_release(&icd->vb2_vidq); |
582 | 585 | ||
583 | soc_camera_power_set(icd, icl, 0); | 586 | soc_camera_power_off(icd, icl); |
584 | } | 587 | } |
585 | 588 | ||
586 | if (icd->streamer == file) | 589 | if (icd->streamer == file) |
@@ -1026,7 +1029,7 @@ static int soc_camera_probe(struct soc_camera_device *icd) | |||
1026 | if (ret < 0) | 1029 | if (ret < 0) |
1027 | goto ereg; | 1030 | goto ereg; |
1028 | 1031 | ||
1029 | ret = soc_camera_power_set(icd, icl, 1); | 1032 | ret = soc_camera_power_on(icd, icl); |
1030 | if (ret < 0) | 1033 | if (ret < 0) |
1031 | goto epower; | 1034 | goto epower; |
1032 | 1035 | ||
@@ -1106,7 +1109,7 @@ static int soc_camera_probe(struct soc_camera_device *icd) | |||
1106 | 1109 | ||
1107 | ici->ops->remove(icd); | 1110 | ici->ops->remove(icd); |
1108 | 1111 | ||
1109 | soc_camera_power_set(icd, icl, 0); | 1112 | soc_camera_power_off(icd, icl); |
1110 | 1113 | ||
1111 | mutex_unlock(&icd->video_lock); | 1114 | mutex_unlock(&icd->video_lock); |
1112 | 1115 | ||
@@ -1129,7 +1132,7 @@ eadddev: | |||
1129 | evdc: | 1132 | evdc: |
1130 | ici->ops->remove(icd); | 1133 | ici->ops->remove(icd); |
1131 | eadd: | 1134 | eadd: |
1132 | soc_camera_power_set(icd, icl, 0); | 1135 | soc_camera_power_off(icd, icl); |
1133 | epower: | 1136 | epower: |
1134 | regulator_bulk_free(icl->num_regulators, icl->regulators); | 1137 | regulator_bulk_free(icl->num_regulators, icl->regulators); |
1135 | ereg: | 1138 | ereg: |