interwave.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. /*
  2. * Driver for AMD InterWave soundcard
  3. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  4. *
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. * 1999/07/22 Erik Inge Bolso <knan@mo.himolde.no>
  21. * * mixer group handlers
  22. *
  23. */
  24. #include <linux/init.h>
  25. #include <linux/err.h>
  26. #include <linux/isa.h>
  27. #include <linux/delay.h>
  28. #include <linux/pnp.h>
  29. #include <linux/module.h>
  30. #include <asm/dma.h>
  31. #include <sound/core.h>
  32. #include <sound/gus.h>
  33. #include <sound/wss.h>
  34. #ifdef SNDRV_STB
  35. #include <sound/tea6330t.h>
  36. #endif
  37. #define SNDRV_LEGACY_FIND_FREE_IRQ
  38. #define SNDRV_LEGACY_FIND_FREE_DMA
  39. #include <sound/initval.h>
  40. MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
  41. MODULE_LICENSE("GPL");
  42. #ifndef SNDRV_STB
  43. MODULE_DESCRIPTION("AMD InterWave");
  44. MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Plug & Play},"
  45. "{STB,SoundRage32},"
  46. "{MED,MED3210},"
  47. "{Dynasonix,Dynasonix Pro},"
  48. "{Panasonic,PCA761AW}}");
  49. #else
  50. MODULE_DESCRIPTION("AMD InterWave STB with TEA6330T");
  51. MODULE_SUPPORTED_DEVICE("{{AMD,InterWave STB with TEA6330T}}");
  52. #endif
  53. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  54. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  55. static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
  56. #ifdef CONFIG_PNP
  57. static bool isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
  58. #endif
  59. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x210,0x220,0x230,0x240,0x250,0x260 */
  60. #ifdef SNDRV_STB
  61. static long port_tc[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x350,0x360,0x370,0x380 */
  62. #endif
  63. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 2,3,5,9,11,12,15 */
  64. static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
  65. static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
  66. static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29};
  67. /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
  68. static int midi[SNDRV_CARDS];
  69. static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
  70. static int effect[SNDRV_CARDS];
  71. #ifdef SNDRV_STB
  72. #define PFX "interwave-stb: "
  73. #define INTERWAVE_DRIVER "snd_interwave_stb"
  74. #define INTERWAVE_PNP_DRIVER "interwave-stb"
  75. #else
  76. #define PFX "interwave: "
  77. #define INTERWAVE_DRIVER "snd_interwave"
  78. #define INTERWAVE_PNP_DRIVER "interwave"
  79. #endif
  80. module_param_array(index, int, NULL, 0444);
  81. MODULE_PARM_DESC(index, "Index value for InterWave soundcard.");
  82. module_param_array(id, charp, NULL, 0444);
  83. MODULE_PARM_DESC(id, "ID string for InterWave soundcard.");
  84. module_param_array(enable, bool, NULL, 0444);
  85. MODULE_PARM_DESC(enable, "Enable InterWave soundcard.");
  86. #ifdef CONFIG_PNP
  87. module_param_array(isapnp, bool, NULL, 0444);
  88. MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
  89. #endif
  90. module_param_array(port, long, NULL, 0444);
  91. MODULE_PARM_DESC(port, "Port # for InterWave driver.");
  92. #ifdef SNDRV_STB
  93. module_param_array(port_tc, long, NULL, 0444);
  94. MODULE_PARM_DESC(port_tc, "Tone control (TEA6330T - i2c bus) port # for InterWave driver.");
  95. #endif
  96. module_param_array(irq, int, NULL, 0444);
  97. MODULE_PARM_DESC(irq, "IRQ # for InterWave driver.");
  98. module_param_array(dma1, int, NULL, 0444);
  99. MODULE_PARM_DESC(dma1, "DMA1 # for InterWave driver.");
  100. module_param_array(dma2, int, NULL, 0444);
  101. MODULE_PARM_DESC(dma2, "DMA2 # for InterWave driver.");
  102. module_param_array(joystick_dac, int, NULL, 0444);
  103. MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for InterWave driver.");
  104. module_param_array(midi, int, NULL, 0444);
  105. MODULE_PARM_DESC(midi, "MIDI UART enable for InterWave driver.");
  106. module_param_array(pcm_channels, int, NULL, 0444);
  107. MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for InterWave driver.");
  108. module_param_array(effect, int, NULL, 0444);
  109. MODULE_PARM_DESC(effect, "Effects enable for InterWave driver.");
  110. struct snd_interwave {
  111. int irq;
  112. struct snd_card *card;
  113. struct snd_gus_card *gus;
  114. struct snd_wss *wss;
  115. #ifdef SNDRV_STB
  116. struct resource *i2c_res;
  117. #endif
  118. unsigned short gus_status_reg;
  119. unsigned short pcm_status_reg;
  120. #ifdef CONFIG_PNP
  121. struct pnp_dev *dev;
  122. #ifdef SNDRV_STB
  123. struct pnp_dev *devtc;
  124. #endif
  125. #endif
  126. };
  127. #ifdef CONFIG_PNP
  128. static int isa_registered;
  129. static int pnp_registered;
  130. static struct pnp_card_device_id snd_interwave_pnpids[] = {
  131. #ifndef SNDRV_STB
  132. /* Gravis UltraSound Plug & Play */
  133. { .id = "GRV0001", .devs = { { .id = "GRV0000" } } },
  134. /* STB SoundRage32 */
  135. { .id = "STB011a", .devs = { { .id = "STB0010" } } },
  136. /* MED3210 */
  137. { .id = "DXP3201", .devs = { { .id = "DXP0010" } } },
  138. /* Dynasonic Pro */
  139. /* This device also have CDC1117:DynaSonix Pro Audio Effects Processor */
  140. { .id = "CDC1111", .devs = { { .id = "CDC1112" } } },
  141. /* Panasonic PCA761AW Audio Card */
  142. { .id = "ADV55ff", .devs = { { .id = "ADV0010" } } },
  143. /* InterWave STB without TEA6330T */
  144. { .id = "ADV550a", .devs = { { .id = "ADV0010" } } },
  145. #else
  146. /* InterWave STB with TEA6330T */
  147. { .id = "ADV550a", .devs = { { .id = "ADV0010" }, { .id = "ADV0015" } } },
  148. #endif
  149. { .id = "" }
  150. };
  151. MODULE_DEVICE_TABLE(pnp_card, snd_interwave_pnpids);
  152. #endif /* CONFIG_PNP */
  153. #ifdef SNDRV_STB
  154. static void snd_interwave_i2c_setlines(struct snd_i2c_bus *bus, int ctrl, int data)
  155. {
  156. unsigned long port = bus->private_value;
  157. #if 0
  158. printk(KERN_DEBUG "i2c_setlines - 0x%lx <- %i,%i\n", port, ctrl, data);
  159. #endif
  160. outb((data << 1) | ctrl, port);
  161. udelay(10);
  162. }
  163. static int snd_interwave_i2c_getclockline(struct snd_i2c_bus *bus)
  164. {
  165. unsigned long port = bus->private_value;
  166. unsigned char res;
  167. res = inb(port) & 1;
  168. #if 0
  169. printk(KERN_DEBUG "i2c_getclockline - 0x%lx -> %i\n", port, res);
  170. #endif
  171. return res;
  172. }
  173. static int snd_interwave_i2c_getdataline(struct snd_i2c_bus *bus, int ack)
  174. {
  175. unsigned long port = bus->private_value;
  176. unsigned char res;
  177. if (ack)
  178. udelay(10);
  179. res = (inb(port) & 2) >> 1;
  180. #if 0
  181. printk(KERN_DEBUG "i2c_getdataline - 0x%lx -> %i\n", port, res);
  182. #endif
  183. return res;
  184. }
  185. static struct snd_i2c_bit_ops snd_interwave_i2c_bit_ops = {
  186. .setlines = snd_interwave_i2c_setlines,
  187. .getclock = snd_interwave_i2c_getclockline,
  188. .getdata = snd_interwave_i2c_getdataline,
  189. };
  190. static int snd_interwave_detect_stb(struct snd_interwave *iwcard,
  191. struct snd_gus_card *gus, int dev,
  192. struct snd_i2c_bus **rbus)
  193. {
  194. unsigned long port;
  195. struct snd_i2c_bus *bus;
  196. struct snd_card *card = iwcard->card;
  197. char name[32];
  198. int err;
  199. *rbus = NULL;
  200. port = port_tc[dev];
  201. if (port == SNDRV_AUTO_PORT) {
  202. port = 0x350;
  203. if (gus->gf1.port == 0x250) {
  204. port = 0x360;
  205. }
  206. while (port <= 0x380) {
  207. if ((iwcard->i2c_res = request_region(port, 1, "InterWave (I2C bus)")) != NULL)
  208. break;
  209. port += 0x10;
  210. }
  211. } else {
  212. iwcard->i2c_res = request_region(port, 1, "InterWave (I2C bus)");
  213. }
  214. if (iwcard->i2c_res == NULL) {
  215. snd_printk(KERN_ERR "interwave: can't grab i2c bus port\n");
  216. return -ENODEV;
  217. }
  218. sprintf(name, "InterWave-%i", card->number);
  219. if ((err = snd_i2c_bus_create(card, name, NULL, &bus)) < 0)
  220. return err;
  221. bus->private_value = port;
  222. bus->hw_ops.bit = &snd_interwave_i2c_bit_ops;
  223. if ((err = snd_tea6330t_detect(bus, 0)) < 0)
  224. return err;
  225. *rbus = bus;
  226. return 0;
  227. }
  228. #endif
  229. static int snd_interwave_detect(struct snd_interwave *iwcard,
  230. struct snd_gus_card *gus,
  231. int dev
  232. #ifdef SNDRV_STB
  233. , struct snd_i2c_bus **rbus
  234. #endif
  235. )
  236. {
  237. unsigned long flags;
  238. unsigned char rev1, rev2;
  239. int d;
  240. snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */
  241. if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) {
  242. snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
  243. return -ENODEV;
  244. }
  245. udelay(160);
  246. snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */
  247. udelay(160);
  248. if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) {
  249. snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
  250. return -ENODEV;
  251. }
  252. spin_lock_irqsave(&gus->reg_lock, flags);
  253. rev1 = snd_gf1_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER);
  254. snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, ~rev1);
  255. rev2 = snd_gf1_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER);
  256. snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, rev1);
  257. spin_unlock_irqrestore(&gus->reg_lock, flags);
  258. snd_printdd("[0x%lx] InterWave check - rev1=0x%x, rev2=0x%x\n", gus->gf1.port, rev1, rev2);
  259. if ((rev1 & 0xf0) == (rev2 & 0xf0) &&
  260. (rev1 & 0x0f) != (rev2 & 0x0f)) {
  261. snd_printdd("[0x%lx] InterWave check - passed\n", gus->gf1.port);
  262. gus->interwave = 1;
  263. strcpy(gus->card->shortname, "AMD InterWave");
  264. gus->revision = rev1 >> 4;
  265. #ifndef SNDRV_STB
  266. return 0; /* ok.. We have an InterWave board */
  267. #else
  268. return snd_interwave_detect_stb(iwcard, gus, dev, rbus);
  269. #endif
  270. }
  271. snd_printdd("[0x%lx] InterWave check - failed\n", gus->gf1.port);
  272. return -ENODEV;
  273. }
  274. static irqreturn_t snd_interwave_interrupt(int irq, void *dev_id)
  275. {
  276. struct snd_interwave *iwcard = dev_id;
  277. int loop, max = 5;
  278. int handled = 0;
  279. do {
  280. loop = 0;
  281. if (inb(iwcard->gus_status_reg)) {
  282. handled = 1;
  283. snd_gus_interrupt(irq, iwcard->gus);
  284. loop++;
  285. }
  286. if (inb(iwcard->pcm_status_reg) & 0x01) { /* IRQ bit is set? */
  287. handled = 1;
  288. snd_wss_interrupt(irq, iwcard->wss);
  289. loop++;
  290. }
  291. } while (loop && --max > 0);
  292. return IRQ_RETVAL(handled);
  293. }
  294. static void snd_interwave_reset(struct snd_gus_card *gus)
  295. {
  296. snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x00);
  297. udelay(160);
  298. snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x01);
  299. udelay(160);
  300. }
  301. static void snd_interwave_bank_sizes(struct snd_gus_card *gus, int *sizes)
  302. {
  303. unsigned int idx;
  304. unsigned int local;
  305. unsigned char d;
  306. for (idx = 0; idx < 4; idx++) {
  307. sizes[idx] = 0;
  308. d = 0x55;
  309. for (local = idx << 22;
  310. local < (idx << 22) + 0x400000;
  311. local += 0x40000, d++) {
  312. snd_gf1_poke(gus, local, d);
  313. snd_gf1_poke(gus, local + 1, d + 1);
  314. #if 0
  315. printk(KERN_DEBUG "d = 0x%x, local = 0x%x, "
  316. "local + 1 = 0x%x, idx << 22 = 0x%x\n",
  317. d,
  318. snd_gf1_peek(gus, local),
  319. snd_gf1_peek(gus, local + 1),
  320. snd_gf1_peek(gus, idx << 22));
  321. #endif
  322. if (snd_gf1_peek(gus, local) != d ||
  323. snd_gf1_peek(gus, local + 1) != d + 1 ||
  324. snd_gf1_peek(gus, idx << 22) != 0x55)
  325. break;
  326. sizes[idx]++;
  327. }
  328. }
  329. #if 0
  330. printk(KERN_DEBUG "sizes: %i %i %i %i\n",
  331. sizes[0], sizes[1], sizes[2], sizes[3]);
  332. #endif
  333. }
  334. struct rom_hdr {
  335. /* 000 */ unsigned char iwave[8];
  336. /* 008 */ unsigned char rom_hdr_revision;
  337. /* 009 */ unsigned char series_number;
  338. /* 010 */ unsigned char series_name[16];
  339. /* 026 */ unsigned char date[10];
  340. /* 036 */ unsigned short vendor_revision_major;
  341. /* 038 */ unsigned short vendor_revision_minor;
  342. /* 040 */ unsigned int rom_size;
  343. /* 044 */ unsigned char copyright[128];
  344. /* 172 */ unsigned char vendor_name[64];
  345. /* 236 */ unsigned char rom_description[128];
  346. /* 364 */ unsigned char pad[147];
  347. /* 511 */ unsigned char csum;
  348. };
  349. static void snd_interwave_detect_memory(struct snd_gus_card *gus)
  350. {
  351. static unsigned int lmc[13] =
  352. {
  353. 0x00000001, 0x00000101, 0x01010101, 0x00000401,
  354. 0x04040401, 0x00040101, 0x04040101, 0x00000004,
  355. 0x00000404, 0x04040404, 0x00000010, 0x00001010,
  356. 0x10101010
  357. };
  358. int bank_pos, pages;
  359. unsigned int i, lmct;
  360. int psizes[4];
  361. unsigned char iwave[8];
  362. unsigned char csum;
  363. snd_interwave_reset(gus);
  364. snd_gf1_write8(gus, SNDRV_GF1_GB_GLOBAL_MODE, snd_gf1_read8(gus, SNDRV_GF1_GB_GLOBAL_MODE) | 0x01); /* enhanced mode */
  365. snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01); /* DRAM I/O cycles selected */
  366. snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xff10) | 0x004c);
  367. /* ok.. simple test of memory size */
  368. pages = 0;
  369. snd_gf1_poke(gus, 0, 0x55);
  370. snd_gf1_poke(gus, 1, 0xaa);
  371. #if 1
  372. if (snd_gf1_peek(gus, 0) == 0x55 && snd_gf1_peek(gus, 1) == 0xaa)
  373. #else
  374. if (0) /* ok.. for testing of 0k RAM */
  375. #endif
  376. {
  377. snd_interwave_bank_sizes(gus, psizes);
  378. lmct = (psizes[3] << 24) | (psizes[2] << 16) |
  379. (psizes[1] << 8) | psizes[0];
  380. #if 0
  381. printk(KERN_DEBUG "lmct = 0x%08x\n", lmct);
  382. #endif
  383. for (i = 0; i < ARRAY_SIZE(lmc); i++)
  384. if (lmct == lmc[i]) {
  385. #if 0
  386. printk(KERN_DEBUG "found !!! %i\n", i);
  387. #endif
  388. snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | i);
  389. snd_interwave_bank_sizes(gus, psizes);
  390. break;
  391. }
  392. if (i >= ARRAY_SIZE(lmc) && !gus->gf1.enh_mode)
  393. snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | 2);
  394. for (i = 0; i < 4; i++) {
  395. gus->gf1.mem_alloc.banks_8[i].address =
  396. gus->gf1.mem_alloc.banks_16[i].address = i << 22;
  397. gus->gf1.mem_alloc.banks_8[i].size =
  398. gus->gf1.mem_alloc.banks_16[i].size = psizes[i] << 18;
  399. pages += psizes[i];
  400. }
  401. }
  402. pages <<= 18;
  403. gus->gf1.memory = pages;
  404. snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x03); /* select ROM */
  405. snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xff1f) | (4 << 5));
  406. gus->gf1.rom_banks = 0;
  407. gus->gf1.rom_memory = 0;
  408. for (bank_pos = 0; bank_pos < 16L * 1024L * 1024L; bank_pos += 4L * 1024L * 1024L) {
  409. for (i = 0; i < 8; ++i)
  410. iwave[i] = snd_gf1_peek(gus, bank_pos + i);
  411. if (strncmp(iwave, "INTRWAVE", 8))
  412. continue; /* first check */
  413. csum = 0;
  414. for (i = 0; i < sizeof(struct rom_hdr); i++)
  415. csum += snd_gf1_peek(gus, bank_pos + i);
  416. if (csum != 0)
  417. continue; /* not valid rom */
  418. gus->gf1.rom_banks++;
  419. gus->gf1.rom_present |= 1 << (bank_pos >> 22);
  420. gus->gf1.rom_memory = snd_gf1_peek(gus, bank_pos + 40) |
  421. (snd_gf1_peek(gus, bank_pos + 41) << 8) |
  422. (snd_gf1_peek(gus, bank_pos + 42) << 16) |
  423. (snd_gf1_peek(gus, bank_pos + 43) << 24);
  424. }
  425. #if 0
  426. if (gus->gf1.rom_memory > 0) {
  427. if (gus->gf1.rom_banks == 1 && gus->gf1.rom_present == 8)
  428. gus->card->type = SNDRV_CARD_TYPE_IW_DYNASONIC;
  429. }
  430. #endif
  431. snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x00); /* select RAM */
  432. if (!gus->gf1.enh_mode)
  433. snd_interwave_reset(gus);
  434. }
  435. static void snd_interwave_init(int dev, struct snd_gus_card *gus)
  436. {
  437. unsigned long flags;
  438. /* ok.. some InterWave specific initialization */
  439. spin_lock_irqsave(&gus->reg_lock, flags);
  440. snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, 0x00);
  441. snd_gf1_write8(gus, SNDRV_GF1_GB_COMPATIBILITY, 0x1f);
  442. snd_gf1_write8(gus, SNDRV_GF1_GB_DECODE_CONTROL, 0x49);
  443. snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, 0x11);
  444. snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_A, 0x00);
  445. snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_B, 0x30);
  446. snd_gf1_write8(gus, SNDRV_GF1_GB_EMULATION_IRQ, 0x00);
  447. spin_unlock_irqrestore(&gus->reg_lock, flags);
  448. gus->equal_irq = 1;
  449. gus->codec_flag = 1;
  450. gus->interwave = 1;
  451. gus->max_flag = 1;
  452. gus->joystick_dac = joystick_dac[dev];
  453. }
  454. static struct snd_kcontrol_new snd_interwave_controls[] = {
  455. WSS_DOUBLE("Master Playback Switch", 0,
  456. CS4231_LINE_LEFT_OUTPUT, CS4231_LINE_RIGHT_OUTPUT, 7, 7, 1, 1),
  457. WSS_DOUBLE("Master Playback Volume", 0,
  458. CS4231_LINE_LEFT_OUTPUT, CS4231_LINE_RIGHT_OUTPUT, 0, 0, 31, 1),
  459. WSS_DOUBLE("Mic Playback Switch", 0,
  460. CS4231_LEFT_MIC_INPUT, CS4231_RIGHT_MIC_INPUT, 7, 7, 1, 1),
  461. WSS_DOUBLE("Mic Playback Volume", 0,
  462. CS4231_LEFT_MIC_INPUT, CS4231_RIGHT_MIC_INPUT, 0, 0, 31, 1)
  463. };
  464. static int snd_interwave_mixer(struct snd_wss *chip)
  465. {
  466. struct snd_card *card = chip->card;
  467. struct snd_ctl_elem_id id1, id2;
  468. unsigned int idx;
  469. int err;
  470. memset(&id1, 0, sizeof(id1));
  471. memset(&id2, 0, sizeof(id2));
  472. id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  473. #if 0
  474. /* remove mono microphone controls */
  475. strcpy(id1.name, "Mic Playback Switch");
  476. if ((err = snd_ctl_remove_id(card, &id1)) < 0)
  477. return err;
  478. strcpy(id1.name, "Mic Playback Volume");
  479. if ((err = snd_ctl_remove_id(card, &id1)) < 0)
  480. return err;
  481. #endif
  482. /* add new master and mic controls */
  483. for (idx = 0; idx < ARRAY_SIZE(snd_interwave_controls); idx++)
  484. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_interwave_controls[idx], chip))) < 0)
  485. return err;
  486. snd_wss_out(chip, CS4231_LINE_LEFT_OUTPUT, 0x9f);
  487. snd_wss_out(chip, CS4231_LINE_RIGHT_OUTPUT, 0x9f);
  488. snd_wss_out(chip, CS4231_LEFT_MIC_INPUT, 0x9f);
  489. snd_wss_out(chip, CS4231_RIGHT_MIC_INPUT, 0x9f);
  490. /* reassign AUXA to SYNTHESIZER */
  491. strcpy(id1.name, "Aux Playback Switch");
  492. strcpy(id2.name, "Synth Playback Switch");
  493. if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
  494. return err;
  495. strcpy(id1.name, "Aux Playback Volume");
  496. strcpy(id2.name, "Synth Playback Volume");
  497. if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
  498. return err;
  499. /* reassign AUXB to CD */
  500. strcpy(id1.name, "Aux Playback Switch"); id1.index = 1;
  501. strcpy(id2.name, "CD Playback Switch");
  502. if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
  503. return err;
  504. strcpy(id1.name, "Aux Playback Volume");
  505. strcpy(id2.name, "CD Playback Volume");
  506. if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
  507. return err;
  508. return 0;
  509. }
  510. #ifdef CONFIG_PNP
  511. static int snd_interwave_pnp(int dev, struct snd_interwave *iwcard,
  512. struct pnp_card_link *card,
  513. const struct pnp_card_device_id *id)
  514. {
  515. struct pnp_dev *pdev;
  516. int err;
  517. iwcard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
  518. if (iwcard->dev == NULL)
  519. return -EBUSY;
  520. #ifdef SNDRV_STB
  521. iwcard->devtc = pnp_request_card_device(card, id->devs[1].id, NULL);
  522. if (iwcard->devtc == NULL)
  523. return -EBUSY;
  524. #endif
  525. /* Synth & Codec initialization */
  526. pdev = iwcard->dev;
  527. err = pnp_activate_dev(pdev);
  528. if (err < 0) {
  529. snd_printk(KERN_ERR "InterWave PnP configure failure (out of resources?)\n");
  530. return err;
  531. }
  532. if (pnp_port_start(pdev, 0) + 0x100 != pnp_port_start(pdev, 1) ||
  533. pnp_port_start(pdev, 0) + 0x10c != pnp_port_start(pdev, 2)) {
  534. snd_printk(KERN_ERR "PnP configure failure (wrong ports)\n");
  535. return -ENOENT;
  536. }
  537. port[dev] = pnp_port_start(pdev, 0);
  538. dma1[dev] = pnp_dma(pdev, 0);
  539. if (dma2[dev] >= 0)
  540. dma2[dev] = pnp_dma(pdev, 1);
  541. irq[dev] = pnp_irq(pdev, 0);
  542. snd_printdd("isapnp IW: sb port=0x%llx, gf1 port=0x%llx, codec port=0x%llx\n",
  543. (unsigned long long)pnp_port_start(pdev, 0),
  544. (unsigned long long)pnp_port_start(pdev, 1),
  545. (unsigned long long)pnp_port_start(pdev, 2));
  546. snd_printdd("isapnp IW: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]);
  547. #ifdef SNDRV_STB
  548. /* Tone Control initialization */
  549. pdev = iwcard->devtc;
  550. err = pnp_activate_dev(pdev);
  551. if (err < 0) {
  552. snd_printk(KERN_ERR "InterWave ToneControl PnP configure failure (out of resources?)\n");
  553. return err;
  554. }
  555. port_tc[dev] = pnp_port_start(pdev, 0);
  556. snd_printdd("isapnp IW: tone control port=0x%lx\n", port_tc[dev]);
  557. #endif
  558. return 0;
  559. }
  560. #endif /* CONFIG_PNP */
  561. static void snd_interwave_free(struct snd_card *card)
  562. {
  563. struct snd_interwave *iwcard = card->private_data;
  564. if (iwcard == NULL)
  565. return;
  566. #ifdef SNDRV_STB
  567. release_and_free_resource(iwcard->i2c_res);
  568. #endif
  569. if (iwcard->irq >= 0)
  570. free_irq(iwcard->irq, (void *)iwcard);
  571. }
  572. static int snd_interwave_card_new(struct device *pdev, int dev,
  573. struct snd_card **cardp)
  574. {
  575. struct snd_card *card;
  576. struct snd_interwave *iwcard;
  577. int err;
  578. err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
  579. sizeof(struct snd_interwave), &card);
  580. if (err < 0)
  581. return err;
  582. iwcard = card->private_data;
  583. iwcard->card = card;
  584. iwcard->irq = -1;
  585. card->private_free = snd_interwave_free;
  586. *cardp = card;
  587. return 0;
  588. }
  589. static int snd_interwave_probe(struct snd_card *card, int dev)
  590. {
  591. int xirq, xdma1, xdma2;
  592. struct snd_interwave *iwcard = card->private_data;
  593. struct snd_wss *wss;
  594. struct snd_gus_card *gus;
  595. #ifdef SNDRV_STB
  596. struct snd_i2c_bus *i2c_bus;
  597. #endif
  598. char *str;
  599. int err;
  600. xirq = irq[dev];
  601. xdma1 = dma1[dev];
  602. xdma2 = dma2[dev];
  603. if ((err = snd_gus_create(card,
  604. port[dev],
  605. -xirq, xdma1, xdma2,
  606. 0, 32,
  607. pcm_channels[dev], effect[dev], &gus)) < 0)
  608. return err;
  609. if ((err = snd_interwave_detect(iwcard, gus, dev
  610. #ifdef SNDRV_STB
  611. , &i2c_bus
  612. #endif
  613. )) < 0)
  614. return err;
  615. iwcard->gus_status_reg = gus->gf1.reg_irqstat;
  616. iwcard->pcm_status_reg = gus->gf1.port + 0x10c + 2;
  617. snd_interwave_init(dev, gus);
  618. snd_interwave_detect_memory(gus);
  619. if ((err = snd_gus_initialize(gus)) < 0)
  620. return err;
  621. if (request_irq(xirq, snd_interwave_interrupt, 0,
  622. "InterWave", iwcard)) {
  623. snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq);
  624. return -EBUSY;
  625. }
  626. iwcard->irq = xirq;
  627. err = snd_wss_create(card,
  628. gus->gf1.port + 0x10c, -1, xirq,
  629. xdma2 < 0 ? xdma1 : xdma2, xdma1,
  630. WSS_HW_INTERWAVE,
  631. WSS_HWSHARE_IRQ |
  632. WSS_HWSHARE_DMA1 |
  633. WSS_HWSHARE_DMA2,
  634. &wss);
  635. if (err < 0)
  636. return err;
  637. err = snd_wss_pcm(wss, 0);
  638. if (err < 0)
  639. return err;
  640. sprintf(wss->pcm->name + strlen(wss->pcm->name), " rev %c",
  641. gus->revision + 'A');
  642. strcat(wss->pcm->name, " (codec)");
  643. err = snd_wss_timer(wss, 2);
  644. if (err < 0)
  645. return err;
  646. err = snd_wss_mixer(wss);
  647. if (err < 0)
  648. return err;
  649. if (pcm_channels[dev] > 0) {
  650. err = snd_gf1_pcm_new(gus, 1, 1);
  651. if (err < 0)
  652. return err;
  653. }
  654. err = snd_interwave_mixer(wss);
  655. if (err < 0)
  656. return err;
  657. #ifdef SNDRV_STB
  658. {
  659. struct snd_ctl_elem_id id1, id2;
  660. memset(&id1, 0, sizeof(id1));
  661. memset(&id2, 0, sizeof(id2));
  662. id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  663. strcpy(id1.name, "Master Playback Switch");
  664. strcpy(id2.name, id1.name);
  665. id2.index = 1;
  666. if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
  667. return err;
  668. strcpy(id1.name, "Master Playback Volume");
  669. strcpy(id2.name, id1.name);
  670. if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0)
  671. return err;
  672. if ((err = snd_tea6330t_update_mixer(card, i2c_bus, 0, 1)) < 0)
  673. return err;
  674. }
  675. #endif
  676. gus->uart_enable = midi[dev];
  677. if ((err = snd_gf1_rawmidi_new(gus, 0)) < 0)
  678. return err;
  679. #ifndef SNDRV_STB
  680. str = "AMD InterWave";
  681. if (gus->gf1.rom_banks == 1 && gus->gf1.rom_present == 8)
  682. str = "Dynasonic 3-D";
  683. #else
  684. str = "InterWave STB";
  685. #endif
  686. strcpy(card->driver, str);
  687. strcpy(card->shortname, str);
  688. sprintf(card->longname, "%s at 0x%lx, irq %i, dma %d",
  689. str,
  690. gus->gf1.port,
  691. xirq,
  692. xdma1);
  693. if (xdma2 >= 0)
  694. sprintf(card->longname + strlen(card->longname), "&%d", xdma2);
  695. err = snd_card_register(card);
  696. if (err < 0)
  697. return err;
  698. iwcard->wss = wss;
  699. iwcard->gus = gus;
  700. return 0;
  701. }
  702. static int snd_interwave_isa_probe1(int dev, struct device *devptr)
  703. {
  704. struct snd_card *card;
  705. int err;
  706. err = snd_interwave_card_new(devptr, dev, &card);
  707. if (err < 0)
  708. return err;
  709. if ((err = snd_interwave_probe(card, dev)) < 0) {
  710. snd_card_free(card);
  711. return err;
  712. }
  713. dev_set_drvdata(devptr, card);
  714. return 0;
  715. }
  716. static int snd_interwave_isa_match(struct device *pdev,
  717. unsigned int dev)
  718. {
  719. if (!enable[dev])
  720. return 0;
  721. #ifdef CONFIG_PNP
  722. if (isapnp[dev])
  723. return 0;
  724. #endif
  725. return 1;
  726. }
  727. static int snd_interwave_isa_probe(struct device *pdev,
  728. unsigned int dev)
  729. {
  730. int err;
  731. static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, -1};
  732. static int possible_dmas[] = {0, 1, 3, 5, 6, 7, -1};
  733. if (irq[dev] == SNDRV_AUTO_IRQ) {
  734. if ((irq[dev] = snd_legacy_find_free_irq(possible_irqs)) < 0) {
  735. snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
  736. return -EBUSY;
  737. }
  738. }
  739. if (dma1[dev] == SNDRV_AUTO_DMA) {
  740. if ((dma1[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) {
  741. snd_printk(KERN_ERR PFX "unable to find a free DMA1\n");
  742. return -EBUSY;
  743. }
  744. }
  745. if (dma2[dev] == SNDRV_AUTO_DMA) {
  746. if ((dma2[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) {
  747. snd_printk(KERN_ERR PFX "unable to find a free DMA2\n");
  748. return -EBUSY;
  749. }
  750. }
  751. if (port[dev] != SNDRV_AUTO_PORT)
  752. return snd_interwave_isa_probe1(dev, pdev);
  753. else {
  754. static long possible_ports[] = {0x210, 0x220, 0x230, 0x240, 0x250, 0x260};
  755. int i;
  756. for (i = 0; i < ARRAY_SIZE(possible_ports); i++) {
  757. port[dev] = possible_ports[i];
  758. err = snd_interwave_isa_probe1(dev, pdev);
  759. if (! err)
  760. return 0;
  761. }
  762. return err;
  763. }
  764. }
  765. static int snd_interwave_isa_remove(struct device *devptr, unsigned int dev)
  766. {
  767. snd_card_free(dev_get_drvdata(devptr));
  768. return 0;
  769. }
  770. static struct isa_driver snd_interwave_driver = {
  771. .match = snd_interwave_isa_match,
  772. .probe = snd_interwave_isa_probe,
  773. .remove = snd_interwave_isa_remove,
  774. /* FIXME: suspend,resume */
  775. .driver = {
  776. .name = INTERWAVE_DRIVER
  777. },
  778. };
  779. #ifdef CONFIG_PNP
  780. static int snd_interwave_pnp_detect(struct pnp_card_link *pcard,
  781. const struct pnp_card_device_id *pid)
  782. {
  783. static int dev;
  784. struct snd_card *card;
  785. int res;
  786. for ( ; dev < SNDRV_CARDS; dev++) {
  787. if (enable[dev] && isapnp[dev])
  788. break;
  789. }
  790. if (dev >= SNDRV_CARDS)
  791. return -ENODEV;
  792. res = snd_interwave_card_new(&pcard->card->dev, dev, &card);
  793. if (res < 0)
  794. return res;
  795. if ((res = snd_interwave_pnp(dev, card->private_data, pcard, pid)) < 0) {
  796. snd_card_free(card);
  797. return res;
  798. }
  799. if ((res = snd_interwave_probe(card, dev)) < 0) {
  800. snd_card_free(card);
  801. return res;
  802. }
  803. pnp_set_card_drvdata(pcard, card);
  804. dev++;
  805. return 0;
  806. }
  807. static void snd_interwave_pnp_remove(struct pnp_card_link *pcard)
  808. {
  809. snd_card_free(pnp_get_card_drvdata(pcard));
  810. pnp_set_card_drvdata(pcard, NULL);
  811. }
  812. static struct pnp_card_driver interwave_pnpc_driver = {
  813. .flags = PNP_DRIVER_RES_DISABLE,
  814. .name = INTERWAVE_PNP_DRIVER,
  815. .id_table = snd_interwave_pnpids,
  816. .probe = snd_interwave_pnp_detect,
  817. .remove = snd_interwave_pnp_remove,
  818. /* FIXME: suspend,resume */
  819. };
  820. #endif /* CONFIG_PNP */
  821. static int __init alsa_card_interwave_init(void)
  822. {
  823. int err;
  824. err = isa_register_driver(&snd_interwave_driver, SNDRV_CARDS);
  825. #ifdef CONFIG_PNP
  826. if (!err)
  827. isa_registered = 1;
  828. err = pnp_register_card_driver(&interwave_pnpc_driver);
  829. if (!err)
  830. pnp_registered = 1;
  831. if (isa_registered)
  832. err = 0;
  833. #endif
  834. return err;
  835. }
  836. static void __exit alsa_card_interwave_exit(void)
  837. {
  838. #ifdef CONFIG_PNP
  839. if (pnp_registered)
  840. pnp_unregister_card_driver(&interwave_pnpc_driver);
  841. if (isa_registered)
  842. #endif
  843. isa_unregister_driver(&snd_interwave_driver);
  844. }
  845. module_init(alsa_card_interwave_init)
  846. module_exit(alsa_card_interwave_exit)