Skip to content

Commit

Permalink
Merge branch 'master' of github.com:matrix-io/matrixio-kernel-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Calderon committed Mar 29, 2021
2 parents 00d5eea + 81f5ca1 commit 2f3818f
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 51 deletions.
1 change: 0 additions & 1 deletion src/matrixio-everloop.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <asm/uaccess.h>
#include <linux/cdev.h>
#include <linux/fs.h>
#include <linux/init.h>
Expand Down
1 change: 0 additions & 1 deletion src/matrixio-gpio.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <asm/uaccess.h>
#include <linux/bitops.h>
#include <linux/fs.h>
#include <linux/gpio.h>
Expand Down
66 changes: 42 additions & 24 deletions src/matrixio-mic.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ static struct matrixio_mic_substream *ms;

static const struct {
unsigned rate;
unsigned short decimation; /* sample rate = (PDM clock = 3 MHz) / (decimation+1) */
unsigned short
decimation; /* sample rate = (PDM clock = 3 MHz) / (decimation+1) */
unsigned short gain; /* in bits */
} matrixio_params[] = {{8000, 374, 1}, {12000, 249, 2}, {16000, 186, 3},
{22050, 135, 5}, {24000, 124, 5}, {32000, 92, 6},
{44100, 67, 7}, {48000, 61, 7}, {96000, 30, 10}};

static struct snd_pcm_hardware matrixio_pcm_capture_hw = {
.info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP,
.info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP_VALID |
SNDRV_PCM_INFO_BLOCK_TRANSFER,
.formats = MATRIXIO_FORMATS,
.rates = MATRIXIO_RATES,
.rate_min = 8000,
Expand Down Expand Up @@ -134,7 +136,8 @@ static irqreturn_t matrixio_pcm_interrupt(int irq, void *irq_data)
return IRQ_HANDLED;
}

static int matrixio_pcm_open(struct snd_pcm_substream *substream)
static int matrixio_pcm_open(struct snd_soc_component *component,
struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *runtime = substream->runtime;
int ret;
Expand Down Expand Up @@ -182,11 +185,11 @@ static int matrixio_pcm_open(struct snd_pcm_substream *substream)
return ret;
}

static int matrixio_pcm_close(struct snd_pcm_substream *substream)
static int matrixio_pcm_close(struct snd_soc_component *component,
struct snd_pcm_substream *substream)
{
clear_bit(0,
&ms->flags); /* Should already be clear from trigger stop, but
just in case */
clear_bit(0, &ms->flags); /* Should already be clear from trigger stop,
but just in case */
free_irq(ms->irq, ms);
destroy_workqueue(ms->wq);
cancel_work_sync(&ms->work);
Expand All @@ -195,7 +198,8 @@ static int matrixio_pcm_close(struct snd_pcm_substream *substream)
return 0;
}

static int matrixio_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
static int matrixio_pcm_trigger(struct snd_soc_component *component,
struct snd_pcm_substream *substream, int cmd)
{
unsigned long flags;

Expand All @@ -218,7 +222,8 @@ static int matrixio_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
}
}

