Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1976127pxk; Sat, 19 Sep 2020 08:18:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOdmR+PybkLZvNXQZCrRml1rxPQklYmeNjjNWb7PP9SoSLuIWeGkDv5VCR0G9H7JoWThQq X-Received: by 2002:aa7:dd8b:: with SMTP id g11mr2880617edv.22.1600528687906; Sat, 19 Sep 2020 08:18:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600528687; cv=none; d=google.com; s=arc-20160816; b=u1UA76xKKPiKG+EeqYWi+O/WKGhL9x2OqyFy6pjUvF8OjPQ1WdCyNsybivmwAebwuC 4lrGo1GcJ25/q3MjAbB8RePaAb7wXkfwxEYZZ1O6+I02CIybbpQ/EILmZITmaThlgHvi W+l1UC1YpUlPyu0m3MacZjM0o7lIvkNklnh7bdgM5EjOhhqlI7c33oub0eRIWAtwye5q hESbdIs7ZFNGK1BlTANqTx1ZnqciyoZoPAqJnmMJdIJrtV+CQcUa9/LGfJemIRTnGqOh OA08UeqMLwr1+wsq9Fxqy2IgSnbT1TS2bihKxa5PeqsVAXIhT0xzzLXAd8CWzRCGfGRm aUyg== 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=T0u7fgoE8wGj7dSNypxJFhMIJFg4EZLjw+rF1z8IVjQ=; b=SiXHBY08Cqtbon9xHbWBF93tKiSFZf933MqBEC7/2rUmz9CBRjlghU61hEGmNXV5TQ AR03iRl27GqQhwaMKt7xd1mQXSWu4bpbN4As9/P4BG4fIeZOMe4T/xy74jjG5jMHH4EA atcIKSWS99Dw7Sqkpk9S0LCBrPJ2xyPSnVHPxDNcHcnsA4MMgfefn3XslbyFfa+OWoz3 n48BGhjaeolxYxPS3tW7lPuHNT9+5eFuECtE5rwUL/3qIPsTeMv+65hF7Nvabo7zRiHM SUnFM/TI+3/rvKLSfarUPRBSeocRtR4pxJKGfUc2KM1iaItc7BJcPGwAXNflR4y5vjkv CMKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vQ6YJwb0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c12si4456925edy.146.2020.09.19.08.17.43; Sat, 19 Sep 2020 08:18:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vQ6YJwb0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726528AbgISPQn (ORCPT + 99 others); Sat, 19 Sep 2020 11:16:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:59390 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726400AbgISPQm (ORCPT ); Sat, 19 Sep 2020 11:16:42 -0400 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8A3AA2098B; Sat, 19 Sep 2020 15:16:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600528602; bh=+y+bw6n8SN9jBc2YfWVyglQV2EMkOcqIEAz8BTxArUM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=vQ6YJwb0MAvZmQTt8VWRi/4UHGWj/sAU0vkflZggHdQKGUDh90EPecpI8sM1jkYqB 0nhluLmhujFq5UyPHVC+HstjGe4Kxpc4lJJHqZfYt9WwbLjKIRSfUD/R9XL+uP5EeL PrA1zHzd0Akl7+4KfAU/1KsNut24RzDFs+Xt84pQ= Date: Sat, 19 Sep 2020 16:16:38 +0100 From: Jonathan Cameron To: Cristian Pop Cc: , Subject: Re: [PATCH v5] iio: adc: ad7768-1: Add channel label example Message-ID: <20200919161638.3357f266@archlinux> In-Reply-To: <20200919161440.2cb17583@archlinux> References: <20200918093356.93670-1-cristian.pop@analog.com> <20200919161440.2cb17583@archlinux> X-Mailer: Claws Mail 3.17.6 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 19 Sep 2020 16:14:40 +0100 Jonathan Cameron wrote: > On Fri, 18 Sep 2020 12:33:56 +0300 > Cristian Pop wrote: > > > This is a demo usage of new "label" attribute for channel. > While I can see this is a demo in someways, I assume we also have > a valid usecase for doing this beyond as a demo! > > So perhaps rephrase that intro. I also forgot to say that you also need to update the dt-bindings for this driver. I've just committed a patch converting them to yaml so work on top of that. Thanks Jonathan > > > > > Signed-off-by: Cristian Pop > > --- > > Changes in V5: > > Create a separate patch file for this commit > > drivers/iio/adc/ad7768-1.c | 49 ++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 49 insertions(+) > > > > diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c > > index 0d132708c429..5ca9f9febb5a 100644 > > --- a/drivers/iio/adc/ad7768-1.c > > +++ b/drivers/iio/adc/ad7768-1.c > > @@ -161,6 +161,7 @@ struct ad7768_state { > > struct completion completion; > > struct iio_trigger *trig; > > struct gpio_desc *gpio_sync_in; > > + const char **labels; > > /* > > * DMA (thus cache coherency maintenance) requires the > > * transfer buffers to live in their own cache lines. > > @@ -407,6 +408,14 @@ static int ad7768_write_raw(struct iio_dev *indio_dev, > > } > > } > > > > +static int ad7768_read_label(struct iio_dev *indio_dev, > > + const struct iio_chan_spec *chan, char *label) > > +{ > > + struct ad7768_state *st = iio_priv(indio_dev); > > + > > + return sprintf(label, "%s\n", st->labels[chan->channel]); > > +} > > + > > static struct attribute *ad7768_attributes[] = { > > &iio_dev_attr_sampling_frequency_available.dev_attr.attr, > > NULL > > @@ -420,6 +429,7 @@ static const struct iio_info ad7768_info = { > > .attrs = &ad7768_group, > > .read_raw = &ad7768_read_raw, > > .write_raw = &ad7768_write_raw, > > + .read_label = ad7768_read_label, > > .debugfs_reg_access = &ad7768_reg_access, > > }; > > > > @@ -538,6 +548,41 @@ static void ad7768_clk_disable(void *data) > > clk_disable_unprepare(st->mclk); > > } > > > > +static int ad7768_set_channel_label(struct iio_dev *indio_dev, > > + int num_channels) > > +{ > > + struct ad7768_state *st = iio_priv(indio_dev); > > + struct device *device = indio_dev->dev.parent; > > + struct fwnode_handle *fwnode; > > + struct fwnode_handle *child; > > + const char *label; > > + int crt_ch = 0; > > + > > + st->labels = devm_kcalloc(indio_dev->dev.parent, > > + num_channels, > > + sizeof(**st->labels), > > I think that ends up being the size of a single character which isn't > the intent. I assume aim is a suitable sized array of pointers to > strings which we will fill in later? > > If so we can probably just use a static sized array as the maximum > number of channels is well constrained. In this particular driver > that is 1 I think! > > > + GFP_KERNEL); > > + > > + if (!st->labels) > > + return -ENOMEM; > > + > > + fwnode = dev_fwnode(device); > > + fwnode_for_each_child_node(fwnode, child) { > > + if (fwnode_property_read_u32(child, "reg", &crt_ch)) > > + continue; > > + > > + if (crt_ch >= num_channels) > > + continue; > > + > > + if (fwnode_property_read_string(child, "label", &label)) > > + continue; > > + > > + st->labels[crt_ch] = label; > > + } > > + > > + return 0; > > +} > > + > > static int ad7768_probe(struct spi_device *spi) > > { > > struct ad7768_state *st; > > @@ -611,6 +656,10 @@ static int ad7768_probe(struct spi_device *spi) > > > > init_completion(&st->completion); > > > > + ret = ad7768_set_channel_label(indio_dev, ARRAY_SIZE(ad7768_channels)); > > + if (ret) > > + return ret; > > + > > ret = devm_request_irq(&spi->dev, spi->irq, > > &ad7768_interrupt, > > IRQF_TRIGGER_RISING | IRQF_ONESHOT, >