2019-05-27 06:55:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Driver for Tascam US-X2Y USB soundcards
|
|
|
|
*
|
|
|
|
* FPGA Loader + ALSA Startup
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003 by Karsten Wiese <annabellesgarden@yahoo.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/interrupt.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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/memalloc.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/hwdep.h>
|
|
|
|
#include "usx2y.h"
|
|
|
|
#include "usbusx2y.h"
|
|
|
|
#include "usX2Yhwdep.h"
|
|
|
|
|
2018-04-25 04:14:45 +00:00
|
|
|
static vm_fault_t snd_us428ctls_vm_fault(struct vm_fault *vmf)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long offset;
|
2021-05-17 13:15:36 +00:00
|
|
|
struct page *page;
|
2005-04-16 22:20:36 +00:00
|
|
|
void *vaddr;
|
|
|
|
|
2007-12-13 15:16:40 +00:00
|
|
|
snd_printdd("ENTER, start %lXh, pgoff %ld\n",
|
2017-02-24 22:56:41 +00:00
|
|
|
vmf->vma->vm_start,
|
2007-12-13 15:16:40 +00:00
|
|
|
vmf->pgoff);
|
2021-05-17 13:15:36 +00:00
|
|
|
|
2007-12-13 15:16:40 +00:00
|
|
|
offset = vmf->pgoff << PAGE_SHIFT;
|
2021-05-17 13:15:35 +00:00
|
|
|
vaddr = (char *)((struct usx2ydev *)vmf->vma->vm_private_data)->us428ctls_sharedmem + offset;
|
2005-04-16 22:20:36 +00:00
|
|
|
page = virt_to_page(vaddr);
|
|
|
|
get_page(page);
|
2007-12-13 15:16:40 +00:00
|
|
|
vmf->page = page;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-12-13 15:16:40 +00:00
|
|
|
snd_printdd("vaddr=%p made us428ctls_vm_fault() page %p\n",
|
|
|
|
vaddr, page);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-12-13 15:16:40 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2009-09-27 18:29:37 +00:00
|
|
|
static const struct vm_operations_struct us428ctls_vm_ops = {
|
2007-12-13 15:16:40 +00:00
|
|
|
.fault = snd_us428ctls_vm_fault,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2021-05-17 13:15:36 +00:00
|
|
|
static int snd_us428ctls_mmap(struct snd_hwdep *hw, struct file *filp, struct vm_area_struct *area)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long size = (unsigned long)(area->vm_end - area->vm_start);
|
2021-05-17 13:15:35 +00:00
|
|
|
struct usx2ydev *us428 = hw->private_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
// FIXME this hwdep interface is used twice: fpga download and mmap for controlling Lights etc. Maybe better using 2 hwdep devs?
|
|
|
|
// so as long as the device isn't fully initialised yet we return -EBUSY here.
|
2021-05-17 13:15:36 +00:00
|
|
|
if (!(us428->chip_status & USX2Y_STAT_CHIP_INIT))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EBUSY;
|
|
|
|
|
2021-05-17 13:15:36 +00:00
|
|
|
/* if userspace tries to mmap beyond end of our buffer, fail */
|
2021-05-17 13:15:38 +00:00
|
|
|
if (size > US428_SHAREDMEM_PAGES) {
|
|
|
|
snd_printd("%lu > %lu\n", size, (unsigned long)US428_SHAREDMEM_PAGES);
|
2021-05-17 13:15:36 +00:00
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
area->vm_ops = &us428ctls_vm_ops;
|
2023-01-26 19:37:49 +00:00
|
|
|
vm_flags_set(area, VM_DONTEXPAND | VM_DONTDUMP);
|
2005-04-16 22:20:36 +00:00
|
|
|
area->vm_private_data = hw->private_data;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-03 03:27:36 +00:00
|
|
|
static __poll_t snd_us428ctls_poll(struct snd_hwdep *hw, struct file *file, poll_table *wait)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2017-07-03 03:27:36 +00:00
|
|
|
__poll_t mask = 0;
|
2021-05-17 13:15:35 +00:00
|
|
|
struct usx2ydev *us428 = hw->private_data;
|
2005-11-17 14:08:26 +00:00
|
|
|
struct us428ctls_sharedmem *shm = us428->us428ctls_sharedmem;
|
2021-05-17 13:15:36 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (us428->chip_status & USX2Y_STAT_CHIP_HUP)
|
2018-02-11 22:34:03 +00:00
|
|
|
return EPOLLHUP;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
poll_wait(file, &us428->us428ctls_wait_queue_head, wait);
|
|
|
|
|
2021-05-17 13:15:37 +00:00
|
|
|
if (shm && shm->ctl_snapshot_last != shm->ctl_snapshot_red)
|
2018-02-11 22:34:03 +00:00
|
|
|
mask |= EPOLLIN;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-17 13:15:35 +00:00
|
|
|
static int snd_usx2y_hwdep_dsp_status(struct snd_hwdep *hw,
|
2005-11-17 14:08:26 +00:00
|
|
|
struct snd_hwdep_dsp_status *info)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2020-01-05 14:47:37 +00:00
|
|
|
static const char * const type_ids[USX2Y_TYPE_NUMS] = {
|
2005-04-16 22:20:36 +00:00
|
|
|
[USX2Y_TYPE_122] = "us122",
|
|
|
|
[USX2Y_TYPE_224] = "us224",
|
|
|
|
[USX2Y_TYPE_428] = "us428",
|
|
|
|
};
|
2021-05-17 13:15:35 +00:00
|
|
|
struct usx2ydev *us428 = hw->private_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
int id = -1;
|
|
|
|
|
2009-11-16 11:26:30 +00:00
|
|
|
switch (le16_to_cpu(us428->dev->descriptor.idProduct)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
case USB_ID_US122:
|
|
|
|
id = USX2Y_TYPE_122;
|
|
|
|
break;
|
|
|
|
case USB_ID_US224:
|
|
|
|
id = USX2Y_TYPE_224;
|
|
|
|
break;
|
|
|
|
case USB_ID_US428:
|
|
|
|
id = USX2Y_TYPE_428;
|
|
|
|
break;
|
|
|
|
}
|
2021-05-17 13:15:37 +00:00
|
|
|
if (id < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENODEV;
|
|
|
|
strcpy(info->id, type_ids[id]);
|
|
|
|
info->num_dsps = 2; // 0: Prepad Data, 1: FPGA Code
|
2005-11-17 14:08:26 +00:00
|
|
|
if (us428->chip_status & USX2Y_STAT_CHIP_INIT)
|
2005-04-16 22:20:36 +00:00
|
|
|
info->chip_ready = 1;
|
2019-12-18 03:42:57 +00:00
|
|
|
info->version = USX2Y_DRIVER_VERSION;
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-05-17 13:15:35 +00:00
|
|
|
static int usx2y_create_usbmidi(struct snd_card *card)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2020-01-03 08:17:07 +00:00
|
|
|
static const struct snd_usb_midi_endpoint_info quirk_data_1 = {
|
2005-11-17 14:08:26 +00:00
|
|
|
.out_ep = 0x06,
|
2005-04-16 22:20:36 +00:00
|
|
|
.in_ep = 0x06,
|
|
|
|
.out_cables = 0x001,
|
|
|
|
.in_cables = 0x001
|
|
|
|
};
|
2020-01-03 08:17:07 +00:00
|
|
|
static const struct snd_usb_audio_quirk quirk_1 = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.vendor_name = "TASCAM",
|
|
|
|
.product_name = NAME_ALLCAPS,
|
2021-05-17 13:15:36 +00:00
|
|
|
.ifnum = 0,
|
|
|
|
.type = QUIRK_MIDI_FIXED_ENDPOINT,
|
2005-04-16 22:20:36 +00:00
|
|
|
.data = &quirk_data_1
|
|
|
|
};
|
2020-01-03 08:17:07 +00:00
|
|
|
static const struct snd_usb_midi_endpoint_info quirk_data_2 = {
|
2005-11-17 14:08:26 +00:00
|
|
|
.out_ep = 0x06,
|
2005-04-16 22:20:36 +00:00
|
|
|
.in_ep = 0x06,
|
|
|
|
.out_cables = 0x003,
|
|
|
|
.in_cables = 0x003
|
|
|
|
};
|
2020-01-03 08:17:07 +00:00
|
|
|
static const struct snd_usb_audio_quirk quirk_2 = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.vendor_name = "TASCAM",
|
|
|
|
.product_name = "US428",
|
2021-05-17 13:15:36 +00:00
|
|
|
.ifnum = 0,
|
|
|
|
.type = QUIRK_MIDI_FIXED_ENDPOINT,
|
2005-04-16 22:20:36 +00:00
|
|
|
.data = &quirk_data_2
|
|
|
|
};
|
2021-05-17 13:15:35 +00:00
|
|
|
struct usb_device *dev = usx2y(card)->dev;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct usb_interface *iface = usb_ifnum_to_if(dev, 0);
|
2020-01-03 08:17:07 +00:00
|
|
|
const struct snd_usb_audio_quirk *quirk =
|
2005-11-17 14:08:26 +00:00
|
|
|
le16_to_cpu(dev->descriptor.idProduct) == USB_ID_US428 ?
|
|
|
|
&quirk_2 : &quirk_1;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-05-17 13:15:37 +00:00
|
|
|
snd_printdd("%s\n", __func__);
|
2021-05-17 13:15:35 +00:00
|
|
|
return snd_usbmidi_create(card, iface, &usx2y(card)->midi_list, quirk);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 13:15:35 +00:00
|
|
|
static int usx2y_create_alsa_devices(struct snd_card *card)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2021-05-17 13:15:37 +00:00
|
|
|
err = usx2y_create_usbmidi(card);
|
|
|
|
if (err < 0) {
|
|
|
|
snd_printk(KERN_ERR "%s: usx2y_create_usbmidi error %i\n", __func__, err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
err = usx2y_audio_create(card);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
err = usx2y_hwdep_pcm_new(card);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
err = snd_card_register(card);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
return 0;
|
2021-05-17 13:15:36 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-05-17 13:15:35 +00:00
|
|
|
static int snd_usx2y_hwdep_dsp_load(struct snd_hwdep *hw,
|
2005-11-17 14:08:26 +00:00
|
|
|
struct snd_hwdep_dsp_image *dsp)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2021-05-17 13:15:35 +00:00
|
|
|
struct usx2ydev *priv = hw->private_data;
|
2021-05-17 13:15:36 +00:00
|
|
|
struct usb_device *dev = priv->dev;
|
2017-12-28 19:43:06 +00:00
|
|
|
int lret, err;
|
|
|
|
char *buf;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-05-17 13:15:36 +00:00
|
|
|
snd_printdd("dsp_load %s\n", dsp->name);
|
2009-04-10 01:43:59 +00:00
|
|
|
|
2017-12-28 19:43:06 +00:00
|
|
|
buf = memdup_user(dsp->image, dsp->length);
|
|
|
|
if (IS_ERR(buf))
|
|
|
|
return PTR_ERR(buf);
|
2009-04-10 01:43:59 +00:00
|
|
|
|
2017-12-28 19:43:06 +00:00
|
|
|
err = usb_set_interface(dev, 0, 1);
|
|
|
|
if (err)
|
2021-05-17 13:15:36 +00:00
|
|
|
snd_printk(KERN_ERR "usb_set_interface error\n");
|
2017-12-28 19:43:06 +00:00
|
|
|
else
|
|
|
|
err = usb_bulk_msg(dev, usb_sndbulkpipe(dev, 2), buf, dsp->length, &lret, 6000);
|
|
|
|
kfree(buf);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
if (dsp->index == 1) {
|
2005-07-09 08:54:37 +00:00
|
|
|
msleep(250); // give the device some time
|
2021-05-17 13:15:35 +00:00
|
|
|
err = usx2y_async_seq04_init(priv);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err) {
|
2021-05-17 13:15:36 +00:00
|
|
|
snd_printk(KERN_ERR "usx2y_async_seq04_init error\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
2021-05-17 13:15:35 +00:00
|
|
|
err = usx2y_in04_init(priv);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err) {
|
2021-05-17 13:15:36 +00:00
|
|
|
snd_printk(KERN_ERR "usx2y_in04_init error\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
2021-05-17 13:15:35 +00:00
|
|
|
err = usx2y_create_alsa_devices(hw->card);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err) {
|
2021-05-17 13:15:36 +00:00
|
|
|
snd_printk(KERN_ERR "usx2y_create_alsa_devices error %i\n", err);
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
2021-05-17 13:15:36 +00:00
|
|
|
priv->chip_status |= USX2Y_STAT_CHIP_INIT;
|
2005-04-16 22:20:36 +00:00
|
|
|
snd_printdd("%s: alsa all started\n", hw->name);
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-05-17 13:15:36 +00:00
|
|
|
int usx2y_hwdep_new(struct snd_card *card, struct usb_device *device)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int err;
|
2005-11-17 14:08:26 +00:00
|
|
|
struct snd_hwdep *hw;
|
2021-05-17 13:15:42 +00:00
|
|
|
struct usx2ydev *us428 = usx2y(card);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-05-17 13:15:37 +00:00
|
|
|
err = snd_hwdep_new(card, SND_USX2Y_LOADER_ID, 0, &hw);
|
|
|
|
if (err < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
|
|
|
|
hw->iface = SNDRV_HWDEP_IFACE_USX2Y;
|
2021-05-17 13:15:42 +00:00
|
|
|
hw->private_data = us428;
|
2021-05-17 13:15:35 +00:00
|
|
|
hw->ops.dsp_status = snd_usx2y_hwdep_dsp_status;
|
|
|
|
hw->ops.dsp_load = snd_usx2y_hwdep_dsp_load;
|
2005-04-16 22:20:36 +00:00
|
|
|
hw->ops.mmap = snd_us428ctls_mmap;
|
|
|
|
hw->ops.poll = snd_us428ctls_poll;
|
|
|
|
hw->exclusive = 1;
|
2017-04-17 00:51:11 +00:00
|
|
|
sprintf(hw->name, "/dev/bus/usb/%03d/%03d", device->bus->busnum, device->devnum);
|
2021-05-17 13:15:42 +00:00
|
|
|
|
|
|
|
us428->us428ctls_sharedmem = alloc_pages_exact(US428_SHAREDMEM_PAGES, GFP_KERNEL);
|
|
|
|
if (!us428->us428ctls_sharedmem)
|
|
|
|
return -ENOMEM;
|
|
|
|
memset(us428->us428ctls_sharedmem, -1, US428_SHAREDMEM_PAGES);
|
|
|
|
us428->us428ctls_sharedmem->ctl_snapshot_last = -2;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|