AnsweredAssumed Answered

Linux SD driver code

Question asked by RobertCraig on Aug 17, 2014
Latest reply on Aug 25, 2014 by RobertCraig

I've just spent a number of days debugging the SD card driver code and thought that maybe some others could benefit from what I found.  Out system is a bit strange in that we swap the RSI lines between two processors, but I suspect that the fixes I added to bfin_sdh.c are applicable to everyone.


1) The card detect interrupt (SD_CARD_DET in the RSI Exception Status / Mask register).  The code handling this in sdh_stat_irq doesn't set "handled = 1".  We ended up in a situation where the SD interrupt was disabled because of spurious interrupt generation because of this (this isn't likely to be a generic problem and is related to the way that we swap the RSI lines).  I added a line of code to disable the interrupt in the sdh_probe function.


2) The SD_CARD_DET interrupt is enabled by default on reset.  The HW manual specifically recommends that the SD_CARD_DET interrupt should be disabled after the card insert has been detected.  We found that with the current code, the interrupt handler gets called every few 10s of us with this as the cause when doing data transfer.  This strikes me as a bad thing...  Given that using SD_DATA3 as a card detection mechanism isn't recommended, it makes more sense to just disable this interrupt from the start (or have the enabling specifically handled by a configuration setting).


3)  I encountered a weird situation (once) in which, over the course of several days of testing and mount / reads / dismounts / reboots,   I could mount the raw partition but the subsequent mounting of the file system hung.  Strangely enough, this hang went away with the SD_CARD_DET interrupt enabled. The failure mode survived soft reboots, but not a power cycle.  I eventually found that doing a full RSI reset in sdh_reset got things working again (with the SD_CARD_DET interrupt disabled).


(I added the following lines to the start of the sdh_reset function


    bfin_write_SDH_CCF(bfin_read_SDH_CFG() | SD_RST);




  You may want to consider some of these changes for inclusion in the main line code.  If you could let me know if there's anything wrong with the changes, that would be appreciated as well.



       Robert Craig.