Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4322416rwd; Sat, 17 Jun 2023 11:13:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ48TPBoI+EjMz08RYBMLCbTscP/AbCktKpE5rh6qilEhDAFC45FM83+7xBv94i7UBNcM4Ij X-Received: by 2002:a05:6a20:158d:b0:118:e011:5e44 with SMTP id h13-20020a056a20158d00b00118e0115e44mr7476840pzj.48.1687025580822; Sat, 17 Jun 2023 11:13:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687025580; cv=none; d=google.com; s=arc-20160816; b=dsDQUm04uZRvhwKnBMuipk72iA3yrd7Ho0BN6NJEeXYNv9VuIhF15Mbc5QyVw+EG0Z YlawINAiNfcYlFTdgDsNqXtGuEL3gNwVP/fOjNFMNNDIZk3XCiTYeUi8NprgxDe1T3JL iu9yewrHNdrSOmGAxYUbfiYSeP8xAftVxd2MzBKc/RqMd0LRVSgeJIwq6DNeWHKErtW7 iu5fciGDSS/nW37PXwKykaNoG7c/wY1y4t9UBN6kDaKJz1kI8gaIRlFaS8A/9suLnhWC Eq6QthgE0tVzW+JQjW4CpM5QG/1k9MTxr3KpMObxHCueodmrw4ljRGaDDj7pIgp+4hBk kzfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=QS0ZpmFu8eRJ7uJrwHd1vTf7wyKx+QcdVUDZ/sHx/g0=; b=jn3fLTs+XTR4skQRHy9FDBCxZNsG6tyIrMHmV68Ambs74nnyWYKVDSPioIjRcCV9KK wIAgYpkGrHf7E3RLNDx7rZ+3SfC8RWV7snmiIJcl0b5IJxlyXS6qNCQfF7PjDGykRGlq dRfj/fX5qhR8LzgQE137Ai9NJknTDKT6lMitC2nNnk59/XSielJSq+aYp/9DQWOy3zFi wMqFsq/+mbzzIWEva+QDzIErFOyTfYPlBZfaZE3ITCLW0PjAIVl6eJ1T1LffhPBdstSd fhm+c+Av3vubVDj6QxJx0xxBb8CLe546ZvFpeoVswvbRWpnOzfNLdnEX9iQ2uZqG6f4N KvQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=naqtaYMt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c7-20020a637247000000b0053ef09db573si6352416pgn.247.2023.06.17.11.12.47; Sat, 17 Jun 2023 11:13:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=naqtaYMt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233713AbjFQSBk (ORCPT + 99 others); Sat, 17 Jun 2023 14:01:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229637AbjFQSBg (ORCPT ); Sat, 17 Jun 2023 14:01:36 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68C7A1729; Sat, 17 Jun 2023 11:01:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E3B4B61041; Sat, 17 Jun 2023 18:01:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7239DC433C0; Sat, 17 Jun 2023 18:01:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687024894; bh=RERf5RbZg+WAAGOHyyxJF20kJeK52BhhW35kQfeQM6A=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=naqtaYMtiG5Uj7Vcbfv5sFoudBw/ld7Tbza9e3k0Dm/mu0TFQTeFwwLOi5X4neHZK /oUtLmYcSs9tVImqb2mepYCsGWcrp4ecdegIft6Lot0hW1FBGd80W7W4OigegE+hnH 2BzNqbzmpDWcjEQlTfLzayMrraXefq8eYb+5kLSFBFMKYjWdpfboJrwyfKUXndVWTN TpY62tY3WHS0bOfK8PXcP4KrHdNg+np5G2hRKdhgshbRk3CqPbZQ66R2nnA0Qw+gt+ Ff5WO+rqV2wykkDcWOCBr5uEK4+3Ho4/o5tEvIQ4HM/d6ARMGZFcQv//KHcvGVYfCN yQiWsQiRcX7ZA== Date: Sat, 17 Jun 2023 19:01:25 +0100 From: Jonathan Cameron To: Herve Codina Cc: Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lars-Peter Clausen , Jaroslav Kysela , Takashi Iwai , Kuninori Morimoto , Andy Shevchenko , alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Christophe Leroy , Thomas Petazzoni Subject: Re: [PATCH v5 12/13] ASoC: codecs: Add support for the generic IIO auxiliary devices Message-ID: <20230617190125.147434b9@jic23-huawei> In-Reply-To: <20230615152631.224529-13-herve.codina@bootlin.com> References: <20230615152631.224529-1-herve.codina@bootlin.com> <20230615152631.224529-13-herve.codina@bootlin.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 15 Jun 2023 17:26:30 +0200 Herve Codina wrote: > Industrial I/O devices can be present in the audio path. > These devices needs to be used as audio components in order to be > fully integrated in the audio path. > > This support allows to consider these Industrial I/O devices as > auxiliary audio devices and allows one to control them using mixer > controls. > > Signed-off-by: Herve Codina A few trivial things inline. With those tidied up, (for the IIO bits and general code - but I don't know the snd part well enough to review that). Reviewed-by: Jonathan Cameron > index 000000000000..b9d72cbb85f2 > --- /dev/null > +++ b/sound/soc/codecs/audio-iio-aux.c > @@ -0,0 +1,338 @@ ... > +static int audio_iio_aux_add_controls(struct snd_soc_component *component, > + struct audio_iio_aux_chan *chan) > +{ > + struct snd_kcontrol_new control = {}; Why not: struct snd_kcontrol_new control = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER; .name = chan->name; .info = audio_iio_aux_info_volsw; .get = audio_iio_aux_get_volsw; .put = audio_iio_aux_put_volsw; .private_value = (unsigned long)chan; }; > + > + control.iface = SNDRV_CTL_ELEM_IFACE_MIXER; > + control.name = chan->name; > + control.info = audio_iio_aux_info_volsw; > + control.get = audio_iio_aux_get_volsw; > + control.put = audio_iio_aux_put_volsw; > + control.private_value = (unsigned long)chan; > + > + return snd_soc_add_component_controls(component, &control, 1); > +} > + > +/* > + * These data could be on stack but they are pretty big. > + * As ASoC internally copy them and protect them against concurrent accesses > + * (snd_soc_bind_card() protects using client_mutex), keep them in the global > + * data area. > + */ > +static struct snd_soc_dapm_widget widgets[3]; > +static struct snd_soc_dapm_route routes[2]; > + > +/* Be sure sizes are correct (need 3 widgets and 2 routes) */ > +static_assert(ARRAY_SIZE(widgets) >= 3, "3 widgets are needed"); > +static_assert(ARRAY_SIZE(routes) >= 2, "2 routes are needed"); > + > +static int audio_iio_aux_add_dapms(struct snd_soc_component *component, > + struct audio_iio_aux_chan *chan) > +{ > + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); > + char *output_name; > + char *input_name; > + char *pga_name; > + int ret; > + > + input_name = kasprintf(GFP_KERNEL, "%s IN", chan->name); > + if (!input_name) > + return -ENOMEM; > + > + output_name = kasprintf(GFP_KERNEL, "%s OUT", chan->name); > + if (!output_name) { > + ret = -ENOMEM; > + goto out_free_input_name; > + } Trivial but a blank line here would be nice. > + pga_name = kasprintf(GFP_KERNEL, "%s PGA", chan->name); > + if (!pga_name) { > + ret = -ENOMEM; > + goto out_free_output_name; > + } > + > + widgets[0] = SND_SOC_DAPM_INPUT(input_name); > + widgets[1] = SND_SOC_DAPM_OUTPUT(output_name); > + widgets[2] = SND_SOC_DAPM_PGA(pga_name, SND_SOC_NOPM, 0, 0, NULL, 0); > + ret = snd_soc_dapm_new_controls(dapm, widgets, 3); > + if (ret) > + goto out_free_pga_name; > + > + routes[0].sink = pga_name; > + routes[0].control = NULL; > + routes[0].source = input_name; > + routes[1].sink = output_name; > + routes[1].control = NULL; > + routes[1].source = pga_name; > + ret = snd_soc_dapm_add_routes(dapm, routes, 2); > + > + /* Allocated names are no more needed (duplicated in ASoC internals) */ > + > +out_free_pga_name: > + kfree(pga_name); > +out_free_output_name: > + kfree(output_name); > +out_free_input_name: > + kfree(input_name); > + return ret; > +} > + > +static int audio_iio_aux_component_probe(struct snd_soc_component *component) > +{ > + struct audio_iio_aux *iio_aux = snd_soc_component_get_drvdata(component); > + struct audio_iio_aux_chan *chan; > + int ret; > + int i; > + > + for (i = 0; i < iio_aux->num_chans; i++) { > + chan = iio_aux->chans + i; > + > + ret = iio_read_max_channel_raw(chan->iio_chan, &chan->max); > + if (ret) > + return dev_err_probe(component->dev, ret, > + "chan[%d] %s: Cannot get max raw value\n", > + i, chan->name); > + > + ret = iio_read_min_channel_raw(chan->iio_chan, &chan->min); > + if (ret) > + return dev_err_probe(component->dev, ret, > + "chan[%d] %s: Cannot get min raw value\n", > + i, chan->name); > + > + if (chan->min > chan->max) { > + dev_dbg(component->dev, "chan[%d] %s: Swap min and max\n", > + i, chan->name); Why? I'd like a comment here on what circumstances could cause this to happen. > + swap(chan->min, chan->max); > + } > + > + /* Set initial value */ > + ret = iio_write_channel_raw(chan->iio_chan, > + chan->is_invert_range ? chan->max : chan->min); > + if (ret) > + return dev_err_probe(component->dev, ret, > + "chan[%d] %s: Cannot set initial value\n", > + i, chan->name); > + > + ret = audio_iio_aux_add_controls(component, chan); > + if (ret) > + return ret; > + > + ret = audio_iio_aux_add_dapms(component, chan); > + if (ret) > + return ret; > + > + dev_dbg(component->dev, "chan[%d]: Added %s (min=%d, max=%d, invert=%s)\n", > + i, chan->name, chan->min, chan->max, > + str_on_off(chan->is_invert_range)); > + } > + > + return 0; > +}