| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * The driver for the Yamaha's DS1/DS1E cards |
|---|
| 3 | 4 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
|---|
| 4 | | - * |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 8 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | | - * (at your option) any later version. |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | | - * GNU General Public License for more details. |
|---|
| 15 | | - * |
|---|
| 16 | | - * You should have received a copy of the GNU General Public License |
|---|
| 17 | | - * along with this program; if not, write to the Free Software |
|---|
| 18 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | | - * |
|---|
| 20 | 5 | */ |
|---|
| 21 | 6 | |
|---|
| 22 | 7 | #include <linux/init.h> |
|---|
| .. | .. |
|---|
| 93 | 78 | |
|---|
| 94 | 79 | if (io_port == 1) { |
|---|
| 95 | 80 | /* auto-detect */ |
|---|
| 96 | | - if (!(io_port = pci_resource_start(chip->pci, 2))) |
|---|
| 81 | + io_port = pci_resource_start(chip->pci, 2); |
|---|
| 82 | + if (!io_port) |
|---|
| 97 | 83 | return -ENODEV; |
|---|
| 98 | 84 | } |
|---|
| 99 | 85 | } else { |
|---|
| .. | .. |
|---|
| 102 | 88 | for (io_port = 0x201; io_port <= 0x205; io_port++) { |
|---|
| 103 | 89 | if (io_port == 0x203) |
|---|
| 104 | 90 | continue; |
|---|
| 105 | | - if ((r = request_region(io_port, 1, "YMFPCI gameport")) != NULL) |
|---|
| 91 | + r = request_region(io_port, 1, "YMFPCI gameport"); |
|---|
| 92 | + if (r) |
|---|
| 106 | 93 | break; |
|---|
| 107 | 94 | } |
|---|
| 108 | 95 | if (!r) { |
|---|
| .. | .. |
|---|
| 123 | 110 | } |
|---|
| 124 | 111 | } |
|---|
| 125 | 112 | |
|---|
| 126 | | - if (!r && !(r = request_region(io_port, 1, "YMFPCI gameport"))) { |
|---|
| 127 | | - dev_err(chip->card->dev, |
|---|
| 128 | | - "joystick port %#x is in use.\n", io_port); |
|---|
| 129 | | - return -EBUSY; |
|---|
| 113 | + if (!r) { |
|---|
| 114 | + r = request_region(io_port, 1, "YMFPCI gameport"); |
|---|
| 115 | + if (!r) { |
|---|
| 116 | + dev_err(chip->card->dev, |
|---|
| 117 | + "joystick port %#x is in use.\n", io_port); |
|---|
| 118 | + return -EBUSY; |
|---|
| 119 | + } |
|---|
| 130 | 120 | } |
|---|
| 131 | 121 | |
|---|
| 132 | 122 | chip->gameport = gp = gameport_allocate_port(); |
|---|
| .. | .. |
|---|
| 214 | 204 | /* auto-detect */ |
|---|
| 215 | 205 | fm_port[dev] = pci_resource_start(pci, 1); |
|---|
| 216 | 206 | } |
|---|
| 217 | | - if (fm_port[dev] > 0 && |
|---|
| 218 | | - (fm_res = request_region(fm_port[dev], 4, "YMFPCI OPL3")) != NULL) { |
|---|
| 207 | + if (fm_port[dev] > 0) |
|---|
| 208 | + fm_res = request_region(fm_port[dev], 4, "YMFPCI OPL3"); |
|---|
| 209 | + if (fm_res) { |
|---|
| 219 | 210 | legacy_ctrl |= YMFPCI_LEGACY_FMEN; |
|---|
| 220 | 211 | pci_write_config_word(pci, PCIR_DSXG_FMBASE, fm_port[dev]); |
|---|
| 221 | 212 | } |
|---|
| .. | .. |
|---|
| 223 | 214 | /* auto-detect */ |
|---|
| 224 | 215 | mpu_port[dev] = pci_resource_start(pci, 1) + 0x20; |
|---|
| 225 | 216 | } |
|---|
| 226 | | - if (mpu_port[dev] > 0 && |
|---|
| 227 | | - (mpu_res = request_region(mpu_port[dev], 2, "YMFPCI MPU401")) != NULL) { |
|---|
| 217 | + if (mpu_port[dev] > 0) |
|---|
| 218 | + mpu_res = request_region(mpu_port[dev], 2, "YMFPCI MPU401"); |
|---|
| 219 | + if (mpu_res) { |
|---|
| 228 | 220 | legacy_ctrl |= YMFPCI_LEGACY_MEN; |
|---|
| 229 | 221 | pci_write_config_word(pci, PCIR_DSXG_MPU401BASE, mpu_port[dev]); |
|---|
| 230 | 222 | } |
|---|
| .. | .. |
|---|
| 236 | 228 | case 0x3a8: legacy_ctrl2 |= 3; break; |
|---|
| 237 | 229 | default: fm_port[dev] = 0; break; |
|---|
| 238 | 230 | } |
|---|
| 239 | | - if (fm_port[dev] > 0 && |
|---|
| 240 | | - (fm_res = request_region(fm_port[dev], 4, "YMFPCI OPL3")) != NULL) { |
|---|
| 231 | + if (fm_port[dev] > 0) |
|---|
| 232 | + fm_res = request_region(fm_port[dev], 4, "YMFPCI OPL3"); |
|---|
| 233 | + if (fm_res) { |
|---|
| 241 | 234 | legacy_ctrl |= YMFPCI_LEGACY_FMEN; |
|---|
| 242 | 235 | } else { |
|---|
| 243 | 236 | legacy_ctrl2 &= ~YMFPCI_LEGACY2_FMIO; |
|---|
| .. | .. |
|---|
| 250 | 243 | case 0x334: legacy_ctrl2 |= 3 << 4; break; |
|---|
| 251 | 244 | default: mpu_port[dev] = 0; break; |
|---|
| 252 | 245 | } |
|---|
| 253 | | - if (mpu_port[dev] > 0 && |
|---|
| 254 | | - (mpu_res = request_region(mpu_port[dev], 2, "YMFPCI MPU401")) != NULL) { |
|---|
| 246 | + if (mpu_port[dev] > 0) |
|---|
| 247 | + mpu_res = request_region(mpu_port[dev], 2, "YMFPCI MPU401"); |
|---|
| 248 | + if (mpu_res) { |
|---|
| 255 | 249 | legacy_ctrl |= YMFPCI_LEGACY_MEN; |
|---|
| 256 | 250 | } else { |
|---|
| 257 | 251 | legacy_ctrl2 &= ~YMFPCI_LEGACY2_MPUIO; |
|---|
| .. | .. |
|---|
| 265 | 259 | pci_read_config_word(pci, PCIR_DSXG_LEGACY, &old_legacy_ctrl); |
|---|
| 266 | 260 | pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl); |
|---|
| 267 | 261 | pci_write_config_word(pci, PCIR_DSXG_ELEGACY, legacy_ctrl2); |
|---|
| 268 | | - if ((err = snd_ymfpci_create(card, pci, |
|---|
| 269 | | - old_legacy_ctrl, |
|---|
| 270 | | - &chip)) < 0) { |
|---|
| 262 | + err = snd_ymfpci_create(card, pci, old_legacy_ctrl, &chip); |
|---|
| 263 | + if (err < 0) { |
|---|
| 271 | 264 | release_and_free_resource(mpu_res); |
|---|
| 272 | 265 | release_and_free_resource(fm_res); |
|---|
| 273 | 266 | goto free_card; |
|---|
| .. | .. |
|---|
| 308 | 301 | goto free_card; |
|---|
| 309 | 302 | |
|---|
| 310 | 303 | if (chip->mpu_res) { |
|---|
| 311 | | - if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_YMFPCI, |
|---|
| 312 | | - mpu_port[dev], |
|---|
| 313 | | - MPU401_INFO_INTEGRATED | |
|---|
| 314 | | - MPU401_INFO_IRQ_HOOK, |
|---|
| 315 | | - -1, &chip->rawmidi)) < 0) { |
|---|
| 304 | + err = snd_mpu401_uart_new(card, 0, MPU401_HW_YMFPCI, |
|---|
| 305 | + mpu_port[dev], |
|---|
| 306 | + MPU401_INFO_INTEGRATED | |
|---|
| 307 | + MPU401_INFO_IRQ_HOOK, |
|---|
| 308 | + -1, &chip->rawmidi); |
|---|
| 309 | + if (err < 0) { |
|---|
| 316 | 310 | dev_warn(card->dev, |
|---|
| 317 | 311 | "cannot initialize MPU401 at 0x%lx, skipping...\n", |
|---|
| 318 | 312 | mpu_port[dev]); |
|---|
| .. | .. |
|---|
| 321 | 315 | } |
|---|
| 322 | 316 | } |
|---|
| 323 | 317 | if (chip->fm_res) { |
|---|
| 324 | | - if ((err = snd_opl3_create(card, |
|---|
| 325 | | - fm_port[dev], |
|---|
| 326 | | - fm_port[dev] + 2, |
|---|
| 327 | | - OPL3_HW_OPL3, 1, &opl3)) < 0) { |
|---|
| 318 | + err = snd_opl3_create(card, |
|---|
| 319 | + fm_port[dev], |
|---|
| 320 | + fm_port[dev] + 2, |
|---|
| 321 | + OPL3_HW_OPL3, 1, &opl3); |
|---|
| 322 | + if (err < 0) { |
|---|
| 328 | 323 | dev_warn(card->dev, |
|---|
| 329 | 324 | "cannot initialize FM OPL3 at 0x%lx, skipping...\n", |
|---|
| 330 | 325 | fm_port[dev]); |
|---|
| 331 | 326 | legacy_ctrl &= ~YMFPCI_LEGACY_FMEN; |
|---|
| 332 | 327 | pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl); |
|---|
| 333 | | - } else if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { |
|---|
| 334 | | - dev_err(card->dev, "cannot create opl3 hwdep\n"); |
|---|
| 335 | | - goto free_card; |
|---|
| 328 | + } else { |
|---|
| 329 | + err = snd_opl3_hwdep_new(opl3, 0, 1, NULL); |
|---|
| 330 | + if (err < 0) { |
|---|
| 331 | + dev_err(card->dev, "cannot create opl3 hwdep\n"); |
|---|
| 332 | + goto free_card; |
|---|
| 333 | + } |
|---|
| 336 | 334 | } |
|---|
| 337 | 335 | } |
|---|
| 338 | 336 | |
|---|