dmasound_awacs.c 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188
  1. /*
  2. * linux/sound/oss/dmasound/dmasound_awacs.c
  3. *
  4. * PowerMac `AWACS' and `Burgundy' DMA Sound Driver
  5. * with some limited support for DACA & Tumbler
  6. *
  7. * See linux/sound/oss/dmasound/dmasound_core.c for copyright and
  8. * history prior to 2001/01/26.
  9. *
  10. * 26/01/2001 ed 0.1 Iain Sandoe
  11. * - added version info.
  12. * - moved dbdma command buffer allocation to PMacXXXSqSetup()
  13. * - fixed up beep dbdma cmd buffers
  14. *
  15. * 08/02/2001 [0.2]
  16. * - make SNDCTL_DSP_GETFMTS return the correct info for the h/w
  17. * - move soft format translations to a separate file
  18. * - [0.3] make SNDCTL_DSP_GETCAPS return correct info.
  19. * - [0.4] more informative machine name strings.
  20. * - [0.5]
  21. * - record changes.
  22. * - made the default_hard/soft entries.
  23. * 04/04/2001 [0.6]
  24. * - minor correction to bit assignments in awacs_defs.h
  25. * - incorporate mixer changes from 2.2.x back-port.
  26. * - take out passthru as a rec input (it isn't).
  27. * - make Input Gain slider work the 'right way up'.
  28. * - try to make the mixer sliders more logical - so now the
  29. * input selectors are just two-state (>50% == ON) and the
  30. * Input Gain slider handles the rest of the gain issues.
  31. * - try to pick slider representations that most closely match
  32. * the actual use - e.g. IGain for input gain...
  33. * - first stab at over/under-run detection.
  34. * - minor cosmetic changes to IRQ identification.
  35. * - fix bug where rates > max would be reported as supported.
  36. * - first stab at over/under-run detection.
  37. * - make use of i2c for mixer settings conditional on perch
  38. * rather than cuda (some machines without perch have cuda).
  39. * - fix bug where TX stops when dbdma status comes up "DEAD"
  40. * so far only reported on PowerComputing clones ... but.
  41. * - put in AWACS/Screamer register write timeouts.
  42. * - part way to partitioning the init() stuff
  43. * - first pass at 'tumbler' stuff (not support - just an attempt
  44. * to allow the driver to load on new G4s).
  45. * 01/02/2002 [0.7] - BenH
  46. * - all sort of minor bits went in since the latest update, I
  47. * bumped the version number for that reason
  48. *
  49. * 07/26/2002 [0.8] - BenH
  50. * - More minor bits since last changelog (I should be more careful
  51. * with those)
  52. * - Support for snapper & better tumbler integration by Toby Sargeant
  53. * - Headphone detect for scremer by Julien Blache
  54. * - More tumbler fixed by Andreas Schwab
  55. * 11/29/2003 [0.8.1] - Renzo Davoli (King Enzo)
  56. * - Support for Snapper line in
  57. * - snapper input resampling (for rates < 44100)
  58. * - software line gain control
  59. */
  60. /* GENERAL FIXME/TODO: check that the assumptions about what is written to
  61. mac-io is valid for DACA & Tumbler.
  62. This driver is in bad need of a rewrite. The dbdma code has to be split,
  63. some proper device-tree parsing code has to be written, etc...
  64. */
  65. #include <linux/types.h>
  66. #include <linux/module.h>
  67. #include <linux/slab.h>
  68. #include <linux/init.h>
  69. #include <linux/delay.h>
  70. #include <linux/soundcard.h>
  71. #include <linux/adb.h>
  72. #include <linux/nvram.h>
  73. #include <linux/tty.h>
  74. #include <linux/vt_kern.h>
  75. #include <linux/spinlock.h>
  76. #include <linux/kmod.h>
  77. #include <linux/interrupt.h>
  78. #include <linux/input.h>
  79. #include <linux/mutex.h>
  80. #ifdef CONFIG_ADB_CUDA
  81. #include <linux/cuda.h>
  82. #endif
  83. #ifdef CONFIG_ADB_PMU
  84. #include <linux/pmu.h>
  85. #endif
  86. #include <asm/uaccess.h>
  87. #include <asm/prom.h>
  88. #include <asm/machdep.h>
  89. #include <asm/io.h>
  90. #include <asm/dbdma.h>
  91. #include <asm/pmac_feature.h>
  92. #include <asm/irq.h>
  93. #include <asm/nvram.h>
  94. #include "awacs_defs.h"
  95. #include "dmasound.h"
  96. #include "tas3001c.h"
  97. #include "tas3004.h"
  98. #include "tas_common.h"
  99. #define DMASOUND_AWACS_REVISION 0
  100. #define DMASOUND_AWACS_EDITION 7
  101. #define AWACS_SNAPPER 110 /* fake revision # for snapper */
  102. #define AWACS_BURGUNDY 100 /* fake revision # for burgundy */
  103. #define AWACS_TUMBLER 90 /* fake revision # for tumbler */
  104. #define AWACS_DACA 80 /* fake revision # for daca (ibook) */
  105. #define AWACS_AWACS 2 /* holding revision for AWACS */
  106. #define AWACS_SCREAMER 3 /* holding revision for Screamer */
  107. /*
  108. * Interrupt numbers and addresses, & info obtained from the device tree.
  109. */
  110. static int awacs_irq, awacs_tx_irq, awacs_rx_irq;
  111. static volatile struct awacs_regs __iomem *awacs;
  112. static volatile u32 __iomem *i2s;
  113. static volatile struct dbdma_regs __iomem *awacs_txdma, *awacs_rxdma;
  114. static int awacs_rate_index;
  115. static int awacs_subframe;
  116. static struct device_node* awacs_node;
  117. static struct device_node* i2s_node;
  118. static struct resource awacs_rsrc[3];
  119. static char awacs_name[64];
  120. static int awacs_revision;
  121. static int awacs_sleeping;
  122. static DEFINE_MUTEX(dmasound_mutex);
  123. static int sound_device_id; /* exists after iMac revA */
  124. static int hw_can_byteswap = 1 ; /* most pmac sound h/w can */
  125. /* model info */
  126. /* To be replaced with better interaction with pmac_feature.c */
  127. static int is_pbook_3X00;
  128. static int is_pbook_g3;
  129. /* expansion info */
  130. static int has_perch;
  131. static int has_ziva;
  132. /* for earlier powerbooks which need fiddling with mac-io to enable
  133. * cd etc.
  134. */
  135. static unsigned char __iomem *latch_base;
  136. static unsigned char __iomem *macio_base;
  137. /*
  138. * Space for the DBDMA command blocks.
  139. */
  140. static void *awacs_tx_cmd_space;
  141. static volatile struct dbdma_cmd *awacs_tx_cmds;
  142. static int number_of_tx_cmd_buffers;
  143. static void *awacs_rx_cmd_space;
  144. static volatile struct dbdma_cmd *awacs_rx_cmds;
  145. static int number_of_rx_cmd_buffers;
  146. /*
  147. * Cached values of AWACS registers (we can't read them).
  148. * Except on the burgundy (and screamer). XXX
  149. */
  150. int awacs_reg[8];
  151. int awacs_reg1_save;
  152. /* tracking values for the mixer contents
  153. */
  154. static int spk_vol;
  155. static int line_vol;
  156. static int passthru_vol;
  157. static int ip_gain; /* mic preamp settings */
  158. static int rec_lev = 0x4545 ; /* default CD gain 69 % */
  159. static int mic_lev;
  160. static int cd_lev = 0x6363 ; /* 99 % */
  161. static int line_lev;
  162. static int hdp_connected;
  163. /*
  164. * Stuff for outputting a beep. The values range from -327 to +327
  165. * so we can multiply by an amplitude in the range 0..100 to get a
  166. * signed short value to put in the output buffer.
  167. */
  168. static short beep_wform[256] = {
  169. 0, 40, 79, 117, 153, 187, 218, 245,
  170. 269, 288, 304, 316, 323, 327, 327, 324,
  171. 318, 310, 299, 288, 275, 262, 249, 236,
  172. 224, 213, 204, 196, 190, 186, 183, 182,
  173. 182, 183, 186, 189, 192, 196, 200, 203,
  174. 206, 208, 209, 209, 209, 207, 204, 201,
  175. 197, 193, 188, 183, 179, 174, 170, 166,
  176. 163, 161, 160, 159, 159, 160, 161, 162,
  177. 164, 166, 168, 169, 171, 171, 171, 170,
  178. 169, 167, 163, 159, 155, 150, 144, 139,
  179. 133, 128, 122, 117, 113, 110, 107, 105,
  180. 103, 103, 103, 103, 104, 104, 105, 105,
  181. 105, 103, 101, 97, 92, 86, 78, 68,
  182. 58, 45, 32, 18, 3, -11, -26, -41,
  183. -55, -68, -79, -88, -95, -100, -102, -102,
  184. -99, -93, -85, -75, -62, -48, -33, -16,
  185. 0, 16, 33, 48, 62, 75, 85, 93,
  186. 99, 102, 102, 100, 95, 88, 79, 68,
  187. 55, 41, 26, 11, -3, -18, -32, -45,
  188. -58, -68, -78, -86, -92, -97, -101, -103,
  189. -105, -105, -105, -104, -104, -103, -103, -103,
  190. -103, -105, -107, -110, -113, -117, -122, -128,
  191. -133, -139, -144, -150, -155, -159, -163, -167,
  192. -169, -170, -171, -171, -171, -169, -168, -166,
  193. -164, -162, -161, -160, -159, -159, -160, -161,
  194. -163, -166, -170, -174, -179, -183, -188, -193,
  195. -197, -201, -204, -207, -209, -209, -209, -208,
  196. -206, -203, -200, -196, -192, -189, -186, -183,
  197. -182, -182, -183, -186, -190, -196, -204, -213,
  198. -224, -236, -249, -262, -275, -288, -299, -310,
  199. -318, -324, -327, -327, -323, -316, -304, -288,
  200. -269, -245, -218, -187, -153, -117, -79, -40,
  201. };
  202. /* beep support */
  203. #define BEEP_SRATE 22050 /* 22050 Hz sample rate */
  204. #define BEEP_BUFLEN 512
  205. #define BEEP_VOLUME 15 /* 0 - 100 */
  206. static int beep_vol = BEEP_VOLUME;
  207. static int beep_playing;
  208. static int awacs_beep_state;
  209. static short *beep_buf;
  210. static void *beep_dbdma_cmd_space;
  211. static volatile struct dbdma_cmd *beep_dbdma_cmd;
  212. /* Burgundy functions */
  213. static void awacs_burgundy_wcw(unsigned addr,unsigned newval);
  214. static unsigned awacs_burgundy_rcw(unsigned addr);
  215. static void awacs_burgundy_write_volume(unsigned address, int volume);
  216. static int awacs_burgundy_read_volume(unsigned address);
  217. static void awacs_burgundy_write_mvolume(unsigned address, int volume);
  218. static int awacs_burgundy_read_mvolume(unsigned address);
  219. /* we will allocate a single 'emergency' dbdma cmd block to use if the
  220. tx status comes up "DEAD". This happens on some PowerComputing Pmac
  221. clones, either owing to a bug in dbdma or some interaction between
  222. IDE and sound. However, this measure would deal with DEAD status if
  223. if appeared elsewhere.
  224. for the sake of memory efficiency we'll allocate this cmd as part of
  225. the beep cmd stuff.
  226. */
  227. static volatile struct dbdma_cmd *emergency_dbdma_cmd;
  228. #ifdef CONFIG_PM
  229. /*
  230. * Stuff for restoring after a sleep.
  231. */
  232. static int awacs_sleep_notify(struct pmu_sleep_notifier *self, int when);
  233. struct pmu_sleep_notifier awacs_sleep_notifier = {
  234. awacs_sleep_notify, SLEEP_LEVEL_SOUND,
  235. };
  236. #endif /* CONFIG_PM */
  237. /* for (soft) sample rate translations */
  238. int expand_bal; /* Balance factor for expanding (not volume!) */
  239. int expand_read_bal; /* Balance factor for expanding reads (not volume!) */
  240. /*** Low level stuff *********************************************************/
  241. static void *PMacAlloc(unsigned int size, gfp_t flags);
  242. static void PMacFree(void *ptr, unsigned int size);
  243. static int PMacIrqInit(void);
  244. #ifdef MODULE
  245. static void PMacIrqCleanup(void);
  246. #endif
  247. static void PMacSilence(void);
  248. static void PMacInit(void);
  249. static int PMacSetFormat(int format);
  250. static int PMacSetVolume(int volume);
  251. static void PMacPlay(void);
  252. static void PMacRecord(void);
  253. static irqreturn_t pmac_awacs_tx_intr(int irq, void *devid);
  254. static irqreturn_t pmac_awacs_rx_intr(int irq, void *devid);
  255. static irqreturn_t pmac_awacs_intr(int irq, void *devid);
  256. static void awacs_write(int val);
  257. static int awacs_get_volume(int reg, int lshift);
  258. static int awacs_volume_setter(int volume, int n, int mute, int lshift);
  259. /*** Mid level stuff **********************************************************/
  260. static int PMacMixerIoctl(u_int cmd, u_long arg);
  261. static int PMacWriteSqSetup(void);
  262. static int PMacReadSqSetup(void);
  263. static void PMacAbortRead(void);
  264. extern TRANS transAwacsNormal ;
  265. extern TRANS transAwacsExpand ;
  266. extern TRANS transAwacsNormalRead ;
  267. extern TRANS transAwacsExpandRead ;
  268. extern int daca_init(void);
  269. extern void daca_cleanup(void);
  270. extern int daca_set_volume(uint left_vol, uint right_vol);
  271. extern void daca_get_volume(uint * left_vol, uint *right_vol);
  272. extern int daca_enter_sleep(void);
  273. extern int daca_leave_sleep(void);
  274. #define TRY_LOCK() \
  275. if ((rc = mutex_lock_interruptible(&dmasound_mutex)) != 0) \
  276. return rc;
  277. #define LOCK() mutex_lock(&dmasound_mutex);
  278. #define UNLOCK() mutex_unlock(&dmasound_mutex);
  279. /* We use different versions that the ones provided in dmasound.h
  280. *
  281. * FIXME: Use different names ;)
  282. */
  283. #undef IOCTL_IN
  284. #undef IOCTL_OUT
  285. #define IOCTL_IN(arg, ret) \
  286. rc = get_user(ret, (int __user *)(arg)); \
  287. if (rc) break;
  288. #define IOCTL_OUT(arg, ret) \
  289. ioctl_return2((int __user *)(arg), ret)
  290. static inline int ioctl_return2(int __user *addr, int value)
  291. {
  292. return value < 0 ? value : put_user(value, addr);
  293. }
  294. /*** AE - TUMBLER / SNAPPER START ************************************************/
  295. int gpio_audio_reset, gpio_audio_reset_pol;
  296. int gpio_amp_mute, gpio_amp_mute_pol;
  297. int gpio_headphone_mute, gpio_headphone_mute_pol;
  298. int gpio_headphone_detect, gpio_headphone_detect_pol;
  299. int gpio_headphone_irq;
  300. int
  301. setup_audio_gpio(const char *name, const char* compatible, int *gpio_addr, int* gpio_pol)
  302. {
  303. struct device_node *np;
  304. const u32* pp;
  305. np = find_devices("gpio");
  306. if (!np)
  307. return -ENODEV;
  308. np = np->child;
  309. while(np != 0) {
  310. if (name) {
  311. const char *property =
  312. get_property(np,"audio-gpio",NULL);
  313. if (property != 0 && strcmp(property,name) == 0)
  314. break;
  315. } else if (compatible && device_is_compatible(np, compatible))
  316. break;
  317. np = np->sibling;
  318. }
  319. if (!np)
  320. return -ENODEV;
  321. pp = get_property(np, "AAPL,address", NULL);
  322. if (!pp)
  323. return -ENODEV;
  324. *gpio_addr = (*pp) & 0x0000ffff;
  325. pp = get_property(np, "audio-gpio-active-state", NULL);
  326. if (pp)
  327. *gpio_pol = *pp;
  328. else
  329. *gpio_pol = 1;
  330. return irq_of_parse_and_map(np, 0);
  331. }
  332. static inline void
  333. write_audio_gpio(int gpio_addr, int data)
  334. {
  335. if (!gpio_addr)
  336. return;
  337. pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, gpio_addr, data ? 0x05 : 0x04);
  338. }
  339. static inline int
  340. read_audio_gpio(int gpio_addr)
  341. {
  342. if (!gpio_addr)
  343. return 0;
  344. return ((pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, gpio_addr, 0) & 0x02) !=0);
  345. }
  346. /*
  347. * Headphone interrupt via GPIO (Tumbler, Snapper, DACA)
  348. */
  349. static irqreturn_t
  350. headphone_intr(int irq, void *devid)
  351. {
  352. unsigned long flags;
  353. spin_lock_irqsave(&dmasound.lock, flags);
  354. if (read_audio_gpio(gpio_headphone_detect) == gpio_headphone_detect_pol) {
  355. printk(KERN_INFO "Audio jack plugged, muting speakers.\n");
  356. write_audio_gpio(gpio_headphone_mute, !gpio_headphone_mute_pol);
  357. write_audio_gpio(gpio_amp_mute, gpio_amp_mute_pol);
  358. tas_output_device_change(sound_device_id,TAS_OUTPUT_HEADPHONES,0);
  359. } else {
  360. printk(KERN_INFO "Audio jack unplugged, enabling speakers.\n");
  361. write_audio_gpio(gpio_amp_mute, !gpio_amp_mute_pol);
  362. write_audio_gpio(gpio_headphone_mute, gpio_headphone_mute_pol);
  363. tas_output_device_change(sound_device_id,TAS_OUTPUT_INTERNAL_SPKR,0);
  364. }
  365. spin_unlock_irqrestore(&dmasound.lock, flags);
  366. return IRQ_HANDLED;
  367. }
  368. /* Initialize tumbler */
  369. static int
  370. tas_dmasound_init(void)
  371. {
  372. setup_audio_gpio(
  373. "audio-hw-reset",
  374. NULL,
  375. &gpio_audio_reset,
  376. &gpio_audio_reset_pol);
  377. setup_audio_gpio(
  378. "amp-mute",
  379. NULL,
  380. &gpio_amp_mute,
  381. &gpio_amp_mute_pol);
  382. setup_audio_gpio("headphone-mute",
  383. NULL,
  384. &gpio_headphone_mute,
  385. &gpio_headphone_mute_pol);
  386. gpio_headphone_irq = setup_audio_gpio(
  387. "headphone-detect",
  388. NULL,
  389. &gpio_headphone_detect,
  390. &gpio_headphone_detect_pol);
  391. /* Fix some broken OF entries in desktop machines */
  392. if (!gpio_headphone_irq)
  393. gpio_headphone_irq = setup_audio_gpio(
  394. NULL,
  395. "keywest-gpio15",
  396. &gpio_headphone_detect,
  397. &gpio_headphone_detect_pol);
  398. write_audio_gpio(gpio_audio_reset, gpio_audio_reset_pol);
  399. msleep(100);
  400. write_audio_gpio(gpio_audio_reset, !gpio_audio_reset_pol);
  401. msleep(100);
  402. if (gpio_headphone_irq) {
  403. if (request_irq(gpio_headphone_irq,headphone_intr,0,"Headphone detect",NULL) < 0) {
  404. printk(KERN_ERR "tumbler: Can't request headphone interrupt\n");
  405. gpio_headphone_irq = 0;
  406. } else {
  407. u8 val;
  408. /* Activate headphone status interrupts */
  409. val = pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, gpio_headphone_detect, 0);
  410. pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, gpio_headphone_detect, val | 0x80);
  411. /* Trigger it */
  412. headphone_intr(0, NULL);
  413. }
  414. }
  415. if (!gpio_headphone_irq) {
  416. /* Some machine enter this case ? */
  417. printk(KERN_WARNING "tumbler: Headphone detect IRQ not found, enabling all outputs !\n");
  418. write_audio_gpio(gpio_amp_mute, !gpio_amp_mute_pol);
  419. write_audio_gpio(gpio_headphone_mute, !gpio_headphone_mute_pol);
  420. }
  421. return 0;
  422. }
  423. static int
  424. tas_dmasound_cleanup(void)
  425. {
  426. if (gpio_headphone_irq)
  427. free_irq(gpio_headphone_irq, NULL);
  428. return 0;
  429. }
  430. /* We don't support 48k yet */
  431. static int tas_freqs[1] = { 44100 } ;
  432. static int tas_freqs_ok[1] = { 1 } ;
  433. /* don't know what to do really - just have to leave it where
  434. * OF left things
  435. */
  436. static int
  437. tas_set_frame_rate(void)
  438. {
  439. if (i2s) {
  440. out_le32(i2s + (I2S_REG_SERIAL_FORMAT >> 2), 0x41190000);
  441. out_le32(i2s + (I2S_REG_DATAWORD_SIZES >> 2), 0x02000200);
  442. }
  443. dmasound.hard.speed = 44100 ;
  444. awacs_rate_index = 0 ;
  445. return 44100 ;
  446. }
  447. static int
  448. tas_mixer_ioctl(u_int cmd, u_long arg)
  449. {
  450. int __user *argp = (int __user *)arg;
  451. int data;
  452. int rc;
  453. rc=tas_device_ioctl(cmd, arg);
  454. if (rc != -EINVAL) {
  455. return rc;
  456. }
  457. if ((cmd & ~0xff) == MIXER_WRITE(0) &&
  458. tas_supported_mixers() & (1<<(cmd & 0xff))) {
  459. rc = get_user(data, argp);
  460. if (rc<0) return rc;
  461. tas_set_mixer_level(cmd & 0xff, data);
  462. tas_get_mixer_level(cmd & 0xff, &data);
  463. return ioctl_return2(argp, data);
  464. }
  465. if ((cmd & ~0xff) == MIXER_READ(0) &&
  466. tas_supported_mixers() & (1<<(cmd & 0xff))) {
  467. tas_get_mixer_level(cmd & 0xff, &data);
  468. return ioctl_return2(argp, data);
  469. }
  470. switch(cmd) {
  471. case SOUND_MIXER_READ_DEVMASK:
  472. data = tas_supported_mixers() | SOUND_MASK_SPEAKER;
  473. rc = IOCTL_OUT(arg, data);
  474. break;
  475. case SOUND_MIXER_READ_STEREODEVS:
  476. data = tas_stereo_mixers();
  477. rc = IOCTL_OUT(arg, data);
  478. break;
  479. case SOUND_MIXER_READ_CAPS:
  480. rc = IOCTL_OUT(arg, 0);
  481. break;
  482. case SOUND_MIXER_READ_RECMASK:
  483. // XXX FIXME: find a way to check what is really available */
  484. data = SOUND_MASK_LINE | SOUND_MASK_MIC;
  485. rc = IOCTL_OUT(arg, data);
  486. break;
  487. case SOUND_MIXER_READ_RECSRC:
  488. if (awacs_reg[0] & MASK_MUX_AUDIN)
  489. data |= SOUND_MASK_LINE;
  490. if (awacs_reg[0] & MASK_MUX_MIC)
  491. data |= SOUND_MASK_MIC;
  492. rc = IOCTL_OUT(arg, data);
  493. break;
  494. case SOUND_MIXER_WRITE_RECSRC:
  495. IOCTL_IN(arg, data);
  496. data =0;
  497. rc = IOCTL_OUT(arg, data);
  498. break;
  499. case SOUND_MIXER_WRITE_SPEAKER: /* really bell volume */
  500. IOCTL_IN(arg, data);
  501. beep_vol = data & 0xff;
  502. /* fall through */
  503. case SOUND_MIXER_READ_SPEAKER:
  504. rc = IOCTL_OUT(arg, (beep_vol<<8) | beep_vol);
  505. break;
  506. case SOUND_MIXER_OUTMASK:
  507. case SOUND_MIXER_OUTSRC:
  508. default:
  509. rc = -EINVAL;
  510. }
  511. return rc;
  512. }
  513. static void __init
  514. tas_init_frame_rates(unsigned int *prop, unsigned int l)
  515. {
  516. int i ;
  517. if (prop) {
  518. for (i=0; i<1; i++)
  519. tas_freqs_ok[i] = 0;
  520. for (l /= sizeof(int); l > 0; --l) {
  521. unsigned int r = *prop++;
  522. /* Apple 'Fixed' format */
  523. if (r >= 0x10000)
  524. r >>= 16;
  525. for (i = 0; i < 1; ++i) {
  526. if (r == tas_freqs[i]) {
  527. tas_freqs_ok[i] = 1;
  528. break;
  529. }
  530. }
  531. }
  532. }
  533. /* else we assume that all the rates are available */
  534. }
  535. /*** AE - TUMBLER / SNAPPER END ************************************************/
  536. /*** Low level stuff *********************************************************/
  537. /*
  538. * PCI PowerMac, with AWACS, Screamer, Burgundy, DACA or Tumbler and DBDMA.
  539. */
  540. static void *PMacAlloc(unsigned int size, gfp_t flags)
  541. {
  542. return kmalloc(size, flags);
  543. }
  544. static void PMacFree(void *ptr, unsigned int size)
  545. {
  546. kfree(ptr);
  547. }
  548. static int __init PMacIrqInit(void)
  549. {
  550. if (awacs)
  551. if (request_irq(awacs_irq, pmac_awacs_intr, 0, "Built-in Sound misc", NULL))
  552. return 0;
  553. if (request_irq(awacs_tx_irq, pmac_awacs_tx_intr, 0, "Built-in Sound out", NULL)
  554. || request_irq(awacs_rx_irq, pmac_awacs_rx_intr, 0, "Built-in Sound in", NULL))
  555. return 0;
  556. return 1;
  557. }
  558. #ifdef MODULE
  559. static void PMacIrqCleanup(void)
  560. {
  561. /* turn off input & output dma */
  562. DBDMA_DO_STOP(awacs_txdma);
  563. DBDMA_DO_STOP(awacs_rxdma);
  564. if (awacs)
  565. /* disable interrupts from awacs interface */
  566. out_le32(&awacs->control, in_le32(&awacs->control) & 0xfff);
  567. /* Switch off the sound clock */
  568. pmac_call_feature(PMAC_FTR_SOUND_CHIP_ENABLE, awacs_node, 0, 0);
  569. /* Make sure proper bits are set on pismo & tipb */
  570. if ((machine_is_compatible("PowerBook3,1") ||
  571. machine_is_compatible("PowerBook3,2")) && awacs) {
  572. awacs_reg[1] |= MASK_PAROUT0 | MASK_PAROUT1;
  573. awacs_write(MASK_ADDR1 | awacs_reg[1]);
  574. msleep(200);
  575. }
  576. if (awacs)
  577. free_irq(awacs_irq, NULL);
  578. free_irq(awacs_tx_irq, NULL);
  579. free_irq(awacs_rx_irq, NULL);
  580. if (awacs)
  581. iounmap(awacs);
  582. if (i2s)
  583. iounmap(i2s);
  584. iounmap(awacs_txdma);
  585. iounmap(awacs_rxdma);
  586. release_mem_region(awacs_rsrc[0].start,
  587. awacs_rsrc[0].end - awacs_rsrc[0].start + 1);
  588. release_mem_region(awacs_rsrc[1].start,
  589. awacs_rsrc[1].end - awacs_rsrc[1].start + 1);
  590. release_mem_region(awacs_rsrc[2].start,
  591. awacs_rsrc[2].end - awacs_rsrc[2].start + 1);
  592. kfree(awacs_tx_cmd_space);
  593. kfree(awacs_rx_cmd_space);
  594. kfree(beep_dbdma_cmd_space);
  595. kfree(beep_buf);
  596. #ifdef CONFIG_PM
  597. pmu_unregister_sleep_notifier(&awacs_sleep_notifier);
  598. #endif
  599. }
  600. #endif /* MODULE */
  601. static void PMacSilence(void)
  602. {
  603. /* turn off output dma */
  604. DBDMA_DO_STOP(awacs_txdma);
  605. }
  606. /* don't know what to do really - just have to leave it where
  607. * OF left things
  608. */
  609. static int daca_set_frame_rate(void)
  610. {
  611. if (i2s) {
  612. out_le32(i2s + (I2S_REG_SERIAL_FORMAT >> 2), 0x41190000);
  613. out_le32(i2s + (I2S_REG_DATAWORD_SIZES >> 2), 0x02000200);
  614. }
  615. dmasound.hard.speed = 44100 ;
  616. awacs_rate_index = 0 ;
  617. return 44100 ;
  618. }
  619. static int awacs_freqs[8] = {
  620. 44100, 29400, 22050, 17640, 14700, 11025, 8820, 7350
  621. };
  622. static int awacs_freqs_ok[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
  623. static int
  624. awacs_set_frame_rate(int desired, int catch_r)
  625. {
  626. int tolerance, i = 8 ;
  627. /*
  628. * If we have a sample rate which is within catchRadius percent
  629. * of the requested value, we don't have to expand the samples.
  630. * Otherwise choose the next higher rate.
  631. * N.B.: burgundy awacs only works at 44100 Hz.
  632. */
  633. do {
  634. tolerance = catch_r * awacs_freqs[--i] / 100;
  635. if (awacs_freqs_ok[i]
  636. && dmasound.soft.speed <= awacs_freqs[i] + tolerance)
  637. break;
  638. } while (i > 0);
  639. dmasound.hard.speed = awacs_freqs[i];
  640. awacs_rate_index = i;
  641. out_le32(&awacs->control, MASK_IEPC | (i << 8) | 0x11 );
  642. awacs_reg[1] = (awacs_reg[1] & ~MASK_SAMPLERATE) | (i << 3);
  643. awacs_write(awacs_reg[1] | MASK_ADDR1);
  644. return dmasound.hard.speed;
  645. }
  646. static int
  647. burgundy_set_frame_rate(void)
  648. {
  649. awacs_rate_index = 0 ;
  650. awacs_reg[1] = (awacs_reg[1] & ~MASK_SAMPLERATE) ;
  651. /* XXX disable error interrupt on burgundy for now */
  652. out_le32(&awacs->control, MASK_IEPC | 0 | 0x11 | MASK_IEE);
  653. return 44100 ;
  654. }
  655. static int
  656. set_frame_rate(int desired, int catch_r)
  657. {
  658. switch (awacs_revision) {
  659. case AWACS_BURGUNDY:
  660. dmasound.hard.speed = burgundy_set_frame_rate();
  661. break ;
  662. case AWACS_TUMBLER:
  663. case AWACS_SNAPPER:
  664. dmasound.hard.speed = tas_set_frame_rate();
  665. break ;
  666. case AWACS_DACA:
  667. dmasound.hard.speed =
  668. daca_set_frame_rate();
  669. break ;
  670. default:
  671. dmasound.hard.speed = awacs_set_frame_rate(desired,
  672. catch_r);
  673. break ;
  674. }
  675. return dmasound.hard.speed ;
  676. }
  677. static void
  678. awacs_recalibrate(void)
  679. {
  680. /* Sorry for the horrible delays... I hope to get that improved
  681. * by making the whole PM process asynchronous in a future version
  682. */
  683. msleep(750);
  684. awacs_reg[1] |= MASK_CMUTE | MASK_AMUTE;
  685. awacs_write(awacs_reg[1] | MASK_RECALIBRATE | MASK_ADDR1);
  686. msleep(1000);
  687. awacs_write(awacs_reg[1] | MASK_ADDR1);
  688. }
  689. static void PMacInit(void)
  690. {
  691. int tolerance;
  692. switch (dmasound.soft.format) {
  693. case AFMT_S16_LE:
  694. case AFMT_U16_LE:
  695. if (hw_can_byteswap)
  696. dmasound.hard.format = AFMT_S16_LE;
  697. else
  698. dmasound.hard.format = AFMT_S16_BE;
  699. break;
  700. default:
  701. dmasound.hard.format = AFMT_S16_BE;
  702. break;
  703. }
  704. dmasound.hard.stereo = 1;
  705. dmasound.hard.size = 16;
  706. /* set dmasound.hard.speed - on the basis of what we want (soft)
  707. * and the tolerance we'll allow.
  708. */
  709. set_frame_rate(dmasound.soft.speed, catchRadius) ;
  710. tolerance = (catchRadius * dmasound.hard.speed) / 100;
  711. if (dmasound.soft.speed >= dmasound.hard.speed - tolerance) {
  712. dmasound.trans_write = &transAwacsNormal;
  713. dmasound.trans_read = &transAwacsNormalRead;
  714. } else {
  715. dmasound.trans_write = &transAwacsExpand;
  716. dmasound.trans_read = &transAwacsExpandRead;
  717. }
  718. if (awacs) {
  719. if (hw_can_byteswap && (dmasound.hard.format == AFMT_S16_LE))
  720. out_le32(&awacs->byteswap, BS_VAL);
  721. else
  722. out_le32(&awacs->byteswap, 0);
  723. }
  724. expand_bal = -dmasound.soft.speed;
  725. expand_read_bal = -dmasound.soft.speed;
  726. }
  727. static int PMacSetFormat(int format)
  728. {
  729. int size;
  730. int req_format = format;
  731. switch (format) {
  732. case AFMT_QUERY:
  733. return dmasound.soft.format;
  734. case AFMT_MU_LAW:
  735. case AFMT_A_LAW:
  736. case AFMT_U8:
  737. case AFMT_S8:
  738. size = 8;
  739. break;
  740. case AFMT_S16_LE:
  741. if(!hw_can_byteswap)
  742. format = AFMT_S16_BE;
  743. case AFMT_S16_BE:
  744. size = 16;
  745. break;
  746. case AFMT_U16_LE:
  747. if(!hw_can_byteswap)
  748. format = AFMT_U16_BE;
  749. case AFMT_U16_BE:
  750. size = 16;
  751. break;
  752. default: /* :-) */
  753. printk(KERN_ERR "dmasound: unknown format 0x%x, using AFMT_U8\n",
  754. format);
  755. size = 8;
  756. format = AFMT_U8;
  757. }
  758. if (req_format == format) {
  759. dmasound.soft.format = format;
  760. dmasound.soft.size = size;
  761. if (dmasound.minDev == SND_DEV_DSP) {
  762. dmasound.dsp.format = format;
  763. dmasound.dsp.size = size;
  764. }
  765. }
  766. return format;
  767. }
  768. #define AWACS_VOLUME_TO_MASK(x) (15 - ((((x) - 1) * 15) / 99))
  769. #define AWACS_MASK_TO_VOLUME(y) (100 - ((y) * 99 / 15))
  770. static int awacs_get_volume(int reg, int lshift)
  771. {
  772. int volume;
  773. volume = AWACS_MASK_TO_VOLUME((reg >> lshift) & 0xf);
  774. volume |= AWACS_MASK_TO_VOLUME(reg & 0xf) << 8;
  775. return volume;
  776. }
  777. static int awacs_volume_setter(int volume, int n, int mute, int lshift)
  778. {
  779. int r1, rn;
  780. if (mute && volume == 0) {
  781. r1 = awacs_reg[1] | mute;
  782. } else {
  783. r1 = awacs_reg[1] & ~mute;
  784. rn = awacs_reg[n] & ~(0xf | (0xf << lshift));
  785. rn |= ((AWACS_VOLUME_TO_MASK(volume & 0xff) & 0xf) << lshift);
  786. rn |= AWACS_VOLUME_TO_MASK((volume >> 8) & 0xff) & 0xf;
  787. awacs_reg[n] = rn;
  788. awacs_write((n << 12) | rn);
  789. volume = awacs_get_volume(rn, lshift);
  790. }
  791. if (r1 != awacs_reg[1]) {
  792. awacs_reg[1] = r1;
  793. awacs_write(r1 | MASK_ADDR1);
  794. }
  795. return volume;
  796. }
  797. static int PMacSetVolume(int volume)
  798. {
  799. printk(KERN_WARNING "Bogus call to PMacSetVolume !\n");
  800. return 0;
  801. }
  802. static void awacs_setup_for_beep(int speed)
  803. {
  804. out_le32(&awacs->control,
  805. (in_le32(&awacs->control) & ~0x1f00)
  806. | ((speed > 0 ? speed : awacs_rate_index) << 8));
  807. if (hw_can_byteswap && (dmasound.hard.format == AFMT_S16_LE) && speed == -1)
  808. out_le32(&awacs->byteswap, BS_VAL);
  809. else
  810. out_le32(&awacs->byteswap, 0);
  811. }
  812. /* CHECK: how much of this *really* needs IRQs masked? */
  813. static void __PMacPlay(void)
  814. {
  815. volatile struct dbdma_cmd *cp;
  816. int next_frg, count;
  817. count = 300 ; /* > two cycles at the lowest sample rate */
  818. /* what we want to send next */
  819. next_frg = (write_sq.front + write_sq.active) % write_sq.max_count;
  820. if (awacs_beep_state) {
  821. /* sound takes precedence over beeps */
  822. /* stop the dma channel */
  823. out_le32(&awacs_txdma->control, (RUN|PAUSE|FLUSH|WAKE) << 16);
  824. while ( (in_le32(&awacs_txdma->status) & RUN) && count--)
  825. udelay(1);
  826. if (awacs)
  827. awacs_setup_for_beep(-1);
  828. out_le32(&awacs_txdma->cmdptr,
  829. virt_to_bus(&(awacs_tx_cmds[next_frg])));
  830. beep_playing = 0;
  831. awacs_beep_state = 0;
  832. }
  833. /* this won't allow more than two frags to be in the output queue at
  834. once. (or one, if the max frags is 2 - because count can't exceed
  835. 2 in that case)
  836. */
  837. while (write_sq.active < 2 && write_sq.active < write_sq.count) {
  838. count = (write_sq.count == write_sq.active + 1) ?
  839. write_sq.rear_size:write_sq.block_size ;
  840. if (count < write_sq.block_size) {
  841. if (!write_sq.syncing) /* last block not yet filled,*/
  842. break; /* and we're not syncing or POST-ed */
  843. else {
  844. /* pretend the block is full to force a new
  845. block to be started on the next write */
  846. write_sq.rear_size = write_sq.block_size ;
  847. write_sq.syncing &= ~2 ; /* clear POST */
  848. }
  849. }
  850. cp = &awacs_tx_cmds[next_frg];
  851. st_le16(&cp->req_count, count);
  852. st_le16(&cp->xfer_status, 0);
  853. st_le16(&cp->command, OUTPUT_MORE + INTR_ALWAYS);
  854. /* put a STOP at the end of the queue - but only if we have
  855. space for it. This means that, if we under-run and we only
  856. have two fragments, we might re-play sound from an existing
  857. queued frag. I guess the solution to that is not to set two
  858. frags if you are likely to under-run...
  859. */
  860. if (write_sq.count < write_sq.max_count) {
  861. if (++next_frg >= write_sq.max_count)
  862. next_frg = 0 ; /* wrap */
  863. /* if we get here then we've underrun so we will stop*/
  864. st_le16(&awacs_tx_cmds[next_frg].command, DBDMA_STOP);
  865. }
  866. /* set the dbdma controller going, if it is not already */
  867. if (write_sq.active == 0)
  868. out_le32(&awacs_txdma->cmdptr, virt_to_bus(cp));
  869. (void)in_le32(&awacs_txdma->status);
  870. out_le32(&awacs_txdma->control, ((RUN|WAKE) << 16) + (RUN|WAKE));
  871. ++write_sq.active;
  872. }
  873. }
  874. static void PMacPlay(void)
  875. {
  876. LOCK();
  877. if (!awacs_sleeping) {
  878. unsigned long flags;
  879. spin_lock_irqsave(&dmasound.lock, flags);
  880. __PMacPlay();
  881. spin_unlock_irqrestore(&dmasound.lock, flags);
  882. }
  883. UNLOCK();
  884. }
  885. static void PMacRecord(void)
  886. {
  887. unsigned long flags;
  888. if (read_sq.active)
  889. return;
  890. spin_lock_irqsave(&dmasound.lock, flags);
  891. /* This is all we have to do......Just start it up.
  892. */
  893. out_le32(&awacs_rxdma->control, ((RUN|WAKE) << 16) + (RUN|WAKE));
  894. read_sq.active = 1;
  895. spin_unlock_irqrestore(&dmasound.lock, flags);
  896. }
  897. /* if the TX status comes up "DEAD" - reported on some Power Computing machines
  898. we need to re-start the dbdma - but from a different physical start address
  899. and with a different transfer length. It would get very messy to do this
  900. with the normal dbdma_cmd blocks - we would have to re-write the buffer start
  901. addresses each time. So, we will keep a single dbdma_cmd block which can be
  902. fiddled with.
  903. When DEAD status is first reported the content of the faulted dbdma block is
  904. copied into the emergency buffer and we note that the buffer is in use.
  905. we then bump the start physical address by the amount that was successfully
  906. output before it died.
  907. On any subsequent DEAD result we just do the bump-ups (we know that we are
  908. already using the emergency dbdma_cmd).
  909. CHECK: this just tries to "do it". It is possible that we should abandon
  910. xfers when the number of residual bytes gets below a certain value - I can
  911. see that this might cause a loop-forever if too small a transfer causes
  912. DEAD status. However this is a TODO for now - we'll see what gets reported.
  913. When we get a successful transfer result with the emergency buffer we just
  914. pretend that it completed using the original dmdma_cmd and carry on. The
  915. 'next_cmd' field will already point back to the original loop of blocks.
  916. */
  917. static irqreturn_t
  918. pmac_awacs_tx_intr(int irq, void *devid)
  919. {
  920. int i = write_sq.front;
  921. int stat;
  922. int i_nowrap = write_sq.front;
  923. volatile struct dbdma_cmd *cp;
  924. /* != 0 when we are dealing with a DEAD xfer */
  925. static int emergency_in_use;
  926. spin_lock(&dmasound.lock);
  927. while (write_sq.active > 0) { /* we expect to have done something*/
  928. if (emergency_in_use) /* we are dealing with DEAD xfer */
  929. cp = emergency_dbdma_cmd ;
  930. else
  931. cp = &awacs_tx_cmds[i];
  932. stat = ld_le16(&cp->xfer_status);
  933. if (stat & DEAD) {
  934. unsigned short req, res ;
  935. unsigned int phy ;
  936. #ifdef DEBUG_DMASOUND
  937. printk("dmasound_pmac: tx-irq: xfer died - patching it up...\n") ;
  938. #endif
  939. /* to clear DEAD status we must first clear RUN
  940. set it to quiescent to be on the safe side */
  941. (void)in_le32(&awacs_txdma->status);
  942. out_le32(&awacs_txdma->control,
  943. (RUN|PAUSE|FLUSH|WAKE) << 16);
  944. write_sq.died++ ;
  945. if (!emergency_in_use) { /* new problem */
  946. memcpy((void *)emergency_dbdma_cmd, (void *)cp,
  947. sizeof(struct dbdma_cmd));
  948. emergency_in_use = 1;
  949. cp = emergency_dbdma_cmd;
  950. }
  951. /* now bump the values to reflect the amount
  952. we haven't yet shifted */
  953. req = ld_le16(&cp->req_count);
  954. res = ld_le16(&cp->res_count);
  955. phy = ld_le32(&cp->phy_addr);
  956. phy += (req - res);
  957. st_le16(&cp->req_count, res);
  958. st_le16(&cp->res_count, 0);
  959. st_le16(&cp->xfer_status, 0);
  960. st_le32(&cp->phy_addr, phy);
  961. st_le32(&cp->cmd_dep, virt_to_bus(&awacs_tx_cmds[(i+1)%write_sq.max_count]));
  962. st_le16(&cp->command, OUTPUT_MORE | BR_ALWAYS | INTR_ALWAYS);
  963. /* point at our patched up command block */
  964. out_le32(&awacs_txdma->cmdptr, virt_to_bus(cp));
  965. /* we must re-start the controller */
  966. (void)in_le32(&awacs_txdma->status);
  967. /* should complete clearing the DEAD status */
  968. out_le32(&awacs_txdma->control,
  969. ((RUN|WAKE) << 16) + (RUN|WAKE));
  970. break; /* this block is still going */
  971. }
  972. if ((stat & ACTIVE) == 0)
  973. break; /* this frame is still going */
  974. if (emergency_in_use)
  975. emergency_in_use = 0 ; /* done that */
  976. --write_sq.count;
  977. --write_sq.active;
  978. i_nowrap++;
  979. if (++i >= write_sq.max_count)
  980. i = 0;
  981. }
  982. /* if we stopped and we were not sync-ing - then we under-ran */
  983. if( write_sq.syncing == 0 ){
  984. stat = in_le32(&awacs_txdma->status) ;
  985. /* we hit the dbdma_stop */
  986. if( (stat & ACTIVE) == 0 ) write_sq.xruns++ ;
  987. }
  988. /* if we used some data up then wake the writer to supply some more*/
  989. if (i_nowrap != write_sq.front)
  990. WAKE_UP(write_sq.action_queue);
  991. write_sq.front = i;
  992. /* but make sure we funnel what we've already got */\
  993. if (!awacs_sleeping)
  994. __PMacPlay();
  995. /* make the wake-on-empty conditional on syncing */
  996. if (!write_sq.active && (write_sq.syncing & 1))
  997. WAKE_UP(write_sq.sync_queue); /* any time we're empty */
  998. spin_unlock(&dmasound.lock);
  999. return IRQ_HANDLED;
  1000. }
  1001. static irqreturn_t
  1002. pmac_awacs_rx_intr(int irq, void *devid)
  1003. {
  1004. int stat ;
  1005. /* For some reason on my PowerBook G3, I get one interrupt
  1006. * when the interrupt vector is installed (like something is
  1007. * pending). This happens before the dbdma is initialized by
  1008. * us, so I just check the command pointer and if it is zero,
  1009. * just blow it off.
  1010. */
  1011. if (in_le32(&awacs_rxdma->cmdptr) == 0)
  1012. return IRQ_HANDLED;
  1013. /* We also want to blow 'em off when shutting down.
  1014. */
  1015. if (read_sq.active == 0)
  1016. return IRQ_HANDLED;
  1017. spin_lock(&dmasound.lock);
  1018. /* Check multiple buffers in case we were held off from
  1019. * interrupt processing for a long time. Geeze, I really hope
  1020. * this doesn't happen.
  1021. */
  1022. while ((stat=awacs_rx_cmds[read_sq.rear].xfer_status)) {
  1023. /* if we got a "DEAD" status then just log it for now.
  1024. and try to restart dma.
  1025. TODO: figure out how best to fix it up
  1026. */
  1027. if (stat & DEAD){
  1028. #ifdef DEBUG_DMASOUND
  1029. printk("dmasound_pmac: rx-irq: DIED - attempting resurection\n");
  1030. #endif
  1031. /* to clear DEAD status we must first clear RUN
  1032. set it to quiescent to be on the safe side */
  1033. (void)in_le32(&awacs_txdma->status);
  1034. out_le32(&awacs_txdma->control,
  1035. (RUN|PAUSE|FLUSH|WAKE) << 16);
  1036. awacs_rx_cmds[read_sq.rear].xfer_status = 0;
  1037. awacs_rx_cmds[read_sq.rear].res_count = 0;
  1038. read_sq.died++ ;
  1039. (void)in_le32(&awacs_txdma->status);
  1040. /* re-start the same block */
  1041. out_le32(&awacs_rxdma->cmdptr,
  1042. virt_to_bus(&awacs_rx_cmds[read_sq.rear]));
  1043. /* we must re-start the controller */
  1044. (void)in_le32(&awacs_rxdma->status);
  1045. /* should complete clearing the DEAD status */
  1046. out_le32(&awacs_rxdma->control,
  1047. ((RUN|WAKE) << 16) + (RUN|WAKE));
  1048. spin_unlock(&dmasound.lock);
  1049. return IRQ_HANDLED; /* try this block again */
  1050. }
  1051. /* Clear status and move on to next buffer.
  1052. */
  1053. awacs_rx_cmds[read_sq.rear].xfer_status = 0;
  1054. read_sq.rear++;
  1055. /* Wrap the buffer ring.
  1056. */
  1057. if (read_sq.rear >= read_sq.max_active)
  1058. read_sq.rear = 0;
  1059. /* If we have caught up to the front buffer, bump it.
  1060. * This will cause weird (but not fatal) results if the
  1061. * read loop is currently using this buffer. The user is
  1062. * behind in this case anyway, so weird things are going
  1063. * to happen.
  1064. */
  1065. if (read_sq.rear == read_sq.front) {
  1066. read_sq.front++;
  1067. read_sq.xruns++ ; /* we overan */
  1068. if (read_sq.front >= read_sq.max_active)
  1069. read_sq.front = 0;
  1070. }
  1071. }
  1072. WAKE_UP(read_sq.action_queue);
  1073. spin_unlock(&dmasound.lock);
  1074. return IRQ_HANDLED;
  1075. }
  1076. static irqreturn_t
  1077. pmac_awacs_intr(int irq, void *devid)
  1078. {
  1079. int ctrl;
  1080. int status;
  1081. int r1;
  1082. spin_lock(&dmasound.lock);
  1083. ctrl = in_le32(&awacs->control);
  1084. status = in_le32(&awacs->codec_stat);
  1085. if (ctrl & MASK_PORTCHG) {
  1086. /* tested on Screamer, should work on others too */
  1087. if (awacs_revision == AWACS_SCREAMER) {
  1088. if (((status & MASK_HDPCONN) >> 3) && (hdp_connected == 0)) {
  1089. hdp_connected = 1;
  1090. r1 = awacs_reg[1] | MASK_SPKMUTE;
  1091. awacs_reg[1] = r1;
  1092. awacs_write(r1 | MASK_ADDR_MUTE);
  1093. } else if (((status & MASK_HDPCONN) >> 3 == 0) && (hdp_connected == 1)) {
  1094. hdp_connected = 0;
  1095. r1 = awacs_reg[1] & ~MASK_SPKMUTE;
  1096. awacs_reg[1] = r1;
  1097. awacs_write(r1 | MASK_ADDR_MUTE);
  1098. }
  1099. }
  1100. }
  1101. if (ctrl & MASK_CNTLERR) {
  1102. int err = (in_le32(&awacs->codec_stat) & MASK_ERRCODE) >> 16;
  1103. /* CHECK: we just swallow burgundy errors at the moment..*/
  1104. if (err != 0 && awacs_revision != AWACS_BURGUNDY)
  1105. printk(KERN_ERR "dmasound_pmac: error %x\n", err);
  1106. }
  1107. /* Writing 1s to the CNTLERR and PORTCHG bits clears them... */
  1108. out_le32(&awacs->control, ctrl);
  1109. spin_unlock(&dmasound.lock);
  1110. return IRQ_HANDLED;
  1111. }
  1112. static void
  1113. awacs_write(int val)
  1114. {
  1115. int count = 300 ;
  1116. if (awacs_revision >= AWACS_DACA || !awacs)
  1117. return ;
  1118. while ((in_le32(&awacs->codec_ctrl) & MASK_NEWECMD) && count--)
  1119. udelay(1) ; /* timeout is > 2 samples at lowest rate */
  1120. out_le32(&awacs->codec_ctrl, val | (awacs_subframe << 22));
  1121. (void)in_le32(&awacs->byteswap);
  1122. }
  1123. /* this is called when the beep timer expires... it will be called even
  1124. if the beep has been overidden by other sound output.
  1125. */
  1126. static void awacs_nosound(unsigned long xx)
  1127. {
  1128. unsigned long flags;
  1129. int count = 600 ; /* > four samples at lowest rate */
  1130. spin_lock_irqsave(&dmasound.lock, flags);
  1131. if (beep_playing) {
  1132. st_le16(&beep_dbdma_cmd->command, DBDMA_STOP);
  1133. out_le32(&awacs_txdma->control, (RUN|PAUSE|FLUSH|WAKE) << 16);
  1134. while ((in_le32(&awacs_txdma->status) & RUN) && count--)
  1135. udelay(1);
  1136. if (awacs)
  1137. awacs_setup_for_beep(-1);
  1138. beep_playing = 0;
  1139. }
  1140. spin_unlock_irqrestore(&dmasound.lock, flags);
  1141. }
  1142. /*
  1143. * We generate the beep with a single dbdma command that loops a buffer
  1144. * forever - without generating interrupts.
  1145. *
  1146. * So, to stop it you have to stop dma output as per awacs_nosound.
  1147. */
  1148. static int awacs_beep_event(struct input_dev *dev, unsigned int type,
  1149. unsigned int code, int hz)
  1150. {
  1151. unsigned long flags;
  1152. int beep_speed = 0;
  1153. int srate;
  1154. int period, ncycles, nsamples;
  1155. int i, j, f;
  1156. short *p;
  1157. static int beep_hz_cache;
  1158. static int beep_nsamples_cache;
  1159. static int beep_volume_cache;
  1160. if (type != EV_SND)
  1161. return -1;
  1162. switch (code) {
  1163. case SND_BELL:
  1164. if (hz)
  1165. hz = 1000;
  1166. break;
  1167. case SND_TONE:
  1168. break;
  1169. default:
  1170. return -1;
  1171. }
  1172. if (beep_buf == NULL)
  1173. return -1;
  1174. /* quick-hack fix for DACA, Burgundy & Tumbler */
  1175. if (awacs_revision >= AWACS_DACA){
  1176. srate = 44100 ;
  1177. } else {
  1178. for (i = 0; i < 8 && awacs_freqs[i] >= BEEP_SRATE; ++i)
  1179. if (awacs_freqs_ok[i])
  1180. beep_speed = i;
  1181. srate = awacs_freqs[beep_speed];
  1182. }
  1183. if (hz <= srate / BEEP_BUFLEN || hz > srate / 2) {
  1184. /* cancel beep currently playing */
  1185. awacs_nosound(0);
  1186. return 0;
  1187. }
  1188. spin_lock_irqsave(&dmasound.lock, flags);
  1189. if (beep_playing || write_sq.active || beep_buf == NULL) {
  1190. spin_unlock_irqrestore(&dmasound.lock, flags);
  1191. return -1; /* too hard, sorry :-( */
  1192. }
  1193. beep_playing = 1;
  1194. st_le16(&beep_dbdma_cmd->command, OUTPUT_MORE + BR_ALWAYS);
  1195. spin_unlock_irqrestore(&dmasound.lock, flags);
  1196. if (hz == beep_hz_cache && beep_vol == beep_volume_cache) {
  1197. nsamples = beep_nsamples_cache;
  1198. } else {
  1199. period = srate * 256 / hz; /* fixed point */
  1200. ncycles = BEEP_BUFLEN * 256 / period;
  1201. nsamples = (period * ncycles) >> 8;
  1202. f = ncycles * 65536 / nsamples;
  1203. j = 0;
  1204. p = beep_buf;
  1205. for (i = 0; i < nsamples; ++i, p += 2) {
  1206. p[0] = p[1] = beep_wform[j >> 8] * beep_vol;
  1207. j = (j + f) & 0xffff;
  1208. }
  1209. beep_hz_cache = hz;
  1210. beep_volume_cache = beep_vol;
  1211. beep_nsamples_cache = nsamples;
  1212. }
  1213. st_le16(&beep_dbdma_cmd->req_count, nsamples*4);
  1214. st_le16(&beep_dbdma_cmd->xfer_status, 0);
  1215. st_le32(&beep_dbdma_cmd->cmd_dep, virt_to_bus(beep_dbdma_cmd));
  1216. st_le32(&beep_dbdma_cmd->phy_addr, virt_to_bus(beep_buf));
  1217. awacs_beep_state = 1;
  1218. spin_lock_irqsave(&dmasound.lock, flags);
  1219. if (beep_playing) { /* i.e. haven't been terminated already */
  1220. int count = 300 ;
  1221. out_le32(&awacs_txdma->control, (RUN|WAKE|FLUSH|PAUSE) << 16);
  1222. while ((in_le32(&awacs_txdma->status) & RUN) && count--)
  1223. udelay(1); /* timeout > 2 samples at lowest rate*/
  1224. if (awacs)
  1225. awacs_setup_for_beep(beep_speed);
  1226. out_le32(&awacs_txdma->cmdptr, virt_to_bus(beep_dbdma_cmd));
  1227. (void)in_le32(&awacs_txdma->status);
  1228. out_le32(&awacs_txdma->control, RUN | (RUN << 16));
  1229. }
  1230. spin_unlock_irqrestore(&dmasound.lock, flags);
  1231. return 0;
  1232. }
  1233. /* used in init and for wake-up */
  1234. static void
  1235. load_awacs(void)
  1236. {
  1237. awacs_write(awacs_reg[0] + MASK_ADDR0);
  1238. awacs_write(awacs_reg[1] + MASK_ADDR1);
  1239. awacs_write(awacs_reg[2] + MASK_ADDR2);
  1240. awacs_write(awacs_reg[4] + MASK_ADDR4);
  1241. if (awacs_revision == AWACS_SCREAMER) {
  1242. awacs_write(awacs_reg[5] + MASK_ADDR5);
  1243. msleep(100);
  1244. awacs_write(awacs_reg[6] + MASK_ADDR6);
  1245. msleep(2);
  1246. awacs_write(awacs_reg[1] + MASK_ADDR1);
  1247. awacs_write(awacs_reg[7] + MASK_ADDR7);
  1248. }
  1249. if (awacs) {
  1250. if (hw_can_byteswap && (dmasound.hard.format == AFMT_S16_LE))
  1251. out_le32(&awacs->byteswap, BS_VAL);
  1252. else
  1253. out_le32(&awacs->byteswap, 0);
  1254. }
  1255. }
  1256. #ifdef CONFIG_PM
  1257. /*
  1258. * Save state when going to sleep, restore it afterwards.
  1259. */
  1260. /* FIXME: sort out disabling/re-enabling of read stuff as well */
  1261. static int awacs_sleep_notify(struct pmu_sleep_notifier *self, int when)
  1262. {
  1263. unsigned long flags;
  1264. switch (when) {
  1265. case PBOOK_SLEEP_NOW:
  1266. LOCK();
  1267. awacs_sleeping = 1;
  1268. /* Tell the rest of the driver we are now going to sleep */
  1269. mb();
  1270. if (awacs_revision == AWACS_SCREAMER ||
  1271. awacs_revision == AWACS_AWACS) {
  1272. awacs_reg1_save = awacs_reg[1];
  1273. awacs_reg[1] |= MASK_AMUTE | MASK_CMUTE;
  1274. awacs_write(MASK_ADDR1 | awacs_reg[1]);
  1275. }
  1276. PMacSilence();
  1277. /* stop rx - if going - a bit of a daft user... but */
  1278. out_le32(&awacs_rxdma->control, (RUN|WAKE|FLUSH << 16));
  1279. /* deny interrupts */
  1280. if (awacs)
  1281. disable_irq(awacs_irq);
  1282. disable_irq(awacs_tx_irq);
  1283. disable_irq(awacs_rx_irq);
  1284. /* Chip specific sleep code */
  1285. switch (awacs_revision) {
  1286. case AWACS_TUMBLER:
  1287. case AWACS_SNAPPER:
  1288. write_audio_gpio(gpio_headphone_mute, gpio_headphone_mute_pol);
  1289. write_audio_gpio(gpio_amp_mute, gpio_amp_mute_pol);
  1290. tas_enter_sleep();
  1291. write_audio_gpio(gpio_audio_reset, gpio_audio_reset_pol);
  1292. break ;
  1293. case AWACS_DACA:
  1294. daca_enter_sleep();
  1295. break ;
  1296. case AWACS_BURGUNDY:
  1297. break ;
  1298. case AWACS_SCREAMER:
  1299. case AWACS_AWACS:
  1300. default:
  1301. out_le32(&awacs->control, 0x11) ;
  1302. break ;
  1303. }
  1304. /* Disable sound clock */
  1305. pmac_call_feature(PMAC_FTR_SOUND_CHIP_ENABLE, awacs_node, 0, 0);
  1306. /* According to Darwin, we do that after turning off the sound
  1307. * chip clock. All this will have to be cleaned up once we properly
  1308. * parse the OF sound-objects
  1309. */
  1310. if ((machine_is_compatible("PowerBook3,1") ||
  1311. machine_is_compatible("PowerBook3,2")) && awacs) {
  1312. awacs_reg[1] |= MASK_PAROUT0 | MASK_PAROUT1;
  1313. awacs_write(MASK_ADDR1 | awacs_reg[1]);
  1314. msleep(200);
  1315. }
  1316. break;
  1317. case PBOOK_WAKE:
  1318. /* Enable sound clock */
  1319. pmac_call_feature(PMAC_FTR_SOUND_CHIP_ENABLE, awacs_node, 0, 1);
  1320. if ((machine_is_compatible("PowerBook3,1") ||
  1321. machine_is_compatible("PowerBook3,2")) && awacs) {
  1322. msleep(100);
  1323. awacs_reg[1] &= ~(MASK_PAROUT0 | MASK_PAROUT1);
  1324. awacs_write(MASK_ADDR1 | awacs_reg[1]);
  1325. msleep(300);
  1326. } else
  1327. msleep(1000);
  1328. /* restore settings */
  1329. switch (awacs_revision) {
  1330. case AWACS_TUMBLER:
  1331. case AWACS_SNAPPER:
  1332. write_audio_gpio(gpio_headphone_mute, gpio_headphone_mute_pol);
  1333. write_audio_gpio(gpio_amp_mute, gpio_amp_mute_pol);
  1334. write_audio_gpio(gpio_audio_reset, gpio_audio_reset_pol);
  1335. msleep(100);
  1336. write_audio_gpio(gpio_audio_reset, !gpio_audio_reset_pol);
  1337. msleep(150);
  1338. tas_leave_sleep(); /* Stub for now */
  1339. headphone_intr(0, NULL);
  1340. break;
  1341. case AWACS_DACA:
  1342. msleep(10); /* Check this !!! */
  1343. daca_leave_sleep();
  1344. break ; /* dont know how yet */
  1345. case AWACS_BURGUNDY:
  1346. break ;
  1347. case AWACS_SCREAMER:
  1348. case AWACS_AWACS:
  1349. default:
  1350. load_awacs() ;
  1351. break ;
  1352. }
  1353. /* Recalibrate chip */
  1354. if (awacs_revision == AWACS_SCREAMER && awacs)
  1355. awacs_recalibrate();
  1356. /* Make sure dma is stopped */
  1357. PMacSilence();
  1358. if (awacs)
  1359. enable_irq(awacs_irq);
  1360. enable_irq(awacs_tx_irq);
  1361. enable_irq(awacs_rx_irq);
  1362. if (awacs) {
  1363. /* OK, allow ints back again */
  1364. out_le32(&awacs->control, MASK_IEPC
  1365. | (awacs_rate_index << 8) | 0x11
  1366. | (awacs_revision < AWACS_DACA ? MASK_IEE: 0));
  1367. }
  1368. if (macio_base && is_pbook_g3) {
  1369. /* FIXME: should restore the setup we had...*/
  1370. out_8(macio_base + 0x37, 3);
  1371. } else if (is_pbook_3X00) {
  1372. in_8(latch_base + 0x190);
  1373. }
  1374. /* Remove mute */
  1375. if (awacs_revision == AWACS_SCREAMER ||
  1376. awacs_revision == AWACS_AWACS) {
  1377. awacs_reg[1] = awacs_reg1_save;
  1378. awacs_write(MASK_ADDR1 | awacs_reg[1]);
  1379. }
  1380. awacs_sleeping = 0;
  1381. /* Resume pending sounds. */
  1382. /* we don't try to restart input... */
  1383. spin_lock_irqsave(&dmasound.lock, flags);
  1384. __PMacPlay();
  1385. spin_unlock_irqrestore(&dmasound.lock, flags);
  1386. UNLOCK();
  1387. }
  1388. return PBOOK_SLEEP_OK;
  1389. }
  1390. #endif /* CONFIG_PM */
  1391. /* All the burgundy functions: */
  1392. /* Waits for busy flag to clear */
  1393. static inline void
  1394. awacs_burgundy_busy_wait(void)
  1395. {
  1396. int count = 50; /* > 2 samples at 44k1 */
  1397. while ((in_le32(&awacs->codec_ctrl) & MASK_NEWECMD) && count--)
  1398. udelay(1) ;
  1399. }
  1400. static inline void
  1401. awacs_burgundy_extend_wait(void)
  1402. {
  1403. int count = 50 ; /* > 2 samples at 44k1 */
  1404. while ((!(in_le32(&awacs->codec_stat) & MASK_EXTEND)) && count--)
  1405. udelay(1) ;
  1406. count = 50;
  1407. while ((in_le32(&awacs->codec_stat) & MASK_EXTEND) && count--)
  1408. udelay(1);
  1409. }
  1410. static void
  1411. awacs_burgundy_wcw(unsigned addr, unsigned val)
  1412. {
  1413. out_le32(&awacs->codec_ctrl, addr + 0x200c00 + (val & 0xff));
  1414. awacs_burgundy_busy_wait();
  1415. out_le32(&awacs->codec_ctrl, addr + 0x200d00 +((val>>8) & 0xff));
  1416. awacs_burgundy_busy_wait();
  1417. out_le32(&awacs->codec_ctrl, addr + 0x200e00 +((val>>16) & 0xff));
  1418. awacs_burgundy_busy_wait();
  1419. out_le32(&awacs->codec_ctrl, addr + 0x200f00 +((val>>24) & 0xff));
  1420. awacs_burgundy_busy_wait();
  1421. }
  1422. static unsigned
  1423. awacs_burgundy_rcw(unsigned addr)
  1424. {
  1425. unsigned val = 0;
  1426. unsigned long flags;
  1427. /* should have timeouts here */
  1428. spin_lock_irqsave(&dmasound.lock, flags);
  1429. out_le32(&awacs->codec_ctrl, addr + 0x100000);
  1430. awacs_burgundy_busy_wait();
  1431. awacs_burgundy_extend_wait();
  1432. val += (in_le32(&awacs->codec_stat) >> 4) & 0xff;
  1433. out_le32(&awacs->codec_ctrl, addr + 0x100100);
  1434. awacs_burgundy_busy_wait();
  1435. awacs_burgundy_extend_wait();
  1436. val += ((in_le32(&awacs->codec_stat)>>4) & 0xff) <<8;
  1437. out_le32(&awacs->codec_ctrl, addr + 0x100200);
  1438. awacs_burgundy_busy_wait();
  1439. awacs_burgundy_extend_wait();
  1440. val += ((in_le32(&awacs->codec_stat)>>4) & 0xff) <<16;
  1441. out_le32(&awacs->codec_ctrl, addr + 0x100300);
  1442. awacs_burgundy_busy_wait();
  1443. awacs_burgundy_extend_wait();
  1444. val += ((in_le32(&awacs->codec_stat)>>4) & 0xff) <<24;
  1445. spin_unlock_irqrestore(&dmasound.lock, flags);
  1446. return val;
  1447. }
  1448. static void
  1449. awacs_burgundy_wcb(unsigned addr, unsigned val)
  1450. {
  1451. out_le32(&awacs->codec_ctrl, addr + 0x300000 + (val & 0xff));
  1452. awacs_burgundy_busy_wait();
  1453. }
  1454. static unsigned
  1455. awacs_burgundy_rcb(unsigned addr)
  1456. {
  1457. unsigned val = 0;
  1458. unsigned long flags;
  1459. /* should have timeouts here */
  1460. spin_lock_irqsave(&dmasound.lock, flags);
  1461. out_le32(&awacs->codec_ctrl, addr + 0x100000);
  1462. awacs_burgundy_busy_wait();
  1463. awacs_burgundy_extend_wait();
  1464. val += (in_le32(&awacs->codec_stat) >> 4) & 0xff;
  1465. spin_unlock_irqrestore(&dmasound.lock, flags);
  1466. return val;
  1467. }
  1468. static int
  1469. awacs_burgundy_check(void)
  1470. {
  1471. /* Checks to see the chip is alive and kicking */
  1472. int error = in_le32(&awacs->codec_ctrl) & MASK_ERRCODE;
  1473. return error == 0xf0000;
  1474. }
  1475. static int
  1476. awacs_burgundy_init(void)
  1477. {
  1478. if (awacs_burgundy_check()) {
  1479. printk(KERN_WARNING "dmasound_pmac: burgundy not working :-(\n");
  1480. return 1;
  1481. }
  1482. awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_OUTPUTENABLES,
  1483. DEF_BURGUNDY_OUTPUTENABLES);
  1484. awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  1485. DEF_BURGUNDY_MORE_OUTPUTENABLES);
  1486. awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_OUTPUTSELECTS,
  1487. DEF_BURGUNDY_OUTPUTSELECTS);
  1488. awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_INPSEL21,
  1489. DEF_BURGUNDY_INPSEL21);
  1490. awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_INPSEL3,
  1491. DEF_BURGUNDY_INPSEL3);
  1492. awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_GAINCD,
  1493. DEF_BURGUNDY_GAINCD);
  1494. awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_GAINLINE,
  1495. DEF_BURGUNDY_GAINLINE);
  1496. awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_GAINMIC,
  1497. DEF_BURGUNDY_GAINMIC);
  1498. awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_GAINMODEM,
  1499. DEF_BURGUNDY_GAINMODEM);
  1500. awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_ATTENSPEAKER,
  1501. DEF_BURGUNDY_ATTENSPEAKER);
  1502. awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_ATTENLINEOUT,
  1503. DEF_BURGUNDY_ATTENLINEOUT);
  1504. awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_ATTENHP,
  1505. DEF_BURGUNDY_ATTENHP);
  1506. awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_MASTER_VOLUME,
  1507. DEF_BURGUNDY_MASTER_VOLUME);
  1508. awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_VOLCD,
  1509. DEF_BURGUNDY_VOLCD);
  1510. awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_VOLLINE,
  1511. DEF_BURGUNDY_VOLLINE);
  1512. awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_VOLMIC,
  1513. DEF_BURGUNDY_VOLMIC);
  1514. return 0;
  1515. }
  1516. static void
  1517. awacs_burgundy_write_volume(unsigned address, int volume)
  1518. {
  1519. int hardvolume,lvolume,rvolume;
  1520. lvolume = (volume & 0xff) ? (volume & 0xff) + 155 : 0;
  1521. rvolume = ((volume >>8)&0xff) ? ((volume >> 8)&0xff ) + 155 : 0;
  1522. hardvolume = lvolume + (rvolume << 16);
  1523. awacs_burgundy_wcw(address, hardvolume);
  1524. }
  1525. static int
  1526. awacs_burgundy_read_volume(unsigned address)
  1527. {
  1528. int softvolume,wvolume;
  1529. wvolume = awacs_burgundy_rcw(address);
  1530. softvolume = (wvolume & 0xff) - 155;
  1531. softvolume += (((wvolume >> 16) & 0xff) - 155)<<8;
  1532. return softvolume > 0 ? softvolume : 0;
  1533. }
  1534. static int
  1535. awacs_burgundy_read_mvolume(unsigned address)
  1536. {
  1537. int lvolume,rvolume,wvolume;
  1538. wvolume = awacs_burgundy_rcw(address);
  1539. wvolume &= 0xffff;
  1540. rvolume = (wvolume & 0xff) - 155;
  1541. lvolume = ((wvolume & 0xff00)>>8) - 155;
  1542. return lvolume + (rvolume << 8);
  1543. }
  1544. static void
  1545. awacs_burgundy_write_mvolume(unsigned address, int volume)
  1546. {
  1547. int lvolume,rvolume,hardvolume;
  1548. lvolume = (volume &0xff) ? (volume & 0xff) + 155 :0;
  1549. rvolume = ((volume >>8) & 0xff) ? (volume >> 8) + 155 :0;
  1550. hardvolume = lvolume + (rvolume << 8);
  1551. hardvolume += (hardvolume << 16);
  1552. awacs_burgundy_wcw(address, hardvolume);
  1553. }
  1554. /* End burgundy functions */
  1555. /* Set up output volumes on machines with the 'perch/whisper' extension card.
  1556. * this has an SGS i2c chip (7433) which is accessed using the cuda.
  1557. *
  1558. * TODO: split this out and make use of the other parts of the SGS chip to
  1559. * do Bass, Treble etc.
  1560. */
  1561. static void
  1562. awacs_enable_amp(int spkr_vol)
  1563. {
  1564. #ifdef CONFIG_ADB_CUDA
  1565. struct adb_request req;
  1566. if (sys_ctrler != SYS_CTRLER_CUDA)
  1567. return;
  1568. /* turn on headphones */
  1569. cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC,
  1570. 0x8a, 4, 0);
  1571. while (!req.complete) cuda_poll();
  1572. cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC,
  1573. 0x8a, 6, 0);
  1574. while (!req.complete) cuda_poll();
  1575. /* turn on speaker */
  1576. cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC,
  1577. 0x8a, 3, (100 - (spkr_vol & 0xff)) * 32 / 100);
  1578. while (!req.complete) cuda_poll();
  1579. cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC,
  1580. 0x8a, 5, (100 - ((spkr_vol >> 8) & 0xff)) * 32 / 100);
  1581. while (!req.complete) cuda_poll();
  1582. cuda_request(&req, NULL, 5, CUDA_PACKET,
  1583. CUDA_GET_SET_IIC, 0x8a, 1, 0x29);
  1584. while (!req.complete) cuda_poll();
  1585. #endif /* CONFIG_ADB_CUDA */
  1586. }
  1587. /*** Mid level stuff *********************************************************/
  1588. /*
  1589. * /dev/mixer abstraction
  1590. */
  1591. static void do_line_lev(int data)
  1592. {
  1593. line_lev = data ;
  1594. awacs_reg[0] &= ~MASK_MUX_AUDIN;
  1595. if ((data & 0xff) >= 50)
  1596. awacs_reg[0] |= MASK_MUX_AUDIN;
  1597. awacs_write(MASK_ADDR0 | awacs_reg[0]);
  1598. }
  1599. static void do_ip_gain(int data)
  1600. {
  1601. ip_gain = data ;
  1602. data &= 0xff;
  1603. awacs_reg[0] &= ~MASK_GAINLINE;
  1604. if (awacs_revision == AWACS_SCREAMER) {
  1605. awacs_reg[6] &= ~MASK_MIC_BOOST ;
  1606. if (data >= 33) {
  1607. awacs_reg[0] |= MASK_GAINLINE;
  1608. if( data >= 66)
  1609. awacs_reg[6] |= MASK_MIC_BOOST ;
  1610. }
  1611. awacs_write(MASK_ADDR6 | awacs_reg[6]) ;
  1612. } else {
  1613. if (data >= 50)
  1614. awacs_reg[0] |= MASK_GAINLINE;
  1615. }
  1616. awacs_write(MASK_ADDR0 | awacs_reg[0]);
  1617. }
  1618. static void do_mic_lev(int data)
  1619. {
  1620. mic_lev = data ;
  1621. data &= 0xff;
  1622. awacs_reg[0] &= ~MASK_MUX_MIC;
  1623. if (data >= 50)
  1624. awacs_reg[0] |= MASK_MUX_MIC;
  1625. awacs_write(MASK_ADDR0 | awacs_reg[0]);
  1626. }
  1627. static void do_cd_lev(int data)
  1628. {
  1629. cd_lev = data ;
  1630. awacs_reg[0] &= ~MASK_MUX_CD;
  1631. if ((data & 0xff) >= 50)
  1632. awacs_reg[0] |= MASK_MUX_CD;
  1633. awacs_write(MASK_ADDR0 | awacs_reg[0]);
  1634. }
  1635. static void do_rec_lev(int data)
  1636. {
  1637. int left, right ;
  1638. rec_lev = data ;
  1639. /* need to fudge this to use the volume setter routine */
  1640. left = 100 - (data & 0xff) ; if( left < 0 ) left = 0 ;
  1641. right = 100 - ((data >> 8) & 0xff) ; if( right < 0 ) right = 0 ;
  1642. left |= (right << 8 );
  1643. left = awacs_volume_setter(left, 0, 0, 4);
  1644. }
  1645. static void do_passthru_vol(int data)
  1646. {
  1647. passthru_vol = data ;
  1648. awacs_reg[1] &= ~MASK_LOOPTHRU;
  1649. if (awacs_revision == AWACS_SCREAMER) {
  1650. if( data ) { /* switch it on for non-zero */
  1651. awacs_reg[1] |= MASK_LOOPTHRU;
  1652. awacs_write(MASK_ADDR1 | awacs_reg[1]);
  1653. }
  1654. data = awacs_volume_setter(data, 5, 0, 6) ;
  1655. } else {
  1656. if ((data & 0xff) >= 50)
  1657. awacs_reg[1] |= MASK_LOOPTHRU;
  1658. awacs_write(MASK_ADDR1 | awacs_reg[1]);
  1659. data = (awacs_reg[1] & MASK_LOOPTHRU)? 100: 0;
  1660. }
  1661. }
  1662. static int awacs_mixer_ioctl(u_int cmd, u_long arg)
  1663. {
  1664. int data;
  1665. int rc;
  1666. switch (cmd) {
  1667. case SOUND_MIXER_READ_CAPS:
  1668. /* say we will allow multiple inputs? prob. wrong
  1669. so I'm switching it to single */
  1670. return IOCTL_OUT(arg, 1);
  1671. case SOUND_MIXER_READ_DEVMASK:
  1672. data = SOUND_MASK_VOLUME | SOUND_MASK_SPEAKER
  1673. | SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD
  1674. | SOUND_MASK_IGAIN | SOUND_MASK_RECLEV
  1675. | SOUND_MASK_ALTPCM
  1676. | SOUND_MASK_MONITOR;
  1677. rc = IOCTL_OUT(arg, data);
  1678. break;
  1679. case SOUND_MIXER_READ_RECMASK:
  1680. data = SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD;
  1681. rc = IOCTL_OUT(arg, data);
  1682. break;
  1683. case SOUND_MIXER_READ_RECSRC:
  1684. data = 0;
  1685. if (awacs_reg[0] & MASK_MUX_AUDIN)
  1686. data |= SOUND_MASK_LINE;
  1687. if (awacs_reg[0] & MASK_MUX_MIC)
  1688. data |= SOUND_MASK_MIC;
  1689. if (awacs_reg[0] & MASK_MUX_CD)
  1690. data |= SOUND_MASK_CD;
  1691. rc = IOCTL_OUT(arg, data);
  1692. break;
  1693. case SOUND_MIXER_WRITE_RECSRC:
  1694. IOCTL_IN(arg, data);
  1695. data &= (SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD);
  1696. awacs_reg[0] &= ~(MASK_MUX_CD | MASK_MUX_MIC
  1697. | MASK_MUX_AUDIN);
  1698. if (data & SOUND_MASK_LINE)
  1699. awacs_reg[0] |= MASK_MUX_AUDIN;
  1700. if (data & SOUND_MASK_MIC)
  1701. awacs_reg[0] |= MASK_MUX_MIC;
  1702. if (data & SOUND_MASK_CD)
  1703. awacs_reg[0] |= MASK_MUX_CD;
  1704. awacs_write(awacs_reg[0] | MASK_ADDR0);
  1705. rc = IOCTL_OUT(arg, data);
  1706. break;
  1707. case SOUND_MIXER_READ_STEREODEVS:
  1708. data = SOUND_MASK_VOLUME | SOUND_MASK_SPEAKER| SOUND_MASK_RECLEV ;
  1709. if (awacs_revision == AWACS_SCREAMER)
  1710. data |= SOUND_MASK_MONITOR ;
  1711. rc = IOCTL_OUT(arg, data);
  1712. break;
  1713. case SOUND_MIXER_WRITE_VOLUME:
  1714. IOCTL_IN(arg, data);
  1715. line_vol = data ;
  1716. awacs_volume_setter(data, 2, 0, 6);
  1717. /* fall through */
  1718. case SOUND_MIXER_READ_VOLUME:
  1719. rc = IOCTL_OUT(arg, line_vol);
  1720. break;
  1721. case SOUND_MIXER_WRITE_SPEAKER:
  1722. IOCTL_IN(arg, data);
  1723. spk_vol = data ;
  1724. if (has_perch)
  1725. awacs_enable_amp(data);
  1726. else
  1727. (void)awacs_volume_setter(data, 4, MASK_CMUTE, 6);
  1728. /* fall though */
  1729. case SOUND_MIXER_READ_SPEAKER:
  1730. rc = IOCTL_OUT(arg, spk_vol);
  1731. break;
  1732. case SOUND_MIXER_WRITE_ALTPCM: /* really bell volume */
  1733. IOCTL_IN(arg, data);
  1734. beep_vol = data & 0xff;
  1735. /* fall through */
  1736. case SOUND_MIXER_READ_ALTPCM:
  1737. rc = IOCTL_OUT(arg, beep_vol);
  1738. break;
  1739. case SOUND_MIXER_WRITE_LINE:
  1740. IOCTL_IN(arg, data);
  1741. do_line_lev(data) ;
  1742. /* fall through */
  1743. case SOUND_MIXER_READ_LINE:
  1744. rc = IOCTL_OUT(arg, line_lev);
  1745. break;
  1746. case SOUND_MIXER_WRITE_IGAIN:
  1747. IOCTL_IN(arg, data);
  1748. do_ip_gain(data) ;
  1749. /* fall through */
  1750. case SOUND_MIXER_READ_IGAIN:
  1751. rc = IOCTL_OUT(arg, ip_gain);
  1752. break;
  1753. case SOUND_MIXER_WRITE_MIC:
  1754. IOCTL_IN(arg, data);
  1755. do_mic_lev(data);
  1756. /* fall through */
  1757. case SOUND_MIXER_READ_MIC:
  1758. rc = IOCTL_OUT(arg, mic_lev);
  1759. break;
  1760. case SOUND_MIXER_WRITE_CD:
  1761. IOCTL_IN(arg, data);
  1762. do_cd_lev(data);
  1763. /* fall through */
  1764. case SOUND_MIXER_READ_CD:
  1765. rc = IOCTL_OUT(arg, cd_lev);
  1766. break;
  1767. case SOUND_MIXER_WRITE_RECLEV:
  1768. IOCTL_IN(arg, data);
  1769. do_rec_lev(data) ;
  1770. /* fall through */
  1771. case SOUND_MIXER_READ_RECLEV:
  1772. rc = IOCTL_OUT(arg, rec_lev);
  1773. break;
  1774. case MIXER_WRITE(SOUND_MIXER_MONITOR):
  1775. IOCTL_IN(arg, data);
  1776. do_passthru_vol(data) ;
  1777. /* fall through */
  1778. case MIXER_READ(SOUND_MIXER_MONITOR):
  1779. rc = IOCTL_OUT(arg, passthru_vol);
  1780. break;
  1781. default:
  1782. rc = -EINVAL;
  1783. }
  1784. return rc;
  1785. }
  1786. static void awacs_mixer_init(void)
  1787. {
  1788. awacs_volume_setter(line_vol, 2, 0, 6);
  1789. if (has_perch)
  1790. awacs_enable_amp(spk_vol);
  1791. else
  1792. (void)awacs_volume_setter(spk_vol, 4, MASK_CMUTE, 6);
  1793. do_line_lev(line_lev) ;
  1794. do_ip_gain(ip_gain) ;
  1795. do_mic_lev(mic_lev) ;
  1796. do_cd_lev(cd_lev) ;
  1797. do_rec_lev(rec_lev) ;
  1798. do_passthru_vol(passthru_vol) ;
  1799. }
  1800. static int burgundy_mixer_ioctl(u_int cmd, u_long arg)
  1801. {
  1802. int data;
  1803. int rc;
  1804. /* We are, we are, we are... Burgundy or better */
  1805. switch(cmd) {
  1806. case SOUND_MIXER_READ_DEVMASK:
  1807. data = SOUND_MASK_VOLUME | SOUND_MASK_CD |
  1808. SOUND_MASK_LINE | SOUND_MASK_MIC |
  1809. SOUND_MASK_SPEAKER | SOUND_MASK_ALTPCM;
  1810. rc = IOCTL_OUT(arg, data);
  1811. break;
  1812. case SOUND_MIXER_READ_RECMASK:
  1813. data = SOUND_MASK_LINE | SOUND_MASK_MIC
  1814. | SOUND_MASK_CD;
  1815. rc = IOCTL_OUT(arg, data);
  1816. break;
  1817. case SOUND_MIXER_READ_RECSRC:
  1818. data = 0;
  1819. if (awacs_reg[0] & MASK_MUX_AUDIN)
  1820. data |= SOUND_MASK_LINE;
  1821. if (awacs_reg[0] & MASK_MUX_MIC)
  1822. data |= SOUND_MASK_MIC;
  1823. if (awacs_reg[0] & MASK_MUX_CD)
  1824. data |= SOUND_MASK_CD;
  1825. rc = IOCTL_OUT(arg, data);
  1826. break;
  1827. case SOUND_MIXER_WRITE_RECSRC:
  1828. IOCTL_IN(arg, data);
  1829. data &= (SOUND_MASK_LINE
  1830. | SOUND_MASK_MIC | SOUND_MASK_CD);
  1831. awacs_reg[0] &= ~(MASK_MUX_CD | MASK_MUX_MIC
  1832. | MASK_MUX_AUDIN);
  1833. if (data & SOUND_MASK_LINE)
  1834. awacs_reg[0] |= MASK_MUX_AUDIN;
  1835. if (data & SOUND_MASK_MIC)
  1836. awacs_reg[0] |= MASK_MUX_MIC;
  1837. if (data & SOUND_MASK_CD)
  1838. awacs_reg[0] |= MASK_MUX_CD;
  1839. awacs_write(awacs_reg[0] | MASK_ADDR0);
  1840. rc = IOCTL_OUT(arg, data);
  1841. break;
  1842. case SOUND_MIXER_READ_STEREODEVS:
  1843. data = SOUND_MASK_VOLUME | SOUND_MASK_SPEAKER
  1844. | SOUND_MASK_RECLEV | SOUND_MASK_CD
  1845. | SOUND_MASK_LINE;
  1846. rc = IOCTL_OUT(arg, data);
  1847. break;
  1848. case SOUND_MIXER_READ_CAPS:
  1849. rc = IOCTL_OUT(arg, 0);
  1850. break;
  1851. case SOUND_MIXER_WRITE_VOLUME:
  1852. IOCTL_IN(arg, data);
  1853. awacs_burgundy_write_mvolume(MASK_ADDR_BURGUNDY_MASTER_VOLUME, data);
  1854. /* Fall through */
  1855. case SOUND_MIXER_READ_VOLUME:
  1856. rc = IOCTL_OUT(arg, awacs_burgundy_read_mvolume(MASK_ADDR_BURGUNDY_MASTER_VOLUME));
  1857. break;
  1858. case SOUND_MIXER_WRITE_SPEAKER:
  1859. IOCTL_IN(arg, data);
  1860. if (!(data & 0xff)) {
  1861. /* Mute the left speaker */
  1862. awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  1863. awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES) & ~0x2);
  1864. } else {
  1865. /* Unmute the left speaker */
  1866. awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  1867. awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES) | 0x2);
  1868. }
  1869. if (!(data & 0xff00)) {
  1870. /* Mute the right speaker */
  1871. awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  1872. awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES) & ~0x4);
  1873. } else {
  1874. /* Unmute the right speaker */
  1875. awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  1876. awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES) | 0x4);
  1877. }
  1878. data = (((data&0xff)*16)/100 > 0xf ? 0xf :
  1879. (((data&0xff)*16)/100)) +
  1880. ((((data>>8)*16)/100 > 0xf ? 0xf :
  1881. ((((data>>8)*16)/100)))<<4);
  1882. awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_ATTENSPEAKER, ~data);
  1883. /* Fall through */
  1884. case SOUND_MIXER_READ_SPEAKER:
  1885. data = awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_ATTENSPEAKER);
  1886. data = (((data & 0xf)*100)/16) + ((((data>>4)*100)/16)<<8);
  1887. rc = IOCTL_OUT(arg, (~data) & 0x0000ffff);
  1888. break;
  1889. case SOUND_MIXER_WRITE_ALTPCM: /* really bell volume */
  1890. IOCTL_IN(arg, data);
  1891. beep_vol = data & 0xff;
  1892. /* fall through */
  1893. case SOUND_MIXER_READ_ALTPCM:
  1894. rc = IOCTL_OUT(arg, beep_vol);
  1895. break;
  1896. case SOUND_MIXER_WRITE_LINE:
  1897. IOCTL_IN(arg, data);
  1898. awacs_burgundy_write_volume(MASK_ADDR_BURGUNDY_VOLLINE, data);
  1899. /* fall through */
  1900. case SOUND_MIXER_READ_LINE:
  1901. data = awacs_burgundy_read_volume(MASK_ADDR_BURGUNDY_VOLLINE);
  1902. rc = IOCTL_OUT(arg, data);
  1903. break;
  1904. case SOUND_MIXER_WRITE_MIC:
  1905. IOCTL_IN(arg, data);
  1906. /* Mic is mono device */
  1907. data = (data << 8) + (data << 24);
  1908. awacs_burgundy_write_volume(MASK_ADDR_BURGUNDY_VOLMIC, data);
  1909. /* fall through */
  1910. case SOUND_MIXER_READ_MIC:
  1911. data = awacs_burgundy_read_volume(MASK_ADDR_BURGUNDY_VOLMIC);
  1912. data <<= 24;
  1913. rc = IOCTL_OUT(arg, data);
  1914. break;
  1915. case SOUND_MIXER_WRITE_CD:
  1916. IOCTL_IN(arg, data);
  1917. awacs_burgundy_write_volume(MASK_ADDR_BURGUNDY_VOLCD, data);
  1918. /* fall through */
  1919. case SOUND_MIXER_READ_CD:
  1920. data = awacs_burgundy_read_volume(MASK_ADDR_BURGUNDY_VOLCD);
  1921. rc = IOCTL_OUT(arg, data);
  1922. break;
  1923. case SOUND_MIXER_WRITE_RECLEV:
  1924. IOCTL_IN(arg, data);
  1925. data = awacs_volume_setter(data, 0, 0, 4);
  1926. rc = IOCTL_OUT(arg, data);
  1927. break;
  1928. case SOUND_MIXER_READ_RECLEV:
  1929. data = awacs_get_volume(awacs_reg[0], 4);
  1930. rc = IOCTL_OUT(arg, data);
  1931. break;
  1932. case SOUND_MIXER_OUTMASK:
  1933. case SOUND_MIXER_OUTSRC:
  1934. default:
  1935. rc = -EINVAL;
  1936. }
  1937. return rc;
  1938. }
  1939. static int daca_mixer_ioctl(u_int cmd, u_long arg)
  1940. {
  1941. int data;
  1942. int rc;
  1943. /* And the DACA's no genius either! */
  1944. switch(cmd) {
  1945. case SOUND_MIXER_READ_DEVMASK:
  1946. data = SOUND_MASK_VOLUME;
  1947. rc = IOCTL_OUT(arg, data);
  1948. break;
  1949. case SOUND_MIXER_READ_RECMASK:
  1950. data = 0;
  1951. rc = IOCTL_OUT(arg, data);
  1952. break;
  1953. case SOUND_MIXER_READ_RECSRC:
  1954. data = 0;
  1955. rc = IOCTL_OUT(arg, data);
  1956. break;
  1957. case SOUND_MIXER_WRITE_RECSRC:
  1958. IOCTL_IN(arg, data);
  1959. data =0;
  1960. rc = IOCTL_OUT(arg, data);
  1961. break;
  1962. case SOUND_MIXER_READ_STEREODEVS:
  1963. data = SOUND_MASK_VOLUME;
  1964. rc = IOCTL_OUT(arg, data);
  1965. break;
  1966. case SOUND_MIXER_READ_CAPS:
  1967. rc = IOCTL_OUT(arg, 0);
  1968. break;
  1969. case SOUND_MIXER_WRITE_VOLUME:
  1970. IOCTL_IN(arg, data);
  1971. daca_set_volume(data, data);
  1972. /* Fall through */
  1973. case SOUND_MIXER_READ_VOLUME:
  1974. daca_get_volume(& data, &data);
  1975. rc = IOCTL_OUT(arg, data);
  1976. break;
  1977. case SOUND_MIXER_OUTMASK:
  1978. case SOUND_MIXER_OUTSRC:
  1979. default:
  1980. rc = -EINVAL;
  1981. }
  1982. return rc;
  1983. }
  1984. static int PMacMixerIoctl(u_int cmd, u_long arg)
  1985. {
  1986. int rc;
  1987. /* Different IOCTLS for burgundy and, eventually, DACA & Tumbler */
  1988. TRY_LOCK();
  1989. switch (awacs_revision){
  1990. case AWACS_BURGUNDY:
  1991. rc = burgundy_mixer_ioctl(cmd, arg);
  1992. break ;
  1993. case AWACS_DACA:
  1994. rc = daca_mixer_ioctl(cmd, arg);
  1995. break;
  1996. case AWACS_TUMBLER:
  1997. case AWACS_SNAPPER:
  1998. rc = tas_mixer_ioctl(cmd, arg);
  1999. break ;
  2000. default: /* ;-)) */
  2001. rc = awacs_mixer_ioctl(cmd, arg);
  2002. }
  2003. UNLOCK();
  2004. return rc;
  2005. }
  2006. static void PMacMixerInit(void)
  2007. {
  2008. switch (awacs_revision) {
  2009. case AWACS_TUMBLER:
  2010. printk("AE-Init tumbler mixer\n");
  2011. break ;
  2012. case AWACS_SNAPPER:
  2013. printk("AE-Init snapper mixer\n");
  2014. break ;
  2015. case AWACS_DACA:
  2016. case AWACS_BURGUNDY:
  2017. break ; /* don't know yet */
  2018. case AWACS_AWACS:
  2019. case AWACS_SCREAMER:
  2020. default:
  2021. awacs_mixer_init() ;
  2022. break ;
  2023. }
  2024. }
  2025. /* Write/Read sq setup functions:
  2026. Check to see if we have enough (or any) dbdma cmd buffers for the
  2027. user's fragment settings. If not, allocate some. If this fails we will
  2028. point at the beep buffer - as an emergency provision - to stop dma tromping
  2029. on some random bit of memory (if someone lets it go anyway).
  2030. The command buffers are then set up to point to the fragment buffers
  2031. (allocated elsewhere). We need n+1 commands the last of which holds
  2032. a NOP + loop to start.
  2033. */
  2034. static int PMacWriteSqSetup(void)
  2035. {
  2036. int i, count = 600 ;
  2037. volatile struct dbdma_cmd *cp;
  2038. LOCK();
  2039. /* stop the controller from doing any output - if it isn't already.
  2040. it _should_ be before this is called anyway */
  2041. out_le32(&awacs_txdma->control, (RUN|PAUSE|FLUSH|WAKE) << 16);
  2042. while ((in_le32(&awacs_txdma->status) & RUN) && count--)
  2043. udelay(1);
  2044. #ifdef DEBUG_DMASOUND
  2045. if (count <= 0)
  2046. printk("dmasound_pmac: write sq setup: timeout waiting for dma to stop\n");
  2047. #endif
  2048. if ((write_sq.max_count + 1) > number_of_tx_cmd_buffers) {
  2049. kfree(awacs_tx_cmd_space);
  2050. number_of_tx_cmd_buffers = 0;
  2051. /* we need nbufs + 1 (for the loop) and we should request + 1
  2052. again because the DBDMA_ALIGN might pull the start up by up
  2053. to sizeof(struct dbdma_cmd) - 4.
  2054. */
  2055. awacs_tx_cmd_space = kmalloc
  2056. ((write_sq.max_count + 1 + 1) * sizeof(struct dbdma_cmd),
  2057. GFP_KERNEL);
  2058. if (awacs_tx_cmd_space == NULL) {
  2059. /* don't leave it dangling - nasty but better than a
  2060. random address */
  2061. out_le32(&awacs_txdma->cmdptr, virt_to_bus(beep_dbdma_cmd));
  2062. printk(KERN_ERR
  2063. "dmasound_pmac: can't allocate dbdma cmd buffers"
  2064. ", driver disabled\n");
  2065. UNLOCK();
  2066. return -ENOMEM;
  2067. }
  2068. awacs_tx_cmds = (volatile struct dbdma_cmd *)
  2069. DBDMA_ALIGN(awacs_tx_cmd_space);
  2070. number_of_tx_cmd_buffers = write_sq.max_count + 1;
  2071. }
  2072. cp = awacs_tx_cmds;
  2073. memset((void *)cp, 0, (write_sq.max_count+1) * sizeof(struct dbdma_cmd));
  2074. for (i = 0; i < write_sq.max_count; ++i, ++cp) {
  2075. st_le32(&cp->phy_addr, virt_to_bus(write_sq.buffers[i]));
  2076. }
  2077. st_le16(&cp->command, DBDMA_NOP + BR_ALWAYS);
  2078. st_le32(&cp->cmd_dep, virt_to_bus(awacs_tx_cmds));
  2079. /* point the controller at the command stack - ready to go */
  2080. out_le32(&awacs_txdma->cmdptr, virt_to_bus(awacs_tx_cmds));
  2081. UNLOCK();
  2082. return 0;
  2083. }
  2084. static int PMacReadSqSetup(void)
  2085. {
  2086. int i, count = 600;
  2087. volatile struct dbdma_cmd *cp;
  2088. LOCK();
  2089. /* stop the controller from doing any input - if it isn't already.
  2090. it _should_ be before this is called anyway */
  2091. out_le32(&awacs_rxdma->control, (RUN|PAUSE|FLUSH|WAKE) << 16);
  2092. while ((in_le32(&awacs_rxdma->status) & RUN) && count--)
  2093. udelay(1);
  2094. #ifdef DEBUG_DMASOUND
  2095. if (count <= 0)
  2096. printk("dmasound_pmac: read sq setup: timeout waiting for dma to stop\n");
  2097. #endif
  2098. if ((read_sq.max_count+1) > number_of_rx_cmd_buffers ) {
  2099. kfree(awacs_rx_cmd_space);
  2100. number_of_rx_cmd_buffers = 0;
  2101. /* we need nbufs + 1 (for the loop) and we should request + 1 again
  2102. because the DBDMA_ALIGN might pull the start up by up to
  2103. sizeof(struct dbdma_cmd) - 4 (assuming kmalloc aligns 32 bits).
  2104. */
  2105. awacs_rx_cmd_space = kmalloc
  2106. ((read_sq.max_count + 1 + 1) * sizeof(struct dbdma_cmd),
  2107. GFP_KERNEL);
  2108. if (awacs_rx_cmd_space == NULL) {
  2109. /* don't leave it dangling - nasty but better than a
  2110. random address */
  2111. out_le32(&awacs_rxdma->cmdptr, virt_to_bus(beep_dbdma_cmd));
  2112. printk(KERN_ERR
  2113. "dmasound_pmac: can't allocate dbdma cmd buffers"
  2114. ", driver disabled\n");
  2115. UNLOCK();
  2116. return -ENOMEM;
  2117. }
  2118. awacs_rx_cmds = (volatile struct dbdma_cmd *)
  2119. DBDMA_ALIGN(awacs_rx_cmd_space);
  2120. number_of_rx_cmd_buffers = read_sq.max_count + 1 ;
  2121. }
  2122. cp = awacs_rx_cmds;
  2123. memset((void *)cp, 0, (read_sq.max_count+1) * sizeof(struct dbdma_cmd));
  2124. /* Set dma buffers up in a loop */
  2125. for (i = 0; i < read_sq.max_count; i++,cp++) {
  2126. st_le32(&cp->phy_addr, virt_to_bus(read_sq.buffers[i]));
  2127. st_le16(&cp->command, INPUT_MORE + INTR_ALWAYS);
  2128. st_le16(&cp->req_count, read_sq.block_size);
  2129. st_le16(&cp->xfer_status, 0);
  2130. }
  2131. /* The next two lines make the thing loop around.
  2132. */
  2133. st_le16(&cp->command, DBDMA_NOP + BR_ALWAYS);
  2134. st_le32(&cp->cmd_dep, virt_to_bus(awacs_rx_cmds));
  2135. /* point the controller at the command stack - ready to go */
  2136. out_le32(&awacs_rxdma->cmdptr, virt_to_bus(awacs_rx_cmds));
  2137. UNLOCK();
  2138. return 0;
  2139. }
  2140. /* TODO: this needs work to guarantee that when it returns DMA has stopped
  2141. but in a more elegant way than is done here....
  2142. */
  2143. static void PMacAbortRead(void)
  2144. {
  2145. int i;
  2146. volatile struct dbdma_cmd *cp;
  2147. LOCK();
  2148. /* give it a chance to update the output and provide the IRQ
  2149. that is expected.
  2150. */
  2151. out_le32(&awacs_rxdma->control, ((FLUSH) << 16) + FLUSH );
  2152. cp = awacs_rx_cmds;
  2153. for (i = 0; i < read_sq.max_count; i++,cp++)
  2154. st_le16(&cp->command, DBDMA_STOP);
  2155. /*
  2156. * We should probably wait for the thing to stop before we
  2157. * release the memory.
  2158. */
  2159. msleep(100) ; /* give it a (small) chance to act */
  2160. /* apply the sledgehammer approach - just stop it now */
  2161. out_le32(&awacs_rxdma->control, (RUN|PAUSE|FLUSH|WAKE) << 16);
  2162. UNLOCK();
  2163. }
  2164. extern char *get_afmt_string(int);
  2165. static int PMacStateInfo(char *b, size_t sp)
  2166. {
  2167. int i, len = 0;
  2168. len = sprintf(b,"HW rates: ");
  2169. switch (awacs_revision){
  2170. case AWACS_DACA:
  2171. case AWACS_BURGUNDY:
  2172. len += sprintf(b,"44100 ") ;
  2173. break ;
  2174. case AWACS_TUMBLER:
  2175. case AWACS_SNAPPER:
  2176. for (i=0; i<1; i++){
  2177. if (tas_freqs_ok[i])
  2178. len += sprintf(b+len,"%d ", tas_freqs[i]) ;
  2179. }
  2180. break ;
  2181. case AWACS_AWACS:
  2182. case AWACS_SCREAMER:
  2183. default:
  2184. for (i=0; i<8; i++){
  2185. if (awacs_freqs_ok[i])
  2186. len += sprintf(b+len,"%d ", awacs_freqs[i]) ;
  2187. }
  2188. break ;
  2189. }
  2190. len += sprintf(b+len,"s/sec\n") ;
  2191. if (len < sp) {
  2192. len += sprintf(b+len,"HW AFMTS: ");
  2193. i = AFMT_U16_BE ;
  2194. while (i) {
  2195. if (i & dmasound.mach.hardware_afmts)
  2196. len += sprintf(b+len,"%s ",
  2197. get_afmt_string(i & dmasound.mach.hardware_afmts));
  2198. i >>= 1 ;
  2199. }
  2200. len += sprintf(b+len,"\n") ;
  2201. }
  2202. return len ;
  2203. }
  2204. /*** Machine definitions *****************************************************/
  2205. static SETTINGS def_hard = {
  2206. .format = AFMT_S16_BE,
  2207. .stereo = 1,
  2208. .size = 16,
  2209. .speed = 44100
  2210. } ;
  2211. static SETTINGS def_soft = {
  2212. .format = AFMT_S16_BE,
  2213. .stereo = 1,
  2214. .size = 16,
  2215. .speed = 44100
  2216. } ;
  2217. static MACHINE machPMac = {
  2218. .name = awacs_name,
  2219. .name2 = "PowerMac Built-in Sound",
  2220. .owner = THIS_MODULE,
  2221. .dma_alloc = PMacAlloc,
  2222. .dma_free = PMacFree,
  2223. .irqinit = PMacIrqInit,
  2224. #ifdef MODULE
  2225. .irqcleanup = PMacIrqCleanup,
  2226. #endif /* MODULE */
  2227. .init = PMacInit,
  2228. .silence = PMacSilence,
  2229. .setFormat = PMacSetFormat,
  2230. .setVolume = PMacSetVolume,
  2231. .play = PMacPlay,
  2232. .record = NULL, /* default to no record */
  2233. .mixer_init = PMacMixerInit,
  2234. .mixer_ioctl = PMacMixerIoctl,
  2235. .write_sq_setup = PMacWriteSqSetup,
  2236. .read_sq_setup = PMacReadSqSetup,
  2237. .state_info = PMacStateInfo,
  2238. .abort_read = PMacAbortRead,
  2239. .min_dsp_speed = 7350,
  2240. .max_dsp_speed = 44100,
  2241. .version = ((DMASOUND_AWACS_REVISION<<8) + DMASOUND_AWACS_EDITION)
  2242. };
  2243. /*** Config & Setup **********************************************************/
  2244. /* Check for pmac models that we care about in terms of special actions.
  2245. */
  2246. void __init
  2247. set_model(void)
  2248. {
  2249. /* portables/lap-tops */
  2250. if (machine_is_compatible("AAPL,3400/2400") ||
  2251. machine_is_compatible("AAPL,3500")) {
  2252. is_pbook_3X00 = 1 ;
  2253. }
  2254. if (machine_is_compatible("PowerBook1,1") || /* lombard */
  2255. machine_is_compatible("AAPL,PowerBook1998")){ /* wallstreet */
  2256. is_pbook_g3 = 1 ;
  2257. return ;
  2258. }
  2259. }
  2260. /* Get the OF node that tells us about the registers, interrupts etc. to use
  2261. for sound IO.
  2262. On most machines the sound IO OF node is the 'davbus' node. On newer pmacs
  2263. with DACA (& Tumbler) the node to use is i2s-a. On much older machines i.e.
  2264. before 9500 there is no davbus node and we have to use the 'awacs' property.
  2265. In the latter case we signal this by setting the codec value - so that the
  2266. code that looks for chip properties knows how to go about it.
  2267. */
  2268. static struct device_node* __init
  2269. get_snd_io_node(void)
  2270. {
  2271. struct device_node *np = NULL;
  2272. /* set up awacs_node for early OF which doesn't have a full set of
  2273. * properties on davbus
  2274. */
  2275. awacs_node = find_devices("awacs");
  2276. if (awacs_node)
  2277. awacs_revision = AWACS_AWACS;
  2278. /* powermac models after 9500 (other than those which use DACA or
  2279. * Tumbler) have a node called "davbus".
  2280. */
  2281. np = find_devices("davbus");
  2282. /*
  2283. * if we didn't find a davbus device, try 'i2s-a' since
  2284. * this seems to be what iBooks (& Tumbler) have.
  2285. */
  2286. if (np == NULL)
  2287. np = i2s_node = find_devices("i2s-a");
  2288. /* if we didn't find this - perhaps we are on an early model
  2289. * which _only_ has an 'awacs' node
  2290. */
  2291. if (np == NULL && awacs_node)
  2292. np = awacs_node ;
  2293. /* if we failed all these return null - this will cause the
  2294. * driver to give up...
  2295. */
  2296. return np ;
  2297. }
  2298. /* Get the OF node that contains the info about the sound chip, inputs s-rates
  2299. etc.
  2300. This node does not exist (or contains much reduced info) on earlier machines
  2301. we have to deduce the info other ways for these.
  2302. */
  2303. static struct device_node* __init
  2304. get_snd_info_node(struct device_node *io)
  2305. {
  2306. struct device_node *info;
  2307. info = find_devices("sound");
  2308. while (info && info->parent != io)
  2309. info = info->next;
  2310. return info;
  2311. }
  2312. /* Find out what type of codec we have.
  2313. */
  2314. static int __init
  2315. get_codec_type(struct device_node *info)
  2316. {
  2317. /* already set if pre-davbus model and info will be NULL */
  2318. int codec = awacs_revision ;
  2319. if (info) {
  2320. /* must do awacs first to allow screamer to overide it */
  2321. if (device_is_compatible(info, "awacs"))
  2322. codec = AWACS_AWACS ;
  2323. if (device_is_compatible(info, "screamer"))
  2324. codec = AWACS_SCREAMER;
  2325. if (device_is_compatible(info, "burgundy"))
  2326. codec = AWACS_BURGUNDY ;
  2327. if (device_is_compatible(info, "daca"))
  2328. codec = AWACS_DACA;
  2329. if (device_is_compatible(info, "tumbler"))
  2330. codec = AWACS_TUMBLER;
  2331. if (device_is_compatible(info, "snapper"))
  2332. codec = AWACS_SNAPPER;
  2333. }
  2334. return codec ;
  2335. }
  2336. /* find out what type, if any, of expansion card we have
  2337. */
  2338. static void __init
  2339. get_expansion_type(void)
  2340. {
  2341. if (find_devices("perch") != NULL)
  2342. has_perch = 1;
  2343. if (find_devices("pb-ziva-pc") != NULL)
  2344. has_ziva = 1;
  2345. /* need to work out how we deal with iMac SRS module */
  2346. }
  2347. /* set up frame rates.
  2348. * I suspect that these routines don't quite go about it the right way:
  2349. * - where there is more than one rate - I think that the first property
  2350. * value is the number of rates.
  2351. * TODO: check some more device trees and modify accordingly
  2352. * Set dmasound.mach.max_dsp_rate on the basis of these routines.
  2353. */
  2354. static void __init
  2355. awacs_init_frame_rates(unsigned int *prop, unsigned int l)
  2356. {
  2357. int i ;
  2358. if (prop) {
  2359. for (i=0; i<8; i++)
  2360. awacs_freqs_ok[i] = 0 ;
  2361. for (l /= sizeof(int); l > 0; --l) {
  2362. unsigned int r = *prop++;
  2363. /* Apple 'Fixed' format */
  2364. if (r >= 0x10000)
  2365. r >>= 16;
  2366. for (i = 0; i < 8; ++i) {
  2367. if (r == awacs_freqs[i]) {
  2368. awacs_freqs_ok[i] = 1;
  2369. break;
  2370. }
  2371. }
  2372. }
  2373. }
  2374. /* else we assume that all the rates are available */
  2375. }
  2376. static void __init
  2377. burgundy_init_frame_rates(unsigned int *prop, unsigned int l)
  2378. {
  2379. int temp[9] ;
  2380. int i = 0 ;
  2381. if (prop) {
  2382. for (l /= sizeof(int); l > 0; --l) {
  2383. unsigned int r = *prop++;
  2384. /* Apple 'Fixed' format */
  2385. if (r >= 0x10000)
  2386. r >>= 16;
  2387. temp[i] = r ;
  2388. i++ ; if(i>=9) i=8;
  2389. }
  2390. }
  2391. #ifdef DEBUG_DMASOUND
  2392. if (i > 1){
  2393. int j;
  2394. printk("dmasound_pmac: burgundy with multiple frame rates\n");
  2395. for(j=0; j<i; j++)
  2396. printk("%d ", temp[j]) ;
  2397. printk("\n") ;
  2398. }
  2399. #endif
  2400. }
  2401. static void __init
  2402. daca_init_frame_rates(unsigned int *prop, unsigned int l)
  2403. {
  2404. int temp[9] ;
  2405. int i = 0 ;
  2406. if (prop) {
  2407. for (l /= sizeof(int); l > 0; --l) {
  2408. unsigned int r = *prop++;
  2409. /* Apple 'Fixed' format */
  2410. if (r >= 0x10000)
  2411. r >>= 16;
  2412. temp[i] = r ;
  2413. i++ ; if(i>=9) i=8;
  2414. }
  2415. }
  2416. #ifdef DEBUG_DMASOUND
  2417. if (i > 1){
  2418. int j;
  2419. printk("dmasound_pmac: DACA with multiple frame rates\n");
  2420. for(j=0; j<i; j++)
  2421. printk("%d ", temp[j]) ;
  2422. printk("\n") ;
  2423. }
  2424. #endif
  2425. }
  2426. static void __init
  2427. init_frame_rates(unsigned int *prop, unsigned int l)
  2428. {
  2429. switch (awacs_revision) {
  2430. case AWACS_TUMBLER:
  2431. case AWACS_SNAPPER:
  2432. tas_init_frame_rates(prop, l);
  2433. break ;
  2434. case AWACS_DACA:
  2435. daca_init_frame_rates(prop, l);
  2436. break ;
  2437. case AWACS_BURGUNDY:
  2438. burgundy_init_frame_rates(prop, l);
  2439. break ;
  2440. default:
  2441. awacs_init_frame_rates(prop, l);
  2442. break ;
  2443. }
  2444. }
  2445. /* find things/machines that can't do mac-io byteswap
  2446. */
  2447. static void __init
  2448. set_hw_byteswap(struct device_node *io)
  2449. {
  2450. struct device_node *mio ;
  2451. unsigned int kl = 0 ;
  2452. /* if seems that Keylargo can't byte-swap */
  2453. for (mio = io->parent; mio ; mio = mio->parent) {
  2454. if (strcmp(mio->name, "mac-io") == 0) {
  2455. if (device_is_compatible(mio, "Keylargo"))
  2456. kl = 1;
  2457. break;
  2458. }
  2459. }
  2460. hw_can_byteswap = !kl;
  2461. }
  2462. /* Allocate the resources necessary for beep generation. This cannot be (quite)
  2463. done statically (yet) because we cannot do virt_to_bus() on static vars when
  2464. the code is loaded as a module.
  2465. for the sake of saving the possibility that two allocations will incur the
  2466. overhead of two pull-ups in DBDMA_ALIGN() we allocate the 'emergency' dmdma
  2467. command here as well... even tho' it is not part of the beep process.
  2468. */
  2469. int32_t
  2470. __init setup_beep(void)
  2471. {
  2472. /* Initialize beep stuff */
  2473. /* want one cmd buffer for beeps, and a second one for emergencies
  2474. - i.e. dbdma error conditions.
  2475. ask for three to allow for pull up in DBDMA_ALIGN().
  2476. */
  2477. beep_dbdma_cmd_space =
  2478. kmalloc((2 + 1) * sizeof(struct dbdma_cmd), GFP_KERNEL);
  2479. if(beep_dbdma_cmd_space == NULL) {
  2480. printk(KERN_ERR "dmasound_pmac: no beep dbdma cmd space\n") ;
  2481. return -ENOMEM ;
  2482. }
  2483. beep_dbdma_cmd = (volatile struct dbdma_cmd *)
  2484. DBDMA_ALIGN(beep_dbdma_cmd_space);
  2485. /* set up emergency dbdma cmd */
  2486. emergency_dbdma_cmd = beep_dbdma_cmd+1 ;
  2487. beep_buf = kmalloc(BEEP_BUFLEN * 4, GFP_KERNEL);
  2488. if (beep_buf == NULL) {
  2489. printk(KERN_ERR "dmasound_pmac: no memory for beep buffer\n");
  2490. kfree(beep_dbdma_cmd_space) ;
  2491. return -ENOMEM ;
  2492. }
  2493. return 0 ;
  2494. }
  2495. static struct input_dev *awacs_beep_dev;
  2496. int __init dmasound_awacs_init(void)
  2497. {
  2498. struct device_node *io = NULL, *info = NULL;
  2499. int vol, res;
  2500. if (!machine_is(powermac))
  2501. return -ENODEV;
  2502. awacs_subframe = 0;
  2503. awacs_revision = 0;
  2504. hw_can_byteswap = 1 ; /* most can */
  2505. /* look for models we need to handle specially */
  2506. set_model() ;
  2507. /* find the OF node that tells us about the dbdma stuff
  2508. */
  2509. io = get_snd_io_node();
  2510. if (io == NULL) {
  2511. #ifdef DEBUG_DMASOUND
  2512. printk("dmasound_pmac: couldn't find sound io OF node\n");
  2513. #endif
  2514. return -ENODEV ;
  2515. }
  2516. /* find the OF node that tells us about the sound sub-system
  2517. * this doesn't exist on pre-davbus machines (earlier than 9500)
  2518. */
  2519. if (awacs_revision != AWACS_AWACS) { /* set for pre-davbus */
  2520. info = get_snd_info_node(io) ;
  2521. if (info == NULL){
  2522. #ifdef DEBUG_DMASOUND
  2523. printk("dmasound_pmac: couldn't find 'sound' OF node\n");
  2524. #endif
  2525. return -ENODEV ;
  2526. }
  2527. }
  2528. awacs_revision = get_codec_type(info) ;
  2529. if (awacs_revision == 0) {
  2530. #ifdef DEBUG_DMASOUND
  2531. printk("dmasound_pmac: couldn't find a Codec we can handle\n");
  2532. #endif
  2533. return -ENODEV ; /* we don't know this type of h/w */
  2534. }
  2535. /* set up perch, ziva, SRS or whatever else we have as sound
  2536. * expansion.
  2537. */
  2538. get_expansion_type();
  2539. /* we've now got enough information to make up the audio topology.
  2540. * we will map the sound part of mac-io now so that we can probe for
  2541. * other info if necessary (early AWACS we want to read chip ids)
  2542. */
  2543. if (of_get_address(io, 2, NULL, NULL) == NULL) {
  2544. /* OK - maybe we need to use the 'awacs' node (on earlier
  2545. * machines).
  2546. */
  2547. if (awacs_node) {
  2548. io = awacs_node ;
  2549. if (of_get_address(io, 2, NULL, NULL) == NULL) {
  2550. printk("dmasound_pmac: can't use %s\n",
  2551. io->full_name);
  2552. return -ENODEV;
  2553. }
  2554. } else
  2555. printk("dmasound_pmac: can't use %s\n", io->full_name);
  2556. }
  2557. if (of_address_to_resource(io, 0, &awacs_rsrc[0]) ||
  2558. request_mem_region(awacs_rsrc[0].start,
  2559. awacs_rsrc[0].end - awacs_rsrc[0].start + 1,
  2560. " (IO)") == NULL) {
  2561. printk(KERN_ERR "dmasound: can't request IO resource !\n");
  2562. return -ENODEV;
  2563. }
  2564. if (of_address_to_resource(io, 1, &awacs_rsrc[1]) ||
  2565. request_mem_region(awacs_rsrc[1].start,
  2566. awacs_rsrc[1].end - awacs_rsrc[1].start + 1,
  2567. " (tx dma)") == NULL) {
  2568. release_mem_region(awacs_rsrc[0].start,
  2569. awacs_rsrc[0].end - awacs_rsrc[0].start + 1);
  2570. printk(KERN_ERR "dmasound: can't request Tx DMA resource !\n");
  2571. return -ENODEV;
  2572. }
  2573. if (of_address_to_resource(io, 2, &awacs_rsrc[2]) ||
  2574. request_mem_region(awacs_rsrc[2].start,
  2575. awacs_rsrc[2].end - awacs_rsrc[2].start + 1,
  2576. " (rx dma)") == NULL) {
  2577. release_mem_region(awacs_rsrc[0].start,
  2578. awacs_rsrc[0].end - awacs_rsrc[0].start + 1);
  2579. release_mem_region(awacs_rsrc[1].start,
  2580. awacs_rsrc[1].end - awacs_rsrc[1].start + 1);
  2581. printk(KERN_ERR "dmasound: can't request Rx DMA resource !\n");
  2582. return -ENODEV;
  2583. }
  2584. awacs_beep_dev = input_allocate_device();
  2585. if (!awacs_beep_dev) {
  2586. release_mem_region(awacs_rsrc[0].start,
  2587. awacs_rsrc[0].end - awacs_rsrc[0].start + 1);
  2588. release_mem_region(awacs_rsrc[1].start,
  2589. awacs_rsrc[1].end - awacs_rsrc[1].start + 1);
  2590. release_mem_region(awacs_rsrc[2].start,
  2591. awacs_rsrc[2].end - awacs_rsrc[2].start + 1);
  2592. printk(KERN_ERR "dmasound: can't allocate input device !\n");
  2593. return -ENOMEM;
  2594. }
  2595. awacs_beep_dev->name = "dmasound beeper";
  2596. awacs_beep_dev->phys = "macio/input0";
  2597. awacs_beep_dev->id.bustype = BUS_HOST;
  2598. awacs_beep_dev->event = awacs_beep_event;
  2599. awacs_beep_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
  2600. awacs_beep_dev->evbit[0] = BIT(EV_SND);
  2601. /* all OF versions I've seen use this value */
  2602. if (i2s_node)
  2603. i2s = ioremap(awacs_rsrc[0].start, 0x1000);
  2604. else
  2605. awacs = ioremap(awacs_rsrc[0].start, 0x1000);
  2606. awacs_txdma = ioremap(awacs_rsrc[1].start, 0x100);
  2607. awacs_rxdma = ioremap(awacs_rsrc[2].start, 0x100);
  2608. /* first of all make sure that the chip is powered up....*/
  2609. pmac_call_feature(PMAC_FTR_SOUND_CHIP_ENABLE, io, 0, 1);
  2610. if (awacs_revision == AWACS_SCREAMER && awacs)
  2611. awacs_recalibrate();
  2612. awacs_irq = irq_of_parse_and_map(io, 0);
  2613. awacs_tx_irq = irq_of_parse_and_map(io, 1);
  2614. awacs_rx_irq = irq_of_parse_and_map(io, 2);
  2615. /* Hack for legacy crap that will be killed someday */
  2616. awacs_node = io;
  2617. /* if we have an awacs or screamer - probe the chip to make
  2618. * sure we have the right revision.
  2619. */
  2620. if (awacs_revision <= AWACS_SCREAMER){
  2621. uint32_t temp, rev, mfg ;
  2622. /* find out the awacs revision from the chip */
  2623. temp = in_le32(&awacs->codec_stat);
  2624. rev = (temp >> 12) & 0xf;
  2625. mfg = (temp >> 8) & 0xf;
  2626. #ifdef DEBUG_DMASOUND
  2627. printk("dmasound_pmac: Awacs/Screamer Codec Mfct: %d Rev %d\n", mfg, rev);
  2628. #endif
  2629. if (rev >= AWACS_SCREAMER)
  2630. awacs_revision = AWACS_SCREAMER ;
  2631. else
  2632. awacs_revision = rev ;
  2633. }
  2634. dmasound.mach = machPMac;
  2635. /* find out other bits & pieces from OF, these may be present
  2636. only on some models ... so be careful.
  2637. */
  2638. /* in the absence of a frame rates property we will use the defaults
  2639. */
  2640. if (info) {
  2641. unsigned int *prop, l;
  2642. sound_device_id = 0;
  2643. /* device ID appears post g3 b&w */
  2644. prop = (unsigned int *)get_property(info, "device-id", NULL);
  2645. if (prop != 0)
  2646. sound_device_id = *prop;
  2647. /* look for a property saying what sample rates
  2648. are available */
  2649. prop = (unsigned int *)get_property(info, "sample-rates", &l);
  2650. if (prop == 0)
  2651. prop = (unsigned int *) get_property
  2652. (info, "output-frame-rates", &l);
  2653. /* if it's there use it to set up frame rates */
  2654. init_frame_rates(prop, l) ;
  2655. }
  2656. if (awacs)
  2657. out_le32(&awacs->control, 0x11); /* set everything quiesent */
  2658. set_hw_byteswap(io) ; /* figure out if the h/w can do it */
  2659. #ifdef CONFIG_NVRAM
  2660. /* get default volume from nvram */
  2661. vol = ((pmac_xpram_read( 8 ) & 7 ) << 1 );
  2662. #else
  2663. vol = 0;
  2664. #endif
  2665. /* set up tracking values */
  2666. spk_vol = vol * 100 ;
  2667. spk_vol /= 7 ; /* get set value to a percentage */
  2668. spk_vol |= (spk_vol << 8) ; /* equal left & right */
  2669. line_vol = passthru_vol = spk_vol ;
  2670. /* fill regs that are shared between AWACS & Burgundy */
  2671. awacs_reg[2] = vol + (vol << 6);
  2672. awacs_reg[4] = vol + (vol << 6);
  2673. awacs_reg[5] = vol + (vol << 6); /* screamer has loopthru vol control */
  2674. awacs_reg[6] = 0; /* maybe should be vol << 3 for PCMCIA speaker */
  2675. awacs_reg[7] = 0;
  2676. awacs_reg[0] = MASK_MUX_CD;
  2677. awacs_reg[1] = MASK_LOOPTHRU;
  2678. /* FIXME: Only machines with external SRS module need MASK_PAROUT */
  2679. if (has_perch || sound_device_id == 0x5
  2680. || /*sound_device_id == 0x8 ||*/ sound_device_id == 0xb)
  2681. awacs_reg[1] |= MASK_PAROUT0 | MASK_PAROUT1;
  2682. switch (awacs_revision) {
  2683. case AWACS_TUMBLER:
  2684. tas_register_driver(&tas3001c_hooks);
  2685. tas_init(I2C_DRIVERID_TAS3001C, I2C_DRIVERNAME_TAS3001C);
  2686. tas_dmasound_init();
  2687. tas_post_init();
  2688. break ;
  2689. case AWACS_SNAPPER:
  2690. tas_register_driver(&tas3004_hooks);
  2691. tas_init(I2C_DRIVERID_TAS3004,I2C_DRIVERNAME_TAS3004);
  2692. tas_dmasound_init();
  2693. tas_post_init();
  2694. break;
  2695. case AWACS_DACA:
  2696. daca_init();
  2697. break;
  2698. case AWACS_BURGUNDY:
  2699. awacs_burgundy_init();
  2700. break ;
  2701. case AWACS_SCREAMER:
  2702. case AWACS_AWACS:
  2703. default:
  2704. load_awacs();
  2705. break ;
  2706. }
  2707. /* enable/set-up external modules - when we know how */
  2708. if (has_perch)
  2709. awacs_enable_amp(100 * 0x101);
  2710. /* Reset dbdma channels */
  2711. out_le32(&awacs_txdma->control, (RUN|PAUSE|FLUSH|WAKE|DEAD) << 16);
  2712. while (in_le32(&awacs_txdma->status) & RUN)
  2713. udelay(1);
  2714. out_le32(&awacs_rxdma->control, (RUN|PAUSE|FLUSH|WAKE|DEAD) << 16);
  2715. while (in_le32(&awacs_rxdma->status) & RUN)
  2716. udelay(1);
  2717. /* Initialize beep stuff */
  2718. if ((res=setup_beep()))
  2719. return res ;
  2720. #ifdef CONFIG_PM
  2721. pmu_register_sleep_notifier(&awacs_sleep_notifier);
  2722. #endif /* CONFIG_PM */
  2723. /* Powerbooks have odd ways of enabling inputs such as
  2724. an expansion-bay CD or sound from an internal modem
  2725. or a PC-card modem. */
  2726. if (is_pbook_3X00) {
  2727. /*
  2728. * Enable CD and PC-card sound inputs.
  2729. * This is done by reading from address
  2730. * f301a000, + 0x10 to enable the expansion-bay
  2731. * CD sound input, + 0x80 to enable the PC-card
  2732. * sound input. The 0x100 enables the SCSI bus
  2733. * terminator power.
  2734. */
  2735. latch_base = ioremap (0xf301a000, 0x1000);
  2736. in_8(latch_base + 0x190);
  2737. } else if (is_pbook_g3) {
  2738. struct device_node* mio;
  2739. macio_base = NULL;
  2740. for (mio = io->parent; mio; mio = mio->parent) {
  2741. if (strcmp(mio->name, "mac-io") == 0) {
  2742. struct resource r;
  2743. if (of_address_to_resource(mio, 0, &r) == 0)
  2744. macio_base = ioremap(r.start, 0x40);
  2745. break;
  2746. }
  2747. }
  2748. /*
  2749. * Enable CD sound input.
  2750. * The relevant bits for writing to this byte are 0x8f.
  2751. * I haven't found out what the 0x80 bit does.
  2752. * For the 0xf bits, writing 3 or 7 enables the CD
  2753. * input, any other value disables it. Values
  2754. * 1, 3, 5, 7 enable the microphone. Values 0, 2,
  2755. * 4, 6, 8 - f enable the input from the modem.
  2756. * -- paulus.
  2757. */
  2758. if (macio_base)
  2759. out_8(macio_base + 0x37, 3);
  2760. }
  2761. if (hw_can_byteswap)
  2762. dmasound.mach.hardware_afmts = (AFMT_S16_BE | AFMT_S16_LE) ;
  2763. else
  2764. dmasound.mach.hardware_afmts = AFMT_S16_BE ;
  2765. /* shut out chips that do output only.
  2766. * may need to extend this to machines which have no inputs - even tho'
  2767. * they use screamer - IIRC one of the powerbooks is like this.
  2768. */
  2769. if (awacs_revision != AWACS_DACA) {
  2770. dmasound.mach.capabilities = DSP_CAP_DUPLEX ;
  2771. dmasound.mach.record = PMacRecord ;
  2772. }
  2773. dmasound.mach.default_hard = def_hard ;
  2774. dmasound.mach.default_soft = def_soft ;
  2775. switch (awacs_revision) {
  2776. case AWACS_BURGUNDY:
  2777. sprintf(awacs_name, "PowerMac Burgundy ") ;
  2778. break ;
  2779. case AWACS_DACA:
  2780. sprintf(awacs_name, "PowerMac DACA ") ;
  2781. break ;
  2782. case AWACS_TUMBLER:
  2783. sprintf(awacs_name, "PowerMac Tumbler ") ;
  2784. break ;
  2785. case AWACS_SNAPPER:
  2786. sprintf(awacs_name, "PowerMac Snapper ") ;
  2787. break ;
  2788. case AWACS_SCREAMER:
  2789. sprintf(awacs_name, "PowerMac Screamer ") ;
  2790. break ;
  2791. case AWACS_AWACS:
  2792. default:
  2793. sprintf(awacs_name, "PowerMac AWACS rev %d ", awacs_revision) ;
  2794. break ;
  2795. }
  2796. /*
  2797. * XXX: we should handle errors here, but that would mean
  2798. * rewriting the whole init code. later..
  2799. */
  2800. input_register_device(awacs_beep_dev);
  2801. return dmasound_init();
  2802. }
  2803. static void __exit dmasound_awacs_cleanup(void)
  2804. {
  2805. input_unregister_device(awacs_beep_dev);
  2806. switch (awacs_revision) {
  2807. case AWACS_TUMBLER:
  2808. case AWACS_SNAPPER:
  2809. tas_dmasound_cleanup();
  2810. tas_cleanup();
  2811. break ;
  2812. case AWACS_DACA:
  2813. daca_cleanup();
  2814. break;
  2815. }
  2816. dmasound_deinit();
  2817. }
  2818. MODULE_DESCRIPTION("PowerMac built-in audio driver.");
  2819. MODULE_LICENSE("GPL");
  2820. module_init(dmasound_awacs_init);
  2821. module_exit(dmasound_awacs_cleanup);