From patchwork Mon Jun 14 11:35:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 459849 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp3201506jae; Mon, 14 Jun 2021 04:40:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7h0S5C6hNVzGCJAXTGhxlXixfi1c/5ENI6qZniuoUKZTN/8B4bsYUzps0vQILCqhNEmjX X-Received: by 2002:a17:906:6849:: with SMTP id a9mr14970046ejs.415.1623670824107; Mon, 14 Jun 2021 04:40:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623670824; cv=none; d=google.com; s=arc-20160816; b=J6vEARIVFWkidKZp4qmskxx+3hAXXQiBuCoYvpJMIV0QezmqnsgmWMIAcfGV+RVr2U goQVuUfib0JqSffz4HnogRW3rclUEftCRzhNBszj2Ow17zYPD1knNqe/Y82FGrzvcFfs Yk0gqHOQNGHoM0Qxg5IVq7hlIbToSVZqU6qmdmteIXZHv2wRpzD59w1Sqbfb181xM+kQ stQE0Nfh9ljIGvWJtUh4H0K3i/+rlCybkY4MW/fR3Y7rX9aAnKDdGQhkUrhLfgYL8lmn juH4tb8pRcq7vQDny8P3kL7affhcl7U6otq1vn4R9WbqQmDHz4PwBw8IW6VWlDGqyRZv TOdA== 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:date:subject:cc:to:from :dkim-signature; bh=w1svZxsJ8CO9hPTISe7SMt+lW1K2u8YEOtbHtm3UR4I=; b=qxa5cJDix5uAJMVSBUnEU4Yw5yJncGxjLEJxtG0TJybLeVCXD/PXVir4tFwrA80G1P m1zGRJpLv7Wa43I9KrStPJvldVTyYyHLBTvSIhiRx29SDLhH0s61bM93AuPjjWP3I5gM OC5OnYJQxFN0isTYSkZzBROrQVe+IX39ikaZMBHHFtZIUzVj1+X3HSR+fp8dIce5Qmqv T161YW5mo/MHF5HVvmJ42tdVkfUseLIWCW23WiSaKhKkOs9oxoQi4TF+6i/7q1x1R7gS MgwktEvuYpFZM1YQfALPSEDbLcjqdmV+jKMlATxCMtSh3nxd4fILRBAFpMbVg6Zt75FV RFyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JpktRzJc; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-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 nb10si11945869ejc.344.2021.06.14.04.40.23; Mon, 14 Jun 2021 04:40:24 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-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=k20201202 header.b=JpktRzJc; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-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 S235765AbhFNLlo (ORCPT + 7 others); Mon, 14 Jun 2021 07:41:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:59770 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233546AbhFNLh1 (ORCPT ); Mon, 14 Jun 2021 07:37:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 51D566134F; Mon, 14 Jun 2021 11:33:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623670429; bh=F7XmoMcwJPPcXxw0bTIa6C1AAdnqrRXSH7Ps7AlrnWA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JpktRzJcqNTTAprJpDC33fEaGbIl+ih5rIRvpeksqSY1VUjM3CdfuUoWAzTshg5Z2 eNq8Mg4F9LYf5gh4Di5L/OIGQDo6gqgpK60MicoMSf896oyus4bD8ABL9OA7kuoR5S +lvtXmeSGSE6Em+m5NewFH/qYoC2pSHR/O6/E7Q8oN+mO49OAYDHYNBg98FlyS+JGk 9LPSpD4cyKIBh2vQAcevYdTjGv6sMVzvybeohYOjxfueFuashvu0vrKcCCYEcqzp+y 7t3QSFsfjDfvTjIGBNv0aJ7IVUaNcWspoJ+TE3W5NElYvEP0ENktMXxMOQuRaoCrTz Ya0bnfmMMr+dw== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Rob Herring Cc: Michael.Hennerich@analog.com, lars@metafoo.de, devicetree@vger.kernel.org, Nuno Sa , Jonathan Cameron Subject: [PATCH 12/17] staging:iio:ad7280a: Reflect optionality of irq in ABI Date: Mon, 14 Jun 2021 12:35:02 +0100 Message-Id: <20210614113507.897732-13-jic23@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210614113507.897732-1-jic23@kernel.org> References: <20210614113507.897732-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Jonathan Cameron Given the irq is optional, let us remove the interfaces related to events when it is not present. Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad7280a.c | 48 +++++++++++++++++++------------ 1 file changed, 29 insertions(+), 19 deletions(-) -- 2.32.0 diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c index 7f9e2276e41a..b4ba6da07af9 100644 --- a/drivers/staging/iio/adc/ad7280a.c +++ b/drivers/staging/iio/adc/ad7280a.c @@ -579,23 +579,29 @@ static const struct iio_event_spec ad7280_events[] = { }, }; -static void ad7280_voltage_channel_init(struct iio_chan_spec *chan, int i) +static void ad7280_voltage_channel_init(struct iio_chan_spec *chan, int i, + bool irq_present) { chan->type = IIO_VOLTAGE; chan->differential = 1; chan->channel = i; chan->channel2 = chan->channel + 1; - chan->event_spec = ad7280_events; - chan->num_event_specs = ARRAY_SIZE(ad7280_events); + if (irq_present) { + chan->event_spec = ad7280_events; + chan->num_event_specs = ARRAY_SIZE(ad7280_events); + } chan->ext_info = ad7280_cell_ext_info; } -static void ad7280_temp_channel_init(struct iio_chan_spec *chan, int i) +static void ad7280_temp_channel_init(struct iio_chan_spec *chan, int i, + bool irq_present) { chan->type = IIO_TEMP; chan->channel = i; - chan->event_spec = ad7280_events; - chan->num_event_specs = ARRAY_SIZE(ad7280_events); + if (irq_present) { + chan->event_spec = ad7280_events; + chan->num_event_specs = ARRAY_SIZE(ad7280_events); + } } static void ad7280_common_fields_init(struct iio_chan_spec *chan, int addr, @@ -629,7 +635,8 @@ static void ad7280_total_voltage_channel_init(struct iio_chan_spec *chan, chan->scan_type.storagebits = 32; } -static void ad7280_init_dev_channels(struct ad7280_state *st, int dev, int *cnt) +static void ad7280_init_dev_channels(struct ad7280_state *st, int dev, int *cnt, + bool irq_present) { int addr, ch, i; struct iio_chan_spec *chan; @@ -639,10 +646,10 @@ static void ad7280_init_dev_channels(struct ad7280_state *st, int dev, int *cnt) if (ch < AD7280A_AUX_ADC_1_REG) { i = AD7280A_CALC_VOLTAGE_CHAN_NUM(dev, ch); - ad7280_voltage_channel_init(chan, i); + ad7280_voltage_channel_init(chan, i, irq_present); } else { i = AD7280A_CALC_TEMP_CHAN_NUM(dev, ch); - ad7280_temp_channel_init(chan, i); + ad7280_temp_channel_init(chan, i, irq_present); } addr = ad7280a_devaddr(dev) << 8 | ch; @@ -652,7 +659,7 @@ static void ad7280_init_dev_channels(struct ad7280_state *st, int dev, int *cnt) } } -static int ad7280_channel_init(struct ad7280_state *st) +static int ad7280_channel_init(struct ad7280_state *st, bool irq_present) { int dev, cnt = 0; @@ -662,7 +669,7 @@ static int ad7280_channel_init(struct ad7280_state *st) return -ENOMEM; for (dev = 0; dev <= st->slave_num; dev++) - ad7280_init_dev_channels(st, dev, &cnt); + ad7280_init_dev_channels(st, dev, &cnt, irq_present); ad7280_total_voltage_channel_init(&st->channels[cnt], cnt, dev); @@ -920,6 +927,11 @@ static const struct iio_info ad7280_info = { .write_event_value = &ad7280a_write_thresh, }; +static const struct iio_info ad7280_info_no_irq = { + .read_event_value = &ad7280a_read_thresh, + .write_event_value = &ad7280a_write_thresh, +}; + static const struct ad7280_platform_data ad7793_default_pdata = { .acquisition_time = AD7280A_ACQ_TIME_400ns, .thermistor_term_en = true, @@ -973,18 +985,12 @@ static int ad7280_probe(struct spi_device *spi) indio_dev->name = spi_get_device_id(spi)->name; indio_dev->modes = INDIO_DIRECT_MODE; - ret = ad7280_channel_init(st); + ret = ad7280_channel_init(st, spi->irq > 0); if (ret < 0) return ret; indio_dev->num_channels = ret; indio_dev->channels = st->channels; - indio_dev->info = &ad7280_info; - - ret = devm_iio_device_register(&spi->dev, indio_dev); - if (ret) - return ret; - if (spi->irq > 0) { ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_ALERT_REG, 1, @@ -1008,9 +1014,13 @@ static int ad7280_probe(struct spi_device *spi) indio_dev); if (ret) return ret; + + indio_dev->info = &ad7280_info; + } else { + indio_dev->info = &ad7280_info_no_irq; } - return 0; + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct spi_device_id ad7280_id[] = {