sbpcd.c 167 KB

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