dbg.c 109 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497
  1. #include <linux/version.h>
  2. #include <linux/kernel.h>
  3. #include <linux/sched.h>
  4. #include <linux/kthread.h>
  5. #include <linux/delay.h>
  6. #include <linux/module.h>
  7. #include <linux/init.h>
  8. #include <linux/proc_fs.h>
  9. #include <linux/string.h>
  10. #include <linux/uaccess.h>
  11. #include <linux/slab.h>
  12. #include <linux/mmc/host.h>
  13. #include <linux/seq_file.h>
  14. #include <mach/mt_gpt.h>
  15. #include <asm/io.h>
  16. /* for fpga early porting */
  17. #include <linux/mmc/mmc.h>
  18. #include <linux/mmc/card.h>
  19. #include <linux/scatterlist.h>
  20. #include <linux/mm_types.h>
  21. /* end for fpga early porting */
  22. #include "dbg.h"
  23. #ifndef FPGA_PLATFORM
  24. #ifdef CONFIG_MTK_CLKMGR
  25. #include <mach/mt_clkmgr.h>
  26. #endif
  27. #endif
  28. #ifdef MTK_MSDC_BRINGUP_DEBUG
  29. #include <mach/mt_pmic_wrap.h>
  30. #endif
  31. #ifdef MTK_IO_PERFORMANCE_DEBUG
  32. unsigned int g_mtk_mmc_perf_dbg = 0;
  33. unsigned int g_mtk_mmc_dbg_range = 0;
  34. unsigned int g_dbg_range_start = 0;
  35. unsigned int g_dbg_range_end = 0;
  36. unsigned int g_mtk_mmc_dbg_flag = 0;
  37. unsigned int g_dbg_req_count = 0;
  38. unsigned int g_dbg_raw_count = 0;
  39. unsigned int g_dbg_write_count = 0;
  40. unsigned int g_dbg_raw_count_old = 0;
  41. unsigned int g_mtk_mmc_clear = 0;
  42. int g_check_read_write = 0;
  43. int g_i = 0;
  44. unsigned long long g_req_buf[4000][30] = { {0} };
  45. unsigned long long g_req_write_buf[4000][30] = { {0} };
  46. unsigned long long g_req_write_count[4000] = { 0 };
  47. unsigned long long g_mmcqd_buf[400][300] = { {0} };
  48. char *g_time_mark[] = {
  49. "--start fetch request",
  50. "--end fetch request",
  51. "--start dma map this request",
  52. "--end dma map this request",
  53. "--start request",
  54. "--DMA start",
  55. "--DMA transfer done",
  56. "--start dma unmap request",
  57. "--end dma unmap request",
  58. "--end of request",
  59. };
  60. char *g_time_mark_vfs_write[] = {
  61. "--in vfs_write",
  62. "--before generic_segment_checks",
  63. "--after generic_segment_checks",
  64. "--after vfs_check_frozen",
  65. "--after generic_write_checks",
  66. "--after file_remove_suid",
  67. "--after file_update_time",
  68. "--after generic_file_direct_write",
  69. "--after generic_file_buffered_write",
  70. "--after filemap_write_and_wait_range",
  71. "--after invalidate_mapping_pages",
  72. "--after 2nd generic_file_buffered_write",
  73. "--before generic_write_sync",
  74. "--after generic_write_sync",
  75. "--out vfs_write"
  76. };
  77. #endif
  78. /* for get transfer time with each trunk size, default not open */
  79. #ifdef MTK_MMC_PERFORMANCE_TEST
  80. unsigned int g_mtk_mmc_perf_test = 0;
  81. #endif
  82. #ifdef MTK_MSDC_ERROR_TUNE_DEBUG
  83. unsigned int g_err_tune_dbg_count = 0;
  84. unsigned int g_err_tune_dbg_host = 0;
  85. unsigned int g_err_tune_dbg_cmd = 0;
  86. unsigned int g_err_tune_dbg_arg = 0;
  87. unsigned int g_err_tune_dbg_error = MTK_MSDC_ERROR_NONE;
  88. #endif
  89. typedef enum {
  90. SDHC_HIGHSPEED = 0, /* 0x1 Host supports HS mode */
  91. UHS_SDR12, /* 0x2 Host supports UHS SDR12 mode */
  92. UHS_SDR25, /* 0x3 Host supports UHS SDR25 mode */
  93. UHS_SDR50, /* 0x4 Host supports UHS SDR50 mode */
  94. UHS_SDR104, /* 0x5 Host supports UHS SDR104/EMMC HS200 mode */
  95. UHS_DDR50, /* 0x6 Host supports UHS DDR50 mode */
  96. EMMC_HS400, /* 0x7 Host supports EMMC HS400 mode */
  97. CAPS_SPEED_NULL,
  98. } HOST_CAPS_SPEED_MODE;
  99. typedef enum {
  100. DRIVER_TYPE_A = 0, /* 0x7 Host supports Driver Type A */
  101. DRIVER_TYPE_B, /* 0x8 Host supports Driver Type B */
  102. DRIVER_TYPE_C, /* 0x9 Host supports Driver Type C */
  103. DRIVER_TYPE_D, /* 0xA Host supports Driver Type D */
  104. CAPS_DRIVE_NULL,
  105. } HOST_CAPS_DRIVE_TYPE;
  106. typedef enum {
  107. MAX_CURRENT_200 = 0, /* 0xB Host max current limit is 200mA */
  108. MAX_CURRENT_400, /* 0xC Host max current limit is 400mA */
  109. MAX_CURRENT_600, /* 0xD Host max current limit is 600mA */
  110. MAX_CURRENT_800, /* 0xE Host max current limit is 800mA */
  111. CAPS_CURRENT_NULL,
  112. } HOST_CAPS_MAX_CURRENT;
  113. typedef enum {
  114. SDXC_NO_POWER_CONTROL = 0, /*0xF Host not supports >150mA current at 3.3V /3.0V/1.8V */
  115. SDXC_POWER_CONTROL, /*0x10 Host supports >150mA current at 3.3V /3.0V/1.8V */
  116. CAPS_POWER_NULL,
  117. } HOST_CAPS_POWER_CONTROL;
  118. static char cmd_buf[256];
  119. drv_mod msdc_drv_mode[HOST_MAX_NUM];
  120. int sdio_cd_result = 1;
  121. /* for driver profile */
  122. #define TICKS_ONE_MS (13000)
  123. u32 gpt_enable = 0;
  124. u32 sdio_pro_enable = 0; /* make sure gpt is enabled */
  125. static unsigned long long sdio_pro_time = 30; /* no more than 30s */
  126. static unsigned long long sdio_profiling_start;
  127. struct sdio_profile sdio_perfomance = { 0 };
  128. u32 sdio_enable_tune = 0;
  129. u32 sdio_iocon_dspl = 0;
  130. u32 sdio_iocon_w_dspl = 0;
  131. u32 sdio_iocon_rspl = 0;
  132. u32 sdio_pad_tune_rrdly = 0;
  133. u32 sdio_pad_tune_rdly = 0;
  134. u32 sdio_pad_tune_wrdly = 0;
  135. u32 sdio_dat_rd_dly0_0 = 0;
  136. u32 sdio_dat_rd_dly0_1 = 0;
  137. u32 sdio_dat_rd_dly0_2 = 0;
  138. u32 sdio_dat_rd_dly0_3 = 0;
  139. u32 sdio_dat_rd_dly1_0 = 0;
  140. u32 sdio_dat_rd_dly1_1 = 0;
  141. u32 sdio_dat_rd_dly1_2 = 0;
  142. u32 sdio_dat_rd_dly1_3 = 0;
  143. u32 sdio_clk_drv = 0;
  144. u32 sdio_cmd_drv = 0;
  145. u32 sdio_data_drv = 0;
  146. static void msdc_set_field(void __iomem *address, unsigned int start_bit, unsigned int len,
  147. unsigned int value)
  148. {
  149. unsigned long field;
  150. if (start_bit > 31 || start_bit < 0 || len >= 32 || len <= 0)
  151. pr_err("[****SD_Debug****]reg filed beyoned (0~31) or length beyoned (1~32)\n");
  152. else {
  153. field = ((1 << len) - 1) << start_bit;
  154. value &= (1 << len) - 1;
  155. pr_notice("[****SD_Debug****]Original:0x%p (0x%x)\n", address, sdr_read32(address));
  156. sdr_set_field(address, field, value);
  157. pr_notice("[****SD_Debug****]Modified:0x%p (0x%x)\n", address, sdr_read32(address));
  158. }
  159. }
  160. static void msdc_get_field(void __iomem *address, unsigned int start_bit, unsigned int len,
  161. unsigned int value)
  162. {
  163. unsigned long field;
  164. if (start_bit > 31 || start_bit < 0 || len >= 32 || len <= 0)
  165. pr_err("[****SD_Debug****]reg filed beyoned (0~31) or length beyoned (1~32)\n");
  166. else {
  167. field = ((1 << len) - 1) << start_bit;
  168. sdr_get_field(address, field, value);
  169. pr_err("[****SD_Debug****]Reg:0x%p start_bit(%d)len(%d)(0x%x)\n", address,
  170. start_bit, len, value);
  171. }
  172. }
  173. static void msdc_init_gpt(void)
  174. {
  175. #if 0
  176. GPT_CONFIG config;
  177. config.num = GPT6;
  178. config.mode = GPT_FREE_RUN;
  179. config.clkSrc = GPT_CLK_SRC_SYS;
  180. config.clkDiv = GPT_CLK_DIV_1; /* 13MHz GPT6 */
  181. if (GPT_Config(config) == FALSE)
  182. return;
  183. GPT_Start(GPT6);
  184. #endif
  185. }
  186. u32 msdc_time_calc(u32 old_L32, u32 old_H32, u32 new_L32, u32 new_H32)
  187. {
  188. u32 ret = 0;
  189. if (new_H32 == old_H32) {
  190. ret = new_L32 - old_L32;
  191. } else if (new_H32 == (old_H32 + 1)) {
  192. if (new_L32 > old_L32)
  193. pr_notice("msdc old_L<0x%x> new_L<0x%x>\n", old_L32, new_L32);
  194. ret = (0xffffffff - old_L32);
  195. ret += new_L32;
  196. } else {
  197. pr_notice("msdc old_H<0x%x> new_H<0x%x>\n", old_H32, new_H32);
  198. }
  199. return ret;
  200. }
  201. void msdc_sdio_profile(struct sdio_profile *result)
  202. {
  203. struct cmd_profile *cmd;
  204. u32 i;
  205. pr_notice("sdio === performance dump ===\n");
  206. pr_notice("sdio === total execute tick<%d> time<%dms> Tx<%dB> Rx<%dB>\n",
  207. result->total_tc, result->total_tc / TICKS_ONE_MS,
  208. result->total_tx_bytes, result->total_rx_bytes);
  209. /* CMD52 Dump */
  210. cmd = &result->cmd52_rx;
  211. pr_notice("sdio === CMD52 Rx <%d>times tick<%d> Max<%d> Min<%d> Aver<%d>\n", cmd->count,
  212. cmd->tot_tc, cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count);
  213. cmd = &result->cmd52_tx;
  214. pr_notice("sdio === CMD52 Tx <%d>times tick<%d> Max<%d> Min<%d> Aver<%d>\n", cmd->count,
  215. cmd->tot_tc, cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count);
  216. /* CMD53 Rx bytes + block mode */
  217. for (i = 0; i < 512; i++) {
  218. cmd = &result->cmd53_rx_byte[i];
  219. if (cmd->count) {
  220. pr_notice("sdio<%6d><%3dB>_Rx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n",
  221. cmd->count, i, cmd->tot_tc, cmd->max_tc, cmd->min_tc,
  222. cmd->tot_tc / cmd->count, cmd->tot_bytes,
  223. (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
  224. }
  225. }
  226. for (i = 0; i < 100; i++) {
  227. cmd = &result->cmd53_rx_blk[i];
  228. if (cmd->count) {
  229. pr_notice("sdio<%6d><%3d>B_Rx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n",
  230. cmd->count, i, cmd->tot_tc, cmd->max_tc, cmd->min_tc,
  231. cmd->tot_tc / cmd->count, cmd->tot_bytes,
  232. (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
  233. }
  234. }
  235. /* CMD53 Tx bytes + block mode */
  236. for (i = 0; i < 512; i++) {
  237. cmd = &result->cmd53_tx_byte[i];
  238. if (cmd->count) {
  239. pr_notice("sdio<%6d><%3dB>_Tx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n",
  240. cmd->count, i, cmd->tot_tc, cmd->max_tc, cmd->min_tc,
  241. cmd->tot_tc / cmd->count, cmd->tot_bytes,
  242. (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
  243. }
  244. }
  245. for (i = 0; i < 100; i++) {
  246. cmd = &result->cmd53_tx_blk[i];
  247. if (cmd->count) {
  248. pr_notice("sdio<%6d><%3d>B_Tx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n",
  249. cmd->count, i, cmd->tot_tc, cmd->max_tc, cmd->min_tc,
  250. cmd->tot_tc / cmd->count, cmd->tot_bytes,
  251. (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
  252. }
  253. }
  254. pr_notice("sdio === performance dump done ===\n");
  255. }
  256. /* ========= sdio command table =========== */
  257. void msdc_performance(u32 opcode, u32 sizes, u32 bRx, u32 ticks)
  258. {
  259. struct sdio_profile *result = &sdio_perfomance;
  260. struct cmd_profile *cmd;
  261. u32 block;
  262. long long endtime;
  263. if (sdio_pro_enable == 0)
  264. return;
  265. if (opcode == 52) {
  266. cmd = bRx ? &result->cmd52_rx : &result->cmd52_tx;
  267. } else if (opcode == 53) {
  268. if (sizes < 512) {
  269. cmd = bRx ? &result->cmd53_rx_byte[sizes] : &result->cmd53_tx_byte[sizes];
  270. } else {
  271. block = sizes / 512;
  272. if (block >= 99) {
  273. pr_err("cmd53 error blocks\n");
  274. while (1)
  275. ;
  276. }
  277. cmd = bRx ? &result->cmd53_rx_blk[block] : &result->cmd53_tx_blk[block];
  278. }
  279. } else {
  280. return;
  281. }
  282. /* update the members */
  283. if (ticks > cmd->max_tc)
  284. cmd->max_tc = ticks;
  285. if (cmd->min_tc == 0 || ticks < cmd->min_tc)
  286. cmd->min_tc = ticks;
  287. cmd->tot_tc += ticks;
  288. cmd->tot_bytes += sizes;
  289. cmd->count++;
  290. if (bRx)
  291. result->total_rx_bytes += sizes;
  292. else
  293. result->total_tx_bytes += sizes;
  294. result->total_tc += ticks;
  295. #if 0
  296. /* dump when total_tc > 30s */
  297. if (result->total_tc >= sdio_pro_time * TICKS_ONE_MS * 1000) {
  298. msdc_sdio_profile(result);
  299. memset(result, 0, sizeof(struct sdio_profile));
  300. }
  301. #endif
  302. endtime = sched_clock();
  303. if ((endtime - sdio_profiling_start) >= sdio_pro_time * 1000000000) {
  304. msdc_sdio_profile(result);
  305. memset(result, 0, sizeof(struct sdio_profile));
  306. sdio_profiling_start = endtime;
  307. }
  308. }
  309. #define COMPARE_ADDRESS_MMC 0x402000
  310. #define COMPARE_ADDRESS_SD 0x2000
  311. #define COMPARE_ADDRESS_SDIO 0x0
  312. #define COMPARE_ADDRESS_SD_COMBO 0x2000
  313. #define MSDC_MULTI_BUF_LEN (4*4*1024) /*16KB write/read/compare*/
  314. static DEFINE_MUTEX(sd_lock);
  315. static DEFINE_MUTEX(emmc_lock);
  316. u8 read_write_state = 0; /* 0:stop, 1:read, 2:write */
  317. #define is_card_present(h) (((struct msdc_host *)(h))->card_inserted)
  318. /*
  319. * @read, bit0: 1:read/0:write; bit1: 0:compare/1:not compare
  320. */
  321. static int sd_multi_rw_compare_slave(int host_num, int read, uint address)
  322. {
  323. #ifdef CONFIG_MTK_EMMC_SUPPORT
  324. char l_buf[512];
  325. #endif
  326. struct scatterlist msdc_sg;
  327. struct mmc_data msdc_data;
  328. struct mmc_command msdc_cmd;
  329. struct mmc_command msdc_stop;
  330. #ifdef MTK_MSDC_USE_CMD23
  331. /*struct mmc_command msdc_sbc;*/
  332. #endif
  333. u32 *multi_rwbuf = NULL;
  334. u8 *wPtr = NULL, *rPtr = NULL;
  335. struct mmc_request msdc_mrq;
  336. struct msdc_host *host_ctl;
  337. int result = 0, forIndex = 0;
  338. u8 wData[200] = {
  339. 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00,
  340. 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00,
  341. 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00,
  342. 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00,
  343. 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00,
  344. 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00,
  345. 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff,
  346. 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00,
  347. 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
  348. 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
  349. 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
  350. 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
  351. 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55,
  352. 0x80, 0x80, 0x80, 0x7f, 0x80, 0x80, 0x80, 0x7f,
  353. 0x7f, 0x7f, 0x80, 0x7f, 0x7f, 0x7f, 0x40, 0x40,
  354. 0x04, 0xfb, 0x04, 0x04, 0x04, 0xfb, 0xfb, 0xfb,
  355. 0x04, 0xfb, 0xfb, 0xfb, 0x02, 0x02, 0x02, 0xfd,
  356. 0x02, 0x02, 0x02, 0xfd, 0xfd, 0xfd, 0x02, 0xfd,
  357. 0xfd, 0xfd, 0x01, 0x01, 0x01, 0xfe, 0x01, 0x01,
  358. 0x01, 0xfe, 0xfe, 0xfe, 0x01, 0xfe, 0xfe, 0xfe,
  359. 0x80, 0x80, 0x80, 0x7f, 0x80, 0x80, 0x80, 0x7f,
  360. 0x7f, 0x7f, 0x80, 0x7f, 0x7f, 0x7f, 0x40, 0x40,
  361. 0x40, 0x40, 0x80, 0x7f, 0x7f, 0x7f, 0x40, 0x40,
  362. 0x20, 0xdf, 0x20, 0x20, 0x20, 0xdf, 0xdf, 0xdf,
  363. 0x10, 0x10, 0x10, 0xef, 0xef, 0x10, 0xef, 0xef,
  364. };
  365. if (host_num >= HOST_MAX_NUM || host_num < 0) {
  366. pr_err("[%s]:invalid host id: %d\n", __func__, host_num);
  367. return -1;
  368. }
  369. /*allock memory for test buf */
  370. multi_rwbuf = kzalloc((MSDC_MULTI_BUF_LEN), GFP_KERNEL);
  371. rPtr = wPtr = (u8 *) multi_rwbuf;
  372. host_ctl = mtk_msdc_host[host_num];
  373. if (!host_ctl || !host_ctl->mmc || !host_ctl->mmc->card) {
  374. pr_err(" there is no card initialized in host[%d]\n", host_num);
  375. result = -1;
  376. goto free;
  377. }
  378. if (!is_card_present(host_ctl)) {
  379. pr_err(" [%s]: card is removed!\n", __func__);
  380. result = -1;
  381. goto free;
  382. }
  383. mmc_claim_host(host_ctl->mmc);
  384. #ifdef CONFIG_MTK_EMMC_SUPPORT
  385. if (!g_ett_tune && (host_ctl->hw->host_function == MSDC_EMMC)) {
  386. mmc_send_ext_csd(host_ctl->mmc->card, l_buf);
  387. /* make sure access partition is user data area */
  388. if (0 != (l_buf[179] & 0x7)) {
  389. /* set back to access user area */
  390. pr_notice("set back to user area\n");
  391. l_buf[179] &= ~0x7;
  392. l_buf[179] |= 0x0;
  393. mmc_switch(host_ctl->mmc->card, 0, 179, l_buf[179], 1000);
  394. }
  395. }
  396. #endif
  397. memset(&msdc_data, 0, sizeof(struct mmc_data));
  398. memset(&msdc_mrq, 0, sizeof(struct mmc_request));
  399. memset(&msdc_cmd, 0, sizeof(struct mmc_command));
  400. memset(&msdc_stop, 0, sizeof(struct mmc_command));
  401. #ifdef MTK_MSDC_USE_CMD23
  402. /*memset(&msdc_sbc, 0, sizeof(struct mmc_command));*/
  403. #endif
  404. msdc_mrq.cmd = &msdc_cmd;
  405. msdc_mrq.data = &msdc_data;
  406. msdc_data.blocks = MSDC_MULTI_BUF_LEN / 512;
  407. if (read) {
  408. /* init read command */
  409. msdc_data.flags = MMC_DATA_READ;
  410. msdc_cmd.opcode = MMC_READ_MULTIPLE_BLOCK;
  411. } else {
  412. /* init write command */
  413. msdc_data.flags = MMC_DATA_WRITE;
  414. msdc_cmd.opcode = MMC_WRITE_MULTIPLE_BLOCK;
  415. /* init write buffer */
  416. for (forIndex = 0; forIndex < MSDC_MULTI_BUF_LEN; forIndex++)
  417. *(wPtr + forIndex) = wData[forIndex % 200];
  418. /* for(forIndex=0;forIndex<MSDC_MULTI_BUF_LEN;forIndex++) */
  419. /* pr_notice("W_buffer[0x%x]\n",wPtr[forIndex]); */
  420. }
  421. msdc_cmd.arg = address;
  422. BUG_ON(!host_ctl->mmc->card);
  423. #if 0
  424. /*#ifdef MTK_MSDC_USE_CMD23*/
  425. if ((mmc_card_mmc(host_ctl->mmc->card)
  426. || (mmc_card_sd(host_ctl->mmc->card)
  427. && host_ctl->mmc->card->scr.cmds & SD_SCR_CMD23_SUPPORT))
  428. && !(host_ctl->mmc->card->quirks & MMC_QUIRK_BLK_NO_CMD23)) {
  429. msdc_mrq.sbc = &msdc_sbc;
  430. msdc_mrq.sbc->opcode = MMC_SET_BLOCK_COUNT;
  431. msdc_mrq.sbc->arg = msdc_data.blocks;
  432. msdc_mrq.sbc->flags = MMC_RSP_R1 | MMC_CMD_AC;
  433. }
  434. #endif
  435. msdc_stop.opcode = MMC_STOP_TRANSMISSION;
  436. msdc_stop.arg = 0;
  437. msdc_stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
  438. msdc_data.stop = &msdc_stop;
  439. if (!mmc_card_blockaddr(host_ctl->mmc->card)) {
  440. /*pr_err("this device use byte address!!\n");*/
  441. msdc_cmd.arg <<= 9;
  442. }
  443. msdc_cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
  444. msdc_data.blksz = 512;
  445. msdc_data.sg = &msdc_sg;
  446. msdc_data.sg_len = 1;
  447. sg_init_one(&msdc_sg, multi_rwbuf, MSDC_MULTI_BUF_LEN);
  448. mmc_set_data_timeout(&msdc_data, host_ctl->mmc->card);
  449. mmc_wait_for_req(host_ctl->mmc, &msdc_mrq);
  450. /* compare */
  451. if (read) {
  452. for (forIndex = 0; forIndex < MSDC_MULTI_BUF_LEN; forIndex++) {
  453. if (rPtr[forIndex] != wData[forIndex % 200]) {
  454. pr_err("index[%d]\tW_buffer[0x%x]\tR_buffer[0x%x]\tfailed\n",
  455. forIndex, wData[forIndex % 200], multi_rwbuf[forIndex]);
  456. return -1;
  457. }
  458. }
  459. }
  460. mmc_release_host(host_ctl->mmc);
  461. if (msdc_cmd.error)
  462. result = msdc_cmd.error;
  463. if (msdc_data.error)
  464. result = msdc_data.error;
  465. else
  466. result = 0;
  467. free:
  468. kfree(multi_rwbuf);
  469. return result;
  470. }
  471. static int sd_multi_rw_compare(int host_num, uint address, int count)
  472. {
  473. int i = 0, j = 0;
  474. int error = 0;
  475. if (host_num >= HOST_MAX_NUM || host_num < 0) {
  476. pr_err("[%s]:invalid host id: %d\n", __func__, host_num);
  477. return -1;
  478. }
  479. for (i = 0; i < count; i++) {
  480. /* pr_notice("cpu[%d] pid[%d]:the %d compare\n", task_cpu(current), current->pid, i); */
  481. mutex_lock(&sd_lock);
  482. error = sd_multi_rw_compare_slave(host_num, 0, address); /* write */
  483. if (error) {
  484. pr_err("[%s]: failed to write data, error=%d\n", __func__, error);
  485. mutex_unlock(&sd_lock);
  486. break;
  487. }
  488. for (j = 0; j < 1; j++) {
  489. error = sd_multi_rw_compare_slave(host_num, 1, address); /* read */
  490. if (error) {
  491. pr_err("[%s]: failed to read data, error=%d\n", __func__, error);
  492. break;
  493. }
  494. }
  495. if (error)
  496. pr_err
  497. ("============ cpu[%d] pid[%d]: FAILED the %d time compare ============\n",
  498. task_cpu(current), current->pid, i);
  499. else
  500. pr_err
  501. ("============ cpu[%d] pid[%d]: FINISH the %d time compare ============\n",
  502. task_cpu(current), current->pid, i);
  503. mutex_unlock(&sd_lock);
  504. }
  505. if (i == count)
  506. pr_err("pid[%d]: successed to compare data within %d times\n", current->pid, count);
  507. return error;
  508. }
  509. static int emmc_multi_rw_compare_slave(int host_num, int read, uint address)
  510. {
  511. #ifdef CONFIG_MTK_EMMC_SUPPORT
  512. char l_buf[512];
  513. #endif
  514. struct scatterlist msdc_sg;
  515. struct mmc_data msdc_data;
  516. struct mmc_command msdc_cmd;
  517. struct mmc_command msdc_stop;
  518. #ifdef MTK_MSDC_USE_CMD23
  519. struct mmc_command msdc_sbc;
  520. #endif
  521. u32 *multi_rwbuf = NULL;
  522. u8 *wPtr = NULL, *rPtr = NULL;
  523. struct mmc_request msdc_mrq;
  524. struct msdc_host *host_ctl;
  525. /* struct msdc_host *host = mtk_msdc_host[host_num]; */
  526. int result = 0, forIndex = 0;
  527. u8 wData[16] = {
  528. 0x67, 0x45, 0x23, 0x01,
  529. 0xef, 0xcd, 0xab, 0x89,
  530. 0xce, 0x8a, 0x46, 0x02,
  531. 0xde, 0x9b, 0x57, 0x13
  532. };
  533. /*allock memory for test buf */
  534. multi_rwbuf = kzalloc((MSDC_MULTI_BUF_LEN), GFP_KERNEL);
  535. rPtr = wPtr = (u8 *) multi_rwbuf;
  536. host_ctl = mtk_msdc_host[host_num];
  537. if (!host_ctl || !host_ctl->mmc || !host_ctl->mmc->card) {
  538. pr_err(" there is no card initialized in host[%d]\n", host_num);
  539. result = -1;
  540. goto free;
  541. }
  542. if (!is_card_present(host_ctl)) {
  543. pr_err(" [%s]: card is removed!\n", __func__);
  544. result = -1;
  545. goto free;
  546. }
  547. mmc_claim_host(host_ctl->mmc);
  548. #ifdef CONFIG_MTK_EMMC_SUPPORT
  549. if (!g_ett_tune && (host_ctl->hw->host_function == MSDC_EMMC)) {
  550. mmc_send_ext_csd(host_ctl->mmc->card, l_buf);
  551. /* make sure access partition is user data area */
  552. if (0 != (l_buf[179] & 0x7)) {
  553. /* set back to access user area */
  554. pr_notice("set back to user area\n");
  555. l_buf[179] &= ~0x7;
  556. l_buf[179] |= 0x0;
  557. mmc_switch(host_ctl->mmc->card, 0, 179, l_buf[179], 1000);
  558. }
  559. }
  560. #endif
  561. memset(&msdc_data, 0, sizeof(struct mmc_data));
  562. memset(&msdc_mrq, 0, sizeof(struct mmc_request));
  563. memset(&msdc_cmd, 0, sizeof(struct mmc_command));
  564. memset(&msdc_stop, 0, sizeof(struct mmc_command));
  565. #ifdef MTK_MSDC_USE_CMD23
  566. memset(&msdc_sbc, 0, sizeof(struct mmc_command));
  567. #endif
  568. msdc_mrq.cmd = &msdc_cmd;
  569. msdc_mrq.data = &msdc_data;
  570. msdc_data.blocks = (MSDC_MULTI_BUF_LEN) / 512;
  571. if (read) {
  572. /* init read command */
  573. msdc_data.flags = MMC_DATA_READ;
  574. msdc_cmd.opcode = MMC_READ_MULTIPLE_BLOCK;
  575. } else {
  576. /* init write command */
  577. msdc_data.flags = MMC_DATA_WRITE;
  578. msdc_cmd.opcode = MMC_WRITE_MULTIPLE_BLOCK;
  579. /* init write buffer */
  580. for (forIndex = 0; forIndex < MSDC_MULTI_BUF_LEN; forIndex++)
  581. *(wPtr + forIndex) = wData[forIndex % 16];
  582. }
  583. msdc_cmd.arg = address;
  584. BUG_ON(!host_ctl->mmc->card);
  585. #ifdef MTK_MSDC_USE_CMD23
  586. if ((mmc_card_mmc(host_ctl->mmc->card)
  587. || (mmc_card_sd(host_ctl->mmc->card)
  588. && host_ctl->mmc->card->scr.cmds & SD_SCR_CMD23_SUPPORT))
  589. && !(host_ctl->mmc->card->quirks & MMC_QUIRK_BLK_NO_CMD23)) {
  590. msdc_mrq.sbc = &msdc_sbc;
  591. msdc_mrq.sbc->opcode = MMC_SET_BLOCK_COUNT;
  592. msdc_mrq.sbc->arg = msdc_data.blocks;
  593. msdc_mrq.sbc->flags = MMC_RSP_R1 | MMC_CMD_AC;
  594. }
  595. #endif
  596. msdc_stop.opcode = MMC_STOP_TRANSMISSION;
  597. msdc_stop.arg = 0;
  598. msdc_stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
  599. msdc_data.stop = &msdc_stop;
  600. if (!mmc_card_blockaddr(host_ctl->mmc->card)) {
  601. /* pr_notice("this device use byte address!!\n"); */
  602. msdc_cmd.arg <<= 9;
  603. }
  604. msdc_cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
  605. msdc_data.blksz = 512;
  606. msdc_data.sg = &msdc_sg;
  607. msdc_data.sg_len = 1;
  608. sg_init_one(&msdc_sg, multi_rwbuf, MSDC_MULTI_BUF_LEN);
  609. mmc_set_data_timeout(&msdc_data, host_ctl->mmc->card);
  610. mmc_wait_for_req(host_ctl->mmc, &msdc_mrq);
  611. /* compare */
  612. if (read && !g_ett_tune) {
  613. for (forIndex = 0; forIndex < MSDC_MULTI_BUF_LEN; forIndex++) {
  614. if (rPtr[forIndex] != wData[forIndex % 16]) {
  615. pr_err("index[%d]\tW_buffer[0x%x]\tR_buffer[0x%x]\tfailed\n",
  616. forIndex, wData[forIndex % 16], rPtr[forIndex]);
  617. result = -1;
  618. }
  619. }
  620. }
  621. mmc_release_host(host_ctl->mmc);
  622. if (msdc_cmd.error)
  623. result = msdc_cmd.error;
  624. if (msdc_data.error)
  625. result = msdc_data.error;
  626. else
  627. result = 0;
  628. free:
  629. kfree(multi_rwbuf);
  630. return result;
  631. }
  632. int emmc_multi_rw_compare(int host_num, uint address, int count)
  633. {
  634. int i = 0, j = 0;
  635. int error = 0;
  636. for (i = 0; i < count; i++) {
  637. /* pr_notice("cpu[%d]pid[%d]:start %d time compare\n", task_cpu(current), current->pid, i);*/
  638. mutex_lock(&emmc_lock);
  639. error = emmc_multi_rw_compare_slave(host_num, 0, address); /* write */
  640. if (error) {
  641. pr_err("[%s]: failed to write data, error=%d\n", __func__, error);
  642. mutex_unlock(&emmc_lock);
  643. break;
  644. }
  645. for (j = 0; j < 1; j++) {
  646. error = emmc_multi_rw_compare_slave(host_num, 1, address); /* read */
  647. if (error) {
  648. pr_err("[%s]: failed to read data, error=%d\n", __func__, error);
  649. break;
  650. }
  651. }
  652. if (error)
  653. pr_err
  654. ("============ cpu[%d] pid[%d]: FAILED the %d time compare ============\n",
  655. task_cpu(current), current->pid, i);
  656. else
  657. pr_err
  658. ("============ cpu[%d] pid[%d]: FINISH the %d time compare ============\n",
  659. task_cpu(current), current->pid, i);
  660. mutex_unlock(&emmc_lock);
  661. }
  662. if (i == count)
  663. pr_err("pid[%d]: successed to compare data within %d times\n", current->pid, count);
  664. return error;
  665. }
  666. #define ETT_CMD (0)
  667. #define ETT_DATA_READ (1)
  668. #define ETT_DATA_WRITE (2)
  669. #define ETT_DATA_HS400 (3)
  670. #if 0
  671. /*
  672. * ETT tune of Command & Response
  673. * -- host: the host controller
  674. * -- count: how many time re-send the command is needed before a ETT seting pass
  675. * -- voltage: the voltage(vCore1 & vCore2) which the ETT settings working at
  676. */
  677. void msdc_ett_cmd(struct msdc_host *host, int count, int voltage)
  678. {
  679. int index = 0, j = 0;
  680. char tune_result_cmd[CMD_TUNE_UHS_MAX_TIME];
  681. if (!host || !host->mmc || !host->mmc->card) {
  682. pr_err(" there is no card initialized in host[%d]\n", host->id);
  683. return -1;
  684. }
  685. if (!is_card_present(host)) {
  686. pr_err(" [%s]: card is removed!\n", __func__);
  687. return -1;
  688. }
  689. for (index = 0; index < (CMD_TUNE_UHS_MAX_TIME); index++)
  690. tune_result_cmd[index] = 'Z';
  691. tune_result_cmd[CMD_TUNE_UHS_MAX_TIME] = '\0';
  692. /* init the ETT settings */
  693. /* start ETT tune */
  694. index = 0;
  695. while (index < CMD_TUNE_UHS_MAX_TIME) {
  696. g_ett_cmd_tune = 0;
  697. j = 0;
  698. for (j = 0; j < count; j++) {
  699. emmc_multi_rw_compare_slave(host->id, 1, COMPARE_ADDRESS_MMC);
  700. if (g_ett_cmd_tune > 0) {
  701. do {
  702. tune_result_cmd[index] = 'X';
  703. pr_err("tune_result_cmd[%d]: %c\n", index,
  704. tune_result_cmd[index]);
  705. } while ((--g_ett_cmd_tune > 0)
  706. && (++index < CMD_TUNE_UHS_MAX_TIME));
  707. break;
  708. }
  709. }
  710. if (j == count) {
  711. tune_result_cmd[index] = 'O';
  712. pr_err("tune_result_cmd[%d]: %c\n", index, tune_result_cmd[index]);
  713. msdc_tune_cmdrsp(host);
  714. host->t_counter.time_cmd = 0;
  715. index++;
  716. }
  717. }
  718. tune_result_cmd[CMD_TUNE_UHS_MAX_TIME] = '\0';
  719. /* output the ETT result */
  720. pr_err("==============CMD ETT result at voltage:%dmV, index=%d=============\n", voltage,
  721. index);
  722. index = 0;
  723. while (index < CMD_TUNE_UHS_MAX_TIME) {
  724. mdelay(10);
  725. pr_err("[rsmpl=%d, rrdly=%d, cmdrtc=%d, cksel=%d]",
  726. index % 2, index % (2 * 32), index % (2 * 32 * 8), index(%2 * 32 * 8 * 8));
  727. pr_err
  728. ("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
  729. tune_result_cmd[index + 0], tune_result_cmd[index + 1],
  730. tune_result_cmd[index + 2], tune_result_cmd[index + 3],
  731. tune_result_cmd[index + 4], tune_result_cmd[index + 5],
  732. tune_result_cmd[index + 6], tune_result_cmd[index + 7],
  733. tune_result_cmd[index + 8], tune_result_cmd[index + 9],
  734. tune_result_cmd[index + 10], tune_result_cmd[index + 11],
  735. tune_result_cmd[index + 12], tune_result_cmd[index + 13],
  736. tune_result_cmd[index + 14], tune_result_cmd[index + 15],
  737. tune_result_cmd[index + 16], tune_result_cmd[index + 17],
  738. tune_result_cmd[index + 18], tune_result_cmd[index + 19],
  739. tune_result_cmd[index + 20], tune_result_cmd[index + 21],
  740. tune_result_cmd[index + 22], tune_result_cmd[index + 23],
  741. tune_result_cmd[index + 24], tune_result_cmd[index + 25],
  742. tune_result_cmd[index + 26], tune_result_cmd[index + 27],
  743. tune_result_cmd[index + 28], tune_result_cmd[index + 29],
  744. tune_result_cmd[index + 30], tune_result_cmd[index + 31]);
  745. index += 32;
  746. }
  747. }
  748. /*
  749. * ETT tune of Read Data
  750. * -- host: the host controller
  751. * -- count: how many time re-send the command is needed before a ETT seting pass
  752. * -- voltage: the voltage(vCore1 & vCore2) which the ETT settings working at
  753. */
  754. void msdc_ett_read(struct msdc_host *host, int count, int voltage)
  755. {
  756. int index = 0, j = 0;
  757. char tune_result_read[READ_TUNE_UHS_MAX_TIME];
  758. if (!host || !host->mmc || !host->mmc->card) {
  759. pr_err(" there is no card initialized in host[%d]\n", host->id);
  760. return -1;
  761. }
  762. if (!is_card_present(host)) {
  763. pr_err(" [%s]: card is removed!\n", __func__);
  764. return -1;
  765. }
  766. for (index = 0; index < (READ_TUNE_UHS_MAX_TIME); index++)
  767. tune_result_read[index] = 'Z';
  768. tune_result_read[READ_TUNE_UHS_MAX_TIME] = '\0';
  769. /* init the ETT settings */
  770. /* start ETT tune */
  771. index = 0;
  772. while (index < READ_TUNE_UHS_MAX_TIME) {
  773. g_ett_read_tune = 0;
  774. j = 0;
  775. for (j = 0; j < count; j++) {
  776. emmc_multi_rw_compare_slave(host->id, 1, COMPARE_ADDRESS_MMC);
  777. if (g_ett_read_tune > 0) {
  778. do {
  779. tune_result_read[index] = 'X';
  780. pr_err("tune_result_read[%d]: %c\n", index,
  781. tune_result_read[index]);
  782. } while ((--g_ett_read_tune > 0) && (++index < READ_TUNE_UHS_MAX_TIME));
  783. break;
  784. }
  785. }
  786. if (j == count) {
  787. tune_result_read[index] = 'O';
  788. pr_err("tune_result_read[%d]: %c\n", index, tune_result_read[index]);
  789. msdc_tune_read(host);
  790. host->t_counter.time_read = 0;
  791. index++;
  792. }
  793. }
  794. tune_result_read[READ_TUNE_UHS_MAX_TIME] = '\0';
  795. /* output the ETT result */
  796. pr_err("==============READ ETT result at voltage:%dmV, index=%d=============\n", voltage,
  797. index);
  798. index = 0;
  799. while (index < READ_TUNE_UHS_MAX_TIME) {
  800. mdelay(10);
  801. pr_err("[%d] %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
  802. index / 32, tune_result_read[index + 0], tune_result_read[index + 1],
  803. tune_result_read[index + 2], tune_result_read[index + 3],
  804. tune_result_read[index + 4], tune_result_read[index + 5],
  805. tune_result_read[index + 6], tune_result_read[index + 7],
  806. tune_result_read[index + 8], tune_result_read[index + 9],
  807. tune_result_read[index + 10], tune_result_read[index + 11],
  808. tune_result_read[index + 12], tune_result_read[index + 13],
  809. tune_result_read[index + 14], tune_result_read[index + 15],
  810. tune_result_read[index + 16], tune_result_read[index + 17],
  811. tune_result_read[index + 18], tune_result_read[index + 19],
  812. tune_result_read[index + 20], tune_result_read[index + 21],
  813. tune_result_read[index + 22], tune_result_read[index + 23],
  814. tune_result_read[index + 24], tune_result_read[index + 25],
  815. tune_result_read[index + 26], tune_result_read[index + 27],
  816. tune_result_read[index + 28], tune_result_read[index + 29],
  817. tune_result_read[index + 30], tune_result_read[index + 31]);
  818. index += 32;
  819. }
  820. }
  821. /*
  822. * ETT tune of Write Data
  823. * -- host: the host controller
  824. * -- count: how many time re-send the command is needed before a ETT seting pass
  825. * -- voltage: the voltage(vCore1 & vCore2) which the ETT settings working at
  826. */
  827. void msdc_ett_write(struct msdc_host *host, int count, int voltage)
  828. {
  829. int index = 0, j = 0;
  830. char tune_result_write[WRITE_TUNE_UHS_MAX_TIME];
  831. if (!host || !host->mmc || !host->mmc->card) {
  832. pr_err(" there is no card initialized in host[%d]\n", host->id);
  833. return -1;
  834. }
  835. if (!is_card_present(host)) {
  836. pr_err(" [%s]: card is removed!\n", __func__);
  837. return -1;
  838. }
  839. for (index = 0; index < (WRITE_TUNE_UHS_MAX_TIME); index++)
  840. tune_result_write[index] = 'Z';
  841. tune_result_write[WRITE_TUNE_UHS_MAX_TIME] = '\0';
  842. /* init the ETT settings */
  843. /* start ETT tune */
  844. index = 0;
  845. while (index < WRITE_TUNE_UHS_MAX_TIME) {
  846. g_ett_write_tune = 0;
  847. j = 0;
  848. for (j = 0; j < count; j++) {
  849. emmc_multi_rw_compare_slave(host->id, 0, COMPARE_ADDRESS_MMC);
  850. if (g_ett_write_tune > 0) {
  851. do {
  852. tune_result_write[index] = 'X';
  853. pr_err("tune_result_write[%d]: %c\n", index,
  854. tune_result_write[index]);
  855. } while ((--g_ett_write_tune > 0)
  856. && (++index < WRITE_TUNE_UHS_MAX_TIME));
  857. break;
  858. }
  859. }
  860. if (j == count) {
  861. tune_result_write[index] = 'O';
  862. pr_err("tune_result_write[%d]: %c\n", index, tune_result_write[index]);
  863. msdc_tune_write(host);
  864. host->t_counter.time_write = 0;
  865. index++;
  866. }
  867. }
  868. tune_result_write[WRITE_TUNE_UHS_MAX_TIME] = '\0';
  869. /* output the ETT result */
  870. pr_err("==============WRITE ETT result at voltage:%dmV, index=%d =============\n", voltage,
  871. index);
  872. index = 0;
  873. while (index < WRITE_TUNE_UHS_MAX_TIME) {
  874. mdelay(10);
  875. pr_err("[%d] %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
  876. index / 32, tune_result_write[index + 0], tune_result_write[index + 1],
  877. tune_result_write[index + 2], tune_result_write[index + 3],
  878. tune_result_write[index + 4], tune_result_write[index + 5],
  879. tune_result_write[index + 6], tune_result_write[index + 7],
  880. tune_result_write[index + 8], tune_result_write[index + 9],
  881. tune_result_write[index + 10], tune_result_write[index + 11],
  882. tune_result_write[index + 12], tune_result_write[index + 13],
  883. tune_result_write[index + 14], tune_result_write[index + 15],
  884. tune_result_write[index + 16], tune_result_write[index + 17],
  885. tune_result_write[index + 18], tune_result_write[index + 19],
  886. tune_result_write[index + 20], tune_result_write[index + 21],
  887. tune_result_write[index + 22], tune_result_write[index + 23],
  888. tune_result_write[index + 24], tune_result_write[index + 25],
  889. tune_result_write[index + 26], tune_result_write[index + 27],
  890. tune_result_write[index + 28], tune_result_write[index + 29],
  891. tune_result_write[index + 30], tune_result_write[index + 31]);
  892. index += 32;
  893. }
  894. }
  895. #endif
  896. #ifndef CONFIG_MTK_FPGA
  897. /*
  898. * ETT tune of HS400 Data
  899. * -- host: the host controller
  900. * -- count: how many time re-send the command is needed before a ETT seting pass
  901. * -- voltage: the voltage(vCore1 & vCore2) which the ETT settings working at
  902. */
  903. void msdc_ett_hs400(struct msdc_host *host, int count, int voltage)
  904. {
  905. int index = 0, j = 0, skip = 0;
  906. char tune_result_hs400[32 * 32 + 1];
  907. void __iomem *base;
  908. unsigned int ds_dly1 = 0, ds_dly3 = 0, orig_ds_dly1 = 0, orig_ds_dly3 = 0;
  909. if (!host || !host->mmc || !host->mmc->card) {
  910. pr_err(" there is no card initialized in host\n");
  911. return;
  912. }
  913. if (!is_card_present(host)) {
  914. pr_err(" [%s]: card is removed!\n", __func__);
  915. return;
  916. }
  917. base = host->base;
  918. for (index = 0; index < (32 * 32); index++)
  919. tune_result_hs400[index] = 'Z';
  920. tune_result_hs400[32 * 32] = '\0';
  921. /* init the ETT settings */
  922. sdr_set_field(EMMC50_PAD_DS_TUNE, MSDC_EMMC50_PAD_DS_TUNE_DLY1, 0);
  923. sdr_set_field(EMMC50_PAD_DS_TUNE, MSDC_EMMC50_PAD_DS_TUNE_DLY3, 0);
  924. /* start ETT tune */
  925. index = 0;
  926. while (index < (32 * 32)) {
  927. sdr_get_field(EMMC50_PAD_DS_TUNE, MSDC_EMMC50_PAD_DS_TUNE_DLY1, orig_ds_dly1);
  928. sdr_get_field(EMMC50_PAD_DS_TUNE, MSDC_EMMC50_PAD_DS_TUNE_DLY3, orig_ds_dly3);
  929. /* pr_err("[%s]: tune ds1=%d, ds3=%d\n", __func__, orig_ds_dly1, orig_ds_dly3); */
  930. for (j = 0; j < count; j++) {
  931. emmc_multi_rw_compare_slave(host->id, 0, COMPARE_ADDRESS_MMC);
  932. emmc_multi_rw_compare_slave(host->id, 1, COMPARE_ADDRESS_MMC);
  933. }
  934. sdr_get_field(EMMC50_PAD_DS_TUNE, MSDC_EMMC50_PAD_DS_TUNE_DLY1, ds_dly1);
  935. sdr_get_field(EMMC50_PAD_DS_TUNE, MSDC_EMMC50_PAD_DS_TUNE_DLY3, ds_dly3);
  936. skip = (ds_dly1 - orig_ds_dly1) * 32 + (ds_dly3 - orig_ds_dly3);
  937. if (skip == 0) {
  938. tune_result_hs400[index] = 'O';
  939. pr_err("tune_result_hs400[%d]: %c, ds1=%d, ds3=%d, skip=0\n",
  940. index, tune_result_hs400[index], ds_dly1, ds_dly3);
  941. emmc_hs400_tune_rw(host);
  942. host->t_counter.time_hs400 = 0;
  943. index++;
  944. } else if (skip > 0) {
  945. do {
  946. tune_result_hs400[index] = 'X';
  947. pr_err("tune_result_hs400[%d]: %c, ds1=%d, ds3=%d, skip=%d\n",
  948. index, tune_result_hs400[index], orig_ds_dly1, orig_ds_dly3,
  949. skip);
  950. index++;
  951. if (++orig_ds_dly3 >= 32) {
  952. orig_ds_dly3 = 0;
  953. if (++orig_ds_dly1 >= 32)
  954. orig_ds_dly1 = 0;
  955. }
  956. } while ((--skip > 0) && (index < (32 * 32)));
  957. } else {
  958. pr_err
  959. ("ETT settings failed, skip: %d, orig_ds1=%d, orig_ds3=%d, ds1=%d, ds3=%d\n",
  960. skip, orig_ds_dly1, orig_ds_dly3, ds_dly1, ds_dly3);
  961. do {
  962. tune_result_hs400[index] = 'X';
  963. } while (++index < (32 * 32));
  964. }
  965. }
  966. tune_result_hs400[32 * 32] = '\0';
  967. /* output the ETT result */
  968. pr_err("==============HS400 ETT result at voltage:%dmV, index=%d =============\n", voltage,
  969. index);
  970. index = 0;
  971. while (index < (32 * 32)) {
  972. mdelay(10);
  973. pr_err
  974. ("[ds1=%d] %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
  975. index / 32, tune_result_hs400[index + 0], tune_result_hs400[index + 1],
  976. tune_result_hs400[index + 2], tune_result_hs400[index + 3],
  977. tune_result_hs400[index + 4], tune_result_hs400[index + 5],
  978. tune_result_hs400[index + 6], tune_result_hs400[index + 7],
  979. tune_result_hs400[index + 8], tune_result_hs400[index + 9],
  980. tune_result_hs400[index + 10], tune_result_hs400[index + 11],
  981. tune_result_hs400[index + 12], tune_result_hs400[index + 13],
  982. tune_result_hs400[index + 14], tune_result_hs400[index + 15],
  983. tune_result_hs400[index + 16], tune_result_hs400[index + 17],
  984. tune_result_hs400[index + 18], tune_result_hs400[index + 19],
  985. tune_result_hs400[index + 20], tune_result_hs400[index + 21],
  986. tune_result_hs400[index + 22], tune_result_hs400[index + 23],
  987. tune_result_hs400[index + 24], tune_result_hs400[index + 25],
  988. tune_result_hs400[index + 26], tune_result_hs400[index + 27],
  989. tune_result_hs400[index + 28], tune_result_hs400[index + 29],
  990. tune_result_hs400[index + 30], tune_result_hs400[index + 31]);
  991. index += 32;
  992. }
  993. }
  994. #define ETT_VCORE1 (0)
  995. #define ETT_VCORE2 (1)
  996. #define ETT_VIO (3)
  997. int msdc_ett_set_voltage(int type, int vol, int vol_on)
  998. {
  999. if (vol < 0 || vol > 0x7f || vol_on < 0 || vol_on > 0x7f) {
  1000. pr_err("[%s]: invalid voltage: %d, %d\n", __func__, vol, vol_on);
  1001. return -1;
  1002. }
  1003. if (type < 0) {
  1004. pr_err("[%s]: invalid type: %d\n", __func__, type);
  1005. return -1;
  1006. }
  1007. switch (type) {
  1008. case ETT_VCORE1:
  1009. pmic_config_interface(0x24c, vol, 0x7f, 0); /* VDFS11_VOSEL */
  1010. pmic_config_interface(0x24e, vol_on, 0x7f, 0); /* VDFS11_VOSEL_ON */
  1011. mdelay(10);
  1012. break;
  1013. case ETT_VCORE2:
  1014. pmic_config_interface(0x36a, vol, 0x7f, 0); /* VCORE2_VOSEL */
  1015. pmic_config_interface(0x36c, vol_on, 0x7f, 0); /* VCORE2_VOSEL_ON */
  1016. mdelay(10);
  1017. break;
  1018. case ETT_VIO:
  1019. pmic_config_interface(0x396, vol, 0x7F, 0); /* VIO18_VOSEL; */
  1020. pmic_config_interface(0x398, vol_on, 0x7F, 0); /* VIO18_VOSEL_ON; */
  1021. mdelay(10);
  1022. break;
  1023. default:
  1024. pr_err("[%s]: invalid type: %d\n", __func__, type);
  1025. break;
  1026. }
  1027. return 0;
  1028. }
  1029. int msdc_ett_get_voltage(int type, int *vol, int *vol_on)
  1030. {
  1031. if (type < 0) {
  1032. pr_err("[%s]: invalid type: %d\n", __func__, type);
  1033. return -1;
  1034. }
  1035. switch (type) {
  1036. case ETT_VCORE1:
  1037. pmic_read_interface(0x24c, vol, 0x7f, 0); /* VDFS11_VOSEL */
  1038. pmic_read_interface(0x24e, vol_on, 0x7f, 0); /* VDFS11_VOSEL_ON */
  1039. break;
  1040. case ETT_VCORE2:
  1041. pmic_read_interface(0x36a, vol, 0x7f, 0); /* VCORE2_VOSEL */
  1042. pmic_read_interface(0x36c, vol_on, 0x7f, 0); /* VCORE2_VOSEL_ON */
  1043. break;
  1044. case ETT_VIO:
  1045. pmic_read_interface(0x396, vol, 0x7F, 0); /* VIO18_VOSEL; */
  1046. pmic_read_interface(0x398, vol_on, 0x7F, 0); /* VIO18_VOSEL_ON; */
  1047. break;
  1048. default:
  1049. pr_err("[%s]: invalid type: %d\n", __func__, type);
  1050. break;
  1051. }
  1052. return 0;
  1053. }
  1054. /*
  1055. * ETT tune of eMMC
  1056. * -- host_num: the host controller port ID
  1057. * -- type: what settings does ETT tune for? command, read data, write data
  1058. * -- count: how many time re-send the command is needed before a ETT seting pass
  1059. * -- voltage: the voltage(vCore1 & vCore2) which the ETT settings working at
  1060. */
  1061. int msdc_ett_tunning(int host_num, int type, int count, int start_voltage, int end_voltage)
  1062. {
  1063. int i = 0;
  1064. int start_vol = 0, end_vol = 0, temp_vol = 0;
  1065. struct msdc_host *host;
  1066. unsigned int orig_vcore1_vosel = 0, orig_vcore1_vosel_on = 0, orig_vcore2_vosel =
  1067. 0, orig_vcore2_vosel_on = 0, orig_vio_vosel = 0, orig_vio_vosel_on = 0;
  1068. char l_buf[512];
  1069. char orig_partition;
  1070. int div_for_temp;
  1071. int mul_for_temp;
  1072. host = mtk_msdc_host[host_num];
  1073. if (!host || !host->mmc || !host->mmc->card) {
  1074. pr_err(" there is no card initialized in host[%d]\n", host_num);
  1075. return -1;
  1076. }
  1077. if (!is_card_present(host)) {
  1078. pr_err(" [%s]: card is removed!\n", __func__);
  1079. return -1;
  1080. }
  1081. /* calculate the voltage range (mV) */
  1082. div_for_temp = 25; /*6.25 * 4 */
  1083. start_vol = (int)((start_voltage - 700) * 4 / div_for_temp); /* 1.05v */
  1084. end_vol = (int)((end_voltage - 700) * 4 / div_for_temp); /* 0.9v */
  1085. if ((start_vol < 0) || (end_vol < 0) || (end_vol > 0x7f) || (start_vol > 0x7f)) {
  1086. pr_err(" invalid voltage: start_vol=%d, end_vol=%d\n", start_vol, end_vol);
  1087. return -1;
  1088. } else if (start_vol < end_vol) {
  1089. temp_vol = start_vol;
  1090. start_vol = end_vol;
  1091. end_vol = temp_vol;
  1092. }
  1093. mmc_claim_host(host->mmc);
  1094. g_ett_tune = 1;
  1095. /* make sure access partition is user data area */
  1096. pr_err("[%s]: switch to user data partition\n", __func__);
  1097. mmc_send_ext_csd(host->mmc->card, l_buf);
  1098. orig_partition = l_buf[179] & 0x7;
  1099. if (0 != orig_partition) {
  1100. /* set back to access user area */
  1101. l_buf[179] &= ~0x7;
  1102. l_buf[179] |= 0x0;
  1103. mmc_switch(host->mmc->card, 0, 179, l_buf[179], 1000);
  1104. }
  1105. /* back up the origial voltage settings */
  1106. pr_err("[%s]: line:%d, back up original voltage settings\n", __func__, __LINE__);
  1107. msdc_ett_get_voltage(ETT_VCORE1, &orig_vcore1_vosel, &orig_vcore1_vosel_on);
  1108. msdc_ett_get_voltage(ETT_VCORE2, &orig_vcore2_vosel, &orig_vcore2_vosel_on);
  1109. msdc_ett_get_voltage(ETT_VIO, &orig_vio_vosel, &orig_vio_vosel_on);
  1110. msdc_ett_set_voltage(ETT_VIO, 0x28, 0x28); /* 1.9v */
  1111. /* ETT tune by type */
  1112. pr_err
  1113. (" ====================MSDC%d, start ETT tune from %dmV to %d mV==========================\n",
  1114. host_num, start_vol, end_vol);
  1115. for (i = start_vol; i >= end_vol; i--) {
  1116. /* change voltage */
  1117. if (msdc_ett_set_voltage(ETT_VCORE1, i, i) < 0)
  1118. continue;
  1119. if (msdc_ett_set_voltage(ETT_VCORE2, i, i) < 0)
  1120. continue;
  1121. mul_for_temp = 25; /*6.25 * 4 */
  1122. switch (type) {
  1123. #if 0
  1124. case ETT_CMD:
  1125. msdc_ett_cmd(host, count, (unsigned int)(mul_for_temp * i / 4 + 700));
  1126. break;
  1127. case ETT_DATA_READ:
  1128. if (host->timing != MMC_TIMING_MMC_HS400) {
  1129. msdc_ett_read(host, count,
  1130. (unsigned int)(mul_for_temp * i / 4 + 700));
  1131. break;
  1132. }
  1133. case ETT_DATA_WRITE:
  1134. if (host->timing != MMC_TIMING_MMC_HS400) {
  1135. msdc_ett_write(host, count,
  1136. (unsigned int)(mul_for_temp * i / 4 + 700));
  1137. break;
  1138. }
  1139. case ETT_DATA_HS400:
  1140. if (host->timing == MMC_TIMING_MMC_HS400) {
  1141. msdc_ett_hs400(host, count,
  1142. (unsigned int)(mul_for_temp * i / 4 + 700));
  1143. }
  1144. break;
  1145. #endif
  1146. default:
  1147. pr_err("[%s]: invalid type: %d\n", __func__, type);
  1148. break;
  1149. }
  1150. }
  1151. /* restore the original voltage settings */
  1152. pr_err
  1153. ("[%s]: restore the original voltage settigns: vdfs11[%d, %d], vcore2[%d, %d], vio[%d, %d]\n",
  1154. __func__, orig_vcore1_vosel, orig_vcore1_vosel_on, orig_vcore2_vosel,
  1155. orig_vcore2_vosel_on, orig_vio_vosel, orig_vio_vosel_on);
  1156. msdc_ett_set_voltage(ETT_VCORE1, orig_vcore1_vosel, orig_vcore1_vosel_on);
  1157. msdc_ett_set_voltage(ETT_VCORE2, orig_vcore2_vosel, orig_vcore2_vosel_on);
  1158. msdc_ett_set_voltage(ETT_VIO, orig_vio_vosel, orig_vio_vosel_on);
  1159. g_ett_tune = 0;
  1160. if (0 != orig_partition) {
  1161. pr_err("[%s]: switch back to original parittion:%d\n", __func__, orig_partition);
  1162. /* set back to access user area */
  1163. l_buf[179] &= ~0x7;
  1164. l_buf[179] |= orig_partition;
  1165. mmc_switch(host->mmc->card, 0, 179, l_buf[179], 1000);
  1166. }
  1167. mmc_release_host(host->mmc);
  1168. pr_err
  1169. (" ====================MSDC%d, end ETT tune from %dmV to %d mV==========================\n",
  1170. host_num, start_vol, end_vol);
  1171. return 0;
  1172. }
  1173. #endif
  1174. #define MAX_THREAD_NUM_FOR_SMP 20
  1175. /* make the test can run on 4GB card */
  1176. static uint smp_address_on_sd[MAX_THREAD_NUM_FOR_SMP] = {
  1177. 0x2000,
  1178. 0x80000,
  1179. 0x100000,
  1180. 0x180000,
  1181. 0x200000, /* 1GB */
  1182. 0x202000,
  1183. 0x280000,
  1184. 0x300000,
  1185. 0x380000,
  1186. 0x400000, /* 2GB */
  1187. 0x402000,
  1188. 0x480000,
  1189. 0x500000,
  1190. 0x580000,
  1191. 0x600000,
  1192. 0x602000, /* 3GB */
  1193. 0x660000, /* the real total size of 4GB sd card is below 4GB */
  1194. 0x680000,
  1195. 0x6a0000,
  1196. 0x6b0000,
  1197. };
  1198. /* cause the system run on the emmc storage,
  1199. * so do not to access the first 2GB region */
  1200. static uint smp_address_on_mmc[MAX_THREAD_NUM_FOR_SMP] = {
  1201. 0x402000,
  1202. 0x410000,
  1203. 0x520000,
  1204. 0x530000,
  1205. 0x640000,
  1206. 0x452000,
  1207. 0x460000,
  1208. 0x470000,
  1209. 0x480000,
  1210. 0x490000,
  1211. 0x4a2000,
  1212. 0x4b0000,
  1213. 0x5c0000,
  1214. 0x5d0000,
  1215. 0x6e0000,
  1216. 0x602000,
  1217. 0x660000, /* the real total size of 4GB sd card is below 4GB */
  1218. 0x680000,
  1219. 0x6a0000,
  1220. 0x6b0000,
  1221. };
  1222. static uint smp_address_on_sd_combo[MAX_THREAD_NUM_FOR_SMP] = {
  1223. 0x2000,
  1224. 0x20000,
  1225. 0x200000,
  1226. 0x2000000,
  1227. 0x2200000,
  1228. 0x2400000,
  1229. 0x2800000,
  1230. 0x2c00000,
  1231. 0x4000000,
  1232. 0x4200000,
  1233. 0x4400000,
  1234. 0x4800000,
  1235. 0x4c00000,
  1236. 0x8000000,
  1237. 0x8200000,
  1238. 0x8400000,
  1239. 0x8800000,
  1240. 0x8c00000,
  1241. 0xc000000,
  1242. 0xc200000
  1243. };
  1244. struct write_read_data {
  1245. int host_id; /* the target host you want to do SMP test on. */
  1246. uint start_address; /* where you want to do write/read of the memory card */
  1247. int count; /* how many times you want to do read after write bit by bit comparison */
  1248. };
  1249. static struct write_read_data wr_data[HOST_MAX_NUM][MAX_THREAD_NUM_FOR_SMP];
  1250. /*
  1251. * 2012-03-25
  1252. * the SMP thread function
  1253. * do read after write the memory card, and bit by bit comparison
  1254. */
  1255. static int write_read_thread(void *ptr)
  1256. {
  1257. struct write_read_data *data = (struct write_read_data *)ptr;
  1258. if (1 == data->host_id) {
  1259. pr_err("sd thread\n");
  1260. sd_multi_rw_compare(data->host_id, data->start_address, data->count);
  1261. } else if (0 == data->host_id) {
  1262. pr_err("emmc thread\n");
  1263. emmc_multi_rw_compare(data->host_id, data->start_address, data->count);
  1264. }
  1265. return 0;
  1266. }
  1267. /*
  1268. * 2012-03-25
  1269. * function: do SMP test on the same one MSDC host
  1270. * thread_num: the number of thread you want to trigger on this host.
  1271. * host_id: the target host you want to do SMP test on.
  1272. * count: how many times you want to do read after write bit by bit comparison in each thread.
  1273. * multi_address: whether do read/write the same/different address of the memory card in each thread.
  1274. */
  1275. static int smp_test_on_one_host(int thread_num, int host_id, int count, int multi_address)
  1276. {
  1277. int i = 0, ret = 0;
  1278. char thread_name[128];
  1279. struct msdc_host *host_ctl;
  1280. pr_err("============================[%s] start ================================\n\n",
  1281. __func__);
  1282. pr_err(" host %d run %d thread, each thread run %d RW comparison\n",
  1283. host_id, thread_num, count);
  1284. if (host_id >= HOST_MAX_NUM || host_id < 0) {
  1285. pr_err(" bad host id: %d\n", host_id);
  1286. ret = -1;
  1287. goto out;
  1288. }
  1289. if (thread_num > MAX_THREAD_NUM_FOR_SMP) { /* && (multi_address != 0)) */
  1290. pr_err(" too much thread for SMP test, thread_num=%d\n", thread_num);
  1291. ret = -1;
  1292. goto out;
  1293. }
  1294. host_ctl = mtk_msdc_host[host_id];
  1295. if (!host_ctl || !host_ctl->mmc || !host_ctl->mmc->card) {
  1296. pr_err(" there is no card initialized in host[%d]\n", host_id);
  1297. ret = -1;
  1298. goto out;
  1299. }
  1300. for (i = 0; i < thread_num; i++) {
  1301. switch (host_ctl->mmc->card->type) {
  1302. case MMC_TYPE_MMC:
  1303. if (!multi_address)
  1304. wr_data[host_id][i].start_address = COMPARE_ADDRESS_MMC;
  1305. else
  1306. wr_data[host_id][i].start_address = smp_address_on_mmc[i];
  1307. if (i == 0)
  1308. pr_err(" MSDC[%d], MMC:\n", host_id);
  1309. break;
  1310. case MMC_TYPE_SD:
  1311. if (!multi_address)
  1312. wr_data[host_id][i].start_address = COMPARE_ADDRESS_SD;
  1313. else
  1314. wr_data[host_id][i].start_address = smp_address_on_sd[i];
  1315. if (i == 0)
  1316. pr_err(" MSDC[%d], SD:\n", host_id);
  1317. break;
  1318. case MMC_TYPE_SDIO:
  1319. if (i == 0) {
  1320. pr_err(" MSDC[%d], SDIO:\n", host_id);
  1321. pr_err
  1322. ("manually trigger wifi instead of write/read on SDIO card\n");
  1323. }
  1324. ret = -1;
  1325. goto out;
  1326. case MMC_TYPE_SD_COMBO:
  1327. if (!multi_address)
  1328. wr_data[host_id][i].start_address = COMPARE_ADDRESS_SD_COMBO;
  1329. else
  1330. wr_data[host_id][i].start_address = smp_address_on_sd_combo[i];
  1331. if (i == 0)
  1332. pr_err(" MSDC[%d], SD_COMBO:\n", host_id);
  1333. break;
  1334. default:
  1335. if (i == 0)
  1336. pr_err(" MSDC[%d], cannot recognize this card\n", host_id);
  1337. ret = -1;
  1338. goto out;
  1339. }
  1340. wr_data[host_id][i].host_id = host_id;
  1341. wr_data[host_id][i].count = count;
  1342. sprintf(thread_name, "msdc_H%d_T%d", host_id, i);
  1343. kthread_run(write_read_thread, &wr_data[host_id][i], thread_name);
  1344. pr_err(" start thread: %s, at address 0x%x\n",
  1345. thread_name, wr_data[host_id][i].start_address);
  1346. }
  1347. out:
  1348. pr_err("============================[%s] end ================================\n\n",
  1349. __func__);
  1350. return ret;
  1351. }
  1352. /*
  1353. * 2012-03-25
  1354. * function: do SMP test on all MSDC hosts
  1355. * thread_num: the number of thread you want to trigger on this host.
  1356. * count: how many times you want to do read after write bit by bit comparison in each thread.
  1357. * multi_address: whether do read/write the same/different address of the memory card in each thread.
  1358. */
  1359. static int smp_test_on_all_host(int thread_num, int count, int multi_address)
  1360. {
  1361. int i = 0;
  1362. int j = 0;
  1363. int ret = 0;
  1364. char thread_name[128];
  1365. struct msdc_host *host_ctl;
  1366. pr_err("============================[%s] start ================================\n\n",
  1367. __func__);
  1368. pr_err(" each host run %d thread, each thread run %d RW comparison\n", thread_num, count);
  1369. if (thread_num > MAX_THREAD_NUM_FOR_SMP) { /* && (multi_address != 0)) */
  1370. pr_err(" too much thread for SMP test, thread_num=%d\n", thread_num);
  1371. ret = -1;
  1372. goto out;
  1373. }
  1374. for (i = 0; i < HOST_MAX_NUM; i++) {
  1375. host_ctl = mtk_msdc_host[i];
  1376. if (!host_ctl || !host_ctl->mmc || !host_ctl->mmc->card) {
  1377. pr_err(" MSDC[%d], no card is initialized\n", i);
  1378. continue;
  1379. }
  1380. if (host_ctl->mmc->card->type == MMC_TYPE_SDIO) {
  1381. pr_err
  1382. (" MSDC[%d],manually trigger wifi instead of write/read on SDIO\n",
  1383. i);
  1384. continue;
  1385. }
  1386. for (j = 0; j < thread_num; j++) {
  1387. wr_data[i][j].host_id = i;
  1388. wr_data[i][j].count = count;
  1389. switch (host_ctl->mmc->card->type) {
  1390. case MMC_TYPE_MMC:
  1391. if (!multi_address)
  1392. wr_data[i][j].start_address = COMPARE_ADDRESS_MMC;
  1393. else
  1394. wr_data[i][j].start_address = smp_address_on_mmc[i];
  1395. if (j == 0)
  1396. pr_err(" MSDC[%d], MMC:\n ", i);
  1397. break;
  1398. case MMC_TYPE_SD:
  1399. if (!multi_address)
  1400. wr_data[i][j].start_address = COMPARE_ADDRESS_SD;
  1401. else
  1402. wr_data[i][j].start_address = smp_address_on_sd[i];
  1403. if (j == 0)
  1404. pr_err(" MSDC[%d], SD:\n", i);
  1405. break;
  1406. case MMC_TYPE_SDIO:
  1407. if (j == 0) {
  1408. pr_err(" MSDC[%d], SDIO:\n", i);
  1409. pr_err
  1410. ("manually trigger wifi application instead of write/read on SDIO\n");
  1411. }
  1412. ret = -1;
  1413. goto out;
  1414. case MMC_TYPE_SD_COMBO:
  1415. if (!multi_address)
  1416. wr_data[i][j].start_address = COMPARE_ADDRESS_SD_COMBO;
  1417. else
  1418. wr_data[i][j].start_address = smp_address_on_sd_combo[i];
  1419. if (j == 0)
  1420. pr_err(" MSDC[%d], SD_COMBO:\n", i);
  1421. break;
  1422. default:
  1423. if (j == 0)
  1424. pr_err(" MSDC[%d], cannot recognize this card\n", i);
  1425. ret = -1;
  1426. goto out;
  1427. }
  1428. sprintf(thread_name, "msdc_H%d_T%d", i, j);
  1429. kthread_run(write_read_thread, &wr_data[i][j], thread_name);
  1430. pr_err(" start thread: %s, at address: 0x%x\n",
  1431. thread_name, wr_data[i][j].start_address);
  1432. }
  1433. }
  1434. out:
  1435. pr_err("============================[%s] end ================================\n\n",
  1436. __func__);
  1437. return ret;
  1438. }
  1439. static int msdc_help_proc_show(struct seq_file *m, void *v)
  1440. {
  1441. seq_puts(m, "\n====================[msdc_help]=====================\n");
  1442. seq_printf(m, "\n LOG control: echo %x [host_id] [debug_zone] > msdc_debug\n",
  1443. SD_TOOL_ZONE);
  1444. seq_printf(m,
  1445. " [debug_zone] DMA:0x%x, CMD:0x%x, RSP:0x%x, INT:0x%x, CFG:0x%x, FUC:0x%x,\n",
  1446. MSDC_EVT_DMA, MSDC_EVT_CMD, MSDC_EVT_RSP, MSDC_EVT_INT, MSDC_EVT_CFG,
  1447. MSDC_EVT_FUC);
  1448. seq_printf(m,
  1449. " OPS:0x%x, FIO:0x%x, WRN:0x%x, PWR:0x%x, CLK:0x%x, RW:0x%x, NRW:0x%x, CHE:0x%x\n",
  1450. MSDC_EVT_OPS, MSDC_EVT_FIO, MSDC_EVT_WRN, MSDC_EVT_PWR, MSDC_EVT_CLK,
  1451. MSDC_EVT_RW, MSDC_EVT_NRW, MSDC_EVT_CHE);
  1452. seq_puts(m, "\n DMA mode:\n");
  1453. seq_printf(m,
  1454. " set DMA mode: echo %x 0 [host_id] [dma_mode] [dma_size] > msdc_debug\n",
  1455. SD_TOOL_DMA_SIZE);
  1456. seq_printf(m, " get DMA mode: echo %x 1 [host_id] > msdc_debug\n",
  1457. SD_TOOL_DMA_SIZE);
  1458. seq_puts(m, " [dma_mode] 0:PIO, 1:DMA, 2:SIZE_DEP\n");
  1459. seq_printf(m,
  1460. " [dma_size] valid for SIZE_DEP mode, the min size can trigger the DMA mode\n");
  1461. seq_printf(m, "\n SDIO profile: echo %x [enable] [time] > msdc_debug\n",
  1462. SD_TOOL_SDIO_PROFILE);
  1463. seq_puts(m, "\n CLOCK control:\n");
  1464. seq_printf(m, " set clk src: echo %x 0 [host_id] [clk_src] > msdc_debug\n",
  1465. SD_TOOL_CLK_SRC_SELECT);
  1466. seq_printf(m, " get clk src: echo %x 1 [host_id] > msdc_debug\n",
  1467. SD_TOOL_CLK_SRC_SELECT);
  1468. seq_puts(m,
  1469. " [clk_src] msdc0: 0:26M, 1:800M, 2:400M, 3:200M, 4:182M, 5:136M, 6:156M, 7:48M, 8:91M\n");
  1470. seq_puts(m,
  1471. " [clk_src] msdc1/2/3: 0:26M, 1:208M, 2:200M, 3:182M, 4:182M, 5:136M, 6:156M, 7:48M, 8:91M\n");
  1472. seq_puts(m, "\n REGISTER control:\n");
  1473. seq_printf(m,
  1474. " write register: echo %x 0 [host_id] [register_offset] [value] > msdc_debug\n",
  1475. SD_TOOL_REG_ACCESS);
  1476. seq_printf(m,
  1477. " read register: echo %x 1 [host_id] [register_offset] > msdc_debug\n",
  1478. SD_TOOL_REG_ACCESS);
  1479. seq_printf(m,
  1480. " write mask: echo %x 2 [host_id] [register_offset] [start_bit] [len] [value] > msdc_debug\n",
  1481. SD_TOOL_REG_ACCESS);
  1482. seq_printf(m,
  1483. " read mask: echo %x 3 [host_id] [register_offset] [start_bit] [len] > msdc_debug\n",
  1484. SD_TOOL_REG_ACCESS);
  1485. seq_printf(m, " dump all: echo %x 4 [host_id]> msdc_debug\n",
  1486. SD_TOOL_REG_ACCESS);
  1487. seq_puts(m, "\n DRVING control:\n");
  1488. seq_printf(m,
  1489. " set driving: echo %x [host_id] [clk_drv] [cmd_drv] [dat_drv] [rst_drv] [ds_drv] [voltage] > msdc_debug\n",
  1490. SD_TOOL_SET_DRIVING);
  1491. seq_puts(m, " [voltage] 0x18:18v, 0x33:33v\n");
  1492. seq_puts(m, "\n DESENSE control:\n");
  1493. seq_printf(m, " write register: echo %x 0 [value] > msdc_debug\n",
  1494. SD_TOOL_DESENSE);
  1495. seq_printf(m, " read register: echo %x 1 > msdc_debug\n", SD_TOOL_DESENSE);
  1496. seq_printf(m,
  1497. " write mask: echo %x 2 [start_bit] [len] [value] > msdc_debug\n",
  1498. SD_TOOL_DESENSE);
  1499. seq_printf(m, " read mask: echo %x 3 [start_bit] [len] > msdc_debug\n",
  1500. SD_TOOL_DESENSE);
  1501. seq_printf(m,
  1502. "\n RW_COMPARE test: echo %x [host_id] [compare_count] > msdc_debug\n",
  1503. RW_BIT_BY_BIT_COMPARE);
  1504. seq_printf(m,
  1505. " [compare_count] how many time you want to \"write=>read=>compare\"\n");
  1506. seq_printf(m,
  1507. "\n SMP_ON_ONE_HOST test: echo %x [host_id] [thread_num] [compare_count] [multi_address] > msdc_debug\n",
  1508. SMP_TEST_ON_ONE_HOST);
  1509. seq_printf(m,
  1510. " [thread_num] how many R/W comparision thread you want to run at host_id\n");
  1511. seq_printf(m,
  1512. " [compare_count] how many time you want to \"write=>read=>compare\" in each thread\n");
  1513. seq_printf(m,
  1514. " [multi_address] whether read/write different address in each thread, 0:No, 1:Yes\n");
  1515. seq_printf(m,
  1516. "\n SMP_ON_ALL_HOST test: echo %x [thread_num] [compare_count] [multi_address] > msdc_debug\n",
  1517. SMP_TEST_ON_ALL_HOST);
  1518. seq_printf(m,
  1519. " [thread_num] how many R/W comparision thread you want to run at each host\n");
  1520. seq_printf(m,
  1521. " [compare_count] how many time you want to \"write=>read=>compare\" in each thread\n");
  1522. seq_printf(m,
  1523. " [multi_address] whether read/write different address in each thread, 0:No, 1:Yes\n");
  1524. seq_puts(m, "\n SPEED_MODE control:\n");
  1525. seq_printf(m,
  1526. " set speed mode: echo %x 0 [host_id] [speed_mode] [driver_type] [max_current] [power_control] > msdc_debug\n",
  1527. SD_TOOL_MSDC_HOST_MODE);
  1528. seq_printf(m, " get speed mode: echo %x 1 [host_id]\n", SD_TOOL_MSDC_HOST_MODE);
  1529. seq_printf(m,
  1530. " [speed_mode] ff:N/A, 0:HS, 1:SDR12, 2:SDR25, 3:SDR:50, 4:SDR104, 5:DDR, 6:HS400\n");
  1531. seq_printf(m,
  1532. " [driver_type] ff:N/A, 0: type A, 1:type B, 2:type C, 3:type D\n");
  1533. seq_printf(m,
  1534. " [max_current] ff:N/A, 0:200mA, 1:400mA, 2:600mA, 3:800mA\n");
  1535. seq_puts(m, " [power_control] ff:N/A, 0:disable, 1:enable\n");
  1536. seq_printf(m, "\n DMA viloation: echo %x [host_id] [ops]> msdc_debug\n",
  1537. SD_TOOL_DMA_STATUS);
  1538. seq_printf(m,
  1539. " [ops] 0:get latest dma address, 1:start violation test\n");
  1540. seq_printf(m,
  1541. "\n SET Slew Rate: echo %x [host_id] [clk] [cmd] [dat] [rst] [ds]> msdc_debug\n",
  1542. SD_TOOL_ENABLE_SLEW_RATE);
  1543. seq_puts(m, "\n TD/RD SEL:\n");
  1544. seq_printf(m, " set rdsel: echo %x [host_id] 0 [value] > msdc_debug\n",
  1545. SD_TOOL_SET_RDTDSEL);
  1546. seq_printf(m, " set tdsel: echo %x [host_id] 1 [value] > msdc_debug\n",
  1547. SD_TOOL_SET_RDTDSEL);
  1548. seq_printf(m, " get tdsel/rdsel: echo %x [host_id] 2 > msdc_debug\n",
  1549. SD_TOOL_SET_RDTDSEL);
  1550. seq_printf(m,
  1551. " [value] rdsel: 0x0<<4 ~ 0x3f<<4, tdsel: 0x0~0xf\n");
  1552. seq_printf(m, "\n EMMC/SD RW test: echo %x [host_id] [mode] > msdc_debug\n",
  1553. MSDC_READ_WRITE);
  1554. seq_puts(m, " [mode] mode 0:stop, 1:read, 2:write\n");
  1555. seq_printf(m,
  1556. "\n Error tune debug: echo %x [host_id] [cmd_id] [arg] [error_type] [count] > msdc_debug\n",
  1557. MMC_ERROR_TUNE);
  1558. seq_puts(m, " [cmd_id] 0: CMD0, 1: CMD1, 2: CMD2......\n");
  1559. seq_puts(m, " [arg] for CMD6, arg means ext_csd index......\n");
  1560. seq_printf(m,
  1561. " [error] 0: disable error tune debug, 1: cmd timeout, 2: cmd crc, 4: dat timeout, 8: dat crc, 16: acmd timeout, 32: acmd crc\n");
  1562. seq_puts(m, " [count] error count\n");
  1563. seq_printf(m, "\n eMMC Cache Control: echo %x [host_id] [action_id] > /proc/msdc_debug\n",
  1564. MMC_EDC_EMMC_CACHE);
  1565. seq_printf(m,
  1566. " [action_id] 0:Disable cache 1:Enable cache 2:check cache status\n");
  1567. seq_printf(m, "\n eMMC Dump GPD/BD: echo %x [host_id] > /proc/msdc_debug\n",
  1568. MMC_DUMP_GPD);
  1569. seq_printf(m,
  1570. "\n eMMC ETT Tune: echo %x [type] [start_voltage], [end_voltage] > /proc/msdc_debug\n",
  1571. MMC_ETT_TUNE);
  1572. seq_printf(m,
  1573. " [type] 0:tune cmd 1:tune read 2:tune write 3:tune HS400\n");
  1574. seq_puts(m, " [start_voltage] ?mV\n");
  1575. seq_printf(m,
  1576. " [end_voltage] ?mV, we try ETT from bigger voltage to lower voltage\n");
  1577. seq_printf(m, "\n CRC Stress Test: echo %x [action_id]> /proc/msdc_debug\n",
  1578. MMC_CRC_STRESS);
  1579. seq_puts(m, " [action_id] 0:disable 1:enable\n");
  1580. seq_printf(m,
  1581. "\n Enable AXI Modules: echo %x [action_id][module_id]> /proc/msdc_debug\n",
  1582. ENABLE_AXI_MODULE);
  1583. seq_puts(m, " [action_id] 0:disable 1:enable\n");
  1584. seq_printf(m,
  1585. " [module_id] 0:NFI 1:MSDC1 2:USB 3:PERI 4:AUDIO 5:ALL\n");
  1586. seq_puts(m, "\n NOTE: All input data is Hex number!\n");
  1587. seq_puts(m, "\n======================================================\n\n");
  1588. return 0;
  1589. }
  1590. void msdc_hw_parameter_debug(struct msdc_hw *hw, struct seq_file *m, void *v)
  1591. {
  1592. unsigned int i;
  1593. seq_printf(m, "hw->clk_src = %x\n", hw->clk_src);
  1594. seq_printf(m, "hw->cmd_edge = %x\n", hw->cmd_edge);
  1595. seq_printf(m, "hw->rdata_edge = %x\n", hw->rdata_edge);
  1596. seq_printf(m, "hw->wdata_edge = %x\n", hw->wdata_edge);
  1597. seq_printf(m, "hw->clk_drv = %x\n", hw->clk_drv);
  1598. seq_printf(m, "hw->cmd_drv = %x\n", hw->cmd_drv);
  1599. seq_printf(m, "hw->dat_drv = %x\n", hw->dat_drv);
  1600. seq_printf(m, "hw->rst_drv = %x\n", hw->rst_drv);
  1601. seq_printf(m, "hw->ds_drv = %x\n", hw->ds_drv);
  1602. seq_printf(m, "hw->data_pins = %x\n", (unsigned int)hw->data_pins);
  1603. seq_printf(m, "hw->data_offset = %x\n", (unsigned int)hw->data_offset);
  1604. seq_printf(m, "hw->flags = %x\n", (unsigned int)hw->flags);
  1605. seq_printf(m, "hw->dat0rddly = %x\n", hw->dat0rddly);
  1606. seq_printf(m, "hw->dat1rddly = %x\n", hw->dat1rddly);
  1607. seq_printf(m, "hw->dat2rddly = %x\n", hw->dat2rddly);
  1608. seq_printf(m, "hw->dat3rddly = %x\n", hw->dat3rddly);
  1609. seq_printf(m, "hw->dat4rddly = %x\n", hw->dat4rddly);
  1610. seq_printf(m, "hw->dat5rddly = %x\n", hw->dat5rddly);
  1611. seq_printf(m, "hw->dat6rddly = %x\n", hw->dat6rddly);
  1612. seq_printf(m, "hw->dat7rddly = %x\n", hw->dat7rddly);
  1613. seq_printf(m, "hw->datwrddly = %x\n", hw->datwrddly);
  1614. seq_printf(m, "hw->cmdrrddly = %x\n", hw->cmdrrddly);
  1615. seq_printf(m, "hw->cmdrddly = %x\n", hw->cmdrddly);
  1616. seq_printf(m, "hw->ett_hs200_count = %x\n", hw->ett_hs200_count);
  1617. seq_printf(m, "hw->ett_hs400_count = %x\n", hw->ett_hs400_count);
  1618. seq_printf(m, "hw->host_function = %x\n", (unsigned int)hw->host_function);
  1619. seq_printf(m, "hw->boot = %x\n", hw->boot);
  1620. for (i = 0; i < hw->ett_hs200_count; i++) {
  1621. seq_printf(m, "msdc0_ett_hs200_settings[%d]: %x, %x, %x\n", i,
  1622. hw->ett_hs200_settings[i].reg_addr,
  1623. hw->ett_hs200_settings[i].reg_offset, hw->ett_hs200_settings[i].value);
  1624. }
  1625. for (i = 0; i < hw->ett_hs400_count; i++) {
  1626. seq_printf(m, "msdc0_ett_hs400_settings[%d]: %x, %x, %x\n", i,
  1627. hw->ett_hs400_settings[i].reg_addr,
  1628. hw->ett_hs400_settings[i].reg_offset, hw->ett_hs400_settings[i].value);
  1629. }
  1630. }
  1631. /* ========== driver proc interface =========== */
  1632. static int msdc_debug_proc_show(struct seq_file *m, void *v)
  1633. {
  1634. seq_puts(m, "\n=========================================\n");
  1635. seq_puts(m, "Index<0> + Id + Zone\n");
  1636. seq_printf(m,
  1637. "-> PWR<9> WRN<8> | FIO<7> OPS<6> FUN<5> CFG<4> | INT<3> RSP<2> CMD<1> DMA<0>\n");
  1638. seq_puts(m, "-> echo 0 3 0x3ff >msdc_bebug -> host[3] debug zone set to 0x3ff\n");
  1639. seq_printf(m, "-> MSDC[0] Zone: 0x%.8x\n", sd_debug_zone[0]);
  1640. seq_printf(m, "-> MSDC[1] Zone: 0x%.8x\n", sd_debug_zone[1]);
  1641. seq_printf(m, "-> MSDC[2] Zone: 0x%.8x\n", sd_debug_zone[2]);
  1642. seq_printf(m, "-> MSDC[3] Zone: 0x%.8x\n", sd_debug_zone[3]);
  1643. seq_puts(m, "Index<1> + ID:4|Mode:4 + DMA_SIZE\n");
  1644. seq_puts(m, "-> 0)PIO 1)DMA 2)SIZE\n");
  1645. seq_puts(m, "-> echo 1 22 0x200 >msdc_bebug -> host[2] size mode, dma when >= 512\n");
  1646. seq_printf(m, "-> MSDC[0] mode<%d> size<%d>\n", drv_mode[0], dma_size[0]);
  1647. seq_printf(m, "-> MSDC[1] mode<%d> size<%d>\n", drv_mode[1], dma_size[1]);
  1648. seq_printf(m, "-> MSDC[2] mode<%d> size<%d>\n", drv_mode[2], dma_size[2]);
  1649. seq_printf(m, "-> MSDC[3] mode<%d> size<%d>\n", drv_mode[3], dma_size[3]);
  1650. seq_puts(m, "Index<3> + SDIO_PROFILE + TIME\n");
  1651. seq_puts(m, "-> echo 3 1 0x1E >msdc_bebug -> enable sdio_profile, 30s\n");
  1652. seq_printf(m, "-> SDIO_PROFILE<%d> TIME<%llu s>\n", sdio_pro_enable, sdio_pro_time);
  1653. seq_printf(m, "-> Clokc SRC selection Host[0]<%d>\n", msdc_clock_src[0]);
  1654. seq_printf(m, "-> Clokc SRC selection Host[1]<%d>\n", msdc_clock_src[1]);
  1655. seq_printf(m, "-> Clokc SRC selection Host[2]<%d>\n", msdc_clock_src[2]);
  1656. seq_printf(m, "-> Clokc SRC selection Host[3]<%d>\n", msdc_clock_src[3]);
  1657. seq_puts(m, "=========================================\n\n");
  1658. if (mtk_msdc_host[0]) {
  1659. seq_puts(m, "Index<4> msdc0 hw parameter and ett settings:\n");
  1660. msdc_hw_parameter_debug(mtk_msdc_host[0]->hw, m, v);
  1661. }
  1662. if (mtk_msdc_host[1]) {
  1663. seq_puts(m, "Index<5> msdc1 hw parameter:\n");
  1664. msdc_hw_parameter_debug(mtk_msdc_host[1]->hw, m, v);
  1665. }
  1666. return 0;
  1667. }
  1668. /*
  1669. *data: bit0~4:id, bit4~7: mode
  1670. */
  1671. static int rwThread(void *data)
  1672. {
  1673. int error = 0, i = 0;
  1674. ulong p = (ulong) data;
  1675. int id = p & 0x3;
  1676. int mode = (p >> 4) & 0x3;
  1677. pr_err("[****SD_rwThread****]id=%d, mode=%d.\n", id, mode);
  1678. while (read_write_state != 0) {
  1679. if (read_write_state == 1)
  1680. p = 0x3;
  1681. else if (read_write_state == 2)
  1682. p = 0;
  1683. #ifdef CONFIG_MTK_EMMC_SUPPORT
  1684. if (id == 0) {
  1685. if (mode == 1)
  1686. error = emmc_multi_rw_compare_slave(id, 1, COMPARE_ADDRESS_MMC);
  1687. else if (mode == 2)
  1688. error = emmc_multi_rw_compare_slave(id, 0, COMPARE_ADDRESS_MMC);
  1689. if (error) {
  1690. pr_err("[%s]: failed data id0, error=%d\n", __func__, error);
  1691. break;
  1692. }
  1693. } else
  1694. #endif
  1695. if (id < HOST_MAX_NUM) {
  1696. if (mode == 1)
  1697. error = sd_multi_rw_compare_slave(id, 1, COMPARE_ADDRESS_SD);
  1698. else if (mode == 2)
  1699. error = sd_multi_rw_compare_slave(id, 0, COMPARE_ADDRESS_SD);
  1700. if (error) {
  1701. pr_err("[%s]: failed data id1, error=%d\n", __func__, error);
  1702. break;
  1703. }
  1704. }
  1705. i++;
  1706. if (i == 10000) {
  1707. pr_err("[***rwThread %s***]", read_write_state == 1 ? "read" : "write");
  1708. i = 0;
  1709. }
  1710. }
  1711. pr_err("[****SD_Debug****]rwThread exit.\n");
  1712. return 0;
  1713. }
  1714. static int msdc_check_emmc_cache_status(struct msdc_host *host)
  1715. {
  1716. BUG_ON(!host);
  1717. BUG_ON(!host->mmc);
  1718. BUG_ON(!host->mmc->card);
  1719. if (!mmc_card_mmc(host->mmc->card)) {
  1720. pr_err("msdc%d: is not a eMMC card\n", host->id);
  1721. return -1;
  1722. }
  1723. if (0 == host->mmc->card->ext_csd.cache_size) {
  1724. pr_err("msdc%d:card don't support cache feature\n", host->id);
  1725. return -1;
  1726. }
  1727. pr_err("msdc%d: Current eMMC Cache status: %s, Cache size:%dKB\n", host->id,
  1728. host->mmc->card->ext_csd.cache_ctrl ? "Enable" : "Disable",
  1729. host->mmc->card->ext_csd.cache_size/8);
  1730. return host->mmc->card->ext_csd.cache_ctrl;
  1731. }
  1732. static int msdc_enable_emmc_cache(struct msdc_host *host, int enable)
  1733. {
  1734. int err;
  1735. u8 c_ctrl;
  1736. err = msdc_check_emmc_cache_status(host);
  1737. if (err < 0)
  1738. goto out;
  1739. mmc_get_card(host->mmc->card);
  1740. c_ctrl = host->mmc->card->ext_csd.cache_ctrl;
  1741. if (c_ctrl == enable)
  1742. pr_err("msdc%d:cache has already been %s state,\n", host->id,
  1743. enable ? "enable" : "disable");
  1744. else {
  1745. err = msdc_cache_ctrl(host, enable, NULL);
  1746. if (err)
  1747. pr_err("msdc%d: Cache is supported, but %s failed\n", host->id,
  1748. enable ? "enable" : "disable");
  1749. else
  1750. pr_err("msdc%d: %s cache successfully\n", host->id,
  1751. enable ? "enable" : "disable");
  1752. }
  1753. out:
  1754. mmc_put_card(host->mmc->card);
  1755. return err;
  1756. }
  1757. static ssize_t msdc_debug_proc_write(struct file *file, const char *buf, size_t count,
  1758. loff_t *data)
  1759. {
  1760. int ret = 0;
  1761. int cmd, p1, p2, p3, p4, p5, p6, p7 = 0;
  1762. int id, zone;
  1763. int mode, size;
  1764. int thread_num, compare_count, multi_address;
  1765. void __iomem *base = NULL;
  1766. ulong data_for_wr;
  1767. unsigned int offset = 0;
  1768. unsigned int reg_value;
  1769. HOST_CAPS_SPEED_MODE spd_mode = CAPS_SPEED_NULL;
  1770. HOST_CAPS_DRIVE_TYPE drv_type = CAPS_DRIVE_NULL;
  1771. HOST_CAPS_MAX_CURRENT current_limit = CAPS_CURRENT_NULL;
  1772. HOST_CAPS_POWER_CONTROL pw_cr = CAPS_POWER_NULL;
  1773. struct msdc_host *host = NULL;
  1774. #ifdef MSDC_DMA_ADDR_DEBUG
  1775. struct dma_addr *dma_address, *p_dma_address;
  1776. #endif
  1777. int dma_status;
  1778. struct task_struct *rw_thread = NULL;
  1779. int sscanf_num;
  1780. if (count == 0)
  1781. return -1;
  1782. if (count > 255)
  1783. count = 255;
  1784. ret = copy_from_user(cmd_buf, buf, count);
  1785. if (ret < 0)
  1786. return -1;
  1787. cmd_buf[count] = '\0';
  1788. pr_err("[****SD_Debug****]msdc Write %s\n", cmd_buf);
  1789. sscanf_num = sscanf(cmd_buf, "%x %x %x %x %x %x %x %x", &cmd, &p1, &p2, &p3, &p4, &p5, &p6, &p7);
  1790. if (sscanf_num < 1)
  1791. return count;
  1792. if (cmd == SD_TOOL_ZONE) {
  1793. id = p1;
  1794. zone = p2; /* zone &= 0x3ff; */
  1795. pr_err("[****SD_Debug****]msdc host_id<%d> zone<0x%.8x>\n", id, zone);
  1796. if (id >= 0 && id <= HOST_MAX_NUM - 1) {
  1797. sd_debug_zone[id] = zone;
  1798. } else if (id == HOST_MAX_NUM) {
  1799. sd_debug_zone[0] = sd_debug_zone[1] = zone;
  1800. sd_debug_zone[2] = zone;
  1801. sd_debug_zone[3] = zone;
  1802. } else {
  1803. pr_err("[****SD_Debug****]msdc host_id error when set debug zone\n");
  1804. }
  1805. } else if (cmd == SD_TOOL_DMA_SIZE) {
  1806. id = p2;
  1807. mode = p3;
  1808. size = p4;
  1809. if (id >= 0 && id <= HOST_MAX_NUM - 1) {
  1810. if (p1 == 0) {
  1811. drv_mode[id] = mode;
  1812. dma_size[id] = size;
  1813. } else {
  1814. pr_err("-> MSDC[%d] mode<%d> size<%d>\n",
  1815. id, drv_mode[id], dma_size[id]);
  1816. }
  1817. } else {
  1818. pr_err("[****SD_Debug****]msdc host_id error when select mode\n");
  1819. }
  1820. } else if (cmd == SD_TOOL_SDIO_PROFILE) {
  1821. if (p1 == 1) { /* enable profile */
  1822. if (gpt_enable == 0) {
  1823. msdc_init_gpt();
  1824. gpt_enable = 1;
  1825. }
  1826. sdio_pro_enable = 1;
  1827. if (p2 == 0)
  1828. p2 = 1;
  1829. if (p2 >= 30)
  1830. p2 = 30;
  1831. sdio_pro_time = p2;
  1832. } else if (p1 == 0) {
  1833. /* todo */
  1834. sdio_pro_enable = 0;
  1835. }
  1836. } else if (cmd == SD_TOOL_CLK_SRC_SELECT) {
  1837. id = p2;
  1838. if (id >= 0 && id < HOST_MAX_NUM) {
  1839. if (p1 == 0) {
  1840. if (p3 >= 0 && p3 < CLK_SRC_MAX_NUM) {
  1841. msdc_clock_src[id] = p3;
  1842. pr_err
  1843. ("[****SD_Debug****]msdc%d's clk source changed to %d\n",
  1844. id, msdc_clock_src[id]);
  1845. pr_err
  1846. ("[****SD_Debug****]to enable settings, suspend&resume again\n");
  1847. } else {
  1848. pr_err
  1849. ("[****SD_Debug****] invalid clock src id:%d, check /proc/msdc_help\n",
  1850. p3);
  1851. }
  1852. } else if (p1 == 1) {
  1853. switch (id) {
  1854. case 0:
  1855. pr_err("[****SD_Debug****]msdc%d's pll source is %d\n",
  1856. id, msdc_clock_src[id]);
  1857. break;
  1858. case 1:
  1859. pr_err("[****SD_Debug****]msdc%d's pll source is %d\n",
  1860. id, msdc_clock_src[id]);
  1861. break;
  1862. case 2:
  1863. pr_err("[****SD_Debug****]msdc%d's pll source is %d\n",
  1864. id, msdc_clock_src[id]);
  1865. break;
  1866. case 3:
  1867. pr_err("[****SD_Debug****]msdc%d's pll source is %d\n",
  1868. id, msdc_clock_src[id]);
  1869. break;
  1870. }
  1871. }
  1872. } else
  1873. pr_err("[****SD_Debug****]msdc host_id error when select clock source\n");
  1874. } else if (cmd == SD_TOOL_REG_ACCESS) {
  1875. id = p2;
  1876. offset = (unsigned int)p3;
  1877. if (id >= HOST_MAX_NUM || id < 0)
  1878. pr_err("[****SD_Debug****]msdc host_id error when modify msdc reg\n");
  1879. else {
  1880. if (id == 0 && mtk_msdc_host[0])
  1881. base = mtk_msdc_host[0]->base;
  1882. if (id == 1 && mtk_msdc_host[1])
  1883. base = mtk_msdc_host[1]->base;
  1884. if (id == 2 && mtk_msdc_host[2])
  1885. base = mtk_msdc_host[2]->base;
  1886. if (id == 3 && mtk_msdc_host[3])
  1887. base = mtk_msdc_host[3]->base;
  1888. host = mtk_msdc_host[id];
  1889. if ((offset == 0x18 || offset == 0x1C) && p1 != 4) {
  1890. pr_err
  1891. ("[****SD_Debug****]Err: Accessing TXDATA and RXDATA is forbidden\n");
  1892. return count;
  1893. }
  1894. #ifndef FPGA_PLATFORM
  1895. #ifdef CONFIG_MTK_CLKMGR
  1896. enable_clock(MT_CG_PERI_MSDC30_0 + id, "SD");
  1897. #else
  1898. clk_enable(host->clock_control);
  1899. #endif
  1900. #endif
  1901. if (p1 == 0) {
  1902. reg_value = p4;
  1903. if (offset == 0xE0 || offset == 0xE4 || offset == 0xE8) {
  1904. pr_err("[****SD_Debug****]Err: Bypass PAD_CTL\n");
  1905. } else {
  1906. pr_err
  1907. ("[****SD_Debug****][MSDC Reg]Original:0x%p+0x%x (0x%x)\n",
  1908. base, offset, sdr_read32(base + offset));
  1909. sdr_write32(base + offset, reg_value);
  1910. pr_err
  1911. ("[****SD_Debug****][MSDC Reg]Modified:0x%p+0x%x (0x%x)\n",
  1912. base, offset, sdr_read32(base + offset));
  1913. }
  1914. } else if (p1 == 1) {
  1915. if (offset == 0xE0 || offset == 0xE4 || offset == 0xE8)
  1916. pr_err("[****SD_Debug****]Err: Bypass PAD_CTL\n");
  1917. else
  1918. pr_err
  1919. ("[****SD_Debug****][MSDC Reg]Reg:0x%p+0x%x (0x%x)\n",
  1920. base, offset, sdr_read32(base + offset));
  1921. } else if (p1 == 2) {
  1922. if (offset == 0xE0 || offset == 0xE4 || offset == 0xE8)
  1923. pr_err("[****SD_Debug****]Err: Bypass PAD_CTL\n");
  1924. else
  1925. msdc_set_field(base + offset, p4, p5, p6);
  1926. } else if (p1 == 3) {
  1927. if (offset == 0xE0 || offset == 0xE4 || offset == 0xE8)
  1928. pr_err("[****SD_Debug****]Err: Bypass PAD_CTL\n");
  1929. else
  1930. msdc_get_field(base + offset, p4, p5, p6);
  1931. } else if (p1 == 4) {
  1932. msdc_dump_info(host->id);
  1933. } else if (p1 == 5) {
  1934. msdc_dump_info(host->id);
  1935. }
  1936. #ifndef FPGA_PLATFORM
  1937. #ifdef CONFIG_MTK_CLKMGR
  1938. disable_clock(MT_CG_PERI_MSDC30_0 + id, "SD");
  1939. #else
  1940. clk_disable(host->clock_control);
  1941. #endif
  1942. #endif
  1943. }
  1944. } else if (cmd == SD_TOOL_SET_DRIVING) {
  1945. id = p1;
  1946. if (id >= HOST_MAX_NUM || id < 0)
  1947. pr_err("[****SD_Debug****]msdc host_id error when modify msdc driving\n");
  1948. else {
  1949. host = mtk_msdc_host[id];
  1950. if ((unsigned char)p2 > 7 || (unsigned char)p3 > 7 || (unsigned char)p4 > 7
  1951. || (unsigned char)p5 > 7 || (unsigned char)p6 > 7)
  1952. pr_err
  1953. ("[****SD_Debug****]Some drving value was not right(correct:0~7)\n");
  1954. else {
  1955. #ifndef FPGA_PLATFORM
  1956. if (p7 == 0x33) {
  1957. host->hw->clk_drv = (unsigned char)p2;
  1958. host->hw->cmd_drv = (unsigned char)p3;
  1959. host->hw->dat_drv = (unsigned char)p4;
  1960. host->hw->rst_drv = (unsigned char)p5;
  1961. host->hw->ds_drv = (unsigned char)p6;
  1962. msdc_set_driving(host, host->hw, 0);
  1963. } else if (p7 == 0x18) {
  1964. host->hw->clk_drv_sd_18 = (unsigned char)p2;
  1965. host->hw->cmd_drv_sd_18 = (unsigned char)p3;
  1966. host->hw->dat_drv_sd_18 = (unsigned char)p4;
  1967. msdc_set_driving(host, host->hw, 1);
  1968. }
  1969. #endif
  1970. pr_err
  1971. ("[****SD_Debug****]clk_drv=%d, cmd_drv=%d, dat_drv=%d, rst_drv=%d, ds_drv=%d\n",
  1972. p2, p3, p4, p5, p6);
  1973. }
  1974. }
  1975. } else if (cmd == SD_TOOL_ENABLE_SLEW_RATE) {
  1976. id = p1;
  1977. if (id >= HOST_MAX_NUM || id < 0)
  1978. pr_err("[****SD_Debug****]invalid host id: %d\n", id);
  1979. else {
  1980. host = mtk_msdc_host[id];
  1981. if ((unsigned char)p2 > 1 || (unsigned char)p3 > 1
  1982. || (unsigned char)p4 > 1 || (unsigned char)p5 > 1
  1983. || (unsigned char)p6 > 1)
  1984. pr_err
  1985. ("[****SD_Debug****]Some sr value was not right(correct:0(disable),1(enable))\n");
  1986. else {
  1987. #ifndef FPGA_PLATFORM
  1988. msdc_set_sr(host, p2, p3, p4, p5, p6);
  1989. #endif
  1990. pr_err
  1991. ("[****SD_Debug****]msdc%d, clk_sr=%d, cmd_sr=%d, dat_sr=%d, rst_sr=%d, ds_sr=%d\n",
  1992. id, p2, p3, p4, p5, p6);
  1993. }
  1994. }
  1995. } else if (cmd == SD_TOOL_SET_RDTDSEL) {
  1996. id = p1;
  1997. if (id >= HOST_MAX_NUM || id < 0)
  1998. pr_err("[****SD_Debug****]msdc host_id error when modify msdc sr\n");
  1999. else {
  2000. host = mtk_msdc_host[id];
  2001. if ((p2 < 0) || (p2 > 2))
  2002. pr_err
  2003. ("[****SD_Debug****]invalid option ( set rd:0, set td:1, get td/rd: 2)\n");
  2004. else if ((p2 == 0 && (unsigned char)p3 > 0x3F)
  2005. || (p2 == 1 && (unsigned char)p3 > 0xF))
  2006. pr_err
  2007. ("[****SD_Debug****]rd/td value was not right\n");
  2008. else {
  2009. #ifndef FPGA_PLATFORM
  2010. if (p2 == 0) {
  2011. msdc_set_rdtdsel_dbg(host, 1, p3);
  2012. pr_err("[****SD_Debug****]msdc%d, set rd=%d\n", id, p3);
  2013. } else if (p2 == 1) { /* set td:1 */
  2014. msdc_set_rdtdsel_dbg(host, 0, p3);
  2015. pr_err("[****SD_Debug****]msdc%d, set td=%d\n", id, p3);
  2016. } else if (p2 == 2) { /* get td/rd:2 */
  2017. msdc_get_rdtdsel_dbg(host, 1, &p3); /* get rd */
  2018. msdc_get_rdtdsel_dbg(host, 0, &p4); /* get td */
  2019. pr_err("[****SD_Debug****]msdc%d, rd : 0x%x, td : 0x%x\n",
  2020. id, p3, p4);
  2021. }
  2022. #endif
  2023. }
  2024. }
  2025. } else if (cmd == SD_TOOL_ENABLE_SMT) {
  2026. id = p1;
  2027. if (id >= HOST_MAX_NUM || id < 0)
  2028. pr_err
  2029. ("[****SD_Debug****]msdc host_id error when enable/disable msdc smt\n");
  2030. else {
  2031. host = mtk_msdc_host[id];
  2032. #ifndef FPGA_PLATFORM
  2033. msdc_set_smt(host, p2);
  2034. #endif
  2035. pr_err("[****SD_Debug****]smt=%d\n", p2);
  2036. }
  2037. } else if (cmd == SD_TOOL_DESENSE) {
  2038. if (p1 == 0)
  2039. reg_value = p2;
  2040. } else if (cmd == RW_BIT_BY_BIT_COMPARE) {
  2041. id = p1;
  2042. compare_count = p2;
  2043. if (id >= HOST_MAX_NUM || id < 0) {
  2044. pr_err("[****SD_Debug****]: bad host id: %d\n", id);
  2045. return count;
  2046. }
  2047. if (compare_count < 0) {
  2048. pr_err("[****SD_Debug****]: bad compare count: %d\n", compare_count);
  2049. return count;
  2050. }
  2051. if (id == 0) { /* for msdc0 */
  2052. #ifdef CONFIG_MTK_EMMC_SUPPORT
  2053. emmc_multi_rw_compare(0, COMPARE_ADDRESS_MMC, compare_count);
  2054. #else
  2055. sd_multi_rw_compare(0, COMPARE_ADDRESS_SD, compare_count);
  2056. #endif
  2057. } else {
  2058. sd_multi_rw_compare(id, COMPARE_ADDRESS_SD, compare_count);
  2059. }
  2060. } else if (cmd == MSDC_READ_WRITE) {
  2061. id = p1;
  2062. mode = p2; /* 0:stop, 1:read, 2:write */
  2063. if (id >= HOST_MAX_NUM || id < 0 || mode > 2 || mode < 0) {
  2064. pr_err("[****SD_Debug****]: bad host id: %d, mode: %d\n", id, mode);
  2065. return count;
  2066. }
  2067. if (mode == read_write_state) {
  2068. pr_err("[****SD_Debug****]: same operation mode=%d.\n", read_write_state);
  2069. return count;
  2070. }
  2071. if (mode == 1 && read_write_state == 2) {
  2072. pr_err
  2073. ("[****SD_Debug****]: cannot read in write state, please stop first.\n");
  2074. return count;
  2075. }
  2076. if (mode == 2 && read_write_state == 1) {
  2077. pr_err
  2078. ("[****SD_Debug****]: cannot write in read state, please stop first.\n");
  2079. return count;
  2080. }
  2081. read_write_state = mode;
  2082. pr_err("[****SD_Debug****]: host id: %d, mode: %d.\n", id, mode);
  2083. if (mode == 0) {
  2084. if (rw_thread) {
  2085. kthread_stop(rw_thread);
  2086. pr_err("[****SD_Debug****]: stop read/write thread.\n");
  2087. }
  2088. } else {
  2089. pr_err("[****SD_Debug****]: start read/write thread.\n");
  2090. data_for_wr = (id & 0x3) | ((mode & 0x3) << 4);
  2091. rw_thread = kthread_create(rwThread, (void *)data_for_wr, "msdc_rw_thread");
  2092. wake_up_process(rw_thread);
  2093. }
  2094. } else if (cmd == SMP_TEST_ON_ONE_HOST) {
  2095. id = p1;
  2096. thread_num = p2;
  2097. compare_count = p3;
  2098. multi_address = p4;
  2099. if (id >= HOST_MAX_NUM || id < 0) {
  2100. pr_err(" bad host id: %d\n", id);
  2101. return -1;
  2102. }
  2103. if (thread_num > MAX_THREAD_NUM_FOR_SMP) { /* && (multi_address != 0)) */
  2104. pr_err(" too much thread for SMP test, thread_num=%d\n", thread_num);
  2105. return -1;
  2106. }
  2107. if (compare_count < 0) {
  2108. pr_err("illegal compare count!\n");
  2109. return -1;
  2110. }
  2111. if (multi_address < 0) {
  2112. pr_err("illegal test address!\n");
  2113. return -1;
  2114. }
  2115. smp_test_on_one_host(thread_num, id, compare_count, multi_address);
  2116. } else if (cmd == SMP_TEST_ON_ALL_HOST) {
  2117. thread_num = p1;
  2118. compare_count = p2;
  2119. multi_address = p3;
  2120. smp_test_on_all_host(thread_num, compare_count, multi_address);
  2121. } else if (cmd == SD_TOOL_MSDC_HOST_MODE) {
  2122. id = p2;
  2123. if (id >= HOST_MAX_NUM || id < 0)
  2124. pr_err("[****SD_Debug****]msdc host_id error when modify msdc host mode\n");
  2125. else {
  2126. if (p1 == 0) {
  2127. if (p3 <= UHS_DDR50 && p3 >= SDHC_HIGHSPEED)
  2128. spd_mode = p3;
  2129. if (p4 <= DRIVER_TYPE_D && p4 >= DRIVER_TYPE_A)
  2130. drv_type = p4;
  2131. if (p5 <= MAX_CURRENT_800 && p5 >= MAX_CURRENT_200)
  2132. current_limit = p5;
  2133. if (p6 <= SDXC_POWER_CONTROL && p6 >= SDXC_NO_POWER_CONTROL)
  2134. pw_cr = p6;
  2135. if (spd_mode != CAPS_SPEED_NULL) {
  2136. switch (spd_mode) {
  2137. case SDHC_HIGHSPEED:
  2138. msdc_host_mode[id] |=
  2139. MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED;
  2140. msdc_host_mode[id] &=
  2141. (~MMC_CAP_UHS_SDR12) & (~MMC_CAP_UHS_SDR25) &
  2142. (~MMC_CAP_UHS_SDR50) & (~MMC_CAP_UHS_DDR50) &
  2143. (~MMC_CAP_1_8V_DDR) & (~MMC_CAP_UHS_SDR104);
  2144. msdc_host_mode2[id] &=
  2145. (~MMC_CAP2_HS200_1_8V_SDR) &
  2146. (~MMC_CAP2_HS400_1_8V);
  2147. pr_err
  2148. ("[****SD_Debug****]host will support Highspeed\n");
  2149. break;
  2150. case UHS_SDR12:
  2151. msdc_host_mode[id] |= MMC_CAP_UHS_SDR12;
  2152. msdc_host_mode[id] &=
  2153. (~MMC_CAP_UHS_SDR25) & (~MMC_CAP_UHS_SDR50) &
  2154. (~MMC_CAP_UHS_DDR50) & (~MMC_CAP_1_8V_DDR) &
  2155. (~MMC_CAP_UHS_SDR104);
  2156. msdc_host_mode2[id] &=
  2157. (~MMC_CAP2_HS200_1_8V_SDR) &
  2158. (~MMC_CAP2_HS400_1_8V);
  2159. pr_err
  2160. ("[****SD_Debug****]host will support UHS-SDR12\n");
  2161. break;
  2162. case UHS_SDR25:
  2163. msdc_host_mode[id] |=
  2164. MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25;
  2165. msdc_host_mode[id] &=
  2166. (~MMC_CAP_UHS_SDR50) & (~MMC_CAP_UHS_DDR50) &
  2167. (~MMC_CAP_1_8V_DDR) & (~MMC_CAP_UHS_SDR104);
  2168. msdc_host_mode2[id] &=
  2169. (~MMC_CAP2_HS200_1_8V_SDR) &
  2170. (~MMC_CAP2_HS400_1_8V);
  2171. pr_err
  2172. ("[****SD_Debug****]host will support UHS-SDR25\n");
  2173. break;
  2174. case UHS_SDR50:
  2175. msdc_host_mode[id] |=
  2176. MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
  2177. MMC_CAP_UHS_SDR50;
  2178. msdc_host_mode[id] &=
  2179. (~MMC_CAP_UHS_DDR50) & (~MMC_CAP_1_8V_DDR) &
  2180. (~MMC_CAP_UHS_SDR104);
  2181. msdc_host_mode2[id] &=
  2182. (~MMC_CAP2_HS200_1_8V_SDR) &
  2183. (~MMC_CAP2_HS400_1_8V);
  2184. pr_err
  2185. ("[****SD_Debug****]host will support UHS-SDR50\n");
  2186. break;
  2187. case UHS_SDR104:
  2188. msdc_host_mode[id] |=
  2189. MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
  2190. MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104;
  2191. msdc_host_mode2[id] |= MMC_CAP2_HS200_1_8V_SDR;
  2192. msdc_host_mode2[id] &= (~MMC_CAP2_HS400_1_8V);
  2193. pr_err
  2194. ("[****SD_Debug****]host will support UHS-SDR104\n");
  2195. break;
  2196. case UHS_DDR50:
  2197. msdc_host_mode[id] |=
  2198. MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
  2199. MMC_CAP_UHS_DDR50 | MMC_CAP_1_8V_DDR;
  2200. pr_err
  2201. ("[****SD_Debug****]host will support UHS-DDR50\n");
  2202. break;
  2203. case EMMC_HS400:
  2204. msdc_host_mode[id] |=
  2205. MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
  2206. MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_DDR50 |
  2207. MMC_CAP_1_8V_DDR | MMC_CAP_UHS_SDR104;
  2208. msdc_host_mode2[id] |=
  2209. MMC_CAP2_HS200_1_8V_SDR | MMC_CAP2_HS400_1_8V;
  2210. pr_err
  2211. ("[****SD_Debug****]host will support EMMC_HS400\n");
  2212. break;
  2213. default:
  2214. pr_err("[****SD_Debug****]invalid sd30_mode:%d\n",
  2215. spd_mode);
  2216. break;
  2217. }
  2218. }
  2219. if (drv_type != CAPS_DRIVE_NULL) {
  2220. switch (drv_type) {
  2221. case DRIVER_TYPE_A:
  2222. msdc_host_mode[id] |= MMC_CAP_DRIVER_TYPE_A;
  2223. msdc_host_mode[id] &=
  2224. (~MMC_CAP_DRIVER_TYPE_C) &
  2225. (~MMC_CAP_DRIVER_TYPE_D);
  2226. pr_err
  2227. ("[****SD_Debug****]host will support DRIVING TYPE A\n");
  2228. break;
  2229. case DRIVER_TYPE_B:
  2230. msdc_host_mode[id] &=
  2231. (~MMC_CAP_DRIVER_TYPE_A) &
  2232. (~MMC_CAP_DRIVER_TYPE_C) &
  2233. (~MMC_CAP_DRIVER_TYPE_D);
  2234. pr_err
  2235. ("[****SD_Debug****]host will support DRIVING TYPE B\n");
  2236. break;
  2237. case DRIVER_TYPE_C:
  2238. msdc_host_mode[id] |= MMC_CAP_DRIVER_TYPE_C;
  2239. msdc_host_mode[id] &=
  2240. (~MMC_CAP_DRIVER_TYPE_A) &
  2241. (~MMC_CAP_DRIVER_TYPE_D);
  2242. pr_err
  2243. ("[****SD_Debug****]host will support DRIVING TYPE C\n");
  2244. break;
  2245. case DRIVER_TYPE_D:
  2246. msdc_host_mode[id] |= MMC_CAP_DRIVER_TYPE_D;
  2247. msdc_host_mode[id] &=
  2248. (~MMC_CAP_DRIVER_TYPE_A) &
  2249. (~MMC_CAP_DRIVER_TYPE_C);
  2250. pr_err
  2251. ("[****SD_Debug****]host will support DRIVING TYPE D\n");
  2252. break;
  2253. default:
  2254. pr_err("[****SD_Debug****]invalid drv_type:%d\n",
  2255. drv_type);
  2256. break;
  2257. }
  2258. }
  2259. if (current_limit != CAPS_CURRENT_NULL) {
  2260. #if 0 /* cause MMC_CAP_MAX??? and MMC_CAP_SET??? removed from linux3.6 */
  2261. switch (current_limit) {
  2262. case MAX_CURRENT_200:
  2263. msdc_host_mode[id] |= MMC_CAP_MAX_CURRENT_200;
  2264. msdc_host_mode[id] &=
  2265. (~MMC_CAP_MAX_CURRENT_400) &
  2266. (~MMC_CAP_MAX_CURRENT_600) &
  2267. (~MMC_CAP_MAX_CURRENT_800);
  2268. pr_err
  2269. ("[****SD_Debug****]host will support MAX_CURRENT_200\n");
  2270. break;
  2271. case MAX_CURRENT_400:
  2272. msdc_host_mode[id] |=
  2273. MMC_CAP_MAX_CURRENT_200 |
  2274. MMC_CAP_MAX_CURRENT_400;
  2275. msdc_host_mode[id] &=
  2276. (~MMC_CAP_MAX_CURRENT_600) &
  2277. (~MMC_CAP_MAX_CURRENT_800);
  2278. pr_err
  2279. ("[****SD_Debug****]host will support MAX_CURRENT_400\n");
  2280. break;
  2281. case MAX_CURRENT_600:
  2282. msdc_host_mode[id] |=
  2283. MMC_CAP_MAX_CURRENT_200 |
  2284. MMC_CAP_MAX_CURRENT_400 |
  2285. MMC_CAP_MAX_CURRENT_600;
  2286. msdc_host_mode[id] &= (~MMC_CAP_MAX_CURRENT_800);
  2287. pr_err
  2288. ("[****SD_Debug****]host will support MAX_CURRENT_600\n");
  2289. break;
  2290. case MAX_CURRENT_800:
  2291. msdc_host_mode[id] |=
  2292. MMC_CAP_MAX_CURRENT_200 |
  2293. MMC_CAP_MAX_CURRENT_400 |
  2294. MMC_CAP_MAX_CURRENT_600 |
  2295. MMC_CAP_MAX_CURRENT_800;
  2296. pr_err
  2297. ("[****SD_Debug****]host will support MAX_CURRENT_800\n");
  2298. break;
  2299. default:
  2300. pr_err
  2301. ("[****SD_Debug****]invalid current_limit:%d\n",
  2302. current_limit);
  2303. break;
  2304. }
  2305. #endif
  2306. }
  2307. if (pw_cr != CAPS_POWER_NULL)
  2308. #if 0
  2309. switch (pw_cr) {
  2310. case SDXC_NO_POWER_CONTROL:
  2311. msdc_host_mode[id] &=
  2312. (~MMC_CAP_SET_XPC_330) & (~MMC_CAP_SET_XPC_300)
  2313. & (~MMC_CAP_SET_XPC_180);
  2314. ("[****SD_Debug****]host will not support SDXC power control\n");
  2315. break;
  2316. case SDXC_POWER_CONTROL:
  2317. msdc_host_mode[id] |=
  2318. MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 |
  2319. MMC_CAP_SET_XPC_180;
  2320. pr_err
  2321. ("[****SD_Debug****]host will support SDXC power control\n");
  2322. break;
  2323. default:
  2324. pr_err("[****SD_Debug****]invalid pw_cr:%d\n",
  2325. pw_cr);
  2326. break;
  2327. }
  2328. #endif
  2329. pr_err
  2330. ("[****SD_Debug****]to enable settings, suspend and resume the phone\n");
  2331. } else {
  2332. pr_err("[****SD_Debug****]msdc[%d] supports:\n", id);
  2333. {
  2334. pr_err("[****SD_Debug****] speed mode: ");
  2335. if ((msdc_host_mode[id] & MMC_CAP_MMC_HIGHSPEED)
  2336. || (msdc_host_mode[id] & MMC_CAP_SD_HIGHSPEED))
  2337. pr_err("HS, ");
  2338. if (msdc_host_mode[id] & MMC_CAP_UHS_SDR12)
  2339. pr_err("SDR12, ");
  2340. if (msdc_host_mode[id] & MMC_CAP_UHS_SDR25)
  2341. pr_err("SDR25, ");
  2342. if (msdc_host_mode[id] & MMC_CAP_UHS_SDR50)
  2343. pr_err("SDR50, ");
  2344. if (msdc_host_mode[id] & MMC_CAP_UHS_SDR104)
  2345. pr_err("SDR104, ");
  2346. if (msdc_host_mode[id] & MMC_CAP_UHS_DDR50)
  2347. pr_err("DDR50 ");
  2348. if (!
  2349. (msdc_host_mode[id] &
  2350. (MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED |
  2351. MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
  2352. MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 |
  2353. MMC_CAP_UHS_DDR50)))
  2354. pr_err("N/A");
  2355. pr_err("\n");
  2356. }
  2357. {
  2358. pr_err("[****SD_Debug****] driver_type: ");
  2359. if (msdc_host_mode[id] & MMC_CAP_DRIVER_TYPE_A)
  2360. pr_err("A, ");
  2361. pr_err("B, ");
  2362. if (msdc_host_mode[id] & MMC_CAP_DRIVER_TYPE_C)
  2363. pr_err("C, ");
  2364. if (msdc_host_mode[id] & MMC_CAP_DRIVER_TYPE_D)
  2365. pr_err("D, ");
  2366. pr_err("\n");
  2367. }
  2368. {
  2369. #if 0
  2370. pr_err("[****SD_Debug****] current limit: ");
  2371. if (msdc_host_mode[id] & MMC_CAP_MAX_CURRENT_200)
  2372. pr_err("200mA, ");
  2373. if (msdc_host_mode[id] & MMC_CAP_MAX_CURRENT_400)
  2374. pr_err("400mA, ");
  2375. if (msdc_host_mode[id] & MMC_CAP_MAX_CURRENT_600)
  2376. pr_err("600mA, ");
  2377. if (msdc_host_mode[id] & MMC_CAP_MAX_CURRENT_800)
  2378. pr_err("800mA, ");
  2379. if (!
  2380. (msdc_host_mode[id] &
  2381. (MMC_CAP_MAX_CURRENT_200 | MMC_CAP_MAX_CURRENT_400 |
  2382. MMC_CAP_MAX_CURRENT_600 | MMC_CAP_MAX_CURRENT_800)))
  2383. pr_err("N/A");
  2384. pr_err("\n");
  2385. #endif
  2386. }
  2387. {
  2388. #if 0
  2389. pr_err("[****SD_Debug****] power control: ");
  2390. if (msdc_host_mode[id] & MMC_CAP_SET_XPC_330)
  2391. pr_err("3.3v ");
  2392. if (msdc_host_mode[id] & MMC_CAP_SET_XPC_300)
  2393. pr_err("3v ");
  2394. if (msdc_host_mode[id] & MMC_CAP_SET_XPC_180)
  2395. pr_err("1.8v ");
  2396. if (!
  2397. (msdc_host_mode[id] &
  2398. (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 |
  2399. MMC_CAP_SET_XPC_180)))
  2400. pr_err("N/A");
  2401. pr_err("\n");
  2402. #endif
  2403. }
  2404. }
  2405. }
  2406. } else if (cmd == SD_TOOL_DMA_STATUS) {
  2407. id = p1;
  2408. if (id >= HOST_MAX_NUM || id < 0)
  2409. pr_err("[****SD_Debug****]invalid host id: %d\n", id);
  2410. else {
  2411. if (p2 == 0) {
  2412. dma_status = msdc_get_dma_status(id);
  2413. pr_err(">>>> msdc%d: dma_status=%d, ", id, dma_status);
  2414. if (dma_status == 0) {
  2415. pr_err("DMA mode is disabled Now\n");
  2416. } else if (dma_status == 1) {
  2417. pr_err("Write data from SD to DRAM within DMA mode\n");
  2418. } else if (dma_status == 2) {
  2419. pr_err("Write data from DRAM to SD within DMA mode\n");
  2420. } else if (dma_status == -1) {
  2421. pr_err
  2422. ("No data transaction or the device is not present until now\n");
  2423. }
  2424. } else if (p2 == 1) {
  2425. pr_err(">>>> msdc%d: start dma violation test\n", id);
  2426. g_dma_debug[id] = 1;
  2427. sd_multi_rw_compare(id, COMPARE_ADDRESS_SD, 3);
  2428. }
  2429. }
  2430. } else if (cmd == MMC_REGISTER_READ) {
  2431. pr_err("p1 = 0x%x\n", p1);
  2432. /* get the register value, must know some register can't be read */
  2433. pr_err("regiser: 0x%x = 0x%x\n", p1, sdr_read32((ulong) p1));
  2434. }
  2435. #ifdef MTK_IO_PERFORMANCE_DEBUG
  2436. else if (cmd == MMC_PERF_DEBUG) {
  2437. /* 1 enable; 0 disable */
  2438. g_mtk_mmc_perf_dbg = p1;
  2439. g_mtk_mmc_dbg_range = p2;
  2440. if (2 == g_mtk_mmc_dbg_range) {
  2441. g_dbg_range_start = p3;
  2442. g_dbg_range_end = p3 + p4;
  2443. g_check_read_write = p5;
  2444. }
  2445. pr_err
  2446. ("g_mtk_mmc_perf_dbg = 0x%x, g_mtk_mmc_dbg_range = 0x%x, start = 0x%x, end = 0x%x\n",
  2447. g_mtk_mmc_perf_dbg, g_mtk_mmc_dbg_range, g_dbg_range_start, g_dbg_range_end);
  2448. } else if (cmd == MMC_PERF_DEBUG_PRINT) {
  2449. int i, j, k, num = 0;
  2450. if (p1 == 0) {
  2451. g_mtk_mmc_clear = 0;
  2452. return count;
  2453. }
  2454. pr_err("msdc g_dbg_req_count<%d>\n", g_dbg_req_count);
  2455. for (i = 1; i <= g_dbg_req_count; i++) {
  2456. pr_err("anslysis: %s 0x%x %d block, PGh %d\n",
  2457. (g_check_read_write == 18 ? "read" : "write"),
  2458. (unsigned int)g_mmcqd_buf[i][298], (unsigned int)g_mmcqd_buf[i][299],
  2459. (unsigned int)(g_mmcqd_buf[i][297] * 2));
  2460. if (g_check_read_write == 18) {
  2461. for (j = 1; j <= g_mmcqd_buf[i][296] * 2; j++) {
  2462. pr_err("page %d:\n", num + 1);
  2463. for (k = 0; k < 5; k++)
  2464. pr_err("%d %llu\n", k, g_req_buf[num][k]);
  2465. num += 1;
  2466. }
  2467. }
  2468. pr_err("-------------------------------------------\n");
  2469. for (j = 0; j < sizeof(g_time_mark) / sizeof(char *); j++)
  2470. pr_err("%d. %llu %s\n", j, g_mmcqd_buf[i][j], g_time_mark[j]);
  2471. pr_err("===========================================\n");
  2472. }
  2473. if (g_check_read_write == 25) {
  2474. pr_err("msdc g_dbg_write_count<%d>\n", g_dbg_write_count);
  2475. for (i = 1; i <= g_dbg_write_count; i++) {
  2476. pr_err("********************************************\n");
  2477. pr_err("write count: %llu\n", g_req_write_count[i]);
  2478. for (j = 0; j < sizeof(g_time_mark_vfs_write) / sizeof(char *); j++)
  2479. pr_err("%d. %llu %s\n", j, g_req_write_buf[i][j],
  2480. g_time_mark_vfs_write[j]);
  2481. }
  2482. pr_err("********************************************\n");
  2483. }
  2484. g_mtk_mmc_clear = 0;
  2485. }
  2486. #endif
  2487. #ifdef MTK_MMC_PERFORMANCE_TEST
  2488. else if (cmd == MMC_PERF_TEST) {
  2489. /* 1 enable; 0 disable */
  2490. g_mtk_mmc_perf_test = p1;
  2491. }
  2492. #endif
  2493. #ifdef MTK_MSDC_ERROR_TUNE_DEBUG
  2494. else if (cmd == MMC_ERROR_TUNE) {
  2495. g_err_tune_dbg_host = p1;
  2496. g_err_tune_dbg_cmd = p2;
  2497. g_err_tune_dbg_arg = p3;
  2498. g_err_tune_dbg_error = p4;
  2499. g_err_tune_dbg_count = p5;
  2500. if (g_err_tune_dbg_count && (g_err_tune_dbg_error != MTK_MSDC_ERROR_NONE)) {
  2501. pr_err
  2502. ("==========================MSDC error debug start ============================\n");
  2503. pr_err("host:%d, cmd=%d, arg=%d, error=%d, count=%d\n", g_err_tune_dbg_host,
  2504. g_err_tune_dbg_cmd, g_err_tune_dbg_arg, g_err_tune_dbg_error,
  2505. g_err_tune_dbg_count);
  2506. } else {
  2507. g_err_tune_dbg_host = 0;
  2508. g_err_tune_dbg_cmd = 0;
  2509. g_err_tune_dbg_arg = 0;
  2510. g_err_tune_dbg_error = MTK_MSDC_ERROR_NONE;
  2511. g_err_tune_dbg_count = 0;
  2512. pr_err("host:%d, cmd=%d, arg=%d, error=%d, count=%d\n",
  2513. g_err_tune_dbg_host, g_err_tune_dbg_cmd, g_err_tune_dbg_arg,
  2514. g_err_tune_dbg_error, g_err_tune_dbg_count);
  2515. pr_err
  2516. ("==========================MSDC error debug end ============================\n");
  2517. }
  2518. }
  2519. #endif
  2520. else if (cmd == MMC_EDC_EMMC_CACHE) {
  2521. pr_err
  2522. ("==========================MSDC Cache Feature Test ==============================\n");
  2523. id = p1;
  2524. if (id >= HOST_MAX_NUM || id < 0)
  2525. pr_err("[****MSDC Cache Feature Test****]invalid host id: %d\n", id);
  2526. else {
  2527. host = mtk_msdc_host[id];
  2528. switch (p2) {
  2529. case 0:
  2530. msdc_enable_emmc_cache(host, 0);
  2531. break;
  2532. case 1:
  2533. msdc_enable_emmc_cache(host, 1);
  2534. break;
  2535. case 2:
  2536. msdc_check_emmc_cache_status(host);
  2537. break;
  2538. default:
  2539. pr_err("ERROR:3rd parameter is wrong, please see the msdc_help\n");
  2540. break;
  2541. }
  2542. }
  2543. } else if (cmd == MMC_DUMP_GPD) {
  2544. pr_err
  2545. ("==========================MSDC DUMP GPD/BD ==============================\n");
  2546. id = p1;
  2547. if (id >= HOST_MAX_NUM || id < 0)
  2548. pr_err("invalid host id: %d\n", id);
  2549. else
  2550. msdc_dump_gpd_bd(id);
  2551. } else if (cmd == MMC_ETT_TUNE) {
  2552. pr_err("==========================MSDC ETT Tune ==============================\n");
  2553. #ifndef CONFIG_MTK_FPGA
  2554. msdc_ett_tunning(0, p1, 15, p2, p3);
  2555. #else
  2556. pr_err("not support ETT Tune on fpga\n");
  2557. #endif
  2558. } else if (cmd == MMC_CRC_STRESS) {
  2559. pr_err
  2560. ("==========================CRC Stress Test ==============================\n");
  2561. if (0 == p1) {
  2562. g_reset_tune = 0;
  2563. } else {
  2564. g_reset_tune = 1;
  2565. base = mtk_msdc_host[0]->base;
  2566. sdr_set_field(EMMC50_PAD_DS_TUNE, MSDC_EMMC50_PAD_DS_TUNE_DLY1, 0x1c);
  2567. sdr_set_field(EMMC50_PAD_DS_TUNE, MSDC_EMMC50_PAD_DS_TUNE_DLY3, 0xe);
  2568. }
  2569. } else if (cmd == ENABLE_AXI_MODULE) {
  2570. pr_err("===============%s AXI MODULE===============\n",
  2571. (p1 ? "enable" : "disable"));
  2572. if (p1) {
  2573. switch (p2) {
  2574. case 0:
  2575. pr_err("enable NFI transaction on AXI bus\n");
  2576. sdr_set_field(pericfg_reg_base, (0x1 << 14), 0x0); /* NFI_SW_RST */
  2577. break;
  2578. case 1:
  2579. pr_err("enable SD transaction on AXI bus\n");
  2580. sdr_set_field(pericfg_reg_base, (0x1 << 20), 0x0); /* MSDC1_SW_RST */
  2581. break;
  2582. case 2:
  2583. pr_err("enable USB transaction on AXI bus\n");
  2584. sdr_set_field(pericfg_reg_base, (0x1 << 28), 0x0); /* USB_SW_RST */
  2585. break;
  2586. case 3:
  2587. pr_err("enable PERI transaction on AXI bus\n");
  2588. sdr_set_field(pericfg_reg_base + 0x210, (0x3 << 8), 0x3); /* PERI_AXI */
  2589. break;
  2590. case 4:
  2591. pr_err("enable AUDIO transaction on AXI bus\n");
  2592. sdr_set_field(infracfg_ao_reg_base + 0x40, (0x1 << 5), 0x0); /* AUDIO_RST */
  2593. break;
  2594. case 5:
  2595. pr_err("enable ALL transaction on AXI bus\n");
  2596. sdr_set_field(pericfg_reg_base, (0x1 << 14), 0x0); /* NFI_SW_RST */
  2597. sdr_set_field(pericfg_reg_base, (0x1 << 20), 0x0); /* MSDC1_SW_RST */
  2598. sdr_set_field(pericfg_reg_base, (0x1 << 28), 0x0); /* USB_SW_RST */
  2599. sdr_set_field(pericfg_reg_base + 0x210, (0x3 << 8), 0x3); /* PERI_AXI */
  2600. sdr_set_field(infracfg_ao_reg_base + 0x40, (0x1 << 5), 0x0); /* AUDIO_RST */
  2601. break;
  2602. default:
  2603. break;
  2604. }
  2605. } else {
  2606. switch (p2) {
  2607. case 0:
  2608. pr_err("disable NFI transaction on AXI bus\n");
  2609. sdr_set_field(pericfg_reg_base, (0x1 << 14), 0x1); /* NFI_SW_RST */
  2610. break;
  2611. case 1:
  2612. pr_err("disable SD transaction on AXI bus\n");
  2613. sdr_set_field(pericfg_reg_base, (0x1 << 20), 0x1); /* MSDC1_SW_RST */
  2614. break;
  2615. case 2:
  2616. pr_err("disable USB transaction on AXI bus\n");
  2617. sdr_set_field(pericfg_reg_base, (0x1 << 28), 0x1); /* USB_SW_RST */
  2618. break;
  2619. case 3:
  2620. pr_err("disable PERI transaction on AXI bus\n");
  2621. sdr_set_field(pericfg_reg_base + 0x210, (0x3 << 8), 0x2); /* PERI_AXI */
  2622. break;
  2623. case 4:
  2624. pr_err("disable AUDIO transaction on AXI bus\n");
  2625. sdr_set_field(infracfg_ao_reg_base + 0x40, (0x1 << 5), 0x1); /* AUDIO_RST */
  2626. break;
  2627. case 5:
  2628. pr_err("disable ALL transaction on AXI bus\n");
  2629. sdr_set_field(pericfg_reg_base, (0x1 << 14), 0x1); /* NFI_SW_RST */
  2630. sdr_set_field(pericfg_reg_base, (0x1 << 20), 0x1); /* MSDC1_SW_RST */
  2631. sdr_set_field(pericfg_reg_base, (0x1 << 28), 0x1); /* USB_SW_RST */
  2632. sdr_set_field(pericfg_reg_base + 0x210, (0x3 << 8), 0x2); /* PERI_AXI */
  2633. sdr_set_field(infracfg_ao_reg_base + 0x40, (0x1 << 5), 0x1); /* AUDIO_RST */
  2634. break;
  2635. default:
  2636. break;
  2637. }
  2638. }
  2639. pr_err
  2640. ("disable AXI modules, reg[0x10003000]=0x%x, reg[0x10003210]=0x%x, reg[0x10001040]=0x%x\n",
  2641. sdr_read32(pericfg_reg_base), sdr_read32(pericfg_reg_base + 0x210),
  2642. sdr_read32(infracfg_ao_reg_base + 0x40));
  2643. }
  2644. return count;
  2645. }
  2646. static int msdc_tune_flag_proc_read_show(struct seq_file *m, void *data)
  2647. {
  2648. seq_printf(m, "0x%X\n", sdio_tune_flag);
  2649. return 0;
  2650. }
  2651. static int msdc_debug_proc_read_FT_show(struct seq_file *m, void *data)
  2652. {
  2653. #if defined(CONFIG_MTK_WCN_CMB_SDIO_SLOT)
  2654. int msdc_id = 0;
  2655. void __iomem *base;
  2656. unsigned char cmd_edge;
  2657. unsigned char data_edge;
  2658. unsigned char clk_drv1 = 0, clk_drv2 = 0, cmd_drv1 = 0, cmd_drv2 = 0, dat_drv1 =
  2659. 0, dat_drv2 = 0;
  2660. u32 cur_rxdly0;
  2661. u8 u8_dat0, u8_dat1, u8_dat2, u8_dat3;
  2662. u8 u8_wdat, u8_cmddat;
  2663. u8 u8_DDLSEL;
  2664. if (CONFIG_MTK_WCN_CMB_SDIO_SLOT == 0 && mtk_msdc_host[0]) {
  2665. base = mtk_msdc_host[0]->base;
  2666. msdc_id = 0;
  2667. } else if (CONFIG_MTK_WCN_CMB_SDIO_SLOT == 1 && mtk_msdc_host[1]) {
  2668. base = mtk_msdc_host[1]->base;
  2669. msdc_id = 1;
  2670. } else if (CONFIG_MTK_WCN_CMB_SDIO_SLOT == 2 && mtk_msdc_host[2]) {
  2671. base = mtk_msdc_host[2]->base;
  2672. msdc_id = 2;
  2673. } else if (CONFIG_MTK_WCN_CMB_SDIO_SLOT == 3 && mtk_msdc_host[3]) {
  2674. base = mtk_msdc_host[3]->base;
  2675. msdc_id = 3;
  2676. }
  2677. #ifndef FPGA_PLATFORM
  2678. #ifdef CONFIG_MTK_CLKMGR
  2679. enable_clock(MT_CG_PERI_MSDC30_0 + msdc_id, "SD");
  2680. #else
  2681. clk_enable(host->clock_control);
  2682. #endif
  2683. #endif
  2684. sdr_get_field((base + 0x04), MSDC_IOCON_RSPL, cmd_edge);
  2685. sdr_get_field((base + 0x04), MSDC_IOCON_R_D_SMPL, data_edge);
  2686. /*
  2687. sdr_get_field((base + 0xe0), MSDC_PAD_CTL0_CLKDRVN, clk_drv1);
  2688. sdr_get_field((base + 0xe0), MSDC_PAD_CTL0_CLKDRVP, clk_drv2);
  2689. sdr_get_field((base + 0xe4), MSDC_PAD_CTL1_CMDDRVN, cmd_drv1);
  2690. sdr_get_field((base + 0xe4), MSDC_PAD_CTL1_CMDDRVP, cmd_drv2);
  2691. sdr_get_field((base + 0xe8), MSDC_PAD_CTL2_DATDRVN, dat_drv1);
  2692. sdr_get_field((base + 0xe8), MSDC_PAD_CTL2_DATDRVP, dat_drv2);*/
  2693. sdr_get_field(MSDC_IOCON, MSDC_IOCON_DDLSEL, u8_DDLSEL);
  2694. cur_rxdly0 = sdr_read32(MSDC_DAT_RDDLY0);
  2695. if (sdr_read32(MSDC_ECO_VER) >= 4) {
  2696. u8_dat0 = (cur_rxdly0 >> 24) & 0x1F;
  2697. u8_dat1 = (cur_rxdly0 >> 16) & 0x1F;
  2698. u8_dat2 = (cur_rxdly0 >> 8) & 0x1F;
  2699. u8_dat3 = (cur_rxdly0 >> 0) & 0x1F;
  2700. } else {
  2701. u8_dat0 = (cur_rxdly0 >> 0) & 0x1F;
  2702. u8_dat1 = (cur_rxdly0 >> 8) & 0x1F;
  2703. u8_dat2 = (cur_rxdly0 >> 16) & 0x1F;
  2704. u8_dat3 = (cur_rxdly0 >> 24) & 0x1F;
  2705. }
  2706. sdr_get_field((base + 0xf0), MSDC_PAD_TUNE0_DATWRDLY, u8_wdat);
  2707. sdr_get_field((base + 0xf0), MSDC_PAD_TUNE0_CMDRRDLY, u8_cmddat);
  2708. seq_puts(m, "\n=========================================\n");
  2709. #if defined(CONFIG_MTK_WCN_CMB_SDIO_SLOT)
  2710. seq_printf(m, "(1) WCN SDIO SLOT is at msdc<%d>\n", CONFIG_MTK_WCN_CMB_SDIO_SLOT);
  2711. #endif
  2712. seq_puts(m, "-----------------------------------------\n");
  2713. seq_puts(m, "(2) clk settings\n");
  2714. seq_puts(m, "mt6589 only using internal clock\n");
  2715. seq_puts(m, "-----------------------------------------\n");
  2716. seq_puts(m, "(3) settings of driving current\n");
  2717. if ((clk_drv1 == clk_drv2) && (cmd_drv1 == cmd_drv2) && (dat_drv1 == dat_drv2)
  2718. && (clk_drv2 == cmd_drv1) && (cmd_drv2 == dat_drv1))
  2719. seq_printf(m, "driving current is <%d>\n", clk_drv1);
  2720. else {
  2721. seq_printf(m,
  2722. "clk_drv1<%d> clk_drv2<%d> cmd_drv1<%d> cmd_drv2<%d> dat_drv1<%d> dat_drv2<%d>\n",
  2723. clk_drv1, clk_drv2, cmd_drv1, cmd_drv2, dat_drv1, dat_drv2);
  2724. }
  2725. seq_puts(m, "-----------------------------------------\n");
  2726. seq_puts(m, "(4) edge settings\n");
  2727. if (cmd_edge)
  2728. seq_puts(m, "cmd_edge is falling\n");
  2729. else
  2730. seq_puts(m, "cmd_edge is rising\n");
  2731. if (data_edge)
  2732. seq_puts(m, "data_edge is falling\n");
  2733. else
  2734. seq_puts(m, "data_edge is rising\n");
  2735. seq_puts(m, "-----------------------------------------\n");
  2736. seq_puts(m, "(5) data delay info\n");
  2737. seq_printf(m, "Read (MSDC_DAT_RDDLY0) is <0x%x> and (MSDC_IOCON_DDLSEL) is <0x%x>\n",
  2738. cur_rxdly0, u8_DDLSEL);
  2739. seq_printf(m, "data0<0x%x> data1<0x%x> data2<0x%x> data3<0x%x>\n", u8_dat0, u8_dat1,
  2740. u8_dat2, u8_dat3);
  2741. seq_printf(m, "Write is <0x%x>\n", u8_wdat);
  2742. seq_printf(m, "Cmd is <0x%x>\n", u8_cmddat);
  2743. seq_puts(m, "=========================================\n\n");
  2744. return 0;
  2745. #else
  2746. seq_puts(m, "\n=========================================\n");
  2747. seq_puts(m, "There is no WCN SDIO SLOT.\n");
  2748. seq_puts(m, "=========================================\n\n");
  2749. return 0;
  2750. #endif
  2751. }
  2752. static ssize_t msdc_debug_proc_write_FT(struct file *file, const char __user *buf, size_t count,
  2753. loff_t *data)
  2754. {
  2755. int ret;
  2756. int i_case = 0, i_par1 = -1, i_par2 = -1, i_clk = 0, i_driving = 0, i_edge = 0, i_data =
  2757. 0, i_delay = 0;
  2758. u32 cur_rxdly0;
  2759. u8 u8_dat0, u8_dat1, u8_dat2, u8_dat3;
  2760. void __iomem *base;
  2761. int scan_ret;
  2762. if (count == 0)
  2763. return -1;
  2764. if (count > 255)
  2765. count = 255;
  2766. ret = copy_from_user(cmd_buf, buf, count);
  2767. if (ret < 0)
  2768. return -1;
  2769. cmd_buf[count] = '\0';
  2770. pr_err("[****SD_Debug****]msdc Write %s\n", cmd_buf);
  2771. scan_ret = sscanf(cmd_buf, "%d %d %d ", &i_case, &i_par1, &i_par2);
  2772. if (scan_ret < 0)
  2773. return scan_ret;
  2774. if (i_par2 == -1)
  2775. return -1;
  2776. pr_err("i_case=%d i_par1=%d i_par2=%d\n", i_case, i_par1, i_par2);
  2777. #if defined(CONFIG_MTK_WCN_CMB_SDIO_SLOT)
  2778. if (CONFIG_MTK_WCN_CMB_SDIO_SLOT == 0 && mtk_msdc_host[0])
  2779. base = mtk_msdc_host[0]->base;
  2780. if (CONFIG_MTK_WCN_CMB_SDIO_SLOT == 1 && mtk_msdc_host[1])
  2781. base = mtk_msdc_host[1]->base;
  2782. if (CONFIG_MTK_WCN_CMB_SDIO_SLOT == 2 && mtk_msdc_host[2])
  2783. base = mtk_msdc_host[2]->base;
  2784. if (CONFIG_MTK_WCN_CMB_SDIO_SLOT == 3 && mtk_msdc_host[3])
  2785. base = mtk_msdc_host[3]->base;
  2786. #else
  2787. return -1;
  2788. #endif
  2789. if (i_case == 1) {
  2790. if (!((i_par1 == 0) || (i_par1 == 1)))
  2791. return -1;
  2792. i_clk = i_par1;
  2793. /*sdr_set_field(MSDC_PATCH_BIT0, MSDC_PATCH_BIT_CKGEN_CK, i_clk);*/
  2794. pr_err("i_clk=%d\n", i_clk);
  2795. } else if (i_case == 2) {
  2796. if (!((i_par1 >= 0) && (i_par1 <= 7)))
  2797. return -1;
  2798. i_driving = i_par1;
  2799. /*
  2800. sdr_set_field((base + 0xe0), MSDC_PAD_CTL0_CLKDRVN, i_driving);
  2801. sdr_set_field((base + 0xe0), MSDC_PAD_CTL0_CLKDRVP, i_driving);
  2802. sdr_set_field((base + 0xe4), MSDC_PAD_CTL1_CMDDRVN, i_driving);
  2803. sdr_set_field((base + 0xe4), MSDC_PAD_CTL1_CMDDRVP, i_driving);
  2804. sdr_set_field((base + 0xe8), MSDC_PAD_CTL2_DATDRVN, i_driving);
  2805. sdr_set_field((base + 0xe8), MSDC_PAD_CTL2_DATDRVP, i_driving);*/
  2806. pr_err("i_driving=%d\n", i_driving);
  2807. } else if (i_case == 3) {
  2808. if (!((i_par1 >= 0) && (i_par1 <= 3)))
  2809. return -1;
  2810. if (!((i_par2 >= 0) && (i_par2 <= 31)))
  2811. return -1;
  2812. i_data = i_par1;
  2813. i_delay = i_par2;
  2814. cur_rxdly0 = sdr_read32(MSDC_DAT_RDDLY0);
  2815. if (sdr_read32(MSDC_ECO_VER) >= 4) {
  2816. u8_dat0 = (cur_rxdly0 >> 24) & 0x1F;
  2817. u8_dat1 = (cur_rxdly0 >> 16) & 0x1F;
  2818. u8_dat2 = (cur_rxdly0 >> 8) & 0x1F;
  2819. u8_dat3 = (cur_rxdly0 >> 0) & 0x1F;
  2820. } else {
  2821. u8_dat0 = (cur_rxdly0 >> 0) & 0x1F;
  2822. u8_dat1 = (cur_rxdly0 >> 8) & 0x1F;
  2823. u8_dat2 = (cur_rxdly0 >> 16) & 0x1F;
  2824. u8_dat3 = (cur_rxdly0 >> 24) & 0x1F;
  2825. }
  2826. if (i_data == 0)
  2827. u8_dat0 = i_delay;
  2828. else if (i_data == 1)
  2829. u8_dat1 = i_delay;
  2830. else if (i_data == 2)
  2831. u8_dat2 = i_delay;
  2832. else if (i_data == 3)
  2833. u8_dat3 = i_delay;
  2834. else if (i_data == 4)
  2835. sdr_set_field((base + 0xf0), MSDC_PAD_TUNE0_DATWRDLY, i_delay);
  2836. else if (i_data == 5)
  2837. sdr_set_field((base + 0xf0), MSDC_PAD_TUNE0_CMDRRDLY, i_delay);
  2838. else
  2839. return -1;
  2840. if (sdr_read32(MSDC_ECO_VER) >= 4) {
  2841. cur_rxdly0 = ((u8_dat0 & 0x1F) << 24) | ((u8_dat1 & 0x1F) << 16) |
  2842. ((u8_dat2 & 0x1F) << 8) | ((u8_dat3 & 0x1F) << 0);
  2843. } else {
  2844. cur_rxdly0 = ((u8_dat3 & 0x1F) << 24) | ((u8_dat2 & 0x1F) << 16) |
  2845. ((u8_dat1 & 0x1F) << 8) | ((u8_dat0 & 0x1F) << 0);
  2846. }
  2847. sdr_set_field(MSDC_IOCON, MSDC_IOCON_DDLSEL, 1);
  2848. sdr_write32(MSDC_DAT_RDDLY0, cur_rxdly0);
  2849. pr_err("i_data=%d i_delay=%d\n", i_data, i_delay);
  2850. } else if (i_case == 4) {
  2851. if (!((i_par1 == 0) || (i_par1 == 1)))
  2852. return -1;
  2853. i_edge = i_par1;
  2854. sdr_set_field((base + 0x04), MSDC_IOCON_RSPL, i_edge);
  2855. sdr_set_field((base + 0x04), MSDC_IOCON_R_D_SMPL, i_edge);
  2856. pr_err("i_edge=%d\n", i_edge);
  2857. } else {
  2858. return -1;
  2859. }
  2860. return 1;
  2861. }
  2862. #ifdef ONLINE_TUNING_DVTTEST
  2863. static int msdc_debug_proc_read_DVT_show(struct seq_file *m, void *data)
  2864. {
  2865. return 0;
  2866. }
  2867. static ssize_t msdc_debug_proc_write_DVT(struct file *file, const char __user *buf, size_t count,
  2868. loff_t *data)
  2869. {
  2870. int ret;
  2871. int i_msdc_id = 0;
  2872. int scan_ret;
  2873. struct msdc_host *host;
  2874. ret = copy_from_user(cmd_buf, buf, count);
  2875. if (ret < 0)
  2876. return -1;
  2877. cmd_buf[count] = '\0';
  2878. pr_err("[****SD_Debug****]msdc Write %s\n", cmd_buf);
  2879. i_msdc_id = 0;
  2880. if (scan_ret < 0)
  2881. return scan_ret;
  2882. if ((i_msdc_id < 0) || (i_msdc_id >= HOST_MAX_NUM)) {
  2883. pr_err("[****SD_Debug****]msdc id %d out of range [0~%d]\n", i_msdc_id,
  2884. HOST_MAX_NUM - 1);
  2885. return -1;
  2886. }
  2887. host = mtk_msdc_host[i_msdc_id];
  2888. pr_err("[****SD_Debug****] Start Online Tuning DVT test\n");
  2889. mt_msdc_online_tuning_test(host, 0, 0, 0);
  2890. pr_err("[****SD_Debug****] Finish Online Tuning DVT test\n");
  2891. return count;
  2892. }
  2893. #endif /* ONLINE_TUNING_DVTTEST*/
  2894. static int msdc_tune_proc_read_show(struct seq_file *m, void *data)
  2895. {
  2896. seq_puts(m, "\n=========================================\n");
  2897. seq_printf(m, "sdio_enable_tune: 0x%.8x\n", sdio_enable_tune);
  2898. seq_printf(m, "sdio_iocon_dspl: 0x%.8x\n", sdio_iocon_dspl);
  2899. seq_printf(m, "sdio_iocon_w_dspl: 0x%.8x\n", sdio_iocon_w_dspl);
  2900. seq_printf(m, "sdio_iocon_rspl: 0x%.8x\n", sdio_iocon_rspl);
  2901. seq_printf(m, "sdio_pad_tune_rrdly: 0x%.8x\n", sdio_pad_tune_rrdly);
  2902. seq_printf(m, "sdio_pad_tune_rdly: 0x%.8x\n", sdio_pad_tune_rdly);
  2903. seq_printf(m, "sdio_pad_tune_wrdly: 0x%.8x\n", sdio_pad_tune_wrdly);
  2904. seq_printf(m, "sdio_dat_rd_dly0_0: 0x%.8x\n", sdio_dat_rd_dly0_0);
  2905. seq_printf(m, "sdio_dat_rd_dly0_1: 0x%.8x\n", sdio_dat_rd_dly0_1);
  2906. seq_printf(m, "sdio_dat_rd_dly0_2: 0x%.8x\n", sdio_dat_rd_dly0_2);
  2907. seq_printf(m, "sdio_dat_rd_dly0_3: 0x%.8x\n", sdio_dat_rd_dly0_3);
  2908. seq_printf(m, "sdio_dat_rd_dly1_0: 0x%.8x\n", sdio_dat_rd_dly1_0);
  2909. seq_printf(m, "sdio_dat_rd_dly1_1: 0x%.8x\n", sdio_dat_rd_dly1_1);
  2910. seq_printf(m, "sdio_dat_rd_dly1_2: 0x%.8x\n", sdio_dat_rd_dly1_2);
  2911. seq_printf(m, "sdio_dat_rd_dly1_3: 0x%.8x\n", sdio_dat_rd_dly1_3);
  2912. seq_printf(m, "sdio_clk_drv: 0x%.8x\n", sdio_clk_drv);
  2913. seq_printf(m, "sdio_cmd_drv: 0x%.8x\n", sdio_cmd_drv);
  2914. seq_printf(m, "sdio_data_drv: 0x%.8x\n", sdio_data_drv);
  2915. seq_printf(m, "sdio_tune_flag: 0x%.8x\n", sdio_tune_flag);
  2916. seq_puts(m, "=========================================\n\n");
  2917. return 0;
  2918. }
  2919. static ssize_t msdc_tune_proc_write(struct file *file, const char __user *buf, size_t count,
  2920. loff_t *data)
  2921. {
  2922. int ret;
  2923. int cmd, p1, p2;
  2924. if (count == 0)
  2925. return -1;
  2926. if (count > 255)
  2927. count = 255;
  2928. ret = copy_from_user(cmd_buf, buf, count);
  2929. if (ret < 0)
  2930. return -1;
  2931. cmd_buf[count] = '\0';
  2932. pr_err("msdc Write %s\n", cmd_buf);
  2933. if (3 == sscanf(cmd_buf, "%x %x %x", &cmd, &p1, &p2)) {
  2934. switch (cmd) {
  2935. case 0:
  2936. if (p1 && p2) {
  2937. /*sdio_enable_tune = 1;*/
  2938. /* ettagent_init();*/
  2939. } else {
  2940. /*sdio_enable_tune = 0;*/
  2941. /* ettagent_exit();*/
  2942. }
  2943. break;
  2944. case 1: /*Cmd and Data latch edge*/
  2945. sdio_iocon_rspl = p1 & 0x1;
  2946. sdio_iocon_dspl = p2 & 0x1;
  2947. break;
  2948. case 2: /*Cmd Pad/Async*/
  2949. sdio_pad_tune_rrdly = (p1 & 0x1F);
  2950. sdio_pad_tune_rdly = (p2 & 0x1F);
  2951. break;
  2952. case 3:
  2953. sdio_dat_rd_dly0_0 = (p1 & 0x1F);
  2954. sdio_dat_rd_dly0_1 = (p2 & 0x1F);
  2955. break;
  2956. case 4:
  2957. sdio_dat_rd_dly0_2 = (p1 & 0x1F);
  2958. sdio_dat_rd_dly0_3 = (p2 & 0x1F);
  2959. break;
  2960. case 5: /*Write data edge/delay*/
  2961. sdio_iocon_w_dspl = p1 & 0x1;
  2962. sdio_pad_tune_wrdly = (p2 & 0x1F);
  2963. break;
  2964. case 6:
  2965. sdio_dat_rd_dly1_2 = (p1 & 0x1F);
  2966. sdio_dat_rd_dly1_3 = (p2 & 0x1F);
  2967. break;
  2968. case 7:
  2969. sdio_clk_drv = (p1 & 0x7);
  2970. break;
  2971. case 8:
  2972. sdio_cmd_drv = (p1 & 0x7);
  2973. sdio_data_drv = (p2 & 0x7);
  2974. break;
  2975. }
  2976. }
  2977. return count;
  2978. }
  2979. static int msdc_proc_open(struct inode *inode, struct file *file)
  2980. {
  2981. return single_open(file, msdc_debug_proc_show, inode->i_private);
  2982. }
  2983. static const struct file_operations msdc_proc_fops = {
  2984. .open = msdc_proc_open,
  2985. .write = msdc_debug_proc_write,
  2986. .read = seq_read,
  2987. .llseek = seq_lseek,
  2988. .release = single_release,
  2989. };
  2990. static int msdc_help_proc_open(struct inode *inode, struct file *file)
  2991. {
  2992. return single_open(file, msdc_help_proc_show, inode->i_private);
  2993. }
  2994. static const struct file_operations msdc_help_fops = {
  2995. .open = msdc_help_proc_open,
  2996. .read = seq_read,
  2997. .llseek = seq_lseek,
  2998. .release = single_release,
  2999. };
  3000. static int msdc_FT_open(struct inode *inode, struct file *file)
  3001. {
  3002. return single_open(file, msdc_debug_proc_read_FT_show, inode->i_private);
  3003. }
  3004. static const struct file_operations msdc_FT_fops = {
  3005. .open = msdc_FT_open,
  3006. .write = msdc_debug_proc_write_FT,
  3007. .read = seq_read,
  3008. .llseek = seq_lseek,
  3009. .release = single_release,
  3010. };
  3011. #ifdef ONLINE_TUNING_DVTTEST
  3012. static int msdc_DVT_open(struct inode *inode, struct file *file)
  3013. {
  3014. return single_open(file, msdc_debug_proc_read_DVT_show, inode->i_private);
  3015. }
  3016. static const struct file_operations msdc_DVT_fops = {
  3017. .open = msdc_DVT_open,
  3018. .write = msdc_debug_proc_write_DVT,
  3019. .read = seq_read,
  3020. .llseek = seq_lseek,
  3021. .release = single_release,
  3022. };
  3023. #endif /* ONLINE_TUNING_DVTTEST */
  3024. static int msdc_tune_proc_open(struct inode *inode, struct file *file)
  3025. {
  3026. return single_open(file, msdc_tune_proc_read_show, inode->i_private);
  3027. }
  3028. static const struct file_operations msdc_tune_fops = {
  3029. .open = msdc_tune_proc_open,
  3030. .read = seq_read,
  3031. .llseek = seq_lseek,
  3032. .release = single_release,
  3033. .write = msdc_tune_proc_write,
  3034. };
  3035. static int msdc_tune_flag_proc_open(struct inode *inode, struct file *file)
  3036. {
  3037. return single_open(file, msdc_tune_flag_proc_read_show, inode->i_private);
  3038. }
  3039. static const struct file_operations msdc_tune_flag_fops = {
  3040. .open = msdc_tune_flag_proc_open,
  3041. .read = seq_read,
  3042. .llseek = seq_lseek,
  3043. .release = single_release,
  3044. };
  3045. #ifdef MSDC_HQA
  3046. u32 sdio_vio18_flag = 0;
  3047. u32 sdio_vcore1_flag = 0;
  3048. u32 sdio_vcore2_flag = 0;
  3049. u32 vio18_reg = 0;
  3050. u32 vcore1_reg = 0;
  3051. u32 vcore2_reg = 0;
  3052. static ssize_t msdc_voltage_proc_write(struct file *file, const char __user *buf, size_t count,
  3053. loff_t *data)
  3054. {
  3055. int ret;
  3056. int scan_ret;
  3057. ret = copy_from_user(cmd_buf, buf, count);
  3058. if (ret < 0)
  3059. return -1;
  3060. cmd_buf[count] = '\0';
  3061. pr_err("[****SD_Debug****]msdc Write %s\n", cmd_buf);
  3062. scan_ret = sscanf(cmd_buf, "%d %d %d", &sdio_vio18_flag, &sdio_vcore1_flag, &sdio_vcore2_flag);
  3063. if (scan_ret < 0)
  3064. return scan_ret;
  3065. if (sdio_vio18_flag > 1600 && sdio_vio18_flag < 2000) {
  3066. /*0.0125V per step
  3067. Originally divied by 12.5, to avoid floating-point division, amplify numerator and denominator by 4*/
  3068. vio18_reg = ((sdio_vio18_flag - 1400) << 2) / 50;
  3069. pmic_config_interface(0x68c, vio18_reg, 0x7F, 0); /*VIO18 1700mv 0x18*/
  3070. pmic_config_interface(0x68e, vio18_reg, 0x7F, 0);
  3071. }
  3072. /*For K2, Vcore2 is VCORE_AO*/
  3073. if (sdio_vcore2_flag > 900 && sdio_vcore2_flag < 1200) {
  3074. /*0.00625V per step
  3075. Originally divied by 12.5, to avoid floating-point division, amplify numerator and denominator by 4*/
  3076. vcore2_reg = ((sdio_vcore2_flag - 600) << 2) / 25;
  3077. pmic_config_interface(0x662, vcore2_reg, 0x7F, 0); /*VCORE2 990mv 0x2e*/
  3078. pmic_config_interface(0x664, vcore2_reg, 0x7F, 0);
  3079. }
  3080. return count;
  3081. }
  3082. static int msdc_voltage_flag_proc_read_show(struct seq_file *m, void *data)
  3083. {
  3084. seq_printf(m, "vio18: 0x%d 0x%X\n", sdio_vio18_flag, vio18_reg);
  3085. seq_printf(m, "vcore1: 0x%d 0x%X\n", sdio_vcore1_flag, vcore1_reg);
  3086. seq_printf(m, "vcore2: 0x%d 0x%X\n", sdio_vcore2_flag, vcore2_reg);
  3087. return 0;
  3088. }
  3089. static int msdc_voltage_flag_proc_open(struct inode *inode, struct file *file)
  3090. {
  3091. return single_open(file, msdc_voltage_flag_proc_read_show, inode->i_private);
  3092. }
  3093. static const struct file_operations msdc_voltage_flag_fops = {
  3094. .open = msdc_voltage_flag_proc_open,
  3095. .read = seq_read,
  3096. .llseek = seq_lseek,
  3097. .release = single_release,
  3098. .write = msdc_voltage_proc_write,
  3099. };
  3100. #endif
  3101. int msdc_debug_proc_init(void)
  3102. {
  3103. struct proc_dir_entry *prEntry;
  3104. struct proc_dir_entry *tune;
  3105. struct proc_dir_entry *tune_flag;
  3106. kuid_t uid;
  3107. kgid_t gid;
  3108. #ifdef MSDC_HQA
  3109. struct proc_dir_entry *voltage_flag;
  3110. #endif
  3111. uid = make_kuid(&init_user_ns, 0);
  3112. gid = make_kgid(&init_user_ns, 1001);
  3113. #ifndef USER_BUILD_KERNEL
  3114. prEntry = proc_create("msdc_debug", 0660, NULL, &msdc_proc_fops);
  3115. #else
  3116. prEntry = proc_create("msdc_debug", 0660, NULL, &msdc_proc_fops);
  3117. #endif
  3118. if (prEntry) {
  3119. pr_err("[%s]: successfully create /proc/msdc_debug\n", __func__);
  3120. proc_set_user(prEntry, uid, gid);
  3121. } else {
  3122. pr_err("[%s]: failed to create /proc/msdc_debug\n", __func__);
  3123. }
  3124. #ifndef USER_BUILD_KERNEL
  3125. prEntry = proc_create("msdc_help", 0660, NULL, &msdc_help_fops);
  3126. #else
  3127. prEntry = proc_create("msdc_help", 0440, NULL, &msdc_help_fops);
  3128. #endif
  3129. if (prEntry)
  3130. pr_err("[%s]: successfully create /proc/msdc_help\n", __func__);
  3131. else
  3132. pr_err("[%s]: failed to create /proc/msdc_help\n", __func__);
  3133. #ifndef USER_BUILD_KERNEL
  3134. prEntry = proc_create("msdc_FT", 0660, NULL, &msdc_FT_fops);
  3135. #else
  3136. prEntry = proc_create("msdc_FT", 0440, NULL, &msdc_FT_fops);
  3137. #endif
  3138. if (prEntry)
  3139. pr_err("[%s]: successfully create /proc/msdc_FT\n", __func__);
  3140. else
  3141. pr_err("[%s]: failed to create /proc/msdc_FT\n", __func__);
  3142. #ifdef ONLINE_TUNING_DVTTEST
  3143. #ifndef USER_BUILD_KERNEL
  3144. prEntry = proc_create("msdc_DVT", 0660, NULL, &msdc_DVT_fops);
  3145. #else
  3146. prEntry = proc_create("msdc_DVT", 0440, NULL, &msdc_DVT_fops);
  3147. #endif
  3148. if (prEntry)
  3149. pr_err("[%s]: successfully create /proc/msdc_DVT\n", __func__);
  3150. else
  3151. pr_err("[%s]: failed to create /proc/msdc_DVT\n", __func__);
  3152. #endif
  3153. memset(msdc_drv_mode, 0, sizeof(msdc_drv_mode));
  3154. #ifndef USER_BUILD_KERNEL
  3155. tune = proc_create("msdc_tune", 0660, NULL, &msdc_tune_fops);
  3156. #else
  3157. tune = proc_create("msdc_tune", 0460, NULL, &msdc_tune_fops);
  3158. #endif
  3159. if (tune) {
  3160. proc_set_user(tune, uid, gid);
  3161. pr_err("[%s]: successfully create /proc/msdc_tune\n", __func__);
  3162. } else {
  3163. pr_err("[%s]: failed to create /proc/msdc_tune\n", __func__);
  3164. }
  3165. #ifndef USER_BUILD_KERNEL
  3166. tune_flag = proc_create("msdc_tune_flag", 0660, NULL, &msdc_tune_flag_fops);
  3167. #else
  3168. tune_flag = proc_create("msdc_tune_flag", 0440, NULL, &msdc_tune_flag_fops);
  3169. #endif
  3170. if (tune_flag)
  3171. pr_err("[%s]: successfully create /proc/msdc_tune_flag\n", __func__);
  3172. else
  3173. pr_err("[%s]: failed to create /proc/msdc_tune_flag\n", __func__);
  3174. #ifdef MSDC_HQA
  3175. #ifndef USER_BUILD_KERNEL
  3176. voltage_flag = proc_create("msdc_voltage_flag", 0660, NULL, &msdc_voltage_flag_fops);
  3177. #else
  3178. voltage_flag = proc_create("msdc_voltage_flag", 0460, NULL, &msdc_voltage_flag_fops);
  3179. #endif
  3180. if (voltage_flag) {
  3181. proc_set_user(voltage_flag, uid, gid);
  3182. pr_err("[%s]: successfully create /proc/msdc_voltage_flag\n", __func__);
  3183. } else {
  3184. pr_err("[%s]: failed to create /proc/msdc_voltage_flag\n", __func__);
  3185. }
  3186. #endif
  3187. return 0;
  3188. }
  3189. EXPORT_SYMBOL_GPL(msdc_debug_proc_init);