mmc_test.c 80 KB

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