From patchwork Tue Jun 18 16:08:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Moysan X-Patchwork-Id: 13702583 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (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 1116D768E1; Tue, 18 Jun 2024 16:10:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.132.182.106 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718727028; cv=none; b=MkK7KDF2GmKr7/k99PlqpL2XKpL6xKxH2qXJhRliZrJcHiSEWatcwpf6ZHy9p9Gnjc65J+YgJzLO5mV8M3j3UYiEg0XXBytCnBHyuP+jtE0mnMM4TOb4N9BG1Pd1rK0+i2DCjgAP2iG12Yg6xEZApEtVNoFS9gF2Htap9a+7FM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718727028; c=relaxed/simple; bh=WnYHhpxz9XlN8DeOrkUc8ti0eDWrfck7MDCrMFMg9h0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MnJArWGn9IzsH65cqI1ZYyHCXDV5vUNk7nIEtt2eC7Ss9o/UA+30dSTRsokDxD2NfGXrUme3xsNzPMEowdODRrN7RXlkvMhTsvstXbGElN6lolXjDgYd29Klo3VtGRG9Y1o3jgbAxtdoG0/XGln6lpJv4z45zKIV8oaMg/EiQrE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=i5Q6aiiA; arc=none smtp.client-ip=185.132.182.106 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="i5Q6aiiA" Received: from pps.filterd (m0288072.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45IFZ34s031794; Tue, 18 Jun 2024 18:09:55 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= oBCkKn2xGyjUcuH9Isse3UsfR/NglWbSwpBTIgOD8P4=; b=i5Q6aiiAhdqsWdh3 COWH75mYjCzG2pIayjSaeCWo6gFdff4vmdgtWq0H5fK7Lz7VeVLwCQj/27uWzC89 aSeC+TFdNXZqE7qFTSbn/rqFEmzsfTCRiN3r3E8Jier68lWgX0sMdBhzyoAtjaPI 4gf5QOURQlUDWssLYf4eFVKXh6dblMisLnDziwJ0iRAdoQJP3AHqC9UUb/WIthLH 7culiSKt+7p9vJg8W1YlDrb2IGsjEOAPeZGaxZdE8mFm7ExV0tSbkHDCIXUCdL0g vz8j8P03g0I4nPHV81MP/AhFt8nxWR5it/pJX6L2oVI/xQUM/DGpqJ2IyVTkgBRf Ov5BeQ== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3ys0cgca1p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Jun 2024 18:09:55 +0200 (MEST) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 76F3940044; Tue, 18 Jun 2024 18:09:46 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 7B94321D3C8; Tue, 18 Jun 2024 18:09:23 +0200 (CEST) Received: from localhost (10.252.27.64) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 18 Jun 2024 18:09:23 +0200 From: Olivier Moysan To: Nuno Sa , Olivier Moysan , Jonathan Cameron , Lars-Peter Clausen CC: , Subject: [PATCH 1/8] iio: add read raw service to iio backend framework Date: Tue, 18 Jun 2024 18:08:27 +0200 Message-ID: <20240618160836.945242-2-olivier.moysan@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240618160836.945242-1-olivier.moysan@foss.st.com> References: <20240618160836.945242-1-olivier.moysan@foss.st.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-18_02,2024-06-17_01,2024-05-17_01 Add iio_backend_read_raw() service to support attributes read from an IIO backend. Signed-off-by: Olivier Moysan Reviewed-by: Nuno Sa --- drivers/iio/industrialio-backend.c | 16 ++++++++++++++++ include/linux/iio/backend.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c index 929aff4040ed..b950e30018ca 100644 --- a/drivers/iio/industrialio-backend.c +++ b/drivers/iio/industrialio-backend.c @@ -357,6 +357,22 @@ int devm_iio_backend_request_buffer(struct device *dev, } EXPORT_SYMBOL_NS_GPL(devm_iio_backend_request_buffer, IIO_BACKEND); +/** + * iio_backend_read_raw - Request a value from the backend. + * @back: Backend device + * @val: First element of the returned value + * @val2: Second element of the returned value + * @mask: Specify value to retrieve + * + * RETURNS: + * 0 on success, negative error number on failure. + */ +int iio_backend_read_raw(struct iio_backend *back, int *val, int *val2, long mask) +{ + return iio_backend_op_call(back, read_raw, val, val2, mask); +} +EXPORT_SYMBOL_NS_GPL(iio_backend_read_raw, IIO_BACKEND); + static struct iio_backend *iio_backend_from_indio_dev_parent(const struct device *dev) { struct iio_backend *back = ERR_PTR(-ENODEV), *iter; diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h index 8099759d7242..cff486699054 100644 --- a/include/linux/iio/backend.h +++ b/include/linux/iio/backend.h @@ -81,6 +81,7 @@ enum iio_backend_sample_trigger { * @extend_chan_spec: Extend an IIO channel. * @ext_info_set: Extended info setter. * @ext_info_get: Extended info getter. + * @read_raw: Read value from a backend device **/ struct iio_backend_ops { int (*enable)(struct iio_backend *back); @@ -113,6 +114,7 @@ struct iio_backend_ops { const char *buf, size_t len); int (*ext_info_get)(struct iio_backend *back, uintptr_t private, const struct iio_chan_spec *chan, char *buf); + int (*read_raw)(struct iio_backend *back, int *val, int *val2, long mask); }; int iio_backend_chan_enable(struct iio_backend *back, unsigned int chan); @@ -141,6 +143,7 @@ ssize_t iio_backend_ext_info_set(struct iio_dev *indio_dev, uintptr_t private, const char *buf, size_t len); ssize_t iio_backend_ext_info_get(struct iio_dev *indio_dev, uintptr_t private, const struct iio_chan_spec *chan, char *buf); +int iio_backend_read_raw(struct iio_backend *back, int *val, int *val2, long mask); int iio_backend_extend_chan_spec(struct iio_dev *indio_dev, struct iio_backend *back, From patchwork Tue Jun 18 16:08:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Moysan X-Patchwork-Id: 13702582 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (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 BB08C50297; Tue, 18 Jun 2024 16:10:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.207.212.93 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718727017; cv=none; b=pvvfSMb7dhWegkpKzFNskyvPVCjnCZUgzKNshraw02tiDcIEWiKg1tK6qlTXC49Jmo8w404KAs6TrSjeN5LyieOwRHInmU7QXM5enAXWOtd4Y5fGi770twM4VHgzGO5a2sUdGUehoHYs2lObPZnSa/QBw4l8LrSpi2yvZds6GBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718727017; c=relaxed/simple; bh=USB1J3c1I1YDJiBjUQrzN4H4/OWzJtRXO4GYW8Vt/iQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aXmSD53vuKtsxUWn+IW0fCnWama6/Nt7esg5tQqxlX0wBbah8p5oNLK8a0lUrqV2zYtsUMm+dPcewrY4elLyTYkFbhZ9tTASVOC/wfhZiMsYbeScEoKTbAMQA5PG9IDfpdcTxO9Vs3x+uXJtz5pLdhCnGUTt8TQO/mn29tTwT24= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=i91YT2Ob; arc=none smtp.client-ip=91.207.212.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="i91YT2Ob" Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45IG0GqB014183; Tue, 18 Jun 2024 18:09:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= vtRrWuN32WlRT8GMWwj0eu9Vi1SpQstEyGYmHWc9F/Q=; b=i91YT2ObqSmeWtxS zaCibFgRdSefsdEGbk5Z0BCAbbxaetDrrArO1KAXjF1jMj1Da1L57S5qJl6fsIod Z4kegLTNGV1Kxvf6TwyrAoauzoEv5hbSxLMO7JxO+5LQ9iw1hJSL1mzFJ3eeBP2L 28gIuW7HlDQuRod8ThzH6mZuWD9ji5Z5ougpr8lp8C2RyRImxHMBr+sKW2+StWkW nlHD/btne38O1VFsH4y1thO3ZQhUPdE/8Fz5nqVPoZ2vSLtPNYUIVqqlSDeUOraO QbIJP4kazrBTv7U9a5WQX8Q7vzZ/xKEsBl/xpM3rmPd41ItjzDZYspjExazOxHbu XOPWQQ== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3ys035m8dv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Jun 2024 18:09:56 +0200 (MEST) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 60A5A40045; Tue, 18 Jun 2024 18:09:47 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id A141721D3CA; Tue, 18 Jun 2024 18:09:24 +0200 (CEST) Received: from localhost (10.252.27.64) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 18 Jun 2024 18:09:24 +0200 From: Olivier Moysan To: Nuno Sa , Olivier Moysan , Jonathan Cameron , Lars-Peter Clausen CC: , Subject: [PATCH 2/8] iio: add enable and disable services to iio backend framework Date: Tue, 18 Jun 2024 18:08:28 +0200 Message-ID: <20240618160836.945242-3-olivier.moysan@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240618160836.945242-1-olivier.moysan@foss.st.com> References: <20240618160836.945242-1-olivier.moysan@foss.st.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-18_02,2024-06-17_01,2024-05-17_01 Add iio_backend_disable() and iio_backend_enable() APIs to allow IIO backend consumer to request backend disabling and enabling. Signed-off-by: Olivier Moysan Reviewed-by: Nuno Sa --- drivers/iio/industrialio-backend.c | 26 ++++++++++++++++++++++++++ include/linux/iio/backend.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c index b950e30018ca..d3db048c086b 100644 --- a/drivers/iio/industrialio-backend.c +++ b/drivers/iio/industrialio-backend.c @@ -166,6 +166,32 @@ int devm_iio_backend_enable(struct device *dev, struct iio_backend *back) } EXPORT_SYMBOL_NS_GPL(devm_iio_backend_enable, IIO_BACKEND); +/** + * iio_backend_enable - Backend enable + * @dev: Consumer device for the backend + * @back: Backend device + * + * RETURNS: + * 0 on success, negative error number on failure. + */ +int iio_backend_enable(struct device *dev, struct iio_backend *back) +{ + return iio_backend_op_call(back, enable); +} +EXPORT_SYMBOL_NS_GPL(iio_backend_enable, IIO_BACKEND); + +/** + * iio_backend_disable - Backend disable + * @dev: Consumer device for the backend + * @back: Backend device + * + */ +void iio_backend_disable(struct device *dev, struct iio_backend *back) +{ + iio_backend_void_op_call(back, disable); +} +EXPORT_SYMBOL_NS_GPL(iio_backend_disable, IIO_BACKEND); + /** * iio_backend_data_format_set - Configure the channel data format * @back: Backend device diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h index cff486699054..81277e5b6160 100644 --- a/include/linux/iio/backend.h +++ b/include/linux/iio/backend.h @@ -120,6 +120,8 @@ struct iio_backend_ops { int iio_backend_chan_enable(struct iio_backend *back, unsigned int chan); int iio_backend_chan_disable(struct iio_backend *back, unsigned int chan); int devm_iio_backend_enable(struct device *dev, struct iio_backend *back); +int iio_backend_enable(struct device *dev, struct iio_backend *back); +void iio_backend_disable(struct device *dev, struct iio_backend *back); int iio_backend_data_format_set(struct iio_backend *back, unsigned int chan, const struct iio_backend_data_fmt *data); int iio_backend_data_source_set(struct iio_backend *back, unsigned int chan, From patchwork Tue Jun 18 16:08:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Moysan X-Patchwork-Id: 13702584 Received: from mx08-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (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 9746C4C630; Tue, 18 Jun 2024 16:11:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.207.212.93 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718727074; cv=none; b=ePc1hQtyy1/gIr3Wwafq/V828GYrrgTtaJgG5f/aqZUtfhte/wOxmL0vlAlbTMy9YhvnE/DD2YNek3aAf9IfC4wJRkDVSxOZeLFXA1WNBzThXJOVUgus+6eB/w7dqIaAupCGBv5d2BMtj/Ilw6oe22TJeWWL7FAbAsGFkMhgFDI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718727074; c=relaxed/simple; bh=blUqWMur+GT3FDU86sdlfITnHZzcxIPkaS2QFUl1y9E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WcJF+2SS7cv79NMDQq4YicLpR66fToZfqQ6GNM8+11+K/pBpZ29PX2kCWVV9IfhUK5uhoq1gC730SsMwphKrd6hC4tZxL73fZnEyzw+efahINdq9jqu3twa787uKBcxk4G22clq34FfFHO2NoMsewI+G+Vppn+vLN9U4BxdsPE8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=aY9Ll6nD; arc=none smtp.client-ip=91.207.212.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="aY9Ll6nD" Received: from pps.filterd (m0369457.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45IBAh6F032172; Tue, 18 Jun 2024 18:10:57 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= GSJTsNXSeJ6OnoklQniiPvioT7fGdiL7gkkotOLYSXs=; b=aY9Ll6nDpTI5ll9p DoYmMKCz/5PcDEr2IxYR7Pt7Vo7DMtMgwGQxGh8DVBAjjjohNur5hy1Red9vjexv KdyDWPHZypu6KN1H26s4P/OL0IP8+WIu6neHakpnsoVomqTzFvx/I/EaYmNfIqRC unVwnoINZuOBPTA/zualkFGy3ozNgOl4LHiCPFlORZ+kffZ976wTdR5m+4arbx7m UGBnFAHeMkguhY2dRLctnQVQHq09IpYiJrVKF+QT9idR0ekUu1cHUBM8ZrxIl+j4 OVTVZD6i1qUFy9e9NqgI5cHttH0dSjt0q/jLFCC+ftL7kjFDDoXA2z1CkgZ9B4s0 D7SCew== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3ysnwja5dw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Jun 2024 18:10:56 +0200 (MEST) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 9F27E40044; Tue, 18 Jun 2024 18:10:47 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id C5E8E21D382; Tue, 18 Jun 2024 18:10:25 +0200 (CEST) Received: from localhost (10.252.27.64) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 18 Jun 2024 18:10:25 +0200 From: Olivier Moysan To: Nuno Sa , Olivier Moysan , Jonathan Cameron , Lars-Peter Clausen CC: , Subject: [PATCH 3/8] iio: add child nodes support in iio backend framework Date: Tue, 18 Jun 2024 18:08:29 +0200 Message-ID: <20240618160836.945242-4-olivier.moysan@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240618160836.945242-1-olivier.moysan@foss.st.com> References: <20240618160836.945242-1-olivier.moysan@foss.st.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-18_02,2024-06-17_01,2024-05-17_01 Add an API to support IIO generic channels binding: http://devicetree.org/schemas/iio/adc/adc.yaml# This new API is needed, as generic channel DT node isn't populated as a device. Add devm_iio_backend_subnode_get() to allow an IIO device backend consumer to configure backend phandles in its child nodes. Signed-off-by: Olivier Moysan Reviewed-by: Nuno Sa --- drivers/iio/industrialio-backend.c | 48 ++++++++++++++++++++++-------- include/linux/iio/backend.h | 2 ++ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c index d3db048c086b..e9d29131634d 100644 --- a/drivers/iio/industrialio-backend.c +++ b/drivers/iio/industrialio-backend.c @@ -575,17 +575,8 @@ static int __devm_iio_backend_get(struct device *dev, struct iio_backend *back) return 0; } -/** - * devm_iio_backend_get - Device managed backend device get - * @dev: Consumer device for the backend - * @name: Backend name - * - * Get's the backend associated with @dev. - * - * RETURNS: - * A backend pointer, negative error pointer otherwise. - */ -struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name) +static struct iio_backend *__devm_iio_backend_node_get(struct device *dev, const char *name, + struct fwnode_handle *node) { struct fwnode_handle *fwnode; struct iio_backend *back; @@ -602,7 +593,7 @@ struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name) index = 0; } - fwnode = fwnode_find_reference(dev_fwnode(dev), "io-backends", index); + fwnode = fwnode_find_reference(node, "io-backends", index); if (IS_ERR(fwnode)) { dev_err_probe(dev, PTR_ERR(fwnode), "Cannot get Firmware reference\n"); @@ -625,8 +616,41 @@ struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name) fwnode_handle_put(fwnode); return ERR_PTR(-EPROBE_DEFER); } + +/** + * devm_iio_backend_get - Device managed backend device get + * @dev: Consumer device for the backend + * @name: Backend name + * + * Get's the backend associated with @dev. + * + * RETURNS: + * A backend pointer, negative error pointer otherwise. + */ +struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name) +{ + return __devm_iio_backend_node_get(dev, name, dev_fwnode(dev)); +} EXPORT_SYMBOL_NS_GPL(devm_iio_backend_get, IIO_BACKEND); +/** + * devm_iio_backend_subnode_get - Device managed backend device get + * @dev: Consumer device for the backend + * @name: Backend name + * @node: Firmware node of the backend consumer + * + * Get's the backend associated with @dev. + * + * RETURNS: + * A backend pointer, negative error pointer otherwise. + */ +struct iio_backend *devm_iio_backend_subnode_get(struct device *dev, const char *name, + struct fwnode_handle *node) +{ + return __devm_iio_backend_node_get(dev, name, node); +} +EXPORT_SYMBOL_NS_GPL(devm_iio_backend_subnode_get, IIO_BACKEND); + /** * __devm_iio_backend_get_from_fwnode_lookup - Device managed fwnode backend device get * @dev: Consumer device for the backend diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h index 81277e5b6160..1050ab68e4e4 100644 --- a/include/linux/iio/backend.h +++ b/include/linux/iio/backend.h @@ -152,6 +152,8 @@ int iio_backend_extend_chan_spec(struct iio_dev *indio_dev, struct iio_chan_spec *chan); void *iio_backend_get_priv(const struct iio_backend *conv); struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name); +struct iio_backend *devm_iio_backend_subnode_get(struct device *dev, const char *name, + struct fwnode_handle *node); struct iio_backend * __devm_iio_backend_get_from_fwnode_lookup(struct device *dev, struct fwnode_handle *fwnode); From patchwork Tue Jun 18 16:08:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Moysan X-Patchwork-Id: 13702673 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (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 367C44F5EA; Tue, 18 Jun 2024 16:11:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.132.182.106 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718727107; cv=none; b=r58G83DBFKOpBxhh4OOu2F9MECKb35r3Zb/yr7IH6oc2mLhXwxgfvyctaIhhBrXgCmqk81i1T3r9i4AZQI9aFA7nniOEfTSPmIgXdfFPjYHjDBRlTuYmXHJMUBB+mGsZBb2ONaQXJU5ccJonjJBRVHSL58Cw76zIkP07XQ0Yqec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718727107; c=relaxed/simple; bh=j8UQyaa1lDFuOHaljzhOsivgcRkyHQkPDFY4yaSBxCw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gphlv1O1hJVhcoTgQi7JRYaSUeiaPpKI4fycZ1sibQIvLgJJSwjSXwDa7GT/yR4fwNcdYzULxCHb/OOYEfvBR2D3qAKz6hgScgQVsDZXI+tq+rYuqDGYJJ68nyf8p9uwI3wDiW8h54Wn03asfIG+7Esu7lJBE4tRsC0HrGnASYI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=zmUxWSyU; arc=none smtp.client-ip=185.132.182.106 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="zmUxWSyU" Received: from pps.filterd (m0288072.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45IF4uJW031745; Tue, 18 Jun 2024 18:11:20 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= mt4jA5DmMOxU5cEiI40uNpQZdbSX0OU07yEosb4wrjs=; b=zmUxWSyUaWPyD1f4 nUMXNuHMstF5QGTrQlEQ5/Dxm7qGtodUfeVC6Vl8+lAvHCyUmY2tnfvvx0//qyvz Sou+XG4yxp11ifnGz5e/h0/5DPPO7HiEg9p58KGPMDujdA9KcGcPITaAgjGAK37W ZplON2yYkxFu7v5SpmPnRl3urPt+nMIdPDM8i4uxo4xPu6/b/KvroeQa5qC2FkjW UoUTIDiWCWAqjeFmhrxJeD4zBnudM1dqjhSRvUaX6+4V92Do/BDhQGs/0v1HdrZt t3JZBxpE7h0KNP82l7IcgWZZiMZsU0quVSkIt0zSA2T6XxDCUYwFKRCoR/OqRmHk iL3DVw== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3ys0cgca63-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Jun 2024 18:11:19 +0200 (MEST) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id AA77E4002D; Tue, 18 Jun 2024 18:11:15 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 1A8D421D385; Tue, 18 Jun 2024 18:10:27 +0200 (CEST) Received: from localhost (10.252.27.64) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 18 Jun 2024 18:10:26 +0200 From: Olivier Moysan To: Olivier Moysan , Arnaud Pouliquen , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Maxime Coquelin , Alexandre Torgue , Fabrice Gasnier CC: , , , , , Subject: [PATCH 4/8] dt-bindings: iio: dfsdm: move to backend framework Date: Tue, 18 Jun 2024 18:08:30 +0200 Message-ID: <20240618160836.945242-5-olivier.moysan@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240618160836.945242-1-olivier.moysan@foss.st.com> References: <20240618160836.945242-1-olivier.moysan@foss.st.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-18_02,2024-06-17_01,2024-05-17_01 Change the DFSDM binding to use the new IIO backend framework, along with the adoption of IIO generic channels. This binding change allows to add scaling support to the DFSDM. Keep the legacy binding as deprecated for backward compatibility. The io-backends property is supported only in generic IIO channel binding. - Channel description with the generic binding (Audio and Analog): Properties supersed by generic properties: st,adc-channels: becomes "reg" property in channel node st,adc-channel-names: becomes "label" property in channel node Properties moved to channel child node: st,adc-channel-types, st,adc-channel-clk-src, st,adc-alt-channel - Analog binding: DFSDM filter channel is configured as an IIO backend consumer. Add io-backends property in channel child nodes. DFSDM is no more configured as a channel consumer from SD modulator. Use of io-channels in DFSDM node is deprecated. - Audio binding: DFSDM audio DAI is configured as a channel consumer from DFSDM filter. No change compare to legacy. Signed-off-by: Olivier Moysan --- .../bindings/iio/adc/st,stm32-dfsdm-adc.yaml | 158 +++++++++++++++++- 1 file changed, 152 insertions(+), 6 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/adc/st,stm32-dfsdm-adc.yaml b/Documentation/devicetree/bindings/iio/adc/st,stm32-dfsdm-adc.yaml index c1b1324fa132..dd414bab74c1 100644 --- a/Documentation/devicetree/bindings/iio/adc/st,stm32-dfsdm-adc.yaml +++ b/Documentation/devicetree/bindings/iio/adc/st,stm32-dfsdm-adc.yaml @@ -102,9 +102,11 @@ patternProperties: items: minimum: 0 maximum: 7 + deprecated: true st,adc-channel-names: description: List of single-ended channel names. + deprecated: true st,filter-order: description: | @@ -118,6 +120,12 @@ patternProperties: "#io-channel-cells": const: 1 + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + st,adc-channel-types: description: | Single-ended channel input type. @@ -128,6 +136,7 @@ patternProperties: items: enum: [ SPI_R, SPI_F, MANCH_R, MANCH_F ] $ref: /schemas/types.yaml#/definitions/non-unique-string-array + deprecated: true st,adc-channel-clk-src: description: | @@ -139,6 +148,7 @@ patternProperties: items: enum: [ CLKIN, CLKOUT, CLKOUT_F, CLKOUT_R ] $ref: /schemas/types.yaml#/definitions/non-unique-string-array + deprecated: true st,adc-alt-channel: description: @@ -147,6 +157,7 @@ patternProperties: If not set, channel n is connected to SPI input n. If set, channel n is connected to SPI input n + 1. type: boolean + deprecated: true st,filter0-sync: description: @@ -165,11 +176,65 @@ patternProperties: - compatible - reg - interrupts - - st,adc-channels - - st,adc-channel-names - st,filter-order - "#io-channel-cells" + patternProperties: + "^channel@([0-9]|1[0-9])$": + type: object + $ref: adc.yaml + description: Represents the external channels which are connected to the DFSDM. + + properties: + reg: + items: + minimum: 0 + maximum: 8 + + label: + description: + Unique name to identify which channel this is. + + st,adc-channel-types: + description: | + Single-ended channel input type. + - "SPI_R": SPI with data on rising edge (default) + - "SPI_F": SPI with data on falling edge + - "MANCH_R": manchester codec, rising edge = logic 0, falling edge = logic 1 + - "MANCH_F": manchester codec, rising edge = logic 1, falling edge = logic 0 + items: + enum: [ SPI_R, SPI_F, MANCH_R, MANCH_F ] + $ref: /schemas/types.yaml#/definitions/non-unique-string-array + + st,adc-channel-clk-src: + description: | + Conversion clock source. + - "CLKIN": external SPI clock (CLKIN x) + - "CLKOUT": internal SPI clock (CLKOUT) (default) + - "CLKOUT_F": internal SPI clock divided by 2 (falling edge). + - "CLKOUT_R": internal SPI clock divided by 2 (rising edge). + items: + enum: [ CLKIN, CLKOUT, CLKOUT_F, CLKOUT_R ] + $ref: /schemas/types.yaml#/definitions/non-unique-string-array + + st,adc-alt-channel: + description: + Must be defined if two sigma delta modulators are + connected on same SPI input. + If not set, channel n is connected to SPI input n. + If set, channel n is connected to SPI input n + 1. + type: boolean + + io-backends: + description: + From common IIO binding. Used to pipe external sigma delta + modulator or internal ADC backend to DFSDM channel. + + required: + - reg + + additionalProperties: false + allOf: - if: properties: @@ -199,9 +264,19 @@ patternProperties: description: From common IIO binding. Used to pipe external sigma delta modulator or internal ADC output to DFSDM channel. + deprecated: true - required: - - io-channels + if: + required: + - st,adc-channels + then: + required: + - io-channels + + patternProperties: + "^channel@([0-9]|1[0-9])$": + required: + - io-backends - if: properties: @@ -294,7 +369,77 @@ examples: #address-cells = <1>; #size-cells = <0>; + // Example 1: Audio use case with generic binding dfsdm0: filter@0 { + compatible = "st,stm32-dfsdm-dmic"; + reg = <0>; + interrupts = ; + dmas = <&dmamux1 101 0x400 0x01>; + dma-names = "rx"; + #io-channel-cells = <1>; + #address-cells = <1>; + #size-cells = <0>; + st,filter-order = <5>; + + channel@1 { + reg = <1>; + label = "dmic0"; + st,adc-channel-types = "SPI_R"; + st,adc-channel-clk-src = "CLKOUT"; + st,adc-alt-channel; + }; + + asoc_pdm0: dfsdm-dai { + compatible = "st,stm32h7-dfsdm-dai"; + #sound-dai-cells = <0>; + io-channels = <&dfsdm0 0>; + }; + }; + + // Example 1: Analog use case with generic binding + dfsdm1: filter@1 { + compatible = "st,stm32-dfsdm-adc"; + reg = <1>; + interrupts = ; + dmas = <&dmamux1 102 0x400 0x01>; + dma-names = "rx"; + st,filter-order = <1>; + #io-channel-cells = <1>; + #address-cells = <1>; + #size-cells = <0>; + + channel@2 { + reg = <2>; + label = "in2"; + st,adc-channel-types = "SPI_F"; + st,adc-channel-clk-src = "CLKOUT"; + st,adc-alt-channel; + io-backends = <&sd_adc2>; + }; + + channel@3 { + reg = <3>; + label = "in3"; + st,adc-channel-types = "SPI_R"; + st,adc-channel-clk-src = "CLKOUT"; + io-backends = <&sd_adc3>; + }; + }; + }; + + - | + #include + #include + dfsdm_2: dfsdm@4400d000 { + compatible = "st,stm32mp1-dfsdm"; + reg = <0x4400d000 0x800>; + clocks = <&rcc DFSDM_K>, <&rcc ADFSDM_K>; + clock-names = "dfsdm", "audio"; + #address-cells = <1>; + #size-cells = <0>; + + // Example 3: Audio use case with legacy binding + dfsdm0_2: filter@0 { compatible = "st,stm32-dfsdm-dmic"; reg = <0>; interrupts = ; @@ -307,14 +452,15 @@ examples: st,adc-channel-clk-src = "CLKOUT"; st,filter-order = <5>; - asoc_pdm0: dfsdm-dai { + asoc_pdm0_2: dfsdm-dai { compatible = "st,stm32h7-dfsdm-dai"; #sound-dai-cells = <0>; io-channels = <&dfsdm0 0>; }; }; - dfsdm_pdm1: filter@1 { + // Example 3: Analog use case with legacy binding + dfsdm1_2: filter@1 { compatible = "st,stm32-dfsdm-adc"; reg = <1>; interrupts = ; From patchwork Tue Jun 18 16:08:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Moysan X-Patchwork-Id: 13702586 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (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 AEBA713BC30; Tue, 18 Jun 2024 16:11:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.132.182.106 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718727080; cv=none; b=OoT9btYjIjA9xTCWzAwNokJW/qpOlPLZmoSmBi6DdNQoifcFd3tm03p2ci7vSU0HzFZHy0zVsUZA1i827Y3kNmjWGHslMS+Gw4sCo9t2Fdd1IAIHazaoOa3Bq7WlwAhls7eBl2wiFSNQvTYBtAOlrPu6X66KzwrwWP2j3b39E2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718727080; c=relaxed/simple; bh=OixfWHuwr8fk2cZhP8A5Y4L7J7wxqUqTFUVglM0/iZs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=E1Vcv18pDbMwIJ+ht5anScMI4W+RP047OskoLsJAiDyMHZBc+1FuSUpF77ALMUP4YRluTVkr1Z/X5DIRu56x/tgpXxQrDW9tGvsz90Ei5d1kY3rkYJ6iuy/RQZ+69Lq/toY1jOTJgXi10814qvUOOObmub6i6SwuQtdikhNXIRo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=ku5z62w0; arc=none smtp.client-ip=185.132.182.106 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="ku5z62w0" Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45IFe3x4027003; Tue, 18 Jun 2024 18:11:03 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= XpA+f9bQP61dqrvt0OM80VMLJKM/XB9fUzUgYOfoOkg=; b=ku5z62w0yaQ98uao lOBliKdZgAYwPrvLo5BVwAUxCmthX+MJRz5eHMmtIelgucTH3yF8d5kxBmWnMVc/ 16+AZhBA7VJKlqUG5het3hdUFtLZyy0tw7uoK5WVT58hUdjyG3gLv9sQ4WK9ubEO JOb3PONl/VTuV44uVQN1IBd4OgQxiavkzBfWJ/ooduCCHzss938Lk6N9jOy/z4Bg 6B7LjD12FGX+elaGqL2vc/80j/Z2w3VCJ1GNFlfT5FXbnIOfAc1WE3nB/auHyqUg YC09PxBVe0jspwHh1bTfURXp+4TR+x2yQH/0JfIWdng8FfRF2zJZw+jK8lzH+XvY c7Z4xA== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3ys29y3yky-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Jun 2024 18:11:03 +0200 (MEST) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id A336A40044; Tue, 18 Jun 2024 18:10:59 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 4A6DA21D386; Tue, 18 Jun 2024 18:10:28 +0200 (CEST) Received: from localhost (10.252.27.64) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 18 Jun 2024 18:10:28 +0200 From: Olivier Moysan To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Olivier Moysan CC: , , Subject: [PATCH 5/8] dt-bindings: iio: add sigma delta modulator backend Date: Tue, 18 Jun 2024 18:08:31 +0200 Message-ID: <20240618160836.945242-6-olivier.moysan@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240618160836.945242-1-olivier.moysan@foss.st.com> References: <20240618160836.945242-1-olivier.moysan@foss.st.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-18_02,2024-06-17_01,2024-05-17_01 Add documentation of device tree bindings to support sigma delta modulator backend in IIO framework. Signed-off-by: Olivier Moysan --- .../iio/adc/sd-modulator-backend.yaml | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/sd-modulator-backend.yaml diff --git a/Documentation/devicetree/bindings/iio/adc/sd-modulator-backend.yaml b/Documentation/devicetree/bindings/iio/adc/sd-modulator-backend.yaml new file mode 100644 index 000000000000..b0fa71b75cd0 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/adc/sd-modulator-backend.yaml @@ -0,0 +1,43 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/sd-modulator-backend.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sigma delta modulator backend + +maintainers: + - Olivier Moysan + +properties: + compatible: + description: | + "sd-backend" can be used as a generic SD modulator backend, + if the modulator is not specified in the compatible list. + enum: + - sd-backend + - ads1201 + + '#io-backend-cells': + const: 0 + + reg: + maxItems: 1 + + vref-supply: + description: Phandle to the vref input analog reference voltage. + +required: + - compatible + - '#io-backend-cells' + +additionalProperties: false + +examples: + - | + ads1201: adc { + compatible = "sd-backend"; + #io-backend-cells = <0>; + }; + +... From patchwork Tue Jun 18 16:08:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Moysan X-Patchwork-Id: 13702676 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (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 AA4FC14EC75; Tue, 18 Jun 2024 16:12:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.207.212.93 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718727153; cv=none; b=HFbFrz5Iz/zR9rCtvIojlsVxrPTwidUBCgJ748EQMGLX8asDM3++iglWIcHbtwsbgfpPdAsCRN/ZQcziL2sxTpTf8AJjJ7USQvTkCqPUw7xpqf+q7eNGgyHDng0VX4EpNDWDAaK7+eWZz0AyiXOENY/oUG1jBMU9GVeId7l58hw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718727153; c=relaxed/simple; bh=3KU21BM4DptTemFM55sT4bR//UCVOoqfyebmjkzqEkw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=c5MFEZLRZ9EpUiHA6VZ7DASPWs/Z6MS1TSZSLtyZnkk1aNjw/2O0FTM0rOxXQLKNreI96FRtUKsIGmKmduqo+Lq/HfucIY2xn+5Nkc101Q65EppxN11GUCHwVvKpixnYSERm0kZS70PJSf8py87UDu4nxCCGdxURVgE70+nNtLI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=hqR/8pXr; arc=none smtp.client-ip=91.207.212.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="hqR/8pXr" Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45IFY30t022612; Tue, 18 Jun 2024 18:12:03 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= 1xkl3j3al9JPMlWYgUjS8acK8wY1K8FsM4cPZz1jQ5U=; b=hqR/8pXrFbYj6iDT ynObsl7be9i7NaItxP3h+jJN7743MyuhrAj41xpM03td70GK6wB5qMwzgkUNdhNj 7r7T9CqrcS/hVm+A7pyVROJtl7w6Frct3y7+pnkFyFi4cC/EwmJWGMpmOeVq3D3R vW+u6mtastr2zGfeKlB2RBL3ZewHFBZKMSj3/GU0gB4MxHi/EbIvks3hJ7Mbf7vb JJ7QRxrlM2awNoUE1WvEDV6t9FJETaiHggN+kS6dNw4QHyA1ERodEtd0CeJCGfZS FpzU76cNT9Enbhs8GuqwomZJpPZPu+Zgf0NWckdjgbX2KmEeH2TsFq4y9Wn8yC8u rDCi6w== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3ys035m8m7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Jun 2024 18:12:03 +0200 (MEST) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 430DE40044; Tue, 18 Jun 2024 18:11:59 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 8148E21BF70; Tue, 18 Jun 2024 18:11:29 +0200 (CEST) Received: from localhost (10.252.27.64) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 18 Jun 2024 18:11:29 +0200 From: Olivier Moysan To: Jonathan Cameron , Lars-Peter Clausen , Maxime Coquelin , Alexandre Torgue CC: Olivier Moysan , , , , Subject: [PATCH 6/8] iio: adc: stm32-dfsdm: adopt generic channels bindings Date: Tue, 18 Jun 2024 18:08:32 +0200 Message-ID: <20240618160836.945242-7-olivier.moysan@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240618160836.945242-1-olivier.moysan@foss.st.com> References: <20240618160836.945242-1-olivier.moysan@foss.st.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-18_02,2024-06-17_01,2024-05-17_01 Move to generic channels binding to ease new backend framework adoption and prepare the convergence with MDF IP support on STM32MP2 SoC family. Legacy binding: DFSDM is an IIO channel consumer. SD modulator is an IIO channels provider. The channel phandles are provided in DT through io-channels property and channel indexes through st,adc-channels property. New binding: DFSDM is an IIO channel provider. The channel indexes are given by reg property in channel child node. This new binding is intended to be used with SD modulator IIO backends. It does not support SD modulator legacy IIO devices. The st,adc-channels property presence is used to discriminate between legacy and backend bindings. The support of the DFSDM legacy channels and SD modulator IIO devices is kept for backward compatibility. Signed-off-by: Olivier Moysan --- drivers/iio/adc/stm32-dfsdm-adc.c | 208 ++++++++++++++++++++++++------ 1 file changed, 171 insertions(+), 37 deletions(-) diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c index 9a47d2c87f05..69b4764d7cba 100644 --- a/drivers/iio/adc/stm32-dfsdm-adc.c +++ b/drivers/iio/adc/stm32-dfsdm-adc.c @@ -666,6 +666,64 @@ static int stm32_dfsdm_channel_parse_of(struct stm32_dfsdm *dfsdm, return 0; } +static int stm32_dfsdm_generic_channel_parse_of(struct stm32_dfsdm *dfsdm, + struct iio_dev *indio_dev, + struct iio_chan_spec *ch, + struct fwnode_handle *node) +{ + struct stm32_dfsdm_channel *df_ch; + const char *of_str; + int ret, val; + + ret = fwnode_property_read_u32(node, "reg", &ch->channel); + if (ret < 0) { + dev_err(&indio_dev->dev, "Missing channel index %d\n", ret); + return ret; + } + + if (ch->channel >= dfsdm->num_chs) { + dev_err(&indio_dev->dev, " Error bad channel number %d (max = %d)\n", + ch->channel, dfsdm->num_chs); + return -EINVAL; + } + + ret = fwnode_property_read_string(node, "label", &ch->datasheet_name); + if (ret < 0) { + dev_err(&indio_dev->dev, + " Error parsing 'label' for idx %d\n", ch->channel); + return ret; + } + + df_ch = &dfsdm->ch_list[ch->channel]; + df_ch->id = ch->channel; + + ret = fwnode_property_read_string(node, "st,adc-channel-types", &of_str); + if (!ret) { + val = stm32_dfsdm_str2val(of_str, stm32_dfsdm_chan_type); + if (val < 0) + return val; + } else { + val = 0; + } + df_ch->type = val; + + ret = fwnode_property_read_string(node, "st,adc-channel-clk-src", &of_str); + if (!ret) { + val = stm32_dfsdm_str2val(of_str, stm32_dfsdm_chan_src); + if (val < 0) + return val; + } else { + val = 0; + } + df_ch->src = val; + + ret = fwnode_property_read_u32(node, "st,adc-alt-channel", &df_ch->alt_si); + if (ret != -EINVAL) + df_ch->alt_si = 0; + + return 0; +} + static ssize_t dfsdm_adc_audio_get_spiclk(struct iio_dev *indio_dev, uintptr_t priv, const struct iio_chan_spec *chan, @@ -1231,7 +1289,8 @@ static int stm32_dfsdm_read_raw(struct iio_dev *indio_dev, ret = iio_device_claim_direct_mode(indio_dev); if (ret) return ret; - ret = iio_hw_consumer_enable(adc->hwc); + if (adc->hwc) + ret = iio_hw_consumer_enable(adc->hwc); if (ret < 0) { dev_err(&indio_dev->dev, "%s: IIO enable failed (channel %d)\n", @@ -1240,7 +1299,8 @@ static int stm32_dfsdm_read_raw(struct iio_dev *indio_dev, return ret; } ret = stm32_dfsdm_single_conv(indio_dev, chan, val); - iio_hw_consumer_disable(adc->hwc); + if (adc->hwc) + iio_hw_consumer_disable(adc->hwc); if (ret < 0) { dev_err(&indio_dev->dev, "%s: Conversion failed (channel %d)\n", @@ -1367,15 +1427,20 @@ static int stm32_dfsdm_dma_request(struct device *dev, return 0; } -static int stm32_dfsdm_adc_chan_init_one(struct iio_dev *indio_dev, - struct iio_chan_spec *ch) +static int stm32_dfsdm_adc_chan_init_one(struct iio_dev *indio_dev, struct iio_chan_spec *ch, + struct fwnode_handle *child) { struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); int ret; - ret = stm32_dfsdm_channel_parse_of(adc->dfsdm, indio_dev, ch); - if (ret < 0) + if (child) + ret = stm32_dfsdm_generic_channel_parse_of(adc->dfsdm, indio_dev, ch, child); + else /* Legacy binding */ + ret = stm32_dfsdm_channel_parse_of(adc->dfsdm, indio_dev, ch); + if (ret < 0) { + dev_err(&indio_dev->dev, "Failed to parse channel\n"); return ret; + } ch->type = IIO_VOLTAGE; ch->indexed = 1; @@ -1390,6 +1455,7 @@ static int stm32_dfsdm_adc_chan_init_one(struct iio_dev *indio_dev, if (adc->dev_data->type == DFSDM_AUDIO) { ch->ext_info = dfsdm_adc_audio_ext_info; + ch->scan_index = 0; } else { ch->scan_type.shift = 8; } @@ -1397,8 +1463,51 @@ static int stm32_dfsdm_adc_chan_init_one(struct iio_dev *indio_dev, ch->scan_type.realbits = 24; ch->scan_type.storagebits = 32; - return stm32_dfsdm_chan_configure(adc->dfsdm, - &adc->dfsdm->ch_list[ch->channel]); + return stm32_dfsdm_chan_configure(adc->dfsdm, &adc->dfsdm->ch_list[ch->channel]); +} + +static int stm32_dfsdm_chan_init(struct iio_dev *indio_dev, struct iio_chan_spec *channels) +{ + int num_ch = indio_dev->num_channels; + int chan_idx = 0, ret = 0; + + for (chan_idx = 0; chan_idx < num_ch; chan_idx++) { + channels[chan_idx].scan_index = chan_idx; + ret = stm32_dfsdm_adc_chan_init_one(indio_dev, &channels[chan_idx], NULL); + if (ret < 0) { + dev_err(&indio_dev->dev, "Channels init failed\n"); + return ret; + } + } + + return ret; +} + +static int stm32_dfsdm_generic_chan_init(struct iio_dev *indio_dev, struct iio_chan_spec *channels) +{ + struct fwnode_handle *child; + int chan_idx = 0, ret; + + device_for_each_child_node(&indio_dev->dev, child) { + /* Skip DAI node in DFSDM audio nodes */ + if (fwnode_property_present(child, "compatible")) + continue; + + channels[chan_idx].scan_index = chan_idx; + ret = stm32_dfsdm_adc_chan_init_one(indio_dev, &channels[chan_idx], child); + if (ret < 0) { + dev_err(&indio_dev->dev, "Channels init failed\n"); + goto err; + } + + chan_idx++; + } + return chan_idx; + +err: + fwnode_handle_put(child); + + return ret; } static int stm32_dfsdm_audio_init(struct device *dev, struct iio_dev *indio_dev) @@ -1406,15 +1515,26 @@ static int stm32_dfsdm_audio_init(struct device *dev, struct iio_dev *indio_dev) struct iio_chan_spec *ch; struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); struct stm32_dfsdm_channel *d_ch; - int ret; + bool legacy = false; + int num_ch, ret; + + /* If st,adc-channels is defined legacy binding is used. Else assume generic binding. */ + num_ch = of_property_count_u32_elems(indio_dev->dev.of_node, "st,adc-channels"); + if (num_ch == 1) + legacy = true; ch = devm_kzalloc(&indio_dev->dev, sizeof(*ch), GFP_KERNEL); if (!ch) return -ENOMEM; - ch->scan_index = 0; + indio_dev->num_channels = 1; + indio_dev->channels = ch; + + if (legacy) + ret = stm32_dfsdm_chan_init(indio_dev, ch); + else + ret = stm32_dfsdm_generic_chan_init(indio_dev, ch); - ret = stm32_dfsdm_adc_chan_init_one(indio_dev, ch); if (ret < 0) { dev_err(&indio_dev->dev, "Channels init failed\n"); return ret; @@ -1425,9 +1545,6 @@ static int stm32_dfsdm_audio_init(struct device *dev, struct iio_dev *indio_dev) if (d_ch->src != DFSDM_CHANNEL_SPI_CLOCK_EXTERNAL) adc->spi_freq = adc->dfsdm->spi_master_freq; - indio_dev->num_channels = 1; - indio_dev->channels = ch; - return stm32_dfsdm_dma_request(dev, indio_dev); } @@ -1435,43 +1552,60 @@ static int stm32_dfsdm_adc_init(struct device *dev, struct iio_dev *indio_dev) { struct iio_chan_spec *ch; struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); - int num_ch; - int ret, chan_idx; + int num_ch, ret; + bool legacy = false; adc->oversamp = DFSDM_DEFAULT_OVERSAMPLING; ret = stm32_dfsdm_compute_all_osrs(indio_dev, adc->oversamp); if (ret < 0) return ret; - num_ch = of_property_count_u32_elems(indio_dev->dev.of_node, - "st,adc-channels"); - if (num_ch < 0 || num_ch > adc->dfsdm->num_chs) { - dev_err(&indio_dev->dev, "Bad st,adc-channels\n"); - return num_ch < 0 ? num_ch : -EINVAL; + num_ch = device_get_child_node_count(&indio_dev->dev); + if (!num_ch) { + /* No channels nodes found. Assume legacy binding */ + num_ch = of_property_count_u32_elems(indio_dev->dev.of_node, "st,adc-channels"); + if (num_ch < 0) { + dev_err(&indio_dev->dev, "Bad st,adc-channels\n"); + return num_ch; + } + + legacy = true; } - /* Bind to SD modulator IIO device */ - adc->hwc = devm_iio_hw_consumer_alloc(&indio_dev->dev); - if (IS_ERR(adc->hwc)) - return -EPROBE_DEFER; + if (num_ch > adc->dfsdm->num_chs) { + dev_err(&indio_dev->dev, "Number of channel [%d] exceeds [%d]\n", + num_ch, adc->dfsdm->num_chs); + return -EINVAL; + } + indio_dev->num_channels = num_ch; - ch = devm_kcalloc(&indio_dev->dev, num_ch, sizeof(*ch), - GFP_KERNEL); - if (!ch) - return -ENOMEM; + if (legacy) { + /* Bind to SD modulator IIO device. */ + adc->hwc = devm_iio_hw_consumer_alloc(&indio_dev->dev); + if (IS_ERR(adc->hwc)) + return -EPROBE_DEFER; + } else { + /* Generic binding. SD modulator IIO device not used. Use SD modulator backend. */ + adc->hwc = NULL; - for (chan_idx = 0; chan_idx < num_ch; chan_idx++) { - ch[chan_idx].scan_index = chan_idx; - ret = stm32_dfsdm_adc_chan_init_one(indio_dev, &ch[chan_idx]); - if (ret < 0) { - dev_err(&indio_dev->dev, "Channels init failed\n"); - return ret; - } + adc->backend = devm_kzalloc(&indio_dev->dev, sizeof(*adc->backend) * num_ch, + GFP_KERNEL); + if (!adc->backend) + return -ENOMEM; } - indio_dev->num_channels = num_ch; + ch = devm_kcalloc(&indio_dev->dev, num_ch, sizeof(*ch), GFP_KERNEL); + if (!ch) + return -ENOMEM; indio_dev->channels = ch; + if (legacy) + ret = stm32_dfsdm_chan_init(indio_dev, ch); + else + ret = stm32_dfsdm_generic_chan_init(indio_dev, ch); + if (ret < 0) + return ret; + init_completion(&adc->completion); /* Optionally request DMA */ From patchwork Tue Jun 18 16:08:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Moysan X-Patchwork-Id: 13702674 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (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 B08E94DA0C; Tue, 18 Jun 2024 16:12:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.132.182.106 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718727138; cv=none; b=VrugwjhOZWCRv3TiFCztSN8r6YaNCNc37dI9kd5snQBIOJQQ9LS+9LjFxu9XbJpFGO0LgqEdPrHq5/wV9+Voyo8P+2aPMlVC7+f+oeKE9GQN6NuL/zWVweFNyo5ML6h7X5AZqst6lZ8YEqppQs6q7lQIfQpFrMxomc++oapOnww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718727138; c=relaxed/simple; bh=AwPVk18OdGcscZHTFXzEXSjzJXtISdJya6SrT29SPXU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SOVOeiZj1s1xBp/us7/sX3nlOYLKpFo9x55+PJ53WQ4jrc7CtN4dJcFD1dnLkYrGV18orl2lURcygQQNUW6ZTVydeeNNWNb5+3WsoBLyLTFIZdrc2YG9OqdxmPDwTMIHQhCWPAvR3W5r+2BLeUStcbC4dxdqfYsIHPlQMEcL6js= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=DWg+vTeG; arc=none smtp.client-ip=185.132.182.106 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="DWg+vTeG" Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45IFxAKF024676; Tue, 18 Jun 2024 18:12:02 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= qL0QIk/5tc56Rf9/m2Q6wHM/v+PyGRnuQRu8OBBKDr4=; b=DWg+vTeGp/UYuPoA 2Os3m6pr72ek3sgwdvIL/QgGbfc2KYb6YA5AavqMoXE0nUXJ8bX3S6DkBVnybmUt ufIsCyR7TzWSwe2i3Uq577jiB1H32/Vi+X2dsOVK58ebu4+1YhIYFVwEkdxzvX5A KdN8yf5BOSOSAgBrxkHvHNeve0lwcTnQ1w9mKFT+AEl5S0oaQsUGw3eHGDWiHg9p wc+//h6fG/TO7H54moP4uH+mCl5cEkGpLi+MDalI0OoeGipGMjywi1RoJj2BIEoQ lNqanTWOdbjTBLDhkx5qYukbOynk6Erswo2z3CyMwAgt2ezEAclKqF33JTrv1H03 j2ssBA== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3ys29y3ypf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Jun 2024 18:12:01 +0200 (MEST) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 3E50E4002D; Tue, 18 Jun 2024 18:11:56 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id D4AB521BF78; Tue, 18 Jun 2024 18:11:30 +0200 (CEST) Received: from localhost (10.252.27.64) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 18 Jun 2024 18:11:30 +0200 From: Olivier Moysan To: Jonathan Cameron , Lars-Peter Clausen , Liam Girdwood , Mark Brown CC: Olivier Moysan , , Subject: [PATCH 7/8] iio: add sd modulator generic iio backend Date: Tue, 18 Jun 2024 18:08:33 +0200 Message-ID: <20240618160836.945242-8-olivier.moysan@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240618160836.945242-1-olivier.moysan@foss.st.com> References: <20240618160836.945242-1-olivier.moysan@foss.st.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-18_02,2024-06-17_01,2024-05-17_01 Add a generic driver to support sigma delta modulators. Typically, this device is a hardware connected to an IIO device in charge of the conversion. The device is exposed as an IIO backend device. This backend device and the associated conversion device can be seen as an aggregate device from IIO framework. Signed-off-by: Olivier Moysan --- drivers/iio/adc/Kconfig | 10 +++ drivers/iio/adc/Makefile | 1 + drivers/iio/adc/sd_adc_backend.c | 110 +++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 drivers/iio/adc/sd_adc_backend.c diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 3d91015af6ea..f3dfdaa80678 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -1155,6 +1155,16 @@ config SPEAR_ADC To compile this driver as a module, choose M here: the module will be called spear_adc. +config SD_ADC_BACKEND + tristate "Generic sigma delta modulator IIO backend" + select IIO_BACKEND + help + Select this option to enables sigma delta modulator. This driver can + support generic sigma delta modulators, as IIO backend devices. + + This driver can also be built as a module. If so, the module + will be called sd_adc_backend. + config SD_ADC_MODULATOR tristate "Generic sigma delta modulator" select IIO_BUFFER diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index 37ac689a0209..9aee2e4307d7 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile @@ -139,3 +139,4 @@ obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o obj-$(CONFIG_XILINX_AMS) += xilinx-ams.o xilinx-xadc-y := xilinx-xadc-core.o xilinx-xadc-events.o obj-$(CONFIG_XILINX_XADC) += xilinx-xadc.o +obj-$(CONFIG_SD_ADC_BACKEND) += sd_adc_backend.o diff --git a/drivers/iio/adc/sd_adc_backend.c b/drivers/iio/adc/sd_adc_backend.c new file mode 100644 index 000000000000..556a49dc537b --- /dev/null +++ b/drivers/iio/adc/sd_adc_backend.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Generic sigma delta modulator IIO backend + * + * Copyright (C) 2024, STMicroelectronics - All Rights Reserved + */ + +#include +#include +#include +#include +#include +#include + +struct iio_sd_backend_priv { + struct regulator *vref; + int vref_mv; +}; + +static int sd_backend_enable(struct iio_backend *backend) +{ + struct iio_sd_backend_priv *priv = iio_backend_get_priv(backend); + + return regulator_enable(priv->vref); +}; + +static void sd_backend_disable(struct iio_backend *backend) +{ + struct iio_sd_backend_priv *priv = iio_backend_get_priv(backend); + + regulator_disable(priv->vref); +}; + +static int sd_backend_read(struct iio_backend *backend, int *val, int *val2, long mask) +{ + struct iio_sd_backend_priv *priv = iio_backend_get_priv(backend); + + switch (mask) { + case IIO_CHAN_INFO_SCALE: + *val = priv->vref_mv; + *val2 = 0; + return IIO_VAL_INT; + + case IIO_CHAN_INFO_OFFSET: + *val = 0; + *val2 = 0; + return IIO_VAL_INT; + } + + return -EINVAL; +}; + +static const struct iio_backend_ops sd_backend_ops = { + .enable = sd_backend_enable, + .disable = sd_backend_disable, + .read_raw = sd_backend_read, +}; + +static int iio_sd_backend_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct regulator *vref; + struct iio_sd_backend_priv *priv; + int ret; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + vref = devm_regulator_get_optional(dev, "vref"); + if (IS_ERR(vref)) { + if (PTR_ERR(vref) != -ENODEV) + return dev_err_probe(dev, PTR_ERR(vref), "Failed to get vref\n"); + } else { + ret = regulator_get_voltage(vref); + if (ret < 0) + return ret; + + priv->vref = vref; + priv->vref_mv = ret / 1000; + } + + ret = devm_iio_backend_register(&pdev->dev, &sd_backend_ops, priv); + if (ret) + return ret; + + return 0; +}; + +static const struct of_device_id sd_backend_of_match[] = { + { .compatible = "sd-backend" }, + { .compatible = "ads1201" }, + { } +}; +MODULE_DEVICE_TABLE(of, sd_backend_of_match); + +static struct platform_driver iio_sd_backend_adc = { + .driver = { + .name = "iio_sd_adc_backend", + .of_match_table = sd_backend_of_match, + }, + .probe = iio_sd_backend_probe, +}; + +module_platform_driver(iio_sd_backend_adc); + +MODULE_DESCRIPTION("Basic sigma delta modulator IIO backend"); +MODULE_AUTHOR("Olivier Moysan "); +MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS(IIO_BACKEND); From patchwork Tue Jun 18 16:08:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Moysan X-Patchwork-Id: 13702675 Received: from mx08-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (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 6145A14EC79; Tue, 18 Jun 2024 16:12:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.207.212.93 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718727153; cv=none; b=QUYdCfOJic327qKQccNqHpCYBpyIpF60UgQBcFX6NUueu/henjGWfJfqCwh/dvzwh6H0N619rkBBvRaA1OH7rYNbPfkyUQthHSFVBuiDfP8uEXalGJV/1IlNcXUuYz9lZjrUOPOc6LmZhewMWbTKrhlKlPiu6DF0ybVlFn6UPfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718727153; c=relaxed/simple; bh=1F52Yx/ZQ4nCWj8eVMsenNJs/hsF0vmXXhuKUIvd89w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kaFuRXN0/B3e0mZGIJu0ygoEMcfiB8lejuOVq/8OCntwK9TIlbXovixNEkW2s/dpgiltNrAuD4cHRfGkiKCAVr3HPPJvwBz/3XU/XOWityDWfMbB85+o1JyoI7gv+wKhvyNU8kynykjHweNtH6PJHFCAE4QOQ8hFi9S3UqCbxyw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=EfjyD904; arc=none smtp.client-ip=91.207.212.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="EfjyD904" Received: from pps.filterd (m0369457.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45IFAEX5008943; Tue, 18 Jun 2024 18:12:04 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= S+H8H+djGQYAAsQ0PjdqLYQJy1Hwlzih8CMqVRnehcE=; b=EfjyD9044mkD/CzS aQyX5J8AxI0RFm2bxYDYHjqPGsFy2FDAWVMdZSPWydiRib+V8AD7Mc1Xz/U7JNb9 YXFnpOVTtVFmO6AjzVp00NrhL3eLEuzaTUUHpOGBwFwTdraaypUa8TrBr6ZDUr4F oLfvYsCLArgGoVNCuBFfDTv95Px8TqiGcabS1cZ1r03cQIHsn/h30FADp/1EUteL LhVNEv4D60hvmibrVSnKhEgcuO6Azjvkrwfh7C45iX645UU0/xZsDdN5jL63DK4J JAH6z/cktZQsudySTjs/O/w0Aa/q7wndNg+doXN5hiMLgVlzPR7c59bvjbKlt9pj HT+mFQ== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3ysnwja5h9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Jun 2024 18:12:04 +0200 (MEST) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 41F5F40045; Tue, 18 Jun 2024 18:12:00 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 13D6721197B; Tue, 18 Jun 2024 18:11:32 +0200 (CEST) Received: from localhost (10.252.27.64) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 18 Jun 2024 18:11:31 +0200 From: Olivier Moysan To: Jonathan Cameron , Lars-Peter Clausen , Maxime Coquelin , Alexandre Torgue CC: Olivier Moysan , , , , Subject: [PATCH 8/8] iio: adc: stm32-dfsdm: add scaling support to dfsdm Date: Tue, 18 Jun 2024 18:08:34 +0200 Message-ID: <20240618160836.945242-9-olivier.moysan@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240618160836.945242-1-olivier.moysan@foss.st.com> References: <20240618160836.945242-1-olivier.moysan@foss.st.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-18_02,2024-06-17_01,2024-05-17_01 Add scaling support to STM32 DFSDM. Signed-off-by: Olivier Moysan Acked-by: Nuno Sa --- drivers/iio/adc/Kconfig | 1 + drivers/iio/adc/stm32-dfsdm-adc.c | 94 ++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 3 deletions(-) diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index f3dfdaa80678..858ae8161fa4 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -1223,6 +1223,7 @@ config STM32_DFSDM_ADC select IIO_BUFFER select IIO_BUFFER_HW_CONSUMER select IIO_TRIGGERED_BUFFER + select IIO_BACKEND help Select this option to support ADCSigma delta modulator for STMicroelectronics STM32 digital filter for sigma delta converter. diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c index 69b4764d7cba..93bf6035bd6d 100644 --- a/drivers/iio/adc/stm32-dfsdm-adc.c +++ b/drivers/iio/adc/stm32-dfsdm-adc.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -78,6 +79,7 @@ struct stm32_dfsdm_adc { /* ADC specific */ unsigned int oversamp; struct iio_hw_consumer *hwc; + struct iio_backend **backend; struct completion completion; u32 *buffer; @@ -672,6 +674,8 @@ static int stm32_dfsdm_generic_channel_parse_of(struct stm32_dfsdm *dfsdm, struct fwnode_handle *node) { struct stm32_dfsdm_channel *df_ch; + struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); + struct iio_backend *backend; const char *of_str; int ret, val; @@ -721,6 +725,14 @@ static int stm32_dfsdm_generic_channel_parse_of(struct stm32_dfsdm *dfsdm, if (ret != -EINVAL) df_ch->alt_si = 0; + if (adc->dev_data->type == DFSDM_IIO) { + backend = devm_iio_backend_subnode_get(&indio_dev->dev, NULL, node); + if (IS_ERR(backend)) + return dev_err_probe(&indio_dev->dev, PTR_ERR(backend), + "Failed to get backend\n"); + adc->backend[ch->scan_index] = backend; + } + return 0; } @@ -1060,7 +1072,7 @@ static int stm32_dfsdm_update_scan_mode(struct iio_dev *indio_dev, static int stm32_dfsdm_postenable(struct iio_dev *indio_dev) { struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); - int ret; + int i = 0, ret; /* Reset adc buffer index */ adc->bufi = 0; @@ -1071,6 +1083,15 @@ static int stm32_dfsdm_postenable(struct iio_dev *indio_dev) return ret; } + if (adc->backend) { + while (adc->backend[i]) { + ret = iio_backend_enable(&indio_dev->dev, adc->backend[i]); + if (ret < 0) + return ret; + i++; + } + } + ret = stm32_dfsdm_start_dfsdm(adc->dfsdm); if (ret < 0) goto err_stop_hwc; @@ -1103,6 +1124,7 @@ static int stm32_dfsdm_postenable(struct iio_dev *indio_dev) static int stm32_dfsdm_predisable(struct iio_dev *indio_dev) { struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); + int i = 0; stm32_dfsdm_stop_conv(indio_dev); @@ -1110,6 +1132,13 @@ static int stm32_dfsdm_predisable(struct iio_dev *indio_dev) stm32_dfsdm_stop_dfsdm(adc->dfsdm); + if (adc->backend) { + while (adc->backend[i]) { + iio_backend_disable(&indio_dev->dev, adc->backend[i]); + i++; + } + } + if (adc->hwc) iio_hw_consumer_disable(adc->hwc); @@ -1282,7 +1311,14 @@ static int stm32_dfsdm_read_raw(struct iio_dev *indio_dev, int *val2, long mask) { struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); - int ret; + + struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id]; + struct stm32_dfsdm_filter_osr *flo = &fl->flo[fl->fast]; + u32 max = flo->max << (flo->lshift - chan->scan_type.shift); + int ret, idx = chan->scan_index; + + if (flo->lshift < chan->scan_type.shift) + max = flo->max >> (chan->scan_type.shift - flo->lshift); switch (mask) { case IIO_CHAN_INFO_RAW: @@ -1291,6 +1327,8 @@ static int stm32_dfsdm_read_raw(struct iio_dev *indio_dev, return ret; if (adc->hwc) ret = iio_hw_consumer_enable(adc->hwc); + if (adc->backend[idx]) + ret = iio_backend_enable(&indio_dev->dev, adc->backend[idx]); if (ret < 0) { dev_err(&indio_dev->dev, "%s: IIO enable failed (channel %d)\n", @@ -1301,6 +1339,8 @@ static int stm32_dfsdm_read_raw(struct iio_dev *indio_dev, ret = stm32_dfsdm_single_conv(indio_dev, chan, val); if (adc->hwc) iio_hw_consumer_disable(adc->hwc); + if (adc->backend[idx]) + iio_backend_disable(&indio_dev->dev, adc->backend[idx]); if (ret < 0) { dev_err(&indio_dev->dev, "%s: Conversion failed (channel %d)\n", @@ -1320,6 +1360,45 @@ static int stm32_dfsdm_read_raw(struct iio_dev *indio_dev, *val = adc->sample_freq; return IIO_VAL_INT; + + case IIO_CHAN_INFO_SCALE: + /* + * Scale is expressed in mV. + * When fast mode is disabled, actual resolution may be lower + * than 2^n, where n=realbits-1. + * This leads to underestimating input voltage. To + * compensate this deviation, the voltage reference can be + * corrected with a factor = realbits resolution / actual max + */ + if (adc->backend[idx]) { + iio_backend_read_raw(adc->backend[idx], val, val2, mask); + + *val = div_u64((u64)*val * (u64)BIT(DFSDM_DATA_RES - 1), max); + *val2 = chan->scan_type.realbits; + if (chan->differential) + *val *= 2; + } + return IIO_VAL_FRACTIONAL_LOG2; + + case IIO_CHAN_INFO_OFFSET: + /* + * DFSDM output data are in the range [-2^n,2^n], + * with n=realbits-1. + * - Differential modulator: + * Offset correspond to SD modulator offset. + * - Single ended modulator: + * Input is in [0V,Vref] range, where 0V corresponds to -2^n, and Vref to 2^n. + * Add 2^n to offset. (i.e. middle of input range) + * offset = offset(sd) * vref / res(sd) * max / vref. + */ + if (adc->backend[idx]) { + iio_backend_read_raw(adc->backend[idx], val, val2, mask); + + *val = div_u64((u64)max * *val, BIT(*val2 - 1)); + if (!chan->differential) + *val += max; + } + return IIO_VAL_INT; } return -EINVAL; @@ -1449,7 +1528,15 @@ static int stm32_dfsdm_adc_chan_init_one(struct iio_dev *indio_dev, struct iio_c * IIO_CHAN_INFO_RAW: used to compute regular conversion * IIO_CHAN_INFO_OVERSAMPLING_RATIO: used to set oversampling */ - ch->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); + if (child) { + ch->info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_OFFSET); + } else { + /* Legacy. Scaling not supported */ + ch->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); + } + ch->info_mask_shared_by_all = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO) | BIT(IIO_CHAN_INFO_SAMP_FREQ); @@ -1816,3 +1903,4 @@ module_platform_driver(stm32_dfsdm_adc_driver); MODULE_DESCRIPTION("STM32 sigma delta ADC"); MODULE_AUTHOR("Arnaud Pouliquen "); MODULE_LICENSE("GPL v2"); +MODULE_IMPORT_NS(IIO_BACKEND);