linux/sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c
Tejun Heo 5a0e3ad6af 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-30 22:02:32 +09:00

308 lines
7.6 KiB
C

/*
* Driver for Sound Core PDAudioCF soundcards
*
* PCM part
*
* Copyright (c) 2003 by Jaroslav Kysela <perex@perex.cz>
*
* 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 <linux/delay.h>
#include <sound/core.h>
#include <sound/asoundef.h>
#include "pdaudiocf.h"
/*
* clear the SRAM contents
*/
static int pdacf_pcm_clear_sram(struct snd_pdacf *chip)
{
int max_loop = 64 * 1024;
while (inw(chip->port + PDAUDIOCF_REG_RDP) != inw(chip->port + PDAUDIOCF_REG_WDP)) {
if (max_loop-- < 0)
return -EIO;
inw(chip->port + PDAUDIOCF_REG_MD);
}
return 0;
}
/*
* pdacf_pcm_trigger - trigger callback for capture
*/
static int pdacf_pcm_trigger(struct snd_pcm_substream *subs, int cmd)
{
struct snd_pdacf *chip = snd_pcm_substream_chip(subs);
struct snd_pcm_runtime *runtime = subs->runtime;
int inc, ret = 0, rate;
unsigned short mask, val, tmp;
if (chip->chip_status & PDAUDIOCF_STAT_IS_STALE)
return -EBUSY;
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
chip->pcm_hwptr = 0;
chip->pcm_tdone = 0;
/* fall thru */
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
case SNDRV_PCM_TRIGGER_RESUME:
mask = 0;
val = PDAUDIOCF_RECORD;
inc = 1;
rate = snd_ak4117_check_rate_and_errors(chip->ak4117, AK4117_CHECK_NO_STAT|AK4117_CHECK_NO_RATE);
break;
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
case SNDRV_PCM_TRIGGER_SUSPEND:
mask = PDAUDIOCF_RECORD;
val = 0;
inc = -1;
rate = 0;
break;
default:
return -EINVAL;
}
spin_lock(&chip->reg_lock);
chip->pcm_running += inc;
tmp = pdacf_reg_read(chip, PDAUDIOCF_REG_SCR);
if (chip->pcm_running) {
if ((chip->ak4117->rcs0 & AK4117_UNLCK) || runtime->rate != rate) {
chip->pcm_running -= inc;
ret = -EIO;
goto __end;
}
}
tmp &= ~mask;
tmp |= val;
pdacf_reg_write(chip, PDAUDIOCF_REG_SCR, tmp);
__end:
spin_unlock(&chip->reg_lock);
snd_ak4117_check_rate_and_errors(chip->ak4117, AK4117_CHECK_NO_RATE);
return ret;
}
/*
* pdacf_pcm_hw_params - hw_params callback for playback and capture
*/
static int pdacf_pcm_hw_params(struct snd_pcm_substream *subs,
struct snd_pcm_hw_params *hw_params)
{
return snd_pcm_lib_alloc_vmalloc_32_buffer
(subs, params_buffer_bytes(hw_params));
}
/*
* pdacf_pcm_hw_free - hw_free callback for playback and capture
*/
static int pdacf_pcm_hw_free(struct snd_pcm_substream *subs)
{
return snd_pcm_lib_free_vmalloc_buffer(subs);
}
/*
* pdacf_pcm_prepare - prepare callback for playback and capture
*/
static int pdacf_pcm_prepare(struct snd_pcm_substream *subs)
{
struct snd_pdacf *chip = snd_pcm_substream_chip(subs);
struct snd_pcm_runtime *runtime = subs->runtime;
u16 val, nval, aval;
if (chip->chip_status & PDAUDIOCF_STAT_IS_STALE)
return -EBUSY;
chip->pcm_channels = runtime->channels;
chip->pcm_little = snd_pcm_format_little_endian(runtime->format) > 0;
#ifdef SNDRV_LITTLE_ENDIAN
chip->pcm_swab = snd_pcm_format_big_endian(runtime->format) > 0;
#else
chip->pcm_swab = chip->pcm_little;
#endif
if (snd_pcm_format_unsigned(runtime->format))
chip->pcm_xor = 0x80008000;
if (pdacf_pcm_clear_sram(chip) < 0)
return -EIO;
val = nval = pdacf_reg_read(chip, PDAUDIOCF_REG_SCR);
nval &= ~(PDAUDIOCF_DATAFMT0|PDAUDIOCF_DATAFMT1);
switch (runtime->format) {
case SNDRV_PCM_FORMAT_S16_LE:
case SNDRV_PCM_FORMAT_S16_BE:
break;
default: /* 24-bit */
nval |= PDAUDIOCF_DATAFMT0 | PDAUDIOCF_DATAFMT1;
break;
}
aval = 0;
chip->pcm_sample = 4;
switch (runtime->format) {
case SNDRV_PCM_FORMAT_S16_LE:
case SNDRV_PCM_FORMAT_S16_BE:
aval = AK4117_DIF_16R;
chip->pcm_frame = 2;
chip->pcm_sample = 2;
break;
case SNDRV_PCM_FORMAT_S24_3LE:
case SNDRV_PCM_FORMAT_S24_3BE:
chip->pcm_sample = 3;
/* fall through */
default: /* 24-bit */
aval = AK4117_DIF_24R;
chip->pcm_frame = 3;
chip->pcm_xor &= 0xffff0000;
break;
}
if (val != nval) {
snd_ak4117_reg_write(chip->ak4117, AK4117_REG_IO, AK4117_DIF2|AK4117_DIF1|AK4117_DIF0, aval);
pdacf_reg_write(chip, PDAUDIOCF_REG_SCR, nval);
}
val = pdacf_reg_read(chip, PDAUDIOCF_REG_IER);
val &= ~(PDAUDIOCF_IRQLVLEN1);
val |= PDAUDIOCF_IRQLVLEN0;
pdacf_reg_write(chip, PDAUDIOCF_REG_IER, val);
chip->pcm_size = runtime->buffer_size;
chip->pcm_period = runtime->period_size;
chip->pcm_area = runtime->dma_area;
return 0;
}
/*
* capture hw information
*/
static struct snd_pcm_hardware pdacf_pcm_capture_hw = {
.info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME |
SNDRV_PCM_INFO_MMAP_VALID |
SNDRV_PCM_INFO_BATCH),
.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |
SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE |
SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
.rates = SNDRV_PCM_RATE_32000 |
SNDRV_PCM_RATE_44100 |
SNDRV_PCM_RATE_48000 |
SNDRV_PCM_RATE_88200 |
SNDRV_PCM_RATE_96000 |
SNDRV_PCM_RATE_176400 |
SNDRV_PCM_RATE_192000,
.rate_min = 32000,
.rate_max = 192000,
.channels_min = 1,
.channels_max = 2,
.buffer_bytes_max = (512*1024),
.period_bytes_min = 8*1024,
.period_bytes_max = (64*1024),
.periods_min = 2,
.periods_max = 128,
.fifo_size = 0,
};
/*
* pdacf_pcm_capture_open - open callback for capture
*/
static int pdacf_pcm_capture_open(struct snd_pcm_substream *subs)
{
struct snd_pcm_runtime *runtime = subs->runtime;
struct snd_pdacf *chip = snd_pcm_substream_chip(subs);
if (chip->chip_status & PDAUDIOCF_STAT_IS_STALE)
return -EBUSY;
runtime->hw = pdacf_pcm_capture_hw;
runtime->private_data = chip;
chip->pcm_substream = subs;
return 0;
}
/*
* pdacf_pcm_capture_close - close callback for capture
*/
static int pdacf_pcm_capture_close(struct snd_pcm_substream *subs)
{
struct snd_pdacf *chip = snd_pcm_substream_chip(subs);
if (!chip)
return -EINVAL;
pdacf_reinit(chip, 0);
chip->pcm_substream = NULL;
return 0;
}
/*
* pdacf_pcm_capture_pointer - pointer callback for capture
*/
static snd_pcm_uframes_t pdacf_pcm_capture_pointer(struct snd_pcm_substream *subs)
{
struct snd_pdacf *chip = snd_pcm_substream_chip(subs);
return chip->pcm_hwptr;
}
/*
* operators for PCM capture
*/
static struct snd_pcm_ops pdacf_pcm_capture_ops = {
.open = pdacf_pcm_capture_open,
.close = pdacf_pcm_capture_close,
.ioctl = snd_pcm_lib_ioctl,
.hw_params = pdacf_pcm_hw_params,
.hw_free = pdacf_pcm_hw_free,
.prepare = pdacf_pcm_prepare,
.trigger = pdacf_pcm_trigger,
.pointer = pdacf_pcm_capture_pointer,
.page = snd_pcm_lib_get_vmalloc_page,
.mmap = snd_pcm_lib_mmap_vmalloc,
};
/*
* snd_pdacf_pcm_new - create and initialize a pcm
*/
int snd_pdacf_pcm_new(struct snd_pdacf *chip)
{
struct snd_pcm *pcm;
int err;
err = snd_pcm_new(chip->card, "PDAudioCF", 0, 0, 1, &pcm);
if (err < 0)
return err;
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &pdacf_pcm_capture_ops);
pcm->private_data = chip;
pcm->info_flags = 0;
strcpy(pcm->name, chip->card->shortname);
chip->pcm = pcm;
err = snd_ak4117_build(chip->ak4117, pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
if (err < 0)
return err;
return 0;
}