[RAMEN9610-12937][COMMON] media: radio: fix FM open fail
authorYunsu Kim <iamyunsu.kim@samsung.com>
Wed, 6 Mar 2019 04:53:17 +0000 (13:53 +0900)
committerCosmin Tanislav <demonsingur@gmail.com>
Mon, 22 Apr 2024 17:23:19 +0000 (20:23 +0300)
Add polling for wlbt shared ldo stable

Change-Id: Ic3f80ca8a419238b2ad37028c1b2595855777d79
Signed-off-by: Yunsu Kim <iamyunsu.kim@samsung.com>
drivers/media/radio/s610/radio-s610.c

index 01a409f9090b00ee15acc0a89f3d05c1e0bc4224..f36f7d3ccd3e732b004c3287ce3ede841108702c 100755 (executable)
@@ -1509,38 +1509,37 @@ static int set_eLNA_gpio(struct s610_radio *radio, int stat)
 
 static int s610_radio_fops_open(struct file *file)
 {
+#ifdef CONFIG_SCSC_FM
+       int i;
+       int ret_mx250;
+       int xtal_clkdet;
+#endif /* CONFIG_SCSC_FM */
        int ret;
        struct s610_radio *radio = video_drvdata(file);
-       static bool run_once = true;
 
        FUNC_ENTRY(radio);
 
-#ifdef CONFIG_SCSC_FM
-       /* Start FM/WLBT LDO */
-       ret = mx250_fm_request();
-       if (ret < 0) {
-               dev_err(radio->v4l2dev.dev,
-                       "mx250_fm_request() failed with err %d\n", ret);
-               return ret;
-       }
-#endif /* CONFIG_SCSC_FM */
-
        shared_fm_open_cnt++;
 
-#ifdef USE_FM_LNA_ENABLE
-       if (radio->elna_gpio != -EINVAL) {
-               ret = set_eLNA_gpio(radio, GPIO_HIGH);
-               if (ret)
-                       dev_info(radio->v4l2dev.dev,
-                                       "Failed to set gpio for eLNA\n");
-       }
-#endif /* USE_FM_LNA_ENABLE */
-
        ret = v4l2_fh_open(file);
        if (ret)
                return ret;
 
        if (v4l2_fh_is_singular_file(file)) {
+#ifdef CONFIG_SCSC_FM
+               /* Start FM/WLBT LDO */
+               ret_mx250 = mx250_fm_request();
+#endif /* CONFIG_SCSC_FM */
+
+#ifdef USE_FM_LNA_ENABLE
+               if (radio->elna_gpio != -EINVAL) {
+                       ret = set_eLNA_gpio(radio, GPIO_HIGH);
+                       if (ret)
+                               dev_info(radio->v4l2dev.dev,
+                                               "Failed to set gpio for eLNA\n");
+               }
+#endif /* USE_FM_LNA_ENABLE */
+
                s610_core_lock(radio->core);
                atomic_set(&radio->is_doing, 0);
                atomic_set(&radio->is_rds_doing, 0);
@@ -1568,12 +1567,28 @@ static int s610_radio_fops_open(struct file *file)
 
                fmspeedy_wakeup();
 
-               if (run_once) {
-                       fm_ds_set(0);
-                       fm_aux_pll_off();
+#ifdef CONFIG_SCSC_FM
+               i = 0;
+               do {
+                       if (i > 10) {
+                               dev_err(radio->v4l2dev.dev, "mx250_fm_request() failed\n");
+                               ret = -1;
+                               goto err_open;
+                       }
 
-                       run_once = false;
-               }
+                       if (i > 0)
+                               ret_mx250 = mx250_fm_request();
+
+                       msleep(200);
+                       xtal_clkdet = fmspeedy_get_reg_field(0xFFF25B, 7, (0x0001 << 7));
+
+                       dev_err(radio->v4l2dev.dev,
+                               "#%d, mx250_fm_request ret : %d, xtal_clkdet : %d\n",
+                               i, ret_mx250, xtal_clkdet);
+
+                       i++;
+               } while ((xtal_clkdet != 1) || (ret_mx250 < 0));
+#endif /* CONFIG_SCSC_FM */
 
                fm_get_version_number();
 
@@ -1686,23 +1701,14 @@ static int s610_radio_fops_release(struct file *file)
                }
 #endif /* USE_AUDIO_PM */
                s610_core_unlock(radio->core);
-       }
-
-       if (wake_lock_active(&radio->wakelock))
-               wake_unlock(&radio->wakelock);
-
-       if (wake_lock_active(&radio->rdswakelock))
-               wake_unlock(&radio->rdswakelock);
-
-       ret = v4l2_fh_release(file);
 
 #ifdef USE_FM_LNA_ENABLE
-       if (radio->elna_gpio != -EINVAL) {
-               ret = set_eLNA_gpio(radio, GPIO_LOW);
-               if (ret)
-                       dev_info(radio->v4l2dev.dev,
-                                       "Failed to set gpio for eLNA\n");
-       }
+               if (radio->elna_gpio != -EINVAL) {
+                       ret = set_eLNA_gpio(radio, GPIO_LOW);
+                       if (ret)
+                               dev_info(radio->v4l2dev.dev,
+                                               "Failed to set gpio for eLNA\n");
+               }
 #endif /* USE_FM_LNA_ENABLE */
 
 #ifdef CONFIG_SCSC_FM
@@ -1712,6 +1718,15 @@ static int s610_radio_fops_release(struct file *file)
                        dev_err(radio->v4l2dev.dev,
                                "mx250_fm_release() failed with err %d\n", ret);
 #endif
+       }
+
+       if (wake_lock_active(&radio->wakelock))
+               wake_unlock(&radio->wakelock);
+
+       if (wake_lock_active(&radio->rdswakelock))
+               wake_unlock(&radio->rdswakelock);
+
+       ret = v4l2_fh_release(file);
 
        shared_fm_open_cnt--;