dmasound_awacs.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:82k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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