[PATCH v2] ASoC: hdmi-codec: Get ELD in before reporting plugged event

2020-11-17 Thread Cheng-Yi Chiang
In plugged callback, ELD should be updated from display driver so that
user space can query information from ELD immediately after receiving jack
plugged event.

When jack is unplugged, clear ELD buffer so that user space does not get
obsolete information of unplugged HDMI.

Signed-off-by: Cheng-Yi Chiang 
---
Change from v1 to v2:
 - Report jack unplug event then clear ELD. This makes sure user will not get a
   cleared ELD during their usage of jack.

 sound/soc/codecs/hdmi-codec.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c
index 403d4c6a49a8..e8410b2433de 100644
--- a/sound/soc/codecs/hdmi-codec.c
+++ b/sound/soc/codecs/hdmi-codec.c
@@ -692,10 +692,16 @@ static void plugged_cb(struct device *dev, bool plugged)
 {
struct hdmi_codec_priv *hcp = dev_get_drvdata(dev);
 
-   if (plugged)
+   if (plugged) {
+   if (hcp->hcd.ops->get_eld) {
+   hcp->hcd.ops->get_eld(dev->parent, hcp->hcd.data,
+   hcp->eld, sizeof(hcp->eld));
+   }
hdmi_codec_jack_report(hcp, SND_JACK_LINEOUT);
-   else
+   } else {
hdmi_codec_jack_report(hcp, 0);
+   memset(hcp->eld, 0, sizeof(hcp->eld));
+   }
 }
 
 static int hdmi_codec_set_jack(struct snd_soc_component *component,
-- 
2.29.2.299.gdc1121823c-goog



[PATCH] ASoC: hdmi-codec: Get ELD in before reporting plugged event

2020-11-17 Thread Cheng-Yi Chiang
In plugged callback, ELD should be updated from display driver so that
user space can query information from ELD immediately after receiving jack
plugged event.

When jack is unplugged, clear ELD buffer so that user space does not get
obsolete information of unplugged HDMI.

Signed-off-by: Cheng-Yi Chiang 
---
 sound/soc/codecs/hdmi-codec.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c
index 403d4c6a49a8..f0e0e1836000 100644
--- a/sound/soc/codecs/hdmi-codec.c
+++ b/sound/soc/codecs/hdmi-codec.c
@@ -692,10 +692,16 @@ static void plugged_cb(struct device *dev, bool plugged)
 {
struct hdmi_codec_priv *hcp = dev_get_drvdata(dev);
 
-   if (plugged)
+   if (plugged) {
+   if (hcp->hcd.ops->get_eld) {
+   hcp->hcd.ops->get_eld(dev->parent, hcp->hcd.data,
+   hcp->eld, sizeof(hcp->eld));
+   }
hdmi_codec_jack_report(hcp, SND_JACK_LINEOUT);
-   else
+   } else {
+   memset(hcp->eld, 0, sizeof(hcp->eld));
hdmi_codec_jack_report(hcp, 0);
+   }
 }
 
 static int hdmi_codec_set_jack(struct snd_soc_component *component,
-- 
2.29.2.299.gdc1121823c-goog



[PATCH] ASoC: qcom: sc7180: Add missing PM ops

2020-11-09 Thread Cheng-Yi Chiang
Use PM ops snd_soc_pm_ops to handle suspend/resume like other machine
drivers.

Signed-off-by: Cheng-Yi Chiang 
---
 sound/soc/qcom/sc7180.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
index b391f64c3a80..42e366ecc689 100644
--- a/sound/soc/qcom/sc7180.c
+++ b/sound/soc/qcom/sc7180.c
@@ -258,6 +258,7 @@ static struct platform_driver sc7180_snd_driver = {
.driver = {
.name = "msm-snd-sc7180",
.of_match_table = sc7180_snd_device_id,
+   .pm = _soc_pm_ops,
},
 };
 module_platform_driver(sc7180_snd_driver);
-- 
2.29.2.222.g5d2a92d10f8-goog



[PATCH v12 2/2] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-10-26 Thread Cheng-Yi Chiang
From: Ajit Pandey 

Add new driver to register sound card on sc7180 trogdor board and
do the required configuration for lpass cpu dai and external codecs
connected over MI2S interfaces.

Signed-off-by: Ajit Pandey 
Signed-off-by: Cheng-Yi Chiang 
---
Changes from v11 to v12
- Machine driver:
 - Use the definitaion of index LPASS_DP_RX in sc7180-lpass.h.
 - Fix compatible string.
 - Replace a comma with semicolon.

 sound/soc/qcom/Kconfig  |  12 ++
 sound/soc/qcom/Makefile |   2 +
 sound/soc/qcom/sc7180.c | 266 
 3 files changed, 280 insertions(+)
 create mode 100644 sound/soc/qcom/sc7180.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 484cad31da25..41cb08bd5588 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -138,4 +138,16 @@ config SND_SOC_SM8250
  SM8250 SoC-based systems.
  Say Y if you want to use audio device on this SoCs.
 
+config SND_SOC_SC7180
+   tristate "SoC Machine driver for SC7180 boards"
+   depends on I2C
+   select SND_SOC_QCOM_COMMON
+   select SND_SOC_LPASS_SC7180
+   select SND_SOC_MAX98357A
+   select SND_SOC_RT5682_I2C
+   help
+ To add support for audio on Qualcomm Technologies Inc.
+ SC7180 SoC-based systems.
+ Say Y if you want to use audio device on this SoCs.
+
 endif #SND_SOC_QCOM
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index effa4b3f58fa..1600ae55bd34 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_SND_SOC_LPASS_SC7180) += snd-soc-lpass-sc7180.o
 snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
 snd-soc-apq8096-objs := apq8096.o
+snd-soc-sc7180-objs := sc7180.o
 snd-soc-sdm845-objs := sdm845.o
 snd-soc-sm8250-objs := sm8250.o
 snd-soc-qcom-common-objs := common.o
@@ -25,6 +26,7 @@ snd-soc-qcom-common-objs := common.o
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
 obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
+obj-$(CONFIG_SND_SOC_SC7180) += snd-soc-sc7180.o
 obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
 obj-$(CONFIG_SND_SOC_SM8250) += snd-soc-sm8250.o
 obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o
diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
new file mode 100644
index ..b391f64c3a80
--- /dev/null
+++ b/sound/soc/qcom/sc7180.c
@@ -0,0 +1,266 @@
+// SPDX-License-Identifier: GPL-2.0-only
+//
+// Copyright (c) 2020, The Linux Foundation. All rights reserved.
+//
+// sc7180.c -- ALSA SoC Machine driver for SC7180
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../codecs/rt5682.h"
+#include "common.h"
+#include "lpass.h"
+
+#define DEFAULT_MCLK_RATE  1920
+#define RT5682_PLL1_FREQ (48000 * 512)
+
+#define DRIVER_NAME "SC7180"
+
+struct sc7180_snd_data {
+   struct snd_soc_card card;
+   u32 pri_mi2s_clk_count;
+   struct snd_soc_jack hs_jack;
+   struct snd_soc_jack hdmi_jack;
+};
+
+static void sc7180_jack_free(struct snd_jack *jack)
+{
+   struct snd_soc_component *component = jack->private_data;
+
+   snd_soc_component_set_jack(component, NULL, NULL);
+}
+
+static int sc7180_headset_init(struct snd_soc_pcm_runtime *rtd)
+{
+   struct snd_soc_card *card = rtd->card;
+   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
+   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+   struct snd_soc_component *component = codec_dai->component;
+   struct snd_jack *jack;
+   int rval;
+
+   rval = snd_soc_card_jack_new(
+   card, "Headset Jack",
+   SND_JACK_HEADSET |
+   SND_JACK_HEADPHONE |
+   SND_JACK_BTN_0 | SND_JACK_BTN_1 |
+   SND_JACK_BTN_2 | SND_JACK_BTN_3,
+   >hs_jack, NULL, 0);
+
+   if (rval < 0) {
+   dev_err(card->dev, "Unable to add Headset Jack\n");
+   return rval;
+   }
+
+   jack = pdata->hs_jack.jack;
+
+   snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
+   snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
+   snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
+   snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
+
+   jack->private_data = component;
+   jack->private_free = sc7180_jack_free;
+
+   return snd_soc_component_set_jack(component, >hs_jack, NULL);
+}
+
+static int sc7180_hdmi_init(struct snd_soc_pcm_runtime *rtd)
+{
+   struct snd_soc_card *card = rtd->card;
+   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
+   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+   struct snd_soc_compo

[PATCH v12 1/2] ASoC: google: dt-bindings: Add sc7180-trogdor machine bindings

2020-10-26 Thread Cheng-Yi Chiang
Add devicetree bindings documentation file for sc7180 sound card.

Signed-off-by: Cheng-Yi Chiang 
---
Changes from v11 to v12
- Documentation:
 - Change the file and title name for new compatible string 
google,sc7180-trogdor.
 - Change the example of model name.

 .../bindings/sound/google,sc7180-trogdor.yaml | 130 ++
 1 file changed, 130 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/sound/google,sc7180-trogdor.yaml

diff --git a/Documentation/devicetree/bindings/sound/google,sc7180-trogdor.yaml 
b/Documentation/devicetree/bindings/sound/google,sc7180-trogdor.yaml
new file mode 100644
index ..efc34689d6b5
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/google,sc7180-trogdor.yaml
@@ -0,0 +1,130 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/google,sc7180-trogdor.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Google SC7180-Trogdor ASoC sound card driver
+
+maintainers:
+  - Rohit kumar 
+  - Cheng-Yi Chiang 
+
+description:
+  This binding describes the SC7180 sound card which uses LPASS for audio.
+
+properties:
+  compatible:
+const: google,sc7180-trogdor
+
+  audio-routing:
+$ref: /schemas/types.yaml#/definitions/non-unique-string-array
+description:
+  A list of the connections between audio components. Each entry is a
+  pair of strings, the first being the connection's sink, the second
+  being the connection's source.
+
+  model:
+$ref: /schemas/types.yaml#/definitions/string
+description: User specified audio sound card name
+
+  "#address-cells":
+const: 1
+
+  "#size-cells":
+const: 0
+
+patternProperties:
+  "^dai-link(@[0-9])?$":
+description:
+  Each subnode represents a dai link. Subnodes of each dai links would be
+  cpu/codec dais.
+
+type: object
+
+properties:
+  link-name:
+description: Indicates dai-link name and PCM stream name.
+$ref: /schemas/types.yaml#/definitions/string
+maxItems: 1
+
+  reg:
+description: dai link address.
+
+  cpu:
+description: Holds subnode which indicates cpu dai.
+type: object
+properties:
+  sound-dai: true
+
+  codec:
+description: Holds subnode which indicates codec dai.
+type: object
+properties:
+  sound-dai: true
+
+required:
+  - link-name
+  - cpu
+  - codec
+
+additionalProperties: false
+
+required:
+  - compatible
+  - model
+  - "#address-cells"
+  - "#size-cells"
+
+additionalProperties: false
+
+examples:
+
+  - |
+sound {
+compatible = "google,sc7180-trogdor";
+model = "sc7180-rt5682-max98357a-1mic";
+
+audio-routing =
+"Headphone Jack", "HPOL",
+"Headphone Jack", "HPOR";
+
+#address-cells = <1>;
+#size-cells = <0>;
+
+dai-link@0 {
+link-name = "MultiMedia0";
+reg = <0>;
+cpu {
+sound-dai = <_cpu 0>;
+};
+
+codec {
+sound-dai = < 0>;
+};
+};
+
+dai-link@1 {
+link-name = "MultiMedia1";
+reg = <1>;
+cpu {
+sound-dai = <_cpu 1>;
+};
+
+codec {
+sound-dai = <>;
+};
+};
+
+dai-link@2 {
+link-name = "MultiMedia2";
+reg = <2>;
+cpu {
+sound-dai = <_hdmi 0>;
+};
+
+codec {
+sound-dai = <_dp>;
+};
+};
+};
-- 
2.29.0.rc2.309.g374f81d7ae-goog



[PATCH v12 0/2] Add documentation and machine driver for SC7180 sound card

2020-10-26 Thread Cheng-Yi Chiang
Note:
- The machine driver patch is made by the collaboration of
  Cheng-Yi Chiang 
  Rohit kumar 
  Ajit Pandey 
  But Ajit has left codeaurora.

Changes from v1 to v2:
- Ducumentation: Addressed all suggestions from Doug.
- Machine driver:
  - Fix comment style for license.
  - Sort includes.
  - Remove sc7180_snd_hw_params.
  - Remove sc7180_dai_init and use aux device instead for headset jack 
registration.
  - Statically define format for Primary MI2S.
  - Atomic is not a concern because there is mutex in card to make sure
startup and shutdown happen sequentially.
  - Fix missing return -EINVAL in startup.
  - Use static sound card.
  - Use devm_kzalloc to avoid kfree.

Changes from v2 to v3:
- Ducumentation: Addressed suggestions from Srini.
- Machine driver:
  - Reuse qcom_snd_parse_of to parse properties.
  - Remove playback-only and capture-only.
  - Misc fixes to address comments.

Changes from v3 to v4:
- Ducumentation: Addressed suggestions from Rob.
 - Remove definition of dai.
 - Use 'sound-dai: true' for sound-dai schema.
 - Add reg property to pass 'make dt_binding_check' check although reg is not 
used in the driver.
- Machine driver:
 - Add Reviewed-by: Tzung-Bi Shih 

Changes from v4 to v5:
- Documentation: Addressed suggestions from Rob.
 - Add definition for "#address-cells" and "#size-cells".
 - Add additionalProperties: false
 - Add required properties.

Changes from v5 to v6:
- Documentation: Addressed suggestions from Rob.
 - Drop contains in compatible strings.
 - Only allow dai-link@[0-9]
 - Remove reg ref since it has a type definition already.

Changes from v6 to v7
- Documentation:
  - Add headset-jack and hdmi-jack to specify the codec
responsible for jack detection.
- HDMI codec driver:
  - Use component set_jack ops instead of exporting hdmi_codec_set_jack_detect.
- Machine driver:
  - Removed aux device following Stephan's suggestion.
  - Use headset-jack and hdmi-jack to specify the codec
responsible for jack detection.
  - Add support for HDMI(actually DP) playback.

Changes from v7 to v8
- Documentation:
  - Remove headset-jack and hdmi-jack.
- Machine driver:
  - Let machine driver decide whether there is a jack on the DAI.

Changes from v8 to v9
- hdmi-codec driver:
  - Fixed the naming.
- Machine driver:
  - Fixed unused fields.
  - Moved snd_soc_card_set_drvdata
  - Keep the naming of HDMI as dai name until v5 of lpass-hdmi patches.

Changes from v9 to v10
- Documentation:
  - Let compatible string be more specific for board configuration to allow
for future changes.
- Machine driver:
  - Fixed unused include and macro.
  - Add temporary macro SC7180_LPASS_DP for future change in sc7180-lpass.h.
  - Let sound card be dynamically allocated.
  - Change compatible string accordingly.

Changes from v10 to v11
- Machine driver:
  - Use temporary macro LPASS_DP_RX for future change in sc7180-lpass.h.

Changes from v11 to v12
- Documentation:
 - Change the file and title name for new compatible string 
google,sc7180-trogdor.
 - Change the example of model name.
- Machine driver:
 - Use the definitaion of index LPASS_DP_RX in sc7180-lpass.h.
 - Fix for compatible string.
 - Replace a comma with semicolon.

Ajit Pandey (1):
  ASoC: qcom: sc7180: Add machine driver for sound card registration

Cheng-Yi Chiang (1):
  ASoC: google: dt-bindings: Add sc7180-trogdor machine bindings

 .../bindings/sound/google,sc7180-trogdor.yaml | 130 +
 sound/soc/qcom/Kconfig|  12 +
 sound/soc/qcom/Makefile   |   2 +
 sound/soc/qcom/sc7180.c   | 266 ++
 4 files changed, 410 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/sound/google,sc7180-trogdor.yaml
 create mode 100644 sound/soc/qcom/sc7180.c

-- 
2.29.0.rc2.309.g374f81d7ae-goog



Re: [PATCH v11 2/3] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-10-23 Thread Cheng-yi Chiang
Sorry for resending this mail.
I forgot to use plain text mode in the previous mail.
On Thu, Oct 22, 2020 at 6:12 PM Srinivas Kandagatla
 wrote:
>
>
>
> On 22/10/2020 04:29, Tzung-Bi Shih wrote:
> > Hi, sorry for jumping into your discussion but I am trying to
> > summarize them to make sure we are on the same page.  Pardon me to
> > manually copy-and-paste partial sentences to quote.
> >
> > ACK:
> > - Don't expose DAI connections in compatible strings.
> > - Use "model" DT property to make the card more UCM2-friendly.
> > - Expose new DT properties to distinguish different DMIC models.
> >
> > NACK:
> > - All the board variations using exactly the same compatible string.
> > => This is less realistic.  Although the CODECS information can be
> > retrieved from DT, it is inevitable to have some custom code for each
> > CODEC.
> >
> > Per Mark's words:
> >> a different CODEC is something that often justifies a separate compatible
> > I think we should use different compatible strings for new CODECS
> > combinations.  And we should try to reuse the machine driver if they
> > share the most code.  In the worst case, introduce a new machine
> > driver for the new CODECS combinations.
> >
> > - Srinivas's suggestion to set driver_name.
> > e.g. card->driver_name = "SM8250";
> > => This sounds like a new DT property should be parsed in
> > sound/soc/qcom/common.c.  For example: "qcom,family"?  But as we do
> > less care about UCM2 for now, I would prefer to just leave it as is.
> >
> No, you can just hardcode this driver_name in your machine driver rather
> than getting it from DT, this is how everyone does!.
> So need of adding anything to common.c
>
ACK
> The thing that I suggested to add to common.c is setting card->long_name
> from "model" property.
>

NACK
I found that I don't need to set card->long_name in common.c because
soc-core.c already sets longname using card->name if
card->long_name is NULL.

soc_setup_card_name(card->snd_card->longname,
card->long_name, card->name, 0);

So we can leave common.c as it is and still get long name.

> >
> > I would expect the following variants in DTS (just for example):
> >
> > sound {
> >compatible = "qcom,sc7180-trogdor";
> Make sure that vendor name is correct here, am not sure if trogdor is
> qcom board or Google own board!
ACK
I should use "google,sc7180-trogdor" because google is the vendor.
>
> >model = "sc7180-rt5682-max98357a-1mic";
> > }
> >
> > sound {
> >compatible = "qcom,sc7180-trogdor";
> >model = "sc7180-rt5682-max98357a-2mic";
> >dmic-gpio = ...
> > }
> >
> > sound {
> >compatible = "qcom,sc7180-pompom";
> >model = "sc7180-adau7002-max98357a";
> > }
> >
> >
> > Please correct me if there is any misunderstanding.
>
> Looks good to me!
> thanks for doing this!
Thank you. I will collect the discussion result to send a v12, and
sync with variant board partners to submit following machine driver
changes.
We will make sure future projects follow this approach
>
> --srini
> >


Re: [PATCH v11 2/3] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-10-20 Thread Cheng-yi Chiang
On Tue, Oct 20, 2020 at 10:55 PM Srinivas Kandagatla
 wrote:
>
>
>
> On 20/10/2020 15:37, Mark Brown wrote:
> > I don't understand what "logic scattered in various dtsi files" means,
> > sorry.
> >
> >> Yes, that should work to describe the dailink we are using.
> >> But a more tricky issue is how to do calls like setting PLL in dai startup 
> >> ops.
> > ...
> >
> >> I think that asking a generic machine driver to do configuration like
> >> this with only a limited interface of device property
> >> might be too much of an ask for the machine driver.
> > Richard was looking at some basic configuration for PLLs.
> >
> >> Would you mind if I simplify the compatible string like Srinivas
> >> suggested, and send a v12?
> >> As for other two kinds of variations that I am aware of:
> >> 1. front mic / rear mic
> >> 2. replace alc5682 with adau7002
> > The CODEC change is going to be described in the DT no matter what -
> > you'll have a reference to the CODEC node but it may make sense if
> > there's enough custom code around it.  For front vs rear mic the
> > simplest thing would just be to not mention which if this is a hardware
> > fixed thing, otherwise a control.
> >
> >> We can set different board names and different compatible strings to
> >> achieve such variation.
> >> So that it would make sense to describe configuration in compatible
> >> strings like you suggested, and also provides UCM a way to distinguish
> >> different boards.
> > I don't recall having suggested distinguishing these things with a
> > compatible string, especially not the microphones.  UCM can already use
> > the display names for the boards to distinguish things.
>
>
> Not with the compatible string!
>
> Currently card name, and long name are exactly same in all Qualcomm
> soundcards, which makes it very difficult to identify how those boards
> re wired up at UCM2 level. So the plan is to properly populate card long
> name with "model" property which can include details on how things are
> wiredup on that board.
>
> --srini

Hi Srini,
Thanks for taking a look.
Let me try to clarify your comments in case there is any misunderstanding.

I understand your request on having different board variations using
different sound card names through model property, and I totally agree
with that.
As for compatible strings, do you insist on having all the board
variations using exactly the same compatible string ?

Thanks!


Re: [PATCH v11 2/3] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-10-20 Thread Cheng-yi Chiang
On Tue, Oct 20, 2020 at 10:37 PM Mark Brown  wrote:
>
> On Tue, Oct 20, 2020 at 09:37:05PM +0800, Cheng-yi Chiang wrote:
>
> > May I know your suggestion on Ajye's patch "ASoC: qcom: sc7180: Modify
> > machine driver for 2mic" ?
>
> > https://lore.kernel.org/r/20200928063744.525700-3-ajye_hu...@compal.corp-partner.google.com
>
> > I think adding code in the machine driver makes the intent straightforward.
> > If we want the machine driver to be fully configurable,
> > we can always add more code to handle properties like gpio, route,
> > widget (mux, text selection) passed in from the device tree.
>
> If the device has both front and rear mics and only one can be active at
> once that seems obvious and sensible.  If the devices only have one of
> these then this seems like a bad idea.
>

trogdor board: only front mic.
pompom board: having both front mic and rear mic. Only one of them
will be used at a time. It is toggled by mixer control backed by a
gpio.

My proposed solution: instead of using compatible strings, expose only
dmic-gpio property.
When the machine driver sees this property, it uses the dapm widgets
and controls created in the machine driver.

> > But I feel that we don't need a machine driver to be that configurable
> > from the device tree.
> > I think having the logic scattered in various dtsi files and relying
> > on manual inspection to understand the usage would be less
> > maintainable than only exposing needed property like gpio.
> > Especially in the complicated case where we need to create a mux
> > widget with callback toggling the gpio like this:
>
> I don't understand what "logic scattered in various dtsi files" means,
> sorry.
>
I mean I don't want to use device property to pass in widget name,
type, text and callbacks.
Let me give an example:

- Board trogdor uses front mic, rt5682, and max98357a.
- Board pompom is based on board trogdor, but it has front mic and rear mic.
If we somehow managed to add the code to pass in widget, route, type,
text, and callbacks needed for dmic control, we will need to put a
bunch of properties in trogdor-pompom.dtsi file.
- Board ABC is based on trogdor as well, and it has front mic and rear
mic, but with a different speaker amp.

To use widget, route, type, text and callbacks for front mic and rear
mic, in trogdor-ABC.dtsi file we would copy some properties used in
trogdor-pompom.dtsi file. To support the different combination of
codec, we would need some modification of the route and widget.

Now the support of front mic and rear mic switch is scattered in
trogdor-ABC.dtsi and trogdor-pompom.dtsi files.
For example, when we change the code to parse or build the widget and
route, we need to fix both trogdor-pompom.dtsi and trogdor-ABC.dtsi.

Alternatively, if we only expose dmic-gpio property and put
surrounding code in the machine driver, we can use this dmic-gpio
property, plus the sound card name to identify the needed widget and
route.

> > Yes, that should work to describe the dailink we are using.
> > But a more tricky issue is how to do calls like setting PLL in dai startup 
> > ops.
>
> ...
>
> > I think that asking a generic machine driver to do configuration like
> > this with only a limited interface of device property
> > might be too much of an ask for the machine driver.
>
> Richard was looking at some basic configuration for PLLs.

That sounds promising. If we don't need to include the codec driver
header file explicitly, that can make machine drivers simpler.
Maybe for most of the simple cases we don't even need a dedicated
machine driver.

>
> > Would you mind if I simplify the compatible string like Srinivas
> > suggested, and send a v12?
>
> > As for other two kinds of variations that I am aware of:
>
> > 1. front mic / rear mic
> > 2. replace alc5682 with adau7002
>
> The CODEC change is going to be described in the DT no matter what -
> you'll have a reference to the CODEC node but it may make sense if
> there's enough custom code around it.  For front vs rear mic the
> simplest thing would just be to not mention which if this is a hardware
> fixed thing, otherwise a control.
>

Would you suggest checking whether the codec node is a rt5682 node,
and call required PLL calls accordingly ?

"For front vs rear mic the simplest thing would just be to not mention
which if this is a hardware fixed thing, otherwise a control."
Sorry I am not sure if I understand this correctly. Please correct me
if I am wrong.

- For default case having 1 mic: not mention this at all
- For front mic / rear mic case: see gpio property and use an
additional control.

> > We can set different board names and different compatible strings to
> > achieve such var

Re: [PATCH v11 2/3] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-10-20 Thread Cheng-yi Chiang
On Fri, Oct 16, 2020 at 12:13 AM Mark Brown  wrote:
>
> On Thu, Oct 15, 2020 at 03:59:26PM +0800, Cheng-yi Chiang wrote:
> > On Tue, Oct 13, 2020 at 6:36 PM Srinivas Kandagatla
>
> > > > +properties:
> > > > +  compatible:
> > > > +const: qcom,sc7180-sndcard-rt5682-m98357-1mic
>
> > > This information can come from the dai link description itself, why
> > > should compatible string have this information?
>
> > I think dailink description is not enough to specify everything
> > machine driver needs to know.
> > E.g. there is a variation where there are front mic and rear mic. We
> > need to tell the machine driver about it so
> > it can create proper widget, route, and controls.
>
> That sounds like something that could be better described with
> properties (including for example the existing bindings used for setting
> up things like analogue outputs and DAPM routes)?
>

Hi Mark, thank you for the comments.

May I know your suggestion on Ajye's patch "ASoC: qcom: sc7180: Modify
machine driver for 2mic" ?

https://lore.kernel.org/r/20200928063744.525700-3-ajye_hu...@compal.corp-partner.google.com

I think adding code in the machine driver makes the intent straightforward.
If we want the machine driver to be fully configurable,
we can always add more code to handle properties like gpio, route,
widget (mux, text selection) passed in from the device tree.
But I feel that we don't need a machine driver to be that configurable
from the device tree.
I think having the logic scattered in various dtsi files and relying
on manual inspection to understand the usage would be less
maintainable than only exposing needed property like gpio.
Especially in the complicated case where we need to create a mux
widget with callback toggling the gpio like this:

+static const char * const dmic_mux_text[] = {
+   "Front Mic",
+   "Rear Mic",
+};
+
+static SOC_ENUM_SINGLE_DECL(sc7180_dmic_enum,
+   SND_SOC_NOPM, 0, dmic_mux_text);
+
+static const struct snd_kcontrol_new sc7180_dmic_mux_control =
+   SOC_DAPM_ENUM_EXT("DMIC Select Mux", sc7180_dmic_enum,
+ dmic_get, dmic_set);
+
+SND_SOC_DAPM_MUX("Dmic Mux", SND_SOC_NOPM, 0, 0, _dmic_mux_control),

Passing all the logic along with the callback of dmic_get, dmic_set
from the device tree would be too hard to maintain.

> > The codec combination also matters. There will be a variation where
> > rt5682 is replaced with adau7002 for dmic.
> > Although machine driver can derive some information by looking at dailink,
> > I think specifying it explicitly in the compatible string is easier to
> > tell what machine driver should do, e.g.
> > setting PLL related to rt5682 or not.
>
> These feel more like things that fit with compatible, though please take
> a look at Morimoto-san's (CCed) work on generic sound cards for more
> complex devices:
>
>
> https://lore.kernel.org/alsa-devel/87imbeybq5.wl-kuninori.morimoto...@renesas.com/
>
> This is not yet implemented but it'd be good to make sure that the
> Qualcomm systems can be handled too in future.

Yes, that should work to describe the dailink we are using.
But a more tricky issue is how to do calls like setting PLL in dai startup ops.

/* Configure PLL1 for codec */
ret = snd_soc_dai_set_pll(codec_dai, 0, RT5682_PLL1_S_MCLK,
  DEFAULT_MCLK_RATE, RT5682_PLL1_FREQ);

I think that asking a generic machine driver to do configuration like
this with only a limited interface of device property
might be too much of an ask for the machine driver.

>
> > You can see widget, route, controls are used according to the configuration.
> > The alternative approach is to check whether "dmic-gpio" property
> > exists to decide adding these stuff or not.
> > But it makes the intent less easier to understand.
>
> OTOH if you have lots of compatibles then it can get hard to work out
> exactly which one corresponds to a given board.

Totally agree. Glad we have only three variations up to now.

Would you mind if I simplify the compatible string like Srinivas
suggested, and send a v12?

As for other two kinds of variations that I am aware of:

1. front mic / rear mic
2. replace alc5682 with adau7002

We can set different board names and different compatible strings to
achieve such variation.
So that it would make sense to describe configuration in compatible
strings like you suggested, and also provides UCM a way to distinguish
different boards.
What do you think ?

Thanks!


Re: [PATCH v11 3/3] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-10-15 Thread Cheng-yi Chiang
On Tue, Oct 13, 2020 at 11:50 AM Cheng-yi Chiang  wrote:
>
> On Mon, Sep 14, 2020 at 4:06 PM Cheng-Yi Chiang  wrote:
> >
> > From: Ajit Pandey 
> >
> > Add new driver to register sound card on sc7180 trogdor board and
> > do the required configuration for lpass cpu dai and external codecs
> > connected over MI2S interfaces.
> >
> > Signed-off-by: Ajit Pandey 
> > Signed-off-by: Cheng-Yi Chiang 
> > ---
> >  sound/soc/qcom/Kconfig  |  12 ++
> >  sound/soc/qcom/Makefile |   2 +
> >  sound/soc/qcom/sc7180.c | 266 
> >  3 files changed, 280 insertions(+)
> >  create mode 100644 sound/soc/qcom/sc7180.c
> >
> > diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
> > index a607ace8b089..0459185ee243 100644
> > --- a/sound/soc/qcom/Kconfig
> > +++ b/sound/soc/qcom/Kconfig
> > @@ -116,4 +116,16 @@ config SND_SOC_SDM845
> >   SDM845 SoC-based systems.
> >   Say Y if you want to use audio device on this SoCs.
> >
> > +config SND_SOC_SC7180
> > +   tristate "SoC Machine driver for SC7180 boards"
> > +   depends on I2C
> > +   select SND_SOC_QCOM_COMMON
> > +   select SND_SOC_LPASS_SC7180
> > +   select SND_SOC_MAX98357A
> > +   select SND_SOC_RT5682_I2C
> > +   help
> > + To add support for audio on Qualcomm Technologies Inc.
> > + SC7180 SoC-based systems.
> > + Say Y if you want to use audio device on this SoCs.
> > +
> >  endif #SND_SOC_QCOM
> > diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
> > index 7972c9479ab0..0cdcbf367ef1 100644
> > --- a/sound/soc/qcom/Makefile
> > +++ b/sound/soc/qcom/Makefile
> > @@ -17,12 +17,14 @@ snd-soc-storm-objs := storm.o
> >  snd-soc-apq8016-sbc-objs := apq8016_sbc.o
> >  snd-soc-apq8096-objs := apq8096.o
> >  snd-soc-sdm845-objs := sdm845.o
> > +snd-soc-sc7180-objs := sc7180.o
> >  snd-soc-qcom-common-objs := common.o
> >
> >  obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
> >  obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
> >  obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
> >  obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
> > +obj-$(CONFIG_SND_SOC_SC7180) += snd-soc-sc7180.o
> >  obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o
> >
> >  #DSP lib
> > diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
> > new file mode 100644
> > index ..0e90448523b0
> > --- /dev/null
> > +++ b/sound/soc/qcom/sc7180.c
> > @@ -0,0 +1,266 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +//
> > +// Copyright (c) 2020, The Linux Foundation. All rights reserved.
> > +//
> > +// sc7180.c -- ALSA SoC Machine driver for SC7180
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include "../codecs/rt5682.h"
> > +#include "common.h"
> > +#include "lpass.h"
> > +
> > +#define DEFAULT_MCLK_RATE  1920
> > +#define RT5682_PLL1_FREQ (48000 * 512)
> > +
> > +// This will be defined in include/dt-bindings/sound/sc7180-lpass.h
> > +#define LPASS_DP_RX 2
> > +
> > +struct sc7180_snd_data {
> > +   struct snd_soc_card card;
> > +   u32 pri_mi2s_clk_count;
> > +   struct snd_soc_jack hs_jack;
> > +   struct snd_soc_jack hdmi_jack;
> > +};
> > +
> > +static void sc7180_jack_free(struct snd_jack *jack)
> > +{
> > +   struct snd_soc_component *component = jack->private_data;
> > +
> > +   snd_soc_component_set_jack(component, NULL, NULL);
> > +}
> > +
> > +static int sc7180_headset_init(struct snd_soc_pcm_runtime *rtd)
> > +{
> > +   struct snd_soc_card *card = rtd->card;
> > +   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
> > +   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
> > +   struct snd_soc_component *component = codec_dai->component;
> > +   struct snd_jack *jack;
> > +   int rval;
> > +
> > +   rval = snd_soc_card_jack_new(
> > +   card, "Headset Jack",
> > +   SND_JACK_HEADSET |
> > +   SND_JACK_HEADPHONE |
> > +   SND_JACK_BTN_0 | SND_JACK_BTN_1 |
> > +   SND_JACK_BTN_2 |

Re: [PATCH v11 2/3] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-10-15 Thread Cheng-yi Chiang
On Tue, Oct 13, 2020 at 6:36 PM Srinivas Kandagatla
 wrote:
>
> Hi Cheng,
>
> Sorry for such late review w.r.t compatibles,
>
Hi Srini,
Thank you for taking another look!

> On 14/09/2020 09:06, Cheng-Yi Chiang wrote:
> > +---
> > +$id:http://devicetree.org/schemas/sound/qcom,sc7180.yaml#
> > +$schema:http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: Qualcomm Technologies Inc. SC7180 ASoC sound card driver
> > +
> > +maintainers:
> > +  - Rohit kumar
> > +  - Cheng-Yi Chiang
> > +
> > +description:
> > +  This binding describes the SC7180 sound card which uses LPASS for audio.
> > +
> > +properties:
> > +  compatible:
> > +const: qcom,sc7180-sndcard-rt5682-m98357-1mic
>
> This information can come from the dai link description itself, why
> should compatible string have this information?


I think dailink description is not enough to specify everything
machine driver needs to know.
E.g. there is a variation where there are front mic and rear mic. We
need to tell the machine driver about it so
it can create proper widget, route, and controls.
The codec combination also matters. There will be a variation where
rt5682 is replaced with adau7002 for dmic.
Although machine driver can derive some information by looking at dailink,
I think specifying it explicitly in the compatible string is easier to
tell what machine driver should do, e.g.
setting PLL related to rt5682 or not.

>
> Can't we have better compatible string with actual board name or use the
> same compatible name as used by other boards?
>
>
> Can you give us some details on the advantages of doing this way?


Machine driver can easily tell what is expected when it sees the
compatible string (or model property, as you suggested below).
E.g. in 1-mic v.s. 2-mic case, the patch by Ajye Huang:

"[v1,2/2] ASoC: qcom: sc7180: Modify machine driver for 2mic"

You can see widget, route, controls are used according to the configuration.
The alternative approach is to check whether "dmic-gpio" property
exists to decide adding these stuff or not.
But it makes the intent less easier to understand.


>
> Or am I missing something?
>
> AFAIU, you should add proper board name / model name to the compatible
> string rather than describe how its connected. Connection is already
> part of dai link definition.
>
> On the other hand model property can include variant information.
> This can also be used to set card long name which will help in UCM2.
>
>
> The reason I had to bring this up is because the use-space (ucm in this
> case) will not be in a position to differentiate between different board
> variants to select correct mixer controls, so its going to be a pain!


I think your suggestions makes sense since we need to consider UCM.
Having the card with the same name doing different things will be
confusing to user (and to UCM).
I'll follow your suggestion to use the same compatible string, and put
the board variation information in card name using model property.
Thanks a lot for the great help!


>
>
>
> Thanks,
> srini


Re: [PATCH v11 3/3] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-10-12 Thread Cheng-yi Chiang
On Mon, Sep 14, 2020 at 4:06 PM Cheng-Yi Chiang  wrote:
>
> From: Ajit Pandey 
>
> Add new driver to register sound card on sc7180 trogdor board and
> do the required configuration for lpass cpu dai and external codecs
> connected over MI2S interfaces.
>
> Signed-off-by: Ajit Pandey 
> Signed-off-by: Cheng-Yi Chiang 
> ---
>  sound/soc/qcom/Kconfig  |  12 ++
>  sound/soc/qcom/Makefile |   2 +
>  sound/soc/qcom/sc7180.c | 266 
>  3 files changed, 280 insertions(+)
>  create mode 100644 sound/soc/qcom/sc7180.c
>
> diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
> index a607ace8b089..0459185ee243 100644
> --- a/sound/soc/qcom/Kconfig
> +++ b/sound/soc/qcom/Kconfig
> @@ -116,4 +116,16 @@ config SND_SOC_SDM845
>   SDM845 SoC-based systems.
>   Say Y if you want to use audio device on this SoCs.
>
> +config SND_SOC_SC7180
> +   tristate "SoC Machine driver for SC7180 boards"
> +   depends on I2C
> +   select SND_SOC_QCOM_COMMON
> +   select SND_SOC_LPASS_SC7180
> +   select SND_SOC_MAX98357A
> +   select SND_SOC_RT5682_I2C
> +   help
> + To add support for audio on Qualcomm Technologies Inc.
> + SC7180 SoC-based systems.
> + Say Y if you want to use audio device on this SoCs.
> +
>  endif #SND_SOC_QCOM
> diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
> index 7972c9479ab0..0cdcbf367ef1 100644
> --- a/sound/soc/qcom/Makefile
> +++ b/sound/soc/qcom/Makefile
> @@ -17,12 +17,14 @@ snd-soc-storm-objs := storm.o
>  snd-soc-apq8016-sbc-objs := apq8016_sbc.o
>  snd-soc-apq8096-objs := apq8096.o
>  snd-soc-sdm845-objs := sdm845.o
> +snd-soc-sc7180-objs := sc7180.o
>  snd-soc-qcom-common-objs := common.o
>
>  obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
>  obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
>  obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
>  obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
> +obj-$(CONFIG_SND_SOC_SC7180) += snd-soc-sc7180.o
>  obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o
>
>  #DSP lib
> diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
> new file mode 100644
> index ..0e90448523b0
> --- /dev/null
> +++ b/sound/soc/qcom/sc7180.c
> @@ -0,0 +1,266 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +//
> +// Copyright (c) 2020, The Linux Foundation. All rights reserved.
> +//
> +// sc7180.c -- ALSA SoC Machine driver for SC7180
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "../codecs/rt5682.h"
> +#include "common.h"
> +#include "lpass.h"
> +
> +#define DEFAULT_MCLK_RATE  1920
> +#define RT5682_PLL1_FREQ (48000 * 512)
> +
> +// This will be defined in include/dt-bindings/sound/sc7180-lpass.h
> +#define LPASS_DP_RX 2
> +
> +struct sc7180_snd_data {
> +   struct snd_soc_card card;
> +   u32 pri_mi2s_clk_count;
> +   struct snd_soc_jack hs_jack;
> +   struct snd_soc_jack hdmi_jack;
> +};
> +
> +static void sc7180_jack_free(struct snd_jack *jack)
> +{
> +   struct snd_soc_component *component = jack->private_data;
> +
> +   snd_soc_component_set_jack(component, NULL, NULL);
> +}
> +
> +static int sc7180_headset_init(struct snd_soc_pcm_runtime *rtd)
> +{
> +   struct snd_soc_card *card = rtd->card;
> +   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
> +   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
> +   struct snd_soc_component *component = codec_dai->component;
> +   struct snd_jack *jack;
> +   int rval;
> +
> +   rval = snd_soc_card_jack_new(
> +   card, "Headset Jack",
> +   SND_JACK_HEADSET |
> +   SND_JACK_HEADPHONE |
> +   SND_JACK_BTN_0 | SND_JACK_BTN_1 |
> +   SND_JACK_BTN_2 | SND_JACK_BTN_3,
> +   >hs_jack, NULL, 0);
> +
> +   if (rval < 0) {
> +   dev_err(card->dev, "Unable to add Headset Jack\n");
> +   return rval;
> +   }
> +
> +   jack = pdata->hs_jack.jack;
> +
> +   snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
> +   snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
> +   snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
> +   snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
> +
> +   jack->private_data = component;
> +   jac

Re: [PATCH v11 2/3] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-10-12 Thread Cheng-yi Chiang
On Tue, Sep 15, 2020 at 8:44 PM Cheng-yi Chiang  wrote:
>
> On Tue, Sep 15, 2020 at 1:48 AM Rob Herring  wrote:
> >
> > On Mon, 14 Sep 2020 16:06:18 +0800, Cheng-Yi Chiang wrote:
> > > Add devicetree bindings documentation file for sc7180 sound card.
> > >
> > > Signed-off-by: Cheng-Yi Chiang 
> > > ---
> > >  .../bindings/sound/qcom,sc7180.yaml   | 130 ++
> > >  1 file changed, 130 insertions(+)
> > >  create mode 100644 
> > > Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> > >
> >
> >
> > Please add Acked-by/Reviewed-by tags when posting new versions. However,
> > there's no need to repost patches *only* to add the tags. The upstream
> > maintainer will do that for acks received on the version they apply.
> >
> > If a tag was not added on purpose, please state why and what changed.
> >
>
> Hi Rob,
> There was a change between v9 and v10 on compatible string so I did
> not add your Reviewed-by.
> Now it is "qcom,sc7180-sndcard-rt5682-m98357-1mic" following Stephan's
> comment in
>
> https://patchwork.kernel.org/comment/23608881/
>
> to make compatible string more specific to board configuration.
> I only add the note to the cover letter. Sorry the cover letter became
> too long to follow.
> I will add the note in patch mail itself for future changes.
> Thanks for taking a look again.


Hi Rob,
Could you please kindly review this patch ?

v11 contains the compatible string  "qcom,sc7180-sndcard-rt5682-m98357-1mic"
following Stephan's suggestion in

"[v9,3/3] ASoC: qcom: sc7180: Add machine driver for sound card registration"
( https://patchwork.kernel.org/patch/11770201/#23608881 )

to specify the combination of components.

Please let me know if this looks good to you.
Thanks!


[PATCH] ASoC: hdmi-codec: Use set_jack ops to set jack

2020-09-22 Thread Cheng-Yi Chiang
Use set_jack ops to set jack so machine drivers do not need to include
hdmi-codec.h explicitly.

Signed-off-by: Cheng-Yi Chiang 
Reviewed-by: Tzung-Bi Shih 
---
Separate this patch from the machine driver patch series at
https://patchwork.kernel.org/cover/11773209/
in the hope that this can be merged first to ease other
machine drivers' usage.

 include/sound/hdmi-codec.h   |  3 ---
 sound/soc/codecs/hdmi-codec.c| 12 
 sound/soc/mediatek/mt8173/mt8173-rt5650.c|  5 ++---
 sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c   |  5 ++---
 .../mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c |  5 ++---
 sound/soc/rockchip/rockchip_max98090.c   |  3 +--
 6 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/include/sound/hdmi-codec.h b/include/sound/hdmi-codec.h
index 7754631a3102..b55970859a13 100644
--- a/include/sound/hdmi-codec.h
+++ b/include/sound/hdmi-codec.h
@@ -117,9 +117,6 @@ struct hdmi_codec_pdata {
 struct snd_soc_component;
 struct snd_soc_jack;
 
-int hdmi_codec_set_jack_detect(struct snd_soc_component *component,
-  struct snd_soc_jack *jack);
-
 #define HDMI_CODEC_DRV_NAME "hdmi-audio-codec"
 
 #endif /* __HDMI_CODEC_H__ */
diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c
index 8c6f540533ba..403d4c6a49a8 100644
--- a/sound/soc/codecs/hdmi-codec.c
+++ b/sound/soc/codecs/hdmi-codec.c
@@ -698,13 +698,9 @@ static void plugged_cb(struct device *dev, bool plugged)
hdmi_codec_jack_report(hcp, 0);
 }
 
-/**
- * hdmi_codec_set_jack_detect - register HDMI plugged callback
- * @component: the hdmi-codec instance
- * @jack: ASoC jack to report (dis)connection events on
- */
-int hdmi_codec_set_jack_detect(struct snd_soc_component *component,
-  struct snd_soc_jack *jack)
+static int hdmi_codec_set_jack(struct snd_soc_component *component,
+  struct snd_soc_jack *jack,
+  void *data)
 {
struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component);
int ret = -EOPNOTSUPP;
@@ -720,7 +716,6 @@ int hdmi_codec_set_jack_detect(struct snd_soc_component 
*component,
}
return ret;
 }
-EXPORT_SYMBOL_GPL(hdmi_codec_set_jack_detect);
 
 static int hdmi_dai_spdif_probe(struct snd_soc_dai *dai)
 {
@@ -806,6 +801,7 @@ static const struct snd_soc_component_driver hdmi_driver = {
.use_pmdown_time= 1,
.endianness = 1,
.non_legacy_dai_naming  = 1,
+   .set_jack   = hdmi_codec_set_jack,
 };
 
 static int hdmi_codec_probe(struct platform_device *pdev)
diff --git a/sound/soc/mediatek/mt8173/mt8173-rt5650.c 
b/sound/soc/mediatek/mt8173/mt8173-rt5650.c
index 347b095d478d..c28ebf891cb0 100644
--- a/sound/soc/mediatek/mt8173/mt8173-rt5650.c
+++ b/sound/soc/mediatek/mt8173/mt8173-rt5650.c
@@ -11,7 +11,6 @@
 #include 
 #include 
 #include 
-#include 
 #include "../../codecs/rt5645.h"
 
 #define MCLK_FOR_CODECS12288000
@@ -154,8 +153,8 @@ static int mt8173_rt5650_hdmi_init(struct 
snd_soc_pcm_runtime *rtd)
if (ret)
return ret;
 
-   return hdmi_codec_set_jack_detect(asoc_rtd_to_codec(rtd, 0)->component,
- _rt5650_hdmi_jack);
+   return snd_soc_component_set_jack(asoc_rtd_to_codec(rtd, 0)->component,
+ _rt5650_hdmi_jack, NULL);
 }
 
 enum {
diff --git a/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c 
b/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
index 68fe23b96b14..15e48cde4921 100644
--- a/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
+++ b/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
@@ -10,7 +10,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -375,8 +374,8 @@ static int mt8183_da7219_max98357_hdmi_init(struct 
snd_soc_pcm_runtime *rtd)
if (ret)
return ret;
 
-   return hdmi_codec_set_jack_detect(asoc_rtd_to_codec(rtd, 0)->component,
- >hdmi_jack);
+   return snd_soc_component_set_jack(asoc_rtd_to_codec(rtd, 0)->component,
+ >hdmi_jack, NULL);
 }
 
 static struct snd_soc_dai_link mt8183_da7219_dai_links[] = {
diff --git a/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c 
b/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
index 07410d7afaa9..327dfad41e31 100644
--- a/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
+++ b/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
@@ -9,7 +9,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -350,8 +349,8 @@ mt8183_mt6358_ts3a227_max98357_hdmi_init(struct 
snd_soc_pcm_runtime *rtd)
if (ret)
return ret;
 
-   return hdmi_c

Re: [PATCH v11 2/3] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-09-15 Thread Cheng-yi Chiang
On Tue, Sep 15, 2020 at 1:48 AM Rob Herring  wrote:
>
> On Mon, 14 Sep 2020 16:06:18 +0800, Cheng-Yi Chiang wrote:
> > Add devicetree bindings documentation file for sc7180 sound card.
> >
> > Signed-off-by: Cheng-Yi Chiang 
> > ---
> >  .../bindings/sound/qcom,sc7180.yaml   | 130 ++
> >  1 file changed, 130 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> >
>
>
> Please add Acked-by/Reviewed-by tags when posting new versions. However,
> there's no need to repost patches *only* to add the tags. The upstream
> maintainer will do that for acks received on the version they apply.
>
> If a tag was not added on purpose, please state why and what changed.
>

Hi Rob,
There was a change between v9 and v10 on compatible string so I did
not add your Reviewed-by.
Now it is "qcom,sc7180-sndcard-rt5682-m98357-1mic" following Stephan's
comment in

https://patchwork.kernel.org/comment/23608881/

to make compatible string more specific to board configuration.
I only add the note to the cover letter. Sorry the cover letter became
too long to follow.
I will add the note in patch mail itself for future changes.
Thanks for taking a look again.


[PATCH v11 0/3] Add documentation and machine driver for SC7180 sound card

2020-09-14 Thread Cheng-Yi Chiang
Note:
- The machine driver patch is made by the collaboration of
  Cheng-Yi Chiang 
  Rohit kumar 
  Ajit Pandey 
  But Ajit has left codeaurora.
- This patch series needs HDMI DAI name SC7180_LPASS_DP defined in 
sc7180-lpass.h.
  It will be posted in the newer patchset of 
https://patchwork.kernel.org/patch/11745565/

Changes from v1 to v2:
- Ducumentation: Addressed all suggestions from Doug.
- Machine driver:
  - Fix comment style for license.
  - Sort includes.
  - Remove sc7180_snd_hw_params.
  - Remove sc7180_dai_init and use aux device instead for headset jack 
registration.
  - Statically define format for Primary MI2S.
  - Atomic is not a concern because there is mutex in card to make sure
startup and shutdown happen sequentially.
  - Fix missing return -EINVAL in startup.
  - Use static sound card.
  - Use devm_kzalloc to avoid kfree.

Changes from v2 to v3:
- Ducumentation: Addressed suggestions from Srini.
- Machine driver:
  - Reuse qcom_snd_parse_of to parse properties.
  - Remove playback-only and capture-only.
  - Misc fixes to address comments.

Changes from v3 to v4:
- Ducumentation: Addressed suggestions from Rob.
 - Remove definition of dai.
 - Use 'sound-dai: true' for sound-dai schema.
 - Add reg property to pass 'make dt_binding_check' check although reg is not 
used in the driver.
- Machine driver:
 - Add Reviewed-by: Tzung-Bi Shih 

Changes from v4 to v5:
- Documentation: Addressed suggestions from Rob.
 - Add definition for "#address-cells" and "#size-cells".
 - Add additionalProperties: false
 - Add required properties.

Changes from v5 to v6:
- Documentation: Addressed suggestions from Rob.
 - Drop contains in compatible strings.
 - Only allow dai-link@[0-9]
 - Remove reg ref since it has a type definition already.

Changes from v6 to v7
- Documentation:
  - Add headset-jack and hdmi-jack to specify the codec
responsible for jack detection.
- HDMI codec driver:
  - Use component set_jack ops instead of exporting hdmi_codec_set_jack_detect.
- Machine driver:
  - Removed aux device following Stephan's suggestion.
  - Use headset-jack and hdmi-jack to specify the codec
responsible for jack detection.
  - Add support for HDMI(actually DP) playback.

Changes from v7 to v8
- Documentation:
  - Remove headset-jack and hdmi-jack.
- Machine driver:
  - Let machine driver decide whether there is a jack on the DAI.

Changes from v8 to v9
- hdmi-codec driver:
  - Fixed the naming.
- Machine driver:
  - Fixed unused fields.
  - Moved snd_soc_card_set_drvdata
  - Keep the naming of HDMI as dai name until v5 of lpass-hdmi patches.

Changes from v9 to v10
- Documentation:
  - Let compatible string be more specific for board configuration to allow
for future changes.
- Machine driver:
  - Fixed unused include and macro.
  - Add temporary macro SC7180_LPASS_DP for future change in sc7180-lpass.h.
  - Let sound card be dynamically allocated.
  - Change compatible string accordingly.

Changes from v10 to v11
- Machine driver:
  - Use temporary macro LPASS_DP_RX for future change in sc7180-lpass.h.

Ajit Pandey (1):
  ASoC: qcom: sc7180: Add machine driver for sound card registration

Cheng-Yi Chiang (2):
  ASoC: hdmi-codec: Use set_jack ops to set jack
  ASoC: qcom: dt-bindings: Add sc7180 machine bindings

 .../bindings/sound/qcom,sc7180.yaml   | 130 +
 include/sound/hdmi-codec.h|   3 -
 sound/soc/codecs/hdmi-codec.c |  12 +-
 sound/soc/mediatek/mt8173/mt8173-rt5650.c |   5 +-
 .../mediatek/mt8183/mt8183-da7219-max98357.c  |   5 +-
 .../mt8183/mt8183-mt6358-ts3a227-max98357.c   |   5 +-
 sound/soc/qcom/Kconfig|  12 +
 sound/soc/qcom/Makefile   |   2 +
 sound/soc/qcom/sc7180.c   | 266 ++
 sound/soc/rockchip/rockchip_max98090.c|   3 +-
 10 files changed, 421 insertions(+), 22 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
 create mode 100644 sound/soc/qcom/sc7180.c

-- 
2.28.0.618.gf4bc123cb7-goog



[PATCH v11 1/3] ASoC: hdmi-codec: Use set_jack ops to set jack

2020-09-14 Thread Cheng-Yi Chiang
Use set_jack ops to set jack so machine drivers do not need to include
hdmi-codec.h explicitly.

Signed-off-by: Cheng-Yi Chiang 
Reviewed-by: Tzung-Bi Shih 
---
 include/sound/hdmi-codec.h   |  3 ---
 sound/soc/codecs/hdmi-codec.c| 12 
 sound/soc/mediatek/mt8173/mt8173-rt5650.c|  5 ++---
 sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c   |  5 ++---
 .../mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c |  5 ++---
 sound/soc/rockchip/rockchip_max98090.c   |  3 +--
 6 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/include/sound/hdmi-codec.h b/include/sound/hdmi-codec.h
index 7754631a3102..b55970859a13 100644
--- a/include/sound/hdmi-codec.h
+++ b/include/sound/hdmi-codec.h
@@ -117,9 +117,6 @@ struct hdmi_codec_pdata {
 struct snd_soc_component;
 struct snd_soc_jack;
 
-int hdmi_codec_set_jack_detect(struct snd_soc_component *component,
-  struct snd_soc_jack *jack);
-
 #define HDMI_CODEC_DRV_NAME "hdmi-audio-codec"
 
 #endif /* __HDMI_CODEC_H__ */
diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c
index 8c6f540533ba..403d4c6a49a8 100644
--- a/sound/soc/codecs/hdmi-codec.c
+++ b/sound/soc/codecs/hdmi-codec.c
@@ -698,13 +698,9 @@ static void plugged_cb(struct device *dev, bool plugged)
hdmi_codec_jack_report(hcp, 0);
 }
 
-/**
- * hdmi_codec_set_jack_detect - register HDMI plugged callback
- * @component: the hdmi-codec instance
- * @jack: ASoC jack to report (dis)connection events on
- */
-int hdmi_codec_set_jack_detect(struct snd_soc_component *component,
-  struct snd_soc_jack *jack)
+static int hdmi_codec_set_jack(struct snd_soc_component *component,
+  struct snd_soc_jack *jack,
+  void *data)
 {
struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component);
int ret = -EOPNOTSUPP;
@@ -720,7 +716,6 @@ int hdmi_codec_set_jack_detect(struct snd_soc_component 
*component,
}
return ret;
 }
-EXPORT_SYMBOL_GPL(hdmi_codec_set_jack_detect);
 
 static int hdmi_dai_spdif_probe(struct snd_soc_dai *dai)
 {
@@ -806,6 +801,7 @@ static const struct snd_soc_component_driver hdmi_driver = {
.use_pmdown_time= 1,
.endianness = 1,
.non_legacy_dai_naming  = 1,
+   .set_jack   = hdmi_codec_set_jack,
 };
 
 static int hdmi_codec_probe(struct platform_device *pdev)
diff --git a/sound/soc/mediatek/mt8173/mt8173-rt5650.c 
b/sound/soc/mediatek/mt8173/mt8173-rt5650.c
index 347b095d478d..c28ebf891cb0 100644
--- a/sound/soc/mediatek/mt8173/mt8173-rt5650.c
+++ b/sound/soc/mediatek/mt8173/mt8173-rt5650.c
@@ -11,7 +11,6 @@
 #include 
 #include 
 #include 
-#include 
 #include "../../codecs/rt5645.h"
 
 #define MCLK_FOR_CODECS12288000
@@ -154,8 +153,8 @@ static int mt8173_rt5650_hdmi_init(struct 
snd_soc_pcm_runtime *rtd)
if (ret)
return ret;
 
-   return hdmi_codec_set_jack_detect(asoc_rtd_to_codec(rtd, 0)->component,
- _rt5650_hdmi_jack);
+   return snd_soc_component_set_jack(asoc_rtd_to_codec(rtd, 0)->component,
+ _rt5650_hdmi_jack, NULL);
 }
 
 enum {
diff --git a/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c 
b/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
index 06d0a4f80fc1..e53c6200d5a7 100644
--- a/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
+++ b/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
@@ -10,7 +10,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -369,8 +368,8 @@ static int mt8183_da7219_max98357_hdmi_init(struct 
snd_soc_pcm_runtime *rtd)
if (ret)
return ret;
 
-   return hdmi_codec_set_jack_detect(asoc_rtd_to_codec(rtd, 0)->component,
- >hdmi_jack);
+   return snd_soc_component_set_jack(asoc_rtd_to_codec(rtd, 0)->component,
+ >hdmi_jack, NULL);
 }
 
 static struct snd_soc_dai_link mt8183_da7219_dai_links[] = {
diff --git a/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c 
b/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
index 07410d7afaa9..327dfad41e31 100644
--- a/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
+++ b/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
@@ -9,7 +9,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -350,8 +349,8 @@ mt8183_mt6358_ts3a227_max98357_hdmi_init(struct 
snd_soc_pcm_runtime *rtd)
if (ret)
return ret;
 
-   return hdmi_codec_set_jack_detect(asoc_rtd_to_codec(rtd, 0)->component,
- >hdmi_jack);
+   return snd_soc_component_s

[PATCH v11 2/3] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-09-14 Thread Cheng-Yi Chiang
Add devicetree bindings documentation file for sc7180 sound card.

Signed-off-by: Cheng-Yi Chiang 
---
 .../bindings/sound/qcom,sc7180.yaml   | 130 ++
 1 file changed, 130 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml

diff --git a/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml 
b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
new file mode 100644
index ..b77311bb5190
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
@@ -0,0 +1,130 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/qcom,sc7180.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Technologies Inc. SC7180 ASoC sound card driver
+
+maintainers:
+  - Rohit kumar 
+  - Cheng-Yi Chiang 
+
+description:
+  This binding describes the SC7180 sound card which uses LPASS for audio.
+
+properties:
+  compatible:
+const: qcom,sc7180-sndcard-rt5682-m98357-1mic
+
+  audio-routing:
+$ref: /schemas/types.yaml#/definitions/non-unique-string-array
+description:
+  A list of the connections between audio components. Each entry is a
+  pair of strings, the first being the connection's sink, the second
+  being the connection's source.
+
+  model:
+$ref: /schemas/types.yaml#/definitions/string
+description: User specified audio sound card name
+
+  "#address-cells":
+const: 1
+
+  "#size-cells":
+const: 0
+
+patternProperties:
+  "^dai-link(@[0-9])?$":
+description:
+  Each subnode represents a dai link. Subnodes of each dai links would be
+  cpu/codec dais.
+
+type: object
+
+properties:
+  link-name:
+description: Indicates dai-link name and PCM stream name.
+$ref: /schemas/types.yaml#/definitions/string
+maxItems: 1
+
+  reg:
+description: dai link address.
+
+  cpu:
+description: Holds subnode which indicates cpu dai.
+type: object
+properties:
+  sound-dai: true
+
+  codec:
+description: Holds subnode which indicates codec dai.
+type: object
+properties:
+  sound-dai: true
+
+required:
+  - link-name
+  - cpu
+  - codec
+
+additionalProperties: false
+
+required:
+  - compatible
+  - model
+  - "#address-cells"
+  - "#size-cells"
+
+additionalProperties: false
+
+examples:
+
+  - |
+sound {
+compatible = "qcom,sc7180-sndcard-rt5682-m98357-1mic";
+model = "sc7180-snd-card";
+
+audio-routing =
+"Headphone Jack", "HPOL",
+"Headphone Jack", "HPOR";
+
+#address-cells = <1>;
+#size-cells = <0>;
+
+dai-link@0 {
+link-name = "MultiMedia0";
+reg = <0>;
+cpu {
+sound-dai = <_cpu 0>;
+};
+
+codec {
+sound-dai = < 0>;
+};
+};
+
+dai-link@1 {
+link-name = "MultiMedia1";
+reg = <1>;
+cpu {
+sound-dai = <_cpu 1>;
+};
+
+codec {
+sound-dai = <>;
+};
+};
+
+dai-link@2 {
+link-name = "MultiMedia2";
+reg = <2>;
+cpu {
+sound-dai = <_hdmi 0>;
+};
+
+codec {
+sound-dai = <_dp>;
+};
+};
+};
-- 
2.28.0.618.gf4bc123cb7-goog



[PATCH v11 3/3] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-09-14 Thread Cheng-Yi Chiang
From: Ajit Pandey 

Add new driver to register sound card on sc7180 trogdor board and
do the required configuration for lpass cpu dai and external codecs
connected over MI2S interfaces.

Signed-off-by: Ajit Pandey 
Signed-off-by: Cheng-Yi Chiang 
---
 sound/soc/qcom/Kconfig  |  12 ++
 sound/soc/qcom/Makefile |   2 +
 sound/soc/qcom/sc7180.c | 266 
 3 files changed, 280 insertions(+)
 create mode 100644 sound/soc/qcom/sc7180.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index a607ace8b089..0459185ee243 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -116,4 +116,16 @@ config SND_SOC_SDM845
  SDM845 SoC-based systems.
  Say Y if you want to use audio device on this SoCs.
 
+config SND_SOC_SC7180
+   tristate "SoC Machine driver for SC7180 boards"
+   depends on I2C
+   select SND_SOC_QCOM_COMMON
+   select SND_SOC_LPASS_SC7180
+   select SND_SOC_MAX98357A
+   select SND_SOC_RT5682_I2C
+   help
+ To add support for audio on Qualcomm Technologies Inc.
+ SC7180 SoC-based systems.
+ Say Y if you want to use audio device on this SoCs.
+
 endif #SND_SOC_QCOM
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index 7972c9479ab0..0cdcbf367ef1 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -17,12 +17,14 @@ snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
 snd-soc-apq8096-objs := apq8096.o
 snd-soc-sdm845-objs := sdm845.o
+snd-soc-sc7180-objs := sc7180.o
 snd-soc-qcom-common-objs := common.o
 
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
 obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
 obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
+obj-$(CONFIG_SND_SOC_SC7180) += snd-soc-sc7180.o
 obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o
 
 #DSP lib
diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
new file mode 100644
index ..0e90448523b0
--- /dev/null
+++ b/sound/soc/qcom/sc7180.c
@@ -0,0 +1,266 @@
+// SPDX-License-Identifier: GPL-2.0-only
+//
+// Copyright (c) 2020, The Linux Foundation. All rights reserved.
+//
+// sc7180.c -- ALSA SoC Machine driver for SC7180
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../codecs/rt5682.h"
+#include "common.h"
+#include "lpass.h"
+
+#define DEFAULT_MCLK_RATE  1920
+#define RT5682_PLL1_FREQ (48000 * 512)
+
+// This will be defined in include/dt-bindings/sound/sc7180-lpass.h
+#define LPASS_DP_RX 2
+
+struct sc7180_snd_data {
+   struct snd_soc_card card;
+   u32 pri_mi2s_clk_count;
+   struct snd_soc_jack hs_jack;
+   struct snd_soc_jack hdmi_jack;
+};
+
+static void sc7180_jack_free(struct snd_jack *jack)
+{
+   struct snd_soc_component *component = jack->private_data;
+
+   snd_soc_component_set_jack(component, NULL, NULL);
+}
+
+static int sc7180_headset_init(struct snd_soc_pcm_runtime *rtd)
+{
+   struct snd_soc_card *card = rtd->card;
+   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
+   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+   struct snd_soc_component *component = codec_dai->component;
+   struct snd_jack *jack;
+   int rval;
+
+   rval = snd_soc_card_jack_new(
+   card, "Headset Jack",
+   SND_JACK_HEADSET |
+   SND_JACK_HEADPHONE |
+   SND_JACK_BTN_0 | SND_JACK_BTN_1 |
+   SND_JACK_BTN_2 | SND_JACK_BTN_3,
+   >hs_jack, NULL, 0);
+
+   if (rval < 0) {
+   dev_err(card->dev, "Unable to add Headset Jack\n");
+   return rval;
+   }
+
+   jack = pdata->hs_jack.jack;
+
+   snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
+   snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
+   snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
+   snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
+
+   jack->private_data = component;
+   jack->private_free = sc7180_jack_free;
+
+   return snd_soc_component_set_jack(component, >hs_jack, NULL);
+}
+
+static int sc7180_hdmi_init(struct snd_soc_pcm_runtime *rtd)
+{
+   struct snd_soc_card *card = rtd->card;
+   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
+   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+   struct snd_soc_component *component = codec_dai->component;
+   struct snd_jack *jack;
+   int rval;
+
+   rval = snd_soc_card_jack_new(
+   card, "HDMI Jack",
+   SND_JACK_LINEOUT,
+   >hdmi_jack, NULL, 0);
+
+   if (rval < 0) {
+ 

[PATCH v10 1/3] ASoC: hdmi-codec: Use set_jack ops to set jack

2020-09-11 Thread Cheng-Yi Chiang
Use set_jack ops to set jack so machine drivers do not need to include
hdmi-codec.h explicitly.

Signed-off-by: Cheng-Yi Chiang 
Reviewed-by: Tzung-Bi Shih 
---
 include/sound/hdmi-codec.h   |  3 ---
 sound/soc/codecs/hdmi-codec.c| 12 
 sound/soc/mediatek/mt8173/mt8173-rt5650.c|  5 ++---
 sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c   |  5 ++---
 .../mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c |  5 ++---
 sound/soc/rockchip/rockchip_max98090.c   |  3 +--
 6 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/include/sound/hdmi-codec.h b/include/sound/hdmi-codec.h
index 7754631a3102..b55970859a13 100644
--- a/include/sound/hdmi-codec.h
+++ b/include/sound/hdmi-codec.h
@@ -117,9 +117,6 @@ struct hdmi_codec_pdata {
 struct snd_soc_component;
 struct snd_soc_jack;
 
-int hdmi_codec_set_jack_detect(struct snd_soc_component *component,
-  struct snd_soc_jack *jack);
-
 #define HDMI_CODEC_DRV_NAME "hdmi-audio-codec"
 
 #endif /* __HDMI_CODEC_H__ */
diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c
index 8c6f540533ba..403d4c6a49a8 100644
--- a/sound/soc/codecs/hdmi-codec.c
+++ b/sound/soc/codecs/hdmi-codec.c
@@ -698,13 +698,9 @@ static void plugged_cb(struct device *dev, bool plugged)
hdmi_codec_jack_report(hcp, 0);
 }
 
-/**
- * hdmi_codec_set_jack_detect - register HDMI plugged callback
- * @component: the hdmi-codec instance
- * @jack: ASoC jack to report (dis)connection events on
- */
-int hdmi_codec_set_jack_detect(struct snd_soc_component *component,
-  struct snd_soc_jack *jack)
+static int hdmi_codec_set_jack(struct snd_soc_component *component,
+  struct snd_soc_jack *jack,
+  void *data)
 {
struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component);
int ret = -EOPNOTSUPP;
@@ -720,7 +716,6 @@ int hdmi_codec_set_jack_detect(struct snd_soc_component 
*component,
}
return ret;
 }
-EXPORT_SYMBOL_GPL(hdmi_codec_set_jack_detect);
 
 static int hdmi_dai_spdif_probe(struct snd_soc_dai *dai)
 {
@@ -806,6 +801,7 @@ static const struct snd_soc_component_driver hdmi_driver = {
.use_pmdown_time= 1,
.endianness = 1,
.non_legacy_dai_naming  = 1,
+   .set_jack   = hdmi_codec_set_jack,
 };
 
 static int hdmi_codec_probe(struct platform_device *pdev)
diff --git a/sound/soc/mediatek/mt8173/mt8173-rt5650.c 
b/sound/soc/mediatek/mt8173/mt8173-rt5650.c
index 347b095d478d..c28ebf891cb0 100644
--- a/sound/soc/mediatek/mt8173/mt8173-rt5650.c
+++ b/sound/soc/mediatek/mt8173/mt8173-rt5650.c
@@ -11,7 +11,6 @@
 #include 
 #include 
 #include 
-#include 
 #include "../../codecs/rt5645.h"
 
 #define MCLK_FOR_CODECS12288000
@@ -154,8 +153,8 @@ static int mt8173_rt5650_hdmi_init(struct 
snd_soc_pcm_runtime *rtd)
if (ret)
return ret;
 
-   return hdmi_codec_set_jack_detect(asoc_rtd_to_codec(rtd, 0)->component,
- _rt5650_hdmi_jack);
+   return snd_soc_component_set_jack(asoc_rtd_to_codec(rtd, 0)->component,
+ _rt5650_hdmi_jack, NULL);
 }
 
 enum {
diff --git a/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c 
b/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
index 06d0a4f80fc1..e53c6200d5a7 100644
--- a/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
+++ b/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
@@ -10,7 +10,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -369,8 +368,8 @@ static int mt8183_da7219_max98357_hdmi_init(struct 
snd_soc_pcm_runtime *rtd)
if (ret)
return ret;
 
-   return hdmi_codec_set_jack_detect(asoc_rtd_to_codec(rtd, 0)->component,
- >hdmi_jack);
+   return snd_soc_component_set_jack(asoc_rtd_to_codec(rtd, 0)->component,
+ >hdmi_jack, NULL);
 }
 
 static struct snd_soc_dai_link mt8183_da7219_dai_links[] = {
diff --git a/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c 
b/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
index 07410d7afaa9..327dfad41e31 100644
--- a/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
+++ b/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
@@ -9,7 +9,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -350,8 +349,8 @@ mt8183_mt6358_ts3a227_max98357_hdmi_init(struct 
snd_soc_pcm_runtime *rtd)
if (ret)
return ret;
 
-   return hdmi_codec_set_jack_detect(asoc_rtd_to_codec(rtd, 0)->component,
- >hdmi_jack);
+   return snd_soc_component_s

[PATCH v10 0/3] Add documentation and machine driver for SC7180 sound card

2020-09-11 Thread Cheng-Yi Chiang
Note:
- The machine driver patch is made by the collaboration of
  Cheng-Yi Chiang 
  Rohit kumar 
  Ajit Pandey 
  But Ajit has left codeaurora.
- This patch series needs HDMI DAI name SC7180_LPASS_DP defined in 
sc7180-lpass.h.
  It will be posted in the newer patchset of 
https://patchwork.kernel.org/patch/11745565/

Changes from v1 to v2:
- Ducumentation: Addressed all suggestions from Doug.
- Machine driver:
  - Fix comment style for license.
  - Sort includes.
  - Remove sc7180_snd_hw_params.
  - Remove sc7180_dai_init and use aux device instead for headset jack 
registration.
  - Statically define format for Primary MI2S.
  - Atomic is not a concern because there is mutex in card to make sure
startup and shutdown happen sequentially.
  - Fix missing return -EINVAL in startup.
  - Use static sound card.
  - Use devm_kzalloc to avoid kfree.

Changes from v2 to v3:
- Ducumentation: Addressed suggestions from Srini.
- Machine driver:
  - Reuse qcom_snd_parse_of to parse properties.
  - Remove playback-only and capture-only.
  - Misc fixes to address comments.

Changes from v3 to v4:
- Ducumentation: Addressed suggestions from Rob.
 - Remove definition of dai.
 - Use 'sound-dai: true' for sound-dai schema.
 - Add reg property to pass 'make dt_binding_check' check although reg is not 
used in the driver.
- Machine driver:
 - Add Reviewed-by: Tzung-Bi Shih 

Changes from v4 to v5:
- Documentation: Addressed suggestions from Rob.
 - Add definition for "#address-cells" and "#size-cells".
 - Add additionalProperties: false
 - Add required properties.

Changes from v5 to v6:
- Documentation: Addressed suggestions from Rob.
 - Drop contains in compatible strings.
 - Only allow dai-link@[0-9]
 - Remove reg ref since it has a type definition already.

Changes from v6 to v7
- Documentation:
  - Add headset-jack and hdmi-jack to specify the codec
responsible for jack detection.
- HDMI codec driver:
  - Use component set_jack ops instead of exporting hdmi_codec_set_jack_detect.
- Machine driver:
  - Removed aux device following Stephan's suggestion.
  - Use headset-jack and hdmi-jack to specify the codec
responsible for jack detection.
  - Add support for HDMI(actually DP) playback.

Changes from v7 to v8
- Documentation:
  - Remove headset-jack and hdmi-jack.
- Machine driver:
  - Let machine driver decide whether there is a jack on the DAI.

Changes from v8 to v9
- hdmi-codec driver:
  - Fixed the naming.
- Machine driver:
  - Fixed unused fields.
  - Moved snd_soc_card_set_drvdata
  - Keep the naming of HDMI as dai name until v5 of lpass-hdmi patches.

Changes from v9 to v10
- Documentation:
  - Let compatible string be more specific for board configuration to allow
for future changes.
- Machine driver:
  - Fixed unused include and macro.
  - Add temporary macro SC7180_LPASS_DP for future change in sc7180-lpass.h.
  - Let sound card be dynamically allocated.
  - Change compatible string accordingly.

Ajit Pandey (1):
  ASoC: qcom: sc7180: Add machine driver for sound card registration

Cheng-Yi Chiang (2):
  ASoC: hdmi-codec: Use set_jack ops to set jack
  ASoC: qcom: dt-bindings: Add sc7180 machine bindings

 .../bindings/sound/qcom,sc7180.yaml   | 130 +
 include/sound/hdmi-codec.h|   3 -
 sound/soc/codecs/hdmi-codec.c |  12 +-
 sound/soc/mediatek/mt8173/mt8173-rt5650.c |   5 +-
 .../mediatek/mt8183/mt8183-da7219-max98357.c  |   5 +-
 .../mt8183/mt8183-mt6358-ts3a227-max98357.c   |   5 +-
 sound/soc/qcom/Kconfig|  12 +
 sound/soc/qcom/Makefile   |   2 +
 sound/soc/qcom/sc7180.c   | 266 ++
 sound/soc/rockchip/rockchip_max98090.c|   3 +-
 10 files changed, 421 insertions(+), 22 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
 create mode 100644 sound/soc/qcom/sc7180.c

-- 
2.28.0.618.gf4bc123cb7-goog



[PATCH v10 2/3] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-09-11 Thread Cheng-Yi Chiang
Add devicetree bindings documentation file for sc7180 sound card.

Signed-off-by: Cheng-Yi Chiang 
---
 .../bindings/sound/qcom,sc7180.yaml   | 130 ++
 1 file changed, 130 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml

diff --git a/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml 
b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
new file mode 100644
index ..b77311bb5190
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
@@ -0,0 +1,130 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/qcom,sc7180.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Technologies Inc. SC7180 ASoC sound card driver
+
+maintainers:
+  - Rohit kumar 
+  - Cheng-Yi Chiang 
+
+description:
+  This binding describes the SC7180 sound card which uses LPASS for audio.
+
+properties:
+  compatible:
+const: qcom,sc7180-sndcard-rt5682-m98357-1mic
+
+  audio-routing:
+$ref: /schemas/types.yaml#/definitions/non-unique-string-array
+description:
+  A list of the connections between audio components. Each entry is a
+  pair of strings, the first being the connection's sink, the second
+  being the connection's source.
+
+  model:
+$ref: /schemas/types.yaml#/definitions/string
+description: User specified audio sound card name
+
+  "#address-cells":
+const: 1
+
+  "#size-cells":
+const: 0
+
+patternProperties:
+  "^dai-link(@[0-9])?$":
+description:
+  Each subnode represents a dai link. Subnodes of each dai links would be
+  cpu/codec dais.
+
+type: object
+
+properties:
+  link-name:
+description: Indicates dai-link name and PCM stream name.
+$ref: /schemas/types.yaml#/definitions/string
+maxItems: 1
+
+  reg:
+description: dai link address.
+
+  cpu:
+description: Holds subnode which indicates cpu dai.
+type: object
+properties:
+  sound-dai: true
+
+  codec:
+description: Holds subnode which indicates codec dai.
+type: object
+properties:
+  sound-dai: true
+
+required:
+  - link-name
+  - cpu
+  - codec
+
+additionalProperties: false
+
+required:
+  - compatible
+  - model
+  - "#address-cells"
+  - "#size-cells"
+
+additionalProperties: false
+
+examples:
+
+  - |
+sound {
+compatible = "qcom,sc7180-sndcard-rt5682-m98357-1mic";
+model = "sc7180-snd-card";
+
+audio-routing =
+"Headphone Jack", "HPOL",
+"Headphone Jack", "HPOR";
+
+#address-cells = <1>;
+#size-cells = <0>;
+
+dai-link@0 {
+link-name = "MultiMedia0";
+reg = <0>;
+cpu {
+sound-dai = <_cpu 0>;
+};
+
+codec {
+sound-dai = < 0>;
+};
+};
+
+dai-link@1 {
+link-name = "MultiMedia1";
+reg = <1>;
+cpu {
+sound-dai = <_cpu 1>;
+};
+
+codec {
+sound-dai = <>;
+};
+};
+
+dai-link@2 {
+link-name = "MultiMedia2";
+reg = <2>;
+cpu {
+sound-dai = <_hdmi 0>;
+};
+
+codec {
+sound-dai = <_dp>;
+};
+};
+};
-- 
2.28.0.618.gf4bc123cb7-goog



[PATCH v10 3/3] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-09-11 Thread Cheng-Yi Chiang
From: Ajit Pandey 

Add new driver to register sound card on sc7180 trogdor board and
do the required configuration for lpass cpu dai and external codecs
connected over MI2S interfaces.

Signed-off-by: Ajit Pandey 
Signed-off-by: Cheng-Yi Chiang 
---
 sound/soc/qcom/Kconfig  |  12 ++
 sound/soc/qcom/Makefile |   2 +
 sound/soc/qcom/sc7180.c | 266 
 3 files changed, 280 insertions(+)
 create mode 100644 sound/soc/qcom/sc7180.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index a607ace8b089..0459185ee243 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -116,4 +116,16 @@ config SND_SOC_SDM845
  SDM845 SoC-based systems.
  Say Y if you want to use audio device on this SoCs.
 
+config SND_SOC_SC7180
+   tristate "SoC Machine driver for SC7180 boards"
+   depends on I2C
+   select SND_SOC_QCOM_COMMON
+   select SND_SOC_LPASS_SC7180
+   select SND_SOC_MAX98357A
+   select SND_SOC_RT5682_I2C
+   help
+ To add support for audio on Qualcomm Technologies Inc.
+ SC7180 SoC-based systems.
+ Say Y if you want to use audio device on this SoCs.
+
 endif #SND_SOC_QCOM
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index 7972c9479ab0..0cdcbf367ef1 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -17,12 +17,14 @@ snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
 snd-soc-apq8096-objs := apq8096.o
 snd-soc-sdm845-objs := sdm845.o
+snd-soc-sc7180-objs := sc7180.o
 snd-soc-qcom-common-objs := common.o
 
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
 obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
 obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
+obj-$(CONFIG_SND_SOC_SC7180) += snd-soc-sc7180.o
 obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o
 
 #DSP lib
diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
new file mode 100644
index ..a82512b8b754
--- /dev/null
+++ b/sound/soc/qcom/sc7180.c
@@ -0,0 +1,266 @@
+// SPDX-License-Identifier: GPL-2.0-only
+//
+// Copyright (c) 2020, The Linux Foundation. All rights reserved.
+//
+// sc7180.c -- ALSA SoC Machine driver for SC7180
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../codecs/rt5682.h"
+#include "common.h"
+#include "lpass.h"
+
+#define DEFAULT_MCLK_RATE  1920
+#define RT5682_PLL1_FREQ (48000 * 512)
+
+// This will be defined in include/dt-bindings/sound/sc7180-lpass.h
+#define SC7180_LPASS_DP 2
+
+struct sc7180_snd_data {
+   struct snd_soc_card card;
+   u32 pri_mi2s_clk_count;
+   struct snd_soc_jack hs_jack;
+   struct snd_soc_jack hdmi_jack;
+};
+
+static void sc7180_jack_free(struct snd_jack *jack)
+{
+   struct snd_soc_component *component = jack->private_data;
+
+   snd_soc_component_set_jack(component, NULL, NULL);
+}
+
+static int sc7180_headset_init(struct snd_soc_pcm_runtime *rtd)
+{
+   struct snd_soc_card *card = rtd->card;
+   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
+   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+   struct snd_soc_component *component = codec_dai->component;
+   struct snd_jack *jack;
+   int rval;
+
+   rval = snd_soc_card_jack_new(
+   card, "Headset Jack",
+   SND_JACK_HEADSET |
+   SND_JACK_HEADPHONE |
+   SND_JACK_BTN_0 | SND_JACK_BTN_1 |
+   SND_JACK_BTN_2 | SND_JACK_BTN_3,
+   >hs_jack, NULL, 0);
+
+   if (rval < 0) {
+   dev_err(card->dev, "Unable to add Headset Jack\n");
+   return rval;
+   }
+
+   jack = pdata->hs_jack.jack;
+
+   snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
+   snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
+   snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
+   snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
+
+   jack->private_data = component;
+   jack->private_free = sc7180_jack_free;
+
+   return snd_soc_component_set_jack(component, >hs_jack, NULL);
+}
+
+static int sc7180_hdmi_init(struct snd_soc_pcm_runtime *rtd)
+{
+   struct snd_soc_card *card = rtd->card;
+   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
+   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+   struct snd_soc_component *component = codec_dai->component;
+   struct snd_jack *jack;
+   int rval;
+
+   rval = snd_soc_card_jack_new(
+   card, "HDMI Jack",
+   SND_JACK_LINEOUT,
+   >hdmi_jack, NULL, 0);
+
+   if (rval < 0) {
+ 

Re: [PATCH v9 3/3] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-09-11 Thread Cheng-yi Chiang
On Fri, Sep 11, 2020 at 11:01 PM Stephan Gerhold  wrote:
>
> Hi,
>
> Thanks for removing the weird use of auxilliary devices :)
>
Hi Stephan,
Thanks for the suggestion!

> On Fri, Sep 11, 2020 at 06:22:59PM +0800, Cheng-Yi Chiang wrote:
> > From: Ajit Pandey 
> >
> > Add new driver to register sound card on sc7180 trogdor board and
> > do the required configuration for lpass cpu dai and external codecs
> > connected over MI2S interfaces.
> >
> > Signed-off-by: Ajit Pandey 
> > Signed-off-by: Cheng-Yi Chiang 
> > ---
> >  sound/soc/qcom/Kconfig  |  12 ++
> >  sound/soc/qcom/Makefile |   2 +
> >  sound/soc/qcom/sc7180.c | 267 
> >  3 files changed, 281 insertions(+)
> >  create mode 100644 sound/soc/qcom/sc7180.c
> >
> > diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
> > index a607ace8b089..0459185ee243 100644
> > --- a/sound/soc/qcom/Kconfig
> > +++ b/sound/soc/qcom/Kconfig
> > @@ -116,4 +116,16 @@ config SND_SOC_SDM845
> > SDM845 SoC-based systems.
> > Say Y if you want to use audio device on this SoCs.
> >
> > +config SND_SOC_SC7180
> > + tristate "SoC Machine driver for SC7180 boards"
> > + depends on I2C
> > + select SND_SOC_QCOM_COMMON
> > + select SND_SOC_LPASS_SC7180
> > + select SND_SOC_MAX98357A
> > + select SND_SOC_RT5682_I2C
> > + help
> > +   To add support for audio on Qualcomm Technologies Inc.
> > +   SC7180 SoC-based systems.
> > +   Say Y if you want to use audio device on this SoCs.
> > +
> >  endif #SND_SOC_QCOM
> > diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
> > index 7972c9479ab0..0cdcbf367ef1 100644
> > --- a/sound/soc/qcom/Makefile
> > +++ b/sound/soc/qcom/Makefile
> > @@ -17,12 +17,14 @@ snd-soc-storm-objs := storm.o
> >  snd-soc-apq8016-sbc-objs := apq8016_sbc.o
> >  snd-soc-apq8096-objs := apq8096.o
> >  snd-soc-sdm845-objs := sdm845.o
> > +snd-soc-sc7180-objs := sc7180.o
> >  snd-soc-qcom-common-objs := common.o
> >
> >  obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
> >  obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
> >  obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
> >  obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
> > +obj-$(CONFIG_SND_SOC_SC7180) += snd-soc-sc7180.o
> >  obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o
> >
> >  #DSP lib
> > diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
> > new file mode 100644
> > index ..40bc4fc98842
> > --- /dev/null
> > +++ b/sound/soc/qcom/sc7180.c
> > @@ -0,0 +1,267 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +//
> > +// Copyright (c) 2020, The Linux Foundation. All rights reserved.
> > +//
> > +// sc7180.c -- ALSA SoC Machine driver for SC7180
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include "../codecs/rt5682.h"
> > +#include "common.h"
> > +#include "lpass.h"
> > +
> > +#define DEFAULT_SAMPLE_RATE_48K  48000
> > +#define DEFAULT_MCLK_RATE1920
> > +#define RT5682_PLL1_FREQ (48000 * 512)
> > +
> > +struct sc7180_snd_data {
> > + u32 pri_mi2s_clk_count;
> > + struct snd_soc_jack hs_jack;
> > + struct snd_soc_jack hdmi_jack;
> > +};
>
> [...]
>
> > +
> > +static const struct snd_soc_ops sc7180_ops = {
> > + .startup = sc7180_snd_startup,
> > + .shutdown = sc7180_snd_shutdown,
> > +};
> > +
> > +static const struct snd_soc_dapm_widget sc7180_snd_widgets[] = {
> > + SND_SOC_DAPM_HP("Headphone Jack", NULL),
> > + SND_SOC_DAPM_MIC("Headset Mic", NULL),
> > +};
> > +
> > +static struct snd_soc_card sc7180_card = {
> > + .owner = THIS_MODULE,
> > + .dapm_widgets = sc7180_snd_widgets,
> > + .num_dapm_widgets = ARRAY_SIZE(sc7180_snd_widgets),
> > +};
>
> Given that you modify this struct and already allocate some memory
> dynamically (sc7810_snd_data), it might be a bit cleaner to avoid
> modifying global memory and instead allocate snd_soc_card dynamically as
> well. Could just add it to sc7180_snd_data for example (see e.g. apq8016_sbc)
>
Good idea. I will modify it in v10.

> > +
> > +static void sc7180_add_ops(

Re: [PATCH v9 3/3] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-09-11 Thread Cheng-yi Chiang
On Fri, Sep 11, 2020 at 7:05 PM Srinivas Kandagatla
 wrote:
>
>
>
> On 11/09/2020 11:22, Cheng-Yi Chiang wrote:
> > From: Ajit Pandey 
> >
> > Add new driver to register sound card on sc7180 trogdor board and
> > do the required configuration for lpass cpu dai and external codecs
> > connected over MI2S interfaces.
> >
> > Signed-off-by: Ajit Pandey 
> > Signed-off-by: Cheng-Yi Chiang 
> > ---
> >   sound/soc/qcom/Kconfig  |  12 ++
> >   sound/soc/qcom/Makefile |   2 +
> >   sound/soc/qcom/sc7180.c | 267 
> >   3 files changed, 281 insertions(+)
> >   create mode 100644 sound/soc/qcom/sc7180.c
> >
> ...
> >
> >   obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
> >   obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
> >   obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
> >   obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
> > +obj-$(CONFIG_SND_SOC_SC7180) += snd-soc-sc7180.o
> >   obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o
> >
> >   #DSP lib
> > diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
> > new file mode 100644
> > index ..40bc4fc98842
> > --- /dev/null
> > +++ b/sound/soc/qcom/sc7180.c
> > @@ -0,0 +1,267 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +//
> > +// Copyright (c) 2020, The Linux Foundation. All rights reserved.
> > +//
> > +// sc7180.c -- ALSA SoC Machine driver for SC7180
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> Do you need this header?
>
Hi Srinivas, thanks for taking a closer look!
I will remove it in v10.
>
> > +#include 
> > +#include 
> > +
> > +#include "../codecs/rt5682.h"
> > +#include "common.h"
> > +#include "lpass.h"
> > +
> > +#define DEFAULT_SAMPLE_RATE_48K  48000
>
> Looks like ^ is Not used!
>
I will remove it in v10.

>
> Overall the driver looks much cleaner now!
>
> Also to make progress on this patch, may be you add define for HDMI with
> a comment!


After discussion with Srinivasa Rao, we plan to use a new name that is
more specific to lpass-sc7180 DP dai:

// This will be defined in include/dt-bindings/sound/sc7180-lpass.h
#define SC7180_LPASS_DP 2
Do you think it is okay ?
Thanks!

>
> Once unused remove, pl feel free to add !
>
> Reviewed-by: Srinivas Kandagatla 
>
>
> --srini
>
>
> > +#define DEFAULT_MCLK_RATE1920
> > +#define RT5682_PLL1_FREQ (48000 * 512)
> > +
> > +struct sc7180_snd_data {
> > + u32 pri_mi2s_clk_count;
> > + struct snd_soc_jack hs_jack;
> > + struct snd_soc_jack hdmi_jack;
> > +};
> > +
> > +static void sc7180_jack_free(struct snd_jack *jack)
> > +{
> > + struct snd_soc_component *component = jack->private_data;
> > +
> > + snd_soc_component_set_jack(component, NULL, NULL);
> > +}
> > +
> > +static int sc7180_headset_init(struct snd_soc_pcm_runtime *rtd)
> > +{
> > + struct snd_soc_card *card = rtd->card;
> > + struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
> > + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
> > + struct snd_soc_component *component = codec_dai->component;
> > + struct snd_jack *jack;
> > + int rval;
> > +
> > + rval = snd_soc_card_jack_new(
> > + card, "Headset Jack",
> > + SND_JACK_HEADSET |
> > + SND_JACK_HEADPHONE |
> > + SND_JACK_BTN_0 | SND_JACK_BTN_1 |
> > + SND_JACK_BTN_2 | SND_JACK_BTN_3,
> > + >hs_jack, NULL, 0);
> > +
> > + if (rval < 0) {
> > + dev_err(card->dev, "Unable to add Headset Jack\n");
> > + return rval;
> > + }
> > +
> > + jack = pdata->hs_jack.jack;
> > +
> > + snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
> > + snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
> > + snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
> > + snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
> > +
> > + jack->private_data = component;
> > + jack->private_free = sc7180_jack_free;
> > +
> > + return snd_soc_component_set_jack(component, >hs_jack, NULL);
> > +}
> > +

[PATCH v9 2/3] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-09-11 Thread Cheng-Yi Chiang
Add devicetree bindings documentation file for sc7180 sound card.

Signed-off-by: Cheng-Yi Chiang 
---
 .../bindings/sound/qcom,sc7180.yaml   | 130 ++
 1 file changed, 130 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml

diff --git a/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml 
b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
new file mode 100644
index ..a1fc53e33b07
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
@@ -0,0 +1,130 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/qcom,sc7180.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Technologies Inc. SC7180 ASoC sound card driver
+
+maintainers:
+  - Rohit kumar 
+  - Cheng-Yi Chiang 
+
+description:
+  This binding describes the SC7180 sound card which uses LPASS for audio.
+
+properties:
+  compatible:
+const: qcom,sc7180-sndcard
+
+  audio-routing:
+$ref: /schemas/types.yaml#/definitions/non-unique-string-array
+description:
+  A list of the connections between audio components. Each entry is a
+  pair of strings, the first being the connection's sink, the second
+  being the connection's source.
+
+  model:
+$ref: /schemas/types.yaml#/definitions/string
+description: User specified audio sound card name
+
+  "#address-cells":
+const: 1
+
+  "#size-cells":
+const: 0
+
+patternProperties:
+  "^dai-link(@[0-9])?$":
+description:
+  Each subnode represents a dai link. Subnodes of each dai links would be
+  cpu/codec dais.
+
+type: object
+
+properties:
+  link-name:
+description: Indicates dai-link name and PCM stream name.
+$ref: /schemas/types.yaml#/definitions/string
+maxItems: 1
+
+  reg:
+description: dai link address.
+
+  cpu:
+description: Holds subnode which indicates cpu dai.
+type: object
+properties:
+  sound-dai: true
+
+  codec:
+description: Holds subnode which indicates codec dai.
+type: object
+properties:
+  sound-dai: true
+
+required:
+  - link-name
+  - cpu
+  - codec
+
+additionalProperties: false
+
+required:
+  - compatible
+  - model
+  - "#address-cells"
+  - "#size-cells"
+
+additionalProperties: false
+
+examples:
+
+  - |
+sound {
+compatible = "qcom,sc7180-sndcard";
+model = "sc7180-snd-card";
+
+audio-routing =
+"Headphone Jack", "HPOL",
+"Headphone Jack", "HPOR";
+
+#address-cells = <1>;
+#size-cells = <0>;
+
+dai-link@0 {
+link-name = "MultiMedia0";
+reg = <0>;
+cpu {
+sound-dai = <_cpu 0>;
+};
+
+codec {
+sound-dai = < 0>;
+};
+};
+
+dai-link@1 {
+link-name = "MultiMedia1";
+reg = <1>;
+cpu {
+sound-dai = <_cpu 1>;
+};
+
+codec {
+sound-dai = <>;
+};
+};
+
+dai-link@2 {
+link-name = "MultiMedia2";
+reg = <2>;
+cpu {
+sound-dai = <_hdmi 0>;
+};
+
+codec {
+sound-dai = <_dp>;
+};
+};
+};
-- 
2.28.0.618.gf4bc123cb7-goog



[PATCH v9 0/3] Add documentation and machine driver for SC7180 sound card

2020-09-11 Thread Cheng-Yi Chiang
Note:
- The machine driver patch is made by the collaboration of
  Cheng-Yi Chiang 
  Rohit kumar 
  Ajit Pandey 
  But Ajit has left codeaurora.
- This patch series needs HDMI DAI name defined in sc7180-lpass.h.
  https://patchwork.kernel.org/patch/11745565/

Changes from v1 to v2:
- Ducumentation: Addressed all suggestions from Doug.
- Machine driver:
  - Fix comment style for license.
  - Sort includes.
  - Remove sc7180_snd_hw_params.
  - Remove sc7180_dai_init and use aux device instead for headset jack 
registration.
  - Statically define format for Primary MI2S.
  - Atomic is not a concern because there is mutex in card to make sure
startup and shutdown happen sequentially.
  - Fix missing return -EINVAL in startup.
  - Use static sound card.
  - Use devm_kzalloc to avoid kfree.

Changes from v2 to v3:
- Ducumentation: Addressed suggestions from Srini.
- Machine driver:
  - Reuse qcom_snd_parse_of to parse properties.
  - Remove playback-only and capture-only.
  - Misc fixes to address comments.

Changes from v3 to v4:
- Ducumentation: Addressed suggestions from Rob.
 - Remove definition of dai.
 - Use 'sound-dai: true' for sound-dai schema.
 - Add reg property to pass 'make dt_binding_check' check although reg is not 
used in the driver.
- Machine driver:
 - Add Reviewed-by: Tzung-Bi Shih 

Changes from v4 to v5:
- Documentation: Addressed suggestions from Rob.
 - Add definition for "#address-cells" and "#size-cells".
 - Add additionalProperties: false
 - Add required properties.

Changes from v5 to v6:
- Documentation: Addressed suggestions from Rob.
 - Drop contains in compatible strings.
 - Only allow dai-link@[0-9]
 - Remove reg ref since it has a type definition already.

Changes from v6 to v7
- Documentation:
  - Add headset-jack and hdmi-jack to specify the codec
responsible for jack detection.
- HDMI codec driver:
  - Use component set_jack ops instead of exporting hdmi_codec_set_jack_detect.
- Machine driver:
  - Removed aux device following Stephan's suggestion.
  - Use headset-jack and hdmi-jack to specify the codec
responsible for jack detection.
  - Add support for HDMI(actually DP) playback.

Changes from v7 to v8
- Documentation:
  - Remove headset-jack and hdmi-jack.
- Machine driver:
  - Let machine driver decide whether there is a jack on the DAI.

Changes from v8 to v9
- hdmi-codec driver:
  - Fixed the naming.
- Machine driver:
  - Fixed unused fields.
  - Moved snd_soc_card_set_drvdata
  - Keep the naming of HDMI as dai name until v5 of lpass-hdmi patches.

Ajit Pandey (1):
  ASoC: qcom: sc7180: Add machine driver for sound card registration

Cheng-Yi Chiang (2):
  ASoC: hdmi-codec: Use set_jack ops to set jack
  ASoC: qcom: dt-bindings: Add sc7180 machine bindings

 .../bindings/sound/qcom,sc7180.yaml   | 130 +
 include/sound/hdmi-codec.h|   3 -
 sound/soc/codecs/hdmi-codec.c |  12 +-
 sound/soc/mediatek/mt8173/mt8173-rt5650.c |   5 +-
 .../mediatek/mt8183/mt8183-da7219-max98357.c  |   5 +-
 .../mt8183/mt8183-mt6358-ts3a227-max98357.c   |   5 +-
 sound/soc/qcom/Kconfig|  12 +
 sound/soc/qcom/Makefile   |   2 +
 sound/soc/qcom/sc7180.c   | 267 ++
 sound/soc/rockchip/rockchip_max98090.c|   3 +-
 10 files changed, 422 insertions(+), 22 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
 create mode 100644 sound/soc/qcom/sc7180.c

-- 
2.28.0.618.gf4bc123cb7-goog



[PATCH v9 1/3] ASoC: hdmi-codec: Use set_jack ops to set jack

2020-09-11 Thread Cheng-Yi Chiang
Use set_jack ops to set jack so machine drivers do not need to include
hdmi-codec.h explicitly.

Signed-off-by: Cheng-Yi Chiang 
Reviewed-by: Tzung-Bi Shih 
---
 include/sound/hdmi-codec.h   |  3 ---
 sound/soc/codecs/hdmi-codec.c| 12 
 sound/soc/mediatek/mt8173/mt8173-rt5650.c|  5 ++---
 sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c   |  5 ++---
 .../mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c |  5 ++---
 sound/soc/rockchip/rockchip_max98090.c   |  3 +--
 6 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/include/sound/hdmi-codec.h b/include/sound/hdmi-codec.h
index 7754631a3102..b55970859a13 100644
--- a/include/sound/hdmi-codec.h
+++ b/include/sound/hdmi-codec.h
@@ -117,9 +117,6 @@ struct hdmi_codec_pdata {
 struct snd_soc_component;
 struct snd_soc_jack;
 
-int hdmi_codec_set_jack_detect(struct snd_soc_component *component,
-  struct snd_soc_jack *jack);
-
 #define HDMI_CODEC_DRV_NAME "hdmi-audio-codec"
 
 #endif /* __HDMI_CODEC_H__ */
diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c
index 8c6f540533ba..403d4c6a49a8 100644
--- a/sound/soc/codecs/hdmi-codec.c
+++ b/sound/soc/codecs/hdmi-codec.c
@@ -698,13 +698,9 @@ static void plugged_cb(struct device *dev, bool plugged)
hdmi_codec_jack_report(hcp, 0);
 }
 
-/**
- * hdmi_codec_set_jack_detect - register HDMI plugged callback
- * @component: the hdmi-codec instance
- * @jack: ASoC jack to report (dis)connection events on
- */
-int hdmi_codec_set_jack_detect(struct snd_soc_component *component,
-  struct snd_soc_jack *jack)
+static int hdmi_codec_set_jack(struct snd_soc_component *component,
+  struct snd_soc_jack *jack,
+  void *data)
 {
struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component);
int ret = -EOPNOTSUPP;
@@ -720,7 +716,6 @@ int hdmi_codec_set_jack_detect(struct snd_soc_component 
*component,
}
return ret;
 }
-EXPORT_SYMBOL_GPL(hdmi_codec_set_jack_detect);
 
 static int hdmi_dai_spdif_probe(struct snd_soc_dai *dai)
 {
@@ -806,6 +801,7 @@ static const struct snd_soc_component_driver hdmi_driver = {
.use_pmdown_time= 1,
.endianness = 1,
.non_legacy_dai_naming  = 1,
+   .set_jack   = hdmi_codec_set_jack,
 };
 
 static int hdmi_codec_probe(struct platform_device *pdev)
diff --git a/sound/soc/mediatek/mt8173/mt8173-rt5650.c 
b/sound/soc/mediatek/mt8173/mt8173-rt5650.c
index 347b095d478d..c28ebf891cb0 100644
--- a/sound/soc/mediatek/mt8173/mt8173-rt5650.c
+++ b/sound/soc/mediatek/mt8173/mt8173-rt5650.c
@@ -11,7 +11,6 @@
 #include 
 #include 
 #include 
-#include 
 #include "../../codecs/rt5645.h"
 
 #define MCLK_FOR_CODECS12288000
@@ -154,8 +153,8 @@ static int mt8173_rt5650_hdmi_init(struct 
snd_soc_pcm_runtime *rtd)
if (ret)
return ret;
 
-   return hdmi_codec_set_jack_detect(asoc_rtd_to_codec(rtd, 0)->component,
- _rt5650_hdmi_jack);
+   return snd_soc_component_set_jack(asoc_rtd_to_codec(rtd, 0)->component,
+ _rt5650_hdmi_jack, NULL);
 }
 
 enum {
diff --git a/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c 
b/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
index 06d0a4f80fc1..e53c6200d5a7 100644
--- a/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
+++ b/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
@@ -10,7 +10,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -369,8 +368,8 @@ static int mt8183_da7219_max98357_hdmi_init(struct 
snd_soc_pcm_runtime *rtd)
if (ret)
return ret;
 
-   return hdmi_codec_set_jack_detect(asoc_rtd_to_codec(rtd, 0)->component,
- >hdmi_jack);
+   return snd_soc_component_set_jack(asoc_rtd_to_codec(rtd, 0)->component,
+ >hdmi_jack, NULL);
 }
 
 static struct snd_soc_dai_link mt8183_da7219_dai_links[] = {
diff --git a/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c 
b/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
index 07410d7afaa9..327dfad41e31 100644
--- a/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
+++ b/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
@@ -9,7 +9,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -350,8 +349,8 @@ mt8183_mt6358_ts3a227_max98357_hdmi_init(struct 
snd_soc_pcm_runtime *rtd)
if (ret)
return ret;
 
-   return hdmi_codec_set_jack_detect(asoc_rtd_to_codec(rtd, 0)->component,
- >hdmi_jack);
+   return snd_soc_component_s

[PATCH v9 3/3] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-09-11 Thread Cheng-Yi Chiang
From: Ajit Pandey 

Add new driver to register sound card on sc7180 trogdor board and
do the required configuration for lpass cpu dai and external codecs
connected over MI2S interfaces.

Signed-off-by: Ajit Pandey 
Signed-off-by: Cheng-Yi Chiang 
---
 sound/soc/qcom/Kconfig  |  12 ++
 sound/soc/qcom/Makefile |   2 +
 sound/soc/qcom/sc7180.c | 267 
 3 files changed, 281 insertions(+)
 create mode 100644 sound/soc/qcom/sc7180.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index a607ace8b089..0459185ee243 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -116,4 +116,16 @@ config SND_SOC_SDM845
  SDM845 SoC-based systems.
  Say Y if you want to use audio device on this SoCs.
 
+config SND_SOC_SC7180
+   tristate "SoC Machine driver for SC7180 boards"
+   depends on I2C
+   select SND_SOC_QCOM_COMMON
+   select SND_SOC_LPASS_SC7180
+   select SND_SOC_MAX98357A
+   select SND_SOC_RT5682_I2C
+   help
+ To add support for audio on Qualcomm Technologies Inc.
+ SC7180 SoC-based systems.
+ Say Y if you want to use audio device on this SoCs.
+
 endif #SND_SOC_QCOM
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index 7972c9479ab0..0cdcbf367ef1 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -17,12 +17,14 @@ snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
 snd-soc-apq8096-objs := apq8096.o
 snd-soc-sdm845-objs := sdm845.o
+snd-soc-sc7180-objs := sc7180.o
 snd-soc-qcom-common-objs := common.o
 
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
 obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
 obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
+obj-$(CONFIG_SND_SOC_SC7180) += snd-soc-sc7180.o
 obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o
 
 #DSP lib
diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
new file mode 100644
index ..40bc4fc98842
--- /dev/null
+++ b/sound/soc/qcom/sc7180.c
@@ -0,0 +1,267 @@
+// SPDX-License-Identifier: GPL-2.0-only
+//
+// Copyright (c) 2020, The Linux Foundation. All rights reserved.
+//
+// sc7180.c -- ALSA SoC Machine driver for SC7180
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../codecs/rt5682.h"
+#include "common.h"
+#include "lpass.h"
+
+#define DEFAULT_SAMPLE_RATE_48K48000
+#define DEFAULT_MCLK_RATE  1920
+#define RT5682_PLL1_FREQ (48000 * 512)
+
+struct sc7180_snd_data {
+   u32 pri_mi2s_clk_count;
+   struct snd_soc_jack hs_jack;
+   struct snd_soc_jack hdmi_jack;
+};
+
+static void sc7180_jack_free(struct snd_jack *jack)
+{
+   struct snd_soc_component *component = jack->private_data;
+
+   snd_soc_component_set_jack(component, NULL, NULL);
+}
+
+static int sc7180_headset_init(struct snd_soc_pcm_runtime *rtd)
+{
+   struct snd_soc_card *card = rtd->card;
+   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
+   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+   struct snd_soc_component *component = codec_dai->component;
+   struct snd_jack *jack;
+   int rval;
+
+   rval = snd_soc_card_jack_new(
+   card, "Headset Jack",
+   SND_JACK_HEADSET |
+   SND_JACK_HEADPHONE |
+   SND_JACK_BTN_0 | SND_JACK_BTN_1 |
+   SND_JACK_BTN_2 | SND_JACK_BTN_3,
+   >hs_jack, NULL, 0);
+
+   if (rval < 0) {
+   dev_err(card->dev, "Unable to add Headset Jack\n");
+   return rval;
+   }
+
+   jack = pdata->hs_jack.jack;
+
+   snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
+   snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
+   snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
+   snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
+
+   jack->private_data = component;
+   jack->private_free = sc7180_jack_free;
+
+   return snd_soc_component_set_jack(component, >hs_jack, NULL);
+}
+
+static int sc7180_hdmi_init(struct snd_soc_pcm_runtime *rtd)
+{
+   struct snd_soc_card *card = rtd->card;
+   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
+   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+   struct snd_soc_component *component = codec_dai->component;
+   struct snd_jack *jack;
+   int rval;
+
+   rval = snd_soc_card_jack_new(
+   card, "HDMI Jack",
+   SND_JACK_LINEOUT,
+   >hdmi_jack, NULL, 0);
+
+   if (rval < 0) {
+   dev_err(card->dev, "Unable to add HDMI Jack\n&

[PATCH v8 3/3] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-09-09 Thread Cheng-Yi Chiang
From: Ajit Pandey 

Add new driver to register sound card on sc7180 trogdor board and
do the required configuration for lpass cpu dai and external codecs
connected over MI2S interfaces.

Signed-off-by: Ajit Pandey 
Signed-off-by: Cheng-Yi Chiang 
---
 sound/soc/qcom/Kconfig  |  12 ++
 sound/soc/qcom/Makefile |   2 +
 sound/soc/qcom/sc7180.c | 270 
 3 files changed, 284 insertions(+)
 create mode 100644 sound/soc/qcom/sc7180.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index a607ace8b089..0459185ee243 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -116,4 +116,16 @@ config SND_SOC_SDM845
  SDM845 SoC-based systems.
  Say Y if you want to use audio device on this SoCs.
 
+config SND_SOC_SC7180
+   tristate "SoC Machine driver for SC7180 boards"
+   depends on I2C
+   select SND_SOC_QCOM_COMMON
+   select SND_SOC_LPASS_SC7180
+   select SND_SOC_MAX98357A
+   select SND_SOC_RT5682_I2C
+   help
+ To add support for audio on Qualcomm Technologies Inc.
+ SC7180 SoC-based systems.
+ Say Y if you want to use audio device on this SoCs.
+
 endif #SND_SOC_QCOM
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index 7972c9479ab0..0cdcbf367ef1 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -17,12 +17,14 @@ snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
 snd-soc-apq8096-objs := apq8096.o
 snd-soc-sdm845-objs := sdm845.o
+snd-soc-sc7180-objs := sc7180.o
 snd-soc-qcom-common-objs := common.o
 
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
 obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
 obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
+obj-$(CONFIG_SND_SOC_SC7180) += snd-soc-sc7180.o
 obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o
 
 #DSP lib
diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
new file mode 100644
index ..1fad946e3e07
--- /dev/null
+++ b/sound/soc/qcom/sc7180.c
@@ -0,0 +1,270 @@
+// SPDX-License-Identifier: GPL-2.0-only
+//
+// Copyright (c) 2020, The Linux Foundation. All rights reserved.
+//
+// sc7180.c -- ALSA SoC Machine driver for SC7180
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../codecs/rt5682.h"
+#include "common.h"
+#include "lpass.h"
+
+#define DEFAULT_SAMPLE_RATE_48K48000
+#define DEFAULT_MCLK_RATE  1920
+#define RT5682_PLL1_FREQ (48000 * 512)
+
+struct sc7180_snd_data {
+   u32 pri_mi2s_clk_count;
+   struct snd_soc_jack hs_jack;
+   struct device_node *hs_jack_of_node;
+   struct snd_soc_jack hdmi_jack;
+   struct device_node *hdmi_jack_of_node;
+};
+
+static void sc7180_jack_free(struct snd_jack *jack)
+{
+   struct snd_soc_component *component = jack->private_data;
+
+   snd_soc_component_set_jack(component, NULL, NULL);
+}
+
+static int sc7180_headset_init(struct snd_soc_pcm_runtime *rtd)
+{
+   struct snd_soc_card *card = rtd->card;
+   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
+   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+   struct snd_soc_component *component = codec_dai->component;
+   struct snd_jack *jack;
+   int rval;
+
+   rval = snd_soc_card_jack_new(
+   card, "Headset Jack",
+   SND_JACK_HEADSET |
+   SND_JACK_HEADPHONE |
+   SND_JACK_BTN_0 | SND_JACK_BTN_1 |
+   SND_JACK_BTN_2 | SND_JACK_BTN_3,
+   >hs_jack, NULL, 0);
+
+   if (rval < 0) {
+   dev_err(card->dev, "Unable to add Headset Jack\n");
+   return rval;
+   }
+
+   jack = pdata->hs_jack.jack;
+
+   snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
+   snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
+   snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
+   snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
+
+   jack->private_data = component;
+   jack->private_free = sc7180_jack_free;
+
+   return snd_soc_component_set_jack(component, >hs_jack, NULL);
+}
+
+static int sc7180_hdmi_init(struct snd_soc_pcm_runtime *rtd)
+{
+   struct snd_soc_card *card = rtd->card;
+   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
+   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+   struct snd_soc_component *component = codec_dai->component;
+   struct snd_jack *jack;
+   int rval;
+
+   rval = snd_soc_card_jack_new(
+   card, "HDMI Jack",
+   SND_JACK_LINEOUT,
+   >hdmi_jack, NULL, 0);
+
+  

[PATCH v8 2/3] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-09-09 Thread Cheng-Yi Chiang
Add devicetree bindings documentation file for sc7180 sound card.

Signed-off-by: Cheng-Yi Chiang 
---
 .../bindings/sound/qcom,sc7180.yaml   | 130 ++
 1 file changed, 130 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml

diff --git a/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml 
b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
new file mode 100644
index ..a1fc53e33b07
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
@@ -0,0 +1,130 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/qcom,sc7180.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Technologies Inc. SC7180 ASoC sound card driver
+
+maintainers:
+  - Rohit kumar 
+  - Cheng-Yi Chiang 
+
+description:
+  This binding describes the SC7180 sound card which uses LPASS for audio.
+
+properties:
+  compatible:
+const: qcom,sc7180-sndcard
+
+  audio-routing:
+$ref: /schemas/types.yaml#/definitions/non-unique-string-array
+description:
+  A list of the connections between audio components. Each entry is a
+  pair of strings, the first being the connection's sink, the second
+  being the connection's source.
+
+  model:
+$ref: /schemas/types.yaml#/definitions/string
+description: User specified audio sound card name
+
+  "#address-cells":
+const: 1
+
+  "#size-cells":
+const: 0
+
+patternProperties:
+  "^dai-link(@[0-9])?$":
+description:
+  Each subnode represents a dai link. Subnodes of each dai links would be
+  cpu/codec dais.
+
+type: object
+
+properties:
+  link-name:
+description: Indicates dai-link name and PCM stream name.
+$ref: /schemas/types.yaml#/definitions/string
+maxItems: 1
+
+  reg:
+description: dai link address.
+
+  cpu:
+description: Holds subnode which indicates cpu dai.
+type: object
+properties:
+  sound-dai: true
+
+  codec:
+description: Holds subnode which indicates codec dai.
+type: object
+properties:
+  sound-dai: true
+
+required:
+  - link-name
+  - cpu
+  - codec
+
+additionalProperties: false
+
+required:
+  - compatible
+  - model
+  - "#address-cells"
+  - "#size-cells"
+
+additionalProperties: false
+
+examples:
+
+  - |
+sound {
+compatible = "qcom,sc7180-sndcard";
+model = "sc7180-snd-card";
+
+audio-routing =
+"Headphone Jack", "HPOL",
+"Headphone Jack", "HPOR";
+
+#address-cells = <1>;
+#size-cells = <0>;
+
+dai-link@0 {
+link-name = "MultiMedia0";
+reg = <0>;
+cpu {
+sound-dai = <_cpu 0>;
+};
+
+codec {
+sound-dai = < 0>;
+};
+};
+
+dai-link@1 {
+link-name = "MultiMedia1";
+reg = <1>;
+cpu {
+sound-dai = <_cpu 1>;
+};
+
+codec {
+sound-dai = <>;
+};
+};
+
+dai-link@2 {
+link-name = "MultiMedia2";
+reg = <2>;
+cpu {
+sound-dai = <_hdmi 0>;
+};
+
+codec {
+sound-dai = <_dp>;
+};
+};
+};
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v8 1/3] ASoC: hdmi-codec: Use set_jack ops to set jack

2020-09-09 Thread Cheng-Yi Chiang
Use set_jack ops to set jack so machine drivers do not need to include
hdmi-codec.h explicitly.

Signed-off-by: Cheng-Yi Chiang 
---
 include/sound/hdmi-codec.h   |  3 ---
 sound/soc/codecs/hdmi-codec.c| 12 
 sound/soc/mediatek/mt8173/mt8173-rt5650.c|  5 ++---
 sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c   |  5 ++---
 .../mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c |  5 ++---
 sound/soc/rockchip/rockchip_max98090.c   |  3 +--
 6 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/include/sound/hdmi-codec.h b/include/sound/hdmi-codec.h
index 7754631a3102..b55970859a13 100644
--- a/include/sound/hdmi-codec.h
+++ b/include/sound/hdmi-codec.h
@@ -117,9 +117,6 @@ struct hdmi_codec_pdata {
 struct snd_soc_component;
 struct snd_soc_jack;
 
-int hdmi_codec_set_jack_detect(struct snd_soc_component *component,
-  struct snd_soc_jack *jack);
-
 #define HDMI_CODEC_DRV_NAME "hdmi-audio-codec"
 
 #endif /* __HDMI_CODEC_H__ */
diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c
index 8c6f540533ba..d1de5bcd5daa 100644
--- a/sound/soc/codecs/hdmi-codec.c
+++ b/sound/soc/codecs/hdmi-codec.c
@@ -698,13 +698,9 @@ static void plugged_cb(struct device *dev, bool plugged)
hdmi_codec_jack_report(hcp, 0);
 }
 
-/**
- * hdmi_codec_set_jack_detect - register HDMI plugged callback
- * @component: the hdmi-codec instance
- * @jack: ASoC jack to report (dis)connection events on
- */
-int hdmi_codec_set_jack_detect(struct snd_soc_component *component,
-  struct snd_soc_jack *jack)
+static int hdmi_codec_set_jack_detect(struct snd_soc_component *component,
+ struct snd_soc_jack *jack,
+ void *data)
 {
struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component);
int ret = -EOPNOTSUPP;
@@ -720,7 +716,6 @@ int hdmi_codec_set_jack_detect(struct snd_soc_component 
*component,
}
return ret;
 }
-EXPORT_SYMBOL_GPL(hdmi_codec_set_jack_detect);
 
 static int hdmi_dai_spdif_probe(struct snd_soc_dai *dai)
 {
@@ -806,6 +801,7 @@ static const struct snd_soc_component_driver hdmi_driver = {
.use_pmdown_time= 1,
.endianness = 1,
.non_legacy_dai_naming  = 1,
+   .set_jack   = hdmi_codec_set_jack_detect,
 };
 
 static int hdmi_codec_probe(struct platform_device *pdev)
diff --git a/sound/soc/mediatek/mt8173/mt8173-rt5650.c 
b/sound/soc/mediatek/mt8173/mt8173-rt5650.c
index 347b095d478d..c28ebf891cb0 100644
--- a/sound/soc/mediatek/mt8173/mt8173-rt5650.c
+++ b/sound/soc/mediatek/mt8173/mt8173-rt5650.c
@@ -11,7 +11,6 @@
 #include 
 #include 
 #include 
-#include 
 #include "../../codecs/rt5645.h"
 
 #define MCLK_FOR_CODECS12288000
@@ -154,8 +153,8 @@ static int mt8173_rt5650_hdmi_init(struct 
snd_soc_pcm_runtime *rtd)
if (ret)
return ret;
 
-   return hdmi_codec_set_jack_detect(asoc_rtd_to_codec(rtd, 0)->component,
- _rt5650_hdmi_jack);
+   return snd_soc_component_set_jack(asoc_rtd_to_codec(rtd, 0)->component,
+ _rt5650_hdmi_jack, NULL);
 }
 
 enum {
diff --git a/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c 
b/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
index 06d0a4f80fc1..e53c6200d5a7 100644
--- a/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
+++ b/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
@@ -10,7 +10,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -369,8 +368,8 @@ static int mt8183_da7219_max98357_hdmi_init(struct 
snd_soc_pcm_runtime *rtd)
if (ret)
return ret;
 
-   return hdmi_codec_set_jack_detect(asoc_rtd_to_codec(rtd, 0)->component,
- >hdmi_jack);
+   return snd_soc_component_set_jack(asoc_rtd_to_codec(rtd, 0)->component,
+ >hdmi_jack, NULL);
 }
 
 static struct snd_soc_dai_link mt8183_da7219_dai_links[] = {
diff --git a/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c 
b/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
index 07410d7afaa9..327dfad41e31 100644
--- a/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
+++ b/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
@@ -9,7 +9,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -350,8 +349,8 @@ mt8183_mt6358_ts3a227_max98357_hdmi_init(struct 
snd_soc_pcm_runtime *rtd)
if (ret)
return ret;
 
-   return hdmi_codec_set_jack_detect(asoc_rtd_to_codec(rtd, 0)->component,
- >hdmi_jack);
+   return snd_soc_component_s

[PATCH v8 0/3] Add documentation and machine driver for SC7180 sound card

2020-09-09 Thread Cheng-Yi Chiang
Note:
- The machine driver patch is made by the collaboration of
  Cheng-Yi Chiang 
  Rohit kumar 
  Ajit Pandey 
  But Ajit has left codeaurora.
- This patch series needs HDMI DAI name defined in sc7180-lpass.h.
  https://patchwork.kernel.org/patch/11745565/

Changes from v1 to v2:
- Ducumentation: Addressed all suggestions from Doug.
- Machine driver:
  - Fix comment style for license.
  - Sort includes.
  - Remove sc7180_snd_hw_params.
  - Remove sc7180_dai_init and use aux device instead for headset jack 
registration.
  - Statically define format for Primary MI2S.
  - Atomic is not a concern because there is mutex in card to make sure
startup and shutdown happen sequentially.
  - Fix missing return -EINVAL in startup.
  - Use static sound card.
  - Use devm_kzalloc to avoid kfree.

Changes from v2 to v3:
- Ducumentation: Addressed suggestions from Srini.
- Machine driver:
  - Reuse qcom_snd_parse_of to parse properties.
  - Remove playback-only and capture-only.
  - Misc fixes to address comments.

Changes from v3 to v4:
- Ducumentation: Addressed suggestions from Rob.
 - Remove definition of dai.
 - Use 'sound-dai: true' for sound-dai schema.
 - Add reg property to pass 'make dt_binding_check' check although reg is not 
used in the driver.
- Machine driver:
 - Add Reviewed-by: Tzung-Bi Shih 

Changes from v4 to v5:
- Documentation: Addressed suggestions from Rob.
 - Add definition for "#address-cells" and "#size-cells".
 - Add additionalProperties: false
 - Add required properties.

Changes from v5 to v6:
- Documentation: Addressed suggestions from Rob.
 - Drop contains in compatible strings.
 - Only allow dai-link@[0-9]
 - Remove reg ref since it has a type definition already.

Changes from v6 to v7
- Documentation:
  - Add headset-jack and hdmi-jack to specify the codec
responsible for jack detection.
- HDMI codec driver:
  - Use component set_jack ops instead of exporting hdmi_codec_set_jack_detect.
- Machine driver:
  - Removed aux device following Stephan's suggestion.
  - Use headset-jack and hdmi-jack to specify the codec
responsible for jack detection.
  - Add support for HDMI(actually DP) playback.

Changes from v7 to v8
- Documentation:
  - Remove headset-jack and hdmi-jack.
- Machine driver:
  - Let machine driver decide whether there is a jack on the DAI.

Ajit Pandey (1):
  ASoC: qcom: sc7180: Add machine driver for sound card registration

Cheng-Yi Chiang (2):
  ASoC: hdmi-codec: Use set_jack ops to set jack
  ASoC: qcom: dt-bindings: Add sc7180 machine bindings

 .../bindings/sound/qcom,sc7180.yaml   | 130 +
 include/sound/hdmi-codec.h|   3 -
 sound/soc/codecs/hdmi-codec.c |  12 +-
 sound/soc/mediatek/mt8173/mt8173-rt5650.c |   5 +-
 .../mediatek/mt8183/mt8183-da7219-max98357.c  |   5 +-
 .../mt8183/mt8183-mt6358-ts3a227-max98357.c   |   5 +-
 sound/soc/qcom/Kconfig|  12 +
 sound/soc/qcom/Makefile   |   2 +
 sound/soc/qcom/sc7180.c   | 270 ++
 sound/soc/rockchip/rockchip_max98090.c|   3 +-
 10 files changed, 425 insertions(+), 22 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
 create mode 100644 sound/soc/qcom/sc7180.c

-- 
2.28.0.526.ge36021eeef-goog



Re: [PATCH v7 2/3] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-09-09 Thread Cheng-yi Chiang
On Thu, Sep 10, 2020 at 1:49 AM Rob Herring  wrote:
>
> On Wed, Sep 9, 2020 at 3:24 AM Cheng-yi Chiang  wrote:
> >
> > On Wed, Sep 9, 2020 at 4:34 AM Rob Herring  wrote:
> > >
> > > On Mon, Sep 07, 2020 at 06:00:38PM +0800, Cheng-Yi Chiang wrote:
> > > > Add devicetree bindings documentation file for sc7180 sound card.
> > > >
> > > > Signed-off-by: Cheng-Yi Chiang 
> > > > ---
> > > >  .../bindings/sound/qcom,sc7180.yaml   | 143 ++
> > > >  1 file changed, 143 insertions(+)
> > > >  create mode 100644 
> > > > Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> > > >
> > > > diff --git a/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml 
> > > > b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> > > > new file mode 100644
> > > > index ..ae809346ca80
> > > > --- /dev/null
> > > > +++ b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> > > > @@ -0,0 +1,143 @@
> > > > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> > > > +%YAML 1.2
> > > > +---
> > > > +$id: http://devicetree.org/schemas/sound/qcom,sc7180.yaml#
> > > > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > > > +
> > > > +title: Qualcomm Technologies Inc. SC7180 ASoC sound card driver
> > > > +
> > > > +maintainers:
> > > > +  - Rohit kumar 
> > > > +  - Cheng-Yi Chiang 
> > > > +
> > > > +description:
> > > > +  This binding describes the SC7180 sound card which uses LPASS for 
> > > > audio.
> > > > +
> > > > +properties:
> > > > +  compatible:
> > > > +const: qcom,sc7180-sndcard
> > > > +
> > > > +  audio-routing:
> > > > +$ref: /schemas/types.yaml#/definitions/non-unique-string-array
> > > > +description:
> > > > +  A list of the connections between audio components. Each entry 
> > > > is a
> > > > +  pair of strings, the first being the connection's sink, the 
> > > > second
> > > > +  being the connection's source.
> > > > +
> > > > +  model:
> > > > +$ref: /schemas/types.yaml#/definitions/string
> > > > +description: User specified audio sound card name
> > > > +
> > > > +  headset-jack:
> > > > +$ref: /schemas/types.yaml#/definitions/phandle
> > > > +description: phandle of the codec for headset detection
> > > > +
> > > > +  hdmi-jack:
> > > > +$ref: /schemas/types.yaml#/definitions/phandle
> > > > +description: phandle of the codec for hdmi jack detection
> > >
> > > You already have links to these devices. Why duplicate it here?
> > >
> > > What if you had 2 headsets? This doesn't scale.
> > >
> > Hi Rob, thanks for reviewing.
> > There was some discussion in
> > https://patchwork.kernel.org/patch/11737905/#23571643 about how to
> > specify the dailink that has a headset jack.
> > I would like to pass the information of headset jack and hdmi jack to
> > the machine driver so the machine driver can call
> > snd_soc_component_set_jack to set jack when init the corresponding link.
> > Headset jack and hdmi jack will be treated differently for button and
> > event type.
> > Because of this, we can not just set a property "jack" in the link.
>
> Don't design your binding around some driver architecture. Limitations
> of ASoC are not reasons for your binding.
>
> For DP and HDMI, we assume HPD is supported generally as that's a
> standard function for HDMI/DP controllers. There's a 'no-hpd' property
> for cases of broken HPD. That hardware description is part of the
> device HPD is connected to which is the HDMI/DP controller/bridge or
> the connector node in the case of a GPIO line. That doesn't belong in
> the virtual sound card.
>
> I would assume a codec to be similar. The codec node (the alc5682
> node) should have any jack related properties (or possibly implicitly
> support it by default).


Thanks for the explanation. Now I can follow your thoughts.
I see that the sound card driver should assume that there is jack/hpd
available on HDMI/codec unless it is specified in HDMI/codec node
(should not specified in sound card).

>
>
> > As for the 2 headsets case (I guess you mean hp jack and mic jack), on
> > this board we will no

Re: [PATCH v7 2/3] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-09-09 Thread Cheng-yi Chiang
On Wed, Sep 9, 2020 at 5:23 PM Cheng-yi Chiang  wrote:
>
> On Wed, Sep 9, 2020 at 4:34 AM Rob Herring  wrote:
> >
> > On Mon, Sep 07, 2020 at 06:00:38PM +0800, Cheng-Yi Chiang wrote:
> > > Add devicetree bindings documentation file for sc7180 sound card.
> > >
> > > Signed-off-by: Cheng-Yi Chiang 
> > > ---
> > >  .../bindings/sound/qcom,sc7180.yaml   | 143 ++
> > >  1 file changed, 143 insertions(+)
> > >  create mode 100644 
> > > Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> > >
> > > diff --git a/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml 
> > > b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> > > new file mode 100644
> > > index ..ae809346ca80
> > > --- /dev/null
> > > +++ b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> > > @@ -0,0 +1,143 @@
> > > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> > > +%YAML 1.2
> > > +---
> > > +$id: http://devicetree.org/schemas/sound/qcom,sc7180.yaml#
> > > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > > +
> > > +title: Qualcomm Technologies Inc. SC7180 ASoC sound card driver
> > > +
> > > +maintainers:
> > > +  - Rohit kumar 
> > > +  - Cheng-Yi Chiang 
> > > +
> > > +description:
> > > +  This binding describes the SC7180 sound card which uses LPASS for 
> > > audio.
> > > +
> > > +properties:
> > > +  compatible:
> > > +const: qcom,sc7180-sndcard
> > > +
> > > +  audio-routing:
> > > +$ref: /schemas/types.yaml#/definitions/non-unique-string-array
> > > +description:
> > > +  A list of the connections between audio components. Each entry is a
> > > +  pair of strings, the first being the connection's sink, the second
> > > +  being the connection's source.
> > > +
> > > +  model:
> > > +$ref: /schemas/types.yaml#/definitions/string
> > > +description: User specified audio sound card name
> > > +
> > > +  headset-jack:
> > > +$ref: /schemas/types.yaml#/definitions/phandle
> > > +description: phandle of the codec for headset detection
> > > +
> > > +  hdmi-jack:
> > > +$ref: /schemas/types.yaml#/definitions/phandle
> > > +description: phandle of the codec for hdmi jack detection
> >
> > You already have links to these devices. Why duplicate it here?
> >
> > What if you had 2 headsets? This doesn't scale.
> >
> Hi Rob, thanks for reviewing.
> There was some discussion in
> https://patchwork.kernel.org/patch/11737905/#23571643 about how to
> specify the dailink that has a headset jack.
> I would like to pass the information of headset jack and hdmi jack to
> the machine driver so the machine driver can call
> snd_soc_component_set_jack to set jack when init the corresponding link.
> Headset jack and hdmi jack will be treated differently for button and
> event type.
> Because of this, we can not just set a property "jack" in the link.
>
> As for the 2 headsets case (I guess you mean hp jack and mic jack), on
> this board we will not have this use case.
> If someone really wants to build hp jack and mic jack on the board
> based on this machine driver, we can add two more property hp-jack and
> mic-jack to specify that,
> as the machine driver will need to know the different jack types
> anyway. What do you think ?
>
> Or could you please suggest a proper way to pass such information ?
>
> Thanks!
> >
Alternatively we can probably do

dai-link@0 {
link-name = "MultiMedia0";
reg = <0>;
cpu {
sound-dai = <_cpu 0>;
};
headset_jack;
codec {
sound-dai = < 0>;
};
};
dai-link@2 {
link-name = "MultiMedia2";
reg = <2>;
cpu {
sound-dai = <_hdmi 0>;
};
hdmi_jack;
codec {
sound-dai = <_dp>;
};
};

Or even put the flag into codec {}.
Please let me know if you feel this is a better way.
I think it will make the driver code a little more complicated, but
the interface on dts might looks cleaner.
Thanks!

> > Rob


Re: [PATCH v7 2/3] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-09-09 Thread Cheng-yi Chiang
On Wed, Sep 9, 2020 at 4:34 AM Rob Herring  wrote:
>
> On Mon, Sep 07, 2020 at 06:00:38PM +0800, Cheng-Yi Chiang wrote:
> > Add devicetree bindings documentation file for sc7180 sound card.
> >
> > Signed-off-by: Cheng-Yi Chiang 
> > ---
> >  .../bindings/sound/qcom,sc7180.yaml   | 143 ++
> >  1 file changed, 143 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> >
> > diff --git a/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml 
> > b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> > new file mode 100644
> > index ..ae809346ca80
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> > @@ -0,0 +1,143 @@
> > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> > +%YAML 1.2
> > +---
> > +$id: http://devicetree.org/schemas/sound/qcom,sc7180.yaml#
> > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: Qualcomm Technologies Inc. SC7180 ASoC sound card driver
> > +
> > +maintainers:
> > +  - Rohit kumar 
> > +  - Cheng-Yi Chiang 
> > +
> > +description:
> > +  This binding describes the SC7180 sound card which uses LPASS for audio.
> > +
> > +properties:
> > +  compatible:
> > +const: qcom,sc7180-sndcard
> > +
> > +  audio-routing:
> > +$ref: /schemas/types.yaml#/definitions/non-unique-string-array
> > +description:
> > +  A list of the connections between audio components. Each entry is a
> > +  pair of strings, the first being the connection's sink, the second
> > +  being the connection's source.
> > +
> > +  model:
> > +$ref: /schemas/types.yaml#/definitions/string
> > +description: User specified audio sound card name
> > +
> > +  headset-jack:
> > +$ref: /schemas/types.yaml#/definitions/phandle
> > +description: phandle of the codec for headset detection
> > +
> > +  hdmi-jack:
> > +$ref: /schemas/types.yaml#/definitions/phandle
> > +description: phandle of the codec for hdmi jack detection
>
> You already have links to these devices. Why duplicate it here?
>
> What if you had 2 headsets? This doesn't scale.
>
Hi Rob, thanks for reviewing.
There was some discussion in
https://patchwork.kernel.org/patch/11737905/#23571643 about how to
specify the dailink that has a headset jack.
I would like to pass the information of headset jack and hdmi jack to
the machine driver so the machine driver can call
snd_soc_component_set_jack to set jack when init the corresponding link.
Headset jack and hdmi jack will be treated differently for button and
event type.
Because of this, we can not just set a property "jack" in the link.

As for the 2 headsets case (I guess you mean hp jack and mic jack), on
this board we will not have this use case.
If someone really wants to build hp jack and mic jack on the board
based on this machine driver, we can add two more property hp-jack and
mic-jack to specify that,
as the machine driver will need to know the different jack types
anyway. What do you think ?

Or could you please suggest a proper way to pass such information ?

Thanks!
>
> Rob


[PATCH v7 3/3] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-09-07 Thread Cheng-Yi Chiang
From: Ajit Pandey 

Add new driver to register sound card on sc7180 trogdor board and
do the required configuration for lpass cpu dai and external codecs
connected over MI2S interfaces.

Signed-off-by: Ajit Pandey 
Signed-off-by: Cheng-Yi Chiang 
Reviewed-by: Tzung-Bi Shih 
---
 sound/soc/qcom/Kconfig  |  12 ++
 sound/soc/qcom/Makefile |   2 +
 sound/soc/qcom/sc7180.c | 288 
 3 files changed, 302 insertions(+)
 create mode 100644 sound/soc/qcom/sc7180.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index a607ace8b089..0459185ee243 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -116,4 +116,16 @@ config SND_SOC_SDM845
  SDM845 SoC-based systems.
  Say Y if you want to use audio device on this SoCs.
 
+config SND_SOC_SC7180
+   tristate "SoC Machine driver for SC7180 boards"
+   depends on I2C
+   select SND_SOC_QCOM_COMMON
+   select SND_SOC_LPASS_SC7180
+   select SND_SOC_MAX98357A
+   select SND_SOC_RT5682_I2C
+   help
+ To add support for audio on Qualcomm Technologies Inc.
+ SC7180 SoC-based systems.
+ Say Y if you want to use audio device on this SoCs.
+
 endif #SND_SOC_QCOM
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index 7972c9479ab0..0cdcbf367ef1 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -17,12 +17,14 @@ snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
 snd-soc-apq8096-objs := apq8096.o
 snd-soc-sdm845-objs := sdm845.o
+snd-soc-sc7180-objs := sc7180.o
 snd-soc-qcom-common-objs := common.o
 
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
 obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
 obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
+obj-$(CONFIG_SND_SOC_SC7180) += snd-soc-sc7180.o
 obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o
 
 #DSP lib
diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
new file mode 100644
index ..175a2f36842c
--- /dev/null
+++ b/sound/soc/qcom/sc7180.c
@@ -0,0 +1,288 @@
+// SPDX-License-Identifier: GPL-2.0-only
+//
+// Copyright (c) 2020, The Linux Foundation. All rights reserved.
+//
+// sc7180.c -- ALSA SoC Machine driver for SC7180
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../codecs/rt5682.h"
+#include "common.h"
+#include "lpass.h"
+
+#define DEFAULT_SAMPLE_RATE_48K48000
+#define DEFAULT_MCLK_RATE  1920
+#define RT5682_PLL1_FREQ (48000 * 512)
+
+struct sc7180_snd_data {
+   u32 pri_mi2s_clk_count;
+   struct snd_soc_jack hs_jack;
+   struct device_node *hs_jack_of_node;
+   struct snd_soc_jack hdmi_jack;
+   struct device_node *hdmi_jack_of_node;
+};
+
+static void sc7180_jack_free(struct snd_jack *jack)
+{
+   struct snd_soc_component *component = jack->private_data;
+
+   snd_soc_component_set_jack(component, NULL, NULL);
+}
+
+static int sc7180_headset_init(struct snd_soc_pcm_runtime *rtd)
+{
+   struct snd_soc_card *card = rtd->card;
+   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
+   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+   struct snd_soc_component *component = codec_dai->component;
+   struct snd_jack *jack;
+   int rval;
+
+   rval = snd_soc_card_jack_new(
+   card, "Headset Jack",
+   SND_JACK_HEADSET |
+   SND_JACK_HEADPHONE |
+   SND_JACK_BTN_0 | SND_JACK_BTN_1 |
+   SND_JACK_BTN_2 | SND_JACK_BTN_3,
+   >hs_jack, NULL, 0);
+
+   if (rval < 0) {
+   dev_err(card->dev, "Unable to add Headset Jack\n");
+   return rval;
+   }
+
+   jack = pdata->hs_jack.jack;
+
+   snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
+   snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
+   snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
+   snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
+
+   jack->private_data = component;
+   jack->private_free = sc7180_jack_free;
+
+   return snd_soc_component_set_jack(component, >hs_jack, NULL);
+}
+
+static int sc7180_hdmi_init(struct snd_soc_pcm_runtime *rtd)
+{
+   struct snd_soc_card *card = rtd->card;
+   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
+   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+   struct snd_soc_component *component = codec_dai->component;
+   struct snd_jack *jack;
+   int rval;
+
+   rval = snd_soc_card_jack_new(
+   card, "HDMI Jack",
+   SND_JACK_LINEOUT,
+   >

[PATCH v7 0/3] Add documentation and machine driver for SC7180 sound card

2020-09-07 Thread Cheng-Yi Chiang
Note:
- The machine driver patch is made by the collaboration of
  Cheng-Yi Chiang 
  Rohit kumar 
  Ajit Pandey 
  But Ajit has left codeaurora.
- This patch series needs HDMI DAI name defined in sc7180-lpass.h.
  https://patchwork.kernel.org/patch/11745565/

Changes from v1 to v2:
- Ducumentation: Addressed all suggestions from Doug.
- Machine driver:
  - Fix comment style for license.
  - Sort includes.
  - Remove sc7180_snd_hw_params.
  - Remove sc7180_dai_init and use aux device instead for headset jack 
registration.
  - Statically define format for Primary MI2S.
  - Atomic is not a concern because there is mutex in card to make sure
startup and shutdown happen sequentially.
  - Fix missing return -EINVAL in startup.
  - Use static sound card.
  - Use devm_kzalloc to avoid kfree.

Changes from v2 to v3:
- Ducumentation: Addressed suggestions from Srini.
- Machine driver:
  - Reuse qcom_snd_parse_of to parse properties.
  - Remove playback-only and capture-only.
  - Misc fixes to address comments.

Changes from v3 to v4:
- Ducumentation: Addressed suggestions from Rob.
 - Remove definition of dai.
 - Use 'sound-dai: true' for sound-dai schema.
 - Add reg property to pass 'make dt_binding_check' check although reg is not 
used in the driver.
- Machine driver:
 - Add Reviewed-by: Tzung-Bi Shih 

Changes from v4 to v5:
- Documentation: Addressed suggestions from Rob.
 - Add definition for "#address-cells" and "#size-cells".
 - Add additionalProperties: false
 - Add required properties.

Changes from v5 to v6:
- Documentation: Addressed suggestions from Rob.
 - Drop contains in compatible strings.
 - Only allow dai-link@[0-9]
 - Remove reg ref since it has a type definition already.

Changes from v6 to v7
- Documentation:
  - Add headset-jack and hdmi-jack to specify the codec
responsible for jack detection.
- HDMI codec driver:
  - Use component set_jack ops instead of exporting hdmi_codec_set_jack_detect.
- Machine driver:
  - Removed aux device following Stephan's suggestion.
  - Use headset-jack and hdmi-jack to specify the codec
responsible for jack detection.
  - Add support for HDMI(actually DP) playback.

Ajit Pandey (1):
  ASoC: qcom: sc7180: Add machine driver for sound card registration

Cheng-Yi Chiang (2):
  ASoC: hdmi-codec: Use set_jack ops to set jack
  ASoC: qcom: dt-bindings: Add sc7180 machine bindings

 .../bindings/sound/qcom,sc7180.yaml   | 143 +
 include/sound/hdmi-codec.h|   3 -
 sound/soc/codecs/hdmi-codec.c |  12 +-
 sound/soc/mediatek/mt8173/mt8173-rt5650.c |   5 +-
 .../mediatek/mt8183/mt8183-da7219-max98357.c  |   5 +-
 .../mt8183/mt8183-mt6358-ts3a227-max98357.c   |   5 +-
 sound/soc/qcom/Kconfig|  12 +
 sound/soc/qcom/Makefile   |   2 +
 sound/soc/qcom/sc7180.c   | 288 ++
 sound/soc/rockchip/rockchip_max98090.c|   3 +-
 10 files changed, 456 insertions(+), 22 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
 create mode 100644 sound/soc/qcom/sc7180.c

-- 
2.28.0.526.ge36021eeef-goog



[PATCH v7 2/3] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-09-07 Thread Cheng-Yi Chiang
Add devicetree bindings documentation file for sc7180 sound card.

Signed-off-by: Cheng-Yi Chiang 
---
 .../bindings/sound/qcom,sc7180.yaml   | 143 ++
 1 file changed, 143 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml

diff --git a/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml 
b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
new file mode 100644
index ..ae809346ca80
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
@@ -0,0 +1,143 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/qcom,sc7180.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Technologies Inc. SC7180 ASoC sound card driver
+
+maintainers:
+  - Rohit kumar 
+  - Cheng-Yi Chiang 
+
+description:
+  This binding describes the SC7180 sound card which uses LPASS for audio.
+
+properties:
+  compatible:
+const: qcom,sc7180-sndcard
+
+  audio-routing:
+$ref: /schemas/types.yaml#/definitions/non-unique-string-array
+description:
+  A list of the connections between audio components. Each entry is a
+  pair of strings, the first being the connection's sink, the second
+  being the connection's source.
+
+  model:
+$ref: /schemas/types.yaml#/definitions/string
+description: User specified audio sound card name
+
+  headset-jack:
+$ref: /schemas/types.yaml#/definitions/phandle
+description: phandle of the codec for headset detection
+
+  hdmi-jack:
+$ref: /schemas/types.yaml#/definitions/phandle
+description: phandle of the codec for hdmi jack detection
+
+  "#address-cells":
+const: 1
+
+  "#size-cells":
+const: 0
+
+patternProperties:
+  "^dai-link(@[0-9])?$":
+description:
+  Each subnode represents a dai link. Subnodes of each dai links would be
+  cpu/codec dais.
+
+type: object
+
+properties:
+  link-name:
+description: Indicates dai-link name and PCM stream name.
+$ref: /schemas/types.yaml#/definitions/string
+maxItems: 1
+
+  reg:
+description: dai link address.
+
+  cpu:
+description: Holds subnode which indicates cpu dai.
+type: object
+properties:
+  sound-dai: true
+
+  codec:
+description: Holds subnode which indicates codec dai.
+type: object
+properties:
+  sound-dai: true
+
+required:
+  - link-name
+  - cpu
+  - codec
+
+additionalProperties: false
+
+required:
+  - compatible
+  - model
+  - headset-jack
+  - hdmi-jack
+  - "#address-cells"
+  - "#size-cells"
+
+additionalProperties: false
+
+examples:
+
+  - |
+sound {
+compatible = "qcom,sc7180-sndcard";
+model = "sc7180-snd-card";
+
+audio-routing =
+"Headphone Jack", "HPOL",
+"Headphone Jack", "HPOR";
+
+headset-jack = <>;
+hdmi-jack = <_dp>;
+
+#address-cells = <1>;
+#size-cells = <0>;
+
+dai-link@0 {
+link-name = "MultiMedia0";
+reg = <0>;
+cpu {
+sound-dai = <_cpu 0>;
+};
+
+codec {
+sound-dai = < 0>;
+};
+};
+
+dai-link@1 {
+link-name = "MultiMedia1";
+reg = <1>;
+cpu {
+sound-dai = <_cpu 1>;
+};
+
+codec {
+sound-dai = <>;
+};
+};
+
+dai-link@2 {
+link-name = "MultiMedia2";
+reg = <2>;
+cpu {
+sound-dai = <_hdmi 0>;
+};
+
+codec {
+sound-dai = <_dp>;
+};
+};
+};
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v7 1/3] ASoC: hdmi-codec: Use set_jack ops to set jack

2020-09-07 Thread Cheng-Yi Chiang
Use set_jack ops to set jack so machine drivers do not need to include
hdmi-codec.h explicitly.

Signed-off-by: Cheng-Yi Chiang 
---
 include/sound/hdmi-codec.h   |  3 ---
 sound/soc/codecs/hdmi-codec.c| 12 
 sound/soc/mediatek/mt8173/mt8173-rt5650.c|  5 ++---
 sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c   |  5 ++---
 .../mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c |  5 ++---
 sound/soc/rockchip/rockchip_max98090.c   |  3 +--
 6 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/include/sound/hdmi-codec.h b/include/sound/hdmi-codec.h
index 7754631a3102..b55970859a13 100644
--- a/include/sound/hdmi-codec.h
+++ b/include/sound/hdmi-codec.h
@@ -117,9 +117,6 @@ struct hdmi_codec_pdata {
 struct snd_soc_component;
 struct snd_soc_jack;
 
-int hdmi_codec_set_jack_detect(struct snd_soc_component *component,
-  struct snd_soc_jack *jack);
-
 #define HDMI_CODEC_DRV_NAME "hdmi-audio-codec"
 
 #endif /* __HDMI_CODEC_H__ */
diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c
index 8c6f540533ba..d1de5bcd5daa 100644
--- a/sound/soc/codecs/hdmi-codec.c
+++ b/sound/soc/codecs/hdmi-codec.c
@@ -698,13 +698,9 @@ static void plugged_cb(struct device *dev, bool plugged)
hdmi_codec_jack_report(hcp, 0);
 }
 
-/**
- * hdmi_codec_set_jack_detect - register HDMI plugged callback
- * @component: the hdmi-codec instance
- * @jack: ASoC jack to report (dis)connection events on
- */
-int hdmi_codec_set_jack_detect(struct snd_soc_component *component,
-  struct snd_soc_jack *jack)
+static int hdmi_codec_set_jack_detect(struct snd_soc_component *component,
+ struct snd_soc_jack *jack,
+ void *data)
 {
struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component);
int ret = -EOPNOTSUPP;
@@ -720,7 +716,6 @@ int hdmi_codec_set_jack_detect(struct snd_soc_component 
*component,
}
return ret;
 }
-EXPORT_SYMBOL_GPL(hdmi_codec_set_jack_detect);
 
 static int hdmi_dai_spdif_probe(struct snd_soc_dai *dai)
 {
@@ -806,6 +801,7 @@ static const struct snd_soc_component_driver hdmi_driver = {
.use_pmdown_time= 1,
.endianness = 1,
.non_legacy_dai_naming  = 1,
+   .set_jack   = hdmi_codec_set_jack_detect,
 };
 
 static int hdmi_codec_probe(struct platform_device *pdev)
diff --git a/sound/soc/mediatek/mt8173/mt8173-rt5650.c 
b/sound/soc/mediatek/mt8173/mt8173-rt5650.c
index 347b095d478d..c28ebf891cb0 100644
--- a/sound/soc/mediatek/mt8173/mt8173-rt5650.c
+++ b/sound/soc/mediatek/mt8173/mt8173-rt5650.c
@@ -11,7 +11,6 @@
 #include 
 #include 
 #include 
-#include 
 #include "../../codecs/rt5645.h"
 
 #define MCLK_FOR_CODECS12288000
@@ -154,8 +153,8 @@ static int mt8173_rt5650_hdmi_init(struct 
snd_soc_pcm_runtime *rtd)
if (ret)
return ret;
 
-   return hdmi_codec_set_jack_detect(asoc_rtd_to_codec(rtd, 0)->component,
- _rt5650_hdmi_jack);
+   return snd_soc_component_set_jack(asoc_rtd_to_codec(rtd, 0)->component,
+ _rt5650_hdmi_jack, NULL);
 }
 
 enum {
diff --git a/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c 
b/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
index 06d0a4f80fc1..e53c6200d5a7 100644
--- a/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
+++ b/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
@@ -10,7 +10,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -369,8 +368,8 @@ static int mt8183_da7219_max98357_hdmi_init(struct 
snd_soc_pcm_runtime *rtd)
if (ret)
return ret;
 
-   return hdmi_codec_set_jack_detect(asoc_rtd_to_codec(rtd, 0)->component,
- >hdmi_jack);
+   return snd_soc_component_set_jack(asoc_rtd_to_codec(rtd, 0)->component,
+ >hdmi_jack, NULL);
 }
 
 static struct snd_soc_dai_link mt8183_da7219_dai_links[] = {
diff --git a/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c 
b/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
index 07410d7afaa9..327dfad41e31 100644
--- a/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
+++ b/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
@@ -9,7 +9,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -350,8 +349,8 @@ mt8183_mt6358_ts3a227_max98357_hdmi_init(struct 
snd_soc_pcm_runtime *rtd)
if (ret)
return ret;
 
-   return hdmi_codec_set_jack_detect(asoc_rtd_to_codec(rtd, 0)->component,
- >hdmi_jack);
+   return snd_soc_component_s

Re: [PATCH] ASoC: rt5682: Prefer async probe

2020-08-30 Thread Cheng-yi Chiang
On Sat, Aug 29, 2020 at 7:20 AM Douglas Anderson  wrote:
>
> The probe of rt5682 is pretty slow.  A quick measurement shows that it
> takes ~650 ms on at least one board.  There's no reason to block all
> other drivers waiting for this probe to finish.  Set the flag to allow
> other drivers to probe while we're probing.
>
> Signed-off-by: Douglas Anderson 
> ---
> NOTE: I haven't done any analysis of the driver to see _why_ it's so
> slow, only that I have measured it to be slow.  Someone could
> certainly take the time to profile / optimize it, but in any case it
> still won't hurt to be async.


Hi Doug, thank you for the fix.

There are multiple usleep in the probe of rt5682 driver.
The major one is a 300 ms sleep after the regulator turns on.
There are other sleeps for several tens of ms.
>
>
> This is a very safe flag to turn on since:
>
> 1. It's not like our probe order was defined by anything anyway.  When
> we probe is at the whim of when our i2c controller probes and that can
> be any time.
>
> 2. If some other driver needs us then they have to handle the fact
> that we might not have probed yet anyway.


Agree.
soc-core already handled this by returning -EPROBE_DEFER when a
component is not found.
So the machine driver can probe again.
Even in the current behavior, we already see machine driver probe
again when the codec driver is not ready,
so I think adding this async flag will not affect the machine driver.

>
>
> 3. There may be other drivers probing at the same time as us anyway
> because _they_ used async probe.
>
> While I won't say that it's impossible to tickle a bug by turning on
> async probe, I would assert that in almost all cases the bug was
> already there and needed to be fixed anyway.
>
>  sound/soc/codecs/rt5682-i2c.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/sound/soc/codecs/rt5682-i2c.c b/sound/soc/codecs/rt5682-i2c.c
> index 85aba311bdc8..6b4e0eb30c89 100644
> --- a/sound/soc/codecs/rt5682-i2c.c
> +++ b/sound/soc/codecs/rt5682-i2c.c
> @@ -294,6 +294,7 @@ static struct i2c_driver rt5682_i2c_driver = {
> .name = "rt5682",
> .of_match_table = rt5682_of_match,
> .acpi_match_table = rt5682_acpi_match,
> +   .probe_type = PROBE_PREFER_ASYNCHRONOUS,


One thing I am wondering is that there has not been any usage in codec
driver for this.
I think every codec driver can use this, and take the benefit of a
possible faster boot time ?

>
> },
> .probe = rt5682_i2c_probe,
> .shutdown = rt5682_i2c_shutdown,
> --
> 2.28.0.402.g5ffc5be6b7-goog
>


Re: [PATCH v6 2/2] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-08-27 Thread Cheng-yi Chiang
On Wed, Aug 26, 2020 at 10:48 PM Stephan Gerhold  wrote:
>
> On Wed, Aug 26, 2020 at 07:04:54PM +0800, Cheng-Yi Chiang wrote:
> > From: Ajit Pandey 
> >
> > Add new driver to register sound card on sc7180 trogdor board and
> > do the required configuration for lpass cpu dai and external codecs
> > connected over MI2S interfaces.
> >
> > Signed-off-by: Ajit Pandey 
> > Signed-off-by: Cheng-Yi Chiang 
> > Reviewed-by: Tzung-Bi Shih 
> > ---
> >  sound/soc/qcom/Kconfig  |  12 ++
> >  sound/soc/qcom/Makefile |   2 +
> >  sound/soc/qcom/sc7180.c | 244 
> >  3 files changed, 258 insertions(+)
> >  create mode 100644 sound/soc/qcom/sc7180.c
> >
> > diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
> > index a607ace8b089..63678b746299 100644
> > --- a/sound/soc/qcom/Kconfig
> > +++ b/sound/soc/qcom/Kconfig
> > @@ -116,4 +116,16 @@ config SND_SOC_SDM845
> > SDM845 SoC-based systems.
> > Say Y if you want to use audio device on this SoCs.
> >
> > +config SND_SOC_SC7180
> > + tristate "SoC Machine driver for SC7180 boards"
> > + depends on SND_SOC_QCOM
> > + select SND_SOC_QCOM_COMMON
> > + select SND_SOC_LPASS_SC7180
> > + select SND_SOC_MAX98357A
> > + select SND_SOC_RT5682
> > + help
> > +   To add support for audio on Qualcomm Technologies Inc.
> > +   SC7180 SoC-based systems.
> > +   Say Y if you want to use audio device on this SoCs.
> > +
> >  endif #SND_SOC_QCOM
> > diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
> > index 7972c9479ab0..0cdcbf367ef1 100644
> > --- a/sound/soc/qcom/Makefile
> > +++ b/sound/soc/qcom/Makefile
> > @@ -17,12 +17,14 @@ snd-soc-storm-objs := storm.o
> >  snd-soc-apq8016-sbc-objs := apq8016_sbc.o
> >  snd-soc-apq8096-objs := apq8096.o
> >  snd-soc-sdm845-objs := sdm845.o
> > +snd-soc-sc7180-objs := sc7180.o
> >  snd-soc-qcom-common-objs := common.o
> >
> >  obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
> >  obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
> >  obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
> >  obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
> > +obj-$(CONFIG_SND_SOC_SC7180) += snd-soc-sc7180.o
> >  obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o
> >
> >  #DSP lib
> > diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
> > new file mode 100644
> > index ..7849376f63ba
> > --- /dev/null
> > +++ b/sound/soc/qcom/sc7180.c
> > @@ -0,0 +1,244 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +//
> > +// Copyright (c) 2020, The Linux Foundation. All rights reserved.
> > +//
> > +// sc7180.c -- ALSA SoC Machine driver for SC7180
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include "../codecs/rt5682.h"
> > +#include "common.h"
> > +#include "lpass.h"
> > +
> > +#define DEFAULT_SAMPLE_RATE_48K  48000
> > +#define DEFAULT_MCLK_RATE1920
> > +#define RT5682_PLL1_FREQ (48000 * 512)
> > +
> > +struct sc7180_snd_data {
> > + struct snd_soc_jack jack;
> > + u32 pri_mi2s_clk_count;
> > +};
> > +
> > +static void sc7180_jack_free(struct snd_jack *jack)
> > +{
> > + struct snd_soc_component *component = jack->private_data;
> > +
> > + snd_soc_component_set_jack(component, NULL, NULL);
> > +}
> > +
> > +static int sc7180_headset_init(struct snd_soc_component *component)
> > +{
> > + struct snd_soc_card *card = component->card;
> > + struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
> > + struct snd_jack *jack;
> > + int rval;
> > +
> > + rval = snd_soc_card_jack_new(
> > + card, "Headset Jack",
> > + SND_JACK_HEADSET |
> > + SND_JACK_HEADPHONE |
> > + SND_JACK_BTN_0 | SND_JACK_BTN_1 |
> > + SND_JACK_BTN_2 | SND_JACK_BTN_3,
> > + >jack, NULL, 0);
> > +
> > + if (rval < 0) {
> > + dev_err(card->dev, "Unable to add Headset Jack\n");
> > + return rval;
> > + }
> > +
> > +

Re: [PATCH v6 2/2] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-08-26 Thread Cheng-yi Chiang
On Wed, Aug 26, 2020 at 7:05 PM Cheng-Yi Chiang  wrote:
>
> From: Ajit Pandey 
>
> Add new driver to register sound card on sc7180 trogdor board and
> do the required configuration for lpass cpu dai and external codecs
> connected over MI2S interfaces.
>
> Signed-off-by: Ajit Pandey 
> Signed-off-by: Cheng-Yi Chiang 
> Reviewed-by: Tzung-Bi Shih 
> ---
>  sound/soc/qcom/Kconfig  |  12 ++
>  sound/soc/qcom/Makefile |   2 +
>  sound/soc/qcom/sc7180.c | 244 
>  3 files changed, 258 insertions(+)
>  create mode 100644 sound/soc/qcom/sc7180.c
>
> diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
> index a607ace8b089..63678b746299 100644
> --- a/sound/soc/qcom/Kconfig
> +++ b/sound/soc/qcom/Kconfig
> @@ -116,4 +116,16 @@ config SND_SOC_SDM845
>   SDM845 SoC-based systems.
>   Say Y if you want to use audio device on this SoCs.
>
> +config SND_SOC_SC7180
> +   tristate "SoC Machine driver for SC7180 boards"
> +   depends on SND_SOC_QCOM
> +   select SND_SOC_QCOM_COMMON
> +   select SND_SOC_LPASS_SC7180
> +   select SND_SOC_MAX98357A
> +   select SND_SOC_RT5682
> +   help
> + To add support for audio on Qualcomm Technologies Inc.
> + SC7180 SoC-based systems.
> + Say Y if you want to use audio device on this SoCs.
> +
>  endif #SND_SOC_QCOM
> diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
> index 7972c9479ab0..0cdcbf367ef1 100644
> --- a/sound/soc/qcom/Makefile
> +++ b/sound/soc/qcom/Makefile
> @@ -17,12 +17,14 @@ snd-soc-storm-objs := storm.o
>  snd-soc-apq8016-sbc-objs := apq8016_sbc.o
>  snd-soc-apq8096-objs := apq8096.o
>  snd-soc-sdm845-objs := sdm845.o
> +snd-soc-sc7180-objs := sc7180.o
>  snd-soc-qcom-common-objs := common.o
>
>  obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
>  obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
>  obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
>  obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
> +obj-$(CONFIG_SND_SOC_SC7180) += snd-soc-sc7180.o
>  obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o
>
>  #DSP lib
> diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
> new file mode 100644
> index ..7849376f63ba
> --- /dev/null
> +++ b/sound/soc/qcom/sc7180.c
> @@ -0,0 +1,244 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +//
> +// Copyright (c) 2020, The Linux Foundation. All rights reserved.
> +//
> +// sc7180.c -- ALSA SoC Machine driver for SC7180
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "../codecs/rt5682.h"
> +#include "common.h"
> +#include "lpass.h"
> +
> +#define DEFAULT_SAMPLE_RATE_48K48000
> +#define DEFAULT_MCLK_RATE  1920
> +#define RT5682_PLL1_FREQ (48000 * 512)
> +
> +struct sc7180_snd_data {
> +   struct snd_soc_jack jack;
> +   u32 pri_mi2s_clk_count;
> +};
> +
> +static void sc7180_jack_free(struct snd_jack *jack)
> +{
> +   struct snd_soc_component *component = jack->private_data;
> +
> +   snd_soc_component_set_jack(component, NULL, NULL);
> +}
> +
> +static int sc7180_headset_init(struct snd_soc_component *component)
> +{
> +   struct snd_soc_card *card = component->card;
> +   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
> +   struct snd_jack *jack;
> +   int rval;
> +
> +   rval = snd_soc_card_jack_new(
> +   card, "Headset Jack",
> +   SND_JACK_HEADSET |
> +   SND_JACK_HEADPHONE |
> +   SND_JACK_BTN_0 | SND_JACK_BTN_1 |
> +   SND_JACK_BTN_2 | SND_JACK_BTN_3,
> +   >jack, NULL, 0);
> +
> +   if (rval < 0) {
> +   dev_err(card->dev, "Unable to add Headset Jack\n");
> +   return rval;
> +   }
> +
> +   jack = pdata->jack.jack;
> +
> +   snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
> +   snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
> +   snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
> +   snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
> +
> +   jack->private_data = component;
> +   jack->private_free = sc7180_jack_free;
> +
> +   rval = snd_soc_component_set_jack(component,
> + >jack, NULL);
> +   if (rval != 0 && rval != -EOPNOTSUPP) {

[PATCH v6 2/2] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-08-26 Thread Cheng-Yi Chiang
From: Ajit Pandey 

Add new driver to register sound card on sc7180 trogdor board and
do the required configuration for lpass cpu dai and external codecs
connected over MI2S interfaces.

Signed-off-by: Ajit Pandey 
Signed-off-by: Cheng-Yi Chiang 
Reviewed-by: Tzung-Bi Shih 
---
 sound/soc/qcom/Kconfig  |  12 ++
 sound/soc/qcom/Makefile |   2 +
 sound/soc/qcom/sc7180.c | 244 
 3 files changed, 258 insertions(+)
 create mode 100644 sound/soc/qcom/sc7180.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index a607ace8b089..63678b746299 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -116,4 +116,16 @@ config SND_SOC_SDM845
  SDM845 SoC-based systems.
  Say Y if you want to use audio device on this SoCs.
 
+config SND_SOC_SC7180
+   tristate "SoC Machine driver for SC7180 boards"
+   depends on SND_SOC_QCOM
+   select SND_SOC_QCOM_COMMON
+   select SND_SOC_LPASS_SC7180
+   select SND_SOC_MAX98357A
+   select SND_SOC_RT5682
+   help
+ To add support for audio on Qualcomm Technologies Inc.
+ SC7180 SoC-based systems.
+ Say Y if you want to use audio device on this SoCs.
+
 endif #SND_SOC_QCOM
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index 7972c9479ab0..0cdcbf367ef1 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -17,12 +17,14 @@ snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
 snd-soc-apq8096-objs := apq8096.o
 snd-soc-sdm845-objs := sdm845.o
+snd-soc-sc7180-objs := sc7180.o
 snd-soc-qcom-common-objs := common.o
 
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
 obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
 obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
+obj-$(CONFIG_SND_SOC_SC7180) += snd-soc-sc7180.o
 obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o
 
 #DSP lib
diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
new file mode 100644
index ..7849376f63ba
--- /dev/null
+++ b/sound/soc/qcom/sc7180.c
@@ -0,0 +1,244 @@
+// SPDX-License-Identifier: GPL-2.0-only
+//
+// Copyright (c) 2020, The Linux Foundation. All rights reserved.
+//
+// sc7180.c -- ALSA SoC Machine driver for SC7180
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../codecs/rt5682.h"
+#include "common.h"
+#include "lpass.h"
+
+#define DEFAULT_SAMPLE_RATE_48K48000
+#define DEFAULT_MCLK_RATE  1920
+#define RT5682_PLL1_FREQ (48000 * 512)
+
+struct sc7180_snd_data {
+   struct snd_soc_jack jack;
+   u32 pri_mi2s_clk_count;
+};
+
+static void sc7180_jack_free(struct snd_jack *jack)
+{
+   struct snd_soc_component *component = jack->private_data;
+
+   snd_soc_component_set_jack(component, NULL, NULL);
+}
+
+static int sc7180_headset_init(struct snd_soc_component *component)
+{
+   struct snd_soc_card *card = component->card;
+   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
+   struct snd_jack *jack;
+   int rval;
+
+   rval = snd_soc_card_jack_new(
+   card, "Headset Jack",
+   SND_JACK_HEADSET |
+   SND_JACK_HEADPHONE |
+   SND_JACK_BTN_0 | SND_JACK_BTN_1 |
+   SND_JACK_BTN_2 | SND_JACK_BTN_3,
+   >jack, NULL, 0);
+
+   if (rval < 0) {
+   dev_err(card->dev, "Unable to add Headset Jack\n");
+   return rval;
+   }
+
+   jack = pdata->jack.jack;
+
+   snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
+   snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
+   snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
+   snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
+
+   jack->private_data = component;
+   jack->private_free = sc7180_jack_free;
+
+   rval = snd_soc_component_set_jack(component,
+ >jack, NULL);
+   if (rval != 0 && rval != -EOPNOTSUPP) {
+   dev_warn(card->dev, "Failed to set jack: %d\n", rval);
+   return rval;
+   }
+
+   return 0;
+}
+
+static struct snd_soc_aux_dev sc7180_headset_dev = {
+   .dlc = COMP_EMPTY(),
+   .init = sc7180_headset_init,
+};
+
+static int sc7180_snd_startup(struct snd_pcm_substream *substream)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct snd_soc_card *card = rtd->card;
+   struct sc7180_snd_data *data = snd_soc_card_get_drvdata(card);
+   struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
+   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+   int re

[PATCH v6 1/2] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-08-26 Thread Cheng-Yi Chiang
Add devicetree bindings documentation file for sc7180 sound card.

Signed-off-by: Cheng-Yi Chiang 
---
 .../bindings/sound/qcom,sc7180.yaml   | 124 ++
 1 file changed, 124 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml

diff --git a/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml 
b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
new file mode 100644
index ..a85375974a4c
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
@@ -0,0 +1,124 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/qcom,sc7180.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Technologies Inc. SC7180 ASoC sound card driver
+
+maintainers:
+  - Rohit kumar 
+  - Cheng-Yi Chiang 
+
+description:
+  This binding describes the SC7180 sound card which uses LPASS for audio.
+
+properties:
+  compatible:
+const: qcom,sc7180-sndcard
+
+  audio-routing:
+$ref: /schemas/types.yaml#/definitions/non-unique-string-array
+description:
+  A list of the connections between audio components. Each entry is a
+  pair of strings, the first being the connection's sink, the second
+  being the connection's source.
+
+  model:
+$ref: /schemas/types.yaml#/definitions/string
+description: User specified audio sound card name
+
+  aux-dev:
+$ref: /schemas/types.yaml#/definitions/phandle
+description: phandle of the codec for headset detection
+
+  "#address-cells":
+const: 1
+
+  "#size-cells":
+const: 0
+
+patternProperties:
+  "^dai-link(@[0-9])?$":
+description:
+  Each subnode represents a dai link. Subnodes of each dai links would be
+  cpu/codec dais.
+
+type: object
+
+properties:
+  link-name:
+description: Indicates dai-link name and PCM stream name.
+$ref: /schemas/types.yaml#/definitions/string
+maxItems: 1
+
+  reg:
+description: dai link address.
+
+  cpu:
+description: Holds subnode which indicates cpu dai.
+type: object
+properties:
+  sound-dai: true
+
+  codec:
+description: Holds subnode which indicates codec dai.
+type: object
+properties:
+  sound-dai: true
+
+required:
+  - link-name
+  - cpu
+  - codec
+
+additionalProperties: false
+
+required:
+  - compatible
+  - model
+  - "#address-cells"
+  - "#size-cells"
+
+additionalProperties: false
+
+examples:
+
+  - |
+sound {
+compatible = "qcom,sc7180-sndcard";
+model = "sc7180-snd-card";
+
+audio-routing =
+"Headphone Jack", "HPOL",
+"Headphone Jack", "HPOR";
+
+aux-dev = <>;
+
+#address-cells = <1>;
+#size-cells = <0>;
+
+dai-link@0 {
+link-name = "MultiMedia0";
+reg = <0>;
+cpu {
+sound-dai = <_cpu 0>;
+};
+
+codec {
+sound-dai = < 0>;
+};
+};
+
+dai-link@1 {
+link-name = "MultiMedia1";
+reg = <1>;
+cpu {
+sound-dai = <_cpu 1>;
+};
+
+codec {
+sound-dai = <>;
+};
+};
+};
-- 
2.28.0.297.g1956fa8f8d-goog



[PATCH v6 0/2] Add documentation and machine driver for SC7180 sound card

2020-08-26 Thread Cheng-Yi Chiang
Note:
- The machine driver patch is made by the collaboration of
  Cheng-Yi Chiang 
  Rohit kumar 
  Ajit Pandey 
  But Ajit has left codeaurora.

Changes from v1 to v2:
- Ducumentation: Addressed all suggestions from Doug.
- Machine driver:
  - Fix comment style for license.
  - Sort includes.
  - Remove sc7180_snd_hw_params.
  - Remove sc7180_dai_init and use aux device instead for headset jack 
registration.
  - Statically define format for Primary MI2S.
  - Atomic is not a concern because there is mutex in card to make sure
startup and shutdown happen sequentially.
  - Fix missing return -EINVAL in startup.
  - Use static sound card.
  - Use devm_kzalloc to avoid kfree.

Changes from v2 to v3:
- Ducumentation: Addressed suggestions from Srini.
- Machine driver:
  - Reuse qcom_snd_parse_of to parse properties.
  - Remove playback-only and capture-only.
  - Misc fixes to address comments.

Changes from v3 to v4:
- Ducumentation: Addressed suggestions from Rob.
 - Remove definition of dai.
 - Use 'sound-dai: true' for sound-dai schema.
 - Add reg property to pass 'make dt_binding_check' check although reg is not 
used in the driver.
- Machine driver:
 - Add Reviewed-by: Tzung-Bi Shih 

Changes from v4 to v5:
- Documentation: Addressed suggestions from Rob.
 - Add definition for "#address-cells" and "#size-cells".
 - Add additionalProperties: false
 - Add required properties.

Changes from v5 to v6:
- Documentation: Addressed suggestions from Rob.
 - Drop contains in compatible strings.
 - Only allow dai-link@[0-9]
 - Remove reg ref since it has a type definition already.
Ajit Pandey (1):
  ASoC: qcom: sc7180: Add machine driver for sound card registration

Cheng-Yi Chiang (1):
  ASoC: qcom: dt-bindings: Add sc7180 machine bindings

 .../bindings/sound/qcom,sc7180.yaml   | 124 +
 sound/soc/qcom/Kconfig|  12 +
 sound/soc/qcom/Makefile   |   2 +
 sound/soc/qcom/sc7180.c   | 244 ++
 4 files changed, 382 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
 create mode 100644 sound/soc/qcom/sc7180.c

-- 
2.28.0.297.g1956fa8f8d-goog



[PATCH v5 1/2] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-08-17 Thread Cheng-Yi Chiang
Add devicetree bindings documentation file for sc7180 sound card.

Signed-off-by: Cheng-Yi Chiang 
---
 .../bindings/sound/qcom,sc7180.yaml   | 127 ++
 1 file changed, 127 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml

diff --git a/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml 
b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
new file mode 100644
index ..b5cdaa0fe559
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
@@ -0,0 +1,127 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/qcom,sc7180.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Technologies Inc. SC7180 ASoC sound card driver
+
+maintainers:
+  - Rohit kumar 
+  - Cheng-Yi Chiang 
+
+description:
+  This binding describes the SC7180 sound card which uses LPASS for audio.
+
+properties:
+  compatible:
+contains:
+  const: qcom,sc7180-sndcard
+
+  audio-routing:
+$ref: /schemas/types.yaml#/definitions/non-unique-string-array
+description:
+  A list of the connections between audio components. Each entry is a
+  pair of strings, the first being the connection's sink, the second
+  being the connection's source.
+
+  model:
+$ref: /schemas/types.yaml#/definitions/string
+description: User specified audio sound card name
+
+  aux-dev:
+$ref: /schemas/types.yaml#/definitions/phandle
+description: phandle of the codec for headset detection
+
+  "#address-cells":
+const: 1
+
+  "#size-cells":
+const: 0
+
+patternProperties:
+  "^dai-link(@[0-9]+)?$":
+description:
+  Each subnode represents a dai link. Subnodes of each dai links would be
+  cpu/codec dais.
+
+type: object
+
+properties:
+  link-name:
+description: Indicates dai-link name and PCM stream name.
+$ref: /schemas/types.yaml#/definitions/string
+maxItems: 1
+
+  reg:
+description: dai link address.
+$ref: /schemas/types.yaml#/definitions/uint32
+maxItems: 1
+
+  cpu:
+description: Holds subnode which indicates cpu dai.
+type: object
+properties:
+  sound-dai: true
+
+  codec:
+description: Holds subnode which indicates codec dai.
+type: object
+properties:
+  sound-dai: true
+
+required:
+  - link-name
+  - cpu
+  - codec
+
+additionalProperties: false
+
+required:
+  - compatible
+  - model
+  - "#address-cells"
+  - "#size-cells"
+
+additionalProperties: false
+
+examples:
+
+  - |
+sound {
+compatible = "qcom,sc7180-sndcard";
+model = "sc7180-snd-card";
+
+audio-routing =
+"Headphone Jack", "HPOL",
+"Headphone Jack", "HPOR";
+
+aux-dev = <>;
+
+#address-cells = <1>;
+#size-cells = <0>;
+
+dai-link@0 {
+link-name = "MultiMedia0";
+reg = <0>;
+cpu {
+sound-dai = <_cpu 0>;
+};
+
+codec {
+sound-dai = < 0>;
+};
+};
+
+dai-link@1 {
+link-name = "MultiMedia1";
+reg = <1>;
+cpu {
+sound-dai = <_cpu 1>;
+};
+
+codec {
+sound-dai = <>;
+};
+};
+};
-- 
2.28.0.220.ged08abb693-goog



[PATCH v5 2/2] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-08-17 Thread Cheng-Yi Chiang
From: Ajit Pandey 

Add new driver to register sound card on sc7180 trogdor board and
do the required configuration for lpass cpu dai and external codecs
connected over MI2S interfaces.

Signed-off-by: Ajit Pandey 
Signed-off-by: Cheng-Yi Chiang 
Reviewed-by: Tzung-Bi Shih 
---
 sound/soc/qcom/Kconfig  |  12 ++
 sound/soc/qcom/Makefile |   2 +
 sound/soc/qcom/sc7180.c | 244 
 3 files changed, 258 insertions(+)
 create mode 100644 sound/soc/qcom/sc7180.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 5d6b2466a2f2..54aa2ede229c 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -110,3 +110,15 @@ config SND_SOC_SDM845
  To add support for audio on Qualcomm Technologies Inc.
  SDM845 SoC-based systems.
  Say Y if you want to use audio device on this SoCs.
+
+config SND_SOC_SC7180
+   tristate "SoC Machine driver for SC7180 boards"
+   depends on SND_SOC_QCOM
+   select SND_SOC_QCOM_COMMON
+   select SND_SOC_LPASS_SC7180
+   select SND_SOC_MAX98357A
+   select SND_SOC_RT5682
+   help
+To add support for audio on Qualcomm Technologies Inc.
+SC7180 SoC-based systems.
+Say Y if you want to use audio device on this SoCs.
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index 41b2c7a23a4d..3f6275d90526 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -15,12 +15,14 @@ snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
 snd-soc-apq8096-objs := apq8096.o
 snd-soc-sdm845-objs := sdm845.o
+snd-soc-sc7180-objs := sc7180.o
 snd-soc-qcom-common-objs := common.o
 
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
 obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
 obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
+obj-$(CONFIG_SND_SOC_SC7180) += snd-soc-sc7180.o
 obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o
 
 #DSP lib
diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
new file mode 100644
index ..7849376f63ba
--- /dev/null
+++ b/sound/soc/qcom/sc7180.c
@@ -0,0 +1,244 @@
+// SPDX-License-Identifier: GPL-2.0-only
+//
+// Copyright (c) 2020, The Linux Foundation. All rights reserved.
+//
+// sc7180.c -- ALSA SoC Machine driver for SC7180
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../codecs/rt5682.h"
+#include "common.h"
+#include "lpass.h"
+
+#define DEFAULT_SAMPLE_RATE_48K48000
+#define DEFAULT_MCLK_RATE  1920
+#define RT5682_PLL1_FREQ (48000 * 512)
+
+struct sc7180_snd_data {
+   struct snd_soc_jack jack;
+   u32 pri_mi2s_clk_count;
+};
+
+static void sc7180_jack_free(struct snd_jack *jack)
+{
+   struct snd_soc_component *component = jack->private_data;
+
+   snd_soc_component_set_jack(component, NULL, NULL);
+}
+
+static int sc7180_headset_init(struct snd_soc_component *component)
+{
+   struct snd_soc_card *card = component->card;
+   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
+   struct snd_jack *jack;
+   int rval;
+
+   rval = snd_soc_card_jack_new(
+   card, "Headset Jack",
+   SND_JACK_HEADSET |
+   SND_JACK_HEADPHONE |
+   SND_JACK_BTN_0 | SND_JACK_BTN_1 |
+   SND_JACK_BTN_2 | SND_JACK_BTN_3,
+   >jack, NULL, 0);
+
+   if (rval < 0) {
+   dev_err(card->dev, "Unable to add Headset Jack\n");
+   return rval;
+   }
+
+   jack = pdata->jack.jack;
+
+   snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
+   snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
+   snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
+   snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
+
+   jack->private_data = component;
+   jack->private_free = sc7180_jack_free;
+
+   rval = snd_soc_component_set_jack(component,
+ >jack, NULL);
+   if (rval != 0 && rval != -EOPNOTSUPP) {
+   dev_warn(card->dev, "Failed to set jack: %d\n", rval);
+   return rval;
+   }
+
+   return 0;
+}
+
+static struct snd_soc_aux_dev sc7180_headset_dev = {
+   .dlc = COMP_EMPTY(),
+   .init = sc7180_headset_init,
+};
+
+static int sc7180_snd_startup(struct snd_pcm_substream *substream)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct snd_soc_card *card = rtd->card;
+   struct sc7180_snd_data *data = snd_soc_card_get_drvdata(card);
+   struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
+   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+   i

[PATCH v5 0/2] Add documentation and machine driver for SC7180 sound card

2020-08-17 Thread Cheng-Yi Chiang
Note:
- The machine driver patch depends on LPASS patch series so it is not ready to 
be merged now.
  ASoC: qcom: Add support for SC7180 lpass variant 
https://patchwork.kernel.org/cover/11714317/
- The machine driver patch is made by the collaboration of
  Cheng-Yi Chiang 
  Rohit kumar 
  Ajit Pandey 
  But Ajit has left codeaurora.

Changes from v1 to v2:
- Ducumentation: Addressed all suggestions from Doug.
- Machine driver:
  - Fix comment style for license.
  - Sort includes.
  - Remove sc7180_snd_hw_params.
  - Remove sc7180_dai_init and use aux device instead for headset jack 
registration.
  - Statically define format for Primary MI2S.
  - Atomic is not a concern because there is mutex in card to make sure
startup and shutdown happen sequentially.
  - Fix missing return -EINVAL in startup.
  - Use static sound card.
  - Use devm_kzalloc to avoid kfree.

Changes from v2 to v3:
- Ducumentation: Addressed suggestions from Srini.
- Machine driver:
  - Reuse qcom_snd_parse_of to parse properties.
  - Remove playback-only and capture-only.
  - Misc fixes to address comments.

Changes from v3 to v4:
- Ducumentation: Addressed suggestions from Rob.
 - Remove definition of dai.
 - Use 'sound-dai: true' for sound-dai schema.
 - Add reg property to pass 'make dt_binding_check' check although reg is not 
used in the driver.
- Machine driver:
 - Add Reviewed-by: Tzung-Bi Shih 

 Changes from v4 to v5:
- Documentation: Addressed suggestions from Rob.
 - Add definition for "#address-cells" and "#size-cells".
 - Add additionalProperties: false
 - Add required properties.

Ajit Pandey (1):
  ASoC: qcom: sc7180: Add machine driver for sound card registration

Cheng-Yi Chiang (1):
  ASoC: qcom: dt-bindings: Add sc7180 machine bindings

 .../bindings/sound/qcom,sc7180.yaml   | 127 +
 sound/soc/qcom/Kconfig|  12 +
 sound/soc/qcom/Makefile   |   2 +
 sound/soc/qcom/sc7180.c   | 244 ++
 4 files changed, 385 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
 create mode 100644 sound/soc/qcom/sc7180.c

-- 
2.28.0.220.ged08abb693-goog



Re: [PATCH v3 1/2] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-08-03 Thread Cheng-yi Chiang
On Sat, Aug 1, 2020 at 2:32 AM Rob Herring  wrote:
>
> On Fri, Jul 31, 2020 at 04:40:22PM +0800, Cheng-Yi Chiang wrote:
> > Add devicetree bindings documentation file for sc7180 sound card.
> >
> > Signed-off-by: Cheng-Yi Chiang 
> > ---
> >  .../bindings/sound/qcom,sc7180.yaml   | 113 ++
> >  1 file changed, 113 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> >
> > diff --git a/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml 
> > b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> > new file mode 100644
> > index ..ce8a5a2d9df9
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> > @@ -0,0 +1,113 @@
> > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> > +%YAML 1.2
> > +---
> > +$id: http://devicetree.org/schemas/sound/qcom,sc7180.yaml#
> > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: Qualcomm Technologies Inc. SC7180 ASoC sound card driver
> > +
> > +maintainers:
> > +  - Rohit kumar 
> > +  - Cheng-Yi Chiang 
> > +
> > +description:
> > +  This binding describes the SC7180 sound card which uses LPASS for audio.
> > +
> > +definitions:
>
> Please don't use 'definitions'. Either just duplicate it or you can do
> 'patternProperties'.
>
Removed dai definition in v4.
> > +
> > +  dai:
> > +type: object
> > +properties:
> > +  sound-dai:
> > +maxItems: 1
> > +$ref: /schemas/types.yaml#/definitions/phandle-array
> > +description: phandle array of the codec or CPU DAI
>
> This is a common property. You can assume we have a common schema
> definition for it. IOW, 'sound-dai: true' is enough as it's always a
> single phandle+args.
>
In the examples I found,
Documentation/devicetree/bindings/sound/amlogic,gx-sound-card.yaml,
Documentation/devicetree/bindings/sound/samsung,midas-audio.yaml
use:

  sound-dai:
$ref: /schemas/types.yaml#/definitions/phandle
description: phandle of the CPU DAI

Documentation/devicetree/bindings/sound/simple-card.yaml
just use

  sound-dai:
maxItems: 1

In v4, I used 'sound-dai: true' as suggested.

But I am a bit confused about assuming there is a common schema
definition for it.
I checked the code at https://github.com/devicetree-org/dt-schema but
did not found the definition for it.
Did I miss something here ?

Thanks for the help!

> > +
> > +required:
> > +  - sound-dai
> > +
> > +properties:
> > +  compatible:
> > +contains:
> > +  const: qcom,sc7180-sndcard
> > +
> > +  audio-routing:
> > +$ref: /schemas/types.yaml#/definitions/non-unique-string-array
> > +description:
> > +  A list of the connections between audio components. Each entry is a
> > +  pair of strings, the first being the connection's sink, the second
> > +  being the connection's source.
> > +
> > +  model:
> > +$ref: /schemas/types.yaml#/definitions/string
> > +description: User specified audio sound card name
> > +
> > +  aux-dev:
> > +$ref: /schemas/types.yaml#/definitions/phandle
> > +description: phandle of the codec for headset detection
> > +
> > +patternProperties:
> > +  "^dai-link(@[0-9]+)?$":
> > +description:
> > +  Each subnode represents a dai link. Subnodes of each dai links would 
> > be
> > +  cpu/codec dais.
> > +
> > +type: object
> > +
> > +properties:
> > +  link-name:
> > +description: Indicates dai-link name and PCM stream name.
> > +$ref: /schemas/types.yaml#/definitions/string
> > +maxItems: 1
> > +
> > +  cpu:
> > +$ref: "#/definitions/dai"
> > +
> > +  codec:
> > +$ref: "#/definitions/dai"
> > +
> > +required:
> > +  - link-name
> > +  - cpu
> > +  - codec
> > +
> > +additionalProperties: false
> > +
> > +examples:
> > +
> > +  - |
> > +sound {
> > +compatible = "qcom,sc7180-sndcard";
> > +model = "sc7180-snd-card";
> > +
> > +audio-routing =
> > +"Headphone Jack", "HPOL",
> > +"Headphone Jack", "HPOR";
> > +
> > +aux-dev = <>;
> > +
> > +#address-cells = <1>;
> > +#size-cells = <0>;
> > +
> > +dai-link@0 {
> > +link-name = "MultiMedia0";
> > +cpu {
> > +sound-dai = <_cpu 0>;
> > +};
> > +
> > +codec {
> > +sound-dai = < 0>;
> > +};
> > +};
> > +
> > +dai-link@1 {
> > +link-name = "MultiMedia1";
> > +cpu {
> > +sound-dai = <_cpu 1>;
> > +};
> > +
> > +codec {
> > +sound-dai = <>;
> > +};
> > +};
> > +};
> > --
> > 2.28.0.163.g6104cc2f0b6-goog
> >


Re: [PATCH v3 1/2] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-08-03 Thread Cheng-yi Chiang
On Sat, Aug 1, 2020 at 2:27 AM Rob Herring  wrote:
>
> On Fri, 31 Jul 2020 16:40:22 +0800, Cheng-Yi Chiang wrote:
> > Add devicetree bindings documentation file for sc7180 sound card.
> >
> > Signed-off-by: Cheng-Yi Chiang 
> > ---
> >  .../bindings/sound/qcom,sc7180.yaml   | 113 ++
> >  1 file changed, 113 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> >
>
>
> My bot found errors running 'make dt_binding_check' on your patch:
>
> Documentation/devicetree/bindings/sound/qcom,sc7180.example.dts:32.24-41.15: 
> Warning (unit_address_vs_reg): /example-0/sound/dai-link@0: node has a unit 
> name, but no reg or ranges property
> Documentation/devicetree/bindings/sound/qcom,sc7180.example.dts:43.24-52.15: 
> Warning (unit_address_vs_reg): /example-0/sound/dai-link@1: node has a unit 
> name, but no reg or ranges property
>
>
> See https://patchwork.ozlabs.org/patch/1339316
>
> If you already ran 'make dt_binding_check' and didn't see the above
> error(s), then make sure dt-schema is up to date:
>
> pip3 install git+https://github.com/devicetree-org/dt-schema.git@master 
> --upgrade
>
> Please check and re-submit.
>
I have passed this in v2 patch, but removed reg in v3 patch since it
is not used.
In v4, I have added back reg = <0> and reg = <1> into the example, and
reg property into schema to fix this error.
Since reg property is not used in the driver, I am not sure whether I
should add it in the schema.
Please let me know which is preferred. Thanks!


[PATCH v4 0/2] Add documentation and machine driver for SC7180 sound card

2020-08-02 Thread Cheng-Yi Chiang
Note:
- The machine driver patch depends on LPASS patch series so it is not ready to 
be merged now.
  ASoC: qcom: Add support for SC7180 lpass variant 
https://patchwork.kernel.org/cover/11678133/
- The machine driver patch is made by the collaboration of
  Cheng-Yi Chiang 
  Rohit kumar 
  Ajit Pandey 
  But Ajit has left codeaurora.

Changes from v1 to v2:
- Ducumentation: Addressed all suggestions from Doug.
- Machine driver:
  - Fix comment style for license.
  - Sort includes.
  - Remove sc7180_snd_hw_params.
  - Remove sc7180_dai_init and use aux device instead for headset jack 
registration.
  - Statically define format for Primary MI2S.
  - Atomic is not a concern because there is mutex in card to make sure
startup and shutdown happen sequentially.
  - Fix missing return -EINVAL in startup.
  - Use static sound card.
  - Use devm_kzalloc to avoid kfree.

Changes from v2 to v3:
- Ducumentation: Addressed suggestions from Srini.
- Machine driver:
  - Reuse qcom_snd_parse_of to parse properties.
  - Remove playback-only and capture-only.
  - Misc fixes to address comments.

Changes from v3 to v4:
- Ducumentation: Addressed suggestions from Rob.
 - Remove definition of dai.
 - Use 'sound-dai: true' for sound-dai schema.
 - Add reg property to pass 'make dt_binding_check' check although reg is not 
used in the driver.
- Machine driver:
 - Add Reviewed-by: Tzung-Bi Shih 

Ajit Pandey (1):
  ASoC: qcom: sc7180: Add machine driver for sound card registration

Cheng-Yi Chiang (1):
  ASoC: qcom: dt-bindings: Add sc7180 machine bindings

 .../bindings/sound/qcom,sc7180.yaml   | 113 
 sound/soc/qcom/Kconfig|  12 +
 sound/soc/qcom/Makefile   |   2 +
 sound/soc/qcom/sc7180.c   | 244 ++
 4 files changed, 371 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
 create mode 100644 sound/soc/qcom/sc7180.c

-- 
2.28.0.163.g6104cc2f0b6-goog



[PATCH v4 2/2] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-08-02 Thread Cheng-Yi Chiang
From: Ajit Pandey 

Add new driver to register sound card on sc7180 trogdor board and
do the required configuration for lpass cpu dai and external codecs
connected over MI2S interfaces.

Signed-off-by: Ajit Pandey 
Signed-off-by: Cheng-Yi Chiang 
Reviewed-by: Tzung-Bi Shih 
---
 sound/soc/qcom/Kconfig  |  12 ++
 sound/soc/qcom/Makefile |   2 +
 sound/soc/qcom/sc7180.c | 244 
 3 files changed, 258 insertions(+)
 create mode 100644 sound/soc/qcom/sc7180.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 5d6b2466a2f2..54aa2ede229c 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -110,3 +110,15 @@ config SND_SOC_SDM845
  To add support for audio on Qualcomm Technologies Inc.
  SDM845 SoC-based systems.
  Say Y if you want to use audio device on this SoCs.
+
+config SND_SOC_SC7180
+   tristate "SoC Machine driver for SC7180 boards"
+   depends on SND_SOC_QCOM
+   select SND_SOC_QCOM_COMMON
+   select SND_SOC_LPASS_SC7180
+   select SND_SOC_MAX98357A
+   select SND_SOC_RT5682
+   help
+To add support for audio on Qualcomm Technologies Inc.
+SC7180 SoC-based systems.
+Say Y if you want to use audio device on this SoCs.
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index 41b2c7a23a4d..3f6275d90526 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -15,12 +15,14 @@ snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
 snd-soc-apq8096-objs := apq8096.o
 snd-soc-sdm845-objs := sdm845.o
+snd-soc-sc7180-objs := sc7180.o
 snd-soc-qcom-common-objs := common.o
 
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
 obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
 obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
+obj-$(CONFIG_SND_SOC_SC7180) += snd-soc-sc7180.o
 obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o
 
 #DSP lib
diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
new file mode 100644
index ..7849376f63ba
--- /dev/null
+++ b/sound/soc/qcom/sc7180.c
@@ -0,0 +1,244 @@
+// SPDX-License-Identifier: GPL-2.0-only
+//
+// Copyright (c) 2020, The Linux Foundation. All rights reserved.
+//
+// sc7180.c -- ALSA SoC Machine driver for SC7180
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../codecs/rt5682.h"
+#include "common.h"
+#include "lpass.h"
+
+#define DEFAULT_SAMPLE_RATE_48K48000
+#define DEFAULT_MCLK_RATE  1920
+#define RT5682_PLL1_FREQ (48000 * 512)
+
+struct sc7180_snd_data {
+   struct snd_soc_jack jack;
+   u32 pri_mi2s_clk_count;
+};
+
+static void sc7180_jack_free(struct snd_jack *jack)
+{
+   struct snd_soc_component *component = jack->private_data;
+
+   snd_soc_component_set_jack(component, NULL, NULL);
+}
+
+static int sc7180_headset_init(struct snd_soc_component *component)
+{
+   struct snd_soc_card *card = component->card;
+   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
+   struct snd_jack *jack;
+   int rval;
+
+   rval = snd_soc_card_jack_new(
+   card, "Headset Jack",
+   SND_JACK_HEADSET |
+   SND_JACK_HEADPHONE |
+   SND_JACK_BTN_0 | SND_JACK_BTN_1 |
+   SND_JACK_BTN_2 | SND_JACK_BTN_3,
+   >jack, NULL, 0);
+
+   if (rval < 0) {
+   dev_err(card->dev, "Unable to add Headset Jack\n");
+   return rval;
+   }
+
+   jack = pdata->jack.jack;
+
+   snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
+   snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
+   snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
+   snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
+
+   jack->private_data = component;
+   jack->private_free = sc7180_jack_free;
+
+   rval = snd_soc_component_set_jack(component,
+ >jack, NULL);
+   if (rval != 0 && rval != -EOPNOTSUPP) {
+   dev_warn(card->dev, "Failed to set jack: %d\n", rval);
+   return rval;
+   }
+
+   return 0;
+}
+
+static struct snd_soc_aux_dev sc7180_headset_dev = {
+   .dlc = COMP_EMPTY(),
+   .init = sc7180_headset_init,
+};
+
+static int sc7180_snd_startup(struct snd_pcm_substream *substream)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct snd_soc_card *card = rtd->card;
+   struct sc7180_snd_data *data = snd_soc_card_get_drvdata(card);
+   struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
+   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+   i

[PATCH v4 1/2] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-08-02 Thread Cheng-Yi Chiang
Add devicetree bindings documentation file for sc7180 sound card.

Signed-off-by: Cheng-Yi Chiang 
---
 .../bindings/sound/qcom,sc7180.yaml   | 113 ++
 1 file changed, 113 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml

diff --git a/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml 
b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
new file mode 100644
index ..c74f0fe9fb3b
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
@@ -0,0 +1,113 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/qcom,sc7180.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Technologies Inc. SC7180 ASoC sound card driver
+
+maintainers:
+  - Rohit kumar 
+  - Cheng-Yi Chiang 
+
+description:
+  This binding describes the SC7180 sound card which uses LPASS for audio.
+
+properties:
+  compatible:
+contains:
+  const: qcom,sc7180-sndcard
+
+  audio-routing:
+$ref: /schemas/types.yaml#/definitions/non-unique-string-array
+description:
+  A list of the connections between audio components. Each entry is a
+  pair of strings, the first being the connection's sink, the second
+  being the connection's source.
+
+  model:
+$ref: /schemas/types.yaml#/definitions/string
+description: User specified audio sound card name
+
+  aux-dev:
+$ref: /schemas/types.yaml#/definitions/phandle
+description: phandle of the codec for headset detection
+
+patternProperties:
+  "^dai-link(@[0-9]+)?$":
+description:
+  Each subnode represents a dai link. Subnodes of each dai links would be
+  cpu/codec dais.
+
+type: object
+
+properties:
+  link-name:
+description: Indicates dai-link name and PCM stream name.
+$ref: /schemas/types.yaml#/definitions/string
+maxItems: 1
+
+  reg:
+description: dai link address.
+$ref: /schemas/types.yaml#/definitions/uint32
+maxItems: 1
+
+  cpu:
+description: Holds subnode which indicates cpu dai.
+type: object
+properties:
+  sound-dai: true
+
+  codec:
+description: Holds subnode which indicates codec dai.
+type: object
+properties:
+  sound-dai: true
+
+required:
+  - link-name
+  - cpu
+  - codec
+
+additionalProperties: false
+
+examples:
+
+  - |
+sound {
+compatible = "qcom,sc7180-sndcard";
+model = "sc7180-snd-card";
+
+audio-routing =
+"Headphone Jack", "HPOL",
+"Headphone Jack", "HPOR";
+
+aux-dev = <>;
+
+#address-cells = <1>;
+#size-cells = <0>;
+
+dai-link@0 {
+link-name = "MultiMedia0";
+reg = <0>;
+cpu {
+sound-dai = <_cpu 0>;
+};
+
+codec {
+sound-dai = < 0>;
+};
+};
+
+dai-link@1 {
+link-name = "MultiMedia1";
+reg = <1>;
+cpu {
+sound-dai = <_cpu 1>;
+};
+
+codec {
+sound-dai = <>;
+};
+};
+};
-- 
2.28.0.163.g6104cc2f0b6-goog



Re: [PATCH v2 2/2] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-07-31 Thread Cheng-yi Chiang
On Fri, Jul 24, 2020 at 2:45 AM Stephan Gerhold  wrote:
>
> On Wed, Jul 22, 2020 at 10:25:14AM +0100, Srinivas Kandagatla wrote:
> > > +static int sc7180_parse_of(struct snd_soc_card *card)
> > > +{
> >
> > This code is getting duplicated in various places like apq8016_sbc_parse_of,
> > it will be nice to common this up, if possible!
> >
>
> FYI, I started work on making apq8016_sbc use qcom_snd_parse_of()
> a while ago already, but didn't find the time to finish it up.
> I have now sent it, this should make it possible to use the common
> qcom_snd_parse_of() function in this driver as well.
>
> See: 
> https://lore.kernel.org/alsa-devel/20200723183904.321040-1-step...@gerhold.net/
>
> Stephan
>
Hi Stephan, thanks a lot for jumping on this to help.
It indeed makes this new driver much cleaner.
I have tested with your patches and it works great.


Re: [PATCH v2 2/2] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-07-31 Thread Cheng-yi Chiang
On Wed, Jul 22, 2020 at 5:25 PM Srinivas Kandagatla
 wrote:
>
> Few comments apart from Tzung-Bi comments,
>
Thanks a lot for reviewing the patch!

> On 21/07/2020 11:44, Cheng-Yi Chiang wrote:
> > From: Ajit Pandey 
> >
> > Add new driver to register sound card on sc7180 trogdor board and
> > do the required configuration for lpass cpu dai and external codecs
> > connected over MI2S interfaces.
> >
> > Signed-off-by: Cheng-Yi Chiang 
> > ---
> >   sound/soc/qcom/Kconfig  |  11 ++
> >   sound/soc/qcom/Makefile |   2 +
> >   sound/soc/qcom/sc7180.c | 380 
> >   3 files changed, 393 insertions(+)
> >   create mode 100644 sound/soc/qcom/sc7180.c
> >
>
> > diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
> > new file mode 100644
> > index ..3beb2b129d01
> > --- /dev/null
> > +++ b/sound/soc/qcom/sc7180.c
> > @@ -0,0 +1,380 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +//
> > +//Copyright (c) 2020, The Linux Foundation. All rights reserved.
> > +//
> > +//sc7180.c -- ALSA SoC Machine driver for SC7180
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include "../codecs/rt5682.h"
> > +#include "common.h"
>
> What is that you are using from this header?
>
It is not used in v2, but will be used in v3.

> > +#include "lpass.h"
> > +
> > +#define DEFAULT_SAMPLE_RATE_48K  48000
> > +#define DEFAULT_MCLK_RATE1920
> > +#define RT5682_PLL1_FREQ (48000 * 512)
> > +
> > +static int sc7180_headset_init(struct snd_soc_component *component);
> > +
> > +static struct snd_soc_aux_dev sc7180_headset_dev = {
> > + .dlc = COMP_EMPTY(),
> > + .init = sc7180_headset_init,
> > +};
>
> Can you explain why can you not use snd_soc_component_set_jack() on the
> codec component from link->init() callback?
>
I am using snd_soc_component_set_jack, but only on aux device.
As Tzungbi suggested in his comment on v1 machine driver patch, the
current approach in other qcom driver like sdm845.c and apq8016_sbc.c
of setting jack is not clean.
For example, in sdm845.c, a bool jack_etup is needed in
sdm845_snd_data so that jack will be created once.
Also, the machine driver assumes that snd_soc_component_set_jack is
used when cpu_dai->id == PRIMARY_MI2S_RX, which is not easy to
understand.
In apq8016_sbc.c, apq8016_sbc_dai_init tries to set jack on every
codec_dai which does not make sense.
These downsides can be avoided by using aux-dev so that the logic of
setting jack is easy to understand, and dai_init function can be much
cleaner.
> > +
> > +struct sc7180_snd_data {
> > + struct snd_soc_jack jack;
> > + struct snd_soc_card *card;
> > + u32 pri_mi2s_clk_count;
> > +};
> > +
> > +static void sc7180_jack_free(struct snd_jack *jack)
> > +{
> > + struct snd_soc_component *component = jack->private_data;
> > +
> > + snd_soc_component_set_jack(component, NULL, NULL);
> > +}
> > +
> > +static int sc7180_headset_init(struct snd_soc_component *component)
> > +{
> > + struct snd_soc_card *card = component->card;
> > + struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
> > + struct snd_jack *jack;
> > + int rval;
> > +
> > + rval = snd_soc_card_jack_new(
> > + card, "Headset Jack",
> > + SND_JACK_HEADSET |
> > + SND_JACK_HEADPHONE |
> > + SND_JACK_BTN_0 | SND_JACK_BTN_1 |
> > + SND_JACK_BTN_2 | SND_JACK_BTN_3,
> > + >jack, NULL, 0);
> > +
> > + if (rval < 0) {
> > + dev_err(card->dev, "Unable to add Headset Jack\n");
> > + return rval;
> > + }
> > +
> > + jack = pdata->jack.jack;
> > +
> > + snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
> > + snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
> > + snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
> > + snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
> > +
> > + jack->private_data = component;
> > + jack->private_free = sc7180_jack_free;
> > +
> > + rval = snd_soc_component_set_jack(component,
> > +  

Re: [PATCH v2 2/2] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-07-31 Thread Cheng-yi Chiang
On Wed, Jul 22, 2020 at 11:15 AM Tzung-Bi Shih  wrote:
>
> On Tue, Jul 21, 2020 at 6:44 PM Cheng-Yi Chiang  wrote:
> > diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
> > new file mode 100644
> > index ..3beb2b129d01
> > --- /dev/null
> > +++ b/sound/soc/qcom/sc7180.c
> > @@ -0,0 +1,380 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +//
> > +//Copyright (c) 2020, The Linux Foundation. All rights reserved.
> > +//
> > +//sc7180.c -- ALSA SoC Machine driver for SC7180
> Insert an extra space between // and text to make it look better.
>
Fixed in v3.
> > +static int sc7180_headset_init(struct snd_soc_component *component);
> > +
> > +static struct snd_soc_aux_dev sc7180_headset_dev = {
> > +   .dlc = COMP_EMPTY(),
> > +   .init = sc7180_headset_init,
> > +};
> Move definition of sc7180_headset_dev after sc7180_headset_init( ) so
> that you don't need forward declaration of sc7180_headset_init( ).
>
Fixed in v3.
> > +static unsigned int primary_dai_fmt = SND_SOC_DAIFMT_CBS_CFS |
> > + SND_SOC_DAIFMT_NB_NF |
> > + SND_SOC_DAIFMT_I2S;
> > +
> > +static int sc7180_snd_startup(struct snd_pcm_substream *substream)
> > +{
> > +   struct snd_soc_pcm_runtime *rtd = substream->private_data;
> > +   struct snd_soc_card *card = rtd->card;
> > +   struct sc7180_snd_data *data = snd_soc_card_get_drvdata(card);
> > +   struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
> > +   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
> > +   int ret;
> > +
> > +   switch (cpu_dai->id) {
> > +   case MI2S_PRIMARY:
> > +   if (++data->pri_mi2s_clk_count == 1) {
> > +   snd_soc_dai_set_sysclk(cpu_dai,
> > +  LPASS_MCLK0,
> > +  DEFAULT_MCLK_RATE,
> > +  SNDRV_PCM_STREAM_PLAYBACK);
> > +   }
> > +   snd_soc_dai_set_fmt(codec_dai, primary_dai_fmt);
> My comment on the previous thread may mislead.  My original intent:
> move the DAIFMT setting to DAI link->dai_fmt in sc7180_parse_of( ).
>
> If you need to keep it as is: inline the SND_SOC_DAIFMT_* into
> snd_soc_dai_set_fmt( ) (i.e. eliminate primary_dai_fmt).
>
Fixed in v3. Since in v3 I am reusing parse function in common.c, I
will keep the format setting in startup.

> > +static int sc7180_parse_of(struct snd_soc_card *card)
> > +{
> > +   struct device_node *np;
> > +   struct device_node *codec = NULL;
> > +   struct device_node *platform = NULL;
> The function doesn't use platform.
>

sc7180_parse_of is removed in v3.

> > +   struct device_node *cpu = NULL;
> > +   struct device *dev = card->dev;
> > +   struct snd_soc_dai_link *link;
> > +   struct of_phandle_args args;
> > +   struct snd_soc_dai_link_component *dlc;
> > +   int ret, num_links;
> > +
> > +   ret = snd_soc_of_parse_card_name(card, "model");
> > +   if (ret) {
> > +   dev_err(dev, "Error parsing card name: %d\n", ret);
> > +   return ret;
> > +   }
> > +
> > +   /* DAPM routes */
> > +   if (of_property_read_bool(dev->of_node, "audio-routing")) {
> > +   ret = snd_soc_of_parse_audio_routing(card,
> > +"audio-routing");
> > +   if (ret)
> > +   return ret;
> > +   }
> > +
> > +   /* headset aux dev. */
> > +   sc7180_headset_dev.dlc.of_node = of_parse_phandle(
> > +   dev->of_node, "aux-dev", 0);
> > +   if (!sc7180_headset_dev.dlc.of_node) {
> > +   dev_err(dev,
> > +   "Property 'aux-dev' missing/invalid\n");
> > +   return -EINVAL;
> > +   }
> > +
> > +   /* Populate links */
> > +   num_links = of_get_child_count(dev->of_node);
> Eliminate num_links but use card->num_links directly.
>
> > +
> > +   /* Allocate the DAI link array */
> > +   card->dai_link = devm_kcalloc(dev, num_links, sizeof(*link),
> > + GFP_KERNEL);
> > +   if (!card->dai_link)
> > +   return -ENOMEM;
> > +
> > +   card->num_links = 

Re: [PATCH v2 1/2] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-07-31 Thread Cheng-yi Chiang
On Wed, Jul 22, 2020 at 5:25 PM Srinivas Kandagatla
 wrote:
>
>
>
> On 21/07/2020 11:44, Cheng-Yi Chiang wrote:
> > Add devicetree bindings documentation file for sc7180 sound card.
> >
> > Signed-off-by: Cheng-Yi Chiang 
> > ---
> >   .../bindings/sound/qcom,sc7180.yaml   | 130 ++
> >   1 file changed, 130 insertions(+)
> >   create mode 100644 
> > Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> >
> > diff --git a/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml 
> > b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> > new file mode 100644
> > index ..82f9483276eb
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> > @@ -0,0 +1,130 @@
> > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> > +%YAML 1.2
> > +---
> > +$id: http://devicetree.org/schemas/sound/qcom,sc7180.yaml#
> > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: Qualcomm Technologies Inc. SC7180 ASoC sound card driver
> > +
> > +maintainers:
> > +  - Rohit kumar 
> > +  - Cheng-Yi Chiang 
> > +
> > +description:
> > +  This binding describes the SC7180 sound card which uses LPASS for audio.
> > +
> > +definitions:
> > +
> > +  dai:
> > +type: object
> > +properties:
> > +  sound-dai:
> > +maxItems: 1
> > +$ref: /schemas/types.yaml#/definitions/phandle-array
> > +description: phandle array of the codec or CPU DAI
> > +
> > +required:
> > +  - sound-dai
> > +
> > +properties:
> > +  compatible:
> > +contains:
> > +  const: qcom,sc7180-sndcard
> > +
> > +  audio-routing:
> > +$ref: /schemas/types.yaml#/definitions/non-unique-string-array
> > +description:
> > +  A list of the connections between audio components. Each entry is a
> > +  pair of strings, the first being the connection's sink, the second
> > +  being the connection's source.
> > +
> > +  model:
> > +$ref: /schemas/types.yaml#/definitions/string
> > +description: User specified audio sound card name
> > +
> > +  aux-dev:
> > +$ref: /schemas/types.yaml#/definitions/phandle
> > +description: phandle of the codec for headset detection
>
>
> Why do we need this? You should be able to set the jack for codec
> snd_soc_component_set_jack()?
>
>
I put my explanation in the machine driver patch since there is more
context there.

> > +
> > +patternProperties:
> > +  "^dai-link(@[0-9]+)?$":
> > +description:
> > +  Each subnode represents a dai link. Subnodes of each dai links would 
> > be
> > +  cpu/codec dais.
> > +
> > +type: object
> > +
> > +properties:
> > +  link-name:
> > +description: Indicates dai-link name and PCM stream name.
> > +$ref: /schemas/types.yaml#/definitions/string
> > +maxItems: 1
> > +
> > +  reg:
> > +description: dai link address.
> > +$ref: /schemas/types.yaml#/definitions/uint32
> > +maxItems: 1
>
> Why do we need this?? I have not seen the parsing code using this.
>
>
When checking the yaml file using dt_binding_check, I got this warnings:

$  make dt_binding_check
DT_SCHEMA_FILES=Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
  CHKDT   Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
  SCHEMA  Documentation/devicetree/bindings/processed-schema-examples.yaml
  DTC Documentation/devicetree/bindings/sound/qcom,sc7180.example.dt.yaml
Documentation/devicetree/bindings/sound/qcom,sc7180.example.dts:32.24-41.15:
Warning (unit_address_vs_reg): /example-0/sound/dai-link@0: node has a
unit name, but no reg or ranges property
Documentation/devicetree/bindings/sound/qcom,sc7180.example.dts:43.24-52.15:
Warning (unit_address_vs_reg): /example-0/sound/dai-link@1: node has a
unit name, but no reg or ranges property
  CHECK   Documentation/devicetree/bindings/sound/qcom,sc7180.example.dt.yaml

Should I ignore these warnings because reg is not used in the driver ?

> > +
> > +  playback-only:
> > +description: Specify that the dai link is only for playback.
> > +$ref: /schemas/types.yaml#/definitions/flag
> > +
> > +  capture-only:
> > +description: Specify that the dai link is only for capture.
> > +$ref: /schemas/types.yaml#/definitions/flag
> > +
>
> Are these because the cpu/codec dais are single directional?
>
&

[PATCH v3 1/2] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-07-31 Thread Cheng-Yi Chiang
Add devicetree bindings documentation file for sc7180 sound card.

Signed-off-by: Cheng-Yi Chiang 
---
 .../bindings/sound/qcom,sc7180.yaml   | 113 ++
 1 file changed, 113 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml

diff --git a/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml 
b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
new file mode 100644
index ..ce8a5a2d9df9
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
@@ -0,0 +1,113 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/qcom,sc7180.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Technologies Inc. SC7180 ASoC sound card driver
+
+maintainers:
+  - Rohit kumar 
+  - Cheng-Yi Chiang 
+
+description:
+  This binding describes the SC7180 sound card which uses LPASS for audio.
+
+definitions:
+
+  dai:
+type: object
+properties:
+  sound-dai:
+maxItems: 1
+$ref: /schemas/types.yaml#/definitions/phandle-array
+description: phandle array of the codec or CPU DAI
+
+required:
+  - sound-dai
+
+properties:
+  compatible:
+contains:
+  const: qcom,sc7180-sndcard
+
+  audio-routing:
+$ref: /schemas/types.yaml#/definitions/non-unique-string-array
+description:
+  A list of the connections between audio components. Each entry is a
+  pair of strings, the first being the connection's sink, the second
+  being the connection's source.
+
+  model:
+$ref: /schemas/types.yaml#/definitions/string
+description: User specified audio sound card name
+
+  aux-dev:
+$ref: /schemas/types.yaml#/definitions/phandle
+description: phandle of the codec for headset detection
+
+patternProperties:
+  "^dai-link(@[0-9]+)?$":
+description:
+  Each subnode represents a dai link. Subnodes of each dai links would be
+  cpu/codec dais.
+
+type: object
+
+properties:
+  link-name:
+description: Indicates dai-link name and PCM stream name.
+$ref: /schemas/types.yaml#/definitions/string
+maxItems: 1
+
+  cpu:
+$ref: "#/definitions/dai"
+
+  codec:
+$ref: "#/definitions/dai"
+
+required:
+  - link-name
+  - cpu
+  - codec
+
+additionalProperties: false
+
+examples:
+
+  - |
+sound {
+compatible = "qcom,sc7180-sndcard";
+model = "sc7180-snd-card";
+
+audio-routing =
+"Headphone Jack", "HPOL",
+"Headphone Jack", "HPOR";
+
+aux-dev = <>;
+
+#address-cells = <1>;
+#size-cells = <0>;
+
+dai-link@0 {
+link-name = "MultiMedia0";
+cpu {
+sound-dai = <_cpu 0>;
+};
+
+codec {
+sound-dai = < 0>;
+};
+};
+
+dai-link@1 {
+link-name = "MultiMedia1";
+cpu {
+sound-dai = <_cpu 1>;
+};
+
+codec {
+sound-dai = <>;
+};
+};
+};
-- 
2.28.0.163.g6104cc2f0b6-goog



[PATCH v3 2/2] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-07-31 Thread Cheng-Yi Chiang
From: Ajit Pandey 

Add new driver to register sound card on sc7180 trogdor board and
do the required configuration for lpass cpu dai and external codecs
connected over MI2S interfaces.

Signed-off-by: Ajit Pandey 
Signed-off-by: Cheng-Yi Chiang 
---
 sound/soc/qcom/Kconfig  |  12 ++
 sound/soc/qcom/Makefile |   2 +
 sound/soc/qcom/sc7180.c | 244 
 3 files changed, 258 insertions(+)
 create mode 100644 sound/soc/qcom/sc7180.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 5d6b2466a2f2..54aa2ede229c 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -110,3 +110,15 @@ config SND_SOC_SDM845
  To add support for audio on Qualcomm Technologies Inc.
  SDM845 SoC-based systems.
  Say Y if you want to use audio device on this SoCs.
+
+config SND_SOC_SC7180
+   tristate "SoC Machine driver for SC7180 boards"
+   depends on SND_SOC_QCOM
+   select SND_SOC_QCOM_COMMON
+   select SND_SOC_LPASS_SC7180
+   select SND_SOC_MAX98357A
+   select SND_SOC_RT5682
+   help
+To add support for audio on Qualcomm Technologies Inc.
+SC7180 SoC-based systems.
+Say Y if you want to use audio device on this SoCs.
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index 41b2c7a23a4d..3f6275d90526 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -15,12 +15,14 @@ snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
 snd-soc-apq8096-objs := apq8096.o
 snd-soc-sdm845-objs := sdm845.o
+snd-soc-sc7180-objs := sc7180.o
 snd-soc-qcom-common-objs := common.o
 
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
 obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
 obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
+obj-$(CONFIG_SND_SOC_SC7180) += snd-soc-sc7180.o
 obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o
 
 #DSP lib
diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
new file mode 100644
index ..7849376f63ba
--- /dev/null
+++ b/sound/soc/qcom/sc7180.c
@@ -0,0 +1,244 @@
+// SPDX-License-Identifier: GPL-2.0-only
+//
+// Copyright (c) 2020, The Linux Foundation. All rights reserved.
+//
+// sc7180.c -- ALSA SoC Machine driver for SC7180
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../codecs/rt5682.h"
+#include "common.h"
+#include "lpass.h"
+
+#define DEFAULT_SAMPLE_RATE_48K48000
+#define DEFAULT_MCLK_RATE  1920
+#define RT5682_PLL1_FREQ (48000 * 512)
+
+struct sc7180_snd_data {
+   struct snd_soc_jack jack;
+   u32 pri_mi2s_clk_count;
+};
+
+static void sc7180_jack_free(struct snd_jack *jack)
+{
+   struct snd_soc_component *component = jack->private_data;
+
+   snd_soc_component_set_jack(component, NULL, NULL);
+}
+
+static int sc7180_headset_init(struct snd_soc_component *component)
+{
+   struct snd_soc_card *card = component->card;
+   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
+   struct snd_jack *jack;
+   int rval;
+
+   rval = snd_soc_card_jack_new(
+   card, "Headset Jack",
+   SND_JACK_HEADSET |
+   SND_JACK_HEADPHONE |
+   SND_JACK_BTN_0 | SND_JACK_BTN_1 |
+   SND_JACK_BTN_2 | SND_JACK_BTN_3,
+   >jack, NULL, 0);
+
+   if (rval < 0) {
+   dev_err(card->dev, "Unable to add Headset Jack\n");
+   return rval;
+   }
+
+   jack = pdata->jack.jack;
+
+   snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
+   snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
+   snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
+   snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
+
+   jack->private_data = component;
+   jack->private_free = sc7180_jack_free;
+
+   rval = snd_soc_component_set_jack(component,
+ >jack, NULL);
+   if (rval != 0 && rval != -EOPNOTSUPP) {
+   dev_warn(card->dev, "Failed to set jack: %d\n", rval);
+   return rval;
+   }
+
+   return 0;
+}
+
+static struct snd_soc_aux_dev sc7180_headset_dev = {
+   .dlc = COMP_EMPTY(),
+   .init = sc7180_headset_init,
+};
+
+static int sc7180_snd_startup(struct snd_pcm_substream *substream)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct snd_soc_card *card = rtd->card;
+   struct sc7180_snd_data *data = snd_soc_card_get_drvdata(card);
+   struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
+   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+   int re

[PATCH v3 0/2] Add documentation and machine driver for SC7180 sound card

2020-07-31 Thread Cheng-Yi Chiang
Note:
- The machine driver patch depends on LPASS patch series so it is not ready to 
be merged now.
  ASoC: qcom: Add support for SC7180 lpass variant 
https://patchwork.kernel.org/cover/11678133/
- The machine driver patch is made by the collaboration of
  Cheng-Yi Chiang 
  Rohit kumar 
  Ajit Pandey 
  But Ajit has left codeaurora.

Changes from v1 to v2:
- Ducumentation: Addressed all suggestions from Doug.
- Machine driver:
  - Fix comment style for license.
  - Sort includes.
  - Remove sc7180_snd_hw_params.
  - Remove sc7180_dai_init and use aux device instead for headset jack 
registration.
  - Statically define format for Primary MI2S.
  - Atomic is not a concern because there is mutex in card to make sure
startup and shutdown happen sequentially.
  - Fix missing return -EINVAL in startup.
  - Use static sound card.
  - Use devm_kzalloc to avoid kfree.

Changes from v2 to v3:
- Ducumentation: Addressed suggestions from Srini.
- Machine driver:
  - Reuse qcom_snd_parse_of to parse properties.
  - Remove playback-only and capture-only.
  - Misc fixes to address comments.

Thanks for the review!
Ajit Pandey (1):
  ASoC: qcom: sc7180: Add machine driver for sound card registration

Cheng-Yi Chiang (1):
  ASoC: qcom: dt-bindings: Add sc7180 machine bindings

 .../bindings/sound/qcom,sc7180.yaml   | 113 
 sound/soc/qcom/Kconfig|  12 +
 sound/soc/qcom/Makefile   |   2 +
 sound/soc/qcom/sc7180.c   | 244 ++
 4 files changed, 371 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
 create mode 100644 sound/soc/qcom/sc7180.c

-- 
2.28.0.163.g6104cc2f0b6-goog



Re: [PATCH] ASoC: Intel: Atom: use hardware counter to update hw_ptr

2020-07-28 Thread Cheng-yi Chiang
On Wed, Jul 29, 2020 at 1:31 AM Pierre-Louis Bossart
 wrote:
>
>
>
> On 7/28/20 12:02 PM, Lu, Brent wrote:
> >>
> >> So if there are already quirks in atom machine drivers to change the period
> >> size, why is this patch necessary?
> >>
> >
> > The story is: google implemented the constraint but doesn't know why it 
> > works
> > so asked us to explain. After checking the two counters I realized the 
> > increase of
> > ring buffer pointer follows the period size setting in hw_param (256) but 
> > the
> > period of interrupt is always 5ms instead of 5.33 so it's running little 
> > bit too fast.
> > It seems the LPE keeps tracking the difference of two counters. When the
> > difference exceeds 2160 samples, the next interrupt will be canceled so the
> > hardware counter could catch up a little.
> >
> > [   43.208299] intel_sst_acpi 808622A8:00: mrfld ring_buffer_counter 107520 
> > hardware_counter 98880 pcm delay 8640 (in bytes)
> > [   43.208306] intel_sst_acpi 808622A8:00: buffer ptr 26880 pcm_delay rep: 
> > 2160
> > [   43.208321] sound pcmC1D0p: [Q] pos 26880 hw_ptr 26880 appl_ptr 4 
> > avail 191680
> > => one interrupt is skipped.
> > [   43.218299] intel_sst_acpi 808622A8:00: mrfld ring_buffer_counter 108544 
> > hardware_counter 100800 pcm delay 7744 (in bytes)
> > [   43.218307] intel_sst_acpi 808622A8:00: buffer ptr 27136 pcm_delay rep: 
> > 1936
> > [   43.218336] sound pcmC1D0p: [Q] pos 27136 hw_ptr 27136 appl_ptr 4 
> > avail 191936
> >
> > So I think why not using the hardware counter? It increases 240 samples 
> > every 5ms
> > perfectly match the 48000 sample rate. The test result is good but I know 
> > there must
> > be a reason for the original designer to use ring buffer counter instead of 
> > hardware
> > counter. I uploaded this patch to see if anyone still remember the reason 
> > and share
> > some insight with me.
> >
> > I totally agree that we shouldn't touch this part of design. Do you think 
> > it make sense
> > to add a constraint to enforce the period size in machine driver? If yes 
> > then I would
> > upload patches for Chrome atom machines for google.
>
> I think it'd make sense to add this constraint, either in the machine
> driver or in the platform driver, so that we don't change the position
> updates and introduce more issues by accident by doing so. As you
> rightly said, I don't think anyone tested periods multiple of 256
> samples so it's not a regression, more aligning with the internal design.

Thanks for the explanation and discussion.
A slight correction in this thread is that CRAS does not set period size to 256.
It just uses whatever value that driver wants to use, which happens to be 256.
If the driver can limit the selection to only correct values that
would be the best.
Adding constraints in the machine driver or platform driver looks
good. Prefer to adding in platform driver so we don't need to add for
each machine driver.
Thanks!


Re: [PATCH 2/2] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-07-21 Thread Cheng-yi Chiang
Hi Tzung-Bi,
Thanks for the review!
On Mon, Jul 20, 2020 at 10:47 AM Tzung-Bi Shih  wrote:
>
> On Fri, Jul 17, 2020 at 8:02 PM Cheng-Yi Chiang  wrote:
> > diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
> > new file mode 100644
> > index ..cbe6b487d432
> > --- /dev/null
> > +++ b/sound/soc/qcom/sc7180.c
> > @@ -0,0 +1,410 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/*
> > + * Copyright (c) 2020, The Linux Foundation. All rights reserved.
> > + *
> > + * sc7180.c -- ALSA SoC Machine driver for SC7180
> > + */
> Use "//" for all lines (see https://lkml.org/lkml/2020/5/14/332).
>

Thanks for the pointer. Fixed in v2.

> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include "../codecs/rt5682.h"
> > +#include "common.h"
> > +#include "lpass.h"
> Insert a blank line in between <...> and "..." and sort the list
> alphabetically to make it less likely to conflict.

Fixed in v2.

>
> > +static int sc7180_snd_hw_params(struct snd_pcm_substream *substream,
> > +   struct snd_pcm_hw_params *params)
> > +{
> Dummy function?  Or is it still work in progress?
>
Removed in v2.

> > +   struct snd_soc_pcm_runtime *rtd = substream->private_data;
> > +   struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
> > +   int ret = 0;
> > +
> > +   switch (cpu_dai->id) {
> > +   case MI2S_PRIMARY:
> > +   break;
> > +   case MI2S_SECONDARY:
> > +   break;
> > +   default:
> > +   pr_err("%s: invalid dai id 0x%x\n", __func__, cpu_dai->id);
> -EINVAL.
>
Removed in v2.
> > +static int sc7180_dai_init(struct snd_soc_pcm_runtime *rtd)
> > +{
> > +   struct snd_soc_component *component;
> > +   struct snd_soc_card *card = rtd->card;
> > +   struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
> > +   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
> > +   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
> > +   struct snd_jack *jack;
> > +   int rval;
> > +
> > +   if (!pdata->jack_setup) {
> > +   rval = snd_soc_card_jack_new(
> > +   card, "Headset Jack",
> > +   SND_JACK_HEADSET |
> > +   SND_JACK_HEADPHONE |
> > +   SND_JACK_BTN_0 | SND_JACK_BTN_1 |
> > +   SND_JACK_BTN_2 | SND_JACK_BTN_3,
> > +   >jack, NULL, 0);
> > +
> > +   if (rval < 0) {
> > +   dev_err(card->dev, "Unable to add Headphone 
> > Jack\n");
> > +   return rval;
> > +   }
> > +
> > +   jack = pdata->jack.jack;
> > +
> > +   snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
> > +   snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
> > +   snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
> > +   snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
> > +   pdata->jack_setup = true;
> This block is something I don't expect to be in "dai_init" (i.e. there
> is only 1 headset jack, why do we need to run the code for n times).
>
Thanks for the suggestion. In v2 I am using aux device so this
function is cleaned up to be specific to aux device for jack
detection.

> > +   switch (cpu_dai->id) {
> > +   case MI2S_PRIMARY:
> > +   jack  = pdata->jack.jack;
> > +   component = codec_dai->component;
> > +
> > +   jack->private_data = component;
> > +   jack->private_free = sc7180_jack_free;
> > +   rval = snd_soc_component_set_jack(component,
> > + >jack, NULL);
> > +   if (rval != 0 && rval != -EOPNOTSUPP) {
> > +   dev_warn(card->dev, "Failed to set jack: %d\n", 
> > rval);
> > +   return rval;
> > +   }
> > +   break;
> > +   case MI2S_SECONDARY:
> > +   break;
> > +   default:
> > +   pr_err(&

Re: [PATCH 1/2] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-07-21 Thread Cheng-yi Chiang
On Fri, Jul 17, 2020 at 11:03 PM Doug Anderson  wrote:
>
> Hi,
>

Thanks for the review!

> On Fri, Jul 17, 2020 at 5:02 AM Cheng-Yi Chiang  wrote:
> >
> > Add devicetree bindings documentation file for sc7180 sound card.
> >
> > Signed-off-by: Cheng-Yi Chiang 
> > ---
> >  .../bindings/sound/qcom,sc7180.yaml   | 123 ++
> >  1 file changed, 123 insertions(+)
>
> A bit of a mechanical review since my audio knowledge is not strong.
>
>
> >  create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> >
> > diff --git a/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml 
> > b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> > new file mode 100644
> > index ..d60d2880d991
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
> > @@ -0,0 +1,123 @@
> > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> > +%YAML 1.2
> > +---
> > +$id: http://devicetree.org/schemas/sound/qcom,sc7180.yaml#
> > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: Qualcomm Technologies Inc. SC7180 ASoC sound card driver
> > +
> > +maintainers:
> > +  - Rohit kumar 
> > +  - Cheng-Yi Chiang 
> > +
> > +description: |
> > +  This binding describes the SC7180 sound card, which uses LPASS for audio.
>
> nit: you don't need the pipe at the end of the "description" line.
> That means that newlines are important and you don't need it.
>
>
Thanks for the explanation. Fixed in v2.
> > +definitions:
>
> I haven't yet seen much yaml using definitions like this.  It feels
> like overkill for some of these properties, especially ones that are
> only ever used once in the "properties:" section and are/or are really
> simple.
>
>
ACK. In v2 I only kept dai definition and removed others.

> > +  link-name:
> > +description: Indicates dai-link name and PCM stream name.
> > +$ref: /schemas/types.yaml#/definitions/string
> > +maxItems: 1
> > +
> > +  dai:
> > +type: object
> > +properties:
> > +  sound-dai:
> > +maxItems: 1
> > +$ref: /schemas/types.yaml#/definitions/phandle-array
> > +description: phandle array of the codec or CPU DAI
> > +
> > +required:
> > +  - sound-dai
> > +
> > +  unidirectional:
> > +description: Specify direction of unidirectional dai link.
> > + 0 for playback only. 1 for capture only.
> > +$ref: /schemas/types.yaml#/definitions/uint32
>
> So if the property isn't there then it's _not_ unidirectional and if
> it is there then this specifies the direction, right?  I almost wonder
> if this should just be two boolean properties, like:
>
> playback-only;
> capture-only;
>
> ...but I guess I'd leave it to Rob and/or Mark to say what they liked
> better.  In any case if you keep it how you have it then you should
> use yaml to force it to be either 0 or 1 if present.
>
>
ACK
Use playback-only and capture-only in v2 instead.

> > +
> > +properties:
> > +  compatible:
> > +contains:
> > +  enum:
> > +- qcom,sc7180-sndcard
>
> Just:
>
> properties:
>   compatible:
> const: qcom,sc7180-sndcard
>
>

Fixed in v2.

>
> > +  audio-routing:
> > +$ref: /schemas/types.yaml#/definitions/non-unique-string-array
> > +description: |-
> > +  A list of the connections between audio components. Each entry is a
> > +  pair of strings, the first being the connection's sink, the second
> > +  being the connection's source.
>
> You don't need the "|-" after the "description:".  That says newlines
> are important but strip the newline from the end.
>
Fixed in v2.
>
> > +  model:
> > +$ref: /schemas/types.yaml#/definitions/string
> > +description: User specified audio sound card name
> > +
> > +patternProperties:
> > +  "^dai-link-[0-9]+$":
> > +description: |
> > +  Each subnode represents a dai link. Subnodes of each dai links would 
> > be
> > +  cpu/codec dais.
>
> From looking at "simple-card.yaml", I'm gonna guess that instead of
> encoding the link number in the name of the node that you should
> actually use a unit address and a reg in the subnodes.

Thanks for the explanation. Fixed in v2.
I think this naming is better, although there is no usage in the
machine driver for the reg.

>
> ...also, again your description doesn't need th

[PATCH v2 2/2] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-07-21 Thread Cheng-Yi Chiang
From: Ajit Pandey 

Add new driver to register sound card on sc7180 trogdor board and
do the required configuration for lpass cpu dai and external codecs
connected over MI2S interfaces.

Signed-off-by: Cheng-Yi Chiang 
---
 sound/soc/qcom/Kconfig  |  11 ++
 sound/soc/qcom/Makefile |   2 +
 sound/soc/qcom/sc7180.c | 380 
 3 files changed, 393 insertions(+)
 create mode 100644 sound/soc/qcom/sc7180.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index cfca0f730c61..1b02f521f355 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -109,3 +109,14 @@ config SND_SOC_SDM845
  To add support for audio on Qualcomm Technologies Inc.
  SDM845 SoC-based systems.
  Say Y if you want to use audio device on this SoCs.
+
+config SND_SOC_SC7180
+   tristate "SoC Machine driver for SC7180 boards"
+   depends on SND_SOC_QCOM
+   select SND_SOC_LPASS_SC7180
+   select SND_SOC_MAX98357A
+   select SND_SOC_RT5682
+   help
+To add support for audio on Qualcomm Technologies Inc.
+SC7180 SoC-based systems.
+Say Y if you want to use audio device on this SoCs.
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index 41b2c7a23a4d..3f6275d90526 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -15,12 +15,14 @@ snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
 snd-soc-apq8096-objs := apq8096.o
 snd-soc-sdm845-objs := sdm845.o
+snd-soc-sc7180-objs := sc7180.o
 snd-soc-qcom-common-objs := common.o
 
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
 obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
 obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
+obj-$(CONFIG_SND_SOC_SC7180) += snd-soc-sc7180.o
 obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o
 
 #DSP lib
diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
new file mode 100644
index ..3beb2b129d01
--- /dev/null
+++ b/sound/soc/qcom/sc7180.c
@@ -0,0 +1,380 @@
+// SPDX-License-Identifier: GPL-2.0-only
+//
+//Copyright (c) 2020, The Linux Foundation. All rights reserved.
+//
+//sc7180.c -- ALSA SoC Machine driver for SC7180
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../codecs/rt5682.h"
+#include "common.h"
+#include "lpass.h"
+
+#define DEFAULT_SAMPLE_RATE_48K48000
+#define DEFAULT_MCLK_RATE  1920
+#define RT5682_PLL1_FREQ (48000 * 512)
+
+static int sc7180_headset_init(struct snd_soc_component *component);
+
+static struct snd_soc_aux_dev sc7180_headset_dev = {
+   .dlc = COMP_EMPTY(),
+   .init = sc7180_headset_init,
+};
+
+struct sc7180_snd_data {
+   struct snd_soc_jack jack;
+   struct snd_soc_card *card;
+   u32 pri_mi2s_clk_count;
+};
+
+static void sc7180_jack_free(struct snd_jack *jack)
+{
+   struct snd_soc_component *component = jack->private_data;
+
+   snd_soc_component_set_jack(component, NULL, NULL);
+}
+
+static int sc7180_headset_init(struct snd_soc_component *component)
+{
+   struct snd_soc_card *card = component->card;
+   struct sc7180_snd_data *pdata = snd_soc_card_get_drvdata(card);
+   struct snd_jack *jack;
+   int rval;
+
+   rval = snd_soc_card_jack_new(
+   card, "Headset Jack",
+   SND_JACK_HEADSET |
+   SND_JACK_HEADPHONE |
+   SND_JACK_BTN_0 | SND_JACK_BTN_1 |
+   SND_JACK_BTN_2 | SND_JACK_BTN_3,
+   >jack, NULL, 0);
+
+   if (rval < 0) {
+   dev_err(card->dev, "Unable to add Headset Jack\n");
+   return rval;
+   }
+
+   jack = pdata->jack.jack;
+
+   snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
+   snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
+   snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
+   snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
+
+   jack->private_data = component;
+   jack->private_free = sc7180_jack_free;
+
+   rval = snd_soc_component_set_jack(component,
+ >jack, NULL);
+   if (rval != 0 && rval != -EOPNOTSUPP) {
+   dev_warn(card->dev, "Failed to set jack: %d\n", rval);
+   return rval;
+   }
+
+   return 0;
+}
+
+
+static unsigned int primary_dai_fmt = SND_SOC_DAIFMT_CBS_CFS |
+ SND_SOC_DAIFMT_NB_NF |
+ SND_SOC_DAIFMT_I2S;
+
+static int sc7180_snd_startup(struct snd_pcm_substream *substream)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct snd_soc_card *card = rtd-&g

[PATCH v2 0/2] Add documentation and machine driver for SC7180 sound card

2020-07-21 Thread Cheng-Yi Chiang
Note:
- The machine driver patch depends on LPASS patch series so it is not ready to 
be merged now.
  ASoC: qcom: Add support for SC7180 lpass variant 
https://patchwork.kernel.org/cover/11650649/
- The machine driver patch is made by the collaboration of
  Cheng-Yi Chiang 
  Rohit kumar 
  Ajit Pandey 
  But Ajit has left codeaurora.

Changes from v1 to v2:
- Ducumentation: Addressed all suggestions from Doug.
- Machine driver:
  - Fix comment style for license.
  - Sort includes.
  - Remove sc7180_snd_hw_params.
  - Remove sc7180_dai_init and use aux device instead for headset jack 
registration.
  - Statically define format for Primary MI2S.
  - Atomic is not a concern because there is mutex in card to make sure
startup and shutdown happen sequentially.
  - Fix missing return -EINVAL in startup.
  - Use static sound card.
  - Use devm_kzalloc to avoid kfree.

Thanks for the review!

Ajit Pandey (1):
  ASoC: qcom: sc7180: Add machine driver for sound card registration

Cheng-Yi Chiang (1):
  ASoC: qcom: dt-bindings: Add sc7180 machine bindings

 .../bindings/sound/qcom,sc7180.yaml   | 130 ++
 sound/soc/qcom/Kconfig|  11 +
 sound/soc/qcom/Makefile   |   2 +
 sound/soc/qcom/sc7180.c   | 380 ++
 4 files changed, 523 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
 create mode 100644 sound/soc/qcom/sc7180.c

-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v2 1/2] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-07-21 Thread Cheng-Yi Chiang
Add devicetree bindings documentation file for sc7180 sound card.

Signed-off-by: Cheng-Yi Chiang 
---
 .../bindings/sound/qcom,sc7180.yaml   | 130 ++
 1 file changed, 130 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml

diff --git a/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml 
b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
new file mode 100644
index ..82f9483276eb
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
@@ -0,0 +1,130 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/qcom,sc7180.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Technologies Inc. SC7180 ASoC sound card driver
+
+maintainers:
+  - Rohit kumar 
+  - Cheng-Yi Chiang 
+
+description:
+  This binding describes the SC7180 sound card which uses LPASS for audio.
+
+definitions:
+
+  dai:
+type: object
+properties:
+  sound-dai:
+maxItems: 1
+$ref: /schemas/types.yaml#/definitions/phandle-array
+description: phandle array of the codec or CPU DAI
+
+required:
+  - sound-dai
+
+properties:
+  compatible:
+contains:
+  const: qcom,sc7180-sndcard
+
+  audio-routing:
+$ref: /schemas/types.yaml#/definitions/non-unique-string-array
+description:
+  A list of the connections between audio components. Each entry is a
+  pair of strings, the first being the connection's sink, the second
+  being the connection's source.
+
+  model:
+$ref: /schemas/types.yaml#/definitions/string
+description: User specified audio sound card name
+
+  aux-dev:
+$ref: /schemas/types.yaml#/definitions/phandle
+description: phandle of the codec for headset detection
+
+patternProperties:
+  "^dai-link(@[0-9]+)?$":
+description:
+  Each subnode represents a dai link. Subnodes of each dai links would be
+  cpu/codec dais.
+
+type: object
+
+properties:
+  link-name:
+description: Indicates dai-link name and PCM stream name.
+$ref: /schemas/types.yaml#/definitions/string
+maxItems: 1
+
+  reg:
+description: dai link address.
+$ref: /schemas/types.yaml#/definitions/uint32
+maxItems: 1
+
+  playback-only:
+description: Specify that the dai link is only for playback.
+$ref: /schemas/types.yaml#/definitions/flag
+
+  capture-only:
+description: Specify that the dai link is only for capture.
+$ref: /schemas/types.yaml#/definitions/flag
+
+  cpu:
+$ref: "#/definitions/dai"
+
+  codec:
+$ref: "#/definitions/dai"
+
+required:
+  - link-name
+  - reg
+  - cpu
+  - codec
+
+additionalProperties: false
+
+examples:
+
+  - |
+sound {
+compatible = "qcom,sc7180-sndcard";
+model = "sc7180-snd-card";
+
+audio-routing =
+"Headphone Jack", "HPOL",
+"Headphone Jack", "HPOR";
+
+aux-dev = <>;
+
+#address-cells = <1>;
+#size-cells = <0>;
+
+dai-link@0 {
+reg = <0>;
+link-name = "MultiMedia0";
+cpu {
+sound-dai = <_cpu 0>;
+};
+
+codec {
+sound-dai = < 0>;
+};
+};
+
+dai-link@1 {
+reg = <1>;
+link-name = "MultiMedia1";
+playback-only;
+cpu {
+sound-dai = <_cpu 1>;
+};
+
+codec {
+sound-dai = <>;
+};
+};
+};
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH 2/2] ASoC: qcom: sc7180: Add machine driver for sound card registration

2020-07-17 Thread Cheng-Yi Chiang
From: Ajit Pandey 

Add new driver to register sound card on sc7180 trogdor board and
do the required configuration for lpass cpu dai and external codecs
connected over MI2S interfaces.

Signed-off-by: Ajit Pandey 
Signed-off-by: Cheng-Yi Chiang 
---
Note:
- This patch depends on this patch series so it is not ready to be merged now.
 ASoC: qcom: Add support for SC7180 lpass variant 
https://patchwork.kernel.org/cover/11650649/
- The patch is made by the collaboration of
 Cheng-Yi Chiang 
 Rohit kumar 
 Ajit Pandey 
 But Ajit has left codeaurora.
- We may reduce the duplicate code of sc7180_parse_of and qcom_snd_parse_of in 
snd/soc/qcom/common.c.
 However, qcom_snd_parse_of has specific logic with qdsp. In this initial 
version, to keep it simple,
 I choose to only implement needed device property parsing by sc7180 sound card 
in sc7180_parse_of.

Thanks for the review!

 sound/soc/qcom/Kconfig  |  11 ++
 sound/soc/qcom/Makefile |   2 +
 sound/soc/qcom/sc7180.c | 410 
 3 files changed, 423 insertions(+)
 create mode 100644 sound/soc/qcom/sc7180.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index cfca0f730c61..4adc2362865b 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -109,3 +109,14 @@ config SND_SOC_SDM845
  To add support for audio on Qualcomm Technologies Inc.
  SDM845 SoC-based systems.
  Say Y if you want to use audio device on this SoCs.
+
+config SND_SOC_SC7180
+   tristate "SoC Machine driver for SC7180 boards"
+depends on SND_SOC_QCOM
+   select SND_SOC_LPASS_SC7180
+select SND_SOC_MAX98357A
+select SND_SOC_RT5682
+   help
+To add support for audio on Qualcomm Technologies Inc.
+SC7180 SoC-based systems.
+Say Y if you want to use audio device on this SoCs.
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index 41b2c7a23a4d..3f6275d90526 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -15,12 +15,14 @@ snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
 snd-soc-apq8096-objs := apq8096.o
 snd-soc-sdm845-objs := sdm845.o
+snd-soc-sc7180-objs := sc7180.o
 snd-soc-qcom-common-objs := common.o
 
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
 obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
 obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
+obj-$(CONFIG_SND_SOC_SC7180) += snd-soc-sc7180.o
 obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o
 
 #DSP lib
diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
new file mode 100644
index ..cbe6b487d432
--- /dev/null
+++ b/sound/soc/qcom/sc7180.c
@@ -0,0 +1,410 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2020, The Linux Foundation. All rights reserved.
+ *
+ * sc7180.c -- ALSA SoC Machine driver for SC7180
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../codecs/rt5682.h"
+#include "common.h"
+#include "lpass.h"
+
+#define DEFAULT_SAMPLE_RATE_48K48000
+#define DEFAULT_MCLK_RATE  1920
+#define RT5682_PLL1_FREQ (48000 * 512)
+
+int sc7180_parse_of(struct snd_soc_card *card)
+{
+   struct device_node *np;
+   struct device_node *codec = NULL;
+   struct device_node *platform = NULL;
+   struct device_node *cpu = NULL;
+   struct device *dev = card->dev;
+   struct snd_soc_dai_link *link;
+   struct of_phandle_args args;
+   struct snd_soc_dai_link_component *dlc;
+   int ret, num_links, dir;
+
+   ret = snd_soc_of_parse_card_name(card, "model");
+   if (ret) {
+   dev_err(dev, "Error parsing card name: %d\n", ret);
+   return ret;
+   }
+
+   /* DAPM routes */
+   if (of_property_read_bool(dev->of_node, "audio-routing")) {
+   ret = snd_soc_of_parse_audio_routing(card,
+"audio-routing");
+   if (ret)
+   return ret;
+   }
+
+   /* Populate links */
+   num_links = of_get_child_count(dev->of_node);
+
+   /* Allocate the DAI link array */
+   card->dai_link = kcalloc(num_links, sizeof(*link), GFP_KERNEL);
+   if (!card->dai_link)
+   return -ENOMEM;
+
+   card->num_links = num_links;
+   link = card->dai_link;
+
+   for_each_child_of_node(dev->of_node, np) {
+   dlc = devm_kzalloc(dev, 2 * sizeof(*dlc), GFP_KERNEL);
+   if (!dlc)
+   return -ENOMEM;
+
+   link->cpus  = [0];
+   link->platforms = [1];
+
+   link->num_cpus  = 1;
+   link->num_platforms = 1;
+
+   ret = o

[PATCH 1/2] ASoC: qcom: dt-bindings: Add sc7180 machine bindings

2020-07-17 Thread Cheng-Yi Chiang
Add devicetree bindings documentation file for sc7180 sound card.

Signed-off-by: Cheng-Yi Chiang 
---
 .../bindings/sound/qcom,sc7180.yaml   | 123 ++
 1 file changed, 123 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sc7180.yaml

diff --git a/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml 
b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
new file mode 100644
index ..d60d2880d991
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/qcom,sc7180.yaml
@@ -0,0 +1,123 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/qcom,sc7180.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Technologies Inc. SC7180 ASoC sound card driver
+
+maintainers:
+  - Rohit kumar 
+  - Cheng-Yi Chiang 
+
+description: |
+  This binding describes the SC7180 sound card, which uses LPASS for audio.
+
+definitions:
+
+  link-name:
+description: Indicates dai-link name and PCM stream name.
+$ref: /schemas/types.yaml#/definitions/string
+maxItems: 1
+
+  dai:
+type: object
+properties:
+  sound-dai:
+maxItems: 1
+$ref: /schemas/types.yaml#/definitions/phandle-array
+description: phandle array of the codec or CPU DAI
+
+required:
+  - sound-dai
+
+  unidirectional:
+description: Specify direction of unidirectional dai link.
+ 0 for playback only. 1 for capture only.
+$ref: /schemas/types.yaml#/definitions/uint32
+
+properties:
+  compatible:
+contains:
+  enum:
+- qcom,sc7180-sndcard
+
+  audio-routing:
+$ref: /schemas/types.yaml#/definitions/non-unique-string-array
+description: |-
+  A list of the connections between audio components. Each entry is a
+  pair of strings, the first being the connection's sink, the second
+  being the connection's source.
+
+  model:
+$ref: /schemas/types.yaml#/definitions/string
+description: User specified audio sound card name
+
+patternProperties:
+  "^dai-link-[0-9]+$":
+description: |
+  Each subnode represents a dai link. Subnodes of each dai links would be
+  cpu/codec dais.
+
+type: object
+
+properties:
+  link-name:
+$ref: "#/definitions/link-name"
+
+  unidirectional:
+$ref: "#/definitions/unidirectional"
+
+  cpu:
+$ref: "#/definitions/dai"
+
+  codec:
+$ref: "#/definitions/dai"
+
+required:
+  - link-name
+  - cpu
+  - codec
+
+additionalProperties: false
+
+examples:
+
+  - |
+snd {
+compatible = "qcom,sc7180-sndcard";
+model = "sc7180-snd-card";
+
+pinctrl-names = "default";
+pinctrl-0 = <_mi2s_active _mi2s_dout_active
+ _mi2s_ws_active _mi2s_active
+ _mi2s_dout_active _mi2s_ws_active
+ _mi2s_din_active _mi2s_mclk_active>;
+
+audio-routing =
+"Headphone Jack", "HPOL",
+"Headphone Jack", "HPOR";
+
+dai-link-0 {
+link-name = "MultiMedia0";
+cpu {
+sound-dai = <_cpu 0>;
+};
+
+codec {
+sound-dai = < 0>;
+};
+};
+
+dai-link-1 {
+link-name = "MultiMedia1";
+unidirectional = <0>;
+cpu {
+sound-dai = <_cpu 1>;
+};
+
+codec {
+sound-dai = <>;
+};
+};
+};
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH] arm64: dts: qcom: sc7180: Add lpass cpu node for I2S driver

2020-07-16 Thread Cheng-Yi Chiang
From: Ajit Pandey 

Add the I2S controller node to sc7180 dtsi.
Add pinmux for pirmary and secondary I2S.

Signed-off-by: Ajit Pandey 
Signed-off-by: Cheng-Yi Chiang 
---
This patch depends on these patch series so it is not ready to be merged now.
- clk: qcom: Support for Low Power Audio Clocks on SC7180 
https://patchwork.kernel.org/cover/11664273/
- arm64: dts: qcom: sc7180: Add LPASS clock controller nodes 
https://patchwork.kernel.org/patch/11664303/
- ASoC: qcom: Add support for SC7180 lpass variant 
https://patchwork.kernel.org/cover/11650649/

 arch/arm64/boot/dts/qcom/sc7180.dtsi | 132 +++
 1 file changed, 132 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sc7180.dtsi 
b/arch/arm64/boot/dts/qcom/sc7180.dtsi
index 6eb14b6a47f5..2fe3bd89f950 100644
--- a/arch/arm64/boot/dts/qcom/sc7180.dtsi
+++ b/arch/arm64/boot/dts/qcom/sc7180.dtsi
@@ -511,6 +511,34 @@ qusb2p_hstx_trim: hstx-trim-primary@25b {
};
};
 
+   lpass_cpu: lpass {
+   compatible = "qcom,lpass-cpu-sc7180";
+
+   reg = <0 0x62F0 0 0x29000>;
+   reg-names = "lpass-lpaif";
+
+   iommus = <_smmu 0x1020 0>;
+
+   power-domains = <_hm LPASS_CORE_HM_GDSCR>;
+
+   status = "disabled";
+
+   clocks = < GCC_LPASS_CFG_NOC_SWAY_CLK>,
+< LPASS_AUDIO_CORE_CORE_CLK>,
+< LPASS_AUDIO_CORE_EXT_MCLK0_CLK>,
+< 
LPASS_AUDIO_CORE_SYSNOC_MPORT_CORE_CLK>,
+< LPASS_AUDIO_CORE_LPAIF_PRI_IBIT_CLK>,
+< LPASS_AUDIO_CORE_LPAIF_SEC_IBIT_CLK>;
+
+   clock-names = "noc", "audio-core", "mclk0", 
"sysnoc_mport",
+ "pri_ibit", "sec_ibit";
+
+   #sound-dai-cells = <1>;
+
+   interrupts = <0 160 IRQ_TYPE_LEVEL_HIGH>;
+   interrupt-names = "lpass-irq-lpaif";
+   };
+
sdhc_1: sdhci@7c4000 {
compatible = "qcom,sc7180-sdhci", "qcom,sdhci-msm-v5";
reg = <0 0x7c4000 0 0x1000>,
@@ -1357,6 +1385,110 @@ pinmux {
};
};
 
+   sec_mi2s_active: sec-mi2s-active {
+   pinmux {
+   pins = "gpio49";
+   function = "mi2s_1";
+   };
+
+   pinconf {
+   pins = "gpio49";
+   drive-strength = <8>;
+   bias-pull-up;
+   };
+   };
+
+   sec_mi2s_ws_active: sec-mi2s-ws-active {
+   pinmux {
+   pins = "gpio50";
+   function = "mi2s_1";
+   };
+
+   pinconf {
+   pins = "gpio50";
+   drive-strength = <8>;
+   bias-pull-up;
+   };
+   };
+
+   sec_mi2s_dout_active: sec-mi2s-dout-active {
+   pinmux {
+   pins = "gpio51";
+   function = "mi2s_1";
+   };
+
+   pinconf {
+   pins = "gpio51";
+   drive-strength = <8>;
+   bias-pull-up;
+   };
+   };
+
+   pri_mi2s_active: pri-mi2s-active {
+   pinmux {
+   pins = "gpio53";
+   function = "mi2s_0";
+   };
+
+   pinconf {
+   pins = "gpio53";
+   drive-strength = <8>;
+   bias-pull-up;
+   };
+   };
+
+   pri_mi2s_ws_active: pri-mi2s-ws-active {
+ 

Re: [PATCH] pinctrl: qcom: Handle broken PDC dual edge case on sc7180

2020-07-13 Thread Cheng-yi Chiang
On Thu, Jul 9, 2020 at 5:16 AM Douglas Anderson  wrote:
>
> As per Qualcomm, there is a PDC hardware issue (with the specific IP
> rev that exists on sc7180) that causes the PDC not to work properly
> when configured to handle dual edges.
>
> Let's work around this by emulating only ever letting our parent see
> requests for single edge interrupts on affected hardware.
>
> Fixes: e35a6ae0eb3a ("pinctrl/msm: Setup GPIO chip in hierarchy")
> Signed-off-by: Douglas Anderson 

Tested-by: Cheng-Yi Chiang 

>
> ---
> As far as I can tell everything here should work and the limited
> testing I'm able to give it shows that, in fact, I can detect both
> edges.
>
> Please give this an extra thorough review since it's trying to find
> the exact right place to insert this code and I'm not massively
> familiar with all the frameworks.
>
> If someone has hardware where it's easy to stress test this that'd be
> wonderful too.  The board I happen to have in front of me doesn't have
> any easy-to-toggle GPIOs where I can just poke a button or a switch to
> generate edges.  My testing was done by hacking the "write protect"
> GPIO on my board into gpio-keys as a dual-edge interrupt and then
> sending commands to our security chip to toggle it--not exactly great
> for testing to make sure there are no race conditions if the interrupt
> bounces a lot.
>
>  drivers/pinctrl/qcom/pinctrl-msm.c| 80 +++
>  drivers/pinctrl/qcom/pinctrl-msm.h|  4 ++
>  drivers/pinctrl/qcom/pinctrl-sc7180.c |  1 +
>  3 files changed, 85 insertions(+)
>
> diff --git a/drivers/pinctrl/qcom/pinctrl-msm.c 
> b/drivers/pinctrl/qcom/pinctrl-msm.c
> index 83b7d64bc4c1..45ca09ebb7b3 100644
> --- a/drivers/pinctrl/qcom/pinctrl-msm.c
> +++ b/drivers/pinctrl/qcom/pinctrl-msm.c
> @@ -860,6 +860,79 @@ static void msm_gpio_irq_ack(struct irq_data *d)
> raw_spin_unlock_irqrestore(>lock, flags);
>  }
>
> +/**
> + * msm_gpio_update_dual_edge_parent() - Prime next edge for IRQs handled by 
> parent.
> + * @d: The irq dta.
> + *
> + * This is much like msm_gpio_update_dual_edge_pos() but for IRQs that are
> + * normally handled by the parent irqchip.  The logic here is slightly
> + * different due to what's easy to do with our parent, but in principle it's
> + * the same.
> + */
> +static void msm_gpio_update_dual_edge_parent(struct irq_data *d)
> +{
> +   struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
> +   struct msm_pinctrl *pctrl = gpiochip_get_data(gc);
> +   const struct msm_pingroup *g = >soc->groups[d->hwirq];
> +   unsigned long flags;
> +   int loop_limit = 100;
> +   unsigned int val;
> +   unsigned int type;
> +
> +   /* Read the value and make a guess about what edge we need to catch */
> +   val = msm_readl_io(pctrl, g) & BIT(g->in_bit);
> +   type = val ? IRQ_TYPE_EDGE_FALLING : IRQ_TYPE_EDGE_RISING;
> +
> +   raw_spin_lock_irqsave(>lock, flags);
> +   do {
> +   /* Set the parent to catch the next edge */
> +   irq_chip_set_type_parent(d, type);
> +
> +   /*
> +* Possibly the line changed between when we last read "val"
> +* (and decided what edge we needed) and when set the edge.
> +* If the value didn't change (or changed and then changed
> +* back) then we're done.
> +*/
> +   val = msm_readl_io(pctrl, g) & BIT(g->in_bit);
> +   if (type == IRQ_TYPE_EDGE_RISING) {
> +   if (!val)
> +   break;
> +   type = IRQ_TYPE_EDGE_FALLING;
> +   } else if (type == IRQ_TYPE_EDGE_FALLING) {
> +   if (val)
> +   break;
> +   type = IRQ_TYPE_EDGE_RISING;
> +   }
> +   } while (loop_limit-- > 0);
> +   raw_spin_unlock_irqrestore(>lock, flags);
> +
> +   if (!loop_limit)
> +   dev_err(pctrl->dev, "dual-edge irq failed to stabilize\n");
> +}
> +
> +void msm_gpio_handle_dual_edge_parent_irq(struct irq_desc *desc)
> +{
> +   struct irq_data *d = >irq_data;
> +
> +   /* Make sure we're primed for the next edge */
> +   msm_gpio_update_dual_edge_parent(d);
> +
> +   /* Pass on to the normal interrupt handler */
> +   handle_fasteoi_irq(desc);
> +}
> +
> +static bool msm_gpio_needs_dual_edge_parent_workaround(struct irq_data *d,
> +  unsigned int type)
> +{
> +   struct gp

Re: [PATCH] firmware: vpd: Add an interface to read VPD value

2019-10-13 Thread Cheng-yi Chiang
On Wed, Oct 9, 2019 at 10:05 PM Srinivas Kandagatla
 wrote:
>
>
>
> On 08/10/2019 16:14, Stephen Boyd wrote:
> >> 3) As my use case does not use device tree, it is hard for ASoC
> >> machine to access nvmem device. I am wondering if I can use
> >> nvm_cell_lookup so machine driver can find the nvmem device using a
> >> con_id. But currently the cell lookup API requires a matched device,
> >> which does not fit my usage because there will be different machine
> >> drivers requesting the value.
> >> I think I can still workaround this by adding the lookup table in
> >> machine driver. This would seem to be a bit weird because I found that
> >> most lookup table is added in provider side, not consumer side. Not
> >> sure if this is logically correct.
> > Maybe Srini has some input here. It looks like your main concern is
> > consumer to provider mapping?
> >
>
> In non-DT setup, there are various ways to lookup nvmem provider.
>
> 1> nvmem_device_get()/put() using provider devid/name. I think you
> should be able to use this in your case.
> 2> nvmem_register_notifier() which notifies when nvmem provider is added
> to system.
> 3> nvmem_device_find() with own match function this will be merged in
> next window (https://lkml.org/lkml/2019/10/3/215)
>
>
> If none of these are of any help, could explain what exactly are you
> looking for w.r.t nvmem to be able to move to what Stephen Boyd suggested?
>
> --srini
>

Hi Stephen, Mark and Srinivas,
Thank you all for the suggestions.
In my non-DT setup, I have been working on coreboot changes to prepare
data in _DSD following suggestion in
https://patchwork.kernel.org/patch/11179237
The basic idea is that codec driver should just get data it needs from
device property.
The coreboot approach works in my local setup, but I have not sent the
change to coreboot upstream yet.
If that path work, then the change needed in kernel will be much simpler.

In the future, there might be DT setup use case, and I think it should
be doable for VPD to register a nvmem device, and let codec driver
gets the property.
But I would drop this path for now.
Thanks!


Re: [PATCH v2] firmware: vpd: Add an interface to read VPD value

2019-10-08 Thread Cheng-yi Chiang
On Tue, Oct 8, 2019 at 8:06 PM Greg Kroah-Hartman
 wrote:
>
> On Tue, Oct 08, 2019 at 06:11:44PM +0800, Cheng-Yi Chiang wrote:
> > Add an interface for other driver to query VPD value.
> > This will be used for ASoC machine driver to query calibration
> > data stored in VPD for smart amplifier speaker resistor
> > calibration.
> >
> > The example usage in ASoC machine driver is like:
> >
> > #define DSM_CALIB_KEY "dsm_calib"
> > static int load_calibration_data(struct cml_card_private *ctx) {
> > char *data = NULL;
> > int ret;
> > u32 value_len;
> >
> > /* Read calibration data from VPD. */
> > ret = vpd_attribute_read(1, DSM_CALIB_KEY,
> >         (u8 **), _len);
> >
> > /* Parsing of this string...*/
> > }
> >
> >
> > Signed-off-by: Cheng-Yi Chiang 
> > ---
>
> I can't take this patch without a real user of this function in the
> kernel tree at the same time.  Please submit it as part of a patch
> series with that change as well.
>

Hi Greg,
I see.
There is an ongoing discussion with Mark in

https://patchwork.kernel.org/patch/11179237/

I will resend this after machine driver is merged, and after codec
driver change get sorted out there.
Thanks!

> thanks,
>
> greg k-h


[PATCH v2] firmware: vpd: Add an interface to read VPD value

2019-10-08 Thread Cheng-Yi Chiang
Add an interface for other driver to query VPD value.
This will be used for ASoC machine driver to query calibration
data stored in VPD for smart amplifier speaker resistor
calibration.

The example usage in ASoC machine driver is like:

#define DSM_CALIB_KEY "dsm_calib"
static int load_calibration_data(struct cml_card_private *ctx) {
char *data = NULL;
int ret;
u32 value_len;

/* Read calibration data from VPD. */
ret = vpd_attribute_read(1, DSM_CALIB_KEY,
(u8 **), _len);

/* Parsing of this string...*/
}


Signed-off-by: Cheng-Yi Chiang 
---
Change from v1 to v2:
- Use kmemdup to copy data.
- Set value_len according to bin_attr.size.
- Check return value of kmemdup.
- Rename the function to vpd_attribute_read.
- Add docstrings for the function.
- Returns -ENOENT when the key is not found.
- Use EXPORT_SYMBOL_GPL.

Note:

The user of this API is in ASoC machine driver cml_rt1011_rt5682.
It is pending on the initial machine driver change

https://patchwork.kernel.org/patch/11161145/

and the codec driver change to provide API to do calibration.

https://patchwork.kernel.org/patch/11179237/

The draft patch of machine driver change which uses this API is at

https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1838091



 drivers/firmware/google/vpd.c  | 31 ++
 include/linux/firmware/google/google_vpd.h | 18 +
 2 files changed, 49 insertions(+)
 create mode 100644 include/linux/firmware/google/google_vpd.h

diff --git a/drivers/firmware/google/vpd.c b/drivers/firmware/google/vpd.c
index db0812263d46..c2be0e756402 100644
--- a/drivers/firmware/google/vpd.c
+++ b/drivers/firmware/google/vpd.c
@@ -65,6 +65,37 @@ static ssize_t vpd_attrib_read(struct file *filp, struct 
kobject *kobp,
   info->bin_attr.size);
 }
 
+/**
+ * vpd_attribute_read - Read VPD value for a key.
+ * @ro: True for RO section. False for RW section.
+ * @key: A string for key.
+ * @value: Where to write the VPD value on success. The caller
+ * must free the memory.
+ * @value_len: The length of value in bytes.
+ *
+ * Returns 0 on success, -ENOENT when the key is not found, and
+ * -ENOMEM when failed to allocate memory for value.
+ */
+int vpd_attribute_read(bool ro, const char *key,
+  u8 **value, u32 *value_len)
+{
+   struct vpd_attrib_info *info;
+   struct vpd_section *sec = ro ? _vpd : _vpd;
+
+   list_for_each_entry(info, >attribs, list) {
+   if (strcmp(info->key, key) == 0) {
+   *value = kmemdup(info->value, info->bin_attr.size,
+GFP_KERNEL);
+   if (!*value)
+   return -ENOMEM;
+   *value_len = info->bin_attr.size;
+   return 0;
+   }
+   }
+   return -ENOENT;
+}
+EXPORT_SYMBOL_GPL(vpd_attribute_read);
+
 /*
  * vpd_section_check_key_name()
  *
diff --git a/include/linux/firmware/google/google_vpd.h 
b/include/linux/firmware/google/google_vpd.h
new file mode 100644
index ..4364eaa4e1e3
--- /dev/null
+++ b/include/linux/firmware/google/google_vpd.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Google VPD interface.
+ *
+ * Copyright 2019 Google Inc.
+ */
+
+/* Interface for reading VPD value on Chrome platform. */
+
+#ifndef __GOOGLE_VPD_H
+#define __GOOGLE_VPD_H
+
+#include 
+
+int vpd_attribute_read(bool ro, const char *key,
+  u8 **value, u32 *value_len);
+
+#endif  /* __GOOGLE_VPD_H */
-- 
2.23.0.581.g78d2f28ef7-goog



Re: [PATCH] firmware: vpd: Add an interface to read VPD value

2019-10-07 Thread Cheng-yi Chiang
On Mon, Oct 7, 2019 at 11:35 PM Stephen Boyd  wrote:
>
> Quoting Cheng-yi Chiang (2019-10-07 06:58:41)
> >
> > Hi Guenter,
> > Thanks for the quick review.
> > I'll update accordingly in v2.
>
> I'd prefer this use the nvmem framework which already handles many of
> the requirements discussed here. Implement an nvmem provider and figure
> out how to wire that up to the kernel users. Also, please include a user
> of the added support, otherwise it is impossible to understand how this
> code is used.
>
Hi Stephen,
Thanks for the suggestion.
My usage is for Intel machine driver to read a string for speaker calibration.

https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1838091/4/sound/soc/intel/boards/cml_rt1011_rt5682.c#325

Based on the comments in this thread, its usage would look like

#define DSM_CALIB_KEY "dsm_calib"
static int load_calibration_data(struct cml_card_private *ctx) {
  char *data = NULL;
  int ret;
  u32 value_len;

  /* Read calibration data from VPD. */
  ret = vpd_attribute_read(1, DSM_CALIB_KEY,
 (u8 **), _len);

  /* Parsing of this string...*/
}

It is currently pending on unmerged machine driver cml_rt1011_rt5682.c
in ASoC so I can not post it for review for now.

As for nvmem approach, I looked into examples of nvmem usage, and have
a rough idea how to do this.

1) In vpd.c, as it parses key and value in the VPD section, add nvmem cell  with
{
.name=key,
.offset=consumed,   // need some change in vpd_decodec.c to get the
offset of value in the section.
.bytes=value
}
Implement read function with vpd_section as context.

2) In vpd.c, register an nvm_device using devm_nvmem_register in
coreboot_driver's probe function vpd_probe.

3) As my use case does not use device tree, it is hard for ASoC
machine to access nvmem device. I am wondering if I can use
nvm_cell_lookup so machine driver can find the nvmem device using a
con_id. But currently the cell lookup API requires a matched device,
which does not fit my usage because there will be different machine
drivers requesting the value.
I think I can still workaround this by adding the lookup table in
machine driver. This would seem to be a bit weird because I found that
most lookup table is added in provider side, not consumer side. Not
sure if this is logically correct.

IMO the nvmem approach would create more complexity to support this
simple usage. Plus, the underlying assumption of accessing data with
offset in a buffer does not fit well with the already parsed VPD
values in a list of vpd_attrib_info. But if you strongly feel that
this is a better approach I can work toward this.

Thanks!


Re: [PATCH] firmware: vpd: Add an interface to read VPD value

2019-10-07 Thread Cheng-yi Chiang
On Mon, Oct 7, 2019 at 8:27 PM Guenter Roeck  wrote:
>
> On 10/7/19 1:03 AM, Tzung-Bi Shih wrote:
> > On Mon, Oct 7, 2019 at 3:16 PM Cheng-Yi Chiang  
> > wrote:
> >>
> >> Add an interface for other driver to query VPD value.
> >> This will be used for ASoC machine driver to query calibration
> >> data stored in VPD for smart amplifier speaker resistor
> >> calibration.
> >>
> >> Signed-off-by: Cheng-Yi Chiang 
> >> ---
> >>   drivers/firmware/google/vpd.c  | 16 
> >>   include/linux/firmware/google/google_vpd.h | 18 ++
> >>   2 files changed, 34 insertions(+)
> >>   create mode 100644 include/linux/firmware/google/google_vpd.h
> >>
> >> diff --git a/drivers/firmware/google/vpd.c b/drivers/firmware/google/vpd.c
> >> index db0812263d46..71e9d2da63be 100644
> >> --- a/drivers/firmware/google/vpd.c
> >> +++ b/drivers/firmware/google/vpd.c
> >> @@ -65,6 +65,22 @@ static ssize_t vpd_attrib_read(struct file *filp, 
> >> struct kobject *kobp,
> >> info->bin_attr.size);
> >>   }
> >>
> >> +int vpd_attribute_read_value(bool ro, const char *key,
> >> +char **value, u32 value_len)
>
> FWIW, I don't think the "_value" in this function name adds any value,
> unless there is going to be some other read function.
ACK
>
> The API should be documented, and state clearly that the caller must release
> the returned value.
ACK
>
> >> +{
> >> +   struct vpd_attrib_info *info;
> >> +   struct vpd_section *sec = ro ? _vpd : _vpd;
> >> +
> >> +   list_for_each_entry(info, >attribs, list) {
> >> +   if (strcmp(info->key, key) == 0) {
> >> +   *value = kstrndup(info->value, value_len, 
> >> GFP_KERNEL);
> >
> > Value is not necessary a NULL-terminated string.
> > kmalloc(info->bin_attr.size) and memcpy(...) would make the most
> > sense.
> >
> kmemdup() ?
ACK
>
> > The value_len parameter makes less sense.  It seems the caller knows
> > the length of the value in advance.
> > Suggest to change the value_len to report the length of value.  I.e.
> > *value_len = info->bin_attr.size;
> >  > Also please check the return value for memory allocation-like
> > functions (e.g. kstrndup, kmalloc) so that *value won't be NULL but
> > the function returned 0.
> >
> >> +   return 0;
> >> +   }
> >> +   }
> >> +   return -EINVAL;
>
> Maybe something like -ENOENT would be more appropriate here.
>
ACK
> >> +}
> >> +EXPORT_SYMBOL(vpd_attribute_read_value);
> >> +
>
> I would suggest to use EXPORT_SYMBOL_GPL().
>
ACK

Hi Guenter,
Thanks for the quick review.
I'll update accordingly in v2.

> >>   /*
> >>* vpd_section_check_key_name()
> >>*
> >> diff --git a/include/linux/firmware/google/google_vpd.h 
> >> b/include/linux/firmware/google/google_vpd.h
> >> new file mode 100644
> >> index ..6f1160f28af8
> >> --- /dev/null
> >> +++ b/include/linux/firmware/google/google_vpd.h
> >> @@ -0,0 +1,18 @@
> >> +/* SPDX-License-Identifier: GPL-2.0 */
> >> +/*
> >> + * Google VPD interface.
> >> + *
> >> + * Copyright 2019 Google Inc.
> >> + */
> >> +
> >> +/* Interface for reading VPD value on Chrome platform. */
> >> +
> >> +#ifndef __GOOGLE_VPD_H
> >> +#define __GOOGLE_VPD_H
> >> +
> >> +#include 
> >> +
> >> +int vpd_attribute_read_value(bool ro, const char *key,
> >> +char **value, u32 value_len);
> >> +
> >> +#endif  /* __GOOGLE_VPD_H */
> >> --
> >> 2.23.0.581.g78d2f28ef7-goog
> >>
> >
>


Re: [PATCH] firmware: vpd: Add an interface to read VPD value

2019-10-07 Thread Cheng-yi Chiang
On Mon, Oct 7, 2019 at 4:03 PM Tzung-Bi Shih  wrote:
>
> On Mon, Oct 7, 2019 at 3:16 PM Cheng-Yi Chiang  wrote:
> >
> > Add an interface for other driver to query VPD value.
> > This will be used for ASoC machine driver to query calibration
> > data stored in VPD for smart amplifier speaker resistor
> > calibration.
> >
> > Signed-off-by: Cheng-Yi Chiang 
> > ---
> >  drivers/firmware/google/vpd.c  | 16 
> >  include/linux/firmware/google/google_vpd.h | 18 ++
> >  2 files changed, 34 insertions(+)
> >  create mode 100644 include/linux/firmware/google/google_vpd.h
> >
> > diff --git a/drivers/firmware/google/vpd.c b/drivers/firmware/google/vpd.c
> > index db0812263d46..71e9d2da63be 100644
> > --- a/drivers/firmware/google/vpd.c
> > +++ b/drivers/firmware/google/vpd.c
> > @@ -65,6 +65,22 @@ static ssize_t vpd_attrib_read(struct file *filp, struct 
> > kobject *kobp,
> >info->bin_attr.size);
> >  }
> >
> > +int vpd_attribute_read_value(bool ro, const char *key,
> > +char **value, u32 value_len)
> > +{
> > +   struct vpd_attrib_info *info;
> > +   struct vpd_section *sec = ro ? _vpd : _vpd;
> > +
> > +   list_for_each_entry(info, >attribs, list) {
> > +   if (strcmp(info->key, key) == 0) {
> > +   *value = kstrndup(info->value, value_len, 
> > GFP_KERNEL);
>
> Value is not necessary a NULL-terminated string.
> kmalloc(info->bin_attr.size) and memcpy(...) would make the most
> sense.
>
> The value_len parameter makes less sense.  It seems the caller knows
> the length of the value in advance.
> Suggest to change the value_len to report the length of value.  I.e.
> *value_len = info->bin_attr.size;
>
> Also please check the return value for memory allocation-like
> functions (e.g. kstrndup, kmalloc) so that *value won't be NULL but
> the function returned 0.

Thanks for the review.
I will them in v2.

>
> > +   return 0;
> > +   }
> > +   }
> > +   return -EINVAL;
> > +}
> > +EXPORT_SYMBOL(vpd_attribute_read_value);
> > +
> >  /*
> >   * vpd_section_check_key_name()
> >   *
> > diff --git a/include/linux/firmware/google/google_vpd.h 
> > b/include/linux/firmware/google/google_vpd.h
> > new file mode 100644
> > index ..6f1160f28af8
> > --- /dev/null
> > +++ b/include/linux/firmware/google/google_vpd.h
> > @@ -0,0 +1,18 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +/*
> > + * Google VPD interface.
> > + *
> > + * Copyright 2019 Google Inc.
> > + */
> > +
> > +/* Interface for reading VPD value on Chrome platform. */
> > +
> > +#ifndef __GOOGLE_VPD_H
> > +#define __GOOGLE_VPD_H
> > +
> > +#include 
> > +
> > +int vpd_attribute_read_value(bool ro, const char *key,
> > +char **value, u32 value_len);
> > +
> > +#endif  /* __GOOGLE_VPD_H */
> > --
> > 2.23.0.581.g78d2f28ef7-goog
> >


[PATCH] firmware: vpd: Add an interface to read VPD value

2019-10-07 Thread Cheng-Yi Chiang
Add an interface for other driver to query VPD value.
This will be used for ASoC machine driver to query calibration
data stored in VPD for smart amplifier speaker resistor
calibration.

Signed-off-by: Cheng-Yi Chiang 
---
 drivers/firmware/google/vpd.c  | 16 
 include/linux/firmware/google/google_vpd.h | 18 ++
 2 files changed, 34 insertions(+)
 create mode 100644 include/linux/firmware/google/google_vpd.h

diff --git a/drivers/firmware/google/vpd.c b/drivers/firmware/google/vpd.c
index db0812263d46..71e9d2da63be 100644
--- a/drivers/firmware/google/vpd.c
+++ b/drivers/firmware/google/vpd.c
@@ -65,6 +65,22 @@ static ssize_t vpd_attrib_read(struct file *filp, struct 
kobject *kobp,
   info->bin_attr.size);
 }
 
+int vpd_attribute_read_value(bool ro, const char *key,
+char **value, u32 value_len)
+{
+   struct vpd_attrib_info *info;
+   struct vpd_section *sec = ro ? _vpd : _vpd;
+
+   list_for_each_entry(info, >attribs, list) {
+   if (strcmp(info->key, key) == 0) {
+   *value = kstrndup(info->value, value_len, GFP_KERNEL);
+   return 0;
+   }
+   }
+   return -EINVAL;
+}
+EXPORT_SYMBOL(vpd_attribute_read_value);
+
 /*
  * vpd_section_check_key_name()
  *
diff --git a/include/linux/firmware/google/google_vpd.h 
b/include/linux/firmware/google/google_vpd.h
new file mode 100644
index ..6f1160f28af8
--- /dev/null
+++ b/include/linux/firmware/google/google_vpd.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Google VPD interface.
+ *
+ * Copyright 2019 Google Inc.
+ */
+
+/* Interface for reading VPD value on Chrome platform. */
+
+#ifndef __GOOGLE_VPD_H
+#define __GOOGLE_VPD_H
+
+#include 
+
+int vpd_attribute_read_value(bool ro, const char *key,
+char **value, u32 value_len);
+
+#endif  /* __GOOGLE_VPD_H */
-- 
2.23.0.581.g78d2f28ef7-goog



[PATCH v7 1/4] drm: bridge: dw-hdmi: Report connector status using callback

2019-09-19 Thread Cheng-Yi Chiang
Allow codec driver register callback function for plug event.

The callback registration flow:
dw-hdmi <--- hw-hdmi-i2s-audio <--- hdmi-codec

dw-hdmi-i2s-audio implements hook_plugged_cb op
so codec driver can register the callback.

dw-hdmi exports a function dw_hdmi_set_plugged_cb so platform device
can register the callback.

When connector plug/unplug event happens, report this event using the
callback.

Make sure that audio and drm are using the single source of truth for
connector status.

Signed-off-by: Cheng-Yi Chiang 
---
 .../drm/bridge/synopsys/dw-hdmi-i2s-audio.c   | 11 +
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 41 ++-
 include/drm/bridge/dw_hdmi.h  |  4 ++
 3 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c 
b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c
index 20f4f92dd866..d7e65c869415 100644
--- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c
+++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c
@@ -160,12 +160,23 @@ static int dw_hdmi_i2s_get_dai_id(struct 
snd_soc_component *component,
return -EINVAL;
 }
 
+static int dw_hdmi_i2s_hook_plugged_cb(struct device *dev, void *data,
+  hdmi_codec_plugged_cb fn,
+  struct device *codec_dev)
+{
+   struct dw_hdmi_i2s_audio_data *audio = data;
+   struct dw_hdmi *hdmi = audio->hdmi;
+
+   return dw_hdmi_set_plugged_cb(hdmi, fn, codec_dev);
+}
+
 static struct hdmi_codec_ops dw_hdmi_i2s_ops = {
.hw_params  = dw_hdmi_i2s_hw_params,
.audio_startup  = dw_hdmi_i2s_audio_startup,
.audio_shutdown = dw_hdmi_i2s_audio_shutdown,
.get_eld= dw_hdmi_i2s_get_eld,
.get_dai_id = dw_hdmi_i2s_get_dai_id,
+   .hook_plugged_cb = dw_hdmi_i2s_hook_plugged_cb,
 };
 
 static int snd_dw_hdmi_probe(struct platform_device *pdev)
diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c 
b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
index aa7efd4da1c8..7ffe8ed675ff 100644
--- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
+++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
@@ -193,6 +193,10 @@ struct dw_hdmi {
 
struct mutex cec_notifier_mutex;
struct cec_notifier *cec_notifier;
+
+   hdmi_codec_plugged_cb plugged_cb;
+   struct device *codec_dev;
+   enum drm_connector_status last_connector_result;
 };
 
 #define HDMI_IH_PHY_STAT0_RX_SENSE \
@@ -217,6 +221,28 @@ static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int 
offset)
return val;
 }
 
+static void handle_plugged_change(struct dw_hdmi *hdmi, bool plugged)
+{
+   if (hdmi->plugged_cb && hdmi->codec_dev)
+   hdmi->plugged_cb(hdmi->codec_dev, plugged);
+}
+
+int dw_hdmi_set_plugged_cb(struct dw_hdmi *hdmi, hdmi_codec_plugged_cb fn,
+  struct device *codec_dev)
+{
+   bool plugged;
+
+   mutex_lock(>mutex);
+   hdmi->plugged_cb = fn;
+   hdmi->codec_dev = codec_dev;
+   plugged = hdmi->last_connector_result == connector_status_connected;
+   handle_plugged_change(hdmi, plugged);
+   mutex_unlock(>mutex);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(dw_hdmi_set_plugged_cb);
+
 static void hdmi_modb(struct dw_hdmi *hdmi, u8 data, u8 mask, unsigned reg)
 {
regmap_update_bits(hdmi->regm, reg << hdmi->reg_shift, mask, data);
@@ -2183,6 +2209,7 @@ dw_hdmi_connector_detect(struct drm_connector *connector, 
bool force)
 {
struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi,
 connector);
+   enum drm_connector_status result;
 
mutex_lock(>mutex);
hdmi->force = DRM_FORCE_UNSPECIFIED;
@@ -2190,7 +2217,18 @@ dw_hdmi_connector_detect(struct drm_connector 
*connector, bool force)
dw_hdmi_update_phy_mask(hdmi);
mutex_unlock(>mutex);
 
-   return hdmi->phy.ops->read_hpd(hdmi, hdmi->phy.data);
+   result = hdmi->phy.ops->read_hpd(hdmi, hdmi->phy.data);
+
+   mutex_lock(>mutex);
+   if (result != hdmi->last_connector_result) {
+   dev_dbg(hdmi->dev, "read_hpd result: %d", result);
+   handle_plugged_change(hdmi,
+ result == connector_status_connected);
+   hdmi->last_connector_result = result;
+   }
+   mutex_unlock(>mutex);
+
+   return result;
 }
 
 static int dw_hdmi_connector_get_modes(struct drm_connector *connector)
@@ -2641,6 +2679,7 @@ __dw_hdmi_probe(struct platform_device *pdev,
hdmi->rxsense = true;
hdmi->phy_mask = (u8)~(HDMI_PHY_HPD | HDMI_PHY_RX_SENSE);
hdmi->mc_clkdis = 0x7f;
+   hdmi->last_connector_result = connector_status_disconnected;
 
mutex_init(>mutex);
mutex_init(>audio_mutex);
diff

[PATCH v7 3/4] ASoC: rockchip_max98090: Add dai_link for HDMI

2019-09-19 Thread Cheng-Yi Chiang
Use two dai_links. One for HDMI and one for max98090.
With this setup, audio can play to speaker and HDMI selectively.

Signed-off-by: Cheng-Yi Chiang 
---
 .../boot/dts/rk3288-veyron-analog-audio.dtsi  |   1 +
 sound/soc/rockchip/rockchip_max98090.c| 129 ++
 2 files changed, 103 insertions(+), 27 deletions(-)

diff --git a/arch/arm/boot/dts/rk3288-veyron-analog-audio.dtsi 
b/arch/arm/boot/dts/rk3288-veyron-analog-audio.dtsi
index 445270aa136e..51208d161d65 100644
--- a/arch/arm/boot/dts/rk3288-veyron-analog-audio.dtsi
+++ b/arch/arm/boot/dts/rk3288-veyron-analog-audio.dtsi
@@ -17,6 +17,7 @@
rockchip,hp-det-gpios = < RK_PA5 GPIO_ACTIVE_HIGH>;
rockchip,mic-det-gpios = < RK_PB3 GPIO_ACTIVE_LOW>;
rockchip,headset-codec = <>;
+   rockchip,hdmi-codec = <>;
};
 };
 
diff --git a/sound/soc/rockchip/rockchip_max98090.c 
b/sound/soc/rockchip/rockchip_max98090.c
index c5fc24675a33..6c217492bb30 100644
--- a/sound/soc/rockchip/rockchip_max98090.c
+++ b/sound/soc/rockchip/rockchip_max98090.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -41,6 +42,7 @@ static const struct snd_soc_dapm_widget rk_dapm_widgets[] = {
SND_SOC_DAPM_MIC("Headset Mic", NULL),
SND_SOC_DAPM_MIC("Int Mic", NULL),
SND_SOC_DAPM_SPK("Speaker", NULL),
+   SND_SOC_DAPM_LINE("HDMI", NULL),
 };
 
 static const struct snd_soc_dapm_route rk_audio_map[] = {
@@ -52,6 +54,7 @@ static const struct snd_soc_dapm_route rk_audio_map[] = {
{"Headphone", NULL, "HPR"},
{"Speaker", NULL, "SPKL"},
{"Speaker", NULL, "SPKR"},
+   {"HDMI", NULL, "TX"},
 };
 
 static const struct snd_kcontrol_new rk_mc_controls[] = {
@@ -59,6 +62,7 @@ static const struct snd_kcontrol_new rk_mc_controls[] = {
SOC_DAPM_PIN_SWITCH("Headset Mic"),
SOC_DAPM_PIN_SWITCH("Int Mic"),
SOC_DAPM_PIN_SWITCH("Speaker"),
+   SOC_DAPM_PIN_SWITCH("HDMI"),
 };
 
 static int rk_aif1_hw_params(struct snd_pcm_substream *substream,
@@ -92,38 +96,63 @@ static int rk_aif1_hw_params(struct snd_pcm_substream 
*substream,
 
ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
 SND_SOC_CLOCK_OUT);
-   if (ret < 0) {
-   dev_err(codec_dai->dev, "Can't set codec clock %d\n", ret);
+   if (ret) {
+   dev_err(cpu_dai->dev, "Can't set cpu dai clock %d\n", ret);
return ret;
}
 
+   /* HDMI codec dai does not need to set sysclk. */
+   if (!strcmp(rtd->dai_link->name, "HDMI"))
+   return 0;
+
ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
 SND_SOC_CLOCK_IN);
-   if (ret < 0) {
-   dev_err(codec_dai->dev, "Can't set codec clock %d\n", ret);
+   if (ret) {
+   dev_err(codec_dai->dev, "Can't set codec dai clock %d\n", ret);
return ret;
}
 
-   return ret;
+   return 0;
 }
 
 static const struct snd_soc_ops rk_aif1_ops = {
.hw_params = rk_aif1_hw_params,
 };
 
-SND_SOC_DAILINK_DEFS(hifi,
-   DAILINK_COMP_ARRAY(COMP_EMPTY()),
-   DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "HiFi")),
-   DAILINK_COMP_ARRAY(COMP_EMPTY()));
-
-static struct snd_soc_dai_link rk_dailink = {
-   .name = "max98090",
-   .stream_name = "Audio",
-   .ops = _aif1_ops,
-   /* set max98090 as slave */
-   .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
-   SND_SOC_DAIFMT_CBS_CFS,
-   SND_SOC_DAILINK_REG(hifi),
+SND_SOC_DAILINK_DEFS(analog,
+DAILINK_COMP_ARRAY(COMP_EMPTY()),
+DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "HiFi")),
+DAILINK_COMP_ARRAY(COMP_EMPTY()));
+
+SND_SOC_DAILINK_DEFS(hdmi,
+DAILINK_COMP_ARRAY(COMP_EMPTY()),
+DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "i2s-hifi")),
+DAILINK_COMP_ARRAY(COMP_EMPTY()));
+
+enum {
+   DAILINK_MAX98090,
+   DAILINK_HDMI,
+};
+
+/* max98090 and HDMI codec dai_link */
+static struct snd_soc_dai_link rk_dailinks[] = {
+   [DAILINK_MAX98090] = {
+   .name = "max98090",
+   .stream_name = "Analog",
+   .ops = _aif1_ops,
+   /* set max98090 as slave */
+   .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+   SND_SOC_DAIFMT_CBS_CFS,
+   SND_SOC_DAILINK_REG(analog),
+   },
+   [DAILINK_HDMI] = {
+   .name = "HDMI",
+   .stream_name = &qu

[PATCH v7 0/4] Add HDMI jack support on RK3288

2019-09-19 Thread Cheng-Yi Chiang
This patch series supports HDMI jack reporting on RK3288, which uses
DRM dw-hdmi driver and hdmi-codec codec driver.

The previous discussion about reporting jack status using hdmi-notifier
and drm_audio_component is at

https://lore.kernel.org/patchwork/patch/1083027/

The new approach is to use a callback mechanism that is
specific to hdmi-codec.

The dependent change on hdmi-codec.c

https://patchwork.kernel.org/patch/11047447

has been picked up by Mark Brown in ASoC tree for-5.4 branch.

Changes from v6 to v7:

1. rockchip_max98090: Use phandle of HDMI from DTS to find
   codec_dai. With this we don't need to set fixed id for the
   created hdmi-audio-codec device.

Cheng-Yi Chiang (4):
  drm: bridge: dw-hdmi: Report connector status using callback
  ASoC: rockchip-max98090: Add description for rockchip,hdmi-codec
  ASoC: rockchip_max98090: Add dai_link for HDMI
  ASoC: rockchip_max98090: Add HDMI jack support

 .../bindings/sound/rockchip-max98090.txt  |   2 +
 .../boot/dts/rk3288-veyron-analog-audio.dtsi  |   1 +
 .../drm/bridge/synopsys/dw-hdmi-i2s-audio.c   |  11 ++
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c |  41 -
 include/drm/bridge/dw_hdmi.h  |   4 +
 sound/soc/rockchip/Kconfig|   3 +-
 sound/soc/rockchip/rockchip_max98090.c| 149 ++
 7 files changed, 182 insertions(+), 29 deletions(-)

-- 
2.23.0.237.gc6a4ce50a0-goog



[PATCH v6 4/4] ASoC: rockchip_max98090: Add HDMI jack support

2019-09-18 Thread Cheng-Yi Chiang
In machine driver, create a jack and let hdmi-codec report jack status.

Signed-off-by: Cheng-Yi Chiang 
---
 sound/soc/rockchip/Kconfig |  3 ++-
 sound/soc/rockchip/rockchip_max98090.c | 20 
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/sound/soc/rockchip/Kconfig b/sound/soc/rockchip/Kconfig
index b43657e6e655..d610b553ea3b 100644
--- a/sound/soc/rockchip/Kconfig
+++ b/sound/soc/rockchip/Kconfig
@@ -40,9 +40,10 @@ config SND_SOC_ROCKCHIP_MAX98090
select SND_SOC_ROCKCHIP_I2S
select SND_SOC_MAX98090
select SND_SOC_TS3A227E
+   select SND_SOC_HDMI_CODEC
help
  Say Y or M here if you want to add support for SoC audio on Rockchip
- boards using the MAX98090 codec, such as Veyron.
+ boards using the MAX98090 codec and HDMI codec, such as Veyron.
 
 config SND_SOC_ROCKCHIP_RT5645
tristate "ASoC support for Rockchip boards using a RT5645/RT5650 codec"
diff --git a/sound/soc/rockchip/rockchip_max98090.c 
b/sound/soc/rockchip/rockchip_max98090.c
index c82948e383da..c81c4acda917 100644
--- a/sound/soc/rockchip/rockchip_max98090.c
+++ b/sound/soc/rockchip/rockchip_max98090.c
@@ -134,6 +134,25 @@ enum {
DAILINK_HDMI,
 };
 
+static struct snd_soc_jack rk_hdmi_jack;
+
+static int rk_hdmi_init(struct snd_soc_pcm_runtime *runtime)
+{
+   struct snd_soc_card *card = runtime->card;
+   struct snd_soc_component *component = runtime->codec_dai->component;
+   int ret;
+
+   /* enable jack detection */
+   ret = snd_soc_card_jack_new(card, "HDMI Jack", SND_JACK_LINEOUT,
+   _hdmi_jack, NULL, 0);
+   if (ret) {
+   dev_err(card->dev, "Can't new HDMI Jack %d\n", ret);
+   return ret;
+   }
+
+   return hdmi_codec_set_jack_detect(component, _hdmi_jack);
+}
+
 /* max98090 and HDMI codec dai_link */
 static struct snd_soc_dai_link rk_dailinks[] = {
[DAILINK_MAX98090] = {
@@ -151,6 +170,7 @@ static struct snd_soc_dai_link rk_dailinks[] = {
.ops = _aif1_ops,
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
SND_SOC_DAIFMT_CBS_CFS,
+   .init = rk_hdmi_init,
SND_SOC_DAILINK_REG(hdmi),
}
 };
-- 
2.23.0.237.gc6a4ce50a0-goog



[PATCH v6 3/4] ASoC: rockchip_max98090: Add dai_link for HDMI

2019-09-18 Thread Cheng-Yi Chiang
Use two dai_links. One for HDMI and one for max98090.
With this setup, audio can play to speaker and HDMI selectively.

Signed-off-by: Cheng-Yi Chiang 
---
 sound/soc/rockchip/rockchip_max98090.c | 96 --
 1 file changed, 73 insertions(+), 23 deletions(-)

diff --git a/sound/soc/rockchip/rockchip_max98090.c 
b/sound/soc/rockchip/rockchip_max98090.c
index c5fc24675a33..c82948e383da 100644
--- a/sound/soc/rockchip/rockchip_max98090.c
+++ b/sound/soc/rockchip/rockchip_max98090.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -41,6 +42,7 @@ static const struct snd_soc_dapm_widget rk_dapm_widgets[] = {
SND_SOC_DAPM_MIC("Headset Mic", NULL),
SND_SOC_DAPM_MIC("Int Mic", NULL),
SND_SOC_DAPM_SPK("Speaker", NULL),
+   SND_SOC_DAPM_LINE("HDMI", NULL),
 };
 
 static const struct snd_soc_dapm_route rk_audio_map[] = {
@@ -52,6 +54,7 @@ static const struct snd_soc_dapm_route rk_audio_map[] = {
{"Headphone", NULL, "HPR"},
{"Speaker", NULL, "SPKL"},
{"Speaker", NULL, "SPKR"},
+   {"HDMI", NULL, "TX"},
 };
 
 static const struct snd_kcontrol_new rk_mc_controls[] = {
@@ -59,6 +62,7 @@ static const struct snd_kcontrol_new rk_mc_controls[] = {
SOC_DAPM_PIN_SWITCH("Headset Mic"),
SOC_DAPM_PIN_SWITCH("Int Mic"),
SOC_DAPM_PIN_SWITCH("Speaker"),
+   SOC_DAPM_PIN_SWITCH("HDMI"),
 };
 
 static int rk_aif1_hw_params(struct snd_pcm_substream *substream,
@@ -92,38 +96,63 @@ static int rk_aif1_hw_params(struct snd_pcm_substream 
*substream,
 
ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
 SND_SOC_CLOCK_OUT);
-   if (ret < 0) {
-   dev_err(codec_dai->dev, "Can't set codec clock %d\n", ret);
+   if (ret) {
+   dev_err(cpu_dai->dev, "Can't set cpu dai clock %d\n", ret);
return ret;
}
 
+   /* HDMI codec dai does not need to set sysclk. */
+   if (!strcmp(rtd->dai_link->name, "HDMI"))
+   return 0;
+
ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
 SND_SOC_CLOCK_IN);
-   if (ret < 0) {
-   dev_err(codec_dai->dev, "Can't set codec clock %d\n", ret);
+   if (ret) {
+   dev_err(codec_dai->dev, "Can't set codec dai clock %d\n", ret);
return ret;
}
 
-   return ret;
+   return 0;
 }
 
 static const struct snd_soc_ops rk_aif1_ops = {
.hw_params = rk_aif1_hw_params,
 };
 
-SND_SOC_DAILINK_DEFS(hifi,
+SND_SOC_DAILINK_DEFS(analog,
DAILINK_COMP_ARRAY(COMP_EMPTY()),
DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "HiFi")),
DAILINK_COMP_ARRAY(COMP_EMPTY()));
 
-static struct snd_soc_dai_link rk_dailink = {
-   .name = "max98090",
-   .stream_name = "Audio",
-   .ops = _aif1_ops,
-   /* set max98090 as slave */
-   .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
-   SND_SOC_DAIFMT_CBS_CFS,
-   SND_SOC_DAILINK_REG(hifi),
+SND_SOC_DAILINK_DEFS(hdmi,
+   DAILINK_COMP_ARRAY(COMP_EMPTY()),
+   DAILINK_COMP_ARRAY(COMP_CODEC(HDMI_CODEC_DRV_NAME, "i2s-hifi")),
+   DAILINK_COMP_ARRAY(COMP_EMPTY()));
+
+enum {
+   DAILINK_MAX98090,
+   DAILINK_HDMI,
+};
+
+/* max98090 and HDMI codec dai_link */
+static struct snd_soc_dai_link rk_dailinks[] = {
+   [DAILINK_MAX98090] = {
+   .name = "max98090",
+   .stream_name = "Analog",
+   .ops = _aif1_ops,
+   /* set max98090 as slave */
+   .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+   SND_SOC_DAIFMT_CBS_CFS,
+   SND_SOC_DAILINK_REG(analog),
+   },
+   [DAILINK_HDMI] = {
+   .name = "HDMI",
+   .stream_name = "HDMI",
+   .ops = _aif1_ops,
+   .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+   SND_SOC_DAIFMT_CBS_CFS,
+   SND_SOC_DAILINK_REG(hdmi),
+   }
 };
 
 static int rk_98090_headset_init(struct snd_soc_component *component);
@@ -136,8 +165,8 @@ static struct snd_soc_aux_dev rk_98090_headset_dev = {
 static struct snd_soc_card snd_soc_card_rk = {
.name = "ROCKCHIP-I2S",
.owner = THIS_MODULE,
-   .dai_link = _dailink,
-   .num_links = 1,
+   .dai_link = rk_dailinks,
+   .num_links = ARRAY_SIZE(rk_dailinks),
.aux_dev = _98090_headset_dev,
.num_aux_devs = 1,
.dapm_widgets = rk_dapm_widgets,
@@ -173,27 +202,48 @@ static int snd_rk_mc_probe(struct platform_device *pdev)
int

[PATCH] ASoC: rockchip: rockchip_max98090: Set period size to 240

2019-08-13 Thread Cheng-Yi Chiang
>From stress testing of arecord, we found that period size
greater than ~900 will bring pl330 to DYING state and
can not recover within 100 iterations.
The result is that arecord will stuck and get I/O error,
and issue can not be recovered until reboot.

This issue does not happen when period size is small.
Set constraint of period size to 240 to prevent such issue.
With the constraint, there will be no issue after 2000 iterations.

We can revert this patch once the root cause is found
in rockchip's pl330 implementation.

Signed-off-by: Cheng-Yi Chiang 
---
 sound/soc/rockchip/rockchip_max98090.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/sound/soc/rockchip/rockchip_max98090.c 
b/sound/soc/rockchip/rockchip_max98090.c
index 7b0c21fa6dca..0097df1fae66 100644
--- a/sound/soc/rockchip/rockchip_max98090.c
+++ b/sound/soc/rockchip/rockchip_max98090.c
@@ -137,8 +137,19 @@ static int rk_aif1_hw_params(struct snd_pcm_substream 
*substream,
return ret;
 }
 
+static int rk_aif1_startup(struct snd_pcm_substream *substream)
+{
+   /*
+* Set period size to 240 because pl330 has issue
+* dealing with larger period in stress testing.
+*/
+   return snd_pcm_hw_constraint_minmax(substream->runtime,
+   SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 240, 240);
+}
+
 static const struct snd_soc_ops rk_aif1_ops = {
.hw_params = rk_aif1_hw_params,
+   .startup = rk_aif1_startup,
 };
 
 SND_SOC_DAILINK_DEFS(hifi,
-- 
2.23.0.rc1.153.gdeed80330f-goog



Re: [PATCH] Revert "ASoC: rockchip: i2s: Support mono capture"

2019-07-26 Thread Cheng-yi Chiang
On Fri, Jul 26, 2019 at 7:17 PM Mark Brown  wrote:
>
> On Fri, Jul 26, 2019 at 12:42:02PM +0800, Cheng-Yi Chiang wrote:
> > This reverts commit db51707b9c9aeedd310ebce60f15d5bb006567e0.
> >
> > Previous discussion in
>
> Please use subject lines matching the style for the subsystem.  This
> makes it easier for people to identify relevant patches.
>
>
> Please include human readable descriptions of things like commits and
> issues being discussed in e-mail in your mails, this makes them much
> easier for humans to read especially when they have no internet access.
> I do frequently catch up on my mail on flights or while otherwise
> travelling so this is even more pressing for me than just being about
> making things a bit easier to read.
Hi Mark,
Thank you for the reply.
Fixed the title and commit messages in v2.


[PATCH v2] ASoC: rockchip: i2s: Revert "ASoC: rockchip: i2s: Support mono capture"

2019-07-26 Thread Cheng-Yi Chiang
This reverts commit db51707b9c9aeedd310ebce60f15d5bb006567e0.

Commit db51707b9c9a ("ASoC: rockchip: i2s: Support mono capture")
adds support of mono capture to rockchip_i2s_dai.

However, I2S controller is still generating a 2-channel stream
because it only supports even number of channels.
When user space reads the data and assumes it is a mono stream,
the rate will be slowed down.

Revert the change so the DAI no longer claims that mono capture
is supported.

Fixes: db51707b9c9a ("ASoC: rockchip: i2s: Support mono capture")
Signed-off-by: Cheng-Yi Chiang 
---
 sound/soc/rockchip/rockchip_i2s.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/sound/soc/rockchip/rockchip_i2s.c 
b/sound/soc/rockchip/rockchip_i2s.c
index 0a34d0eb8dba..88ebaf6e1880 100644
--- a/sound/soc/rockchip/rockchip_i2s.c
+++ b/sound/soc/rockchip/rockchip_i2s.c
@@ -326,7 +326,6 @@ static int rockchip_i2s_hw_params(struct snd_pcm_substream 
*substream,
val |= I2S_CHN_4;
break;
case 2:
-   case 1:
val |= I2S_CHN_2;
break;
default:
@@ -459,7 +458,7 @@ static struct snd_soc_dai_driver rockchip_i2s_dai = {
},
.capture = {
.stream_name = "Capture",
-   .channels_min = 1,
+   .channels_min = 2,
.channels_max = 2,
.rates = SNDRV_PCM_RATE_8000_192000,
.formats = (SNDRV_PCM_FMTBIT_S8 |
@@ -659,7 +658,7 @@ static int rockchip_i2s_probe(struct platform_device *pdev)
}
 
if (!of_property_read_u32(node, "rockchip,capture-channels", )) {
-   if (val >= 1 && val <= 8)
+   if (val >= 2 && val <= 8)
soc_dai->capture.channels_max = val;
}
 
-- 
2.22.0.709.g102302147b-goog



[PATCH] Revert "ASoC: rockchip: i2s: Support mono capture"

2019-07-25 Thread Cheng-Yi Chiang
This reverts commit db51707b9c9aeedd310ebce60f15d5bb006567e0.

Previous discussion in

https://patchwork.kernel.org/patch/10147153/

explains the issue of the patch.
While device is configured as 1-ch, hardware is still
generating a 2-ch stream.
When user space reads the data and assumes it is a 1-ch stream,
the rate will be slower by 2x.

Revert the change so 1-ch is not supported.
User space can selectively take one channel data out of two channel
if 1-ch is preferred.
Currently, both channels record identical data.

Signed-off-by: Cheng-Yi Chiang 
---
 sound/soc/rockchip/rockchip_i2s.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/sound/soc/rockchip/rockchip_i2s.c 
b/sound/soc/rockchip/rockchip_i2s.c
index 0a34d0eb8dba..88ebaf6e1880 100644
--- a/sound/soc/rockchip/rockchip_i2s.c
+++ b/sound/soc/rockchip/rockchip_i2s.c
@@ -326,7 +326,6 @@ static int rockchip_i2s_hw_params(struct snd_pcm_substream 
*substream,
val |= I2S_CHN_4;
break;
case 2:
-   case 1:
val |= I2S_CHN_2;
break;
default:
@@ -459,7 +458,7 @@ static struct snd_soc_dai_driver rockchip_i2s_dai = {
},
.capture = {
.stream_name = "Capture",
-   .channels_min = 1,
+   .channels_min = 2,
.channels_max = 2,
.rates = SNDRV_PCM_RATE_8000_192000,
.formats = (SNDRV_PCM_FMTBIT_S8 |
@@ -659,7 +658,7 @@ static int rockchip_i2s_probe(struct platform_device *pdev)
}
 
if (!of_property_read_u32(node, "rockchip,capture-channels", )) {
-   if (val >= 1 && val <= 8)
+   if (val >= 2 && val <= 8)
soc_dai->capture.channels_max = val;
}
 
-- 
2.22.0.709.g102302147b-goog



Re: [PATCH v3 2/5] drm: bridge: dw-hdmi: Report connector status using callback

2019-07-16 Thread Cheng-yi Chiang
On Fri, Jul 12, 2019 at 6:48 PM Russell King - ARM Linux admin
 wrote:
>
> On Fri, Jul 12, 2019 at 06:04:40PM +0800, Cheng-Yi Chiang wrote:
> > Allow codec driver register callback function for plug event.
> >
> > The callback registration flow:
> > dw-hdmi <--- hw-hdmi-i2s-audio <--- hdmi-codec
> >
> > dw-hdmi-i2s-audio implements hook_plugged_cb op
> > so codec driver can register the callback.
> >
> > dw-hdmi implements set_plugged_cb op so platform device can register the
> > callback.
> >
> > When connector plug/unplug event happens, report this event using the
> > callback.
> >
> > Make sure that audio and drm are using the single source of truth for
> > connector status.
> >
> > Signed-off-by: Cheng-Yi Chiang 
> > ---
> >  .../gpu/drm/bridge/synopsys/dw-hdmi-audio.h   |  3 +
> >  .../drm/bridge/synopsys/dw-hdmi-i2s-audio.c   | 10 
> >  drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 55 ++-
> >  3 files changed, 67 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-audio.h 
> > b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-audio.h
> > index 63b5756f463b..f523c590984e 100644
> > --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-audio.h
> > +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-audio.h
> > @@ -2,6 +2,8 @@
> >  #ifndef DW_HDMI_AUDIO_H
> >  #define DW_HDMI_AUDIO_H
> >
> > +#include 
> > +
> >  struct dw_hdmi;
> >
> >  struct dw_hdmi_audio_data {
> > @@ -17,6 +19,7 @@ struct dw_hdmi_i2s_audio_data {
> >
> >   void (*write)(struct dw_hdmi *hdmi, u8 val, int offset);
> >   u8 (*read)(struct dw_hdmi *hdmi, int offset);
> > + int (*set_plugged_cb)(struct dw_hdmi *hdmi, hdmi_codec_plugged_cb fn);
> >  };
> >
> >  #endif
> > diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c 
> > b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c
> > index 5cbb71a866d5..7b93cf05c985 100644
> > --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c
> > +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c
> > @@ -104,10 +104,20 @@ static int dw_hdmi_i2s_get_dai_id(struct 
> > snd_soc_component *component,
> >   return -EINVAL;
> >  }
> >
> > +static int dw_hdmi_i2s_hook_plugged_cb(struct device *dev, void *data,
> > +hdmi_codec_plugged_cb fn)
> > +{
> > + struct dw_hdmi_i2s_audio_data *audio = data;
> > + struct dw_hdmi *hdmi = audio->hdmi;
> > +
> > + return audio->set_plugged_cb(hdmi, fn);
> > +}
> > +
> >  static struct hdmi_codec_ops dw_hdmi_i2s_ops = {
> >   .hw_params  = dw_hdmi_i2s_hw_params,
> >   .audio_shutdown = dw_hdmi_i2s_audio_shutdown,
> >   .get_dai_id = dw_hdmi_i2s_get_dai_id,
> > + .hook_plugged_cb = dw_hdmi_i2s_hook_plugged_cb,
> >  };
> >
> >  static int snd_dw_hdmi_probe(struct platform_device *pdev)
> > diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c 
> > b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> > index 045b1b13fd0e..ce6646067472 100644
> > --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> > +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> > @@ -26,6 +26,8 @@
> >  #include 
> >  #include 
> >
> > +#include 
> > +
> >  #include 
> >  #include 
> >
> > @@ -185,6 +187,9 @@ struct dw_hdmi {
> >   void (*disable_audio)(struct dw_hdmi *hdmi);
> >
> >   struct cec_notifier *cec_notifier;
> > +
> > + hdmi_codec_plugged_cb plugged_cb;
> > + enum drm_connector_status last_connector_result;
> >  };
> >
> >  #define HDMI_IH_PHY_STAT0_RX_SENSE \
> > @@ -209,6 +214,40 @@ static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int 
> > offset)
> >   return val;
> >  }
> >
> > +static void handle_plugged_change(struct dw_hdmi *hdmi, bool plugged)
> > +{
> > + struct platform_device *codec_pdev;
> > +
> > + if (!hdmi->audio || IS_ERR(hdmi->audio))
> > + return;
> > + codec_pdev = platform_get_drvdata(hdmi->audio);
> > + if (!codec_pdev || IS_ERR(codec_pdev))
> > + return;
>
> This looks fragile to me, poking about in another device's driver data
> from another driver is really not a good design decision.  I think this
> can be simplified if the registration function took the function
> pointer and the struct device pointer, and then you only need one test
> below:
>
Hi Russell

Re: [PATCH 1/7] video: add HDMI state notifier support

2019-06-21 Thread Cheng-yi Chiang
On Fri, Jun 21, 2019 at 5:12 AM Daniel Vetter  wrote:
>
> Massively cutting this thread, since halfway through in my previous reply
> I realized that maybe hdmi_codec is a much better starting point.
>
ACK
> On Thu, Jun 20, 2019 at 09:23:23PM +0800, Cheng-yi Chiang wrote:
> > On Thu, Jun 20, 2019 at 5:25 PM Daniel Vetter  wrote:
> > > Yeah fully agreeing that hdmi_audio_code is probably a better starting
> > > point. Problem is that becuase hdmi_codec is built on top of platform
> > > device it's quite a bit harder to extend with callbacks and things like
> > > that, without breaking the driver model.
> > >
> > > I need to think about this more, but if all we need to look at is
> > > hdmi_codec, then I think this becomes a lot easier. And we can ignore
> > > drm_audio_component.h completely.
> >
> >
> > It is surprising that you think this way.
> > Maybe the original patch before hdmi-notifier was introduced is the
> > better way to solve this issue, if we only need to look at hdmi_codec.
> >
> > The history of hdmi_codec driver is in this patch series:
> >
> > https://lore.kernel.org/patchwork/patch/539656/
>
> Hm, this doesn't seem to be the hdmi_codec driver I meant, but another,
> new one. I was talking about SND_SOC_HDMI_CODEC.
>
Yes you are right. They are different codec drivers.
Sorry for the confusion. What I meant was that my use case on RK3288
was using dw-hdmi-audio.c codec driver,
which was later replaced by a more general version hdmi-codec.c.

> > There was a callback mechanism implemented between dw-hdmi and hdmi
> > codec driver.
> > It was later consolidated by Doug in this patch for better jack status
> > reporting:
> >
> > https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/303573/
>
> Hm that still seems entirely separate hdmi-codec specific to dw-hdmi only
> ...
>
Again you are right. Sorry for the confusion. What I meant is that
this callback mechanism should work on hdmi-codec.c driver as well.

> > I am not sure why the original patch series did not get fully accepted
> > in the upstream.
> > It was quite long time ago.
> >
> > But if you think this might be the right way to do, then it is even
> > better for us because the patch series and Doug's patch had been quite
> > stable
> > on our RK3288 products for about four years with plenty of users, so
> > we have much higher confidence in them.
> > I can rebase and clean up them and post another patch for review.
> >
> > Please let me know what approach you feel is better.
> > Thanks again!
>
> Not sure we're talking about the same. What I had in mind is to add jack
> status to the hdmi-codec.c stuff, which is used by multiple soc drm
> display drivers already. Looking at git grep output, there seems to be
> already some support for dw-hdmi synopsys drm_bridge driver. I thought of
> extending that. Does that not work for you?
>
I think extending current interface will work.
There is a struct hdmi_codec_pdata to let ALSA codec driver access
some ops through platform data.
And after this patch

https://lore.kernel.org/patchwork/patch/692324/

ALSA codec driver can get access to the struct on DRM side.
Based on this I can add a new ops to register callback function for jack status.
It will be similar to Doug's chromium patch above.
I think that is quite a feasible way, and can benefit all boards using
hdmi-codec.c.

Thanks a lot!!

> Thanks, Daniel
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch


Re: [alsa-devel] [PATCH] ASoC: DA7219: Fix failure in hw_params by not letting set_rate error out

2019-04-22 Thread Cheng-yi Chiang
Hi Akshu,


On Mon, Apr 22, 2019 at 2:15 PM Agrawal, Akshu  wrote:
>
> We need to set minimum bclk 64x of wclk as this is hw constraint in one
> of the component used.
> Since, clk_set_rate and clk is enabled in machine driver the
> clk_set_rate in hw_params of da7219 fails and errors out and when it
> tries to override the value.
>
> In cases like these not only clk_set_rate of da7219 codec should fail
> and not override the value but also should not error out.
>
> Signed-off-by: Akshu Agrawal 
> ---
>  sound/soc/codecs/da7219.c | 8 +---
>  1 file changed, 1 insertion(+), 7 deletions(-)
>
> diff --git a/sound/soc/codecs/da7219.c b/sound/soc/codecs/da7219.c
> index 5f5fa3416af3..a041dbf442af 100644
> --- a/sound/soc/codecs/da7219.c
> +++ b/sound/soc/codecs/da7219.c
> @@ -1621,13 +1621,7 @@ static int da7219_hw_params(struct snd_pcm_substream 
> *substream,
>
> if (bclk) {
> bclk_rate = frame_size * sr;
> -   ret = clk_set_rate(bclk, bclk_rate);
> -   if (ret) {
> -   dev_err(component->dev,
> -   "Failed to set BCLK rate %lu: %d\n",
> -   bclk_rate, ret);
> -   return ret;
> -   }
> +   clk_set_rate(bclk, bclk_rate);

I think this might mask the real issue when setting rate fails.
A more fundamental problem might be what are the acceptable ratios
between bclk and wclk.

>From existing code of da7219 I see there are only two choices of
frame_size: 32 or 64.

In da7219_hw_params:
...
if (da7219->master && !da7219->tdm_en) {
  if ((word_len * DA7219_DAI_CH_NUM_MAX) <= 32)
 frame_size = 32;
  else
 frame_size = 64;

And in https://lkml.org/lkml/2019/4/17/322
the choice from machine driver is 64 or higher.

In cz_da7219_params:
 ...
 if (bclk < (wclk * 64))
  bclk = wclk * 64;
 return da7219_clk_enable(substream, wclk, bclk);

I don't know what is the best solution to avoid this conflict.
Maybe just set a fixed ratio from device property that can best work
for the combination of codecs on the machine?





> } else {
> ret = da7219_set_bclks_per_wclk(component, 
> frame_size);
> if (ret) {
> --
> 2.17.1
>
> ___
> Alsa-devel mailing list
> alsa-de...@alsa-project.org
> https://mailman.alsa-project.org/mailman/listinfo/alsa-devel


Re: [PATCH 3/3] ASoC: qcom: add i2c dependency for SND_SOC_SDM845

2019-03-04 Thread Cheng-yi Chiang
On Tue, Mar 5, 2019 at 4:32 AM Arnd Bergmann  wrote:
>
> We must not select SND_SOC_MAX98927 unless CONFIG_I2C
> is also enabled:
>
> WARNING: unmet direct dependencies detected for SND_SOC_MAX98927
>   Depends on [n]: SOUND [=y] && !UML && SND [=y] && SND_SOC [=y] && I2C [=n]
>   Selected by [y]:
>   - SND_SOC_SDM845 [=y] && SOUND [=y] && !UML && SND [=y] && SND_SOC [=y] && 
> QCOM_APR [=y] && MFD_CROS_EC [=y]
>
> Signed-off-by: Arnd Bergmann 
> ---
>  sound/soc/qcom/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
> index 75ceb04d8bf0..b1764af858ba 100644
> --- a/sound/soc/qcom/Kconfig
> +++ b/sound/soc/qcom/Kconfig
> @@ -98,7 +98,7 @@ config SND_SOC_MSM8996
>
>  config SND_SOC_SDM845
> tristate "SoC Machine driver for SDM845 boards"
> -   depends on QCOM_APR && MFD_CROS_EC
> +   depends on QCOM_APR && MFD_CROS_EC && I2C
> select SND_SOC_QDSP6
> select SND_SOC_QCOM_COMMON
> select SND_SOC_RT5663
> --
> 2.20.0
>
Hi Arnd,
Thank you for the fix.
Acked-by: Cheng-Yi Chiang 


Re: [PATCH -next] platform/chrome: Fix Kconfig dependencies for wilco_ec

2019-02-25 Thread Cheng-yi Chiang
On Mon, Feb 25, 2019 at 8:23 PM Enric Balletbo i Serra
 wrote:
>
> Hi Cheng-yi,
>
> Attached the config that Randy sent.
>
> Thanks,
>  Enric

Hi Enric,
Thanks for the quick reply.
I have posted a patch to fix it.

> On 25/2/19 11:22, Cheng-yi Chiang wrote:
> > On Mon, Feb 25, 2019 at 6:11 PM Enric Balletbo i Serra
> >  wrote:
> >>
> >> Hi Randy,
> >>
> >> Thanks for the report
> >>
> >> On 22/2/19 17:50, Randy Dunlap wrote:
> >>> On 2/20/19 11:57 PM, Enric Balletbo i Serra wrote:
> >>>> Hi,
> >>>>
> >>>> On 21/2/19 0:09, Randy Dunlap wrote:
> >>>>> On 2/20/19 2:11 PM, Nick Crews wrote:
> >>>>>> In the initial version of the Wilco EC Driver, the
> >>>>>> dependency order was wrong. It before was possible to
> >>>>>> select CONFIG_WILCO_EC and CONFIG_CROS_EC_LPC without
> >>>>>> having CONFIG_CROS_EC_LPC_MEC. This was wrong, since
> >>>>>> WILCO_EC depends upon CONFIG CROS_EC_LPC_MEC, not the
> >>>>>> other way around.
> >>>>>>
> >>>>>> Fixes: 1733c32834e5d1 ("platform/chrome: Add new driver for Wilco EC")
> >>>>>> Signed-off-by: Nick Crews 
> >>>>>
> >>>>> Reported-by: Randy Dunlap 
> >>>>> Acked-by: Randy Dunlap  # build-tested
> >>>>>
> >>>>
> >>>> As this is [-next] material I squashed that commit and queued for 5.1
> >>>
> >>> Hi,
> >>>
> >>> on linux-next of 20190222, I now see this build error + Kconfig warnings:
> >>>
> >>> (this is on i386; randconfig file is attached)
> >>>
> >>> WARNING: unmet direct dependencies detected for SND_SOC_CROS_EC_CODEC
> >>>   Depends on [n]: SOUND [=y] && !UML && SND [=y] && SND_SOC [=y] && 
> >>> MFD_CROS_EC [=n]
> >>>   Selected by [y]:
> >>>   - SND_SOC_SDM845 [=y] && SOUND [=y] && !UML && SND [=y] && SND_SOC [=y] 
> >>> && QCOM_APR [=y]
> >>
> >>
> >> This error seems to be introduced by following commit.
> >>
> >> commit 74c6ecf4194ebed285b29964a950e0cd7414fe19
> >> Author: Cheng-Yi Chiang 
> >> Date:   Mon Feb 18 12:18:19 2019 +0800
> >>
> >> ASoC: qcom: Kconfig: select dmic for sdm845
> >>
> >> sdm845 uses dmic on EC so it should select CROS_EC_CODEC.
> >>
> >> Signed-off-by: Cheng-Yi Chiang 
> >> Signed-off-by: Mark Brown 
> >>
> >> The problem is that this commit selects CROS_EC_CODEC but the CROS_EC_CODEC
> >> depends on MFD_CROS_EC which is not selected.
> >>
> >> A question for Cheng-Yi, I suppose that the answer is yes but worth ask 
> >> because
> >> I don't know about this device. Is the sdm845 a chromebook with and 
> >> embedded
> >> controller right?
> >>
> >> Thanks,
> >> Enric
> >>
> >
> > Hi Enric,
> > Yes you are right.
> > Sorry for causing the trouble.
> > I will post a patch to fix it.
> >
> > Could you please let me know what is the command for your build ?
> > Currently I am using command like
> > ARCH=x86_64 make allyesconfig
> > ARCH=x86_64 make -j64
> >
> > to verify the build, which is not useful to catch bug like this.
> > If you have any other good tip for checking this kind of error please
> > kindly let me know.
> > Thanks!
> >
> >>>
> >>> ld: sound/soc/codecs/cros_ec_codec.o: in function `ec_command_no_resp':
> >>> cros_ec_codec.c:(.text+0x50): undefined reference to 
> >>> `cros_ec_cmd_xfer_status'
> >>> ld: sound/soc/codecs/cros_ec_codec.o: in function `mic_gain_get':
> >>> cros_ec_codec.c:(.text+0x5a8): undefined reference to 
> >>> `cros_ec_cmd_xfer_status'
> >>>
> >>>
> >>>


[PATCH] ASoC: qcom: Kconfig: fix dependency for sdm845

2019-02-25 Thread Cheng-Yi Chiang
SND_SOC_CROS_EC_CODEC depends on MFD_CROS_EC.
Add that dependency to SND_SOC_SDM845 to fix unmet direct dependencies
warning.

Fixes: 74c6ecf4194e (ASoC: qcom: Kconfig: select dmic for sdm845)
Signed-off-by: Cheng-Yi Chiang 
---
 sound/soc/qcom/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 8f206cb4fcc0..75ceb04d8bf0 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -98,7 +98,7 @@ config SND_SOC_MSM8996
 
 config SND_SOC_SDM845
tristate "SoC Machine driver for SDM845 boards"
-   depends on QCOM_APR
+   depends on QCOM_APR && MFD_CROS_EC
select SND_SOC_QDSP6
select SND_SOC_QCOM_COMMON
select SND_SOC_RT5663
-- 
2.21.0.rc0.258.g878e2cd30e-goog



Re: [PATCH -next] platform/chrome: Fix Kconfig dependencies for wilco_ec

2019-02-25 Thread Cheng-yi Chiang
On Mon, Feb 25, 2019 at 6:11 PM Enric Balletbo i Serra
 wrote:
>
> Hi Randy,
>
> Thanks for the report
>
> On 22/2/19 17:50, Randy Dunlap wrote:
> > On 2/20/19 11:57 PM, Enric Balletbo i Serra wrote:
> >> Hi,
> >>
> >> On 21/2/19 0:09, Randy Dunlap wrote:
> >>> On 2/20/19 2:11 PM, Nick Crews wrote:
> >>>> In the initial version of the Wilco EC Driver, the
> >>>> dependency order was wrong. It before was possible to
> >>>> select CONFIG_WILCO_EC and CONFIG_CROS_EC_LPC without
> >>>> having CONFIG_CROS_EC_LPC_MEC. This was wrong, since
> >>>> WILCO_EC depends upon CONFIG CROS_EC_LPC_MEC, not the
> >>>> other way around.
> >>>>
> >>>> Fixes: 1733c32834e5d1 ("platform/chrome: Add new driver for Wilco EC")
> >>>> Signed-off-by: Nick Crews 
> >>>
> >>> Reported-by: Randy Dunlap 
> >>> Acked-by: Randy Dunlap  # build-tested
> >>>
> >>
> >> As this is [-next] material I squashed that commit and queued for 5.1
> >
> > Hi,
> >
> > on linux-next of 20190222, I now see this build error + Kconfig warnings:
> >
> > (this is on i386; randconfig file is attached)
> >
> > WARNING: unmet direct dependencies detected for SND_SOC_CROS_EC_CODEC
> >   Depends on [n]: SOUND [=y] && !UML && SND [=y] && SND_SOC [=y] && 
> > MFD_CROS_EC [=n]
> >   Selected by [y]:
> >   - SND_SOC_SDM845 [=y] && SOUND [=y] && !UML && SND [=y] && SND_SOC [=y] 
> > && QCOM_APR [=y]
>
>
> This error seems to be introduced by following commit.
>
> commit 74c6ecf4194ebed285b29964a950e0cd7414fe19
> Author: Cheng-Yi Chiang 
> Date:   Mon Feb 18 12:18:19 2019 +0800
>
> ASoC: qcom: Kconfig: select dmic for sdm845
>
> sdm845 uses dmic on EC so it should select CROS_EC_CODEC.
>
> Signed-off-by: Cheng-Yi Chiang 
> Signed-off-by: Mark Brown 
>
> The problem is that this commit selects CROS_EC_CODEC but the CROS_EC_CODEC
> depends on MFD_CROS_EC which is not selected.
>
> A question for Cheng-Yi, I suppose that the answer is yes but worth ask 
> because
> I don't know about this device. Is the sdm845 a chromebook with and embedded
> controller right?
>
> Thanks,
> Enric
>

Hi Enric,
Yes you are right.
Sorry for causing the trouble.
I will post a patch to fix it.

Could you please let me know what is the command for your build ?
Currently I am using command like
ARCH=x86_64 make allyesconfig
ARCH=x86_64 make -j64

to verify the build, which is not useful to catch bug like this.
If you have any other good tip for checking this kind of error please
kindly let me know.
Thanks!

> >
> > ld: sound/soc/codecs/cros_ec_codec.o: in function `ec_command_no_resp':
> > cros_ec_codec.c:(.text+0x50): undefined reference to 
> > `cros_ec_cmd_xfer_status'
> > ld: sound/soc/codecs/cros_ec_codec.o: in function `mic_gain_get':
> > cros_ec_codec.c:(.text+0x5a8): undefined reference to 
> > `cros_ec_cmd_xfer_status'
> >
> >
> >


[PATCH] ASoC: qcom: Kconfig: select dmic for sdm845

2019-02-17 Thread Cheng-Yi Chiang
sdm845 uses dmic on EC so it should select CROS_EC_CODEC.

Signed-off-by: Cheng-Yi Chiang 
---
 sound/soc/qcom/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 7948e993adba..8f206cb4fcc0 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -103,6 +103,7 @@ config SND_SOC_SDM845
select SND_SOC_QCOM_COMMON
select SND_SOC_RT5663
select SND_SOC_MAX98927
+   select SND_SOC_CROS_EC_CODEC
help
  To add support for audio on Qualcomm Technologies Inc.
  SDM845 SoC-based systems.
-- 
2.21.0.rc0.258.g878e2cd30e-goog



Re: [PATCH -next] ASoC: cros_ec_codec: Make symbol 'cros_ec_dai' static

2019-02-12 Thread Cheng-yi Chiang
On Wed, Feb 13, 2019 at 2:16 PM Wei Yongjun  wrote:
>
> Fixes the following sparse warning:
>
> sound/soc/codecs/cros_ec_codec.c:209:27: warning:
>  symbol 'cros_ec_dai' was not declared. Should it be static?
>
> Fixes: b291f42a3718 ("ASoC: cros_ec_codec: Add codec driver for Cros EC")
> Signed-off-by: Wei Yongjun 
> ---
>  sound/soc/codecs/cros_ec_codec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sound/soc/codecs/cros_ec_codec.c 
> b/sound/soc/codecs/cros_ec_codec.c
> index b14100b6a939..99a3af8a15ff 100644
> --- a/sound/soc/codecs/cros_ec_codec.c
> +++ b/sound/soc/codecs/cros_ec_codec.c
> @@ -206,7 +206,7 @@ static const struct snd_soc_dai_ops cros_ec_i2s_dai_ops = 
> {
> .set_fmt = cros_ec_i2s_set_dai_fmt,
>  };
>
> -struct snd_soc_dai_driver cros_ec_dai[] = {
> +static struct snd_soc_dai_driver cros_ec_dai[] = {
> {
> .name = "cros_ec_codec I2S",
> .id = 0,
>
>
>
Hi Wei,
  Yes you are right. Thanks for the fix!


Re: [PATCH v3 1/3] mfd: cros_ec: Add commands to control codec

2019-01-28 Thread Cheng-yi Chiang
On Mon, Jan 28, 2019 at 2:50 PM Lee Jones  wrote:
>
> On Mon, 28 Jan 2019, Cheng-yi Chiang wrote:
>
> > Hi Lee,
> >   Could you please give Mark a tag so he can merge ?
> > The later patch for cros_ec_codec driver is pending on it.
>
> Apologies for not getting back to you.
>
> I was waiting to see if my late PR would be merged.
>
> It was, which means the tag you were asking for is actually upstream.
>
> Any issues, let me know.

Hi Lee,
  Thanks for the reply. I see. Yes it was merged in upstream:
c1f3375be60c mfd: cros_ec: Add commands to control codec

Hi Mark,
  I am not sure what would be the best practice for you.
Would it work if you cherrypick this patch from upstream into your branch ?

Thanks!


>
> --
> Lee Jones [李琼斯]
> Linaro Services Technical Lead
> Linaro.org │ Open source software for ARM SoCs
> Follow Linaro: Facebook | Twitter | Blog


Re: [PATCH v4 2/2] ASoC: cros_ec_codec: Add codec driver for Cros EC

2019-01-19 Thread Cheng-yi Chiang
Hi Mark,

Sorry, I forgot to mention that the patch for EC command definition
has been already merged in upstream, but not in Mark's for-next tree
yet.

c1f3375be60c mfd: cros_ec: Add commands to control codec

This is needed.
Thanks!

On Sat, Jan 19, 2019 at 7:34 PM Cheng-Yi Chiang  wrote:
>
> Add a codec driver to control ChromeOS EC codec.
>
> Use EC Host command to enable/disable I2S recording and control other
> configurations.
>
> Signed-off-by: Cheng-Yi Chiang 
> ---
>  Changes in v4:
>
> - Fix Kconfig that SND_SOC_CROS_EC_CODEC should depend on MFD_CROS_EC.
> - Remove usage of MAX_GAIN.
> - Add max-dmic-gain device property.
> - Read max-dmic-gain property and add mixer control in component probe.
> - Rename cros_ec_dapm_widgets to cros_ec_codec_dapm_widgets for consistency.
> - Fix missing return code in cros_ec_codec_platform_probe.
> - Rename set_bclk to set_i2s_bclk.
> - Add ec_command_get_gain for EC subcommand EC_CODEC_GET_GAIN, which
>   is the only subcommand that needs response.
> - Add ec_command_no_resp as a simplified version of ec_command for EC commands
>   that do not need response.
> - Simplify all static functions that uses ec_command_no_resp. Return return 
> code
>   directly without logging.
> - Remove useless frame_size in cros_ec_i2s_hw_params.
> - Remove error messages in cros_ec_i2s_hw_params for consistency.
> - Remove error messages in get_ec_mic_gain.
>
>
>  MAINTAINERS  |   1 +
>  sound/soc/codecs/Kconfig |   8 +
>  sound/soc/codecs/Makefile|   2 +
>  sound/soc/codecs/cros_ec_codec.c | 441 +++
>  4 files changed, 452 insertions(+)
>  create mode 100644 sound/soc/codecs/cros_ec_codec.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index a5678e4041e9..e5696ab5d10a 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -3694,6 +3694,7 @@ S:Maintained
>  R: Enric Balletbo i Serra 
>  R: Guenter Roeck 
>  F: Documentation/devicetree/bindings/sound/google,cros-ec-codec.txt
> +F: sound/soc/codecs/cros_ec_codec.*
>
>  CIRRUS LOGIC AUDIO CODEC DRIVERS
>  M: Brian Austin 
> diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
> index 71e6e123a115..d1ef359b47bd 100644
> --- a/sound/soc/codecs/Kconfig
> +++ b/sound/soc/codecs/Kconfig
> @@ -50,6 +50,7 @@ config SND_SOC_ALL_CODECS
> select SND_SOC_BT_SCO
> select SND_SOC_BD28623
> select SND_SOC_CQ0093VC
> +   select SND_SOC_CROS_EC_CODEC if MFD_CROS_EC
> select SND_SOC_CS35L32 if I2C
> select SND_SOC_CS35L33 if I2C
> select SND_SOC_CS35L34 if I2C
> @@ -457,6 +458,13 @@ config SND_SOC_CPCAP
>  config SND_SOC_CQ0093VC
> tristate
>
> +config SND_SOC_CROS_EC_CODEC
> +   tristate "codec driver for ChromeOS EC"
> +   depends on MFD_CROS_EC
> +   help
> + If you say yes here you will get support for the
> + ChromeOS Embedded Controller's Audio Codec.
> +
>  config SND_SOC_CS35L32
> tristate "Cirrus Logic CS35L32 CODEC"
> depends on I2C
> diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
> index 9bb3346fab2f..3cfd8f5f6170 100644
> --- a/sound/soc/codecs/Makefile
> +++ b/sound/soc/codecs/Makefile
> @@ -42,6 +42,7 @@ snd-soc-bd28623-objs := bd28623.o
>  snd-soc-bt-sco-objs := bt-sco.o
>  snd-soc-cpcap-objs := cpcap.o
>  snd-soc-cq93vc-objs := cq93vc.o
> +snd-soc-cros-ec-codec-objs := cros_ec_codec.o
>  snd-soc-cs35l32-objs := cs35l32.o
>  snd-soc-cs35l33-objs := cs35l33.o
>  snd-soc-cs35l34-objs := cs35l34.o
> @@ -310,6 +311,7 @@ obj-$(CONFIG_SND_SOC_BD28623)   += snd-soc-bd28623.o
>  obj-$(CONFIG_SND_SOC_BT_SCO)   += snd-soc-bt-sco.o
>  obj-$(CONFIG_SND_SOC_CQ0093VC) += snd-soc-cq93vc.o
>  obj-$(CONFIG_SND_SOC_CPCAP)+= snd-soc-cpcap.o
> +obj-$(CONFIG_SND_SOC_CROS_EC_CODEC)+= snd-soc-cros-ec-codec.o
>  obj-$(CONFIG_SND_SOC_CS35L32)  += snd-soc-cs35l32.o
>  obj-$(CONFIG_SND_SOC_CS35L33)  += snd-soc-cs35l33.o
>  obj-$(CONFIG_SND_SOC_CS35L34)  += snd-soc-cs35l34.o
> diff --git a/sound/soc/codecs/cros_ec_codec.c 
> b/sound/soc/codecs/cros_ec_codec.c
> new file mode 100644
> index ..b14100b6a939
> --- /dev/null
> +++ b/sound/soc/codecs/cros_ec_codec.c
> @@ -0,0 +1,441 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Driver for ChromeOS Embedded Controller codec.
> + *
> + * This driver uses the cros-ec interface to communicate with the ChromeOS
> + * EC for audio function.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include

[PATCH v4 1/2] ASoC: Documentation: Add google,cros-ec-codec

2019-01-19 Thread Cheng-Yi Chiang
Add documentation for Chrome EC codec driver.

Signed-off-by: Cheng-Yi Chiang 
---
 Change in v4:
 - Add a property max-dmic-gain so we can configure maximum gain on dmic.
 - Add Guenter to the reviewer list.

 .../bindings/sound/google,cros-ec-codec.txt   | 26 +++
 MAINTAINERS   |  7 +
 2 files changed, 33 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/sound/google,cros-ec-codec.txt

diff --git a/Documentation/devicetree/bindings/sound/google,cros-ec-codec.txt 
b/Documentation/devicetree/bindings/sound/google,cros-ec-codec.txt
new file mode 100644
index ..1084f7f22eea
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/google,cros-ec-codec.txt
@@ -0,0 +1,26 @@
+* Audio codec controlled by ChromeOS EC
+
+Google's ChromeOS EC codec is a digital mic codec provided by the
+Embedded Controller (EC) and is controlled via a host-command interface.
+
+An EC codec node should only be found as a sub-node of the EC node (see
+Documentation/devicetree/bindings/mfd/cros-ec.txt).
+
+Required properties:
+- compatible: Must contain "google,cros-ec-codec"
+- #sound-dai-cells: Should be 1. The cell specifies number of DAIs.
+- max-dmic-gain: A number for maximum gain in dB on digital microphone.
+
+Example:
+
+cros-ec@0 {
+   compatible = "google,cros-ec-spi";
+
+   ...
+
+   cros_ec_codec: ec-codec {
+   compatible = "google,cros-ec-codec";
+   #sound-dai-cells = <1>;
+   max-dmic-gain = <43>;
+   };
+};
diff --git a/MAINTAINERS b/MAINTAINERS
index 4d04cebb4a71..a5678e4041e9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3688,6 +3688,13 @@ N:   cros_ec
 N: cros-ec
 F: drivers/power/supply/cros_usbpd-charger.c
 
+CHROMEOS EC CODEC DRIVER
+M: Cheng-Yi Chiang 
+S: Maintained
+R: Enric Balletbo i Serra 
+R: Guenter Roeck 
+F: Documentation/devicetree/bindings/sound/google,cros-ec-codec.txt
+
 CIRRUS LOGIC AUDIO CODEC DRIVERS
 M: Brian Austin 
 M: Paul Handrigan 
-- 
2.20.1.321.g9e740568ce-goog



  1   2   >