sbpcd.c 167 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967
  1. /*
  2. * sbpcd.c CD-ROM device driver for the whole family of traditional,
  3. * non-ATAPI IDE-style Matsushita/Panasonic CR-5xx drives.
  4. * Works with SoundBlaster compatible cards and with "no-sound"
  5. * interface cards like Lasermate, Panasonic CI-101P, Teac, ...
  6. * Also for the Longshine LCS-7260 drive.
  7. * Also for the IBM "External ISA CD-Rom" drive.
  8. * Also for the CreativeLabs CD200 drive.
  9. * Also for the TEAC CD-55A drive.
  10. * Also for the ECS-AT "Vertos 100" drive.
  11. * Not for Sanyo drives (but for the H94A, sjcd is there...).
  12. * Not for any other Funai drives than the CD200 types (sometimes
  13. * labelled E2550UA or MK4015 or 2800F).
  14. */
  15. #define VERSION "v4.63 Andrew J. Kroll <ag784@freenet.buffalo.edu> Wed Jul 26 04:24:10 EDT 2000"
  16. /* Copyright (C) 1993, 1994, 1995 Eberhard Moenkeberg <emoenke@gwdg.de>
  17. *
  18. * This program is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation; either version 2, or (at your option)
  21. * any later version.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * (for example /usr/src/linux/COPYING); if not, write to the Free
  25. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. *
  27. * If you change this software, you should mail a .diff file with some
  28. * description lines to emoenke@gwdg.de. I want to know about it.
  29. *
  30. * If you are the editor of a Linux CD, you should enable sbpcd.c within
  31. * your boot floppy kernel and send me one of your CDs for free.
  32. *
  33. * If you would like to port the driver to an other operating system (f.e.
  34. * FreeBSD or NetBSD) or use it as an information source, you shall not be
  35. * restricted by the GPL under the following conditions:
  36. * a) the source code of your work is freely available
  37. * b) my part of the work gets mentioned at all places where your
  38. * authorship gets mentioned
  39. * c) I receive a copy of your code together with a full installation
  40. * package of your operating system for free.
  41. *
  42. *
  43. * VERSION HISTORY
  44. *
  45. * 0.1 initial release, April/May 93, after mcd.c (Martin Harriss)
  46. *
  47. * 0.2 thek "repeat:"-loop in do_sbpcd_request did not check for
  48. * end-of-request_queue (resulting in kernel panic).
  49. * Flow control seems stable, but throughput is not better.
  50. *
  51. * 0.3 interrupt locking totally eliminated (maybe "inb" and "outb"
  52. * are still locking) - 0.2 made keyboard-type-ahead losses.
  53. * check_sbpcd_media_change added (to use by isofs/inode.c)
  54. * - but it detects almost nothing.
  55. *
  56. * 0.4 use MAJOR 25 definitely.
  57. * Almost total re-design to support double-speed drives and
  58. * "naked" (no sound) interface cards ("LaserMate" interface type).
  59. * Flow control should be exact now.
  60. * Don't occupy the SbPro IRQ line (not needed either); will
  61. * live together with Hannu Savolainen's sndkit now.
  62. * Speeded up data transfer to 150 kB/sec, with help from Kai
  63. * Makisara, the "provider" of the "mt" tape utility.
  64. * Give "SpinUp" command if necessary.
  65. * First steps to support up to 4 drives (but currently only one).
  66. * Implemented audio capabilities - workman should work, xcdplayer
  67. * gives some problems.
  68. * This version is still consuming too much CPU time, and
  69. * sleeping still has to be worked on.
  70. * During "long" implied seeks, it seems possible that a
  71. * ReadStatus command gets ignored. That gives the message
  72. * "ResponseStatus timed out" (happens about 6 times here during
  73. * a "ls -alR" of the YGGDRASIL LGX-Beta CD). Such a case is
  74. * handled without data error, but it should get done better.
  75. *
  76. * 0.5 Free CPU during waits (again with help from Kai Makisara).
  77. * Made it work together with the LILO/kernel setup standard.
  78. * Included auto-probing code, as suggested by YGGDRASIL.
  79. * Formal redesign to add DDI debugging.
  80. * There are still flaws in IOCTL (workman with double speed drive).
  81. *
  82. * 1.0 Added support for all drive IDs (0...3, no longer only 0)
  83. * and up to 4 drives on one controller.
  84. * Added "#define MANY_SESSION" for "old" multi session CDs.
  85. *
  86. * 1.1 Do SpinUp for new drives, too.
  87. * Revised for clean compile under "old" kernels (0.99pl9).
  88. *
  89. * 1.2 Found the "workman with double-speed drive" bug: use the driver's
  90. * audio_state, not what the drive is reporting with ReadSubQ.
  91. *
  92. * 1.3 Minor cleanups.
  93. * Refinements regarding Workman.
  94. *
  95. * 1.4 Read XA disks (PhotoCDs) with "old" drives, too (but only the first
  96. * session - no chance to fully access a "multi-session" CD).
  97. * This currently still is too slow (50 kB/sec) - but possibly
  98. * the old drives won't do it faster.
  99. * Implemented "door (un)lock" for new drives (still does not work
  100. * as wanted - no lock possible after an unlock).
  101. * Added some debugging printout for the UPC/EAN code - but my drives
  102. * return only zeroes. Is there no UPC/EAN code written?
  103. *
  104. * 1.5 Laborate with UPC/EAN code (not better yet).
  105. * Adapt to kernel 1.1.8 change (have to explicitly include
  106. * <linux/string.h> now).
  107. *
  108. * 1.6 Trying to read audio frames as data. Impossible with the current
  109. * drive firmware levels, as it seems. Awaiting any hint. ;-)
  110. * Changed "door unlock": repeat it until success.
  111. * Changed CDROMSTOP routine (stop somewhat "softer" so that Workman
  112. * won't get confused).
  113. * Added a third interface type: Sequoia S-1000, as used with the SPEA
  114. * Media FX sound card. This interface (usable for Sony and Mitsumi
  115. * drives, too) needs a special configuration setup and behaves like a
  116. * LaserMate type after that. Still experimental - I do not have such
  117. * an interface.
  118. * Use the "variable BLOCK_SIZE" feature (2048). But it does only work
  119. * if you give the mount option "block=2048".
  120. * The media_check routine is currently disabled; now that it gets
  121. * called as it should I fear it must get synchronized for not to
  122. * disturb the normal driver's activity.
  123. *
  124. * 2.0 Version number bumped - two reasons:
  125. * - reading audio tracks as data works now with CR-562 and CR-563. We
  126. * currently do it by an IOCTL (yet has to get standardized), one frame
  127. * at a time; that is pretty slow. But it works.
  128. * - we are maintaining now up to 4 interfaces (each up to 4 drives):
  129. * did it the easy way - a different MAJOR (25, 26, ...) and a different
  130. * copy of the driver (sbpcd.c, sbpcd2.c, sbpcd3.c, sbpcd4.c - only
  131. * distinguished by the value of SBPCD_ISSUE and the driver's name),
  132. * and a common sbpcd.h file.
  133. * Bettered the "ReadCapacity error" problem with old CR-52x drives (the
  134. * drives sometimes need a manual "eject/insert" before work): just
  135. * reset the drive and do again. Needs lots of resets here and sometimes
  136. * that does not cure, so this can't be the solution.
  137. *
  138. * 2.1 Found bug with multisession CDs (accessing frame 16).
  139. * "read audio" works now with address type CDROM_MSF, too.
  140. * Bigger audio frame buffer: allows reading max. 4 frames at time; this
  141. * gives a significant speedup, but reading more than one frame at once
  142. * gives missing chunks at each single frame boundary.
  143. *
  144. * 2.2 Kernel interface cleanups: timers, init, setup, media check.
  145. *
  146. * 2.3 Let "door lock" and "eject" live together.
  147. * Implemented "close tray" (done automatically during open).
  148. *
  149. * 2.4 Use different names for device registering.
  150. *
  151. * 2.5 Added "#if EJECT" code (default: enabled) to automatically eject
  152. * the tray during last call to "sbpcd_release".
  153. * Added "#if JUKEBOX" code (default: disabled) to automatically eject
  154. * the tray during call to "sbpcd_open" if no disk is in.
  155. * Turn on the CD volume of "compatible" sound cards, too; just define
  156. * SOUND_BASE (in sbpcd.h) accordingly (default: disabled).
  157. *
  158. * 2.6 Nothing new.
  159. *
  160. * 2.7 Added CDROMEJECT_SW ioctl to set the "EJECT" behavior on the fly:
  161. * 0 disables, 1 enables auto-ejecting. Useful to keep the tray in
  162. * during shutdown.
  163. *
  164. * 2.8 Added first support (still BETA, I need feedback or a drive) for
  165. * the Longshine LCS-7260 drives. They appear as double-speed drives
  166. * using the "old" command scheme, extended by tray control and door
  167. * lock functions.
  168. * Found (and fixed preliminary) a flaw with some multisession CDs: we
  169. * have to re-direct not only the accesses to frame 16 (the isofs
  170. * routines drive it up to max. 100), but also those to the continuation
  171. * (repetition) frames (as far as they exist - currently set fix as
  172. * 16..20).
  173. * Changed default of the "JUKEBOX" define. If you use this default,
  174. * your tray will eject if you try to mount without a disk in. Next
  175. * mount command will insert the tray - so, just fill in a disk. ;-)
  176. *
  177. * 2.9 Fulfilled the Longshine LCS-7260 support; with great help and
  178. * experiments by Serge Robyns.
  179. * First attempts to support the TEAC CD-55A drives; but still not
  180. * usable yet.
  181. * Implemented the CDROMMULTISESSION ioctl; this is an attempt to handle
  182. * multi session CDs more "transparent" (redirection handling has to be
  183. * done within the isofs routines, and only for the special purpose of
  184. * obtaining the "right" volume descriptor; accesses to the raw device
  185. * should not get redirected).
  186. *
  187. * 3.0 Just a "normal" increment, with some provisions to do it better. ;-)
  188. * Introduced "#define READ_AUDIO" to specify the maximum number of
  189. * audio frames to grab with one request. This defines a buffer size
  190. * within kernel space; a value of 0 will reserve no such space and
  191. * disable the CDROMREADAUDIO ioctl. A value of 75 enables the reading
  192. * of a whole second with one command, but will use a buffer of more
  193. * than 172 kB.
  194. * Started CD200 support. Drive detection should work, but nothing
  195. * more.
  196. *
  197. * 3.1 Working to support the CD200 and the Teac CD-55A drives.
  198. * AT-BUS style device numbering no longer used: use SCSI style now.
  199. * So, the first "found" device has MINOR 0, regardless of the
  200. * jumpered drive ID. This implies modifications to the /dev/sbpcd*
  201. * entries for some people, but will help the DAU (german TLA, english:
  202. * "newbie", maybe ;-) to install his "first" system from a CD.
  203. *
  204. * 3.2 Still testing with CD200 and CD-55A drives.
  205. *
  206. * 3.3 Working with CD200 support.
  207. *
  208. * 3.4 Auto-probing stops if an address of 0 is seen (to be entered with
  209. * the kernel command line).
  210. * Made the driver "loadable". If used as a module, "audio copy" is
  211. * disabled, and the internal read ahead data buffer has a reduced size
  212. * of 4 kB; so, throughput may be reduced a little bit with slow CPUs.
  213. *
  214. * 3.5 Provisions to handle weird photoCDs which have an interrupted
  215. * "formatting" immediately after the last frames of some files: simply
  216. * never "read ahead" with MultiSession CDs. By this, CPU usage may be
  217. * increased with those CDs, and there may be a loss in speed.
  218. * Re-structured the messaging system.
  219. * The "loadable" version no longer has a limited READ_AUDIO buffer
  220. * size.
  221. * Removed "MANY_SESSION" handling for "old" multi session CDs.
  222. * Added "private" IOCTLs CDROMRESET and CDROMVOLREAD.
  223. * Started again to support the TEAC CD-55A drives, now that I found
  224. * the money for "my own" drive. ;-)
  225. * The TEAC CD-55A support is fairly working now.
  226. * I have measured that the drive "delivers" at 600 kB/sec (even with
  227. * bigger requests than the drive's 64 kB buffer can satisfy), but
  228. * the "real" rate does not exceed 520 kB/sec at the moment.
  229. * Caused by the various changes to build in TEAC support, the timed
  230. * loops are de-optimized at the moment (less throughput with CR-52x
  231. * drives, and the TEAC will give speed only with SBP_BUFFER_FRAMES 64).
  232. *
  233. * 3.6 Fixed TEAC data read problems with SbPro interfaces.
  234. * Initial size of the READ_AUDIO buffer is 0. Can get set to any size
  235. * during runtime.
  236. *
  237. * 3.7 Introduced MAX_DRIVES for some poor interface cards (seen with TEAC
  238. * drives) which allow only one drive (ID 0); this avoids repetitive
  239. * detection under IDs 1..3.
  240. * Elongated cmd_out_T response waiting; necessary for photo CDs with
  241. * a lot of sessions.
  242. * Bettered the sbpcd_open() behavior with TEAC drives.
  243. *
  244. * 3.8 Elongated max_latency for CR-56x drives.
  245. *
  246. * 3.9 Finally fixed the long-known SoundScape/SPEA/Sequoia S-1000 interface
  247. * configuration bug.
  248. * Now Corey, Heiko, Ken, Leo, Vadim/Eric & Werner are invited to copy
  249. * the config_spea() routine into their drivers. ;-)
  250. *
  251. * 4.0 No "big step" - normal version increment.
  252. * Adapted the benefits from 1.3.33.
  253. * Fiddled with CDROMREADAUDIO flaws.
  254. * Avoid ReadCapacity command with CD200 drives (the MKE 1.01 version
  255. * seems not to support it).
  256. * Fulfilled "read audio" for CD200 drives, with help of Pete Heist
  257. * (heistp@rpi.edu).
  258. *
  259. * 4.1 Use loglevel KERN_INFO with printk().
  260. * Added support for "Vertos 100" drive ("ECS-AT") - it is very similar
  261. * to the Longshine LCS-7260. Give feedback if you can - I never saw
  262. * such a drive, and I have no specs.
  263. *
  264. * 4.2 Support for Teac 16-bit interface cards. Can't get auto-detected,
  265. * so you have to jumper your card to 0x2C0. Still not 100% - come
  266. * in contact if you can give qualified feedback.
  267. * Use loglevel KERN_NOTICE with printk(). If you get annoyed by a
  268. * flood of unwanted messages and the accompanied delay, try to read
  269. * my documentation. Especially the Linux CDROM drivers have to do an
  270. * important job for the newcomers, so the "distributed" version has
  271. * to fit some special needs. Since generations, the flood of messages
  272. * is user-configurable (even at runtime), but to get aware of this, one
  273. * needs a special mental quality: the ability to read.
  274. *
  275. * 4.3 CD200F does not like to receive a command while the drive is
  276. * reading the ToC; still trying to solve it.
  277. * Removed some redundant verify_area calls (yes, Heiko Eissfeldt
  278. * is visiting all the Linux CDROM drivers ;-).
  279. *
  280. * 4.4 Adapted one idea from tiensivu@pilot.msu.edu's "stripping-down"
  281. * experiments: "KLOGD_PAUSE".
  282. * Inhibited "play audio" attempts with data CDs. Provisions for a
  283. * "data-safe" handling of "mixed" (data plus audio) Cds.
  284. *
  285. * 4.5 Meanwhile Gonzalo Tornaria <tornaria@cmat.edu.uy> (GTL) built a
  286. * special end_request routine: we seem to have to take care for not
  287. * to have two processes working at the request list. My understanding
  288. * was and is that ll_rw_blk should not call do_sbpcd_request as long
  289. * as there is still one call active (the first call will care for all
  290. * outstanding I/Os, and if a second call happens, that is a bug in
  291. * ll_rw_blk.c).
  292. * "Check media change" without touching any drive.
  293. *
  294. * 4.6 Use a semaphore to synchronize multi-activity; elaborated by Rob
  295. * Riggs <rriggs@tesser.com>. At the moment, we simply block "read"
  296. * against "ioctl" and vice versa. This could be refined further, but
  297. * I guess with almost no performance increase.
  298. * Experiments to speed up the CD-55A; again with help of Rob Riggs
  299. * (to be true, he gave both, idea & code. ;-)
  300. *
  301. * 4.61 Ported to Uniform CD-ROM driver by
  302. * Heiko Eissfeldt <heiko@colossus.escape.de> with additional
  303. * changes by Erik Andersen <andersee@debian.org>
  304. *
  305. * 4.62 Fix a bug where playing audio left the drive in an unusable state.
  306. * Heiko Eissfeldt <heiko@colossus.escape.de>
  307. *
  308. * November 1999 -- Make kernel-parameter implementation work with 2.3.x
  309. * Removed init_module & cleanup_module in favor of
  310. * module_init & module_exit.
  311. * Torben Mathiasen <tmm@image.dk>
  312. *
  313. * 4.63 Bug fixes for audio annoyances, new legacy CDROM maintainer.
  314. * Annoying things fixed:
  315. * TOC reread on automated disk changes
  316. * TOC reread on manual cd changes
  317. * Play IOCTL tries to play CD before it's actually ready... sometimes.
  318. * CD_AUDIO_COMPLETED state so workman (and other playes) can repeat play.
  319. * Andrew J. Kroll <ag784@freenet.buffalo.edu> Wed Jul 26 04:24:10 EDT 2000
  320. *
  321. * 4.64 Fix module parameters - were being completely ignored.
  322. * Can also specify max_drives=N as a setup int to get rid of
  323. * "ghost" drives on crap hardware (aren't they all?) Paul Gortmaker
  324. *
  325. * TODO
  326. * implement "read all subchannel data" (96 bytes per frame)
  327. * remove alot of the virtual status bits and deal with hardware status
  328. * move the change of cd for audio to a better place
  329. * add debug levels to insmod parameters (trivial)
  330. *
  331. * special thanks to Kai Makisara (kai.makisara@vtt.fi) for his fine
  332. * elaborated speed-up experiments (and the fabulous results!), for
  333. * the "push" towards load-free wait loops, and for the extensive mail
  334. * thread which brought additional hints and bug fixes.
  335. *
  336. */
  337. /*
  338. * Trying to merge requests breaks this driver horribly (as in it goes
  339. * boom and apparently has done so since 2.3.41). As it is a legacy
  340. * driver for a horribly slow double speed CD on a hideous interface
  341. * designed for polled operation, I won't lose any sleep in simply
  342. * disallowing merging. Paul G. 02/2001
  343. *
  344. * Thu May 30 14:14:47 CEST 2002:
  345. *
  346. * I have presumably found the reson for the above - there was a bogous
  347. * end_request substitute, which was manipulating the request queues
  348. * incorrectly. If someone has access to the actual hardware, and it's
  349. * still operations - well please free to test it.
  350. *
  351. * Marcin Dalecki
  352. */
  353. /*
  354. * Add bio/kdev_t changes for 2.5.x required to make it work again.
  355. * Still room for improvement in the request handling here if anyone
  356. * actually cares. Bring your own chainsaw. Paul G. 02/2002
  357. */
  358. #include <linux/module.h>
  359. #include <linux/errno.h>
  360. #include <linux/sched.h>
  361. #include <linux/mm.h>
  362. #include <linux/timer.h>
  363. #include <linux/fs.h>
  364. #include <linux/kernel.h>
  365. #include <linux/cdrom.h>
  366. #include <linux/ioport.h>
  367. #include <linux/major.h>
  368. #include <linux/string.h>
  369. #include <linux/vmalloc.h>
  370. #include <linux/init.h>
  371. #include <linux/interrupt.h>
  372. #include <asm/system.h>
  373. #include <asm/io.h>
  374. #include <asm/uaccess.h>
  375. #include <stdarg.h>
  376. #include "sbpcd.h"
  377. #define MAJOR_NR MATSUSHITA_CDROM_MAJOR
  378. #include <linux/blkdev.h>
  379. /*==========================================================================*/
  380. #if SBPCD_DIS_IRQ
  381. # define SBPCD_CLI cli()
  382. # define SBPCD_STI sti()
  383. #else
  384. # define SBPCD_CLI
  385. # define SBPCD_STI
  386. #endif
  387. /*==========================================================================*/
  388. /*
  389. * auto-probing address list
  390. * inspired by Adam J. Richter from Yggdrasil
  391. *
  392. * still not good enough - can cause a hang.
  393. * example: a NE 2000 ethernet card at 300 will cause a hang probing 310.
  394. * if that happens, reboot and use the LILO (kernel) command line.
  395. * The possibly conflicting ethernet card addresses get NOT probed
  396. * by default - to minimize the hang possibilities.
  397. *
  398. * The SB Pro addresses get "mirrored" at 0x6xx and some more locations - to
  399. * avoid a type error, the 0x2xx-addresses must get checked before 0x6xx.
  400. *
  401. * send mail to emoenke@gwdg.de if your interface card is not FULLY
  402. * represented here.
  403. */
  404. static int sbpcd[] =
  405. {
  406. CDROM_PORT, SBPRO, /* probe with user's setup first */
  407. #if DISTRIBUTION
  408. 0x230, 1, /* Soundblaster Pro and 16 (default) */
  409. #if 0
  410. 0x300, 0, /* CI-101P (default), WDH-7001C (default),
  411. Galaxy (default), Reveal (one default) */
  412. 0x250, 1, /* OmniCD default, Soundblaster Pro and 16 */
  413. 0x2C0, 3, /* Teac 16-bit cards */
  414. 0x260, 1, /* OmniCD */
  415. 0x320, 0, /* Lasermate, CI-101P, WDH-7001C, Galaxy, Reveal (other default),
  416. Longshine LCS-6853 (default) */
  417. 0x338, 0, /* Reveal Sound Wave 32 card model #SC600 */
  418. 0x340, 0, /* Mozart sound card (default), Lasermate, CI-101P */
  419. 0x360, 0, /* Lasermate, CI-101P */
  420. 0x270, 1, /* Soundblaster 16 */
  421. 0x670, 0, /* "sound card #9" */
  422. 0x690, 0, /* "sound card #9" */
  423. 0x338, 2, /* SPEA Media FX, Ensonic SoundScape (default) */
  424. 0x328, 2, /* SPEA Media FX */
  425. 0x348, 2, /* SPEA Media FX */
  426. 0x634, 0, /* some newer sound cards */
  427. 0x638, 0, /* some newer sound cards */
  428. 0x230, 1, /* some newer sound cards */
  429. /* due to incomplete address decoding of the SbPro card, these must be last */
  430. 0x630, 0, /* "sound card #9" (default) */
  431. 0x650, 0, /* "sound card #9" */
  432. #ifdef MODULE
  433. /*
  434. * some "hazardous" locations (no harm with the loadable version)
  435. * (will stop the bus if a NE2000 ethernet card resides at offset -0x10)
  436. */
  437. 0x330, 0, /* Lasermate, CI-101P, WDH-7001C */
  438. 0x350, 0, /* Lasermate, CI-101P */
  439. 0x358, 2, /* SPEA Media FX */
  440. 0x370, 0, /* Lasermate, CI-101P */
  441. 0x290, 1, /* Soundblaster 16 */
  442. 0x310, 0, /* Lasermate, CI-101P, WDH-7001C */
  443. #endif /* MODULE */
  444. #endif
  445. #endif /* DISTRIBUTION */
  446. };
  447. /*
  448. * Protects access to global structures etc.
  449. */
  450. static __cacheline_aligned DEFINE_SPINLOCK(sbpcd_lock);
  451. static struct request_queue *sbpcd_queue;
  452. /* You can only set the first pair, from old MODULE_PARM code. */
  453. static int sbpcd_set(const char *val, struct kernel_param *kp)
  454. {
  455. get_options((char *)val, 2, (int *)sbpcd);
  456. return 0;
  457. }
  458. module_param_call(sbpcd, sbpcd_set, NULL, NULL, 0);
  459. #define NUM_PROBE (sizeof(sbpcd) / sizeof(int))
  460. /*==========================================================================*/
  461. #define INLINE inline
  462. /*==========================================================================*/
  463. /*
  464. * the forward references:
  465. */
  466. static void sbp_sleep(u_int);
  467. static void mark_timeout_delay(u_long);
  468. static void mark_timeout_data(u_long);
  469. #if 0
  470. static void mark_timeout_audio(u_long);
  471. #endif
  472. static void sbp_read_cmd(struct request *req);
  473. static int sbp_data(struct request *req);
  474. static int cmd_out(void);
  475. static int DiskInfo(void);
  476. /*==========================================================================*/
  477. /*
  478. * pattern for printk selection:
  479. *
  480. * (1<<DBG_INF) necessary information
  481. * (1<<DBG_BSZ) BLOCK_SIZE trace
  482. * (1<<DBG_REA) "read" status trace
  483. * (1<<DBG_CHK) "media check" trace
  484. * (1<<DBG_TIM) datarate timer test
  485. * (1<<DBG_INI) initialization trace
  486. * (1<<DBG_TOC) tell TocEntry values
  487. * (1<<DBG_IOC) ioctl trace
  488. * (1<<DBG_STA) "ResponseStatus" trace
  489. * (1<<DBG_ERR) "cc_ReadError" trace
  490. * (1<<DBG_CMD) "cmd_out" trace
  491. * (1<<DBG_WRN) give explanation before auto-probing
  492. * (1<<DBG_MUL) multi session code test
  493. * (1<<DBG_IDX) "drive_id != 0" test code
  494. * (1<<DBG_IOX) some special information
  495. * (1<<DBG_DID) drive ID test
  496. * (1<<DBG_RES) drive reset info
  497. * (1<<DBG_SPI) SpinUp test info
  498. * (1<<DBG_IOS) ioctl trace: "subchannel"
  499. * (1<<DBG_IO2) ioctl trace: general
  500. * (1<<DBG_UPC) show UPC info
  501. * (1<<DBG_XA1) XA mode debugging
  502. * (1<<DBG_LCK) door (un)lock info
  503. * (1<<DBG_SQ1) dump SubQ frame
  504. * (1<<DBG_AUD) "read audio" debugging
  505. * (1<<DBG_SEQ) Sequoia interface configuration trace
  506. * (1<<DBG_LCS) Longshine LCS-7260 debugging trace
  507. * (1<<DBG_CD2) MKE/Funai CD200 debugging trace
  508. * (1<<DBG_TEA) TEAC CD-55A debugging trace
  509. * (1<<DBG_ECS) ECS-AT (Vertos-100) debugging trace
  510. * (1<<DBG_000) unnecessary information
  511. */
  512. #if DISTRIBUTION
  513. static int sbpcd_debug = (1<<DBG_INF);
  514. #else
  515. static int sbpcd_debug = 0 & ((1<<DBG_INF) |
  516. (1<<DBG_TOC) |
  517. (1<<DBG_MUL) |
  518. (1<<DBG_UPC));
  519. #endif /* DISTRIBUTION */
  520. static int sbpcd_ioaddr = CDROM_PORT; /* default I/O base address */
  521. static int sbpro_type = SBPRO;
  522. static unsigned char f_16bit;
  523. static unsigned char do_16bit;
  524. static int CDo_command, CDo_reset;
  525. static int CDo_sel_i_d, CDo_enable;
  526. static int CDi_info, CDi_status, CDi_data;
  527. static struct cdrom_msf msf;
  528. static struct cdrom_ti ti;
  529. static struct cdrom_tochdr tochdr;
  530. static struct cdrom_tocentry tocentry;
  531. static struct cdrom_subchnl SC;
  532. static struct cdrom_volctrl volctrl;
  533. static struct cdrom_read_audio read_audio;
  534. static unsigned char msgnum;
  535. static char msgbuf[80];
  536. static int max_drives = MAX_DRIVES;
  537. module_param(max_drives, int, 0);
  538. #ifndef MODULE
  539. static unsigned char setup_done;
  540. static const char *str_sb_l = "soundblaster";
  541. static const char *str_sp_l = "spea";
  542. static const char *str_ss_l = "soundscape";
  543. static const char *str_t16_l = "teac16bit";
  544. static const char *str_ss = "SoundScape";
  545. #endif
  546. static const char *str_sb = "SoundBlaster";
  547. static const char *str_lm = "LaserMate";
  548. static const char *str_sp = "SPEA";
  549. static const char *str_t16 = "Teac16bit";
  550. static const char *type;
  551. static const char *major_name="sbpcd";
  552. /*==========================================================================*/
  553. #ifdef FUTURE
  554. static DECLARE_WAIT_QUEUE_HEAD(sbp_waitq);
  555. #endif /* FUTURE */
  556. static int teac=SBP_TEAC_SPEED;
  557. static int buffers=SBP_BUFFER_FRAMES;
  558. static u_char family0[]="MATSHITA"; /* MKE CR-521, CR-522, CR-523 */
  559. static u_char family1[]="CR-56"; /* MKE CR-562, CR-563 */
  560. static u_char family2[]="CD200"; /* MKE CD200, Funai CD200F */
  561. static u_char familyL[]="LCS-7260"; /* Longshine LCS-7260 */
  562. static u_char familyT[]="CD-55"; /* TEAC CD-55A */
  563. static u_char familyV[]="ECS-AT"; /* ECS Vertos 100 */
  564. static u_int recursion; /* internal testing only */
  565. static u_int fatal_err; /* internal testing only */
  566. static u_int response_count;
  567. static u_int flags_cmd_out;
  568. static u_char cmd_type;
  569. static u_char drvcmd[10];
  570. static u_char infobuf[20];
  571. static u_char xa_head_buf[CD_XA_HEAD];
  572. static u_char xa_tail_buf[CD_XA_TAIL];
  573. #if OLD_BUSY
  574. static volatile u_char busy_data;
  575. static volatile u_char busy_audio; /* true semaphores would be safer */
  576. #endif /* OLD_BUSY */
  577. static DECLARE_MUTEX(ioctl_read_sem);
  578. static u_long timeout;
  579. static volatile u_char timed_out_delay;
  580. static volatile u_char timed_out_data;
  581. #if 0
  582. static volatile u_char timed_out_audio;
  583. #endif
  584. static u_int datarate= 1000000;
  585. static u_int maxtim16=16000000;
  586. static u_int maxtim04= 4000000;
  587. static u_int maxtim02= 2000000;
  588. static u_int maxtim_8= 30000;
  589. #if LONG_TIMING
  590. static u_int maxtim_data= 9000;
  591. #else
  592. static u_int maxtim_data= 3000;
  593. #endif /* LONG_TIMING */
  594. #if DISTRIBUTION
  595. static int n_retries=6;
  596. #else
  597. static int n_retries=6;
  598. #endif
  599. /*==========================================================================*/
  600. static int ndrives;
  601. static u_char drv_pattern[NR_SBPCD]={speed_auto,speed_auto,speed_auto,speed_auto};
  602. /*==========================================================================*/
  603. /*
  604. * drive space begins here (needed separate for each unit)
  605. */
  606. static struct sbpcd_drive {
  607. char drv_id; /* "jumpered" drive ID or -1 */
  608. char drv_sel; /* drive select lines bits */
  609. char drive_model[9];
  610. u_char firmware_version[4];
  611. char f_eject; /* auto-eject flag: 0 or 1 */
  612. u_char *sbp_buf; /* Pointer to internal data buffer,
  613. space allocated during sbpcd_init() */
  614. u_int sbp_bufsiz; /* size of sbp_buf (# of frames) */
  615. int sbp_first_frame; /* First frame in buffer */
  616. int sbp_last_frame; /* Last frame in buffer */
  617. int sbp_read_frames; /* Number of frames being read to buffer */
  618. int sbp_current; /* Frame being currently read */
  619. u_char mode; /* read_mode: READ_M1, READ_M2, READ_SC, READ_AU */
  620. u_char *aud_buf; /* Pointer to audio data buffer,
  621. space allocated during sbpcd_init() */
  622. u_int sbp_audsiz; /* size of aud_buf (# of raw frames) */
  623. u_int drv_type;
  624. u_char drv_options;
  625. int status_bits;
  626. u_char diskstate_flags;
  627. u_char sense_byte;
  628. u_char CD_changed;
  629. char open_count;
  630. u_char error_byte;
  631. u_char f_multisession;
  632. u_int lba_multi;
  633. int first_session;
  634. int last_session;
  635. int track_of_last_session;
  636. u_char audio_state;
  637. u_int pos_audio_start;
  638. u_int pos_audio_end;
  639. char vol_chan0;
  640. u_char vol_ctrl0;
  641. char vol_chan1;
  642. u_char vol_ctrl1;
  643. #if 000 /* no supported drive has it */
  644. char vol_chan2;
  645. u_char vol_ctrl2;
  646. char vol_chan3;
  647. u_char vol_ctrl3;
  648. #endif /*000 */
  649. u_char volume_control; /* TEAC on/off bits */
  650. u_char SubQ_ctl_adr;
  651. u_char SubQ_trk;
  652. u_char SubQ_pnt_idx;
  653. u_int SubQ_run_tot;
  654. u_int SubQ_run_trk;
  655. u_char SubQ_whatisthis;
  656. u_char UPC_ctl_adr;
  657. u_char UPC_buf[7];
  658. int frame_size;
  659. int CDsize_frm;
  660. u_char xa_byte; /* 0x20: XA capabilities */
  661. u_char n_first_track; /* binary */
  662. u_char n_last_track; /* binary (not bcd), 0x01...0x63 */
  663. u_int size_msf; /* time of whole CD, position of LeadOut track */
  664. u_int size_blk;
  665. u_char TocEnt_nixbyte; /* em */
  666. u_char TocEnt_ctl_adr;
  667. u_char TocEnt_number;
  668. u_char TocEnt_format; /* em */
  669. u_int TocEnt_address;
  670. #ifdef SAFE_MIXED
  671. char has_data;
  672. #endif /* SAFE_MIXED */
  673. u_char ored_ctl_adr; /* to detect if CDROM contains data tracks */
  674. struct {
  675. u_char nixbyte; /* em */
  676. u_char ctl_adr; /* 0x4x: data, 0x0x: audio */
  677. u_char number;
  678. u_char format; /* em */ /* 0x00: lba, 0x01: msf */
  679. u_int address;
  680. } TocBuffer[MAX_TRACKS+1]; /* last entry faked */
  681. int in_SpinUp; /* CR-52x test flag */
  682. int n_bytes; /* TEAC awaited response count */
  683. u_char error_state, b3, b4; /* TEAC command error state */
  684. u_char f_drv_error; /* TEAC command error flag */
  685. u_char speed_byte;
  686. int frmsiz;
  687. u_char f_XA; /* 1: XA */
  688. u_char type_byte; /* 0, 1, 3 */
  689. u_char mode_xb_6;
  690. u_char mode_yb_7;
  691. u_char mode_xb_8;
  692. u_char delay;
  693. struct cdrom_device_info *sbpcd_infop;
  694. struct gendisk *disk;
  695. } D_S[NR_SBPCD];
  696. static struct sbpcd_drive *current_drive = D_S;
  697. /*
  698. * drive space ends here (needed separate for each unit)
  699. */
  700. /*==========================================================================*/
  701. #if 0
  702. unsigned long cli_sti; /* for saving the processor flags */
  703. #endif
  704. /*==========================================================================*/
  705. static DEFINE_TIMER(delay_timer, mark_timeout_delay, 0, 0);
  706. static DEFINE_TIMER(data_timer, mark_timeout_data, 0, 0);
  707. #if 0
  708. static DEFINE_TIMER(audio_timer, mark_timeout_audio, 0, 0);
  709. #endif
  710. /*==========================================================================*/
  711. /*
  712. * DDI interface
  713. */
  714. static void msg(int level, const char *fmt, ...)
  715. {
  716. #if DISTRIBUTION
  717. #define MSG_LEVEL KERN_NOTICE
  718. #else
  719. #define MSG_LEVEL KERN_INFO
  720. #endif /* DISTRIBUTION */
  721. char buf[256];
  722. va_list args;
  723. if (!(sbpcd_debug&(1<<level))) return;
  724. msgnum++;
  725. if (msgnum>99) msgnum=0;
  726. sprintf(buf, MSG_LEVEL "%s-%d [%02d]: ", major_name, current_drive - D_S, msgnum);
  727. va_start(args, fmt);
  728. vsprintf(&buf[18], fmt, args);
  729. va_end(args);
  730. printk(buf);
  731. #if KLOGD_PAUSE
  732. sbp_sleep(KLOGD_PAUSE); /* else messages get lost */
  733. #endif /* KLOGD_PAUSE */
  734. return;
  735. }
  736. /*==========================================================================*/
  737. /*
  738. * DDI interface: runtime trace bit pattern maintenance
  739. */
  740. static int sbpcd_dbg_ioctl(unsigned long arg, int level)
  741. {
  742. switch(arg)
  743. {
  744. case 0: /* OFF */
  745. sbpcd_debug = DBG_INF;
  746. break;
  747. default:
  748. if (arg>=128) sbpcd_debug &= ~(1<<(arg-128));
  749. else sbpcd_debug |= (1<<arg);
  750. }
  751. return (arg);
  752. }
  753. /*==========================================================================*/
  754. static void mark_timeout_delay(u_long i)
  755. {
  756. timed_out_delay=1;
  757. #if 0
  758. msg(DBG_TIM,"delay timer expired.\n");
  759. #endif
  760. }
  761. /*==========================================================================*/
  762. static void mark_timeout_data(u_long i)
  763. {
  764. timed_out_data=1;
  765. #if 0
  766. msg(DBG_TIM,"data timer expired.\n");
  767. #endif
  768. }
  769. /*==========================================================================*/
  770. #if 0
  771. static void mark_timeout_audio(u_long i)
  772. {
  773. timed_out_audio=1;
  774. #if 0
  775. msg(DBG_TIM,"audio timer expired.\n");
  776. #endif
  777. }
  778. #endif
  779. /*==========================================================================*/
  780. /*
  781. * Wait a little while (used for polling the drive).
  782. */
  783. static void sbp_sleep(u_int time)
  784. {
  785. sti();
  786. schedule_timeout_interruptible(time);
  787. sti();
  788. }
  789. /*==========================================================================*/
  790. #define RETURN_UP(rc) {up(&ioctl_read_sem); return(rc);}
  791. /*==========================================================================*/
  792. /*
  793. * convert logical_block_address to m-s-f_number (3 bytes only)
  794. */
  795. static INLINE void lba2msf(int lba, u_char *msf)
  796. {
  797. lba += CD_MSF_OFFSET;
  798. msf[0] = lba / (CD_SECS*CD_FRAMES);
  799. lba %= CD_SECS*CD_FRAMES;
  800. msf[1] = lba / CD_FRAMES;
  801. msf[2] = lba % CD_FRAMES;
  802. }
  803. /*==========================================================================*/
  804. /*==========================================================================*/
  805. /*
  806. * convert msf-bin to msf-bcd
  807. */
  808. static INLINE void bin2bcdx(u_char *p) /* must work only up to 75 or 99 */
  809. {
  810. *p=((*p/10)<<4)|(*p%10);
  811. }
  812. /*==========================================================================*/
  813. static INLINE u_int blk2msf(u_int blk)
  814. {
  815. MSF msf;
  816. u_int mm;
  817. msf.c[3] = 0;
  818. msf.c[2] = (blk + CD_MSF_OFFSET) / (CD_SECS * CD_FRAMES);
  819. mm = (blk + CD_MSF_OFFSET) % (CD_SECS * CD_FRAMES);
  820. msf.c[1] = mm / CD_FRAMES;
  821. msf.c[0] = mm % CD_FRAMES;
  822. return (msf.n);
  823. }
  824. /*==========================================================================*/
  825. static INLINE u_int make16(u_char rh, u_char rl)
  826. {
  827. return ((rh<<8)|rl);
  828. }
  829. /*==========================================================================*/
  830. static INLINE u_int make32(u_int rh, u_int rl)
  831. {
  832. return ((rh<<16)|rl);
  833. }
  834. /*==========================================================================*/
  835. static INLINE u_char swap_nibbles(u_char i)
  836. {
  837. return ((i<<4)|(i>>4));
  838. }
  839. /*==========================================================================*/
  840. static INLINE u_char byt2bcd(u_char i)
  841. {
  842. return (((i/10)<<4)+i%10);
  843. }
  844. /*==========================================================================*/
  845. static INLINE u_char bcd2bin(u_char bcd)
  846. {
  847. return ((bcd>>4)*10+(bcd&0x0F));
  848. }
  849. /*==========================================================================*/
  850. static INLINE int msf2blk(int msfx)
  851. {
  852. MSF msf;
  853. int i;
  854. msf.n=msfx;
  855. i=(msf.c[2] * CD_SECS + msf.c[1]) * CD_FRAMES + msf.c[0] - CD_MSF_OFFSET;
  856. if (i<0) return (0);
  857. return (i);
  858. }
  859. /*==========================================================================*/
  860. /*
  861. * convert m-s-f_number (3 bytes only) to logical_block_address
  862. */
  863. static INLINE int msf2lba(u_char *msf)
  864. {
  865. int i;
  866. i=(msf[0] * CD_SECS + msf[1]) * CD_FRAMES + msf[2] - CD_MSF_OFFSET;
  867. if (i<0) return (0);
  868. return (i);
  869. }
  870. /*==========================================================================*/
  871. /* evaluate cc_ReadError code */
  872. static int sta2err(int sta)
  873. {
  874. if (famT_drive)
  875. {
  876. if (sta==0x00) return (0);
  877. if (sta==0x01) return (-604); /* CRC error */
  878. if (sta==0x02) return (-602); /* drive not ready */
  879. if (sta==0x03) return (-607); /* unknown media */
  880. if (sta==0x04) return (-612); /* general failure */
  881. if (sta==0x05) return (0);
  882. if (sta==0x06) return (-ERR_DISKCHANGE); /* disk change */
  883. if (sta==0x0b) return (-612); /* general failure */
  884. if (sta==0xff) return (-612); /* general failure */
  885. return (0);
  886. }
  887. else
  888. {
  889. if (sta<=2) return (sta);
  890. if (sta==0x05) return (-604); /* CRC error */
  891. if (sta==0x06) return (-606); /* seek error */
  892. if (sta==0x0d) return (-606); /* seek error */
  893. if (sta==0x0e) return (-603); /* unknown command */
  894. if (sta==0x14) return (-603); /* unknown command */
  895. if (sta==0x0c) return (-611); /* read fault */
  896. if (sta==0x0f) return (-611); /* read fault */
  897. if (sta==0x10) return (-611); /* read fault */
  898. if (sta>=0x16) return (-612); /* general failure */
  899. if (sta==0x11) return (-ERR_DISKCHANGE); /* disk change (LCS: removed) */
  900. if (famL_drive)
  901. if (sta==0x12) return (-ERR_DISKCHANGE); /* disk change (inserted) */
  902. return (-602); /* drive not ready */
  903. }
  904. }
  905. /*==========================================================================*/
  906. static INLINE void clr_cmdbuf(void)
  907. {
  908. int i;
  909. for (i=0;i<10;i++) drvcmd[i]=0;
  910. cmd_type=0;
  911. }
  912. /*==========================================================================*/
  913. static void flush_status(void)
  914. {
  915. int i;
  916. sbp_sleep(15*HZ/10);
  917. for (i=maxtim_data;i!=0;i--) inb(CDi_status);
  918. }
  919. /*====================================================================*/
  920. /*
  921. * CDi status loop for Teac CD-55A (Rob Riggs)
  922. *
  923. * This is needed because for some strange reason
  924. * the CD-55A can take a real long time to give a
  925. * status response. This seems to happen after we
  926. * issue a READ command where a long seek is involved.
  927. *
  928. * I tried to ensure that we get max throughput with
  929. * minimal busy waiting. We busy wait at first, then
  930. * "switch gears" and start sleeping. We sleep for
  931. * longer periods of time the longer we wait.
  932. *
  933. */
  934. static int CDi_stat_loop_T(void)
  935. {
  936. int i, gear=1;
  937. u_long timeout_1, timeout_2, timeout_3, timeout_4;
  938. timeout_1 = jiffies + HZ / 50; /* sbp_sleep(0) for a short period */
  939. timeout_2 = jiffies + HZ / 5; /* nap for no more than 200ms */
  940. timeout_3 = jiffies + 5 * HZ; /* sleep for up to 5s */
  941. timeout_4 = jiffies + 45 * HZ; /* long sleep for up to 45s. */
  942. do
  943. {
  944. i = inb(CDi_status);
  945. if (!(i&s_not_data_ready)) return (i);
  946. if (!(i&s_not_result_ready)) return (i);
  947. switch(gear)
  948. {
  949. case 4:
  950. sbp_sleep(HZ);
  951. if (time_after(jiffies, timeout_4)) gear++;
  952. msg(DBG_TEA, "CDi_stat_loop_T: long sleep active.\n");
  953. break;
  954. case 3:
  955. sbp_sleep(HZ/10);
  956. if (time_after(jiffies, timeout_3)) gear++;
  957. break;
  958. case 2:
  959. sbp_sleep(HZ/100);
  960. if (time_after(jiffies, timeout_2)) gear++;
  961. break;
  962. case 1:
  963. sbp_sleep(0);
  964. if (time_after(jiffies, timeout_1)) gear++;
  965. }
  966. } while (gear < 5);
  967. return -1;
  968. }
  969. /*==========================================================================*/
  970. static int CDi_stat_loop(void)
  971. {
  972. int i,j;
  973. for(timeout = jiffies + 10*HZ, i=maxtim_data; time_before(jiffies, timeout); )
  974. {
  975. for ( ;i!=0;i--)
  976. {
  977. j=inb(CDi_status);
  978. if (!(j&s_not_data_ready)) return (j);
  979. if (!(j&s_not_result_ready)) return (j);
  980. if (fam0L_drive) if (j&s_attention) return (j);
  981. }
  982. sbp_sleep(1);
  983. i = 1;
  984. }
  985. msg(DBG_LCS,"CDi_stat_loop failed in line %d\n", __LINE__);
  986. return (-1);
  987. }
  988. /*==========================================================================*/
  989. #if 00000
  990. /*==========================================================================*/
  991. static int tst_DataReady(void)
  992. {
  993. int i;
  994. i=inb(CDi_status);
  995. if (i&s_not_data_ready) return (0);
  996. return (1);
  997. }
  998. /*==========================================================================*/
  999. static int tst_ResultReady(void)
  1000. {
  1001. int i;
  1002. i=inb(CDi_status);
  1003. if (i&s_not_result_ready) return (0);
  1004. return (1);
  1005. }
  1006. /*==========================================================================*/
  1007. static int tst_Attention(void)
  1008. {
  1009. int i;
  1010. i=inb(CDi_status);
  1011. if (i&s_attention) return (1);
  1012. return (0);
  1013. }
  1014. /*==========================================================================*/
  1015. #endif
  1016. /*==========================================================================*/
  1017. static int ResponseInfo(void)
  1018. {
  1019. int i,j,st=0;
  1020. u_long timeout;
  1021. for (i=0,timeout=jiffies+HZ;i<response_count;i++)
  1022. {
  1023. for (j=maxtim_data; ; )
  1024. {
  1025. for ( ;j!=0;j-- )
  1026. {
  1027. st=inb(CDi_status);
  1028. if (!(st&s_not_result_ready)) break;
  1029. }
  1030. if ((j!=0)||time_after_eq(jiffies, timeout)) break;
  1031. sbp_sleep(1);
  1032. j = 1;
  1033. }
  1034. if (time_after_eq(jiffies, timeout)) break;
  1035. infobuf[i]=inb(CDi_info);
  1036. }
  1037. #if 000
  1038. while (!(inb(CDi_status)&s_not_result_ready))
  1039. {
  1040. infobuf[i++]=inb(CDi_info);
  1041. }
  1042. j=i-response_count;
  1043. if (j>0) msg(DBG_INF,"ResponseInfo: got %d trailing bytes.\n",j);
  1044. #endif /* 000 */
  1045. for (j=0;j<i;j++)
  1046. sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
  1047. msgbuf[j*3]=0;
  1048. msg(DBG_CMD,"ResponseInfo:%s (%d,%d)\n",msgbuf,response_count,i);
  1049. j=response_count-i;
  1050. if (j>0) return (-j);
  1051. else return (i);
  1052. }
  1053. /*==========================================================================*/
  1054. static void EvaluateStatus(int st)
  1055. {
  1056. current_drive->status_bits=0;
  1057. if (fam1_drive) current_drive->status_bits=st|p_success;
  1058. else if (fam0_drive)
  1059. {
  1060. if (st&p_caddin_old) current_drive->status_bits |= p_door_closed|p_caddy_in;
  1061. if (st&p_spinning) current_drive->status_bits |= p_spinning;
  1062. if (st&p_check) current_drive->status_bits |= p_check;
  1063. if (st&p_success_old) current_drive->status_bits |= p_success;
  1064. if (st&p_busy_old) current_drive->status_bits |= p_busy_new;
  1065. if (st&p_disk_ok) current_drive->status_bits |= p_disk_ok;
  1066. }
  1067. else if (famLV_drive)
  1068. {
  1069. current_drive->status_bits |= p_success;
  1070. if (st&p_caddin_old) current_drive->status_bits |= p_disk_ok|p_caddy_in;
  1071. if (st&p_spinning) current_drive->status_bits |= p_spinning;
  1072. if (st&p_check) current_drive->status_bits |= p_check;
  1073. if (st&p_busy_old) current_drive->status_bits |= p_busy_new;
  1074. if (st&p_lcs_door_closed) current_drive->status_bits |= p_door_closed;
  1075. if (st&p_lcs_door_locked) current_drive->status_bits |= p_door_locked;
  1076. }
  1077. else if (fam2_drive)
  1078. {
  1079. current_drive->status_bits |= p_success;
  1080. if (st&p2_check) current_drive->status_bits |= p1_check;
  1081. if (st&p2_door_closed) current_drive->status_bits |= p1_door_closed;
  1082. if (st&p2_disk_in) current_drive->status_bits |= p1_disk_in;
  1083. if (st&p2_busy1) current_drive->status_bits |= p1_busy;
  1084. if (st&p2_busy2) current_drive->status_bits |= p1_busy;
  1085. if (st&p2_spinning) current_drive->status_bits |= p1_spinning;
  1086. if (st&p2_door_locked) current_drive->status_bits |= p1_door_locked;
  1087. if (st&p2_disk_ok) current_drive->status_bits |= p1_disk_ok;
  1088. }
  1089. else if (famT_drive)
  1090. {
  1091. return; /* still needs to get coded */
  1092. current_drive->status_bits |= p_success;
  1093. if (st&p2_check) current_drive->status_bits |= p1_check;
  1094. if (st&p2_door_closed) current_drive->status_bits |= p1_door_closed;
  1095. if (st&p2_disk_in) current_drive->status_bits |= p1_disk_in;
  1096. if (st&p2_busy1) current_drive->status_bits |= p1_busy;
  1097. if (st&p2_busy2) current_drive->status_bits |= p1_busy;
  1098. if (st&p2_spinning) current_drive->status_bits |= p1_spinning;
  1099. if (st&p2_door_locked) current_drive->status_bits |= p1_door_locked;
  1100. if (st&p2_disk_ok) current_drive->status_bits |= p1_disk_ok;
  1101. }
  1102. return;
  1103. }
  1104. /*==========================================================================*/
  1105. static int cmd_out_T(void);
  1106. static int get_state_T(void)
  1107. {
  1108. int i;
  1109. clr_cmdbuf();
  1110. current_drive->n_bytes=1;
  1111. drvcmd[0]=CMDT_STATUS;
  1112. i=cmd_out_T();
  1113. if (i>=0) i=infobuf[0];
  1114. else
  1115. {
  1116. msg(DBG_TEA,"get_state_T error %d\n", i);
  1117. return (i);
  1118. }
  1119. if (i>=0)
  1120. /* 2: closed, disk in */
  1121. current_drive->status_bits=p1_door_closed|p1_disk_in|p1_spinning|p1_disk_ok;
  1122. else if (current_drive->error_state==6)
  1123. {
  1124. /* 3: closed, disk in, changed ("06 xx xx") */
  1125. current_drive->status_bits=p1_door_closed|p1_disk_in;
  1126. current_drive->CD_changed=0xFF;
  1127. current_drive->diskstate_flags &= ~toc_bit;
  1128. }
  1129. else if ((current_drive->error_state!=2)||(current_drive->b3!=0x3A)||(current_drive->b4==0x00))
  1130. {
  1131. /* 1: closed, no disk ("xx yy zz"or "02 3A 00") */
  1132. current_drive->status_bits=p1_door_closed;
  1133. current_drive->open_count=0;
  1134. }
  1135. else if (current_drive->b4==0x01)
  1136. {
  1137. /* 0: open ("02 3A 01") */
  1138. current_drive->status_bits=0;
  1139. current_drive->open_count=0;
  1140. }
  1141. else
  1142. {
  1143. /* 1: closed, no disk ("02 3A xx") */
  1144. current_drive->status_bits=p1_door_closed;
  1145. current_drive->open_count=0;
  1146. }
  1147. return (current_drive->status_bits);
  1148. }
  1149. /*==========================================================================*/
  1150. static int ResponseStatus(void)
  1151. {
  1152. int i,j;
  1153. u_long timeout;
  1154. msg(DBG_STA,"doing ResponseStatus...\n");
  1155. if (famT_drive) return (get_state_T());
  1156. if (flags_cmd_out & f_respo3) timeout = jiffies;
  1157. else if (flags_cmd_out & f_respo2) timeout = jiffies + 16*HZ;
  1158. else timeout = jiffies + 4*HZ;
  1159. j=maxtim_8;
  1160. do
  1161. {
  1162. for ( ;j!=0;j--)
  1163. {
  1164. i=inb(CDi_status);
  1165. if (!(i&s_not_result_ready)) break;
  1166. }
  1167. if ((j!=0)||time_after(jiffies, timeout)) break;
  1168. sbp_sleep(1);
  1169. j = 1;
  1170. }
  1171. while (1);
  1172. if (j==0)
  1173. {
  1174. if ((flags_cmd_out & f_respo3) == 0)
  1175. msg(DBG_STA,"ResponseStatus: timeout.\n");
  1176. current_drive->status_bits=0;
  1177. return (-401);
  1178. }
  1179. i=inb(CDi_info);
  1180. msg(DBG_STA,"ResponseStatus: response %02X.\n", i);
  1181. EvaluateStatus(i);
  1182. msg(DBG_STA,"status_bits=%02X, i=%02X\n",current_drive->status_bits,i);
  1183. return (current_drive->status_bits);
  1184. }
  1185. /*==========================================================================*/
  1186. static void cc_ReadStatus(void)
  1187. {
  1188. int i;
  1189. msg(DBG_STA,"giving cc_ReadStatus command\n");
  1190. if (famT_drive) return;
  1191. SBPCD_CLI;
  1192. if (fam0LV_drive) OUT(CDo_command,CMD0_STATUS);
  1193. else if (fam1_drive) OUT(CDo_command,CMD1_STATUS);
  1194. else if (fam2_drive) OUT(CDo_command,CMD2_STATUS);
  1195. if (!fam0LV_drive) for (i=0;i<6;i++) OUT(CDo_command,0);
  1196. SBPCD_STI;
  1197. }
  1198. /*==========================================================================*/
  1199. static int cc_ReadError(void)
  1200. {
  1201. int i;
  1202. clr_cmdbuf();
  1203. msg(DBG_ERR,"giving cc_ReadError command.\n");
  1204. if (fam1_drive)
  1205. {
  1206. drvcmd[0]=CMD1_READ_ERR;
  1207. response_count=8;
  1208. flags_cmd_out=f_putcmd|f_ResponseStatus;
  1209. }
  1210. else if (fam0LV_drive)
  1211. {
  1212. drvcmd[0]=CMD0_READ_ERR;
  1213. response_count=6;
  1214. if (famLV_drive)
  1215. flags_cmd_out=f_putcmd;
  1216. else
  1217. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus;
  1218. }
  1219. else if (fam2_drive)
  1220. {
  1221. drvcmd[0]=CMD2_READ_ERR;
  1222. response_count=6;
  1223. flags_cmd_out=f_putcmd;
  1224. }
  1225. else if (famT_drive)
  1226. {
  1227. response_count=5;
  1228. drvcmd[0]=CMDT_READ_ERR;
  1229. }
  1230. i=cmd_out();
  1231. current_drive->error_byte=0;
  1232. msg(DBG_ERR,"cc_ReadError: cmd_out(CMDx_READ_ERR) returns %d (%02X)\n",i,i);
  1233. if (i<0) return (i);
  1234. if (fam0V_drive) i=1;
  1235. else i=2;
  1236. current_drive->error_byte=infobuf[i];
  1237. msg(DBG_ERR,"cc_ReadError: infobuf[%d] is %d (%02X)\n",i,current_drive->error_byte,current_drive->error_byte);
  1238. i=sta2err(infobuf[i]);
  1239. if (i==-ERR_DISKCHANGE)
  1240. {
  1241. current_drive->CD_changed=0xFF;
  1242. current_drive->diskstate_flags &= ~toc_bit;
  1243. }
  1244. return (i);
  1245. }
  1246. /*==========================================================================*/
  1247. static int cc_DriveReset(void);
  1248. static int cmd_out_T(void)
  1249. {
  1250. #undef CMDT_TRIES
  1251. #define CMDT_TRIES 1000
  1252. #define TEST_FALSE_FF 1
  1253. int i, j, l=0, m, ntries;
  1254. unsigned long flags;
  1255. current_drive->error_state=0;
  1256. current_drive->b3=0;
  1257. current_drive->b4=0;
  1258. current_drive->f_drv_error=0;
  1259. for (i=0;i<10;i++) sprintf(&msgbuf[i*3]," %02X",drvcmd[i]);
  1260. msgbuf[i*3]=0;
  1261. msg(DBG_CMD,"cmd_out_T:%s\n",msgbuf);
  1262. OUT(CDo_sel_i_d,0);
  1263. OUT(CDo_enable,current_drive->drv_sel);
  1264. i=inb(CDi_status);
  1265. do_16bit=0;
  1266. if ((f_16bit)&&(!(i&0x80)))
  1267. {
  1268. do_16bit=1;
  1269. msg(DBG_TEA,"cmd_out_T: do_16bit set.\n");
  1270. }
  1271. if (!(i&s_not_result_ready))
  1272. do
  1273. {
  1274. j=inb(CDi_info);
  1275. i=inb(CDi_status);
  1276. sbp_sleep(0);
  1277. msg(DBG_TEA,"cmd_out_T: spurious !s_not_result_ready. (%02X)\n", j);
  1278. }
  1279. while (!(i&s_not_result_ready));
  1280. save_flags(flags); cli();
  1281. for (i=0;i<10;i++) OUT(CDo_command,drvcmd[i]);
  1282. restore_flags(flags);
  1283. for (ntries=CMDT_TRIES;ntries>0;ntries--)
  1284. {
  1285. if (drvcmd[0]==CMDT_READ_VER) sbp_sleep(HZ); /* fixme */
  1286. #if 01
  1287. OUT(CDo_sel_i_d,1);
  1288. #endif /* 01 */
  1289. if (teac==2)
  1290. {
  1291. if ((i=CDi_stat_loop_T()) == -1) break;
  1292. }
  1293. else
  1294. {
  1295. #if 0
  1296. OUT(CDo_sel_i_d,1);
  1297. #endif /* 0 */
  1298. i=inb(CDi_status);
  1299. }
  1300. if (!(i&s_not_data_ready)) /* f.e. CMDT_DISKINFO */
  1301. {
  1302. OUT(CDo_sel_i_d,1);
  1303. if (drvcmd[0]==CMDT_READ) return (0); /* handled elsewhere */
  1304. if (drvcmd[0]==CMDT_DISKINFO)
  1305. {
  1306. l=0;
  1307. do
  1308. {
  1309. if (do_16bit)
  1310. {
  1311. i=inw(CDi_data);
  1312. infobuf[l++]=i&0x0ff;
  1313. infobuf[l++]=i>>8;
  1314. #if TEST_FALSE_FF
  1315. if ((l==2)&&(infobuf[0]==0x0ff))
  1316. {
  1317. infobuf[0]=infobuf[1];
  1318. l=1;
  1319. msg(DBG_TEA,"cmd_out_T: do_16bit: false first byte!\n");
  1320. }
  1321. #endif /* TEST_FALSE_FF */
  1322. }
  1323. else infobuf[l++]=inb(CDi_data);
  1324. i=inb(CDi_status);
  1325. }
  1326. while (!(i&s_not_data_ready));
  1327. for (j=0;j<l;j++) sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
  1328. msgbuf[j*3]=0;
  1329. msg(DBG_CMD,"cmd_out_T data response:%s\n", msgbuf);
  1330. }
  1331. else
  1332. {
  1333. msg(DBG_TEA,"cmd_out_T: data response with cmd_%02X!\n",
  1334. drvcmd[0]);
  1335. j=0;
  1336. do
  1337. {
  1338. if (do_16bit) i=inw(CDi_data);
  1339. else i=inb(CDi_data);
  1340. j++;
  1341. i=inb(CDi_status);
  1342. }
  1343. while (!(i&s_not_data_ready));
  1344. msg(DBG_TEA,"cmd_out_T: data response: discarded %d bytes/words.\n", j);
  1345. fatal_err++;
  1346. }
  1347. }
  1348. i=inb(CDi_status);
  1349. if (!(i&s_not_result_ready))
  1350. {
  1351. OUT(CDo_sel_i_d,0);
  1352. if (drvcmd[0]==CMDT_DISKINFO) m=l;
  1353. else m=0;
  1354. do
  1355. {
  1356. infobuf[m++]=inb(CDi_info);
  1357. i=inb(CDi_status);
  1358. }
  1359. while (!(i&s_not_result_ready));
  1360. for (j=0;j<m;j++) sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
  1361. msgbuf[j*3]=0;
  1362. msg(DBG_CMD,"cmd_out_T info response:%s\n", msgbuf);
  1363. if (drvcmd[0]==CMDT_DISKINFO)
  1364. {
  1365. infobuf[0]=infobuf[l];
  1366. if (infobuf[0]!=0x02) return (l); /* data length */
  1367. }
  1368. else if (infobuf[0]!=0x02) return (m); /* info length */
  1369. do
  1370. {
  1371. ++recursion;
  1372. if (recursion>1) msg(DBG_TEA,"cmd_out_T READ_ERR recursion (%02X): %d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", drvcmd[0], recursion);
  1373. clr_cmdbuf();
  1374. drvcmd[0]=CMDT_READ_ERR;
  1375. j=cmd_out_T(); /* !!! recursive here !!! */
  1376. --recursion;
  1377. sbp_sleep(1);
  1378. }
  1379. while (j<0);
  1380. current_drive->error_state=infobuf[2];
  1381. current_drive->b3=infobuf[3];
  1382. current_drive->b4=infobuf[4];
  1383. if (current_drive->f_drv_error)
  1384. {
  1385. current_drive->f_drv_error=0;
  1386. cc_DriveReset();
  1387. current_drive->error_state=2;
  1388. }
  1389. return (-current_drive->error_state-400);
  1390. }
  1391. if (drvcmd[0]==CMDT_READ) return (0); /* handled elsewhere */
  1392. if ((teac==0)||(ntries<(CMDT_TRIES-5))) sbp_sleep(HZ/10);
  1393. else sbp_sleep(HZ/100);
  1394. if (ntries>(CMDT_TRIES-50)) continue;
  1395. msg(DBG_TEA,"cmd_out_T: next CMDT_TRIES (%02X): %d.\n", drvcmd[0], ntries-1);
  1396. }
  1397. current_drive->f_drv_error=1;
  1398. cc_DriveReset();
  1399. current_drive->error_state=2;
  1400. return (-99);
  1401. }
  1402. /*==========================================================================*/
  1403. static int cmd_out(void)
  1404. {
  1405. int i=0;
  1406. if (famT_drive) return(cmd_out_T());
  1407. if (flags_cmd_out&f_putcmd)
  1408. {
  1409. unsigned long flags;
  1410. for (i=0;i<7;i++)
  1411. sprintf(&msgbuf[i*3], " %02X", drvcmd[i]);
  1412. msgbuf[i*3]=0;
  1413. msg(DBG_CMD,"cmd_out:%s\n", msgbuf);
  1414. save_flags(flags); cli();
  1415. for (i=0;i<7;i++) OUT(CDo_command,drvcmd[i]);
  1416. restore_flags(flags);
  1417. }
  1418. if (response_count!=0)
  1419. {
  1420. if (cmd_type!=0)
  1421. {
  1422. if (sbpro_type==1) OUT(CDo_sel_i_d,1);
  1423. msg(DBG_INF,"misleaded to try ResponseData.\n");
  1424. if (sbpro_type==1) OUT(CDo_sel_i_d,0);
  1425. return (-22);
  1426. }
  1427. else i=ResponseInfo();
  1428. if (i<0) return (i);
  1429. }
  1430. if (current_drive->in_SpinUp) msg(DBG_SPI,"in_SpinUp: to CDi_stat_loop.\n");
  1431. if (flags_cmd_out&f_lopsta)
  1432. {
  1433. i=CDi_stat_loop();
  1434. if ((i<0)||!(i&s_attention)) return (-8);
  1435. }
  1436. if (!(flags_cmd_out&f_getsta)) goto LOC_229;
  1437. LOC_228:
  1438. if (current_drive->in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cc_ReadStatus.\n");
  1439. cc_ReadStatus();
  1440. LOC_229:
  1441. if (flags_cmd_out&f_ResponseStatus)
  1442. {
  1443. if (current_drive->in_SpinUp) msg(DBG_SPI,"in_SpinUp: to ResponseStatus.\n");
  1444. i=ResponseStatus();
  1445. /* builds status_bits, returns orig. status or p_busy_new */
  1446. if (i<0) return (i);
  1447. if (flags_cmd_out&(f_bit1|f_wait_if_busy))
  1448. {
  1449. if (!st_check)
  1450. {
  1451. if ((flags_cmd_out&f_bit1)&&(i&p_success)) goto LOC_232;
  1452. if ((!(flags_cmd_out&f_wait_if_busy))||(!st_busy)) goto LOC_228;
  1453. }
  1454. }
  1455. }
  1456. LOC_232:
  1457. if (!(flags_cmd_out&f_obey_p_check)) return (0);
  1458. if (!st_check) return (0);
  1459. if (current_drive->in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cc_ReadError.\n");
  1460. i=cc_ReadError();
  1461. if (current_drive->in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cmd_out OK.\n");
  1462. msg(DBG_000,"cmd_out: cc_ReadError=%d\n", i);
  1463. return (i);
  1464. }
  1465. /*==========================================================================*/
  1466. static int cc_Seek(u_int pos, char f_blk_msf)
  1467. {
  1468. int i;
  1469. clr_cmdbuf();
  1470. if (f_blk_msf>1) return (-3);
  1471. if (fam0V_drive)
  1472. {
  1473. drvcmd[0]=CMD0_SEEK;
  1474. if (f_blk_msf==1) pos=msf2blk(pos);
  1475. drvcmd[2]=(pos>>16)&0x00FF;
  1476. drvcmd[3]=(pos>>8)&0x00FF;
  1477. drvcmd[4]=pos&0x00FF;
  1478. if (fam0_drive)
  1479. flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
  1480. f_ResponseStatus | f_obey_p_check | f_bit1;
  1481. else
  1482. flags_cmd_out = f_putcmd;
  1483. }
  1484. else if (fam1L_drive)
  1485. {
  1486. drvcmd[0]=CMD1_SEEK; /* same as CMD1_ and CMDL_ */
  1487. if (f_blk_msf==0) pos=blk2msf(pos);
  1488. drvcmd[1]=(pos>>16)&0x00FF;
  1489. drvcmd[2]=(pos>>8)&0x00FF;
  1490. drvcmd[3]=pos&0x00FF;
  1491. if (famL_drive)
  1492. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  1493. else
  1494. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  1495. }
  1496. else if (fam2_drive)
  1497. {
  1498. drvcmd[0]=CMD2_SEEK;
  1499. if (f_blk_msf==0) pos=blk2msf(pos);
  1500. drvcmd[2]=(pos>>24)&0x00FF;
  1501. drvcmd[3]=(pos>>16)&0x00FF;
  1502. drvcmd[4]=(pos>>8)&0x00FF;
  1503. drvcmd[5]=pos&0x00FF;
  1504. flags_cmd_out=f_putcmd|f_ResponseStatus;
  1505. }
  1506. else if (famT_drive)
  1507. {
  1508. drvcmd[0]=CMDT_SEEK;
  1509. if (f_blk_msf==1) pos=msf2blk(pos);
  1510. drvcmd[2]=(pos>>24)&0x00FF;
  1511. drvcmd[3]=(pos>>16)&0x00FF;
  1512. drvcmd[4]=(pos>>8)&0x00FF;
  1513. drvcmd[5]=pos&0x00FF;
  1514. current_drive->n_bytes=1;
  1515. }
  1516. response_count=0;
  1517. i=cmd_out();
  1518. return (i);
  1519. }
  1520. /*==========================================================================*/
  1521. static int cc_SpinUp(void)
  1522. {
  1523. int i;
  1524. msg(DBG_SPI,"SpinUp.\n");
  1525. current_drive->in_SpinUp = 1;
  1526. clr_cmdbuf();
  1527. if (fam0LV_drive)
  1528. {
  1529. drvcmd[0]=CMD0_SPINUP;
  1530. if (fam0L_drive)
  1531. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|
  1532. f_ResponseStatus|f_obey_p_check|f_bit1;
  1533. else
  1534. flags_cmd_out=f_putcmd;
  1535. }
  1536. else if (fam1_drive)
  1537. {
  1538. drvcmd[0]=CMD1_SPINUP;
  1539. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  1540. }
  1541. else if (fam2_drive)
  1542. {
  1543. drvcmd[0]=CMD2_TRAY_CTL;
  1544. drvcmd[4]=0x01; /* "spinup" */
  1545. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  1546. }
  1547. else if (famT_drive)
  1548. {
  1549. drvcmd[0]=CMDT_TRAY_CTL;
  1550. drvcmd[4]=0x03; /* "insert", it hopefully spins the drive up */
  1551. }
  1552. response_count=0;
  1553. i=cmd_out();
  1554. current_drive->in_SpinUp = 0;
  1555. return (i);
  1556. }
  1557. /*==========================================================================*/
  1558. static int cc_SpinDown(void)
  1559. {
  1560. int i;
  1561. if (fam0_drive) return (0);
  1562. clr_cmdbuf();
  1563. response_count=0;
  1564. if (fam1_drive)
  1565. {
  1566. drvcmd[0]=CMD1_SPINDOWN;
  1567. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  1568. }
  1569. else if (fam2_drive)
  1570. {
  1571. drvcmd[0]=CMD2_TRAY_CTL;
  1572. drvcmd[4]=0x02; /* "eject" */
  1573. flags_cmd_out=f_putcmd|f_ResponseStatus;
  1574. }
  1575. else if (famL_drive)
  1576. {
  1577. drvcmd[0]=CMDL_SPINDOWN;
  1578. drvcmd[1]=1;
  1579. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  1580. }
  1581. else if (famV_drive)
  1582. {
  1583. drvcmd[0]=CMDV_SPINDOWN;
  1584. flags_cmd_out=f_putcmd;
  1585. }
  1586. else if (famT_drive)
  1587. {
  1588. drvcmd[0]=CMDT_TRAY_CTL;
  1589. drvcmd[4]=0x02; /* "eject" */
  1590. }
  1591. i=cmd_out();
  1592. return (i);
  1593. }
  1594. /*==========================================================================*/
  1595. static int cc_get_mode_T(void)
  1596. {
  1597. int i;
  1598. clr_cmdbuf();
  1599. response_count=10;
  1600. drvcmd[0]=CMDT_GETMODE;
  1601. drvcmd[4]=response_count;
  1602. i=cmd_out_T();
  1603. return (i);
  1604. }
  1605. /*==========================================================================*/
  1606. static int cc_set_mode_T(void)
  1607. {
  1608. int i;
  1609. clr_cmdbuf();
  1610. response_count=1;
  1611. drvcmd[0]=CMDT_SETMODE;
  1612. drvcmd[1]=current_drive->speed_byte;
  1613. drvcmd[2]=current_drive->frmsiz>>8;
  1614. drvcmd[3]=current_drive->frmsiz&0x0FF;
  1615. drvcmd[4]=current_drive->f_XA; /* 1: XA */
  1616. drvcmd[5]=current_drive->type_byte; /* 0, 1, 3 */
  1617. drvcmd[6]=current_drive->mode_xb_6;
  1618. drvcmd[7]=current_drive->mode_yb_7|current_drive->volume_control;
  1619. drvcmd[8]=current_drive->mode_xb_8;
  1620. drvcmd[9]=current_drive->delay;
  1621. i=cmd_out_T();
  1622. return (i);
  1623. }
  1624. /*==========================================================================*/
  1625. static int cc_prep_mode_T(void)
  1626. {
  1627. int i, j;
  1628. i=cc_get_mode_T();
  1629. if (i<0) return (i);
  1630. for (i=0;i<10;i++)
  1631. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  1632. msgbuf[i*3]=0;
  1633. msg(DBG_TEA,"CMDT_GETMODE:%s\n", msgbuf);
  1634. current_drive->speed_byte=0x02; /* 0x02: auto quad, 0x82: quad, 0x81: double, 0x80: single */
  1635. current_drive->frmsiz=make16(infobuf[2],infobuf[3]);
  1636. current_drive->f_XA=infobuf[4];
  1637. if (current_drive->f_XA==0) current_drive->type_byte=0;
  1638. else current_drive->type_byte=1;
  1639. current_drive->mode_xb_6=infobuf[6];
  1640. current_drive->mode_yb_7=1;
  1641. current_drive->mode_xb_8=infobuf[8];
  1642. current_drive->delay=0; /* 0, 1, 2, 3 */
  1643. j=cc_set_mode_T();
  1644. i=cc_get_mode_T();
  1645. for (i=0;i<10;i++)
  1646. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  1647. msgbuf[i*3]=0;
  1648. msg(DBG_TEA,"CMDT_GETMODE:%s\n", msgbuf);
  1649. return (j);
  1650. }
  1651. /*==========================================================================*/
  1652. static int cc_SetSpeed(u_char speed, u_char x1, u_char x2)
  1653. {
  1654. int i;
  1655. if (fam0LV_drive) return (0);
  1656. clr_cmdbuf();
  1657. response_count=0;
  1658. if (fam1_drive)
  1659. {
  1660. drvcmd[0]=CMD1_SETMODE;
  1661. drvcmd[1]=0x03;
  1662. drvcmd[2]=speed;
  1663. drvcmd[3]=x1;
  1664. drvcmd[4]=x2;
  1665. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  1666. }
  1667. else if (fam2_drive)
  1668. {
  1669. drvcmd[0]=CMD2_SETSPEED;
  1670. if (speed&speed_auto)
  1671. {
  1672. drvcmd[2]=0xFF;
  1673. drvcmd[3]=0xFF;
  1674. }
  1675. else
  1676. {
  1677. drvcmd[2]=0;
  1678. drvcmd[3]=150;
  1679. }
  1680. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  1681. }
  1682. else if (famT_drive)
  1683. {
  1684. return (0);
  1685. }
  1686. i=cmd_out();
  1687. return (i);
  1688. }
  1689. /*==========================================================================*/
  1690. static int cc_SetVolume(void)
  1691. {
  1692. int i;
  1693. u_char channel0,channel1,volume0,volume1;
  1694. u_char control0,value0,control1,value1;
  1695. current_drive->diskstate_flags &= ~volume_bit;
  1696. clr_cmdbuf();
  1697. channel0=current_drive->vol_chan0;
  1698. volume0=current_drive->vol_ctrl0;
  1699. channel1=control1=current_drive->vol_chan1;
  1700. volume1=value1=current_drive->vol_ctrl1;
  1701. control0=value0=0;
  1702. if (famV_drive) return (0);
  1703. if (((current_drive->drv_options&audio_mono)!=0)&&(current_drive->drv_type>=drv_211))
  1704. {
  1705. if ((volume0!=0)&&(volume1==0))
  1706. {
  1707. volume1=volume0;
  1708. channel1=channel0;
  1709. }
  1710. else if ((volume0==0)&&(volume1!=0))
  1711. {
  1712. volume0=volume1;
  1713. channel0=channel1;
  1714. }
  1715. }
  1716. if (channel0>1)
  1717. {
  1718. channel0=0;
  1719. volume0=0;
  1720. }
  1721. if (channel1>1)
  1722. {
  1723. channel1=1;
  1724. volume1=0;
  1725. }
  1726. if (fam1_drive)
  1727. {
  1728. control0=channel0+1;
  1729. control1=channel1+1;
  1730. value0=(volume0>volume1)?volume0:volume1;
  1731. value1=value0;
  1732. if (volume0==0) control0=0;
  1733. if (volume1==0) control1=0;
  1734. drvcmd[0]=CMD1_SETMODE;
  1735. drvcmd[1]=0x05;
  1736. drvcmd[3]=control0;
  1737. drvcmd[4]=value0;
  1738. drvcmd[5]=control1;
  1739. drvcmd[6]=value1;
  1740. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  1741. }
  1742. else if (fam2_drive)
  1743. {
  1744. control0=channel0+1;
  1745. control1=channel1+1;
  1746. value0=(volume0>volume1)?volume0:volume1;
  1747. value1=value0;
  1748. if (volume0==0) control0=0;
  1749. if (volume1==0) control1=0;
  1750. drvcmd[0]=CMD2_SETMODE;
  1751. drvcmd[1]=0x0E;
  1752. drvcmd[3]=control0;
  1753. drvcmd[4]=value0;
  1754. drvcmd[5]=control1;
  1755. drvcmd[6]=value1;
  1756. flags_cmd_out=f_putcmd|f_ResponseStatus;
  1757. }
  1758. else if (famL_drive)
  1759. {
  1760. if ((volume0==0)||(channel0!=0)) control0 |= 0x80;
  1761. if ((volume1==0)||(channel1!=1)) control0 |= 0x40;
  1762. if (volume0|volume1) value0=0x80;
  1763. drvcmd[0]=CMDL_SETMODE;
  1764. drvcmd[1]=0x03;
  1765. drvcmd[4]=control0;
  1766. drvcmd[5]=value0;
  1767. flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  1768. }
  1769. else if (fam0_drive) /* different firmware levels */
  1770. {
  1771. if (current_drive->drv_type>=drv_300)
  1772. {
  1773. control0=volume0&0xFC;
  1774. value0=volume1&0xFC;
  1775. if ((volume0!=0)&&(volume0<4)) control0 |= 0x04;
  1776. if ((volume1!=0)&&(volume1<4)) value0 |= 0x04;
  1777. if (channel0!=0) control0 |= 0x01;
  1778. if (channel1==1) value0 |= 0x01;
  1779. }
  1780. else
  1781. {
  1782. value0=(volume0>volume1)?volume0:volume1;
  1783. if (current_drive->drv_type<drv_211)
  1784. {
  1785. if (channel0!=0)
  1786. {
  1787. i=channel1;
  1788. channel1=channel0;
  1789. channel0=i;
  1790. i=volume1;
  1791. volume1=volume0;
  1792. volume0=i;
  1793. }
  1794. if (channel0==channel1)
  1795. {
  1796. if (channel0==0)
  1797. {
  1798. channel1=1;
  1799. volume1=0;
  1800. volume0=value0;
  1801. }
  1802. else
  1803. {
  1804. channel0=0;
  1805. volume0=0;
  1806. volume1=value0;
  1807. }
  1808. }
  1809. }
  1810. if ((volume0!=0)&&(volume1!=0))
  1811. {
  1812. if (volume0==0xFF) volume1=0xFF;
  1813. else if (volume1==0xFF) volume0=0xFF;
  1814. }
  1815. else if (current_drive->drv_type<drv_201) volume0=volume1=value0;
  1816. if (current_drive->drv_type>=drv_201)
  1817. {
  1818. if (volume0==0) control0 |= 0x80;
  1819. if (volume1==0) control0 |= 0x40;
  1820. }
  1821. if (current_drive->drv_type>=drv_211)
  1822. {
  1823. if (channel0!=0) control0 |= 0x20;
  1824. if (channel1!=1) control0 |= 0x10;
  1825. }
  1826. }
  1827. drvcmd[0]=CMD0_SETMODE;
  1828. drvcmd[1]=0x83;
  1829. drvcmd[4]=control0;
  1830. drvcmd[5]=value0;
  1831. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  1832. }
  1833. else if (famT_drive)
  1834. {
  1835. current_drive->volume_control=0;
  1836. if (!volume0) current_drive->volume_control|=0x10;
  1837. if (!volume1) current_drive->volume_control|=0x20;
  1838. i=cc_prep_mode_T();
  1839. if (i<0) return (i);
  1840. }
  1841. if (!famT_drive)
  1842. {
  1843. response_count=0;
  1844. i=cmd_out();
  1845. if (i<0) return (i);
  1846. }
  1847. current_drive->diskstate_flags |= volume_bit;
  1848. return (0);
  1849. }
  1850. /*==========================================================================*/
  1851. static int GetStatus(void)
  1852. {
  1853. int i;
  1854. if (famT_drive) return (0);
  1855. flags_cmd_out=f_getsta|f_ResponseStatus|f_obey_p_check;
  1856. response_count=0;
  1857. cmd_type=0;
  1858. i=cmd_out();
  1859. return (i);
  1860. }
  1861. /*==========================================================================*/
  1862. static int cc_DriveReset(void)
  1863. {
  1864. int i;
  1865. msg(DBG_RES,"cc_DriveReset called.\n");
  1866. clr_cmdbuf();
  1867. response_count=0;
  1868. if (fam0LV_drive) OUT(CDo_reset,0x00);
  1869. else if (fam1_drive)
  1870. {
  1871. drvcmd[0]=CMD1_RESET;
  1872. flags_cmd_out=f_putcmd;
  1873. i=cmd_out();
  1874. }
  1875. else if (fam2_drive)
  1876. {
  1877. drvcmd[0]=CMD2_RESET;
  1878. flags_cmd_out=f_putcmd;
  1879. i=cmd_out();
  1880. OUT(CDo_reset,0x00);
  1881. }
  1882. else if (famT_drive)
  1883. {
  1884. OUT(CDo_sel_i_d,0);
  1885. OUT(CDo_enable,current_drive->drv_sel);
  1886. OUT(CDo_command,CMDT_RESET);
  1887. for (i=1;i<10;i++) OUT(CDo_command,0);
  1888. }
  1889. if (fam0LV_drive) sbp_sleep(5*HZ); /* wait 5 seconds */
  1890. else sbp_sleep(1*HZ); /* wait a second */
  1891. #if 1
  1892. if (famT_drive)
  1893. {
  1894. msg(DBG_TEA, "================CMDT_RESET given=================.\n");
  1895. sbp_sleep(3*HZ);
  1896. }
  1897. #endif /* 1 */
  1898. flush_status();
  1899. i=GetStatus();
  1900. if (i<0) return i;
  1901. if (!famT_drive)
  1902. if (current_drive->error_byte!=aud_12) return -501;
  1903. return (0);
  1904. }
  1905. /*==========================================================================*/
  1906. static int SetSpeed(void)
  1907. {
  1908. int i, speed;
  1909. if (!(current_drive->drv_options&(speed_auto|speed_300|speed_150))) return (0);
  1910. speed=speed_auto;
  1911. if (!(current_drive->drv_options&speed_auto))
  1912. {
  1913. speed |= speed_300;
  1914. if (!(current_drive->drv_options&speed_300)) speed=0;
  1915. }
  1916. i=cc_SetSpeed(speed,0,0);
  1917. return (i);
  1918. }
  1919. static void switch_drive(struct sbpcd_drive *);
  1920. static int sbpcd_select_speed(struct cdrom_device_info *cdi, int speed)
  1921. {
  1922. struct sbpcd_drive *p = cdi->handle;
  1923. if (p != current_drive)
  1924. switch_drive(p);
  1925. return cc_SetSpeed(speed == 2 ? speed_300 : speed_150, 0, 0);
  1926. }
  1927. /*==========================================================================*/
  1928. static int DriveReset(void)
  1929. {
  1930. int i;
  1931. i=cc_DriveReset();
  1932. if (i<0) return (-22);
  1933. do
  1934. {
  1935. i=GetStatus();
  1936. if ((i<0)&&(i!=-ERR_DISKCHANGE)) {
  1937. return (-2); /* from sta2err */
  1938. }
  1939. if (!st_caddy_in) break;
  1940. sbp_sleep(1);
  1941. }
  1942. while (!st_diskok);
  1943. #if 000
  1944. current_drive->CD_changed=1;
  1945. #endif
  1946. if ((st_door_closed) && (st_caddy_in))
  1947. {
  1948. i=DiskInfo();
  1949. if (i<0) return (-23);
  1950. }
  1951. return (0);
  1952. }
  1953. static int sbpcd_reset(struct cdrom_device_info *cdi)
  1954. {
  1955. struct sbpcd_drive *p = cdi->handle;
  1956. if (p != current_drive)
  1957. switch_drive(p);
  1958. return DriveReset();
  1959. }
  1960. /*==========================================================================*/
  1961. static int cc_PlayAudio(int pos_audio_start,int pos_audio_end)
  1962. {
  1963. int i, j, n;
  1964. if (current_drive->audio_state==audio_playing) return (-EINVAL);
  1965. clr_cmdbuf();
  1966. response_count=0;
  1967. if (famLV_drive)
  1968. {
  1969. drvcmd[0]=CMDL_PLAY;
  1970. i=msf2blk(pos_audio_start);
  1971. n=msf2blk(pos_audio_end)+1-i;
  1972. drvcmd[1]=(i>>16)&0x00FF;
  1973. drvcmd[2]=(i>>8)&0x00FF;
  1974. drvcmd[3]=i&0x00FF;
  1975. drvcmd[4]=(n>>16)&0x00FF;
  1976. drvcmd[5]=(n>>8)&0x00FF;
  1977. drvcmd[6]=n&0x00FF;
  1978. if (famL_drive)
  1979. flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
  1980. f_ResponseStatus | f_obey_p_check | f_wait_if_busy;
  1981. else
  1982. flags_cmd_out = f_putcmd;
  1983. }
  1984. else
  1985. {
  1986. j=1;
  1987. if (fam1_drive)
  1988. {
  1989. drvcmd[0]=CMD1_PLAY_MSF;
  1990. flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus |
  1991. f_obey_p_check | f_wait_if_busy;
  1992. }
  1993. else if (fam2_drive)
  1994. {
  1995. drvcmd[0]=CMD2_PLAY_MSF;
  1996. flags_cmd_out = f_putcmd | f_ResponseStatus | f_obey_p_check;
  1997. }
  1998. else if (famT_drive)
  1999. {
  2000. drvcmd[0]=CMDT_PLAY_MSF;
  2001. j=3;
  2002. response_count=1;
  2003. }
  2004. else if (fam0_drive)
  2005. {
  2006. drvcmd[0]=CMD0_PLAY_MSF;
  2007. flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
  2008. f_ResponseStatus | f_obey_p_check | f_wait_if_busy;
  2009. }
  2010. drvcmd[j]=(pos_audio_start>>16)&0x00FF;
  2011. drvcmd[j+1]=(pos_audio_start>>8)&0x00FF;
  2012. drvcmd[j+2]=pos_audio_start&0x00FF;
  2013. drvcmd[j+3]=(pos_audio_end>>16)&0x00FF;
  2014. drvcmd[j+4]=(pos_audio_end>>8)&0x00FF;
  2015. drvcmd[j+5]=pos_audio_end&0x00FF;
  2016. }
  2017. i=cmd_out();
  2018. return (i);
  2019. }
  2020. /*==========================================================================*/
  2021. static int cc_Pause_Resume(int pau_res)
  2022. {
  2023. int i;
  2024. clr_cmdbuf();
  2025. response_count=0;
  2026. if (fam1_drive)
  2027. {
  2028. drvcmd[0]=CMD1_PAU_RES;
  2029. if (pau_res!=1) drvcmd[1]=0x80;
  2030. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  2031. }
  2032. else if (fam2_drive)
  2033. {
  2034. drvcmd[0]=CMD2_PAU_RES;
  2035. if (pau_res!=1) drvcmd[2]=0x01;
  2036. flags_cmd_out=f_putcmd|f_ResponseStatus;
  2037. }
  2038. else if (fam0LV_drive)
  2039. {
  2040. drvcmd[0]=CMD0_PAU_RES;
  2041. if (pau_res!=1) drvcmd[1]=0x80;
  2042. if (famL_drive)
  2043. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|
  2044. f_obey_p_check|f_bit1;
  2045. else if (famV_drive)
  2046. flags_cmd_out=f_putcmd;
  2047. else
  2048. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|
  2049. f_obey_p_check;
  2050. }
  2051. else if (famT_drive)
  2052. {
  2053. if (pau_res==3) return (cc_PlayAudio(current_drive->pos_audio_start,current_drive->pos_audio_end));
  2054. else if (pau_res==1) drvcmd[0]=CMDT_PAUSE;
  2055. else return (-56);
  2056. }
  2057. i=cmd_out();
  2058. return (i);
  2059. }
  2060. /*==========================================================================*/
  2061. static int cc_LockDoor(char lock)
  2062. {
  2063. int i;
  2064. if (fam0_drive) return (0);
  2065. msg(DBG_LCK,"cc_LockDoor: %d (drive %d)\n", lock, current_drive - D_S);
  2066. msg(DBG_LCS,"p_door_locked bit %d before\n", st_door_locked);
  2067. clr_cmdbuf();
  2068. response_count=0;
  2069. if (fam1_drive)
  2070. {
  2071. drvcmd[0]=CMD1_LOCK_CTL;
  2072. if (lock==1) drvcmd[1]=0x01;
  2073. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2074. }
  2075. else if (fam2_drive)
  2076. {
  2077. drvcmd[0]=CMD2_LOCK_CTL;
  2078. if (lock==1) drvcmd[4]=0x01;
  2079. flags_cmd_out=f_putcmd|f_ResponseStatus;
  2080. }
  2081. else if (famLV_drive)
  2082. {
  2083. drvcmd[0]=CMDL_LOCK_CTL;
  2084. if (lock==1) drvcmd[1]=0x01;
  2085. if (famL_drive)
  2086. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  2087. else
  2088. flags_cmd_out=f_putcmd;
  2089. }
  2090. else if (famT_drive)
  2091. {
  2092. drvcmd[0]=CMDT_LOCK_CTL;
  2093. if (lock==1) drvcmd[4]=0x01;
  2094. }
  2095. i=cmd_out();
  2096. msg(DBG_LCS,"p_door_locked bit %d after\n", st_door_locked);
  2097. return (i);
  2098. }
  2099. /*==========================================================================*/
  2100. /*==========================================================================*/
  2101. static int UnLockDoor(void)
  2102. {
  2103. int i,j;
  2104. j=20;
  2105. do
  2106. {
  2107. i=cc_LockDoor(0);
  2108. --j;
  2109. sbp_sleep(1);
  2110. }
  2111. while ((i<0)&&(j));
  2112. if (i<0)
  2113. {
  2114. cc_DriveReset();
  2115. return -84;
  2116. }
  2117. return (0);
  2118. }
  2119. /*==========================================================================*/
  2120. static int LockDoor(void)
  2121. {
  2122. int i,j;
  2123. j=20;
  2124. do
  2125. {
  2126. i=cc_LockDoor(1);
  2127. --j;
  2128. sbp_sleep(1);
  2129. }
  2130. while ((i<0)&&(j));
  2131. if (j==0)
  2132. {
  2133. cc_DriveReset();
  2134. j=20;
  2135. do
  2136. {
  2137. i=cc_LockDoor(1);
  2138. --j;
  2139. sbp_sleep(1);
  2140. }
  2141. while ((i<0)&&(j));
  2142. }
  2143. return (i);
  2144. }
  2145. static int sbpcd_lock_door(struct cdrom_device_info *cdi, int lock)
  2146. {
  2147. return lock ? LockDoor() : UnLockDoor();
  2148. }
  2149. /*==========================================================================*/
  2150. static int cc_CloseTray(void)
  2151. {
  2152. int i;
  2153. if (fam0_drive) return (0);
  2154. msg(DBG_LCK,"cc_CloseTray (drive %d)\n", current_drive - D_S);
  2155. msg(DBG_LCS,"p_door_closed bit %d before\n", st_door_closed);
  2156. clr_cmdbuf();
  2157. response_count=0;
  2158. if (fam1_drive)
  2159. {
  2160. drvcmd[0]=CMD1_TRAY_CTL;
  2161. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  2162. }
  2163. else if (fam2_drive)
  2164. {
  2165. drvcmd[0]=CMD2_TRAY_CTL;
  2166. drvcmd[1]=0x01;
  2167. drvcmd[4]=0x03; /* "insert" */
  2168. flags_cmd_out=f_putcmd|f_ResponseStatus;
  2169. }
  2170. else if (famLV_drive)
  2171. {
  2172. drvcmd[0]=CMDL_TRAY_CTL;
  2173. if (famLV_drive)
  2174. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|
  2175. f_ResponseStatus|f_obey_p_check|f_bit1;
  2176. else
  2177. flags_cmd_out=f_putcmd;
  2178. }
  2179. else if (famT_drive)
  2180. {
  2181. drvcmd[0]=CMDT_TRAY_CTL;
  2182. drvcmd[4]=0x03; /* "insert" */
  2183. }
  2184. i=cmd_out();
  2185. msg(DBG_LCS,"p_door_closed bit %d after\n", st_door_closed);
  2186. i=cc_ReadError();
  2187. flags_cmd_out |= f_respo2;
  2188. cc_ReadStatus(); /* command: give 1-byte status */
  2189. i=ResponseStatus();
  2190. if (famT_drive&&(i<0))
  2191. {
  2192. cc_DriveReset();
  2193. i=ResponseStatus();
  2194. #if 0
  2195. sbp_sleep(HZ);
  2196. #endif /* 0 */
  2197. i=ResponseStatus();
  2198. }
  2199. if (i<0)
  2200. {
  2201. msg(DBG_INF,"sbpcd cc_CloseTray: ResponseStatus timed out (%d).\n",i);
  2202. }
  2203. if (!(famT_drive))
  2204. {
  2205. if (!st_spinning)
  2206. {
  2207. cc_SpinUp();
  2208. if (st_check) i=cc_ReadError();
  2209. flags_cmd_out |= f_respo2;
  2210. cc_ReadStatus();
  2211. i=ResponseStatus();
  2212. } else {
  2213. }
  2214. }
  2215. i=DiskInfo();
  2216. return (i);
  2217. }
  2218. static int sbpcd_tray_move(struct cdrom_device_info *cdi, int position)
  2219. {
  2220. int retval=0;
  2221. switch_drive(cdi->handle);
  2222. /* DUH! --AJK */
  2223. if(current_drive->CD_changed != 0xFF) {
  2224. current_drive->CD_changed=0xFF;
  2225. current_drive->diskstate_flags &= ~cd_size_bit;
  2226. }
  2227. if (position == 1) {
  2228. cc_SpinDown();
  2229. } else {
  2230. retval=cc_CloseTray();
  2231. }
  2232. return retval;
  2233. }
  2234. /*==========================================================================*/
  2235. static int cc_ReadSubQ(void)
  2236. {
  2237. int i,j;
  2238. current_drive->diskstate_flags &= ~subq_bit;
  2239. for (j=255;j>0;j--)
  2240. {
  2241. clr_cmdbuf();
  2242. if (fam1_drive)
  2243. {
  2244. drvcmd[0]=CMD1_READSUBQ;
  2245. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2246. response_count=11;
  2247. }
  2248. else if (fam2_drive)
  2249. {
  2250. drvcmd[0]=CMD2_READSUBQ;
  2251. drvcmd[1]=0x02;
  2252. drvcmd[3]=0x01;
  2253. flags_cmd_out=f_putcmd;
  2254. response_count=10;
  2255. }
  2256. else if (fam0LV_drive)
  2257. {
  2258. drvcmd[0]=CMD0_READSUBQ;
  2259. drvcmd[1]=0x02;
  2260. if (famLV_drive)
  2261. flags_cmd_out=f_putcmd;
  2262. else
  2263. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2264. response_count=13;
  2265. }
  2266. else if (famT_drive)
  2267. {
  2268. response_count=12;
  2269. drvcmd[0]=CMDT_READSUBQ;
  2270. drvcmd[1]=0x02;
  2271. drvcmd[2]=0x40;
  2272. drvcmd[3]=0x01;
  2273. drvcmd[8]=response_count;
  2274. }
  2275. i=cmd_out();
  2276. if (i<0) return (i);
  2277. for (i=0;i<response_count;i++)
  2278. {
  2279. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  2280. msgbuf[i*3]=0;
  2281. msg(DBG_SQ1,"cc_ReadSubQ:%s\n", msgbuf);
  2282. }
  2283. if (famT_drive) break;
  2284. if (infobuf[0]!=0) break;
  2285. if ((!st_spinning) || (j==1))
  2286. {
  2287. current_drive->SubQ_ctl_adr=current_drive->SubQ_trk=current_drive->SubQ_pnt_idx=current_drive->SubQ_whatisthis=0;
  2288. current_drive->SubQ_run_tot=current_drive->SubQ_run_trk=0;
  2289. return (0);
  2290. }
  2291. }
  2292. if (famT_drive) current_drive->SubQ_ctl_adr=infobuf[1];
  2293. else current_drive->SubQ_ctl_adr=swap_nibbles(infobuf[1]);
  2294. current_drive->SubQ_trk=byt2bcd(infobuf[2]);
  2295. current_drive->SubQ_pnt_idx=byt2bcd(infobuf[3]);
  2296. if (fam0LV_drive) i=5;
  2297. else if (fam12_drive) i=4;
  2298. else if (famT_drive) i=8;
  2299. current_drive->SubQ_run_tot=make32(make16(0,infobuf[i]),make16(infobuf[i+1],infobuf[i+2])); /* msf-bin */
  2300. i=7;
  2301. if (fam0LV_drive) i=9;
  2302. else if (fam12_drive) i=7;
  2303. else if (famT_drive) i=4;
  2304. current_drive->SubQ_run_trk=make32(make16(0,infobuf[i]),make16(infobuf[i+1],infobuf[i+2])); /* msf-bin */
  2305. current_drive->SubQ_whatisthis=infobuf[i+3];
  2306. current_drive->diskstate_flags |= subq_bit;
  2307. return (0);
  2308. }
  2309. /*==========================================================================*/
  2310. static int cc_ModeSense(void)
  2311. {
  2312. int i;
  2313. if (fam2_drive) return (0);
  2314. if (famV_drive) return (0);
  2315. current_drive->diskstate_flags &= ~frame_size_bit;
  2316. clr_cmdbuf();
  2317. if (fam1_drive)
  2318. {
  2319. response_count=5;
  2320. drvcmd[0]=CMD1_GETMODE;
  2321. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2322. }
  2323. else if (fam0L_drive)
  2324. {
  2325. response_count=2;
  2326. drvcmd[0]=CMD0_GETMODE;
  2327. if (famL_drive) flags_cmd_out=f_putcmd;
  2328. else flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2329. }
  2330. else if (famT_drive)
  2331. {
  2332. response_count=10;
  2333. drvcmd[0]=CMDT_GETMODE;
  2334. drvcmd[4]=response_count;
  2335. }
  2336. i=cmd_out();
  2337. if (i<0) return (i);
  2338. i=0;
  2339. current_drive->sense_byte=0;
  2340. if (fam1_drive) current_drive->sense_byte=infobuf[i++];
  2341. else if (famT_drive)
  2342. {
  2343. if (infobuf[4]==0x01) current_drive->xa_byte=0x20;
  2344. else current_drive->xa_byte=0;
  2345. i=2;
  2346. }
  2347. current_drive->frame_size=make16(infobuf[i],infobuf[i+1]);
  2348. for (i=0;i<response_count;i++)
  2349. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  2350. msgbuf[i*3]=0;
  2351. msg(DBG_XA1,"cc_ModeSense:%s\n", msgbuf);
  2352. current_drive->diskstate_flags |= frame_size_bit;
  2353. return (0);
  2354. }
  2355. /*==========================================================================*/
  2356. /*==========================================================================*/
  2357. static int cc_ModeSelect(int framesize)
  2358. {
  2359. int i;
  2360. if (fam2_drive) return (0);
  2361. if (famV_drive) return (0);
  2362. current_drive->diskstate_flags &= ~frame_size_bit;
  2363. clr_cmdbuf();
  2364. current_drive->frame_size=framesize;
  2365. if (framesize==CD_FRAMESIZE_RAW) current_drive->sense_byte=0x82;
  2366. else current_drive->sense_byte=0x00;
  2367. msg(DBG_XA1,"cc_ModeSelect: %02X %04X\n",
  2368. current_drive->sense_byte, current_drive->frame_size);
  2369. if (fam1_drive)
  2370. {
  2371. drvcmd[0]=CMD1_SETMODE;
  2372. drvcmd[1]=0x00;
  2373. drvcmd[2]=current_drive->sense_byte;
  2374. drvcmd[3]=(current_drive->frame_size>>8)&0xFF;
  2375. drvcmd[4]=current_drive->frame_size&0xFF;
  2376. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2377. }
  2378. else if (fam0L_drive)
  2379. {
  2380. drvcmd[0]=CMD0_SETMODE;
  2381. drvcmd[1]=0x00;
  2382. drvcmd[2]=(current_drive->frame_size>>8)&0xFF;
  2383. drvcmd[3]=current_drive->frame_size&0xFF;
  2384. drvcmd[4]=0x00;
  2385. if(famL_drive)
  2386. flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check;
  2387. else
  2388. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2389. }
  2390. else if (famT_drive)
  2391. {
  2392. return (-1);
  2393. }
  2394. response_count=0;
  2395. i=cmd_out();
  2396. if (i<0) return (i);
  2397. current_drive->diskstate_flags |= frame_size_bit;
  2398. return (0);
  2399. }
  2400. /*==========================================================================*/
  2401. static int cc_GetVolume(void)
  2402. {
  2403. int i;
  2404. u_char switches;
  2405. u_char chan0=0;
  2406. u_char vol0=0;
  2407. u_char chan1=1;
  2408. u_char vol1=0;
  2409. if (famV_drive) return (0);
  2410. current_drive->diskstate_flags &= ~volume_bit;
  2411. clr_cmdbuf();
  2412. if (fam1_drive)
  2413. {
  2414. drvcmd[0]=CMD1_GETMODE;
  2415. drvcmd[1]=0x05;
  2416. response_count=5;
  2417. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2418. }
  2419. else if (fam2_drive)
  2420. {
  2421. drvcmd[0]=CMD2_GETMODE;
  2422. drvcmd[1]=0x0E;
  2423. response_count=5;
  2424. flags_cmd_out=f_putcmd;
  2425. }
  2426. else if (fam0L_drive)
  2427. {
  2428. drvcmd[0]=CMD0_GETMODE;
  2429. drvcmd[1]=0x03;
  2430. response_count=2;
  2431. if(famL_drive)
  2432. flags_cmd_out=f_putcmd;
  2433. else
  2434. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2435. }
  2436. else if (famT_drive)
  2437. {
  2438. i=cc_get_mode_T();
  2439. if (i<0) return (i);
  2440. }
  2441. if (!famT_drive)
  2442. {
  2443. i=cmd_out();
  2444. if (i<0) return (i);
  2445. }
  2446. if (fam1_drive)
  2447. {
  2448. chan0=infobuf[1]&0x0F;
  2449. vol0=infobuf[2];
  2450. chan1=infobuf[3]&0x0F;
  2451. vol1=infobuf[4];
  2452. if (chan0==0)
  2453. {
  2454. chan0=1;
  2455. vol0=0;
  2456. }
  2457. if (chan1==0)
  2458. {
  2459. chan1=2;
  2460. vol1=0;
  2461. }
  2462. chan0 >>= 1;
  2463. chan1 >>= 1;
  2464. }
  2465. else if (fam2_drive)
  2466. {
  2467. chan0=infobuf[1];
  2468. vol0=infobuf[2];
  2469. chan1=infobuf[3];
  2470. vol1=infobuf[4];
  2471. }
  2472. else if (famL_drive)
  2473. {
  2474. chan0=0;
  2475. chan1=1;
  2476. vol0=vol1=infobuf[1];
  2477. switches=infobuf[0];
  2478. if ((switches&0x80)!=0) chan0=1;
  2479. if ((switches&0x40)!=0) chan1=0;
  2480. }
  2481. else if (fam0_drive) /* different firmware levels */
  2482. {
  2483. chan0=0;
  2484. chan1=1;
  2485. vol0=vol1=infobuf[1];
  2486. if (current_drive->drv_type>=drv_201)
  2487. {
  2488. if (current_drive->drv_type<drv_300)
  2489. {
  2490. switches=infobuf[0];
  2491. if ((switches&0x80)!=0) vol0=0;
  2492. if ((switches&0x40)!=0) vol1=0;
  2493. if (current_drive->drv_type>=drv_211)
  2494. {
  2495. if ((switches&0x20)!=0) chan0=1;
  2496. if ((switches&0x10)!=0) chan1=0;
  2497. }
  2498. }
  2499. else
  2500. {
  2501. vol0=infobuf[0];
  2502. if ((vol0&0x01)!=0) chan0=1;
  2503. if ((vol1&0x01)==0) chan1=0;
  2504. vol0 &= 0xFC;
  2505. vol1 &= 0xFC;
  2506. if (vol0!=0) vol0 += 3;
  2507. if (vol1!=0) vol1 += 3;
  2508. }
  2509. }
  2510. }
  2511. else if (famT_drive)
  2512. {
  2513. current_drive->volume_control=infobuf[7];
  2514. chan0=0;
  2515. chan1=1;
  2516. if (current_drive->volume_control&0x10) vol0=0;
  2517. else vol0=0xff;
  2518. if (current_drive->volume_control&0x20) vol1=0;
  2519. else vol1=0xff;
  2520. }
  2521. current_drive->vol_chan0=chan0;
  2522. current_drive->vol_ctrl0=vol0;
  2523. current_drive->vol_chan1=chan1;
  2524. current_drive->vol_ctrl1=vol1;
  2525. #if 000
  2526. current_drive->vol_chan2=2;
  2527. current_drive->vol_ctrl2=0xFF;
  2528. current_drive->vol_chan3=3;
  2529. current_drive->vol_ctrl3=0xFF;
  2530. #endif /* 000 */
  2531. current_drive->diskstate_flags |= volume_bit;
  2532. return (0);
  2533. }
  2534. /*==========================================================================*/
  2535. static int cc_ReadCapacity(void)
  2536. {
  2537. int i, j;
  2538. if (fam2_drive) return (0); /* some firmware lacks this command */
  2539. if (famLV_drive) return (0); /* some firmware lacks this command */
  2540. if (famT_drive) return (0); /* done with cc_ReadTocDescr() */
  2541. current_drive->diskstate_flags &= ~cd_size_bit;
  2542. for (j=3;j>0;j--)
  2543. {
  2544. clr_cmdbuf();
  2545. if (fam1_drive)
  2546. {
  2547. drvcmd[0]=CMD1_CAPACITY;
  2548. response_count=5;
  2549. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2550. }
  2551. #if 00
  2552. else if (fam2_drive)
  2553. {
  2554. drvcmd[0]=CMD2_CAPACITY;
  2555. response_count=8;
  2556. flags_cmd_out=f_putcmd;
  2557. }
  2558. #endif
  2559. else if (fam0_drive)
  2560. {
  2561. drvcmd[0]=CMD0_CAPACITY;
  2562. response_count=5;
  2563. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2564. }
  2565. i=cmd_out();
  2566. if (i>=0) break;
  2567. msg(DBG_000,"cc_ReadCapacity: cmd_out: err %d\n", i);
  2568. cc_ReadError();
  2569. }
  2570. if (j==0) return (i);
  2571. if (fam1_drive) current_drive->CDsize_frm=msf2blk(make32(make16(0,infobuf[0]),make16(infobuf[1],infobuf[2])))+CD_MSF_OFFSET;
  2572. else if (fam0_drive) current_drive->CDsize_frm=make32(make16(0,infobuf[0]),make16(infobuf[1],infobuf[2]));
  2573. #if 00
  2574. else if (fam2_drive) current_drive->CDsize_frm=make32(make16(infobuf[0],infobuf[1]),make16(infobuf[2],infobuf[3]));
  2575. #endif
  2576. current_drive->diskstate_flags |= cd_size_bit;
  2577. msg(DBG_000,"cc_ReadCapacity: %d frames.\n", current_drive->CDsize_frm);
  2578. return (0);
  2579. }
  2580. /*==========================================================================*/
  2581. static int cc_ReadTocDescr(void)
  2582. {
  2583. int i;
  2584. current_drive->diskstate_flags &= ~toc_bit;
  2585. clr_cmdbuf();
  2586. if (fam1_drive)
  2587. {
  2588. drvcmd[0]=CMD1_DISKINFO;
  2589. response_count=6;
  2590. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2591. }
  2592. else if (fam0LV_drive)
  2593. {
  2594. drvcmd[0]=CMD0_DISKINFO;
  2595. response_count=6;
  2596. if(famLV_drive)
  2597. flags_cmd_out=f_putcmd;
  2598. else
  2599. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2600. }
  2601. else if (fam2_drive)
  2602. {
  2603. /* possibly longer timeout periods necessary */
  2604. current_drive->f_multisession=0;
  2605. drvcmd[0]=CMD2_DISKINFO;
  2606. drvcmd[1]=0x02;
  2607. drvcmd[2]=0xAB;
  2608. drvcmd[3]=0xFF; /* session */
  2609. response_count=8;
  2610. flags_cmd_out=f_putcmd;
  2611. }
  2612. else if (famT_drive)
  2613. {
  2614. current_drive->f_multisession=0;
  2615. response_count=12;
  2616. drvcmd[0]=CMDT_DISKINFO;
  2617. drvcmd[1]=0x02;
  2618. drvcmd[6]=CDROM_LEADOUT;
  2619. drvcmd[8]=response_count;
  2620. drvcmd[9]=0x00;
  2621. }
  2622. i=cmd_out();
  2623. if (i<0) return (i);
  2624. if ((famT_drive)&&(i<response_count)) return (-100-i);
  2625. if ((fam1_drive)||(fam2_drive)||(fam0LV_drive))
  2626. current_drive->xa_byte=infobuf[0];
  2627. if (fam2_drive)
  2628. {
  2629. current_drive->first_session=infobuf[1];
  2630. current_drive->last_session=infobuf[2];
  2631. current_drive->n_first_track=infobuf[3];
  2632. current_drive->n_last_track=infobuf[4];
  2633. if (current_drive->first_session!=current_drive->last_session)
  2634. {
  2635. current_drive->f_multisession=1;
  2636. current_drive->lba_multi=msf2blk(make32(make16(0,infobuf[5]),make16(infobuf[6],infobuf[7])));
  2637. }
  2638. #if 0
  2639. if (current_drive->first_session!=current_drive->last_session)
  2640. {
  2641. if (current_drive->last_session<=20)
  2642. zwanzig=current_drive->last_session+1;
  2643. else zwanzig=20;
  2644. for (count=current_drive->first_session;count<zwanzig;count++)
  2645. {
  2646. drvcmd[0]=CMD2_DISKINFO;
  2647. drvcmd[1]=0x02;
  2648. drvcmd[2]=0xAB;
  2649. drvcmd[3]=count;
  2650. response_count=8;
  2651. flags_cmd_out=f_putcmd;
  2652. i=cmd_out();
  2653. if (i<0) return (i);
  2654. current_drive->msf_multi_n[count]=make32(make16(0,infobuf[5]),make16(infobuf[6],infobuf[7]));
  2655. }
  2656. current_drive->diskstate_flags |= multisession_bit;
  2657. }
  2658. #endif
  2659. drvcmd[0]=CMD2_DISKINFO;
  2660. drvcmd[1]=0x02;
  2661. drvcmd[2]=0xAA;
  2662. drvcmd[3]=0xFF;
  2663. response_count=5;
  2664. flags_cmd_out=f_putcmd;
  2665. i=cmd_out();
  2666. if (i<0) return (i);
  2667. current_drive->size_msf=make32(make16(0,infobuf[2]),make16(infobuf[3],infobuf[4]));
  2668. current_drive->size_blk=msf2blk(current_drive->size_msf);
  2669. current_drive->CDsize_frm=current_drive->size_blk+1;
  2670. }
  2671. else if (famT_drive)
  2672. {
  2673. current_drive->size_msf=make32(make16(infobuf[8],infobuf[9]),make16(infobuf[10],infobuf[11]));
  2674. current_drive->size_blk=msf2blk(current_drive->size_msf);
  2675. current_drive->CDsize_frm=current_drive->size_blk+1;
  2676. current_drive->n_first_track=infobuf[2];
  2677. current_drive->n_last_track=infobuf[3];
  2678. }
  2679. else
  2680. {
  2681. current_drive->n_first_track=infobuf[1];
  2682. current_drive->n_last_track=infobuf[2];
  2683. current_drive->size_msf=make32(make16(0,infobuf[3]),make16(infobuf[4],infobuf[5]));
  2684. current_drive->size_blk=msf2blk(current_drive->size_msf);
  2685. if (famLV_drive) current_drive->CDsize_frm=current_drive->size_blk+1;
  2686. }
  2687. current_drive->diskstate_flags |= toc_bit;
  2688. msg(DBG_TOC,"TocDesc: xa %02X firstt %02X lastt %02X size %08X firstses %02X lastsess %02X\n",
  2689. current_drive->xa_byte,
  2690. current_drive->n_first_track,
  2691. current_drive->n_last_track,
  2692. current_drive->size_msf,
  2693. current_drive->first_session,
  2694. current_drive->last_session);
  2695. return (0);
  2696. }
  2697. /*==========================================================================*/
  2698. static int cc_ReadTocEntry(int num)
  2699. {
  2700. int i;
  2701. clr_cmdbuf();
  2702. if (fam1_drive)
  2703. {
  2704. drvcmd[0]=CMD1_READTOC;
  2705. drvcmd[2]=num;
  2706. response_count=8;
  2707. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2708. }
  2709. else if (fam2_drive)
  2710. {
  2711. /* possibly longer timeout periods necessary */
  2712. drvcmd[0]=CMD2_DISKINFO;
  2713. drvcmd[1]=0x02;
  2714. drvcmd[2]=num;
  2715. response_count=5;
  2716. flags_cmd_out=f_putcmd;
  2717. }
  2718. else if (fam0LV_drive)
  2719. {
  2720. drvcmd[0]=CMD0_READTOC;
  2721. drvcmd[1]=0x02;
  2722. drvcmd[2]=num;
  2723. response_count=8;
  2724. if (famLV_drive)
  2725. flags_cmd_out=f_putcmd;
  2726. else
  2727. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2728. }
  2729. else if (famT_drive)
  2730. {
  2731. response_count=12;
  2732. drvcmd[0]=CMDT_DISKINFO;
  2733. drvcmd[1]=0x02;
  2734. drvcmd[6]=num;
  2735. drvcmd[8]=response_count;
  2736. drvcmd[9]=0x00;
  2737. }
  2738. i=cmd_out();
  2739. if (i<0) return (i);
  2740. if ((famT_drive)&&(i<response_count)) return (-100-i);
  2741. if ((fam1_drive)||(fam0LV_drive))
  2742. {
  2743. current_drive->TocEnt_nixbyte=infobuf[0];
  2744. i=1;
  2745. }
  2746. else if (fam2_drive) i=0;
  2747. else if (famT_drive) i=5;
  2748. current_drive->TocEnt_ctl_adr=swap_nibbles(infobuf[i++]);
  2749. if ((fam1_drive)||(fam0L_drive))
  2750. {
  2751. current_drive->TocEnt_number=infobuf[i++];
  2752. current_drive->TocEnt_format=infobuf[i];
  2753. }
  2754. else
  2755. {
  2756. current_drive->TocEnt_number=num;
  2757. current_drive->TocEnt_format=0;
  2758. }
  2759. if (fam1_drive) i=4;
  2760. else if (fam0LV_drive) i=5;
  2761. else if (fam2_drive) i=2;
  2762. else if (famT_drive) i=9;
  2763. current_drive->TocEnt_address=make32(make16(0,infobuf[i]),
  2764. make16(infobuf[i+1],infobuf[i+2]));
  2765. for (i=0;i<response_count;i++)
  2766. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  2767. msgbuf[i*3]=0;
  2768. msg(DBG_ECS,"TocEntry:%s\n", msgbuf);
  2769. msg(DBG_TOC,"TocEntry: %02X %02X %02X %02X %08X\n",
  2770. current_drive->TocEnt_nixbyte, current_drive->TocEnt_ctl_adr,
  2771. current_drive->TocEnt_number, current_drive->TocEnt_format,
  2772. current_drive->TocEnt_address);
  2773. return (0);
  2774. }
  2775. /*==========================================================================*/
  2776. static int cc_ReadPacket(void)
  2777. {
  2778. int i;
  2779. clr_cmdbuf();
  2780. drvcmd[0]=CMD0_PACKET;
  2781. drvcmd[1]=response_count;
  2782. if(famL_drive) flags_cmd_out=f_putcmd;
  2783. else if (fam01_drive)
  2784. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2785. else if (fam2_drive) return (-1); /* not implemented yet */
  2786. else if (famT_drive)
  2787. {
  2788. return (-1);
  2789. }
  2790. i=cmd_out();
  2791. return (i);
  2792. }
  2793. /*==========================================================================*/
  2794. static int convert_UPC(u_char *p)
  2795. {
  2796. int i;
  2797. p++;
  2798. if (fam0L_drive) p[13]=0;
  2799. for (i=0;i<7;i++)
  2800. {
  2801. if (fam1_drive) current_drive->UPC_buf[i]=swap_nibbles(*p++);
  2802. else if (fam0L_drive)
  2803. {
  2804. current_drive->UPC_buf[i]=((*p++)<<4)&0xFF;
  2805. current_drive->UPC_buf[i] |= *p++;
  2806. }
  2807. else if (famT_drive)
  2808. {
  2809. return (-1);
  2810. }
  2811. else /* CD200 */
  2812. {
  2813. return (-1);
  2814. }
  2815. }
  2816. current_drive->UPC_buf[6] &= 0xF0;
  2817. return (0);
  2818. }
  2819. /*==========================================================================*/
  2820. static int cc_ReadUPC(void)
  2821. {
  2822. int i;
  2823. #if TEST_UPC
  2824. int block, checksum;
  2825. #endif /* TEST_UPC */
  2826. if (fam2_drive) return (0); /* not implemented yet */
  2827. if (famT_drive) return (0); /* not implemented yet */
  2828. if (famV_drive) return (0); /* not implemented yet */
  2829. #if 1
  2830. if (fam0_drive) return (0); /* but it should work */
  2831. #endif
  2832. current_drive->diskstate_flags &= ~upc_bit;
  2833. #if TEST_UPC
  2834. for (block=CD_MSF_OFFSET+1;block<CD_MSF_OFFSET+200;block++)
  2835. {
  2836. #endif /* TEST_UPC */
  2837. clr_cmdbuf();
  2838. if (fam1_drive)
  2839. {
  2840. drvcmd[0]=CMD1_READ_UPC;
  2841. #if TEST_UPC
  2842. drvcmd[1]=(block>>16)&0xFF;
  2843. drvcmd[2]=(block>>8)&0xFF;
  2844. drvcmd[3]=block&0xFF;
  2845. #endif /* TEST_UPC */
  2846. response_count=8;
  2847. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2848. }
  2849. else if (fam0L_drive)
  2850. {
  2851. drvcmd[0]=CMD0_READ_UPC;
  2852. #if TEST_UPC
  2853. drvcmd[2]=(block>>16)&0xFF;
  2854. drvcmd[3]=(block>>8)&0xFF;
  2855. drvcmd[4]=block&0xFF;
  2856. #endif /* TEST_UPC */
  2857. response_count=0;
  2858. flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  2859. }
  2860. else if (fam2_drive)
  2861. {
  2862. return (-1);
  2863. }
  2864. else if (famT_drive)
  2865. {
  2866. return (-1);
  2867. }
  2868. i=cmd_out();
  2869. if (i<0)
  2870. {
  2871. msg(DBG_000,"cc_ReadUPC cmd_out: err %d\n", i);
  2872. return (i);
  2873. }
  2874. if (fam0L_drive)
  2875. {
  2876. response_count=16;
  2877. if (famL_drive) flags_cmd_out=f_putcmd;
  2878. i=cc_ReadPacket();
  2879. if (i<0)
  2880. {
  2881. msg(DBG_000,"cc_ReadUPC ReadPacket: err %d\n", i);
  2882. return (i);
  2883. }
  2884. }
  2885. #if TEST_UPC
  2886. checksum=0;
  2887. #endif /* TEST_UPC */
  2888. for (i=0;i<(fam1_drive?8:16);i++)
  2889. {
  2890. #if TEST_UPC
  2891. checksum |= infobuf[i];
  2892. #endif /* TEST_UPC */
  2893. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  2894. }
  2895. msgbuf[i*3]=0;
  2896. msg(DBG_UPC,"UPC info:%s\n", msgbuf);
  2897. #if TEST_UPC
  2898. if ((checksum&0x7F)!=0) break;
  2899. }
  2900. #endif /* TEST_UPC */
  2901. current_drive->UPC_ctl_adr=0;
  2902. if (fam1_drive) i=0;
  2903. else i=2;
  2904. if ((infobuf[i]&0x80)!=0)
  2905. {
  2906. convert_UPC(&infobuf[i]);
  2907. current_drive->UPC_ctl_adr = (current_drive->TocEnt_ctl_adr & 0xF0) | 0x02;
  2908. }
  2909. for (i=0;i<7;i++)
  2910. sprintf(&msgbuf[i*3], " %02X", current_drive->UPC_buf[i]);
  2911. sprintf(&msgbuf[i*3], " (%02X)", current_drive->UPC_ctl_adr);
  2912. msgbuf[i*3+5]=0;
  2913. msg(DBG_UPC,"UPC code:%s\n", msgbuf);
  2914. current_drive->diskstate_flags |= upc_bit;
  2915. return (0);
  2916. }
  2917. static int sbpcd_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
  2918. {
  2919. int i;
  2920. unsigned char *mcnp = mcn->medium_catalog_number;
  2921. unsigned char *resp;
  2922. current_drive->diskstate_flags &= ~upc_bit;
  2923. clr_cmdbuf();
  2924. if (fam1_drive)
  2925. {
  2926. drvcmd[0]=CMD1_READ_UPC;
  2927. response_count=8;
  2928. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2929. }
  2930. else if (fam0L_drive)
  2931. {
  2932. drvcmd[0]=CMD0_READ_UPC;
  2933. response_count=0;
  2934. flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  2935. }
  2936. else if (fam2_drive)
  2937. {
  2938. return (-1);
  2939. }
  2940. else if (famT_drive)
  2941. {
  2942. return (-1);
  2943. }
  2944. i=cmd_out();
  2945. if (i<0)
  2946. {
  2947. msg(DBG_000,"cc_ReadUPC cmd_out: err %d\n", i);
  2948. return (i);
  2949. }
  2950. if (fam0L_drive)
  2951. {
  2952. response_count=16;
  2953. if (famL_drive) flags_cmd_out=f_putcmd;
  2954. i=cc_ReadPacket();
  2955. if (i<0)
  2956. {
  2957. msg(DBG_000,"cc_ReadUPC ReadPacket: err %d\n", i);
  2958. return (i);
  2959. }
  2960. }
  2961. current_drive->UPC_ctl_adr=0;
  2962. if (fam1_drive) i=0;
  2963. else i=2;
  2964. resp = infobuf + i;
  2965. if (*resp++ == 0x80) {
  2966. /* packed bcd to single ASCII digits */
  2967. *mcnp++ = (*resp >> 4) + '0';
  2968. *mcnp++ = (*resp++ & 0x0f) + '0';
  2969. *mcnp++ = (*resp >> 4) + '0';
  2970. *mcnp++ = (*resp++ & 0x0f) + '0';
  2971. *mcnp++ = (*resp >> 4) + '0';
  2972. *mcnp++ = (*resp++ & 0x0f) + '0';
  2973. *mcnp++ = (*resp >> 4) + '0';
  2974. *mcnp++ = (*resp++ & 0x0f) + '0';
  2975. *mcnp++ = (*resp >> 4) + '0';
  2976. *mcnp++ = (*resp++ & 0x0f) + '0';
  2977. *mcnp++ = (*resp >> 4) + '0';
  2978. *mcnp++ = (*resp++ & 0x0f) + '0';
  2979. *mcnp++ = (*resp >> 4) + '0';
  2980. }
  2981. *mcnp = '\0';
  2982. current_drive->diskstate_flags |= upc_bit;
  2983. return (0);
  2984. }
  2985. /*==========================================================================*/
  2986. static int cc_CheckMultiSession(void)
  2987. {
  2988. int i;
  2989. if (fam2_drive) return (0);
  2990. current_drive->f_multisession=0;
  2991. current_drive->lba_multi=0;
  2992. if (fam0_drive) return (0);
  2993. clr_cmdbuf();
  2994. if (fam1_drive)
  2995. {
  2996. drvcmd[0]=CMD1_MULTISESS;
  2997. response_count=6;
  2998. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2999. i=cmd_out();
  3000. if (i<0) return (i);
  3001. if ((infobuf[0]&0x80)!=0)
  3002. {
  3003. current_drive->f_multisession=1;
  3004. current_drive->lba_multi=msf2blk(make32(make16(0,infobuf[1]),
  3005. make16(infobuf[2],infobuf[3])));
  3006. }
  3007. }
  3008. else if (famLV_drive)
  3009. {
  3010. drvcmd[0]=CMDL_MULTISESS;
  3011. drvcmd[1]=3;
  3012. drvcmd[2]=1;
  3013. response_count=8;
  3014. flags_cmd_out=f_putcmd;
  3015. i=cmd_out();
  3016. if (i<0) return (i);
  3017. current_drive->lba_multi=msf2blk(make32(make16(0,infobuf[5]),
  3018. make16(infobuf[6],infobuf[7])));
  3019. }
  3020. else if (famT_drive)
  3021. {
  3022. response_count=12;
  3023. drvcmd[0]=CMDT_DISKINFO;
  3024. drvcmd[1]=0x02;
  3025. drvcmd[6]=0;
  3026. drvcmd[8]=response_count;
  3027. drvcmd[9]=0x40;
  3028. i=cmd_out();
  3029. if (i<0) return (i);
  3030. if (i<response_count) return (-100-i);
  3031. current_drive->first_session=infobuf[2];
  3032. current_drive->last_session=infobuf[3];
  3033. current_drive->track_of_last_session=infobuf[6];
  3034. if (current_drive->first_session!=current_drive->last_session)
  3035. {
  3036. current_drive->f_multisession=1;
  3037. current_drive->lba_multi=msf2blk(make32(make16(0,infobuf[9]),make16(infobuf[10],infobuf[11])));
  3038. }
  3039. }
  3040. for (i=0;i<response_count;i++)
  3041. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  3042. msgbuf[i*3]=0;
  3043. msg(DBG_MUL,"MultiSession Info:%s (%d)\n", msgbuf, current_drive->lba_multi);
  3044. if (current_drive->lba_multi>200)
  3045. {
  3046. current_drive->f_multisession=1;
  3047. msg(DBG_MUL,"MultiSession base: %06X\n", current_drive->lba_multi);
  3048. }
  3049. return (0);
  3050. }
  3051. /*==========================================================================*/
  3052. #ifdef FUTURE
  3053. static int cc_SubChanInfo(int frame, int count, u_char *buffer)
  3054. /* "frame" is a RED BOOK (msf-bin) address */
  3055. {
  3056. int i;
  3057. if (fam0LV_drive) return (-ENOSYS); /* drive firmware lacks it */
  3058. if (famT_drive)
  3059. {
  3060. return (-1);
  3061. }
  3062. #if 0
  3063. if (current_drive->audio_state!=audio_playing) return (-ENODATA);
  3064. #endif
  3065. clr_cmdbuf();
  3066. drvcmd[0]=CMD1_SUBCHANINF;
  3067. drvcmd[1]=(frame>>16)&0xFF;
  3068. drvcmd[2]=(frame>>8)&0xFF;
  3069. drvcmd[3]=frame&0xFF;
  3070. drvcmd[5]=(count>>8)&0xFF;
  3071. drvcmd[6]=count&0xFF;
  3072. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  3073. cmd_type=READ_SC;
  3074. current_drive->frame_size=CD_FRAMESIZE_SUB;
  3075. i=cmd_out(); /* which buffer to use? */
  3076. return (i);
  3077. }
  3078. #endif /* FUTURE */
  3079. /*==========================================================================*/
  3080. static void __init check_datarate(void)
  3081. {
  3082. int i=0;
  3083. msg(DBG_IOX,"check_datarate entered.\n");
  3084. datarate=0;
  3085. #if TEST_STI
  3086. for (i=0;i<=1000;i++) printk(".");
  3087. #endif
  3088. /* set a timer to make (timed_out_delay!=0) after 1.1 seconds */
  3089. #if 1
  3090. del_timer(&delay_timer);
  3091. #endif
  3092. delay_timer.expires=jiffies+11*HZ/10;
  3093. timed_out_delay=0;
  3094. add_timer(&delay_timer);
  3095. #if 0
  3096. msg(DBG_TIM,"delay timer started (11*HZ/10).\n");
  3097. #endif
  3098. do
  3099. {
  3100. i=inb(CDi_status);
  3101. datarate++;
  3102. #if 1
  3103. if (datarate>0x6FFFFFFF) break;
  3104. #endif
  3105. }
  3106. while (!timed_out_delay);
  3107. del_timer(&delay_timer);
  3108. #if 0
  3109. msg(DBG_TIM,"datarate: %04X\n", datarate);
  3110. #endif
  3111. if (datarate<65536) datarate=65536;
  3112. maxtim16=datarate*16;
  3113. maxtim04=datarate*4;
  3114. maxtim02=datarate*2;
  3115. maxtim_8=datarate/32;
  3116. #if LONG_TIMING
  3117. maxtim_data=datarate/100;
  3118. #else
  3119. maxtim_data=datarate/300;
  3120. #endif /* LONG_TIMING */
  3121. #if 0
  3122. msg(DBG_TIM,"maxtim_8 %d, maxtim_data %d.\n", maxtim_8, maxtim_data);
  3123. #endif
  3124. }
  3125. /*==========================================================================*/
  3126. #if 0
  3127. static int c2_ReadError(int fam)
  3128. {
  3129. int i;
  3130. clr_cmdbuf();
  3131. response_count=9;
  3132. clr_respo_buf(9);
  3133. if (fam==1)
  3134. {
  3135. drvcmd[0]=CMD0_READ_ERR; /* same as CMD1_ and CMDL_ */
  3136. i=do_cmd(f_putcmd|f_lopsta|f_getsta|f_ResponseStatus);
  3137. }
  3138. else if (fam==2)
  3139. {
  3140. drvcmd[0]=CMD2_READ_ERR;
  3141. i=do_cmd(f_putcmd);
  3142. }
  3143. else return (-1);
  3144. return (i);
  3145. }
  3146. #endif
  3147. /*==========================================================================*/
  3148. static void __init ask_mail(void)
  3149. {
  3150. int i;
  3151. msg(DBG_INF, "please mail the following lines to emoenke@gwdg.de\n");
  3152. msg(DBG_INF, "(don't mail if you are not using the actual kernel):\n");
  3153. msg(DBG_INF, "%s\n", VERSION);
  3154. msg(DBG_INF, "address %03X, type %s, drive %s (ID %d)\n",
  3155. CDo_command, type, current_drive->drive_model, current_drive->drv_id);
  3156. for (i=0;i<12;i++)
  3157. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  3158. msgbuf[i*3]=0;
  3159. msg(DBG_INF,"infobuf =%s\n", msgbuf);
  3160. for (i=0;i<12;i++)
  3161. sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
  3162. msgbuf[i*3]=0;
  3163. msg(DBG_INF,"infobuf =%s\n", msgbuf);
  3164. }
  3165. /*==========================================================================*/
  3166. static int __init check_version(void)
  3167. {
  3168. int i, j, l;
  3169. int teac_possible=0;
  3170. msg(DBG_INI,"check_version: id=%d, d=%d.\n", current_drive->drv_id, current_drive - D_S);
  3171. current_drive->drv_type=0;
  3172. /* check for CR-52x, CR-56x, LCS-7260 and ECS-AT */
  3173. /* clear any pending error state */
  3174. clr_cmdbuf();
  3175. drvcmd[0]=CMD0_READ_ERR; /* same as CMD1_ and CMDL_ */
  3176. response_count=9;
  3177. flags_cmd_out=f_putcmd;
  3178. i=cmd_out();
  3179. if (i<0) msg(DBG_INI,"CMD0_READ_ERR returns %d (ok anyway).\n",i);
  3180. /* read drive version */
  3181. clr_cmdbuf();
  3182. for (i=0;i<12;i++) infobuf[i]=0;
  3183. drvcmd[0]=CMD0_READ_VER; /* same as CMD1_ and CMDL_ */
  3184. response_count=12; /* fam1: only 11 */
  3185. flags_cmd_out=f_putcmd;
  3186. i=cmd_out();
  3187. if (i<-1) msg(DBG_INI,"CMD0_READ_VER returns %d\n",i);
  3188. if (i==-11) teac_possible++;
  3189. j=0;
  3190. for (i=0;i<12;i++) j+=infobuf[i];
  3191. if (j)
  3192. {
  3193. for (i=0;i<12;i++)
  3194. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  3195. msgbuf[i*3]=0;
  3196. msg(DBG_ECS,"infobuf =%s\n", msgbuf);
  3197. for (i=0;i<12;i++)
  3198. sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
  3199. msgbuf[i*3]=0;
  3200. msg(DBG_ECS,"infobuf =%s\n", msgbuf);
  3201. }
  3202. for (i=0;i<4;i++) if (infobuf[i]!=family1[i]) break;
  3203. if (i==4)
  3204. {
  3205. current_drive->drive_model[0]='C';
  3206. current_drive->drive_model[1]='R';
  3207. current_drive->drive_model[2]='-';
  3208. current_drive->drive_model[3]='5';
  3209. current_drive->drive_model[4]=infobuf[i++];
  3210. current_drive->drive_model[5]=infobuf[i++];
  3211. current_drive->drive_model[6]=0;
  3212. current_drive->drv_type=drv_fam1;
  3213. }
  3214. if (!current_drive->drv_type)
  3215. {
  3216. for (i=0;i<8;i++) if (infobuf[i]!=family0[i]) break;
  3217. if (i==8)
  3218. {
  3219. current_drive->drive_model[0]='C';
  3220. current_drive->drive_model[1]='R';
  3221. current_drive->drive_model[2]='-';
  3222. current_drive->drive_model[3]='5';
  3223. current_drive->drive_model[4]='2';
  3224. current_drive->drive_model[5]='x';
  3225. current_drive->drive_model[6]=0;
  3226. current_drive->drv_type=drv_fam0;
  3227. }
  3228. }
  3229. if (!current_drive->drv_type)
  3230. {
  3231. for (i=0;i<8;i++) if (infobuf[i]!=familyL[i]) break;
  3232. if (i==8)
  3233. {
  3234. for (j=0;j<8;j++)
  3235. current_drive->drive_model[j]=infobuf[j];
  3236. current_drive->drive_model[8]=0;
  3237. current_drive->drv_type=drv_famL;
  3238. }
  3239. }
  3240. if (!current_drive->drv_type)
  3241. {
  3242. for (i=0;i<6;i++) if (infobuf[i]!=familyV[i]) break;
  3243. if (i==6)
  3244. {
  3245. for (j=0;j<6;j++)
  3246. current_drive->drive_model[j]=infobuf[j];
  3247. current_drive->drive_model[6]=0;
  3248. current_drive->drv_type=drv_famV;
  3249. i+=2; /* 2 blanks before version */
  3250. }
  3251. }
  3252. if (!current_drive->drv_type)
  3253. {
  3254. /* check for CD200 */
  3255. clr_cmdbuf();
  3256. drvcmd[0]=CMD2_READ_ERR;
  3257. response_count=9;
  3258. flags_cmd_out=f_putcmd;
  3259. i=cmd_out();
  3260. if (i<0) msg(DBG_INI,"CMD2_READERR returns %d (ok anyway).\n",i);
  3261. if (i<0) msg(DBG_000,"CMD2_READERR returns %d (ok anyway).\n",i);
  3262. /* read drive version */
  3263. clr_cmdbuf();
  3264. for (i=0;i<12;i++) infobuf[i]=0;
  3265. if (sbpro_type==1) OUT(CDo_sel_i_d,0);
  3266. #if 0
  3267. OUT(CDo_reset,0);
  3268. sbp_sleep(6*HZ);
  3269. OUT(CDo_enable,current_drive->drv_sel);
  3270. #endif
  3271. drvcmd[0]=CMD2_READ_VER;
  3272. response_count=12;
  3273. flags_cmd_out=f_putcmd;
  3274. i=cmd_out();
  3275. if (i<0) msg(DBG_INI,"CMD2_READ_VER returns %d\n",i);
  3276. if (i==-7) teac_possible++;
  3277. j=0;
  3278. for (i=0;i<12;i++) j+=infobuf[i];
  3279. if (j)
  3280. {
  3281. for (i=0;i<12;i++)
  3282. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  3283. msgbuf[i*3]=0;
  3284. msg(DBG_IDX,"infobuf =%s\n", msgbuf);
  3285. for (i=0;i<12;i++)
  3286. sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
  3287. msgbuf[i*3]=0;
  3288. msg(DBG_IDX,"infobuf =%s\n", msgbuf);
  3289. }
  3290. if (i>=0)
  3291. {
  3292. for (i=0;i<5;i++) if (infobuf[i]!=family2[i]) break;
  3293. if (i==5)
  3294. {
  3295. current_drive->drive_model[0]='C';
  3296. current_drive->drive_model[1]='D';
  3297. current_drive->drive_model[2]='2';
  3298. current_drive->drive_model[3]='0';
  3299. current_drive->drive_model[4]='0';
  3300. current_drive->drive_model[5]=infobuf[i++];
  3301. current_drive->drive_model[6]=infobuf[i++];
  3302. current_drive->drive_model[7]=0;
  3303. current_drive->drv_type=drv_fam2;
  3304. }
  3305. }
  3306. }
  3307. if (!current_drive->drv_type)
  3308. {
  3309. /* check for TEAC CD-55A */
  3310. msg(DBG_TEA,"teac_possible: %d\n",teac_possible);
  3311. for (j=1;j<=((current_drive->drv_id==0)?3:1);j++)
  3312. {
  3313. for (l=1;l<=((current_drive->drv_id==0)?10:1);l++)
  3314. {
  3315. msg(DBG_TEA,"TEAC reset #%d-%d.\n", j, l);
  3316. if (sbpro_type==1) OUT(CDo_reset,0);
  3317. else
  3318. {
  3319. OUT(CDo_enable,current_drive->drv_sel);
  3320. OUT(CDo_sel_i_d,0);
  3321. OUT(CDo_command,CMDT_RESET);
  3322. for (i=0;i<9;i++) OUT(CDo_command,0);
  3323. }
  3324. sbp_sleep(5*HZ/10);
  3325. OUT(CDo_enable,current_drive->drv_sel);
  3326. OUT(CDo_sel_i_d,0);
  3327. i=inb(CDi_status);
  3328. msg(DBG_TEA,"TEAC CDi_status: %02X.\n",i);
  3329. #if 0
  3330. if (i&s_not_result_ready) continue; /* drive not present or ready */
  3331. #endif
  3332. i=inb(CDi_info);
  3333. msg(DBG_TEA,"TEAC CDi_info: %02X.\n",i);
  3334. if (i==0x55) break; /* drive found */
  3335. }
  3336. if (i==0x55) break; /* drive found */
  3337. }
  3338. if (i==0x55) /* drive found */
  3339. {
  3340. msg(DBG_TEA,"TEAC drive found.\n");
  3341. clr_cmdbuf();
  3342. flags_cmd_out=f_putcmd;
  3343. response_count=12;
  3344. drvcmd[0]=CMDT_READ_VER;
  3345. drvcmd[4]=response_count;
  3346. for (i=0;i<12;i++) infobuf[i]=0;
  3347. i=cmd_out_T();
  3348. if (i!=0) msg(DBG_TEA,"cmd_out_T(CMDT_READ_VER) returns %d.\n",i);
  3349. for (i=1;i<6;i++) if (infobuf[i]!=familyT[i-1]) break;
  3350. if (i==6)
  3351. {
  3352. current_drive->drive_model[0]='C';
  3353. current_drive->drive_model[1]='D';
  3354. current_drive->drive_model[2]='-';
  3355. current_drive->drive_model[3]='5';
  3356. current_drive->drive_model[4]='5';
  3357. current_drive->drive_model[5]=0;
  3358. current_drive->drv_type=drv_famT;
  3359. }
  3360. }
  3361. }
  3362. if (!current_drive->drv_type)
  3363. {
  3364. msg(DBG_TEA,"no drive found at address %03X under ID %d.\n",CDo_command,current_drive->drv_id);
  3365. return (-522);
  3366. }
  3367. for (j=0;j<4;j++) current_drive->firmware_version[j]=infobuf[i+j];
  3368. if (famL_drive)
  3369. {
  3370. u_char lcs_firm_e1[]="A E1";
  3371. u_char lcs_firm_f4[]="A4F4";
  3372. for (j=0;j<4;j++)
  3373. if (current_drive->firmware_version[j]!=lcs_firm_e1[j]) break;
  3374. if (j==4) current_drive->drv_type=drv_e1;
  3375. for (j=0;j<4;j++)
  3376. if (current_drive->firmware_version[j]!=lcs_firm_f4[j]) break;
  3377. if (j==4) current_drive->drv_type=drv_f4;
  3378. if (current_drive->drv_type==drv_famL) ask_mail();
  3379. }
  3380. else if (famT_drive)
  3381. {
  3382. j=infobuf[4]; /* one-byte version??? - here: 0x15 */
  3383. if (j=='5')
  3384. {
  3385. current_drive->firmware_version[0]=infobuf[7];
  3386. current_drive->firmware_version[1]=infobuf[8];
  3387. current_drive->firmware_version[2]=infobuf[10];
  3388. current_drive->firmware_version[3]=infobuf[11];
  3389. }
  3390. else
  3391. {
  3392. if (j!=0x15) ask_mail();
  3393. current_drive->firmware_version[0]='0';
  3394. current_drive->firmware_version[1]='.';
  3395. current_drive->firmware_version[2]='0'+(j>>4);
  3396. current_drive->firmware_version[3]='0'+(j&0x0f);
  3397. }
  3398. }
  3399. else /* CR-52x, CR-56x, CD200, ECS-AT */
  3400. {
  3401. j = (current_drive->firmware_version[0] & 0x0F) * 100 +
  3402. (current_drive->firmware_version[2] & 0x0F) *10 +
  3403. (current_drive->firmware_version[3] & 0x0F);
  3404. if (fam0_drive)
  3405. {
  3406. if (j<200) current_drive->drv_type=drv_199;
  3407. else if (j<201) current_drive->drv_type=drv_200;
  3408. else if (j<210) current_drive->drv_type=drv_201;
  3409. else if (j<211) current_drive->drv_type=drv_210;
  3410. else if (j<300) current_drive->drv_type=drv_211;
  3411. else if (j>=300) current_drive->drv_type=drv_300;
  3412. }
  3413. else if (fam1_drive)
  3414. {
  3415. if (j<100) current_drive->drv_type=drv_099;
  3416. else
  3417. {
  3418. current_drive->drv_type=drv_100;
  3419. if ((j!=500)&&(j!=102)) ask_mail();
  3420. }
  3421. }
  3422. else if (fam2_drive)
  3423. {
  3424. if (current_drive->drive_model[5]=='F')
  3425. {
  3426. if ((j!=1)&&(j!=35)&&(j!=200)&&(j!=210))
  3427. ask_mail(); /* unknown version at time */
  3428. }
  3429. else
  3430. {
  3431. msg(DBG_INF,"this CD200 drive is not fully supported yet - only audio will work.\n");
  3432. if ((j!=101)&&(j!=35))
  3433. ask_mail(); /* unknown version at time */
  3434. }
  3435. }
  3436. else if (famV_drive)
  3437. {
  3438. if ((j==100)||(j==150)) current_drive->drv_type=drv_at;
  3439. ask_mail(); /* hopefully we get some feedback by this */
  3440. }
  3441. }
  3442. msg(DBG_LCS,"drive type %02X\n",current_drive->drv_type);
  3443. msg(DBG_INI,"check_version done.\n");
  3444. return (0);
  3445. }
  3446. /*==========================================================================*/
  3447. static void switch_drive(struct sbpcd_drive *p)
  3448. {
  3449. current_drive = p;
  3450. OUT(CDo_enable,current_drive->drv_sel);
  3451. msg(DBG_DID,"drive %d (ID=%d) activated.\n",
  3452. current_drive - D_S, current_drive->drv_id);
  3453. return;
  3454. }
  3455. /*==========================================================================*/
  3456. #ifdef PATH_CHECK
  3457. /*
  3458. * probe for the presence of an interface card
  3459. */
  3460. static int __init check_card(int port)
  3461. {
  3462. #undef N_RESPO
  3463. #define N_RESPO 20
  3464. int i, j, k;
  3465. u_char response[N_RESPO];
  3466. u_char save_port0;
  3467. u_char save_port3;
  3468. msg(DBG_INI,"check_card entered.\n");
  3469. save_port0=inb(port+0);
  3470. save_port3=inb(port+3);
  3471. for (j=0;j<NR_SBPCD;j++)
  3472. {
  3473. OUT(port+3,j) ; /* enable drive #j */
  3474. OUT(port+0,CMD0_PATH_CHECK);
  3475. for (i=10;i>0;i--) OUT(port+0,0);
  3476. for (k=0;k<N_RESPO;k++) response[k]=0;
  3477. for (k=0;k<N_RESPO;k++)
  3478. {
  3479. for (i=10000;i>0;i--)
  3480. {
  3481. if (inb(port+1)&s_not_result_ready) continue;
  3482. response[k]=inb(port+0);
  3483. break;
  3484. }
  3485. }
  3486. for (i=0;i<N_RESPO;i++)
  3487. sprintf(&msgbuf[i*3], " %02X", response[i]);
  3488. msgbuf[i*3]=0;
  3489. msg(DBG_TEA,"path check 00 (%d): %s\n", j, msgbuf);
  3490. OUT(port+0,CMD0_PATH_CHECK);
  3491. for (i=10;i>0;i--) OUT(port+0,0);
  3492. for (k=0;k<N_RESPO;k++) response[k]=0xFF;
  3493. for (k=0;k<N_RESPO;k++)
  3494. {
  3495. for (i=10000;i>0;i--)
  3496. {
  3497. if (inb(port+1)&s_not_result_ready) continue;
  3498. response[k]=inb(port+0);
  3499. break;
  3500. }
  3501. }
  3502. for (i=0;i<N_RESPO;i++)
  3503. sprintf(&msgbuf[i*3], " %02X", response[i]);
  3504. msgbuf[i*3]=0;
  3505. msg(DBG_TEA,"path check 00 (%d): %s\n", j, msgbuf);
  3506. if (response[0]==0xAA)
  3507. if (response[1]==0x55)
  3508. return (0);
  3509. }
  3510. for (j=0;j<NR_SBPCD;j++)
  3511. {
  3512. OUT(port+3,j) ; /* enable drive #j */
  3513. OUT(port+0,CMD2_READ_VER);
  3514. for (i=10;i>0;i--) OUT(port+0,0);
  3515. for (k=0;k<N_RESPO;k++) response[k]=0;
  3516. for (k=0;k<N_RESPO;k++)
  3517. {
  3518. for (i=1000000;i>0;i--)
  3519. {
  3520. if (inb(port+1)&s_not_result_ready) continue;
  3521. response[k]=inb(port+0);
  3522. break;
  3523. }
  3524. }
  3525. for (i=0;i<N_RESPO;i++)
  3526. sprintf(&msgbuf[i*3], " %02X", response[i]);
  3527. msgbuf[i*3]=0;
  3528. msg(DBG_TEA,"path check 12 (%d): %s\n", j, msgbuf);
  3529. OUT(port+0,CMD2_READ_VER);
  3530. for (i=10;i>0;i--) OUT(port+0,0);
  3531. for (k=0;k<N_RESPO;k++) response[k]=0xFF;
  3532. for (k=0;k<N_RESPO;k++)
  3533. {
  3534. for (i=1000000;i>0;i--)
  3535. {
  3536. if (inb(port+1)&s_not_result_ready) continue;
  3537. response[k]=inb(port+0);
  3538. break;
  3539. }
  3540. }
  3541. for (i=0;i<N_RESPO;i++)
  3542. sprintf(&msgbuf[i*3], " %02X", response[i]);
  3543. msgbuf[i*3]=0;
  3544. msg(DBG_TEA,"path check 12 (%d): %s\n", j, msgbuf);
  3545. if (response[0]==0xAA)
  3546. if (response[1]==0x55)
  3547. return (0);
  3548. }
  3549. OUT(port+0,save_port0);
  3550. OUT(port+3,save_port3);
  3551. return (0); /* in any case - no real "function" at time */
  3552. }
  3553. #endif /* PATH_CHECK */
  3554. /*==========================================================================*/
  3555. /*==========================================================================*/
  3556. /*
  3557. * probe for the presence of drives on the selected controller
  3558. */
  3559. static int __init check_drives(void)
  3560. {
  3561. int i, j;
  3562. msg(DBG_INI,"check_drives entered.\n");
  3563. ndrives=0;
  3564. for (j=0;j<max_drives;j++)
  3565. {
  3566. struct sbpcd_drive *p = D_S + ndrives;
  3567. p->drv_id=j;
  3568. if (sbpro_type==1) p->drv_sel=(j&0x01)<<1|(j&0x02)>>1;
  3569. else p->drv_sel=j;
  3570. switch_drive(p);
  3571. msg(DBG_INI,"check_drives: drive %d (ID=%d) activated.\n",ndrives,j);
  3572. msg(DBG_000,"check_drives: drive %d (ID=%d) activated.\n",ndrives,j);
  3573. i=check_version();
  3574. if (i<0) msg(DBG_INI,"check_version returns %d.\n",i);
  3575. else
  3576. {
  3577. current_drive->drv_options=drv_pattern[j];
  3578. if (fam0L_drive) current_drive->drv_options&=~(speed_auto|speed_300|speed_150);
  3579. msg(DBG_INF, "Drive %d (ID=%d): %.9s (%.4s) at 0x%03X (type %d)\n",
  3580. current_drive - D_S,
  3581. current_drive->drv_id,
  3582. current_drive->drive_model,
  3583. current_drive->firmware_version,
  3584. CDo_command,
  3585. sbpro_type);
  3586. ndrives++;
  3587. }
  3588. }
  3589. for (j=ndrives;j<NR_SBPCD;j++) D_S[j].drv_id=-1;
  3590. if (ndrives==0) return (-1);
  3591. return (0);
  3592. }
  3593. /*==========================================================================*/
  3594. #ifdef FUTURE
  3595. /*
  3596. * obtain if requested service disturbs current audio state
  3597. */
  3598. static int obey_audio_state(u_char audio_state, u_char func,u_char subfunc)
  3599. {
  3600. switch (audio_state) /* audio status from controller */
  3601. {
  3602. case aud_11: /* "audio play in progress" */
  3603. case audx11:
  3604. switch (func) /* DOS command code */
  3605. {
  3606. case cmd_07: /* input flush */
  3607. case cmd_0d: /* open device */
  3608. case cmd_0e: /* close device */
  3609. case cmd_0c: /* ioctl output */
  3610. return (1);
  3611. case cmd_03: /* ioctl input */
  3612. switch (subfunc)
  3613. /* DOS ioctl input subfunction */
  3614. {
  3615. case cxi_00:
  3616. case cxi_06:
  3617. case cxi_09:
  3618. return (1);
  3619. default:
  3620. return (ERROR15);
  3621. }
  3622. return (1);
  3623. default:
  3624. return (ERROR15);
  3625. }
  3626. return (1);
  3627. case aud_12: /* "audio play paused" */
  3628. case audx12:
  3629. return (1);
  3630. default:
  3631. return (2);
  3632. }
  3633. }
  3634. /*==========================================================================*/
  3635. /* allowed is only
  3636. * ioctl_o, flush_input, open_device, close_device,
  3637. * tell_address, tell_volume, tell_capabiliti,
  3638. * tell_framesize, tell_CD_changed, tell_audio_posi
  3639. */
  3640. static int check_allowed1(u_char func1, u_char func2)
  3641. {
  3642. #if 000
  3643. if (func1==ioctl_o) return (0);
  3644. if (func1==read_long) return (-1);
  3645. if (func1==read_long_prefetch) return (-1);
  3646. if (func1==seek) return (-1);
  3647. if (func1==audio_play) return (-1);
  3648. if (func1==audio_pause) return (-1);
  3649. if (func1==audio_resume) return (-1);
  3650. if (func1!=ioctl_i) return (0);
  3651. if (func2==tell_SubQ_run_tot) return (-1);
  3652. if (func2==tell_cdsize) return (-1);
  3653. if (func2==tell_TocDescrip) return (-1);
  3654. if (func2==tell_TocEntry) return (-1);
  3655. if (func2==tell_subQ_info) return (-1);
  3656. if (fam1_drive) if (func2==tell_SubChanInfo) return (-1);
  3657. if (func2==tell_UPC) return (-1);
  3658. #else
  3659. return (0);
  3660. #endif
  3661. }
  3662. /*==========================================================================*/
  3663. static int check_allowed2(u_char func1, u_char func2)
  3664. {
  3665. #if 000
  3666. if (func1==read_long) return (-1);
  3667. if (func1==read_long_prefetch) return (-1);
  3668. if (func1==seek) return (-1);
  3669. if (func1==audio_play) return (-1);
  3670. if (func1!=ioctl_o) return (0);
  3671. if (fam1_drive)
  3672. {
  3673. if (func2==EjectDisk) return (-1);
  3674. if (func2==CloseTray) return (-1);
  3675. }
  3676. #else
  3677. return (0);
  3678. #endif
  3679. }
  3680. /*==========================================================================*/
  3681. static int check_allowed3(u_char func1, u_char func2)
  3682. {
  3683. #if 000
  3684. if (func1==ioctl_i)
  3685. {
  3686. if (func2==tell_address) return (0);
  3687. if (func2==tell_capabiliti) return (0);
  3688. if (func2==tell_CD_changed) return (0);
  3689. if (fam0L_drive) if (func2==tell_SubChanInfo) return (0);
  3690. return (-1);
  3691. }
  3692. if (func1==ioctl_o)
  3693. {
  3694. if (func2==DriveReset) return (0);
  3695. if (fam0L_drive)
  3696. {
  3697. if (func2==EjectDisk) return (0);
  3698. if (func2==LockDoor) return (0);
  3699. if (func2==CloseTray) return (0);
  3700. }
  3701. return (-1);
  3702. }
  3703. if (func1==flush_input) return (-1);
  3704. if (func1==read_long) return (-1);
  3705. if (func1==read_long_prefetch) return (-1);
  3706. if (func1==seek) return (-1);
  3707. if (func1==audio_play) return (-1);
  3708. if (func1==audio_pause) return (-1);
  3709. if (func1==audio_resume) return (-1);
  3710. #else
  3711. return (0);
  3712. #endif
  3713. }
  3714. /*==========================================================================*/
  3715. static int seek_pos_audio_end(void)
  3716. {
  3717. int i;
  3718. i=msf2blk(current_drive->pos_audio_end)-1;
  3719. if (i<0) return (-1);
  3720. i=cc_Seek(i,0);
  3721. return (i);
  3722. }
  3723. #endif /* FUTURE */
  3724. /*==========================================================================*/
  3725. static int ReadToC(void)
  3726. {
  3727. int i, j;
  3728. current_drive->diskstate_flags &= ~toc_bit;
  3729. current_drive->ored_ctl_adr=0;
  3730. /* special handling of CD-I HE */
  3731. if ((current_drive->n_first_track == 2 && current_drive->n_last_track == 2) ||
  3732. current_drive->xa_byte == 0x10)
  3733. {
  3734. current_drive->TocBuffer[1].nixbyte=0;
  3735. current_drive->TocBuffer[1].ctl_adr=0x40;
  3736. current_drive->TocBuffer[1].number=1;
  3737. current_drive->TocBuffer[1].format=0;
  3738. current_drive->TocBuffer[1].address=blk2msf(0);
  3739. current_drive->ored_ctl_adr |= 0x40;
  3740. current_drive->n_first_track = 1;
  3741. current_drive->n_last_track = 1;
  3742. current_drive->xa_byte = 0x10;
  3743. j = 2;
  3744. } else
  3745. for (j=current_drive->n_first_track;j<=current_drive->n_last_track;j++)
  3746. {
  3747. i=cc_ReadTocEntry(j);
  3748. if (i<0)
  3749. {
  3750. msg(DBG_INF,"cc_ReadTocEntry(%d) returns %d.\n",j,i);
  3751. return (i);
  3752. }
  3753. current_drive->TocBuffer[j].nixbyte=current_drive->TocEnt_nixbyte;
  3754. current_drive->TocBuffer[j].ctl_adr=current_drive->TocEnt_ctl_adr;
  3755. current_drive->TocBuffer[j].number=current_drive->TocEnt_number;
  3756. current_drive->TocBuffer[j].format=current_drive->TocEnt_format;
  3757. current_drive->TocBuffer[j].address=current_drive->TocEnt_address;
  3758. current_drive->ored_ctl_adr |= current_drive->TocEnt_ctl_adr;
  3759. }
  3760. /* fake entry for LeadOut Track */
  3761. current_drive->TocBuffer[j].nixbyte=0;
  3762. current_drive->TocBuffer[j].ctl_adr=0;
  3763. current_drive->TocBuffer[j].number=CDROM_LEADOUT;
  3764. current_drive->TocBuffer[j].format=0;
  3765. current_drive->TocBuffer[j].address=current_drive->size_msf;
  3766. current_drive->diskstate_flags |= toc_bit;
  3767. return (0);
  3768. }
  3769. /*==========================================================================*/
  3770. static int DiskInfo(void)
  3771. {
  3772. int i, j;
  3773. current_drive->mode=READ_M1;
  3774. #undef LOOP_COUNT
  3775. #define LOOP_COUNT 10 /* needed for some "old" drives */
  3776. msg(DBG_000,"DiskInfo entered.\n");
  3777. for (j=1;j<LOOP_COUNT;j++)
  3778. {
  3779. #if 0
  3780. i=SetSpeed();
  3781. if (i<0)
  3782. {
  3783. msg(DBG_INF,"DiskInfo: SetSpeed returns %d\n", i);
  3784. continue;
  3785. }
  3786. i=cc_ModeSense();
  3787. if (i<0)
  3788. {
  3789. msg(DBG_INF,"DiskInfo: cc_ModeSense returns %d\n", i);
  3790. continue;
  3791. }
  3792. #endif
  3793. i=cc_ReadCapacity();
  3794. if (i>=0) break;
  3795. msg(DBG_INF,"DiskInfo: ReadCapacity #%d returns %d\n", j, i);
  3796. #if 0
  3797. i=cc_DriveReset();
  3798. #endif
  3799. if (!fam0_drive && j == 2) break;
  3800. }
  3801. if (j==LOOP_COUNT) return (-33); /* give up */
  3802. i=cc_ReadTocDescr();
  3803. if (i<0)
  3804. {
  3805. msg(DBG_INF,"DiskInfo: ReadTocDescr returns %d\n", i);
  3806. return (i);
  3807. }
  3808. i=ReadToC();
  3809. if (i<0)
  3810. {
  3811. msg(DBG_INF,"DiskInfo: ReadToC returns %d\n", i);
  3812. return (i);
  3813. }
  3814. i=cc_CheckMultiSession();
  3815. if (i<0)
  3816. {
  3817. msg(DBG_INF,"DiskInfo: cc_CheckMultiSession returns %d\n", i);
  3818. return (i);
  3819. }
  3820. if (current_drive->f_multisession) current_drive->sbp_bufsiz=1; /* possibly a weird PhotoCD */
  3821. else current_drive->sbp_bufsiz=buffers;
  3822. i=cc_ReadTocEntry(current_drive->n_first_track);
  3823. if (i<0)
  3824. {
  3825. msg(DBG_INF,"DiskInfo: cc_ReadTocEntry(1) returns %d\n", i);
  3826. return (i);
  3827. }
  3828. i=cc_ReadUPC();
  3829. if (i<0) msg(DBG_INF,"DiskInfo: cc_ReadUPC returns %d\n", i);
  3830. if ((fam0L_drive) && (current_drive->xa_byte==0x20 || current_drive->xa_byte == 0x10))
  3831. {
  3832. /* XA disk with old drive */
  3833. cc_ModeSelect(CD_FRAMESIZE_RAW1);
  3834. cc_ModeSense();
  3835. }
  3836. if (famT_drive) cc_prep_mode_T();
  3837. msg(DBG_000,"DiskInfo done.\n");
  3838. return (0);
  3839. }
  3840. static int sbpcd_drive_status(struct cdrom_device_info *cdi, int slot_nr)
  3841. {
  3842. struct sbpcd_drive *p = cdi->handle;
  3843. int st;
  3844. if (CDSL_CURRENT != slot_nr) {
  3845. /* we have no changer support */
  3846. return -EINVAL;
  3847. }
  3848. cc_ReadStatus();
  3849. st=ResponseStatus();
  3850. if (st<0)
  3851. {
  3852. msg(DBG_INF,"sbpcd_drive_status: timeout.\n");
  3853. return (0);
  3854. }
  3855. msg(DBG_000,"Drive Status: door_locked =%d.\n", st_door_locked);
  3856. msg(DBG_000,"Drive Status: door_closed =%d.\n", st_door_closed);
  3857. msg(DBG_000,"Drive Status: caddy_in =%d.\n", st_caddy_in);
  3858. msg(DBG_000,"Drive Status: disk_ok =%d.\n", st_diskok);
  3859. msg(DBG_000,"Drive Status: spinning =%d.\n", st_spinning);
  3860. msg(DBG_000,"Drive Status: busy =%d.\n", st_busy);
  3861. #if 0
  3862. if (!(p->status_bits & p_door_closed)) return CDS_TRAY_OPEN;
  3863. if (p->status_bits & p_disk_ok) return CDS_DISC_OK;
  3864. if (p->status_bits & p_disk_in) return CDS_DRIVE_NOT_READY;
  3865. return CDS_NO_DISC;
  3866. #else
  3867. if (p->status_bits & p_spinning) return CDS_DISC_OK;
  3868. /* return CDS_TRAY_OPEN; */
  3869. return CDS_NO_DISC;
  3870. #endif
  3871. }
  3872. /*==========================================================================*/
  3873. #ifdef FUTURE
  3874. /*
  3875. * called always if driver gets entered
  3876. * returns 0 or ERROR2 or ERROR15
  3877. */
  3878. static int prepare(u_char func, u_char subfunc)
  3879. {
  3880. int i;
  3881. if (fam0L_drive)
  3882. {
  3883. i=inb(CDi_status);
  3884. if (i&s_attention) GetStatus();
  3885. }
  3886. else if (fam1_drive) GetStatus();
  3887. else if (fam2_drive) GetStatus();
  3888. else if (famT_drive) GetStatus();
  3889. if (current_drive->CD_changed==0xFF)
  3890. {
  3891. current_drive->diskstate_flags=0;
  3892. current_drive->audio_state=0;
  3893. if (!st_diskok)
  3894. {
  3895. i=check_allowed1(func,subfunc);
  3896. if (i<0) return (-2);
  3897. }
  3898. else
  3899. {
  3900. i=check_allowed3(func,subfunc);
  3901. if (i<0)
  3902. {
  3903. current_drive->CD_changed=1;
  3904. return (-15);
  3905. }
  3906. }
  3907. }
  3908. else
  3909. {
  3910. if (!st_diskok)
  3911. {
  3912. current_drive->diskstate_flags=0;
  3913. current_drive->audio_state=0;
  3914. i=check_allowed1(func,subfunc);
  3915. if (i<0) return (-2);
  3916. }
  3917. else
  3918. {
  3919. if (st_busy)
  3920. {
  3921. if (current_drive->audio_state!=audio_pausing)
  3922. {
  3923. i=check_allowed2(func,subfunc);
  3924. if (i<0) return (-2);
  3925. }
  3926. }
  3927. else
  3928. {
  3929. if (current_drive->audio_state==audio_playing) seek_pos_audio_end();
  3930. current_drive->audio_state=0;
  3931. }
  3932. if (!frame_size_valid)
  3933. {
  3934. i=DiskInfo();
  3935. if (i<0)
  3936. {
  3937. current_drive->diskstate_flags=0;
  3938. current_drive->audio_state=0;
  3939. i=check_allowed1(func,subfunc);
  3940. if (i<0) return (-2);
  3941. }
  3942. }
  3943. }
  3944. }
  3945. return (0);
  3946. }
  3947. #endif /* FUTURE */
  3948. /*==========================================================================*/
  3949. /*==========================================================================*/
  3950. /*
  3951. * Check the results of the "get status" command.
  3952. */
  3953. static int sbp_status(void)
  3954. {
  3955. int st;
  3956. st=ResponseStatus();
  3957. if (st<0)
  3958. {
  3959. msg(DBG_INF,"sbp_status: timeout.\n");
  3960. return (0);
  3961. }
  3962. if (!st_spinning) msg(DBG_SPI,"motor got off - ignoring.\n");
  3963. if (st_check)
  3964. {
  3965. msg(DBG_INF,"st_check detected - retrying.\n");
  3966. return (0);
  3967. }
  3968. if (!st_door_closed)
  3969. {
  3970. msg(DBG_INF,"door is open - retrying.\n");
  3971. return (0);
  3972. }
  3973. if (!st_caddy_in)
  3974. {
  3975. msg(DBG_INF,"disk removed - retrying.\n");
  3976. return (0);
  3977. }
  3978. if (!st_diskok)
  3979. {
  3980. msg(DBG_INF,"!st_diskok detected - retrying.\n");
  3981. return (0);
  3982. }
  3983. if (st_busy)
  3984. {
  3985. msg(DBG_INF,"st_busy detected - retrying.\n");
  3986. return (0);
  3987. }
  3988. return (1);
  3989. }
  3990. /*==========================================================================*/
  3991. static int sbpcd_get_last_session(struct cdrom_device_info *cdi, struct cdrom_multisession *ms_infp)
  3992. {
  3993. struct sbpcd_drive *p = cdi->handle;
  3994. ms_infp->addr_format = CDROM_LBA;
  3995. ms_infp->addr.lba = p->lba_multi;
  3996. if (p->f_multisession)
  3997. ms_infp->xa_flag=1; /* valid redirection address */
  3998. else
  3999. ms_infp->xa_flag=0; /* invalid redirection address */
  4000. return 0;
  4001. }
  4002. static int sbpcd_audio_ioctl(struct cdrom_device_info *cdi, u_int cmd,
  4003. void * arg)
  4004. {
  4005. struct sbpcd_drive *p = cdi->handle;
  4006. int i, st, j;
  4007. msg(DBG_IO2,"ioctl(%s, 0x%08lX, 0x%08p)\n", cdi->name, cmd, arg);
  4008. if (p->drv_id==-1) {
  4009. msg(DBG_INF, "ioctl: bad device: %s\n", cdi->name);
  4010. return (-ENXIO); /* no such drive */
  4011. }
  4012. down(&ioctl_read_sem);
  4013. if (p != current_drive)
  4014. switch_drive(p);
  4015. msg(DBG_IO2,"ioctl: device %s, request %04X\n",cdi->name,cmd);
  4016. switch (cmd) /* Sun-compatible */
  4017. {
  4018. case CDROMPAUSE: /* Pause the drive */
  4019. msg(DBG_IOC,"ioctl: CDROMPAUSE entered.\n");
  4020. /* pause the drive unit when it is currently in PLAY mode, */
  4021. /* or reset the starting and ending locations when in PAUSED mode. */
  4022. /* If applicable, at the next stopping point it reaches */
  4023. /* the drive will discontinue playing. */
  4024. switch (current_drive->audio_state)
  4025. {
  4026. case audio_playing:
  4027. if (famL_drive) i=cc_ReadSubQ();
  4028. else i=cc_Pause_Resume(1);
  4029. if (i<0) RETURN_UP(-EIO);
  4030. if (famL_drive) i=cc_Pause_Resume(1);
  4031. else i=cc_ReadSubQ();
  4032. if (i<0) RETURN_UP(-EIO);
  4033. current_drive->pos_audio_start=current_drive->SubQ_run_tot;
  4034. current_drive->audio_state=audio_pausing;
  4035. RETURN_UP(0);
  4036. case audio_pausing:
  4037. i=cc_Seek(current_drive->pos_audio_start,1);
  4038. if (i<0) RETURN_UP(-EIO);
  4039. RETURN_UP(0);
  4040. default:
  4041. RETURN_UP(-EINVAL);
  4042. }
  4043. case CDROMRESUME: /* resume paused audio play */
  4044. msg(DBG_IOC,"ioctl: CDROMRESUME entered.\n");
  4045. /* resume playing audio tracks when a previous PLAY AUDIO call has */
  4046. /* been paused with a PAUSE command. */
  4047. /* It will resume playing from the location saved in SubQ_run_tot. */
  4048. if (current_drive->audio_state!=audio_pausing) RETURN_UP(-EINVAL);
  4049. if (famL_drive)
  4050. i=cc_PlayAudio(current_drive->pos_audio_start,
  4051. current_drive->pos_audio_end);
  4052. else i=cc_Pause_Resume(3);
  4053. if (i<0) RETURN_UP(-EIO);
  4054. current_drive->audio_state=audio_playing;
  4055. RETURN_UP(0);
  4056. case CDROMPLAYMSF:
  4057. msg(DBG_IOC,"ioctl: CDROMPLAYMSF entered.\n");
  4058. #ifdef SAFE_MIXED
  4059. if (current_drive->has_data>1) RETURN_UP(-EBUSY);
  4060. #endif /* SAFE_MIXED */
  4061. if (current_drive->audio_state==audio_playing)
  4062. {
  4063. i=cc_Pause_Resume(1);
  4064. if (i<0) RETURN_UP(-EIO);
  4065. i=cc_ReadSubQ();
  4066. if (i<0) RETURN_UP(-EIO);
  4067. current_drive->pos_audio_start=current_drive->SubQ_run_tot;
  4068. i=cc_Seek(current_drive->pos_audio_start,1);
  4069. }
  4070. memcpy(&msf, (void *) arg, sizeof(struct cdrom_msf));
  4071. /* values come as msf-bin */
  4072. current_drive->pos_audio_start = (msf.cdmsf_min0<<16) |
  4073. (msf.cdmsf_sec0<<8) |
  4074. msf.cdmsf_frame0;
  4075. current_drive->pos_audio_end = (msf.cdmsf_min1<<16) |
  4076. (msf.cdmsf_sec1<<8) |
  4077. msf.cdmsf_frame1;
  4078. msg(DBG_IOX,"ioctl: CDROMPLAYMSF %08X %08X\n",
  4079. current_drive->pos_audio_start,current_drive->pos_audio_end);
  4080. i=cc_PlayAudio(current_drive->pos_audio_start,current_drive->pos_audio_end);
  4081. if (i<0)
  4082. {
  4083. msg(DBG_INF,"ioctl: cc_PlayAudio returns %d\n",i);
  4084. DriveReset();
  4085. current_drive->audio_state=0;
  4086. RETURN_UP(-EIO);
  4087. }
  4088. current_drive->audio_state=audio_playing;
  4089. RETURN_UP(0);
  4090. case CDROMPLAYTRKIND: /* Play a track. This currently ignores index. */
  4091. msg(DBG_IOC,"ioctl: CDROMPLAYTRKIND entered.\n");
  4092. #ifdef SAFE_MIXED
  4093. if (current_drive->has_data>1) RETURN_UP(-EBUSY);
  4094. #endif /* SAFE_MIXED */
  4095. if (current_drive->audio_state==audio_playing)
  4096. {
  4097. msg(DBG_IOX,"CDROMPLAYTRKIND: already audio_playing.\n");
  4098. #if 1
  4099. RETURN_UP(0); /* just let us play on */
  4100. #else
  4101. RETURN_UP(-EINVAL); /* play on, but say "error" */
  4102. #endif
  4103. }
  4104. memcpy(&ti,(void *) arg,sizeof(struct cdrom_ti));
  4105. msg(DBG_IOX,"ioctl: trk0: %d, ind0: %d, trk1:%d, ind1:%d\n",
  4106. ti.cdti_trk0,ti.cdti_ind0,ti.cdti_trk1,ti.cdti_ind1);
  4107. if (ti.cdti_trk0<current_drive->n_first_track) RETURN_UP(-EINVAL);
  4108. if (ti.cdti_trk0>current_drive->n_last_track) RETURN_UP(-EINVAL);
  4109. if (ti.cdti_trk1<ti.cdti_trk0) ti.cdti_trk1=ti.cdti_trk0;
  4110. if (ti.cdti_trk1>current_drive->n_last_track) ti.cdti_trk1=current_drive->n_last_track;
  4111. current_drive->pos_audio_start=current_drive->TocBuffer[ti.cdti_trk0].address;
  4112. current_drive->pos_audio_end=current_drive->TocBuffer[ti.cdti_trk1+1].address;
  4113. i=cc_PlayAudio(current_drive->pos_audio_start,current_drive->pos_audio_end);
  4114. if (i<0)
  4115. {
  4116. msg(DBG_INF,"ioctl: cc_PlayAudio returns %d\n",i);
  4117. DriveReset();
  4118. current_drive->audio_state=0;
  4119. RETURN_UP(-EIO);
  4120. }
  4121. current_drive->audio_state=audio_playing;
  4122. RETURN_UP(0);
  4123. case CDROMREADTOCHDR: /* Read the table of contents header */
  4124. msg(DBG_IOC,"ioctl: CDROMREADTOCHDR entered.\n");
  4125. tochdr.cdth_trk0=current_drive->n_first_track;
  4126. tochdr.cdth_trk1=current_drive->n_last_track;
  4127. memcpy((void *) arg, &tochdr, sizeof(struct cdrom_tochdr));
  4128. RETURN_UP(0);
  4129. case CDROMREADTOCENTRY: /* Read an entry in the table of contents */
  4130. msg(DBG_IOC,"ioctl: CDROMREADTOCENTRY entered.\n");
  4131. memcpy(&tocentry, (void *) arg, sizeof(struct cdrom_tocentry));
  4132. i=tocentry.cdte_track;
  4133. if (i==CDROM_LEADOUT) i=current_drive->n_last_track+1;
  4134. else if (i<current_drive->n_first_track||i>current_drive->n_last_track)
  4135. RETURN_UP(-EINVAL);
  4136. tocentry.cdte_adr=current_drive->TocBuffer[i].ctl_adr&0x0F;
  4137. tocentry.cdte_ctrl=(current_drive->TocBuffer[i].ctl_adr>>4)&0x0F;
  4138. tocentry.cdte_datamode=current_drive->TocBuffer[i].format;
  4139. if (tocentry.cdte_format==CDROM_MSF) /* MSF-bin required */
  4140. {
  4141. tocentry.cdte_addr.msf.minute=(current_drive->TocBuffer[i].address>>16)&0x00FF;
  4142. tocentry.cdte_addr.msf.second=(current_drive->TocBuffer[i].address>>8)&0x00FF;
  4143. tocentry.cdte_addr.msf.frame=current_drive->TocBuffer[i].address&0x00FF;
  4144. }
  4145. else if (tocentry.cdte_format==CDROM_LBA) /* blk required */
  4146. tocentry.cdte_addr.lba=msf2blk(current_drive->TocBuffer[i].address);
  4147. else RETURN_UP(-EINVAL);
  4148. memcpy((void *) arg, &tocentry, sizeof(struct cdrom_tocentry));
  4149. RETURN_UP(0);
  4150. case CDROMSTOP: /* Spin down the drive */
  4151. msg(DBG_IOC,"ioctl: CDROMSTOP entered.\n");
  4152. #ifdef SAFE_MIXED
  4153. if (current_drive->has_data>1) RETURN_UP(-EBUSY);
  4154. #endif /* SAFE_MIXED */
  4155. i=cc_Pause_Resume(1);
  4156. current_drive->audio_state=0;
  4157. #if 0
  4158. cc_DriveReset();
  4159. #endif
  4160. RETURN_UP(i);
  4161. case CDROMSTART: /* Spin up the drive */
  4162. msg(DBG_IOC,"ioctl: CDROMSTART entered.\n");
  4163. cc_SpinUp();
  4164. current_drive->audio_state=0;
  4165. RETURN_UP(0);
  4166. case CDROMVOLCTRL: /* Volume control */
  4167. msg(DBG_IOC,"ioctl: CDROMVOLCTRL entered.\n");
  4168. memcpy(&volctrl,(char *) arg,sizeof(volctrl));
  4169. current_drive->vol_chan0=0;
  4170. current_drive->vol_ctrl0=volctrl.channel0;
  4171. current_drive->vol_chan1=1;
  4172. current_drive->vol_ctrl1=volctrl.channel1;
  4173. i=cc_SetVolume();
  4174. RETURN_UP(0);
  4175. case CDROMVOLREAD: /* read Volume settings from drive */
  4176. msg(DBG_IOC,"ioctl: CDROMVOLREAD entered.\n");
  4177. st=cc_GetVolume();
  4178. if (st<0) RETURN_UP(st);
  4179. volctrl.channel0=current_drive->vol_ctrl0;
  4180. volctrl.channel1=current_drive->vol_ctrl1;
  4181. volctrl.channel2=0;
  4182. volctrl.channel2=0;
  4183. memcpy((void *)arg,&volctrl,sizeof(volctrl));
  4184. RETURN_UP(0);
  4185. case CDROMSUBCHNL: /* Get subchannel info */
  4186. msg(DBG_IOS,"ioctl: CDROMSUBCHNL entered.\n");
  4187. /* Bogus, I can do better than this! --AJK
  4188. if ((st_spinning)||(!subq_valid)) {
  4189. i=cc_ReadSubQ();
  4190. if (i<0) RETURN_UP(-EIO);
  4191. }
  4192. */
  4193. i=cc_ReadSubQ();
  4194. if (i<0) {
  4195. j=cc_ReadError(); /* clear out error status from drive */
  4196. current_drive->audio_state=CDROM_AUDIO_NO_STATUS;
  4197. /* get and set the disk state here,
  4198. probably not the right place, but who cares!
  4199. It makes it work properly! --AJK */
  4200. if (current_drive->CD_changed==0xFF) {
  4201. msg(DBG_000,"Disk changed detect\n");
  4202. current_drive->diskstate_flags &= ~cd_size_bit;
  4203. }
  4204. RETURN_UP(-EIO);
  4205. }
  4206. if (current_drive->CD_changed==0xFF) {
  4207. /* reread the TOC because the disk has changed! --AJK */
  4208. msg(DBG_000,"Disk changed STILL detected, rereading TOC!\n");
  4209. i=DiskInfo();
  4210. if(i==0) {
  4211. current_drive->CD_changed=0x00; /* cd has changed, procede, */
  4212. RETURN_UP(-EIO); /* and get TOC, etc on next try! --AJK */
  4213. } else {
  4214. RETURN_UP(-EIO); /* we weren't ready yet! --AJK */
  4215. }
  4216. }
  4217. memcpy(&SC, (void *) arg, sizeof(struct cdrom_subchnl));
  4218. /*
  4219. This virtual crap is very bogus!
  4220. It doesn't detect when the cd is done playing audio!
  4221. Lets do this right with proper hardware register reading!
  4222. */
  4223. cc_ReadStatus();
  4224. i=ResponseStatus();
  4225. msg(DBG_000,"Drive Status: door_locked =%d.\n", st_door_locked);
  4226. msg(DBG_000,"Drive Status: door_closed =%d.\n", st_door_closed);
  4227. msg(DBG_000,"Drive Status: caddy_in =%d.\n", st_caddy_in);
  4228. msg(DBG_000,"Drive Status: disk_ok =%d.\n", st_diskok);
  4229. msg(DBG_000,"Drive Status: spinning =%d.\n", st_spinning);
  4230. msg(DBG_000,"Drive Status: busy =%d.\n", st_busy);
  4231. /* st_busy indicates if it's _ACTUALLY_ playing audio */
  4232. switch (current_drive->audio_state)
  4233. {
  4234. case audio_playing:
  4235. if(st_busy==0) {
  4236. /* CD has stopped playing audio --AJK */
  4237. current_drive->audio_state=audio_completed;
  4238. SC.cdsc_audiostatus=CDROM_AUDIO_COMPLETED;
  4239. } else {
  4240. SC.cdsc_audiostatus=CDROM_AUDIO_PLAY;
  4241. }
  4242. break;
  4243. case audio_pausing:
  4244. SC.cdsc_audiostatus=CDROM_AUDIO_PAUSED;
  4245. break;
  4246. case audio_completed:
  4247. SC.cdsc_audiostatus=CDROM_AUDIO_COMPLETED;
  4248. break;
  4249. default:
  4250. SC.cdsc_audiostatus=CDROM_AUDIO_NO_STATUS;
  4251. break;
  4252. }
  4253. SC.cdsc_adr=current_drive->SubQ_ctl_adr;
  4254. SC.cdsc_ctrl=current_drive->SubQ_ctl_adr>>4;
  4255. SC.cdsc_trk=bcd2bin(current_drive->SubQ_trk);
  4256. SC.cdsc_ind=bcd2bin(current_drive->SubQ_pnt_idx);
  4257. if (SC.cdsc_format==CDROM_LBA)
  4258. {
  4259. SC.cdsc_absaddr.lba=msf2blk(current_drive->SubQ_run_tot);
  4260. SC.cdsc_reladdr.lba=msf2blk(current_drive->SubQ_run_trk);
  4261. }
  4262. else /* not only if (SC.cdsc_format==CDROM_MSF) */
  4263. {
  4264. SC.cdsc_absaddr.msf.minute=(current_drive->SubQ_run_tot>>16)&0x00FF;
  4265. SC.cdsc_absaddr.msf.second=(current_drive->SubQ_run_tot>>8)&0x00FF;
  4266. SC.cdsc_absaddr.msf.frame=current_drive->SubQ_run_tot&0x00FF;
  4267. SC.cdsc_reladdr.msf.minute=(current_drive->SubQ_run_trk>>16)&0x00FF;
  4268. SC.cdsc_reladdr.msf.second=(current_drive->SubQ_run_trk>>8)&0x00FF;
  4269. SC.cdsc_reladdr.msf.frame=current_drive->SubQ_run_trk&0x00FF;
  4270. }
  4271. memcpy((void *) arg, &SC, sizeof(struct cdrom_subchnl));
  4272. msg(DBG_IOS,"CDROMSUBCHNL: %1X %02X %08X %08X %02X %02X %06X %06X\n",
  4273. SC.cdsc_format,SC.cdsc_audiostatus,
  4274. SC.cdsc_adr,SC.cdsc_ctrl,
  4275. SC.cdsc_trk,SC.cdsc_ind,
  4276. SC.cdsc_absaddr,SC.cdsc_reladdr);
  4277. RETURN_UP(0);
  4278. default:
  4279. msg(DBG_IOC,"ioctl: unknown function request %04X\n", cmd);
  4280. RETURN_UP(-EINVAL);
  4281. } /* end switch(cmd) */
  4282. }
  4283. /*==========================================================================*/
  4284. /*
  4285. * Take care of the different block sizes between cdrom and Linux.
  4286. */
  4287. static void sbp_transfer(struct request *req)
  4288. {
  4289. long offs;
  4290. while ( (req->nr_sectors > 0) &&
  4291. (req->sector/4 >= current_drive->sbp_first_frame) &&
  4292. (req->sector/4 <= current_drive->sbp_last_frame) )
  4293. {
  4294. offs = (req->sector - current_drive->sbp_first_frame * 4) * 512;
  4295. memcpy(req->buffer, current_drive->sbp_buf + offs, 512);
  4296. req->nr_sectors--;
  4297. req->sector++;
  4298. req->buffer += 512;
  4299. }
  4300. }
  4301. /*==========================================================================*/
  4302. /*
  4303. * special end_request for sbpcd to solve CURRENT==NULL bug. (GTL)
  4304. * GTL = Gonzalo Tornaria <tornaria@cmat.edu.uy>
  4305. *
  4306. * This is a kludge so we don't need to modify end_request.
  4307. * We put the req we take out after INIT_REQUEST in the requests list,
  4308. * so that end_request will discard it.
  4309. *
  4310. * The bug could be present in other block devices, perhaps we
  4311. * should modify INIT_REQUEST and end_request instead, and
  4312. * change every block device..
  4313. *
  4314. * Could be a race here?? Could e.g. a timer interrupt schedule() us?
  4315. * If so, we should copy end_request here, and do it right.. (or
  4316. * modify end_request and the block devices).
  4317. *
  4318. * In any case, the race here would be much small than it was, and
  4319. * I couldn't reproduce..
  4320. *
  4321. * The race could be: suppose CURRENT==NULL. We put our req in the list,
  4322. * and we are scheduled. Other process takes over, and gets into
  4323. * do_sbpcd_request. It sees CURRENT!=NULL (it is == to our req), so
  4324. * proceeds. It ends, so CURRENT is now NULL.. Now we awake somewhere in
  4325. * end_request, but now CURRENT==NULL... oops!
  4326. *
  4327. */
  4328. #undef DEBUG_GTL
  4329. /*==========================================================================*/
  4330. /*
  4331. * I/O request routine, called from Linux kernel.
  4332. */
  4333. static void do_sbpcd_request(request_queue_t * q)
  4334. {
  4335. u_int block;
  4336. u_int nsect;
  4337. int status_tries, data_tries;
  4338. struct request *req;
  4339. struct sbpcd_drive *p;
  4340. #ifdef DEBUG_GTL
  4341. static int xx_nr=0;
  4342. int xnr;
  4343. #endif
  4344. request_loop:
  4345. #ifdef DEBUG_GTL
  4346. xnr=++xx_nr;
  4347. req = elv_next_request(q);
  4348. if (!req)
  4349. {
  4350. printk( "do_sbpcd_request[%di](NULL), Pid:%d, Time:%li\n",
  4351. xnr, current->pid, jiffies);
  4352. printk( "do_sbpcd_request[%do](NULL) end 0 (null), Time:%li\n",
  4353. xnr, jiffies);
  4354. return;
  4355. }
  4356. printk(" do_sbpcd_request[%di](%p:%ld+%ld), Pid:%d, Time:%li\n",
  4357. xnr, req, req->sector, req->nr_sectors, current->pid, jiffies);
  4358. #endif
  4359. req = elv_next_request(q); /* take out our request so no other */
  4360. if (!req)
  4361. return;
  4362. if (req -> sector == -1)
  4363. end_request(req, 0);
  4364. spin_unlock_irq(q->queue_lock);
  4365. down(&ioctl_read_sem);
  4366. if (rq_data_dir(elv_next_request(q)) != READ)
  4367. {
  4368. msg(DBG_INF, "bad cmd %d\n", req->cmd[0]);
  4369. goto err_done;
  4370. }
  4371. p = req->rq_disk->private_data;
  4372. #if OLD_BUSY
  4373. while (busy_audio) sbp_sleep(HZ); /* wait a bit */
  4374. busy_data=1;
  4375. #endif /* OLD_BUSY */
  4376. if (p->audio_state==audio_playing) goto err_done;
  4377. if (p != current_drive)
  4378. switch_drive(p);
  4379. block = req->sector; /* always numbered as 512-byte-pieces */
  4380. nsect = req->nr_sectors; /* always counted as 512-byte-pieces */
  4381. msg(DBG_BSZ,"read sector %d (%d sectors)\n", block, nsect);
  4382. #if 0
  4383. msg(DBG_MUL,"read LBA %d\n", block/4);
  4384. #endif
  4385. sbp_transfer(req);
  4386. /* if we satisfied the request from the buffer, we're done. */
  4387. if (req->nr_sectors == 0)
  4388. {
  4389. #ifdef DEBUG_GTL
  4390. printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 2, Time:%li\n",
  4391. xnr, req, req->sector, req->nr_sectors, jiffies);
  4392. #endif
  4393. up(&ioctl_read_sem);
  4394. spin_lock_irq(q->queue_lock);
  4395. end_request(req, 1);
  4396. goto request_loop;
  4397. }
  4398. #ifdef FUTURE
  4399. i=prepare(0,0); /* at moment not really a hassle check, but ... */
  4400. if (i!=0)
  4401. msg(DBG_INF,"\"prepare\" tells error %d -- ignored\n", i);
  4402. #endif /* FUTURE */
  4403. if (!st_spinning) cc_SpinUp();
  4404. for (data_tries=n_retries; data_tries > 0; data_tries--)
  4405. {
  4406. for (status_tries=3; status_tries > 0; status_tries--)
  4407. {
  4408. flags_cmd_out |= f_respo3;
  4409. cc_ReadStatus();
  4410. if (sbp_status() != 0) break;
  4411. if (st_check) cc_ReadError();
  4412. sbp_sleep(1); /* wait a bit, try again */
  4413. }
  4414. if (status_tries == 0)
  4415. {
  4416. msg(DBG_INF,"sbp_status: failed after 3 tries in line %d\n", __LINE__);
  4417. break;
  4418. }
  4419. sbp_read_cmd(req);
  4420. sbp_sleep(0);
  4421. if (sbp_data(req) != 0)
  4422. {
  4423. #ifdef SAFE_MIXED
  4424. current_drive->has_data=2; /* is really a data disk */
  4425. #endif /* SAFE_MIXED */
  4426. #ifdef DEBUG_GTL
  4427. printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 3, Time:%li\n",
  4428. xnr, req, req->sector, req->nr_sectors, jiffies);
  4429. #endif
  4430. up(&ioctl_read_sem);
  4431. spin_lock_irq(q->queue_lock);
  4432. end_request(req, 1);
  4433. goto request_loop;
  4434. }
  4435. }
  4436. err_done:
  4437. #if OLD_BUSY
  4438. busy_data=0;
  4439. #endif /* OLD_BUSY */
  4440. #ifdef DEBUG_GTL
  4441. printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 4 (error), Time:%li\n",
  4442. xnr, req, req->sector, req->nr_sectors, jiffies);
  4443. #endif
  4444. up(&ioctl_read_sem);
  4445. sbp_sleep(0); /* wait a bit, try again */
  4446. spin_lock_irq(q->queue_lock);
  4447. end_request(req, 0);
  4448. goto request_loop;
  4449. }
  4450. /*==========================================================================*/
  4451. /*
  4452. * build and send the READ command.
  4453. */
  4454. static void sbp_read_cmd(struct request *req)
  4455. {
  4456. #undef OLD
  4457. int i;
  4458. int block;
  4459. current_drive->sbp_first_frame=current_drive->sbp_last_frame=-1; /* purge buffer */
  4460. current_drive->sbp_current = 0;
  4461. block=req->sector/4;
  4462. if (block+current_drive->sbp_bufsiz <= current_drive->CDsize_frm)
  4463. current_drive->sbp_read_frames = current_drive->sbp_bufsiz;
  4464. else
  4465. {
  4466. current_drive->sbp_read_frames=current_drive->CDsize_frm-block;
  4467. /* avoid reading past end of data */
  4468. if (current_drive->sbp_read_frames < 1)
  4469. {
  4470. msg(DBG_INF,"requested frame %d, CD size %d ???\n",
  4471. block, current_drive->CDsize_frm);
  4472. current_drive->sbp_read_frames=1;
  4473. }
  4474. }
  4475. flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check;
  4476. clr_cmdbuf();
  4477. if (famV_drive)
  4478. {
  4479. drvcmd[0]=CMDV_READ;
  4480. lba2msf(block,&drvcmd[1]); /* msf-bcd format required */
  4481. bin2bcdx(&drvcmd[1]);
  4482. bin2bcdx(&drvcmd[2]);
  4483. bin2bcdx(&drvcmd[3]);
  4484. drvcmd[4]=current_drive->sbp_read_frames>>8;
  4485. drvcmd[5]=current_drive->sbp_read_frames&0xff;
  4486. drvcmd[6]=0x02; /* flag "msf-bcd" */
  4487. }
  4488. else if (fam0L_drive)
  4489. {
  4490. flags_cmd_out |= f_lopsta | f_getsta | f_bit1;
  4491. if (current_drive->xa_byte==0x20)
  4492. {
  4493. cmd_type=READ_M2;
  4494. drvcmd[0]=CMD0_READ_XA; /* "read XA frames", old drives */
  4495. drvcmd[1]=(block>>16)&0x0ff;
  4496. drvcmd[2]=(block>>8)&0x0ff;
  4497. drvcmd[3]=block&0x0ff;
  4498. drvcmd[4]=(current_drive->sbp_read_frames>>8)&0x0ff;
  4499. drvcmd[5]=current_drive->sbp_read_frames&0x0ff;
  4500. }
  4501. else
  4502. {
  4503. drvcmd[0]=CMD0_READ; /* "read frames", old drives */
  4504. if (current_drive->drv_type>=drv_201)
  4505. {
  4506. lba2msf(block,&drvcmd[1]); /* msf-bcd format required */
  4507. bin2bcdx(&drvcmd[1]);
  4508. bin2bcdx(&drvcmd[2]);
  4509. bin2bcdx(&drvcmd[3]);
  4510. }
  4511. else
  4512. {
  4513. drvcmd[1]=(block>>16)&0x0ff;
  4514. drvcmd[2]=(block>>8)&0x0ff;
  4515. drvcmd[3]=block&0x0ff;
  4516. }
  4517. drvcmd[4]=(current_drive->sbp_read_frames>>8)&0x0ff;
  4518. drvcmd[5]=current_drive->sbp_read_frames&0x0ff;
  4519. drvcmd[6]=(current_drive->drv_type<drv_201)?0:2; /* flag "lba or msf-bcd format" */
  4520. }
  4521. }
  4522. else if (fam1_drive)
  4523. {
  4524. drvcmd[0]=CMD1_READ;
  4525. lba2msf(block,&drvcmd[1]); /* msf-bin format required */
  4526. drvcmd[5]=(current_drive->sbp_read_frames>>8)&0x0ff;
  4527. drvcmd[6]=current_drive->sbp_read_frames&0x0ff;
  4528. }
  4529. else if (fam2_drive)
  4530. {
  4531. drvcmd[0]=CMD2_READ;
  4532. lba2msf(block,&drvcmd[1]); /* msf-bin format required */
  4533. drvcmd[4]=(current_drive->sbp_read_frames>>8)&0x0ff;
  4534. drvcmd[5]=current_drive->sbp_read_frames&0x0ff;
  4535. drvcmd[6]=0x02;
  4536. }
  4537. else if (famT_drive)
  4538. {
  4539. drvcmd[0]=CMDT_READ;
  4540. drvcmd[2]=(block>>24)&0x0ff;
  4541. drvcmd[3]=(block>>16)&0x0ff;
  4542. drvcmd[4]=(block>>8)&0x0ff;
  4543. drvcmd[5]=block&0x0ff;
  4544. drvcmd[7]=(current_drive->sbp_read_frames>>8)&0x0ff;
  4545. drvcmd[8]=current_drive->sbp_read_frames&0x0ff;
  4546. }
  4547. flags_cmd_out=f_putcmd;
  4548. response_count=0;
  4549. i=cmd_out();
  4550. if (i<0) msg(DBG_INF,"error giving READ command: %0d\n", i);
  4551. return;
  4552. }
  4553. /*==========================================================================*/
  4554. /*
  4555. * Check the completion of the read-data command. On success, read
  4556. * the current_drive->sbp_bufsiz * 2048 bytes of data from the disk into buffer.
  4557. */
  4558. static int sbp_data(struct request *req)
  4559. {
  4560. int i=0, j=0, l, frame;
  4561. u_int try=0;
  4562. u_long timeout;
  4563. u_char *p;
  4564. u_int data_tries = 0;
  4565. u_int data_waits = 0;
  4566. u_int data_retrying = 0;
  4567. int error_flag;
  4568. int xa_count;
  4569. int max_latency;
  4570. int success;
  4571. int wait;
  4572. int duration;
  4573. error_flag=0;
  4574. success=0;
  4575. #if LONG_TIMING
  4576. max_latency=9*HZ;
  4577. #else
  4578. if (current_drive->f_multisession) max_latency=15*HZ;
  4579. else max_latency=5*HZ;
  4580. #endif
  4581. duration=jiffies;
  4582. for (frame=0;frame<current_drive->sbp_read_frames&&!error_flag; frame++)
  4583. {
  4584. SBPCD_CLI;
  4585. del_timer(&data_timer);
  4586. data_timer.expires=jiffies+max_latency;
  4587. timed_out_data=0;
  4588. add_timer(&data_timer);
  4589. while (!timed_out_data)
  4590. {
  4591. if (current_drive->f_multisession) try=maxtim_data*4;
  4592. else try=maxtim_data;
  4593. msg(DBG_000,"sbp_data: CDi_status loop: try=%d.\n",try);
  4594. for ( ; try!=0;try--)
  4595. {
  4596. j=inb(CDi_status);
  4597. if (!(j&s_not_data_ready)) break;
  4598. if (!(j&s_not_result_ready)) break;
  4599. if (fam0LV_drive) if (j&s_attention) break;
  4600. }
  4601. if (!(j&s_not_data_ready)) goto data_ready;
  4602. if (try==0)
  4603. {
  4604. if (data_retrying == 0) data_waits++;
  4605. data_retrying = 1;
  4606. msg(DBG_000,"sbp_data: CDi_status loop: sleeping.\n");
  4607. sbp_sleep(1);
  4608. try = 1;
  4609. }
  4610. }
  4611. msg(DBG_INF,"sbp_data: CDi_status loop expired.\n");
  4612. data_ready:
  4613. del_timer(&data_timer);
  4614. if (timed_out_data)
  4615. {
  4616. msg(DBG_INF,"sbp_data: CDi_status timeout (timed_out_data) (%02X).\n", j);
  4617. error_flag++;
  4618. }
  4619. if (try==0)
  4620. {
  4621. msg(DBG_INF,"sbp_data: CDi_status timeout (try=0) (%02X).\n", j);
  4622. error_flag++;
  4623. }
  4624. if (!(j&s_not_result_ready))
  4625. {
  4626. msg(DBG_INF, "sbp_data: RESULT_READY where DATA_READY awaited (%02X).\n", j);
  4627. response_count=20;
  4628. j=ResponseInfo();
  4629. j=inb(CDi_status);
  4630. }
  4631. if (j&s_not_data_ready)
  4632. {
  4633. if ((current_drive->ored_ctl_adr&0x40)==0)
  4634. msg(DBG_INF, "CD contains no data tracks.\n");
  4635. else msg(DBG_INF, "sbp_data: DATA_READY timeout (%02X).\n", j);
  4636. error_flag++;
  4637. }
  4638. SBPCD_STI;
  4639. if (error_flag) break;
  4640. msg(DBG_000, "sbp_data: beginning to read.\n");
  4641. p = current_drive->sbp_buf + frame * CD_FRAMESIZE;
  4642. if (sbpro_type==1) OUT(CDo_sel_i_d,1);
  4643. if (cmd_type==READ_M2) {
  4644. if (do_16bit) insw(CDi_data, xa_head_buf, CD_XA_HEAD>>1);
  4645. else insb(CDi_data, xa_head_buf, CD_XA_HEAD);
  4646. }
  4647. if (do_16bit) insw(CDi_data, p, CD_FRAMESIZE>>1);
  4648. else insb(CDi_data, p, CD_FRAMESIZE);
  4649. if (cmd_type==READ_M2) {
  4650. if (do_16bit) insw(CDi_data, xa_tail_buf, CD_XA_TAIL>>1);
  4651. else insb(CDi_data, xa_tail_buf, CD_XA_TAIL);
  4652. }
  4653. current_drive->sbp_current++;
  4654. if (sbpro_type==1) OUT(CDo_sel_i_d,0);
  4655. if (cmd_type==READ_M2)
  4656. {
  4657. for (xa_count=0;xa_count<CD_XA_HEAD;xa_count++)
  4658. sprintf(&msgbuf[xa_count*3], " %02X", xa_head_buf[xa_count]);
  4659. msgbuf[xa_count*3]=0;
  4660. msg(DBG_XA1,"xa head:%s\n", msgbuf);
  4661. }
  4662. data_retrying = 0;
  4663. data_tries++;
  4664. if (data_tries >= 1000)
  4665. {
  4666. msg(DBG_INF,"sbp_data() statistics: %d waits in %d frames.\n", data_waits, data_tries);
  4667. data_waits = data_tries = 0;
  4668. }
  4669. }
  4670. duration=jiffies-duration;
  4671. msg(DBG_TEA,"time to read %d frames: %d jiffies .\n",frame,duration);
  4672. if (famT_drive)
  4673. {
  4674. wait=8;
  4675. do
  4676. {
  4677. if (teac==2)
  4678. {
  4679. if ((i=CDi_stat_loop_T()) == -1) break;
  4680. }
  4681. else
  4682. {
  4683. sbp_sleep(1);
  4684. OUT(CDo_sel_i_d,0);
  4685. i=inb(CDi_status);
  4686. }
  4687. if (!(i&s_not_data_ready))
  4688. {
  4689. OUT(CDo_sel_i_d,1);
  4690. j=0;
  4691. do
  4692. {
  4693. if (do_16bit) i=inw(CDi_data);
  4694. else i=inb(CDi_data);
  4695. j++;
  4696. i=inb(CDi_status);
  4697. }
  4698. while (!(i&s_not_data_ready));
  4699. msg(DBG_TEA, "==========too much data (%d bytes/words)==============.\n", j);
  4700. }
  4701. if (!(i&s_not_result_ready))
  4702. {
  4703. OUT(CDo_sel_i_d,0);
  4704. l=0;
  4705. do
  4706. {
  4707. infobuf[l++]=inb(CDi_info);
  4708. i=inb(CDi_status);
  4709. }
  4710. while (!(i&s_not_result_ready));
  4711. if (infobuf[0]==0x00) success=1;
  4712. #if 1
  4713. for (j=0;j<l;j++) sprintf(&msgbuf[j*3], " %02X", infobuf[j]);
  4714. msgbuf[j*3]=0;
  4715. msg(DBG_TEA,"sbp_data info response:%s\n", msgbuf);
  4716. #endif
  4717. if (infobuf[0]==0x02)
  4718. {
  4719. error_flag++;
  4720. do
  4721. {
  4722. ++recursion;
  4723. if (recursion>1) msg(DBG_TEA,"cmd_out_T READ_ERR recursion (sbp_data): %d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",recursion);
  4724. else msg(DBG_TEA,"sbp_data: CMDT_READ_ERR necessary.\n");
  4725. clr_cmdbuf();
  4726. drvcmd[0]=CMDT_READ_ERR;
  4727. j=cmd_out_T(); /* !!! recursive here !!! */
  4728. --recursion;
  4729. sbp_sleep(1);
  4730. }
  4731. while (j<0);
  4732. current_drive->error_state=infobuf[2];
  4733. current_drive->b3=infobuf[3];
  4734. current_drive->b4=infobuf[4];
  4735. }
  4736. break;
  4737. }
  4738. else
  4739. {
  4740. #if 0
  4741. msg(DBG_TEA, "============= waiting for result=================.\n");
  4742. sbp_sleep(1);
  4743. #endif
  4744. }
  4745. }
  4746. while (wait--);
  4747. }
  4748. if (error_flag) /* must have been spurious D_RDY or (ATTN&&!D_RDY) */
  4749. {
  4750. msg(DBG_TEA, "================error flag: %d=================.\n", error_flag);
  4751. msg(DBG_INF,"sbp_data: read aborted by drive.\n");
  4752. #if 1
  4753. i=cc_DriveReset(); /* ugly fix to prevent a hang */
  4754. #else
  4755. i=cc_ReadError();
  4756. #endif
  4757. return (0);
  4758. }
  4759. if (fam0LV_drive)
  4760. {
  4761. SBPCD_CLI;
  4762. i=maxtim_data;
  4763. for (timeout=jiffies+HZ; time_before(jiffies, timeout); timeout--)
  4764. {
  4765. for ( ;i!=0;i--)
  4766. {
  4767. j=inb(CDi_status);
  4768. if (!(j&s_not_data_ready)) break;
  4769. if (!(j&s_not_result_ready)) break;
  4770. if (j&s_attention) break;
  4771. }
  4772. if (i != 0 || time_after_eq(jiffies, timeout)) break;
  4773. sbp_sleep(0);
  4774. i = 1;
  4775. }
  4776. if (i==0) msg(DBG_INF,"status timeout after READ.\n");
  4777. if (!(j&s_attention))
  4778. {
  4779. msg(DBG_INF,"sbp_data: timeout waiting DRV_ATTN - retrying.\n");
  4780. i=cc_DriveReset(); /* ugly fix to prevent a hang */
  4781. SBPCD_STI;
  4782. return (0);
  4783. }
  4784. SBPCD_STI;
  4785. }
  4786. #if 0
  4787. if (!success)
  4788. #endif
  4789. do
  4790. {
  4791. if (fam0LV_drive) cc_ReadStatus();
  4792. #if 1
  4793. if (famT_drive) msg(DBG_TEA, "================before ResponseStatus=================.\n", i);
  4794. #endif
  4795. i=ResponseStatus(); /* builds status_bits, returns orig. status (old) or faked p_success (new) */
  4796. #if 1
  4797. if (famT_drive) msg(DBG_TEA, "================ResponseStatus: %d=================.\n", i);
  4798. #endif
  4799. if (i<0)
  4800. {
  4801. msg(DBG_INF,"bad cc_ReadStatus after read: %02X\n", current_drive->status_bits);
  4802. return (0);
  4803. }
  4804. }
  4805. while ((fam0LV_drive)&&(!st_check)&&(!(i&p_success)));
  4806. if (st_check)
  4807. {
  4808. i=cc_ReadError();
  4809. msg(DBG_INF,"cc_ReadError was necessary after read: %d\n",i);
  4810. return (0);
  4811. }
  4812. if (fatal_err)
  4813. {
  4814. fatal_err=0;
  4815. current_drive->sbp_first_frame=current_drive->sbp_last_frame=-1; /* purge buffer */
  4816. current_drive->sbp_current = 0;
  4817. msg(DBG_INF,"sbp_data: fatal_err - retrying.\n");
  4818. return (0);
  4819. }
  4820. current_drive->sbp_first_frame = req -> sector / 4;
  4821. current_drive->sbp_last_frame = current_drive->sbp_first_frame + current_drive->sbp_read_frames - 1;
  4822. sbp_transfer(req);
  4823. return (1);
  4824. }
  4825. /*==========================================================================*/
  4826. static int sbpcd_block_open(struct inode *inode, struct file *file)
  4827. {
  4828. struct sbpcd_drive *p = inode->i_bdev->bd_disk->private_data;
  4829. return cdrom_open(p->sbpcd_infop, inode, file);
  4830. }
  4831. static int sbpcd_block_release(struct inode *inode, struct file *file)
  4832. {
  4833. struct sbpcd_drive *p = inode->i_bdev->bd_disk->private_data;
  4834. return cdrom_release(p->sbpcd_infop, file);
  4835. }
  4836. static int sbpcd_block_ioctl(struct inode *inode, struct file *file,
  4837. unsigned cmd, unsigned long arg)
  4838. {
  4839. struct sbpcd_drive *p = inode->i_bdev->bd_disk->private_data;
  4840. struct cdrom_device_info *cdi = p->sbpcd_infop;
  4841. int ret, i;
  4842. ret = cdrom_ioctl(file, p->sbpcd_infop, inode, cmd, arg);
  4843. if (ret != -ENOSYS)
  4844. return ret;
  4845. msg(DBG_IO2,"ioctl(%s, 0x%08lX, 0x%08lX)\n", cdi->name, cmd, arg);
  4846. if (p->drv_id==-1) {
  4847. msg(DBG_INF, "ioctl: bad device: %s\n", cdi->name);
  4848. return (-ENXIO); /* no such drive */
  4849. }
  4850. down(&ioctl_read_sem);
  4851. if (p != current_drive)
  4852. switch_drive(p);
  4853. msg(DBG_IO2,"ioctl: device %s, request %04X\n",cdi->name,cmd);
  4854. switch (cmd) /* Sun-compatible */
  4855. {
  4856. case DDIOCSDBG: /* DDI Debug */
  4857. if (!capable(CAP_SYS_ADMIN)) RETURN_UP(-EPERM);
  4858. i=sbpcd_dbg_ioctl(arg,1);
  4859. RETURN_UP(i);
  4860. case CDROMRESET: /* hard reset the drive */
  4861. msg(DBG_IOC,"ioctl: CDROMRESET entered.\n");
  4862. i=DriveReset();
  4863. current_drive->audio_state=0;
  4864. RETURN_UP(i);
  4865. case CDROMREADMODE1:
  4866. msg(DBG_IOC,"ioctl: CDROMREADMODE1 requested.\n");
  4867. #ifdef SAFE_MIXED
  4868. if (current_drive->has_data>1) RETURN_UP(-EBUSY);
  4869. #endif /* SAFE_MIXED */
  4870. cc_ModeSelect(CD_FRAMESIZE);
  4871. cc_ModeSense();
  4872. current_drive->mode=READ_M1;
  4873. RETURN_UP(0);
  4874. case CDROMREADMODE2: /* not usable at the moment */
  4875. msg(DBG_IOC,"ioctl: CDROMREADMODE2 requested.\n");
  4876. #ifdef SAFE_MIXED
  4877. if (current_drive->has_data>1) RETURN_UP(-EBUSY);
  4878. #endif /* SAFE_MIXED */
  4879. cc_ModeSelect(CD_FRAMESIZE_RAW1);
  4880. cc_ModeSense();
  4881. current_drive->mode=READ_M2;
  4882. RETURN_UP(0);
  4883. case CDROMAUDIOBUFSIZ: /* configure the audio buffer size */
  4884. msg(DBG_IOC,"ioctl: CDROMAUDIOBUFSIZ entered.\n");
  4885. if (current_drive->sbp_audsiz>0)
  4886. vfree(current_drive->aud_buf);
  4887. current_drive->aud_buf=NULL;
  4888. current_drive->sbp_audsiz=arg;
  4889. if (current_drive->sbp_audsiz>16)
  4890. {
  4891. current_drive->sbp_audsiz = 0;
  4892. RETURN_UP(current_drive->sbp_audsiz);
  4893. }
  4894. if (current_drive->sbp_audsiz>0)
  4895. {
  4896. current_drive->aud_buf=(u_char *) vmalloc(current_drive->sbp_audsiz*CD_FRAMESIZE_RAW);
  4897. if (current_drive->aud_buf==NULL)
  4898. {
  4899. msg(DBG_INF,"audio buffer (%d frames) not available.\n",current_drive->sbp_audsiz);
  4900. current_drive->sbp_audsiz=0;
  4901. }
  4902. else msg(DBG_INF,"audio buffer size: %d frames.\n",current_drive->sbp_audsiz);
  4903. }
  4904. RETURN_UP(current_drive->sbp_audsiz);
  4905. case CDROMREADAUDIO:
  4906. { /* start of CDROMREADAUDIO */
  4907. int i=0, j=0, frame, block=0;
  4908. u_int try=0;
  4909. u_long timeout;
  4910. u_char *p;
  4911. u_int data_tries = 0;
  4912. u_int data_waits = 0;
  4913. u_int data_retrying = 0;
  4914. int status_tries;
  4915. int error_flag;
  4916. msg(DBG_IOC,"ioctl: CDROMREADAUDIO entered.\n");
  4917. if (fam0_drive) RETURN_UP(-EINVAL);
  4918. if (famL_drive) RETURN_UP(-EINVAL);
  4919. if (famV_drive) RETURN_UP(-EINVAL);
  4920. if (famT_drive) RETURN_UP(-EINVAL);
  4921. #ifdef SAFE_MIXED
  4922. if (current_drive->has_data>1) RETURN_UP(-EBUSY);
  4923. #endif /* SAFE_MIXED */
  4924. if (current_drive->aud_buf==NULL) RETURN_UP(-EINVAL);
  4925. if (copy_from_user(&read_audio, (void __user *)arg,
  4926. sizeof(struct cdrom_read_audio)))
  4927. RETURN_UP(-EFAULT);
  4928. if (read_audio.nframes < 0 || read_audio.nframes>current_drive->sbp_audsiz) RETURN_UP(-EINVAL);
  4929. if (!access_ok(VERIFY_WRITE, read_audio.buf,
  4930. read_audio.nframes*CD_FRAMESIZE_RAW))
  4931. RETURN_UP(-EFAULT);
  4932. if (read_audio.addr_format==CDROM_MSF) /* MSF-bin specification of where to start */
  4933. block=msf2lba(&read_audio.addr.msf.minute);
  4934. else if (read_audio.addr_format==CDROM_LBA) /* lba specification of where to start */
  4935. block=read_audio.addr.lba;
  4936. else RETURN_UP(-EINVAL);
  4937. #if 000
  4938. i=cc_SetSpeed(speed_150,0,0);
  4939. if (i) msg(DBG_AUD,"read_audio: SetSpeed error %d\n", i);
  4940. #endif
  4941. msg(DBG_AUD,"read_audio: lba: %d, msf: %06X\n",
  4942. block, blk2msf(block));
  4943. msg(DBG_AUD,"read_audio: before cc_ReadStatus.\n");
  4944. #if OLD_BUSY
  4945. while (busy_data) sbp_sleep(HZ/10); /* wait a bit */
  4946. busy_audio=1;
  4947. #endif /* OLD_BUSY */
  4948. error_flag=0;
  4949. for (data_tries=5; data_tries>0; data_tries--)
  4950. {
  4951. msg(DBG_AUD,"data_tries=%d ...\n", data_tries);
  4952. current_drive->mode=READ_AU;
  4953. cc_ModeSelect(CD_FRAMESIZE_RAW);
  4954. cc_ModeSense();
  4955. for (status_tries=3; status_tries > 0; status_tries--)
  4956. {
  4957. flags_cmd_out |= f_respo3;
  4958. cc_ReadStatus();
  4959. if (sbp_status() != 0) break;
  4960. if (st_check) cc_ReadError();
  4961. sbp_sleep(1); /* wait a bit, try again */
  4962. }
  4963. if (status_tries == 0)
  4964. {
  4965. msg(DBG_AUD,"read_audio: sbp_status: failed after 3 tries in line %d.\n", __LINE__);
  4966. continue;
  4967. }
  4968. msg(DBG_AUD,"read_audio: sbp_status: ok.\n");
  4969. flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check;
  4970. if (fam0L_drive)
  4971. {
  4972. flags_cmd_out |= f_lopsta | f_getsta | f_bit1;
  4973. cmd_type=READ_M2;
  4974. drvcmd[0]=CMD0_READ_XA; /* "read XA frames", old drives */
  4975. drvcmd[1]=(block>>16)&0x000000ff;
  4976. drvcmd[2]=(block>>8)&0x000000ff;
  4977. drvcmd[3]=block&0x000000ff;
  4978. drvcmd[4]=0;
  4979. drvcmd[5]=read_audio.nframes; /* # of frames */
  4980. drvcmd[6]=0;
  4981. }
  4982. else if (fam1_drive)
  4983. {
  4984. drvcmd[0]=CMD1_READ; /* "read frames", new drives */
  4985. lba2msf(block,&drvcmd[1]); /* msf-bin format required */
  4986. drvcmd[4]=0;
  4987. drvcmd[5]=0;
  4988. drvcmd[6]=read_audio.nframes; /* # of frames */
  4989. }
  4990. else if (fam2_drive)
  4991. {
  4992. drvcmd[0]=CMD2_READ_XA2;
  4993. lba2msf(block,&drvcmd[1]); /* msf-bin format required */
  4994. drvcmd[4]=0;
  4995. drvcmd[5]=read_audio.nframes; /* # of frames */
  4996. drvcmd[6]=0x11; /* raw mode */
  4997. }
  4998. else if (famT_drive) /* CD-55A: not tested yet */
  4999. {
  5000. }
  5001. msg(DBG_AUD,"read_audio: before giving \"read\" command.\n");
  5002. flags_cmd_out=f_putcmd;
  5003. response_count=0;
  5004. i=cmd_out();
  5005. if (i<0) msg(DBG_INF,"error giving READ AUDIO command: %0d\n", i);
  5006. sbp_sleep(0);
  5007. msg(DBG_AUD,"read_audio: after giving \"read\" command.\n");
  5008. for (frame=1;frame<2 && !error_flag; frame++)
  5009. {
  5010. try=maxtim_data;
  5011. for (timeout=jiffies+9*HZ; ; )
  5012. {
  5013. for ( ; try!=0;try--)
  5014. {
  5015. j=inb(CDi_status);
  5016. if (!(j&s_not_data_ready)) break;
  5017. if (!(j&s_not_result_ready)) break;
  5018. if (fam0L_drive) if (j&s_attention) break;
  5019. }
  5020. if (try != 0 || time_after_eq(jiffies, timeout)) break;
  5021. if (data_retrying == 0) data_waits++;
  5022. data_retrying = 1;
  5023. sbp_sleep(1);
  5024. try = 1;
  5025. }
  5026. if (try==0)
  5027. {
  5028. msg(DBG_INF,"read_audio: sbp_data: CDi_status timeout.\n");
  5029. error_flag++;
  5030. break;
  5031. }
  5032. msg(DBG_AUD,"read_audio: sbp_data: CDi_status ok.\n");
  5033. if (j&s_not_data_ready)
  5034. {
  5035. msg(DBG_INF, "read_audio: sbp_data: DATA_READY timeout.\n");
  5036. error_flag++;
  5037. break;
  5038. }
  5039. msg(DBG_AUD,"read_audio: before reading data.\n");
  5040. error_flag=0;
  5041. p = current_drive->aud_buf;
  5042. if (sbpro_type==1) OUT(CDo_sel_i_d,1);
  5043. if (do_16bit)
  5044. {
  5045. u_short *p2 = (u_short *) p;
  5046. for (; (u_char *) p2 < current_drive->aud_buf + read_audio.nframes*CD_FRAMESIZE_RAW;)
  5047. {
  5048. if ((inb_p(CDi_status)&s_not_data_ready)) continue;
  5049. /* get one sample */
  5050. *p2++ = inw_p(CDi_data);
  5051. *p2++ = inw_p(CDi_data);
  5052. }
  5053. } else {
  5054. for (; p < current_drive->aud_buf + read_audio.nframes*CD_FRAMESIZE_RAW;)
  5055. {
  5056. if ((inb_p(CDi_status)&s_not_data_ready)) continue;
  5057. /* get one sample */
  5058. *p++ = inb_p(CDi_data);
  5059. *p++ = inb_p(CDi_data);
  5060. *p++ = inb_p(CDi_data);
  5061. *p++ = inb_p(CDi_data);
  5062. }
  5063. }
  5064. if (sbpro_type==1) OUT(CDo_sel_i_d,0);
  5065. data_retrying = 0;
  5066. }
  5067. msg(DBG_AUD,"read_audio: after reading data.\n");
  5068. if (error_flag) /* must have been spurious D_RDY or (ATTN&&!D_RDY) */
  5069. {
  5070. msg(DBG_AUD,"read_audio: read aborted by drive\n");
  5071. #if 0000
  5072. i=cc_DriveReset(); /* ugly fix to prevent a hang */
  5073. #else
  5074. i=cc_ReadError();
  5075. #endif
  5076. continue;
  5077. }
  5078. if (fam0L_drive)
  5079. {
  5080. i=maxtim_data;
  5081. for (timeout=jiffies+9*HZ; time_before(jiffies, timeout); timeout--)
  5082. {
  5083. for ( ;i!=0;i--)
  5084. {
  5085. j=inb(CDi_status);
  5086. if (!(j&s_not_data_ready)) break;
  5087. if (!(j&s_not_result_ready)) break;
  5088. if (j&s_attention) break;
  5089. }
  5090. if (i != 0 || time_after_eq(jiffies, timeout)) break;
  5091. sbp_sleep(0);
  5092. i = 1;
  5093. }
  5094. if (i==0) msg(DBG_AUD,"read_audio: STATUS TIMEOUT AFTER READ");
  5095. if (!(j&s_attention))
  5096. {
  5097. msg(DBG_AUD,"read_audio: sbp_data: timeout waiting DRV_ATTN - retrying\n");
  5098. i=cc_DriveReset(); /* ugly fix to prevent a hang */
  5099. continue;
  5100. }
  5101. }
  5102. do
  5103. {
  5104. if (fam0L_drive) cc_ReadStatus();
  5105. i=ResponseStatus(); /* builds status_bits, returns orig. status (old) or faked p_success (new) */
  5106. if (i<0) { msg(DBG_AUD,
  5107. "read_audio: cc_ReadStatus error after read: %02X\n",
  5108. current_drive->status_bits);
  5109. continue; /* FIXME */
  5110. }
  5111. }
  5112. while ((fam0L_drive)&&(!st_check)&&(!(i&p_success)));
  5113. if (st_check)
  5114. {
  5115. i=cc_ReadError();
  5116. msg(DBG_AUD,"read_audio: cc_ReadError was necessary after read: %02X\n",i);
  5117. continue;
  5118. }
  5119. if (copy_to_user(read_audio.buf,
  5120. current_drive->aud_buf,
  5121. read_audio.nframes * CD_FRAMESIZE_RAW))
  5122. RETURN_UP(-EFAULT);
  5123. msg(DBG_AUD,"read_audio: copy_to_user done.\n");
  5124. break;
  5125. }
  5126. cc_ModeSelect(CD_FRAMESIZE);
  5127. cc_ModeSense();
  5128. current_drive->mode=READ_M1;
  5129. #if OLD_BUSY
  5130. busy_audio=0;
  5131. #endif /* OLD_BUSY */
  5132. if (data_tries == 0)
  5133. {
  5134. msg(DBG_AUD,"read_audio: failed after 5 tries in line %d.\n", __LINE__);
  5135. RETURN_UP(-EIO);
  5136. }
  5137. msg(DBG_AUD,"read_audio: successful return.\n");
  5138. RETURN_UP(0);
  5139. } /* end of CDROMREADAUDIO */
  5140. default:
  5141. msg(DBG_IOC,"ioctl: unknown function request %04X\n", cmd);
  5142. RETURN_UP(-EINVAL);
  5143. } /* end switch(cmd) */
  5144. }
  5145. static int sbpcd_block_media_changed(struct gendisk *disk)
  5146. {
  5147. struct sbpcd_drive *p = disk->private_data;
  5148. return cdrom_media_changed(p->sbpcd_infop);
  5149. }
  5150. static struct block_device_operations sbpcd_bdops =
  5151. {
  5152. .owner = THIS_MODULE,
  5153. .open = sbpcd_block_open,
  5154. .release = sbpcd_block_release,
  5155. .ioctl = sbpcd_block_ioctl,
  5156. .media_changed = sbpcd_block_media_changed,
  5157. };
  5158. /*==========================================================================*/
  5159. /*
  5160. * Open the device special file. Check that a disk is in. Read TOC.
  5161. */
  5162. static int sbpcd_open(struct cdrom_device_info *cdi, int purpose)
  5163. {
  5164. struct sbpcd_drive *p = cdi->handle;
  5165. down(&ioctl_read_sem);
  5166. switch_drive(p);
  5167. /*
  5168. * try to keep an "open" counter here and lock the door if 0->1.
  5169. */
  5170. msg(DBG_LCK,"open_count: %d -> %d\n",
  5171. current_drive->open_count,current_drive->open_count+1);
  5172. if (++current_drive->open_count<=1)
  5173. {
  5174. int i;
  5175. i=LockDoor();
  5176. current_drive->open_count=1;
  5177. if (famT_drive) msg(DBG_TEA,"sbpcd_open: before i=DiskInfo();.\n");
  5178. i=DiskInfo();
  5179. if (famT_drive) msg(DBG_TEA,"sbpcd_open: after i=DiskInfo();.\n");
  5180. if ((current_drive->ored_ctl_adr&0x40)==0)
  5181. {
  5182. msg(DBG_INF,"CD contains no data tracks.\n");
  5183. #ifdef SAFE_MIXED
  5184. current_drive->has_data=0;
  5185. #endif /* SAFE_MIXED */
  5186. }
  5187. #ifdef SAFE_MIXED
  5188. else if (current_drive->has_data<1) current_drive->has_data=1;
  5189. #endif /* SAFE_MIXED */
  5190. }
  5191. if (!st_spinning) cc_SpinUp();
  5192. RETURN_UP(0);
  5193. }
  5194. /*==========================================================================*/
  5195. /*
  5196. * On close, we flush all sbp blocks from the buffer cache.
  5197. */
  5198. static void sbpcd_release(struct cdrom_device_info * cdi)
  5199. {
  5200. struct sbpcd_drive *p = cdi->handle;
  5201. if (p->drv_id==-1) {
  5202. msg(DBG_INF, "release: bad device: %s\n", cdi->name);
  5203. return;
  5204. }
  5205. down(&ioctl_read_sem);
  5206. switch_drive(p);
  5207. /*
  5208. * try to keep an "open" counter here and unlock the door if 1->0.
  5209. */
  5210. msg(DBG_LCK,"open_count: %d -> %d\n",
  5211. p->open_count,p->open_count-1);
  5212. if (p->open_count>-2) /* CDROMEJECT may have been done */
  5213. {
  5214. if (--p->open_count<=0)
  5215. {
  5216. p->sbp_first_frame=p->sbp_last_frame=-1;
  5217. if (p->audio_state!=audio_playing)
  5218. if (p->f_eject) cc_SpinDown();
  5219. p->diskstate_flags &= ~cd_size_bit;
  5220. p->open_count=0;
  5221. #ifdef SAFE_MIXED
  5222. p->has_data=0;
  5223. #endif /* SAFE_MIXED */
  5224. }
  5225. }
  5226. up(&ioctl_read_sem);
  5227. return ;
  5228. }
  5229. /*==========================================================================*/
  5230. /*
  5231. *
  5232. */
  5233. static int sbpcd_media_changed( struct cdrom_device_info *cdi, int disc_nr);
  5234. static struct cdrom_device_ops sbpcd_dops = {
  5235. .open = sbpcd_open,
  5236. .release = sbpcd_release,
  5237. .drive_status = sbpcd_drive_status,
  5238. .media_changed = sbpcd_media_changed,
  5239. .tray_move = sbpcd_tray_move,
  5240. .lock_door = sbpcd_lock_door,
  5241. .select_speed = sbpcd_select_speed,
  5242. .get_last_session = sbpcd_get_last_session,
  5243. .get_mcn = sbpcd_get_mcn,
  5244. .reset = sbpcd_reset,
  5245. .audio_ioctl = sbpcd_audio_ioctl,
  5246. .capability = CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK |
  5247. CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
  5248. CDC_MCN | CDC_PLAY_AUDIO,
  5249. .n_minors = 1,
  5250. };
  5251. /*==========================================================================*/
  5252. /*
  5253. * accept "kernel command line" parameters
  5254. * (suggested by Peter MacDonald with SLS 1.03)
  5255. *
  5256. * This is only implemented for the first controller. Should be enough to
  5257. * allow installing with a "strange" distribution kernel.
  5258. *
  5259. * use: tell LILO:
  5260. * sbpcd=0x230,SoundBlaster
  5261. * or
  5262. * sbpcd=0x300,LaserMate
  5263. * or
  5264. * sbpcd=0x338,SoundScape
  5265. * or
  5266. * sbpcd=0x2C0,Teac16bit
  5267. *
  5268. * (upper/lower case sensitive here - but all-lowercase is ok!!!).
  5269. *
  5270. * the address value has to be the CDROM PORT ADDRESS -
  5271. * not the soundcard base address.
  5272. * For the SPEA/SoundScape setup, DO NOT specify the "configuration port"
  5273. * address, but the address which is really used for the CDROM (usually 8
  5274. * bytes above).
  5275. *
  5276. */
  5277. int sbpcd_setup(char *s)
  5278. {
  5279. #ifndef MODULE
  5280. int p[4];
  5281. (void)get_options(s, ARRAY_SIZE(p), p);
  5282. setup_done++;
  5283. msg(DBG_INI,"sbpcd_setup called with %04X,%s\n",p[1], s);
  5284. sbpro_type=0; /* default: "LaserMate" */
  5285. if (p[0]>1) sbpro_type=p[2];
  5286. else if (!strcmp(s,str_sb)) sbpro_type=1;
  5287. else if (!strcmp(s,str_sb_l)) sbpro_type=1;
  5288. else if (!strcmp(s,str_sp)) sbpro_type=2;
  5289. else if (!strcmp(s,str_sp_l)) sbpro_type=2;
  5290. else if (!strcmp(s,str_ss)) sbpro_type=2;
  5291. else if (!strcmp(s,str_ss_l)) sbpro_type=2;
  5292. else if (!strcmp(s,str_t16)) sbpro_type=3;
  5293. else if (!strcmp(s,str_t16_l)) sbpro_type=3;
  5294. if (p[0]>0) sbpcd_ioaddr=p[1];
  5295. if (p[0]>2) max_drives=p[3];
  5296. #else
  5297. sbpcd_ioaddr = sbpcd[0];
  5298. sbpro_type = sbpcd[1];
  5299. #endif
  5300. CDo_command=sbpcd_ioaddr;
  5301. CDi_info=sbpcd_ioaddr;
  5302. CDi_status=sbpcd_ioaddr+1;
  5303. CDo_sel_i_d=sbpcd_ioaddr+1;
  5304. CDo_reset=sbpcd_ioaddr+2;
  5305. CDo_enable=sbpcd_ioaddr+3;
  5306. f_16bit=0;
  5307. if ((sbpro_type==1)||(sbpro_type==3))
  5308. {
  5309. CDi_data=sbpcd_ioaddr;
  5310. if (sbpro_type==3)
  5311. {
  5312. f_16bit=1;
  5313. sbpro_type=1;
  5314. }
  5315. }
  5316. else CDi_data=sbpcd_ioaddr+2;
  5317. return 1;
  5318. }
  5319. __setup("sbpcd=", sbpcd_setup);
  5320. /*==========================================================================*/
  5321. /*
  5322. * Sequoia S-1000 CD-ROM Interface Configuration
  5323. * as used within SPEA Media FX, Ensonic SoundScape and some Reveal cards
  5324. * The soundcard has to get jumpered for the interface type "Panasonic"
  5325. * (not Sony or Mitsumi) and to get soft-configured for
  5326. * -> configuration port address
  5327. * -> CDROM port offset (num_ports): has to be 8 here. Possibly this
  5328. * offset value determines the interface type (none, Panasonic,
  5329. * Mitsumi, Sony).
  5330. * The interface uses a configuration port (0x320, 0x330, 0x340, 0x350)
  5331. * some bytes below the real CDROM address.
  5332. *
  5333. * For the Panasonic style (LaserMate) interface and the configuration
  5334. * port 0x330, we have to use an offset of 8; so, the real CDROM port
  5335. * address is 0x338.
  5336. */
  5337. static int __init config_spea(void)
  5338. {
  5339. /*
  5340. * base address offset between configuration port and CDROM port,
  5341. * this probably defines the interface type
  5342. * 2 (type=??): 0x00
  5343. * 8 (type=LaserMate):0x10
  5344. * 16 (type=??):0x20
  5345. * 32 (type=??):0x30
  5346. */
  5347. int n_ports=0x10;
  5348. int irq_number=0; /* off:0x00, 2/9:0x01, 7:0x03, 12:0x05, 15:0x07 */
  5349. int dma_channel=0; /* off: 0x00, 0:0x08, 1:0x18, 3:0x38, 5:0x58, 6:0x68 */
  5350. int dack_polarity=0; /* L:0x00, H:0x80 */
  5351. int drq_polarity=0x40; /* L:0x00, H:0x40 */
  5352. int i;
  5353. #define SPEA_REG_1 sbpcd_ioaddr-0x08+4
  5354. #define SPEA_REG_2 sbpcd_ioaddr-0x08+5
  5355. OUT(SPEA_REG_1,0xFF);
  5356. i=inb(SPEA_REG_1);
  5357. if (i!=0x0F)
  5358. {
  5359. msg(DBG_SEQ,"no SPEA interface at %04X present.\n", sbpcd_ioaddr);
  5360. return (-1); /* no interface found */
  5361. }
  5362. OUT(SPEA_REG_1,0x04);
  5363. OUT(SPEA_REG_2,0xC0);
  5364. OUT(SPEA_REG_1,0x05);
  5365. OUT(SPEA_REG_2,0x10|drq_polarity|dack_polarity);
  5366. #if 1
  5367. #define SPEA_PATTERN 0x80
  5368. #else
  5369. #define SPEA_PATTERN 0x00
  5370. #endif
  5371. OUT(SPEA_REG_1,0x06);
  5372. OUT(SPEA_REG_2,dma_channel|irq_number|SPEA_PATTERN);
  5373. OUT(SPEA_REG_2,dma_channel|irq_number|SPEA_PATTERN);
  5374. OUT(SPEA_REG_1,0x09);
  5375. i=(inb(SPEA_REG_2)&0xCF)|n_ports;
  5376. OUT(SPEA_REG_2,i);
  5377. sbpro_type = 0; /* acts like a LaserMate interface now */
  5378. msg(DBG_SEQ,"found SoundScape interface at %04X.\n", sbpcd_ioaddr);
  5379. return (0);
  5380. }
  5381. /*==========================================================================*/
  5382. /*
  5383. * Test for presence of drive and initialize it.
  5384. * Called once at boot or load time.
  5385. */
  5386. /* FIXME: cleanups after failed allocations are too ugly for words */
  5387. #ifdef MODULE
  5388. int __init __sbpcd_init(void)
  5389. #else
  5390. int __init sbpcd_init(void)
  5391. #endif
  5392. {
  5393. int i=0, j=0;
  5394. int addr[2]={1, CDROM_PORT};
  5395. int port_index;
  5396. sti();
  5397. msg(DBG_INF,"sbpcd.c %s\n", VERSION);
  5398. #ifndef MODULE
  5399. #if DISTRIBUTION
  5400. if (!setup_done)
  5401. {
  5402. msg(DBG_INF,"Looking for Matsushita/Panasonic, CreativeLabs, Longshine, TEAC CD-ROM drives\n");
  5403. msg(DBG_INF,"= = = = = = = = = = W A R N I N G = = = = = = = = = =\n");
  5404. msg(DBG_INF,"Auto-Probing can cause a hang (f.e. touching an NE2000 card).\n");
  5405. msg(DBG_INF,"If that happens, you have to reboot and use the\n");
  5406. msg(DBG_INF,"LILO (kernel) command line feature like:\n");
  5407. msg(DBG_INF," LILO boot: ... sbpcd=0x230,SoundBlaster\n");
  5408. msg(DBG_INF,"or like:\n");
  5409. msg(DBG_INF," LILO boot: ... sbpcd=0x300,LaserMate\n");
  5410. msg(DBG_INF,"or like:\n");
  5411. msg(DBG_INF," LILO boot: ... sbpcd=0x338,SoundScape\n");
  5412. msg(DBG_INF,"with your REAL address.\n");
  5413. msg(DBG_INF,"= = = = = = = = = = END of WARNING = = = = = == = = =\n");
  5414. }
  5415. #endif /* DISTRIBUTION */
  5416. sbpcd[0]=sbpcd_ioaddr; /* possibly changed by kernel command line */
  5417. sbpcd[1]=sbpro_type; /* possibly changed by kernel command line */
  5418. #endif /* MODULE */
  5419. for (port_index=0;port_index<NUM_PROBE;port_index+=2)
  5420. {
  5421. addr[1]=sbpcd[port_index];
  5422. if (addr[1]==0) break;
  5423. if (check_region(addr[1],4))
  5424. {
  5425. msg(DBG_INF,"check_region: %03X is not free.\n",addr[1]);
  5426. continue;
  5427. }
  5428. if (sbpcd[port_index+1]==2) type=str_sp;
  5429. else if (sbpcd[port_index+1]==1) type=str_sb;
  5430. else if (sbpcd[port_index+1]==3) type=str_t16;
  5431. else type=str_lm;
  5432. sbpcd_setup((char *)type);
  5433. #if DISTRIBUTION
  5434. msg(DBG_INF,"Scanning 0x%X (%s)...\n", CDo_command, type);
  5435. #endif /* DISTRIBUTION */
  5436. if (sbpcd[port_index+1]==2)
  5437. {
  5438. i=config_spea();
  5439. if (i<0) continue;
  5440. }
  5441. #ifdef PATH_CHECK
  5442. if (check_card(addr[1])) continue;
  5443. #endif /* PATH_CHECK */
  5444. i=check_drives();
  5445. msg(DBG_INI,"check_drives done.\n");
  5446. if (i>=0) break; /* drive found */
  5447. } /* end of cycling through the set of possible I/O port addresses */
  5448. if (ndrives==0)
  5449. {
  5450. msg(DBG_INF, "No drive found.\n");
  5451. #ifdef MODULE
  5452. return -EIO;
  5453. #else
  5454. goto init_done;
  5455. #endif /* MODULE */
  5456. }
  5457. if (port_index>0)
  5458. {
  5459. msg(DBG_INF, "You should read Documentation/cdrom/sbpcd\n");
  5460. msg(DBG_INF, "and then configure sbpcd.h for your hardware.\n");
  5461. }
  5462. check_datarate();
  5463. msg(DBG_INI,"check_datarate done.\n");
  5464. for (j=0;j<NR_SBPCD;j++)
  5465. {
  5466. struct sbpcd_drive *p = D_S + j;
  5467. if (p->drv_id==-1)
  5468. continue;
  5469. switch_drive(p);
  5470. #if 1
  5471. if (!famL_drive) cc_DriveReset();
  5472. #endif
  5473. if (!st_spinning) cc_SpinUp();
  5474. p->sbp_first_frame = -1; /* First frame in buffer */
  5475. p->sbp_last_frame = -1; /* Last frame in buffer */
  5476. p->sbp_read_frames = 0; /* Number of frames being read to buffer */
  5477. p->sbp_current = 0; /* Frame being currently read */
  5478. p->CD_changed=1;
  5479. p->frame_size=CD_FRAMESIZE;
  5480. p->f_eject=0;
  5481. #if EJECT
  5482. if (!fam0_drive) p->f_eject=1;
  5483. #endif /* EJECT */
  5484. cc_ReadStatus();
  5485. i=ResponseStatus(); /* returns orig. status or p_busy_new */
  5486. if (famT_drive) i=ResponseStatus(); /* returns orig. status or p_busy_new */
  5487. if (i<0)
  5488. {
  5489. if (i!=-402)
  5490. msg(DBG_INF,"init: ResponseStatus returns %d.\n",i);
  5491. }
  5492. else
  5493. {
  5494. if (st_check)
  5495. {
  5496. i=cc_ReadError();
  5497. msg(DBG_INI,"init: cc_ReadError returns %d\n",i);
  5498. }
  5499. }
  5500. msg(DBG_INI,"init: first GetStatus: %d\n",i);
  5501. msg(DBG_LCS,"init: first GetStatus: error_byte=%d\n",
  5502. p->error_byte);
  5503. if (p->error_byte==aud_12)
  5504. {
  5505. timeout=jiffies+2*HZ;
  5506. do
  5507. {
  5508. i=GetStatus();
  5509. msg(DBG_INI,"init: second GetStatus: %02X\n",i);
  5510. msg(DBG_LCS,
  5511. "init: second GetStatus: error_byte=%d\n",
  5512. p->error_byte);
  5513. if (i<0) break;
  5514. if (!st_caddy_in) break;
  5515. }
  5516. while ((!st_diskok)||time_after(jiffies, timeout));
  5517. }
  5518. i=SetSpeed();
  5519. if (i>=0) p->CD_changed=1;
  5520. }
  5521. if (!request_region(CDo_command,4,major_name))
  5522. {
  5523. printk(KERN_WARNING "sbpcd: Unable to request region 0x%x\n", CDo_command);
  5524. return -EIO;
  5525. }
  5526. /*
  5527. * Turn on the CD audio channels.
  5528. * The addresses are obtained from SOUND_BASE (see sbpcd.h).
  5529. */
  5530. #if SOUND_BASE
  5531. OUT(MIXER_addr,MIXER_CD_Volume); /* select SB Pro mixer register */
  5532. OUT(MIXER_data,0xCC); /* one nibble per channel, max. value: 0xFF */
  5533. #endif /* SOUND_BASE */
  5534. if (register_blkdev(MAJOR_NR, major_name)) {
  5535. #ifdef MODULE
  5536. return -EIO;
  5537. #else
  5538. goto init_done;
  5539. #endif /* MODULE */
  5540. }
  5541. /*
  5542. * init error handling is broken beyond belief in this driver...
  5543. */
  5544. sbpcd_queue = blk_init_queue(do_sbpcd_request, &sbpcd_lock);
  5545. if (!sbpcd_queue) {
  5546. release_region(CDo_command,4);
  5547. unregister_blkdev(MAJOR_NR, major_name);
  5548. return -ENOMEM;
  5549. }
  5550. for (j=0;j<NR_SBPCD;j++)
  5551. {
  5552. struct cdrom_device_info * sbpcd_infop;
  5553. struct gendisk *disk;
  5554. struct sbpcd_drive *p = D_S + j;
  5555. if (p->drv_id==-1) continue;
  5556. switch_drive(p);
  5557. #ifdef SAFE_MIXED
  5558. p->has_data=0;
  5559. #endif /* SAFE_MIXED */
  5560. /*
  5561. * allocate memory for the frame buffers
  5562. */
  5563. p->aud_buf=NULL;
  5564. p->sbp_audsiz=0;
  5565. p->sbp_bufsiz=buffers;
  5566. if (p->drv_type&drv_fam1)
  5567. if (READ_AUDIO>0)
  5568. p->sbp_audsiz = READ_AUDIO;
  5569. p->sbp_buf=(u_char *) vmalloc(buffers*CD_FRAMESIZE);
  5570. if (!p->sbp_buf) {
  5571. msg(DBG_INF,"data buffer (%d frames) not available.\n",
  5572. buffers);
  5573. if ((unregister_blkdev(MAJOR_NR, major_name) == -EINVAL))
  5574. {
  5575. printk("Can't unregister %s\n", major_name);
  5576. }
  5577. release_region(CDo_command,4);
  5578. blk_cleanup_queue(sbpcd_queue);
  5579. return -EIO;
  5580. }
  5581. #ifdef MODULE
  5582. msg(DBG_INF,"data buffer size: %d frames.\n",buffers);
  5583. #endif /* MODULE */
  5584. if (p->sbp_audsiz>0)
  5585. {
  5586. p->aud_buf=(u_char *) vmalloc(p->sbp_audsiz*CD_FRAMESIZE_RAW);
  5587. if (p->aud_buf==NULL) msg(DBG_INF,"audio buffer (%d frames) not available.\n",p->sbp_audsiz);
  5588. else msg(DBG_INF,"audio buffer size: %d frames.\n",p->sbp_audsiz);
  5589. }
  5590. sbpcd_infop = vmalloc(sizeof (struct cdrom_device_info));
  5591. if (sbpcd_infop == NULL)
  5592. {
  5593. release_region(CDo_command,4);
  5594. blk_cleanup_queue(sbpcd_queue);
  5595. return -ENOMEM;
  5596. }
  5597. memset(sbpcd_infop, 0, sizeof(struct cdrom_device_info));
  5598. sbpcd_infop->ops = &sbpcd_dops;
  5599. sbpcd_infop->speed = 2;
  5600. sbpcd_infop->capacity = 1;
  5601. sprintf(sbpcd_infop->name, "sbpcd%d", j);
  5602. sbpcd_infop->handle = p;
  5603. p->sbpcd_infop = sbpcd_infop;
  5604. disk = alloc_disk(1);
  5605. disk->major = MAJOR_NR;
  5606. disk->first_minor = j;
  5607. disk->fops = &sbpcd_bdops;
  5608. strcpy(disk->disk_name, sbpcd_infop->name);
  5609. disk->flags = GENHD_FL_CD;
  5610. p->disk = disk;
  5611. if (register_cdrom(sbpcd_infop))
  5612. {
  5613. printk(" sbpcd: Unable to register with Uniform CD-ROm driver\n");
  5614. }
  5615. disk->private_data = p;
  5616. disk->queue = sbpcd_queue;
  5617. add_disk(disk);
  5618. }
  5619. blk_queue_hardsect_size(sbpcd_queue, CD_FRAMESIZE);
  5620. #ifndef MODULE
  5621. init_done:
  5622. #endif
  5623. return 0;
  5624. }
  5625. /*==========================================================================*/
  5626. #ifdef MODULE
  5627. static void sbpcd_exit(void)
  5628. {
  5629. int j;
  5630. if ((unregister_blkdev(MAJOR_NR, major_name) == -EINVAL))
  5631. {
  5632. msg(DBG_INF, "What's that: can't unregister %s.\n", major_name);
  5633. return;
  5634. }
  5635. release_region(CDo_command,4);
  5636. blk_cleanup_queue(sbpcd_queue);
  5637. for (j=0;j<NR_SBPCD;j++)
  5638. {
  5639. if (D_S[j].drv_id==-1) continue;
  5640. del_gendisk(D_S[j].disk);
  5641. put_disk(D_S[j].disk);
  5642. vfree(D_S[j].sbp_buf);
  5643. if (D_S[j].sbp_audsiz>0)
  5644. vfree(D_S[j].aud_buf);
  5645. if ((unregister_cdrom(D_S[j].sbpcd_infop) == -EINVAL))
  5646. {
  5647. msg(DBG_INF, "What's that: can't unregister info %s.\n", major_name);
  5648. return;
  5649. }
  5650. vfree(D_S[j].sbpcd_infop);
  5651. }
  5652. msg(DBG_INF, "%s module released.\n", major_name);
  5653. }
  5654. module_init(__sbpcd_init) /*HACK!*/;
  5655. module_exit(sbpcd_exit);
  5656. #endif /* MODULE */
  5657. static int sbpcd_media_changed(struct cdrom_device_info *cdi, int disc_nr)
  5658. {
  5659. struct sbpcd_drive *p = cdi->handle;
  5660. msg(DBG_CHK,"media_check (%s) called\n", cdi->name);
  5661. if (p->CD_changed==0xFF)
  5662. {
  5663. p->CD_changed=0;
  5664. msg(DBG_CHK,"medium changed (drive %s)\n", cdi->name);
  5665. current_drive->diskstate_flags &= ~toc_bit;
  5666. /* we *don't* need invalidate here, it's done by caller */
  5667. current_drive->diskstate_flags &= ~cd_size_bit;
  5668. #ifdef SAFE_MIXED
  5669. current_drive->has_data=0;
  5670. #endif /* SAFE_MIXED */
  5671. return (1);
  5672. }
  5673. else
  5674. return (0);
  5675. }
  5676. MODULE_LICENSE("GPL");
  5677. /* FIXME: Old modules.conf claims MATSUSHITA_CDROM2_MAJOR and CDROM3, but
  5678. AFAICT this doesn't support those majors, so why? --RR 30 Jul 2003 */
  5679. MODULE_ALIAS_BLOCKDEV_MAJOR(MATSUSHITA_CDROM_MAJOR);
  5680. /*==========================================================================*/
  5681. /*
  5682. * Overrides for Emacs so that we follow Linus's tabbing style.
  5683. * Emacs will notice this stuff at the end of the file and automatically
  5684. * adjust the settings for this buffer only. This must remain at the end
  5685. * of the file.
  5686. * ---------------------------------------------------------------------------
  5687. * Local variables:
  5688. * c-indent-level: 8
  5689. * c-brace-imaginary-offset: 0
  5690. * c-brace-offset: -8
  5691. * c-argdecl-indent: 8
  5692. * c-label-offset: -8
  5693. * c-continued-statement-offset: 8
  5694. * c-continued-brace-offset: 0
  5695. * End:
  5696. */