Re: [PATCH v1] [media] atmel-isi: code cleanup

2017-05-21 Thread Wu, Songjun

Hi Hugues,

Thank you for your patch.
Is it necessary to ensure ISI is clocked before starting sensor sub device?

On 5/19/2017 20:08, Hugues FRUCHET wrote:

Adding Songjun and Ludovic as Atmel maintainers, sorry for inconvenience.

On 05/19/2017 12:04 PM, Hugues Fruchet wrote:

Ensure that ISI is clocked before starting sensor sub device.
Remove un-needed type check in try_fmt().
Use clamp() macro for hardware capabilities.
Fix wrong tabulation to space.

Signed-off-by: Hugues Fruchet 
---
   drivers/media/platform/atmel/atmel-isi.c | 24 ++--
   1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/drivers/media/platform/atmel/atmel-isi.c 
b/drivers/media/platform/atmel/atmel-isi.c
index e4867f8..7bf9f7d 100644
--- a/drivers/media/platform/atmel/atmel-isi.c
+++ b/drivers/media/platform/atmel/atmel-isi.c
@@ -36,8 +36,8 @@
   
   #include "atmel-isi.h"
   
-#define MAX_SUPPORT_WIDTH		2048

-#define MAX_SUPPORT_HEIGHT 2048
+#define MAX_SUPPORT_WIDTH  2048U
+#define MAX_SUPPORT_HEIGHT 2048U
   #define MIN_FRAME_RATE   15
   #define FRAME_INTERVAL_MILLI_SEC (1000 / MIN_FRAME_RATE)
   
@@ -424,6 +424,8 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)

struct frame_buffer *buf, *node;
int ret;
   
+	pm_runtime_get_sync(isi->dev);

+
/* Enable stream on the sub device */
ret = v4l2_subdev_call(isi->entity.subdev, video, s_stream, 1);
if (ret && ret != -ENOIOCTLCMD) {
@@ -431,8 +433,6 @@ static int start_streaming(struct vb2_queue *vq, unsigned 
int count)
goto err_start_stream;
}
   
-	pm_runtime_get_sync(isi->dev);

-
/* Reset ISI */
ret = atmel_isi_wait_status(isi, WAIT_ISI_RESET);
if (ret < 0) {
@@ -455,10 +455,11 @@ static int start_streaming(struct vb2_queue *vq, unsigned 
int count)
return 0;
   
   err_reset:

-   pm_runtime_put(isi->dev);
v4l2_subdev_call(isi->entity.subdev, video, s_stream, 0);
   
   err_start_stream:

+   pm_runtime_put(isi->dev);
+
spin_lock_irq(>irqlock);
isi->active = NULL;
/* Release all active buffers */
@@ -566,20 +567,15 @@ static int isi_try_fmt(struct atmel_isi *isi, struct 
v4l2_format *f,
};
int ret;
   
-	if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)

-   return -EINVAL;
-
isi_fmt = find_format_by_fourcc(isi, pixfmt->pixelformat);
if (!isi_fmt) {
isi_fmt = isi->user_formats[isi->num_user_formats - 1];
pixfmt->pixelformat = isi_fmt->fourcc;
}
   
-	/* Limit to Atmel ISC hardware capabilities */

-   if (pixfmt->width > MAX_SUPPORT_WIDTH)
-   pixfmt->width = MAX_SUPPORT_WIDTH;
-   if (pixfmt->height > MAX_SUPPORT_HEIGHT)
-   pixfmt->height = MAX_SUPPORT_HEIGHT;
+   /* Limit to Atmel ISI hardware capabilities */
+   pixfmt->width = clamp(pixfmt->width, 0U, MAX_SUPPORT_WIDTH);
+   pixfmt->height = clamp(pixfmt->height, 0U, MAX_SUPPORT_HEIGHT);
   
   	v4l2_fill_mbus_format(, pixfmt, isi_fmt->mbus_code);

