From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753689AbdC0OYQ (ORCPT ); Mon, 27 Mar 2017 10:24:16 -0400 Received: from mail-db5eur01on0100.outbound.protection.outlook.com ([104.47.2.100]:11432 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753000AbdC0OVM (ORCPT ); Mon, 27 Mar 2017 10:21:12 -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 v12 04/10] iio: inkern: api for manipulating ext_info of iio channels Date: Mon, 27 Mar 2017 16:21:59 +0200 Message-ID: <1490624525-15865-5-git-send-email-peda@axentia.se> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1490624525-15865-1-git-send-email-peda@axentia.se> References: <1490624525-15865-1-git-send-email-peda@axentia.se> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [81.224.171.159] X-ClientProxiedBy: DB6PR0202CA0048.eurprd02.prod.outlook.com (10.171.70.34) To DB6PR0202MB2550.eurprd02.prod.outlook.com (10.169.211.8) X-MS-Office365-Filtering-Correlation-Id: 7ebbbae8-5f4d-46cc-d583-08d4751c7112 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:DB6PR0202MB2550; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0202MB2550;3:RPPqPhPpWl5OQABQlXdZLKK4wxfkESVBy92aUxIfh3nSX8Mddc2xreTB0YFdq+sgRMiFAlDcaejerZXN/81hRaexypvVXwHOXuEgjN3KNb7vgAbc9w6E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rZ+4dh0IygV1bwcyUl89TT2BMhNbIYA3sQkz7NUQsuE5QMNEE3pE/rg6Bht5+aF+5DrWLjxJNV/NJNVlARQJ7Twk0SkZK7Uc6YurVNS7cQ8kAnsGBB/3FlfqsZaiF085CmJbufSR6414wVsZ/GjGj0Ao8g7JBwhBpfIjQQ2pqYU4FTm9Wh9bdnEvcqWwHav59MuZFwDL/14mXpXKCk/8yHGE6xchGADpl1AqeU0USNCktyOVFaqrDp85wnOAn5T7ZWL/aPnJRKtMtJYiQX1blxsIMsf9UpvCBK/8wgNWgfWNQ/3RFoj0Gmhmx+WkfQ0/fe50GrOWC+17RXx+75CMU4guIDEKyHOZDncDnlU2A8s1vFJdPMGk9V2ZNukqhk5xki8pfBoqtElT+WI9cbA6gNmreKdNfG8+nOQ83eV92iJe4EnoEENCQFLBC8Grvxg1r9xLaGHXMfk9Ecb3cpPAa1eBWzkhKvS0J1mujUkt267yIFh82gSrfXsDOh++MEuMf4gE18Eup9eatms72U2DvxhuDLm9FapyFSzE= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6041248)(20161123564025)(20161123558025)(20161123555025)(20161123560025)(20161123562025)(2016111802025)(6072148)(6043046);SRVR:DB6PR0202MB2550;BCL:0;PCL:0;RULEID:;SRVR:DB6PR0202MB2550; X-Forefront-PRVS: 02596AB7DA X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(6069001)(39840400002)(39410400002)(39450400003)(4326008)(36756003)(5003940100001)(33646002)(50466002)(53936002)(76176999)(66066001)(47776003)(6506006)(6486002)(7736002)(8666007)(50986999)(54906002)(38730400002)(50226002)(86362001)(6512007)(48376002)(3846002)(6116002)(8676002)(110136004)(2906002)(81166006)(42186005)(7416002)(189998001)(6916009)(305945005)(6666003)(25786009)(2950100002)(74482002)(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:Xij+WflaX+wnn0yBTaGbTSHM1wsdKszu0H6ncK8?= =?us-ascii?Q?J2iL0Tm2H9ZrCDOHhctptYnmrbRgwrDhB7c3wsGf2l2vti47ePzBgTbNzHo1?= =?us-ascii?Q?IgmDsWUwumNqMuVemm+QtYNuZBPlVNdcZI0X+y+Tmob3o7Z5zk78awQa2bmA?= =?us-ascii?Q?KUy/xEXNg8xsHvep/74hd2yLc9TJJcElycPCVBfQ+ilIgusKee9q7Z654bd4?= =?us-ascii?Q?0iSptZto582HjOfJI7qo97Gme14v/UkhwZYU7LRmo7C7Ma87jItSfuySQ6Hm?= =?us-ascii?Q?xtcyw2mCZEoCXFQAaW6FRQNWZfYS750Uyi+TnNE10iovw0dpxXVN6yWwWkTq?= =?us-ascii?Q?AGpfsxU/A/LBo2ARaWIaJonWrwBV2ypsVTIV5xaYL6HZ9ewrilh3uUuSBrLW?= =?us-ascii?Q?8HSbr2jVT/3RxT2mulf0nvfJGqaAJg2qc5fBjjckqdBFf5NKZZmE+6yZ5wM2?= =?us-ascii?Q?2xFq+zt3NsHNxJkbhUg5HlK+PoCNcCpT8STPcIKk/FrCMOifOenambaqmx+q?= =?us-ascii?Q?/Og3SIC5PcJ1wGYbDS/hTHzpr2fVIGTWdFQhaJULANjqx2idk8QGYOtDdy71?= =?us-ascii?Q?JOmKQ6MJR0KJwQajz2hn6YGhQoxNatZQgZHqlTL07Hk2pW4GKmPmcVI7zTOy?= =?us-ascii?Q?iKKEHoW3MKZ6ee6X+3+lPJ7+wg+KwB4/WuEptPlnx8o+5CR5w5Vt8Ot3Ar3l?= =?us-ascii?Q?O/muFEHiWVbN9j//Z92QaM7ruzCZrtcAdAvYY0Wz+44/HnZyzUW6hk8R9ake?= =?us-ascii?Q?EZal5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ac1xWorldnOr7cQc+1wGDCAf7W4mDM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DB6PR0202MB2550;7:XOLK/JIRVkygYjxfJcbWK6AFxk71pjrtd6UyCnD5E2cxrYZmIbD8GTX98eU0Xr50WOEu0wC2VD8c0Yp/ovCECZFQNLRxVHiDWStuxv91FsUE7r6n4fIFvc+xUUvs/G/pZHJeDRtDGHxUMxzmLVw2pqrRFAxJe5HytynwHcQE164tl0ktMTG0Us6ZsSKeuqbR1109KQ83u3p3rlEBFUUMmiv2AyY95VDZz93r8vtK+vB/OucKxFGGjXg5XaB69odYTuIaW/2ssyDv3V0Bn4c7ZOhLW+7XdIq0TuqYAibSRvu3gXgIxUGYU9CGjq1+CL2lxuj1a1AI2rL3zpQOdwrngQ== X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2017 14:20:36.6132 (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