sbpcd.c 167 KB

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