nm256.c 45 KB

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