summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/imx233/sdmmc-imx233.c
AgeCommit message (Collapse)AuthorFilesLines
2017-10-26Unify storage threads into oneMichael Sevakis1-109/+81
* Editing a bunch of drivers' thread routines in order to implement a new feature is tedious. * No matter the number of storage drivers, they share one thread. No extra threads needed for CONFIG_STORAGE_MULTI. * Each has an event callback called by the storage thread. * A default callback is provided to fake sleeping in order to trigger idle callbacks. It could also do other default processing. Changes to it will be part of driver code without editing each one. * Drivers may sleep and wake as they please as long as they give a low pulse on their storage bit to ask to go into sleep mode. Idle callback is called on its behalf and driver immediately put into sleep mode. * Drivers may indicate they are to continue receiving events in USB mode, otherwise they receve nothing until disconnect (they do receive SYS_USB_DISCONNECTED no matter what). * Rework a few things to keep the callback implementation sane and maintainable. ata.c was dreadful with all those bools; make it a state machine and easier to follow. Remove last_user_activity; it has no purpose that isn't served by keeping the disk active through last_disk_activity instead. * Even-out stack sizes partly because of a lack of a decent place to define them by driver or SoC or whatever; it doesn't seem too critical to do that anyway. Many are simply too large while at least one isn't really adequate. They may be individually overridden if necessary (figure out where). The thread uses the greatest size demanded. Newer file code is much more frugal with stack space. I barely see use crack 50% after idle callbacks (usually mid-40s). Card insert/eject doesn't demand much. * No forcing of idle callbacks. If it isn't necessary for one or more non-disk storage types, it really isn't any more necessary for disk storage. Besides, it makes the whole thing easier to implement. Change-Id: Id30c284d82a8af66e47f2cfe104c52cbd8aa7215
2017-03-12Do some housekeeping with fat.h and SECTOR_SIZEMichael Sevakis1-1/+0
Many includes of fat.h are pointless. Some includes are just for SECTOR_SIZE. Add a file 'firmware/include/fs_defines.h' for that and to define tuneable values that were scattered amongst various headers. Remove some local definitions of SECTOR_SIZE since they have to be in agreement with the rest of the fs code anyway. (We'll see what's in fact pointless in a moment ;) Change-Id: I9ba183bf58bd87f5c45eba7bd675c7e2c1c18ed5
2016-05-29imx233: two minor fixes for sd/mmcAmaury Pouly1-2/+5
Always enable support for SET_BLOCK_COUNT on mmc: it is mandatory. For some reason (probably a mistake) it was disabled unconditionaly on mmc. Also deselect sd card after init. Although it is unlikely to make a difference, it is already done for mmc so stay consistent. Change-Id: I276f0d95f5bb6a0bf431c2fff4589d3dfb15f8c7
2016-05-29imx233: add sd/mmc debug screenAmaury Pouly1-6/+65
The screen currently displays for each device the bus width, set_block_count support, HS capability and whether it is enabled for not. Change-Id: I6b1c3b1019e55ef1097a23c1f54fb07f5c7aa3b0
2016-05-28imx233: generate register headers using headergen_v2 and update code for itAmaury Pouly1-0/+2
NOTE: this commit does not introduce any change, ideally even the binary should be almost the same. I checked the disassembly by hand and there are only a few differences here and there, mostly the compiler decides to compile very close expressions slightly differently. I tried to run the new code on several targets to make sure and saw no difference. The major syntax changes of the new headers are as follows: - BF_{WR,SET,CLR} are now superpowerful and allows to set several fileds at once: BF_WR(reg, field1(value1), field2(value2), ...) - BF_CS (use like BF_WR) does a write to reg_CLR and then reg_SET instead of RMW - there is no more need for macros like BF_{WR_,SET,CLR}_V, since one can simply BF_WR with field_V(name) - the old BF_SETV macro has no trivial equivalent and is replaced with its its equivalent for BF_WR(reg_SET, ...) I also rename the register headers: "regs/regs-x.h" -> "regs/x.h" to avoid the redundant "regs". Final note: the registers were generated using the following command: ./headergen_v2 -g imx -o ../../firmware/target/arm/imx233/regs/ desc/regs-stmp3{600,700,780}.xml Change-Id: I7485e8b4315a0929a8edb63e7fa1edcaa54b1edc
2014-11-10zen: typoAmaury Pouly1-1/+1
Change-Id: I68be3c768c092d7e43df8fa233f3a954e56f4d93
2014-08-30Rewrite filesystem code (WIP)Michael Sevakis1-25/+20
This patch redoes the filesystem code from the FAT driver up to the clipboard code in onplay.c. Not every aspect of this is finished therefore it is still "WIP". I don't wish to do too much at once (haha!). What is left to do is get dircache back in the sim and find an implementation for the dircache indicies in the tagcache and playlist code or do something else that has the same benefit. Leaving these out for now does not make anything unusable. All the basics are done. Phone app code should probably get vetted (and app path handling just plain rewritten as environment expansions); the SDL app and Android run well. Main things addressed: 1) Thread safety: There is none right now in the trunk code. Most of what currently works is luck when multiple threads are involved or multiple descriptors to the same file are open. 2) POSIX compliance: Many of the functions behave nothing like their counterparts on a host system. This leads to inconsistent code or very different behavior from native to hosted. One huge offender was rename(). Going point by point would fill a book. 3) Actual running RAM usage: Many targets will use less RAM and less stack space (some more RAM because I upped the number of cache buffers for large memory). There's very little memory lying fallow in rarely-used areas (see 'Key core changes' below). Also, all targets may open the same number of directory streams whereas before those with less than 8MB RAM were limited to 8, not 12 implying those targets will save slightly less. 4) Performance: The test_disk plugin shows markedly improved performance, particularly in the area of (uncached) directory scanning, due partly to more optimal directory reading and to a better sector cache algorithm. Uncached times tend to be better while there is a bit of a slowdown in dircache due to it being a bit heavier of an implementation. It's not noticeable by a human as far as I can say. Key core changes: 1) Files and directories share core code and data structures. 2) The filesystem code knows which descriptors refer to same file. This ensures that changes from one stream are appropriately reflected in every open descriptor for that file (fileobj_mgr.c). 3) File and directory cache buffers are borrowed from the main sector cache. This means that when they are not in use by a file, they are not wasted, but used for the cache. Most of the time, only a few of them are needed. It also means that adding more file and directory handles is less expensive. All one must do in ensure a large enough cache to borrow from. 4) Relative path components are supported and the namespace is unified. It does not support full relative paths to an implied current directory; what is does support is use of "." and "..". Adding the former would not be very difficult. The namespace is unified in the sense that volumes may be specified several times along with relative parts, e.g.: "/<0>/foo/../../<1>/bar" :<=> "/<1>/bar". 5) Stack usage is down due to sharing of data, static allocation and less duplication of strings on the stack. This requires more serialization than I would like but since the number of threads is limited to a low number, the tradoff in favor of the stack seems reasonable. 6) Separates and heirarchicalizes (sic) the SIM and APP filesystem code. SIM path and volume handling is just like the target. Some aspects of the APP file code get more straightforward (e.g. no path hashing is needed). Dircache: Deserves its own section. Dircache is new but pays homage to the old. The old one was not compatible and so it, since it got redone, does all the stuff it always should have done such as: 1) It may be update and used at any time during the build process. No longer has one to wait for it to finish building to do basic file management (create, remove, rename, etc.). 2) It does not need to be either fully scanned or completely disabled; it can be incomplete (i.e. overfilled, missing paths), still be of benefit and be correct. 3) Handles mounting and dismounting of individual volumes which means a full rebuild is not needed just because you pop a new SD card in the slot. Now, because it reuses its freed entry data, may rebuild only that volume. 4) Much more fundamental to the file code. When it is built, it is the keeper of the master file list whether enabled or not ("disabled" is just a state of the cache). Its must always to ready to be started and bind all streams opened prior to being enabled. 5) Maintains any short filenames in OEM format which means that it does not need to be rebuilt when changing the default codepage. Miscellaneous Compatibility: 1) Update any other code that would otherwise not work such as the hotswap mounting code in various card drivers. 2) File management: Clipboard needed updating because of the behavioral changes. Still needs a little more work on some finer points. 3) Remove now-obsolete functionality such as the mutex's "no preempt" flag (which was only for the prior FAT driver). 4) struct dirinfo uses time_t rather than raw FAT directory entry time fields. I plan to follow up on genericizing everything there (i.e. no FAT attributes). 5) unicode.c needed some redoing so that the file code does not try try to load codepages during a scan, which is actually a problem with the current code. The default codepage, if any is required, is now kept in RAM separarately (bufalloced) from codepages specified to iso_decode() (which must not be bufalloced because the conversion may be done by playback threads). Brings with it some additional reusable core code: 1) Revised file functions: Reusable code that does things such as safe path concatenation and parsing without buffer limitations or data duplication. Variants that copy or alter the input path may be based off these. To do: 1) Put dircache functionality back in the sim. Treating it internally as a different kind of file system seems the best approach at this time. 2) Restore use of dircache indexes in the playlist and database or something effectively the same. Since the cache doesn't have to be complete in order to be used, not getting a hit on the cache doesn't unambiguously say if the path exists or not. Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8 Reviewed-on: http://gerrit.rockbox.org/566 Reviewed-by: Michael Sevakis <jethead71@rockbox.org> Tested: Michael Sevakis <jethead71@rockbox.org>
2014-04-24imx233: fix commentsAmaury Pouly1-8/+8
Change-Id: I2e907feaec39e6ec1614ed19676b13a1d4f7f6b2
2014-04-23imx233: fix typos and sdmmc bug regarding write bufferAmaury Pouly1-2/+6
The write buffer should not be modified but the current code does and then forget to restore it to its original content. I'm not sure if any code relies to the write buffer to not be modifies by the write function but this seems like a reasonable assumption in general so it's better not to break it. Change-Id: I449a01db2ec51d2273e59b69c59db0e7d2eed3db
2014-04-23imx233: fix sdmmc driver bug when sector count is 0Amaury Pouly1-0/+3
Since the driver will read count-1 sectors, this will stuck the card. Change-Id: Ib80484044acd1fad2914d3ffeb3940a13d2480c4
2014-02-11imx233: cleanup in sdmmcAmaury Pouly1-11/+9
Change-Id: I82eac65b1bf9f2e963c4ebfb7c22da678ae63642
2014-02-10imx233: add support for sd/mmc probingAmaury Pouly1-1/+25
zenxfi2: add support for internal storage on the SD version The code can now skip devices marked as PROBE if they fail to init, thus making it possible to handle various kinds of internal storages. The current code probably doesn't interplay nicely since it acquires pins and never release them so it will probably break NAND code when it's ready but NAND code is not ready yet anyway. Change-Id: I4cb962de4215661e521743a3f511445dbbf28673
2014-01-21Initial commit for the ZEN X-Fi StyleAmaury Pouly1-0/+7
Change-Id: Ib25a357a7bafd2ef25f273cadff70fafbd8d4661
2013-12-06imx233: fix storage code to work for non-MD buildsAmaury Pouly1-8/+8
Change-Id: Ic326e59385aff3be1ada52b482e94051c512323d
2013-11-30Revert "imx233: always keep cards in TRAN mode"Amaury Pouly1-0/+21
This reverts commit 462adf2a0fefbfdbccfafa11c999ac6beb114e8a. Leaving the card in TRAN results in a huge power consumption because some cards and internal bridges do not automatically enter power saving mode in TRAN state. Change-Id: If79efe8cf99b24174889b3a5ebbcb51b07085f58
2013-11-20imx233/sdmmc: {sd,mmc}_{present,removable} don't depend on multivolumeAmaury Pouly1-16/+4
Change-Id: Id35fbdbc62b804e9a67c6d1f18b19a1d2051bb78
2013-10-22imx233: fix partition window computationAmaury Pouly1-2/+8
The code was broken in two ways: - it called storage_read_sectors with a wrong drive number - calling storage_read_sectors too early at boot time will fail because we are in the init function, so the drive is not yet registered. To fix this, use a user provided read callback instead of storage read functions. Change-Id: I5ab79d48391fae619d5f8ae09c3d499fc43854c8
2013-10-22Initial commit for the Creative ZEN and ZEN X-FiAmaury Pouly1-0/+17
Change-Id: Ibd7b1b0b957ef11c200cb63eff7da53f11774748
2013-10-22Initial commit for the Creative ZEN MozaicAmaury Pouly1-0/+7
Change-Id: Ib65aad9f5de37e514047955cad7ca40dc0af4f74
2013-10-22imx233/sdmmc: add write protect pin configAmaury Pouly1-0/+3
The setting is currently unused but it provides some documentation and basic support for a more comprehensive implementation of read-only support. Change-Id: I353c33ef765ef6e6c09d59e943da6654a311ad84
2013-10-22imx233: extend partition window support to be more genericAmaury Pouly1-6/+4
The new code can select among several types of window (user, system, ...). Furthermore, the type of partitions to use is selectable in config file. Currently, two types are support: Freescale style MBR and Creative MBLK Change-Id: I969d60a3d08f2c9448fb4b9c440051b7801b94cd
2013-10-21imx233: simplify sd/mmc codeAmaury Pouly1-7/+7
Change-Id: I7e36b4c1c91540a2ae383109e440818bc610dde6
2013-09-25Initial commit for the sony NWZ-E360 and NWZ-E370Amaury Pouly1-0/+9
Change-Id: I52d21e136a98eaf481615d641795cf7ecf325465
2013-09-07imx233: implement mmc card infoAmaury Pouly1-0/+5
This one is a bit strange: our codebase just don't use it if there is both SD and MMC, so this missing function got unnoticed so far. Change-Id: Ifea4bb5140477b7637d033737594259cc44fb10e
2013-09-06imx233: fix horrible sd/mmc bugAmaury Pouly1-2/+3
The wrong variable was used to enumerate mmc drives. Also fix incorrect function prototype. Change-Id: Idd8dca7685bbc2bc4744b7b29e948f0ca2f56cc9
2013-09-06cosmeticsAmaury Pouly1-2/+2
Change-Id: Ia2b334ad9dd3f465ad5024e6fc226cb3e60a6e45
2013-08-22imx233: revert sd card high speed (unstable)Amaury Pouly1-1/+1
Change-Id: I3d6a20de4ea1ca0d0150e6b4fc6af849eda0f4ab
2013-08-21imx233: add support for 50MHz clock with SD cardsAmaury Pouly1-34/+25
Now that the drive strength problem has been fixed, we can safely drive sd cards at 48MHz in HS mode to get the best possible transfer speed at 3.3V. Change-Id: I0291589c399fb4880deba97895ff578451a32f99
2013-08-21imx233: fix drive strength for sd/mmcAmaury Pouly1-7/+13
At high speed, we need a drive strength of 8mA on the clock line to get stable transfers. Change-Id: Ida668db10cd3e10ad5740e35fd973f2fa394edb2
2013-08-21imx233: always keep cards in TRAN modeAmaury Pouly1-22/+0
Instead of going back and forth between TRAN and STBY modes, stay in TRAN mode all the time, this avoid two commands on each read/write and a potential delay to wait for the card. Change-Id: Iafd456ab9a581d870331b622eeb48dcc254eda7f
2013-08-21imx233: add support for CMD23 in sd/mmcAmaury Pouly1-2/+27
This allows tells the card the number of blocks that will be transfered. This is usually faster than continuous read/write. It is mandatory for MMC and on SD cards, support is probed. Change-Id: Ide3f97c26c2b714390884c69e05b00c2caa552f8
2013-08-21imx233: rework yield management for wait state, didn't make senseAmaury Pouly1-6/+3
Change-Id: I5ecb1afb5461018c2c9675d5f4ee1c6e4ded636d
2013-08-17Cleanup MV/MD macros a little.Michael Sevakis1-5/+5
When using variadic macros there's no need for IF_MD2/IF_MV2 to deal with function parameters. IF_MD/IF_MV are enough. Throw in IF_MD_DRV/ID_MV_VOL that return the parameter if MD/MV, or 0 if not. Change-Id: I7605e6039f3be19cb47110c84dcb3c5516f2c3eb
2013-07-02imx233: fix sd init sequenceAmaury Pouly1-4/+12
Implement the switch function as specified by the specification, that is wait for the response AND transfer 64 bytes of data. This fixes some issue when the SD card take a long time to switch. In particular waiting 100ms (max per spec) will not work if no data is transfered in some cases. Change-Id: Ia22350468018b842e57ce6f6c1a8d676eba97fb8
2013-06-17imx233: various sdmmc fixesAmaury Pouly1-16/+46
Change-Id: I261d0bdea1e7c5bc9139b10bf42e7ce7ce6b6dd8
2013-06-17imx233: introduce virtual pins to simplify pin setupAmaury Pouly1-1/+1
A number of pins on the imx233 are standard and manually calling functions to acquire, set function/drive/output is painful. This will become unmanageable when we will add support for the other stmp chips. Introduce the concept of virtual pin which is a way to completely describe a virtual pin (virtual because pins are muxed). Change-Id: I01b6e040945648e58e1d1abab06529c9571c5f10
2013-06-17imx233: normalise pinctrl namesAmaury Pouly1-5/+5
The current pinctrl functions were a mess. Normalise the functions names to make them shorter and clearer. Change-Id: Iac6ff84625ef2b7610268e3a5802dc0088de3167
2013-06-16imx233: rewrite ssp using new register headersAmaury Pouly1-2/+2
Change-Id: Ibf186b610beb07bd615c976630cdca9de2c7448e
2013-06-16imx233: fix sdmmc codeAmaury Pouly1-2/+1
The SD SWITCH command has a result and can take a long time to finish. Ignoring the answer and waiting an arbitrary time is unreliable at best. Change-Id: I1bfbb193952b96598f8bb056bac88220d4edf1fc
2013-01-15imx233: fix sd windowed driveAmaury Pouly1-1/+3
The SD driver doesn't initialised drives at the beginning but upon request to handle removable drives. Since means that the init should call init_drive() and not init_sd_card() otherwise the check for WINDOW flag is bypasses. This breaks the zenxfi3 bootloader and has been overlooked for some time. Change-Id: I7325f7164d16d7e7e54eeb4645e98517a08e0836
2012-12-16imx233: simplify sdmmc led handling, fix typoAmaury Pouly1-10/+3
Change-Id: Iffbb05afd41bd0accfac9c127ea3a26fd33f1387
2012-10-10imx233/fuze+: add status led(icon) support to sd/mmc storage layerAmaury Pouly1-0/+13
Change-Id: I9c0e1ecd04d1935825606e906e6a434a3afb2175
2012-08-30imx233: fix compilation of sdmmc for non-mmc targetsAmaury Pouly1-2/+8
Change-Id: I0f61d0ca8e385fbfeaba53b81c3320b24aa61ab9
2012-08-30fix yellowAmaury Pouly1-1/+3
Change-Id: I798826c8240fa9ce5a87cb0443002ca1b8882922
2012-08-30imx233: fix idle storage notification for sd/mmc driverAmaury Pouly1-15/+35
Change-Id: Ia70a0058f0e86824e2b0d74d12e369295629eb5a
2012-08-23imx233: sdmmc driver enhancementAmaury Pouly1-33/+87
Implement cache aligned transfer of more than one sectors. The current code now transfers almost all data at once by moving it within the buffer to make it cache aligned. This greatly improves the performance of the transfers, especially in mass storage mode. Change-Id: Ic6e78773302f368426209f6fd6099089ea34cb16
2012-08-21imx233: remove debug panicAmaury Pouly1-2/+0
Change-Id: I7b6bf2bcac31ff65ae17f4a833587f4a5c9e6d7a
2012-08-21imx233: simplify sd/mmc driverAmaury Pouly1-190/+178
Further merge drivers by using the same command and data functions. No use one mutex per drive instead of a global sd lock. Fix the RCA handling which was different between SD and MMC (shifted 16) and thus confusing. Add MMC commands definition to the mmc.h header similarly to the SD one. Change MMC handling a bit by selecting/deselecting on each transfer like SD, which allows for several MMC devices in theory and is more uniform. Change-Id: I7024cb19c079553806138ead75b00640f1d2d95c
2012-08-18imx233: merge sd and mmc drivers, fix dma issuesAmaury Pouly1-0/+874
Merge sd and mmc drivers into a single sdmmc driver. This allows some factoring of the code and simplify bug fixing. Also fix the dma/cache related issue by doing all transfers via a correctly aligned buffer. The current code is not smart enough to take advantage of large user buffers currently but at least it is safe! Change-Id: Ib0fd16dc7d52ef7bfe99fd586e03ecf08691edcd