sbpcd.c 167 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975
  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. current->state = TASK_INTERRUPTIBLE;
  783. schedule_timeout(time);
  784. sti();
  785. }
  786. /*==========================================================================*/
  787. #define RETURN_UP(rc) {up(&ioctl_read_sem); return(rc);}
  788. /*==========================================================================*/
  789. /*
  790. * convert logical_block_address to m-s-f_number (3 bytes only)
  791. */
  792. static INLINE void lba2msf(int lba, u_char *msf)
  793. {
  794. lba += CD_MSF_OFFSET;
  795. msf[0] = lba / (CD_SECS*CD_FRAMES);
  796. lba %= CD_SECS*CD_FRAMES;
  797. msf[1] = lba / CD_FRAMES;
  798. msf[2] = lba % CD_FRAMES;
  799. }
  800. /*==========================================================================*/
  801. /*==========================================================================*/
  802. /*
  803. * convert msf-bin to msf-bcd
  804. */
  805. static INLINE void bin2bcdx(u_char *p) /* must work only up to 75 or 99 */
  806. {
  807. *p=((*p/10)<<4)|(*p%10);
  808. }
  809. /*==========================================================================*/
  810. static INLINE u_int blk2msf(u_int blk)
  811. {
  812. MSF msf;
  813. u_int mm;
  814. msf.c[3] = 0;
  815. msf.c[2] = (blk + CD_MSF_OFFSET) / (CD_SECS * CD_FRAMES);
  816. mm = (blk + CD_MSF_OFFSET) % (CD_SECS * CD_FRAMES);
  817. msf.c[1] = mm / CD_FRAMES;
  818. msf.c[0] = mm % CD_FRAMES;
  819. return (msf.n);
  820. }
  821. /*==========================================================================*/
  822. static INLINE u_int make16(u_char rh, u_char rl)
  823. {
  824. return ((rh<<8)|rl);
  825. }
  826. /*==========================================================================*/
  827. static INLINE u_int make32(u_int rh, u_int rl)
  828. {
  829. return ((rh<<16)|rl);
  830. }
  831. /*==========================================================================*/
  832. static INLINE u_char swap_nibbles(u_char i)
  833. {
  834. return ((i<<4)|(i>>4));
  835. }
  836. /*==========================================================================*/
  837. static INLINE u_char byt2bcd(u_char i)
  838. {
  839. return (((i/10)<<4)+i%10);
  840. }
  841. /*==========================================================================*/
  842. static INLINE u_char bcd2bin(u_char bcd)
  843. {
  844. return ((bcd>>4)*10+(bcd&0x0F));
  845. }
  846. /*==========================================================================*/
  847. static INLINE int msf2blk(int msfx)
  848. {
  849. MSF msf;
  850. int i;
  851. msf.n=msfx;
  852. i=(msf.c[2] * CD_SECS + msf.c[1]) * CD_FRAMES + msf.c[0] - CD_MSF_OFFSET;
  853. if (i<0) return (0);
  854. return (i);
  855. }
  856. /*==========================================================================*/
  857. /*
  858. * convert m-s-f_number (3 bytes only) to logical_block_address
  859. */
  860. static INLINE int msf2lba(u_char *msf)
  861. {
  862. int i;
  863. i=(msf[0] * CD_SECS + msf[1]) * CD_FRAMES + msf[2] - CD_MSF_OFFSET;
  864. if (i<0) return (0);
  865. return (i);
  866. }
  867. /*==========================================================================*/
  868. /* evaluate cc_ReadError code */
  869. static int sta2err(int sta)
  870. {
  871. if (famT_drive)
  872. {
  873. if (sta==0x00) return (0);
  874. if (sta==0x01) return (-604); /* CRC error */
  875. if (sta==0x02) return (-602); /* drive not ready */
  876. if (sta==0x03) return (-607); /* unknown media */
  877. if (sta==0x04) return (-612); /* general failure */
  878. if (sta==0x05) return (0);
  879. if (sta==0x06) return (-ERR_DISKCHANGE); /* disk change */
  880. if (sta==0x0b) return (-612); /* general failure */
  881. if (sta==0xff) return (-612); /* general failure */
  882. return (0);
  883. }
  884. else
  885. {
  886. if (sta<=2) return (sta);
  887. if (sta==0x05) return (-604); /* CRC error */
  888. if (sta==0x06) return (-606); /* seek error */
  889. if (sta==0x0d) return (-606); /* seek error */
  890. if (sta==0x0e) return (-603); /* unknown command */
  891. if (sta==0x14) return (-603); /* unknown command */
  892. if (sta==0x0c) return (-611); /* read fault */
  893. if (sta==0x0f) return (-611); /* read fault */
  894. if (sta==0x10) return (-611); /* read fault */
  895. if (sta>=0x16) return (-612); /* general failure */
  896. if (sta==0x11) return (-ERR_DISKCHANGE); /* disk change (LCS: removed) */
  897. if (famL_drive)
  898. if (sta==0x12) return (-ERR_DISKCHANGE); /* disk change (inserted) */
  899. return (-602); /* drive not ready */
  900. }
  901. }
  902. /*==========================================================================*/
  903. static INLINE void clr_cmdbuf(void)
  904. {
  905. int i;
  906. for (i=0;i<10;i++) drvcmd[i]=0;
  907. cmd_type=0;
  908. }
  909. /*==========================================================================*/
  910. static void flush_status(void)
  911. {
  912. int i;
  913. sbp_sleep(15*HZ/10);
  914. for (i=maxtim_data;i!=0;i--) inb(CDi_status);
  915. }
  916. /*====================================================================*/
  917. /*
  918. * CDi status loop for Teac CD-55A (Rob Riggs)
  919. *
  920. * This is needed because for some strange reason
  921. * the CD-55A can take a real long time to give a
  922. * status response. This seems to happen after we
  923. * issue a READ command where a long seek is involved.
  924. *
  925. * I tried to ensure that we get max throughput with
  926. * minimal busy waiting. We busy wait at first, then
  927. * "switch gears" and start sleeping. We sleep for
  928. * longer periods of time the longer we wait.
  929. *
  930. */
  931. static int CDi_stat_loop_T(void)
  932. {
  933. int i, gear=1;
  934. u_long timeout_1, timeout_2, timeout_3, timeout_4;
  935. timeout_1 = jiffies + HZ / 50; /* sbp_sleep(0) for a short period */
  936. timeout_2 = jiffies + HZ / 5; /* nap for no more than 200ms */
  937. timeout_3 = jiffies + 5 * HZ; /* sleep for up to 5s */
  938. timeout_4 = jiffies + 45 * HZ; /* long sleep for up to 45s. */
  939. do
  940. {
  941. i = inb(CDi_status);
  942. if (!(i&s_not_data_ready)) return (i);
  943. if (!(i&s_not_result_ready)) return (i);
  944. switch(gear)
  945. {
  946. case 4:
  947. sbp_sleep(HZ);
  948. if (time_after(jiffies, timeout_4)) gear++;
  949. msg(DBG_TEA, "CDi_stat_loop_T: long sleep active.\n");
  950. break;
  951. case 3:
  952. sbp_sleep(HZ/10);
  953. if (time_after(jiffies, timeout_3)) gear++;
  954. break;
  955. case 2:
  956. sbp_sleep(HZ/100);
  957. if (time_after(jiffies, timeout_2)) gear++;
  958. break;
  959. case 1:
  960. sbp_sleep(0);
  961. if (time_after(jiffies, timeout_1)) gear++;
  962. }
  963. } while (gear < 5);
  964. return -1;
  965. }
  966. /*==========================================================================*/
  967. static int CDi_stat_loop(void)
  968. {
  969. int i,j;
  970. for(timeout = jiffies + 10*HZ, i=maxtim_data; time_before(jiffies, timeout); )
  971. {
  972. for ( ;i!=0;i--)
  973. {
  974. j=inb(CDi_status);
  975. if (!(j&s_not_data_ready)) return (j);
  976. if (!(j&s_not_result_ready)) return (j);
  977. if (fam0L_drive) if (j&s_attention) return (j);
  978. }
  979. sbp_sleep(1);
  980. i = 1;
  981. }
  982. msg(DBG_LCS,"CDi_stat_loop failed in line %d\n", __LINE__);
  983. return (-1);
  984. }
  985. /*==========================================================================*/
  986. #if 00000
  987. /*==========================================================================*/
  988. static int tst_DataReady(void)
  989. {
  990. int i;
  991. i=inb(CDi_status);
  992. if (i&s_not_data_ready) return (0);
  993. return (1);
  994. }
  995. /*==========================================================================*/
  996. static int tst_ResultReady(void)
  997. {
  998. int i;
  999. i=inb(CDi_status);
  1000. if (i&s_not_result_ready) return (0);
  1001. return (1);
  1002. }
  1003. /*==========================================================================*/
  1004. static int tst_Attention(void)
  1005. {
  1006. int i;
  1007. i=inb(CDi_status);
  1008. if (i&s_attention) return (1);
  1009. return (0);
  1010. }
  1011. /*==========================================================================*/
  1012. #endif
  1013. /*==========================================================================*/
  1014. static int ResponseInfo(void)
  1015. {
  1016. int i,j,st=0;
  1017. u_long timeout;
  1018. for (i=0,timeout=jiffies+HZ;i<response_count;i++)
  1019. {
  1020. for (j=maxtim_data; ; )
  1021. {
  1022. for ( ;j!=0;j-- )
  1023. {
  1024. st=inb(CDi_status);
  1025. if (!(st&s_not_result_ready)) break;
  1026. }
  1027. if ((j!=0)||time_after_eq(jiffies, timeout)) break;
  1028. sbp_sleep(1);
  1029. j = 1;
  1030. }
  1031. if (time_after_eq(jiffies, timeout)) break;
  1032. infobuf[i]=inb(CDi_info);
  1033. }
  1034. #if 000
  1035. while (!(inb(CDi_status)&s_not_result_ready))
  1036. {
  1037. infobuf[i++]=inb(CDi_info);
  1038. }
  1039. j=i-response_count;
  1040. if (j>0) msg(DBG_INF,"ResponseInfo: got %d trailing bytes.\n",j);
  1041. #endif /* 000 */
  1042. for (j=0;j<i;j++)
  1043. sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
  1044. msgbuf[j*3]=0;
  1045. msg(DBG_CMD,"ResponseInfo:%s (%d,%d)\n",msgbuf,response_count,i);
  1046. j=response_count-i;
  1047. if (j>0) return (-j);
  1048. else return (i);
  1049. }
  1050. /*==========================================================================*/
  1051. static void EvaluateStatus(int st)
  1052. {
  1053. current_drive->status_bits=0;
  1054. if (fam1_drive) current_drive->status_bits=st|p_success;
  1055. else if (fam0_drive)
  1056. {
  1057. if (st&p_caddin_old) current_drive->status_bits |= p_door_closed|p_caddy_in;
  1058. if (st&p_spinning) current_drive->status_bits |= p_spinning;
  1059. if (st&p_check) current_drive->status_bits |= p_check;
  1060. if (st&p_success_old) current_drive->status_bits |= p_success;
  1061. if (st&p_busy_old) current_drive->status_bits |= p_busy_new;
  1062. if (st&p_disk_ok) current_drive->status_bits |= p_disk_ok;
  1063. }
  1064. else if (famLV_drive)
  1065. {
  1066. current_drive->status_bits |= p_success;
  1067. if (st&p_caddin_old) current_drive->status_bits |= p_disk_ok|p_caddy_in;
  1068. if (st&p_spinning) current_drive->status_bits |= p_spinning;
  1069. if (st&p_check) current_drive->status_bits |= p_check;
  1070. if (st&p_busy_old) current_drive->status_bits |= p_busy_new;
  1071. if (st&p_lcs_door_closed) current_drive->status_bits |= p_door_closed;
  1072. if (st&p_lcs_door_locked) current_drive->status_bits |= p_door_locked;
  1073. }
  1074. else if (fam2_drive)
  1075. {
  1076. current_drive->status_bits |= p_success;
  1077. if (st&p2_check) current_drive->status_bits |= p1_check;
  1078. if (st&p2_door_closed) current_drive->status_bits |= p1_door_closed;
  1079. if (st&p2_disk_in) current_drive->status_bits |= p1_disk_in;
  1080. if (st&p2_busy1) current_drive->status_bits |= p1_busy;
  1081. if (st&p2_busy2) current_drive->status_bits |= p1_busy;
  1082. if (st&p2_spinning) current_drive->status_bits |= p1_spinning;
  1083. if (st&p2_door_locked) current_drive->status_bits |= p1_door_locked;
  1084. if (st&p2_disk_ok) current_drive->status_bits |= p1_disk_ok;
  1085. }
  1086. else if (famT_drive)
  1087. {
  1088. return; /* still needs to get coded */
  1089. current_drive->status_bits |= p_success;
  1090. if (st&p2_check) current_drive->status_bits |= p1_check;
  1091. if (st&p2_door_closed) current_drive->status_bits |= p1_door_closed;
  1092. if (st&p2_disk_in) current_drive->status_bits |= p1_disk_in;
  1093. if (st&p2_busy1) current_drive->status_bits |= p1_busy;
  1094. if (st&p2_busy2) current_drive->status_bits |= p1_busy;
  1095. if (st&p2_spinning) current_drive->status_bits |= p1_spinning;
  1096. if (st&p2_door_locked) current_drive->status_bits |= p1_door_locked;
  1097. if (st&p2_disk_ok) current_drive->status_bits |= p1_disk_ok;
  1098. }
  1099. return;
  1100. }
  1101. /*==========================================================================*/
  1102. static int cmd_out_T(void);
  1103. static int get_state_T(void)
  1104. {
  1105. int i;
  1106. clr_cmdbuf();
  1107. current_drive->n_bytes=1;
  1108. drvcmd[0]=CMDT_STATUS;
  1109. i=cmd_out_T();
  1110. if (i>=0) i=infobuf[0];
  1111. else
  1112. {
  1113. msg(DBG_TEA,"get_state_T error %d\n", i);
  1114. return (i);
  1115. }
  1116. if (i>=0)
  1117. /* 2: closed, disk in */
  1118. current_drive->status_bits=p1_door_closed|p1_disk_in|p1_spinning|p1_disk_ok;
  1119. else if (current_drive->error_state==6)
  1120. {
  1121. /* 3: closed, disk in, changed ("06 xx xx") */
  1122. current_drive->status_bits=p1_door_closed|p1_disk_in;
  1123. current_drive->CD_changed=0xFF;
  1124. current_drive->diskstate_flags &= ~toc_bit;
  1125. }
  1126. else if ((current_drive->error_state!=2)||(current_drive->b3!=0x3A)||(current_drive->b4==0x00))
  1127. {
  1128. /* 1: closed, no disk ("xx yy zz"or "02 3A 00") */
  1129. current_drive->status_bits=p1_door_closed;
  1130. current_drive->open_count=0;
  1131. }
  1132. else if (current_drive->b4==0x01)
  1133. {
  1134. /* 0: open ("02 3A 01") */
  1135. current_drive->status_bits=0;
  1136. current_drive->open_count=0;
  1137. }
  1138. else
  1139. {
  1140. /* 1: closed, no disk ("02 3A xx") */
  1141. current_drive->status_bits=p1_door_closed;
  1142. current_drive->open_count=0;
  1143. }
  1144. return (current_drive->status_bits);
  1145. }
  1146. /*==========================================================================*/
  1147. static int ResponseStatus(void)
  1148. {
  1149. int i,j;
  1150. u_long timeout;
  1151. msg(DBG_STA,"doing ResponseStatus...\n");
  1152. if (famT_drive) return (get_state_T());
  1153. if (flags_cmd_out & f_respo3) timeout = jiffies;
  1154. else if (flags_cmd_out & f_respo2) timeout = jiffies + 16*HZ;
  1155. else timeout = jiffies + 4*HZ;
  1156. j=maxtim_8;
  1157. do
  1158. {
  1159. for ( ;j!=0;j--)
  1160. {
  1161. i=inb(CDi_status);
  1162. if (!(i&s_not_result_ready)) break;
  1163. }
  1164. if ((j!=0)||time_after(jiffies, timeout)) break;
  1165. sbp_sleep(1);
  1166. j = 1;
  1167. }
  1168. while (1);
  1169. if (j==0)
  1170. {
  1171. if ((flags_cmd_out & f_respo3) == 0)
  1172. msg(DBG_STA,"ResponseStatus: timeout.\n");
  1173. current_drive->status_bits=0;
  1174. return (-401);
  1175. }
  1176. i=inb(CDi_info);
  1177. msg(DBG_STA,"ResponseStatus: response %02X.\n", i);
  1178. EvaluateStatus(i);
  1179. msg(DBG_STA,"status_bits=%02X, i=%02X\n",current_drive->status_bits,i);
  1180. return (current_drive->status_bits);
  1181. }
  1182. /*==========================================================================*/
  1183. static void cc_ReadStatus(void)
  1184. {
  1185. int i;
  1186. msg(DBG_STA,"giving cc_ReadStatus command\n");
  1187. if (famT_drive) return;
  1188. SBPCD_CLI;
  1189. if (fam0LV_drive) OUT(CDo_command,CMD0_STATUS);
  1190. else if (fam1_drive) OUT(CDo_command,CMD1_STATUS);
  1191. else if (fam2_drive) OUT(CDo_command,CMD2_STATUS);
  1192. if (!fam0LV_drive) for (i=0;i<6;i++) OUT(CDo_command,0);
  1193. SBPCD_STI;
  1194. }
  1195. /*==========================================================================*/
  1196. static int cc_ReadError(void)
  1197. {
  1198. int i;
  1199. clr_cmdbuf();
  1200. msg(DBG_ERR,"giving cc_ReadError command.\n");
  1201. if (fam1_drive)
  1202. {
  1203. drvcmd[0]=CMD1_READ_ERR;
  1204. response_count=8;
  1205. flags_cmd_out=f_putcmd|f_ResponseStatus;
  1206. }
  1207. else if (fam0LV_drive)
  1208. {
  1209. drvcmd[0]=CMD0_READ_ERR;
  1210. response_count=6;
  1211. if (famLV_drive)
  1212. flags_cmd_out=f_putcmd;
  1213. else
  1214. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus;
  1215. }
  1216. else if (fam2_drive)
  1217. {
  1218. drvcmd[0]=CMD2_READ_ERR;
  1219. response_count=6;
  1220. flags_cmd_out=f_putcmd;
  1221. }
  1222. else if (famT_drive)
  1223. {
  1224. response_count=5;
  1225. drvcmd[0]=CMDT_READ_ERR;
  1226. }
  1227. i=cmd_out();
  1228. current_drive->error_byte=0;
  1229. msg(DBG_ERR,"cc_ReadError: cmd_out(CMDx_READ_ERR) returns %d (%02X)\n",i,i);
  1230. if (i<0) return (i);
  1231. if (fam0V_drive) i=1;
  1232. else i=2;
  1233. current_drive->error_byte=infobuf[i];
  1234. msg(DBG_ERR,"cc_ReadError: infobuf[%d] is %d (%02X)\n",i,current_drive->error_byte,current_drive->error_byte);
  1235. i=sta2err(infobuf[i]);
  1236. if (i==-ERR_DISKCHANGE)
  1237. {
  1238. current_drive->CD_changed=0xFF;
  1239. current_drive->diskstate_flags &= ~toc_bit;
  1240. }
  1241. return (i);
  1242. }
  1243. /*==========================================================================*/
  1244. static int cc_DriveReset(void);
  1245. static int cmd_out_T(void)
  1246. {
  1247. #undef CMDT_TRIES
  1248. #define CMDT_TRIES 1000
  1249. #define TEST_FALSE_FF 1
  1250. int i, j, l=0, m, ntries;
  1251. unsigned long flags;
  1252. current_drive->error_state=0;
  1253. current_drive->b3=0;
  1254. current_drive->b4=0;
  1255. current_drive->f_drv_error=0;
  1256. for (i=0;i<10;i++) sprintf(&msgbuf[i*3]," %02X",drvcmd[i]);
  1257. msgbuf[i*3]=0;
  1258. msg(DBG_CMD,"cmd_out_T:%s\n",msgbuf);
  1259. OUT(CDo_sel_i_d,0);
  1260. OUT(CDo_enable,current_drive->drv_sel);
  1261. i=inb(CDi_status);
  1262. do_16bit=0;
  1263. if ((f_16bit)&&(!(i&0x80)))
  1264. {
  1265. do_16bit=1;
  1266. msg(DBG_TEA,"cmd_out_T: do_16bit set.\n");
  1267. }
  1268. if (!(i&s_not_result_ready))
  1269. do
  1270. {
  1271. j=inb(CDi_info);
  1272. i=inb(CDi_status);
  1273. sbp_sleep(0);
  1274. msg(DBG_TEA,"cmd_out_T: spurious !s_not_result_ready. (%02X)\n", j);
  1275. }
  1276. while (!(i&s_not_result_ready));
  1277. save_flags(flags); cli();
  1278. for (i=0;i<10;i++) OUT(CDo_command,drvcmd[i]);
  1279. restore_flags(flags);
  1280. for (ntries=CMDT_TRIES;ntries>0;ntries--)
  1281. {
  1282. if (drvcmd[0]==CMDT_READ_VER) sbp_sleep(HZ); /* fixme */
  1283. #if 01
  1284. OUT(CDo_sel_i_d,1);
  1285. #endif /* 01 */
  1286. if (teac==2)
  1287. {
  1288. if ((i=CDi_stat_loop_T()) == -1) break;
  1289. }
  1290. else
  1291. {
  1292. #if 0
  1293. OUT(CDo_sel_i_d,1);
  1294. #endif /* 0 */
  1295. i=inb(CDi_status);
  1296. }
  1297. if (!(i&s_not_data_ready)) /* f.e. CMDT_DISKINFO */
  1298. {
  1299. OUT(CDo_sel_i_d,1);
  1300. if (drvcmd[0]==CMDT_READ) return (0); /* handled elsewhere */
  1301. if (drvcmd[0]==CMDT_DISKINFO)
  1302. {
  1303. l=0;
  1304. do
  1305. {
  1306. if (do_16bit)
  1307. {
  1308. i=inw(CDi_data);
  1309. infobuf[l++]=i&0x0ff;
  1310. infobuf[l++]=i>>8;
  1311. #if TEST_FALSE_FF
  1312. if ((l==2)&&(infobuf[0]==0x0ff))
  1313. {
  1314. infobuf[0]=infobuf[1];
  1315. l=1;
  1316. msg(DBG_TEA,"cmd_out_T: do_16bit: false first byte!\n");
  1317. }
  1318. #endif /* TEST_FALSE_FF */
  1319. }
  1320. else infobuf[l++]=inb(CDi_data);
  1321. i=inb(CDi_status);
  1322. }
  1323. while (!(i&s_not_data_ready));
  1324. for (j=0;j<l;j++) sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
  1325. msgbuf[j*3]=0;
  1326. msg(DBG_CMD,"cmd_out_T data response:%s\n", msgbuf);
  1327. }
  1328. else
  1329. {
  1330. msg(DBG_TEA,"cmd_out_T: data response with cmd_%02X!\n",
  1331. drvcmd[0]);
  1332. j=0;
  1333. do
  1334. {
  1335. if (do_16bit) i=inw(CDi_data);
  1336. else i=inb(CDi_data);
  1337. j++;
  1338. i=inb(CDi_status);
  1339. }
  1340. while (!(i&s_not_data_ready));
  1341. msg(DBG_TEA,"cmd_out_T: data response: discarded %d bytes/words.\n", j);
  1342. fatal_err++;
  1343. }
  1344. }
  1345. i=inb(CDi_status);
  1346. if (!(i&s_not_result_ready))
  1347. {
  1348. OUT(CDo_sel_i_d,0);
  1349. if (drvcmd[0]==CMDT_DISKINFO) m=l;
  1350. else m=0;
  1351. do
  1352. {
  1353. infobuf[m++]=inb(CDi_info);
  1354. i=inb(CDi_status);
  1355. }
  1356. while (!(i&s_not_result_ready));
  1357. for (j=0;j<m;j++) sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
  1358. msgbuf[j*3]=0;
  1359. msg(DBG_CMD,"cmd_out_T info response:%s\n", msgbuf);
  1360. if (drvcmd[0]==CMDT_DISKINFO)
  1361. {
  1362. infobuf[0]=infobuf[l];
  1363. if (infobuf[0]!=0x02) return (l); /* data length */
  1364. }
  1365. else if (infobuf[0]!=0x02) return (m); /* info length */
  1366. do
  1367. {
  1368. ++recursion;
  1369. if (recursion>1) msg(DBG_TEA,"cmd_out_T READ_ERR recursion (%02X): %d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", drvcmd[0], recursion);
  1370. clr_cmdbuf();
  1371. drvcmd[0]=CMDT_READ_ERR;
  1372. j=cmd_out_T(); /* !!! recursive here !!! */
  1373. --recursion;
  1374. sbp_sleep(1);
  1375. }
  1376. while (j<0);
  1377. current_drive->error_state=infobuf[2];
  1378. current_drive->b3=infobuf[3];
  1379. current_drive->b4=infobuf[4];
  1380. if (current_drive->f_drv_error)
  1381. {
  1382. current_drive->f_drv_error=0;
  1383. cc_DriveReset();
  1384. current_drive->error_state=2;
  1385. }
  1386. return (-current_drive->error_state-400);
  1387. }
  1388. if (drvcmd[0]==CMDT_READ) return (0); /* handled elsewhere */
  1389. if ((teac==0)||(ntries<(CMDT_TRIES-5))) sbp_sleep(HZ/10);
  1390. else sbp_sleep(HZ/100);
  1391. if (ntries>(CMDT_TRIES-50)) continue;
  1392. msg(DBG_TEA,"cmd_out_T: next CMDT_TRIES (%02X): %d.\n", drvcmd[0], ntries-1);
  1393. }
  1394. current_drive->f_drv_error=1;
  1395. cc_DriveReset();
  1396. current_drive->error_state=2;
  1397. return (-99);
  1398. }
  1399. /*==========================================================================*/
  1400. static int cmd_out(void)
  1401. {
  1402. int i=0;
  1403. if (famT_drive) return(cmd_out_T());
  1404. if (flags_cmd_out&f_putcmd)
  1405. {
  1406. unsigned long flags;
  1407. for (i=0;i<7;i++)
  1408. sprintf(&msgbuf[i*3], " %02X", drvcmd[i]);
  1409. msgbuf[i*3]=0;
  1410. msg(DBG_CMD,"cmd_out:%s\n", msgbuf);
  1411. save_flags(flags); cli();
  1412. for (i=0;i<7;i++) OUT(CDo_command,drvcmd[i]);
  1413. restore_flags(flags);
  1414. }
  1415. if (response_count!=0)
  1416. {
  1417. if (cmd_type!=0)
  1418. {
  1419. if (sbpro_type==1) OUT(CDo_sel_i_d,1);
  1420. msg(DBG_INF,"misleaded to try ResponseData.\n");
  1421. if (sbpro_type==1) OUT(CDo_sel_i_d,0);
  1422. return (-22);
  1423. }
  1424. else i=ResponseInfo();
  1425. if (i<0) return (i);
  1426. }
  1427. if (current_drive->in_SpinUp) msg(DBG_SPI,"in_SpinUp: to CDi_stat_loop.\n");
  1428. if (flags_cmd_out&f_lopsta)
  1429. {
  1430. i=CDi_stat_loop();
  1431. if ((i<0)||!(i&s_attention)) return (-8);
  1432. }
  1433. if (!(flags_cmd_out&f_getsta)) goto LOC_229;
  1434. LOC_228:
  1435. if (current_drive->in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cc_ReadStatus.\n");
  1436. cc_ReadStatus();
  1437. LOC_229:
  1438. if (flags_cmd_out&f_ResponseStatus)
  1439. {
  1440. if (current_drive->in_SpinUp) msg(DBG_SPI,"in_SpinUp: to ResponseStatus.\n");
  1441. i=ResponseStatus();
  1442. /* builds status_bits, returns orig. status or p_busy_new */
  1443. if (i<0) return (i);
  1444. if (flags_cmd_out&(f_bit1|f_wait_if_busy))
  1445. {
  1446. if (!st_check)
  1447. {
  1448. if ((flags_cmd_out&f_bit1)&&(i&p_success)) goto LOC_232;
  1449. if ((!(flags_cmd_out&f_wait_if_busy))||(!st_busy)) goto LOC_228;
  1450. }
  1451. }
  1452. }
  1453. LOC_232:
  1454. if (!(flags_cmd_out&f_obey_p_check)) return (0);
  1455. if (!st_check) return (0);
  1456. if (current_drive->in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cc_ReadError.\n");
  1457. i=cc_ReadError();
  1458. if (current_drive->in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cmd_out OK.\n");
  1459. msg(DBG_000,"cmd_out: cc_ReadError=%d\n", i);
  1460. return (i);
  1461. }
  1462. /*==========================================================================*/
  1463. static int cc_Seek(u_int pos, char f_blk_msf)
  1464. {
  1465. int i;
  1466. clr_cmdbuf();
  1467. if (f_blk_msf>1) return (-3);
  1468. if (fam0V_drive)
  1469. {
  1470. drvcmd[0]=CMD0_SEEK;
  1471. if (f_blk_msf==1) pos=msf2blk(pos);
  1472. drvcmd[2]=(pos>>16)&0x00FF;
  1473. drvcmd[3]=(pos>>8)&0x00FF;
  1474. drvcmd[4]=pos&0x00FF;
  1475. if (fam0_drive)
  1476. flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
  1477. f_ResponseStatus | f_obey_p_check | f_bit1;
  1478. else
  1479. flags_cmd_out = f_putcmd;
  1480. }
  1481. else if (fam1L_drive)
  1482. {
  1483. drvcmd[0]=CMD1_SEEK; /* same as CMD1_ and CMDL_ */
  1484. if (f_blk_msf==0) pos=blk2msf(pos);
  1485. drvcmd[1]=(pos>>16)&0x00FF;
  1486. drvcmd[2]=(pos>>8)&0x00FF;
  1487. drvcmd[3]=pos&0x00FF;
  1488. if (famL_drive)
  1489. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  1490. else
  1491. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  1492. }
  1493. else if (fam2_drive)
  1494. {
  1495. drvcmd[0]=CMD2_SEEK;
  1496. if (f_blk_msf==0) pos=blk2msf(pos);
  1497. drvcmd[2]=(pos>>24)&0x00FF;
  1498. drvcmd[3]=(pos>>16)&0x00FF;
  1499. drvcmd[4]=(pos>>8)&0x00FF;
  1500. drvcmd[5]=pos&0x00FF;
  1501. flags_cmd_out=f_putcmd|f_ResponseStatus;
  1502. }
  1503. else if (famT_drive)
  1504. {
  1505. drvcmd[0]=CMDT_SEEK;
  1506. if (f_blk_msf==1) pos=msf2blk(pos);
  1507. drvcmd[2]=(pos>>24)&0x00FF;
  1508. drvcmd[3]=(pos>>16)&0x00FF;
  1509. drvcmd[4]=(pos>>8)&0x00FF;
  1510. drvcmd[5]=pos&0x00FF;
  1511. current_drive->n_bytes=1;
  1512. }
  1513. response_count=0;
  1514. i=cmd_out();
  1515. return (i);
  1516. }
  1517. /*==========================================================================*/
  1518. static int cc_SpinUp(void)
  1519. {
  1520. int i;
  1521. msg(DBG_SPI,"SpinUp.\n");
  1522. current_drive->in_SpinUp = 1;
  1523. clr_cmdbuf();
  1524. if (fam0LV_drive)
  1525. {
  1526. drvcmd[0]=CMD0_SPINUP;
  1527. if (fam0L_drive)
  1528. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|
  1529. f_ResponseStatus|f_obey_p_check|f_bit1;
  1530. else
  1531. flags_cmd_out=f_putcmd;
  1532. }
  1533. else if (fam1_drive)
  1534. {
  1535. drvcmd[0]=CMD1_SPINUP;
  1536. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  1537. }
  1538. else if (fam2_drive)
  1539. {
  1540. drvcmd[0]=CMD2_TRAY_CTL;
  1541. drvcmd[4]=0x01; /* "spinup" */
  1542. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  1543. }
  1544. else if (famT_drive)
  1545. {
  1546. drvcmd[0]=CMDT_TRAY_CTL;
  1547. drvcmd[4]=0x03; /* "insert", it hopefully spins the drive up */
  1548. }
  1549. response_count=0;
  1550. i=cmd_out();
  1551. current_drive->in_SpinUp = 0;
  1552. return (i);
  1553. }
  1554. /*==========================================================================*/
  1555. static int cc_SpinDown(void)
  1556. {
  1557. int i;
  1558. if (fam0_drive) return (0);
  1559. clr_cmdbuf();
  1560. response_count=0;
  1561. if (fam1_drive)
  1562. {
  1563. drvcmd[0]=CMD1_SPINDOWN;
  1564. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  1565. }
  1566. else if (fam2_drive)
  1567. {
  1568. drvcmd[0]=CMD2_TRAY_CTL;
  1569. drvcmd[4]=0x02; /* "eject" */
  1570. flags_cmd_out=f_putcmd|f_ResponseStatus;
  1571. }
  1572. else if (famL_drive)
  1573. {
  1574. drvcmd[0]=CMDL_SPINDOWN;
  1575. drvcmd[1]=1;
  1576. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  1577. }
  1578. else if (famV_drive)
  1579. {
  1580. drvcmd[0]=CMDV_SPINDOWN;
  1581. flags_cmd_out=f_putcmd;
  1582. }
  1583. else if (famT_drive)
  1584. {
  1585. drvcmd[0]=CMDT_TRAY_CTL;
  1586. drvcmd[4]=0x02; /* "eject" */
  1587. }
  1588. i=cmd_out();
  1589. return (i);
  1590. }
  1591. /*==========================================================================*/
  1592. static int cc_get_mode_T(void)
  1593. {
  1594. int i;
  1595. clr_cmdbuf();
  1596. response_count=10;
  1597. drvcmd[0]=CMDT_GETMODE;
  1598. drvcmd[4]=response_count;
  1599. i=cmd_out_T();
  1600. return (i);
  1601. }
  1602. /*==========================================================================*/
  1603. static int cc_set_mode_T(void)
  1604. {
  1605. int i;
  1606. clr_cmdbuf();
  1607. response_count=1;
  1608. drvcmd[0]=CMDT_SETMODE;
  1609. drvcmd[1]=current_drive->speed_byte;
  1610. drvcmd[2]=current_drive->frmsiz>>8;
  1611. drvcmd[3]=current_drive->frmsiz&0x0FF;
  1612. drvcmd[4]=current_drive->f_XA; /* 1: XA */
  1613. drvcmd[5]=current_drive->type_byte; /* 0, 1, 3 */
  1614. drvcmd[6]=current_drive->mode_xb_6;
  1615. drvcmd[7]=current_drive->mode_yb_7|current_drive->volume_control;
  1616. drvcmd[8]=current_drive->mode_xb_8;
  1617. drvcmd[9]=current_drive->delay;
  1618. i=cmd_out_T();
  1619. return (i);
  1620. }
  1621. /*==========================================================================*/
  1622. static int cc_prep_mode_T(void)
  1623. {
  1624. int i, j;
  1625. i=cc_get_mode_T();
  1626. if (i<0) return (i);
  1627. for (i=0;i<10;i++)
  1628. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  1629. msgbuf[i*3]=0;
  1630. msg(DBG_TEA,"CMDT_GETMODE:%s\n", msgbuf);
  1631. current_drive->speed_byte=0x02; /* 0x02: auto quad, 0x82: quad, 0x81: double, 0x80: single */
  1632. current_drive->frmsiz=make16(infobuf[2],infobuf[3]);
  1633. current_drive->f_XA=infobuf[4];
  1634. if (current_drive->f_XA==0) current_drive->type_byte=0;
  1635. else current_drive->type_byte=1;
  1636. current_drive->mode_xb_6=infobuf[6];
  1637. current_drive->mode_yb_7=1;
  1638. current_drive->mode_xb_8=infobuf[8];
  1639. current_drive->delay=0; /* 0, 1, 2, 3 */
  1640. j=cc_set_mode_T();
  1641. i=cc_get_mode_T();
  1642. for (i=0;i<10;i++)
  1643. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  1644. msgbuf[i*3]=0;
  1645. msg(DBG_TEA,"CMDT_GETMODE:%s\n", msgbuf);
  1646. return (j);
  1647. }
  1648. /*==========================================================================*/
  1649. static int cc_SetSpeed(u_char speed, u_char x1, u_char x2)
  1650. {
  1651. int i;
  1652. if (fam0LV_drive) return (0);
  1653. clr_cmdbuf();
  1654. response_count=0;
  1655. if (fam1_drive)
  1656. {
  1657. drvcmd[0]=CMD1_SETMODE;
  1658. drvcmd[1]=0x03;
  1659. drvcmd[2]=speed;
  1660. drvcmd[3]=x1;
  1661. drvcmd[4]=x2;
  1662. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  1663. }
  1664. else if (fam2_drive)
  1665. {
  1666. drvcmd[0]=CMD2_SETSPEED;
  1667. if (speed&speed_auto)
  1668. {
  1669. drvcmd[2]=0xFF;
  1670. drvcmd[3]=0xFF;
  1671. }
  1672. else
  1673. {
  1674. drvcmd[2]=0;
  1675. drvcmd[3]=150;
  1676. }
  1677. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  1678. }
  1679. else if (famT_drive)
  1680. {
  1681. return (0);
  1682. }
  1683. i=cmd_out();
  1684. return (i);
  1685. }
  1686. /*==========================================================================*/
  1687. static int cc_SetVolume(void)
  1688. {
  1689. int i;
  1690. u_char channel0,channel1,volume0,volume1;
  1691. u_char control0,value0,control1,value1;
  1692. current_drive->diskstate_flags &= ~volume_bit;
  1693. clr_cmdbuf();
  1694. channel0=current_drive->vol_chan0;
  1695. volume0=current_drive->vol_ctrl0;
  1696. channel1=control1=current_drive->vol_chan1;
  1697. volume1=value1=current_drive->vol_ctrl1;
  1698. control0=value0=0;
  1699. if (famV_drive) return (0);
  1700. if (((current_drive->drv_options&audio_mono)!=0)&&(current_drive->drv_type>=drv_211))
  1701. {
  1702. if ((volume0!=0)&&(volume1==0))
  1703. {
  1704. volume1=volume0;
  1705. channel1=channel0;
  1706. }
  1707. else if ((volume0==0)&&(volume1!=0))
  1708. {
  1709. volume0=volume1;
  1710. channel0=channel1;
  1711. }
  1712. }
  1713. if (channel0>1)
  1714. {
  1715. channel0=0;
  1716. volume0=0;
  1717. }
  1718. if (channel1>1)
  1719. {
  1720. channel1=1;
  1721. volume1=0;
  1722. }
  1723. if (fam1_drive)
  1724. {
  1725. control0=channel0+1;
  1726. control1=channel1+1;
  1727. value0=(volume0>volume1)?volume0:volume1;
  1728. value1=value0;
  1729. if (volume0==0) control0=0;
  1730. if (volume1==0) control1=0;
  1731. drvcmd[0]=CMD1_SETMODE;
  1732. drvcmd[1]=0x05;
  1733. drvcmd[3]=control0;
  1734. drvcmd[4]=value0;
  1735. drvcmd[5]=control1;
  1736. drvcmd[6]=value1;
  1737. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  1738. }
  1739. else if (fam2_drive)
  1740. {
  1741. control0=channel0+1;
  1742. control1=channel1+1;
  1743. value0=(volume0>volume1)?volume0:volume1;
  1744. value1=value0;
  1745. if (volume0==0) control0=0;
  1746. if (volume1==0) control1=0;
  1747. drvcmd[0]=CMD2_SETMODE;
  1748. drvcmd[1]=0x0E;
  1749. drvcmd[3]=control0;
  1750. drvcmd[4]=value0;
  1751. drvcmd[5]=control1;
  1752. drvcmd[6]=value1;
  1753. flags_cmd_out=f_putcmd|f_ResponseStatus;
  1754. }
  1755. else if (famL_drive)
  1756. {
  1757. if ((volume0==0)||(channel0!=0)) control0 |= 0x80;
  1758. if ((volume1==0)||(channel1!=1)) control0 |= 0x40;
  1759. if (volume0|volume1) value0=0x80;
  1760. drvcmd[0]=CMDL_SETMODE;
  1761. drvcmd[1]=0x03;
  1762. drvcmd[4]=control0;
  1763. drvcmd[5]=value0;
  1764. flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  1765. }
  1766. else if (fam0_drive) /* different firmware levels */
  1767. {
  1768. if (current_drive->drv_type>=drv_300)
  1769. {
  1770. control0=volume0&0xFC;
  1771. value0=volume1&0xFC;
  1772. if ((volume0!=0)&&(volume0<4)) control0 |= 0x04;
  1773. if ((volume1!=0)&&(volume1<4)) value0 |= 0x04;
  1774. if (channel0!=0) control0 |= 0x01;
  1775. if (channel1==1) value0 |= 0x01;
  1776. }
  1777. else
  1778. {
  1779. value0=(volume0>volume1)?volume0:volume1;
  1780. if (current_drive->drv_type<drv_211)
  1781. {
  1782. if (channel0!=0)
  1783. {
  1784. i=channel1;
  1785. channel1=channel0;
  1786. channel0=i;
  1787. i=volume1;
  1788. volume1=volume0;
  1789. volume0=i;
  1790. }
  1791. if (channel0==channel1)
  1792. {
  1793. if (channel0==0)
  1794. {
  1795. channel1=1;
  1796. volume1=0;
  1797. volume0=value0;
  1798. }
  1799. else
  1800. {
  1801. channel0=0;
  1802. volume0=0;
  1803. volume1=value0;
  1804. }
  1805. }
  1806. }
  1807. if ((volume0!=0)&&(volume1!=0))
  1808. {
  1809. if (volume0==0xFF) volume1=0xFF;
  1810. else if (volume1==0xFF) volume0=0xFF;
  1811. }
  1812. else if (current_drive->drv_type<drv_201) volume0=volume1=value0;
  1813. if (current_drive->drv_type>=drv_201)
  1814. {
  1815. if (volume0==0) control0 |= 0x80;
  1816. if (volume1==0) control0 |= 0x40;
  1817. }
  1818. if (current_drive->drv_type>=drv_211)
  1819. {
  1820. if (channel0!=0) control0 |= 0x20;
  1821. if (channel1!=1) control0 |= 0x10;
  1822. }
  1823. }
  1824. drvcmd[0]=CMD0_SETMODE;
  1825. drvcmd[1]=0x83;
  1826. drvcmd[4]=control0;
  1827. drvcmd[5]=value0;
  1828. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  1829. }
  1830. else if (famT_drive)
  1831. {
  1832. current_drive->volume_control=0;
  1833. if (!volume0) current_drive->volume_control|=0x10;
  1834. if (!volume1) current_drive->volume_control|=0x20;
  1835. i=cc_prep_mode_T();
  1836. if (i<0) return (i);
  1837. }
  1838. if (!famT_drive)
  1839. {
  1840. response_count=0;
  1841. i=cmd_out();
  1842. if (i<0) return (i);
  1843. }
  1844. current_drive->diskstate_flags |= volume_bit;
  1845. return (0);
  1846. }
  1847. /*==========================================================================*/
  1848. static int GetStatus(void)
  1849. {
  1850. int i;
  1851. if (famT_drive) return (0);
  1852. flags_cmd_out=f_getsta|f_ResponseStatus|f_obey_p_check;
  1853. response_count=0;
  1854. cmd_type=0;
  1855. i=cmd_out();
  1856. return (i);
  1857. }
  1858. /*==========================================================================*/
  1859. static int cc_DriveReset(void)
  1860. {
  1861. int i;
  1862. msg(DBG_RES,"cc_DriveReset called.\n");
  1863. clr_cmdbuf();
  1864. response_count=0;
  1865. if (fam0LV_drive) OUT(CDo_reset,0x00);
  1866. else if (fam1_drive)
  1867. {
  1868. drvcmd[0]=CMD1_RESET;
  1869. flags_cmd_out=f_putcmd;
  1870. i=cmd_out();
  1871. }
  1872. else if (fam2_drive)
  1873. {
  1874. drvcmd[0]=CMD2_RESET;
  1875. flags_cmd_out=f_putcmd;
  1876. i=cmd_out();
  1877. OUT(CDo_reset,0x00);
  1878. }
  1879. else if (famT_drive)
  1880. {
  1881. OUT(CDo_sel_i_d,0);
  1882. OUT(CDo_enable,current_drive->drv_sel);
  1883. OUT(CDo_command,CMDT_RESET);
  1884. for (i=1;i<10;i++) OUT(CDo_command,0);
  1885. }
  1886. if (fam0LV_drive) sbp_sleep(5*HZ); /* wait 5 seconds */
  1887. else sbp_sleep(1*HZ); /* wait a second */
  1888. #if 1
  1889. if (famT_drive)
  1890. {
  1891. msg(DBG_TEA, "================CMDT_RESET given=================.\n");
  1892. sbp_sleep(3*HZ);
  1893. }
  1894. #endif /* 1 */
  1895. flush_status();
  1896. i=GetStatus();
  1897. if (i<0) return i;
  1898. if (!famT_drive)
  1899. if (current_drive->error_byte!=aud_12) return -501;
  1900. return (0);
  1901. }
  1902. /*==========================================================================*/
  1903. static int SetSpeed(void)
  1904. {
  1905. int i, speed;
  1906. if (!(current_drive->drv_options&(speed_auto|speed_300|speed_150))) return (0);
  1907. speed=speed_auto;
  1908. if (!(current_drive->drv_options&speed_auto))
  1909. {
  1910. speed |= speed_300;
  1911. if (!(current_drive->drv_options&speed_300)) speed=0;
  1912. }
  1913. i=cc_SetSpeed(speed,0,0);
  1914. return (i);
  1915. }
  1916. static void switch_drive(struct sbpcd_drive *);
  1917. static int sbpcd_select_speed(struct cdrom_device_info *cdi, int speed)
  1918. {
  1919. struct sbpcd_drive *p = cdi->handle;
  1920. if (p != current_drive)
  1921. switch_drive(p);
  1922. return cc_SetSpeed(speed == 2 ? speed_300 : speed_150, 0, 0);
  1923. }
  1924. /*==========================================================================*/
  1925. static int DriveReset(void)
  1926. {
  1927. int i;
  1928. i=cc_DriveReset();
  1929. if (i<0) return (-22);
  1930. do
  1931. {
  1932. i=GetStatus();
  1933. if ((i<0)&&(i!=-ERR_DISKCHANGE)) {
  1934. return (-2); /* from sta2err */
  1935. }
  1936. if (!st_caddy_in) break;
  1937. sbp_sleep(1);
  1938. }
  1939. while (!st_diskok);
  1940. #if 000
  1941. current_drive->CD_changed=1;
  1942. #endif
  1943. if ((st_door_closed) && (st_caddy_in))
  1944. {
  1945. i=DiskInfo();
  1946. if (i<0) return (-23);
  1947. }
  1948. return (0);
  1949. }
  1950. static int sbpcd_reset(struct cdrom_device_info *cdi)
  1951. {
  1952. struct sbpcd_drive *p = cdi->handle;
  1953. if (p != current_drive)
  1954. switch_drive(p);
  1955. return DriveReset();
  1956. }
  1957. /*==========================================================================*/
  1958. static int cc_PlayAudio(int pos_audio_start,int pos_audio_end)
  1959. {
  1960. int i, j, n;
  1961. if (current_drive->audio_state==audio_playing) return (-EINVAL);
  1962. clr_cmdbuf();
  1963. response_count=0;
  1964. if (famLV_drive)
  1965. {
  1966. drvcmd[0]=CMDL_PLAY;
  1967. i=msf2blk(pos_audio_start);
  1968. n=msf2blk(pos_audio_end)+1-i;
  1969. drvcmd[1]=(i>>16)&0x00FF;
  1970. drvcmd[2]=(i>>8)&0x00FF;
  1971. drvcmd[3]=i&0x00FF;
  1972. drvcmd[4]=(n>>16)&0x00FF;
  1973. drvcmd[5]=(n>>8)&0x00FF;
  1974. drvcmd[6]=n&0x00FF;
  1975. if (famL_drive)
  1976. flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
  1977. f_ResponseStatus | f_obey_p_check | f_wait_if_busy;
  1978. else
  1979. flags_cmd_out = f_putcmd;
  1980. }
  1981. else
  1982. {
  1983. j=1;
  1984. if (fam1_drive)
  1985. {
  1986. drvcmd[0]=CMD1_PLAY_MSF;
  1987. flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus |
  1988. f_obey_p_check | f_wait_if_busy;
  1989. }
  1990. else if (fam2_drive)
  1991. {
  1992. drvcmd[0]=CMD2_PLAY_MSF;
  1993. flags_cmd_out = f_putcmd | f_ResponseStatus | f_obey_p_check;
  1994. }
  1995. else if (famT_drive)
  1996. {
  1997. drvcmd[0]=CMDT_PLAY_MSF;
  1998. j=3;
  1999. response_count=1;
  2000. }
  2001. else if (fam0_drive)
  2002. {
  2003. drvcmd[0]=CMD0_PLAY_MSF;
  2004. flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
  2005. f_ResponseStatus | f_obey_p_check | f_wait_if_busy;
  2006. }
  2007. drvcmd[j]=(pos_audio_start>>16)&0x00FF;
  2008. drvcmd[j+1]=(pos_audio_start>>8)&0x00FF;
  2009. drvcmd[j+2]=pos_audio_start&0x00FF;
  2010. drvcmd[j+3]=(pos_audio_end>>16)&0x00FF;
  2011. drvcmd[j+4]=(pos_audio_end>>8)&0x00FF;
  2012. drvcmd[j+5]=pos_audio_end&0x00FF;
  2013. }
  2014. i=cmd_out();
  2015. return (i);
  2016. }
  2017. /*==========================================================================*/
  2018. static int cc_Pause_Resume(int pau_res)
  2019. {
  2020. int i;
  2021. clr_cmdbuf();
  2022. response_count=0;
  2023. if (fam1_drive)
  2024. {
  2025. drvcmd[0]=CMD1_PAU_RES;
  2026. if (pau_res!=1) drvcmd[1]=0x80;
  2027. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  2028. }
  2029. else if (fam2_drive)
  2030. {
  2031. drvcmd[0]=CMD2_PAU_RES;
  2032. if (pau_res!=1) drvcmd[2]=0x01;
  2033. flags_cmd_out=f_putcmd|f_ResponseStatus;
  2034. }
  2035. else if (fam0LV_drive)
  2036. {
  2037. drvcmd[0]=CMD0_PAU_RES;
  2038. if (pau_res!=1) drvcmd[1]=0x80;
  2039. if (famL_drive)
  2040. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|
  2041. f_obey_p_check|f_bit1;
  2042. else if (famV_drive)
  2043. flags_cmd_out=f_putcmd;
  2044. else
  2045. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|
  2046. f_obey_p_check;
  2047. }
  2048. else if (famT_drive)
  2049. {
  2050. if (pau_res==3) return (cc_PlayAudio(current_drive->pos_audio_start,current_drive->pos_audio_end));
  2051. else if (pau_res==1) drvcmd[0]=CMDT_PAUSE;
  2052. else return (-56);
  2053. }
  2054. i=cmd_out();
  2055. return (i);
  2056. }
  2057. /*==========================================================================*/
  2058. static int cc_LockDoor(char lock)
  2059. {
  2060. int i;
  2061. if (fam0_drive) return (0);
  2062. msg(DBG_LCK,"cc_LockDoor: %d (drive %d)\n", lock, current_drive - D_S);
  2063. msg(DBG_LCS,"p_door_locked bit %d before\n", st_door_locked);
  2064. clr_cmdbuf();
  2065. response_count=0;
  2066. if (fam1_drive)
  2067. {
  2068. drvcmd[0]=CMD1_LOCK_CTL;
  2069. if (lock==1) drvcmd[1]=0x01;
  2070. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2071. }
  2072. else if (fam2_drive)
  2073. {
  2074. drvcmd[0]=CMD2_LOCK_CTL;
  2075. if (lock==1) drvcmd[4]=0x01;
  2076. flags_cmd_out=f_putcmd|f_ResponseStatus;
  2077. }
  2078. else if (famLV_drive)
  2079. {
  2080. drvcmd[0]=CMDL_LOCK_CTL;
  2081. if (lock==1) drvcmd[1]=0x01;
  2082. if (famL_drive)
  2083. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  2084. else
  2085. flags_cmd_out=f_putcmd;
  2086. }
  2087. else if (famT_drive)
  2088. {
  2089. drvcmd[0]=CMDT_LOCK_CTL;
  2090. if (lock==1) drvcmd[4]=0x01;
  2091. }
  2092. i=cmd_out();
  2093. msg(DBG_LCS,"p_door_locked bit %d after\n", st_door_locked);
  2094. return (i);
  2095. }
  2096. /*==========================================================================*/
  2097. /*==========================================================================*/
  2098. static int UnLockDoor(void)
  2099. {
  2100. int i,j;
  2101. j=20;
  2102. do
  2103. {
  2104. i=cc_LockDoor(0);
  2105. --j;
  2106. sbp_sleep(1);
  2107. }
  2108. while ((i<0)&&(j));
  2109. if (i<0)
  2110. {
  2111. cc_DriveReset();
  2112. return -84;
  2113. }
  2114. return (0);
  2115. }
  2116. /*==========================================================================*/
  2117. static int LockDoor(void)
  2118. {
  2119. int i,j;
  2120. j=20;
  2121. do
  2122. {
  2123. i=cc_LockDoor(1);
  2124. --j;
  2125. sbp_sleep(1);
  2126. }
  2127. while ((i<0)&&(j));
  2128. if (j==0)
  2129. {
  2130. cc_DriveReset();
  2131. j=20;
  2132. do
  2133. {
  2134. i=cc_LockDoor(1);
  2135. --j;
  2136. sbp_sleep(1);
  2137. }
  2138. while ((i<0)&&(j));
  2139. }
  2140. return (i);
  2141. }
  2142. static int sbpcd_lock_door(struct cdrom_device_info *cdi, int lock)
  2143. {
  2144. return lock ? LockDoor() : UnLockDoor();
  2145. }
  2146. /*==========================================================================*/
  2147. static int cc_CloseTray(void)
  2148. {
  2149. int i;
  2150. if (fam0_drive) return (0);
  2151. msg(DBG_LCK,"cc_CloseTray (drive %d)\n", current_drive - D_S);
  2152. msg(DBG_LCS,"p_door_closed bit %d before\n", st_door_closed);
  2153. clr_cmdbuf();
  2154. response_count=0;
  2155. if (fam1_drive)
  2156. {
  2157. drvcmd[0]=CMD1_TRAY_CTL;
  2158. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  2159. }
  2160. else if (fam2_drive)
  2161. {
  2162. drvcmd[0]=CMD2_TRAY_CTL;
  2163. drvcmd[1]=0x01;
  2164. drvcmd[4]=0x03; /* "insert" */
  2165. flags_cmd_out=f_putcmd|f_ResponseStatus;
  2166. }
  2167. else if (famLV_drive)
  2168. {
  2169. drvcmd[0]=CMDL_TRAY_CTL;
  2170. if (famLV_drive)
  2171. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|
  2172. f_ResponseStatus|f_obey_p_check|f_bit1;
  2173. else
  2174. flags_cmd_out=f_putcmd;
  2175. }
  2176. else if (famT_drive)
  2177. {
  2178. drvcmd[0]=CMDT_TRAY_CTL;
  2179. drvcmd[4]=0x03; /* "insert" */
  2180. }
  2181. i=cmd_out();
  2182. msg(DBG_LCS,"p_door_closed bit %d after\n", st_door_closed);
  2183. i=cc_ReadError();
  2184. flags_cmd_out |= f_respo2;
  2185. cc_ReadStatus(); /* command: give 1-byte status */
  2186. i=ResponseStatus();
  2187. if (famT_drive&&(i<0))
  2188. {
  2189. cc_DriveReset();
  2190. i=ResponseStatus();
  2191. #if 0
  2192. sbp_sleep(HZ);
  2193. #endif /* 0 */
  2194. i=ResponseStatus();
  2195. }
  2196. if (i<0)
  2197. {
  2198. msg(DBG_INF,"sbpcd cc_CloseTray: ResponseStatus timed out (%d).\n",i);
  2199. }
  2200. if (!(famT_drive))
  2201. {
  2202. if (!st_spinning)
  2203. {
  2204. cc_SpinUp();
  2205. if (st_check) i=cc_ReadError();
  2206. flags_cmd_out |= f_respo2;
  2207. cc_ReadStatus();
  2208. i=ResponseStatus();
  2209. } else {
  2210. }
  2211. }
  2212. i=DiskInfo();
  2213. return (i);
  2214. }
  2215. static int sbpcd_tray_move(struct cdrom_device_info *cdi, int position)
  2216. {
  2217. int retval=0;
  2218. switch_drive(cdi->handle);
  2219. /* DUH! --AJK */
  2220. if(current_drive->CD_changed != 0xFF) {
  2221. current_drive->CD_changed=0xFF;
  2222. current_drive->diskstate_flags &= ~cd_size_bit;
  2223. }
  2224. if (position == 1) {
  2225. cc_SpinDown();
  2226. } else {
  2227. retval=cc_CloseTray();
  2228. }
  2229. return retval;
  2230. }
  2231. /*==========================================================================*/
  2232. static int cc_ReadSubQ(void)
  2233. {
  2234. int i,j;
  2235. current_drive->diskstate_flags &= ~subq_bit;
  2236. for (j=255;j>0;j--)
  2237. {
  2238. clr_cmdbuf();
  2239. if (fam1_drive)
  2240. {
  2241. drvcmd[0]=CMD1_READSUBQ;
  2242. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2243. response_count=11;
  2244. }
  2245. else if (fam2_drive)
  2246. {
  2247. drvcmd[0]=CMD2_READSUBQ;
  2248. drvcmd[1]=0x02;
  2249. drvcmd[3]=0x01;
  2250. flags_cmd_out=f_putcmd;
  2251. response_count=10;
  2252. }
  2253. else if (fam0LV_drive)
  2254. {
  2255. drvcmd[0]=CMD0_READSUBQ;
  2256. drvcmd[1]=0x02;
  2257. if (famLV_drive)
  2258. flags_cmd_out=f_putcmd;
  2259. else
  2260. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2261. response_count=13;
  2262. }
  2263. else if (famT_drive)
  2264. {
  2265. response_count=12;
  2266. drvcmd[0]=CMDT_READSUBQ;
  2267. drvcmd[1]=0x02;
  2268. drvcmd[2]=0x40;
  2269. drvcmd[3]=0x01;
  2270. drvcmd[8]=response_count;
  2271. }
  2272. i=cmd_out();
  2273. if (i<0) return (i);
  2274. for (i=0;i<response_count;i++)
  2275. {
  2276. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  2277. msgbuf[i*3]=0;
  2278. msg(DBG_SQ1,"cc_ReadSubQ:%s\n", msgbuf);
  2279. }
  2280. if (famT_drive) break;
  2281. if (infobuf[0]!=0) break;
  2282. if ((!st_spinning) || (j==1))
  2283. {
  2284. current_drive->SubQ_ctl_adr=current_drive->SubQ_trk=current_drive->SubQ_pnt_idx=current_drive->SubQ_whatisthis=0;
  2285. current_drive->SubQ_run_tot=current_drive->SubQ_run_trk=0;
  2286. return (0);
  2287. }
  2288. }
  2289. if (famT_drive) current_drive->SubQ_ctl_adr=infobuf[1];
  2290. else current_drive->SubQ_ctl_adr=swap_nibbles(infobuf[1]);
  2291. current_drive->SubQ_trk=byt2bcd(infobuf[2]);
  2292. current_drive->SubQ_pnt_idx=byt2bcd(infobuf[3]);
  2293. if (fam0LV_drive) i=5;
  2294. else if (fam12_drive) i=4;
  2295. else if (famT_drive) i=8;
  2296. current_drive->SubQ_run_tot=make32(make16(0,infobuf[i]),make16(infobuf[i+1],infobuf[i+2])); /* msf-bin */
  2297. i=7;
  2298. if (fam0LV_drive) i=9;
  2299. else if (fam12_drive) i=7;
  2300. else if (famT_drive) i=4;
  2301. current_drive->SubQ_run_trk=make32(make16(0,infobuf[i]),make16(infobuf[i+1],infobuf[i+2])); /* msf-bin */
  2302. current_drive->SubQ_whatisthis=infobuf[i+3];
  2303. current_drive->diskstate_flags |= subq_bit;
  2304. return (0);
  2305. }
  2306. /*==========================================================================*/
  2307. static int cc_ModeSense(void)
  2308. {
  2309. int i;
  2310. if (fam2_drive) return (0);
  2311. if (famV_drive) return (0);
  2312. current_drive->diskstate_flags &= ~frame_size_bit;
  2313. clr_cmdbuf();
  2314. if (fam1_drive)
  2315. {
  2316. response_count=5;
  2317. drvcmd[0]=CMD1_GETMODE;
  2318. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2319. }
  2320. else if (fam0L_drive)
  2321. {
  2322. response_count=2;
  2323. drvcmd[0]=CMD0_GETMODE;
  2324. if (famL_drive) flags_cmd_out=f_putcmd;
  2325. else flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2326. }
  2327. else if (famT_drive)
  2328. {
  2329. response_count=10;
  2330. drvcmd[0]=CMDT_GETMODE;
  2331. drvcmd[4]=response_count;
  2332. }
  2333. i=cmd_out();
  2334. if (i<0) return (i);
  2335. i=0;
  2336. current_drive->sense_byte=0;
  2337. if (fam1_drive) current_drive->sense_byte=infobuf[i++];
  2338. else if (famT_drive)
  2339. {
  2340. if (infobuf[4]==0x01) current_drive->xa_byte=0x20;
  2341. else current_drive->xa_byte=0;
  2342. i=2;
  2343. }
  2344. current_drive->frame_size=make16(infobuf[i],infobuf[i+1]);
  2345. for (i=0;i<response_count;i++)
  2346. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  2347. msgbuf[i*3]=0;
  2348. msg(DBG_XA1,"cc_ModeSense:%s\n", msgbuf);
  2349. current_drive->diskstate_flags |= frame_size_bit;
  2350. return (0);
  2351. }
  2352. /*==========================================================================*/
  2353. /*==========================================================================*/
  2354. static int cc_ModeSelect(int framesize)
  2355. {
  2356. int i;
  2357. if (fam2_drive) return (0);
  2358. if (famV_drive) return (0);
  2359. current_drive->diskstate_flags &= ~frame_size_bit;
  2360. clr_cmdbuf();
  2361. current_drive->frame_size=framesize;
  2362. if (framesize==CD_FRAMESIZE_RAW) current_drive->sense_byte=0x82;
  2363. else current_drive->sense_byte=0x00;
  2364. msg(DBG_XA1,"cc_ModeSelect: %02X %04X\n",
  2365. current_drive->sense_byte, current_drive->frame_size);
  2366. if (fam1_drive)
  2367. {
  2368. drvcmd[0]=CMD1_SETMODE;
  2369. drvcmd[1]=0x00;
  2370. drvcmd[2]=current_drive->sense_byte;
  2371. drvcmd[3]=(current_drive->frame_size>>8)&0xFF;
  2372. drvcmd[4]=current_drive->frame_size&0xFF;
  2373. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2374. }
  2375. else if (fam0L_drive)
  2376. {
  2377. drvcmd[0]=CMD0_SETMODE;
  2378. drvcmd[1]=0x00;
  2379. drvcmd[2]=(current_drive->frame_size>>8)&0xFF;
  2380. drvcmd[3]=current_drive->frame_size&0xFF;
  2381. drvcmd[4]=0x00;
  2382. if(famL_drive)
  2383. flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check;
  2384. else
  2385. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2386. }
  2387. else if (famT_drive)
  2388. {
  2389. return (-1);
  2390. }
  2391. response_count=0;
  2392. i=cmd_out();
  2393. if (i<0) return (i);
  2394. current_drive->diskstate_flags |= frame_size_bit;
  2395. return (0);
  2396. }
  2397. /*==========================================================================*/
  2398. static int cc_GetVolume(void)
  2399. {
  2400. int i;
  2401. u_char switches;
  2402. u_char chan0=0;
  2403. u_char vol0=0;
  2404. u_char chan1=1;
  2405. u_char vol1=0;
  2406. if (famV_drive) return (0);
  2407. current_drive->diskstate_flags &= ~volume_bit;
  2408. clr_cmdbuf();
  2409. if (fam1_drive)
  2410. {
  2411. drvcmd[0]=CMD1_GETMODE;
  2412. drvcmd[1]=0x05;
  2413. response_count=5;
  2414. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2415. }
  2416. else if (fam2_drive)
  2417. {
  2418. drvcmd[0]=CMD2_GETMODE;
  2419. drvcmd[1]=0x0E;
  2420. response_count=5;
  2421. flags_cmd_out=f_putcmd;
  2422. }
  2423. else if (fam0L_drive)
  2424. {
  2425. drvcmd[0]=CMD0_GETMODE;
  2426. drvcmd[1]=0x03;
  2427. response_count=2;
  2428. if(famL_drive)
  2429. flags_cmd_out=f_putcmd;
  2430. else
  2431. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2432. }
  2433. else if (famT_drive)
  2434. {
  2435. i=cc_get_mode_T();
  2436. if (i<0) return (i);
  2437. }
  2438. if (!famT_drive)
  2439. {
  2440. i=cmd_out();
  2441. if (i<0) return (i);
  2442. }
  2443. if (fam1_drive)
  2444. {
  2445. chan0=infobuf[1]&0x0F;
  2446. vol0=infobuf[2];
  2447. chan1=infobuf[3]&0x0F;
  2448. vol1=infobuf[4];
  2449. if (chan0==0)
  2450. {
  2451. chan0=1;
  2452. vol0=0;
  2453. }
  2454. if (chan1==0)
  2455. {
  2456. chan1=2;
  2457. vol1=0;
  2458. }
  2459. chan0 >>= 1;
  2460. chan1 >>= 1;
  2461. }
  2462. else if (fam2_drive)
  2463. {
  2464. chan0=infobuf[1];
  2465. vol0=infobuf[2];
  2466. chan1=infobuf[3];
  2467. vol1=infobuf[4];
  2468. }
  2469. else if (famL_drive)
  2470. {
  2471. chan0=0;
  2472. chan1=1;
  2473. vol0=vol1=infobuf[1];
  2474. switches=infobuf[0];
  2475. if ((switches&0x80)!=0) chan0=1;
  2476. if ((switches&0x40)!=0) chan1=0;
  2477. }
  2478. else if (fam0_drive) /* different firmware levels */
  2479. {
  2480. chan0=0;
  2481. chan1=1;
  2482. vol0=vol1=infobuf[1];
  2483. if (current_drive->drv_type>=drv_201)
  2484. {
  2485. if (current_drive->drv_type<drv_300)
  2486. {
  2487. switches=infobuf[0];
  2488. if ((switches&0x80)!=0) vol0=0;
  2489. if ((switches&0x40)!=0) vol1=0;
  2490. if (current_drive->drv_type>=drv_211)
  2491. {
  2492. if ((switches&0x20)!=0) chan0=1;
  2493. if ((switches&0x10)!=0) chan1=0;
  2494. }
  2495. }
  2496. else
  2497. {
  2498. vol0=infobuf[0];
  2499. if ((vol0&0x01)!=0) chan0=1;
  2500. if ((vol1&0x01)==0) chan1=0;
  2501. vol0 &= 0xFC;
  2502. vol1 &= 0xFC;
  2503. if (vol0!=0) vol0 += 3;
  2504. if (vol1!=0) vol1 += 3;
  2505. }
  2506. }
  2507. }
  2508. else if (famT_drive)
  2509. {
  2510. current_drive->volume_control=infobuf[7];
  2511. chan0=0;
  2512. chan1=1;
  2513. if (current_drive->volume_control&0x10) vol0=0;
  2514. else vol0=0xff;
  2515. if (current_drive->volume_control&0x20) vol1=0;
  2516. else vol1=0xff;
  2517. }
  2518. current_drive->vol_chan0=chan0;
  2519. current_drive->vol_ctrl0=vol0;
  2520. current_drive->vol_chan1=chan1;
  2521. current_drive->vol_ctrl1=vol1;
  2522. #if 000
  2523. current_drive->vol_chan2=2;
  2524. current_drive->vol_ctrl2=0xFF;
  2525. current_drive->vol_chan3=3;
  2526. current_drive->vol_ctrl3=0xFF;
  2527. #endif /* 000 */
  2528. current_drive->diskstate_flags |= volume_bit;
  2529. return (0);
  2530. }
  2531. /*==========================================================================*/
  2532. static int cc_ReadCapacity(void)
  2533. {
  2534. int i, j;
  2535. if (fam2_drive) return (0); /* some firmware lacks this command */
  2536. if (famLV_drive) return (0); /* some firmware lacks this command */
  2537. if (famT_drive) return (0); /* done with cc_ReadTocDescr() */
  2538. current_drive->diskstate_flags &= ~cd_size_bit;
  2539. for (j=3;j>0;j--)
  2540. {
  2541. clr_cmdbuf();
  2542. if (fam1_drive)
  2543. {
  2544. drvcmd[0]=CMD1_CAPACITY;
  2545. response_count=5;
  2546. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2547. }
  2548. #if 00
  2549. else if (fam2_drive)
  2550. {
  2551. drvcmd[0]=CMD2_CAPACITY;
  2552. response_count=8;
  2553. flags_cmd_out=f_putcmd;
  2554. }
  2555. #endif
  2556. else if (fam0_drive)
  2557. {
  2558. drvcmd[0]=CMD0_CAPACITY;
  2559. response_count=5;
  2560. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2561. }
  2562. i=cmd_out();
  2563. if (i>=0) break;
  2564. msg(DBG_000,"cc_ReadCapacity: cmd_out: err %d\n", i);
  2565. cc_ReadError();
  2566. }
  2567. if (j==0) return (i);
  2568. if (fam1_drive) current_drive->CDsize_frm=msf2blk(make32(make16(0,infobuf[0]),make16(infobuf[1],infobuf[2])))+CD_MSF_OFFSET;
  2569. else if (fam0_drive) current_drive->CDsize_frm=make32(make16(0,infobuf[0]),make16(infobuf[1],infobuf[2]));
  2570. #if 00
  2571. else if (fam2_drive) current_drive->CDsize_frm=make32(make16(infobuf[0],infobuf[1]),make16(infobuf[2],infobuf[3]));
  2572. #endif
  2573. current_drive->diskstate_flags |= cd_size_bit;
  2574. msg(DBG_000,"cc_ReadCapacity: %d frames.\n", current_drive->CDsize_frm);
  2575. return (0);
  2576. }
  2577. /*==========================================================================*/
  2578. static int cc_ReadTocDescr(void)
  2579. {
  2580. int i;
  2581. current_drive->diskstate_flags &= ~toc_bit;
  2582. clr_cmdbuf();
  2583. if (fam1_drive)
  2584. {
  2585. drvcmd[0]=CMD1_DISKINFO;
  2586. response_count=6;
  2587. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2588. }
  2589. else if (fam0LV_drive)
  2590. {
  2591. drvcmd[0]=CMD0_DISKINFO;
  2592. response_count=6;
  2593. if(famLV_drive)
  2594. flags_cmd_out=f_putcmd;
  2595. else
  2596. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2597. }
  2598. else if (fam2_drive)
  2599. {
  2600. /* possibly longer timeout periods necessary */
  2601. current_drive->f_multisession=0;
  2602. drvcmd[0]=CMD2_DISKINFO;
  2603. drvcmd[1]=0x02;
  2604. drvcmd[2]=0xAB;
  2605. drvcmd[3]=0xFF; /* session */
  2606. response_count=8;
  2607. flags_cmd_out=f_putcmd;
  2608. }
  2609. else if (famT_drive)
  2610. {
  2611. current_drive->f_multisession=0;
  2612. response_count=12;
  2613. drvcmd[0]=CMDT_DISKINFO;
  2614. drvcmd[1]=0x02;
  2615. drvcmd[6]=CDROM_LEADOUT;
  2616. drvcmd[8]=response_count;
  2617. drvcmd[9]=0x00;
  2618. }
  2619. i=cmd_out();
  2620. if (i<0) return (i);
  2621. if ((famT_drive)&&(i<response_count)) return (-100-i);
  2622. if ((fam1_drive)||(fam2_drive)||(fam0LV_drive))
  2623. current_drive->xa_byte=infobuf[0];
  2624. if (fam2_drive)
  2625. {
  2626. current_drive->first_session=infobuf[1];
  2627. current_drive->last_session=infobuf[2];
  2628. current_drive->n_first_track=infobuf[3];
  2629. current_drive->n_last_track=infobuf[4];
  2630. if (current_drive->first_session!=current_drive->last_session)
  2631. {
  2632. current_drive->f_multisession=1;
  2633. current_drive->lba_multi=msf2blk(make32(make16(0,infobuf[5]),make16(infobuf[6],infobuf[7])));
  2634. }
  2635. #if 0
  2636. if (current_drive->first_session!=current_drive->last_session)
  2637. {
  2638. if (current_drive->last_session<=20)
  2639. zwanzig=current_drive->last_session+1;
  2640. else zwanzig=20;
  2641. for (count=current_drive->first_session;count<zwanzig;count++)
  2642. {
  2643. drvcmd[0]=CMD2_DISKINFO;
  2644. drvcmd[1]=0x02;
  2645. drvcmd[2]=0xAB;
  2646. drvcmd[3]=count;
  2647. response_count=8;
  2648. flags_cmd_out=f_putcmd;
  2649. i=cmd_out();
  2650. if (i<0) return (i);
  2651. current_drive->msf_multi_n[count]=make32(make16(0,infobuf[5]),make16(infobuf[6],infobuf[7]));
  2652. }
  2653. current_drive->diskstate_flags |= multisession_bit;
  2654. }
  2655. #endif
  2656. drvcmd[0]=CMD2_DISKINFO;
  2657. drvcmd[1]=0x02;
  2658. drvcmd[2]=0xAA;
  2659. drvcmd[3]=0xFF;
  2660. response_count=5;
  2661. flags_cmd_out=f_putcmd;
  2662. i=cmd_out();
  2663. if (i<0) return (i);
  2664. current_drive->size_msf=make32(make16(0,infobuf[2]),make16(infobuf[3],infobuf[4]));
  2665. current_drive->size_blk=msf2blk(current_drive->size_msf);
  2666. current_drive->CDsize_frm=current_drive->size_blk+1;
  2667. }
  2668. else if (famT_drive)
  2669. {
  2670. current_drive->size_msf=make32(make16(infobuf[8],infobuf[9]),make16(infobuf[10],infobuf[11]));
  2671. current_drive->size_blk=msf2blk(current_drive->size_msf);
  2672. current_drive->CDsize_frm=current_drive->size_blk+1;
  2673. current_drive->n_first_track=infobuf[2];
  2674. current_drive->n_last_track=infobuf[3];
  2675. }
  2676. else
  2677. {
  2678. current_drive->n_first_track=infobuf[1];
  2679. current_drive->n_last_track=infobuf[2];
  2680. current_drive->size_msf=make32(make16(0,infobuf[3]),make16(infobuf[4],infobuf[5]));
  2681. current_drive->size_blk=msf2blk(current_drive->size_msf);
  2682. if (famLV_drive) current_drive->CDsize_frm=current_drive->size_blk+1;
  2683. }
  2684. current_drive->diskstate_flags |= toc_bit;
  2685. msg(DBG_TOC,"TocDesc: xa %02X firstt %02X lastt %02X size %08X firstses %02X lastsess %02X\n",
  2686. current_drive->xa_byte,
  2687. current_drive->n_first_track,
  2688. current_drive->n_last_track,
  2689. current_drive->size_msf,
  2690. current_drive->first_session,
  2691. current_drive->last_session);
  2692. return (0);
  2693. }
  2694. /*==========================================================================*/
  2695. static int cc_ReadTocEntry(int num)
  2696. {
  2697. int i;
  2698. clr_cmdbuf();
  2699. if (fam1_drive)
  2700. {
  2701. drvcmd[0]=CMD1_READTOC;
  2702. drvcmd[2]=num;
  2703. response_count=8;
  2704. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2705. }
  2706. else if (fam2_drive)
  2707. {
  2708. /* possibly longer timeout periods necessary */
  2709. drvcmd[0]=CMD2_DISKINFO;
  2710. drvcmd[1]=0x02;
  2711. drvcmd[2]=num;
  2712. response_count=5;
  2713. flags_cmd_out=f_putcmd;
  2714. }
  2715. else if (fam0LV_drive)
  2716. {
  2717. drvcmd[0]=CMD0_READTOC;
  2718. drvcmd[1]=0x02;
  2719. drvcmd[2]=num;
  2720. response_count=8;
  2721. if (famLV_drive)
  2722. flags_cmd_out=f_putcmd;
  2723. else
  2724. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2725. }
  2726. else if (famT_drive)
  2727. {
  2728. response_count=12;
  2729. drvcmd[0]=CMDT_DISKINFO;
  2730. drvcmd[1]=0x02;
  2731. drvcmd[6]=num;
  2732. drvcmd[8]=response_count;
  2733. drvcmd[9]=0x00;
  2734. }
  2735. i=cmd_out();
  2736. if (i<0) return (i);
  2737. if ((famT_drive)&&(i<response_count)) return (-100-i);
  2738. if ((fam1_drive)||(fam0LV_drive))
  2739. {
  2740. current_drive->TocEnt_nixbyte=infobuf[0];
  2741. i=1;
  2742. }
  2743. else if (fam2_drive) i=0;
  2744. else if (famT_drive) i=5;
  2745. current_drive->TocEnt_ctl_adr=swap_nibbles(infobuf[i++]);
  2746. if ((fam1_drive)||(fam0L_drive))
  2747. {
  2748. current_drive->TocEnt_number=infobuf[i++];
  2749. current_drive->TocEnt_format=infobuf[i];
  2750. }
  2751. else
  2752. {
  2753. current_drive->TocEnt_number=num;
  2754. current_drive->TocEnt_format=0;
  2755. }
  2756. if (fam1_drive) i=4;
  2757. else if (fam0LV_drive) i=5;
  2758. else if (fam2_drive) i=2;
  2759. else if (famT_drive) i=9;
  2760. current_drive->TocEnt_address=make32(make16(0,infobuf[i]),
  2761. make16(infobuf[i+1],infobuf[i+2]));
  2762. for (i=0;i<response_count;i++)
  2763. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  2764. msgbuf[i*3]=0;
  2765. msg(DBG_ECS,"TocEntry:%s\n", msgbuf);
  2766. msg(DBG_TOC,"TocEntry: %02X %02X %02X %02X %08X\n",
  2767. current_drive->TocEnt_nixbyte, current_drive->TocEnt_ctl_adr,
  2768. current_drive->TocEnt_number, current_drive->TocEnt_format,
  2769. current_drive->TocEnt_address);
  2770. return (0);
  2771. }
  2772. /*==========================================================================*/
  2773. static int cc_ReadPacket(void)
  2774. {
  2775. int i;
  2776. clr_cmdbuf();
  2777. drvcmd[0]=CMD0_PACKET;
  2778. drvcmd[1]=response_count;
  2779. if(famL_drive) flags_cmd_out=f_putcmd;
  2780. else if (fam01_drive)
  2781. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2782. else if (fam2_drive) return (-1); /* not implemented yet */
  2783. else if (famT_drive)
  2784. {
  2785. return (-1);
  2786. }
  2787. i=cmd_out();
  2788. return (i);
  2789. }
  2790. /*==========================================================================*/
  2791. static int convert_UPC(u_char *p)
  2792. {
  2793. int i;
  2794. p++;
  2795. if (fam0L_drive) p[13]=0;
  2796. for (i=0;i<7;i++)
  2797. {
  2798. if (fam1_drive) current_drive->UPC_buf[i]=swap_nibbles(*p++);
  2799. else if (fam0L_drive)
  2800. {
  2801. current_drive->UPC_buf[i]=((*p++)<<4)&0xFF;
  2802. current_drive->UPC_buf[i] |= *p++;
  2803. }
  2804. else if (famT_drive)
  2805. {
  2806. return (-1);
  2807. }
  2808. else /* CD200 */
  2809. {
  2810. return (-1);
  2811. }
  2812. }
  2813. current_drive->UPC_buf[6] &= 0xF0;
  2814. return (0);
  2815. }
  2816. /*==========================================================================*/
  2817. static int cc_ReadUPC(void)
  2818. {
  2819. int i;
  2820. #if TEST_UPC
  2821. int block, checksum;
  2822. #endif /* TEST_UPC */
  2823. if (fam2_drive) return (0); /* not implemented yet */
  2824. if (famT_drive) return (0); /* not implemented yet */
  2825. if (famV_drive) return (0); /* not implemented yet */
  2826. #if 1
  2827. if (fam0_drive) return (0); /* but it should work */
  2828. #endif
  2829. current_drive->diskstate_flags &= ~upc_bit;
  2830. #if TEST_UPC
  2831. for (block=CD_MSF_OFFSET+1;block<CD_MSF_OFFSET+200;block++)
  2832. {
  2833. #endif /* TEST_UPC */
  2834. clr_cmdbuf();
  2835. if (fam1_drive)
  2836. {
  2837. drvcmd[0]=CMD1_READ_UPC;
  2838. #if TEST_UPC
  2839. drvcmd[1]=(block>>16)&0xFF;
  2840. drvcmd[2]=(block>>8)&0xFF;
  2841. drvcmd[3]=block&0xFF;
  2842. #endif /* TEST_UPC */
  2843. response_count=8;
  2844. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2845. }
  2846. else if (fam0L_drive)
  2847. {
  2848. drvcmd[0]=CMD0_READ_UPC;
  2849. #if TEST_UPC
  2850. drvcmd[2]=(block>>16)&0xFF;
  2851. drvcmd[3]=(block>>8)&0xFF;
  2852. drvcmd[4]=block&0xFF;
  2853. #endif /* TEST_UPC */
  2854. response_count=0;
  2855. flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  2856. }
  2857. else if (fam2_drive)
  2858. {
  2859. return (-1);
  2860. }
  2861. else if (famT_drive)
  2862. {
  2863. return (-1);
  2864. }
  2865. i=cmd_out();
  2866. if (i<0)
  2867. {
  2868. msg(DBG_000,"cc_ReadUPC cmd_out: err %d\n", i);
  2869. return (i);
  2870. }
  2871. if (fam0L_drive)
  2872. {
  2873. response_count=16;
  2874. if (famL_drive) flags_cmd_out=f_putcmd;
  2875. i=cc_ReadPacket();
  2876. if (i<0)
  2877. {
  2878. msg(DBG_000,"cc_ReadUPC ReadPacket: err %d\n", i);
  2879. return (i);
  2880. }
  2881. }
  2882. #if TEST_UPC
  2883. checksum=0;
  2884. #endif /* TEST_UPC */
  2885. for (i=0;i<(fam1_drive?8:16);i++)
  2886. {
  2887. #if TEST_UPC
  2888. checksum |= infobuf[i];
  2889. #endif /* TEST_UPC */
  2890. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  2891. }
  2892. msgbuf[i*3]=0;
  2893. msg(DBG_UPC,"UPC info:%s\n", msgbuf);
  2894. #if TEST_UPC
  2895. if ((checksum&0x7F)!=0) break;
  2896. }
  2897. #endif /* TEST_UPC */
  2898. current_drive->UPC_ctl_adr=0;
  2899. if (fam1_drive) i=0;
  2900. else i=2;
  2901. if ((infobuf[i]&0x80)!=0)
  2902. {
  2903. convert_UPC(&infobuf[i]);
  2904. current_drive->UPC_ctl_adr = (current_drive->TocEnt_ctl_adr & 0xF0) | 0x02;
  2905. }
  2906. for (i=0;i<7;i++)
  2907. sprintf(&msgbuf[i*3], " %02X", current_drive->UPC_buf[i]);
  2908. sprintf(&msgbuf[i*3], " (%02X)", current_drive->UPC_ctl_adr);
  2909. msgbuf[i*3+5]=0;
  2910. msg(DBG_UPC,"UPC code:%s\n", msgbuf);
  2911. current_drive->diskstate_flags |= upc_bit;
  2912. return (0);
  2913. }
  2914. static int sbpcd_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
  2915. {
  2916. int i;
  2917. unsigned char *mcnp = mcn->medium_catalog_number;
  2918. unsigned char *resp;
  2919. current_drive->diskstate_flags &= ~upc_bit;
  2920. clr_cmdbuf();
  2921. if (fam1_drive)
  2922. {
  2923. drvcmd[0]=CMD1_READ_UPC;
  2924. response_count=8;
  2925. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2926. }
  2927. else if (fam0L_drive)
  2928. {
  2929. drvcmd[0]=CMD0_READ_UPC;
  2930. response_count=0;
  2931. flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  2932. }
  2933. else if (fam2_drive)
  2934. {
  2935. return (-1);
  2936. }
  2937. else if (famT_drive)
  2938. {
  2939. return (-1);
  2940. }
  2941. i=cmd_out();
  2942. if (i<0)
  2943. {
  2944. msg(DBG_000,"cc_ReadUPC cmd_out: err %d\n", i);
  2945. return (i);
  2946. }
  2947. if (fam0L_drive)
  2948. {
  2949. response_count=16;
  2950. if (famL_drive) flags_cmd_out=f_putcmd;
  2951. i=cc_ReadPacket();
  2952. if (i<0)
  2953. {
  2954. msg(DBG_000,"cc_ReadUPC ReadPacket: err %d\n", i);
  2955. return (i);
  2956. }
  2957. }
  2958. current_drive->UPC_ctl_adr=0;
  2959. if (fam1_drive) i=0;
  2960. else i=2;
  2961. resp = infobuf + i;
  2962. if (*resp++ == 0x80) {
  2963. /* packed bcd to single ASCII digits */
  2964. *mcnp++ = (*resp >> 4) + '0';
  2965. *mcnp++ = (*resp++ & 0x0f) + '0';
  2966. *mcnp++ = (*resp >> 4) + '0';
  2967. *mcnp++ = (*resp++ & 0x0f) + '0';
  2968. *mcnp++ = (*resp >> 4) + '0';
  2969. *mcnp++ = (*resp++ & 0x0f) + '0';
  2970. *mcnp++ = (*resp >> 4) + '0';
  2971. *mcnp++ = (*resp++ & 0x0f) + '0';
  2972. *mcnp++ = (*resp >> 4) + '0';
  2973. *mcnp++ = (*resp++ & 0x0f) + '0';
  2974. *mcnp++ = (*resp >> 4) + '0';
  2975. *mcnp++ = (*resp++ & 0x0f) + '0';
  2976. *mcnp++ = (*resp >> 4) + '0';
  2977. }
  2978. *mcnp = '\0';
  2979. current_drive->diskstate_flags |= upc_bit;
  2980. return (0);
  2981. }
  2982. /*==========================================================================*/
  2983. static int cc_CheckMultiSession(void)
  2984. {
  2985. int i;
  2986. if (fam2_drive) return (0);
  2987. current_drive->f_multisession=0;
  2988. current_drive->lba_multi=0;
  2989. if (fam0_drive) return (0);
  2990. clr_cmdbuf();
  2991. if (fam1_drive)
  2992. {
  2993. drvcmd[0]=CMD1_MULTISESS;
  2994. response_count=6;
  2995. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2996. i=cmd_out();
  2997. if (i<0) return (i);
  2998. if ((infobuf[0]&0x80)!=0)
  2999. {
  3000. current_drive->f_multisession=1;
  3001. current_drive->lba_multi=msf2blk(make32(make16(0,infobuf[1]),
  3002. make16(infobuf[2],infobuf[3])));
  3003. }
  3004. }
  3005. else if (famLV_drive)
  3006. {
  3007. drvcmd[0]=CMDL_MULTISESS;
  3008. drvcmd[1]=3;
  3009. drvcmd[2]=1;
  3010. response_count=8;
  3011. flags_cmd_out=f_putcmd;
  3012. i=cmd_out();
  3013. if (i<0) return (i);
  3014. current_drive->lba_multi=msf2blk(make32(make16(0,infobuf[5]),
  3015. make16(infobuf[6],infobuf[7])));
  3016. }
  3017. else if (famT_drive)
  3018. {
  3019. response_count=12;
  3020. drvcmd[0]=CMDT_DISKINFO;
  3021. drvcmd[1]=0x02;
  3022. drvcmd[6]=0;
  3023. drvcmd[8]=response_count;
  3024. drvcmd[9]=0x40;
  3025. i=cmd_out();
  3026. if (i<0) return (i);
  3027. if (i<response_count) return (-100-i);
  3028. current_drive->first_session=infobuf[2];
  3029. current_drive->last_session=infobuf[3];
  3030. current_drive->track_of_last_session=infobuf[6];
  3031. if (current_drive->first_session!=current_drive->last_session)
  3032. {
  3033. current_drive->f_multisession=1;
  3034. current_drive->lba_multi=msf2blk(make32(make16(0,infobuf[9]),make16(infobuf[10],infobuf[11])));
  3035. }
  3036. }
  3037. for (i=0;i<response_count;i++)
  3038. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  3039. msgbuf[i*3]=0;
  3040. msg(DBG_MUL,"MultiSession Info:%s (%d)\n", msgbuf, current_drive->lba_multi);
  3041. if (current_drive->lba_multi>200)
  3042. {
  3043. current_drive->f_multisession=1;
  3044. msg(DBG_MUL,"MultiSession base: %06X\n", current_drive->lba_multi);
  3045. }
  3046. return (0);
  3047. }
  3048. /*==========================================================================*/
  3049. #ifdef FUTURE
  3050. static int cc_SubChanInfo(int frame, int count, u_char *buffer)
  3051. /* "frame" is a RED BOOK (msf-bin) address */
  3052. {
  3053. int i;
  3054. if (fam0LV_drive) return (-ENOSYS); /* drive firmware lacks it */
  3055. if (famT_drive)
  3056. {
  3057. return (-1);
  3058. }
  3059. #if 0
  3060. if (current_drive->audio_state!=audio_playing) return (-ENODATA);
  3061. #endif
  3062. clr_cmdbuf();
  3063. drvcmd[0]=CMD1_SUBCHANINF;
  3064. drvcmd[1]=(frame>>16)&0xFF;
  3065. drvcmd[2]=(frame>>8)&0xFF;
  3066. drvcmd[3]=frame&0xFF;
  3067. drvcmd[5]=(count>>8)&0xFF;
  3068. drvcmd[6]=count&0xFF;
  3069. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  3070. cmd_type=READ_SC;
  3071. current_drive->frame_size=CD_FRAMESIZE_SUB;
  3072. i=cmd_out(); /* which buffer to use? */
  3073. return (i);
  3074. }
  3075. #endif /* FUTURE */
  3076. /*==========================================================================*/
  3077. static void __init check_datarate(void)
  3078. {
  3079. int i=0;
  3080. msg(DBG_IOX,"check_datarate entered.\n");
  3081. datarate=0;
  3082. #if TEST_STI
  3083. for (i=0;i<=1000;i++) printk(".");
  3084. #endif
  3085. /* set a timer to make (timed_out_delay!=0) after 1.1 seconds */
  3086. #if 1
  3087. del_timer(&delay_timer);
  3088. #endif
  3089. delay_timer.expires=jiffies+11*HZ/10;
  3090. timed_out_delay=0;
  3091. add_timer(&delay_timer);
  3092. #if 0
  3093. msg(DBG_TIM,"delay timer started (11*HZ/10).\n");
  3094. #endif
  3095. do
  3096. {
  3097. i=inb(CDi_status);
  3098. datarate++;
  3099. #if 1
  3100. if (datarate>0x6FFFFFFF) break;
  3101. #endif
  3102. }
  3103. while (!timed_out_delay);
  3104. del_timer(&delay_timer);
  3105. #if 0
  3106. msg(DBG_TIM,"datarate: %04X\n", datarate);
  3107. #endif
  3108. if (datarate<65536) datarate=65536;
  3109. maxtim16=datarate*16;
  3110. maxtim04=datarate*4;
  3111. maxtim02=datarate*2;
  3112. maxtim_8=datarate/32;
  3113. #if LONG_TIMING
  3114. maxtim_data=datarate/100;
  3115. #else
  3116. maxtim_data=datarate/300;
  3117. #endif /* LONG_TIMING */
  3118. #if 0
  3119. msg(DBG_TIM,"maxtim_8 %d, maxtim_data %d.\n", maxtim_8, maxtim_data);
  3120. #endif
  3121. }
  3122. /*==========================================================================*/
  3123. #if 0
  3124. static int c2_ReadError(int fam)
  3125. {
  3126. int i;
  3127. clr_cmdbuf();
  3128. response_count=9;
  3129. clr_respo_buf(9);
  3130. if (fam==1)
  3131. {
  3132. drvcmd[0]=CMD0_READ_ERR; /* same as CMD1_ and CMDL_ */
  3133. i=do_cmd(f_putcmd|f_lopsta|f_getsta|f_ResponseStatus);
  3134. }
  3135. else if (fam==2)
  3136. {
  3137. drvcmd[0]=CMD2_READ_ERR;
  3138. i=do_cmd(f_putcmd);
  3139. }
  3140. else return (-1);
  3141. return (i);
  3142. }
  3143. #endif
  3144. /*==========================================================================*/
  3145. static void __init ask_mail(void)
  3146. {
  3147. int i;
  3148. msg(DBG_INF, "please mail the following lines to emoenke@gwdg.de\n");
  3149. msg(DBG_INF, "(don't mail if you are not using the actual kernel):\n");
  3150. msg(DBG_INF, "%s\n", VERSION);
  3151. msg(DBG_INF, "address %03X, type %s, drive %s (ID %d)\n",
  3152. CDo_command, type, current_drive->drive_model, current_drive->drv_id);
  3153. for (i=0;i<12;i++)
  3154. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  3155. msgbuf[i*3]=0;
  3156. msg(DBG_INF,"infobuf =%s\n", msgbuf);
  3157. for (i=0;i<12;i++)
  3158. sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
  3159. msgbuf[i*3]=0;
  3160. msg(DBG_INF,"infobuf =%s\n", msgbuf);
  3161. }
  3162. /*==========================================================================*/
  3163. static int __init check_version(void)
  3164. {
  3165. int i, j, l;
  3166. int teac_possible=0;
  3167. msg(DBG_INI,"check_version: id=%d, d=%d.\n", current_drive->drv_id, current_drive - D_S);
  3168. current_drive->drv_type=0;
  3169. /* check for CR-52x, CR-56x, LCS-7260 and ECS-AT */
  3170. /* clear any pending error state */
  3171. clr_cmdbuf();
  3172. drvcmd[0]=CMD0_READ_ERR; /* same as CMD1_ and CMDL_ */
  3173. response_count=9;
  3174. flags_cmd_out=f_putcmd;
  3175. i=cmd_out();
  3176. if (i<0) msg(DBG_INI,"CMD0_READ_ERR returns %d (ok anyway).\n",i);
  3177. /* read drive version */
  3178. clr_cmdbuf();
  3179. for (i=0;i<12;i++) infobuf[i]=0;
  3180. drvcmd[0]=CMD0_READ_VER; /* same as CMD1_ and CMDL_ */
  3181. response_count=12; /* fam1: only 11 */
  3182. flags_cmd_out=f_putcmd;
  3183. i=cmd_out();
  3184. if (i<-1) msg(DBG_INI,"CMD0_READ_VER returns %d\n",i);
  3185. if (i==-11) teac_possible++;
  3186. j=0;
  3187. for (i=0;i<12;i++) j+=infobuf[i];
  3188. if (j)
  3189. {
  3190. for (i=0;i<12;i++)
  3191. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  3192. msgbuf[i*3]=0;
  3193. msg(DBG_ECS,"infobuf =%s\n", msgbuf);
  3194. for (i=0;i<12;i++)
  3195. sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
  3196. msgbuf[i*3]=0;
  3197. msg(DBG_ECS,"infobuf =%s\n", msgbuf);
  3198. }
  3199. for (i=0;i<4;i++) if (infobuf[i]!=family1[i]) break;
  3200. if (i==4)
  3201. {
  3202. current_drive->drive_model[0]='C';
  3203. current_drive->drive_model[1]='R';
  3204. current_drive->drive_model[2]='-';
  3205. current_drive->drive_model[3]='5';
  3206. current_drive->drive_model[4]=infobuf[i++];
  3207. current_drive->drive_model[5]=infobuf[i++];
  3208. current_drive->drive_model[6]=0;
  3209. current_drive->drv_type=drv_fam1;
  3210. }
  3211. if (!current_drive->drv_type)
  3212. {
  3213. for (i=0;i<8;i++) if (infobuf[i]!=family0[i]) break;
  3214. if (i==8)
  3215. {
  3216. current_drive->drive_model[0]='C';
  3217. current_drive->drive_model[1]='R';
  3218. current_drive->drive_model[2]='-';
  3219. current_drive->drive_model[3]='5';
  3220. current_drive->drive_model[4]='2';
  3221. current_drive->drive_model[5]='x';
  3222. current_drive->drive_model[6]=0;
  3223. current_drive->drv_type=drv_fam0;
  3224. }
  3225. }
  3226. if (!current_drive->drv_type)
  3227. {
  3228. for (i=0;i<8;i++) if (infobuf[i]!=familyL[i]) break;
  3229. if (i==8)
  3230. {
  3231. for (j=0;j<8;j++)
  3232. current_drive->drive_model[j]=infobuf[j];
  3233. current_drive->drive_model[8]=0;
  3234. current_drive->drv_type=drv_famL;
  3235. }
  3236. }
  3237. if (!current_drive->drv_type)
  3238. {
  3239. for (i=0;i<6;i++) if (infobuf[i]!=familyV[i]) break;
  3240. if (i==6)
  3241. {
  3242. for (j=0;j<6;j++)
  3243. current_drive->drive_model[j]=infobuf[j];
  3244. current_drive->drive_model[6]=0;
  3245. current_drive->drv_type=drv_famV;
  3246. i+=2; /* 2 blanks before version */
  3247. }
  3248. }
  3249. if (!current_drive->drv_type)
  3250. {
  3251. /* check for CD200 */
  3252. clr_cmdbuf();
  3253. drvcmd[0]=CMD2_READ_ERR;
  3254. response_count=9;
  3255. flags_cmd_out=f_putcmd;
  3256. i=cmd_out();
  3257. if (i<0) msg(DBG_INI,"CMD2_READERR returns %d (ok anyway).\n",i);
  3258. if (i<0) msg(DBG_000,"CMD2_READERR returns %d (ok anyway).\n",i);
  3259. /* read drive version */
  3260. clr_cmdbuf();
  3261. for (i=0;i<12;i++) infobuf[i]=0;
  3262. if (sbpro_type==1) OUT(CDo_sel_i_d,0);
  3263. #if 0
  3264. OUT(CDo_reset,0);
  3265. sbp_sleep(6*HZ);
  3266. OUT(CDo_enable,current_drive->drv_sel);
  3267. #endif
  3268. drvcmd[0]=CMD2_READ_VER;
  3269. response_count=12;
  3270. flags_cmd_out=f_putcmd;
  3271. i=cmd_out();
  3272. if (i<0) msg(DBG_INI,"CMD2_READ_VER returns %d\n",i);
  3273. if (i==-7) teac_possible++;
  3274. j=0;
  3275. for (i=0;i<12;i++) j+=infobuf[i];
  3276. if (j)
  3277. {
  3278. for (i=0;i<12;i++)
  3279. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  3280. msgbuf[i*3]=0;
  3281. msg(DBG_IDX,"infobuf =%s\n", msgbuf);
  3282. for (i=0;i<12;i++)
  3283. sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
  3284. msgbuf[i*3]=0;
  3285. msg(DBG_IDX,"infobuf =%s\n", msgbuf);
  3286. }
  3287. if (i>=0)
  3288. {
  3289. for (i=0;i<5;i++) if (infobuf[i]!=family2[i]) break;
  3290. if (i==5)
  3291. {
  3292. current_drive->drive_model[0]='C';
  3293. current_drive->drive_model[1]='D';
  3294. current_drive->drive_model[2]='2';
  3295. current_drive->drive_model[3]='0';
  3296. current_drive->drive_model[4]='0';
  3297. current_drive->drive_model[5]=infobuf[i++];
  3298. current_drive->drive_model[6]=infobuf[i++];
  3299. current_drive->drive_model[7]=0;
  3300. current_drive->drv_type=drv_fam2;
  3301. }
  3302. }
  3303. }
  3304. if (!current_drive->drv_type)
  3305. {
  3306. /* check for TEAC CD-55A */
  3307. msg(DBG_TEA,"teac_possible: %d\n",teac_possible);
  3308. for (j=1;j<=((current_drive->drv_id==0)?3:1);j++)
  3309. {
  3310. for (l=1;l<=((current_drive->drv_id==0)?10:1);l++)
  3311. {
  3312. msg(DBG_TEA,"TEAC reset #%d-%d.\n", j, l);
  3313. if (sbpro_type==1) OUT(CDo_reset,0);
  3314. else
  3315. {
  3316. OUT(CDo_enable,current_drive->drv_sel);
  3317. OUT(CDo_sel_i_d,0);
  3318. OUT(CDo_command,CMDT_RESET);
  3319. for (i=0;i<9;i++) OUT(CDo_command,0);
  3320. }
  3321. sbp_sleep(5*HZ/10);
  3322. OUT(CDo_enable,current_drive->drv_sel);
  3323. OUT(CDo_sel_i_d,0);
  3324. i=inb(CDi_status);
  3325. msg(DBG_TEA,"TEAC CDi_status: %02X.\n",i);
  3326. #if 0
  3327. if (i&s_not_result_ready) continue; /* drive not present or ready */
  3328. #endif
  3329. i=inb(CDi_info);
  3330. msg(DBG_TEA,"TEAC CDi_info: %02X.\n",i);
  3331. if (i==0x55) break; /* drive found */
  3332. }
  3333. if (i==0x55) break; /* drive found */
  3334. }
  3335. if (i==0x55) /* drive found */
  3336. {
  3337. msg(DBG_TEA,"TEAC drive found.\n");
  3338. clr_cmdbuf();
  3339. flags_cmd_out=f_putcmd;
  3340. response_count=12;
  3341. drvcmd[0]=CMDT_READ_VER;
  3342. drvcmd[4]=response_count;
  3343. for (i=0;i<12;i++) infobuf[i]=0;
  3344. i=cmd_out_T();
  3345. if (i!=0) msg(DBG_TEA,"cmd_out_T(CMDT_READ_VER) returns %d.\n",i);
  3346. for (i=1;i<6;i++) if (infobuf[i]!=familyT[i-1]) break;
  3347. if (i==6)
  3348. {
  3349. current_drive->drive_model[0]='C';
  3350. current_drive->drive_model[1]='D';
  3351. current_drive->drive_model[2]='-';
  3352. current_drive->drive_model[3]='5';
  3353. current_drive->drive_model[4]='5';
  3354. current_drive->drive_model[5]=0;
  3355. current_drive->drv_type=drv_famT;
  3356. }
  3357. }
  3358. }
  3359. if (!current_drive->drv_type)
  3360. {
  3361. msg(DBG_TEA,"no drive found at address %03X under ID %d.\n",CDo_command,current_drive->drv_id);
  3362. return (-522);
  3363. }
  3364. for (j=0;j<4;j++) current_drive->firmware_version[j]=infobuf[i+j];
  3365. if (famL_drive)
  3366. {
  3367. u_char lcs_firm_e1[]="A E1";
  3368. u_char lcs_firm_f4[]="A4F4";
  3369. for (j=0;j<4;j++)
  3370. if (current_drive->firmware_version[j]!=lcs_firm_e1[j]) break;
  3371. if (j==4) current_drive->drv_type=drv_e1;
  3372. for (j=0;j<4;j++)
  3373. if (current_drive->firmware_version[j]!=lcs_firm_f4[j]) break;
  3374. if (j==4) current_drive->drv_type=drv_f4;
  3375. if (current_drive->drv_type==drv_famL) ask_mail();
  3376. }
  3377. else if (famT_drive)
  3378. {
  3379. j=infobuf[4]; /* one-byte version??? - here: 0x15 */
  3380. if (j=='5')
  3381. {
  3382. current_drive->firmware_version[0]=infobuf[7];
  3383. current_drive->firmware_version[1]=infobuf[8];
  3384. current_drive->firmware_version[2]=infobuf[10];
  3385. current_drive->firmware_version[3]=infobuf[11];
  3386. }
  3387. else
  3388. {
  3389. if (j!=0x15) ask_mail();
  3390. current_drive->firmware_version[0]='0';
  3391. current_drive->firmware_version[1]='.';
  3392. current_drive->firmware_version[2]='0'+(j>>4);
  3393. current_drive->firmware_version[3]='0'+(j&0x0f);
  3394. }
  3395. }
  3396. else /* CR-52x, CR-56x, CD200, ECS-AT */
  3397. {
  3398. j = (current_drive->firmware_version[0] & 0x0F) * 100 +
  3399. (current_drive->firmware_version[2] & 0x0F) *10 +
  3400. (current_drive->firmware_version[3] & 0x0F);
  3401. if (fam0_drive)
  3402. {
  3403. if (j<200) current_drive->drv_type=drv_199;
  3404. else if (j<201) current_drive->drv_type=drv_200;
  3405. else if (j<210) current_drive->drv_type=drv_201;
  3406. else if (j<211) current_drive->drv_type=drv_210;
  3407. else if (j<300) current_drive->drv_type=drv_211;
  3408. else if (j>=300) current_drive->drv_type=drv_300;
  3409. }
  3410. else if (fam1_drive)
  3411. {
  3412. if (j<100) current_drive->drv_type=drv_099;
  3413. else
  3414. {
  3415. current_drive->drv_type=drv_100;
  3416. if ((j!=500)&&(j!=102)) ask_mail();
  3417. }
  3418. }
  3419. else if (fam2_drive)
  3420. {
  3421. if (current_drive->drive_model[5]=='F')
  3422. {
  3423. if ((j!=1)&&(j!=35)&&(j!=200)&&(j!=210))
  3424. ask_mail(); /* unknown version at time */
  3425. }
  3426. else
  3427. {
  3428. msg(DBG_INF,"this CD200 drive is not fully supported yet - only audio will work.\n");
  3429. if ((j!=101)&&(j!=35))
  3430. ask_mail(); /* unknown version at time */
  3431. }
  3432. }
  3433. else if (famV_drive)
  3434. {
  3435. if ((j==100)||(j==150)) current_drive->drv_type=drv_at;
  3436. ask_mail(); /* hopefully we get some feedback by this */
  3437. }
  3438. }
  3439. msg(DBG_LCS,"drive type %02X\n",current_drive->drv_type);
  3440. msg(DBG_INI,"check_version done.\n");
  3441. return (0);
  3442. }
  3443. /*==========================================================================*/
  3444. static void switch_drive(struct sbpcd_drive *p)
  3445. {
  3446. current_drive = p;
  3447. OUT(CDo_enable,current_drive->drv_sel);
  3448. msg(DBG_DID,"drive %d (ID=%d) activated.\n",
  3449. current_drive - D_S, current_drive->drv_id);
  3450. return;
  3451. }
  3452. /*==========================================================================*/
  3453. #ifdef PATH_CHECK
  3454. /*
  3455. * probe for the presence of an interface card
  3456. */
  3457. static int __init check_card(int port)
  3458. {
  3459. #undef N_RESPO
  3460. #define N_RESPO 20
  3461. int i, j, k;
  3462. u_char response[N_RESPO];
  3463. u_char save_port0;
  3464. u_char save_port3;
  3465. msg(DBG_INI,"check_card entered.\n");
  3466. save_port0=inb(port+0);
  3467. save_port3=inb(port+3);
  3468. for (j=0;j<NR_SBPCD;j++)
  3469. {
  3470. OUT(port+3,j) ; /* enable drive #j */
  3471. OUT(port+0,CMD0_PATH_CHECK);
  3472. for (i=10;i>0;i--) OUT(port+0,0);
  3473. for (k=0;k<N_RESPO;k++) response[k]=0;
  3474. for (k=0;k<N_RESPO;k++)
  3475. {
  3476. for (i=10000;i>0;i--)
  3477. {
  3478. if (inb(port+1)&s_not_result_ready) continue;
  3479. response[k]=inb(port+0);
  3480. break;
  3481. }
  3482. }
  3483. for (i=0;i<N_RESPO;i++)
  3484. sprintf(&msgbuf[i*3], " %02X", response[i]);
  3485. msgbuf[i*3]=0;
  3486. msg(DBG_TEA,"path check 00 (%d): %s\n", j, msgbuf);
  3487. OUT(port+0,CMD0_PATH_CHECK);
  3488. for (i=10;i>0;i--) OUT(port+0,0);
  3489. for (k=0;k<N_RESPO;k++) response[k]=0xFF;
  3490. for (k=0;k<N_RESPO;k++)
  3491. {
  3492. for (i=10000;i>0;i--)
  3493. {
  3494. if (inb(port+1)&s_not_result_ready) continue;
  3495. response[k]=inb(port+0);
  3496. break;
  3497. }
  3498. }
  3499. for (i=0;i<N_RESPO;i++)
  3500. sprintf(&msgbuf[i*3], " %02X", response[i]);
  3501. msgbuf[i*3]=0;
  3502. msg(DBG_TEA,"path check 00 (%d): %s\n", j, msgbuf);
  3503. if (response[0]==0xAA)
  3504. if (response[1]==0x55)
  3505. return (0);
  3506. }
  3507. for (j=0;j<NR_SBPCD;j++)
  3508. {
  3509. OUT(port+3,j) ; /* enable drive #j */
  3510. OUT(port+0,CMD2_READ_VER);
  3511. for (i=10;i>0;i--) OUT(port+0,0);
  3512. for (k=0;k<N_RESPO;k++) response[k]=0;
  3513. for (k=0;k<N_RESPO;k++)
  3514. {
  3515. for (i=1000000;i>0;i--)
  3516. {
  3517. if (inb(port+1)&s_not_result_ready) continue;
  3518. response[k]=inb(port+0);
  3519. break;
  3520. }
  3521. }
  3522. for (i=0;i<N_RESPO;i++)
  3523. sprintf(&msgbuf[i*3], " %02X", response[i]);
  3524. msgbuf[i*3]=0;
  3525. msg(DBG_TEA,"path check 12 (%d): %s\n", j, msgbuf);
  3526. OUT(port+0,CMD2_READ_VER);
  3527. for (i=10;i>0;i--) OUT(port+0,0);
  3528. for (k=0;k<N_RESPO;k++) response[k]=0xFF;
  3529. for (k=0;k<N_RESPO;k++)
  3530. {
  3531. for (i=1000000;i>0;i--)
  3532. {
  3533. if (inb(port+1)&s_not_result_ready) continue;
  3534. response[k]=inb(port+0);
  3535. break;
  3536. }
  3537. }
  3538. for (i=0;i<N_RESPO;i++)
  3539. sprintf(&msgbuf[i*3], " %02X", response[i]);
  3540. msgbuf[i*3]=0;
  3541. msg(DBG_TEA,"path check 12 (%d): %s\n", j, msgbuf);
  3542. if (response[0]==0xAA)
  3543. if (response[1]==0x55)
  3544. return (0);
  3545. }
  3546. OUT(port+0,save_port0);
  3547. OUT(port+3,save_port3);
  3548. return (0); /* in any case - no real "function" at time */
  3549. }
  3550. #endif /* PATH_CHECK */
  3551. /*==========================================================================*/
  3552. /*==========================================================================*/
  3553. /*
  3554. * probe for the presence of drives on the selected controller
  3555. */
  3556. static int __init check_drives(void)
  3557. {
  3558. int i, j;
  3559. msg(DBG_INI,"check_drives entered.\n");
  3560. ndrives=0;
  3561. for (j=0;j<max_drives;j++)
  3562. {
  3563. struct sbpcd_drive *p = D_S + ndrives;
  3564. p->drv_id=j;
  3565. if (sbpro_type==1) p->drv_sel=(j&0x01)<<1|(j&0x02)>>1;
  3566. else p->drv_sel=j;
  3567. switch_drive(p);
  3568. msg(DBG_INI,"check_drives: drive %d (ID=%d) activated.\n",ndrives,j);
  3569. msg(DBG_000,"check_drives: drive %d (ID=%d) activated.\n",ndrives,j);
  3570. i=check_version();
  3571. if (i<0) msg(DBG_INI,"check_version returns %d.\n",i);
  3572. else
  3573. {
  3574. current_drive->drv_options=drv_pattern[j];
  3575. if (fam0L_drive) current_drive->drv_options&=~(speed_auto|speed_300|speed_150);
  3576. msg(DBG_INF, "Drive %d (ID=%d): %.9s (%.4s) at 0x%03X (type %d)\n",
  3577. current_drive - D_S,
  3578. current_drive->drv_id,
  3579. current_drive->drive_model,
  3580. current_drive->firmware_version,
  3581. CDo_command,
  3582. sbpro_type);
  3583. ndrives++;
  3584. }
  3585. }
  3586. for (j=ndrives;j<NR_SBPCD;j++) D_S[j].drv_id=-1;
  3587. if (ndrives==0) return (-1);
  3588. return (0);
  3589. }
  3590. /*==========================================================================*/
  3591. #ifdef FUTURE
  3592. /*
  3593. * obtain if requested service disturbs current audio state
  3594. */
  3595. static int obey_audio_state(u_char audio_state, u_char func,u_char subfunc)
  3596. {
  3597. switch (audio_state) /* audio status from controller */
  3598. {
  3599. case aud_11: /* "audio play in progress" */
  3600. case audx11:
  3601. switch (func) /* DOS command code */
  3602. {
  3603. case cmd_07: /* input flush */
  3604. case cmd_0d: /* open device */
  3605. case cmd_0e: /* close device */
  3606. case cmd_0c: /* ioctl output */
  3607. return (1);
  3608. case cmd_03: /* ioctl input */
  3609. switch (subfunc)
  3610. /* DOS ioctl input subfunction */
  3611. {
  3612. case cxi_00:
  3613. case cxi_06:
  3614. case cxi_09:
  3615. return (1);
  3616. default:
  3617. return (ERROR15);
  3618. }
  3619. return (1);
  3620. default:
  3621. return (ERROR15);
  3622. }
  3623. return (1);
  3624. case aud_12: /* "audio play paused" */
  3625. case audx12:
  3626. return (1);
  3627. default:
  3628. return (2);
  3629. }
  3630. }
  3631. /*==========================================================================*/
  3632. /* allowed is only
  3633. * ioctl_o, flush_input, open_device, close_device,
  3634. * tell_address, tell_volume, tell_capabiliti,
  3635. * tell_framesize, tell_CD_changed, tell_audio_posi
  3636. */
  3637. static int check_allowed1(u_char func1, u_char func2)
  3638. {
  3639. #if 000
  3640. if (func1==ioctl_o) return (0);
  3641. if (func1==read_long) return (-1);
  3642. if (func1==read_long_prefetch) return (-1);
  3643. if (func1==seek) return (-1);
  3644. if (func1==audio_play) return (-1);
  3645. if (func1==audio_pause) return (-1);
  3646. if (func1==audio_resume) return (-1);
  3647. if (func1!=ioctl_i) return (0);
  3648. if (func2==tell_SubQ_run_tot) return (-1);
  3649. if (func2==tell_cdsize) return (-1);
  3650. if (func2==tell_TocDescrip) return (-1);
  3651. if (func2==tell_TocEntry) return (-1);
  3652. if (func2==tell_subQ_info) return (-1);
  3653. if (fam1_drive) if (func2==tell_SubChanInfo) return (-1);
  3654. if (func2==tell_UPC) return (-1);
  3655. #else
  3656. return (0);
  3657. #endif
  3658. }
  3659. /*==========================================================================*/
  3660. static int check_allowed2(u_char func1, u_char func2)
  3661. {
  3662. #if 000
  3663. if (func1==read_long) return (-1);
  3664. if (func1==read_long_prefetch) return (-1);
  3665. if (func1==seek) return (-1);
  3666. if (func1==audio_play) return (-1);
  3667. if (func1!=ioctl_o) return (0);
  3668. if (fam1_drive)
  3669. {
  3670. if (func2==EjectDisk) return (-1);
  3671. if (func2==CloseTray) return (-1);
  3672. }
  3673. #else
  3674. return (0);
  3675. #endif
  3676. }
  3677. /*==========================================================================*/
  3678. static int check_allowed3(u_char func1, u_char func2)
  3679. {
  3680. #if 000
  3681. if (func1==ioctl_i)
  3682. {
  3683. if (func2==tell_address) return (0);
  3684. if (func2==tell_capabiliti) return (0);
  3685. if (func2==tell_CD_changed) return (0);
  3686. if (fam0L_drive) if (func2==tell_SubChanInfo) return (0);
  3687. return (-1);
  3688. }
  3689. if (func1==ioctl_o)
  3690. {
  3691. if (func2==DriveReset) return (0);
  3692. if (fam0L_drive)
  3693. {
  3694. if (func2==EjectDisk) return (0);
  3695. if (func2==LockDoor) return (0);
  3696. if (func2==CloseTray) return (0);
  3697. }
  3698. return (-1);
  3699. }
  3700. if (func1==flush_input) return (-1);
  3701. if (func1==read_long) return (-1);
  3702. if (func1==read_long_prefetch) return (-1);
  3703. if (func1==seek) return (-1);
  3704. if (func1==audio_play) return (-1);
  3705. if (func1==audio_pause) return (-1);
  3706. if (func1==audio_resume) return (-1);
  3707. #else
  3708. return (0);
  3709. #endif
  3710. }
  3711. /*==========================================================================*/
  3712. static int seek_pos_audio_end(void)
  3713. {
  3714. int i;
  3715. i=msf2blk(current_drive->pos_audio_end)-1;
  3716. if (i<0) return (-1);
  3717. i=cc_Seek(i,0);
  3718. return (i);
  3719. }
  3720. #endif /* FUTURE */
  3721. /*==========================================================================*/
  3722. static int ReadToC(void)
  3723. {
  3724. int i, j;
  3725. current_drive->diskstate_flags &= ~toc_bit;
  3726. current_drive->ored_ctl_adr=0;
  3727. /* special handling of CD-I HE */
  3728. if ((current_drive->n_first_track == 2 && current_drive->n_last_track == 2) ||
  3729. current_drive->xa_byte == 0x10)
  3730. {
  3731. current_drive->TocBuffer[1].nixbyte=0;
  3732. current_drive->TocBuffer[1].ctl_adr=0x40;
  3733. current_drive->TocBuffer[1].number=1;
  3734. current_drive->TocBuffer[1].format=0;
  3735. current_drive->TocBuffer[1].address=blk2msf(0);
  3736. current_drive->ored_ctl_adr |= 0x40;
  3737. current_drive->n_first_track = 1;
  3738. current_drive->n_last_track = 1;
  3739. current_drive->xa_byte = 0x10;
  3740. j = 2;
  3741. } else
  3742. for (j=current_drive->n_first_track;j<=current_drive->n_last_track;j++)
  3743. {
  3744. i=cc_ReadTocEntry(j);
  3745. if (i<0)
  3746. {
  3747. msg(DBG_INF,"cc_ReadTocEntry(%d) returns %d.\n",j,i);
  3748. return (i);
  3749. }
  3750. current_drive->TocBuffer[j].nixbyte=current_drive->TocEnt_nixbyte;
  3751. current_drive->TocBuffer[j].ctl_adr=current_drive->TocEnt_ctl_adr;
  3752. current_drive->TocBuffer[j].number=current_drive->TocEnt_number;
  3753. current_drive->TocBuffer[j].format=current_drive->TocEnt_format;
  3754. current_drive->TocBuffer[j].address=current_drive->TocEnt_address;
  3755. current_drive->ored_ctl_adr |= current_drive->TocEnt_ctl_adr;
  3756. }
  3757. /* fake entry for LeadOut Track */
  3758. current_drive->TocBuffer[j].nixbyte=0;
  3759. current_drive->TocBuffer[j].ctl_adr=0;
  3760. current_drive->TocBuffer[j].number=CDROM_LEADOUT;
  3761. current_drive->TocBuffer[j].format=0;
  3762. current_drive->TocBuffer[j].address=current_drive->size_msf;
  3763. current_drive->diskstate_flags |= toc_bit;
  3764. return (0);
  3765. }
  3766. /*==========================================================================*/
  3767. static int DiskInfo(void)
  3768. {
  3769. int i, j;
  3770. current_drive->mode=READ_M1;
  3771. #undef LOOP_COUNT
  3772. #define LOOP_COUNT 10 /* needed for some "old" drives */
  3773. msg(DBG_000,"DiskInfo entered.\n");
  3774. for (j=1;j<LOOP_COUNT;j++)
  3775. {
  3776. #if 0
  3777. i=SetSpeed();
  3778. if (i<0)
  3779. {
  3780. msg(DBG_INF,"DiskInfo: SetSpeed returns %d\n", i);
  3781. continue;
  3782. }
  3783. i=cc_ModeSense();
  3784. if (i<0)
  3785. {
  3786. msg(DBG_INF,"DiskInfo: cc_ModeSense returns %d\n", i);
  3787. continue;
  3788. }
  3789. #endif
  3790. i=cc_ReadCapacity();
  3791. if (i>=0) break;
  3792. msg(DBG_INF,"DiskInfo: ReadCapacity #%d returns %d\n", j, i);
  3793. #if 0
  3794. i=cc_DriveReset();
  3795. #endif
  3796. if (!fam0_drive && j == 2) break;
  3797. }
  3798. if (j==LOOP_COUNT) return (-33); /* give up */
  3799. i=cc_ReadTocDescr();
  3800. if (i<0)
  3801. {
  3802. msg(DBG_INF,"DiskInfo: ReadTocDescr returns %d\n", i);
  3803. return (i);
  3804. }
  3805. i=ReadToC();
  3806. if (i<0)
  3807. {
  3808. msg(DBG_INF,"DiskInfo: ReadToC returns %d\n", i);
  3809. return (i);
  3810. }
  3811. i=cc_CheckMultiSession();
  3812. if (i<0)
  3813. {
  3814. msg(DBG_INF,"DiskInfo: cc_CheckMultiSession returns %d\n", i);
  3815. return (i);
  3816. }
  3817. if (current_drive->f_multisession) current_drive->sbp_bufsiz=1; /* possibly a weird PhotoCD */
  3818. else current_drive->sbp_bufsiz=buffers;
  3819. i=cc_ReadTocEntry(current_drive->n_first_track);
  3820. if (i<0)
  3821. {
  3822. msg(DBG_INF,"DiskInfo: cc_ReadTocEntry(1) returns %d\n", i);
  3823. return (i);
  3824. }
  3825. i=cc_ReadUPC();
  3826. if (i<0) msg(DBG_INF,"DiskInfo: cc_ReadUPC returns %d\n", i);
  3827. if ((fam0L_drive) && (current_drive->xa_byte==0x20 || current_drive->xa_byte == 0x10))
  3828. {
  3829. /* XA disk with old drive */
  3830. cc_ModeSelect(CD_FRAMESIZE_RAW1);
  3831. cc_ModeSense();
  3832. }
  3833. if (famT_drive) cc_prep_mode_T();
  3834. msg(DBG_000,"DiskInfo done.\n");
  3835. return (0);
  3836. }
  3837. static int sbpcd_drive_status(struct cdrom_device_info *cdi, int slot_nr)
  3838. {
  3839. struct sbpcd_drive *p = cdi->handle;
  3840. int st;
  3841. if (CDSL_CURRENT != slot_nr) {
  3842. /* we have no changer support */
  3843. return -EINVAL;
  3844. }
  3845. cc_ReadStatus();
  3846. st=ResponseStatus();
  3847. if (st<0)
  3848. {
  3849. msg(DBG_INF,"sbpcd_drive_status: timeout.\n");
  3850. return (0);
  3851. }
  3852. msg(DBG_000,"Drive Status: door_locked =%d.\n", st_door_locked);
  3853. msg(DBG_000,"Drive Status: door_closed =%d.\n", st_door_closed);
  3854. msg(DBG_000,"Drive Status: caddy_in =%d.\n", st_caddy_in);
  3855. msg(DBG_000,"Drive Status: disk_ok =%d.\n", st_diskok);
  3856. msg(DBG_000,"Drive Status: spinning =%d.\n", st_spinning);
  3857. msg(DBG_000,"Drive Status: busy =%d.\n", st_busy);
  3858. #if 0
  3859. if (!(p->status_bits & p_door_closed)) return CDS_TRAY_OPEN;
  3860. if (p->status_bits & p_disk_ok) return CDS_DISC_OK;
  3861. if (p->status_bits & p_disk_in) return CDS_DRIVE_NOT_READY;
  3862. return CDS_NO_DISC;
  3863. #else
  3864. if (p->status_bits & p_spinning) return CDS_DISC_OK;
  3865. /* return CDS_TRAY_OPEN; */
  3866. return CDS_NO_DISC;
  3867. #endif
  3868. }
  3869. /*==========================================================================*/
  3870. #ifdef FUTURE
  3871. /*
  3872. * called always if driver gets entered
  3873. * returns 0 or ERROR2 or ERROR15
  3874. */
  3875. static int prepare(u_char func, u_char subfunc)
  3876. {
  3877. int i;
  3878. if (fam0L_drive)
  3879. {
  3880. i=inb(CDi_status);
  3881. if (i&s_attention) GetStatus();
  3882. }
  3883. else if (fam1_drive) GetStatus();
  3884. else if (fam2_drive) GetStatus();
  3885. else if (famT_drive) GetStatus();
  3886. if (current_drive->CD_changed==0xFF)
  3887. {
  3888. current_drive->diskstate_flags=0;
  3889. current_drive->audio_state=0;
  3890. if (!st_diskok)
  3891. {
  3892. i=check_allowed1(func,subfunc);
  3893. if (i<0) return (-2);
  3894. }
  3895. else
  3896. {
  3897. i=check_allowed3(func,subfunc);
  3898. if (i<0)
  3899. {
  3900. current_drive->CD_changed=1;
  3901. return (-15);
  3902. }
  3903. }
  3904. }
  3905. else
  3906. {
  3907. if (!st_diskok)
  3908. {
  3909. current_drive->diskstate_flags=0;
  3910. current_drive->audio_state=0;
  3911. i=check_allowed1(func,subfunc);
  3912. if (i<0) return (-2);
  3913. }
  3914. else
  3915. {
  3916. if (st_busy)
  3917. {
  3918. if (current_drive->audio_state!=audio_pausing)
  3919. {
  3920. i=check_allowed2(func,subfunc);
  3921. if (i<0) return (-2);
  3922. }
  3923. }
  3924. else
  3925. {
  3926. if (current_drive->audio_state==audio_playing) seek_pos_audio_end();
  3927. current_drive->audio_state=0;
  3928. }
  3929. if (!frame_size_valid)
  3930. {
  3931. i=DiskInfo();
  3932. if (i<0)
  3933. {
  3934. current_drive->diskstate_flags=0;
  3935. current_drive->audio_state=0;
  3936. i=check_allowed1(func,subfunc);
  3937. if (i<0) return (-2);
  3938. }
  3939. }
  3940. }
  3941. }
  3942. return (0);
  3943. }
  3944. #endif /* FUTURE */
  3945. /*==========================================================================*/
  3946. /*==========================================================================*/
  3947. /*
  3948. * Check the results of the "get status" command.
  3949. */
  3950. static int sbp_status(void)
  3951. {
  3952. int st;
  3953. st=ResponseStatus();
  3954. if (st<0)
  3955. {
  3956. msg(DBG_INF,"sbp_status: timeout.\n");
  3957. return (0);
  3958. }
  3959. if (!st_spinning) msg(DBG_SPI,"motor got off - ignoring.\n");
  3960. if (st_check)
  3961. {
  3962. msg(DBG_INF,"st_check detected - retrying.\n");
  3963. return (0);
  3964. }
  3965. if (!st_door_closed)
  3966. {
  3967. msg(DBG_INF,"door is open - retrying.\n");
  3968. return (0);
  3969. }
  3970. if (!st_caddy_in)
  3971. {
  3972. msg(DBG_INF,"disk removed - retrying.\n");
  3973. return (0);
  3974. }
  3975. if (!st_diskok)
  3976. {
  3977. msg(DBG_INF,"!st_diskok detected - retrying.\n");
  3978. return (0);
  3979. }
  3980. if (st_busy)
  3981. {
  3982. msg(DBG_INF,"st_busy detected - retrying.\n");
  3983. return (0);
  3984. }
  3985. return (1);
  3986. }
  3987. /*==========================================================================*/
  3988. static int sbpcd_get_last_session(struct cdrom_device_info *cdi, struct cdrom_multisession *ms_infp)
  3989. {
  3990. struct sbpcd_drive *p = cdi->handle;
  3991. ms_infp->addr_format = CDROM_LBA;
  3992. ms_infp->addr.lba = p->lba_multi;
  3993. if (p->f_multisession)
  3994. ms_infp->xa_flag=1; /* valid redirection address */
  3995. else
  3996. ms_infp->xa_flag=0; /* invalid redirection address */
  3997. return 0;
  3998. }
  3999. /*==========================================================================*/
  4000. /*==========================================================================*/
  4001. /*
  4002. * ioctl support
  4003. */
  4004. static int sbpcd_dev_ioctl(struct cdrom_device_info *cdi, u_int cmd,
  4005. u_long arg)
  4006. {
  4007. struct sbpcd_drive *p = cdi->handle;
  4008. int i;
  4009. msg(DBG_IO2,"ioctl(%s, 0x%08lX, 0x%08lX)\n", cdi->name, cmd, arg);
  4010. if (p->drv_id==-1) {
  4011. msg(DBG_INF, "ioctl: bad device: %s\n", cdi->name);
  4012. return (-ENXIO); /* no such drive */
  4013. }
  4014. down(&ioctl_read_sem);
  4015. if (p != current_drive)
  4016. switch_drive(p);
  4017. msg(DBG_IO2,"ioctl: device %s, request %04X\n",cdi->name,cmd);
  4018. switch (cmd) /* Sun-compatible */
  4019. {
  4020. case DDIOCSDBG: /* DDI Debug */
  4021. if (!capable(CAP_SYS_ADMIN)) RETURN_UP(-EPERM);
  4022. i=sbpcd_dbg_ioctl(arg,1);
  4023. RETURN_UP(i);
  4024. case CDROMRESET: /* hard reset the drive */
  4025. msg(DBG_IOC,"ioctl: CDROMRESET entered.\n");
  4026. i=DriveReset();
  4027. current_drive->audio_state=0;
  4028. RETURN_UP(i);
  4029. case CDROMREADMODE1:
  4030. msg(DBG_IOC,"ioctl: CDROMREADMODE1 requested.\n");
  4031. #ifdef SAFE_MIXED
  4032. if (current_drive->has_data>1) RETURN_UP(-EBUSY);
  4033. #endif /* SAFE_MIXED */
  4034. cc_ModeSelect(CD_FRAMESIZE);
  4035. cc_ModeSense();
  4036. current_drive->mode=READ_M1;
  4037. RETURN_UP(0);
  4038. case CDROMREADMODE2: /* not usable at the moment */
  4039. msg(DBG_IOC,"ioctl: CDROMREADMODE2 requested.\n");
  4040. #ifdef SAFE_MIXED
  4041. if (current_drive->has_data>1) RETURN_UP(-EBUSY);
  4042. #endif /* SAFE_MIXED */
  4043. cc_ModeSelect(CD_FRAMESIZE_RAW1);
  4044. cc_ModeSense();
  4045. current_drive->mode=READ_M2;
  4046. RETURN_UP(0);
  4047. case CDROMAUDIOBUFSIZ: /* configure the audio buffer size */
  4048. msg(DBG_IOC,"ioctl: CDROMAUDIOBUFSIZ entered.\n");
  4049. if (current_drive->sbp_audsiz>0) 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) vfree(D_S[j].aud_buf);
  5651. if ((unregister_cdrom(D_S[j].sbpcd_infop) == -EINVAL))
  5652. {
  5653. msg(DBG_INF, "What's that: can't unregister info %s.\n", major_name);
  5654. return;
  5655. }
  5656. vfree(D_S[j].sbpcd_infop);
  5657. }
  5658. devfs_remove("sbp");
  5659. msg(DBG_INF, "%s module released.\n", major_name);
  5660. }
  5661. module_init(__sbpcd_init) /*HACK!*/;
  5662. module_exit(sbpcd_exit);
  5663. #endif /* MODULE */
  5664. static int sbpcd_media_changed(struct cdrom_device_info *cdi, int disc_nr)
  5665. {
  5666. struct sbpcd_drive *p = cdi->handle;
  5667. msg(DBG_CHK,"media_check (%s) called\n", cdi->name);
  5668. if (p->CD_changed==0xFF)
  5669. {
  5670. p->CD_changed=0;
  5671. msg(DBG_CHK,"medium changed (drive %s)\n", cdi->name);
  5672. current_drive->diskstate_flags &= ~toc_bit;
  5673. /* we *don't* need invalidate here, it's done by caller */
  5674. current_drive->diskstate_flags &= ~cd_size_bit;
  5675. #ifdef SAFE_MIXED
  5676. current_drive->has_data=0;
  5677. #endif /* SAFE_MIXED */
  5678. return (1);
  5679. }
  5680. else
  5681. return (0);
  5682. }
  5683. MODULE_LICENSE("GPL");
  5684. /* FIXME: Old modules.conf claims MATSUSHITA_CDROM2_MAJOR and CDROM3, but
  5685. AFAICT this doesn't support those majors, so why? --RR 30 Jul 2003 */
  5686. MODULE_ALIAS_BLOCKDEV_MAJOR(MATSUSHITA_CDROM_MAJOR);
  5687. /*==========================================================================*/
  5688. /*
  5689. * Overrides for Emacs so that we follow Linus's tabbing style.
  5690. * Emacs will notice this stuff at the end of the file and automatically
  5691. * adjust the settings for this buffer only. This must remain at the end
  5692. * of the file.
  5693. * ---------------------------------------------------------------------------
  5694. * Local variables:
  5695. * c-indent-level: 8
  5696. * c-brace-imaginary-offset: 0
  5697. * c-brace-offset: -8
  5698. * c-argdecl-indent: 8
  5699. * c-label-offset: -8
  5700. * c-continued-statement-offset: 8
  5701. * c-continued-brace-offset: 0
  5702. * End:
  5703. */