nm256.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778
  1. /*
  2. * Driver for NeoMagic 256AV and 256ZX chipsets.
  3. * Copyright (c) 2000 by Takashi Iwai <tiwai@suse.de>
  4. *
  5. * Based on nm256_audio.c OSS driver in linux kernel.
  6. * The original author of OSS nm256 driver wishes to remain anonymous,
  7. * so I just put my acknoledgment to him/her here.
  8. * The original author's web page is found at
  9. * http://www.uglx.org/sony.html
  10. *
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. */
  26. #include <sound/driver.h>
  27. #include <asm/io.h>
  28. #include <linux/delay.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/init.h>
  31. #include <linux/pci.h>
  32. #include <linux/slab.h>
  33. #include <linux/moduleparam.h>
  34. #include <linux/mutex.h>
  35. #include <sound/core.h>
  36. #include <sound/info.h>
  37. #include <sound/control.h>
  38. #include <sound/pcm.h>
  39. #include <sound/ac97_codec.h>
  40. #include <sound/initval.h>
  41. #define CARD_NAME "NeoMagic 256AV/ZX"
  42. #define DRIVER_NAME "NM256"
  43. MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
  44. MODULE_DESCRIPTION("NeoMagic NM256AV/ZX");
  45. MODULE_LICENSE("GPL");
  46. MODULE_SUPPORTED_DEVICE("{{NeoMagic,NM256AV},"
  47. "{NeoMagic,NM256ZX}}");
  48. /*
  49. * some compile conditions.
  50. */
  51. static int index = SNDRV_DEFAULT_IDX1; /* Index */
  52. static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
  53. static int playback_bufsize = 16;
  54. static int capture_bufsize = 16;
  55. static int force_ac97; /* disabled as default */
  56. static int buffer_top; /* not specified */
  57. static int use_cache; /* disabled */
  58. static int vaio_hack; /* disabled */
  59. static int reset_workaround;
  60. static int reset_workaround_2;
  61. module_param(index, int, 0444);
  62. MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");
  63. module_param(id, charp, 0444);
  64. MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard.");
  65. module_param(playback_bufsize, int, 0444);
  66. MODULE_PARM_DESC(playback_bufsize, "DAC frame size in kB for " CARD_NAME " soundcard.");
  67. module_param(capture_bufsize, int, 0444);
  68. MODULE_PARM_DESC(capture_bufsize, "ADC frame size in kB for " CARD_NAME " soundcard.");
  69. module_param(force_ac97, bool, 0444);
  70. MODULE_PARM_DESC(force_ac97, "Force to use AC97 codec for " CARD_NAME " soundcard.");
  71. module_param(buffer_top, int, 0444);
  72. MODULE_PARM_DESC(buffer_top, "Set the top address of audio buffer for " CARD_NAME " soundcard.");
  73. module_param(use_cache, bool, 0444);
  74. MODULE_PARM_DESC(use_cache, "Enable the cache for coefficient table access.");
  75. module_param(vaio_hack, bool, 0444);
  76. MODULE_PARM_DESC(vaio_hack, "Enable workaround for Sony VAIO notebooks.");
  77. module_param(reset_workaround, bool, 0444);
  78. MODULE_PARM_DESC(reset_workaround, "Enable AC97 RESET workaround for some laptops.");
  79. module_param(reset_workaround_2, bool, 0444);
  80. MODULE_PARM_DESC(reset_workaround_2, "Enable extended AC97 RESET workaround for some other laptops.");
  81. /* just for backward compatibility */
  82. static int enable;
  83. module_param(enable, bool, 0444);
  84. /*
  85. * hw definitions
  86. */
  87. /* The BIOS signature. */
  88. #define NM_SIGNATURE 0x4e4d0000
  89. /* Signature mask. */
  90. #define NM_SIG_MASK 0xffff0000
  91. /* Size of the second memory area. */
  92. #define NM_PORT2_SIZE 4096
  93. /* The base offset of the mixer in the second memory area. */
  94. #define NM_MIXER_OFFSET 0x600
  95. /* The maximum size of a coefficient entry. */
  96. #define NM_MAX_PLAYBACK_COEF_SIZE 0x5000
  97. #define NM_MAX_RECORD_COEF_SIZE 0x1260
  98. /* The interrupt register. */
  99. #define NM_INT_REG 0xa04
  100. /* And its bits. */
  101. #define NM_PLAYBACK_INT 0x40
  102. #define NM_RECORD_INT 0x100
  103. #define NM_MISC_INT_1 0x4000
  104. #define NM_MISC_INT_2 0x1
  105. #define NM_ACK_INT(chip, X) snd_nm256_writew(chip, NM_INT_REG, (X) << 1)
  106. /* The AV's "mixer ready" status bit and location. */
  107. #define NM_MIXER_STATUS_OFFSET 0xa04
  108. #define NM_MIXER_READY_MASK 0x0800
  109. #define NM_MIXER_PRESENCE 0xa06
  110. #define NM_PRESENCE_MASK 0x0050
  111. #define NM_PRESENCE_VALUE 0x0040
  112. /*
  113. * For the ZX. It uses the same interrupt register, but it holds 32
  114. * bits instead of 16.
  115. */
  116. #define NM2_PLAYBACK_INT 0x10000
  117. #define NM2_RECORD_INT 0x80000
  118. #define NM2_MISC_INT_1 0x8
  119. #define NM2_MISC_INT_2 0x2
  120. #define NM2_ACK_INT(chip, X) snd_nm256_writel(chip, NM_INT_REG, (X))
  121. /* The ZX's "mixer ready" status bit and location. */
  122. #define NM2_MIXER_STATUS_OFFSET 0xa06
  123. #define NM2_MIXER_READY_MASK 0x0800
  124. /* The playback registers start from here. */
  125. #define NM_PLAYBACK_REG_OFFSET 0x0
  126. /* The record registers start from here. */
  127. #define NM_RECORD_REG_OFFSET 0x200
  128. /* The rate register is located 2 bytes from the start of the register area. */
  129. #define NM_RATE_REG_OFFSET 2
  130. /* Mono/stereo flag, number of bits on playback, and rate mask. */
  131. #define NM_RATE_STEREO 1
  132. #define NM_RATE_BITS_16 2
  133. #define NM_RATE_MASK 0xf0
  134. /* Playback enable register. */
  135. #define NM_PLAYBACK_ENABLE_REG (NM_PLAYBACK_REG_OFFSET + 0x1)
  136. #define NM_PLAYBACK_ENABLE_FLAG 1
  137. #define NM_PLAYBACK_ONESHOT 2
  138. #define NM_PLAYBACK_FREERUN 4
  139. /* Mutes the audio output. */
  140. #define NM_AUDIO_MUTE_REG (NM_PLAYBACK_REG_OFFSET + 0x18)
  141. #define NM_AUDIO_MUTE_LEFT 0x8000
  142. #define NM_AUDIO_MUTE_RIGHT 0x0080
  143. /* Recording enable register. */
  144. #define NM_RECORD_ENABLE_REG (NM_RECORD_REG_OFFSET + 0)
  145. #define NM_RECORD_ENABLE_FLAG 1
  146. #define NM_RECORD_FREERUN 2
  147. /* coefficient buffer pointer */
  148. #define NM_COEFF_START_OFFSET 0x1c
  149. #define NM_COEFF_END_OFFSET 0x20
  150. /* DMA buffer offsets */
  151. #define NM_RBUFFER_START (NM_RECORD_REG_OFFSET + 0x4)
  152. #define NM_RBUFFER_END (NM_RECORD_REG_OFFSET + 0x10)
  153. #define NM_RBUFFER_WMARK (NM_RECORD_REG_OFFSET + 0xc)
  154. #define NM_RBUFFER_CURRP (NM_RECORD_REG_OFFSET + 0x8)
  155. #define NM_PBUFFER_START (NM_PLAYBACK_REG_OFFSET + 0x4)
  156. #define NM_PBUFFER_END (NM_PLAYBACK_REG_OFFSET + 0x14)
  157. #define NM_PBUFFER_WMARK (NM_PLAYBACK_REG_OFFSET + 0xc)
  158. #define NM_PBUFFER_CURRP (NM_PLAYBACK_REG_OFFSET + 0x8)
  159. struct nm256_stream {
  160. struct nm256 *chip;
  161. struct snd_pcm_substream *substream;
  162. int running;
  163. int suspended;
  164. u32 buf; /* offset from chip->buffer */
  165. int bufsize; /* buffer size in bytes */
  166. void __iomem *bufptr; /* mapped pointer */
  167. unsigned long bufptr_addr; /* physical address of the mapped pointer */
  168. int dma_size; /* buffer size of the substream in bytes */
  169. int period_size; /* period size in bytes */
  170. int periods; /* # of periods */
  171. int shift; /* bit shifts */
  172. int cur_period; /* current period # */
  173. };
  174. struct nm256 {
  175. struct snd_card *card;
  176. void __iomem *cport; /* control port */
  177. struct resource *res_cport; /* its resource */
  178. unsigned long cport_addr; /* physical address */
  179. void __iomem *buffer; /* buffer */
  180. struct resource *res_buffer; /* its resource */
  181. unsigned long buffer_addr; /* buffer phyiscal address */
  182. u32 buffer_start; /* start offset from pci resource 0 */
  183. u32 buffer_end; /* end offset */
  184. u32 buffer_size; /* total buffer size */
  185. u32 all_coeff_buf; /* coefficient buffer */
  186. u32 coeff_buf[2]; /* coefficient buffer for each stream */
  187. unsigned int coeffs_current: 1; /* coeff. table is loaded? */
  188. unsigned int use_cache: 1; /* use one big coef. table */
  189. unsigned int reset_workaround: 1; /* Workaround for some laptops to avoid freeze */
  190. unsigned int reset_workaround_2: 1; /* Extended workaround for some other laptops to avoid freeze */
  191. unsigned int in_resume: 1;
  192. int mixer_base; /* register offset of ac97 mixer */
  193. int mixer_status_offset; /* offset of mixer status reg. */
  194. int mixer_status_mask; /* bit mask to test the mixer status */
  195. int irq;
  196. int irq_acks;
  197. irq_handler_t interrupt;
  198. int badintrcount; /* counter to check bogus interrupts */
  199. struct mutex irq_mutex;
  200. struct nm256_stream streams[2];
  201. struct snd_ac97 *ac97;
  202. unsigned short *ac97_regs; /* register caches, only for valid regs */
  203. struct snd_pcm *pcm;
  204. struct pci_dev *pci;
  205. spinlock_t reg_lock;
  206. };
  207. /*
  208. * include coefficient table
  209. */
  210. #include "nm256_coef.c"
  211. /*
  212. * PCI ids
  213. */
  214. static struct pci_device_id snd_nm256_ids[] = {
  215. {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  216. {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  217. {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  218. {0,},
  219. };
  220. MODULE_DEVICE_TABLE(pci, snd_nm256_ids);
  221. /*
  222. * lowlvel stuffs
  223. */
  224. static inline u8
  225. snd_nm256_readb(struct nm256 *chip, int offset)
  226. {
  227. return readb(chip->cport + offset);
  228. }
  229. static inline u16
  230. snd_nm256_readw(struct nm256 *chip, int offset)
  231. {
  232. return readw(chip->cport + offset);
  233. }
  234. static inline u32
  235. snd_nm256_readl(struct nm256 *chip, int offset)
  236. {
  237. return readl(chip->cport + offset);
  238. }
  239. static inline void
  240. snd_nm256_writeb(struct nm256 *chip, int offset, u8 val)
  241. {
  242. writeb(val, chip->cport + offset);
  243. }
  244. static inline void
  245. snd_nm256_writew(struct nm256 *chip, int offset, u16 val)
  246. {
  247. writew(val, chip->cport + offset);
  248. }
  249. static inline void
  250. snd_nm256_writel(struct nm256 *chip, int offset, u32 val)
  251. {
  252. writel(val, chip->cport + offset);
  253. }
  254. static inline void
  255. snd_nm256_write_buffer(struct nm256 *chip, void *src, int offset, int size)
  256. {
  257. offset -= chip->buffer_start;
  258. #ifdef CONFIG_SND_DEBUG
  259. if (offset < 0 || offset >= chip->buffer_size) {
  260. snd_printk(KERN_ERR "write_buffer invalid offset = %d size = %d\n",
  261. offset, size);
  262. return;
  263. }
  264. #endif
  265. memcpy_toio(chip->buffer + offset, src, size);
  266. }
  267. /*
  268. * coefficient handlers -- what a magic!
  269. */
  270. static u16
  271. snd_nm256_get_start_offset(int which)
  272. {
  273. u16 offset = 0;
  274. while (which-- > 0)
  275. offset += coefficient_sizes[which];
  276. return offset;
  277. }
  278. static void
  279. snd_nm256_load_one_coefficient(struct nm256 *chip, int stream, u32 port, int which)
  280. {
  281. u32 coeff_buf = chip->coeff_buf[stream];
  282. u16 offset = snd_nm256_get_start_offset(which);
  283. u16 size = coefficient_sizes[which];
  284. snd_nm256_write_buffer(chip, coefficients + offset, coeff_buf, size);
  285. snd_nm256_writel(chip, port, coeff_buf);
  286. /* ??? Record seems to behave differently than playback. */
  287. if (stream == SNDRV_PCM_STREAM_PLAYBACK)
  288. size--;
  289. snd_nm256_writel(chip, port + 4, coeff_buf + size);
  290. }
  291. static void
  292. snd_nm256_load_coefficient(struct nm256 *chip, int stream, int number)
  293. {
  294. /* The enable register for the specified engine. */
  295. u32 poffset = (stream == SNDRV_PCM_STREAM_CAPTURE ?
  296. NM_RECORD_ENABLE_REG : NM_PLAYBACK_ENABLE_REG);
  297. u32 addr = NM_COEFF_START_OFFSET;
  298. addr += (stream == SNDRV_PCM_STREAM_CAPTURE ?
  299. NM_RECORD_REG_OFFSET : NM_PLAYBACK_REG_OFFSET);
  300. if (snd_nm256_readb(chip, poffset) & 1) {
  301. snd_printd("NM256: Engine was enabled while loading coefficients!\n");
  302. return;
  303. }
  304. /* The recording engine uses coefficient values 8-15. */
  305. number &= 7;
  306. if (stream == SNDRV_PCM_STREAM_CAPTURE)
  307. number += 8;
  308. if (! chip->use_cache) {
  309. snd_nm256_load_one_coefficient(chip, stream, addr, number);
  310. return;
  311. }
  312. if (! chip->coeffs_current) {
  313. snd_nm256_write_buffer(chip, coefficients, chip->all_coeff_buf,
  314. NM_TOTAL_COEFF_COUNT * 4);
  315. chip->coeffs_current = 1;
  316. } else {
  317. u32 base = chip->all_coeff_buf;
  318. u32 offset = snd_nm256_get_start_offset(number);
  319. u32 end_offset = offset + coefficient_sizes[number];
  320. snd_nm256_writel(chip, addr, base + offset);
  321. if (stream == SNDRV_PCM_STREAM_PLAYBACK)
  322. end_offset--;
  323. snd_nm256_writel(chip, addr + 4, base + end_offset);
  324. }
  325. }
  326. /* The actual rates supported by the card. */
  327. static unsigned int samplerates[8] = {
  328. 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000,
  329. };
  330. static struct snd_pcm_hw_constraint_list constraints_rates = {
  331. .count = ARRAY_SIZE(samplerates),
  332. .list = samplerates,
  333. .mask = 0,
  334. };
  335. /*
  336. * return the index of the target rate
  337. */
  338. static int
  339. snd_nm256_fixed_rate(unsigned int rate)
  340. {
  341. unsigned int i;
  342. for (i = 0; i < ARRAY_SIZE(samplerates); i++) {
  343. if (rate == samplerates[i])
  344. return i;
  345. }
  346. snd_BUG();
  347. return 0;
  348. }
  349. /*
  350. * set sample rate and format
  351. */
  352. static void
  353. snd_nm256_set_format(struct nm256 *chip, struct nm256_stream *s,
  354. struct snd_pcm_substream *substream)
  355. {
  356. struct snd_pcm_runtime *runtime = substream->runtime;
  357. int rate_index = snd_nm256_fixed_rate(runtime->rate);
  358. unsigned char ratebits = (rate_index << 4) & NM_RATE_MASK;
  359. s->shift = 0;
  360. if (snd_pcm_format_width(runtime->format) == 16) {
  361. ratebits |= NM_RATE_BITS_16;
  362. s->shift++;
  363. }
  364. if (runtime->channels > 1) {
  365. ratebits |= NM_RATE_STEREO;
  366. s->shift++;
  367. }
  368. runtime->rate = samplerates[rate_index];
  369. switch (substream->stream) {
  370. case SNDRV_PCM_STREAM_PLAYBACK:
  371. snd_nm256_load_coefficient(chip, 0, rate_index); /* 0 = playback */
  372. snd_nm256_writeb(chip,
  373. NM_PLAYBACK_REG_OFFSET + NM_RATE_REG_OFFSET,
  374. ratebits);
  375. break;
  376. case SNDRV_PCM_STREAM_CAPTURE:
  377. snd_nm256_load_coefficient(chip, 1, rate_index); /* 1 = record */
  378. snd_nm256_writeb(chip,
  379. NM_RECORD_REG_OFFSET + NM_RATE_REG_OFFSET,
  380. ratebits);
  381. break;
  382. }
  383. }
  384. /* acquire interrupt */
  385. static int snd_nm256_acquire_irq(struct nm256 *chip)
  386. {
  387. mutex_lock(&chip->irq_mutex);
  388. if (chip->irq < 0) {
  389. if (request_irq(chip->pci->irq, chip->interrupt, IRQF_DISABLED|IRQF_SHARED,
  390. chip->card->driver, chip)) {
  391. snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->pci->irq);
  392. mutex_unlock(&chip->irq_mutex);
  393. return -EBUSY;
  394. }
  395. chip->irq = chip->pci->irq;
  396. }
  397. chip->irq_acks++;
  398. mutex_unlock(&chip->irq_mutex);
  399. return 0;
  400. }
  401. /* release interrupt */
  402. static void snd_nm256_release_irq(struct nm256 *chip)
  403. {
  404. mutex_lock(&chip->irq_mutex);
  405. if (chip->irq_acks > 0)
  406. chip->irq_acks--;
  407. if (chip->irq_acks == 0 && chip->irq >= 0) {
  408. free_irq(chip->irq, chip);
  409. chip->irq = -1;
  410. }
  411. mutex_unlock(&chip->irq_mutex);
  412. }
  413. /*
  414. * start / stop
  415. */
  416. /* update the watermark (current period) */
  417. static void snd_nm256_pcm_mark(struct nm256 *chip, struct nm256_stream *s, int reg)
  418. {
  419. s->cur_period++;
  420. s->cur_period %= s->periods;
  421. snd_nm256_writel(chip, reg, s->buf + s->cur_period * s->period_size);
  422. }
  423. #define snd_nm256_playback_mark(chip, s) snd_nm256_pcm_mark(chip, s, NM_PBUFFER_WMARK)
  424. #define snd_nm256_capture_mark(chip, s) snd_nm256_pcm_mark(chip, s, NM_RBUFFER_WMARK)
  425. static void
  426. snd_nm256_playback_start(struct nm256 *chip, struct nm256_stream *s,
  427. struct snd_pcm_substream *substream)
  428. {
  429. /* program buffer pointers */
  430. snd_nm256_writel(chip, NM_PBUFFER_START, s->buf);
  431. snd_nm256_writel(chip, NM_PBUFFER_END, s->buf + s->dma_size - (1 << s->shift));
  432. snd_nm256_writel(chip, NM_PBUFFER_CURRP, s->buf);
  433. snd_nm256_playback_mark(chip, s);
  434. /* Enable playback engine and interrupts. */
  435. snd_nm256_writeb(chip, NM_PLAYBACK_ENABLE_REG,
  436. NM_PLAYBACK_ENABLE_FLAG | NM_PLAYBACK_FREERUN);
  437. /* Enable both channels. */
  438. snd_nm256_writew(chip, NM_AUDIO_MUTE_REG, 0x0);
  439. }
  440. static void
  441. snd_nm256_capture_start(struct nm256 *chip, struct nm256_stream *s,
  442. struct snd_pcm_substream *substream)
  443. {
  444. /* program buffer pointers */
  445. snd_nm256_writel(chip, NM_RBUFFER_START, s->buf);
  446. snd_nm256_writel(chip, NM_RBUFFER_END, s->buf + s->dma_size);
  447. snd_nm256_writel(chip, NM_RBUFFER_CURRP, s->buf);
  448. snd_nm256_capture_mark(chip, s);
  449. /* Enable playback engine and interrupts. */
  450. snd_nm256_writeb(chip, NM_RECORD_ENABLE_REG,
  451. NM_RECORD_ENABLE_FLAG | NM_RECORD_FREERUN);
  452. }
  453. /* Stop the play engine. */
  454. static void
  455. snd_nm256_playback_stop(struct nm256 *chip)
  456. {
  457. /* Shut off sound from both channels. */
  458. snd_nm256_writew(chip, NM_AUDIO_MUTE_REG,
  459. NM_AUDIO_MUTE_LEFT | NM_AUDIO_MUTE_RIGHT);
  460. /* Disable play engine. */
  461. snd_nm256_writeb(chip, NM_PLAYBACK_ENABLE_REG, 0);
  462. }
  463. static void
  464. snd_nm256_capture_stop(struct nm256 *chip)
  465. {
  466. /* Disable recording engine. */
  467. snd_nm256_writeb(chip, NM_RECORD_ENABLE_REG, 0);
  468. }
  469. static int
  470. snd_nm256_playback_trigger(struct snd_pcm_substream *substream, int cmd)
  471. {
  472. struct nm256 *chip = snd_pcm_substream_chip(substream);
  473. struct nm256_stream *s = substream->runtime->private_data;
  474. int err = 0;
  475. snd_assert(s != NULL, return -ENXIO);
  476. spin_lock(&chip->reg_lock);
  477. switch (cmd) {
  478. case SNDRV_PCM_TRIGGER_RESUME:
  479. s->suspended = 0;
  480. /* fallthru */
  481. case SNDRV_PCM_TRIGGER_START:
  482. if (! s->running) {
  483. snd_nm256_playback_start(chip, s, substream);
  484. s->running = 1;
  485. }
  486. break;
  487. case SNDRV_PCM_TRIGGER_SUSPEND:
  488. s->suspended = 1;
  489. /* fallthru */
  490. case SNDRV_PCM_TRIGGER_STOP:
  491. if (s->running) {
  492. snd_nm256_playback_stop(chip);
  493. s->running = 0;
  494. }
  495. break;
  496. default:
  497. err = -EINVAL;
  498. break;
  499. }
  500. spin_unlock(&chip->reg_lock);
  501. return err;
  502. }
  503. static int
  504. snd_nm256_capture_trigger(struct snd_pcm_substream *substream, int cmd)
  505. {
  506. struct nm256 *chip = snd_pcm_substream_chip(substream);
  507. struct nm256_stream *s = substream->runtime->private_data;
  508. int err = 0;
  509. snd_assert(s != NULL, return -ENXIO);
  510. spin_lock(&chip->reg_lock);
  511. switch (cmd) {
  512. case SNDRV_PCM_TRIGGER_START:
  513. case SNDRV_PCM_TRIGGER_RESUME:
  514. if (! s->running) {
  515. snd_nm256_capture_start(chip, s, substream);
  516. s->running = 1;
  517. }
  518. break;
  519. case SNDRV_PCM_TRIGGER_STOP:
  520. case SNDRV_PCM_TRIGGER_SUSPEND:
  521. if (s->running) {
  522. snd_nm256_capture_stop(chip);
  523. s->running = 0;
  524. }
  525. break;
  526. default:
  527. err = -EINVAL;
  528. break;
  529. }
  530. spin_unlock(&chip->reg_lock);
  531. return err;
  532. }
  533. /*
  534. * prepare playback/capture channel
  535. */
  536. static int snd_nm256_pcm_prepare(struct snd_pcm_substream *substream)
  537. {
  538. struct nm256 *chip = snd_pcm_substream_chip(substream);
  539. struct snd_pcm_runtime *runtime = substream->runtime;
  540. struct nm256_stream *s = runtime->private_data;
  541. snd_assert(s, return -ENXIO);
  542. s->dma_size = frames_to_bytes(runtime, substream->runtime->buffer_size);
  543. s->period_size = frames_to_bytes(runtime, substream->runtime->period_size);
  544. s->periods = substream->runtime->periods;
  545. s->cur_period = 0;
  546. spin_lock_irq(&chip->reg_lock);
  547. s->running = 0;
  548. snd_nm256_set_format(chip, s, substream);
  549. spin_unlock_irq(&chip->reg_lock);
  550. return 0;
  551. }
  552. /*
  553. * get the current pointer
  554. */
  555. static snd_pcm_uframes_t
  556. snd_nm256_playback_pointer(struct snd_pcm_substream *substream)
  557. {
  558. struct nm256 *chip = snd_pcm_substream_chip(substream);
  559. struct nm256_stream *s = substream->runtime->private_data;
  560. unsigned long curp;
  561. snd_assert(s, return 0);
  562. curp = snd_nm256_readl(chip, NM_PBUFFER_CURRP) - (unsigned long)s->buf;
  563. curp %= s->dma_size;
  564. return bytes_to_frames(substream->runtime, curp);
  565. }
  566. static snd_pcm_uframes_t
  567. snd_nm256_capture_pointer(struct snd_pcm_substream *substream)
  568. {
  569. struct nm256 *chip = snd_pcm_substream_chip(substream);
  570. struct nm256_stream *s = substream->runtime->private_data;
  571. unsigned long curp;
  572. snd_assert(s != NULL, return 0);
  573. curp = snd_nm256_readl(chip, NM_RBUFFER_CURRP) - (unsigned long)s->buf;
  574. curp %= s->dma_size;
  575. return bytes_to_frames(substream->runtime, curp);
  576. }
  577. /* Remapped I/O space can be accessible as pointer on i386 */
  578. /* This might be changed in the future */
  579. #ifndef __i386__
  580. /*
  581. * silence / copy for playback
  582. */
  583. static int
  584. snd_nm256_playback_silence(struct snd_pcm_substream *substream,
  585. int channel, /* not used (interleaved data) */
  586. snd_pcm_uframes_t pos,
  587. snd_pcm_uframes_t count)
  588. {
  589. struct snd_pcm_runtime *runtime = substream->runtime;
  590. struct nm256_stream *s = runtime->private_data;
  591. count = frames_to_bytes(runtime, count);
  592. pos = frames_to_bytes(runtime, pos);
  593. memset_io(s->bufptr + pos, 0, count);
  594. return 0;
  595. }
  596. static int
  597. snd_nm256_playback_copy(struct snd_pcm_substream *substream,
  598. int channel, /* not used (interleaved data) */
  599. snd_pcm_uframes_t pos,
  600. void __user *src,
  601. snd_pcm_uframes_t count)
  602. {
  603. struct snd_pcm_runtime *runtime = substream->runtime;
  604. struct nm256_stream *s = runtime->private_data;
  605. count = frames_to_bytes(runtime, count);
  606. pos = frames_to_bytes(runtime, pos);
  607. if (copy_from_user_toio(s->bufptr + pos, src, count))
  608. return -EFAULT;
  609. return 0;
  610. }
  611. /*
  612. * copy to user
  613. */
  614. static int
  615. snd_nm256_capture_copy(struct snd_pcm_substream *substream,
  616. int channel, /* not used (interleaved data) */
  617. snd_pcm_uframes_t pos,
  618. void __user *dst,
  619. snd_pcm_uframes_t count)
  620. {
  621. struct snd_pcm_runtime *runtime = substream->runtime;
  622. struct nm256_stream *s = runtime->private_data;
  623. count = frames_to_bytes(runtime, count);
  624. pos = frames_to_bytes(runtime, pos);
  625. if (copy_to_user_fromio(dst, s->bufptr + pos, count))
  626. return -EFAULT;
  627. return 0;
  628. }
  629. #endif /* !__i386__ */
  630. /*
  631. * update playback/capture watermarks
  632. */
  633. /* spinlock held! */
  634. static void
  635. snd_nm256_playback_update(struct nm256 *chip)
  636. {
  637. struct nm256_stream *s;
  638. s = &chip->streams[SNDRV_PCM_STREAM_PLAYBACK];
  639. if (s->running && s->substream) {
  640. spin_unlock(&chip->reg_lock);
  641. snd_pcm_period_elapsed(s->substream);
  642. spin_lock(&chip->reg_lock);
  643. snd_nm256_playback_mark(chip, s);
  644. }
  645. }
  646. /* spinlock held! */
  647. static void
  648. snd_nm256_capture_update(struct nm256 *chip)
  649. {
  650. struct nm256_stream *s;
  651. s = &chip->streams[SNDRV_PCM_STREAM_CAPTURE];
  652. if (s->running && s->substream) {
  653. spin_unlock(&chip->reg_lock);
  654. snd_pcm_period_elapsed(s->substream);
  655. spin_lock(&chip->reg_lock);
  656. snd_nm256_capture_mark(chip, s);
  657. }
  658. }
  659. /*
  660. * hardware info
  661. */
  662. static struct snd_pcm_hardware snd_nm256_playback =
  663. {
  664. .info = SNDRV_PCM_INFO_MMAP_IOMEM |SNDRV_PCM_INFO_MMAP_VALID |
  665. SNDRV_PCM_INFO_INTERLEAVED |
  666. /*SNDRV_PCM_INFO_PAUSE |*/
  667. SNDRV_PCM_INFO_RESUME,
  668. .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  669. .rates = SNDRV_PCM_RATE_KNOT/*24k*/ | SNDRV_PCM_RATE_8000_48000,
  670. .rate_min = 8000,
  671. .rate_max = 48000,
  672. .channels_min = 1,
  673. .channels_max = 2,
  674. .periods_min = 2,
  675. .periods_max = 1024,
  676. .buffer_bytes_max = 128 * 1024,
  677. .period_bytes_min = 256,
  678. .period_bytes_max = 128 * 1024,
  679. };
  680. static struct snd_pcm_hardware snd_nm256_capture =
  681. {
  682. .info = SNDRV_PCM_INFO_MMAP_IOMEM | SNDRV_PCM_INFO_MMAP_VALID |
  683. SNDRV_PCM_INFO_INTERLEAVED |
  684. /*SNDRV_PCM_INFO_PAUSE |*/
  685. SNDRV_PCM_INFO_RESUME,
  686. .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  687. .rates = SNDRV_PCM_RATE_KNOT/*24k*/ | SNDRV_PCM_RATE_8000_48000,
  688. .rate_min = 8000,
  689. .rate_max = 48000,
  690. .channels_min = 1,
  691. .channels_max = 2,
  692. .periods_min = 2,
  693. .periods_max = 1024,
  694. .buffer_bytes_max = 128 * 1024,
  695. .period_bytes_min = 256,
  696. .period_bytes_max = 128 * 1024,
  697. };
  698. /* set dma transfer size */
  699. static int snd_nm256_pcm_hw_params(struct snd_pcm_substream *substream,
  700. struct snd_pcm_hw_params *hw_params)
  701. {
  702. /* area and addr are already set and unchanged */
  703. substream->runtime->dma_bytes = params_buffer_bytes(hw_params);
  704. return 0;
  705. }
  706. /*
  707. * open
  708. */
  709. static void snd_nm256_setup_stream(struct nm256 *chip, struct nm256_stream *s,
  710. struct snd_pcm_substream *substream,
  711. struct snd_pcm_hardware *hw_ptr)
  712. {
  713. struct snd_pcm_runtime *runtime = substream->runtime;
  714. s->running = 0;
  715. runtime->hw = *hw_ptr;
  716. runtime->hw.buffer_bytes_max = s->bufsize;
  717. runtime->hw.period_bytes_max = s->bufsize / 2;
  718. runtime->dma_area = (void __force *) s->bufptr;
  719. runtime->dma_addr = s->bufptr_addr;
  720. runtime->dma_bytes = s->bufsize;
  721. runtime->private_data = s;
  722. s->substream = substream;
  723. snd_pcm_set_sync(substream);
  724. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  725. &constraints_rates);
  726. }
  727. static int
  728. snd_nm256_playback_open(struct snd_pcm_substream *substream)
  729. {
  730. struct nm256 *chip = snd_pcm_substream_chip(substream);
  731. if (snd_nm256_acquire_irq(chip) < 0)
  732. return -EBUSY;
  733. snd_nm256_setup_stream(chip, &chip->streams[SNDRV_PCM_STREAM_PLAYBACK],
  734. substream, &snd_nm256_playback);
  735. return 0;
  736. }
  737. static int
  738. snd_nm256_capture_open(struct snd_pcm_substream *substream)
  739. {
  740. struct nm256 *chip = snd_pcm_substream_chip(substream);
  741. if (snd_nm256_acquire_irq(chip) < 0)
  742. return -EBUSY;
  743. snd_nm256_setup_stream(chip, &chip->streams[SNDRV_PCM_STREAM_CAPTURE],
  744. substream, &snd_nm256_capture);
  745. return 0;
  746. }
  747. /*
  748. * close - we don't have to do special..
  749. */
  750. static int
  751. snd_nm256_playback_close(struct snd_pcm_substream *substream)
  752. {
  753. struct nm256 *chip = snd_pcm_substream_chip(substream);
  754. snd_nm256_release_irq(chip);
  755. return 0;
  756. }
  757. static int
  758. snd_nm256_capture_close(struct snd_pcm_substream *substream)
  759. {
  760. struct nm256 *chip = snd_pcm_substream_chip(substream);
  761. snd_nm256_release_irq(chip);
  762. return 0;
  763. }
  764. /*
  765. * create a pcm instance
  766. */
  767. static struct snd_pcm_ops snd_nm256_playback_ops = {
  768. .open = snd_nm256_playback_open,
  769. .close = snd_nm256_playback_close,
  770. .ioctl = snd_pcm_lib_ioctl,
  771. .hw_params = snd_nm256_pcm_hw_params,
  772. .prepare = snd_nm256_pcm_prepare,
  773. .trigger = snd_nm256_playback_trigger,
  774. .pointer = snd_nm256_playback_pointer,
  775. #ifndef __i386__
  776. .copy = snd_nm256_playback_copy,
  777. .silence = snd_nm256_playback_silence,
  778. #endif
  779. .mmap = snd_pcm_lib_mmap_iomem,
  780. };
  781. static struct snd_pcm_ops snd_nm256_capture_ops = {
  782. .open = snd_nm256_capture_open,
  783. .close = snd_nm256_capture_close,
  784. .ioctl = snd_pcm_lib_ioctl,
  785. .hw_params = snd_nm256_pcm_hw_params,
  786. .prepare = snd_nm256_pcm_prepare,
  787. .trigger = snd_nm256_capture_trigger,
  788. .pointer = snd_nm256_capture_pointer,
  789. #ifndef __i386__
  790. .copy = snd_nm256_capture_copy,
  791. #endif
  792. .mmap = snd_pcm_lib_mmap_iomem,
  793. };
  794. static int __devinit
  795. snd_nm256_pcm(struct nm256 *chip, int device)
  796. {
  797. struct snd_pcm *pcm;
  798. int i, err;
  799. for (i = 0; i < 2; i++) {
  800. struct nm256_stream *s = &chip->streams[i];
  801. s->bufptr = chip->buffer + (s->buf - chip->buffer_start);
  802. s->bufptr_addr = chip->buffer_addr + (s->buf - chip->buffer_start);
  803. }
  804. err = snd_pcm_new(chip->card, chip->card->driver, device,
  805. 1, 1, &pcm);
  806. if (err < 0)
  807. return err;
  808. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_nm256_playback_ops);
  809. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_nm256_capture_ops);
  810. pcm->private_data = chip;
  811. pcm->info_flags = 0;
  812. chip->pcm = pcm;
  813. return 0;
  814. }
  815. /*
  816. * Initialize the hardware.
  817. */
  818. static void
  819. snd_nm256_init_chip(struct nm256 *chip)
  820. {
  821. /* Reset everything. */
  822. snd_nm256_writeb(chip, 0x0, 0x11);
  823. snd_nm256_writew(chip, 0x214, 0);
  824. /* stop sounds.. */
  825. //snd_nm256_playback_stop(chip);
  826. //snd_nm256_capture_stop(chip);
  827. }
  828. static irqreturn_t
  829. snd_nm256_intr_check(struct nm256 *chip)
  830. {
  831. if (chip->badintrcount++ > 1000) {
  832. /*
  833. * I'm not sure if the best thing is to stop the card from
  834. * playing or just release the interrupt (after all, we're in
  835. * a bad situation, so doing fancy stuff may not be such a good
  836. * idea).
  837. *
  838. * I worry about the card engine continuing to play noise
  839. * over and over, however--that could become a very
  840. * obnoxious problem. And we know that when this usually
  841. * happens things are fairly safe, it just means the user's
  842. * inserted a PCMCIA card and someone's spamming us with IRQ 9s.
  843. */
  844. if (chip->streams[SNDRV_PCM_STREAM_PLAYBACK].running)
  845. snd_nm256_playback_stop(chip);
  846. if (chip->streams[SNDRV_PCM_STREAM_CAPTURE].running)
  847. snd_nm256_capture_stop(chip);
  848. chip->badintrcount = 0;
  849. return IRQ_HANDLED;
  850. }
  851. return IRQ_NONE;
  852. }
  853. /*
  854. * Handle a potential interrupt for the device referred to by DEV_ID.
  855. *
  856. * I don't like the cut-n-paste job here either between the two routines,
  857. * but there are sufficient differences between the two interrupt handlers
  858. * that parameterizing it isn't all that great either. (Could use a macro,
  859. * I suppose...yucky bleah.)
  860. */
  861. static irqreturn_t
  862. snd_nm256_interrupt(int irq, void *dev_id)
  863. {
  864. struct nm256 *chip = dev_id;
  865. u16 status;
  866. u8 cbyte;
  867. status = snd_nm256_readw(chip, NM_INT_REG);
  868. /* Not ours. */
  869. if (status == 0)
  870. return snd_nm256_intr_check(chip);
  871. chip->badintrcount = 0;
  872. /* Rather boring; check for individual interrupts and process them. */
  873. spin_lock(&chip->reg_lock);
  874. if (status & NM_PLAYBACK_INT) {
  875. status &= ~NM_PLAYBACK_INT;
  876. NM_ACK_INT(chip, NM_PLAYBACK_INT);
  877. snd_nm256_playback_update(chip);
  878. }
  879. if (status & NM_RECORD_INT) {
  880. status &= ~NM_RECORD_INT;
  881. NM_ACK_INT(chip, NM_RECORD_INT);
  882. snd_nm256_capture_update(chip);
  883. }
  884. if (status & NM_MISC_INT_1) {
  885. status &= ~NM_MISC_INT_1;
  886. NM_ACK_INT(chip, NM_MISC_INT_1);
  887. snd_printd("NM256: Got misc interrupt #1\n");
  888. snd_nm256_writew(chip, NM_INT_REG, 0x8000);
  889. cbyte = snd_nm256_readb(chip, 0x400);
  890. snd_nm256_writeb(chip, 0x400, cbyte | 2);
  891. }
  892. if (status & NM_MISC_INT_2) {
  893. status &= ~NM_MISC_INT_2;
  894. NM_ACK_INT(chip, NM_MISC_INT_2);
  895. snd_printd("NM256: Got misc interrupt #2\n");
  896. cbyte = snd_nm256_readb(chip, 0x400);
  897. snd_nm256_writeb(chip, 0x400, cbyte & ~2);
  898. }
  899. /* Unknown interrupt. */
  900. if (status) {
  901. snd_printd("NM256: Fire in the hole! Unknown status 0x%x\n",
  902. status);
  903. /* Pray. */
  904. NM_ACK_INT(chip, status);
  905. }
  906. spin_unlock(&chip->reg_lock);
  907. return IRQ_HANDLED;
  908. }
  909. /*
  910. * Handle a potential interrupt for the device referred to by DEV_ID.
  911. * This handler is for the 256ZX, and is very similar to the non-ZX
  912. * routine.
  913. */
  914. static irqreturn_t
  915. snd_nm256_interrupt_zx(int irq, void *dev_id)
  916. {
  917. struct nm256 *chip = dev_id;
  918. u32 status;
  919. u8 cbyte;
  920. status = snd_nm256_readl(chip, NM_INT_REG);
  921. /* Not ours. */
  922. if (status == 0)
  923. return snd_nm256_intr_check(chip);
  924. chip->badintrcount = 0;
  925. /* Rather boring; check for individual interrupts and process them. */
  926. spin_lock(&chip->reg_lock);
  927. if (status & NM2_PLAYBACK_INT) {
  928. status &= ~NM2_PLAYBACK_INT;
  929. NM2_ACK_INT(chip, NM2_PLAYBACK_INT);
  930. snd_nm256_playback_update(chip);
  931. }
  932. if (status & NM2_RECORD_INT) {
  933. status &= ~NM2_RECORD_INT;
  934. NM2_ACK_INT(chip, NM2_RECORD_INT);
  935. snd_nm256_capture_update(chip);
  936. }
  937. if (status & NM2_MISC_INT_1) {
  938. status &= ~NM2_MISC_INT_1;
  939. NM2_ACK_INT(chip, NM2_MISC_INT_1);
  940. snd_printd("NM256: Got misc interrupt #1\n");
  941. cbyte = snd_nm256_readb(chip, 0x400);
  942. snd_nm256_writeb(chip, 0x400, cbyte | 2);
  943. }
  944. if (status & NM2_MISC_INT_2) {
  945. status &= ~NM2_MISC_INT_2;
  946. NM2_ACK_INT(chip, NM2_MISC_INT_2);
  947. snd_printd("NM256: Got misc interrupt #2\n");
  948. cbyte = snd_nm256_readb(chip, 0x400);
  949. snd_nm256_writeb(chip, 0x400, cbyte & ~2);
  950. }
  951. /* Unknown interrupt. */
  952. if (status) {
  953. snd_printd("NM256: Fire in the hole! Unknown status 0x%x\n",
  954. status);
  955. /* Pray. */
  956. NM2_ACK_INT(chip, status);
  957. }
  958. spin_unlock(&chip->reg_lock);
  959. return IRQ_HANDLED;
  960. }
  961. /*
  962. * AC97 interface
  963. */
  964. /*
  965. * Waits for the mixer to become ready to be written; returns a zero value
  966. * if it timed out.
  967. */
  968. static int
  969. snd_nm256_ac97_ready(struct nm256 *chip)
  970. {
  971. int timeout = 10;
  972. u32 testaddr;
  973. u16 testb;
  974. testaddr = chip->mixer_status_offset;
  975. testb = chip->mixer_status_mask;
  976. /*
  977. * Loop around waiting for the mixer to become ready.
  978. */
  979. while (timeout-- > 0) {
  980. if ((snd_nm256_readw(chip, testaddr) & testb) == 0)
  981. return 1;
  982. udelay(100);
  983. }
  984. return 0;
  985. }
  986. /*
  987. * Initial register values to be written to the AC97 mixer.
  988. * While most of these are identical to the reset values, we do this
  989. * so that we have most of the register contents cached--this avoids
  990. * reading from the mixer directly (which seems to be problematic,
  991. * probably due to ignorance).
  992. */
  993. struct initialValues {
  994. unsigned short reg;
  995. unsigned short value;
  996. };
  997. static struct initialValues nm256_ac97_init_val[] =
  998. {
  999. { AC97_MASTER, 0x8000 },
  1000. { AC97_HEADPHONE, 0x8000 },
  1001. { AC97_MASTER_MONO, 0x8000 },
  1002. { AC97_PC_BEEP, 0x8000 },
  1003. { AC97_PHONE, 0x8008 },
  1004. { AC97_MIC, 0x8000 },
  1005. { AC97_LINE, 0x8808 },
  1006. { AC97_CD, 0x8808 },
  1007. { AC97_VIDEO, 0x8808 },
  1008. { AC97_AUX, 0x8808 },
  1009. { AC97_PCM, 0x8808 },
  1010. { AC97_REC_SEL, 0x0000 },
  1011. { AC97_REC_GAIN, 0x0B0B },
  1012. { AC97_GENERAL_PURPOSE, 0x0000 },
  1013. { AC97_3D_CONTROL, 0x8000 },
  1014. { AC97_VENDOR_ID1, 0x8384 },
  1015. { AC97_VENDOR_ID2, 0x7609 },
  1016. };
  1017. static int nm256_ac97_idx(unsigned short reg)
  1018. {
  1019. int i;
  1020. for (i = 0; i < ARRAY_SIZE(nm256_ac97_init_val); i++)
  1021. if (nm256_ac97_init_val[i].reg == reg)
  1022. return i;
  1023. return -1;
  1024. }
  1025. /*
  1026. * some nm256 easily crash when reading from mixer registers
  1027. * thus we're treating it as a write-only mixer and cache the
  1028. * written values
  1029. */
  1030. static unsigned short
  1031. snd_nm256_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
  1032. {
  1033. struct nm256 *chip = ac97->private_data;
  1034. int idx = nm256_ac97_idx(reg);
  1035. if (idx < 0)
  1036. return 0;
  1037. return chip->ac97_regs[idx];
  1038. }
  1039. /*
  1040. */
  1041. static void
  1042. snd_nm256_ac97_write(struct snd_ac97 *ac97,
  1043. unsigned short reg, unsigned short val)
  1044. {
  1045. struct nm256 *chip = ac97->private_data;
  1046. int tries = 2;
  1047. int idx = nm256_ac97_idx(reg);
  1048. u32 base;
  1049. if (idx < 0)
  1050. return;
  1051. base = chip->mixer_base;
  1052. snd_nm256_ac97_ready(chip);
  1053. /* Wait for the write to take, too. */
  1054. while (tries-- > 0) {
  1055. snd_nm256_writew(chip, base + reg, val);
  1056. msleep(1); /* a little delay here seems better.. */
  1057. if (snd_nm256_ac97_ready(chip)) {
  1058. /* successful write: set cache */
  1059. chip->ac97_regs[idx] = val;
  1060. return;
  1061. }
  1062. }
  1063. snd_printd("nm256: ac97 codec not ready..\n");
  1064. }
  1065. /* static resolution table */
  1066. static struct snd_ac97_res_table nm256_res_table[] = {
  1067. { AC97_MASTER, 0x1f1f },
  1068. { AC97_HEADPHONE, 0x1f1f },
  1069. { AC97_MASTER_MONO, 0x001f },
  1070. { AC97_PC_BEEP, 0x001f },
  1071. { AC97_PHONE, 0x001f },
  1072. { AC97_MIC, 0x001f },
  1073. { AC97_LINE, 0x1f1f },
  1074. { AC97_CD, 0x1f1f },
  1075. { AC97_VIDEO, 0x1f1f },
  1076. { AC97_AUX, 0x1f1f },
  1077. { AC97_PCM, 0x1f1f },
  1078. { AC97_REC_GAIN, 0x0f0f },
  1079. { } /* terminator */
  1080. };
  1081. /* initialize the ac97 into a known state */
  1082. static void
  1083. snd_nm256_ac97_reset(struct snd_ac97 *ac97)
  1084. {
  1085. struct nm256 *chip = ac97->private_data;
  1086. /* Reset the mixer. 'Tis magic! */
  1087. snd_nm256_writeb(chip, 0x6c0, 1);
  1088. if (! chip->reset_workaround) {
  1089. /* Dell latitude LS will lock up by this */
  1090. snd_nm256_writeb(chip, 0x6cc, 0x87);
  1091. }
  1092. if (! chip->reset_workaround_2) {
  1093. /* Dell latitude CSx will lock up by this */
  1094. snd_nm256_writeb(chip, 0x6cc, 0x80);
  1095. snd_nm256_writeb(chip, 0x6cc, 0x0);
  1096. }
  1097. if (! chip->in_resume) {
  1098. int i;
  1099. for (i = 0; i < ARRAY_SIZE(nm256_ac97_init_val); i++) {
  1100. /* preload the cache, so as to avoid even a single
  1101. * read of the mixer regs
  1102. */
  1103. snd_nm256_ac97_write(ac97, nm256_ac97_init_val[i].reg,
  1104. nm256_ac97_init_val[i].value);
  1105. }
  1106. }
  1107. }
  1108. /* create an ac97 mixer interface */
  1109. static int __devinit
  1110. snd_nm256_mixer(struct nm256 *chip)
  1111. {
  1112. struct snd_ac97_bus *pbus;
  1113. struct snd_ac97_template ac97;
  1114. int err;
  1115. static struct snd_ac97_bus_ops ops = {
  1116. .reset = snd_nm256_ac97_reset,
  1117. .write = snd_nm256_ac97_write,
  1118. .read = snd_nm256_ac97_read,
  1119. };
  1120. chip->ac97_regs = kcalloc(sizeof(short),
  1121. ARRAY_SIZE(nm256_ac97_init_val), GFP_KERNEL);
  1122. if (! chip->ac97_regs)
  1123. return -ENOMEM;
  1124. if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus)) < 0)
  1125. return err;
  1126. memset(&ac97, 0, sizeof(ac97));
  1127. ac97.scaps = AC97_SCAP_AUDIO; /* we support audio! */
  1128. ac97.private_data = chip;
  1129. ac97.res_table = nm256_res_table;
  1130. pbus->no_vra = 1;
  1131. err = snd_ac97_mixer(pbus, &ac97, &chip->ac97);
  1132. if (err < 0)
  1133. return err;
  1134. if (! (chip->ac97->id & (0xf0000000))) {
  1135. /* looks like an invalid id */
  1136. sprintf(chip->card->mixername, "%s AC97", chip->card->driver);
  1137. }
  1138. return 0;
  1139. }
  1140. /*
  1141. * See if the signature left by the NM256 BIOS is intact; if so, we use
  1142. * the associated address as the end of our audio buffer in the video
  1143. * RAM.
  1144. */
  1145. static int __devinit
  1146. snd_nm256_peek_for_sig(struct nm256 *chip)
  1147. {
  1148. /* The signature is located 1K below the end of video RAM. */
  1149. void __iomem *temp;
  1150. /* Default buffer end is 5120 bytes below the top of RAM. */
  1151. unsigned long pointer_found = chip->buffer_end - 0x1400;
  1152. u32 sig;
  1153. temp = ioremap_nocache(chip->buffer_addr + chip->buffer_end - 0x400, 16);
  1154. if (temp == NULL) {
  1155. snd_printk(KERN_ERR "Unable to scan for card signature in video RAM\n");
  1156. return -EBUSY;
  1157. }
  1158. sig = readl(temp);
  1159. if ((sig & NM_SIG_MASK) == NM_SIGNATURE) {
  1160. u32 pointer = readl(temp + 4);
  1161. /*
  1162. * If it's obviously invalid, don't use it
  1163. */
  1164. if (pointer == 0xffffffff ||
  1165. pointer < chip->buffer_size ||
  1166. pointer > chip->buffer_end) {
  1167. snd_printk(KERN_ERR "invalid signature found: 0x%x\n", pointer);
  1168. iounmap(temp);
  1169. return -ENODEV;
  1170. } else {
  1171. pointer_found = pointer;
  1172. printk(KERN_INFO "nm256: found card signature in video RAM: 0x%x\n",
  1173. pointer);
  1174. }
  1175. }
  1176. iounmap(temp);
  1177. chip->buffer_end = pointer_found;
  1178. return 0;
  1179. }
  1180. #ifdef CONFIG_PM
  1181. /*
  1182. * APM event handler, so the card is properly reinitialized after a power
  1183. * event.
  1184. */
  1185. static int nm256_suspend(struct pci_dev *pci, pm_message_t state)
  1186. {
  1187. struct snd_card *card = pci_get_drvdata(pci);
  1188. struct nm256 *chip = card->private_data;
  1189. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  1190. snd_pcm_suspend_all(chip->pcm);
  1191. snd_ac97_suspend(chip->ac97);
  1192. chip->coeffs_current = 0;
  1193. pci_disable_device(pci);
  1194. pci_save_state(pci);
  1195. pci_set_power_state(pci, pci_choose_state(pci, state));
  1196. return 0;
  1197. }
  1198. static int nm256_resume(struct pci_dev *pci)
  1199. {
  1200. struct snd_card *card = pci_get_drvdata(pci);
  1201. struct nm256 *chip = card->private_data;
  1202. int i;
  1203. /* Perform a full reset on the hardware */
  1204. chip->in_resume = 1;
  1205. pci_set_power_state(pci, PCI_D0);
  1206. pci_restore_state(pci);
  1207. if (pci_enable_device(pci) < 0) {
  1208. printk(KERN_ERR "nm256: pci_enable_device failed, "
  1209. "disabling device\n");
  1210. snd_card_disconnect(card);
  1211. return -EIO;
  1212. }
  1213. pci_set_master(pci);
  1214. snd_nm256_init_chip(chip);
  1215. /* restore ac97 */
  1216. snd_ac97_resume(chip->ac97);
  1217. for (i = 0; i < 2; i++) {
  1218. struct nm256_stream *s = &chip->streams[i];
  1219. if (s->substream && s->suspended) {
  1220. spin_lock_irq(&chip->reg_lock);
  1221. snd_nm256_set_format(chip, s, s->substream);
  1222. spin_unlock_irq(&chip->reg_lock);
  1223. }
  1224. }
  1225. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  1226. chip->in_resume = 0;
  1227. return 0;
  1228. }
  1229. #endif /* CONFIG_PM */
  1230. static int snd_nm256_free(struct nm256 *chip)
  1231. {
  1232. if (chip->streams[SNDRV_PCM_STREAM_PLAYBACK].running)
  1233. snd_nm256_playback_stop(chip);
  1234. if (chip->streams[SNDRV_PCM_STREAM_CAPTURE].running)
  1235. snd_nm256_capture_stop(chip);
  1236. if (chip->irq >= 0)
  1237. synchronize_irq(chip->irq);
  1238. if (chip->cport)
  1239. iounmap(chip->cport);
  1240. if (chip->buffer)
  1241. iounmap(chip->buffer);
  1242. release_and_free_resource(chip->res_cport);
  1243. release_and_free_resource(chip->res_buffer);
  1244. if (chip->irq >= 0)
  1245. free_irq(chip->irq, chip);
  1246. pci_disable_device(chip->pci);
  1247. kfree(chip->ac97_regs);
  1248. kfree(chip);
  1249. return 0;
  1250. }
  1251. static int snd_nm256_dev_free(struct snd_device *device)
  1252. {
  1253. struct nm256 *chip = device->device_data;
  1254. return snd_nm256_free(chip);
  1255. }
  1256. static int __devinit
  1257. snd_nm256_create(struct snd_card *card, struct pci_dev *pci,
  1258. struct nm256 **chip_ret)
  1259. {
  1260. struct nm256 *chip;
  1261. int err, pval;
  1262. static struct snd_device_ops ops = {
  1263. .dev_free = snd_nm256_dev_free,
  1264. };
  1265. u32 addr;
  1266. *chip_ret = NULL;
  1267. if ((err = pci_enable_device(pci)) < 0)
  1268. return err;
  1269. chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  1270. if (chip == NULL) {
  1271. pci_disable_device(pci);
  1272. return -ENOMEM;
  1273. }
  1274. chip->card = card;
  1275. chip->pci = pci;
  1276. chip->use_cache = use_cache;
  1277. spin_lock_init(&chip->reg_lock);
  1278. chip->irq = -1;
  1279. mutex_init(&chip->irq_mutex);
  1280. /* store buffer sizes in bytes */
  1281. chip->streams[SNDRV_PCM_STREAM_PLAYBACK].bufsize = playback_bufsize * 1024;
  1282. chip->streams[SNDRV_PCM_STREAM_CAPTURE].bufsize = capture_bufsize * 1024;
  1283. /*
  1284. * The NM256 has two memory ports. The first port is nothing
  1285. * more than a chunk of video RAM, which is used as the I/O ring
  1286. * buffer. The second port has the actual juicy stuff (like the
  1287. * mixer and the playback engine control registers).
  1288. */
  1289. chip->buffer_addr = pci_resource_start(pci, 0);
  1290. chip->cport_addr = pci_resource_start(pci, 1);
  1291. /* Init the memory port info. */
  1292. /* remap control port (#2) */
  1293. chip->res_cport = request_mem_region(chip->cport_addr, NM_PORT2_SIZE,
  1294. card->driver);
  1295. if (chip->res_cport == NULL) {
  1296. snd_printk(KERN_ERR "memory region 0x%lx (size 0x%x) busy\n",
  1297. chip->cport_addr, NM_PORT2_SIZE);
  1298. err = -EBUSY;
  1299. goto __error;
  1300. }
  1301. chip->cport = ioremap_nocache(chip->cport_addr, NM_PORT2_SIZE);
  1302. if (chip->cport == NULL) {
  1303. snd_printk(KERN_ERR "unable to map control port %lx\n", chip->cport_addr);
  1304. err = -ENOMEM;
  1305. goto __error;
  1306. }
  1307. if (!strcmp(card->driver, "NM256AV")) {
  1308. /* Ok, try to see if this is a non-AC97 version of the hardware. */
  1309. pval = snd_nm256_readw(chip, NM_MIXER_PRESENCE);
  1310. if ((pval & NM_PRESENCE_MASK) != NM_PRESENCE_VALUE) {
  1311. if (! force_ac97) {
  1312. printk(KERN_ERR "nm256: no ac97 is found!\n");
  1313. printk(KERN_ERR " force the driver to load by "
  1314. "passing in the module parameter\n");
  1315. printk(KERN_ERR " force_ac97=1\n");
  1316. printk(KERN_ERR " or try sb16 or cs423x drivers instead.\n");
  1317. err = -ENXIO;
  1318. goto __error;
  1319. }
  1320. }
  1321. chip->buffer_end = 2560 * 1024;
  1322. chip->interrupt = snd_nm256_interrupt;
  1323. chip->mixer_status_offset = NM_MIXER_STATUS_OFFSET;
  1324. chip->mixer_status_mask = NM_MIXER_READY_MASK;
  1325. } else {
  1326. /* Not sure if there is any relevant detect for the ZX or not. */
  1327. if (snd_nm256_readb(chip, 0xa0b) != 0)
  1328. chip->buffer_end = 6144 * 1024;
  1329. else
  1330. chip->buffer_end = 4096 * 1024;
  1331. chip->interrupt = snd_nm256_interrupt_zx;
  1332. chip->mixer_status_offset = NM2_MIXER_STATUS_OFFSET;
  1333. chip->mixer_status_mask = NM2_MIXER_READY_MASK;
  1334. }
  1335. chip->buffer_size = chip->streams[SNDRV_PCM_STREAM_PLAYBACK].bufsize +
  1336. chip->streams[SNDRV_PCM_STREAM_CAPTURE].bufsize;
  1337. if (chip->use_cache)
  1338. chip->buffer_size += NM_TOTAL_COEFF_COUNT * 4;
  1339. else
  1340. chip->buffer_size += NM_MAX_PLAYBACK_COEF_SIZE + NM_MAX_RECORD_COEF_SIZE;
  1341. if (buffer_top >= chip->buffer_size && buffer_top < chip->buffer_end)
  1342. chip->buffer_end = buffer_top;
  1343. else {
  1344. /* get buffer end pointer from signature */
  1345. if ((err = snd_nm256_peek_for_sig(chip)) < 0)
  1346. goto __error;
  1347. }
  1348. chip->buffer_start = chip->buffer_end - chip->buffer_size;
  1349. chip->buffer_addr += chip->buffer_start;
  1350. printk(KERN_INFO "nm256: Mapping port 1 from 0x%x - 0x%x\n",
  1351. chip->buffer_start, chip->buffer_end);
  1352. chip->res_buffer = request_mem_region(chip->buffer_addr,
  1353. chip->buffer_size,
  1354. card->driver);
  1355. if (chip->res_buffer == NULL) {
  1356. snd_printk(KERN_ERR "nm256: buffer 0x%lx (size 0x%x) busy\n",
  1357. chip->buffer_addr, chip->buffer_size);
  1358. err = -EBUSY;
  1359. goto __error;
  1360. }
  1361. chip->buffer = ioremap_nocache(chip->buffer_addr, chip->buffer_size);
  1362. if (chip->buffer == NULL) {
  1363. err = -ENOMEM;
  1364. snd_printk(KERN_ERR "unable to map ring buffer at %lx\n", chip->buffer_addr);
  1365. goto __error;
  1366. }
  1367. /* set offsets */
  1368. addr = chip->buffer_start;
  1369. chip->streams[SNDRV_PCM_STREAM_PLAYBACK].buf = addr;
  1370. addr += chip->streams[SNDRV_PCM_STREAM_PLAYBACK].bufsize;
  1371. chip->streams[SNDRV_PCM_STREAM_CAPTURE].buf = addr;
  1372. addr += chip->streams[SNDRV_PCM_STREAM_CAPTURE].bufsize;
  1373. if (chip->use_cache) {
  1374. chip->all_coeff_buf = addr;
  1375. } else {
  1376. chip->coeff_buf[SNDRV_PCM_STREAM_PLAYBACK] = addr;
  1377. addr += NM_MAX_PLAYBACK_COEF_SIZE;
  1378. chip->coeff_buf[SNDRV_PCM_STREAM_CAPTURE] = addr;
  1379. }
  1380. /* Fixed setting. */
  1381. chip->mixer_base = NM_MIXER_OFFSET;
  1382. chip->coeffs_current = 0;
  1383. snd_nm256_init_chip(chip);
  1384. // pci_set_master(pci); /* needed? */
  1385. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0)
  1386. goto __error;
  1387. snd_card_set_dev(card, &pci->dev);
  1388. *chip_ret = chip;
  1389. return 0;
  1390. __error:
  1391. snd_nm256_free(chip);
  1392. return err;
  1393. }
  1394. struct nm256_quirk {
  1395. unsigned short vendor;
  1396. unsigned short device;
  1397. int type;
  1398. };
  1399. enum { NM_BLACKLISTED, NM_RESET_WORKAROUND, NM_RESET_WORKAROUND_2 };
  1400. static struct nm256_quirk nm256_quirks[] __devinitdata = {
  1401. /* HP omnibook 4150 has cs4232 codec internally */
  1402. { .vendor = 0x103c, .device = 0x0007, .type = NM_BLACKLISTED },
  1403. /* Sony PCG-F305 */
  1404. { .vendor = 0x104d, .device = 0x8041, .type = NM_RESET_WORKAROUND },
  1405. /* Dell Latitude LS */
  1406. { .vendor = 0x1028, .device = 0x0080, .type = NM_RESET_WORKAROUND },
  1407. /* Dell Latitude CSx */
  1408. { .vendor = 0x1028, .device = 0x0091, .type = NM_RESET_WORKAROUND_2 },
  1409. { } /* terminator */
  1410. };
  1411. static int __devinit snd_nm256_probe(struct pci_dev *pci,
  1412. const struct pci_device_id *pci_id)
  1413. {
  1414. struct snd_card *card;
  1415. struct nm256 *chip;
  1416. int err;
  1417. struct nm256_quirk *q;
  1418. u16 subsystem_vendor, subsystem_device;
  1419. pci_read_config_word(pci, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vendor);
  1420. pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &subsystem_device);
  1421. for (q = nm256_quirks; q->vendor; q++) {
  1422. if (q->vendor == subsystem_vendor && q->device == subsystem_device) {
  1423. switch (q->type) {
  1424. case NM_BLACKLISTED:
  1425. printk(KERN_INFO "nm256: The device is blacklisted. "
  1426. "Loading stopped\n");
  1427. return -ENODEV;
  1428. case NM_RESET_WORKAROUND_2:
  1429. reset_workaround_2 = 1;
  1430. /* Fall-through */
  1431. case NM_RESET_WORKAROUND:
  1432. reset_workaround = 1;
  1433. break;
  1434. }
  1435. }
  1436. }
  1437. card = snd_card_new(index, id, THIS_MODULE, 0);
  1438. if (card == NULL)
  1439. return -ENOMEM;
  1440. switch (pci->device) {
  1441. case PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO:
  1442. strcpy(card->driver, "NM256AV");
  1443. break;
  1444. case PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO:
  1445. strcpy(card->driver, "NM256ZX");
  1446. break;
  1447. case PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO:
  1448. strcpy(card->driver, "NM256XL+");
  1449. break;
  1450. default:
  1451. snd_printk(KERN_ERR "invalid device id 0x%x\n", pci->device);
  1452. snd_card_free(card);
  1453. return -EINVAL;
  1454. }
  1455. if (vaio_hack)
  1456. buffer_top = 0x25a800; /* this avoids conflicts with XFree86 server */
  1457. if (playback_bufsize < 4)
  1458. playback_bufsize = 4;
  1459. if (playback_bufsize > 128)
  1460. playback_bufsize = 128;
  1461. if (capture_bufsize < 4)
  1462. capture_bufsize = 4;
  1463. if (capture_bufsize > 128)
  1464. capture_bufsize = 128;
  1465. if ((err = snd_nm256_create(card, pci, &chip)) < 0) {
  1466. snd_card_free(card);
  1467. return err;
  1468. }
  1469. card->private_data = chip;
  1470. if (reset_workaround) {
  1471. snd_printdd(KERN_INFO "nm256: reset_workaround activated\n");
  1472. chip->reset_workaround = 1;
  1473. }
  1474. if (reset_workaround_2) {
  1475. snd_printdd(KERN_INFO "nm256: reset_workaround_2 activated\n");
  1476. chip->reset_workaround_2 = 1;
  1477. }
  1478. if ((err = snd_nm256_pcm(chip, 0)) < 0 ||
  1479. (err = snd_nm256_mixer(chip)) < 0) {
  1480. snd_card_free(card);
  1481. return err;
  1482. }
  1483. sprintf(card->shortname, "NeoMagic %s", card->driver);
  1484. sprintf(card->longname, "%s at 0x%lx & 0x%lx, irq %d",
  1485. card->shortname,
  1486. chip->buffer_addr, chip->cport_addr, chip->irq);
  1487. if ((err = snd_card_register(card)) < 0) {
  1488. snd_card_free(card);
  1489. return err;
  1490. }
  1491. pci_set_drvdata(pci, card);
  1492. return 0;
  1493. }
  1494. static void __devexit snd_nm256_remove(struct pci_dev *pci)
  1495. {
  1496. snd_card_free(pci_get_drvdata(pci));
  1497. pci_set_drvdata(pci, NULL);
  1498. }
  1499. static struct pci_driver driver = {
  1500. .name = "NeoMagic 256",
  1501. .id_table = snd_nm256_ids,
  1502. .probe = snd_nm256_probe,
  1503. .remove = __devexit_p(snd_nm256_remove),
  1504. #ifdef CONFIG_PM
  1505. .suspend = nm256_suspend,
  1506. .resume = nm256_resume,
  1507. #endif
  1508. };
  1509. static int __init alsa_card_nm256_init(void)
  1510. {
  1511. return pci_register_driver(&driver);
  1512. }
  1513. static void __exit alsa_card_nm256_exit(void)
  1514. {
  1515. pci_unregister_driver(&driver);
  1516. }
  1517. module_init(alsa_card_nm256_init)
  1518. module_exit(alsa_card_nm256_exit)