Changeset 679 for GPL/trunk/alsa-kernel/pci/fm801.c
- Timestamp:
- Mar 18, 2021, 8:57:36 PM (4 years ago)
- Location:
- GPL/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GPL/trunk
- Property svn:mergeinfo changed
/GPL/branches/uniaud32-linux-3.2.102 (added) merged: 611-614 /GPL/branches/uniaud32-next (added) merged: 615-678
- Property svn:mergeinfo changed
-
GPL/trunk/alsa-kernel/pci/fm801.c
r598 r679 1 // SPDX-License-Identifier: GPL-2.0-or-later 1 2 /* 2 3 * The driver for the ForteMedia FM801 based soundcards 3 4 * Copyright (c) by Jaroslav Kysela <perex@perex.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 modify8 * it under the terms of the GNU General Public License as published by9 * the Free Software Foundation; either version 2 of the License, or10 * (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 of14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15 * GNU General Public License for more details.16 *17 * You should have received a copy of the GNU General Public License18 * along with this program; if not, write to the Free Software19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA20 *21 5 */ 22 6 … … 24 8 #include <linux/init.h> 25 9 #include <linux/interrupt.h> 10 #include <linux/io.h> 26 11 #include <linux/pci.h> 27 12 #include <linux/slab.h> 28 #include <linux/module param.h>13 #include <linux/module.h> 29 14 #include <sound/core.h> 30 15 #include <sound/pcm.h> … … 35 20 #include <sound/initval.h> 36 21 37 #include <asm/io.h> 22 #ifdef TARGET_OS2 23 #define KBUILD_MODNAME "fm801" 24 #endif 38 25 39 26 #ifdef CONFIG_SND_FM801_TEA575X_BOOL 40 #include <sound/tea575x-tuner.h> 41 #define TEA575X_RADIO 1 27 #include <media/drv-intf/tea575x.h> 42 28 #endif 43 29 … … 50 36 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 51 37 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 52 static intenable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */38 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 53 39 /* 54 40 * Enable TEA575x tuner 55 41 * 1 = MediaForte 256-PCS 56 * 2 = MediaForte 256-PCP R42 * 2 = MediaForte 256-PCP 57 43 * 3 = MediaForte 64-PCR 58 44 * 16 = setup tuner only (this is additional bit), i.e. SF64-PCR FM card … … 60 46 */ 61 47 static int tea575x_tuner[SNDRV_CARDS]; 48 #ifndef TARGET_OS2 49 static int radio_nr[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1}; 50 #else 51 static int radio_nr[SNDRV_CARDS] = { REPEAT_SNDRV(1) }; 52 #endif 62 53 63 54 module_param_array(index, int, NULL, 0444); … … 68 59 MODULE_PARM_DESC(enable, "Enable FM801 soundcard."); 69 60 module_param_array(tea575x_tuner, int, NULL, 0444); 70 MODULE_PARM_DESC(tea575x_tuner, "TEA575x tuner access method (1 = SF256-PCS, 2=SF256-PCPR, 3=SF64-PCR, +16=tuner-only)."); 71 61 MODULE_PARM_DESC(tea575x_tuner, "TEA575x tuner access method (0 = auto, 1 = SF256-PCS, 2=SF256-PCP, 3=SF64-PCR, 8=disable, +16=tuner-only)."); 62 module_param_array(radio_nr, int, NULL, 0444); 63 MODULE_PARM_DESC(radio_nr, "Radio device numbers"); 64 65 66 #define TUNER_DISABLED (1<<3) 72 67 #define TUNER_ONLY (1<<4) 73 68 #define TUNER_TYPE_MASK (~TUNER_ONLY & 0xFFFF) … … 77 72 */ 78 73 79 #define FM801_REG(chip, reg) (chip->port + FM801_##reg) 74 #define fm801_writew(chip,reg,value) outw((value), chip->port + FM801_##reg) 75 #define fm801_readw(chip,reg) inw(chip->port + FM801_##reg) 76 77 #define fm801_writel(chip,reg,value) outl((value), chip->port + FM801_##reg) 80 78 81 79 #define FM801_PCM_VOL 0x00 /* PCM Output Volume */ … … 153 151 #define FM801_GPIO_GS(x) (1<<(12+(x))) 154 152 155 /* 156 153 /** 154 * struct fm801 - describes FM801 chip 155 * @dev: device for this chio 156 * @irq: irq number 157 * @port: I/O port number 158 * @multichannel: multichannel support 159 * @secondary: secondary codec 160 * @secondary_addr: address of the secondary codec 161 * @tea575x_tuner: tuner access method & flags 162 * @ply_ctrl: playback control 163 * @cap_ctrl: capture control 164 * @ply_buffer: playback buffer 165 * @ply_buf: playback buffer index 166 * @ply_count: playback buffer count 167 * @ply_size: playback buffer size 168 * @ply_pos: playback position 169 * @cap_buffer: capture buffer 170 * @cap_buf: capture buffer index 171 * @cap_count: capture buffer count 172 * @cap_size: capture buffer size 173 * @cap_pos: capture position 174 * @ac97_bus: ac97 bus handle 175 * @ac97: ac97 handle 176 * @ac97_sec: ac97 secondary handle 177 * @card: ALSA card 178 * @pcm: PCM devices 179 * @rmidi: rmidi device 180 * @playback_substream: substream for playback 181 * @capture_substream: substream for capture 182 * @p_dma_size: playback DMA size 183 * @c_dma_size: capture DMA size 184 * @reg_lock: lock 185 * @proc_entry: /proc entry 186 * @v4l2_dev: v4l2 device 187 * @tea: tea575a structure 188 * @saved_regs: context saved during suspend 157 189 */ 158 159 190 struct fm801 { 191 struct device *dev; 160 192 int irq; 161 193 162 unsigned long port; /* I/O port number */163 unsigned int multichannel: 1, /* multichannel support */164 secondary: 1; /* secondary codec */165 unsigned char secondary_addr; /* address of the secondary codec */166 unsigned int tea575x_tuner; /* tuner access method & flags */167 168 unsigned short ply_ctrl; /* playback control */169 unsigned short cap_ctrl; /* capture control */194 unsigned long port; 195 unsigned int multichannel: 1, 196 secondary: 1; 197 unsigned char secondary_addr; 198 unsigned int tea575x_tuner; 199 200 unsigned short ply_ctrl; 201 unsigned short cap_ctrl; 170 202 171 203 unsigned long ply_buffer; … … 185 217 struct snd_ac97 *ac97_sec; 186 218 187 struct pci_dev *pci;188 219 struct snd_card *card; 189 220 struct snd_pcm *pcm; … … 197 228 struct snd_info_entry *proc_entry; 198 229 199 #ifdef TEA575X_RADIO 230 #ifdef CONFIG_SND_FM801_TEA575X_BOOL 231 struct v4l2_device v4l2_dev; 200 232 struct snd_tea575x tea; 201 233 #endif 202 234 203 #ifdef CONFIG_PM 235 #ifdef CONFIG_PM_SLEEP 204 236 u16 saved_regs[0x20]; 205 237 #endif 206 238 }; 207 239 208 static DEFINE_PCI_DEVICE_TABLE(snd_fm801_ids) = { 240 /* 241 * IO accessors 242 */ 243 244 static inline void fm801_iowrite16(struct fm801 *chip, unsigned short offset, u16 value) 245 { 246 outw(value, chip->port + offset); 247 } 248 249 static inline u16 fm801_ioread16(struct fm801 *chip, unsigned short offset) 250 { 251 return inw(chip->port + offset); 252 } 253 254 static const struct pci_device_id snd_fm801_ids[] = { 209 255 { 0x1319, 0x0801, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, }, /* FM801 */ 210 256 { 0x5213, 0x0510, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, }, /* Gallant Odyssey Sound 4 */ … … 218 264 */ 219 265 266 static bool fm801_ac97_is_ready(struct fm801 *chip, unsigned int iterations) 267 { 268 unsigned int idx; 269 270 for (idx = 0; idx < iterations; idx++) { 271 if (!(fm801_readw(chip, AC97_CMD) & FM801_AC97_BUSY)) 272 return true; 273 udelay(10); 274 } 275 return false; 276 } 277 278 static bool fm801_ac97_is_valid(struct fm801 *chip, unsigned int iterations) 279 { 280 unsigned int idx; 281 282 for (idx = 0; idx < iterations; idx++) { 283 if (fm801_readw(chip, AC97_CMD) & FM801_AC97_VALID) 284 return true; 285 udelay(10); 286 } 287 return false; 288 } 289 220 290 static int snd_fm801_update_bits(struct fm801 *chip, unsigned short reg, 221 291 unsigned short mask, unsigned short value) … … 226 296 227 297 spin_lock_irqsave(&chip->reg_lock, flags); 228 old = inw(chip->port +reg);298 old = fm801_ioread16(chip, reg); 229 299 new = (old & ~mask) | value; 230 300 change = old != new; 231 301 if (change) 232 outw(new, chip->port + reg);302 fm801_iowrite16(chip, reg, new); 233 303 spin_unlock_irqrestore(&chip->reg_lock, flags); 234 304 return change; … … 240 310 { 241 311 struct fm801 *chip = ac97->private_data; 242 int idx;243 312 244 313 /* 245 314 * Wait until the codec interface is not ready.. 246 315 */ 247 for (idx = 0; idx < 100; idx++) { 248 if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY)) 249 goto ok1; 250 udelay(10); 251 } 252 snd_printk(KERN_ERR "AC'97 interface is busy (1)\n"); 253 return; 254 255 ok1: 316 if (!fm801_ac97_is_ready(chip, 100)) { 317 dev_err(chip->card->dev, "AC'97 interface is busy (1)\n"); 318 return; 319 } 320 256 321 /* write data and address */ 257 outw(val, FM801_REG(chip, AC97_DATA));258 outw(reg | (ac97->addr << FM801_AC97_ADDR_SHIFT), FM801_REG(chip, AC97_CMD));322 fm801_writew(chip, AC97_DATA, val); 323 fm801_writew(chip, AC97_CMD, reg | (ac97->addr << FM801_AC97_ADDR_SHIFT)); 259 324 /* 260 325 * Wait until the write command is not completed.. 261 */ 262 for (idx = 0; idx < 1000; idx++) { 263 if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY)) 264 return; 265 udelay(10); 266 } 267 snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num); 326 */ 327 if (!fm801_ac97_is_ready(chip, 1000)) 328 dev_err(chip->card->dev, "AC'97 interface #%d is busy (2)\n", 329 ac97->num); 268 330 } 269 331 … … 271 333 { 272 334 struct fm801 *chip = ac97->private_data; 273 int idx;274 335 275 336 /* 276 337 * Wait until the codec interface is not ready.. 277 338 */ 278 for (idx = 0; idx < 100; idx++) { 279 if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY)) 280 goto ok1; 281 udelay(10); 282 } 283 snd_printk(KERN_ERR "AC'97 interface is busy (1)\n"); 284 return 0; 285 286 ok1: 339 if (!fm801_ac97_is_ready(chip, 100)) { 340 dev_err(chip->card->dev, "AC'97 interface is busy (1)\n"); 341 return 0; 342 } 343 287 344 /* read command */ 288 outw(reg | (ac97->addr << FM801_AC97_ADDR_SHIFT) | FM801_AC97_READ, 289 FM801_REG(chip, AC97_CMD)); 290 for (idx = 0; idx < 100; idx++) { 291 if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY)) 292 goto ok2; 293 udelay(10); 294 } 295 snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num); 296 return 0; 297 298 ok2: 299 for (idx = 0; idx < 1000; idx++) { 300 if (inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_VALID) 301 goto ok3; 302 udelay(10); 303 } 304 snd_printk(KERN_ERR "AC'97 interface #%d is not valid (2)\n", ac97->num); 305 return 0; 306 307 ok3: 308 return inw(FM801_REG(chip, AC97_DATA)); 309 } 310 311 static unsigned int rates[] = { 345 fm801_writew(chip, AC97_CMD, 346 reg | (ac97->addr << FM801_AC97_ADDR_SHIFT) | FM801_AC97_READ); 347 if (!fm801_ac97_is_ready(chip, 100)) { 348 dev_err(chip->card->dev, "AC'97 interface #%d is busy (2)\n", 349 ac97->num); 350 return 0; 351 } 352 353 if (!fm801_ac97_is_valid(chip, 1000)) { 354 dev_err(chip->card->dev, 355 "AC'97 interface #%d is not valid (2)\n", ac97->num); 356 return 0; 357 } 358 359 return fm801_readw(chip, AC97_DATA); 360 } 361 362 static const unsigned int rates[] = { 312 363 5500, 8000, 9600, 11025, 313 364 16000, 19200, 22050, 32000, … … 315 366 }; 316 367 317 static struct snd_pcm_hw_constraint_list hw_constraints_rates = {368 static const struct snd_pcm_hw_constraint_list hw_constraints_rates = { 318 369 .count = ARRAY_SIZE(rates), 319 370 .list = rates, … … 321 372 }; 322 373 323 static unsigned int channels[] = {374 static const unsigned int channels[] = { 324 375 2, 4, 6 325 376 }; 326 377 327 static struct snd_pcm_hw_constraint_list hw_constraints_channels = {378 static const struct snd_pcm_hw_constraint_list hw_constraints_channels = { 328 379 .count = ARRAY_SIZE(channels), 329 380 .list = channels, … … 380 431 return -EINVAL; 381 432 } 382 outw(chip->ply_ctrl, FM801_REG(chip, PLY_CTRL));433 fm801_writew(chip, PLY_CTRL, chip->ply_ctrl); 383 434 spin_unlock(&chip->reg_lock); 384 435 return 0; … … 415 466 return -EINVAL; 416 467 } 417 outw(chip->cap_ctrl, FM801_REG(chip, CAP_CTRL));468 fm801_writew(chip, CAP_CTRL, chip->cap_ctrl); 418 469 spin_unlock(&chip->reg_lock); 419 470 return 0; 420 }421 422 static int snd_fm801_hw_params(struct snd_pcm_substream *substream,423 struct snd_pcm_hw_params *hw_params)424 {425 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));426 }427 428 static int snd_fm801_hw_free(struct snd_pcm_substream *substream)429 {430 return snd_pcm_lib_free_pages(substream);431 471 } 432 472 … … 453 493 chip->ply_ctrl |= snd_fm801_rate_bits(runtime->rate) << FM801_RATE_SHIFT; 454 494 chip->ply_buf = 0; 455 outw(chip->ply_ctrl, FM801_REG(chip, PLY_CTRL));456 outw(chip->ply_count - 1, FM801_REG(chip, PLY_COUNT));495 fm801_writew(chip, PLY_CTRL, chip->ply_ctrl); 496 fm801_writew(chip, PLY_COUNT, chip->ply_count - 1); 457 497 chip->ply_buffer = runtime->dma_addr; 458 498 chip->ply_pos = 0; 459 outl(chip->ply_buffer, FM801_REG(chip, PLY_BUF1)); 460 outl(chip->ply_buffer + (chip->ply_count % chip->ply_size), FM801_REG(chip, PLY_BUF2)); 499 fm801_writel(chip, PLY_BUF1, chip->ply_buffer); 500 fm801_writel(chip, PLY_BUF2, 501 chip->ply_buffer + (chip->ply_count % chip->ply_size)); 461 502 spin_unlock_irq(&chip->reg_lock); 462 503 return 0; … … 479 520 chip->cap_ctrl |= snd_fm801_rate_bits(runtime->rate) << FM801_RATE_SHIFT; 480 521 chip->cap_buf = 0; 481 outw(chip->cap_ctrl, FM801_REG(chip, CAP_CTRL));482 outw(chip->cap_count - 1, FM801_REG(chip, CAP_COUNT));522 fm801_writew(chip, CAP_CTRL, chip->cap_ctrl); 523 fm801_writew(chip, CAP_COUNT, chip->cap_count - 1); 483 524 chip->cap_buffer = runtime->dma_addr; 484 525 chip->cap_pos = 0; 485 outl(chip->cap_buffer, FM801_REG(chip, CAP_BUF1)); 486 outl(chip->cap_buffer + (chip->cap_count % chip->cap_size), FM801_REG(chip, CAP_BUF2)); 526 fm801_writel(chip, CAP_BUF1, chip->cap_buffer); 527 fm801_writel(chip, CAP_BUF2, 528 chip->cap_buffer + (chip->cap_count % chip->cap_size)); 487 529 spin_unlock_irq(&chip->reg_lock); 488 530 return 0; … … 497 539 return 0; 498 540 spin_lock(&chip->reg_lock); 499 ptr = chip->ply_pos + (chip->ply_count - 1) - inw(FM801_REG(chip, PLY_COUNT));500 if ( inw(FM801_REG(chip, IRQ_STATUS)) & FM801_IRQ_PLAYBACK) {541 ptr = chip->ply_pos + (chip->ply_count - 1) - fm801_readw(chip, PLY_COUNT); 542 if (fm801_readw(chip, IRQ_STATUS) & FM801_IRQ_PLAYBACK) { 501 543 ptr += chip->ply_count; 502 544 ptr %= chip->ply_size; … … 514 556 return 0; 515 557 spin_lock(&chip->reg_lock); 516 ptr = chip->cap_pos + (chip->cap_count - 1) - inw(FM801_REG(chip, CAP_COUNT));517 if ( inw(FM801_REG(chip, IRQ_STATUS)) & FM801_IRQ_CAPTURE) {558 ptr = chip->cap_pos + (chip->cap_count - 1) - fm801_readw(chip, CAP_COUNT); 559 if (fm801_readw(chip, IRQ_STATUS) & FM801_IRQ_CAPTURE) { 518 560 ptr += chip->cap_count; 519 561 ptr %= chip->cap_size; … … 529 571 unsigned int tmp; 530 572 531 status = inw(FM801_REG(chip, IRQ_STATUS));573 status = fm801_readw(chip, IRQ_STATUS); 532 574 status &= FM801_IRQ_PLAYBACK|FM801_IRQ_CAPTURE|FM801_IRQ_MPU|FM801_IRQ_VOLUME; 533 575 if (! status) 534 576 return IRQ_NONE; 535 577 /* ack first */ 536 outw(status, FM801_REG(chip, IRQ_STATUS));578 fm801_writew(chip, IRQ_STATUS, status); 537 579 if (chip->pcm && (status & FM801_IRQ_PLAYBACK) && chip->playback_substream) { 538 580 spin_lock(&chip->reg_lock); … … 542 584 tmp = chip->ply_pos + chip->ply_count; 543 585 tmp %= chip->ply_size; 544 outl(chip->ply_buffer + tmp,545 (chip->ply_buf & 1) ?546 FM801_REG(chip, PLY_BUF1) :547 FM801_REG(chip, PLY_BUF2));586 if (chip->ply_buf & 1) 587 fm801_writel(chip, PLY_BUF1, chip->ply_buffer + tmp); 588 else 589 fm801_writel(chip, PLY_BUF2, chip->ply_buffer + tmp); 548 590 spin_unlock(&chip->reg_lock); 549 591 snd_pcm_period_elapsed(chip->playback_substream); … … 556 598 tmp = chip->cap_pos + chip->cap_count; 557 599 tmp %= chip->cap_size; 558 outl(chip->cap_buffer + tmp,559 (chip->cap_buf & 1) ?560 FM801_REG(chip, CAP_BUF1) :561 FM801_REG(chip, CAP_BUF2));600 if (chip->cap_buf & 1) 601 fm801_writel(chip, CAP_BUF1, chip->cap_buffer + tmp); 602 else 603 fm801_writel(chip, CAP_BUF2, chip->cap_buffer + tmp); 562 604 spin_unlock(&chip->reg_lock); 563 605 snd_pcm_period_elapsed(chip->capture_substream); … … 565 607 if (chip->rmidi && (status & FM801_IRQ_MPU)) 566 608 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data); 567 if (status & FM801_IRQ_VOLUME) 568 ;/* TODO */ 609 if (status & FM801_IRQ_VOLUME) { 610 /* TODO */ 611 } 569 612 570 613 return IRQ_HANDLED; 571 614 } 572 615 573 static struct snd_pcm_hardware snd_fm801_playback =616 static const struct snd_pcm_hardware snd_fm801_playback = 574 617 { 575 618 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | … … 591 634 }; 592 635 593 static struct snd_pcm_hardware snd_fm801_capture =636 static const struct snd_pcm_hardware snd_fm801_capture = 594 637 { 595 638 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | … … 663 706 } 664 707 665 static struct snd_pcm_ops snd_fm801_playback_ops = {708 static const struct snd_pcm_ops snd_fm801_playback_ops = { 666 709 .open = snd_fm801_playback_open, 667 710 .close = snd_fm801_playback_close, 668 .ioctl = snd_pcm_lib_ioctl,669 .hw_params = snd_fm801_hw_params,670 .hw_free = snd_fm801_hw_free,671 711 .prepare = snd_fm801_playback_prepare, 672 712 .trigger = snd_fm801_playback_trigger, … … 674 714 }; 675 715 676 static struct snd_pcm_ops snd_fm801_capture_ops = {716 static const struct snd_pcm_ops snd_fm801_capture_ops = { 677 717 .open = snd_fm801_capture_open, 678 718 .close = snd_fm801_capture_close, 679 .ioctl = snd_pcm_lib_ioctl,680 .hw_params = snd_fm801_hw_params,681 .hw_free = snd_fm801_hw_free,682 719 .prepare = snd_fm801_capture_prepare, 683 720 .trigger = snd_fm801_capture_trigger, … … 685 722 }; 686 723 687 static int __devinit snd_fm801_pcm(struct fm801 *chip, int device, struct snd_pcm ** rpcm) 688 { 724 static int snd_fm801_pcm(struct fm801 *chip, int device) 725 { 726 struct pci_dev *pdev = to_pci_dev(chip->dev); 689 727 struct snd_pcm *pcm; 690 728 int err; 691 729 692 if (rpcm)693 *rpcm = NULL;694 730 if ((err = snd_pcm_new(chip->card, "FM801", device, 1, 1, &pcm)) < 0) 695 731 return err; … … 703 739 chip->pcm = pcm; 704 740 705 snd_pcm_ lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,706 snd_dma_pci_data(chip->pci),707 chip->multichannel ? 128*1024 : 64*1024, 128*1024); 708 709 if (rpcm)710 *rpcm = pcm;711 return 0;741 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, &pdev->dev, 742 chip->multichannel ? 128*1024 : 64*1024, 128*1024); 743 744 return snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK, 745 snd_pcm_alt_chmaps, 746 chip->multichannel ? 6 : 2, 0, 747 NULL); 712 748 } 713 749 … … 716 752 */ 717 753 718 #ifdef TEA575X_RADIO 719 720 /* 256PCS GPIO numbers */ 721 #define TEA_256PCS_DATA 1 722 #define TEA_256PCS_WRITE_ENABLE 2 /* inverted */ 723 #define TEA_256PCS_BUS_CLOCK 3 724 725 static void snd_fm801_tea575x_256pcs_write(struct snd_tea575x *tea, unsigned int val) 754 #ifdef CONFIG_SND_FM801_TEA575X_BOOL 755 756 /* GPIO to TEA575x maps */ 757 struct snd_fm801_tea575x_gpio { 758 u8 data, clk, wren, most; 759 char *name; 760 }; 761 762 static const struct snd_fm801_tea575x_gpio snd_fm801_tea575x_gpios[] = { 763 { .data = 1, .clk = 3, .wren = 2, .most = 0, .name = "SF256-PCS" }, 764 { .data = 1, .clk = 0, .wren = 2, .most = 3, .name = "SF256-PCP" }, 765 { .data = 2, .clk = 0, .wren = 1, .most = 3, .name = "SF64-PCR" }, 766 }; 767 768 #define get_tea575x_gpio(chip) \ 769 (&snd_fm801_tea575x_gpios[((chip)->tea575x_tuner & TUNER_TYPE_MASK) - 1]) 770 771 static void snd_fm801_tea575x_set_pins(struct snd_tea575x *tea, u8 pins) 726 772 { 727 773 struct fm801 *chip = tea->private_data; 728 unsigned short reg; 729 int i = 25; 730 731 spin_lock_irq(&chip->reg_lock); 732 reg = inw(FM801_REG(chip, GPIO_CTRL)); 774 unsigned short reg = fm801_readw(chip, GPIO_CTRL); 775 struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip); 776 777 reg &= ~(FM801_GPIO_GP(gpio.data) | 778 FM801_GPIO_GP(gpio.clk) | 779 FM801_GPIO_GP(gpio.wren)); 780 781 reg |= (pins & TEA575X_DATA) ? FM801_GPIO_GP(gpio.data) : 0; 782 reg |= (pins & TEA575X_CLK) ? FM801_GPIO_GP(gpio.clk) : 0; 783 /* WRITE_ENABLE is inverted */ 784 reg |= (pins & TEA575X_WREN) ? 0 : FM801_GPIO_GP(gpio.wren); 785 786 fm801_writew(chip, GPIO_CTRL, reg); 787 } 788 789 static u8 snd_fm801_tea575x_get_pins(struct snd_tea575x *tea) 790 { 791 struct fm801 *chip = tea->private_data; 792 unsigned short reg = fm801_readw(chip, GPIO_CTRL); 793 struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip); 794 u8 ret; 795 796 ret = 0; 797 if (reg & FM801_GPIO_GP(gpio.data)) 798 ret |= TEA575X_DATA; 799 if (reg & FM801_GPIO_GP(gpio.most)) 800 ret |= TEA575X_MOST; 801 return ret; 802 } 803 804 static void snd_fm801_tea575x_set_direction(struct snd_tea575x *tea, bool output) 805 { 806 struct fm801 *chip = tea->private_data; 807 unsigned short reg = fm801_readw(chip, GPIO_CTRL); 808 struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip); 809 733 810 /* use GPIO lines and set write enable bit */ 734 reg |= FM801_GPIO_GS(TEA_256PCS_DATA) | 735 FM801_GPIO_GS(TEA_256PCS_WRITE_ENABLE) | 736 FM801_GPIO_GS(TEA_256PCS_BUS_CLOCK); 737 /* all of lines are in the write direction */ 738 /* clear data and clock lines */ 739 reg &= ~(FM801_GPIO_GD(TEA_256PCS_DATA) | 740 FM801_GPIO_GD(TEA_256PCS_WRITE_ENABLE) | 741 FM801_GPIO_GD(TEA_256PCS_BUS_CLOCK) | 742 FM801_GPIO_GP(TEA_256PCS_DATA) | 743 FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK) | 744 FM801_GPIO_GP(TEA_256PCS_WRITE_ENABLE)); 745 outw(reg, FM801_REG(chip, GPIO_CTRL)); 746 udelay(1); 747 748 while (i--) { 749 if (val & (1 << i)) 750 reg |= FM801_GPIO_GP(TEA_256PCS_DATA); 751 else 752 reg &= ~FM801_GPIO_GP(TEA_256PCS_DATA); 753 outw(reg, FM801_REG(chip, GPIO_CTRL)); 754 udelay(1); 755 reg |= FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK); 756 outw(reg, FM801_REG(chip, GPIO_CTRL)); 757 reg &= ~FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK); 758 outw(reg, FM801_REG(chip, GPIO_CTRL)); 759 udelay(1); 760 } 761 762 /* and reset the write enable bit */ 763 reg |= FM801_GPIO_GP(TEA_256PCS_WRITE_ENABLE) | 764 FM801_GPIO_GP(TEA_256PCS_DATA); 765 outw(reg, FM801_REG(chip, GPIO_CTRL)); 766 spin_unlock_irq(&chip->reg_lock); 767 } 768 769 static unsigned int snd_fm801_tea575x_256pcs_read(struct snd_tea575x *tea) 770 { 771 struct fm801 *chip = tea->private_data; 772 unsigned short reg; 773 unsigned int val = 0; 774 int i; 775 776 spin_lock_irq(&chip->reg_lock); 777 reg = inw(FM801_REG(chip, GPIO_CTRL)); 778 /* use GPIO lines, set data direction to input */ 779 reg |= FM801_GPIO_GS(TEA_256PCS_DATA) | 780 FM801_GPIO_GS(TEA_256PCS_WRITE_ENABLE) | 781 FM801_GPIO_GS(TEA_256PCS_BUS_CLOCK) | 782 FM801_GPIO_GD(TEA_256PCS_DATA) | 783 FM801_GPIO_GP(TEA_256PCS_DATA) | 784 FM801_GPIO_GP(TEA_256PCS_WRITE_ENABLE); 785 /* all of lines are in the write direction, except data */ 786 /* clear data, write enable and clock lines */ 787 reg &= ~(FM801_GPIO_GD(TEA_256PCS_WRITE_ENABLE) | 788 FM801_GPIO_GD(TEA_256PCS_BUS_CLOCK) | 789 FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK)); 790 791 for (i = 0; i < 24; i++) { 792 reg &= ~FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK); 793 outw(reg, FM801_REG(chip, GPIO_CTRL)); 794 udelay(1); 795 reg |= FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK); 796 outw(reg, FM801_REG(chip, GPIO_CTRL)); 797 udelay(1); 798 val <<= 1; 799 if (inw(FM801_REG(chip, GPIO_CTRL)) & FM801_GPIO_GP(TEA_256PCS_DATA)) 800 val |= 1; 801 } 802 803 spin_unlock_irq(&chip->reg_lock); 804 805 return val; 806 } 807 808 /* 256PCPR GPIO numbers */ 809 #define TEA_256PCPR_BUS_CLOCK 0 810 #define TEA_256PCPR_DATA 1 811 #define TEA_256PCPR_WRITE_ENABLE 2 /* inverted */ 812 813 static void snd_fm801_tea575x_256pcpr_write(struct snd_tea575x *tea, unsigned int val) 814 { 815 struct fm801 *chip = tea->private_data; 816 unsigned short reg; 817 int i = 25; 818 819 spin_lock_irq(&chip->reg_lock); 820 reg = inw(FM801_REG(chip, GPIO_CTRL)); 821 /* use GPIO lines and set write enable bit */ 822 reg |= FM801_GPIO_GS(TEA_256PCPR_DATA) | 823 FM801_GPIO_GS(TEA_256PCPR_WRITE_ENABLE) | 824 FM801_GPIO_GS(TEA_256PCPR_BUS_CLOCK); 825 /* all of lines are in the write direction */ 826 /* clear data and clock lines */ 827 reg &= ~(FM801_GPIO_GD(TEA_256PCPR_DATA) | 828 FM801_GPIO_GD(TEA_256PCPR_WRITE_ENABLE) | 829 FM801_GPIO_GD(TEA_256PCPR_BUS_CLOCK) | 830 FM801_GPIO_GP(TEA_256PCPR_DATA) | 831 FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK) | 832 FM801_GPIO_GP(TEA_256PCPR_WRITE_ENABLE)); 833 outw(reg, FM801_REG(chip, GPIO_CTRL)); 834 udelay(1); 835 836 while (i--) { 837 if (val & (1 << i)) 838 reg |= FM801_GPIO_GP(TEA_256PCPR_DATA); 839 else 840 reg &= ~FM801_GPIO_GP(TEA_256PCPR_DATA); 841 outw(reg, FM801_REG(chip, GPIO_CTRL)); 842 udelay(1); 843 reg |= FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK); 844 outw(reg, FM801_REG(chip, GPIO_CTRL)); 845 reg &= ~FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK); 846 outw(reg, FM801_REG(chip, GPIO_CTRL)); 847 udelay(1); 848 } 849 850 /* and reset the write enable bit */ 851 reg |= FM801_GPIO_GP(TEA_256PCPR_WRITE_ENABLE) | 852 FM801_GPIO_GP(TEA_256PCPR_DATA); 853 outw(reg, FM801_REG(chip, GPIO_CTRL)); 854 spin_unlock_irq(&chip->reg_lock); 855 } 856 857 static unsigned int snd_fm801_tea575x_256pcpr_read(struct snd_tea575x *tea) 858 { 859 struct fm801 *chip = tea->private_data; 860 unsigned short reg; 861 unsigned int val = 0; 862 int i; 863 864 spin_lock_irq(&chip->reg_lock); 865 reg = inw(FM801_REG(chip, GPIO_CTRL)); 866 /* use GPIO lines, set data direction to input */ 867 reg |= FM801_GPIO_GS(TEA_256PCPR_DATA) | 868 FM801_GPIO_GS(TEA_256PCPR_WRITE_ENABLE) | 869 FM801_GPIO_GS(TEA_256PCPR_BUS_CLOCK) | 870 FM801_GPIO_GD(TEA_256PCPR_DATA) | 871 FM801_GPIO_GP(TEA_256PCPR_DATA) | 872 FM801_GPIO_GP(TEA_256PCPR_WRITE_ENABLE); 873 /* all of lines are in the write direction, except data */ 874 /* clear data, write enable and clock lines */ 875 reg &= ~(FM801_GPIO_GD(TEA_256PCPR_WRITE_ENABLE) | 876 FM801_GPIO_GD(TEA_256PCPR_BUS_CLOCK) | 877 FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK)); 878 879 for (i = 0; i < 24; i++) { 880 reg &= ~FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK); 881 outw(reg, FM801_REG(chip, GPIO_CTRL)); 882 udelay(1); 883 reg |= FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK); 884 outw(reg, FM801_REG(chip, GPIO_CTRL)); 885 udelay(1); 886 val <<= 1; 887 if (inw(FM801_REG(chip, GPIO_CTRL)) & FM801_GPIO_GP(TEA_256PCPR_DATA)) 888 val |= 1; 889 } 890 891 spin_unlock_irq(&chip->reg_lock); 892 893 return val; 894 } 895 896 /* 64PCR GPIO numbers */ 897 #define TEA_64PCR_BUS_CLOCK 0 898 #define TEA_64PCR_WRITE_ENABLE 1 /* inverted */ 899 #define TEA_64PCR_DATA 2 900 901 static void snd_fm801_tea575x_64pcr_write(struct snd_tea575x *tea, unsigned int val) 902 { 903 struct fm801 *chip = tea->private_data; 904 unsigned short reg; 905 int i = 25; 906 907 spin_lock_irq(&chip->reg_lock); 908 reg = inw(FM801_REG(chip, GPIO_CTRL)); 909 /* use GPIO lines and set write enable bit */ 910 reg |= FM801_GPIO_GS(TEA_64PCR_DATA) | 911 FM801_GPIO_GS(TEA_64PCR_WRITE_ENABLE) | 912 FM801_GPIO_GS(TEA_64PCR_BUS_CLOCK); 913 /* all of lines are in the write direction */ 914 /* clear data and clock lines */ 915 reg &= ~(FM801_GPIO_GD(TEA_64PCR_DATA) | 916 FM801_GPIO_GD(TEA_64PCR_WRITE_ENABLE) | 917 FM801_GPIO_GD(TEA_64PCR_BUS_CLOCK) | 918 FM801_GPIO_GP(TEA_64PCR_DATA) | 919 FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK) | 920 FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE)); 921 outw(reg, FM801_REG(chip, GPIO_CTRL)); 922 udelay(1); 923 924 while (i--) { 925 if (val & (1 << i)) 926 reg |= FM801_GPIO_GP(TEA_64PCR_DATA); 927 else 928 reg &= ~FM801_GPIO_GP(TEA_64PCR_DATA); 929 outw(reg, FM801_REG(chip, GPIO_CTRL)); 930 udelay(1); 931 reg |= FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK); 932 outw(reg, FM801_REG(chip, GPIO_CTRL)); 933 reg &= ~FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK); 934 outw(reg, FM801_REG(chip, GPIO_CTRL)); 935 udelay(1); 936 } 937 938 /* and reset the write enable bit */ 939 reg |= FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE) | 940 FM801_GPIO_GP(TEA_64PCR_DATA); 941 outw(reg, FM801_REG(chip, GPIO_CTRL)); 942 spin_unlock_irq(&chip->reg_lock); 943 } 944 945 static unsigned int snd_fm801_tea575x_64pcr_read(struct snd_tea575x *tea) 946 { 947 struct fm801 *chip = tea->private_data; 948 unsigned short reg; 949 unsigned int val = 0; 950 int i; 951 952 spin_lock_irq(&chip->reg_lock); 953 reg = inw(FM801_REG(chip, GPIO_CTRL)); 954 /* use GPIO lines, set data direction to input */ 955 reg |= FM801_GPIO_GS(TEA_64PCR_DATA) | 956 FM801_GPIO_GS(TEA_64PCR_WRITE_ENABLE) | 957 FM801_GPIO_GS(TEA_64PCR_BUS_CLOCK) | 958 FM801_GPIO_GD(TEA_64PCR_DATA) | 959 FM801_GPIO_GP(TEA_64PCR_DATA) | 960 FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE); 961 /* all of lines are in the write direction, except data */ 962 /* clear data, write enable and clock lines */ 963 reg &= ~(FM801_GPIO_GD(TEA_64PCR_WRITE_ENABLE) | 964 FM801_GPIO_GD(TEA_64PCR_BUS_CLOCK) | 965 FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK)); 966 967 for (i = 0; i < 24; i++) { 968 reg &= ~FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK); 969 outw(reg, FM801_REG(chip, GPIO_CTRL)); 970 udelay(1); 971 reg |= FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK); 972 outw(reg, FM801_REG(chip, GPIO_CTRL)); 973 udelay(1); 974 val <<= 1; 975 if (inw(FM801_REG(chip, GPIO_CTRL)) & FM801_GPIO_GP(TEA_64PCR_DATA)) 976 val |= 1; 977 } 978 979 spin_unlock_irq(&chip->reg_lock); 980 981 return val; 982 } 983 984 static void snd_fm801_tea575x_64pcr_mute(struct snd_tea575x *tea, 985 unsigned int mute) 986 { 987 struct fm801 *chip = tea->private_data; 988 unsigned short reg; 989 990 spin_lock_irq(&chip->reg_lock); 991 992 reg = inw(FM801_REG(chip, GPIO_CTRL)); 993 if (mute) 994 /* 0xf800 (mute) */ 995 reg &= ~FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE); 996 else 997 /* 0xf802 (unmute) */ 998 reg |= FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE); 999 outw(reg, FM801_REG(chip, GPIO_CTRL)); 1000 udelay(1); 1001 1002 spin_unlock_irq(&chip->reg_lock); 1003 } 1004 1005 static struct snd_tea575x_ops snd_fm801_tea_ops[3] = { 1006 { 1007 /* 1 = MediaForte 256-PCS */ 1008 .write = snd_fm801_tea575x_256pcs_write, 1009 .read = snd_fm801_tea575x_256pcs_read, 1010 }, 1011 { 1012 /* 2 = MediaForte 256-PCPR */ 1013 .write = snd_fm801_tea575x_256pcpr_write, 1014 .read = snd_fm801_tea575x_256pcpr_read, 1015 }, 1016 { 1017 /* 3 = MediaForte 64-PCR */ 1018 .write = snd_fm801_tea575x_64pcr_write, 1019 .read = snd_fm801_tea575x_64pcr_read, 1020 .mute = snd_fm801_tea575x_64pcr_mute, 1021 } 811 reg |= FM801_GPIO_GS(gpio.data) | 812 FM801_GPIO_GS(gpio.wren) | 813 FM801_GPIO_GS(gpio.clk) | 814 FM801_GPIO_GS(gpio.most); 815 if (output) { 816 /* all of lines are in the write direction */ 817 /* clear data and clock lines */ 818 reg &= ~(FM801_GPIO_GD(gpio.data) | 819 FM801_GPIO_GD(gpio.wren) | 820 FM801_GPIO_GD(gpio.clk) | 821 FM801_GPIO_GP(gpio.data) | 822 FM801_GPIO_GP(gpio.clk) | 823 FM801_GPIO_GP(gpio.wren)); 824 } else { 825 /* use GPIO lines, set data direction to input */ 826 reg |= FM801_GPIO_GD(gpio.data) | 827 FM801_GPIO_GD(gpio.most) | 828 FM801_GPIO_GP(gpio.data) | 829 FM801_GPIO_GP(gpio.most) | 830 FM801_GPIO_GP(gpio.wren); 831 /* all of lines are in the write direction, except data */ 832 /* clear data, write enable and clock lines */ 833 reg &= ~(FM801_GPIO_GD(gpio.wren) | 834 FM801_GPIO_GD(gpio.clk) | 835 FM801_GPIO_GP(gpio.clk)); 836 } 837 838 fm801_writew(chip, GPIO_CTRL, reg); 839 } 840 841 static const struct snd_tea575x_ops snd_fm801_tea_ops = { 842 .set_pins = snd_fm801_tea575x_set_pins, 843 .get_pins = snd_fm801_tea575x_get_pins, 844 .set_direction = snd_fm801_tea575x_set_direction, 1022 845 }; 1023 846 #endif … … 1052 875 int mask = (kcontrol->private_value >> 16) & 0xff; 1053 876 int invert = (kcontrol->private_value >> 24) & 0xff; 1054 1055 ucontrol->value.integer.value[0] = (inw(chip->port + reg) >> shift) & mask; 877 long *value = ucontrol->value.integer.value; 878 879 value[0] = (fm801_ioread16(chip, reg) >> shift) & mask; 1056 880 if (invert) 1057 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];881 value[0] = mask - value[0]; 1058 882 return 0; 1059 883 } … … 1108 932 int mask = (kcontrol->private_value >> 16) & 0xff; 1109 933 int invert = (kcontrol->private_value >> 24) & 0xff; 934 long *value = ucontrol->value.integer.value; 1110 935 1111 936 spin_lock_irq(&chip->reg_lock); 1112 ucontrol->value.integer.value[0] = (inw(chip->port +reg) >> shift_left) & mask;1113 ucontrol->value.integer.value[1] = (inw(chip->port +reg) >> shift_right) & mask;937 value[0] = (fm801_ioread16(chip, reg) >> shift_left) & mask; 938 value[1] = (fm801_ioread16(chip, reg) >> shift_right) & mask; 1114 939 spin_unlock_irq(&chip->reg_lock); 1115 940 if (invert) { 1116 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];1117 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];941 value[0] = mask - value[0]; 942 value[1] = mask - value[1]; 1118 943 } 1119 944 return 0; … … 1145 970 struct snd_ctl_elem_info *uinfo) 1146 971 { 1147 static c har *texts[5] = {972 static const char * const texts[5] = { 1148 973 "AC97 Primary", "FM", "I2S", "PCM", "AC97 Secondary" 1149 974 }; 1150 975 1151 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1152 uinfo->count = 1; 1153 uinfo->value.enumerated.items = 5; 1154 if (uinfo->value.enumerated.item > 4) 1155 uinfo->value.enumerated.item = 4; 1156 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1157 return 0; 976 return snd_ctl_enum_info(uinfo, 1, 5, texts); 1158 977 } 1159 978 … … 1164 983 unsigned short val; 1165 984 1166 val = inw(FM801_REG(chip, REC_SRC)) & 7;985 val = fm801_readw(chip, REC_SRC) & 7; 1167 986 if (val > 4) 1168 987 val = 4; … … 1186 1005 #define FM801_CONTROLS ARRAY_SIZE(snd_fm801_controls) 1187 1006 1188 static struct snd_kcontrol_new snd_fm801_controls[] __devinitdata= {1007 static const struct snd_kcontrol_new snd_fm801_controls[] = { 1189 1008 FM801_DOUBLE_TLV("Wave Playback Volume", FM801_PCM_VOL, 0, 8, 31, 1, 1190 1009 db_scale_dsp), … … 1207 1026 #define FM801_CONTROLS_MULTI ARRAY_SIZE(snd_fm801_controls_multi) 1208 1027 1209 static struct snd_kcontrol_new snd_fm801_controls_multi[] __devinitdata= {1028 static const struct snd_kcontrol_new snd_fm801_controls_multi[] = { 1210 1029 FM801_SINGLE("AC97 2ch->4ch Copy Switch", FM801_CODEC_CTRL, 7, 1, 0), 1211 1030 FM801_SINGLE("AC97 18-bit Switch", FM801_CODEC_CTRL, 10, 1, 0), … … 1232 1051 } 1233 1052 1234 static int __devinitsnd_fm801_mixer(struct fm801 *chip)1053 static int snd_fm801_mixer(struct fm801 *chip) 1235 1054 { 1236 1055 struct snd_ac97_template ac97; 1237 1056 unsigned int i; 1238 1057 int err; 1239 static struct snd_ac97_bus_ops ops = {1058 static const struct snd_ac97_bus_ops ops = { 1240 1059 .write = snd_fm801_codec_write, 1241 1060 .read = snd_fm801_codec_read, … … 1257 1076 return err; 1258 1077 } 1259 for (i = 0; i < FM801_CONTROLS; i++) 1260 snd_ctl_add(chip->card, snd_ctl_new1(&snd_fm801_controls[i], chip)); 1078 for (i = 0; i < FM801_CONTROLS; i++) { 1079 err = snd_ctl_add(chip->card, 1080 snd_ctl_new1(&snd_fm801_controls[i], chip)); 1081 if (err < 0) 1082 return err; 1083 } 1261 1084 if (chip->multichannel) { 1262 for (i = 0; i < FM801_CONTROLS_MULTI; i++) 1263 snd_ctl_add(chip->card, snd_ctl_new1(&snd_fm801_controls_multi[i], chip)); 1085 for (i = 0; i < FM801_CONTROLS_MULTI; i++) { 1086 err = snd_ctl_add(chip->card, 1087 snd_ctl_new1(&snd_fm801_controls_multi[i], chip)); 1088 if (err < 0) 1089 return err; 1090 } 1264 1091 } 1265 1092 return 0; … … 1275 1102 unsigned long timeout = jiffies + waits; 1276 1103 1277 outw(FM801_AC97_READ | (codec_id << FM801_AC97_ADDR_SHIFT) | reg,1278 FM801_REG(chip, AC97_CMD));1104 fm801_writew(chip, AC97_CMD, 1105 reg | (codec_id << FM801_AC97_ADDR_SHIFT) | FM801_AC97_READ); 1279 1106 udelay(5); 1280 1107 do { 1281 if (( inw(FM801_REG(chip, AC97_CMD)) & (FM801_AC97_VALID|FM801_AC97_BUSY))1282 == FM801_AC97_VALID)1108 if ((fm801_readw(chip, AC97_CMD) & 1109 (FM801_AC97_VALID | FM801_AC97_BUSY)) == FM801_AC97_VALID) 1283 1110 return 0; 1284 1111 schedule_timeout_uninterruptible(1); … … 1287 1114 } 1288 1115 1289 static int snd_fm801_chip_init(struct fm801 *chip, int resume) 1116 static int reset_codec(struct fm801 *chip) 1117 { 1118 /* codec cold reset + AC'97 warm reset */ 1119 fm801_writew(chip, CODEC_CTRL, (1 << 5) | (1 << 6)); 1120 fm801_readw(chip, CODEC_CTRL); /* flush posting data */ 1121 udelay(100); 1122 fm801_writew(chip, CODEC_CTRL, 0); 1123 1124 return wait_for_codec(chip, 0, AC97_RESET, msecs_to_jiffies(750)); 1125 } 1126 1127 static void snd_fm801_chip_multichannel_init(struct fm801 *chip) 1290 1128 { 1291 1129 unsigned short cmdw; 1292 1293 if (chip->tea575x_tuner & TUNER_ONLY)1294 goto __ac97_ok;1295 1296 /* codec cold reset + AC'97 warm reset */1297 outw((1<<5) | (1<<6), FM801_REG(chip, CODEC_CTRL));1298 inw(FM801_REG(chip, CODEC_CTRL)); /* flush posting data */1299 udelay(100);1300 outw(0, FM801_REG(chip, CODEC_CTRL));1301 1302 if (wait_for_codec(chip, 0, AC97_RESET, msecs_to_jiffies(750)) < 0)1303 if (!resume) {1304 snd_printk(KERN_INFO "Primary AC'97 codec not found, "1305 "assume SF64-PCR (tuner-only)\n");1306 chip->tea575x_tuner = 3 | TUNER_ONLY;1307 goto __ac97_ok;1308 }1309 1130 1310 1131 if (chip->multichannel) { … … 1319 1140 if (!wait_for_codec(chip, i, AC97_VENDOR_ID1, 1320 1141 msecs_to_jiffies(50))) { 1321 cmdw = inw(FM801_REG(chip, AC97_DATA));1142 cmdw = fm801_readw(chip, AC97_DATA); 1322 1143 if (cmdw != 0xffff && cmdw != 0) { 1323 1144 chip->secondary = 1; … … 1333 1154 wait_for_codec(chip, 0, AC97_VENDOR_ID1, msecs_to_jiffies(750)); 1334 1155 } 1335 1336 __ac97_ok: 1156 } 1157 1158 static void snd_fm801_chip_init(struct fm801 *chip) 1159 { 1160 unsigned short cmdw; 1337 1161 1338 1162 /* init volume */ 1339 outw(0x0808, FM801_REG(chip, PCM_VOL));1340 outw(0x9f1f, FM801_REG(chip, FM_VOL));1341 outw(0x8808, FM801_REG(chip, I2S_VOL));1163 fm801_writew(chip, PCM_VOL, 0x0808); 1164 fm801_writew(chip, FM_VOL, 0x9f1f); 1165 fm801_writew(chip, I2S_VOL, 0x8808); 1342 1166 1343 1167 /* I2S control - I2S mode */ 1344 outw(0x0003, FM801_REG(chip, I2S_MODE));1168 fm801_writew(chip, I2S_MODE, 0x0003); 1345 1169 1346 1170 /* interrupt setup */ 1347 cmdw = inw(FM801_REG(chip, IRQ_MASK));1171 cmdw = fm801_readw(chip, IRQ_MASK); 1348 1172 if (chip->irq < 0) 1349 1173 cmdw |= 0x00c3; /* mask everything, no PCM nor MPU */ 1350 1174 else 1351 1175 cmdw &= ~0x0083; /* unmask MPU, PLAYBACK & CAPTURE */ 1352 outw(cmdw, FM801_REG(chip, IRQ_MASK));1176 fm801_writew(chip, IRQ_MASK, cmdw); 1353 1177 1354 1178 /* interrupt clear */ 1355 outw(FM801_IRQ_PLAYBACK|FM801_IRQ_CAPTURE|FM801_IRQ_MPU, FM801_REG(chip, IRQ_STATUS)); 1356 1357 return 0; 1358 } 1359 1179 fm801_writew(chip, IRQ_STATUS, 1180 FM801_IRQ_PLAYBACK | FM801_IRQ_CAPTURE | FM801_IRQ_MPU); 1181 } 1360 1182 1361 1183 static int snd_fm801_free(struct fm801 *chip) … … 1367 1189 1368 1190 /* interrupt setup - mask everything */ 1369 cmdw = inw(FM801_REG(chip, IRQ_MASK));1191 cmdw = fm801_readw(chip, IRQ_MASK); 1370 1192 cmdw |= 0x00c3; 1371 outw(cmdw, FM801_REG(chip, IRQ_MASK)); 1193 fm801_writew(chip, IRQ_MASK, cmdw); 1194 1195 devm_free_irq(chip->dev, chip->irq, chip); 1372 1196 1373 1197 __end_hw: 1374 #ifdef TEA575X_RADIO 1375 snd_tea575x_exit(&chip->tea); 1198 #ifdef CONFIG_SND_FM801_TEA575X_BOOL 1199 if (!(chip->tea575x_tuner & TUNER_DISABLED)) { 1200 snd_tea575x_exit(&chip->tea); 1201 v4l2_device_unregister(&chip->v4l2_dev); 1202 } 1376 1203 #endif 1377 if (chip->irq >= 0)1378 free_irq(chip->irq, chip);1379 pci_release_regions(chip->pci);1380 pci_disable_device(chip->pci);1381 1382 kfree(chip);1383 1204 return 0; 1384 1205 } … … 1390 1211 } 1391 1212 1392 static int __devinit snd_fm801_create(struct snd_card *card, 1393 struct pci_dev * pci, 1394 int tea575x_tuner, 1395 struct fm801 ** rchip) 1213 static int snd_fm801_create(struct snd_card *card, 1214 struct pci_dev *pci, 1215 int tea575x_tuner, 1216 int radio_nr, 1217 struct fm801 **rchip) 1396 1218 { 1397 1219 struct fm801 *chip; 1398 1220 int err; 1399 static struct snd_device_ops ops = {1221 static const struct snd_device_ops ops = { 1400 1222 .dev_free = snd_fm801_dev_free, 1401 1223 }; 1402 1224 1403 1225 *rchip = NULL; 1226 #ifndef TARGET_OS2 1227 if ((err = pcim_enable_device(pci)) < 0) 1228 return err; 1229 chip = devm_kzalloc(&pci->dev, sizeof(*chip), GFP_KERNEL); 1230 #else 1404 1231 if ((err = pci_enable_device(pci)) < 0) 1405 1232 return err; 1406 1233 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1407 if (chip == NULL) { 1408 pci_disable_device(pci);1234 #endif 1235 if (chip == NULL) 1409 1236 return -ENOMEM; 1410 }1411 1237 spin_lock_init(&chip->reg_lock); 1412 1238 chip->card = card; 1413 chip-> pci = pci;1239 chip->dev = &pci->dev; 1414 1240 chip->irq = -1; 1415 1241 chip->tea575x_tuner = tea575x_tuner; 1416 if ((err = pci_request_regions(pci, "FM801")) < 0) { 1417 kfree(chip); 1418 pci_disable_device(pci); 1419 return err; 1420 } 1242 if ((err = pci_request_regions(pci, "FM801")) < 0) 1243 return err; 1421 1244 chip->port = pci_resource_start(pci, 0); 1422 if ((tea575x_tuner & TUNER_ONLY) == 0) {1423 if (request_irq(pci->irq, snd_fm801_interrupt, IRQF_SHARED,1424 "FM801", chip)) {1425 snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->irq);1426 snd_fm801_free(chip);1427 return -EBUSY;1428 }1429 chip->irq = pci->irq;1430 pci_set_master(pci);1431 }1432 1245 1433 1246 #ifndef TARGET_OS2 … … 1438 1251 chip->multichannel = 1; 1439 1252 1440 snd_fm801_chip_init(chip, 0); 1441 /* init might set tuner access method */ 1442 tea575x_tuner = chip->tea575x_tuner; 1443 1444 if (chip->irq >= 0 && (tea575x_tuner & TUNER_ONLY)) { 1445 pci_clear_master(pci); 1446 free_irq(chip->irq, chip); 1447 chip->irq = -1; 1448 } 1253 if (!(chip->tea575x_tuner & TUNER_ONLY)) { 1254 if (reset_codec(chip) < 0) { 1255 dev_info(chip->card->dev, 1256 "Primary AC'97 codec not found, assume SF64-PCR (tuner-only)\n"); 1257 chip->tea575x_tuner = 3 | TUNER_ONLY; 1258 } else { 1259 snd_fm801_chip_multichannel_init(chip); 1260 } 1261 } 1262 1263 if ((chip->tea575x_tuner & TUNER_ONLY) == 0) { 1264 #ifndef TARGET_OS2 1265 if (devm_request_irq(&pci->dev, pci->irq, snd_fm801_interrupt, 1266 IRQF_SHARED, KBUILD_MODNAME, chip)) { 1267 #else 1268 if (request_irq(pci->irq, snd_fm801_interrupt, IRQF_SHARED, 1269 KBUILD_MODNAME, chip)) { 1270 #endif 1271 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); 1272 snd_fm801_free(chip); 1273 return -EBUSY; 1274 } 1275 chip->irq = pci->irq; 1276 card->sync_irq = chip->irq; 1277 pci_set_master(pci); 1278 } 1279 1280 snd_fm801_chip_init(chip); 1449 1281 1450 1282 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { … … 1453 1285 } 1454 1286 1455 snd_card_set_dev(card, &pci->dev); 1456 1457 #ifdef TEA575X_RADIO 1458 if ((tea575x_tuner & TUNER_TYPE_MASK) > 0 && 1459 (tea575x_tuner & TUNER_TYPE_MASK) < 4) { 1460 chip->tea.dev_nr = tea575x_tuner >> 16; 1461 chip->tea.card = card; 1462 chip->tea.freq_fixup = 10700; 1463 chip->tea.private_data = chip; 1464 chip->tea.ops = &snd_fm801_tea_ops[(tea575x_tuner & TUNER_TYPE_MASK) - 1]; 1465 snd_tea575x_init(&chip->tea); 1287 #ifdef CONFIG_SND_FM801_TEA575X_BOOL 1288 err = v4l2_device_register(&pci->dev, &chip->v4l2_dev); 1289 if (err < 0) { 1290 snd_fm801_free(chip); 1291 return err; 1292 } 1293 chip->tea.v4l2_dev = &chip->v4l2_dev; 1294 chip->tea.radio_nr = radio_nr; 1295 chip->tea.private_data = chip; 1296 chip->tea.ops = &snd_fm801_tea_ops; 1297 sprintf(chip->tea.bus_info, "PCI:%s", pci_name(pci)); 1298 if ((chip->tea575x_tuner & TUNER_TYPE_MASK) > 0 && 1299 (chip->tea575x_tuner & TUNER_TYPE_MASK) < 4) { 1300 if (snd_tea575x_init(&chip->tea, THIS_MODULE)) { 1301 dev_err(card->dev, "TEA575x radio not found\n"); 1302 snd_fm801_free(chip); 1303 return -ENODEV; 1304 } 1305 } else if ((chip->tea575x_tuner & TUNER_TYPE_MASK) == 0) { 1306 unsigned int tuner_only = chip->tea575x_tuner & TUNER_ONLY; 1307 1308 /* autodetect tuner connection */ 1309 for (tea575x_tuner = 1; tea575x_tuner <= 3; tea575x_tuner++) { 1310 chip->tea575x_tuner = tea575x_tuner; 1311 if (!snd_tea575x_init(&chip->tea, THIS_MODULE)) { 1312 dev_info(card->dev, 1313 "detected TEA575x radio type %s\n", 1314 get_tea575x_gpio(chip)->name); 1315 break; 1316 } 1317 } 1318 if (tea575x_tuner == 4) { 1319 dev_err(card->dev, "TEA575x radio not found\n"); 1320 chip->tea575x_tuner = TUNER_DISABLED; 1321 } 1322 1323 chip->tea575x_tuner |= tuner_only; 1324 } 1325 if (!(chip->tea575x_tuner & TUNER_DISABLED)) { 1326 strlcpy(chip->tea.card, get_tea575x_gpio(chip)->name, 1327 sizeof(chip->tea.card)); 1466 1328 } 1467 1329 #endif … … 1471 1333 } 1472 1334 1473 static int __devinitsnd_card_fm801_probe(struct pci_dev *pci,1474 1335 static int snd_card_fm801_probe(struct pci_dev *pci, 1336 const struct pci_device_id *pci_id) 1475 1337 { 1476 1338 static int dev; … … 1487 1349 } 1488 1350 1489 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 1351 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, 1352 0, &card); 1490 1353 if (err < 0) 1491 1354 return err; 1492 if ((err = snd_fm801_create(card, pci, tea575x_tuner[dev], &chip)) < 0) {1355 if ((err = snd_fm801_create(card, pci, tea575x_tuner[dev], radio_nr[dev], &chip)) < 0) { 1493 1356 snd_card_free(card); 1494 1357 return err; … … 1505 1368 goto __fm801_tuner_only; 1506 1369 1507 if ((err = snd_fm801_pcm(chip, 0 , NULL)) < 0) {1370 if ((err = snd_fm801_pcm(chip, 0)) < 0) { 1508 1371 snd_card_free(card); 1509 1372 return err; … … 1514 1377 } 1515 1378 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_FM801, 1516 FM801_REG(chip, MPU401_DATA), 1517 MPU401_INFO_INTEGRATED, 1518 chip->irq, 0, &chip->rmidi)) < 0) { 1379 chip->port + FM801_MPU401_DATA, 1380 MPU401_INFO_INTEGRATED | 1381 MPU401_INFO_IRQ_HOOK, 1382 -1, &chip->rmidi)) < 0) { 1519 1383 snd_card_free(card); 1520 1384 return err; 1521 1385 } 1522 if ((err = snd_opl3_create(card, FM801_REG(chip, OPL3_BANK0),1523 FM801_REG(chip, OPL3_BANK1),1386 if ((err = snd_opl3_create(card, chip->port + FM801_OPL3_BANK0, 1387 chip->port + FM801_OPL3_BANK1, 1524 1388 OPL3_HW_OPL3_FM801, 1, &opl3)) < 0) { 1525 1389 snd_card_free(card); … … 1541 1405 } 1542 1406 1543 static void __devexitsnd_card_fm801_remove(struct pci_dev *pci)1407 static void snd_card_fm801_remove(struct pci_dev *pci) 1544 1408 { 1545 1409 snd_card_free(pci_get_drvdata(pci)); 1546 pci_set_drvdata(pci, NULL); 1547 } 1548 1549 #ifdef CONFIG_PM 1550 static unsigned char saved_regs[] = { 1410 } 1411 1412 #ifdef CONFIG_PM_SLEEP 1413 static const unsigned char saved_regs[] = { 1551 1414 FM801_PCM_VOL, FM801_I2S_VOL, FM801_FM_VOL, FM801_REC_SRC, 1552 1415 FM801_PLY_CTRL, FM801_PLY_COUNT, FM801_PLY_BUF1, FM801_PLY_BUF2, … … 1555 1418 }; 1556 1419 1557 static int snd_fm801_suspend(struct pci_dev *pci, pm_message_t state)1558 { 1559 struct snd_card *card = pci_get_drvdata(pci);1420 static int snd_fm801_suspend(struct device *dev) 1421 { 1422 struct snd_card *card = dev_get_drvdata(dev); 1560 1423 struct fm801 *chip = card->private_data; 1561 1424 int i; 1562 1425 1563 1426 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 1564 snd_pcm_suspend_all(chip->pcm); 1565 snd_ac97_suspend(chip->ac97); 1566 snd_ac97_suspend(chip->ac97_sec); 1427 1567 1428 for (i = 0; i < ARRAY_SIZE(saved_regs); i++) 1568 chip->saved_regs[i] = inw(chip->port + saved_regs[i]); 1569 /* FIXME: tea575x suspend */ 1570 1571 pci_disable_device(pci); 1572 pci_save_state(pci); 1573 pci_set_power_state(pci, pci_choose_state(pci, state)); 1574 return 0; 1575 } 1576 1577 static int snd_fm801_resume(struct pci_dev *pci) 1578 { 1579 struct snd_card *card = pci_get_drvdata(pci); 1429 chip->saved_regs[i] = fm801_ioread16(chip, saved_regs[i]); 1430 1431 if (chip->tea575x_tuner & TUNER_ONLY) { 1432 /* FIXME: tea575x suspend */ 1433 } else { 1434 snd_ac97_suspend(chip->ac97); 1435 snd_ac97_suspend(chip->ac97_sec); 1436 } 1437 1438 return 0; 1439 } 1440 1441 static int snd_fm801_resume(struct device *dev) 1442 { 1443 struct snd_card *card = dev_get_drvdata(dev); 1580 1444 struct fm801 *chip = card->private_data; 1581 1445 int i; 1582 1446 1583 pci_set_power_state(pci, PCI_D0); 1584 pci_restore_state(pci); 1585 if (pci_enable_device(pci) < 0) { 1586 printk(KERN_ERR "fm801: pci_enable_device failed, " 1587 "disabling device\n"); 1588 snd_card_disconnect(card); 1589 return -EIO; 1590 } 1591 pci_set_master(pci); 1592 1593 snd_fm801_chip_init(chip, 1); 1594 snd_ac97_resume(chip->ac97); 1595 snd_ac97_resume(chip->ac97_sec); 1447 if (chip->tea575x_tuner & TUNER_ONLY) { 1448 snd_fm801_chip_init(chip); 1449 } else { 1450 reset_codec(chip); 1451 snd_fm801_chip_multichannel_init(chip); 1452 snd_fm801_chip_init(chip); 1453 snd_ac97_resume(chip->ac97); 1454 snd_ac97_resume(chip->ac97_sec); 1455 } 1456 1596 1457 for (i = 0; i < ARRAY_SIZE(saved_regs); i++) 1597 outw(chip->saved_regs[i], chip->port + saved_regs[i]); 1458 fm801_iowrite16(chip, saved_regs[i], chip->saved_regs[i]); 1459 1460 #ifdef CONFIG_SND_FM801_TEA575X_BOOL 1461 if (!(chip->tea575x_tuner & TUNER_DISABLED)) 1462 snd_tea575x_set_freq(&chip->tea); 1463 #endif 1598 1464 1599 1465 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 1600 1466 return 0; 1601 1467 } 1602 #endif 1603 1604 static struct pci_driver driver = { 1605 .name = "FM801", 1468 1469 static SIMPLE_DEV_PM_OPS(snd_fm801_pm, snd_fm801_suspend, snd_fm801_resume); 1470 #define SND_FM801_PM_OPS &snd_fm801_pm 1471 #else 1472 #define SND_FM801_PM_OPS NULL 1473 #endif /* CONFIG_PM_SLEEP */ 1474 1475 static struct pci_driver fm801_driver = { 1476 .name = KBUILD_MODNAME, 1606 1477 .id_table = snd_fm801_ids, 1607 1478 .probe = snd_card_fm801_probe, 1608 .remove = __devexit_p(snd_card_fm801_remove), 1609 #ifdef CONFIG_PM 1610 .suspend = snd_fm801_suspend, 1611 .resume = snd_fm801_resume, 1612 #endif 1613 }; 1614 1615 static int __init alsa_card_fm801_init(void) 1616 { 1617 return pci_register_driver(&driver); 1618 } 1619 1620 static void __exit alsa_card_fm801_exit(void) 1621 { 1622 pci_unregister_driver(&driver); 1623 } 1624 1625 module_init(alsa_card_fm801_init) 1626 module_exit(alsa_card_fm801_exit) 1479 .remove = snd_card_fm801_remove, 1480 .driver = { 1481 .pm = SND_FM801_PM_OPS, 1482 }, 1483 }; 1484 1485 module_pci_driver(fm801_driver);
Note:
See TracChangeset
for help on using the changeset viewer.