1 // SPDX-License-Identifier: GPL-2.0-or-later 2 3 /* 4 card-ad1816a.c - driver for ADI SoundPort AD1816A based soundcards. 5 Copyright (C) 2000 by Massimo Piccioni <dafastidio@libero.it> 6 7 */ 8 9 #include <linux/init.h> 10 #include <linux/time.h> 11 #include <linux/wait.h> 12 #include <linux/pnp.h> 13 #include <linux/module.h> 14 #include <sound/core.h> 15 #include <sound/initval.h> 16 #include <sound/ad1816a.h> 17 #include <sound/mpu401.h> 18 #include <sound/opl3.h> 19 20 MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>"); 21 MODULE_DESCRIPTION("AD1816A, AD1815"); 22 MODULE_LICENSE("GPL"); 23 24 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 1-MAX */ 25 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 26 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */ 27 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ 28 static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ 29 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ 30 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */ 31 static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */ 32 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */ 33 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */ 34 static int clockfreq[SNDRV_CARDS]; 35 36 module_param_array(index, int, NULL, 0444); 37 MODULE_PARM_DESC(index, "Index value for ad1816a based soundcard."); 38 module_param_array(id, charp, NULL, 0444); 39 MODULE_PARM_DESC(id, "ID string for ad1816a based soundcard."); 40 module_param_array(enable, bool, NULL, 0444); 41 MODULE_PARM_DESC(enable, "Enable ad1816a based soundcard."); 42 module_param_array(clockfreq, int, NULL, 0444); 43 MODULE_PARM_DESC(clockfreq, "Clock frequency for ad1816a driver (default = 0)."); 44 45 static const struct pnp_card_device_id snd_ad1816a_pnpids[] = { 46 /* Analog Devices AD1815 */ 47 { .id = "ADS7150", .devs = { { .id = "ADS7150" }, { .id = "ADS7151" } } }, 48 /* Analog Devices AD1816? */ 49 { .id = "ADS7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } }, 50 /* Analog Devices AD1816A - added by Kenneth Platz <kxp@atl.hp.com> */ 51 { .id = "ADS7181", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } }, 52 /* Analog Devices AD1816A - Aztech/Newcom SC-16 3D */ 53 { .id = "AZT1022", .devs = { { .id = "AZT1018" }, { .id = "AZT2002" } } }, 54 /* Highscreen Sound-Boostar 16 3D - added by Stefan Behnel */ 55 { .id = "LWC1061", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } }, 56 /* Highscreen Sound-Boostar 16 3D */ 57 { .id = "MDK1605", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } }, 58 /* Shark Predator ISA - added by Ken Arromdee */ 59 { .id = "SMM7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } }, 60 /* Analog Devices AD1816A - Terratec AudioSystem EWS64 S */ 61 { .id = "TER1112", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } }, 62 /* Analog Devices AD1816A - Terratec AudioSystem EWS64 S */ 63 { .id = "TER1112", .devs = { { .id = "TER1100" }, { .id = "TER1101" } } }, 64 /* Analog Devices AD1816A - Terratec Base 64 */ 65 { .id = "TER1411", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } }, 66 /* end */ 67 { .id = "" } 68 }; 69 70 MODULE_DEVICE_TABLE(pnp_card, snd_ad1816a_pnpids); 71 72 73 #define DRIVER_NAME "snd-card-ad1816a" 74 75 76 static int snd_card_ad1816a_pnp(int dev, struct pnp_card_link *card, 77 const struct pnp_card_device_id *id) 78 { 79 struct pnp_dev *pdev; 80 int err; 81 82 pdev = pnp_request_card_device(card, id->devs[0].id, NULL); 83 if (pdev == NULL) 84 return -EBUSY; 85 86 err = pnp_activate_dev(pdev); 87 if (err < 0) { 88 dev_err(&pdev->dev, "AUDIO PnP configure failure\n"); 89 return -EBUSY; 90 } 91 92 port[dev] = pnp_port_start(pdev, 2); 93 fm_port[dev] = pnp_port_start(pdev, 1); 94 dma1[dev] = pnp_dma(pdev, 0); 95 dma2[dev] = pnp_dma(pdev, 1); 96 irq[dev] = pnp_irq(pdev, 0); 97 98 pdev = pnp_request_card_device(card, id->devs[1].id, NULL); 99 if (pdev == NULL) { 100 mpu_port[dev] = -1; 101 dev_warn(&pdev->dev, "MPU401 device busy, skipping.\n"); 102 return 0; 103 } 104 105 err = pnp_activate_dev(pdev); 106 if (err < 0) { 107 dev_err(&pdev->dev, "MPU401 PnP configure failure\n"); 108 mpu_port[dev] = -1; 109 } else { 110 mpu_port[dev] = pnp_port_start(pdev, 0); 111 mpu_irq[dev] = pnp_irq(pdev, 0); 112 } 113 114 return 0; 115 } 116 117 static int snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard, 118 const struct pnp_card_device_id *pid) 119 { 120 int error; 121 struct snd_card *card; 122 struct snd_ad1816a *chip; 123 struct snd_opl3 *opl3; 124 125 error = snd_devm_card_new(&pcard->card->dev, 126 index[dev], id[dev], THIS_MODULE, 127 sizeof(struct snd_ad1816a), &card); 128 if (error < 0) 129 return error; 130 chip = card->private_data; 131 132 error = snd_card_ad1816a_pnp(dev, pcard, pid); 133 if (error) 134 return error; 135 136 error = snd_ad1816a_create(card, port[dev], 137 irq[dev], 138 dma1[dev], 139 dma2[dev], 140 chip); 141 if (error) 142 return error; 143 if (clockfreq[dev] >= 5000 && clockfreq[dev] <= 100000) 144 chip->clock_freq = clockfreq[dev]; 145 146 strcpy(card->driver, "AD1816A"); 147 strcpy(card->shortname, "ADI SoundPort AD1816A"); 148 sprintf(card->longname, "%s, SS at 0x%lx, irq %d, dma %d&%d", 149 card->shortname, chip->port, irq[dev], dma1[dev], dma2[dev]); 150 151 error = snd_ad1816a_pcm(chip, 0); 152 if (error < 0) 153 return error; 154 155 error = snd_ad1816a_mixer(chip); 156 if (error < 0) 157 return error; 158 159 error = snd_ad1816a_timer(chip, 0); 160 if (error < 0) 161 return error; 162 163 if (mpu_port[dev] > 0) { 164 if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, 165 mpu_port[dev], 0, mpu_irq[dev], 166 NULL) < 0) 167 dev_err(card->dev, "no MPU-401 device at 0x%lx.\n", 168 mpu_port[dev]); 169 } 170 171 if (fm_port[dev] > 0) { 172 if (snd_opl3_create(card, 173 fm_port[dev], fm_port[dev] + 2, 174 OPL3_HW_AUTO, 0, &opl3) < 0) { 175 dev_err(card->dev, "no OPL device at 0x%lx-0x%lx.\n", 176 fm_port[dev], fm_port[dev] + 2); 177 } else { 178 error = snd_opl3_hwdep_new(opl3, 0, 1, NULL); 179 if (error < 0) 180 return error; 181 } 182 } 183 184 error = snd_card_register(card); 185 if (error < 0) 186 return error; 187 pnp_set_card_drvdata(pcard, card); 188 return 0; 189 } 190 191 static unsigned int ad1816a_devices; 192 193 static int snd_ad1816a_pnp_detect(struct pnp_card_link *card, 194 const struct pnp_card_device_id *id) 195 { 196 static int dev; 197 int res; 198 199 for ( ; dev < SNDRV_CARDS; dev++) { 200 if (!enable[dev]) 201 continue; 202 res = snd_card_ad1816a_probe(dev, card, id); 203 if (res < 0) 204 return res; 205 dev++; 206 ad1816a_devices++; 207 return 0; 208 } 209 return -ENODEV; 210 } 211 212 #ifdef CONFIG_PM 213 static int snd_ad1816a_pnp_suspend(struct pnp_card_link *pcard, 214 pm_message_t state) 215 { 216 struct snd_card *card = pnp_get_card_drvdata(pcard); 217 218 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 219 snd_ad1816a_suspend(card->private_data); 220 return 0; 221 } 222 223 static int snd_ad1816a_pnp_resume(struct pnp_card_link *pcard) 224 { 225 struct snd_card *card = pnp_get_card_drvdata(pcard); 226 227 snd_ad1816a_resume(card->private_data); 228 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 229 return 0; 230 } 231 #endif 232 233 static struct pnp_card_driver ad1816a_pnpc_driver = { 234 .flags = PNP_DRIVER_RES_DISABLE, 235 .name = "ad1816a", 236 .id_table = snd_ad1816a_pnpids, 237 .probe = snd_ad1816a_pnp_detect, 238 #ifdef CONFIG_PM 239 .suspend = snd_ad1816a_pnp_suspend, 240 .resume = snd_ad1816a_pnp_resume, 241 #endif 242 }; 243 244 static int __init alsa_card_ad1816a_init(void) 245 { 246 int err; 247 248 err = pnp_register_card_driver(&ad1816a_pnpc_driver); 249 if (err) 250 return err; 251 252 if (!ad1816a_devices) { 253 pnp_unregister_card_driver(&ad1816a_pnpc_driver); 254 #ifdef MODULE 255 pr_err("no AD1816A based soundcards found.\n"); 256 #endif /* MODULE */ 257 return -ENODEV; 258 } 259 return 0; 260 } 261 262 static void __exit alsa_card_ad1816a_exit(void) 263 { 264 pnp_unregister_card_driver(&ad1816a_pnpc_driver); 265 } 266 267 module_init(alsa_card_ad1816a_init) 268 module_exit(alsa_card_ad1816a_exit) 269