mmc_test.c 76 KB

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