Blame view

sound/isa/adlib.c 2.94 KB
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
1
2
3
  /*
   * AdLib FM card driver.
   */
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
4
5
  #include <linux/kernel.h>
  #include <linux/module.h>
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
6
  #include <linux/isa.h>
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
7
8
9
10
11
  #include <sound/core.h>
  #include <sound/initval.h>
  #include <sound/opl3.h>
  
  #define CRD_NAME "AdLib FM"
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
12
  #define DEV_NAME "adlib"
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
13
14
15
16
17
18
19
  
  MODULE_DESCRIPTION(CRD_NAME);
  MODULE_AUTHOR("Rene Herman");
  MODULE_LICENSE("GPL");
  
  static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
a67ff6a54   Rusty Russell   ALSA: module_para...
20
  static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
21
22
23
24
25
26
27
28
29
30
  static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  
  module_param_array(index, int, NULL, 0444);
  MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
  module_param_array(id, charp, NULL, 0444);
  MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
  module_param_array(enable, bool, NULL, 0444);
  MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
  module_param_array(port, long, NULL, 0444);
  MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
31
32
33
34
35
36
  static int __devinit snd_adlib_match(struct device *dev, unsigned int n)
  {
  	if (!enable[n])
  		return 0;
  
  	if (port[n] == SNDRV_AUTO_PORT) {
0418ff0c8   Takashi Iwai   ALSA: remove dire...
37
38
  		dev_err(dev, "please specify port
  ");
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
39
40
41
42
  		return 0;
  	}
  	return 1;
  }
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
43
44
45
46
47
  
  static void snd_adlib_free(struct snd_card *card)
  {
  	release_and_free_resource(card->private_data);
  }
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
48
  static int __devinit snd_adlib_probe(struct device *dev, unsigned int n)
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
49
50
51
  {
  	struct snd_card *card;
  	struct snd_opl3 *opl3;
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
52
  	int error;
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
53

c95eadd2f   Takashi Iwai   ALSA: Convert to ...
54
55
  	error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card);
  	if (error < 0) {
0418ff0c8   Takashi Iwai   ALSA: remove dire...
56
57
  		dev_err(dev, "could not create card
  ");
c95eadd2f   Takashi Iwai   ALSA: Convert to ...
58
  		return error;
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
59
  	}
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
60
  	card->private_data = request_region(port[n], 4, CRD_NAME);
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
61
  	if (!card->private_data) {
0418ff0c8   Takashi Iwai   ALSA: remove dire...
62
63
  		dev_err(dev, "could not grab ports
  ");
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
64
  		error = -EBUSY;
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
65
  		goto out;
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
66
67
  	}
  	card->private_free = snd_adlib_free;
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
68
69
70
71
72
  	strcpy(card->driver, DEV_NAME);
  	strcpy(card->shortname, CRD_NAME);
  	sprintf(card->longname, CRD_NAME " at %#lx", port[n]);
  
  	error = snd_opl3_create(card, port[n], port[n] + 2, OPL3_HW_AUTO, 1, &opl3);
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
73
  	if (error < 0) {
0418ff0c8   Takashi Iwai   ALSA: remove dire...
74
75
  		dev_err(dev, "could not create OPL
  ");
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
76
  		goto out;
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
77
78
79
80
  	}
  
  	error = snd_opl3_hwdep_new(opl3, 0, 0, NULL);
  	if (error < 0) {
0418ff0c8   Takashi Iwai   ALSA: remove dire...
81
82
  		dev_err(dev, "could not create FM
  ");
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
83
  		goto out;
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
84
  	}
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
85
  	snd_card_set_dev(card, dev);
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
86
87
88
  
  	error = snd_card_register(card);
  	if (error < 0) {
0418ff0c8   Takashi Iwai   ALSA: remove dire...
89
90
  		dev_err(dev, "could not register card
  ");
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
91
  		goto out;
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
92
  	}
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
93
  	dev_set_drvdata(dev, card);
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
94
  	return 0;
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
95
96
  out:	snd_card_free(card);
  	return error;
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
97
  }
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
98
  static int __devexit snd_adlib_remove(struct device *dev, unsigned int n)
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
99
  {
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
100
101
  	snd_card_free(dev_get_drvdata(dev));
  	dev_set_drvdata(dev, NULL);
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
102
103
  	return 0;
  }
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
104
105
  static struct isa_driver snd_adlib_driver = {
  	.match		= snd_adlib_match,
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
106
107
108
109
  	.probe		= snd_adlib_probe,
  	.remove		= __devexit_p(snd_adlib_remove),
  
  	.driver		= {
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
110
  		.name	= DEV_NAME
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
111
112
113
114
115
  	}
  };
  
  static int __init alsa_card_adlib_init(void)
  {
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
116
  	return isa_register_driver(&snd_adlib_driver, SNDRV_CARDS);
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
117
118
119
120
  }
  
  static void __exit alsa_card_adlib_exit(void)
  {
ab7942b20   Rene Herman   [ALSA] isa_bus: a...
121
  	isa_unregister_driver(&snd_adlib_driver);
cf40a310a   Rene Herman   [ALSA] AdLib FM c...
122
123
124
125
  }
  
  module_init(alsa_card_adlib_init);
  module_exit(alsa_card_adlib_exit);