Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755147AbcJ3WpQ (ORCPT ); Sun, 30 Oct 2016 18:45:16 -0400 Received: from mail-db5eur01on0135.outbound.protection.outlook.com ([104.47.2.135]:61897 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752580AbcJ3WpM (ORCPT ); Sun, 30 Oct 2016 18:45:12 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=peda@axentia.se; Subject: Re: [PATCH v3 2/8] iio: inkern: add helpers to query available values from channels To: Peter Meerwald-Stadler , Jonathan Cameron References: <1477262381-7800-1-git-send-email-peda@axentia.se> <1477262381-7800-3-git-send-email-peda@axentia.se> CC: , Hartmut Knaack , Lars-Peter Clausen , Rob Herring , "Mark Rutland" , , From: Peter Rosin Organization: Axentia Technologies AB Message-ID: Date: Sun, 30 Oct 2016 22:12:32 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [217.210.101.82] X-ClientProxiedBy: DB5PR08CA0050.eurprd08.prod.outlook.com (10.166.166.146) To DB6PR0201MB2311.eurprd02.prod.outlook.com (10.169.222.150) X-MS-Office365-Filtering-Correlation-Id: e2e459ad-5b78-4db5-fb50-08d4010979c5 X-Microsoft-Exchange-Diagnostics: 1;DB6PR0201MB2311;2:X7I4P2wud01rZfkRmXFeE9+Bi1OG7DtsbEPlZbwEjbRnCZ1aQ4q6i1MnbeWFKU9Y/kMwDezPGdLqyKRclJ3sYbChuQhIJO12MflmMFJfLkl5YyIwtTnp6pGI90lJjc9fwfEeQ9Zhq3Kvv6nGuC0imQ2VoAo65P/5ENlOuJ/Jz9mx/6qteCKg/XFpkJWxXYPj5Cpb72rOzSS0XiIKdcIr0Q==;3:RAovuwws/TqD1CaA1C0CoyfddWrFkAqv4AQm9jSAc7sIUXlzamahQjXwPnZwqYChgajzUbmX2WhMZZwcVt+mxFJyIxhgwnWeAEyXeOyE9ilOXZp9AHDi9BQOtpsO2AdadVjkza0SWCnjYsuzPtfizQ== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB6PR0201MB2311; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0201MB2311;25:z8YDHmbV8yKIsrAuqbCQShgIDUXBvlaSWVY9S02TWbymz+HS6TrOKXKJJvuK0fpFz5idM+l7gMXy91ZNkuhbvXKYkgp5qElwI3tLAVAoVczX1E/talg17py82rENjTd13Ys1W8k1B+J4VG/Z1bwelWSEpP0Q5qy10LbktqqZ9nklpyCB+dhKkThsncxcKwPXMTrittGs1NqMEyfpsdoebWa/YM8wmMPWN2Y9m9PeYyNRKHU1blFSUSEz3sA3SPVvhr4TAw01X4W9Ee9PgHVLYjs/G9DC1XB/QmY0XNWfY3BRIJ0MZXudOcFgdIDgqJoHLhkics1VmUgvQOGHTCZJ8yuqAJtZEhwGHSPtW+T3hX5Ns+Y15NUxfV/TzfDtXU8JUC/8I57gN+i0YddMEQFFJD8aYhiNGmeT/tESYr7g/7uQqWLQg1BwLCqyrtF85Cfs+Q69HrNAuBrL0VdzyExA+U6w1bwmcAQcpHSol3Kn2drvI6SkoXuSvQKDshyQaDiNNAplWzmvm4puGe8O6yYYiB3wxGNdNWYyclukK+m/IhIijVOTqRX1et8ZoIx3Wc4k6bH1T5pTDQJI3Y89x/t57QTcV8uLsz6pt61lFhg3DEmvQSJ3ei8XikjG2LoyRn09EI1cuWGGscGCGHH5+i2GdzRf56s3lWd/Xdge5sCjcAKBgXOsWn2BDGSwncoJxi/LGGOiebPwW+sjM4/p1C8G0A== X-Microsoft-Exchange-Diagnostics: 1;DB6PR0201MB2311;31:c4KkeFVKweSKFovsKkPMe6OUAK698YxDln4NwtYXdiNk8DGtODsYNHpT89ZMKq3K3POyqhRg3r51A0BA7E6FWiQojzMFIM9RJRyJGmd+94Lw6lg11nd7H5XuaVGPVRi1UnzidOZEO3ABGQEPXvAQ04GZR3Gs/g2Bmc4xNSRcw/KZVDBfOUCXal2FkfITltF0/tCnVN3WQfY2zGI+SCbrvOyhg9GLyDusGI8XZk6unBroLt4vAF1gqZtFrsO2rjKQ;4:kAnFMQmstdRC+3CXOBYM/meYKp0f6Lg7s6dCqOz71Yh7TaxLjA7HCSzZTW3mQLQb9TwBoPSfR80GUcSX9Jcj981V8Ul22aKDAUL0dIvSlFyR9IHeU4QCRz77ZkZLueGiyxNOxOEeyAxcKs9pcZUlpnTEywxm+HIl3ZkVxl7MdKGhLQP3/5pCN/qRGKPG2+cXTdwNfF3jKb6K65n2qclw8jW0bf6Xhtg1mWMBlM8NXh9MBEHUlX+q7icpRIrs7JOSJS90S20pwuBMeeWzAVZyO6CM200W+TZaCIccEQgCRMzGNd/V4EacptBPUzRQkkwJJTxXv5WIo3IEMMI4k2LnCP232svUT9Orm98hq0ajcUdh7wO44RFkAnNyQLYjghQ2Fq6YFGUqcsqgBXP+laOVpfTSGCAXbwGZjuexjlpEnu4ecXZpS5iWwI5m0MnAJdTRiQ6xUT/a99o4q+QzGgh/HYptes4/IDUO9X+3H2AhpKs= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(211171220733660); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6043046)(6042046);SRVR:DB6PR0201MB2311;BCL:0;PCL:0;RULEID:;SRVR:DB6PR0201MB2311; X-Forefront-PRVS: 01110342A5 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6049001)(6009001)(7916002)(199003)(189002)(24454002)(377424004)(74482002)(86362001)(54356999)(36756003)(76176999)(83506001)(31696002)(65956001)(106356001)(65806001)(4001350100001)(105586002)(2950100002)(92566002)(66066001)(47776003)(6666003)(101416001)(50986999)(68736007)(33646002)(586003)(8676002)(189998001)(81166006)(81156014)(7846002)(93886004)(7736002)(4001150100001)(2906002)(31686004)(117156001)(305945005)(4326007)(64126003)(19580405001)(5001770100001)(97736004)(19580395003)(23746002)(50466002)(5660300001)(77096005)(65826007)(6116002)(3846002)(8666005)(42186005)(230700001)(7059030)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:DB6PR0201MB2311;H:[192.168.0.125];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;DB6PR0201MB2311;23:J9mD6JrLbpAXMH6UHtSYwmNTDDx+DorUwHN?= =?Windows-1252?Q?tdYSwVI3s5VdaJjMi7/sXCu+TMdtjr1ox1CsqIvXMia2dHYmlkmYErM1?= =?Windows-1252?Q?oxrZc4KlVpGVPPTlgzxpY8+XqjyePilsiZxEy1ZbKOJmi+PiP8TCJjE9?= =?Windows-1252?Q?wt9DlWqG5tJEONCQYNK9hyJ3dfQyg2vMFLe6Y5ZMhXYxyni/Ara81Yw7?= =?Windows-1252?Q?lSDskNnDnkEiyTjdusSEHKpv88GRnp68udwrioMVeCr0mzzDdMFcCQHr?= =?Windows-1252?Q?l4hYNSpKhG9E72ON1LvJVd78yd8Mq7DT9yXI7v6pivA2QcZt3CXMbaNA?= =?Windows-1252?Q?ZxlsRPDzdXg3AsV1kV+u7/nkVlE2mtS0RYEmuf+FtS3RTBvgyDswROip?= =?Windows-1252?Q?uu6JX8kuJV5a5SZoI72j7DWR7zarw4nQpXo1ikvzmHB2bsj4MY6CHkB1?= =?Windows-1252?Q?WAVNxqGOXb7tqx5VKoVbWlojpnnVCrdjQDq0q9bT+ytaXBGPvC8/7I3p?= =?Windows-1252?Q?Tk6P+BLk8xBoCQzBt19ZWbpYjodL9lek5PnrwSn9qioQRFh8TBx23uxu?= =?Windows-1252?Q?SGWdOTZ8s5oODoBO3Dzid3mi14W7xj51pwopHM1am56pCh/UUx3a2vBX?= =?Windows-1252?Q?Tp95jzBE7hCOScxvs0J9zQ8DdMqJIfsG6WcjIFXHhiM2noYnSqupJT+9?= =?Windows-1252?Q?N7IVp4MqOyhuO2qPGQKu2aRyWn5SGWYmVVWvBrqos7oZoEwDzc0iLnfG?= =?Windows-1252?Q?GIeDx6tGmYKu97Yd/eAn/MKUMvoCqVjBwodaucHP9JXr3VK+PhOdd8CF?= =?Windows-1252?Q?Zwtu7duRoeZdbw4DSbVjsCk9rYcJ7MB5GfkghiOrs2h5iDWCAgg0ohyF?= =?Windows-1252?Q?YGcpHFx/atXbRdZRxuAhgBWalpiY03nYIq0qqAR2Bu+FODZSCP2JJ+AZ?= =?Windows-1252?Q?GLJI78XMRFrtqjZiqpFfG+n94g7Qru8bBk1EO04x9cvl4ROwVBa67SwB?= =?Windows-1252?Q?1aa2u8CYSITb327EPqG//q8PILHv2tUb0GEu2We6b6qKF8ea+v0cSEQP?= =?Windows-1252?Q?npXBsPBUHhKvQaTZXb5hfTIo9ZjVCaVzDkT2DyAHZxLBXXJkLXzIo+Ck?= =?Windows-1252?Q?9Q3PWMhXQEneaoWwZ6zr1d9to8QXQbTXdJxF2C4U1P3DDCCYCXfgyySl?= =?Windows-1252?Q?5EtqK8aFR43UY9gIYSbRER2H4K7fLV/MBq5fDZc0p46u8RYKsdGRNznN?= =?Windows-1252?Q?1Mo25dA0BaLMazk+YS8+uN7R4zJL5qSz7b46RSRz4Sppy1EK8vU5NyiT?= =?Windows-1252?Q?HBvYjuKpNsZ7ACSiYmnbOxkKEyYCA5wiEt5beyy3u2kroWswYN8blycx?= =?Windows-1252?Q?d9SCISK/4/yJorpeT1wC1aUMgrd1LOqIsmvBpksIw0RNyDC+uPCDgYmq?= =?Windows-1252?Q?KfoNJYPq/af10vb4s5JJ/m/aeSnApmmEMd8Q1Xxzf3aWut+A0urlj5YN?= =?Windows-1252?Q?HoqyUa9p2O0eIcFjWFQMjZMyWcYAMCVuo6yXK9AnTfrH+q/+Z+CN3HjY?= =?Windows-1252?Q?ztfkwkhCi1hyvF6g=3D?= X-Microsoft-Exchange-Diagnostics: 1;DB6PR0201MB2311;6:mpU5hLBTtP4EbPe1Ci9NS77GblnBQOSeGPLOMtcSfcaPGITC+vwkG1JU0gqGHUXTVNuFCsS9CD3VGD5ErfJaiI0X+j2NySSuT2DpwfnhM8XnezcjgMJk6byTh6QU+BkffRYo99d5Ij9pKhlInMJknrdEA99D5UAiSPp1vkOJpfiOAiqK+XhmgZCa0M7bRU0FGGkAmuvn4ufhbWlIBVeBSyYNUK8skhlISOQnRMoD7kkgdI8eBJGc7HHY1jlIf7iWjE19+erpewOaHN+aG7mmRBrwOzMXGKfuoQoaDU484ax0B2Y3RC53Y/KrRHISt2Rox03Zu17GnDy7VodATxxBOg==;5:+NkFthCqSl4ZrE0MnY3UezBVMflW/LPqE0Mygehsvvz/n2NSo6ve/+1sqyvHI+przdh093q0KUynZTFpzSF4mFybD1hgEXoIt6ql8fU9rDUuTv8YjVKDmUJHuBZLRZGjZdznKULlEeASFn90+nioxA==;24:Srm1+c32ZnmlNugWDL7F+DTTmyNwUD/wmPFprut1OUCC75OLY+Wpqu4W1UsIE/ffq7NTGoECiB6scUYHM3NpOFDvqvl7ZBmNq8Zzie/OExc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DB6PR0201MB2311;7:XyNaoPJLSWh2CzJIWQp+ahRJ6J/IM0rsLV9w5zklBBFus4k2uL0bM22PXl1yOby+zXAQKC85ljV4pYBAtSpPkqK9ch7MxFmFWoNfdZA2niObaN2mBnkYtwsXQfeU8i7tE5rqGV6Uvla8KPLu65mezyNM6xuCq7OULihKfCXwIuXO81RLL7/ingZZuAo8Xl/TfTTNd/QptvLxos2ZXDYuKztS3WdJMX52QBRa56jYVGREQCnPmiwgrLgrUQNnGwOHR53+n+FbZ6cvzoriDUZoqX2BNjUIOWnLeJ0QryNuFR5CPplBVQgxRQCMTnQBeXmqWlKfBG6xwQ1/W4nWYLdqMy3UyVQttUJUcetRsw2DvoQ= X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2016 21:12:35.8720 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0201MB2311 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 7953 Lines: 247 On 2016-10-30 16:23, Peter Meerwald-Stadler wrote: > >> On 23/10/16 23:39, Peter Rosin wrote: >>> Specifically a helper for reading the available maximum raw value of a >>> channel and a helper for forwarding read_avail requests for raw values >>> from one iio driver to an iio channel that is consumed. >>> >>> These rather specific helpers are in turn built with generic helpers >>> making it easy to build more helpers for available values as needed. >>> >>> Signed-off-by: Peter Rosin >> Looks good to me. Just what I was after. > > some comments below > >> Jonathan >>> --- >>> drivers/iio/inkern.c | 97 ++++++++++++++++++++++++++++++++++++++++++++ >>> include/linux/iio/consumer.h | 29 +++++++++++++ >>> include/linux/iio/iio.h | 17 ++++++++ >>> 3 files changed, 143 insertions(+) >>> >>> diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c >>> index c4757e6367e7..74808f8a187a 100644 >>> --- a/drivers/iio/inkern.c >>> +++ b/drivers/iio/inkern.c >>> @@ -703,6 +703,103 @@ int iio_read_channel_scale(struct iio_channel *chan, int *val, int *val2) >>> } >>> EXPORT_SYMBOL_GPL(iio_read_channel_scale); >>> >>> +static int iio_channel_read_avail(struct iio_channel *chan, >>> + const int **vals, int *type, int *length, >>> + enum iio_chan_info_enum info) >>> +{ >>> + if (!iio_channel_has_available(chan->channel, info)) >>> + return -EINVAL; >>> + >>> + return chan->indio_dev->info->read_avail(chan->indio_dev, chan->channel, >>> + vals, type, length, info); >>> +} >>> + >>> +int iio_read_avail_channel_raw(struct iio_channel *chan, >>> + const int **vals, int *type, int *length) >>> +{ >>> + int ret; >>> + >>> + mutex_lock(&chan->indio_dev->info_exist_lock); >>> + if (!chan->indio_dev->info) { >>> + ret = -ENODEV; >>> + goto err_unlock; >>> + } >>> + >>> + ret = iio_channel_read_avail(chan, >>> + vals, type, length, IIO_CHAN_INFO_RAW); >>> +err_unlock: >>> + mutex_unlock(&chan->indio_dev->info_exist_lock); >>> + >>> + return ret; >>> +} >>> +EXPORT_SYMBOL_GPL(iio_read_avail_channel_raw); >>> + >>> +static int iio_channel_read_max(struct iio_channel *chan, >>> + int *val, int *val2, int *type, >>> + enum iio_chan_info_enum info) >>> +{ >>> + int unused; >>> + const int *vals; >>> + int length; >>> + int ret; >>> + >>> + if (!val2) >>> + val2 = &unused; >>> + >>> + ret = iio_channel_read_avail(chan, &vals, type, &length, info); >>> + switch (ret) { >>> + case IIO_AVAIL_RANGE: >>> + switch (*type) { >>> + case IIO_VAL_INT: >>> + *val = vals[2]; >>> + break; >>> + default: >>> + *val = vals[4]; >>> + *val2 = vals[5]; >>> + } >>> + return 0; >>> + >>> + case IIO_AVAIL_LIST: >>> + if (length <= 0) >>> + return -EINVAL; >>> + switch (*type) { >>> + case IIO_VAL_INT: >>> + *val = vals[--length]; >>> + while (length) { >>> + if (vals[--length] > *val) >>> + *val = vals[length]; >>> + } >>> + break; >>> + default: >>> + /* FIXME: learn about max for other iio values */ >>> + return -EINVAL; >>> + } >>> + return 0; >>> + >>> + default: >>> + return ret; >>> + } >>> +} >>> + >>> +int iio_read_max_channel_raw(struct iio_channel *chan, int *val) >>> +{ >>> + int ret; >>> + int type; >>> + >>> + mutex_lock(&chan->indio_dev->info_exist_lock); >>> + if (!chan->indio_dev->info) { >>> + ret = -ENODEV; >>> + goto err_unlock; >>> + } >>> + >>> + ret = iio_channel_read_max(chan, val, NULL, &type, IIO_CHAN_INFO_RAW); >>> +err_unlock: >>> + mutex_unlock(&chan->indio_dev->info_exist_lock); >>> + >>> + return ret; >>> +} >>> +EXPORT_SYMBOL_GPL(iio_read_max_channel_raw); >>> + >>> int iio_get_channel_type(struct iio_channel *chan, enum iio_chan_type *type) >>> { >>> int ret = 0; >>> diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h >>> index 9edccfba1ffb..baab5e45734f 100644 >>> --- a/include/linux/iio/consumer.h >>> +++ b/include/linux/iio/consumer.h >>> @@ -226,6 +226,35 @@ int iio_read_channel_processed(struct iio_channel *chan, int *val); >>> int iio_write_channel_raw(struct iio_channel *chan, int val); >>> >>> /** >>> + * iio_read_max_channel_raw() - read maximum available raw value from a given >>> + * channel >>> + * @chan: The channel being queried. >>> + * @val: Value read back. >>> + * >>> + * Note raw reads from iio channels are in adc counts and hence > > "Note: raw reads..." would be easier... > here and below All other function comments lack the colon after that Note, so I was just following that lead. I suggest that this can be fixed up later with one patch for all comments, if needed? > why is there no val2 here? Everything else in inkern.c that handles the raw channel assumes it is of type IIO_VAL_INT. Again, just following the lead. > just reading the documentation ("maximum available raw value") I am not > sure what the function does: does it return the maximum value possible? or > the maximum value in some internal buffer? maximum value ever seen? Maximum possible, that's what the available attribute is all about; possible values. How about: * iio_read_max_channel_raw() - read maximum available raw value from a given * channel, i.e. the maximum possible value. >>> + * scale will need to be applied if standard units are required. >>> + */ >>> +int iio_read_max_channel_raw(struct iio_channel *chan, int *val); >>> + >>> +/** >>> + * iio_read_avail_channel_raw() - read available raw values from a given channel >>> + * @chan: The channel being queried. >>> + * @vals: Available values read back. > > no vals2? Same raw channel assumption about IIO_VAL_INT. >>> + * @type: Type of available values in vals. > > it is not clear what type is Same as in the iio_channel_has_info function right above which has the same kind of explanation. Again, just following the lead. >>> + * @length: Number of entries in vals. >>> + * >>> + * Returns an error code, IIO_AVAIL_RANGE or IIO_AVAIL_LIST. >>> + * >>> + * For ranges, three vals are always returned; min, step and max. >>> + * For lists, all the possible values are enumerated. >>> + * >>> + * Note raw available values from iio channels are in adc counts and >>> + * hence scale will need to be applied if standard units are required. >>> + */ >>> +int iio_read_avail_channel_raw(struct iio_channel *chan, >>> + const int **vals, int *type, int *length); >>> + >>> +/** >>> * iio_get_channel_type() - get the type of a channel >>> * @channel: The channel being queried. >>> * @type: The type of the channel. >>> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h >>> index 45b781084a4b..e565701d13ce 100644 >>> --- a/include/linux/iio/iio.h >>> +++ b/include/linux/iio/iio.h >>> @@ -315,6 +315,23 @@ static inline bool iio_channel_has_info(const struct iio_chan_spec *chan, >>> (chan->info_mask_shared_by_all & BIT(type)); >>> } >>> >>> +/** >>> + * iio_channel_has_available() - Checks if a channel has an available attribute >>> + * @chan: The channel to be queried >>> + * @type: Type of the available attribute to be checked >>> + * >>> + * Returns true if the channels supports reporting available values for the > > channel I'll fix that. Sigh, I guess there's enough small changes that I'll need to do a v4. I'll hold off on that for a couple of days though since there is nothing badly wrong... Cheers, Peter >>> + * given attribute type, false otherwise. >>> + */ >>> +static inline bool iio_channel_has_available(const struct iio_chan_spec *chan, >>> + enum iio_chan_info_enum type) >>> +{ >>> + return (chan->info_mask_separate_available & BIT(type)) | >>> + (chan->info_mask_shared_by_type_available & BIT(type)) | >>> + (chan->info_mask_shared_by_dir_available & BIT(type)) | >>> + (chan->info_mask_shared_by_all_available & BIT(type)); >>> +} >>> + >>> #define IIO_CHAN_SOFT_TIMESTAMP(_si) { \ >>> .type = IIO_TIMESTAMP, \ >>> .channel = -1, \ >>> >> >