sbpcd.c 167 KB

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