From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753227AbdC0MUj (ORCPT ); Mon, 27 Mar 2017 08:20:39 -0400 Received: from mail-eopbgr30115.outbound.protection.outlook.com ([40.107.3.115]:55773 "EHLO EUR03-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752891AbdC0MSD (ORCPT ); Mon, 27 Mar 2017 08:18:03 -0400 Authentication-Results: linuxfoundation.org; dkim=none (message not signed) header.d=none;linuxfoundation.org; dmarc=none action=none header.from=axentia.se; From: Peter Rosin To: Greg Kroah-Hartman CC: Peter Rosin , Wolfram Sang , "Rob Herring" , Mark Rutland , "Jonathan Cameron" , Hartmut Knaack , "Lars-Peter Clausen" , Peter Meerwald-Stadler , Jonathan Corbet , , , , , , Andrew Morton , Colin Ian King , "Paul Gortmaker" Subject: [PATCH v11 04/12] iio: inkern: api for manipulating ext_info of iio channels Date: Mon, 27 Mar 2017 14:17:41 +0200 Message-ID: <1490617069-13119-5-git-send-email-peda@axentia.se> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1490617069-13119-1-git-send-email-peda@axentia.se> References: <1490617069-13119-1-git-send-email-peda@axentia.se> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [81.224.171.159] X-ClientProxiedBy: HE1PR0402CA0008.eurprd04.prod.outlook.com (10.175.27.18) To DB6PR0202MB2550.eurprd02.prod.outlook.com (10.169.211.8) X-MS-Office365-Filtering-Correlation-Id: 6cb08fd9-5802-4ebc-3a9c-08d4750b1911 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:DB6PR0202MB2550; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0202MB2550;3:w7huFieTtGih4A714MIf7j6Cu/kaiOYfhZ6upoX1IVxdDtROj/E8uVgVoN4Q8lLHGRDKRlPsNv4yMbCl4zX09hrXQ3qK1Bh2XWOnn38U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+61U5J1ZBPdX6KFS4BPenMn/nqpCJQrXoSYldbVYrOCfga4I7fpugXmHCxQ7HXwkA7YPqKPBc6OxZuwIN3KNvEKQ7anpcc/cEzmNglD41lVF3lARc7rJOdecir7G9spVOhxlr88girZ8nqzEBuBXcwRc4ryQsfe47rlcbqvn1a/47pAhyB0zpcW3cZ7mJ+UWRqiTDRAwVWa0c6ugdZrlQLc3nyz+DRLF3pvqgvqnJlL8trqgdkdypL/LRXiqWaEvxTrTKT6pLzmChVWwNolrK7S1bDEU0ICqrBmeFimOWRHA+2nOSI91YzD0qkJDkF2ubS6qk/R8OgoZNTuVCXBzj/oLd3E6EE0au0D53+2YuIARgJNCazLrtUMadNImf643rahLEjfUuuexdTzXcxIP8F6CSUzuMlfwkLCJST3cJdf7UEI+CYvx/P4DEC+SjB0yT9gn7OhfTanBTrjO4ON2ReSTKxSkeSdRw3z7amfsymlGuF/1RxCZdmRGgeJSPN//Q80qdemjGLrOZaY= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6041248)(20161123555025)(20161123558025)(20161123564025)(2016111802025)(20161123562025)(20161123560025)(6072148)(6043046);SRVR:DB6PR0202MB2550;BCL:0;PCL:0;RULEID:;SRVR:DB6PR0202MB2550; X-Forefront-PRVS: 02596AB7DA X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6069001)(6009001)(39410400002)(39450400003)(39830400002)(36756003)(4326008)(50466002)(5003940100001)(33646002)(76176999)(53936002)(66066001)(6506006)(47776003)(6486002)(7736002)(8666007)(50986999)(54906002)(38730400002)(50226002)(86362001)(48376002)(6512007)(3846002)(6116002)(110136004)(8676002)(2906002)(189998001)(81166006)(42186005)(7416002)(6916009)(305945005)(6666003)(74482002)(2950100002)(25786009)(5660300001)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:DB6PR0202MB2550;H:localhost.localdomain;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DB6PR0202MB2550;23:ieDmguHMgqMGRraJHLRzbnEGzzUcQ2brhJg4tl4?= =?us-ascii?Q?bzGfb/0edo6z8GcL31mh1wOruIKdI/WMhLYfC9gHeydGdwyezcktF8wH0RV8?= =?us-ascii?Q?P7IpRDFcp+muT4reOB8HZOHZfnGx9yvJF5D9vk8RpKyBpYU4pnHFuRaThZoN?= =?us-ascii?Q?syaxAfrucy34JGXlqglqp0aW9PiRT/dRZ2+5ghjud8UE0UmzitFar2o93Hj5?= =?us-ascii?Q?Eqr+1+PT0YH1vx5yViAI/iDjUx8cvRc4ZQFQwWt/HATuoONf0RvYLHMXBBeU?= =?us-ascii?Q?mrtS27anU4tCSjTGiRwe/do9gNbqVbVy7HuQV645qmuLkJYPtJyq/gn9N2/Q?= =?us-ascii?Q?PwGBFfqKIt6dGnOy+AVuFjBiW5/CoGYH+nZobPT2rfcNvij6Ly2tNLAKAgPD?= =?us-ascii?Q?ZQTUhJTIIO3sldnbPloxev2kEs02lGj7nb0da8gkshkHPlX8iuhY8gJggdBo?= =?us-ascii?Q?lba8lJnwjdWovS4ck62vU/CVwLZpkVn3OnP3tN3XpscgakKpJN1MyDu7pTn2?= =?us-ascii?Q?OatxJPoytzTZX4jhV7H9NsYLs2+/ITFjs75szZt1aQUp0oi3XyreNc/AxXnt?= =?us-ascii?Q?J31q09t4wSsHAJT/rfeE+4IjYGCl1dazrbdsXLUa7KAlmIJPY5N9G0WihaT1?= =?us-ascii?Q?I6CqAnqQ35iIAMcOcff0SUjO91oNObZcIHAtkbiFmaV4fX3pTB0YxazlVPql?= =?us-ascii?Q?Jzq0Eq6WqelqUaDBU6kIWFIcqJvKnpeAL3yjmL2vTQkAIcPqpUxEcTQ0HBVJ?= =?us-ascii?Q?gUhUGfrZu40/N+KH1mITc2qZd880RoCuhDe4EJg8C0yiAZh9Ks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agnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DB6PR0202MB2550;7:u4Eq8JSn+JWFYXQC60UImzISY4pERVV++LasAzStYv2Xb95rCnHhOOXGwkBEJCtcbZCfAkagWLMYZqNt3ebEGL9i1KzYi+PndMdAlRNYkXxQKn9mVqoQwSjulRzRTtVXRtqtu8SHfCMsOliIv8LCkb3bXqef3XrO1eASU9Fhl8mqnOG3L/yu4yBY27NWWfxbtTwQYjgmcGkKWYb9fLidEaAe5syHzatFsdq6hcHNHveOHr/dVyv5GlVIKlEQlCE1vyBYEfxU7iRJd28cpV7WW99rWfmawrECqcgBonu6VL/UghjNdhYkKw5zDAQ+4Id1uWTXe9qWlJKvIjm2yyf80w== X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2017 12:16:26.9983 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0202MB2550 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Extend the inkern api with functions for reading and writing ext_info of iio channels. Acked-by: Jonathan Cameron Signed-off-by: Peter Rosin --- drivers/iio/inkern.c | 60 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/iio/consumer.h | 37 +++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 7a13535dc3e9..8292ad4435ea 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -869,3 +869,63 @@ int iio_write_channel_raw(struct iio_channel *chan, int val) return ret; } EXPORT_SYMBOL_GPL(iio_write_channel_raw); + +unsigned int iio_get_channel_ext_info_count(struct iio_channel *chan) +{ + const struct iio_chan_spec_ext_info *ext_info; + unsigned int i = 0; + + if (!chan->channel->ext_info) + return i; + + for (ext_info = chan->channel->ext_info; ext_info->name; ext_info++) + ++i; + + return i; +} +EXPORT_SYMBOL_GPL(iio_get_channel_ext_info_count); + +static const struct iio_chan_spec_ext_info *iio_lookup_ext_info( + const struct iio_channel *chan, + const char *attr) +{ + const struct iio_chan_spec_ext_info *ext_info; + + if (!chan->channel->ext_info) + return NULL; + + for (ext_info = chan->channel->ext_info; ext_info->name; ++ext_info) { + if (!strcmp(attr, ext_info->name)) + return ext_info; + } + + return NULL; +} + +ssize_t iio_read_channel_ext_info(struct iio_channel *chan, + const char *attr, char *buf) +{ + const struct iio_chan_spec_ext_info *ext_info; + + ext_info = iio_lookup_ext_info(chan, attr); + if (!ext_info) + return -EINVAL; + + return ext_info->read(chan->indio_dev, ext_info->private, + chan->channel, buf); +} +EXPORT_SYMBOL_GPL(iio_read_channel_ext_info); + +ssize_t iio_write_channel_ext_info(struct iio_channel *chan, const char *attr, + const char *buf, size_t len) +{ + const struct iio_chan_spec_ext_info *ext_info; + + ext_info = iio_lookup_ext_info(chan, attr); + if (!ext_info) + return -EINVAL; + + return ext_info->write(chan->indio_dev, ext_info->private, + chan->channel, buf, len); +} +EXPORT_SYMBOL_GPL(iio_write_channel_ext_info); diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h index 47eeec3218b5..5e347a9805fd 100644 --- a/include/linux/iio/consumer.h +++ b/include/linux/iio/consumer.h @@ -312,4 +312,41 @@ int iio_read_channel_scale(struct iio_channel *chan, int *val, int iio_convert_raw_to_processed(struct iio_channel *chan, int raw, int *processed, unsigned int scale); +/** + * iio_get_channel_ext_info_count() - get number of ext_info attributes + * connected to the channel. + * @chan: The channel being queried + * + * Returns the number of ext_info attributes + */ +unsigned int iio_get_channel_ext_info_count(struct iio_channel *chan); + +/** + * iio_read_channel_ext_info() - read ext_info attribute from a given channel + * @chan: The channel being queried. + * @attr: The ext_info attribute to read. + * @buf: Where to store the attribute value. Assumed to hold + * at least PAGE_SIZE bytes. + * + * Returns the number of bytes written to buf (perhaps w/o zero termination; + * it need not even be a string), or an error code. + */ +ssize_t iio_read_channel_ext_info(struct iio_channel *chan, + const char *attr, char *buf); + +/** + * iio_write_channel_ext_info() - write ext_info attribute from a given channel + * @chan: The channel being queried. + * @attr: The ext_info attribute to read. + * @buf: The new attribute value. Strings needs to be zero- + * terminated, but the terminator should not be included + * in the below len. + * @len: The size of the new attribute value. + * + * Returns the number of accepted bytes, which should be the same as len. + * An error code can also be returned. + */ +ssize_t iio_write_channel_ext_info(struct iio_channel *chan, const char *attr, + const char *buf, size_t len); + #endif -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Rosin Subject: [PATCH v11 04/12] iio: inkern: api for manipulating ext_info of iio channels Date: Mon, 27 Mar 2017 14:17:41 +0200 Message-ID: <1490617069-13119-5-git-send-email-peda@axentia.se> References: <1490617069-13119-1-git-send-email-peda@axentia.se> Mime-Version: 1.0 Content-Type: text/plain Return-path: In-Reply-To: <1490617069-13119-1-git-send-email-peda@axentia.se> Sender: linux-doc-owner@vger.kernel.org To: Greg Kroah-Hartman Cc: Peter Rosin , Wolfram Sang , Rob Herring , Mark Rutland , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Jonathan Corbet , linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-doc@vger.kernel.org, Andrew Morton , Colin Ian King , Paul Gortmaker List-Id: devicetree@vger.kernel.org Extend the inkern api with functions for reading and writing ext_info of iio channels. Acked-by: Jonathan Cameron Signed-off-by: Peter Rosin --- drivers/iio/inkern.c | 60 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/iio/consumer.h | 37 +++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 7a13535dc3e9..8292ad4435ea 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -869,3 +869,63 @@ int iio_write_channel_raw(struct iio_channel *chan, int val) return ret; } EXPORT_SYMBOL_GPL(iio_write_channel_raw); + +unsigned int iio_get_channel_ext_info_count(struct iio_channel *chan) +{ + const struct iio_chan_spec_ext_info *ext_info; + unsigned int i = 0; + + if (!chan->channel->ext_info) + return i; + + for (ext_info = chan->channel->ext_info; ext_info->name; ext_info++) + ++i; + + return i; +} +EXPORT_SYMBOL_GPL(iio_get_channel_ext_info_count); + +static const struct iio_chan_spec_ext_info *iio_lookup_ext_info( + const struct iio_channel *chan, + const char *attr) +{ + const struct iio_chan_spec_ext_info *ext_info; + + if (!chan->channel->ext_info) + return NULL; + + for (ext_info = chan->channel->ext_info; ext_info->name; ++ext_info) { + if (!strcmp(attr, ext_info->name)) + return ext_info; + } + + return NULL; +} + +ssize_t iio_read_channel_ext_info(struct iio_channel *chan, + const char *attr, char *buf) +{ + const struct iio_chan_spec_ext_info *ext_info; + + ext_info = iio_lookup_ext_info(chan, attr); + if (!ext_info) + return -EINVAL; + + return ext_info->read(chan->indio_dev, ext_info->private, + chan->channel, buf); +} +EXPORT_SYMBOL_GPL(iio_read_channel_ext_info); + +ssize_t iio_write_channel_ext_info(struct iio_channel *chan, const char *attr, + const char *buf, size_t len) +{ + const struct iio_chan_spec_ext_info *ext_info; + + ext_info = iio_lookup_ext_info(chan, attr); + if (!ext_info) + return -EINVAL; + + return ext_info->write(chan->indio_dev, ext_info->private, + chan->channel, buf, len); +} +EXPORT_SYMBOL_GPL(iio_write_channel_ext_info); diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h index 47eeec3218b5..5e347a9805fd 100644 --- a/include/linux/iio/consumer.h +++ b/include/linux/iio/consumer.h @@ -312,4 +312,41 @@ int iio_read_channel_scale(struct iio_channel *chan, int *val, int iio_convert_raw_to_processed(struct iio_channel *chan, int raw, int *processed, unsigned int scale); +/** + * iio_get_channel_ext_info_count() - get number of ext_info attributes + * connected to the channel. + * @chan: The channel being queried + * + * Returns the number of ext_info attributes + */ +unsigned int iio_get_channel_ext_info_count(struct iio_channel *chan); + +/** + * iio_read_channel_ext_info() - read ext_info attribute from a given channel + * @chan: The channel being queried. + * @attr: The ext_info attribute to read. + * @buf: Where to store the attribute value. Assumed to hold + * at least PAGE_SIZE bytes. + * + * Returns the number of bytes written to buf (perhaps w/o zero termination; + * it need not even be a string), or an error code. + */ +ssize_t iio_read_channel_ext_info(struct iio_channel *chan, + const char *attr, char *buf); + +/** + * iio_write_channel_ext_info() - write ext_info attribute from a given channel + * @chan: The channel being queried. + * @attr: The ext_info attribute to read. + * @buf: The new attribute value. Strings needs to be zero- + * terminated, but the terminator should not be included + * in the below len. + * @len: The size of the new attribute value. + * + * Returns the number of accepted bytes, which should be the same as len. + * An error code can also be returned. + */ +ssize_t iio_write_channel_ext_info(struct iio_channel *chan, const char *attr, + const char *buf, size_t len); + #endif -- 2.1.4