From nobody Sat Oct 4 00:21:54 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3CBC2F90E2 for ; Fri, 22 Aug 2025 10:49:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755859778; cv=none; b=EEf3I9gcelLwmsgIpptBSrL4XFNpdE/i7BxoXQqDCRu4zBm1fq/+C1fMnwzyrZPsbF77SWOt0sfiFC6Z8J9pCa3mR/mB2aG3bsFESvzYS/tRJXVKD01gfEyM8nGIDERRlYAEVtOQOOCqLJLB1GbKv5l4KAggtWwWYfbT0nsZxZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755859778; c=relaxed/simple; bh=3flbEGAO2D/K+6LGudhp2wibfu47tX5VrVpPUqtmkgE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JCSPvb+VK9i1U7O5AWTnAgn+FaBv52M7JrLwYStqyINjdolX3KAPAu8cHjJpQVEdWkSLgzwKEExs7slc9kxURKDHqv6zmQVfAoOJZcTcVTzt92g9SoeTsaLF5OByM3H7BPCDe5yxfdgp8IkjQdnodtXMrKeOoLsKTxaYVJb2hnc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=Ku7oX+ME; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="Ku7oX+ME" Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 57M8UMeo001094 for ; Fri, 22 Aug 2025 10:49:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=H7kL8BoKCuZ ke5IvvMrdrVeeFy5dmIj3Oh/eMtOzVoc=; b=Ku7oX+MEgrSUhuZu8Nw7Jp4DuiX 2miElBruirS/Jqq1RUK+jIZ5uk7PV6U7BRu7JdsLVETwdYiS29XVyeQA95GaMPh+ 6AB7g33ndSuykQNBvR10akL+mj8KjFdjcxwf6J/VlrI844DhZ3qsSi3ZloJ4r2F0 A+IMoywq6wQdiNpRnGv0YpzQjU+/Ioyz9d6KWCCqkefXtlyBZ2tva23V5f+NjEOh M1I9Xs5c3MFFcG0bRmFBMt1etsOU6F0wFYP+5tPnTApmG85t9iPFi7WpdZ0Qa6CA uI4lp5E1Wo2gqYsm9nvVFSouZl7m5fD2BYy1r5vzmSVQlN7n+K9dJxZYSBw== Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 48n5298xwh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 22 Aug 2025 10:49:34 +0000 (GMT) Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-70d9eb2ec70so2490606d6.0 for ; Fri, 22 Aug 2025 03:49:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755859773; x=1756464573; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H7kL8BoKCuZke5IvvMrdrVeeFy5dmIj3Oh/eMtOzVoc=; b=EcKr9evGlFNYV/v4ANejj0CKdgg+jVeisb0at1jjvdiVvHFe8sLUd+xdzXU6Y9sQBJ DYs7/AVqqspp/RQDEFMwBRkxyp/CD6vxJ3W+r2PU02ZPsnjL9FEB1LE5ISIdRgb/okIp gKenukv12Udw50E0hQ2G+eHDhMoTXjpO3o2FeaNhdjfZk3Gjkuqp3n9CaPjoRceidVvg APZ1N6/gqVePo9cgfVHg3W86LErvszwOJDWCG8P5Q6L2VhTTIODdPGGcRk2usFwK3jo9 5wL1DffKYpwijnNN+nB9UaFKae+ufnglF2QI1/ai8mY+9YmLH1womXP5PLVDlzH+zZjO njVw== X-Forwarded-Encrypted: i=1; AJvYcCUJjguRYYJBHQVdvsFuy6fvKmkhQ5a+DOu5boGLPdmKIBxjTqa/mRO47VZaf7sDeFgtDrUOFWa8+iwb1is=@vger.kernel.org X-Gm-Message-State: AOJu0YxsFZweFKF4g/R29Ex6x21i1//m1NIW4WdB3H3xaP/x5uaVHTFo vvnufEvPNXkmZgmAN2GuUmeFnb8REkDi7ZLlw3BZM1qbkoogJUzw9jovVotI9B/bodeOw5AAG29 OOvcICShBCmHwIK3FOHkg44SceOOL3Ijjn4wRGZaUTacwglzuacmzK8iUQCApvPPTF9o= X-Gm-Gg: ASbGnctKx2jQRMfojSvGavFw4fckFy+/flDCYV2YCDe2cRKSmA7cgAnpR0aHsgpjhNw vFhfxD+JigAKUCwVyilqZ8wEtl/+tVQY5ackxYzqrJVuZax34pfYZJoTFS3W2CTgW2LRKyuKD2R UAQDB7HqqLBCpmxf9434Geivupe6opJ0Of+NgLR+TuUDnrW9Y8una0UPRbvqk92FObI4NQn9Ej3 bJxMsjn2CqDgfZgpxzlN0lHjwSNi7T8lcsHxB9JF7z867FlgEZlkmlQztVAmbkyCaEWiEwevJN5 EmJ6LkDmRlgqu6pfRSzZu/h0TiJ+SLeLrLXo3j8dJbVQm9veW3uRyA== X-Received: by 2002:a05:6214:411c:b0:707:1dd2:a47d with SMTP id 6a1803df08f44-70d972d7739mr34833316d6.28.1755859772834; Fri, 22 Aug 2025 03:49:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGW9IG7LQK2ggWC4b5IL7KWMF85spAEG6RShorJbfyiLkMxuf5AvM3r40hh6aMbPM78NLd90g== X-Received: by 2002:a05:6214:411c:b0:707:1dd2:a47d with SMTP id 6a1803df08f44-70d972d7739mr34832886d6.28.1755859772019; Fri, 22 Aug 2025 03:49:32 -0700 (PDT) Received: from debian ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b50e4249bsm31367155e9.25.2025.08.22.03.49.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Aug 2025 03:49:31 -0700 (PDT) From: Srinivas Kandagatla To: broonie@kernel.org Cc: perex@perex.cz, tiwai@suse.com, srini@kernel.org, lgirdwood@gmail.com, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, krzysztof.kozlowski@linaro.org, neil.armstrong@linaro.org, Srinivas Kandagatla Subject: [PATCH v2 2/8] ASoC: codecs: wcd: add common helper for wcd codecs Date: Fri, 22 Aug 2025 11:49:21 +0100 Message-ID: <20250822104927.2621866-3-srinivas.kandagatla@oss.qualcomm.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250822104927.2621866-1-srinivas.kandagatla@oss.qualcomm.com> References: <20250822104927.2621866-1-srinivas.kandagatla@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: SsMSV9SfBQF3Z1ydT9euEtHSNvFKeErX X-Proofpoint-ORIG-GUID: SsMSV9SfBQF3Z1ydT9euEtHSNvFKeErX X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwODIwMDAxMyBTYWx0ZWRfX770GXwfXJvAO HpiNYmUAh4fQjgL2rMJlxWvox2vGlkIXgR7zaqS40psAP1g5H57ZssNp7YhUFhgV6cOrSuIru6+ k80R5visqoXxxlJ6okty+GgwFcVfZK6n1ZRKCr8TwJwSMFQN76kaDnxNRYzyiMiOvbIyMp0MFkd ktzqthZiOYe32bdcl6umqvTwTozLQsUwbK7NqQV4lnyIUDXP4IIzM2DhA5DNWjjVIBOWpxu0Cs7 wxzUrrfGBk0hUkGmaDVwcVPg+91H8jrasvvZfQRafU2qRg2D8WhTT5IqOVbVK6JqLKUu/9YLaue GXdh6abjxBx4J6RSX/5tGIKaq7idvpeGXC5+YoMXIM6/ilDHVat5brqJ6hjTAlG7r4wO+hLth3N 0olfpZo9/PleZBW68q+vc5cTpyrRDw== X-Authority-Analysis: v=2.4 cv=SPkblOvH c=1 sm=1 tr=0 ts=68a84b3f cx=c_pps a=wEM5vcRIz55oU/E2lInRtA==:117 a=ZsC4DHZuhs/kKio7QBcDoQ==:17 a=2OwXVqhp2XgA:10 a=EUspDBNiAAAA:8 a=wa_gl3HYg-BSzEidaMMA:9 a=sbBvEVo_xVyyD6Se:21 a=OIgjcC2v60KrkQgK7BGD:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-08-22_03,2025-08-20_03,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 priorityscore=1501 bulkscore=0 spamscore=0 phishscore=0 impostorscore=0 adultscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2508110000 definitions=main-2508200013 Content-Type: text/plain; charset="utf-8" All the Qualcomm WCD codecs have most of its code duplicated across all these 3/4 drivers. This patch is an attempt to remove those duplicate parts by adding a common helper library for these codecs. To start with move all the micbias parsing and voltage settings these are identical in WCD934x, WCD937x, WCD938x and WCD939x codec driver. Signed-off-by: Srinivas Kandagatla --- sound/soc/codecs/Kconfig | 8 ++++ sound/soc/codecs/Makefile | 2 + sound/soc/codecs/wcd-common.c | 66 ++++++++++++++++++++++++++ sound/soc/codecs/wcd-common.h | 24 ++++++++++ sound/soc/codecs/wcd934x.c | 82 +++++++++----------------------- sound/soc/codecs/wcd937x.c | 75 +++++++---------------------- sound/soc/codecs/wcd937x.h | 6 +-- sound/soc/codecs/wcd938x.c | 87 +++++++--------------------------- sound/soc/codecs/wcd938x.h | 1 + sound/soc/codecs/wcd939x.c | 89 +++++++---------------------------- sound/soc/codecs/wcd939x.h | 1 + 11 files changed, 176 insertions(+), 265 deletions(-) create mode 100644 sound/soc/codecs/wcd-common.c create mode 100644 sound/soc/codecs/wcd-common.h diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index b8d58d2fe326..f8476914e4ba 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -2251,12 +2251,16 @@ config SND_SOC_UDA1380 config SND_SOC_WCD_CLASSH tristate =20 +config SND_SOC_WCD_COMMON + tristate + config SND_SOC_WCD9335 tristate "WCD9335 Codec" depends on SLIMBUS select REGMAP_SLIMBUS select REGMAP_IRQ select SND_SOC_WCD_CLASSH + select SND_SOC_WCD_COMMON help The WCD9335 is a standalone Hi-Fi audio CODEC IC, supports Qualcomm Technologies, Inc. (QTI) multimedia solutions, @@ -2272,6 +2276,7 @@ config SND_SOC_WCD934X select REGMAP_IRQ select REGMAP_SLIMBUS select SND_SOC_WCD_CLASSH + select SND_SOC_WCD_COMMON select SND_SOC_WCD_MBHC depends on MFD_WCD934X || COMPILE_TEST help @@ -2283,6 +2288,7 @@ config SND_SOC_WCD937X tristate depends on SOUNDWIRE || !SOUNDWIRE select SND_SOC_WCD_CLASSH + select SND_SOC_WCD_COMMON =20 config SND_SOC_WCD937X_SDW tristate "WCD9370/WCD9375 Codec - SDW" @@ -2302,6 +2308,7 @@ config SND_SOC_WCD938X tristate depends on SOUNDWIRE || !SOUNDWIRE select SND_SOC_WCD_CLASSH + select SND_SOC_WCD_COMMON select MULTIPLEXER =20 config SND_SOC_WCD938X_SDW @@ -2321,6 +2328,7 @@ config SND_SOC_WCD939X depends on SOUNDWIRE || !SOUNDWIRE depends on TYPEC || !TYPEC select SND_SOC_WCD_CLASSH + select SND_SOC_WCD_COMMON =20 config SND_SOC_WCD939X_SDW tristate "WCD9390/WCD9395 Codec - SDW" diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index a476d6c45451..8d9bc03ecc60 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -341,6 +341,7 @@ snd-soc-uda1334-y :=3D uda1334.o snd-soc-uda1342-y :=3D uda1342.o snd-soc-uda1380-y :=3D uda1380.o snd-soc-wcd-classh-y :=3D wcd-clsh-v2.o +snd-soc-wcd-common-y :=3D wcd-common.o snd-soc-wcd-mbhc-y :=3D wcd-mbhc-v2.o snd-soc-wcd9335-y :=3D wcd9335.o snd-soc-wcd934x-y :=3D wcd934x.o @@ -764,6 +765,7 @@ obj-$(CONFIG_SND_SOC_UDA1334) +=3D snd-soc-uda1334.o obj-$(CONFIG_SND_SOC_UDA1342) +=3D snd-soc-uda1342.o obj-$(CONFIG_SND_SOC_UDA1380) +=3D snd-soc-uda1380.o obj-$(CONFIG_SND_SOC_WCD_CLASSH) +=3D snd-soc-wcd-classh.o +obj-$(CONFIG_SND_SOC_WCD_COMMON) +=3D snd-soc-wcd-common.o obj-$(CONFIG_SND_SOC_WCD_MBHC) +=3D snd-soc-wcd-mbhc.o obj-$(CONFIG_SND_SOC_WCD9335) +=3D snd-soc-wcd9335.o obj-$(CONFIG_SND_SOC_WCD934X) +=3D snd-soc-wcd934x.o diff --git a/sound/soc/codecs/wcd-common.c b/sound/soc/codecs/wcd-common.c new file mode 100644 index 000000000000..dffb0431a48c --- /dev/null +++ b/sound/soc/codecs/wcd-common.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved. + +#include +#include +#include +#include +#include +#include + +#include "wcd-common.h" + +int wcd_get_micb_vout_ctl_val(struct device *dev, u32 micb_mv) +{ + /* min micbias voltage is 1V and maximum is 2.85V */ + if (micb_mv < WCD_MIN_MICBIAS_MV || micb_mv > WCD_MAX_MICBIAS_MV) { + dev_err(dev, "Unsupported micbias voltage (%u mV)\n", micb_mv); + return -EINVAL; + } + + return (micb_mv - WCD_MIN_MICBIAS_MV) / 50; +} +EXPORT_SYMBOL_GPL(wcd_get_micb_vout_ctl_val); + +static int wcd_get_micbias_val(struct device *dev, int micb_num, u32 *micb= _mv) +{ + char micbias[32]; + int mv; + + sprintf(micbias, "qcom,micbias%d-microvolt", micb_num); + + if (of_property_read_u32(dev->of_node, micbias, &mv)) { + dev_err(dev, "%s value not found, using default\n", micbias); + mv =3D WCD_DEF_MICBIAS_MV; + } else { + /* convert it to milli volts */ + mv =3D mv/1000; + } + if (micb_mv) + *micb_mv =3D mv; + + mv =3D wcd_get_micb_vout_ctl_val(dev, mv); + if (mv < 0) { + dev_err(dev, "Unsupported %s voltage (%d mV), falling back to default (%= d mV)\n", + micbias, mv, WCD_DEF_MICBIAS_MV); + return wcd_get_micb_vout_ctl_val(dev, WCD_DEF_MICBIAS_MV); + } + + return mv; +} + +int wcd_dt_parse_micbias_info(struct wcd_common *common) +{ + int i; + + for (i =3D 0; i < common->max_bias; i++) { + common->micb_vout[i] =3D wcd_get_micbias_val(common->dev, i+1, &common->= micb_mv[i]); + if (common->micb_vout[i] < 0) + return -EINVAL; + } + + return 0; +} +EXPORT_SYMBOL_GPL(wcd_dt_parse_micbias_info); +MODULE_DESCRIPTION("Common Qualcomm WCD Codec helpers driver"); +MODULE_LICENSE("GPL"); diff --git a/sound/soc/codecs/wcd-common.h b/sound/soc/codecs/wcd-common.h new file mode 100644 index 000000000000..08c8e7ce9814 --- /dev/null +++ b/sound/soc/codecs/wcd-common.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef __WCD_COMMON_H__ +#define __WCD_COMMON_H___ + +#define WCD_MIN_MICBIAS_MV 1000 +#define WCD_DEF_MICBIAS_MV 1800 +#define WCD_MAX_MICBIAS_MV 2850 +#define WCD_MAX_MICBIAS 4 + +struct wcd_common { + struct device *dev; + int max_bias; + u32 micb_mv[WCD_MAX_MICBIAS]; + u32 micb_vout[WCD_MAX_MICBIAS]; +}; + +int wcd_get_micb_vout_ctl_val(struct device *dev, u32 micb_mv); +int wcd_dt_parse_micbias_info(struct wcd_common *common); + +#endif /* __WCD_COMMON_H___ */ diff --git a/sound/soc/codecs/wcd934x.c b/sound/soc/codecs/wcd934x.c index 1bb7e1dc7e6b..d10b457e6c9a 100644 --- a/sound/soc/codecs/wcd934x.c +++ b/sound/soc/codecs/wcd934x.c @@ -21,6 +21,7 @@ #include #include #include "wcd-clsh-v2.h" +#include "wcd-common.h" #include "wcd-mbhc-v2.h" =20 #include @@ -116,9 +117,6 @@ #define WCD934X_DEC_PWR_LVL_DF 0x00 #define WCD934X_DEC_PWR_LVL_HYBRID WCD934X_DEC_PWR_LVL_DF =20 -#define WCD934X_DEF_MICBIAS_MV 1800 -#define WCD934X_MAX_MICBIAS_MV 2850 - #define WCD_IIR_FILTER_SIZE (sizeof(u32) * BAND_MAX) =20 #define WCD_IIR_FILTER_CTL(xname, iidx, bidx) \ @@ -530,6 +528,7 @@ struct wcd934x_codec { struct slim_device *sdev; struct slim_device *sidev; struct wcd_clsh_ctrl *clsh_ctrl; + struct wcd_common common; struct snd_soc_component *component; struct wcd934x_slim_ch rx_chs[WCD934X_RX_MAX]; struct wcd934x_slim_ch tx_chs[WCD934X_TX_MAX]; @@ -555,7 +554,6 @@ struct wcd934x_codec { struct mutex micb_lock; u32 micb_ref[WCD934X_MAX_MICBIAS]; u32 pullup_ref[WCD934X_MAX_MICBIAS]; - u32 micb2_mv; }; =20 #define to_wcd934x_codec(_hw) container_of(_hw, struct wcd934x_codec, hw) @@ -2168,55 +2166,24 @@ static struct clk *wcd934x_register_mclk_output(str= uct wcd934x_codec *wcd) return NULL; } =20 -static int wcd934x_get_micbias_val(struct device *dev, const char *micbias, - u32 *micb_mv) -{ - int mv; - - if (of_property_read_u32(dev->parent->of_node, micbias, &mv)) { - dev_err(dev, "%s value not found, using default\n", micbias); - mv =3D WCD934X_DEF_MICBIAS_MV; - } else { - /* convert it to milli volts */ - mv =3D mv/1000; - } - - if (mv < 1000 || mv > 2850) { - dev_err(dev, "%s value not in valid range, using default\n", - micbias); - mv =3D WCD934X_DEF_MICBIAS_MV; - } - - if (micb_mv) - *micb_mv =3D mv; - - return (mv - 1000) / 50; -} - static int wcd934x_init_dmic(struct snd_soc_component *comp) { - int vout_ctl_1, vout_ctl_2, vout_ctl_3, vout_ctl_4; struct wcd934x_codec *wcd =3D dev_get_drvdata(comp->dev); u32 def_dmic_rate, dmic_clk_drv; + int ret; =20 - vout_ctl_1 =3D wcd934x_get_micbias_val(comp->dev, - "qcom,micbias1-microvolt", NULL); - vout_ctl_2 =3D wcd934x_get_micbias_val(comp->dev, - "qcom,micbias2-microvolt", - &wcd->micb2_mv); - vout_ctl_3 =3D wcd934x_get_micbias_val(comp->dev, - "qcom,micbias3-microvolt", NULL); - vout_ctl_4 =3D wcd934x_get_micbias_val(comp->dev, - "qcom,micbias4-microvolt", NULL); + ret =3D wcd_dt_parse_mbhc_data(comp->dev, &wcd->mbhc_cfg); + if (ret) + return ret; =20 snd_soc_component_update_bits(comp, WCD934X_ANA_MICB1, - WCD934X_MICB_VAL_MASK, vout_ctl_1); + WCD934X_MICB_VAL_MASK, wcd->common.micb_vout[0]); snd_soc_component_update_bits(comp, WCD934X_ANA_MICB2, - WCD934X_MICB_VAL_MASK, vout_ctl_2); + WCD934X_MICB_VAL_MASK, wcd->common.micb_vout[1]); snd_soc_component_update_bits(comp, WCD934X_ANA_MICB3, - WCD934X_MICB_VAL_MASK, vout_ctl_3); + WCD934X_MICB_VAL_MASK, wcd->common.micb_vout[2]); snd_soc_component_update_bits(comp, WCD934X_ANA_MICB4, - WCD934X_MICB_VAL_MASK, vout_ctl_4); + WCD934X_MICB_VAL_MASK, wcd->common.micb_vout[3]); =20 if (wcd->rate =3D=3D WCD934X_MCLK_CLK_9P6MHZ) def_dmic_rate =3D WCD9XXX_DMIC_SAMPLE_RATE_4P8MHZ; @@ -2517,15 +2484,6 @@ static void wcd934x_mbhc_micb_ramp_control(struct sn= d_soc_component *component, } } =20 -static int wcd934x_get_micb_vout_ctl_val(u32 micb_mv) -{ - /* min micbias voltage is 1V and maximum is 2.85V */ - if (micb_mv < 1000 || micb_mv > 2850) - return -EINVAL; - - return (micb_mv - 1000) / 50; -} - static int wcd934x_mbhc_micb_adjust_voltage(struct snd_soc_component *comp= onent, int req_volt, int micb_num) { @@ -2562,7 +2520,7 @@ static int wcd934x_mbhc_micb_adjust_voltage(struct sn= d_soc_component *component, cur_vout_ctl =3D snd_soc_component_read_field(component, micb_reg, WCD934X_MICB_VAL_MASK); =20 - req_vout_ctl =3D wcd934x_get_micb_vout_ctl_val(req_volt); + req_vout_ctl =3D wcd_get_micb_vout_ctl_val(component->dev, req_volt); if (req_vout_ctl < 0) { ret =3D -EINVAL; goto exit; @@ -2610,10 +2568,10 @@ static int wcd934x_mbhc_micb_ctrl_threshold_mic(str= uct snd_soc_component *compon * voltage needed to detect threshold microphone, then do * not change the micbias, just return. */ - if (wcd934x->micb2_mv >=3D WCD_MBHC_THR_HS_MICB_MV) + if (wcd934x->common.micb_mv[1] >=3D WCD_MBHC_THR_HS_MICB_MV) return 0; =20 - micb_mv =3D req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd934x->micb2_mv; + micb_mv =3D req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd934x->common.micb_mv[1]; =20 rc =3D wcd934x_mbhc_micb_adjust_voltage(component, micb_mv, MIC_BIAS_2); =20 @@ -3036,7 +2994,7 @@ static void wcd934x_mbhc_deinit(struct snd_soc_compon= ent *component) static int wcd934x_comp_probe(struct snd_soc_component *component) { struct wcd934x_codec *wcd =3D dev_get_drvdata(component->dev); - int i; + int i, ret; =20 snd_soc_component_init_regmap(component, wcd->regmap); wcd->component =3D component; @@ -3054,7 +3012,12 @@ static int wcd934x_comp_probe(struct snd_soc_compone= nt *component) for (i =3D 0; i < NUM_CODEC_DAIS; i++) INIT_LIST_HEAD(&wcd->dai[i].slim_ch_list); =20 - wcd934x_init_dmic(component); + + ret =3D wcd934x_init_dmic(component); + if (ret) { + dev_err(component->dev, "Failed to Initialize micbias\n"); + return ret; + } =20 if (wcd934x_mbhc_init(component)) dev_err(component->dev, "Failed to Initialize MBHC\n"); @@ -5860,14 +5823,13 @@ static int wcd934x_codec_parse_data(struct wcd934x_= codec *wcd) cfg->anc_micbias =3D MIC_BIAS_2; cfg->v_hs_max =3D WCD_MBHC_HS_V_MAX; cfg->num_btn =3D WCD934X_MBHC_MAX_BUTTONS; - cfg->micb_mv =3D wcd->micb2_mv; + cfg->micb_mv =3D wcd->common.micb_mv[1]; cfg->linein_th =3D 5000; cfg->hs_thr =3D 1700; cfg->hph_thr =3D 50; =20 wcd_dt_parse_mbhc_data(dev, cfg); =20 - return 0; } =20 @@ -5888,6 +5850,8 @@ static int wcd934x_codec_probe(struct platform_device= *pdev) wcd->sdev =3D to_slim_device(data->dev); mutex_init(&wcd->sysclk_mutex); mutex_init(&wcd->micb_lock); + wcd->common.dev =3D dev->parent; + wcd->common.max_bias =3D 4; =20 ret =3D wcd934x_codec_parse_data(wcd); if (ret) diff --git a/sound/soc/codecs/wcd937x.c b/sound/soc/codecs/wcd937x.c index b78f37c582ca..5c8faff3976d 100644 --- a/sound/soc/codecs/wcd937x.c +++ b/sound/soc/codecs/wcd937x.c @@ -21,6 +21,7 @@ #include =20 #include "wcd-clsh-v2.h" +#include "wcd-common.h" #include "wcd-mbhc-v2.h" #include "wcd937x.h" =20 @@ -85,6 +86,7 @@ struct wcd937x_priv { struct wcd_mbhc_config mbhc_cfg; struct wcd_mbhc_intr intr_ids; struct wcd_clsh_ctrl *clsh_info; + struct wcd_common common; struct irq_domain *virq; struct regmap_irq_chip_data *irq_chip; struct snd_soc_jack *jack; @@ -93,9 +95,6 @@ struct wcd937x_priv { s32 pullup_ref[WCD937X_MAX_MICBIAS]; u32 hph_mode; int ear_rx_path; - u32 micb1_mv; - u32 micb2_mv; - u32 micb3_mv; int hphr_pdm_wd_int; int hphl_pdm_wd_int; int aux_pdm_wd_int; @@ -872,15 +871,6 @@ static int wcd937x_enable_rx3(struct snd_soc_dapm_widg= et *w, return 0; } =20 -static int wcd937x_get_micb_vout_ctl_val(u32 micb_mv) -{ - if (micb_mv < 1000 || micb_mv > 2850) { - pr_err("Unsupported micbias voltage (%u mV)\n", micb_mv); - return -EINVAL; - } - - return (micb_mv - 1000) / 50; -} =20 static int wcd937x_tx_swr_ctrl(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) @@ -1481,7 +1471,7 @@ static int wcd937x_mbhc_micb_adjust_voltage(struct sn= d_soc_component *component, cur_vout_ctl =3D snd_soc_component_read_field(component, micb_reg, WCD937X_MICB_VOUT_MASK); =20 - req_vout_ctl =3D wcd937x_get_micb_vout_ctl_val(req_volt); + req_vout_ctl =3D wcd_get_micb_vout_ctl_val(component->dev, req_volt); if (req_vout_ctl < 0) { ret =3D -EINVAL; goto exit; @@ -2436,22 +2426,14 @@ static const struct snd_soc_dapm_route wcd9375_audi= o_map[] =3D { { "DMIC6_MIXER", "Switch", "DMIC6" }, }; =20 -static int wcd937x_set_micbias_data(struct wcd937x_priv *wcd937x) +static void wcd937x_set_micbias_data(struct device *dev, struct wcd937x_pr= iv *wcd937x) { - int vout_ctl[3]; - - /* Set micbias voltage */ - vout_ctl[0] =3D wcd937x_get_micb_vout_ctl_val(wcd937x->micb1_mv); - vout_ctl[1] =3D wcd937x_get_micb_vout_ctl_val(wcd937x->micb2_mv); - vout_ctl[2] =3D wcd937x_get_micb_vout_ctl_val(wcd937x->micb3_mv); - if ((vout_ctl[0] | vout_ctl[1] | vout_ctl[2]) < 0) - return -EINVAL; - - regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB1, WCD937X_ANA_MICB_V= OUT, vout_ctl[0]); - regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB2, WCD937X_ANA_MICB_V= OUT, vout_ctl[1]); - regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB3, WCD937X_ANA_MICB_V= OUT, vout_ctl[2]); - - return 0; + regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB1, WCD937X_ANA_MICB_V= OUT, + wcd937x->commmon.micb_vout[0]); + regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB2, WCD937X_ANA_MICB_V= OUT, + wcd937x->commmon.micb_vout[1]); + regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB3, WCD937X_ANA_MICB_V= OUT, + wcd937x->commmon.micb_vout[2]); } =20 static irqreturn_t wcd937x_wd_handle_irq(int irq, void *data) @@ -2630,31 +2612,6 @@ static const struct snd_soc_component_driver soc_cod= ec_dev_wcd937x =3D { .endianness =3D 1, }; =20 -static void wcd937x_dt_parse_micbias_info(struct device *dev, struct wcd93= 7x_priv *wcd) -{ - struct device_node *np =3D dev->of_node; - u32 prop_val =3D 0; - int ret =3D 0; - - ret =3D of_property_read_u32(np, "qcom,micbias1-microvolt", &prop_val); - if (!ret) - wcd->micb1_mv =3D prop_val / 1000; - else - dev_warn(dev, "Micbias1 DT property not found\n"); - - ret =3D of_property_read_u32(np, "qcom,micbias2-microvolt", &prop_val); - if (!ret) - wcd->micb2_mv =3D prop_val / 1000; - else - dev_warn(dev, "Micbias2 DT property not found\n"); - - ret =3D of_property_read_u32(np, "qcom,micbias3-microvolt", &prop_val); - if (!ret) - wcd->micb3_mv =3D prop_val / 1000; - else - dev_warn(dev, "Micbias3 DT property not found\n"); -} - static bool wcd937x_swap_gnd_mic(struct snd_soc_component *component) { int value; @@ -2848,11 +2805,7 @@ static int wcd937x_bind(struct device *dev) wcd937x->sdw_priv[AIF1_PB]->slave_irq =3D wcd937x->virq; wcd937x->sdw_priv[AIF1_CAP]->slave_irq =3D wcd937x->virq; =20 - ret =3D wcd937x_set_micbias_data(wcd937x); - if (ret < 0) { - dev_err(dev, "Bad micbias pdata\n"); - return ret; - } + wcd937x_set_micbias_data(dev, wcd937x); =20 ret =3D snd_soc_register_component(dev, &soc_codec_dev_wcd937x, wcd937x_dais, ARRAY_SIZE(wcd937x_dais)); @@ -2920,6 +2873,8 @@ static int wcd937x_probe(struct platform_device *pdev) =20 dev_set_drvdata(dev, wcd937x); mutex_init(&wcd937x->micb_lock); + wcd937x->common.dev =3D dev; + wcd937x->common.max_bias =3D 3; =20 wcd937x->reset_gpio =3D devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); if (IS_ERR(wcd937x->reset_gpio)) @@ -2939,7 +2894,9 @@ static int wcd937x_probe(struct platform_device *pdev) if (ret) return dev_err_probe(dev, ret, "Failed to get and enable supplies\n"); =20 - wcd937x_dt_parse_micbias_info(dev, wcd937x); + ret =3D wcd_dt_parse_micbias_info(dev, &wcd937x->common); + if (ret) + return dev_err_probe(dev, ret, "Failed to get micbias\n"); =20 cfg->mbhc_micbias =3D MIC_BIAS_2; cfg->anc_micbias =3D MIC_BIAS_2; diff --git a/sound/soc/codecs/wcd937x.h b/sound/soc/codecs/wcd937x.h index 49e5dce6f8c9..0f96b7108a7e 100644 --- a/sound/soc/codecs/wcd937x.h +++ b/sound/soc/codecs/wcd937x.h @@ -550,21 +550,21 @@ int wcd937x_sdw_hw_params(struct wcd937x_sdw_priv *wc= d, struct snd_soc_dai *dai); =20 #else -int wcd937x_sdw_free(struct wcd937x_sdw_priv *wcd, +static inline int wcd937x_sdw_free(struct wcd937x_sdw_priv *wcd, struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { return -EOPNOTSUPP; } =20 -int wcd937x_sdw_set_sdw_stream(struct wcd937x_sdw_priv *wcd, +static inline int wcd937x_sdw_set_sdw_stream(struct wcd937x_sdw_priv *wcd, struct snd_soc_dai *dai, void *stream, int direction) { return -EOPNOTSUPP; } =20 -int wcd937x_sdw_hw_params(struct wcd937x_sdw_priv *wcd, +static inline int wcd937x_sdw_hw_params(struct wcd937x_sdw_priv *wcd, struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) diff --git a/sound/soc/codecs/wcd938x.c b/sound/soc/codecs/wcd938x.c index f8d7bf27a6ed..6d77cbcafa70 100644 --- a/sound/soc/codecs/wcd938x.c +++ b/sound/soc/codecs/wcd938x.c @@ -155,6 +155,7 @@ struct wcd938x_priv { struct wcd_mbhc_config mbhc_cfg; struct wcd_mbhc_intr intr_ids; struct wcd_clsh_ctrl *clsh_info; + struct wcd_common common; struct irq_domain *virq; struct regmap_irq_chip_data *irq_chip; struct snd_soc_jack *jack; @@ -169,10 +170,6 @@ struct wcd938x_priv { struct gpio_desc *us_euro_gpio; struct mux_control *us_euro_mux; unsigned int mux_state; - u32 micb1_mv; - u32 micb2_mv; - u32 micb3_mv; - u32 micb4_mv; int hphr_pdm_wd_int; int hphl_pdm_wd_int; int aux_pdm_wd_int; @@ -1974,15 +1971,6 @@ static void wcd938x_mbhc_micb_ramp_control(struct sn= d_soc_component *component, } } =20 -static int wcd938x_get_micb_vout_ctl_val(u32 micb_mv) -{ - /* min micbias voltage is 1V and maximum is 2.85V */ - if (micb_mv < 1000 || micb_mv > 2850) - return -EINVAL; - - return (micb_mv - 1000) / 50; -} - static int wcd938x_mbhc_micb_adjust_voltage(struct snd_soc_component *comp= onent, int req_volt, int micb_num) { @@ -2019,7 +2007,7 @@ static int wcd938x_mbhc_micb_adjust_voltage(struct sn= d_soc_component *component, cur_vout_ctl =3D snd_soc_component_read_field(component, micb_reg, WCD938X_MICB_VOUT_MASK); =20 - req_vout_ctl =3D wcd938x_get_micb_vout_ctl_val(req_volt); + req_vout_ctl =3D wcd_get_micb_vout_ctl_val(component->dev, req_volt); if (req_vout_ctl < 0) { ret =3D -EINVAL; goto exit; @@ -2067,10 +2055,10 @@ static int wcd938x_mbhc_micb_ctrl_threshold_mic(str= uct snd_soc_component *compon * voltage needed to detect threshold microphone, then do * not change the micbias, just return. */ - if (wcd938x->micb2_mv >=3D WCD_MBHC_THR_HS_MICB_MV) + if (wcd938x->common.micb_mv[2] >=3D WCD_MBHC_THR_HS_MICB_MV) return 0; =20 - micb_mv =3D req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd938x->micb2_mv; + micb_mv =3D req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd938x->common.micb_mv[2]; =20 return wcd938x_mbhc_micb_adjust_voltage(component, micb_mv, MIC_BIAS_2); } @@ -2975,28 +2963,16 @@ static const struct snd_soc_dapm_route wcd938x_audi= o_map[] =3D { {"EAR", NULL, "EAR PGA"}, }; =20 -static int wcd938x_set_micbias_data(struct wcd938x_priv *wcd938x) +static void wcd938x_set_micbias_data(struct device *dev, struct wcd938x_pr= iv *wcd938x) { - int vout_ctl_1, vout_ctl_2, vout_ctl_3, vout_ctl_4; - - /* set micbias voltage */ - vout_ctl_1 =3D wcd938x_get_micb_vout_ctl_val(wcd938x->micb1_mv); - vout_ctl_2 =3D wcd938x_get_micb_vout_ctl_val(wcd938x->micb2_mv); - vout_ctl_3 =3D wcd938x_get_micb_vout_ctl_val(wcd938x->micb3_mv); - vout_ctl_4 =3D wcd938x_get_micb_vout_ctl_val(wcd938x->micb4_mv); - if (vout_ctl_1 < 0 || vout_ctl_2 < 0 || vout_ctl_3 < 0 || vout_ctl_4 < 0) - return -EINVAL; - regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB1, - WCD938X_MICB_VOUT_MASK, vout_ctl_1); + WCD938X_MICB_VOUT_MASK, wcd938x->common.micb_vout[0]); regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB2, - WCD938X_MICB_VOUT_MASK, vout_ctl_2); + WCD938X_MICB_VOUT_MASK, wcd938x->common.micb_vout[1]); regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB3, - WCD938X_MICB_VOUT_MASK, vout_ctl_3); + WCD938X_MICB_VOUT_MASK, wcd938x->common.micb_vout[2]); regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB4, - WCD938X_MICB_VOUT_MASK, vout_ctl_4); - - return 0; + WCD938X_MICB_VOUT_MASK, wcd938x->common.micb_vout[3]); } =20 static irqreturn_t wcd938x_wd_handle_irq(int irq, void *data) @@ -3200,37 +3176,6 @@ static const struct snd_soc_component_driver soc_cod= ec_dev_wcd938x =3D { .endianness =3D 1, }; =20 -static void wcd938x_dt_parse_micbias_info(struct device *dev, struct wcd93= 8x_priv *wcd) -{ - struct device_node *np =3D dev->of_node; - u32 prop_val =3D 0; - int rc =3D 0; - - rc =3D of_property_read_u32(np, "qcom,micbias1-microvolt", &prop_val); - if (!rc) - wcd->micb1_mv =3D prop_val/1000; - else - dev_info(dev, "%s: Micbias1 DT property not found\n", __func__); - - rc =3D of_property_read_u32(np, "qcom,micbias2-microvolt", &prop_val); - if (!rc) - wcd->micb2_mv =3D prop_val/1000; - else - dev_info(dev, "%s: Micbias2 DT property not found\n", __func__); - - rc =3D of_property_read_u32(np, "qcom,micbias3-microvolt", &prop_val); - if (!rc) - wcd->micb3_mv =3D prop_val/1000; - else - dev_info(dev, "%s: Micbias3 DT property not found\n", __func__); - - rc =3D of_property_read_u32(np, "qcom,micbias4-microvolt", &prop_val); - if (!rc) - wcd->micb4_mv =3D prop_val/1000; - else - dev_info(dev, "%s: Micbias4 DT property not found\n", __func__); -} - static bool wcd938x_swap_gnd_mic(struct snd_soc_component *component) { struct wcd938x_priv *wcd938x =3D snd_soc_component_get_drvdata(component); @@ -3295,13 +3240,15 @@ static int wcd938x_populate_dt_data(struct wcd938x_= priv *wcd938x, struct device if (ret) return dev_err_probe(dev, ret, "Failed to get and enable supplies\n"); =20 - wcd938x_dt_parse_micbias_info(dev, wcd938x); + ret =3D wcd_dt_parse_micbias_info(&wcd938x->common); + if (ret) + return dev_err_probe(dev, ret, "Failed to get and enable supplies\n"); =20 cfg->mbhc_micbias =3D MIC_BIAS_2; cfg->anc_micbias =3D MIC_BIAS_2; cfg->v_hs_max =3D WCD_MBHC_HS_V_MAX; cfg->num_btn =3D WCD938X_MBHC_MAX_BUTTONS; - cfg->micb_mv =3D wcd938x->micb2_mv; + cfg->micb_mv =3D wcd938x->common.micb_mv[2]; cfg->linein_th =3D 5000; cfg->hs_thr =3D 1700; cfg->hph_thr =3D 50; @@ -3457,11 +3404,7 @@ static int wcd938x_bind(struct device *dev) wcd938x->sdw_priv[AIF1_PB]->slave_irq =3D wcd938x->virq; wcd938x->sdw_priv[AIF1_CAP]->slave_irq =3D wcd938x->virq; =20 - ret =3D wcd938x_set_micbias_data(wcd938x); - if (ret < 0) { - dev_err(dev, "%s: bad micbias pdata\n", __func__); - goto err_remove_rx_link; - } + wcd938x_set_micbias_data(dev, wcd938x); =20 ret =3D snd_soc_register_component(dev, &soc_codec_dev_wcd938x, wcd938x_dais, ARRAY_SIZE(wcd938x_dais)); @@ -3550,6 +3493,8 @@ static int wcd938x_probe(struct platform_device *pdev) =20 dev_set_drvdata(dev, wcd938x); mutex_init(&wcd938x->micb_lock); + wcd938x->common.dev =3D dev; + wcd938x->common.max_bias =3D 4; =20 ret =3D wcd938x_populate_dt_data(wcd938x, dev); if (ret) diff --git a/sound/soc/codecs/wcd938x.h b/sound/soc/codecs/wcd938x.h index 54ee56b7fbd6..a6fda63d7f98 100644 --- a/sound/soc/codecs/wcd938x.h +++ b/sound/soc/codecs/wcd938x.h @@ -3,6 +3,7 @@ #define __WCD938X_H__ #include #include +#include "wcd-common.h" =20 #define WCD938X_BASE_ADDRESS (0x3000) #define WCD938X_ANA_PAGE_REGISTER (0x3000) diff --git a/sound/soc/codecs/wcd939x.c b/sound/soc/codecs/wcd939x.c index 85730ae40c2c..ef8def695219 100644 --- a/sound/soc/codecs/wcd939x.c +++ b/sound/soc/codecs/wcd939x.c @@ -191,6 +191,7 @@ struct wcd939x_priv { struct wcd_mbhc_config mbhc_cfg; struct wcd_mbhc_intr intr_ids; struct wcd_clsh_ctrl *clsh_info; + struct wcd_common common; struct irq_domain *virq; struct regmap_irq_chip_data *irq_chip; struct snd_soc_jack *jack; @@ -201,10 +202,6 @@ struct wcd939x_priv { u32 tx_mode[TX_ADC_MAX]; int variant; struct gpio_desc *reset_gpio; - u32 micb1_mv; - u32 micb2_mv; - u32 micb3_mv; - u32 micb4_mv; int hphr_pdm_wd_int; int hphl_pdm_wd_int; int ear_pdm_wd_int; @@ -1919,17 +1916,6 @@ static void wcd939x_mbhc_micb_ramp_control(struct sn= d_soc_component *component, } } =20 -static int wcd939x_get_micb_vout_ctl_val(u32 micb_mv) -{ - /* min micbias voltage is 1V and maximum is 2.85V */ - if (micb_mv < 1000 || micb_mv > 2850) { - pr_err("%s: unsupported micbias voltage\n", __func__); - return -EINVAL; - } - - return (micb_mv - 1000) / 50; -} - static int wcd939x_mbhc_micb_adjust_voltage(struct snd_soc_component *comp= onent, int req_volt, int micb_num) { @@ -1969,7 +1955,7 @@ static int wcd939x_mbhc_micb_adjust_voltage(struct sn= d_soc_component *component, cur_vout_ctl =3D snd_soc_component_read_field(component, micb_reg, WCD939X_MICB_VOUT_CTL); =20 - req_vout_ctl =3D wcd939x_get_micb_vout_ctl_val(req_volt); + req_vout_ctl =3D wcd_get_micb_vout_ctl_val(component->dev, req_volt); if (req_vout_ctl < 0) { ret =3D req_vout_ctl; goto exit; @@ -2021,10 +2007,10 @@ static int wcd939x_mbhc_micb_ctrl_threshold_mic(str= uct snd_soc_component *compon * voltage needed to detect threshold microphone, then do * not change the micbias, just return. */ - if (wcd939x->micb2_mv >=3D WCD_MBHC_THR_HS_MICB_MV) + if (wcd939x->common.micb_mv[1] >=3D WCD_MBHC_THR_HS_MICB_MV) return 0; =20 - micb_mv =3D req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd939x->micb2_mv; + micb_mv =3D req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd939x->common.micb_mv[1]; =20 return wcd939x_mbhc_micb_adjust_voltage(component, micb_mv, MIC_BIAS_2); } @@ -2895,28 +2881,16 @@ static const struct snd_soc_dapm_route wcd939x_audi= o_map[] =3D { {"EAR", NULL, "EAR PGA"}, }; =20 -static int wcd939x_set_micbias_data(struct wcd939x_priv *wcd939x) +static void wcd939x_set_micbias_data(struct device *dev, struct wcd939x_pr= iv *wcd939x) { - int vout_ctl_1, vout_ctl_2, vout_ctl_3, vout_ctl_4; - - /* set micbias voltage */ - vout_ctl_1 =3D wcd939x_get_micb_vout_ctl_val(wcd939x->micb1_mv); - vout_ctl_2 =3D wcd939x_get_micb_vout_ctl_val(wcd939x->micb2_mv); - vout_ctl_3 =3D wcd939x_get_micb_vout_ctl_val(wcd939x->micb3_mv); - vout_ctl_4 =3D wcd939x_get_micb_vout_ctl_val(wcd939x->micb4_mv); - if (vout_ctl_1 < 0 || vout_ctl_2 < 0 || vout_ctl_3 < 0 || vout_ctl_4 < 0) - return -EINVAL; - regmap_update_bits(wcd939x->regmap, WCD939X_ANA_MICB1, - WCD939X_MICB_VOUT_CTL, vout_ctl_1); + WCD939X_MICB_VOUT_CTL, wcd939x->common.micb_vout[0]); regmap_update_bits(wcd939x->regmap, WCD939X_ANA_MICB2, - WCD939X_MICB_VOUT_CTL, vout_ctl_2); + WCD939X_MICB_VOUT_CTL, wcd939x->common.micb_vout[1]); regmap_update_bits(wcd939x->regmap, WCD939X_ANA_MICB3, - WCD939X_MICB_VOUT_CTL, vout_ctl_3); + WCD939X_MICB_VOUT_CTL, wcd939x->common.micb_vout[2]); regmap_update_bits(wcd939x->regmap, WCD939X_ANA_MICB4, - WCD939X_MICB_VOUT_CTL, vout_ctl_4); - - return 0; + WCD939X_MICB_VOUT_CTL, wcd939x->common.micb_vout[3]); } =20 static irqreturn_t wcd939x_wd_handle_irq(int irq, void *data) @@ -3186,37 +3160,6 @@ static int wcd939x_typec_mux_set(struct typec_mux_de= v *mux, } #endif /* CONFIG_TYPEC */ =20 -static void wcd939x_dt_parse_micbias_info(struct device *dev, struct wcd93= 9x_priv *wcd) -{ - struct device_node *np =3D dev->of_node; - u32 prop_val =3D 0; - int rc =3D 0; - - rc =3D of_property_read_u32(np, "qcom,micbias1-microvolt", &prop_val); - if (!rc) - wcd->micb1_mv =3D prop_val / 1000; - else - dev_info(dev, "%s: Micbias1 DT property not found\n", __func__); - - rc =3D of_property_read_u32(np, "qcom,micbias2-microvolt", &prop_val); - if (!rc) - wcd->micb2_mv =3D prop_val / 1000; - else - dev_info(dev, "%s: Micbias2 DT property not found\n", __func__); - - rc =3D of_property_read_u32(np, "qcom,micbias3-microvolt", &prop_val); - if (!rc) - wcd->micb3_mv =3D prop_val / 1000; - else - dev_info(dev, "%s: Micbias3 DT property not found\n", __func__); - - rc =3D of_property_read_u32(np, "qcom,micbias4-microvolt", &prop_val); - if (!rc) - wcd->micb4_mv =3D prop_val / 1000; - else - dev_info(dev, "%s: Micbias4 DT property not found\n", __func__); -} - #if IS_ENABLED(CONFIG_TYPEC) static bool wcd939x_swap_gnd_mic(struct snd_soc_component *component) { @@ -3252,13 +3195,15 @@ static int wcd939x_populate_dt_data(struct wcd939x_= priv *wcd939x, struct device if (ret) return dev_err_probe(dev, ret, "Failed to get and enable supplies\n"); =20 - wcd939x_dt_parse_micbias_info(dev, wcd939x); + ret =3D wcd_dt_parse_micbias_info(&wcd939x->common); + if (ret) + return dev_err_probe(dev, ret, "Failed to get micbias\n"); =20 cfg->mbhc_micbias =3D MIC_BIAS_2; cfg->anc_micbias =3D MIC_BIAS_2; cfg->v_hs_max =3D WCD_MBHC_HS_V_MAX; cfg->num_btn =3D WCD939X_MBHC_MAX_BUTTONS; - cfg->micb_mv =3D wcd939x->micb2_mv; + cfg->micb_mv =3D wcd939x->common.micb_mv[1]; cfg->linein_th =3D 5000; cfg->hs_thr =3D 1700; cfg->hph_thr =3D 50; @@ -3444,11 +3389,7 @@ static int wcd939x_bind(struct device *dev) wcd939x->sdw_priv[AIF1_PB]->slave_irq =3D wcd939x->virq; wcd939x->sdw_priv[AIF1_CAP]->slave_irq =3D wcd939x->virq; =20 - ret =3D wcd939x_set_micbias_data(wcd939x); - if (ret < 0) { - dev_err(dev, "%s: bad micbias pdata\n", __func__); - goto err_remove_rx_link; - } + wcd939x_set_micbias_data(dev, wcd939x); =20 /* Check WCD9395 version */ regmap_read(wcd939x->regmap, WCD939X_DIGITAL_CHIP_ID1, &id1); @@ -3613,6 +3554,8 @@ static int wcd939x_probe(struct platform_device *pdev) =20 dev_set_drvdata(dev, wcd939x); mutex_init(&wcd939x->micb_lock); + wcd939x->common.dev =3D dev; + wcd939x->common.max_bias =3D 4; =20 ret =3D wcd939x_populate_dt_data(wcd939x, dev); if (ret) { diff --git a/sound/soc/codecs/wcd939x.h b/sound/soc/codecs/wcd939x.h index e70445b1a4bc..f587cf22f86f 100644 --- a/sound/soc/codecs/wcd939x.h +++ b/sound/soc/codecs/wcd939x.h @@ -8,6 +8,7 @@ #define __WCD939X_H__ #include #include +#include "wcd-common.h" =20 #define WCD939X_BASE (0x3000) #define WCD939X_ANA_PAGE (0x3000) --=20 2.50.0