interwave.c 27 KB

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