Commit e5408081 authored by Mark Brown's avatar Mark Brown

Merge remote-tracking branches 'asoc/topic/da7219', 'asoc/topic/da732x',...

Merge remote-tracking branches 'asoc/topic/da7219', 'asoc/topic/da732x', 'asoc/topic/da9055' and 'asoc/topic/dmic' into asoc-next
...@@ -25,6 +25,9 @@ Optional properties: ...@@ -25,6 +25,9 @@ Optional properties:
interrupt is to be used to wake system, otherwise "irq" should be used. interrupt is to be used to wake system, otherwise "irq" should be used.
- wakeup-source: Flag to indicate this device can wake system (suspend/resume). - wakeup-source: Flag to indicate this device can wake system (suspend/resume).
- #clock-cells : Should be set to '<0>', only one clock source provided;
- clock-output-names : Name given for DAI clocks output;
- clocks : phandle and clock specifier for codec MCLK. - clocks : phandle and clock specifier for codec MCLK.
- clock-names : Clock name string for 'clocks' attribute, should be "mclk". - clock-names : Clock name string for 'clocks' attribute, should be "mclk".
...@@ -83,6 +86,9 @@ Example: ...@@ -83,6 +86,9 @@ Example:
VDDMIC-supply = <&reg_audio>; VDDMIC-supply = <&reg_audio>;
VDDIO-supply = <&reg_audio>; VDDIO-supply = <&reg_audio>;
#clock-cells = <0>;
clock-output-names = "dai-clks";
clocks = <&clks 201>; clocks = <&clks 201>;
clock-names = "mclk"; clock-names = "mclk";
......
...@@ -8,6 +8,7 @@ Required properties: ...@@ -8,6 +8,7 @@ Required properties:
Optional properties: Optional properties:
- dmicen-gpios: GPIO specifier for dmic to control start and stop - dmicen-gpios: GPIO specifier for dmic to control start and stop
- num-channels: Number of microphones on this DAI - num-channels: Number of microphones on this DAI
- wakeup-delay-ms: Delay (in ms) after enabling the DMIC
Example node: Example node:
...@@ -15,4 +16,5 @@ Example node: ...@@ -15,4 +16,5 @@ Example node:
compatible = "dmic-codec"; compatible = "dmic-codec";
dmicen-gpios = <&gpio4 3 GPIO_ACTIVE_HIGH>; dmicen-gpios = <&gpio4 3 GPIO_ACTIVE_HIGH>;
num-channels = <1>; num-channels = <1>;
wakeup-delay-ms <50>;
}; };
...@@ -36,6 +36,8 @@ struct da7219_aad_pdata; ...@@ -36,6 +36,8 @@ struct da7219_aad_pdata;
struct da7219_pdata { struct da7219_pdata {
bool wakeup_source; bool wakeup_source;
const char *dai_clks_name;
/* Mic */ /* Mic */
enum da7219_micbias_voltage micbias_lvl; enum da7219_micbias_voltage micbias_lvl;
enum da7219_mic_amp_in_sel mic_amp_in_sel; enum da7219_mic_amp_in_sel mic_amp_in_sel;
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include <linux/acpi.h> #include <linux/acpi.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/clkdev.h>
#include <linux/clk-provider.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/property.h> #include <linux/property.h>
...@@ -772,16 +774,27 @@ static int da7219_dai_event(struct snd_soc_dapm_widget *w, ...@@ -772,16 +774,27 @@ static int da7219_dai_event(struct snd_soc_dapm_widget *w,
struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
u8 pll_ctrl, pll_status; u8 pll_ctrl, pll_status;
int i = 0; int i = 0, ret;
bool srm_lock = false; bool srm_lock = false;
switch (event) { switch (event) {
case SND_SOC_DAPM_PRE_PMU: case SND_SOC_DAPM_PRE_PMU:
if (da7219->master) if (da7219->master) {
/* Enable DAI clks for master mode */ /* Enable DAI clks for master mode */
snd_soc_component_update_bits(component, DA7219_DAI_CLK_MODE, if (da7219->dai_clks) {
ret = clk_prepare_enable(da7219->dai_clks);
if (ret) {
dev_err(component->dev,
"Failed to enable dai_clks\n");
return ret;
}
} else {
snd_soc_component_update_bits(component,
DA7219_DAI_CLK_MODE,
DA7219_DAI_CLK_EN_MASK, DA7219_DAI_CLK_EN_MASK,
DA7219_DAI_CLK_EN_MASK); DA7219_DAI_CLK_EN_MASK);
}
}
/* PC synchronised to DAI */ /* PC synchronised to DAI */
snd_soc_component_update_bits(component, DA7219_PC_COUNT, snd_soc_component_update_bits(component, DA7219_PC_COUNT,
...@@ -814,9 +827,16 @@ static int da7219_dai_event(struct snd_soc_dapm_widget *w, ...@@ -814,9 +827,16 @@ static int da7219_dai_event(struct snd_soc_dapm_widget *w,
DA7219_PC_FREERUN_MASK); DA7219_PC_FREERUN_MASK);
/* Disable DAI clks if in master mode */ /* Disable DAI clks if in master mode */
if (da7219->master) if (da7219->master) {
snd_soc_component_update_bits(component, DA7219_DAI_CLK_MODE, if (da7219->dai_clks)
DA7219_DAI_CLK_EN_MASK, 0); clk_disable_unprepare(da7219->dai_clks);
else
snd_soc_component_update_bits(component,
DA7219_DAI_CLK_MODE,
DA7219_DAI_CLK_EN_MASK,
0);
}
return 0; return 0;
default: default:
return -EINVAL; return -EINVAL;
...@@ -1598,6 +1618,12 @@ static struct da7219_pdata *da7219_fw_to_pdata(struct snd_soc_component *compone ...@@ -1598,6 +1618,12 @@ static struct da7219_pdata *da7219_fw_to_pdata(struct snd_soc_component *compone
pdata->wakeup_source = device_property_read_bool(dev, "wakeup-source"); pdata->wakeup_source = device_property_read_bool(dev, "wakeup-source");
pdata->dai_clks_name = "da7219-dai-clks";
if (device_property_read_string(dev, "clock-output-names",
&pdata->dai_clks_name))
dev_warn(dev, "Using default clk name: %s\n",
pdata->dai_clks_name);
if (device_property_read_u32(dev, "dlg,micbias-lvl", &of_val32) >= 0) if (device_property_read_u32(dev, "dlg,micbias-lvl", &of_val32) >= 0)
pdata->micbias_lvl = da7219_fw_micbias_lvl(dev, of_val32); pdata->micbias_lvl = da7219_fw_micbias_lvl(dev, of_val32);
else else
...@@ -1712,6 +1738,88 @@ static int da7219_handle_supplies(struct snd_soc_component *component) ...@@ -1712,6 +1738,88 @@ static int da7219_handle_supplies(struct snd_soc_component *component)
return 0; return 0;
} }
#ifdef CONFIG_COMMON_CLK
static int da7219_dai_clks_prepare(struct clk_hw *hw)
{
struct da7219_priv *da7219 =
container_of(hw, struct da7219_priv, dai_clks_hw);
struct snd_soc_component *component = da7219->aad->component;
snd_soc_component_update_bits(component, DA7219_DAI_CLK_MODE,
DA7219_DAI_CLK_EN_MASK,
DA7219_DAI_CLK_EN_MASK);
return 0;
}
static void da7219_dai_clks_unprepare(struct clk_hw *hw)
{
struct da7219_priv *da7219 =
container_of(hw, struct da7219_priv, dai_clks_hw);
struct snd_soc_component *component = da7219->aad->component;
snd_soc_component_update_bits(component, DA7219_DAI_CLK_MODE,
DA7219_DAI_CLK_EN_MASK, 0);
}
static int da7219_dai_clks_is_prepared(struct clk_hw *hw)
{
struct da7219_priv *da7219 =
container_of(hw, struct da7219_priv, dai_clks_hw);
struct snd_soc_component *component = da7219->aad->component;
u8 clk_reg;
clk_reg = snd_soc_component_read32(component, DA7219_DAI_CLK_MODE);
return !!(clk_reg & DA7219_DAI_CLK_EN_MASK);
}
static const struct clk_ops da7219_dai_clks_ops = {
.prepare = da7219_dai_clks_prepare,
.unprepare = da7219_dai_clks_unprepare,
.is_prepared = da7219_dai_clks_is_prepared,
};
static void da7219_register_dai_clks(struct snd_soc_component *component)
{
struct device *dev = component->dev;
struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
struct da7219_pdata *pdata = da7219->pdata;
struct clk_init_data init = {};
struct clk *dai_clks;
struct clk_lookup *dai_clks_lookup;
init.parent_names = NULL;
init.num_parents = 0;
init.name = pdata->dai_clks_name;
init.ops = &da7219_dai_clks_ops;
da7219->dai_clks_hw.init = &init;
dai_clks = devm_clk_register(dev, &da7219->dai_clks_hw);
if (IS_ERR(dai_clks)) {
dev_warn(dev, "Failed to register DAI clocks: %ld\n",
PTR_ERR(dai_clks));
return;
}
da7219->dai_clks = dai_clks;
/* If we're using DT, then register as provider accordingly */
if (dev->of_node) {
devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get,
&da7219->dai_clks_hw);
} else {
dai_clks_lookup = clkdev_create(dai_clks, pdata->dai_clks_name,
"%s", dev_name(dev));
if (!dai_clks_lookup)
dev_warn(dev, "Failed to create DAI clkdev");
else
da7219->dai_clks_lookup = dai_clks_lookup;
}
}
#else
static inline void da7219_register_dai_clks(struct snd_soc_component *component) {}
#endif /* CONFIG_COMMON_CLK */
static void da7219_handle_pdata(struct snd_soc_component *component) static void da7219_handle_pdata(struct snd_soc_component *component)
{ {
struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
...@@ -1722,6 +1830,8 @@ static void da7219_handle_pdata(struct snd_soc_component *component) ...@@ -1722,6 +1830,8 @@ static void da7219_handle_pdata(struct snd_soc_component *component)
da7219->wakeup_source = pdata->wakeup_source; da7219->wakeup_source = pdata->wakeup_source;
da7219_register_dai_clks(component);
/* Mic Bias voltages */ /* Mic Bias voltages */
switch (pdata->micbias_lvl) { switch (pdata->micbias_lvl) {
case DA7219_MICBIAS_1_6V: case DA7219_MICBIAS_1_6V:
...@@ -1856,6 +1966,11 @@ static void da7219_remove(struct snd_soc_component *component) ...@@ -1856,6 +1966,11 @@ static void da7219_remove(struct snd_soc_component *component)
da7219_aad_exit(component); da7219_aad_exit(component);
#ifdef CONFIG_COMMON_CLK
if (da7219->dai_clks_lookup)
clkdev_drop(da7219->dai_clks_lookup);
#endif
/* Supplies */ /* Supplies */
regulator_bulk_disable(DA7219_NUM_SUPPLIES, da7219->supplies); regulator_bulk_disable(DA7219_NUM_SUPPLIES, da7219->supplies);
} }
......
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
#ifndef __DA7219_H #ifndef __DA7219_H
#define __DA7219_H #define __DA7219_H
#include <linux/clk.h>
#include <linux/clkdev.h>
#include <linux/clk-provider.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#include <sound/da7219.h> #include <sound/da7219.h>
...@@ -813,6 +816,12 @@ struct da7219_priv { ...@@ -813,6 +816,12 @@ struct da7219_priv {
struct mutex ctrl_lock; struct mutex ctrl_lock;
struct mutex pll_lock; struct mutex pll_lock;
#ifdef CONFIG_COMMON_CLK
struct clk_hw dai_clks_hw;
#endif
struct clk_lookup *dai_clks_lookup;
struct clk *dai_clks;
struct clk *mclk; struct clk *mclk;
unsigned int mclk_rate; unsigned int mclk_rate;
int clk_src; int clk_src;
......
This diff is collapsed.
This diff is collapsed.
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
* *
*/ */
#include <linux/delay.h>
#include <linux/gpio.h> #include <linux/gpio.h>
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
...@@ -29,34 +30,33 @@ ...@@ -29,34 +30,33 @@
#include <sound/soc.h> #include <sound/soc.h>
#include <sound/soc-dapm.h> #include <sound/soc-dapm.h>
static int dmic_daiops_trigger(struct snd_pcm_substream *substream, struct dmic {
int cmd, struct snd_soc_dai *dai) struct gpio_desc *gpio_en;
{ int wakeup_delay;
struct gpio_desc *dmic_en = snd_soc_dai_get_drvdata(dai); };
if (!dmic_en) static int dmic_aif_event(struct snd_soc_dapm_widget *w,
return 0; struct snd_kcontrol *kcontrol, int event) {
struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
struct dmic *dmic = snd_soc_component_get_drvdata(component);
switch (event) {
case SND_SOC_DAPM_POST_PMU:
if (dmic->gpio_en)
gpiod_set_value(dmic->gpio_en, 1);
switch (cmd) { if (dmic->wakeup_delay)
case SNDRV_PCM_TRIGGER_START: msleep(dmic->wakeup_delay);
case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
gpiod_set_value(dmic_en, 1);
break; break;
case SNDRV_PCM_TRIGGER_STOP: case SND_SOC_DAPM_POST_PMD:
case SNDRV_PCM_TRIGGER_SUSPEND: if (dmic->gpio_en)
case SNDRV_PCM_TRIGGER_PAUSE_PUSH: gpiod_set_value(dmic->gpio_en, 0);
gpiod_set_value(dmic_en, 0);
break; break;
} }
return 0; return 0;
} }
static const struct snd_soc_dai_ops dmic_dai_ops = {
.trigger = dmic_daiops_trigger,
};
static struct snd_soc_dai_driver dmic_dai = { static struct snd_soc_dai_driver dmic_dai = {
.name = "dmic-hifi", .name = "dmic-hifi",
.capture = { .capture = {
...@@ -68,26 +68,33 @@ static struct snd_soc_dai_driver dmic_dai = { ...@@ -68,26 +68,33 @@ static struct snd_soc_dai_driver dmic_dai = {
| SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_LE
| SNDRV_PCM_FMTBIT_S16_LE, | SNDRV_PCM_FMTBIT_S16_LE,
}, },
.ops = &dmic_dai_ops,
}; };
static int dmic_codec_probe(struct snd_soc_codec *codec) static int dmic_component_probe(struct snd_soc_component *component)
{ {
struct gpio_desc *dmic_en; struct dmic *dmic;
dmic = devm_kzalloc(component->dev, sizeof(*dmic), GFP_KERNEL);
if (!dmic)
return -ENOMEM;
dmic_en = devm_gpiod_get_optional(codec->dev, dmic->gpio_en = devm_gpiod_get_optional(component->dev,
"dmicen", GPIOD_OUT_LOW); "dmicen", GPIOD_OUT_LOW);
if (IS_ERR(dmic_en)) if (IS_ERR(dmic->gpio_en))
return PTR_ERR(dmic_en); return PTR_ERR(dmic->gpio_en);
device_property_read_u32(component->dev, "wakeup-delay-ms",
&dmic->wakeup_delay);
snd_soc_codec_set_drvdata(codec, dmic_en); snd_soc_component_set_drvdata(component, dmic);
return 0; return 0;
} }
static const struct snd_soc_dapm_widget dmic_dapm_widgets[] = { static const struct snd_soc_dapm_widget dmic_dapm_widgets[] = {
SND_SOC_DAPM_AIF_OUT("DMIC AIF", "Capture", 0, SND_SOC_DAPM_AIF_OUT_E("DMIC AIF", "Capture", 0,
SND_SOC_NOPM, 0, 0), SND_SOC_NOPM, 0, 0, dmic_aif_event,
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
SND_SOC_DAPM_INPUT("DMic"), SND_SOC_DAPM_INPUT("DMic"),
}; };
...@@ -95,14 +102,16 @@ static const struct snd_soc_dapm_route intercon[] = { ...@@ -95,14 +102,16 @@ static const struct snd_soc_dapm_route intercon[] = {
{"DMIC AIF", NULL, "DMic"}, {"DMIC AIF", NULL, "DMic"},
}; };
static const struct snd_soc_codec_driver soc_dmic = { static const struct snd_soc_component_driver soc_dmic = {
.probe = dmic_codec_probe, .probe = dmic_component_probe,
.component_driver = {
.dapm_widgets = dmic_dapm_widgets, .dapm_widgets = dmic_dapm_widgets,
.num_dapm_widgets = ARRAY_SIZE(dmic_dapm_widgets), .num_dapm_widgets = ARRAY_SIZE(dmic_dapm_widgets),
.dapm_routes = intercon, .dapm_routes = intercon,
.num_dapm_routes = ARRAY_SIZE(intercon), .num_dapm_routes = ARRAY_SIZE(intercon),
}, .idle_bias_on = 1,
.use_pmdown_time = 1,
.endianness = 1,
.non_legacy_dai_naming = 1,
}; };
static int dmic_dev_probe(struct platform_device *pdev) static int dmic_dev_probe(struct platform_device *pdev)
...@@ -129,16 +138,10 @@ static int dmic_dev_probe(struct platform_device *pdev) ...@@ -129,16 +138,10 @@ static int dmic_dev_probe(struct platform_device *pdev)
} }
} }
return snd_soc_register_codec(&pdev->dev, return devm_snd_soc_register_component(&pdev->dev,
&soc_dmic, dai_drv, 1); &soc_dmic, dai_drv, 1);
} }
static int dmic_dev_remove(struct platform_device *pdev)
{
snd_soc_unregister_codec(&pdev->dev);
return 0;
}
MODULE_ALIAS("platform:dmic-codec"); MODULE_ALIAS("platform:dmic-codec");
static const struct of_device_id dmic_dev_match[] = { static const struct of_device_id dmic_dev_match[] = {
...@@ -152,7 +155,6 @@ static struct platform_driver dmic_driver = { ...@@ -152,7 +155,6 @@ static struct platform_driver dmic_driver = {
.of_match_table = dmic_dev_match, .of_match_table = dmic_dev_match,
}, },
.probe = dmic_dev_probe, .probe = dmic_dev_probe,
.remove = dmic_dev_remove,
}; };
module_platform_driver(dmic_driver); module_platform_driver(dmic_driver);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment