dbg.c 109 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513
  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. if (count == 0)
  2875. return -1;
  2876. if (count > 255)
  2877. count = 255;
  2878. ret = copy_from_user(cmd_buf, buf, count);
  2879. if (ret < 0)
  2880. return -1;
  2881. cmd_buf[count] = '\0';
  2882. pr_err("[****SD_Debug****]msdc Write %s\n", cmd_buf);
  2883. i_msdc_id = 0;
  2884. if (scan_ret < 0)
  2885. return scan_ret;
  2886. if ((i_msdc_id < 0) || (i_msdc_id >= HOST_MAX_NUM)) {
  2887. pr_err("[****SD_Debug****]msdc id %d out of range [0~%d]\n", i_msdc_id,
  2888. HOST_MAX_NUM - 1);
  2889. return -1;
  2890. }
  2891. host = mtk_msdc_host[i_msdc_id];
  2892. if (host) {
  2893. pr_err("[****SD_Debug****] Start Online Tuning DVT test\n");
  2894. mt_msdc_online_tuning_test(host, 0, 0, 0);
  2895. pr_err("[****SD_Debug****] Finish Online Tuning DVT test\n");
  2896. }
  2897. return count;
  2898. }
  2899. #endif /* ONLINE_TUNING_DVTTEST*/
  2900. static int msdc_tune_proc_read_show(struct seq_file *m, void *data)
  2901. {
  2902. seq_puts(m, "\n=========================================\n");
  2903. seq_printf(m, "sdio_enable_tune: 0x%.8x\n", sdio_enable_tune);
  2904. seq_printf(m, "sdio_iocon_dspl: 0x%.8x\n", sdio_iocon_dspl);
  2905. seq_printf(m, "sdio_iocon_w_dspl: 0x%.8x\n", sdio_iocon_w_dspl);
  2906. seq_printf(m, "sdio_iocon_rspl: 0x%.8x\n", sdio_iocon_rspl);
  2907. seq_printf(m, "sdio_pad_tune_rrdly: 0x%.8x\n", sdio_pad_tune_rrdly);
  2908. seq_printf(m, "sdio_pad_tune_rdly: 0x%.8x\n", sdio_pad_tune_rdly);
  2909. seq_printf(m, "sdio_pad_tune_wrdly: 0x%.8x\n", sdio_pad_tune_wrdly);
  2910. seq_printf(m, "sdio_dat_rd_dly0_0: 0x%.8x\n", sdio_dat_rd_dly0_0);
  2911. seq_printf(m, "sdio_dat_rd_dly0_1: 0x%.8x\n", sdio_dat_rd_dly0_1);
  2912. seq_printf(m, "sdio_dat_rd_dly0_2: 0x%.8x\n", sdio_dat_rd_dly0_2);
  2913. seq_printf(m, "sdio_dat_rd_dly0_3: 0x%.8x\n", sdio_dat_rd_dly0_3);
  2914. seq_printf(m, "sdio_dat_rd_dly1_0: 0x%.8x\n", sdio_dat_rd_dly1_0);
  2915. seq_printf(m, "sdio_dat_rd_dly1_1: 0x%.8x\n", sdio_dat_rd_dly1_1);
  2916. seq_printf(m, "sdio_dat_rd_dly1_2: 0x%.8x\n", sdio_dat_rd_dly1_2);
  2917. seq_printf(m, "sdio_dat_rd_dly1_3: 0x%.8x\n", sdio_dat_rd_dly1_3);
  2918. seq_printf(m, "sdio_clk_drv: 0x%.8x\n", sdio_clk_drv);
  2919. seq_printf(m, "sdio_cmd_drv: 0x%.8x\n", sdio_cmd_drv);
  2920. seq_printf(m, "sdio_data_drv: 0x%.8x\n", sdio_data_drv);
  2921. seq_printf(m, "sdio_tune_flag: 0x%.8x\n", sdio_tune_flag);
  2922. seq_puts(m, "=========================================\n\n");
  2923. return 0;
  2924. }
  2925. static ssize_t msdc_tune_proc_write(struct file *file, const char __user *buf, size_t count,
  2926. loff_t *data)
  2927. {
  2928. int ret;
  2929. int cmd, p1, p2;
  2930. if (count == 0)
  2931. return -1;
  2932. if (count > 255)
  2933. count = 255;
  2934. ret = copy_from_user(cmd_buf, buf, count);
  2935. if (ret < 0)
  2936. return -1;
  2937. cmd_buf[count] = '\0';
  2938. pr_err("msdc Write %s\n", cmd_buf);
  2939. if (3 == sscanf(cmd_buf, "%x %x %x", &cmd, &p1, &p2)) {
  2940. switch (cmd) {
  2941. case 0:
  2942. if (p1 && p2) {
  2943. /*sdio_enable_tune = 1;*/
  2944. /* ettagent_init();*/
  2945. } else {
  2946. /*sdio_enable_tune = 0;*/
  2947. /* ettagent_exit();*/
  2948. }
  2949. break;
  2950. case 1: /*Cmd and Data latch edge*/
  2951. sdio_iocon_rspl = p1 & 0x1;
  2952. sdio_iocon_dspl = p2 & 0x1;
  2953. break;
  2954. case 2: /*Cmd Pad/Async*/
  2955. sdio_pad_tune_rrdly = (p1 & 0x1F);
  2956. sdio_pad_tune_rdly = (p2 & 0x1F);
  2957. break;
  2958. case 3:
  2959. sdio_dat_rd_dly0_0 = (p1 & 0x1F);
  2960. sdio_dat_rd_dly0_1 = (p2 & 0x1F);
  2961. break;
  2962. case 4:
  2963. sdio_dat_rd_dly0_2 = (p1 & 0x1F);
  2964. sdio_dat_rd_dly0_3 = (p2 & 0x1F);
  2965. break;
  2966. case 5: /*Write data edge/delay*/
  2967. sdio_iocon_w_dspl = p1 & 0x1;
  2968. sdio_pad_tune_wrdly = (p2 & 0x1F);
  2969. break;
  2970. case 6:
  2971. sdio_dat_rd_dly1_2 = (p1 & 0x1F);
  2972. sdio_dat_rd_dly1_3 = (p2 & 0x1F);
  2973. break;
  2974. case 7:
  2975. sdio_clk_drv = (p1 & 0x7);
  2976. break;
  2977. case 8:
  2978. sdio_cmd_drv = (p1 & 0x7);
  2979. sdio_data_drv = (p2 & 0x7);
  2980. break;
  2981. }
  2982. }
  2983. return count;
  2984. }
  2985. static int msdc_proc_open(struct inode *inode, struct file *file)
  2986. {
  2987. return single_open(file, msdc_debug_proc_show, inode->i_private);
  2988. }
  2989. static const struct file_operations msdc_proc_fops = {
  2990. .open = msdc_proc_open,
  2991. .write = msdc_debug_proc_write,
  2992. .read = seq_read,
  2993. .llseek = seq_lseek,
  2994. .release = single_release,
  2995. };
  2996. static int msdc_help_proc_open(struct inode *inode, struct file *file)
  2997. {
  2998. return single_open(file, msdc_help_proc_show, inode->i_private);
  2999. }
  3000. static const struct file_operations msdc_help_fops = {
  3001. .open = msdc_help_proc_open,
  3002. .read = seq_read,
  3003. .llseek = seq_lseek,
  3004. .release = single_release,
  3005. };
  3006. static int msdc_FT_open(struct inode *inode, struct file *file)
  3007. {
  3008. return single_open(file, msdc_debug_proc_read_FT_show, inode->i_private);
  3009. }
  3010. static const struct file_operations msdc_FT_fops = {
  3011. .open = msdc_FT_open,
  3012. .write = msdc_debug_proc_write_FT,
  3013. .read = seq_read,
  3014. .llseek = seq_lseek,
  3015. .release = single_release,
  3016. };
  3017. #ifdef ONLINE_TUNING_DVTTEST
  3018. static int msdc_DVT_open(struct inode *inode, struct file *file)
  3019. {
  3020. return single_open(file, msdc_debug_proc_read_DVT_show, inode->i_private);
  3021. }
  3022. static const struct file_operations msdc_DVT_fops = {
  3023. .open = msdc_DVT_open,
  3024. .write = msdc_debug_proc_write_DVT,
  3025. .read = seq_read,
  3026. .llseek = seq_lseek,
  3027. .release = single_release,
  3028. };
  3029. #endif /* ONLINE_TUNING_DVTTEST */
  3030. static int msdc_tune_proc_open(struct inode *inode, struct file *file)
  3031. {
  3032. return single_open(file, msdc_tune_proc_read_show, inode->i_private);
  3033. }
  3034. static const struct file_operations msdc_tune_fops = {
  3035. .open = msdc_tune_proc_open,
  3036. .read = seq_read,
  3037. .llseek = seq_lseek,
  3038. .release = single_release,
  3039. .write = msdc_tune_proc_write,
  3040. };
  3041. static int msdc_tune_flag_proc_open(struct inode *inode, struct file *file)
  3042. {
  3043. return single_open(file, msdc_tune_flag_proc_read_show, inode->i_private);
  3044. }
  3045. static const struct file_operations msdc_tune_flag_fops = {
  3046. .open = msdc_tune_flag_proc_open,
  3047. .read = seq_read,
  3048. .llseek = seq_lseek,
  3049. .release = single_release,
  3050. };
  3051. #ifdef MSDC_HQA
  3052. u32 sdio_vio18_flag = 0;
  3053. u32 sdio_vcore1_flag = 0;
  3054. u32 sdio_vcore2_flag = 0;
  3055. u32 vio18_reg = 0;
  3056. u32 vcore1_reg = 0;
  3057. u32 vcore2_reg = 0;
  3058. static ssize_t msdc_voltage_proc_write(struct file *file, const char __user *buf, size_t count,
  3059. loff_t *data)
  3060. {
  3061. int ret;
  3062. int scan_ret;
  3063. if (count == 0)
  3064. return -1;
  3065. if (count > 255)
  3066. count = 255;
  3067. ret = copy_from_user(cmd_buf, buf, count);
  3068. if (ret < 0)
  3069. return -1;
  3070. cmd_buf[count] = '\0';
  3071. pr_err("[****SD_Debug****]msdc Write %s\n", cmd_buf);
  3072. scan_ret = sscanf(cmd_buf, "%d %d %d", &sdio_vio18_flag, &sdio_vcore1_flag, &sdio_vcore2_flag);
  3073. if (scan_ret < 0)
  3074. return scan_ret;
  3075. if (sdio_vio18_flag > 1600 && sdio_vio18_flag < 2000) {
  3076. /*0.0125V per step
  3077. Originally divied by 12.5, to avoid floating-point division, amplify numerator and denominator by 4*/
  3078. vio18_reg = ((sdio_vio18_flag - 1400) << 2) / 50;
  3079. pmic_config_interface(0x68c, vio18_reg, 0x7F, 0); /*VIO18 1700mv 0x18*/
  3080. pmic_config_interface(0x68e, vio18_reg, 0x7F, 0);
  3081. }
  3082. /*For K2, Vcore2 is VCORE_AO*/
  3083. if (sdio_vcore2_flag > 900 && sdio_vcore2_flag < 1200) {
  3084. /*0.00625V per step
  3085. Originally divied by 12.5, to avoid floating-point division, amplify numerator and denominator by 4*/
  3086. vcore2_reg = ((sdio_vcore2_flag - 600) << 2) / 25;
  3087. pmic_config_interface(0x662, vcore2_reg, 0x7F, 0); /*VCORE2 990mv 0x2e*/
  3088. pmic_config_interface(0x664, vcore2_reg, 0x7F, 0);
  3089. }
  3090. return count;
  3091. }
  3092. static int msdc_voltage_flag_proc_read_show(struct seq_file *m, void *data)
  3093. {
  3094. seq_printf(m, "vio18: 0x%d 0x%X\n", sdio_vio18_flag, vio18_reg);
  3095. seq_printf(m, "vcore1: 0x%d 0x%X\n", sdio_vcore1_flag, vcore1_reg);
  3096. seq_printf(m, "vcore2: 0x%d 0x%X\n", sdio_vcore2_flag, vcore2_reg);
  3097. return 0;
  3098. }
  3099. static int msdc_voltage_flag_proc_open(struct inode *inode, struct file *file)
  3100. {
  3101. return single_open(file, msdc_voltage_flag_proc_read_show, inode->i_private);
  3102. }
  3103. static const struct file_operations msdc_voltage_flag_fops = {
  3104. .open = msdc_voltage_flag_proc_open,
  3105. .read = seq_read,
  3106. .llseek = seq_lseek,
  3107. .release = single_release,
  3108. .write = msdc_voltage_proc_write,
  3109. };
  3110. #endif
  3111. int msdc_debug_proc_init(void)
  3112. {
  3113. #if 0
  3114. struct proc_dir_entry *prEntry;
  3115. struct proc_dir_entry *tune;
  3116. struct proc_dir_entry *tune_flag;
  3117. #endif
  3118. kuid_t uid;
  3119. kgid_t gid;
  3120. #ifdef MSDC_HQA
  3121. struct proc_dir_entry *voltage_flag;
  3122. #endif
  3123. uid = make_kuid(&init_user_ns, 0);
  3124. gid = make_kgid(&init_user_ns, 1001);
  3125. #if 0
  3126. #ifndef USER_BUILD_KERNEL
  3127. prEntry = proc_create("msdc_debug", 0660, NULL, &msdc_proc_fops);
  3128. #else
  3129. prEntry = proc_create("msdc_debug", 0660, NULL, &msdc_proc_fops);
  3130. #endif
  3131. if (prEntry) {
  3132. pr_err("[%s]: successfully create /proc/msdc_debug\n", __func__);
  3133. proc_set_user(prEntry, uid, gid);
  3134. } else {
  3135. pr_err("[%s]: failed to create /proc/msdc_debug\n", __func__);
  3136. }
  3137. #ifndef USER_BUILD_KERNEL
  3138. prEntry = proc_create("msdc_help", 0660, NULL, &msdc_help_fops);
  3139. #else
  3140. prEntry = proc_create("msdc_help", 0440, NULL, &msdc_help_fops);
  3141. #endif
  3142. if (prEntry)
  3143. pr_err("[%s]: successfully create /proc/msdc_help\n", __func__);
  3144. else
  3145. pr_err("[%s]: failed to create /proc/msdc_help\n", __func__);
  3146. #ifndef USER_BUILD_KERNEL
  3147. prEntry = proc_create("msdc_FT", 0660, NULL, &msdc_FT_fops);
  3148. #else
  3149. prEntry = proc_create("msdc_FT", 0440, NULL, &msdc_FT_fops);
  3150. #endif
  3151. if (prEntry)
  3152. pr_err("[%s]: successfully create /proc/msdc_FT\n", __func__);
  3153. else
  3154. pr_err("[%s]: failed to create /proc/msdc_FT\n", __func__);
  3155. #ifdef ONLINE_TUNING_DVTTEST
  3156. #ifndef USER_BUILD_KERNEL
  3157. prEntry = proc_create("msdc_DVT", 0660, NULL, &msdc_DVT_fops);
  3158. #else
  3159. prEntry = proc_create("msdc_DVT", 0440, NULL, &msdc_DVT_fops);
  3160. #endif
  3161. if (prEntry)
  3162. pr_err("[%s]: successfully create /proc/msdc_DVT\n", __func__);
  3163. else
  3164. pr_err("[%s]: failed to create /proc/msdc_DVT\n", __func__);
  3165. #endif
  3166. #endif
  3167. memset(msdc_drv_mode, 0, sizeof(msdc_drv_mode));
  3168. #if 0
  3169. #ifndef USER_BUILD_KERNEL
  3170. tune = proc_create("msdc_tune", 0660, NULL, &msdc_tune_fops);
  3171. #else
  3172. tune = proc_create("msdc_tune", 0460, NULL, &msdc_tune_fops);
  3173. #endif
  3174. if (tune) {
  3175. proc_set_user(tune, uid, gid);
  3176. pr_err("[%s]: successfully create /proc/msdc_tune\n", __func__);
  3177. } else {
  3178. pr_err("[%s]: failed to create /proc/msdc_tune\n", __func__);
  3179. }
  3180. #ifndef USER_BUILD_KERNEL
  3181. tune_flag = proc_create("msdc_tune_flag", 0660, NULL, &msdc_tune_flag_fops);
  3182. #else
  3183. tune_flag = proc_create("msdc_tune_flag", 0440, NULL, &msdc_tune_flag_fops);
  3184. #endif
  3185. if (tune_flag)
  3186. pr_err("[%s]: successfully create /proc/msdc_tune_flag\n", __func__);
  3187. else
  3188. pr_err("[%s]: failed to create /proc/msdc_tune_flag\n", __func__);
  3189. #endif
  3190. #ifdef MSDC_HQA
  3191. #ifndef USER_BUILD_KERNEL
  3192. voltage_flag = proc_create("msdc_voltage_flag", 0660, NULL, &msdc_voltage_flag_fops);
  3193. #else
  3194. voltage_flag = proc_create("msdc_voltage_flag", 0460, NULL, &msdc_voltage_flag_fops);
  3195. #endif
  3196. if (voltage_flag) {
  3197. proc_set_user(voltage_flag, uid, gid);
  3198. pr_err("[%s]: successfully create /proc/msdc_voltage_flag\n", __func__);
  3199. } else {
  3200. pr_err("[%s]: failed to create /proc/msdc_voltage_flag\n", __func__);
  3201. }
  3202. #endif
  3203. return 0;
  3204. }
  3205. EXPORT_SYMBOL_GPL(msdc_debug_proc_init);