summaryrefslogtreecommitdiff
path: root/sound/soc/rockchip/rk3288_hdmi_analog.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/rockchip/rk3288_hdmi_analog.c')
-rw-r--r--sound/soc/rockchip/rk3288_hdmi_analog.c116
1 files changed, 40 insertions, 76 deletions
diff --git a/sound/soc/rockchip/rk3288_hdmi_analog.c b/sound/soc/rockchip/rk3288_hdmi_analog.c
index a472d5eb2950..cf642a23c38a 100644
--- a/sound/soc/rockchip/rk3288_hdmi_analog.c
+++ b/sound/soc/rockchip/rk3288_hdmi_analog.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-only
/*
* Rockchip machine ASoC driver for RK3288 boards that have an HDMI and analog
* audio output
@@ -6,26 +7,12 @@
*
* Authors: Sjoerd Simons <sjoerd.simons@collabora.com>,
* Romain Perier <romain.perier@collabora.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
*/
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
-#include <linux/gpio.h>
-#include <linux/of_gpio.h>
+#include <linux/gpio/consumer.h>
#include <sound/core.h>
#include <sound/jack.h>
#include <sound/pcm.h>
@@ -38,20 +25,17 @@
#define DRV_NAME "rk3288-snd-hdmi-analog"
struct rk_drvdata {
- int gpio_hp_en;
- int gpio_hp_det;
+ struct gpio_desc *gpio_hp_en;
};
static int rk_hp_power(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *k, int event)
{
- struct rk_drvdata *machine = snd_soc_card_get_drvdata(w->dapm->card);
+ struct snd_soc_card *card = snd_soc_dapm_to_card(w->dapm);
+ struct rk_drvdata *machine = snd_soc_card_get_drvdata(card);
- if (!gpio_is_valid(machine->gpio_hp_en))
- return 0;
-
- gpio_set_value_cansleep(machine->gpio_hp_en,
- SND_SOC_DAPM_EVENT_ON(event));
+ gpiod_set_value_cansleep(machine->gpio_hp_en,
+ SND_SOC_DAPM_EVENT_ON(event));
return 0;
}
@@ -78,9 +62,9 @@ static int rk_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
int ret = 0;
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
+ struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+ struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
+ struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
int mclk;
switch (params_rate(params)) {
@@ -125,22 +109,23 @@ static int rk_hw_params(struct snd_pcm_substream *substream,
}
static struct snd_soc_jack_gpio rk_hp_jack_gpio = {
- .name = "Headphone detection",
+ .name = "rockchip,hp-det",
.report = SND_JACK_HEADPHONE,
.debounce_time = 150
};
static int rk_init(struct snd_soc_pcm_runtime *runtime)
{
- struct rk_drvdata *machine = snd_soc_card_get_drvdata(runtime->card);
-
- /* Enable Headset Jack detection */
- if (gpio_is_valid(machine->gpio_hp_det)) {
- snd_soc_card_jack_new(runtime->card, "Headphone Jack",
- SND_JACK_HEADPHONE, &headphone_jack,
- headphone_jack_pins,
- ARRAY_SIZE(headphone_jack_pins));
- rk_hp_jack_gpio.gpio = machine->gpio_hp_det;
+ struct snd_soc_card *card = runtime->card;
+ struct device *dev = card->dev;
+
+ /* Enable optional Headset Jack detection */
+ if (of_property_present(dev->of_node, "rockchip,hp-det-gpios")) {
+ rk_hp_jack_gpio.gpiod_dev = dev;
+ snd_soc_card_jack_new_pins(runtime->card, "Headphone Jack",
+ SND_JACK_HEADPHONE, &headphone_jack,
+ headphone_jack_pins,
+ ARRAY_SIZE(headphone_jack_pins));
snd_soc_jack_add_gpios(&headphone_jack, 1, &rk_hp_jack_gpio);
}
@@ -151,24 +136,21 @@ static const struct snd_soc_ops rk_ops = {
.hw_params = rk_hw_params,
};
-static struct snd_soc_dai_link_component rk_codecs[] = {
- { },
- {
- .name = "hdmi-audio-codec.2.auto",
- .dai_name = "i2s-hifi",
- },
-};
+SND_SOC_DAILINK_DEFS(audio,
+ DAILINK_COMP_ARRAY(COMP_EMPTY()),
+ DAILINK_COMP_ARRAY(COMP_CODEC(NULL, NULL),
+ COMP_CODEC("hdmi-audio-codec.2.auto", "i2s-hifi")),
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
static struct snd_soc_dai_link rk_dailink = {
.name = "Codecs",
.stream_name = "Audio",
.init = rk_init,
.ops = &rk_ops,
- .codecs = rk_codecs,
- .num_codecs = ARRAY_SIZE(rk_codecs),
/* Set codecs as slave */
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
- SND_SOC_DAIFMT_CBS_CFS,
+ SND_SOC_DAIFMT_CBC_CFC,
+ SND_SOC_DAILINK_REG(audio),
};
static struct snd_soc_card snd_soc_card_rk = {
@@ -184,7 +166,7 @@ static struct snd_soc_card snd_soc_card_rk = {
static int snd_rk_mc_probe(struct platform_device *pdev)
{
- int ret = 0;
+ int ret;
struct snd_soc_card *card = &snd_soc_card_rk;
struct device_node *np = pdev->dev.of_node;
struct rk_drvdata *machine;
@@ -197,24 +179,10 @@ static int snd_rk_mc_probe(struct platform_device *pdev)
card->dev = &pdev->dev;
- machine->gpio_hp_det = of_get_named_gpio(np,
- "rockchip,hp-det-gpios", 0);
- if (!gpio_is_valid(machine->gpio_hp_det) && machine->gpio_hp_det != -ENODEV)
- return machine->gpio_hp_det;
-
- machine->gpio_hp_en = of_get_named_gpio(np,
- "rockchip,hp-en-gpios", 0);
- if (!gpio_is_valid(machine->gpio_hp_en) && machine->gpio_hp_en != -ENODEV)
- return machine->gpio_hp_en;
-
- if (gpio_is_valid(machine->gpio_hp_en)) {
- ret = devm_gpio_request_one(&pdev->dev, machine->gpio_hp_en,
- GPIOF_OUT_INIT_LOW, "hp_en");
- if (ret) {
- dev_err(card->dev, "cannot get hp_en gpio\n");
- return ret;
- }
- }
+ machine->gpio_hp_en = devm_gpiod_get_optional(&pdev->dev, "rockchip,hp-en", GPIOD_OUT_LOW);
+ if (IS_ERR(machine->gpio_hp_en))
+ return PTR_ERR(machine->gpio_hp_en);
+ gpiod_set_consumer_name(machine->gpio_hp_en, "hp_en");
ret = snd_soc_of_parse_card_name(card, "rockchip,model");
if (ret) {
@@ -244,15 +212,15 @@ static int snd_rk_mc_probe(struct platform_device *pdev)
return ret;
}
- rk_dailink.cpu_of_node = of_parse_phandle(np, "rockchip,i2s-controller",
+ rk_dailink.cpus->of_node = of_parse_phandle(np, "rockchip,i2s-controller",
0);
- if (!rk_dailink.cpu_of_node) {
+ if (!rk_dailink.cpus->of_node) {
dev_err(&pdev->dev,
"Property 'rockchip,i2s-controller' missing or invalid\n");
return -EINVAL;
}
- rk_dailink.platform_of_node = rk_dailink.cpu_of_node;
+ rk_dailink.platforms->of_node = rk_dailink.cpus->of_node;
ret = snd_soc_of_parse_audio_routing(card, "rockchip,routing");
if (ret) {
@@ -264,15 +232,11 @@ static int snd_rk_mc_probe(struct platform_device *pdev)
snd_soc_card_set_drvdata(card, machine);
ret = devm_snd_soc_register_card(&pdev->dev, card);
- if (ret == -EPROBE_DEFER)
- return -EPROBE_DEFER;
- if (ret) {
- dev_err(&pdev->dev,
- "Soc register card failed %d\n", ret);
- return ret;
- }
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret,
+ "Soc register card failed\n");
- return ret;
+ return 0;
}
static const struct of_device_id rockchip_sound_of_match[] = {