2006-06-21 21:42:43 +08:00
|
|
|
/*
|
|
|
|
* i2sbus driver
|
|
|
|
*
|
2009-01-16 01:21:48 +08:00
|
|
|
* Copyright 2006-2008 Johannes Berg <johannes@sipsolutions.net>
|
2006-06-21 21:42:43 +08:00
|
|
|
*
|
|
|
|
* GPL v2, can be found in COPYING.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.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>
|
2006-06-21 21:42:43 +08:00
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/interrupt.h>
|
2006-07-10 19:44:34 +08:00
|
|
|
#include <linux/dma-mapping.h>
|
2013-09-18 03:28:33 +08:00
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/of_irq.h>
|
2006-07-10 19:44:34 +08:00
|
|
|
|
2006-06-21 21:42:43 +08:00
|
|
|
#include <sound/core.h>
|
2006-07-10 19:44:34 +08:00
|
|
|
|
|
|
|
#include <asm/macio.h>
|
|
|
|
#include <asm/dbdma.h>
|
|
|
|
|
2006-06-21 21:42:43 +08:00
|
|
|
#include "../soundbus.h"
|
|
|
|
#include "i2sbus.h"
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
|
|
|
|
MODULE_DESCRIPTION("Apple Soundbus: I2S support");
|
|
|
|
|
2006-07-10 19:44:34 +08:00
|
|
|
static int force;
|
|
|
|
module_param(force, int, 0444);
|
|
|
|
MODULE_PARM_DESC(force, "Force loading i2sbus even when"
|
|
|
|
" no layout-id property is present");
|
|
|
|
|
2015-03-19 00:48:56 +08:00
|
|
|
static const struct of_device_id i2sbus_match[] = {
|
2006-06-21 21:42:43 +08:00
|
|
|
{ .name = "i2s" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2007-03-28 19:42:25 +08:00
|
|
|
MODULE_DEVICE_TABLE(of, i2sbus_match);
|
|
|
|
|
2006-06-21 21:42:43 +08:00
|
|
|
static int alloc_dbdma_descriptor_ring(struct i2sbus_dev *i2sdev,
|
|
|
|
struct dbdma_command_mem *r,
|
|
|
|
int numcmds)
|
|
|
|
{
|
2007-02-08 21:25:39 +08:00
|
|
|
/* one more for rounding, one for branch back, one for stop command */
|
|
|
|
r->size = (numcmds + 3) * sizeof(struct dbdma_cmd);
|
2006-06-21 21:42:43 +08:00
|
|
|
/* We use the PCI APIs for now until the generic one gets fixed
|
|
|
|
* enough or until we get some macio-specific versions
|
|
|
|
*/
|
2014-06-16 04:37:55 +08:00
|
|
|
r->space = dma_zalloc_coherent(&macio_get_pci_dev(i2sdev->macio)->dev,
|
|
|
|
r->size, &r->bus_addr, GFP_KERNEL);
|
|
|
|
if (!r->space)
|
|
|
|
return -ENOMEM;
|
2006-06-21 21:42:43 +08:00
|
|
|
|
|
|
|
r->cmds = (void*)DBDMA_ALIGN(r->space);
|
|
|
|
r->bus_cmd_start = r->bus_addr +
|
|
|
|
(dma_addr_t)((char*)r->cmds - (char*)r->space);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_dbdma_descriptor_ring(struct i2sbus_dev *i2sdev,
|
|
|
|
struct dbdma_command_mem *r)
|
|
|
|
{
|
|
|
|
if (!r->space) return;
|
2008-10-23 21:47:56 +08:00
|
|
|
|
2006-06-21 21:42:43 +08:00
|
|
|
dma_free_coherent(&macio_get_pci_dev(i2sdev->macio)->dev,
|
|
|
|
r->size, r->space, r->bus_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void i2sbus_release_dev(struct device *dev)
|
|
|
|
{
|
|
|
|
struct i2sbus_dev *i2sdev;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i2sdev = container_of(dev, struct i2sbus_dev, sound.ofdev.dev);
|
2015-01-04 05:55:54 +08:00
|
|
|
iounmap(i2sdev->intfregs);
|
|
|
|
iounmap(i2sdev->out.dbdma);
|
|
|
|
iounmap(i2sdev->in.dbdma);
|
2006-07-10 19:44:34 +08:00
|
|
|
for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++)
|
2014-12-03 05:50:24 +08:00
|
|
|
release_and_free_resource(i2sdev->allocated_resource[i]);
|
2006-06-21 21:42:43 +08:00
|
|
|
free_dbdma_descriptor_ring(i2sdev, &i2sdev->out.dbdma_ring);
|
|
|
|
free_dbdma_descriptor_ring(i2sdev, &i2sdev->in.dbdma_ring);
|
2006-07-10 19:44:34 +08:00
|
|
|
for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++)
|
2006-06-21 21:42:43 +08:00
|
|
|
free_irq(i2sdev->interrupts[i], i2sdev);
|
|
|
|
i2sbus_control_remove_dev(i2sdev->control, i2sdev);
|
|
|
|
mutex_destroy(&i2sdev->lock);
|
|
|
|
kfree(i2sdev);
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
static irqreturn_t i2sbus_bus_intr(int irq, void *devid)
|
2006-06-21 21:42:43 +08:00
|
|
|
{
|
|
|
|
struct i2sbus_dev *dev = devid;
|
|
|
|
u32 intreg;
|
|
|
|
|
|
|
|
spin_lock(&dev->low_lock);
|
|
|
|
intreg = in_le32(&dev->intfregs->intr_ctl);
|
|
|
|
|
|
|
|
/* acknowledge interrupt reasons */
|
|
|
|
out_le32(&dev->intfregs->intr_ctl, intreg);
|
|
|
|
|
|
|
|
spin_unlock(&dev->low_lock);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2006-07-10 19:44:34 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX FIXME: We test the layout_id's here to get the proper way of
|
|
|
|
* mapping in various registers, thanks to bugs in Apple device-trees.
|
|
|
|
* We could instead key off the machine model and the name of the i2s
|
|
|
|
* node (i2s-a). This we'll do when we move it all to macio_asic.c
|
|
|
|
* and have that export items for each sub-node too.
|
|
|
|
*/
|
|
|
|
static int i2sbus_get_and_fixup_rsrc(struct device_node *np, int index,
|
|
|
|
int layout, struct resource *res)
|
|
|
|
{
|
|
|
|
struct device_node *parent;
|
|
|
|
int pindex, rc = -ENXIO;
|
2007-04-03 08:52:17 +08:00
|
|
|
const u32 *reg;
|
2006-07-10 19:44:34 +08:00
|
|
|
|
|
|
|
/* Machines with layout 76 and 36 (K2 based) have a weird device
|
|
|
|
* tree what we need to special case.
|
|
|
|
* Normal machines just fetch the resource from the i2s-X node.
|
|
|
|
* Darwin further divides normal machines into old and new layouts
|
|
|
|
* with a subtely different code path but that doesn't seem necessary
|
|
|
|
* in practice, they just bloated it. In addition, even on our K2
|
|
|
|
* case the i2s-modem node, if we ever want to handle it, uses the
|
|
|
|
* normal layout
|
|
|
|
*/
|
|
|
|
if (layout != 76 && layout != 36)
|
|
|
|
return of_address_to_resource(np, index, res);
|
|
|
|
|
|
|
|
parent = of_get_parent(np);
|
|
|
|
pindex = (index == aoa_resource_i2smmio) ? 0 : 1;
|
|
|
|
rc = of_address_to_resource(parent, pindex, res);
|
|
|
|
if (rc)
|
|
|
|
goto bail;
|
2007-04-03 20:39:14 +08:00
|
|
|
reg = of_get_property(np, "reg", NULL);
|
2006-07-10 19:44:34 +08:00
|
|
|
if (reg == NULL) {
|
|
|
|
rc = -ENXIO;
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
res->start += reg[index * 2];
|
|
|
|
res->end = res->start + reg[index * 2 + 1] - 1;
|
|
|
|
bail:
|
|
|
|
of_node_put(parent);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2006-06-21 21:42:43 +08:00
|
|
|
/* FIXME: look at device node refcounting */
|
|
|
|
static int i2sbus_add_dev(struct macio_dev *macio,
|
|
|
|
struct i2sbus_control *control,
|
|
|
|
struct device_node *np)
|
|
|
|
{
|
|
|
|
struct i2sbus_dev *dev;
|
|
|
|
struct device_node *child = NULL, *sound = NULL;
|
2006-07-10 19:44:34 +08:00
|
|
|
struct resource *r;
|
2008-10-23 19:57:39 +08:00
|
|
|
int i, layout = 0, rlen, ok = force;
|
2006-06-21 21:42:43 +08:00
|
|
|
static const char *rnames[] = { "i2sbus: %s (control)",
|
|
|
|
"i2sbus: %s (tx)",
|
|
|
|
"i2sbus: %s (rx)" };
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
static irq_handler_t ints[] = {
|
2006-06-21 21:42:43 +08:00
|
|
|
i2sbus_bus_intr,
|
|
|
|
i2sbus_tx_intr,
|
|
|
|
i2sbus_rx_intr
|
|
|
|
};
|
|
|
|
|
|
|
|
if (strlen(np->name) != 5)
|
|
|
|
return 0;
|
|
|
|
if (strncmp(np->name, "i2s-", 4))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
dev = kzalloc(sizeof(struct i2sbus_dev), GFP_KERNEL);
|
|
|
|
if (!dev)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while ((child = of_get_next_child(np, child))) {
|
|
|
|
if (strcmp(child->name, "sound") == 0) {
|
|
|
|
i++;
|
|
|
|
sound = child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == 1) {
|
2009-01-16 01:21:48 +08:00
|
|
|
const u32 *id = of_get_property(sound, "layout-id", NULL);
|
|
|
|
|
|
|
|
if (id) {
|
|
|
|
layout = *id;
|
2006-06-21 21:42:43 +08:00
|
|
|
snprintf(dev->sound.modalias, 32,
|
2006-07-10 19:44:34 +08:00
|
|
|
"sound-layout-%d", layout);
|
2008-10-23 19:57:39 +08:00
|
|
|
ok = 1;
|
2009-01-16 01:21:48 +08:00
|
|
|
} else {
|
|
|
|
id = of_get_property(sound, "device-id", NULL);
|
|
|
|
/*
|
|
|
|
* We probably cannot handle all device-id machines,
|
|
|
|
* so restrict to those we do handle for now.
|
|
|
|
*/
|
2013-05-06 09:01:05 +08:00
|
|
|
if (id && (*id == 22 || *id == 14 || *id == 35 ||
|
2016-08-25 01:57:47 +08:00
|
|
|
*id == 31 || *id == 44)) {
|
2009-01-16 01:21:48 +08:00
|
|
|
snprintf(dev->sound.modalias, 32,
|
|
|
|
"aoa-device-id-%d", *id);
|
|
|
|
ok = 1;
|
|
|
|
layout = -1;
|
|
|
|
}
|
2006-06-21 21:42:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* for the time being, until we can handle non-layout-id
|
|
|
|
* things in some fabric, refuse to attach if there is no
|
|
|
|
* layout-id property or we haven't been forced to attach.
|
|
|
|
* When there are two i2s busses and only one has a layout-id,
|
|
|
|
* then this depends on the order, but that isn't important
|
|
|
|
* either as the second one in that case is just a modem. */
|
2008-10-23 19:57:39 +08:00
|
|
|
if (!ok) {
|
2006-06-21 21:42:43 +08:00
|
|
|
kfree(dev);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_init(&dev->lock);
|
|
|
|
spin_lock_init(&dev->low_lock);
|
2010-04-14 07:12:59 +08:00
|
|
|
dev->sound.ofdev.archdata.dma_mask = macio->ofdev.archdata.dma_mask;
|
2010-04-14 07:12:29 +08:00
|
|
|
dev->sound.ofdev.dev.of_node = np;
|
2010-04-14 07:12:59 +08:00
|
|
|
dev->sound.ofdev.dev.dma_mask = &dev->sound.ofdev.archdata.dma_mask;
|
2006-06-21 21:42:43 +08:00
|
|
|
dev->sound.ofdev.dev.parent = &macio->ofdev.dev;
|
|
|
|
dev->sound.ofdev.dev.release = i2sbus_release_dev;
|
|
|
|
dev->sound.attach_codec = i2sbus_attach_codec;
|
|
|
|
dev->sound.detach_codec = i2sbus_detach_codec;
|
|
|
|
dev->sound.pcmid = -1;
|
|
|
|
dev->macio = macio;
|
|
|
|
dev->control = control;
|
|
|
|
dev->bus_number = np->name[4] - 'a';
|
|
|
|
INIT_LIST_HEAD(&dev->sound.codec_list);
|
|
|
|
|
2006-07-10 19:44:34 +08:00
|
|
|
for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++) {
|
2006-06-21 21:42:43 +08:00
|
|
|
dev->interrupts[i] = -1;
|
2006-07-10 19:44:34 +08:00
|
|
|
snprintf(dev->rnames[i], sizeof(dev->rnames[i]),
|
|
|
|
rnames[i], np->name);
|
2006-06-21 21:42:43 +08:00
|
|
|
}
|
2006-07-10 19:44:34 +08:00
|
|
|
for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++) {
|
2006-07-10 19:44:33 +08:00
|
|
|
int irq = irq_of_parse_and_map(np, i);
|
|
|
|
if (request_irq(irq, ints[i], 0, dev->rnames[i], dev))
|
2006-06-21 21:42:43 +08:00
|
|
|
goto err;
|
2006-07-10 19:44:33 +08:00
|
|
|
dev->interrupts[i] = irq;
|
2006-06-21 21:42:43 +08:00
|
|
|
}
|
|
|
|
|
2006-07-10 19:44:34 +08:00
|
|
|
|
|
|
|
/* Resource handling is problematic as some device-trees contain
|
|
|
|
* useless crap (ugh ugh ugh). We work around that here by calling
|
|
|
|
* specific functions for calculating the appropriate resources.
|
|
|
|
*
|
|
|
|
* This will all be moved to macio_asic.c at one point
|
|
|
|
*/
|
|
|
|
for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++) {
|
|
|
|
if (i2sbus_get_and_fixup_rsrc(np,i,layout,&dev->resources[i]))
|
2006-06-21 21:42:43 +08:00
|
|
|
goto err;
|
2006-07-10 19:44:34 +08:00
|
|
|
/* If only we could use our resource dev->resources[i]...
|
2006-06-21 21:42:43 +08:00
|
|
|
* but request_resource doesn't know about parents and
|
2006-07-10 19:44:34 +08:00
|
|
|
* contained resources...
|
|
|
|
*/
|
2008-10-23 21:47:56 +08:00
|
|
|
dev->allocated_resource[i] =
|
2006-06-21 21:42:43 +08:00
|
|
|
request_mem_region(dev->resources[i].start,
|
2011-06-10 00:13:32 +08:00
|
|
|
resource_size(&dev->resources[i]),
|
2006-06-21 21:42:43 +08:00
|
|
|
dev->rnames[i]);
|
|
|
|
if (!dev->allocated_resource[i]) {
|
|
|
|
printk(KERN_ERR "i2sbus: failed to claim resource %d!\n", i);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
2006-07-10 19:44:34 +08:00
|
|
|
|
|
|
|
r = &dev->resources[aoa_resource_i2smmio];
|
2011-06-10 00:13:32 +08:00
|
|
|
rlen = resource_size(r);
|
2006-07-10 19:44:34 +08:00
|
|
|
if (rlen < sizeof(struct i2s_interface_regs))
|
|
|
|
goto err;
|
|
|
|
dev->intfregs = ioremap(r->start, rlen);
|
|
|
|
|
|
|
|
r = &dev->resources[aoa_resource_txdbdma];
|
2011-06-10 00:13:32 +08:00
|
|
|
rlen = resource_size(r);
|
2006-07-10 19:44:34 +08:00
|
|
|
if (rlen < sizeof(struct dbdma_regs))
|
|
|
|
goto err;
|
|
|
|
dev->out.dbdma = ioremap(r->start, rlen);
|
|
|
|
|
|
|
|
r = &dev->resources[aoa_resource_rxdbdma];
|
2011-06-10 00:13:32 +08:00
|
|
|
rlen = resource_size(r);
|
2006-07-10 19:44:34 +08:00
|
|
|
if (rlen < sizeof(struct dbdma_regs))
|
|
|
|
goto err;
|
|
|
|
dev->in.dbdma = ioremap(r->start, rlen);
|
|
|
|
|
2006-06-21 21:42:43 +08:00
|
|
|
if (!dev->intfregs || !dev->out.dbdma || !dev->in.dbdma)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (alloc_dbdma_descriptor_ring(dev, &dev->out.dbdma_ring,
|
|
|
|
MAX_DBDMA_COMMANDS))
|
|
|
|
goto err;
|
|
|
|
if (alloc_dbdma_descriptor_ring(dev, &dev->in.dbdma_ring,
|
|
|
|
MAX_DBDMA_COMMANDS))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (i2sbus_control_add_dev(dev->control, dev)) {
|
|
|
|
printk(KERN_ERR "i2sbus: control layer didn't like bus\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (soundbus_add_one(&dev->sound)) {
|
|
|
|
printk(KERN_DEBUG "i2sbus: device registration error!\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* enable this cell */
|
|
|
|
i2sbus_control_cell(dev->control, dev, 1);
|
|
|
|
i2sbus_control_enable(dev->control, dev);
|
|
|
|
i2sbus_control_clock(dev->control, dev, 1);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
err:
|
|
|
|
for (i=0;i<3;i++)
|
|
|
|
if (dev->interrupts[i] != -1)
|
|
|
|
free_irq(dev->interrupts[i], dev);
|
|
|
|
free_dbdma_descriptor_ring(dev, &dev->out.dbdma_ring);
|
|
|
|
free_dbdma_descriptor_ring(dev, &dev->in.dbdma_ring);
|
2015-01-04 05:55:54 +08:00
|
|
|
iounmap(dev->intfregs);
|
|
|
|
iounmap(dev->out.dbdma);
|
|
|
|
iounmap(dev->in.dbdma);
|
2006-06-21 21:42:43 +08:00
|
|
|
for (i=0;i<3;i++)
|
2014-12-03 05:50:24 +08:00
|
|
|
release_and_free_resource(dev->allocated_resource[i]);
|
2006-06-21 21:42:43 +08:00
|
|
|
mutex_destroy(&dev->lock);
|
|
|
|
kfree(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int i2sbus_probe(struct macio_dev* dev, const struct of_device_id *match)
|
|
|
|
{
|
|
|
|
struct device_node *np = NULL;
|
|
|
|
int got = 0, err;
|
|
|
|
struct i2sbus_control *control = NULL;
|
|
|
|
|
|
|
|
err = i2sbus_control_init(dev, &control);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
if (!control) {
|
|
|
|
printk(KERN_ERR "i2sbus_control_init API breakage\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2010-04-14 07:12:29 +08:00
|
|
|
while ((np = of_get_next_child(dev->ofdev.dev.of_node, np))) {
|
2007-05-03 15:26:52 +08:00
|
|
|
if (of_device_is_compatible(np, "i2sbus") ||
|
|
|
|
of_device_is_compatible(np, "i2s-modem")) {
|
2006-06-21 21:42:43 +08:00
|
|
|
got += i2sbus_add_dev(dev, control, np);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!got) {
|
|
|
|
/* found none, clean up */
|
|
|
|
i2sbus_control_destroy(control);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2009-05-05 03:40:54 +08:00
|
|
|
dev_set_drvdata(&dev->ofdev.dev, control);
|
2006-06-21 21:42:43 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int i2sbus_remove(struct macio_dev* dev)
|
|
|
|
{
|
2009-05-05 03:40:54 +08:00
|
|
|
struct i2sbus_control *control = dev_get_drvdata(&dev->ofdev.dev);
|
2006-06-21 21:42:43 +08:00
|
|
|
struct i2sbus_dev *i2sdev, *tmp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(i2sdev, tmp, &control->list, item)
|
|
|
|
soundbus_remove_one(&i2sdev->sound);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
static int i2sbus_suspend(struct macio_dev* dev, pm_message_t state)
|
|
|
|
{
|
2009-05-05 03:40:54 +08:00
|
|
|
struct i2sbus_control *control = dev_get_drvdata(&dev->ofdev.dev);
|
2006-06-21 21:42:43 +08:00
|
|
|
struct codec_info_item *cii;
|
|
|
|
struct i2sbus_dev* i2sdev;
|
|
|
|
int err, ret = 0;
|
|
|
|
|
|
|
|
list_for_each_entry(i2sdev, &control->list, item) {
|
|
|
|
/* Notify Alsa */
|
2015-01-04 03:43:01 +08:00
|
|
|
/* Suspend PCM streams */
|
|
|
|
snd_pcm_suspend_all(i2sdev->sound.pcm);
|
2007-02-08 21:25:39 +08:00
|
|
|
|
2006-06-21 21:42:43 +08:00
|
|
|
/* Notify codecs */
|
|
|
|
list_for_each_entry(cii, &i2sdev->sound.codec_list, list) {
|
|
|
|
err = 0;
|
|
|
|
if (cii->codec->suspend)
|
|
|
|
err = cii->codec->suspend(cii, state);
|
|
|
|
if (err)
|
|
|
|
ret = err;
|
|
|
|
}
|
2007-02-08 21:25:39 +08:00
|
|
|
|
|
|
|
/* wait until streams are stopped */
|
|
|
|
i2sbus_wait_for_stop_both(i2sdev);
|
2006-06-21 21:42:43 +08:00
|
|
|
}
|
2007-02-08 21:25:39 +08:00
|
|
|
|
2006-06-21 21:42:43 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int i2sbus_resume(struct macio_dev* dev)
|
|
|
|
{
|
2009-05-05 03:40:54 +08:00
|
|
|
struct i2sbus_control *control = dev_get_drvdata(&dev->ofdev.dev);
|
2006-06-21 21:42:43 +08:00
|
|
|
struct codec_info_item *cii;
|
|
|
|
struct i2sbus_dev* i2sdev;
|
|
|
|
int err, ret = 0;
|
|
|
|
|
|
|
|
list_for_each_entry(i2sdev, &control->list, item) {
|
2007-02-08 21:25:39 +08:00
|
|
|
/* reset i2s bus format etc. */
|
|
|
|
i2sbus_pcm_prepare_both(i2sdev);
|
|
|
|
|
2006-06-21 21:42:43 +08:00
|
|
|
/* Notify codecs so they can re-initialize */
|
|
|
|
list_for_each_entry(cii, &i2sdev->sound.codec_list, list) {
|
|
|
|
err = 0;
|
|
|
|
if (cii->codec->resume)
|
|
|
|
err = cii->codec->resume(cii);
|
|
|
|
if (err)
|
|
|
|
ret = err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_PM */
|
|
|
|
|
|
|
|
static int i2sbus_shutdown(struct macio_dev* dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct macio_driver i2sbus_drv = {
|
2010-06-02 15:09:18 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "soundbus-i2s",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.of_match_table = i2sbus_match,
|
|
|
|
},
|
2006-06-21 21:42:43 +08:00
|
|
|
.probe = i2sbus_probe,
|
|
|
|
.remove = i2sbus_remove,
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
.suspend = i2sbus_suspend,
|
|
|
|
.resume = i2sbus_resume,
|
|
|
|
#endif
|
|
|
|
.shutdown = i2sbus_shutdown,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init soundbus_i2sbus_init(void)
|
|
|
|
{
|
|
|
|
return macio_register_driver(&i2sbus_drv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit soundbus_i2sbus_exit(void)
|
|
|
|
{
|
|
|
|
macio_unregister_driver(&i2sbus_drv);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(soundbus_i2sbus_init);
|
|
|
|
module_exit(soundbus_i2sbus_exit);
|