Skip to content

Commit 72a04d6

Browse files
committed
Merge remote-tracking branches 'asoc/topic/adau', 'asoc/topic/adau7002', 'asoc/topic/adsp', 'asoc/topic/ak4613' and 'asoc/topic/ak4642' into asoc-next
6 parents a39fbe0 + 5d76de6 + a0d3546 + 6facd2d + f9ae17b + a2ebd58 commit 72a04d6

File tree

24 files changed

+555
-140
lines changed

24 files changed

+555
-140
lines changed

Documentation/devicetree/bindings/sound/adi,adau17x1.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,20 @@ Required properties:
1313
- reg: The i2c address. Value depends on the state of ADDR0
1414
and ADDR1, as wired in hardware.
1515

16+
Optional properties:
17+
- clock-names: If provided must be "mclk".
18+
- clocks: phandle + clock-specifiers for the clock that provides
19+
the audio master clock for the device.
20+
1621
Examples:
1722
#include <dt-bindings/sound/adau17x1.h>
1823

1924
i2c_bus {
2025
adau1361@38 {
2126
compatible = "adi,adau1761";
2227
reg = <0x38>;
28+
29+
clock-names = "mclk";
30+
clocks = <&audio_clock>;
2331
};
2432
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Analog Devices ADAU7002 Stereo PDM-to-I2S/TDM Converter
2+
3+
Required properties:
4+
5+
- compatible: Must be "adi,adau7002"
6+
7+
Optional properties:
8+
9+
- IOVDD-supply: Phandle and specifier for the power supply providing the IOVDD
10+
supply as covered in Documentation/devicetree/bindings/regulator/regulator.txt
11+
12+
If this property is not present it is assumed that the supply pin is
13+
hardwired to always on.
14+
15+
Example:
16+
adau7002: pdm-to-i2s {
17+
compatible = "adi,adau7002";
18+
IOVDD-supply = <&supply>;
19+
};

include/linux/mfd/arizona/core.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define _WM_ARIZONA_CORE_H
1515

1616
#include <linux/interrupt.h>
17+
#include <linux/notifier.h>
1718
#include <linux/regmap.h>
1819
#include <linux/regulator/consumer.h>
1920
#include <linux/mfd/arizona/pdata.h>
@@ -148,8 +149,17 @@ struct arizona {
148149
uint16_t dac_comp_coeff;
149150
uint8_t dac_comp_enabled;
150151
struct mutex dac_comp_lock;
152+
153+
struct blocking_notifier_head notifier;
151154
};
152155

156+
static inline int arizona_call_notifiers(struct arizona *arizona,
157+
unsigned long event,
158+
void *data)
159+
{
160+
return blocking_notifier_call_chain(&arizona->notifier, event, data);
161+
}
162+
153163
int arizona_clk32k_enable(struct arizona *arizona);
154164
int arizona_clk32k_disable(struct arizona *arizona);
155165

include/sound/compress_driver.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct snd_compr_runtime {
6868
* @ops: pointer to DSP callbacks
6969
* @runtime: pointer to runtime structure
7070
* @device: device pointer
71+
* @error_work: delayed work used when closing the stream due to an error
7172
* @direction: stream direction, playback/recording
7273
* @metadata_set: metadata set flag, true when set
7374
* @next_track: has userspace signal next track transition, true when set
@@ -78,6 +79,7 @@ struct snd_compr_stream {
7879
struct snd_compr_ops *ops;
7980
struct snd_compr_runtime *runtime;
8081
struct snd_compr *device;
82+
struct delayed_work error_work;
8183
enum snd_compr_direction direction;
8284
bool metadata_set;
8385
bool next_track;
@@ -187,4 +189,7 @@ static inline void snd_compr_drain_notify(struct snd_compr_stream *stream)
187189
wake_up(&stream->runtime->sleep);
188190
}
189191

192+
int snd_compr_stop_error(struct snd_compr_stream *stream,
193+
snd_pcm_state_t state);
194+
190195
#endif

sound/core/compress_offload.c

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ struct snd_compr_file {
6767
struct snd_compr_stream stream;
6868
};
6969

70+
static void error_delayed_work(struct work_struct *work);
71+
7072
/*
7173
* a note on stream states used:
7274
* we use following states in the compressed core
@@ -123,6 +125,9 @@ static int snd_compr_open(struct inode *inode, struct file *f)
123125
snd_card_unref(compr->card);
124126
return -ENOMEM;
125127
}
128+
129+
INIT_DELAYED_WORK(&data->stream.error_work, error_delayed_work);
130+
126131
data->stream.ops = compr->ops;
127132
data->stream.direction = dirn;
128133
data->stream.private_data = compr->private_data;
@@ -153,6 +158,8 @@ static int snd_compr_free(struct inode *inode, struct file *f)
153158
struct snd_compr_file *data = f->private_data;
154159
struct snd_compr_runtime *runtime = data->stream.runtime;
155160

161+
cancel_delayed_work_sync(&data->stream.error_work);
162+
156163
switch (runtime->state) {
157164
case SNDRV_PCM_STATE_RUNNING:
158165
case SNDRV_PCM_STATE_DRAINING:
@@ -237,6 +244,15 @@ snd_compr_ioctl_avail(struct snd_compr_stream *stream, unsigned long arg)
237244
avail = snd_compr_calc_avail(stream, &ioctl_avail);
238245
ioctl_avail.avail = avail;
239246

247+
switch (stream->runtime->state) {
248+
case SNDRV_PCM_STATE_OPEN:
249+
return -EBADFD;
250+
case SNDRV_PCM_STATE_XRUN:
251+
return -EPIPE;
252+
default:
253+
break;
254+
}
255+
240256
if (copy_to_user((__u64 __user *)arg,
241257
&ioctl_avail, sizeof(ioctl_avail)))
242258
return -EFAULT;
@@ -346,11 +362,13 @@ static ssize_t snd_compr_read(struct file *f, char __user *buf,
346362
switch (stream->runtime->state) {
347363
case SNDRV_PCM_STATE_OPEN:
348364
case SNDRV_PCM_STATE_PREPARED:
349-
case SNDRV_PCM_STATE_XRUN:
350365
case SNDRV_PCM_STATE_SUSPENDED:
351366
case SNDRV_PCM_STATE_DISCONNECTED:
352367
retval = -EBADFD;
353368
goto out;
369+
case SNDRV_PCM_STATE_XRUN:
370+
retval = -EPIPE;
371+
goto out;
354372
}
355373

356374
avail = snd_compr_get_avail(stream);
@@ -399,10 +417,16 @@ static unsigned int snd_compr_poll(struct file *f, poll_table *wait)
399417
stream = &data->stream;
400418

401419
mutex_lock(&stream->device->lock);
402-
if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) {
420+
421+
switch (stream->runtime->state) {
422+
case SNDRV_PCM_STATE_OPEN:
423+
case SNDRV_PCM_STATE_XRUN:
403424
retval = snd_compr_get_poll(stream) | POLLERR;
404425
goto out;
426+
default:
427+
break;
405428
}
429+
406430
poll_wait(f, &stream->runtime->sleep, wait);
407431

408432
avail = snd_compr_get_avail(stream);
@@ -697,6 +721,45 @@ static int snd_compr_stop(struct snd_compr_stream *stream)
697721
return retval;
698722
}
699723

724+
static void error_delayed_work(struct work_struct *work)
725+
{
726+
struct snd_compr_stream *stream;
727+
728+
stream = container_of(work, struct snd_compr_stream, error_work.work);
729+
730+
mutex_lock(&stream->device->lock);
731+
732+
stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP);
733+
wake_up(&stream->runtime->sleep);
734+
735+
mutex_unlock(&stream->device->lock);
736+
}
737+
738+
/*
739+
* snd_compr_stop_error: Report a fatal error on a stream
740+
* @stream: pointer to stream
741+
* @state: state to transition the stream to
742+
*
743+
* Stop the stream and set its state.
744+
*
745+
* Should be called with compressed device lock held.
746+
*/
747+
int snd_compr_stop_error(struct snd_compr_stream *stream,
748+
snd_pcm_state_t state)
749+
{
750+
if (stream->runtime->state == state)
751+
return 0;
752+
753+
stream->runtime->state = state;
754+
755+
pr_debug("Changing state to: %d\n", state);
756+
757+
queue_delayed_work(system_power_efficient_wq, &stream->error_work, 0);
758+
759+
return 0;
760+
}
761+
EXPORT_SYMBOL_GPL(snd_compr_stop_error);
762+
700763
static int snd_compress_wait_for_drain(struct snd_compr_stream *stream)
701764
{
702765
int ret;

sound/soc/codecs/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ config SND_SOC_ALL_CODECS
3232
select SND_SOC_ADAU1977_SPI if SPI_MASTER
3333
select SND_SOC_ADAU1977_I2C if I2C
3434
select SND_SOC_ADAU1701 if I2C
35+
select SND_SOC_ADAU7002
3536
select SND_SOC_ADS117X
3637
select SND_SOC_AK4104 if SPI_MASTER
3738
select SND_SOC_AK4535 if I2C
@@ -269,8 +270,12 @@ config SND_SOC_AD1980
269270
config SND_SOC_AD73311
270271
tristate
271272

273+
config SND_SOC_ADAU_UTILS
274+
tristate
275+
272276
config SND_SOC_ADAU1373
273277
tristate
278+
select SND_SOC_ADAU_UTILS
274279

275280
config SND_SOC_ADAU1701
276281
tristate "Analog Devices ADAU1701 CODEC"
@@ -280,6 +285,7 @@ config SND_SOC_ADAU1701
280285
config SND_SOC_ADAU17X1
281286
tristate
282287
select SND_SOC_SIGMADSP_REGMAP
288+
select SND_SOC_ADAU_UTILS
283289

284290
config SND_SOC_ADAU1761
285291
tristate
@@ -322,6 +328,9 @@ config SND_SOC_ADAU1977_I2C
322328
select SND_SOC_ADAU1977
323329
select REGMAP_I2C
324330

331+
config SND_SOC_ADAU7002
332+
tristate "Analog Devices ADAU7002 Stereo PDM-to-I2S/TDM Converter"
333+
325334
config SND_SOC_ADAV80X
326335
tristate
327336

sound/soc/codecs/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ snd-soc-ad193x-spi-objs := ad193x-spi.o
77
snd-soc-ad193x-i2c-objs := ad193x-i2c.o
88
snd-soc-ad1980-objs := ad1980.o
99
snd-soc-ad73311-objs := ad73311.o
10+
snd-soc-adau-utils-objs := adau-utils.o
1011
snd-soc-adau1373-objs := adau1373.o
1112
snd-soc-adau1701-objs := adau1701.o
1213
snd-soc-adau17x1-objs := adau17x1.o
@@ -19,6 +20,7 @@ snd-soc-adau1781-spi-objs := adau1781-spi.o
1920
snd-soc-adau1977-objs := adau1977.o
2021
snd-soc-adau1977-spi-objs := adau1977-spi.o
2122
snd-soc-adau1977-i2c-objs := adau1977-i2c.o
23+
snd-soc-adau7002-objs := adau7002.o
2224
snd-soc-adav80x-objs := adav80x.o
2325
snd-soc-adav801-objs := adav801.o
2426
snd-soc-adav803-objs := adav803.o
@@ -220,6 +222,7 @@ obj-$(CONFIG_SND_SOC_AD193X_SPI) += snd-soc-ad193x-spi.o
220222
obj-$(CONFIG_SND_SOC_AD193X_I2C) += snd-soc-ad193x-i2c.o
221223
obj-$(CONFIG_SND_SOC_AD1980) += snd-soc-ad1980.o
222224
obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o
225+
obj-$(CONFIG_SND_SOC_ADAU_UTILS) += snd-soc-adau-utils.o
223226
obj-$(CONFIG_SND_SOC_ADAU1373) += snd-soc-adau1373.o
224227
obj-$(CONFIG_SND_SOC_ADAU1701) += snd-soc-adau1701.o
225228
obj-$(CONFIG_SND_SOC_ADAU17X1) += snd-soc-adau17x1.o
@@ -232,6 +235,7 @@ obj-$(CONFIG_SND_SOC_ADAU1781_SPI) += snd-soc-adau1781-spi.o
232235
obj-$(CONFIG_SND_SOC_ADAU1977) += snd-soc-adau1977.o
233236
obj-$(CONFIG_SND_SOC_ADAU1977_SPI) += snd-soc-adau1977-spi.o
234237
obj-$(CONFIG_SND_SOC_ADAU1977_I2C) += snd-soc-adau1977-i2c.o
238+
obj-$(CONFIG_SND_SOC_ADAU7002) += snd-soc-adau7002.o
235239
obj-$(CONFIG_SND_SOC_ADAV80X) += snd-soc-adav80x.o
236240
obj-$(CONFIG_SND_SOC_ADAV801) += snd-soc-adav801.o
237241
obj-$(CONFIG_SND_SOC_ADAV803) += snd-soc-adav803.o

sound/soc/codecs/adau-utils.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Shared helper functions for devices from the ADAU family
3+
*
4+
* Copyright 2011-2016 Analog Devices Inc.
5+
* Author: Lars-Peter Clausen <[email protected]>
6+
*
7+
* Licensed under the GPL-2 or later.
8+
*/
9+
10+
#include <linux/gcd.h>
11+
#include <linux/kernel.h>
12+
#include <linux/module.h>
13+
14+
#include "adau-utils.h"
15+
16+
int adau_calc_pll_cfg(unsigned int freq_in, unsigned int freq_out,
17+
uint8_t regs[5])
18+
{
19+
unsigned int r, n, m, i, j;
20+
unsigned int div;
21+
22+
if (!freq_out) {
23+
r = 0;
24+
n = 0;
25+
m = 0;
26+
div = 0;
27+
} else {
28+
if (freq_out % freq_in != 0) {
29+
div = DIV_ROUND_UP(freq_in, 13500000);
30+
freq_in /= div;
31+
r = freq_out / freq_in;
32+
i = freq_out % freq_in;
33+
j = gcd(i, freq_in);
34+
n = i / j;
35+
m = freq_in / j;
36+
div--;
37+
} else {
38+
r = freq_out / freq_in;
39+
n = 0;
40+
m = 0;
41+
div = 0;
42+
}
43+
if (n > 0xffff || m > 0xffff || div > 3 || r > 8 || r < 2)
44+
return -EINVAL;
45+
}
46+
47+
regs[0] = m >> 8;
48+
regs[1] = m & 0xff;
49+
regs[2] = n >> 8;
50+
regs[3] = n & 0xff;
51+
regs[4] = (r << 3) | (div << 1);
52+
if (m != 0)
53+
regs[4] |= 1; /* Fractional mode */
54+
55+
return 0;
56+
}
57+
EXPORT_SYMBOL_GPL(adau_calc_pll_cfg);
58+
59+
MODULE_DESCRIPTION("ASoC ADAU audio CODECs shared helper functions");
60+
MODULE_AUTHOR("Lars-Peter Clausen <[email protected]>");
61+
MODULE_LICENSE("GPL v2");

sound/soc/codecs/adau-utils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef SOUND_SOC_CODECS_ADAU_PLL_H
2+
#define SOUND_SOC_CODECS_ADAU_PLL_H
3+
4+
int adau_calc_pll_cfg(unsigned int freq_in, unsigned int freq_out,
5+
uint8_t regs[5]);
6+
7+
#endif

0 commit comments

Comments
 (0)