interwave.c 28 KB

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