sbpcd.c 167 KB

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