mmc_test.c 92 KB

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