unsigned long inIRQ;
unsigned long iobase;
- struct resource *res_iomem;
- struct resource *res_ioport;
- struct resource *res_iomem2;
-
- struct snd_dma_device dma_dev;
-
struct snd_dma_buffer dma_dsp;
struct snd_dma_buffer dma_play;
struct snd_dma_buffer dma_rec;
MODULE_DESCRIPTION("korg1212");
MODULE_LICENSE("GPL");
-MODULE_CLASSES("{sound}");
-MODULE_DEVICES("{{KORG,korg1212}}");
+MODULE_SUPPORTED_DEVICE("{{KORG,korg1212}}");
static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
module_param_array(index, int, boot_devs, 0444);
MODULE_PARM_DESC(index, "Index value for Korg 1212 soundcard.");
-MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
module_param_array(id, charp, boot_devs, 0444);
MODULE_PARM_DESC(id, "ID string for Korg 1212 soundcard.");
-MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
module_param_array(enable, bool, boot_devs, 0444);
MODULE_PARM_DESC(enable, "Enable Korg 1212 soundcard.");
-MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
MODULE_AUTHOR("Haroldo Gamal <gamal@alternex.com.br>");
static struct pci_device_id snd_korg1212_ids[] = {
/* timer callback for checking the ack of stop request */
static void snd_korg1212_timer_func(unsigned long data)
{
- korg1212_t *korg1212 = snd_magic_cast(korg1212_t, (void*)data, return);
+ korg1212_t *korg1212 = (korg1212_t *) data;
spin_lock(&korg1212->lock);
if (readl(&korg1212->sharedBufferPtr->cardCommand) == 0) {
static irqreturn_t snd_korg1212_interrupt(int irq, void *dev_id, struct pt_regs *regs)
{
u32 doorbellValue;
- korg1212_t *korg1212 = snd_magic_cast(korg1212_t, dev_id, return IRQ_NONE);
+ korg1212_t *korg1212 = dev_id;
if(irq != korg1212->irq)
return IRQ_NONE;
static int snd_korg1212_playback_open(snd_pcm_substream_t *substream)
{
unsigned long flags;
- korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
+ korg1212_t *korg1212 = snd_pcm_substream_chip(substream);
snd_pcm_runtime_t *runtime = substream->runtime;
#if K1212_DEBUG_LEVEL > 0
snd_korg1212_OpenCard(korg1212);
runtime->hw = snd_korg1212_playback_info;
- runtime->dma_area = (char *) korg1212->playDataBufsPtr;
- runtime->dma_bytes = K1212_BUF_SIZE;
+ snd_pcm_set_runtime_buffer(substream, &korg1212->dma_play);
spin_lock_irqsave(&korg1212->lock, flags);
static int snd_korg1212_capture_open(snd_pcm_substream_t *substream)
{
unsigned long flags;
- korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
+ korg1212_t *korg1212 = snd_pcm_substream_chip(substream);
snd_pcm_runtime_t *runtime = substream->runtime;
#if K1212_DEBUG_LEVEL > 0
snd_korg1212_OpenCard(korg1212);
runtime->hw = snd_korg1212_capture_info;
- runtime->dma_area = (char *) korg1212->recordDataBufsPtr;
- runtime->dma_bytes = K1212_BUF_SIZE;
+ snd_pcm_set_runtime_buffer(substream, &korg1212->dma_rec);
spin_lock_irqsave(&korg1212->lock, flags);
static int snd_korg1212_playback_close(snd_pcm_substream_t *substream)
{
unsigned long flags;
- korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
+ korg1212_t *korg1212 = snd_pcm_substream_chip(substream);
#if K1212_DEBUG_LEVEL > 0
K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_close [%s]\n", stateName[korg1212->cardState]);
static int snd_korg1212_capture_close(snd_pcm_substream_t *substream)
{
unsigned long flags;
- korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
+ korg1212_t *korg1212 = snd_pcm_substream_chip(substream);
#if K1212_DEBUG_LEVEL > 0
K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_close [%s]\n", stateName[korg1212->cardState]);
snd_pcm_hw_params_t *params)
{
unsigned long flags;
- korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
+ korg1212_t *korg1212 = snd_pcm_substream_chip(substream);
int err;
#if K1212_DEBUG_LEVEL > 0
static int snd_korg1212_prepare(snd_pcm_substream_t *substream)
{
- korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
+ korg1212_t *korg1212 = snd_pcm_substream_chip(substream);
int rc;
#if K1212_DEBUG_LEVEL > 0
K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare [%s]\n", stateName[korg1212->cardState]);
#endif
- spin_lock(&korg1212->lock);
+ spin_lock_irq(&korg1212->lock);
/* FIXME: we should wait for ack! */
if (korg1212->stop_pending_cnt > 0) {
#if K1212_DEBUG_LEVEL > 0
K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare - Stop is pending... [%s]\n", stateName[korg1212->cardState]);
#endif
- spin_unlock(&korg1212->lock);
+ spin_unlock_irq(&korg1212->lock);
return -EAGAIN;
/*
writel(0, &korg1212->sharedBufferPtr->cardCommand);
korg1212->currentBuffer = 0;
- spin_unlock(&korg1212->lock);
+ spin_unlock_irq(&korg1212->lock);
return rc ? -EINVAL : 0;
}
static int snd_korg1212_trigger(snd_pcm_substream_t *substream,
int cmd)
{
- korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
+ korg1212_t *korg1212 = snd_pcm_substream_chip(substream);
int rc;
#if K1212_DEBUG_LEVEL > 0
static snd_pcm_uframes_t snd_korg1212_playback_pointer(snd_pcm_substream_t *substream)
{
- korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
+ korg1212_t *korg1212 = snd_pcm_substream_chip(substream);
snd_pcm_uframes_t pos;
pos = korg1212->currentBuffer * kPlayBufferFrames;
static snd_pcm_uframes_t snd_korg1212_capture_pointer(snd_pcm_substream_t *substream)
{
- korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
+ korg1212_t *korg1212 = snd_pcm_substream_chip(substream);
snd_pcm_uframes_t pos;
pos = korg1212->currentBuffer * kPlayBufferFrames;
void __user *src,
snd_pcm_uframes_t count)
{
- korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
+ korg1212_t *korg1212 = snd_pcm_substream_chip(substream);
#if K1212_DEBUG_LEVEL > 2
K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_copy [%s] %ld %ld\n", stateName[korg1212->cardState], pos, count);
snd_pcm_uframes_t pos,
snd_pcm_uframes_t count)
{
- korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
+ korg1212_t *korg1212 = snd_pcm_substream_chip(substream);
#if K1212_DEBUG_LEVEL > 0
K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_silence [%s]\n", stateName[korg1212->cardState]);
void __user *dst,
snd_pcm_uframes_t count)
{
- korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
+ korg1212_t *korg1212 = snd_pcm_substream_chip(substream);
#if K1212_DEBUG_LEVEL > 2
K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_copy [%s] %ld %ld\n", stateName[korg1212->cardState], pos, count);
static int snd_korg1212_control_phase_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u)
{
- korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol);
- unsigned long flags;
+ korg1212_t *korg1212 = snd_kcontrol_chip(kcontrol);
int i = kcontrol->private_value;
- spin_lock_irqsave(&korg1212->lock, flags);
+ spin_lock_irq(&korg1212->lock);
u->value.integer.value[0] = korg1212->volumePhase[i];
if (i >= 8)
u->value.integer.value[1] = korg1212->volumePhase[i+1];
- spin_unlock_irqrestore(&korg1212->lock, flags);
+ spin_unlock_irq(&korg1212->lock);
return 0;
}
static int snd_korg1212_control_phase_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u)
{
- korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol);
- unsigned long flags;
+ korg1212_t *korg1212 = snd_kcontrol_chip(kcontrol);
int change = 0;
int i, val;
- spin_lock_irqsave(&korg1212->lock, flags);
+ spin_lock_irq(&korg1212->lock);
i = kcontrol->private_value;
}
}
- spin_unlock_irqrestore(&korg1212->lock, flags);
+ spin_unlock_irq(&korg1212->lock);
return change;
}
static int snd_korg1212_control_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u)
{
- korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol);
- unsigned long flags;
+ korg1212_t *korg1212 = snd_kcontrol_chip(kcontrol);
int i;
- spin_lock_irqsave(&korg1212->lock, flags);
+ spin_lock_irq(&korg1212->lock);
i = kcontrol->private_value;
u->value.integer.value[0] = abs(korg1212->sharedBufferPtr->volumeData[i]);
if (i >= 8)
u->value.integer.value[1] = abs(korg1212->sharedBufferPtr->volumeData[i+1]);
- spin_unlock_irqrestore(&korg1212->lock, flags);
+ spin_unlock_irq(&korg1212->lock);
return 0;
}
static int snd_korg1212_control_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u)
{
- korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol);
- unsigned long flags;
+ korg1212_t *korg1212 = snd_kcontrol_chip(kcontrol);
int change = 0;
int i;
int val;
- spin_lock_irqsave(&korg1212->lock, flags);
+ spin_lock_irq(&korg1212->lock);
i = kcontrol->private_value;
}
}
- spin_unlock_irqrestore(&korg1212->lock, flags);
+ spin_unlock_irq(&korg1212->lock);
return change;
}
static int snd_korg1212_control_route_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u)
{
- korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol);
- unsigned long flags;
+ korg1212_t *korg1212 = snd_kcontrol_chip(kcontrol);
int i;
- spin_lock_irqsave(&korg1212->lock, flags);
+ spin_lock_irq(&korg1212->lock);
i = kcontrol->private_value;
u->value.enumerated.item[0] = korg1212->sharedBufferPtr->routeData[i];
if (i >= 8)
u->value.enumerated.item[1] = korg1212->sharedBufferPtr->routeData[i+1];
- spin_unlock_irqrestore(&korg1212->lock, flags);
+ spin_unlock_irq(&korg1212->lock);
return 0;
}
static int snd_korg1212_control_route_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u)
{
- korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol);
- unsigned long flags;
+ korg1212_t *korg1212 = snd_kcontrol_chip(kcontrol);
int change = 0, i;
- spin_lock_irqsave(&korg1212->lock, flags);
+ spin_lock_irq(&korg1212->lock);
i = kcontrol->private_value;
}
}
- spin_unlock_irqrestore(&korg1212->lock, flags);
+ spin_unlock_irq(&korg1212->lock);
return change;
}
static int snd_korg1212_control_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u)
{
- korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol);
- unsigned long flags;
+ korg1212_t *korg1212 = snd_kcontrol_chip(kcontrol);
- spin_lock_irqsave(&korg1212->lock, flags);
+ spin_lock_irq(&korg1212->lock);
u->value.integer.value[0] = korg1212->leftADCInSens;
u->value.integer.value[1] = korg1212->rightADCInSens;
- spin_unlock_irqrestore(&korg1212->lock, flags);
+ spin_unlock_irq(&korg1212->lock);
return 0;
}
static int snd_korg1212_control_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u)
{
- korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol);
- unsigned long flags;
+ korg1212_t *korg1212 = snd_kcontrol_chip(kcontrol);
int change = 0;
- spin_lock_irqsave(&korg1212->lock, flags);
+ spin_lock_irq(&korg1212->lock);
if (u->value.integer.value[0] != korg1212->leftADCInSens) {
korg1212->leftADCInSens = u->value.integer.value[0];
change = 1;
}
- spin_unlock_irqrestore(&korg1212->lock, flags);
+ spin_unlock_irq(&korg1212->lock);
if (change)
snd_korg1212_WriteADCSensitivity(korg1212);
static int snd_korg1212_control_sync_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
{
- korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol);
- unsigned long flags;
+ korg1212_t *korg1212 = snd_kcontrol_chip(kcontrol);
- spin_lock_irqsave(&korg1212->lock, flags);
+ spin_lock_irq(&korg1212->lock);
ucontrol->value.enumerated.item[0] = korg1212->clkSource;
- spin_unlock_irqrestore(&korg1212->lock, flags);
+ spin_unlock_irq(&korg1212->lock);
return 0;
}
static int snd_korg1212_control_sync_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
{
- korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol);
- unsigned long flags;
+ korg1212_t *korg1212 = snd_kcontrol_chip(kcontrol);
unsigned int val;
int change;
val = ucontrol->value.enumerated.item[0] % 3;
- spin_lock_irqsave(&korg1212->lock, flags);
+ spin_lock_irq(&korg1212->lock);
change = val != korg1212->clkSource;
snd_korg1212_SetClockSource(korg1212, val);
- spin_unlock_irqrestore(&korg1212->lock, flags);
+ spin_unlock_irq(&korg1212->lock);
return change;
}
}
};
-#define K1212_CONTROL_ELEMENTS (sizeof(snd_korg1212_controls) / sizeof(snd_korg1212_controls[0]))
-
/*
* proc interface
*/
korg1212->iobase = 0;
}
- if (korg1212->res_iomem != NULL) {
- release_resource(korg1212->res_iomem);
- kfree_nocheck(korg1212->res_iomem);
- korg1212->res_iomem = NULL;
- }
-
- if (korg1212->res_ioport != NULL) {
- release_resource(korg1212->res_ioport);
- kfree_nocheck(korg1212->res_ioport);
- korg1212->res_ioport = NULL;
- }
-
- if (korg1212->res_iomem2 != NULL) {
- release_resource(korg1212->res_iomem2);
- kfree_nocheck(korg1212->res_iomem2);
- korg1212->res_iomem2 = NULL;
- }
+ pci_release_regions(korg1212->pci);
// ----------------------------------------------------
// free up memory resources used for the DSP download.
// ----------------------------------------------------
if (korg1212->dma_dsp.area) {
- snd_dma_free_pages(&korg1212->dma_dev, &korg1212->dma_dsp);
+ snd_dma_free_pages(&korg1212->dma_dsp);
korg1212->dma_dsp.area = NULL;
}
// free up memory resources used for the Play/Rec Buffers
// ------------------------------------------------------
if (korg1212->dma_play.area) {
- snd_dma_free_pages(&korg1212->dma_dev, &korg1212->dma_play);
+ snd_dma_free_pages(&korg1212->dma_play);
korg1212->dma_play.area = NULL;
}
if (korg1212->dma_rec.area) {
- snd_dma_free_pages(&korg1212->dma_dev, &korg1212->dma_rec);
+ snd_dma_free_pages(&korg1212->dma_rec);
korg1212->dma_rec.area = NULL;
}
// free up memory resources used for the Shared Buffers
// ----------------------------------------------------
if (korg1212->dma_shared.area) {
- snd_dma_free_pages(&korg1212->dma_dev, &korg1212->dma_shared);
+ snd_dma_free_pages(&korg1212->dma_shared);
korg1212->dma_shared.area = NULL;
}
- snd_magic_kfree(korg1212);
+ kfree(korg1212);
return 0;
}
static int snd_korg1212_dev_free(snd_device_t *device)
{
- korg1212_t *korg1212 = snd_magic_cast(korg1212_t, device->device_data, return -ENXIO);
+ korg1212_t *korg1212 = device->device_data;
#if K1212_DEBUG_LEVEL > 0
K1212_DEBUG_PRINTK("K1212_DEBUG: Freeing device\n");
#endif
if ((err = pci_enable_device(pci)) < 0)
return err;
- korg1212 = snd_magic_kcalloc(korg1212_t, 0, GFP_KERNEL);
+ korg1212 = kcalloc(1, sizeof(*korg1212), GFP_KERNEL);
if (korg1212 == NULL)
return -ENOMEM;
for (i=0; i<kAudioChannels; i++)
korg1212->volumePhase[i] = 0;
+ if ((err = pci_request_regions(pci, "korg1212")) < 0) {
+ kfree(korg1212);
+ return err;
+ }
+
korg1212->iomem = pci_resource_start(korg1212->pci, 0);
korg1212->ioport = pci_resource_start(korg1212->pci, 1);
korg1212->iomem2 = pci_resource_start(korg1212->pci, 2);
stateName[korg1212->cardState]);
#endif
- korg1212->res_iomem = request_mem_region(korg1212->iomem, iomem_size, "korg1212");
- if (korg1212->res_iomem == NULL) {
- snd_printk(KERN_ERR "unable to grab region 0x%lx-0x%lx\n",
- korg1212->iomem, korg1212->iomem + iomem_size - 1);
- return -EBUSY;
- }
-
- korg1212->res_ioport = request_region(korg1212->ioport, ioport_size, "korg1212");
- if (korg1212->res_ioport == NULL) {
- snd_printk(KERN_ERR "unable to grab region 0x%lx-0x%lx\n",
- korg1212->ioport, korg1212->ioport + ioport_size - 1);
- return -EBUSY;
- }
-
- korg1212->res_iomem2 = request_mem_region(korg1212->iomem2, iomem2_size, "korg1212");
- if (korg1212->res_iomem2 == NULL) {
- snd_printk(KERN_ERR "unable to grab region 0x%lx-0x%lx\n",
- korg1212->iomem2, korg1212->iomem2 + iomem2_size - 1);
- return -EBUSY;
- }
-
if ((korg1212->iobase = (unsigned long) ioremap(korg1212->iomem, iomem_size)) == 0) {
snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n", korg1212->iobase,
korg1212->iobase + iomem_size - 1);
stateName[korg1212->cardState]);
#endif
- memset(&korg1212->dma_dev, 0, sizeof(korg1212->dma_dev));
- korg1212->dma_dev.type = SNDRV_DMA_TYPE_DEV;
- korg1212->dma_dev.dev = snd_dma_pci_data(korg1212->pci);
-
- if (snd_dma_alloc_pages(&korg1212->dma_dev, sizeof(KorgSharedBuffer), &korg1212->dma_shared) < 0) {
+ if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
+ sizeof(KorgSharedBuffer), &korg1212->dma_shared) < 0) {
snd_printk(KERN_ERR "can not allocate shared buffer memory (%Zd bytes)\n", sizeof(KorgSharedBuffer));
return -ENOMEM;
}
korg1212->DataBufsSize = sizeof(KorgAudioBuffer) * kNumBuffers;
- if (snd_dma_alloc_pages(&korg1212->dma_dev, korg1212->DataBufsSize, &korg1212->dma_play) < 0) {
+ if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
+ korg1212->DataBufsSize, &korg1212->dma_play) < 0) {
snd_printk(KERN_ERR "can not allocate play data buffer memory (%d bytes)\n", korg1212->DataBufsSize);
return -ENOMEM;
}
korg1212->playDataBufsPtr, korg1212->PlayDataPhy, korg1212->DataBufsSize);
#endif
- if (snd_dma_alloc_pages(&korg1212->dma_dev, korg1212->DataBufsSize, &korg1212->dma_rec) < 0) {
+ if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
+ korg1212->DataBufsSize, &korg1212->dma_rec) < 0) {
snd_printk(KERN_ERR "can not allocate record data buffer memory (%d bytes)\n", korg1212->DataBufsSize);
return -ENOMEM;
}
korg1212->AdatTimeCodePhy = korg1212->sharedBufferPhy +
offsetof(KorgSharedBuffer, AdatTimeCode);
- if (snd_dma_alloc_pages(&korg1212->dma_dev, korg1212->dspCodeSize, &korg1212->dma_dsp) < 0) {
+ if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
+ korg1212->dspCodeSize, &korg1212->dma_dsp) < 0) {
snd_printk(KERN_ERR "can not allocate dsp code memory (%d bytes)\n", korg1212->dspCodeSize);
return -ENOMEM;
}
"VolumeTablePhy = %08x L[%08x]\n"
"RoutingTablePhy = %08x L[%08x]\n"
"AdatTimeCodePhy = %08x L[%08x]\n",
- korg1212->dma_dsp.addr, UpperWordSwap(korg1212->dma_dsp.addr),
+ (int)korg1212->dma_dsp.addr, UpperWordSwap(korg1212->dma_dsp.addr),
korg1212->PlayDataPhy, LowerWordSwap(korg1212->PlayDataPhy),
korg1212->RecDataPhy, LowerWordSwap(korg1212->RecDataPhy),
korg1212->VolumeTablePhy, LowerWordSwap(korg1212->VolumeTablePhy),
//snd_pcm_lib_preallocate_pages_for_all(korg1212->pcm,
// K1212_MAX_BUF_SIZE, K1212_MAX_BUF_SIZE, GFP_KERNEL);
- for (i = 0; i < K1212_CONTROL_ELEMENTS; i++) {
+ for (i = 0; i < ARRAY_SIZE(snd_korg1212_controls); i++) {
err = snd_ctl_add(korg1212->card, snd_ctl_new1(&snd_korg1212_controls[i], korg1212));
if (err < 0)
return err;