ret = v4l2_subdev_call(isi->entity.subdev, pad, set_fmt,
@@ -1058,7 +1054,7 @@ static int isi_graph_notify_complete(struct 
v4l2_async_notifier *notifier)
struct atmel_isi *isi = notifier_to_isi(notifier);
int ret;
   
-	isi->vdev->ctrl_handler	= isi->entity.subdev->ctrl_handler;

+   isi->vdev->ctrl_handler = isi->entity.subdev->ctrl_handler;
ret = isi_formats_init(isi);
if (ret) {
dev_err(isi->dev, "No supported mediabus format found\n");


cron job: media_tree daily build: ERRORS

2017-05-21 Thread Hans Verkuil
This message is generated daily by a cron job that builds media_tree for
the kernels and architectures in the list below.

Results of the daily build of media_tree:

date:   Mon May 22 05:00:16 CEST 2017
media-tree git hash:36bcba973ad478042d1ffc6e89afd92e8bd17030
media_build git hash:   ab988a3d089232ce9e1aec2f259e947c06983dbc
v4l-utils git hash: d16a17abd1d8d7885ca2f44fb295035278baa89c
gcc version:i686-linux-gcc (GCC) 7.1.0
sparse version: v0.5.0-3553-g78b2ea6
smatch version: v0.5.0-3553-g78b2ea6
host hardware:  x86_64
host os:4.9.0-164

linux-git-arm-at91: ERRORS
linux-git-arm-davinci: ERRORS
linux-git-arm-multi: ERRORS
linux-git-arm-pxa: ERRORS
linux-git-blackfin-bf561: ERRORS
linux-git-i686: OK
linux-git-m32r: OK
linux-git-mips: ERRORS
linux-git-powerpc64: OK
linux-git-sh: ERRORS
linux-git-x86_64: WARNINGS
linux-2.6.36.4-i686: ERRORS
linux-2.6.37.6-i686: ERRORS
linux-2.6.38.8-i686: ERRORS
linux-2.6.39.4-i686: ERRORS
linux-3.0.60-i686: ERRORS
linux-3.1.10-i686: ERRORS
linux-3.2.37-i686: ERRORS
linux-3.3.8-i686: ERRORS
linux-3.4.27-i686: ERRORS
linux-3.5.7-i686: ERRORS
linux-3.6.11-i686: ERRORS
linux-3.7.4-i686: ERRORS
linux-3.8-i686: ERRORS
linux-3.9.2-i686: ERRORS
linux-3.10.1-i686: ERRORS
linux-3.11.1-i686: ERRORS
linux-3.12.67-i686: ERRORS
linux-3.13.11-i686: ERRORS
linux-3.14.9-i686: ERRORS
linux-3.15.2-i686: ERRORS
linux-3.16.7-i686: ERRORS
linux-3.17.8-i686: ERRORS
linux-3.18.7-i686: ERRORS
linux-3.19-i686: ERRORS
linux-4.0.9-i686: ERRORS
linux-4.1.33-i686: ERRORS
linux-4.2.8-i686: ERRORS
linux-4.3.6-i686: ERRORS
linux-4.4.22-i686: ERRORS
linux-4.5.7-i686: ERRORS
linux-4.6.7-i686: ERRORS
linux-4.7.5-i686: ERRORS
linux-4.8-i686: ERRORS
linux-4.9.26-i686: ERRORS
linux-4.10.14-i686: ERRORS
linux-4.11-i686: ERRORS
linux-4.12-rc1-i686: ERRORS
linux-2.6.36.4-x86_64: ERRORS
linux-2.6.37.6-x86_64: ERRORS
linux-2.6.38.8-x86_64: ERRORS
linux-2.6.39.4-x86_64: ERRORS
linux-3.0.60-x86_64: ERRORS
linux-3.1.10-x86_64: ERRORS
linux-3.2.37-x86_64: ERRORS
linux-3.3.8-x86_64: ERRORS
linux-3.4.27-x86_64: ERRORS
linux-3.5.7-x86_64: ERRORS
linux-3.6.11-x86_64: ERRORS
linux-3.7.4-x86_64: ERRORS
linux-3.8-x86_64: ERRORS
linux-3.9.2-x86_64: ERRORS
linux-3.10.1-x86_64: ERRORS
linux-3.11.1-x86_64: ERRORS
linux-3.12.67-x86_64: ERRORS
linux-3.13.11-x86_64: ERRORS
linux-3.14.9-x86_64: ERRORS
linux-3.15.2-x86_64: ERRORS
linux-3.16.7-x86_64: ERRORS
linux-3.17.8-x86_64: ERRORS
linux-3.18.7-x86_64: ERRORS
linux-3.19-x86_64: ERRORS
linux-4.0.9-x86_64: ERRORS
linux-4.1.33-x86_64: ERRORS
linux-4.2.8-x86_64: ERRORS
linux-4.3.6-x86_64: ERRORS
linux-4.4.22-x86_64: ERRORS
linux-4.5.7-x86_64: ERRORS
linux-4.6.7-x86_64: ERRORS
linux-4.7.5-x86_64: ERRORS
linux-4.8-x86_64: ERRORS
linux-4.9.26-x86_64: ERRORS
linux-4.10.14-x86_64: ERRORS
linux-4.11-x86_64: ERRORS
linux-4.12-rc1-x86_64: ERRORS
apps: WARNINGS
spec-git: OK
sparse: WARNINGS

Detailed results are available here:

http://www.xs4all.nl/~hverkuil/logs/Monday.log

Full logs are available here:

http://www.xs4all.nl/~hverkuil/logs/Monday.tar.bz2

The Media Infrastructure API from this daily build is here:

http://www.xs4all.nl/~hverkuil/spec/index.html


[PATCH 14/16] ASoC: blackfin: Convert to copy_silence ops

2017-05-21 Thread Takashi Iwai
Replace the copy and the silence ops with the new merged ops.
The silence is performed only when CONFIG_SND_BF5XX_MMAP_SUPPORT is
set (since copy_silence ops is set only with this config), so in
bf5xx-ac97.c we have a bit tricky macro for a slight optimization.

Note that we don't need to take in_kernel into account on this
architecture, so the conversion is easy otherwise.

Signed-off-by: Takashi Iwai 
---
 sound/soc/blackfin/bf5xx-ac97-pcm.c |  6 ++---
 sound/soc/blackfin/bf5xx-ac97.c | 18 ++-
 sound/soc/blackfin/bf5xx-i2s-pcm.c  | 46 -
 3 files changed, 30 insertions(+), 40 deletions(-)

diff --git a/sound/soc/blackfin/bf5xx-ac97-pcm.c 
b/sound/soc/blackfin/bf5xx-ac97-pcm.c
index 02ad2606fa19..2fdffa7d376c 100644
--- a/sound/soc/blackfin/bf5xx-ac97-pcm.c
+++ b/sound/soc/blackfin/bf5xx-ac97-pcm.c
@@ -280,8 +280,8 @@ static int bf5xx_pcm_mmap(struct snd_pcm_substream 
*substream,
 }
 #else
 static int bf5xx_pcm_copy(struct snd_pcm_substream *substream, int channel,
-   snd_pcm_uframes_t pos,
-   void __user *buf, snd_pcm_uframes_t count)
+  snd_pcm_uframes_t pos, void __user *buf,
+  snd_pcm_uframes_t count, bool in_kernel)
 {
struct snd_pcm_runtime *runtime = substream->runtime;
unsigned int chan_mask = ac97_chan_mask[runtime->channels - 1];
@@ -309,7 +309,7 @@ static struct snd_pcm_ops bf5xx_pcm_ac97_ops = {
 #if defined(CONFIG_SND_BF5XX_MMAP_SUPPORT)
.mmap   = bf5xx_pcm_mmap,
 #else
-   .copy   = bf5xx_pcm_copy,
+   .copy_silence   = bf5xx_pcm_copy,
 #endif
 };
 
diff --git a/sound/soc/blackfin/bf5xx-ac97.c b/sound/soc/blackfin/bf5xx-ac97.c
index a040cfe29fc0..d1f11d9ecb07 100644
--- a/sound/soc/blackfin/bf5xx-ac97.c
+++ b/sound/soc/blackfin/bf5xx-ac97.c
@@ -43,35 +43,41 @@
 
 static struct sport_device *ac97_sport_handle;
 
+#ifdef CONFIG_SND_BF5XX_MMAP_SUPPORT
+#define GET_VAL(src)   (*src++)/* copy only */
+#else
+#define GET_VAL(src)   (src ? *src++ : 0)  /* copy/silence */
+#endif
+
 void bf5xx_pcm_to_ac97(struct ac97_frame *dst, const __u16 *src,
size_t count, unsigned int chan_mask)
 {
while (count--) {
dst->ac97_tag = TAG_VALID;
if (chan_mask & SP_FL) {
-   dst->ac97_pcm_r = *src++;
+   dst->ac97_pcm_r = GET_VAL(src);
dst->ac97_tag |= TAG_PCM_RIGHT;
}
if (chan_mask & SP_FR) {
-   dst->ac97_pcm_l = *src++;
+   dst->ac97_pcm_l = GET_VAL(src);
dst->ac97_tag |= TAG_PCM_LEFT;
 
}
 #if defined(CONFIG_SND_BF5XX_MULTICHAN_SUPPORT)
if (chan_mask & SP_SR) {
-   dst->ac97_sl = *src++;
+   dst->ac97_sl = GET_VAL(src);
dst->ac97_tag |= TAG_PCM_SL;
}
if (chan_mask & SP_SL) {
-   dst->ac97_sr = *src++;
+   dst->ac97_sr = GET_VAL(src);
dst->ac97_tag |= TAG_PCM_SR;
}
if (chan_mask & SP_LFE) {
-   dst->ac97_lfe = *src++;
+   dst->ac97_lfe = GET_VAL(src);
dst->ac97_tag |= TAG_PCM_LFE;
}
if (chan_mask & SP_FC) {
-   dst->ac97_center = *src++;
+   dst->ac97_center = GET_VAL(src);
dst->ac97_tag |= TAG_PCM_CENTER;
}
 #endif
diff --git a/sound/soc/blackfin/bf5xx-i2s-pcm.c 
b/sound/soc/blackfin/bf5xx-i2s-pcm.c
index 6cba211da32e..5686c29fb058 100644
--- a/sound/soc/blackfin/bf5xx-i2s-pcm.c
+++ b/sound/soc/blackfin/bf5xx-i2s-pcm.c
@@ -226,7 +226,8 @@ static int bf5xx_pcm_mmap(struct snd_pcm_substream 
*substream,
 }
 
 static int bf5xx_pcm_copy(struct snd_pcm_substream *substream, int channel,
-   snd_pcm_uframes_t pos, void *buf, snd_pcm_uframes_t count)
+ snd_pcm_uframes_t pos, void *buf,
+ snd_pcm_uframes_t count, bool in_kernel)
 {
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_pcm_runtime *runtime = substream->runtime;
@@ -245,8 +246,14 @@ static int bf5xx_pcm_copy(struct snd_pcm_substream 
*substream, int channel,
 
while (count--) {
for (i = 0; i < runtime->channels; i++) {
-   memcpy(dst + dma_data->map[i] *
-   sample_size, src, sample_size);
+   if (!buf)
+   memset(dst + dma_data->map[i] *
+  sample_size, 0,
+ 

[PATCH 16/16] ALSA: pcm: Drop the old copy and silence ops

2017-05-21 Thread Takashi Iwai
Now that all users of old copy and silence ops have been converted to
the new copy_silence ops, the old stuff can be retired and go away.

Signed-off-by: Takashi Iwai 
---
 include/sound/pcm.h  |  5 -
 sound/core/pcm_lib.c | 38 +-
 sound/soc/soc-pcm.c  |  2 --
 3 files changed, 1 insertion(+), 44 deletions(-)

diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index b9dd813dd885..4243c02c3f11 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -78,11 +78,6 @@ struct snd_pcm_ops {
struct timespec *system_ts, struct timespec *audio_ts,
struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
struct snd_pcm_audio_tstamp_report 
*audio_tstamp_report);
-   int (*copy)(struct snd_pcm_substream *substream, int channel,
-   snd_pcm_uframes_t pos,
-   void __user *buf, snd_pcm_uframes_t count);
-   int (*silence)(struct snd_pcm_substream *substream, int channel, 
-  snd_pcm_uframes_t pos, snd_pcm_uframes_t count);
int (*copy_silence)(struct snd_pcm_substream *substream, int channel,
snd_pcm_uframes_t pos, void __user *buf,
snd_pcm_uframes_t count, bool in_kernel);
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index b720cbda017f..1c9d43fefacc 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -115,9 +115,6 @@ void snd_pcm_playback_silence(struct snd_pcm_substream 
*substream, snd_pcm_ufram
err = substream->ops->copy_silence(substream,
-1, ofs, NULL, transfer, false);
snd_BUG_ON(err < 0);
-   } else if (substream->ops->silence) {
-   err = substream->ops->silence(substream, -1, 
ofs, transfer);
-   snd_BUG_ON(err < 0);
} else {
hwbuf = runtime->dma_area + 
frames_to_bytes(runtime, ofs);
snd_pcm_format_set_silence(runtime->format, 
hwbuf, transfer * runtime->channels);
@@ -131,11 +128,6 @@ void snd_pcm_playback_silence(struct snd_pcm_substream 
*substream, snd_pcm_ufram
c, ofs, NULL, transfer, false);
snd_BUG_ON(err < 0);
}
-   } else if (substream->ops->silence) {
-   for (c = 0; c < channels; ++c) {
-   err = 
substream->ops->silence(substream, c, ofs, transfer);
-   snd_BUG_ON(err < 0);
-   }
} else {
size_t dma_csize = runtime->dma_bytes / 
channels;
for (c = 0; c < channels; ++c) {
@@ -2010,9 +2002,6 @@ static int snd_pcm_lib_write_transfer(struct 
snd_pcm_substream *substream,
   frames, false);
if (err < 0)
return err;
-   } else if (substream->ops->copy) {
-   if ((err = substream->ops->copy(substream, -1, hwoff, buf, 
frames)) < 0)
-   return err;
} else {
char *hwbuf = runtime->dma_area + frames_to_bytes(runtime, 
hwoff);
if (copy_from_user(hwbuf, buf, frames_to_bytes(runtime, 
frames)))
@@ -2134,8 +2123,7 @@ static int pcm_sanity_check(struct snd_pcm_substream 
*substream)
if (PCM_RUNTIME_CHECK(substream))
return -ENXIO;
runtime = substream->runtime;
-   if (snd_BUG_ON(!substream->ops->copy_silence && !substream->ops->copy
-  && !runtime->dma_area))
+   if (snd_BUG_ON(!substream->ops->copy_silence && !runtime->dma_area))
return -EINVAL;
if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
return -EBADFD;
@@ -2186,19 +2174,6 @@ static int snd_pcm_lib_writev_transfer(struct 
snd_pcm_substream *substream,
if (err < 0)
return err;
}
-   } else if (substream->ops->copy) {
-   if (snd_BUG_ON(!substream->ops->silence))
-   return -EINVAL;
-   for (c = 0; c < channels; ++c, ++bufs) {
-   if (*bufs == NULL) {
-   if ((err = substream->ops->silence(substream, 
c, hwoff, frames)) < 0)
-   return err;
-   } else {
-   buf = *bufs + samples_to_bytes(runtime, off);
-   if ((err = substream->ops->copy(substream, c, 
hwoff, buf, frames)) < 0)
-   return err;

[PATCH 15/16] [media] solo6x10: Convert to copy_silence ops

2017-05-21 Thread Takashi Iwai
Replace the copy and the silence ops with the new merged ops.
It's a capture stream, thus no silence is needed.

Signed-off-by: Takashi Iwai 
---
 drivers/media/pci/solo6x10/solo6x10-g723.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c 
b/drivers/media/pci/solo6x10/solo6x10-g723.c
index 36e93540bb49..e21db3efb748 100644
--- a/drivers/media/pci/solo6x10/solo6x10-g723.c
+++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
@@ -225,7 +225,7 @@ static snd_pcm_uframes_t snd_solo_pcm_pointer(struct 
snd_pcm_substream *ss)
 
 static int snd_solo_pcm_copy(struct snd_pcm_substream *ss, int channel,
 snd_pcm_uframes_t pos, void __user *dst,
-snd_pcm_uframes_t count)
+snd_pcm_uframes_t count, bool in_kernel)
 {
struct solo_snd_pcm *solo_pcm = snd_pcm_substream_chip(ss);
struct solo_dev *solo_dev = solo_pcm->solo_dev;
@@ -242,10 +242,11 @@ static int snd_solo_pcm_copy(struct snd_pcm_substream 
*ss, int channel,
if (err)
return err;
 
-   err = copy_to_user(dst + (i * G723_PERIOD_BYTES),
-  solo_pcm->g723_buf, G723_PERIOD_BYTES);
-
-   if (err)
+   if (in_kernel)
+   memcpy((void *)dst + (i * G723_PERIOD_BYTES),
+  solo_pcm->g723_buf, G723_PERIOD_BYTES);
+   else if (copy_to_user(dst + (i * G723_PERIOD_BYTES),
+ solo_pcm->g723_buf, G723_PERIOD_BYTES))
return -EFAULT;
}
 
@@ -261,7 +262,7 @@ static const struct snd_pcm_ops snd_solo_pcm_ops = {
.prepare = snd_solo_pcm_prepare,
.trigger = snd_solo_pcm_trigger,
.pointer = snd_solo_pcm_pointer,
-   .copy = snd_solo_pcm_copy,
+   .copy_silence = snd_solo_pcm_copy,
 };
 
 static int snd_solo_capture_volume_info(struct snd_kcontrol *kcontrol,
-- 
2.13.0



[PATCH 01/16] ALSA: pcm: Introduce copy_silence PCM ops

2017-05-21 Thread Takashi Iwai
For supporting the explicit in-kernel copy of PCM buffer data, and
also for reducing the redundant codes for both PCM copy and silence
callbacks, a new ops copy_silence is introduced in this patch.  This
is supposed to serve for both copy and silence operations.  The
silence operation is distinguished by NULL buffer passed (required
only in playback direction).

Also, the callback receives a new boolean flag, in_kernel, which
indicates that the callback gets called for copying the data from/to
the kernel buffer instead of the user-space buffer.  The in_kernel
flag will be used mainly in PCM OSS code for the on-the-fly
conversion.  As this patch stands, only in_kernel=false is passed.
The actual usage of in_kernel=true will be introduced later.

Signed-off-by: Takashi Iwai 
---
 include/sound/pcm.h  |  3 +++
 sound/core/pcm_lib.c | 74 +---
 sound/soc/soc-pcm.c  |  1 +
 3 files changed, 63 insertions(+), 15 deletions(-)

diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index c609b891c4c2..b9dd813dd885 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -83,6 +83,9 @@ struct snd_pcm_ops {
void __user *buf, snd_pcm_uframes_t count);
int (*silence)(struct snd_pcm_substream *substream, int channel, 
   snd_pcm_uframes_t pos, snd_pcm_uframes_t count);
+   int (*copy_silence)(struct snd_pcm_substream *substream, int channel,
+   snd_pcm_uframes_t pos, void __user *buf,
+   snd_pcm_uframes_t count, bool in_kernel);
struct page *(*page)(struct snd_pcm_substream *substream,
 unsigned long offset);
int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct 
*vma);
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index ab4b1d1e44ee..b720cbda017f 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -55,6 +55,8 @@ void snd_pcm_playback_silence(struct snd_pcm_substream 
*substream, snd_pcm_ufram
 {
struct snd_pcm_runtime *runtime = substream->runtime;
snd_pcm_uframes_t frames, ofs, transfer;
+   char *hwbuf;
+   int err;
 
if (runtime->silence_size < runtime->boundary) {
snd_pcm_sframes_t noise_dist, n;
@@ -109,27 +111,35 @@ void snd_pcm_playback_silence(struct snd_pcm_substream 
*substream, snd_pcm_ufram
transfer = ofs + frames > runtime->buffer_size ? 
runtime->buffer_size - ofs : frames;
if (runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED ||
runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED) {
-   if (substream->ops->silence) {
-   int err;
+   if (substream->ops->copy_silence) {
+   err = substream->ops->copy_silence(substream,
+   -1, ofs, NULL, transfer, false);
+   snd_BUG_ON(err < 0);
+   } else if (substream->ops->silence) {
err = substream->ops->silence(substream, -1, 
ofs, transfer);
snd_BUG_ON(err < 0);
} else {
-   char *hwbuf = runtime->dma_area + 
frames_to_bytes(runtime, ofs);
+   hwbuf = runtime->dma_area + 
frames_to_bytes(runtime, ofs);
snd_pcm_format_set_silence(runtime->format, 
hwbuf, transfer * runtime->channels);
}
} else {
unsigned int c;
unsigned int channels = runtime->channels;
-   if (substream->ops->silence) {
+   if (substream->ops->copy_silence) {
+   for (c = 0; c < channels; ++c) {
+   err = 
substream->ops->copy_silence(substream,
+   c, ofs, NULL, transfer, false);
+   snd_BUG_ON(err < 0);
+   }
+   } else if (substream->ops->silence) {
for (c = 0; c < channels; ++c) {
-   int err;
err = 
substream->ops->silence(substream, c, ofs, transfer);
snd_BUG_ON(err < 0);
}
} else {
size_t dma_csize = runtime->dma_bytes / 
channels;
for (c = 0; c < channels; ++c) {
-   char *hwbuf = runtime->dma_area + (c * 
dma_csize) + samples_to_bytes(runtime, ofs);
+   hwbuf = runtime->dma_area + (c * 
dma_csize) + samples_to_bytes(runtime, ofs);
 

[PATCH 12/16] ALSA: sb: Convert to copy_silence ops

2017-05-21 Thread Takashi Iwai
Replace the copy and the silence ops with the new merged ops.
We could reduce the redundant silence code by that.

Signed-off-by: Takashi Iwai 
---
 sound/isa/sb/emu8000_pcm.c | 99 ++
 1 file changed, 30 insertions(+), 69 deletions(-)

diff --git a/sound/isa/sb/emu8000_pcm.c b/sound/isa/sb/emu8000_pcm.c
index 32f234f494e5..fd42ae2f73b8 100644
--- a/sound/isa/sb/emu8000_pcm.c
+++ b/sound/isa/sb/emu8000_pcm.c
@@ -422,16 +422,28 @@ do { \
return -EAGAIN;\
 } while (0)
 
+static inline int get_val(unsigned short *sval, unsigned short __user *buf,
+ bool in_kernel)
+{
+   if (!buf)
+   *sval = 0;
+   else if (in_kernel)
+   *sval = *(unsigned short *)buf;
+   else if (get_user(*sval, buf))
+   return -EFAULT;
+   return 0;
+}
 
 #ifdef USE_NONINTERLEAVE
 /* copy one channel block */
-static int emu8k_transfer_block(struct snd_emu8000 *emu, int offset, unsigned 
short *buf, int count)
+static int emu8k_transfer_block(struct snd_emu8000 *emu, int offset,
+   unsigned short *buf, int count, bool in_kernel)
 {
EMU8000_SMALW_WRITE(emu, offset);
while (count > 0) {
unsigned short sval;
CHECK_SCHEDULER();
-   if (get_user(sval, buf))
+   if (get_val(, buf, in_kernel))
return -EFAULT;
EMU8000_SMLD_WRITE(emu, sval);
buf++;
@@ -455,48 +467,18 @@ static int emu8k_pcm_copy(struct snd_pcm_substream *subs,
int i, err;
count /= rec->voices;
for (i = 0; i < rec->voices; i++) {
-   err = emu8k_transfer_block(emu, pos + 
rec->loop_start[i], buf, count);
+   err = emu8k_transfer_block(emu,
+  pos + rec->loop_start[i],
+  buf, count, in_kernel);
if (err < 0)
return err;
-   buf += count;
+   if (buf)
+   buf += count;
}
return 0;
} else {
-   return emu8k_transfer_block(emu, pos + rec->loop_start[voice], 
src, count);
-   }
-}
-
-/* make a channel block silence */
-static int emu8k_silence_block(struct snd_emu8000 *emu, int offset, int count)
-{
-   EMU8000_SMALW_WRITE(emu, offset);
-   while (count > 0) {
-   CHECK_SCHEDULER();
-   EMU8000_SMLD_WRITE(emu, 0);
-   count--;
-   }
-   return 0;
-}
-
-static int emu8k_pcm_silence(struct snd_pcm_substream *subs,
-int voice,
-snd_pcm_uframes_t pos,
-snd_pcm_uframes_t count)
-{
-   struct snd_emu8k_pcm *rec = subs->runtime->private_data;
-   struct snd_emu8000 *emu = rec->emu;
-
-   snd_emu8000_write_wait(emu, 1);
-   if (voice == -1 && rec->voices == 1)
-   voice = 0;
-   if (voice == -1) {
-   int err;
-   err = emu8k_silence_block(emu, pos + rec->loop_start[0], count 
/ 2);
-   if (err < 0)
-   return err;
-   return emu8k_silence_block(emu, pos + rec->loop_start[1], count 
/ 2);
-   } else {
-   return emu8k_silence_block(emu, pos + rec->loop_start[voice], 
count);
+   return emu8k_transfer_block(emu, pos + rec->loop_start[voice],
+   src, count, in_kernel);
}
 }
 
@@ -510,7 +492,8 @@ static int emu8k_pcm_copy(struct snd_pcm_substream *subs,
  int voice,
  snd_pcm_uframes_t pos,
  void __user *src,
- snd_pcm_uframes_t count)
+ snd_pcm_uframes_t count,
+ bool in_kernel)
 {
struct snd_emu8k_pcm *rec = subs->runtime->private_data;
struct snd_emu8000 *emu = rec->emu;
@@ -524,39 +507,18 @@ static int emu8k_pcm_copy(struct snd_pcm_substream *subs,
while (count-- > 0) {
unsigned short sval;
CHECK_SCHEDULER();
-   if (get_user(sval, buf))
+   if (get_val(, buf, in_kernel))
return -EFAULT;
EMU8000_SMLD_WRITE(emu, sval);
-   buf++;
+   if (buf)
+   buf++;
if (rec->voices > 1) {
CHECK_SCHEDULER();
-   if (get_user(sval, buf))
+   if (get_val(, buf, in_kernel))
return -EFAULT;
EMU8000_SMRD_WRITE(emu, sval);
-   buf++;
-   }
-   }
-   return 0;
-}
-

[PATCH 04/16] ALSA: es1938: Convert to copy_silence ops

2017-05-21 Thread Takashi Iwai
Replace the copy and the silence ops with the new merged ops.
It's used only for a capture stream (for some hardware workaround),
thus we need no silence operation but only to add the in_kernel
memcpy() handling.

Signed-off-by: Takashi Iwai 
---
 sound/pci/es1938.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index e8d943071a8c..d79ac13d6f70 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -842,7 +842,8 @@ static int snd_es1938_capture_copy(struct snd_pcm_substream 
*substream,
   int channel,
   snd_pcm_uframes_t pos,
   void __user *dst,
-  snd_pcm_uframes_t count)
+  snd_pcm_uframes_t count,
+  bool in_kernel)
 {
struct snd_pcm_runtime *runtime = substream->runtime;
struct es1938 *chip = snd_pcm_substream_chip(substream);
@@ -850,8 +851,10 @@ static int snd_es1938_capture_copy(struct 
snd_pcm_substream *substream,
count <<= chip->dma1_shift;
if (snd_BUG_ON(pos + count > chip->dma1_size))
return -EINVAL;
-   if (pos + count < chip->dma1_size) {
-   if (copy_to_user(dst, runtime->dma_area + pos + 1, count))
+   if (in_kernel || pos + count < chip->dma1_size) {
+   if (in_kernel)
+   memcpy((void *)dst, runtime->dma_area + pos + 1, count);
+   else if (copy_to_user(dst, runtime->dma_area + pos + 1, count))
return -EFAULT;
} else {
if (copy_to_user(dst, runtime->dma_area + pos + 1, count - 1))
@@ -1012,7 +1015,7 @@ static const struct snd_pcm_ops snd_es1938_capture_ops = {
.prepare =  snd_es1938_capture_prepare,
.trigger =  snd_es1938_capture_trigger,
.pointer =  snd_es1938_capture_pointer,
-   .copy = snd_es1938_capture_copy,
+   .copy_silence = snd_es1938_capture_copy,
 };
 
 static int snd_es1938_new_pcm(struct es1938 *chip, int device)
-- 
2.13.0



[PATCH 10/16] ALSA: hdsp: Convert to copy_silence ops

2017-05-21 Thread Takashi Iwai
Replace the copy and the silence ops with the new merged ops.
The conversion is straightforward with standard helper functions.

Signed-off-by: Takashi Iwai 
---
 sound/pci/rme9652/hdsp.c | 44 
 1 file changed, 20 insertions(+), 24 deletions(-)

diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index fc0face6cdc6..5325e91fc3a8 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -3913,8 +3913,10 @@ static char *hdsp_channel_buffer_location(struct hdsp 
*hdsp,
return hdsp->playback_buffer + (mapped_channel * 
HDSP_CHANNEL_BUFFER_BYTES);
 }
 
-static int snd_hdsp_playback_copy(struct snd_pcm_substream *substream, int 
channel,
- snd_pcm_uframes_t pos, void __user *src, 
snd_pcm_uframes_t count)
+static int snd_hdsp_playback_copy(struct snd_pcm_substream *substream,
+ int channel, snd_pcm_uframes_t pos,
+ void __user *src, snd_pcm_uframes_t count,
+ bool in_kernel)
 {
struct hdsp *hdsp = snd_pcm_substream_chip(substream);
char *channel_buf;
@@ -3925,13 +3927,19 @@ static int snd_hdsp_playback_copy(struct 
snd_pcm_substream *substream, int chann
channel_buf = hdsp_channel_buffer_location (hdsp, 
substream->pstr->stream, channel);
if (snd_BUG_ON(!channel_buf))
return -EIO;
-   if (copy_from_user(channel_buf + pos * 4, src, count * 4))
+   if (!src)
+   memset(channel_buf + pos * 4, 0, count * 4);
+   else if (in_kernel)
+   memcpy(channel_buf + pos * 4, (void *)src, count * 4);
+   else if (copy_from_user(channel_buf + pos * 4, src, count * 4))
return -EFAULT;
-   return count;
+   return 0;
 }
 
-static int snd_hdsp_capture_copy(struct snd_pcm_substream *substream, int 
channel,
-snd_pcm_uframes_t pos, void __user *dst, 
snd_pcm_uframes_t count)
+static int snd_hdsp_capture_copy(struct snd_pcm_substream *substream,
+int channel, snd_pcm_uframes_t pos,
+void __user *dst, snd_pcm_uframes_t count,
+bool in_kernel)
 {
struct hdsp *hdsp = snd_pcm_substream_chip(substream);
char *channel_buf;
@@ -3942,22 +3950,11 @@ static int snd_hdsp_capture_copy(struct 
snd_pcm_substream *substream, int channe
channel_buf = hdsp_channel_buffer_location (hdsp, 
substream->pstr->stream, channel);
if (snd_BUG_ON(!channel_buf))
return -EIO;
-   if (copy_to_user(dst, channel_buf + pos * 4, count * 4))
+   if (in_kernel)
+   memcpy((void *)dst, channel_buf + pos * 4, count * 4);
+   else if (copy_to_user(dst, channel_buf + pos * 4, count * 4))
return -EFAULT;
-   return count;
-}
-
-static int snd_hdsp_hw_silence(struct snd_pcm_substream *substream, int 
channel,
- snd_pcm_uframes_t pos, snd_pcm_uframes_t 
count)
-{
-   struct hdsp *hdsp = snd_pcm_substream_chip(substream);
-   char *channel_buf;
-
-   channel_buf = hdsp_channel_buffer_location (hdsp, 
substream->pstr->stream, channel);
-   if (snd_BUG_ON(!channel_buf))
-   return -EIO;
-   memset(channel_buf + pos * 4, 0, count * 4);
-   return count;
+   return 0;
 }
 
 static int snd_hdsp_reset(struct snd_pcm_substream *substream)
@@ -4869,8 +4866,7 @@ static const struct snd_pcm_ops snd_hdsp_playback_ops = {
.prepare =  snd_hdsp_prepare,
.trigger =  snd_hdsp_trigger,
.pointer =  snd_hdsp_hw_pointer,
-   .copy = snd_hdsp_playback_copy,
-   .silence =  snd_hdsp_hw_silence,
+   .copy_silence = snd_hdsp_playback_copy,
 };
 
 static const struct snd_pcm_ops snd_hdsp_capture_ops = {
@@ -4881,7 +4877,7 @@ static const struct snd_pcm_ops snd_hdsp_capture_ops = {
.prepare =  snd_hdsp_prepare,
.trigger =  snd_hdsp_trigger,
.pointer =  snd_hdsp_hw_pointer,
-   .copy = snd_hdsp_capture_copy,
+   .copy_silence = snd_hdsp_capture_copy,
 };
 
 static int snd_hdsp_create_hwdep(struct snd_card *card, struct hdsp *hdsp)
-- 
2.13.0



[PATCH 02/16] ALSA: Update document about copy_silence PCM ops

2017-05-21 Thread Takashi Iwai
Signed-off-by: Takashi Iwai 
---
 .../sound/kernel-api/writing-an-alsa-driver.rst| 110 -
 1 file changed, 63 insertions(+), 47 deletions(-)

diff --git a/Documentation/sound/kernel-api/writing-an-alsa-driver.rst 
b/Documentation/sound/kernel-api/writing-an-alsa-driver.rst
index 95c5443eff38..ebaf8b1e0079 100644
--- a/Documentation/sound/kernel-api/writing-an-alsa-driver.rst
+++ b/Documentation/sound/kernel-api/writing-an-alsa-driver.rst
@@ -2080,18 +2080,18 @@ sleeping poll threads, etc.
 
 This callback is also atomic as default.
 
-copy and silence callbacks
-~~
+copy_silence callback
+~
 
-These callbacks are not mandatory, and can be omitted in most cases.
-These callbacks are used when the hardware buffer cannot be in the
+This callback is not mandatory, and can be omitted in most cases.
+This callback is used when the hardware buffer cannot be in the
 normal memory space. Some chips have their own buffer on the hardware
 which is not mappable. In such a case, you have to transfer the data
 manually from the memory buffer to the hardware buffer. Or, if the
 buffer is non-contiguous on both physical and virtual memory spaces,
 these callbacks must be defined, too.
 
-If these two callbacks are defined, copy and set-silence operations
+If this callback is defined, copy and set-silence operations
 are done by them. The detailed will be described in the later section
 `Buffer and Memory Management`_.
 
@@ -3545,30 +3545,34 @@ Another case is when the chip uses a PCI memory-map 
region for the
 buffer instead of the host memory. In this case, mmap is available only
 on certain architectures like the Intel one. In non-mmap mode, the data
 cannot be transferred as in the normal way. Thus you need to define the
-``copy`` and ``silence`` callbacks as well, as in the cases above. The
+``copy_silence`` callback as well, as in the cases above. The
 examples are found in ``rme32.c`` and ``rme96.c``.
 
-The implementation of the ``copy`` and ``silence`` callbacks depends
+The implementation of the ``copy_silence`` callback depends
 upon whether the hardware supports interleaved or non-interleaved
-samples. The ``copy`` callback is defined like below, a bit
+samples. The ``copy_silence`` callback is defined like below, a bit
 differently depending whether the direction is playback or capture:
 
 ::
 
   static int playback_copy(struct snd_pcm_substream *substream, int channel,
-   snd_pcm_uframes_t pos, void *src, snd_pcm_uframes_t count);
+   snd_pcm_uframes_t pos, void __user *src,
+  snd_pcm_uframes_t count, bool in_kernel);
   static int capture_copy(struct snd_pcm_substream *substream, int channel,
-   snd_pcm_uframes_t pos, void *dst, snd_pcm_uframes_t count);
+   snd_pcm_uframes_t pos, void __user *dst,
+  snd_pcm_uframes_t count, bool in_kernel);
 
 In the case of interleaved samples, the second argument (``channel``) is
-not used. The third argument (``pos``) points the current position
-offset in frames.
+not used, and -1 is passed. The third argument (``pos``) points the
+current position offset in frames.
 
 The meaning of the fourth argument is different between playback and
 capture. For playback, it holds the source data pointer, and for
 capture, it's the destination data pointer.
 
-The last argument is the number of frames to be copied.
+The fifth argument is the number of frames to be copied.
+And the last argument indicates whether the passed buffer pointer is in
+user-space or in kernel-space.  The copy operation depends on this.
 
 What you have to do in this callback is again different between playback
 and capture directions. In the playback case, you copy the given amount
@@ -3578,52 +3582,64 @@ way, the copy would be like:
 
 ::
 
-  my_memcpy(my_buffer + frames_to_bytes(runtime, pos), src,
-frames_to_bytes(runtime, count));
-
-For the capture direction, you copy the given amount of data (``count``)
-at the specified offset (``pos``) on the hardware buffer to the
-specified pointer (``dst``).
-
-::
+  if (!src)
+  my_memset(my_buffer + frames_to_bytes(runtime, pos), 0,
+frames_to_bytes(runtime, count));
+  else if (in_kernel)
+  memcpy_toio(my_buffer + frames_to_bytes(runtime, pos),
+  (void *)src, frames_to_bytes(runtime, count));
+  else if (copy_from_user_toio(my_buffer + frames_to_bytes(runtime, pos),
+   src, frames_to_bytes(runtime, count)))
+  return -EFAULT;
+  return 0;
 
-  my_memcpy(dst, my_buffer + frames_to_bytes(runtime, pos),
-frames_to_bytes(runtime, count));
+Here we prepared three different memory operations operations.
 
-Note that both the position and the amount of data are given in frames.
+The first one, with the NULL ``src`` pointer, is for silencing the
+buffer. In this case, we clear the samples 

[PATCH 08/16] ALSA: rme96: Convert to copy_silence ops

2017-05-21 Thread Takashi Iwai
Replace the copy and the silence ops with the new merged ops.
The conversion is straightforward with standard helper functions.

Signed-off-by: Takashi Iwai 
---
 sound/pci/rme96.c | 52 ++--
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c
index 05b9da30990d..2161f6aad532 100644
--- a/sound/pci/rme96.c
+++ b/sound/pci/rme96.c
@@ -326,31 +326,25 @@ snd_rme96_capture_ptr(struct rme96 *rme96)
 }
 
 static int
-snd_rme96_playback_silence(struct snd_pcm_substream *substream,
-  int channel, /* not used (interleaved data) */
-  snd_pcm_uframes_t pos,
-  snd_pcm_uframes_t count)
-{
-   struct rme96 *rme96 = snd_pcm_substream_chip(substream);
-   count <<= rme96->playback_frlog;
-   pos <<= rme96->playback_frlog;
-   memset_io(rme96->iobase + RME96_IO_PLAY_BUFFER + pos,
- 0, count);
-   return 0;
-}
-
-static int
 snd_rme96_playback_copy(struct snd_pcm_substream *substream,
int channel, /* not used (interleaved data) */
snd_pcm_uframes_t pos,
void __user *src,
-   snd_pcm_uframes_t count)
+   snd_pcm_uframes_t count,
+   bool in_kernel)
 {
struct rme96 *rme96 = snd_pcm_substream_chip(substream);
count <<= rme96->playback_frlog;
pos <<= rme96->playback_frlog;
-   return copy_from_user_toio(rme96->iobase + RME96_IO_PLAY_BUFFER + pos, 
src,
-  count);
+   if (!src)
+   memset_io(rme96->iobase + RME96_IO_PLAY_BUFFER + pos, 0, count);
+   else if (in_kernel)
+   memcpy_toio(rme96->iobase + RME96_IO_PLAY_BUFFER + pos,
+   (void *)src, count);
+   else if (copy_from_user_toio(rme96->iobase + RME96_IO_PLAY_BUFFER + pos,
+src, count))
+   return -EFAULT;
+   return 0;
 }
 
 static int
@@ -358,13 +352,21 @@ snd_rme96_capture_copy(struct snd_pcm_substream 
*substream,
   int channel, /* not used (interleaved data) */
   snd_pcm_uframes_t pos,
   void __user *dst,
-  snd_pcm_uframes_t count)
+  snd_pcm_uframes_t count,
+  bool in_kernel)
 {
struct rme96 *rme96 = snd_pcm_substream_chip(substream);
count <<= rme96->capture_frlog;
pos <<= rme96->capture_frlog;
-   return copy_to_user_fromio(dst, rme96->iobase + RME96_IO_REC_BUFFER + 
pos,
-  count);
+   if (in_kernel)
+   memcpy_fromio((void *)dst,
+ rme96->iobase + RME96_IO_REC_BUFFER + pos,
+ count);
+   else if (copy_to_user_fromio(dst,
+rme96->iobase + RME96_IO_REC_BUFFER + pos,
+count))
+   return -EFAULT;
+   return 0;
 }
 
 /*
@@ -1513,8 +1515,7 @@ static const struct snd_pcm_ops 
snd_rme96_playback_spdif_ops = {
.prepare =  snd_rme96_playback_prepare,
.trigger =  snd_rme96_playback_trigger,
.pointer =  snd_rme96_playback_pointer,
-   .copy = snd_rme96_playback_copy,
-   .silence =  snd_rme96_playback_silence,
+   .copy_silence = snd_rme96_playback_copy,
.mmap = snd_pcm_lib_mmap_iomem,
 };
 
@@ -1526,7 +1527,7 @@ static const struct snd_pcm_ops 
snd_rme96_capture_spdif_ops = {
.prepare =  snd_rme96_capture_prepare,
.trigger =  snd_rme96_capture_trigger,
.pointer =  snd_rme96_capture_pointer,
-   .copy = snd_rme96_capture_copy,
+   .copy_silence = snd_rme96_capture_copy,
.mmap = snd_pcm_lib_mmap_iomem,
 };
 
@@ -1538,8 +1539,7 @@ static const struct snd_pcm_ops 
snd_rme96_playback_adat_ops = {
.prepare =  snd_rme96_playback_prepare,
.trigger =  snd_rme96_playback_trigger,
.pointer =  snd_rme96_playback_pointer,
-   .copy = snd_rme96_playback_copy,
-   .silence =  snd_rme96_playback_silence,
+   .copy_silence = snd_rme96_playback_copy,
.mmap = snd_pcm_lib_mmap_iomem,
 };
 
@@ -1551,7 +1551,7 @@ static const struct snd_pcm_ops 
snd_rme96_capture_adat_ops = {
.prepare =  snd_rme96_capture_prepare,
.trigger =  snd_rme96_capture_trigger,
.pointer =  snd_rme96_capture_pointer,
-   .copy = snd_rme96_capture_copy,
+   .copy_silence = snd_rme96_capture_copy,
.mmap = snd_pcm_lib_mmap_iomem,
 };
 
-- 
2.13.0



[PATCH 06/16] ALSA: nm256: Convert to copy_silence ops

2017-05-21 Thread Takashi Iwai
Replace the copy and the silence ops with the new merged ops.
The conversion is straightforward with standard helper functions.

Signed-off-by: Takashi Iwai 
---
 sound/pci/nm256/nm256.c | 35 ++-
 1 file changed, 14 insertions(+), 21 deletions(-)

diff --git a/sound/pci/nm256/nm256.c b/sound/pci/nm256/nm256.c
index 103fe311e5a9..d8e765f7e758 100644
--- a/sound/pci/nm256/nm256.c
+++ b/sound/pci/nm256/nm256.c
@@ -694,31 +694,22 @@ snd_nm256_capture_pointer(struct snd_pcm_substream 
*substream)
  * silence / copy for playback
  */
 static int
-snd_nm256_playback_silence(struct snd_pcm_substream *substream,
-  int channel, /* not used (interleaved data) */
-  snd_pcm_uframes_t pos,
-  snd_pcm_uframes_t count)
-{
-   struct snd_pcm_runtime *runtime = substream->runtime;
-   struct nm256_stream *s = runtime->private_data;
-   count = frames_to_bytes(runtime, count);
-   pos = frames_to_bytes(runtime, pos);
-   memset_io(s->bufptr + pos, 0, count);
-   return 0;
-}
-
-static int
 snd_nm256_playback_copy(struct snd_pcm_substream *substream,
int channel, /* not used (interleaved data) */
snd_pcm_uframes_t pos,
void __user *src,
-   snd_pcm_uframes_t count)
+   snd_pcm_uframes_t count,
+   bool in_kernel)
 {
struct snd_pcm_runtime *runtime = substream->runtime;
struct nm256_stream *s = runtime->private_data;
count = frames_to_bytes(runtime, count);
pos = frames_to_bytes(runtime, pos);
-   if (copy_from_user_toio(s->bufptr + pos, src, count))
+   if (!src)
+   memset_io(s->bufptr + pos, 0, count);
+   else if (in_kernel)
+   memcpy_toio(s->bufptr + pos, (void *)src, count);
+   else if (copy_from_user_toio(s->bufptr + pos, src, count))
return -EFAULT;
return 0;
 }
@@ -731,13 +722,16 @@ snd_nm256_capture_copy(struct snd_pcm_substream 
*substream,
   int channel, /* not used (interleaved data) */
   snd_pcm_uframes_t pos,
   void __user *dst,
-  snd_pcm_uframes_t count)
+  snd_pcm_uframes_t count,
+  bool in_kernel)
 {
struct snd_pcm_runtime *runtime = substream->runtime;
struct nm256_stream *s = runtime->private_data;
count = frames_to_bytes(runtime, count);
pos = frames_to_bytes(runtime, pos);
-   if (copy_to_user_fromio(dst, s->bufptr + pos, count))
+   if (in_kernel)
+   memcpy_fromio((void *)dst, s->bufptr + pos, count);
+   else if (copy_to_user_fromio(dst, s->bufptr + pos, count))
return -EFAULT;
return 0;
 }
@@ -911,8 +905,7 @@ static const struct snd_pcm_ops snd_nm256_playback_ops = {
.trigger =  snd_nm256_playback_trigger,
.pointer =  snd_nm256_playback_pointer,
 #ifndef __i386__
-   .copy = snd_nm256_playback_copy,
-   .silence =  snd_nm256_playback_silence,
+   .copy_silence = snd_nm256_playback_copy,
 #endif
.mmap = snd_pcm_lib_mmap_iomem,
 };
@@ -926,7 +919,7 @@ static const struct snd_pcm_ops snd_nm256_capture_ops = {
.trigger =  snd_nm256_capture_trigger,
.pointer =  snd_nm256_capture_pointer,
 #ifndef __i386__
-   .copy = snd_nm256_capture_copy,
+   .copy_silence = snd_nm256_capture_copy,
 #endif
.mmap = snd_pcm_lib_mmap_iomem,
 };
-- 
2.13.0



[PATCH 09/16] ALSA: rme9652: Convert to copy_silence ops

2017-05-21 Thread Takashi Iwai
Replace the copy and the silence ops with the new merged ops.
The conversion is straightforward with standard helper functions.

Signed-off-by: Takashi Iwai 
---
 sound/pci/rme9652/rme9652.c | 46 -
 1 file changed, 20 insertions(+), 26 deletions(-)

diff --git a/sound/pci/rme9652/rme9652.c b/sound/pci/rme9652/rme9652.c
index 55172c689991..ce9faa32c7ed 100644
--- a/sound/pci/rme9652/rme9652.c
+++ b/sound/pci/rme9652/rme9652.c
@@ -1883,8 +1883,10 @@ static char *rme9652_channel_buffer_location(struct 
snd_rme9652 *rme9652,
}
 }
 
-static int snd_rme9652_playback_copy(struct snd_pcm_substream *substream, int 
channel,
-snd_pcm_uframes_t pos, void __user *src, 
snd_pcm_uframes_t count)
+static int snd_rme9652_playback_copy(struct snd_pcm_substream *substream,
+int channel, snd_pcm_uframes_t pos,
+void __user *src, snd_pcm_uframes_t count,
+bool in_kernel)
 {
struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream);
char *channel_buf;
@@ -1897,13 +1899,19 @@ static int snd_rme9652_playback_copy(struct 
snd_pcm_substream *substream, int ch
   channel);
if (snd_BUG_ON(!channel_buf))
return -EIO;
-   if (copy_from_user(channel_buf + pos * 4, src, count * 4))
+   if (!src)
+   memset(channel_buf + pos * 4, 0, count * 4);
+   else if (in_kernel)
+   memcpy(channel_buf + pos * 4, (void *)src, count * 4);
+   else if (copy_from_user(channel_buf + pos * 4, src, count * 4))
return -EFAULT;
-   return count;
+   return 0;
 }
 
-static int snd_rme9652_capture_copy(struct snd_pcm_substream *substream, int 
channel,
-   snd_pcm_uframes_t pos, void __user *dst, 
snd_pcm_uframes_t count)
+static int snd_rme9652_capture_copy(struct snd_pcm_substream *substream,
+   int channel, snd_pcm_uframes_t pos,
+   void __user *dst, snd_pcm_uframes_t count,
+   bool in_kernel)
 {
struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream);
char *channel_buf;
@@ -1916,24 +1924,11 @@ static int snd_rme9652_capture_copy(struct 
snd_pcm_substream *substream, int cha
   channel);
if (snd_BUG_ON(!channel_buf))
return -EIO;
-   if (copy_to_user(dst, channel_buf + pos * 4, count * 4))
+   if (in_kernel)
+   memcpy((void *)dst, channel_buf + pos * 4, count * 4);
+   else if (copy_to_user(dst, channel_buf + pos * 4, count * 4))
return -EFAULT;
-   return count;
-}
-
-static int snd_rme9652_hw_silence(struct snd_pcm_substream *substream, int 
channel,
- snd_pcm_uframes_t pos, snd_pcm_uframes_t 
count)
-{
-   struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream);
-   char *channel_buf;
-
-   channel_buf = rme9652_channel_buffer_location (rme9652,
-  substream->pstr->stream,
-  channel);
-   if (snd_BUG_ON(!channel_buf))
-   return -EIO;
-   memset(channel_buf + pos * 4, 0, count * 4);
-   return count;
+   return 0;
 }
 
 static int snd_rme9652_reset(struct snd_pcm_substream *substream)
@@ -2376,8 +2371,7 @@ static const struct snd_pcm_ops snd_rme9652_playback_ops 
= {
.prepare =  snd_rme9652_prepare,
.trigger =  snd_rme9652_trigger,
.pointer =  snd_rme9652_hw_pointer,
-   .copy = snd_rme9652_playback_copy,
-   .silence =  snd_rme9652_hw_silence,
+   .copy_silence = snd_rme9652_playback_copy,
 };
 
 static const struct snd_pcm_ops snd_rme9652_capture_ops = {
@@ -2388,7 +2382,7 @@ static const struct snd_pcm_ops snd_rme9652_capture_ops = 
{
.prepare =  snd_rme9652_prepare,
.trigger =  snd_rme9652_trigger,
.pointer =  snd_rme9652_hw_pointer,
-   .copy = snd_rme9652_capture_copy,
+   .copy_silence = snd_rme9652_capture_copy,
 };
 
 static int snd_rme9652_create_pcm(struct snd_card *card,
-- 
2.13.0



[PATCH 05/16] ALSA: korg1212: Convert to copy_silence ops

2017-05-21 Thread Takashi Iwai
Replace the copy and the silence ops with the new merged ops.
The redundant function calls are reduced and the copy/silence are
handled directly in callback functions now.

Signed-off-by: Takashi Iwai 
---
 sound/pci/korg1212/korg1212.c | 128 --
 1 file changed, 36 insertions(+), 92 deletions(-)

diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c
index 1e25095fd144..865ff553dc87 100644
--- a/sound/pci/korg1212/korg1212.c
+++ b/sound/pci/korg1212/korg1212.c
@@ -1273,43 +1273,24 @@ static struct snd_pcm_hardware 
snd_korg1212_capture_info =
 .fifo_size =  0,
 };
 
-static int snd_korg1212_silence(struct snd_korg1212 *korg1212, int pos, int 
count, int offset, int size)
-{
-   struct KorgAudioFrame * dst =  korg1212->playDataBufsPtr[0].bufferData 
+ pos;
-   int i;
-
-   K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_silence pos=%d 
offset=%d size=%d count=%d\n",
-  pos, offset, size, count);
-   if (snd_BUG_ON(pos + count > K1212_MAX_SAMPLES))
-   return -EINVAL;
-
-   for (i=0; i < count; i++) {
-#if K1212_DEBUG_LEVEL > 0
-   if ( (void *) dst < (void *) korg1212->playDataBufsPtr ||
-(void *) dst > (void *) 
korg1212->playDataBufsPtr[8].bufferData ) {
-   printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_silence 
KERNEL EFAULT dst=%p iter=%d\n",
-  dst, i);
-   return -EFAULT;
-   }
-#endif
-   memset((void*) dst + offset, 0, size);
-   dst++;
-   }
-
-   return 0;
-}
-
-static int snd_korg1212_copy_to(struct snd_korg1212 *korg1212, void __user 
*dst, int pos, int count, int offset, int size)
+static int snd_korg1212_capture_copy(struct snd_pcm_substream *substream,
+int channel,
+snd_pcm_uframes_t pos,
+void __user *dst,
+snd_pcm_uframes_t count,
+bool in_kernel)
 {
+   struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream);
struct KorgAudioFrame * src =  
korg1212->recordDataBufsPtr[0].bufferData + pos;
-   int i, rc;
+   int size, i;
 
-   K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_to pos=%d 
offset=%d size=%d\n",
-  pos, offset, size);
+   size = korg1212->channels * 2;
+   K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_to pos=%ld 
size=%d\n",
+  pos, size);
if (snd_BUG_ON(pos + count > K1212_MAX_SAMPLES))
return -EINVAL;
 
-   for (i=0; i < count; i++) {
+   for (i = 0; i < count; i++) {
 #if K1212_DEBUG_LEVEL > 0
if ( (void *) src < (void *) korg1212->recordDataBufsPtr ||
 (void *) src > (void *) 
korg1212->recordDataBufsPtr[8].bufferData ) {
@@ -1317,11 +1298,10 @@ static int snd_korg1212_copy_to(struct snd_korg1212 
*korg1212, void __user *dst,
return -EFAULT;
}
 #endif
-   rc = copy_to_user(dst + offset, src, size);
-   if (rc) {
-   K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_to 
USER EFAULT src=%p dst=%p iter=%d\n", src, dst, i);
+   if (in_kernel)
+   memcpy((char *)dst, src, size);
+   else if (copy_to_user(dst, src, size))
return -EFAULT;
-   }
src++;
dst += size;
}
@@ -1329,18 +1309,25 @@ static int snd_korg1212_copy_to(struct snd_korg1212 
*korg1212, void __user *dst,
return 0;
 }
 
-static int snd_korg1212_copy_from(struct snd_korg1212 *korg1212, void __user 
*src, int pos, int count, int offset, int size)
+static int snd_korg1212_playback_copy(struct snd_pcm_substream *substream,
+ int channel,
+ snd_pcm_uframes_t pos,
+ void __user *src,
+ snd_pcm_uframes_t count,
+ bool in_kernel)
 {
+   struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream);
struct KorgAudioFrame * dst =  korg1212->playDataBufsPtr[0].bufferData 
+ pos;
-   int i, rc;
+   int size, i;
 
-   K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_from pos=%d 
offset=%d size=%d count=%d\n",
-  pos, offset, size, count);
+   size = korg1212->channels * 2;
+   K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_from pos=%ld 
size=%d count=%ld\n",
+  pos, size, count);
 
if (snd_BUG_ON(pos + count > K1212_MAX_SAMPLES))

[PATCH 11/16] ALSA: gus: Convert to copy_silence ops

2017-05-21 Thread Takashi Iwai
Replace the copy and the silence ops with the new merged ops.
The conversion is straightforward with standard helper functions.

Signed-off-by: Takashi Iwai 
---
 sound/isa/gus/gus_pcm.c | 43 +--
 1 file changed, 9 insertions(+), 34 deletions(-)

diff --git a/sound/isa/gus/gus_pcm.c b/sound/isa/gus/gus_pcm.c
index 33c1891f469a..c541370d3d76 100644
--- a/sound/isa/gus/gus_pcm.c
+++ b/sound/isa/gus/gus_pcm.c
@@ -359,7 +359,8 @@ static int snd_gf1_pcm_playback_copy(struct 
snd_pcm_substream *substream,
 int voice,
 snd_pcm_uframes_t pos,
 void __user *src,
-snd_pcm_uframes_t count)
+snd_pcm_uframes_t count,
+bool in_kernel)
 {
struct snd_pcm_runtime *runtime = substream->runtime;
struct gus_pcm_private *pcmp = runtime->private_data;
@@ -371,7 +372,12 @@ static int snd_gf1_pcm_playback_copy(struct 
snd_pcm_substream *substream,
return -EIO;
if (snd_BUG_ON(bpos + len > pcmp->dma_size))
return -EIO;
-   if (copy_from_user(runtime->dma_area + bpos, src, len))
+   if (!src)
+   snd_pcm_format_set_silence(runtime->format,
+  runtime->dma_area + bpos, count);
+   else if (in_kernel)
+   memcpy(runtime->dma_area + bpos, (void *)src, len);
+   else if (copy_from_user(runtime->dma_area + bpos, src, len))
return -EFAULT;
if (snd_gf1_pcm_use_dma && len > 32) {
return snd_gf1_pcm_block_change(substream, bpos, pcmp->memory + 
bpos, len);
@@ -387,36 +393,6 @@ static int snd_gf1_pcm_playback_copy(struct 
snd_pcm_substream *substream,
return 0;
 }
 
-static int snd_gf1_pcm_playback_silence(struct snd_pcm_substream *substream,
-   int voice,
-   snd_pcm_uframes_t pos,
-   snd_pcm_uframes_t count)
-{
-   struct snd_pcm_runtime *runtime = substream->runtime;
-   struct gus_pcm_private *pcmp = runtime->private_data;
-   unsigned int bpos, len;
-   
-   bpos = samples_to_bytes(runtime, pos) + (voice * (pcmp->dma_size / 2));
-   len = samples_to_bytes(runtime, count);
-   if (snd_BUG_ON(bpos > pcmp->dma_size))
-   return -EIO;
-   if (snd_BUG_ON(bpos + len > pcmp->dma_size))
-   return -EIO;
-   snd_pcm_format_set_silence(runtime->format, runtime->dma_area + bpos, 
count);
-   if (snd_gf1_pcm_use_dma && len > 32) {
-   return snd_gf1_pcm_block_change(substream, bpos, pcmp->memory + 
bpos, len);
-   } else {
-   struct snd_gus_card *gus = pcmp->gus;
-   int err, w16, invert;
-
-   w16 = (snd_pcm_format_width(runtime->format) == 16);
-   invert = snd_pcm_format_unsigned(runtime->format);
-   if ((err = snd_gf1_pcm_poke_block(gus, runtime->dma_area + 
bpos, pcmp->memory + bpos, len, w16, invert)) < 0)
-   return err;
-   }
-   return 0;
-}
-
 static int snd_gf1_pcm_playback_hw_params(struct snd_pcm_substream *substream,
  struct snd_pcm_hw_params *hw_params)
 {
@@ -836,8 +812,7 @@ static struct snd_pcm_ops snd_gf1_pcm_playback_ops = {
.prepare =  snd_gf1_pcm_playback_prepare,
.trigger =  snd_gf1_pcm_playback_trigger,
.pointer =  snd_gf1_pcm_playback_pointer,
-   .copy = snd_gf1_pcm_playback_copy,
-   .silence =  snd_gf1_pcm_playback_silence,
+   .copy_silence = snd_gf1_pcm_playback_copy,
 };
 
 static struct snd_pcm_ops snd_gf1_pcm_capture_ops = {
-- 
2.13.0



[PATCH 13/16] ALSA: sh: Convert to copy_silence ops

2017-05-21 Thread Takashi Iwai
Replace the copy and the silence ops with the new merged ops.
A straightforward conversion with standard helper functions.

Signed-off-by: Takashi Iwai 
---
 sound/sh/sh_dac_audio.c | 40 +---
 1 file changed, 9 insertions(+), 31 deletions(-)

diff --git a/sound/sh/sh_dac_audio.c b/sound/sh/sh_dac_audio.c
index 461b310c7872..a4014a4548d0 100644
--- a/sound/sh/sh_dac_audio.c
+++ b/sound/sh/sh_dac_audio.c
@@ -185,7 +185,8 @@ static int snd_sh_dac_pcm_trigger(struct snd_pcm_substream 
*substream, int cmd)
 }
 
 static int snd_sh_dac_pcm_copy(struct snd_pcm_substream *substream, int 
channel,
-   snd_pcm_uframes_t pos, void __user *src, snd_pcm_uframes_t count)
+  snd_pcm_uframes_t pos, void __user *src,
+  snd_pcm_uframes_t count, bool in_kernel)
 {
/* channel is not used (interleaved data) */
struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
@@ -199,34 +200,12 @@ static int snd_sh_dac_pcm_copy(struct snd_pcm_substream 
*substream, int channel,
if (!count)
return 0;
 
-   memcpy_toio(chip->data_buffer + b_pos, src, b_count);
-   chip->buffer_end = chip->data_buffer + b_pos + b_count;
-
-   if (chip->empty) {
-   chip->empty = 0;
-   dac_audio_start_timer(chip);
-   }
-
-   return 0;
-}
-
-static int snd_sh_dac_pcm_silence(struct snd_pcm_substream *substream,
- int channel, snd_pcm_uframes_t pos,
- snd_pcm_uframes_t count)
-{
-   /* channel is not used (interleaved data) */
-   struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
-   struct snd_pcm_runtime *runtime = substream->runtime;
-   ssize_t b_count = frames_to_bytes(runtime , count);
-   ssize_t b_pos = frames_to_bytes(runtime , pos);
-
-   if (count < 0)
-   return -EINVAL;
-
-   if (!count)
-   return 0;
-
-   memset_io(chip->data_buffer + b_pos, 0, b_count);
+   if (!src)
+   memset_io(chip->data_buffer + b_pos, 0, b_count);
+   else if (in_kernel)
+   memcpy_toio(chip->data_buffer + b_pos, (void *)src, b_count);
+   else if (copy_from_user_toio(chip->data_buffer + b_pos, src, b_count))
+   return -EFAULT;
chip->buffer_end = chip->data_buffer + b_pos + b_count;
 
if (chip->empty) {
@@ -256,8 +235,7 @@ static struct snd_pcm_ops snd_sh_dac_pcm_ops = {
.prepare= snd_sh_dac_pcm_prepare,
.trigger= snd_sh_dac_pcm_trigger,
.pointer= snd_sh_dac_pcm_pointer,
-   .copy   = snd_sh_dac_pcm_copy,
-   .silence= snd_sh_dac_pcm_silence,
+   .copy_silence   = snd_sh_dac_pcm_copy,
.mmap   = snd_pcm_lib_mmap_iomem,
 };
 
-- 
2.13.0



[PATCH 07/16] ALSA: rme32: Convert to copy_silence ops

2017-05-21 Thread Takashi Iwai
Replace the copy and the silence ops with the new merged ops.
The conversion is straightforward with standard helper functions.

Signed-off-by: Takashi Iwai 
---
 sound/pci/rme32.c | 49 -
 1 file changed, 24 insertions(+), 25 deletions(-)

diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c
index 96d15db65dfd..d2b4a3ef0bd3 100644
--- a/sound/pci/rme32.c
+++ b/sound/pci/rme32.c
@@ -253,41 +253,42 @@ static inline unsigned int snd_rme32_pcm_byteptr(struct 
rme32 * rme32)
& RME32_RCR_AUDIO_ADDR_MASK);
 }
 
-/* silence callback for halfduplex mode */
-static int snd_rme32_playback_silence(struct snd_pcm_substream *substream, int 
channel,/* not used (interleaved data) */
- snd_pcm_uframes_t pos,
- snd_pcm_uframes_t count)
-{
-   struct rme32 *rme32 = snd_pcm_substream_chip(substream);
-   count <<= rme32->playback_frlog;
-   pos <<= rme32->playback_frlog;
-   memset_io(rme32->iobase + RME32_IO_DATA_BUFFER + pos, 0, count);
-   return 0;
-}
-
 /* copy callback for halfduplex mode */
-static int snd_rme32_playback_copy(struct snd_pcm_substream *substream, int 
channel,   /* not used (interleaved data) */
+static int snd_rme32_playback_copy(struct snd_pcm_substream *substream,
+  int channel, /* not used (interleaved data) 
*/
   snd_pcm_uframes_t pos,
-  void __user *src, snd_pcm_uframes_t count)
+  void __user *src, snd_pcm_uframes_t count,
+  bool in_kernel)
 {
struct rme32 *rme32 = snd_pcm_substream_chip(substream);
count <<= rme32->playback_frlog;
pos <<= rme32->playback_frlog;
-   if (copy_from_user_toio(rme32->iobase + RME32_IO_DATA_BUFFER + pos,
-   src, count))
+   if (!src)
+   memset_io(rme32->iobase + RME32_IO_DATA_BUFFER + pos, 0, count);
+   else if (in_kernel)
+   memcpy_toio(rme32->iobase + RME32_IO_DATA_BUFFER + pos,
+   (void *)src, count);
+   else if (copy_from_user_toio(rme32->iobase + RME32_IO_DATA_BUFFER + pos,
+src, count))
return -EFAULT;
return 0;
 }
 
 /* copy callback for halfduplex mode */
-static int snd_rme32_capture_copy(struct snd_pcm_substream *substream, int 
channel,/* not used (interleaved data) */
+static int snd_rme32_capture_copy(struct snd_pcm_substream *substream,
+ int channel,  /* not used (interleaved data) 
*/
  snd_pcm_uframes_t pos,
- void __user *dst, snd_pcm_uframes_t count)
+ void __user *dst, snd_pcm_uframes_t count,
+ bool in_kernel)
 {
struct rme32 *rme32 = snd_pcm_substream_chip(substream);
count <<= rme32->capture_frlog;
pos <<= rme32->capture_frlog;
-   if (copy_to_user_fromio(dst,
+   if (in_kernel)
+   memcpy_fromio((void *)dst,
+ rme32->iobase + RME32_IO_DATA_BUFFER + pos,
+ count);
+   else if (copy_to_user_fromio(dst,
rme32->iobase + RME32_IO_DATA_BUFFER + pos,
count))
return -EFAULT;
@@ -1205,8 +1206,7 @@ static const struct snd_pcm_ops 
snd_rme32_playback_spdif_ops = {
.prepare =  snd_rme32_playback_prepare,
.trigger =  snd_rme32_pcm_trigger,
.pointer =  snd_rme32_playback_pointer,
-   .copy = snd_rme32_playback_copy,
-   .silence =  snd_rme32_playback_silence,
+   .copy_silence = snd_rme32_playback_copy,
.mmap = snd_pcm_lib_mmap_iomem,
 };
 
@@ -1219,7 +1219,7 @@ static const struct snd_pcm_ops 
snd_rme32_capture_spdif_ops = {
.prepare =  snd_rme32_capture_prepare,
.trigger =  snd_rme32_pcm_trigger,
.pointer =  snd_rme32_capture_pointer,
-   .copy = snd_rme32_capture_copy,
+   .copy_silence = snd_rme32_capture_copy,
.mmap = snd_pcm_lib_mmap_iomem,
 };
 
@@ -1231,8 +1231,7 @@ static const struct snd_pcm_ops 
snd_rme32_playback_adat_ops = {
.prepare =  snd_rme32_playback_prepare,
.trigger =  snd_rme32_pcm_trigger,
.pointer =  snd_rme32_playback_pointer,
-   .copy = snd_rme32_playback_copy,
-   .silence =  snd_rme32_playback_silence,
+   .copy_silence = snd_rme32_playback_copy,
.mmap = snd_pcm_lib_mmap_iomem,
 };
 
@@ -1244,7 +1243,7 @@ static const struct snd_pcm_ops 
snd_rme32_capture_adat_ops = {
.prepare =  snd_rme32_capture_prepare,
.trigger =  snd_rme32_pcm_trigger,
   

[PATCH 03/16] ALSA: dummy: Convert to copy_silence ops

2017-05-21 Thread Takashi Iwai
It's a dummy ops, so just replacing it.

Signed-off-by: Takashi Iwai 
---
 sound/drivers/dummy.c | 13 +++--
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
index 172dacd925f5..68519689a9ea 100644
--- a/sound/drivers/dummy.c
+++ b/sound/drivers/dummy.c
@@ -645,14 +645,8 @@ static int alloc_fake_buffer(void)
 
 static int dummy_pcm_copy(struct snd_pcm_substream *substream,
  int channel, snd_pcm_uframes_t pos,
- void __user *dst, snd_pcm_uframes_t count)
-{
-   return 0; /* do nothing */
-}
-
-static int dummy_pcm_silence(struct snd_pcm_substream *substream,
-int channel, snd_pcm_uframes_t pos,
-snd_pcm_uframes_t count)
+ void __user *dst, snd_pcm_uframes_t count,
+ bool in_kernel)
 {
return 0; /* do nothing */
 }
@@ -683,8 +677,7 @@ static struct snd_pcm_ops dummy_pcm_ops_no_buf = {
.prepare =  dummy_pcm_prepare,
.trigger =  dummy_pcm_trigger,
.pointer =  dummy_pcm_pointer,
-   .copy = dummy_pcm_copy,
-   .silence =  dummy_pcm_silence,
+   .copy_silence = dummy_pcm_copy,
.page = dummy_pcm_page,
 };
 
-- 
2.13.0



[PATCH 00/16] ALSA: Convert to new copy_silence PCM ops

2017-05-21 Thread Takashi Iwai
Hi,

this is a part of the previous RFC patchset, and it's preliminary for
eliminating set_fs() usages in the rest ALSA codes.  This patchset
itself converts the existing copy and silence PCM ops to a new single
copy_silence ops.  The new callback takes in_kernel flag for allowing
in-kernel buffer copy, so that the PCM drivers can pass the buffer in
kernel-space later directly without set_fs() hackery.

The latest codes are found in topic/kill-set_fs branch of sound git
tree.

The media people are Cc'ed for solo6x10 changes.


Takashi

===

Takashi Iwai (16):
  ALSA: pcm: Introduce copy_silence PCM ops
  ALSA: Update document about copy_silence PCM ops
  ALSA: dummy: Convert to copy_silence ops
  ALSA: es1938: Convert to copy_silence ops
  ALSA: korg1212: Convert to copy_silence ops
  ALSA: nm256: Convert to copy_silence ops
  ALSA: rme32: Convert to copy_silence ops
  ALSA: rme96: Convert to copy_silence ops
  ALSA: rme9652: Convert to copy_silence ops
  ALSA: hdsp: Convert to copy_silence ops
  ALSA: gus: Convert to copy_silence ops
  ALSA: sb: Convert to copy_silence ops
  ALSA: sh: Convert to copy_silence ops
  ASoC: blackfin: Convert to copy_silence ops
  [media] solo6x10: Convert to copy_silence ops
  ALSA: pcm: Drop the old copy and silence ops

 .../sound/kernel-api/writing-an-alsa-driver.rst| 110 ++
 drivers/media/pci/solo6x10/solo6x10-g723.c |  13 ++-
 include/sound/pcm.h|   8 +-
 sound/core/pcm_lib.c   |  68 ++-
 sound/drivers/dummy.c  |  13 +--
 sound/isa/gus/gus_pcm.c|  43 ++-
 sound/isa/sb/emu8000_pcm.c |  99 +---
 sound/pci/es1938.c |  11 +-
 sound/pci/korg1212/korg1212.c  | 128 ++---
 sound/pci/nm256/nm256.c|  35 +++---
 sound/pci/rme32.c  |  49 
 sound/pci/rme96.c  |  52 -
 sound/pci/rme9652/hdsp.c   |  44 ---
 sound/pci/rme9652/rme9652.c|  46 
 sound/sh/sh_dac_audio.c|  40 ++-
 sound/soc/blackfin/bf5xx-ac97-pcm.c|   6 +-
 sound/soc/blackfin/bf5xx-ac97.c|  18 ++-
 sound/soc/blackfin/bf5xx-i2s-pcm.c |  46 +++-
 sound/soc/soc-pcm.c|   3 +-
 19 files changed, 340 insertions(+), 492 deletions(-)

-- 
2.13.0



Working with you | 2m

2017-05-21 Thread VS - .52
Hello and good day.

I am looking to work with a reputable individual/firm to engage in a profit 
oriented ventures in your country and perhaps with your assistance, we could 
get low tax rates.

I have the directive of Mr. Mikhail Khodorkovsky to source for partner abroad 
who can accommodate and manage 150M & 350M USD respectively. The sums are 
derived from an executed project with Yukos Oil Company before the company was 
change merged into Rosneft Oil Corporation in Russia.

We shall apply for the necessary paper work required to re-profile your name as 
the receipient and also ensure payment is carried out by Rosneft into a bank 
account in your name. I guaranty we would execute this business under a 
legitimate arrangement without breach of the law.

Further details will follow upon your positive reply.

Regards,

Vladimir Stankov.

--
This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.


[patch, libv4l]: add sdlcam example for testing digital still camera functionality

2017-05-21 Thread Pavel Machek
Add simple SDL-based application for capturing photos. Manual
focus/gain/exposure can be set, flash can be controlled and
autofocus/autogain can be selected if camera supports that.

It is already useful for testing autofocus/autogain improvements to
the libraries on Nokia N900.

Signed-off-by: Pavel Machek 

diff --git a/configure.ac b/configure.ac
index f30d66d..2c8ad7e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -88,6 +88,247 @@ LIBDVBV5_DOMAIN="libdvbv5"
 AC_DEFINE([LIBDVBV5_DOMAIN], "libdvbv5", [libdvbv5 domain])
 AC_SUBST(LIBDVBV5_DOMAIN)
 
+# Configure paths for SDL
+# Sam Lantinga 9/21/99
+# stolen from Manish Singh
+# stolen back from Frank Belew
+# stolen from Manish Singh
+# Shamelessly stolen from Owen Taylor
+#
+# Changelog:
+# * also look for SDL2.framework under Mac OS X
+
+# serial 1
+
+dnl AM_PATH_SDL2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
+dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
+dnl
+AC_DEFUN([AM_PATH_SDL2],
+[dnl 
+dnl Get the cflags and libraries from the sdl2-config script
+dnl
+AC_ARG_WITH(sdl-prefix,[  --with-sdl-prefix=PFX   Prefix where SDL is 
installed (optional)],
+sdl_prefix="$withval", sdl_prefix="")
+AC_ARG_WITH(sdl-exec-prefix,[  --with-sdl-exec-prefix=PFX Exec prefix where 
SDL is installed (optional)],
+sdl_exec_prefix="$withval", sdl_exec_prefix="")
+AC_ARG_ENABLE(sdltest, [  --disable-sdltest   Do not try to compile and 
run a test SDL program],
+   , enable_sdltest=yes)
+AC_ARG_ENABLE(sdlframework, [  --disable-sdlframework Do not search for 
SDL2.framework],
+, search_sdl_framework=yes)
+
+AC_ARG_VAR(SDL2_FRAMEWORK, [Path to SDL2.framework])
+
+  min_sdl_version=ifelse([$1], ,2.0.0,$1)
+
+  if test "x$sdl_prefix$sdl_exec_prefix" = x ; then
+PKG_CHECK_MODULES([SDL], [sdl2 >= $min_sdl_version],
+   [sdl_pc=yes],
+   [sdl_pc=no])
+  else
+sdl_pc=no
+if test x$sdl_exec_prefix != x ; then
+  sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix"
+  if test x${SDL2_CONFIG+set} != xset ; then
+SDL2_CONFIG=$sdl_exec_prefix/bin/sdl2-config
+  fi
+fi
+if test x$sdl_prefix != x ; then
+  sdl_config_args="$sdl_config_args --prefix=$sdl_prefix"
+  if test x${SDL2_CONFIG+set} != xset ; then
+SDL2_CONFIG=$sdl_prefix/bin/sdl2-config
+  fi
+fi
+  fi
+
+  if test "x$sdl_pc" = xyes ; then
+no_sdl=""
+SDL2_CONFIG="pkg-config sdl2"
+  else
+as_save_PATH="$PATH"
+if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
+  PATH="$prefix/bin:$prefix/usr/bin:$PATH"
+fi
+AC_PATH_PROG(SDL2_CONFIG, sdl2-config, no, [$PATH])
+PATH="$as_save_PATH"
+no_sdl=""
+
+if test "$SDL2_CONFIG" = "no" -a "x$search_sdl_framework" = "xyes"; then
+  AC_MSG_CHECKING(for SDL2.framework)
+  if test "x$SDL2_FRAMEWORK" != x; then
+sdl_framework=$SDL2_FRAMEWORK
+  else
+for d in / ~/ /System/; do
+  if test -d "$dLibrary/Frameworks/SDL2.framework"; then
+sdl_framework="$dLibrary/Frameworks/SDL2.framework"
+  fi
+done
+  fi
+
+  if test -d $sdl_framework; then
+AC_MSG_RESULT($sdl_framework)
+sdl_framework_dir=`dirname $sdl_framework`
+SDL_CFLAGS="-F$sdl_framework_dir -Wl,-framework,SDL2 
-I$sdl_framework/include"
+SDL_LIBS="-F$sdl_framework_dir -Wl,-framework,SDL2"
+  else
+no_sdl=yes
+  fi
+fi
+
+if test "$SDL2_CONFIG" != "no"; then
+  if test "x$sdl_pc" = "xno"; then
+AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
+SDL_CFLAGS=`$SDL2_CONFIG $sdl_config_args --cflags`
+SDL_LIBS=`$SDL2_CONFIG $sdl_config_args --libs`
+  fi
+
+  sdl_major_version=`$SDL2_CONFIG $sdl_config_args --version | \
+ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
+  sdl_minor_version=`$SDL2_CONFIG $sdl_config_args --version | \
+ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
+  sdl_micro_version=`$SDL2_CONFIG $sdl_config_args --version | \
+ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
+  if test "x$enable_sdltest" = "xyes" ; then
+ac_save_CFLAGS="$CFLAGS"
+ac_save_CXXFLAGS="$CXXFLAGS"
+ac_save_LIBS="$LIBS"
+CFLAGS="$CFLAGS $SDL_CFLAGS"
+CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
+LIBS="$LIBS $SDL_LIBS"
+dnl
+dnl Now check if the installed SDL is sufficiently new. (Also sanity
+dnl checks the results of sdl2-config to some extent
+dnl
+  rm -f conf.sdltest
+  AC_TRY_RUN([
+#include 
+#include 
+#include 
+#include "SDL.h"
+
+char*
+my_strdup (char *str)
+{
+  char *new_str;
+  
+  if (str)
+{
+  new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
+  strcpy (new_str, str);
+}
+  else
+new_str = NULL;
+  
+  return new_str;
+}
+
+int main (int argc, char *argv[])
+{
+  int major, minor, micro;

Re: [PATCH 03/16] lirc_dev: correct error handling

2017-05-21 Thread Sean Young
On Mon, May 01, 2017 at 06:03:51PM +0200, David Härdeman wrote:
> If an error is generated, nonseekable_open() shouldn't be called.

There is no harm in calling nonseekable_open(), so this commit is
misleading.

Sean

> 
> Signed-off-by: David Härdeman 
> ---
>  drivers/media/rc/lirc_dev.c |6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c
> index 05f600bd6c67..7f13ed479e1c 100644
> --- a/drivers/media/rc/lirc_dev.c
> +++ b/drivers/media/rc/lirc_dev.c
> @@ -431,7 +431,7 @@ EXPORT_SYMBOL(lirc_unregister_driver);
>  int lirc_dev_fop_open(struct inode *inode, struct file *file)
>  {
>   struct irctl *ir;
> - int retval = 0;
> + int retval;
>  
>   if (iminor(inode) >= MAX_IRCTL_DEVICES) {
>   pr_err("open result for %d is -ENODEV\n", iminor(inode));
> @@ -475,9 +475,11 @@ int lirc_dev_fop_open(struct inode *inode, struct file 
> *file)
>  
>   ir->open++;
>  
> -error:
>   nonseekable_open(inode, file);
>  
> + return 0;
> +
> +error:
>   return retval;
>  }
>  EXPORT_SYMBOL(lirc_dev_fop_open);


Re: [PATCH] rc-core: cleanup rc_register_device (v2)

2017-05-21 Thread Sean Young
On Sun, May 21, 2017 at 08:45:09AM +0200, David Härdeman wrote:
> On Sat, May 20, 2017 at 12:10:40PM +0100, Sean Young wrote:
> >On Wed, May 03, 2017 at 12:04:00PM +0200, David Härdeman wrote:
> >> The device core infrastructure is based on the presumption that
> >> once a driver calls device_add(), it must be ready to accept
> >> userspace interaction.
> >> 
> >> This requires splitting rc_setup_rx_device() into two functions
> >> and reorganizing rc_register_device() so that as much work
> >> as possible is performed before calling device_add().
> >> 
> >> Version 2: switch the order in which rc_prepare_rx_device() and
> >> ir_raw_event_prepare() gets called so that dev->change_protocol()
> >> gets called before device_add().
> >
> >With this patch applied, when I plug in an iguanair usb device, I get.
> 
> I'm not surprised that changes to rc_register_device() might require
> some driver-specific fixes as well.

No, it means that if any driver generates IR early enough after
rc_register_device(), you will get this.

> I haven't looked at this yet, and I'm going on vacation in a few hours,
> so I'll probably take a look in a week...

I'm currently testing and reviewing all the pending rc patches for v4.13,
if I have time left I might fix it up.

Thanks
Sean


Re: [PATCH 14/16] lirc_dev: cleanup includes

2017-05-21 Thread David Härdeman
On Fri, May 19, 2017 at 07:21:23PM +0100, Sean Young wrote:
>On Mon, May 01, 2017 at 06:04:47PM +0200, David Härdeman wrote:
>> Remove superfluous includes and defines.
>> 
>> Signed-off-by: David Härdeman 
>> ---
>>  drivers/media/rc/lirc_dev.c |   12 +---
>>  1 file changed, 1 insertion(+), 11 deletions(-)
>> 
>> diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c
>> index 7db7d4c57991..4ba6c7e2d41b 100644
>> --- a/drivers/media/rc/lirc_dev.c
>> +++ b/drivers/media/rc/lirc_dev.c
>> @@ -15,20 +15,11 @@
>>   *
>>   */
>>  
>> -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>> -
>>  #include 
>> -#include 
>>  #include 
>> -#include 
>>  #include 
>> -#include 
>>  #include 
>> -#include 
>>  #include 
>> -#include 
>> -#include 
>> -#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -37,7 +28,6 @@
>>  #include 
>>  #include 
>>  
>> -#define IRCTL_DEV_NAME  "BaseRemoteCtl"
>>  #define LOGHEAD "lirc_dev (%s[%d]): "
>>  
>>  static dev_t lirc_base_dev;
>> @@ -545,7 +535,7 @@ static int __init lirc_dev_init(void)
>>  }
>>  
>>  retval = alloc_chrdev_region(_base_dev, 0, LIRC_MAX_DEVICES,
>> - IRCTL_DEV_NAME);
>> + "BaseRemoteCtl");
>
>This has always surprised/annoyed me. Why is this called BaseRemoteCtl? As
>far as I know, this is only used for /proc/devices, where it says:
>
>$ grep 239 /proc/devices 
>239 BaseRemoteCtl
>
>And not lirc, as you would expect.

Yeah, I also find it a bit of an ugly wart. I didn't dare to change it
though since userspace might rely on "BaseRemoteCtl". For example:
https://build.opensuse.org/package/view_file/openSUSE:12.2/lirc/rc.lirc?expand=1)

-- 
David Härdeman


Re: [PATCH] rc-core: cleanup rc_register_device (v2)

2017-05-21 Thread David Härdeman
On Sat, May 20, 2017 at 12:10:40PM +0100, Sean Young wrote:
>On Wed, May 03, 2017 at 12:04:00PM +0200, David Härdeman wrote:
>> The device core infrastructure is based on the presumption that
>> once a driver calls device_add(), it must be ready to accept
>> userspace interaction.
>> 
>> This requires splitting rc_setup_rx_device() into two functions
>> and reorganizing rc_register_device() so that as much work
>> as possible is performed before calling device_add().
>> 
>> Version 2: switch the order in which rc_prepare_rx_device() and
>> ir_raw_event_prepare() gets called so that dev->change_protocol()
>> gets called before device_add().
>
>With this patch applied, when I plug in an iguanair usb device, I get.

I'm not surprised that changes to rc_register_device() might require
some driver-specific fixes as well.

I haven't looked at this yet, and I'm going on vacation in a few hours,
so I'll probably take a look in a week...


-- 
David Härdeman