Linux Audio

Check our new training course

Loading...
v4.10.11
 
  1/*
  2 * AdLib FM card driver.
  3 */
  4
  5#include <linux/kernel.h>
  6#include <linux/module.h>
  7#include <linux/isa.h>
  8#include <sound/core.h>
  9#include <sound/initval.h>
 10#include <sound/opl3.h>
 11
 12#define CRD_NAME "AdLib FM"
 13#define DEV_NAME "adlib"
 14
 15MODULE_DESCRIPTION(CRD_NAME);
 16MODULE_AUTHOR("Rene Herman");
 17MODULE_LICENSE("GPL");
 18
 19static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
 20static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
 21static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;
 22static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
 23
 24module_param_array(index, int, NULL, 0444);
 25MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
 26module_param_array(id, charp, NULL, 0444);
 27MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
 28module_param_array(enable, bool, NULL, 0444);
 29MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
 30module_param_array(port, long, NULL, 0444);
 31MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
 32
 33static int snd_adlib_match(struct device *dev, unsigned int n)
 34{
 35	if (!enable[n])
 36		return 0;
 37
 38	if (port[n] == SNDRV_AUTO_PORT) {
 39		dev_err(dev, "please specify port\n");
 40		return 0;
 41	}
 42	return 1;
 43}
 44
 45static void snd_adlib_free(struct snd_card *card)
 46{
 47	release_and_free_resource(card->private_data);
 48}
 49
 50static int snd_adlib_probe(struct device *dev, unsigned int n)
 51{
 52	struct snd_card *card;
 53	struct snd_opl3 *opl3;
 54	int error;
 55
 56	error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
 57	if (error < 0) {
 58		dev_err(dev, "could not create card\n");
 59		return error;
 60	}
 61
 62	card->private_data = request_region(port[n], 4, CRD_NAME);
 63	if (!card->private_data) {
 64		dev_err(dev, "could not grab ports\n");
 65		error = -EBUSY;
 66		goto out;
 67	}
 68	card->private_free = snd_adlib_free;
 69
 70	strcpy(card->driver, DEV_NAME);
 71	strcpy(card->shortname, CRD_NAME);
 72	sprintf(card->longname, CRD_NAME " at %#lx", port[n]);
 73
 74	error = snd_opl3_create(card, port[n], port[n] + 2, OPL3_HW_AUTO, 1, &opl3);
 75	if (error < 0) {
 76		dev_err(dev, "could not create OPL\n");
 77		goto out;
 78	}
 79
 80	error = snd_opl3_hwdep_new(opl3, 0, 0, NULL);
 81	if (error < 0) {
 82		dev_err(dev, "could not create FM\n");
 83		goto out;
 84	}
 85
 86	error = snd_card_register(card);
 87	if (error < 0) {
 88		dev_err(dev, "could not register card\n");
 89		goto out;
 90	}
 91
 92	dev_set_drvdata(dev, card);
 93	return 0;
 94
 95out:	snd_card_free(card);
 96	return error;
 97}
 98
 99static int snd_adlib_remove(struct device *dev, unsigned int n)
100{
101	snd_card_free(dev_get_drvdata(dev));
102	return 0;
103}
104
105static struct isa_driver snd_adlib_driver = {
106	.match		= snd_adlib_match,
107	.probe		= snd_adlib_probe,
108	.remove		= snd_adlib_remove,
109
110	.driver		= {
111		.name	= DEV_NAME
112	}
113};
114
115module_isa_driver(snd_adlib_driver, SNDRV_CARDS);
v5.4
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * AdLib FM card driver.
  4 */
  5
  6#include <linux/kernel.h>
  7#include <linux/module.h>
  8#include <linux/isa.h>
  9#include <sound/core.h>
 10#include <sound/initval.h>
 11#include <sound/opl3.h>
 12
 13#define CRD_NAME "AdLib FM"
 14#define DEV_NAME "adlib"
 15
 16MODULE_DESCRIPTION(CRD_NAME);
 17MODULE_AUTHOR("Rene Herman");
 18MODULE_LICENSE("GPL");
 19
 20static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
 21static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
 22static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;
 23static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
 24
 25module_param_array(index, int, NULL, 0444);
 26MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
 27module_param_array(id, charp, NULL, 0444);
 28MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
 29module_param_array(enable, bool, NULL, 0444);
 30MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
 31module_param_hw_array(port, long, ioport, NULL, 0444);
 32MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
 33
 34static int snd_adlib_match(struct device *dev, unsigned int n)
 35{
 36	if (!enable[n])
 37		return 0;
 38
 39	if (port[n] == SNDRV_AUTO_PORT) {
 40		dev_err(dev, "please specify port\n");
 41		return 0;
 42	}
 43	return 1;
 44}
 45
 46static void snd_adlib_free(struct snd_card *card)
 47{
 48	release_and_free_resource(card->private_data);
 49}
 50
 51static int snd_adlib_probe(struct device *dev, unsigned int n)
 52{
 53	struct snd_card *card;
 54	struct snd_opl3 *opl3;
 55	int error;
 56
 57	error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
 58	if (error < 0) {
 59		dev_err(dev, "could not create card\n");
 60		return error;
 61	}
 62
 63	card->private_data = request_region(port[n], 4, CRD_NAME);
 64	if (!card->private_data) {
 65		dev_err(dev, "could not grab ports\n");
 66		error = -EBUSY;
 67		goto out;
 68	}
 69	card->private_free = snd_adlib_free;
 70
 71	strcpy(card->driver, DEV_NAME);
 72	strcpy(card->shortname, CRD_NAME);
 73	sprintf(card->longname, CRD_NAME " at %#lx", port[n]);
 74
 75	error = snd_opl3_create(card, port[n], port[n] + 2, OPL3_HW_AUTO, 1, &opl3);
 76	if (error < 0) {
 77		dev_err(dev, "could not create OPL\n");
 78		goto out;
 79	}
 80
 81	error = snd_opl3_hwdep_new(opl3, 0, 0, NULL);
 82	if (error < 0) {
 83		dev_err(dev, "could not create FM\n");
 84		goto out;
 85	}
 86
 87	error = snd_card_register(card);
 88	if (error < 0) {
 89		dev_err(dev, "could not register card\n");
 90		goto out;
 91	}
 92
 93	dev_set_drvdata(dev, card);
 94	return 0;
 95
 96out:	snd_card_free(card);
 97	return error;
 98}
 99
100static int snd_adlib_remove(struct device *dev, unsigned int n)
101{
102	snd_card_free(dev_get_drvdata(dev));
103	return 0;
104}
105
106static struct isa_driver snd_adlib_driver = {
107	.match		= snd_adlib_match,
108	.probe		= snd_adlib_probe,
109	.remove		= snd_adlib_remove,
110
111	.driver		= {
112		.name	= DEV_NAME
113	}
114};
115
116module_isa_driver(snd_adlib_driver, SNDRV_CARDS);