mmc_test.c 99 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein is
  5. * confidential and proprietary to MediaTek Inc. and/or its licensors. Without
  6. * the prior written permission of MediaTek inc. and/or its licensors, any
  7. * reproduction, modification, use or disclosure of MediaTek Software, and
  8. * information contained herein, in whole or in part, shall be strictly
  9. * prohibited.
  10. *
  11. * MediaTek Inc. (C) 2010. All rights reserved.
  12. *
  13. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  14. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  15. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
  16. * ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
  17. * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  19. * NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
  20. * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
  21. * INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES
  22. * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
  23. * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
  24. * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK
  25. * SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
  26. * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  27. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S
  28. * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE
  29. * RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE
  30. * MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
  31. * CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  32. *
  33. * The following software/firmware and/or related documentation ("MediaTek
  34. * Software") have been modified by MediaTek Inc. All revisions are subject to
  35. * any receiver's applicable license agreements with MediaTek Inc.
  36. */
  37. //#define MMC_ICE_DOWNLOAD
  38. //#define MMC_BOOT_TEST
  39. /*=======================================================================*/
  40. /* HEADER FILES */
  41. /*=======================================================================*/
  42. #include <stdio.h>
  43. #include <string.h>
  44. #include <platform/msdc.h>
  45. #include <platform/msdc_utils.h>
  46. #include <platform/mmc_core.h>
  47. #include <platform/mmc_test.h>
  48. #include <platform/partition_wp.h>
  49. #define MMC_BUF_ADDR (0x01000000)
  50. #define BLK_SIZE (512)
  51. #if defined(MMC_TEST)
  52. #define TC_MSG "[SD%d] <%s> TC%d: %s"
  53. #define MMC_TST_CHK_RESULT (1)
  54. #define MMC_TST_SBLK_RW (1)
  55. #define MMC_TST_MBLK_RW (1)
  56. #define MMC_TST_IMBLK_RW (1)
  57. #define MMC_TST_COUNTS (1)
  58. #define MMC_TST_BUF_ADDR (0x01000000)
  59. #ifdef MMC_PROFILING
  60. #define MMC_TST_SIZE (4 * 1024 * 1024) /* 4MB */
  61. #define MMC_TST_CHUNK_BLKS (128) /* 64KB */
  62. #else
  63. #define MMC_TST_SIZE (1 * 1024 * 1024) /* 1MB */
  64. #define MMC_TST_CHUNK_BLKS (128) /* 8KB */
  65. #endif
  66. #define MMC_TST_START_ADDR (128 * 1024 * 1024) /* 128MB */
  67. #define MMC_TST_START_BLK (MMC_TST_START_ADDR / MMC_BLOCK_SIZE)
  68. #define MMC_TST_BLK_NR(x) (MMC_TST_START_BLK+(x)*(MMC_TST_SIZE/MMC_BLOCK_SIZE))
  69. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  70. static unsigned int clkfreq[] = { MSDC_200M_SCLK};
  71. static unsigned int buswidth[] = { HOST_BUS_WIDTH_4};
  72. #ifdef MMC_PROFILING
  73. static struct mmc_op_perf mmc_perf[MSDC_MAX_NUM];
  74. struct mmc_op_perf *mmc_prof_handle(int id)
  75. {
  76. return &mmc_perf[id];
  77. }
  78. void mmc_prof_init(int id, struct mmc_host *host, struct mmc_card *card)
  79. {
  80. memset(&mmc_perf[id], 0, sizeof(struct mmc_op_perf));
  81. mmc_perf[id].host = host;
  82. mmc_perf[id].card = card;
  83. msdc_timer_init();
  84. msdc_timer_stop_clear();
  85. }
  86. void mmc_prof_start(void)
  87. {
  88. msdc_timer_stop_clear();
  89. msdc_timer_start();
  90. }
  91. void mmc_prof_stop(void)
  92. {
  93. msdc_timer_stop();
  94. }
  95. unsigned int mmc_prof_count(void)
  96. {
  97. return msdc_timer_get_count();
  98. }
  99. void mmc_prof_update(mmc_prof_callback cb, ulong id, void *data)
  100. {
  101. ulong counts = (ulong)msdc_timer_get_count();
  102. if (cb) {
  103. cb(data, id, counts);
  104. }
  105. }
  106. void mmc_prof_report(struct mmc_op_report *rpt)
  107. {
  108. printf("\t\tCount : %d\n", rpt->count);
  109. printf("\t\tMax. Time : %d counts\n", rpt->max_time);
  110. printf("\t\tMin. Time : %d counts\n", rpt->min_time);
  111. printf("\t\tTotal Size : %d KB\n", rpt->total_size / 1024);
  112. printf("\t\tTotal Time : %d counts\n", rpt->total_time);
  113. if (rpt->total_time) {
  114. printf("\t\tPerformance: %d KB/sec\n",
  115. ((rpt->total_size / 1024) * 32768) / rpt->total_time);
  116. }
  117. }
  118. int mmc_prof_dump(int dev_id)
  119. {
  120. struct mmc_host *host;
  121. struct mmc_card *card;
  122. struct mmc_op_perf *perf;
  123. u32 total_read_size, total_write_size;
  124. u32 total_read_time, total_write_time;
  125. perf = &mmc_perf[dev_id];
  126. host = mmc_perf[dev_id].host;
  127. card = mmc_perf[dev_id].card;
  128. total_read_size = total_write_size = 0;
  129. total_read_time = total_write_time = 0;
  130. printf("\tSD Host ID : %d\n", dev_id);
  131. printf("\tOP Clock Freq. : %d khz\n", host->src_clk / 1000);
  132. printf("\tSD Clock Freq. : %d khz\n", host->cur_bus_clk / 1000);
  133. printf("\tCard Type : %s card\n", (card->type == MMC_TYPE_MMC) ? "MMC" : "SD/SDHC/SDXC");
  134. printf("\tCard Mode : UHS1(%d) DDR(%d) HS(%d)\n",
  135. mmc_card_uhs1(card) ? 1 : 0, mmc_card_ddr(card) ? 1 : 0,
  136. mmc_card_highspeed(card) ? 1 : 0);
  137. printf("\tCard Size : %d MB\n", (card->nblks * card->blklen) / 1024 / 1024);
  138. printf("\tCard Max. Freq.: %d khz\n", card->maxhz / 1000);
  139. if (perf->multi_blks_read.count) {
  140. printf("\tMulti-Blks-Read:\n");
  141. mmc_prof_report(&perf->multi_blks_read);
  142. total_read_size += perf->multi_blks_read.total_size;
  143. total_read_time += perf->multi_blks_read.total_time;
  144. }
  145. if (perf->multi_blks_write.count) {
  146. printf("\tMulti-Blks-Write:\n");
  147. mmc_prof_report(&perf->multi_blks_write);
  148. total_write_size += perf->multi_blks_write.total_size;
  149. total_write_time += perf->multi_blks_write.total_time;
  150. }
  151. if (perf->single_blk_read.count) {
  152. printf("\tSingle-Blk-Read:\n");
  153. mmc_prof_report(&perf->single_blk_read);
  154. total_read_size += perf->single_blk_read.total_size;
  155. total_read_time += perf->single_blk_read.total_time;
  156. }
  157. if (perf->single_blk_write.count) {
  158. printf("\tSingle-Blk-Write:\n");
  159. mmc_prof_report(&perf->single_blk_write);
  160. total_write_size += perf->single_blk_write.total_size;
  161. total_write_time += perf->single_blk_write.total_time;
  162. }
  163. if (total_read_time) {
  164. printf("\tPerformance Read : %d KB/sec\n",
  165. ((total_read_size / 1024) * 32768) / total_read_time);
  166. }
  167. if (total_write_time) {
  168. printf("\tPerformance Write: %d KB/sec\n",
  169. ((total_write_size / 1024) * 32768) / total_write_time);
  170. }
  171. return 0;
  172. }
  173. #endif
  174. #ifdef MMC_ICE_DOWNLOAD
  175. volatile u32 mmc_download_addr;
  176. volatile u32 mmc_download_size;
  177. volatile u32 mmc_image_addr;
  178. int mmc_download(int dev_id, u32 imgaddr, u32 size, u32 addr, int bootarea)
  179. {
  180. int ret;
  181. int i, j, result = 0;
  182. u8 val;
  183. u8 *ext_csd;
  184. uchar *buf, *chkbuf;
  185. u32 chunks, chunk_blks = 128, left_blks, blknr;
  186. u32 total_blks;
  187. struct mmc_card *card;
  188. if (!size)
  189. return 0;
  190. if (addr % MMC_BLOCK_SIZE)
  191. return MMC_ERR_FAILED;
  192. card = mmc_get_card(dev_id);
  193. ext_csd = &card->raw_ext_csd[0];
  194. if (bootarea && !mmc_card_sd(card) && card->ext_csd.part_en) {
  195. /* configure to specified partition */
  196. val = (ext_csd[EXT_CSD_PART_CFG] & ~0x7) | EXT_CSD_PART_CFG_BOOT_PART_1;
  197. if (mmc_set_part_config(card, val) != MMC_ERR_NONE) {
  198. result = -__LINE__;
  199. goto done;
  200. }
  201. }
  202. blknr = addr / MMC_BLOCK_SIZE;
  203. total_blks = (size + MMC_BLOCK_SIZE - 1) / MMC_BLOCK_SIZE;
  204. /* multiple block write */
  205. chunks = total_blks / chunk_blks;
  206. left_blks = total_blks % chunk_blks;
  207. buf = (uchar*)imgaddr;
  208. chkbuf = (uchar*)MMC_BUF_ADDR;
  209. for (i = 0; i < chunks; i++) {
  210. ret = mmc_block_write(dev_id, blknr + i * chunk_blks,
  211. chunk_blks, (unsigned long*)buf);
  212. if (ret != MMC_ERR_NONE) {
  213. result = -__LINE__;
  214. goto done;
  215. }
  216. ret = mmc_block_read(dev_id, blknr + i * chunk_blks,
  217. chunk_blks, (unsigned long*)chkbuf);
  218. if (ret != MMC_ERR_NONE) {
  219. result = -__LINE__;
  220. goto done;
  221. }
  222. for (j = 0; j < chunk_blks * MMC_BLOCK_SIZE; j++) {
  223. if (buf[j] == chkbuf[j])
  224. continue;
  225. result = -__LINE__;
  226. goto done;
  227. }
  228. printf("[SD%d] Write %3d blocks from 0x%.8x(RAM) to 0x%.8x(FLASH).\n",
  229. dev_id, chunk_blks, (unsigned int)buf,
  230. (blknr + i * chunk_blks) * MMC_BLOCK_SIZE);
  231. buf += (chunk_blks * MMC_BLOCK_SIZE);
  232. }
  233. if (left_blks) {
  234. ret = mmc_block_write(dev_id, blknr + chunks * chunk_blks,
  235. left_blks, (unsigned long*)buf);
  236. if (ret != MMC_ERR_NONE) {
  237. result = -__LINE__;
  238. goto done;
  239. }
  240. ret = mmc_block_read(dev_id, blknr + chunks * chunk_blks,
  241. left_blks, (unsigned long*)chkbuf);
  242. if (ret != MMC_ERR_NONE) {
  243. result = -__LINE__;
  244. goto done;
  245. }
  246. for (j = 0; j < left_blks * MMC_BLOCK_SIZE; j++) {
  247. if (buf[j] == chkbuf[j])
  248. continue;
  249. printf("[SD%d] chkbuf[%d] = %xh (!= %xh) \n", dev_id,
  250. j, chkbuf[j], buf[j]);
  251. result = -__LINE__;
  252. goto done;
  253. }
  254. printf("[SD%d] Write %3d blocks from 0x%.8x(RAM) to 0x%.8x(FLASH).\n",
  255. dev_id, left_blks, (unsigned int)buf,
  256. (blknr + chunks * chunk_blks) * MMC_BLOCK_SIZE);
  257. }
  258. done:
  259. if (bootarea && !mmc_card_sd(card) && card->ext_csd.part_en) {
  260. /* configure to user partition */
  261. val = (ext_csd[EXT_CSD_PART_CFG] & ~0x7) | EXT_CSD_PART_CFG_DEFT_PART;
  262. if (mmc_set_part_config(card, val) != MMC_ERR_NONE)
  263. result = -__LINE__;
  264. }
  265. if (!result) {
  266. printf("[SD%d] Download %d blocks (%d bytes) to 0x%.8x successfully\n",
  267. dev_id, total_blks, total_blks * MMC_BLOCK_SIZE, blknr * MMC_BLOCK_SIZE);
  268. } else {
  269. printf("[SD%d] Download %d blocks (%d bytes) to 0x%.8x failed %d\n",
  270. dev_id, total_blks, total_blks * MMC_BLOCK_SIZE, blknr * MMC_BLOCK_SIZE, result);
  271. }
  272. return result;
  273. }
  274. int mmc_download_part(int dev_id, char *part_name, int bootarea)
  275. {
  276. int ret = -1;
  277. struct mmc_card *card;
  278. struct mmc_host *host;
  279. part_t *part = mt6573_part_get_partition(part_name);
  280. mmc_download_addr = 0;
  281. mmc_download_size = 0;
  282. mmc_image_addr = 0;
  283. host = mmc_get_host(dev_id);
  284. card = mmc_get_card(dev_id);
  285. if (part) {
  286. printf("[SD%d] Waiting for '%s' image loading from ICE...\n", dev_id, part_name);
  287. while (!mmc_download_size); /* Wait for loading image from ICE */
  288. ret = mmc_download(dev_id, mmc_image_addr, mmc_download_size,
  289. part->startblk * BLK_SIZE, bootarea);
  290. if (ret != 0)
  291. goto done;
  292. if (bootarea) {
  293. /* set reset signal function */
  294. //ret = mmc_set_reset_func(card, 1);
  295. //if (ret != 0)
  296. // goto done;
  297. /* set boot config */
  298. ret = mmc_boot_config(card, EXT_CSD_PART_CFG_EN_ACK,
  299. EXT_CSD_PART_CFG_EN_BOOT_PART_1, EXT_CSD_BOOT_BUS_WIDTH_1,
  300. EXT_CSD_BOOT_BUS_MODE_DEFT);
  301. if (ret != 0)
  302. goto done;
  303. ret = mmc_read_ext_csd(host, card);
  304. }
  305. }
  306. done:
  307. return ret;
  308. }
  309. #endif
  310. /* r: read only, w: write only, a:readable & writable
  311. * k: read clear, x: don't care, n: do not test
  312. * s: readable and write 1 set, c: readable and write 1 clear
  313. *
  314. * RU: read only bit value update by the hw, denote as 't', like MSDC_RXDATA, MSDC_CFG[7]:CARD_CK_STABLE
  315. * RO: read only, denote as 'r', like MSDC_VERSION
  316. * RW: writeable and readable, denote as 'a'
  317. * WO: write only, denote as 'w', like MSDC_TXDATA
  318. * W1: write once, denote as '', not used yet.
  319. * RC: clear on read, denote as 'k', not used yet.
  320. * A1: auto set by the hw.
  321. * A0: auto clear by the hw, denote as 'z' like MSDC_CS[31]
  322. * DC: don't care, denote as 'n' or 'x'
  323. * W1C: write 1 to bit wise-clear, denote as 'c', like SDC_CSTS
  324. * note: RU means the content of the regiter will change,
  325. * RO means the content of the register will not change
  326. */
  327. /* need confirmed with cui
  328. * card detect bit 0x8[1] default is set to 0, why fpga set to 1?
  329. * msdc inten bit 0x10[20,21.22], not define, why fpga test it as readonly bit? emmc read as '0', but sd card read as '1'
  330. * msdc cmd bit 0x34[31], not define, why fpga test it as r/w bit? emmc read as '0', but sd card read as '1'
  331. * msdc dma cfg bit 0x9c[17], not define, why fpga test it as readonly bit? emmc read as '0', but sd card read as '1'
  332. * sdwp 0x08[31], default is set to 0, why fpga set to 1? */
  333. static reg_desc_t msdc0_reg_desc[] = {
  334. //{"01234567890123456789012345678901"}, {"01234567890123456789012345678901"}
  335. {OFFSET_MSDC_CFG , {"aazaaarraaaaaaaaaaaaaaaaaaxxxxxx"}, {"10011001000000000000000001xxxxxx"}}, //bit[2] is rw, but not test. cause this is a reset bit. write to "1" will back to "0" when reset sequence done
  336. {OFFSET_MSDC_IOCON , {"aaaaaaxxaaaaaaxxaaaaaaaaxxxxxxxx"}, {"000000xx000000xx0000000000xxxxxx"}},//bit[24][25] can not write(Not in MT8320 MSDC IP)
  337. {OFFSET_MSDC_PS , {"arxxxxxxxxxxaaaarrrrrrrrrxxxxxxr"}, {"01xxxxxxxxxx0000111111111xxxxxx1"}},//bit[1]/bit[16-20]/bit[24]/bit[31] default to 0
  338. {OFFSET_MSDC_INT , {"ccxccccccccrccccccccccccxxxxxxxx"}, {"00x000000000000000000000xxxxxxxx"}},
  339. {OFFSET_MSDC_INTEN , {"aaxaaaaaaaaaaaaaaaaarrraxxxxxxxx"}, {"00x000000000000000000000xxxxxxxx"}},//bit[2] to RW, default to 0
  340. {OFFSET_MSDC_FIFOCS , {"rrrrrrrrxxxxxxxxrrrrrrrrxxxxxxxr"}, {"00000000xxxxxxxx00000000xxxxxxx0"}},//bit[0]~[7] are variable if you use memory tool in Code visor (memory tool must be closed)
  341. {OFFSET_MSDC_TXDATA , {"wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"}, {"00000000000000000000000000000000"}},
  342. //{OFFSET_MSDC_RXDATA , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},/* Should not be touched. or 0x78 init value will wrong */
  343. {OFFSET_SDC_CFG , {"aaxxxxxxxxxxxxxxaaxaaaxxaaaaaaaa"}, {"00xxxxxxxxxxxxxx00x010xx00000000"}},
  344. {OFFSET_SDC_CMD , {"aaaaaaaaaaxaaaaaaaaaaaaaaaaaaaar"}, {"0000000000x000000000000000000000"}},
  345. {OFFSET_SDC_ARG , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  346. {OFFSET_SDC_STS , {"rrxxxxxxxxxxxxxxcxxxxxxxxxxxxxxr"}, {"00xxxxxxxxxxxxxx0xxxxxxxxxxxxxx0"}},
  347. {OFFSET_SDC_RESP0 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  348. {OFFSET_SDC_RESP1 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  349. {OFFSET_SDC_RESP2 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  350. {OFFSET_SDC_RESP3 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  351. {OFFSET_SDC_BLK_NUM , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"10000000000000000000000000000000"}},
  352. {OFFSET_SDC_VOL_CHG , {"aaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxx"}, {"1010001010000000xxxxxxxxxxxxxxxx"}}, //new register in denali1
  353. {OFFSET_SDC_CSTS , {"cccccccccccccccccccccccccccccccc"}, {"00000000000000000000000000000000"}},
  354. {OFFSET_SDC_CSTS_EN , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  355. {OFFSET_SDC_DCRC_STS , {"rrrrrrrrrrrrrrrrxxxxxxxxxxxxxxxx"}, {"0000000000000000xxxxxxxxxxxxxxxx"}},//bit[12-15] modify
  356. {OFFSET_EMMC_CFG0 , {"wwaaxxxxxxxxaaaaxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxx0000xxxxxxxxxxxxxxxx"}},
  357. {OFFSET_EMMC_CFG1 , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"11000000000000000000010000000000"}},
  358. {OFFSET_EMMC_STS , {"ccccrcrxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0000000xxxxxxxxxxxxxxxxxxxxxxxxx"}},////bit[6]=1,0 is wrong,maybe has relationship with OFFSET_MSDC_FIFOCS register bit[0]~[7] which are variable
  359. {OFFSET_EMMC_IOCON , {"axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  360. {OFFSET_SDC_ACMD_RESP , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  361. {OFFSET_SDC_ACMD19_TRG, {"aaaaxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  362. {OFFSET_SDC_ACMD19_STS, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  363. {OFFSET_MSDC_DMA_SA_HIGH4BIT, {"aaaaxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxxxxxxxxxxxxxxxxxxxxxx"}}, //new register in denali1
  364. {OFFSET_MSDC_DMA_SA , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  365. {OFFSET_MSDC_DMA_CA , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  366. {OFFSET_MSDC_DMA_CTRL , {"wrwrxxxxaaaaaaaxxxxxxxxxxxxxxxxx"}, {"0001xxxx0000011xxxxxxxxxxxxxxxxx"}}, //need new design, bit[1] = AO
  367. {OFFSET_MSDC_DMA_CFG , {"raaxxxxxaaxxaaxxaxxxxxxxxxxxxxxx"}, {"001xxxxx00xx00xx0xxxxxxxxxxxxxxx"}},
  368. {OFFSET_MSDC_DBG_SEL , {"aaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxx"}, {"0000000000000000xxxxxxxxxxxxxxxx"}},
  369. {OFFSET_MSDC_DBG_OUT , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  370. {OFFSET_MSDC_DMA_LEN , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}}, //new register in MT6582
  371. {OFFSET_MSDC_PATCH_BIT0, {"xaaxxxaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"x11xxx00000000000011110000000010"}},
  372. {OFFSET_MSDC_PATCH_BIT1, {"aaaaaaaaaaaaaaxaaaaaaaaaaaaaaaaa"}, {"10010000000000x00111111111111111"}},
  373. {OFFSET_MSDC_PATCH_BIT2, {"aaaaaaaaaaxaaaaaaaaxaaaaaaaaaaaa"}, {"1100000000x11000000x000100101000"}}, //new register in denali1
  374. {OFFSET_DAT0_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  375. {OFFSET_DAT1_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  376. {OFFSET_DAT2_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  377. {OFFSET_DAT3_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  378. {OFFSET_CMD_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  379. //{OFFSET_SDIO_TUNE_WIND, {"aaaaaxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"00000xxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  380. //{OFFSET_MSDC_PAD_CTL0, {"aaaxxxxxaxxxxxxaaaaaaaaaaaaaaaaa"}, {"000xxxxx0xxxxxx11001000000000000"}},
  381. //{OFFSET_MSDC_PAD_CTL1, {"aaaxxxxxaxxxxxxaaaaaaaaaaaaaaaaa"}, {"000xxxxx0xxxxxx00101000000000000"}},
  382. //{OFFSET_MSDC_PAD_CTL2, {"aaaxxxxxaxxxxxxaaaaaaaaaaaaaaaaa"}, {"000xxxxx0xxxxxx00101000000000000"}},
  383. {OFFSET_MSDC_PAD_TUNE0 , {"aaaaaxxaaaaaaxxxaaaaaxaaaaaaaaaa"}, {"00000xx000000xxx00000x0000000000"}},
  384. {OFFSET_MSDC_DAT_RDDLY0, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  385. {OFFSET_MSDC_DAT_RDDLY1, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  386. {OFFSET_MSDC_HW_DBG , {"aaaaaaaaaaaaaaxxaaaaaaaaaaaaaaax"}, {"00000000000000xx000000000000000x"}},
  387. {OFFSET_MSDC_VERSION , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"11000000010010001100100000000100"}},//20140126
  388. {OFFSET_MSDC_ECO_VER , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"10000000000000000000000000000000"}},//0
  389. {OFFSET_EMMC50_PAD_CTL0, {"aaaaaaaaaaxxxxxxxxxxxxxxxxxxxxxx"}, {"0000000000xxxxxxxxxxxxxxxxxxxxxx"}},
  390. {OFFSET_EMMC50_PAD_DS_CTL0, {"aaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxx"}, {"0011100000000000000xxxxxxxxxxxxx"}},
  391. //{OFFSET_EMMC50_PAD_DS_TUNE, {"aaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxx"}, {"10101000000000101xxxxxxxxxxxxxxx"}},
  392. {OFFSET_EMMC50_PAD_CMD_TUNE, {"aaaaaaaaaaaxxxxxxxxxxxxxxxxxxxxx"}, {"00000000000xxxxxxxxxxxxxxxxxxxxx"}},
  393. {OFFSET_EMMC50_PAD_DAT01_TUNE, {"aaaaaaaaaaaxxxxxaaaaaaaaaaaxxxxx"}, {"00000000000xxxxx00000000000xxxxx"}},
  394. {OFFSET_EMMC50_PAD_DAT23_TUNE, {"aaaaaaaaaaaxxxxxaaaaaaaaaaaxxxxx"}, {"00000000000xxxxx00000000000xxxxx"}},
  395. {OFFSET_EMMC50_PAD_DAT45_TUNE, {"aaaaaaaaaaaxxxxxaaaaaaaaaaaxxxxx"}, {"00000000000xxxxx00000000000xxxxx"}},
  396. {OFFSET_EMMC50_PAD_DAT67_TUNE, {"aaaaaaaaaaaxxxxxaaaaaaaaaaaxxxxx"}, {"00000000000xxxxx00000000000xxxxx"}},
  397. {OFFSET_EMMC51_CFG0, {"aaaaaaaaaaaaaaaaaaaaaaxxxxxxxxxx"}, {"0010101100001010110000xxxxxxxxxx"}},
  398. {OFFSET_EMMC50_CFG0, {"aaaaaaaaaaaaaaaaaaaaaaaaarraaxxa"}, {"01000111100100010001011101000xx0"}},
  399. {OFFSET_EMMC50_CFG1, {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00110000111000000000000010000000"}},
  400. {OFFSET_EMMC50_CFG2, {"xaaaaaaaaxxxxaaaaaaaaaaaaaaarrrx"}, {"x00000000xxxx000001100001111000x"}},
  401. {OFFSET_EMMC50_CFG3, {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaarrr"}, {"10000011110001010001010011110000"}},
  402. {OFFSET_EMMC50_CFG4, {"aaaaaaaaaaaaaaaaaaaaaaaxxxxxxxxx"}, {"01111000000101001000000xxxxxxxxx"}},
  403. };
  404. static reg_desc_t msdc1_reg_desc[] = {
  405. //{"01234567890123456789012345678901"}, {"01234567890123456789012345678901"}
  406. {OFFSET_MSDC_CFG , {"aazaaarraaaaaaaaaaaaaaxxxaxxxxxx"}, {"1001100100000000000000xxx1xxxxxx"}}, //bit[2] is rw, but not test. cause this is a reset bit. write to "1" will back to "0" when reset sequence done
  407. {OFFSET_MSDC_IOCON , {"aaaaaaxxaaaaaaxxaaaaaaaaxxxxxxxx"}, {"000000xx000000xx0000000000xxxxxx"}},//bit[24][25] can not write(Not in MT8320 MSDC IP)
  408. {OFFSET_MSDC_PS , {"atxxxxxxxxxxaaaattttxxxxtxxxxxxt"}, {"00xxxxxxxxxx00001111xxxx1xxxxxx0"}},//bit[1]/bit[16-20]/bit[24]/bit[31] default to 0
  409. {OFFSET_MSDC_INT , {"ccxccccccccrccccccccccccxxxxxxxx"}, {"00x000000000000000000000xxxxxxxx"}},
  410. {OFFSET_MSDC_INTEN , {"aaxaaaaaaaaaaaaaaaaaxxxxxxxxxxxx"}, {"00x00000000000000000xxxxxxxxxxxx"}},//bit[2] to RW, default to 0
  411. {OFFSET_MSDC_FIFOCS , {"rrrrrrrrxxxxxxxxrrrrrrrrxxxxxxxz"}, {"00000000xxxxxxxx00000000xxxxxxx0"}},//bit[0]~[7] are variable if you use memory tool in Code visor (memory tool must be closed)
  412. {OFFSET_MSDC_TXDATA , {"wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"}, {"00000000000000000000000000000000"}},
  413. //{OFFSET_MSDC_RXDATA , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},/* Should not be touched. */
  414. {OFFSET_SDC_CFG , {"aaxxxxxxxxxxxxxxaaxaaaxxaaaaaaaa"}, {"00xxxxxxxxxxxxxx00x010xx00000000"}},
  415. {OFFSET_SDC_CMD , {"xaaaaaaaaaxaaaaaaaaaaaaaaaaaaaax"}, {"x000000000x000000000000000000000"}},
  416. {OFFSET_SDC_ARG , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  417. {OFFSET_SDC_STS , {"ttxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr"}, {"00xxxxxxxxxxxxxxxxxxxxxxxxxxxxx0"}},
  418. {OFFSET_SDC_RESP0 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  419. {OFFSET_SDC_RESP1 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  420. {OFFSET_SDC_RESP2 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  421. {OFFSET_SDC_RESP3 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  422. {OFFSET_SDC_BLK_NUM , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"10000000000000000000000000000000"}},
  423. {OFFSET_SDC_VOL_CHG , {"aaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxx"}, {"1010001010000000xxxxxxxxxxxxxxxx"}}, //new register in denali1
  424. {OFFSET_SDC_CSTS , {"cccccccccccccccccccccccccccccccc"}, {"00000000000000000000000000000000"}},
  425. {OFFSET_SDC_CSTS_EN , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  426. {OFFSET_SDC_DCRC_STS , {"rrrrrrrrrrrrrrrrxxxxxxxxxxxxxxxx"}, {"0000000000000000xxxxxxxxxxxxxxxx"}},//bit[12-15] modify
  427. {OFFSET_EMMC_CFG0 , {"wwaaxxxxxxxxaaaaxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxx0000xxxxxxxxxxxxxxxx"}},
  428. {OFFSET_EMMC_CFG1 , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"11000000000000000000010000000000"}},
  429. {OFFSET_EMMC_STS , {"ccccrcrxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0000000xxxxxxxxxxxxxxxxxxxxxxxxx"}},////bit[6]=1,0 is wrong,maybe has relationship with OFFSET_MSDC_FIFOCS register bit[0]~[7] which are variable
  430. {OFFSET_EMMC_IOCON , {"axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  431. {OFFSET_SDC_ACMD_RESP , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  432. {OFFSET_SDC_ACMD19_TRG, {"aaaaxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  433. {OFFSET_SDC_ACMD19_STS, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  434. {OFFSET_MSDC_DMA_SA_HIGH4BIT, {"aaaaxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxxxxxxxxxxxxxxxxxxxxxx"}}, //new register in denali1
  435. {OFFSET_MSDC_DMA_SA , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  436. {OFFSET_MSDC_DMA_CA , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  437. {OFFSET_MSDC_DMA_CTRL , {"wrwxxxxxaxaxaaaxxxxxxxxxxxxxxxxx"}, {"000xxxxx0x0x011xxxxxxxxxxxxxxxxx"}}, //need new design, bit[1] = AO
  438. {OFFSET_MSDC_DMA_CFG , {"raxxxxxxaaxxaaxxaxxxxxxxxxxxxxxx"}, {"00xxxxxx00xx00xx0xxxxxxxxxxxxxxx"}},
  439. {OFFSET_MSDC_DBG_SEL , {"aaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxx"}, {"0000000000000000xxxxxxxxxxxxxxxx"}},
  440. {OFFSET_MSDC_DBG_OUT , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  441. {OFFSET_MSDC_DMA_LEN , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}}, //new register in MT6582
  442. {OFFSET_MSDC_PATCH_BIT0, {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"11110010000000000011110000000010"}},
  443. {OFFSET_MSDC_PATCH_BIT1, {"aaaaaaaaaaaaaaxaaxxxaaxaaaaaaaaa"}, {"10010000000000x00xxx11x111111111"}},
  444. {OFFSET_MSDC_PATCH_BIT2, {"aaaaaaaaaaxaaaaaaaaxaaaaaaaaaaaa"}, {"1100000000x11000000x000100101000"}}, //new register in denali1
  445. #if 0
  446. {OFFSET_SDIO_TUNE_WIND, {"aaaaaxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"00000xxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  447. {OFFSET_MSDC_PAD_CTL0, {"aaaxxxxxaxxxxxxaaaaaaaaaaaaaaaaa"}, {"000xxxxx0xxxxxx11001000000000000"}},
  448. {OFFSET_MSDC_PAD_CTL1, {"aaaxxxxxaxxxxxxaaaaaaaaaaaaaaaaa"}, {"000xxxxx0xxxxxx00101000000000000"}},
  449. {OFFSET_MSDC_PAD_CTL2, {"aaaxxxxxaxxxxxxaaaaaaaaaaaaaaaaa"}, {"000xxxxx0xxxxxx00101000000000000"}},
  450. #endif
  451. {OFFSET_MSDC_PAD_TUNE0 , {"aaaaaxxxaaaaaxxxaaaaaxaaaaaaaaaa"}, {"00000xxx00000xxx00000x0000000000"}},
  452. {OFFSET_MSDC_DAT_RDDLY0, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  453. {OFFSET_MSDC_DAT_RDDLY1, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  454. {OFFSET_MSDC_HW_DBG , {"aaaaaaaaaaaaaaxxaaaaaaaaaaaaaaax"}, {"00000000000000xx000000000000000x"}},
  455. {OFFSET_MSDC_VERSION , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00001100101000001100100000000100"}},//20130530
  456. {OFFSET_MSDC_ECO_VER , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},//eco value
  457. };
  458. static reg_desc_t msdc2_reg_desc[] = {
  459. {OFFSET_MSDC_CFG , {"aazaaarraaaaaaaaccxxxaxxxxxxxxxx"}, {"100110010000000000xxx1xxxxxxxxxx"}}, //bit[2] is rw, but not test. cause this is a reset bit. write to "1" will back to "0" when reset sequence done
  460. {OFFSET_MSDC_IOCON , {"aaaaaaxxaaaaaaxxaaaaaaaaxxxxxxxx"}, {"000000xx000000xx0000000000xxxxxx"}},//bit[24][25] can not write(Not in MT8320 MSDC IP)
  461. {OFFSET_MSDC_PS , {"atxxxxxxxxxxaaaattttxxxxtxxxxxxt"}, {"00xxxxxxxxxx00001111xxxx1xxxxxxx"}},//bit[1]/bit[16-20]/bit[24]/bit[31] default to 0
  462. {OFFSET_MSDC_INT , {"ccxccccccccrccccccccccccxxxxxxxx"}, {"00x000000000000000000000xxxxxxxx"}},
  463. {OFFSET_MSDC_INTEN , {"aaxaaaaaaaaaaaaaaaaaaaaxxxxxxxxx"}, {"00x000000000000000000000xxxxxxxx"}},//bit[2] to RW, default to 0
  464. {OFFSET_MSDC_FIFOCS , {"rrrrrrrrxxxxxxxxrrrrrrrrxxxxxxxz"}, {"00000000xxxxxxxx00000000xxxxxxx0"}},//bit[0]~[7] are variable if you use memory tool in Code visor (memory tool must be closed)
  465. {OFFSET_MSDC_TXDATA , {"wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"}, {"00000000000000000000000000000000"}},
  466. //{OFFSET_MSDC_RXDATA , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},/* Should not be touched. */
  467. {OFFSET_SDC_CFG , {"aaxxxxxxxxxxxxxxaaxaaaxxaaaaaaaa"}, {"00xxxxxxxxxxxxxx00x010xx00000000"}},
  468. {OFFSET_SDC_CMD , {"aaaaaaaaaaxaaaaaaaaaaaaaaaaaaaaa"}, {"0000000000x000000000000000000000"}},
  469. {OFFSET_SDC_ARG , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  470. {OFFSET_SDC_STS , {"rrxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr"}, {"00xxxxxxxxxxxxxxxxxxxxxxxxxxxxx0"}},
  471. {OFFSET_SDC_RESP0 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  472. {OFFSET_SDC_RESP1 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  473. {OFFSET_SDC_RESP2 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  474. {OFFSET_SDC_RESP3 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  475. {OFFSET_SDC_BLK_NUM , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"10000000000000000000000000000000"}},
  476. {OFFSET_SDC_CSTS , {"cccccccccccccccccccccccccccccccc"}, {"00000000000000000000000000000000"}},
  477. {OFFSET_SDC_CSTS_EN , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  478. {OFFSET_SDC_DCRC_STS , {"rrrrrrrrrrrrrrrrxxxxxxxxxxxxxxxx"}, {"0000000000000000xxxxxxxxxxxxxxxx"}},//bit[12-15] modify
  479. //msdc2 have not register for emmc, please msdc2 CODA
  480. //{OFFSET_EMMC_CFG0 , {"wwaaxxxxxxxxaaaaxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxx0000xxxxxxxxxxxxxxxx"}},
  481. //{OFFSET_EMMC_CFG1 , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"11000000000000000000010000000000"}},
  482. //{OFFSET_EMMC_STS , {"ccccrcrxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0000000xxxxxxxxxxxxxxxxxxxxxxxxx"}},////bit[6]=1,0 is wrong,maybe has relationship with OFFSET_MSDC_FIFOCS register bit[0]~[7] which are variable
  483. //{OFFSET_EMMC_IOCON , {"axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  484. {OFFSET_SDC_ACMD_RESP , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  485. {OFFSET_SDC_ACMD19_TRG, {"aaaaxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  486. {OFFSET_SDC_ACMD19_STS, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  487. {OFFSET_MSDC_DMA_SA , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  488. {OFFSET_MSDC_DMA_CA , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  489. {OFFSET_MSDC_DMA_CTRL , {"wrwxxxxxaxaxaaaxxxxxxxxxxxxxxxxx"}, {"000xxxxx0x0x011xxxxxxxxxxxxxxxxx"}}, //need new design, bit[1] = AO
  490. {OFFSET_MSDC_DMA_CFG , {"raxxxxxxaaxxaaxxaaxxxxxxxxxxxxxx"}, {"00xxxxxx00xx00xx00xxxxxxxxxxxxxx"}},
  491. {OFFSET_MSDC_DBG_SEL , {"aaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxx"}, {"0000000000000000xxxxxxxxxxxxxxxx"}},
  492. {OFFSET_MSDC_DBG_OUT , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  493. {OFFSET_MSDC_DMA_LEN , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}}, //new register in MT6582
  494. {OFFSET_MSDC_PATCH_BIT0, {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"11110010000000000011110000000010"}},
  495. {OFFSET_MSDC_PATCH_BIT1, {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"10010000000000001111111111111111"}},
  496. #if 0
  497. {OFFSET_SDIO_TUNE_WIND, {"aaaaaxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"00000xxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  498. {OFFSET_MSDC_PAD_CTL0, {"aaaxxxxxaxxxxxxaaaaaaaaaaaaaaaaa"}, {"000xxxxx0xxxxxx11001000000000000"}},
  499. {OFFSET_MSDC_PAD_CTL1, {"aaaxxxxxaxxxxxxaaaaaaaaaaaaaaaaa"}, {"000xxxxx0xxxxxx00101000000000000"}},
  500. {OFFSET_MSDC_PAD_CTL2, {"aaaxxxxxaxxxxxxaaaaaaaaaaaaaaaaa"}, {"000xxxxx0xxxxxx00101000000000000"}},
  501. #endif
  502. {OFFSET_MSDC_PAD_TUNE0 , {"aaaaaxxxaaaaaxxxaaaaaxaaaaaaaaaa"}, {"00000xxx00000xxx00000x0000000000"}},
  503. {OFFSET_MSDC_DAT_RDDLY0, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  504. {OFFSET_MSDC_DAT_RDDLY1, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  505. {OFFSET_MSDC_HW_DBG , {"aaaaaaaaaaaaaaxxaaaaaaaaaaaaaaax"}, {"00000000000000xx000000000000000x"}},
  506. {OFFSET_MSDC_VERSION , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00001100101000001100100000000100"}},//20130530
  507. {OFFSET_MSDC_ECO_VER , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},//eco value
  508. };
  509. static reg_desc_t msdc3_reg_desc[] = {
  510. {OFFSET_MSDC_CFG , {"aazaaarraaaaaaaaccxxxaxxxxxxxxxx"}, {"1001100100000000000001xxxxxxxxxx"}}, //bit[2] is rw, but not test. cause this is a reset bit. write to "1" will back to "0" when reset sequence done
  511. {OFFSET_MSDC_IOCON , {"aaaaaaxxaaaaaaxxaaaaaaaaxxxxxxxx"}, {"000000xx000000xx0000000000xxxxxx"}},//bit[24][25] can not write(Not in MT8320 MSDC IP)
  512. {OFFSET_MSDC_PS , {"atxxxxxxxxxxaaaarrrrxxxxrxxxxxxt"}, {"00xxxxxxxxxx0000111111111xxxxxx0"}},//bit[1]/bit[16-20]/bit[24]/bit[31] default to 0
  513. {OFFSET_MSDC_INT , {"ccxccccccccrccccccccccccxxxxxxxx"}, {"00x000000000000000000000xxxxxxxx"}},
  514. {OFFSET_MSDC_INTEN , {"aaxaaaaaaaaaaaaaaaaaaaaxxxxxxxxx"}, {"00x000000000000000000000xxxxxxxx"}},//bit[2] to ignore
  515. {OFFSET_MSDC_FIFOCS , {"rrrrrrrrxxxxxxxxrrrrrrrrxxxxxxxz"}, {"00000000xxxxxxxx00000000xxxxxxx0"}},//bit[0]~[7] are variable if you use memory tool in Code visor (memory tool must be closed)
  516. {OFFSET_MSDC_TXDATA , {"wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"}, {"00000000000000000000000000000000"}},
  517. //{OFFSET_MSDC_RXDATA , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},/* Should not be touched. */
  518. {OFFSET_SDC_CFG , {"aaxxxxxxxxxxxxxxaaxaaaxxaaaaaaaa"}, {"00xxxxxxxxxxxxxx00x010xx00000000"}},
  519. {OFFSET_SDC_CMD , {"aaaaaaaaaaxaaaaaaaaaaaaaaaaaaaaa"}, {"0000000000x000000000000000000000"}},
  520. {OFFSET_SDC_ARG , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  521. {OFFSET_SDC_STS , {"rrxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr"}, {"00xxxxxxxxxxxxxxxxxxxxxxxxxxxxx0"}},
  522. {OFFSET_SDC_RESP0 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  523. {OFFSET_SDC_RESP1 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  524. {OFFSET_SDC_RESP2 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  525. {OFFSET_SDC_RESP3 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  526. {OFFSET_SDC_BLK_NUM , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"10000000000000000000000000000000"}},
  527. {OFFSET_SDC_CSTS , {"cccccccccccccccccccccccccccccccc"}, {"00000000000000000000000000000000"}},
  528. {OFFSET_SDC_CSTS_EN , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  529. {OFFSET_SDC_DCRC_STS , {"rrrrrrrrrrrrrrrrxxxxxxxxxxxxxxxx"}, {"0000000000000000xxxxxxxxxxxxxxxx"}},//bit[12-15] modify
  530. //{OFFSET_EMMC_CFG0 , {"wwaaxxxxxxxxaaaaxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxx0000xxxxxxxxxxxxxxxx"}},
  531. //{OFFSET_EMMC_CFG1 , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"11000000000000000000010000000000"}},
  532. {OFFSET_EMMC_STS , {"ccccrcrxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0000000xxxxxxxxxxxxxxxxxxxxxxxxx"}},////bit[6]=1,0 is wrong,maybe has relationship with OFFSET_MSDC_FIFOCS register bit[0]~[7] which are variable
  533. //{OFFSET_EMMC_IOCON , {"axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  534. {OFFSET_SDC_ACMD_RESP , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  535. {OFFSET_SDC_ACMD19_TRG, {"aaaaxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  536. {OFFSET_SDC_ACMD19_STS, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  537. {OFFSET_MSDC_DMA_SA , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  538. {OFFSET_MSDC_DMA_CA , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  539. {OFFSET_MSDC_DMA_CTRL , {"wrwxxxxxaxaxaaaxxxxxxxxxxxxxxxxx"}, {"000xxxxx0x0x011xxxxxxxxxxxxxxxxx"}}, //need new design, bit[1] = AO
  540. {OFFSET_MSDC_DMA_CFG , {"raxxxxxxaaxxaaxxaaxxxxxxxxxxxxxx"}, {"00xxxxxx00xx00xx00xxxxxxxxxxxxxx"}},
  541. {OFFSET_MSDC_DBG_SEL , {"aaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxx"}, {"0000000000000000xxxxxxxxxxxxxxxx"}},
  542. {OFFSET_MSDC_DBG_OUT , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  543. {OFFSET_MSDC_DMA_LEN , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}}, //new register in MT6582
  544. {OFFSET_MSDC_PATCH_BIT0, {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"11110010000000000011110000000010"}},
  545. {OFFSET_MSDC_PATCH_BIT1, {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"10010000000000001111111111111111"}},
  546. #if 0
  547. {OFFSET_SDIO_TUNE_WIND, {"aaaaaxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"00000xxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  548. {OFFSET_MSDC_PAD_CTL0, {"aaaxxxxxaxxxxxxaaaaaaaaaaaaaaaaa"}, {"000xxxxx0xxxxxx11001000000000000"}},
  549. {OFFSET_MSDC_PAD_CTL1, {"aaaxxxxxaxxxxxxaaaaaaaaaaaaaaaaa"}, {"000xxxxx0xxxxxx00101000000000000"}},
  550. {OFFSET_MSDC_PAD_CTL2, {"aaaxxxxxaxxxxxxaaaaaaaaaaaaaaaaa"}, {"000xxxxx0xxxxxx00101000000000000"}},
  551. #endif
  552. {OFFSET_MSDC_PAD_TUNE0 , {"aaaaaxxxaaaaaxxxaaaaaxaaaaaaaaaa"}, {"00000xxx00000xxx00000x0000000000"}},
  553. {OFFSET_MSDC_DAT_RDDLY0, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  554. {OFFSET_MSDC_DAT_RDDLY1, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  555. {OFFSET_MSDC_HW_DBG , {"aaaaaaaaaaaaaaxxaaaaaaaaaaaaaaax"}, {"00000000000000xx000000000000000x"}},
  556. {OFFSET_MSDC_VERSION , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00001100101000001100100000000100"}},//20130530
  557. {OFFSET_MSDC_ECO_VER , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},//eco value
  558. };
  559. /* r: read only, w: write only, a:readable & writable
  560. * k: read clear, x: don't care, n: do not test
  561. * s: readable and write 1 set, c: readable and write 1 clear
  562. *
  563. * RU: read only bit value update by the hw, denote as 't', like MSDC_RXDATA, MSDC_CFG[7]:CARD_CK_STABLE
  564. * RO: read only, denote as 'r', like MSDC_VERSION
  565. * RW: writeable and readable, denote as 'a'
  566. * WO: write only, denote as 'w', like MSDC_TXDATA
  567. * W1: write once, denote as '', not used yet.
  568. * RC: clear on read, denote as 'k', not used yet.
  569. * A1: auto set by the hw.
  570. * A0: auto clear by the hw.
  571. * DC: don't care, denote as 'n' or 'x'
  572. * W1C: write 1 to bit wise-clear, denote as 'c', like SDC_CSTS
  573. * note: RU means the content of the regiter will change,
  574. * RO means the content of the register will not change
  575. */
  576. int msdc_reg_test(struct mmc_host* host, int id)
  577. {
  578. u32 baddr[] = {MSDC0_BASE, MSDC1_BASE, MSDC2_BASE};
  579. u32 base = baddr[id];
  580. u32 i, j, k, l_array_size;
  581. char v , v_r;
  582. int error = MMC_ERR_NONE;
  583. reg_desc_t* msdc_reg_desc;
  584. msdc_reg_desc = msdc0_reg_desc;
  585. l_array_size = ARRAY_SIZE(msdc0_reg_desc);
  586. if (id == 0){
  587. l_array_size = ARRAY_SIZE(msdc0_reg_desc);
  588. msdc_reg_desc = msdc0_reg_desc;
  589. } else if (id == 1){
  590. l_array_size = ARRAY_SIZE(msdc1_reg_desc);
  591. msdc_reg_desc = msdc1_reg_desc;
  592. } else if (id == 2){
  593. l_array_size = ARRAY_SIZE(msdc2_reg_desc);
  594. msdc_reg_desc = msdc2_reg_desc;
  595. } else if (id == 3){
  596. l_array_size = ARRAY_SIZE(msdc3_reg_desc);
  597. msdc_reg_desc = msdc3_reg_desc;
  598. }
  599. /* [r/s/c/k/a] check register reset Value
  600. * by pass the bit which can not read and the bit we don't cara about */
  601. for (i = 0; i < l_array_size; i++) {
  602. for (j = 0; j < 32; j++) {
  603. if (('w' == (msdc_reg_desc[i].attr[j])) ||
  604. ('x' == (msdc_reg_desc[i].attr[j])) ||
  605. ('n' == (msdc_reg_desc[i].attr[j])))
  606. continue;
  607. v = (MSDC_READ32(base + msdc_reg_desc[i].offset) >> j) & 0x1;
  608. if (v != (msdc_reg_desc[i].reset[j] - '0')) {
  609. printf("[SD%d] Invalid Reset Value in 0x%x[%d]=%d != %d\n",
  610. id, base + msdc_reg_desc[i].offset, j, v,
  611. msdc_reg_desc[i].reset[j] - '0');
  612. error = __LINE__;
  613. }
  614. }
  615. }
  616. #if 1
  617. /* [r] check read only register: make sure the bit can not be write */
  618. for (i = 0; i < l_array_size; i++) {
  619. for (j = 0; j < 32; j++) {
  620. if ('r' != (msdc_reg_desc[i].attr[j]))
  621. continue;
  622. v_r =(MSDC_READ32(base + msdc_reg_desc[i].offset) >> j) & 0x1;
  623. if (v_r == 0x0)
  624. MSDC_SET_BIT32(base + msdc_reg_desc[i].offset, 0x1 << j);
  625. else
  626. MSDC_CLR_BIT32(base + msdc_reg_desc[i].offset, 0x1 << j);
  627. v = (MSDC_READ32(base + msdc_reg_desc[i].offset) >> j) & 0x1;
  628. if (v != v_r) {
  629. printf("[SD%d] Read Only Reg Modified in 0x%x[%d]=%d != %d\n",
  630. id, base + msdc_reg_desc[i].offset, j, v, v_r);
  631. error = __LINE__;
  632. }
  633. }
  634. }
  635. #endif
  636. #if 1
  637. /* [a] check write register: set or clear the bit, make sure anther bit will not affected */
  638. for (i = 0; i < l_array_size; i++) {
  639. for (j = 0; j < 32; j++) {
  640. if ('a' != (msdc_reg_desc[i].attr[j]))
  641. continue;
  642. MSDC_SET_BIT32(base + msdc_reg_desc[i].offset, 0x1 << j);
  643. v = (MSDC_READ32(base + msdc_reg_desc[i].offset) >> j) & 0x1;
  644. if (v != 1) {
  645. printf("[SD%d] Write 1 Reg Failed in 0x%x[%d]=%d != %d\n",
  646. id, base + msdc_reg_desc[i].offset, j, v,
  647. msdc_reg_desc[i].reset[j] - '0');
  648. error = __LINE__;
  649. }
  650. #ifndef CLOCK_GATE_TEST
  651. /* exception rule for clock stable */
  652. if (((u32)MSDC_CFG == (base + msdc_reg_desc[i].offset)) &&
  653. (j >= 8 && j < 18)) { /* wait clock stable */
  654. while (!(MSDC_READ32(MSDC_CFG) & MSDC_CFG_CKSTB));
  655. }
  656. #endif
  657. /* check other bits are not affected by write 1 */
  658. for (k = 0; k < 32; k++) {
  659. if (k == j)
  660. continue;
  661. if (('w' == (msdc_reg_desc[i].attr[k])) ||
  662. ('x' == (msdc_reg_desc[i].attr[k])) ||
  663. ('n' == (msdc_reg_desc[i].attr[k])) ||
  664. ('t' == (msdc_reg_desc[i].attr[k])))
  665. continue;
  666. v = (MSDC_READ32(base + msdc_reg_desc[i].offset) >> k) & 0x1;
  667. if (v != (msdc_reg_desc[i].reset[k] - '0')) {
  668. printf("[SD%d] Affected by Write 1 to 0x%x[%d] and [%d]=%d != 1\n",
  669. id, base + msdc_reg_desc[i].offset, j, k, v);
  670. error = __LINE__;
  671. }
  672. }
  673. /* write 0 to target bit */
  674. MSDC_CLR_BIT32(base + msdc_reg_desc[i].offset, 0x1 << j);
  675. v = (MSDC_READ32(base + msdc_reg_desc[i].offset) >> j) & 0x1;
  676. if (v != 0) {
  677. printf("[SD%d] Write 0 Reg Failed in 0x%x[%d]=%d != %d\n",
  678. id, base + msdc_reg_desc[i].offset, j, v,
  679. msdc_reg_desc[i].reset[j] - '0');
  680. error = __LINE__;
  681. }
  682. #ifndef CLOCK_GATE_TEST
  683. /* exception rule for clock stable */
  684. if (((u32)MSDC_CFG == (base + msdc_reg_desc[i].offset)) &&
  685. (j >= 8 && j < 18)) { /* wait clock stable */
  686. while (!(MSDC_READ32(MSDC_CFG) & MSDC_CFG_CKSTB));
  687. }
  688. #endif
  689. /* check other bits are not affected by write 1 */
  690. for (k = 0; k < 32; k++) {
  691. if (k == j)
  692. continue;
  693. if (('w' == (msdc_reg_desc[i].attr[k])) ||
  694. ('x' == (msdc_reg_desc[i].attr[k])) ||
  695. ('t' == (msdc_reg_desc[i].attr[k])))
  696. continue;
  697. v = (MSDC_READ32(base + msdc_reg_desc[i].offset) >> k) & 0x1;
  698. if (v != (msdc_reg_desc[i].reset[k] - '0')) {
  699. printf("[SD%d] Affected by Write 0 to 0x%x[%d] and [%d]=%d != %d\n",
  700. id, base + msdc_reg_desc[i].offset, j, k, v,
  701. msdc_reg_desc[i].reset[k] - '0');
  702. error = __LINE__;
  703. }
  704. }
  705. /* reset to default value */
  706. if ((msdc_reg_desc[i].reset[j] - '0') == 1)
  707. MSDC_SET_BIT32(base + msdc_reg_desc[i].offset, 0x1 << j);
  708. else{
  709. MSDC_CLR_BIT32(base + msdc_reg_desc[i].offset, 0x1 << j);
  710. }
  711. }
  712. }
  713. #endif
  714. /* [z] check AO register, write 1, wait 100ms, check the result */
  715. for (i = 0; i < l_array_size; i++) {
  716. for (j = 0; j < 32; j++) {
  717. if ('z' != (msdc_reg_desc[i].attr[j]))
  718. continue;
  719. MSDC_SET_BIT32(base + msdc_reg_desc[i].offset, 0x1 << j);
  720. mdelay(100);
  721. v =(MSDC_READ32(base + msdc_reg_desc[i].offset) >> j) & 0x1;
  722. if (v != 0) {
  723. printf("[SD%d] write 1, wait change to zero failed. 0x%x[%d]=%d after 100ms when write '1' to this bit\n",
  724. id, base + msdc_reg_desc[i].offset, j, v);
  725. error = __LINE__;
  726. }
  727. }
  728. }
  729. return error;
  730. }
  731. int mmc_readback_blks(int dev_id, unsigned long addr, int blks, int bootarea)
  732. {
  733. int i, j, result = 0;
  734. u8 val;
  735. u8 *ext_csd;
  736. unsigned long blknr = addr / MMC_BLOCK_SIZE;
  737. unsigned char *buf = (unsigned char*)MMC_BUF_ADDR;
  738. struct mmc_card *card;
  739. struct mmc_host *host;
  740. host = mmc_get_host(dev_id);
  741. card = mmc_get_card(dev_id);
  742. ext_csd = &card->raw_ext_csd[0];
  743. if (bootarea && !mmc_card_sd(card)) {
  744. /* configure to specified partition */
  745. val = (ext_csd[EXT_CSD_PART_CFG] & ~0x7) | EXT_CSD_PART_CFG_BOOT_PART_1;
  746. if (mmc_set_part_config(card, val) != MMC_ERR_NONE) {
  747. result = -__LINE__;
  748. goto done;
  749. }
  750. if (mmc_read_ext_csd(host, card) != MMC_ERR_NONE) {
  751. result = -__LINE__;
  752. goto done;
  753. }
  754. }
  755. printf("[SD%d] Dump %d blks from 0x%lx (FLASH)\n", dev_id, blks,
  756. blknr * MMC_BLOCK_SIZE);
  757. for (i = 0; i < blks; i++) {
  758. memset(buf, 0, MMC_BLOCK_SIZE);
  759. if (MMC_ERR_NONE != mmc_block_read(dev_id, blknr + i, 1, (unsigned long*)buf)) {
  760. printf("\n[SD%d] Read from %ldth block error\n", dev_id, blknr + i);
  761. break;
  762. }
  763. for (j = 0; j < MMC_BLOCK_SIZE; j++) {
  764. if (j % 16 == 0)
  765. printf("\n%lxh: ", (blknr + i) * MMC_BLOCK_SIZE + j);
  766. printf("%x ", buf[j]);
  767. }
  768. printf("\n");
  769. buf += MMC_BLOCK_SIZE;
  770. }
  771. done:
  772. if (bootarea && !mmc_card_sd(card)) {
  773. /* configure to user partition */
  774. val = (ext_csd[EXT_CSD_PART_CFG] & ~0x7) | EXT_CSD_PART_CFG_DEFT_PART;
  775. if (mmc_set_part_config(card, val) != MMC_ERR_NONE)
  776. result = -__LINE__;
  777. if (mmc_read_ext_csd(host, card) != MMC_ERR_NONE) {
  778. result = -__LINE__;
  779. }
  780. }
  781. return result;
  782. }
  783. #if 0
  784. int mmc_readback_part(int dev_id, char *part_name, int bootarea)
  785. {
  786. int ret = -1;
  787. part_t *part = mt6573_part_get_partition(part_name);
  788. if (part) {
  789. ret = mmc_readback_blks(dev_id, part->startblk * BLK_SIZE,
  790. 1, bootarea);
  791. }
  792. return ret;
  793. }
  794. #endif
  795. int mmc_erase_blks(int dev_id, u32 addr, u32 size, int bootarea)
  796. {
  797. int result = 0;
  798. u8 val;
  799. u8 *ext_csd;
  800. u32 blknr;
  801. u32 total_blks;
  802. struct mmc_card *card;
  803. if (!size)
  804. return 0;
  805. if (addr % MMC_BLOCK_SIZE)
  806. return MMC_ERR_FAILED;
  807. card = mmc_get_card(dev_id);
  808. ext_csd = &card->raw_ext_csd[0];
  809. blknr = addr / MMC_BLOCK_SIZE;
  810. total_blks = (size + MMC_BLOCK_SIZE - 1) / MMC_BLOCK_SIZE;
  811. if (bootarea && !mmc_card_sd(card) && card->ext_csd.part_en) {
  812. /* configure to specified partition */
  813. val = (ext_csd[EXT_CSD_PART_CFG] & ~0x7) | EXT_CSD_PART_CFG_BOOT_PART_1;
  814. if (mmc_set_part_config(card, val) != MMC_ERR_NONE) {
  815. result = -__LINE__;
  816. goto done;
  817. }
  818. }
  819. if (mmc_erase_start(card, blknr * MMC_BLOCK_SIZE) != MMC_ERR_NONE) {
  820. result = -__LINE__;
  821. goto done;
  822. }
  823. if (mmc_erase_end(card, (blknr + total_blks) * MMC_BLOCK_SIZE) != MMC_ERR_NONE) {
  824. result = -__LINE__;
  825. goto done;
  826. }
  827. if (mmc_erase(card, MMC_ERASE_NORMAL) != MMC_ERR_NONE) {
  828. result = -__LINE__;
  829. goto done;
  830. }
  831. done:
  832. if (bootarea && !mmc_card_sd(card) && card->ext_csd.part_en) {
  833. /* configure to user partition */
  834. val = (ext_csd[EXT_CSD_PART_CFG] & ~0x7) | EXT_CSD_PART_CFG_DEFT_PART;
  835. if (mmc_set_part_config(card, val) != MMC_ERR_NONE)
  836. result = -__LINE__;
  837. }
  838. if (!result) {
  839. printf("[SD%d] Erase %d blocks (%d bytes) from 0x%x successfully\n",
  840. dev_id, total_blks, total_blks * MMC_BLOCK_SIZE, blknr * MMC_BLOCK_SIZE);
  841. } else {
  842. printf("[SD%d] Erase %d blocks (%d bytes) from 0x%x failed %d\n",
  843. dev_id, total_blks, total_blks * MMC_BLOCK_SIZE, blknr * MMC_BLOCK_SIZE, result);
  844. }
  845. return result;
  846. }
  847. #if 0
  848. int mmc_erase_part(int dev_id, char *part_name, int bootarea)
  849. {
  850. int ret = -1;
  851. part_t *part = mt6573_part_get_partition(part_name);
  852. if (part) {
  853. /* Notice that the block size is different with different emmc.
  854. * Thus, it could overwrite other partitions while erasing data.
  855. */
  856. ret = mmc_erase_blks(dev_id, part->startblk * BLK_SIZE,
  857. part->blknum * BLK_SIZE, bootarea);
  858. }
  859. return ret;
  860. }
  861. #endif
  862. #ifdef MMC_BOOT_TEST
  863. int mmc_boot_up_test(int id, int reset)
  864. {
  865. int err = MMC_ERR_FAILED;
  866. struct mmc_host *host;
  867. host = mmc_get_host(id);
  868. mmc_init_host(host, id);
  869. msdc_emmc_boot_reset(host, reset);
  870. err = msdc_emmc_boot_start(host, 25000000, 0, EMMC_BOOT_RST_CMD_MODE, (u64)0);
  871. if (err) {
  872. printf("[EMMC] Boot Error: %d\n", err);
  873. goto done;
  874. }
  875. err = msdc_emmc_boot_read(host, (u64)128 * 1024, MMC_BUF_ADDR);
  876. msdc_emmc_boot_stop(host);
  877. done:
  878. if (!err) {
  879. int i, j;
  880. char *buf = (char*)MMC_BUF_ADDR;
  881. for (i = 0; i < 16; i++) {
  882. for (j = 0; j < MMC_BLOCK_SIZE; j++) {
  883. if (j % 16 == 0)
  884. printf("\n%.8xh: ", i * MMC_BLOCK_SIZE + j);
  885. printf("%.2x ", buf[j]);
  886. }
  887. printf("\n");
  888. buf += MMC_BLOCK_SIZE;
  889. }
  890. }
  891. return err;
  892. }
  893. int mmc_boot_enable(int id, int bootpart)
  894. {
  895. int err = MMC_ERR_FAILED;
  896. struct mmc_host *host;
  897. struct mmc_card *card;
  898. host = mmc_get_host(id);
  899. card = mmc_get_card(id);
  900. err = mmc_boot_config(card, EXT_CSD_PART_CFG_EN_ACK,
  901. bootpart, EXT_CSD_BOOT_BUS_WIDTH_1, EXT_CSD_BOOT_BUS_MODE_DEFT);
  902. if (err != 0)
  903. goto done;
  904. err = mmc_read_ext_csd(host, card);
  905. done:
  906. return err;
  907. }
  908. #endif
  909. int mmc_test_dump_buff(char *buffer,int index,int buf_size)
  910. {
  911. int start_index = index - 256 > 0 ? index-256:0;
  912. int end_index = index + 256 < buf_size ? index + 256 : buf_size;
  913. int i = 0;
  914. printf("dump error buffer\n");
  915. for(;i < end_index - start_index;i++){
  916. if(i%8 == 0)
  917. printf("\n");
  918. printf("0x%x ",buffer[start_index+i]);
  919. }
  920. return 0;
  921. }
  922. int indata = 0;
  923. int mmc_test_mem_card(struct mmc_test_config *cfg)
  924. {
  925. int id, count, forever;
  926. int ret, chk_result, tid = 0, result = 0;
  927. unsigned int chunks, chunk_blks, left_blks, pass = 0, fail = 0;
  928. unsigned int total_blks;
  929. unsigned int i, j;
  930. unsigned int blksz;
  931. unsigned int clkhz;
  932. unsigned int status;
  933. //unsigned int base;
  934. char pattern = 0;
  935. char *buf;
  936. unsigned long blknr;
  937. struct mmc_host *host;
  938. struct mmc_card *card;
  939. id = cfg->id;
  940. count = cfg->count;
  941. buf = cfg->buf;
  942. blknr = cfg->blknr;
  943. blksz = cfg->blksz;
  944. chk_result = cfg->chk_result;
  945. chunk_blks = cfg->chunk_blks;
  946. total_blks = (cfg->total_size + blksz - 1) / blksz;
  947. forever = (count == -1) ? 1 : 0;
  948. host = mmc_get_host(id);
  949. card = mmc_get_card(id);
  950. while (forever || count--) {
  951. printf("[TST] ==============================================\n");
  952. printf("[TST] read/write buf address : 0x%x\n", (unsigned int)buf);
  953. printf("[TST] BEGIN: %d/%d, No Stop(%d)\n",
  954. (cfg->count != -1) ? cfg->count - count : 0,
  955. (cfg->count != -1) ? cfg->count : 0, forever);
  956. printf("[TST] ----------------------------------------------\n");
  957. printf("[TST] Mode : %d\n", cfg->mode);
  958. printf("[TST] Clock : %d kHz\n", cfg->clock / 1000);
  959. printf("[TST] BusWidth: %d bits\n", cfg->buswidth);
  960. printf("[TST] DDR : %d \n", (msdc_cap[id].flags & MSDC_DDR)? 1:0);
  961. printf("[TST] BurstSz : %d bytes\n", 0x1 << cfg->burstsz);
  962. printf("[TST] BlkAddr : %lxh\n", blknr);
  963. printf("[TST] BlkSize : %dbytes\n", blksz);
  964. printf("[TST] TstBlks : %d\n", total_blks);
  965. printf("[TST] AutoCMD : 12(%d), 23(%d)\n",
  966. (cfg->autocmd & MSDC_AUTOCMD12) ? 1 : 0,
  967. (cfg->autocmd & MSDC_AUTOCMD23) ? 1 : 0);
  968. printf("[TST] CheckResult : %d\n", cfg->chk_result);
  969. printf("[TST] ----------------------------------------------\n");
  970. indata= 0;
  971. if (mmc_init_host(host, id, cfg->clksrc, cfg->mode) != 0) {
  972. result = -__LINE__;
  973. goto failure;
  974. }
  975. if (mmc_init_card(host, card) != 0) {
  976. result = -__LINE__;
  977. goto failure;
  978. }
  979. msdc_set_dma(host, (u8)cfg->burstsz, (u32)cfg->flags);
  980. msdc_set_autocmd(host, cfg->autocmd, 1);
  981. /* change uhs-1 mode */
  982. #if 0
  983. if (mmc_card_uhs1(card)) {
  984. if (mmc_switch_uhs1(host, card, cfg->uhsmode) != 0) {
  985. result = -__LINE__;
  986. goto failure;
  987. }
  988. }
  989. #endif
  990. /* change clock */
  991. printf("card->maxhz(%d), cfg->clock(%d)\n",card->maxhz,cfg->clock);
  992. if (cfg->clock) {
  993. clkhz = card->maxhz < cfg->clock ? card->maxhz : cfg->clock;
  994. mmc_set_clock(host, mmc_card_ddr(card), clkhz);
  995. }
  996. printf("host->src_clk(%d)\n",host->src_clk);
  997. if (mmc_card_sd(card) && cfg->buswidth == HOST_BUS_WIDTH_8) {
  998. printf("[TST] SD card doesn't support 8-bit bus width (SKIP)\n");
  999. result = MMC_ERR_NONE;
  1000. }
  1001. printf("cfg->buswidth(%d)\n",cfg->buswidth);
  1002. if (mmc_set_bus_width(host, card, cfg->buswidth) != 0) {
  1003. result = -__LINE__;
  1004. goto failure;
  1005. }
  1006. /* cmd16 is illegal while card is in ddr mode */
  1007. if (!(mmc_card_mmc(card) && (mmc_card_ddr(card) || mmc_card_hs400(card)))) {
  1008. if (mmc_set_blk_length(host, blksz) != 0) {
  1009. result = -__LINE__;
  1010. goto failure;
  1011. }
  1012. }
  1013. tid = result = 0;
  1014. //printf("host->sclk(%d)\n",host->sclk);
  1015. if (cfg->piobits) {
  1016. printf("[TST] PIO bits: %d\n", cfg->piobits);
  1017. msdc_set_pio_bits(host, cfg->piobits);
  1018. }
  1019. //printf("host->sclk(%d)\n",host->sclk);
  1020. /* show the init test condition, its useful for debug */
  1021. //base = host->base;
  1022. //MSDC_WRITE32(MSDC_PATCH_BIT1, 0xFFFE00C9); /* 2013-1-6 close KPI for e2 eco verify */
  1023. //msdc_dump_register(host);
  1024. if (cfg->start_bit) {
  1025. printf("start bit=%d\n", (cfg->start_bit - 1));
  1026. msdc_set_startbit(host,(cfg->start_bit - 1));
  1027. }
  1028. if (cfg->axi_burst_len) {
  1029. printf("axi_burst_len=%d\n", (cfg->axi_burst_len - 1));
  1030. msdc_set_axi_burst_len(host,(cfg->axi_burst_len - 1));
  1031. }
  1032. if (cfg->axi_rd_os) {
  1033. printf("axi_rd_os=%d\n", (cfg->axi_rd_os));
  1034. msdc_set_axi_outstanding(host, 0, (cfg->axi_rd_os));
  1035. }
  1036. if (cfg->axi_wr_os) {
  1037. printf("axi_wr_os=%d\n", (cfg->axi_wr_os));
  1038. msdc_set_axi_outstanding(host, 1, (cfg->axi_wr_os));
  1039. }
  1040. tid = result = 0;
  1041. #if 0 //UT only, change as if 0 temporarily
  1042. if (mmc_erase_start(card, blknr * blksz) != MMC_ERR_NONE) {
  1043. result = -__LINE__;
  1044. goto failure;
  1045. }
  1046. if (mmc_erase_end(card, (blknr + total_blks) * blksz) != MMC_ERR_NONE) {
  1047. result = -__LINE__;
  1048. goto failure;
  1049. }
  1050. if (mmc_erase(card, MMC_ERASE_NORMAL) != MMC_ERR_NONE) {
  1051. result = -__LINE__;
  1052. goto failure;
  1053. }
  1054. printf("[TST] 0x%x - 0x%x Erased\n", blknr * blksz,
  1055. (blknr + total_blks) * blksz);
  1056. printf("host->sclk(%d)\n",host->sclk);
  1057. printf(TC_MSG, host->id, result == 0 ? "PASS" : "FAIL", tid++,
  1058. "test block erase\n");
  1059. #endif
  1060. mmc_send_status(host, card, &status);
  1061. if (cfg->tst_single) {
  1062. indata = 1;
  1063. #if 1
  1064. /* single block write */
  1065. for (i = 0; i < total_blks; i++) {
  1066. pattern = (i + count + 1) % 256;
  1067. memset(buf, pattern, blksz);
  1068. #if 0 // dump the write buf
  1069. printf("the %d block data in write buf\n", i);
  1070. for (j = 0; j < blksz; j++) {
  1071. printf("0x%x ", buf[j]);
  1072. if((j+1)%8 == 0)
  1073. printf("\n");
  1074. }
  1075. #endif
  1076. ret = mmc_block_write(id, blknr + i, 1, (unsigned long*)buf);
  1077. if (ret != MMC_ERR_NONE) {
  1078. printf("test single block write failed (%d)\n", i);
  1079. result = -__LINE__;
  1080. goto failure;
  1081. }
  1082. }
  1083. printf(TC_MSG, host->id, result == 0 ? "PASS" : "FAIL", tid++,
  1084. "test single block write\n");
  1085. if (result)
  1086. break;
  1087. #endif
  1088. #if 1
  1089. /* single block read */
  1090. for (i = 0; i < total_blks && !result; i++) {
  1091. pattern = (i + count + 1) % 256;
  1092. memset(buf, pattern + 1, blksz);
  1093. ret = mmc_block_read(id, blknr + i, 1, (unsigned long*)buf);
  1094. if (ret != MMC_ERR_NONE) {
  1095. result = -__LINE__;
  1096. goto failure;
  1097. }
  1098. if (chk_result) {
  1099. for (j = 0; j < blksz; j++) {
  1100. if (buf[j] != pattern) {
  1101. printf("compare,i=%d, j=%d, buf[j]=%d, pattern(%d), buf(0x%x)\n", i, j, buf[j], pattern, (unsigned int)buf);
  1102. mmc_test_dump_buff(buf,j,blksz);
  1103. result = -__LINE__;
  1104. goto failure;
  1105. }
  1106. }
  1107. }
  1108. }
  1109. printf(TC_MSG, host->id, result == 0 ? "PASS" : "FAIL", tid++,
  1110. "test single block read\n");
  1111. if (result) {
  1112. printf("[SD%d]\t\tread back pattern(0x%.2x) failed\n",
  1113. id, pattern);
  1114. goto failure;
  1115. }
  1116. #endif
  1117. }
  1118. mmc_send_status(host, card, &status);
  1119. #if 0 // Change mode
  1120. mmc_card_clear_hs400(card);
  1121. mmc_card_clear_ddr(card);
  1122. mmc_switch(host, card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_8);
  1123. mmc_switch(host, card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, 2);
  1124. printf("[SD0] HS400 change to HS200 TC41 \n");
  1125. if (cfg->clock) {
  1126. clkhz = card->maxhz < cfg->clock ? card->maxhz : cfg->clock;
  1127. //msdc_config_clksrc(host, 6); // Change clock source to 200Mzh
  1128. mmc_set_clock(host,card->state, clkhz);
  1129. }
  1130. #endif
  1131. if (cfg->tst_multiple) {
  1132. /* multiple block write */
  1133. chunks = total_blks / chunk_blks;
  1134. left_blks = total_blks % chunk_blks;
  1135. //printf("total_blks(%d),chunks(%d),left_blks(%d)\n",total_blks,chunks,left_blks);
  1136. #if 1
  1137. for (i = 0; i < chunks; i++) {
  1138. pattern = (i + count) % 256;
  1139. memset(buf, pattern, blksz * chunk_blks);
  1140. ret = mmc_block_write(id, blknr + i * chunk_blks,
  1141. chunk_blks, (unsigned long*)buf);
  1142. if (ret != MMC_ERR_NONE) {
  1143. result = -__LINE__;
  1144. goto failure;
  1145. }
  1146. }
  1147. if (!result && left_blks) {
  1148. pattern = (i + count) % 256;
  1149. memset(buf, pattern, blksz * left_blks);
  1150. ret = mmc_block_write(id, blknr + chunks * chunk_blks,
  1151. left_blks, (unsigned long*)buf);
  1152. if (ret != MMC_ERR_NONE) {
  1153. result = -__LINE__;
  1154. goto failure;
  1155. }
  1156. }
  1157. printf(TC_MSG, host->id, result == 0 ? "PASS" : "FAIL", tid++,
  1158. "test multiple block write\n");
  1159. if (result)
  1160. goto failure;
  1161. #endif
  1162. #if 1
  1163. /* multiple block read */
  1164. for (i = 0; i < chunks; i++) {
  1165. pattern = (i + count) % 256;
  1166. memset(buf, pattern + 1, blksz * chunk_blks);
  1167. ret = mmc_block_read(id, blknr + i * chunk_blks,
  1168. chunk_blks, (unsigned long*)buf);
  1169. if (ret != MMC_ERR_NONE) {
  1170. printf("[SD%d]\t\tread %d blks failed(ret = %d blks), buf(0x%x)\n",
  1171. host->id, chunk_blks, ret, (unsigned int)buf);
  1172. result = -__LINE__;
  1173. goto failure;
  1174. }
  1175. if (chk_result) {
  1176. for (j = 0; j < chunk_blks * blksz; j++) {
  1177. if (buf[j] == pattern)
  1178. continue;
  1179. result = -__LINE__;
  1180. printf("[SD%d]\t\t%lxh = %x (!= %x)\n",
  1181. host->id, blknr + i * chunk_blks, buf[j], pattern);
  1182. printf("j(%d),buf[j](%d),pattern(%d)\n",j,buf[j],pattern);
  1183. printf("dump read value at addr0x%x", (unsigned int)(buf + j));
  1184. mmc_test_dump_buff(buf,j,chunk_blks * blksz);
  1185. printf("dump write value at addr0x%x", (unsigned int)(buf + j));
  1186. mmc_test_dump_buff(buf,j,chunk_blks * blksz);
  1187. goto failure;
  1188. }
  1189. }
  1190. }
  1191. if (!result && left_blks) {
  1192. pattern = (i + count) % 256;
  1193. memset(buf, pattern + 1, blksz * left_blks);
  1194. ret = mmc_block_read(id, blknr + chunks * chunk_blks,
  1195. left_blks, (unsigned long*)buf);
  1196. if (ret != MMC_ERR_NONE) {
  1197. printf("[SD%d]\t\tread %d blks failed(ret = %d blks)\n",
  1198. host->id, left_blks, ret);
  1199. result = -__LINE__;
  1200. goto failure;
  1201. }
  1202. if (chk_result) {
  1203. for (j = 0; j < left_blks * blksz; j++) {
  1204. if (buf[j] == pattern)
  1205. continue;
  1206. printf("[SD%d]\t\t%lxh = %x (!= %x),j(%d)\n",
  1207. host->id, blknr + chunks * chunk_blks, buf[j], pattern,j);
  1208. printf("j(%d),buf[j](%d),pattern(%d)\n",j,buf[j],pattern);
  1209. printf("dump read value at addr0x%x", (unsigned int)(buf + j));
  1210. mmc_test_dump_buff(buf,j,chunk_blks * blksz);
  1211. printf("dump write value at addr0x%x", (unsigned int)(buf + j));
  1212. mmc_test_dump_buff(buf,j,chunk_blks * blksz);
  1213. result = -__LINE__;
  1214. goto failure;
  1215. }
  1216. }
  1217. }
  1218. printf(TC_MSG, host->id, result == 0 ? "PASS" : "FAIL", tid++,
  1219. "test multiple block read\n");
  1220. if (result)
  1221. goto failure;
  1222. #endif
  1223. }
  1224. mmc_send_status(host, card, &status);
  1225. #if 1
  1226. if (cfg->tst_interleave) {
  1227. /* multiple block write */
  1228. chunks = total_blks / chunk_blks;
  1229. left_blks = total_blks % chunk_blks;
  1230. for (i = 0; i < chunks; i++) {
  1231. pattern = (i + count) % 256;
  1232. memset(buf, pattern, blksz * chunk_blks);
  1233. ret = mmc_block_write(id, blknr + i * chunk_blks,
  1234. chunk_blks, (unsigned long*)buf);
  1235. if (ret != MMC_ERR_NONE) {
  1236. result = -__LINE__;
  1237. goto failure;
  1238. }
  1239. /* populate buffer with different pattern */
  1240. memset(buf, pattern + 1, blksz * chunk_blks);
  1241. ret = mmc_block_read(id, blknr + i * chunk_blks,
  1242. chunk_blks, (unsigned long*)buf);
  1243. if (ret != MMC_ERR_NONE) {
  1244. result = -__LINE__;
  1245. goto failure;
  1246. }
  1247. if (chk_result) {
  1248. for (j = 0; j < chunk_blks * blksz; j++) {
  1249. if (buf[j] == pattern)
  1250. continue;
  1251. printf("[SD%d]\t\t%lxh = %x (!= %x),j(%d)\n",
  1252. host->id, blknr + i * chunk_blks, buf[j], pattern,j);
  1253. printf("j(%d),buf[j](%d),pattern(%d)\n",j,buf[j],pattern);
  1254. mmc_test_dump_buff(buf,j,chunk_blks * blksz);
  1255. result = -__LINE__;
  1256. goto failure;
  1257. }
  1258. }
  1259. }
  1260. if (!result && left_blks) {
  1261. pattern = (i + count) % 256;
  1262. memset(buf, pattern, blksz * left_blks);
  1263. ret = mmc_block_write(id, blknr + chunks * chunk_blks,
  1264. left_blks, (unsigned long*)buf);
  1265. if (ret != MMC_ERR_NONE) {
  1266. result = -__LINE__;
  1267. goto failure;
  1268. }
  1269. /* populate buffer with different pattern */
  1270. memset(buf, pattern + 1, blksz * left_blks);
  1271. ret = mmc_block_read(id, blknr + chunks * chunk_blks,
  1272. left_blks, (unsigned long*)buf);
  1273. if (ret != MMC_ERR_NONE) {
  1274. result = -__LINE__;
  1275. break;
  1276. }
  1277. if (chk_result) {
  1278. for (j = 0; j < left_blks * blksz; j++) {
  1279. if (buf[j] == pattern)
  1280. continue;
  1281. printf("[SD%d]\t\t%lxh = %x (!= %x),j(%d)\n",
  1282. host->id, blknr + chunks * chunk_blks, buf[j], pattern,j);
  1283. printf("j(%d),buf[j](%d),pattern(%d)\n",j,buf[j],pattern);
  1284. mmc_test_dump_buff(buf,j,left_blks * blksz);
  1285. result = -__LINE__;
  1286. goto failure;
  1287. }
  1288. }
  1289. }
  1290. printf(TC_MSG, host->id, result == 0 ? "PASS" : "FAIL", tid++,
  1291. "test multiple block interleave write-read\n");
  1292. if (result)
  1293. goto failure;
  1294. }
  1295. #endif
  1296. if (cfg->desc) {
  1297. printf("[TST] ----------------------------------------------\n");
  1298. printf("[TST] Report - %s \n", cfg->desc);
  1299. printf("[TST] ----------------------------------------------\n");
  1300. }
  1301. mmc_prof_dump(id);
  1302. failure:
  1303. if (result) {
  1304. printf("[SD%d] mmc test failed (%d)\n", host->id, result);
  1305. fail++;
  1306. } else {
  1307. pass++;
  1308. }
  1309. printf("[TST] ----------------------------------------------\n");
  1310. printf("[TST] Test Result: TOTAL(%d/%d), PASS(%d), FAIL(%d) \n",
  1311. cfg->count - count, cfg->count, pass, fail);
  1312. printf("[TST] ----------------------------------------------\n");
  1313. //mdelay(1000);
  1314. }
  1315. return result;
  1316. }
  1317. #if 0
  1318. #define MSDC_NO_USE_RANDOM_TEST_PATTERN (1)
  1319. int mmc_test_mem_card(struct mmc_test_config *cfg)
  1320. {
  1321. int id, count, forever;
  1322. int ret, chk_result, tid = 0, result = 0;
  1323. unsigned int chunks, chunk_blks, left_blks, pass = 0, fail = 0;
  1324. unsigned int total_blks;
  1325. unsigned int i, j;
  1326. unsigned int blksz;
  1327. unsigned int clkhz;
  1328. unsigned int status;
  1329. unsigned int base;
  1330. char pattern = 0;
  1331. char *buf;
  1332. unsigned long blknr;
  1333. struct mmc_host *host;
  1334. struct mmc_card *card;
  1335. #if (0 == MSDC_NO_USE_RANDOM_TEST_PATTERN)
  1336. u32 k, l_low_tick0, l_high_tick0;
  1337. #endif
  1338. id = cfg->id;
  1339. count = cfg->count;
  1340. buf = cfg->buf;
  1341. blknr = cfg->blknr;
  1342. blksz = cfg->blksz;
  1343. chk_result = cfg->chk_result;
  1344. chunk_blks = cfg->chunk_blks;
  1345. total_blks = (cfg->total_size + blksz - 1) / blksz;
  1346. forever = (count == -1) ? 1 : 0;
  1347. host = mmc_get_host(id);
  1348. card = mmc_get_card(id);
  1349. while (forever || count--) {
  1350. printf("[TST] ==============================================\n");
  1351. printf("[TST]buf address : 0x%x\n",buf);
  1352. printf("[TST] BEGIN: %d/%d, No Stop(%d)\n",
  1353. (cfg->count != -1) ? cfg->count - count : 0,
  1354. (cfg->count != -1) ? cfg->count : 0, forever);
  1355. printf("[TST] ----------------------------------------------\n");
  1356. printf("[TST] Clock : %d kHz\n", cfg->clock / 1000);
  1357. printf("[TST] BusWidth: %d bits\n", cfg->buswidth);
  1358. printf("[TST] BurstSz : %d bytes\n", 0x1 << cfg->burstsz);
  1359. printf("[TST] BlkAddr : %xh\n", blknr);
  1360. printf("[TST] BlkSize : %dbytes\n", blksz);
  1361. printf("[TST] TstBlks : %d\n", total_blks);
  1362. printf("[TST] AutoCMD : 12(%d), 23(%d)\n",
  1363. (cfg->autocmd & MSDC_AUTOCMD12) ? 1 : 0,
  1364. (cfg->autocmd & MSDC_AUTOCMD23) ? 1 : 0);
  1365. printf("[TST] CheckResult : %d\n", cfg->chk_result);
  1366. printf("[TST] ----------------------------------------------\n");
  1367. if (mmc_init_host(id, host, cfg->clksrc, cfg->mode) != 0) {
  1368. result = -__LINE__;
  1369. goto failure;
  1370. }
  1371. //#if (1 == (MSDC_USE_SD30_USH50 || MSDC_USE_SD30_USH104))
  1372. if (cfg->clock > 100000000) {
  1373. host->f_max = MSDC_208M_SCLK;
  1374. } else if (cfg->clock <= 100000000 && cfg->clock > 50000000) {
  1375. host->f_max = MSDC_100M_SCLK;
  1376. } else if (cfg->clock <= 50000000 && cfg->clock > 25000000) {
  1377. host->f_max = MSDC_50M_SCLK;
  1378. } else {
  1379. host->f_max = MSDC_25M_SCLK;
  1380. }
  1381. //#endif /* end of MSDC_USE_SD30_USH50 || MSDC_USE_SD30_USH104 */
  1382. if (mmc_init_card(host, card) != 0) {
  1383. result = -__LINE__;
  1384. goto failure;
  1385. }
  1386. msdc_set_dma(host, (u8)cfg->burstsz, (u32)cfg->flags);
  1387. msdc_set_autocmd(host, cfg->autocmd, 1);
  1388. /* change clock */
  1389. printf("host->sclk(%d), card->maxhz(%d), cfg->clock(%d)\n",host->sclk, card->maxhz, cfg->clock);
  1390. if (cfg->clock) {
  1391. clkhz = card->maxhz < cfg->clock ? card->maxhz : cfg->clock;
  1392. mmc_set_clock(host, card->state, clkhz);
  1393. }
  1394. printf("host->sclk(%d)\n",host->sclk);
  1395. if (mmc_card_sd(card) && cfg->buswidth == HOST_BUS_WIDTH_8) {
  1396. printf("[TST] SD card doesn't support 8-bit bus width (SKIP)\n");
  1397. result = MMC_ERR_NONE;
  1398. }
  1399. printf("cfg->buswidth(%d)\n",cfg->buswidth);
  1400. if (mmc_set_bus_width(host, card, cfg->buswidth) != 0) {
  1401. result = -__LINE__;
  1402. goto failure;
  1403. }
  1404. /* cmd16 is illegal while card is in ddr mode */
  1405. if (!(mmc_card_mmc(card) && (mmc_card_ddr(card)|| mmc_card_hs400(card)))) {
  1406. if (mmc_set_blk_length(host, blksz) != 0) {
  1407. result = -__LINE__;
  1408. goto failure;
  1409. }
  1410. }
  1411. if (cfg->piobits) {
  1412. printf("[TST] PIO bits: %d\n", cfg->piobits);
  1413. msdc_set_pio_bits(host, cfg->piobits);
  1414. }
  1415. //printf("host->sclk(%d)\n",host->sclk);
  1416. #if 0
  1417. //#if (1 == MSDC_USE_SD30)
  1418. /* change uhs-1 mode, switch will failed, but don't know why? */
  1419. if (mmc_card_uhs1(card)) {
  1420. if (mmc_switch_uhs1(host, card, cfg->uhsmode) != 0) {
  1421. result = -__LINE__;
  1422. goto failure;
  1423. }
  1424. }
  1425. mmc_send_status(host, card, &status);
  1426. #endif
  1427. /* show the init test condition, its useful for debug */
  1428. base = host->base;
  1429. MSDC_WRITE32(MSDC_PATCH_BIT1, 0xFFFE00C9); /* 2013-1-6 close KPI for e2 eco verify */
  1430. msdc_dump_register(host);
  1431. tid = result = 0;
  1432. if (mmc_erase_start(card, blknr * blksz) != MMC_ERR_NONE) {
  1433. result = -__LINE__;
  1434. goto failure;
  1435. }
  1436. if (mmc_erase_end(card, (blknr + total_blks) * blksz) != MMC_ERR_NONE) {
  1437. result = -__LINE__;
  1438. goto failure;
  1439. }
  1440. if (mmc_erase(card, MMC_ERASE_NORMAL) != MMC_ERR_NONE) {
  1441. result = -__LINE__;
  1442. goto failure;
  1443. }
  1444. printf("[TST] 0x%x - 0x%x Erased\n", blknr * blksz, (blknr + total_blks) * blksz);
  1445. mmc_send_status(host, card, &status);
  1446. if (cfg->tst_single) {
  1447. /* single block write */
  1448. for (i = 0; i < total_blks; i++) {
  1449. #if (1 == MSDC_NO_USE_RANDOM_TEST_PATTERN)
  1450. #ifdef MSDC_USE_FIXED_PATTERN1
  1451. pattern = (i + count + 1) % 256;
  1452. #endif /* end of MSDC_USE_FIXED_PATTERN1 */
  1453. #ifdef MSDC_USE_FIXED_PATTERN2
  1454. pattern = MSDC_TEST_PATTERN;
  1455. #endif /* end of MSDC_USE_FIXED_PATTERN2 */
  1456. memset(buf, pattern, blksz);
  1457. #else
  1458. for (k = 0; k < blksz; k++){
  1459. /* random pattern */
  1460. l_low_tick0 = GPT_GetTickCount(&l_high_tick0);
  1461. buf[k] = (l_low_tick0 + i + k) % 255;
  1462. sg_wbuf_single[i][k] = buf[k];
  1463. //printf("0x%x ", buf[k]);
  1464. //if ((k % 32) == 0)
  1465. //printf("\n");
  1466. }
  1467. #endif /* end of MSDC_NO_USE_RANDOM_TEST_PATTERN */
  1468. //printf("signal block write: 0x%x\n", blknr + i);
  1469. ret = mmc_block_write(id, blknr + i, 1, (unsigned long*)buf);
  1470. if (ret != MMC_ERR_NONE) {
  1471. printf("test single block write failed (%d)\n", i);
  1472. result = -__LINE__;
  1473. goto failure;
  1474. }
  1475. }
  1476. printf(TC_MSG, host->id, result == 0 ? "PASS" : "FAIL", tid++,
  1477. "test single block write\n");
  1478. if (result)
  1479. break;
  1480. /* single block read */
  1481. for (i = 0; i < total_blks && !result; i++) {
  1482. #if (1 == MSDC_NO_USE_RANDOM_TEST_PATTERN)
  1483. #ifdef MSDC_USE_FIXED_PATTERN1
  1484. pattern = (i + count + 1) % 256;
  1485. #endif /* end of MSDC_USE_FIXED_PATTERN1 */
  1486. #ifdef MSDC_USE_FIXED_PATTERN2
  1487. pattern = MSDC_TEST_PATTERN;
  1488. #endif /* end of MSDC_USE_FIXED_PATTERN2 */
  1489. #endif /* end of MSDC_NO_USE_RANDOM_TEST_PATTERN */
  1490. memset(buf, 0, blksz);
  1491. //printf("signal block read: 0x%x\n", blknr + i);
  1492. ret = mmc_block_read(id, blknr + i, 1, (unsigned long*)buf);
  1493. if (ret != MMC_ERR_NONE) {
  1494. result = -__LINE__;
  1495. goto failure;
  1496. }
  1497. if (chk_result) {
  1498. for (j = 0; j < blksz; j++) {
  1499. #if (1 == MSDC_NO_USE_RANDOM_TEST_PATTERN)
  1500. if (buf[j] != pattern) {
  1501. printf("ops:0x%x j(%d),buf[j](%d),pattern(%d)\n", blknr + i, j, buf[j], pattern);
  1502. #else
  1503. if (buf[j] != sg_wbuf_single[i][j]){
  1504. printf("ops:0x%x j(%d),buf[j](%d),pattern(%d)\n", blknr + i, j, buf[j], sg_wbuf_single[i][j]);
  1505. #endif
  1506. mmc_test_dump_buff(buf, j, blksz);
  1507. result = -__LINE__;
  1508. goto failure;
  1509. }
  1510. }
  1511. }
  1512. }
  1513. printf(TC_MSG, host->id, result == 0 ? "PASS" : "FAIL", tid++,
  1514. "test single block read\n");
  1515. if (result) {
  1516. printf("[SD%d]\t\tread back pattern(0x%.2x) failed\n",
  1517. id, pattern);
  1518. goto failure;
  1519. }
  1520. }
  1521. mmc_send_status(host, card, &status);
  1522. if (cfg->tst_multiple) {
  1523. /* multiple block write */
  1524. chunks = total_blks / chunk_blks;
  1525. left_blks = total_blks % chunk_blks;
  1526. //printf("total_blks(%d),chunks(%d),left_blks(%d)\n",total_blks,chunks,left_blks);
  1527. for (i = 0; i < chunks; i++) {
  1528. #if (1 == MSDC_NO_USE_RANDOM_TEST_PATTERN)
  1529. #ifdef MSDC_USE_FIXED_PATTERN1
  1530. pattern = (i + count + 1) % 256;
  1531. #endif /* end of MSDC_USE_FIXED_PATTERN1 */
  1532. #ifdef MSDC_USE_FIXED_PATTERN2
  1533. pattern = MSDC_TEST_PATTERN;
  1534. #endif /* end of MSDC_USE_FIXED_PATTERN2 */
  1535. memset(buf, pattern, blksz * chunk_blks);
  1536. #else
  1537. for (k = 0; k < blksz * chunk_blks; k++){
  1538. /* random pattern */
  1539. l_low_tick0 = GPT_GetTickCount(&l_high_tick0);
  1540. buf[k] = (l_low_tick0 + i + k) % 255;
  1541. sg_wbuf_multi[i][k] = buf[k];
  1542. //printf("0x%x ", buf[k]);
  1543. //if ((k % 32) == 0)
  1544. //printf("\n");
  1545. }
  1546. #endif /* end of MSDC_NO_USE_RANDOM_TEST_PATTERN */
  1547. //printf("multi block write: 0x%x\n(%d)", blknr + i* chunk_blks, chunk_blks);
  1548. ret = mmc_block_write(id, blknr + i * chunk_blks,
  1549. chunk_blks, (unsigned long*)buf);
  1550. if (ret != MMC_ERR_NONE) {
  1551. result = -__LINE__;
  1552. goto failure;
  1553. }
  1554. }
  1555. if (!result && left_blks) {
  1556. #if (1 == MSDC_NO_USE_RANDOM_TEST_PATTERN)
  1557. #ifdef MSDC_USE_FIXED_PATTERN1
  1558. pattern = (i + count + 1) % 256;
  1559. #endif /* end of MSDC_USE_FIXED_PATTERN1 */
  1560. #ifdef MSDC_USE_FIXED_PATTERN2
  1561. pattern = MSDC_TEST_PATTERN;
  1562. #endif /*end of MSDC_USE_FIXED_PATTERN2 */
  1563. memset(buf, pattern, blksz * left_blks);
  1564. #else
  1565. for (k = 0; k < blksz * left_blks; k++){
  1566. /* random pattern */
  1567. l_low_tick0 = GPT_GetTickCount(&l_high_tick0);
  1568. buf[k] = (l_low_tick0 + i + k) % 255;
  1569. sg_wbuf_multi[i][k] = buf[k];
  1570. //printf("0x%x ", buf[k]);
  1571. //if ((k % 32) == 0)
  1572. //printf("\n");
  1573. }
  1574. #endif /* end of MSDC_NO_USE_RANDOM_TEST_PATTERN */
  1575. //printf("multi block write: 0x%x\n(%d)", blknr + i* chunk_blks, left_blks);
  1576. ret = mmc_block_write(id, blknr + chunks * chunk_blks,
  1577. left_blks, (unsigned long*)buf);
  1578. if (ret != MMC_ERR_NONE) {
  1579. result = -__LINE__;
  1580. goto failure;
  1581. }
  1582. }
  1583. printf(TC_MSG, host->id, result == 0 ? "PASS" : "FAIL", tid++,
  1584. "test multiple block write\n");
  1585. if (result)
  1586. goto failure;
  1587. /* multiple block read */
  1588. for (i = 0; i < chunks; i++) {
  1589. #if (1 == MSDC_NO_USE_RANDOM_TEST_PATTERN)
  1590. #ifdef MSDC_USE_FIXED_PATTERN1
  1591. pattern = (i + count + 1) % 256;
  1592. #endif
  1593. #ifdef MSDC_USE_FIXED_PATTERN2
  1594. pattern = MSDC_TEST_PATTERN;
  1595. #endif
  1596. #endif /* end of MSDC_NO_USE_RANDOM_TEST_PATTERN */
  1597. /* populate buffer with different pattern */
  1598. memset(buf, 0, blksz * chunk_blks);
  1599. //printf("multi block read: 0x%x\n(%d)", blknr + i* chunk_blks, chunk_blks);
  1600. ret = mmc_block_read(id, blknr + i * chunk_blks,
  1601. chunk_blks, (unsigned long*)buf);
  1602. if (ret != MMC_ERR_NONE) {
  1603. printf("[SD%d]\t\tread %d blks failed(ret = %d blks)\n",
  1604. host->id, chunk_blks, ret);
  1605. result = -__LINE__;
  1606. goto failure;
  1607. }
  1608. //pattern = 0x07;
  1609. if (chk_result) {
  1610. for (j = 0; j < chunk_blks * blksz; j++) {
  1611. #if (1 == MSDC_NO_USE_RANDOM_TEST_PATTERN)
  1612. if (buf[j] != pattern) {
  1613. printf("ops:0x%x, j(%d),buf[j](%d),pattern(%d)\n", blknr + i * chunk_blks, j, buf[j], pattern);
  1614. #else
  1615. if (buf[j] != sg_wbuf_multi[i][j]){
  1616. printf("ops:0x%x, j(%d),buf[j](%d),pattern(%d)\n", blknr + i * chunk_blks, j, buf[j], sg_wbuf_multi[i][j]);
  1617. #endif
  1618. mmc_test_dump_buff(buf, j, blksz);
  1619. result = -__LINE__;
  1620. goto failure;
  1621. }
  1622. }
  1623. }
  1624. }
  1625. if (!result && left_blks) {
  1626. #if (1 == MSDC_NO_USE_RANDOM_TEST_PATTERN)
  1627. #ifdef MSDC_USE_FIXED_PATTERN1
  1628. pattern = (i + count + 1) % 256;
  1629. #endif
  1630. #ifdef MSDC_USE_FIXED_PATTERN2
  1631. pattern = MSDC_TEST_PATTERN;
  1632. #endif
  1633. #endif /* end of MSDC_NO_USE_RANDOM_TEST_PATTERN */
  1634. /* populate buffer with different pattern */
  1635. memset(buf, 0, blksz * left_blks);
  1636. //printf("multi block read: 0x%x\n(%d)", blknr + i* chunk_blks, left_blks);
  1637. ret = mmc_block_read(id, blknr + chunks * chunk_blks,
  1638. left_blks, (unsigned long*)buf);
  1639. if (ret != MMC_ERR_NONE) {
  1640. printf("[SD%d]\t\tread %d blks failed(ret = %d blks)\n",
  1641. host->id, left_blks, ret);
  1642. result = -__LINE__;
  1643. goto failure;
  1644. }
  1645. if (chk_result) {
  1646. for (j = 0; j < left_blks * blksz; j++) {
  1647. #if (1 == MSDC_NO_USE_RANDOM_TEST_PATTERN)
  1648. if (buf[j] != pattern) {
  1649. printf("ops:0x%x, j(%d),buf[j](%d),pattern(%d)\n", blknr + i * chunk_blks, j, buf[j], pattern);
  1650. #else
  1651. if (buf[j] != sg_wbuf_multi[i][j]){
  1652. printf("ops:0x%x, j(%d),buf[j](%d),pattern(%d)\n", blknr + i * chunk_blks, j, buf[j], sg_wbuf_multi[i][j]);
  1653. #endif
  1654. mmc_test_dump_buff(buf, j, blksz);
  1655. result = -__LINE__;
  1656. goto failure;
  1657. }
  1658. }
  1659. }
  1660. }
  1661. printf(TC_MSG, host->id, result == 0 ? "PASS" : "FAIL", tid++,
  1662. "test multiple block read\n");
  1663. if (result)
  1664. goto failure;
  1665. }
  1666. mmc_send_status(host, card, &status);
  1667. if (cfg->tst_interleave) {
  1668. /* multiple block write */
  1669. chunks = total_blks / chunk_blks;
  1670. left_blks = total_blks % chunk_blks;
  1671. for (i = 0; i < chunks; i++) {
  1672. #if (1 == MSDC_NO_USE_RANDOM_TEST_PATTERN)
  1673. #ifdef MSDC_USE_FIXED_PATTERN1
  1674. pattern = (i + count + 1) % 256;
  1675. #endif
  1676. #ifdef MSDC_USE_FIXED_PATTERN2
  1677. pattern = MSDC_TEST_PATTERN;
  1678. #endif
  1679. memset(buf, pattern, blksz * chunk_blks);
  1680. #else
  1681. for (k = 0; k < blksz * chunk_blks; k++){
  1682. /* random pattern */
  1683. l_low_tick0 = GPT_GetTickCount(&l_high_tick0);
  1684. buf[k] = (l_low_tick0 + i + k) % 255;
  1685. sg_wbuf_multi[i][k] = buf[k];
  1686. //printf("0x%x ", buf[k]);
  1687. //if ((k % 32) == 0)
  1688. //printf("\n");
  1689. }
  1690. #endif /* end of MSDC_NO_USE_RANDOM_TEST_PATTERN */
  1691. //printf("multi block write: 0x%x\n(%d)", blknr + i* chunk_blks, chunk_blks);
  1692. ret = mmc_block_write(id, blknr + i * chunk_blks,
  1693. chunk_blks, (unsigned long*)buf);
  1694. if (ret != MMC_ERR_NONE) {
  1695. result = -__LINE__;
  1696. goto failure;
  1697. }
  1698. /* populate buffer with different pattern */
  1699. memset(buf, 0, blksz * chunk_blks);
  1700. //printf("multi block read: 0x%x\n(%d)", blknr + i* chunk_blks, chunk_blks);
  1701. ret = mmc_block_read(id, blknr + i * chunk_blks,
  1702. chunk_blks, (unsigned long*)buf);
  1703. if (ret != MMC_ERR_NONE) {
  1704. result = -__LINE__;
  1705. goto failure;
  1706. }
  1707. //pattern = 0x07;
  1708. if (chk_result) {
  1709. for (j = 0; j < chunk_blks * blksz; j++) {
  1710. #if (1 == MSDC_NO_USE_RANDOM_TEST_PATTERN)
  1711. if (buf[j] != pattern) {
  1712. printf("ops:0x%x, j(%d),buf[j](%d),pattern(%d)\n", blknr + i * chunk_blks, j, buf[j], pattern);
  1713. #else
  1714. if (buf[j] != sg_wbuf_multi[i][j]){
  1715. printf("ops:0x%x, j(%d),buf[j](%d),pattern(%d)\n", blknr + i * chunk_blks, j, buf[j], sg_wbuf_multi[i][j]);
  1716. #endif
  1717. mmc_test_dump_buff(buf, j, blksz);
  1718. result = -__LINE__;
  1719. goto failure;
  1720. }
  1721. }
  1722. }
  1723. }
  1724. if (!result && left_blks) {
  1725. #if (1 == MSDC_NO_USE_RANDOM_TEST_PATTERN)
  1726. #ifdef MSDC_USE_FIXED_PATTERN1
  1727. pattern = (i + count + 1) % 256;
  1728. #endif
  1729. #ifdef MSDC_USE_FIXED_PATTERN2
  1730. pattern = MSDC_TEST_PATTERN;
  1731. #endif
  1732. memset(buf, pattern, blksz * left_blks);
  1733. #else
  1734. for (k = 0; k < blksz * left_blks; k++){
  1735. /* random pattern */
  1736. l_low_tick0 = GPT_GetTickCount(&l_high_tick0);
  1737. buf[k] = (l_low_tick0 + i + k) % 255;
  1738. sg_wbuf_multi[i][k] = buf[k];
  1739. //printf("0x%x ", buf[k]);
  1740. //if ((k % 32) == 0)
  1741. //printf("\n");
  1742. }
  1743. #endif /* end of MSDC_NO_USE_RANDOM_TEST_PATTERN */
  1744. //printf("multi block write: 0x%x\n(%d)", blknr + i* chunk_blks, left_blks);
  1745. ret = mmc_block_write(id, blknr + chunks * chunk_blks,
  1746. left_blks, (unsigned long*)buf);
  1747. if (ret != MMC_ERR_NONE) {
  1748. result = -__LINE__;
  1749. goto failure;
  1750. }
  1751. /* populate buffer with different pattern */
  1752. memset(buf, 0, blksz * left_blks);
  1753. //printf("multi block read: 0x%x\n(%d)", blknr + i* chunk_blks, left_blks);
  1754. ret = mmc_block_read(id, blknr + chunks * chunk_blks,
  1755. left_blks, (unsigned long*)buf);
  1756. if (ret != MMC_ERR_NONE) {
  1757. result = -__LINE__;
  1758. break;
  1759. }
  1760. //pattern = 0x07;
  1761. if (chk_result) {
  1762. for (j = 0; j < left_blks * blksz; j++) {
  1763. #if (1 == MSDC_NO_USE_RANDOM_TEST_PATTERN)
  1764. if (buf[j] != pattern) {
  1765. printf("ops:0x%x, j(%d),buf[j](%d),pattern(%d)\n", blknr + i * chunk_blks, j, buf[j], pattern);
  1766. #else
  1767. if (buf[j] != sg_wbuf_multi[i][j]){
  1768. printf("ops:0x%x, j(%d),buf[j](%d),pattern(%d)\n", blknr + i * chunk_blks, j, buf[j], sg_wbuf_multi[i][j]);
  1769. #endif
  1770. mmc_test_dump_buff(buf, j, blksz);
  1771. result = -__LINE__;
  1772. goto failure;
  1773. }
  1774. }
  1775. }
  1776. }
  1777. printf(TC_MSG, host->id, result == 0 ? "PASS" : "FAIL", tid++,
  1778. "test multiple block interleave write-read\n");
  1779. if (result)
  1780. goto failure;
  1781. }
  1782. if (cfg->desc) {
  1783. printf("[TST] ----------------------------------------------\n");
  1784. printf("[TST] Report - %s \n", cfg->desc);
  1785. printf("[TST] ----------------------------------------------\n");
  1786. }
  1787. mmc_prof_dump(id);
  1788. failure:
  1789. if (result) {
  1790. printf("[SD%d] mmc test failed (%d)\n", host->id, result);
  1791. fail++;
  1792. } else {
  1793. pass++;
  1794. }
  1795. printf("[TST] ----------------------------------------------\n");
  1796. printf("[TST] Test Result: TOTAL(%d/%d), PASS(%d), FAIL(%d) \n",
  1797. cfg->count - count, cfg->count, pass, fail);
  1798. printf("[TST] ----------------------------------------------\n");
  1799. }
  1800. return result;
  1801. }
  1802. #endif
  1803. int mmc_test(int argc, char *argv[])
  1804. {
  1805. unsigned int i, j;
  1806. int result = -1;
  1807. struct mmc_test_config cfg;
  1808. #ifdef MMC_ICE_DOWNLOAD
  1809. mmc_readback_part(0, PART_UBOOT, 0);
  1810. mmc_erase_part(0, PART_UBOOT, 0);
  1811. mmc_readback_part(0, PART_UBOOT, 0);
  1812. mmc_download_part(0, PART_UBOOT, 0);
  1813. mmc_readback_part(0, PART_UBOOT, 0);
  1814. while(1);
  1815. #endif
  1816. #ifdef MMC_BOOT_TEST
  1817. printf("[EMMC] Boot up with power reset (MMCv4.3 above)\n");
  1818. mmc_boot_up_test(0, EMMC_BOOT_PWR_RESET);
  1819. mdelay(100);
  1820. for (i = 0; i < 20; i++) {
  1821. printf("[EMMC] Boot up with RST_n reset (MMCv4.41 above)\n");
  1822. mmc_boot_up_test(0, EMMC_BOOT_RST_N_SIG);
  1823. mdelay(100);
  1824. }
  1825. printf("[EMMC] Boot up with PRE_IDLE_CMD reset (MMCv4.41 above)\n");
  1826. mmc_boot_up_test(0, EMMC_BOOT_PRE_IDLE_CMD);
  1827. //mmc_boot_enable(0, EXT_CSD_PART_CFG_EN_NO_BOOT);
  1828. //mmc_boot_enable(0, EXT_CSD_PART_CFG_EN_BOOT_PART_1);
  1829. #endif
  1830. memset(&cfg, 0, sizeof(struct mmc_test_config));
  1831. cfg.id = 0;
  1832. cfg.desc = "Memory Card Read/Write Test";
  1833. cfg.count = MMC_TST_COUNTS;
  1834. cfg.blksz = MMC_BLOCK_SIZE;
  1835. cfg.blknr = MMC_TST_BLK_NR(0);
  1836. cfg.total_size = MMC_TST_SIZE;
  1837. cfg.chunk_blks = MMC_TST_CHUNK_BLKS;
  1838. cfg.buf = (char*) MMC_TST_BUF_ADDR;
  1839. #if defined(MMC_MSDC_DRV_PRELOADER) || defined(MMC_MSDC_DRV_LK)
  1840. cfg.buf = (char*) malloc(MMC_TST_SIZE);
  1841. #endif
  1842. cfg.chk_result = MMC_TST_CHK_RESULT;
  1843. cfg.tst_single = MMC_TST_SBLK_RW;
  1844. cfg.tst_multiple = MMC_TST_MBLK_RW;
  1845. cfg.tst_interleave = MMC_TST_IMBLK_RW;
  1846. cfg.mode = MSDC_MODE_DEFAULT;
  1847. for (i = 0; i < ARRAY_SIZE(clkfreq); i++) {
  1848. for (j = 0; j < ARRAY_SIZE(buswidth); j++) {
  1849. cfg.clock = clkfreq[i];
  1850. cfg.buswidth = buswidth[j];
  1851. if (mmc_test_mem_card(&cfg) != 0)
  1852. goto exit;
  1853. }
  1854. }
  1855. result = 0;
  1856. //mmc_readback_blks(0, MMC_TST_BLK_NR(0) * MMC_BLOCK_SIZE, 16, 0);
  1857. exit:
  1858. while(1);
  1859. return result;
  1860. }
  1861. #endif /* MMC_TEST */
  1862. #if 1
  1863. #define LK_MMC_TEST_SIZE (8*512)
  1864. unsigned char g_mmc_buf[LK_MMC_TEST_SIZE + 1];
  1865. static void emmc_r_w_compare_test(struct mmc_card *card, u32 part_id, unsigned long blknr,
  1866. u32 blkcnt)
  1867. {
  1868. unsigned int i;
  1869. int err = 0;
  1870. //unsigned char g_mmc_buf[LK_MMC_TEST_SIZE + 1];
  1871. /* write 0x40000000(1G) with 256 block(0x5a) , maybe 8 block*/
  1872. if(blkcnt > 8)
  1873. {
  1874. dprintf(CRITICAL,"blkcnt is invalid\n");
  1875. return;
  1876. }
  1877. dprintf(CRITICAL, "[LK][%s:%d]eMMC WP_FEATURE_TEST start\n", __func__, __LINE__);
  1878. for (i = 0; i < 512 * blkcnt; i++)
  1879. {
  1880. g_mmc_buf[i] = 0x5a;
  1881. }
  1882. /* 0 is for emmc */
  1883. //err = mmc_block_write(0, blknr, blkcnt, (unsigned long *)g_mmc_buf, part_id);
  1884. err = mmc_part_write(card, part_id, blknr, blkcnt, (unsigned long *)g_mmc_buf);
  1885. if(err == MMC_ERR_WP_VIOLATION)
  1886. {
  1887. dprintf(CRITICAL, "[LK][%s:%d] MMC_ERR_WP_VIOLATION\n", __func__, __LINE__);
  1888. return;
  1889. }
  1890. if(err){
  1891. dprintf(CRITICAL, "[LK][%s:%d] other write error(%d)\n", __func__, __LINE__, err);
  1892. return;
  1893. }
  1894. dprintf(CRITICAL, "[LK][%s:%d] finish write\n", __func__, __LINE__);
  1895. /* read */
  1896. for (i = 0; i < 512 * blkcnt; i++)
  1897. {
  1898. g_mmc_buf[i] = 0x0;
  1899. }
  1900. //mmc_block_read(0, blknr, blkcnt, (unsigned long *)g_mmc_buf, part_id);
  1901. mmc_part_read(card, part_id, blknr, blkcnt, (unsigned long *)g_mmc_buf);
  1902. dprintf(CRITICAL, "[LK][%s:%d] finish read\n", __func__, __LINE__);
  1903. /* compara */
  1904. for (i = 0; i < 512 * blkcnt; i++)
  1905. {
  1906. if (g_mmc_buf[i] != 0x5a)
  1907. {
  1908. dprintf(CRITICAL, "[LK][%s:%d]mmc WP_FEATURE_TEST r/w compare failed(%d is %d, not 0x5a)\n", __func__, __LINE__, i, g_mmc_buf[i]);
  1909. break;
  1910. }
  1911. }
  1912. dprintf(CRITICAL, "[LK][%s:%d]eMMC simp test end\n", __func__, __LINE__);
  1913. }
  1914. int mmc_wp_test()
  1915. {
  1916. int err;
  1917. #if 0
  1918. int dev_num = 0;
  1919. unsigned long blknr;
  1920. u32 blkcnt;
  1921. u32 part_id;
  1922. u8 case_id=1;
  1923. // struct mmc_host *host = mmc_get_host(dev_num);
  1924. struct mmc_card *card = mmc_get_card(dev_num);
  1925. //case 1
  1926. /* blknr = 2;
  1927. blkcnt = 6;
  1928. part_id = EMMC_PART_BOOT1;
  1929. dprintf(CRITICAL, "[case %d] blknr=%ld, blkcnt=%x,partition=%d \n",
  1930. case_id,blknr,blkcnt,part_id);
  1931. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_POWER_ON);
  1932. if(err)
  1933. dprintf(CRITICAL, "[%s]: (case %d) wp error\n", __func__,case_id++);
  1934. else
  1935. dprintf(CRITICAL, "[%s]: (case %d) wp successfully\n", __func__,case_id++);
  1936. */
  1937. //case2
  1938. blknr = 0;
  1939. blkcnt = card->wp_size;
  1940. part_id = EMMC_PART_USER;
  1941. dprintf(CRITICAL, "[case %d] blknr=0x%x, blkcnt=0x%x,partition=%d \n",
  1942. case_id,blknr,blkcnt,part_id);
  1943. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_POWER_ON);
  1944. if(err)
  1945. dprintf(CRITICAL, "[%s]: (case %d) wp error\n", __func__,case_id++);
  1946. else
  1947. dprintf(CRITICAL, "[%s]: (case %d) wp successfully\n", __func__,case_id++);
  1948. //case3
  1949. blknr = card->wp_size;
  1950. blkcnt = 10 * card->wp_size;
  1951. part_id = EMMC_PART_USER;
  1952. dprintf(CRITICAL, "[case %d] blknr=0x%x, blkcnt=0x%x,partition=%d \n",
  1953. case_id,blknr,blkcnt,part_id);
  1954. u64 time_before= gpt4_get_current_tick();//%lld
  1955. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_POWER_ON);
  1956. u64 time_after= gpt4_get_current_tick();//%lld
  1957. if(err)
  1958. dprintf(CRITICAL, "[%s]: (case %d) wp error,[time cost of 10 wp grps]: %lld \n",
  1959. __func__,case_id++,(time_after - time_before)*76);
  1960. else
  1961. dprintf(CRITICAL, "[%s]: (case %d) wp successfully\n", __func__,case_id++);
  1962. //case4
  1963. blknr = 1;
  1964. blkcnt = card->wp_size;
  1965. part_id = EMMC_PART_USER;
  1966. dprintf(CRITICAL, "[case %d] blknr=0x%x, blkcnt=0x%x,partition=%d \n",
  1967. case_id,blknr,blkcnt,part_id);
  1968. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_POWER_ON);
  1969. if(err)
  1970. dprintf(CRITICAL, "[%s]: (case %d) wp error\n", __func__,case_id++);
  1971. else
  1972. dprintf(CRITICAL, "[%s]: (case %d) wp successfully\n", __func__,case_id++);
  1973. //case5
  1974. blknr = card->wp_size;
  1975. blkcnt = 1;
  1976. part_id = EMMC_PART_USER;
  1977. dprintf(CRITICAL, "[case %d] blknr=0x%x, blkcnt=0x%x,partition=%d \n",
  1978. case_id,blknr,blkcnt,part_id);
  1979. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_POWER_ON);
  1980. if(err)
  1981. dprintf(CRITICAL, "[%s]: (case %d) wp error\n", __func__,case_id++);
  1982. else
  1983. dprintf(CRITICAL, "[%s]: (case %d) wp successfully\n", __func__,case_id++);
  1984. //case6
  1985. blknr = card->wp_size;
  1986. blkcnt = card->nblks;
  1987. part_id = EMMC_PART_USER;
  1988. dprintf(CRITICAL, "[case %d] blknr=0x%x, blkcnt=0x%x,partition=%d \n",
  1989. case_id,blknr,blkcnt,part_id);
  1990. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_POWER_ON);
  1991. if(err)
  1992. dprintf(CRITICAL, "[%s]: (case %d) wp error\n", __func__,case_id++);
  1993. else
  1994. dprintf(CRITICAL, "[%s]: (case %d) wp successfully\n", __func__,case_id++);
  1995. //case7
  1996. blknr = card->wp_size;
  1997. blkcnt = card->wp_size;;
  1998. part_id = EMMC_PART_END;
  1999. dprintf(CRITICAL, "[case %d] blknr=0x%x, blkcnt=0x%x,partition=%d \n",
  2000. case_id,blknr,blkcnt,part_id);
  2001. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_POWER_ON);
  2002. if(err)
  2003. dprintf(CRITICAL, "[%s]: (case %d) wp error\n", __func__,case_id++);
  2004. else
  2005. dprintf(CRITICAL, "[%s]: (case %d) wp successfully\n", __func__,case_id++);
  2006. //case8
  2007. blknr = 11 * card->wp_size;
  2008. blkcnt = card->wp_size;
  2009. part_id = EMMC_PART_USER;
  2010. dprintf(CRITICAL, "[case %d] blknr=0x%x, blkcnt=0x%x,partition=%d \n",
  2011. case_id,blknr,blkcnt,part_id);
  2012. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_PERMANENT);
  2013. if(err)
  2014. dprintf(CRITICAL, "[%s]: (case %d) wp error\n", __func__,case_id++);
  2015. else
  2016. dprintf(CRITICAL, "[%s]: (case %d) wp successfully\n", __func__,case_id++);
  2017. //case9
  2018. blknr = 0;
  2019. blkcnt = card->wp_size;
  2020. part_id = EMMC_PART_GP1;
  2021. dprintf(CRITICAL, "[case %d] blknr=0x%x, blkcnt=0x%x,partition=%d \n",
  2022. case_id,blknr,blkcnt,part_id);
  2023. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_POWER_ON);
  2024. if(err)
  2025. dprintf(CRITICAL, "[%s]: (case %d) wp error\n", __func__,case_id++);
  2026. else
  2027. dprintf(CRITICAL, "[%s]: (case %d) wp successfully\n", __func__,case_id++);
  2028. //case10
  2029. blknr = 0;
  2030. blkcnt = card->wp_size;
  2031. part_id = EMMC_PART_USER;
  2032. dprintf(CRITICAL, "[case %d] blknr=0x%x, blkcnt=0x%x,partition=%d \n",
  2033. case_id,blknr,blkcnt,part_id);
  2034. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_TEMPORARY);
  2035. if(err)
  2036. dprintf(CRITICAL, "[%s]: (case %d) wp error\n", __func__,case_id++);
  2037. else
  2038. dprintf(CRITICAL, "[%s]: (case %d) wp successfully\n", __func__,case_id++);
  2039. #endif
  2040. // partiton test case
  2041. dprintf(CRITICAL, "[%s]: (partition case: 1) preloader->lk\n", __func__);
  2042. err = partition_write_prot_set("preloader", "lk", WP_POWER_ON);
  2043. dprintf(CRITICAL, "[%s]: (partition case: 1) preloader->lk, err=%d\n", __func__, err);
  2044. dprintf(CRITICAL, "[%s]: (partition case: 2) boot->recovery\n", __func__);
  2045. err = partition_write_prot_set("boot", "recovery", WP_POWER_ON);
  2046. dprintf(CRITICAL, "[%s]: (partition case: 2) boot->recovery, err=%d\n", __func__, err);
  2047. dprintf(CRITICAL, "[%s]: (partition case: 3) keystore->oemkeystore\n", __func__);
  2048. err = partition_write_prot_set("keystore", "oemkeystore", WP_POWER_ON);
  2049. dprintf(CRITICAL, "[%s]: (partition case: 3) keystore->oemkeystore, err=%d\n", __func__, err);
  2050. dprintf(CRITICAL, "[%s]: (partition case: 4) oemkeystore->secro\n", __func__);
  2051. err = partition_write_prot_set("oemkeystore", "secro", WP_POWER_ON);
  2052. dprintf(CRITICAL, "[%s]: (partition case: 4) oemkeystore->secro, err=%d\n", __func__, err);
  2053. dprintf(CRITICAL, "[%s]: (partition case: 5) test_start->keystore\n", __func__);
  2054. err = partition_write_prot_set("test_starte", "keystor", WP_POWER_ON);
  2055. dprintf(CRITICAL, "[%s]: (partition case: 5) test_start->keystore, err=%d\n", __func__, err);
  2056. dprintf(CRITICAL, "[%s]: (partition case: 6) oemkeystore->test_end\n", __func__);
  2057. err = partition_write_prot_set("oemkeystore", "test_end", WP_POWER_ON);
  2058. dprintf(CRITICAL, "[%s]: (partition case: 6) oemkeystore->test_end, err=%d\n", __func__, err);
  2059. dprintf(CRITICAL, "[%s]: (partition case: 7) keystore->keystore\n", __func__);
  2060. err = partition_write_prot_set("keystore", "keystore", WP_POWER_ON);
  2061. dprintf(CRITICAL, "[%s]: (partition case: 7) keystore->keystore, err=%d\n", __func__, err);
  2062. return err;
  2063. }
  2064. #endif