felica.c 137 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495
  1. /*
  2. * This program is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU General Public License
  4. * version 2 as published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. * See the GNU General Public License for more details.
  10. */
  11. #ifdef CONFIG_FELICA
  12. #include "felica.h"
  13. #include <linux/init.h>
  14. #include <linux/cdev.h>
  15. #include <linux/device.h>
  16. #include <linux/gpio.h>
  17. #include <linux/delay.h>
  18. #include <linux/termios.h>
  19. #include <linux/serial_core.h>
  20. #include <linux/uaccess.h>
  21. #ifdef F_WAKE_LOCK
  22. #include <linux/wakelock.h>
  23. #endif
  24. #include <linux/types.h>
  25. /* jmodel */
  26. #if defined(CONFIG_ARCH_EXYNOS)
  27. #include <mach/smc.h>
  28. #elif defined(CONFIG_ARCH_APQ8064) || defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  29. #include <mach/scm.h>
  30. #endif
  31. #include <asm/system_info.h>
  32. #include <linux/of_gpio.h>
  33. #include <linux/mfd/pm8xxx/gpio.h>
  34. /******************************************************************************
  35. * log
  36. ******************************************************************************/
  37. #include <mach/sec_debug.h>
  38. #define NO_CHECK_TAMPER
  39. #define SRIB_DIAG_ENABLED
  40. /******************************************************************************
  41. * Board configuration
  42. ******************************************************************************/
  43. /* jmodel */
  44. #if defined(CONFIG_ARCH_EXYNOS)
  45. #define FELICA_UART1RX EXYNOS5410_GPA0(4)
  46. #endif
  47. /* Hmodel */
  48. #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  49. #if !defined(CONFIG_MACH_KLTE_KDI) && !defined(CONFIG_MACH_KLTE_DCM) && !defined(CONFIG_MACH_KLTE_SBM)
  50. static int gfelica_irq_int_pin = -1;
  51. #endif
  52. static struct platform_device *felica_gpio_pdev;
  53. #if defined(CONFIG_MACH_HLTEDCM)
  54. static int g_uicc_initrev = 7; //HW Rev 0.9
  55. static int gfelica_sps_pin = 130; //Select Power Supply
  56. static int gfelica_hsel_pin = GPIO_PINID_NFC_HSEL;
  57. #define HW_REV09_OR_10 7 // to fix hltedcm i2c h/w issue in REV 09/10.
  58. extern void of_sii8240_hw_poweron(bool enable); // to fix hltedcm i2c h/w issue in REV 09/10. Defined in driver/video/msm/mhl_v2/sii8240.c
  59. /* K MODEL */
  60. #elif defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
  61. static int gfelica_sps_pin = -1; //Select Power Supply
  62. static int gfelica_pon_pin = GPIO_FELICA_PON_REV06; // PON
  63. static int gfelica_hsel_pin = -1;
  64. static int g_uicc_initrev = 0;
  65. //#define NO_CHECK_TAMPER
  66. //#define SRIB_DIAG_ENABLED
  67. #elif defined(CONFIG_MACH_KLTE_KDI)
  68. static int gfelica_pon_pin = GPIO_FELICA_PON_REV06; // PON
  69. static int gfelica_hsel_pin = -1;
  70. static int gfelica_sps_pin = -1;
  71. static int g_uicc_initrev = 0;
  72. static int gfelica_uim_mon = 0;
  73. //#define NO_CHECK_TAMPER
  74. //#define SRIB_DIAG_ENABLED
  75. #elif defined(CONFIG_MACH_HLTEKDI)
  76. static int g_uicc_initrev = 4;
  77. static int gfelica_sps_pin = -1;
  78. static int gfelica_hsel_pin = GPIO_PINID_NFC_HSEL;
  79. #elif defined(CONFIG_MACH_JS01LTEDCM)
  80. static int g_uicc_initrev = 8; // HW Rev 0.4
  81. static int gfelica_sps_pin = 130; // Select Power Supply
  82. static int gfelica_hsel_pin = GPIO_PINID_NFC_HSEL;
  83. #endif
  84. #endif /* CONFIG_ARCH_MSM8974 */
  85. /******************************************************************************
  86. * global variable
  87. ******************************************************************************/
  88. static struct class *felica_class;
  89. #ifdef F_WAKE_LOCK
  90. struct wake_lock felica_wake_1;
  91. struct wake_lock felica_wake_2;
  92. static int tmout_1 = 3*1000; // wake lock timeout for INT irq.
  93. #endif
  94. /* storages for communicate to netlink */
  95. static int gfa_open_cnt;
  96. static int gfa_pid;
  97. static int gfa_connect_flag;
  98. static struct sock *gfanl_sk;
  99. static char gfa_send_str[FELICA_NL_MSG_SIZE];
  100. static char gfa_rcv_str[FELICA_NL_MSG_SIZE];
  101. static int gfa_wait_flag;
  102. /* R/W functions availability information storage */
  103. static char gfelica_rw_status;
  104. /* IRQ data storage for INT terminal monitoring */
  105. struct felica_int_irqdata {
  106. struct delayed_work work;
  107. wait_queue_head_t read_wait;
  108. int irq_done;
  109. int open_flag;
  110. };
  111. static struct felica_int_irqdata gint_irq;
  112. static struct felica_int_irqdata *pgint_irq = &gint_irq;
  113. /* storages for access restriction */
  114. static uid_t gmfc_uid = -1;
  115. static uid_t gmfl_uid = -1;
  116. static uid_t grwm_uid = -1;
  117. static uid_t gdiag_uid = -1;
  118. #ifdef CONFIG_NFC_FELICA
  119. static uid_t gnfc_uid = -1;
  120. struct file *pg_tty;
  121. static int gnfc_open_cnt;
  122. #endif /* CONFIG_NFC_FELICA */
  123. /* package name's storage for access restriction */
  124. static char gdiag_name[DIAG_NAME_MAXSIZE + 1];
  125. #ifdef FELICA_UICC_FUNCTION
  126. static char gproc_name[PROC_NAME_MAXSIZE + 1];
  127. #endif
  128. static uid_t gant_uid = -1;
  129. static int gi2c_address;
  130. static char gi2c_antaddress;
  131. static char gi2c_lockaddress;
  132. static struct i2c_msg gread_msgs[] = {
  133. {
  134. .addr = 0,
  135. .flags = 0,
  136. .len = 0,
  137. .buf = NULL,
  138. },
  139. {
  140. .addr = 0,
  141. .flags = 0,
  142. .len = 0,
  143. .buf = NULL,
  144. },
  145. };
  146. static struct i2c_msg gwrite_msgs[] = {
  147. {
  148. .addr = 0,
  149. .flags = 0,
  150. .len = 0,
  151. .buf = NULL,
  152. },
  153. };
  154. #ifdef CONFIG_NFC_FELICA
  155. /******************************************************************************
  156. * Add global variable
  157. ******************************************************************************/
  158. struct icc_poll_data {
  159. wait_queue_head_t read_wait;
  160. wait_queue_head_t rsp_wait;
  161. wait_queue_head_t dummy_wait;
  162. int handler_done;
  163. int rsp_done;
  164. struct delayed_work work;
  165. int device_status;
  166. int read_error;
  167. int open_flag;
  168. int available_flag;
  169. };
  170. struct poll_data {
  171. wait_queue_head_t read_wait;
  172. int irq_handler_done;
  173. struct delayed_work work;
  174. int device_status;
  175. int read_error;
  176. int open_flag;
  177. };
  178. static struct icc_poll_data gfelica_poll_data;
  179. static struct icc_poll_data g_available_data;
  180. static struct icc_poll_data *available_d = &g_available_data;
  181. static int guartcc_start_req = UARTCC_NFC_START_ENDPROC;
  182. #ifdef FELICA_UICC_FUNCTION
  183. static int guartcc_felica_status = UARTCC_FELICA_STATAUS_IN_INIT;
  184. #else
  185. static int guartcc_felica_status = UARTCC_FELICA_STATAUS_IDLE;
  186. #endif
  187. static int g_cen_sts = 0;
  188. static int g_rfs_sts = 0;
  189. static char g_uicc_sts = 0x00; // permissive mode issue
  190. static int felica_varying_gpio_intu;
  191. #ifdef P2P_FPGA_ALWAYS_ON
  192. extern void set_fpga_felica_flag(int on);
  193. #endif /* P2P_FPGA_ALWAYS_ON */
  194. #endif /* CONFIG_NFC_FELICA */
  195. /******************************************************************************
  196. * /dev/felica
  197. ******************************************************************************/
  198. /* character device definition */
  199. static int felica_uart_port;
  200. static dev_t devid_felica_uart;
  201. static struct cdev cdev_felica_uart;
  202. static const struct file_operations fops_felica_uart = {
  203. .owner = THIS_MODULE,
  204. .open = felica_uart_open,
  205. .release = felica_uart_close,
  206. .read = felica_uart_read,
  207. .write = felica_uart_write,
  208. .fsync = felica_uart_sync,
  209. .unlocked_ioctl = felica_uart_ioctl,
  210. };
  211. struct felica_sem_data {
  212. struct semaphore felica_sem;
  213. };
  214. static struct felica_sem_data *dev_sem;
  215. /*
  216. * initialize device
  217. */
  218. static void felica_uart_init(void)
  219. {
  220. int ret;
  221. struct device *device_felica_uart;
  222. FELICA_PR_DBG(" %s START", __func__);
  223. devid_felica_uart = MKDEV(FELICA_MAJOR, FELICA_MINOR);
  224. ret =
  225. alloc_chrdev_region(&devid_felica_uart, FELICA_BASEMINOR,
  226. FELICA_MINOR_COUNT, FELICA_UART_NAME);
  227. if (ret < 0) {
  228. FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
  229. __func__, ret);
  230. return;
  231. }
  232. cdev_init(&cdev_felica_uart, &fops_felica_uart);
  233. ret =
  234. cdev_add(&cdev_felica_uart, devid_felica_uart, FELICA_MINOR_COUNT);
  235. if (ret < 0) {
  236. unregister_chrdev_region(devid_felica_uart, FELICA_MINOR_COUNT);
  237. FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
  238. ret);
  239. return;
  240. }
  241. device_felica_uart =
  242. device_create(felica_class, NULL, devid_felica_uart, NULL,
  243. FELICA_UART_NAME);
  244. if (IS_ERR(device_felica_uart)) {
  245. cdev_del(&cdev_felica_uart);
  246. unregister_chrdev_region(devid_felica_uart, FELICA_MINOR_COUNT);
  247. FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
  248. return;
  249. }
  250. dev_sem = kmalloc(sizeof(struct felica_sem_data), GFP_KERNEL);
  251. if (!dev_sem) {
  252. cdev_del(&cdev_felica_uart);
  253. unregister_chrdev_region(devid_felica_uart, FELICA_MINOR_COUNT);
  254. FELICA_PR_ERR(" %s ERROR(dev_sem malloc)", __func__);
  255. return;
  256. }
  257. sema_init(&dev_sem->felica_sem, 1);
  258. #ifdef CONFIG_NFC_FELICA
  259. memset((void *)&gfelica_poll_data, 0x00, sizeof(struct icc_poll_data));
  260. init_waitqueue_head(&gfelica_poll_data.rsp_wait);
  261. gfelica_poll_data.rsp_done = 0;
  262. gfelica_poll_data.open_flag = 0;
  263. #endif /* CONFIG_NFC_FELICA */
  264. FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
  265. MAJOR(devid_felica_uart), MINOR(devid_felica_uart));
  266. }
  267. /*
  268. * finalize device
  269. */
  270. static void felica_uart_exit(void)
  271. {
  272. kfree(dev_sem);
  273. device_destroy(felica_class, devid_felica_uart);
  274. cdev_del(&cdev_felica_uart);
  275. unregister_chrdev_region(devid_felica_uart, FELICA_MINOR_COUNT);
  276. FELICA_PR_DBG(" %s START", __func__);
  277. }
  278. /*
  279. * open device
  280. */
  281. static int felica_uart_open(struct inode *inode, struct file *file)
  282. {
  283. uid_t uid;
  284. int ret;
  285. FELICA_PR_DBG(" %s START", __func__);
  286. uid = __task_cred(current)->uid;
  287. if ((uid != gmfc_uid) && (uid != gdiag_uid) && (uid != gant_uid)) {
  288. FELICA_PR_ERR
  289. (" %s END -EACCESS, uid=[%d], gmfc_uid=[%d], gdiag_uid=[%d]",
  290. __func__, uid, gmfc_uid, gdiag_uid);
  291. #ifdef SRIB_DIAG_ENABLED
  292. FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
  293. #else
  294. return -EACCES;
  295. #endif
  296. }
  297. if (down_interruptible(&dev_sem->felica_sem)) {
  298. FELICA_PR_ERR(" %s ERROR(down_interruptible)", \
  299. __func__);
  300. return -ERESTARTSYS;
  301. }
  302. if (gfa_open_cnt == 0) {
  303. #ifdef CONFIG_NFC_FELICA
  304. switch (guartcc_start_req) {
  305. case UARTCC_NFC_START_AUTOPOLLING: /* AutoPoiing */
  306. {
  307. /* felica open-waiting for nfc autopolling */
  308. ret = felica_uart_open_wait_for_polling();
  309. if (ret < 0) {
  310. FELICA_PR_ERR( \
  311. " %s open-waiting fail= [%d]\n " \
  312. , __func__, ret);
  313. return ret;
  314. }
  315. FELICA_PR_INFO( \
  316. " %s open wait release\n", \
  317. __func__);
  318. }
  319. break;
  320. case UARTCC_NFC_START_ENDPROC: /* Unused NFC */
  321. /* set felica status -> in use */
  322. uartcc_set_felica_status(UARTCC_FELICA_STATAUS_IN_USE);
  323. FELICA_PR_INFO( \
  324. " %s started using FeliCa=[%d]\n", \
  325. __func__, guartcc_start_req);
  326. break;
  327. default: /* NFC in use */
  328. FELICA_PR_ERR(" -EFAULT %s NFC in use=[%d]\n", \
  329. __func__, guartcc_start_req);
  330. /* reset felica status -> idle */
  331. uartcc_set_felica_status(
  332. UARTCC_FELICA_STATAUS_IDLE);
  333. up(&dev_sem->felica_sem);
  334. return -EFAULT;
  335. break;
  336. }
  337. #endif /* CONFIG_NFC_FELICA */
  338. memset(gfa_send_str, 0, FELICA_NL_MSG_SIZE);
  339. memset(gfa_rcv_str, 0, FELICA_NL_MSG_SIZE);
  340. gfa_send_str[0] = FELICA_NL_REQ_OPEN;
  341. gfa_send_str[1] = felica_uart_port;
  342. ret = felica_nl_send_msg(2);
  343. if (ret == 0) {
  344. felica_nl_wait_ret_msg();
  345. if (gfa_rcv_str[1] == FELICA_NL_EFAILED) {
  346. FELICA_PR_ERR(" %s Open Fail", __func__);
  347. #ifdef CONFIG_NFC_FELICA
  348. /* reset felica status -> idle */
  349. uartcc_set_felica_status(
  350. UARTCC_FELICA_STATAUS_IDLE);
  351. #endif /* CONFIG_NFC_FELICA */
  352. up(&dev_sem->felica_sem);
  353. return -EFAULT;
  354. }
  355. } else {
  356. FELICA_PR_ERR(" %s felica_nl_send_msg Fail", \
  357. __func__);
  358. #ifdef CONFIG_NFC_FELICA
  359. /* reset felica status -> idle */
  360. uartcc_set_felica_status(
  361. UARTCC_FELICA_STATAUS_IDLE);
  362. #endif /* CONFIG_NFC_FELICA */
  363. up(&dev_sem->felica_sem);
  364. return -EFAULT;
  365. }
  366. #ifdef F_WAKE_LOCK
  367. wake_lock(&felica_wake_2);
  368. FELICA_PR_INFO(" %s Wake Lock(2)", __func__);
  369. #endif
  370. }
  371. gfa_open_cnt++;
  372. up(&dev_sem->felica_sem);
  373. FELICA_PR_DBG(" %s END", __func__);
  374. return 0;
  375. }
  376. #ifdef CONFIG_NFC_FELICA
  377. /*
  378. * felica open-waiting for nfc autopolling
  379. */
  380. static int felica_uart_open_wait_for_polling(void)
  381. {
  382. int ret = 0;
  383. struct icc_poll_data *felica_poll = &gfelica_poll_data;
  384. FELICA_PR_DBG(" %s START\n", __func__);
  385. /* set felica status -> wait polling */
  386. uartcc_set_felica_status(UARTCC_FELICA_STATAUS_WAIT_POLLING);
  387. up(&dev_sem->felica_sem);
  388. ret = wait_event_interruptible(felica_poll->rsp_wait,
  389. felica_poll->rsp_done == 1);
  390. if (ret < 0) {
  391. /* reset felica status -> idle */
  392. uartcc_set_felica_status(UARTCC_FELICA_STATAUS_IDLE);
  393. FELICA_PR_ERR
  394. (" %s ERROR(wait_event_interruptible), ret=[%d]\n", \
  395. __func__, ret);
  396. return -EIO;
  397. }
  398. if (down_interruptible(&dev_sem->felica_sem)) {
  399. /* reset felica status -> idle */
  400. uartcc_set_felica_status(UARTCC_FELICA_STATAUS_IDLE);
  401. FELICA_PR_ERR(" %s ERROR(down_interruptible)\n", \
  402. __func__);
  403. return -ERESTARTSYS;
  404. }
  405. /* set felica status -> in use */
  406. uartcc_set_felica_status(UARTCC_FELICA_STATAUS_IN_USE);
  407. felica_poll->rsp_done = 0;
  408. FELICA_PR_DBG(" %s END\n", __func__);
  409. return 0;
  410. }
  411. #endif /* CONFIG_NFC_FELICA */
  412. /*
  413. * close device
  414. */
  415. static int felica_uart_close(struct inode *inode, struct file *file)
  416. {
  417. int ret;
  418. FELICA_PR_DBG(" %s START", __func__);
  419. if (down_interruptible(&dev_sem->felica_sem)) {
  420. FELICA_PR_ERR(" %s ERROR(down_interruptible)", \
  421. __func__);
  422. return -ERESTARTSYS;
  423. }
  424. gfa_open_cnt--;
  425. if (gfa_open_cnt == 0) {
  426. memset(gfa_send_str, 0, FELICA_NL_MSG_SIZE);
  427. memset(gfa_rcv_str, 0, FELICA_NL_MSG_SIZE);
  428. gfa_send_str[0] = FELICA_NL_REQ_CLOSE;
  429. ret = felica_nl_send_msg(1);
  430. if (ret == 0) {
  431. felica_nl_wait_ret_msg();
  432. if (gfa_rcv_str[1] == FELICA_NL_EFAILED) {
  433. FELICA_PR_ERR(" %s Close Fail",\
  434. __func__);
  435. gfa_open_cnt++;
  436. up(&dev_sem->felica_sem);
  437. return -EFAULT;
  438. }
  439. #ifdef CONFIG_NFC_FELICA
  440. /* set felica status -> idle */
  441. uartcc_set_felica_status(UARTCC_FELICA_STATAUS_IDLE);
  442. if (1 == available_d->available_flag) {
  443. if (0 != g_cen_sts) {
  444. if (GPIO_VALUE_LOW != g_rfs_sts) {
  445. available_d->rsp_done = 1;
  446. FELICA_PR_INFO(
  447. " wake up available");
  448. wake_up_interruptible(
  449. &available_d->read_wait);
  450. }
  451. }
  452. }
  453. #endif /* CONFIG_NFC_FELICA */
  454. } else {
  455. FELICA_PR_ERR(" %s felica_nl_send_msg Fail", \
  456. __func__);
  457. gfa_open_cnt++;
  458. up(&dev_sem->felica_sem);
  459. return -EFAULT;
  460. }
  461. #ifdef F_WAKE_LOCK
  462. wake_unlock(&felica_wake_2);
  463. FELICA_PR_INFO(" %s Wake UnLock(2)", __func__);
  464. #endif
  465. }
  466. up(&dev_sem->felica_sem);
  467. FELICA_PR_DBG(" %s END", __func__);
  468. return 0;
  469. }
  470. /*
  471. * read operation
  472. */
  473. static ssize_t felica_uart_read(struct file *file, char __user *buf,
  474. size_t len, loff_t *ppos)
  475. {
  476. int ret = 0;
  477. int nlret;
  478. size_t wk_len = 0;
  479. FELICA_PR_DBG(" %s START", __func__);
  480. if (down_interruptible(&dev_sem->felica_sem)) {
  481. FELICA_PR_ERR(" %s ERROR(down_interruptible)", \
  482. __func__);
  483. return -ERESTARTSYS;
  484. }
  485. memset(gfa_send_str, 0, FELICA_NL_MSG_SIZE);
  486. memset(gfa_rcv_str, 0, FELICA_NL_MSG_SIZE);
  487. wk_len = len;
  488. if (FELICA_NL_MSG_DATA_SIZE < wk_len) {
  489. FELICA_PR_INFO(" %s read max size over [%d]", __func__,
  490. wk_len);
  491. wk_len = FELICA_NL_MSG_DATA_SIZE;
  492. }
  493. gfa_send_str[0] = FELICA_NL_REQ_READ;
  494. gfa_send_str[1] = (char)(wk_len >> 8);
  495. gfa_send_str[2] = (char)wk_len;
  496. nlret = felica_nl_send_msg(3);
  497. wk_len = 0;
  498. if (nlret == 0) {
  499. felica_nl_wait_ret_msg();
  500. if (gfa_rcv_str[1] == FELICA_NL_SUCCESS) {
  501. wk_len =
  502. (((int)gfa_rcv_str[2] << 8) & 0xFF00) | \
  503. (int)gfa_rcv_str[3];
  504. FELICA_PR_DBG(" %s Rcv len [%d]", __func__, wk_len);
  505. FELICA_PR_DBG(
  506. " %s Rcv data [%x][%x][%x][%x][%x][%x][%x][%x][%x][%x]",
  507. __func__, gfa_rcv_str[4], gfa_rcv_str[5],
  508. gfa_rcv_str[6], gfa_rcv_str[7],
  509. gfa_rcv_str[8], gfa_rcv_str[9],
  510. gfa_rcv_str[10], gfa_rcv_str[11],
  511. gfa_rcv_str[12], gfa_rcv_str[13]);
  512. FELICA_PR_DBG(
  513. " %s Rcv data2 [%x][%x][%x][%x][%x][%x][%x][%x][%x][%x]",
  514. __func__, gfa_rcv_str[14], gfa_rcv_str[15],
  515. gfa_rcv_str[16], gfa_rcv_str[17],
  516. gfa_rcv_str[18], gfa_rcv_str[19],
  517. gfa_rcv_str[20], gfa_rcv_str[21],
  518. gfa_rcv_str[22], gfa_rcv_str[23]);
  519. FELICA_PR_DBG(
  520. " %s Rcv data3 [%x][%x][%x][%x][%x][%x][%x][%x][%x][%x]",
  521. __func__, gfa_rcv_str[24], gfa_rcv_str[25],
  522. gfa_rcv_str[26], gfa_rcv_str[27],
  523. gfa_rcv_str[28], gfa_rcv_str[29],
  524. gfa_rcv_str[30], gfa_rcv_str[31],
  525. gfa_rcv_str[32], gfa_rcv_str[33]);
  526. ret = copy_to_user(buf, &gfa_rcv_str[4], wk_len);
  527. if (ret != 0) {
  528. FELICA_PR_ERR
  529. ("%s ERROR(copy_from_user), ret=[%d]",
  530. __func__, ret);
  531. up(&dev_sem->felica_sem);
  532. return -EFAULT;
  533. }
  534. *ppos = *ppos + wk_len;
  535. } else {
  536. FELICA_PR_ERR(" %s FAIL", __func__);
  537. up(&dev_sem->felica_sem);
  538. return -EFAULT;
  539. }
  540. } else {
  541. FELICA_PR_ERR(" %s FAIL", __func__);
  542. up(&dev_sem->felica_sem);
  543. return -EFAULT;
  544. }
  545. up(&dev_sem->felica_sem);
  546. FELICA_PR_DBG(" %s END", __func__);
  547. return (ssize_t) wk_len;
  548. }
  549. /*
  550. * write operation
  551. */
  552. static ssize_t felica_uart_write(struct file *file, const char __user *data,
  553. size_t len, loff_t *ppos)
  554. {
  555. int ret = 0;
  556. int nlret;
  557. size_t wk_len = 0;
  558. FELICA_PR_DBG(" %s START", __func__);
  559. if (down_interruptible(&dev_sem->felica_sem)) {
  560. FELICA_PR_ERR(" %s ERROR(down_interruptible)", \
  561. __func__);
  562. return -ERESTARTSYS;
  563. }
  564. memset(gfa_send_str, 0, FELICA_NL_MSG_SIZE);
  565. memset(gfa_rcv_str, 0, FELICA_NL_MSG_SIZE);
  566. wk_len = len;
  567. if (FELICA_NL_MSG_DATA_SIZE < wk_len) {
  568. FELICA_PR_INFO(" %s read max size over [%d]", __func__,
  569. wk_len);
  570. wk_len = FELICA_NL_MSG_DATA_SIZE;
  571. }
  572. gfa_send_str[0] = FELICA_NL_REQ_WRITE;
  573. gfa_send_str[1] = (char)(wk_len >> 8);
  574. gfa_send_str[2] = (char)wk_len;
  575. ret = copy_from_user(&gfa_send_str[3], data, wk_len);
  576. if (ret != 0) {
  577. FELICA_PR_ERR(" %s ERROR(copy_from_user), ret=[%d]",
  578. __func__, ret);
  579. up(&dev_sem->felica_sem);
  580. return -EFAULT;
  581. }
  582. nlret = felica_nl_send_msg(3 + len);
  583. if (nlret == 0) {
  584. wk_len = 0;
  585. felica_nl_wait_ret_msg();
  586. wk_len = (((int)gfa_rcv_str[2] << 8) & 0xFF00) | \
  587. (int)gfa_rcv_str[3];
  588. if (gfa_rcv_str[1] == FELICA_NL_EFAILED) {
  589. FELICA_PR_ERR(" %s Write Fail", __func__);
  590. up(&dev_sem->felica_sem);
  591. return -EINVAL;
  592. }
  593. } else {
  594. FELICA_PR_ERR(" %s felica_nl_send_msg Fail", __func__);
  595. up(&dev_sem->felica_sem);
  596. return -EINVAL;
  597. }
  598. up(&dev_sem->felica_sem);
  599. FELICA_PR_DBG(" %s END", __func__);
  600. return wk_len;
  601. }
  602. /*
  603. * sync operation
  604. */
  605. static int felica_uart_sync(struct file *file, loff_t start,
  606. loff_t len, int datasync)
  607. {
  608. FELICA_PR_DBG(" %s START", __func__);
  609. FELICA_PR_DBG(" %s END", __func__);
  610. return 0;
  611. }
  612. /*
  613. * available operation
  614. */
  615. static long felica_uart_ioctl(struct file *file, unsigned int cmd,
  616. unsigned long arg)
  617. {
  618. unsigned int ret_str = 0;
  619. int ret;
  620. FELICA_PR_DBG(" %s START", __func__);
  621. FELICA_PR_INFO(" %s cmd = [0x%x]", __func__, cmd);
  622. /* Ignore [TCGETS:0x5401] and [TCSBRK:0x5409] */
  623. if (TCGETS == cmd || TCSBRK == cmd) {
  624. FELICA_PR_INFO(" %s cmd throw [0x%x]", __func__, cmd);
  625. return 0;
  626. }
  627. if (down_interruptible(&dev_sem->felica_sem)) {
  628. FELICA_PR_ERR(" %s ERROR(down_interruptible)", \
  629. __func__);
  630. return -ERESTARTSYS;
  631. }
  632. memset(gfa_send_str, 0, FELICA_NL_MSG_SIZE);
  633. memset(gfa_rcv_str, 0, FELICA_NL_MSG_SIZE);
  634. gfa_send_str[0] = FELICA_NL_REQ_AVAIABLE;
  635. ret = felica_nl_send_msg(1);
  636. if (ret == 0) {
  637. /* 20130216 add for APQ support -S- */
  638. /* 1ms sleep */
  639. usleep_range(1000, 1000);
  640. /* 20130216 add for APQ support -E- */
  641. felica_nl_wait_ret_msg();
  642. if (gfa_rcv_str[1] == FELICA_NL_SUCCESS) {
  643. /* create response data */
  644. ret_str =
  645. (((unsigned int)gfa_rcv_str[2] << 8) & 0xFF00) | \
  646. (unsigned int)gfa_rcv_str[3];
  647. FELICA_PR_INFO(" Available Success data size [%d]", \
  648. ret_str);
  649. } else {
  650. FELICA_PR_ERR(" %s Available Fail", __func__);
  651. up(&dev_sem->felica_sem);
  652. return -EINVAL;
  653. }
  654. } else {
  655. FELICA_PR_ERR(" %s felica_nl_send_msg Fail", __func__);
  656. up(&dev_sem->felica_sem);
  657. return -EINVAL;
  658. }
  659. up(&dev_sem->felica_sem);
  660. FELICA_PR_DBG(" %s END", __func__);
  661. return put_user(ret_str, (unsigned int __user *)arg);
  662. }
  663. /*
  664. * create netlink socket
  665. */
  666. static void felica_nl_init(void)
  667. {
  668. FELICA_PR_DBG(" %s START", __func__);
  669. gfa_connect_flag = 0;
  670. gfa_pid = 0;
  671. gfa_wait_flag = 0;
  672. memset(gfa_send_str, 0, FELICA_NL_MSG_SIZE);
  673. memset(gfa_rcv_str, 0, FELICA_NL_MSG_SIZE);
  674. gfanl_sk =
  675. netlink_kernel_create(&init_net, FELICA_NL_NETLINK_USER, 0,
  676. felica_nl_recv_msg, NULL, THIS_MODULE);
  677. if (!gfanl_sk)
  678. FELICA_PR_ERR(" Error creating socket. %s\n", __func__);
  679. FELICA_PR_DBG(" %s END", __func__);
  680. }
  681. /*
  682. * release netlink socket
  683. */
  684. static void felica_nl_exit(void)
  685. {
  686. FELICA_PR_DBG(" %s START", __func__);
  687. netlink_kernel_release(gfanl_sk);
  688. FELICA_PR_DBG(" %s END", __func__);
  689. }
  690. /*
  691. * send message to FeliCa-Serial-Connector
  692. */
  693. static int felica_nl_send_msg(int len)
  694. {
  695. struct nlmsghdr *nlh;
  696. struct sk_buff *skb_out;
  697. int msg_size = 0;
  698. FELICA_PR_DBG(" %s START len: %d", __func__,len);
  699. if (!gfanl_sk) {
  700. FELICA_PR_ERR("Error Not creating socket. %s\n",
  701. __func__);
  702. return 1;
  703. }
  704. if (gfa_pid == 0) {
  705. FELICA_PR_ERR("Error Not Rcv Connect Msg %s\n",
  706. __func__);
  707. return 1;
  708. }
  709. msg_size = len;
  710. skb_out = nlmsg_new(msg_size, 0);
  711. if (!skb_out) {
  712. FELICA_PR_ERR(" Failed to allocate new skb_out %s\n", __func__);
  713. return 1;
  714. }
  715. nlh = nlmsg_put(skb_out, 0, 0, NLMSG_DONE, msg_size, 0);
  716. NETLINK_CB(skb_out).dst_group = 0;
  717. memcpy(NLMSG_DATA(nlh), gfa_send_str, msg_size);
  718. /* "skb_out" will release by netlink.*/
  719. nlmsg_unicast(gfanl_sk, skb_out, gfa_pid);
  720. FELICA_PR_DBG(" %s END", __func__);
  721. return 0;
  722. }
  723. /*
  724. * receive message from FeliCa-Serial-Connector
  725. */
  726. static void felica_nl_recv_msg(struct sk_buff *skb)
  727. {
  728. struct nlmsghdr *nlh;
  729. struct sk_buff *wskb;
  730. #ifdef FELICA_UICC_FUNCTION
  731. int init_flag = 0;
  732. #endif
  733. if (!skb) {
  734. FELICA_PR_ERR(" %s ERROR(skb NULL)", __func__);
  735. return;
  736. }
  737. wskb = skb_get(skb);
  738. if (wskb && (wskb->len > NLMSG_SPACE(0))) {
  739. nlh = nlmsg_hdr(wskb);
  740. memcpy(gfa_rcv_str, NLMSG_DATA(nlh), sizeof(gfa_rcv_str));
  741. FELICA_PR_DBG(" %s START gfa_rcv_str[0]: 0x%x", __func__,gfa_rcv_str[0]);
  742. if ((gfa_rcv_str[0] == FELICA_NL_CONNECT_MSG)
  743. && (gfa_connect_flag == 0)) {
  744. /* pid of sending process */
  745. gfa_pid = nlh->nlmsg_pid;
  746. if (felica_get_tamper_fuse_cmd() != 1)
  747. {
  748. /* jmodel */
  749. #if defined(CONFIG_ARCH_EXYNOS)
  750. s3c_gpio_cfgall_range(FELICA_UART1RX, 2,\
  751. S3C_GPIO_SFN(2), S3C_GPIO_PULL_DOWN);
  752. felica_uart_port = 1;
  753. #elif defined(CONFIG_ARCH_APQ8064)
  754. felica_uart_port = 2;
  755. #elif defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_SBM)
  756. felica_uart_port = 2;
  757. #elif defined(CONFIG_MACH_HLTEDCM) || defined(CONFIG_MACH_HLTEKDI) || defined(CONFIG_MACH_JS01LTEDCM)
  758. felica_uart_port = 1;
  759. #endif
  760. felica_set_felica_info();
  761. felica_uart_init();
  762. felica_pon_init();
  763. felica_cen_init();
  764. felica_rfs_init();
  765. felica_rws_init();
  766. felica_ant_init();
  767. #ifdef CONFIG_NFC_FELICA
  768. snfc_uart_init();
  769. cxd2235power_init();
  770. hsel_init();
  771. snfc_rfs_init();
  772. available_poll_init();
  773. snfc_cen_init();
  774. #endif
  775. if (gdiag_name[0] != 0x00)
  776. felica_uid_init();
  777. }
  778. gfa_connect_flag = 1;
  779. #ifdef FELICA_UICC_FUNCTION
  780. init_flag = 1;
  781. guartcc_felica_status = UARTCC_FELICA_STATAUS_IN_INIT;
  782. FELICA_PR_INFO(" RCV MSG [%d]", gfa_rcv_str[0]);
  783. #endif
  784. } else if ((gfa_rcv_str[0] == FELICA_NL_RESPONCE)
  785. && (gfa_pid == nlh->nlmsg_pid)) {
  786. /* wake up */
  787. gfa_wait_flag = 1;
  788. #ifdef FELICA_UICC_FUNCTION
  789. } else if ((gfa_rcv_str[0] == FELICA_INIT_UICC_END)
  790. && (gfa_pid == nlh->nlmsg_pid)) {
  791. FELICA_PR_INFO("RCV MSG FELICA_INIT_UICC_END [%d]",
  792. gfa_rcv_str[0]);
  793. if (gfa_rcv_str[1] == FELICA_NL_SUCCESS)
  794. FELICA_PR_INFO("UICC INIT END SUCCESS");
  795. else
  796. FELICA_PR_INFO("UICC INIT END FAIL");
  797. guartcc_felica_status = UARTCC_FELICA_STATAUS_IDLE;
  798. #endif
  799. } else {
  800. FELICA_PR_ERR(" %s ERROR(RCV Undefine MSG) RCV MSG [%d], rcv pid [%d], gfa_pid [%d]",
  801. __func__, gfa_rcv_str[0],nlh->nlmsg_pid,gfa_pid);
  802. }
  803. }
  804. kfree_skb(skb);
  805. #ifdef FELICA_UICC_FUNCTION
  806. if (init_flag) {
  807. FELICA_PR_INFO("UICC INIT START");
  808. memset(gfa_send_str, 0, FELICA_NL_MSG_SIZE);
  809. memset(gfa_rcv_str, 0, FELICA_NL_MSG_SIZE);
  810. gfa_send_str[0] = FELICA_NL_INIT_END_RES;
  811. felica_nl_send_msg(1);
  812. }
  813. #endif
  814. FELICA_PR_DBG(" %s END", __func__);
  815. }
  816. static void felica_set_felica_info(void)
  817. {
  818. FELICA_PR_DBG(" %s START ", __func__);
  819. memset(gdiag_name, 0x00, DIAG_NAME_MAXSIZE + 1);
  820. #ifdef FELICA_UICC_FUNCTION
  821. memset(gproc_name, 0x00, PROC_NAME_MAXSIZE + 1);
  822. #endif
  823. gread_msgs[0].flags = gfa_rcv_str[MSG_READ1_FLAGS_OFFSET];
  824. gread_msgs[0].len = gfa_rcv_str[MSG_READ1_LEN_OFFSET];
  825. gread_msgs[1].flags = gfa_rcv_str[MSG_READ2_FLAGS_OFFSET];
  826. gread_msgs[1].len = gfa_rcv_str[MSG_READ2_LEN_OFFSET];
  827. gwrite_msgs[0].flags = gfa_rcv_str[MSG_WRITE_FLAGS_OFFSET];
  828. gwrite_msgs[0].len = gfa_rcv_str[MSG_WRITE_LEN_OFFSET];
  829. gi2c_lockaddress = gfa_rcv_str[MSG_LOCK_ADDR_OFFSET];
  830. gi2c_address = gfa_rcv_str[MSG_I2C_ADDR_OFFSET];
  831. memcpy(gdiag_name, &gfa_rcv_str[MSG_DIAG_NAME_OFFSET],
  832. DIAG_NAME_MAXSIZE);
  833. gmfc_uid =
  834. (((int)gfa_rcv_str[MSG_MFC_UID_FRONT_OFFSET] << 8) & 0xFF00) |
  835. (int)gfa_rcv_str[MSG_MFC_UID_BACK_OFFSET];
  836. gmfl_uid =
  837. (((int)gfa_rcv_str[MSG_MFL_UID_FRONT_OFFSET] << 8) & 0xFF00) |
  838. (int)gfa_rcv_str[MSG_MFL_UID_BACK_OFFSET];
  839. gi2c_antaddress = gfa_rcv_str[MSG_ANT_ADDR_OFFSET];
  840. gant_uid =
  841. (((int)gfa_rcv_str[MSG_ANT_UID_FRONT_OFFSET] << 8) & 0xFF00) |
  842. (int)gfa_rcv_str[MSG_ANT_UID_BACK_OFFSET];
  843. #ifdef CONFIG_NFC_FELICA
  844. gnfc_uid =
  845. (((int)gfa_rcv_str[MSG_NFC_UID_FRONT_OFFSET] << 8) & 0xFF00) |
  846. (int)gfa_rcv_str[MSG_NFC_UID_BACK_OFFSET];
  847. snfc_cen_sts_init();
  848. #endif
  849. #ifdef FELICA_UICC_FUNCTION
  850. memcpy(gproc_name, &gfa_rcv_str[MSG_PROC_NAME_OFFSET],
  851. PROC_NAME_MAXSIZE);
  852. #endif
  853. FELICA_PR_DBG(" %s END", __func__);
  854. }
  855. /*
  856. * waiting to receive messages from FeliCa-Serial-Connector
  857. */
  858. static void felica_nl_wait_ret_msg(void)
  859. {
  860. unsigned int cnt = 0;
  861. FELICA_PR_DBG(" %s START ", __func__);
  862. while (1) {
  863. if (gfa_wait_flag == 1) {
  864. FELICA_PR_DBG(" %s sleep cnt [%d]", __func__,
  865. cnt);
  866. break;
  867. }
  868. mdelay(1);
  869. cnt++;
  870. }
  871. gfa_wait_flag = 0;
  872. FELICA_PR_DBG(" %s END ", __func__);
  873. }
  874. #if defined(CONFIG_ARCH_EXYNOS)
  875. static int felica_smc_read_oemflag(u32 ctrl_word, u32 *val)
  876. {
  877. register u32 reg0 __asm__("r0");
  878. register u32 reg1 __asm__("r1");
  879. register u32 reg2 __asm__("r2");
  880. register u32 reg3 __asm__("r3");
  881. u32 idx = 0;
  882. for (idx = 0; reg2 != ctrl_word; idx++) {
  883. reg0 = -202;
  884. reg1 = 1;
  885. reg2 = idx;
  886. __asm__ volatile ("smc 0\n" : "+r" (reg0), "+r"(reg1),
  887. "+r"(reg2), "+r"(reg3)
  888. );
  889. if (reg1)
  890. return -1;
  891. }
  892. reg0 = -202;
  893. reg1 = 1;
  894. reg2 = idx;
  895. __asm__ volatile ("smc 0\n" : "+r" (reg0), "+r"(reg1),
  896. "+r"(reg2), "+r"(reg3)
  897. );
  898. if (reg1)
  899. return -1;
  900. *val = reg2;
  901. return 0;
  902. }
  903. static int felica_Cpu0(void)
  904. {
  905. int ret = 0;
  906. struct cpumask mask = CPU_MASK_CPU0;
  907. FELICA_PR_INFO(" System has %d CPU's, we are on CPU #%d\n"
  908. "\tBinding this process to CPU #0.\n"
  909. "\tactive mask is %lx, setting it to mask=%lx\n",
  910. nr_cpu_ids,
  911. raw_smp_processor_id(), cpu_active_mask->bits[0], mask.bits[0]);
  912. ret = set_cpus_allowed_ptr(current, &mask);
  913. if (0 != ret)
  914. FELICA_PR_INFO(" set_cpus_allowed_ptr=%d.\n", ret);
  915. FELICA_PR_INFO(" And now we are on CPU #%d", raw_smp_processor_id());
  916. return ret;
  917. }
  918. static int felica_CpuAll(void)
  919. {
  920. int ret = 0;
  921. struct cpumask mask = CPU_MASK_ALL;
  922. FELICA_PR_INFO(" System has %d CPU's, we are on CPU #%d\n"
  923. "\tBinding this process to CPU #0.\n"
  924. "\tactive mask is %lx, setting it to mask=%lx\n",
  925. nr_cpu_ids,
  926. raw_smp_processor_id(), cpu_active_mask->bits[0], mask.bits[0]);
  927. ret = set_cpus_allowed_ptr(current, &mask);
  928. if (0 != ret)
  929. FELICA_PR_INFO(" set_cpus_allowed_ptr=%d.\n", ret);
  930. FELICA_PR_INFO(" And now we are on CPU #%d", raw_smp_processor_id());
  931. return ret;
  932. }
  933. static uint8_t felica_get_tamper_fuse_cmd(void)
  934. {
  935. u32 fuse_id = 0;
  936. int ret;
  937. ret = felica_Cpu0();
  938. if (0 != ret) {
  939. FELICA_PR_ERR(" changing core failed!");
  940. return -1;
  941. }
  942. FELICA_PR_INFO(" get_fuse");
  943. if (felica_smc_read_oemflag(0x80010001, (u32 *)&fuse_id) < 0) {
  944. FELICA_PR_ERR(" %s read flag error", __func__);
  945. return -1;
  946. }
  947. FELICA_PR_INFO(" Kernel Status[%x]", fuse_id);
  948. felica_CpuAll();
  949. return (uint8_t)fuse_id;
  950. }
  951. #elif defined(CONFIG_ARCH_APQ8064) || defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  952. static uint8_t felica_get_tamper_fuse_cmd(void)
  953. {
  954. uint32_t fuse_id = FELICA_HLOS_IMG_TAMPER_FUSE;
  955. void *cmd_buf;
  956. size_t cmd_len;
  957. size_t resp_len = 0;
  958. uint8_t resp_buf;
  959. FELICA_PR_DBG(" %s START ", __func__);
  960. resp_len = sizeof(resp_buf);
  961. cmd_buf = (void *)&fuse_id;
  962. cmd_len = sizeof(fuse_id);
  963. scm_call(FELICA_SCM_SVC_FUSE, FELICA_SCM_IS_SW_FUSE_BLOWN_ID, cmd_buf,
  964. cmd_len, &resp_buf, resp_len);
  965. FELICA_PR_DBG(" %s END resp_buf = %d\n",__func__, resp_buf);
  966. #ifdef NO_CHECK_TAMPER
  967. FELICA_PR_ERR(" No checking tampered kernel just for test!\n");
  968. return 0;
  969. #endif
  970. return resp_buf;
  971. }
  972. #endif
  973. /******************************************************************************
  974. * /dev/felica_pon
  975. *****************************************************************************/
  976. /* character device definition */
  977. static dev_t devid_felica_pon;
  978. static struct cdev cdev_felica_pon;
  979. static const struct file_operations fops_felica_pon = {
  980. .owner = THIS_MODULE,
  981. .open = felica_pon_open,
  982. .release = felica_pon_close,
  983. .read = felica_pon_read,
  984. .write = felica_pon_write,
  985. };
  986. /*
  987. * initialize device
  988. */
  989. static void felica_pon_init(void)
  990. {
  991. int ret;
  992. struct device *device_felica_pon;
  993. FELICA_PR_DBG(" %s START", __func__);
  994. devid_felica_pon = MKDEV(FELICA_MAJOR, FELICA_MINOR);
  995. ret =
  996. alloc_chrdev_region(&devid_felica_pon, FELICA_BASEMINOR,
  997. FELICA_MINOR_COUNT, FELICA_PON_NAME);
  998. if (ret < 0) {
  999. FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
  1000. __func__, ret);
  1001. return;
  1002. }
  1003. cdev_init(&cdev_felica_pon, &fops_felica_pon);
  1004. ret = cdev_add(&cdev_felica_pon, devid_felica_pon, FELICA_MINOR_COUNT);
  1005. if (ret < 0) {
  1006. unregister_chrdev_region(devid_felica_pon, FELICA_MINOR_COUNT);
  1007. FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
  1008. ret);
  1009. return;
  1010. }
  1011. device_felica_pon =
  1012. device_create(felica_class, NULL, devid_felica_pon, NULL,
  1013. FELICA_PON_NAME);
  1014. if (IS_ERR(device_felica_pon)) {
  1015. cdev_del(&cdev_felica_pon);
  1016. unregister_chrdev_region(devid_felica_pon, FELICA_MINOR_COUNT);
  1017. FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
  1018. return;
  1019. }
  1020. FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
  1021. MAJOR(devid_felica_pon), MINOR(devid_felica_pon));
  1022. }
  1023. /*
  1024. * finalize device
  1025. */
  1026. static void felica_pon_exit(void)
  1027. {
  1028. FELICA_PR_DBG(" %s START", __func__);
  1029. device_destroy(felica_class, devid_felica_pon);
  1030. cdev_del(&cdev_felica_pon);
  1031. unregister_chrdev_region(devid_felica_pon, FELICA_MINOR_COUNT);
  1032. FELICA_PR_DBG(" %s START", __func__);
  1033. }
  1034. /*
  1035. * open device
  1036. */
  1037. static int felica_pon_open(struct inode *inode, struct file *file)
  1038. {
  1039. uid_t uid;
  1040. #ifdef FELICA_UICC_FUNCTION
  1041. int ret = 0;
  1042. char *cmdpos;
  1043. static char cmdline[1025];
  1044. static unsigned long start_adr, end_adr, leng;
  1045. #endif
  1046. #ifdef FELICA_UICC_FUNCTION
  1047. start_adr = current->mm->arg_start;
  1048. end_adr = current->mm->arg_end;
  1049. leng = end_adr - start_adr;
  1050. if (1024 < leng)
  1051. leng = 1024;
  1052. cmdpos = (char *)(current->mm->arg_start);
  1053. ret = copy_from_user(cmdline, cmdpos, leng);
  1054. cmdline[leng] = '\0';
  1055. if(ret != 0)
  1056. {
  1057. FELICA_PR_ERR(" %s cmdline[%s] ret[%d]", __func__, cmdline, ret);
  1058. return -EFAULT;
  1059. }
  1060. #endif
  1061. uid = __task_cred(current)->uid;
  1062. #ifdef FELICA_UICC_FUNCTION
  1063. if (((uid != gmfc_uid) && (uid != gdiag_uid)
  1064. && (uid != gant_uid)) &&
  1065. (strncmp(cmdline,gproc_name, leng) != 0)) {
  1066. #else
  1067. if ((uid != gmfc_uid) && (uid != gdiag_uid)
  1068. && (uid != gant_uid)) {
  1069. #endif
  1070. FELICA_PR_ERR
  1071. (" %s END -EACCES, uid=[%d], gmfc_uid=[%d], gdiag_uid=[%d]",
  1072. __func__, uid, gmfc_uid, gdiag_uid);
  1073. #ifdef SRIB_DIAG_ENABLED
  1074. FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
  1075. #else
  1076. return -EACCES;
  1077. #endif
  1078. }
  1079. FELICA_PR_DBG(" %s END", __func__);
  1080. return 0;
  1081. }
  1082. /*
  1083. * close device
  1084. */
  1085. static int felica_pon_close(struct inode *inode, struct file *file)
  1086. {
  1087. #if defined(CONFIG_ARCH_EXYNOS)
  1088. gpio_set_value(GPIO_PINID_FELICA_PON, GPIO_VALUE_LOW);
  1089. #elif defined(CONFIG_ARCH_APQ8064)
  1090. ice_gpiox_set(GPIO_PINID_FELICA_PON, GPIO_VALUE_LOW);
  1091. #elif defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  1092. #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
  1093. gpio_set_value(gfelica_pon_pin, GPIO_VALUE_LOW);
  1094. #else
  1095. gpio_set_value(GPIO_PINID_FELICA_PON, GPIO_VALUE_LOW);
  1096. #endif // CONFIG_MACH_KLTE
  1097. #endif
  1098. FELICA_PR_DBG(" %s END", __func__);
  1099. return 0;
  1100. }
  1101. /*
  1102. * read operation
  1103. */
  1104. static ssize_t felica_pon_read(struct file *file, char __user *buf, size_t len,
  1105. loff_t *ppos)
  1106. {
  1107. int ret;
  1108. char retparam;
  1109. #if defined(CONFIG_ARCH_EXYNOS)
  1110. ret = gpio_get_value(GPIO_PINID_FELICA_PON);
  1111. #elif defined(CONFIG_ARCH_APQ8064)
  1112. ret = ice_gpiox_get(GPIO_PINID_FELICA_PON);
  1113. #elif defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  1114. #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
  1115. ret = gpio_get_value(gfelica_pon_pin);
  1116. #else
  1117. ret = gpio_get_value(GPIO_PINID_FELICA_PON);
  1118. #endif // CONFIG_MACH_KLTE
  1119. #endif
  1120. FELICA_PR_INFO(" %s GPIO Read value of GPIO_PINID_FELICA_PON -> ret=[%d]", __func__,ret);
  1121. if (ret == GPIO_VALUE_HIGH) {
  1122. retparam = FELICA_PON_WIRED;
  1123. FELICA_PR_INFO(" Wired interface Status is [%d][start]",
  1124. retparam);
  1125. } else if (ret == GPIO_VALUE_LOW) {
  1126. retparam = FELICA_PON_WIRELESS;
  1127. FELICA_PR_INFO(" Wired interface Status is [%d][standby]",
  1128. retparam);
  1129. } else {
  1130. FELICA_PR_ERR(" %s ERROR(gpio_get_value), ret=[%d]",
  1131. __func__, ret);
  1132. return -EIO;
  1133. }
  1134. ret = copy_to_user(buf, &retparam, FELICA_PON_DATA_LEN);
  1135. if (ret != 0) {
  1136. FELICA_PR_ERR(" %s ERROR(copy_to_user), ret=[%d]",
  1137. __func__, ret);
  1138. return -EFAULT;
  1139. }
  1140. *ppos += 1;
  1141. return FELICA_PON_DATA_LEN;
  1142. }
  1143. /*
  1144. * write operation
  1145. */
  1146. static ssize_t felica_pon_write(struct file *file, const char __user *data,
  1147. size_t len, loff_t *ppos)
  1148. {
  1149. char pon;
  1150. int ret;
  1151. int setparam;
  1152. ret = copy_from_user(&pon, data, FELICA_PON_DATA_LEN);
  1153. if (ret != 0) {
  1154. FELICA_PR_ERR(" %s ERROR(copy_from_user), ret=[%d]",
  1155. __func__, ret);
  1156. return -EFAULT;
  1157. }
  1158. if (pon == FELICA_PON_WIRED) {
  1159. setparam = GPIO_VALUE_HIGH;
  1160. FELICA_PR_INFO(" Set wired interface to [%d][start]",
  1161. setparam);
  1162. } else if (pon == FELICA_PON_WIRELESS) {
  1163. setparam = GPIO_VALUE_LOW;
  1164. FELICA_PR_INFO(" Set wired interface to [%d][standby]",
  1165. setparam);
  1166. } else {
  1167. FELICA_PR_ERR(" %s ERROR(copy_from_user), pon=[%d]",
  1168. __func__, pon);
  1169. return -EINVAL;
  1170. }
  1171. #if defined(CONFIG_ARCH_EXYNOS)
  1172. gpio_set_value(GPIO_PINID_FELICA_PON, setparam);
  1173. #elif defined(CONFIG_ARCH_APQ8064)
  1174. ice_gpiox_set(GPIO_PINID_FELICA_PON, setparam);
  1175. #elif defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  1176. #if defined(CONFIG_MACH_KLTE_KDI)
  1177. if(gfelica_uim_mon == 1) {
  1178. FELICA_PR_ERR(" %s gfelica_uim_mon=%d\n", __func__, gfelica_uim_mon);
  1179. gpio_set_value(gfelica_pon_pin, GPIO_VALUE_HIGH);
  1180. return FELICA_PON_DATA_LEN;
  1181. }
  1182. gpio_set_value(gfelica_pon_pin, setparam);
  1183. #elif defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
  1184. gpio_set_value(gfelica_pon_pin, setparam);
  1185. #else
  1186. gpio_set_value(GPIO_PINID_FELICA_PON, setparam);
  1187. #endif // CONFIG_MACH_KLTE
  1188. #endif
  1189. return FELICA_PON_DATA_LEN;
  1190. }
  1191. /******************************************************************************
  1192. * felica_i2c_driver
  1193. ******************************************************************************/
  1194. static struct i2c_client *felica_i2c_client;
  1195. static const struct i2c_device_id felica_i2c_idtable[] =
  1196. {
  1197. {FELICA_I2C_NAME, 0},
  1198. {}
  1199. };
  1200. MODULE_DEVICE_TABLE(i2c, felica_i2c_idtable);
  1201. #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  1202. static struct of_device_id felica_i2c_match_table[] =
  1203. {
  1204. { .compatible = "felica,felica-i2c",},
  1205. {},
  1206. };
  1207. #endif
  1208. static struct i2c_driver felica_i2c_driver =
  1209. {
  1210. .probe = felica_i2c_probe,
  1211. .remove = felica_i2c_remove,
  1212. .driver =
  1213. {
  1214. .name = FELICA_I2C_NAME,
  1215. .owner = THIS_MODULE,
  1216. #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  1217. .of_match_table = felica_i2c_match_table,
  1218. #endif
  1219. },
  1220. .id_table = felica_i2c_idtable,
  1221. };
  1222. /*
  1223. * felica_i2c_init
  1224. */
  1225. static void felica_i2c_init(void)
  1226. {
  1227. int ret;
  1228. FELICA_PR_DBG(" %s START", __func__);
  1229. ret = i2c_add_driver(&felica_i2c_driver);
  1230. if (ret < 0) {
  1231. FELICA_PR_ERR(" %s ERROR(i2c_add_driver), ret=[%d]",
  1232. __func__, ret);
  1233. return;
  1234. }
  1235. FELICA_PR_DBG(" %s END", __func__);
  1236. return;
  1237. }
  1238. /*
  1239. * felica_i2c_exit
  1240. */
  1241. static void felica_i2c_exit(void)
  1242. {
  1243. FELICA_PR_DBG(" %s START", __func__);
  1244. i2c_del_driver(&felica_i2c_driver);
  1245. FELICA_PR_DBG(" %s END", __func__);
  1246. return;
  1247. }
  1248. /*
  1249. * probe device
  1250. */
  1251. static int felica_i2c_probe(struct i2c_client *client,
  1252. const struct i2c_device_id *devid)
  1253. {
  1254. FELICA_PR_INFO(" %s START", __func__);
  1255. felica_i2c_client = client;
  1256. if (!felica_i2c_client) {
  1257. FELICA_PR_ERR(" %s ERROR(felica_i2c_client==NULL)", \
  1258. __func__);
  1259. return -EINVAL;
  1260. }
  1261. FELICA_PR_INFO(" %s END", __func__);
  1262. return 0;
  1263. }
  1264. /*
  1265. * remove device
  1266. */
  1267. static int felica_i2c_remove(struct i2c_client *client)
  1268. {
  1269. /* no operation */
  1270. FELICA_PR_DBG(" %s END", __func__);
  1271. return 0;
  1272. }
  1273. /******************************************************************************
  1274. * /dev/felica_cen
  1275. ******************************************************************************/
  1276. /* character device definition */
  1277. static dev_t devid_felica_cen;
  1278. static struct cdev cdev_felica_cen;
  1279. static const struct file_operations fops_felica_cen = {
  1280. .owner = THIS_MODULE,
  1281. .open = felica_cen_open,
  1282. .release = felica_cen_close,
  1283. .read = felica_cen_read,
  1284. .write = felica_cen_write,
  1285. };
  1286. /*
  1287. * felica_cen_init
  1288. */
  1289. static void felica_cen_init(void)
  1290. {
  1291. int ret;
  1292. struct device *device_felica_cen;
  1293. FELICA_PR_DBG(" %s START", __func__);
  1294. devid_felica_cen = MKDEV(FELICA_MAJOR, FELICA_MINOR);
  1295. ret =
  1296. alloc_chrdev_region(&devid_felica_cen, FELICA_BASEMINOR,
  1297. FELICA_MINOR_COUNT, FELICA_CEN_NAME);
  1298. if (ret < 0) {
  1299. FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
  1300. __func__, ret);
  1301. return;
  1302. }
  1303. cdev_init(&cdev_felica_cen, &fops_felica_cen);
  1304. ret = cdev_add(&cdev_felica_cen, devid_felica_cen, FELICA_MINOR_COUNT);
  1305. if (ret < 0) {
  1306. unregister_chrdev_region(devid_felica_cen, FELICA_MINOR_COUNT);
  1307. FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
  1308. ret);
  1309. return;
  1310. }
  1311. device_felica_cen =
  1312. device_create(felica_class, NULL, devid_felica_cen, NULL,
  1313. FELICA_CEN_NAME);
  1314. if (IS_ERR(device_felica_cen)) {
  1315. cdev_del(&cdev_felica_cen);
  1316. unregister_chrdev_region(devid_felica_cen, FELICA_MINOR_COUNT);
  1317. FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
  1318. return;
  1319. }
  1320. FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
  1321. MAJOR(devid_felica_cen), MINOR(devid_felica_cen));
  1322. }
  1323. /*
  1324. * felica_cen_exit
  1325. */
  1326. static void felica_cen_exit(void)
  1327. {
  1328. FELICA_PR_DBG(" %s START", __func__);
  1329. device_destroy(felica_class, devid_felica_cen);
  1330. cdev_del(&cdev_felica_cen);
  1331. unregister_chrdev_region(devid_felica_cen, FELICA_MINOR_COUNT);
  1332. FELICA_PR_DBG(" %s END", __func__);
  1333. }
  1334. /*
  1335. * open device
  1336. */
  1337. static int felica_cen_open(struct inode *inode, struct file *file)
  1338. {
  1339. uid_t uid;
  1340. #ifdef FELICA_UICC_FUNCTION
  1341. int ret = 0;
  1342. char *cmdpos;
  1343. static char cmdline[1025];
  1344. static unsigned long start_adr, end_adr, leng;
  1345. #endif
  1346. FELICA_PR_DBG(" %s START . system_rev=[%d]", __func__,system_rev);
  1347. #if defined(CONFIG_MACH_HLTEDCM)
  1348. //high
  1349. if (system_rev == HW_REV09_OR_10)
  1350. {
  1351. FELICA_PR_INFO(" %s Making MHL_EN HIGH", __func__);
  1352. of_sii8240_hw_poweron(FELICA_CEN_UNLOCK);
  1353. }
  1354. #endif
  1355. #ifdef FELICA_UICC_FUNCTION
  1356. start_adr = current->mm->arg_start;
  1357. end_adr = current->mm->arg_end;
  1358. leng = end_adr - start_adr;
  1359. if (1024 < leng)
  1360. leng = 1024;
  1361. cmdpos = (char *)(current->mm->arg_start);
  1362. ret = copy_from_user(cmdline, cmdpos, leng);
  1363. cmdline[leng] = '\0';
  1364. if(ret != 0)
  1365. {
  1366. FELICA_PR_ERR(" %s cmdline[%s] ret[%d]", __func__, cmdline, ret);
  1367. return -EFAULT;
  1368. }
  1369. #endif
  1370. uid = __task_cred(current)->uid;
  1371. if (file->f_mode & FMODE_WRITE) {
  1372. #ifdef FELICA_UICC_FUNCTION
  1373. if ((uid != gdiag_uid) && (uid != gmfl_uid)
  1374. && (strncmp(cmdline,gproc_name, leng) != 0)) {
  1375. #else
  1376. if ((uid != gdiag_uid) && (uid != gmfl_uid)) {
  1377. #endif
  1378. FELICA_PR_ERR(" %s END -EACCES, uid=[%d], gmfc_uid=[%d], gdiag_uid=[%d], gmfl_uid=[%d]\n", __func__, uid,gmfc_uid,gdiag_uid,gmfl_uid);
  1379. #if defined(CONFIG_MACH_HLTEDCM)
  1380. //low
  1381. if (system_rev == HW_REV09_OR_10)
  1382. {
  1383. FELICA_PR_INFO(" %s Making MHL_EN LOW", __func__);
  1384. // of_sii8240_hw_poweron(FELICA_CEN_LOCK);
  1385. }
  1386. #endif
  1387. #ifdef SRIB_DIAG_ENABLED
  1388. FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
  1389. #else
  1390. return -EACCES;
  1391. #endif
  1392. }
  1393. }
  1394. FELICA_PR_DBG(" %s END", __func__);
  1395. return 0;
  1396. }
  1397. /*
  1398. * close device
  1399. */
  1400. static int felica_cen_close(struct inode *inode, struct file *file)
  1401. {
  1402. /* no operation */
  1403. #if defined(CONFIG_MACH_HLTEDCM)
  1404. //low
  1405. if (system_rev == HW_REV09_OR_10)
  1406. {
  1407. FELICA_PR_INFO(" %s Making MHL_EN LOW", __func__);
  1408. // of_sii8240_hw_poweron(FELICA_CEN_LOCK);
  1409. }
  1410. #endif
  1411. FELICA_PR_DBG(" %s END system_rev=[%d]", __func__,system_rev);
  1412. return 0;
  1413. }
  1414. /*
  1415. * read operation
  1416. */
  1417. static ssize_t felica_cen_read(struct file *file, char __user *buf, \
  1418. size_t len, loff_t *ppos)
  1419. {
  1420. int ret;
  1421. unsigned char address = gi2c_lockaddress;
  1422. unsigned char read_buff = 0;
  1423. struct i2c_msg read_msgs[2];
  1424. read_msgs[0].flags = gread_msgs[0].flags;
  1425. read_msgs[0].len = gread_msgs[0].len;
  1426. read_msgs[1].flags = gread_msgs[1].flags;
  1427. read_msgs[1].len = gread_msgs[1].len;
  1428. read_msgs[0].addr = gi2c_address;
  1429. read_msgs[0].buf = &address;
  1430. read_msgs[1].addr = gi2c_address;
  1431. read_msgs[1].buf = &read_buff;
  1432. if (felica_i2c_client == NULL) {
  1433. FELICA_PR_ERR(" felica_i2c_client is NULL %s -EIO",__func__);
  1434. return -EIO;
  1435. }
  1436. ret = i2c_transfer(felica_i2c_client->adapter, &read_msgs[0], 1);
  1437. if (ret < 0) {
  1438. FELICA_PR_ERR(" %s ERROR(i2c_transfer[0]), ret=[%d]",
  1439. __func__, ret);
  1440. return -EIO;
  1441. }
  1442. ret = i2c_transfer(felica_i2c_client->adapter, &read_msgs[1], 1);
  1443. if (ret < 0) {
  1444. FELICA_PR_ERR(" %s ERROR(i2c_transfer[1]), ret=[%d]",
  1445. __func__, ret);
  1446. return -EIO;
  1447. }
  1448. read_buff &= FELICA_CONTROL_LOCK_MASK;
  1449. #ifdef CONFIG_NFC_FELICA
  1450. g_cen_sts = read_buff;
  1451. #endif
  1452. FELICA_PR_INFO(" %s g_cen_sts=[%d]", __func__, g_cen_sts);
  1453. ret = copy_to_user(buf, &read_buff, FELICA_CEN_DATA_LEN);
  1454. if (ret != 0) {
  1455. FELICA_PR_ERR(" %s ERROR(copy_to_user), ret=[%d]",
  1456. __func__, ret);
  1457. return -EFAULT;
  1458. }
  1459. *ppos += 1;
  1460. return FELICA_CEN_DATA_LEN;
  1461. }
  1462. /*
  1463. * write operation
  1464. */
  1465. static ssize_t felica_cen_write(struct file *file, const char __user *data,
  1466. size_t len, loff_t *ppos)
  1467. {
  1468. char cen;
  1469. int ret;
  1470. unsigned char write_buff[2];
  1471. if (felica_i2c_client == NULL) {
  1472. FELICA_PR_ERR(" felica_i2c_client is NULL %s",__func__);
  1473. return -EIO;
  1474. }
  1475. gwrite_msgs[0].buf = &write_buff[0];
  1476. gwrite_msgs[0].addr = gi2c_address;
  1477. write_buff[0] = gi2c_lockaddress;
  1478. ret = copy_from_user(&cen, data, FELICA_CEN_DATA_LEN);
  1479. if (ret != 0) {
  1480. FELICA_PR_ERR(" %s ERROR(copy_from_user), ret=[%d]",
  1481. __func__, ret);
  1482. return -EFAULT;
  1483. }
  1484. if (cen == FELICA_CEN_UNLOCK) {
  1485. write_buff[1] = FELICA_CEN_SET_UNLOCK;
  1486. FELICA_PR_INFO(" Set FeliCa-Lock status to [%d][UnLock]",
  1487. write_buff[1]);
  1488. } else if (cen == FELICA_CEN_LOCK) {
  1489. write_buff[1] = FELICA_CEN_SET_LOCK;
  1490. FELICA_PR_INFO(" Set FeliCa-Lock status to [%d][Lock]",
  1491. write_buff[1]);
  1492. } else {
  1493. FELICA_PR_ERR(" %s ERROR(copy_from_user), cen=[%d]",
  1494. __func__, cen);
  1495. return -EINVAL;
  1496. }
  1497. ret = i2c_transfer(felica_i2c_client->adapter, gwrite_msgs, 1);
  1498. if (ret < 0) {
  1499. FELICA_PR_ERR(" %s ERROR(i2c_transfer), ret=[%d]",
  1500. __func__, ret);
  1501. return -EIO;
  1502. }
  1503. #ifdef CONFIG_NFC_FELICA
  1504. g_cen_sts = cen;
  1505. if (1 == available_d->available_flag) {
  1506. if (0 != g_cen_sts) {
  1507. if (GPIO_VALUE_LOW != g_rfs_sts) {
  1508. if (0 == guartcc_felica_status) {
  1509. available_d->rsp_done = 1;
  1510. FELICA_PR_INFO(" wake up available");
  1511. wake_up_interruptible(
  1512. &available_d->read_wait);
  1513. }
  1514. }
  1515. }
  1516. }
  1517. #endif
  1518. FELICA_PR_INFO(" %s END, g_cen_sts =%d, g_rfs_sts = %d", __func__, g_cen_sts, g_rfs_sts);
  1519. return FELICA_CEN_DATA_LEN;
  1520. }
  1521. /******************************************************************************
  1522. * /dev/felica_rfs
  1523. ******************************************************************************/
  1524. /* character device definition */
  1525. static dev_t devid_felica_rfs;
  1526. static struct cdev cdev_felica_rfs;
  1527. static const struct file_operations fops_felica_rfs = {
  1528. .owner = THIS_MODULE,
  1529. .open = felica_rfs_open,
  1530. .release = felica_rfs_close,
  1531. .read = felica_rfs_read,
  1532. };
  1533. /*
  1534. * initialize device
  1535. */
  1536. static void felica_rfs_init(void)
  1537. {
  1538. int ret;
  1539. struct device *device_felica_rfs;
  1540. FELICA_PR_DBG(" %s START", __func__);
  1541. devid_felica_rfs = MKDEV(FELICA_MAJOR, FELICA_MINOR);
  1542. ret =
  1543. alloc_chrdev_region(&devid_felica_rfs, FELICA_BASEMINOR,
  1544. FELICA_MINOR_COUNT, FELICA_RFS_NAME);
  1545. if (ret < 0) {
  1546. FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
  1547. __func__, ret);
  1548. return;
  1549. }
  1550. cdev_init(&cdev_felica_rfs, &fops_felica_rfs);
  1551. ret = cdev_add(&cdev_felica_rfs, devid_felica_rfs, FELICA_MINOR_COUNT);
  1552. if (ret < 0) {
  1553. unregister_chrdev_region(devid_felica_rfs, FELICA_MINOR_COUNT);
  1554. FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
  1555. ret);
  1556. return;
  1557. }
  1558. device_felica_rfs =
  1559. device_create(felica_class, NULL, devid_felica_rfs, NULL,
  1560. FELICA_RFS_NAME);
  1561. if (IS_ERR(device_felica_rfs)) {
  1562. cdev_del(&cdev_felica_rfs);
  1563. unregister_chrdev_region(devid_felica_rfs, FELICA_MINOR_COUNT);
  1564. FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
  1565. return;
  1566. }
  1567. FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
  1568. MAJOR(devid_felica_rfs), MINOR(devid_felica_rfs));
  1569. }
  1570. /*
  1571. * finalize device
  1572. */
  1573. static void felica_rfs_exit(void)
  1574. {
  1575. FELICA_PR_DBG(" %s START", __func__);
  1576. device_destroy(felica_class, devid_felica_rfs);
  1577. cdev_del(&cdev_felica_rfs);
  1578. unregister_chrdev_region(devid_felica_rfs, FELICA_MINOR_COUNT);
  1579. FELICA_PR_DBG(" %s START", __func__);
  1580. }
  1581. /*
  1582. * open device
  1583. */
  1584. static int felica_rfs_open(struct inode *inode, struct file *file)
  1585. {
  1586. uid_t uid;
  1587. uid = __task_cred(current)->uid;
  1588. if ((uid != gmfc_uid) && (uid != gdiag_uid)) {
  1589. FELICA_PR_ERR
  1590. (" %s -EACCESS, uid=[%d], gmfc_uid=[%d], gdiag_uid=[%d]",
  1591. __func__, uid, gmfc_uid, gdiag_uid);
  1592. #ifdef SRIB_DIAG_ENABLED
  1593. FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
  1594. #else
  1595. return -EACCES;
  1596. #endif
  1597. }
  1598. FELICA_PR_DBG(" %s END, uid=[%d], gmfc_uid=[%d], gdiag_uid=[%d]", __func__, uid, gmfc_uid, gdiag_uid);
  1599. return 0;
  1600. }
  1601. /*
  1602. * close device
  1603. */
  1604. static int felica_rfs_close(struct inode *inode, struct file *file)
  1605. {
  1606. /* no operation */
  1607. FELICA_PR_DBG(" %s END", __func__);
  1608. return 0;
  1609. }
  1610. /*
  1611. * read operation
  1612. */
  1613. static ssize_t felica_rfs_read(struct file *file, char __user *buf, \
  1614. size_t len, loff_t *ppos)
  1615. {
  1616. int ret;
  1617. char retparam;
  1618. FELICA_PR_DBG(" %s START", __func__);
  1619. ret = gpio_get_value(GPIO_PINID_FELICA_RFS);
  1620. if (ret == GPIO_VALUE_HIGH) {
  1621. retparam = FELICA_RFS_STANDBY;
  1622. FELICA_PR_INFO(" Carrier-Wave Status is [%d][standby]",
  1623. retparam);
  1624. } else if (ret == GPIO_VALUE_LOW) {
  1625. retparam = FELICA_RFS_DETECTED;
  1626. FELICA_PR_INFO(" Carrier-Wave Status is [%d][detected]",
  1627. retparam);
  1628. } else {
  1629. FELICA_PR_ERR(" %s ERROR(gpio_get_value), ret=[%d]",
  1630. __func__, ret);
  1631. return -EIO;
  1632. }
  1633. ret = copy_to_user(buf, &retparam, FELICA_RFS_DATA_LEN);
  1634. if (ret != 0) {
  1635. FELICA_PR_ERR(" %s ERROR(copy_to_user), ret=[%d]",
  1636. __func__, ret);
  1637. return -EFAULT;
  1638. }
  1639. *ppos += 1;
  1640. FELICA_PR_DBG(" %s END", __func__);
  1641. return FELICA_RFS_DATA_LEN;
  1642. }
  1643. /******************************************************************************
  1644. * /dev/felica_rws
  1645. ******************************************************************************/
  1646. /* character device definition */
  1647. static dev_t devid_felica_rws;
  1648. static struct cdev cdev_felica_rws;
  1649. static const struct file_operations fops_felica_rws = {
  1650. .owner = THIS_MODULE,
  1651. .open = felica_rws_open,
  1652. .release = felica_rws_close,
  1653. .read = felica_rws_read,
  1654. .write = felica_rws_write,
  1655. };
  1656. /*
  1657. * initialize device
  1658. */
  1659. static void felica_rws_init(void)
  1660. {
  1661. int ret;
  1662. struct device *device_felica_rws;
  1663. FELICA_PR_DBG(" %s START", __func__);
  1664. devid_felica_rws = MKDEV(FELICA_MAJOR, FELICA_MINOR);
  1665. ret =
  1666. alloc_chrdev_region(&devid_felica_rws, FELICA_BASEMINOR,
  1667. FELICA_MINOR_COUNT, FELICA_RWS_NAME);
  1668. if (ret < 0) {
  1669. FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
  1670. __func__, ret);
  1671. return;
  1672. }
  1673. cdev_init(&cdev_felica_rws, &fops_felica_rws);
  1674. ret = cdev_add(&cdev_felica_rws, devid_felica_rws, FELICA_MINOR_COUNT);
  1675. if (ret < 0) {
  1676. unregister_chrdev_region(devid_felica_rws, FELICA_MINOR_COUNT);
  1677. FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
  1678. ret);
  1679. return;
  1680. }
  1681. device_felica_rws =
  1682. device_create(felica_class, NULL, devid_felica_rws, NULL,
  1683. FELICA_RWS_NAME);
  1684. if (IS_ERR(device_felica_rws)) {
  1685. cdev_del(&cdev_felica_rws);
  1686. unregister_chrdev_region(devid_felica_rws, FELICA_MINOR_COUNT);
  1687. FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
  1688. return;
  1689. }
  1690. gfelica_rw_status = FELICA_RW_STATUS_INIT;
  1691. FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
  1692. MAJOR(devid_felica_rws), MINOR(devid_felica_rws));
  1693. }
  1694. /*
  1695. * finalize device
  1696. */
  1697. static void felica_rws_exit(void)
  1698. {
  1699. FELICA_PR_DBG(" %s START", __func__);
  1700. device_destroy(felica_class, devid_felica_rws);
  1701. cdev_del(&cdev_felica_rws);
  1702. unregister_chrdev_region(devid_felica_rws, FELICA_MINOR_COUNT);
  1703. }
  1704. /*
  1705. * open device
  1706. */
  1707. static int felica_rws_open(struct inode *inode, struct file *file)
  1708. {
  1709. uid_t uid;
  1710. FELICA_PR_DBG(" %s START", __func__);
  1711. uid = __task_cred(current)->uid;
  1712. if (file->f_mode & FMODE_WRITE) {
  1713. if (uid != grwm_uid) {
  1714. FELICA_PR_ERR(\
  1715. " %s END -EACCES, uid=[%d],gmfc_uid=[%d],gdiag_uid=[%d]",
  1716. __func__, uid, gmfc_uid, gdiag_uid);
  1717. #ifdef SRIB_DIAG_ENABLED
  1718. FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
  1719. #else
  1720. return -EACCES;
  1721. #endif
  1722. }
  1723. } else {
  1724. if ((uid != gmfc_uid) && (uid != grwm_uid)) {
  1725. FELICA_PR_ERR(\
  1726. " %s END -EACCES, uid=[%d],gmfc_uid=[%d],gdiag_uid=[%d]",
  1727. __func__, uid, gmfc_uid, gdiag_uid);
  1728. #ifdef SRIB_DIAG_ENABLED
  1729. FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
  1730. #else
  1731. return -EACCES;
  1732. #endif
  1733. }
  1734. }
  1735. FELICA_PR_DBG(" %s END", __func__);
  1736. return 0;
  1737. }
  1738. /*
  1739. * close device
  1740. */
  1741. static int felica_rws_close(struct inode *inode, struct file *file)
  1742. {
  1743. /* no operation */
  1744. FELICA_PR_DBG(" %s END", __func__);
  1745. return 0;
  1746. }
  1747. /*
  1748. * read operation
  1749. */
  1750. static ssize_t felica_rws_read(struct file *file, char __user *buf, size_t len,
  1751. loff_t *ppos)
  1752. {
  1753. int ret;
  1754. char retparam;
  1755. if (gfelica_rw_status == FELICA_RW_STATUS_ENABLE) {
  1756. retparam = FELICA_RW_STATUS_ENABLE;
  1757. FELICA_PR_INFO(" ReaderWriterFunction status is [%d][enabled] %s",
  1758. retparam,__func__);
  1759. } else if (gfelica_rw_status == FELICA_RW_STATUS_DISABLE) {
  1760. retparam = FELICA_RW_STATUS_DISABLE;
  1761. FELICA_PR_INFO
  1762. (" ReaderWriterFunction status is [%d][disabled] %s", retparam,__func__);
  1763. } else {
  1764. FELICA_PR_ERR(" %s ERROR(gfelica_rw_status), RWM=[%d]",
  1765. __func__, gfelica_rw_status);
  1766. return -EIO;
  1767. }
  1768. ret = copy_to_user(buf, &retparam, FELICA_RWS_DATA_LEN);
  1769. if (ret != 0) {
  1770. FELICA_PR_ERR(" %s ERROR(copy_to_user), ret=[%d]",
  1771. __func__, ret);
  1772. return -EFAULT;
  1773. }
  1774. *ppos += 1;
  1775. return FELICA_RWS_DATA_LEN;
  1776. }
  1777. /*
  1778. * write operation
  1779. */
  1780. static ssize_t felica_rws_write(struct file *file, const char __user *data,
  1781. size_t len, loff_t *ppos)
  1782. {
  1783. char work;
  1784. int ret;
  1785. FELICA_PR_DBG(" %s START", __func__);
  1786. ret = copy_from_user(&work, data, FELICA_RWS_DATA_LEN);
  1787. if (ret != 0) {
  1788. FELICA_PR_ERR(" %s ERROR(copy_from_user), ret=[%d]",
  1789. __func__, ret);
  1790. return -EFAULT;
  1791. }
  1792. if (work == FELICA_RW_STATUS_ENABLE) {
  1793. FELICA_PR_INFO
  1794. ("Set ReaderWriterFunction status to [%d][enable]", work);
  1795. } else if (work == FELICA_RW_STATUS_DISABLE) {
  1796. FELICA_PR_INFO
  1797. ("Set ReaderWriterFunction status to s[%d][disable]", work);
  1798. } else {
  1799. FELICA_PR_ERR(" %s ERROR(copy_from_user), work=[%d]",
  1800. __func__, work);
  1801. return -EINVAL;
  1802. }
  1803. gfelica_rw_status = work;
  1804. FELICA_PR_DBG(" %s END", __func__);
  1805. return FELICA_RWS_DATA_LEN;
  1806. }
  1807. /******************************************************************************
  1808. * /dev/felica_int_poll
  1809. ******************************************************************************/
  1810. /* character device definition */
  1811. static dev_t devid_felica_int_poll;
  1812. static struct cdev cdev_felica_int_poll;
  1813. static const struct file_operations fops_felica_int_poll = {
  1814. .owner = THIS_MODULE,
  1815. .open = felica_int_poll_open,
  1816. .release = felica_int_poll_close,
  1817. .read = felica_int_poll_read,
  1818. .poll = felica_int_poll_poll,
  1819. };
  1820. /*
  1821. * top half of irq_handler
  1822. */
  1823. static irqreturn_t felica_int_irq_handler(int irq, void *dev_id)
  1824. {
  1825. FELICA_PR_DBG(" %s START", __func__);
  1826. #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  1827. #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
  1828. disable_irq_nosync(gpio_to_irq(GPIO_PINID_FELICA_INT));
  1829. #else
  1830. disable_irq_nosync(gpio_to_irq(gfelica_irq_int_pin));
  1831. #endif
  1832. #else
  1833. disable_irq_nosync(gpio_to_irq(GPIO_PINID_FELICA_INT_REV03));
  1834. #endif /* CONFIG_ARCH_MSM8974 */
  1835. schedule_delayed_work(&pgint_irq->work,
  1836. msecs_to_jiffies(FELICA_INT_DELAY_TIME));
  1837. FELICA_PR_DBG(" %s END", __func__);
  1838. return IRQ_HANDLED;
  1839. }
  1840. /*
  1841. * bottom half of irq_handler
  1842. */
  1843. static void felica_int_irq_work(struct work_struct *work)
  1844. {
  1845. FELICA_PR_DBG(" %s START", __func__);
  1846. #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  1847. #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
  1848. enable_irq(gpio_to_irq(GPIO_PINID_FELICA_INT));
  1849. #else
  1850. enable_irq(gpio_to_irq(gfelica_irq_int_pin));
  1851. #endif // CONFIG_MACH_KLTE
  1852. #else
  1853. enable_irq(gpio_to_irq(GPIO_PINID_FELICA_INT_REV03));
  1854. #endif /* CONFIG_ARCH_MSM8974 */
  1855. pgint_irq->irq_done = 1;
  1856. #ifdef F_WAKE_LOCK
  1857. wake_lock_timeout(&felica_wake_1, msecs_to_jiffies(tmout_1));
  1858. FELICA_PR_INFO(" %s Wake Lock(1)[%d]", __func__, tmout_1);
  1859. #endif
  1860. wake_up_interruptible(&pgint_irq->read_wait);
  1861. FELICA_PR_DBG(" %s END", __func__);
  1862. }
  1863. /*
  1864. * initialize device
  1865. */
  1866. static void felica_int_poll_init(void)
  1867. {
  1868. int ret;
  1869. struct device *device_felica_int_poll;
  1870. #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  1871. #if !defined(CONFIG_MACH_KLTE_KDI) && !defined(CONFIG_MACH_KLTE_DCM) && !defined(CONFIG_MACH_KLTE_SBM)
  1872. struct device *dev = &felica_gpio_pdev->dev;
  1873. struct device_node *np;
  1874. #endif // CONFIG_MACH_KLTE
  1875. #endif
  1876. FELICA_PR_DBG(" %s START", __func__);
  1877. devid_felica_int_poll = MKDEV(FELICA_MAJOR, FELICA_MINOR);
  1878. ret =
  1879. alloc_chrdev_region(&devid_felica_int_poll, FELICA_BASEMINOR,
  1880. FELICA_MINOR_COUNT, FELICA_INT_POLL_NAME);
  1881. if (ret < 0) {
  1882. FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
  1883. __func__, ret);
  1884. return;
  1885. }
  1886. cdev_init(&cdev_felica_int_poll, &fops_felica_int_poll);
  1887. ret =
  1888. cdev_add(&cdev_felica_int_poll, devid_felica_int_poll,
  1889. FELICA_MINOR_COUNT);
  1890. if (ret < 0) {
  1891. unregister_chrdev_region(devid_felica_int_poll,
  1892. FELICA_MINOR_COUNT);
  1893. FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
  1894. ret);
  1895. return;
  1896. }
  1897. device_felica_int_poll =
  1898. device_create(felica_class, NULL, devid_felica_int_poll, NULL,
  1899. FELICA_INT_POLL_NAME);
  1900. if (IS_ERR(device_felica_int_poll)) {
  1901. cdev_del(&cdev_felica_int_poll);
  1902. unregister_chrdev_region(devid_felica_int_poll,
  1903. FELICA_MINOR_COUNT);
  1904. FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
  1905. return;
  1906. }
  1907. memset(pgint_irq, 0x00, sizeof(struct felica_int_irqdata));
  1908. INIT_DELAYED_WORK(&pgint_irq->work, felica_int_irq_work);
  1909. init_waitqueue_head(&pgint_irq->read_wait);
  1910. #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  1911. #if !defined(CONFIG_MACH_KLTE_KDI) && !defined(CONFIG_MACH_KLTE_DCM) && !defined(CONFIG_MACH_KLTE_SBM)
  1912. if (!dev) {
  1913. FELICA_PR_ERR(" %s ERROR NULL", __func__);
  1914. return;
  1915. }
  1916. np = dev->of_node;
  1917. gfelica_irq_int_pin = of_get_named_gpio(np, "felica,irq-gpio", 0);
  1918. FELICA_PR_INFO(" %s gfelica_irq_int_pin [%d]",
  1919. __func__, gfelica_irq_int_pin);
  1920. #endif // CONFIG_MACH_KLTE
  1921. #if defined(CONFIG_MACH_HLTEKDI)
  1922. gfelica_sps_pin = of_get_named_gpio(np, "felica,sps-gpio", 0);
  1923. if(gfelica_sps_pin < 0)
  1924. {
  1925. FELICA_PR_ERR(" %s ERROR(), ret=[%d]",__func__, gfelica_sps_pin);
  1926. return;
  1927. }
  1928. FELICA_PR_INFO(" %s gfelica_sps_pin [%d]",
  1929. __func__, gfelica_sps_pin);
  1930. ret = gpio_get_value(gfelica_sps_pin);
  1931. FELICA_PR_INFO(" %s gfelica_sps_pin [%d]",
  1932. __func__, ret);
  1933. #endif
  1934. #if defined(CONFIG_MACH_HLTEDCM) || defined(CONFIG_MACH_JS01LTEDCM)
  1935. if (system_rev >= g_uicc_initrev) {
  1936. gpio_tlmm_config(GPIO_CFG(gfelica_sps_pin, GPIOMUX_FUNC_GPIO,
  1937. GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
  1938. GPIO_CFG_ENABLE);
  1939. FELICA_PR_INFO(" %s gfelica_sps_pin dcm [%d]",
  1940. __func__, gfelica_sps_pin);
  1941. FELICA_PR_INFO(" %s gfelica_sps_pin dcm [%d]",
  1942. __func__, gpio_get_value(gfelica_sps_pin));
  1943. }
  1944. #endif
  1945. #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
  1946. ret = request_threaded_irq(
  1947. gpio_to_irq(GPIO_PINID_FELICA_INT),
  1948. NULL,
  1949. felica_int_irq_handler,
  1950. IRQF_TRIGGER_FALLING,
  1951. FELICA_INT_POLL_NAME,
  1952. (void *)pgint_irq);
  1953. FELICA_PR_INFO(" %s INFO(request_irq)= %d GPIO=%d, ret=[%d]",
  1954. __func__, gpio_to_irq(GPIO_PINID_FELICA_INT),GPIO_PINID_FELICA_INT,ret);
  1955. #else
  1956. ret = request_threaded_irq(
  1957. gpio_to_irq(gfelica_irq_int_pin),
  1958. NULL,
  1959. felica_int_irq_handler,
  1960. IRQF_TRIGGER_FALLING,
  1961. FELICA_INT_POLL_NAME,
  1962. (void *)pgint_irq);
  1963. #endif // CONFIG_MACH_KLTE
  1964. #else
  1965. ret = request_irq(gpio_to_irq(GPIO_PINID_FELICA_INT_REV03),
  1966. felica_int_irq_handler,
  1967. IRQF_TRIGGER_FALLING,
  1968. FELICA_INT_POLL_NAME, (void *)pgint_irq);
  1969. #endif /* CONFIG_ARCH_MSM8974 */
  1970. if (ret != 0) {
  1971. device_destroy(felica_class, devid_felica_int_poll);
  1972. cdev_del(&cdev_felica_int_poll);
  1973. unregister_chrdev_region(devid_felica_int_poll,
  1974. FELICA_MINOR_COUNT);
  1975. FELICA_PR_ERR(" %s ERROR(request_irq), ret=[%d]",
  1976. __func__,ret);
  1977. return;
  1978. }
  1979. #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  1980. #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
  1981. ret = enable_irq_wake(gpio_to_irq(GPIO_PINID_FELICA_INT));
  1982. if (ret < 0) {
  1983. free_irq(gpio_to_irq(GPIO_PINID_FELICA_INT), (void *)pgint_irq);
  1984. device_destroy(felica_class, devid_felica_int_poll);
  1985. cdev_del(&cdev_felica_int_poll);
  1986. unregister_chrdev_region(devid_felica_int_poll,
  1987. FELICA_MINOR_COUNT);
  1988. FELICA_PR_ERR(" %s ERROR(enable_irq_wake), ret=[%d]",
  1989. __func__, ret);
  1990. return;
  1991. }
  1992. #else
  1993. ret = enable_irq_wake(gpio_to_irq(gfelica_irq_int_pin));
  1994. if (ret < 0) {
  1995. free_irq(gpio_to_irq(gfelica_irq_int_pin), (void *)pgint_irq);
  1996. device_destroy(felica_class, devid_felica_int_poll);
  1997. cdev_del(&cdev_felica_int_poll);
  1998. unregister_chrdev_region(devid_felica_int_poll,
  1999. FELICA_MINOR_COUNT);
  2000. FELICA_PR_ERR(" %s ERROR(enable_irq_wake), ret=[%d]",
  2001. __func__, ret);
  2002. return;
  2003. }
  2004. #endif // CONFIG_MACH_KLTE
  2005. #else
  2006. ret = enable_irq_wake(gpio_to_irq(GPIO_PINID_FELICA_INT_REV03));
  2007. if (ret < 0) {
  2008. free_irq(gpio_to_irq(
  2009. GPIO_PINID_FELICA_INT_REV03),
  2010. (void *)pgint_irq);
  2011. device_destroy(felica_class, devid_felica_int_poll);
  2012. cdev_del(&cdev_felica_int_poll);
  2013. unregister_chrdev_region(devid_felica_int_poll,
  2014. FELICA_MINOR_COUNT);
  2015. FELICA_PR_ERR(" %s ERROR(enable_irq_wake), ret=[%d]",
  2016. __func__, ret);
  2017. return;
  2018. }
  2019. #endif /* CONFIG_ARCH_MSM8974 */
  2020. pgint_irq->irq_done = 0;
  2021. FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__, \
  2022. MAJOR(devid_felica_int_poll),
  2023. MINOR(devid_felica_int_poll));
  2024. }
  2025. /*
  2026. * finalize device
  2027. */
  2028. static void felica_int_poll_exit(void)
  2029. {
  2030. FELICA_PR_DBG(" %s START", __func__);
  2031. #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  2032. #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
  2033. disable_irq(gpio_to_irq(GPIO_PINID_FELICA_INT));
  2034. free_irq(gpio_to_irq(
  2035. GPIO_PINID_FELICA_INT),
  2036. (void *)pgint_irq);
  2037. #else
  2038. disable_irq(gpio_to_irq(gfelica_irq_int_pin));
  2039. free_irq(gpio_to_irq(
  2040. gfelica_irq_int_pin),
  2041. (void *)pgint_irq);
  2042. #endif // CONFIG_MACH_KLTE
  2043. #else
  2044. disable_irq(gpio_to_irq(GPIO_PINID_FELICA_INT_REV03));
  2045. free_irq(gpio_to_irq(
  2046. GPIO_PINID_FELICA_INT_REV03),
  2047. (void *)pgint_irq);
  2048. #endif
  2049. device_destroy(felica_class, devid_felica_int_poll);
  2050. cdev_del(&cdev_felica_int_poll);
  2051. unregister_chrdev_region(
  2052. devid_felica_int_poll,
  2053. FELICA_MINOR_COUNT);
  2054. FELICA_PR_DBG(" %s END", __func__);
  2055. }
  2056. /*
  2057. * open device
  2058. */
  2059. static int felica_int_poll_open(struct inode *inode, struct file *file)
  2060. {
  2061. /* no operation */
  2062. FELICA_PR_DBG(" %s END", __func__);
  2063. return 0;
  2064. }
  2065. /*
  2066. * close device
  2067. */
  2068. static int felica_int_poll_close(struct inode *inode, struct file *file)
  2069. {
  2070. /* no operation */
  2071. FELICA_PR_DBG(" %s END", __func__);
  2072. return 0;
  2073. }
  2074. /*
  2075. * read operation
  2076. */
  2077. static ssize_t felica_int_poll_read(struct file *file, char __user *buf,
  2078. size_t len, loff_t *ppos)
  2079. {
  2080. int ret;
  2081. char retparam;
  2082. FELICA_PR_DBG(" %s START", __func__);
  2083. if (!pgint_irq->irq_done) {
  2084. ret =
  2085. wait_event_interruptible(pgint_irq->read_wait,
  2086. pgint_irq->irq_done == 1);
  2087. if (ret < 0) {
  2088. FELICA_PR_ERR
  2089. (" %s ERROR(wait_event_interruptible),ret=[%d]",\
  2090. __func__, ret);
  2091. return -EINTR;
  2092. }
  2093. }
  2094. #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  2095. #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
  2096. ret = gpio_get_value(GPIO_PINID_FELICA_INT);
  2097. #else
  2098. ret = gpio_get_value(gfelica_irq_int_pin);
  2099. #endif // CONFIG_MACH_KLTE
  2100. #else
  2101. ret = gpio_get_value(GPIO_PINID_FELICA_INT_REV03);
  2102. #endif
  2103. if (ret == GPIO_VALUE_HIGH) {
  2104. retparam = FELICA_INT_HIGH;
  2105. FELICA_PR_INFO(" INT-PIN value is [%d][HIGH]", retparam);
  2106. } else if (ret == GPIO_VALUE_LOW) {
  2107. retparam = FELICA_INT_LOW;
  2108. FELICA_PR_INFO(" INT-PIN value is [%d][LOW]", retparam);
  2109. } else {
  2110. FELICA_PR_ERR(" %s ERROR(gpio_get_value), ret=[%d]",
  2111. __func__, ret);
  2112. return -EIO;
  2113. }
  2114. ret = copy_to_user(buf, &retparam, FELICA_INT_DATA_LEN);
  2115. if (ret != 0) {
  2116. FELICA_PR_ERR(" %s ERROR(copy_to_user), ret=[%d]",
  2117. __func__, ret);
  2118. return -EFAULT;
  2119. }
  2120. *ppos += 1;
  2121. pgint_irq->irq_done = 0;
  2122. FELICA_PR_DBG(" %s END", __func__);
  2123. return FELICA_INT_DATA_LEN;
  2124. }
  2125. /*
  2126. * poll operation
  2127. */
  2128. static unsigned int felica_int_poll_poll(struct file *file, poll_table *wait)
  2129. {
  2130. unsigned int mask = 0;
  2131. FELICA_PR_DBG(" %s START", __func__);
  2132. poll_wait(file, &pgint_irq->read_wait, wait);
  2133. if (pgint_irq->irq_done)
  2134. mask = POLLIN | POLLRDNORM;
  2135. FELICA_PR_DBG(" %s END", __func__);
  2136. return mask;
  2137. }
  2138. /******************************************************************************
  2139. * /dev/felica_uid
  2140. ******************************************************************************/
  2141. /* character device definition */
  2142. static dev_t devid_felica_uid;
  2143. static struct cdev cdev_felica_uid;
  2144. static const struct file_operations fops_felica_uid = {
  2145. .owner = THIS_MODULE,
  2146. .open = felica_uid_open,
  2147. .release = felica_uid_close,
  2148. .unlocked_ioctl = felica_uid_ioctl,
  2149. };
  2150. /*
  2151. * initialize device
  2152. */
  2153. static void felica_uid_init(void)
  2154. {
  2155. int ret;
  2156. struct device *device_felica_uid;
  2157. FELICA_PR_DBG(" %s START", __func__);
  2158. devid_felica_uid = MKDEV(FELICA_MAJOR, FELICA_MINOR);
  2159. ret =
  2160. alloc_chrdev_region(&devid_felica_uid, FELICA_BASEMINOR,
  2161. FELICA_MINOR_COUNT, FELICA_UID_NAME);
  2162. if (ret < 0) {
  2163. FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
  2164. __func__, ret);
  2165. return;
  2166. }
  2167. cdev_init(&cdev_felica_uid, &fops_felica_uid);
  2168. ret = cdev_add(&cdev_felica_uid, devid_felica_uid, FELICA_MINOR_COUNT);
  2169. if (ret < 0) {
  2170. unregister_chrdev_region(devid_felica_uid, FELICA_MINOR_COUNT);
  2171. FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
  2172. ret);
  2173. return;
  2174. }
  2175. device_felica_uid =
  2176. device_create(felica_class, NULL, devid_felica_uid, NULL,
  2177. FELICA_UID_NAME);
  2178. if (IS_ERR(device_felica_uid)) {
  2179. cdev_del(&cdev_felica_uid);
  2180. unregister_chrdev_region(devid_felica_uid, FELICA_MINOR_COUNT);
  2181. FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
  2182. return;
  2183. }
  2184. FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
  2185. MAJOR(devid_felica_uid), MINOR(devid_felica_uid));
  2186. }
  2187. /*
  2188. * finalize device
  2189. */
  2190. static void felica_uid_exit(void)
  2191. {
  2192. FELICA_PR_DBG(" %s START", __func__);
  2193. if (gdiag_name[0] != 0x00) {
  2194. device_destroy(felica_class, devid_felica_uid);
  2195. cdev_del(&cdev_felica_uid);
  2196. unregister_chrdev_region(devid_felica_uid, \
  2197. FELICA_MINOR_COUNT);
  2198. }
  2199. }
  2200. /*
  2201. * open device
  2202. */
  2203. static int felica_uid_open(struct inode *inode, struct file *file)
  2204. {
  2205. int ret = 0;
  2206. char *cmdpos;
  2207. static char cmdline[1025];
  2208. static unsigned long start_adr, end_adr, leng;
  2209. FELICA_PR_DBG(" %s START", __func__);
  2210. start_adr = current->mm->arg_start;
  2211. end_adr = current->mm->arg_end;
  2212. leng = end_adr - start_adr;
  2213. if (1024 < leng)
  2214. leng = 1024;
  2215. cmdpos = (char *)(current->mm->arg_start);
  2216. ret = copy_from_user(cmdline, cmdpos, leng);
  2217. cmdline[leng] = '\0';
  2218. if(ret != 0)
  2219. {
  2220. FELICA_PR_ERR(" %s cmdline[%s] ret[%d]", __func__, cmdline, ret);
  2221. return -EFAULT;
  2222. }
  2223. if (strncmp(cmdline, gdiag_name, leng) != 0) {
  2224. FELICA_PR_INFO(" %s ERROR, %s gdiag %s", \
  2225. __func__, cmdline, gdiag_name);
  2226. #ifdef SRIB_DIAG_ENABLED
  2227. FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
  2228. #else
  2229. return -EACCES;
  2230. #endif
  2231. }
  2232. FELICA_PR_DBG(" %s END", __func__);
  2233. return 0;
  2234. }
  2235. /*
  2236. * close device
  2237. */
  2238. static int felica_uid_close(struct inode *inode, struct file *file)
  2239. {
  2240. /* no operation */
  2241. FELICA_PR_DBG(" %s END", __func__);
  2242. return 0;
  2243. }
  2244. /*
  2245. * uid registration
  2246. */
  2247. static long felica_uid_ioctl(struct file *file, unsigned int cmd,
  2248. unsigned long arg)
  2249. {
  2250. FELICA_PR_DBG(" %s START, cmd=[%d]", __func__, cmd);
  2251. switch (cmd) {
  2252. case SET_FELICA_UID_DIAG:
  2253. gdiag_uid = *((int *)arg);
  2254. FELICA_PR_INFO("Set gdiag_uid to [%d]", gdiag_uid);
  2255. break;
  2256. default:
  2257. FELICA_PR_ERR(" %s ERROR(unknown command)", __func__);
  2258. break;
  2259. }
  2260. FELICA_PR_DBG(" %s END", __func__);
  2261. return 0;
  2262. }
  2263. /******************************************************************************
  2264. * /dev/felica_ant
  2265. ******************************************************************************/
  2266. /* character device definition */
  2267. static dev_t devid_felica_ant;
  2268. static struct cdev cdev_felica_ant;
  2269. static const struct file_operations fops_felica_ant = {
  2270. .owner = THIS_MODULE,
  2271. .open = felica_ant_open,
  2272. .release = felica_ant_close,
  2273. .read = felica_ant_read,
  2274. .write = felica_ant_write,
  2275. };
  2276. /*
  2277. * felica_ant_init
  2278. */
  2279. static void felica_ant_init(void)
  2280. {
  2281. int ret;
  2282. struct device *device_felica_ant;
  2283. FELICA_PR_DBG(" %s START", __func__);
  2284. devid_felica_ant = MKDEV(FELICA_MAJOR, FELICA_MINOR);
  2285. ret =
  2286. alloc_chrdev_region(&devid_felica_ant, FELICA_BASEMINOR,
  2287. FELICA_MINOR_COUNT, FELICA_ANT_NAME);
  2288. if (ret < 0) {
  2289. FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
  2290. __func__, ret);
  2291. return;
  2292. }
  2293. cdev_init(&cdev_felica_ant, &fops_felica_ant);
  2294. ret = cdev_add(&cdev_felica_ant, devid_felica_ant, FELICA_MINOR_COUNT);
  2295. if (ret < 0) {
  2296. unregister_chrdev_region(devid_felica_ant, FELICA_MINOR_COUNT);
  2297. FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
  2298. ret);
  2299. return;
  2300. }
  2301. device_felica_ant =
  2302. device_create(felica_class, NULL, devid_felica_ant, NULL,
  2303. FELICA_ANT_NAME);
  2304. if (IS_ERR(device_felica_ant)) {
  2305. cdev_del(&cdev_felica_ant);
  2306. unregister_chrdev_region(devid_felica_ant, FELICA_MINOR_COUNT);
  2307. FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
  2308. return;
  2309. }
  2310. FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
  2311. MAJOR(devid_felica_ant), MINOR(devid_felica_ant));
  2312. }
  2313. /*
  2314. * felica_ant_exit
  2315. */
  2316. static void felica_ant_exit(void)
  2317. {
  2318. FELICA_PR_DBG(" %s START", __func__);
  2319. device_destroy(felica_class, devid_felica_ant);
  2320. cdev_del(&cdev_felica_ant);
  2321. unregister_chrdev_region(devid_felica_ant, FELICA_MINOR_COUNT);
  2322. FELICA_PR_DBG(" %s END", __func__);
  2323. }
  2324. /*
  2325. * open device
  2326. */
  2327. static int felica_ant_open(struct inode *inode, struct file *file)
  2328. {
  2329. uid_t uid;
  2330. FELICA_PR_DBG(" %s START", __func__);
  2331. #if defined(CONFIG_MACH_HLTEDCM)
  2332. //high
  2333. if (system_rev == HW_REV09_OR_10)
  2334. {
  2335. FELICA_PR_INFO(" %s Making MHL_EN HIGH", __func__);
  2336. of_sii8240_hw_poweron(FELICA_CEN_UNLOCK);
  2337. }
  2338. #endif
  2339. uid = __task_cred(current)->uid;
  2340. if ((uid != gant_uid) && (uid != gdiag_uid)) {
  2341. FELICA_PR_ERR(\
  2342. " %s END -EACCES, uid=[%d], gant_uid=[%d]\n", __func__, uid, gant_uid);
  2343. #if defined(CONFIG_MACH_HLTEDCM)
  2344. //low
  2345. if (system_rev == HW_REV09_OR_10)
  2346. {
  2347. FELICA_PR_INFO(" %s Making MHL_EN LOW", __func__);
  2348. // of_sii8240_hw_poweron(FELICA_CEN_LOCK);
  2349. }
  2350. #endif
  2351. #ifdef SRIB_DIAG_ENABLED
  2352. FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
  2353. #else
  2354. return -EACCES;
  2355. #endif
  2356. }
  2357. FELICA_PR_DBG(" %s END", __func__);
  2358. return 0;
  2359. }
  2360. /*
  2361. * close device
  2362. */
  2363. static int felica_ant_close(struct inode *inode, struct file *file)
  2364. {
  2365. /* no operation */
  2366. #if defined(CONFIG_MACH_HLTEDCM)
  2367. //low
  2368. if (system_rev == HW_REV09_OR_10)
  2369. {
  2370. FELICA_PR_INFO(" %s Making MHL_EN LOW", __func__);
  2371. // of_sii8240_hw_poweron(FELICA_CEN_LOCK);
  2372. }
  2373. #endif
  2374. FELICA_PR_DBG(" %s END system_rev=[%d]", __func__,system_rev);
  2375. return 0;
  2376. }
  2377. /*
  2378. * read operation
  2379. */
  2380. static ssize_t felica_ant_read(struct file *file, char __user *buf, \
  2381. size_t len, loff_t *ppos)
  2382. {
  2383. int ret;
  2384. unsigned char address = gi2c_antaddress;
  2385. unsigned char read_buff = 0;
  2386. struct i2c_msg read_msgs[2];
  2387. read_msgs[0].flags = gread_msgs[0].flags;
  2388. read_msgs[0].len = gread_msgs[0].len;
  2389. read_msgs[1].flags = gread_msgs[1].flags;
  2390. read_msgs[1].len = gread_msgs[1].len;
  2391. read_msgs[0].addr = gi2c_address;
  2392. read_msgs[0].buf = &address;
  2393. read_msgs[1].addr = gi2c_address;
  2394. read_msgs[1].buf = &read_buff;
  2395. FELICA_PR_DBG(" %s START", __func__);
  2396. if (felica_i2c_client == NULL) {
  2397. FELICA_PR_ERR(" %s -EIO felica_i2c_client is NULL", \
  2398. __func__);
  2399. return -EIO;
  2400. }
  2401. ret = i2c_transfer(felica_i2c_client->adapter, &read_msgs[0], 1);
  2402. if (ret < 0) {
  2403. FELICA_PR_ERR(" %s ERROR(i2c_transfer[0]), ret=[%d]",
  2404. __func__, ret);
  2405. return -EIO;
  2406. }
  2407. ret = i2c_transfer(felica_i2c_client->adapter, &read_msgs[1], 1);
  2408. if (ret < 0) {
  2409. FELICA_PR_ERR(" %s ERROR(i2c_transfer[1]), ret=[%d]",
  2410. __func__, ret);
  2411. return -EIO;
  2412. }
  2413. FELICA_PR_INFO(" %s read_buff=[%d]", __func__, read_buff);
  2414. ret = copy_to_user(buf, &read_buff, FELICA_ANT_DATA_LEN);
  2415. if (ret != 0) {
  2416. FELICA_PR_ERR(" %s ERROR(copy_to_user), ret=[%d]",
  2417. __func__, ret);
  2418. return -EFAULT;
  2419. }
  2420. *ppos += 1;
  2421. FELICA_PR_DBG(" %s END", __func__);
  2422. return FELICA_ANT_DATA_LEN;
  2423. }
  2424. /*
  2425. * write operation
  2426. */
  2427. static ssize_t felica_ant_write(struct file *file, const char __user *data,
  2428. size_t len, loff_t *ppos)
  2429. {
  2430. char ant;
  2431. int ret;
  2432. unsigned char write_buff[2];
  2433. FELICA_PR_DBG(" %s START", __func__);
  2434. if (felica_i2c_client == NULL) {
  2435. FELICA_PR_ERR(" %s -EIO felica_i2c_client is NULL", \
  2436. __func__);
  2437. return -EIO;
  2438. }
  2439. ret = copy_from_user(&ant, data, FELICA_ANT_DATA_LEN);
  2440. if (ret != 0) {
  2441. FELICA_PR_ERR(" %s ERROR(copy_from_user), ret=[%d]",
  2442. __func__, ret);
  2443. return -EFAULT;
  2444. }
  2445. write_buff[0] = gi2c_antaddress;
  2446. write_buff[1] = ant;
  2447. gwrite_msgs[0].buf = &write_buff[0];
  2448. gwrite_msgs[0].addr = gi2c_address;
  2449. ret = i2c_transfer(felica_i2c_client->adapter, gwrite_msgs, 1);
  2450. if (ret < 0) {
  2451. FELICA_PR_ERR(" %s ERROR(i2c_transfer), ret=[%d]",
  2452. __func__, ret);
  2453. return -EIO;
  2454. }
  2455. FELICA_PR_DBG(" %s END", __func__);
  2456. return FELICA_ANT_DATA_LEN;
  2457. }
  2458. /******************************************************************************
  2459. * Mobile FeliCa device driver initialization / termination function
  2460. ******************************************************************************/
  2461. /*
  2462. * to set initial value to each terminal
  2463. */
  2464. static void felica_initialize_pin(void)
  2465. {
  2466. FELICA_PR_DBG(" %s START", __func__);
  2467. #if defined(CONFIG_ARCH_EXYNOS)
  2468. gpio_set_value(GPIO_PINID_FELICA_PON, GPIO_VALUE_LOW);
  2469. #elif defined(CONFIG_ARCH_APQ8064)
  2470. ice_gpiox_set(GPIO_PINID_FELICA_PON, GPIO_VALUE_LOW);
  2471. #elif defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  2472. #if !defined(CONFIG_MACH_KLTE_KDI) && !defined(CONFIG_MACH_KLTE_DCM) && !defined(CONFIG_MACH_KLTE_SBM) // We are not doing the initialization here. felica_register_device() does it and sets up the initial pin value to LOW.
  2473. gpio_set_value(GPIO_PINID_FELICA_PON, GPIO_VALUE_LOW);
  2474. #endif
  2475. #endif
  2476. FELICA_PR_DBG(" %s END", __func__);
  2477. }
  2478. /*
  2479. * to set final value to each terminal
  2480. */
  2481. static void felica_finalize_pin(void)
  2482. {
  2483. FELICA_PR_DBG(" %s START", __func__);
  2484. #if defined(CONFIG_ARCH_EXYNOS)
  2485. gpio_set_value(GPIO_PINID_FELICA_PON, GPIO_VALUE_LOW);
  2486. #elif defined(CONFIG_ARCH_APQ8064)
  2487. ice_gpiox_set(GPIO_PINID_FELICA_PON, GPIO_VALUE_LOW);
  2488. #elif defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  2489. #if !defined (CONFIG_MACH_KLTE_KDI) && !defined (CONFIG_MACH_KLTE_DCM) && !defined(CONFIG_MACH_KLTE_SBM) // We are not doing the initialization here. felica_register_device() does it and sets up the initial pin value to LOW.
  2490. gpio_set_value(GPIO_PINID_FELICA_PON, GPIO_VALUE_LOW);
  2491. #endif
  2492. #endif
  2493. FELICA_PR_DBG(" %s END", __func__);
  2494. }
  2495. /*
  2496. * device driver registration
  2497. */
  2498. static void felica_register_device(void)
  2499. {
  2500. #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
  2501. struct device *dev = &felica_gpio_pdev->dev;
  2502. struct device_node *np;
  2503. #endif
  2504. FELICA_PR_DBG(" %s START", __func__);
  2505. #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
  2506. if (!dev)
  2507. {
  2508. FELICA_PR_ERR(" %s ERROR NULL", __func__);
  2509. return;
  2510. }
  2511. np = dev->of_node;
  2512. if(system_rev <=8)
  2513. {
  2514. gfelica_pon_pin = of_get_named_gpio(np, "felica,pon-gpio", 0);
  2515. if(gfelica_pon_pin < 0)
  2516. {
  2517. FELICA_PR_ERR(" %s ERROR(), gfelica_pon_pin=[%d]",__func__, gfelica_pon_pin);
  2518. return;
  2519. }
  2520. gpio_tlmm_config(GPIO_CFG(gfelica_pon_pin, GPIOMUX_FUNC_GPIO,
  2521. GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
  2522. GPIO_CFG_ENABLE);
  2523. FELICA_PR_INFO(" %s gfelica_pon_pin [%d]",__func__, gpio_get_value(gfelica_pon_pin));
  2524. }
  2525. gpio_set_value(gfelica_pon_pin, GPIO_VALUE_LOW);
  2526. gfelica_hsel_pin = of_get_named_gpio (np, "felica,hsel-gpio", 0);
  2527. if(gfelica_hsel_pin < 0)
  2528. {
  2529. FELICA_PR_ERR(" %s ERROR(), ret=[%d]",__func__, gfelica_hsel_pin);
  2530. return;
  2531. }
  2532. FELICA_PR_INFO(" %s gfelica_hsel_pin [%d]",__func__, gfelica_hsel_pin);
  2533. if (system_rev >= g_uicc_initrev)
  2534. {
  2535. gpio_tlmm_config(GPIO_CFG(gfelica_hsel_pin, GPIOMUX_FUNC_GPIO,
  2536. GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
  2537. GPIO_CFG_ENABLE);
  2538. FELICA_PR_INFO(" %s gfelica_hsel_pin [%d]",__func__, gpio_get_value(gfelica_hsel_pin));
  2539. }
  2540. gpio_set_value(gfelica_hsel_pin, GPIO_VALUE_LOW);
  2541. #if defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
  2542. gfelica_sps_pin = of_get_named_gpio(np, "felica,sps-gpio", 0);
  2543. if(gfelica_sps_pin < 0)
  2544. {
  2545. FELICA_PR_ERR(" %s ERROR(), ret=[%d]",__func__, gfelica_sps_pin);
  2546. return;
  2547. }
  2548. FELICA_PR_INFO(" %s gfelica_sps_pin [%d]",__func__, gfelica_sps_pin);
  2549. if (system_rev >= g_uicc_initrev)
  2550. {
  2551. gpio_tlmm_config(GPIO_CFG(gfelica_sps_pin, GPIOMUX_FUNC_GPIO,
  2552. GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
  2553. GPIO_CFG_ENABLE);
  2554. FELICA_PR_INFO(" %s gfelica_sps_pin [%d]",__func__, gpio_get_value(gfelica_sps_pin));
  2555. }
  2556. #endif
  2557. #else
  2558. felica_int_poll_init();
  2559. #endif //CONFIG_MACH_KLTE
  2560. FELICA_PR_DBG(" %s END", __func__);
  2561. }
  2562. /*
  2563. * device driver deregistration
  2564. */
  2565. static void felica_deregister_device(void)
  2566. {
  2567. FELICA_PR_DBG(" %s START", __func__);
  2568. felica_uid_exit();
  2569. #if !defined(CONFIG_ARCH_MSM8974) && !defined(CONFIG_ARCH_MSM8974PRO)
  2570. felica_int_poll_exit();
  2571. #endif
  2572. felica_ant_exit();
  2573. felica_rws_exit();
  2574. felica_rfs_exit();
  2575. felica_cen_exit();
  2576. felica_pon_exit();
  2577. felica_uart_exit();
  2578. FELICA_PR_DBG(" %s END", __func__);
  2579. }
  2580. #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  2581. static struct of_device_id felica_of_match[] =
  2582. {
  2583. { .compatible = "felica,gpio-table",
  2584. },
  2585. {}
  2586. };
  2587. static int __devexit felica_gpio_remove(struct platform_device *pdev)
  2588. {
  2589. felica_int_poll_exit();
  2590. return 0;
  2591. }
  2592. static struct platform_driver felica_of_driver =
  2593. {
  2594. .remove = __devexit_p(felica_gpio_remove),
  2595. .driver =
  2596. {
  2597. .name = FELICA_GPIO_DRIVER_NAME,
  2598. .owner = THIS_MODULE,
  2599. .of_match_table = felica_of_match,
  2600. },
  2601. };
  2602. static int __init felica_gpio_probe(struct platform_device *pdev)
  2603. {
  2604. felica_gpio_pdev = pdev;
  2605. if (felica_gpio_pdev == NULL) {
  2606. FELICA_PR_ERR(" %s -EIO felica_gpio_pdev is NULL", \
  2607. __func__);
  2608. return -EIO;
  2609. }
  2610. felica_register_device();
  2611. schedule_delayed_work(&pgint_irq->work, msecs_to_jiffies(10));
  2612. return 0;
  2613. }
  2614. #endif
  2615. /*
  2616. * The entry point for initialization module
  2617. */
  2618. static int __init felica_init(void)
  2619. {
  2620. FELICA_PR_DBG(" %s START", __func__);
  2621. #ifdef F_WAKE_LOCK
  2622. wake_lock_init(&felica_wake_1, WAKE_LOCK_SUSPEND, "felica-int-1");
  2623. wake_lock_init(&felica_wake_2, WAKE_LOCK_SUSPEND, "felica-int-2");
  2624. #endif
  2625. felica_class = class_create(THIS_MODULE, "felica");
  2626. if (IS_ERR(felica_class)) {
  2627. FELICA_PR_ERR(" %s ERROR(class_create)", __func__);
  2628. return PTR_ERR(felica_class);
  2629. }
  2630. felica_initialize_pin();
  2631. #if !defined(CONFIG_ARCH_MSM8974) && !defined(CONFIG_ARCH_MSM8974PRO)
  2632. felica_register_device();
  2633. #endif
  2634. felica_nl_init();
  2635. felica_i2c_init();
  2636. uicc_init();
  2637. /* MFC UID registration */
  2638. #if !defined(CONFIG_ARCH_MSM8974) && !defined(CONFIG_ARCH_MSM8974PRO)
  2639. schedule_delayed_work(&pgint_irq->work, msecs_to_jiffies(10));
  2640. #endif
  2641. #ifdef CONFIG_NFC_FELICA
  2642. /* FELICA_INTU GPIO is changed Start*/
  2643. #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  2644. felica_varying_gpio_intu = GPIO_PINID_NFC_INTU;
  2645. #else
  2646. if (system_rev > 0 && system_rev < 15)
  2647. felica_varying_gpio_intu = GPIO_PINID_NFC_INTU_REV03;
  2648. else
  2649. felica_varying_gpio_intu = GPIO_PINID_NFC_INTU_REV06;
  2650. #endif
  2651. FELICA_PR_INFO(" %s , system_rev=[%d]", __func__, system_rev);
  2652. /* FELICA_INTU GPIO is changed End */
  2653. #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
  2654. felica_int_poll_init();
  2655. #endif // CONFIG_MACH_KLTE
  2656. snfc_register_device();
  2657. uartcc_init();
  2658. #endif /* CONFIG_NFC_FELICA */
  2659. FELICA_PR_DBG(" %s END", __func__);
  2660. #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  2661. return platform_driver_probe(&felica_of_driver, felica_gpio_probe);
  2662. #else
  2663. return 0;
  2664. #endif
  2665. }
  2666. /*
  2667. * The entry point for the termination module
  2668. */
  2669. static void __exit felica_exit(void)
  2670. {
  2671. FELICA_PR_DBG(" %s START", __func__);
  2672. #ifdef F_WAKE_LOCK
  2673. wake_lock_destroy(&felica_wake_1);
  2674. wake_lock_destroy(&felica_wake_2);
  2675. #endif
  2676. uicc_exit();
  2677. felica_i2c_exit();
  2678. felica_nl_exit();
  2679. felica_deregister_device();
  2680. #ifdef CONFIG_NFC_FELICA
  2681. snfc_deregister_device();
  2682. snfc_uart_exit();
  2683. uartcc_exit();
  2684. snfc_cen_exit();
  2685. #endif /* CONFIG_NFC_FELICA */
  2686. felica_finalize_pin();
  2687. class_destroy(felica_class);
  2688. FELICA_PR_DBG(" %s END", __func__);
  2689. }
  2690. /******************************************************************************
  2691. *
  2692. *
  2693. *
  2694. *
  2695. * Add driver code for CXD2235AGG NFC/Felica combo IC
  2696. *
  2697. *
  2698. *
  2699. *
  2700. ******************************************************************************/
  2701. #ifdef CONFIG_NFC_FELICA
  2702. /******************************************************************************
  2703. * /dev/snfc_hsel
  2704. ******************************************************************************/
  2705. /* character device definition */
  2706. static dev_t devid_snfc_hsel;
  2707. static struct cdev hsel_cdev;
  2708. static const struct file_operations hsel_fileops = {
  2709. .owner = THIS_MODULE,
  2710. .read = hsel_read,
  2711. .write = hsel_write,
  2712. .open = hsel_open,
  2713. .release = hsel_release,
  2714. };
  2715. /* function prototype */
  2716. static int hsel_init(void)
  2717. {
  2718. int ret = 0;
  2719. struct device *class_dev;
  2720. devid_snfc_hsel = MKDEV(MISC_MAJOR, 0);
  2721. FELICA_PR_DBG(" %s START", __func__);
  2722. ret = alloc_chrdev_region(&devid_snfc_hsel, 0, HSEL_DEV_COUNT,
  2723. HSEL_DEV_NAME);
  2724. if (0 != ret) {
  2725. FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
  2726. __func__, ret);
  2727. return ret;
  2728. }
  2729. cdev_init(&hsel_cdev, &hsel_fileops);
  2730. hsel_cdev.owner = THIS_MODULE;
  2731. ret = cdev_add(&hsel_cdev, devid_snfc_hsel, HSEL_DEV_COUNT);
  2732. if (0 != ret) {
  2733. unregister_chrdev_region(devid_snfc_hsel, HSEL_DEV_COUNT);
  2734. FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]",
  2735. __func__, ret);
  2736. return ret;
  2737. }
  2738. class_dev = device_create(felica_class, NULL, devid_snfc_hsel,
  2739. NULL, HSEL_DEV_NAME);
  2740. if (0 != IS_ERR(class_dev)) {
  2741. cdev_del(&hsel_cdev);
  2742. unregister_chrdev_region(devid_snfc_hsel, HSEL_DEV_COUNT);
  2743. ret = PTR_ERR(class_dev);
  2744. FELICA_PR_ERR(" %s ERROR(device_create), ret=[%d]",
  2745. __func__, ret);
  2746. return ret;
  2747. }
  2748. FELICA_PR_DBG(" %s END", __func__);
  2749. return ret;
  2750. }
  2751. /*
  2752. * finalize device
  2753. */
  2754. static void hsel_exit(void)
  2755. {
  2756. FELICA_PR_DBG(" %s START", __func__);
  2757. device_destroy(felica_class, devid_snfc_hsel);
  2758. cdev_del(&hsel_cdev);
  2759. unregister_chrdev_region(devid_snfc_hsel, HSEL_DEV_COUNT);
  2760. FELICA_PR_DBG(" %s END", __func__);
  2761. }
  2762. /*
  2763. * open device
  2764. */
  2765. static int hsel_open(struct inode *inode, struct file *file)
  2766. {
  2767. FELICA_PR_DBG(" %s START", __func__);
  2768. FELICA_PR_DBG(" %s END", __func__);
  2769. return 0;
  2770. }
  2771. /*
  2772. * close device
  2773. */
  2774. static int hsel_release(struct inode *inode, struct file *file)
  2775. {
  2776. FELICA_PR_DBG(" %s START", __func__);
  2777. FELICA_PR_DBG(" %s END", __func__);
  2778. return 0;
  2779. }
  2780. /*
  2781. * read operation
  2782. */
  2783. static ssize_t hsel_read(struct file *file, char __user *buf, size_t len,
  2784. loff_t *ppos)
  2785. {
  2786. char hsel_val;
  2787. int ret = -EINVAL;
  2788. FELICA_PR_DBG(" %s START", __func__);
  2789. if (NULL == buf) {
  2790. FELICA_PR_ERR(" %s hsel_read param err", __func__);
  2791. return -EIO;
  2792. }
  2793. if (1 > len) {
  2794. FELICA_PR_ERR(
  2795. " %s length check len = %d", __func__, len);
  2796. return -EIO;
  2797. }
  2798. #if defined(CONFIG_ARCH_EXYNOS)
  2799. ret = gpio_get_value(GPIO_PINID_NFC_HSEL);
  2800. #elif defined(CONFIG_ARCH_APQ8064)
  2801. ret = ice_gpiox_get(GPIO_PINID_NFC_HSEL);
  2802. #elif defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  2803. ret = gpio_get_value(gfelica_hsel_pin);
  2804. #endif
  2805. if (0 > ret) {
  2806. FELICA_PR_ERR(" %s ERROR(gpio_get_value), ret=[%d]",
  2807. __func__, ret);
  2808. return ret;
  2809. }
  2810. if (0 == ret)
  2811. hsel_val = 0;
  2812. else
  2813. hsel_val = 1;
  2814. if (copy_to_user(buf, &hsel_val, 1)) {
  2815. FELICA_PR_ERR(" %s ERROR(copy_to_user)", __func__);
  2816. return -EFAULT;
  2817. }
  2818. FELICA_PR_DBG(" %s END", __func__);
  2819. return 1;
  2820. }
  2821. /*
  2822. * write operation
  2823. */
  2824. static ssize_t hsel_write(struct file *file, const char __user *data,\
  2825. size_t len, loff_t *ppos)
  2826. {
  2827. char hsel_val;
  2828. FELICA_PR_DBG(" %s START", __func__);
  2829. if (NULL == data) {
  2830. FELICA_PR_ERR(" %s hsel_write param err", __func__);
  2831. return -EIO;
  2832. }
  2833. if (1 > len) {
  2834. FELICA_PR_ERR(
  2835. " %s length check len = %d",
  2836. __func__, len);
  2837. return -EIO;
  2838. }
  2839. if (copy_from_user(&hsel_val, data, 1)) {
  2840. FELICA_PR_ERR(" %s ERROR(copy_from_user)", __func__);
  2841. return -EFAULT;
  2842. }
  2843. if (0 == hsel_val) {
  2844. FELICA_PR_INFO(" %s HSEL = Low", __func__);
  2845. } else if (1 == hsel_val) {
  2846. FELICA_PR_INFO(" %s HSEL = High", __func__);
  2847. } else {
  2848. FELICA_PR_ERR(" param err = %d", hsel_val);
  2849. return -EIO;
  2850. }
  2851. #if defined(CONFIG_ARCH_EXYNOS)
  2852. gpio_set_value(GPIO_PINID_NFC_HSEL , hsel_val);
  2853. #elif defined(CONFIG_ARCH_APQ8064)
  2854. ice_gpiox_set(GPIO_PINID_NFC_HSEL , hsel_val);
  2855. #elif defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  2856. gpio_set_value(gfelica_hsel_pin , hsel_val);
  2857. #endif
  2858. FELICA_PR_DBG(" %s END", __func__);
  2859. return 1;
  2860. }
  2861. /******************************************************************************
  2862. * /dev/snfc_intu_poll
  2863. ******************************************************************************/
  2864. /* character device definition */
  2865. static dev_t devid_snfc_intu_poll;
  2866. static struct cdev intu_poll_cdev;
  2867. static struct poll_data g_intu_data;
  2868. static struct poll_data *g_intu_d = &g_intu_data;
  2869. static const struct file_operations intu_poll_fileops = {
  2870. .owner = THIS_MODULE,
  2871. .read = intu_poll_read,
  2872. .open = intu_poll_open,
  2873. .release = intu_poll_release,
  2874. /* .poll = intu_poll_poll,*/
  2875. };
  2876. /*
  2877. * top half of irq_handler
  2878. */
  2879. static irqreturn_t intu_poll_irq_handler(int irq, void *dev_id)
  2880. {
  2881. struct poll_data *intu_d = g_intu_d;
  2882. FELICA_PR_DBG(" %s START irq = %d", __func__, irq);
  2883. disable_irq_nosync(gpio_to_irq(felica_varying_gpio_intu));
  2884. schedule_delayed_work(&intu_d->work, 0);
  2885. FELICA_PR_DBG(" %s END", __func__);
  2886. return IRQ_HANDLED;
  2887. }
  2888. /*
  2889. * bottom half of irq_handler
  2890. */
  2891. static void intu_poll_work_func(struct work_struct *work)
  2892. {
  2893. struct poll_data *intu_d = g_intu_d;
  2894. int read_value = 0;
  2895. int old_value = 0;
  2896. unsigned long irqflag = 0;
  2897. FELICA_PR_DBG(" %s START", __func__);
  2898. old_value = intu_d->device_status;
  2899. read_value = gpio_get_value(felica_varying_gpio_intu);
  2900. FELICA_PR_INFO(" %s read_value = %d old_value = %d",
  2901. __func__, read_value, old_value);
  2902. if (read_value < 0) {
  2903. intu_d->read_error = read_value;
  2904. } else if (read_value != old_value) {
  2905. intu_d->device_status = read_value;
  2906. intu_d->read_error = 0;
  2907. if (intu_d->device_status == INTU_POLL_DEV_LOW)
  2908. irqflag = IRQF_TRIGGER_HIGH | IRQF_SHARED;
  2909. else
  2910. irqflag = IRQF_TRIGGER_LOW | IRQF_SHARED;
  2911. if (irq_set_irq_type(gpio_to_irq(felica_varying_gpio_intu),
  2912. irqflag)) {
  2913. FELICA_PR_ERR(
  2914. " %s ERROR(set_irq_type), irqflag=[%ld]",
  2915. __func__, irqflag);
  2916. }
  2917. }
  2918. enable_irq(gpio_to_irq(felica_varying_gpio_intu));
  2919. if (read_value != old_value || intu_d->read_error) {
  2920. intu_d->irq_handler_done = 1;
  2921. wake_up_interruptible(&intu_d->read_wait);
  2922. }
  2923. FELICA_PR_DBG(
  2924. " %s END read_value = %d, old_value = %d, intu_d->read_error = %d",
  2925. __func__, read_value, old_value, intu_d->read_error);
  2926. }
  2927. /*
  2928. * initialize device
  2929. */
  2930. static int intu_poll_init(void)
  2931. {
  2932. int ret = 0;
  2933. struct device *class_dev;
  2934. unsigned long irqflag = 0;
  2935. devid_snfc_intu_poll = MKDEV(MISC_MAJOR, 0);
  2936. FELICA_PR_DBG(" %s START", __func__);
  2937. ret = alloc_chrdev_region(&devid_snfc_intu_poll,
  2938. 0, INTU_POLL_DEV_COUNT, INTU_POLL_DEV_NAME);
  2939. if (ret) {
  2940. FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
  2941. __func__, ret);
  2942. return ret;
  2943. }
  2944. cdev_init(&intu_poll_cdev, &intu_poll_fileops);
  2945. intu_poll_cdev.owner = THIS_MODULE;
  2946. ret = cdev_add(&intu_poll_cdev,
  2947. devid_snfc_intu_poll,
  2948. INTU_POLL_DEV_COUNT);
  2949. if (ret) {
  2950. unregister_chrdev_region(
  2951. devid_snfc_intu_poll,
  2952. INTU_POLL_DEV_COUNT);
  2953. FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]",
  2954. __func__, ret);
  2955. return ret;
  2956. }
  2957. class_dev = device_create(felica_class,
  2958. NULL, devid_snfc_intu_poll, NULL,
  2959. INTU_POLL_DEV_NAME);
  2960. if (IS_ERR(class_dev)) {
  2961. cdev_del(&intu_poll_cdev);
  2962. unregister_chrdev_region(
  2963. devid_snfc_intu_poll, INTU_POLL_DEV_COUNT);
  2964. ret = PTR_ERR(class_dev);
  2965. FELICA_PR_ERR(" %s ERROR(device_create), ret=[%d]",
  2966. __func__, ret);
  2967. return ret;
  2968. }
  2969. memset(g_intu_d, 0x00, sizeof(struct poll_data));
  2970. INIT_DELAYED_WORK(&g_intu_d->work, intu_poll_work_func);
  2971. init_waitqueue_head(&g_intu_d->read_wait);
  2972. g_intu_d->open_flag = 0;
  2973. if (g_intu_d->open_flag) {
  2974. FELICA_PR_ERR(" %s only one time", __func__);
  2975. return 0;
  2976. }
  2977. g_intu_d->open_flag = 1;
  2978. ret = gpio_get_value(felica_varying_gpio_intu);
  2979. if (ret < 0) {
  2980. g_intu_d->open_flag = 0;
  2981. FELICA_PR_ERR(" %s ERROR(gpio_get_value), ret=[%d]",
  2982. __func__, ret);
  2983. return -EIO;
  2984. }
  2985. g_intu_d->device_status = ret;
  2986. if (g_intu_d->device_status == INTU_POLL_DEV_LOW)
  2987. irqflag = IRQF_TRIGGER_HIGH | IRQF_SHARED;
  2988. else
  2989. irqflag = IRQF_TRIGGER_LOW | IRQF_SHARED;
  2990. if (request_irq(gpio_to_irq(felica_varying_gpio_intu),
  2991. intu_poll_irq_handler, irqflag, INTU_POLL_DEV_NAME,
  2992. (void *)g_intu_d)) {
  2993. g_intu_d->open_flag = 0;
  2994. FELICA_PR_ERR(" %s ERROR(request_irq), irqflag=[%ld]",
  2995. __func__, irqflag);
  2996. return -EIO;
  2997. }
  2998. g_intu_d->irq_handler_done = 0;
  2999. FELICA_PR_DBG(" %s END", __func__);
  3000. return ret;
  3001. }
  3002. /*
  3003. * finalize device
  3004. */
  3005. static void intu_poll_exit(void)
  3006. {
  3007. struct poll_data *intu_d = g_intu_d;
  3008. FELICA_PR_DBG(" %s START", __func__);
  3009. cancel_delayed_work(&intu_d->work);
  3010. free_irq(gpio_to_irq(felica_varying_gpio_intu), (void *)intu_d);
  3011. intu_d->open_flag = 0;
  3012. cdev_del(&intu_poll_cdev);
  3013. unregister_chrdev_region(devid_snfc_intu_poll, INTU_POLL_DEV_COUNT);
  3014. FELICA_PR_DBG(" %s END", __func__);
  3015. }
  3016. /*
  3017. * open device
  3018. */
  3019. static int intu_poll_open(struct inode *inode, struct file *file)
  3020. {
  3021. /* no operation */
  3022. FELICA_PR_DBG(" %s END", __func__);
  3023. return 0;
  3024. }
  3025. /*
  3026. * close device
  3027. */
  3028. static int intu_poll_release(struct inode *inode, struct file *file)
  3029. {
  3030. /* no operation */
  3031. FELICA_PR_DBG(" %s END", __func__);
  3032. return 0;
  3033. }
  3034. /*
  3035. * read operation
  3036. */
  3037. static ssize_t intu_poll_read(struct file *file, char __user *buf,
  3038. size_t len, loff_t *ppos)
  3039. {
  3040. struct poll_data *intu_d = g_intu_d;
  3041. int ret;
  3042. char cret;
  3043. FELICA_PR_DBG(" %s START", __func__);
  3044. if (len < 1) {
  3045. FELICA_PR_ERR(
  3046. " %s length check len = %d", __func__, len);
  3047. return -EIO;
  3048. }
  3049. if (!intu_d->irq_handler_done) {
  3050. if (file->f_flags & O_NONBLOCK) {
  3051. FELICA_PR_ERR(" NONBLOCK");
  3052. return -EAGAIN;
  3053. }
  3054. FELICA_PR_INFO(" NFC intu_poll wait irq");
  3055. ret = wait_event_interruptible(intu_d->read_wait,
  3056. intu_d->irq_handler_done == 1);
  3057. if (-ERESTARTSYS == ret) {
  3058. FELICA_PR_ERR(
  3059. " %s -EINTR wait_event_interruptible ret = %d",
  3060. __func__, ret);
  3061. return -EINTR;
  3062. }
  3063. }
  3064. if (intu_d->read_error) {
  3065. intu_d->irq_handler_done = 0;
  3066. intu_d->read_error = 0;
  3067. FELICA_PR_ERR(" %s intu_d->read_error = %d",
  3068. __func__, intu_d->read_error);
  3069. return -EIO;
  3070. }
  3071. if (intu_d->device_status == INTU_POLL_DEV_HIGH)
  3072. cret = 1;
  3073. else
  3074. cret = 0;
  3075. len = 1;
  3076. if (copy_to_user(buf, &cret, len)) {
  3077. FELICA_PR_ERR(" %s ERROR(copy_to_user)", __func__);
  3078. return -EFAULT;
  3079. }
  3080. intu_d->irq_handler_done = 0;
  3081. FELICA_PR_DBG(
  3082. " %s END len = %d, cret = %d", __func__, len, cret);
  3083. return len;
  3084. }
  3085. /******************************************************************************
  3086. * /dev/snfc_available_poll
  3087. ******************************************************************************/
  3088. /* character device definition */
  3089. static dev_t devid_snfc_abailable_poll;
  3090. static struct cdev available_poll_cdev;
  3091. static const struct file_operations available_poll_fileops = {
  3092. .owner = THIS_MODULE,
  3093. .unlocked_ioctl = available_poll_ioctl,
  3094. .read = available_poll_read,
  3095. .open = available_poll_open,
  3096. .release = available_poll_release,
  3097. };
  3098. /*
  3099. * initialize device
  3100. */
  3101. static int available_poll_init(void)
  3102. {
  3103. int ret = 0;
  3104. struct device *class_dev;
  3105. devid_snfc_abailable_poll = MKDEV(MISC_MAJOR, 0);
  3106. FELICA_PR_DBG(" %s START", __func__);
  3107. ret = alloc_chrdev_region(&devid_snfc_abailable_poll, 0,
  3108. AVAILABLE_POLL_DEV_COUNT, AVAILABLE_POLL_DEV_NAME);
  3109. if (ret) {
  3110. FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
  3111. __func__, ret);
  3112. return ret;
  3113. }
  3114. cdev_init(&available_poll_cdev, &available_poll_fileops);
  3115. available_poll_cdev.owner = THIS_MODULE;
  3116. ret = cdev_add(&available_poll_cdev, devid_snfc_abailable_poll,
  3117. AVAILABLE_POLL_DEV_COUNT);
  3118. if (ret) {
  3119. unregister_chrdev_region(devid_snfc_abailable_poll,
  3120. AVAILABLE_POLL_DEV_COUNT);
  3121. FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]",
  3122. __func__, ret);
  3123. return ret;
  3124. }
  3125. class_dev = device_create(felica_class, NULL, devid_snfc_abailable_poll,
  3126. NULL, AVAILABLE_POLL_DEV_NAME);
  3127. if (IS_ERR(class_dev)) {
  3128. cdev_del(&available_poll_cdev);
  3129. unregister_chrdev_region(devid_snfc_abailable_poll,
  3130. AVAILABLE_POLL_DEV_COUNT);
  3131. ret = PTR_ERR(class_dev);
  3132. FELICA_PR_ERR(" %s ERROR(device_create), ret=[%d]",
  3133. __func__, ret);
  3134. return ret;
  3135. }
  3136. memset((void *)&g_available_data, 0x00, sizeof(struct icc_poll_data));
  3137. init_waitqueue_head(&g_available_data.read_wait);
  3138. FELICA_PR_DBG(" %s END", __func__);
  3139. return ret;
  3140. }
  3141. /*
  3142. * finalize device
  3143. */
  3144. static void available_poll_exit(void)
  3145. {
  3146. FELICA_PR_DBG(" %s START", __func__);
  3147. device_destroy(felica_class, devid_snfc_abailable_poll);
  3148. cdev_del(&available_poll_cdev);
  3149. unregister_chrdev_region(devid_snfc_abailable_poll,
  3150. AVAILABLE_POLL_DEV_COUNT);
  3151. FELICA_PR_DBG(" %s END", __func__);
  3152. }
  3153. /*
  3154. * open device
  3155. */
  3156. static int available_poll_open(struct inode *inode, struct file *file)
  3157. {
  3158. /* no operation */
  3159. FELICA_PR_DBG(" %s END", __func__);
  3160. return 0;
  3161. }
  3162. /*
  3163. * close device
  3164. */
  3165. static int available_poll_release(struct inode *inode, struct file *file)
  3166. {
  3167. FELICA_PR_DBG(" %s START", __func__);
  3168. if (g_available_data.available_flag == 1) {
  3169. g_available_data.rsp_done = 1;
  3170. wake_up_interruptible(&g_available_data.read_wait);
  3171. }
  3172. g_available_data.rsp_done = 0;
  3173. g_available_data.available_flag = 0;
  3174. FELICA_PR_DBG(" %s END", __func__);
  3175. return 0;
  3176. }
  3177. /*
  3178. * read operation
  3179. */
  3180. static ssize_t available_poll_read(struct file *file, char __user *buf,
  3181. size_t len, loff_t *ppos)
  3182. {
  3183. char type = 0;
  3184. int nRet = -1;
  3185. struct icc_poll_data *available_d = &g_available_data;
  3186. FELICA_PR_DBG(" %s START", __func__);
  3187. if ((!uartcc_is_idle_status()) ||
  3188. (0 == g_cen_sts) ||
  3189. (GPIO_VALUE_LOW == g_rfs_sts)) {
  3190. available_d->available_flag = 1;
  3191. nRet = wait_event_interruptible(available_d->read_wait,
  3192. available_d->rsp_done == 1);
  3193. if (nRet < 0) {
  3194. FELICA_PR_ERR(
  3195. " %s ERROR(wait_event_interruptible), ret=[%d]"
  3196. , __func__, nRet);
  3197. return -EIO;
  3198. }
  3199. type = 0x01;
  3200. available_d->rsp_done = 0;
  3201. available_d->available_flag = 0;
  3202. } else {
  3203. type = 0x01;
  3204. }
  3205. if (copy_to_user(buf, &type, len)) {
  3206. FELICA_PR_ERR(" %s ERROR(copy_to_user)", __func__);
  3207. return -EFAULT;
  3208. }
  3209. FELICA_PR_DBG(" %s END read size = %d ", __func__, len);
  3210. return len;
  3211. }
  3212. /*
  3213. * available operation
  3214. */
  3215. static long available_poll_ioctl(struct file *file, unsigned int cmd,
  3216. unsigned long arg)
  3217. {
  3218. long nRet = -EIO;
  3219. FELICA_PR_DBG(" %s START cmd = %x", __func__, cmd);
  3220. switch (cmd) {
  3221. case AVAILABLE_POLL_DEV_SET_PRE_LOCK:
  3222. g_cen_sts = 0;
  3223. nRet = 0;
  3224. break;
  3225. default:
  3226. break;
  3227. }
  3228. FELICA_PR_DBG(" %s END cmd = %x", __func__, cmd);
  3229. return nRet;
  3230. }
  3231. /******************************************************************************
  3232. * /dev/snfc_rfs_poll
  3233. ******************************************************************************/
  3234. /* character device definition */
  3235. static dev_t devid_snfc_rfs_poll;
  3236. static struct cdev rfs_poll_cdev;
  3237. static struct poll_data g_rfs_data;
  3238. static struct poll_data *g_rfs_d = &g_rfs_data;
  3239. static const struct file_operations rfs_poll_fileops = {
  3240. .owner = THIS_MODULE,
  3241. .read = rfs_poll_read,
  3242. .open = rfs_poll_open,
  3243. .release = rfs_poll_release,
  3244. .poll = rfs_poll_poll,
  3245. };
  3246. /*
  3247. * top half of irq_handler
  3248. */
  3249. static irqreturn_t rfs_poll_irq_handler(int irq, void *dev_id)
  3250. {
  3251. struct poll_data *rfs_d = g_rfs_d;
  3252. FELICA_PR_DBG(" %s START irq = %d", __func__, irq);
  3253. disable_irq_nosync(gpio_to_irq(GPIO_PINID_NFC_RFS_POLL));
  3254. schedule_delayed_work(&rfs_d->work, msecs_to_jiffies(RFS_POLL_DELAY));
  3255. FELICA_PR_DBG(" %s END", __func__);
  3256. return IRQ_HANDLED;
  3257. }
  3258. /*
  3259. * bottom half of irq_handler
  3260. */
  3261. static void rfs_poll_work_func(struct work_struct *work)
  3262. {
  3263. struct poll_data *rfs_d = g_rfs_d;
  3264. int read_value = 0;
  3265. int old_value = 0;
  3266. unsigned long irqflag = 0;
  3267. struct icc_poll_data *available_d = &g_available_data;
  3268. FELICA_PR_DBG(" %s START", __func__);
  3269. old_value = rfs_d->device_status;
  3270. read_value = gpio_get_value(GPIO_PINID_NFC_RFS_POLL);
  3271. FELICA_PR_INFO(" %s read_value = %d old_value = %d",
  3272. __func__ , read_value, old_value);
  3273. if (read_value < 0) {
  3274. rfs_d->read_error = read_value;
  3275. } else if (read_value != old_value) {
  3276. g_rfs_sts = read_value;
  3277. if (1 == available_d->available_flag) {
  3278. if (0 != g_cen_sts) {
  3279. if (GPIO_VALUE_LOW != g_rfs_sts) {
  3280. if (uartcc_is_idle_status()) {
  3281. FELICA_PR_INFO(
  3282. " %s wake up available",
  3283. __func__);
  3284. available_d->rsp_done = 1;
  3285. wake_up_interruptible(
  3286. &available_d->read_wait);
  3287. }
  3288. }
  3289. }
  3290. }
  3291. rfs_d->device_status = read_value;
  3292. rfs_d->read_error = 0;
  3293. if (rfs_d->device_status == RFS_POLL_DEV_LOW)
  3294. irqflag = IRQF_TRIGGER_HIGH | IRQF_SHARED;
  3295. else
  3296. irqflag = IRQF_TRIGGER_LOW | IRQF_SHARED;
  3297. if (irq_set_irq_type(
  3298. gpio_to_irq(GPIO_PINID_NFC_RFS_POLL), irqflag)) {
  3299. FELICA_PR_ERR(
  3300. " %s ERROR(set_irq_type), irqflag=[%ld]",
  3301. __func__, irqflag);
  3302. }
  3303. }
  3304. enable_irq(gpio_to_irq(GPIO_PINID_NFC_RFS_POLL));
  3305. if (read_value != old_value || rfs_d->read_error) {
  3306. rfs_d->irq_handler_done = 1;
  3307. wake_up_interruptible(&rfs_d->read_wait);
  3308. }
  3309. FELICA_PR_INFO(
  3310. " %s END read_value = %d,old_value = %d,rfs_d->read_error = %d",
  3311. __func__, read_value, old_value, rfs_d->read_error);
  3312. }
  3313. /*
  3314. * initialize device
  3315. */
  3316. static int rfs_poll_init(void)
  3317. {
  3318. int ret = 0;
  3319. struct device *class_dev;
  3320. unsigned long irqflag = 0;
  3321. devid_snfc_rfs_poll = MKDEV(MISC_MAJOR, 0);
  3322. FELICA_PR_DBG(" %s START", __func__);
  3323. ret = alloc_chrdev_region(&devid_snfc_rfs_poll , 0 , RFS_POLL_DEV_COUNT,
  3324. RFS_POLL_DEV_NAME);
  3325. if (ret) {
  3326. FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region) ret=[%d]",
  3327. __func__, ret);
  3328. return ret;
  3329. }
  3330. cdev_init(&rfs_poll_cdev, &rfs_poll_fileops);
  3331. rfs_poll_cdev.owner = THIS_MODULE;
  3332. ret = cdev_add(&rfs_poll_cdev, devid_snfc_rfs_poll, RFS_POLL_DEV_COUNT);
  3333. if (ret) {
  3334. unregister_chrdev_region(
  3335. devid_snfc_rfs_poll, RFS_POLL_DEV_COUNT);
  3336. FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]",
  3337. __func__, ret);
  3338. return ret;
  3339. }
  3340. class_dev = device_create(felica_class, NULL, devid_snfc_rfs_poll, NULL,
  3341. RFS_POLL_DEV_NAME);
  3342. if (IS_ERR(class_dev)) {
  3343. cdev_del(&rfs_poll_cdev);
  3344. unregister_chrdev_region(
  3345. devid_snfc_rfs_poll, RFS_POLL_DEV_COUNT);
  3346. ret = PTR_ERR(class_dev);
  3347. FELICA_PR_ERR(" %s ERROR(device_create), ret=[%d]",
  3348. __func__, ret);
  3349. return ret;
  3350. }
  3351. memset(g_rfs_d, 0x00, sizeof(struct poll_data));
  3352. INIT_DELAYED_WORK(&g_rfs_d->work, rfs_poll_work_func);
  3353. init_waitqueue_head(&g_rfs_d->read_wait);
  3354. g_rfs_d->open_flag = 0;
  3355. if (g_rfs_d->open_flag) {
  3356. FELICA_PR_ERR(" %s only one time", __func__);
  3357. return -EBUSY;
  3358. }
  3359. g_rfs_d->open_flag = 1;
  3360. ret = gpio_get_value(GPIO_PINID_NFC_RFS_POLL);
  3361. if (ret < 0) {
  3362. g_rfs_d->open_flag = 0;
  3363. FELICA_PR_ERR(" %s ERROR(gpio_get_value), ret=[%d]",
  3364. __func__, ret);
  3365. return -EIO;
  3366. }
  3367. g_rfs_d->device_status = ret;
  3368. g_rfs_sts = ret;
  3369. if (g_rfs_d->device_status == RFS_POLL_DEV_LOW)
  3370. irqflag = IRQF_TRIGGER_HIGH | IRQF_SHARED;
  3371. else
  3372. irqflag = IRQF_TRIGGER_LOW | IRQF_SHARED;
  3373. if (request_irq(gpio_to_irq(
  3374. GPIO_PINID_NFC_RFS_POLL), rfs_poll_irq_handler,
  3375. irqflag, RFS_POLL_DEV_NAME, (void *)g_rfs_d)) {
  3376. g_rfs_d->open_flag = 0;
  3377. FELICA_PR_ERR(" %s ERROR(request_irq), irqflag=[%ld]",
  3378. __func__, irqflag);
  3379. return -EIO;
  3380. }
  3381. g_rfs_d->irq_handler_done = 0;
  3382. FELICA_PR_DBG(" %s END", __func__);
  3383. return ret;
  3384. }
  3385. /*
  3386. * finalize device
  3387. */
  3388. static void rfs_poll_exit(void)
  3389. {
  3390. struct poll_data *rfs_d = g_rfs_d;
  3391. FELICA_PR_DBG(" %s START", __func__);
  3392. cancel_delayed_work(&rfs_d->work);
  3393. free_irq(gpio_to_irq(GPIO_PINID_NFC_RFS_POLL), (void *)rfs_d);
  3394. rfs_d->open_flag = 0;
  3395. cdev_del(&rfs_poll_cdev);
  3396. unregister_chrdev_region(
  3397. devid_snfc_rfs_poll, RFS_POLL_DEV_COUNT);
  3398. FELICA_PR_DBG(" %s END", __func__);
  3399. }
  3400. /*
  3401. * open operation
  3402. */
  3403. static int rfs_poll_open(struct inode *inode, struct file *file)
  3404. {
  3405. int uid_ret = 0;
  3406. FELICA_PR_DBG(" %s START", __func__);
  3407. uid_ret = snfc_uid_check();
  3408. if (uid_ret < 0) {
  3409. FELICA_PR_ERR
  3410. (" %s open fail=[%d]", __func__, uid_ret);
  3411. #ifdef SRIB_DIAG_ENABLED
  3412. FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
  3413. #else
  3414. return -EACCES;
  3415. #endif
  3416. }
  3417. FELICA_PR_DBG(" %s END", __func__);
  3418. return 0;
  3419. }
  3420. /*
  3421. * close operation
  3422. */
  3423. static int rfs_poll_release(struct inode *inode, struct file *file)
  3424. {
  3425. /* no operation */
  3426. FELICA_PR_DBG(" %s END", __func__);
  3427. return 0;
  3428. }
  3429. /*
  3430. * poll operation
  3431. */
  3432. static unsigned int rfs_poll_poll(struct file *file, poll_table *wait)
  3433. {
  3434. struct poll_data *rfs_d = g_rfs_d;
  3435. unsigned int mask = 0;
  3436. FELICA_PR_DBG(" %s START", __func__);
  3437. poll_wait(file, &rfs_d->read_wait, wait);
  3438. if (rfs_d->irq_handler_done)
  3439. mask = POLLIN | POLLRDNORM;
  3440. FELICA_PR_DBG(" %s END mask = %d", __func__, mask);
  3441. return mask;
  3442. }
  3443. /*
  3444. * read operation
  3445. */
  3446. static ssize_t rfs_poll_read(struct file *file, char __user *buf, size_t len,
  3447. loff_t *ppos)
  3448. {
  3449. struct poll_data *rfs_d = g_rfs_d;
  3450. int ret;
  3451. char cret;
  3452. FELICA_PR_DBG(" %s START", __func__);
  3453. if (len < 1) {
  3454. FELICA_PR_ERR(
  3455. " %s length check len = %d", __func__, len);
  3456. return -EIO;
  3457. }
  3458. if (!rfs_d->irq_handler_done) {
  3459. if (file->f_flags & O_NONBLOCK) {
  3460. FELICA_PR_ERR(" %s NONBLOCK", __func__);
  3461. return -EAGAIN;
  3462. }
  3463. FELICA_PR_INFO(
  3464. " %s FeliCa rfs_poll wait irq", __func__);
  3465. ret = wait_event_interruptible(rfs_d->read_wait,
  3466. rfs_d->irq_handler_done == 1);
  3467. if (-ERESTARTSYS == ret) {
  3468. FELICA_PR_ERR(
  3469. " %s -EINTR wait_event_interruptible ret=[%d]",
  3470. __func__, ret);
  3471. return -EINTR;
  3472. }
  3473. }
  3474. if (rfs_d->read_error) {
  3475. rfs_d->irq_handler_done = 0;
  3476. rfs_d->read_error = 0;
  3477. FELICA_PR_ERR(" %s rfs_d->read_error = %d",
  3478. __func__, rfs_d->read_error);
  3479. return -EIO;
  3480. }
  3481. if (rfs_d->device_status == RFS_POLL_DEV_HIGH)
  3482. cret = RFS_POLL_RET_STS_HIGH;
  3483. else
  3484. cret = RFS_POLL_RET_STS_LOW;
  3485. len = 1;
  3486. if (copy_to_user(buf, &cret, len)) {
  3487. FELICA_PR_ERR(" %s ERROR(copy_to_user)", __func__);
  3488. return -EFAULT;
  3489. }
  3490. rfs_d->irq_handler_done = 0;
  3491. FELICA_PR_DBG(
  3492. " %s END len = %d, cret = %d",
  3493. __func__, len, cret);
  3494. return len;
  3495. }
  3496. /******************************************************************************
  3497. * /dev/snfc_pon
  3498. ******************************************************************************/
  3499. /* character device definition */
  3500. static dev_t devid_snfc_pon;
  3501. static struct cdev cxd2235power_cdev;
  3502. static const struct file_operations cxd2235power_fileops = {
  3503. .owner = THIS_MODULE,
  3504. .write = cxd2235power_write,
  3505. .open = cxd2235power_open,
  3506. .release = cxd2235power_release,
  3507. };
  3508. /*
  3509. * initialize device
  3510. */
  3511. static int cxd2235power_init(void)
  3512. {
  3513. int ret = 0;
  3514. struct device *class_dev;
  3515. devid_snfc_pon = MKDEV(MISC_MAJOR, 0);
  3516. FELICA_PR_DBG(" %s START", __func__);
  3517. ret = alloc_chrdev_region(&devid_snfc_pon , 0 , CXD2235_POWER_DEV_COUNT,
  3518. CXD2235_POWER_DEV_NAME);
  3519. if (ret) {
  3520. FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
  3521. __func__, ret);
  3522. return ret;
  3523. }
  3524. cdev_init(&cxd2235power_cdev, &cxd2235power_fileops);
  3525. cxd2235power_cdev.owner = THIS_MODULE;
  3526. ret = cdev_add(&cxd2235power_cdev, devid_snfc_pon,
  3527. CXD2235_POWER_DEV_COUNT);
  3528. if (ret) {
  3529. unregister_chrdev_region(
  3530. devid_snfc_pon, CXD2235_POWER_DEV_COUNT);
  3531. FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]",
  3532. __func__, ret);
  3533. return ret;
  3534. }
  3535. class_dev = device_create(felica_class, NULL, devid_snfc_pon, NULL,
  3536. CXD2235_POWER_DEV_NAME);
  3537. if (IS_ERR(class_dev)) {
  3538. cdev_del(&cxd2235power_cdev);
  3539. unregister_chrdev_region(
  3540. devid_snfc_pon, CXD2235_POWER_DEV_COUNT);
  3541. ret = PTR_ERR(class_dev);
  3542. FELICA_PR_ERR(" %s ERROR(device_create), ret=[%d]",
  3543. __func__, ret);
  3544. return ret;
  3545. }
  3546. FELICA_PR_DBG(" %s END", __func__);
  3547. return ret;
  3548. }
  3549. /*
  3550. * finalize device
  3551. */
  3552. static void cxd2235power_exit(void)
  3553. {
  3554. FELICA_PR_DBG(" %s START", __func__);
  3555. device_destroy(felica_class, devid_snfc_pon);
  3556. cdev_del(&cxd2235power_cdev);
  3557. unregister_chrdev_region(devid_snfc_pon, CXD2235_POWER_DEV_COUNT);
  3558. FELICA_PR_DBG(" %s END", __func__);
  3559. }
  3560. /*
  3561. * open operation
  3562. */
  3563. static int cxd2235power_open(struct inode *inode, struct file *file)
  3564. {
  3565. int uid_ret = 0;
  3566. FELICA_PR_DBG(" %s START", __func__);
  3567. uid_ret = snfc_uid_check();
  3568. if (uid_ret < 0) {
  3569. FELICA_PR_ERR
  3570. (" %s open fail=[%d]", __func__, uid_ret);
  3571. #ifdef SRIB_DIAG_ENABLED
  3572. FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
  3573. #else
  3574. return -EACCES;
  3575. #endif
  3576. }
  3577. FELICA_PR_DBG(" %s END", __func__);
  3578. return 0;
  3579. }
  3580. /*
  3581. * close operation
  3582. */
  3583. static int cxd2235power_release(struct inode *inode, struct file *file)
  3584. {
  3585. /* no operation */
  3586. FELICA_PR_DBG(" %s END", __func__);
  3587. return 0;
  3588. }
  3589. /*
  3590. * write operation
  3591. */
  3592. static ssize_t cxd2235power_write(struct file *file, const char __user *data,
  3593. size_t len, loff_t *ppos)
  3594. {
  3595. char on;
  3596. FELICA_PR_DBG(" %s START", __func__);
  3597. if (len < 1) {
  3598. FELICA_PR_ERR(
  3599. " %s length check len = %d", __func__, len);
  3600. return -EIO;
  3601. }
  3602. len = 1;
  3603. if (copy_from_user(&on, data, len)) {
  3604. FELICA_PR_ERR(" %s ERROR(copy_from_user)", __func__);
  3605. return -EFAULT;
  3606. }
  3607. #if defined(CONFIG_ARCH_EXYNOS)
  3608. gpio_set_value(GPIO_PINID_NFC_PON , on);
  3609. #elif defined(CONFIG_ARCH_APQ8064)
  3610. ice_gpiox_set(GPIO_PINID_NFC_PON, on);
  3611. #elif defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
  3612. #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
  3613. gpio_set_value(gfelica_pon_pin , on); // PON is same for FELICA and NFC.
  3614. #else
  3615. gpio_set_value(GPIO_PINID_NFC_PON , on);
  3616. #endif // CONFIG_MACH_KLTE
  3617. #endif
  3618. FELICA_PR_DBG(" %s END on = %d", __func__, on);
  3619. return len;
  3620. }
  3621. /******************************************************************************
  3622. * /dev/snfc_rfs
  3623. ******************************************************************************/
  3624. /* character device definition */
  3625. static dev_t devid_snfc_rfs;
  3626. static struct cdev cdev_snfc_rfs;
  3627. static const struct file_operations fops_snfc_rfs = {
  3628. .owner = THIS_MODULE,
  3629. .open = snfc_rfs_open,
  3630. .release = snfc_rfs_close,
  3631. .read = snfc_rfs_read,
  3632. };
  3633. /*
  3634. * initialize device
  3635. */
  3636. static void snfc_rfs_init(void)
  3637. {
  3638. int ret;
  3639. struct device *device_snfc_rfs;
  3640. FELICA_PR_DBG(" %s START", __func__);
  3641. devid_snfc_rfs = MKDEV(FELICA_MAJOR, FELICA_MINOR);
  3642. ret =
  3643. alloc_chrdev_region(&devid_snfc_rfs, FELICA_BASEMINOR,
  3644. FELICA_MINOR_COUNT, SNFC_RFS_NAME);
  3645. if (ret < 0) {
  3646. FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
  3647. __func__, ret);
  3648. return;
  3649. }
  3650. cdev_init(&cdev_snfc_rfs, &fops_snfc_rfs);
  3651. ret = cdev_add(&cdev_snfc_rfs, devid_snfc_rfs, FELICA_MINOR_COUNT);
  3652. if (ret < 0) {
  3653. unregister_chrdev_region(devid_snfc_rfs, FELICA_MINOR_COUNT);
  3654. FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
  3655. ret);
  3656. return;
  3657. }
  3658. device_snfc_rfs =
  3659. device_create(felica_class, NULL, devid_snfc_rfs, NULL,
  3660. SNFC_RFS_NAME);
  3661. if (IS_ERR(device_snfc_rfs)) {
  3662. cdev_del(&cdev_snfc_rfs);
  3663. unregister_chrdev_region(devid_snfc_rfs, FELICA_MINOR_COUNT);
  3664. FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
  3665. return;
  3666. }
  3667. FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
  3668. MAJOR(devid_snfc_rfs), MINOR(devid_snfc_rfs));
  3669. }
  3670. /*
  3671. * finalize device
  3672. */
  3673. static void snfc_rfs_exit(void)
  3674. {
  3675. FELICA_PR_DBG(" %s START", __func__);
  3676. device_destroy(felica_class, devid_snfc_rfs);
  3677. cdev_del(&cdev_snfc_rfs);
  3678. unregister_chrdev_region(devid_snfc_rfs, FELICA_MINOR_COUNT);
  3679. }
  3680. /*
  3681. * open device
  3682. */
  3683. static int snfc_rfs_open(struct inode *inode, struct file *file)
  3684. {
  3685. int uid_ret = 0;
  3686. FELICA_PR_DBG(" %s START", __func__);
  3687. uid_ret = snfc_uid_check();
  3688. if (uid_ret < 0) {
  3689. FELICA_PR_ERR
  3690. (" %s open fail=[%d]", __func__, uid_ret);
  3691. #ifdef SRIB_DIAG_ENABLED
  3692. FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
  3693. #else
  3694. return -EACCES;
  3695. #endif
  3696. }
  3697. FELICA_PR_DBG(" %s END", __func__);
  3698. return 0;
  3699. }
  3700. /*
  3701. * close device
  3702. */
  3703. static int snfc_rfs_close(struct inode *inode, struct file *file)
  3704. {
  3705. /* no operation */
  3706. FELICA_PR_DBG(" %s END", __func__);
  3707. return 0;
  3708. }
  3709. /*
  3710. * read operation
  3711. */
  3712. static ssize_t snfc_rfs_read(struct file *file, char __user *buf, \
  3713. size_t len, loff_t *ppos)
  3714. {
  3715. int ret;
  3716. char retparam;
  3717. FELICA_PR_DBG(" %s START", __func__);
  3718. ret = gpio_get_value(GPIO_PINID_SNFC_RFS);
  3719. if (ret == GPIO_VALUE_HIGH) {
  3720. retparam = SNFC_RFS_STANDBY;
  3721. FELICA_PR_INFO(" Carrier-Wave Status is [%d][standby]",
  3722. retparam);
  3723. } else if (ret == GPIO_VALUE_LOW) {
  3724. retparam = SNFC_RFS_DETECTED;
  3725. FELICA_PR_INFO(" Carrier-Wave Status is [%d][detected]",
  3726. retparam);
  3727. } else {
  3728. FELICA_PR_ERR(" %s ERROR(gpio_get_value), ret=[%d]",
  3729. __func__, ret);
  3730. return -EIO;
  3731. }
  3732. ret = copy_to_user(buf, &retparam, SNFC_RFS_DATA_LEN);
  3733. if (ret != 0) {
  3734. FELICA_PR_ERR(" %s ERROR(copy_to_user), ret=[%d]",
  3735. __func__, ret);
  3736. return -EFAULT;
  3737. }
  3738. *ppos += 1;
  3739. FELICA_PR_DBG(" %s END", __func__);
  3740. return SNFC_RFS_DATA_LEN;
  3741. }
  3742. /******************************************************************************
  3743. * /dev/snfc_uart
  3744. ******************************************************************************/
  3745. /* character device definition */
  3746. static dev_t devid_snfc;
  3747. static struct cdev cdev_snfc;
  3748. static const struct file_operations fops_snfc = {
  3749. .owner = THIS_MODULE,
  3750. .open = snfc_uart_open,
  3751. .release = snfc_uart_close,
  3752. .read = snfc_uart_read,
  3753. .write = snfc_uart_write,
  3754. .unlocked_ioctl = snfc_uart_ioctl,
  3755. .poll = snfc_uart_poll,
  3756. };
  3757. /*
  3758. * initialize device
  3759. */
  3760. static void snfc_uart_init(void)
  3761. {
  3762. int ret;
  3763. struct device *device_snfc;
  3764. FELICA_PR_DBG(" %s START", __func__);
  3765. devid_snfc = MKDEV(FELICA_MAJOR, FELICA_MINOR);
  3766. ret = alloc_chrdev_region(&devid_snfc, FELICA_BASEMINOR,
  3767. FELICA_MINOR_COUNT, SNFC_UART_NAME);
  3768. if (ret < 0) {
  3769. FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
  3770. __func__, ret);
  3771. return;
  3772. }
  3773. cdev_init(&cdev_snfc, &fops_snfc);
  3774. ret = cdev_add(&cdev_snfc, devid_snfc, FELICA_MINOR_COUNT);
  3775. if (ret < 0) {
  3776. unregister_chrdev_region(devid_snfc, FELICA_MINOR_COUNT);
  3777. FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
  3778. ret);
  3779. return;
  3780. }
  3781. device_snfc = device_create(felica_class, NULL, devid_snfc, NULL,
  3782. SNFC_UART_NAME);
  3783. if (IS_ERR(device_snfc)) {
  3784. cdev_del(&cdev_snfc);
  3785. unregister_chrdev_region(devid_snfc, FELICA_MINOR_COUNT);
  3786. FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
  3787. return;
  3788. }
  3789. FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
  3790. MAJOR(devid_snfc), MINOR(devid_snfc));
  3791. }
  3792. /*
  3793. * finalize device
  3794. */
  3795. static void snfc_uart_exit(void)
  3796. {
  3797. FELICA_PR_DBG(" %s START", __func__);
  3798. device_destroy(felica_class, devid_snfc);
  3799. cdev_del(&cdev_snfc);
  3800. unregister_chrdev_region(devid_snfc, FELICA_MINOR_COUNT);
  3801. }
  3802. /*
  3803. * open device
  3804. */
  3805. static int snfc_uart_open(struct inode *inode, struct file *file)
  3806. {
  3807. uid_t uid;
  3808. /* struct termios termios;*/
  3809. struct file *tty;
  3810. int ret = 0;
  3811. FELICA_PR_DBG(" %s START", __func__);
  3812. /* check NFC uid */
  3813. uid = __task_cred(current)->uid;
  3814. if (uid != gnfc_uid) {
  3815. FELICA_PR_ERR(\
  3816. " %s END -EACCES, uid=[%d], gnfc_uid=[%d]\n", __func__, uid,gnfc_uid);
  3817. #ifdef SRIB_DIAG_ENABLED
  3818. FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
  3819. #else
  3820. return -EACCES;
  3821. #endif
  3822. }
  3823. file->private_data = dev_sem;
  3824. if (down_interruptible(&dev_sem->felica_sem)) {
  3825. FELICA_PR_ERR(\
  3826. " %s END, ERR[ERESTARTSYS]\n", __func__);
  3827. return -ERESTARTSYS;
  3828. }
  3829. if (pg_tty != NULL) {
  3830. FELICA_PR_ERR(
  3831. " %s multi open result=%d", __func__, ret);
  3832. gnfc_open_cnt++;
  3833. up(&dev_sem->felica_sem);
  3834. return ret;
  3835. }
  3836. tty = filp_open(UART_DEV_NAME, O_RDWR | O_NOCTTY | O_NONBLOCK, 0);
  3837. if (IS_ERR(tty)) {
  3838. pg_tty = NULL;
  3839. ret = PTR_ERR(tty);
  3840. up(&dev_sem->felica_sem);
  3841. FELICA_PR_ERR(
  3842. " %s filp_open result = %d", __func__, ret);
  3843. return ret;
  3844. }
  3845. pg_tty = tty;
  3846. gnfc_open_cnt++;
  3847. ret = 0;
  3848. up(&dev_sem->felica_sem);
  3849. FELICA_PR_DBG(" %s END", __func__);
  3850. return ret;
  3851. }
  3852. /*
  3853. * close device
  3854. */
  3855. static int snfc_uart_close(struct inode *inode, struct file *file)
  3856. {
  3857. struct file *tty;
  3858. FELICA_PR_DBG(" %s START", __func__);
  3859. if (down_interruptible(&dev_sem->felica_sem)) {
  3860. FELICA_PR_ERR(\
  3861. " %s END, ERR[ERESTARTSYS]\n", __func__);
  3862. return -ERESTARTSYS;
  3863. }
  3864. gnfc_open_cnt--;
  3865. tty = NULL;
  3866. if (gnfc_open_cnt == 0) {
  3867. tty = pg_tty;
  3868. if (tty) {
  3869. filp_close(tty, 0);
  3870. pg_tty = NULL;
  3871. }
  3872. }
  3873. up(&dev_sem->felica_sem);
  3874. FELICA_PR_DBG(" %s END", __func__);
  3875. return 0;
  3876. }
  3877. /*
  3878. * read operation
  3879. */
  3880. static ssize_t snfc_uart_read(struct file *file, char __user *buf,\
  3881. size_t len, loff_t *ppos)
  3882. {
  3883. struct file *tty;
  3884. ssize_t ret = -ENOSYS;
  3885. FELICA_PR_DBG(" %s START", __func__);
  3886. if (down_interruptible(&dev_sem->felica_sem)) {
  3887. FELICA_PR_ERR(\
  3888. " %s END, ERR[ERESTARTSYS]\n", __func__);
  3889. return -ERESTARTSYS;
  3890. }
  3891. tty = pg_tty;
  3892. if (tty && tty->f_op->read)
  3893. ret = tty->f_op->read(tty, buf, len, ppos);
  3894. up(&dev_sem->felica_sem);
  3895. FELICA_PR_DBG(" %s END", __func__);
  3896. return ret;
  3897. }
  3898. /*
  3899. * write operation
  3900. */
  3901. static ssize_t snfc_uart_write(struct file *file, const char __user *data, \
  3902. size_t len, loff_t *ppos)
  3903. {
  3904. struct file *tty;
  3905. ssize_t ret = -ENOSYS;
  3906. FELICA_PR_DBG(" %s START", __func__);
  3907. if (down_interruptible(&dev_sem->felica_sem)) {
  3908. FELICA_PR_ERR(\
  3909. " %s END, ERR[ERESTARTSYS]\n", __func__);
  3910. return -ERESTARTSYS;
  3911. }
  3912. tty = pg_tty;
  3913. if (tty && tty->f_op->write)
  3914. ret = tty->f_op->write(tty, data, len, ppos);
  3915. up(&dev_sem->felica_sem);
  3916. FELICA_PR_DBG(" %s END", __func__);
  3917. return ret;
  3918. }
  3919. /*
  3920. * ioctl operation
  3921. */
  3922. static long snfc_uart_ioctl(struct file *file, unsigned int cmd, \
  3923. unsigned long arg)
  3924. {
  3925. struct file *tty;
  3926. ssize_t ret = -ENOSYS;
  3927. FELICA_PR_DBG(" %s START", __func__);
  3928. if (down_interruptible(&dev_sem->felica_sem)) {
  3929. FELICA_PR_ERR(\
  3930. " %s END, ERR[ERESTARTSYS]\n", __func__);
  3931. return -ERESTARTSYS;
  3932. }
  3933. tty = pg_tty;
  3934. if (tty && tty->f_op->unlocked_ioctl)
  3935. ret = tty->f_op->unlocked_ioctl(tty, cmd, arg);
  3936. up(&dev_sem->felica_sem);
  3937. FELICA_PR_DBG(" %s END", __func__);
  3938. return ret;
  3939. }
  3940. /*
  3941. * poll operation
  3942. */
  3943. static unsigned int snfc_uart_poll(struct file *file,
  3944. struct poll_table_struct *poll_table)
  3945. {
  3946. struct file *tty;
  3947. unsigned int ret = 0;
  3948. FELICA_PR_DBG(" %s START", __func__);
  3949. if (down_interruptible(&dev_sem->felica_sem))
  3950. return 0;
  3951. tty = pg_tty;
  3952. if (tty && tty->f_op->poll)
  3953. ret = tty->f_op->poll(tty, poll_table);
  3954. up(&dev_sem->felica_sem);
  3955. FELICA_PR_DBG(" %s END", __func__);
  3956. return ret;
  3957. }
  3958. /******************************************************************************
  3959. * /dev/uartcc
  3960. ******************************************************************************/
  3961. /* character device definition */
  3962. static struct felica_sem_data *guartcc_sem;
  3963. static dev_t devid_uartcc;
  3964. static struct cdev cdev_uartcc;
  3965. static const struct file_operations fops_uartcc = {
  3966. .owner = THIS_MODULE,
  3967. .open = uartcc_open,
  3968. .release = uartcc_close,
  3969. .unlocked_ioctl = uartcc_ioctl,
  3970. };
  3971. /*
  3972. * uartcc_init
  3973. */
  3974. static void uartcc_init(void)
  3975. {
  3976. int ret;
  3977. struct device *device_uartcc;
  3978. FELICA_PR_DBG(" %s START\n", __func__);
  3979. devid_uartcc = MKDEV(UARTCC_MAJOR, UARTCC_MINOR);
  3980. ret =
  3981. alloc_chrdev_region(&devid_uartcc, UARTCC_BASEMINOR,
  3982. UARTCC_MINOR_COUNT, UARTCC_NAME);
  3983. if (ret < 0) {
  3984. FELICA_PR_ERR(
  3985. " %s ERROR(alloc_chrdev_region), ret=[%d]\n",
  3986. __func__, ret);
  3987. return;
  3988. }
  3989. cdev_init(&cdev_uartcc, &fops_uartcc);
  3990. ret = cdev_add(&cdev_uartcc, devid_uartcc, UARTCC_MINOR_COUNT);
  3991. if (ret < 0) {
  3992. unregister_chrdev_region(devid_uartcc, UARTCC_MINOR_COUNT);
  3993. FELICA_PR_ERR(
  3994. " %s ERROR(cdev_add), ret=[%d]\n", __func__,
  3995. ret);
  3996. return;
  3997. }
  3998. device_uartcc =
  3999. device_create(felica_class, NULL, devid_uartcc, NULL,
  4000. UARTCC_NAME);
  4001. if (IS_ERR(device_uartcc)) {
  4002. cdev_del(&cdev_uartcc);
  4003. unregister_chrdev_region(devid_uartcc, UARTCC_MINOR_COUNT);
  4004. FELICA_PR_ERR(" %s ERROR(device_create)\n", __func__);
  4005. return;
  4006. }
  4007. guartcc_sem = kmalloc(sizeof(struct felica_sem_data), GFP_KERNEL);
  4008. if (!guartcc_sem) {
  4009. cdev_del(&cdev_uartcc);
  4010. unregister_chrdev_region(devid_uartcc, UARTCC_MINOR_COUNT);
  4011. FELICA_PR_ERR(
  4012. " %s ERROR(guartcc_sem malloc)\n", __func__);
  4013. return;
  4014. }
  4015. sema_init(&guartcc_sem->felica_sem, 1);
  4016. FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]\n", __func__, \
  4017. MAJOR(devid_uartcc), MINOR(devid_uartcc));
  4018. }
  4019. /*
  4020. * uartcc_exit
  4021. */
  4022. static void uartcc_exit(void)
  4023. {
  4024. FELICA_PR_DBG(" %s START\n", __func__);
  4025. kfree(guartcc_sem);
  4026. device_destroy(felica_class, devid_uartcc);
  4027. cdev_del(&cdev_uartcc);
  4028. unregister_chrdev_region(devid_uartcc, UARTCC_MINOR_COUNT);
  4029. FELICA_PR_DBG(" %s END\n", __func__);
  4030. }
  4031. /*
  4032. * open device
  4033. */
  4034. static int uartcc_open(struct inode *inode, struct file *file)
  4035. {
  4036. /* no operation */
  4037. FELICA_PR_DBG(" %s END\n", __func__);
  4038. return 0;
  4039. }
  4040. /*
  4041. * close device
  4042. */
  4043. static int uartcc_close(struct inode *inode, struct file *file)
  4044. {
  4045. /* no operation */
  4046. FELICA_PR_DBG(" %s END\n", __func__);
  4047. return 0;
  4048. }
  4049. /*
  4050. * available operation
  4051. */
  4052. static long uartcc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  4053. {
  4054. int ret = 0;
  4055. int user_buf = 0;
  4056. FELICA_PR_DBG(" %s START, cmd=[%d]\n", __func__, cmd);
  4057. switch (cmd) {
  4058. case UARTCC_SET_NFC_START_REQ:
  4059. if (down_interruptible(&guartcc_sem->felica_sem)) {
  4060. FELICA_PR_ERR(
  4061. " %s ERROR(down_interruptible)\n",
  4062. __func__);
  4063. return -ERESTARTSYS;
  4064. }
  4065. ret = copy_from_user(
  4066. &user_buf, (void __user *)arg, sizeof(user_buf));
  4067. if (ret != 0) {
  4068. FELICA_PR_ERR
  4069. (" %s ERROR(copy_from_user), ret=[%d]\n",
  4070. __func__, ret);
  4071. up(&guartcc_sem->felica_sem);
  4072. return -EFAULT;
  4073. }
  4074. guartcc_start_req = user_buf;
  4075. /* felica start request */
  4076. uartcc_felica_start_request();
  4077. FELICA_PR_INFO(" %s Set nfc start request=[%d]\n",
  4078. __func__, guartcc_start_req);
  4079. #ifdef P2P_FPGA_ALWAYS_ON
  4080. switch (guartcc_start_req) {
  4081. case SNFC_START_TARGET:
  4082. case SNFC_START_INTU:
  4083. set_fpga_felica_flag(1);
  4084. break;
  4085. case UARTCC_NFC_START_ENDPROC:
  4086. break;
  4087. default:
  4088. set_fpga_felica_flag(0);
  4089. break;
  4090. }
  4091. FELICA_PR_INFO(" %s [fpga]felica_status=[%d]\n",
  4092. __func__, felica_status);
  4093. #endif /* P2P_FPGA_ALWAYS_ON */
  4094. up(&guartcc_sem->felica_sem);
  4095. break;
  4096. case UARTCC_GET_FELICA_STATUS:
  4097. if (down_interruptible(&guartcc_sem->felica_sem)) {
  4098. FELICA_PR_ERR(
  4099. " %s ERROR(down_interruptible)\n", \
  4100. __func__);
  4101. return -ERESTARTSYS;
  4102. }
  4103. user_buf = uartcc_get_felica_status();
  4104. ret = copy_to_user(
  4105. (int __user *)arg, &user_buf, sizeof(user_buf));
  4106. if (ret != 0) {
  4107. FELICA_PR_ERR
  4108. (" %s ERROR(copy_to_user), ret=[%d]\n", \
  4109. __func__, ret);
  4110. up(&guartcc_sem->felica_sem);
  4111. return -EFAULT;
  4112. }
  4113. FELICA_PR_INFO(" %s Get felica status=[%d]\n", \
  4114. __func__, guartcc_felica_status);
  4115. up(&guartcc_sem->felica_sem);
  4116. break;
  4117. case UARTCC_SET_FELICA_STATUS:
  4118. case UARTCC_GET_NFC_START_REQ:
  4119. FELICA_PR_INFO(" %s No operation cmd\n", __func__);
  4120. break;
  4121. default:
  4122. FELICA_PR_ERR(" %s ERROR(unknown command)\n", __func__);
  4123. ret = -EIO;
  4124. break;
  4125. }
  4126. FELICA_PR_DBG(" %s END\n", __func__);
  4127. return ret;
  4128. }
  4129. /*
  4130. * felica start request
  4131. */
  4132. static void uartcc_felica_start_request(void)
  4133. {
  4134. struct icc_poll_data *felica_poll = &gfelica_poll_data;
  4135. FELICA_PR_DBG(" %s START\n", __func__);
  4136. FELICA_PR_INFO(" %s start_req=[%d], felica_status=[%d]\n", \
  4137. __func__, guartcc_start_req, guartcc_felica_status);
  4138. /* wake up condition
  4139. * - nfc star req is ENDPROC
  4140. * - felica usage is waiting AutoPolling
  4141. */
  4142. if ((guartcc_start_req == UARTCC_NFC_START_ENDPROC) &&
  4143. (uartcc_get_felica_status() ==
  4144. UARTCC_FELICA_STATAUS_WAIT_POLLING)) {
  4145. felica_poll->rsp_done = 1;
  4146. wake_up_interruptible(&felica_poll->rsp_wait);
  4147. FELICA_PR_INFO(
  4148. " %s wake up felica start event\n", __func__);
  4149. }
  4150. FELICA_PR_DBG(" %s END\n", __func__);
  4151. }
  4152. /*
  4153. * set felica status
  4154. */
  4155. static void uartcc_set_felica_status(int status)
  4156. {
  4157. FELICA_PR_DBG(" %s START, status=[%d]\n", __func__, status);
  4158. guartcc_felica_status = status;
  4159. FELICA_PR_INFO(" %s guartcc_felica_status=[%d]\n",
  4160. __func__, guartcc_felica_status);
  4161. FELICA_PR_DBG(" %s END\n", __func__);
  4162. }
  4163. /*
  4164. * get felica status
  4165. */
  4166. static int uartcc_get_felica_status(void)
  4167. {
  4168. FELICA_PR_DBG(" %s START, guartcc_felica_status=[%d]\n", \
  4169. __func__, guartcc_felica_status);
  4170. FELICA_PR_DBG(" %s END\n", __func__);
  4171. #if defined(CONFIG_MACH_KLTE_KDI)
  4172. if(gfelica_uim_mon == 1) {
  4173. FELICA_PR_ERR(" %s gfelica_uim_mon=%d\n", __func__, gfelica_uim_mon);
  4174. return UARTCC_FELICA_STATAUS_IN_INIT;
  4175. }
  4176. return guartcc_felica_status;
  4177. #else
  4178. return guartcc_felica_status;
  4179. #endif
  4180. }
  4181. /*
  4182. * check for idle state felica
  4183. */
  4184. static unsigned int uartcc_is_idle_status(void)
  4185. {
  4186. int ret = 0;
  4187. int flc_cts = 0;
  4188. FELICA_PR_DBG(" %s START\n", __func__);
  4189. flc_cts = uartcc_get_felica_status();
  4190. if (!flc_cts) { /* idle */
  4191. FELICA_PR_INFO(" %s felica status is idle\n", __func__);
  4192. ret = 1;
  4193. } else { /* else state */
  4194. FELICA_PR_INFO(" %s felica status isn't idle=[%d]\n", \
  4195. __func__, flc_cts);
  4196. }
  4197. FELICA_PR_DBG(" %s END\n", __func__);
  4198. return ret;
  4199. }
  4200. /******************************************************************************
  4201. * /dev/felica_uicc
  4202. ******************************************************************************/
  4203. /* character device definition */
  4204. static dev_t devid_uicc;
  4205. static struct cdev cdev_uicc;
  4206. static const struct file_operations fops_uicc = {
  4207. .owner = THIS_MODULE,
  4208. .open = uicc_open,
  4209. .release = uicc_close,
  4210. .read = uicc_read, // permissive mode issue
  4211. .unlocked_ioctl = uicc_ioctl,
  4212. };
  4213. /*
  4214. * uartcc_init
  4215. */
  4216. static void uicc_init(void)
  4217. {
  4218. int ret;
  4219. struct device *device_uicc;
  4220. FELICA_PR_DBG(" %s START\n", __func__);
  4221. devid_uicc = MKDEV(UICC_MAJOR, UICC_MINOR);
  4222. ret =
  4223. alloc_chrdev_region(&devid_uicc, UICC_BASEMINOR,
  4224. UICC_MINOR_COUNT, UICC_NAME);
  4225. if (ret < 0) {
  4226. FELICA_PR_ERR(
  4227. " %s ERROR(alloc_chrdev_region), ret=[%d]\n",
  4228. __func__, ret);
  4229. return;
  4230. }
  4231. cdev_init(&cdev_uicc, &fops_uicc);
  4232. ret = cdev_add(&cdev_uicc, devid_uicc, UICC_MINOR_COUNT);
  4233. if (ret < 0) {
  4234. unregister_chrdev_region(devid_uicc, UICC_MINOR_COUNT);
  4235. FELICA_PR_ERR(
  4236. " %s ERROR(cdev_add), ret=[%d]\n", __func__,
  4237. ret);
  4238. return;
  4239. }
  4240. device_uicc =
  4241. device_create(felica_class, NULL, devid_uicc, NULL,
  4242. UICC_NAME);
  4243. if (IS_ERR(device_uicc)) {
  4244. cdev_del(&cdev_uicc);
  4245. unregister_chrdev_region(devid_uicc, UICC_MINOR_COUNT);
  4246. FELICA_PR_ERR(" %s ERROR(device_create)\n", __func__);
  4247. return;
  4248. }
  4249. FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]\n", __func__, \
  4250. MAJOR(devid_uicc), MINOR(devid_uicc));
  4251. }
  4252. /*
  4253. * uicc_exit
  4254. */
  4255. static void uicc_exit(void)
  4256. {
  4257. FELICA_PR_DBG(" %s START\n", __func__);
  4258. device_destroy(felica_class, devid_uicc);
  4259. cdev_del(&cdev_uicc);
  4260. unregister_chrdev_region(devid_uicc, UICC_MINOR_COUNT);
  4261. FELICA_PR_DBG(" %s END\n", __func__);
  4262. }
  4263. /*
  4264. * open device
  4265. */
  4266. static int uicc_open(struct inode *inode, struct file *file)
  4267. {
  4268. /* no operation */
  4269. FELICA_PR_DBG(" %s END\n", __func__);
  4270. return 0;
  4271. }
  4272. /*
  4273. * close device
  4274. */
  4275. static int uicc_close(struct inode *inode, struct file *file)
  4276. {
  4277. /* no operation */
  4278. FELICA_PR_DBG(" %s END\n", __func__);
  4279. return 0;
  4280. }
  4281. /*
  4282. * read operation // permissive mode issue
  4283. */
  4284. static ssize_t uicc_read(struct file *file, char __user *buf, \
  4285. size_t len, loff_t *ppos)
  4286. {
  4287. int ret;
  4288. char read_buff = 0;
  4289. read_buff = g_uicc_sts;
  4290. ret = copy_to_user(buf, &read_buff, FELICA_UICC_DATA_LEN);
  4291. if (ret != 0) {
  4292. FELICA_PR_ERR(" %s ERROR(copy_to_user), ret=[%d]",
  4293. __func__, ret);
  4294. return -EFAULT;
  4295. }
  4296. *ppos += 1;
  4297. FELICA_PR_DBG(" %s END", __func__);
  4298. return FELICA_UICC_DATA_LEN;
  4299. }
  4300. /*
  4301. * available operation
  4302. */
  4303. static long uicc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  4304. {
  4305. int ret = 0;
  4306. struct regulator *reg_l9;
  4307. FELICA_PR_DBG(" %s START, cmd=[%d]\n", __func__, cmd);
  4308. FELICA_PR_INFO(" %s START, system_rev=[%d] UICC_rev[%d]\n",
  4309. __func__, system_rev,g_uicc_initrev);
  4310. switch (cmd) {
  4311. case UICC_POWER_ON:
  4312. if(system_rev < g_uicc_initrev)
  4313. {
  4314. reg_l9 = regulator_get(NULL, "8941_l9");
  4315. if (IS_ERR(reg_l9)) {
  4316. FELICA_PR_ERR(" %s 2 could not get 8917_l9, rc = %ld\n",
  4317. __func__, PTR_ERR(reg_l9));
  4318. return UICC_ERROR;
  4319. }
  4320. FELICA_PR_INFO(" %s regulator_get, reg_l9 OK]", __func__);
  4321. ret = regulator_set_voltage(reg_l9, 1800000, 1800000);
  4322. if (ret) {
  4323. FELICA_PR_ERR(
  4324. " %s ERROR(regulator_set_voltage 1.8V~1.8V), ret=[%d]"
  4325. , __func__, ret);
  4326. return UICC_ERROR;
  4327. }
  4328. FELICA_PR_INFO(
  4329. " %s regulator_set_voltage(1.8v~1.8v), ret=[%d]"
  4330. , __func__, ret);
  4331. if (regulator_is_enabled(reg_l9)) {
  4332. FELICA_PR_INFO(
  4333. " %s L9(0V) is enabled. No need to do anything\n"
  4334. , __func__);
  4335. } else {
  4336. ret = regulator_enable(reg_l9);
  4337. if (ret) {
  4338. FELICA_PR_ERR(
  4339. " %s regulator_enable l9 failed, rc=%d\n"
  4340. , __func__, ret);
  4341. return UICC_ERROR;
  4342. }
  4343. }
  4344. FELICA_PR_INFO(
  4345. " %s regulator_enable, ret=[%d]", __func__, ret);
  4346. }
  4347. break;
  4348. case UICC_POWER_OFF:
  4349. if(system_rev < g_uicc_initrev)
  4350. {
  4351. reg_l9 = regulator_get(NULL, "8941_l9");
  4352. if (IS_ERR(reg_l9)) {
  4353. FELICA_PR_ERR(" %s could not get 8917_l9, rc = %ld\n",
  4354. __func__, PTR_ERR(reg_l9));
  4355. return UICC_ERROR;
  4356. }
  4357. FELICA_PR_INFO(" %s regulator_get, reg_l9 OK]", __func__);
  4358. if (regulator_is_enabled(reg_l9)) {
  4359. FELICA_PR_INFO(
  4360. " %s L9(0V) is enabled already\n",__func__);
  4361. if (regulator_disable(reg_l9)) {
  4362. FELICA_PR_ERR
  4363. (" %s disable l9 failed\n", __func__);
  4364. return UICC_ERROR;
  4365. }
  4366. } else {
  4367. FELICA_PR_ERR
  4368. (" %s regulator l9 already disabled", __func__);
  4369. return UICC_ERROR;
  4370. }
  4371. }
  4372. break;
  4373. case UICC_POWER_SPS_PMIC:
  4374. g_uicc_sts = 0x01; // permissive mode issue
  4375. if(system_rev >= g_uicc_initrev)
  4376. {
  4377. #if defined(CONFIG_MACH_KLTE_KDI)
  4378. FELICA_PR_ERR(" %s Select Power Supply control is missing in K-KDDI! This makes kernel panic! gfelica_sps_pin=%d\n", __func__, gfelica_sps_pin);
  4379. #else
  4380. gpio_set_value(gfelica_sps_pin, GPIO_VALUE_HIGH);
  4381. FELICA_PR_INFO(
  4382. " %s Select Power Supply -> HI [%d][%d]\n", __func__,
  4383. gfelica_sps_pin, gpio_get_value(gfelica_sps_pin));
  4384. #endif
  4385. }
  4386. break;
  4387. case UICC_POWER_UIM_MON:
  4388. #if defined(CONFIG_MACH_KLTE_KDI)
  4389. FELICA_PR_INFO(" %s UICC_POWER_UIM_MON! make PON always high!\n", __func__);
  4390. gfelica_uim_mon = 1;
  4391. gpio_set_value(gfelica_pon_pin, GPIO_VALUE_HIGH);
  4392. #else
  4393. FELICA_PR_ERR(" %s UICC_POWER_UIM_MON! this is only for K-KDDI\n", __func__);
  4394. #endif
  4395. break;
  4396. default:
  4397. FELICA_PR_ERR(" %s Undefine Paramater [%d]", __func__, cmd);
  4398. return UICC_ERROR;
  4399. break;
  4400. }
  4401. FELICA_PR_DBG(" %s END\n", __func__);
  4402. return UICC_SUCCESS;
  4403. }
  4404. /******************************************************************************
  4405. * common
  4406. ******************************************************************************/
  4407. /*
  4408. * add CXD2235 additional pin registration
  4409. */
  4410. static void snfc_register_device(void)
  4411. {
  4412. FELICA_PR_DBG(" %s START", __func__);
  4413. intu_poll_init();
  4414. schedule_delayed_work(&g_intu_d->work, msecs_to_jiffies(10));
  4415. rfs_poll_init();
  4416. schedule_delayed_work(&g_rfs_d->work, msecs_to_jiffies(10));
  4417. FELICA_PR_DBG(" %s END", __func__);
  4418. }
  4419. /*
  4420. * add CXD2235 additional pin unregistration
  4421. */
  4422. static void snfc_deregister_device(void)
  4423. {
  4424. FELICA_PR_DBG(" %s START", __func__);
  4425. available_poll_exit();
  4426. intu_poll_exit();
  4427. snfc_rfs_exit();
  4428. rfs_poll_exit();
  4429. hsel_exit();
  4430. cxd2235power_exit();
  4431. FELICA_PR_DBG(" %s END", __func__);
  4432. }
  4433. /*
  4434. * add read and store CEN status for snfc_available_poll device
  4435. */
  4436. static ssize_t snfc_cen_sts_init(void)
  4437. {
  4438. int ret;
  4439. unsigned char address = gi2c_lockaddress;
  4440. unsigned char read_buff = 0;
  4441. struct i2c_msg read_msgs[2];
  4442. read_msgs[0].flags = gread_msgs[0].flags;
  4443. read_msgs[0].len = gread_msgs[0].len;
  4444. read_msgs[1].flags = gread_msgs[1].flags;
  4445. read_msgs[1].len = gread_msgs[1].len;
  4446. read_msgs[0].addr = gi2c_address;
  4447. read_msgs[0].buf = &address;
  4448. read_msgs[1].addr = gi2c_address;
  4449. read_msgs[1].buf = &read_buff;
  4450. FELICA_PR_DBG(" %s START", __func__);
  4451. if (felica_i2c_client == NULL) {
  4452. FELICA_PR_ERR(" felica_i2c_client is NULL");
  4453. return -EIO;
  4454. }
  4455. #if defined(CONFIG_MACH_HLTEDCM)
  4456. //high
  4457. if (system_rev == HW_REV09_OR_10)
  4458. {
  4459. FELICA_PR_INFO(" %s Making MHL_EN HIGH", __func__);
  4460. of_sii8240_hw_poweron(FELICA_CEN_UNLOCK);
  4461. }
  4462. #endif
  4463. ret = i2c_transfer(felica_i2c_client->adapter, &read_msgs[0], 1);
  4464. if (ret < 0) {
  4465. FELICA_PR_ERR(" %s ERROR(i2c_transfer[0]), ret=[%d]",
  4466. __func__, ret);
  4467. return -EIO;
  4468. }
  4469. ret = i2c_transfer(felica_i2c_client->adapter, &read_msgs[1], 1);
  4470. if (ret < 0) {
  4471. FELICA_PR_ERR(" %s ERROR(i2c_transfer[1]), ret=[%d]",
  4472. __func__, ret);
  4473. return -EIO;
  4474. }
  4475. FELICA_PR_INFO(" %s read_buff=[%d]", __func__, read_buff);
  4476. read_buff &= FELICA_CONTROL_LOCK_MASK;
  4477. FELICA_PR_INFO(" %s read_buff=[%d]", __func__, read_buff);
  4478. g_cen_sts = read_buff;
  4479. #if defined(CONFIG_MACH_HLTEDCM)
  4480. //low
  4481. if (system_rev == HW_REV09_OR_10)
  4482. {
  4483. FELICA_PR_INFO(" %s Making MHL_EN LOW", __func__);
  4484. // of_sii8240_hw_poweron(FELICA_CEN_LOCK);
  4485. }
  4486. #endif
  4487. FELICA_PR_DBG(" %s END", __func__);
  4488. return FELICA_CEN_DATA_LEN;
  4489. }
  4490. /******************************************************************************
  4491. * /dev/snfc_cen
  4492. ******************************************************************************/
  4493. /* character device definition */
  4494. static dev_t devid_snfca_cen;
  4495. static struct cdev cdev_snfc_cen;
  4496. static const struct file_operations fops_snfc_cen = {
  4497. .owner = THIS_MODULE,
  4498. .open = snfc_cen_open,
  4499. .release = snfc_cen_close,
  4500. .read = snfc_cen_read,
  4501. };
  4502. /*
  4503. * initialize device
  4504. */
  4505. static void snfc_cen_init(void)
  4506. {
  4507. int ret;
  4508. struct device *device_snfc_cen;
  4509. FELICA_PR_DBG(" %s START", __func__);
  4510. devid_snfca_cen = MKDEV(FELICA_MAJOR, FELICA_MINOR);
  4511. ret =
  4512. alloc_chrdev_region(&devid_snfca_cen, FELICA_BASEMINOR,
  4513. FELICA_MINOR_COUNT, SNFC_CEN_NAME);
  4514. if (ret < 0) {
  4515. FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
  4516. __func__, ret);
  4517. return;
  4518. }
  4519. cdev_init(&cdev_snfc_cen, &fops_snfc_cen);
  4520. ret = cdev_add(&cdev_snfc_cen, devid_snfca_cen, FELICA_MINOR_COUNT);
  4521. if (ret < 0) {
  4522. unregister_chrdev_region(devid_snfca_cen, FELICA_MINOR_COUNT);
  4523. FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
  4524. ret);
  4525. return;
  4526. }
  4527. device_snfc_cen =
  4528. device_create(felica_class, NULL, devid_snfca_cen, NULL,
  4529. SNFC_CEN_NAME);
  4530. if (IS_ERR(device_snfc_cen)) {
  4531. cdev_del(&cdev_snfc_cen);
  4532. unregister_chrdev_region(devid_snfca_cen, FELICA_MINOR_COUNT);
  4533. FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
  4534. return;
  4535. }
  4536. FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
  4537. MAJOR(devid_snfca_cen), MINOR(devid_snfca_cen));
  4538. }
  4539. /*
  4540. * finalize device
  4541. */
  4542. static void snfc_cen_exit(void)
  4543. {
  4544. FELICA_PR_DBG(" %s START", __func__);
  4545. device_destroy(felica_class, devid_snfca_cen);
  4546. cdev_del(&cdev_snfc_cen);
  4547. unregister_chrdev_region(devid_snfca_cen, FELICA_MINOR_COUNT);
  4548. FELICA_PR_DBG(" %s END", __func__);
  4549. }
  4550. /*
  4551. * open device
  4552. */
  4553. static int snfc_cen_open(struct inode *inode, struct file *file)
  4554. {
  4555. uid_t uid;
  4556. #ifdef FELICA_UICC_FUNCTION
  4557. int ret = 0;
  4558. char *cmdpos;
  4559. static char cmdline[1025];
  4560. static unsigned long start_adr, end_adr, leng;
  4561. #endif
  4562. FELICA_PR_DBG(" %s START . system_rev=[%d]", __func__,system_rev);
  4563. #if defined(CONFIG_MACH_HLTEDCM)
  4564. //high
  4565. if (system_rev == HW_REV09_OR_10)
  4566. {
  4567. FELICA_PR_INFO(" %s Making MHL_EN HIGH", __func__);
  4568. of_sii8240_hw_poweron(SNFC_CEN_UNLOCK);
  4569. }
  4570. #endif
  4571. #ifdef FELICA_UICC_FUNCTION
  4572. start_adr = current->mm->arg_start;
  4573. end_adr = current->mm->arg_end;
  4574. leng = end_adr - start_adr;
  4575. if (1024 < leng)
  4576. leng = 1024;
  4577. cmdpos = (char *)(current->mm->arg_start);
  4578. ret = copy_from_user(cmdline, cmdpos, leng);
  4579. cmdline[leng] = '\0';
  4580. if(ret != 0)
  4581. {
  4582. FELICA_PR_ERR(" %s cmdline[%s] ret[%d]", __func__, cmdline, ret);
  4583. return -EFAULT;
  4584. }
  4585. #endif
  4586. uid = __task_cred(current)->uid;
  4587. if (file->f_mode & FMODE_WRITE) {
  4588. #ifdef FELICA_UICC_FUNCTION
  4589. if ((uid != gdiag_uid) && (uid != gmfl_uid)
  4590. && (strncmp(cmdline,gproc_name, leng) != 0)) {
  4591. #else
  4592. if ((uid != gdiag_uid) && (uid != gmfl_uid)) {
  4593. #endif
  4594. FELICA_PR_ERR(" %s END -EACCES, uid=[%d], gmfc_uid=[%d], gdiag_uid=[%d], gmfl_uid=[%d]\n", __func__, uid,gmfc_uid,gdiag_uid,gmfl_uid);
  4595. #if defined(CONFIG_MACH_HLTEDCM)
  4596. //low
  4597. if (system_rev == HW_REV09_OR_10)
  4598. {
  4599. FELICA_PR_INFO(" %s Making MHL_EN LOW", __func__);
  4600. // of_sii8240_hw_poweron(SNFC_CEN_LOCK);
  4601. }
  4602. #endif
  4603. #ifdef SRIB_DIAG_ENABLED
  4604. FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
  4605. #else
  4606. return -EACCES;
  4607. #endif
  4608. }
  4609. }
  4610. FELICA_PR_DBG(" %s END", __func__);
  4611. return 0;
  4612. }
  4613. /*
  4614. * close device
  4615. */
  4616. static int snfc_cen_close(struct inode *inode, struct file *file)
  4617. {
  4618. /* no operation */
  4619. #if defined(CONFIG_MACH_HLTEDCM)
  4620. //low
  4621. if (system_rev == HW_REV09_OR_10)
  4622. {
  4623. FELICA_PR_INFO(" %s Making MHL_EN LOW", __func__);
  4624. // of_sii8240_hw_poweron(SNFC_CEN_LOCK);
  4625. }
  4626. #endif
  4627. FELICA_PR_DBG(" %s END system_rev=[%d]", __func__,system_rev);
  4628. return 0;
  4629. }
  4630. /*
  4631. * read operation
  4632. */
  4633. static ssize_t snfc_cen_read(struct file *file, char __user *buf, \
  4634. size_t len, loff_t *ppos)
  4635. {
  4636. int ret;
  4637. unsigned char address = gi2c_lockaddress;
  4638. unsigned char read_buff = 0;
  4639. struct i2c_msg read_msgs[2];
  4640. read_msgs[0].flags = gread_msgs[0].flags;
  4641. read_msgs[0].len = gread_msgs[0].len;
  4642. read_msgs[1].flags = gread_msgs[1].flags;
  4643. read_msgs[1].len = gread_msgs[1].len;
  4644. read_msgs[0].addr = gi2c_address;
  4645. read_msgs[0].buf = &address;
  4646. read_msgs[1].addr = gi2c_address;
  4647. read_msgs[1].buf = &read_buff;
  4648. if (felica_i2c_client == NULL) {
  4649. FELICA_PR_ERR(" felica_i2c_client is NULL %s -EIO",__func__);
  4650. return -EIO;
  4651. }
  4652. ret = i2c_transfer(felica_i2c_client->adapter, &read_msgs[0], 1);
  4653. if (ret < 0) {
  4654. FELICA_PR_ERR(" %s ERROR(i2c_transfer[0]), ret=[%d]",
  4655. __func__, ret);
  4656. return -EIO;
  4657. }
  4658. ret = i2c_transfer(felica_i2c_client->adapter, &read_msgs[1], 1);
  4659. if (ret < 0) {
  4660. FELICA_PR_ERR(" %s ERROR(i2c_transfer[1]), ret=[%d]",
  4661. __func__, ret);
  4662. return -EIO;
  4663. }
  4664. read_buff &= SNFC_CONTROL_LOCK_MASK;
  4665. #ifdef CONFIG_NFC_FELICA
  4666. g_cen_sts = read_buff;
  4667. #endif
  4668. FELICA_PR_DBG(" %s g_cen_sts=[%d]", __func__, g_cen_sts);
  4669. ret = copy_to_user(buf, &read_buff, SNFC_CEN_DATA_LEN);
  4670. if (ret != 0) {
  4671. FELICA_PR_ERR(" %s ERROR(copy_to_user), ret=[%d]",
  4672. __func__, ret);
  4673. return -EFAULT;
  4674. }
  4675. *ppos += 1;
  4676. return SNFC_CEN_DATA_LEN;
  4677. }
  4678. /*
  4679. * uid check
  4680. */
  4681. static int snfc_uid_check(void)
  4682. {
  4683. uid_t uid;
  4684. uid = __task_cred(current)->uid;
  4685. FELICA_PR_DBG(" %s START", __func__);
  4686. FELICA_PR_INFO(" %s gnfc_uid=[%d]", __func__, (int)gnfc_uid);
  4687. if ((uid != gnfc_uid) && (uid != gdiag_uid)) {
  4688. FELICA_PR_ERR
  4689. (" %s END, uid=[%d], gnfc_uid=[%d], gdiag_uid=[%d]", \
  4690. __func__, uid, gnfc_uid, gdiag_uid);
  4691. #ifdef SRIB_DIAG_ENABLED
  4692. FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
  4693. #else
  4694. return -1;
  4695. #endif
  4696. }
  4697. FELICA_PR_DBG(" %s END", __func__);
  4698. return 0;
  4699. }
  4700. #endif /* CONFIG_NFC_FELICA */
  4701. module_init(felica_init);
  4702. module_exit(felica_exit);
  4703. MODULE_DESCRIPTION("felica_dd");
  4704. MODULE_LICENSE("GPL v2");
  4705. #endif /* CONFIG_FELICA */