fm801.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571
  1. /*
  2. * The driver for the ForteMedia FM801 based soundcards
  3. * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  4. *
  5. * Support FM only card by Andy Shevchenko <andy@smile.org.ua>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. #include <sound/driver.h>
  23. #include <linux/delay.h>
  24. #include <linux/init.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/pci.h>
  27. #include <linux/slab.h>
  28. #include <linux/moduleparam.h>
  29. #include <sound/core.h>
  30. #include <sound/pcm.h>
  31. #include <sound/ac97_codec.h>
  32. #include <sound/mpu401.h>
  33. #include <sound/opl3.h>
  34. #include <sound/initval.h>
  35. #include <asm/io.h>
  36. #ifdef CONFIG_SND_FM801_TEA575X_BOOL
  37. #include <sound/tea575x-tuner.h>
  38. #define TEA575X_RADIO 1
  39. #endif
  40. MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
  41. MODULE_DESCRIPTION("ForteMedia FM801");
  42. MODULE_LICENSE("GPL");
  43. MODULE_SUPPORTED_DEVICE("{{ForteMedia,FM801},"
  44. "{Genius,SoundMaker Live 5.1}}");
  45. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  46. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  47. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
  48. /*
  49. * Enable TEA575x tuner
  50. * 1 = MediaForte 256-PCS
  51. * 2 = MediaForte 256-PCPR
  52. * 3 = MediaForte 64-PCR
  53. * 16 = setup tuner only (this is additional bit), i.e. SF-64-PCR FM card
  54. * High 16-bits are video (radio) device number + 1
  55. */
  56. static int tea575x_tuner[SNDRV_CARDS];
  57. module_param_array(index, int, NULL, 0444);
  58. MODULE_PARM_DESC(index, "Index value for the FM801 soundcard.");
  59. module_param_array(id, charp, NULL, 0444);
  60. MODULE_PARM_DESC(id, "ID string for the FM801 soundcard.");
  61. module_param_array(enable, bool, NULL, 0444);
  62. MODULE_PARM_DESC(enable, "Enable FM801 soundcard.");
  63. module_param_array(tea575x_tuner, int, NULL, 0444);
  64. MODULE_PARM_DESC(tea575x_tuner, "Enable TEA575x tuner.");
  65. /*
  66. * Direct registers
  67. */
  68. #define FM801_REG(chip, reg) (chip->port + FM801_##reg)
  69. #define FM801_PCM_VOL 0x00 /* PCM Output Volume */
  70. #define FM801_FM_VOL 0x02 /* FM Output Volume */
  71. #define FM801_I2S_VOL 0x04 /* I2S Volume */
  72. #define FM801_REC_SRC 0x06 /* Record Source */
  73. #define FM801_PLY_CTRL 0x08 /* Playback Control */
  74. #define FM801_PLY_COUNT 0x0a /* Playback Count */
  75. #define FM801_PLY_BUF1 0x0c /* Playback Bufer I */
  76. #define FM801_PLY_BUF2 0x10 /* Playback Buffer II */
  77. #define FM801_CAP_CTRL 0x14 /* Capture Control */
  78. #define FM801_CAP_COUNT 0x16 /* Capture Count */
  79. #define FM801_CAP_BUF1 0x18 /* Capture Buffer I */
  80. #define FM801_CAP_BUF2 0x1c /* Capture Buffer II */
  81. #define FM801_CODEC_CTRL 0x22 /* Codec Control */
  82. #define FM801_I2S_MODE 0x24 /* I2S Mode Control */
  83. #define FM801_VOLUME 0x26 /* Volume Up/Down/Mute Status */
  84. #define FM801_I2C_CTRL 0x29 /* I2C Control */
  85. #define FM801_AC97_CMD 0x2a /* AC'97 Command */
  86. #define FM801_AC97_DATA 0x2c /* AC'97 Data */
  87. #define FM801_MPU401_DATA 0x30 /* MPU401 Data */
  88. #define FM801_MPU401_CMD 0x31 /* MPU401 Command */
  89. #define FM801_GPIO_CTRL 0x52 /* General Purpose I/O Control */
  90. #define FM801_GEN_CTRL 0x54 /* General Control */
  91. #define FM801_IRQ_MASK 0x56 /* Interrupt Mask */
  92. #define FM801_IRQ_STATUS 0x5a /* Interrupt Status */
  93. #define FM801_OPL3_BANK0 0x68 /* OPL3 Status Read / Bank 0 Write */
  94. #define FM801_OPL3_DATA0 0x69 /* OPL3 Data 0 Write */
  95. #define FM801_OPL3_BANK1 0x6a /* OPL3 Bank 1 Write */
  96. #define FM801_OPL3_DATA1 0x6b /* OPL3 Bank 1 Write */
  97. #define FM801_POWERDOWN 0x70 /* Blocks Power Down Control */
  98. /* codec access */
  99. #define FM801_AC97_READ (1<<7) /* read=1, write=0 */
  100. #define FM801_AC97_VALID (1<<8) /* port valid=1 */
  101. #define FM801_AC97_BUSY (1<<9) /* busy=1 */
  102. #define FM801_AC97_ADDR_SHIFT 10 /* codec id (2bit) */
  103. /* playback and record control register bits */
  104. #define FM801_BUF1_LAST (1<<1)
  105. #define FM801_BUF2_LAST (1<<2)
  106. #define FM801_START (1<<5)
  107. #define FM801_PAUSE (1<<6)
  108. #define FM801_IMMED_STOP (1<<7)
  109. #define FM801_RATE_SHIFT 8
  110. #define FM801_RATE_MASK (15 << FM801_RATE_SHIFT)
  111. #define FM801_CHANNELS_4 (1<<12) /* playback only */
  112. #define FM801_CHANNELS_6 (2<<12) /* playback only */
  113. #define FM801_CHANNELS_6MS (3<<12) /* playback only */
  114. #define FM801_CHANNELS_MASK (3<<12)
  115. #define FM801_16BIT (1<<14)
  116. #define FM801_STEREO (1<<15)
  117. /* IRQ status bits */
  118. #define FM801_IRQ_PLAYBACK (1<<8)
  119. #define FM801_IRQ_CAPTURE (1<<9)
  120. #define FM801_IRQ_VOLUME (1<<14)
  121. #define FM801_IRQ_MPU (1<<15)
  122. /* GPIO control register */
  123. #define FM801_GPIO_GP0 (1<<0) /* read/write */
  124. #define FM801_GPIO_GP1 (1<<1)
  125. #define FM801_GPIO_GP2 (1<<2)
  126. #define FM801_GPIO_GP3 (1<<3)
  127. #define FM801_GPIO_GP(x) (1<<(0+(x)))
  128. #define FM801_GPIO_GD0 (1<<8) /* directions: 1 = input, 0 = output*/
  129. #define FM801_GPIO_GD1 (1<<9)
  130. #define FM801_GPIO_GD2 (1<<10)
  131. #define FM801_GPIO_GD3 (1<<11)
  132. #define FM801_GPIO_GD(x) (1<<(8+(x)))
  133. #define FM801_GPIO_GS0 (1<<12) /* function select: */
  134. #define FM801_GPIO_GS1 (1<<13) /* 1 = GPIO */
  135. #define FM801_GPIO_GS2 (1<<14) /* 0 = other (S/PDIF, VOL) */
  136. #define FM801_GPIO_GS3 (1<<15)
  137. #define FM801_GPIO_GS(x) (1<<(12+(x)))
  138. /*
  139. */
  140. struct fm801 {
  141. int irq;
  142. unsigned long port; /* I/O port number */
  143. unsigned int multichannel: 1, /* multichannel support */
  144. secondary: 1; /* secondary codec */
  145. unsigned char secondary_addr; /* address of the secondary codec */
  146. unsigned int tea575x_tuner; /* tuner flags */
  147. unsigned short ply_ctrl; /* playback control */
  148. unsigned short cap_ctrl; /* capture control */
  149. unsigned long ply_buffer;
  150. unsigned int ply_buf;
  151. unsigned int ply_count;
  152. unsigned int ply_size;
  153. unsigned int ply_pos;
  154. unsigned long cap_buffer;
  155. unsigned int cap_buf;
  156. unsigned int cap_count;
  157. unsigned int cap_size;
  158. unsigned int cap_pos;
  159. struct snd_ac97_bus *ac97_bus;
  160. struct snd_ac97 *ac97;
  161. struct snd_ac97 *ac97_sec;
  162. struct pci_dev *pci;
  163. struct snd_card *card;
  164. struct snd_pcm *pcm;
  165. struct snd_rawmidi *rmidi;
  166. struct snd_pcm_substream *playback_substream;
  167. struct snd_pcm_substream *capture_substream;
  168. unsigned int p_dma_size;
  169. unsigned int c_dma_size;
  170. spinlock_t reg_lock;
  171. struct snd_info_entry *proc_entry;
  172. #ifdef TEA575X_RADIO
  173. struct snd_tea575x tea;
  174. #endif
  175. #ifdef CONFIG_PM
  176. u16 saved_regs[0x20];
  177. #endif
  178. };
  179. static struct pci_device_id snd_fm801_ids[] = {
  180. { 0x1319, 0x0801, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, }, /* FM801 */
  181. { 0x5213, 0x0510, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, }, /* Gallant Odyssey Sound 4 */
  182. { 0, }
  183. };
  184. MODULE_DEVICE_TABLE(pci, snd_fm801_ids);
  185. /*
  186. * common I/O routines
  187. */
  188. static int snd_fm801_update_bits(struct fm801 *chip, unsigned short reg,
  189. unsigned short mask, unsigned short value)
  190. {
  191. int change;
  192. unsigned long flags;
  193. unsigned short old, new;
  194. spin_lock_irqsave(&chip->reg_lock, flags);
  195. old = inw(chip->port + reg);
  196. new = (old & ~mask) | value;
  197. change = old != new;
  198. if (change)
  199. outw(new, chip->port + reg);
  200. spin_unlock_irqrestore(&chip->reg_lock, flags);
  201. return change;
  202. }
  203. static void snd_fm801_codec_write(struct snd_ac97 *ac97,
  204. unsigned short reg,
  205. unsigned short val)
  206. {
  207. struct fm801 *chip = ac97->private_data;
  208. int idx;
  209. /*
  210. * Wait until the codec interface is not ready..
  211. */
  212. for (idx = 0; idx < 100; idx++) {
  213. if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
  214. goto ok1;
  215. udelay(10);
  216. }
  217. snd_printk(KERN_ERR "AC'97 interface is busy (1)\n");
  218. return;
  219. ok1:
  220. /* write data and address */
  221. outw(val, FM801_REG(chip, AC97_DATA));
  222. outw(reg | (ac97->addr << FM801_AC97_ADDR_SHIFT), FM801_REG(chip, AC97_CMD));
  223. /*
  224. * Wait until the write command is not completed..
  225. */
  226. for (idx = 0; idx < 1000; idx++) {
  227. if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
  228. return;
  229. udelay(10);
  230. }
  231. snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num);
  232. }
  233. static unsigned short snd_fm801_codec_read(struct snd_ac97 *ac97, unsigned short reg)
  234. {
  235. struct fm801 *chip = ac97->private_data;
  236. int idx;
  237. /*
  238. * Wait until the codec interface is not ready..
  239. */
  240. for (idx = 0; idx < 100; idx++) {
  241. if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
  242. goto ok1;
  243. udelay(10);
  244. }
  245. snd_printk(KERN_ERR "AC'97 interface is busy (1)\n");
  246. return 0;
  247. ok1:
  248. /* read command */
  249. outw(reg | (ac97->addr << FM801_AC97_ADDR_SHIFT) | FM801_AC97_READ,
  250. FM801_REG(chip, AC97_CMD));
  251. for (idx = 0; idx < 100; idx++) {
  252. if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
  253. goto ok2;
  254. udelay(10);
  255. }
  256. snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num);
  257. return 0;
  258. ok2:
  259. for (idx = 0; idx < 1000; idx++) {
  260. if (inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_VALID)
  261. goto ok3;
  262. udelay(10);
  263. }
  264. snd_printk(KERN_ERR "AC'97 interface #%d is not valid (2)\n", ac97->num);
  265. return 0;
  266. ok3:
  267. return inw(FM801_REG(chip, AC97_DATA));
  268. }
  269. static unsigned int rates[] = {
  270. 5500, 8000, 9600, 11025,
  271. 16000, 19200, 22050, 32000,
  272. 38400, 44100, 48000
  273. };
  274. static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
  275. .count = ARRAY_SIZE(rates),
  276. .list = rates,
  277. .mask = 0,
  278. };
  279. static unsigned int channels[] = {
  280. 2, 4, 6
  281. };
  282. static struct snd_pcm_hw_constraint_list hw_constraints_channels = {
  283. .count = ARRAY_SIZE(channels),
  284. .list = channels,
  285. .mask = 0,
  286. };
  287. /*
  288. * Sample rate routines
  289. */
  290. static unsigned short snd_fm801_rate_bits(unsigned int rate)
  291. {
  292. unsigned int idx;
  293. for (idx = 0; idx < ARRAY_SIZE(rates); idx++)
  294. if (rates[idx] == rate)
  295. return idx;
  296. snd_BUG();
  297. return ARRAY_SIZE(rates) - 1;
  298. }
  299. /*
  300. * PCM part
  301. */
  302. static int snd_fm801_playback_trigger(struct snd_pcm_substream *substream,
  303. int cmd)
  304. {
  305. struct fm801 *chip = snd_pcm_substream_chip(substream);
  306. spin_lock(&chip->reg_lock);
  307. switch (cmd) {
  308. case SNDRV_PCM_TRIGGER_START:
  309. chip->ply_ctrl &= ~(FM801_BUF1_LAST |
  310. FM801_BUF2_LAST |
  311. FM801_PAUSE);
  312. chip->ply_ctrl |= FM801_START |
  313. FM801_IMMED_STOP;
  314. break;
  315. case SNDRV_PCM_TRIGGER_STOP:
  316. chip->ply_ctrl &= ~(FM801_START | FM801_PAUSE);
  317. break;
  318. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  319. case SNDRV_PCM_TRIGGER_SUSPEND:
  320. chip->ply_ctrl |= FM801_PAUSE;
  321. break;
  322. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  323. case SNDRV_PCM_TRIGGER_RESUME:
  324. chip->ply_ctrl &= ~FM801_PAUSE;
  325. break;
  326. default:
  327. spin_unlock(&chip->reg_lock);
  328. snd_BUG();
  329. return -EINVAL;
  330. }
  331. outw(chip->ply_ctrl, FM801_REG(chip, PLY_CTRL));
  332. spin_unlock(&chip->reg_lock);
  333. return 0;
  334. }
  335. static int snd_fm801_capture_trigger(struct snd_pcm_substream *substream,
  336. int cmd)
  337. {
  338. struct fm801 *chip = snd_pcm_substream_chip(substream);
  339. spin_lock(&chip->reg_lock);
  340. switch (cmd) {
  341. case SNDRV_PCM_TRIGGER_START:
  342. chip->cap_ctrl &= ~(FM801_BUF1_LAST |
  343. FM801_BUF2_LAST |
  344. FM801_PAUSE);
  345. chip->cap_ctrl |= FM801_START |
  346. FM801_IMMED_STOP;
  347. break;
  348. case SNDRV_PCM_TRIGGER_STOP:
  349. chip->cap_ctrl &= ~(FM801_START | FM801_PAUSE);
  350. break;
  351. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  352. case SNDRV_PCM_TRIGGER_SUSPEND:
  353. chip->cap_ctrl |= FM801_PAUSE;
  354. break;
  355. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  356. case SNDRV_PCM_TRIGGER_RESUME:
  357. chip->cap_ctrl &= ~FM801_PAUSE;
  358. break;
  359. default:
  360. spin_unlock(&chip->reg_lock);
  361. snd_BUG();
  362. return -EINVAL;
  363. }
  364. outw(chip->cap_ctrl, FM801_REG(chip, CAP_CTRL));
  365. spin_unlock(&chip->reg_lock);
  366. return 0;
  367. }
  368. static int snd_fm801_hw_params(struct snd_pcm_substream *substream,
  369. struct snd_pcm_hw_params *hw_params)
  370. {
  371. return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  372. }
  373. static int snd_fm801_hw_free(struct snd_pcm_substream *substream)
  374. {
  375. return snd_pcm_lib_free_pages(substream);
  376. }
  377. static int snd_fm801_playback_prepare(struct snd_pcm_substream *substream)
  378. {
  379. struct fm801 *chip = snd_pcm_substream_chip(substream);
  380. struct snd_pcm_runtime *runtime = substream->runtime;
  381. chip->ply_size = snd_pcm_lib_buffer_bytes(substream);
  382. chip->ply_count = snd_pcm_lib_period_bytes(substream);
  383. spin_lock_irq(&chip->reg_lock);
  384. chip->ply_ctrl &= ~(FM801_START | FM801_16BIT |
  385. FM801_STEREO | FM801_RATE_MASK |
  386. FM801_CHANNELS_MASK);
  387. if (snd_pcm_format_width(runtime->format) == 16)
  388. chip->ply_ctrl |= FM801_16BIT;
  389. if (runtime->channels > 1) {
  390. chip->ply_ctrl |= FM801_STEREO;
  391. if (runtime->channels == 4)
  392. chip->ply_ctrl |= FM801_CHANNELS_4;
  393. else if (runtime->channels == 6)
  394. chip->ply_ctrl |= FM801_CHANNELS_6;
  395. }
  396. chip->ply_ctrl |= snd_fm801_rate_bits(runtime->rate) << FM801_RATE_SHIFT;
  397. chip->ply_buf = 0;
  398. outw(chip->ply_ctrl, FM801_REG(chip, PLY_CTRL));
  399. outw(chip->ply_count - 1, FM801_REG(chip, PLY_COUNT));
  400. chip->ply_buffer = runtime->dma_addr;
  401. chip->ply_pos = 0;
  402. outl(chip->ply_buffer, FM801_REG(chip, PLY_BUF1));
  403. outl(chip->ply_buffer + (chip->ply_count % chip->ply_size), FM801_REG(chip, PLY_BUF2));
  404. spin_unlock_irq(&chip->reg_lock);
  405. return 0;
  406. }
  407. static int snd_fm801_capture_prepare(struct snd_pcm_substream *substream)
  408. {
  409. struct fm801 *chip = snd_pcm_substream_chip(substream);
  410. struct snd_pcm_runtime *runtime = substream->runtime;
  411. chip->cap_size = snd_pcm_lib_buffer_bytes(substream);
  412. chip->cap_count = snd_pcm_lib_period_bytes(substream);
  413. spin_lock_irq(&chip->reg_lock);
  414. chip->cap_ctrl &= ~(FM801_START | FM801_16BIT |
  415. FM801_STEREO | FM801_RATE_MASK);
  416. if (snd_pcm_format_width(runtime->format) == 16)
  417. chip->cap_ctrl |= FM801_16BIT;
  418. if (runtime->channels > 1)
  419. chip->cap_ctrl |= FM801_STEREO;
  420. chip->cap_ctrl |= snd_fm801_rate_bits(runtime->rate) << FM801_RATE_SHIFT;
  421. chip->cap_buf = 0;
  422. outw(chip->cap_ctrl, FM801_REG(chip, CAP_CTRL));
  423. outw(chip->cap_count - 1, FM801_REG(chip, CAP_COUNT));
  424. chip->cap_buffer = runtime->dma_addr;
  425. chip->cap_pos = 0;
  426. outl(chip->cap_buffer, FM801_REG(chip, CAP_BUF1));
  427. outl(chip->cap_buffer + (chip->cap_count % chip->cap_size), FM801_REG(chip, CAP_BUF2));
  428. spin_unlock_irq(&chip->reg_lock);
  429. return 0;
  430. }
  431. static snd_pcm_uframes_t snd_fm801_playback_pointer(struct snd_pcm_substream *substream)
  432. {
  433. struct fm801 *chip = snd_pcm_substream_chip(substream);
  434. size_t ptr;
  435. if (!(chip->ply_ctrl & FM801_START))
  436. return 0;
  437. spin_lock(&chip->reg_lock);
  438. ptr = chip->ply_pos + (chip->ply_count - 1) - inw(FM801_REG(chip, PLY_COUNT));
  439. if (inw(FM801_REG(chip, IRQ_STATUS)) & FM801_IRQ_PLAYBACK) {
  440. ptr += chip->ply_count;
  441. ptr %= chip->ply_size;
  442. }
  443. spin_unlock(&chip->reg_lock);
  444. return bytes_to_frames(substream->runtime, ptr);
  445. }
  446. static snd_pcm_uframes_t snd_fm801_capture_pointer(struct snd_pcm_substream *substream)
  447. {
  448. struct fm801 *chip = snd_pcm_substream_chip(substream);
  449. size_t ptr;
  450. if (!(chip->cap_ctrl & FM801_START))
  451. return 0;
  452. spin_lock(&chip->reg_lock);
  453. ptr = chip->cap_pos + (chip->cap_count - 1) - inw(FM801_REG(chip, CAP_COUNT));
  454. if (inw(FM801_REG(chip, IRQ_STATUS)) & FM801_IRQ_CAPTURE) {
  455. ptr += chip->cap_count;
  456. ptr %= chip->cap_size;
  457. }
  458. spin_unlock(&chip->reg_lock);
  459. return bytes_to_frames(substream->runtime, ptr);
  460. }
  461. static irqreturn_t snd_fm801_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  462. {
  463. struct fm801 *chip = dev_id;
  464. unsigned short status;
  465. unsigned int tmp;
  466. status = inw(FM801_REG(chip, IRQ_STATUS));
  467. status &= FM801_IRQ_PLAYBACK|FM801_IRQ_CAPTURE|FM801_IRQ_MPU|FM801_IRQ_VOLUME;
  468. if (! status)
  469. return IRQ_NONE;
  470. /* ack first */
  471. outw(status, FM801_REG(chip, IRQ_STATUS));
  472. if (chip->pcm && (status & FM801_IRQ_PLAYBACK) && chip->playback_substream) {
  473. spin_lock(&chip->reg_lock);
  474. chip->ply_buf++;
  475. chip->ply_pos += chip->ply_count;
  476. chip->ply_pos %= chip->ply_size;
  477. tmp = chip->ply_pos + chip->ply_count;
  478. tmp %= chip->ply_size;
  479. outl(chip->ply_buffer + tmp,
  480. (chip->ply_buf & 1) ?
  481. FM801_REG(chip, PLY_BUF1) :
  482. FM801_REG(chip, PLY_BUF2));
  483. spin_unlock(&chip->reg_lock);
  484. snd_pcm_period_elapsed(chip->playback_substream);
  485. }
  486. if (chip->pcm && (status & FM801_IRQ_CAPTURE) && chip->capture_substream) {
  487. spin_lock(&chip->reg_lock);
  488. chip->cap_buf++;
  489. chip->cap_pos += chip->cap_count;
  490. chip->cap_pos %= chip->cap_size;
  491. tmp = chip->cap_pos + chip->cap_count;
  492. tmp %= chip->cap_size;
  493. outl(chip->cap_buffer + tmp,
  494. (chip->cap_buf & 1) ?
  495. FM801_REG(chip, CAP_BUF1) :
  496. FM801_REG(chip, CAP_BUF2));
  497. spin_unlock(&chip->reg_lock);
  498. snd_pcm_period_elapsed(chip->capture_substream);
  499. }
  500. if (chip->rmidi && (status & FM801_IRQ_MPU))
  501. snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs);
  502. if (status & FM801_IRQ_VOLUME)
  503. ;/* TODO */
  504. return IRQ_HANDLED;
  505. }
  506. static struct snd_pcm_hardware snd_fm801_playback =
  507. {
  508. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  509. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  510. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME |
  511. SNDRV_PCM_INFO_MMAP_VALID),
  512. .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  513. .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
  514. .rate_min = 5500,
  515. .rate_max = 48000,
  516. .channels_min = 1,
  517. .channels_max = 2,
  518. .buffer_bytes_max = (128*1024),
  519. .period_bytes_min = 64,
  520. .period_bytes_max = (128*1024),
  521. .periods_min = 1,
  522. .periods_max = 1024,
  523. .fifo_size = 0,
  524. };
  525. static struct snd_pcm_hardware snd_fm801_capture =
  526. {
  527. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  528. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  529. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME |
  530. SNDRV_PCM_INFO_MMAP_VALID),
  531. .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  532. .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
  533. .rate_min = 5500,
  534. .rate_max = 48000,
  535. .channels_min = 1,
  536. .channels_max = 2,
  537. .buffer_bytes_max = (128*1024),
  538. .period_bytes_min = 64,
  539. .period_bytes_max = (128*1024),
  540. .periods_min = 1,
  541. .periods_max = 1024,
  542. .fifo_size = 0,
  543. };
  544. static int snd_fm801_playback_open(struct snd_pcm_substream *substream)
  545. {
  546. struct fm801 *chip = snd_pcm_substream_chip(substream);
  547. struct snd_pcm_runtime *runtime = substream->runtime;
  548. int err;
  549. chip->playback_substream = substream;
  550. runtime->hw = snd_fm801_playback;
  551. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  552. &hw_constraints_rates);
  553. if (chip->multichannel) {
  554. runtime->hw.channels_max = 6;
  555. snd_pcm_hw_constraint_list(runtime, 0,
  556. SNDRV_PCM_HW_PARAM_CHANNELS,
  557. &hw_constraints_channels);
  558. }
  559. if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
  560. return err;
  561. return 0;
  562. }
  563. static int snd_fm801_capture_open(struct snd_pcm_substream *substream)
  564. {
  565. struct fm801 *chip = snd_pcm_substream_chip(substream);
  566. struct snd_pcm_runtime *runtime = substream->runtime;
  567. int err;
  568. chip->capture_substream = substream;
  569. runtime->hw = snd_fm801_capture;
  570. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  571. &hw_constraints_rates);
  572. if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
  573. return err;
  574. return 0;
  575. }
  576. static int snd_fm801_playback_close(struct snd_pcm_substream *substream)
  577. {
  578. struct fm801 *chip = snd_pcm_substream_chip(substream);
  579. chip->playback_substream = NULL;
  580. return 0;
  581. }
  582. static int snd_fm801_capture_close(struct snd_pcm_substream *substream)
  583. {
  584. struct fm801 *chip = snd_pcm_substream_chip(substream);
  585. chip->capture_substream = NULL;
  586. return 0;
  587. }
  588. static struct snd_pcm_ops snd_fm801_playback_ops = {
  589. .open = snd_fm801_playback_open,
  590. .close = snd_fm801_playback_close,
  591. .ioctl = snd_pcm_lib_ioctl,
  592. .hw_params = snd_fm801_hw_params,
  593. .hw_free = snd_fm801_hw_free,
  594. .prepare = snd_fm801_playback_prepare,
  595. .trigger = snd_fm801_playback_trigger,
  596. .pointer = snd_fm801_playback_pointer,
  597. };
  598. static struct snd_pcm_ops snd_fm801_capture_ops = {
  599. .open = snd_fm801_capture_open,
  600. .close = snd_fm801_capture_close,
  601. .ioctl = snd_pcm_lib_ioctl,
  602. .hw_params = snd_fm801_hw_params,
  603. .hw_free = snd_fm801_hw_free,
  604. .prepare = snd_fm801_capture_prepare,
  605. .trigger = snd_fm801_capture_trigger,
  606. .pointer = snd_fm801_capture_pointer,
  607. };
  608. static int __devinit snd_fm801_pcm(struct fm801 *chip, int device, struct snd_pcm ** rpcm)
  609. {
  610. struct snd_pcm *pcm;
  611. int err;
  612. if (rpcm)
  613. *rpcm = NULL;
  614. if ((err = snd_pcm_new(chip->card, "FM801", device, 1, 1, &pcm)) < 0)
  615. return err;
  616. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_fm801_playback_ops);
  617. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_fm801_capture_ops);
  618. pcm->private_data = chip;
  619. pcm->info_flags = 0;
  620. strcpy(pcm->name, "FM801");
  621. chip->pcm = pcm;
  622. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  623. snd_dma_pci_data(chip->pci),
  624. chip->multichannel ? 128*1024 : 64*1024, 128*1024);
  625. if (rpcm)
  626. *rpcm = pcm;
  627. return 0;
  628. }
  629. /*
  630. * TEA5757 radio
  631. */
  632. #ifdef TEA575X_RADIO
  633. /* 256PCS GPIO numbers */
  634. #define TEA_256PCS_DATA 1
  635. #define TEA_256PCS_WRITE_ENABLE 2 /* inverted */
  636. #define TEA_256PCS_BUS_CLOCK 3
  637. static void snd_fm801_tea575x_256pcs_write(struct snd_tea575x *tea, unsigned int val)
  638. {
  639. struct fm801 *chip = tea->private_data;
  640. unsigned short reg;
  641. int i = 25;
  642. spin_lock_irq(&chip->reg_lock);
  643. reg = inw(FM801_REG(chip, GPIO_CTRL));
  644. /* use GPIO lines and set write enable bit */
  645. reg |= FM801_GPIO_GS(TEA_256PCS_DATA) |
  646. FM801_GPIO_GS(TEA_256PCS_WRITE_ENABLE) |
  647. FM801_GPIO_GS(TEA_256PCS_BUS_CLOCK);
  648. /* all of lines are in the write direction */
  649. /* clear data and clock lines */
  650. reg &= ~(FM801_GPIO_GD(TEA_256PCS_DATA) |
  651. FM801_GPIO_GD(TEA_256PCS_WRITE_ENABLE) |
  652. FM801_GPIO_GD(TEA_256PCS_BUS_CLOCK) |
  653. FM801_GPIO_GP(TEA_256PCS_DATA) |
  654. FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK) |
  655. FM801_GPIO_GP(TEA_256PCS_WRITE_ENABLE));
  656. outw(reg, FM801_REG(chip, GPIO_CTRL));
  657. udelay(1);
  658. while (i--) {
  659. if (val & (1 << i))
  660. reg |= FM801_GPIO_GP(TEA_256PCS_DATA);
  661. else
  662. reg &= ~FM801_GPIO_GP(TEA_256PCS_DATA);
  663. outw(reg, FM801_REG(chip, GPIO_CTRL));
  664. udelay(1);
  665. reg |= FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK);
  666. outw(reg, FM801_REG(chip, GPIO_CTRL));
  667. reg &= ~FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK);
  668. outw(reg, FM801_REG(chip, GPIO_CTRL));
  669. udelay(1);
  670. }
  671. /* and reset the write enable bit */
  672. reg |= FM801_GPIO_GP(TEA_256PCS_WRITE_ENABLE) |
  673. FM801_GPIO_GP(TEA_256PCS_DATA);
  674. outw(reg, FM801_REG(chip, GPIO_CTRL));
  675. spin_unlock_irq(&chip->reg_lock);
  676. }
  677. static unsigned int snd_fm801_tea575x_256pcs_read(struct snd_tea575x *tea)
  678. {
  679. struct fm801 *chip = tea->private_data;
  680. unsigned short reg;
  681. unsigned int val = 0;
  682. int i;
  683. spin_lock_irq(&chip->reg_lock);
  684. reg = inw(FM801_REG(chip, GPIO_CTRL));
  685. /* use GPIO lines, set data direction to input */
  686. reg |= FM801_GPIO_GS(TEA_256PCS_DATA) |
  687. FM801_GPIO_GS(TEA_256PCS_WRITE_ENABLE) |
  688. FM801_GPIO_GS(TEA_256PCS_BUS_CLOCK) |
  689. FM801_GPIO_GD(TEA_256PCS_DATA) |
  690. FM801_GPIO_GP(TEA_256PCS_DATA) |
  691. FM801_GPIO_GP(TEA_256PCS_WRITE_ENABLE);
  692. /* all of lines are in the write direction, except data */
  693. /* clear data, write enable and clock lines */
  694. reg &= ~(FM801_GPIO_GD(TEA_256PCS_WRITE_ENABLE) |
  695. FM801_GPIO_GD(TEA_256PCS_BUS_CLOCK) |
  696. FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK));
  697. for (i = 0; i < 24; i++) {
  698. reg &= ~FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK);
  699. outw(reg, FM801_REG(chip, GPIO_CTRL));
  700. udelay(1);
  701. reg |= FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK);
  702. outw(reg, FM801_REG(chip, GPIO_CTRL));
  703. udelay(1);
  704. val <<= 1;
  705. if (inw(FM801_REG(chip, GPIO_CTRL)) & FM801_GPIO_GP(TEA_256PCS_DATA))
  706. val |= 1;
  707. }
  708. spin_unlock_irq(&chip->reg_lock);
  709. return val;
  710. }
  711. /* 256PCPR GPIO numbers */
  712. #define TEA_256PCPR_BUS_CLOCK 0
  713. #define TEA_256PCPR_DATA 1
  714. #define TEA_256PCPR_WRITE_ENABLE 2 /* inverted */
  715. static void snd_fm801_tea575x_256pcpr_write(struct snd_tea575x *tea, unsigned int val)
  716. {
  717. struct fm801 *chip = tea->private_data;
  718. unsigned short reg;
  719. int i = 25;
  720. spin_lock_irq(&chip->reg_lock);
  721. reg = inw(FM801_REG(chip, GPIO_CTRL));
  722. /* use GPIO lines and set write enable bit */
  723. reg |= FM801_GPIO_GS(TEA_256PCPR_DATA) |
  724. FM801_GPIO_GS(TEA_256PCPR_WRITE_ENABLE) |
  725. FM801_GPIO_GS(TEA_256PCPR_BUS_CLOCK);
  726. /* all of lines are in the write direction */
  727. /* clear data and clock lines */
  728. reg &= ~(FM801_GPIO_GD(TEA_256PCPR_DATA) |
  729. FM801_GPIO_GD(TEA_256PCPR_WRITE_ENABLE) |
  730. FM801_GPIO_GD(TEA_256PCPR_BUS_CLOCK) |
  731. FM801_GPIO_GP(TEA_256PCPR_DATA) |
  732. FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK) |
  733. FM801_GPIO_GP(TEA_256PCPR_WRITE_ENABLE));
  734. outw(reg, FM801_REG(chip, GPIO_CTRL));
  735. udelay(1);
  736. while (i--) {
  737. if (val & (1 << i))
  738. reg |= FM801_GPIO_GP(TEA_256PCPR_DATA);
  739. else
  740. reg &= ~FM801_GPIO_GP(TEA_256PCPR_DATA);
  741. outw(reg, FM801_REG(chip, GPIO_CTRL));
  742. udelay(1);
  743. reg |= FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK);
  744. outw(reg, FM801_REG(chip, GPIO_CTRL));
  745. reg &= ~FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK);
  746. outw(reg, FM801_REG(chip, GPIO_CTRL));
  747. udelay(1);
  748. }
  749. /* and reset the write enable bit */
  750. reg |= FM801_GPIO_GP(TEA_256PCPR_WRITE_ENABLE) |
  751. FM801_GPIO_GP(TEA_256PCPR_DATA);
  752. outw(reg, FM801_REG(chip, GPIO_CTRL));
  753. spin_unlock_irq(&chip->reg_lock);
  754. }
  755. static unsigned int snd_fm801_tea575x_256pcpr_read(struct snd_tea575x *tea)
  756. {
  757. struct fm801 *chip = tea->private_data;
  758. unsigned short reg;
  759. unsigned int val = 0;
  760. int i;
  761. spin_lock_irq(&chip->reg_lock);
  762. reg = inw(FM801_REG(chip, GPIO_CTRL));
  763. /* use GPIO lines, set data direction to input */
  764. reg |= FM801_GPIO_GS(TEA_256PCPR_DATA) |
  765. FM801_GPIO_GS(TEA_256PCPR_WRITE_ENABLE) |
  766. FM801_GPIO_GS(TEA_256PCPR_BUS_CLOCK) |
  767. FM801_GPIO_GD(TEA_256PCPR_DATA) |
  768. FM801_GPIO_GP(TEA_256PCPR_DATA) |
  769. FM801_GPIO_GP(TEA_256PCPR_WRITE_ENABLE);
  770. /* all of lines are in the write direction, except data */
  771. /* clear data, write enable and clock lines */
  772. reg &= ~(FM801_GPIO_GD(TEA_256PCPR_WRITE_ENABLE) |
  773. FM801_GPIO_GD(TEA_256PCPR_BUS_CLOCK) |
  774. FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK));
  775. for (i = 0; i < 24; i++) {
  776. reg &= ~FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK);
  777. outw(reg, FM801_REG(chip, GPIO_CTRL));
  778. udelay(1);
  779. reg |= FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK);
  780. outw(reg, FM801_REG(chip, GPIO_CTRL));
  781. udelay(1);
  782. val <<= 1;
  783. if (inw(FM801_REG(chip, GPIO_CTRL)) & FM801_GPIO_GP(TEA_256PCPR_DATA))
  784. val |= 1;
  785. }
  786. spin_unlock_irq(&chip->reg_lock);
  787. return val;
  788. }
  789. /* 64PCR GPIO numbers */
  790. #define TEA_64PCR_BUS_CLOCK 0
  791. #define TEA_64PCR_WRITE_ENABLE 1 /* inverted */
  792. #define TEA_64PCR_DATA 2
  793. static void snd_fm801_tea575x_64pcr_write(struct snd_tea575x *tea, unsigned int val)
  794. {
  795. struct fm801 *chip = tea->private_data;
  796. unsigned short reg;
  797. int i = 25;
  798. spin_lock_irq(&chip->reg_lock);
  799. reg = inw(FM801_REG(chip, GPIO_CTRL));
  800. /* use GPIO lines and set write enable bit */
  801. reg |= FM801_GPIO_GS(TEA_64PCR_DATA) |
  802. FM801_GPIO_GS(TEA_64PCR_WRITE_ENABLE) |
  803. FM801_GPIO_GS(TEA_64PCR_BUS_CLOCK);
  804. /* all of lines are in the write direction */
  805. /* clear data and clock lines */
  806. reg &= ~(FM801_GPIO_GD(TEA_64PCR_DATA) |
  807. FM801_GPIO_GD(TEA_64PCR_WRITE_ENABLE) |
  808. FM801_GPIO_GD(TEA_64PCR_BUS_CLOCK) |
  809. FM801_GPIO_GP(TEA_64PCR_DATA) |
  810. FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK) |
  811. FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE));
  812. outw(reg, FM801_REG(chip, GPIO_CTRL));
  813. udelay(1);
  814. while (i--) {
  815. if (val & (1 << i))
  816. reg |= FM801_GPIO_GP(TEA_64PCR_DATA);
  817. else
  818. reg &= ~FM801_GPIO_GP(TEA_64PCR_DATA);
  819. outw(reg, FM801_REG(chip, GPIO_CTRL));
  820. udelay(1);
  821. reg |= FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK);
  822. outw(reg, FM801_REG(chip, GPIO_CTRL));
  823. reg &= ~FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK);
  824. outw(reg, FM801_REG(chip, GPIO_CTRL));
  825. udelay(1);
  826. }
  827. /* and reset the write enable bit */
  828. reg |= FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE) |
  829. FM801_GPIO_GP(TEA_64PCR_DATA);
  830. outw(reg, FM801_REG(chip, GPIO_CTRL));
  831. spin_unlock_irq(&chip->reg_lock);
  832. }
  833. static unsigned int snd_fm801_tea575x_64pcr_read(struct snd_tea575x *tea)
  834. {
  835. struct fm801 *chip = tea->private_data;
  836. unsigned short reg;
  837. unsigned int val = 0;
  838. int i;
  839. spin_lock_irq(&chip->reg_lock);
  840. reg = inw(FM801_REG(chip, GPIO_CTRL));
  841. /* use GPIO lines, set data direction to input */
  842. reg |= FM801_GPIO_GS(TEA_64PCR_DATA) |
  843. FM801_GPIO_GS(TEA_64PCR_WRITE_ENABLE) |
  844. FM801_GPIO_GS(TEA_64PCR_BUS_CLOCK) |
  845. FM801_GPIO_GD(TEA_64PCR_DATA) |
  846. FM801_GPIO_GP(TEA_64PCR_DATA) |
  847. FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE);
  848. /* all of lines are in the write direction, except data */
  849. /* clear data, write enable and clock lines */
  850. reg &= ~(FM801_GPIO_GD(TEA_64PCR_WRITE_ENABLE) |
  851. FM801_GPIO_GD(TEA_64PCR_BUS_CLOCK) |
  852. FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK));
  853. for (i = 0; i < 24; i++) {
  854. reg &= ~FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK);
  855. outw(reg, FM801_REG(chip, GPIO_CTRL));
  856. udelay(1);
  857. reg |= FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK);
  858. outw(reg, FM801_REG(chip, GPIO_CTRL));
  859. udelay(1);
  860. val <<= 1;
  861. if (inw(FM801_REG(chip, GPIO_CTRL)) & FM801_GPIO_GP(TEA_64PCR_DATA))
  862. val |= 1;
  863. }
  864. spin_unlock_irq(&chip->reg_lock);
  865. return val;
  866. }
  867. static struct snd_tea575x_ops snd_fm801_tea_ops[3] = {
  868. {
  869. /* 1 = MediaForte 256-PCS */
  870. .write = snd_fm801_tea575x_256pcs_write,
  871. .read = snd_fm801_tea575x_256pcs_read,
  872. },
  873. {
  874. /* 2 = MediaForte 256-PCPR */
  875. .write = snd_fm801_tea575x_256pcpr_write,
  876. .read = snd_fm801_tea575x_256pcpr_read,
  877. },
  878. {
  879. /* 3 = MediaForte 64-PCR */
  880. .write = snd_fm801_tea575x_64pcr_write,
  881. .read = snd_fm801_tea575x_64pcr_read,
  882. }
  883. };
  884. #endif
  885. /*
  886. * Mixer routines
  887. */
  888. #define FM801_SINGLE(xname, reg, shift, mask, invert) \
  889. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_fm801_info_single, \
  890. .get = snd_fm801_get_single, .put = snd_fm801_put_single, \
  891. .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
  892. static int snd_fm801_info_single(struct snd_kcontrol *kcontrol,
  893. struct snd_ctl_elem_info *uinfo)
  894. {
  895. int mask = (kcontrol->private_value >> 16) & 0xff;
  896. uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
  897. uinfo->count = 1;
  898. uinfo->value.integer.min = 0;
  899. uinfo->value.integer.max = mask;
  900. return 0;
  901. }
  902. static int snd_fm801_get_single(struct snd_kcontrol *kcontrol,
  903. struct snd_ctl_elem_value *ucontrol)
  904. {
  905. struct fm801 *chip = snd_kcontrol_chip(kcontrol);
  906. int reg = kcontrol->private_value & 0xff;
  907. int shift = (kcontrol->private_value >> 8) & 0xff;
  908. int mask = (kcontrol->private_value >> 16) & 0xff;
  909. int invert = (kcontrol->private_value >> 24) & 0xff;
  910. ucontrol->value.integer.value[0] = (inw(chip->port + reg) >> shift) & mask;
  911. if (invert)
  912. ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
  913. return 0;
  914. }
  915. static int snd_fm801_put_single(struct snd_kcontrol *kcontrol,
  916. struct snd_ctl_elem_value *ucontrol)
  917. {
  918. struct fm801 *chip = snd_kcontrol_chip(kcontrol);
  919. int reg = kcontrol->private_value & 0xff;
  920. int shift = (kcontrol->private_value >> 8) & 0xff;
  921. int mask = (kcontrol->private_value >> 16) & 0xff;
  922. int invert = (kcontrol->private_value >> 24) & 0xff;
  923. unsigned short val;
  924. val = (ucontrol->value.integer.value[0] & mask);
  925. if (invert)
  926. val = mask - val;
  927. return snd_fm801_update_bits(chip, reg, mask << shift, val << shift);
  928. }
  929. #define FM801_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \
  930. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_fm801_info_double, \
  931. .get = snd_fm801_get_double, .put = snd_fm801_put_double, \
  932. .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24) }
  933. static int snd_fm801_info_double(struct snd_kcontrol *kcontrol,
  934. struct snd_ctl_elem_info *uinfo)
  935. {
  936. int mask = (kcontrol->private_value >> 16) & 0xff;
  937. uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
  938. uinfo->count = 2;
  939. uinfo->value.integer.min = 0;
  940. uinfo->value.integer.max = mask;
  941. return 0;
  942. }
  943. static int snd_fm801_get_double(struct snd_kcontrol *kcontrol,
  944. struct snd_ctl_elem_value *ucontrol)
  945. {
  946. struct fm801 *chip = snd_kcontrol_chip(kcontrol);
  947. int reg = kcontrol->private_value & 0xff;
  948. int shift_left = (kcontrol->private_value >> 8) & 0x0f;
  949. int shift_right = (kcontrol->private_value >> 12) & 0x0f;
  950. int mask = (kcontrol->private_value >> 16) & 0xff;
  951. int invert = (kcontrol->private_value >> 24) & 0xff;
  952. spin_lock_irq(&chip->reg_lock);
  953. ucontrol->value.integer.value[0] = (inw(chip->port + reg) >> shift_left) & mask;
  954. ucontrol->value.integer.value[1] = (inw(chip->port + reg) >> shift_right) & mask;
  955. spin_unlock_irq(&chip->reg_lock);
  956. if (invert) {
  957. ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
  958. ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
  959. }
  960. return 0;
  961. }
  962. static int snd_fm801_put_double(struct snd_kcontrol *kcontrol,
  963. struct snd_ctl_elem_value *ucontrol)
  964. {
  965. struct fm801 *chip = snd_kcontrol_chip(kcontrol);
  966. int reg = kcontrol->private_value & 0xff;
  967. int shift_left = (kcontrol->private_value >> 8) & 0x0f;
  968. int shift_right = (kcontrol->private_value >> 12) & 0x0f;
  969. int mask = (kcontrol->private_value >> 16) & 0xff;
  970. int invert = (kcontrol->private_value >> 24) & 0xff;
  971. unsigned short val1, val2;
  972. val1 = ucontrol->value.integer.value[0] & mask;
  973. val2 = ucontrol->value.integer.value[1] & mask;
  974. if (invert) {
  975. val1 = mask - val1;
  976. val2 = mask - val2;
  977. }
  978. return snd_fm801_update_bits(chip, reg,
  979. (mask << shift_left) | (mask << shift_right),
  980. (val1 << shift_left ) | (val2 << shift_right));
  981. }
  982. static int snd_fm801_info_mux(struct snd_kcontrol *kcontrol,
  983. struct snd_ctl_elem_info *uinfo)
  984. {
  985. static char *texts[5] = {
  986. "AC97 Primary", "FM", "I2S", "PCM", "AC97 Secondary"
  987. };
  988. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  989. uinfo->count = 1;
  990. uinfo->value.enumerated.items = 5;
  991. if (uinfo->value.enumerated.item > 4)
  992. uinfo->value.enumerated.item = 4;
  993. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  994. return 0;
  995. }
  996. static int snd_fm801_get_mux(struct snd_kcontrol *kcontrol,
  997. struct snd_ctl_elem_value *ucontrol)
  998. {
  999. struct fm801 *chip = snd_kcontrol_chip(kcontrol);
  1000. unsigned short val;
  1001. val = inw(FM801_REG(chip, REC_SRC)) & 7;
  1002. if (val > 4)
  1003. val = 4;
  1004. ucontrol->value.enumerated.item[0] = val;
  1005. return 0;
  1006. }
  1007. static int snd_fm801_put_mux(struct snd_kcontrol *kcontrol,
  1008. struct snd_ctl_elem_value *ucontrol)
  1009. {
  1010. struct fm801 *chip = snd_kcontrol_chip(kcontrol);
  1011. unsigned short val;
  1012. if ((val = ucontrol->value.enumerated.item[0]) > 4)
  1013. return -EINVAL;
  1014. return snd_fm801_update_bits(chip, FM801_REC_SRC, 7, val);
  1015. }
  1016. #define FM801_CONTROLS ARRAY_SIZE(snd_fm801_controls)
  1017. static struct snd_kcontrol_new snd_fm801_controls[] __devinitdata = {
  1018. FM801_DOUBLE("Wave Playback Volume", FM801_PCM_VOL, 0, 8, 31, 1),
  1019. FM801_SINGLE("Wave Playback Switch", FM801_PCM_VOL, 15, 1, 1),
  1020. FM801_DOUBLE("I2S Playback Volume", FM801_I2S_VOL, 0, 8, 31, 1),
  1021. FM801_SINGLE("I2S Playback Switch", FM801_I2S_VOL, 15, 1, 1),
  1022. FM801_DOUBLE("FM Playback Volume", FM801_FM_VOL, 0, 8, 31, 1),
  1023. FM801_SINGLE("FM Playback Switch", FM801_FM_VOL, 15, 1, 1),
  1024. {
  1025. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1026. .name = "Digital Capture Source",
  1027. .info = snd_fm801_info_mux,
  1028. .get = snd_fm801_get_mux,
  1029. .put = snd_fm801_put_mux,
  1030. }
  1031. };
  1032. #define FM801_CONTROLS_MULTI ARRAY_SIZE(snd_fm801_controls_multi)
  1033. static struct snd_kcontrol_new snd_fm801_controls_multi[] __devinitdata = {
  1034. FM801_SINGLE("AC97 2ch->4ch Copy Switch", FM801_CODEC_CTRL, 7, 1, 0),
  1035. FM801_SINGLE("AC97 18-bit Switch", FM801_CODEC_CTRL, 10, 1, 0),
  1036. FM801_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), FM801_I2S_MODE, 8, 1, 0),
  1037. FM801_SINGLE(SNDRV_CTL_NAME_IEC958("Raw Data ",PLAYBACK,SWITCH), FM801_I2S_MODE, 9, 1, 0),
  1038. FM801_SINGLE(SNDRV_CTL_NAME_IEC958("Raw Data ",CAPTURE,SWITCH), FM801_I2S_MODE, 10, 1, 0),
  1039. FM801_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), FM801_GEN_CTRL, 2, 1, 0),
  1040. };
  1041. static void snd_fm801_mixer_free_ac97_bus(struct snd_ac97_bus *bus)
  1042. {
  1043. struct fm801 *chip = bus->private_data;
  1044. chip->ac97_bus = NULL;
  1045. }
  1046. static void snd_fm801_mixer_free_ac97(struct snd_ac97 *ac97)
  1047. {
  1048. struct fm801 *chip = ac97->private_data;
  1049. if (ac97->num == 0) {
  1050. chip->ac97 = NULL;
  1051. } else {
  1052. chip->ac97_sec = NULL;
  1053. }
  1054. }
  1055. static int __devinit snd_fm801_mixer(struct fm801 *chip)
  1056. {
  1057. struct snd_ac97_template ac97;
  1058. unsigned int i;
  1059. int err;
  1060. static struct snd_ac97_bus_ops ops = {
  1061. .write = snd_fm801_codec_write,
  1062. .read = snd_fm801_codec_read,
  1063. };
  1064. if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus)) < 0)
  1065. return err;
  1066. chip->ac97_bus->private_free = snd_fm801_mixer_free_ac97_bus;
  1067. memset(&ac97, 0, sizeof(ac97));
  1068. ac97.private_data = chip;
  1069. ac97.private_free = snd_fm801_mixer_free_ac97;
  1070. if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0)
  1071. return err;
  1072. if (chip->secondary) {
  1073. ac97.num = 1;
  1074. ac97.addr = chip->secondary_addr;
  1075. if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97_sec)) < 0)
  1076. return err;
  1077. }
  1078. for (i = 0; i < FM801_CONTROLS; i++)
  1079. snd_ctl_add(chip->card, snd_ctl_new1(&snd_fm801_controls[i], chip));
  1080. if (chip->multichannel) {
  1081. for (i = 0; i < FM801_CONTROLS_MULTI; i++)
  1082. snd_ctl_add(chip->card, snd_ctl_new1(&snd_fm801_controls_multi[i], chip));
  1083. }
  1084. return 0;
  1085. }
  1086. /*
  1087. * initialization routines
  1088. */
  1089. static int wait_for_codec(struct fm801 *chip, unsigned int codec_id,
  1090. unsigned short reg, unsigned long waits)
  1091. {
  1092. unsigned long timeout = jiffies + waits;
  1093. outw(FM801_AC97_READ | (codec_id << FM801_AC97_ADDR_SHIFT) | reg,
  1094. FM801_REG(chip, AC97_CMD));
  1095. udelay(5);
  1096. do {
  1097. if ((inw(FM801_REG(chip, AC97_CMD)) & (FM801_AC97_VALID|FM801_AC97_BUSY))
  1098. == FM801_AC97_VALID)
  1099. return 0;
  1100. schedule_timeout_uninterruptible(1);
  1101. } while (time_after(timeout, jiffies));
  1102. return -EIO;
  1103. }
  1104. static int snd_fm801_chip_init(struct fm801 *chip, int resume)
  1105. {
  1106. int id;
  1107. unsigned short cmdw;
  1108. if (chip->tea575x_tuner & 0x0010)
  1109. goto __ac97_ok;
  1110. /* codec cold reset + AC'97 warm reset */
  1111. outw((1<<5) | (1<<6), FM801_REG(chip, CODEC_CTRL));
  1112. inw(FM801_REG(chip, CODEC_CTRL)); /* flush posting data */
  1113. udelay(100);
  1114. outw(0, FM801_REG(chip, CODEC_CTRL));
  1115. if (wait_for_codec(chip, 0, AC97_RESET, msecs_to_jiffies(750)) < 0) {
  1116. snd_printk(KERN_ERR "Primary AC'97 codec not found\n");
  1117. if (! resume)
  1118. return -EIO;
  1119. }
  1120. if (chip->multichannel) {
  1121. if (chip->secondary_addr) {
  1122. wait_for_codec(chip, chip->secondary_addr,
  1123. AC97_VENDOR_ID1, msecs_to_jiffies(50));
  1124. } else {
  1125. /* my card has the secondary codec */
  1126. /* at address #3, so the loop is inverted */
  1127. for (id = 3; id > 0; id--) {
  1128. if (! wait_for_codec(chip, id, AC97_VENDOR_ID1,
  1129. msecs_to_jiffies(50))) {
  1130. cmdw = inw(FM801_REG(chip, AC97_DATA));
  1131. if (cmdw != 0xffff && cmdw != 0) {
  1132. chip->secondary = 1;
  1133. chip->secondary_addr = id;
  1134. break;
  1135. }
  1136. }
  1137. }
  1138. }
  1139. /* the recovery phase, it seems that probing for non-existing codec might */
  1140. /* cause timeout problems */
  1141. wait_for_codec(chip, 0, AC97_VENDOR_ID1, msecs_to_jiffies(750));
  1142. }
  1143. __ac97_ok:
  1144. /* init volume */
  1145. outw(0x0808, FM801_REG(chip, PCM_VOL));
  1146. outw(0x9f1f, FM801_REG(chip, FM_VOL));
  1147. outw(0x8808, FM801_REG(chip, I2S_VOL));
  1148. /* I2S control - I2S mode */
  1149. outw(0x0003, FM801_REG(chip, I2S_MODE));
  1150. /* interrupt setup */
  1151. cmdw = inw(FM801_REG(chip, IRQ_MASK));
  1152. if (chip->irq < 0)
  1153. cmdw |= 0x00c3; /* mask everything, no PCM nor MPU */
  1154. else
  1155. cmdw &= ~0x0083; /* unmask MPU, PLAYBACK & CAPTURE */
  1156. outw(cmdw, FM801_REG(chip, IRQ_MASK));
  1157. /* interrupt clear */
  1158. outw(FM801_IRQ_PLAYBACK|FM801_IRQ_CAPTURE|FM801_IRQ_MPU, FM801_REG(chip, IRQ_STATUS));
  1159. return 0;
  1160. }
  1161. static int snd_fm801_free(struct fm801 *chip)
  1162. {
  1163. unsigned short cmdw;
  1164. if (chip->irq < 0)
  1165. goto __end_hw;
  1166. /* interrupt setup - mask everything */
  1167. cmdw = inw(FM801_REG(chip, IRQ_MASK));
  1168. cmdw |= 0x00c3;
  1169. outw(cmdw, FM801_REG(chip, IRQ_MASK));
  1170. __end_hw:
  1171. #ifdef TEA575X_RADIO
  1172. snd_tea575x_exit(&chip->tea);
  1173. #endif
  1174. if (chip->irq >= 0)
  1175. free_irq(chip->irq, chip);
  1176. pci_release_regions(chip->pci);
  1177. pci_disable_device(chip->pci);
  1178. kfree(chip);
  1179. return 0;
  1180. }
  1181. static int snd_fm801_dev_free(struct snd_device *device)
  1182. {
  1183. struct fm801 *chip = device->device_data;
  1184. return snd_fm801_free(chip);
  1185. }
  1186. static int __devinit snd_fm801_create(struct snd_card *card,
  1187. struct pci_dev * pci,
  1188. int tea575x_tuner,
  1189. struct fm801 ** rchip)
  1190. {
  1191. struct fm801 *chip;
  1192. unsigned char rev;
  1193. int err;
  1194. static struct snd_device_ops ops = {
  1195. .dev_free = snd_fm801_dev_free,
  1196. };
  1197. *rchip = NULL;
  1198. if ((err = pci_enable_device(pci)) < 0)
  1199. return err;
  1200. chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  1201. if (chip == NULL) {
  1202. pci_disable_device(pci);
  1203. return -ENOMEM;
  1204. }
  1205. spin_lock_init(&chip->reg_lock);
  1206. chip->card = card;
  1207. chip->pci = pci;
  1208. chip->irq = -1;
  1209. chip->tea575x_tuner = tea575x_tuner;
  1210. if ((err = pci_request_regions(pci, "FM801")) < 0) {
  1211. kfree(chip);
  1212. pci_disable_device(pci);
  1213. return err;
  1214. }
  1215. chip->port = pci_resource_start(pci, 0);
  1216. if ((tea575x_tuner & 0x0010) == 0) {
  1217. if (request_irq(pci->irq, snd_fm801_interrupt, IRQF_DISABLED|IRQF_SHARED,
  1218. "FM801", chip)) {
  1219. snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->irq);
  1220. snd_fm801_free(chip);
  1221. return -EBUSY;
  1222. }
  1223. chip->irq = pci->irq;
  1224. pci_set_master(pci);
  1225. }
  1226. pci_read_config_byte(pci, PCI_REVISION_ID, &rev);
  1227. if (rev >= 0xb1) /* FM801-AU */
  1228. chip->multichannel = 1;
  1229. snd_fm801_chip_init(chip, 0);
  1230. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
  1231. snd_fm801_free(chip);
  1232. return err;
  1233. }
  1234. snd_card_set_dev(card, &pci->dev);
  1235. #ifdef TEA575X_RADIO
  1236. if (tea575x_tuner > 0 && (tea575x_tuner & 0x000f) < 4) {
  1237. chip->tea.dev_nr = tea575x_tuner >> 16;
  1238. chip->tea.card = card;
  1239. chip->tea.freq_fixup = 10700;
  1240. chip->tea.private_data = chip;
  1241. chip->tea.ops = &snd_fm801_tea_ops[(tea575x_tuner & 0x000f) - 1];
  1242. snd_tea575x_init(&chip->tea);
  1243. }
  1244. #endif
  1245. *rchip = chip;
  1246. return 0;
  1247. }
  1248. static int __devinit snd_card_fm801_probe(struct pci_dev *pci,
  1249. const struct pci_device_id *pci_id)
  1250. {
  1251. static int dev;
  1252. struct snd_card *card;
  1253. struct fm801 *chip;
  1254. struct snd_opl3 *opl3;
  1255. int err;
  1256. if (dev >= SNDRV_CARDS)
  1257. return -ENODEV;
  1258. if (!enable[dev]) {
  1259. dev++;
  1260. return -ENOENT;
  1261. }
  1262. card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
  1263. if (card == NULL)
  1264. return -ENOMEM;
  1265. if ((err = snd_fm801_create(card, pci, tea575x_tuner[dev], &chip)) < 0) {
  1266. snd_card_free(card);
  1267. return err;
  1268. }
  1269. card->private_data = chip;
  1270. strcpy(card->driver, "FM801");
  1271. strcpy(card->shortname, "ForteMedia FM801-");
  1272. strcat(card->shortname, chip->multichannel ? "AU" : "AS");
  1273. sprintf(card->longname, "%s at 0x%lx, irq %i",
  1274. card->shortname, chip->port, chip->irq);
  1275. if (tea575x_tuner[dev] & 0x0010)
  1276. goto __fm801_tuner_only;
  1277. if ((err = snd_fm801_pcm(chip, 0, NULL)) < 0) {
  1278. snd_card_free(card);
  1279. return err;
  1280. }
  1281. if ((err = snd_fm801_mixer(chip)) < 0) {
  1282. snd_card_free(card);
  1283. return err;
  1284. }
  1285. if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_FM801,
  1286. FM801_REG(chip, MPU401_DATA),
  1287. MPU401_INFO_INTEGRATED,
  1288. chip->irq, 0, &chip->rmidi)) < 0) {
  1289. snd_card_free(card);
  1290. return err;
  1291. }
  1292. if ((err = snd_opl3_create(card, FM801_REG(chip, OPL3_BANK0),
  1293. FM801_REG(chip, OPL3_BANK1),
  1294. OPL3_HW_OPL3_FM801, 1, &opl3)) < 0) {
  1295. snd_card_free(card);
  1296. return err;
  1297. }
  1298. if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
  1299. snd_card_free(card);
  1300. return err;
  1301. }
  1302. __fm801_tuner_only:
  1303. if ((err = snd_card_register(card)) < 0) {
  1304. snd_card_free(card);
  1305. return err;
  1306. }
  1307. pci_set_drvdata(pci, card);
  1308. dev++;
  1309. return 0;
  1310. }
  1311. static void __devexit snd_card_fm801_remove(struct pci_dev *pci)
  1312. {
  1313. snd_card_free(pci_get_drvdata(pci));
  1314. pci_set_drvdata(pci, NULL);
  1315. }
  1316. #ifdef CONFIG_PM
  1317. static unsigned char saved_regs[] = {
  1318. FM801_PCM_VOL, FM801_I2S_VOL, FM801_FM_VOL, FM801_REC_SRC,
  1319. FM801_PLY_CTRL, FM801_PLY_COUNT, FM801_PLY_BUF1, FM801_PLY_BUF2,
  1320. FM801_CAP_CTRL, FM801_CAP_COUNT, FM801_CAP_BUF1, FM801_CAP_BUF2,
  1321. FM801_CODEC_CTRL, FM801_I2S_MODE, FM801_VOLUME, FM801_GEN_CTRL,
  1322. };
  1323. static int snd_fm801_suspend(struct pci_dev *pci, pm_message_t state)
  1324. {
  1325. struct snd_card *card = pci_get_drvdata(pci);
  1326. struct fm801 *chip = card->private_data;
  1327. int i;
  1328. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  1329. snd_pcm_suspend_all(chip->pcm);
  1330. snd_ac97_suspend(chip->ac97);
  1331. snd_ac97_suspend(chip->ac97_sec);
  1332. for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
  1333. chip->saved_regs[i] = inw(chip->port + saved_regs[i]);
  1334. /* FIXME: tea575x suspend */
  1335. pci_set_power_state(pci, PCI_D3hot);
  1336. pci_disable_device(pci);
  1337. pci_save_state(pci);
  1338. return 0;
  1339. }
  1340. static int snd_fm801_resume(struct pci_dev *pci)
  1341. {
  1342. struct snd_card *card = pci_get_drvdata(pci);
  1343. struct fm801 *chip = card->private_data;
  1344. int i;
  1345. pci_restore_state(pci);
  1346. pci_enable_device(pci);
  1347. pci_set_power_state(pci, PCI_D0);
  1348. pci_set_master(pci);
  1349. snd_fm801_chip_init(chip, 1);
  1350. snd_ac97_resume(chip->ac97);
  1351. snd_ac97_resume(chip->ac97_sec);
  1352. for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
  1353. outw(chip->saved_regs[i], chip->port + saved_regs[i]);
  1354. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  1355. return 0;
  1356. }
  1357. #endif
  1358. static struct pci_driver driver = {
  1359. .name = "FM801",
  1360. .id_table = snd_fm801_ids,
  1361. .probe = snd_card_fm801_probe,
  1362. .remove = __devexit_p(snd_card_fm801_remove),
  1363. #ifdef CONFIG_PM
  1364. .suspend = snd_fm801_suspend,
  1365. .resume = snd_fm801_resume,
  1366. #endif
  1367. };
  1368. static int __init alsa_card_fm801_init(void)
  1369. {
  1370. return pci_register_driver(&driver);
  1371. }
  1372. static void __exit alsa_card_fm801_exit(void)
  1373. {
  1374. pci_unregister_driver(&driver);
  1375. }
  1376. module_init(alsa_card_fm801_init)
  1377. module_exit(alsa_card_fm801_exit)