diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2021-07-02 15:25:23 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2021-07-02 15:25:23 -0700 |
commit | d6b63b5b7d7f363c6a54421533791e9849adf2e0 (patch) | |
tree | 4ce13ab8c97a3eafe0669b217fc24c9273dc42c6 /sound/soc/sh/rcar | |
parent | bd31b9efbf549d9630bf2f269a3a56dcb29fcac1 (diff) | |
parent | 9a7b7ec3c6f2aedb99c9f39dd9cb63c2deff3437 (diff) |
Merge tag 'sound-5.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound
Pull sound updates from Takashi Iwai:
"As the diffstat scatters over the tree, we've got many tree-wide small
changes, but also got quite a few intrusive changes in the core side.
The only ABI-visible core change is the new rawmidi framing mode
support while others are kernel-internal, mostly code refactoring
and/or nice improvements.
Here are some highlights:
Core:
- A new framing access mode for rawmidi to get timestamps
- Cleanup / refactoring of buffer memory management helper code
- Support for automatic negotiation of ASoC DAI formats
- Revival of software suspend for PCM and control core, as a
preliminary work for PCI BAR rescan support
ASoC:
- Accessory detection support for several Qualcomm parts
- Support for IEC958 control with hdmi-codec
- Merging of Tegra machine drivers into a single driver
- Support for AmLogic SM1 TOACODEC, Intel AlderLake-M, several NXP
i.MX8 variants, NXP TFA1 and TDF9897, Rockchip RK817, Qualcomm
Quinary MI2S, Texas Instruments TAS2505
USB-audio:
- Reduction of latency at playback start
- Code cleanup / fixes of usx2y driver
- Scarlett2 mixer code fixes and enhancements
- Quirks for Ozone and Denon devices
HD-audio:
- A few quirks for HP and ASUS machines
- Display power management fixes
Others:
- FireWire code refactoring and enhancements
- Tree-wide trivial coding-style fixes"
* tag 'sound-5.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound: (594 commits)
ALSA: usb-audio: scarlett2: Fix for loop increment in scarlett2_usb_get_config
ALSA: hda/realtek: fix mute/micmute LEDs for HP ProBook 630 G8
ALSA: hda/realtek: fix mute/micmute LEDs for HP ProBook 445 G8
ALSA: hda/realtek: fix mute/micmute LEDs for HP ProBook 450 G8
ALSA: hda/realtek - Add ALC285 HP init procedure
ALSA: hda/realtek - Add type for ALC287
ALSA: scarlett2: Fix scarlett2_*_ctl_put() return values again
ALSA: scarlett2: Fix pad count for 18i8 Gen 3
ALSA: hda/realtek: fix mute/micmute LEDs for HP EliteBook 830 G8 Notebook PC
ALSA: firewire-lib: Fix 'amdtp_domain_start()' when no AMDTP_OUT_STREAM stream is found
ASoC: qcom: lpass-cpu: mark IRQ_CLEAR register as volatile and readable
ALSA: hda: Release codec display power during shutdown/reboot
ALSA: hda: Release controller display power during shutdown/reboot
ALSA: hda/realtek: Apply LED fixup for HP Dragonfly G1, too
ASoC: fsl: remove unnecessary oom message
ASoC: tlv320aic32x4: dt-bindings: add TAS2505 to compatible
ASoC: tlv320aic32x4: add support for TAS2505
ASoC: tlv320aic32x4: add type to device private data struct
ASoC: tegra30: ahub: Use devm_platform_get_and_ioremap_resource()
ASoC: tegra: tegra210_admaif: Use devm_platform_get_and_ioremap_resource()
...
Diffstat (limited to 'sound/soc/sh/rcar')
-rw-r--r-- | sound/soc/sh/rcar/Makefile | 2 | ||||
-rw-r--r-- | sound/soc/sh/rcar/adg.c | 180 | ||||
-rw-r--r-- | sound/soc/sh/rcar/cmd.c | 14 | ||||
-rw-r--r-- | sound/soc/sh/rcar/core.c | 154 | ||||
-rw-r--r-- | sound/soc/sh/rcar/ctu.c | 14 | ||||
-rw-r--r-- | sound/soc/sh/rcar/debugfs.c | 96 | ||||
-rw-r--r-- | sound/soc/sh/rcar/dma.c | 39 | ||||
-rw-r--r-- | sound/soc/sh/rcar/dvc.c | 16 | ||||
-rw-r--r-- | sound/soc/sh/rcar/gen.c | 9 | ||||
-rw-r--r-- | sound/soc/sh/rcar/mix.c | 14 | ||||
-rw-r--r-- | sound/soc/sh/rcar/rsnd.h | 75 | ||||
-rw-r--r-- | sound/soc/sh/rcar/src.c | 32 | ||||
-rw-r--r-- | sound/soc/sh/rcar/ssi.c | 160 | ||||
-rw-r--r-- | sound/soc/sh/rcar/ssiu.c | 147 |
14 files changed, 696 insertions, 256 deletions
diff --git a/sound/soc/sh/rcar/Makefile b/sound/soc/sh/rcar/Makefile index 5d1ff8ef26f9..d07eccfa3ac2 100644 --- a/sound/soc/sh/rcar/Makefile +++ b/sound/soc/sh/rcar/Makefile @@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 -snd-soc-rcar-objs := core.o gen.o dma.o adg.o ssi.o ssiu.o src.o ctu.o mix.o dvc.o cmd.o +snd-soc-rcar-objs := core.o gen.o dma.o adg.o ssi.o ssiu.o src.o ctu.o mix.o dvc.o cmd.o debugfs.o obj-$(CONFIG_SND_SOC_RCAR) += snd-soc-rcar.o diff --git a/sound/soc/sh/rcar/adg.c b/sound/soc/sh/rcar/adg.c index 0b8ae3eee148..0ebee1ed06a9 100644 --- a/sound/soc/sh/rcar/adg.c +++ b/sound/soc/sh/rcar/adg.c @@ -3,8 +3,8 @@ // Helper routines for R-Car sound ADG. // // Copyright (C) 2013 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> - #include <linux/clk-provider.h> +#include <linux/clkdev.h> #include "rsnd.h" #define CLKA 0 @@ -28,6 +28,7 @@ static struct rsnd_mod_ops adg_ops = { struct rsnd_adg { struct clk *clk[CLKMAX]; struct clk *clkout[CLKOUTMAX]; + struct clk *null_clk; struct clk_onecell_data onecell; struct rsnd_mod mod; int clk_rate[CLKMAX]; @@ -290,7 +291,6 @@ static void rsnd_adg_set_ssi_clk(struct rsnd_mod *ssi_mod, u32 val) int rsnd_adg_clk_query(struct rsnd_priv *priv, unsigned int rate) { struct rsnd_adg *adg = rsnd_priv_to_adg(priv); - struct clk *clk; int i; int sel_table[] = { [CLKA] = 0x1, @@ -303,10 +303,9 @@ int rsnd_adg_clk_query(struct rsnd_priv *priv, unsigned int rate) * find suitable clock from * AUDIO_CLKA/AUDIO_CLKB/AUDIO_CLKC/AUDIO_CLKI. */ - for_each_rsnd_clk(clk, adg, i) { + for (i = 0; i < CLKMAX; i++) if (rate == adg->clk_rate[i]) return sel_table[i]; - } /* * find divided clock from BRGA/BRGB @@ -365,48 +364,103 @@ int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *ssi_mod, unsigned int rate) void rsnd_adg_clk_control(struct rsnd_priv *priv, int enable) { struct rsnd_adg *adg = rsnd_priv_to_adg(priv); - struct device *dev = rsnd_priv_to_dev(priv); struct clk *clk; int i; for_each_rsnd_clk(clk, adg, i) { if (enable) { - int ret = clk_prepare_enable(clk); + clk_prepare_enable(clk); /* * We shouldn't use clk_get_rate() under * atomic context. Let's keep it when * rsnd_adg_clk_enable() was called */ - adg->clk_rate[i] = 0; - if (ret < 0) - dev_warn(dev, "can't use clk %d\n", i); - else - adg->clk_rate[i] = clk_get_rate(clk); + adg->clk_rate[i] = clk_get_rate(clk); } else { - if (adg->clk_rate[i]) - clk_disable_unprepare(clk); - adg->clk_rate[i] = 0; + clk_disable_unprepare(clk); } } } -static void rsnd_adg_get_clkin(struct rsnd_priv *priv, - struct rsnd_adg *adg) +static struct clk *rsnd_adg_create_null_clk(struct rsnd_priv *priv, + const char * const name, + const char *parent) +{ + struct device *dev = rsnd_priv_to_dev(priv); + struct clk *clk; + + clk = clk_register_fixed_rate(dev, name, parent, 0, 0); + if (IS_ERR(clk)) { + dev_err(dev, "create null clk error\n"); + return NULL; + } + + return clk; +} + +static struct clk *rsnd_adg_null_clk_get(struct rsnd_priv *priv) +{ + struct rsnd_adg *adg = priv->adg; + + if (!adg->null_clk) { + static const char * const name = "rsnd_adg_null"; + + adg->null_clk = rsnd_adg_create_null_clk(priv, name, NULL); + } + + return adg->null_clk; +} + +static void rsnd_adg_null_clk_clean(struct rsnd_priv *priv) { + struct rsnd_adg *adg = priv->adg; + + if (adg->null_clk) + clk_unregister_fixed_rate(adg->null_clk); +} + +static int rsnd_adg_get_clkin(struct rsnd_priv *priv) +{ + struct rsnd_adg *adg = priv->adg; struct device *dev = rsnd_priv_to_dev(priv); + struct clk *clk; int i; for (i = 0; i < CLKMAX; i++) { - struct clk *clk = devm_clk_get(dev, clk_name[i]); + clk = devm_clk_get(dev, clk_name[i]); + + if (IS_ERR(clk)) + clk = rsnd_adg_null_clk_get(priv); + if (IS_ERR(clk)) + goto err; - adg->clk[i] = IS_ERR(clk) ? NULL : clk; + adg->clk[i] = clk; } + + return 0; + +err: + dev_err(dev, "adg clock IN get failed\n"); + + rsnd_adg_null_clk_clean(priv); + + return -EIO; } -static void rsnd_adg_get_clkout(struct rsnd_priv *priv, - struct rsnd_adg *adg) +static void rsnd_adg_unregister_clkout(struct rsnd_priv *priv) { + struct rsnd_adg *adg = priv->adg; + struct clk *clk; + int i; + + for_each_rsnd_clkout(clk, adg, i) + clk_unregister_fixed_rate(clk); +} + +static int rsnd_adg_get_clkout(struct rsnd_priv *priv) +{ + struct rsnd_adg *adg = priv->adg; struct clk *clk; struct device *dev = rsnd_priv_to_dev(priv); struct device_node *np = dev->of_node; @@ -446,9 +500,8 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv, req_size = prop->length / sizeof(u32); if (req_size > REQ_SIZE) { - dev_err(dev, - "too many clock-frequency, use top %d\n", REQ_SIZE); - req_size = REQ_SIZE; + dev_err(dev, "too many clock-frequency\n"); + return -EINVAL; } of_property_read_u32_array(np, "clock-frequency", req_rate, req_size); @@ -529,10 +582,11 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv, if (!count) { clk = clk_register_fixed_rate(dev, clkout_name[CLKOUT], parent_clk_name, 0, req_rate[0]); - if (!IS_ERR(clk)) { - adg->clkout[CLKOUT] = clk; - of_clk_add_provider(np, of_clk_src_simple_get, clk); - } + if (IS_ERR(clk)) + goto err; + + adg->clkout[CLKOUT] = clk; + of_clk_add_provider(np, of_clk_src_simple_get, clk); } /* * for clkout0/1/2/3 @@ -542,8 +596,10 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv, clk = clk_register_fixed_rate(dev, clkout_name[i], parent_clk_name, 0, req_rate[0]); - if (!IS_ERR(clk)) - adg->clkout[i] = clk; + if (IS_ERR(clk)) + goto err; + + adg->clkout[i] = clk; } adg->onecell.clks = adg->clkout; adg->onecell.clk_num = CLKOUTMAX; @@ -555,34 +611,61 @@ rsnd_adg_get_clkout_end: adg->ckr = ckr; adg->rbga = rbga; adg->rbgb = rbgb; + + return 0; + +err: + dev_err(dev, "adg clock OUT get failed\n"); + + rsnd_adg_unregister_clkout(priv); + + return -EIO; } -#ifdef DEBUG -static void rsnd_adg_clk_dbg_info(struct rsnd_priv *priv, struct rsnd_adg *adg) +#if defined(DEBUG) || defined(CONFIG_DEBUG_FS) +__printf(3, 4) +static void dbg_msg(struct device *dev, struct seq_file *m, + const char *fmt, ...) { + char msg[128]; + va_list args; + + va_start(args, fmt); + vsnprintf(msg, sizeof(msg), fmt, args); + va_end(args); + + if (m) + seq_puts(m, msg); + else + dev_dbg(dev, "%s", msg); +} + +void rsnd_adg_clk_dbg_info(struct rsnd_priv *priv, struct seq_file *m) +{ + struct rsnd_adg *adg = rsnd_priv_to_adg(priv); struct device *dev = rsnd_priv_to_dev(priv); struct clk *clk; int i; for_each_rsnd_clk(clk, adg, i) - dev_dbg(dev, "%s : %pa : %ld\n", + dbg_msg(dev, m, "%s : %pa : %ld\n", clk_name[i], clk, clk_get_rate(clk)); - dev_dbg(dev, "BRGCKR = 0x%08x, BRRA/BRRB = 0x%x/0x%x\n", + dbg_msg(dev, m, "BRGCKR = 0x%08x, BRRA/BRRB = 0x%x/0x%x\n", adg->ckr, adg->rbga, adg->rbgb); - dev_dbg(dev, "BRGA (for 44100 base) = %d\n", adg->rbga_rate_for_441khz); - dev_dbg(dev, "BRGB (for 48000 base) = %d\n", adg->rbgb_rate_for_48khz); + dbg_msg(dev, m, "BRGA (for 44100 base) = %d\n", adg->rbga_rate_for_441khz); + dbg_msg(dev, m, "BRGB (for 48000 base) = %d\n", adg->rbgb_rate_for_48khz); /* * Actual CLKOUT will be exchanged in rsnd_adg_ssi_clk_try_start() * by BRGCKR::BRGCKR_31 */ for_each_rsnd_clkout(clk, adg, i) - dev_dbg(dev, "clkout %d : %pa : %ld\n", i, + dbg_msg(dev, m, "clkout %d : %pa : %ld\n", i, clk, clk_get_rate(clk)); } #else -#define rsnd_adg_clk_dbg_info(priv, adg) +#define rsnd_adg_clk_dbg_info(priv, m) #endif int rsnd_adg_probe(struct rsnd_priv *priv) @@ -600,13 +683,18 @@ int rsnd_adg_probe(struct rsnd_priv *priv) if (ret) return ret; - rsnd_adg_get_clkin(priv, adg); - rsnd_adg_get_clkout(priv, adg); - rsnd_adg_clk_dbg_info(priv, adg); - priv->adg = adg; + ret = rsnd_adg_get_clkin(priv); + if (ret) + return ret; + + ret = rsnd_adg_get_clkout(priv); + if (ret) + return ret; + rsnd_adg_clk_enable(priv); + rsnd_adg_clk_dbg_info(priv, NULL); return 0; } @@ -615,15 +703,13 @@ void rsnd_adg_remove(struct rsnd_priv *priv) { struct device *dev = rsnd_priv_to_dev(priv); struct device_node *np = dev->of_node; - struct rsnd_adg *adg = priv->adg; - struct clk *clk; - int i; - for_each_rsnd_clkout(clk, adg, i) - if (adg->clkout[i]) - clk_unregister_fixed_rate(adg->clkout[i]); + rsnd_adg_unregister_clkout(priv); of_clk_del_provider(np); rsnd_adg_clk_disable(priv); + + /* It should be called after rsnd_adg_clk_disable() */ + rsnd_adg_null_clk_clean(priv); } diff --git a/sound/soc/sh/rcar/cmd.c b/sound/soc/sh/rcar/cmd.c index 9fdb37c2cbc2..329e6ab1b222 100644 --- a/sound/soc/sh/rcar/cmd.c +++ b/sound/soc/sh/rcar/cmd.c @@ -114,12 +114,26 @@ static int rsnd_cmd_stop(struct rsnd_mod *mod, return 0; } +#ifdef CONFIG_DEBUG_FS +static void rsnd_cmd_debug_info(struct seq_file *m, + struct rsnd_dai_stream *io, + struct rsnd_mod *mod) +{ + rsnd_debugfs_mod_reg_show(m, mod, RSND_GEN2_SCU, + 0x180 + rsnd_mod_id_raw(mod) * 0x20, 0x30); +} +#define DEBUG_INFO .debug_info = rsnd_cmd_debug_info +#else +#define DEBUG_INFO +#endif + static struct rsnd_mod_ops rsnd_cmd_ops = { .name = CMD_NAME, .init = rsnd_cmd_init, .start = rsnd_cmd_start, .stop = rsnd_cmd_stop, .get_status = rsnd_mod_get_status, + DEBUG_INFO }; static struct rsnd_mod *rsnd_cmd_mod_get(struct rsnd_priv *priv, int id) diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c index 8696a993c478..5e382b5c9d45 100644 --- a/sound/soc/sh/rcar/core.c +++ b/sound/soc/sh/rcar/core.c @@ -90,14 +90,6 @@ * */ -/* - * you can enable below define if you don't need - * DAI status debug message when debugging - * see rsnd_dbg_dai_call() - * - * #define RSND_DEBUG_NO_DAI_CALL 1 - */ - #include <linux/pm_runtime.h> #include "rsnd.h" @@ -267,8 +259,9 @@ int rsnd_runtime_channel_original_with_params(struct rsnd_dai_stream *io, */ if (params) return params_channels(params); - else + else if (runtime) return runtime->channels; + return 0; } int rsnd_runtime_channel_after_ctu_with_params(struct rsnd_dai_stream *io, @@ -533,16 +526,22 @@ static enum rsnd_mod_type rsnd_mod_sequence[][RSND_MOD_MAX] = { }, }; -static int rsnd_status_update(u32 *status, +static int rsnd_status_update(struct rsnd_dai_stream *io, + struct rsnd_mod *mod, enum rsnd_mod_type type, int shift, int add, int timing) { + u32 *status = mod->ops->get_status(mod, io, type); u32 mask = 0xF << shift; u8 val = (*status >> shift) & 0xF; u8 next_val = (val + add) & 0xF; int func_call = (val == timing); + /* no status update */ + if (add == 0 || shift == 28) + return 1; + if (next_val == 0xF) /* underflow case */ - func_call = 0; + func_call = -1; else *status = (*status & ~mask) + (next_val << shift); @@ -558,19 +557,16 @@ static int rsnd_status_update(u32 *status, enum rsnd_mod_type *types = rsnd_mod_sequence[is_play]; \ for_each_rsnd_mod_arrays(i, mod, io, types, RSND_MOD_MAX) { \ int tmp = 0; \ - u32 *status = mod->ops->get_status(mod, io, types[i]); \ - int func_call = rsnd_status_update(status, \ + int func_call = rsnd_status_update(io, mod, types[i], \ __rsnd_mod_shift_##fn, \ __rsnd_mod_add_##fn, \ __rsnd_mod_call_##fn); \ - rsnd_dbg_dai_call(dev, "%s\t0x%08x %s\n", \ - rsnd_mod_name(mod), *status, \ - (func_call && (mod)->ops->fn) ? #fn : ""); \ - if (func_call && (mod)->ops->fn) \ + if (func_call > 0 && (mod)->ops->fn) \ tmp = (mod)->ops->fn(mod, io, param); \ - if (tmp && (tmp != -EPROBE_DEFER)) \ - dev_err(dev, "%s : %s error %d\n", \ - rsnd_mod_name(mod), #fn, tmp); \ + if (unlikely(func_call < 0) || \ + unlikely(tmp && (tmp != -EPROBE_DEFER))) \ + dev_err(dev, "%s : %s error (%d, %d)\n", \ + rsnd_mod_name(mod), #fn, tmp, func_call);\ ret |= tmp; \ } \ ret; \ @@ -760,10 +756,10 @@ static int rsnd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) /* set clock master for audio interface */ switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { - case SND_SOC_DAIFMT_CBM_CFM: + case SND_SOC_DAIFMT_CBP_CFP: rdai->clk_master = 0; break; - case SND_SOC_DAIFMT_CBS_CFS: + case SND_SOC_DAIFMT_CBC_CFC: rdai->clk_master = 1; /* cpu is master */ break; default: @@ -1043,6 +1039,31 @@ static int rsnd_soc_dai_prepare(struct snd_pcm_substream *substream, return rsnd_dai_call(prepare, io, priv); } +static u64 rsnd_soc_dai_formats[] = { + /* + * 1st Priority + * + * Well tested formats. + * Select below from Sound Card, not auto + * SND_SOC_DAIFMT_CBC_CFC + * SND_SOC_DAIFMT_CBP_CFP + */ + SND_SOC_POSSIBLE_DAIFMT_I2S | + SND_SOC_POSSIBLE_DAIFMT_RIGHT_J | + SND_SOC_POSSIBLE_DAIFMT_LEFT_J | + SND_SOC_POSSIBLE_DAIFMT_NB_NF | + SND_SOC_POSSIBLE_DAIFMT_NB_IF | + SND_SOC_POSSIBLE_DAIFMT_IB_NF | + SND_SOC_POSSIBLE_DAIFMT_IB_IF, + /* + * 2nd Priority + * + * Supported, but not well tested + */ + SND_SOC_POSSIBLE_DAIFMT_DSP_A | + SND_SOC_POSSIBLE_DAIFMT_DSP_B, +}; + static const struct snd_soc_dai_ops rsnd_soc_dai_ops = { .startup = rsnd_soc_dai_startup, .shutdown = rsnd_soc_dai_shutdown, @@ -1050,6 +1071,8 @@ static const struct snd_soc_dai_ops rsnd_soc_dai_ops = { .set_fmt = rsnd_soc_dai_set_fmt, .set_tdm_slot = rsnd_soc_set_dai_tdm_slot, .prepare = rsnd_soc_dai_prepare, + .auto_selectable_formats = rsnd_soc_dai_formats, + .num_auto_selectable_formats = ARRAY_SIZE(rsnd_soc_dai_formats), }; static void rsnd_parse_tdm_split_mode(struct rsnd_priv *priv, @@ -1129,7 +1152,7 @@ static void rsnd_parse_connect_graph(struct rsnd_priv *priv, of_node_put(remote_node); } -void rsnd_parse_connect_common(struct rsnd_dai *rdai, +void rsnd_parse_connect_common(struct rsnd_dai *rdai, char *name, struct rsnd_mod* (*mod_get)(struct rsnd_priv *priv, int id), struct device_node *node, struct device_node *playback, @@ -1144,7 +1167,11 @@ void rsnd_parse_connect_common(struct rsnd_dai *rdai, i = 0; for_each_child_of_node(node, np) { - struct rsnd_mod *mod = mod_get(priv, i); + struct rsnd_mod *mod; + + i = rsnd_node_fixed_index(np, name, i); + + mod = mod_get(priv, i); if (np == playback) rsnd_dai_connect(mod, &rdai->playback, mod->type); @@ -1156,6 +1183,56 @@ void rsnd_parse_connect_common(struct rsnd_dai *rdai, of_node_put(node); } +int rsnd_node_fixed_index(struct device_node *node, char *name, int idx) +{ + char node_name[16]; + + /* + * rsnd is assuming each device nodes are sequential numbering, + * but some of them are not. + * This function adjusts index for it. + * + * ex) + * Normal case, special case + * ssi-0 + * ssi-1 + * ssi-2 + * ssi-3 ssi-3 + * ssi-4 ssi-4 + * ... + * + * assume Max 64 node + */ + for (; idx < 64; idx++) { + snprintf(node_name, sizeof(node_name), "%s-%d", name, idx); + + if (strncmp(node_name, of_node_full_name(node), sizeof(node_name)) == 0) + return idx; + } + + return -EINVAL; +} + +int rsnd_node_count(struct rsnd_priv *priv, struct device_node *node, char *name) +{ + struct device *dev = rsnd_priv_to_dev(priv); + struct device_node *np; + int i; + + i = 0; + for_each_child_of_node(node, np) { + i = rsnd_node_fixed_index(np, name, i); + if (i < 0) { + dev_err(dev, "strange node numbering (%s)", + of_node_full_name(node)); + return 0; + } + i++; + } + + return i; +} + static struct device_node *rsnd_dai_of_node(struct rsnd_priv *priv, int *is_graph) { @@ -1388,6 +1465,26 @@ static int rsnd_dai_probe(struct rsnd_priv *priv) /* * pcm ops */ +static int rsnd_hw_update(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params) +{ + struct snd_soc_dai *dai = rsnd_substream_to_dai(substream); + struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai); + struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream); + struct rsnd_priv *priv = rsnd_io_to_priv(io); + unsigned long flags; + int ret; + + spin_lock_irqsave(&priv->lock, flags); + if (hw_params) + ret = rsnd_dai_call(hw_params, io, substream, hw_params); + else + ret = rsnd_dai_call(hw_free, io, substream); + spin_unlock_irqrestore(&priv->lock, flags); + + return ret; +} + static int rsnd_hw_params(struct snd_soc_component *component, struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) @@ -1495,17 +1592,13 @@ static int rsnd_hw_params(struct snd_soc_component *component, } } - return rsnd_dai_call(hw_params, io, substream, hw_params); + return rsnd_hw_update(substream, hw_params); } static int rsnd_hw_free(struct snd_soc_component *component, struct snd_pcm_substream *substream) { - struct snd_soc_dai *dai = rsnd_substream_to_dai(substream); - struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai); - struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream); - - return rsnd_dai_call(hw_free, io, substream); + return rsnd_hw_update(substream, NULL); } static snd_pcm_uframes_t rsnd_pointer(struct snd_soc_component *component, @@ -1715,6 +1808,7 @@ int rsnd_kctrl_new(struct rsnd_mod *mod, */ static const struct snd_soc_component_driver rsnd_soc_component = { .name = "rsnd", + .probe = rsnd_debugfs_probe, .hw_params = rsnd_hw_params, .hw_free = rsnd_hw_free, .pointer = rsnd_pointer, diff --git a/sound/soc/sh/rcar/ctu.c b/sound/soc/sh/rcar/ctu.c index 20eecd088d13..6156445bcb69 100644 --- a/sound/soc/sh/rcar/ctu.c +++ b/sound/soc/sh/rcar/ctu.c @@ -275,6 +275,19 @@ static int rsnd_ctu_id_sub(struct rsnd_mod *mod) return mod->id % 4; } +#ifdef CONFIG_DEBUG_FS +static void rsnd_ctu_debug_info(struct seq_file *m, + struct rsnd_dai_stream *io, + struct rsnd_mod *mod) +{ + rsnd_debugfs_mod_reg_show(m, mod, RSND_GEN2_SCU, + 0x500 + rsnd_mod_id_raw(mod) * 0x100, 0x100); +} +#define DEBUG_INFO .debug_info = rsnd_ctu_debug_info +#else +#define DEBUG_INFO +#endif + static struct rsnd_mod_ops rsnd_ctu_ops = { .name = CTU_NAME, .probe = rsnd_ctu_probe_, @@ -285,6 +298,7 @@ static struct rsnd_mod_ops rsnd_ctu_ops = { .id = rsnd_ctu_id, .id_sub = rsnd_ctu_id_sub, .id_cmd = rsnd_mod_id_raw, + DEBUG_INFO }; struct rsnd_mod *rsnd_ctu_mod_get(struct rsnd_priv *priv, int id) diff --git a/sound/soc/sh/rcar/debugfs.c b/sound/soc/sh/rcar/debugfs.c new file mode 100644 index 000000000000..26d3b310b9db --- /dev/null +++ b/sound/soc/sh/rcar/debugfs.c @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// // Renesas R-Car debugfs support +// +// Copyright (c) 2021 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> +// +// > mount -t debugfs none /sys/kernel/debug +// > cd /sys/kernel/debug/asoc/rcar-sound/ec500000.sound/rdai{N}/ +// > cat playback/xxx +// > cat capture/xxx +// +#ifdef CONFIG_DEBUG_FS + +#include <linux/debugfs.h> +#include "rsnd.h" + +static int rsnd_debugfs_show(struct seq_file *m, void *v) +{ + struct rsnd_dai_stream *io = m->private; + struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io); + struct rsnd_priv *priv = rsnd_mod_to_priv(mod); + int i; + + /* adg is out of mods */ + rsnd_adg_clk_dbg_info(priv, m); + + for_each_rsnd_mod(i, mod, io) { + u32 *status = mod->ops->get_status(mod, io, mod->type); + + seq_printf(m, "name: %s\n", rsnd_mod_name(mod)); + seq_printf(m, "status: %08x\n", *status); + + if (mod->ops->debug_info) + mod->ops->debug_info(m, io, mod); + } + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(rsnd_debugfs); + +void rsnd_debugfs_reg_show(struct seq_file *m, phys_addr_t _addr, + void __iomem *base, int offset, int size) +{ + int i, j; + + for (i = 0; i < size; i += 0x10) { + phys_addr_t addr = _addr + offset + i; + + seq_printf(m, "%pa:", &addr); + for (j = 0; j < 0x10; j += 0x4) + seq_printf(m, " %08x", __raw_readl(base + offset + i + j)); + seq_puts(m, "\n"); + } +} + +void rsnd_debugfs_mod_reg_show(struct seq_file *m, struct rsnd_mod *mod, + int reg_id, int offset, int size) +{ + struct rsnd_priv *priv = rsnd_mod_to_priv(mod); + + rsnd_debugfs_reg_show(m, + rsnd_gen_get_phy_addr(priv, reg_id), + rsnd_gen_get_base_addr(priv, reg_id), + offset, size); +} + +int rsnd_debugfs_probe(struct snd_soc_component *component) +{ + struct rsnd_priv *priv = dev_get_drvdata(component->dev); + struct rsnd_dai *rdai; + struct dentry *dir; + char name[64]; + int i; + + /* Gen1 is not supported */ + if (rsnd_is_gen1(priv)) + return 0; + + for_each_rsnd_dai(rdai, priv, i) { + /* + * created debugfs will be automatically + * removed, nothing to do for _remove. + * see + * soc_cleanup_component_debugfs() + */ + snprintf(name, sizeof(name), "rdai%d", i); + dir = debugfs_create_dir(name, component->debugfs_root); + + debugfs_create_file("playback", 0444, dir, &rdai->playback, &rsnd_debugfs_fops); + debugfs_create_file("capture", 0444, dir, &rdai->capture, &rsnd_debugfs_fops); + } + + return 0; +} + +#endif /* CONFIG_DEBUG_FS */ diff --git a/sound/soc/sh/rcar/dma.c b/sound/soc/sh/rcar/dma.c index 95aa26d62e4f..82d16e037d9a 100644 --- a/sound/soc/sh/rcar/dma.c +++ b/sound/soc/sh/rcar/dma.c @@ -44,7 +44,8 @@ struct rsnd_dma { }; struct rsnd_dma_ctrl { - void __iomem *base; + void __iomem *ppbase; + phys_addr_t ppres; int dmaen_num; int dmapp_num; }; @@ -236,16 +237,18 @@ static int rsnd_dmaen_start(struct rsnd_mod *mod, return 0; } -struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, - struct rsnd_mod *mod, char *name) +struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, char *name, + struct rsnd_mod *mod, char *x) { struct dma_chan *chan = NULL; struct device_node *np; int i = 0; for_each_child_of_node(of_node, np) { + i = rsnd_node_fixed_index(np, name, i); + if (i == rsnd_mod_id_raw(mod) && (!chan)) - chan = of_dma_request_slave_channel(np, name); + chan = of_dma_request_slave_channel(np, x); i++; } @@ -415,7 +418,7 @@ static u32 rsnd_dmapp_get_chcr(struct rsnd_dai_stream *io, } #define rsnd_dmapp_addr(dmac, dma, reg) \ - (dmac->base + 0x20 + reg + \ + (dmac->ppbase + 0x20 + reg + \ (0x10 * rsnd_dma_to_dmapp(dma)->dmapp_id)) static void rsnd_dmapp_write(struct rsnd_dma *dma, u32 data, u32 reg) { @@ -504,12 +507,31 @@ static int rsnd_dmapp_attach(struct rsnd_dai_stream *io, return 0; } +#ifdef CONFIG_DEBUG_FS +static void rsnd_dmapp_debug_info(struct seq_file *m, + struct rsnd_dai_stream *io, + struct rsnd_mod *mod) +{ + struct rsnd_priv *priv = rsnd_mod_to_priv(mod); + struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv); + struct rsnd_dma *dma = rsnd_mod_to_dma(mod); + struct rsnd_dmapp *dmapp = rsnd_dma_to_dmapp(dma); + + rsnd_debugfs_reg_show(m, dmac->ppres, dmac->ppbase, + 0x20 + 0x10 * dmapp->dmapp_id, 0x10); +} +#define DEBUG_INFO .debug_info = rsnd_dmapp_debug_info +#else +#define DEBUG_INFO +#endif + static struct rsnd_mod_ops rsnd_dmapp_ops = { .name = "audmac-pp", .start = rsnd_dmapp_start, .stop = rsnd_dmapp_stop, .quit = rsnd_dmapp_stop, .get_status = rsnd_mod_get_status, + DEBUG_INFO }; /* @@ -864,9 +886,10 @@ int rsnd_dma_probe(struct rsnd_priv *priv) } dmac->dmapp_num = 0; - dmac->base = devm_ioremap_resource(dev, res); - if (IS_ERR(dmac->base)) - return PTR_ERR(dmac->base); + dmac->ppres = res->start; + dmac->ppbase = devm_ioremap_resource(dev, res); + if (IS_ERR(dmac->ppbase)) + return PTR_ERR(dmac->ppbase); priv->dma = dmac; diff --git a/sound/soc/sh/rcar/dvc.c b/sound/soc/sh/rcar/dvc.c index 8d91c0eb0880..5137e03a9d7c 100644 --- a/sound/soc/sh/rcar/dvc.c +++ b/sound/soc/sh/rcar/dvc.c @@ -282,9 +282,22 @@ static struct dma_chan *rsnd_dvc_dma_req(struct rsnd_dai_stream *io, struct rsnd_priv *priv = rsnd_mod_to_priv(mod); return rsnd_dma_request_channel(rsnd_dvc_of_node(priv), - mod, "tx"); + DVC_NAME, mod, "tx"); } +#ifdef CONFIG_DEBUG_FS +static void rsnd_dvc_debug_info(struct seq_file *m, + struct rsnd_dai_stream *io, + struct rsnd_mod *mod) +{ + rsnd_debugfs_mod_reg_show(m, mod, RSND_GEN2_SCU, + 0xe00 + rsnd_mod_id(mod) * 0x100, 0x60); +} +#define DEBUG_INFO .debug_info = rsnd_dvc_debug_info +#else +#define DEBUG_INFO +#endif + static struct rsnd_mod_ops rsnd_dvc_ops = { .name = DVC_NAME, .dma_req = rsnd_dvc_dma_req, @@ -293,6 +306,7 @@ static struct rsnd_mod_ops rsnd_dvc_ops = { .quit = rsnd_dvc_quit, .pcm_new = rsnd_dvc_pcm_new, .get_status = rsnd_mod_get_status, + DEBUG_INFO }; struct rsnd_mod *rsnd_dvc_mod_get(struct rsnd_priv *priv, int id) diff --git a/sound/soc/sh/rcar/gen.c b/sound/soc/sh/rcar/gen.c index 8bd49c8a9517..925565baaa41 100644 --- a/sound/soc/sh/rcar/gen.c +++ b/sound/soc/sh/rcar/gen.c @@ -141,6 +141,15 @@ phys_addr_t rsnd_gen_get_phy_addr(struct rsnd_priv *priv, int reg_id) return gen->res[reg_id]; } +#ifdef CONFIG_DEBUG_FS +void __iomem *rsnd_gen_get_base_addr(struct rsnd_priv *priv, int reg_id) +{ + struct rsnd_gen *gen = rsnd_priv_to_gen(priv); + + return gen->base[reg_id]; +} +#endif + #define rsnd_gen_regmap_init(priv, id_size, reg_id, name, conf) \ _rsnd_gen_regmap_init(priv, id_size, reg_id, name, conf, ARRAY_SIZE(conf)) static int _rsnd_gen_regmap_init(struct rsnd_priv *priv, diff --git a/sound/soc/sh/rcar/mix.c b/sound/soc/sh/rcar/mix.c index a3e0370f5704..3572c2c5686c 100644 --- a/sound/soc/sh/rcar/mix.c +++ b/sound/soc/sh/rcar/mix.c @@ -250,6 +250,19 @@ static int rsnd_mix_pcm_new(struct rsnd_mod *mod, return ret; } +#ifdef CONFIG_DEBUG_FS +static void rsnd_mix_debug_info(struct seq_file *m, + struct rsnd_dai_stream *io, + struct rsnd_mod *mod) +{ + rsnd_debugfs_mod_reg_show(m, mod, RSND_GEN2_SCU, + 0xd00 + rsnd_mod_id(mod) * 0x40, 0x30); +} +#define DEBUG_INFO .debug_info = rsnd_mix_debug_info +#else +#define DEBUG_INFO +#endif + static struct rsnd_mod_ops rsnd_mix_ops = { .name = MIX_NAME, .probe = rsnd_mix_probe_, @@ -257,6 +270,7 @@ static struct rsnd_mod_ops rsnd_mix_ops = { .quit = rsnd_mix_quit, .pcm_new = rsnd_mix_pcm_new, .get_status = rsnd_mod_get_status, + DEBUG_INFO }; struct rsnd_mod *rsnd_mix_mod_get(struct rsnd_priv *priv, int id) diff --git a/sound/soc/sh/rcar/rsnd.h b/sound/soc/sh/rcar/rsnd.h index 1255a85151db..6580bab0e229 100644 --- a/sound/soc/sh/rcar/rsnd.h +++ b/sound/soc/sh/rcar/rsnd.h @@ -269,8 +269,8 @@ u32 rsnd_get_busif_shift(struct rsnd_dai_stream *io, struct rsnd_mod *mod); int rsnd_dma_attach(struct rsnd_dai_stream *io, struct rsnd_mod *mod, struct rsnd_mod **dma_mod); int rsnd_dma_probe(struct rsnd_priv *priv); -struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, - struct rsnd_mod *mod, char *name); +struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, char *name, + struct rsnd_mod *mod, char *x); /* * R-Car sound mod @@ -345,6 +345,11 @@ struct rsnd_mod_ops { int (*id)(struct rsnd_mod *mod); int (*id_sub)(struct rsnd_mod *mod); int (*id_cmd)(struct rsnd_mod *mod); + +#ifdef CONFIG_DEBUG_FS + void (*debug_info)(struct seq_file *m, + struct rsnd_dai_stream *io, struct rsnd_mod *mod); +#endif }; struct rsnd_dai_stream; @@ -359,19 +364,13 @@ struct rsnd_mod { /* * status * - * 0xH0000CB0 + * 0xH000DCB0 * * B 0: init 1: quit * C 0: start 1: stop * D 0: hw_params 1: hw_free * * H is always called (see __rsnd_mod_call) - * H 0: probe 1: remove - * H 0: pcm_new - * H 0: fallback - * H 0: pointer - * H 0: prepare - * H 0: cleanup */ #define __rsnd_mod_shift_init 4 #define __rsnd_mod_shift_quit 4 @@ -392,12 +391,12 @@ struct rsnd_mod { #define __rsnd_mod_add_remove 0 #define __rsnd_mod_add_prepare 0 #define __rsnd_mod_add_cleanup 0 -#define __rsnd_mod_add_init 1 -#define __rsnd_mod_add_quit -1 -#define __rsnd_mod_add_start 1 -#define __rsnd_mod_add_stop -1 -#define __rsnd_mod_add_hw_params 1 -#define __rsnd_mod_add_hw_free -1 +#define __rsnd_mod_add_init 1 /* needs protect */ +#define __rsnd_mod_add_quit -1 /* needs protect */ +#define __rsnd_mod_add_start 1 /* needs protect */ +#define __rsnd_mod_add_stop -1 /* needs protect */ +#define __rsnd_mod_add_hw_params 1 /* needs protect */ +#define __rsnd_mod_add_hw_free -1 /* needs protect */ #define __rsnd_mod_add_irq 0 #define __rsnd_mod_add_pcm_new 0 #define __rsnd_mod_add_fallback 0 @@ -407,16 +406,16 @@ struct rsnd_mod { #define __rsnd_mod_call_remove 0 #define __rsnd_mod_call_prepare 0 #define __rsnd_mod_call_cleanup 0 -#define __rsnd_mod_call_init 0 -#define __rsnd_mod_call_quit 1 -#define __rsnd_mod_call_start 0 -#define __rsnd_mod_call_stop 1 +#define __rsnd_mod_call_init 0 /* needs protect */ +#define __rsnd_mod_call_quit 1 /* needs protect */ +#define __rsnd_mod_call_start 0 /* needs protect */ +#define __rsnd_mod_call_stop 1 /* needs protect */ +#define __rsnd_mod_call_hw_params 0 /* needs protect */ +#define __rsnd_mod_call_hw_free 1 /* needs protect */ #define __rsnd_mod_call_irq 0 #define __rsnd_mod_call_pcm_new 0 #define __rsnd_mod_call_fallback 0 -#define __rsnd_mod_call_hw_params 0 #define __rsnd_mod_call_pointer 0 -#define __rsnd_mod_call_hw_free 1 #define rsnd_mod_to_priv(mod) ((mod)->priv) #define rsnd_mod_power_on(mod) clk_enable((mod)->clk) @@ -455,11 +454,13 @@ struct rsnd_mod *rsnd_mod_next(int *iterator, #define for_each_rsnd_mod_array(iterator, pos, io, array) \ for_each_rsnd_mod_arrays(iterator, pos, io, array, ARRAY_SIZE(array)) -void rsnd_parse_connect_common(struct rsnd_dai *rdai, +void rsnd_parse_connect_common(struct rsnd_dai *rdai, char *name, struct rsnd_mod* (*mod_get)(struct rsnd_priv *priv, int id), struct device_node *node, struct device_node *playback, struct device_node *capture); +int rsnd_node_count(struct rsnd_priv *priv, struct device_node *node, char *name); +int rsnd_node_fixed_index(struct device_node *node, char *name, int idx); int rsnd_channel_normalization(int chan); #define rsnd_runtime_channel_original(io) \ @@ -592,6 +593,9 @@ void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg); phys_addr_t rsnd_gen_get_phy_addr(struct rsnd_priv *priv, int reg_id); +#ifdef CONFIG_DEBUG_FS +void __iomem *rsnd_gen_get_base_addr(struct rsnd_priv *priv, int reg_id); +#endif /* * R-Car ADG @@ -610,6 +614,7 @@ int rsnd_adg_set_cmd_timsel_gen2(struct rsnd_mod *cmd_mod, #define rsnd_adg_clk_enable(priv) rsnd_adg_clk_control(priv, 1) #define rsnd_adg_clk_disable(priv) rsnd_adg_clk_control(priv, 0) void rsnd_adg_clk_control(struct rsnd_priv *priv, int enable); +void rsnd_adg_clk_dbg_info(struct rsnd_priv *priv, struct seq_file *m); /* * R-Car sound priv @@ -776,6 +781,7 @@ void rsnd_ssi_remove(struct rsnd_priv *priv); struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id); int rsnd_ssi_use_busif(struct rsnd_dai_stream *io); u32 rsnd_ssi_multi_secondaries_runtime(struct rsnd_dai_stream *io); +int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod); #define rsnd_ssi_is_pin_sharing(io) \ __rsnd_ssi_is_pin_sharing(rsnd_io_to_mod_ssi(io)) @@ -799,6 +805,7 @@ void rsnd_parse_connect_ssiu(struct rsnd_dai *rdai, struct device_node *playback, struct device_node *capture); #define rsnd_ssiu_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_SSIU) +bool rsnd_ssiu_busif_err_status_clear(struct rsnd_mod *mod); /* * R-Car SRC @@ -815,7 +822,7 @@ unsigned int rsnd_src_get_rate(struct rsnd_priv *priv, #define rsnd_src_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_SRC) #define rsnd_parse_connect_src(rdai, playback, capture) \ - rsnd_parse_connect_common(rdai, rsnd_src_mod_get, \ + rsnd_parse_connect_common(rdai, "src", rsnd_src_mod_get, \ rsnd_src_of_node(rsnd_rdai_to_priv(rdai)), \ playback, capture) @@ -827,7 +834,7 @@ void rsnd_ctu_remove(struct rsnd_priv *priv); struct rsnd_mod *rsnd_ctu_mod_get(struct rsnd_priv *priv, int id); #define rsnd_ctu_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_CTU) #define rsnd_parse_connect_ctu(rdai, playback, capture) \ - rsnd_parse_connect_common(rdai, rsnd_ctu_mod_get, \ + rsnd_parse_connect_common(rdai, "ctu", rsnd_ctu_mod_get, \ rsnd_ctu_of_node(rsnd_rdai_to_priv(rdai)), \ playback, capture) @@ -839,7 +846,7 @@ void rsnd_mix_remove(struct rsnd_priv *priv); struct rsnd_mod *rsnd_mix_mod_get(struct rsnd_priv *priv, int id); #define rsnd_mix_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_MIX) #define rsnd_parse_connect_mix(rdai, playback, capture) \ - rsnd_parse_connect_common(rdai, rsnd_mix_mod_get, \ + rsnd_parse_connect_common(rdai, "mix", rsnd_mix_mod_get, \ rsnd_mix_of_node(rsnd_rdai_to_priv(rdai)), \ playback, capture) @@ -851,7 +858,7 @@ void rsnd_dvc_remove(struct rsnd_priv *priv); struct rsnd_mod *rsnd_dvc_mod_get(struct rsnd_priv *priv, int id); #define rsnd_dvc_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_DVC) #define rsnd_parse_connect_dvc(rdai, playback, capture) \ - rsnd_parse_connect_common(rdai, rsnd_dvc_mod_get, \ + rsnd_parse_connect_common(rdai, "dvc", rsnd_dvc_mod_get, \ rsnd_dvc_of_node(rsnd_rdai_to_priv(rdai)), \ playback, capture) @@ -879,9 +886,10 @@ void rsnd_mod_make_sure(struct rsnd_mod *mod, enum rsnd_mod_type type); * * #define RSND_DEBUG_NO_IRQ_STATUS 1 */ -#define rsnd_dbg_irq_status(dev, param...) \ +#define rsnd_print_irq_status(dev, param...) do { \ if (!IS_BUILTIN(RSND_DEBUG_NO_IRQ_STATUS)) \ - dev_dbg(dev, param) + dev_info(dev, param); \ +} while (0) /* * If you don't need rsnd_dai_call debug message, @@ -894,3 +902,14 @@ void rsnd_mod_make_sure(struct rsnd_mod *mod, enum rsnd_mod_type type); dev_dbg(dev, param) #endif + +#ifdef CONFIG_DEBUG_FS +int rsnd_debugfs_probe(struct snd_soc_component *component); +void rsnd_debugfs_reg_show(struct seq_file *m, phys_addr_t _addr, + void __iomem *base, int offset, int size); +void rsnd_debugfs_mod_reg_show(struct seq_file *m, struct rsnd_mod *mod, + int reg_id, int offset, int size); + +#else +#define rsnd_debugfs_probe NULL +#endif diff --git a/sound/soc/sh/rcar/src.c b/sound/soc/sh/rcar/src.c index 628af8f3920d..42a100c6303d 100644 --- a/sound/soc/sh/rcar/src.c +++ b/sound/soc/sh/rcar/src.c @@ -17,7 +17,7 @@ /* * you can enable below define if you don't need * SSI interrupt status debug message when debugging - * see rsnd_dbg_irq_status() + * see rsnd_print_irq_status() * * #define RSND_DEBUG_NO_IRQ_STATUS 1 */ @@ -82,7 +82,7 @@ static struct dma_chan *rsnd_src_dma_req(struct rsnd_dai_stream *io, int is_play = rsnd_io_is_play(io); return rsnd_dma_request_channel(rsnd_src_of_node(priv), - mod, + SRC_NAME, mod, is_play ? "rx" : "tx"); } @@ -421,8 +421,8 @@ static bool rsnd_src_error_occurred(struct rsnd_mod *mod) status0 = rsnd_mod_read(mod, SCU_SYS_STATUS0); status1 = rsnd_mod_read(mod, SCU_SYS_STATUS1); if ((status0 & val0) || (status1 & val1)) { - rsnd_dbg_irq_status(dev, "%s err status : 0x%08x, 0x%08x\n", - rsnd_mod_name(mod), status0, status1); + rsnd_print_irq_status(dev, "%s err status : 0x%08x, 0x%08x\n", + rsnd_mod_name(mod), status0, status1); ret = true; } @@ -597,6 +597,25 @@ static int rsnd_src_pcm_new(struct rsnd_mod *mod, return ret; } +#ifdef CONFIG_DEBUG_FS +static void rsnd_src_debug_info(struct seq_file *m, + struct rsnd_dai_stream *io, + struct rsnd_mod *mod) +{ + rsnd_debugfs_mod_reg_show(m, mod, RSND_GEN2_SCU, + rsnd_mod_id(mod) * 0x20, 0x20); + seq_puts(m, "\n"); + rsnd_debugfs_mod_reg_show(m, mod, RSND_GEN2_SCU, + 0x1c0, 0x20); + seq_puts(m, "\n"); + rsnd_debugfs_mod_reg_show(m, mod, RSND_GEN2_SCU, + 0x200 + rsnd_mod_id(mod) * 0x40, 0x40); +} +#define DEBUG_INFO .debug_info = rsnd_src_debug_info +#else +#define DEBUG_INFO +#endif + static struct rsnd_mod_ops rsnd_src_ops = { .name = SRC_NAME, .dma_req = rsnd_src_dma_req, @@ -608,6 +627,7 @@ static struct rsnd_mod_ops rsnd_src_ops = { .irq = rsnd_src_irq, .pcm_new = rsnd_src_pcm_new, .get_status = rsnd_mod_get_status, + DEBUG_INFO }; struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id) @@ -636,7 +656,7 @@ int rsnd_src_probe(struct rsnd_priv *priv) if (!node) return 0; /* not used is not error */ - nr = of_get_child_count(node); + nr = rsnd_node_count(priv, node, SRC_NAME); if (!nr) { ret = -EINVAL; goto rsnd_src_probe_done; @@ -656,6 +676,8 @@ int rsnd_src_probe(struct rsnd_priv *priv) if (!of_device_is_available(np)) goto skip; + i = rsnd_node_fixed_index(np, SRC_NAME, i); + src = rsnd_src_get(priv, i); snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d", diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c index e29482c26d6a..27f34ca6059d 100644 --- a/sound/soc/sh/rcar/ssi.c +++ b/sound/soc/sh/rcar/ssi.c @@ -11,7 +11,7 @@ /* * you can enable below define if you don't need * SSI interrupt status debug message when debugging - * see rsnd_dbg_irq_status() + * see rsnd_print_irq_status() * * #define RSND_DEBUG_NO_IRQ_STATUS 1 */ @@ -117,8 +117,6 @@ struct rsnd_ssi { (rsnd_ssi_run_mods(io) & (1 << rsnd_mod_id(mod))) #define rsnd_ssi_can_output_clk(mod) (!__rsnd_ssi_is_pin_sharing(mod)) -static int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod); - int rsnd_ssi_use_busif(struct rsnd_dai_stream *io) { struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io); @@ -359,96 +357,6 @@ static void rsnd_ssi_master_clk_stop(struct rsnd_mod *mod, rsnd_adg_ssi_clk_stop(mod); } -/* enable busif buffer over/under run interrupt. */ -#define rsnd_ssi_busif_err_irq_enable(mod) rsnd_ssi_busif_err_irq_ctrl(mod, 1) -#define rsnd_ssi_busif_err_irq_disable(mod) rsnd_ssi_busif_err_irq_ctrl(mod, 0) -static void rsnd_ssi_busif_err_irq_ctrl(struct rsnd_mod *mod, int enable) -{ - u32 sys_int_enable = 0; - int id = rsnd_mod_id(mod); - int i; - - switch (id) { - case 0: - case 1: - case 2: - case 3: - case 4: - for (i = 0; i < 4; i++) { - sys_int_enable = rsnd_mod_read(mod, SSI_SYS_INT_ENABLE(i * 2)); - if (enable) - sys_int_enable |= 0xf << (id * 4); - else - sys_int_enable &= ~(0xf << (id * 4)); - rsnd_mod_write(mod, - SSI_SYS_INT_ENABLE(i * 2), - sys_int_enable); - } - break; - case 9: - for (i = 0; i < 4; i++) { - sys_int_enable = rsnd_mod_read(mod, SSI_SYS_INT_ENABLE((i * 2) + 1)); - if (enable) - sys_int_enable |= 0xf << 4; - else - sys_int_enable &= ~(0xf << 4); - rsnd_mod_write(mod, - SSI_SYS_INT_ENABLE((i * 2) + 1), - sys_int_enable); - } - break; - } -} - -static bool rsnd_ssi_busif_err_status_clear(struct rsnd_mod *mod) -{ - struct rsnd_priv *priv = rsnd_mod_to_priv(mod); - struct device *dev = rsnd_priv_to_dev(priv); - u32 status; - bool stop = false; - int id = rsnd_mod_id(mod); - int i; - - switch (id) { - case 0: - case 1: - case 2: - case 3: - case 4: - for (i = 0; i < 4; i++) { - status = rsnd_mod_read(mod, SSI_SYS_STATUS(i * 2)); - status &= 0xf << (id * 4); - - if (status) { - rsnd_dbg_irq_status(dev, "%s err status : 0x%08x\n", - rsnd_mod_name(mod), status); - rsnd_mod_write(mod, - SSI_SYS_STATUS(i * 2), - 0xf << (id * 4)); - stop = true; - } - } - break; - case 9: - for (i = 0; i < 4; i++) { - status = rsnd_mod_read(mod, SSI_SYS_STATUS((i * 2) + 1)); - status &= 0xf << 4; - - if (status) { - rsnd_dbg_irq_status(dev, "%s err status : 0x%08x\n", - rsnd_mod_name(mod), status); - rsnd_mod_write(mod, - SSI_SYS_STATUS((i * 2) + 1), - 0xf << 4); - stop = true; - } - } - break; - } - - return stop; -} - static void rsnd_ssi_config_init(struct rsnd_mod *mod, struct rsnd_dai_stream *io) { @@ -536,10 +444,6 @@ static void rsnd_ssi_config_init(struct rsnd_mod *mod, cr_mode = DIEN; /* PIO : enable Data interrupt */ } - /* enable busif buffer over/under run interrupt. */ - if (is_tdm || is_tdm_split) - rsnd_ssi_busif_err_irq_enable(mod); - init_end: ssi->cr_own = cr_own; ssi->cr_mode = cr_mode; @@ -594,10 +498,6 @@ static int rsnd_ssi_quit(struct rsnd_mod *mod, { struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); struct device *dev = rsnd_priv_to_dev(priv); - int is_tdm, is_tdm_split; - - is_tdm = rsnd_runtime_is_tdm(io); - is_tdm_split = rsnd_runtime_is_tdm_split(io); if (!rsnd_ssi_is_run_mods(mod, io)) return 0; @@ -619,10 +519,6 @@ static int rsnd_ssi_quit(struct rsnd_mod *mod, ssi->wsr = 0; } - /* disable busif buffer over/under run interrupt. */ - if (is_tdm || is_tdm_split) - rsnd_ssi_busif_err_irq_disable(mod); - return 0; } @@ -775,10 +671,6 @@ static void __rsnd_ssi_interrupt(struct rsnd_mod *mod, u32 status; bool elapsed = false; bool stop = false; - int is_tdm, is_tdm_split; - - is_tdm = rsnd_runtime_is_tdm(io); - is_tdm_split = rsnd_runtime_is_tdm_split(io); spin_lock(&priv->lock); @@ -794,14 +686,13 @@ static void __rsnd_ssi_interrupt(struct rsnd_mod *mod, /* DMA only */ if (is_dma && (status & (UIRQ | OIRQ))) { - rsnd_dbg_irq_status(dev, "%s err status : 0x%08x\n", - rsnd_mod_name(mod), status); + rsnd_print_irq_status(dev, "%s err status : 0x%08x\n", + rsnd_mod_name(mod), status); stop = true; } - if (is_tdm || is_tdm_split) - stop |= rsnd_ssi_busif_err_status_clear(mod); + stop |= rsnd_ssiu_busif_err_status_clear(mod); rsnd_ssi_status_clear(mod); rsnd_ssi_interrupt_out: @@ -1128,8 +1019,36 @@ static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_dai_stream *io, name = is_play ? "rx" : "tx"; return rsnd_dma_request_channel(rsnd_ssi_of_node(priv), - mod, name); + SSI_NAME, mod, name); +} + +#ifdef CONFIG_DEBUG_FS +static void rsnd_ssi_debug_info(struct seq_file *m, + struct rsnd_dai_stream *io, + struct rsnd_mod *mod) +{ + struct rsnd_dai *rdai = rsnd_io_to_rdai(io); + struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); + + seq_printf(m, "clock: %s\n", rsnd_rdai_is_clk_master(rdai) ? + "provider" : "consumer"); + seq_printf(m, "bit_clk_inv: %d\n", rdai->bit_clk_inv); + seq_printf(m, "frm_clk_inv: %d\n", rdai->frm_clk_inv); + seq_printf(m, "pin share: %d\n", __rsnd_ssi_is_pin_sharing(mod)); + seq_printf(m, "can out clk: %d\n", rsnd_ssi_can_output_clk(mod)); + seq_printf(m, "multi secondary: %d\n", rsnd_ssi_is_multi_secondary(mod, io)); + seq_printf(m, "tdm: %d, %d\n", rsnd_runtime_is_tdm(io), + rsnd_runtime_is_tdm_split(io)); + seq_printf(m, "chan: %d\n", ssi->chan); + seq_printf(m, "user: %d\n", ssi->usrcnt); + + rsnd_debugfs_mod_reg_show(m, mod, RSND_GEN2_SSI, + rsnd_mod_id(mod) * 0x40, 0x40); } +#define DEBUG_INFO .debug_info = rsnd_ssi_debug_info +#else +#define DEBUG_INFO +#endif static struct rsnd_mod_ops rsnd_ssi_dma_ops = { .name = SSI_NAME, @@ -1145,9 +1064,10 @@ static struct rsnd_mod_ops rsnd_ssi_dma_ops = { .fallback = rsnd_ssi_fallback, .hw_params = rsnd_ssi_hw_params, .get_status = rsnd_ssi_get_status, + DEBUG_INFO }; -static int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod) +int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod) { return mod->ops == &rsnd_ssi_dma_ops; } @@ -1195,7 +1115,11 @@ void rsnd_parse_connect_ssi(struct rsnd_dai *rdai, i = 0; for_each_child_of_node(node, np) { - struct rsnd_mod *mod = rsnd_ssi_mod_get(priv, i); + struct rsnd_mod *mod; + + i = rsnd_node_fixed_index(np, SSI_NAME, i); + + mod = rsnd_ssi_mod_get(priv, i); if (np == playback) rsnd_ssi_connect(mod, &rdai->playback); @@ -1238,7 +1162,7 @@ int rsnd_ssi_probe(struct rsnd_priv *priv) if (!node) return -EINVAL; - nr = of_get_child_count(node); + nr = rsnd_node_count(priv, node, SSI_NAME); if (!nr) { ret = -EINVAL; goto rsnd_ssi_probe_done; @@ -1258,6 +1182,8 @@ int rsnd_ssi_probe(struct rsnd_priv *priv) if (!of_device_is_available(np)) goto skip; + i = rsnd_node_fixed_index(np, SSI_NAME, i); + ssi = rsnd_ssi_get(priv, i); snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d", diff --git a/sound/soc/sh/rcar/ssiu.c b/sound/soc/sh/rcar/ssiu.c index 852cdeedf7e9..0d8f97633dd2 100644 --- a/sound/soc/sh/rcar/ssiu.c +++ b/sound/soc/sh/rcar/ssiu.c @@ -45,6 +45,85 @@ struct rsnd_ssiu { static const int gen2_id[] = { 0, 4, 8, 12, 13, 14, 15, 16, 17, 18 }; static const int gen3_id[] = { 0, 8, 16, 24, 32, 40, 41, 42, 43, 44 }; +/* enable busif buffer over/under run interrupt. */ +#define rsnd_ssiu_busif_err_irq_enable(mod) rsnd_ssiu_busif_err_irq_ctrl(mod, 1) +#define rsnd_ssiu_busif_err_irq_disable(mod) rsnd_ssiu_busif_err_irq_ctrl(mod, 0) +static void rsnd_ssiu_busif_err_irq_ctrl(struct rsnd_mod *mod, int enable) +{ + int id = rsnd_mod_id(mod); + int shift, offset; + int i; + + switch (id) { + case 0: + case 1: + case 2: + case 3: + case 4: + shift = id; + offset = 0; + break; + case 9: + shift = 1; + offset = 1; + break; + } + + for (i = 0; i < 4; i++) { + enum rsnd_reg reg = SSI_SYS_INT_ENABLE((i * 2) + offset); + u32 val = 0xf << (shift * 4); + u32 sys_int_enable = rsnd_mod_read(mod, reg); + + if (enable) + sys_int_enable |= val; + else + sys_int_enable &= ~val; + rsnd_mod_write(mod, reg, sys_int_enable); + } +} + +bool rsnd_ssiu_busif_err_status_clear(struct rsnd_mod *mod) +{ + bool error = false; + int id = rsnd_mod_id(mod); + int shift, offset; + int i; + + switch (id) { + case 0: + case 1: + case 2: + case 3: + case 4: + shift = id; + offset = 0; + break; + case 9: + shift = 1; + offset = 1; + break; + } + + for (i = 0; i < 4; i++) { + u32 reg = SSI_SYS_STATUS(i * 2) + offset; + u32 status = rsnd_mod_read(mod, reg); + u32 val = 0xf << (shift * 4); + + status &= val; + if (status) { + struct rsnd_priv *priv = rsnd_mod_to_priv(mod); + struct device *dev = rsnd_priv_to_dev(priv); + + rsnd_print_irq_status(dev, "%s err status : 0x%08x\n", + rsnd_mod_name(mod), status); + error = true; + } + rsnd_mod_write(mod, reg, val); + } + + return error; +} + static u32 *rsnd_ssiu_get_status(struct rsnd_mod *mod, struct rsnd_dai_stream *io, enum rsnd_mod_type type) @@ -65,23 +144,9 @@ static int rsnd_ssiu_init(struct rsnd_mod *mod, int id = rsnd_mod_id(mod); int is_clk_master = rsnd_rdai_is_clk_master(rdai); u32 val1, val2; - int i; /* clear status */ - switch (id) { - case 0: - case 1: - case 2: - case 3: - case 4: - for (i = 0; i < 4; i++) - rsnd_mod_write(mod, SSI_SYS_STATUS(i * 2), 0xf << (id * 4)); - break; - case 9: - for (i = 0; i < 4; i++) - rsnd_mod_write(mod, SSI_SYS_STATUS((i * 2) + 1), 0xf << 4); - break; - } + rsnd_ssiu_busif_err_status_clear(mod); /* * SSI_MODE0 @@ -137,12 +202,31 @@ static int rsnd_ssiu_init(struct rsnd_mod *mod, rsnd_mod_bset(mod, SSI_MODE1, 0x0013001f, val1); rsnd_mod_bset(mod, SSI_MODE2, 0x00000017, val2); + /* + * Enable busif buffer over/under run interrupt. + * It will be handled from ssi.c + * see + * __rsnd_ssi_interrupt() + */ + rsnd_ssiu_busif_err_irq_enable(mod); + + return 0; +} + +static int rsnd_ssiu_quit(struct rsnd_mod *mod, + struct rsnd_dai_stream *io, + struct rsnd_priv *priv) +{ + /* disable busif buffer over/under run interrupt. */ + rsnd_ssiu_busif_err_irq_disable(mod); + return 0; } static struct rsnd_mod_ops rsnd_ssiu_ops_gen1 = { .name = SSIU_NAME, .init = rsnd_ssiu_init, + .quit = rsnd_ssiu_quit, .get_status = rsnd_ssiu_get_status, }; @@ -311,9 +395,22 @@ static struct dma_chan *rsnd_ssiu_dma_req(struct rsnd_dai_stream *io, name = is_play ? "rx" : "tx"; return rsnd_dma_request_channel(rsnd_ssiu_of_node(priv), - mod, name); + SSIU_NAME, mod, name); } +#ifdef CONFIG_DEBUG_FS +static void rsnd_ssiu_debug_info(struct seq_file *m, + struct rsnd_dai_stream *io, + struct rsnd_mod *mod) +{ + rsnd_debugfs_mod_reg_show(m, mod, RSND_GEN2_SSIU, + rsnd_mod_id(mod) * 0x80, 0x80); +} +#define DEBUG_INFO .debug_info = rsnd_ssiu_debug_info +#else +#define DEBUG_INFO +#endif + static struct rsnd_mod_ops rsnd_ssiu_ops_gen2 = { .name = SSIU_NAME, .dma_req = rsnd_ssiu_dma_req, @@ -321,6 +418,7 @@ static struct rsnd_mod_ops rsnd_ssiu_ops_gen2 = { .start = rsnd_ssiu_start_gen2, .stop = rsnd_ssiu_stop_gen2, .get_status = rsnd_ssiu_get_status, + DEBUG_INFO }; static struct rsnd_mod *rsnd_ssiu_mod_get(struct rsnd_priv *priv, int id) @@ -336,16 +434,20 @@ static void rsnd_parse_connect_ssiu_compatible(struct rsnd_priv *priv, { struct rsnd_mod *ssi_mod = rsnd_io_to_mod_ssi(io); struct rsnd_ssiu *ssiu; + int is_dma_mode; int i; if (!ssi_mod) return; + is_dma_mode = rsnd_ssi_is_dma_mode(ssi_mod); + /* select BUSIF0 */ for_each_rsnd_ssiu(ssiu, priv, i) { struct rsnd_mod *mod = rsnd_mod_get(ssiu); - if ((rsnd_mod_id(ssi_mod) == rsnd_mod_id(mod)) && + if (is_dma_mode && + (rsnd_mod_id(ssi_mod) == rsnd_mod_id(mod)) && (rsnd_mod_id_sub(mod) == 0)) { rsnd_dai_connect(mod, io, mod->type); return; @@ -368,7 +470,11 @@ void rsnd_parse_connect_ssiu(struct rsnd_dai *rdai, int i = 0; for_each_child_of_node(node, np) { - struct rsnd_mod *mod = rsnd_ssiu_mod_get(priv, i); + struct rsnd_mod *mod; + + i = rsnd_node_fixed_index(np, SSIU_NAME, i); + + mod = rsnd_ssiu_mod_get(priv, i); if (np == playback) rsnd_dai_connect(mod, io_p, mod->type); @@ -405,10 +511,13 @@ int rsnd_ssiu_probe(struct rsnd_priv *priv) */ node = rsnd_ssiu_of_node(priv); if (node) - nr = of_get_child_count(node); + nr = rsnd_node_count(priv, node, SSIU_NAME); else nr = priv->ssi_nr; + if (!nr) + return -EINVAL; + ssiu = devm_kcalloc(dev, nr, sizeof(*ssiu), GFP_KERNEL); if (!ssiu) return -ENOMEM; |