Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1 | /* |
| 2 | * ALSA soundcard driver for Miro miroSOUND PCM1 pro |
| 3 | * miroSOUND PCM12 |
| 4 | * miroSOUND PCM20 Radio |
| 5 | * |
| 6 | * Copyright (C) 2004-2005 Martin Langer <martin-langer@gmx.de> |
| 7 | * |
| 8 | * Based on OSS ACI and ALSA OPTi9xx drivers |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | */ |
| 24 | |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 25 | #include <linux/init.h> |
| 26 | #include <linux/err.h> |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 27 | #include <linux/isa.h> |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 28 | #include <linux/delay.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/ioport.h> |
| 31 | #include <linux/moduleparam.h> |
| 32 | #include <asm/io.h> |
| 33 | #include <asm/dma.h> |
| 34 | #include <sound/core.h> |
Krzysztof Helt | 61ef19d | 2008-07-31 21:02:42 +0200 | [diff] [blame] | 35 | #include <sound/wss.h> |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 36 | #include <sound/mpu401.h> |
| 37 | #include <sound/opl4.h> |
| 38 | #include <sound/control.h> |
| 39 | #include <sound/info.h> |
| 40 | #define SNDRV_LEGACY_FIND_FREE_IRQ |
| 41 | #define SNDRV_LEGACY_FIND_FREE_DMA |
| 42 | #include <sound/initval.h> |
| 43 | #include "miro.h" |
| 44 | |
| 45 | MODULE_AUTHOR("Martin Langer <martin-langer@gmx.de>"); |
| 46 | MODULE_LICENSE("GPL"); |
| 47 | MODULE_DESCRIPTION("Miro miroSOUND PCM1 pro, PCM12, PCM20 Radio"); |
| 48 | MODULE_SUPPORTED_DEVICE("{{Miro,miroSOUND PCM1 pro}, " |
| 49 | "{Miro,miroSOUND PCM12}, " |
| 50 | "{Miro,miroSOUND PCM20 Radio}}"); |
| 51 | |
| 52 | static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */ |
| 53 | static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ |
| 54 | static long port = SNDRV_DEFAULT_PORT1; /* 0x530,0xe80,0xf40,0x604 */ |
| 55 | static long mpu_port = SNDRV_DEFAULT_PORT1; /* 0x300,0x310,0x320,0x330 */ |
| 56 | static long fm_port = SNDRV_DEFAULT_PORT1; /* 0x388 */ |
| 57 | static int irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10,11 */ |
| 58 | static int mpu_irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10 */ |
| 59 | static int dma1 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */ |
| 60 | static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */ |
| 61 | static int wss; |
| 62 | static int ide; |
| 63 | |
| 64 | module_param(index, int, 0444); |
| 65 | MODULE_PARM_DESC(index, "Index value for miro soundcard."); |
| 66 | module_param(id, charp, 0444); |
| 67 | MODULE_PARM_DESC(id, "ID string for miro soundcard."); |
| 68 | module_param(port, long, 0444); |
| 69 | MODULE_PARM_DESC(port, "WSS port # for miro driver."); |
| 70 | module_param(mpu_port, long, 0444); |
| 71 | MODULE_PARM_DESC(mpu_port, "MPU-401 port # for miro driver."); |
| 72 | module_param(fm_port, long, 0444); |
| 73 | MODULE_PARM_DESC(fm_port, "FM Port # for miro driver."); |
| 74 | module_param(irq, int, 0444); |
| 75 | MODULE_PARM_DESC(irq, "WSS irq # for miro driver."); |
| 76 | module_param(mpu_irq, int, 0444); |
| 77 | MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for miro driver."); |
| 78 | module_param(dma1, int, 0444); |
| 79 | MODULE_PARM_DESC(dma1, "1st dma # for miro driver."); |
| 80 | module_param(dma2, int, 0444); |
| 81 | MODULE_PARM_DESC(dma2, "2nd dma # for miro driver."); |
| 82 | module_param(wss, int, 0444); |
| 83 | MODULE_PARM_DESC(wss, "wss mode"); |
| 84 | module_param(ide, int, 0444); |
| 85 | MODULE_PARM_DESC(ide, "enable ide port"); |
| 86 | |
| 87 | #define OPTi9XX_HW_DETECT 0 |
| 88 | #define OPTi9XX_HW_82C928 1 |
| 89 | #define OPTi9XX_HW_82C929 2 |
| 90 | #define OPTi9XX_HW_82C924 3 |
| 91 | #define OPTi9XX_HW_82C925 4 |
| 92 | #define OPTi9XX_HW_82C930 5 |
| 93 | #define OPTi9XX_HW_82C931 6 |
| 94 | #define OPTi9XX_HW_82C933 7 |
| 95 | #define OPTi9XX_HW_LAST OPTi9XX_HW_82C933 |
| 96 | |
| 97 | #define OPTi9XX_MC_REG(n) n |
| 98 | |
| 99 | |
| 100 | struct snd_miro { |
| 101 | unsigned short hardware; |
| 102 | unsigned char password; |
| 103 | char name[7]; |
| 104 | |
| 105 | struct resource *res_mc_base; |
| 106 | struct resource *res_aci_port; |
| 107 | |
| 108 | unsigned long mc_base; |
| 109 | unsigned long mc_base_size; |
| 110 | unsigned long pwd_reg; |
| 111 | |
| 112 | spinlock_t lock; |
| 113 | struct snd_card *card; |
| 114 | struct snd_pcm *pcm; |
| 115 | |
| 116 | long wss_base; |
| 117 | int irq; |
| 118 | int dma1; |
| 119 | int dma2; |
| 120 | |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 121 | long mpu_port; |
| 122 | int mpu_irq; |
| 123 | |
| 124 | unsigned long aci_port; |
| 125 | int aci_vendor; |
| 126 | int aci_product; |
| 127 | int aci_version; |
| 128 | int aci_amp; |
| 129 | int aci_preamp; |
| 130 | int aci_solomode; |
| 131 | |
| 132 | struct mutex aci_mutex; |
| 133 | }; |
| 134 | |
| 135 | static void snd_miro_proc_init(struct snd_miro * miro); |
| 136 | |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 137 | static char * snd_opti9xx_names[] = { |
| 138 | "unkown", |
| 139 | "82C928", "82C929", |
| 140 | "82C924", "82C925", |
| 141 | "82C930", "82C931", "82C933" |
| 142 | }; |
| 143 | |
| 144 | /* |
| 145 | * ACI control |
| 146 | */ |
| 147 | |
| 148 | static int aci_busy_wait(struct snd_miro * miro) |
| 149 | { |
| 150 | long timeout; |
| 151 | unsigned char byte; |
| 152 | |
| 153 | for (timeout = 1; timeout <= ACI_MINTIME+30; timeout++) { |
| 154 | if (((byte=inb(miro->aci_port + ACI_REG_BUSY)) & 1) == 0) { |
| 155 | if (timeout >= ACI_MINTIME) |
| 156 | snd_printd("aci ready in round %ld.\n", |
| 157 | timeout-ACI_MINTIME); |
| 158 | return byte; |
| 159 | } |
| 160 | if (timeout >= ACI_MINTIME) { |
| 161 | long out=10*HZ; |
| 162 | switch (timeout-ACI_MINTIME) { |
| 163 | case 0 ... 9: |
| 164 | out /= 10; |
| 165 | case 10 ... 19: |
| 166 | out /= 10; |
| 167 | case 20 ... 30: |
| 168 | out /= 10; |
| 169 | default: |
| 170 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 171 | schedule_timeout(out); |
| 172 | break; |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | snd_printk(KERN_ERR "aci_busy_wait() time out\n"); |
| 177 | return -EBUSY; |
| 178 | } |
| 179 | |
| 180 | static inline int aci_write(struct snd_miro * miro, unsigned char byte) |
| 181 | { |
| 182 | if (aci_busy_wait(miro) >= 0) { |
| 183 | outb(byte, miro->aci_port + ACI_REG_COMMAND); |
| 184 | return 0; |
| 185 | } else { |
| 186 | snd_printk(KERN_ERR "aci busy, aci_write(0x%x) stopped.\n", byte); |
| 187 | return -EBUSY; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | static inline int aci_read(struct snd_miro * miro) |
| 192 | { |
| 193 | unsigned char byte; |
| 194 | |
| 195 | if (aci_busy_wait(miro) >= 0) { |
| 196 | byte=inb(miro->aci_port + ACI_REG_STATUS); |
| 197 | return byte; |
| 198 | } else { |
| 199 | snd_printk(KERN_ERR "aci busy, aci_read() stopped.\n"); |
| 200 | return -EBUSY; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | static int aci_cmd(struct snd_miro * miro, int write1, int write2, int write3) |
| 205 | { |
| 206 | int write[] = {write1, write2, write3}; |
| 207 | int value, i; |
| 208 | |
| 209 | if (mutex_lock_interruptible(&miro->aci_mutex)) |
| 210 | return -EINTR; |
| 211 | |
| 212 | for (i=0; i<3; i++) { |
| 213 | if (write[i]< 0 || write[i] > 255) |
| 214 | break; |
| 215 | else { |
| 216 | value = aci_write(miro, write[i]); |
| 217 | if (value < 0) |
| 218 | goto out; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | value = aci_read(miro); |
| 223 | |
| 224 | out: mutex_unlock(&miro->aci_mutex); |
| 225 | return value; |
| 226 | } |
| 227 | |
| 228 | static int aci_getvalue(struct snd_miro * miro, unsigned char index) |
| 229 | { |
| 230 | return aci_cmd(miro, ACI_STATUS, index, -1); |
| 231 | } |
| 232 | |
| 233 | static int aci_setvalue(struct snd_miro * miro, unsigned char index, int value) |
| 234 | { |
| 235 | return aci_cmd(miro, index, value, -1); |
| 236 | } |
| 237 | |
| 238 | /* |
| 239 | * MIXER part |
| 240 | */ |
| 241 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 242 | #define snd_miro_info_capture snd_ctl_boolean_mono_info |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 243 | |
| 244 | static int snd_miro_get_capture(struct snd_kcontrol *kcontrol, |
| 245 | struct snd_ctl_elem_value *ucontrol) |
| 246 | { |
| 247 | struct snd_miro *miro = snd_kcontrol_chip(kcontrol); |
| 248 | int value; |
| 249 | |
| 250 | if ((value = aci_getvalue(miro, ACI_S_GENERAL)) < 0) { |
| 251 | snd_printk(KERN_ERR "snd_miro_get_capture() failed: %d\n", value); |
| 252 | return value; |
| 253 | } |
| 254 | |
| 255 | ucontrol->value.integer.value[0] = value & 0x20; |
| 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | static int snd_miro_put_capture(struct snd_kcontrol *kcontrol, |
| 261 | struct snd_ctl_elem_value *ucontrol) |
| 262 | { |
| 263 | struct snd_miro *miro = snd_kcontrol_chip(kcontrol); |
| 264 | int change, value, error; |
| 265 | |
| 266 | value = !(ucontrol->value.integer.value[0]); |
| 267 | |
| 268 | if ((error = aci_setvalue(miro, ACI_SET_SOLOMODE, value)) < 0) { |
| 269 | snd_printk(KERN_ERR "snd_miro_put_capture() failed: %d\n", error); |
| 270 | return error; |
| 271 | } |
| 272 | |
| 273 | change = (value != miro->aci_solomode); |
| 274 | miro->aci_solomode = value; |
| 275 | |
| 276 | return change; |
| 277 | } |
| 278 | |
| 279 | static int snd_miro_info_preamp(struct snd_kcontrol *kcontrol, |
| 280 | struct snd_ctl_elem_info *uinfo) |
| 281 | { |
| 282 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 283 | uinfo->count = 1; |
| 284 | uinfo->value.integer.min = 0; |
| 285 | uinfo->value.integer.max = 3; |
| 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | static int snd_miro_get_preamp(struct snd_kcontrol *kcontrol, |
| 291 | struct snd_ctl_elem_value *ucontrol) |
| 292 | { |
| 293 | struct snd_miro *miro = snd_kcontrol_chip(kcontrol); |
| 294 | int value; |
| 295 | |
| 296 | if (miro->aci_version <= 176) { |
| 297 | |
| 298 | /* |
| 299 | OSS says it's not readable with versions < 176. |
| 300 | But it doesn't work on my card, |
| 301 | which is a PCM12 with aci_version = 176. |
| 302 | */ |
| 303 | |
| 304 | ucontrol->value.integer.value[0] = miro->aci_preamp; |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | if ((value = aci_getvalue(miro, ACI_GET_PREAMP)) < 0) { |
| 309 | snd_printk(KERN_ERR "snd_miro_get_preamp() failed: %d\n", value); |
| 310 | return value; |
| 311 | } |
| 312 | |
| 313 | ucontrol->value.integer.value[0] = value; |
| 314 | |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | static int snd_miro_put_preamp(struct snd_kcontrol *kcontrol, |
| 319 | struct snd_ctl_elem_value *ucontrol) |
| 320 | { |
| 321 | struct snd_miro *miro = snd_kcontrol_chip(kcontrol); |
| 322 | int error, value, change; |
| 323 | |
| 324 | value = ucontrol->value.integer.value[0]; |
| 325 | |
| 326 | if ((error = aci_setvalue(miro, ACI_SET_PREAMP, value)) < 0) { |
| 327 | snd_printk(KERN_ERR "snd_miro_put_preamp() failed: %d\n", error); |
| 328 | return error; |
| 329 | } |
| 330 | |
| 331 | change = (value != miro->aci_preamp); |
| 332 | miro->aci_preamp = value; |
| 333 | |
| 334 | return change; |
| 335 | } |
| 336 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 337 | #define snd_miro_info_amp snd_ctl_boolean_mono_info |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 338 | |
| 339 | static int snd_miro_get_amp(struct snd_kcontrol *kcontrol, |
| 340 | struct snd_ctl_elem_value *ucontrol) |
| 341 | { |
| 342 | struct snd_miro *miro = snd_kcontrol_chip(kcontrol); |
| 343 | ucontrol->value.integer.value[0] = miro->aci_amp; |
| 344 | |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | static int snd_miro_put_amp(struct snd_kcontrol *kcontrol, |
| 349 | struct snd_ctl_elem_value *ucontrol) |
| 350 | { |
| 351 | struct snd_miro *miro = snd_kcontrol_chip(kcontrol); |
| 352 | int error, value, change; |
| 353 | |
| 354 | value = ucontrol->value.integer.value[0]; |
| 355 | |
| 356 | if ((error = aci_setvalue(miro, ACI_SET_POWERAMP, value)) < 0) { |
| 357 | snd_printk(KERN_ERR "snd_miro_put_amp() to %d failed: %d\n", value, error); |
| 358 | return error; |
| 359 | } |
| 360 | |
| 361 | change = (value != miro->aci_amp); |
| 362 | miro->aci_amp = value; |
| 363 | |
| 364 | return change; |
| 365 | } |
| 366 | |
| 367 | #define MIRO_DOUBLE(ctl_name, ctl_index, get_right_reg, set_right_reg) \ |
| 368 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 369 | .name = ctl_name, \ |
| 370 | .index = ctl_index, \ |
| 371 | .info = snd_miro_info_double, \ |
| 372 | .get = snd_miro_get_double, \ |
| 373 | .put = snd_miro_put_double, \ |
| 374 | .private_value = get_right_reg | (set_right_reg << 8) \ |
| 375 | } |
| 376 | |
| 377 | static int snd_miro_info_double(struct snd_kcontrol *kcontrol, |
| 378 | struct snd_ctl_elem_info *uinfo) |
| 379 | { |
| 380 | int reg = kcontrol->private_value & 0xff; |
| 381 | |
| 382 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 383 | uinfo->count = 2; |
| 384 | |
| 385 | if ((reg >= ACI_GET_EQ1) && (reg <= ACI_GET_EQ7)) { |
| 386 | |
| 387 | /* equalizer elements */ |
| 388 | |
| 389 | uinfo->value.integer.min = - 0x7f; |
| 390 | uinfo->value.integer.max = 0x7f; |
| 391 | } else { |
| 392 | |
| 393 | /* non-equalizer elements */ |
| 394 | |
| 395 | uinfo->value.integer.min = 0; |
| 396 | uinfo->value.integer.max = 0x20; |
| 397 | } |
| 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | static int snd_miro_get_double(struct snd_kcontrol *kcontrol, |
| 403 | struct snd_ctl_elem_value *uinfo) |
| 404 | { |
| 405 | struct snd_miro *miro = snd_kcontrol_chip(kcontrol); |
| 406 | int left_val, right_val; |
| 407 | |
| 408 | int right_reg = kcontrol->private_value & 0xff; |
| 409 | int left_reg = right_reg + 1; |
| 410 | |
| 411 | if ((right_val = aci_getvalue(miro, right_reg)) < 0) { |
| 412 | snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", right_reg, right_val); |
| 413 | return right_val; |
| 414 | } |
| 415 | |
| 416 | if ((left_val = aci_getvalue(miro, left_reg)) < 0) { |
| 417 | snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", left_reg, left_val); |
| 418 | return left_val; |
| 419 | } |
| 420 | |
| 421 | if ((right_reg >= ACI_GET_EQ1) && (right_reg <= ACI_GET_EQ7)) { |
| 422 | |
| 423 | /* equalizer elements */ |
| 424 | |
| 425 | if (left_val < 0x80) { |
| 426 | uinfo->value.integer.value[0] = left_val; |
| 427 | } else { |
| 428 | uinfo->value.integer.value[0] = 0x80 - left_val; |
| 429 | } |
| 430 | |
| 431 | if (right_val < 0x80) { |
| 432 | uinfo->value.integer.value[1] = right_val; |
| 433 | } else { |
| 434 | uinfo->value.integer.value[1] = 0x80 - right_val; |
| 435 | } |
| 436 | |
| 437 | } else { |
| 438 | |
| 439 | /* non-equalizer elements */ |
| 440 | |
| 441 | uinfo->value.integer.value[0] = 0x20 - left_val; |
| 442 | uinfo->value.integer.value[1] = 0x20 - right_val; |
| 443 | } |
| 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | static int snd_miro_put_double(struct snd_kcontrol *kcontrol, |
| 449 | struct snd_ctl_elem_value *ucontrol) |
| 450 | { |
| 451 | struct snd_miro *miro = snd_kcontrol_chip(kcontrol); |
| 452 | int left, right, left_old, right_old; |
| 453 | int setreg_left, setreg_right, getreg_left, getreg_right; |
| 454 | int change, error; |
| 455 | |
| 456 | left = ucontrol->value.integer.value[0]; |
| 457 | right = ucontrol->value.integer.value[1]; |
| 458 | |
| 459 | setreg_right = (kcontrol->private_value >> 8) & 0xff; |
| 460 | if (setreg_right == ACI_SET_MASTER) { |
| 461 | setreg_left = setreg_right + 1; |
| 462 | } else { |
| 463 | setreg_left = setreg_right + 8; |
| 464 | } |
| 465 | |
| 466 | getreg_right = kcontrol->private_value & 0xff; |
| 467 | getreg_left = getreg_right + 1; |
| 468 | |
| 469 | if ((left_old = aci_getvalue(miro, getreg_left)) < 0) { |
| 470 | snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_left, left_old); |
| 471 | return left_old; |
| 472 | } |
| 473 | |
| 474 | if ((right_old = aci_getvalue(miro, getreg_right)) < 0) { |
| 475 | snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_right, right_old); |
| 476 | return right_old; |
| 477 | } |
| 478 | |
| 479 | if ((getreg_right >= ACI_GET_EQ1) && (getreg_right <= ACI_GET_EQ7)) { |
| 480 | |
| 481 | /* equalizer elements */ |
| 482 | |
Takashi Iwai | 3b89246 | 2007-11-15 16:17:24 +0100 | [diff] [blame] | 483 | if (left < -0x7f || left > 0x7f || |
| 484 | right < -0x7f || right > 0x7f) |
| 485 | return -EINVAL; |
| 486 | |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 487 | if (left_old > 0x80) |
| 488 | left_old = 0x80 - left_old; |
| 489 | if (right_old > 0x80) |
| 490 | right_old = 0x80 - right_old; |
| 491 | |
| 492 | if (left >= 0) { |
| 493 | if ((error = aci_setvalue(miro, setreg_left, left)) < 0) { |
| 494 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", |
| 495 | left, error); |
| 496 | return error; |
| 497 | } |
| 498 | } else { |
| 499 | if ((error = aci_setvalue(miro, setreg_left, 0x80 - left)) < 0) { |
| 500 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", |
| 501 | 0x80 - left, error); |
| 502 | return error; |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | if (right >= 0) { |
| 507 | if ((error = aci_setvalue(miro, setreg_right, right)) < 0) { |
| 508 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", |
| 509 | right, error); |
| 510 | return error; |
| 511 | } |
| 512 | } else { |
| 513 | if ((error = aci_setvalue(miro, setreg_right, 0x80 - right)) < 0) { |
| 514 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", |
| 515 | 0x80 - right, error); |
| 516 | return error; |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | } else { |
| 521 | |
| 522 | /* non-equalizer elements */ |
| 523 | |
Takashi Iwai | 3b89246 | 2007-11-15 16:17:24 +0100 | [diff] [blame] | 524 | if (left < 0 || left > 0x20 || |
| 525 | right < 0 || right > 0x20) |
| 526 | return -EINVAL; |
| 527 | |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 528 | left_old = 0x20 - left_old; |
| 529 | right_old = 0x20 - right_old; |
| 530 | |
| 531 | if ((error = aci_setvalue(miro, setreg_left, 0x20 - left)) < 0) { |
| 532 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", |
| 533 | 0x20 - left, error); |
| 534 | return error; |
| 535 | } |
| 536 | if ((error = aci_setvalue(miro, setreg_right, 0x20 - right)) < 0) { |
| 537 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", |
| 538 | 0x20 - right, error); |
| 539 | return error; |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | change = (left != left_old) || (right != right_old); |
| 544 | |
| 545 | return change; |
| 546 | } |
| 547 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 548 | static struct snd_kcontrol_new snd_miro_controls[] __devinitdata = { |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 549 | MIRO_DOUBLE("Master Playback Volume", 0, ACI_GET_MASTER, ACI_SET_MASTER), |
| 550 | MIRO_DOUBLE("Mic Playback Volume", 1, ACI_GET_MIC, ACI_SET_MIC), |
| 551 | MIRO_DOUBLE("Line Playback Volume", 1, ACI_GET_LINE, ACI_SET_LINE), |
| 552 | MIRO_DOUBLE("CD Playback Volume", 0, ACI_GET_CD, ACI_SET_CD), |
| 553 | MIRO_DOUBLE("Synth Playback Volume", 0, ACI_GET_SYNTH, ACI_SET_SYNTH), |
| 554 | MIRO_DOUBLE("PCM Playback Volume", 1, ACI_GET_PCM, ACI_SET_PCM), |
| 555 | MIRO_DOUBLE("Aux Playback Volume", 2, ACI_GET_LINE2, ACI_SET_LINE2), |
| 556 | }; |
| 557 | |
| 558 | /* Equalizer with seven bands (only PCM20) |
| 559 | from -12dB up to +12dB on each band */ |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 560 | static struct snd_kcontrol_new snd_miro_eq_controls[] __devinitdata = { |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 561 | MIRO_DOUBLE("Tone Control - 28 Hz", 0, ACI_GET_EQ1, ACI_SET_EQ1), |
| 562 | MIRO_DOUBLE("Tone Control - 160 Hz", 0, ACI_GET_EQ2, ACI_SET_EQ2), |
| 563 | MIRO_DOUBLE("Tone Control - 400 Hz", 0, ACI_GET_EQ3, ACI_SET_EQ3), |
| 564 | MIRO_DOUBLE("Tone Control - 1 kHz", 0, ACI_GET_EQ4, ACI_SET_EQ4), |
| 565 | MIRO_DOUBLE("Tone Control - 2.5 kHz", 0, ACI_GET_EQ5, ACI_SET_EQ5), |
| 566 | MIRO_DOUBLE("Tone Control - 6.3 kHz", 0, ACI_GET_EQ6, ACI_SET_EQ6), |
| 567 | MIRO_DOUBLE("Tone Control - 16 kHz", 0, ACI_GET_EQ7, ACI_SET_EQ7), |
| 568 | }; |
| 569 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 570 | static struct snd_kcontrol_new snd_miro_radio_control[] __devinitdata = { |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 571 | MIRO_DOUBLE("Radio Playback Volume", 0, ACI_GET_LINE1, ACI_SET_LINE1), |
| 572 | }; |
| 573 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 574 | static struct snd_kcontrol_new snd_miro_line_control[] __devinitdata = { |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 575 | MIRO_DOUBLE("Line Playback Volume", 2, ACI_GET_LINE1, ACI_SET_LINE1), |
| 576 | }; |
| 577 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 578 | static struct snd_kcontrol_new snd_miro_preamp_control[] __devinitdata = { |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 579 | { |
| 580 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 581 | .name = "Mic Boost", |
| 582 | .index = 1, |
| 583 | .info = snd_miro_info_preamp, |
| 584 | .get = snd_miro_get_preamp, |
| 585 | .put = snd_miro_put_preamp, |
| 586 | }}; |
| 587 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 588 | static struct snd_kcontrol_new snd_miro_amp_control[] __devinitdata = { |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 589 | { |
| 590 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 591 | .name = "Line Boost", |
| 592 | .index = 0, |
| 593 | .info = snd_miro_info_amp, |
| 594 | .get = snd_miro_get_amp, |
| 595 | .put = snd_miro_put_amp, |
| 596 | }}; |
| 597 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 598 | static struct snd_kcontrol_new snd_miro_capture_control[] __devinitdata = { |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 599 | { |
| 600 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 601 | .name = "PCM Capture Switch", |
| 602 | .index = 0, |
| 603 | .info = snd_miro_info_capture, |
| 604 | .get = snd_miro_get_capture, |
| 605 | .put = snd_miro_put_capture, |
| 606 | }}; |
| 607 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 608 | static unsigned char aci_init_values[][2] __devinitdata = { |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 609 | { ACI_SET_MUTE, 0x00 }, |
| 610 | { ACI_SET_POWERAMP, 0x00 }, |
| 611 | { ACI_SET_PREAMP, 0x00 }, |
| 612 | { ACI_SET_SOLOMODE, 0x00 }, |
| 613 | { ACI_SET_MIC + 0, 0x20 }, |
| 614 | { ACI_SET_MIC + 8, 0x20 }, |
| 615 | { ACI_SET_LINE + 0, 0x20 }, |
| 616 | { ACI_SET_LINE + 8, 0x20 }, |
| 617 | { ACI_SET_CD + 0, 0x20 }, |
| 618 | { ACI_SET_CD + 8, 0x20 }, |
| 619 | { ACI_SET_PCM + 0, 0x20 }, |
| 620 | { ACI_SET_PCM + 8, 0x20 }, |
| 621 | { ACI_SET_LINE1 + 0, 0x20 }, |
| 622 | { ACI_SET_LINE1 + 8, 0x20 }, |
| 623 | { ACI_SET_LINE2 + 0, 0x20 }, |
| 624 | { ACI_SET_LINE2 + 8, 0x20 }, |
| 625 | { ACI_SET_SYNTH + 0, 0x20 }, |
| 626 | { ACI_SET_SYNTH + 8, 0x20 }, |
| 627 | { ACI_SET_MASTER + 0, 0x20 }, |
| 628 | { ACI_SET_MASTER + 1, 0x20 }, |
| 629 | }; |
| 630 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 631 | static int __devinit snd_set_aci_init_values(struct snd_miro *miro) |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 632 | { |
| 633 | int idx, error; |
| 634 | |
| 635 | /* enable WSS on PCM1 */ |
| 636 | |
| 637 | if ((miro->aci_product == 'A') && wss) { |
| 638 | if ((error = aci_setvalue(miro, ACI_SET_WSS, wss)) < 0) { |
| 639 | snd_printk(KERN_ERR "enabling WSS mode failed\n"); |
| 640 | return error; |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | /* enable IDE port */ |
| 645 | |
| 646 | if (ide) { |
| 647 | if ((error = aci_setvalue(miro, ACI_SET_IDE, ide)) < 0) { |
| 648 | snd_printk(KERN_ERR "enabling IDE port failed\n"); |
| 649 | return error; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | /* set common aci values */ |
| 654 | |
| 655 | for (idx = 0; idx < ARRAY_SIZE(aci_init_values); idx++) |
| 656 | if ((error = aci_setvalue(miro, aci_init_values[idx][0], |
| 657 | aci_init_values[idx][1])) < 0) { |
| 658 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", |
| 659 | aci_init_values[idx][0], error); |
| 660 | return error; |
| 661 | } |
| 662 | |
| 663 | miro->aci_amp = 0; |
| 664 | miro->aci_preamp = 0; |
| 665 | miro->aci_solomode = 1; |
| 666 | |
| 667 | return 0; |
| 668 | } |
| 669 | |
Randy Dunlap | 9478bc3 | 2008-01-23 11:52:38 +0100 | [diff] [blame] | 670 | static int __devinit snd_miro_mixer(struct snd_miro *miro) |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 671 | { |
| 672 | struct snd_card *card; |
| 673 | unsigned int idx; |
| 674 | int err; |
| 675 | |
Takashi Iwai | 622207d | 2008-08-08 17:11:45 +0200 | [diff] [blame] | 676 | if (snd_BUG_ON(!miro || !miro->card)) |
| 677 | return -EINVAL; |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 678 | |
| 679 | card = miro->card; |
| 680 | |
| 681 | switch (miro->hardware) { |
| 682 | case OPTi9XX_HW_82C924: |
| 683 | strcpy(card->mixername, "ACI & OPTi924"); |
| 684 | break; |
| 685 | case OPTi9XX_HW_82C929: |
| 686 | strcpy(card->mixername, "ACI & OPTi929"); |
| 687 | break; |
| 688 | default: |
| 689 | snd_BUG(); |
| 690 | break; |
| 691 | } |
| 692 | |
| 693 | for (idx = 0; idx < ARRAY_SIZE(snd_miro_controls); idx++) { |
| 694 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_controls[idx], miro))) < 0) |
| 695 | return err; |
| 696 | } |
| 697 | |
| 698 | if ((miro->aci_product == 'A') || (miro->aci_product == 'B')) { |
| 699 | /* PCM1/PCM12 with power-amp and Line 2 */ |
| 700 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_line_control[0], miro))) < 0) |
| 701 | return err; |
| 702 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_amp_control[0], miro))) < 0) |
| 703 | return err; |
| 704 | } |
| 705 | |
| 706 | if ((miro->aci_product == 'B') || (miro->aci_product == 'C')) { |
| 707 | /* PCM12/PCM20 with mic-preamp */ |
| 708 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_preamp_control[0], miro))) < 0) |
| 709 | return err; |
| 710 | if (miro->aci_version >= 176) |
| 711 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_capture_control[0], miro))) < 0) |
| 712 | return err; |
| 713 | } |
| 714 | |
| 715 | if (miro->aci_product == 'C') { |
| 716 | /* PCM20 with radio and 7 band equalizer */ |
| 717 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_radio_control[0], miro))) < 0) |
| 718 | return err; |
| 719 | for (idx = 0; idx < ARRAY_SIZE(snd_miro_eq_controls); idx++) { |
| 720 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_eq_controls[idx], miro))) < 0) |
| 721 | return err; |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | return 0; |
| 726 | } |
| 727 | |
| 728 | static long snd_legacy_find_free_ioport(long *port_table, long size) |
| 729 | { |
| 730 | while (*port_table != -1) { |
| 731 | struct resource *res; |
| 732 | if ((res = request_region(*port_table, size, |
| 733 | "ALSA test")) != NULL) { |
Takashi Iwai | 10d150e | 2006-03-27 13:42:39 +0200 | [diff] [blame] | 734 | release_and_free_resource(res); |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 735 | return *port_table; |
| 736 | } |
| 737 | port_table++; |
| 738 | } |
| 739 | return -1; |
| 740 | } |
| 741 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 742 | static int __devinit snd_miro_init(struct snd_miro *chip, |
| 743 | unsigned short hardware) |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 744 | { |
| 745 | static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2}; |
| 746 | |
| 747 | chip->hardware = hardware; |
| 748 | strcpy(chip->name, snd_opti9xx_names[hardware]); |
| 749 | |
| 750 | chip->mc_base_size = opti9xx_mc_size[hardware]; |
| 751 | |
| 752 | spin_lock_init(&chip->lock); |
| 753 | |
| 754 | chip->wss_base = -1; |
| 755 | chip->irq = -1; |
| 756 | chip->dma1 = -1; |
| 757 | chip->dma2 = -1; |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 758 | chip->mpu_port = -1; |
| 759 | chip->mpu_irq = -1; |
| 760 | |
| 761 | switch (hardware) { |
| 762 | case OPTi9XX_HW_82C929: |
| 763 | chip->mc_base = 0xf8c; |
| 764 | chip->password = 0xe3; |
| 765 | chip->pwd_reg = 3; |
| 766 | break; |
| 767 | |
| 768 | case OPTi9XX_HW_82C924: |
| 769 | chip->mc_base = 0xf8c; |
| 770 | chip->password = 0xe5; |
| 771 | chip->pwd_reg = 3; |
| 772 | break; |
| 773 | |
| 774 | default: |
| 775 | snd_printk(KERN_ERR "sorry, no support for %d\n", hardware); |
| 776 | return -ENODEV; |
| 777 | } |
| 778 | |
| 779 | return 0; |
| 780 | } |
| 781 | |
| 782 | static unsigned char snd_miro_read(struct snd_miro *chip, |
| 783 | unsigned char reg) |
| 784 | { |
| 785 | unsigned long flags; |
| 786 | unsigned char retval = 0xff; |
| 787 | |
| 788 | spin_lock_irqsave(&chip->lock, flags); |
| 789 | outb(chip->password, chip->mc_base + chip->pwd_reg); |
| 790 | |
| 791 | switch (chip->hardware) { |
| 792 | case OPTi9XX_HW_82C924: |
| 793 | if (reg > 7) { |
| 794 | outb(reg, chip->mc_base + 8); |
| 795 | outb(chip->password, chip->mc_base + chip->pwd_reg); |
| 796 | retval = inb(chip->mc_base + 9); |
| 797 | break; |
| 798 | } |
| 799 | |
| 800 | case OPTi9XX_HW_82C929: |
| 801 | retval = inb(chip->mc_base + reg); |
| 802 | break; |
| 803 | |
| 804 | default: |
| 805 | snd_printk(KERN_ERR "sorry, no support for %d\n", chip->hardware); |
| 806 | } |
| 807 | |
| 808 | spin_unlock_irqrestore(&chip->lock, flags); |
| 809 | return retval; |
| 810 | } |
| 811 | |
| 812 | static void snd_miro_write(struct snd_miro *chip, unsigned char reg, |
| 813 | unsigned char value) |
| 814 | { |
| 815 | unsigned long flags; |
| 816 | |
| 817 | spin_lock_irqsave(&chip->lock, flags); |
| 818 | outb(chip->password, chip->mc_base + chip->pwd_reg); |
| 819 | |
| 820 | switch (chip->hardware) { |
| 821 | case OPTi9XX_HW_82C924: |
| 822 | if (reg > 7) { |
| 823 | outb(reg, chip->mc_base + 8); |
| 824 | outb(chip->password, chip->mc_base + chip->pwd_reg); |
| 825 | outb(value, chip->mc_base + 9); |
| 826 | break; |
| 827 | } |
| 828 | |
| 829 | case OPTi9XX_HW_82C929: |
| 830 | outb(value, chip->mc_base + reg); |
| 831 | break; |
| 832 | |
| 833 | default: |
| 834 | snd_printk(KERN_ERR "sorry, no support for %d\n", chip->hardware); |
| 835 | } |
| 836 | |
| 837 | spin_unlock_irqrestore(&chip->lock, flags); |
| 838 | } |
| 839 | |
| 840 | |
| 841 | #define snd_miro_write_mask(chip, reg, value, mask) \ |
| 842 | snd_miro_write(chip, reg, \ |
| 843 | (snd_miro_read(chip, reg) & ~(mask)) | ((value) & (mask))) |
| 844 | |
| 845 | /* |
| 846 | * Proc Interface |
| 847 | */ |
| 848 | |
| 849 | static void snd_miro_proc_read(struct snd_info_entry * entry, |
| 850 | struct snd_info_buffer *buffer) |
| 851 | { |
| 852 | struct snd_miro *miro = (struct snd_miro *) entry->private_data; |
| 853 | char* model = "unknown"; |
| 854 | |
| 855 | /* miroSOUND PCM1 pro, early PCM12 */ |
| 856 | |
| 857 | if ((miro->hardware == OPTi9XX_HW_82C929) && |
| 858 | (miro->aci_vendor == 'm') && |
| 859 | (miro->aci_product == 'A')) { |
| 860 | switch(miro->aci_version) { |
| 861 | case 3: |
| 862 | model = "miroSOUND PCM1 pro"; |
| 863 | break; |
| 864 | default: |
| 865 | model = "miroSOUND PCM1 pro / (early) PCM12"; |
| 866 | break; |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | /* miroSOUND PCM12, PCM12 (Rev. E), PCM12 pnp */ |
| 871 | |
| 872 | if ((miro->hardware == OPTi9XX_HW_82C924) && |
| 873 | (miro->aci_vendor == 'm') && |
| 874 | (miro->aci_product == 'B')) { |
| 875 | switch(miro->aci_version) { |
| 876 | case 4: |
| 877 | model = "miroSOUND PCM12"; |
| 878 | break; |
| 879 | case 176: |
| 880 | model = "miroSOUND PCM12 (Rev. E)"; |
| 881 | break; |
| 882 | default: |
| 883 | model = "miroSOUND PCM12 / PCM12 pnp"; |
| 884 | break; |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | /* miroSOUND PCM20 radio */ |
| 889 | |
| 890 | if ((miro->hardware == OPTi9XX_HW_82C924) && |
| 891 | (miro->aci_vendor == 'm') && |
| 892 | (miro->aci_product == 'C')) { |
| 893 | switch(miro->aci_version) { |
| 894 | case 7: |
| 895 | model = "miroSOUND PCM20 radio (Rev. E)"; |
| 896 | break; |
| 897 | default: |
| 898 | model = "miroSOUND PCM20 radio"; |
| 899 | break; |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | snd_iprintf(buffer, "\nGeneral information:\n"); |
| 904 | snd_iprintf(buffer, " model : %s\n", model); |
| 905 | snd_iprintf(buffer, " opti : %s\n", miro->name); |
| 906 | snd_iprintf(buffer, " codec : %s\n", miro->pcm->name); |
| 907 | snd_iprintf(buffer, " port : 0x%lx\n", miro->wss_base); |
| 908 | snd_iprintf(buffer, " irq : %d\n", miro->irq); |
| 909 | snd_iprintf(buffer, " dma : %d,%d\n\n", miro->dma1, miro->dma2); |
| 910 | |
| 911 | snd_iprintf(buffer, "MPU-401:\n"); |
| 912 | snd_iprintf(buffer, " port : 0x%lx\n", miro->mpu_port); |
| 913 | snd_iprintf(buffer, " irq : %d\n\n", miro->mpu_irq); |
| 914 | |
| 915 | snd_iprintf(buffer, "ACI information:\n"); |
| 916 | snd_iprintf(buffer, " vendor : "); |
| 917 | switch(miro->aci_vendor) { |
| 918 | case 'm': |
| 919 | snd_iprintf(buffer, "Miro\n"); |
| 920 | break; |
| 921 | default: |
| 922 | snd_iprintf(buffer, "unknown (0x%x)\n", miro->aci_vendor); |
| 923 | break; |
| 924 | } |
| 925 | |
| 926 | snd_iprintf(buffer, " product : "); |
| 927 | switch(miro->aci_product) { |
| 928 | case 'A': |
| 929 | snd_iprintf(buffer, "miroSOUND PCM1 pro / (early) PCM12\n"); |
| 930 | break; |
| 931 | case 'B': |
| 932 | snd_iprintf(buffer, "miroSOUND PCM12\n"); |
| 933 | break; |
| 934 | case 'C': |
| 935 | snd_iprintf(buffer, "miroSOUND PCM20 radio\n"); |
| 936 | break; |
| 937 | default: |
| 938 | snd_iprintf(buffer, "unknown (0x%x)\n", miro->aci_product); |
| 939 | break; |
| 940 | } |
| 941 | |
| 942 | snd_iprintf(buffer, " firmware: %d (0x%x)\n", |
| 943 | miro->aci_version, miro->aci_version); |
| 944 | snd_iprintf(buffer, " port : 0x%lx-0x%lx\n", |
| 945 | miro->aci_port, miro->aci_port+2); |
| 946 | snd_iprintf(buffer, " wss : 0x%x\n", wss); |
| 947 | snd_iprintf(buffer, " ide : 0x%x\n", ide); |
| 948 | snd_iprintf(buffer, " solomode: 0x%x\n", miro->aci_solomode); |
| 949 | snd_iprintf(buffer, " amp : 0x%x\n", miro->aci_amp); |
| 950 | snd_iprintf(buffer, " preamp : 0x%x\n", miro->aci_preamp); |
| 951 | } |
| 952 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 953 | static void __devinit snd_miro_proc_init(struct snd_miro * miro) |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 954 | { |
| 955 | struct snd_info_entry *entry; |
| 956 | |
| 957 | if (! snd_card_proc_new(miro->card, "miro", &entry)) |
Takashi Iwai | bf85020 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 958 | snd_info_set_text_ops(entry, miro, snd_miro_proc_read); |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | /* |
| 962 | * Init |
| 963 | */ |
| 964 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 965 | static int __devinit snd_miro_configure(struct snd_miro *chip) |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 966 | { |
| 967 | unsigned char wss_base_bits; |
| 968 | unsigned char irq_bits; |
| 969 | unsigned char dma_bits; |
| 970 | unsigned char mpu_port_bits = 0; |
| 971 | unsigned char mpu_irq_bits; |
| 972 | unsigned long flags; |
| 973 | |
| 974 | switch (chip->hardware) { |
| 975 | case OPTi9XX_HW_82C924: |
| 976 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02); |
| 977 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80); |
| 978 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */ |
| 979 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff); |
| 980 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02); |
| 981 | break; |
| 982 | case OPTi9XX_HW_82C929: |
| 983 | /* untested init commands for OPTi929 */ |
| 984 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80); |
| 985 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */ |
| 986 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c); |
| 987 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02); |
| 988 | break; |
| 989 | default: |
| 990 | snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware); |
| 991 | return -EINVAL; |
| 992 | } |
| 993 | |
| 994 | switch (chip->wss_base) { |
| 995 | case 0x530: |
| 996 | wss_base_bits = 0x00; |
| 997 | break; |
| 998 | case 0x604: |
| 999 | wss_base_bits = 0x03; |
| 1000 | break; |
| 1001 | case 0xe80: |
| 1002 | wss_base_bits = 0x01; |
| 1003 | break; |
| 1004 | case 0xf40: |
| 1005 | wss_base_bits = 0x02; |
| 1006 | break; |
| 1007 | default: |
| 1008 | snd_printk(KERN_ERR "WSS port 0x%lx not valid\n", chip->wss_base); |
| 1009 | goto __skip_base; |
| 1010 | } |
| 1011 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30); |
| 1012 | |
| 1013 | __skip_base: |
| 1014 | switch (chip->irq) { |
| 1015 | case 5: |
| 1016 | irq_bits = 0x05; |
| 1017 | break; |
| 1018 | case 7: |
| 1019 | irq_bits = 0x01; |
| 1020 | break; |
| 1021 | case 9: |
| 1022 | irq_bits = 0x02; |
| 1023 | break; |
| 1024 | case 10: |
| 1025 | irq_bits = 0x03; |
| 1026 | break; |
| 1027 | case 11: |
| 1028 | irq_bits = 0x04; |
| 1029 | break; |
| 1030 | default: |
| 1031 | snd_printk(KERN_ERR "WSS irq # %d not valid\n", chip->irq); |
| 1032 | goto __skip_resources; |
| 1033 | } |
| 1034 | |
| 1035 | switch (chip->dma1) { |
| 1036 | case 0: |
| 1037 | dma_bits = 0x01; |
| 1038 | break; |
| 1039 | case 1: |
| 1040 | dma_bits = 0x02; |
| 1041 | break; |
| 1042 | case 3: |
| 1043 | dma_bits = 0x03; |
| 1044 | break; |
| 1045 | default: |
| 1046 | snd_printk(KERN_ERR "WSS dma1 # %d not valid\n", chip->dma1); |
| 1047 | goto __skip_resources; |
| 1048 | } |
| 1049 | |
| 1050 | if (chip->dma1 == chip->dma2) { |
| 1051 | snd_printk(KERN_ERR "don't want to share dmas\n"); |
| 1052 | return -EBUSY; |
| 1053 | } |
| 1054 | |
| 1055 | switch (chip->dma2) { |
| 1056 | case 0: |
| 1057 | case 1: |
| 1058 | break; |
| 1059 | default: |
| 1060 | snd_printk(KERN_ERR "WSS dma2 # %d not valid\n", chip->dma2); |
| 1061 | goto __skip_resources; |
| 1062 | } |
| 1063 | dma_bits |= 0x04; |
| 1064 | |
| 1065 | spin_lock_irqsave(&chip->lock, flags); |
| 1066 | outb(irq_bits << 3 | dma_bits, chip->wss_base); |
| 1067 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1068 | |
| 1069 | __skip_resources: |
| 1070 | if (chip->hardware > OPTi9XX_HW_82C928) { |
| 1071 | switch (chip->mpu_port) { |
| 1072 | case 0: |
| 1073 | case -1: |
| 1074 | break; |
| 1075 | case 0x300: |
| 1076 | mpu_port_bits = 0x03; |
| 1077 | break; |
| 1078 | case 0x310: |
| 1079 | mpu_port_bits = 0x02; |
| 1080 | break; |
| 1081 | case 0x320: |
| 1082 | mpu_port_bits = 0x01; |
| 1083 | break; |
| 1084 | case 0x330: |
| 1085 | mpu_port_bits = 0x00; |
| 1086 | break; |
| 1087 | default: |
| 1088 | snd_printk(KERN_ERR "MPU-401 port 0x%lx not valid\n", |
| 1089 | chip->mpu_port); |
| 1090 | goto __skip_mpu; |
| 1091 | } |
| 1092 | |
| 1093 | switch (chip->mpu_irq) { |
| 1094 | case 5: |
| 1095 | mpu_irq_bits = 0x02; |
| 1096 | break; |
| 1097 | case 7: |
| 1098 | mpu_irq_bits = 0x03; |
| 1099 | break; |
| 1100 | case 9: |
| 1101 | mpu_irq_bits = 0x00; |
| 1102 | break; |
| 1103 | case 10: |
| 1104 | mpu_irq_bits = 0x01; |
| 1105 | break; |
| 1106 | default: |
| 1107 | snd_printk(KERN_ERR "MPU-401 irq # %d not valid\n", |
| 1108 | chip->mpu_irq); |
| 1109 | goto __skip_mpu; |
| 1110 | } |
| 1111 | |
| 1112 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(6), |
| 1113 | (chip->mpu_port <= 0) ? 0x00 : |
| 1114 | 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3, |
| 1115 | 0xf8); |
| 1116 | } |
| 1117 | __skip_mpu: |
| 1118 | |
| 1119 | return 0; |
| 1120 | } |
| 1121 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 1122 | static int __devinit snd_card_miro_detect(struct snd_card *card, |
| 1123 | struct snd_miro *chip) |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1124 | { |
| 1125 | int i, err; |
| 1126 | unsigned char value; |
| 1127 | |
| 1128 | for (i = OPTi9XX_HW_82C929; i <= OPTi9XX_HW_82C924; i++) { |
| 1129 | |
| 1130 | if ((err = snd_miro_init(chip, i)) < 0) |
| 1131 | return err; |
| 1132 | |
| 1133 | if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL) |
| 1134 | continue; |
| 1135 | |
| 1136 | value = snd_miro_read(chip, OPTi9XX_MC_REG(1)); |
| 1137 | if ((value != 0xff) && (value != inb(chip->mc_base + 1))) |
| 1138 | if (value == snd_miro_read(chip, OPTi9XX_MC_REG(1))) |
| 1139 | return 1; |
| 1140 | |
Takashi Iwai | 10d150e | 2006-03-27 13:42:39 +0200 | [diff] [blame] | 1141 | release_and_free_resource(chip->res_mc_base); |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1142 | chip->res_mc_base = NULL; |
| 1143 | |
| 1144 | } |
| 1145 | |
| 1146 | return -ENODEV; |
| 1147 | } |
| 1148 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 1149 | static int __devinit snd_card_miro_aci_detect(struct snd_card *card, |
| 1150 | struct snd_miro * miro) |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1151 | { |
| 1152 | unsigned char regval; |
| 1153 | int i; |
| 1154 | |
| 1155 | mutex_init(&miro->aci_mutex); |
| 1156 | |
| 1157 | /* get ACI port from OPTi9xx MC 4 */ |
| 1158 | |
| 1159 | miro->mc_base = 0xf8c; |
| 1160 | regval=inb(miro->mc_base + 4); |
| 1161 | miro->aci_port = (regval & 0x10) ? 0x344: 0x354; |
| 1162 | |
| 1163 | if ((miro->res_aci_port = request_region(miro->aci_port, 3, "miro aci")) == NULL) { |
| 1164 | snd_printk(KERN_ERR "aci i/o area 0x%lx-0x%lx already used.\n", |
| 1165 | miro->aci_port, miro->aci_port+2); |
| 1166 | return -ENOMEM; |
| 1167 | } |
| 1168 | |
| 1169 | /* force ACI into a known state */ |
| 1170 | for (i = 0; i < 3; i++) |
| 1171 | if (aci_cmd(miro, ACI_ERROR_OP, -1, -1) < 0) { |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1172 | snd_printk(KERN_ERR "can't force aci into known state.\n"); |
| 1173 | return -ENXIO; |
| 1174 | } |
| 1175 | |
| 1176 | if ((miro->aci_vendor=aci_cmd(miro, ACI_READ_IDCODE, -1, -1)) < 0 || |
| 1177 | (miro->aci_product=aci_cmd(miro, ACI_READ_IDCODE, -1, -1)) < 0) { |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1178 | snd_printk(KERN_ERR "can't read aci id on 0x%lx.\n", miro->aci_port); |
| 1179 | return -ENXIO; |
| 1180 | } |
| 1181 | |
| 1182 | if ((miro->aci_version=aci_cmd(miro, ACI_READ_VERSION, -1, -1)) < 0) { |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1183 | snd_printk(KERN_ERR "can't read aci version on 0x%lx.\n", |
| 1184 | miro->aci_port); |
| 1185 | return -ENXIO; |
| 1186 | } |
| 1187 | |
| 1188 | if (aci_cmd(miro, ACI_INIT, -1, -1) < 0 || |
| 1189 | aci_cmd(miro, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0 || |
| 1190 | aci_cmd(miro, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0) { |
| 1191 | snd_printk(KERN_ERR "can't initialize aci.\n"); |
| 1192 | return -ENXIO; |
| 1193 | } |
| 1194 | |
| 1195 | return 0; |
| 1196 | } |
| 1197 | |
| 1198 | static void snd_card_miro_free(struct snd_card *card) |
| 1199 | { |
| 1200 | struct snd_miro *miro = card->private_data; |
| 1201 | |
| 1202 | release_and_free_resource(miro->res_aci_port); |
| 1203 | release_and_free_resource(miro->res_mc_base); |
| 1204 | } |
| 1205 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 1206 | static int __devinit snd_miro_match(struct device *devptr, unsigned int n) |
| 1207 | { |
| 1208 | return 1; |
| 1209 | } |
| 1210 | |
| 1211 | static int __devinit snd_miro_probe(struct device *devptr, unsigned int n) |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1212 | { |
| 1213 | static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1}; |
| 1214 | static long possible_mpu_ports[] = {0x330, 0x300, 0x310, 0x320, -1}; |
| 1215 | static int possible_irqs[] = {11, 9, 10, 7, -1}; |
| 1216 | static int possible_mpu_irqs[] = {10, 5, 9, 7, -1}; |
| 1217 | static int possible_dma1s[] = {3, 1, 0, -1}; |
| 1218 | static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}}; |
| 1219 | |
| 1220 | int error; |
| 1221 | struct snd_miro *miro; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1222 | struct snd_wss *codec; |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1223 | struct snd_timer *timer; |
| 1224 | struct snd_card *card; |
| 1225 | struct snd_pcm *pcm; |
| 1226 | struct snd_rawmidi *rmidi; |
| 1227 | |
Takashi Iwai | c95eadd | 2008-12-28 16:43:35 +0100 | [diff] [blame] | 1228 | error = snd_card_create(index, id, THIS_MODULE, |
| 1229 | sizeof(struct snd_miro), &card); |
| 1230 | if (error < 0) |
| 1231 | return error; |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1232 | |
| 1233 | card->private_free = snd_card_miro_free; |
| 1234 | miro = card->private_data; |
| 1235 | miro->card = card; |
| 1236 | |
| 1237 | if ((error = snd_card_miro_aci_detect(card, miro)) < 0) { |
| 1238 | snd_card_free(card); |
| 1239 | snd_printk(KERN_ERR "unable to detect aci chip\n"); |
| 1240 | return -ENODEV; |
| 1241 | } |
| 1242 | |
| 1243 | /* init proc interface */ |
| 1244 | snd_miro_proc_init(miro); |
| 1245 | |
| 1246 | if ((error = snd_card_miro_detect(card, miro)) < 0) { |
| 1247 | snd_card_free(card); |
| 1248 | snd_printk(KERN_ERR "unable to detect OPTi9xx chip\n"); |
| 1249 | return -ENODEV; |
| 1250 | } |
| 1251 | |
| 1252 | if (! miro->res_mc_base && |
| 1253 | (miro->res_mc_base = request_region(miro->mc_base, miro->mc_base_size, |
| 1254 | "miro (OPTi9xx MC)")) == NULL) { |
| 1255 | snd_card_free(card); |
| 1256 | snd_printk(KERN_ERR "request for OPTI9xx MC failed\n"); |
| 1257 | return -ENOMEM; |
| 1258 | } |
| 1259 | |
| 1260 | miro->wss_base = port; |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1261 | miro->mpu_port = mpu_port; |
| 1262 | miro->irq = irq; |
| 1263 | miro->mpu_irq = mpu_irq; |
| 1264 | miro->dma1 = dma1; |
| 1265 | miro->dma2 = dma2; |
| 1266 | |
| 1267 | if (miro->wss_base == SNDRV_AUTO_PORT) { |
| 1268 | if ((miro->wss_base = snd_legacy_find_free_ioport(possible_ports, 4)) < 0) { |
| 1269 | snd_card_free(card); |
| 1270 | snd_printk(KERN_ERR "unable to find a free WSS port\n"); |
| 1271 | return -EBUSY; |
| 1272 | } |
| 1273 | } |
| 1274 | |
Krzysztof Helt | b67cad9 | 2009-11-17 18:35:41 +0100 | [diff] [blame^] | 1275 | if (mpu_port == SNDRV_AUTO_PORT) { |
| 1276 | mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2); |
| 1277 | if (mpu_port < 0) { |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1278 | snd_card_free(card); |
| 1279 | snd_printk(KERN_ERR "unable to find a free MPU401 port\n"); |
Krzysztof Helt | b67cad9 | 2009-11-17 18:35:41 +0100 | [diff] [blame^] | 1280 | return -EBUSY |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1281 | } |
| 1282 | } |
| 1283 | if (miro->irq == SNDRV_AUTO_IRQ) { |
| 1284 | if ((miro->irq = snd_legacy_find_free_irq(possible_irqs)) < 0) { |
| 1285 | snd_card_free(card); |
| 1286 | snd_printk(KERN_ERR "unable to find a free IRQ\n"); |
| 1287 | return -EBUSY; |
| 1288 | } |
| 1289 | } |
| 1290 | if (miro->mpu_irq == SNDRV_AUTO_IRQ) { |
| 1291 | if ((miro->mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) { |
| 1292 | snd_card_free(card); |
| 1293 | snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n"); |
| 1294 | return -EBUSY; |
| 1295 | } |
| 1296 | } |
| 1297 | if (miro->dma1 == SNDRV_AUTO_DMA) { |
| 1298 | if ((miro->dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) { |
| 1299 | snd_card_free(card); |
| 1300 | snd_printk(KERN_ERR "unable to find a free DMA1\n"); |
| 1301 | return -EBUSY; |
| 1302 | } |
| 1303 | } |
| 1304 | if (miro->dma2 == SNDRV_AUTO_DMA) { |
| 1305 | if ((miro->dma2 = snd_legacy_find_free_dma(possible_dma2s[miro->dma1 % 4])) < 0) { |
| 1306 | snd_card_free(card); |
| 1307 | snd_printk(KERN_ERR "unable to find a free DMA2\n"); |
| 1308 | return -EBUSY; |
| 1309 | } |
| 1310 | } |
| 1311 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1312 | error = snd_miro_configure(miro); |
| 1313 | if (error) { |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1314 | snd_card_free(card); |
| 1315 | return error; |
| 1316 | } |
| 1317 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1318 | error = snd_wss_create(card, miro->wss_base + 4, -1, |
| 1319 | miro->irq, miro->dma1, miro->dma2, |
| 1320 | WSS_HW_AD1845, 0, &codec); |
| 1321 | if (error < 0) { |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1322 | snd_card_free(card); |
| 1323 | return error; |
| 1324 | } |
| 1325 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1326 | error = snd_wss_pcm(codec, 0, &pcm); |
| 1327 | if (error < 0) { |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1328 | snd_card_free(card); |
| 1329 | return error; |
| 1330 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1331 | error = snd_wss_mixer(codec); |
| 1332 | if (error < 0) { |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1333 | snd_card_free(card); |
| 1334 | return error; |
| 1335 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1336 | error = snd_wss_timer(codec, 0, &timer); |
| 1337 | if (error < 0) { |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1338 | snd_card_free(card); |
| 1339 | return error; |
| 1340 | } |
| 1341 | |
| 1342 | miro->pcm = pcm; |
| 1343 | |
| 1344 | if ((error = snd_miro_mixer(miro)) < 0) { |
| 1345 | snd_card_free(card); |
| 1346 | return error; |
| 1347 | } |
| 1348 | |
| 1349 | if (miro->aci_vendor == 'm') { |
| 1350 | /* It looks like a miro sound card. */ |
| 1351 | switch (miro->aci_product) { |
| 1352 | case 'A': |
| 1353 | sprintf(card->shortname, |
| 1354 | "miroSOUND PCM1 pro / PCM12"); |
| 1355 | break; |
| 1356 | case 'B': |
| 1357 | sprintf(card->shortname, |
| 1358 | "miroSOUND PCM12"); |
| 1359 | break; |
| 1360 | case 'C': |
| 1361 | sprintf(card->shortname, |
| 1362 | "miroSOUND PCM20 radio"); |
| 1363 | break; |
| 1364 | default: |
| 1365 | sprintf(card->shortname, |
| 1366 | "unknown miro"); |
| 1367 | snd_printk(KERN_INFO "unknown miro aci id\n"); |
| 1368 | break; |
| 1369 | } |
| 1370 | } else { |
| 1371 | snd_printk(KERN_INFO "found unsupported aci card\n"); |
| 1372 | sprintf(card->shortname, "unknown Cardinal Technologies"); |
| 1373 | } |
| 1374 | |
| 1375 | strcpy(card->driver, "miro"); |
| 1376 | sprintf(card->longname, "%s: OPTi%s, %s at 0x%lx, irq %d, dma %d&%d", |
| 1377 | card->shortname, miro->name, pcm->name, miro->wss_base + 4, |
| 1378 | miro->irq, miro->dma1, miro->dma2); |
| 1379 | |
Krzysztof Helt | b67cad9 | 2009-11-17 18:35:41 +0100 | [diff] [blame^] | 1380 | if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT) |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1381 | rmidi = NULL; |
Krzysztof Helt | b67cad9 | 2009-11-17 18:35:41 +0100 | [diff] [blame^] | 1382 | else { |
| 1383 | error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, |
| 1384 | mpu_port, 0, miro->mpu_irq, IRQF_DISABLED, |
| 1385 | &rmidi); |
| 1386 | if (error < 0) |
| 1387 | snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", |
| 1388 | mpu_port); |
| 1389 | } |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1390 | |
Krzysztof Helt | b67cad9 | 2009-11-17 18:35:41 +0100 | [diff] [blame^] | 1391 | if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) { |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1392 | struct snd_opl3 *opl3 = NULL; |
| 1393 | struct snd_opl4 *opl4; |
Krzysztof Helt | b67cad9 | 2009-11-17 18:35:41 +0100 | [diff] [blame^] | 1394 | if (snd_opl4_create(card, fm_port, fm_port - 8, |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1395 | 2, &opl3, &opl4) < 0) |
Krzysztof Helt | b67cad9 | 2009-11-17 18:35:41 +0100 | [diff] [blame^] | 1396 | snd_printk(KERN_WARNING "no OPL4 device at 0x%lx\n", |
| 1397 | fm_port); |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | if ((error = snd_set_aci_init_values(miro)) < 0) { |
| 1401 | snd_card_free(card); |
| 1402 | return error; |
| 1403 | } |
| 1404 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 1405 | snd_card_set_dev(card, devptr); |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1406 | |
| 1407 | if ((error = snd_card_register(card))) { |
| 1408 | snd_card_free(card); |
| 1409 | return error; |
| 1410 | } |
| 1411 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 1412 | dev_set_drvdata(devptr, card); |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1413 | return 0; |
| 1414 | } |
| 1415 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 1416 | static int __devexit snd_miro_remove(struct device *devptr, unsigned int dev) |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1417 | { |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 1418 | snd_card_free(dev_get_drvdata(devptr)); |
| 1419 | dev_set_drvdata(devptr, NULL); |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1420 | return 0; |
| 1421 | } |
| 1422 | |
Rene Herman | 83c51c0 | 2007-03-20 11:33:46 +0100 | [diff] [blame] | 1423 | #define DEV_NAME "miro" |
| 1424 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 1425 | static struct isa_driver snd_miro_driver = { |
| 1426 | .match = snd_miro_match, |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1427 | .probe = snd_miro_probe, |
| 1428 | .remove = __devexit_p(snd_miro_remove), |
| 1429 | /* FIXME: suspend/resume */ |
| 1430 | .driver = { |
Rene Herman | 83c51c0 | 2007-03-20 11:33:46 +0100 | [diff] [blame] | 1431 | .name = DEV_NAME |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1432 | }, |
| 1433 | }; |
| 1434 | |
| 1435 | static int __init alsa_card_miro_init(void) |
| 1436 | { |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 1437 | return isa_register_driver(&snd_miro_driver, 1); |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | static void __exit alsa_card_miro_exit(void) |
| 1441 | { |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 1442 | isa_unregister_driver(&snd_miro_driver); |
Martin Langer | 1841f61 | 2006-03-27 12:41:01 +0200 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | module_init(alsa_card_miro_init) |
| 1446 | module_exit(alsa_card_miro_exit) |