radio-iris.c 131 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162
  1. /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #define DRIVER_AUTHOR "Archana Ramchandran <archanar@codeaurora.org>"
  13. #define DRIVER_NAME "radio-iris"
  14. #define DRIVER_CARD "Qualcomm FM Radio Transceiver"
  15. #define DRIVER_DESC "Driver for Qualcomm FM Radio Transceiver "
  16. #include <linux/version.h>
  17. #include <linux/init.h>
  18. #include <linux/delay.h>
  19. #include <linux/uaccess.h>
  20. #include <linux/kfifo.h>
  21. #include <linux/param.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/sched.h>
  26. #include <linux/version.h>
  27. #include <linux/videodev2.h>
  28. #include <linux/mutex.h>
  29. #include <linux/unistd.h>
  30. #include <linux/atomic.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/workqueue.h>
  33. #include <linux/slab.h>
  34. #include <media/v4l2-common.h>
  35. #include <media/v4l2-ioctl.h>
  36. #include <media/radio-iris.h>
  37. #include <asm/unaligned.h>
  38. static unsigned int rds_buf = 100;
  39. static int oda_agt;
  40. static int grp_mask;
  41. static int rt_plus_carrier = -1;
  42. static int ert_carrier = -1;
  43. static unsigned char ert_buf[256];
  44. static unsigned char ert_len;
  45. static unsigned char c_byt_pair_index;
  46. static char utf_8_flag;
  47. static char rt_ert_flag;
  48. static char formatting_dir;
  49. static unsigned char sig_blend = CTRL_ON;
  50. static DEFINE_MUTEX(iris_fm);
  51. module_param(rds_buf, uint, 0);
  52. MODULE_PARM_DESC(rds_buf, "RDS buffer entries: *100*");
  53. module_param(sig_blend, byte, S_IWUSR | S_IRUGO);
  54. MODULE_PARM_DESC(sig_blend, "signal blending switch: 0:OFF 1:ON");
  55. static void radio_hci_cmd_task(unsigned long arg);
  56. static void radio_hci_rx_task(unsigned long arg);
  57. static struct video_device *video_get_dev(void);
  58. static DEFINE_RWLOCK(hci_task_lock);
  59. extern struct mutex fm_smd_enable;
  60. typedef int (*radio_hci_request_func)(struct radio_hci_dev *hdev,
  61. int (*req)(struct
  62. radio_hci_dev * hdev, unsigned long param),
  63. unsigned long param, __u32 timeout);
  64. struct iris_device {
  65. struct device *dev;
  66. struct kfifo data_buf[IRIS_BUF_MAX];
  67. int pending_xfrs[IRIS_XFR_MAX];
  68. int xfr_bytes_left;
  69. int xfr_in_progress;
  70. struct completion sync_xfr_start;
  71. int tune_req;
  72. unsigned int mode;
  73. int is_fm_closing;
  74. __u16 pi;
  75. __u8 pty;
  76. __u8 ps_repeatcount;
  77. __u8 prev_trans_rds;
  78. __u8 af_jump_bit;
  79. struct video_device *videodev;
  80. struct mutex lock;
  81. spinlock_t buf_lock[IRIS_BUF_MAX];
  82. wait_queue_head_t event_queue;
  83. wait_queue_head_t read_queue;
  84. struct radio_hci_dev *fm_hdev;
  85. struct v4l2_capability *g_cap;
  86. struct v4l2_control *g_ctl;
  87. struct hci_fm_mute_mode_req mute_mode;
  88. struct hci_fm_stereo_mode_req stereo_mode;
  89. struct hci_fm_station_rsp fm_st_rsp;
  90. struct hci_fm_search_station_req srch_st;
  91. struct hci_fm_search_rds_station_req srch_rds;
  92. struct hci_fm_search_station_list_req srch_st_list;
  93. struct hci_fm_recv_conf_req recv_conf;
  94. struct hci_fm_trans_conf_req_struct trans_conf;
  95. struct hci_fm_rds_grp_req rds_grp;
  96. unsigned char g_search_mode;
  97. unsigned char power_mode;
  98. int search_on;
  99. unsigned int tone_freq;
  100. unsigned char spur_table_size;
  101. unsigned char g_scan_time;
  102. unsigned int g_antenna;
  103. unsigned int g_rds_grp_proc_ps;
  104. unsigned char event_mask;
  105. enum iris_region_t region;
  106. struct hci_fm_dbg_param_rsp st_dbg_param;
  107. struct hci_ev_srch_list_compl srch_st_result;
  108. struct hci_fm_riva_poke riva_data_req;
  109. struct hci_fm_ssbi_req ssbi_data_accs;
  110. struct hci_fm_ssbi_peek ssbi_peek_reg;
  111. struct hci_fm_sig_threshold_rsp sig_th;
  112. struct hci_fm_ch_det_threshold ch_det_threshold;
  113. struct hci_fm_data_rd_rsp default_data;
  114. struct hci_fm_spur_data spur_data;
  115. unsigned char is_station_valid;
  116. struct hci_fm_blend_table blend_tbl;
  117. char is_rds_grp_3A_enabled;
  118. char is_ert_enabled;
  119. char is_rt_plus_enabled;
  120. };
  121. static struct video_device *priv_videodev;
  122. static int iris_do_calibration(struct iris_device *radio);
  123. static void hci_buff_ert(struct iris_device *radio,
  124. struct rds_grp_data *rds_buf);
  125. static void hci_ev_rt_plus(struct iris_device *radio,
  126. struct rds_grp_data rds_buf);
  127. static void hci_ev_ert(struct iris_device *radio);
  128. static int update_spur_table(struct iris_device *radio);
  129. static int initialise_recv(struct iris_device *radio);
  130. static int initialise_trans(struct iris_device *radio);
  131. static int is_enable_rx_possible(struct iris_device *radio);
  132. static int is_enable_tx_possible(struct iris_device *radio);
  133. static struct v4l2_queryctrl iris_v4l2_queryctrl[] = {
  134. {
  135. .id = V4L2_CID_AUDIO_VOLUME,
  136. .type = V4L2_CTRL_TYPE_INTEGER,
  137. .name = "Volume",
  138. .minimum = 0,
  139. .maximum = 15,
  140. .step = 1,
  141. .default_value = 15,
  142. },
  143. {
  144. .id = V4L2_CID_AUDIO_BALANCE,
  145. .flags = V4L2_CTRL_FLAG_DISABLED,
  146. },
  147. {
  148. .id = V4L2_CID_AUDIO_BASS,
  149. .flags = V4L2_CTRL_FLAG_DISABLED,
  150. },
  151. {
  152. .id = V4L2_CID_AUDIO_TREBLE,
  153. .flags = V4L2_CTRL_FLAG_DISABLED,
  154. },
  155. {
  156. .id = V4L2_CID_AUDIO_MUTE,
  157. .type = V4L2_CTRL_TYPE_BOOLEAN,
  158. .name = "Mute",
  159. .minimum = 0,
  160. .maximum = 1,
  161. .step = 1,
  162. .default_value = 1,
  163. },
  164. {
  165. .id = V4L2_CID_AUDIO_LOUDNESS,
  166. .flags = V4L2_CTRL_FLAG_DISABLED,
  167. },
  168. {
  169. .id = V4L2_CID_PRIVATE_IRIS_SRCHMODE,
  170. .type = V4L2_CTRL_TYPE_INTEGER,
  171. .name = "Search mode",
  172. .minimum = 0,
  173. .maximum = 7,
  174. .step = 1,
  175. .default_value = 0,
  176. },
  177. {
  178. .id = V4L2_CID_PRIVATE_IRIS_SCANDWELL,
  179. .type = V4L2_CTRL_TYPE_INTEGER,
  180. .name = "Search dwell time",
  181. .minimum = 0,
  182. .maximum = 7,
  183. .step = 1,
  184. .default_value = 0,
  185. },
  186. {
  187. .id = V4L2_CID_PRIVATE_IRIS_SRCHON,
  188. .type = V4L2_CTRL_TYPE_BOOLEAN,
  189. .name = "Search on/off",
  190. .minimum = 0,
  191. .maximum = 1,
  192. .step = 1,
  193. .default_value = 1,
  194. },
  195. {
  196. .id = V4L2_CID_PRIVATE_IRIS_STATE,
  197. .type = V4L2_CTRL_TYPE_INTEGER,
  198. .name = "radio 0ff/rx/tx/reset",
  199. .minimum = 0,
  200. .maximum = 3,
  201. .step = 1,
  202. .default_value = 1,
  203. },
  204. {
  205. .id = V4L2_CID_PRIVATE_IRIS_REGION,
  206. .type = V4L2_CTRL_TYPE_INTEGER,
  207. .name = "radio standard",
  208. .minimum = 0,
  209. .maximum = 2,
  210. .step = 1,
  211. .default_value = 0,
  212. },
  213. {
  214. .id = V4L2_CID_PRIVATE_IRIS_SIGNAL_TH,
  215. .type = V4L2_CTRL_TYPE_INTEGER,
  216. .name = "Signal Threshold",
  217. .minimum = 0x80,
  218. .maximum = 0x7F,
  219. .step = 1,
  220. .default_value = 0,
  221. },
  222. {
  223. .id = V4L2_CID_PRIVATE_IRIS_SRCH_PTY,
  224. .type = V4L2_CTRL_TYPE_INTEGER,
  225. .name = "Search PTY",
  226. .minimum = 0,
  227. .maximum = 31,
  228. .default_value = 0,
  229. },
  230. {
  231. .id = V4L2_CID_PRIVATE_IRIS_SRCH_PI,
  232. .type = V4L2_CTRL_TYPE_INTEGER,
  233. .name = "Search PI",
  234. .minimum = 0,
  235. .maximum = 0xFF,
  236. .default_value = 0,
  237. },
  238. {
  239. .id = V4L2_CID_PRIVATE_IRIS_SRCH_CNT,
  240. .type = V4L2_CTRL_TYPE_INTEGER,
  241. .name = "Preset num",
  242. .minimum = 0,
  243. .maximum = 12,
  244. .default_value = 0,
  245. },
  246. {
  247. .id = V4L2_CID_PRIVATE_IRIS_EMPHASIS,
  248. .type = V4L2_CTRL_TYPE_BOOLEAN,
  249. .name = "Emphasis",
  250. .minimum = 0,
  251. .maximum = 1,
  252. .default_value = 0,
  253. },
  254. {
  255. .id = V4L2_CID_PRIVATE_IRIS_RDS_STD,
  256. .type = V4L2_CTRL_TYPE_BOOLEAN,
  257. .name = "RDS standard",
  258. .minimum = 0,
  259. .maximum = 1,
  260. .default_value = 0,
  261. },
  262. {
  263. .id = V4L2_CID_PRIVATE_IRIS_SPACING,
  264. .type = V4L2_CTRL_TYPE_INTEGER,
  265. .name = "Channel spacing",
  266. .minimum = 0,
  267. .maximum = 2,
  268. .default_value = 0,
  269. },
  270. {
  271. .id = V4L2_CID_PRIVATE_IRIS_RDSON,
  272. .type = V4L2_CTRL_TYPE_BOOLEAN,
  273. .name = "RDS on/off",
  274. .minimum = 0,
  275. .maximum = 1,
  276. .default_value = 0,
  277. },
  278. {
  279. .id = V4L2_CID_PRIVATE_IRIS_RDSGROUP_MASK,
  280. .type = V4L2_CTRL_TYPE_INTEGER,
  281. .name = "RDS group mask",
  282. .minimum = 0,
  283. .maximum = 0xFFFFFFFF,
  284. .default_value = 0,
  285. },
  286. {
  287. .id = V4L2_CID_PRIVATE_IRIS_RDSGROUP_PROC,
  288. .type = V4L2_CTRL_TYPE_INTEGER,
  289. .name = "RDS processing",
  290. .minimum = 0,
  291. .maximum = 0xFF,
  292. .default_value = 0,
  293. },
  294. {
  295. .id = V4L2_CID_PRIVATE_IRIS_RDSD_BUF,
  296. .type = V4L2_CTRL_TYPE_INTEGER,
  297. .name = "RDS data groups to buffer",
  298. .minimum = 1,
  299. .maximum = 21,
  300. .default_value = 0,
  301. },
  302. {
  303. .id = V4L2_CID_PRIVATE_IRIS_PSALL,
  304. .type = V4L2_CTRL_TYPE_BOOLEAN,
  305. .name = "pass all ps strings",
  306. .minimum = 0,
  307. .maximum = 1,
  308. .default_value = 0,
  309. },
  310. {
  311. .id = V4L2_CID_PRIVATE_IRIS_LP_MODE,
  312. .type = V4L2_CTRL_TYPE_BOOLEAN,
  313. .name = "Low power mode",
  314. .minimum = 0,
  315. .maximum = 1,
  316. .default_value = 0,
  317. },
  318. {
  319. .id = V4L2_CID_PRIVATE_IRIS_ANTENNA,
  320. .type = V4L2_CTRL_TYPE_BOOLEAN,
  321. .name = "headset/internal",
  322. .minimum = 0,
  323. .maximum = 1,
  324. .default_value = 0,
  325. },
  326. {
  327. .id = V4L2_CID_PRIVATE_IRIS_TX_SETPSREPEATCOUNT,
  328. .type = V4L2_CTRL_TYPE_INTEGER,
  329. .name = "Set PS REPEATCOUNT",
  330. .minimum = 0,
  331. .maximum = 15,
  332. },
  333. {
  334. .id = V4L2_CID_PRIVATE_IRIS_STOP_RDS_TX_PS_NAME,
  335. .type = V4L2_CTRL_TYPE_BOOLEAN,
  336. .name = "Stop PS NAME",
  337. .minimum = 0,
  338. .maximum = 1,
  339. },
  340. {
  341. .id = V4L2_CID_PRIVATE_IRIS_STOP_RDS_TX_RT,
  342. .type = V4L2_CTRL_TYPE_BOOLEAN,
  343. .name = "Stop RT",
  344. .minimum = 0,
  345. .maximum = 1,
  346. },
  347. {
  348. .id = V4L2_CID_PRIVATE_IRIS_SOFT_MUTE,
  349. .type = V4L2_CTRL_TYPE_BOOLEAN,
  350. .name = "Soft Mute",
  351. .minimum = 0,
  352. .maximum = 1,
  353. },
  354. {
  355. .id = V4L2_CID_PRIVATE_IRIS_RIVA_ACCS_ADDR,
  356. .type = V4L2_CTRL_TYPE_BOOLEAN,
  357. .name = "Riva addr",
  358. .minimum = 0x3180000,
  359. .maximum = 0x31E0004,
  360. },
  361. {
  362. .id = V4L2_CID_PRIVATE_IRIS_RIVA_ACCS_LEN,
  363. .type = V4L2_CTRL_TYPE_INTEGER,
  364. .name = "Data len",
  365. .minimum = 0,
  366. .maximum = 0xFF,
  367. },
  368. {
  369. .id = V4L2_CID_PRIVATE_IRIS_RIVA_PEEK,
  370. .type = V4L2_CTRL_TYPE_BOOLEAN,
  371. .name = "Riva peek",
  372. .minimum = 0,
  373. .maximum = 1,
  374. },
  375. {
  376. .id = V4L2_CID_PRIVATE_IRIS_RIVA_POKE,
  377. .type = V4L2_CTRL_TYPE_INTEGER,
  378. .name = "Riva poke",
  379. .minimum = 0x3180000,
  380. .maximum = 0x31E0004,
  381. },
  382. {
  383. .id = V4L2_CID_PRIVATE_IRIS_SSBI_ACCS_ADDR,
  384. .type = V4L2_CTRL_TYPE_INTEGER,
  385. .name = "Ssbi addr",
  386. .minimum = 0x280,
  387. .maximum = 0x37F,
  388. },
  389. {
  390. .id = V4L2_CID_PRIVATE_IRIS_SSBI_PEEK,
  391. .type = V4L2_CTRL_TYPE_INTEGER,
  392. .name = "Ssbi peek",
  393. .minimum = 0,
  394. .maximum = 0x37F,
  395. },
  396. {
  397. .id = V4L2_CID_PRIVATE_IRIS_SSBI_POKE,
  398. .type = V4L2_CTRL_TYPE_INTEGER,
  399. .name = "ssbi poke",
  400. .minimum = 0x01,
  401. .maximum = 0xFF,
  402. },
  403. {
  404. .id = V4L2_CID_PRIVATE_IRIS_HLSI,
  405. .type = V4L2_CTRL_TYPE_INTEGER,
  406. .name = "set hlsi",
  407. .minimum = 0,
  408. .maximum = 2,
  409. },
  410. {
  411. .id = V4L2_CID_PRIVATE_IRIS_RDS_GRP_COUNTERS,
  412. .type = V4L2_CTRL_TYPE_BOOLEAN,
  413. .name = "RDS grp",
  414. .minimum = 0,
  415. .maximum = 1,
  416. },
  417. {
  418. .id = V4L2_CID_PRIVATE_IRIS_SET_NOTCH_FILTER,
  419. .type = V4L2_CTRL_TYPE_INTEGER,
  420. .name = "Notch filter",
  421. .minimum = 0,
  422. .maximum = 2,
  423. },
  424. {
  425. .id = V4L2_CID_PRIVATE_IRIS_READ_DEFAULT,
  426. .type = V4L2_CTRL_TYPE_INTEGER,
  427. .name = "Read default",
  428. },
  429. {
  430. .id = V4L2_CID_PRIVATE_IRIS_WRITE_DEFAULT,
  431. .type = V4L2_CTRL_TYPE_INTEGER,
  432. .name = "Write default",
  433. },
  434. {
  435. .id = V4L2_CID_PRIVATE_IRIS_SET_CALIBRATION,
  436. .type = V4L2_CTRL_TYPE_BOOLEAN,
  437. .name = "SET Calibration",
  438. .minimum = 0,
  439. .maximum = 1,
  440. },
  441. {
  442. .id = V4L2_CID_PRIVATE_IRIS_DO_CALIBRATION,
  443. .type = V4L2_CTRL_TYPE_BOOLEAN,
  444. .name = "SET Calibration",
  445. .minimum = 0,
  446. .maximum = 1,
  447. },
  448. {
  449. .id = V4L2_CID_PRIVATE_IRIS_GET_SINR,
  450. .type = V4L2_CTRL_TYPE_INTEGER,
  451. .name = "GET SINR",
  452. .minimum = -128,
  453. .maximum = 127,
  454. },
  455. {
  456. .id = V4L2_CID_PRIVATE_INTF_HIGH_THRESHOLD,
  457. .type = V4L2_CTRL_TYPE_INTEGER,
  458. .name = "Intf High Threshold",
  459. .minimum = 0,
  460. .maximum = 0xFF,
  461. .default_value = 0,
  462. },
  463. {
  464. .id = V4L2_CID_PRIVATE_INTF_LOW_THRESHOLD,
  465. .type = V4L2_CTRL_TYPE_INTEGER,
  466. .name = "Intf low Threshold",
  467. .minimum = 0,
  468. .maximum = 0xFF,
  469. .default_value = 0,
  470. },
  471. {
  472. .id = V4L2_CID_PRIVATE_SINR_THRESHOLD,
  473. .type = V4L2_CTRL_TYPE_INTEGER,
  474. .name = "SINR Threshold",
  475. .minimum = -128,
  476. .maximum = 127,
  477. .default_value = 0,
  478. },
  479. {
  480. .id = V4L2_CID_PRIVATE_SINR_SAMPLES,
  481. .type = V4L2_CTRL_TYPE_INTEGER,
  482. .name = "SINR samples",
  483. .minimum = 1,
  484. .maximum = 0xFF,
  485. .default_value = 0,
  486. },
  487. };
  488. static void iris_q_event(struct iris_device *radio,
  489. enum iris_evt_t event)
  490. {
  491. struct kfifo *data_b = &radio->data_buf[IRIS_BUF_EVENTS];
  492. unsigned char evt = event;
  493. if (radio == NULL) {
  494. FMDERR(":radio is null");
  495. return;
  496. }
  497. if (kfifo_in_locked(data_b, &evt, 1, &radio->buf_lock[IRIS_BUF_EVENTS]))
  498. wake_up_interruptible(&radio->event_queue);
  499. }
  500. static int hci_send_frame(struct sk_buff *skb)
  501. {
  502. struct radio_hci_dev *hdev = (struct radio_hci_dev *) skb->dev;
  503. if (!hdev) {
  504. kfree_skb(skb);
  505. return -ENODEV;
  506. }
  507. __net_timestamp(skb);
  508. skb_orphan(skb);
  509. return hdev->send(skb);
  510. }
  511. static void radio_hci_cmd_task(unsigned long arg)
  512. {
  513. struct radio_hci_dev *hdev = (struct radio_hci_dev *) arg;
  514. struct sk_buff *skb;
  515. if (!(atomic_read(&hdev->cmd_cnt))
  516. && time_after(jiffies, hdev->cmd_last_tx + HZ)) {
  517. FMDERR("%s command tx timeout", hdev->name);
  518. atomic_set(&hdev->cmd_cnt, 1);
  519. }
  520. skb = skb_dequeue(&hdev->cmd_q);
  521. if (atomic_read(&hdev->cmd_cnt) && skb) {
  522. kfree_skb(hdev->sent_cmd);
  523. hdev->sent_cmd = skb_clone(skb, GFP_ATOMIC);
  524. if (hdev->sent_cmd) {
  525. atomic_dec(&hdev->cmd_cnt);
  526. hci_send_frame(skb);
  527. hdev->cmd_last_tx = jiffies;
  528. } else {
  529. skb_queue_head(&hdev->cmd_q, skb);
  530. tasklet_schedule(&hdev->cmd_task);
  531. }
  532. }
  533. }
  534. static void radio_hci_rx_task(unsigned long arg)
  535. {
  536. struct radio_hci_dev *hdev = (struct radio_hci_dev *) arg;
  537. struct sk_buff *skb;
  538. read_lock(&hci_task_lock);
  539. skb = skb_dequeue(&hdev->rx_q);
  540. radio_hci_event_packet(hdev, skb);
  541. read_unlock(&hci_task_lock);
  542. }
  543. int radio_hci_register_dev(struct radio_hci_dev *hdev)
  544. {
  545. struct iris_device *radio = video_get_drvdata(video_get_dev());
  546. if (!radio) {
  547. FMDERR(":radio is null");
  548. return -EINVAL;
  549. }
  550. if (!hdev) {
  551. FMDERR("hdev is null");
  552. return -EINVAL;
  553. }
  554. hdev->flags = 0;
  555. tasklet_init(&hdev->cmd_task, radio_hci_cmd_task, (unsigned long)
  556. hdev);
  557. tasklet_init(&hdev->rx_task, radio_hci_rx_task, (unsigned long)
  558. hdev);
  559. init_waitqueue_head(&hdev->req_wait_q);
  560. skb_queue_head_init(&hdev->rx_q);
  561. skb_queue_head_init(&hdev->cmd_q);
  562. skb_queue_head_init(&hdev->raw_q);
  563. if (!radio)
  564. FMDERR(":radio is null");
  565. radio->fm_hdev = hdev;
  566. return 0;
  567. }
  568. EXPORT_SYMBOL(radio_hci_register_dev);
  569. int radio_hci_unregister_dev(void)
  570. {
  571. struct iris_device *radio = video_get_drvdata(video_get_dev());
  572. struct radio_hci_dev *hdev = NULL;
  573. if (!radio && !radio->fm_hdev) {
  574. FMDERR("radio/hdev is null");
  575. return -EINVAL;
  576. }
  577. hdev = radio->fm_hdev;
  578. tasklet_kill(&hdev->rx_task);
  579. tasklet_kill(&hdev->cmd_task);
  580. skb_queue_purge(&hdev->rx_q);
  581. skb_queue_purge(&hdev->cmd_q);
  582. skb_queue_purge(&hdev->raw_q);
  583. radio->fm_hdev = NULL;
  584. return 0;
  585. }
  586. EXPORT_SYMBOL(radio_hci_unregister_dev);
  587. int radio_hci_recv_frame(struct sk_buff *skb)
  588. {
  589. struct radio_hci_dev *hdev = (struct radio_hci_dev *) skb->dev;
  590. if (!hdev) {
  591. FMDERR("%s hdev is null while receiving frame", hdev->name);
  592. kfree_skb(skb);
  593. return -ENXIO;
  594. }
  595. __net_timestamp(skb);
  596. radio_hci_event_packet(hdev, skb);
  597. kfree_skb(skb);
  598. return 0;
  599. }
  600. EXPORT_SYMBOL(radio_hci_recv_frame);
  601. int radio_hci_send_cmd(struct radio_hci_dev *hdev, __u16 opcode, __u32 plen,
  602. void *param)
  603. {
  604. int len = RADIO_HCI_COMMAND_HDR_SIZE + plen;
  605. struct radio_hci_command_hdr *hdr;
  606. struct sk_buff *skb;
  607. int ret = 0;
  608. skb = alloc_skb(len, GFP_ATOMIC);
  609. if (!skb) {
  610. FMDERR("%s no memory for command", hdev->name);
  611. return -ENOMEM;
  612. }
  613. hdr = (struct radio_hci_command_hdr *) skb_put(skb,
  614. RADIO_HCI_COMMAND_HDR_SIZE);
  615. hdr->opcode = cpu_to_le16(opcode);
  616. hdr->plen = plen;
  617. if (plen)
  618. memcpy(skb_put(skb, plen), param, plen);
  619. skb->dev = (void *) hdev;
  620. ret = hci_send_frame(skb);
  621. return ret;
  622. }
  623. EXPORT_SYMBOL(radio_hci_send_cmd);
  624. static int hci_fm_enable_recv_req(struct radio_hci_dev *hdev,
  625. unsigned long param)
  626. {
  627. __u16 opcode = 0;
  628. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  629. HCI_OCF_FM_ENABLE_RECV_REQ);
  630. return radio_hci_send_cmd(hdev, opcode, 0, NULL);
  631. }
  632. static int hci_fm_tone_generator(struct radio_hci_dev *hdev,
  633. unsigned long param)
  634. {
  635. struct iris_device *radio = video_get_drvdata(video_get_dev());
  636. __u16 opcode = 0;
  637. if (radio == NULL) {
  638. FMDERR(":radio is null");
  639. return -EINVAL;
  640. }
  641. opcode = hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ,
  642. HCI_FM_SET_INTERNAL_TONE_GENRATOR);
  643. return radio_hci_send_cmd(hdev, opcode,
  644. sizeof(radio->tone_freq), &radio->tone_freq);
  645. }
  646. static int hci_fm_enable_trans_req(struct radio_hci_dev *hdev,
  647. unsigned long param)
  648. {
  649. __u16 opcode = 0;
  650. opcode = hci_opcode_pack(HCI_OGF_FM_TRANS_CTRL_CMD_REQ,
  651. HCI_OCF_FM_ENABLE_TRANS_REQ);
  652. return radio_hci_send_cmd(hdev, opcode, 0, NULL);
  653. }
  654. static int hci_fm_disable_recv_req(struct radio_hci_dev *hdev,
  655. unsigned long param)
  656. {
  657. __u16 opcode = 0;
  658. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  659. HCI_OCF_FM_DISABLE_RECV_REQ);
  660. return radio_hci_send_cmd(hdev, opcode, 0, NULL);
  661. }
  662. static int hci_fm_disable_trans_req(struct radio_hci_dev *hdev,
  663. unsigned long param)
  664. {
  665. __u16 opcode = 0;
  666. opcode = hci_opcode_pack(HCI_OGF_FM_TRANS_CTRL_CMD_REQ,
  667. HCI_OCF_FM_DISABLE_TRANS_REQ);
  668. return radio_hci_send_cmd(hdev, opcode, 0, NULL);
  669. }
  670. static int hci_get_fm_recv_conf_req(struct radio_hci_dev *hdev,
  671. unsigned long param)
  672. {
  673. __u16 opcode = 0;
  674. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  675. HCI_OCF_FM_GET_RECV_CONF_REQ);
  676. return radio_hci_send_cmd(hdev, opcode, 0, NULL);
  677. }
  678. static int hci_get_fm_trans_conf_req(struct radio_hci_dev *hdev,
  679. unsigned long param)
  680. {
  681. u16 opcode = 0;
  682. opcode = hci_opcode_pack(HCI_OGF_FM_TRANS_CTRL_CMD_REQ,
  683. HCI_OCF_FM_GET_TRANS_CONF_REQ);
  684. return radio_hci_send_cmd(hdev, opcode, 0, NULL);
  685. }
  686. static int hci_set_fm_recv_conf_req(struct radio_hci_dev *hdev,
  687. unsigned long param)
  688. {
  689. __u16 opcode = 0;
  690. struct hci_fm_recv_conf_req *recv_conf_req =
  691. (struct hci_fm_recv_conf_req *) param;
  692. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  693. HCI_OCF_FM_SET_RECV_CONF_REQ);
  694. return radio_hci_send_cmd(hdev, opcode, sizeof((*recv_conf_req)),
  695. recv_conf_req);
  696. }
  697. static int hci_set_fm_trans_conf_req(struct radio_hci_dev *hdev,
  698. unsigned long param)
  699. {
  700. __u16 opcode = 0;
  701. struct hci_fm_trans_conf_req_struct *trans_conf_req =
  702. (struct hci_fm_trans_conf_req_struct *) param;
  703. opcode = hci_opcode_pack(HCI_OGF_FM_TRANS_CTRL_CMD_REQ,
  704. HCI_OCF_FM_SET_TRANS_CONF_REQ);
  705. return radio_hci_send_cmd(hdev, opcode, sizeof((*trans_conf_req)),
  706. trans_conf_req);
  707. }
  708. static int hci_fm_get_station_param_req(struct radio_hci_dev *hdev,
  709. unsigned long param)
  710. {
  711. __u16 opcode = 0;
  712. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  713. HCI_OCF_FM_GET_STATION_PARAM_REQ);
  714. return radio_hci_send_cmd(hdev, opcode, 0, NULL);
  715. }
  716. static int hci_set_fm_mute_mode_req(struct radio_hci_dev *hdev,
  717. unsigned long param)
  718. {
  719. __u16 opcode = 0;
  720. struct hci_fm_mute_mode_req *mute_mode_req =
  721. (struct hci_fm_mute_mode_req *) param;
  722. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  723. HCI_OCF_FM_SET_MUTE_MODE_REQ);
  724. return radio_hci_send_cmd(hdev, opcode, sizeof((*mute_mode_req)),
  725. mute_mode_req);
  726. }
  727. static int hci_trans_ps_req(struct radio_hci_dev *hdev,
  728. unsigned long param)
  729. {
  730. __u16 opcode = 0;
  731. struct hci_fm_tx_ps *tx_ps_req =
  732. (struct hci_fm_tx_ps *) param;
  733. opcode = hci_opcode_pack(HCI_OGF_FM_TRANS_CTRL_CMD_REQ,
  734. HCI_OCF_FM_RDS_PS_REQ);
  735. return radio_hci_send_cmd(hdev, opcode, sizeof((*tx_ps_req)),
  736. tx_ps_req);
  737. }
  738. static int hci_trans_rt_req(struct radio_hci_dev *hdev,
  739. unsigned long param)
  740. {
  741. __u16 opcode = 0;
  742. struct hci_fm_tx_rt *tx_rt_req =
  743. (struct hci_fm_tx_rt *) param;
  744. opcode = hci_opcode_pack(HCI_OGF_FM_TRANS_CTRL_CMD_REQ,
  745. HCI_OCF_FM_RDS_RT_REQ);
  746. return radio_hci_send_cmd(hdev, opcode, sizeof((*tx_rt_req)),
  747. tx_rt_req);
  748. }
  749. static int hci_set_fm_stereo_mode_req(struct radio_hci_dev *hdev,
  750. unsigned long param)
  751. {
  752. __u16 opcode = 0;
  753. struct hci_fm_stereo_mode_req *stereo_mode_req =
  754. (struct hci_fm_stereo_mode_req *) param;
  755. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  756. HCI_OCF_FM_SET_STEREO_MODE_REQ);
  757. return radio_hci_send_cmd(hdev, opcode, sizeof((*stereo_mode_req)),
  758. stereo_mode_req);
  759. }
  760. static int hci_fm_set_antenna_req(struct radio_hci_dev *hdev,
  761. unsigned long param)
  762. {
  763. __u16 opcode = 0;
  764. __u8 antenna = param;
  765. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  766. HCI_OCF_FM_SET_ANTENNA);
  767. return radio_hci_send_cmd(hdev, opcode, sizeof(antenna), &antenna);
  768. }
  769. static int hci_fm_set_sig_threshold_req(struct radio_hci_dev *hdev,
  770. unsigned long param)
  771. {
  772. __u16 opcode = 0;
  773. __u8 sig_threshold = param;
  774. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  775. HCI_OCF_FM_SET_SIGNAL_THRESHOLD);
  776. return radio_hci_send_cmd(hdev, opcode, sizeof(sig_threshold),
  777. &sig_threshold);
  778. }
  779. static int hci_fm_set_event_mask(struct radio_hci_dev *hdev,
  780. unsigned long param)
  781. {
  782. u16 opcode = 0;
  783. u8 event_mask = param;
  784. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  785. HCI_OCF_FM_SET_EVENT_MASK);
  786. return radio_hci_send_cmd(hdev, opcode, sizeof(event_mask),
  787. &event_mask);
  788. }
  789. static int hci_fm_get_sig_threshold_req(struct radio_hci_dev *hdev,
  790. unsigned long param)
  791. {
  792. __u16 opcode = 0;
  793. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  794. HCI_OCF_FM_GET_SIGNAL_THRESHOLD);
  795. return radio_hci_send_cmd(hdev, opcode, 0, NULL);
  796. }
  797. static int hci_fm_get_program_service_req(struct radio_hci_dev *hdev,
  798. unsigned long param)
  799. {
  800. __u16 opcode = 0;
  801. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  802. HCI_OCF_FM_GET_PROGRAM_SERVICE_REQ);
  803. return radio_hci_send_cmd(hdev, opcode, 0, NULL);
  804. }
  805. static int hci_fm_get_radio_text_req(struct radio_hci_dev *hdev,
  806. unsigned long param)
  807. {
  808. __u16 opcode = 0;
  809. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  810. HCI_OCF_FM_GET_RADIO_TEXT_REQ);
  811. return radio_hci_send_cmd(hdev, opcode, 0, NULL);
  812. }
  813. static int hci_fm_get_af_list_req(struct radio_hci_dev *hdev,
  814. unsigned long param)
  815. {
  816. __u16 opcode = 0;
  817. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  818. HCI_OCF_FM_GET_AF_LIST_REQ);
  819. return radio_hci_send_cmd(hdev, opcode, 0, NULL);
  820. }
  821. static int hci_fm_search_stations_req(struct radio_hci_dev *hdev,
  822. unsigned long param)
  823. {
  824. __u16 opcode = 0;
  825. struct hci_fm_search_station_req *srch_stations =
  826. (struct hci_fm_search_station_req *) param;
  827. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  828. HCI_OCF_FM_SEARCH_STATIONS);
  829. return radio_hci_send_cmd(hdev, opcode, sizeof((*srch_stations)),
  830. srch_stations);
  831. }
  832. static int hci_fm_srch_rds_stations_req(struct radio_hci_dev *hdev,
  833. unsigned long param)
  834. {
  835. __u16 opcode = 0;
  836. struct hci_fm_search_rds_station_req *srch_stations =
  837. (struct hci_fm_search_rds_station_req *) param;
  838. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  839. HCI_OCF_FM_SEARCH_RDS_STATIONS);
  840. return radio_hci_send_cmd(hdev, opcode, sizeof((*srch_stations)),
  841. srch_stations);
  842. }
  843. static int hci_fm_srch_station_list_req(struct radio_hci_dev *hdev,
  844. unsigned long param)
  845. {
  846. __u16 opcode = 0;
  847. struct hci_fm_search_station_list_req *srch_list =
  848. (struct hci_fm_search_station_list_req *) param;
  849. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  850. HCI_OCF_FM_SEARCH_STATIONS_LIST);
  851. return radio_hci_send_cmd(hdev, opcode, sizeof((*srch_list)),
  852. srch_list);
  853. }
  854. static int hci_fm_cancel_search_req(struct radio_hci_dev *hdev,
  855. unsigned long param)
  856. {
  857. __u16 opcode = 0;
  858. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  859. HCI_OCF_FM_CANCEL_SEARCH);
  860. return radio_hci_send_cmd(hdev, opcode, 0, NULL);
  861. }
  862. static int hci_fm_rds_grp_mask_req(struct radio_hci_dev *hdev,
  863. unsigned long param)
  864. {
  865. __u16 opcode = 0;
  866. struct hci_fm_rds_grp_req *fm_grp_mask =
  867. (struct hci_fm_rds_grp_req *)param;
  868. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  869. HCI_OCF_FM_RDS_GRP);
  870. return radio_hci_send_cmd(hdev, opcode, sizeof(*fm_grp_mask),
  871. fm_grp_mask);
  872. }
  873. static int hci_fm_rds_grp_process_req(struct radio_hci_dev *hdev,
  874. unsigned long param)
  875. {
  876. __u16 opcode = 0;
  877. __u32 fm_grps_process = param;
  878. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  879. HCI_OCF_FM_RDS_GRP_PROCESS);
  880. return radio_hci_send_cmd(hdev, opcode, sizeof(fm_grps_process),
  881. &fm_grps_process);
  882. }
  883. static int hci_fm_tune_station_req(struct radio_hci_dev *hdev,
  884. unsigned long param)
  885. {
  886. __u16 opcode = 0;
  887. __u32 tune_freq = param;
  888. opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ,
  889. HCI_OCF_FM_TUNE_STATION_REQ);
  890. return radio_hci_send_cmd(hdev, opcode, sizeof(tune_freq), &tune_freq);
  891. }
  892. static int hci_def_data_read_req(struct radio_hci_dev *hdev,
  893. unsigned long param)
  894. {
  895. __u16 opcode = 0;
  896. struct hci_fm_def_data_rd_req *def_data_rd =
  897. (struct hci_fm_def_data_rd_req *) param;
  898. opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ,
  899. HCI_OCF_FM_DEFAULT_DATA_READ);
  900. return radio_hci_send_cmd(hdev, opcode, sizeof((*def_data_rd)),
  901. def_data_rd);
  902. }
  903. static int hci_def_data_write_req(struct radio_hci_dev *hdev,
  904. unsigned long param)
  905. {
  906. __u16 opcode = 0;
  907. struct hci_fm_def_data_wr_req *def_data_wr =
  908. (struct hci_fm_def_data_wr_req *) param;
  909. opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ,
  910. HCI_OCF_FM_DEFAULT_DATA_WRITE);
  911. return radio_hci_send_cmd(hdev, opcode, (def_data_wr->length+2),
  912. def_data_wr);
  913. }
  914. static int hci_set_notch_filter_req(struct radio_hci_dev *hdev,
  915. unsigned long param)
  916. {
  917. __u16 opcode = 0;
  918. __u8 notch_filter_val = param;
  919. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  920. HCI_OCF_FM_EN_NOTCH_CTRL);
  921. return radio_hci_send_cmd(hdev, opcode, sizeof(notch_filter_val),
  922. &notch_filter_val);
  923. }
  924. static int hci_fm_reset_req(struct radio_hci_dev *hdev, unsigned long param)
  925. {
  926. __u16 opcode = 0;
  927. opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ,
  928. HCI_OCF_FM_RESET);
  929. return radio_hci_send_cmd(hdev, opcode, 0, NULL);
  930. }
  931. static int hci_fm_get_feature_lists_req(struct radio_hci_dev *hdev,
  932. unsigned long param)
  933. {
  934. __u16 opcode = 0;
  935. opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ,
  936. HCI_OCF_FM_GET_FEATURE_LIST);
  937. return radio_hci_send_cmd(hdev, opcode, 0, NULL);
  938. }
  939. static int hci_fm_do_calibration_req(struct radio_hci_dev *hdev,
  940. unsigned long param)
  941. {
  942. __u16 opcode = 0;
  943. __u8 mode = param;
  944. opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ,
  945. HCI_OCF_FM_DO_CALIBRATION);
  946. return radio_hci_send_cmd(hdev, opcode, sizeof(mode), &mode);
  947. }
  948. static int hci_read_grp_counters_req(struct radio_hci_dev *hdev,
  949. unsigned long param)
  950. {
  951. __u16 opcode = 0;
  952. __u8 reset_counters = param;
  953. opcode = hci_opcode_pack(HCI_OGF_FM_STATUS_PARAMETERS_CMD_REQ,
  954. HCI_OCF_FM_READ_GRP_COUNTERS);
  955. return radio_hci_send_cmd(hdev, opcode, sizeof(reset_counters),
  956. &reset_counters);
  957. }
  958. static int hci_peek_data_req(struct radio_hci_dev *hdev, unsigned long param)
  959. {
  960. __u16 opcode = 0;
  961. struct hci_fm_riva_data *peek_data = (struct hci_fm_riva_data *)param;
  962. opcode = hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ,
  963. HCI_OCF_FM_PEEK_DATA);
  964. return radio_hci_send_cmd(hdev, opcode, sizeof((*peek_data)),
  965. peek_data);
  966. }
  967. static int hci_poke_data_req(struct radio_hci_dev *hdev, unsigned long param)
  968. {
  969. __u16 opcode = 0;
  970. struct hci_fm_riva_poke *poke_data = (struct hci_fm_riva_poke *) param;
  971. opcode = hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ,
  972. HCI_OCF_FM_POKE_DATA);
  973. return radio_hci_send_cmd(hdev, opcode, sizeof((*poke_data)),
  974. poke_data);
  975. }
  976. static int hci_ssbi_peek_reg_req(struct radio_hci_dev *hdev,
  977. unsigned long param)
  978. {
  979. __u16 opcode = 0;
  980. struct hci_fm_ssbi_peek *ssbi_peek = (struct hci_fm_ssbi_peek *) param;
  981. opcode = hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ,
  982. HCI_OCF_FM_SSBI_PEEK_REG);
  983. return radio_hci_send_cmd(hdev, opcode, sizeof((*ssbi_peek)),
  984. ssbi_peek);
  985. }
  986. static int hci_ssbi_poke_reg_req(struct radio_hci_dev *hdev,
  987. unsigned long param)
  988. {
  989. __u16 opcode = 0;
  990. struct hci_fm_ssbi_req *ssbi_poke = (struct hci_fm_ssbi_req *) param;
  991. opcode = hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ,
  992. HCI_OCF_FM_SSBI_POKE_REG);
  993. return radio_hci_send_cmd(hdev, opcode, sizeof((*ssbi_poke)),
  994. ssbi_poke);
  995. }
  996. static int hci_fm_get_station_dbg_param_req(struct radio_hci_dev *hdev,
  997. unsigned long param)
  998. {
  999. __u16 opcode = 0;
  1000. opcode = hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ,
  1001. HCI_OCF_FM_STATION_DBG_PARAM);
  1002. return radio_hci_send_cmd(hdev, opcode, 0, NULL);
  1003. }
  1004. static int hci_fm_set_ch_det_th(struct radio_hci_dev *hdev,
  1005. unsigned long param)
  1006. {
  1007. struct hci_fm_ch_det_threshold *ch_det_th =
  1008. (struct hci_fm_ch_det_threshold *) param;
  1009. u16 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  1010. HCI_OCF_FM_SET_CH_DET_THRESHOLD);
  1011. return radio_hci_send_cmd(hdev, opcode, sizeof((*ch_det_th)),
  1012. ch_det_th);
  1013. }
  1014. static int hci_fm_get_ch_det_th(struct radio_hci_dev *hdev,
  1015. unsigned long param)
  1016. {
  1017. u16 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  1018. HCI_OCF_FM_GET_CH_DET_THRESHOLD);
  1019. return radio_hci_send_cmd(hdev, opcode, 0, NULL);
  1020. }
  1021. static int hci_fm_get_blend_tbl(struct radio_hci_dev *hdev,
  1022. unsigned long param)
  1023. {
  1024. u16 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  1025. HCI_OCF_FM_GET_BLND_TBL);
  1026. return radio_hci_send_cmd(hdev, opcode, 0, NULL);
  1027. }
  1028. static int hci_fm_set_blend_tbl(struct radio_hci_dev *hdev,
  1029. unsigned long param)
  1030. {
  1031. struct hci_fm_blend_table *blnd_tbl =
  1032. (struct hci_fm_blend_table *) param;
  1033. u16 opcode;
  1034. if (blnd_tbl == NULL) {
  1035. FMDERR("%s, blend tbl is null\n", __func__);
  1036. return -EINVAL;
  1037. }
  1038. opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
  1039. HCI_OCF_FM_SET_BLND_TBL);
  1040. return radio_hci_send_cmd(hdev, opcode,
  1041. sizeof(struct hci_fm_blend_table), blnd_tbl);
  1042. }
  1043. static int radio_hci_err(__u32 code)
  1044. {
  1045. switch (code) {
  1046. case 0:
  1047. return 0;
  1048. case 0x01:
  1049. return -EBADRQC;
  1050. case 0x02:
  1051. return -ENOTCONN;
  1052. case 0x03:
  1053. return -EIO;
  1054. case 0x07:
  1055. return -ENOMEM;
  1056. case 0x0c:
  1057. return -EBUSY;
  1058. case 0x11:
  1059. return -EOPNOTSUPP;
  1060. case 0x12:
  1061. return -EINVAL;
  1062. default:
  1063. return -ENOSYS;
  1064. }
  1065. }
  1066. static int __radio_hci_request(struct radio_hci_dev *hdev,
  1067. int (*req)(struct radio_hci_dev *hdev,
  1068. unsigned long param),
  1069. unsigned long param, __u32 timeout, int interruptible)
  1070. {
  1071. int err = 0;
  1072. DECLARE_WAITQUEUE(wait, current);
  1073. mutex_lock(&iris_fm);
  1074. hdev->req_status = HCI_REQ_PEND;
  1075. add_wait_queue(&hdev->req_wait_q, &wait);
  1076. if (interruptible)
  1077. set_current_state(TASK_INTERRUPTIBLE);
  1078. else
  1079. set_current_state(TASK_UNINTERRUPTIBLE);
  1080. err = req(hdev, param);
  1081. schedule_timeout(msecs_to_jiffies(timeout));
  1082. remove_wait_queue(&hdev->req_wait_q, &wait);
  1083. if (interruptible && signal_pending(current)) {
  1084. mutex_unlock(&iris_fm);
  1085. return -EINTR;
  1086. }
  1087. switch (hdev->req_status) {
  1088. case HCI_REQ_DONE:
  1089. case HCI_REQ_STATUS:
  1090. err = radio_hci_err(hdev->req_result);
  1091. break;
  1092. case HCI_REQ_CANCELED:
  1093. err = -hdev->req_result;
  1094. break;
  1095. default:
  1096. err = -ETIMEDOUT;
  1097. break;
  1098. }
  1099. hdev->req_status = hdev->req_result = 0;
  1100. mutex_unlock(&iris_fm);
  1101. return err;
  1102. }
  1103. static inline int radio_hci_request_interruptible(struct radio_hci_dev *hdev,
  1104. int (*req)(struct
  1105. radio_hci_dev * hdev, unsigned long param),
  1106. unsigned long param, __u32 timeout)
  1107. {
  1108. int ret = 0;
  1109. ret = __radio_hci_request(hdev, req, param, timeout, 1);
  1110. return ret;
  1111. }
  1112. static inline int radio_hci_request_uninterruptible(struct radio_hci_dev *hdev,
  1113. int (*req)(struct
  1114. radio_hci_dev * hdev, unsigned long param),
  1115. unsigned long param, __u32 timeout)
  1116. {
  1117. int ret = 0;
  1118. ret = __radio_hci_request(hdev, req, param, timeout, 0);
  1119. return ret;
  1120. }
  1121. static inline int radio_hci_request(struct radio_hci_dev *hdev,
  1122. int (*req)(struct
  1123. radio_hci_dev * hdev, unsigned long param),
  1124. unsigned long param, __u32 timeout)
  1125. {
  1126. return radio_hci_request_interruptible(hdev, req, param, timeout);
  1127. }
  1128. static inline int hci_conf_event_mask(__u8 *arg,
  1129. struct radio_hci_dev *hdev)
  1130. {
  1131. u8 event_mask = *arg;
  1132. return radio_hci_request(hdev, hci_fm_set_event_mask,
  1133. event_mask, RADIO_HCI_TIMEOUT);
  1134. }
  1135. static int hci_set_fm_recv_conf(struct hci_fm_recv_conf_req *arg,
  1136. struct radio_hci_dev *hdev)
  1137. {
  1138. int ret = 0;
  1139. struct hci_fm_recv_conf_req *set_recv_conf = arg;
  1140. ret = radio_hci_request(hdev, hci_set_fm_recv_conf_req, (unsigned
  1141. long)set_recv_conf, RADIO_HCI_TIMEOUT);
  1142. return ret;
  1143. }
  1144. static int hci_set_fm_trans_conf(struct hci_fm_trans_conf_req_struct *arg,
  1145. struct radio_hci_dev *hdev)
  1146. {
  1147. int ret = 0;
  1148. struct hci_fm_trans_conf_req_struct *set_trans_conf = arg;
  1149. ret = radio_hci_request(hdev, hci_set_fm_trans_conf_req, (unsigned
  1150. long)set_trans_conf, RADIO_HCI_TIMEOUT);
  1151. return ret;
  1152. }
  1153. static int hci_fm_tune_station(__u32 *arg, struct radio_hci_dev *hdev)
  1154. {
  1155. int ret = 0;
  1156. __u32 tune_freq = *arg;
  1157. ret = radio_hci_request(hdev, hci_fm_tune_station_req, tune_freq,
  1158. RADIO_HCI_TIMEOUT);
  1159. return ret;
  1160. }
  1161. static int hci_set_fm_mute_mode(struct hci_fm_mute_mode_req *arg,
  1162. struct radio_hci_dev *hdev)
  1163. {
  1164. int ret = 0;
  1165. struct hci_fm_mute_mode_req *set_mute_conf = arg;
  1166. ret = radio_hci_request(hdev, hci_set_fm_mute_mode_req, (unsigned
  1167. long)set_mute_conf, RADIO_HCI_TIMEOUT);
  1168. return ret;
  1169. }
  1170. static int hci_set_fm_stereo_mode(struct hci_fm_stereo_mode_req *arg,
  1171. struct radio_hci_dev *hdev)
  1172. {
  1173. int ret = 0;
  1174. struct hci_fm_stereo_mode_req *set_stereo_conf = arg;
  1175. ret = radio_hci_request(hdev, hci_set_fm_stereo_mode_req, (unsigned
  1176. long)set_stereo_conf, RADIO_HCI_TIMEOUT);
  1177. return ret;
  1178. }
  1179. static int hci_fm_set_antenna(__u8 *arg, struct radio_hci_dev *hdev)
  1180. {
  1181. int ret = 0;
  1182. __u8 antenna = *arg;
  1183. ret = radio_hci_request(hdev, hci_fm_set_antenna_req, antenna,
  1184. RADIO_HCI_TIMEOUT);
  1185. return ret;
  1186. }
  1187. static int hci_fm_set_signal_threshold(__u8 *arg,
  1188. struct radio_hci_dev *hdev)
  1189. {
  1190. int ret = 0;
  1191. __u8 sig_threshold = *arg;
  1192. ret = radio_hci_request(hdev, hci_fm_set_sig_threshold_req,
  1193. sig_threshold, RADIO_HCI_TIMEOUT);
  1194. return ret;
  1195. }
  1196. static int hci_fm_search_stations(struct hci_fm_search_station_req *arg,
  1197. struct radio_hci_dev *hdev)
  1198. {
  1199. int ret = 0;
  1200. struct hci_fm_search_station_req *srch_stations = arg;
  1201. ret = radio_hci_request(hdev, hci_fm_search_stations_req, (unsigned
  1202. long)srch_stations, RADIO_HCI_TIMEOUT);
  1203. return ret;
  1204. }
  1205. static int hci_fm_search_rds_stations(struct hci_fm_search_rds_station_req *arg,
  1206. struct radio_hci_dev *hdev)
  1207. {
  1208. int ret = 0;
  1209. struct hci_fm_search_rds_station_req *srch_stations = arg;
  1210. ret = radio_hci_request(hdev, hci_fm_srch_rds_stations_req, (unsigned
  1211. long)srch_stations, RADIO_HCI_TIMEOUT);
  1212. return ret;
  1213. }
  1214. static int hci_fm_search_station_list
  1215. (struct hci_fm_search_station_list_req *arg,
  1216. struct radio_hci_dev *hdev)
  1217. {
  1218. int ret = 0;
  1219. struct hci_fm_search_station_list_req *srch_list = arg;
  1220. ret = radio_hci_request(hdev, hci_fm_srch_station_list_req, (unsigned
  1221. long)srch_list, RADIO_HCI_TIMEOUT);
  1222. return ret;
  1223. }
  1224. static int hci_fm_rds_grp(struct hci_fm_rds_grp_req *arg,
  1225. struct radio_hci_dev *hdev)
  1226. {
  1227. int ret = 0;
  1228. struct hci_fm_rds_grp_req *fm_grp_mask = arg;
  1229. ret = radio_hci_request(hdev, hci_fm_rds_grp_mask_req, (unsigned
  1230. long)fm_grp_mask, RADIO_HCI_TIMEOUT);
  1231. return ret;
  1232. }
  1233. static int hci_fm_rds_grps_process(__u32 *arg, struct radio_hci_dev *hdev)
  1234. {
  1235. int ret = 0;
  1236. __u32 fm_grps_process = *arg;
  1237. ret = radio_hci_request(hdev, hci_fm_rds_grp_process_req,
  1238. fm_grps_process, RADIO_HCI_TIMEOUT);
  1239. return ret;
  1240. }
  1241. int hci_def_data_read(struct hci_fm_def_data_rd_req *arg,
  1242. struct radio_hci_dev *hdev)
  1243. {
  1244. int ret = 0;
  1245. struct hci_fm_def_data_rd_req *def_data_rd = arg;
  1246. ret = radio_hci_request(hdev, hci_def_data_read_req, (unsigned
  1247. long)def_data_rd, RADIO_HCI_TIMEOUT);
  1248. return ret;
  1249. }
  1250. int hci_def_data_write(struct hci_fm_def_data_wr_req *arg,
  1251. struct radio_hci_dev *hdev)
  1252. {
  1253. int ret = 0;
  1254. struct hci_fm_def_data_wr_req *def_data_wr = arg;
  1255. ret = radio_hci_request(hdev, hci_def_data_write_req, (unsigned
  1256. long)def_data_wr, RADIO_HCI_TIMEOUT);
  1257. return ret;
  1258. }
  1259. int hci_fm_do_calibration(__u8 *arg, struct radio_hci_dev *hdev)
  1260. {
  1261. int ret = 0;
  1262. __u8 mode = *arg;
  1263. ret = radio_hci_request(hdev, hci_fm_do_calibration_req, mode,
  1264. RADIO_HCI_TIMEOUT);
  1265. return ret;
  1266. }
  1267. static int hci_read_grp_counters(__u8 *arg, struct radio_hci_dev *hdev)
  1268. {
  1269. int ret = 0;
  1270. __u8 reset_counters = *arg;
  1271. ret = radio_hci_request(hdev, hci_read_grp_counters_req,
  1272. reset_counters, RADIO_HCI_TIMEOUT);
  1273. return ret;
  1274. }
  1275. static int hci_set_notch_filter(__u8 *arg, struct radio_hci_dev *hdev)
  1276. {
  1277. int ret = 0;
  1278. __u8 notch_filter = *arg;
  1279. ret = radio_hci_request(hdev, hci_set_notch_filter_req,
  1280. notch_filter, RADIO_HCI_TIMEOUT);
  1281. return ret;
  1282. }
  1283. static int hci_peek_data(struct hci_fm_riva_data *arg,
  1284. struct radio_hci_dev *hdev)
  1285. {
  1286. int ret = 0;
  1287. struct hci_fm_riva_data *peek_data = arg;
  1288. ret = radio_hci_request(hdev, hci_peek_data_req, (unsigned
  1289. long)peek_data, RADIO_HCI_TIMEOUT);
  1290. return ret;
  1291. }
  1292. static int hci_poke_data(struct hci_fm_riva_poke *arg,
  1293. struct radio_hci_dev *hdev)
  1294. {
  1295. int ret = 0;
  1296. struct hci_fm_riva_poke *poke_data = arg;
  1297. ret = radio_hci_request(hdev, hci_poke_data_req, (unsigned
  1298. long)poke_data, RADIO_HCI_TIMEOUT);
  1299. return ret;
  1300. }
  1301. static int hci_ssbi_peek_reg(struct hci_fm_ssbi_peek *arg,
  1302. struct radio_hci_dev *hdev)
  1303. {
  1304. int ret = 0;
  1305. struct hci_fm_ssbi_peek *ssbi_peek_reg = arg;
  1306. ret = radio_hci_request(hdev, hci_ssbi_peek_reg_req, (unsigned
  1307. long)ssbi_peek_reg, RADIO_HCI_TIMEOUT);
  1308. return ret;
  1309. }
  1310. static int hci_ssbi_poke_reg(struct hci_fm_ssbi_req *arg,
  1311. struct radio_hci_dev *hdev)
  1312. {
  1313. int ret = 0;
  1314. struct hci_fm_ssbi_req *ssbi_poke_reg = arg;
  1315. ret = radio_hci_request(hdev, hci_ssbi_poke_reg_req, (unsigned
  1316. long)ssbi_poke_reg, RADIO_HCI_TIMEOUT);
  1317. return ret;
  1318. }
  1319. static int hci_set_ch_det_thresholds_req(struct hci_fm_ch_det_threshold *arg,
  1320. struct radio_hci_dev *hdev)
  1321. {
  1322. int ret = 0;
  1323. struct hci_fm_ch_det_threshold *ch_det_threshold = arg;
  1324. ret = radio_hci_request(hdev, hci_fm_set_ch_det_th,
  1325. (unsigned long)ch_det_threshold, RADIO_HCI_TIMEOUT);
  1326. return ret;
  1327. }
  1328. static int hci_fm_set_cal_req_proc(struct radio_hci_dev *hdev,
  1329. unsigned long param)
  1330. {
  1331. u16 opcode = 0;
  1332. struct hci_fm_set_cal_req_proc *cal_req =
  1333. (struct hci_fm_set_cal_req_proc *)param;
  1334. opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ,
  1335. HCI_OCF_FM_SET_CALIBRATION);
  1336. return radio_hci_send_cmd(hdev, opcode,
  1337. sizeof(struct hci_fm_set_cal_req_proc), cal_req);
  1338. }
  1339. static int hci_fm_do_cal_req(struct radio_hci_dev *hdev,
  1340. unsigned long param)
  1341. {
  1342. u16 opcode = 0;
  1343. u8 cal_mode = param;
  1344. opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ,
  1345. HCI_OCF_FM_DO_CALIBRATION);
  1346. return radio_hci_send_cmd(hdev, opcode, sizeof(cal_mode),
  1347. &cal_mode);
  1348. }
  1349. static int hci_fm_set_spur_tbl_req(struct radio_hci_dev *hdev,
  1350. unsigned long param)
  1351. {
  1352. u16 opcode = 0, len = 0;
  1353. struct hci_fm_set_spur_table_req *spur_req =
  1354. (struct hci_fm_set_spur_table_req *)param;
  1355. opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ,
  1356. HCI_OCF_FM_SET_SPUR_TABLE);
  1357. if (spur_req->no_of_freqs_entries > ENTRIES_EACH_CMD)
  1358. len = (ENTRIES_EACH_CMD * SPUR_DATA_LEN)
  1359. + SPUR_DATA_INDEX;
  1360. else
  1361. len = (spur_req->no_of_freqs_entries * SPUR_DATA_LEN)
  1362. + SPUR_DATA_INDEX;
  1363. return radio_hci_send_cmd(hdev, opcode, len, spur_req);
  1364. }
  1365. static int hci_fm_get_spur_tbl_data(struct radio_hci_dev *hdev,
  1366. unsigned long param)
  1367. {
  1368. u16 opcode = 0;
  1369. unsigned int spur_freq = (unsigned int)param;
  1370. opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ,
  1371. HCI_OCF_FM_GET_SPUR_TABLE);
  1372. return radio_hci_send_cmd(hdev, opcode, sizeof(int), &spur_freq);
  1373. }
  1374. static int hci_set_blend_tbl_req(struct hci_fm_blend_table *arg,
  1375. struct radio_hci_dev *hdev)
  1376. {
  1377. int ret = 0;
  1378. struct hci_fm_blend_table *blend_tbl = arg;
  1379. ret = radio_hci_request(hdev, hci_fm_set_blend_tbl,
  1380. (unsigned long)blend_tbl, RADIO_HCI_TIMEOUT);
  1381. return ret;
  1382. }
  1383. static int hci_cmd_internal(unsigned int cmd, struct radio_hci_dev *hdev,
  1384. int interruptible)
  1385. {
  1386. int ret = 0;
  1387. unsigned long arg = 0;
  1388. radio_hci_request_func radio_hci_request;
  1389. if (!hdev)
  1390. return -ENODEV;
  1391. radio_hci_request = interruptible ? radio_hci_request_interruptible :
  1392. radio_hci_request_uninterruptible;
  1393. switch (cmd) {
  1394. case HCI_FM_ENABLE_RECV_CMD:
  1395. ret = radio_hci_request(hdev, hci_fm_enable_recv_req, arg,
  1396. RADIO_HCI_TIMEOUT);
  1397. break;
  1398. case HCI_FM_DISABLE_RECV_CMD:
  1399. ret = radio_hci_request(hdev, hci_fm_disable_recv_req, arg,
  1400. RADIO_HCI_TIMEOUT);
  1401. break;
  1402. case HCI_FM_GET_RECV_CONF_CMD:
  1403. ret = radio_hci_request(hdev, hci_get_fm_recv_conf_req, arg,
  1404. RADIO_HCI_TIMEOUT);
  1405. break;
  1406. case HCI_FM_GET_STATION_PARAM_CMD:
  1407. ret = radio_hci_request(hdev,
  1408. hci_fm_get_station_param_req, arg,
  1409. RADIO_HCI_TIMEOUT);
  1410. break;
  1411. case HCI_FM_GET_SIGNAL_TH_CMD:
  1412. ret = radio_hci_request(hdev,
  1413. hci_fm_get_sig_threshold_req, arg,
  1414. RADIO_HCI_TIMEOUT);
  1415. break;
  1416. case HCI_FM_GET_PROGRAM_SERVICE_CMD:
  1417. ret = radio_hci_request(hdev,
  1418. hci_fm_get_program_service_req, arg,
  1419. RADIO_HCI_TIMEOUT);
  1420. break;
  1421. case HCI_FM_GET_RADIO_TEXT_CMD:
  1422. ret = radio_hci_request(hdev, hci_fm_get_radio_text_req, arg,
  1423. RADIO_HCI_TIMEOUT);
  1424. break;
  1425. case HCI_FM_GET_AF_LIST_CMD:
  1426. ret = radio_hci_request(hdev, hci_fm_get_af_list_req, arg,
  1427. RADIO_HCI_TIMEOUT);
  1428. break;
  1429. case HCI_FM_CANCEL_SEARCH_CMD:
  1430. ret = radio_hci_request(hdev, hci_fm_cancel_search_req, arg,
  1431. RADIO_HCI_TIMEOUT);
  1432. break;
  1433. case HCI_FM_RESET_CMD:
  1434. ret = radio_hci_request(hdev, hci_fm_reset_req, arg,
  1435. RADIO_HCI_TIMEOUT);
  1436. break;
  1437. case HCI_FM_GET_FEATURES_CMD:
  1438. ret = radio_hci_request(hdev,
  1439. hci_fm_get_feature_lists_req, arg,
  1440. RADIO_HCI_TIMEOUT);
  1441. break;
  1442. case HCI_FM_STATION_DBG_PARAM_CMD:
  1443. ret = radio_hci_request(hdev,
  1444. hci_fm_get_station_dbg_param_req, arg,
  1445. RADIO_HCI_TIMEOUT);
  1446. break;
  1447. case HCI_FM_ENABLE_TRANS_CMD:
  1448. ret = radio_hci_request(hdev, hci_fm_enable_trans_req, arg,
  1449. RADIO_HCI_TIMEOUT);
  1450. break;
  1451. case HCI_FM_DISABLE_TRANS_CMD:
  1452. ret = radio_hci_request(hdev, hci_fm_disable_trans_req, arg,
  1453. RADIO_HCI_TIMEOUT);
  1454. break;
  1455. case HCI_FM_GET_TX_CONFIG:
  1456. ret = radio_hci_request(hdev, hci_get_fm_trans_conf_req, arg,
  1457. RADIO_HCI_TIMEOUT);
  1458. break;
  1459. case HCI_FM_GET_DET_CH_TH_CMD:
  1460. ret = radio_hci_request(hdev, hci_fm_get_ch_det_th, arg,
  1461. RADIO_HCI_TIMEOUT);
  1462. break;
  1463. case HCI_FM_GET_BLND_TBL_CMD:
  1464. ret = radio_hci_request(hdev, hci_fm_get_blend_tbl, arg,
  1465. RADIO_HCI_TIMEOUT);
  1466. break;
  1467. default:
  1468. ret = -EINVAL;
  1469. break;
  1470. }
  1471. return ret;
  1472. }
  1473. static int hci_cmd(unsigned int cmd, struct radio_hci_dev *hdev)
  1474. {
  1475. return hci_cmd_internal(cmd, hdev, 1);
  1476. }
  1477. static int hci_cmd_uninterruptible(unsigned int cmd, struct radio_hci_dev *hdev)
  1478. {
  1479. return hci_cmd_internal(cmd, hdev, 0);
  1480. }
  1481. static void radio_hci_req_complete(struct radio_hci_dev *hdev, int result)
  1482. {
  1483. hdev->req_result = result;
  1484. hdev->req_status = HCI_REQ_DONE;
  1485. wake_up(&hdev->req_wait_q);
  1486. }
  1487. static void radio_hci_status_complete(struct radio_hci_dev *hdev, int result)
  1488. {
  1489. hdev->req_result = result;
  1490. hdev->req_status = HCI_REQ_STATUS;
  1491. wake_up(&hdev->req_wait_q);
  1492. }
  1493. static void hci_cc_rsp(struct radio_hci_dev *hdev, struct sk_buff *skb)
  1494. {
  1495. __u8 status = *((__u8 *) skb->data);
  1496. if (status)
  1497. return;
  1498. radio_hci_req_complete(hdev, status);
  1499. }
  1500. static void hci_cc_fm_disable_rsp(struct radio_hci_dev *hdev,
  1501. struct sk_buff *skb)
  1502. {
  1503. __u8 status = *((__u8 *) skb->data);
  1504. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1505. if (radio == NULL) {
  1506. FMDERR(":radio is null");
  1507. return;
  1508. }
  1509. if ((radio->mode == FM_TURNING_OFF) && (status == 0)) {
  1510. if (!radio->is_fm_closing)
  1511. iris_q_event(radio, IRIS_EVT_RADIO_DISABLED);
  1512. radio_hci_req_complete(hdev, status);
  1513. radio->mode = FM_OFF;
  1514. goto handle_rds;
  1515. } else if (radio->mode == FM_CALIB) {
  1516. radio_hci_req_complete(hdev, status);
  1517. return;
  1518. } else if ((radio->mode == FM_RECV) || (radio->mode == FM_TRANS)) {
  1519. iris_q_event(radio, IRIS_EVT_RADIO_DISABLED);
  1520. radio->mode = FM_OFF;
  1521. goto handle_rds;
  1522. } else if ((radio->mode == FM_TURNING_OFF) && (status != 0)) {
  1523. radio_hci_req_complete(hdev, status);
  1524. goto handle_rds;
  1525. }
  1526. handle_rds :
  1527. radio->g_rds_grp_proc_ps = 0;
  1528. memset(&radio->rds_grp, 0, sizeof(radio->rds_grp));
  1529. grp_mask = 0;
  1530. oda_agt = 0;
  1531. rt_plus_carrier = -1;
  1532. ert_carrier = -1;
  1533. memset(ert_buf, 0, 256);
  1534. ert_len = 0;
  1535. c_byt_pair_index = 0;
  1536. utf_8_flag = 0;
  1537. rt_ert_flag = 0;
  1538. formatting_dir = 0;
  1539. radio->is_ert_enabled = 0;
  1540. radio->is_rt_plus_enabled = 0;
  1541. radio->is_rds_grp_3A_enabled = 0;
  1542. }
  1543. static void hci_cc_conf_rsp(struct radio_hci_dev *hdev, struct sk_buff *skb)
  1544. {
  1545. struct hci_fm_conf_rsp *rsp = (void *)skb->data;
  1546. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1547. if (radio == NULL) {
  1548. FMDERR(":radio is null");
  1549. return;
  1550. }
  1551. if (rsp->status)
  1552. return;
  1553. radio->recv_conf = rsp->recv_conf_rsp;
  1554. radio_hci_req_complete(hdev, rsp->status);
  1555. }
  1556. static void hci_cc_fm_trans_get_conf_rsp(struct radio_hci_dev *hdev,
  1557. struct sk_buff *skb)
  1558. {
  1559. struct hci_fm_get_trans_conf_rsp *rsp = (void *)skb->data;
  1560. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1561. if (radio == NULL) {
  1562. FMDERR(":radio is null");
  1563. return;
  1564. }
  1565. if (rsp->status)
  1566. return;
  1567. memcpy((void *)&radio->trans_conf, (void*)&rsp->trans_conf_rsp,
  1568. sizeof(rsp->trans_conf_rsp));
  1569. radio_hci_req_complete(hdev, rsp->status);
  1570. }
  1571. static void hci_cc_fm_enable_rsp(struct radio_hci_dev *hdev,
  1572. struct sk_buff *skb)
  1573. {
  1574. struct hci_fm_conf_rsp *rsp = (void *)skb->data;
  1575. //struct iris_device *radio = video_get_drvdata(video_get_dev());
  1576. if (rsp->status) {
  1577. radio_hci_req_complete(hdev, rsp->status);
  1578. return;
  1579. }
  1580. radio_hci_req_complete(hdev, rsp->status);
  1581. }
  1582. static void hci_cc_fm_trans_set_conf_rsp(struct radio_hci_dev *hdev,
  1583. struct sk_buff *skb)
  1584. {
  1585. struct hci_fm_conf_rsp *rsp = (void *)skb->data;
  1586. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1587. if (radio == NULL) {
  1588. FMDERR(":radio is null");
  1589. return;
  1590. }
  1591. if (rsp->status)
  1592. return;
  1593. iris_q_event(radio, HCI_EV_CMD_COMPLETE);
  1594. radio_hci_req_complete(hdev, rsp->status);
  1595. }
  1596. static void hci_cc_sig_threshold_rsp(struct radio_hci_dev *hdev,
  1597. struct sk_buff *skb)
  1598. {
  1599. struct hci_fm_sig_threshold_rsp *rsp = (void *)skb->data;
  1600. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1601. if (radio == NULL) {
  1602. FMDERR(":radio is null");
  1603. return;
  1604. }
  1605. if (rsp->status)
  1606. return;
  1607. memcpy(&radio->sig_th, rsp, sizeof(struct hci_fm_sig_threshold_rsp));
  1608. radio_hci_req_complete(hdev, rsp->status);
  1609. }
  1610. static void hci_cc_station_rsp(struct radio_hci_dev *hdev, struct sk_buff *skb)
  1611. {
  1612. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1613. struct hci_fm_station_rsp *rsp = (void *)skb->data;
  1614. if (radio == NULL) {
  1615. FMDERR(":radio is null");
  1616. return;
  1617. }
  1618. radio->fm_st_rsp = *(rsp);
  1619. /* Tune is always succesful */
  1620. radio_hci_req_complete(hdev, 0);
  1621. }
  1622. static void hci_cc_prg_srv_rsp(struct radio_hci_dev *hdev, struct sk_buff *skb)
  1623. {
  1624. struct hci_fm_prgm_srv_rsp *rsp = (void *)skb->data;
  1625. if (rsp->status)
  1626. return;
  1627. radio_hci_req_complete(hdev, rsp->status);
  1628. }
  1629. static void hci_cc_rd_txt_rsp(struct radio_hci_dev *hdev, struct sk_buff *skb)
  1630. {
  1631. struct hci_fm_radio_txt_rsp *rsp = (void *)skb->data;
  1632. if (rsp->status)
  1633. return;
  1634. radio_hci_req_complete(hdev, rsp->status);
  1635. }
  1636. static void hci_cc_af_list_rsp(struct radio_hci_dev *hdev, struct sk_buff *skb)
  1637. {
  1638. struct hci_fm_af_list_rsp *rsp = (void *)skb->data;
  1639. if (rsp->status)
  1640. return;
  1641. radio_hci_req_complete(hdev, rsp->status);
  1642. }
  1643. static void hci_cc_feature_list_rsp(struct radio_hci_dev *hdev,
  1644. struct sk_buff *skb)
  1645. {
  1646. struct hci_fm_feature_list_rsp *rsp = (void *)skb->data;
  1647. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1648. struct v4l2_capability *v4l_cap = radio->g_cap;
  1649. if (radio == NULL) {
  1650. FMDERR(":radio is null");
  1651. return;
  1652. }
  1653. if (rsp->status)
  1654. return;
  1655. v4l_cap->capabilities = (rsp->feature_mask & 0x000002) |
  1656. (rsp->feature_mask & 0x000001);
  1657. radio_hci_req_complete(hdev, rsp->status);
  1658. }
  1659. static void hci_cc_dbg_param_rsp(struct radio_hci_dev *hdev,
  1660. struct sk_buff *skb)
  1661. {
  1662. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1663. struct hci_fm_dbg_param_rsp *rsp = (void *)skb->data;
  1664. if (radio == NULL) {
  1665. FMDERR(":radio is null");
  1666. return;
  1667. }
  1668. radio->st_dbg_param = *(rsp);
  1669. if (radio->st_dbg_param.status)
  1670. return;
  1671. radio_hci_req_complete(hdev, radio->st_dbg_param.status);
  1672. }
  1673. static void iris_q_evt_data(struct iris_device *radio,
  1674. char *data, int len, int event)
  1675. {
  1676. struct kfifo *data_b;
  1677. if (radio == NULL) {
  1678. FMDERR(":radio is null");
  1679. return;
  1680. }
  1681. data_b = &radio->data_buf[event];
  1682. if (kfifo_in_locked(data_b, data, len, &radio->buf_lock[event]))
  1683. wake_up_interruptible(&radio->event_queue);
  1684. }
  1685. static void hci_cc_riva_peek_rsp(struct radio_hci_dev *hdev,
  1686. struct sk_buff *skb)
  1687. {
  1688. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1689. __u8 status = *((__u8 *) skb->data);
  1690. int len;
  1691. char *data;
  1692. if (status)
  1693. return;
  1694. len = skb->data[RIVA_PEEK_LEN_OFSET] + RIVA_PEEK_PARAM;
  1695. data = kmalloc(len, GFP_ATOMIC);
  1696. if (!data) {
  1697. FMDERR("Memory allocation failed");
  1698. return;
  1699. }
  1700. memcpy(data, &skb->data[PEEK_DATA_OFSET], len);
  1701. iris_q_evt_data(radio, data, len, IRIS_BUF_PEEK);
  1702. radio_hci_req_complete(hdev, status);
  1703. kfree(data);
  1704. }
  1705. static void hci_cc_riva_read_default_rsp(struct radio_hci_dev *hdev,
  1706. struct sk_buff *skb)
  1707. {
  1708. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1709. __u8 status = *((__u8 *) skb->data);
  1710. __u8 len;
  1711. if (radio == NULL) {
  1712. FMDERR(":radio is null");
  1713. return;
  1714. }
  1715. if (status)
  1716. return;
  1717. len = skb->data[1];
  1718. memset(&radio->default_data, 0 , sizeof(struct hci_fm_data_rd_rsp));
  1719. memcpy(&radio->default_data, &skb->data[0], len+2);
  1720. iris_q_evt_data(radio, &skb->data[0], len+2, IRIS_BUF_RD_DEFAULT);
  1721. radio_hci_req_complete(hdev, status);
  1722. }
  1723. static void hci_cc_get_spur_tbl(struct radio_hci_dev *hdev,
  1724. struct sk_buff *skb)
  1725. {
  1726. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1727. __u8 status;
  1728. if (unlikely(radio == NULL)) {
  1729. FMDERR(":radio is null");
  1730. return;
  1731. }
  1732. if (unlikely(skb == NULL)) {
  1733. FMDERR("%s, socket buffer is null\n", __func__);
  1734. return;
  1735. }
  1736. status = *((__u8 *) skb->data);
  1737. if (!status) {
  1738. iris_q_evt_data(radio, &skb->data[1], SPUR_DATA_LEN,
  1739. IRIS_BUF_SPUR);
  1740. iris_q_event(radio, IRIS_EVT_SPUR_TBL);
  1741. }
  1742. radio_hci_req_complete(hdev, status);
  1743. }
  1744. static void hci_cc_ssbi_peek_rsp(struct radio_hci_dev *hdev,
  1745. struct sk_buff *skb)
  1746. {
  1747. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1748. __u8 status = *((__u8 *) skb->data);
  1749. char *data;
  1750. if (status)
  1751. return;
  1752. data = kmalloc(SSBI_PEEK_LEN, GFP_ATOMIC);
  1753. if (!data) {
  1754. FMDERR("Memory allocation failed");
  1755. return;
  1756. }
  1757. data[0] = skb->data[PEEK_DATA_OFSET];
  1758. iris_q_evt_data(radio, data, SSBI_PEEK_LEN, IRIS_BUF_SSBI_PEEK);
  1759. radio_hci_req_complete(hdev, status);
  1760. kfree(data);
  1761. }
  1762. static void hci_cc_rds_grp_cntrs_rsp(struct radio_hci_dev *hdev,
  1763. struct sk_buff *skb)
  1764. {
  1765. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1766. __u8 status = *((__u8 *) skb->data);
  1767. char *data;
  1768. if (status)
  1769. return;
  1770. data = kmalloc(RDS_GRP_CNTR_LEN, GFP_ATOMIC);
  1771. if (!data) {
  1772. FMDERR("memory allocation failed");
  1773. return;
  1774. }
  1775. memcpy(data, &skb->data[1], RDS_GRP_CNTR_LEN);
  1776. iris_q_evt_data(radio, data, RDS_GRP_CNTR_LEN, IRIS_BUF_RDS_CNTRS);
  1777. radio_hci_req_complete(hdev, status);
  1778. kfree(data);
  1779. }
  1780. static void hci_cc_do_calibration_rsp(struct radio_hci_dev *hdev,
  1781. struct sk_buff *skb)
  1782. {
  1783. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1784. static struct hci_cc_do_calibration_rsp rsp;
  1785. rsp.status = skb->data[0];
  1786. rsp.mode = skb->data[CALIB_MODE_OFSET];
  1787. if (rsp.status) {
  1788. FMDERR("status = %d", rsp.status);
  1789. return;
  1790. }
  1791. if (rsp.mode == PROCS_CALIB_MODE) {
  1792. memcpy(&rsp.data[0], &skb->data[CALIB_DATA_OFSET],
  1793. PROCS_CALIB_SIZE);
  1794. iris_q_evt_data(radio, rsp.data, PROCS_CALIB_SIZE,
  1795. IRIS_BUF_CAL_DATA);
  1796. } else {
  1797. return;
  1798. }
  1799. radio_hci_req_complete(hdev, rsp.status);
  1800. }
  1801. static void hci_cc_get_ch_det_threshold_rsp(struct radio_hci_dev *hdev,
  1802. struct sk_buff *skb)
  1803. {
  1804. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1805. u8 status = skb->data[0];
  1806. if (radio == NULL) {
  1807. FMDERR(":radio is null");
  1808. return;
  1809. }
  1810. if (status) {
  1811. FMDERR("status = %d", status);
  1812. return;
  1813. }
  1814. memcpy(&radio->ch_det_threshold, &skb->data[1],
  1815. sizeof(struct hci_fm_ch_det_threshold));
  1816. radio_hci_req_complete(hdev, status);
  1817. }
  1818. static void hci_cc_get_blend_tbl_rsp(struct radio_hci_dev *hdev,
  1819. struct sk_buff *skb)
  1820. {
  1821. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1822. u8 status;
  1823. if (unlikely(radio == NULL)) {
  1824. FMDERR(":radio is null");
  1825. return;
  1826. }
  1827. if (unlikely(skb == NULL)) {
  1828. FMDERR("%s, socket buffer is null\n", __func__);
  1829. return;
  1830. }
  1831. status = skb->data[0];
  1832. if (!status)
  1833. memcpy(&radio->blend_tbl, &skb->data[1],
  1834. sizeof(struct hci_fm_blend_table));
  1835. radio_hci_req_complete(hdev, status);
  1836. }
  1837. static inline void hci_cmd_complete_event(struct radio_hci_dev *hdev,
  1838. struct sk_buff *skb)
  1839. {
  1840. struct hci_ev_cmd_complete *cmd_compl_ev = (void *) skb->data;
  1841. __u16 opcode;
  1842. skb_pull(skb, sizeof(*cmd_compl_ev));
  1843. opcode = __le16_to_cpu(cmd_compl_ev->cmd_opcode);
  1844. switch (opcode) {
  1845. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_ENABLE_RECV_REQ):
  1846. case hci_trans_ctrl_cmd_op_pack(HCI_OCF_FM_ENABLE_TRANS_REQ):
  1847. hci_cc_fm_enable_rsp(hdev, skb);
  1848. break;
  1849. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_RECV_CONF_REQ):
  1850. hci_cc_conf_rsp(hdev, skb);
  1851. break;
  1852. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_DISABLE_RECV_REQ):
  1853. case hci_trans_ctrl_cmd_op_pack(HCI_OCF_FM_DISABLE_TRANS_REQ):
  1854. hci_cc_fm_disable_rsp(hdev, skb);
  1855. break;
  1856. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_RECV_CONF_REQ):
  1857. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_MUTE_MODE_REQ):
  1858. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_STEREO_MODE_REQ):
  1859. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_ANTENNA):
  1860. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_SIGNAL_THRESHOLD):
  1861. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_CANCEL_SEARCH):
  1862. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_RDS_GRP):
  1863. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_RDS_GRP_PROCESS):
  1864. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_EN_WAN_AVD_CTRL):
  1865. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_EN_NOTCH_CTRL):
  1866. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_CH_DET_THRESHOLD):
  1867. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_BLND_TBL):
  1868. case hci_trans_ctrl_cmd_op_pack(HCI_OCF_FM_RDS_RT_REQ):
  1869. case hci_trans_ctrl_cmd_op_pack(HCI_OCF_FM_RDS_PS_REQ):
  1870. case hci_common_cmd_op_pack(HCI_OCF_FM_DEFAULT_DATA_WRITE):
  1871. hci_cc_rsp(hdev, skb);
  1872. break;
  1873. case hci_common_cmd_op_pack(HCI_OCF_FM_RESET):
  1874. case hci_diagnostic_cmd_op_pack(HCI_OCF_FM_SSBI_POKE_REG):
  1875. case hci_diagnostic_cmd_op_pack(HCI_OCF_FM_POKE_DATA):
  1876. case hci_diagnostic_cmd_op_pack(HCI_FM_SET_INTERNAL_TONE_GENRATOR):
  1877. case hci_common_cmd_op_pack(HCI_OCF_FM_SET_CALIBRATION):
  1878. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_EVENT_MASK):
  1879. case hci_common_cmd_op_pack(HCI_OCF_FM_SET_SPUR_TABLE):
  1880. hci_cc_rsp(hdev, skb);
  1881. break;
  1882. case hci_common_cmd_op_pack(HCI_OCF_FM_GET_SPUR_TABLE):
  1883. hci_cc_get_spur_tbl(hdev, skb);
  1884. break;
  1885. case hci_diagnostic_cmd_op_pack(HCI_OCF_FM_SSBI_PEEK_REG):
  1886. hci_cc_ssbi_peek_rsp(hdev, skb);
  1887. break;
  1888. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_SIGNAL_THRESHOLD):
  1889. hci_cc_sig_threshold_rsp(hdev, skb);
  1890. break;
  1891. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_STATION_PARAM_REQ):
  1892. hci_cc_station_rsp(hdev, skb);
  1893. break;
  1894. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_PROGRAM_SERVICE_REQ):
  1895. hci_cc_prg_srv_rsp(hdev, skb);
  1896. break;
  1897. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_RADIO_TEXT_REQ):
  1898. hci_cc_rd_txt_rsp(hdev, skb);
  1899. break;
  1900. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_AF_LIST_REQ):
  1901. hci_cc_af_list_rsp(hdev, skb);
  1902. break;
  1903. case hci_common_cmd_op_pack(HCI_OCF_FM_DEFAULT_DATA_READ):
  1904. hci_cc_riva_read_default_rsp(hdev, skb);
  1905. break;
  1906. case hci_diagnostic_cmd_op_pack(HCI_OCF_FM_PEEK_DATA):
  1907. hci_cc_riva_peek_rsp(hdev, skb);
  1908. break;
  1909. case hci_common_cmd_op_pack(HCI_OCF_FM_GET_FEATURE_LIST):
  1910. hci_cc_feature_list_rsp(hdev, skb);
  1911. break;
  1912. case hci_diagnostic_cmd_op_pack(HCI_OCF_FM_STATION_DBG_PARAM):
  1913. hci_cc_dbg_param_rsp(hdev, skb);
  1914. break;
  1915. case hci_trans_ctrl_cmd_op_pack(HCI_OCF_FM_SET_TRANS_CONF_REQ):
  1916. hci_cc_fm_trans_set_conf_rsp(hdev, skb);
  1917. break;
  1918. case hci_status_param_op_pack(HCI_OCF_FM_READ_GRP_COUNTERS):
  1919. hci_cc_rds_grp_cntrs_rsp(hdev, skb);
  1920. break;
  1921. case hci_common_cmd_op_pack(HCI_OCF_FM_DO_CALIBRATION):
  1922. hci_cc_do_calibration_rsp(hdev, skb);
  1923. break;
  1924. case hci_trans_ctrl_cmd_op_pack(HCI_OCF_FM_GET_TRANS_CONF_REQ):
  1925. hci_cc_fm_trans_get_conf_rsp(hdev, skb);
  1926. break;
  1927. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_CH_DET_THRESHOLD):
  1928. hci_cc_get_ch_det_threshold_rsp(hdev, skb);
  1929. break;
  1930. case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_BLND_TBL):
  1931. hci_cc_get_blend_tbl_rsp(hdev, skb);
  1932. break;
  1933. default:
  1934. FMDERR("%s opcode 0x%x", hdev->name, opcode);
  1935. break;
  1936. }
  1937. }
  1938. static inline void hci_cmd_status_event(struct radio_hci_dev *hdev,
  1939. struct sk_buff *skb)
  1940. {
  1941. struct hci_ev_cmd_status *ev = (void *) skb->data;
  1942. radio_hci_status_complete(hdev, ev->status);
  1943. }
  1944. static inline void hci_ev_tune_status(struct radio_hci_dev *hdev,
  1945. struct sk_buff *skb)
  1946. {
  1947. int i;
  1948. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1949. if (radio == NULL) {
  1950. FMDERR(":radio is null");
  1951. return;
  1952. }
  1953. memcpy(&radio->fm_st_rsp.station_rsp, &skb->data[0],
  1954. sizeof(struct hci_ev_tune_status));
  1955. if (radio->fm_st_rsp.station_rsp.sub_event == AF_JMP_TUNE)
  1956. iris_q_event(radio, IRIS_EVT_AFJMP);
  1957. else
  1958. iris_q_event(radio, IRIS_EVT_TUNE_SUCC);
  1959. for (i = 0; i < IRIS_BUF_MAX; i++) {
  1960. if (i >= IRIS_BUF_RT_RDS)
  1961. kfifo_reset(&radio->data_buf[i]);
  1962. }
  1963. if (radio->fm_st_rsp.station_rsp.serv_avble)
  1964. iris_q_event(radio, IRIS_EVT_ABOVE_TH);
  1965. else
  1966. iris_q_event(radio, IRIS_EVT_BELOW_TH);
  1967. if (radio->fm_st_rsp.station_rsp.stereo_prg)
  1968. iris_q_event(radio, IRIS_EVT_STEREO);
  1969. else if (radio->fm_st_rsp.station_rsp.stereo_prg == 0)
  1970. iris_q_event(radio, IRIS_EVT_MONO);
  1971. if (radio->fm_st_rsp.station_rsp.rds_sync_status)
  1972. iris_q_event(radio, IRIS_EVT_RDS_AVAIL);
  1973. else
  1974. iris_q_event(radio, IRIS_EVT_RDS_NOT_AVAIL);
  1975. }
  1976. static inline void hci_ev_search_compl(struct radio_hci_dev *hdev,
  1977. struct sk_buff *skb)
  1978. {
  1979. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1980. iris_q_event(radio, IRIS_EVT_SEEK_COMPLETE);
  1981. }
  1982. static inline void hci_ev_srch_st_list_compl(struct radio_hci_dev *hdev,
  1983. struct sk_buff *skb)
  1984. {
  1985. struct iris_device *radio = video_get_drvdata(video_get_dev());
  1986. struct hci_ev_srch_list_compl *ev ;
  1987. int cnt;
  1988. int stn_num;
  1989. int rel_freq;
  1990. int abs_freq;
  1991. int len;
  1992. if (radio == NULL) {
  1993. FMDERR(":radio is null");
  1994. return;
  1995. }
  1996. ev = kmalloc(sizeof(*ev), GFP_ATOMIC);
  1997. if (!ev) {
  1998. FMDERR("Memory allocation failed");
  1999. return ;
  2000. }
  2001. ev->num_stations_found = skb->data[STN_NUM_OFFSET];
  2002. len = ev->num_stations_found * PARAMS_PER_STATION + STN_FREQ_OFFSET;
  2003. for (cnt = STN_FREQ_OFFSET, stn_num = 0;
  2004. (cnt < len) && (stn_num < ev->num_stations_found)
  2005. && (stn_num < ARRAY_SIZE(ev->rel_freq));
  2006. cnt += PARAMS_PER_STATION, stn_num++) {
  2007. abs_freq = *((int *)&skb->data[cnt]);
  2008. rel_freq = abs_freq - radio->recv_conf.band_low_limit;
  2009. rel_freq = (rel_freq * 20) / KHZ_TO_MHZ;
  2010. ev->rel_freq[stn_num].rel_freq_lsb = GET_LSB(rel_freq);
  2011. ev->rel_freq[stn_num].rel_freq_msb = GET_MSB(rel_freq);
  2012. }
  2013. len = ev->num_stations_found * 2 + sizeof(ev->num_stations_found);
  2014. iris_q_event(radio, IRIS_EVT_NEW_SRCH_LIST);
  2015. iris_q_evt_data(radio, (char *)ev, len, IRIS_BUF_SRCH_LIST);
  2016. kfree(ev);
  2017. }
  2018. static inline void hci_ev_search_next(struct radio_hci_dev *hdev,
  2019. struct sk_buff *skb)
  2020. {
  2021. struct iris_device *radio = video_get_drvdata(video_get_dev());
  2022. iris_q_event(radio, IRIS_EVT_SCAN_NEXT);
  2023. }
  2024. static inline void hci_ev_stereo_status(struct radio_hci_dev *hdev,
  2025. struct sk_buff *skb)
  2026. {
  2027. struct iris_device *radio = video_get_drvdata(video_get_dev());
  2028. __u8 st_status = *((__u8 *) skb->data);
  2029. if (st_status)
  2030. iris_q_event(radio, IRIS_EVT_STEREO);
  2031. else
  2032. iris_q_event(radio, IRIS_EVT_MONO);
  2033. }
  2034. static void hci_ev_raw_rds_group_data(struct radio_hci_dev *hdev,
  2035. struct sk_buff *skb)
  2036. {
  2037. struct iris_device *radio;
  2038. unsigned char blocknum, index;
  2039. struct rds_grp_data temp;
  2040. unsigned int mask_bit;
  2041. unsigned short int aid, agt, gtc;
  2042. unsigned short int carrier;
  2043. radio = video_get_drvdata(video_get_dev());
  2044. index = RDSGRP_DATA_OFFSET;
  2045. if (radio == NULL) {
  2046. FMDERR(":radio is null");
  2047. return;
  2048. }
  2049. for (blocknum = 0; blocknum < RDS_BLOCKS_NUM; blocknum++) {
  2050. temp.rdsBlk[blocknum].rdsLsb =
  2051. (skb->data[index]);
  2052. temp.rdsBlk[blocknum].rdsMsb =
  2053. (skb->data[index+1]);
  2054. temp.rdsBlk[blocknum].blockStatus =
  2055. (skb->data[RDSGRP_DATA_OFFSET + blocknum +
  2056. (RDS_BLOCKS_NUM << 1)]);
  2057. index = index + 2;
  2058. }
  2059. aid = AID(temp.rdsBlk[3].rdsLsb, temp.rdsBlk[3].rdsMsb);
  2060. gtc = GTC(temp.rdsBlk[1].rdsMsb);
  2061. agt = AGT(temp.rdsBlk[1].rdsLsb);
  2062. if (gtc == GRP_3A) {
  2063. switch (aid) {
  2064. case ERT_AID:
  2065. /* calculate the grp mask for RDS grp
  2066. * which will contain actual eRT text
  2067. *
  2068. * Bit Pos 0 1 2 3 4 5 6 7
  2069. * Grp Type 0A 0B 1A 1B 2A 2B 3A 3B
  2070. *
  2071. * similary for rest grps
  2072. */
  2073. if (!radio->is_ert_enabled)
  2074. break;
  2075. mask_bit = (((agt >> 1) << 1) + (agt & 1));
  2076. oda_agt = (1 << mask_bit);
  2077. utf_8_flag = (temp.rdsBlk[2].rdsLsb & 1);
  2078. formatting_dir = EXTRACT_BIT(temp.rdsBlk[2].rdsLsb,
  2079. ERT_FORMAT_DIR_BIT);
  2080. if (ert_carrier != agt)
  2081. iris_q_event(radio, IRIS_EVT_NEW_ODA);
  2082. ert_carrier = agt;
  2083. break;
  2084. case RT_PLUS_AID:
  2085. /* calculate the grp mask for RDS grp
  2086. * which will contain actual eRT text
  2087. *
  2088. * Bit Pos 0 1 2 3 4 5 6 7
  2089. * Grp Type 0A 0B 1A 1B 2A 2B 3A 3B
  2090. *
  2091. * similary for rest grps
  2092. */
  2093. if (!radio->is_rt_plus_enabled)
  2094. break;
  2095. mask_bit = (((agt >> 1) << 1) + (agt & 1));
  2096. oda_agt = (1 << mask_bit);
  2097. /*Extract 5th bit of MSB (b7b6b5b4b3b2b1b0)*/
  2098. rt_ert_flag = EXTRACT_BIT(temp.rdsBlk[2].rdsMsb,
  2099. RT_ERT_FLAG_BIT);
  2100. if (rt_plus_carrier != agt)
  2101. iris_q_event(radio, IRIS_EVT_NEW_ODA);
  2102. rt_plus_carrier = agt;
  2103. break;
  2104. default:
  2105. oda_agt = 0;
  2106. break;
  2107. }
  2108. } else {
  2109. carrier = gtc;
  2110. if ((carrier == rt_plus_carrier)&&
  2111. radio->is_rt_plus_enabled) {
  2112. hci_ev_rt_plus(radio, temp);
  2113. }else if ((carrier == ert_carrier) &&
  2114. radio->is_ert_enabled) {
  2115. hci_buff_ert(radio, &temp);
  2116. }else {
  2117. iris_q_evt_data(radio, (char *)(&temp),
  2118. sizeof (struct rds_grp_data), IRIS_BUF_RAW_RDS);
  2119. iris_q_event(radio, IRIS_EVT_NEW_RAW_RDS);
  2120. }
  2121. }
  2122. }
  2123. static void hci_buff_ert(struct iris_device *radio,
  2124. struct rds_grp_data *rds_buf)
  2125. {
  2126. int i;
  2127. unsigned short int info_byte = 0;
  2128. unsigned short int byte_pair_index;
  2129. byte_pair_index = AGT(rds_buf->rdsBlk[1].rdsLsb);
  2130. if (byte_pair_index == 0) {
  2131. c_byt_pair_index = 0;
  2132. ert_len = 0;
  2133. }
  2134. if (c_byt_pair_index == byte_pair_index) {
  2135. c_byt_pair_index++;
  2136. for (i = 2; i <= 3; i++) {
  2137. info_byte = rds_buf->rdsBlk[i].rdsLsb;
  2138. info_byte |= (rds_buf->rdsBlk[i].rdsMsb << 8);
  2139. ert_buf[ert_len++] = rds_buf->rdsBlk[i].rdsMsb;
  2140. ert_buf[ert_len++] = rds_buf->rdsBlk[i].rdsLsb;
  2141. if ((utf_8_flag == 0)
  2142. && (info_byte == CARRIAGE_RETURN)) {
  2143. ert_len -= 2;
  2144. break;
  2145. } else if ((utf_8_flag == 1)
  2146. &&
  2147. (rds_buf->rdsBlk[i].rdsMsb
  2148. == CARRIAGE_RETURN)) {
  2149. info_byte = CARRIAGE_RETURN;
  2150. ert_len -= 2;
  2151. break;
  2152. } else if ((utf_8_flag == 1)
  2153. &&
  2154. (rds_buf->rdsBlk[i].rdsLsb
  2155. == CARRIAGE_RETURN)) {
  2156. info_byte = CARRIAGE_RETURN;
  2157. ert_len--;
  2158. break;
  2159. }
  2160. }
  2161. if ((byte_pair_index == MAX_ERT_SEGMENT) ||
  2162. (info_byte == CARRIAGE_RETURN)) {
  2163. hci_ev_ert(radio);
  2164. c_byt_pair_index = 0;
  2165. ert_len = 0;
  2166. }
  2167. } else {
  2168. ert_len = 0;
  2169. c_byt_pair_index = 0;
  2170. }
  2171. }
  2172. static void hci_ev_ert(struct iris_device *radio)
  2173. {
  2174. char *data = NULL;
  2175. if (ert_len <= 0)
  2176. return;
  2177. data = kmalloc((ert_len + 3), GFP_ATOMIC);
  2178. if (data != NULL) {
  2179. data[0] = ert_len;
  2180. data[1] = utf_8_flag;
  2181. data[2] = formatting_dir;
  2182. memcpy((data + 3), ert_buf, ert_len);
  2183. if (radio->is_ert_enabled) {
  2184. iris_q_evt_data(radio, data,
  2185. (ert_len + 3), IRIS_BUF_ERT);
  2186. iris_q_event(radio, IRIS_EVT_NEW_ERT);
  2187. }
  2188. kfree(data);
  2189. }
  2190. }
  2191. static void hci_ev_rt_plus(struct iris_device *radio,
  2192. struct rds_grp_data rds_buf)
  2193. {
  2194. char tag_type1, tag_type2;
  2195. char *data = NULL;
  2196. int len = 0;
  2197. int tags_num = 0;
  2198. char item_toggle;
  2199. char item_running;
  2200. unsigned short int agt;
  2201. item_toggle = EXTRACT_BIT(rds_buf.rdsBlk[1].rdsLsb,
  2202. ITEM_TOGGLE_BIT);
  2203. item_running = EXTRACT_BIT(rds_buf.rdsBlk[1].rdsLsb,
  2204. ITEM_RUNNING_BIT);
  2205. agt = AGT(rds_buf.rdsBlk[1].rdsLsb);
  2206. /*right most 3 bits of Lsb of block 2
  2207. * and left most 3 bits of Msb of block 3
  2208. */
  2209. tag_type1 = (((agt & TAG1_MSB_MASK) << TAG1_MSB_OFFSET) |
  2210. (rds_buf.rdsBlk[2].rdsMsb >> TAG1_LSB_OFFSET));
  2211. /*right most 1 bit of lsb of 3rd block
  2212. * and left most 5 bits of Msb of 4th block
  2213. */
  2214. tag_type2 = (((rds_buf.rdsBlk[2].rdsLsb & TAG2_MSB_MASK)
  2215. << TAG2_MSB_OFFSET) |
  2216. (rds_buf.rdsBlk[3].rdsMsb >> TAG2_LSB_OFFSET));
  2217. if (tag_type1 != DUMMY_CLASS) {
  2218. len += RT_PLUS_LEN_1_TAG;
  2219. tags_num++;
  2220. }
  2221. if (tag_type2 != DUMMY_CLASS) {
  2222. len += RT_PLUS_LEN_1_TAG;
  2223. tags_num++;
  2224. }
  2225. if (len != 0) {
  2226. len += 4;
  2227. data = kmalloc(len, GFP_ATOMIC);
  2228. } else {
  2229. FMDERR("Len is zero\n");
  2230. return ;
  2231. }
  2232. if (data != NULL) {
  2233. data[0] = tags_num;
  2234. len = 1;
  2235. data[len++] = rt_ert_flag;
  2236. data[len++] = item_toggle;
  2237. data[len++] = item_running;
  2238. if (tag_type1 != DUMMY_CLASS) {
  2239. data[len++] = tag_type1;
  2240. /*start position of tag1
  2241. *right most 5 bits of msb of 3rd block
  2242. *and left most bit of lsb of 3rd block
  2243. */
  2244. data[len++] = (((rds_buf.rdsBlk[2].rdsMsb &
  2245. TAG1_POS_MSB_MASK)
  2246. << TAG1_POS_MSB_OFFSET)
  2247. |
  2248. (rds_buf.rdsBlk[2].rdsLsb >>
  2249. TAG1_POS_LSB_OFFSET));
  2250. /*length of tag1
  2251. *left most 6 bits of lsb of 3rd block
  2252. */
  2253. data[len++] = ((rds_buf.rdsBlk[2].rdsLsb
  2254. >> TAG1_LEN_OFFSET)
  2255. &
  2256. TAG1_LEN_MASK) + 1;
  2257. }
  2258. if (tag_type2 != DUMMY_CLASS) {
  2259. data[len++] = tag_type2;
  2260. /*start position of tag2
  2261. *right most 3 bit of msb of 4th block
  2262. *and left most 3 bits of lsb of 4th block
  2263. */
  2264. data[len++] = (((rds_buf.rdsBlk[3].rdsMsb
  2265. & TAG2_POS_MSB_MASK)
  2266. << TAG2_POS_MSB_OFFSET)
  2267. |
  2268. (rds_buf.rdsBlk[3].rdsLsb
  2269. >> TAG2_POS_LSB_OFFSET));
  2270. /*length of tag2
  2271. *right most 5 bits of lsb of 4th block
  2272. */
  2273. data[len++] = (rds_buf.rdsBlk[3].rdsLsb
  2274. & TAG2_LEN_MASK) + 1;
  2275. }
  2276. if (radio->is_rt_plus_enabled) {
  2277. iris_q_evt_data(radio, data,
  2278. len, IRIS_BUF_RT_PLUS);
  2279. iris_q_event(radio, IRIS_EVT_NEW_RT_PLUS);
  2280. }
  2281. kfree(data);
  2282. } else {
  2283. FMDERR("memory allocation failed\n");
  2284. }
  2285. }
  2286. static inline void hci_ev_program_service(struct radio_hci_dev *hdev,
  2287. struct sk_buff *skb)
  2288. {
  2289. struct iris_device *radio = video_get_drvdata(video_get_dev());
  2290. int len;
  2291. char *data;
  2292. len = (skb->data[RDS_PS_LENGTH_OFFSET] * RDS_STRING) + RDS_OFFSET;
  2293. iris_q_event(radio, IRIS_EVT_NEW_PS_RDS);
  2294. data = kmalloc(len, GFP_ATOMIC);
  2295. if (!data) {
  2296. FMDERR("Failed to allocate memory");
  2297. return;
  2298. }
  2299. data[0] = skb->data[RDS_PS_LENGTH_OFFSET];
  2300. data[1] = skb->data[RDS_PTYPE];
  2301. data[2] = skb->data[RDS_PID_LOWER];
  2302. data[3] = skb->data[RDS_PID_HIGHER];
  2303. data[4] = 0;
  2304. memcpy(data+RDS_OFFSET, &skb->data[RDS_PS_DATA_OFFSET], len-RDS_OFFSET);
  2305. iris_q_evt_data(radio, data, len, IRIS_BUF_PS_RDS);
  2306. kfree(data);
  2307. }
  2308. static inline void hci_ev_radio_text(struct radio_hci_dev *hdev,
  2309. struct sk_buff *skb)
  2310. {
  2311. struct iris_device *radio = video_get_drvdata(video_get_dev());
  2312. int len = 0;
  2313. char *data;
  2314. iris_q_event(radio, IRIS_EVT_NEW_RT_RDS);
  2315. while ((skb->data[len+RDS_OFFSET] != 0x0d) && (len < MAX_RT_LENGTH))
  2316. len++;
  2317. data = kmalloc(len+RDS_OFFSET, GFP_ATOMIC);
  2318. if (!data) {
  2319. FMDERR("Failed to allocate memory");
  2320. return;
  2321. }
  2322. data[0] = len;
  2323. data[1] = skb->data[RDS_PTYPE];
  2324. data[2] = skb->data[RDS_PID_LOWER];
  2325. data[3] = skb->data[RDS_PID_HIGHER];
  2326. data[4] = skb->data[RT_A_B_FLAG_OFFSET];
  2327. memcpy(data+RDS_OFFSET, &skb->data[RDS_OFFSET], len);
  2328. data[len+RDS_OFFSET] = 0x00;
  2329. iris_q_evt_data(radio, data, len+RDS_OFFSET, IRIS_BUF_RT_RDS);
  2330. kfree(data);
  2331. }
  2332. static void hci_ev_af_list(struct radio_hci_dev *hdev,
  2333. struct sk_buff *skb)
  2334. {
  2335. struct iris_device *radio = video_get_drvdata(video_get_dev());
  2336. struct hci_ev_af_list ev;
  2337. ev.tune_freq = *((int *) &skb->data[0]);
  2338. ev.pi_code = *((__le16 *) &skb->data[PI_CODE_OFFSET]);
  2339. ev.af_size = skb->data[AF_SIZE_OFFSET];
  2340. if (ev.af_size > AF_LIST_MAX) {
  2341. FMDERR("AF list size received more than available size");
  2342. return;
  2343. }
  2344. memcpy(&ev.af_list[0], &skb->data[AF_LIST_OFFSET], ev.af_size * sizeof(int));
  2345. iris_q_event(radio, IRIS_EVT_NEW_AF_LIST);
  2346. iris_q_evt_data(radio, (char *)&ev, (7 + ev.af_size * sizeof(int)), IRIS_BUF_AF_LIST);
  2347. }
  2348. static void hci_ev_rds_lock_status(struct radio_hci_dev *hdev,
  2349. struct sk_buff *skb)
  2350. {
  2351. struct iris_device *radio = video_get_drvdata(video_get_dev());
  2352. __u8 rds_status = skb->data[0];
  2353. if (rds_status)
  2354. iris_q_event(radio, IRIS_EVT_RDS_AVAIL);
  2355. else
  2356. iris_q_event(radio, IRIS_EVT_RDS_NOT_AVAIL);
  2357. }
  2358. static void hci_ev_service_available(struct radio_hci_dev *hdev,
  2359. struct sk_buff *skb)
  2360. {
  2361. struct iris_device *radio = video_get_drvdata(video_get_dev());
  2362. u8 serv_avble = skb->data[0];
  2363. if (serv_avble)
  2364. iris_q_event(radio, IRIS_EVT_ABOVE_TH);
  2365. else
  2366. iris_q_event(radio, IRIS_EVT_BELOW_TH);
  2367. }
  2368. static void hci_ev_rds_grp_complete(struct radio_hci_dev *hdev,
  2369. struct sk_buff *skb)
  2370. {
  2371. struct iris_device *radio = video_get_drvdata(video_get_dev());
  2372. iris_q_event(radio, IRIS_EVT_TXRDSDONE);
  2373. }
  2374. void radio_hci_event_packet(struct radio_hci_dev *hdev, struct sk_buff *skb)
  2375. {
  2376. struct radio_hci_event_hdr *hdr;
  2377. u8 event;
  2378. if (skb == NULL) {
  2379. FMDERR("Socket buffer is NULL");
  2380. return;
  2381. }
  2382. hdr = (void *) skb->data;
  2383. event = hdr->evt;
  2384. skb_pull(skb, RADIO_HCI_EVENT_HDR_SIZE);
  2385. switch (event) {
  2386. case HCI_EV_TUNE_STATUS:
  2387. hci_ev_tune_status(hdev, skb);
  2388. break;
  2389. case HCI_EV_SEARCH_PROGRESS:
  2390. case HCI_EV_SEARCH_RDS_PROGRESS:
  2391. case HCI_EV_SEARCH_LIST_PROGRESS:
  2392. hci_ev_search_next(hdev, skb);
  2393. break;
  2394. case HCI_EV_STEREO_STATUS:
  2395. hci_ev_stereo_status(hdev, skb);
  2396. break;
  2397. case HCI_EV_RDS_LOCK_STATUS:
  2398. hci_ev_rds_lock_status(hdev, skb);
  2399. break;
  2400. case HCI_EV_SERVICE_AVAILABLE:
  2401. hci_ev_service_available(hdev, skb);
  2402. break;
  2403. case HCI_EV_RDS_RX_DATA:
  2404. hci_ev_raw_rds_group_data(hdev, skb);
  2405. break;
  2406. case HCI_EV_PROGRAM_SERVICE:
  2407. hci_ev_program_service(hdev, skb);
  2408. break;
  2409. case HCI_EV_RADIO_TEXT:
  2410. hci_ev_radio_text(hdev, skb);
  2411. break;
  2412. case HCI_EV_FM_AF_LIST:
  2413. hci_ev_af_list(hdev, skb);
  2414. break;
  2415. case HCI_EV_TX_RDS_GRP_COMPL:
  2416. hci_ev_rds_grp_complete(hdev, skb);
  2417. break;
  2418. case HCI_EV_TX_RDS_CONT_GRP_COMPL:
  2419. break;
  2420. case HCI_EV_CMD_COMPLETE:
  2421. hci_cmd_complete_event(hdev, skb);
  2422. break;
  2423. case HCI_EV_CMD_STATUS:
  2424. hci_cmd_status_event(hdev, skb);
  2425. break;
  2426. case HCI_EV_SEARCH_COMPLETE:
  2427. case HCI_EV_SEARCH_RDS_COMPLETE:
  2428. hci_ev_search_compl(hdev, skb);
  2429. break;
  2430. case HCI_EV_SEARCH_LIST_COMPLETE:
  2431. hci_ev_srch_st_list_compl(hdev, skb);
  2432. break;
  2433. default:
  2434. break;
  2435. }
  2436. }
  2437. /*
  2438. * fops/IOCTL helper functions
  2439. */
  2440. static int iris_search(struct iris_device *radio, int on, int dir)
  2441. {
  2442. int retval = 0;
  2443. enum search_t srch;
  2444. if (radio == NULL) {
  2445. FMDERR(":radio is null");
  2446. return -EINVAL;
  2447. }
  2448. srch = radio->g_search_mode & SRCH_MODE;
  2449. radio->search_on = on;
  2450. if (on) {
  2451. switch (srch) {
  2452. case SCAN_FOR_STRONG:
  2453. case SCAN_FOR_WEAK:
  2454. radio->srch_st_list.srch_list_dir = dir;
  2455. radio->srch_st_list.srch_list_mode = srch;
  2456. retval = hci_fm_search_station_list(
  2457. &radio->srch_st_list, radio->fm_hdev);
  2458. break;
  2459. case RDS_SEEK_PTY:
  2460. case RDS_SCAN_PTY:
  2461. case RDS_SEEK_PI:
  2462. srch = srch - SEARCH_RDS_STNS_MODE_OFFSET;
  2463. radio->srch_rds.srch_station.srch_mode = srch;
  2464. radio->srch_rds.srch_station.srch_dir = dir;
  2465. radio->srch_rds.srch_station.scan_time =
  2466. radio->g_scan_time;
  2467. retval = hci_fm_search_rds_stations(&radio->srch_rds,
  2468. radio->fm_hdev);
  2469. break;
  2470. default:
  2471. radio->srch_st.srch_mode = srch;
  2472. radio->srch_st.scan_time = radio->g_scan_time;
  2473. radio->srch_st.srch_dir = dir;
  2474. retval = hci_fm_search_stations(
  2475. &radio->srch_st, radio->fm_hdev);
  2476. break;
  2477. }
  2478. } else {
  2479. retval = hci_cmd(HCI_FM_CANCEL_SEARCH_CMD, radio->fm_hdev);
  2480. }
  2481. return retval;
  2482. }
  2483. static int set_low_power_mode(struct iris_device *radio, int power_mode)
  2484. {
  2485. int rds_grps_proc = 0x00;
  2486. int retval = 0;
  2487. struct hci_fm_rds_grp_req grp_3a;
  2488. if (radio == NULL) {
  2489. FMDERR(":radio is null");
  2490. return -EINVAL;
  2491. }
  2492. if (radio->power_mode != power_mode) {
  2493. if (power_mode) {
  2494. memcpy(&grp_3a, &radio->rds_grp,
  2495. sizeof(struct hci_fm_rds_grp_req));
  2496. /* Disable 3A group */
  2497. grp_3a.rds_grp_enable_mask &= ~FM_RDS_3A_GRP;
  2498. retval = hci_fm_rds_grp(&grp_3a, radio->fm_hdev);
  2499. if (retval < 0)
  2500. FMDERR("error in disable 3A group mask\n");
  2501. radio->event_mask = 0x00;
  2502. if (radio->af_jump_bit)
  2503. rds_grps_proc = 0x00 | AF_JUMP_ENABLE;
  2504. else
  2505. rds_grps_proc = 0x00;
  2506. retval = hci_fm_rds_grps_process(
  2507. &rds_grps_proc,
  2508. radio->fm_hdev);
  2509. if (retval < 0) {
  2510. FMDERR("Disable RDS failed");
  2511. return retval;
  2512. }
  2513. retval = hci_conf_event_mask(&radio->event_mask,
  2514. radio->fm_hdev);
  2515. } else {
  2516. /* Enable RDS group to normal */
  2517. retval = hci_fm_rds_grp(&radio->rds_grp,
  2518. radio->fm_hdev);
  2519. if (retval < 0)
  2520. FMDERR("error in enable 3A group mask\n");
  2521. radio->event_mask = SIG_LEVEL_INTR |
  2522. RDS_SYNC_INTR | AUDIO_CTRL_INTR;
  2523. retval = hci_conf_event_mask(&radio->event_mask,
  2524. radio->fm_hdev);
  2525. if (retval < 0) {
  2526. FMDERR("Enable Async events failed");
  2527. return retval;
  2528. }
  2529. retval = hci_fm_rds_grps_process(
  2530. &radio->g_rds_grp_proc_ps,
  2531. radio->fm_hdev);
  2532. }
  2533. radio->power_mode = power_mode;
  2534. }
  2535. return retval;
  2536. }
  2537. static int iris_recv_set_region(struct iris_device *radio, int req_region)
  2538. {
  2539. int retval;
  2540. if (radio == NULL) {
  2541. FMDERR(":radio is null");
  2542. return -EINVAL;
  2543. }
  2544. radio->region = req_region;
  2545. retval = hci_set_fm_recv_conf(
  2546. &radio->recv_conf,
  2547. radio->fm_hdev);
  2548. return retval;
  2549. }
  2550. static int iris_trans_set_region(struct iris_device *radio, int req_region)
  2551. {
  2552. int retval;
  2553. if (radio == NULL) {
  2554. FMDERR(":radio is null");
  2555. return -EINVAL;
  2556. }
  2557. radio->region = req_region;
  2558. retval = hci_set_fm_trans_conf(
  2559. &radio->trans_conf,
  2560. radio->fm_hdev);
  2561. return retval;
  2562. }
  2563. static int iris_set_freq(struct iris_device *radio, unsigned int freq)
  2564. {
  2565. int retval;
  2566. if (radio == NULL) {
  2567. FMDERR(":radio is null");
  2568. return -EINVAL;
  2569. }
  2570. retval = hci_fm_tune_station(&freq, radio->fm_hdev);
  2571. if (retval < 0)
  2572. FMDERR("Error while setting the frequency : %d\n", retval);
  2573. return retval;
  2574. }
  2575. static int iris_vidioc_queryctrl(struct file *file, void *priv,
  2576. struct v4l2_queryctrl *qc)
  2577. {
  2578. unsigned char i;
  2579. int retval = -EINVAL;
  2580. for (i = 0; i < ARRAY_SIZE(iris_v4l2_queryctrl); i++) {
  2581. if (qc->id && qc->id == iris_v4l2_queryctrl[i].id) {
  2582. memcpy(qc, &(iris_v4l2_queryctrl[i]), sizeof(*qc));
  2583. retval = 0;
  2584. break;
  2585. }
  2586. }
  2587. return retval;
  2588. }
  2589. static int iris_do_calibration(struct iris_device *radio)
  2590. {
  2591. char cal_mode = 0x00;
  2592. int retval = 0x00;
  2593. if (radio == NULL) {
  2594. FMDERR(":radio is null");
  2595. return -EINVAL;
  2596. }
  2597. cal_mode = PROCS_CALIB_MODE;
  2598. radio->mode = FM_CALIB;
  2599. retval = hci_cmd(HCI_FM_ENABLE_RECV_CMD,
  2600. radio->fm_hdev);
  2601. if (retval < 0) {
  2602. FMDERR("Enable failed before calibration %x", retval);
  2603. radio->mode = FM_OFF;
  2604. return retval;
  2605. }
  2606. retval = radio_hci_request(radio->fm_hdev, hci_fm_do_cal_req,
  2607. (unsigned long)cal_mode, RADIO_HCI_TIMEOUT);
  2608. if (retval < 0) {
  2609. FMDERR("Do Process calibration failed %x", retval);
  2610. radio->mode = FM_RECV;
  2611. return retval;
  2612. }
  2613. retval = hci_cmd(HCI_FM_DISABLE_RECV_CMD,
  2614. radio->fm_hdev);
  2615. if (retval < 0)
  2616. FMDERR("Disable Failed after calibration %d", retval);
  2617. return retval;
  2618. }
  2619. static int iris_vidioc_g_ctrl(struct file *file, void *priv,
  2620. struct v4l2_control *ctrl)
  2621. {
  2622. struct iris_device *radio = video_get_drvdata(video_devdata(file));
  2623. int retval = 0;
  2624. int cf0;
  2625. struct hci_fm_def_data_rd_req rd;
  2626. int lsb, msb;
  2627. if (radio == NULL) {
  2628. FMDERR(":radio is null");
  2629. return -EINVAL;
  2630. }
  2631. switch (ctrl->id) {
  2632. case V4L2_CID_AUDIO_VOLUME:
  2633. break;
  2634. case V4L2_CID_AUDIO_MUTE:
  2635. ctrl->value = radio->mute_mode.hard_mute;
  2636. break;
  2637. case V4L2_CID_PRIVATE_IRIS_SRCHMODE:
  2638. ctrl->value = radio->g_search_mode;
  2639. break;
  2640. case V4L2_CID_PRIVATE_IRIS_SCANDWELL:
  2641. ctrl->value = radio->g_scan_time;
  2642. break;
  2643. case V4L2_CID_PRIVATE_IRIS_SRCHON:
  2644. ctrl->value = radio->search_on;
  2645. break;
  2646. case V4L2_CID_PRIVATE_IRIS_STATE:
  2647. ctrl->value = radio->mode;
  2648. break;
  2649. case V4L2_CID_PRIVATE_IRIS_IOVERC:
  2650. retval = hci_cmd(HCI_FM_STATION_DBG_PARAM_CMD, radio->fm_hdev);
  2651. if (retval < 0)
  2652. return retval;
  2653. ctrl->value = radio->st_dbg_param.io_verc;
  2654. break;
  2655. case V4L2_CID_PRIVATE_IRIS_INTDET:
  2656. retval = hci_cmd(HCI_FM_STATION_DBG_PARAM_CMD, radio->fm_hdev);
  2657. if (retval < 0)
  2658. return retval;
  2659. ctrl->value = radio->st_dbg_param.in_det_out;
  2660. break;
  2661. case V4L2_CID_PRIVATE_IRIS_REGION:
  2662. ctrl->value = radio->region;
  2663. break;
  2664. case V4L2_CID_PRIVATE_IRIS_SIGNAL_TH:
  2665. retval = hci_cmd(HCI_FM_GET_SIGNAL_TH_CMD, radio->fm_hdev);
  2666. if (retval < 0) {
  2667. FMDERR("Error in get signal threshold %d\n", retval);
  2668. return retval;
  2669. }
  2670. ctrl->value = radio->sig_th.sig_threshold;
  2671. break;
  2672. case V4L2_CID_PRIVATE_IRIS_SRCH_PTY:
  2673. ctrl->value = radio->srch_rds.srch_pty;
  2674. break;
  2675. case V4L2_CID_PRIVATE_IRIS_SRCH_PI:
  2676. ctrl->value = radio->srch_rds.srch_pi;
  2677. break;
  2678. case V4L2_CID_PRIVATE_IRIS_SRCH_CNT:
  2679. ctrl->value = radio->srch_st_result.num_stations_found;
  2680. break;
  2681. case V4L2_CID_PRIVATE_IRIS_EMPHASIS:
  2682. if (radio->mode == FM_RECV) {
  2683. ctrl->value = radio->recv_conf.emphasis;
  2684. } else if (radio->mode == FM_TRANS) {
  2685. ctrl->value = radio->trans_conf.emphasis;
  2686. } else {
  2687. FMDERR("Error in radio mode"
  2688. " %d\n", retval);
  2689. return -EINVAL;
  2690. }
  2691. break;
  2692. case V4L2_CID_PRIVATE_IRIS_RDS_STD:
  2693. if (radio->mode == FM_RECV) {
  2694. ctrl->value = radio->recv_conf.rds_std;
  2695. } else if (radio->mode == FM_TRANS) {
  2696. ctrl->value = radio->trans_conf.rds_std;
  2697. } else {
  2698. FMDERR("Error in radio mode"
  2699. " %d\n", retval);
  2700. return -EINVAL;
  2701. }
  2702. break;
  2703. case V4L2_CID_PRIVATE_IRIS_SPACING:
  2704. if (radio->mode == FM_RECV) {
  2705. ctrl->value = radio->recv_conf.ch_spacing;
  2706. } else {
  2707. FMDERR("Error in radio mode"
  2708. " %d\n", retval);
  2709. return -EINVAL;
  2710. }
  2711. break;
  2712. case V4L2_CID_PRIVATE_IRIS_RDSON:
  2713. if (radio->mode == FM_RECV) {
  2714. ctrl->value = radio->recv_conf.rds_std;
  2715. } else {
  2716. FMDERR("Error in radio mode"
  2717. " %d\n", retval);
  2718. return -EINVAL;
  2719. }
  2720. break;
  2721. case V4L2_CID_PRIVATE_IRIS_RDSGROUP_MASK:
  2722. ctrl->value = radio->rds_grp.rds_grp_enable_mask;
  2723. break;
  2724. case V4L2_CID_PRIVATE_IRIS_RDSGROUP_PROC:
  2725. case V4L2_CID_PRIVATE_IRIS_PSALL:
  2726. ctrl->value = (radio->g_rds_grp_proc_ps << RDS_CONFIG_OFFSET);
  2727. break;
  2728. case V4L2_CID_PRIVATE_IRIS_RDSD_BUF:
  2729. ctrl->value = radio->rds_grp.rds_buf_size;
  2730. break;
  2731. case V4L2_CID_PRIVATE_IRIS_LP_MODE:
  2732. ctrl->value = radio->power_mode;
  2733. break;
  2734. case V4L2_CID_PRIVATE_IRIS_ANTENNA:
  2735. ctrl->value = radio->g_antenna;
  2736. break;
  2737. case V4L2_CID_PRIVATE_IRIS_SOFT_MUTE:
  2738. ctrl->value = radio->mute_mode.soft_mute;
  2739. break;
  2740. case V4L2_CID_PRIVATE_IRIS_DO_CALIBRATION:
  2741. retval = iris_do_calibration(radio);
  2742. break;
  2743. case V4L2_CID_PRIVATE_IRIS_GET_SINR:
  2744. if (radio->mode == FM_RECV) {
  2745. retval = hci_cmd(HCI_FM_GET_STATION_PARAM_CMD,
  2746. radio->fm_hdev);
  2747. if (retval < 0) {
  2748. FMDERR("Get SINR Failed");
  2749. return retval;
  2750. }
  2751. ctrl->value = radio->fm_st_rsp.station_rsp.sinr;
  2752. } else
  2753. retval = -EINVAL;
  2754. break;
  2755. case V4L2_CID_PRIVATE_INTF_HIGH_THRESHOLD:
  2756. retval = hci_cmd(HCI_FM_GET_DET_CH_TH_CMD, radio->fm_hdev);
  2757. if (retval < 0) {
  2758. FMDERR("Get High det threshold failed %x", retval);
  2759. return retval;
  2760. }
  2761. ctrl->value = radio->ch_det_threshold.high_th;
  2762. break;
  2763. case V4L2_CID_PRIVATE_INTF_LOW_THRESHOLD:
  2764. retval = hci_cmd(HCI_FM_GET_DET_CH_TH_CMD, radio->fm_hdev);
  2765. if (retval < 0) {
  2766. FMDERR("Get Low det threshold failed %x", retval);
  2767. return retval;
  2768. }
  2769. ctrl->value = radio->ch_det_threshold.low_th;
  2770. break;
  2771. case V4L2_CID_PRIVATE_SINR_THRESHOLD:
  2772. retval = hci_cmd(HCI_FM_GET_DET_CH_TH_CMD, radio->fm_hdev);
  2773. if (retval < 0) {
  2774. FMDERR("Get SINR threshold failed %x", retval);
  2775. return retval;
  2776. }
  2777. ctrl->value = radio->ch_det_threshold.sinr;
  2778. break;
  2779. case V4L2_CID_PRIVATE_SINR_SAMPLES:
  2780. retval = hci_cmd(HCI_FM_GET_DET_CH_TH_CMD, radio->fm_hdev);
  2781. if (retval < 0) {
  2782. FMDERR("Get SINR samples failed %x", retval);
  2783. return retval;
  2784. }
  2785. ctrl->value = radio->ch_det_threshold.sinr_samples;
  2786. break;
  2787. case V4L2_CID_PRIVATE_VALID_CHANNEL:
  2788. ctrl->value = radio->is_station_valid;
  2789. break;
  2790. case V4L2_CID_PRIVATE_AF_RMSSI_TH:
  2791. rd.mode = FM_RDS_CNFG_MODE;
  2792. rd.length = FM_RDS_CNFG_LEN;
  2793. rd.param_len = 0;
  2794. rd.param = 0;
  2795. retval = hci_def_data_read(&rd, radio->fm_hdev);
  2796. if (retval < 0) {
  2797. FMDERR("Get AF Jump Threshold failed %x", retval);
  2798. return retval;
  2799. }
  2800. lsb = radio->default_data.data[AF_RMSSI_TH_LSB_OFFSET];
  2801. msb = radio->default_data.data[AF_RMSSI_TH_MSB_OFFSET];
  2802. ctrl->value = ((msb << 8) | lsb);
  2803. break;
  2804. case V4L2_CID_PRIVATE_AF_RMSSI_SAMPLES:
  2805. rd.mode = FM_RDS_CNFG_MODE;
  2806. rd.length = FM_RDS_CNFG_LEN;
  2807. rd.param_len = 0;
  2808. rd.param = 0;
  2809. retval = hci_def_data_read(&rd, radio->fm_hdev);
  2810. if (retval < 0) {
  2811. FMDERR("Get AF jump rmssi samples failed %x", retval);
  2812. return retval;
  2813. }
  2814. ctrl->value = radio->default_data.data[AF_RMSSI_SAMPLES_OFFSET];
  2815. break;
  2816. case V4L2_CID_PRIVATE_GOOD_CH_RMSSI_TH:
  2817. rd.mode = FM_RX_CONFG_MODE;
  2818. rd.length = FM_RX_CNFG_LEN;
  2819. rd.param_len = 0;
  2820. rd.param = 0;
  2821. retval = hci_def_data_read(&rd, radio->fm_hdev);
  2822. if (retval < 0) {
  2823. FMDERR("get good channel rmssi th failed %x", retval);
  2824. return retval;
  2825. }
  2826. ctrl->value = radio->default_data.data[GD_CH_RMSSI_TH_OFFSET];
  2827. if (ctrl->value > MAX_GD_CH_RMSSI_TH)
  2828. ctrl->value -= 256;
  2829. break;
  2830. case V4L2_CID_PRIVATE_SRCHALGOTYPE:
  2831. rd.mode = FM_RX_CONFG_MODE;
  2832. rd.length = FM_RX_CNFG_LEN;
  2833. rd.param_len = 0;
  2834. rd.param = 0;
  2835. retval = hci_def_data_read(&rd, radio->fm_hdev);
  2836. if (retval < 0) {
  2837. FMDERR("get search algo type failed %x", retval);
  2838. return retval;
  2839. }
  2840. ctrl->value = radio->default_data.data[SRCH_ALGO_TYPE_OFFSET];
  2841. break;
  2842. case V4L2_CID_PRIVATE_SINRFIRSTSTAGE:
  2843. rd.mode = FM_RX_CONFG_MODE;
  2844. rd.length = FM_RX_CNFG_LEN;
  2845. rd.param_len = 0;
  2846. rd.param = 0;
  2847. retval = hci_def_data_read(&rd, radio->fm_hdev);
  2848. if (retval < 0) {
  2849. FMDERR("default data read failed %x", retval);
  2850. return retval;
  2851. }
  2852. ctrl->value = radio->default_data.data[SINRFIRSTSTAGE_OFFSET];
  2853. if (ctrl->value > MAX_SINR_FIRSTSTAGE)
  2854. ctrl->value -= 256;
  2855. break;
  2856. case V4L2_CID_PRIVATE_RMSSIFIRSTSTAGE:
  2857. rd.mode = FM_RX_CONFG_MODE;
  2858. rd.length = FM_RX_CNFG_LEN;
  2859. rd.param_len = 0;
  2860. rd.param = 0;
  2861. retval = hci_def_data_read(&rd, radio->fm_hdev);
  2862. if (retval < 0) {
  2863. FMDERR("default data read failed %x", retval);
  2864. return retval;
  2865. }
  2866. ctrl->value = radio->default_data.data[RMSSIFIRSTSTAGE_OFFSET];
  2867. if (ctrl->value > MAX_RMSSI_FIRSTSTAGE)
  2868. ctrl->value -= 256;
  2869. break;
  2870. case V4L2_CID_PRIVATE_CF0TH12:
  2871. rd.mode = FM_RX_CONFG_MODE;
  2872. rd.length = FM_RX_CNFG_LEN;
  2873. rd.param_len = 0;
  2874. rd.param = 0;
  2875. retval = hci_def_data_read(&rd, radio->fm_hdev);
  2876. if (retval < 0) {
  2877. FMDERR("default data read failed %x", retval);
  2878. return retval;
  2879. }
  2880. ctrl->value = radio->default_data.data[CF0TH12_BYTE1_OFFSET];
  2881. cf0 = radio->default_data.data[CF0TH12_BYTE2_OFFSET];
  2882. ctrl->value |= (cf0 << 8);
  2883. cf0 = radio->default_data.data[CF0TH12_BYTE3_OFFSET];
  2884. ctrl->value |= (cf0 << 16);
  2885. cf0 = radio->default_data.data[CF0TH12_BYTE4_OFFSET];
  2886. if (cf0 > 127)
  2887. cf0 -= 256;
  2888. ctrl->value |= (cf0 << 24);
  2889. break;
  2890. case V4L2_CID_PRIVATE_SOFT_MUTE_TH:
  2891. rd.mode = DIG_AUDIO_0_MODE;
  2892. rd.length = DIG_AUDIO_0_LEN;
  2893. rd.param_len = 0;
  2894. rd.param = 0;
  2895. retval = hci_def_data_read(&rd, radio->fm_hdev);
  2896. if (retval < 0) {
  2897. FMDERR("default data read failed %x", retval);
  2898. return retval;
  2899. }
  2900. ctrl->value = radio->default_data.data[SMUTE_TH_OFFSET];
  2901. if (ctrl->value > MAX_SOFTMUTE_TH)
  2902. ctrl->value -= 256;
  2903. break;
  2904. case V4L2_CID_PRIVATE_BLEND_SINRHI:
  2905. retval = hci_cmd(HCI_FM_GET_BLND_TBL_CMD, radio->fm_hdev);
  2906. if (retval < 0) {
  2907. FMDERR("Failed to get blend table %d", retval);
  2908. goto END;
  2909. }
  2910. ctrl->value = radio->blend_tbl.scBlendSinrHi;
  2911. break;
  2912. case V4L2_CID_PRIVATE_BLEND_RMSSIHI:
  2913. retval = hci_cmd(HCI_FM_GET_BLND_TBL_CMD, radio->fm_hdev);
  2914. if (retval < 0) {
  2915. FMDERR("Failed to get blend table %d", retval);
  2916. goto END;
  2917. }
  2918. ctrl->value = radio->blend_tbl.scBlendRmssiHi;
  2919. break;
  2920. default:
  2921. retval = -EINVAL;
  2922. }
  2923. if (ctrl != NULL && retval < 0)
  2924. FMDERR("get control failed: %d, ret: %d\n", ctrl->id, retval);
  2925. return retval;
  2926. }
  2927. static int iris_vidioc_g_ext_ctrls(struct file *file, void *priv,
  2928. struct v4l2_ext_controls *ctrl)
  2929. {
  2930. int retval = 0;
  2931. char *data = NULL;
  2932. struct iris_device *radio = video_get_drvdata(video_devdata(file));
  2933. struct hci_fm_def_data_rd_req default_data_rd;
  2934. if (radio == NULL) {
  2935. FMDERR(":radio is null");
  2936. return -EINVAL;
  2937. }
  2938. switch ((ctrl->controls[0]).id) {
  2939. case V4L2_CID_PRIVATE_IRIS_READ_DEFAULT:
  2940. data = (ctrl->controls[0]).string;
  2941. memset(&default_data_rd, 0, sizeof(default_data_rd));
  2942. if (copy_from_user(&default_data_rd.mode, data,
  2943. sizeof(default_data_rd)))
  2944. return -EFAULT;
  2945. retval = hci_def_data_read(&default_data_rd, radio->fm_hdev);
  2946. break;
  2947. default:
  2948. retval = -EINVAL;
  2949. }
  2950. return retval;
  2951. }
  2952. static int iris_vidioc_s_ext_ctrls(struct file *file, void *priv,
  2953. struct v4l2_ext_controls *ctrl)
  2954. {
  2955. int retval = 0;
  2956. size_t bytes_to_copy;
  2957. struct hci_fm_tx_ps tx_ps;
  2958. struct hci_fm_tx_rt tx_rt;
  2959. struct hci_fm_def_data_wr_req default_data;
  2960. struct hci_fm_set_cal_req_proc proc_cal_req;
  2961. struct hci_fm_set_spur_table_req spur_tbl_req;
  2962. char *spur_data;
  2963. char tmp_buf[2];
  2964. struct iris_device *radio = video_get_drvdata(video_devdata(file));
  2965. char *data = NULL;
  2966. if ((ctrl == NULL) || (ctrl->controls == NULL)
  2967. || (ctrl->count == 0)) {
  2968. retval = -EINVAL;
  2969. return retval;
  2970. }
  2971. switch ((ctrl->controls[0]).id) {
  2972. case V4L2_CID_RDS_TX_PS_NAME:
  2973. FMDBG("In V4L2_CID_RDS_TX_PS_NAME\n");
  2974. /*Pass a sample PS string */
  2975. memset(tx_ps.ps_data, 0, MAX_PS_LENGTH);
  2976. bytes_to_copy = min(ctrl->controls[0].size,
  2977. (size_t)MAX_PS_LENGTH);
  2978. data = (ctrl->controls[0]).string;
  2979. if (copy_from_user(tx_ps.ps_data,
  2980. data, bytes_to_copy))
  2981. return -EFAULT;
  2982. tx_ps.ps_control = 0x01;
  2983. tx_ps.pi = radio->pi;
  2984. tx_ps.pty = radio->pty;
  2985. tx_ps.ps_repeatcount = radio->ps_repeatcount;
  2986. tx_ps.ps_num = (bytes_to_copy / PS_STRING_LEN);
  2987. retval = radio_hci_request(radio->fm_hdev, hci_trans_ps_req,
  2988. (unsigned long)&tx_ps, RADIO_HCI_TIMEOUT);
  2989. break;
  2990. case V4L2_CID_RDS_TX_RADIO_TEXT:
  2991. bytes_to_copy =
  2992. min((ctrl->controls[0]).size, (size_t)MAX_RT_LENGTH);
  2993. data = (ctrl->controls[0]).string;
  2994. memset(tx_rt.rt_data, 0, MAX_RT_LENGTH);
  2995. if (copy_from_user(tx_rt.rt_data,
  2996. data, bytes_to_copy))
  2997. return -EFAULT;
  2998. tx_rt.rt_control = 0x01;
  2999. tx_rt.pi = radio->pi;
  3000. tx_rt.pty = radio->pty;
  3001. tx_rt.rt_len = bytes_to_copy;
  3002. retval = radio_hci_request(radio->fm_hdev, hci_trans_rt_req,
  3003. (unsigned long)&tx_rt, RADIO_HCI_TIMEOUT);
  3004. break;
  3005. case V4L2_CID_PRIVATE_IRIS_WRITE_DEFAULT:
  3006. data = (ctrl->controls[0]).string;
  3007. memset(&default_data, 0, sizeof(default_data));
  3008. /*
  3009. * Check if length of the 'FM Default Data' to be sent
  3010. * is within the maximum 'FM Default Data' packet limit.
  3011. * Max. 'FM Default Data' packet length is 251 bytes:
  3012. * 1 byte - XFR Mode
  3013. * 1 byte - length of the default data
  3014. * 249 bytes - actual data to be configured
  3015. */
  3016. if (ctrl->controls[0].size > (DEFAULT_DATA_SIZE + 2)) {
  3017. pr_err("%s: Default data buffer overflow!\n", __func__);
  3018. return -EINVAL;
  3019. }
  3020. /* copy only 'size' bytes of data as requested by user */
  3021. retval = copy_from_user(&default_data, data,
  3022. ctrl->controls[0].size);
  3023. if (retval > 0) {
  3024. pr_err("%s: Failed to copy %d bytes of default data"
  3025. " passed by user\n", __func__, retval);
  3026. return -EFAULT;
  3027. }
  3028. FMDBG("%s: XFR Mode\t: 0x%x\n", __func__, default_data.mode);
  3029. FMDBG("%s: XFR Data Length\t: %d\n", __func__,
  3030. default_data.length);
  3031. /*
  3032. * Check if the 'length' of the actual XFR data to be configured
  3033. * is valid or not. Length of actual XFR data should be always
  3034. * 2 bytes less than the total length of the 'FM Default Data'.
  3035. * Length of 'FM Default Data' DEF_DATA_LEN: (1+1+XFR Data Size)
  3036. * Length of 'Actual XFR Data' XFR_DATA_LEN: (DEF_DATA_LEN - 2)
  3037. */
  3038. if (default_data.length != (ctrl->controls[0].size - 2)) {
  3039. pr_err("%s: Invalid 'length' parameter passed for "
  3040. "actual xfr data\n", __func__);
  3041. return -EINVAL;
  3042. }
  3043. retval = hci_def_data_write(&default_data, radio->fm_hdev);
  3044. break;
  3045. case V4L2_CID_PRIVATE_IRIS_SET_CALIBRATION:
  3046. data = (ctrl->controls[0]).string;
  3047. bytes_to_copy = (ctrl->controls[0]).size;
  3048. if (bytes_to_copy < PROCS_CALIB_SIZE) {
  3049. FMDERR("data is less than required size");
  3050. return -EFAULT;
  3051. }
  3052. memset(proc_cal_req.data, 0, PROCS_CALIB_SIZE);
  3053. proc_cal_req.mode = PROCS_CALIB_MODE;
  3054. if (copy_from_user(&proc_cal_req.data[0],
  3055. data, sizeof(proc_cal_req.data)))
  3056. return -EFAULT;
  3057. retval = radio_hci_request(radio->fm_hdev,
  3058. hci_fm_set_cal_req_proc,
  3059. (unsigned long)&proc_cal_req,
  3060. RADIO_HCI_TIMEOUT);
  3061. if (retval < 0)
  3062. FMDERR("Set Process calibration failed %d", retval);
  3063. break;
  3064. case V4L2_CID_PRIVATE_IRIS_SET_SPURTABLE:
  3065. memset(&spur_tbl_req, 0, sizeof(spur_tbl_req));
  3066. data = (ctrl->controls[0]).string;
  3067. if (copy_from_user(&bytes_to_copy, &((ctrl->controls[0]).size),
  3068. sizeof(bytes_to_copy))) {
  3069. retval = -EFAULT;
  3070. goto END;
  3071. }
  3072. if (copy_from_user(&tmp_buf[0], &data[0],
  3073. sizeof(tmp_buf))) {
  3074. retval = -EFAULT;
  3075. goto END;
  3076. }
  3077. spur_tbl_req.mode = tmp_buf[0];
  3078. spur_tbl_req.no_of_freqs_entries = tmp_buf[1];
  3079. if (((spur_tbl_req.no_of_freqs_entries * SPUR_DATA_LEN) !=
  3080. bytes_to_copy - 2) ||
  3081. ((spur_tbl_req.no_of_freqs_entries * SPUR_DATA_LEN) >
  3082. 2 * FM_SPUR_TBL_SIZE)) {
  3083. FMDERR("Invalid data len: data[1] = %d, bytes = %zu",
  3084. spur_tbl_req.no_of_freqs_entries,
  3085. bytes_to_copy);
  3086. retval = -EINVAL;
  3087. goto END;
  3088. }
  3089. spur_data =
  3090. kmalloc((spur_tbl_req.no_of_freqs_entries * SPUR_DATA_LEN)
  3091. + 2, GFP_ATOMIC);
  3092. if (!spur_data) {
  3093. FMDERR("Allocation failed for Spur data");
  3094. retval = -EFAULT;
  3095. goto END;
  3096. }
  3097. if (copy_from_user(spur_data,
  3098. &data[2], (bytes_to_copy - 2))) {
  3099. kfree(spur_data);
  3100. retval = -EFAULT;
  3101. goto END;
  3102. }
  3103. if (spur_tbl_req.no_of_freqs_entries <= ENTRIES_EACH_CMD) {
  3104. memcpy(&spur_tbl_req.spur_data[0], spur_data,
  3105. (spur_tbl_req.no_of_freqs_entries *
  3106. SPUR_DATA_LEN));
  3107. retval = radio_hci_request(radio->fm_hdev,
  3108. hci_fm_set_spur_tbl_req,
  3109. (unsigned long)&spur_tbl_req,
  3110. RADIO_HCI_TIMEOUT);
  3111. } else {
  3112. memcpy(&spur_tbl_req.spur_data[0], spur_data,
  3113. (ENTRIES_EACH_CMD * SPUR_DATA_LEN));
  3114. retval = radio_hci_request(radio->fm_hdev,
  3115. hci_fm_set_spur_tbl_req,
  3116. (unsigned long)&spur_tbl_req,
  3117. RADIO_HCI_TIMEOUT);
  3118. if (retval < 0) {
  3119. FMDERR("Spur command failed to execute");
  3120. kfree(spur_data);
  3121. goto END;
  3122. }
  3123. spur_tbl_req.mode = 0x02;/* 02-Continue mode */
  3124. spur_tbl_req.no_of_freqs_entries =
  3125. spur_tbl_req.no_of_freqs_entries
  3126. - ENTRIES_EACH_CMD;
  3127. memcpy(&spur_tbl_req.spur_data[0],
  3128. &spur_data[ENTRIES_EACH_CMD * SPUR_DATA_LEN],
  3129. (spur_tbl_req.no_of_freqs_entries * SPUR_DATA_LEN));
  3130. retval = radio_hci_request(radio->fm_hdev,
  3131. hci_fm_set_spur_tbl_req,
  3132. (unsigned long)&spur_tbl_req,
  3133. RADIO_HCI_TIMEOUT);
  3134. }
  3135. kfree(spur_data);
  3136. break;
  3137. default:
  3138. FMDBG("Shouldn't reach here\n");
  3139. retval = -1;
  3140. }
  3141. return retval;
  3142. }
  3143. static int iris_vidioc_s_ctrl(struct file *file, void *priv,
  3144. struct v4l2_control *ctrl)
  3145. {
  3146. struct iris_device *radio = video_get_drvdata(video_devdata(file));
  3147. int retval = 0;
  3148. unsigned int rds_grps_proc = 0;
  3149. __u8 temp_val = 0;
  3150. int prev;
  3151. unsigned long arg = 0;
  3152. struct hci_fm_tx_ps tx_ps = {0};
  3153. struct hci_fm_tx_rt tx_rt = {0};
  3154. struct hci_fm_def_data_rd_req rd;
  3155. struct hci_fm_def_data_wr_req wrd;
  3156. char sinr_th, sinr;
  3157. __u8 intf_det_low_th, intf_det_high_th, intf_det_out;
  3158. unsigned int spur_freq;
  3159. if (radio == NULL) {
  3160. FMDERR(":radio is null");
  3161. return -EINVAL;
  3162. }
  3163. switch (ctrl->id) {
  3164. case V4L2_CID_PRIVATE_IRIS_TX_TONE:
  3165. radio->tone_freq = ctrl->value;
  3166. retval = radio_hci_request(radio->fm_hdev,
  3167. hci_fm_tone_generator, arg,
  3168. RADIO_HCI_TIMEOUT);
  3169. if (retval < 0)
  3170. FMDERR("Error while setting the tone %d", retval);
  3171. break;
  3172. case V4L2_CID_AUDIO_VOLUME:
  3173. break;
  3174. case V4L2_CID_AUDIO_MUTE:
  3175. radio->mute_mode.hard_mute = ctrl->value;
  3176. retval = hci_set_fm_mute_mode(
  3177. &radio->mute_mode,
  3178. radio->fm_hdev);
  3179. if (retval < 0)
  3180. FMDERR("Error while set FM hard mute"" %d\n",
  3181. retval);
  3182. break;
  3183. case V4L2_CID_PRIVATE_IRIS_SRCHMODE:
  3184. radio->g_search_mode = ctrl->value;
  3185. break;
  3186. case V4L2_CID_PRIVATE_IRIS_SCANDWELL:
  3187. radio->g_scan_time = ctrl->value;
  3188. break;
  3189. case V4L2_CID_PRIVATE_IRIS_SRCHON:
  3190. iris_search(radio, ctrl->value, SRCH_DIR_UP);
  3191. break;
  3192. case V4L2_CID_PRIVATE_IRIS_STATE:
  3193. switch (ctrl->value) {
  3194. case FM_RECV:
  3195. if (radio->mode != FM_OFF) {
  3196. FMDERR("FM is not in proper state\n");
  3197. retval = -EINVAL;
  3198. goto END;
  3199. }
  3200. if (is_enable_rx_possible(radio) != 0) {
  3201. FMDERR("%s: fm is not in proper state\n",
  3202. __func__);
  3203. retval = -EINVAL;
  3204. goto END;
  3205. }
  3206. radio->mode = FM_RECV_TURNING_ON;
  3207. retval = hci_cmd(HCI_FM_ENABLE_RECV_CMD,
  3208. radio->fm_hdev);
  3209. if (retval < 0) {
  3210. FMDERR("Error while enabling RECV FM"
  3211. " %d\n", retval);
  3212. radio->mode = FM_OFF;
  3213. goto END;
  3214. } else {
  3215. retval = initialise_recv(radio);
  3216. if (retval < 0) {
  3217. FMDERR("Error while initialising"\
  3218. "radio %d\n", retval);
  3219. hci_cmd(HCI_FM_DISABLE_RECV_CMD,
  3220. radio->fm_hdev);
  3221. radio->mode = FM_OFF;
  3222. goto END;
  3223. }
  3224. }
  3225. if (radio->mode == FM_RECV_TURNING_ON) {
  3226. radio->mode = FM_RECV;
  3227. iris_q_event(radio, IRIS_EVT_RADIO_READY);
  3228. }
  3229. break;
  3230. case FM_TRANS:
  3231. if (is_enable_tx_possible(radio) != 0) {
  3232. retval = -EINVAL;
  3233. goto END;
  3234. }
  3235. radio->mode = FM_TRANS_TURNING_ON;
  3236. retval = hci_cmd(HCI_FM_ENABLE_TRANS_CMD,
  3237. radio->fm_hdev);
  3238. if (retval < 0) {
  3239. FMDERR("Error while enabling TRANS FM"
  3240. " %d\n", retval);
  3241. radio->mode = FM_OFF;
  3242. goto END;
  3243. } else {
  3244. retval = initialise_trans(radio);
  3245. if (retval < 0) {
  3246. FMDERR("Error while initialising"\
  3247. "radio %d\n", retval);
  3248. hci_cmd(HCI_FM_DISABLE_TRANS_CMD,
  3249. radio->fm_hdev);
  3250. radio->mode = FM_OFF;
  3251. goto END;
  3252. }
  3253. }
  3254. if (radio->mode == FM_TRANS_TURNING_ON) {
  3255. radio->mode = FM_TRANS;
  3256. iris_q_event(radio, IRIS_EVT_RADIO_READY);
  3257. }
  3258. break;
  3259. case FM_OFF:
  3260. radio->spur_table_size = 0;
  3261. switch (radio->mode) {
  3262. case FM_RECV:
  3263. radio->mode = FM_TURNING_OFF;
  3264. retval = hci_cmd(HCI_FM_DISABLE_RECV_CMD,
  3265. radio->fm_hdev);
  3266. if (retval < 0) {
  3267. FMDERR("Err on disable recv FM"
  3268. " %d\n", retval);
  3269. radio->mode = FM_RECV;
  3270. goto END;
  3271. }
  3272. break;
  3273. case FM_TRANS:
  3274. radio->mode = FM_TURNING_OFF;
  3275. retval = hci_cmd(HCI_FM_DISABLE_TRANS_CMD,
  3276. radio->fm_hdev);
  3277. if (retval < 0) {
  3278. FMDERR("Err disabling trans FM"
  3279. " %d\n", retval);
  3280. radio->mode = FM_TRANS;
  3281. goto END;
  3282. }
  3283. break;
  3284. default:
  3285. retval = -EINVAL;
  3286. }
  3287. break;
  3288. default:
  3289. retval = -EINVAL;
  3290. }
  3291. break;
  3292. case V4L2_CID_PRIVATE_IRIS_REGION:
  3293. if (radio->mode == FM_RECV) {
  3294. retval = iris_recv_set_region(radio, ctrl->value);
  3295. } else {
  3296. if (radio->mode == FM_TRANS)
  3297. retval = iris_trans_set_region(radio,
  3298. ctrl->value);
  3299. else
  3300. retval = -EINVAL;
  3301. }
  3302. break;
  3303. case V4L2_CID_PRIVATE_IRIS_SIGNAL_TH:
  3304. temp_val = ctrl->value;
  3305. retval = hci_fm_set_signal_threshold(
  3306. &temp_val,
  3307. radio->fm_hdev);
  3308. if (retval < 0) {
  3309. FMDERR("Error while setting signal threshold\n");
  3310. break;
  3311. }
  3312. break;
  3313. case V4L2_CID_PRIVATE_IRIS_SRCH_PTY:
  3314. radio->srch_rds.srch_pty = ctrl->value;
  3315. radio->srch_st_list.srch_pty = ctrl->value;
  3316. break;
  3317. case V4L2_CID_PRIVATE_IRIS_SRCH_PI:
  3318. radio->srch_rds.srch_pi = ctrl->value;
  3319. break;
  3320. case V4L2_CID_PRIVATE_IRIS_SRCH_CNT:
  3321. radio->srch_st_list.srch_list_max = ctrl->value;
  3322. break;
  3323. case V4L2_CID_PRIVATE_IRIS_SPACING:
  3324. if (radio->mode == FM_RECV) {
  3325. radio->recv_conf.ch_spacing = ctrl->value;
  3326. retval = hci_set_fm_recv_conf(
  3327. &radio->recv_conf,
  3328. radio->fm_hdev);
  3329. if (retval < 0)
  3330. FMDERR("Error in setting channel spacing");
  3331. }
  3332. break;
  3333. case V4L2_CID_PRIVATE_IRIS_EMPHASIS:
  3334. switch (radio->mode) {
  3335. case FM_RECV:
  3336. radio->recv_conf.emphasis = ctrl->value;
  3337. retval = hci_set_fm_recv_conf(
  3338. &radio->recv_conf,
  3339. radio->fm_hdev);
  3340. if (retval < 0)
  3341. FMDERR("Error in setting emphasis");
  3342. break;
  3343. case FM_TRANS:
  3344. radio->trans_conf.emphasis = ctrl->value;
  3345. retval = hci_set_fm_trans_conf(
  3346. &radio->trans_conf,
  3347. radio->fm_hdev);
  3348. if (retval < 0)
  3349. FMDERR("Error in setting emphasis");
  3350. break;
  3351. default:
  3352. retval = -EINVAL;
  3353. }
  3354. break;
  3355. case V4L2_CID_PRIVATE_IRIS_RDS_STD:
  3356. switch (radio->mode) {
  3357. case FM_RECV:
  3358. radio->recv_conf.rds_std = ctrl->value;
  3359. retval = hci_set_fm_recv_conf(
  3360. &radio->recv_conf,
  3361. radio->fm_hdev);
  3362. if (retval < 0)
  3363. FMDERR("Error in rds_std");
  3364. break;
  3365. case FM_TRANS:
  3366. radio->trans_conf.rds_std = ctrl->value;
  3367. retval = hci_set_fm_trans_conf(
  3368. &radio->trans_conf,
  3369. radio->fm_hdev);
  3370. if (retval < 0)
  3371. FMDERR("Error in rds_Std");
  3372. break;
  3373. default:
  3374. retval = -EINVAL;
  3375. }
  3376. break;
  3377. case V4L2_CID_PRIVATE_IRIS_RDSON:
  3378. switch (radio->mode) {
  3379. case FM_RECV:
  3380. radio->recv_conf.rds_std = ctrl->value;
  3381. retval = hci_set_fm_recv_conf(
  3382. &radio->recv_conf,
  3383. radio->fm_hdev);
  3384. if (retval < 0)
  3385. FMDERR("Error in rds_std");
  3386. break;
  3387. case FM_TRANS:
  3388. radio->trans_conf.rds_std = ctrl->value;
  3389. retval = hci_set_fm_trans_conf(
  3390. &radio->trans_conf,
  3391. radio->fm_hdev);
  3392. if (retval < 0)
  3393. FMDERR("Error in rds_Std");
  3394. break;
  3395. default:
  3396. retval = -EINVAL;
  3397. }
  3398. break;
  3399. case V4L2_CID_PRIVATE_IRIS_RDSGROUP_MASK:
  3400. grp_mask = (grp_mask | oda_agt | ctrl->value);
  3401. radio->rds_grp.rds_grp_enable_mask = grp_mask;
  3402. radio->rds_grp.rds_buf_size = 1;
  3403. radio->rds_grp.en_rds_change_filter = 0;
  3404. retval = hci_fm_rds_grp(&radio->rds_grp, radio->fm_hdev);
  3405. if (retval < 0)
  3406. FMDERR("error in setting group mask\n");
  3407. break;
  3408. case V4L2_CID_PRIVATE_IRIS_RDSGRP_RT:
  3409. if ((ctrl->value < 0) || (ctrl->value > 1))
  3410. return -EINVAL;
  3411. prev = radio->g_rds_grp_proc_ps;
  3412. radio->g_rds_grp_proc_ps &= ~(1 << RDS_RT_OFFSET);
  3413. radio->g_rds_grp_proc_ps |=
  3414. (ctrl->value << RDS_RT_OFFSET);
  3415. retval = hci_fm_rds_grps_process(
  3416. &radio->g_rds_grp_proc_ps,
  3417. radio->fm_hdev);
  3418. if (retval < 0)
  3419. radio->g_rds_grp_proc_ps = prev;
  3420. break;
  3421. case V4L2_CID_PRIVATE_IRIS_RDSGRP_PS_SIMPLE:
  3422. prev = radio->g_rds_grp_proc_ps;
  3423. if ((ctrl->value < 0) || (ctrl->value > 1))
  3424. return -EINVAL;
  3425. radio->g_rds_grp_proc_ps &= ~(1 << RDS_PS_SIMPLE_OFFSET);
  3426. radio->g_rds_grp_proc_ps |=
  3427. (ctrl->value << RDS_PS_SIMPLE_OFFSET);
  3428. retval = hci_fm_rds_grps_process(
  3429. &radio->g_rds_grp_proc_ps,
  3430. radio->fm_hdev);
  3431. if (retval < 0)
  3432. radio->g_rds_grp_proc_ps = prev;
  3433. break;
  3434. case V4L2_CID_PRIVATE_IRIS_RDSGRP_3A:
  3435. prev = grp_mask;
  3436. if ((ctrl->value < 0) || (ctrl->value > 1))
  3437. return -EINVAL;
  3438. grp_mask &= ~(1 << RDS_GRP_3A);
  3439. grp_mask |= (ctrl->value << RDS_GRP_3A);
  3440. radio->rds_grp.rds_grp_enable_mask = grp_mask;
  3441. radio->rds_grp.rds_buf_size = 1;
  3442. radio->rds_grp.en_rds_change_filter = 0;
  3443. retval = hci_fm_rds_grp(&radio->rds_grp, radio->fm_hdev);
  3444. if (retval < 0)
  3445. grp_mask = prev;
  3446. else
  3447. radio->is_rds_grp_3A_enabled = ctrl->value;
  3448. if (ctrl->value == 0) {
  3449. radio->is_rt_plus_enabled = 0;
  3450. radio->is_ert_enabled = 0;
  3451. }
  3452. break;
  3453. case V4L2_CID_PRIVATE_IRIS_RDSGRP_RT_PLUS:
  3454. retval = 0;
  3455. if ((ctrl->value == 1) && (radio->is_rds_grp_3A_enabled == 1))
  3456. radio->is_rt_plus_enabled = ctrl->value;
  3457. else if ((ctrl->value == 0))
  3458. radio->is_rt_plus_enabled = ctrl->value;
  3459. else
  3460. retval = -EINVAL;
  3461. break;
  3462. case V4L2_CID_PRIVATE_IRIS_RDSGRP_ERT:
  3463. retval = 0;
  3464. if ((ctrl->value == 1) && (radio->is_rds_grp_3A_enabled == 1))
  3465. radio->is_ert_enabled = ctrl->value;
  3466. else if ((ctrl->value == 0))
  3467. radio->is_ert_enabled = ctrl->value;
  3468. else
  3469. retval = -EINVAL;
  3470. break;
  3471. case V4L2_CID_PRIVATE_IRIS_RDSGROUP_PROC:
  3472. prev = radio->g_rds_grp_proc_ps;
  3473. rds_grps_proc = radio->g_rds_grp_proc_ps | ctrl->value;
  3474. radio->g_rds_grp_proc_ps = (rds_grps_proc >> RDS_CONFIG_OFFSET);
  3475. retval = hci_fm_rds_grps_process(
  3476. &radio->g_rds_grp_proc_ps,
  3477. radio->fm_hdev);
  3478. if (retval < 0)
  3479. radio->g_rds_grp_proc_ps = prev;
  3480. break;
  3481. case V4L2_CID_PRIVATE_IRIS_RDSD_BUF:
  3482. radio->rds_grp.rds_buf_size = ctrl->value;
  3483. break;
  3484. case V4L2_CID_PRIVATE_IRIS_PSALL:
  3485. prev = radio->g_rds_grp_proc_ps;
  3486. rds_grps_proc = (ctrl->value << RDS_CONFIG_OFFSET);
  3487. radio->g_rds_grp_proc_ps |= rds_grps_proc;
  3488. retval = hci_fm_rds_grps_process(
  3489. &radio->g_rds_grp_proc_ps,
  3490. radio->fm_hdev);
  3491. if (retval < 0)
  3492. radio->g_rds_grp_proc_ps = prev;
  3493. break;
  3494. case V4L2_CID_PRIVATE_IRIS_AF_JUMP:
  3495. /*Clear the current AF jump settings*/
  3496. if ((ctrl->value < 0) || (ctrl->value > 1))
  3497. return -EINVAL;
  3498. prev = radio->g_rds_grp_proc_ps;
  3499. radio->g_rds_grp_proc_ps &= ~(1 << RDS_AF_JUMP_OFFSET);
  3500. radio->af_jump_bit = ctrl->value;
  3501. rds_grps_proc = 0x00;
  3502. rds_grps_proc = (ctrl->value << RDS_AF_JUMP_OFFSET);
  3503. radio->g_rds_grp_proc_ps |= rds_grps_proc;
  3504. retval = hci_fm_rds_grps_process(
  3505. &radio->g_rds_grp_proc_ps,
  3506. radio->fm_hdev);
  3507. if (retval < 0)
  3508. radio->g_rds_grp_proc_ps = prev;
  3509. break;
  3510. case V4L2_CID_PRIVATE_IRIS_LP_MODE:
  3511. set_low_power_mode(radio, ctrl->value);
  3512. break;
  3513. case V4L2_CID_PRIVATE_IRIS_ANTENNA:
  3514. temp_val = ctrl->value;
  3515. retval = hci_fm_set_antenna(&temp_val, radio->fm_hdev);
  3516. if (retval < 0) {
  3517. FMDERR("Set Antenna failed retval = %x", retval);
  3518. return retval;
  3519. }
  3520. radio->g_antenna = ctrl->value;
  3521. break;
  3522. case V4L2_CID_RDS_TX_PTY:
  3523. radio->pty = ctrl->value;
  3524. break;
  3525. case V4L2_CID_RDS_TX_PI:
  3526. radio->pi = ctrl->value;
  3527. break;
  3528. case V4L2_CID_PRIVATE_IRIS_STOP_RDS_TX_PS_NAME:
  3529. tx_ps.ps_control = 0x00;
  3530. retval = radio_hci_request(radio->fm_hdev, hci_trans_ps_req,
  3531. (unsigned long)&tx_ps, RADIO_HCI_TIMEOUT);
  3532. break;
  3533. case V4L2_CID_PRIVATE_IRIS_STOP_RDS_TX_RT:
  3534. tx_rt.rt_control = 0x00;
  3535. retval = radio_hci_request(radio->fm_hdev, hci_trans_rt_req,
  3536. (unsigned long)&tx_rt, RADIO_HCI_TIMEOUT);
  3537. break;
  3538. case V4L2_CID_PRIVATE_IRIS_TX_SETPSREPEATCOUNT:
  3539. radio->ps_repeatcount = ctrl->value;
  3540. break;
  3541. case V4L2_CID_TUNE_POWER_LEVEL:
  3542. if (ctrl->value > FM_TX_PWR_LVL_MAX)
  3543. ctrl->value = FM_TX_PWR_LVL_MAX;
  3544. if (ctrl->value < FM_TX_PWR_LVL_0)
  3545. ctrl->value = FM_TX_PWR_LVL_0;
  3546. rd.mode = FM_TX_PHY_CFG_MODE;
  3547. rd.length = FM_TX_PHY_CFG_LEN;
  3548. rd.param_len = 0x00;
  3549. rd.param = 0x00;
  3550. retval = hci_def_data_read(&rd, radio->fm_hdev);
  3551. if (retval < 0) {
  3552. FMDERR("Default data read failed for PHY_CFG %d\n",
  3553. retval);
  3554. break;
  3555. }
  3556. memset(&wrd, 0, sizeof(wrd));
  3557. wrd.mode = FM_TX_PHY_CFG_MODE;
  3558. wrd.length = FM_TX_PHY_CFG_LEN;
  3559. memcpy(&wrd.data, &radio->default_data.data,
  3560. radio->default_data.ret_data_len);
  3561. wrd.data[FM_TX_PWR_GAIN_OFFSET] =
  3562. (ctrl->value) * FM_TX_PWR_LVL_STEP_SIZE;
  3563. retval = hci_def_data_write(&wrd, radio->fm_hdev);
  3564. if (retval < 0)
  3565. FMDERR("Default write failed for PHY_TXGAIN %d\n",
  3566. retval);
  3567. break;
  3568. case V4L2_CID_PRIVATE_IRIS_SOFT_MUTE:
  3569. radio->mute_mode.soft_mute = ctrl->value;
  3570. retval = hci_set_fm_mute_mode(
  3571. &radio->mute_mode,
  3572. radio->fm_hdev);
  3573. if (retval < 0)
  3574. FMDERR("Error while setting FM soft mute"" %d\n",
  3575. retval);
  3576. break;
  3577. case V4L2_CID_PRIVATE_IRIS_RIVA_ACCS_ADDR:
  3578. radio->riva_data_req.cmd_params.start_addr = ctrl->value;
  3579. break;
  3580. case V4L2_CID_PRIVATE_IRIS_RIVA_ACCS_LEN:
  3581. if ((ctrl->value > 0) &&
  3582. (ctrl->value <= MAX_RIVA_PEEK_RSP_SIZE)) {
  3583. radio->riva_data_req.cmd_params.length = ctrl->value;
  3584. } else {
  3585. FMDERR("Length %d is more than the buffer size %d\n",
  3586. ctrl->value, MAX_RIVA_PEEK_RSP_SIZE);
  3587. retval = -EINVAL;
  3588. }
  3589. break;
  3590. case V4L2_CID_PRIVATE_IRIS_RIVA_POKE:
  3591. if (radio->riva_data_req.cmd_params.length <= MAX_RIVA_PEEK_RSP_SIZE) {
  3592. retval = copy_from_user(radio->riva_data_req.data,
  3593. (void *)ctrl->value,
  3594. radio->riva_data_req.cmd_params.length);
  3595. if (retval == 0) {
  3596. radio->riva_data_req.cmd_params.subopcode =
  3597. RIVA_POKE_OPCODE;
  3598. retval = hci_poke_data(&radio->riva_data_req,
  3599. radio->fm_hdev);
  3600. } else {
  3601. retval = -EINVAL;
  3602. }
  3603. } else {
  3604. FMDERR("Can not copy into driver's buffer. Length %d is more than"
  3605. "the buffer size %d\n", radio->riva_data_req.cmd_params.length,
  3606. MAX_RIVA_PEEK_RSP_SIZE);
  3607. retval = -EINVAL;
  3608. }
  3609. break;
  3610. case V4L2_CID_PRIVATE_IRIS_SSBI_ACCS_ADDR:
  3611. radio->ssbi_data_accs.start_addr = ctrl->value;
  3612. break;
  3613. case V4L2_CID_PRIVATE_IRIS_SSBI_POKE:
  3614. radio->ssbi_data_accs.data = ctrl->value;
  3615. retval = hci_ssbi_poke_reg(&radio->ssbi_data_accs ,
  3616. radio->fm_hdev);
  3617. break;
  3618. case V4L2_CID_PRIVATE_IRIS_RIVA_PEEK:
  3619. radio->riva_data_req.cmd_params.subopcode = RIVA_PEEK_OPCODE;
  3620. ctrl->value = hci_peek_data(&radio->riva_data_req.cmd_params ,
  3621. radio->fm_hdev);
  3622. break;
  3623. case V4L2_CID_PRIVATE_IRIS_SSBI_PEEK:
  3624. radio->ssbi_peek_reg.start_address = ctrl->value;
  3625. hci_ssbi_peek_reg(&radio->ssbi_peek_reg, radio->fm_hdev);
  3626. break;
  3627. case V4L2_CID_PRIVATE_IRIS_RDS_GRP_COUNTERS:
  3628. temp_val = ctrl->value;
  3629. hci_read_grp_counters(&temp_val, radio->fm_hdev);
  3630. break;
  3631. case V4L2_CID_PRIVATE_IRIS_HLSI:
  3632. retval = hci_cmd(HCI_FM_GET_RECV_CONF_CMD,
  3633. radio->fm_hdev);
  3634. if (retval)
  3635. break;
  3636. radio->recv_conf.hlsi = ctrl->value;
  3637. retval = hci_set_fm_recv_conf(
  3638. &radio->recv_conf,
  3639. radio->fm_hdev);
  3640. break;
  3641. case V4L2_CID_PRIVATE_IRIS_SET_NOTCH_FILTER:
  3642. temp_val = ctrl->value;
  3643. retval = hci_set_notch_filter(&temp_val, radio->fm_hdev);
  3644. break;
  3645. case V4L2_CID_PRIVATE_INTF_HIGH_THRESHOLD:
  3646. retval = hci_cmd(HCI_FM_GET_DET_CH_TH_CMD, radio->fm_hdev);
  3647. if (retval < 0) {
  3648. FMDERR("Failed to get chnl det thresholds %d", retval);
  3649. return retval;
  3650. }
  3651. radio->ch_det_threshold.high_th = ctrl->value;
  3652. retval = hci_set_ch_det_thresholds_req(&radio->ch_det_threshold,
  3653. radio->fm_hdev);
  3654. if (retval < 0) {
  3655. FMDERR("Failed to set High det threshold %d ", retval);
  3656. return retval;
  3657. }
  3658. break;
  3659. case V4L2_CID_PRIVATE_INTF_LOW_THRESHOLD:
  3660. retval = hci_cmd(HCI_FM_GET_DET_CH_TH_CMD, radio->fm_hdev);
  3661. if (retval < 0) {
  3662. FMDERR("Failed to get chnl det thresholds %d", retval);
  3663. return retval;
  3664. }
  3665. radio->ch_det_threshold.low_th = ctrl->value;
  3666. retval = hci_set_ch_det_thresholds_req(&radio->ch_det_threshold,
  3667. radio->fm_hdev);
  3668. if (retval < 0) {
  3669. FMDERR("Failed to Set Low det threshold %d", retval);
  3670. return retval;
  3671. }
  3672. break;
  3673. case V4L2_CID_PRIVATE_SINR_THRESHOLD:
  3674. retval = hci_cmd(HCI_FM_GET_DET_CH_TH_CMD, radio->fm_hdev);
  3675. if (retval < 0) {
  3676. FMDERR("Failed to get chnl det thresholds %d", retval);
  3677. return retval;
  3678. }
  3679. radio->ch_det_threshold.sinr = ctrl->value;
  3680. retval = hci_set_ch_det_thresholds_req(&radio->ch_det_threshold,
  3681. radio->fm_hdev);
  3682. if (retval < 0) {
  3683. FMDERR("Failed to set SINR threshold %d", retval);
  3684. return retval;
  3685. }
  3686. break;
  3687. case V4L2_CID_PRIVATE_SINR_SAMPLES:
  3688. retval = hci_cmd(HCI_FM_GET_DET_CH_TH_CMD, radio->fm_hdev);
  3689. if (retval < 0) {
  3690. FMDERR("Failed to get chnl det thresholds %d", retval);
  3691. return retval;
  3692. }
  3693. radio->ch_det_threshold.sinr_samples = ctrl->value;
  3694. retval = hci_set_ch_det_thresholds_req(&radio->ch_det_threshold,
  3695. radio->fm_hdev);
  3696. if (retval < 0) {
  3697. FMDERR("Failed to set SINR samples %d", retval);
  3698. return retval;
  3699. }
  3700. break;
  3701. case V4L2_CID_PRIVATE_IRIS_SRCH_ALGORITHM:
  3702. case V4L2_CID_PRIVATE_IRIS_SET_AUDIO_PATH:
  3703. /*
  3704. These private controls are place holders to keep the
  3705. driver compatible with changes done in the frameworks
  3706. which are specific to TAVARUA.
  3707. */
  3708. retval = 0;
  3709. break;
  3710. case V4L2_CID_PRIVATE_SPUR_FREQ:
  3711. if (radio->spur_table_size >= MAX_SPUR_FREQ_LIMIT) {
  3712. FMDERR("%s: Spur Table Full!\n", __func__);
  3713. retval = -1;
  3714. } else
  3715. radio->spur_data.freq[radio->spur_table_size] =
  3716. ctrl->value;
  3717. break;
  3718. case V4L2_CID_PRIVATE_SPUR_FREQ_RMSSI:
  3719. if (radio->spur_table_size >= MAX_SPUR_FREQ_LIMIT) {
  3720. FMDERR("%s: Spur Table Full!\n", __func__);
  3721. retval = -1;
  3722. } else
  3723. radio->spur_data.rmssi[radio->spur_table_size] =
  3724. ctrl->value;
  3725. break;
  3726. case V4L2_CID_PRIVATE_SPUR_SELECTION:
  3727. if (radio->spur_table_size >= MAX_SPUR_FREQ_LIMIT) {
  3728. FMDERR("%s: Spur Table Full!\n", __func__);
  3729. retval = -1;
  3730. } else {
  3731. radio->spur_data.enable[radio->spur_table_size] =
  3732. ctrl->value;
  3733. radio->spur_table_size++;
  3734. }
  3735. break;
  3736. case V4L2_CID_PRIVATE_UPDATE_SPUR_TABLE:
  3737. update_spur_table(radio);
  3738. break;
  3739. case V4L2_CID_PRIVATE_VALID_CHANNEL:
  3740. retval = hci_cmd(HCI_FM_GET_DET_CH_TH_CMD, radio->fm_hdev);
  3741. if (retval < 0) {
  3742. FMDERR("%s: Failed to determine channel's validity\n",
  3743. __func__);
  3744. return retval;
  3745. } else {
  3746. sinr_th = radio->ch_det_threshold.sinr;
  3747. intf_det_low_th = radio->ch_det_threshold.low_th;
  3748. intf_det_high_th = radio->ch_det_threshold.high_th;
  3749. }
  3750. retval = hci_cmd(HCI_FM_GET_STATION_PARAM_CMD, radio->fm_hdev);
  3751. if (retval < 0) {
  3752. FMDERR("%s: Failed to determine channel's validity\n",
  3753. __func__);
  3754. return retval;
  3755. } else
  3756. sinr = radio->fm_st_rsp.station_rsp.sinr;
  3757. retval = hci_cmd(HCI_FM_STATION_DBG_PARAM_CMD, radio->fm_hdev);
  3758. if (retval < 0) {
  3759. FMDERR("%s: Failed to determine channel's validity\n",
  3760. __func__);
  3761. return retval;
  3762. } else
  3763. intf_det_out = radio->st_dbg_param.in_det_out;
  3764. if ((sinr >= sinr_th) && (intf_det_out >= intf_det_low_th) &&
  3765. (intf_det_out <= intf_det_high_th))
  3766. radio->is_station_valid = VALID_CHANNEL;
  3767. else
  3768. radio->is_station_valid = INVALID_CHANNEL;
  3769. break;
  3770. case V4L2_CID_PRIVATE_AF_RMSSI_TH:
  3771. rd.mode = FM_RDS_CNFG_MODE;
  3772. rd.length = FM_RDS_CNFG_LEN;
  3773. rd.param_len = 0;
  3774. rd.param = 0;
  3775. retval = hci_def_data_read(&rd, radio->fm_hdev);
  3776. if (retval < 0) {
  3777. FMDERR("Get AF Jump RMSSI Threshold failed %x", retval);
  3778. return retval;
  3779. }
  3780. wrd.mode = FM_RDS_CNFG_MODE;
  3781. wrd.length = FM_RDS_CNFG_LEN;
  3782. memcpy(&wrd.data, &radio->default_data.data,
  3783. radio->default_data.ret_data_len);
  3784. wrd.data[AF_RMSSI_TH_LSB_OFFSET] = ((ctrl->value) & 255);
  3785. wrd.data[AF_RMSSI_TH_MSB_OFFSET] = ((ctrl->value) >> 8);
  3786. retval = hci_def_data_write(&wrd, radio->fm_hdev);
  3787. if (retval < 0)
  3788. FMDERR("set AF jump RMSSI threshold failed\n");
  3789. break;
  3790. case V4L2_CID_PRIVATE_AF_RMSSI_SAMPLES:
  3791. rd.mode = FM_RDS_CNFG_MODE;
  3792. rd.length = FM_RDS_CNFG_LEN;
  3793. rd.param_len = 0;
  3794. rd.param = 0;
  3795. retval = hci_def_data_read(&rd, radio->fm_hdev);
  3796. if (retval < 0) {
  3797. FMDERR("Get AF Jump RMSSI SAMPLES failed %x", retval);
  3798. return retval;
  3799. }
  3800. wrd.mode = FM_RDS_CNFG_MODE;
  3801. wrd.length = FM_RDS_CNFG_LEN;
  3802. memcpy(&wrd.data, &radio->default_data.data,
  3803. radio->default_data.ret_data_len);
  3804. wrd.data[AF_RMSSI_SAMPLES_OFFSET] = ctrl->value;
  3805. retval = hci_def_data_write(&wrd, radio->fm_hdev);
  3806. if (retval < 0)
  3807. FMDERR("set AF jump RMSSI Samples failed\n");
  3808. break;
  3809. case V4L2_CID_PRIVATE_GOOD_CH_RMSSI_TH:
  3810. rd.mode = FM_RX_CONFG_MODE;
  3811. rd.length = FM_RX_CNFG_LEN;
  3812. rd.param_len = 0;
  3813. rd.param = 0;
  3814. retval = hci_def_data_read(&rd, radio->fm_hdev);
  3815. if (retval < 0) {
  3816. FMDERR("Get good channel RMSSI th failed %x", retval);
  3817. return retval;
  3818. }
  3819. wrd.mode = FM_RX_CONFG_MODE;
  3820. wrd.length = FM_RX_CNFG_LEN;
  3821. memcpy(&wrd.data, &radio->default_data.data,
  3822. radio->default_data.ret_data_len);
  3823. wrd.data[GD_CH_RMSSI_TH_OFFSET] = ctrl->value;
  3824. retval = hci_def_data_write(&wrd, radio->fm_hdev);
  3825. if (retval < 0)
  3826. FMDERR("set good channel RMSSI th failed\n");
  3827. break;
  3828. case V4L2_CID_PRIVATE_SRCHALGOTYPE:
  3829. rd.mode = FM_RX_CONFG_MODE;
  3830. rd.length = FM_RX_CNFG_LEN;
  3831. rd.param_len = 0;
  3832. rd.param = 0;
  3833. retval = hci_def_data_read(&rd, radio->fm_hdev);
  3834. if (retval < 0) {
  3835. FMDERR("default data read failed %x", retval);
  3836. return retval;
  3837. }
  3838. wrd.mode = FM_RX_CONFG_MODE;
  3839. wrd.length = FM_RX_CNFG_LEN;
  3840. memcpy(&wrd.data, &radio->default_data.data,
  3841. radio->default_data.ret_data_len);
  3842. wrd.data[SRCH_ALGO_TYPE_OFFSET] = ctrl->value;
  3843. retval = hci_def_data_write(&wrd, radio->fm_hdev);
  3844. if (retval < 0)
  3845. FMDERR("set Search Algo Type failed\n");
  3846. break;
  3847. case V4L2_CID_PRIVATE_SINRFIRSTSTAGE:
  3848. rd.mode = FM_RX_CONFG_MODE;
  3849. rd.length = FM_RX_CNFG_LEN;
  3850. rd.param_len = 0;
  3851. rd.param = 0;
  3852. retval = hci_def_data_read(&rd, radio->fm_hdev);
  3853. if (retval < 0) {
  3854. FMDERR("default data read failed %x", retval);
  3855. return retval;
  3856. }
  3857. wrd.mode = FM_RX_CONFG_MODE;
  3858. wrd.length = FM_RX_CNFG_LEN;
  3859. memcpy(&wrd.data, &radio->default_data.data,
  3860. radio->default_data.ret_data_len);
  3861. wrd.data[SINRFIRSTSTAGE_OFFSET] = ctrl->value;
  3862. retval = hci_def_data_write(&wrd, radio->fm_hdev);
  3863. if (retval < 0)
  3864. FMDERR("set SINR First Stage failed\n");
  3865. break;
  3866. case V4L2_CID_PRIVATE_RMSSIFIRSTSTAGE:
  3867. rd.mode = FM_RX_CONFG_MODE;
  3868. rd.length = FM_RX_CNFG_LEN;
  3869. rd.param_len = 0;
  3870. rd.param = 0;
  3871. retval = hci_def_data_read(&rd, radio->fm_hdev);
  3872. if (retval < 0) {
  3873. FMDERR("default data read failed %x", retval);
  3874. return retval;
  3875. }
  3876. wrd.mode = FM_RX_CONFG_MODE;
  3877. wrd.length = FM_RX_CNFG_LEN;
  3878. memcpy(&wrd.data, &radio->default_data.data,
  3879. radio->default_data.ret_data_len);
  3880. wrd.data[RMSSIFIRSTSTAGE_OFFSET] = ctrl->value;
  3881. retval = hci_def_data_write(&wrd, radio->fm_hdev);
  3882. if (retval < 0)
  3883. FMDERR("set RMSSI First Stage failed\n");
  3884. break;
  3885. case V4L2_CID_PRIVATE_CF0TH12:
  3886. rd.mode = FM_RX_CONFG_MODE;
  3887. rd.length = FM_RX_CNFG_LEN;
  3888. rd.param_len = 0;
  3889. rd.param = 0;
  3890. retval = hci_def_data_read(&rd, radio->fm_hdev);
  3891. if (retval < 0) {
  3892. FMDERR("default data read failed %x", retval);
  3893. return retval;
  3894. }
  3895. wrd.mode = FM_RX_CONFG_MODE;
  3896. wrd.length = FM_RX_CNFG_LEN;
  3897. memcpy(&wrd.data, &radio->default_data.data,
  3898. radio->default_data.ret_data_len);
  3899. wrd.data[CF0TH12_BYTE1_OFFSET] = (ctrl->value & 255);
  3900. wrd.data[CF0TH12_BYTE2_OFFSET] = ((ctrl->value >> 8) & 255);
  3901. wrd.data[CF0TH12_BYTE3_OFFSET] = ((ctrl->value >> 16) & 255);
  3902. wrd.data[CF0TH12_BYTE4_OFFSET] = ((ctrl->value >> 24) & 255);
  3903. retval = hci_def_data_write(&wrd, radio->fm_hdev);
  3904. if (retval < 0)
  3905. FMDERR("set CF0 Threshold failed\n");
  3906. break;
  3907. case V4L2_CID_PRIVATE_SOFT_MUTE_TH:
  3908. rd.mode = DIG_AUDIO_0_MODE;
  3909. rd.length = DIG_AUDIO_0_LEN;
  3910. rd.param_len = 0;
  3911. rd.param = 0;
  3912. retval = hci_def_data_read(&rd, radio->fm_hdev);
  3913. if (retval < 0) {
  3914. FMDERR("default data read failed %x", retval);
  3915. return retval;
  3916. }
  3917. wrd.mode = DIG_AUDIO_0_MODE;
  3918. wrd.length = DIG_AUDIO_0_LEN;
  3919. memcpy(&wrd.data, &radio->default_data.data,
  3920. radio->default_data.ret_data_len);
  3921. wrd.data[SMUTE_TH_OFFSET] = ctrl->value;
  3922. retval = hci_def_data_write(&wrd, radio->fm_hdev);
  3923. if (retval < 0)
  3924. FMDERR("Set Soft mute Threshold failed\n");
  3925. break;
  3926. case V4L2_CID_PRIVATE_IRIS_RDSGRP_ALL:
  3927. if((ctrl->value < 0) || (ctrl->value > 1)) {
  3928. retval = -EINVAL;
  3929. break;
  3930. }
  3931. if (ctrl->value == 0) {
  3932. radio->rds_grp.rds_grp_enable_mask = 0;
  3933. } else {
  3934. radio->rds_grp.rds_grp_enable_mask = RDS_GRPS_ALL;
  3935. radio->rds_grp.rds_buf_size = 1;
  3936. radio->rds_grp.en_rds_change_filter = 0;
  3937. retval = hci_fm_rds_grp(&radio->rds_grp,
  3938. radio->fm_hdev);
  3939. if (retval < 0) {
  3940. FMDERR("error in setting all group mask\n");
  3941. } else if(ctrl->value == 0){
  3942. grp_mask = 0;
  3943. oda_agt = 0;
  3944. radio->is_rds_grp_3A_enabled = 0;
  3945. radio->is_rt_plus_enabled = 0;
  3946. radio->is_ert_enabled = 0;
  3947. } else {
  3948. grp_mask = RDS_GRPS_ALL;
  3949. radio->is_rds_grp_3A_enabled = 1;
  3950. }
  3951. }
  3952. break;
  3953. case V4L2_CID_PRIVATE_RXREPEATCOUNT:
  3954. rd.mode = RDS_PS0_XFR_MODE;
  3955. rd.length = RDS_PS0_LEN;
  3956. rd.param_len = 0;
  3957. rd.param = 0;
  3958. retval = hci_def_data_read(&rd, radio->fm_hdev);
  3959. if (retval < 0) {
  3960. FMDERR("default data read failed for PS0 %x", retval);
  3961. return retval;
  3962. }
  3963. wrd.mode = RDS_PS0_XFR_MODE;
  3964. wrd.length = RDS_PS0_LEN;
  3965. memcpy(&wrd.data, &radio->default_data.data,
  3966. radio->default_data.ret_data_len);
  3967. wrd.data[RX_REPEATE_BYTE_OFFSET] = 1;
  3968. retval = hci_def_data_write(&wrd, radio->fm_hdev);
  3969. if (retval < 0)
  3970. FMDERR("set RxRePeat count failed\n");
  3971. break;
  3972. case V4L2_CID_PRIVATE_IRIS_GET_SPUR_TBL:
  3973. spur_freq = ctrl->value;
  3974. retval = radio_hci_request(radio->fm_hdev,
  3975. hci_fm_get_spur_tbl_data,
  3976. (unsigned long)spur_freq,
  3977. RADIO_HCI_TIMEOUT);
  3978. if (retval < 0)
  3979. FMDERR("get Spur data failed\n");
  3980. break;
  3981. case V4L2_CID_PRIVATE_BLEND_SINRHI:
  3982. if (!is_valid_blend_value(ctrl->value)) {
  3983. FMDERR("%s: blend sinr count is not valid\n",
  3984. __func__);
  3985. retval = -EINVAL;
  3986. goto END;
  3987. }
  3988. retval = hci_cmd(HCI_FM_GET_BLND_TBL_CMD, radio->fm_hdev);
  3989. if (retval < 0) {
  3990. FMDERR("Failed to get blend table %d", retval);
  3991. goto END;
  3992. }
  3993. radio->blend_tbl.scBlendSinrHi = ctrl->value;
  3994. retval = hci_set_blend_tbl_req(&radio->blend_tbl,
  3995. radio->fm_hdev);
  3996. if (retval < 0) {
  3997. FMDERR("Failed to set blend tble %d ", retval);
  3998. goto END;
  3999. }
  4000. break;
  4001. case V4L2_CID_PRIVATE_BLEND_RMSSIHI:
  4002. if (!is_valid_blend_value(ctrl->value)) {
  4003. FMDERR("%s: blend rmssi count is not valid\n",
  4004. __func__);
  4005. retval = -EINVAL;
  4006. goto END;
  4007. }
  4008. retval = hci_cmd(HCI_FM_GET_BLND_TBL_CMD, radio->fm_hdev);
  4009. if (retval < 0) {
  4010. FMDERR("Failed to get blend table %d", retval);
  4011. goto END;
  4012. }
  4013. radio->blend_tbl.scBlendRmssiHi = ctrl->value;
  4014. retval = hci_set_blend_tbl_req(&radio->blend_tbl,
  4015. radio->fm_hdev);
  4016. if (retval < 0) {
  4017. FMDERR("Failed to set blend tble %d ", retval);
  4018. goto END;
  4019. }
  4020. break;
  4021. default:
  4022. retval = -EINVAL;
  4023. }
  4024. END:
  4025. if (retval > 0)
  4026. retval = -EINVAL;
  4027. return retval;
  4028. }
  4029. static int update_spur_table(struct iris_device *radio)
  4030. {
  4031. struct hci_fm_def_data_wr_req default_data;
  4032. int len = 0, index = 0, offset = 0, i = 0;
  4033. int retval = 0, temp = 0, cnt = 0;
  4034. memset(&default_data, 0, sizeof(default_data));
  4035. /* Pass the mode of SPUR_CLK */
  4036. default_data.mode = CKK_SPUR;
  4037. if (radio == NULL) {
  4038. FMDERR(":radio is null");
  4039. return -EINVAL;
  4040. }
  4041. temp = radio->spur_table_size;
  4042. for (cnt = 0; cnt < (temp / 5); cnt++) {
  4043. offset = 0;
  4044. /*
  4045. * Program the spur entries in spur table in following order:
  4046. * Spur index
  4047. * Length of the spur data
  4048. * Spur Data:
  4049. * MSB of the spur frequency
  4050. * LSB of the spur frequency
  4051. * Enable/Disable the spur frequency
  4052. * RMSSI value of the spur frequency
  4053. */
  4054. default_data.data[offset++] = ENTRY_0 + cnt;
  4055. for (i = 0; i < SPUR_ENTRIES_PER_ID; i++) {
  4056. default_data.data[offset++] = GET_FREQ(COMPUTE_SPUR(
  4057. radio->spur_data.freq[index]), 0);
  4058. default_data.data[offset++] = GET_FREQ(COMPUTE_SPUR(
  4059. radio->spur_data.freq[index]), 1);
  4060. default_data.data[offset++] =
  4061. radio->spur_data.enable[index];
  4062. default_data.data[offset++] =
  4063. radio->spur_data.rmssi[index];
  4064. index++;
  4065. }
  4066. len = (SPUR_ENTRIES_PER_ID * SPUR_DATA_SIZE);
  4067. default_data.length = (len + 1);
  4068. retval = hci_def_data_write(&default_data, radio->fm_hdev);
  4069. if (retval < 0) {
  4070. FMDBG("%s: Failed to configure entries for ID : %d\n",
  4071. __func__, default_data.data[0]);
  4072. return retval;
  4073. }
  4074. }
  4075. /* Compute balance SPUR frequencies to be programmed */
  4076. temp %= SPUR_ENTRIES_PER_ID;
  4077. if (temp > 0) {
  4078. offset = 0;
  4079. default_data.data[offset++] = (radio->spur_table_size / 5);
  4080. for (i = 0; i < temp; i++) {
  4081. default_data.data[offset++] = GET_FREQ(COMPUTE_SPUR(
  4082. radio->spur_data.freq[index]), 0);
  4083. default_data.data[offset++] = GET_FREQ(COMPUTE_SPUR(
  4084. radio->spur_data.freq[index]), 1);
  4085. default_data.data[offset++] =
  4086. radio->spur_data.enable[index];
  4087. default_data.data[offset++] =
  4088. radio->spur_data.rmssi[index];
  4089. index++;
  4090. }
  4091. len = (temp * SPUR_DATA_SIZE);
  4092. default_data.length = (len + 1);
  4093. retval = hci_def_data_write(&default_data, radio->fm_hdev);
  4094. if (retval < 0) {
  4095. FMDERR("%s: Failed to configure entries for ID : %d\n",
  4096. __func__, default_data.data[0]);
  4097. return retval;
  4098. }
  4099. }
  4100. return retval;
  4101. }
  4102. static int iris_vidioc_g_tuner(struct file *file, void *priv,
  4103. struct v4l2_tuner *tuner)
  4104. {
  4105. int retval;
  4106. struct iris_device *radio = video_get_drvdata(video_devdata(file));
  4107. if (radio == NULL) {
  4108. FMDERR(":radio is null");
  4109. return -EINVAL;
  4110. }
  4111. if (tuner->index > 0) {
  4112. FMDERR("Invalid Tuner Index");
  4113. return -EINVAL;
  4114. }
  4115. if (radio->mode == FM_RECV) {
  4116. retval = hci_cmd(HCI_FM_GET_STATION_PARAM_CMD, radio->fm_hdev);
  4117. if (retval < 0) {
  4118. FMDERR("Failed to Get station params");
  4119. return retval;
  4120. }
  4121. tuner->type = V4L2_TUNER_RADIO;
  4122. tuner->rangelow =
  4123. radio->recv_conf.band_low_limit * TUNE_PARAM;
  4124. tuner->rangehigh =
  4125. radio->recv_conf.band_high_limit * TUNE_PARAM;
  4126. tuner->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
  4127. tuner->capability = V4L2_TUNER_CAP_LOW;
  4128. tuner->signal = radio->fm_st_rsp.station_rsp.rssi;
  4129. tuner->audmode = radio->fm_st_rsp.station_rsp.stereo_prg;
  4130. tuner->afc = 0;
  4131. } else if (radio->mode == FM_TRANS) {
  4132. retval = hci_cmd(HCI_FM_GET_TX_CONFIG, radio->fm_hdev);
  4133. if (retval < 0) {
  4134. FMDERR("get Tx config failed %d\n", retval);
  4135. return retval;
  4136. } else {
  4137. tuner->type = V4L2_TUNER_RADIO;
  4138. tuner->rangelow =
  4139. radio->trans_conf.band_low_limit * TUNE_PARAM;
  4140. tuner->rangehigh =
  4141. radio->trans_conf.band_high_limit * TUNE_PARAM;
  4142. }
  4143. } else
  4144. return -EINVAL;
  4145. return 0;
  4146. }
  4147. static int iris_vidioc_s_tuner(struct file *file, void *priv,
  4148. struct v4l2_tuner *tuner)
  4149. {
  4150. struct iris_device *radio = video_get_drvdata(video_devdata(file));
  4151. int retval = 0;
  4152. if (radio == NULL) {
  4153. FMDERR(":radio is null");
  4154. return -EINVAL;
  4155. }
  4156. if (tuner->index > 0)
  4157. return -EINVAL;
  4158. if (radio->mode == FM_RECV) {
  4159. radio->recv_conf.band_low_limit = tuner->rangelow / TUNE_PARAM;
  4160. radio->recv_conf.band_high_limit =
  4161. tuner->rangehigh / TUNE_PARAM;
  4162. if (tuner->audmode == V4L2_TUNER_MODE_MONO) {
  4163. radio->stereo_mode.stereo_mode = 0x01;
  4164. retval = hci_set_fm_stereo_mode(
  4165. &radio->stereo_mode,
  4166. radio->fm_hdev);
  4167. } else {
  4168. radio->stereo_mode.stereo_mode = 0x00;
  4169. retval = hci_set_fm_stereo_mode(
  4170. &radio->stereo_mode,
  4171. radio->fm_hdev);
  4172. }
  4173. if (retval < 0)
  4174. FMDERR(": set tuner failed with %d\n", retval);
  4175. return retval;
  4176. } else if (radio->mode == FM_TRANS) {
  4177. radio->trans_conf.band_low_limit =
  4178. tuner->rangelow / TUNE_PARAM;
  4179. radio->trans_conf.band_high_limit =
  4180. tuner->rangehigh / TUNE_PARAM;
  4181. } else
  4182. return -EINVAL;
  4183. return retval;
  4184. }
  4185. static int iris_vidioc_g_frequency(struct file *file, void *priv,
  4186. struct v4l2_frequency *freq)
  4187. {
  4188. struct iris_device *radio = video_get_drvdata(video_devdata(file));
  4189. if ((freq != NULL) && (radio != NULL)) {
  4190. freq->frequency =
  4191. radio->fm_st_rsp.station_rsp.station_freq * TUNE_PARAM;
  4192. } else
  4193. return -EINVAL;
  4194. return 0;
  4195. }
  4196. static int iris_vidioc_s_frequency(struct file *file, void *priv,
  4197. struct v4l2_frequency *freq)
  4198. {
  4199. struct iris_device *radio = video_get_drvdata(video_devdata(file));
  4200. int retval = -1;
  4201. freq->frequency = freq->frequency / TUNE_PARAM;
  4202. if (radio == NULL) {
  4203. FMDERR(":radio is null");
  4204. return -EINVAL;
  4205. }
  4206. if (freq->type != V4L2_TUNER_RADIO)
  4207. return -EINVAL;
  4208. /* We turn off RDS prior to tuning to a new station.
  4209. because of a bug in SoC which prevents tuning
  4210. during RDS transmission.
  4211. */
  4212. if (radio->mode == FM_TRANS
  4213. && (radio->trans_conf.rds_std == 0 ||
  4214. radio->trans_conf.rds_std == 1)) {
  4215. radio->prev_trans_rds = radio->trans_conf.rds_std;
  4216. radio->trans_conf.rds_std = 2;
  4217. hci_set_fm_trans_conf(&radio->trans_conf,
  4218. radio->fm_hdev);
  4219. }
  4220. retval = iris_set_freq(radio, freq->frequency);
  4221. if (radio->mode == FM_TRANS
  4222. && radio->trans_conf.rds_std == 2
  4223. && (radio->prev_trans_rds == 1
  4224. || radio->prev_trans_rds == 0)) {
  4225. radio->trans_conf.rds_std = radio->prev_trans_rds;
  4226. hci_set_fm_trans_conf(&radio->trans_conf,
  4227. radio->fm_hdev);
  4228. }
  4229. if (retval < 0)
  4230. FMDERR(" set frequency failed with %d\n", retval);
  4231. return retval;
  4232. }
  4233. static int iris_fops_release(struct file *file)
  4234. {
  4235. struct iris_device *radio = video_get_drvdata(video_devdata(file));
  4236. int retval = 0;
  4237. FMDBG("Enter %s ", __func__);
  4238. if (radio == NULL)
  4239. return -EINVAL;
  4240. if (radio->mode == FM_OFF)
  4241. goto END;
  4242. if (radio->mode == FM_RECV)
  4243. radio->is_fm_closing = 1;
  4244. radio->mode = FM_TURNING_OFF;
  4245. retval = hci_cmd_uninterruptible(HCI_FM_DISABLE_RECV_CMD,
  4246. radio->fm_hdev);
  4247. radio->is_fm_closing = 0;
  4248. else if (radio->mode == FM_TRANS)
  4249. radio->is_fm_closing = 1;
  4250. radio->mode = FM_TURNING_OFF;
  4251. retval = hci_cmd_uninterruptible(HCI_FM_DISABLE_TRANS_CMD,
  4252. radio->fm_hdev);
  4253. radio->is_fm_closing = 0;
  4254. } else if (radio->mode == FM_CALIB) {
  4255. radio->mode = FM_OFF;
  4256. return retval;
  4257. }
  4258. END:
  4259. mutex_lock(&fm_smd_enable);
  4260. if (radio->fm_hdev != NULL)
  4261. radio->fm_hdev->close_smd();
  4262. mutex_unlock(&fm_smd_enable);
  4263. if (retval < 0)
  4264. FMDERR("Err on disable FM %d\n", retval);
  4265. radio->mode = FM_OFF;
  4266. return retval;
  4267. }
  4268. static int iris_vidioc_dqbuf(struct file *file, void *priv,
  4269. struct v4l2_buffer *buffer)
  4270. {
  4271. struct iris_device *radio = video_get_drvdata(video_devdata(file));
  4272. enum iris_buf_t buf_type = -1;
  4273. unsigned char buf_fifo[STD_BUF_SIZE] = {0};
  4274. struct kfifo *data_fifo = NULL;
  4275. unsigned char *buf = NULL;
  4276. unsigned int len = 0, retval = -1;
  4277. if ((radio == NULL) || (buffer == NULL)) {
  4278. FMDERR("radio/buffer is NULL\n");
  4279. return -ENXIO;
  4280. }
  4281. buf_type = buffer->index;
  4282. buf = (unsigned char *)buffer->m.userptr;
  4283. len = buffer->length;
  4284. if ((buf_type < IRIS_BUF_MAX) && (buf_type >= 0)) {
  4285. data_fifo = &radio->data_buf[buf_type];
  4286. if (buf_type == IRIS_BUF_EVENTS)
  4287. if (wait_event_interruptible(radio->event_queue,
  4288. kfifo_len(data_fifo)) < 0)
  4289. return -EINTR;
  4290. } else {
  4291. FMDERR("invalid buffer type\n");
  4292. return -EINVAL;
  4293. }
  4294. if (len <= STD_BUF_SIZE) {
  4295. buffer->bytesused = kfifo_out_locked(data_fifo, &buf_fifo[0],
  4296. len, &radio->buf_lock[buf_type]);
  4297. } else {
  4298. FMDERR("kfifo_out_locked can not use len more than 128\n");
  4299. return -EINVAL;
  4300. }
  4301. retval = copy_to_user(buf, &buf_fifo[0], buffer->bytesused);
  4302. if (retval > 0) {
  4303. FMDERR("Failed to copy %d bytes of data\n", retval);
  4304. return -EAGAIN;
  4305. }
  4306. return retval;
  4307. }
  4308. static int iris_vidioc_g_fmt_type_private(struct file *file, void *priv,
  4309. struct v4l2_format *f)
  4310. {
  4311. return 0;
  4312. }
  4313. static int iris_vidioc_s_hw_freq_seek(struct file *file, void *priv,
  4314. struct v4l2_hw_freq_seek *seek)
  4315. {
  4316. struct iris_device *radio = video_get_drvdata(video_devdata(file));
  4317. int dir;
  4318. if (seek->seek_upward)
  4319. dir = SRCH_DIR_UP;
  4320. else
  4321. dir = SRCH_DIR_DOWN;
  4322. return iris_search(radio, CTRL_ON, dir);
  4323. }
  4324. static int iris_vidioc_querycap(struct file *file, void *priv,
  4325. struct v4l2_capability *capability)
  4326. {
  4327. struct iris_device *radio = video_get_drvdata(video_devdata(file));;
  4328. FMDBG("%s\n", __func__);
  4329. if (radio == NULL) {
  4330. FMDERR(":radio is null");
  4331. return -EINVAL;
  4332. }
  4333. strlcpy(capability->driver, DRIVER_NAME, sizeof(capability->driver));
  4334. strlcpy(capability->card, DRIVER_CARD, sizeof(capability->card));
  4335. capability->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
  4336. radio->g_cap = capability;
  4337. return 0;
  4338. }
  4339. static int initialise_recv(struct iris_device *radio)
  4340. {
  4341. int retval;
  4342. if (unlikely(radio == NULL)) {
  4343. FMDERR(":radio is null");
  4344. return -EINVAL;
  4345. }
  4346. radio->mute_mode.soft_mute = CTRL_OFF;
  4347. retval = hci_set_fm_mute_mode(&radio->mute_mode,
  4348. radio->fm_hdev);
  4349. if (retval < 0) {
  4350. FMDERR("Failed to enable Smute\n");
  4351. return retval;
  4352. }
  4353. radio->stereo_mode.stereo_mode = CTRL_OFF;
  4354. radio->stereo_mode.sig_blend = sig_blend;
  4355. radio->stereo_mode.intf_blend = CTRL_ON;
  4356. radio->stereo_mode.most_switch = CTRL_ON;
  4357. retval = hci_set_fm_stereo_mode(&radio->stereo_mode,
  4358. radio->fm_hdev);
  4359. if (retval < 0) {
  4360. FMDERR("Failed to set stereo mode\n");
  4361. return retval;
  4362. }
  4363. radio->event_mask = SIG_LEVEL_INTR | RDS_SYNC_INTR | AUDIO_CTRL_INTR;
  4364. retval = hci_conf_event_mask(&radio->event_mask, radio->fm_hdev);
  4365. if (retval < 0) {
  4366. FMDERR("Enable Async events failed");
  4367. return retval;
  4368. }
  4369. retval = hci_cmd(HCI_FM_GET_RECV_CONF_CMD, radio->fm_hdev);
  4370. if (retval < 0)
  4371. FMDERR("Failed to get the Recv Config\n");
  4372. return retval;
  4373. }
  4374. static int initialise_trans(struct iris_device *radio)
  4375. {
  4376. int retval;
  4377. if (unlikely(radio == NULL)) {
  4378. FMDERR(":radio is null");
  4379. return -EINVAL;
  4380. }
  4381. retval = hci_cmd(HCI_FM_GET_TX_CONFIG, radio->fm_hdev);
  4382. if (retval < 0)
  4383. FMDERR("get frequency failed %d\n", retval);
  4384. return retval;
  4385. }
  4386. static int is_enable_rx_possible(struct iris_device *radio)
  4387. {
  4388. int retval = 1;
  4389. if (unlikely(radio == NULL)) {
  4390. FMDERR(":radio is null");
  4391. return -EINVAL;
  4392. }
  4393. if (radio->mode == FM_OFF || radio->mode == FM_RECV)
  4394. retval = 0;
  4395. return retval;
  4396. }
  4397. static int is_enable_tx_possible(struct iris_device *radio)
  4398. {
  4399. int retval = 1;
  4400. if (radio->mode == FM_OFF || radio->mode == FM_TRANS)
  4401. retval = 0;
  4402. return retval;
  4403. }
  4404. static const struct v4l2_ioctl_ops iris_ioctl_ops = {
  4405. .vidioc_querycap = iris_vidioc_querycap,
  4406. .vidioc_queryctrl = iris_vidioc_queryctrl,
  4407. .vidioc_g_ctrl = iris_vidioc_g_ctrl,
  4408. .vidioc_s_ctrl = iris_vidioc_s_ctrl,
  4409. .vidioc_g_tuner = iris_vidioc_g_tuner,
  4410. .vidioc_s_tuner = iris_vidioc_s_tuner,
  4411. .vidioc_g_frequency = iris_vidioc_g_frequency,
  4412. .vidioc_s_frequency = iris_vidioc_s_frequency,
  4413. .vidioc_s_hw_freq_seek = iris_vidioc_s_hw_freq_seek,
  4414. .vidioc_dqbuf = iris_vidioc_dqbuf,
  4415. .vidioc_g_fmt_type_private = iris_vidioc_g_fmt_type_private,
  4416. .vidioc_s_ext_ctrls = iris_vidioc_s_ext_ctrls,
  4417. .vidioc_g_ext_ctrls = iris_vidioc_g_ext_ctrls,
  4418. };
  4419. static int is_initialized = 0;
  4420. static int video_open(struct file *file) {
  4421. int retval;
  4422. if (!is_initialized) {
  4423. retval = hci_fm_smd_register();
  4424. if (retval) {
  4425. FMDERR(": hci_fm_smd_register failed\n");
  4426. return retval;
  4427. }
  4428. is_initialized = 1;
  4429. }
  4430. return 0;
  4431. }
  4432. static const struct v4l2_file_operations iris_fops = {
  4433. .owner = THIS_MODULE,
  4434. .unlocked_ioctl = video_ioctl2,
  4435. .release = iris_fops_release,
  4436. .open = video_open,
  4437. };
  4438. static struct video_device iris_viddev_template = {
  4439. .fops = &iris_fops,
  4440. .ioctl_ops = &iris_ioctl_ops,
  4441. .name = DRIVER_NAME,
  4442. .release = video_device_release,
  4443. };
  4444. static struct video_device *video_get_dev(void)
  4445. {
  4446. return priv_videodev;
  4447. }
  4448. static int __init iris_probe(struct platform_device *pdev)
  4449. {
  4450. struct iris_device *radio;
  4451. int retval;
  4452. int radio_nr = -1;
  4453. int i;
  4454. if (!pdev) {
  4455. FMDERR(": pdev is null\n");
  4456. return -ENOMEM;
  4457. }
  4458. radio = kzalloc(sizeof(struct iris_device), GFP_KERNEL);
  4459. if (!radio) {
  4460. FMDERR(": Could not allocate radio device\n");
  4461. return -ENOMEM;
  4462. }
  4463. radio->dev = &pdev->dev;
  4464. platform_set_drvdata(pdev, radio);
  4465. radio->videodev = video_device_alloc();
  4466. if (!radio->videodev) {
  4467. FMDERR(": Could not allocate V4L device\n");
  4468. kfree(radio);
  4469. return -ENOMEM;
  4470. }
  4471. memcpy(radio->videodev, &iris_viddev_template,
  4472. sizeof(iris_viddev_template));
  4473. for (i = 0; i < IRIS_BUF_MAX; i++) {
  4474. int kfifo_alloc_rc = 0;
  4475. spin_lock_init(&radio->buf_lock[i]);
  4476. if ((i == IRIS_BUF_RAW_RDS) || (i == IRIS_BUF_PEEK))
  4477. kfifo_alloc_rc = kfifo_alloc(&radio->data_buf[i],
  4478. rds_buf*3, GFP_KERNEL);
  4479. else if ((i == IRIS_BUF_CAL_DATA) || (i == IRIS_BUF_RT_RDS))
  4480. kfifo_alloc_rc = kfifo_alloc(&radio->data_buf[i],
  4481. STD_BUF_SIZE*2, GFP_KERNEL);
  4482. else
  4483. kfifo_alloc_rc = kfifo_alloc(&radio->data_buf[i],
  4484. STD_BUF_SIZE, GFP_KERNEL);
  4485. if (kfifo_alloc_rc != 0) {
  4486. FMDERR("failed allocating buffers %d\n",
  4487. kfifo_alloc_rc);
  4488. for (; i > -1; i--)
  4489. kfifo_free(&radio->data_buf[i]);
  4490. video_device_release(radio->videodev);
  4491. kfree(radio);
  4492. return -ENOMEM;
  4493. }
  4494. }
  4495. mutex_init(&radio->lock);
  4496. init_completion(&radio->sync_xfr_start);
  4497. radio->tune_req = 0;
  4498. radio->prev_trans_rds = 2;
  4499. radio->is_fm_closing = 0;
  4500. init_waitqueue_head(&radio->event_queue);
  4501. init_waitqueue_head(&radio->read_queue);
  4502. video_set_drvdata(radio->videodev, radio);
  4503. if (NULL == video_get_drvdata(radio->videodev))
  4504. FMDERR(": video_get_drvdata failed\n");
  4505. retval = video_register_device(radio->videodev, VFL_TYPE_RADIO,
  4506. radio_nr);
  4507. if (retval) {
  4508. FMDERR(": Could not register video device\n");
  4509. mutex_destroy(&radio->lock);
  4510. video_device_release(radio->videodev);
  4511. for (; i > -1; i--)
  4512. kfifo_free(&radio->data_buf[i]);
  4513. kfree(radio);
  4514. return retval;
  4515. } else {
  4516. priv_videodev = kzalloc(sizeof(struct video_device),
  4517. GFP_KERNEL);
  4518. if (priv_videodev != NULL) {
  4519. memcpy(priv_videodev, radio->videodev,
  4520. sizeof(struct video_device));
  4521. } else {
  4522. mutex_destroy(&radio->lock);
  4523. video_unregister_device(radio->videodev);
  4524. video_device_release(radio->videodev);
  4525. for (; i > -1; i--)
  4526. kfifo_free(&radio->data_buf[i]);
  4527. kfree(radio);
  4528. return -ENOMEM;
  4529. }
  4530. }
  4531. return 0;
  4532. }
  4533. static int __devexit iris_remove(struct platform_device *pdev)
  4534. {
  4535. int i;
  4536. struct iris_device *radio = platform_get_drvdata(pdev);
  4537. if (radio == NULL) {
  4538. FMDERR(":radio is null");
  4539. return -EINVAL;
  4540. }
  4541. hci_fm_smd_deregister();
  4542. video_unregister_device(radio->videodev);
  4543. for (i = 0; i < IRIS_BUF_MAX; i++)
  4544. kfifo_free(&radio->data_buf[i]);
  4545. kfree(radio);
  4546. platform_set_drvdata(pdev, NULL);
  4547. return 0;
  4548. }
  4549. static const struct of_device_id iris_fm_match[] = {
  4550. {.compatible = "qcom,iris_fm"},
  4551. {}
  4552. };
  4553. static struct platform_driver iris_driver = {
  4554. .driver = {
  4555. .owner = THIS_MODULE,
  4556. .name = "iris_fm",
  4557. .of_match_table = iris_fm_match,
  4558. },
  4559. .remove = __devexit_p(iris_remove),
  4560. };
  4561. static int __init iris_radio_init(void)
  4562. {
  4563. return platform_driver_probe(&iris_driver, iris_probe);
  4564. }
  4565. module_init(iris_radio_init);
  4566. static void __exit iris_radio_exit(void)
  4567. {
  4568. platform_driver_unregister(&iris_driver);
  4569. }
  4570. module_exit(iris_radio_exit);
  4571. MODULE_LICENSE("GPL v2");
  4572. MODULE_AUTHOR(DRIVER_AUTHOR);
  4573. MODULE_DESCRIPTION(DRIVER_DESC);