From patchwork Wed Feb 21 04:33:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Katsuhiro Suzuki X-Patchwork-Id: 128990 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp203603ljc; Tue, 20 Feb 2018 20:33:35 -0800 (PST) X-Google-Smtp-Source: AH8x22426JrZ3lkSJCXgq92mEA24CswlFIHtmuZcfKK6xRy9g4+bbkznguqQ6ClGPCvgEest01nV X-Received: by 2002:a17:902:5982:: with SMTP id p2-v6mr1797141pli.289.1519187615558; Tue, 20 Feb 2018 20:33:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519187615; cv=none; d=google.com; s=arc-20160816; b=gftv8jgjXiwEEzPE7yzf65SrxvhTxSoL0HKCeIo3ZynDC4ahdz4GKFZ8cus/343rxB JAq7clfqyAu2Dv4O/K2ODtAymxF5fQQCD+BwDhCaCwAdjUF6Q47BqV3yA4732W8DVGiP F0xS+cg1KckcPQ/YqpOF/oTyasuB+csxFY3GQQ3RW9ExbGRS+9GroxmWh9djbNjHu5P6 Sf5keroDmsZVk3AwQpZ+2sl7KF9Dp1/2+JVz9fZnPScYf8CI/VehQPyD0An7ezMsU/o4 mVzVW8sb6TmS/9YRYbhiD/Zl2V/6zyCpKcK7ZgduktZFKZ+nLehtClbgyX8EofbrbxVw aCXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=RDFBS9rawAoGotnpZ2QzA6UvSxgceCZ9PUgc6g7GMiQ=; b=PbxGWRm86+tCDRc0RKV4tDdyt6rjolcsQ9m7V5scfEClRUhWtnpEA1rhQ85tetpArd AnhniN4KMEP9mRtIdJHiKS5+40BWa+r8TiimNhMZy6w20u8z1cYYtrRHXiayBJCk4v8V XAy34ML7C3KuM0PiyQZIt6C29EoKGFvgs2+fNadLTB6dwadVRrS/a/jWtzm1RnILVffw ZUNHqjxj/X3+Kr5Hj1iPxfVwDW6WlzNRTAZ/5Cf1GrQA1Uqj3Hbo88a5bAylZFUW87Sh S3jYs0lxD+M+/OEgZmAYELk+wR+y+s9nXHqNvL0nuGzyrGS8i5D51yGTVw8vYqz5IjqN P/+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w1-v6si27528plk.597.2018.02.20.20.33.35; Tue, 20 Feb 2018 20:33:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751503AbeBUEdb (ORCPT + 28 others); Tue, 20 Feb 2018 23:33:31 -0500 Received: from mx.socionext.com ([202.248.49.38]:8750 "EHLO mx.socionext.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751367AbeBUEdQ (ORCPT ); Tue, 20 Feb 2018 23:33:16 -0500 Received: from unknown (HELO kinkan-ex.css.socionext.com) ([172.31.9.52]) by mx.socionext.com with ESMTP; 21 Feb 2018 13:33:14 +0900 Received: from mail.mfilter.local (m-filter-1 [10.213.24.61]) by kinkan-ex.css.socionext.com (Postfix) with ESMTP id 24E371800EE; Wed, 21 Feb 2018 13:33:14 +0900 (JST) Received: from 172.31.9.51 (172.31.9.51) by m-FILTER with ESMTP; Wed, 21 Feb 2018 13:33:41 +0900 Received: from yuzu.css.socionext.com (yuzu [172.31.8.45]) by kinkan.css.socionext.com (Postfix) with ESMTP id C3B531A159F; Wed, 21 Feb 2018 13:33:13 +0900 (JST) Received: from aegis.e01.socionext.com (unknown [10.213.134.210]) by yuzu.css.socionext.com (Postfix) with ESMTP id 94F48120534; Wed, 21 Feb 2018 13:33:13 +0900 (JST) From: Katsuhiro Suzuki To: Mark Brown , alsa-devel@alsa-project.org, Rob Herring , devicetree@vger.kernel.org Cc: Masami Hiramatsu , Jassi Brar , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Katsuhiro Suzuki Subject: [PATCH 2/2] ASoC: support ROHM BD28623 codec Date: Wed, 21 Feb 2018 13:33:11 +0900 Message-Id: <20180221043311.25840-3-suzuki.katsuhiro@socionext.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180221043311.25840-1-suzuki.katsuhiro@socionext.com> References: <20180221043311.25840-1-suzuki.katsuhiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds support of the ROHM BD28623MUV Class D speaker amplifier for Flat-panel TVs. This IC delivers an output power of 20W + 20W. Signed-off-by: Katsuhiro Suzuki --- sound/soc/codecs/Kconfig | 8 ++ sound/soc/codecs/Makefile | 2 + sound/soc/codecs/bd28623.c | 258 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 268 insertions(+) create mode 100644 sound/soc/codecs/bd28623.c -- 2.16.1 diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index f72a90104a58..6a53e188ead6 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -47,6 +47,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_ALC5623 if I2C select SND_SOC_ALC5632 if I2C select SND_SOC_BT_SCO + select SND_SOC_BD28623 select SND_SOC_CQ0093VC select SND_SOC_CS35L32 if I2C select SND_SOC_CS35L33 if I2C @@ -418,6 +419,13 @@ config SND_SOC_ALC5623 config SND_SOC_ALC5632 tristate +config SND_SOC_BD28623 + tristate "ROHM BD28623 CODEC" + help + Enable support for ROHM BD28623MUV Class D speaker amplifier. + This codec does not have any control buses such as I2C, it + detect format of I2S automatically. + config SND_SOC_BT_SCO tristate "Dummy BT SCO codec driver" diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 56c3252820d2..f2c710e16557 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -37,6 +37,7 @@ snd-soc-ak4671-objs := ak4671.o snd-soc-ak5386-objs := ak5386.o snd-soc-ak5558-objs := ak5558.o snd-soc-arizona-objs := arizona.o +snd-soc-bd28623-objs := bd28623.o snd-soc-bt-sco-objs := bt-sco.o snd-soc-cq93vc-objs := cq93vc.o snd-soc-cs35l32-objs := cs35l32.o @@ -285,6 +286,7 @@ obj-$(CONFIG_SND_SOC_AK5558) += snd-soc-ak5558.o obj-$(CONFIG_SND_SOC_ALC5623) += snd-soc-alc5623.o obj-$(CONFIG_SND_SOC_ALC5632) += snd-soc-alc5632.o obj-$(CONFIG_SND_SOC_ARIZONA) += snd-soc-arizona.o +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_CS35L32) += snd-soc-cs35l32.o diff --git a/sound/soc/codecs/bd28623.c b/sound/soc/codecs/bd28623.c new file mode 100644 index 000000000000..672c8e790e24 --- /dev/null +++ b/sound/soc/codecs/bd28623.c @@ -0,0 +1,258 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * ROHM BD28623MUV class D speaker amplifier codec driver. + * + * Copyright (c) 2018 Socionext Inc. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define BD28623_NUM_SUPPLIES 3 + +static const char *const bd28623_supply_names[BD28623_NUM_SUPPLIES] = { + "VCCA", + "VCCP1", + "VCCP2", +}; + +struct bd28623_priv { + struct platform_device *pdev; + struct regulator_bulk_data supplies[BD28623_NUM_SUPPLIES]; + struct gpio_desc *reset_gpio; + struct gpio_desc *mute_gpio; + + int switch_spk; +}; + +static const struct snd_soc_dapm_widget bd28623_widgets[] = { + SND_SOC_DAPM_DAC("DAC", "Playback", SND_SOC_NOPM, 0, 0), + SND_SOC_DAPM_OUTPUT("OUT1P"), + SND_SOC_DAPM_OUTPUT("OUT1N"), + SND_SOC_DAPM_OUTPUT("OUT2P"), + SND_SOC_DAPM_OUTPUT("OUT2N"), +}; + +static const struct snd_soc_dapm_route bd28623_routes[] = { + { "OUT1P", NULL, "DAC" }, + { "OUT1N", NULL, "DAC" }, + { "OUT2P", NULL, "DAC" }, + { "OUT2N", NULL, "DAC" }, +}; + +static int bd28623_power_on(struct bd28623_priv *bd) +{ + struct device *dev = &bd->pdev->dev; + int ret; + + ret = regulator_bulk_enable(ARRAY_SIZE(bd->supplies), bd->supplies); + if (ret) { + dev_err(dev, "Failed to enable supplies: %d\n", ret); + return ret; + } + + gpiod_set_value(bd->reset_gpio, 0); + usleep_range(300000, 400000); + + return 0; +} + +static void bd28623_power_off(struct bd28623_priv *bd) +{ + gpiod_set_value(bd->reset_gpio, 1); + + regulator_bulk_disable(ARRAY_SIZE(bd->supplies), bd->supplies); +} + +static int bd28623_update_switch_spk(struct bd28623_priv *bd) +{ + if (bd->switch_spk) + gpiod_set_value(bd->mute_gpio, 0); + else + gpiod_set_value(bd->mute_gpio, 1); + + return 0; +} + +static int bd28623_get_switch_spk(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component = + snd_soc_kcontrol_component(kcontrol); + struct bd28623_priv *bd = snd_soc_component_get_drvdata(component); + + ucontrol->value.integer.value[0] = bd->switch_spk; + + return 0; +} + +static int bd28623_set_switch_spk(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component = + snd_soc_kcontrol_component(kcontrol); + struct bd28623_priv *bd = snd_soc_component_get_drvdata(component); + + if (bd->switch_spk == ucontrol->value.integer.value[0]) + return 0; + + bd->switch_spk = ucontrol->value.integer.value[0]; + + return bd28623_update_switch_spk(bd); +} + +static const struct snd_kcontrol_new bd28623_controls[] = { + SOC_SINGLE_BOOL_EXT("Speaker Switch", 0, + bd28623_get_switch_spk, bd28623_set_switch_spk), +}; + +static int bd28623_codec_probe(struct snd_soc_component *component) +{ + struct bd28623_priv *bd = snd_soc_component_get_drvdata(component); + int ret; + + bd->switch_spk = 1; + + ret = bd28623_power_on(bd); + if (ret) + return ret; + + bd28623_update_switch_spk(bd); + + return 0; +} + +static int bd28623_codec_suspend(struct snd_soc_component *component) +{ + struct bd28623_priv *bd = snd_soc_component_get_drvdata(component); + + bd28623_power_off(bd); + + return 0; +} + +static int bd28623_codec_resume(struct snd_soc_component *component) +{ + struct bd28623_priv *bd = snd_soc_component_get_drvdata(component); + int ret; + + ret = bd28623_power_on(bd); + if (ret) + return ret; + + bd28623_update_switch_spk(bd); + + return 0; +} + +static const struct snd_soc_component_driver soc_codec_bd = { + .probe = bd28623_codec_probe, + .suspend = bd28623_codec_suspend, + .resume = bd28623_codec_resume, + .dapm_widgets = bd28623_widgets, + .num_dapm_widgets = ARRAY_SIZE(bd28623_widgets), + .dapm_routes = bd28623_routes, + .num_dapm_routes = ARRAY_SIZE(bd28623_routes), + .controls = bd28623_controls, + .num_controls = ARRAY_SIZE(bd28623_controls), + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, +}; + +static struct snd_soc_dai_driver soc_dai_bd = { + .name = "bd28623-speaker", + .playback = { + .stream_name = "Playback", + .formats = SNDRV_PCM_FMTBIT_S32_LE | + SNDRV_PCM_FMTBIT_S24_LE | + SNDRV_PCM_FMTBIT_S16_LE, + .rates = SNDRV_PCM_RATE_48000 | + SNDRV_PCM_RATE_44100 | + SNDRV_PCM_RATE_32000, + .channels_min = 2, + .channels_max = 2, + }, +}; + +static int bd28623_probe(struct platform_device *pdev) +{ + struct bd28623_priv *bd; + struct device *dev = &pdev->dev; + int i, ret; + + bd = devm_kzalloc(&pdev->dev, sizeof(struct bd28623_priv), GFP_KERNEL); + if (!bd) + return -ENOMEM; + + for (i = 0; i < ARRAY_SIZE(bd->supplies); i++) + bd->supplies[i].supply = bd28623_supply_names[i]; + + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(bd->supplies), + bd->supplies); + if (ret) { + dev_err(dev, "Failed to get supplies: %d\n", ret); + return ret; + } + + bd->reset_gpio = devm_gpiod_get_optional(dev, "reset", + GPIOD_OUT_HIGH); + if (IS_ERR(bd->reset_gpio)) { + dev_err(dev, "Failed to request reset_gpio: %ld\n", + PTR_ERR(bd->reset_gpio)); + return PTR_ERR(bd->reset_gpio); + } + + bd->mute_gpio = devm_gpiod_get_optional(dev, "mute", + GPIOD_OUT_HIGH); + if (IS_ERR(bd->mute_gpio)) { + dev_err(dev, "Failed to request mute_gpio: %ld\n", + PTR_ERR(bd->mute_gpio)); + return PTR_ERR(bd->mute_gpio); + } + + platform_set_drvdata(pdev, bd); + bd->pdev = pdev; + + ret = devm_snd_soc_register_component(dev, &soc_codec_bd, + &soc_dai_bd, 1); + if (ret) + return ret; + + return 0; +} + +static int bd28623_remove(struct platform_device *pdev) +{ + struct bd28623_priv *bd = platform_get_drvdata(pdev); + + regulator_bulk_disable(ARRAY_SIZE(bd->supplies), bd->supplies); + + return 0; +} + +static const struct of_device_id bd28623_of_match[] = { + { .compatible = "rohm,bd28623", }, + {} +}; +MODULE_DEVICE_TABLE(of, bd28623_of_match); + +static struct platform_driver bd28623_codec_driver = { + .driver = { + .name = "bd28623", + .of_match_table = of_match_ptr(bd28623_of_match), + }, + .probe = bd28623_probe, + .remove = bd28623_remove, +}; +module_platform_driver(bd28623_codec_driver); + +MODULE_AUTHOR("Katsuhiro Suzuki "); +MODULE_DESCRIPTION("ROHM BD28623 speaker amplifier driver"); +MODULE_LICENSE("GPL v2");