12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495 |
- /*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- */
- #ifdef CONFIG_FELICA
- #include "felica.h"
- #include <linux/init.h>
- #include <linux/cdev.h>
- #include <linux/device.h>
- #include <linux/gpio.h>
- #include <linux/delay.h>
- #include <linux/termios.h>
- #include <linux/serial_core.h>
- #include <linux/uaccess.h>
- #ifdef F_WAKE_LOCK
- #include <linux/wakelock.h>
- #endif
- #include <linux/types.h>
- /* jmodel */
- #if defined(CONFIG_ARCH_EXYNOS)
- #include <mach/smc.h>
- #elif defined(CONFIG_ARCH_APQ8064) || defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- #include <mach/scm.h>
- #endif
- #include <asm/system_info.h>
- #include <linux/of_gpio.h>
- #include <linux/mfd/pm8xxx/gpio.h>
- /******************************************************************************
- * log
- ******************************************************************************/
- #include <mach/sec_debug.h>
- #define NO_CHECK_TAMPER
- #define SRIB_DIAG_ENABLED
- /******************************************************************************
- * Board configuration
- ******************************************************************************/
- /* jmodel */
- #if defined(CONFIG_ARCH_EXYNOS)
- #define FELICA_UART1RX EXYNOS5410_GPA0(4)
- #endif
- /* Hmodel */
- #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- #if !defined(CONFIG_MACH_KLTE_KDI) && !defined(CONFIG_MACH_KLTE_DCM) && !defined(CONFIG_MACH_KLTE_SBM)
- static int gfelica_irq_int_pin = -1;
- #endif
- static struct platform_device *felica_gpio_pdev;
- #if defined(CONFIG_MACH_HLTEDCM)
- static int g_uicc_initrev = 7; //HW Rev 0.9
- static int gfelica_sps_pin = 130; //Select Power Supply
- static int gfelica_hsel_pin = GPIO_PINID_NFC_HSEL;
- #define HW_REV09_OR_10 7 // to fix hltedcm i2c h/w issue in REV 09/10.
- 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
- /* K MODEL */
- #elif defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
- static int gfelica_sps_pin = -1; //Select Power Supply
- static int gfelica_pon_pin = GPIO_FELICA_PON_REV06; // PON
- static int gfelica_hsel_pin = -1;
- static int g_uicc_initrev = 0;
- //#define NO_CHECK_TAMPER
- //#define SRIB_DIAG_ENABLED
- #elif defined(CONFIG_MACH_KLTE_KDI)
- static int gfelica_pon_pin = GPIO_FELICA_PON_REV06; // PON
- static int gfelica_hsel_pin = -1;
- static int gfelica_sps_pin = -1;
- static int g_uicc_initrev = 0;
- static int gfelica_uim_mon = 0;
- //#define NO_CHECK_TAMPER
- //#define SRIB_DIAG_ENABLED
- #elif defined(CONFIG_MACH_HLTEKDI)
- static int g_uicc_initrev = 4;
- static int gfelica_sps_pin = -1;
- static int gfelica_hsel_pin = GPIO_PINID_NFC_HSEL;
- #elif defined(CONFIG_MACH_JS01LTEDCM)
- static int g_uicc_initrev = 8; // HW Rev 0.4
- static int gfelica_sps_pin = 130; // Select Power Supply
- static int gfelica_hsel_pin = GPIO_PINID_NFC_HSEL;
- #endif
- #endif /* CONFIG_ARCH_MSM8974 */
- /******************************************************************************
- * global variable
- ******************************************************************************/
- static struct class *felica_class;
- #ifdef F_WAKE_LOCK
- struct wake_lock felica_wake_1;
- struct wake_lock felica_wake_2;
- static int tmout_1 = 3*1000; // wake lock timeout for INT irq.
- #endif
- /* storages for communicate to netlink */
- static int gfa_open_cnt;
- static int gfa_pid;
- static int gfa_connect_flag;
- static struct sock *gfanl_sk;
- static char gfa_send_str[FELICA_NL_MSG_SIZE];
- static char gfa_rcv_str[FELICA_NL_MSG_SIZE];
- static int gfa_wait_flag;
- /* R/W functions availability information storage */
- static char gfelica_rw_status;
- /* IRQ data storage for INT terminal monitoring */
- struct felica_int_irqdata {
- struct delayed_work work;
- wait_queue_head_t read_wait;
- int irq_done;
- int open_flag;
- };
- static struct felica_int_irqdata gint_irq;
- static struct felica_int_irqdata *pgint_irq = &gint_irq;
- /* storages for access restriction */
- static uid_t gmfc_uid = -1;
- static uid_t gmfl_uid = -1;
- static uid_t grwm_uid = -1;
- static uid_t gdiag_uid = -1;
- #ifdef CONFIG_NFC_FELICA
- static uid_t gnfc_uid = -1;
- struct file *pg_tty;
- static int gnfc_open_cnt;
- #endif /* CONFIG_NFC_FELICA */
- /* package name's storage for access restriction */
- static char gdiag_name[DIAG_NAME_MAXSIZE + 1];
- #ifdef FELICA_UICC_FUNCTION
- static char gproc_name[PROC_NAME_MAXSIZE + 1];
- #endif
- static uid_t gant_uid = -1;
- static int gi2c_address;
- static char gi2c_antaddress;
- static char gi2c_lockaddress;
- static struct i2c_msg gread_msgs[] = {
- {
- .addr = 0,
- .flags = 0,
- .len = 0,
- .buf = NULL,
- },
- {
- .addr = 0,
- .flags = 0,
- .len = 0,
- .buf = NULL,
- },
- };
- static struct i2c_msg gwrite_msgs[] = {
- {
- .addr = 0,
- .flags = 0,
- .len = 0,
- .buf = NULL,
- },
- };
- #ifdef CONFIG_NFC_FELICA
- /******************************************************************************
- * Add global variable
- ******************************************************************************/
- struct icc_poll_data {
- wait_queue_head_t read_wait;
- wait_queue_head_t rsp_wait;
- wait_queue_head_t dummy_wait;
- int handler_done;
- int rsp_done;
- struct delayed_work work;
- int device_status;
- int read_error;
- int open_flag;
- int available_flag;
- };
- struct poll_data {
- wait_queue_head_t read_wait;
- int irq_handler_done;
- struct delayed_work work;
- int device_status;
- int read_error;
- int open_flag;
- };
- static struct icc_poll_data gfelica_poll_data;
- static struct icc_poll_data g_available_data;
- static struct icc_poll_data *available_d = &g_available_data;
- static int guartcc_start_req = UARTCC_NFC_START_ENDPROC;
- #ifdef FELICA_UICC_FUNCTION
- static int guartcc_felica_status = UARTCC_FELICA_STATAUS_IN_INIT;
- #else
- static int guartcc_felica_status = UARTCC_FELICA_STATAUS_IDLE;
- #endif
- static int g_cen_sts = 0;
- static int g_rfs_sts = 0;
- static char g_uicc_sts = 0x00; // permissive mode issue
- static int felica_varying_gpio_intu;
- #ifdef P2P_FPGA_ALWAYS_ON
- extern void set_fpga_felica_flag(int on);
- #endif /* P2P_FPGA_ALWAYS_ON */
- #endif /* CONFIG_NFC_FELICA */
- /******************************************************************************
- * /dev/felica
- ******************************************************************************/
- /* character device definition */
- static int felica_uart_port;
- static dev_t devid_felica_uart;
- static struct cdev cdev_felica_uart;
- static const struct file_operations fops_felica_uart = {
- .owner = THIS_MODULE,
- .open = felica_uart_open,
- .release = felica_uart_close,
- .read = felica_uart_read,
- .write = felica_uart_write,
- .fsync = felica_uart_sync,
- .unlocked_ioctl = felica_uart_ioctl,
- };
- struct felica_sem_data {
- struct semaphore felica_sem;
- };
- static struct felica_sem_data *dev_sem;
- /*
- * initialize device
- */
- static void felica_uart_init(void)
- {
- int ret;
- struct device *device_felica_uart;
- FELICA_PR_DBG(" %s START", __func__);
- devid_felica_uart = MKDEV(FELICA_MAJOR, FELICA_MINOR);
- ret =
- alloc_chrdev_region(&devid_felica_uart, FELICA_BASEMINOR,
- FELICA_MINOR_COUNT, FELICA_UART_NAME);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
- __func__, ret);
- return;
- }
- cdev_init(&cdev_felica_uart, &fops_felica_uart);
- ret =
- cdev_add(&cdev_felica_uart, devid_felica_uart, FELICA_MINOR_COUNT);
- if (ret < 0) {
- unregister_chrdev_region(devid_felica_uart, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
- ret);
- return;
- }
- device_felica_uart =
- device_create(felica_class, NULL, devid_felica_uart, NULL,
- FELICA_UART_NAME);
- if (IS_ERR(device_felica_uart)) {
- cdev_del(&cdev_felica_uart);
- unregister_chrdev_region(devid_felica_uart, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
- return;
- }
- dev_sem = kmalloc(sizeof(struct felica_sem_data), GFP_KERNEL);
- if (!dev_sem) {
- cdev_del(&cdev_felica_uart);
- unregister_chrdev_region(devid_felica_uart, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(dev_sem malloc)", __func__);
- return;
- }
- sema_init(&dev_sem->felica_sem, 1);
- #ifdef CONFIG_NFC_FELICA
- memset((void *)&gfelica_poll_data, 0x00, sizeof(struct icc_poll_data));
- init_waitqueue_head(&gfelica_poll_data.rsp_wait);
- gfelica_poll_data.rsp_done = 0;
- gfelica_poll_data.open_flag = 0;
- #endif /* CONFIG_NFC_FELICA */
- FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
- MAJOR(devid_felica_uart), MINOR(devid_felica_uart));
- }
- /*
- * finalize device
- */
- static void felica_uart_exit(void)
- {
- kfree(dev_sem);
- device_destroy(felica_class, devid_felica_uart);
- cdev_del(&cdev_felica_uart);
- unregister_chrdev_region(devid_felica_uart, FELICA_MINOR_COUNT);
- FELICA_PR_DBG(" %s START", __func__);
- }
- /*
- * open device
- */
- static int felica_uart_open(struct inode *inode, struct file *file)
- {
- uid_t uid;
- int ret;
- FELICA_PR_DBG(" %s START", __func__);
- uid = __task_cred(current)->uid;
- if ((uid != gmfc_uid) && (uid != gdiag_uid) && (uid != gant_uid)) {
- FELICA_PR_ERR
- (" %s END -EACCESS, uid=[%d], gmfc_uid=[%d], gdiag_uid=[%d]",
- __func__, uid, gmfc_uid, gdiag_uid);
- #ifdef SRIB_DIAG_ENABLED
- FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
- #else
- return -EACCES;
- #endif
- }
- if (down_interruptible(&dev_sem->felica_sem)) {
- FELICA_PR_ERR(" %s ERROR(down_interruptible)", \
- __func__);
- return -ERESTARTSYS;
- }
- if (gfa_open_cnt == 0) {
- #ifdef CONFIG_NFC_FELICA
- switch (guartcc_start_req) {
- case UARTCC_NFC_START_AUTOPOLLING: /* AutoPoiing */
- {
- /* felica open-waiting for nfc autopolling */
- ret = felica_uart_open_wait_for_polling();
- if (ret < 0) {
- FELICA_PR_ERR( \
- " %s open-waiting fail= [%d]\n " \
- , __func__, ret);
- return ret;
- }
- FELICA_PR_INFO( \
- " %s open wait release\n", \
- __func__);
- }
- break;
- case UARTCC_NFC_START_ENDPROC: /* Unused NFC */
- /* set felica status -> in use */
- uartcc_set_felica_status(UARTCC_FELICA_STATAUS_IN_USE);
- FELICA_PR_INFO( \
- " %s started using FeliCa=[%d]\n", \
- __func__, guartcc_start_req);
- break;
- default: /* NFC in use */
- FELICA_PR_ERR(" -EFAULT %s NFC in use=[%d]\n", \
- __func__, guartcc_start_req);
- /* reset felica status -> idle */
- uartcc_set_felica_status(
- UARTCC_FELICA_STATAUS_IDLE);
- up(&dev_sem->felica_sem);
- return -EFAULT;
- break;
- }
- #endif /* CONFIG_NFC_FELICA */
- memset(gfa_send_str, 0, FELICA_NL_MSG_SIZE);
- memset(gfa_rcv_str, 0, FELICA_NL_MSG_SIZE);
- gfa_send_str[0] = FELICA_NL_REQ_OPEN;
- gfa_send_str[1] = felica_uart_port;
- ret = felica_nl_send_msg(2);
- if (ret == 0) {
- felica_nl_wait_ret_msg();
- if (gfa_rcv_str[1] == FELICA_NL_EFAILED) {
- FELICA_PR_ERR(" %s Open Fail", __func__);
- #ifdef CONFIG_NFC_FELICA
- /* reset felica status -> idle */
- uartcc_set_felica_status(
- UARTCC_FELICA_STATAUS_IDLE);
- #endif /* CONFIG_NFC_FELICA */
- up(&dev_sem->felica_sem);
- return -EFAULT;
- }
- } else {
- FELICA_PR_ERR(" %s felica_nl_send_msg Fail", \
- __func__);
- #ifdef CONFIG_NFC_FELICA
- /* reset felica status -> idle */
- uartcc_set_felica_status(
- UARTCC_FELICA_STATAUS_IDLE);
- #endif /* CONFIG_NFC_FELICA */
- up(&dev_sem->felica_sem);
- return -EFAULT;
- }
- #ifdef F_WAKE_LOCK
- wake_lock(&felica_wake_2);
- FELICA_PR_INFO(" %s Wake Lock(2)", __func__);
- #endif
- }
- gfa_open_cnt++;
- up(&dev_sem->felica_sem);
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- #ifdef CONFIG_NFC_FELICA
- /*
- * felica open-waiting for nfc autopolling
- */
- static int felica_uart_open_wait_for_polling(void)
- {
- int ret = 0;
- struct icc_poll_data *felica_poll = &gfelica_poll_data;
- FELICA_PR_DBG(" %s START\n", __func__);
- /* set felica status -> wait polling */
- uartcc_set_felica_status(UARTCC_FELICA_STATAUS_WAIT_POLLING);
- up(&dev_sem->felica_sem);
- ret = wait_event_interruptible(felica_poll->rsp_wait,
- felica_poll->rsp_done == 1);
- if (ret < 0) {
- /* reset felica status -> idle */
- uartcc_set_felica_status(UARTCC_FELICA_STATAUS_IDLE);
- FELICA_PR_ERR
- (" %s ERROR(wait_event_interruptible), ret=[%d]\n", \
- __func__, ret);
- return -EIO;
- }
- if (down_interruptible(&dev_sem->felica_sem)) {
- /* reset felica status -> idle */
- uartcc_set_felica_status(UARTCC_FELICA_STATAUS_IDLE);
- FELICA_PR_ERR(" %s ERROR(down_interruptible)\n", \
- __func__);
- return -ERESTARTSYS;
- }
- /* set felica status -> in use */
- uartcc_set_felica_status(UARTCC_FELICA_STATAUS_IN_USE);
- felica_poll->rsp_done = 0;
- FELICA_PR_DBG(" %s END\n", __func__);
- return 0;
- }
- #endif /* CONFIG_NFC_FELICA */
- /*
- * close device
- */
- static int felica_uart_close(struct inode *inode, struct file *file)
- {
- int ret;
- FELICA_PR_DBG(" %s START", __func__);
- if (down_interruptible(&dev_sem->felica_sem)) {
- FELICA_PR_ERR(" %s ERROR(down_interruptible)", \
- __func__);
- return -ERESTARTSYS;
- }
- gfa_open_cnt--;
- if (gfa_open_cnt == 0) {
- memset(gfa_send_str, 0, FELICA_NL_MSG_SIZE);
- memset(gfa_rcv_str, 0, FELICA_NL_MSG_SIZE);
- gfa_send_str[0] = FELICA_NL_REQ_CLOSE;
- ret = felica_nl_send_msg(1);
- if (ret == 0) {
- felica_nl_wait_ret_msg();
- if (gfa_rcv_str[1] == FELICA_NL_EFAILED) {
- FELICA_PR_ERR(" %s Close Fail",\
- __func__);
- gfa_open_cnt++;
- up(&dev_sem->felica_sem);
- return -EFAULT;
- }
- #ifdef CONFIG_NFC_FELICA
- /* set felica status -> idle */
- uartcc_set_felica_status(UARTCC_FELICA_STATAUS_IDLE);
- if (1 == available_d->available_flag) {
- if (0 != g_cen_sts) {
- if (GPIO_VALUE_LOW != g_rfs_sts) {
- available_d->rsp_done = 1;
- FELICA_PR_INFO(
- " wake up available");
- wake_up_interruptible(
- &available_d->read_wait);
- }
- }
- }
- #endif /* CONFIG_NFC_FELICA */
- } else {
- FELICA_PR_ERR(" %s felica_nl_send_msg Fail", \
- __func__);
- gfa_open_cnt++;
- up(&dev_sem->felica_sem);
- return -EFAULT;
- }
- #ifdef F_WAKE_LOCK
- wake_unlock(&felica_wake_2);
- FELICA_PR_INFO(" %s Wake UnLock(2)", __func__);
- #endif
- }
- up(&dev_sem->felica_sem);
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * read operation
- */
- static ssize_t felica_uart_read(struct file *file, char __user *buf,
- size_t len, loff_t *ppos)
- {
- int ret = 0;
- int nlret;
- size_t wk_len = 0;
- FELICA_PR_DBG(" %s START", __func__);
- if (down_interruptible(&dev_sem->felica_sem)) {
- FELICA_PR_ERR(" %s ERROR(down_interruptible)", \
- __func__);
- return -ERESTARTSYS;
- }
- memset(gfa_send_str, 0, FELICA_NL_MSG_SIZE);
- memset(gfa_rcv_str, 0, FELICA_NL_MSG_SIZE);
- wk_len = len;
- if (FELICA_NL_MSG_DATA_SIZE < wk_len) {
- FELICA_PR_INFO(" %s read max size over [%d]", __func__,
- wk_len);
- wk_len = FELICA_NL_MSG_DATA_SIZE;
- }
- gfa_send_str[0] = FELICA_NL_REQ_READ;
- gfa_send_str[1] = (char)(wk_len >> 8);
- gfa_send_str[2] = (char)wk_len;
- nlret = felica_nl_send_msg(3);
- wk_len = 0;
- if (nlret == 0) {
- felica_nl_wait_ret_msg();
- if (gfa_rcv_str[1] == FELICA_NL_SUCCESS) {
- wk_len =
- (((int)gfa_rcv_str[2] << 8) & 0xFF00) | \
- (int)gfa_rcv_str[3];
- FELICA_PR_DBG(" %s Rcv len [%d]", __func__, wk_len);
- FELICA_PR_DBG(
- " %s Rcv data [%x][%x][%x][%x][%x][%x][%x][%x][%x][%x]",
- __func__, gfa_rcv_str[4], gfa_rcv_str[5],
- gfa_rcv_str[6], gfa_rcv_str[7],
- gfa_rcv_str[8], gfa_rcv_str[9],
- gfa_rcv_str[10], gfa_rcv_str[11],
- gfa_rcv_str[12], gfa_rcv_str[13]);
- FELICA_PR_DBG(
- " %s Rcv data2 [%x][%x][%x][%x][%x][%x][%x][%x][%x][%x]",
- __func__, gfa_rcv_str[14], gfa_rcv_str[15],
- gfa_rcv_str[16], gfa_rcv_str[17],
- gfa_rcv_str[18], gfa_rcv_str[19],
- gfa_rcv_str[20], gfa_rcv_str[21],
- gfa_rcv_str[22], gfa_rcv_str[23]);
- FELICA_PR_DBG(
- " %s Rcv data3 [%x][%x][%x][%x][%x][%x][%x][%x][%x][%x]",
- __func__, gfa_rcv_str[24], gfa_rcv_str[25],
- gfa_rcv_str[26], gfa_rcv_str[27],
- gfa_rcv_str[28], gfa_rcv_str[29],
- gfa_rcv_str[30], gfa_rcv_str[31],
- gfa_rcv_str[32], gfa_rcv_str[33]);
- ret = copy_to_user(buf, &gfa_rcv_str[4], wk_len);
- if (ret != 0) {
- FELICA_PR_ERR
- ("%s ERROR(copy_from_user), ret=[%d]",
- __func__, ret);
- up(&dev_sem->felica_sem);
- return -EFAULT;
- }
- *ppos = *ppos + wk_len;
- } else {
- FELICA_PR_ERR(" %s FAIL", __func__);
- up(&dev_sem->felica_sem);
- return -EFAULT;
- }
- } else {
- FELICA_PR_ERR(" %s FAIL", __func__);
- up(&dev_sem->felica_sem);
- return -EFAULT;
- }
- up(&dev_sem->felica_sem);
- FELICA_PR_DBG(" %s END", __func__);
- return (ssize_t) wk_len;
- }
- /*
- * write operation
- */
- static ssize_t felica_uart_write(struct file *file, const char __user *data,
- size_t len, loff_t *ppos)
- {
- int ret = 0;
- int nlret;
- size_t wk_len = 0;
- FELICA_PR_DBG(" %s START", __func__);
- if (down_interruptible(&dev_sem->felica_sem)) {
- FELICA_PR_ERR(" %s ERROR(down_interruptible)", \
- __func__);
- return -ERESTARTSYS;
- }
- memset(gfa_send_str, 0, FELICA_NL_MSG_SIZE);
- memset(gfa_rcv_str, 0, FELICA_NL_MSG_SIZE);
- wk_len = len;
- if (FELICA_NL_MSG_DATA_SIZE < wk_len) {
- FELICA_PR_INFO(" %s read max size over [%d]", __func__,
- wk_len);
- wk_len = FELICA_NL_MSG_DATA_SIZE;
- }
- gfa_send_str[0] = FELICA_NL_REQ_WRITE;
- gfa_send_str[1] = (char)(wk_len >> 8);
- gfa_send_str[2] = (char)wk_len;
- ret = copy_from_user(&gfa_send_str[3], data, wk_len);
- if (ret != 0) {
- FELICA_PR_ERR(" %s ERROR(copy_from_user), ret=[%d]",
- __func__, ret);
- up(&dev_sem->felica_sem);
- return -EFAULT;
- }
- nlret = felica_nl_send_msg(3 + len);
- if (nlret == 0) {
- wk_len = 0;
- felica_nl_wait_ret_msg();
- wk_len = (((int)gfa_rcv_str[2] << 8) & 0xFF00) | \
- (int)gfa_rcv_str[3];
- if (gfa_rcv_str[1] == FELICA_NL_EFAILED) {
- FELICA_PR_ERR(" %s Write Fail", __func__);
- up(&dev_sem->felica_sem);
- return -EINVAL;
- }
- } else {
- FELICA_PR_ERR(" %s felica_nl_send_msg Fail", __func__);
- up(&dev_sem->felica_sem);
- return -EINVAL;
- }
- up(&dev_sem->felica_sem);
- FELICA_PR_DBG(" %s END", __func__);
- return wk_len;
- }
- /*
- * sync operation
- */
- static int felica_uart_sync(struct file *file, loff_t start,
- loff_t len, int datasync)
- {
- FELICA_PR_DBG(" %s START", __func__);
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * available operation
- */
- static long felica_uart_ioctl(struct file *file, unsigned int cmd,
- unsigned long arg)
- {
- unsigned int ret_str = 0;
- int ret;
- FELICA_PR_DBG(" %s START", __func__);
- FELICA_PR_INFO(" %s cmd = [0x%x]", __func__, cmd);
- /* Ignore [TCGETS:0x5401] and [TCSBRK:0x5409] */
- if (TCGETS == cmd || TCSBRK == cmd) {
- FELICA_PR_INFO(" %s cmd throw [0x%x]", __func__, cmd);
- return 0;
- }
- if (down_interruptible(&dev_sem->felica_sem)) {
- FELICA_PR_ERR(" %s ERROR(down_interruptible)", \
- __func__);
- return -ERESTARTSYS;
- }
- memset(gfa_send_str, 0, FELICA_NL_MSG_SIZE);
- memset(gfa_rcv_str, 0, FELICA_NL_MSG_SIZE);
- gfa_send_str[0] = FELICA_NL_REQ_AVAIABLE;
- ret = felica_nl_send_msg(1);
- if (ret == 0) {
- /* 20130216 add for APQ support -S- */
- /* 1ms sleep */
- usleep_range(1000, 1000);
- /* 20130216 add for APQ support -E- */
- felica_nl_wait_ret_msg();
- if (gfa_rcv_str[1] == FELICA_NL_SUCCESS) {
- /* create response data */
- ret_str =
- (((unsigned int)gfa_rcv_str[2] << 8) & 0xFF00) | \
- (unsigned int)gfa_rcv_str[3];
- FELICA_PR_INFO(" Available Success data size [%d]", \
- ret_str);
- } else {
- FELICA_PR_ERR(" %s Available Fail", __func__);
- up(&dev_sem->felica_sem);
- return -EINVAL;
- }
- } else {
- FELICA_PR_ERR(" %s felica_nl_send_msg Fail", __func__);
- up(&dev_sem->felica_sem);
- return -EINVAL;
- }
- up(&dev_sem->felica_sem);
- FELICA_PR_DBG(" %s END", __func__);
- return put_user(ret_str, (unsigned int __user *)arg);
- }
- /*
- * create netlink socket
- */
- static void felica_nl_init(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- gfa_connect_flag = 0;
- gfa_pid = 0;
- gfa_wait_flag = 0;
- memset(gfa_send_str, 0, FELICA_NL_MSG_SIZE);
- memset(gfa_rcv_str, 0, FELICA_NL_MSG_SIZE);
- gfanl_sk =
- netlink_kernel_create(&init_net, FELICA_NL_NETLINK_USER, 0,
- felica_nl_recv_msg, NULL, THIS_MODULE);
- if (!gfanl_sk)
- FELICA_PR_ERR(" Error creating socket. %s\n", __func__);
- FELICA_PR_DBG(" %s END", __func__);
- }
- /*
- * release netlink socket
- */
- static void felica_nl_exit(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- netlink_kernel_release(gfanl_sk);
- FELICA_PR_DBG(" %s END", __func__);
- }
- /*
- * send message to FeliCa-Serial-Connector
- */
- static int felica_nl_send_msg(int len)
- {
- struct nlmsghdr *nlh;
- struct sk_buff *skb_out;
- int msg_size = 0;
- FELICA_PR_DBG(" %s START len: %d", __func__,len);
- if (!gfanl_sk) {
- FELICA_PR_ERR("Error Not creating socket. %s\n",
- __func__);
- return 1;
- }
- if (gfa_pid == 0) {
- FELICA_PR_ERR("Error Not Rcv Connect Msg %s\n",
- __func__);
- return 1;
- }
- msg_size = len;
- skb_out = nlmsg_new(msg_size, 0);
- if (!skb_out) {
- FELICA_PR_ERR(" Failed to allocate new skb_out %s\n", __func__);
- return 1;
- }
- nlh = nlmsg_put(skb_out, 0, 0, NLMSG_DONE, msg_size, 0);
- NETLINK_CB(skb_out).dst_group = 0;
- memcpy(NLMSG_DATA(nlh), gfa_send_str, msg_size);
- /* "skb_out" will release by netlink.*/
- nlmsg_unicast(gfanl_sk, skb_out, gfa_pid);
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * receive message from FeliCa-Serial-Connector
- */
- static void felica_nl_recv_msg(struct sk_buff *skb)
- {
- struct nlmsghdr *nlh;
- struct sk_buff *wskb;
- #ifdef FELICA_UICC_FUNCTION
- int init_flag = 0;
- #endif
- if (!skb) {
- FELICA_PR_ERR(" %s ERROR(skb NULL)", __func__);
- return;
- }
- wskb = skb_get(skb);
- if (wskb && (wskb->len > NLMSG_SPACE(0))) {
- nlh = nlmsg_hdr(wskb);
- memcpy(gfa_rcv_str, NLMSG_DATA(nlh), sizeof(gfa_rcv_str));
- FELICA_PR_DBG(" %s START gfa_rcv_str[0]: 0x%x", __func__,gfa_rcv_str[0]);
- if ((gfa_rcv_str[0] == FELICA_NL_CONNECT_MSG)
- && (gfa_connect_flag == 0)) {
- /* pid of sending process */
- gfa_pid = nlh->nlmsg_pid;
- if (felica_get_tamper_fuse_cmd() != 1)
- {
- /* jmodel */
- #if defined(CONFIG_ARCH_EXYNOS)
- s3c_gpio_cfgall_range(FELICA_UART1RX, 2,\
- S3C_GPIO_SFN(2), S3C_GPIO_PULL_DOWN);
- felica_uart_port = 1;
- #elif defined(CONFIG_ARCH_APQ8064)
- felica_uart_port = 2;
- #elif defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_SBM)
- felica_uart_port = 2;
- #elif defined(CONFIG_MACH_HLTEDCM) || defined(CONFIG_MACH_HLTEKDI) || defined(CONFIG_MACH_JS01LTEDCM)
- felica_uart_port = 1;
- #endif
- felica_set_felica_info();
- felica_uart_init();
- felica_pon_init();
- felica_cen_init();
- felica_rfs_init();
- felica_rws_init();
- felica_ant_init();
- #ifdef CONFIG_NFC_FELICA
- snfc_uart_init();
- cxd2235power_init();
- hsel_init();
- snfc_rfs_init();
- available_poll_init();
- snfc_cen_init();
- #endif
- if (gdiag_name[0] != 0x00)
- felica_uid_init();
- }
- gfa_connect_flag = 1;
- #ifdef FELICA_UICC_FUNCTION
- init_flag = 1;
- guartcc_felica_status = UARTCC_FELICA_STATAUS_IN_INIT;
- FELICA_PR_INFO(" RCV MSG [%d]", gfa_rcv_str[0]);
- #endif
- } else if ((gfa_rcv_str[0] == FELICA_NL_RESPONCE)
- && (gfa_pid == nlh->nlmsg_pid)) {
- /* wake up */
- gfa_wait_flag = 1;
- #ifdef FELICA_UICC_FUNCTION
- } else if ((gfa_rcv_str[0] == FELICA_INIT_UICC_END)
- && (gfa_pid == nlh->nlmsg_pid)) {
- FELICA_PR_INFO("RCV MSG FELICA_INIT_UICC_END [%d]",
- gfa_rcv_str[0]);
- if (gfa_rcv_str[1] == FELICA_NL_SUCCESS)
- FELICA_PR_INFO("UICC INIT END SUCCESS");
- else
- FELICA_PR_INFO("UICC INIT END FAIL");
- guartcc_felica_status = UARTCC_FELICA_STATAUS_IDLE;
- #endif
- } else {
- FELICA_PR_ERR(" %s ERROR(RCV Undefine MSG) RCV MSG [%d], rcv pid [%d], gfa_pid [%d]",
- __func__, gfa_rcv_str[0],nlh->nlmsg_pid,gfa_pid);
- }
- }
- kfree_skb(skb);
- #ifdef FELICA_UICC_FUNCTION
- if (init_flag) {
- FELICA_PR_INFO("UICC INIT START");
- memset(gfa_send_str, 0, FELICA_NL_MSG_SIZE);
- memset(gfa_rcv_str, 0, FELICA_NL_MSG_SIZE);
- gfa_send_str[0] = FELICA_NL_INIT_END_RES;
- felica_nl_send_msg(1);
- }
- #endif
- FELICA_PR_DBG(" %s END", __func__);
- }
- static void felica_set_felica_info(void)
- {
- FELICA_PR_DBG(" %s START ", __func__);
- memset(gdiag_name, 0x00, DIAG_NAME_MAXSIZE + 1);
- #ifdef FELICA_UICC_FUNCTION
- memset(gproc_name, 0x00, PROC_NAME_MAXSIZE + 1);
- #endif
- gread_msgs[0].flags = gfa_rcv_str[MSG_READ1_FLAGS_OFFSET];
- gread_msgs[0].len = gfa_rcv_str[MSG_READ1_LEN_OFFSET];
- gread_msgs[1].flags = gfa_rcv_str[MSG_READ2_FLAGS_OFFSET];
- gread_msgs[1].len = gfa_rcv_str[MSG_READ2_LEN_OFFSET];
- gwrite_msgs[0].flags = gfa_rcv_str[MSG_WRITE_FLAGS_OFFSET];
- gwrite_msgs[0].len = gfa_rcv_str[MSG_WRITE_LEN_OFFSET];
- gi2c_lockaddress = gfa_rcv_str[MSG_LOCK_ADDR_OFFSET];
- gi2c_address = gfa_rcv_str[MSG_I2C_ADDR_OFFSET];
- memcpy(gdiag_name, &gfa_rcv_str[MSG_DIAG_NAME_OFFSET],
- DIAG_NAME_MAXSIZE);
- gmfc_uid =
- (((int)gfa_rcv_str[MSG_MFC_UID_FRONT_OFFSET] << 8) & 0xFF00) |
- (int)gfa_rcv_str[MSG_MFC_UID_BACK_OFFSET];
- gmfl_uid =
- (((int)gfa_rcv_str[MSG_MFL_UID_FRONT_OFFSET] << 8) & 0xFF00) |
- (int)gfa_rcv_str[MSG_MFL_UID_BACK_OFFSET];
- gi2c_antaddress = gfa_rcv_str[MSG_ANT_ADDR_OFFSET];
- gant_uid =
- (((int)gfa_rcv_str[MSG_ANT_UID_FRONT_OFFSET] << 8) & 0xFF00) |
- (int)gfa_rcv_str[MSG_ANT_UID_BACK_OFFSET];
- #ifdef CONFIG_NFC_FELICA
- gnfc_uid =
- (((int)gfa_rcv_str[MSG_NFC_UID_FRONT_OFFSET] << 8) & 0xFF00) |
- (int)gfa_rcv_str[MSG_NFC_UID_BACK_OFFSET];
- snfc_cen_sts_init();
- #endif
- #ifdef FELICA_UICC_FUNCTION
- memcpy(gproc_name, &gfa_rcv_str[MSG_PROC_NAME_OFFSET],
- PROC_NAME_MAXSIZE);
- #endif
- FELICA_PR_DBG(" %s END", __func__);
- }
- /*
- * waiting to receive messages from FeliCa-Serial-Connector
- */
- static void felica_nl_wait_ret_msg(void)
- {
- unsigned int cnt = 0;
- FELICA_PR_DBG(" %s START ", __func__);
- while (1) {
- if (gfa_wait_flag == 1) {
- FELICA_PR_DBG(" %s sleep cnt [%d]", __func__,
- cnt);
- break;
- }
- mdelay(1);
- cnt++;
- }
- gfa_wait_flag = 0;
- FELICA_PR_DBG(" %s END ", __func__);
- }
- #if defined(CONFIG_ARCH_EXYNOS)
- static int felica_smc_read_oemflag(u32 ctrl_word, u32 *val)
- {
- register u32 reg0 __asm__("r0");
- register u32 reg1 __asm__("r1");
- register u32 reg2 __asm__("r2");
- register u32 reg3 __asm__("r3");
- u32 idx = 0;
- for (idx = 0; reg2 != ctrl_word; idx++) {
- reg0 = -202;
- reg1 = 1;
- reg2 = idx;
- __asm__ volatile ("smc 0\n" : "+r" (reg0), "+r"(reg1),
- "+r"(reg2), "+r"(reg3)
- );
- if (reg1)
- return -1;
- }
- reg0 = -202;
- reg1 = 1;
- reg2 = idx;
- __asm__ volatile ("smc 0\n" : "+r" (reg0), "+r"(reg1),
- "+r"(reg2), "+r"(reg3)
- );
- if (reg1)
- return -1;
- *val = reg2;
- return 0;
- }
- static int felica_Cpu0(void)
- {
- int ret = 0;
- struct cpumask mask = CPU_MASK_CPU0;
- FELICA_PR_INFO(" System has %d CPU's, we are on CPU #%d\n"
- "\tBinding this process to CPU #0.\n"
- "\tactive mask is %lx, setting it to mask=%lx\n",
- nr_cpu_ids,
- raw_smp_processor_id(), cpu_active_mask->bits[0], mask.bits[0]);
- ret = set_cpus_allowed_ptr(current, &mask);
- if (0 != ret)
- FELICA_PR_INFO(" set_cpus_allowed_ptr=%d.\n", ret);
- FELICA_PR_INFO(" And now we are on CPU #%d", raw_smp_processor_id());
- return ret;
- }
- static int felica_CpuAll(void)
- {
- int ret = 0;
- struct cpumask mask = CPU_MASK_ALL;
- FELICA_PR_INFO(" System has %d CPU's, we are on CPU #%d\n"
- "\tBinding this process to CPU #0.\n"
- "\tactive mask is %lx, setting it to mask=%lx\n",
- nr_cpu_ids,
- raw_smp_processor_id(), cpu_active_mask->bits[0], mask.bits[0]);
- ret = set_cpus_allowed_ptr(current, &mask);
- if (0 != ret)
- FELICA_PR_INFO(" set_cpus_allowed_ptr=%d.\n", ret);
- FELICA_PR_INFO(" And now we are on CPU #%d", raw_smp_processor_id());
- return ret;
- }
- static uint8_t felica_get_tamper_fuse_cmd(void)
- {
- u32 fuse_id = 0;
- int ret;
- ret = felica_Cpu0();
- if (0 != ret) {
- FELICA_PR_ERR(" changing core failed!");
- return -1;
- }
- FELICA_PR_INFO(" get_fuse");
- if (felica_smc_read_oemflag(0x80010001, (u32 *)&fuse_id) < 0) {
- FELICA_PR_ERR(" %s read flag error", __func__);
- return -1;
- }
- FELICA_PR_INFO(" Kernel Status[%x]", fuse_id);
- felica_CpuAll();
- return (uint8_t)fuse_id;
- }
- #elif defined(CONFIG_ARCH_APQ8064) || defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- static uint8_t felica_get_tamper_fuse_cmd(void)
- {
- uint32_t fuse_id = FELICA_HLOS_IMG_TAMPER_FUSE;
- void *cmd_buf;
- size_t cmd_len;
- size_t resp_len = 0;
- uint8_t resp_buf;
- FELICA_PR_DBG(" %s START ", __func__);
- resp_len = sizeof(resp_buf);
- cmd_buf = (void *)&fuse_id;
- cmd_len = sizeof(fuse_id);
- scm_call(FELICA_SCM_SVC_FUSE, FELICA_SCM_IS_SW_FUSE_BLOWN_ID, cmd_buf,
- cmd_len, &resp_buf, resp_len);
- FELICA_PR_DBG(" %s END resp_buf = %d\n",__func__, resp_buf);
-
- #ifdef NO_CHECK_TAMPER
- FELICA_PR_ERR(" No checking tampered kernel just for test!\n");
- return 0;
- #endif
- return resp_buf;
- }
- #endif
- /******************************************************************************
- * /dev/felica_pon
- *****************************************************************************/
- /* character device definition */
- static dev_t devid_felica_pon;
- static struct cdev cdev_felica_pon;
- static const struct file_operations fops_felica_pon = {
- .owner = THIS_MODULE,
- .open = felica_pon_open,
- .release = felica_pon_close,
- .read = felica_pon_read,
- .write = felica_pon_write,
- };
- /*
- * initialize device
- */
- static void felica_pon_init(void)
- {
- int ret;
- struct device *device_felica_pon;
- FELICA_PR_DBG(" %s START", __func__);
-
- devid_felica_pon = MKDEV(FELICA_MAJOR, FELICA_MINOR);
- ret =
- alloc_chrdev_region(&devid_felica_pon, FELICA_BASEMINOR,
- FELICA_MINOR_COUNT, FELICA_PON_NAME);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
- __func__, ret);
- return;
- }
- cdev_init(&cdev_felica_pon, &fops_felica_pon);
- ret = cdev_add(&cdev_felica_pon, devid_felica_pon, FELICA_MINOR_COUNT);
- if (ret < 0) {
- unregister_chrdev_region(devid_felica_pon, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
- ret);
- return;
- }
- device_felica_pon =
- device_create(felica_class, NULL, devid_felica_pon, NULL,
- FELICA_PON_NAME);
- if (IS_ERR(device_felica_pon)) {
- cdev_del(&cdev_felica_pon);
- unregister_chrdev_region(devid_felica_pon, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
- return;
- }
- FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
- MAJOR(devid_felica_pon), MINOR(devid_felica_pon));
- }
- /*
- * finalize device
- */
- static void felica_pon_exit(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- device_destroy(felica_class, devid_felica_pon);
- cdev_del(&cdev_felica_pon);
- unregister_chrdev_region(devid_felica_pon, FELICA_MINOR_COUNT);
- FELICA_PR_DBG(" %s START", __func__);
- }
- /*
- * open device
- */
- static int felica_pon_open(struct inode *inode, struct file *file)
- {
- uid_t uid;
- #ifdef FELICA_UICC_FUNCTION
- int ret = 0;
- char *cmdpos;
- static char cmdline[1025];
- static unsigned long start_adr, end_adr, leng;
- #endif
- #ifdef FELICA_UICC_FUNCTION
- start_adr = current->mm->arg_start;
- end_adr = current->mm->arg_end;
- leng = end_adr - start_adr;
- if (1024 < leng)
- leng = 1024;
- cmdpos = (char *)(current->mm->arg_start);
- ret = copy_from_user(cmdline, cmdpos, leng);
- cmdline[leng] = '\0';
- if(ret != 0)
- {
- FELICA_PR_ERR(" %s cmdline[%s] ret[%d]", __func__, cmdline, ret);
- return -EFAULT;
- }
- #endif
- uid = __task_cred(current)->uid;
- #ifdef FELICA_UICC_FUNCTION
- if (((uid != gmfc_uid) && (uid != gdiag_uid)
- && (uid != gant_uid)) &&
- (strncmp(cmdline,gproc_name, leng) != 0)) {
- #else
- if ((uid != gmfc_uid) && (uid != gdiag_uid)
- && (uid != gant_uid)) {
- #endif
- FELICA_PR_ERR
- (" %s END -EACCES, uid=[%d], gmfc_uid=[%d], gdiag_uid=[%d]",
- __func__, uid, gmfc_uid, gdiag_uid);
- #ifdef SRIB_DIAG_ENABLED
- FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
- #else
- return -EACCES;
- #endif
- }
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * close device
- */
- static int felica_pon_close(struct inode *inode, struct file *file)
- {
- #if defined(CONFIG_ARCH_EXYNOS)
- gpio_set_value(GPIO_PINID_FELICA_PON, GPIO_VALUE_LOW);
- #elif defined(CONFIG_ARCH_APQ8064)
- ice_gpiox_set(GPIO_PINID_FELICA_PON, GPIO_VALUE_LOW);
- #elif defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
- gpio_set_value(gfelica_pon_pin, GPIO_VALUE_LOW);
- #else
- gpio_set_value(GPIO_PINID_FELICA_PON, GPIO_VALUE_LOW);
- #endif // CONFIG_MACH_KLTE
- #endif
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * read operation
- */
- static ssize_t felica_pon_read(struct file *file, char __user *buf, size_t len,
- loff_t *ppos)
- {
- int ret;
- char retparam;
- #if defined(CONFIG_ARCH_EXYNOS)
- ret = gpio_get_value(GPIO_PINID_FELICA_PON);
- #elif defined(CONFIG_ARCH_APQ8064)
- ret = ice_gpiox_get(GPIO_PINID_FELICA_PON);
- #elif defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
- ret = gpio_get_value(gfelica_pon_pin);
- #else
- ret = gpio_get_value(GPIO_PINID_FELICA_PON);
- #endif // CONFIG_MACH_KLTE
- #endif
- FELICA_PR_INFO(" %s GPIO Read value of GPIO_PINID_FELICA_PON -> ret=[%d]", __func__,ret);
- if (ret == GPIO_VALUE_HIGH) {
- retparam = FELICA_PON_WIRED;
- FELICA_PR_INFO(" Wired interface Status is [%d][start]",
- retparam);
- } else if (ret == GPIO_VALUE_LOW) {
- retparam = FELICA_PON_WIRELESS;
- FELICA_PR_INFO(" Wired interface Status is [%d][standby]",
- retparam);
- } else {
- FELICA_PR_ERR(" %s ERROR(gpio_get_value), ret=[%d]",
- __func__, ret);
- return -EIO;
- }
- ret = copy_to_user(buf, &retparam, FELICA_PON_DATA_LEN);
- if (ret != 0) {
- FELICA_PR_ERR(" %s ERROR(copy_to_user), ret=[%d]",
- __func__, ret);
- return -EFAULT;
- }
- *ppos += 1;
- return FELICA_PON_DATA_LEN;
- }
- /*
- * write operation
- */
- static ssize_t felica_pon_write(struct file *file, const char __user *data,
- size_t len, loff_t *ppos)
- {
- char pon;
- int ret;
- int setparam;
- ret = copy_from_user(&pon, data, FELICA_PON_DATA_LEN);
- if (ret != 0) {
- FELICA_PR_ERR(" %s ERROR(copy_from_user), ret=[%d]",
- __func__, ret);
- return -EFAULT;
- }
- if (pon == FELICA_PON_WIRED) {
- setparam = GPIO_VALUE_HIGH;
- FELICA_PR_INFO(" Set wired interface to [%d][start]",
- setparam);
- } else if (pon == FELICA_PON_WIRELESS) {
- setparam = GPIO_VALUE_LOW;
- FELICA_PR_INFO(" Set wired interface to [%d][standby]",
- setparam);
- } else {
- FELICA_PR_ERR(" %s ERROR(copy_from_user), pon=[%d]",
- __func__, pon);
- return -EINVAL;
- }
- #if defined(CONFIG_ARCH_EXYNOS)
- gpio_set_value(GPIO_PINID_FELICA_PON, setparam);
- #elif defined(CONFIG_ARCH_APQ8064)
- ice_gpiox_set(GPIO_PINID_FELICA_PON, setparam);
- #elif defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- #if defined(CONFIG_MACH_KLTE_KDI)
- if(gfelica_uim_mon == 1) {
- FELICA_PR_ERR(" %s gfelica_uim_mon=%d\n", __func__, gfelica_uim_mon);
- gpio_set_value(gfelica_pon_pin, GPIO_VALUE_HIGH);
- return FELICA_PON_DATA_LEN;
- }
- gpio_set_value(gfelica_pon_pin, setparam);
- #elif defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
- gpio_set_value(gfelica_pon_pin, setparam);
- #else
- gpio_set_value(GPIO_PINID_FELICA_PON, setparam);
- #endif // CONFIG_MACH_KLTE
- #endif
- return FELICA_PON_DATA_LEN;
- }
- /******************************************************************************
- * felica_i2c_driver
- ******************************************************************************/
- static struct i2c_client *felica_i2c_client;
- static const struct i2c_device_id felica_i2c_idtable[] =
- {
- {FELICA_I2C_NAME, 0},
- {}
- };
- MODULE_DEVICE_TABLE(i2c, felica_i2c_idtable);
- #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- static struct of_device_id felica_i2c_match_table[] =
- {
- { .compatible = "felica,felica-i2c",},
- {},
- };
- #endif
- static struct i2c_driver felica_i2c_driver =
- {
- .probe = felica_i2c_probe,
- .remove = felica_i2c_remove,
- .driver =
- {
- .name = FELICA_I2C_NAME,
- .owner = THIS_MODULE,
- #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- .of_match_table = felica_i2c_match_table,
- #endif
- },
- .id_table = felica_i2c_idtable,
- };
- /*
- * felica_i2c_init
- */
- static void felica_i2c_init(void)
- {
- int ret;
- FELICA_PR_DBG(" %s START", __func__);
- ret = i2c_add_driver(&felica_i2c_driver);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(i2c_add_driver), ret=[%d]",
- __func__, ret);
- return;
- }
- FELICA_PR_DBG(" %s END", __func__);
- return;
- }
- /*
- * felica_i2c_exit
- */
- static void felica_i2c_exit(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- i2c_del_driver(&felica_i2c_driver);
- FELICA_PR_DBG(" %s END", __func__);
- return;
- }
- /*
- * probe device
- */
- static int felica_i2c_probe(struct i2c_client *client,
- const struct i2c_device_id *devid)
- {
- FELICA_PR_INFO(" %s START", __func__);
- felica_i2c_client = client;
- if (!felica_i2c_client) {
- FELICA_PR_ERR(" %s ERROR(felica_i2c_client==NULL)", \
- __func__);
- return -EINVAL;
- }
- FELICA_PR_INFO(" %s END", __func__);
- return 0;
- }
- /*
- * remove device
- */
- static int felica_i2c_remove(struct i2c_client *client)
- {
- /* no operation */
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /******************************************************************************
- * /dev/felica_cen
- ******************************************************************************/
- /* character device definition */
- static dev_t devid_felica_cen;
- static struct cdev cdev_felica_cen;
- static const struct file_operations fops_felica_cen = {
- .owner = THIS_MODULE,
- .open = felica_cen_open,
- .release = felica_cen_close,
- .read = felica_cen_read,
- .write = felica_cen_write,
- };
- /*
- * felica_cen_init
- */
- static void felica_cen_init(void)
- {
- int ret;
- struct device *device_felica_cen;
- FELICA_PR_DBG(" %s START", __func__);
- devid_felica_cen = MKDEV(FELICA_MAJOR, FELICA_MINOR);
- ret =
- alloc_chrdev_region(&devid_felica_cen, FELICA_BASEMINOR,
- FELICA_MINOR_COUNT, FELICA_CEN_NAME);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
- __func__, ret);
- return;
- }
- cdev_init(&cdev_felica_cen, &fops_felica_cen);
- ret = cdev_add(&cdev_felica_cen, devid_felica_cen, FELICA_MINOR_COUNT);
- if (ret < 0) {
- unregister_chrdev_region(devid_felica_cen, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
- ret);
- return;
- }
- device_felica_cen =
- device_create(felica_class, NULL, devid_felica_cen, NULL,
- FELICA_CEN_NAME);
- if (IS_ERR(device_felica_cen)) {
- cdev_del(&cdev_felica_cen);
- unregister_chrdev_region(devid_felica_cen, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
- return;
- }
- FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
- MAJOR(devid_felica_cen), MINOR(devid_felica_cen));
- }
- /*
- * felica_cen_exit
- */
- static void felica_cen_exit(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- device_destroy(felica_class, devid_felica_cen);
- cdev_del(&cdev_felica_cen);
- unregister_chrdev_region(devid_felica_cen, FELICA_MINOR_COUNT);
- FELICA_PR_DBG(" %s END", __func__);
- }
- /*
- * open device
- */
- static int felica_cen_open(struct inode *inode, struct file *file)
- {
- uid_t uid;
- #ifdef FELICA_UICC_FUNCTION
- int ret = 0;
- char *cmdpos;
- static char cmdline[1025];
- static unsigned long start_adr, end_adr, leng;
- #endif
- FELICA_PR_DBG(" %s START . system_rev=[%d]", __func__,system_rev);
- #if defined(CONFIG_MACH_HLTEDCM)
- //high
- if (system_rev == HW_REV09_OR_10)
- {
- FELICA_PR_INFO(" %s Making MHL_EN HIGH", __func__);
- of_sii8240_hw_poweron(FELICA_CEN_UNLOCK);
- }
- #endif
-
- #ifdef FELICA_UICC_FUNCTION
- start_adr = current->mm->arg_start;
- end_adr = current->mm->arg_end;
- leng = end_adr - start_adr;
- if (1024 < leng)
- leng = 1024;
- cmdpos = (char *)(current->mm->arg_start);
- ret = copy_from_user(cmdline, cmdpos, leng);
- cmdline[leng] = '\0';
- if(ret != 0)
- {
- FELICA_PR_ERR(" %s cmdline[%s] ret[%d]", __func__, cmdline, ret);
- return -EFAULT;
- }
- #endif
- uid = __task_cred(current)->uid;
- if (file->f_mode & FMODE_WRITE) {
- #ifdef FELICA_UICC_FUNCTION
- if ((uid != gdiag_uid) && (uid != gmfl_uid)
- && (strncmp(cmdline,gproc_name, leng) != 0)) {
- #else
- if ((uid != gdiag_uid) && (uid != gmfl_uid)) {
- #endif
- 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);
-
- #if defined(CONFIG_MACH_HLTEDCM)
- //low
- if (system_rev == HW_REV09_OR_10)
- {
- FELICA_PR_INFO(" %s Making MHL_EN LOW", __func__);
- // of_sii8240_hw_poweron(FELICA_CEN_LOCK);
- }
- #endif
-
- #ifdef SRIB_DIAG_ENABLED
- FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
- #else
- return -EACCES;
- #endif
- }
- }
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * close device
- */
- static int felica_cen_close(struct inode *inode, struct file *file)
- {
- /* no operation */
- #if defined(CONFIG_MACH_HLTEDCM)
- //low
- if (system_rev == HW_REV09_OR_10)
- {
- FELICA_PR_INFO(" %s Making MHL_EN LOW", __func__);
- // of_sii8240_hw_poweron(FELICA_CEN_LOCK);
- }
- #endif
-
- FELICA_PR_DBG(" %s END system_rev=[%d]", __func__,system_rev);
- return 0;
- }
- /*
- * read operation
- */
- static ssize_t felica_cen_read(struct file *file, char __user *buf, \
- size_t len, loff_t *ppos)
- {
- int ret;
- unsigned char address = gi2c_lockaddress;
- unsigned char read_buff = 0;
- struct i2c_msg read_msgs[2];
- read_msgs[0].flags = gread_msgs[0].flags;
- read_msgs[0].len = gread_msgs[0].len;
- read_msgs[1].flags = gread_msgs[1].flags;
- read_msgs[1].len = gread_msgs[1].len;
- read_msgs[0].addr = gi2c_address;
- read_msgs[0].buf = &address;
- read_msgs[1].addr = gi2c_address;
- read_msgs[1].buf = &read_buff;
- if (felica_i2c_client == NULL) {
- FELICA_PR_ERR(" felica_i2c_client is NULL %s -EIO",__func__);
- return -EIO;
- }
- ret = i2c_transfer(felica_i2c_client->adapter, &read_msgs[0], 1);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(i2c_transfer[0]), ret=[%d]",
- __func__, ret);
- return -EIO;
- }
- ret = i2c_transfer(felica_i2c_client->adapter, &read_msgs[1], 1);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(i2c_transfer[1]), ret=[%d]",
- __func__, ret);
- return -EIO;
- }
- read_buff &= FELICA_CONTROL_LOCK_MASK;
- #ifdef CONFIG_NFC_FELICA
- g_cen_sts = read_buff;
- #endif
- FELICA_PR_INFO(" %s g_cen_sts=[%d]", __func__, g_cen_sts);
- ret = copy_to_user(buf, &read_buff, FELICA_CEN_DATA_LEN);
- if (ret != 0) {
- FELICA_PR_ERR(" %s ERROR(copy_to_user), ret=[%d]",
- __func__, ret);
- return -EFAULT;
- }
- *ppos += 1;
- return FELICA_CEN_DATA_LEN;
- }
- /*
- * write operation
- */
- static ssize_t felica_cen_write(struct file *file, const char __user *data,
- size_t len, loff_t *ppos)
- {
- char cen;
- int ret;
- unsigned char write_buff[2];
- if (felica_i2c_client == NULL) {
- FELICA_PR_ERR(" felica_i2c_client is NULL %s",__func__);
- return -EIO;
- }
- gwrite_msgs[0].buf = &write_buff[0];
- gwrite_msgs[0].addr = gi2c_address;
- write_buff[0] = gi2c_lockaddress;
- ret = copy_from_user(&cen, data, FELICA_CEN_DATA_LEN);
- if (ret != 0) {
- FELICA_PR_ERR(" %s ERROR(copy_from_user), ret=[%d]",
- __func__, ret);
- return -EFAULT;
- }
- if (cen == FELICA_CEN_UNLOCK) {
- write_buff[1] = FELICA_CEN_SET_UNLOCK;
- FELICA_PR_INFO(" Set FeliCa-Lock status to [%d][UnLock]",
- write_buff[1]);
- } else if (cen == FELICA_CEN_LOCK) {
- write_buff[1] = FELICA_CEN_SET_LOCK;
- FELICA_PR_INFO(" Set FeliCa-Lock status to [%d][Lock]",
- write_buff[1]);
- } else {
- FELICA_PR_ERR(" %s ERROR(copy_from_user), cen=[%d]",
- __func__, cen);
- return -EINVAL;
- }
- ret = i2c_transfer(felica_i2c_client->adapter, gwrite_msgs, 1);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(i2c_transfer), ret=[%d]",
- __func__, ret);
- return -EIO;
- }
- #ifdef CONFIG_NFC_FELICA
- g_cen_sts = cen;
- if (1 == available_d->available_flag) {
- if (0 != g_cen_sts) {
- if (GPIO_VALUE_LOW != g_rfs_sts) {
- if (0 == guartcc_felica_status) {
- available_d->rsp_done = 1;
- FELICA_PR_INFO(" wake up available");
- wake_up_interruptible(
- &available_d->read_wait);
- }
- }
- }
- }
- #endif
- FELICA_PR_INFO(" %s END, g_cen_sts =%d, g_rfs_sts = %d", __func__, g_cen_sts, g_rfs_sts);
- return FELICA_CEN_DATA_LEN;
- }
- /******************************************************************************
- * /dev/felica_rfs
- ******************************************************************************/
- /* character device definition */
- static dev_t devid_felica_rfs;
- static struct cdev cdev_felica_rfs;
- static const struct file_operations fops_felica_rfs = {
- .owner = THIS_MODULE,
- .open = felica_rfs_open,
- .release = felica_rfs_close,
- .read = felica_rfs_read,
- };
- /*
- * initialize device
- */
- static void felica_rfs_init(void)
- {
- int ret;
- struct device *device_felica_rfs;
- FELICA_PR_DBG(" %s START", __func__);
- devid_felica_rfs = MKDEV(FELICA_MAJOR, FELICA_MINOR);
- ret =
- alloc_chrdev_region(&devid_felica_rfs, FELICA_BASEMINOR,
- FELICA_MINOR_COUNT, FELICA_RFS_NAME);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
- __func__, ret);
- return;
- }
- cdev_init(&cdev_felica_rfs, &fops_felica_rfs);
- ret = cdev_add(&cdev_felica_rfs, devid_felica_rfs, FELICA_MINOR_COUNT);
- if (ret < 0) {
- unregister_chrdev_region(devid_felica_rfs, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
- ret);
- return;
- }
- device_felica_rfs =
- device_create(felica_class, NULL, devid_felica_rfs, NULL,
- FELICA_RFS_NAME);
- if (IS_ERR(device_felica_rfs)) {
- cdev_del(&cdev_felica_rfs);
- unregister_chrdev_region(devid_felica_rfs, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
- return;
- }
- FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
- MAJOR(devid_felica_rfs), MINOR(devid_felica_rfs));
- }
- /*
- * finalize device
- */
- static void felica_rfs_exit(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- device_destroy(felica_class, devid_felica_rfs);
- cdev_del(&cdev_felica_rfs);
- unregister_chrdev_region(devid_felica_rfs, FELICA_MINOR_COUNT);
- FELICA_PR_DBG(" %s START", __func__);
- }
- /*
- * open device
- */
- static int felica_rfs_open(struct inode *inode, struct file *file)
- {
- uid_t uid;
- uid = __task_cred(current)->uid;
- if ((uid != gmfc_uid) && (uid != gdiag_uid)) {
- FELICA_PR_ERR
- (" %s -EACCESS, uid=[%d], gmfc_uid=[%d], gdiag_uid=[%d]",
- __func__, uid, gmfc_uid, gdiag_uid);
- #ifdef SRIB_DIAG_ENABLED
- FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
- #else
- return -EACCES;
- #endif
- }
- FELICA_PR_DBG(" %s END, uid=[%d], gmfc_uid=[%d], gdiag_uid=[%d]", __func__, uid, gmfc_uid, gdiag_uid);
- return 0;
- }
- /*
- * close device
- */
- static int felica_rfs_close(struct inode *inode, struct file *file)
- {
- /* no operation */
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * read operation
- */
- static ssize_t felica_rfs_read(struct file *file, char __user *buf, \
- size_t len, loff_t *ppos)
- {
- int ret;
- char retparam;
- FELICA_PR_DBG(" %s START", __func__);
- ret = gpio_get_value(GPIO_PINID_FELICA_RFS);
- if (ret == GPIO_VALUE_HIGH) {
- retparam = FELICA_RFS_STANDBY;
- FELICA_PR_INFO(" Carrier-Wave Status is [%d][standby]",
- retparam);
- } else if (ret == GPIO_VALUE_LOW) {
- retparam = FELICA_RFS_DETECTED;
- FELICA_PR_INFO(" Carrier-Wave Status is [%d][detected]",
- retparam);
- } else {
- FELICA_PR_ERR(" %s ERROR(gpio_get_value), ret=[%d]",
- __func__, ret);
- return -EIO;
- }
- ret = copy_to_user(buf, &retparam, FELICA_RFS_DATA_LEN);
- if (ret != 0) {
- FELICA_PR_ERR(" %s ERROR(copy_to_user), ret=[%d]",
- __func__, ret);
- return -EFAULT;
- }
- *ppos += 1;
- FELICA_PR_DBG(" %s END", __func__);
- return FELICA_RFS_DATA_LEN;
- }
- /******************************************************************************
- * /dev/felica_rws
- ******************************************************************************/
- /* character device definition */
- static dev_t devid_felica_rws;
- static struct cdev cdev_felica_rws;
- static const struct file_operations fops_felica_rws = {
- .owner = THIS_MODULE,
- .open = felica_rws_open,
- .release = felica_rws_close,
- .read = felica_rws_read,
- .write = felica_rws_write,
- };
- /*
- * initialize device
- */
- static void felica_rws_init(void)
- {
- int ret;
- struct device *device_felica_rws;
- FELICA_PR_DBG(" %s START", __func__);
- devid_felica_rws = MKDEV(FELICA_MAJOR, FELICA_MINOR);
- ret =
- alloc_chrdev_region(&devid_felica_rws, FELICA_BASEMINOR,
- FELICA_MINOR_COUNT, FELICA_RWS_NAME);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
- __func__, ret);
- return;
- }
- cdev_init(&cdev_felica_rws, &fops_felica_rws);
- ret = cdev_add(&cdev_felica_rws, devid_felica_rws, FELICA_MINOR_COUNT);
- if (ret < 0) {
- unregister_chrdev_region(devid_felica_rws, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
- ret);
- return;
- }
- device_felica_rws =
- device_create(felica_class, NULL, devid_felica_rws, NULL,
- FELICA_RWS_NAME);
- if (IS_ERR(device_felica_rws)) {
- cdev_del(&cdev_felica_rws);
- unregister_chrdev_region(devid_felica_rws, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
- return;
- }
- gfelica_rw_status = FELICA_RW_STATUS_INIT;
- FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
- MAJOR(devid_felica_rws), MINOR(devid_felica_rws));
- }
- /*
- * finalize device
- */
- static void felica_rws_exit(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- device_destroy(felica_class, devid_felica_rws);
- cdev_del(&cdev_felica_rws);
- unregister_chrdev_region(devid_felica_rws, FELICA_MINOR_COUNT);
- }
- /*
- * open device
- */
- static int felica_rws_open(struct inode *inode, struct file *file)
- {
- uid_t uid;
- FELICA_PR_DBG(" %s START", __func__);
- uid = __task_cred(current)->uid;
- if (file->f_mode & FMODE_WRITE) {
- if (uid != grwm_uid) {
- FELICA_PR_ERR(\
- " %s END -EACCES, uid=[%d],gmfc_uid=[%d],gdiag_uid=[%d]",
- __func__, uid, gmfc_uid, gdiag_uid);
- #ifdef SRIB_DIAG_ENABLED
- FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
- #else
- return -EACCES;
- #endif
- }
- } else {
- if ((uid != gmfc_uid) && (uid != grwm_uid)) {
- FELICA_PR_ERR(\
- " %s END -EACCES, uid=[%d],gmfc_uid=[%d],gdiag_uid=[%d]",
- __func__, uid, gmfc_uid, gdiag_uid);
- #ifdef SRIB_DIAG_ENABLED
- FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
- #else
- return -EACCES;
- #endif
- }
- }
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * close device
- */
- static int felica_rws_close(struct inode *inode, struct file *file)
- {
- /* no operation */
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * read operation
- */
- static ssize_t felica_rws_read(struct file *file, char __user *buf, size_t len,
- loff_t *ppos)
- {
- int ret;
- char retparam;
- if (gfelica_rw_status == FELICA_RW_STATUS_ENABLE) {
- retparam = FELICA_RW_STATUS_ENABLE;
- FELICA_PR_INFO(" ReaderWriterFunction status is [%d][enabled] %s",
- retparam,__func__);
- } else if (gfelica_rw_status == FELICA_RW_STATUS_DISABLE) {
- retparam = FELICA_RW_STATUS_DISABLE;
- FELICA_PR_INFO
- (" ReaderWriterFunction status is [%d][disabled] %s", retparam,__func__);
- } else {
- FELICA_PR_ERR(" %s ERROR(gfelica_rw_status), RWM=[%d]",
- __func__, gfelica_rw_status);
- return -EIO;
- }
- ret = copy_to_user(buf, &retparam, FELICA_RWS_DATA_LEN);
- if (ret != 0) {
- FELICA_PR_ERR(" %s ERROR(copy_to_user), ret=[%d]",
- __func__, ret);
- return -EFAULT;
- }
- *ppos += 1;
- return FELICA_RWS_DATA_LEN;
- }
- /*
- * write operation
- */
- static ssize_t felica_rws_write(struct file *file, const char __user *data,
- size_t len, loff_t *ppos)
- {
- char work;
- int ret;
- FELICA_PR_DBG(" %s START", __func__);
- ret = copy_from_user(&work, data, FELICA_RWS_DATA_LEN);
- if (ret != 0) {
- FELICA_PR_ERR(" %s ERROR(copy_from_user), ret=[%d]",
- __func__, ret);
- return -EFAULT;
- }
- if (work == FELICA_RW_STATUS_ENABLE) {
- FELICA_PR_INFO
- ("Set ReaderWriterFunction status to [%d][enable]", work);
- } else if (work == FELICA_RW_STATUS_DISABLE) {
- FELICA_PR_INFO
- ("Set ReaderWriterFunction status to s[%d][disable]", work);
- } else {
- FELICA_PR_ERR(" %s ERROR(copy_from_user), work=[%d]",
- __func__, work);
- return -EINVAL;
- }
- gfelica_rw_status = work;
- FELICA_PR_DBG(" %s END", __func__);
- return FELICA_RWS_DATA_LEN;
- }
- /******************************************************************************
- * /dev/felica_int_poll
- ******************************************************************************/
- /* character device definition */
- static dev_t devid_felica_int_poll;
- static struct cdev cdev_felica_int_poll;
- static const struct file_operations fops_felica_int_poll = {
- .owner = THIS_MODULE,
- .open = felica_int_poll_open,
- .release = felica_int_poll_close,
- .read = felica_int_poll_read,
- .poll = felica_int_poll_poll,
- };
- /*
- * top half of irq_handler
- */
- static irqreturn_t felica_int_irq_handler(int irq, void *dev_id)
- {
- FELICA_PR_DBG(" %s START", __func__);
- #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
- disable_irq_nosync(gpio_to_irq(GPIO_PINID_FELICA_INT));
- #else
- disable_irq_nosync(gpio_to_irq(gfelica_irq_int_pin));
- #endif
- #else
- disable_irq_nosync(gpio_to_irq(GPIO_PINID_FELICA_INT_REV03));
- #endif /* CONFIG_ARCH_MSM8974 */
- schedule_delayed_work(&pgint_irq->work,
- msecs_to_jiffies(FELICA_INT_DELAY_TIME));
- FELICA_PR_DBG(" %s END", __func__);
- return IRQ_HANDLED;
- }
- /*
- * bottom half of irq_handler
- */
- static void felica_int_irq_work(struct work_struct *work)
- {
- FELICA_PR_DBG(" %s START", __func__);
- #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
- enable_irq(gpio_to_irq(GPIO_PINID_FELICA_INT));
- #else
- enable_irq(gpio_to_irq(gfelica_irq_int_pin));
- #endif // CONFIG_MACH_KLTE
- #else
- enable_irq(gpio_to_irq(GPIO_PINID_FELICA_INT_REV03));
- #endif /* CONFIG_ARCH_MSM8974 */
- pgint_irq->irq_done = 1;
- #ifdef F_WAKE_LOCK
- wake_lock_timeout(&felica_wake_1, msecs_to_jiffies(tmout_1));
- FELICA_PR_INFO(" %s Wake Lock(1)[%d]", __func__, tmout_1);
- #endif
- wake_up_interruptible(&pgint_irq->read_wait);
- FELICA_PR_DBG(" %s END", __func__);
- }
- /*
- * initialize device
- */
- static void felica_int_poll_init(void)
- {
- int ret;
- struct device *device_felica_int_poll;
-
- #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- #if !defined(CONFIG_MACH_KLTE_KDI) && !defined(CONFIG_MACH_KLTE_DCM) && !defined(CONFIG_MACH_KLTE_SBM)
- struct device *dev = &felica_gpio_pdev->dev;
- struct device_node *np;
- #endif // CONFIG_MACH_KLTE
- #endif
- FELICA_PR_DBG(" %s START", __func__);
- devid_felica_int_poll = MKDEV(FELICA_MAJOR, FELICA_MINOR);
- ret =
- alloc_chrdev_region(&devid_felica_int_poll, FELICA_BASEMINOR,
- FELICA_MINOR_COUNT, FELICA_INT_POLL_NAME);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
- __func__, ret);
- return;
- }
- cdev_init(&cdev_felica_int_poll, &fops_felica_int_poll);
- ret =
- cdev_add(&cdev_felica_int_poll, devid_felica_int_poll,
- FELICA_MINOR_COUNT);
- if (ret < 0) {
- unregister_chrdev_region(devid_felica_int_poll,
- FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
- ret);
- return;
- }
- device_felica_int_poll =
- device_create(felica_class, NULL, devid_felica_int_poll, NULL,
- FELICA_INT_POLL_NAME);
- if (IS_ERR(device_felica_int_poll)) {
- cdev_del(&cdev_felica_int_poll);
- unregister_chrdev_region(devid_felica_int_poll,
- FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
- return;
- }
- memset(pgint_irq, 0x00, sizeof(struct felica_int_irqdata));
- INIT_DELAYED_WORK(&pgint_irq->work, felica_int_irq_work);
- init_waitqueue_head(&pgint_irq->read_wait);
- #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- #if !defined(CONFIG_MACH_KLTE_KDI) && !defined(CONFIG_MACH_KLTE_DCM) && !defined(CONFIG_MACH_KLTE_SBM)
- if (!dev) {
- FELICA_PR_ERR(" %s ERROR NULL", __func__);
- return;
- }
- np = dev->of_node;
- gfelica_irq_int_pin = of_get_named_gpio(np, "felica,irq-gpio", 0);
- FELICA_PR_INFO(" %s gfelica_irq_int_pin [%d]",
- __func__, gfelica_irq_int_pin);
- #endif // CONFIG_MACH_KLTE
- #if defined(CONFIG_MACH_HLTEKDI)
- gfelica_sps_pin = of_get_named_gpio(np, "felica,sps-gpio", 0);
- if(gfelica_sps_pin < 0)
- {
- FELICA_PR_ERR(" %s ERROR(), ret=[%d]",__func__, gfelica_sps_pin);
- return;
- }
- FELICA_PR_INFO(" %s gfelica_sps_pin [%d]",
- __func__, gfelica_sps_pin);
- ret = gpio_get_value(gfelica_sps_pin);
- FELICA_PR_INFO(" %s gfelica_sps_pin [%d]",
- __func__, ret);
- #endif
- #if defined(CONFIG_MACH_HLTEDCM) || defined(CONFIG_MACH_JS01LTEDCM)
- if (system_rev >= g_uicc_initrev) {
- gpio_tlmm_config(GPIO_CFG(gfelica_sps_pin, GPIOMUX_FUNC_GPIO,
- GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
- GPIO_CFG_ENABLE);
- FELICA_PR_INFO(" %s gfelica_sps_pin dcm [%d]",
- __func__, gfelica_sps_pin);
- FELICA_PR_INFO(" %s gfelica_sps_pin dcm [%d]",
- __func__, gpio_get_value(gfelica_sps_pin));
- }
- #endif
- #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
- ret = request_threaded_irq(
- gpio_to_irq(GPIO_PINID_FELICA_INT),
- NULL,
- felica_int_irq_handler,
- IRQF_TRIGGER_FALLING,
- FELICA_INT_POLL_NAME,
- (void *)pgint_irq);
-
- FELICA_PR_INFO(" %s INFO(request_irq)= %d GPIO=%d, ret=[%d]",
- __func__, gpio_to_irq(GPIO_PINID_FELICA_INT),GPIO_PINID_FELICA_INT,ret);
- #else
- ret = request_threaded_irq(
- gpio_to_irq(gfelica_irq_int_pin),
- NULL,
- felica_int_irq_handler,
- IRQF_TRIGGER_FALLING,
- FELICA_INT_POLL_NAME,
- (void *)pgint_irq);
- #endif // CONFIG_MACH_KLTE
- #else
- ret = request_irq(gpio_to_irq(GPIO_PINID_FELICA_INT_REV03),
- felica_int_irq_handler,
- IRQF_TRIGGER_FALLING,
- FELICA_INT_POLL_NAME, (void *)pgint_irq);
- #endif /* CONFIG_ARCH_MSM8974 */
- if (ret != 0) {
- device_destroy(felica_class, devid_felica_int_poll);
- cdev_del(&cdev_felica_int_poll);
- unregister_chrdev_region(devid_felica_int_poll,
- FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(request_irq), ret=[%d]",
- __func__,ret);
- return;
- }
- #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
- ret = enable_irq_wake(gpio_to_irq(GPIO_PINID_FELICA_INT));
- if (ret < 0) {
- free_irq(gpio_to_irq(GPIO_PINID_FELICA_INT), (void *)pgint_irq);
- device_destroy(felica_class, devid_felica_int_poll);
- cdev_del(&cdev_felica_int_poll);
- unregister_chrdev_region(devid_felica_int_poll,
- FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(enable_irq_wake), ret=[%d]",
- __func__, ret);
- return;
- }
- #else
- ret = enable_irq_wake(gpio_to_irq(gfelica_irq_int_pin));
- if (ret < 0) {
- free_irq(gpio_to_irq(gfelica_irq_int_pin), (void *)pgint_irq);
- device_destroy(felica_class, devid_felica_int_poll);
- cdev_del(&cdev_felica_int_poll);
- unregister_chrdev_region(devid_felica_int_poll,
- FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(enable_irq_wake), ret=[%d]",
- __func__, ret);
- return;
- }
- #endif // CONFIG_MACH_KLTE
- #else
- ret = enable_irq_wake(gpio_to_irq(GPIO_PINID_FELICA_INT_REV03));
- if (ret < 0) {
- free_irq(gpio_to_irq(
- GPIO_PINID_FELICA_INT_REV03),
- (void *)pgint_irq);
- device_destroy(felica_class, devid_felica_int_poll);
- cdev_del(&cdev_felica_int_poll);
- unregister_chrdev_region(devid_felica_int_poll,
- FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(enable_irq_wake), ret=[%d]",
- __func__, ret);
- return;
- }
- #endif /* CONFIG_ARCH_MSM8974 */
- pgint_irq->irq_done = 0;
- FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__, \
- MAJOR(devid_felica_int_poll),
- MINOR(devid_felica_int_poll));
- }
- /*
- * finalize device
- */
- static void felica_int_poll_exit(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
- disable_irq(gpio_to_irq(GPIO_PINID_FELICA_INT));
- free_irq(gpio_to_irq(
- GPIO_PINID_FELICA_INT),
- (void *)pgint_irq);
- #else
- disable_irq(gpio_to_irq(gfelica_irq_int_pin));
- free_irq(gpio_to_irq(
- gfelica_irq_int_pin),
- (void *)pgint_irq);
- #endif // CONFIG_MACH_KLTE
- #else
- disable_irq(gpio_to_irq(GPIO_PINID_FELICA_INT_REV03));
- free_irq(gpio_to_irq(
- GPIO_PINID_FELICA_INT_REV03),
- (void *)pgint_irq);
- #endif
- device_destroy(felica_class, devid_felica_int_poll);
- cdev_del(&cdev_felica_int_poll);
- unregister_chrdev_region(
- devid_felica_int_poll,
- FELICA_MINOR_COUNT);
- FELICA_PR_DBG(" %s END", __func__);
- }
- /*
- * open device
- */
- static int felica_int_poll_open(struct inode *inode, struct file *file)
- {
- /* no operation */
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * close device
- */
- static int felica_int_poll_close(struct inode *inode, struct file *file)
- {
- /* no operation */
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * read operation
- */
- static ssize_t felica_int_poll_read(struct file *file, char __user *buf,
- size_t len, loff_t *ppos)
- {
- int ret;
- char retparam;
- FELICA_PR_DBG(" %s START", __func__);
- if (!pgint_irq->irq_done) {
- ret =
- wait_event_interruptible(pgint_irq->read_wait,
- pgint_irq->irq_done == 1);
- if (ret < 0) {
- FELICA_PR_ERR
- (" %s ERROR(wait_event_interruptible),ret=[%d]",\
- __func__, ret);
- return -EINTR;
- }
- }
- #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
- ret = gpio_get_value(GPIO_PINID_FELICA_INT);
- #else
- ret = gpio_get_value(gfelica_irq_int_pin);
- #endif // CONFIG_MACH_KLTE
- #else
- ret = gpio_get_value(GPIO_PINID_FELICA_INT_REV03);
- #endif
- if (ret == GPIO_VALUE_HIGH) {
- retparam = FELICA_INT_HIGH;
- FELICA_PR_INFO(" INT-PIN value is [%d][HIGH]", retparam);
- } else if (ret == GPIO_VALUE_LOW) {
- retparam = FELICA_INT_LOW;
- FELICA_PR_INFO(" INT-PIN value is [%d][LOW]", retparam);
- } else {
- FELICA_PR_ERR(" %s ERROR(gpio_get_value), ret=[%d]",
- __func__, ret);
- return -EIO;
- }
- ret = copy_to_user(buf, &retparam, FELICA_INT_DATA_LEN);
- if (ret != 0) {
- FELICA_PR_ERR(" %s ERROR(copy_to_user), ret=[%d]",
- __func__, ret);
- return -EFAULT;
- }
- *ppos += 1;
- pgint_irq->irq_done = 0;
- FELICA_PR_DBG(" %s END", __func__);
- return FELICA_INT_DATA_LEN;
- }
- /*
- * poll operation
- */
- static unsigned int felica_int_poll_poll(struct file *file, poll_table *wait)
- {
- unsigned int mask = 0;
- FELICA_PR_DBG(" %s START", __func__);
- poll_wait(file, &pgint_irq->read_wait, wait);
- if (pgint_irq->irq_done)
- mask = POLLIN | POLLRDNORM;
- FELICA_PR_DBG(" %s END", __func__);
- return mask;
- }
- /******************************************************************************
- * /dev/felica_uid
- ******************************************************************************/
- /* character device definition */
- static dev_t devid_felica_uid;
- static struct cdev cdev_felica_uid;
- static const struct file_operations fops_felica_uid = {
- .owner = THIS_MODULE,
- .open = felica_uid_open,
- .release = felica_uid_close,
- .unlocked_ioctl = felica_uid_ioctl,
- };
- /*
- * initialize device
- */
- static void felica_uid_init(void)
- {
- int ret;
- struct device *device_felica_uid;
- FELICA_PR_DBG(" %s START", __func__);
- devid_felica_uid = MKDEV(FELICA_MAJOR, FELICA_MINOR);
- ret =
- alloc_chrdev_region(&devid_felica_uid, FELICA_BASEMINOR,
- FELICA_MINOR_COUNT, FELICA_UID_NAME);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
- __func__, ret);
- return;
- }
- cdev_init(&cdev_felica_uid, &fops_felica_uid);
- ret = cdev_add(&cdev_felica_uid, devid_felica_uid, FELICA_MINOR_COUNT);
- if (ret < 0) {
- unregister_chrdev_region(devid_felica_uid, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
- ret);
- return;
- }
- device_felica_uid =
- device_create(felica_class, NULL, devid_felica_uid, NULL,
- FELICA_UID_NAME);
- if (IS_ERR(device_felica_uid)) {
- cdev_del(&cdev_felica_uid);
- unregister_chrdev_region(devid_felica_uid, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
- return;
- }
- FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
- MAJOR(devid_felica_uid), MINOR(devid_felica_uid));
- }
- /*
- * finalize device
- */
- static void felica_uid_exit(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- if (gdiag_name[0] != 0x00) {
- device_destroy(felica_class, devid_felica_uid);
- cdev_del(&cdev_felica_uid);
- unregister_chrdev_region(devid_felica_uid, \
- FELICA_MINOR_COUNT);
- }
- }
- /*
- * open device
- */
- static int felica_uid_open(struct inode *inode, struct file *file)
- {
- int ret = 0;
- char *cmdpos;
- static char cmdline[1025];
- static unsigned long start_adr, end_adr, leng;
- FELICA_PR_DBG(" %s START", __func__);
- start_adr = current->mm->arg_start;
- end_adr = current->mm->arg_end;
- leng = end_adr - start_adr;
- if (1024 < leng)
- leng = 1024;
- cmdpos = (char *)(current->mm->arg_start);
- ret = copy_from_user(cmdline, cmdpos, leng);
- cmdline[leng] = '\0';
- if(ret != 0)
- {
- FELICA_PR_ERR(" %s cmdline[%s] ret[%d]", __func__, cmdline, ret);
- return -EFAULT;
- }
- if (strncmp(cmdline, gdiag_name, leng) != 0) {
- FELICA_PR_INFO(" %s ERROR, %s gdiag %s", \
- __func__, cmdline, gdiag_name);
- #ifdef SRIB_DIAG_ENABLED
- FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
- #else
- return -EACCES;
- #endif
- }
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * close device
- */
- static int felica_uid_close(struct inode *inode, struct file *file)
- {
- /* no operation */
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * uid registration
- */
- static long felica_uid_ioctl(struct file *file, unsigned int cmd,
- unsigned long arg)
- {
- FELICA_PR_DBG(" %s START, cmd=[%d]", __func__, cmd);
- switch (cmd) {
- case SET_FELICA_UID_DIAG:
- gdiag_uid = *((int *)arg);
- FELICA_PR_INFO("Set gdiag_uid to [%d]", gdiag_uid);
- break;
- default:
- FELICA_PR_ERR(" %s ERROR(unknown command)", __func__);
- break;
- }
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /******************************************************************************
- * /dev/felica_ant
- ******************************************************************************/
- /* character device definition */
- static dev_t devid_felica_ant;
- static struct cdev cdev_felica_ant;
- static const struct file_operations fops_felica_ant = {
- .owner = THIS_MODULE,
- .open = felica_ant_open,
- .release = felica_ant_close,
- .read = felica_ant_read,
- .write = felica_ant_write,
- };
- /*
- * felica_ant_init
- */
- static void felica_ant_init(void)
- {
- int ret;
- struct device *device_felica_ant;
- FELICA_PR_DBG(" %s START", __func__);
- devid_felica_ant = MKDEV(FELICA_MAJOR, FELICA_MINOR);
- ret =
- alloc_chrdev_region(&devid_felica_ant, FELICA_BASEMINOR,
- FELICA_MINOR_COUNT, FELICA_ANT_NAME);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
- __func__, ret);
- return;
- }
- cdev_init(&cdev_felica_ant, &fops_felica_ant);
- ret = cdev_add(&cdev_felica_ant, devid_felica_ant, FELICA_MINOR_COUNT);
- if (ret < 0) {
- unregister_chrdev_region(devid_felica_ant, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
- ret);
- return;
- }
- device_felica_ant =
- device_create(felica_class, NULL, devid_felica_ant, NULL,
- FELICA_ANT_NAME);
- if (IS_ERR(device_felica_ant)) {
- cdev_del(&cdev_felica_ant);
- unregister_chrdev_region(devid_felica_ant, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
- return;
- }
- FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
- MAJOR(devid_felica_ant), MINOR(devid_felica_ant));
- }
- /*
- * felica_ant_exit
- */
- static void felica_ant_exit(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- device_destroy(felica_class, devid_felica_ant);
- cdev_del(&cdev_felica_ant);
- unregister_chrdev_region(devid_felica_ant, FELICA_MINOR_COUNT);
- FELICA_PR_DBG(" %s END", __func__);
- }
- /*
- * open device
- */
- static int felica_ant_open(struct inode *inode, struct file *file)
- {
- uid_t uid;
- FELICA_PR_DBG(" %s START", __func__);
- #if defined(CONFIG_MACH_HLTEDCM)
- //high
- if (system_rev == HW_REV09_OR_10)
- {
- FELICA_PR_INFO(" %s Making MHL_EN HIGH", __func__);
- of_sii8240_hw_poweron(FELICA_CEN_UNLOCK);
- }
- #endif
-
- uid = __task_cred(current)->uid;
- if ((uid != gant_uid) && (uid != gdiag_uid)) {
- FELICA_PR_ERR(\
- " %s END -EACCES, uid=[%d], gant_uid=[%d]\n", __func__, uid, gant_uid);
-
- #if defined(CONFIG_MACH_HLTEDCM)
- //low
- if (system_rev == HW_REV09_OR_10)
- {
- FELICA_PR_INFO(" %s Making MHL_EN LOW", __func__);
- // of_sii8240_hw_poweron(FELICA_CEN_LOCK);
- }
- #endif
-
- #ifdef SRIB_DIAG_ENABLED
- FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
- #else
- return -EACCES;
- #endif
- }
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * close device
- */
- static int felica_ant_close(struct inode *inode, struct file *file)
- {
- /* no operation */
- #if defined(CONFIG_MACH_HLTEDCM)
- //low
- if (system_rev == HW_REV09_OR_10)
- {
- FELICA_PR_INFO(" %s Making MHL_EN LOW", __func__);
- // of_sii8240_hw_poweron(FELICA_CEN_LOCK);
- }
- #endif
-
- FELICA_PR_DBG(" %s END system_rev=[%d]", __func__,system_rev);
- return 0;
- }
- /*
- * read operation
- */
- static ssize_t felica_ant_read(struct file *file, char __user *buf, \
- size_t len, loff_t *ppos)
- {
- int ret;
- unsigned char address = gi2c_antaddress;
- unsigned char read_buff = 0;
- struct i2c_msg read_msgs[2];
- read_msgs[0].flags = gread_msgs[0].flags;
- read_msgs[0].len = gread_msgs[0].len;
- read_msgs[1].flags = gread_msgs[1].flags;
- read_msgs[1].len = gread_msgs[1].len;
- read_msgs[0].addr = gi2c_address;
- read_msgs[0].buf = &address;
- read_msgs[1].addr = gi2c_address;
- read_msgs[1].buf = &read_buff;
- FELICA_PR_DBG(" %s START", __func__);
- if (felica_i2c_client == NULL) {
- FELICA_PR_ERR(" %s -EIO felica_i2c_client is NULL", \
- __func__);
- return -EIO;
- }
- ret = i2c_transfer(felica_i2c_client->adapter, &read_msgs[0], 1);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(i2c_transfer[0]), ret=[%d]",
- __func__, ret);
- return -EIO;
- }
- ret = i2c_transfer(felica_i2c_client->adapter, &read_msgs[1], 1);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(i2c_transfer[1]), ret=[%d]",
- __func__, ret);
- return -EIO;
- }
- FELICA_PR_INFO(" %s read_buff=[%d]", __func__, read_buff);
- ret = copy_to_user(buf, &read_buff, FELICA_ANT_DATA_LEN);
- if (ret != 0) {
- FELICA_PR_ERR(" %s ERROR(copy_to_user), ret=[%d]",
- __func__, ret);
- return -EFAULT;
- }
- *ppos += 1;
- FELICA_PR_DBG(" %s END", __func__);
- return FELICA_ANT_DATA_LEN;
- }
- /*
- * write operation
- */
- static ssize_t felica_ant_write(struct file *file, const char __user *data,
- size_t len, loff_t *ppos)
- {
- char ant;
- int ret;
- unsigned char write_buff[2];
- FELICA_PR_DBG(" %s START", __func__);
- if (felica_i2c_client == NULL) {
- FELICA_PR_ERR(" %s -EIO felica_i2c_client is NULL", \
- __func__);
- return -EIO;
- }
- ret = copy_from_user(&ant, data, FELICA_ANT_DATA_LEN);
- if (ret != 0) {
- FELICA_PR_ERR(" %s ERROR(copy_from_user), ret=[%d]",
- __func__, ret);
- return -EFAULT;
- }
- write_buff[0] = gi2c_antaddress;
- write_buff[1] = ant;
- gwrite_msgs[0].buf = &write_buff[0];
- gwrite_msgs[0].addr = gi2c_address;
-
- ret = i2c_transfer(felica_i2c_client->adapter, gwrite_msgs, 1);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(i2c_transfer), ret=[%d]",
- __func__, ret);
- return -EIO;
- }
- FELICA_PR_DBG(" %s END", __func__);
- return FELICA_ANT_DATA_LEN;
- }
- /******************************************************************************
- * Mobile FeliCa device driver initialization / termination function
- ******************************************************************************/
- /*
- * to set initial value to each terminal
- */
- static void felica_initialize_pin(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- #if defined(CONFIG_ARCH_EXYNOS)
- gpio_set_value(GPIO_PINID_FELICA_PON, GPIO_VALUE_LOW);
- #elif defined(CONFIG_ARCH_APQ8064)
- ice_gpiox_set(GPIO_PINID_FELICA_PON, GPIO_VALUE_LOW);
- #elif defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- #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.
- gpio_set_value(GPIO_PINID_FELICA_PON, GPIO_VALUE_LOW);
- #endif
- #endif
- FELICA_PR_DBG(" %s END", __func__);
- }
- /*
- * to set final value to each terminal
- */
- static void felica_finalize_pin(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- #if defined(CONFIG_ARCH_EXYNOS)
- gpio_set_value(GPIO_PINID_FELICA_PON, GPIO_VALUE_LOW);
- #elif defined(CONFIG_ARCH_APQ8064)
- ice_gpiox_set(GPIO_PINID_FELICA_PON, GPIO_VALUE_LOW);
- #elif defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- #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.
- gpio_set_value(GPIO_PINID_FELICA_PON, GPIO_VALUE_LOW);
- #endif
- #endif
- FELICA_PR_DBG(" %s END", __func__);
- }
- /*
- * device driver registration
- */
- static void felica_register_device(void)
- {
- #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
- struct device *dev = &felica_gpio_pdev->dev;
- struct device_node *np;
- #endif
- FELICA_PR_DBG(" %s START", __func__);
- #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
- if (!dev)
- {
- FELICA_PR_ERR(" %s ERROR NULL", __func__);
- return;
- }
-
- np = dev->of_node;
-
- if(system_rev <=8)
- {
- gfelica_pon_pin = of_get_named_gpio(np, "felica,pon-gpio", 0);
- if(gfelica_pon_pin < 0)
- {
- FELICA_PR_ERR(" %s ERROR(), gfelica_pon_pin=[%d]",__func__, gfelica_pon_pin);
- return;
- }
- gpio_tlmm_config(GPIO_CFG(gfelica_pon_pin, GPIOMUX_FUNC_GPIO,
- GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
- GPIO_CFG_ENABLE);
- FELICA_PR_INFO(" %s gfelica_pon_pin [%d]",__func__, gpio_get_value(gfelica_pon_pin));
- }
-
- gpio_set_value(gfelica_pon_pin, GPIO_VALUE_LOW);
-
- gfelica_hsel_pin = of_get_named_gpio (np, "felica,hsel-gpio", 0);
- if(gfelica_hsel_pin < 0)
- {
- FELICA_PR_ERR(" %s ERROR(), ret=[%d]",__func__, gfelica_hsel_pin);
- return;
- }
- FELICA_PR_INFO(" %s gfelica_hsel_pin [%d]",__func__, gfelica_hsel_pin);
-
- if (system_rev >= g_uicc_initrev)
- {
- gpio_tlmm_config(GPIO_CFG(gfelica_hsel_pin, GPIOMUX_FUNC_GPIO,
- GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
- GPIO_CFG_ENABLE);
- FELICA_PR_INFO(" %s gfelica_hsel_pin [%d]",__func__, gpio_get_value(gfelica_hsel_pin));
- }
- gpio_set_value(gfelica_hsel_pin, GPIO_VALUE_LOW);
-
- #if defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
-
- gfelica_sps_pin = of_get_named_gpio(np, "felica,sps-gpio", 0);
- if(gfelica_sps_pin < 0)
- {
- FELICA_PR_ERR(" %s ERROR(), ret=[%d]",__func__, gfelica_sps_pin);
- return;
- }
- FELICA_PR_INFO(" %s gfelica_sps_pin [%d]",__func__, gfelica_sps_pin);
-
- if (system_rev >= g_uicc_initrev)
- {
- gpio_tlmm_config(GPIO_CFG(gfelica_sps_pin, GPIOMUX_FUNC_GPIO,
- GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
- GPIO_CFG_ENABLE);
- FELICA_PR_INFO(" %s gfelica_sps_pin [%d]",__func__, gpio_get_value(gfelica_sps_pin));
- }
- #endif
- #else
- felica_int_poll_init();
- #endif //CONFIG_MACH_KLTE
- FELICA_PR_DBG(" %s END", __func__);
- }
- /*
- * device driver deregistration
- */
- static void felica_deregister_device(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- felica_uid_exit();
- #if !defined(CONFIG_ARCH_MSM8974) && !defined(CONFIG_ARCH_MSM8974PRO)
- felica_int_poll_exit();
- #endif
- felica_ant_exit();
- felica_rws_exit();
- felica_rfs_exit();
- felica_cen_exit();
- felica_pon_exit();
- felica_uart_exit();
- FELICA_PR_DBG(" %s END", __func__);
- }
- #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- static struct of_device_id felica_of_match[] =
- {
- { .compatible = "felica,gpio-table",
- },
- {}
- };
- static int __devexit felica_gpio_remove(struct platform_device *pdev)
- {
- felica_int_poll_exit();
- return 0;
- }
- static struct platform_driver felica_of_driver =
- {
- .remove = __devexit_p(felica_gpio_remove),
- .driver =
- {
- .name = FELICA_GPIO_DRIVER_NAME,
- .owner = THIS_MODULE,
- .of_match_table = felica_of_match,
- },
- };
- static int __init felica_gpio_probe(struct platform_device *pdev)
- {
- felica_gpio_pdev = pdev;
- if (felica_gpio_pdev == NULL) {
- FELICA_PR_ERR(" %s -EIO felica_gpio_pdev is NULL", \
- __func__);
- return -EIO;
- }
- felica_register_device();
- schedule_delayed_work(&pgint_irq->work, msecs_to_jiffies(10));
- return 0;
- }
- #endif
- /*
- * The entry point for initialization module
- */
- static int __init felica_init(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- #ifdef F_WAKE_LOCK
- wake_lock_init(&felica_wake_1, WAKE_LOCK_SUSPEND, "felica-int-1");
- wake_lock_init(&felica_wake_2, WAKE_LOCK_SUSPEND, "felica-int-2");
- #endif
- felica_class = class_create(THIS_MODULE, "felica");
- if (IS_ERR(felica_class)) {
- FELICA_PR_ERR(" %s ERROR(class_create)", __func__);
- return PTR_ERR(felica_class);
- }
- felica_initialize_pin();
- #if !defined(CONFIG_ARCH_MSM8974) && !defined(CONFIG_ARCH_MSM8974PRO)
- felica_register_device();
- #endif
- felica_nl_init();
- felica_i2c_init();
- uicc_init();
- /* MFC UID registration */
- #if !defined(CONFIG_ARCH_MSM8974) && !defined(CONFIG_ARCH_MSM8974PRO)
- schedule_delayed_work(&pgint_irq->work, msecs_to_jiffies(10));
- #endif
- #ifdef CONFIG_NFC_FELICA
- /* FELICA_INTU GPIO is changed Start*/
- #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- felica_varying_gpio_intu = GPIO_PINID_NFC_INTU;
- #else
- if (system_rev > 0 && system_rev < 15)
- felica_varying_gpio_intu = GPIO_PINID_NFC_INTU_REV03;
- else
- felica_varying_gpio_intu = GPIO_PINID_NFC_INTU_REV06;
- #endif
- FELICA_PR_INFO(" %s , system_rev=[%d]", __func__, system_rev);
- /* FELICA_INTU GPIO is changed End */
- #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
- felica_int_poll_init();
- #endif // CONFIG_MACH_KLTE
- snfc_register_device();
- uartcc_init();
- #endif /* CONFIG_NFC_FELICA */
- FELICA_PR_DBG(" %s END", __func__);
- #if defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- return platform_driver_probe(&felica_of_driver, felica_gpio_probe);
- #else
- return 0;
- #endif
- }
- /*
- * The entry point for the termination module
- */
- static void __exit felica_exit(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- #ifdef F_WAKE_LOCK
- wake_lock_destroy(&felica_wake_1);
- wake_lock_destroy(&felica_wake_2);
- #endif
- uicc_exit();
- felica_i2c_exit();
- felica_nl_exit();
- felica_deregister_device();
- #ifdef CONFIG_NFC_FELICA
- snfc_deregister_device();
- snfc_uart_exit();
- uartcc_exit();
- snfc_cen_exit();
- #endif /* CONFIG_NFC_FELICA */
- felica_finalize_pin();
- class_destroy(felica_class);
- FELICA_PR_DBG(" %s END", __func__);
- }
- /******************************************************************************
- *
- *
- *
- *
- * Add driver code for CXD2235AGG NFC/Felica combo IC
- *
- *
- *
- *
- ******************************************************************************/
- #ifdef CONFIG_NFC_FELICA
- /******************************************************************************
- * /dev/snfc_hsel
- ******************************************************************************/
- /* character device definition */
- static dev_t devid_snfc_hsel;
- static struct cdev hsel_cdev;
- static const struct file_operations hsel_fileops = {
- .owner = THIS_MODULE,
- .read = hsel_read,
- .write = hsel_write,
- .open = hsel_open,
- .release = hsel_release,
- };
- /* function prototype */
- static int hsel_init(void)
- {
- int ret = 0;
- struct device *class_dev;
- devid_snfc_hsel = MKDEV(MISC_MAJOR, 0);
- FELICA_PR_DBG(" %s START", __func__);
- ret = alloc_chrdev_region(&devid_snfc_hsel, 0, HSEL_DEV_COUNT,
- HSEL_DEV_NAME);
- if (0 != ret) {
- FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
- __func__, ret);
- return ret;
- }
- cdev_init(&hsel_cdev, &hsel_fileops);
- hsel_cdev.owner = THIS_MODULE;
- ret = cdev_add(&hsel_cdev, devid_snfc_hsel, HSEL_DEV_COUNT);
- if (0 != ret) {
- unregister_chrdev_region(devid_snfc_hsel, HSEL_DEV_COUNT);
- FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]",
- __func__, ret);
- return ret;
- }
- class_dev = device_create(felica_class, NULL, devid_snfc_hsel,
- NULL, HSEL_DEV_NAME);
- if (0 != IS_ERR(class_dev)) {
- cdev_del(&hsel_cdev);
- unregister_chrdev_region(devid_snfc_hsel, HSEL_DEV_COUNT);
- ret = PTR_ERR(class_dev);
- FELICA_PR_ERR(" %s ERROR(device_create), ret=[%d]",
- __func__, ret);
- return ret;
- }
- FELICA_PR_DBG(" %s END", __func__);
- return ret;
- }
- /*
- * finalize device
- */
- static void hsel_exit(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- device_destroy(felica_class, devid_snfc_hsel);
- cdev_del(&hsel_cdev);
- unregister_chrdev_region(devid_snfc_hsel, HSEL_DEV_COUNT);
- FELICA_PR_DBG(" %s END", __func__);
- }
- /*
- * open device
- */
- static int hsel_open(struct inode *inode, struct file *file)
- {
- FELICA_PR_DBG(" %s START", __func__);
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * close device
- */
- static int hsel_release(struct inode *inode, struct file *file)
- {
- FELICA_PR_DBG(" %s START", __func__);
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * read operation
- */
- static ssize_t hsel_read(struct file *file, char __user *buf, size_t len,
- loff_t *ppos)
- {
- char hsel_val;
- int ret = -EINVAL;
- FELICA_PR_DBG(" %s START", __func__);
- if (NULL == buf) {
- FELICA_PR_ERR(" %s hsel_read param err", __func__);
- return -EIO;
- }
- if (1 > len) {
- FELICA_PR_ERR(
- " %s length check len = %d", __func__, len);
- return -EIO;
- }
- #if defined(CONFIG_ARCH_EXYNOS)
- ret = gpio_get_value(GPIO_PINID_NFC_HSEL);
- #elif defined(CONFIG_ARCH_APQ8064)
- ret = ice_gpiox_get(GPIO_PINID_NFC_HSEL);
- #elif defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- ret = gpio_get_value(gfelica_hsel_pin);
- #endif
- if (0 > ret) {
- FELICA_PR_ERR(" %s ERROR(gpio_get_value), ret=[%d]",
- __func__, ret);
- return ret;
- }
- if (0 == ret)
- hsel_val = 0;
- else
- hsel_val = 1;
- if (copy_to_user(buf, &hsel_val, 1)) {
- FELICA_PR_ERR(" %s ERROR(copy_to_user)", __func__);
- return -EFAULT;
- }
- FELICA_PR_DBG(" %s END", __func__);
- return 1;
- }
- /*
- * write operation
- */
- static ssize_t hsel_write(struct file *file, const char __user *data,\
- size_t len, loff_t *ppos)
- {
- char hsel_val;
- FELICA_PR_DBG(" %s START", __func__);
- if (NULL == data) {
- FELICA_PR_ERR(" %s hsel_write param err", __func__);
- return -EIO;
- }
- if (1 > len) {
- FELICA_PR_ERR(
- " %s length check len = %d",
- __func__, len);
- return -EIO;
- }
- if (copy_from_user(&hsel_val, data, 1)) {
- FELICA_PR_ERR(" %s ERROR(copy_from_user)", __func__);
- return -EFAULT;
- }
- if (0 == hsel_val) {
- FELICA_PR_INFO(" %s HSEL = Low", __func__);
- } else if (1 == hsel_val) {
- FELICA_PR_INFO(" %s HSEL = High", __func__);
- } else {
- FELICA_PR_ERR(" param err = %d", hsel_val);
- return -EIO;
- }
- #if defined(CONFIG_ARCH_EXYNOS)
- gpio_set_value(GPIO_PINID_NFC_HSEL , hsel_val);
- #elif defined(CONFIG_ARCH_APQ8064)
- ice_gpiox_set(GPIO_PINID_NFC_HSEL , hsel_val);
- #elif defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- gpio_set_value(gfelica_hsel_pin , hsel_val);
- #endif
- FELICA_PR_DBG(" %s END", __func__);
- return 1;
- }
- /******************************************************************************
- * /dev/snfc_intu_poll
- ******************************************************************************/
- /* character device definition */
- static dev_t devid_snfc_intu_poll;
- static struct cdev intu_poll_cdev;
- static struct poll_data g_intu_data;
- static struct poll_data *g_intu_d = &g_intu_data;
- static const struct file_operations intu_poll_fileops = {
- .owner = THIS_MODULE,
- .read = intu_poll_read,
- .open = intu_poll_open,
- .release = intu_poll_release,
- /* .poll = intu_poll_poll,*/
- };
- /*
- * top half of irq_handler
- */
- static irqreturn_t intu_poll_irq_handler(int irq, void *dev_id)
- {
- struct poll_data *intu_d = g_intu_d;
- FELICA_PR_DBG(" %s START irq = %d", __func__, irq);
- disable_irq_nosync(gpio_to_irq(felica_varying_gpio_intu));
- schedule_delayed_work(&intu_d->work, 0);
- FELICA_PR_DBG(" %s END", __func__);
- return IRQ_HANDLED;
- }
- /*
- * bottom half of irq_handler
- */
- static void intu_poll_work_func(struct work_struct *work)
- {
- struct poll_data *intu_d = g_intu_d;
- int read_value = 0;
- int old_value = 0;
- unsigned long irqflag = 0;
- FELICA_PR_DBG(" %s START", __func__);
- old_value = intu_d->device_status;
- read_value = gpio_get_value(felica_varying_gpio_intu);
- FELICA_PR_INFO(" %s read_value = %d old_value = %d",
- __func__, read_value, old_value);
- if (read_value < 0) {
- intu_d->read_error = read_value;
- } else if (read_value != old_value) {
- intu_d->device_status = read_value;
- intu_d->read_error = 0;
- if (intu_d->device_status == INTU_POLL_DEV_LOW)
- irqflag = IRQF_TRIGGER_HIGH | IRQF_SHARED;
- else
- irqflag = IRQF_TRIGGER_LOW | IRQF_SHARED;
- if (irq_set_irq_type(gpio_to_irq(felica_varying_gpio_intu),
- irqflag)) {
- FELICA_PR_ERR(
- " %s ERROR(set_irq_type), irqflag=[%ld]",
- __func__, irqflag);
- }
- }
- enable_irq(gpio_to_irq(felica_varying_gpio_intu));
- if (read_value != old_value || intu_d->read_error) {
- intu_d->irq_handler_done = 1;
- wake_up_interruptible(&intu_d->read_wait);
- }
- FELICA_PR_DBG(
- " %s END read_value = %d, old_value = %d, intu_d->read_error = %d",
- __func__, read_value, old_value, intu_d->read_error);
- }
- /*
- * initialize device
- */
- static int intu_poll_init(void)
- {
- int ret = 0;
- struct device *class_dev;
- unsigned long irqflag = 0;
- devid_snfc_intu_poll = MKDEV(MISC_MAJOR, 0);
- FELICA_PR_DBG(" %s START", __func__);
- ret = alloc_chrdev_region(&devid_snfc_intu_poll,
- 0, INTU_POLL_DEV_COUNT, INTU_POLL_DEV_NAME);
- if (ret) {
- FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
- __func__, ret);
- return ret;
- }
- cdev_init(&intu_poll_cdev, &intu_poll_fileops);
- intu_poll_cdev.owner = THIS_MODULE;
- ret = cdev_add(&intu_poll_cdev,
- devid_snfc_intu_poll,
- INTU_POLL_DEV_COUNT);
- if (ret) {
- unregister_chrdev_region(
- devid_snfc_intu_poll,
- INTU_POLL_DEV_COUNT);
- FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]",
- __func__, ret);
- return ret;
- }
- class_dev = device_create(felica_class,
- NULL, devid_snfc_intu_poll, NULL,
- INTU_POLL_DEV_NAME);
- if (IS_ERR(class_dev)) {
- cdev_del(&intu_poll_cdev);
- unregister_chrdev_region(
- devid_snfc_intu_poll, INTU_POLL_DEV_COUNT);
- ret = PTR_ERR(class_dev);
- FELICA_PR_ERR(" %s ERROR(device_create), ret=[%d]",
- __func__, ret);
- return ret;
- }
- memset(g_intu_d, 0x00, sizeof(struct poll_data));
- INIT_DELAYED_WORK(&g_intu_d->work, intu_poll_work_func);
- init_waitqueue_head(&g_intu_d->read_wait);
- g_intu_d->open_flag = 0;
- if (g_intu_d->open_flag) {
- FELICA_PR_ERR(" %s only one time", __func__);
- return 0;
- }
- g_intu_d->open_flag = 1;
- ret = gpio_get_value(felica_varying_gpio_intu);
- if (ret < 0) {
- g_intu_d->open_flag = 0;
- FELICA_PR_ERR(" %s ERROR(gpio_get_value), ret=[%d]",
- __func__, ret);
- return -EIO;
- }
- g_intu_d->device_status = ret;
- if (g_intu_d->device_status == INTU_POLL_DEV_LOW)
- irqflag = IRQF_TRIGGER_HIGH | IRQF_SHARED;
- else
- irqflag = IRQF_TRIGGER_LOW | IRQF_SHARED;
- if (request_irq(gpio_to_irq(felica_varying_gpio_intu),
- intu_poll_irq_handler, irqflag, INTU_POLL_DEV_NAME,
- (void *)g_intu_d)) {
- g_intu_d->open_flag = 0;
- FELICA_PR_ERR(" %s ERROR(request_irq), irqflag=[%ld]",
- __func__, irqflag);
- return -EIO;
- }
- g_intu_d->irq_handler_done = 0;
- FELICA_PR_DBG(" %s END", __func__);
- return ret;
- }
- /*
- * finalize device
- */
- static void intu_poll_exit(void)
- {
- struct poll_data *intu_d = g_intu_d;
- FELICA_PR_DBG(" %s START", __func__);
- cancel_delayed_work(&intu_d->work);
- free_irq(gpio_to_irq(felica_varying_gpio_intu), (void *)intu_d);
- intu_d->open_flag = 0;
- cdev_del(&intu_poll_cdev);
- unregister_chrdev_region(devid_snfc_intu_poll, INTU_POLL_DEV_COUNT);
- FELICA_PR_DBG(" %s END", __func__);
- }
- /*
- * open device
- */
- static int intu_poll_open(struct inode *inode, struct file *file)
- {
- /* no operation */
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * close device
- */
- static int intu_poll_release(struct inode *inode, struct file *file)
- {
- /* no operation */
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * read operation
- */
- static ssize_t intu_poll_read(struct file *file, char __user *buf,
- size_t len, loff_t *ppos)
- {
- struct poll_data *intu_d = g_intu_d;
- int ret;
- char cret;
- FELICA_PR_DBG(" %s START", __func__);
- if (len < 1) {
- FELICA_PR_ERR(
- " %s length check len = %d", __func__, len);
- return -EIO;
- }
- if (!intu_d->irq_handler_done) {
- if (file->f_flags & O_NONBLOCK) {
- FELICA_PR_ERR(" NONBLOCK");
- return -EAGAIN;
- }
- FELICA_PR_INFO(" NFC intu_poll wait irq");
- ret = wait_event_interruptible(intu_d->read_wait,
- intu_d->irq_handler_done == 1);
- if (-ERESTARTSYS == ret) {
- FELICA_PR_ERR(
- " %s -EINTR wait_event_interruptible ret = %d",
- __func__, ret);
- return -EINTR;
- }
- }
- if (intu_d->read_error) {
- intu_d->irq_handler_done = 0;
- intu_d->read_error = 0;
- FELICA_PR_ERR(" %s intu_d->read_error = %d",
- __func__, intu_d->read_error);
- return -EIO;
- }
- if (intu_d->device_status == INTU_POLL_DEV_HIGH)
- cret = 1;
- else
- cret = 0;
- len = 1;
- if (copy_to_user(buf, &cret, len)) {
- FELICA_PR_ERR(" %s ERROR(copy_to_user)", __func__);
- return -EFAULT;
- }
- intu_d->irq_handler_done = 0;
- FELICA_PR_DBG(
- " %s END len = %d, cret = %d", __func__, len, cret);
- return len;
- }
- /******************************************************************************
- * /dev/snfc_available_poll
- ******************************************************************************/
- /* character device definition */
- static dev_t devid_snfc_abailable_poll;
- static struct cdev available_poll_cdev;
- static const struct file_operations available_poll_fileops = {
- .owner = THIS_MODULE,
- .unlocked_ioctl = available_poll_ioctl,
- .read = available_poll_read,
- .open = available_poll_open,
- .release = available_poll_release,
- };
- /*
- * initialize device
- */
- static int available_poll_init(void)
- {
- int ret = 0;
- struct device *class_dev;
- devid_snfc_abailable_poll = MKDEV(MISC_MAJOR, 0);
- FELICA_PR_DBG(" %s START", __func__);
- ret = alloc_chrdev_region(&devid_snfc_abailable_poll, 0,
- AVAILABLE_POLL_DEV_COUNT, AVAILABLE_POLL_DEV_NAME);
- if (ret) {
- FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
- __func__, ret);
- return ret;
- }
- cdev_init(&available_poll_cdev, &available_poll_fileops);
- available_poll_cdev.owner = THIS_MODULE;
- ret = cdev_add(&available_poll_cdev, devid_snfc_abailable_poll,
- AVAILABLE_POLL_DEV_COUNT);
- if (ret) {
- unregister_chrdev_region(devid_snfc_abailable_poll,
- AVAILABLE_POLL_DEV_COUNT);
- FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]",
- __func__, ret);
- return ret;
- }
- class_dev = device_create(felica_class, NULL, devid_snfc_abailable_poll,
- NULL, AVAILABLE_POLL_DEV_NAME);
- if (IS_ERR(class_dev)) {
- cdev_del(&available_poll_cdev);
- unregister_chrdev_region(devid_snfc_abailable_poll,
- AVAILABLE_POLL_DEV_COUNT);
- ret = PTR_ERR(class_dev);
- FELICA_PR_ERR(" %s ERROR(device_create), ret=[%d]",
- __func__, ret);
- return ret;
- }
- memset((void *)&g_available_data, 0x00, sizeof(struct icc_poll_data));
- init_waitqueue_head(&g_available_data.read_wait);
- FELICA_PR_DBG(" %s END", __func__);
- return ret;
- }
- /*
- * finalize device
- */
- static void available_poll_exit(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- device_destroy(felica_class, devid_snfc_abailable_poll);
- cdev_del(&available_poll_cdev);
- unregister_chrdev_region(devid_snfc_abailable_poll,
- AVAILABLE_POLL_DEV_COUNT);
- FELICA_PR_DBG(" %s END", __func__);
- }
- /*
- * open device
- */
- static int available_poll_open(struct inode *inode, struct file *file)
- {
- /* no operation */
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * close device
- */
- static int available_poll_release(struct inode *inode, struct file *file)
- {
- FELICA_PR_DBG(" %s START", __func__);
- if (g_available_data.available_flag == 1) {
- g_available_data.rsp_done = 1;
- wake_up_interruptible(&g_available_data.read_wait);
- }
- g_available_data.rsp_done = 0;
- g_available_data.available_flag = 0;
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * read operation
- */
- static ssize_t available_poll_read(struct file *file, char __user *buf,
- size_t len, loff_t *ppos)
- {
- char type = 0;
- int nRet = -1;
- struct icc_poll_data *available_d = &g_available_data;
- FELICA_PR_DBG(" %s START", __func__);
- if ((!uartcc_is_idle_status()) ||
- (0 == g_cen_sts) ||
- (GPIO_VALUE_LOW == g_rfs_sts)) {
- available_d->available_flag = 1;
- nRet = wait_event_interruptible(available_d->read_wait,
- available_d->rsp_done == 1);
- if (nRet < 0) {
- FELICA_PR_ERR(
- " %s ERROR(wait_event_interruptible), ret=[%d]"
- , __func__, nRet);
- return -EIO;
- }
- type = 0x01;
- available_d->rsp_done = 0;
- available_d->available_flag = 0;
- } else {
- type = 0x01;
- }
- if (copy_to_user(buf, &type, len)) {
- FELICA_PR_ERR(" %s ERROR(copy_to_user)", __func__);
- return -EFAULT;
- }
- FELICA_PR_DBG(" %s END read size = %d ", __func__, len);
- return len;
- }
- /*
- * available operation
- */
- static long available_poll_ioctl(struct file *file, unsigned int cmd,
- unsigned long arg)
- {
- long nRet = -EIO;
- FELICA_PR_DBG(" %s START cmd = %x", __func__, cmd);
- switch (cmd) {
- case AVAILABLE_POLL_DEV_SET_PRE_LOCK:
- g_cen_sts = 0;
- nRet = 0;
- break;
- default:
- break;
- }
- FELICA_PR_DBG(" %s END cmd = %x", __func__, cmd);
- return nRet;
- }
- /******************************************************************************
- * /dev/snfc_rfs_poll
- ******************************************************************************/
- /* character device definition */
- static dev_t devid_snfc_rfs_poll;
- static struct cdev rfs_poll_cdev;
- static struct poll_data g_rfs_data;
- static struct poll_data *g_rfs_d = &g_rfs_data;
- static const struct file_operations rfs_poll_fileops = {
- .owner = THIS_MODULE,
- .read = rfs_poll_read,
- .open = rfs_poll_open,
- .release = rfs_poll_release,
- .poll = rfs_poll_poll,
- };
- /*
- * top half of irq_handler
- */
- static irqreturn_t rfs_poll_irq_handler(int irq, void *dev_id)
- {
- struct poll_data *rfs_d = g_rfs_d;
- FELICA_PR_DBG(" %s START irq = %d", __func__, irq);
- disable_irq_nosync(gpio_to_irq(GPIO_PINID_NFC_RFS_POLL));
- schedule_delayed_work(&rfs_d->work, msecs_to_jiffies(RFS_POLL_DELAY));
- FELICA_PR_DBG(" %s END", __func__);
- return IRQ_HANDLED;
- }
- /*
- * bottom half of irq_handler
- */
- static void rfs_poll_work_func(struct work_struct *work)
- {
- struct poll_data *rfs_d = g_rfs_d;
- int read_value = 0;
- int old_value = 0;
- unsigned long irqflag = 0;
- struct icc_poll_data *available_d = &g_available_data;
- FELICA_PR_DBG(" %s START", __func__);
- old_value = rfs_d->device_status;
- read_value = gpio_get_value(GPIO_PINID_NFC_RFS_POLL);
- FELICA_PR_INFO(" %s read_value = %d old_value = %d",
- __func__ , read_value, old_value);
- if (read_value < 0) {
- rfs_d->read_error = read_value;
- } else if (read_value != old_value) {
- g_rfs_sts = read_value;
- if (1 == available_d->available_flag) {
- if (0 != g_cen_sts) {
- if (GPIO_VALUE_LOW != g_rfs_sts) {
- if (uartcc_is_idle_status()) {
- FELICA_PR_INFO(
- " %s wake up available",
- __func__);
- available_d->rsp_done = 1;
- wake_up_interruptible(
- &available_d->read_wait);
- }
- }
- }
- }
- rfs_d->device_status = read_value;
- rfs_d->read_error = 0;
- if (rfs_d->device_status == RFS_POLL_DEV_LOW)
- irqflag = IRQF_TRIGGER_HIGH | IRQF_SHARED;
- else
- irqflag = IRQF_TRIGGER_LOW | IRQF_SHARED;
- if (irq_set_irq_type(
- gpio_to_irq(GPIO_PINID_NFC_RFS_POLL), irqflag)) {
- FELICA_PR_ERR(
- " %s ERROR(set_irq_type), irqflag=[%ld]",
- __func__, irqflag);
- }
- }
- enable_irq(gpio_to_irq(GPIO_PINID_NFC_RFS_POLL));
- if (read_value != old_value || rfs_d->read_error) {
- rfs_d->irq_handler_done = 1;
- wake_up_interruptible(&rfs_d->read_wait);
- }
- FELICA_PR_INFO(
- " %s END read_value = %d,old_value = %d,rfs_d->read_error = %d",
- __func__, read_value, old_value, rfs_d->read_error);
- }
- /*
- * initialize device
- */
- static int rfs_poll_init(void)
- {
- int ret = 0;
- struct device *class_dev;
- unsigned long irqflag = 0;
- devid_snfc_rfs_poll = MKDEV(MISC_MAJOR, 0);
- FELICA_PR_DBG(" %s START", __func__);
- ret = alloc_chrdev_region(&devid_snfc_rfs_poll , 0 , RFS_POLL_DEV_COUNT,
- RFS_POLL_DEV_NAME);
- if (ret) {
- FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region) ret=[%d]",
- __func__, ret);
- return ret;
- }
- cdev_init(&rfs_poll_cdev, &rfs_poll_fileops);
- rfs_poll_cdev.owner = THIS_MODULE;
- ret = cdev_add(&rfs_poll_cdev, devid_snfc_rfs_poll, RFS_POLL_DEV_COUNT);
- if (ret) {
- unregister_chrdev_region(
- devid_snfc_rfs_poll, RFS_POLL_DEV_COUNT);
- FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]",
- __func__, ret);
- return ret;
- }
- class_dev = device_create(felica_class, NULL, devid_snfc_rfs_poll, NULL,
- RFS_POLL_DEV_NAME);
- if (IS_ERR(class_dev)) {
- cdev_del(&rfs_poll_cdev);
- unregister_chrdev_region(
- devid_snfc_rfs_poll, RFS_POLL_DEV_COUNT);
- ret = PTR_ERR(class_dev);
- FELICA_PR_ERR(" %s ERROR(device_create), ret=[%d]",
- __func__, ret);
- return ret;
- }
- memset(g_rfs_d, 0x00, sizeof(struct poll_data));
- INIT_DELAYED_WORK(&g_rfs_d->work, rfs_poll_work_func);
- init_waitqueue_head(&g_rfs_d->read_wait);
- g_rfs_d->open_flag = 0;
- if (g_rfs_d->open_flag) {
- FELICA_PR_ERR(" %s only one time", __func__);
- return -EBUSY;
- }
- g_rfs_d->open_flag = 1;
- ret = gpio_get_value(GPIO_PINID_NFC_RFS_POLL);
- if (ret < 0) {
- g_rfs_d->open_flag = 0;
- FELICA_PR_ERR(" %s ERROR(gpio_get_value), ret=[%d]",
- __func__, ret);
- return -EIO;
- }
- g_rfs_d->device_status = ret;
- g_rfs_sts = ret;
- if (g_rfs_d->device_status == RFS_POLL_DEV_LOW)
- irqflag = IRQF_TRIGGER_HIGH | IRQF_SHARED;
- else
- irqflag = IRQF_TRIGGER_LOW | IRQF_SHARED;
- if (request_irq(gpio_to_irq(
- GPIO_PINID_NFC_RFS_POLL), rfs_poll_irq_handler,
- irqflag, RFS_POLL_DEV_NAME, (void *)g_rfs_d)) {
- g_rfs_d->open_flag = 0;
- FELICA_PR_ERR(" %s ERROR(request_irq), irqflag=[%ld]",
- __func__, irqflag);
- return -EIO;
- }
- g_rfs_d->irq_handler_done = 0;
- FELICA_PR_DBG(" %s END", __func__);
- return ret;
- }
- /*
- * finalize device
- */
- static void rfs_poll_exit(void)
- {
- struct poll_data *rfs_d = g_rfs_d;
- FELICA_PR_DBG(" %s START", __func__);
- cancel_delayed_work(&rfs_d->work);
- free_irq(gpio_to_irq(GPIO_PINID_NFC_RFS_POLL), (void *)rfs_d);
- rfs_d->open_flag = 0;
- cdev_del(&rfs_poll_cdev);
- unregister_chrdev_region(
- devid_snfc_rfs_poll, RFS_POLL_DEV_COUNT);
- FELICA_PR_DBG(" %s END", __func__);
- }
- /*
- * open operation
- */
- static int rfs_poll_open(struct inode *inode, struct file *file)
- {
- int uid_ret = 0;
- FELICA_PR_DBG(" %s START", __func__);
- uid_ret = snfc_uid_check();
- if (uid_ret < 0) {
- FELICA_PR_ERR
- (" %s open fail=[%d]", __func__, uid_ret);
- #ifdef SRIB_DIAG_ENABLED
- FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
- #else
- return -EACCES;
- #endif
- }
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * close operation
- */
- static int rfs_poll_release(struct inode *inode, struct file *file)
- {
- /* no operation */
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * poll operation
- */
- static unsigned int rfs_poll_poll(struct file *file, poll_table *wait)
- {
- struct poll_data *rfs_d = g_rfs_d;
- unsigned int mask = 0;
- FELICA_PR_DBG(" %s START", __func__);
- poll_wait(file, &rfs_d->read_wait, wait);
- if (rfs_d->irq_handler_done)
- mask = POLLIN | POLLRDNORM;
- FELICA_PR_DBG(" %s END mask = %d", __func__, mask);
- return mask;
- }
- /*
- * read operation
- */
- static ssize_t rfs_poll_read(struct file *file, char __user *buf, size_t len,
- loff_t *ppos)
- {
- struct poll_data *rfs_d = g_rfs_d;
- int ret;
- char cret;
- FELICA_PR_DBG(" %s START", __func__);
- if (len < 1) {
- FELICA_PR_ERR(
- " %s length check len = %d", __func__, len);
- return -EIO;
- }
- if (!rfs_d->irq_handler_done) {
- if (file->f_flags & O_NONBLOCK) {
- FELICA_PR_ERR(" %s NONBLOCK", __func__);
- return -EAGAIN;
- }
- FELICA_PR_INFO(
- " %s FeliCa rfs_poll wait irq", __func__);
- ret = wait_event_interruptible(rfs_d->read_wait,
- rfs_d->irq_handler_done == 1);
- if (-ERESTARTSYS == ret) {
- FELICA_PR_ERR(
- " %s -EINTR wait_event_interruptible ret=[%d]",
- __func__, ret);
- return -EINTR;
- }
- }
- if (rfs_d->read_error) {
- rfs_d->irq_handler_done = 0;
- rfs_d->read_error = 0;
- FELICA_PR_ERR(" %s rfs_d->read_error = %d",
- __func__, rfs_d->read_error);
- return -EIO;
- }
- if (rfs_d->device_status == RFS_POLL_DEV_HIGH)
- cret = RFS_POLL_RET_STS_HIGH;
- else
- cret = RFS_POLL_RET_STS_LOW;
- len = 1;
- if (copy_to_user(buf, &cret, len)) {
- FELICA_PR_ERR(" %s ERROR(copy_to_user)", __func__);
- return -EFAULT;
- }
- rfs_d->irq_handler_done = 0;
- FELICA_PR_DBG(
- " %s END len = %d, cret = %d",
- __func__, len, cret);
- return len;
- }
- /******************************************************************************
- * /dev/snfc_pon
- ******************************************************************************/
- /* character device definition */
- static dev_t devid_snfc_pon;
- static struct cdev cxd2235power_cdev;
- static const struct file_operations cxd2235power_fileops = {
- .owner = THIS_MODULE,
- .write = cxd2235power_write,
- .open = cxd2235power_open,
- .release = cxd2235power_release,
- };
- /*
- * initialize device
- */
- static int cxd2235power_init(void)
- {
- int ret = 0;
- struct device *class_dev;
- devid_snfc_pon = MKDEV(MISC_MAJOR, 0);
- FELICA_PR_DBG(" %s START", __func__);
- ret = alloc_chrdev_region(&devid_snfc_pon , 0 , CXD2235_POWER_DEV_COUNT,
- CXD2235_POWER_DEV_NAME);
- if (ret) {
- FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
- __func__, ret);
- return ret;
- }
- cdev_init(&cxd2235power_cdev, &cxd2235power_fileops);
- cxd2235power_cdev.owner = THIS_MODULE;
- ret = cdev_add(&cxd2235power_cdev, devid_snfc_pon,
- CXD2235_POWER_DEV_COUNT);
- if (ret) {
- unregister_chrdev_region(
- devid_snfc_pon, CXD2235_POWER_DEV_COUNT);
- FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]",
- __func__, ret);
- return ret;
- }
- class_dev = device_create(felica_class, NULL, devid_snfc_pon, NULL,
- CXD2235_POWER_DEV_NAME);
- if (IS_ERR(class_dev)) {
- cdev_del(&cxd2235power_cdev);
- unregister_chrdev_region(
- devid_snfc_pon, CXD2235_POWER_DEV_COUNT);
- ret = PTR_ERR(class_dev);
- FELICA_PR_ERR(" %s ERROR(device_create), ret=[%d]",
- __func__, ret);
- return ret;
- }
- FELICA_PR_DBG(" %s END", __func__);
- return ret;
- }
- /*
- * finalize device
- */
- static void cxd2235power_exit(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- device_destroy(felica_class, devid_snfc_pon);
- cdev_del(&cxd2235power_cdev);
- unregister_chrdev_region(devid_snfc_pon, CXD2235_POWER_DEV_COUNT);
- FELICA_PR_DBG(" %s END", __func__);
- }
- /*
- * open operation
- */
- static int cxd2235power_open(struct inode *inode, struct file *file)
- {
- int uid_ret = 0;
- FELICA_PR_DBG(" %s START", __func__);
- uid_ret = snfc_uid_check();
- if (uid_ret < 0) {
- FELICA_PR_ERR
- (" %s open fail=[%d]", __func__, uid_ret);
- #ifdef SRIB_DIAG_ENABLED
- FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
- #else
- return -EACCES;
- #endif
- }
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * close operation
- */
- static int cxd2235power_release(struct inode *inode, struct file *file)
- {
- /* no operation */
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * write operation
- */
- static ssize_t cxd2235power_write(struct file *file, const char __user *data,
- size_t len, loff_t *ppos)
- {
- char on;
- FELICA_PR_DBG(" %s START", __func__);
- if (len < 1) {
- FELICA_PR_ERR(
- " %s length check len = %d", __func__, len);
- return -EIO;
- }
- len = 1;
- if (copy_from_user(&on, data, len)) {
- FELICA_PR_ERR(" %s ERROR(copy_from_user)", __func__);
- return -EFAULT;
- }
- #if defined(CONFIG_ARCH_EXYNOS)
- gpio_set_value(GPIO_PINID_NFC_PON , on);
- #elif defined(CONFIG_ARCH_APQ8064)
- ice_gpiox_set(GPIO_PINID_NFC_PON, on);
- #elif defined(CONFIG_ARCH_MSM8974) || defined(CONFIG_ARCH_MSM8974PRO)
- #if defined(CONFIG_MACH_KLTE_KDI) || defined(CONFIG_MACH_KLTE_DCM) || defined(CONFIG_MACH_KLTE_SBM)
- gpio_set_value(gfelica_pon_pin , on); // PON is same for FELICA and NFC.
- #else
- gpio_set_value(GPIO_PINID_NFC_PON , on);
- #endif // CONFIG_MACH_KLTE
- #endif
- FELICA_PR_DBG(" %s END on = %d", __func__, on);
- return len;
- }
- /******************************************************************************
- * /dev/snfc_rfs
- ******************************************************************************/
- /* character device definition */
- static dev_t devid_snfc_rfs;
- static struct cdev cdev_snfc_rfs;
- static const struct file_operations fops_snfc_rfs = {
- .owner = THIS_MODULE,
- .open = snfc_rfs_open,
- .release = snfc_rfs_close,
- .read = snfc_rfs_read,
- };
- /*
- * initialize device
- */
- static void snfc_rfs_init(void)
- {
- int ret;
- struct device *device_snfc_rfs;
- FELICA_PR_DBG(" %s START", __func__);
- devid_snfc_rfs = MKDEV(FELICA_MAJOR, FELICA_MINOR);
- ret =
- alloc_chrdev_region(&devid_snfc_rfs, FELICA_BASEMINOR,
- FELICA_MINOR_COUNT, SNFC_RFS_NAME);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
- __func__, ret);
- return;
- }
- cdev_init(&cdev_snfc_rfs, &fops_snfc_rfs);
- ret = cdev_add(&cdev_snfc_rfs, devid_snfc_rfs, FELICA_MINOR_COUNT);
- if (ret < 0) {
- unregister_chrdev_region(devid_snfc_rfs, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
- ret);
- return;
- }
- device_snfc_rfs =
- device_create(felica_class, NULL, devid_snfc_rfs, NULL,
- SNFC_RFS_NAME);
- if (IS_ERR(device_snfc_rfs)) {
- cdev_del(&cdev_snfc_rfs);
- unregister_chrdev_region(devid_snfc_rfs, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
- return;
- }
- FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
- MAJOR(devid_snfc_rfs), MINOR(devid_snfc_rfs));
- }
- /*
- * finalize device
- */
- static void snfc_rfs_exit(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- device_destroy(felica_class, devid_snfc_rfs);
- cdev_del(&cdev_snfc_rfs);
- unregister_chrdev_region(devid_snfc_rfs, FELICA_MINOR_COUNT);
- }
- /*
- * open device
- */
- static int snfc_rfs_open(struct inode *inode, struct file *file)
- {
- int uid_ret = 0;
- FELICA_PR_DBG(" %s START", __func__);
- uid_ret = snfc_uid_check();
- if (uid_ret < 0) {
- FELICA_PR_ERR
- (" %s open fail=[%d]", __func__, uid_ret);
- #ifdef SRIB_DIAG_ENABLED
- FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
- #else
- return -EACCES;
- #endif
- }
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * close device
- */
- static int snfc_rfs_close(struct inode *inode, struct file *file)
- {
- /* no operation */
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * read operation
- */
- static ssize_t snfc_rfs_read(struct file *file, char __user *buf, \
- size_t len, loff_t *ppos)
- {
- int ret;
- char retparam;
- FELICA_PR_DBG(" %s START", __func__);
- ret = gpio_get_value(GPIO_PINID_SNFC_RFS);
- if (ret == GPIO_VALUE_HIGH) {
- retparam = SNFC_RFS_STANDBY;
- FELICA_PR_INFO(" Carrier-Wave Status is [%d][standby]",
- retparam);
- } else if (ret == GPIO_VALUE_LOW) {
- retparam = SNFC_RFS_DETECTED;
- FELICA_PR_INFO(" Carrier-Wave Status is [%d][detected]",
- retparam);
- } else {
- FELICA_PR_ERR(" %s ERROR(gpio_get_value), ret=[%d]",
- __func__, ret);
- return -EIO;
- }
- ret = copy_to_user(buf, &retparam, SNFC_RFS_DATA_LEN);
- if (ret != 0) {
- FELICA_PR_ERR(" %s ERROR(copy_to_user), ret=[%d]",
- __func__, ret);
- return -EFAULT;
- }
- *ppos += 1;
- FELICA_PR_DBG(" %s END", __func__);
- return SNFC_RFS_DATA_LEN;
- }
- /******************************************************************************
- * /dev/snfc_uart
- ******************************************************************************/
- /* character device definition */
- static dev_t devid_snfc;
- static struct cdev cdev_snfc;
- static const struct file_operations fops_snfc = {
- .owner = THIS_MODULE,
- .open = snfc_uart_open,
- .release = snfc_uart_close,
- .read = snfc_uart_read,
- .write = snfc_uart_write,
- .unlocked_ioctl = snfc_uart_ioctl,
- .poll = snfc_uart_poll,
- };
- /*
- * initialize device
- */
- static void snfc_uart_init(void)
- {
- int ret;
- struct device *device_snfc;
- FELICA_PR_DBG(" %s START", __func__);
- devid_snfc = MKDEV(FELICA_MAJOR, FELICA_MINOR);
- ret = alloc_chrdev_region(&devid_snfc, FELICA_BASEMINOR,
- FELICA_MINOR_COUNT, SNFC_UART_NAME);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
- __func__, ret);
- return;
- }
- cdev_init(&cdev_snfc, &fops_snfc);
- ret = cdev_add(&cdev_snfc, devid_snfc, FELICA_MINOR_COUNT);
- if (ret < 0) {
- unregister_chrdev_region(devid_snfc, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
- ret);
- return;
- }
- device_snfc = device_create(felica_class, NULL, devid_snfc, NULL,
- SNFC_UART_NAME);
- if (IS_ERR(device_snfc)) {
- cdev_del(&cdev_snfc);
- unregister_chrdev_region(devid_snfc, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
- return;
- }
- FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
- MAJOR(devid_snfc), MINOR(devid_snfc));
- }
- /*
- * finalize device
- */
- static void snfc_uart_exit(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- device_destroy(felica_class, devid_snfc);
- cdev_del(&cdev_snfc);
- unregister_chrdev_region(devid_snfc, FELICA_MINOR_COUNT);
- }
- /*
- * open device
- */
- static int snfc_uart_open(struct inode *inode, struct file *file)
- {
- uid_t uid;
- /* struct termios termios;*/
- struct file *tty;
- int ret = 0;
- FELICA_PR_DBG(" %s START", __func__);
- /* check NFC uid */
- uid = __task_cred(current)->uid;
- if (uid != gnfc_uid) {
- FELICA_PR_ERR(\
- " %s END -EACCES, uid=[%d], gnfc_uid=[%d]\n", __func__, uid,gnfc_uid);
- #ifdef SRIB_DIAG_ENABLED
- FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
- #else
- return -EACCES;
- #endif
- }
- file->private_data = dev_sem;
- if (down_interruptible(&dev_sem->felica_sem)) {
- FELICA_PR_ERR(\
- " %s END, ERR[ERESTARTSYS]\n", __func__);
- return -ERESTARTSYS;
- }
- if (pg_tty != NULL) {
- FELICA_PR_ERR(
- " %s multi open result=%d", __func__, ret);
- gnfc_open_cnt++;
- up(&dev_sem->felica_sem);
- return ret;
- }
- tty = filp_open(UART_DEV_NAME, O_RDWR | O_NOCTTY | O_NONBLOCK, 0);
- if (IS_ERR(tty)) {
- pg_tty = NULL;
- ret = PTR_ERR(tty);
- up(&dev_sem->felica_sem);
- FELICA_PR_ERR(
- " %s filp_open result = %d", __func__, ret);
- return ret;
- }
- pg_tty = tty;
- gnfc_open_cnt++;
- ret = 0;
- up(&dev_sem->felica_sem);
- FELICA_PR_DBG(" %s END", __func__);
- return ret;
- }
- /*
- * close device
- */
- static int snfc_uart_close(struct inode *inode, struct file *file)
- {
- struct file *tty;
- FELICA_PR_DBG(" %s START", __func__);
- if (down_interruptible(&dev_sem->felica_sem)) {
- FELICA_PR_ERR(\
- " %s END, ERR[ERESTARTSYS]\n", __func__);
- return -ERESTARTSYS;
- }
- gnfc_open_cnt--;
- tty = NULL;
- if (gnfc_open_cnt == 0) {
- tty = pg_tty;
- if (tty) {
- filp_close(tty, 0);
- pg_tty = NULL;
- }
- }
- up(&dev_sem->felica_sem);
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * read operation
- */
- static ssize_t snfc_uart_read(struct file *file, char __user *buf,\
- size_t len, loff_t *ppos)
- {
- struct file *tty;
- ssize_t ret = -ENOSYS;
- FELICA_PR_DBG(" %s START", __func__);
- if (down_interruptible(&dev_sem->felica_sem)) {
- FELICA_PR_ERR(\
- " %s END, ERR[ERESTARTSYS]\n", __func__);
- return -ERESTARTSYS;
- }
- tty = pg_tty;
- if (tty && tty->f_op->read)
- ret = tty->f_op->read(tty, buf, len, ppos);
- up(&dev_sem->felica_sem);
- FELICA_PR_DBG(" %s END", __func__);
- return ret;
- }
- /*
- * write operation
- */
- static ssize_t snfc_uart_write(struct file *file, const char __user *data, \
- size_t len, loff_t *ppos)
- {
- struct file *tty;
- ssize_t ret = -ENOSYS;
- FELICA_PR_DBG(" %s START", __func__);
- if (down_interruptible(&dev_sem->felica_sem)) {
- FELICA_PR_ERR(\
- " %s END, ERR[ERESTARTSYS]\n", __func__);
- return -ERESTARTSYS;
- }
- tty = pg_tty;
- if (tty && tty->f_op->write)
- ret = tty->f_op->write(tty, data, len, ppos);
- up(&dev_sem->felica_sem);
- FELICA_PR_DBG(" %s END", __func__);
- return ret;
- }
- /*
- * ioctl operation
- */
- static long snfc_uart_ioctl(struct file *file, unsigned int cmd, \
- unsigned long arg)
- {
- struct file *tty;
- ssize_t ret = -ENOSYS;
- FELICA_PR_DBG(" %s START", __func__);
- if (down_interruptible(&dev_sem->felica_sem)) {
- FELICA_PR_ERR(\
- " %s END, ERR[ERESTARTSYS]\n", __func__);
- return -ERESTARTSYS;
- }
- tty = pg_tty;
- if (tty && tty->f_op->unlocked_ioctl)
- ret = tty->f_op->unlocked_ioctl(tty, cmd, arg);
- up(&dev_sem->felica_sem);
- FELICA_PR_DBG(" %s END", __func__);
- return ret;
- }
- /*
- * poll operation
- */
- static unsigned int snfc_uart_poll(struct file *file,
- struct poll_table_struct *poll_table)
- {
- struct file *tty;
- unsigned int ret = 0;
- FELICA_PR_DBG(" %s START", __func__);
- if (down_interruptible(&dev_sem->felica_sem))
- return 0;
- tty = pg_tty;
- if (tty && tty->f_op->poll)
- ret = tty->f_op->poll(tty, poll_table);
- up(&dev_sem->felica_sem);
- FELICA_PR_DBG(" %s END", __func__);
- return ret;
- }
- /******************************************************************************
- * /dev/uartcc
- ******************************************************************************/
- /* character device definition */
- static struct felica_sem_data *guartcc_sem;
- static dev_t devid_uartcc;
- static struct cdev cdev_uartcc;
- static const struct file_operations fops_uartcc = {
- .owner = THIS_MODULE,
- .open = uartcc_open,
- .release = uartcc_close,
- .unlocked_ioctl = uartcc_ioctl,
- };
- /*
- * uartcc_init
- */
- static void uartcc_init(void)
- {
- int ret;
- struct device *device_uartcc;
- FELICA_PR_DBG(" %s START\n", __func__);
- devid_uartcc = MKDEV(UARTCC_MAJOR, UARTCC_MINOR);
- ret =
- alloc_chrdev_region(&devid_uartcc, UARTCC_BASEMINOR,
- UARTCC_MINOR_COUNT, UARTCC_NAME);
- if (ret < 0) {
- FELICA_PR_ERR(
- " %s ERROR(alloc_chrdev_region), ret=[%d]\n",
- __func__, ret);
- return;
- }
- cdev_init(&cdev_uartcc, &fops_uartcc);
- ret = cdev_add(&cdev_uartcc, devid_uartcc, UARTCC_MINOR_COUNT);
- if (ret < 0) {
- unregister_chrdev_region(devid_uartcc, UARTCC_MINOR_COUNT);
- FELICA_PR_ERR(
- " %s ERROR(cdev_add), ret=[%d]\n", __func__,
- ret);
- return;
- }
- device_uartcc =
- device_create(felica_class, NULL, devid_uartcc, NULL,
- UARTCC_NAME);
- if (IS_ERR(device_uartcc)) {
- cdev_del(&cdev_uartcc);
- unregister_chrdev_region(devid_uartcc, UARTCC_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(device_create)\n", __func__);
- return;
- }
- guartcc_sem = kmalloc(sizeof(struct felica_sem_data), GFP_KERNEL);
- if (!guartcc_sem) {
- cdev_del(&cdev_uartcc);
- unregister_chrdev_region(devid_uartcc, UARTCC_MINOR_COUNT);
- FELICA_PR_ERR(
- " %s ERROR(guartcc_sem malloc)\n", __func__);
- return;
- }
- sema_init(&guartcc_sem->felica_sem, 1);
- FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]\n", __func__, \
- MAJOR(devid_uartcc), MINOR(devid_uartcc));
- }
- /*
- * uartcc_exit
- */
- static void uartcc_exit(void)
- {
- FELICA_PR_DBG(" %s START\n", __func__);
- kfree(guartcc_sem);
- device_destroy(felica_class, devid_uartcc);
- cdev_del(&cdev_uartcc);
- unregister_chrdev_region(devid_uartcc, UARTCC_MINOR_COUNT);
- FELICA_PR_DBG(" %s END\n", __func__);
- }
- /*
- * open device
- */
- static int uartcc_open(struct inode *inode, struct file *file)
- {
- /* no operation */
- FELICA_PR_DBG(" %s END\n", __func__);
- return 0;
- }
- /*
- * close device
- */
- static int uartcc_close(struct inode *inode, struct file *file)
- {
- /* no operation */
- FELICA_PR_DBG(" %s END\n", __func__);
- return 0;
- }
- /*
- * available operation
- */
- static long uartcc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
- {
- int ret = 0;
- int user_buf = 0;
- FELICA_PR_DBG(" %s START, cmd=[%d]\n", __func__, cmd);
- switch (cmd) {
- case UARTCC_SET_NFC_START_REQ:
- if (down_interruptible(&guartcc_sem->felica_sem)) {
- FELICA_PR_ERR(
- " %s ERROR(down_interruptible)\n",
- __func__);
- return -ERESTARTSYS;
- }
- ret = copy_from_user(
- &user_buf, (void __user *)arg, sizeof(user_buf));
- if (ret != 0) {
- FELICA_PR_ERR
- (" %s ERROR(copy_from_user), ret=[%d]\n",
- __func__, ret);
- up(&guartcc_sem->felica_sem);
- return -EFAULT;
- }
- guartcc_start_req = user_buf;
- /* felica start request */
- uartcc_felica_start_request();
- FELICA_PR_INFO(" %s Set nfc start request=[%d]\n",
- __func__, guartcc_start_req);
- #ifdef P2P_FPGA_ALWAYS_ON
- switch (guartcc_start_req) {
- case SNFC_START_TARGET:
- case SNFC_START_INTU:
- set_fpga_felica_flag(1);
- break;
- case UARTCC_NFC_START_ENDPROC:
- break;
- default:
- set_fpga_felica_flag(0);
- break;
- }
- FELICA_PR_INFO(" %s [fpga]felica_status=[%d]\n",
- __func__, felica_status);
- #endif /* P2P_FPGA_ALWAYS_ON */
- up(&guartcc_sem->felica_sem);
- break;
- case UARTCC_GET_FELICA_STATUS:
- if (down_interruptible(&guartcc_sem->felica_sem)) {
- FELICA_PR_ERR(
- " %s ERROR(down_interruptible)\n", \
- __func__);
- return -ERESTARTSYS;
- }
- user_buf = uartcc_get_felica_status();
- ret = copy_to_user(
- (int __user *)arg, &user_buf, sizeof(user_buf));
- if (ret != 0) {
- FELICA_PR_ERR
- (" %s ERROR(copy_to_user), ret=[%d]\n", \
- __func__, ret);
- up(&guartcc_sem->felica_sem);
- return -EFAULT;
- }
- FELICA_PR_INFO(" %s Get felica status=[%d]\n", \
- __func__, guartcc_felica_status);
- up(&guartcc_sem->felica_sem);
- break;
- case UARTCC_SET_FELICA_STATUS:
- case UARTCC_GET_NFC_START_REQ:
- FELICA_PR_INFO(" %s No operation cmd\n", __func__);
- break;
- default:
- FELICA_PR_ERR(" %s ERROR(unknown command)\n", __func__);
- ret = -EIO;
- break;
- }
- FELICA_PR_DBG(" %s END\n", __func__);
- return ret;
- }
- /*
- * felica start request
- */
- static void uartcc_felica_start_request(void)
- {
- struct icc_poll_data *felica_poll = &gfelica_poll_data;
- FELICA_PR_DBG(" %s START\n", __func__);
- FELICA_PR_INFO(" %s start_req=[%d], felica_status=[%d]\n", \
- __func__, guartcc_start_req, guartcc_felica_status);
- /* wake up condition
- * - nfc star req is ENDPROC
- * - felica usage is waiting AutoPolling
- */
- if ((guartcc_start_req == UARTCC_NFC_START_ENDPROC) &&
- (uartcc_get_felica_status() ==
- UARTCC_FELICA_STATAUS_WAIT_POLLING)) {
- felica_poll->rsp_done = 1;
- wake_up_interruptible(&felica_poll->rsp_wait);
- FELICA_PR_INFO(
- " %s wake up felica start event\n", __func__);
- }
- FELICA_PR_DBG(" %s END\n", __func__);
- }
- /*
- * set felica status
- */
- static void uartcc_set_felica_status(int status)
- {
- FELICA_PR_DBG(" %s START, status=[%d]\n", __func__, status);
- guartcc_felica_status = status;
- FELICA_PR_INFO(" %s guartcc_felica_status=[%d]\n",
- __func__, guartcc_felica_status);
- FELICA_PR_DBG(" %s END\n", __func__);
- }
- /*
- * get felica status
- */
- static int uartcc_get_felica_status(void)
- {
- FELICA_PR_DBG(" %s START, guartcc_felica_status=[%d]\n", \
- __func__, guartcc_felica_status);
- FELICA_PR_DBG(" %s END\n", __func__);
- #if defined(CONFIG_MACH_KLTE_KDI)
- if(gfelica_uim_mon == 1) {
- FELICA_PR_ERR(" %s gfelica_uim_mon=%d\n", __func__, gfelica_uim_mon);
- return UARTCC_FELICA_STATAUS_IN_INIT;
- }
- return guartcc_felica_status;
- #else
- return guartcc_felica_status;
- #endif
- }
- /*
- * check for idle state felica
- */
- static unsigned int uartcc_is_idle_status(void)
- {
- int ret = 0;
- int flc_cts = 0;
- FELICA_PR_DBG(" %s START\n", __func__);
- flc_cts = uartcc_get_felica_status();
- if (!flc_cts) { /* idle */
- FELICA_PR_INFO(" %s felica status is idle\n", __func__);
- ret = 1;
- } else { /* else state */
- FELICA_PR_INFO(" %s felica status isn't idle=[%d]\n", \
- __func__, flc_cts);
- }
- FELICA_PR_DBG(" %s END\n", __func__);
- return ret;
- }
- /******************************************************************************
- * /dev/felica_uicc
- ******************************************************************************/
- /* character device definition */
- static dev_t devid_uicc;
- static struct cdev cdev_uicc;
- static const struct file_operations fops_uicc = {
- .owner = THIS_MODULE,
- .open = uicc_open,
- .release = uicc_close,
- .read = uicc_read, // permissive mode issue
- .unlocked_ioctl = uicc_ioctl,
- };
- /*
- * uartcc_init
- */
- static void uicc_init(void)
- {
- int ret;
- struct device *device_uicc;
- FELICA_PR_DBG(" %s START\n", __func__);
- devid_uicc = MKDEV(UICC_MAJOR, UICC_MINOR);
- ret =
- alloc_chrdev_region(&devid_uicc, UICC_BASEMINOR,
- UICC_MINOR_COUNT, UICC_NAME);
- if (ret < 0) {
- FELICA_PR_ERR(
- " %s ERROR(alloc_chrdev_region), ret=[%d]\n",
- __func__, ret);
- return;
- }
- cdev_init(&cdev_uicc, &fops_uicc);
- ret = cdev_add(&cdev_uicc, devid_uicc, UICC_MINOR_COUNT);
- if (ret < 0) {
- unregister_chrdev_region(devid_uicc, UICC_MINOR_COUNT);
- FELICA_PR_ERR(
- " %s ERROR(cdev_add), ret=[%d]\n", __func__,
- ret);
- return;
- }
- device_uicc =
- device_create(felica_class, NULL, devid_uicc, NULL,
- UICC_NAME);
- if (IS_ERR(device_uicc)) {
- cdev_del(&cdev_uicc);
- unregister_chrdev_region(devid_uicc, UICC_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(device_create)\n", __func__);
- return;
- }
- FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]\n", __func__, \
- MAJOR(devid_uicc), MINOR(devid_uicc));
- }
- /*
- * uicc_exit
- */
- static void uicc_exit(void)
- {
- FELICA_PR_DBG(" %s START\n", __func__);
- device_destroy(felica_class, devid_uicc);
- cdev_del(&cdev_uicc);
- unregister_chrdev_region(devid_uicc, UICC_MINOR_COUNT);
- FELICA_PR_DBG(" %s END\n", __func__);
- }
- /*
- * open device
- */
- static int uicc_open(struct inode *inode, struct file *file)
- {
- /* no operation */
- FELICA_PR_DBG(" %s END\n", __func__);
- return 0;
- }
- /*
- * close device
- */
- static int uicc_close(struct inode *inode, struct file *file)
- {
- /* no operation */
- FELICA_PR_DBG(" %s END\n", __func__);
- return 0;
- }
- /*
- * read operation // permissive mode issue
- */
- static ssize_t uicc_read(struct file *file, char __user *buf, \
- size_t len, loff_t *ppos)
- {
- int ret;
- char read_buff = 0;
- read_buff = g_uicc_sts;
- ret = copy_to_user(buf, &read_buff, FELICA_UICC_DATA_LEN);
- if (ret != 0) {
- FELICA_PR_ERR(" %s ERROR(copy_to_user), ret=[%d]",
- __func__, ret);
- return -EFAULT;
- }
- *ppos += 1;
- FELICA_PR_DBG(" %s END", __func__);
- return FELICA_UICC_DATA_LEN;
- }
- /*
- * available operation
- */
- static long uicc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
- {
- int ret = 0;
- struct regulator *reg_l9;
- FELICA_PR_DBG(" %s START, cmd=[%d]\n", __func__, cmd);
- FELICA_PR_INFO(" %s START, system_rev=[%d] UICC_rev[%d]\n",
- __func__, system_rev,g_uicc_initrev);
- switch (cmd) {
- case UICC_POWER_ON:
- if(system_rev < g_uicc_initrev)
- {
- reg_l9 = regulator_get(NULL, "8941_l9");
- if (IS_ERR(reg_l9)) {
- FELICA_PR_ERR(" %s 2 could not get 8917_l9, rc = %ld\n",
- __func__, PTR_ERR(reg_l9));
- return UICC_ERROR;
- }
- FELICA_PR_INFO(" %s regulator_get, reg_l9 OK]", __func__);
- ret = regulator_set_voltage(reg_l9, 1800000, 1800000);
- if (ret) {
- FELICA_PR_ERR(
- " %s ERROR(regulator_set_voltage 1.8V~1.8V), ret=[%d]"
- , __func__, ret);
- return UICC_ERROR;
- }
- FELICA_PR_INFO(
- " %s regulator_set_voltage(1.8v~1.8v), ret=[%d]"
- , __func__, ret);
- if (regulator_is_enabled(reg_l9)) {
- FELICA_PR_INFO(
- " %s L9(0V) is enabled. No need to do anything\n"
- , __func__);
- } else {
- ret = regulator_enable(reg_l9);
- if (ret) {
- FELICA_PR_ERR(
- " %s regulator_enable l9 failed, rc=%d\n"
- , __func__, ret);
- return UICC_ERROR;
- }
- }
- FELICA_PR_INFO(
- " %s regulator_enable, ret=[%d]", __func__, ret);
- }
- break;
- case UICC_POWER_OFF:
- if(system_rev < g_uicc_initrev)
- {
- reg_l9 = regulator_get(NULL, "8941_l9");
- if (IS_ERR(reg_l9)) {
- FELICA_PR_ERR(" %s could not get 8917_l9, rc = %ld\n",
- __func__, PTR_ERR(reg_l9));
- return UICC_ERROR;
- }
- FELICA_PR_INFO(" %s regulator_get, reg_l9 OK]", __func__);
- if (regulator_is_enabled(reg_l9)) {
- FELICA_PR_INFO(
- " %s L9(0V) is enabled already\n",__func__);
- if (regulator_disable(reg_l9)) {
- FELICA_PR_ERR
- (" %s disable l9 failed\n", __func__);
- return UICC_ERROR;
- }
- } else {
- FELICA_PR_ERR
- (" %s regulator l9 already disabled", __func__);
- return UICC_ERROR;
- }
- }
- break;
- case UICC_POWER_SPS_PMIC:
- g_uicc_sts = 0x01; // permissive mode issue
- if(system_rev >= g_uicc_initrev)
- {
- #if defined(CONFIG_MACH_KLTE_KDI)
- 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);
- #else
- gpio_set_value(gfelica_sps_pin, GPIO_VALUE_HIGH);
- FELICA_PR_INFO(
- " %s Select Power Supply -> HI [%d][%d]\n", __func__,
- gfelica_sps_pin, gpio_get_value(gfelica_sps_pin));
- #endif
- }
- break;
- case UICC_POWER_UIM_MON:
- #if defined(CONFIG_MACH_KLTE_KDI)
- FELICA_PR_INFO(" %s UICC_POWER_UIM_MON! make PON always high!\n", __func__);
- gfelica_uim_mon = 1;
- gpio_set_value(gfelica_pon_pin, GPIO_VALUE_HIGH);
- #else
- FELICA_PR_ERR(" %s UICC_POWER_UIM_MON! this is only for K-KDDI\n", __func__);
- #endif
- break;
- default:
- FELICA_PR_ERR(" %s Undefine Paramater [%d]", __func__, cmd);
- return UICC_ERROR;
- break;
- }
- FELICA_PR_DBG(" %s END\n", __func__);
- return UICC_SUCCESS;
- }
- /******************************************************************************
- * common
- ******************************************************************************/
- /*
- * add CXD2235 additional pin registration
- */
- static void snfc_register_device(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- intu_poll_init();
- schedule_delayed_work(&g_intu_d->work, msecs_to_jiffies(10));
- rfs_poll_init();
- schedule_delayed_work(&g_rfs_d->work, msecs_to_jiffies(10));
- FELICA_PR_DBG(" %s END", __func__);
- }
- /*
- * add CXD2235 additional pin unregistration
- */
- static void snfc_deregister_device(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- available_poll_exit();
- intu_poll_exit();
- snfc_rfs_exit();
- rfs_poll_exit();
- hsel_exit();
- cxd2235power_exit();
- FELICA_PR_DBG(" %s END", __func__);
- }
- /*
- * add read and store CEN status for snfc_available_poll device
- */
- static ssize_t snfc_cen_sts_init(void)
- {
- int ret;
- unsigned char address = gi2c_lockaddress;
- unsigned char read_buff = 0;
- struct i2c_msg read_msgs[2];
- read_msgs[0].flags = gread_msgs[0].flags;
- read_msgs[0].len = gread_msgs[0].len;
- read_msgs[1].flags = gread_msgs[1].flags;
- read_msgs[1].len = gread_msgs[1].len;
- read_msgs[0].addr = gi2c_address;
- read_msgs[0].buf = &address;
- read_msgs[1].addr = gi2c_address;
- read_msgs[1].buf = &read_buff;
- FELICA_PR_DBG(" %s START", __func__);
- if (felica_i2c_client == NULL) {
- FELICA_PR_ERR(" felica_i2c_client is NULL");
- return -EIO;
- }
- #if defined(CONFIG_MACH_HLTEDCM)
- //high
- if (system_rev == HW_REV09_OR_10)
- {
- FELICA_PR_INFO(" %s Making MHL_EN HIGH", __func__);
- of_sii8240_hw_poweron(FELICA_CEN_UNLOCK);
- }
- #endif
-
- ret = i2c_transfer(felica_i2c_client->adapter, &read_msgs[0], 1);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(i2c_transfer[0]), ret=[%d]",
- __func__, ret);
- return -EIO;
- }
- ret = i2c_transfer(felica_i2c_client->adapter, &read_msgs[1], 1);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(i2c_transfer[1]), ret=[%d]",
- __func__, ret);
- return -EIO;
- }
- FELICA_PR_INFO(" %s read_buff=[%d]", __func__, read_buff);
- read_buff &= FELICA_CONTROL_LOCK_MASK;
- FELICA_PR_INFO(" %s read_buff=[%d]", __func__, read_buff);
- g_cen_sts = read_buff;
- #if defined(CONFIG_MACH_HLTEDCM)
- //low
- if (system_rev == HW_REV09_OR_10)
- {
- FELICA_PR_INFO(" %s Making MHL_EN LOW", __func__);
- // of_sii8240_hw_poweron(FELICA_CEN_LOCK);
- }
- #endif
-
- FELICA_PR_DBG(" %s END", __func__);
- return FELICA_CEN_DATA_LEN;
- }
- /******************************************************************************
- * /dev/snfc_cen
- ******************************************************************************/
- /* character device definition */
- static dev_t devid_snfca_cen;
- static struct cdev cdev_snfc_cen;
- static const struct file_operations fops_snfc_cen = {
- .owner = THIS_MODULE,
- .open = snfc_cen_open,
- .release = snfc_cen_close,
- .read = snfc_cen_read,
- };
- /*
- * initialize device
- */
- static void snfc_cen_init(void)
- {
- int ret;
- struct device *device_snfc_cen;
- FELICA_PR_DBG(" %s START", __func__);
- devid_snfca_cen = MKDEV(FELICA_MAJOR, FELICA_MINOR);
- ret =
- alloc_chrdev_region(&devid_snfca_cen, FELICA_BASEMINOR,
- FELICA_MINOR_COUNT, SNFC_CEN_NAME);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(alloc_chrdev_region), ret=[%d]",
- __func__, ret);
- return;
- }
- cdev_init(&cdev_snfc_cen, &fops_snfc_cen);
- ret = cdev_add(&cdev_snfc_cen, devid_snfca_cen, FELICA_MINOR_COUNT);
- if (ret < 0) {
- unregister_chrdev_region(devid_snfca_cen, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(cdev_add), ret=[%d]", __func__,
- ret);
- return;
- }
- device_snfc_cen =
- device_create(felica_class, NULL, devid_snfca_cen, NULL,
- SNFC_CEN_NAME);
- if (IS_ERR(device_snfc_cen)) {
- cdev_del(&cdev_snfc_cen);
- unregister_chrdev_region(devid_snfca_cen, FELICA_MINOR_COUNT);
- FELICA_PR_ERR(" %s ERROR(device_create)", __func__);
- return;
- }
- FELICA_PR_DBG(" %s END, major=[%d], minor=[%d]", __func__,
- MAJOR(devid_snfca_cen), MINOR(devid_snfca_cen));
- }
- /*
- * finalize device
- */
- static void snfc_cen_exit(void)
- {
- FELICA_PR_DBG(" %s START", __func__);
- device_destroy(felica_class, devid_snfca_cen);
- cdev_del(&cdev_snfc_cen);
- unregister_chrdev_region(devid_snfca_cen, FELICA_MINOR_COUNT);
- FELICA_PR_DBG(" %s END", __func__);
- }
- /*
- * open device
- */
- static int snfc_cen_open(struct inode *inode, struct file *file)
- {
- uid_t uid;
- #ifdef FELICA_UICC_FUNCTION
- int ret = 0;
- char *cmdpos;
- static char cmdline[1025];
- static unsigned long start_adr, end_adr, leng;
- #endif
- FELICA_PR_DBG(" %s START . system_rev=[%d]", __func__,system_rev);
- #if defined(CONFIG_MACH_HLTEDCM)
- //high
- if (system_rev == HW_REV09_OR_10)
- {
- FELICA_PR_INFO(" %s Making MHL_EN HIGH", __func__);
- of_sii8240_hw_poweron(SNFC_CEN_UNLOCK);
- }
- #endif
-
- #ifdef FELICA_UICC_FUNCTION
- start_adr = current->mm->arg_start;
- end_adr = current->mm->arg_end;
- leng = end_adr - start_adr;
- if (1024 < leng)
- leng = 1024;
- cmdpos = (char *)(current->mm->arg_start);
- ret = copy_from_user(cmdline, cmdpos, leng);
- cmdline[leng] = '\0';
- if(ret != 0)
- {
- FELICA_PR_ERR(" %s cmdline[%s] ret[%d]", __func__, cmdline, ret);
- return -EFAULT;
- }
- #endif
- uid = __task_cred(current)->uid;
- if (file->f_mode & FMODE_WRITE) {
- #ifdef FELICA_UICC_FUNCTION
- if ((uid != gdiag_uid) && (uid != gmfl_uid)
- && (strncmp(cmdline,gproc_name, leng) != 0)) {
- #else
- if ((uid != gdiag_uid) && (uid != gmfl_uid)) {
- #endif
- 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);
- #if defined(CONFIG_MACH_HLTEDCM)
- //low
- if (system_rev == HW_REV09_OR_10)
- {
- FELICA_PR_INFO(" %s Making MHL_EN LOW", __func__);
- // of_sii8240_hw_poweron(SNFC_CEN_LOCK);
- }
- #endif
- #ifdef SRIB_DIAG_ENABLED
- FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
- #else
- return -EACCES;
- #endif
- }
- }
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- /*
- * close device
- */
- static int snfc_cen_close(struct inode *inode, struct file *file)
- {
- /* no operation */
- #if defined(CONFIG_MACH_HLTEDCM)
- //low
- if (system_rev == HW_REV09_OR_10)
- {
- FELICA_PR_INFO(" %s Making MHL_EN LOW", __func__);
- // of_sii8240_hw_poweron(SNFC_CEN_LOCK);
- }
- #endif
-
- FELICA_PR_DBG(" %s END system_rev=[%d]", __func__,system_rev);
- return 0;
- }
- /*
- * read operation
- */
- static ssize_t snfc_cen_read(struct file *file, char __user *buf, \
- size_t len, loff_t *ppos)
- {
- int ret;
- unsigned char address = gi2c_lockaddress;
- unsigned char read_buff = 0;
- struct i2c_msg read_msgs[2];
- read_msgs[0].flags = gread_msgs[0].flags;
- read_msgs[0].len = gread_msgs[0].len;
- read_msgs[1].flags = gread_msgs[1].flags;
- read_msgs[1].len = gread_msgs[1].len;
- read_msgs[0].addr = gi2c_address;
- read_msgs[0].buf = &address;
- read_msgs[1].addr = gi2c_address;
- read_msgs[1].buf = &read_buff;
- if (felica_i2c_client == NULL) {
- FELICA_PR_ERR(" felica_i2c_client is NULL %s -EIO",__func__);
- return -EIO;
- }
- ret = i2c_transfer(felica_i2c_client->adapter, &read_msgs[0], 1);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(i2c_transfer[0]), ret=[%d]",
- __func__, ret);
- return -EIO;
- }
- ret = i2c_transfer(felica_i2c_client->adapter, &read_msgs[1], 1);
- if (ret < 0) {
- FELICA_PR_ERR(" %s ERROR(i2c_transfer[1]), ret=[%d]",
- __func__, ret);
- return -EIO;
- }
- read_buff &= SNFC_CONTROL_LOCK_MASK;
- #ifdef CONFIG_NFC_FELICA
- g_cen_sts = read_buff;
- #endif
- FELICA_PR_DBG(" %s g_cen_sts=[%d]", __func__, g_cen_sts);
- ret = copy_to_user(buf, &read_buff, SNFC_CEN_DATA_LEN);
- if (ret != 0) {
- FELICA_PR_ERR(" %s ERROR(copy_to_user), ret=[%d]",
- __func__, ret);
- return -EFAULT;
- }
- *ppos += 1;
- return SNFC_CEN_DATA_LEN;
- }
- /*
- * uid check
- */
- static int snfc_uid_check(void)
- {
- uid_t uid;
- uid = __task_cred(current)->uid;
- FELICA_PR_DBG(" %s START", __func__);
- FELICA_PR_INFO(" %s gnfc_uid=[%d]", __func__, (int)gnfc_uid);
- if ((uid != gnfc_uid) && (uid != gdiag_uid)) {
- FELICA_PR_ERR
- (" %s END, uid=[%d], gnfc_uid=[%d], gdiag_uid=[%d]", \
- __func__, uid, gnfc_uid, gdiag_uid);
- #ifdef SRIB_DIAG_ENABLED
- FELICA_PR_ERR(" SRIB-Diag enabled just for test\n");
- #else
- return -1;
- #endif
- }
- FELICA_PR_DBG(" %s END", __func__);
- return 0;
- }
- #endif /* CONFIG_NFC_FELICA */
- module_init(felica_init);
- module_exit(felica_exit);
- MODULE_DESCRIPTION("felica_dd");
- MODULE_LICENSE("GPL v2");
- #endif /* CONFIG_FELICA */
|