mmc_test.c 98 KB

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