lemote.patch 113 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271
  1. diff -Nur linux-2.6.37.orig/arch/mips/Kconfig linux-2.6.37/arch/mips/Kconfig
  2. --- linux-2.6.37.orig/arch/mips/Kconfig 2011-01-05 01:50:19.000000000 +0100
  3. +++ linux-2.6.37/arch/mips/Kconfig 2011-01-11 20:44:43.000000000 +0100
  4. @@ -210,7 +210,7 @@
  5. config MACH_LOONGSON
  6. bool "Loongson family of machines"
  7. - select SYS_SUPPORTS_ZBOOT
  8. + select SYS_SUPPORTS_ZBOOT_UART16550
  9. help
  10. This enables the support of Loongson family of machines.
  11. @@ -1101,6 +1101,8 @@
  12. bool "Loongson 2E"
  13. depends on SYS_HAS_CPU_LOONGSON2E
  14. select CPU_LOONGSON2
  15. + select GENERIC_GPIO
  16. + select ARCH_REQUIRE_GPIOLIB
  17. help
  18. The Loongson 2E processor implements the MIPS III instruction set
  19. with many extensions.
  20. @@ -2099,6 +2101,18 @@
  21. source "kernel/time/Kconfig"
  22. #
  23. +# High Resolution sched_clock() Configuration
  24. +#
  25. +
  26. +config CPU_HAS_FIXED_C0_COUNT
  27. + bool
  28. +
  29. +config CPU_SUPPORTS_HR_SCHED_CLOCK
  30. + bool
  31. + depends on CPU_HAS_FIXED_C0_COUNT || !CPU_FREQ
  32. + default y
  33. +
  34. +#
  35. # Timer Interrupt Frequency Configuration
  36. #
  37. diff -Nur linux-2.6.37.orig/arch/mips/include/asm/dma-mapping.h linux-2.6.37/arch/mips/include/asm/dma-mapping.h
  38. --- linux-2.6.37.orig/arch/mips/include/asm/dma-mapping.h 2011-01-05 01:50:19.000000000 +0100
  39. +++ linux-2.6.37/arch/mips/include/asm/dma-mapping.h 2011-01-11 20:44:43.000000000 +0100
  40. @@ -85,4 +85,8 @@
  41. void dma_free_noncoherent(struct device *dev, size_t size,
  42. void *vaddr, dma_addr_t dma_handle);
  43. +#define ARCH_HAS_DMA_MMAP_COHERENT
  44. +extern int dma_mmap_coherent(struct device *dev, struct vm_area_struct *vma,
  45. + void *cpu_addr, dma_addr_t handle, size_t size);
  46. +
  47. #endif /* _ASM_DMA_MAPPING_H */
  48. diff -Nur linux-2.6.37.orig/arch/mips/include/asm/mach-loongson/cs5536/cs5536.h linux-2.6.37/arch/mips/include/asm/mach-loongson/cs5536/cs5536.h
  49. --- linux-2.6.37.orig/arch/mips/include/asm/mach-loongson/cs5536/cs5536.h 2011-01-05 01:50:19.000000000 +0100
  50. +++ linux-2.6.37/arch/mips/include/asm/mach-loongson/cs5536/cs5536.h 2011-01-11 20:44:43.000000000 +0100
  51. @@ -255,21 +255,12 @@
  52. * IDE STANDARD
  53. */
  54. #define IDE_CAP 0x00
  55. -#define IDE_CONFIG 0x01
  56. -#define IDE_SMI 0x02
  57. -#define IDE_ERROR 0x03
  58. -#define IDE_PM 0x04
  59. -#define IDE_DIAG 0x05
  60. -
  61. -/*
  62. - * IDE SPEC.
  63. - */
  64. #define IDE_IO_BAR 0x08
  65. #define IDE_CFG 0x10
  66. #define IDE_DTC 0x12
  67. #define IDE_CAST 0x13
  68. #define IDE_ETC 0x14
  69. -#define IDE_INTERNAL_PM 0x15
  70. +#define IDE_PM 0x15
  71. /*
  72. * ACC STANDARD
  73. @@ -301,5 +292,40 @@
  74. /* GPIO : I/O SPACE; REG : 32BITS */
  75. #define GPIOL_OUT_VAL 0x00
  76. #define GPIOL_OUT_EN 0x04
  77. +#define GPIOL_OUT_AUX1_SEL 0x10
  78. +/* SMB : I/O SPACE, REG : 8BITS WIDTH */
  79. +#define SMB_SDA 0x00
  80. +#define SMB_STS 0x01
  81. +#define SMB_STS_SLVSTP (1 << 7)
  82. +#define SMB_STS_SDAST (1 << 6)
  83. +#define SMB_STS_BER (1 << 5)
  84. +#define SMB_STS_NEGACK (1 << 4)
  85. +#define SMB_STS_STASTR (1 << 3)
  86. +#define SMB_STS_NMATCH (1 << 2)
  87. +#define SMB_STS_MASTER (1 << 1)
  88. +#define SMB_STS_XMIT (1 << 0)
  89. +#define SMB_CTRL_STS 0x02
  90. +#define SMB_CSTS_TGSTL (1 << 5)
  91. +#define SMB_CSTS_TSDA (1 << 4)
  92. +#define SMB_CSTS_GCMTCH (1 << 3)
  93. +#define SMB_CSTS_MATCH (1 << 2)
  94. +#define SMB_CSTS_BB (1 << 1)
  95. +#define SMB_CSTS_BUSY (1 << 0)
  96. +#define SMB_CTRL1 0x03
  97. +#define SMB_CTRL1_STASTRE (1 << 7)
  98. +#define SMB_CTRL1_NMINTE (1 << 6)
  99. +#define SMB_CTRL1_GCMEN (1 << 5)
  100. +#define SMB_CTRL1_ACK (1 << 4)
  101. +#define SMB_CTRL1_RSVD (1 << 3)
  102. +#define SMB_CTRL1_INTEN (1 << 2)
  103. +#define SMB_CTRL1_STOP (1 << 1)
  104. +#define SMB_CTRL1_START (1 << 0)
  105. +#define SMB_ADDR 0x04
  106. +#define SMB_ADDR_SAEN (1 << 7)
  107. +#define SMB_CONTROLLER_ADDR (0xef << 0)
  108. +#define SMB_CTRL2 0x05
  109. +#define SMB_FREQ (0x20 << 1)
  110. +#define SMB_ENABLE (0x01 << 0)
  111. +#define SMB_CTRL3 0x06
  112. #endif /* _CS5536_H */
  113. diff -Nur linux-2.6.37.orig/arch/mips/include/asm/mach-loongson/cs5536/cs5536_mfgpt.h linux-2.6.37/arch/mips/include/asm/mach-loongson/cs5536/cs5536_mfgpt.h
  114. --- linux-2.6.37.orig/arch/mips/include/asm/mach-loongson/cs5536/cs5536_mfgpt.h 2011-01-05 01:50:19.000000000 +0100
  115. +++ linux-2.6.37/arch/mips/include/asm/mach-loongson/cs5536/cs5536_mfgpt.h 2011-01-11 20:44:43.000000000 +0100
  116. @@ -32,4 +32,9 @@
  117. #define MFGPT0_CNT (MFGPT_BASE + 4)
  118. #define MFGPT0_SETUP (MFGPT_BASE + 6)
  119. +#define MFGPT2_CMP1 (MFGPT_BASE + 0x10)
  120. +#define MFGPT2_CMP2 (MFGPT_BASE + 0x12)
  121. +#define MFGPT2_CNT (MFGPT_BASE + 0x14)
  122. +#define MFGPT2_SETUP (MFGPT_BASE + 0x16)
  123. +
  124. #endif /*!_CS5536_MFGPT_H */
  125. diff -Nur linux-2.6.37.orig/arch/mips/include/asm/mach-loongson/ec_kb3310b.h linux-2.6.37/arch/mips/include/asm/mach-loongson/ec_kb3310b.h
  126. --- linux-2.6.37.orig/arch/mips/include/asm/mach-loongson/ec_kb3310b.h 1970-01-01 01:00:00.000000000 +0100
  127. +++ linux-2.6.37/arch/mips/include/asm/mach-loongson/ec_kb3310b.h 2011-01-11 20:44:43.000000000 +0100
  128. @@ -0,0 +1,191 @@
  129. +/*
  130. + * KB3310B Embedded Controller
  131. + *
  132. + * Copyright (C) 2008 Lemote Inc.
  133. + * Author: liujl <liujl@lemote.com>, 2008-03-14
  134. + * Copyright (C) 2009 Lemote Inc.
  135. + * Author: Wu Zhangjin <wuzhangjin@gmail.com>
  136. + *
  137. + * This program is free software; you can redistribute it and/or modify
  138. + * it under the terms of the GNU General Public License as published by
  139. + * the Free Software Foundation; either version 2 of the License, or
  140. + * (at your option) any later version.
  141. + */
  142. +
  143. +#ifndef _EC_KB3310B_H
  144. +#define _EC_KB3310B_H
  145. +
  146. +extern unsigned char ec_read(unsigned short addr);
  147. +extern void ec_write(unsigned short addr, unsigned char val);
  148. +extern int ec_query_seq(unsigned char cmd);
  149. +extern int ec_query_event_num(void);
  150. +extern int ec_get_event_num(void);
  151. +
  152. +typedef int (*sci_handler) (int status);
  153. +extern sci_handler yeeloong_report_lid_status;
  154. +
  155. +#define SCI_IRQ_NUM 0x0A
  156. +
  157. +/*
  158. + * The following registers are determined by the EC index configuration.
  159. + * 1, fill the PORT_HIGH as EC register high part.
  160. + * 2, fill the PORT_LOW as EC register low part.
  161. + * 3, fill the PORT_DATA as EC register write data or get the data from it.
  162. + */
  163. +#define EC_IO_PORT_HIGH 0x0381
  164. +#define EC_IO_PORT_LOW 0x0382
  165. +#define EC_IO_PORT_DATA 0x0383
  166. +
  167. +/*
  168. + * EC delay time is 500us for register and status access
  169. + */
  170. +#define EC_REG_DELAY 500 /* unit : us */
  171. +#define EC_CMD_TIMEOUT 0x1000
  172. +
  173. +/*
  174. + * EC access port for SCI communication
  175. + */
  176. +#define EC_CMD_PORT 0x66
  177. +#define EC_STS_PORT 0x66
  178. +#define EC_DAT_PORT 0x62
  179. +#define CMD_INIT_IDLE_MODE 0xdd
  180. +#define CMD_EXIT_IDLE_MODE 0xdf
  181. +#define CMD_INIT_RESET_MODE 0xd8
  182. +#define CMD_REBOOT_SYSTEM 0x8c
  183. +#define CMD_GET_EVENT_NUM 0x84
  184. +#define CMD_PROGRAM_PIECE 0xda
  185. +
  186. +/* Temperature & Fan registers */
  187. +#define REG_TEMPERATURE_VALUE 0xF458
  188. +#define REG_FAN_AUTO_MAN_SWITCH 0xF459
  189. +#define BIT_FAN_AUTO 0
  190. +#define BIT_FAN_MANUAL 1
  191. +#define REG_FAN_CONTROL 0xF4D2
  192. +#define BIT_FAN_CONTROL_ON (1 << 0)
  193. +#define BIT_FAN_CONTROL_OFF (0 << 0)
  194. +#define REG_FAN_STATUS 0xF4DA
  195. +#define BIT_FAN_STATUS_ON (1 << 0)
  196. +#define BIT_FAN_STATUS_OFF (0 << 0)
  197. +#define REG_FAN_SPEED_HIGH 0xFE22
  198. +#define REG_FAN_SPEED_LOW 0xFE23
  199. +#define REG_FAN_SPEED_LEVEL 0xF4CC
  200. +/* Fan speed divider */
  201. +#define FAN_SPEED_DIVIDER 480000 /* (60*1000*1000/62.5/2)*/
  202. +
  203. +/* Battery registers */
  204. +#define REG_BAT_DESIGN_CAP_HIGH 0xF77D
  205. +#define REG_BAT_DESIGN_CAP_LOW 0xF77E
  206. +#define REG_BAT_FULLCHG_CAP_HIGH 0xF780
  207. +#define REG_BAT_FULLCHG_CAP_LOW 0xF781
  208. +#define REG_BAT_DESIGN_VOL_HIGH 0xF782
  209. +#define REG_BAT_DESIGN_VOL_LOW 0xF783
  210. +#define REG_BAT_CURRENT_HIGH 0xF784
  211. +#define REG_BAT_CURRENT_LOW 0xF785
  212. +#define REG_BAT_VOLTAGE_HIGH 0xF786
  213. +#define REG_BAT_VOLTAGE_LOW 0xF787
  214. +#define REG_BAT_TEMPERATURE_HIGH 0xF788
  215. +#define REG_BAT_TEMPERATURE_LOW 0xF789
  216. +#define REG_BAT_RELATIVE_CAP_HIGH 0xF492
  217. +#define REG_BAT_RELATIVE_CAP_LOW 0xF493
  218. +#define REG_BAT_VENDOR 0xF4C4
  219. +#define FLAG_BAT_VENDOR_SANYO 0x01
  220. +#define FLAG_BAT_VENDOR_SIMPLO 0x02
  221. +#define REG_BAT_CELL_COUNT 0xF4C6
  222. +#define FLAG_BAT_CELL_3S1P 0x03
  223. +#define FLAG_BAT_CELL_3S2P 0x06
  224. +#define REG_BAT_CHARGE 0xF4A2
  225. +#define FLAG_BAT_CHARGE_DISCHARGE 0x01
  226. +#define FLAG_BAT_CHARGE_CHARGE 0x02
  227. +#define FLAG_BAT_CHARGE_ACPOWER 0x00
  228. +#define REG_BAT_STATUS 0xF4B0
  229. +#define BIT_BAT_STATUS_LOW (1 << 5)
  230. +#define BIT_BAT_STATUS_DESTROY (1 << 2)
  231. +#define BIT_BAT_STATUS_FULL (1 << 1)
  232. +#define BIT_BAT_STATUS_IN (1 << 0)
  233. +#define REG_BAT_CHARGE_STATUS 0xF4B1
  234. +#define BIT_BAT_CHARGE_STATUS_OVERTEMP (1 << 2)
  235. +#define BIT_BAT_CHARGE_STATUS_PRECHG (1 << 1)
  236. +#define REG_BAT_STATE 0xF482
  237. +#define BIT_BAT_STATE_CHARGING (1 << 1)
  238. +#define BIT_BAT_STATE_DISCHARGING (1 << 0)
  239. +#define REG_BAT_POWER 0xF440
  240. +#define BIT_BAT_POWER_S3 (1 << 2)
  241. +#define BIT_BAT_POWER_ON (1 << 1)
  242. +#define BIT_BAT_POWER_ACIN (1 << 0)
  243. +
  244. +/* Audio: rd/wr */
  245. +#define REG_AUDIO_VOLUME 0xF46C
  246. +#define REG_AUDIO_MUTE 0xF4E7
  247. +#define REG_AUDIO_BEEP 0xF4D0
  248. +/* USB port power or not: rd/wr */
  249. +#define REG_USB0_FLAG 0xF461
  250. +#define REG_USB1_FLAG 0xF462
  251. +#define REG_USB2_FLAG 0xF463
  252. +#define BIT_USB_FLAG_ON 1
  253. +#define BIT_USB_FLAG_OFF 0
  254. +/* LID */
  255. +#define REG_LID_DETECT 0xF4BD
  256. +#define BIT_LID_DETECT_ON 1
  257. +#define BIT_LID_DETECT_OFF 0
  258. +/* CRT */
  259. +#define REG_CRT_DETECT 0xF4AD
  260. +#define BIT_CRT_DETECT_PLUG 1
  261. +#define BIT_CRT_DETECT_UNPLUG 0
  262. +/* LCD backlight brightness adjust: 9 levels */
  263. +#define REG_DISPLAY_BRIGHTNESS 0xF4F5
  264. +/* Black screen Status */
  265. +#define BIT_DISPLAY_LCD_ON 1
  266. +#define BIT_DISPLAY_LCD_OFF 0
  267. +/* LCD backlight control: off/restore */
  268. +#define REG_BACKLIGHT_CTRL 0xF7BD
  269. +#define BIT_BACKLIGHT_ON 1
  270. +#define BIT_BACKLIGHT_OFF 0
  271. +/* Reset the machine auto-clear: rd/wr */
  272. +#define REG_RESET 0xF4EC
  273. +#define BIT_RESET_ON 1
  274. +/* Light the led: rd/wr */
  275. +#define REG_LED 0xF4C8
  276. +#define BIT_LED_RED_POWER (1 << 0)
  277. +#define BIT_LED_ORANGE_POWER (1 << 1)
  278. +#define BIT_LED_GREEN_CHARGE (1 << 2)
  279. +#define BIT_LED_RED_CHARGE (1 << 3)
  280. +#define BIT_LED_NUMLOCK (1 << 4)
  281. +/* Test led mode, all led on/off */
  282. +#define REG_LED_TEST 0xF4C2
  283. +#define BIT_LED_TEST_IN 1
  284. +#define BIT_LED_TEST_OUT 0
  285. +/* Camera on/off */
  286. +#define REG_CAMERA_STATUS 0xF46A
  287. +#define BIT_CAMERA_STATUS_ON 1
  288. +#define BIT_CAMERA_STATUS_OFF 0
  289. +#define REG_CAMERA_CONTROL 0xF7B7
  290. +#define BIT_CAMERA_CONTROL_OFF 0
  291. +#define BIT_CAMERA_CONTROL_ON 1
  292. +/* Wlan Status */
  293. +#define REG_WLAN 0xF4FA
  294. +#define BIT_WLAN_ON 1
  295. +#define BIT_WLAN_OFF 0
  296. +#define REG_DISPLAY_LCD 0xF79F
  297. +
  298. +/* SCI Event Number from EC */
  299. +enum {
  300. + EVENT_LID = 0x23, /* Turn on/off LID */
  301. + EVENT_SWITCHVIDEOMODE, /* Fn+F3 for display switch */
  302. + EVENT_SLEEP, /* Fn+F1 for entering sleep mode */
  303. + EVENT_OVERTEMP, /* Over-temperature happened */
  304. + EVENT_CRT_DETECT, /* CRT is connected */
  305. + EVENT_CAMERA, /* Camera on/off */
  306. + EVENT_USB_OC2, /* USB2 Over Current occurred */
  307. + EVENT_USB_OC0, /* USB0 Over Current occurred */
  308. + EVENT_DISPLAYTOGGLE, /* Fn+F2, Turn on/off backlight */
  309. + EVENT_AUDIO_MUTE, /* Fn+F4, Mute on/off */
  310. + EVENT_DISPLAY_BRIGHTNESS,/* Fn+^/V, LCD backlight brightness adjust */
  311. + EVENT_AC_BAT, /* AC & Battery relative issue */
  312. + EVENT_AUDIO_VOLUME, /* Fn+<|>, Volume adjust */
  313. + EVENT_WLAN, /* Wlan on/off */
  314. +};
  315. +
  316. +#define EVENT_START EVENT_LID
  317. +#define EVENT_END EVENT_WLAN
  318. +
  319. +#endif /* !_EC_KB3310B_H */
  320. diff -Nur linux-2.6.37.orig/arch/mips/include/asm/mach-loongson/loongson.h linux-2.6.37/arch/mips/include/asm/mach-loongson/loongson.h
  321. --- linux-2.6.37.orig/arch/mips/include/asm/mach-loongson/loongson.h 2011-01-05 01:50:19.000000000 +0100
  322. +++ linux-2.6.37/arch/mips/include/asm/mach-loongson/loongson.h 2011-01-11 20:44:43.000000000 +0100
  323. @@ -43,6 +43,12 @@
  324. #endif
  325. }
  326. +/*
  327. + * Copy kernel command line from arcs_cmdline
  328. + */
  329. +#include <asm/setup.h>
  330. +extern char loongson_cmdline[COMMAND_LINE_SIZE];
  331. +
  332. /* irq operation functions */
  333. extern void bonito_irqdispatch(void);
  334. extern void __init bonito_irq_init(void);
  335. diff -Nur linux-2.6.37.orig/arch/mips/kernel/csrc-r4k.c linux-2.6.37/arch/mips/kernel/csrc-r4k.c
  336. --- linux-2.6.37.orig/arch/mips/kernel/csrc-r4k.c 2011-01-05 01:50:19.000000000 +0100
  337. +++ linux-2.6.37/arch/mips/kernel/csrc-r4k.c 2011-01-11 20:44:43.000000000 +0100
  338. @@ -6,10 +6,66 @@
  339. * Copyright (C) 2007 by Ralf Baechle
  340. */
  341. #include <linux/clocksource.h>
  342. +#include <linux/cnt32_to_63.h>
  343. #include <linux/init.h>
  344. +#include <linux/timer.h>
  345. #include <asm/time.h>
  346. +#ifdef CONFIG_CPU_SUPPORTS_HR_SCHED_CLOCK
  347. +/*
  348. + * MIPS sched_clock implementation.
  349. + *
  350. + * Because the hardware timer period is quite short and because cnt32_to_63()
  351. + * needs to be called at least once per half period to work properly, a kernel
  352. + * timer is set up to ensure this requirement is always met.
  353. + *
  354. + * Please refer to include/linux/cnt32_to_63.h and arch/arm/plat-orion/time.c
  355. + */
  356. +#define CLOCK2NS_SCALE_FACTOR 8
  357. +
  358. +static unsigned long clock2ns_scale __read_mostly;
  359. +
  360. +unsigned long long notrace sched_clock(void)
  361. +{
  362. + unsigned long long v = cnt32_to_63(read_c0_count());
  363. + return (v * clock2ns_scale) >> CLOCK2NS_SCALE_FACTOR;
  364. +}
  365. +
  366. +static struct timer_list cnt32_to_63_keepwarm_timer;
  367. +
  368. +static void cnt32_to_63_keepwarm(unsigned long data)
  369. +{
  370. + mod_timer(&cnt32_to_63_keepwarm_timer, round_jiffies(jiffies + data));
  371. + sched_clock();
  372. +}
  373. +#endif
  374. +
  375. +static inline void setup_hres_sched_clock(unsigned long clock)
  376. +{
  377. +#ifdef CONFIG_CPU_SUPPORTS_HR_SCHED_CLOCK
  378. + unsigned long long v;
  379. + unsigned long data;
  380. +
  381. + v = NSEC_PER_SEC;
  382. + v <<= CLOCK2NS_SCALE_FACTOR;
  383. + v += clock/2;
  384. + do_div(v, clock);
  385. + /*
  386. + * We want an even value to automatically clear the top bit
  387. + * returned by cnt32_to_63() without an additional run time
  388. + * instruction. So if the LSB is 1 then round it up.
  389. + */
  390. + if (v & 1)
  391. + v++;
  392. + clock2ns_scale = v;
  393. +
  394. + data = 0x80000000UL / clock * HZ;
  395. + setup_timer(&cnt32_to_63_keepwarm_timer, cnt32_to_63_keepwarm, data);
  396. + mod_timer(&cnt32_to_63_keepwarm_timer, round_jiffies(jiffies + data));
  397. +#endif
  398. +}
  399. +
  400. static cycle_t c0_hpt_read(struct clocksource *cs)
  401. {
  402. return read_c0_count();
  403. @@ -27,6 +83,8 @@
  404. if (!cpu_has_counter || !mips_hpt_frequency)
  405. return -ENXIO;
  406. + setup_hres_sched_clock(mips_hpt_frequency);
  407. +
  408. /* Calculate a somewhat reasonable rating value */
  409. clocksource_mips.rating = 200 + mips_hpt_frequency / 10000000;
  410. diff -Nur linux-2.6.37.orig/arch/mips/kernel/time.c linux-2.6.37/arch/mips/kernel/time.c
  411. --- linux-2.6.37.orig/arch/mips/kernel/time.c 2011-01-05 01:50:19.000000000 +0100
  412. +++ linux-2.6.37/arch/mips/kernel/time.c 2011-01-11 20:44:43.000000000 +0100
  413. @@ -119,6 +119,11 @@
  414. void __init time_init(void)
  415. {
  416. +#ifdef CONFIG_HR_SCHED_CLOCK
  417. + if (!mips_clockevent_init() || !cpu_has_mfc0_count_bug())
  418. + write_c0_count(0);
  419. +#endif
  420. +
  421. plat_time_init();
  422. if (!mips_clockevent_init() || !cpu_has_mfc0_count_bug())
  423. diff -Nur linux-2.6.37.orig/arch/mips/loongson/common/cmdline.c linux-2.6.37/arch/mips/loongson/common/cmdline.c
  424. --- linux-2.6.37.orig/arch/mips/loongson/common/cmdline.c 2011-01-05 01:50:19.000000000 +0100
  425. +++ linux-2.6.37/arch/mips/loongson/common/cmdline.c 2011-01-11 20:44:43.000000000 +0100
  426. @@ -17,10 +17,15 @@
  427. * Free Software Foundation; either version 2 of the License, or (at your
  428. * option) any later version.
  429. */
  430. +#include <linux/module.h>
  431. #include <asm/bootinfo.h>
  432. #include <loongson.h>
  433. +/* the kernel command line copied from arcs_cmdline */
  434. +char loongson_cmdline[COMMAND_LINE_SIZE];
  435. +EXPORT_SYMBOL(loongson_cmdline);
  436. +
  437. void __init prom_init_cmdline(void)
  438. {
  439. int prom_argc;
  440. @@ -50,4 +55,26 @@
  441. strcat(arcs_cmdline, " root=/dev/hda1");
  442. prom_init_machtype();
  443. +
  444. + /* append machine specific command line */
  445. + switch (mips_machtype) {
  446. + case MACH_LEMOTE_LL2F:
  447. + if ((strstr(arcs_cmdline, "video=")) == NULL)
  448. + strcat(arcs_cmdline, " video=sisfb:1360x768-16@60");
  449. + break;
  450. + case MACH_LEMOTE_FL2F:
  451. + if ((strstr(arcs_cmdline, "ide_core.ignore_cable=")) == NULL)
  452. + strcat(arcs_cmdline, " ide_core.ignore_cable=0");
  453. + break;
  454. + case MACH_LEMOTE_ML2F7:
  455. + /* Mengloong-2F has a 800x480 screen */
  456. + if ((strstr(arcs_cmdline, "vga=")) == NULL)
  457. + strcat(arcs_cmdline, " vga=0x313");
  458. + break;
  459. + default:
  460. + break;
  461. + }
  462. +
  463. + /* copy arcs_cmdline into loongson_cmdline */
  464. + strncpy(loongson_cmdline, arcs_cmdline, COMMAND_LINE_SIZE);
  465. }
  466. diff -Nur linux-2.6.37.orig/arch/mips/loongson/common/cs5536/cs5536_acc.c linux-2.6.37/arch/mips/loongson/common/cs5536/cs5536_acc.c
  467. --- linux-2.6.37.orig/arch/mips/loongson/common/cs5536/cs5536_acc.c 2011-01-05 01:50:19.000000000 +0100
  468. +++ linux-2.6.37/arch/mips/loongson/common/cs5536/cs5536_acc.c 2011-01-11 20:44:43.000000000 +0100
  469. @@ -18,7 +18,7 @@
  470. void pci_acc_write_reg(int reg, u32 value)
  471. {
  472. - u32 hi = 0, lo = value;
  473. + u32 hi, lo;
  474. switch (reg) {
  475. case PCI_COMMAND:
  476. @@ -66,75 +66,73 @@
  477. u32 pci_acc_read_reg(int reg)
  478. {
  479. u32 hi, lo;
  480. - u32 conf_data = 0;
  481. + u32 cfg = 0;
  482. switch (reg) {
  483. case PCI_VENDOR_ID:
  484. - conf_data =
  485. - CFG_PCI_VENDOR_ID(CS5536_ACC_DEVICE_ID, CS5536_VENDOR_ID);
  486. + cfg = CFG_PCI_VENDOR_ID(CS5536_ACC_DEVICE_ID,
  487. + CS5536_VENDOR_ID);
  488. break;
  489. case PCI_COMMAND:
  490. _rdmsr(GLIU_MSR_REG(GLIU_IOD_BM1), &hi, &lo);
  491. if (((lo & 0xfff00000) || (hi & 0x000000ff))
  492. && ((hi & 0xf0000000) == 0xa0000000))
  493. - conf_data |= PCI_COMMAND_IO;
  494. + cfg |= PCI_COMMAND_IO;
  495. _rdmsr(GLIU_MSR_REG(GLIU_PAE), &hi, &lo);
  496. if ((lo & 0x300) == 0x300)
  497. - conf_data |= PCI_COMMAND_MASTER;
  498. + cfg |= PCI_COMMAND_MASTER;
  499. break;
  500. case PCI_STATUS:
  501. - conf_data |= PCI_STATUS_66MHZ;
  502. - conf_data |= PCI_STATUS_FAST_BACK;
  503. + cfg |= PCI_STATUS_66MHZ;
  504. + cfg |= PCI_STATUS_FAST_BACK;
  505. _rdmsr(SB_MSR_REG(SB_ERROR), &hi, &lo);
  506. if (lo & SB_PARE_ERR_FLAG)
  507. - conf_data |= PCI_STATUS_PARITY;
  508. - conf_data |= PCI_STATUS_DEVSEL_MEDIUM;
  509. + cfg |= PCI_STATUS_PARITY;
  510. + cfg |= PCI_STATUS_DEVSEL_MEDIUM;
  511. break;
  512. case PCI_CLASS_REVISION:
  513. _rdmsr(ACC_MSR_REG(ACC_CAP), &hi, &lo);
  514. - conf_data = lo & 0x000000ff;
  515. - conf_data |= (CS5536_ACC_CLASS_CODE << 8);
  516. + cfg = lo & 0x000000ff;
  517. + cfg |= (CS5536_ACC_CLASS_CODE << 8);
  518. break;
  519. case PCI_CACHE_LINE_SIZE:
  520. - conf_data =
  521. - CFG_PCI_CACHE_LINE_SIZE(PCI_NORMAL_HEADER_TYPE,
  522. - PCI_NORMAL_LATENCY_TIMER);
  523. + cfg = CFG_PCI_CACHE_LINE_SIZE(PCI_NORMAL_HEADER_TYPE,
  524. + PCI_NORMAL_LATENCY_TIMER);
  525. break;
  526. case PCI_BAR0_REG:
  527. _rdmsr(GLCP_MSR_REG(GLCP_SOFT_COM), &hi, &lo);
  528. if (lo & SOFT_BAR_ACC_FLAG) {
  529. - conf_data = CS5536_ACC_RANGE |
  530. + cfg = CS5536_ACC_RANGE |
  531. PCI_BASE_ADDRESS_SPACE_IO;
  532. lo &= ~SOFT_BAR_ACC_FLAG;
  533. _wrmsr(GLCP_MSR_REG(GLCP_SOFT_COM), hi, lo);
  534. } else {
  535. _rdmsr(GLIU_MSR_REG(GLIU_IOD_BM1), &hi, &lo);
  536. - conf_data = (hi & 0x000000ff) << 12;
  537. - conf_data |= (lo & 0xfff00000) >> 20;
  538. - conf_data |= 0x01;
  539. - conf_data &= ~0x02;
  540. + cfg = (hi & 0x000000ff) << 12;
  541. + cfg |= (lo & 0xfff00000) >> 20;
  542. + cfg |= 0x01;
  543. + cfg &= ~0x02;
  544. }
  545. break;
  546. case PCI_CARDBUS_CIS:
  547. - conf_data = PCI_CARDBUS_CIS_POINTER;
  548. + cfg = PCI_CARDBUS_CIS_POINTER;
  549. break;
  550. case PCI_SUBSYSTEM_VENDOR_ID:
  551. - conf_data =
  552. - CFG_PCI_VENDOR_ID(CS5536_ACC_SUB_ID, CS5536_SUB_VENDOR_ID);
  553. + cfg = CFG_PCI_VENDOR_ID(CS5536_ACC_SUB_ID,
  554. + CS5536_SUB_VENDOR_ID);
  555. break;
  556. case PCI_ROM_ADDRESS:
  557. - conf_data = PCI_EXPANSION_ROM_BAR;
  558. + cfg = PCI_EXPANSION_ROM_BAR;
  559. break;
  560. case PCI_CAPABILITY_LIST:
  561. - conf_data = PCI_CAPLIST_USB_POINTER;
  562. + cfg = PCI_CAPLIST_USB_POINTER;
  563. break;
  564. case PCI_INTERRUPT_LINE:
  565. - conf_data =
  566. - CFG_PCI_INTERRUPT_LINE(PCI_DEFAULT_PIN, CS5536_ACC_INTR);
  567. + cfg = CFG_PCI_INTERRUPT_LINE(PCI_DEFAULT_PIN, CS5536_ACC_INTR);
  568. break;
  569. default:
  570. break;
  571. }
  572. - return conf_data;
  573. + return cfg;
  574. }
  575. diff -Nur linux-2.6.37.orig/arch/mips/loongson/common/cs5536/cs5536_ehci.c linux-2.6.37/arch/mips/loongson/common/cs5536/cs5536_ehci.c
  576. --- linux-2.6.37.orig/arch/mips/loongson/common/cs5536/cs5536_ehci.c 2011-01-05 01:50:19.000000000 +0100
  577. +++ linux-2.6.37/arch/mips/loongson/common/cs5536/cs5536_ehci.c 2011-01-11 20:44:43.000000000 +0100
  578. @@ -18,7 +18,7 @@
  579. void pci_ehci_write_reg(int reg, u32 value)
  580. {
  581. - u32 hi = 0, lo = value;
  582. + u32 hi, lo;
  583. switch (reg) {
  584. case PCI_COMMAND:
  585. @@ -78,83 +78,81 @@
  586. u32 pci_ehci_read_reg(int reg)
  587. {
  588. - u32 conf_data = 0;
  589. + u32 cfg = 0;
  590. u32 hi, lo;
  591. switch (reg) {
  592. case PCI_VENDOR_ID:
  593. - conf_data =
  594. - CFG_PCI_VENDOR_ID(CS5536_EHCI_DEVICE_ID, CS5536_VENDOR_ID);
  595. + cfg = CFG_PCI_VENDOR_ID(CS5536_EHCI_DEVICE_ID,
  596. + CS5536_VENDOR_ID);
  597. break;
  598. case PCI_COMMAND:
  599. _rdmsr(USB_MSR_REG(USB_EHCI), &hi, &lo);
  600. if (hi & PCI_COMMAND_MASTER)
  601. - conf_data |= PCI_COMMAND_MASTER;
  602. + cfg |= PCI_COMMAND_MASTER;
  603. if (hi & PCI_COMMAND_MEMORY)
  604. - conf_data |= PCI_COMMAND_MEMORY;
  605. + cfg |= PCI_COMMAND_MEMORY;
  606. break;
  607. case PCI_STATUS:
  608. - conf_data |= PCI_STATUS_66MHZ;
  609. - conf_data |= PCI_STATUS_FAST_BACK;
  610. + cfg |= PCI_STATUS_66MHZ;
  611. + cfg |= PCI_STATUS_FAST_BACK;
  612. _rdmsr(SB_MSR_REG(SB_ERROR), &hi, &lo);
  613. if (lo & SB_PARE_ERR_FLAG)
  614. - conf_data |= PCI_STATUS_PARITY;
  615. - conf_data |= PCI_STATUS_DEVSEL_MEDIUM;
  616. + cfg |= PCI_STATUS_PARITY;
  617. + cfg |= PCI_STATUS_DEVSEL_MEDIUM;
  618. break;
  619. case PCI_CLASS_REVISION:
  620. _rdmsr(USB_MSR_REG(USB_CAP), &hi, &lo);
  621. - conf_data = lo & 0x000000ff;
  622. - conf_data |= (CS5536_EHCI_CLASS_CODE << 8);
  623. + cfg = lo & 0x000000ff;
  624. + cfg |= (CS5536_EHCI_CLASS_CODE << 8);
  625. break;
  626. case PCI_CACHE_LINE_SIZE:
  627. - conf_data =
  628. - CFG_PCI_CACHE_LINE_SIZE(PCI_NORMAL_HEADER_TYPE,
  629. - PCI_NORMAL_LATENCY_TIMER);
  630. + cfg = CFG_PCI_CACHE_LINE_SIZE(PCI_NORMAL_HEADER_TYPE,
  631. + PCI_NORMAL_LATENCY_TIMER);
  632. break;
  633. case PCI_BAR0_REG:
  634. _rdmsr(GLCP_MSR_REG(GLCP_SOFT_COM), &hi, &lo);
  635. if (lo & SOFT_BAR_EHCI_FLAG) {
  636. - conf_data = CS5536_EHCI_RANGE |
  637. + cfg = CS5536_EHCI_RANGE |
  638. PCI_BASE_ADDRESS_SPACE_MEMORY;
  639. lo &= ~SOFT_BAR_EHCI_FLAG;
  640. _wrmsr(GLCP_MSR_REG(GLCP_SOFT_COM), hi, lo);
  641. } else {
  642. _rdmsr(USB_MSR_REG(USB_EHCI), &hi, &lo);
  643. - conf_data = lo & 0xfffff000;
  644. + cfg = lo & 0xfffff000;
  645. }
  646. break;
  647. case PCI_CARDBUS_CIS:
  648. - conf_data = PCI_CARDBUS_CIS_POINTER;
  649. + cfg = PCI_CARDBUS_CIS_POINTER;
  650. break;
  651. case PCI_SUBSYSTEM_VENDOR_ID:
  652. - conf_data =
  653. - CFG_PCI_VENDOR_ID(CS5536_EHCI_SUB_ID, CS5536_SUB_VENDOR_ID);
  654. + cfg = CFG_PCI_VENDOR_ID(CS5536_EHCI_SUB_ID,
  655. + CS5536_SUB_VENDOR_ID);
  656. break;
  657. case PCI_ROM_ADDRESS:
  658. - conf_data = PCI_EXPANSION_ROM_BAR;
  659. + cfg = PCI_EXPANSION_ROM_BAR;
  660. break;
  661. case PCI_CAPABILITY_LIST:
  662. - conf_data = PCI_CAPLIST_USB_POINTER;
  663. + cfg = PCI_CAPLIST_USB_POINTER;
  664. break;
  665. case PCI_INTERRUPT_LINE:
  666. - conf_data =
  667. - CFG_PCI_INTERRUPT_LINE(PCI_DEFAULT_PIN, CS5536_USB_INTR);
  668. + cfg = CFG_PCI_INTERRUPT_LINE(PCI_DEFAULT_PIN, CS5536_USB_INTR);
  669. break;
  670. case PCI_EHCI_LEGSMIEN_REG:
  671. _rdmsr(USB_MSR_REG(USB_EHCI), &hi, &lo);
  672. - conf_data = (hi & 0x003f0000) >> 16;
  673. + cfg = (hi & 0x003f0000) >> 16;
  674. break;
  675. case PCI_EHCI_LEGSMISTS_REG:
  676. _rdmsr(USB_MSR_REG(USB_EHCI), &hi, &lo);
  677. - conf_data = (hi & 0x3f000000) >> 24;
  678. + cfg = (hi & 0x3f000000) >> 24;
  679. break;
  680. case PCI_EHCI_FLADJ_REG:
  681. _rdmsr(USB_MSR_REG(USB_EHCI), &hi, &lo);
  682. - conf_data = hi & 0x00003f00;
  683. + cfg = hi & 0x00003f00;
  684. break;
  685. default:
  686. break;
  687. }
  688. - return conf_data;
  689. + return cfg;
  690. }
  691. diff -Nur linux-2.6.37.orig/arch/mips/loongson/common/cs5536/cs5536_ide.c linux-2.6.37/arch/mips/loongson/common/cs5536/cs5536_ide.c
  692. --- linux-2.6.37.orig/arch/mips/loongson/common/cs5536/cs5536_ide.c 2011-01-05 01:50:19.000000000 +0100
  693. +++ linux-2.6.37/arch/mips/loongson/common/cs5536/cs5536_ide.c 2011-01-11 20:44:43.000000000 +0100
  694. @@ -18,7 +18,7 @@
  695. void pci_ide_write_reg(int reg, u32 value)
  696. {
  697. - u32 hi = 0, lo = value;
  698. + u32 hi, lo;
  699. switch (reg) {
  700. case PCI_COMMAND:
  701. @@ -72,26 +72,16 @@
  702. _wrmsr(IDE_MSR_REG(IDE_CFG), hi, lo);
  703. }
  704. break;
  705. - case PCI_IDE_DTC_REG:
  706. - _rdmsr(IDE_MSR_REG(IDE_DTC), &hi, &lo);
  707. - lo = value;
  708. - _wrmsr(IDE_MSR_REG(IDE_DTC), hi, lo);
  709. - break;
  710. - case PCI_IDE_CAST_REG:
  711. - _rdmsr(IDE_MSR_REG(IDE_CAST), &hi, &lo);
  712. - lo = value;
  713. - _wrmsr(IDE_MSR_REG(IDE_CAST), hi, lo);
  714. - break;
  715. - case PCI_IDE_ETC_REG:
  716. - _rdmsr(IDE_MSR_REG(IDE_ETC), &hi, &lo);
  717. - lo = value;
  718. - _wrmsr(IDE_MSR_REG(IDE_ETC), hi, lo);
  719. - break;
  720. - case PCI_IDE_PM_REG:
  721. - _rdmsr(IDE_MSR_REG(IDE_INTERNAL_PM), &hi, &lo);
  722. - lo = value;
  723. - _wrmsr(IDE_MSR_REG(IDE_INTERNAL_PM), hi, lo);
  724. - break;
  725. +#define SET_PCI_IDE_REG(r) \
  726. + case PCI_IDE_##r##_REG: \
  727. + _rdmsr(IDE_MSR_REG(IDE_##r), &hi, &lo); \
  728. + lo = value; \
  729. + _wrmsr(IDE_MSR_REG(IDE_##r), hi, lo); \
  730. + break;
  731. + SET_PCI_IDE_REG(DTC)
  732. + SET_PCI_IDE_REG(CAST)
  733. + SET_PCI_IDE_REG(ETC)
  734. + SET_PCI_IDE_REG(PM)
  735. default:
  736. break;
  737. }
  738. @@ -99,94 +89,82 @@
  739. u32 pci_ide_read_reg(int reg)
  740. {
  741. - u32 conf_data = 0;
  742. + u32 cfg = 0;
  743. u32 hi, lo;
  744. switch (reg) {
  745. case PCI_VENDOR_ID:
  746. - conf_data =
  747. - CFG_PCI_VENDOR_ID(CS5536_IDE_DEVICE_ID, CS5536_VENDOR_ID);
  748. + cfg = CFG_PCI_VENDOR_ID(CS5536_IDE_DEVICE_ID,
  749. + CS5536_VENDOR_ID);
  750. break;
  751. case PCI_COMMAND:
  752. _rdmsr(IDE_MSR_REG(IDE_IO_BAR), &hi, &lo);
  753. if (lo & 0xfffffff0)
  754. - conf_data |= PCI_COMMAND_IO;
  755. + cfg |= PCI_COMMAND_IO;
  756. _rdmsr(GLIU_MSR_REG(GLIU_PAE), &hi, &lo);
  757. if ((lo & 0x30) == 0x30)
  758. - conf_data |= PCI_COMMAND_MASTER;
  759. + cfg |= PCI_COMMAND_MASTER;
  760. break;
  761. case PCI_STATUS:
  762. - conf_data |= PCI_STATUS_66MHZ;
  763. - conf_data |= PCI_STATUS_FAST_BACK;
  764. + cfg |= PCI_STATUS_66MHZ;
  765. + cfg |= PCI_STATUS_FAST_BACK;
  766. _rdmsr(SB_MSR_REG(SB_ERROR), &hi, &lo);
  767. if (lo & SB_PARE_ERR_FLAG)
  768. - conf_data |= PCI_STATUS_PARITY;
  769. - conf_data |= PCI_STATUS_DEVSEL_MEDIUM;
  770. + cfg |= PCI_STATUS_PARITY;
  771. + cfg |= PCI_STATUS_DEVSEL_MEDIUM;
  772. break;
  773. case PCI_CLASS_REVISION:
  774. _rdmsr(IDE_MSR_REG(IDE_CAP), &hi, &lo);
  775. - conf_data = lo & 0x000000ff;
  776. - conf_data |= (CS5536_IDE_CLASS_CODE << 8);
  777. + cfg = lo & 0x000000ff;
  778. + cfg |= (CS5536_IDE_CLASS_CODE << 8);
  779. break;
  780. case PCI_CACHE_LINE_SIZE:
  781. _rdmsr(SB_MSR_REG(SB_CTRL), &hi, &lo);
  782. hi &= 0x000000f8;
  783. - conf_data = CFG_PCI_CACHE_LINE_SIZE(PCI_NORMAL_HEADER_TYPE, hi);
  784. + cfg = CFG_PCI_CACHE_LINE_SIZE(PCI_NORMAL_HEADER_TYPE, hi);
  785. break;
  786. case PCI_BAR4_REG:
  787. _rdmsr(GLCP_MSR_REG(GLCP_SOFT_COM), &hi, &lo);
  788. if (lo & SOFT_BAR_IDE_FLAG) {
  789. - conf_data = CS5536_IDE_RANGE |
  790. + cfg = CS5536_IDE_RANGE |
  791. PCI_BASE_ADDRESS_SPACE_IO;
  792. lo &= ~SOFT_BAR_IDE_FLAG;
  793. _wrmsr(GLCP_MSR_REG(GLCP_SOFT_COM), hi, lo);
  794. } else {
  795. _rdmsr(IDE_MSR_REG(IDE_IO_BAR), &hi, &lo);
  796. - conf_data = lo & 0xfffffff0;
  797. - conf_data |= 0x01;
  798. - conf_data &= ~0x02;
  799. + cfg = lo & 0xfffffff0;
  800. + cfg |= 0x01;
  801. + cfg &= ~0x02;
  802. }
  803. break;
  804. case PCI_CARDBUS_CIS:
  805. - conf_data = PCI_CARDBUS_CIS_POINTER;
  806. + cfg = PCI_CARDBUS_CIS_POINTER;
  807. break;
  808. case PCI_SUBSYSTEM_VENDOR_ID:
  809. - conf_data =
  810. - CFG_PCI_VENDOR_ID(CS5536_IDE_SUB_ID, CS5536_SUB_VENDOR_ID);
  811. + cfg = CFG_PCI_VENDOR_ID(CS5536_IDE_SUB_ID,
  812. + CS5536_SUB_VENDOR_ID);
  813. break;
  814. case PCI_ROM_ADDRESS:
  815. - conf_data = PCI_EXPANSION_ROM_BAR;
  816. + cfg = PCI_EXPANSION_ROM_BAR;
  817. break;
  818. case PCI_CAPABILITY_LIST:
  819. - conf_data = PCI_CAPLIST_POINTER;
  820. + cfg = PCI_CAPLIST_POINTER;
  821. break;
  822. case PCI_INTERRUPT_LINE:
  823. - conf_data =
  824. - CFG_PCI_INTERRUPT_LINE(PCI_DEFAULT_PIN, CS5536_IDE_INTR);
  825. - break;
  826. - case PCI_IDE_CFG_REG:
  827. - _rdmsr(IDE_MSR_REG(IDE_CFG), &hi, &lo);
  828. - conf_data = lo;
  829. - break;
  830. - case PCI_IDE_DTC_REG:
  831. - _rdmsr(IDE_MSR_REG(IDE_DTC), &hi, &lo);
  832. - conf_data = lo;
  833. - break;
  834. - case PCI_IDE_CAST_REG:
  835. - _rdmsr(IDE_MSR_REG(IDE_CAST), &hi, &lo);
  836. - conf_data = lo;
  837. - break;
  838. - case PCI_IDE_ETC_REG:
  839. - _rdmsr(IDE_MSR_REG(IDE_ETC), &hi, &lo);
  840. - conf_data = lo;
  841. - break;
  842. - case PCI_IDE_PM_REG:
  843. - _rdmsr(IDE_MSR_REG(IDE_INTERNAL_PM), &hi, &lo);
  844. - conf_data = lo;
  845. + cfg = CFG_PCI_INTERRUPT_LINE(PCI_DEFAULT_PIN, CS5536_IDE_INTR);
  846. break;
  847. +#define GET_PCI_IDE_REG(r) \
  848. + case PCI_IDE_##r##_REG: \
  849. + _rdmsr(IDE_MSR_REG(IDE_##r), &hi, &cfg); \
  850. + break;
  851. + GET_PCI_IDE_REG(CFG)
  852. + GET_PCI_IDE_REG(DTC)
  853. + GET_PCI_IDE_REG(CAST)
  854. + GET_PCI_IDE_REG(ETC)
  855. + GET_PCI_IDE_REG(PM)
  856. default:
  857. break;
  858. }
  859. - return conf_data;
  860. + return cfg;
  861. }
  862. diff -Nur linux-2.6.37.orig/arch/mips/loongson/common/cs5536/cs5536_ohci.c linux-2.6.37/arch/mips/loongson/common/cs5536/cs5536_ohci.c
  863. --- linux-2.6.37.orig/arch/mips/loongson/common/cs5536/cs5536_ohci.c 2011-01-05 01:50:19.000000000 +0100
  864. +++ linux-2.6.37/arch/mips/loongson/common/cs5536/cs5536_ohci.c 2011-01-11 20:44:43.000000000 +0100
  865. @@ -18,7 +18,7 @@
  866. void pci_ohci_write_reg(int reg, u32 value)
  867. {
  868. - u32 hi = 0, lo = value;
  869. + u32 hi, lo;
  870. switch (reg) {
  871. case PCI_COMMAND:
  872. @@ -73,77 +73,75 @@
  873. u32 pci_ohci_read_reg(int reg)
  874. {
  875. - u32 conf_data = 0;
  876. + u32 cfg = 0;
  877. u32 hi, lo;
  878. switch (reg) {
  879. case PCI_VENDOR_ID:
  880. - conf_data =
  881. - CFG_PCI_VENDOR_ID(CS5536_OHCI_DEVICE_ID, CS5536_VENDOR_ID);
  882. + cfg = CFG_PCI_VENDOR_ID(CS5536_OHCI_DEVICE_ID,
  883. + CS5536_VENDOR_ID);
  884. break;
  885. case PCI_COMMAND:
  886. _rdmsr(USB_MSR_REG(USB_OHCI), &hi, &lo);
  887. if (hi & PCI_COMMAND_MASTER)
  888. - conf_data |= PCI_COMMAND_MASTER;
  889. + cfg |= PCI_COMMAND_MASTER;
  890. if (hi & PCI_COMMAND_MEMORY)
  891. - conf_data |= PCI_COMMAND_MEMORY;
  892. + cfg |= PCI_COMMAND_MEMORY;
  893. break;
  894. case PCI_STATUS:
  895. - conf_data |= PCI_STATUS_66MHZ;
  896. - conf_data |= PCI_STATUS_FAST_BACK;
  897. + cfg |= PCI_STATUS_66MHZ;
  898. + cfg |= PCI_STATUS_FAST_BACK;
  899. _rdmsr(SB_MSR_REG(SB_ERROR), &hi, &lo);
  900. if (lo & SB_PARE_ERR_FLAG)
  901. - conf_data |= PCI_STATUS_PARITY;
  902. - conf_data |= PCI_STATUS_DEVSEL_MEDIUM;
  903. + cfg |= PCI_STATUS_PARITY;
  904. + cfg |= PCI_STATUS_DEVSEL_MEDIUM;
  905. break;
  906. case PCI_CLASS_REVISION:
  907. _rdmsr(USB_MSR_REG(USB_CAP), &hi, &lo);
  908. - conf_data = lo & 0x000000ff;
  909. - conf_data |= (CS5536_OHCI_CLASS_CODE << 8);
  910. + cfg = lo & 0x000000ff;
  911. + cfg |= (CS5536_OHCI_CLASS_CODE << 8);
  912. break;
  913. case PCI_CACHE_LINE_SIZE:
  914. - conf_data =
  915. - CFG_PCI_CACHE_LINE_SIZE(PCI_NORMAL_HEADER_TYPE,
  916. - PCI_NORMAL_LATENCY_TIMER);
  917. + cfg = CFG_PCI_CACHE_LINE_SIZE(PCI_NORMAL_HEADER_TYPE,
  918. + PCI_NORMAL_LATENCY_TIMER);
  919. break;
  920. case PCI_BAR0_REG:
  921. _rdmsr(GLCP_MSR_REG(GLCP_SOFT_COM), &hi, &lo);
  922. if (lo & SOFT_BAR_OHCI_FLAG) {
  923. - conf_data = CS5536_OHCI_RANGE |
  924. + cfg = CS5536_OHCI_RANGE |
  925. PCI_BASE_ADDRESS_SPACE_MEMORY;
  926. lo &= ~SOFT_BAR_OHCI_FLAG;
  927. _wrmsr(GLCP_MSR_REG(GLCP_SOFT_COM), hi, lo);
  928. } else {
  929. _rdmsr(USB_MSR_REG(USB_OHCI), &hi, &lo);
  930. - conf_data = lo & 0xffffff00;
  931. - conf_data &= ~0x0000000f; /* 32bit mem */
  932. + cfg = lo & 0xffffff00;
  933. + cfg &= ~0x0000000f; /* 32bit mem */
  934. }
  935. break;
  936. case PCI_CARDBUS_CIS:
  937. - conf_data = PCI_CARDBUS_CIS_POINTER;
  938. + cfg = PCI_CARDBUS_CIS_POINTER;
  939. break;
  940. case PCI_SUBSYSTEM_VENDOR_ID:
  941. - conf_data =
  942. - CFG_PCI_VENDOR_ID(CS5536_OHCI_SUB_ID, CS5536_SUB_VENDOR_ID);
  943. + cfg = CFG_PCI_VENDOR_ID(CS5536_OHCI_SUB_ID,
  944. + CS5536_SUB_VENDOR_ID);
  945. break;
  946. case PCI_ROM_ADDRESS:
  947. - conf_data = PCI_EXPANSION_ROM_BAR;
  948. + cfg = PCI_EXPANSION_ROM_BAR;
  949. break;
  950. case PCI_CAPABILITY_LIST:
  951. - conf_data = PCI_CAPLIST_USB_POINTER;
  952. + cfg = PCI_CAPLIST_USB_POINTER;
  953. break;
  954. case PCI_INTERRUPT_LINE:
  955. - conf_data =
  956. - CFG_PCI_INTERRUPT_LINE(PCI_DEFAULT_PIN, CS5536_USB_INTR);
  957. + cfg = CFG_PCI_INTERRUPT_LINE(PCI_DEFAULT_PIN, CS5536_USB_INTR);
  958. break;
  959. case PCI_OHCI_INT_REG:
  960. _rdmsr(DIVIL_MSR_REG(PIC_YSEL_LOW), &hi, &lo);
  961. if ((lo & 0x00000f00) == CS5536_USB_INTR)
  962. - conf_data = 1;
  963. + cfg = 1;
  964. break;
  965. default:
  966. break;
  967. }
  968. - return conf_data;
  969. + return cfg;
  970. }
  971. diff -Nur linux-2.6.37.orig/arch/mips/loongson/common/mtd.c linux-2.6.37/arch/mips/loongson/common/mtd.c
  972. --- linux-2.6.37.orig/arch/mips/loongson/common/mtd.c 1970-01-01 01:00:00.000000000 +0100
  973. +++ linux-2.6.37/arch/mips/loongson/common/mtd.c 2011-01-11 20:44:43.000000000 +0100
  974. @@ -0,0 +1,91 @@
  975. +/*
  976. + * Driver for flushing/dumping ROM of PMON on loongson family machines
  977. + *
  978. + * Copyright (C) 2008-2009 Lemote Inc.
  979. + * Author: Yan Hua <yanh@lemote.com>
  980. + *
  981. + * This program is free software; you can redistribute it and/or modify it
  982. + * under the terms of the GNU General Public License as published by the
  983. + * Free Software Foundation; either version 2 of the License, or (at your
  984. + * option) any later version.
  985. + */
  986. +
  987. +#include <linux/module.h>
  988. +#include <linux/types.h>
  989. +#include <linux/kernel.h>
  990. +#include <linux/init.h>
  991. +#include <linux/mtd/mtd.h>
  992. +#include <linux/mtd/map.h>
  993. +#include <linux/mtd/partitions.h>
  994. +
  995. +#include <asm/io.h>
  996. +
  997. +#include <loongson.h>
  998. +
  999. +#define FLASH_PHYS_ADDR LOONGSON_BOOT_BASE
  1000. +#define FLASH_SIZE 0x080000
  1001. +
  1002. +#define FLASH_PARTITION0_ADDR 0x00000000
  1003. +#define FLASH_PARTITION0_SIZE 0x00080000
  1004. +
  1005. +struct map_info flash_map = {
  1006. + .name = "flash device",
  1007. + .size = FLASH_SIZE,
  1008. + .bankwidth = 1,
  1009. +};
  1010. +
  1011. +struct mtd_partition flash_parts[] = {
  1012. + {
  1013. + .name = "Bootloader",
  1014. + .offset = FLASH_PARTITION0_ADDR,
  1015. + .size = FLASH_PARTITION0_SIZE},
  1016. +};
  1017. +
  1018. +#define PARTITION_COUNT ARRAY_SIZE(flash_parts)
  1019. +
  1020. +static struct mtd_info *mymtd;
  1021. +
  1022. +int __init init_flash(void)
  1023. +{
  1024. + printk(KERN_NOTICE "flash device: %x at %x\n",
  1025. + FLASH_SIZE, FLASH_PHYS_ADDR);
  1026. +
  1027. + flash_map.phys = FLASH_PHYS_ADDR;
  1028. + flash_map.virt = ioremap(FLASH_PHYS_ADDR, FLASH_SIZE);
  1029. +
  1030. + if (!flash_map.virt) {
  1031. + printk(KERN_NOTICE "Failed to ioremap\n");
  1032. + return -EIO;
  1033. + }
  1034. +
  1035. + simple_map_init(&flash_map);
  1036. +
  1037. + mymtd = do_map_probe("cfi_probe", &flash_map);
  1038. + if (mymtd) {
  1039. + add_mtd_partitions(mymtd, flash_parts, PARTITION_COUNT);
  1040. + printk(KERN_NOTICE "pmon flash device initialized\n");
  1041. + return 0;
  1042. + }
  1043. +
  1044. + iounmap((void *)flash_map.virt);
  1045. + return -ENXIO;
  1046. +}
  1047. +
  1048. +static void __exit cleanup_flash(void)
  1049. +{
  1050. + if (mymtd) {
  1051. + del_mtd_partitions(mymtd);
  1052. + map_destroy(mymtd);
  1053. + }
  1054. + if (flash_map.virt) {
  1055. + iounmap((void *)flash_map.virt);
  1056. + flash_map.virt = 0;
  1057. + }
  1058. +}
  1059. +
  1060. +module_init(init_flash);
  1061. +module_exit(cleanup_flash);
  1062. +
  1063. +MODULE_LICENSE("GPL");
  1064. +MODULE_AUTHOR("Yanhua <yanh@lemote.com>");
  1065. +MODULE_DESCRIPTION("MTD driver for pmon flushing/dumping");
  1066. diff -Nur linux-2.6.37.orig/arch/mips/loongson/lemote-2f/Makefile linux-2.6.37/arch/mips/loongson/lemote-2f/Makefile
  1067. --- linux-2.6.37.orig/arch/mips/loongson/lemote-2f/Makefile 2011-01-05 01:50:19.000000000 +0100
  1068. +++ linux-2.6.37/arch/mips/loongson/lemote-2f/Makefile 2011-01-11 20:44:43.000000000 +0100
  1069. @@ -2,7 +2,7 @@
  1070. # Makefile for lemote loongson2f family machines
  1071. #
  1072. -obj-y += machtype.o irq.o reset.o ec_kb3310b.o
  1073. +obj-y += machtype.o irq.o reset.o ec_kb3310b.o platform.o
  1074. #
  1075. # Suspend Support
  1076. diff -Nur linux-2.6.37.orig/arch/mips/loongson/lemote-2f/ec_kb3310b.c linux-2.6.37/arch/mips/loongson/lemote-2f/ec_kb3310b.c
  1077. --- linux-2.6.37.orig/arch/mips/loongson/lemote-2f/ec_kb3310b.c 2011-01-05 01:50:19.000000000 +0100
  1078. +++ linux-2.6.37/arch/mips/loongson/lemote-2f/ec_kb3310b.c 2011-01-11 20:44:43.000000000 +0100
  1079. @@ -14,7 +14,7 @@
  1080. #include <linux/spinlock.h>
  1081. #include <linux/delay.h>
  1082. -#include "ec_kb3310b.h"
  1083. +#include <ec_kb3310b.h>
  1084. static DEFINE_SPINLOCK(index_access_lock);
  1085. static DEFINE_SPINLOCK(port_access_lock);
  1086. @@ -78,12 +78,9 @@
  1087. spin_unlock_irqrestore(&port_access_lock, flags);
  1088. if (timeout <= 0) {
  1089. - printk(KERN_ERR "%s: deadable error : timeout...\n", __func__);
  1090. + pr_err("%s: deadable error : timeout...\n", __func__);
  1091. ret = -EINVAL;
  1092. - } else
  1093. - printk(KERN_INFO
  1094. - "(%x/%d)ec issued command %d status : 0x%x\n",
  1095. - timeout, EC_CMD_TIMEOUT - timeout, cmd, status);
  1096. + }
  1097. return ret;
  1098. }
  1099. @@ -118,8 +115,7 @@
  1100. udelay(EC_REG_DELAY);
  1101. }
  1102. if (timeout <= 0) {
  1103. - pr_info("%s: get event number timeout.\n", __func__);
  1104. -
  1105. + pr_err("%s: get event number timeout.\n", __func__);
  1106. return -EINVAL;
  1107. }
  1108. value = inb(EC_DAT_PORT);
  1109. diff -Nur linux-2.6.37.orig/arch/mips/loongson/lemote-2f/ec_kb3310b.h linux-2.6.37/arch/mips/loongson/lemote-2f/ec_kb3310b.h
  1110. --- linux-2.6.37.orig/arch/mips/loongson/lemote-2f/ec_kb3310b.h 2011-01-05 01:50:19.000000000 +0100
  1111. +++ linux-2.6.37/arch/mips/loongson/lemote-2f/ec_kb3310b.h 1970-01-01 01:00:00.000000000 +0100
  1112. @@ -1,188 +0,0 @@
  1113. -/*
  1114. - * KB3310B Embedded Controller
  1115. - *
  1116. - * Copyright (C) 2008 Lemote Inc.
  1117. - * Author: liujl <liujl@lemote.com>, 2008-03-14
  1118. - *
  1119. - * This program is free software; you can redistribute it and/or modify
  1120. - * it under the terms of the GNU General Public License as published by
  1121. - * the Free Software Foundation; either version 2 of the License, or
  1122. - * (at your option) any later version.
  1123. - */
  1124. -
  1125. -#ifndef _EC_KB3310B_H
  1126. -#define _EC_KB3310B_H
  1127. -
  1128. -extern unsigned char ec_read(unsigned short addr);
  1129. -extern void ec_write(unsigned short addr, unsigned char val);
  1130. -extern int ec_query_seq(unsigned char cmd);
  1131. -extern int ec_query_event_num(void);
  1132. -extern int ec_get_event_num(void);
  1133. -
  1134. -typedef int (*sci_handler) (int status);
  1135. -extern sci_handler yeeloong_report_lid_status;
  1136. -
  1137. -#define SCI_IRQ_NUM 0x0A
  1138. -
  1139. -/*
  1140. - * The following registers are determined by the EC index configuration.
  1141. - * 1, fill the PORT_HIGH as EC register high part.
  1142. - * 2, fill the PORT_LOW as EC register low part.
  1143. - * 3, fill the PORT_DATA as EC register write data or get the data from it.
  1144. - */
  1145. -#define EC_IO_PORT_HIGH 0x0381
  1146. -#define EC_IO_PORT_LOW 0x0382
  1147. -#define EC_IO_PORT_DATA 0x0383
  1148. -
  1149. -/*
  1150. - * EC delay time is 500us for register and status access
  1151. - */
  1152. -#define EC_REG_DELAY 500 /* unit : us */
  1153. -#define EC_CMD_TIMEOUT 0x1000
  1154. -
  1155. -/*
  1156. - * EC access port for SCI communication
  1157. - */
  1158. -#define EC_CMD_PORT 0x66
  1159. -#define EC_STS_PORT 0x66
  1160. -#define EC_DAT_PORT 0x62
  1161. -#define CMD_INIT_IDLE_MODE 0xdd
  1162. -#define CMD_EXIT_IDLE_MODE 0xdf
  1163. -#define CMD_INIT_RESET_MODE 0xd8
  1164. -#define CMD_REBOOT_SYSTEM 0x8c
  1165. -#define CMD_GET_EVENT_NUM 0x84
  1166. -#define CMD_PROGRAM_PIECE 0xda
  1167. -
  1168. -/* temperature & fan registers */
  1169. -#define REG_TEMPERATURE_VALUE 0xF458
  1170. -#define REG_FAN_AUTO_MAN_SWITCH 0xF459
  1171. -#define BIT_FAN_AUTO 0
  1172. -#define BIT_FAN_MANUAL 1
  1173. -#define REG_FAN_CONTROL 0xF4D2
  1174. -#define BIT_FAN_CONTROL_ON (1 << 0)
  1175. -#define BIT_FAN_CONTROL_OFF (0 << 0)
  1176. -#define REG_FAN_STATUS 0xF4DA
  1177. -#define BIT_FAN_STATUS_ON (1 << 0)
  1178. -#define BIT_FAN_STATUS_OFF (0 << 0)
  1179. -#define REG_FAN_SPEED_HIGH 0xFE22
  1180. -#define REG_FAN_SPEED_LOW 0xFE23
  1181. -#define REG_FAN_SPEED_LEVEL 0xF4CC
  1182. -/* fan speed divider */
  1183. -#define FAN_SPEED_DIVIDER 480000 /* (60*1000*1000/62.5/2)*/
  1184. -
  1185. -/* battery registers */
  1186. -#define REG_BAT_DESIGN_CAP_HIGH 0xF77D
  1187. -#define REG_BAT_DESIGN_CAP_LOW 0xF77E
  1188. -#define REG_BAT_FULLCHG_CAP_HIGH 0xF780
  1189. -#define REG_BAT_FULLCHG_CAP_LOW 0xF781
  1190. -#define REG_BAT_DESIGN_VOL_HIGH 0xF782
  1191. -#define REG_BAT_DESIGN_VOL_LOW 0xF783
  1192. -#define REG_BAT_CURRENT_HIGH 0xF784
  1193. -#define REG_BAT_CURRENT_LOW 0xF785
  1194. -#define REG_BAT_VOLTAGE_HIGH 0xF786
  1195. -#define REG_BAT_VOLTAGE_LOW 0xF787
  1196. -#define REG_BAT_TEMPERATURE_HIGH 0xF788
  1197. -#define REG_BAT_TEMPERATURE_LOW 0xF789
  1198. -#define REG_BAT_RELATIVE_CAP_HIGH 0xF492
  1199. -#define REG_BAT_RELATIVE_CAP_LOW 0xF493
  1200. -#define REG_BAT_VENDOR 0xF4C4
  1201. -#define FLAG_BAT_VENDOR_SANYO 0x01
  1202. -#define FLAG_BAT_VENDOR_SIMPLO 0x02
  1203. -#define REG_BAT_CELL_COUNT 0xF4C6
  1204. -#define FLAG_BAT_CELL_3S1P 0x03
  1205. -#define FLAG_BAT_CELL_3S2P 0x06
  1206. -#define REG_BAT_CHARGE 0xF4A2
  1207. -#define FLAG_BAT_CHARGE_DISCHARGE 0x01
  1208. -#define FLAG_BAT_CHARGE_CHARGE 0x02
  1209. -#define FLAG_BAT_CHARGE_ACPOWER 0x00
  1210. -#define REG_BAT_STATUS 0xF4B0
  1211. -#define BIT_BAT_STATUS_LOW (1 << 5)
  1212. -#define BIT_BAT_STATUS_DESTROY (1 << 2)
  1213. -#define BIT_BAT_STATUS_FULL (1 << 1)
  1214. -#define BIT_BAT_STATUS_IN (1 << 0)
  1215. -#define REG_BAT_CHARGE_STATUS 0xF4B1
  1216. -#define BIT_BAT_CHARGE_STATUS_OVERTEMP (1 << 2)
  1217. -#define BIT_BAT_CHARGE_STATUS_PRECHG (1 << 1)
  1218. -#define REG_BAT_STATE 0xF482
  1219. -#define BIT_BAT_STATE_CHARGING (1 << 1)
  1220. -#define BIT_BAT_STATE_DISCHARGING (1 << 0)
  1221. -#define REG_BAT_POWER 0xF440
  1222. -#define BIT_BAT_POWER_S3 (1 << 2)
  1223. -#define BIT_BAT_POWER_ON (1 << 1)
  1224. -#define BIT_BAT_POWER_ACIN (1 << 0)
  1225. -
  1226. -/* other registers */
  1227. -/* Audio: rd/wr */
  1228. -#define REG_AUDIO_VOLUME 0xF46C
  1229. -#define REG_AUDIO_MUTE 0xF4E7
  1230. -#define REG_AUDIO_BEEP 0xF4D0
  1231. -/* USB port power or not: rd/wr */
  1232. -#define REG_USB0_FLAG 0xF461
  1233. -#define REG_USB1_FLAG 0xF462
  1234. -#define REG_USB2_FLAG 0xF463
  1235. -#define BIT_USB_FLAG_ON 1
  1236. -#define BIT_USB_FLAG_OFF 0
  1237. -/* LID */
  1238. -#define REG_LID_DETECT 0xF4BD
  1239. -#define BIT_LID_DETECT_ON 1
  1240. -#define BIT_LID_DETECT_OFF 0
  1241. -/* CRT */
  1242. -#define REG_CRT_DETECT 0xF4AD
  1243. -#define BIT_CRT_DETECT_PLUG 1
  1244. -#define BIT_CRT_DETECT_UNPLUG 0
  1245. -/* LCD backlight brightness adjust: 9 levels */
  1246. -#define REG_DISPLAY_BRIGHTNESS 0xF4F5
  1247. -/* Black screen Status */
  1248. -#define BIT_DISPLAY_LCD_ON 1
  1249. -#define BIT_DISPLAY_LCD_OFF 0
  1250. -/* LCD backlight control: off/restore */
  1251. -#define REG_BACKLIGHT_CTRL 0xF7BD
  1252. -#define BIT_BACKLIGHT_ON 1
  1253. -#define BIT_BACKLIGHT_OFF 0
  1254. -/* Reset the machine auto-clear: rd/wr */
  1255. -#define REG_RESET 0xF4EC
  1256. -#define BIT_RESET_ON 1
  1257. -/* Light the led: rd/wr */
  1258. -#define REG_LED 0xF4C8
  1259. -#define BIT_LED_RED_POWER (1 << 0)
  1260. -#define BIT_LED_ORANGE_POWER (1 << 1)
  1261. -#define BIT_LED_GREEN_CHARGE (1 << 2)
  1262. -#define BIT_LED_RED_CHARGE (1 << 3)
  1263. -#define BIT_LED_NUMLOCK (1 << 4)
  1264. -/* Test led mode, all led on/off */
  1265. -#define REG_LED_TEST 0xF4C2
  1266. -#define BIT_LED_TEST_IN 1
  1267. -#define BIT_LED_TEST_OUT 0
  1268. -/* Camera on/off */
  1269. -#define REG_CAMERA_STATUS 0xF46A
  1270. -#define BIT_CAMERA_STATUS_ON 1
  1271. -#define BIT_CAMERA_STATUS_OFF 0
  1272. -#define REG_CAMERA_CONTROL 0xF7B7
  1273. -#define BIT_CAMERA_CONTROL_OFF 0
  1274. -#define BIT_CAMERA_CONTROL_ON 1
  1275. -/* Wlan Status */
  1276. -#define REG_WLAN 0xF4FA
  1277. -#define BIT_WLAN_ON 1
  1278. -#define BIT_WLAN_OFF 0
  1279. -#define REG_DISPLAY_LCD 0xF79F
  1280. -
  1281. -/* SCI Event Number from EC */
  1282. -enum {
  1283. - EVENT_LID = 0x23, /* LID open/close */
  1284. - EVENT_DISPLAY_TOGGLE, /* Fn+F3 for display switch */
  1285. - EVENT_SLEEP, /* Fn+F1 for entering sleep mode */
  1286. - EVENT_OVERTEMP, /* Over-temperature happened */
  1287. - EVENT_CRT_DETECT, /* CRT is connected */
  1288. - EVENT_CAMERA, /* Camera on/off */
  1289. - EVENT_USB_OC2, /* USB2 Over Current occurred */
  1290. - EVENT_USB_OC0, /* USB0 Over Current occurred */
  1291. - EVENT_BLACK_SCREEN, /* Turn on/off backlight */
  1292. - EVENT_AUDIO_MUTE, /* Mute on/off */
  1293. - EVENT_DISPLAY_BRIGHTNESS,/* LCD backlight brightness adjust */
  1294. - EVENT_AC_BAT, /* AC & Battery relative issue */
  1295. - EVENT_AUDIO_VOLUME, /* Volume adjust */
  1296. - EVENT_WLAN, /* Wlan on/off */
  1297. - EVENT_END
  1298. -};
  1299. -
  1300. -#endif /* !_EC_KB3310B_H */
  1301. diff -Nur linux-2.6.37.orig/arch/mips/loongson/lemote-2f/platform.c linux-2.6.37/arch/mips/loongson/lemote-2f/platform.c
  1302. --- linux-2.6.37.orig/arch/mips/loongson/lemote-2f/platform.c 1970-01-01 01:00:00.000000000 +0100
  1303. +++ linux-2.6.37/arch/mips/loongson/lemote-2f/platform.c 2011-01-11 20:44:43.000000000 +0100
  1304. @@ -0,0 +1,48 @@
  1305. +/*
  1306. + * Copyright (C) 2009 Lemote Inc.
  1307. + * Author: Wu Zhangjin, wuzhangjin@gmail.com
  1308. + *
  1309. + * This program is free software; you can redistribute it and/or modify it
  1310. + * under the terms of the GNU General Public License as published by the
  1311. + * Free Software Foundation; either version 2 of the License, or (at your
  1312. + * option) any later version.
  1313. + */
  1314. +
  1315. +#include <linux/err.h>
  1316. +#include <linux/platform_device.h>
  1317. +
  1318. +#include <asm/bootinfo.h>
  1319. +
  1320. +static struct platform_device yeeloong_pdev = {
  1321. + .name = "yeeloong_laptop",
  1322. + .id = -1,
  1323. +};
  1324. +
  1325. +static struct platform_device lynloong_pdev = {
  1326. + .name = "lynloong_pc",
  1327. + .id = -1,
  1328. +};
  1329. +
  1330. +static int __init lemote2f_platform_init(void)
  1331. +{
  1332. + struct platform_device *pdev = NULL;
  1333. +
  1334. + switch (mips_machtype) {
  1335. + case MACH_LEMOTE_YL2F89:
  1336. + pdev = &yeeloong_pdev;
  1337. + break;
  1338. + case MACH_LEMOTE_LL2F:
  1339. + pdev = &lynloong_pdev;
  1340. + break;
  1341. + default:
  1342. + break;
  1343. +
  1344. + }
  1345. +
  1346. + if (pdev != NULL)
  1347. + return platform_device_register(pdev);
  1348. +
  1349. + return -ENODEV;
  1350. +}
  1351. +
  1352. +arch_initcall(lemote2f_platform_init);
  1353. diff -Nur linux-2.6.37.orig/arch/mips/loongson/lemote-2f/pm.c linux-2.6.37/arch/mips/loongson/lemote-2f/pm.c
  1354. --- linux-2.6.37.orig/arch/mips/loongson/lemote-2f/pm.c 2011-01-05 01:50:19.000000000 +0100
  1355. +++ linux-2.6.37/arch/mips/loongson/lemote-2f/pm.c 2011-01-11 20:44:43.000000000 +0100
  1356. @@ -23,7 +23,7 @@
  1357. #include <loongson.h>
  1358. #include <cs5536/cs5536_mfgpt.h>
  1359. -#include "ec_kb3310b.h"
  1360. +#include <ec_kb3310b.h>
  1361. #define I8042_KBD_IRQ 1
  1362. #define I8042_CTR_KBDINT 0x01
  1363. @@ -100,7 +100,7 @@
  1364. if (irq < 0)
  1365. return 0;
  1366. - printk(KERN_INFO "%s: irq = %d\n", __func__, irq);
  1367. + pr_info("%s: irq = %d\n", __func__, irq);
  1368. if (irq == I8042_KBD_IRQ)
  1369. return 1;
  1370. diff -Nur linux-2.6.37.orig/arch/mips/loongson/lemote-2f/reset.c linux-2.6.37/arch/mips/loongson/lemote-2f/reset.c
  1371. --- linux-2.6.37.orig/arch/mips/loongson/lemote-2f/reset.c 2011-01-05 01:50:19.000000000 +0100
  1372. +++ linux-2.6.37/arch/mips/loongson/lemote-2f/reset.c 2011-01-11 20:44:43.000000000 +0100
  1373. @@ -20,7 +20,7 @@
  1374. #include <loongson.h>
  1375. #include <cs5536/cs5536.h>
  1376. -#include "ec_kb3310b.h"
  1377. +#include <ec_kb3310b.h>
  1378. static void reset_cpu(void)
  1379. {
  1380. diff -Nur linux-2.6.37.orig/arch/mips/mm/dma-default.c linux-2.6.37/arch/mips/mm/dma-default.c
  1381. --- linux-2.6.37.orig/arch/mips/mm/dma-default.c 2011-01-05 01:50:19.000000000 +0100
  1382. +++ linux-2.6.37/arch/mips/mm/dma-default.c 2011-01-11 20:46:19.000000000 +0100
  1383. @@ -300,6 +300,20 @@
  1384. EXPORT_SYMBOL(dma_cache_sync);
  1385. +int __weak dma_mmap_coherent(struct device *dev, struct vm_area_struct *vma,
  1386. + void *cpu_addr, dma_addr_t handle, size_t size)
  1387. +{
  1388. + struct page *pg;
  1389. + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  1390. + cpu_addr = (void *)dma_addr_to_virt(dev, handle);
  1391. + pg = virt_to_page(cpu_addr);
  1392. + return remap_pfn_range(vma, vma->vm_start,
  1393. + page_to_pfn(pg) + vma->vm_pgoff,
  1394. + size, vma->vm_page_prot);
  1395. +}
  1396. +EXPORT_SYMBOL(dma_mmap_coherent);
  1397. +
  1398. +
  1399. static struct dma_map_ops mips_default_dma_map_ops = {
  1400. .alloc_coherent = mips_dma_alloc_coherent,
  1401. .free_coherent = mips_dma_free_coherent,
  1402. diff -Nur linux-2.6.37.orig/drivers/ide/ide-iops.c linux-2.6.37/drivers/ide/ide-iops.c
  1403. --- linux-2.6.37.orig/drivers/ide/ide-iops.c 2011-01-05 01:50:19.000000000 +0100
  1404. +++ linux-2.6.37/drivers/ide/ide-iops.c 2011-01-11 20:44:43.000000000 +0100
  1405. @@ -27,6 +27,8 @@
  1406. #include <asm/uaccess.h>
  1407. #include <asm/io.h>
  1408. +#include <asm/bootinfo.h>
  1409. +
  1410. void SELECT_MASK(ide_drive_t *drive, int mask)
  1411. {
  1412. const struct ide_port_ops *port_ops = drive->hwif->port_ops;
  1413. @@ -300,6 +302,9 @@
  1414. {
  1415. const char **list, *m = (char *)&drive->id[ATA_ID_PROD];
  1416. + if (mips_machtype != MACH_LEMOTE_YL2F89)
  1417. + return;
  1418. +
  1419. for (list = nien_quirk_list; *list != NULL; list++)
  1420. if (strstr(m, *list) != NULL) {
  1421. drive->dev_flags |= IDE_DFLAG_NIEN_QUIRK;
  1422. diff -Nur linux-2.6.37.orig/drivers/platform/Kconfig linux-2.6.37/drivers/platform/Kconfig
  1423. --- linux-2.6.37.orig/drivers/platform/Kconfig 2011-01-05 01:50:19.000000000 +0100
  1424. +++ linux-2.6.37/drivers/platform/Kconfig 2011-01-11 20:44:43.000000000 +0100
  1425. @@ -1,3 +1,7 @@
  1426. if X86
  1427. source "drivers/platform/x86/Kconfig"
  1428. endif
  1429. +
  1430. +if MIPS
  1431. +source "drivers/platform/mips/Kconfig"
  1432. +endif
  1433. diff -Nur linux-2.6.37.orig/drivers/platform/Makefile linux-2.6.37/drivers/platform/Makefile
  1434. --- linux-2.6.37.orig/drivers/platform/Makefile 2011-01-05 01:50:19.000000000 +0100
  1435. +++ linux-2.6.37/drivers/platform/Makefile 2011-01-11 20:44:43.000000000 +0100
  1436. @@ -3,3 +3,4 @@
  1437. #
  1438. obj-$(CONFIG_X86) += x86/
  1439. +obj-$(CONFIG_MIPS) += mips/
  1440. diff -Nur linux-2.6.37.orig/drivers/platform/mips/Kconfig linux-2.6.37/drivers/platform/mips/Kconfig
  1441. --- linux-2.6.37.orig/drivers/platform/mips/Kconfig 1970-01-01 01:00:00.000000000 +0100
  1442. +++ linux-2.6.37/drivers/platform/mips/Kconfig 2011-01-11 20:44:43.000000000 +0100
  1443. @@ -0,0 +1,43 @@
  1444. +#
  1445. +# MIPS Platform Specific Drivers
  1446. +#
  1447. +
  1448. +menuconfig MIPS_PLATFORM_DEVICES
  1449. + bool "MIPS Platform Specific Device Drivers"
  1450. + default y
  1451. + help
  1452. + Say Y here to get to see options for device drivers of various
  1453. + MIPS platforms, including vendor-specific netbook/laptop/pc extension
  1454. + drivers. This option alone does not add any kernel code.
  1455. +
  1456. + If you say N, all options in this submenu will be skipped and disabled.
  1457. +
  1458. +if MIPS_PLATFORM_DEVICES
  1459. +
  1460. +config LEMOTE_YEELOONG2F
  1461. + tristate "Lemote YeeLoong Laptop"
  1462. + depends on LEMOTE_MACH2F
  1463. + select BACKLIGHT_CLASS_DEVICE
  1464. + select POWER_SUPPLY
  1465. + select HWMON
  1466. + select VIDEO_OUTPUT_CONTROL
  1467. + select INPUT_SPARSEKMAP
  1468. + depends on INPUT
  1469. + help
  1470. + YeeLoong netbook is a mini laptop made by Lemote, which is basically
  1471. + compatible to FuLoong2F mini PC, but it has an extra Embedded
  1472. + Controller(kb3310b) for battery, hotkey, backlight, temperature and
  1473. + fan management.
  1474. +
  1475. +config LEMOTE_LYNLOONG2F
  1476. + tristate "Lemote LynLoong PC"
  1477. + depends on LEMOTE_MACH2F
  1478. + select BACKLIGHT_CLASS_DEVICE
  1479. + select VIDEO_OUTPUT_CONTROL
  1480. + help
  1481. + LynLoong PC is an AllINONE machine made by Lemote, which is basically
  1482. + compatible to FuLoong2F Mini PC, the only difference is that it has a
  1483. + size-fixed screen: 1360x768 with sisfb video driver. and also, it has
  1484. + its own specific suspend support.
  1485. +
  1486. +endif # MIPS_PLATFORM_DEVICES
  1487. diff -Nur linux-2.6.37.orig/drivers/platform/mips/Makefile linux-2.6.37/drivers/platform/mips/Makefile
  1488. --- linux-2.6.37.orig/drivers/platform/mips/Makefile 1970-01-01 01:00:00.000000000 +0100
  1489. +++ linux-2.6.37/drivers/platform/mips/Makefile 2011-01-11 20:44:43.000000000 +0100
  1490. @@ -0,0 +1,7 @@
  1491. +#
  1492. +# Makefile for MIPS Platform-Specific Drivers
  1493. +#
  1494. +
  1495. +obj-$(CONFIG_LEMOTE_YEELOONG2F) += yeeloong_laptop.o
  1496. +
  1497. +obj-$(CONFIG_LEMOTE_LYNLOONG2F) += lynloong_pc.o
  1498. diff -Nur linux-2.6.37.orig/drivers/platform/mips/lynloong_pc.c linux-2.6.37/drivers/platform/mips/lynloong_pc.c
  1499. --- linux-2.6.37.orig/drivers/platform/mips/lynloong_pc.c 1970-01-01 01:00:00.000000000 +0100
  1500. +++ linux-2.6.37/drivers/platform/mips/lynloong_pc.c 2011-01-11 20:44:43.000000000 +0100
  1501. @@ -0,0 +1,513 @@
  1502. +/*
  1503. + * Driver for LynLoong PC extras
  1504. + *
  1505. + * Copyright (C) 2009 Lemote Inc.
  1506. + * Author: Wu Zhangjin <wuzhangjin@gmail.com>, Xiang Yu <xiangy@lemote.com>
  1507. + *
  1508. + * This program is free software; you can redistribute it and/or modify
  1509. + * it under the terms of the GNU General Public License version 2 as
  1510. + * published by the Free Software Foundation.
  1511. + */
  1512. +
  1513. +#include <linux/err.h>
  1514. +#include <linux/platform_device.h>
  1515. +#include <linux/backlight.h> /* for backlight subdriver */
  1516. +#include <linux/fb.h>
  1517. +#include <linux/video_output.h> /* for video output subdriver */
  1518. +#include <linux/delay.h> /* for suspend support */
  1519. +
  1520. +#include <cs5536/cs5536.h>
  1521. +#include <cs5536/cs5536_mfgpt.h>
  1522. +
  1523. +#include <loongson.h>
  1524. +
  1525. +static u32 gpio_base, mfgpt_base;
  1526. +
  1527. +static void set_gpio_reg_high(int gpio, int reg)
  1528. +{
  1529. + u32 val;
  1530. +
  1531. + val = inl(gpio_base + reg);
  1532. + val |= (1 << gpio);
  1533. + val &= ~(1 << (16 + gpio));
  1534. + outl(val, gpio_base + reg);
  1535. + mmiowb();
  1536. +}
  1537. +
  1538. +static void set_gpio_reg_low(int gpio, int reg)
  1539. +{
  1540. + u32 val;
  1541. +
  1542. + val = inl(gpio_base + reg);
  1543. + val |= (1 << (16 + gpio));
  1544. + val &= ~(1 << gpio);
  1545. + outl(val, gpio_base + reg);
  1546. + mmiowb();
  1547. +}
  1548. +
  1549. +static void set_gpio_output_low(int gpio)
  1550. +{
  1551. + set_gpio_reg_high(gpio, GPIOL_OUT_EN);
  1552. + set_gpio_reg_low(gpio, GPIOL_OUT_VAL);
  1553. +}
  1554. +
  1555. +static void set_gpio_output_high(int gpio)
  1556. +{
  1557. + set_gpio_reg_high(gpio, GPIOL_OUT_EN);
  1558. + set_gpio_reg_high(gpio, GPIOL_OUT_VAL);
  1559. +}
  1560. +
  1561. +/* backlight subdriver */
  1562. +
  1563. +#define MAX_BRIGHTNESS 100
  1564. +#define DEFAULT_BRIGHTNESS 50
  1565. +#define MIN_BRIGHTNESS 0
  1566. +static unsigned int level;
  1567. +
  1568. +DEFINE_SPINLOCK(backlight_lock);
  1569. +/* Tune the brightness */
  1570. +static void setup_mfgpt2(void)
  1571. +{
  1572. + unsigned long flags;
  1573. +
  1574. + spin_lock_irqsave(&backlight_lock, flags);
  1575. +
  1576. + /* Set MFGPT2 comparator 1,2 */
  1577. + outw(MAX_BRIGHTNESS-level, MFGPT2_CMP1);
  1578. + outw(MAX_BRIGHTNESS, MFGPT2_CMP2);
  1579. + /* Clear MFGPT2 UP COUNTER */
  1580. + outw(0, MFGPT2_CNT);
  1581. + /* Enable counter, compare mode, 32k */
  1582. + outw(0x8280, MFGPT2_SETUP);
  1583. +
  1584. + spin_unlock_irqrestore(&backlight_lock, flags);
  1585. +}
  1586. +
  1587. +static int lynloong_set_brightness(struct backlight_device *bd)
  1588. +{
  1589. + level = (bd->props.fb_blank == FB_BLANK_UNBLANK &&
  1590. + bd->props.power == FB_BLANK_UNBLANK) ?
  1591. + bd->props.brightness : 0;
  1592. +
  1593. + if (level > MAX_BRIGHTNESS)
  1594. + level = MAX_BRIGHTNESS;
  1595. + else if (level < MIN_BRIGHTNESS)
  1596. + level = MIN_BRIGHTNESS;
  1597. +
  1598. + setup_mfgpt2();
  1599. +
  1600. + return 0;
  1601. +}
  1602. +
  1603. +static int lynloong_get_brightness(struct backlight_device *bd)
  1604. +{
  1605. + return level;
  1606. +}
  1607. +
  1608. +static struct backlight_ops backlight_ops = {
  1609. + .get_brightness = lynloong_get_brightness,
  1610. + .update_status = lynloong_set_brightness,
  1611. +};
  1612. +
  1613. +static struct backlight_device *lynloong_backlight_dev;
  1614. +
  1615. +static int lynloong_backlight_init(void)
  1616. +{
  1617. + int ret;
  1618. + u32 hi;
  1619. + struct backlight_properties props;
  1620. +
  1621. + /* Get gpio_base */
  1622. + _rdmsr(DIVIL_MSR_REG(DIVIL_LBAR_GPIO), &hi, &gpio_base);
  1623. + /* Get mfgpt_base */
  1624. + _rdmsr(DIVIL_MSR_REG(DIVIL_LBAR_MFGPT), &hi, &mfgpt_base);
  1625. + /* Get gpio_base */
  1626. + _rdmsr(DIVIL_MSR_REG(DIVIL_LBAR_GPIO), &hi, &gpio_base);
  1627. +
  1628. + /* Select for mfgpt */
  1629. + set_gpio_reg_high(7, GPIOL_OUT_AUX1_SEL);
  1630. + /* Enable brightness controlling */
  1631. + set_gpio_output_high(7);
  1632. +
  1633. + memset(&props, 0, sizeof(struct backlight_properties));
  1634. + props.max_brightness = MAX_BRIGHTNESS;
  1635. + lynloong_backlight_dev = backlight_device_register("backlight0", NULL,
  1636. + NULL, &backlight_ops, &props);
  1637. +
  1638. + if (IS_ERR(lynloong_backlight_dev)) {
  1639. + ret = PTR_ERR(lynloong_backlight_dev);
  1640. + return ret;
  1641. + }
  1642. +
  1643. + lynloong_backlight_dev->props.brightness = DEFAULT_BRIGHTNESS;
  1644. + backlight_update_status(lynloong_backlight_dev);
  1645. +
  1646. + return 0;
  1647. +}
  1648. +
  1649. +static void lynloong_backlight_exit(void)
  1650. +{
  1651. + if (lynloong_backlight_dev) {
  1652. + backlight_device_unregister(lynloong_backlight_dev);
  1653. + lynloong_backlight_dev = NULL;
  1654. + }
  1655. + /* Disable brightness controlling */
  1656. + set_gpio_output_low(7);
  1657. +}
  1658. +
  1659. +/* video output driver */
  1660. +static int vo_status = 1;
  1661. +
  1662. +static int lcd_video_output_get(struct output_device *od)
  1663. +{
  1664. + return vo_status;
  1665. +}
  1666. +
  1667. +static int lcd_video_output_set(struct output_device *od)
  1668. +{
  1669. + int i;
  1670. + unsigned long status;
  1671. +
  1672. + status = !!od->request_state;
  1673. +
  1674. + if (status == 0) {
  1675. + /* Set the current status as off */
  1676. + vo_status = 0;
  1677. + /* Turn off the backlight */
  1678. + set_gpio_output_low(11);
  1679. + for (i = 0; i < 0x500; i++)
  1680. + delay();
  1681. + /* Turn off the LCD */
  1682. + set_gpio_output_high(8);
  1683. + } else {
  1684. + /* Turn on the LCD */
  1685. + set_gpio_output_low(8);
  1686. + for (i = 0; i < 0x500; i++)
  1687. + delay();
  1688. + /* Turn on the backlight */
  1689. + set_gpio_output_high(11);
  1690. + /* Set the current status as on */
  1691. + vo_status = 1;
  1692. + }
  1693. +
  1694. + return 0;
  1695. +}
  1696. +
  1697. +static struct output_properties lcd_output_properties = {
  1698. + .set_state = lcd_video_output_set,
  1699. + .get_status = lcd_video_output_get,
  1700. +};
  1701. +
  1702. +static struct output_device *lcd_output_dev;
  1703. +
  1704. +static void lynloong_lcd_vo_set(int status)
  1705. +{
  1706. + lcd_output_dev->request_state = status;
  1707. + lcd_video_output_set(lcd_output_dev);
  1708. +}
  1709. +
  1710. +static int lynloong_vo_init(void)
  1711. +{
  1712. + int ret;
  1713. +
  1714. + /* Register video output device: lcd */
  1715. + lcd_output_dev = video_output_register("LCD", NULL, NULL,
  1716. + &lcd_output_properties);
  1717. +
  1718. + if (IS_ERR(lcd_output_dev)) {
  1719. + ret = PTR_ERR(lcd_output_dev);
  1720. + lcd_output_dev = NULL;
  1721. + return ret;
  1722. + }
  1723. + /* Ensure LCD is on by default */
  1724. + lynloong_lcd_vo_set(1);
  1725. +
  1726. + return 0;
  1727. +}
  1728. +
  1729. +static void lynloong_vo_exit(void)
  1730. +{
  1731. + if (lcd_output_dev) {
  1732. + video_output_unregister(lcd_output_dev);
  1733. + lcd_output_dev = NULL;
  1734. + }
  1735. +}
  1736. +
  1737. +/* suspend support */
  1738. +
  1739. +#ifdef CONFIG_PM
  1740. +
  1741. +static u32 smb_base;
  1742. +
  1743. +/* I2C operations */
  1744. +
  1745. +static int i2c_wait(void)
  1746. +{
  1747. + char c;
  1748. + int i;
  1749. +
  1750. + udelay(1000);
  1751. + for (i = 0; i < 20; i++) {
  1752. + c = inb(smb_base | SMB_STS);
  1753. + if (c & (SMB_STS_BER | SMB_STS_NEGACK))
  1754. + return -1;
  1755. + if (c & SMB_STS_SDAST)
  1756. + return 0;
  1757. + udelay(100);
  1758. + }
  1759. + return -2;
  1760. +}
  1761. +
  1762. +static void i2c_read_single(int addr, int regNo, char *value)
  1763. +{
  1764. + unsigned char c;
  1765. +
  1766. + /* Start condition */
  1767. + c = inb(smb_base | SMB_CTRL1);
  1768. + outb(c | SMB_CTRL1_START, smb_base | SMB_CTRL1);
  1769. + i2c_wait();
  1770. +
  1771. + /* Send slave address */
  1772. + outb(addr & 0xfe, smb_base | SMB_SDA);
  1773. + i2c_wait();
  1774. +
  1775. + /* Acknowledge smbus */
  1776. + c = inb(smb_base | SMB_CTRL1);
  1777. + outb(c | SMB_CTRL1_ACK, smb_base | SMB_CTRL1);
  1778. +
  1779. + /* Send register index */
  1780. + outb(regNo, smb_base | SMB_SDA);
  1781. + i2c_wait();
  1782. +
  1783. + /* Acknowledge smbus */
  1784. + c = inb(smb_base | SMB_CTRL1);
  1785. + outb(c | SMB_CTRL1_ACK, smb_base | SMB_CTRL1);
  1786. +
  1787. + /* Start condition again */
  1788. + c = inb(smb_base | SMB_CTRL1);
  1789. + outb(c | SMB_CTRL1_START, smb_base | SMB_CTRL1);
  1790. + i2c_wait();
  1791. +
  1792. + /* Send salve address again */
  1793. + outb(1 | addr, smb_base | SMB_SDA);
  1794. + i2c_wait();
  1795. +
  1796. + /* Acknowledge smbus */
  1797. + c = inb(smb_base | SMB_CTRL1);
  1798. + outb(c | SMB_CTRL1_ACK, smb_base | SMB_CTRL1);
  1799. +
  1800. + /* Read data */
  1801. + *value = inb(smb_base | SMB_SDA);
  1802. +
  1803. + /* Stop condition */
  1804. + outb(SMB_CTRL1_STOP, smb_base | SMB_CTRL1);
  1805. + i2c_wait();
  1806. +}
  1807. +
  1808. +static void i2c_write_single(int addr, int regNo, char value)
  1809. +{
  1810. + unsigned char c;
  1811. +
  1812. + /* Start condition */
  1813. + c = inb(smb_base | SMB_CTRL1);
  1814. + outb(c | SMB_CTRL1_START, smb_base | SMB_CTRL1);
  1815. + i2c_wait();
  1816. + /* Send slave address */
  1817. + outb(addr & 0xfe, smb_base | SMB_SDA);
  1818. + i2c_wait();;
  1819. +
  1820. + /* Send register index */
  1821. + outb(regNo, smb_base | SMB_SDA);
  1822. + i2c_wait();
  1823. +
  1824. + /* Write data */
  1825. + outb(value, smb_base | SMB_SDA);
  1826. + i2c_wait();
  1827. + /* Stop condition */
  1828. + outb(SMB_CTRL1_STOP, smb_base | SMB_CTRL1);
  1829. + i2c_wait();
  1830. +}
  1831. +
  1832. +static void stop_clock(int clk_reg, int clk_sel)
  1833. +{
  1834. + u8 value;
  1835. +
  1836. + i2c_read_single(0xd3, clk_reg, &value);
  1837. + value &= ~(1 << clk_sel);
  1838. + i2c_write_single(0xd2, clk_reg, value);
  1839. +}
  1840. +
  1841. +static void enable_clock(int clk_reg, int clk_sel)
  1842. +{
  1843. + u8 value;
  1844. +
  1845. + i2c_read_single(0xd3, clk_reg, &value);
  1846. + value |= (1 << clk_sel);
  1847. + i2c_write_single(0xd2, clk_reg, value);
  1848. +}
  1849. +
  1850. +static char cached_clk_freq;
  1851. +static char cached_pci_fixed_freq;
  1852. +
  1853. +static void decrease_clk_freq(void)
  1854. +{
  1855. + char value;
  1856. +
  1857. + i2c_read_single(0xd3, 1, &value);
  1858. + cached_clk_freq = value;
  1859. +
  1860. + /* Select frequency by software */
  1861. + value |= (1 << 1);
  1862. + /* CPU, 3V66, PCI : 100, 66, 33(1) */
  1863. + value |= (1 << 2);
  1864. + i2c_write_single(0xd2, 1, value);
  1865. +
  1866. + /* Cache the pci frequency */
  1867. + i2c_read_single(0xd3, 14, &value);
  1868. + cached_pci_fixed_freq = value;
  1869. +
  1870. + /* Enable PCI fix mode */
  1871. + value |= (1 << 5);
  1872. + /* 3V66, PCI : 64MHz, 32MHz */
  1873. + value |= (1 << 3);
  1874. + i2c_write_single(0xd2, 14, value);
  1875. +
  1876. +}
  1877. +
  1878. +static void resume_clk_freq(void)
  1879. +{
  1880. + i2c_write_single(0xd2, 1, cached_clk_freq);
  1881. + i2c_write_single(0xd2, 14, cached_pci_fixed_freq);
  1882. +}
  1883. +
  1884. +static void stop_clocks(void)
  1885. +{
  1886. + /* CPU Clock Register */
  1887. + stop_clock(2, 5); /* not used */
  1888. + stop_clock(2, 6); /* not used */
  1889. + stop_clock(2, 7); /* not used */
  1890. +
  1891. + /* PCI Clock Register */
  1892. + stop_clock(3, 1); /* 8100 */
  1893. + stop_clock(3, 5); /* SIS */
  1894. + stop_clock(3, 0); /* not used */
  1895. + stop_clock(3, 6); /* not used */
  1896. +
  1897. + /* PCI 48M Clock Register */
  1898. + stop_clock(4, 6); /* USB grounding */
  1899. + stop_clock(4, 5); /* REF(5536_14M) */
  1900. +
  1901. + /* 3V66 Control Register */
  1902. + stop_clock(5, 0); /* VCH_CLK..., grounding */
  1903. +}
  1904. +
  1905. +static void enable_clocks(void)
  1906. +{
  1907. + enable_clock(3, 1); /* 8100 */
  1908. + enable_clock(3, 5); /* SIS */
  1909. +
  1910. + enable_clock(4, 6);
  1911. + enable_clock(4, 5); /* REF(5536_14M) */
  1912. +
  1913. + enable_clock(5, 0); /* VCH_CLOCK, grounding */
  1914. +}
  1915. +
  1916. +static int lynloong_suspend(struct device *dev)
  1917. +{
  1918. + /* Disable AMP */
  1919. + set_gpio_output_high(6);
  1920. + /* Turn off LCD */
  1921. + lynloong_lcd_vo_set(0);
  1922. +
  1923. + /* Stop the clocks of some devices */
  1924. + stop_clocks();
  1925. +
  1926. + /* Decrease the external clock frequency */
  1927. + decrease_clk_freq();
  1928. +
  1929. + return 0;
  1930. +}
  1931. +
  1932. +static int lynloong_resume(struct device *dev)
  1933. +{
  1934. + /* Turn on the LCD */
  1935. + lynloong_lcd_vo_set(1);
  1936. +
  1937. + /* Resume clock frequency, enable the relative clocks */
  1938. + resume_clk_freq();
  1939. + enable_clocks();
  1940. +
  1941. + /* Enable AMP */
  1942. + set_gpio_output_low(6);
  1943. +
  1944. + return 0;
  1945. +}
  1946. +
  1947. +static const SIMPLE_DEV_PM_OPS(lynloong_pm_ops, lynloong_suspend,
  1948. + lynloong_resume);
  1949. +#endif /* !CONFIG_PM */
  1950. +
  1951. +static struct platform_device_id platform_device_ids[] = {
  1952. + {
  1953. + .name = "lynloong_pc",
  1954. + },
  1955. + {}
  1956. +};
  1957. +
  1958. +MODULE_DEVICE_TABLE(platform, platform_device_ids);
  1959. +
  1960. +static struct platform_driver platform_driver = {
  1961. + .driver = {
  1962. + .name = "lynloong_pc",
  1963. + .owner = THIS_MODULE,
  1964. +#ifdef CONFIG_PM
  1965. + .pm = &lynloong_pm_ops,
  1966. +#endif
  1967. + },
  1968. + .id_table = platform_device_ids,
  1969. +};
  1970. +
  1971. +static int __init lynloong_init(void)
  1972. +{
  1973. + int ret;
  1974. +
  1975. + pr_info("Load LynLoong Platform Specific Driver.\n");
  1976. +
  1977. + /* Register platform stuff */
  1978. + ret = platform_driver_register(&platform_driver);
  1979. + if (ret) {
  1980. + pr_err("Fail to register lynloong platform driver.\n");
  1981. + return ret;
  1982. + }
  1983. +
  1984. + ret = lynloong_backlight_init();
  1985. + if (ret) {
  1986. + pr_err("Fail to register lynloong backlight driver.\n");
  1987. + return ret;
  1988. + }
  1989. +
  1990. + ret = lynloong_vo_init();
  1991. + if (ret) {
  1992. + pr_err("Fail to register lynloong backlight driver.\n");
  1993. + lynloong_vo_exit();
  1994. + return ret;
  1995. + }
  1996. +
  1997. + return 0;
  1998. +}
  1999. +
  2000. +static void __exit lynloong_exit(void)
  2001. +{
  2002. + lynloong_vo_exit();
  2003. + lynloong_backlight_exit();
  2004. + platform_driver_unregister(&platform_driver);
  2005. +
  2006. + pr_info("Unload LynLoong Platform Specific Driver.\n");
  2007. +}
  2008. +
  2009. +module_init(lynloong_init);
  2010. +module_exit(lynloong_exit);
  2011. +
  2012. +MODULE_AUTHOR("Wu Zhangjin <wuzhangjin@gmail.com>; Xiang Yu <xiangy@lemote.com>");
  2013. +MODULE_DESCRIPTION("LynLoong PC driver");
  2014. +MODULE_LICENSE("GPL");
  2015. diff -Nur linux-2.6.37.orig/drivers/platform/mips/yeeloong_ecrom.c linux-2.6.37/drivers/platform/mips/yeeloong_ecrom.c
  2016. --- linux-2.6.37.orig/drivers/platform/mips/yeeloong_ecrom.c 1970-01-01 01:00:00.000000000 +0100
  2017. +++ linux-2.6.37/drivers/platform/mips/yeeloong_ecrom.c 2011-01-11 20:44:43.000000000 +0100
  2018. @@ -0,0 +1,943 @@
  2019. +/*
  2020. + * Driver for flushing/dumping ROM of EC on YeeLoong laptop
  2021. + *
  2022. + * Copyright (C) 2009 Lemote Inc.
  2023. + * Author: liujl <liujl@lemote.com>
  2024. + *
  2025. + * NOTE :
  2026. + * The EC resources accessing and programming are supported.
  2027. + */
  2028. +
  2029. +#include <linux/proc_fs.h>
  2030. +#include <linux/miscdevice.h>
  2031. +#include <linux/init.h>
  2032. +#include <linux/delay.h>
  2033. +
  2034. +#include <ec_kb3310b.h>
  2035. +
  2036. +#define EC_MISC_DEV "ec_misc"
  2037. +#define EC_IOC_MAGIC 'E'
  2038. +
  2039. +/* ec registers range */
  2040. +#define EC_MAX_REGADDR 0xFFFF
  2041. +#define EC_MIN_REGADDR 0xF000
  2042. +#define EC_RAM_ADDR 0xF800
  2043. +
  2044. +/* version burned address */
  2045. +#define VER_ADDR 0xf7a1
  2046. +#define VER_MAX_SIZE 7
  2047. +#define EC_ROM_MAX_SIZE 0x10000
  2048. +
  2049. +/* ec internal register */
  2050. +#define REG_POWER_MODE 0xF710
  2051. +#define FLAG_NORMAL_MODE 0x00
  2052. +#define FLAG_IDLE_MODE 0x01
  2053. +#define FLAG_RESET_MODE 0x02
  2054. +
  2055. +/* ec update program flag */
  2056. +#define PROGRAM_FLAG_NONE 0x00
  2057. +#define PROGRAM_FLAG_IE 0x01
  2058. +#define PROGRAM_FLAG_ROM 0x02
  2059. +
  2060. +/* XBI relative registers */
  2061. +#define REG_XBISEG0 0xFEA0
  2062. +#define REG_XBISEG1 0xFEA1
  2063. +#define REG_XBIRSV2 0xFEA2
  2064. +#define REG_XBIRSV3 0xFEA3
  2065. +#define REG_XBIRSV4 0xFEA4
  2066. +#define REG_XBICFG 0xFEA5
  2067. +#define REG_XBICS 0xFEA6
  2068. +#define REG_XBIWE 0xFEA7
  2069. +#define REG_XBISPIA0 0xFEA8
  2070. +#define REG_XBISPIA1 0xFEA9
  2071. +#define REG_XBISPIA2 0xFEAA
  2072. +#define REG_XBISPIDAT 0xFEAB
  2073. +#define REG_XBISPICMD 0xFEAC
  2074. +#define REG_XBISPICFG 0xFEAD
  2075. +#define REG_XBISPIDATR 0xFEAE
  2076. +#define REG_XBISPICFG2 0xFEAF
  2077. +
  2078. +/* commands definition for REG_XBISPICMD */
  2079. +#define SPICMD_WRITE_STATUS 0x01
  2080. +#define SPICMD_BYTE_PROGRAM 0x02
  2081. +#define SPICMD_READ_BYTE 0x03
  2082. +#define SPICMD_WRITE_DISABLE 0x04
  2083. +#define SPICMD_READ_STATUS 0x05
  2084. +#define SPICMD_WRITE_ENABLE 0x06
  2085. +#define SPICMD_HIGH_SPEED_READ 0x0B
  2086. +#define SPICMD_POWER_DOWN 0xB9
  2087. +#define SPICMD_SST_EWSR 0x50
  2088. +#define SPICMD_SST_SEC_ERASE 0x20
  2089. +#define SPICMD_SST_BLK_ERASE 0x52
  2090. +#define SPICMD_SST_CHIP_ERASE 0x60
  2091. +#define SPICMD_FRDO 0x3B
  2092. +#define SPICMD_SEC_ERASE 0xD7
  2093. +#define SPICMD_BLK_ERASE 0xD8
  2094. +#define SPICMD_CHIP_ERASE 0xC7
  2095. +
  2096. +/* bits definition for REG_XBISPICFG */
  2097. +#define SPICFG_AUTO_CHECK 0x01
  2098. +#define SPICFG_SPI_BUSY 0x02
  2099. +#define SPICFG_DUMMY_READ 0x04
  2100. +#define SPICFG_EN_SPICMD 0x08
  2101. +#define SPICFG_LOW_SPICS 0x10
  2102. +#define SPICFG_EN_SHORT_READ 0x20
  2103. +#define SPICFG_EN_OFFSET_READ 0x40
  2104. +#define SPICFG_EN_FAST_READ 0x80
  2105. +
  2106. +/* watchdog timer registers */
  2107. +#define REG_WDTCFG 0xfe80
  2108. +#define REG_WDTPF 0xfe81
  2109. +#define REG_WDT 0xfe82
  2110. +
  2111. +/* lpc configure register */
  2112. +#define REG_LPCCFG 0xfe95
  2113. +
  2114. +/* 8051 reg */
  2115. +#define REG_PXCFG 0xff14
  2116. +
  2117. +/* Fan register in KB3310 */
  2118. +#define REG_ECFAN_SPEED_LEVEL 0xf4e4
  2119. +#define REG_ECFAN_SWITCH 0xf4d2
  2120. +
  2121. +/* the ec flash rom id number */
  2122. +#define EC_ROM_PRODUCT_ID_SPANSION 0x01
  2123. +#define EC_ROM_PRODUCT_ID_MXIC 0xC2
  2124. +#define EC_ROM_PRODUCT_ID_AMIC 0x37
  2125. +#define EC_ROM_PRODUCT_ID_EONIC 0x1C
  2126. +
  2127. +/* misc ioctl operations */
  2128. +#define IOCTL_RDREG _IOR(EC_IOC_MAGIC, 1, int)
  2129. +#define IOCTL_WRREG _IOW(EC_IOC_MAGIC, 2, int)
  2130. +#define IOCTL_READ_EC _IOR(EC_IOC_MAGIC, 3, int)
  2131. +#define IOCTL_PROGRAM_IE _IOW(EC_IOC_MAGIC, 4, int)
  2132. +#define IOCTL_PROGRAM_EC _IOW(EC_IOC_MAGIC, 5, int)
  2133. +
  2134. +/* start address for programming of EC content or IE */
  2135. +/* ec running code start address */
  2136. +#define EC_START_ADDR 0x00000000
  2137. +/* ec information element storing address */
  2138. +#define IE_START_ADDR 0x00020000
  2139. +
  2140. +/* EC state */
  2141. +#define EC_STATE_IDLE 0x00 /* ec in idle state */
  2142. +#define EC_STATE_BUSY 0x01 /* ec in busy state */
  2143. +
  2144. +/* timeout value for programming */
  2145. +#define EC_FLASH_TIMEOUT 0x1000 /* ec program timeout */
  2146. +/* command checkout timeout including cmd to port or state flag check */
  2147. +#define EC_CMD_TIMEOUT 0x1000
  2148. +#define EC_SPICMD_STANDARD_TIMEOUT (4 * 1000) /* unit : us */
  2149. +#define EC_MAX_DELAY_UNIT (10) /* every time for polling */
  2150. +#define SPI_FINISH_WAIT_TIME 10
  2151. +/* EC content max size */
  2152. +#define EC_CONTENT_MAX_SIZE (64 * 1024)
  2153. +#define IE_CONTENT_MAX_SIZE (0x100000 - IE_START_ADDR)
  2154. +
  2155. +/* the register operation access struct */
  2156. +struct ec_reg {
  2157. + u32 addr; /* the address of kb3310 registers */
  2158. + u8 val; /* the register value */
  2159. +};
  2160. +
  2161. +struct ec_info {
  2162. + u32 start_addr;
  2163. + u32 size;
  2164. + u8 *buf;
  2165. +};
  2166. +
  2167. +/* open for using rom protection action */
  2168. +#define EC_ROM_PROTECTION
  2169. +
  2170. +/* enable the chip reset mode */
  2171. +static int ec_init_reset_mode(void)
  2172. +{
  2173. + int timeout;
  2174. + unsigned char status = 0;
  2175. + int ret = 0;
  2176. +
  2177. + /* make chip goto reset mode */
  2178. + ret = ec_query_seq(CMD_INIT_RESET_MODE);
  2179. + if (ret < 0) {
  2180. + printk(KERN_ERR "ec init reset mode failed.\n");
  2181. + goto out;
  2182. + }
  2183. +
  2184. + /* make the action take active */
  2185. + timeout = EC_CMD_TIMEOUT;
  2186. + status = ec_read(REG_POWER_MODE) & FLAG_RESET_MODE;
  2187. + while (timeout--) {
  2188. + if (status) {
  2189. + udelay(EC_REG_DELAY);
  2190. + break;
  2191. + }
  2192. + status = ec_read(REG_POWER_MODE) & FLAG_RESET_MODE;
  2193. + udelay(EC_REG_DELAY);
  2194. + }
  2195. + if (timeout <= 0) {
  2196. + printk(KERN_ERR "ec rom fixup : can't check reset status.\n");
  2197. + ret = -EINVAL;
  2198. + } else
  2199. + printk(KERN_INFO "(%d/%d)reset 0xf710 : 0x%x\n", timeout,
  2200. + EC_CMD_TIMEOUT - timeout, status);
  2201. +
  2202. + /* set MCU to reset mode */
  2203. + udelay(EC_REG_DELAY);
  2204. + status = ec_read(REG_PXCFG);
  2205. + status |= (1 << 0);
  2206. + ec_write(REG_PXCFG, status);
  2207. + udelay(EC_REG_DELAY);
  2208. +
  2209. + /* disable FWH/LPC */
  2210. + udelay(EC_REG_DELAY);
  2211. + status = ec_read(REG_LPCCFG);
  2212. + status &= ~(1 << 7);
  2213. + ec_write(REG_LPCCFG, status);
  2214. + udelay(EC_REG_DELAY);
  2215. +
  2216. + printk(KERN_INFO "entering reset mode ok..............\n");
  2217. +
  2218. + out:
  2219. + return ret;
  2220. +}
  2221. +
  2222. +/* make ec exit from reset mode */
  2223. +static void ec_exit_reset_mode(void)
  2224. +{
  2225. + unsigned char regval;
  2226. +
  2227. + udelay(EC_REG_DELAY);
  2228. + regval = ec_read(REG_LPCCFG);
  2229. + regval |= (1 << 7);
  2230. + ec_write(REG_LPCCFG, regval);
  2231. + regval = ec_read(REG_PXCFG);
  2232. + regval &= ~(1 << 0);
  2233. + ec_write(REG_PXCFG, regval);
  2234. + printk(KERN_INFO "exit reset mode ok..................\n");
  2235. +
  2236. + return;
  2237. +}
  2238. +
  2239. +/* make ec disable WDD */
  2240. +static void ec_disable_WDD(void)
  2241. +{
  2242. + unsigned char status;
  2243. +
  2244. + udelay(EC_REG_DELAY);
  2245. + status = ec_read(REG_WDTCFG);
  2246. + ec_write(REG_WDTPF, 0x03);
  2247. + ec_write(REG_WDTCFG, (status & 0x80) | 0x48);
  2248. + printk(KERN_INFO "Disable WDD ok..................\n");
  2249. +
  2250. + return;
  2251. +}
  2252. +
  2253. +/* make ec enable WDD */
  2254. +static void ec_enable_WDD(void)
  2255. +{
  2256. + unsigned char status;
  2257. +
  2258. + udelay(EC_REG_DELAY);
  2259. + status = ec_read(REG_WDTCFG);
  2260. + ec_write(REG_WDT, 0x28); /* set WDT 5sec(0x28) */
  2261. + ec_write(REG_WDTCFG, (status & 0x80) | 0x03);
  2262. + printk(KERN_INFO "Enable WDD ok..................\n");
  2263. +
  2264. + return;
  2265. +}
  2266. +
  2267. +/* make ec goto idle mode */
  2268. +static int ec_init_idle_mode(void)
  2269. +{
  2270. + int timeout;
  2271. + unsigned char status = 0;
  2272. + int ret = 0;
  2273. +
  2274. + ec_query_seq(CMD_INIT_IDLE_MODE);
  2275. +
  2276. + /* make the action take active */
  2277. + timeout = EC_CMD_TIMEOUT;
  2278. + status = ec_read(REG_POWER_MODE) & FLAG_IDLE_MODE;
  2279. + while (timeout--) {
  2280. + if (status) {
  2281. + udelay(EC_REG_DELAY);
  2282. + break;
  2283. + }
  2284. + status = ec_read(REG_POWER_MODE) & FLAG_IDLE_MODE;
  2285. + udelay(EC_REG_DELAY);
  2286. + }
  2287. + if (timeout <= 0) {
  2288. + printk(KERN_ERR "ec rom fixup : can't check out the status.\n");
  2289. + ret = -EINVAL;
  2290. + } else
  2291. + printk(KERN_INFO "(%d/%d)0xf710 : 0x%x\n", timeout,
  2292. + EC_CMD_TIMEOUT - timeout, ec_read(REG_POWER_MODE));
  2293. +
  2294. + printk(KERN_INFO "entering idle mode ok...................\n");
  2295. +
  2296. + return ret;
  2297. +}
  2298. +
  2299. +/* make ec exit from idle mode */
  2300. +static int ec_exit_idle_mode(void)
  2301. +{
  2302. +
  2303. + ec_query_seq(CMD_EXIT_IDLE_MODE);
  2304. +
  2305. + printk(KERN_INFO "exit idle mode ok...................\n");
  2306. +
  2307. + return 0;
  2308. +}
  2309. +
  2310. +static int ec_instruction_cycle(void)
  2311. +{
  2312. + unsigned long timeout;
  2313. + int ret = 0;
  2314. +
  2315. + timeout = EC_FLASH_TIMEOUT;
  2316. + while (timeout-- >= 0) {
  2317. + if (!(ec_read(REG_XBISPICFG) & SPICFG_SPI_BUSY))
  2318. + break;
  2319. + }
  2320. + if (timeout <= 0) {
  2321. + printk(KERN_ERR
  2322. + "EC_INSTRUCTION_CYCLE : timeout for check flag.\n");
  2323. + ret = -EINVAL;
  2324. + goto out;
  2325. + }
  2326. +
  2327. + out:
  2328. + return ret;
  2329. +}
  2330. +
  2331. +/* To see if the ec is in busy state or not. */
  2332. +static inline int ec_flash_busy(unsigned long timeout)
  2333. +{
  2334. + /* assurance the first command be going to rom */
  2335. + if (ec_instruction_cycle() < 0)
  2336. + return EC_STATE_BUSY;
  2337. +#if 1
  2338. + timeout = timeout / EC_MAX_DELAY_UNIT;
  2339. + while (timeout-- > 0) {
  2340. + /* check the rom's status of busy flag */
  2341. + ec_write(REG_XBISPICMD, SPICMD_READ_STATUS);
  2342. + if (ec_instruction_cycle() < 0)
  2343. + return EC_STATE_BUSY;
  2344. + if ((ec_read(REG_XBISPIDAT) & 0x01) == 0x00)
  2345. + return EC_STATE_IDLE;
  2346. + udelay(EC_MAX_DELAY_UNIT);
  2347. + }
  2348. + if (timeout <= 0) {
  2349. + printk(KERN_ERR
  2350. + "EC_FLASH_BUSY : timeout for check rom flag.\n");
  2351. + return EC_STATE_BUSY;
  2352. + }
  2353. +#else
  2354. + /* check the rom's status of busy flag */
  2355. + ec_write(REG_XBISPICMD, SPICMD_READ_STATUS);
  2356. + if (ec_instruction_cycle() < 0)
  2357. + return EC_STATE_BUSY;
  2358. +
  2359. + timeout = timeout / EC_MAX_DELAY_UNIT;
  2360. + while (timeout-- > 0) {
  2361. + if ((ec_read(REG_XBISPIDAT) & 0x01) == 0x00)
  2362. + return EC_STATE_IDLE;
  2363. + udelay(EC_MAX_DELAY_UNIT);
  2364. + }
  2365. + if (timeout <= 0) {
  2366. + printk(KERN_ERR
  2367. + "EC_FLASH_BUSY : timeout for check rom flag.\n");
  2368. + return EC_STATE_BUSY;
  2369. + }
  2370. +#endif
  2371. +
  2372. + return EC_STATE_IDLE;
  2373. +}
  2374. +
  2375. +static int rom_instruction_cycle(unsigned char cmd)
  2376. +{
  2377. + unsigned long timeout = 0;
  2378. +
  2379. + switch (cmd) {
  2380. + case SPICMD_READ_STATUS:
  2381. + case SPICMD_WRITE_ENABLE:
  2382. + case SPICMD_WRITE_DISABLE:
  2383. + case SPICMD_READ_BYTE:
  2384. + case SPICMD_HIGH_SPEED_READ:
  2385. + timeout = 0;
  2386. + break;
  2387. + case SPICMD_WRITE_STATUS:
  2388. + timeout = 300 * 1000;
  2389. + break;
  2390. + case SPICMD_BYTE_PROGRAM:
  2391. + timeout = 5 * 1000;
  2392. + break;
  2393. + case SPICMD_SST_SEC_ERASE:
  2394. + case SPICMD_SEC_ERASE:
  2395. + timeout = 1000 * 1000;
  2396. + break;
  2397. + case SPICMD_SST_BLK_ERASE:
  2398. + case SPICMD_BLK_ERASE:
  2399. + timeout = 3 * 1000 * 1000;
  2400. + break;
  2401. + case SPICMD_SST_CHIP_ERASE:
  2402. + case SPICMD_CHIP_ERASE:
  2403. + timeout = 20 * 1000 * 1000;
  2404. + break;
  2405. + default:
  2406. + timeout = EC_SPICMD_STANDARD_TIMEOUT;
  2407. + }
  2408. + if (timeout == 0)
  2409. + return ec_instruction_cycle();
  2410. + if (timeout < EC_SPICMD_STANDARD_TIMEOUT)
  2411. + timeout = EC_SPICMD_STANDARD_TIMEOUT;
  2412. +
  2413. + return ec_flash_busy(timeout);
  2414. +}
  2415. +
  2416. +/* delay for start/stop action */
  2417. +static void delay_spi(int n)
  2418. +{
  2419. + while (n--)
  2420. + inb(EC_IO_PORT_HIGH);
  2421. +}
  2422. +
  2423. +/* start the action to spi rom function */
  2424. +static void ec_start_spi(void)
  2425. +{
  2426. + unsigned char val;
  2427. +
  2428. + delay_spi(SPI_FINISH_WAIT_TIME);
  2429. + val = ec_read(REG_XBISPICFG) | SPICFG_EN_SPICMD | SPICFG_AUTO_CHECK;
  2430. + ec_write(REG_XBISPICFG, val);
  2431. + delay_spi(SPI_FINISH_WAIT_TIME);
  2432. +}
  2433. +
  2434. +/* stop the action to spi rom function */
  2435. +static void ec_stop_spi(void)
  2436. +{
  2437. + unsigned char val;
  2438. +
  2439. + delay_spi(SPI_FINISH_WAIT_TIME);
  2440. + val =
  2441. + ec_read(REG_XBISPICFG) & (~(SPICFG_EN_SPICMD | SPICFG_AUTO_CHECK));
  2442. + ec_write(REG_XBISPICFG, val);
  2443. + delay_spi(SPI_FINISH_WAIT_TIME);
  2444. +}
  2445. +
  2446. +/* read one byte from xbi interface */
  2447. +static int ec_read_byte(unsigned int addr, unsigned char *byte)
  2448. +{
  2449. + int ret = 0;
  2450. +
  2451. + /* enable spicmd writing. */
  2452. + ec_start_spi();
  2453. +
  2454. + /* enable write spi flash */
  2455. + ec_write(REG_XBISPICMD, SPICMD_WRITE_ENABLE);
  2456. + if (rom_instruction_cycle(SPICMD_WRITE_ENABLE) == EC_STATE_BUSY) {
  2457. + printk(KERN_ERR "EC_READ_BYTE : SPICMD_WRITE_ENABLE failed.\n");
  2458. + ret = -EINVAL;
  2459. + goto out;
  2460. + }
  2461. +
  2462. + /* write the address */
  2463. + ec_write(REG_XBISPIA2, (addr & 0xff0000) >> 16);
  2464. + ec_write(REG_XBISPIA1, (addr & 0x00ff00) >> 8);
  2465. + ec_write(REG_XBISPIA0, (addr & 0x0000ff) >> 0);
  2466. + /* start action */
  2467. + ec_write(REG_XBISPICMD, SPICMD_HIGH_SPEED_READ);
  2468. + if (rom_instruction_cycle(SPICMD_HIGH_SPEED_READ) == EC_STATE_BUSY) {
  2469. + printk(KERN_ERR
  2470. + "EC_READ_BYTE : SPICMD_HIGH_SPEED_READ failed.\n");
  2471. + ret = -EINVAL;
  2472. + goto out;
  2473. + }
  2474. +
  2475. + *byte = ec_read(REG_XBISPIDAT);
  2476. +
  2477. + out:
  2478. + /* disable spicmd writing. */
  2479. + ec_stop_spi();
  2480. +
  2481. + return ret;
  2482. +}
  2483. +
  2484. +/* write one byte to ec rom */
  2485. +static int ec_write_byte(unsigned int addr, unsigned char byte)
  2486. +{
  2487. + int ret = 0;
  2488. +
  2489. + /* enable spicmd writing. */
  2490. + ec_start_spi();
  2491. +
  2492. + /* enable write spi flash */
  2493. + ec_write(REG_XBISPICMD, SPICMD_WRITE_ENABLE);
  2494. + if (rom_instruction_cycle(SPICMD_WRITE_ENABLE) == EC_STATE_BUSY) {
  2495. + printk(KERN_ERR
  2496. + "EC_WRITE_BYTE : SPICMD_WRITE_ENABLE failed.\n");
  2497. + ret = -EINVAL;
  2498. + goto out;
  2499. + }
  2500. +
  2501. + /* write the address */
  2502. + ec_write(REG_XBISPIA2, (addr & 0xff0000) >> 16);
  2503. + ec_write(REG_XBISPIA1, (addr & 0x00ff00) >> 8);
  2504. + ec_write(REG_XBISPIA0, (addr & 0x0000ff) >> 0);
  2505. + ec_write(REG_XBISPIDAT, byte);
  2506. + /* start action */
  2507. + ec_write(REG_XBISPICMD, SPICMD_BYTE_PROGRAM);
  2508. + if (rom_instruction_cycle(SPICMD_BYTE_PROGRAM) == EC_STATE_BUSY) {
  2509. + printk(KERN_ERR
  2510. + "EC_WRITE_BYTE : SPICMD_BYTE_PROGRAM failed.\n");
  2511. + ret = -EINVAL;
  2512. + goto out;
  2513. + }
  2514. +
  2515. + out:
  2516. + /* disable spicmd writing. */
  2517. + ec_stop_spi();
  2518. +
  2519. + return ret;
  2520. +}
  2521. +
  2522. +/* unprotect SPI ROM */
  2523. +/* EC_ROM_unprotect function code */
  2524. +static int EC_ROM_unprotect(void)
  2525. +{
  2526. + unsigned char status;
  2527. +
  2528. + /* enable write spi flash */
  2529. + ec_write(REG_XBISPICMD, SPICMD_WRITE_ENABLE);
  2530. + if (rom_instruction_cycle(SPICMD_WRITE_ENABLE) == EC_STATE_BUSY) {
  2531. + printk(KERN_ERR
  2532. + "EC_UNIT_ERASE : SPICMD_WRITE_ENABLE failed.\n");
  2533. + return 1;
  2534. + }
  2535. +
  2536. + /* unprotect the status register of rom */
  2537. + ec_write(REG_XBISPICMD, SPICMD_READ_STATUS);
  2538. + if (rom_instruction_cycle(SPICMD_READ_STATUS) == EC_STATE_BUSY) {
  2539. + printk(KERN_ERR "EC_UNIT_ERASE : SPICMD_READ_STATUS failed.\n");
  2540. + return 1;
  2541. + }
  2542. + status = ec_read(REG_XBISPIDAT);
  2543. + ec_write(REG_XBISPIDAT, status & 0x02);
  2544. + if (ec_instruction_cycle() < 0) {
  2545. + printk(KERN_ERR "EC_UNIT_ERASE : write status value failed.\n");
  2546. + return 1;
  2547. + }
  2548. +
  2549. + ec_write(REG_XBISPICMD, SPICMD_WRITE_STATUS);
  2550. + if (rom_instruction_cycle(SPICMD_WRITE_STATUS) == EC_STATE_BUSY) {
  2551. + printk(KERN_ERR
  2552. + "EC_UNIT_ERASE : SPICMD_WRITE_STATUS failed.\n");
  2553. + return 1;
  2554. + }
  2555. +
  2556. + /* enable write spi flash */
  2557. + ec_write(REG_XBISPICMD, SPICMD_WRITE_ENABLE);
  2558. + if (rom_instruction_cycle(SPICMD_WRITE_ENABLE) == EC_STATE_BUSY) {
  2559. + printk(KERN_ERR
  2560. + "EC_UNIT_ERASE : SPICMD_WRITE_ENABLE failed.\n");
  2561. + return 1;
  2562. + }
  2563. +
  2564. + return 0;
  2565. +}
  2566. +
  2567. +/* erase one block or chip or sector as needed */
  2568. +static int ec_unit_erase(unsigned char erase_cmd, unsigned int addr)
  2569. +{
  2570. + unsigned char status;
  2571. + int ret = 0, i = 0;
  2572. + int unprotect_count = 3;
  2573. + int check_flag = 0;
  2574. +
  2575. + /* enable spicmd writing. */
  2576. + ec_start_spi();
  2577. +
  2578. +#ifdef EC_ROM_PROTECTION
  2579. + /* added for re-check SPICMD_READ_STATUS */
  2580. + while (unprotect_count-- > 0) {
  2581. + if (EC_ROM_unprotect()) {
  2582. + ret = -EINVAL;
  2583. + goto out;
  2584. + }
  2585. +
  2586. + /* first time:500ms --> 5.5sec -->10.5sec */
  2587. + for (i = 0; i < ((2 - unprotect_count) * 100 + 10); i++)
  2588. + udelay(50000);
  2589. + ec_write(REG_XBISPICMD, SPICMD_READ_STATUS);
  2590. + if (rom_instruction_cycle(SPICMD_READ_STATUS)
  2591. + == EC_STATE_BUSY) {
  2592. + printk(KERN_ERR
  2593. + "EC_PROGRAM_ROM : SPICMD_READ_STATUS failed.\n");
  2594. + } else {
  2595. + status = ec_read(REG_XBISPIDAT);
  2596. + printk(KERN_INFO "Read unprotect status : 0x%x\n",
  2597. + status);
  2598. + if ((status & 0x1C) == 0x00) {
  2599. + printk(KERN_INFO
  2600. + "Read unprotect status OK1 : 0x%x\n",
  2601. + status & 0x1C);
  2602. + check_flag = 1;
  2603. + break;
  2604. + }
  2605. + }
  2606. + }
  2607. +
  2608. + if (!check_flag) {
  2609. + printk(KERN_INFO "SPI ROM unprotect fail.\n");
  2610. + return 1;
  2611. + }
  2612. +#endif
  2613. +
  2614. + /* block address fill */
  2615. + if (erase_cmd == SPICMD_BLK_ERASE) {
  2616. + ec_write(REG_XBISPIA2, (addr & 0x00ff0000) >> 16);
  2617. + ec_write(REG_XBISPIA1, (addr & 0x0000ff00) >> 8);
  2618. + ec_write(REG_XBISPIA0, (addr & 0x000000ff) >> 0);
  2619. + }
  2620. +
  2621. + /* erase the whole chip first */
  2622. + ec_write(REG_XBISPICMD, erase_cmd);
  2623. + if (rom_instruction_cycle(erase_cmd) == EC_STATE_BUSY) {
  2624. + printk(KERN_ERR "EC_UNIT_ERASE : erase failed.\n");
  2625. + ret = -EINVAL;
  2626. + goto out;
  2627. + }
  2628. +
  2629. + out:
  2630. + /* disable spicmd writing. */
  2631. + ec_stop_spi();
  2632. +
  2633. + return ret;
  2634. +}
  2635. +
  2636. +/* update the whole rom content with H/W mode
  2637. + * PLEASE USING ec_unit_erase() FIRSTLY
  2638. + */
  2639. +static int ec_program_rom(struct ec_info *info, int flag)
  2640. +{
  2641. + unsigned int addr = 0;
  2642. + unsigned long size = 0;
  2643. + unsigned char *ptr = NULL;
  2644. + unsigned char data;
  2645. + unsigned char val = 0;
  2646. + int ret = 0;
  2647. + int i, j;
  2648. + unsigned char status;
  2649. +
  2650. + /* modify for program serial No.
  2651. + * set IE_START_ADDR & use idle mode,
  2652. + * disable WDD
  2653. + */
  2654. + if (flag == PROGRAM_FLAG_ROM) {
  2655. + ret = ec_init_reset_mode();
  2656. + addr = info->start_addr + EC_START_ADDR;
  2657. + printk(KERN_INFO "PROGRAM_FLAG_ROM..............\n");
  2658. + } else if (flag == PROGRAM_FLAG_IE) {
  2659. + ret = ec_init_idle_mode();
  2660. + ec_disable_WDD();
  2661. + addr = info->start_addr + IE_START_ADDR;
  2662. + printk(KERN_INFO "PROGRAM_FLAG_IE..............\n");
  2663. + } else {
  2664. + return 0;
  2665. + }
  2666. +
  2667. + if (ret < 0) {
  2668. + if (flag == PROGRAM_FLAG_IE)
  2669. + ec_enable_WDD();
  2670. + return ret;
  2671. + }
  2672. +
  2673. + size = info->size;
  2674. + ptr = info->buf;
  2675. + printk(KERN_INFO "starting update ec ROM..............\n");
  2676. +
  2677. + ret = ec_unit_erase(SPICMD_BLK_ERASE, addr);
  2678. + if (ret) {
  2679. + printk(KERN_ERR "program ec : erase block failed.\n");
  2680. + goto out;
  2681. + }
  2682. + printk(KERN_ERR "program ec : erase block OK.\n");
  2683. +
  2684. + i = 0;
  2685. + while (i < size) {
  2686. + data = *(ptr + i);
  2687. + ec_write_byte(addr, data);
  2688. + ec_read_byte(addr, &val);
  2689. + if (val != data) {
  2690. + ec_write_byte(addr, data);
  2691. + ec_read_byte(addr, &val);
  2692. + if (val != data) {
  2693. + printk(KERN_INFO
  2694. + "EC : Second flash program failed at:\t");
  2695. + printk(KERN_INFO
  2696. + "addr : 0x%x, source : 0x%x, dest: 0x%x\n",
  2697. + addr, data, val);
  2698. + printk(KERN_INFO "This should not happen... STOP\n");
  2699. + break;
  2700. + }
  2701. + }
  2702. + i++;
  2703. + addr++;
  2704. + }
  2705. +
  2706. +#ifdef EC_ROM_PROTECTION
  2707. + /* we should start spi access firstly */
  2708. + ec_start_spi();
  2709. +
  2710. + /* enable write spi flash */
  2711. + ec_write(REG_XBISPICMD, SPICMD_WRITE_ENABLE);
  2712. + if (rom_instruction_cycle(SPICMD_WRITE_ENABLE) == EC_STATE_BUSY) {
  2713. + printk(KERN_ERR
  2714. + "EC_PROGRAM_ROM : SPICMD_WRITE_ENABLE failed.\n");
  2715. + goto out1;
  2716. + }
  2717. +
  2718. + /* protect the status register of rom */
  2719. + ec_write(REG_XBISPICMD, SPICMD_READ_STATUS);
  2720. + if (rom_instruction_cycle(SPICMD_READ_STATUS) == EC_STATE_BUSY) {
  2721. + printk(KERN_ERR
  2722. + "EC_PROGRAM_ROM : SPICMD_READ_STATUS failed.\n");
  2723. + goto out1;
  2724. + }
  2725. + status = ec_read(REG_XBISPIDAT);
  2726. +
  2727. + ec_write(REG_XBISPIDAT, status | 0x1C);
  2728. + if (ec_instruction_cycle() < 0) {
  2729. + printk(KERN_ERR
  2730. + "EC_PROGRAM_ROM : write status value failed.\n");
  2731. + goto out1;
  2732. + }
  2733. +
  2734. + ec_write(REG_XBISPICMD, SPICMD_WRITE_STATUS);
  2735. + if (rom_instruction_cycle(SPICMD_WRITE_STATUS) == EC_STATE_BUSY) {
  2736. + printk(KERN_ERR
  2737. + "EC_PROGRAM_ROM : SPICMD_WRITE_STATUS failed.\n");
  2738. + goto out1;
  2739. + }
  2740. +#endif
  2741. +
  2742. + /* disable the write action to spi rom */
  2743. + ec_write(REG_XBISPICMD, SPICMD_WRITE_DISABLE);
  2744. + if (rom_instruction_cycle(SPICMD_WRITE_DISABLE) == EC_STATE_BUSY) {
  2745. + printk(KERN_ERR
  2746. + "EC_PROGRAM_ROM : SPICMD_WRITE_DISABLE failed.\n");
  2747. + goto out1;
  2748. + }
  2749. +
  2750. + out1:
  2751. + /* we should stop spi access firstly */
  2752. + ec_stop_spi();
  2753. + out:
  2754. + /* for security */
  2755. + for (j = 0; j < 2000; j++)
  2756. + udelay(1000);
  2757. +
  2758. + /* modify for program serial No.
  2759. + * after program No exit idle mode
  2760. + * and enable WDD
  2761. + */
  2762. + if (flag == PROGRAM_FLAG_ROM) {
  2763. + /* exit from the reset mode */
  2764. + ec_exit_reset_mode();
  2765. + } else {
  2766. + /* ec exit from idle mode */
  2767. + ret = ec_exit_idle_mode();
  2768. + ec_enable_WDD();
  2769. + if (ret < 0)
  2770. + return ret;
  2771. + }
  2772. +
  2773. + return 0;
  2774. +}
  2775. +
  2776. +/* ioctl */
  2777. +static int misc_ioctl(struct inode *inode, struct file *filp, u_int cmd,
  2778. + u_long arg)
  2779. +{
  2780. + struct ec_info ecinfo;
  2781. + void __user *ptr = (void __user *)arg;
  2782. + struct ec_reg *ecreg = (struct ec_reg *)(filp->private_data);
  2783. + int ret = 0;
  2784. +
  2785. + switch (cmd) {
  2786. + case IOCTL_RDREG:
  2787. + ret = copy_from_user(ecreg, ptr, sizeof(struct ec_reg));
  2788. + if (ret) {
  2789. + printk(KERN_ERR "reg read : copy from user error.\n");
  2790. + return -EFAULT;
  2791. + }
  2792. + if ((ecreg->addr > EC_MAX_REGADDR)
  2793. + || (ecreg->addr < EC_MIN_REGADDR)) {
  2794. + printk(KERN_ERR
  2795. + "reg read : out of register address range.\n");
  2796. + return -EINVAL;
  2797. + }
  2798. + ecreg->val = ec_read(ecreg->addr);
  2799. + ret = copy_to_user(ptr, ecreg, sizeof(struct ec_reg));
  2800. + if (ret) {
  2801. + printk(KERN_ERR "reg read : copy to user error.\n");
  2802. + return -EFAULT;
  2803. + }
  2804. + break;
  2805. + case IOCTL_WRREG:
  2806. + ret = copy_from_user(ecreg, ptr, sizeof(struct ec_reg));
  2807. + if (ret) {
  2808. + printk(KERN_ERR "reg write : copy from user error.\n");
  2809. + return -EFAULT;
  2810. + }
  2811. + if ((ecreg->addr > EC_MAX_REGADDR)
  2812. + || (ecreg->addr < EC_MIN_REGADDR)) {
  2813. + printk(KERN_ERR
  2814. + "reg write : out of register address range.\n");
  2815. + return -EINVAL;
  2816. + }
  2817. + ec_write(ecreg->addr, ecreg->val);
  2818. + break;
  2819. + case IOCTL_READ_EC:
  2820. + ret = copy_from_user(ecreg, ptr, sizeof(struct ec_reg));
  2821. + if (ret) {
  2822. + printk(KERN_ERR "spi read : copy from user error.\n");
  2823. + return -EFAULT;
  2824. + }
  2825. + if ((ecreg->addr > EC_RAM_ADDR)
  2826. + && (ecreg->addr < EC_MAX_REGADDR)) {
  2827. + printk(KERN_ERR
  2828. + "spi read : out of register address range.\n");
  2829. + return -EINVAL;
  2830. + }
  2831. + ec_read_byte(ecreg->addr, &(ecreg->val));
  2832. + ret = copy_to_user(ptr, ecreg, sizeof(struct ec_reg));
  2833. + if (ret) {
  2834. + printk(KERN_ERR "spi read : copy to user error.\n");
  2835. + return -EFAULT;
  2836. + }
  2837. + break;
  2838. + case IOCTL_PROGRAM_IE:
  2839. + ecinfo.start_addr = EC_START_ADDR;
  2840. + ecinfo.size = EC_CONTENT_MAX_SIZE;
  2841. + ecinfo.buf = (u8 *) kmalloc(ecinfo.size, GFP_KERNEL);
  2842. + if (ecinfo.buf == NULL) {
  2843. + printk(KERN_ERR "program ie : kmalloc failed.\n");
  2844. + return -ENOMEM;
  2845. + }
  2846. + ret = copy_from_user(ecinfo.buf, (u8 *) ptr, ecinfo.size);
  2847. + if (ret) {
  2848. + printk(KERN_ERR "program ie : copy from user error.\n");
  2849. + kfree(ecinfo.buf);
  2850. + ecinfo.buf = NULL;
  2851. + return -EFAULT;
  2852. + }
  2853. +
  2854. + /* use ec_program_rom to write serial No */
  2855. + ec_program_rom(&ecinfo, PROGRAM_FLAG_IE);
  2856. +
  2857. + kfree(ecinfo.buf);
  2858. + ecinfo.buf = NULL;
  2859. + break;
  2860. + case IOCTL_PROGRAM_EC:
  2861. + ecinfo.start_addr = EC_START_ADDR;
  2862. + if (get_user((ecinfo.size), (u32 *) ptr)) {
  2863. + printk(KERN_ERR "program ec : get user error.\n");
  2864. + return -EFAULT;
  2865. + }
  2866. + if ((ecinfo.size) > EC_CONTENT_MAX_SIZE) {
  2867. + printk(KERN_ERR "program ec : size out of limited.\n");
  2868. + return -EINVAL;
  2869. + }
  2870. + ecinfo.buf = (u8 *) kmalloc(ecinfo.size, GFP_KERNEL);
  2871. + if (ecinfo.buf == NULL) {
  2872. + printk(KERN_ERR "program ec : kmalloc failed.\n");
  2873. + return -ENOMEM;
  2874. + }
  2875. + ret = copy_from_user(ecinfo.buf, ((u8 *) ptr + 4), ecinfo.size);
  2876. + if (ret) {
  2877. + printk(KERN_ERR "program ec : copy from user error.\n");
  2878. + kfree(ecinfo.buf);
  2879. + ecinfo.buf = NULL;
  2880. + return -EFAULT;
  2881. + }
  2882. +
  2883. + ec_program_rom(&ecinfo, PROGRAM_FLAG_ROM);
  2884. +
  2885. + kfree(ecinfo.buf);
  2886. + ecinfo.buf = NULL;
  2887. + break;
  2888. +
  2889. + default:
  2890. + break;
  2891. + }
  2892. +
  2893. + return 0;
  2894. +}
  2895. +
  2896. +static long misc_compat_ioctl(struct file *file, unsigned int cmd,
  2897. + unsigned long arg)
  2898. +{
  2899. + return misc_ioctl(file->f_dentry->d_inode, file, cmd, arg);
  2900. +}
  2901. +
  2902. +static int misc_open(struct inode *inode, struct file *filp)
  2903. +{
  2904. + struct ec_reg *ecreg = NULL;
  2905. + ecreg = kmalloc(sizeof(struct ec_reg), GFP_KERNEL);
  2906. + if (ecreg)
  2907. + filp->private_data = ecreg;
  2908. +
  2909. + return ecreg ? 0 : -ENOMEM;
  2910. +}
  2911. +
  2912. +static int misc_release(struct inode *inode, struct file *filp)
  2913. +{
  2914. + struct ec_reg *ecreg = (struct ec_reg *)(filp->private_data);
  2915. +
  2916. + filp->private_data = NULL;
  2917. + kfree(ecreg);
  2918. +
  2919. + return 0;
  2920. +}
  2921. +
  2922. +static const struct file_operations ecmisc_fops = {
  2923. + .open = misc_open,
  2924. + .release = misc_release,
  2925. + .read = NULL,
  2926. + .write = NULL,
  2927. +#ifdef CONFIG_64BIT
  2928. + .compat_ioctl = misc_compat_ioctl,
  2929. +#else
  2930. + .ioctl = misc_ioctl,
  2931. +#endif
  2932. +};
  2933. +
  2934. +static struct miscdevice ecmisc_device = {
  2935. + .minor = MISC_DYNAMIC_MINOR,
  2936. + .name = EC_MISC_DEV,
  2937. + .fops = &ecmisc_fops
  2938. +};
  2939. +
  2940. +static int __init ecmisc_init(void)
  2941. +{
  2942. + int ret;
  2943. +
  2944. + printk(KERN_INFO "EC misc device init.\n");
  2945. + ret = misc_register(&ecmisc_device);
  2946. +
  2947. + return ret;
  2948. +}
  2949. +
  2950. +static void __exit ecmisc_exit(void)
  2951. +{
  2952. + printk(KERN_INFO "EC misc device exit.\n");
  2953. + misc_deregister(&ecmisc_device);
  2954. +}
  2955. +
  2956. +module_init(ecmisc_init);
  2957. +module_exit(ecmisc_exit);
  2958. +
  2959. +MODULE_AUTHOR("liujl <liujl@lemote.com>");
  2960. +MODULE_DESCRIPTION("Driver for flushing/dumping ROM of EC on YeeLoong laptop");
  2961. +MODULE_LICENSE("GPL");
  2962. diff -Nur linux-2.6.37.orig/drivers/platform/mips/yeeloong_laptop.c linux-2.6.37/drivers/platform/mips/yeeloong_laptop.c
  2963. --- linux-2.6.37.orig/drivers/platform/mips/yeeloong_laptop.c 1970-01-01 01:00:00.000000000 +0100
  2964. +++ linux-2.6.37/drivers/platform/mips/yeeloong_laptop.c 2011-01-11 20:44:43.000000000 +0100
  2965. @@ -0,0 +1,1200 @@
  2966. +/*
  2967. + * Driver for YeeLoong laptop extras
  2968. + *
  2969. + * Copyright (C) 2009 Lemote Inc.
  2970. + * Author: Wu Zhangjin <wuzhangjin@gmail.com>, Liu Junliang <liujl@lemote.com>
  2971. + *
  2972. + * This program is free software; you can redistribute it and/or modify
  2973. + * it under the terms of the GNU General Public License version 2 as
  2974. + * published by the Free Software Foundation.
  2975. + */
  2976. +
  2977. +#include <linux/err.h>
  2978. +#include <linux/platform_device.h>
  2979. +#include <linux/backlight.h> /* for backlight subdriver */
  2980. +#include <linux/fb.h>
  2981. +#include <linux/hwmon.h> /* for hwmon subdriver */
  2982. +#include <linux/hwmon-sysfs.h>
  2983. +#include <linux/video_output.h> /* for video output subdriver */
  2984. +#include <linux/input.h> /* for hotkey subdriver */
  2985. +#include <linux/input/sparse-keymap.h>
  2986. +#include <linux/interrupt.h>
  2987. +#include <linux/delay.h>
  2988. +#include <linux/power_supply.h> /* for AC & Battery subdriver */
  2989. +
  2990. +#include <cs5536/cs5536.h>
  2991. +
  2992. +#include <loongson.h> /* for loongson_cmdline */
  2993. +#include <ec_kb3310b.h>
  2994. +
  2995. +/* common function */
  2996. +#define EC_VER_LEN 64
  2997. +
  2998. +static int ec_version_before(char *version)
  2999. +{
  3000. + char *p, ec_ver[EC_VER_LEN];
  3001. +
  3002. + p = strstr(loongson_cmdline, "EC_VER=");
  3003. + if (!p)
  3004. + memset(ec_ver, 0, EC_VER_LEN);
  3005. + else {
  3006. + strncpy(ec_ver, p, EC_VER_LEN);
  3007. + p = strstr(ec_ver, " ");
  3008. + if (p)
  3009. + *p = '\0';
  3010. + }
  3011. +
  3012. + return (strncasecmp(ec_ver, version, 64) < 0);
  3013. +}
  3014. +
  3015. +/* backlight subdriver */
  3016. +#define MAX_BRIGHTNESS 8
  3017. +
  3018. +static int yeeloong_set_brightness(struct backlight_device *bd)
  3019. +{
  3020. + unsigned int level, current_level;
  3021. + static unsigned int old_level;
  3022. +
  3023. + level = (bd->props.fb_blank == FB_BLANK_UNBLANK &&
  3024. + bd->props.power == FB_BLANK_UNBLANK) ?
  3025. + bd->props.brightness : 0;
  3026. +
  3027. + level = SENSORS_LIMIT(level, 0, MAX_BRIGHTNESS);
  3028. +
  3029. + /* Avoid to modify the brightness when EC is tuning it */
  3030. + if (old_level != level) {
  3031. + current_level = ec_read(REG_DISPLAY_BRIGHTNESS);
  3032. + if (old_level == current_level)
  3033. + ec_write(REG_DISPLAY_BRIGHTNESS, level);
  3034. + old_level = level;
  3035. + }
  3036. +
  3037. + return 0;
  3038. +}
  3039. +
  3040. +static int yeeloong_get_brightness(struct backlight_device *bd)
  3041. +{
  3042. + return ec_read(REG_DISPLAY_BRIGHTNESS);
  3043. +}
  3044. +
  3045. +static struct backlight_ops backlight_ops = {
  3046. + .get_brightness = yeeloong_get_brightness,
  3047. + .update_status = yeeloong_set_brightness,
  3048. +};
  3049. +
  3050. +static struct backlight_device *yeeloong_backlight_dev;
  3051. +
  3052. +static int yeeloong_backlight_init(void)
  3053. +{
  3054. + int ret;
  3055. + struct backlight_properties props;
  3056. +
  3057. + memset(&props, 0, sizeof(struct backlight_properties));
  3058. + props.max_brightness = MAX_BRIGHTNESS;
  3059. + yeeloong_backlight_dev = backlight_device_register("backlight0", NULL,
  3060. + NULL, &backlight_ops, &props);
  3061. +
  3062. + if (IS_ERR(yeeloong_backlight_dev)) {
  3063. + ret = PTR_ERR(yeeloong_backlight_dev);
  3064. + yeeloong_backlight_dev = NULL;
  3065. + return ret;
  3066. + }
  3067. +
  3068. + yeeloong_backlight_dev->props.brightness =
  3069. + yeeloong_get_brightness(yeeloong_backlight_dev);
  3070. + backlight_update_status(yeeloong_backlight_dev);
  3071. +
  3072. + return 0;
  3073. +}
  3074. +
  3075. +static void yeeloong_backlight_exit(void)
  3076. +{
  3077. + if (yeeloong_backlight_dev) {
  3078. + backlight_device_unregister(yeeloong_backlight_dev);
  3079. + yeeloong_backlight_dev = NULL;
  3080. + }
  3081. +}
  3082. +
  3083. +/* AC & Battery subdriver */
  3084. +
  3085. +static struct power_supply yeeloong_ac, yeeloong_bat;
  3086. +
  3087. +#define AC_OFFLINE 0
  3088. +#define AC_ONLINE 1
  3089. +
  3090. +static int yeeloong_get_ac_props(struct power_supply *psy,
  3091. + enum power_supply_property psp,
  3092. + union power_supply_propval *val)
  3093. +{
  3094. + switch (psp) {
  3095. + case POWER_SUPPLY_PROP_ONLINE:
  3096. + val->intval = ((ec_read(REG_BAT_POWER)) & BIT_BAT_POWER_ACIN) ?
  3097. + AC_ONLINE : AC_OFFLINE;
  3098. + break;
  3099. + default:
  3100. + return -EINVAL;
  3101. + }
  3102. +
  3103. + return 0;
  3104. +}
  3105. +
  3106. +static enum power_supply_property yeeloong_ac_props[] = {
  3107. + POWER_SUPPLY_PROP_ONLINE,
  3108. +};
  3109. +
  3110. +static struct power_supply yeeloong_ac = {
  3111. + .name = "yeeloong-ac",
  3112. + .type = POWER_SUPPLY_TYPE_MAINS,
  3113. + .properties = yeeloong_ac_props,
  3114. + .num_properties = ARRAY_SIZE(yeeloong_ac_props),
  3115. + .get_property = yeeloong_get_ac_props,
  3116. +};
  3117. +
  3118. +#define BAT_CAP_CRITICAL 5
  3119. +#define BAT_CAP_HIGH 99
  3120. +
  3121. +#define get_bat_info(type) \
  3122. + ((ec_read(REG_BAT_##type##_HIGH) << 8) | \
  3123. + (ec_read(REG_BAT_##type##_LOW)))
  3124. +
  3125. +static int yeeloong_bat_get_ex_property(enum power_supply_property psp,
  3126. + union power_supply_propval *val)
  3127. +{
  3128. + int bat_in, curr_cap, cap_level, status, charge, health;
  3129. +
  3130. + status = ec_read(REG_BAT_STATUS);
  3131. + bat_in = status & BIT_BAT_STATUS_IN;
  3132. + curr_cap = get_bat_info(RELATIVE_CAP);
  3133. + if (status & BIT_BAT_STATUS_FULL)
  3134. + curr_cap = 100;
  3135. +
  3136. + switch (psp) {
  3137. + case POWER_SUPPLY_PROP_PRESENT:
  3138. + val->intval = bat_in;
  3139. + break;
  3140. + case POWER_SUPPLY_PROP_CAPACITY:
  3141. + val->intval = curr_cap;
  3142. + break;
  3143. + case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
  3144. + cap_level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
  3145. + if (status & BIT_BAT_STATUS_LOW) {
  3146. + cap_level = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
  3147. + if (curr_cap <= BAT_CAP_CRITICAL)
  3148. + cap_level =
  3149. + POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
  3150. + } else if (status & BIT_BAT_STATUS_FULL) {
  3151. + cap_level = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
  3152. + if (curr_cap >= BAT_CAP_HIGH)
  3153. + cap_level = POWER_SUPPLY_CAPACITY_LEVEL_HIGH;
  3154. + } else if (status & BIT_BAT_STATUS_DESTROY)
  3155. + cap_level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
  3156. + val->intval = cap_level;
  3157. + break;
  3158. + case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
  3159. + /* seconds */
  3160. + val->intval = bat_in ? (curr_cap - 3) * 54 + 142 : 0;
  3161. + break;
  3162. + case POWER_SUPPLY_PROP_STATUS:
  3163. + if (!bat_in)
  3164. + charge = POWER_SUPPLY_STATUS_UNKNOWN;
  3165. + else {
  3166. + if (status & BIT_BAT_STATUS_FULL) {
  3167. + val->intval = POWER_SUPPLY_STATUS_FULL;
  3168. + break;
  3169. + }
  3170. +
  3171. + charge = ec_read(REG_BAT_CHARGE);
  3172. + if (charge & FLAG_BAT_CHARGE_DISCHARGE)
  3173. + charge = POWER_SUPPLY_STATUS_DISCHARGING;
  3174. + else if (charge & FLAG_BAT_CHARGE_CHARGE)
  3175. + charge = POWER_SUPPLY_STATUS_CHARGING;
  3176. + else
  3177. + charge = POWER_SUPPLY_STATUS_NOT_CHARGING;
  3178. + }
  3179. + val->intval = charge;
  3180. + break;
  3181. + case POWER_SUPPLY_PROP_HEALTH:
  3182. + if (!bat_in) /* no battery present */
  3183. + health = POWER_SUPPLY_HEALTH_UNKNOWN;
  3184. + else { /* Assume it is good */
  3185. + health = POWER_SUPPLY_HEALTH_GOOD;
  3186. + if (status &
  3187. + (BIT_BAT_STATUS_DESTROY | BIT_BAT_STATUS_LOW))
  3188. + health = POWER_SUPPLY_HEALTH_DEAD;
  3189. + if (ec_read(REG_BAT_CHARGE_STATUS) &
  3190. + BIT_BAT_CHARGE_STATUS_OVERTEMP)
  3191. + health = POWER_SUPPLY_HEALTH_OVERHEAT;
  3192. + }
  3193. + val->intval = health;
  3194. + break;
  3195. + case POWER_SUPPLY_PROP_CHARGE_NOW: /* 1/100(%)*1000 µAh */
  3196. + val->intval = curr_cap * get_bat_info(FULLCHG_CAP) * 10;
  3197. + break;
  3198. + default:
  3199. + return -EINVAL;
  3200. + }
  3201. + return 0;
  3202. +}
  3203. +
  3204. +static int get_battery_temp(void)
  3205. +{
  3206. + int value;
  3207. +
  3208. + value = get_bat_info(TEMPERATURE);
  3209. +
  3210. + return value * 1000;
  3211. +}
  3212. +
  3213. +static int get_battery_current(void)
  3214. +{
  3215. + s16 value;
  3216. +
  3217. + value = get_bat_info(CURRENT);
  3218. +
  3219. + return -value;
  3220. +}
  3221. +
  3222. +static int get_battery_voltage(void)
  3223. +{
  3224. + int value;
  3225. +
  3226. + value = get_bat_info(VOLTAGE);
  3227. +
  3228. + return value;
  3229. +}
  3230. +
  3231. +static int yeeloong_get_bat_props(struct power_supply *psy,
  3232. + enum power_supply_property psp,
  3233. + union power_supply_propval *val)
  3234. +{
  3235. + switch (psp) {
  3236. + /* Fixed information */
  3237. + case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
  3238. + val->intval = get_bat_info(DESIGN_VOL) * 1000; /* mV -> µV */
  3239. + break;
  3240. + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
  3241. + val->intval = get_bat_info(DESIGN_CAP) * 1000; /* mAh->µAh */
  3242. + break;
  3243. + case POWER_SUPPLY_PROP_CHARGE_FULL:
  3244. + val->intval = get_bat_info(FULLCHG_CAP) * 1000; /* µAh */
  3245. + break;
  3246. + case POWER_SUPPLY_PROP_MANUFACTURER:
  3247. + val->strval = (ec_read(REG_BAT_VENDOR) ==
  3248. + FLAG_BAT_VENDOR_SANYO) ? "SANYO" : "SIMPLO";
  3249. + break;
  3250. + /* Dynamic information */
  3251. + case POWER_SUPPLY_PROP_CURRENT_NOW:
  3252. + val->intval = get_battery_current() * 1000; /* mA -> µA */
  3253. + break;
  3254. + case POWER_SUPPLY_PROP_VOLTAGE_NOW:
  3255. + val->intval = get_battery_voltage() * 1000; /* mV -> µV */
  3256. + break;
  3257. + case POWER_SUPPLY_PROP_TEMP:
  3258. + val->intval = get_battery_temp(); /* Celcius */
  3259. + break;
  3260. + /* Dynamic but related information */
  3261. + default:
  3262. + return yeeloong_bat_get_ex_property(psp, val);
  3263. + }
  3264. +
  3265. + return 0;
  3266. +}
  3267. +
  3268. +static enum power_supply_property yeeloong_bat_props[] = {
  3269. + POWER_SUPPLY_PROP_STATUS,
  3270. + POWER_SUPPLY_PROP_PRESENT,
  3271. + POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
  3272. + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
  3273. + POWER_SUPPLY_PROP_CHARGE_FULL,
  3274. + POWER_SUPPLY_PROP_CHARGE_NOW,
  3275. + POWER_SUPPLY_PROP_CURRENT_NOW,
  3276. + POWER_SUPPLY_PROP_VOLTAGE_NOW,
  3277. + POWER_SUPPLY_PROP_HEALTH,
  3278. + POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
  3279. + POWER_SUPPLY_PROP_CAPACITY,
  3280. + POWER_SUPPLY_PROP_CAPACITY_LEVEL,
  3281. + POWER_SUPPLY_PROP_TEMP,
  3282. + POWER_SUPPLY_PROP_MANUFACTURER,
  3283. +};
  3284. +
  3285. +static struct power_supply yeeloong_bat = {
  3286. + .name = "yeeloong-bat",
  3287. + .type = POWER_SUPPLY_TYPE_BATTERY,
  3288. + .properties = yeeloong_bat_props,
  3289. + .num_properties = ARRAY_SIZE(yeeloong_bat_props),
  3290. + .get_property = yeeloong_get_bat_props,
  3291. +};
  3292. +
  3293. +static int ac_bat_initialized;
  3294. +
  3295. +static int yeeloong_bat_init(void)
  3296. +{
  3297. + int ret;
  3298. +
  3299. + ret = power_supply_register(NULL, &yeeloong_ac);
  3300. + if (ret)
  3301. + return ret;
  3302. + ret = power_supply_register(NULL, &yeeloong_bat);
  3303. + if (ret) {
  3304. + power_supply_unregister(&yeeloong_ac);
  3305. + return ret;
  3306. + }
  3307. + ac_bat_initialized = 1;
  3308. +
  3309. + return 0;
  3310. +}
  3311. +
  3312. +static void yeeloong_bat_exit(void)
  3313. +{
  3314. + ac_bat_initialized = 0;
  3315. +
  3316. + power_supply_unregister(&yeeloong_ac);
  3317. + power_supply_unregister(&yeeloong_bat);
  3318. +}
  3319. +/* hwmon subdriver */
  3320. +
  3321. +#define MIN_FAN_SPEED 0
  3322. +#define MAX_FAN_SPEED 3
  3323. +
  3324. +static int get_fan_pwm_enable(void)
  3325. +{
  3326. + int level, mode;
  3327. +
  3328. + level = ec_read(REG_FAN_SPEED_LEVEL);
  3329. + mode = ec_read(REG_FAN_AUTO_MAN_SWITCH);
  3330. +
  3331. + if (level == MAX_FAN_SPEED && mode == BIT_FAN_MANUAL)
  3332. + mode = 0;
  3333. + else if (mode == BIT_FAN_MANUAL)
  3334. + mode = 1;
  3335. + else
  3336. + mode = 2;
  3337. +
  3338. + return mode;
  3339. +}
  3340. +
  3341. +static void set_fan_pwm_enable(int mode)
  3342. +{
  3343. + switch (mode) {
  3344. + case 0:
  3345. + /* fullspeed */
  3346. + ec_write(REG_FAN_AUTO_MAN_SWITCH, BIT_FAN_MANUAL);
  3347. + ec_write(REG_FAN_SPEED_LEVEL, MAX_FAN_SPEED);
  3348. + break;
  3349. + case 1:
  3350. + ec_write(REG_FAN_AUTO_MAN_SWITCH, BIT_FAN_MANUAL);
  3351. + break;
  3352. + case 2:
  3353. + ec_write(REG_FAN_AUTO_MAN_SWITCH, BIT_FAN_AUTO);
  3354. + break;
  3355. + default:
  3356. + break;
  3357. + }
  3358. +}
  3359. +
  3360. +static int get_fan_pwm(void)
  3361. +{
  3362. + return ec_read(REG_FAN_SPEED_LEVEL);
  3363. +}
  3364. +
  3365. +static void set_fan_pwm(int value)
  3366. +{
  3367. + int mode;
  3368. +
  3369. + mode = ec_read(REG_FAN_AUTO_MAN_SWITCH);
  3370. + if (mode != BIT_FAN_MANUAL)
  3371. + return;
  3372. +
  3373. + value = SENSORS_LIMIT(value, 0, 3);
  3374. +
  3375. + /* We must ensure the fan is on */
  3376. + if (value > 0)
  3377. + ec_write(REG_FAN_CONTROL, BIT_FAN_CONTROL_ON);
  3378. +
  3379. + ec_write(REG_FAN_SPEED_LEVEL, value);
  3380. +}
  3381. +
  3382. +static int get_fan_rpm(void)
  3383. +{
  3384. + int value;
  3385. +
  3386. + value = FAN_SPEED_DIVIDER /
  3387. + (((ec_read(REG_FAN_SPEED_HIGH) & 0x0f) << 8) |
  3388. + ec_read(REG_FAN_SPEED_LOW));
  3389. +
  3390. + return value;
  3391. +}
  3392. +
  3393. +static int get_cpu_temp(void)
  3394. +{
  3395. + s8 value;
  3396. +
  3397. + value = ec_read(REG_TEMPERATURE_VALUE);
  3398. +
  3399. + return value * 1000;
  3400. +}
  3401. +
  3402. +static int get_cpu_temp_max(void)
  3403. +{
  3404. + return 60 * 1000;
  3405. +}
  3406. +
  3407. +static int get_battery_temp_alarm(void)
  3408. +{
  3409. + int status;
  3410. +
  3411. + status = (ec_read(REG_BAT_CHARGE_STATUS) &
  3412. + BIT_BAT_CHARGE_STATUS_OVERTEMP);
  3413. +
  3414. + return !!status;
  3415. +}
  3416. +
  3417. +static ssize_t store_sys_hwmon(void (*set) (int), const char *buf, size_t count)
  3418. +{
  3419. + int ret;
  3420. + unsigned long value;
  3421. +
  3422. + if (!count)
  3423. + return 0;
  3424. +
  3425. + ret = strict_strtoul(buf, 10, &value);
  3426. + if (ret)
  3427. + return ret;
  3428. +
  3429. + set(value);
  3430. +
  3431. + return count;
  3432. +}
  3433. +
  3434. +static ssize_t show_sys_hwmon(int (*get) (void), char *buf)
  3435. +{
  3436. + return sprintf(buf, "%d\n", get());
  3437. +}
  3438. +
  3439. +#define CREATE_SENSOR_ATTR(_name, _mode, _set, _get) \
  3440. + static ssize_t show_##_name(struct device *dev, \
  3441. + struct device_attribute *attr, \
  3442. + char *buf) \
  3443. + { \
  3444. + return show_sys_hwmon(_set, buf); \
  3445. + } \
  3446. + static ssize_t store_##_name(struct device *dev, \
  3447. + struct device_attribute *attr, \
  3448. + const char *buf, size_t count) \
  3449. + { \
  3450. + return store_sys_hwmon(_get, buf, count); \
  3451. + } \
  3452. + static SENSOR_DEVICE_ATTR(_name, _mode, show_##_name, store_##_name, 0);
  3453. +
  3454. +CREATE_SENSOR_ATTR(fan1_input, S_IRUGO, get_fan_rpm, NULL);
  3455. +CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR, get_fan_pwm, set_fan_pwm);
  3456. +CREATE_SENSOR_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, get_fan_pwm_enable,
  3457. + set_fan_pwm_enable);
  3458. +CREATE_SENSOR_ATTR(temp1_input, S_IRUGO, get_cpu_temp, NULL);
  3459. +CREATE_SENSOR_ATTR(temp1_max, S_IRUGO, get_cpu_temp_max, NULL);
  3460. +CREATE_SENSOR_ATTR(temp2_input, S_IRUGO, get_battery_temp, NULL);
  3461. +CREATE_SENSOR_ATTR(temp2_max_alarm, S_IRUGO, get_battery_temp_alarm, NULL);
  3462. +CREATE_SENSOR_ATTR(curr1_input, S_IRUGO, get_battery_current, NULL);
  3463. +CREATE_SENSOR_ATTR(in1_input, S_IRUGO, get_battery_voltage, NULL);
  3464. +
  3465. +static ssize_t
  3466. +show_name(struct device *dev, struct device_attribute *attr, char *buf)
  3467. +{
  3468. + return sprintf(buf, "yeeloong\n");
  3469. +}
  3470. +
  3471. +static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0);
  3472. +
  3473. +static struct attribute *hwmon_attributes[] = {
  3474. + &sensor_dev_attr_pwm1.dev_attr.attr,
  3475. + &sensor_dev_attr_pwm1_enable.dev_attr.attr,
  3476. + &sensor_dev_attr_fan1_input.dev_attr.attr,
  3477. + &sensor_dev_attr_temp1_input.dev_attr.attr,
  3478. + &sensor_dev_attr_temp1_max.dev_attr.attr,
  3479. + &sensor_dev_attr_temp2_input.dev_attr.attr,
  3480. + &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
  3481. + &sensor_dev_attr_curr1_input.dev_attr.attr,
  3482. + &sensor_dev_attr_in1_input.dev_attr.attr,
  3483. + &sensor_dev_attr_name.dev_attr.attr,
  3484. + NULL
  3485. +};
  3486. +
  3487. +static struct attribute_group hwmon_attribute_group = {
  3488. + .attrs = hwmon_attributes
  3489. +};
  3490. +
  3491. +static struct device *yeeloong_hwmon_dev;
  3492. +
  3493. +static int yeeloong_hwmon_init(void)
  3494. +{
  3495. + int ret;
  3496. +
  3497. + yeeloong_hwmon_dev = hwmon_device_register(NULL);
  3498. + if (IS_ERR(yeeloong_hwmon_dev)) {
  3499. + pr_err("Fail to register yeeloong hwmon device\n");
  3500. + yeeloong_hwmon_dev = NULL;
  3501. + return PTR_ERR(yeeloong_hwmon_dev);
  3502. + }
  3503. + ret = sysfs_create_group(&yeeloong_hwmon_dev->kobj,
  3504. + &hwmon_attribute_group);
  3505. + if (ret) {
  3506. + hwmon_device_unregister(yeeloong_hwmon_dev);
  3507. + yeeloong_hwmon_dev = NULL;
  3508. + return ret;
  3509. + }
  3510. + /* ensure fan is set to auto mode */
  3511. + set_fan_pwm_enable(2);
  3512. +
  3513. + return 0;
  3514. +}
  3515. +
  3516. +static void yeeloong_hwmon_exit(void)
  3517. +{
  3518. + if (yeeloong_hwmon_dev) {
  3519. + sysfs_remove_group(&yeeloong_hwmon_dev->kobj,
  3520. + &hwmon_attribute_group);
  3521. + hwmon_device_unregister(yeeloong_hwmon_dev);
  3522. + yeeloong_hwmon_dev = NULL;
  3523. + }
  3524. +}
  3525. +
  3526. +/* video output subdriver */
  3527. +
  3528. +static int lcd_video_output_get(struct output_device *od)
  3529. +{
  3530. + return ec_read(REG_DISPLAY_LCD);
  3531. +}
  3532. +
  3533. +#define LCD 0
  3534. +#define CRT 1
  3535. +
  3536. +static void display_vo_set(int display, int on)
  3537. +{
  3538. + int addr;
  3539. + unsigned long value;
  3540. +
  3541. + addr = (display == LCD) ? 0x31 : 0x21;
  3542. +
  3543. + outb(addr, 0x3c4);
  3544. + value = inb(0x3c5);
  3545. +
  3546. + if (display == LCD)
  3547. + value |= (on ? 0x03 : 0x02);
  3548. + else {
  3549. + if (on)
  3550. + clear_bit(7, &value);
  3551. + else
  3552. + set_bit(7, &value);
  3553. + }
  3554. +
  3555. + outb(addr, 0x3c4);
  3556. + outb(value, 0x3c5);
  3557. +}
  3558. +
  3559. +static int lcd_video_output_set(struct output_device *od)
  3560. +{
  3561. + unsigned long status;
  3562. +
  3563. + status = !!od->request_state;
  3564. +
  3565. + display_vo_set(LCD, status);
  3566. + ec_write(REG_BACKLIGHT_CTRL, status);
  3567. +
  3568. + return 0;
  3569. +}
  3570. +
  3571. +static struct output_properties lcd_output_properties = {
  3572. + .set_state = lcd_video_output_set,
  3573. + .get_status = lcd_video_output_get,
  3574. +};
  3575. +
  3576. +static int crt_video_output_get(struct output_device *od)
  3577. +{
  3578. + return ec_read(REG_CRT_DETECT);
  3579. +}
  3580. +
  3581. +static int crt_video_output_set(struct output_device *od)
  3582. +{
  3583. + unsigned long status;
  3584. +
  3585. + status = !!od->request_state;
  3586. +
  3587. + if (ec_read(REG_CRT_DETECT) == BIT_CRT_DETECT_PLUG)
  3588. + display_vo_set(CRT, status);
  3589. +
  3590. + return 0;
  3591. +}
  3592. +
  3593. +static struct output_properties crt_output_properties = {
  3594. + .set_state = crt_video_output_set,
  3595. + .get_status = crt_video_output_get,
  3596. +};
  3597. +
  3598. +static struct output_device *lcd_output_dev, *crt_output_dev;
  3599. +
  3600. +static void yeeloong_lcd_vo_set(int status)
  3601. +{
  3602. + lcd_output_dev->request_state = status;
  3603. + lcd_video_output_set(lcd_output_dev);
  3604. +}
  3605. +
  3606. +static void yeeloong_crt_vo_set(int status)
  3607. +{
  3608. + crt_output_dev->request_state = status;
  3609. + crt_video_output_set(crt_output_dev);
  3610. +}
  3611. +
  3612. +static int yeeloong_vo_init(void)
  3613. +{
  3614. + int ret;
  3615. +
  3616. + /* Register video output device: lcd, crt */
  3617. + lcd_output_dev = video_output_register("LCD", NULL, NULL,
  3618. + &lcd_output_properties);
  3619. +
  3620. + if (IS_ERR(lcd_output_dev)) {
  3621. + ret = PTR_ERR(lcd_output_dev);
  3622. + lcd_output_dev = NULL;
  3623. + return ret;
  3624. + }
  3625. + /* Ensure LCD is on by default */
  3626. + yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_ON);
  3627. +
  3628. + crt_output_dev = video_output_register("CRT", NULL, NULL,
  3629. + &crt_output_properties);
  3630. +
  3631. + if (IS_ERR(crt_output_dev)) {
  3632. + ret = PTR_ERR(crt_output_dev);
  3633. + crt_output_dev = NULL;
  3634. + return ret;
  3635. + }
  3636. +
  3637. + /* Turn off CRT by default, and will be enabled when the CRT
  3638. + * connectting event reported by SCI */
  3639. + yeeloong_crt_vo_set(BIT_CRT_DETECT_UNPLUG);
  3640. +
  3641. + return 0;
  3642. +}
  3643. +
  3644. +static void yeeloong_vo_exit(void)
  3645. +{
  3646. + if (lcd_output_dev) {
  3647. + video_output_unregister(lcd_output_dev);
  3648. + lcd_output_dev = NULL;
  3649. + }
  3650. + if (crt_output_dev) {
  3651. + video_output_unregister(crt_output_dev);
  3652. + crt_output_dev = NULL;
  3653. + }
  3654. +}
  3655. +
  3656. +/* hotkey subdriver */
  3657. +
  3658. +static struct input_dev *yeeloong_hotkey_dev;
  3659. +
  3660. +static const struct key_entry yeeloong_keymap[] = {
  3661. + {KE_SW, EVENT_LID, { SW_LID } },
  3662. + {KE_KEY, EVENT_CAMERA, { KEY_CAMERA } }, /* Fn + ESC */
  3663. + {KE_KEY, EVENT_SLEEP, { KEY_SLEEP } }, /* Fn + F1 */
  3664. + {KE_KEY, EVENT_DISPLAYTOGGLE, { KEY_DISPLAYTOGGLE } }, /* Fn + F2 */
  3665. + {KE_KEY, EVENT_SWITCHVIDEOMODE, { KEY_SWITCHVIDEOMODE } }, /* Fn + F3 */
  3666. + {KE_KEY, EVENT_AUDIO_MUTE, { KEY_MUTE } }, /* Fn + F4 */
  3667. + {KE_KEY, EVENT_WLAN, { KEY_WLAN } }, /* Fn + F5 */
  3668. + {KE_KEY, EVENT_DISPLAY_BRIGHTNESS, { KEY_BRIGHTNESSUP } }, /* Fn + up */
  3669. + {KE_KEY, EVENT_DISPLAY_BRIGHTNESS, { KEY_BRIGHTNESSDOWN } }, /* Fn + down */
  3670. + {KE_KEY, EVENT_AUDIO_VOLUME, { KEY_VOLUMEUP } }, /* Fn + right */
  3671. + {KE_KEY, EVENT_AUDIO_VOLUME, { KEY_VOLUMEDOWN } }, /* Fn + left */
  3672. + {KE_END, 0}
  3673. +};
  3674. +
  3675. +static struct key_entry *get_event_key_entry(int event, int status)
  3676. +{
  3677. + struct key_entry *ke;
  3678. + static int old_brightness_status = -1;
  3679. + static int old_volume_status = -1;
  3680. +
  3681. + ke = sparse_keymap_entry_from_scancode(yeeloong_hotkey_dev, event);
  3682. + if (!ke)
  3683. + return NULL;
  3684. +
  3685. + switch (event) {
  3686. + case EVENT_DISPLAY_BRIGHTNESS:
  3687. + /* current status > old one, means up */
  3688. + if ((status < old_brightness_status) || (0 == status))
  3689. + ke++;
  3690. + old_brightness_status = status;
  3691. + break;
  3692. + case EVENT_AUDIO_VOLUME:
  3693. + if ((status < old_volume_status) || (0 == status))
  3694. + ke++;
  3695. + old_volume_status = status;
  3696. + break;
  3697. + default:
  3698. + break;
  3699. + }
  3700. +
  3701. + return ke;
  3702. +}
  3703. +
  3704. +static int report_lid_switch(int status)
  3705. +{
  3706. + input_report_switch(yeeloong_hotkey_dev, SW_LID, !status);
  3707. + input_sync(yeeloong_hotkey_dev);
  3708. +
  3709. + return status;
  3710. +}
  3711. +
  3712. +static int crt_detect_handler(int status)
  3713. +{
  3714. + if (status) {
  3715. + yeeloong_crt_vo_set(BIT_CRT_DETECT_PLUG);
  3716. + yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_OFF);
  3717. + } else {
  3718. + yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_ON);
  3719. + yeeloong_crt_vo_set(BIT_CRT_DETECT_UNPLUG);
  3720. + }
  3721. + return status;
  3722. +}
  3723. +
  3724. +static int displaytoggle_handler(int status)
  3725. +{
  3726. + /* EC(>=PQ1D26) does this job for us, we can not do it again,
  3727. + * otherwise, the brightness will not resume to the normal level! */
  3728. + if (ec_version_before("EC_VER=PQ1D26"))
  3729. + yeeloong_lcd_vo_set(status);
  3730. +
  3731. + return status;
  3732. +}
  3733. +
  3734. +static int switchvideomode_handler(int status)
  3735. +{
  3736. + static int video_output_status;
  3737. +
  3738. + /* Only enable switch video output button
  3739. + * when CRT is connected */
  3740. + if (ec_read(REG_CRT_DETECT) == BIT_CRT_DETECT_UNPLUG)
  3741. + return 0;
  3742. + /* 0. no CRT connected: LCD on, CRT off
  3743. + * 1. BOTH on
  3744. + * 2. LCD off, CRT on
  3745. + * 3. BOTH off
  3746. + * 4. LCD on, CRT off
  3747. + */
  3748. + video_output_status++;
  3749. + if (video_output_status > 4)
  3750. + video_output_status = 1;
  3751. +
  3752. + switch (video_output_status) {
  3753. + case 1:
  3754. + yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_ON);
  3755. + yeeloong_crt_vo_set(BIT_CRT_DETECT_PLUG);
  3756. + break;
  3757. + case 2:
  3758. + yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_OFF);
  3759. + yeeloong_crt_vo_set(BIT_CRT_DETECT_PLUG);
  3760. + break;
  3761. + case 3:
  3762. + yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_OFF);
  3763. + yeeloong_crt_vo_set(BIT_CRT_DETECT_UNPLUG);
  3764. + break;
  3765. + case 4:
  3766. + yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_ON);
  3767. + yeeloong_crt_vo_set(BIT_CRT_DETECT_UNPLUG);
  3768. + break;
  3769. + default:
  3770. + /* Ensure LCD is on */
  3771. + yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_ON);
  3772. + break;
  3773. + }
  3774. + return video_output_status;
  3775. +}
  3776. +
  3777. +static int camera_handler(int status)
  3778. +{
  3779. + int value;
  3780. +
  3781. + value = ec_read(REG_CAMERA_CONTROL);
  3782. + ec_write(REG_CAMERA_CONTROL, value | (1 << 1));
  3783. +
  3784. + return status;
  3785. +}
  3786. +
  3787. +static int usb2_handler(int status)
  3788. +{
  3789. + pr_emerg("USB2 Over Current occurred\n");
  3790. +
  3791. + return status;
  3792. +}
  3793. +
  3794. +static int usb0_handler(int status)
  3795. +{
  3796. + pr_emerg("USB0 Over Current occurred\n");
  3797. +
  3798. + return status;
  3799. +}
  3800. +
  3801. +static int ac_bat_handler(int status)
  3802. +{
  3803. + if (ac_bat_initialized) {
  3804. + power_supply_changed(&yeeloong_ac);
  3805. + power_supply_changed(&yeeloong_bat);
  3806. + }
  3807. + return status;
  3808. +}
  3809. +
  3810. +static void do_event_action(int event)
  3811. +{
  3812. + sci_handler handler;
  3813. + int reg, status;
  3814. + struct key_entry *ke;
  3815. +
  3816. + reg = 0;
  3817. + handler = NULL;
  3818. +
  3819. + switch (event) {
  3820. + case EVENT_LID:
  3821. + reg = REG_LID_DETECT;
  3822. + break;
  3823. + case EVENT_SWITCHVIDEOMODE:
  3824. + handler = switchvideomode_handler;
  3825. + break;
  3826. + case EVENT_CRT_DETECT:
  3827. + reg = REG_CRT_DETECT;
  3828. + handler = crt_detect_handler;
  3829. + break;
  3830. + case EVENT_CAMERA:
  3831. + reg = REG_CAMERA_STATUS;
  3832. + handler = camera_handler;
  3833. + break;
  3834. + case EVENT_USB_OC2:
  3835. + reg = REG_USB2_FLAG;
  3836. + handler = usb2_handler;
  3837. + break;
  3838. + case EVENT_USB_OC0:
  3839. + reg = REG_USB0_FLAG;
  3840. + handler = usb0_handler;
  3841. + break;
  3842. + case EVENT_DISPLAYTOGGLE:
  3843. + reg = REG_DISPLAY_LCD;
  3844. + handler = displaytoggle_handler;
  3845. + break;
  3846. + case EVENT_AUDIO_MUTE:
  3847. + reg = REG_AUDIO_MUTE;
  3848. + break;
  3849. + case EVENT_DISPLAY_BRIGHTNESS:
  3850. + reg = REG_DISPLAY_BRIGHTNESS;
  3851. + break;
  3852. + case EVENT_AUDIO_VOLUME:
  3853. + reg = REG_AUDIO_VOLUME;
  3854. + break;
  3855. + case EVENT_AC_BAT:
  3856. + handler = ac_bat_handler;
  3857. + break;
  3858. + default:
  3859. + break;
  3860. + }
  3861. +
  3862. + if (reg != 0)
  3863. + status = ec_read(reg);
  3864. +
  3865. + if (handler != NULL)
  3866. + status = handler(status);
  3867. +
  3868. + pr_info("%s: event: %d status: %d\n", __func__, event, status);
  3869. +
  3870. + /* Report current key to user-space */
  3871. + ke = get_event_key_entry(event, status);
  3872. + if (ke) {
  3873. + if (ke->keycode == SW_LID)
  3874. + report_lid_switch(status);
  3875. + else
  3876. + sparse_keymap_report_entry(yeeloong_hotkey_dev, ke, 1,
  3877. + true);
  3878. + }
  3879. +}
  3880. +
  3881. +/*
  3882. + * SCI(system control interrupt) main interrupt routine
  3883. + *
  3884. + * We will do the query and get event number together so the interrupt routine
  3885. + * should be longer than 120us now at least 3ms elpase for it.
  3886. + */
  3887. +static irqreturn_t sci_irq_handler(int irq, void *dev_id)
  3888. +{
  3889. + int ret, event;
  3890. +
  3891. + if (SCI_IRQ_NUM != irq)
  3892. + return IRQ_NONE;
  3893. +
  3894. + /* Query the event number */
  3895. + ret = ec_query_event_num();
  3896. + if (ret < 0)
  3897. + return IRQ_NONE;
  3898. +
  3899. + event = ec_get_event_num();
  3900. + if (event < EVENT_START || event > EVENT_END)
  3901. + return IRQ_NONE;
  3902. +
  3903. + /* Execute corresponding actions */
  3904. + do_event_action(event);
  3905. +
  3906. + return IRQ_HANDLED;
  3907. +}
  3908. +
  3909. +/*
  3910. + * Config and init some msr and gpio register properly.
  3911. + */
  3912. +static int sci_irq_init(void)
  3913. +{
  3914. + u32 hi, lo;
  3915. + u32 gpio_base;
  3916. + unsigned long flags;
  3917. + int ret;
  3918. +
  3919. + /* Get gpio base */
  3920. + _rdmsr(DIVIL_MSR_REG(DIVIL_LBAR_GPIO), &hi, &lo);
  3921. + gpio_base = lo & 0xff00;
  3922. +
  3923. + /* Filter the former kb3310 interrupt for security */
  3924. + ret = ec_query_event_num();
  3925. + if (ret)
  3926. + return ret;
  3927. +
  3928. + /* For filtering next number interrupt */
  3929. + udelay(10000);
  3930. +
  3931. + /* Set gpio native registers and msrs for GPIO27 SCI EVENT PIN
  3932. + * gpio :
  3933. + * input, pull-up, no-invert, event-count and value 0,
  3934. + * no-filter, no edge mode
  3935. + * gpio27 map to Virtual gpio0
  3936. + * msr :
  3937. + * no primary and lpc
  3938. + * Unrestricted Z input to IG10 from Virtual gpio 0.
  3939. + */
  3940. + local_irq_save(flags);
  3941. + _rdmsr(0x80000024, &hi, &lo);
  3942. + lo &= ~(1 << 10);
  3943. + _wrmsr(0x80000024, hi, lo);
  3944. + _rdmsr(0x80000025, &hi, &lo);
  3945. + lo &= ~(1 << 10);
  3946. + _wrmsr(0x80000025, hi, lo);
  3947. + _rdmsr(0x80000023, &hi, &lo);
  3948. + lo |= (0x0a << 0);
  3949. + _wrmsr(0x80000023, hi, lo);
  3950. + local_irq_restore(flags);
  3951. +
  3952. + /* Set gpio27 as sci interrupt
  3953. + *
  3954. + * input, pull-up, no-fliter, no-negedge, invert
  3955. + * the sci event is just about 120us
  3956. + */
  3957. + asm(".set noreorder\n");
  3958. + /* input enable */
  3959. + outl(0x00000800, (gpio_base | 0xA0));
  3960. + /* revert the input */
  3961. + outl(0x00000800, (gpio_base | 0xA4));
  3962. + /* event-int enable */
  3963. + outl(0x00000800, (gpio_base | 0xB8));
  3964. + asm(".set reorder\n");
  3965. +
  3966. + return 0;
  3967. +}
  3968. +
  3969. +static struct irqaction sci_irqaction = {
  3970. + .handler = sci_irq_handler,
  3971. + .name = "sci",
  3972. + .flags = IRQF_SHARED,
  3973. +};
  3974. +
  3975. +static int yeeloong_hotkey_init(void)
  3976. +{
  3977. + int ret;
  3978. +
  3979. + ret = sci_irq_init();
  3980. + if (ret)
  3981. + return -EFAULT;
  3982. +
  3983. + ret = setup_irq(SCI_IRQ_NUM, &sci_irqaction);
  3984. + if (ret)
  3985. + return -EFAULT;
  3986. +
  3987. + yeeloong_hotkey_dev = input_allocate_device();
  3988. +
  3989. + if (!yeeloong_hotkey_dev) {
  3990. + remove_irq(SCI_IRQ_NUM, &sci_irqaction);
  3991. + return -ENOMEM;
  3992. + }
  3993. +
  3994. + yeeloong_hotkey_dev->name = "HotKeys";
  3995. + yeeloong_hotkey_dev->phys = "button/input0";
  3996. + yeeloong_hotkey_dev->id.bustype = BUS_HOST;
  3997. + yeeloong_hotkey_dev->dev.parent = NULL;
  3998. +
  3999. + ret = sparse_keymap_setup(yeeloong_hotkey_dev, yeeloong_keymap, NULL);
  4000. + if (ret) {
  4001. + pr_err("Fail to setup input device keymap\n");
  4002. + input_free_device(yeeloong_hotkey_dev);
  4003. + return ret;
  4004. + }
  4005. +
  4006. + ret = input_register_device(yeeloong_hotkey_dev);
  4007. + if (ret) {
  4008. + sparse_keymap_free(yeeloong_hotkey_dev);
  4009. + input_free_device(yeeloong_hotkey_dev);
  4010. + return ret;
  4011. + }
  4012. +
  4013. + /* Update the current status of LID */
  4014. + report_lid_switch(BIT_LID_DETECT_ON);
  4015. +
  4016. +#ifdef CONFIG_LOONGSON_SUSPEND
  4017. + /* Install the real yeeloong_report_lid_status for pm.c */
  4018. + yeeloong_report_lid_status = report_lid_switch;
  4019. +#endif
  4020. +
  4021. + return 0;
  4022. +}
  4023. +
  4024. +static void yeeloong_hotkey_exit(void)
  4025. +{
  4026. + /* Free irq */
  4027. + remove_irq(SCI_IRQ_NUM, &sci_irqaction);
  4028. +
  4029. +#ifdef CONFIG_LOONGSON_SUSPEND
  4030. + /* Uninstall yeeloong_report_lid_status for pm.c */
  4031. + if (yeeloong_report_lid_status == report_lid_switch)
  4032. + yeeloong_report_lid_status = NULL;
  4033. +#endif
  4034. +
  4035. + if (yeeloong_hotkey_dev) {
  4036. + sparse_keymap_free(yeeloong_hotkey_dev);
  4037. + input_unregister_device(yeeloong_hotkey_dev);
  4038. + yeeloong_hotkey_dev = NULL;
  4039. + }
  4040. +}
  4041. +
  4042. +#ifdef CONFIG_PM
  4043. +static void usb_ports_set(int status)
  4044. +{
  4045. + status = !!status;
  4046. +
  4047. + ec_write(REG_USB0_FLAG, status);
  4048. + ec_write(REG_USB1_FLAG, status);
  4049. + ec_write(REG_USB2_FLAG, status);
  4050. +}
  4051. +
  4052. +static int yeeloong_suspend(struct device *dev)
  4053. +
  4054. +{
  4055. + if (ec_version_before("EC_VER=PQ1D27"))
  4056. + yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_OFF);
  4057. + yeeloong_crt_vo_set(BIT_CRT_DETECT_UNPLUG);
  4058. + usb_ports_set(BIT_USB_FLAG_OFF);
  4059. +
  4060. + return 0;
  4061. +}
  4062. +
  4063. +static int yeeloong_resume(struct device *dev)
  4064. +{
  4065. + if (ec_version_before("EC_VER=PQ1D27"))
  4066. + yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_ON);
  4067. + yeeloong_crt_vo_set(BIT_CRT_DETECT_PLUG);
  4068. + usb_ports_set(BIT_USB_FLAG_ON);
  4069. +
  4070. + return 0;
  4071. +}
  4072. +
  4073. +static const SIMPLE_DEV_PM_OPS(yeeloong_pm_ops, yeeloong_suspend,
  4074. + yeeloong_resume);
  4075. +#endif
  4076. +
  4077. +static struct platform_device_id platform_device_ids[] = {
  4078. + {
  4079. + .name = "yeeloong_laptop",
  4080. + },
  4081. + {}
  4082. +};
  4083. +
  4084. +MODULE_DEVICE_TABLE(platform, platform_device_ids);
  4085. +
  4086. +static struct platform_driver platform_driver = {
  4087. + .driver = {
  4088. + .name = "yeeloong_laptop",
  4089. + .owner = THIS_MODULE,
  4090. +#ifdef CONFIG_PM
  4091. + .pm = &yeeloong_pm_ops,
  4092. +#endif
  4093. + },
  4094. + .id_table = platform_device_ids,
  4095. +};
  4096. +
  4097. +static int __init yeeloong_init(void)
  4098. +{
  4099. + int ret;
  4100. +
  4101. + pr_info("Load YeeLoong Laptop Platform Specific Driver.\n");
  4102. +
  4103. + /* Register platform stuff */
  4104. + ret = platform_driver_register(&platform_driver);
  4105. + if (ret) {
  4106. + pr_err("Fail to register yeeloong platform driver.\n");
  4107. + return ret;
  4108. + }
  4109. +
  4110. + ret = yeeloong_backlight_init();
  4111. + if (ret) {
  4112. + pr_err("Fail to register yeeloong backlight driver.\n");
  4113. + yeeloong_backlight_exit();
  4114. + return ret;
  4115. + }
  4116. +
  4117. + ret = yeeloong_bat_init();
  4118. + if (ret) {
  4119. + pr_err("Fail to register yeeloong battery driver.\n");
  4120. + yeeloong_bat_exit();
  4121. + return ret;
  4122. + }
  4123. +
  4124. + ret = yeeloong_hwmon_init();
  4125. + if (ret) {
  4126. + pr_err("Fail to register yeeloong hwmon driver.\n");
  4127. + yeeloong_hwmon_exit();
  4128. + return ret;
  4129. + }
  4130. +
  4131. + ret = yeeloong_vo_init();
  4132. + if (ret) {
  4133. + pr_err("Fail to register yeeloong video output driver.\n");
  4134. + yeeloong_vo_exit();
  4135. + return ret;
  4136. + }
  4137. +
  4138. + ret = yeeloong_hotkey_init();
  4139. + if (ret) {
  4140. + pr_err("Fail to register yeeloong hotkey driver.\n");
  4141. + yeeloong_hotkey_exit();
  4142. + return ret;
  4143. + }
  4144. +
  4145. + return 0;
  4146. +}
  4147. +
  4148. +static void __exit yeeloong_exit(void)
  4149. +{
  4150. + yeeloong_hotkey_exit();
  4151. + yeeloong_vo_exit();
  4152. + yeeloong_hwmon_exit();
  4153. + yeeloong_bat_exit();
  4154. + yeeloong_backlight_exit();
  4155. + platform_driver_unregister(&platform_driver);
  4156. +
  4157. + pr_info("Unload YeeLoong Platform Specific Driver.\n");
  4158. +}
  4159. +
  4160. +module_init(yeeloong_init);
  4161. +module_exit(yeeloong_exit);
  4162. +
  4163. +MODULE_AUTHOR("Wu Zhangjin <wuzhangjin@gmail.com>; Liu Junliang <liujl@lemote.com>");
  4164. +MODULE_DESCRIPTION("YeeLoong laptop driver");
  4165. +MODULE_LICENSE("GPL");
  4166. diff -Nur linux-2.6.37.orig/drivers/staging/sm7xx/smtcfb.c linux-2.6.37/drivers/staging/sm7xx/smtcfb.c
  4167. --- linux-2.6.37.orig/drivers/staging/sm7xx/smtcfb.c 2011-01-05 01:50:19.000000000 +0100
  4168. +++ linux-2.6.37/drivers/staging/sm7xx/smtcfb.c 2011-01-11 20:44:43.000000000 +0100
  4169. @@ -12,6 +12,8 @@
  4170. * License. See the file COPYING in the main directory of this archive for
  4171. * more details.
  4172. *
  4173. + * - Remove the buggy 2D support for Lynx, 2010/01/06, Wu Zhangjin
  4174. + *
  4175. * Version 0.10.26192.21.01
  4176. * - Add PowerPC/Big endian support
  4177. * - Add 2D support for Lynx
  4178. @@ -107,6 +109,7 @@
  4179. {"0x307", 1280, 1024, 8},
  4180. {"0x311", 640, 480, 16},
  4181. + {"0x313", 800, 480, 16},
  4182. {"0x314", 800, 600, 16},
  4183. {"0x317", 1024, 768, 16},
  4184. {"0x31A", 1280, 1024, 16},
  4185. diff -Nur linux-2.6.37.orig/drivers/usb/host/ohci-hcd.c linux-2.6.37/drivers/usb/host/ohci-hcd.c
  4186. --- linux-2.6.37.orig/drivers/usb/host/ohci-hcd.c 2011-01-05 01:50:19.000000000 +0100
  4187. +++ linux-2.6.37/drivers/usb/host/ohci-hcd.c 2011-01-11 20:44:43.000000000 +0100
  4188. @@ -838,9 +838,13 @@
  4189. }
  4190. if (ints & OHCI_INTR_WDH) {
  4191. - spin_lock (&ohci->lock);
  4192. - dl_done_list (ohci);
  4193. - spin_unlock (&ohci->lock);
  4194. + if (ohci->hcca->done_head == 0) {
  4195. + ints &= ~OHCI_INTR_WDH;
  4196. + } else {
  4197. + spin_lock (&ohci->lock);
  4198. + dl_done_list (ohci);
  4199. + spin_unlock (&ohci->lock);
  4200. + }
  4201. }
  4202. if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) {
  4203. diff -Nur linux-2.6.37.orig/net/rfkill/core.c linux-2.6.37/net/rfkill/core.c
  4204. --- linux-2.6.37.orig/net/rfkill/core.c 2011-01-05 01:50:19.000000000 +0100
  4205. +++ linux-2.6.37/net/rfkill/core.c 2011-01-11 20:44:43.000000000 +0100
  4206. @@ -112,7 +112,7 @@
  4207. static DEFINE_MUTEX(rfkill_global_mutex);
  4208. static LIST_HEAD(rfkill_fds); /* list of open fds of /dev/rfkill */
  4209. -static unsigned int rfkill_default_state = 1;
  4210. +static unsigned int rfkill_default_state; /* default: 0 = radio off */
  4211. module_param_named(default_state, rfkill_default_state, uint, 0444);
  4212. MODULE_PARM_DESC(default_state,
  4213. "Default initial state for all radio types, 0 = radio off");