aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2013-04-08 05:31:30 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2013-04-14 18:52:56 -0400
commit55b2a312c29695520f813e61d668318169895ba7 (patch)
tree75ed8a62d98b0dc0e01048ade3e4f93de357c8c7 /drivers/media
parenta58841d0dcb79aebc558a1b55d29995f62aa61a4 (diff)
[media] radio-si4713: use V4L2 core lock
Simplify locking by using the V4L2 core lock mechanism. This allows us to remove all locking from the i2c module. This will also simplify the upcoming conversion to the control framework. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Acked-by: Eduardo Valentin <edubezval@gmail.com> Tested-by: Eduardo Valentin <edubezval@gmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/radio/radio-si4713.c4
-rw-r--r--drivers/media/radio/si4713-i2c.c156
-rw-r--r--drivers/media/radio/si4713-i2c.h1
3 files changed, 40 insertions, 121 deletions
diff --git a/drivers/media/radio/radio-si4713.c b/drivers/media/radio/radio-si4713.c
index f0f0a90c69ed..633c545438f7 100644
--- a/drivers/media/radio/radio-si4713.c
+++ b/drivers/media/radio/radio-si4713.c
@@ -49,6 +49,7 @@ MODULE_ALIAS("platform:radio-si4713");
49struct radio_si4713_device { 49struct radio_si4713_device {
50 struct v4l2_device v4l2_dev; 50 struct v4l2_device v4l2_dev;
51 struct video_device radio_dev; 51 struct video_device radio_dev;
52 struct mutex lock;
52}; 53};
53 54
54/* radio_si4713_fops - file operations interface */ 55/* radio_si4713_fops - file operations interface */
@@ -247,6 +248,7 @@ static int radio_si4713_pdriver_probe(struct platform_device *pdev)
247 rval = -ENOMEM; 248 rval = -ENOMEM;
248 goto exit; 249 goto exit;
249 } 250 }
251 mutex_init(&rsdev->lock);
250 252
251 rval = v4l2_device_register(&pdev->dev, &rsdev->v4l2_dev); 253 rval = v4l2_device_register(&pdev->dev, &rsdev->v4l2_dev);
252 if (rval) { 254 if (rval) {
@@ -272,6 +274,8 @@ static int radio_si4713_pdriver_probe(struct platform_device *pdev)
272 274
273 rsdev->radio_dev = radio_si4713_vdev_template; 275 rsdev->radio_dev = radio_si4713_vdev_template;
274 rsdev->radio_dev.v4l2_dev = &rsdev->v4l2_dev; 276 rsdev->radio_dev.v4l2_dev = &rsdev->v4l2_dev;
277 /* Serialize all access to the si4713 */
278 rsdev->radio_dev.lock = &rsdev->lock;
275 video_set_drvdata(&rsdev->radio_dev, rsdev); 279 video_set_drvdata(&rsdev->radio_dev, rsdev);
276 if (video_register_device(&rsdev->radio_dev, VFL_TYPE_RADIO, radio_nr)) { 280 if (video_register_device(&rsdev->radio_dev, VFL_TYPE_RADIO, radio_nr)) {
277 dev_err(&pdev->dev, "Could not register video device.\n"); 281 dev_err(&pdev->dev, "Could not register video device.\n");
diff --git a/drivers/media/radio/si4713-i2c.c b/drivers/media/radio/si4713-i2c.c
index e305c14272b5..1cb9a2e7f683 100644
--- a/drivers/media/radio/si4713-i2c.c
+++ b/drivers/media/radio/si4713-i2c.c
@@ -21,7 +21,6 @@
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */ 22 */
23 23
24#include <linux/mutex.h>
25#include <linux/completion.h> 24#include <linux/completion.h>
26#include <linux/delay.h> 25#include <linux/delay.h>
27#include <linux/interrupt.h> 26#include <linux/interrupt.h>
@@ -458,15 +457,13 @@ static int si4713_checkrev(struct si4713_device *sdev)
458 int rval; 457 int rval;
459 u8 resp[SI4713_GETREV_NRESP]; 458 u8 resp[SI4713_GETREV_NRESP];
460 459
461 mutex_lock(&sdev->mutex);
462
463 rval = si4713_send_command(sdev, SI4713_CMD_GET_REV, 460 rval = si4713_send_command(sdev, SI4713_CMD_GET_REV,
464 NULL, 0, 461 NULL, 0,
465 resp, ARRAY_SIZE(resp), 462 resp, ARRAY_SIZE(resp),
466 DEFAULT_TIMEOUT); 463 DEFAULT_TIMEOUT);
467 464
468 if (rval < 0) 465 if (rval < 0)
469 goto unlock; 466 return rval;
470 467
471 if (resp[1] == SI4713_PRODUCT_NUMBER) { 468 if (resp[1] == SI4713_PRODUCT_NUMBER) {
472 v4l2_info(&sdev->sd, "chip found @ 0x%02x (%s)\n", 469 v4l2_info(&sdev->sd, "chip found @ 0x%02x (%s)\n",
@@ -475,9 +472,6 @@ static int si4713_checkrev(struct si4713_device *sdev)
475 v4l2_err(&sdev->sd, "Invalid product number\n"); 472 v4l2_err(&sdev->sd, "Invalid product number\n");
476 rval = -EINVAL; 473 rval = -EINVAL;
477 } 474 }
478
479unlock:
480 mutex_unlock(&sdev->mutex);
481 return rval; 475 return rval;
482} 476}
483 477
@@ -778,17 +772,9 @@ static int si4713_tx_rds_ps(struct si4713_device *sdev, u8 psid,
778 772
779static int si4713_set_power_state(struct si4713_device *sdev, u8 value) 773static int si4713_set_power_state(struct si4713_device *sdev, u8 value)
780{ 774{
781 int rval;
782
783 mutex_lock(&sdev->mutex);
784
785 if (value) 775 if (value)
786 rval = si4713_powerup(sdev); 776 return si4713_powerup(sdev);
787 else 777 return si4713_powerdown(sdev);
788 rval = si4713_powerdown(sdev);
789
790 mutex_unlock(&sdev->mutex);
791 return rval;
792} 778}
793 779
794static int si4713_set_mute(struct si4713_device *sdev, u16 mute) 780static int si4713_set_mute(struct si4713_device *sdev, u16 mute)
@@ -797,8 +783,6 @@ static int si4713_set_mute(struct si4713_device *sdev, u16 mute)
797 783
798 mute = set_mute(mute); 784 mute = set_mute(mute);
799 785
800 mutex_lock(&sdev->mutex);
801
802 if (sdev->power_state) 786 if (sdev->power_state)
803 rval = si4713_write_property(sdev, 787 rval = si4713_write_property(sdev,
804 SI4713_TX_LINE_INPUT_MUTE, mute); 788 SI4713_TX_LINE_INPUT_MUTE, mute);
@@ -806,8 +790,6 @@ static int si4713_set_mute(struct si4713_device *sdev, u16 mute)
806 if (rval >= 0) 790 if (rval >= 0)
807 sdev->mute = get_mute(mute); 791 sdev->mute = get_mute(mute);
808 792
809 mutex_unlock(&sdev->mutex);
810
811 return rval; 793 return rval;
812} 794}
813 795
@@ -820,15 +802,13 @@ static int si4713_set_rds_ps_name(struct si4713_device *sdev, char *ps_name)
820 if (!strlen(ps_name)) 802 if (!strlen(ps_name))
821 memset(ps_name, 0, MAX_RDS_PS_NAME + 1); 803 memset(ps_name, 0, MAX_RDS_PS_NAME + 1);
822 804
823 mutex_lock(&sdev->mutex);
824
825 if (sdev->power_state) { 805 if (sdev->power_state) {
826 /* Write the new ps name and clear the padding */ 806 /* Write the new ps name and clear the padding */
827 for (i = 0; i < MAX_RDS_PS_NAME; i += (RDS_BLOCK / 2)) { 807 for (i = 0; i < MAX_RDS_PS_NAME; i += (RDS_BLOCK / 2)) {
828 rval = si4713_tx_rds_ps(sdev, (i / (RDS_BLOCK / 2)), 808 rval = si4713_tx_rds_ps(sdev, (i / (RDS_BLOCK / 2)),
829 ps_name + i); 809 ps_name + i);
830 if (rval < 0) 810 if (rval < 0)
831 goto unlock; 811 return rval;
832 } 812 }
833 813
834 /* Setup the size to be sent */ 814 /* Setup the size to be sent */
@@ -841,19 +821,16 @@ static int si4713_set_rds_ps_name(struct si4713_device *sdev, char *ps_name)
841 SI4713_TX_RDS_PS_MESSAGE_COUNT, 821 SI4713_TX_RDS_PS_MESSAGE_COUNT,
842 rds_ps_nblocks(len)); 822 rds_ps_nblocks(len));
843 if (rval < 0) 823 if (rval < 0)
844 goto unlock; 824 return rval;
845 825
846 rval = si4713_write_property(sdev, 826 rval = si4713_write_property(sdev,
847 SI4713_TX_RDS_PS_REPEAT_COUNT, 827 SI4713_TX_RDS_PS_REPEAT_COUNT,
848 DEFAULT_RDS_PS_REPEAT_COUNT * 2); 828 DEFAULT_RDS_PS_REPEAT_COUNT * 2);
849 if (rval < 0) 829 if (rval < 0)
850 goto unlock; 830 return rval;
851 } 831 }
852 832
853 strncpy(sdev->rds_info.ps_name, ps_name, MAX_RDS_PS_NAME); 833 strncpy(sdev->rds_info.ps_name, ps_name, MAX_RDS_PS_NAME);
854
855unlock:
856 mutex_unlock(&sdev->mutex);
857 return rval; 834 return rval;
858} 835}
859 836
@@ -864,14 +841,12 @@ static int si4713_set_rds_radio_text(struct si4713_device *sdev, char *rt)
864 u8 b_index = 0, cr_inserted = 0; 841 u8 b_index = 0, cr_inserted = 0;
865 s8 left; 842 s8 left;
866 843
867 mutex_lock(&sdev->mutex);
868
869 if (!sdev->power_state) 844 if (!sdev->power_state)
870 goto copy; 845 goto copy;
871 846
872 rval = si4713_tx_rds_buff(sdev, RDS_BLOCK_CLEAR, 0, 0, 0, &left); 847 rval = si4713_tx_rds_buff(sdev, RDS_BLOCK_CLEAR, 0, 0, 0, &left);
873 if (rval < 0) 848 if (rval < 0)
874 goto unlock; 849 return rval;
875 850
876 if (!strlen(rt)) 851 if (!strlen(rt))
877 goto copy; 852 goto copy;
@@ -898,7 +873,7 @@ static int si4713_set_rds_radio_text(struct si4713_device *sdev, char *rt)
898 compose_u16(rt[t_index + 2], rt[t_index + 3]), 873 compose_u16(rt[t_index + 2], rt[t_index + 3]),
899 &left); 874 &left);
900 if (rval < 0) 875 if (rval < 0)
901 goto unlock; 876 return rval;
902 877
903 t_index += RDS_RADIOTEXT_BLK_SIZE; 878 t_index += RDS_RADIOTEXT_BLK_SIZE;
904 879
@@ -908,9 +883,6 @@ static int si4713_set_rds_radio_text(struct si4713_device *sdev, char *rt)
908 883
909copy: 884copy:
910 strncpy(sdev->rds_info.radio_text, rt, MAX_RDS_RADIO_TEXT); 885 strncpy(sdev->rds_info.radio_text, rt, MAX_RDS_RADIO_TEXT);
911
912unlock:
913 mutex_unlock(&sdev->mutex);
914 return rval; 886 return rval;
915} 887}
916 888
@@ -1114,9 +1086,7 @@ static int si4713_write_econtrol_tune(struct si4713_device *sdev,
1114 1086
1115 rval = validate_range(&sdev->sd, control); 1087 rval = validate_range(&sdev->sd, control);
1116 if (rval < 0) 1088 if (rval < 0)
1117 goto exit; 1089 return rval;
1118
1119 mutex_lock(&sdev->mutex);
1120 1090
1121 switch (control->id) { 1091 switch (control->id) {
1122 case V4L2_CID_TUNE_POWER_LEVEL: 1092 case V4L2_CID_TUNE_POWER_LEVEL:
@@ -1128,8 +1098,7 @@ static int si4713_write_econtrol_tune(struct si4713_device *sdev,
1128 antcap = control->value; 1098 antcap = control->value;
1129 break; 1099 break;
1130 default: 1100 default:
1131 rval = -EINVAL; 1101 return -EINVAL;
1132 goto unlock;
1133 } 1102 }
1134 1103
1135 if (sdev->power_state) 1104 if (sdev->power_state)
@@ -1140,9 +1109,6 @@ static int si4713_write_econtrol_tune(struct si4713_device *sdev,
1140 sdev->antenna_capacitor = antcap; 1109 sdev->antenna_capacitor = antcap;
1141 } 1110 }
1142 1111
1143unlock:
1144 mutex_unlock(&sdev->mutex);
1145exit:
1146 return rval; 1112 return rval;
1147} 1113}
1148 1114
@@ -1159,12 +1125,12 @@ static int si4713_write_econtrol_integers(struct si4713_device *sdev,
1159 1125
1160 rval = validate_range(&sdev->sd, control); 1126 rval = validate_range(&sdev->sd, control);
1161 if (rval < 0) 1127 if (rval < 0)
1162 goto exit; 1128 return rval;
1163 1129
1164 rval = si4713_choose_econtrol_action(sdev, control->id, &shadow, &bit, 1130 rval = si4713_choose_econtrol_action(sdev, control->id, &shadow, &bit,
1165 &mask, &property, &mul, &table, &size); 1131 &mask, &property, &mul, &table, &size);
1166 if (rval < 0) 1132 if (rval < 0)
1167 goto exit; 1133 return rval;
1168 1134
1169 val = control->value; 1135 val = control->value;
1170 if (mul) { 1136 if (mul) {
@@ -1172,24 +1138,22 @@ static int si4713_write_econtrol_integers(struct si4713_device *sdev,
1172 } else if (table) { 1138 } else if (table) {
1173 rval = usecs_to_dev(control->value, table, size); 1139 rval = usecs_to_dev(control->value, table, size);
1174 if (rval < 0) 1140 if (rval < 0)
1175 goto exit; 1141 return rval;
1176 val = rval; 1142 val = rval;
1177 rval = 0; 1143 rval = 0;
1178 } 1144 }
1179 1145
1180 mutex_lock(&sdev->mutex);
1181
1182 if (sdev->power_state) { 1146 if (sdev->power_state) {
1183 if (mask) { 1147 if (mask) {
1184 rval = si4713_read_property(sdev, property, &val); 1148 rval = si4713_read_property(sdev, property, &val);
1185 if (rval < 0) 1149 if (rval < 0)
1186 goto unlock; 1150 return rval;
1187 val = set_bits(val, control->value, bit, mask); 1151 val = set_bits(val, control->value, bit, mask);
1188 } 1152 }
1189 1153
1190 rval = si4713_write_property(sdev, property, val); 1154 rval = si4713_write_property(sdev, property, val);
1191 if (rval < 0) 1155 if (rval < 0)
1192 goto unlock; 1156 return rval;
1193 if (mask) 1157 if (mask)
1194 val = control->value; 1158 val = control->value;
1195 } 1159 }
@@ -1199,16 +1163,13 @@ static int si4713_write_econtrol_integers(struct si4713_device *sdev,
1199 } else if (table) { 1163 } else if (table) {
1200 rval = dev_to_usecs(val, table, size); 1164 rval = dev_to_usecs(val, table, size);
1201 if (rval < 0) 1165 if (rval < 0)
1202 goto unlock; 1166 return rval;
1203 *shadow = rval; 1167 *shadow = rval;
1204 rval = 0; 1168 rval = 0;
1205 } else { 1169 } else {
1206 *shadow = val; 1170 *shadow = val;
1207 } 1171 }
1208 1172
1209unlock:
1210 mutex_unlock(&sdev->mutex);
1211exit:
1212 return rval; 1173 return rval;
1213} 1174}
1214 1175
@@ -1231,9 +1192,7 @@ static int si4713_setup(struct si4713_device *sdev)
1231 return -ENOMEM; 1192 return -ENOMEM;
1232 1193
1233 /* Get a local copy to avoid race */ 1194 /* Get a local copy to avoid race */
1234 mutex_lock(&sdev->mutex);
1235 memcpy(tmp, sdev, sizeof(*sdev)); 1195 memcpy(tmp, sdev, sizeof(*sdev));
1236 mutex_unlock(&sdev->mutex);
1237 1196
1238 ctrl.id = V4L2_CID_RDS_TX_PI; 1197 ctrl.id = V4L2_CID_RDS_TX_PI;
1239 ctrl.value = tmp->rds_info.pi; 1198 ctrl.value = tmp->rds_info.pi;
@@ -1338,17 +1297,15 @@ static int si4713_initialize(struct si4713_device *sdev)
1338 1297
1339 rval = si4713_set_power_state(sdev, POWER_ON); 1298 rval = si4713_set_power_state(sdev, POWER_ON);
1340 if (rval < 0) 1299 if (rval < 0)
1341 goto exit; 1300 return rval;
1342 1301
1343 rval = si4713_checkrev(sdev); 1302 rval = si4713_checkrev(sdev);
1344 if (rval < 0) 1303 if (rval < 0)
1345 goto exit; 1304 return rval;
1346 1305
1347 rval = si4713_set_power_state(sdev, POWER_OFF); 1306 rval = si4713_set_power_state(sdev, POWER_OFF);
1348 if (rval < 0) 1307 if (rval < 0)
1349 goto exit; 1308 return rval;
1350
1351 mutex_lock(&sdev->mutex);
1352 1309
1353 sdev->rds_info.pi = DEFAULT_RDS_PI; 1310 sdev->rds_info.pi = DEFAULT_RDS_PI;
1354 sdev->rds_info.pty = DEFAULT_RDS_PTY; 1311 sdev->rds_info.pty = DEFAULT_RDS_PTY;
@@ -1380,9 +1337,6 @@ static int si4713_initialize(struct si4713_device *sdev)
1380 sdev->stereo = 1; 1337 sdev->stereo = 1;
1381 sdev->tune_rnl = DEFAULT_TUNE_RNL; 1338 sdev->tune_rnl = DEFAULT_TUNE_RNL;
1382 1339
1383 mutex_unlock(&sdev->mutex);
1384
1385exit:
1386 return rval; 1340 return rval;
1387} 1341}
1388 1342
@@ -1428,7 +1382,7 @@ exit:
1428 1382
1429/* 1383/*
1430 * si4713_update_tune_status - update properties from tx_tune_status 1384 * si4713_update_tune_status - update properties from tx_tune_status
1431 * command. Must be called with sdev->mutex held. 1385 * command.
1432 * @sdev: si4713_device structure for the device we are communicating 1386 * @sdev: si4713_device structure for the device we are communicating
1433 */ 1387 */
1434static int si4713_update_tune_status(struct si4713_device *sdev) 1388static int si4713_update_tune_status(struct si4713_device *sdev)
@@ -1456,12 +1410,10 @@ static int si4713_read_econtrol_tune(struct si4713_device *sdev,
1456{ 1410{
1457 s32 rval = 0; 1411 s32 rval = 0;
1458 1412
1459 mutex_lock(&sdev->mutex);
1460
1461 if (sdev->power_state) { 1413 if (sdev->power_state) {
1462 rval = si4713_update_tune_status(sdev); 1414 rval = si4713_update_tune_status(sdev);
1463 if (rval < 0) 1415 if (rval < 0)
1464 goto unlock; 1416 return rval;
1465 } 1417 }
1466 1418
1467 switch (control->id) { 1419 switch (control->id) {
@@ -1472,11 +1424,9 @@ static int si4713_read_econtrol_tune(struct si4713_device *sdev,
1472 control->value = sdev->antenna_capacitor; 1424 control->value = sdev->antenna_capacitor;
1473 break; 1425 break;
1474 default: 1426 default:
1475 rval = -EINVAL; 1427 return -EINVAL;
1476 } 1428 }
1477 1429
1478unlock:
1479 mutex_unlock(&sdev->mutex);
1480 return rval; 1430 return rval;
1481} 1431}
1482 1432
@@ -1494,14 +1444,12 @@ static int si4713_read_econtrol_integers(struct si4713_device *sdev,
1494 rval = si4713_choose_econtrol_action(sdev, control->id, &shadow, &bit, 1444 rval = si4713_choose_econtrol_action(sdev, control->id, &shadow, &bit,
1495 &mask, &property, &mul, &table, &size); 1445 &mask, &property, &mul, &table, &size);
1496 if (rval < 0) 1446 if (rval < 0)
1497 goto exit; 1447 return rval;
1498
1499 mutex_lock(&sdev->mutex);
1500 1448
1501 if (sdev->power_state) { 1449 if (sdev->power_state) {
1502 rval = si4713_read_property(sdev, property, &val); 1450 rval = si4713_read_property(sdev, property, &val);
1503 if (rval < 0) 1451 if (rval < 0)
1504 goto unlock; 1452 return rval;
1505 1453
1506 /* Keep negative values for threshold */ 1454 /* Keep negative values for threshold */
1507 if (control->id == V4L2_CID_AUDIO_COMPRESSION_THRESHOLD) 1455 if (control->id == V4L2_CID_AUDIO_COMPRESSION_THRESHOLD)
@@ -1516,9 +1464,6 @@ static int si4713_read_econtrol_integers(struct si4713_device *sdev,
1516 1464
1517 control->value = *shadow; 1465 control->value = *shadow;
1518 1466
1519unlock:
1520 mutex_unlock(&sdev->mutex);
1521exit:
1522 return rval; 1467 return rval;
1523} 1468}
1524 1469
@@ -1712,14 +1657,12 @@ static int si4713_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1712 if (!sdev) 1657 if (!sdev)
1713 return -ENODEV; 1658 return -ENODEV;
1714 1659
1715 mutex_lock(&sdev->mutex);
1716
1717 if (sdev->power_state) { 1660 if (sdev->power_state) {
1718 rval = si4713_read_property(sdev, SI4713_TX_LINE_INPUT_MUTE, 1661 rval = si4713_read_property(sdev, SI4713_TX_LINE_INPUT_MUTE,
1719 &sdev->mute); 1662 &sdev->mute);
1720 1663
1721 if (rval < 0) 1664 if (rval < 0)
1722 goto unlock; 1665 return rval;
1723 } 1666 }
1724 1667
1725 switch (ctrl->id) { 1668 switch (ctrl->id) {
@@ -1728,8 +1671,6 @@ static int si4713_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1728 break; 1671 break;
1729 } 1672 }
1730 1673
1731unlock:
1732 mutex_unlock(&sdev->mutex);
1733 return rval; 1674 return rval;
1734} 1675}
1735 1676
@@ -1779,7 +1720,6 @@ static long si4713_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
1779 if (!arg) 1720 if (!arg)
1780 return -EINVAL; 1721 return -EINVAL;
1781 1722
1782 mutex_lock(&sdev->mutex);
1783 switch (cmd) { 1723 switch (cmd) {
1784 case SI4713_IOC_MEASURE_RNL: 1724 case SI4713_IOC_MEASURE_RNL:
1785 frequency = v4l2_to_si4713(rnl->frequency); 1725 frequency = v4l2_to_si4713(rnl->frequency);
@@ -1788,11 +1728,11 @@ static long si4713_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
1788 /* Set desired measurement frequency */ 1728 /* Set desired measurement frequency */
1789 rval = si4713_tx_tune_measure(sdev, frequency, 0); 1729 rval = si4713_tx_tune_measure(sdev, frequency, 0);
1790 if (rval < 0) 1730 if (rval < 0)
1791 goto unlock; 1731 return rval;
1792 /* get results from tune status */ 1732 /* get results from tune status */
1793 rval = si4713_update_tune_status(sdev); 1733 rval = si4713_update_tune_status(sdev);
1794 if (rval < 0) 1734 if (rval < 0)
1795 goto unlock; 1735 return rval;
1796 } 1736 }
1797 rnl->rnl = sdev->tune_rnl; 1737 rnl->rnl = sdev->tune_rnl;
1798 break; 1738 break;
@@ -1802,8 +1742,6 @@ static long si4713_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
1802 rval = -ENOIOCTLCMD; 1742 rval = -ENOIOCTLCMD;
1803 } 1743 }
1804 1744
1805unlock:
1806 mutex_unlock(&sdev->mutex);
1807 return rval; 1745 return rval;
1808} 1746}
1809 1747
@@ -1822,15 +1760,11 @@ static int si4713_g_modulator(struct v4l2_subdev *sd, struct v4l2_modulator *vm)
1822 struct si4713_device *sdev = to_si4713_device(sd); 1760 struct si4713_device *sdev = to_si4713_device(sd);
1823 int rval = 0; 1761 int rval = 0;
1824 1762
1825 if (!sdev) { 1763 if (!sdev)
1826 rval = -ENODEV; 1764 return -ENODEV;
1827 goto exit;
1828 }
1829 1765
1830 if (vm->index > 0) { 1766 if (vm->index > 0)
1831 rval = -EINVAL; 1767 return -EINVAL;
1832 goto exit;
1833 }
1834 1768
1835 strncpy(vm->name, "FM Modulator", 32); 1769 strncpy(vm->name, "FM Modulator", 32);
1836 vm->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LOW | 1770 vm->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LOW |
@@ -1840,15 +1774,13 @@ static int si4713_g_modulator(struct v4l2_subdev *sd, struct v4l2_modulator *vm)
1840 vm->rangelow = si4713_to_v4l2(FREQ_RANGE_LOW); 1774 vm->rangelow = si4713_to_v4l2(FREQ_RANGE_LOW);
1841 vm->rangehigh = si4713_to_v4l2(FREQ_RANGE_HIGH); 1775 vm->rangehigh = si4713_to_v4l2(FREQ_RANGE_HIGH);
1842 1776
1843 mutex_lock(&sdev->mutex);
1844
1845 if (sdev->power_state) { 1777 if (sdev->power_state) {
1846 u32 comp_en = 0; 1778 u32 comp_en = 0;
1847 1779
1848 rval = si4713_read_property(sdev, SI4713_TX_COMPONENT_ENABLE, 1780 rval = si4713_read_property(sdev, SI4713_TX_COMPONENT_ENABLE,
1849 &comp_en); 1781 &comp_en);
1850 if (rval < 0) 1782 if (rval < 0)
1851 goto unlock; 1783 return rval;
1852 1784
1853 sdev->stereo = get_status_bit(comp_en, 1, 1 << 1); 1785 sdev->stereo = get_status_bit(comp_en, 1, 1 << 1);
1854 sdev->rds_info.enabled = get_status_bit(comp_en, 2, 1 << 2); 1786 sdev->rds_info.enabled = get_status_bit(comp_en, 2, 1 << 2);
@@ -1866,9 +1798,6 @@ static int si4713_g_modulator(struct v4l2_subdev *sd, struct v4l2_modulator *vm)
1866 else 1798 else
1867 vm->txsubchans &= ~V4L2_TUNER_SUB_RDS; 1799 vm->txsubchans &= ~V4L2_TUNER_SUB_RDS;
1868 1800
1869unlock:
1870 mutex_unlock(&sdev->mutex);
1871exit:
1872 return rval; 1801 return rval;
1873} 1802}
1874 1803
@@ -1896,13 +1825,11 @@ static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulato
1896 1825
1897 rds = !!(vm->txsubchans & V4L2_TUNER_SUB_RDS); 1826 rds = !!(vm->txsubchans & V4L2_TUNER_SUB_RDS);
1898 1827
1899 mutex_lock(&sdev->mutex);
1900
1901 if (sdev->power_state) { 1828 if (sdev->power_state) {
1902 rval = si4713_read_property(sdev, 1829 rval = si4713_read_property(sdev,
1903 SI4713_TX_COMPONENT_ENABLE, &p); 1830 SI4713_TX_COMPONENT_ENABLE, &p);
1904 if (rval < 0) 1831 if (rval < 0)
1905 goto unlock; 1832 return rval;
1906 1833
1907 p = set_bits(p, stereo, 1, 1 << 1); 1834 p = set_bits(p, stereo, 1, 1 << 1);
1908 p = set_bits(p, rds, 2, 1 << 2); 1835 p = set_bits(p, rds, 2, 1 << 2);
@@ -1910,14 +1837,12 @@ static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulato
1910 rval = si4713_write_property(sdev, 1837 rval = si4713_write_property(sdev,
1911 SI4713_TX_COMPONENT_ENABLE, p); 1838 SI4713_TX_COMPONENT_ENABLE, p);
1912 if (rval < 0) 1839 if (rval < 0)
1913 goto unlock; 1840 return rval;
1914 } 1841 }
1915 1842
1916 sdev->stereo = stereo; 1843 sdev->stereo = stereo;
1917 sdev->rds_info.enabled = rds; 1844 sdev->rds_info.enabled = rds;
1918 1845
1919unlock:
1920 mutex_unlock(&sdev->mutex);
1921 return rval; 1846 return rval;
1922} 1847}
1923 1848
@@ -1929,23 +1854,19 @@ static int si4713_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
1929 1854
1930 f->type = V4L2_TUNER_RADIO; 1855 f->type = V4L2_TUNER_RADIO;
1931 1856
1932 mutex_lock(&sdev->mutex);
1933
1934 if (sdev->power_state) { 1857 if (sdev->power_state) {
1935 u16 freq; 1858 u16 freq;
1936 u8 p, a, n; 1859 u8 p, a, n;
1937 1860
1938 rval = si4713_tx_tune_status(sdev, 0x00, &freq, &p, &a, &n); 1861 rval = si4713_tx_tune_status(sdev, 0x00, &freq, &p, &a, &n);
1939 if (rval < 0) 1862 if (rval < 0)
1940 goto unlock; 1863 return rval;
1941 1864
1942 sdev->frequency = freq; 1865 sdev->frequency = freq;
1943 } 1866 }
1944 1867
1945 f->frequency = si4713_to_v4l2(sdev->frequency); 1868 f->frequency = si4713_to_v4l2(sdev->frequency);
1946 1869
1947unlock:
1948 mutex_unlock(&sdev->mutex);
1949 return rval; 1870 return rval;
1950} 1871}
1951 1872
@@ -1960,19 +1881,15 @@ static int si4713_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequenc
1960 if (frequency < FREQ_RANGE_LOW || frequency > FREQ_RANGE_HIGH) 1881 if (frequency < FREQ_RANGE_LOW || frequency > FREQ_RANGE_HIGH)
1961 return -EDOM; 1882 return -EDOM;
1962 1883
1963 mutex_lock(&sdev->mutex);
1964
1965 if (sdev->power_state) { 1884 if (sdev->power_state) {
1966 rval = si4713_tx_tune_freq(sdev, frequency); 1885 rval = si4713_tx_tune_freq(sdev, frequency);
1967 if (rval < 0) 1886 if (rval < 0)
1968 goto unlock; 1887 return rval;
1969 frequency = rval; 1888 frequency = rval;
1970 rval = 0; 1889 rval = 0;
1971 } 1890 }
1972 sdev->frequency = frequency; 1891 sdev->frequency = frequency;
1973 1892
1974unlock:
1975 mutex_unlock(&sdev->mutex);
1976 return rval; 1893 return rval;
1977} 1894}
1978 1895
@@ -2030,7 +1947,6 @@ static int si4713_probe(struct i2c_client *client,
2030 1947
2031 v4l2_i2c_subdev_init(&sdev->sd, client, &si4713_subdev_ops); 1948 v4l2_i2c_subdev_init(&sdev->sd, client, &si4713_subdev_ops);
2032 1949
2033 mutex_init(&sdev->mutex);
2034 init_completion(&sdev->work); 1950 init_completion(&sdev->work);
2035 1951
2036 if (client->irq) { 1952 if (client->irq) {
diff --git a/drivers/media/radio/si4713-i2c.h b/drivers/media/radio/si4713-i2c.h
index c6dfa7fb101c..979828da9d27 100644
--- a/drivers/media/radio/si4713-i2c.h
+++ b/drivers/media/radio/si4713-i2c.h
@@ -220,7 +220,6 @@ struct si4713_device {
220 /* v4l2_subdev and i2c reference (v4l2_subdev priv data) */ 220 /* v4l2_subdev and i2c reference (v4l2_subdev priv data) */
221 struct v4l2_subdev sd; 221 struct v4l2_subdev sd;
222 /* private data structures */ 222 /* private data structures */
223 struct mutex mutex;
224 struct completion work; 223 struct completion work;
225 struct rds_info rds_info; 224 struct rds_info rds_info;
226 struct limiter_info limiter_info; 225 struct limiter_info limiter_info;