From patchwork Wed Jun 26 15:36:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Keepax X-Patchwork-Id: 11018111 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DE94114BB for ; Wed, 26 Jun 2019 15:38:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C835C2843C for ; Wed, 26 Jun 2019 15:38:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B5D64287A3; Wed, 26 Jun 2019 15:38:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ECFD52843C for ; Wed, 26 Jun 2019 15:38:11 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id AB73916A0; Wed, 26 Jun 2019 17:37:18 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz AB73916A0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1561563488; bh=/1OLw00uA7MWP8BAQVPUUgYm7E2YZiGuKCsFf2qAxYA=; h=From:To:Date:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=I3ARCicg4MMN9Xxd/jYVxCuf90dh5KeVkC1Gr2aUJMqg1NVd4BAsHOn8paaP9QUSt Ko7IkZE/xW1bM1a6wmm3r9HpUTEdrURfF/+NZsjKUVTaEE070tSuW0uecSbomXtRl8 oF4//higavvErb4Z6bXl+ZFUPXIRug0nlfE1G+/o= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 783B5F896EC; Wed, 26 Jun 2019 17:36:24 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 062FBF896CC; Wed, 26 Jun 2019 17:36:20 +0200 (CEST) Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id B8AFFF8070C for ; Wed, 26 Jun 2019 17:36:17 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz B8AFFF8070C Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="AZVBIUfP" Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5QFXvHu023029; Wed, 26 Jun 2019 10:36:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=PODMain02222019; bh=YkPGMEnbp9ZPpVKCFAiuojkCOY39vkCxr96wQWpIFss=; b=AZVBIUfPkrJEJ3Fo7tfyE8Yr3k9p4acj+TR5IAqL5SBEQtM2TnuTwuAXc9sIfFKwDm22 hd4hVgQyz/XQcLlPokgzXpLkyDCJGVPWELexDS3S52sX7RU4TovtDryUElElaE6fFTpj ngn5hoSdP+f4F/T6wVIg1aFMREZ5cK5VA6KxH6ImNCrZlzC8bAucFso8F4wmXhs3BLi9 3F6x7UsjG+KagiJA1A/5ssQRw557dp/cVM/WyfdvhDz0a1tKEtHD5Q+P8RN+8HquQd9f abwq4m2JQCYxib1uXaJbrvWyODfOenlZqaqvefWEPj6TE+013BGazRLQ5SqzUs+ZSPap 3A== Authentication-Results: ppops.net; spf=none smtp.mailfrom=ckeepax@opensource.cirrus.com Received: from mail4.cirrus.com ([87.246.98.35]) by mx0b-001ae601.pphosted.com with ESMTP id 2tc7gt8cvy-1; Wed, 26 Jun 2019 10:36:13 -0500 Received: from EDIEX01.ad.cirrus.com (ediex01.ad.cirrus.com [198.61.84.80]) by mail4.cirrus.com (Postfix) with ESMTP id 36865611C8AF; Wed, 26 Jun 2019 10:36:14 -0500 (CDT) Received: from EDIEX01.ad.cirrus.com (198.61.84.80) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1591.10; Wed, 26 Jun 2019 16:36:11 +0100 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.1.1591.10 via Frontend Transport; Wed, 26 Jun 2019 16:36:11 +0100 Received: from algalon.ad.cirrus.com (algalon.ad.cirrus.com [198.90.251.122]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id D91DD45; Wed, 26 Jun 2019 16:36:11 +0100 (BST) From: Charles Keepax To: Date: Wed, 26 Jun 2019 16:36:10 +0100 Message-ID: <20190626153611.10170-1-ckeepax@opensource.cirrus.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906260182 Cc: alsa-devel@alsa-project.org, rafael@kernel.org, gregkh@linuxfoundation.org, lgirdwood@gmail.com, linux-acpi@vger.kernel.org, patches@opensource.cirrus.com Subject: [alsa-devel] [PATCH 1/2] device property: Add new array helper X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" X-Virus-Scanned: ClamAV using ClamSMTP It is fairly common to want to read an integer array property that is composed of an unknown number of fixed size integer groups. For example, say each group consists of three values which correspond to the settings for one input on the device and the driver supports several chips with different numbers of inputs. Add a new helper function to provide this functionality, it differs for the existing helpers in that it allows reading a smaller number of values than the full array size and checks that the number of values read is a multiple of the group size. Signed-off-by: Charles Keepax Acked-by: Greg Kroah-Hartman --- drivers/base/property.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/property.h | 2 ++ 2 files changed, 50 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index 348b37e64944c..656d21e01a648 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -133,6 +133,54 @@ int device_property_read_u32_array(struct device *dev, const char *propname, EXPORT_SYMBOL_GPL(device_property_read_u32_array); /** + * device_property_read_u32_2darray - return a 2d u32 array property of a device + * @dev: Device to get the property of + * @propname: Name of the property + * @val: The values are stored here or %NULL to return the number of values + * @nval: Size of the @val array + * @multiple: Number of entries in each block of data + * + * Function reads an array of u32 properties split up into fixed size + * sub-groups, with @propname from the device firmware description and + * stores them to @val if found. + * + * Return: Number of values read + * %0 if the property was not found, + * %-EINVAL if given arguments are not valid, + * %-ENODATA if the property does not have a value, + * %-EPROTO if the property is not an array of numbers, + * %-EOVERFLOW if the size of the property is not as expected. + * %-ENXIO if no suitable firmware interface is present. + */ +int device_property_read_u32_2darray(struct device *dev, const char *propname, + u32 *val, size_t nval, int multiple) +{ + int n, ret; + + n = device_property_read_u32_array(dev, propname, NULL, 0); + if (n == -EINVAL) { + return 0; /* missing, ignore */ + } else if (n < 0) { + dev_warn(dev, "%s malformed (%d)\n", propname, n); + return n; + } else if ((n % multiple) != 0) { + dev_warn(dev, "%s not a multiple of %d entries\n", + propname, multiple); + return -EOVERFLOW; + } + + if (n > nval) + n = nval; + + ret = device_property_read_u32_array(dev, propname, val, n); + if (ret < 0) + return ret; + else + return n; +} +EXPORT_SYMBOL_GPL(device_property_read_u32_2darray); + +/** * device_property_read_u64_array - return a u64 array property of a device * @dev: Device to get the property of * @propname: Name of the property diff --git a/include/linux/property.h b/include/linux/property.h index e9caa290cda52..5ab0b4a7d34a2 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -40,6 +40,8 @@ int device_property_read_u16_array(struct device *dev, const char *propname, u16 *val, size_t nval); int device_property_read_u32_array(struct device *dev, const char *propname, u32 *val, size_t nval); +int device_property_read_u32_2darray(struct device *dev, const char *propname, + u32 *val, size_t nval, int multiple); int device_property_read_u64_array(struct device *dev, const char *propname, u64 *val, size_t nval); int device_property_read_string_array(struct device *dev, const char *propname, From patchwork Wed Jun 26 15:36:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Keepax X-Patchwork-Id: 11018109 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 686F71575 for ; Wed, 26 Jun 2019 15:37:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5708A287C9 for ; Wed, 26 Jun 2019 15:37:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4AB8D287AB; Wed, 26 Jun 2019 15:37:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4767D2843C for ; Wed, 26 Jun 2019 15:37:15 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id C092D1680; Wed, 26 Jun 2019 17:36:23 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz C092D1680 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1561563433; bh=xFs4riGyNDgjYOC17bEirnvsSRGRaC4quFMejXUbK3M=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=LdDwVRY1WlkmOyj2DSMPMnpqEVKsf9VurLb8TXc8IIU0s82WTGhdWM5lXJ9LT8fYm 4dp9q6nrywSp/ysysX+oCC078W3rz4L0a8bDpQrfyG0oEzaWa4gLdmV2/gl67fLLcC IUPMip04o+wj/7Lm5x9Y6nkcGkBGUb8Br4iuRRgw= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 4A8F9F896B7; Wed, 26 Jun 2019 17:36:23 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1ECA5F896B7; Wed, 26 Jun 2019 17:36:20 +0200 (CEST) Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id E9D95F896B9 for ; Wed, 26 Jun 2019 17:36:17 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz E9D95F896B9 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="XdWeeh8/" Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5QFXYle022897; Wed, 26 Jun 2019 10:36:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=PODMain02222019; bh=AV/T2mCUaARe6CJNXa05QO9AoXOQYuMlU5+Mm4v9h3w=; b=XdWeeh8/g7cPQCN9AaHL6MEFcrJWxb2XFE8ed2AmWDVpcwSTd038KUHfAbYtBKH2Luwd FybTGQHiFQMcD/3Dx31Z7l0u8rq9QSRYTLxgaxTG1qpteafkaX1pRnDUtmGJxxtX1Pmj f6kC9ZifX+v1pcvmDxvseaKLnO/Pw4C9RsyELM1r9tHWWGtinl7HS7yvLGT8cyyltGOM 8YaTq95cb7u6gC61LYO+bYL1Xsq8v18UXkWGPX9LqrnpvKyZ0+yb9YxlDPCWsFpulcr/ rCQxjc8jXo4BwyWU0WEt3tIWhE5Op4surSd6h4Yu9aWdIfYGMAUezzh87Cl1mdwizV/5 Ng== Authentication-Results: ppops.net; spf=none smtp.mailfrom=ckeepax@opensource.cirrus.com Received: from mail4.cirrus.com ([87.246.98.35]) by mx0b-001ae601.pphosted.com with ESMTP id 2tc7gt8cvx-1; Wed, 26 Jun 2019 10:36:12 -0500 Received: from EDIEX01.ad.cirrus.com (ediex01.ad.cirrus.com [198.61.84.80]) by mail4.cirrus.com (Postfix) with ESMTP id 410D6611C8B1; Wed, 26 Jun 2019 10:36:14 -0500 (CDT) Received: from EDIEX01.ad.cirrus.com (198.61.84.80) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1591.10; Wed, 26 Jun 2019 16:36:11 +0100 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.1.1591.10 via Frontend Transport; Wed, 26 Jun 2019 16:36:11 +0100 Received: from algalon.ad.cirrus.com (algalon.ad.cirrus.com [198.90.251.122]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id DF64F2DA; Wed, 26 Jun 2019 16:36:11 +0100 (BST) From: Charles Keepax To: Date: Wed, 26 Jun 2019 16:36:11 +0100 Message-ID: <20190626153611.10170-2-ckeepax@opensource.cirrus.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190626153611.10170-1-ckeepax@opensource.cirrus.com> References: <20190626153611.10170-1-ckeepax@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906260182 Cc: alsa-devel@alsa-project.org, rafael@kernel.org, gregkh@linuxfoundation.org, lgirdwood@gmail.com, linux-acpi@vger.kernel.org, patches@opensource.cirrus.com Subject: [alsa-devel] [PATCH 2/2] ASoC: madera: Read device tree configuration X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" X-Virus-Scanned: ClamAV using ClamSMTP Read the configuration of the Madera sound driver from device tree using the new device tree helper function. Signed-off-by: Charles Keepax --- Note this patch depends on patches that are currently going through Mark's tree so probably best if this one also goes through there. Thanks, Charles sound/soc/codecs/madera.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/sound/soc/codecs/madera.c b/sound/soc/codecs/madera.c index 1b1be19a2f991..8fe16e4e19c7b 100644 --- a/sound/soc/codecs/madera.c +++ b/sound/soc/codecs/madera.c @@ -300,6 +300,68 @@ int madera_free_overheat(struct madera_priv *priv) } EXPORT_SYMBOL_GPL(madera_free_overheat); +static void madera_prop_get_inmode(struct madera_priv *priv) +{ + struct madera *madera = priv->madera; + struct madera_codec_pdata *pdata = &madera->pdata.codec; + u32 tmp[MADERA_MAX_INPUT * MADERA_MAX_MUXED_CHANNELS]; + int n, i, in_idx, ch_idx; + + BUILD_BUG_ON(ARRAY_SIZE(pdata->inmode) != MADERA_MAX_INPUT); + BUILD_BUG_ON(ARRAY_SIZE(pdata->inmode[0]) != MADERA_MAX_MUXED_CHANNELS); + + n = device_property_read_u32_2darray(madera->dev, "cirrus,inmode", + tmp, ARRAY_SIZE(tmp), + MADERA_MAX_MUXED_CHANNELS); + if (n < 0) + return; + + in_idx = 0; + ch_idx = 0; + for (i = 0; i < n; ++i) { + pdata->inmode[in_idx][ch_idx] = tmp[i]; + + if (++ch_idx == MADERA_MAX_MUXED_CHANNELS) { + ch_idx = 0; + ++in_idx; + } + } +} + +static void madera_prop_get_pdata(struct madera_priv *priv) +{ + struct madera *madera = priv->madera; + struct madera_codec_pdata *pdata = &madera->pdata.codec; + u32 out_mono[ARRAY_SIZE(pdata->out_mono)]; + int i, n; + + madera_prop_get_inmode(priv); + + n = device_property_read_u32_2darray(madera->dev, "cirrus,out-mono", + out_mono, ARRAY_SIZE(out_mono), 1); + if (n > 0) + for (i = 0; i < n; ++i) + pdata->out_mono[i] = !!out_mono[i]; + + device_property_read_u32_2darray(madera->dev, + "cirrus,max-channels-clocked", + pdata->max_channels_clocked, + ARRAY_SIZE(pdata->max_channels_clocked), + 1); + + device_property_read_u32_2darray(madera->dev, "cirrus,pdm-fmt", + pdata->pdm_fmt, + ARRAY_SIZE(pdata->pdm_fmt), 1); + + device_property_read_u32_2darray(madera->dev, "cirrus,pdm-mute", + pdata->pdm_mute, + ARRAY_SIZE(pdata->pdm_mute), 1); + + device_property_read_u32_2darray(madera->dev, "cirrus,dmic-ref", + pdata->dmic_ref, + ARRAY_SIZE(pdata->dmic_ref), 1); +} + int madera_core_init(struct madera_priv *priv) { int i; @@ -308,6 +370,9 @@ int madera_core_init(struct madera_priv *priv) BUILD_BUG_ON(!madera_mixer_texts[MADERA_NUM_MIXER_INPUTS - 1]); BUILD_BUG_ON(!madera_mixer_values[MADERA_NUM_MIXER_INPUTS - 1]); + if (!dev_get_platdata(priv->madera->dev)) + madera_prop_get_pdata(priv); + mutex_init(&priv->rate_lock); for (i = 0; i < MADERA_MAX_HP_OUTPUT; i++)