2 * AdLib FM card driver.
5 #include <sound/driver.h>
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/platform_device.h>
9 #include <sound/core.h>
10 #include <sound/initval.h>
11 #include <sound/opl3.h>
13 #define CRD_NAME "AdLib FM"
14 #define DRV_NAME "snd_adlib"
16 MODULE_DESCRIPTION(CRD_NAME
);
17 MODULE_AUTHOR("Rene Herman");
18 MODULE_LICENSE("GPL");
20 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
;
21 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
;
22 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE
;
23 static long port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
25 module_param_array(index
, int, NULL
, 0444);
26 MODULE_PARM_DESC(index
, "Index value for " CRD_NAME
" soundcard.");
27 module_param_array(id
, charp
, NULL
, 0444);
28 MODULE_PARM_DESC(id
, "ID string for " CRD_NAME
" soundcard.");
29 module_param_array(enable
, bool, NULL
, 0444);
30 MODULE_PARM_DESC(enable
, "Enable " CRD_NAME
" soundcard.");
31 module_param_array(port
, long, NULL
, 0444);
32 MODULE_PARM_DESC(port
, "Port # for " CRD_NAME
" driver.");
34 static struct platform_device
*devices
[SNDRV_CARDS
];
36 static void snd_adlib_free(struct snd_card
*card
)
38 release_and_free_resource(card
->private_data
);
41 static int __devinit
snd_adlib_probe(struct platform_device
*device
)
43 struct snd_card
*card
;
44 struct snd_opl3
*opl3
;
49 if (port
[i
] == SNDRV_AUTO_PORT
) {
50 snd_printk(KERN_ERR DRV_NAME
": please specify port\n");
55 card
= snd_card_new(index
[i
], id
[i
], THIS_MODULE
, 0);
57 snd_printk(KERN_ERR DRV_NAME
": could not create card\n");
62 card
->private_data
= request_region(port
[i
], 4, CRD_NAME
);
63 if (!card
->private_data
) {
64 snd_printk(KERN_ERR DRV_NAME
": could not grab ports\n");
68 card
->private_free
= snd_adlib_free
;
70 error
= snd_opl3_create(card
, port
[i
], port
[i
] + 2, OPL3_HW_AUTO
, 1, &opl3
);
72 snd_printk(KERN_ERR DRV_NAME
": could not create OPL\n");
76 error
= snd_opl3_hwdep_new(opl3
, 0, 0, NULL
);
78 snd_printk(KERN_ERR DRV_NAME
": could not create FM\n");
82 strcpy(card
->driver
, DRV_NAME
);
83 strcpy(card
->shortname
, CRD_NAME
);
84 sprintf(card
->longname
, CRD_NAME
" at %#lx", port
[i
]);
86 snd_card_set_dev(card
, &device
->dev
);
88 error
= snd_card_register(card
);
90 snd_printk(KERN_ERR DRV_NAME
": could not register card\n");
94 platform_set_drvdata(device
, card
);
97 out1
: snd_card_free(card
);
98 out0
: error
= -EINVAL
; /* FIXME: should be the original error code */
102 static int __devexit
snd_adlib_remove(struct platform_device
*device
)
104 snd_card_free(platform_get_drvdata(device
));
105 platform_set_drvdata(device
, NULL
);
109 static struct platform_driver snd_adlib_driver
= {
110 .probe
= snd_adlib_probe
,
111 .remove
= __devexit_p(snd_adlib_remove
),
118 static int __init
alsa_card_adlib_init(void)
122 if (platform_driver_register(&snd_adlib_driver
) < 0) {
123 snd_printk(KERN_ERR DRV_NAME
": could not register driver\n");
127 for (cards
= 0, i
= 0; i
< SNDRV_CARDS
; i
++) {
128 struct platform_device
*device
;
133 device
= platform_device_register_simple(DRV_NAME
, i
, NULL
, 0);
143 printk(KERN_ERR CRD_NAME
" soundcard not found or device busy\n");
145 platform_driver_unregister(&snd_adlib_driver
);
151 static void __exit
alsa_card_adlib_exit(void)
155 for (i
= 0; i
< SNDRV_CARDS
; i
++)
156 platform_device_unregister(devices
[i
]);
157 platform_driver_unregister(&snd_adlib_driver
);
160 module_init(alsa_card_adlib_init
);
161 module_exit(alsa_card_adlib_exit
);