@@ -2256,7 +2256,6 @@ static void usdhc_host_reset(struct usdhc_priv *priv)
22562256 usdhc_enable_ddr_mode (base , false, 0 );
22572257 usdhc_tuning (base , SDHC_STANDARD_TUNING_START , SDHC_TUINIG_STEP , false);
22582258#if FSL_FEATURE_USDHC_HAS_HS400_MODE
2259- #error Not implemented!
22602259 /* Disable HS400 mode */
22612260 /* Disable DLL */
22622261#endif
@@ -2600,8 +2599,9 @@ static K_MUTEX_DEFINE(z_usdhc_init_lock);
26002599static int usdhc_board_access_init (struct usdhc_priv * priv )
26012600{
26022601 const struct usdhc_config * config = priv -> config ;
2603- int ret ;
2602+ int ret = 0 ;
26042603 uint32_t gpio_level ;
2604+ USDHC_Type * base = config -> base ;
26052605
26062606 if (config -> pwr_name ) {
26072607 priv -> pwr_gpio = device_get_binding (config -> pwr_name );
@@ -2634,35 +2634,41 @@ static int usdhc_board_access_init(struct usdhc_priv *priv)
26342634 }
26352635
26362636 if (!priv -> detect_gpio ) {
2637- LOG_INF ("USDHC detection other than GPIO not implemented!" );
2638- return 0 ;
2639- }
2637+ LOG_INF ("USDHC detection other than GPIO" );
2638+ /* DATA3 does not monitor card insertion */
2639+ base -> PROT_CTRL &= ~USDHC_PROT_CTRL_D3CD_MASK ;
2640+ if ((base -> PRES_STATE & USDHC_PRES_STATE_CINST_MASK ) != 0 ) {
2641+ priv -> inserted = true;
2642+ } else {
2643+ priv -> inserted = false;
2644+ ret = - ENODEV ;
2645+ }
2646+ } else {
2647+ ret = usdhc_cd_gpio_init (priv -> detect_gpio ,
2648+ config -> detect_pin ,
2649+ config -> detect_flags ,
2650+ & priv -> detect_cb );
2651+ if (ret ) {
2652+ return ret ;
2653+ }
2654+ ret = gpio_pin_get (priv -> detect_gpio , config -> detect_pin );
2655+ if (ret < 0 ) {
2656+ return ret ;
2657+ }
26402658
2641- ret = usdhc_cd_gpio_init (priv -> detect_gpio ,
2642- config -> detect_pin ,
2643- config -> detect_flags ,
2644- & priv -> detect_cb );
2645- if (ret ) {
2646- return ret ;
2647- }
2648- ret = gpio_pin_get (priv -> detect_gpio , config -> detect_pin );
2649- if (ret < 0 ) {
2650- return ret ;
2651- }
2659+ gpio_level = ret ;
26522660
2653- gpio_level = ret ;
2661+ if (gpio_level == 0 ) {
2662+ priv -> inserted = false;
2663+ LOG_ERR ("NO SD inserted!" );
26542664
2655- if (gpio_level == 0 ) {
2656- priv -> inserted = false;
2657- LOG_ERR ("NO SD inserted!" );
2665+ return - ENODEV ;
2666+ }
26582667
2659- return - ENODEV ;
2668+ priv -> inserted = true;
2669+ LOG_INF ("SD inserted!" );
26602670 }
2661-
2662- priv -> inserted = true;
2663- LOG_INF ("SD inserted!" );
2664-
2665- return 0 ;
2671+ return ret ;
26662672}
26672673
26682674static int usdhc_access_init (const struct device * dev )
0 commit comments