static int matrixio_pcm_hw_params(struct snd_pcm_substream *substream,
static int matrixio_pcm_hw_params(struct snd_soc_component *component,
struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *hw_params)
{
int i;
Expand Down Expand Up @@ -255,20 +260,21 @@ static int matrixio_pcm_hw_params(struct snd_pcm_substream *substream,
if (!FIR_Coeff[i].rate_)
return -EINVAL;

return snd_pcm_lib_alloc_vmalloc_buffer(substream,
params_buffer_bytes(hw_params));
return 0;
}

static int matrixio_pcm_hw_free(struct snd_pcm_substream *substream)
static int matrixio_pcm_hw_free(struct snd_soc_component *component,
struct snd_pcm_substream *substream)
{
/* Capture should have been stopped already */
snd_BUG_ON(test_bit(0, &ms->flags));
/* Make sure work function is finished */
flush_workqueue(ms->wq);
return snd_pcm_lib_free_vmalloc_buffer(substream);
return snd_pcm_lib_free_pages(substream);
}

static int matrixio_pcm_prepare(struct snd_pcm_substream *substream)
static int matrixio_pcm_prepare(struct snd_soc_component *component,
struct snd_pcm_substream *substream)
{
if (substream->runtime->period_size != MATRIXIO_PERIOD_FRAMES) {
pcm_err(substream->pcm, "Need %u frames/period, got %lu\n",
Expand All @@ -283,27 +289,39 @@ static int matrixio_pcm_prepare(struct snd_pcm_substream *substream)
}

static snd_pcm_uframes_t
matrixio_pcm_pointer(struct snd_pcm_substream *substream)
matrixio_pcm_pointer(struct snd_soc_component *component,
struct snd_pcm_substream *substream)
{
return atomic_read(&ms->position);
}

static const struct snd_pcm_ops matrixio_pcm_ops = {
static int matrixio_pcm_new(struct snd_soc_component *component,
struct snd_soc_pcm_runtime *rtd)
{
snd_pcm_set_managed_buffer_all(
rtd->pcm, SNDRV_DMA_TYPE_VMALLOC, component->dev,
matrixio_pcm_capture_hw.buffer_bytes_max,
matrixio_pcm_capture_hw.buffer_bytes_max);
return 0;
}

static int matrixio_pcm_dma_mmap(struct snd_soc_component *component,
struct snd_pcm_substream *substream,
struct vm_area_struct *vma)
{
return snd_pcm_lib_default_mmap(substream, vma);
}

static const struct snd_soc_component_driver matrixio_soc_platform = {
.pcm_construct = matrixio_pcm_new,
.open = matrixio_pcm_open,
.ioctl = snd_pcm_lib_ioctl,
.hw_params = matrixio_pcm_hw_params,
.hw_free = matrixio_pcm_hw_free,
.prepare = matrixio_pcm_prepare,
.pointer = matrixio_pcm_pointer,
.close = matrixio_pcm_close,
.mmap = matrixio_pcm_dma_mmap,
.trigger = matrixio_pcm_trigger,
.page = snd_pcm_lib_get_vmalloc_page,
};

static int matrixio_pcm_new(struct snd_soc_pcm_runtime *rtd) { return 0; }

static const struct snd_soc_component_driver matrixio_soc_platform = {
.ops = &matrixio_pcm_ops, .pcm_new = matrixio_pcm_new,
};

static int matrixio_pcm_platform_probe(struct platform_device *pdev)
Expand Down
37 changes: 16 additions & 21 deletions src/matrixio-playback.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static int thread_pcm_playback(void *data)
return 0;
}

static int matrixio_playback_open(struct snd_pcm_substream *substream)
static int matrixio_playback_open(struct snd_soc_component *component, struct snd_pcm_substream *substream)
{
snd_soc_set_runtime_hwparams(substream, &matrixio_playback_capture_hw);

Expand All @@ -162,7 +162,7 @@ static int matrixio_playback_open(struct snd_pcm_substream *substream)
return 0;
}

static int matrixio_playback_close(struct snd_pcm_substream *substream)
static int matrixio_playback_close(struct snd_soc_component *component, struct snd_pcm_substream *substream)
{
up(&sem);

Expand All @@ -175,7 +175,7 @@ static int matrixio_playback_close(struct snd_pcm_substream *substream)
return 0;
}

static int matrixio_playback_hw_params(struct snd_pcm_substream *substream,
static int matrixio_playback_hw_params(struct snd_soc_component *component, struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *hw_params)
{
int i;
Expand All @@ -198,19 +198,19 @@ static int matrixio_playback_hw_params(struct snd_pcm_substream *substream,
return -EINVAL;
}

static int matrixio_playback_hw_free(struct snd_pcm_substream *substream)
static int matrixio_playback_hw_free(struct snd_soc_component *component, struct snd_pcm_substream *substream)
{
return snd_pcm_lib_free_pages(substream);
}

static int matrixio_playback_prepare(struct snd_pcm_substream *substream)
static int matrixio_playback_prepare(struct snd_soc_component *component, struct snd_pcm_substream *substream)
{
ms->position = 0;
return 0;
}

static snd_pcm_uframes_t
matrixio_playback_pointer(struct snd_pcm_substream *substream)
matrixio_playback_pointer(struct snd_soc_component *component, struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *runtime = substream->runtime;

Expand All @@ -225,7 +225,7 @@ matrixio_playback_pointer(struct snd_pcm_substream *substream)
return bytes_to_frames(runtime, ms->position);
}

static int matrixio_playback_copy(struct snd_pcm_substream *substream,
static int matrixio_playback_copy(struct snd_soc_component *component, struct snd_pcm_substream *substream,
int channel, snd_pcm_uframes_t pos,
void __user *buf, snd_pcm_uframes_t bytes)
{
Expand All @@ -242,17 +242,6 @@ static int matrixio_playback_copy(struct snd_pcm_substream *substream,
return frame_count;
}

static struct snd_pcm_ops matrixio_playback_ops = {
.open = matrixio_playback_open,
.ioctl = snd_pcm_lib_ioctl,
.hw_params = matrixio_playback_hw_params,
.hw_free = matrixio_playback_hw_free,
.prepare = matrixio_playback_prepare,
.pointer = matrixio_playback_pointer,
.copy_user = matrixio_playback_copy,
.close = matrixio_playback_close,
};

static int matrixio_playback_select_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
Expand Down Expand Up @@ -332,13 +321,19 @@ static const struct snd_kcontrol_new matrixio_snd_controls[] = {
.put = matrixio_volume_put,
}};

static int matrixio_playback_new(struct snd_soc_pcm_runtime *rtd) { return 0; }
static int matrixio_playback_new(struct snd_soc_component *component, struct snd_soc_pcm_runtime *rtd) { return 0; }

static const struct snd_soc_component_driver matrixio_soc_platform = {
.ops = &matrixio_playback_ops,
.pcm_new = matrixio_playback_new,
.pcm_construct = matrixio_playback_new,
.controls = matrixio_snd_controls,
.num_controls = ARRAY_SIZE(matrixio_snd_controls),
.open = matrixio_playback_open,
.hw_params = matrixio_playback_hw_params,
.hw_free = matrixio_playback_hw_free,
.prepare = matrixio_playback_prepare,
.pointer = matrixio_playback_pointer,
.copy_user = matrixio_playback_copy,
.close = matrixio_playback_close,
};

static int matrixio_playback_platform_probe(struct platform_device *pdev)
Expand Down
1 change: 0 additions & 1 deletion src/matrixio-pwm.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <asm/uaccess.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/module.h>
Expand Down
1 change: 0 additions & 1 deletion src/matrixio-regmap.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <asm/uaccess.h>
#include <linux/cdev.h>
#include <linux/fs.h>
#include <linux/init.h>
Expand Down
4 changes: 2 additions & 2 deletions src/matrixio.dts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@


fragment@4 {
target-path = "/";
target = <&matrixio_core_0>;
__overlay__ {
matrixio-everloop@0 {
compatible = "matrixio-everloop";
Expand Down Expand Up @@ -132,7 +132,7 @@
};

fragment@13 {
target-path = "/";
target = <&matrixio_core_0>;
__overlay__ {
matrixio-regmap@0 {
compatible = "matrixio-regmap";
Expand Down

0 comments on commit 2f3818f

Please sign in to comment.