xref: /openbmc/linux/sound/isa/ad1848/ad1848.c (revision 413d6ed3)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  *  Generic driver for AD1848/AD1847/CS4248 chips (0.1 Alpha)
4  *  Copyright (c) by Tugrul Galatali <galatalt@stuy.edu>,
5  *                   Jaroslav Kysela <perex@perex.cz>
6  *  Based on card-4232.c by Jaroslav Kysela <perex@perex.cz>
7  */
8 
9 #include <linux/init.h>
10 #include <linux/err.h>
11 #include <linux/isa.h>
12 #include <linux/time.h>
13 #include <linux/wait.h>
14 #include <linux/module.h>
15 #include <sound/core.h>
16 #include <sound/wss.h>
17 #include <sound/initval.h>
18 
19 #define CRD_NAME "Generic AD1848/AD1847/CS4248"
20 #define DEV_NAME "ad1848"
21 
22 MODULE_DESCRIPTION(CRD_NAME);
23 MODULE_AUTHOR("Tugrul Galatali <galatalt@stuy.edu>, Jaroslav Kysela <perex@perex.cz>");
24 MODULE_LICENSE("GPL");
25 
26 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
27 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
28 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;	/* Enable this card */
29 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* PnP setup */
30 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;	/* 5,7,9,11,12,15 */
31 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;	/* 0,1,3,5,6,7 */
32 static bool thinkpad[SNDRV_CARDS];			/* Thinkpad special case */
33 
34 module_param_array(index, int, NULL, 0444);
35 MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
36 module_param_array(id, charp, NULL, 0444);
37 MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
38 module_param_array(enable, bool, NULL, 0444);
39 MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
40 module_param_hw_array(port, long, ioport, NULL, 0444);
41 MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
42 module_param_hw_array(irq, int, irq, NULL, 0444);
43 MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
44 module_param_hw_array(dma1, int, dma, NULL, 0444);
45 MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver.");
46 module_param_array(thinkpad, bool, NULL, 0444);
47 MODULE_PARM_DESC(thinkpad, "Enable only for the onboard CS4248 of IBM Thinkpad 360/750/755 series.");
48 
49 static int snd_ad1848_match(struct device *dev, unsigned int n)
50 {
51 	if (!enable[n])
52 		return 0;
53 
54 	if (port[n] == SNDRV_AUTO_PORT) {
55 		dev_err(dev, "please specify port\n");
56 		return 0;
57 	}
58 	if (irq[n] == SNDRV_AUTO_IRQ) {
59 		dev_err(dev, "please specify irq\n");
60 		return 0;
61 	}
62 	if (dma1[n] == SNDRV_AUTO_DMA) {
63 		dev_err(dev, "please specify dma1\n");
64 		return 0;
65 	}
66 	return 1;
67 }
68 
69 static int snd_ad1848_probe(struct device *dev, unsigned int n)
70 {
71 	struct snd_card *card;
72 	struct snd_wss *chip;
73 	int error;
74 
75 	error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
76 	if (error < 0)
77 		return error;
78 
79 	error = snd_wss_create(card, port[n], -1, irq[n], dma1[n], -1,
80 			thinkpad[n] ? WSS_HW_THINKPAD : WSS_HW_DETECT,
81 			0, &chip);
82 	if (error < 0)
83 		goto out;
84 
85 	card->private_data = chip;
86 
87 	error = snd_wss_pcm(chip, 0);
88 	if (error < 0)
89 		goto out;
90 
91 	error = snd_wss_mixer(chip);
92 	if (error < 0)
93 		goto out;
94 
95 	strscpy(card->driver, "AD1848", sizeof(card->driver));
96 	strscpy(card->shortname, chip->pcm->name, sizeof(card->shortname));
97 
98 	if (!thinkpad[n])
99 		snprintf(card->longname, sizeof(card->longname),
100 			 "%s at 0x%lx, irq %d, dma %d",
101 			 chip->pcm->name, chip->port, irq[n], dma1[n]);
102 	else
103 		snprintf(card->longname, sizeof(card->longname),
104 			 "%s at 0x%lx, irq %d, dma %d [Thinkpad]",
105 			 chip->pcm->name, chip->port, irq[n], dma1[n]);
106 
107 	error = snd_card_register(card);
108 	if (error < 0)
109 		goto out;
110 
111 	dev_set_drvdata(dev, card);
112 	return 0;
113 
114 out:	snd_card_free(card);
115 	return error;
116 }
117 
118 static void snd_ad1848_remove(struct device *dev, unsigned int n)
119 {
120 	snd_card_free(dev_get_drvdata(dev));
121 }
122 
123 #ifdef CONFIG_PM
124 static int snd_ad1848_suspend(struct device *dev, unsigned int n, pm_message_t state)
125 {
126 	struct snd_card *card = dev_get_drvdata(dev);
127 	struct snd_wss *chip = card->private_data;
128 
129 	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
130 	chip->suspend(chip);
131 	return 0;
132 }
133 
134 static int snd_ad1848_resume(struct device *dev, unsigned int n)
135 {
136 	struct snd_card *card = dev_get_drvdata(dev);
137 	struct snd_wss *chip = card->private_data;
138 
139 	chip->resume(chip);
140 	snd_power_change_state(card, SNDRV_CTL_POWER_D0);
141 	return 0;
142 }
143 #endif
144 
145 static struct isa_driver snd_ad1848_driver = {
146 	.match		= snd_ad1848_match,
147 	.probe		= snd_ad1848_probe,
148 	.remove		= snd_ad1848_remove,
149 #ifdef CONFIG_PM
150 	.suspend	= snd_ad1848_suspend,
151 	.resume		= snd_ad1848_resume,
152 #endif
153 	.driver		= {
154 		.name	= DEV_NAME
155 	}
156 };
157 
158 module_isa_driver(snd_ad1848_driver, SNDRV_CARDS);
159