18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Generic driver for AD1848/AD1847/CS4248 chips (0.1 Alpha) 48c2ecf20Sopenharmony_ci * Copyright (c) by Tugrul Galatali <galatalt@stuy.edu>, 58c2ecf20Sopenharmony_ci * Jaroslav Kysela <perex@perex.cz> 68c2ecf20Sopenharmony_ci * Based on card-4232.c by Jaroslav Kysela <perex@perex.cz> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/init.h> 108c2ecf20Sopenharmony_ci#include <linux/err.h> 118c2ecf20Sopenharmony_ci#include <linux/isa.h> 128c2ecf20Sopenharmony_ci#include <linux/time.h> 138c2ecf20Sopenharmony_ci#include <linux/wait.h> 148c2ecf20Sopenharmony_ci#include <linux/module.h> 158c2ecf20Sopenharmony_ci#include <sound/core.h> 168c2ecf20Sopenharmony_ci#include <sound/wss.h> 178c2ecf20Sopenharmony_ci#include <sound/initval.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define CRD_NAME "Generic AD1848/AD1847/CS4248" 208c2ecf20Sopenharmony_ci#define DEV_NAME "ad1848" 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ciMODULE_DESCRIPTION(CRD_NAME); 238c2ecf20Sopenharmony_ciMODULE_AUTHOR("Tugrul Galatali <galatalt@stuy.edu>, Jaroslav Kysela <perex@perex.cz>"); 248c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 258c2ecf20Sopenharmony_ciMODULE_SUPPORTED_DEVICE("{{Analog Devices,AD1848}," 268c2ecf20Sopenharmony_ci "{Analog Devices,AD1847}," 278c2ecf20Sopenharmony_ci "{Crystal Semiconductors,CS4248}}"); 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistatic int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 308c2ecf20Sopenharmony_cistatic char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 318c2ecf20Sopenharmony_cistatic bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ 328c2ecf20Sopenharmony_cistatic long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ 338c2ecf20Sopenharmony_cistatic int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */ 348c2ecf20Sopenharmony_cistatic int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */ 358c2ecf20Sopenharmony_cistatic bool thinkpad[SNDRV_CARDS]; /* Thinkpad special case */ 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cimodule_param_array(index, int, NULL, 0444); 388c2ecf20Sopenharmony_ciMODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard."); 398c2ecf20Sopenharmony_cimodule_param_array(id, charp, NULL, 0444); 408c2ecf20Sopenharmony_ciMODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard."); 418c2ecf20Sopenharmony_cimodule_param_array(enable, bool, NULL, 0444); 428c2ecf20Sopenharmony_ciMODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard."); 438c2ecf20Sopenharmony_cimodule_param_hw_array(port, long, ioport, NULL, 0444); 448c2ecf20Sopenharmony_ciMODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver."); 458c2ecf20Sopenharmony_cimodule_param_hw_array(irq, int, irq, NULL, 0444); 468c2ecf20Sopenharmony_ciMODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver."); 478c2ecf20Sopenharmony_cimodule_param_hw_array(dma1, int, dma, NULL, 0444); 488c2ecf20Sopenharmony_ciMODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver."); 498c2ecf20Sopenharmony_cimodule_param_array(thinkpad, bool, NULL, 0444); 508c2ecf20Sopenharmony_ciMODULE_PARM_DESC(thinkpad, "Enable only for the onboard CS4248 of IBM Thinkpad 360/750/755 series."); 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic int snd_ad1848_match(struct device *dev, unsigned int n) 538c2ecf20Sopenharmony_ci{ 548c2ecf20Sopenharmony_ci if (!enable[n]) 558c2ecf20Sopenharmony_ci return 0; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci if (port[n] == SNDRV_AUTO_PORT) { 588c2ecf20Sopenharmony_ci dev_err(dev, "please specify port\n"); 598c2ecf20Sopenharmony_ci return 0; 608c2ecf20Sopenharmony_ci } 618c2ecf20Sopenharmony_ci if (irq[n] == SNDRV_AUTO_IRQ) { 628c2ecf20Sopenharmony_ci dev_err(dev, "please specify irq\n"); 638c2ecf20Sopenharmony_ci return 0; 648c2ecf20Sopenharmony_ci } 658c2ecf20Sopenharmony_ci if (dma1[n] == SNDRV_AUTO_DMA) { 668c2ecf20Sopenharmony_ci dev_err(dev, "please specify dma1\n"); 678c2ecf20Sopenharmony_ci return 0; 688c2ecf20Sopenharmony_ci } 698c2ecf20Sopenharmony_ci return 1; 708c2ecf20Sopenharmony_ci} 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cistatic int snd_ad1848_probe(struct device *dev, unsigned int n) 738c2ecf20Sopenharmony_ci{ 748c2ecf20Sopenharmony_ci struct snd_card *card; 758c2ecf20Sopenharmony_ci struct snd_wss *chip; 768c2ecf20Sopenharmony_ci int error; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card); 798c2ecf20Sopenharmony_ci if (error < 0) 808c2ecf20Sopenharmony_ci return error; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci error = snd_wss_create(card, port[n], -1, irq[n], dma1[n], -1, 838c2ecf20Sopenharmony_ci thinkpad[n] ? WSS_HW_THINKPAD : WSS_HW_DETECT, 848c2ecf20Sopenharmony_ci 0, &chip); 858c2ecf20Sopenharmony_ci if (error < 0) 868c2ecf20Sopenharmony_ci goto out; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci card->private_data = chip; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci error = snd_wss_pcm(chip, 0); 918c2ecf20Sopenharmony_ci if (error < 0) 928c2ecf20Sopenharmony_ci goto out; 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci error = snd_wss_mixer(chip); 958c2ecf20Sopenharmony_ci if (error < 0) 968c2ecf20Sopenharmony_ci goto out; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci strlcpy(card->driver, "AD1848", sizeof(card->driver)); 998c2ecf20Sopenharmony_ci strlcpy(card->shortname, chip->pcm->name, sizeof(card->shortname)); 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci if (!thinkpad[n]) 1028c2ecf20Sopenharmony_ci snprintf(card->longname, sizeof(card->longname), 1038c2ecf20Sopenharmony_ci "%s at 0x%lx, irq %d, dma %d", 1048c2ecf20Sopenharmony_ci chip->pcm->name, chip->port, irq[n], dma1[n]); 1058c2ecf20Sopenharmony_ci else 1068c2ecf20Sopenharmony_ci snprintf(card->longname, sizeof(card->longname), 1078c2ecf20Sopenharmony_ci "%s at 0x%lx, irq %d, dma %d [Thinkpad]", 1088c2ecf20Sopenharmony_ci chip->pcm->name, chip->port, irq[n], dma1[n]); 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci error = snd_card_register(card); 1118c2ecf20Sopenharmony_ci if (error < 0) 1128c2ecf20Sopenharmony_ci goto out; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci dev_set_drvdata(dev, card); 1158c2ecf20Sopenharmony_ci return 0; 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ciout: snd_card_free(card); 1188c2ecf20Sopenharmony_ci return error; 1198c2ecf20Sopenharmony_ci} 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_cistatic int snd_ad1848_remove(struct device *dev, unsigned int n) 1228c2ecf20Sopenharmony_ci{ 1238c2ecf20Sopenharmony_ci snd_card_free(dev_get_drvdata(dev)); 1248c2ecf20Sopenharmony_ci return 0; 1258c2ecf20Sopenharmony_ci} 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci#ifdef CONFIG_PM 1288c2ecf20Sopenharmony_cistatic int snd_ad1848_suspend(struct device *dev, unsigned int n, pm_message_t state) 1298c2ecf20Sopenharmony_ci{ 1308c2ecf20Sopenharmony_ci struct snd_card *card = dev_get_drvdata(dev); 1318c2ecf20Sopenharmony_ci struct snd_wss *chip = card->private_data; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 1348c2ecf20Sopenharmony_ci chip->suspend(chip); 1358c2ecf20Sopenharmony_ci return 0; 1368c2ecf20Sopenharmony_ci} 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_cistatic int snd_ad1848_resume(struct device *dev, unsigned int n) 1398c2ecf20Sopenharmony_ci{ 1408c2ecf20Sopenharmony_ci struct snd_card *card = dev_get_drvdata(dev); 1418c2ecf20Sopenharmony_ci struct snd_wss *chip = card->private_data; 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci chip->resume(chip); 1448c2ecf20Sopenharmony_ci snd_power_change_state(card, SNDRV_CTL_POWER_D0); 1458c2ecf20Sopenharmony_ci return 0; 1468c2ecf20Sopenharmony_ci} 1478c2ecf20Sopenharmony_ci#endif 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_cistatic struct isa_driver snd_ad1848_driver = { 1508c2ecf20Sopenharmony_ci .match = snd_ad1848_match, 1518c2ecf20Sopenharmony_ci .probe = snd_ad1848_probe, 1528c2ecf20Sopenharmony_ci .remove = snd_ad1848_remove, 1538c2ecf20Sopenharmony_ci#ifdef CONFIG_PM 1548c2ecf20Sopenharmony_ci .suspend = snd_ad1848_suspend, 1558c2ecf20Sopenharmony_ci .resume = snd_ad1848_resume, 1568c2ecf20Sopenharmony_ci#endif 1578c2ecf20Sopenharmony_ci .driver = { 1588c2ecf20Sopenharmony_ci .name = DEV_NAME 1598c2ecf20Sopenharmony_ci } 1608c2ecf20Sopenharmony_ci}; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_cimodule_isa_driver(snd_ad1848_driver, SNDRV_CARDS); 163