forte.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138
  1. /*
  2. * forte.c - ForteMedia FM801 OSS Driver
  3. *
  4. * Written by Martin K. Petersen <mkp@mkp.net>
  5. * Copyright (C) 2002 Hewlett-Packard Company
  6. * Portions Copyright (C) 2003 Martin K. Petersen
  7. *
  8. * Latest version: http://mkp.net/forte/
  9. *
  10. * Based upon the ALSA FM801 driver by Jaroslav Kysela and OSS drivers
  11. * by Thomas Sailer, Alan Cox, Zach Brown, and Jeff Garzik. Thanks
  12. * guys!
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License version
  16. * 2 as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful, but
  19. * WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. * General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  26. * USA
  27. *
  28. */
  29. #include <linux/config.h>
  30. #include <linux/module.h>
  31. #include <linux/kernel.h>
  32. #include <linux/init.h>
  33. #include <linux/spinlock.h>
  34. #include <linux/pci.h>
  35. #include <linux/delay.h>
  36. #include <linux/poll.h>
  37. #include <linux/sound.h>
  38. #include <linux/ac97_codec.h>
  39. #include <linux/interrupt.h>
  40. #include <linux/proc_fs.h>
  41. #include <linux/mutex.h>
  42. #include <asm/uaccess.h>
  43. #include <asm/io.h>
  44. #define DRIVER_NAME "forte"
  45. #define DRIVER_VERSION "$Id: forte.c,v 1.63 2003/03/01 05:32:42 mkp Exp $"
  46. #define PFX DRIVER_NAME ": "
  47. #undef M_DEBUG
  48. #ifdef M_DEBUG
  49. #define DPRINTK(args...) printk(KERN_WARNING args)
  50. #else
  51. #define DPRINTK(args...)
  52. #endif
  53. /* Card capabilities */
  54. #define FORTE_CAPS (DSP_CAP_MMAP | DSP_CAP_TRIGGER)
  55. /* Supported audio formats */
  56. #define FORTE_FMTS (AFMT_U8 | AFMT_S16_LE)
  57. /* Buffers */
  58. #define FORTE_MIN_FRAG_SIZE 256
  59. #define FORTE_MAX_FRAG_SIZE PAGE_SIZE
  60. #define FORTE_DEF_FRAG_SIZE 256
  61. #define FORTE_MIN_FRAGMENTS 2
  62. #define FORTE_MAX_FRAGMENTS 256
  63. #define FORTE_DEF_FRAGMENTS 2
  64. #define FORTE_MIN_BUF_MSECS 500
  65. #define FORTE_MAX_BUF_MSECS 1000
  66. /* PCI BARs */
  67. #define FORTE_PCM_VOL 0x00 /* PCM Output Volume */
  68. #define FORTE_FM_VOL 0x02 /* FM Output Volume */
  69. #define FORTE_I2S_VOL 0x04 /* I2S Volume */
  70. #define FORTE_REC_SRC 0x06 /* Record Source */
  71. #define FORTE_PLY_CTRL 0x08 /* Playback Control */
  72. #define FORTE_PLY_COUNT 0x0a /* Playback Count */
  73. #define FORTE_PLY_BUF1 0x0c /* Playback Buffer I */
  74. #define FORTE_PLY_BUF2 0x10 /* Playback Buffer II */
  75. #define FORTE_CAP_CTRL 0x14 /* Capture Control */
  76. #define FORTE_CAP_COUNT 0x16 /* Capture Count */
  77. #define FORTE_CAP_BUF1 0x18 /* Capture Buffer I */
  78. #define FORTE_CAP_BUF2 0x1c /* Capture Buffer II */
  79. #define FORTE_CODEC_CTRL 0x22 /* Codec Control */
  80. #define FORTE_I2S_MODE 0x24 /* I2S Mode Control */
  81. #define FORTE_VOLUME 0x26 /* Volume Up/Down/Mute Status */
  82. #define FORTE_I2C_CTRL 0x29 /* I2C Control */
  83. #define FORTE_AC97_CMD 0x2a /* AC'97 Command */
  84. #define FORTE_AC97_DATA 0x2c /* AC'97 Data */
  85. #define FORTE_MPU401_DATA 0x30 /* MPU401 Data */
  86. #define FORTE_MPU401_CMD 0x31 /* MPU401 Command */
  87. #define FORTE_GPIO_CTRL 0x52 /* General Purpose I/O Control */
  88. #define FORTE_GEN_CTRL 0x54 /* General Control */
  89. #define FORTE_IRQ_MASK 0x56 /* Interrupt Mask */
  90. #define FORTE_IRQ_STATUS 0x5a /* Interrupt Status */
  91. #define FORTE_OPL3_BANK0 0x68 /* OPL3 Status Read / Bank 0 Write */
  92. #define FORTE_OPL3_DATA0 0x69 /* OPL3 Data 0 Write */
  93. #define FORTE_OPL3_BANK1 0x6a /* OPL3 Bank 1 Write */
  94. #define FORTE_OPL3_DATA1 0x6b /* OPL3 Bank 1 Write */
  95. #define FORTE_POWERDOWN 0x70 /* Blocks Power Down Control */
  96. #define FORTE_CAP_OFFSET FORTE_CAP_CTRL - FORTE_PLY_CTRL
  97. #define FORTE_AC97_ADDR_SHIFT 10
  98. /* Playback and record control register bits */
  99. #define FORTE_BUF1_LAST (1<<1)
  100. #define FORTE_BUF2_LAST (1<<2)
  101. #define FORTE_START (1<<5)
  102. #define FORTE_PAUSE (1<<6)
  103. #define FORTE_IMMED_STOP (1<<7)
  104. #define FORTE_RATE_SHIFT 8
  105. #define FORTE_RATE_MASK (15 << FORTE_RATE_SHIFT)
  106. #define FORTE_CHANNELS_4 (1<<12) /* Playback only */
  107. #define FORTE_CHANNELS_6 (2<<12) /* Playback only */
  108. #define FORTE_CHANNELS_6MS (3<<12) /* Playback only */
  109. #define FORTE_CHANNELS_MASK (3<<12)
  110. #define FORTE_16BIT (1<<14)
  111. #define FORTE_STEREO (1<<15)
  112. /* IRQ status bits */
  113. #define FORTE_IRQ_PLAYBACK (1<<8)
  114. #define FORTE_IRQ_CAPTURE (1<<9)
  115. #define FORTE_IRQ_VOLUME (1<<14)
  116. #define FORTE_IRQ_MPU (1<<15)
  117. /* CODEC control */
  118. #define FORTE_CC_CODEC_RESET (1<<5)
  119. #define FORTE_CC_AC97_RESET (1<<6)
  120. /* AC97 cmd */
  121. #define FORTE_AC97_WRITE (0<<7)
  122. #define FORTE_AC97_READ (1<<7)
  123. #define FORTE_AC97_DP_INVALID (0<<8)
  124. #define FORTE_AC97_DP_VALID (1<<8)
  125. #define FORTE_AC97_PORT_RDY (0<<9)
  126. #define FORTE_AC97_PORT_BSY (1<<9)
  127. struct forte_channel {
  128. const char *name;
  129. unsigned short ctrl; /* Ctrl BAR contents */
  130. unsigned long iobase; /* Ctrl BAR address */
  131. wait_queue_head_t wait;
  132. void *buf; /* Buffer */
  133. dma_addr_t buf_handle; /* Buffer handle */
  134. unsigned int record;
  135. unsigned int format;
  136. unsigned int rate;
  137. unsigned int stereo;
  138. unsigned int frag_sz; /* Current fragment size */
  139. unsigned int frag_num; /* Current # of fragments */
  140. unsigned int frag_msecs; /* Milliseconds per frag */
  141. unsigned int buf_sz; /* Current buffer size */
  142. unsigned int hwptr; /* Tail */
  143. unsigned int swptr; /* Head */
  144. unsigned int filled_frags; /* Fragments currently full */
  145. unsigned int next_buf; /* Index of next buffer */
  146. unsigned int active; /* Channel currently in use */
  147. unsigned int mapped; /* mmap */
  148. unsigned int buf_pages; /* Real size of buffer */
  149. unsigned int nr_irqs; /* Number of interrupts */
  150. unsigned int bytes; /* Total bytes */
  151. unsigned int residue; /* Partial fragment */
  152. };
  153. struct forte_chip {
  154. struct pci_dev *pci_dev;
  155. unsigned long iobase;
  156. int irq;
  157. struct mutex open_mutex; /* Device access */
  158. spinlock_t lock; /* State */
  159. spinlock_t ac97_lock;
  160. struct ac97_codec *ac97;
  161. int multichannel;
  162. int dsp; /* OSS handle */
  163. int trigger; /* mmap I/O trigger */
  164. struct forte_channel play;
  165. struct forte_channel rec;
  166. };
  167. static int channels[] = { 2, 4, 6, };
  168. static int rates[] = { 5500, 8000, 9600, 11025, 16000, 19200,
  169. 22050, 32000, 38400, 44100, 48000, };
  170. static struct forte_chip *forte;
  171. static int found;
  172. /* AC97 Codec -------------------------------------------------------------- */
  173. /**
  174. * forte_ac97_wait:
  175. * @chip: fm801 instance whose AC97 codec to wait on
  176. *
  177. * FIXME:
  178. * Stop busy-waiting
  179. */
  180. static inline int
  181. forte_ac97_wait (struct forte_chip *chip)
  182. {
  183. int i = 10000;
  184. while ( (inw (chip->iobase + FORTE_AC97_CMD) & FORTE_AC97_PORT_BSY)
  185. && i-- )
  186. cpu_relax();
  187. return i == 0;
  188. }
  189. /**
  190. * forte_ac97_read:
  191. * @codec: AC97 codec to read from
  192. * @reg: register to read
  193. */
  194. static u16
  195. forte_ac97_read (struct ac97_codec *codec, u8 reg)
  196. {
  197. u16 ret = 0;
  198. struct forte_chip *chip = codec->private_data;
  199. spin_lock (&chip->ac97_lock);
  200. /* Knock, knock */
  201. if (forte_ac97_wait (chip)) {
  202. printk (KERN_ERR PFX "ac97_read: Serial bus busy\n");
  203. goto out;
  204. }
  205. /* Send read command */
  206. outw (reg | (1<<7), chip->iobase + FORTE_AC97_CMD);
  207. if (forte_ac97_wait (chip)) {
  208. printk (KERN_ERR PFX "ac97_read: Bus busy reading reg 0x%x\n",
  209. reg);
  210. goto out;
  211. }
  212. /* Sanity checking */
  213. if (inw (chip->iobase + FORTE_AC97_CMD) & FORTE_AC97_DP_INVALID) {
  214. printk (KERN_ERR PFX "ac97_read: Invalid data port");
  215. goto out;
  216. }
  217. /* Fetch result */
  218. ret = inw (chip->iobase + FORTE_AC97_DATA);
  219. out:
  220. spin_unlock (&chip->ac97_lock);
  221. return ret;
  222. }
  223. /**
  224. * forte_ac97_write:
  225. * @codec: AC97 codec to send command to
  226. * @reg: register to write
  227. * @val: value to write
  228. */
  229. static void
  230. forte_ac97_write (struct ac97_codec *codec, u8 reg, u16 val)
  231. {
  232. struct forte_chip *chip = codec->private_data;
  233. spin_lock (&chip->ac97_lock);
  234. /* Knock, knock */
  235. if (forte_ac97_wait (chip)) {
  236. printk (KERN_ERR PFX "ac97_write: Serial bus busy\n");
  237. goto out;
  238. }
  239. outw (val, chip->iobase + FORTE_AC97_DATA);
  240. outb (reg | FORTE_AC97_WRITE, chip->iobase + FORTE_AC97_CMD);
  241. /* Wait for completion */
  242. if (forte_ac97_wait (chip)) {
  243. printk (KERN_ERR PFX "ac97_write: Bus busy after write\n");
  244. goto out;
  245. }
  246. out:
  247. spin_unlock (&chip->ac97_lock);
  248. }
  249. /* Mixer ------------------------------------------------------------------- */
  250. /**
  251. * forte_mixer_open:
  252. * @inode:
  253. * @file:
  254. */
  255. static int
  256. forte_mixer_open (struct inode *inode, struct file *file)
  257. {
  258. struct forte_chip *chip = forte;
  259. file->private_data = chip->ac97;
  260. return 0;
  261. }
  262. /**
  263. * forte_mixer_release:
  264. * @inode:
  265. * @file:
  266. */
  267. static int
  268. forte_mixer_release (struct inode *inode, struct file *file)
  269. {
  270. /* We will welease Wodewick */
  271. return 0;
  272. }
  273. /**
  274. * forte_mixer_ioctl:
  275. * @inode:
  276. * @file:
  277. */
  278. static int
  279. forte_mixer_ioctl (struct inode *inode, struct file *file,
  280. unsigned int cmd, unsigned long arg)
  281. {
  282. struct ac97_codec *codec = (struct ac97_codec *) file->private_data;
  283. return codec->mixer_ioctl (codec, cmd, arg);
  284. }
  285. static struct file_operations forte_mixer_fops = {
  286. .owner = THIS_MODULE,
  287. .llseek = no_llseek,
  288. .ioctl = forte_mixer_ioctl,
  289. .open = forte_mixer_open,
  290. .release = forte_mixer_release,
  291. };
  292. /* Channel ----------------------------------------------------------------- */
  293. /**
  294. * forte_channel_reset:
  295. * @channel: Channel to reset
  296. *
  297. * Locking: Must be called with lock held.
  298. */
  299. static void
  300. forte_channel_reset (struct forte_channel *channel)
  301. {
  302. if (!channel || !channel->iobase)
  303. return;
  304. DPRINTK ("%s: channel = %s\n", __FUNCTION__, channel->name);
  305. channel->ctrl &= ~FORTE_START;
  306. outw (channel->ctrl, channel->iobase + FORTE_PLY_CTRL);
  307. /* We always play at least two fragments, hence these defaults */
  308. channel->hwptr = channel->frag_sz;
  309. channel->next_buf = 1;
  310. channel->swptr = 0;
  311. channel->filled_frags = 0;
  312. channel->active = 0;
  313. channel->bytes = 0;
  314. channel->nr_irqs = 0;
  315. channel->mapped = 0;
  316. channel->residue = 0;
  317. }
  318. /**
  319. * forte_channel_start:
  320. * @channel: Channel to start (record/playback)
  321. *
  322. * Locking: Must be called with lock held.
  323. */
  324. static void inline
  325. forte_channel_start (struct forte_channel *channel)
  326. {
  327. if (!channel || !channel->iobase || channel->active)
  328. return;
  329. channel->ctrl &= ~(FORTE_PAUSE | FORTE_BUF1_LAST | FORTE_BUF2_LAST
  330. | FORTE_IMMED_STOP);
  331. channel->ctrl |= FORTE_START;
  332. channel->active = 1;
  333. outw (channel->ctrl, channel->iobase + FORTE_PLY_CTRL);
  334. }
  335. /**
  336. * forte_channel_stop:
  337. * @channel: Channel to stop
  338. *
  339. * Locking: Must be called with lock held.
  340. */
  341. static void inline
  342. forte_channel_stop (struct forte_channel *channel)
  343. {
  344. if (!channel || !channel->iobase)
  345. return;
  346. channel->ctrl &= ~(FORTE_START | FORTE_PAUSE);
  347. channel->ctrl |= FORTE_IMMED_STOP;
  348. channel->active = 0;
  349. outw (channel->ctrl, channel->iobase + FORTE_PLY_CTRL);
  350. }
  351. /**
  352. * forte_channel_pause:
  353. * @channel: Channel to pause
  354. *
  355. * Locking: Must be called with lock held.
  356. */
  357. static void inline
  358. forte_channel_pause (struct forte_channel *channel)
  359. {
  360. if (!channel || !channel->iobase)
  361. return;
  362. channel->ctrl |= FORTE_PAUSE;
  363. channel->active = 0;
  364. outw (channel->ctrl, channel->iobase + FORTE_PLY_CTRL);
  365. }
  366. /**
  367. * forte_channel_rate:
  368. * @channel: Channel whose rate to set. Playback and record are
  369. * independent.
  370. * @rate: Channel rate in Hz
  371. *
  372. * Locking: Must be called with lock held.
  373. */
  374. static int
  375. forte_channel_rate (struct forte_channel *channel, unsigned int rate)
  376. {
  377. int new_rate;
  378. if (!channel || !channel->iobase)
  379. return -EINVAL;
  380. /* The FM801 only supports a handful of fixed frequencies.
  381. * We find the value closest to what userland requested.
  382. */
  383. if (rate <= 6250) { rate = 5500; new_rate = 0; }
  384. else if (rate <= 8800) { rate = 8000; new_rate = 1; }
  385. else if (rate <= 10312) { rate = 9600; new_rate = 2; }
  386. else if (rate <= 13512) { rate = 11025; new_rate = 3; }
  387. else if (rate <= 17600) { rate = 16000; new_rate = 4; }
  388. else if (rate <= 20625) { rate = 19200; new_rate = 5; }
  389. else if (rate <= 27025) { rate = 22050; new_rate = 6; }
  390. else if (rate <= 35200) { rate = 32000; new_rate = 7; }
  391. else if (rate <= 41250) { rate = 38400; new_rate = 8; }
  392. else if (rate <= 46050) { rate = 44100; new_rate = 9; }
  393. else { rate = 48000; new_rate = 10; }
  394. channel->ctrl &= ~FORTE_RATE_MASK;
  395. channel->ctrl |= new_rate << FORTE_RATE_SHIFT;
  396. channel->rate = rate;
  397. DPRINTK ("%s: %s rate = %d\n", __FUNCTION__, channel->name, rate);
  398. return rate;
  399. }
  400. /**
  401. * forte_channel_format:
  402. * @channel: Channel whose audio format to set
  403. * @format: OSS format ID
  404. *
  405. * Locking: Must be called with lock held.
  406. */
  407. static int
  408. forte_channel_format (struct forte_channel *channel, int format)
  409. {
  410. if (!channel || !channel->iobase)
  411. return -EINVAL;
  412. switch (format) {
  413. case AFMT_QUERY:
  414. break;
  415. case AFMT_U8:
  416. channel->ctrl &= ~FORTE_16BIT;
  417. channel->format = AFMT_U8;
  418. break;
  419. case AFMT_S16_LE:
  420. default:
  421. channel->ctrl |= FORTE_16BIT;
  422. channel->format = AFMT_S16_LE;
  423. break;
  424. }
  425. DPRINTK ("%s: %s want %d format, got %d\n", __FUNCTION__, channel->name,
  426. format, channel->format);
  427. return channel->format;
  428. }
  429. /**
  430. * forte_channel_stereo:
  431. * @channel: Channel to toggle
  432. * @stereo: 0 for Mono, 1 for Stereo
  433. *
  434. * Locking: Must be called with lock held.
  435. */
  436. static int
  437. forte_channel_stereo (struct forte_channel *channel, unsigned int stereo)
  438. {
  439. int ret;
  440. if (!channel || !channel->iobase)
  441. return -EINVAL;
  442. DPRINTK ("%s: %s stereo = %d\n", __FUNCTION__, channel->name, stereo);
  443. switch (stereo) {
  444. case 0:
  445. channel->ctrl &= ~(FORTE_STEREO | FORTE_CHANNELS_MASK);
  446. channel-> stereo = stereo;
  447. ret = stereo;
  448. break;
  449. case 1:
  450. channel->ctrl &= ~FORTE_CHANNELS_MASK;
  451. channel->ctrl |= FORTE_STEREO;
  452. channel-> stereo = stereo;
  453. ret = stereo;
  454. break;
  455. default:
  456. DPRINTK ("Unsupported channel format");
  457. ret = -EINVAL;
  458. break;
  459. }
  460. return ret;
  461. }
  462. /**
  463. * forte_channel_buffer:
  464. * @channel: Channel whose buffer to set up
  465. *
  466. * Locking: Must be called with lock held.
  467. */
  468. static void
  469. forte_channel_buffer (struct forte_channel *channel, int sz, int num)
  470. {
  471. unsigned int msecs, shift;
  472. /* Go away, I'm busy */
  473. if (channel->filled_frags || channel->bytes)
  474. return;
  475. /* Fragment size must be a power of 2 */
  476. shift = 0; sz++;
  477. while (sz >>= 1)
  478. shift++;
  479. channel->frag_sz = 1 << shift;
  480. /* Round fragment size to something reasonable */
  481. if (channel->frag_sz < FORTE_MIN_FRAG_SIZE)
  482. channel->frag_sz = FORTE_MIN_FRAG_SIZE;
  483. if (channel->frag_sz > FORTE_MAX_FRAG_SIZE)
  484. channel->frag_sz = FORTE_MAX_FRAG_SIZE;
  485. /* Find fragment length in milliseconds */
  486. msecs = channel->frag_sz /
  487. (channel->format == AFMT_S16_LE ? 2 : 1) /
  488. (channel->stereo ? 2 : 1) /
  489. (channel->rate / 1000);
  490. channel->frag_msecs = msecs;
  491. /* Pick a suitable number of fragments */
  492. if (msecs * num < FORTE_MIN_BUF_MSECS)
  493. num = FORTE_MIN_BUF_MSECS / msecs;
  494. if (msecs * num > FORTE_MAX_BUF_MSECS)
  495. num = FORTE_MAX_BUF_MSECS / msecs;
  496. /* Fragment number must be a power of 2 */
  497. shift = 0;
  498. while (num >>= 1)
  499. shift++;
  500. channel->frag_num = 1 << (shift + 1);
  501. /* Round fragment number to something reasonable */
  502. if (channel->frag_num < FORTE_MIN_FRAGMENTS)
  503. channel->frag_num = FORTE_MIN_FRAGMENTS;
  504. if (channel->frag_num > FORTE_MAX_FRAGMENTS)
  505. channel->frag_num = FORTE_MAX_FRAGMENTS;
  506. channel->buf_sz = channel->frag_sz * channel->frag_num;
  507. DPRINTK ("%s: %s frag_sz = %d, frag_num = %d, buf_sz = %d\n",
  508. __FUNCTION__, channel->name, channel->frag_sz,
  509. channel->frag_num, channel->buf_sz);
  510. }
  511. /**
  512. * forte_channel_prep:
  513. * @channel: Channel whose buffer to prepare
  514. *
  515. * Locking: Lock held.
  516. */
  517. static void
  518. forte_channel_prep (struct forte_channel *channel)
  519. {
  520. struct page *page;
  521. int i;
  522. if (channel->buf)
  523. return;
  524. forte_channel_buffer (channel, channel->frag_sz, channel->frag_num);
  525. channel->buf_pages = channel->buf_sz >> PAGE_SHIFT;
  526. if (channel->buf_sz % PAGE_SIZE)
  527. channel->buf_pages++;
  528. DPRINTK ("%s: %s frag_sz = %d, frag_num = %d, buf_sz = %d, pg = %d\n",
  529. __FUNCTION__, channel->name, channel->frag_sz,
  530. channel->frag_num, channel->buf_sz, channel->buf_pages);
  531. /* DMA buffer */
  532. channel->buf = pci_alloc_consistent (forte->pci_dev,
  533. channel->buf_pages * PAGE_SIZE,
  534. &channel->buf_handle);
  535. if (!channel->buf || !channel->buf_handle)
  536. BUG();
  537. page = virt_to_page (channel->buf);
  538. /* FIXME: can this go away ? */
  539. for (i = 0 ; i < channel->buf_pages ; i++)
  540. SetPageReserved(page++);
  541. /* Prep buffer registers */
  542. outw (channel->frag_sz - 1, channel->iobase + FORTE_PLY_COUNT);
  543. outl (channel->buf_handle, channel->iobase + FORTE_PLY_BUF1);
  544. outl (channel->buf_handle + channel->frag_sz,
  545. channel->iobase + FORTE_PLY_BUF2);
  546. /* Reset hwptr */
  547. channel->hwptr = channel->frag_sz;
  548. channel->next_buf = 1;
  549. DPRINTK ("%s: %s buffer @ %p (%p)\n", __FUNCTION__, channel->name,
  550. channel->buf, channel->buf_handle);
  551. }
  552. /**
  553. * forte_channel_drain:
  554. * @chip:
  555. * @channel:
  556. *
  557. * Locking: Don't hold the lock.
  558. */
  559. static inline int
  560. forte_channel_drain (struct forte_channel *channel)
  561. {
  562. DECLARE_WAITQUEUE (wait, current);
  563. unsigned long flags;
  564. DPRINTK ("%s\n", __FUNCTION__);
  565. if (channel->mapped) {
  566. spin_lock_irqsave (&forte->lock, flags);
  567. forte_channel_stop (channel);
  568. spin_unlock_irqrestore (&forte->lock, flags);
  569. return 0;
  570. }
  571. spin_lock_irqsave (&forte->lock, flags);
  572. add_wait_queue (&channel->wait, &wait);
  573. for (;;) {
  574. if (channel->active == 0 || channel->filled_frags == 1)
  575. break;
  576. spin_unlock_irqrestore (&forte->lock, flags);
  577. __set_current_state (TASK_INTERRUPTIBLE);
  578. schedule();
  579. spin_lock_irqsave (&forte->lock, flags);
  580. }
  581. forte_channel_stop (channel);
  582. forte_channel_reset (channel);
  583. set_current_state (TASK_RUNNING);
  584. remove_wait_queue (&channel->wait, &wait);
  585. spin_unlock_irqrestore (&forte->lock, flags);
  586. return 0;
  587. }
  588. /**
  589. * forte_channel_init:
  590. * @chip: Forte chip instance the channel hangs off
  591. * @channel: Channel to initialize
  592. *
  593. * Description:
  594. * Initializes a channel, sets defaults, and allocates
  595. * buffers.
  596. *
  597. * Locking: No lock held.
  598. */
  599. static int
  600. forte_channel_init (struct forte_chip *chip, struct forte_channel *channel)
  601. {
  602. DPRINTK ("%s: chip iobase @ %p\n", __FUNCTION__, (void *)chip->iobase);
  603. spin_lock_irq (&chip->lock);
  604. memset (channel, 0x0, sizeof (*channel));
  605. if (channel == &chip->play) {
  606. channel->name = "PCM_OUT";
  607. channel->iobase = chip->iobase;
  608. DPRINTK ("%s: PCM-OUT iobase @ %p\n", __FUNCTION__,
  609. (void *) channel->iobase);
  610. }
  611. else if (channel == &chip->rec) {
  612. channel->name = "PCM_IN";
  613. channel->iobase = chip->iobase + FORTE_CAP_OFFSET;
  614. channel->record = 1;
  615. DPRINTK ("%s: PCM-IN iobase @ %p\n", __FUNCTION__,
  616. (void *) channel->iobase);
  617. }
  618. else
  619. BUG();
  620. init_waitqueue_head (&channel->wait);
  621. /* Defaults: 48kHz, 16-bit, stereo */
  622. channel->ctrl = inw (channel->iobase + FORTE_PLY_CTRL);
  623. forte_channel_reset (channel);
  624. forte_channel_stereo (channel, 1);
  625. forte_channel_format (channel, AFMT_S16_LE);
  626. forte_channel_rate (channel, 48000);
  627. channel->frag_sz = FORTE_DEF_FRAG_SIZE;
  628. channel->frag_num = FORTE_DEF_FRAGMENTS;
  629. chip->trigger = 0;
  630. spin_unlock_irq (&chip->lock);
  631. return 0;
  632. }
  633. /**
  634. * forte_channel_free:
  635. * @chip: Chip this channel hangs off
  636. * @channel: Channel to nuke
  637. *
  638. * Description:
  639. * Resets channel and frees buffers.
  640. *
  641. * Locking: Hold your horses.
  642. */
  643. static void
  644. forte_channel_free (struct forte_chip *chip, struct forte_channel *channel)
  645. {
  646. DPRINTK ("%s: %s\n", __FUNCTION__, channel->name);
  647. if (!channel->buf_handle)
  648. return;
  649. pci_free_consistent (chip->pci_dev, channel->buf_pages * PAGE_SIZE,
  650. channel->buf, channel->buf_handle);
  651. memset (channel, 0x0, sizeof (*channel));
  652. }
  653. /* DSP --------------------------------------------------------------------- */
  654. /**
  655. * forte_dsp_ioctl:
  656. */
  657. static int
  658. forte_dsp_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
  659. unsigned long arg)
  660. {
  661. int ival=0, ret, rval=0, rd, wr, count;
  662. struct forte_chip *chip;
  663. struct audio_buf_info abi;
  664. struct count_info cinfo;
  665. void __user *argp = (void __user *)arg;
  666. int __user *p = argp;
  667. chip = file->private_data;
  668. if (file->f_mode & FMODE_WRITE)
  669. wr = 1;
  670. else
  671. wr = 0;
  672. if (file->f_mode & FMODE_READ)
  673. rd = 1;
  674. else
  675. rd = 0;
  676. switch (cmd) {
  677. case OSS_GETVERSION:
  678. return put_user (SOUND_VERSION, p);
  679. case SNDCTL_DSP_GETCAPS:
  680. DPRINTK ("%s: GETCAPS\n", __FUNCTION__);
  681. ival = FORTE_CAPS; /* DUPLEX */
  682. return put_user (ival, p);
  683. case SNDCTL_DSP_GETFMTS:
  684. DPRINTK ("%s: GETFMTS\n", __FUNCTION__);
  685. ival = FORTE_FMTS; /* U8, 16LE */
  686. return put_user (ival, p);
  687. case SNDCTL_DSP_SETFMT: /* U8, 16LE */
  688. DPRINTK ("%s: SETFMT\n", __FUNCTION__);
  689. if (get_user (ival, p))
  690. return -EFAULT;
  691. spin_lock_irq (&chip->lock);
  692. if (rd) {
  693. forte_channel_stop (&chip->rec);
  694. rval = forte_channel_format (&chip->rec, ival);
  695. }
  696. if (wr) {
  697. forte_channel_stop (&chip->rec);
  698. rval = forte_channel_format (&chip->play, ival);
  699. }
  700. spin_unlock_irq (&chip->lock);
  701. return put_user (rval, p);
  702. case SNDCTL_DSP_STEREO: /* 0 - mono, 1 - stereo */
  703. DPRINTK ("%s: STEREO\n", __FUNCTION__);
  704. if (get_user (ival, p))
  705. return -EFAULT;
  706. spin_lock_irq (&chip->lock);
  707. if (rd) {
  708. forte_channel_stop (&chip->rec);
  709. rval = forte_channel_stereo (&chip->rec, ival);
  710. }
  711. if (wr) {
  712. forte_channel_stop (&chip->rec);
  713. rval = forte_channel_stereo (&chip->play, ival);
  714. }
  715. spin_unlock_irq (&chip->lock);
  716. return put_user (rval, p);
  717. case SNDCTL_DSP_CHANNELS: /* 1 - mono, 2 - stereo */
  718. DPRINTK ("%s: CHANNELS\n", __FUNCTION__);
  719. if (get_user (ival, p))
  720. return -EFAULT;
  721. spin_lock_irq (&chip->lock);
  722. if (rd) {
  723. forte_channel_stop (&chip->rec);
  724. rval = forte_channel_stereo (&chip->rec, ival-1) + 1;
  725. }
  726. if (wr) {
  727. forte_channel_stop (&chip->play);
  728. rval = forte_channel_stereo (&chip->play, ival-1) + 1;
  729. }
  730. spin_unlock_irq (&chip->lock);
  731. return put_user (rval, p);
  732. case SNDCTL_DSP_SPEED:
  733. DPRINTK ("%s: SPEED\n", __FUNCTION__);
  734. if (get_user (ival, p))
  735. return -EFAULT;
  736. spin_lock_irq (&chip->lock);
  737. if (rd) {
  738. forte_channel_stop (&chip->rec);
  739. rval = forte_channel_rate (&chip->rec, ival);
  740. }
  741. if (wr) {
  742. forte_channel_stop (&chip->play);
  743. rval = forte_channel_rate (&chip->play, ival);
  744. }
  745. spin_unlock_irq (&chip->lock);
  746. return put_user(rval, p);
  747. case SNDCTL_DSP_GETBLKSIZE:
  748. DPRINTK ("%s: GETBLKSIZE\n", __FUNCTION__);
  749. spin_lock_irq (&chip->lock);
  750. if (rd)
  751. ival = chip->rec.frag_sz;
  752. if (wr)
  753. ival = chip->play.frag_sz;
  754. spin_unlock_irq (&chip->lock);
  755. return put_user (ival, p);
  756. case SNDCTL_DSP_RESET:
  757. DPRINTK ("%s: RESET\n", __FUNCTION__);
  758. spin_lock_irq (&chip->lock);
  759. if (rd)
  760. forte_channel_reset (&chip->rec);
  761. if (wr)
  762. forte_channel_reset (&chip->play);
  763. spin_unlock_irq (&chip->lock);
  764. return 0;
  765. case SNDCTL_DSP_SYNC:
  766. DPRINTK ("%s: SYNC\n", __FUNCTION__);
  767. if (wr)
  768. ret = forte_channel_drain (&chip->play);
  769. return 0;
  770. case SNDCTL_DSP_POST:
  771. DPRINTK ("%s: POST\n", __FUNCTION__);
  772. if (wr) {
  773. spin_lock_irq (&chip->lock);
  774. if (chip->play.filled_frags)
  775. forte_channel_start (&chip->play);
  776. spin_unlock_irq (&chip->lock);
  777. }
  778. return 0;
  779. case SNDCTL_DSP_SETFRAGMENT:
  780. DPRINTK ("%s: SETFRAGMENT\n", __FUNCTION__);
  781. if (get_user (ival, p))
  782. return -EFAULT;
  783. spin_lock_irq (&chip->lock);
  784. if (rd) {
  785. forte_channel_buffer (&chip->rec, ival & 0xffff,
  786. (ival >> 16) & 0xffff);
  787. ival = (chip->rec.frag_num << 16) + chip->rec.frag_sz;
  788. }
  789. if (wr) {
  790. forte_channel_buffer (&chip->play, ival & 0xffff,
  791. (ival >> 16) & 0xffff);
  792. ival = (chip->play.frag_num << 16) +chip->play.frag_sz;
  793. }
  794. spin_unlock_irq (&chip->lock);
  795. return put_user (ival, p);
  796. case SNDCTL_DSP_GETISPACE:
  797. DPRINTK ("%s: GETISPACE\n", __FUNCTION__);
  798. if (!rd)
  799. return -EINVAL;
  800. spin_lock_irq (&chip->lock);
  801. abi.fragstotal = chip->rec.frag_num;
  802. abi.fragsize = chip->rec.frag_sz;
  803. if (chip->rec.mapped) {
  804. abi.fragments = chip->rec.frag_num - 2;
  805. abi.bytes = abi.fragments * abi.fragsize;
  806. }
  807. else {
  808. abi.fragments = chip->rec.filled_frags;
  809. abi.bytes = abi.fragments * abi.fragsize;
  810. }
  811. spin_unlock_irq (&chip->lock);
  812. return copy_to_user (argp, &abi, sizeof (abi)) ? -EFAULT : 0;
  813. case SNDCTL_DSP_GETIPTR:
  814. DPRINTK ("%s: GETIPTR\n", __FUNCTION__);
  815. if (!rd)
  816. return -EINVAL;
  817. spin_lock_irq (&chip->lock);
  818. if (chip->rec.active)
  819. cinfo.ptr = chip->rec.hwptr;
  820. else
  821. cinfo.ptr = 0;
  822. cinfo.bytes = chip->rec.bytes;
  823. cinfo.blocks = chip->rec.nr_irqs;
  824. chip->rec.nr_irqs = 0;
  825. spin_unlock_irq (&chip->lock);
  826. return copy_to_user (argp, &cinfo, sizeof (cinfo)) ? -EFAULT : 0;
  827. case SNDCTL_DSP_GETOSPACE:
  828. if (!wr)
  829. return -EINVAL;
  830. spin_lock_irq (&chip->lock);
  831. abi.fragstotal = chip->play.frag_num;
  832. abi.fragsize = chip->play.frag_sz;
  833. if (chip->play.mapped) {
  834. abi.fragments = chip->play.frag_num - 2;
  835. abi.bytes = chip->play.buf_sz;
  836. }
  837. else {
  838. abi.fragments = chip->play.frag_num -
  839. chip->play.filled_frags;
  840. if (chip->play.residue)
  841. abi.fragments--;
  842. abi.bytes = abi.fragments * abi.fragsize +
  843. chip->play.residue;
  844. }
  845. spin_unlock_irq (&chip->lock);
  846. return copy_to_user (argp, &abi, sizeof (abi)) ? -EFAULT : 0;
  847. case SNDCTL_DSP_GETOPTR:
  848. if (!wr)
  849. return -EINVAL;
  850. spin_lock_irq (&chip->lock);
  851. if (chip->play.active)
  852. cinfo.ptr = chip->play.hwptr;
  853. else
  854. cinfo.ptr = 0;
  855. cinfo.bytes = chip->play.bytes;
  856. cinfo.blocks = chip->play.nr_irqs;
  857. chip->play.nr_irqs = 0;
  858. spin_unlock_irq (&chip->lock);
  859. return copy_to_user (argp, &cinfo, sizeof (cinfo)) ? -EFAULT : 0;
  860. case SNDCTL_DSP_GETODELAY:
  861. if (!wr)
  862. return -EINVAL;
  863. spin_lock_irq (&chip->lock);
  864. if (!chip->play.active) {
  865. ival = 0;
  866. }
  867. else if (chip->play.mapped) {
  868. count = inw (chip->play.iobase + FORTE_PLY_COUNT) + 1;
  869. ival = chip->play.frag_sz - count;
  870. }
  871. else {
  872. ival = chip->play.filled_frags * chip->play.frag_sz;
  873. if (chip->play.residue)
  874. ival += chip->play.frag_sz - chip->play.residue;
  875. }
  876. spin_unlock_irq (&chip->lock);
  877. return put_user (ival, p);
  878. case SNDCTL_DSP_SETDUPLEX:
  879. DPRINTK ("%s: SETDUPLEX\n", __FUNCTION__);
  880. return -EINVAL;
  881. case SNDCTL_DSP_GETTRIGGER:
  882. DPRINTK ("%s: GETTRIGGER\n", __FUNCTION__);
  883. return put_user (chip->trigger, p);
  884. case SNDCTL_DSP_SETTRIGGER:
  885. if (get_user (ival, p))
  886. return -EFAULT;
  887. DPRINTK ("%s: SETTRIGGER %d\n", __FUNCTION__, ival);
  888. if (wr) {
  889. spin_lock_irq (&chip->lock);
  890. if (ival & PCM_ENABLE_OUTPUT)
  891. forte_channel_start (&chip->play);
  892. else {
  893. chip->trigger = 1;
  894. forte_channel_prep (&chip->play);
  895. forte_channel_stop (&chip->play);
  896. }
  897. spin_unlock_irq (&chip->lock);
  898. }
  899. else if (rd) {
  900. spin_lock_irq (&chip->lock);
  901. if (ival & PCM_ENABLE_INPUT)
  902. forte_channel_start (&chip->rec);
  903. else {
  904. chip->trigger = 1;
  905. forte_channel_prep (&chip->rec);
  906. forte_channel_stop (&chip->rec);
  907. }
  908. spin_unlock_irq (&chip->lock);
  909. }
  910. return 0;
  911. case SOUND_PCM_READ_RATE:
  912. DPRINTK ("%s: PCM_READ_RATE\n", __FUNCTION__);
  913. return put_user (chip->play.rate, p);
  914. case SOUND_PCM_READ_CHANNELS:
  915. DPRINTK ("%s: PCM_READ_CHANNELS\n", __FUNCTION__);
  916. return put_user (chip->play.stereo, p);
  917. case SOUND_PCM_READ_BITS:
  918. DPRINTK ("%s: PCM_READ_BITS\n", __FUNCTION__);
  919. return put_user (chip->play.format, p);
  920. case SNDCTL_DSP_NONBLOCK:
  921. DPRINTK ("%s: DSP_NONBLOCK\n", __FUNCTION__);
  922. file->f_flags |= O_NONBLOCK;
  923. return 0;
  924. default:
  925. DPRINTK ("Unsupported ioctl: %x (%p)\n", cmd, argp);
  926. break;
  927. }
  928. return -EINVAL;
  929. }
  930. /**
  931. * forte_dsp_open:
  932. */
  933. static int
  934. forte_dsp_open (struct inode *inode, struct file *file)
  935. {
  936. struct forte_chip *chip = forte; /* FIXME: HACK FROM HELL! */
  937. if (file->f_flags & O_NONBLOCK) {
  938. if (!mutex_trylock(&chip->open_mutex)) {
  939. DPRINTK ("%s: returning -EAGAIN\n", __FUNCTION__);
  940. return -EAGAIN;
  941. }
  942. }
  943. else {
  944. if (mutex_lock_interruptible(&chip->open_mutex)) {
  945. DPRINTK ("%s: returning -ERESTARTSYS\n", __FUNCTION__);
  946. return -ERESTARTSYS;
  947. }
  948. }
  949. file->private_data = forte;
  950. DPRINTK ("%s: dsp opened by %d\n", __FUNCTION__, current->pid);
  951. if (file->f_mode & FMODE_WRITE)
  952. forte_channel_init (forte, &forte->play);
  953. if (file->f_mode & FMODE_READ)
  954. forte_channel_init (forte, &forte->rec);
  955. return nonseekable_open(inode, file);
  956. }
  957. /**
  958. * forte_dsp_release:
  959. */
  960. static int
  961. forte_dsp_release (struct inode *inode, struct file *file)
  962. {
  963. struct forte_chip *chip = file->private_data;
  964. int ret = 0;
  965. DPRINTK ("%s: chip @ %p\n", __FUNCTION__, chip);
  966. if (file->f_mode & FMODE_WRITE) {
  967. forte_channel_drain (&chip->play);
  968. spin_lock_irq (&chip->lock);
  969. forte_channel_free (chip, &chip->play);
  970. spin_unlock_irq (&chip->lock);
  971. }
  972. if (file->f_mode & FMODE_READ) {
  973. while (chip->rec.filled_frags > 0)
  974. interruptible_sleep_on (&chip->rec.wait);
  975. spin_lock_irq (&chip->lock);
  976. forte_channel_stop (&chip->rec);
  977. forte_channel_free (chip, &chip->rec);
  978. spin_unlock_irq (&chip->lock);
  979. }
  980. mutex_unlock(&chip->open_mutex);
  981. return ret;
  982. }
  983. /**
  984. * forte_dsp_poll:
  985. *
  986. */
  987. static unsigned int
  988. forte_dsp_poll (struct file *file, struct poll_table_struct *wait)
  989. {
  990. struct forte_chip *chip;
  991. struct forte_channel *channel;
  992. unsigned int mask = 0;
  993. chip = file->private_data;
  994. if (file->f_mode & FMODE_WRITE) {
  995. channel = &chip->play;
  996. if (channel->active)
  997. poll_wait (file, &channel->wait, wait);
  998. spin_lock_irq (&chip->lock);
  999. if (channel->frag_num - channel->filled_frags > 0)
  1000. mask |= POLLOUT | POLLWRNORM;
  1001. spin_unlock_irq (&chip->lock);
  1002. }
  1003. if (file->f_mode & FMODE_READ) {
  1004. channel = &chip->rec;
  1005. if (channel->active)
  1006. poll_wait (file, &channel->wait, wait);
  1007. spin_lock_irq (&chip->lock);
  1008. if (channel->filled_frags > 0)
  1009. mask |= POLLIN | POLLRDNORM;
  1010. spin_unlock_irq (&chip->lock);
  1011. }
  1012. return mask;
  1013. }
  1014. /**
  1015. * forte_dsp_mmap:
  1016. */
  1017. static int
  1018. forte_dsp_mmap (struct file *file, struct vm_area_struct *vma)
  1019. {
  1020. struct forte_chip *chip;
  1021. struct forte_channel *channel;
  1022. unsigned long size;
  1023. int ret;
  1024. chip = file->private_data;
  1025. DPRINTK ("%s: start %lXh, size %ld, pgoff %ld\n", __FUNCTION__,
  1026. vma->vm_start, vma->vm_end - vma->vm_start, vma->vm_pgoff);
  1027. spin_lock_irq (&chip->lock);
  1028. if (vma->vm_flags & VM_WRITE && chip->play.active) {
  1029. ret = -EBUSY;
  1030. goto out;
  1031. }
  1032. if (vma->vm_flags & VM_READ && chip->rec.active) {
  1033. ret = -EBUSY;
  1034. goto out;
  1035. }
  1036. if (file->f_mode & FMODE_WRITE)
  1037. channel = &chip->play;
  1038. else if (file->f_mode & FMODE_READ)
  1039. channel = &chip->rec;
  1040. else {
  1041. ret = -EINVAL;
  1042. goto out;
  1043. }
  1044. forte_channel_prep (channel);
  1045. channel->mapped = 1;
  1046. if (vma->vm_pgoff != 0) {
  1047. ret = -EINVAL;
  1048. goto out;
  1049. }
  1050. size = vma->vm_end - vma->vm_start;
  1051. if (size > channel->buf_pages * PAGE_SIZE) {
  1052. DPRINTK ("%s: size (%ld) > buf_sz (%d) \n", __FUNCTION__,
  1053. size, channel->buf_sz);
  1054. ret = -EINVAL;
  1055. goto out;
  1056. }
  1057. if (remap_pfn_range(vma, vma->vm_start,
  1058. virt_to_phys(channel->buf) >> PAGE_SHIFT,
  1059. size, vma->vm_page_prot)) {
  1060. DPRINTK ("%s: remap el a no worko\n", __FUNCTION__);
  1061. ret = -EAGAIN;
  1062. goto out;
  1063. }
  1064. ret = 0;
  1065. out:
  1066. spin_unlock_irq (&chip->lock);
  1067. return ret;
  1068. }
  1069. /**
  1070. * forte_dsp_write:
  1071. */
  1072. static ssize_t
  1073. forte_dsp_write (struct file *file, const char __user *buffer, size_t bytes,
  1074. loff_t *ppos)
  1075. {
  1076. struct forte_chip *chip;
  1077. struct forte_channel *channel;
  1078. unsigned int i = bytes, sz = 0;
  1079. unsigned long flags;
  1080. if (!access_ok (VERIFY_READ, buffer, bytes))
  1081. return -EFAULT;
  1082. chip = (struct forte_chip *) file->private_data;
  1083. if (!chip)
  1084. BUG();
  1085. channel = &chip->play;
  1086. if (!channel)
  1087. BUG();
  1088. spin_lock_irqsave (&chip->lock, flags);
  1089. /* Set up buffers with the right fragment size */
  1090. forte_channel_prep (channel);
  1091. while (i) {
  1092. /* All fragment buffers in use -> wait */
  1093. if (channel->frag_num - channel->filled_frags == 0) {
  1094. DECLARE_WAITQUEUE (wait, current);
  1095. /* For trigger or non-blocking operation, get out */
  1096. if (chip->trigger || file->f_flags & O_NONBLOCK) {
  1097. spin_unlock_irqrestore (&chip->lock, flags);
  1098. return -EAGAIN;
  1099. }
  1100. /* Otherwise wait for buffers */
  1101. add_wait_queue (&channel->wait, &wait);
  1102. for (;;) {
  1103. spin_unlock_irqrestore (&chip->lock, flags);
  1104. set_current_state (TASK_INTERRUPTIBLE);
  1105. schedule();
  1106. spin_lock_irqsave (&chip->lock, flags);
  1107. if (channel->frag_num - channel->filled_frags)
  1108. break;
  1109. }
  1110. remove_wait_queue (&channel->wait, &wait);
  1111. set_current_state (TASK_RUNNING);
  1112. if (signal_pending (current)) {
  1113. spin_unlock_irqrestore (&chip->lock, flags);
  1114. return -ERESTARTSYS;
  1115. }
  1116. }
  1117. if (channel->residue)
  1118. sz = channel->residue;
  1119. else if (i > channel->frag_sz)
  1120. sz = channel->frag_sz;
  1121. else
  1122. sz = i;
  1123. spin_unlock_irqrestore (&chip->lock, flags);
  1124. if (copy_from_user ((void *) channel->buf + channel->swptr, buffer, sz))
  1125. return -EFAULT;
  1126. spin_lock_irqsave (&chip->lock, flags);
  1127. /* Advance software pointer */
  1128. buffer += sz;
  1129. channel->swptr += sz;
  1130. channel->swptr %= channel->buf_sz;
  1131. i -= sz;
  1132. /* Only bump filled_frags if a full fragment has been written */
  1133. if (channel->swptr % channel->frag_sz == 0) {
  1134. channel->filled_frags++;
  1135. channel->residue = 0;
  1136. }
  1137. else
  1138. channel->residue = channel->frag_sz - sz;
  1139. /* If playback isn't active, start it */
  1140. if (channel->active == 0 && chip->trigger == 0)
  1141. forte_channel_start (channel);
  1142. }
  1143. spin_unlock_irqrestore (&chip->lock, flags);
  1144. return bytes - i;
  1145. }
  1146. /**
  1147. * forte_dsp_read:
  1148. */
  1149. static ssize_t
  1150. forte_dsp_read (struct file *file, char __user *buffer, size_t bytes,
  1151. loff_t *ppos)
  1152. {
  1153. struct forte_chip *chip;
  1154. struct forte_channel *channel;
  1155. unsigned int i = bytes, sz;
  1156. unsigned long flags;
  1157. if (!access_ok (VERIFY_WRITE, buffer, bytes))
  1158. return -EFAULT;
  1159. chip = (struct forte_chip *) file->private_data;
  1160. if (!chip)
  1161. BUG();
  1162. channel = &chip->rec;
  1163. if (!channel)
  1164. BUG();
  1165. spin_lock_irqsave (&chip->lock, flags);
  1166. /* Set up buffers with the right fragment size */
  1167. forte_channel_prep (channel);
  1168. /* Start recording */
  1169. if (!chip->trigger)
  1170. forte_channel_start (channel);
  1171. while (i) {
  1172. /* No fragment buffers in use -> wait */
  1173. if (channel->filled_frags == 0) {
  1174. DECLARE_WAITQUEUE (wait, current);
  1175. /* For trigger mode operation, get out */
  1176. if (chip->trigger) {
  1177. spin_unlock_irqrestore (&chip->lock, flags);
  1178. return -EAGAIN;
  1179. }
  1180. add_wait_queue (&channel->wait, &wait);
  1181. for (;;) {
  1182. if (channel->active == 0)
  1183. break;
  1184. if (channel->filled_frags)
  1185. break;
  1186. spin_unlock_irqrestore (&chip->lock, flags);
  1187. set_current_state (TASK_INTERRUPTIBLE);
  1188. schedule();
  1189. spin_lock_irqsave (&chip->lock, flags);
  1190. }
  1191. set_current_state (TASK_RUNNING);
  1192. remove_wait_queue (&channel->wait, &wait);
  1193. }
  1194. if (i > channel->frag_sz)
  1195. sz = channel->frag_sz;
  1196. else
  1197. sz = i;
  1198. spin_unlock_irqrestore (&chip->lock, flags);
  1199. if (copy_to_user (buffer, (void *)channel->buf+channel->swptr, sz)) {
  1200. DPRINTK ("%s: copy_to_user failed\n", __FUNCTION__);
  1201. return -EFAULT;
  1202. }
  1203. spin_lock_irqsave (&chip->lock, flags);
  1204. /* Advance software pointer */
  1205. buffer += sz;
  1206. if (channel->filled_frags > 0)
  1207. channel->filled_frags--;
  1208. channel->swptr += channel->frag_sz;
  1209. channel->swptr %= channel->buf_sz;
  1210. i -= sz;
  1211. }
  1212. spin_unlock_irqrestore (&chip->lock, flags);
  1213. return bytes - i;
  1214. }
  1215. static struct file_operations forte_dsp_fops = {
  1216. .owner = THIS_MODULE,
  1217. .llseek = &no_llseek,
  1218. .read = &forte_dsp_read,
  1219. .write = &forte_dsp_write,
  1220. .poll = &forte_dsp_poll,
  1221. .ioctl = &forte_dsp_ioctl,
  1222. .open = &forte_dsp_open,
  1223. .release = &forte_dsp_release,
  1224. .mmap = &forte_dsp_mmap,
  1225. };
  1226. /* Common ------------------------------------------------------------------ */
  1227. /**
  1228. * forte_interrupt:
  1229. */
  1230. static irqreturn_t
  1231. forte_interrupt (int irq, void *dev_id, struct pt_regs *regs)
  1232. {
  1233. struct forte_chip *chip = dev_id;
  1234. struct forte_channel *channel = NULL;
  1235. u16 status, count;
  1236. status = inw (chip->iobase + FORTE_IRQ_STATUS);
  1237. /* If this is not for us, get outta here ASAP */
  1238. if ((status & (FORTE_IRQ_PLAYBACK | FORTE_IRQ_CAPTURE)) == 0)
  1239. return IRQ_NONE;
  1240. if (status & FORTE_IRQ_PLAYBACK) {
  1241. channel = &chip->play;
  1242. spin_lock (&chip->lock);
  1243. if (channel->frag_sz == 0)
  1244. goto pack;
  1245. /* Declare a fragment done */
  1246. if (channel->filled_frags > 0)
  1247. channel->filled_frags--;
  1248. channel->bytes += channel->frag_sz;
  1249. channel->nr_irqs++;
  1250. /* Flip-flop between buffer I and II */
  1251. channel->next_buf ^= 1;
  1252. /* Advance hardware pointer by fragment size and wrap around */
  1253. channel->hwptr += channel->frag_sz;
  1254. channel->hwptr %= channel->buf_sz;
  1255. /* Buffer I or buffer II BAR */
  1256. outl (channel->buf_handle + channel->hwptr,
  1257. channel->next_buf == 0 ?
  1258. channel->iobase + FORTE_PLY_BUF1 :
  1259. channel->iobase + FORTE_PLY_BUF2);
  1260. /* If the currently playing fragment is last, schedule pause */
  1261. if (channel->filled_frags == 1)
  1262. forte_channel_pause (channel);
  1263. pack:
  1264. /* Acknowledge interrupt */
  1265. outw (FORTE_IRQ_PLAYBACK, chip->iobase + FORTE_IRQ_STATUS);
  1266. if (waitqueue_active (&channel->wait))
  1267. wake_up_all (&channel->wait);
  1268. spin_unlock (&chip->lock);
  1269. }
  1270. if (status & FORTE_IRQ_CAPTURE) {
  1271. channel = &chip->rec;
  1272. spin_lock (&chip->lock);
  1273. /* One fragment filled */
  1274. channel->filled_frags++;
  1275. /* Get # of completed bytes */
  1276. count = inw (channel->iobase + FORTE_PLY_COUNT) + 1;
  1277. if (count == 0) {
  1278. DPRINTK ("%s: last, filled_frags = %d\n", __FUNCTION__,
  1279. channel->filled_frags);
  1280. channel->filled_frags = 0;
  1281. goto rack;
  1282. }
  1283. /* Buffer I or buffer II BAR */
  1284. outl (channel->buf_handle + channel->hwptr,
  1285. channel->next_buf == 0 ?
  1286. channel->iobase + FORTE_PLY_BUF1 :
  1287. channel->iobase + FORTE_PLY_BUF2);
  1288. /* Flip-flop between buffer I and II */
  1289. channel->next_buf ^= 1;
  1290. /* Advance hardware pointer by fragment size and wrap around */
  1291. channel->hwptr += channel->frag_sz;
  1292. channel->hwptr %= channel->buf_sz;
  1293. /* Out of buffers */
  1294. if (channel->filled_frags == channel->frag_num - 1)
  1295. forte_channel_stop (channel);
  1296. rack:
  1297. /* Acknowledge interrupt */
  1298. outw (FORTE_IRQ_CAPTURE, chip->iobase + FORTE_IRQ_STATUS);
  1299. spin_unlock (&chip->lock);
  1300. if (waitqueue_active (&channel->wait))
  1301. wake_up_all (&channel->wait);
  1302. }
  1303. return IRQ_HANDLED;
  1304. }
  1305. /**
  1306. * forte_proc_read:
  1307. */
  1308. static int
  1309. forte_proc_read (char *page, char **start, off_t off, int count,
  1310. int *eof, void *data)
  1311. {
  1312. int i = 0, p_rate, p_chan, r_rate;
  1313. unsigned short p_reg, r_reg;
  1314. i += sprintf (page, "ForteMedia FM801 OSS Lite driver\n%s\n \n",
  1315. DRIVER_VERSION);
  1316. if (!forte->iobase)
  1317. return i;
  1318. p_rate = p_chan = -1;
  1319. p_reg = inw (forte->iobase + FORTE_PLY_CTRL);
  1320. p_rate = (p_reg >> 8) & 15;
  1321. p_chan = (p_reg >> 12) & 3;
  1322. if (p_rate >= 0 || p_rate <= 10)
  1323. p_rate = rates[p_rate];
  1324. if (p_chan >= 0 || p_chan <= 2)
  1325. p_chan = channels[p_chan];
  1326. r_rate = -1;
  1327. r_reg = inw (forte->iobase + FORTE_CAP_CTRL);
  1328. r_rate = (r_reg >> 8) & 15;
  1329. if (r_rate >= 0 || r_rate <= 10)
  1330. r_rate = rates[r_rate];
  1331. i += sprintf (page + i,
  1332. " Playback Capture\n"
  1333. "FIFO empty : %-3s %-3s\n"
  1334. "Buf1 Last : %-3s %-3s\n"
  1335. "Buf2 Last : %-3s %-3s\n"
  1336. "Started : %-3s %-3s\n"
  1337. "Paused : %-3s %-3s\n"
  1338. "Immed Stop : %-3s %-3s\n"
  1339. "Rate : %-5d %-5d\n"
  1340. "Channels : %-5d -\n"
  1341. "16-bit : %-3s %-3s\n"
  1342. "Stereo : %-3s %-3s\n"
  1343. " \n"
  1344. "Buffer Sz : %-6d %-6d\n"
  1345. "Frag Sz : %-6d %-6d\n"
  1346. "Frag Num : %-6d %-6d\n"
  1347. "Frag msecs : %-6d %-6d\n"
  1348. "Used Frags : %-6d %-6d\n"
  1349. "Mapped : %-3s %-3s\n",
  1350. p_reg & 1<<0 ? "yes" : "no",
  1351. r_reg & 1<<0 ? "yes" : "no",
  1352. p_reg & 1<<1 ? "yes" : "no",
  1353. r_reg & 1<<1 ? "yes" : "no",
  1354. p_reg & 1<<2 ? "yes" : "no",
  1355. r_reg & 1<<2 ? "yes" : "no",
  1356. p_reg & 1<<5 ? "yes" : "no",
  1357. r_reg & 1<<5 ? "yes" : "no",
  1358. p_reg & 1<<6 ? "yes" : "no",
  1359. r_reg & 1<<6 ? "yes" : "no",
  1360. p_reg & 1<<7 ? "yes" : "no",
  1361. r_reg & 1<<7 ? "yes" : "no",
  1362. p_rate, r_rate,
  1363. p_chan,
  1364. p_reg & 1<<14 ? "yes" : "no",
  1365. r_reg & 1<<14 ? "yes" : "no",
  1366. p_reg & 1<<15 ? "yes" : "no",
  1367. r_reg & 1<<15 ? "yes" : "no",
  1368. forte->play.buf_sz, forte->rec.buf_sz,
  1369. forte->play.frag_sz, forte->rec.frag_sz,
  1370. forte->play.frag_num, forte->rec.frag_num,
  1371. forte->play.frag_msecs, forte->rec.frag_msecs,
  1372. forte->play.filled_frags, forte->rec.filled_frags,
  1373. forte->play.mapped ? "yes" : "no",
  1374. forte->rec.mapped ? "yes" : "no"
  1375. );
  1376. return i;
  1377. }
  1378. /**
  1379. * forte_proc_init:
  1380. *
  1381. * Creates driver info entries in /proc
  1382. */
  1383. static int __init
  1384. forte_proc_init (void)
  1385. {
  1386. if (!proc_mkdir ("driver/forte", NULL))
  1387. return -EIO;
  1388. if (!create_proc_read_entry ("driver/forte/chip", 0, NULL, forte_proc_read, forte)) {
  1389. remove_proc_entry ("driver/forte", NULL);
  1390. return -EIO;
  1391. }
  1392. if (!create_proc_read_entry("driver/forte/ac97", 0, NULL, ac97_read_proc, forte->ac97)) {
  1393. remove_proc_entry ("driver/forte/chip", NULL);
  1394. remove_proc_entry ("driver/forte", NULL);
  1395. return -EIO;
  1396. }
  1397. return 0;
  1398. }
  1399. /**
  1400. * forte_proc_remove:
  1401. *
  1402. * Removes driver info entries in /proc
  1403. */
  1404. static void
  1405. forte_proc_remove (void)
  1406. {
  1407. remove_proc_entry ("driver/forte/ac97", NULL);
  1408. remove_proc_entry ("driver/forte/chip", NULL);
  1409. remove_proc_entry ("driver/forte", NULL);
  1410. }
  1411. /**
  1412. * forte_chip_init:
  1413. * @chip: Chip instance to initialize
  1414. *
  1415. * Description:
  1416. * Resets chip, configures codec and registers the driver with
  1417. * the sound subsystem.
  1418. *
  1419. * Press and hold Start for 8 secs, then switch on Run
  1420. * and hold for 4 seconds. Let go of Start. Numbers
  1421. * assume a properly oiled TWG.
  1422. */
  1423. static int __devinit
  1424. forte_chip_init (struct forte_chip *chip)
  1425. {
  1426. u8 revision;
  1427. u16 cmdw;
  1428. struct ac97_codec *codec;
  1429. pci_read_config_byte (chip->pci_dev, PCI_REVISION_ID, &revision);
  1430. if (revision >= 0xB1) {
  1431. chip->multichannel = 1;
  1432. printk (KERN_INFO PFX "Multi-channel device detected.\n");
  1433. }
  1434. /* Reset chip */
  1435. outw (FORTE_CC_CODEC_RESET | FORTE_CC_AC97_RESET,
  1436. chip->iobase + FORTE_CODEC_CTRL);
  1437. udelay(100);
  1438. outw (0, chip->iobase + FORTE_CODEC_CTRL);
  1439. /* Request read from AC97 */
  1440. outw (FORTE_AC97_READ | (0 << FORTE_AC97_ADDR_SHIFT),
  1441. chip->iobase + FORTE_AC97_CMD);
  1442. mdelay(750);
  1443. if ((inw (chip->iobase + FORTE_AC97_CMD) & (3<<8)) != (1<<8)) {
  1444. printk (KERN_INFO PFX "AC97 codec not responding");
  1445. return -EIO;
  1446. }
  1447. /* Init volume */
  1448. outw (0x0808, chip->iobase + FORTE_PCM_VOL);
  1449. outw (0x9f1f, chip->iobase + FORTE_FM_VOL);
  1450. outw (0x8808, chip->iobase + FORTE_I2S_VOL);
  1451. /* I2S control - I2S mode */
  1452. outw (0x0003, chip->iobase + FORTE_I2S_MODE);
  1453. /* Interrupt setup - unmask PLAYBACK & CAPTURE */
  1454. cmdw = inw (chip->iobase + FORTE_IRQ_MASK);
  1455. cmdw &= ~0x0003;
  1456. outw (cmdw, chip->iobase + FORTE_IRQ_MASK);
  1457. /* Interrupt clear */
  1458. outw (FORTE_IRQ_PLAYBACK|FORTE_IRQ_CAPTURE,
  1459. chip->iobase + FORTE_IRQ_STATUS);
  1460. /* Set up the AC97 codec */
  1461. if ((codec = ac97_alloc_codec()) == NULL)
  1462. return -ENOMEM;
  1463. codec->private_data = chip;
  1464. codec->codec_read = forte_ac97_read;
  1465. codec->codec_write = forte_ac97_write;
  1466. codec->id = 0;
  1467. if (ac97_probe_codec (codec) == 0) {
  1468. printk (KERN_ERR PFX "codec probe failed\n");
  1469. ac97_release_codec(codec);
  1470. return -1;
  1471. }
  1472. /* Register mixer */
  1473. if ((codec->dev_mixer =
  1474. register_sound_mixer (&forte_mixer_fops, -1)) < 0) {
  1475. printk (KERN_ERR PFX "couldn't register mixer!\n");
  1476. ac97_release_codec(codec);
  1477. return -1;
  1478. }
  1479. chip->ac97 = codec;
  1480. /* Register DSP */
  1481. if ((chip->dsp = register_sound_dsp (&forte_dsp_fops, -1) ) < 0) {
  1482. printk (KERN_ERR PFX "couldn't register dsp!\n");
  1483. return -1;
  1484. }
  1485. /* Register with /proc */
  1486. if (forte_proc_init()) {
  1487. printk (KERN_ERR PFX "couldn't add entries to /proc!\n");
  1488. return -1;
  1489. }
  1490. return 0;
  1491. }
  1492. /**
  1493. * forte_probe:
  1494. * @pci_dev: PCI struct for probed device
  1495. * @pci_id:
  1496. *
  1497. * Description:
  1498. * Allocates chip instance, I/O region, and IRQ
  1499. */
  1500. static int __init
  1501. forte_probe (struct pci_dev *pci_dev, const struct pci_device_id *pci_id)
  1502. {
  1503. struct forte_chip *chip;
  1504. int ret = 0;
  1505. /* FIXME: Support more than one chip */
  1506. if (found++)
  1507. return -EIO;
  1508. /* Ignition */
  1509. if (pci_enable_device (pci_dev))
  1510. return -EIO;
  1511. pci_set_master (pci_dev);
  1512. /* Allocate chip instance and configure */
  1513. forte = (struct forte_chip *)
  1514. kmalloc (sizeof (struct forte_chip), GFP_KERNEL);
  1515. chip = forte;
  1516. if (chip == NULL) {
  1517. printk (KERN_WARNING PFX "Out of memory");
  1518. return -ENOMEM;
  1519. }
  1520. memset (chip, 0, sizeof (struct forte_chip));
  1521. chip->pci_dev = pci_dev;
  1522. mutex_init(&chip->open_mutex);
  1523. spin_lock_init (&chip->lock);
  1524. spin_lock_init (&chip->ac97_lock);
  1525. if (! request_region (pci_resource_start (pci_dev, 0),
  1526. pci_resource_len (pci_dev, 0), DRIVER_NAME)) {
  1527. printk (KERN_WARNING PFX "Unable to reserve I/O space");
  1528. ret = -ENOMEM;
  1529. goto error;
  1530. }
  1531. chip->iobase = pci_resource_start (pci_dev, 0);
  1532. chip->irq = pci_dev->irq;
  1533. if (request_irq (chip->irq, forte_interrupt, SA_SHIRQ, DRIVER_NAME,
  1534. chip)) {
  1535. printk (KERN_WARNING PFX "Unable to reserve IRQ");
  1536. ret = -EIO;
  1537. goto error;
  1538. }
  1539. pci_set_drvdata (pci_dev, chip);
  1540. printk (KERN_INFO PFX "FM801 chip found at 0x%04lX-0x%04lX IRQ %u\n",
  1541. chip->iobase, pci_resource_end (pci_dev, 0), chip->irq);
  1542. /* Power it up */
  1543. if ((ret = forte_chip_init (chip)) == 0)
  1544. return 0;
  1545. error:
  1546. if (chip->irq)
  1547. free_irq (chip->irq, chip);
  1548. if (chip->iobase)
  1549. release_region (pci_resource_start (pci_dev, 0),
  1550. pci_resource_len (pci_dev, 0));
  1551. kfree (chip);
  1552. return ret;
  1553. }
  1554. /**
  1555. * forte_remove:
  1556. * @pci_dev: PCI device to unclaim
  1557. *
  1558. */
  1559. static void
  1560. forte_remove (struct pci_dev *pci_dev)
  1561. {
  1562. struct forte_chip *chip = pci_get_drvdata (pci_dev);
  1563. if (chip == NULL)
  1564. return;
  1565. /* Turn volume down to avoid popping */
  1566. outw (0x1f1f, chip->iobase + FORTE_PCM_VOL);
  1567. outw (0x1f1f, chip->iobase + FORTE_FM_VOL);
  1568. outw (0x1f1f, chip->iobase + FORTE_I2S_VOL);
  1569. forte_proc_remove();
  1570. free_irq (chip->irq, chip);
  1571. release_region (chip->iobase, pci_resource_len (pci_dev, 0));
  1572. unregister_sound_dsp (chip->dsp);
  1573. unregister_sound_mixer (chip->ac97->dev_mixer);
  1574. ac97_release_codec(chip->ac97);
  1575. kfree (chip);
  1576. printk (KERN_INFO PFX "driver released\n");
  1577. }
  1578. static struct pci_device_id forte_pci_ids[] = {
  1579. { 0x1319, 0x0801, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
  1580. { 0, }
  1581. };
  1582. static struct pci_driver forte_pci_driver = {
  1583. .name = DRIVER_NAME,
  1584. .id_table = forte_pci_ids,
  1585. .probe = forte_probe,
  1586. .remove = forte_remove,
  1587. };
  1588. /**
  1589. * forte_init_module:
  1590. *
  1591. */
  1592. static int __init
  1593. forte_init_module (void)
  1594. {
  1595. printk (KERN_INFO PFX DRIVER_VERSION "\n");
  1596. return pci_register_driver (&forte_pci_driver);
  1597. }
  1598. /**
  1599. * forte_cleanup_module:
  1600. *
  1601. */
  1602. static void __exit
  1603. forte_cleanup_module (void)
  1604. {
  1605. pci_unregister_driver (&forte_pci_driver);
  1606. }
  1607. module_init(forte_init_module);
  1608. module_exit(forte_cleanup_module);
  1609. MODULE_AUTHOR("Martin K. Petersen <mkp@mkp.net>");
  1610. MODULE_DESCRIPTION("ForteMedia FM801 OSS Driver");
  1611. MODULE_LICENSE("GPL");
  1612. MODULE_DEVICE_TABLE (pci, forte_pci_ids);