mmc_test.c 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061
  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. * The following software/firmware and/or related documentation ("MediaTek Software")
  32. * have been modified by MediaTek Inc. All revisions are subject to any receiver\'s
  33. * applicable license agreements with MediaTek Inc.
  34. */
  35. //#define MMC_ICE_DOWNLOAD
  36. //#define MMC_BOOT_TEST
  37. /*=======================================================================*/
  38. /* HEADER FILES */
  39. /*=======================================================================*/
  40. #include "msdc.h"
  41. #if defined(MMC_MSDC_DRV_LK) && defined(MTK_EMMC_POWER_ON_WP)
  42. #include <platform/partition_wp.h>
  43. #endif
  44. #define MMC_BUF_ADDR (0x01000000)
  45. #define BLK_SIZE (512)
  46. #if defined(MMC_MSDC_DRV_CTP)
  47. #include "api.h" //For invocation cache_clean_invalidate()
  48. #include "cache_api.h" //For invocation cache_clean_invalidate()
  49. #endif
  50. #if defined(MMC_TEST)
  51. #define TC_MSG "[SD%d] <%s> TC%d: "
  52. #define MMC_TST_CHK_RESULT (1)
  53. #define MMC_TST_SBLK_RW (1)
  54. #define MMC_TST_MBLK_RW (1)
  55. #define MMC_TST_IMBLK_RW (1)
  56. #define MMC_TST_COUNTS (1)
  57. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  58. static unsigned int clkfreq[] = {2000000};
  59. static unsigned int buswidth[] = {HOST_BUS_WIDTH_4};
  60. #ifdef MMC_PROFILING
  61. static struct mmc_op_perf mmc_perf[MSDC_MAX_NUM];
  62. struct mmc_op_perf *mmc_prof_handle(int id)
  63. {
  64. return &mmc_perf[id];
  65. }
  66. void mmc_prof_init(int id, struct mmc_host *host, struct mmc_card *card)
  67. {
  68. memset(&mmc_perf[id], 0, sizeof(struct mmc_op_perf));
  69. mmc_perf[id].host = host;
  70. mmc_perf[id].card = card;
  71. msdc_timer_init();
  72. msdc_timer_stop_clear();
  73. }
  74. void mmc_prof_start(void)
  75. {
  76. msdc_timer_stop_clear();
  77. msdc_timer_start();
  78. }
  79. void mmc_prof_stop(void)
  80. {
  81. msdc_timer_stop();
  82. }
  83. unsigned int mmc_prof_count(void)
  84. {
  85. return msdc_timer_get_count();
  86. }
  87. void mmc_prof_update(mmc_prof_callback cb, ulong id, void *data)
  88. {
  89. ulong counts = (ulong)msdc_timer_get_count();
  90. if (cb) {
  91. cb(data, id, counts);
  92. }
  93. }
  94. void mmc_prof_report(struct mmc_op_report *rpt)
  95. {
  96. msdc_pr_info("\t\tCount : %d\n", rpt->count);
  97. msdc_pr_info("\t\tMax. Time : %d counts\n", rpt->max_time);
  98. msdc_pr_info("\t\tMin. Time : %d counts\n", rpt->min_time);
  99. msdc_pr_info("\t\tTotal Size : %d KB\n", rpt->total_size / 1024);
  100. msdc_pr_info("\t\tTotal Time : %d counts\n", rpt->total_time);
  101. if (rpt->total_time) {
  102. msdc_pr_info("\t\tPerformance: %d KB/sec\n",
  103. ((rpt->total_size / 1024) * 32768) / rpt->total_time);
  104. }
  105. }
  106. int mmc_prof_dump(int dev_id)
  107. {
  108. struct mmc_host *host;
  109. struct mmc_card *card;
  110. struct mmc_op_perf *perf;
  111. u32 total_read_size, total_write_size;
  112. u32 total_read_time, total_write_time;
  113. perf = &mmc_perf[dev_id];
  114. host = mmc_perf[dev_id].host;
  115. card = mmc_perf[dev_id].card;
  116. total_read_size = total_write_size = 0;
  117. total_read_time = total_write_time = 0;
  118. msdc_pr_info("\tSD Host ID : %d\n", dev_id);
  119. msdc_pr_info("\tOP Clock Freq. : %d khz\n", host->src_clk / 1000);
  120. msdc_pr_info("\tSD Clock Freq. : %d khz\n", host->cur_bus_clk / 1000);
  121. msdc_pr_info("\tCard Type : %s card\n", (card->type == MMC_TYPE_MMC) ? "MMC" : "SD/SDHC/SDXC");
  122. msdc_pr_info("\tCard Mode : UHS1(%d) DDR(%d) HS(%d)\n",
  123. mmc_card_uhs1(card) ? 1 : 0, mmc_card_ddr(card) ? 1 : 0,
  124. mmc_card_highspeed(card) ? 1 : 0);
  125. msdc_pr_info("\tCard Size : %d MB\n", (card->nblks * card->blklen) / 1024 / 1024);
  126. msdc_pr_info("\tCard Max. Freq.: %d khz\n", card->maxhz / 1000);
  127. if (perf->multi_blks_read.count) {
  128. msdc_pr_info("\tMulti-Blks-Read:\n");
  129. mmc_prof_report(&perf->multi_blks_read);
  130. total_read_size += perf->multi_blks_read.total_size;
  131. total_read_time += perf->multi_blks_read.total_time;
  132. }
  133. if (perf->multi_blks_write.count) {
  134. msdc_pr_info("\tMulti-Blks-Write:\n");
  135. mmc_prof_report(&perf->multi_blks_write);
  136. total_write_size += perf->multi_blks_write.total_size;
  137. total_write_time += perf->multi_blks_write.total_time;
  138. }
  139. if (perf->single_blk_read.count) {
  140. msdc_pr_info("\tSingle-Blk-Read:\n");
  141. mmc_prof_report(&perf->single_blk_read);
  142. total_read_size += perf->single_blk_read.total_size;
  143. total_read_time += perf->single_blk_read.total_time;
  144. }
  145. if (perf->single_blk_write.count) {
  146. msdc_pr_info("\tSingle-Blk-Write:\n");
  147. mmc_prof_report(&perf->single_blk_write);
  148. total_write_size += perf->single_blk_write.total_size;
  149. total_write_time += perf->single_blk_write.total_time;
  150. }
  151. if (total_read_time) {
  152. msdc_pr_info("\tPerformance Read : %d KB/sec\n",
  153. ((total_read_size / 1024) * 32768) / total_read_time);
  154. }
  155. if (total_write_time) {
  156. msdc_pr_info("\tPerformance Write: %d KB/sec\n",
  157. ((total_write_size / 1024) * 32768) / total_write_time);
  158. }
  159. return 0;
  160. }
  161. #endif
  162. #ifdef MMC_ICE_DOWNLOAD
  163. volatile u32 mmc_download_addr;
  164. volatile u32 mmc_download_size;
  165. volatile u32 mmc_image_addr;
  166. int mmc_download(int dev_id, u32 imgaddr, u32 size, u32 addr, int bootarea)
  167. {
  168. int ret;
  169. int i, j, result = 0;
  170. u8 val;
  171. u8 *ext_csd;
  172. uchar *buf, *chkbuf;
  173. u32 chunks, chunk_blks = 128, left_blks, blknr;
  174. u32 total_blks;
  175. struct mmc_card *card;
  176. if (!size)
  177. return 0;
  178. if (addr % MMC_BLOCK_SIZE)
  179. return MMC_ERR_FAILED;
  180. card = mmc_get_card(dev_id);
  181. ext_csd = &card->raw_ext_csd[0];
  182. if (bootarea && !mmc_card_sd(card) && card->ext_csd.part_en) {
  183. /* configure to specified partition */
  184. val = (ext_csd[EXT_CSD_PART_CFG] & ~0x7) | EXT_CSD_PART_CFG_BOOT_PART_1;
  185. if (mmc_set_part_config(card, val) != MMC_ERR_NONE) {
  186. result = -__LINE__;
  187. goto done;
  188. }
  189. }
  190. blknr = addr / MMC_BLOCK_SIZE;
  191. total_blks = (size + MMC_BLOCK_SIZE - 1) / MMC_BLOCK_SIZE;
  192. /* multiple block write */
  193. chunks = total_blks / chunk_blks;
  194. left_blks = total_blks % chunk_blks;
  195. buf = (uchar*)imgaddr;
  196. chkbuf = (uchar*)MMC_BUF_ADDR;
  197. for (i = 0; i < chunks; i++) {
  198. ret = mmc_block_write(dev_id, blknr + i * chunk_blks,
  199. chunk_blks, (unsigned long*)buf);
  200. if (ret != MMC_ERR_NONE) {
  201. result = -__LINE__;
  202. goto done;
  203. }
  204. ret = mmc_block_read(dev_id, blknr + i * chunk_blks,
  205. chunk_blks, (unsigned long*)chkbuf);
  206. if (ret != MMC_ERR_NONE) {
  207. result = -__LINE__;
  208. goto done;
  209. }
  210. for (j = 0; j < chunk_blks * MMC_BLOCK_SIZE; j++) {
  211. if (buf[j] == chkbuf[j])
  212. continue;
  213. result = -__LINE__;
  214. goto done;
  215. }
  216. msdc_pr_info("[SD%d] Write %3d blocks from 0x%.8x(RAM) to 0x%.8x(FLASH).\n",
  217. dev_id, chunk_blks, (unsigned int)buf,
  218. (blknr + i * chunk_blks) * MMC_BLOCK_SIZE);
  219. buf += (chunk_blks * MMC_BLOCK_SIZE);
  220. }
  221. if (left_blks) {
  222. ret = mmc_block_write(dev_id, blknr + chunks * chunk_blks,
  223. left_blks, (unsigned long*)buf);
  224. if (ret != MMC_ERR_NONE) {
  225. result = -__LINE__;
  226. goto done;
  227. }
  228. ret = mmc_block_read(dev_id, blknr + chunks * chunk_blks,
  229. left_blks, (unsigned long*)chkbuf);
  230. if (ret != MMC_ERR_NONE) {
  231. result = -__LINE__;
  232. goto done;
  233. }
  234. for (j = 0; j < left_blks * MMC_BLOCK_SIZE; j++) {
  235. if (buf[j] == chkbuf[j])
  236. continue;
  237. msdc_pr_info("[SD%d] chkbuf[%d] = %xh (!= %xh) \n", dev_id,
  238. j, chkbuf[j], buf[j]);
  239. result = -__LINE__;
  240. goto done;
  241. }
  242. msdc_pr_info("[SD%d] Write %3d blocks from 0x%.8x(RAM) to 0x%.8x(FLASH).\n",
  243. dev_id, left_blks, (unsigned int)buf,
  244. (blknr + chunks * chunk_blks) * MMC_BLOCK_SIZE);
  245. }
  246. done:
  247. if (bootarea && !mmc_card_sd(card) && card->ext_csd.part_en) {
  248. /* configure to user partition */
  249. val = (ext_csd[EXT_CSD_PART_CFG] & ~0x7) | EXT_CSD_PART_CFG_DEFT_PART;
  250. if (mmc_set_part_config(card, val) != MMC_ERR_NONE)
  251. result = -__LINE__;
  252. }
  253. if (!result) {
  254. msdc_pr_info("[SD%d] Download %d blocks (%d bytes) to 0x%.8x successfully\n",
  255. dev_id, total_blks, total_blks * MMC_BLOCK_SIZE, blknr * MMC_BLOCK_SIZE);
  256. } else {
  257. msdc_pr_info("[SD%d] Download %d blocks (%d bytes) to 0x%.8x failed %d\n",
  258. dev_id, total_blks, total_blks * MMC_BLOCK_SIZE, blknr * MMC_BLOCK_SIZE, result);
  259. }
  260. return result;
  261. }
  262. int mmc_download_part(int dev_id, char *part_name, int bootarea)
  263. {
  264. int ret = -1;
  265. struct mmc_card *card;
  266. struct mmc_host *host;
  267. part_t *part = mt6573_part_get_partition(part_name);
  268. mmc_download_addr = 0;
  269. mmc_download_size = 0;
  270. mmc_image_addr = 0;
  271. host = mmc_get_host(dev_id);
  272. card = mmc_get_card(dev_id);
  273. if (part) {
  274. msdc_pr_info("[SD%d] Waiting for '%s' image loading from ICE...\n", dev_id, part_name);
  275. while (!mmc_download_size); /* Wait for loading image from ICE */
  276. ret = mmc_download(dev_id, mmc_image_addr, mmc_download_size,
  277. part->startblk * BLK_SIZE, bootarea);
  278. if (ret != 0)
  279. goto done;
  280. if (bootarea) {
  281. /* set reset signal function */
  282. //ret = mmc_set_reset_func(card, 1);
  283. //if (ret != 0)
  284. // goto done;
  285. /* set boot config */
  286. ret = mmc_boot_config(card, EXT_CSD_PART_CFG_EN_ACK,
  287. EXT_CSD_PART_CFG_EN_BOOT_PART_1, EXT_CSD_BOOT_BUS_WIDTH_1,
  288. EXT_CSD_BOOT_BUS_MODE_DEFT);
  289. if (ret != 0)
  290. goto done;
  291. ret = mmc_read_ext_csd(host, card);
  292. }
  293. }
  294. done:
  295. return ret;
  296. }
  297. #endif
  298. #ifdef autok_test
  299. extern void autok_auto_test(struct autok_host *host);
  300. extern struct autok_host autok_test_host;
  301. extern struct msdc_hw autok_hw;
  302. extern struct mmc_ios autok_ios;
  303. #endif
  304. /* r: read only, t: read only and update by hw
  305. * z: write 1 and then auto clear by hw
  306. * w: write only, it cannot be tested since read is nonsense
  307. * a: readable & writable
  308. * x: don't care, do not test
  309. * k: read clear, there is no such bits in MSDC and therefore no test code about it
  310. * s: readable and write 1 set, there is no such bits in MSDC and therefore no test code about it
  311. * 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
  312. *
  313. * RU: read only bit value update by the hw, denote as 't', like MSDC_RXDATA, MSDC_CFG[7]:CARD_CK_STABLE
  314. * RO: read only, denote as 'r', like MSDC_VERSION
  315. * RW: writeable and readable, denote as 'a'
  316. * WO: write only, denote as 'w', like MSDC_TXDATA
  317. * W1: write once, denote as '', not used yet.
  318. * RC: clear on read, denote as 'k', not used yet.
  319. * A1: auto set by the hw.
  320. * AO: auto clear by the hw, denote as 'z' like MSDC_CS[31]
  321. * DC: don't care, denote as 'x'
  322. * W1C: write 1 to bit wise-clear, denote as 'c', like SDC_CSTS
  323. * note: RU means the content of the regiter will change,
  324. * RO means the content of the register will not change
  325. */
  326. /* need confirmed with cui
  327. * card detect bit 0x8[1] default is set to 0, why fpga set to 1?
  328. * 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'
  329. * 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'
  330. * 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'
  331. * sdwp 0x08[31], default is set to 0, why fpga set to 1? */
  332. static reg_desc_t msdc0_reg_desc[] = {
  333. {OFFSET_MSDC_CFG , {"aazaaattaaaaaaaaaaaaccaaaaxxxxxx"}, {"10011001000000000000000001xxxxxx"}}, //bit[2] is rw, but not test. cause this is a reset bit. write to "1" will back to "0" when reset sequence done
  334. {OFFSET_MSDC_IOCON , {"aaaaaaxxaaaaaaxxaaaaaaaaxxxxxxxx"}, {"000000xx000000xx0000000000xxxxxx"}},//bit[24][25] can not write(Not in MT8320 MSDC IP)
  335. {OFFSET_MSDC_PS , {"arxxxxxxxxxxaaaarrrrrrrrrxxxxxxr"}, {"01xxxxxxxxxx0000111111111xxxxxx1"}},//bit[1]/bit[16-20]/bit[24]/bit[31] default to 0
  336. {OFFSET_MSDC_INT , {"ccxccccccccrccccccccccccxxxxxxxx"}, {"00x000000000000000000000xxxxxxxx"}},
  337. {OFFSET_MSDC_INTEN , {"aaxaaaaaaaaaaaaaaaaarrraxxxxxxxx"}, {"00x000000000000000000000xxxxxxxx"}},//bit[2] to RW, default to 0
  338. {OFFSET_MSDC_FIFOCS , {"rrrrrrrrxxxxxxxxrrrrrrrrxxxxxxxz"}, {"00000000xxxxxxxx00000000xxxxxxx0"}},//bit[0]~[7] are variable if you use memory tool in Code visor (memory tool must be closed)
  339. {OFFSET_MSDC_TXDATA , {"wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"}, {"00000000000000000000000000000000"}},
  340. //{OFFSET_MSDC_RXDATA , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},/* Should not be touched. */
  341. {OFFSET_SDC_CFG , {"aaxxxxxxxxxxxxxxaaxaaaxxaaaaaaaa"}, {"00xxxxxxxxxxxxxx00x010xx00000000"}},
  342. {OFFSET_SDC_CMD , {"aaaaaaaaaaxaaaaaaaaaaaaaaaaaaaar"}, {"0000000000x000000000000000000000"}},
  343. {OFFSET_SDC_ARG , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  344. {OFFSET_SDC_STS , {"ttxxxxxxxxxxxxxxcxxxxxxxxxxxxxxt"}, {"00xxxxxxxxxxxxxx0xxxxxxxxxxxxxx0"}},
  345. {OFFSET_SDC_RESP0 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  346. {OFFSET_SDC_RESP1 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  347. {OFFSET_SDC_RESP2 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  348. {OFFSET_SDC_RESP3 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  349. {OFFSET_SDC_BLK_NUM , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"10000000000000000000000000000000"}},
  350. {OFFSET_SDC_VOL_CHG , {"aaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxx"}, {"1010001010000000xxxxxxxxxxxxxxxx"}},
  351. {OFFSET_SDC_CSTS , {"cccccccccccccccccccccccccccccccc"}, {"00000000000000000000000000000000"}},
  352. {OFFSET_SDC_CSTS_EN , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  353. {OFFSET_SDC_DCRC_STS , {"rrrrrrrrrrrrrrrrxxxxxxxxxxxxxxxx"}, {"0000000000000000xxxxxxxxxxxxxxxx"}},//bit[12-15] modify
  354. {OFFSET_EMMC_CFG0 , {"wwaaxxxxxxxxaaaaxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxx0000xxxxxxxxxxxxxxxx"}},
  355. {OFFSET_EMMC_CFG1 , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"11000000000000000000010000000000"}},
  356. {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
  357. {OFFSET_EMMC_IOCON , {"axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  358. {OFFSET_SDC_ACMD_RESP , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  359. {OFFSET_SDC_ACMD19_TRG, {"aaaaxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  360. {OFFSET_SDC_ACMD19_STS, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  361. {OFFSET_MSDC_DMA_SA_HIGH, {"aaaaxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  362. {OFFSET_MSDC_DMA_SA , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  363. {OFFSET_MSDC_DMA_CA , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  364. {OFFSET_MSDC_DMA_CTRL , {"wrwxxxxxaxaxaaaxxxxxxxxxxxxxxxxx"}, {"000xxxxx0x0x011xxxxxxxxxxxxxxxxx"}}, //need new design, bit[1] = AO
  365. {OFFSET_MSDC_DMA_CFG , {"raxxxxxxaaxxaaxxarxxxxxxxxxxxxxx"}, {"00xxxxxx00xx00xx00xxxxxxxxxxxxxx"}},
  366. {OFFSET_MSDC_DBG_SEL , {"aaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxx"}, {"0000000000000000xxxxxxxxxxxxxxxx"}},
  367. {OFFSET_MSDC_DBG_OUT , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  368. {OFFSET_MSDC_DMA_LEN , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}}, //new register in MT6582
  369. {OFFSET_MSDC_PATCH_BIT0, {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"11110000000000000011110000000010"}},
  370. {OFFSET_MSDC_PATCH_BIT1, {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"10010000000000001111111111111111"}},
  371. {OFFSET_MSDC_PATCH_BIT2, {"aaaaaaaaaaxaaaaaaaaxaaaaaaaaaaaa"}, {"11000000000110000000000100101000"}},
  372. {OFFSET_DAT0_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  373. {OFFSET_DAT1_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  374. {OFFSET_DAT2_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  375. {OFFSET_DAT3_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  376. {OFFSET_CMD_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  377. {OFFSET_MSDC_PAD_TUNE0, {"aaaaaxxxaaaaaxxxaaaaaxaaaaaaaaaa"}, {"00000xxx00000xxx00000x0000000000"}},
  378. {OFFSET_MSDC_PAD_TUNE1, {"xxxxxxxxaaaaaaxxaaaaaaxxxxxxxxxx"}, {"xxxxxxxx000000xx000000xxxxxxxxxx"}},
  379. {OFFSET_MSDC_DAT_RDDLY0, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  380. {OFFSET_MSDC_DAT_RDDLY1, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  381. {OFFSET_MSDC_DAT_RDDLY2, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  382. {OFFSET_MSDC_DAT_RDDLY3, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  383. {OFFSET_MSDC_HW_DBG , {"aaaaaaaaaaaaaaxxaaaaaaaaaaaaaaax"}, {"00000000000000xx000000000000000x"}},
  384. {OFFSET_MSDC_VERSION , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"11000000010010001100100000000100"}},//20131203
  385. {OFFSET_MSDC_ECO_VER , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"10000000000000000000000000000000"}},//0
  386. {OFFSET_EMMC50_PAD_CTL0, {"aaaaaaaaaaxxxxxxxxxxxxxxxxxxxxxx"}, {"0000000000xxxxxxxxxxxxxxxxxxxxxx"}},
  387. {OFFSET_EMMC50_PAD_DS_CTL0, {"aaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxx"}, {"0011100000000000000xxxxxxxxxxxxx"}},
  388. {OFFSET_EMMC50_PAD_DS_TUNE, {"aaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxx"}, {"10101000000000101xxxxxxxxxxxxxxx"}},
  389. {OFFSET_EMMC50_PAD_CMD_TUNE, {"aaaaaaaaaaaxxxxxxxxxxxxxxxxxxxxx"}, {"00000000000xxxxxxxxxxxxxxxxxxxxx"}},
  390. {OFFSET_EMMC50_PAD_DAT01_TUNE, {"aaaaaaaaaaaxxxxxaaaaaaaaaaaxxxxx"}, {"00000000000xxxxx00000000000xxxxx"}},
  391. {OFFSET_EMMC50_PAD_DAT23_TUNE, {"aaaaaaaaaaaxxxxxaaaaaaaaaaaxxxxx"}, {"00000000000xxxxx00000000000xxxxx"}},
  392. {OFFSET_EMMC50_PAD_DAT45_TUNE, {"aaaaaaaaaaaxxxxxaaaaaaaaaaaxxxxx"}, {"00000000000xxxxx00000000000xxxxx"}},
  393. {OFFSET_EMMC50_PAD_DAT67_TUNE, {"aaaaaaaaaaaxxxxxaaaaaaaaaaaxxxxx"}, {"00000000000xxxxx00000000000xxxxx"}},
  394. {OFFSET_EMMC51_CFG0, {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00101000000000000110000100001000"}},
  395. {OFFSET_EMMC50_CFG0, {"aaaaaaaaaaaaaaaaaaaaaaaaaxxxxaxx"}, {"0100011110010001000101110xxxx0xx"}},
  396. {OFFSET_EMMC50_CFG1, {"xxxxxxxxaaaaaaaaaaaaaaaaaaaaaaaa"}, {"xxxxxxxx111000000000000010000000"}},
  397. {OFFSET_EMMC50_CFG2, {"xaaaaaaaxxxxaaaaaaaaaaaaaaaarrrx"}, {"x0000000xxxx0000001100001111000x"}},
  398. {OFFSET_EMMC50_CFG3, {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaarrr"}, {"10000011110001010001010011110000"}},
  399. {OFFSET_EMMC50_CFG4, {"aaaaaaaaaaaaaaaaaaaaaaarrrrrrrrr"}, {"01111000000101001000000000000000"}},
  400. {OFFSET_SDC_FIFO_CFG, {"aaaaaaaaaxxxxxxxxxxxxxxxxxxxxxxx"}, {"00000001000000000000000000000000"}},
  401. #if defined(FEATURE_MULTI_HOST)
  402. {OFFSET_EMMC_MTH_CFG, {"azxxrrrxrrrrrrrrrrrxCxxxxxxxxxxx"}, {"00xx000x00001111111x0xxxxxxxxxxx"}},
  403. {OFFSET_EMMC_MTH_PARMAP0, {"aaaaaaaaxxxxxxxxxxxxxxxxxxxxxxxx"}, {"00000000xxxxxxxxxxxxxxxxxxxxxxxx"}},
  404. {OFFSET_EMMC_MTH_PARMAP1, {"aaaaaaaaxxxxxxxxxxxxxxxxxxxxxxxx"}, {"00000000xxxxxxxxxxxxxxxxxxxxxxxx"}},
  405. {OFFSET_EMMC_MTH_PARMAP2, {"aaaaaaaaxxxxxxxxxxxxxxxxxxxxxxxx"}, {"00000000xxxxxxxxxxxxxxxxxxxxxxxx"}},
  406. {OFFSET_EMMC_MTH_PARMAP3, {"aaaaaaaaxxxxxxxxxxxxxxxxxxxxxxxx"}, {"00000000xxxxxxxxxxxxxxxxxxxxxxxx"}},
  407. {OFFSET_EMMC_MTH_TK_CTRL0, {"azxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"00xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  408. {OFFSET_EMMC_MTH_TK_CTRL1, {"azxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"00xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  409. {OFFSET_EMMC_MTH_TK_CTRL2, {"azxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"00xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  410. {OFFSET_EMMC_MTH_TK_CTRL3, {"azxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"00xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  411. #endif
  412. };
  413. static reg_desc_t msdc1_reg_desc[] = {
  414. //{"01234567012345670123456701234567"}, {"01234567012345670123456701234567"}
  415. {OFFSET_MSDC_CFG , {"aazaaattaaaaaaaaaaaaccxxxaxxxxxx"}, {"1001100100000000000000xxx1xxxxxx"}}, //bit[2] is rw, but not test. cause this is a reset bit. write to "1" will back to "0" when reset sequence done
  416. {OFFSET_MSDC_IOCON , {"aaaaaaxxaaaaaaxxaaaaaaaaxxxxxxxx"}, {"000000xx000000xx0000000000xxxxxx"}},//bit[24][25] can not write(Not in MT8320 MSDC IP)
  417. {OFFSET_MSDC_PS , {"atxxxxxxxxxxaaaattttxxxxtxxxxxxr"}, {"01xxxxxxxxxx00001111xxxx1xxxxxx0"}},//bit[1]/bit[16-20]/bit[24]/bit[31] default to 0
  418. {OFFSET_MSDC_INT , {"ccxccccccccrccccccccccccxxxxxxxx"}, {"00x000000000000000000000xxxxxxxx"}},
  419. {OFFSET_MSDC_INTEN , {"aaxaaaaaaaaaaaaaaaaaxxxxxxxxxxxx"}, {"00x00000000000000000xxxxxxxxxxxx"}},//bit[2] to RW, default to 0
  420. {OFFSET_MSDC_FIFOCS , {"rrrrrrrrxxxxxxxxrrrrrrrrxxxxxxxz"}, {"00000000xxxxxxxx00000000xxxxxxx0"}},//bit[0]~[7] are variable if you use memory tool in Code visor (memory tool must be closed)
  421. {OFFSET_MSDC_TXDATA , {"wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"}, {"00000000000000000000000000000000"}},
  422. //{OFFSET_MSDC_RXDATA , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},/* Should not be touched. */
  423. {OFFSET_SDC_CFG , {"aaxxxxxxxxxxxxxxaaxaaaxxaaaaaaaa"}, {"00xxxxxxxxxxxxxx00x010xx00000000"}},
  424. {OFFSET_SDC_CMD , {"xaaaaaaaaaxaaaaaaaaaaaaaaaaaaaax"}, {"x000000000x000000000000000000000"}},
  425. {OFFSET_SDC_ARG , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  426. {OFFSET_SDC_STS , {"ttxxxxxxxxxxxxxxxxxxxxxxxxxxxxxt"}, {"00xxxxxxxxxxxxxxxxxxxxxxxxxxxxx0"}},
  427. {OFFSET_SDC_RESP0 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  428. {OFFSET_SDC_RESP1 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  429. {OFFSET_SDC_RESP2 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  430. {OFFSET_SDC_RESP3 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  431. {OFFSET_SDC_BLK_NUM , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"10000000000000000000000000000000"}},
  432. {OFFSET_SDC_VOL_CHG , {"aaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxx"}, {"1010001010000000xxxxxxxxxxxxxxxx"}},
  433. {OFFSET_SDC_CSTS , {"cccccccccccccccccccccccccccccccc"}, {"00000000000000000000000000000000"}},
  434. {OFFSET_SDC_CSTS_EN , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  435. {OFFSET_SDC_DCRC_STS , {"rrrrrrrrrrrrrrrrxxxxxxxxxxxxxxxx"}, {"0000000000000000xxxxxxxxxxxxxxxx"}},//bit[12-15] modify
  436. {OFFSET_SDC_ACMD_RESP , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  437. {OFFSET_SDC_ACMD19_TRG, {"aaaaxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  438. {OFFSET_SDC_ACMD19_STS, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  439. {OFFSET_MSDC_DMA_SA_HIGH, {"aaaaxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  440. {OFFSET_MSDC_DMA_SA , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  441. {OFFSET_MSDC_DMA_CA , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  442. {OFFSET_MSDC_DMA_CTRL , {"wrwxxxxxaxaxaaaxxxxxxxxxxxxxxxxx"}, {"000xxxxx0x0x011xxxxxxxxxxxxxxxxx"}}, //need new design, bit[1] = AO
  443. {OFFSET_MSDC_DMA_CFG , {"raxxxxxxaaxxaaxxaxxxxxxxxxxxxxxx"}, {"00xxxxxx00xx00xx0xxxxxxxxxxxxxxx"}},
  444. {OFFSET_MSDC_DBG_SEL , {"aaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxx"}, {"0000000000000000xxxxxxxxxxxxxxxx"}},
  445. {OFFSET_MSDC_DBG_OUT , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  446. {OFFSET_MSDC_DMA_LEN , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}}, //new register in MT6582
  447. {OFFSET_MSDC_PATCH_BIT0, {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"11100000000000000011110000000010"}},
  448. {OFFSET_MSDC_PATCH_BIT1, {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"10010000000000001111111111111111"}},
  449. {OFFSET_MSDC_PATCH_BIT2, {"aaaaaaaaaaaaxaaaaaaaaxaaaaaaaaaa"}, {"00010100100000000001100000000011"}},
  450. {OFFSET_MSDC_PAD_TUNE0, {"aaaaaxxxaaaaaxxxaaaaaxaaaaaaaaaa"}, {"00000xxx00000xxx00000x0000000000"}},
  451. {OFFSET_MSDC_PAD_TUNE1, {"xxxxxxxxaaaaaaxxaaaaaaxxxxxxxxxx"}, {"xxxxxxxx000000xx000000xxxxxxxxxx"}},
  452. {OFFSET_MSDC_DAT_RDDLY0, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  453. {OFFSET_MSDC_DAT_RDDLY1, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  454. {OFFSET_MSDC_DAT_RDDLY2, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  455. {OFFSET_MSDC_DAT_RDDLY3, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  456. {OFFSET_MSDC_HW_DBG , {"aaaaaaaaaaaaaaxxaaaaaaaaaaaaaaax"}, {"00000000000000xx000000000000000x"}},
  457. {OFFSET_MSDC_VERSION , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"11000000010010001100100000000100"}},//20131203
  458. {OFFSET_MSDC_ECO_VER , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},//eco value
  459. };
  460. static reg_desc_t msdc2_reg_desc[] = {
  461. {OFFSET_MSDC_CFG , {"aazaaattaaaaaaaaaaaaccxxxaxxxxxx"}, {"1001100100000000000000xxx1xxxxxx"}}, //bit[2] is rw, but not test. cause this is a reset bit. write to "1" will back to "0" when reset sequence done
  462. {OFFSET_MSDC_IOCON , {"aaaaaaxxaaaaaaxxaaaaaaaaxxxxxxxx"}, {"000000xx000000xx00000000xxxxxxxx"}},
  463. {OFFSET_MSDC_PS , {"atxxxxxxxxxxaaaarrrrrrrrrxxxxxxt"}, {"01xxxxxxxxxx0000111111111xxxxxx1"}},//bit[1]/bit[16-20]/bit[24]/bit[31] default to 0
  464. {OFFSET_MSDC_INT , {"ccxccccccccrcccccccccccxxxxxxxxx"}, {"00x00000000000000000000xxxxxxxxx"}},
  465. {OFFSET_MSDC_INTEN , {"aaxaaaaaaaaaaaaaaaaaaaaxxxxxxxxx"}, {"00x00000000000000000000xxxxxxxxx"}},//bit[2] to ignore
  466. {OFFSET_MSDC_FIFOCS , {"rrrrrrrrxxxxxxxxrrrrrrrrxxxxxxxz"}, {"00000000xxxxxxxx00000000xxxxxxx0"}},//bit[0]~[7] are variable if you use memory tool in Code visor (memory tool must be closed)
  467. {OFFSET_MSDC_TXDATA , {"wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"}, {"00000000000000000000000000000000"}},
  468. //{OFFSET_MSDC_RXDATA , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},/* Should not be touched. */
  469. {OFFSET_SDC_CFG , {"aaxxxxxxxxxxaaaaaaxaaaxxaaaaaaaa"}, {"00xxxxxxxxxx000100x010xx00000000"}},
  470. {OFFSET_SDC_CMD , {"aaaaaaaaaaxaaaaaaaaaaaaaaaaaaaaa"}, {"0000000000x000000000000000000000"}},
  471. {OFFSET_SDC_ARG , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  472. {OFFSET_SDC_STS , {"ttxxxxxxxxxxxxxxxxxxxxxxxxxxxxxt"}, {"00xxxxxxxxxxxxxxxxxxxxxxxxxxxxx0"}},
  473. {OFFSET_SDC_RESP0 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  474. {OFFSET_SDC_RESP1 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  475. {OFFSET_SDC_RESP2 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  476. {OFFSET_SDC_RESP3 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  477. {OFFSET_SDC_BLK_NUM , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"10000000000000000000000000000000"}},
  478. {OFFSET_SDC_CSTS , {"cccccccccccccccccccccccccccccccc"}, {"00000000000000000000000000000000"}},
  479. {OFFSET_SDC_CSTS_EN , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  480. {OFFSET_SDC_DCRC_STS , {"rrrrrrrrrrrrrrrrxxxxxxxxxxxxxxxx"}, {"0000000000000000xxxxxxxxxxxxxxxx"}},//bit[12-15] modify
  481. {OFFSET_SDC_ACMD_RESP , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  482. {OFFSET_SDC_ACMD19_TRG, {"aaaaxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  483. {OFFSET_SDC_ACMD19_STS, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  484. {OFFSET_MSDC_DMA_SA_HIGH, {"aaaaxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  485. {OFFSET_MSDC_DMA_SA , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  486. {OFFSET_MSDC_DMA_CA , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  487. {OFFSET_MSDC_DMA_CTRL , {"wrwrxxxxaaaaaaaxxxxxxxxxxxxxxxxx"}, {"0001xxxx0000011xxxxxxxxxxxxxxxxx"}}, //need new design, bit[1] = AO
  488. {OFFSET_MSDC_DMA_CFG , {"raxxxxxxaaxxaaxxaaxxxxxxxxxxxxxx"}, {"00xxxxxx00xx00xx00xxxxxxxxxxxxxx"}},
  489. {OFFSET_MSDC_DBG_SEL , {"aaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxx"}, {"0000000000000000xxxxxxxxxxxxxxxx"}},
  490. {OFFSET_MSDC_DBG_OUT , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  491. {OFFSET_MSDC_DMA_LEN , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}}, //new register in MT6582
  492. {OFFSET_MSDC_PATCH_BIT0, {"xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"x1100000000000000011110000000010"}},
  493. {OFFSET_MSDC_PATCH_BIT1, {"aaaaaaaaaaaaaaxaxxxxxxxaaaaaaaaa"}, {"10010000000000x0xxxxxxx111111111"}},
  494. {OFFSET_MSDC_PATCH_BIT2, {"aaaaaaaaaaaaxaaaaaaaaxaaaaaaaaaa"}, {"00010100100000000001100000000011"}},
  495. {OFFSET_DAT0_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  496. {OFFSET_DAT1_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  497. {OFFSET_DAT2_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  498. {OFFSET_DAT3_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  499. {OFFSET_CMD_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  500. {OFFSET_SDIO_TUNE_WIND, {"aaaaaxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"00000xxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  501. {OFFSET_MSDC_PAD_TUNE0, {"aaaaaxxxaaaaaxxxaaaaaxaaaaaaaaaa"}, {"00000xxx00000xxx00000x0000000000"}},
  502. {OFFSET_MSDC_PAD_TUNE1, {"xxxxxxxxaaaaaaxxaaaaaaxxxxxxxxxx"}, {"xxxxxxxx000000xx000000xxxxxxxxxx"}},
  503. {OFFSET_MSDC_DAT_RDDLY0, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  504. {OFFSET_MSDC_DAT_RDDLY1, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  505. {OFFSET_MSDC_DAT_RDDLY2, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  506. {OFFSET_MSDC_DAT_RDDLY3, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  507. {OFFSET_MSDC_HW_DBG , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  508. {OFFSET_MSDC_VERSION , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"11000000010010001100100000000100"}},//20131203
  509. {OFFSET_MSDC_ECO_VER , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},//eco value
  510. };
  511. static reg_desc_t msdc3_reg_desc[] = {
  512. {OFFSET_MSDC_CFG , {"aazaaattaaaaaaaaaaaaccxxxaxxxxxx"}, {"1001100100000000000000xxx1xxxxxx"}}, //bit[2] is rw, but not test. cause this is a reset bit. write to "1" will back to "0" when reset sequence done
  513. {OFFSET_MSDC_IOCON , {"aaaaaaxxaaaaaaxxaaaaaaaaxxxxxxxx"}, {"000000xx000000xx00000000xxxxxxxx"}},
  514. {OFFSET_MSDC_PS , {"atxxxxxxxxxxaaaarrrrrrrrrxxxxxxt"}, {"01xxxxxxxxxx0000111111111xxxxxx1"}},//bit[1]/bit[16-20]/bit[24]/bit[31] default to 0
  515. {OFFSET_MSDC_INT , {"ccxccccccccrcccccccccccxxxxxxxxx"}, {"00x00000000000000000000xxxxxxxxx"}},
  516. {OFFSET_MSDC_INTEN , {"aaxaaaaaaaaaaaaaaaaaaaaxxxxxxxxx"}, {"00x00000000000000000000xxxxxxxxx"}},//bit[2] to ignore
  517. {OFFSET_MSDC_FIFOCS , {"rrrrrrrrxxxxxxxxrrrrrrrrxxxxxxxz"}, {"00000000xxxxxxxx00000000xxxxxxx0"}},//bit[0]~[7] are variable if you use memory tool in Code visor (memory tool must be closed)
  518. {OFFSET_MSDC_TXDATA , {"wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"}, {"00000000000000000000000000000000"}},
  519. //{OFFSET_MSDC_RXDATA , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},/* Should not be touched. */
  520. {OFFSET_SDC_CFG , {"aaxxxxxxxxxxaaaaaaxaaaxxaaaaaaaa"}, {"00xxxxxxxxxx000100x010xx00000000"}},
  521. {OFFSET_SDC_CMD , {"aaaaaaaaaaxaaaaaaaaaaaaaaaaaaaaa"}, {"0000000000x000000000000000000000"}},
  522. {OFFSET_SDC_ARG , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  523. {OFFSET_SDC_STS , {"ttxxxxxxxxxxxxxx xxxxxxxxxxxxxxt"}, {"00xxxxxxxxxxxxxxxxxxxxxxxxxxxxx0"}},
  524. {OFFSET_SDC_RESP0 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  525. {OFFSET_SDC_RESP1 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  526. {OFFSET_SDC_RESP2 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  527. {OFFSET_SDC_RESP3 , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  528. {OFFSET_SDC_BLK_NUM , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"10000000000000000000000000000000"}},
  529. {OFFSET_SDC_CSTS , {"cccccccccccccccccccccccccccccccc"}, {"00000000000000000000000000000000"}},
  530. {OFFSET_SDC_CSTS_EN , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  531. {OFFSET_SDC_DCRC_STS , {"rrrrrrrrrrrrrrrrxxxxxxxxxxxxxxxx"}, {"0000000000000000xxxxxxxxxxxxxxxx"}},//bit[12-15] modify
  532. {OFFSET_SDC_ACMD_RESP , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  533. {OFFSET_SDC_ACMD19_TRG, {"aaaaxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  534. {OFFSET_SDC_ACMD19_STS, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  535. {OFFSET_MSDC_DMA_SA_HIGH, {"aaaaxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"0000xxxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  536. {OFFSET_MSDC_DMA_SA , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  537. {OFFSET_MSDC_DMA_CA , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  538. {OFFSET_MSDC_DMA_CTRL , {"wrwrxxxxaaaaaaaxxxxxxxxxxxxxxxxx"}, {"0001xxxx0000011xxxxxxxxxxxxxxxxx"}}, //need new design, bit[1] = AO
  539. {OFFSET_MSDC_DMA_CFG , {"raxxxxxxaaxxaaxxaaxxxxxxxxxxxxxx"}, {"00xxxxxx00xx00xx00xxxxxxxxxxxxxx"}},
  540. {OFFSET_MSDC_DBG_SEL , {"aaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxx"}, {"0000000000000000xxxxxxxxxxxxxxxx"}},
  541. {OFFSET_MSDC_DBG_OUT , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  542. {OFFSET_MSDC_DMA_LEN , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}}, //new register in MT6582
  543. {OFFSET_MSDC_PATCH_BIT0, {"xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"x1100000000000000011110000000010"}},
  544. {OFFSET_MSDC_PATCH_BIT1, {"aaaaaaaaaaaaaaxaxxxxxxxaaaaaaaaa"}, {"10010000000000x0xxxxxxx111111111"}},
  545. {OFFSET_MSDC_PATCH_BIT2, {"aaaaaaaaaaaaxaaaaaaaaxaaaaaaaaaa"}, {"00010100100000000001100000000011"}},
  546. {OFFSET_DAT0_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  547. {OFFSET_DAT1_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  548. {OFFSET_DAT2_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  549. {OFFSET_DAT3_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  550. {OFFSET_CMD_TUNE_CRC, {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},
  551. {OFFSET_SDIO_TUNE_WIND, {"aaaaaxxxxxxxxxxxxxxxxxxxxxxxxxxx"}, {"00000xxxxxxxxxxxxxxxxxxxxxxxxxxx"}},
  552. {OFFSET_MSDC_PAD_TUNE0, {"aaaaaxxxaaaaaxxxaaaaaxaaaaaaaaaa"}, {"00000xxx00000xxx00000x0000000000"}},
  553. {OFFSET_MSDC_PAD_TUNE1, {"xxxxxxxxaaaaaaxxaaaaaaxxxxxxxxxx"}, {"xxxxxxxx000000xx000000xxxxxxxxxx"}},
  554. {OFFSET_MSDC_DAT_RDDLY0, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  555. {OFFSET_MSDC_DAT_RDDLY1, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  556. {OFFSET_MSDC_DAT_RDDLY2, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  557. {OFFSET_MSDC_DAT_RDDLY3, {"aaaaaxxxaaaaaxxxaaaaaxxxaaaaaxxx"}, {"00000xxx00000xxx00000xxx00000xxx"}},
  558. {OFFSET_MSDC_HW_DBG , {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {"00000000000000000000000000000000"}},
  559. {OFFSET_MSDC_VERSION , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"11000000010010001100100000000100"}},//20131203
  560. {OFFSET_MSDC_ECO_VER , {"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"}, {"00000000000000000000000000000000"}},//eco value
  561. };
  562. int msdc_reg_test(struct mmc_host* host, int id, int clock_gate_test)
  563. {
  564. #if (MSDC_MAX_NUM==1)
  565. u32 baddr[] = {MSDC0_BASE};
  566. #elif (MSDC_MAX_NUM==2)
  567. u32 baddr[] = {MSDC0_BASE, MSDC1_BASE};
  568. #elif (MSDC_MAX_NUM==3)
  569. u32 baddr[] = {MSDC0_BASE, MSDC1_BASE, MSDC2_BASE};
  570. #elif (MSDC_MAX_NUM==4)
  571. u32 baddr[] = {MSDC0_BASE, MSDC1_BASE, MSDC2_BASE, MSDC3_BASE};
  572. #elif (MSDC_MAX_NUM==5)
  573. u32 baddr[] = {MSDC0_BASE, MSDC1_BASE, MSDC2_BASE, MSDC3_BASE, MSDC4_BASE};
  574. #endif
  575. u32 base = baddr[id];
  576. u32 i, j, k, l_array_size;
  577. u32 val;
  578. u32 val_shall_be;
  579. u32 val_shall_be_cg;
  580. char v , v_r;
  581. int error = MMC_ERR_NONE;
  582. reg_desc_t* msdc_reg_desc;
  583. int cg_write_test=2;
  584. uint32 ttt;
  585. if (id == 0) {
  586. l_array_size = ARRAY_SIZE(msdc0_reg_desc);
  587. msdc_reg_desc = msdc0_reg_desc;
  588. } else if (id == 1) {
  589. l_array_size = ARRAY_SIZE(msdc1_reg_desc);
  590. msdc_reg_desc = msdc1_reg_desc;
  591. } else if (id == 2) {
  592. l_array_size = ARRAY_SIZE(msdc2_reg_desc);
  593. msdc_reg_desc = msdc2_reg_desc;
  594. } else if (id == 3) {
  595. l_array_size = ARRAY_SIZE(msdc3_reg_desc);
  596. msdc_reg_desc = msdc3_reg_desc;
  597. } else {
  598. msdc_pr_info("Invalid host index: %d\n", id);
  599. goto out;
  600. }
  601. #if 0 //This test won't be performed if whole module reset is not supported
  602. /* [r/t/z/a/k/s/c] check register reset Value
  603. * by pass the bit which can not read and the bit we don't cara about */
  604. msdc_pr_info("Reset default test start\n");
  605. if ( clock_gate_test ) msdc_clock(host, 0);
  606. for (i = 0; i < l_array_size; i++) {
  607. val = MSDC_READ32(base + msdc_reg_desc[i].offset);
  608. msdc_pr_info("Reg %x=%x\n",msdc_reg_desc[i].offset, val);
  609. for (j = 0; j < 32; j++) {
  610. if (('w' == (msdc_reg_desc[i].attr[j])) ||
  611. ('x' == (msdc_reg_desc[i].attr[j])) ||
  612. ('n' == (msdc_reg_desc[i].attr[j])))
  613. continue;
  614. v = (val >> j) & 0x1;
  615. if ( !clock_gate_test ) val_shall_be=msdc_reg_desc[i].reset[j] - '0';
  616. else val_shall_be=0;
  617. if (v != val_shall_be) {
  618. msdc_pr_info("[SD%d] Invalid Reset Value in 0x%x[%d]=%d != %d\n",
  619. id, base + msdc_reg_desc[i].offset, j, v,
  620. val_shall_be);
  621. error = __LINE__;
  622. }
  623. }
  624. }
  625. msdc_pr_info("Reset default test end\n\n");
  626. #endif
  627. if ( clock_gate_test ) goto rw_test;
  628. #if 1
  629. /* [r/t] check read only register: make sure the bit can not be write */
  630. msdc_pr_info("Read-only bits test start\n");
  631. for (i = 0; i < l_array_size; i++) {
  632. for (j = 0; j < 32; j++) {
  633. if (('r' != (msdc_reg_desc[i].attr[j])) && ('t' != (msdc_reg_desc[i].attr[j])) )
  634. continue;
  635. /* Special rule for SDC_STS:
  636. When SDCC_STS.SDCBSY may becomes 1 occasionally after toggle other register bits,
  637. Wait it comes 0 */
  638. if ((u32)SDC_STS == (base + msdc_reg_desc[i].offset)) {
  639. do {
  640. val_shall_be = MSDC_READ32(SDC_STS);
  641. //msdc_pr_info("SDC_STS = %x\n", v);
  642. } while ( val_shall_be & SDC_STS_SDCBUSY );
  643. }
  644. val_shall_be = MSDC_READ32(base + msdc_reg_desc[i].offset);
  645. v_r = (val_shall_be >> j) & 0x1;
  646. if (v_r == 0x0)
  647. MSDC_SET_BIT32(base + msdc_reg_desc[i].offset, 0x1 << j);
  648. else
  649. MSDC_CLR_BIT32(base + msdc_reg_desc[i].offset, 0x1 << j);
  650. v = (MSDC_READ32(base + msdc_reg_desc[i].offset) >> j) & 0x1;
  651. if (v != v_r) {
  652. msdc_pr_info("[SD%d] Read Only Reg Modified in 0x%x[%d]=%d != %d\n",
  653. id, base + msdc_reg_desc[i].offset, j, v, v_r);
  654. error = __LINE__;
  655. }
  656. }
  657. }
  658. msdc_pr_info("Read-only bits test end\n\n");
  659. #endif
  660. rw_test:
  661. #if 1
  662. /* [a] check write register: set or clear the bit, make sure anther bit will not affected */
  663. msdc_pr_info("RW bits test start\n");
  664. for (i = 0; i < l_array_size; i++) {
  665. for (j = 0; j < 32; j++) {
  666. //msdc_pr_info("j %d\n", j);
  667. if ('a' != (msdc_reg_desc[i].attr[j]))
  668. continue;
  669. if ( clock_gate_test && cg_write_test==0 ) goto write_0_test;
  670. write_1_test:
  671. val_shall_be = MSDC_READ32(base + msdc_reg_desc[i].offset);
  672. if (clock_gate_test) {
  673. if (((val_shall_be >> j) & 0x1) == 1)
  674. goto write_0_test;
  675. msdc_clock(host, 0);
  676. val_shall_be_cg = MSDC_READ32(base + msdc_reg_desc[i].offset);
  677. }
  678. //msdc_pr_info("1 val_shall_be %x, cg %x\n", val_shall_be, val_shall_be_cg);
  679. MSDC_SET_BIT32(base + msdc_reg_desc[i].offset, 0x1 << j);
  680. v = (MSDC_READ32(base + msdc_reg_desc[i].offset) >> j) & 0x1;
  681. if ((v != 1) && (!clock_gate_test)) {
  682. msdc_pr_info("[SD%d] Write 1 Failed in Reg 0x%x[%d]=%d != %d\n",
  683. id, base + msdc_reg_desc[i].offset, j, v,
  684. msdc_reg_desc[i].reset[j] - '0');
  685. error = __LINE__;
  686. }
  687. if (clock_gate_test) {
  688. //Value shall not change before clock is un-gated
  689. v = (MSDC_READ32(base + msdc_reg_desc[i].offset) >> j) & 0x1;
  690. if (v != ((val_shall_be_cg >> j) & 0x1)) {
  691. msdc_pr_info("[SD%d] CG Write 1 wrongly effected in Reg 0x%x[%d]=%d != %d, before clock ungate\n",
  692. id, base + msdc_reg_desc[i].offset, j, v,
  693. (val_shall_be_cg >> j) & 0x1);
  694. error = __LINE__;
  695. }
  696. msdc_clock(host, 1);
  697. v = (MSDC_READ32(base + msdc_reg_desc[i].offset) >> j) & 0x1;
  698. //Value shall not change after clock is un-gated
  699. if (v !=((val_shall_be >> j) & 0x1)) {
  700. msdc_pr_info("[SD%d] CG Write 1 wrongly effected in Reg 0x%x[%d]=%d != %d, after clock ungate\n",
  701. id, base + msdc_reg_desc[i].offset, j, v,
  702. (val_shall_be >> j) & 0x1);
  703. error = __LINE__;
  704. }
  705. }
  706. if (!clock_gate_test) {
  707. /* exception rule for clock stable */
  708. if (((u32)MSDC_CFG == (base + msdc_reg_desc[i].offset)) &&
  709. (j >= 8 && j < 20)) { /* wait clock stable */
  710. while (!(MSDC_READ32(MSDC_CFG) & MSDC_CFG_CKSTB));
  711. }
  712. }
  713. /* check other bits are not affected by write 1 */
  714. if (!clock_gate_test) {
  715. for (k = 0; k < 32; k++) {
  716. if (k == j)
  717. continue;
  718. if (('w' == (msdc_reg_desc[i].attr[k])) ||
  719. ('x' == (msdc_reg_desc[i].attr[k])) ||
  720. ('t' == (msdc_reg_desc[i].attr[k])))
  721. continue;
  722. v = (MSDC_READ32(base + msdc_reg_desc[i].offset) >> k) & 0x1;
  723. if (v != ((val_shall_be>>k) & 0x1)) {
  724. msdc_pr_info("[SD%d] Affected by Write 1 to 0x%x[%d] and [%d]=%d != %d\n",
  725. id, base + msdc_reg_desc[i].offset, j, k, v,
  726. ((val_shall_be>>k) & 0x1));
  727. error = __LINE__;
  728. }
  729. }
  730. }
  731. if (clock_gate_test && cg_write_test==1)
  732. goto restore_value;
  733. write_0_test:
  734. /* write 0 to target bit */
  735. val_shall_be = MSDC_READ32(base + msdc_reg_desc[i].offset);
  736. if (clock_gate_test) {
  737. if (((val_shall_be >> j) & 0x1) == 0)
  738. goto restore_value;
  739. msdc_clock(host, 0);
  740. val_shall_be_cg = MSDC_READ32(baddr[id] + msdc_reg_desc[i].offset);
  741. }
  742. //msdc_pr_info("0 val_shall_be %x, cg %x\n", val_shall_be, val_shall_be_cg);
  743. MSDC_CLR_BIT32(base + msdc_reg_desc[i].offset, 0x1 << j);
  744. v = (MSDC_READ32(base + msdc_reg_desc[i].offset) >> j) & 0x1;
  745. if ((v != 0) && (!clock_gate_test)) {
  746. msdc_pr_info("[SD%d] Write 0 Reg Failed in 0x%x[%d]=%d != %d\n",
  747. id, base + msdc_reg_desc[i].offset, j, v,
  748. msdc_reg_desc[i].reset[j] - '0');
  749. error = __LINE__;
  750. }
  751. if (clock_gate_test) {
  752. //Value shall not change before clock is un-gated
  753. v = (MSDC_READ32(base + msdc_reg_desc[i].offset) >> j) & 0x1;
  754. if (v !=((val_shall_be_cg >> j) & 0x1)) {
  755. msdc_pr_info("[SD%d] CG Write 0 wrongly effected in Reg 0x%x[%d]=%d != %d, before clock ungate\n",
  756. id, base + msdc_reg_desc[i].offset, j, v,
  757. (val_shall_be_cg >> j) & 0x1);
  758. error = __LINE__;
  759. }
  760. //Value shall not change after clock is un-gated
  761. msdc_clock(host, 1);
  762. v = (MSDC_READ32(base + msdc_reg_desc[i].offset) >> j) & 0x1;
  763. if (v !=((val_shall_be >> j) & 0x1)) {
  764. msdc_pr_info("[SD%d] CG Write 0 wrongly effected in Reg 0x%x[%d]=%d != %d, after clock ungate\n",
  765. id, base + msdc_reg_desc[i].offset, j, v,
  766. (val_shall_be >> j) & 0x1);
  767. error = __LINE__;
  768. }
  769. }
  770. if (!clock_gate_test) {
  771. /* exception rule for clock stable */
  772. if (((u32)MSDC_CFG == (base + msdc_reg_desc[i].offset)) &&
  773. (j >= 8 && j < 20)) { /* wait clock stable */
  774. while (!(MSDC_READ32(MSDC_CFG) & MSDC_CFG_CKSTB));
  775. }
  776. }
  777. /* check other bits are not affected by write 0 */
  778. if (!clock_gate_test) {
  779. for (k = 0; k < 32; k++) {
  780. if (k == j)
  781. continue;
  782. if (('w' == (msdc_reg_desc[i].attr[k])) ||
  783. ('x' == (msdc_reg_desc[i].attr[k])) ||
  784. ('t' == (msdc_reg_desc[i].attr[k])))
  785. continue;
  786. v = (MSDC_READ32(base + msdc_reg_desc[i].offset) >> k) & 0x1;
  787. if (v != ((val_shall_be>>k) & 0x1)) {
  788. msdc_pr_info("[SD%d] Affected by Write 0 to 0x%x[%d] and [%d]=%d != %d\n",
  789. id, base + msdc_reg_desc[i].offset, j, k, v,
  790. ((val_shall_be>>k) & 0x1));
  791. error = __LINE__;
  792. }
  793. }
  794. }
  795. restore_value:
  796. /* restore default value */
  797. if ((msdc_reg_desc[i].reset[j] - '0') == 1) {
  798. MSDC_SET_BIT32(base + msdc_reg_desc[i].offset, 0x1 << j);
  799. } else {
  800. MSDC_CLR_BIT32(base + msdc_reg_desc[i].offset, 0x1 << j);
  801. }
  802. }
  803. }
  804. if ( clock_gate_test && cg_write_test==1 ) {
  805. cg_write_test=0;
  806. goto rw_test;
  807. }
  808. msdc_pr_info("RW bits test end\n\n");
  809. #endif
  810. if ( clock_gate_test ) goto out;
  811. #if 1
  812. /* [z] check AO register, write 1, wait 100ms, check the result */
  813. msdc_pr_info("AO bits test start\n");
  814. for (i = 0; i < l_array_size; i++) {
  815. for (j = 0; j < 32; j++) {
  816. if ('z' != (msdc_reg_desc[i].attr[j]))
  817. continue;
  818. MSDC_SET_BIT32(base + msdc_reg_desc[i].offset, 0x1 << j);
  819. mdelay(100);
  820. v =(MSDC_READ32(base + msdc_reg_desc[i].offset) >> j) & 0x1;
  821. if (v != 0) {
  822. 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",
  823. id, base + msdc_reg_desc[i].offset, j, v);
  824. error = __LINE__;
  825. }
  826. }
  827. }
  828. msdc_pr_info("AO bits test end\n\n");
  829. #endif
  830. out:
  831. return error;
  832. }
  833. int mmc_readback_blks(int dev_id, unsigned long addr, int blks, int bootarea)
  834. {
  835. int i, j, result = 0;
  836. u8 val;
  837. u8 *ext_csd;
  838. unsigned long blknr = addr / MMC_BLOCK_SIZE;
  839. unsigned char *buf = (unsigned char*)MMC_BUF_ADDR;
  840. struct mmc_card *card;
  841. struct mmc_host *host;
  842. host = mmc_get_host(dev_id);
  843. card = mmc_get_card(dev_id);
  844. ext_csd = &card->raw_ext_csd[0];
  845. if (bootarea && !mmc_card_sd(card)) {
  846. /* configure to specified partition */
  847. val = (ext_csd[EXT_CSD_PART_CFG] & ~0x7) | EXT_CSD_PART_CFG_BOOT_PART_1;
  848. if (mmc_set_part_config(card, val) != MMC_ERR_NONE) {
  849. result = -__LINE__;
  850. goto done;
  851. }
  852. if (mmc_read_ext_csd(host, card) != MMC_ERR_NONE) {
  853. result = -__LINE__;
  854. goto done;
  855. }
  856. }
  857. msdc_pr_info("[SD%d] Dump %d blks from 0x%lx (FLASH)\n", dev_id, blks,
  858. blknr * MMC_BLOCK_SIZE);
  859. for (i = 0; i < blks; i++) {
  860. memset(buf, 0, MMC_BLOCK_SIZE);
  861. if (MMC_ERR_NONE != mmc_block_read(dev_id, blknr + i, 1, (unsigned long*)buf)) {
  862. msdc_pr_info("\n[SD%d] Read from %ldth block error\n", dev_id, blknr + i);
  863. break;
  864. }
  865. for (j = 0; j < MMC_BLOCK_SIZE; j++) {
  866. if (j % 16 == 0)
  867. msdc_pr_info("\n%lxh: ", (blknr + i) * MMC_BLOCK_SIZE + j);
  868. msdc_pr_info("%x ", buf[j]);
  869. }
  870. msdc_pr_info("\n");
  871. buf += MMC_BLOCK_SIZE;
  872. }
  873. done:
  874. if (bootarea && !mmc_card_sd(card)) {
  875. /* configure to user partition */
  876. val = (ext_csd[EXT_CSD_PART_CFG] & ~0x7) | EXT_CSD_PART_CFG_DEFT_PART;
  877. if (mmc_set_part_config(card, val) != MMC_ERR_NONE)
  878. result = -__LINE__;
  879. if (mmc_read_ext_csd(host, card) != MMC_ERR_NONE) {
  880. result = -__LINE__;
  881. }
  882. }
  883. return result;
  884. }
  885. #if 0
  886. int mmc_readback_part(int dev_id, char *part_name, int bootarea)
  887. {
  888. int ret = -1;
  889. part_t *part = mt6573_part_get_partition(part_name);
  890. if (part) {
  891. ret = mmc_readback_blks(dev_id, part->startblk * BLK_SIZE,
  892. 1, bootarea);
  893. }
  894. return ret;
  895. }
  896. #endif
  897. int mmc_erase_blks(int dev_id, u32 addr, u32 size, int bootarea)
  898. {
  899. int result = 0;
  900. u8 val;
  901. u8 *ext_csd;
  902. u32 blknr;
  903. u32 total_blks;
  904. struct mmc_card *card;
  905. if (!size)
  906. return 0;
  907. if (addr % MMC_BLOCK_SIZE)
  908. return MMC_ERR_FAILED;
  909. card = mmc_get_card(dev_id);
  910. ext_csd = &card->raw_ext_csd[0];
  911. blknr = addr / MMC_BLOCK_SIZE;
  912. total_blks = (size + MMC_BLOCK_SIZE - 1) / MMC_BLOCK_SIZE;
  913. if (bootarea && !mmc_card_sd(card) && card->ext_csd.part_en) {
  914. /* configure to specified partition */
  915. val = (ext_csd[EXT_CSD_PART_CFG] & ~0x7) | EXT_CSD_PART_CFG_BOOT_PART_1;
  916. if (mmc_set_part_config(card, val) != MMC_ERR_NONE) {
  917. result = -__LINE__;
  918. goto done;
  919. }
  920. }
  921. if (mmc_erase_start(card, blknr * MMC_BLOCK_SIZE) != MMC_ERR_NONE) {
  922. result = -__LINE__;
  923. goto done;
  924. }
  925. if (mmc_erase_end(card, (blknr + total_blks) * MMC_BLOCK_SIZE) != MMC_ERR_NONE) {
  926. result = -__LINE__;
  927. goto done;
  928. }
  929. if (mmc_erase(card, MMC_ERASE_NORMAL) != MMC_ERR_NONE) {
  930. result = -__LINE__;
  931. goto done;
  932. }
  933. done:
  934. if (bootarea && !mmc_card_sd(card) && card->ext_csd.part_en) {
  935. /* configure to user partition */
  936. val = (ext_csd[EXT_CSD_PART_CFG] & ~0x7) | EXT_CSD_PART_CFG_DEFT_PART;
  937. if (mmc_set_part_config(card, val) != MMC_ERR_NONE)
  938. result = -__LINE__;
  939. }
  940. if (!result) {
  941. msdc_pr_info("[SD%d] Erase %d blocks (%d bytes) from 0x%x successfully\n",
  942. dev_id, total_blks, total_blks * MMC_BLOCK_SIZE, blknr * MMC_BLOCK_SIZE);
  943. } else {
  944. msdc_pr_info("[SD%d] Erase %d blocks (%d bytes) from 0x%x failed %d\n",
  945. dev_id, total_blks, total_blks * MMC_BLOCK_SIZE, blknr * MMC_BLOCK_SIZE, result);
  946. }
  947. return result;
  948. }
  949. #if 0
  950. int mmc_erase_part(int dev_id, char *part_name, int bootarea)
  951. {
  952. int ret = -1;
  953. part_t *part = mt6573_part_get_partition(part_name);
  954. if (part) {
  955. /* Notice that the block size is different with different emmc.
  956. * Thus, it could overwrite other partitions while erasing data.
  957. */
  958. ret = mmc_erase_blks(dev_id, part->startblk * BLK_SIZE,
  959. part->blknum * BLK_SIZE, bootarea);
  960. }
  961. return ret;
  962. }
  963. #endif
  964. #ifdef MMC_BOOT_TEST
  965. int mmc_boot_up_test(int id, int reset)
  966. {
  967. int err = MMC_ERR_FAILED;
  968. struct mmc_host *host;
  969. int clksrc = (id == 0) ? MSDC50_CLKSRC_26MHZ: MSDC30_CLKSRC_26MHZ;
  970. host = mmc_get_host(id);
  971. mmc_init_host(host, id, cfg->clksrc, MSDC_MODE_PIO)
  972. msdc_emmc_boot_reset(host, reset);
  973. err = msdc_emmc_boot_start(host, 25000000, 0, EMMC_BOOT_RST_CMD_MODE, (u64)0);
  974. if (err) {
  975. msdc_pr_info("[EMMC] Boot Error: %d\n", err);
  976. goto done;
  977. }
  978. err = msdc_emmc_boot_read(host, (u64)128 * 1024, MMC_BUF_ADDR);
  979. msdc_emmc_boot_stop(host);
  980. done:
  981. if (!err) {
  982. int i, j;
  983. char *buf = (char*)MMC_BUF_ADDR;
  984. for (i = 0; i < 16; i++) {
  985. for (j = 0; j < MMC_BLOCK_SIZE; j++) {
  986. if (j % 16 == 0)
  987. msdc_pr_info("\n%.8xh: ", i * MMC_BLOCK_SIZE + j);
  988. msdc_pr_info("%.2x ", buf[j]);
  989. }
  990. msdc_pr_info("\n");
  991. buf += MMC_BLOCK_SIZE;
  992. }
  993. }
  994. return err;
  995. }
  996. int mmc_boot_enable(int id, int bootpart)
  997. {
  998. int err = MMC_ERR_FAILED;
  999. struct mmc_host *host;
  1000. struct mmc_card *card;
  1001. host = mmc_get_host(id);
  1002. card = mmc_get_card(id);
  1003. err = mmc_boot_config(card, EXT_CSD_PART_CFG_EN_ACK,
  1004. bootpart, EXT_CSD_BOOT_BUS_WIDTH_1, EXT_CSD_BOOT_BUS_MODE_DEFT);
  1005. if (err != 0)
  1006. goto done;
  1007. err = mmc_read_ext_csd(host, card);
  1008. done:
  1009. return err;
  1010. }
  1011. #endif
  1012. int mmc_test_dump_buff(char *buffer,int index,int buf_size)
  1013. {
  1014. int start_index = index - 256 > 0 ? index-256:0;
  1015. int end_index = index + 256 < buf_size ? index + 256 : buf_size;
  1016. int i = 0;
  1017. msdc_pr_info("dump error buffer\n");
  1018. for (; i < end_index - start_index; i++) {
  1019. if (i%8 == 0)
  1020. msdc_pr_info("\n");
  1021. msdc_pr_info("0x%x ",buffer[start_index+i]);
  1022. }
  1023. return 0;
  1024. }
  1025. int mmc_test_mem_card(struct mmc_test_config *cfg)
  1026. {
  1027. int id, count, forever;
  1028. int ret, chk_result, tid = 0, result = 0;
  1029. unsigned int chunks, chunk_blks, left_blks, pass = 0, fail = 0;
  1030. unsigned int total_blks;
  1031. unsigned int i, j;
  1032. unsigned int blksz;
  1033. unsigned int clkhz;
  1034. unsigned int status;
  1035. //unsigned int base;
  1036. char pattern = 0;
  1037. char *buf;
  1038. unsigned long blknr;
  1039. struct mmc_host *host;
  1040. struct mmc_card *card;
  1041. unsigned char tests[3];
  1042. char *tests_str[] = {"single", "multiple", "interleave"};
  1043. unsigned int tests_idx;
  1044. unsigned int inited = 0;
  1045. id = cfg->id;
  1046. count = cfg->count;
  1047. buf = cfg->buf;
  1048. blknr = cfg->blknr;
  1049. blksz = cfg->blksz;
  1050. chk_result = cfg->chk_result;
  1051. chunk_blks = cfg->chunk_blks;
  1052. total_blks = (cfg->total_size + blksz - 1) / blksz;
  1053. forever = (count == -1) ? 1 : 0;
  1054. tests[0] = cfg->tst_single;
  1055. tests[1] = cfg->tst_multiple;
  1056. tests[2] = cfg->tst_interleave;
  1057. host = mmc_get_host(id);
  1058. card = mmc_get_card(id);
  1059. /*ting-hao notice here!!*/
  1060. cache_clean_invalidate();
  1061. while (forever || count--) {
  1062. msdc_pr_info("[TST] ==============================================\n");
  1063. msdc_pr_info("[TST] read/write buf address : 0x%x\n", (unsigned int)buf);
  1064. msdc_pr_info("[TST] BEGIN: %d/%d, No Stop(%d)\n",
  1065. (cfg->count != -1) ? cfg->count - count : 0,
  1066. (cfg->count != -1) ? cfg->count : 0, forever);
  1067. msdc_pr_info("[TST] ----------------------------------------------\n");
  1068. msdc_pr_info("[TST] Mode : %d\n", cfg->mode);
  1069. msdc_pr_info("[TST] Clock : %d kHz\n", cfg->clock / 1000);
  1070. msdc_pr_info("[TST] BusWidth: %d bits\n", cfg->buswidth);
  1071. msdc_pr_info("[TST] DDR : %d \n", (msdc_cap[id].flags & MSDC_DDR)? 1:0);
  1072. msdc_pr_info("[TST] BurstSz : %d bytes\n", 0x1 << cfg->burstsz);
  1073. /*ting-hao notice here!!*/
  1074. msdc_pr_info("[TST] BlkAddr : %xh\n", (unsigned int)blknr);
  1075. msdc_pr_info("[TST] BlkSize : %dbytes\n", blksz);
  1076. msdc_pr_info("[TST] TstBlks : %d\n", total_blks);
  1077. msdc_pr_info("[TST] AutoCMD : 12(%d), 23(%d)\n",
  1078. (cfg->autocmd & MSDC_AUTOCMD12) ? 1 : 0,
  1079. (cfg->autocmd & MSDC_AUTOCMD23) ? 1 : 0);
  1080. msdc_pr_info("[TST] CheckResult : %d\n", cfg->chk_result);
  1081. msdc_pr_info("[TST] ----------------------------------------------\n");
  1082. if ((cfg->skip_reinit==0) || (inited==0)) {
  1083. if (mmc_init_host(host, id, cfg->clksrc, cfg->mode) != 0) {
  1084. result = -__LINE__;
  1085. goto failure;
  1086. }
  1087. if (mmc_init_card(host, card) != 0) {
  1088. result = -__LINE__;
  1089. goto failure;
  1090. }
  1091. inited = 1;
  1092. msdc_apply_timing(id);
  1093. msdc_set_dma(host, (u8)cfg->burstsz, (u32)cfg->flags);
  1094. msdc_set_autocmd(host, cfg->autocmd, 1);
  1095. #ifndef SLT
  1096. if (cfg->reg_tst.test) {
  1097. if(cfg->reg_tst.Test_PB0_RD_DAT_SEL) {
  1098. msdc_pr_info("[Test item] fifo edge 0xB0[4] = %d\n", cfg->reg_tst.PB0_RD_DAT_SEL);
  1099. msdc_set_fifo_edge(host, cfg->reg_tst.PB0_RD_DAT_SEL);
  1100. }
  1101. if(cfg->reg_tst.Test_Start_bit_chk) {
  1102. msdc_pr_info("[Test item] Start bit check 0xB0[0] = %d\n", cfg->reg_tst.PB0_EN_STBIT_CHKSUP);
  1103. msdc_set_startbit_chk(host, cfg->reg_tst.PB0_EN_STBIT_CHKSUP);
  1104. }
  1105. if(cfg->reg_tst.Test_Check_Busy) {
  1106. msdc_pr_info("[Test item] Busy check 0xB4[7] = %d\n", cfg->reg_tst.PB0_EN_STBIT_CHKSUP);
  1107. msdc_pr_info("[Test item] wrdto 0xB4[7] = %d\n", cfg->reg_tst.WriteDatTimeOut);
  1108. msdc_set_busychk(host, cfg->reg_tst.PB1_BUSY_CHECK_SEL);
  1109. msdc_set_wrdtoc(host, cfg->reg_tst.WriteDatTimeOut);
  1110. }
  1111. }
  1112. /* change uhs-1 mode */
  1113. if (mmc_card_uhs1(card) && (cfg->uhsmode != -1)) {
  1114. if (mmc_switch_uhs1(host, card, cfg->uhsmode) != 0) {
  1115. result = -__LINE__;
  1116. //goto failure;
  1117. }
  1118. }
  1119. /* Since SLT use default setting after initialization,
  1120. skip redundant setting to reduce log for reducing test time */
  1121. /* change clock */
  1122. //msdc_pr_info("card->maxhz(%d), cfg->clock(%d)\n",card->maxhz,cfg->clock);
  1123. if (cfg->clock) {
  1124. clkhz = card->maxhz < cfg->clock ? card->maxhz : cfg->clock;
  1125. mmc_set_clock(host, mmc_card_ddr(card), clkhz);
  1126. }
  1127. //msdc_pr_info("host->src_clk(%d)\n",host->src_clk);
  1128. if (mmc_card_sd(card) && cfg->buswidth == HOST_BUS_WIDTH_8) {
  1129. msdc_pr_info("[TST] SD card doesn't support 8-bit bus width (SKIP)\n");
  1130. result = MMC_ERR_NONE;
  1131. }
  1132. msdc_pr_info("cfg->buswidth(%d)\n",cfg->buswidth);
  1133. if (mmc_set_bus_width(host, card, cfg->buswidth) != 0) {
  1134. result = -__LINE__;
  1135. goto failure;
  1136. }
  1137. /* cmd16 is illegal while card is in ddr mode */
  1138. if (!(mmc_card_mmc(card) && (mmc_card_ddr(card) || mmc_card_hs400(card)))) {
  1139. if (mmc_set_blk_length(host, blksz) != 0) {
  1140. result = -__LINE__;
  1141. goto failure;
  1142. }
  1143. }
  1144. #endif
  1145. tid = result = 0;
  1146. if (cfg->piobits) {
  1147. msdc_pr_info("[TST] PIO bits: %d\n", cfg->piobits);
  1148. msdc_set_pio_bits(host, cfg->piobits);
  1149. }
  1150. /* show the init test condition, its useful for debug */
  1151. //base = host->base;
  1152. //MSDC_WRITE32(MSDC_PATCH_BIT1, 0xFFFE00C9); /* 2013-1-6 close KPI for e2 eco verify */
  1153. //msdc_dump_register(host);
  1154. if (cfg->start_bit) {
  1155. msdc_pr_info("start bit=%d\n", (cfg->start_bit - 1));
  1156. msdc_set_startbit(host,(cfg->start_bit - 1));
  1157. }
  1158. if (cfg->axi_burst_len) {
  1159. msdc_pr_info("axi_burst_len=%d\n", (cfg->axi_burst_len - 1));
  1160. msdc_set_axi_burst_len(host,(cfg->axi_burst_len - 1));
  1161. }
  1162. if (cfg->axi_rd_os) {
  1163. msdc_pr_info("axi_rd_os=%d\n", (cfg->axi_rd_os));
  1164. msdc_set_axi_outstanding(host, 0, (cfg->axi_rd_os));
  1165. }
  1166. if (cfg->axi_wr_os) {
  1167. msdc_pr_info("axi_wr_os=%d\n", (cfg->axi_wr_os));
  1168. msdc_set_axi_outstanding(host, 1, (cfg->axi_wr_os));
  1169. }
  1170. msdc_set_signal_burst(host, cfg->single_bst);
  1171. }
  1172. tid = result = 0;
  1173. #if 0 //UT only, change to "if 0" temporarily
  1174. if (mmc_erase_start(card, blknr * blksz) != MMC_ERR_NONE) {
  1175. result = -__LINE__;
  1176. goto failure;
  1177. }
  1178. if (mmc_erase_end(card, (blknr + total_blks) * blksz) != MMC_ERR_NONE) {
  1179. result = -__LINE__;
  1180. goto failure;
  1181. }
  1182. if (mmc_erase(card, MMC_ERASE_NORMAL) != MMC_ERR_NONE) {
  1183. result = -__LINE__;
  1184. goto failure;
  1185. }
  1186. msdc_pr_info("[TST] 0x%x - 0x%x Erased\n", blknr * blksz,
  1187. (blknr + total_blks) * blksz);
  1188. msdc_pr_info("host->sclk(%d)\n",host->sclk);
  1189. msdc_pr_info(TC_MSG "test block erase\n",
  1190. host->id, result == 0 ? "PASS" : "FAIL", tid++);
  1191. #endif
  1192. mmc_send_status(host, card, &status);
  1193. tests_idx = 0;
  1194. #if 0
  1195. #ifdef autok_test
  1196. autok_test_host.base = host->base;
  1197. //autok_test_host.hclk= 400000000;
  1198. //autok_test_host.sclk= 200000000;
  1199. autok_test_host.hclk= mmc_card_ddr(card)? cfg->clksrc * 2 : cfg->clksrc;
  1200. autok_test_host.sclk= cfg->clksrc;
  1201. //autok_test_host.hclk= mmc_card_ddr(card)? host->cur_bus_clk * 2 : host->cur_bus_clk;
  1202. //autok_test_host.sclk=host->cur_bus_clk;
  1203. autok_test_host.hw=(&autok_hw);
  1204. autok_test_host.ios=(&autok_ios);
  1205. autok_hw.host_function=host->id;
  1206. autok_auto_test(&autok_test_host);
  1207. #endif
  1208. /*ting-hao notice here!!*/
  1209. mmc_switch_cache(host, 0);
  1210. #define RAND_BLK_ADDR
  1211. #ifdef RAND_BLK_ADDR
  1212. /*ting-hao notice here!!*/
  1213. do {
  1214. CTP_GetRandom(&blknr, card->nblks);
  1215. if ( blknr+total_blks <card->nblks ) break;
  1216. } while (1);
  1217. /*ting-hao notice here!!*/
  1218. msdc_pr_info("[TST] BlkAddr : %xh\n", (unsigned int)blknr);
  1219. #endif
  1220. #endif
  1221. while (tests_idx<2) {
  1222. if (!tests[tests_idx]) {
  1223. tests_idx++;
  1224. continue;
  1225. }
  1226. if (tests_idx == 0) {
  1227. chunk_blks = 1;
  1228. chunks = 8;
  1229. left_blks = 0;
  1230. } else {
  1231. chunk_blks = cfg->chunk_blks;
  1232. chunks = total_blks / chunk_blks;
  1233. left_blks = total_blks % chunk_blks;;
  1234. }
  1235. msdc_pr_info("total_blks(%d),chunks(%d),left_blks(%d)\n", total_blks, chunks, left_blks);
  1236. #if 1
  1237. for (i = 0; i < chunks; i++) {
  1238. if (tests_idx == 0)
  1239. pattern = (i + count +1) % 256;
  1240. else
  1241. pattern = (i + count) % 256;
  1242. memset(buf, pattern, blksz * chunk_blks);
  1243. #if 0 // dump the write buf
  1244. msdc_pr_info("the %d block data in write buf\n", i);
  1245. for (j = 0; j < blksz * chunk_blks; j++) {
  1246. msdc_pr_info("0x%x ", buf[j]);
  1247. if ((j+1)%8 == 0)
  1248. msdc_pr_info("\n");
  1249. }
  1250. #endif
  1251. ret = mmc_block_write(id, blknr + i * chunk_blks,
  1252. chunk_blks, (unsigned long*)buf);
  1253. if (ret != MMC_ERR_NONE) {
  1254. result = -__LINE__;
  1255. goto failure;
  1256. }
  1257. }
  1258. if (!result && left_blks) {
  1259. pattern = (i + count) % 256;
  1260. memset(buf, pattern, blksz * left_blks);
  1261. ret = mmc_block_write(id, blknr + chunks * chunk_blks,
  1262. left_blks, (unsigned long*)buf);
  1263. if (ret != MMC_ERR_NONE) {
  1264. result = -__LINE__;
  1265. goto failure;
  1266. }
  1267. }
  1268. msdc_pr_info(TC_MSG "test %s block write\n",
  1269. host->id, result == 0 ? "PASS" : "FAIL", tid++, tests_str[tests_idx]);
  1270. if (result)
  1271. goto failure;
  1272. #endif
  1273. #if 1
  1274. /* block read */
  1275. for (i = 0; i < chunks; i++) {
  1276. if (tests_idx == 0)
  1277. pattern = (i + count +1) % 256;
  1278. else
  1279. pattern = (i + count) % 256;
  1280. memset(buf, pattern^0xFF, blksz * chunk_blks);
  1281. ret = mmc_block_read(id, blknr + i * chunk_blks,
  1282. chunk_blks, (unsigned long*)buf);
  1283. if (ret != MMC_ERR_NONE) {
  1284. msdc_pr_info("[SD%d]\t\tread %d blks failed(ret = %d blks), buf(0x%x)\n",
  1285. host->id, chunk_blks, ret, (unsigned int)buf);
  1286. result = -__LINE__;
  1287. goto failure;
  1288. }
  1289. if (chk_result) {
  1290. for (j = 0; j < chunk_blks * blksz; j++) {
  1291. if (buf[j] != pattern) {
  1292. msdc_pr_info("[SD%d]\t\t%lxh = %x (!= %x)\n",
  1293. host->id, blknr + i * chunk_blks, buf[j], pattern);
  1294. msdc_pr_info("j(%d),buf[j](%d),pattern(%d)\n",j,buf[j],pattern);
  1295. msdc_pr_info("dump read value at addr0x%x", (unsigned int)(buf + j));
  1296. mmc_test_dump_buff(buf,j,chunk_blks * blksz);
  1297. msdc_pr_info("dump write value at addr0x%x", (unsigned int)(buf + j));
  1298. mmc_test_dump_buff(buf,j,chunk_blks * blksz);
  1299. result = -__LINE__;
  1300. goto failure;
  1301. }
  1302. }
  1303. }
  1304. }
  1305. if (!result && left_blks) {
  1306. if (tests_idx == 0)
  1307. pattern = (i + count +1) % 256;
  1308. else
  1309. pattern = (i + count) % 256;
  1310. memset(buf, pattern^0xFF, blksz * left_blks);
  1311. ret = mmc_block_read(id, blknr + chunks * chunk_blks,
  1312. left_blks, (unsigned long*)buf);
  1313. if (ret != MMC_ERR_NONE) {
  1314. msdc_pr_info("[SD%d]\t\tread %d blks failed(ret = %d blks)\n",
  1315. host->id, left_blks, ret);
  1316. result = -__LINE__;
  1317. goto failure;
  1318. }
  1319. if (chk_result) {
  1320. for (j = 0; j < left_blks * blksz; j++) {
  1321. if (buf[j] != pattern) {
  1322. msdc_pr_info("[SD%d] 0x%x = %x (!= %x),j(%d)\n",
  1323. host->id, blknr + chunks * chunk_blks, buf[j], pattern,j);
  1324. msdc_pr_info("j(%d),buf[j](%d),pattern(%d)\n",j,buf[j],pattern);
  1325. msdc_pr_info("dump read value at addr0x%x\n", (unsigned int)(buf + j));
  1326. mmc_test_dump_buff(buf,j,chunk_blks * blksz);
  1327. msdc_pr_info("dump write value at addr0x%x\n", (unsigned int)(buf + j));
  1328. mmc_test_dump_buff(buf,j,chunk_blks * blksz);
  1329. result = -__LINE__;
  1330. goto failure;
  1331. }
  1332. }
  1333. }
  1334. }
  1335. msdc_pr_info(TC_MSG "test %s block read\n",
  1336. host->id, result == 0 ? "PASS" : "FAIL", tid++, tests_str[tests_idx]);
  1337. if (result)
  1338. goto failure;
  1339. #endif
  1340. mmc_send_status(host, card, &status);
  1341. tests_idx++;
  1342. }
  1343. #if 1
  1344. if (cfg->tst_interleave) {
  1345. /* multiple block write */
  1346. chunks = total_blks / chunk_blks;
  1347. left_blks = total_blks % chunk_blks;
  1348. for (i = 0; i < chunks; i++) {
  1349. pattern = (i + count) % 256;
  1350. memset(buf, pattern, blksz * chunk_blks);
  1351. ret = mmc_block_write(id, blknr + i * chunk_blks,
  1352. chunk_blks, (unsigned long*)buf);
  1353. if (ret != MMC_ERR_NONE) {
  1354. result = -__LINE__;
  1355. goto failure;
  1356. }
  1357. /* populate buffer with different pattern */
  1358. memset(buf, pattern ^ 0xFF, blksz * chunk_blks);
  1359. ret = mmc_block_read(id, blknr + i * chunk_blks,
  1360. chunk_blks, (unsigned long*)buf);
  1361. if (ret != MMC_ERR_NONE) {
  1362. result = -__LINE__;
  1363. goto failure;
  1364. }
  1365. if (chk_result) {
  1366. for (j = 0; j < chunk_blks * blksz; j++) {
  1367. if (buf[j] == pattern)
  1368. continue;
  1369. msdc_pr_info("[SD%d] 0x%x = %x (!= %x),j(%d)\n",
  1370. host->id, blknr + i * chunk_blks, buf[j], pattern,j);
  1371. msdc_pr_info("j(%d),buf[j](%d),pattern(%d)\n",j,buf[j],pattern);
  1372. mmc_test_dump_buff(buf,j,chunk_blks * blksz);
  1373. result = -__LINE__;
  1374. goto failure;
  1375. }
  1376. }
  1377. }
  1378. if (!result && left_blks) {
  1379. pattern = (i + count) % 256;
  1380. memset(buf, pattern, blksz * left_blks);
  1381. ret = mmc_block_write(id, blknr + chunks * chunk_blks,
  1382. left_blks, (unsigned long*)buf);
  1383. if (ret != MMC_ERR_NONE) {
  1384. result = -__LINE__;
  1385. goto failure;
  1386. }
  1387. /* populate buffer with different pattern */
  1388. memset(buf, pattern ^ 0xFF, blksz * left_blks);
  1389. ret = mmc_block_read(id, blknr + chunks * chunk_blks,
  1390. left_blks, (unsigned long*)buf);
  1391. if (ret != MMC_ERR_NONE) {
  1392. result = -__LINE__;
  1393. break;
  1394. }
  1395. if (chk_result) {
  1396. for (j = 0; j < left_blks * blksz; j++) {
  1397. if (buf[j] == pattern)
  1398. continue;
  1399. msdc_pr_info("[SD%d] 0x%x = %x (!= %x),j(%d)\n",
  1400. host->id, blknr + chunks * chunk_blks, buf[j], pattern,j);
  1401. msdc_pr_info("j(%d),buf[j](%d),pattern(%d)\n",j,buf[j],pattern);
  1402. mmc_test_dump_buff(buf,j,left_blks * blksz);
  1403. result = -__LINE__;
  1404. goto failure;
  1405. }
  1406. }
  1407. }
  1408. msdc_pr_info(TC_MSG "test multiple block interleave write-read\n",
  1409. host->id, result == 0 ? "PASS" : "FAIL", tid++);
  1410. if (result)
  1411. goto failure;
  1412. }
  1413. #endif
  1414. if (cfg->desc) {
  1415. msdc_pr_info("[TST] ----------------------------------------------\n");
  1416. msdc_pr_info("[TST] Report - %s \n", cfg->desc);
  1417. msdc_pr_info("[TST] ----------------------------------------------\n");
  1418. }
  1419. mmc_prof_dump(id);
  1420. failure:
  1421. if (result) {
  1422. msdc_pr_info("[SD%d] mmc test failed (%d)\n", host->id, result);
  1423. fail++;
  1424. } else {
  1425. pass++;
  1426. }
  1427. msdc_pr_info("[TST] ----------------------------------------------\n");
  1428. msdc_pr_info("[TST] Test Result: TOTAL(%d/%d), PASS(%d), FAIL(%d) \n",
  1429. cfg->count - count, cfg->count, pass, fail);
  1430. msdc_pr_info("[TST] ----------------------------------------------\n");
  1431. //mdelay(1000);
  1432. }
  1433. return result;
  1434. }
  1435. int mmc_test(int argc, char *argv[])
  1436. {
  1437. unsigned int i, j;
  1438. int result = -1;
  1439. struct mmc_test_config cfg;
  1440. #ifdef MMC_ICE_DOWNLOAD
  1441. mmc_readback_part(0, PART_UBOOT, 0);
  1442. mmc_erase_part(0, PART_UBOOT, 0);
  1443. mmc_readback_part(0, PART_UBOOT, 0);
  1444. mmc_download_part(0, PART_UBOOT, 0);
  1445. mmc_readback_part(0, PART_UBOOT, 0);
  1446. while (1);
  1447. #endif
  1448. #ifdef MMC_BOOT_TEST
  1449. msdc_pr_info("[EMMC] Boot up with power reset (MMCv4.3 above)\n");
  1450. mmc_boot_up_test(0, EMMC_BOOT_PWR_RESET);
  1451. mdelay(100);
  1452. for (i = 0; i < 20; i++) {
  1453. msdc_pr_info("[EMMC] Boot up with RST_n reset (MMCv4.41 above)\n");
  1454. mmc_boot_up_test(0, EMMC_BOOT_RST_N_SIG);
  1455. mdelay(100);
  1456. }
  1457. msdc_pr_info("[EMMC] Boot up with PRE_IDLE_CMD reset (MMCv4.41 above)\n");
  1458. mmc_boot_up_test(0, EMMC_BOOT_PRE_IDLE_CMD);
  1459. //mmc_boot_enable(0, EXT_CSD_PART_CFG_EN_NO_BOOT);
  1460. //mmc_boot_enable(0, EXT_CSD_PART_CFG_EN_BOOT_PART_1);
  1461. #endif
  1462. memset(&cfg, 0, sizeof(struct mmc_test_config));
  1463. cfg.id = 0;
  1464. cfg.desc = "Memory Card Read/Write Test";
  1465. cfg.count = MMC_TST_COUNTS;
  1466. cfg.blksz = MMC_BLOCK_SIZE;
  1467. cfg.blknr = MMC_TST_BLK_NR(0);
  1468. cfg.total_size = MMC_TST_SIZE;
  1469. cfg.chunk_blks = MMC_TST_CHUNK_BLKS;
  1470. cfg.buf = (char*) MMC_TST_BUF_ADDR;
  1471. #if defined(MMC_MSDC_DRV_PRELOADER) || defined(MMC_MSDC_DRV_LK)
  1472. cfg.buf = (char*) malloc(MMC_TST_SIZE);
  1473. #endif
  1474. cfg.chk_result = MMC_TST_CHK_RESULT;
  1475. cfg.tst_single = MMC_TST_SBLK_RW;
  1476. cfg.tst_multiple = MMC_TST_MBLK_RW;
  1477. cfg.tst_interleave = MMC_TST_IMBLK_RW;
  1478. cfg.mode = MSDC_MODE_DEFAULT;
  1479. for (i = 0; i < ARRAY_SIZE(clkfreq); i++) {
  1480. for (j = 0; j < ARRAY_SIZE(buswidth); j++) {
  1481. cfg.clock = clkfreq[i];
  1482. cfg.buswidth = buswidth[j];
  1483. if (mmc_test_mem_card(&cfg) != 0)
  1484. goto exit;
  1485. }
  1486. }
  1487. result = 0;
  1488. //mmc_readback_blks(0, MMC_TST_BLK_NR(0) * MMC_BLOCK_SIZE, 16, 0);
  1489. exit:
  1490. while (1);
  1491. return result;
  1492. }
  1493. #if defined(MMC_MSDC_DRV_PRELOADER)
  1494. #ifdef MTK_MSDC_PL_TEST
  1495. #define PL_MMC_TEST_SIZE (8*512)
  1496. unsigned char g_mmc_buf[PL_MMC_TEST_SIZE + 1];
  1497. static void emmc_r_w_compare_test()
  1498. {
  1499. unsigned int i;
  1500. /* write 0x40000000(1G) with 256 block(0x5a) */
  1501. msdc_pr_info("[PL][%s:%d]eMMC simp test of user parittion start\n", __func__, __LINE__);
  1502. for (i = 0; i < PL_MMC_TEST_SIZE; i++) {
  1503. g_mmc_buf[i] = 0x5a;
  1504. }
  1505. /* 0 is for emmc */
  1506. /* 0 is for emmc */
  1507. if (mmc_block_write(0, 0x40000000/512, PL_MMC_TEST_SIZE/512, g_mmc_buf))
  1508. msdc_pr_info("[PL][%s:%d] Write user partition failed\n", __func__, __LINE__);
  1509. else
  1510. msdc_pr_info("[PL][%s:%d] finish write user partition\n", __func__, __LINE__);
  1511. /* read */
  1512. for (i = 0; i < PL_MMC_TEST_SIZE; i++) {
  1513. g_mmc_buf[i] = 0x0;
  1514. }
  1515. if (mmc_block_read(0, 0x40000000/512, PL_MMC_TEST_SIZE/512, g_mmc_buf))
  1516. msdc_pr_info("[PL][%s:%d] Read user partition failed\n", __func__, __LINE__);
  1517. else
  1518. msdc_pr_info("[PL][%s:%d] finish read user partition \n", __func__, __LINE__);
  1519. /* compara */
  1520. for (i = 0; i < PL_MMC_TEST_SIZE; i++) {
  1521. if (g_mmc_buf[i] != 0x5a) {
  1522. 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]);
  1523. break;
  1524. }
  1525. }
  1526. /* write 0x40000000(1G) with 256 block(0x5a) */
  1527. #if 0
  1528. msdc_pr_info("[PL][%s:%d]eMMC simp test of boot partition start\n", __func__, __LINE__);
  1529. for (i = 0; i < PL_MMC_TEST_SIZE; i++) {
  1530. g_mmc_buf[i] = 0x5a;
  1531. }
  1532. /* 0 is for emmc */
  1533. mmc_bwrite_boot(NULL, 0x40000000/512, PL_MMC_TEST_SIZE/512, g_mmc_buf);
  1534. msdc_pr_info("[PL][%s:%d] finish write boot partition\n", __func__, __LINE__);
  1535. #endif
  1536. /* read */
  1537. for (i = 0; i < PL_MMC_TEST_SIZE; i++) {
  1538. g_mmc_buf[i] = 0x0;
  1539. }
  1540. if (mmc_bread_boot(NULL, 0x0/512, PL_MMC_TEST_SIZE/512, g_mmc_buf))
  1541. msdc_pr_info("[PL][%s:%d] Read boot partition failed\n", __func__, __LINE__);
  1542. else
  1543. msdc_pr_info("[PL][%s:%d] finish read boot partition\n", __func__, __LINE__);
  1544. #if 0
  1545. /* compara */
  1546. for (i = 0; i < PL_MMC_TEST_SIZE; i++) {
  1547. if (g_mmc_buf[i] != 0x5a) {
  1548. 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]);
  1549. break;
  1550. }
  1551. }
  1552. #endif
  1553. msdc_pr_info("[PL][%s:%d]eMMC simp test end\n", __func__, __LINE__);
  1554. }
  1555. #endif
  1556. #endif
  1557. #if defined(MMC_MSDC_DRV_LK) && defined(MTK_EMMC_POWER_ON_WP)
  1558. #define LK_MMC_TEST_SIZE (8*512)
  1559. unsigned char g_mmc_buf[LK_MMC_TEST_SIZE + 1];
  1560. static void emmc_r_w_compare_test(struct mmc_card *card, u32 part_id, unsigned long blknr,
  1561. u32 blkcnt)
  1562. {
  1563. unsigned int i;
  1564. int err = 0;
  1565. //unsigned char g_mmc_buf[LK_MMC_TEST_SIZE + 1];
  1566. /* write 0x40000000(1G) with 256 block(0x5a) , maybe 8 block*/
  1567. if (blkcnt > 8) {
  1568. msdc_pr_info("blkcnt is invalid\n");
  1569. return;
  1570. }
  1571. msdc_pr_info("[LK][%s:%d]eMMC WP_FEATURE_TEST start\n", __func__, __LINE__);
  1572. for (i = 0; i < 512 * blkcnt; i++) {
  1573. g_mmc_buf[i] = 0x5a;
  1574. }
  1575. /* 0 is for emmc */
  1576. //err = mmc_block_write(0, blknr, blkcnt, (unsigned long *)g_mmc_buf, part_id);
  1577. err = mmc_part_write(card, part_id, blknr, blkcnt, (unsigned long *)g_mmc_buf);
  1578. if (err == MMC_ERR_WP_VIOLATION) {
  1579. msdc_pr_info("[LK][%s:%d] MMC_ERR_WP_VIOLATION\n", __func__, __LINE__);
  1580. return;
  1581. }
  1582. if (err) {
  1583. msdc_pr_info("[LK][%s:%d] other write error(%d)\n", __func__, __LINE__, err);
  1584. return;
  1585. }
  1586. msdc_pr_info("[LK][%s:%d] finish write\n", __func__, __LINE__);
  1587. /* read */
  1588. for (i = 0; i < 512 * blkcnt; i++) {
  1589. g_mmc_buf[i] = 0x0;
  1590. }
  1591. //mmc_block_read(0, blknr, blkcnt, (unsigned long *)g_mmc_buf, part_id);
  1592. mmc_part_read(card, part_id, blknr, blkcnt, (unsigned long *)g_mmc_buf);
  1593. msdc_pr_info("[LK][%s:%d] finish read\n", __func__, __LINE__);
  1594. /* compara */
  1595. for (i = 0; i < 512 * blkcnt; i++) {
  1596. if (g_mmc_buf[i] != 0x5a) {
  1597. 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]);
  1598. break;
  1599. }
  1600. }
  1601. msdc_pr_info("[LK][%s:%d]eMMC simp test end\n", __func__, __LINE__);
  1602. }
  1603. int mmc_wp_test()
  1604. {
  1605. int err;
  1606. #if 0
  1607. int dev_num = 0;
  1608. unsigned long blknr;
  1609. u32 blkcnt;
  1610. u32 part_id;
  1611. u8 case_id=1;
  1612. // struct mmc_host *host = mmc_get_host(dev_num);
  1613. struct mmc_card *card = mmc_get_card(dev_num);
  1614. //case 1
  1615. /* blknr = 2;
  1616. blkcnt = 6;
  1617. part_id = EMMC_PART_BOOT1;
  1618. msdc_pr_info("[case %d] blknr=%ld, blkcnt=%x,partition=%d \n",
  1619. case_id,blknr,blkcnt,part_id);
  1620. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_POWER_ON);
  1621. if(err)
  1622. msdc_pr_info("[%s]: (case %d) wp error\n", __func__,case_id++);
  1623. else
  1624. msdc_pr_info("[%s]: (case %d) wp successfully\n", __func__,case_id++);
  1625. */
  1626. //case2
  1627. blknr = 0;
  1628. blkcnt = card->wp_size;
  1629. part_id = EMMC_PART_USER;
  1630. msdc_pr_info("[case %d] blknr=0x%x, blkcnt=0x%x,partition=%d \n",
  1631. case_id,blknr,blkcnt,part_id);
  1632. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_POWER_ON);
  1633. if (err)
  1634. msdc_pr_info("[%s]: (case %d) wp error\n", __func__,case_id++);
  1635. else
  1636. msdc_pr_info("[%s]: (case %d) wp successfully\n", __func__,case_id++);
  1637. //case3
  1638. blknr = card->wp_size;
  1639. blkcnt = 10 * card->wp_size;
  1640. part_id = EMMC_PART_USER;
  1641. msdc_pr_info("[case %d] blknr=0x%x, blkcnt=0x%x,partition=%d \n",
  1642. case_id,blknr,blkcnt,part_id);
  1643. u64 time_before= gpt4_get_current_tick();//%lld
  1644. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_POWER_ON);
  1645. u64 time_after= gpt4_get_current_tick();//%lld
  1646. if (err)
  1647. msdc_pr_info("[%s]: (case %d) wp error,[time cost of 10 wp grps]: %lld \n",
  1648. __func__,case_id++,(time_after - time_before)*76);
  1649. else
  1650. msdc_pr_info("[%s]: (case %d) wp successfully\n", __func__,case_id++);
  1651. //case4
  1652. blknr = 1;
  1653. blkcnt = card->wp_size;
  1654. part_id = EMMC_PART_USER;
  1655. msdc_pr_info("[case %d] blknr=0x%x, blkcnt=0x%x,partition=%d \n",
  1656. case_id,blknr,blkcnt,part_id);
  1657. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_POWER_ON);
  1658. if (err)
  1659. msdc_pr_info("[%s]: (case %d) wp error\n", __func__,case_id++);
  1660. else
  1661. msdc_pr_info("[%s]: (case %d) wp successfully\n", __func__,case_id++);
  1662. //case5
  1663. blknr = card->wp_size;
  1664. blkcnt = 1;
  1665. part_id = EMMC_PART_USER;
  1666. msdc_pr_info("[case %d] blknr=0x%x, blkcnt=0x%x,partition=%d \n",
  1667. case_id,blknr,blkcnt,part_id);
  1668. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_POWER_ON);
  1669. if (err)
  1670. msdc_pr_info("[%s]: (case %d) wp error\n", __func__,case_id++);
  1671. else
  1672. msdc_pr_info("[%s]: (case %d) wp successfully\n", __func__,case_id++);
  1673. //case6
  1674. blknr = card->wp_size;
  1675. blkcnt = card->nblks;
  1676. part_id = EMMC_PART_USER;
  1677. msdc_pr_info("[case %d] blknr=0x%x, blkcnt=0x%x,partition=%d \n",
  1678. case_id,blknr,blkcnt,part_id);
  1679. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_POWER_ON);
  1680. if (err)
  1681. msdc_pr_info("[%s]: (case %d) wp error\n", __func__,case_id++);
  1682. else
  1683. msdc_pr_info("[%s]: (case %d) wp successfully\n", __func__,case_id++);
  1684. //case7
  1685. blknr = card->wp_size;
  1686. blkcnt = card->wp_size;;
  1687. part_id = EMMC_PART_END;
  1688. msdc_pr_info("[case %d] blknr=0x%x, blkcnt=0x%x,partition=%d \n",
  1689. case_id,blknr,blkcnt,part_id);
  1690. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_POWER_ON);
  1691. if (err)
  1692. msdc_pr_info("[%s]: (case %d) wp error\n", __func__,case_id++);
  1693. else
  1694. msdc_pr_info("[%s]: (case %d) wp successfully\n", __func__,case_id++);
  1695. //case8
  1696. blknr = 11 * card->wp_size;
  1697. blkcnt = card->wp_size;
  1698. part_id = EMMC_PART_USER;
  1699. msdc_pr_info("[case %d] blknr=0x%x, blkcnt=0x%x,partition=%d \n",
  1700. case_id,blknr,blkcnt,part_id);
  1701. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_PERMANENT);
  1702. if (err)
  1703. msdc_pr_info("[%s]: (case %d) wp error\n", __func__,case_id++);
  1704. else
  1705. msdc_pr_info("[%s]: (case %d) wp successfully\n", __func__,case_id++);
  1706. //case9
  1707. blknr = 0;
  1708. blkcnt = card->wp_size;
  1709. part_id = EMMC_PART_GP1;
  1710. msdc_pr_info("[case %d] blknr=0x%x, blkcnt=0x%x,partition=%d \n",
  1711. case_id,blknr,blkcnt,part_id);
  1712. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_POWER_ON);
  1713. if (err)
  1714. msdc_pr_info("[%s]: (case %d) wp error\n", __func__,case_id++);
  1715. else
  1716. msdc_pr_info("[%s]: (case %d) wp successfully\n", __func__,case_id++);
  1717. //case10
  1718. blknr = 0;
  1719. blkcnt = card->wp_size;
  1720. part_id = EMMC_PART_USER;
  1721. msdc_pr_info("[case %d] blknr=0x%x, blkcnt=0x%x,partition=%d \n",
  1722. case_id,blknr,blkcnt,part_id);
  1723. err = mmc_set_write_protect(dev_num, part_id, blknr, blkcnt, WP_TEMPORARY);
  1724. if (err)
  1725. msdc_pr_info("[%s]: (case %d) wp error\n", __func__,case_id++);
  1726. else
  1727. msdc_pr_info("[%s]: (case %d) wp successfully\n", __func__,case_id++);
  1728. #endif
  1729. // partiton test case
  1730. msdc_pr_info("[%s]: (partition case: 1) preloader->lk\n", __func__);
  1731. err = partition_write_prot_set("preloader", "lk", WP_POWER_ON);
  1732. msdc_pr_info("[%s]: (partition case: 1) preloader->lk, err=%d\n", __func__, err);
  1733. msdc_pr_info("[%s]: (partition case: 2) boot->recovery\n", __func__);
  1734. err = partition_write_prot_set("boot", "recovery", WP_POWER_ON);
  1735. msdc_pr_info("[%s]: (partition case: 2) boot->recovery, err=%d\n", __func__, err);
  1736. msdc_pr_info("[%s]: (partition case: 3) keystore->oemkeystore\n", __func__);
  1737. err = partition_write_prot_set("keystore", "oemkeystore", WP_POWER_ON);
  1738. msdc_pr_info("[%s]: (partition case: 3) keystore->oemkeystore, err=%d\n", __func__, err);
  1739. msdc_pr_info("[%s]: (partition case: 4) oemkeystore->secro\n", __func__);
  1740. err = partition_write_prot_set("oemkeystore", "secro", WP_POWER_ON);
  1741. msdc_pr_info("[%s]: (partition case: 4) oemkeystore->secro, err=%d\n", __func__, err);
  1742. msdc_pr_info("[%s]: (partition case: 5) test_start->keystore\n", __func__);
  1743. err = partition_write_prot_set("test_starte", "keystor", WP_POWER_ON);
  1744. msdc_pr_info("[%s]: (partition case: 5) test_start->keystore, err=%d\n", __func__, err);
  1745. msdc_pr_info("[%s]: (partition case: 6) oemkeystore->test_end\n", __func__);
  1746. err = partition_write_prot_set("oemkeystore", "test_end", WP_POWER_ON);
  1747. msdc_pr_info("[%s]: (partition case: 6) oemkeystore->test_end, err=%d\n", __func__, err);
  1748. msdc_pr_info("[%s]: (partition case: 7) keystore->keystore\n", __func__);
  1749. err = partition_write_prot_set("keystore", "keystore", WP_POWER_ON);
  1750. msdc_pr_info("[%s]: (partition case: 7) keystore->keystore, err=%d\n", __func__, err);
  1751. return err;
  1752. }
  1753. #endif
  1754. /*
  1755. * mmc_SettingTimingByClock_eMMC
  1756. * @ddr: ddr ot not
  1757. * @hz : bus frequency
  1758. * return 0 means there is no timing with this condition
  1759. *
  1760. * Setting timning by hz, choise the lowest timing.
  1761. * By setting msdc_cap, we can adjust the timing when card init
  1762. * (hz <= 26M) backware
  1763. * (26M < hz <= 52M) high speed SDR/DDR (By ddr)
  1764. * (52M < hz) HS200/HS400 (By ddr)
  1765. */
  1766. int mmc_SettingTimingByClock_eMMC(int ddr, uint hz)
  1767. {
  1768. int id = 0;
  1769. if (ddr) {
  1770. if (hz > 26000000) {
  1771. msdc_cap[id].flags |= MSDC_DDR;
  1772. } else {
  1773. return 0;
  1774. }
  1775. } else {
  1776. msdc_cap[id].flags &= ~MSDC_DDR;
  1777. }
  1778. if (hz <= 26000000) {
  1779. msdc_cap[id].flags &= ~(MSDC_HS400 | MSDC_HS200 | MSDC_HIGHSPEED);
  1780. } else if (hz <= 52000000) {
  1781. msdc_cap[id].flags &= ~(MSDC_HS400 | MSDC_HS200);
  1782. msdc_cap[id].flags |= MSDC_HIGHSPEED;
  1783. } else {
  1784. if (ddr == 1) {
  1785. msdc_cap[id].flags |= (MSDC_HS400 | MSDC_HS200 | MSDC_HIGHSPEED);
  1786. } else {
  1787. msdc_cap[id].flags |= (MSDC_HS200 | MSDC_HIGHSPEED);
  1788. msdc_cap[id].flags &= ~MSDC_HS400;
  1789. }
  1790. }
  1791. return 1;
  1792. }
  1793. /*
  1794. * mmc_SettingTimingByClock_SD
  1795. * @ddr: ddr ot not
  1796. * @hz : bus frequency
  1797. * return 0 means there is no timing with this condition
  1798. *
  1799. * Setting timning by hz, choise the lowest timing.
  1800. * By setting msdc_cap, we can adjust the timing when card init
  1801. * (hz <= 26M) backware
  1802. * (26M < hz <= 52M) high speed SDR/DDR (By ddr)
  1803. * (52M < hz) HS200/HS400 (By ddr)
  1804. */
  1805. int mmc_SettingTimingByClock_SD(int ddr, uint hz)
  1806. {
  1807. int id = 0;
  1808. if (ddr) {
  1809. if (hz > 26000000) {
  1810. msdc_cap[id].flags |= MSDC_DDR;
  1811. } else {
  1812. return 0;
  1813. }
  1814. } else {
  1815. msdc_cap[id].flags &= ~MSDC_DDR;
  1816. }
  1817. if (hz <= 26000000) {
  1818. msdc_cap[id].flags &= ~(MSDC_HS400 | MSDC_HS200 | MSDC_HIGHSPEED);
  1819. } else if (hz <= 52000000) {
  1820. msdc_cap[id].flags &= ~(MSDC_HS400 | MSDC_HS200);
  1821. msdc_cap[id].flags |= MSDC_HIGHSPEED;
  1822. } else {
  1823. if (ddr == 1) {
  1824. msdc_cap[id].flags |= (MSDC_HS400 | MSDC_HS200 | MSDC_HIGHSPEED);
  1825. } else {
  1826. msdc_cap[id].flags |= (MSDC_HS200 | MSDC_HIGHSPEED);
  1827. msdc_cap[id].flags &= ~MSDC_HS400;
  1828. }
  1829. }
  1830. return 1;
  1831. }
  1832. #endif /* MMC_TEST */