2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Functions for accessing OPL4 devices
|
|
|
|
* Copyright (c) 2003 by Clemens Ladisch <clemens@ladisch.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opl4_local.h"
|
|
|
|
#include <sound/initval.h>
|
|
|
|
#include <linux/ioport.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/init.h>
|
2011-07-16 00:38:28 +08:00
|
|
|
#include <linux/module.h>
|
2015-01-28 23:49:33 +08:00
|
|
|
#include <linux/io.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
|
|
|
|
MODULE_DESCRIPTION("OPL4 driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2017-07-06 04:02:27 +08:00
|
|
|
static inline void snd_opl4_wait(struct snd_opl4 *opl4)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int timeout = 10;
|
|
|
|
while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:13:47 +08:00
|
|
|
void snd_opl4_write(struct snd_opl4 *opl4, u8 reg, u8 value)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
snd_opl4_wait(opl4);
|
|
|
|
outb(reg, opl4->pcm_port);
|
|
|
|
|
|
|
|
snd_opl4_wait(opl4);
|
|
|
|
outb(value, opl4->pcm_port + 1);
|
|
|
|
}
|
|
|
|
|
2006-04-28 21:13:39 +08:00
|
|
|
EXPORT_SYMBOL(snd_opl4_write);
|
|
|
|
|
2005-11-17 21:13:47 +08:00
|
|
|
u8 snd_opl4_read(struct snd_opl4 *opl4, u8 reg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
snd_opl4_wait(opl4);
|
|
|
|
outb(reg, opl4->pcm_port);
|
|
|
|
|
|
|
|
snd_opl4_wait(opl4);
|
|
|
|
return inb(opl4->pcm_port + 1);
|
|
|
|
}
|
|
|
|
|
2006-04-28 21:13:39 +08:00
|
|
|
EXPORT_SYMBOL(snd_opl4_read);
|
|
|
|
|
2005-11-17 21:13:47 +08:00
|
|
|
void snd_opl4_read_memory(struct snd_opl4 *opl4, char *buf, int offset, int size)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
u8 memcfg;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&opl4->reg_lock, flags);
|
|
|
|
|
|
|
|
memcfg = snd_opl4_read(opl4, OPL4_REG_MEMORY_CONFIGURATION);
|
|
|
|
snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, memcfg | OPL4_MODE_BIT);
|
|
|
|
|
|
|
|
snd_opl4_write(opl4, OPL4_REG_MEMORY_ADDRESS_HIGH, offset >> 16);
|
|
|
|
snd_opl4_write(opl4, OPL4_REG_MEMORY_ADDRESS_MID, offset >> 8);
|
|
|
|
snd_opl4_write(opl4, OPL4_REG_MEMORY_ADDRESS_LOW, offset);
|
|
|
|
|
|
|
|
snd_opl4_wait(opl4);
|
|
|
|
outb(OPL4_REG_MEMORY_DATA, opl4->pcm_port);
|
|
|
|
snd_opl4_wait(opl4);
|
|
|
|
insb(opl4->pcm_port + 1, buf, size);
|
|
|
|
|
|
|
|
snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, memcfg);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&opl4->reg_lock, flags);
|
|
|
|
}
|
|
|
|
|
2006-04-28 21:13:39 +08:00
|
|
|
EXPORT_SYMBOL(snd_opl4_read_memory);
|
|
|
|
|
2005-11-17 21:13:47 +08:00
|
|
|
void snd_opl4_write_memory(struct snd_opl4 *opl4, const char *buf, int offset, int size)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
u8 memcfg;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&opl4->reg_lock, flags);
|
|
|
|
|
|
|
|
memcfg = snd_opl4_read(opl4, OPL4_REG_MEMORY_CONFIGURATION);
|
|
|
|
snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, memcfg | OPL4_MODE_BIT);
|
|
|
|
|
|
|
|
snd_opl4_write(opl4, OPL4_REG_MEMORY_ADDRESS_HIGH, offset >> 16);
|
|
|
|
snd_opl4_write(opl4, OPL4_REG_MEMORY_ADDRESS_MID, offset >> 8);
|
|
|
|
snd_opl4_write(opl4, OPL4_REG_MEMORY_ADDRESS_LOW, offset);
|
|
|
|
|
|
|
|
snd_opl4_wait(opl4);
|
|
|
|
outb(OPL4_REG_MEMORY_DATA, opl4->pcm_port);
|
|
|
|
snd_opl4_wait(opl4);
|
|
|
|
outsb(opl4->pcm_port + 1, buf, size);
|
|
|
|
|
|
|
|
snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, memcfg);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&opl4->reg_lock, flags);
|
|
|
|
}
|
|
|
|
|
2006-04-28 21:13:39 +08:00
|
|
|
EXPORT_SYMBOL(snd_opl4_write_memory);
|
|
|
|
|
2005-11-17 21:13:47 +08:00
|
|
|
static void snd_opl4_enable_opl4(struct snd_opl4 *opl4)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
outb(OPL3_REG_MODE, opl4->fm_port + 2);
|
|
|
|
inb(opl4->fm_port);
|
|
|
|
inb(opl4->fm_port);
|
|
|
|
outb(OPL3_OPL3_ENABLE | OPL3_OPL4_ENABLE, opl4->fm_port + 3);
|
|
|
|
inb(opl4->fm_port);
|
|
|
|
inb(opl4->fm_port);
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:13:47 +08:00
|
|
|
static int snd_opl4_detect(struct snd_opl4 *opl4)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
u8 id1, id2;
|
|
|
|
|
|
|
|
snd_opl4_enable_opl4(opl4);
|
|
|
|
|
|
|
|
id1 = snd_opl4_read(opl4, OPL4_REG_MEMORY_CONFIGURATION);
|
|
|
|
snd_printdd("OPL4[02]=%02x\n", id1);
|
|
|
|
switch (id1 & OPL4_DEVICE_ID_MASK) {
|
|
|
|
case 0x20:
|
|
|
|
opl4->hardware = OPL3_HW_OPL4;
|
|
|
|
break;
|
|
|
|
case 0x40:
|
|
|
|
opl4->hardware = OPL3_HW_OPL4_ML;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
snd_opl4_write(opl4, OPL4_REG_MIX_CONTROL_FM, 0x00);
|
|
|
|
snd_opl4_write(opl4, OPL4_REG_MIX_CONTROL_PCM, 0xff);
|
|
|
|
id1 = snd_opl4_read(opl4, OPL4_REG_MIX_CONTROL_FM);
|
|
|
|
id2 = snd_opl4_read(opl4, OPL4_REG_MIX_CONTROL_PCM);
|
|
|
|
snd_printdd("OPL4 id1=%02x id2=%02x\n", id1, id2);
|
|
|
|
if (id1 != 0x00 || id2 != 0xff)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
snd_opl4_write(opl4, OPL4_REG_MIX_CONTROL_FM, 0x3f);
|
|
|
|
snd_opl4_write(opl4, OPL4_REG_MIX_CONTROL_PCM, 0x3f);
|
|
|
|
snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, 0x00);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
ALSA: seq: Allow the modular sequencer registration
Many drivers bind the sequencer stuff in off-load by another driver
module, so that it's loaded only on demand. In the current code, this
mechanism doesn't work when the driver is built-in while the sequencer
is module. We check with IS_REACHABLE() and enable only when the
sequencer is in the same level of build.
However, this is basically a overshoot. The binder code
(snd-seq-device) is an individual module from the sequencer core
(snd-seq), and we just have to make the former a built-in while
keeping the latter a module for allowing the scenario like the above.
This patch achieves that by rewriting Kconfig slightly. Now, a driver
that provides the manual sequencer device binding should select
CONFIG_SND_SEQ_DEVICE in a way as
select SND_SEQ_DEVICE if SND_SEQUENCER != n
Note that the "!=n" is needed here to avoid the influence of the
sequencer core is module while the driver is built-in.
Also, since rawmidi.o may be linked with snd_seq_device.o when
built-in, we have to shuffle the code to make the linker happy.
(the kernel linker isn't smart enough yet to handle such a case.)
That is, snd_seq_device.c is moved to sound/core from sound/core/seq,
as well as Makefile.
Last but not least, the patch replaces the code using IS_REACHABLE()
with IS_ENABLED(), since now the condition meets always when enabled.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-06-09 21:11:58 +08:00
|
|
|
#if IS_ENABLED(CONFIG_SND_SEQUENCER)
|
2005-11-17 21:13:47 +08:00
|
|
|
static void snd_opl4_seq_dev_free(struct snd_seq_device *seq_dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:13:47 +08:00
|
|
|
struct snd_opl4 *opl4 = seq_dev->private_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
opl4->seq_dev = NULL;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:13:47 +08:00
|
|
|
static int snd_opl4_create_seq_dev(struct snd_opl4 *opl4, int seq_device)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
opl4->seq_dev_num = seq_device;
|
|
|
|
if (snd_seq_device_new(opl4->card, seq_device, SNDRV_SEQ_DEV_ID_OPL4,
|
2005-11-17 21:13:47 +08:00
|
|
|
sizeof(struct snd_opl4 *), &opl4->seq_dev) >= 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
strcpy(opl4->seq_dev->name, "OPL4 Wavetable");
|
2005-11-17 21:13:47 +08:00
|
|
|
*(struct snd_opl4 **)SNDRV_SEQ_DEVICE_ARGPTR(opl4->seq_dev) = opl4;
|
2005-04-17 06:20:36 +08:00
|
|
|
opl4->seq_dev->private_data = opl4;
|
|
|
|
opl4->seq_dev->private_free = snd_opl4_seq_dev_free;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-11-17 21:13:47 +08:00
|
|
|
static void snd_opl4_free(struct snd_opl4 *opl4)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
snd_opl4_free_proc(opl4);
|
2005-10-10 17:56:31 +08:00
|
|
|
release_and_free_resource(opl4->res_fm_port);
|
|
|
|
release_and_free_resource(opl4->res_pcm_port);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(opl4);
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:13:47 +08:00
|
|
|
static int snd_opl4_dev_free(struct snd_device *device)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:13:47 +08:00
|
|
|
struct snd_opl4 *opl4 = device->device_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_opl4_free(opl4);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:13:47 +08:00
|
|
|
int snd_opl4_create(struct snd_card *card,
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long fm_port, unsigned long pcm_port,
|
|
|
|
int seq_device,
|
2005-11-17 21:13:47 +08:00
|
|
|
struct snd_opl3 **ropl3, struct snd_opl4 **ropl4)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:13:47 +08:00
|
|
|
struct snd_opl4 *opl4;
|
|
|
|
struct snd_opl3 *opl3;
|
2005-04-17 06:20:36 +08:00
|
|
|
int err;
|
2005-11-17 21:13:47 +08:00
|
|
|
static struct snd_device_ops ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.dev_free = snd_opl4_dev_free
|
|
|
|
};
|
|
|
|
|
|
|
|
if (ropl3)
|
|
|
|
*ropl3 = NULL;
|
|
|
|
if (ropl4)
|
|
|
|
*ropl4 = NULL;
|
|
|
|
|
[ALSA] Replace with kzalloc() - others
Documentation,SA11xx UDA1341 driver,Generic drivers,MPU401 UART,OPL3
OPL4,Digigram VX core,I2C cs8427,I2C lib core,I2C tea6330t,L3 drivers
AK4114 receiver,AK4117 receiver,PDAudioCF driver,PPC PMAC driver
SPARC AMD7930 driver,SPARC cs4231 driver,Synth,Common EMU synth
USB generic driver,USB USX2Y
Replace kcalloc(1,..) with kzalloc().
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2005-09-09 20:22:34 +08:00
|
|
|
opl4 = kzalloc(sizeof(*opl4), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!opl4)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
opl4->res_fm_port = request_region(fm_port, 8, "OPL4 FM");
|
|
|
|
opl4->res_pcm_port = request_region(pcm_port, 8, "OPL4 PCM/MIX");
|
|
|
|
if (!opl4->res_fm_port || !opl4->res_pcm_port) {
|
|
|
|
snd_printk(KERN_ERR "opl4: can't grab ports 0x%lx, 0x%lx\n", fm_port, pcm_port);
|
|
|
|
snd_opl4_free(opl4);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
opl4->card = card;
|
|
|
|
opl4->fm_port = fm_port;
|
|
|
|
opl4->pcm_port = pcm_port;
|
|
|
|
spin_lock_init(&opl4->reg_lock);
|
2006-01-16 23:31:42 +08:00
|
|
|
mutex_init(&opl4->access_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
err = snd_opl4_detect(opl4);
|
|
|
|
if (err < 0) {
|
|
|
|
snd_opl4_free(opl4);
|
|
|
|
snd_printd("OPL4 chip not detected at %#lx/%#lx\n", fm_port, pcm_port);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = snd_device_new(card, SNDRV_DEV_CODEC, opl4, &ops);
|
|
|
|
if (err < 0) {
|
|
|
|
snd_opl4_free(opl4);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = snd_opl3_create(card, fm_port, fm_port + 2, opl4->hardware, 1, &opl3);
|
|
|
|
if (err < 0) {
|
|
|
|
snd_device_free(card, opl4);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* opl3 initialization disabled opl4, so reenable */
|
|
|
|
snd_opl4_enable_opl4(opl4);
|
|
|
|
|
|
|
|
snd_opl4_create_mixer(opl4);
|
|
|
|
snd_opl4_create_proc(opl4);
|
|
|
|
|
ALSA: seq: Allow the modular sequencer registration
Many drivers bind the sequencer stuff in off-load by another driver
module, so that it's loaded only on demand. In the current code, this
mechanism doesn't work when the driver is built-in while the sequencer
is module. We check with IS_REACHABLE() and enable only when the
sequencer is in the same level of build.
However, this is basically a overshoot. The binder code
(snd-seq-device) is an individual module from the sequencer core
(snd-seq), and we just have to make the former a built-in while
keeping the latter a module for allowing the scenario like the above.
This patch achieves that by rewriting Kconfig slightly. Now, a driver
that provides the manual sequencer device binding should select
CONFIG_SND_SEQ_DEVICE in a way as
select SND_SEQ_DEVICE if SND_SEQUENCER != n
Note that the "!=n" is needed here to avoid the influence of the
sequencer core is module while the driver is built-in.
Also, since rawmidi.o may be linked with snd_seq_device.o when
built-in, we have to shuffle the code to make the linker happy.
(the kernel linker isn't smart enough yet to handle such a case.)
That is, snd_seq_device.c is moved to sound/core from sound/core/seq,
as well as Makefile.
Last but not least, the patch replaces the code using IS_REACHABLE()
with IS_ENABLED(), since now the condition meets always when enabled.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-06-09 21:11:58 +08:00
|
|
|
#if IS_ENABLED(CONFIG_SND_SEQUENCER)
|
2005-04-17 06:20:36 +08:00
|
|
|
opl4->seq_client = -1;
|
|
|
|
if (opl4->hardware < OPL3_HW_OPL4_ML)
|
|
|
|
snd_opl4_create_seq_dev(opl4, seq_device);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ropl3)
|
|
|
|
*ropl3 = opl3;
|
|
|
|
if (ropl4)
|
|
|
|
*ropl4 = opl4;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(snd_opl4_create);
|
|
|
|
|
|
|
|
static int __init alsa_opl4_init(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit alsa_opl4_exit(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(alsa_opl4_init)
|
|
|
|
module_exit(alsa_opl4_exit)
|