Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965183AbcJWDUE (ORCPT ); Sat, 22 Oct 2016 23:20:04 -0400 Received: from mail-db5eur01on0114.outbound.protection.outlook.com ([104.47.2.114]:63473 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935604AbcJWDUC (ORCPT ); Sat, 22 Oct 2016 23:20:02 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=peda@axentia.se; From: Peter Rosin To: CC: Peter Rosin , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , "Peter Meerwald-Stadler" , Rob Herring , "Mark Rutland" , , Subject: [PATCH v2 2/7] iio: mcp4531: provide range of available raw values Date: Sun, 23 Oct 2016 00:43:41 +0200 Message-ID: <1477176226-10566-3-git-send-email-peda@axentia.se> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1477176226-10566-1-git-send-email-peda@axentia.se> References: <1477176226-10566-1-git-send-email-peda@axentia.se> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [217.210.101.82] X-ClientProxiedBy: DBXPR04CA0046.eurprd04.prod.outlook.com (10.141.8.174) To VI1PR0201MB2317.eurprd02.prod.outlook.com (10.168.63.19) X-MS-Office365-Filtering-Correlation-Id: 2f9cdd85-6508-4495-53e0-08d3faccff93 X-Microsoft-Exchange-Diagnostics: 1;VI1PR0201MB2317;2:BROQ+iQAZcd8bdJ1AfXyZ9CP6+InZznWxEO2c+9ER5vgE/e+RS7Lz8Dw5WY83+Dj3lipNa+RH4azv8scMyjZFzW0awaguztz5IErYaP/u3ScR5kjoUMO9vP5MGmHkiZGORm4cbu00u7B7gnk8aq03yZrkS3t0Oz90cuSsWi9+SbggtYBo1mnXIwFhuYFhrOlc8Y2BS2yK3fL2OT7AnBAnQ==;3:VTW8BboegYJEym7gCPk7Gi3z/dhLYkN/9RqRk7DFHGEVOzgR9L4hWgKTsetOwvKOUvj8MrJwOA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NJ1onaUpkazEIhFz5PFjOFrBb0hSIF0yJ8kslUHqIfjueyC9MVjIMV6oxyKfX4QjS1u5fZ795vNKJx+J/To19Ylh8QMGC03GeahW1p0ZvNF0yRvLBvNaxWbNpy1rkTfQ1JtiHcIMwm5YImVQWrYvX2duAuDJQeLDWoVtL37q3oKzgm3+BfaEYxchQ==;4:1vpYD5gSI4qTHXwh26HDLz0hwDUi/jITuDwcUEbbOQGaUbuJeMXx9spVL/bZ+r1X/wufHHnwxycsi3ftD88Y88AhHkIEgSkoktyDIoUiY3DX10Jtg5rPjInmFhWPKidrnAkI7XqGJBa6Pt3yx2HHWR1wRpAM5ahQJLAh6X4ewYfwax5YGhVPOZSn4nAJ8PNKoFtcQ5o+VNEX8U8sEnzypK/IdNmKpn7J+HWgWxYMI2tgymmiiVfT0Mp/a8aF917wWv0HZkG2u9XEQ0rv8v9RAH3k67q2NN+l52CBzKZSsRsJsht2uv8RrXBxqk0vpHA6OFF+8Qpdl6SNxpBd+2CEBrevVAXhN1aTJcJ4riIX/d6WsnEyQyM3IJpOq0WL4OHtVHUh86FBRMKIrKzJkYzQdC9WJdGFdfiZbsHKOFwuo/a0lCqMXkMm4UrMV5wuzGy5 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6043046)(6042046);SRVR:VI1PR0201MB2317;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0201MB2317; X-Forefront-PRVS: 01039C93E4 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(6069001)(7916002)(189002)(199003)(33646002)(5660300001)(189998001)(74482002)(110136003)(97736004)(19580405001)(19580395003)(68736007)(81156014)(77096005)(8676002)(92566002)(81166006)(50226002)(48376002)(50466002)(50986999)(305945005)(6666003)(42186005)(2950100002)(6916009)(2906002)(36756003)(229853001)(8666005)(2351001)(7736002)(7846002)(105586002)(76176999)(101416001)(3846002)(5003940100001)(586003)(6116002)(106356001)(4326007)(47776003)(66066001)(86362001)(7059030)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0201MB2317;H:localhost.localdomain;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;VI1PR0201MB2317;23:QJycn3EaprX5BFe9Re7Nv6nZCr+lLj+hnOChtJI?= =?us-ascii?Q?yUJtLw0zLQ/iDxpFiAkl+3jDkVFSklTPPbfo2oBc+rf9MvIV0sqvvHvSQQEi?= =?us-ascii?Q?Fv0QDe3VKxKMUFsmfatZYuvTUCZW+BsrjNrJfNxO05+Nq+BWzr9syvPDLcyb?= =?us-ascii?Q?DxWWSYWD7RD7s3u9XRIqh64zYpixqk6l8F2DKvW2zHB89NNc2SBmNyi/tUj8?= =?us-ascii?Q?NCpwjzktIlgmMxtAdCYMaoUhYlSaZWBtqB8iZ+OXfSVqzQbzbfyghlL7tKMT?= =?us-ascii?Q?p42xTWyWG/wnazwsM4qrmaQq1XO8EcqSVF0Zg4QWoFxDr0SDtgACT6j7o7UN?= =?us-ascii?Q?ov+So5dXVwuFqbJtYN1+KPaKN6/m2/Cvn/BhiEMDtW1oDGR7VBqKeyqJe0X9?= =?us-ascii?Q?62coitAlcyDF+k/4NlkujjSEZkJiI+kt6vb0PSdsG64AXyqFTkk2vjI4lKzu?= =?us-ascii?Q?7Qv2xUHquYn86Gu3Cy2SCTMLuMDCKQg8rSUgF1M0ZikXi+eIvXVPWUHpQogD?= =?us-ascii?Q?5ooKIcTkEao0ESb7idLF71RwJNoF9HXvI69C8bS3AGRmKSfJidHl7ja2aXHY?= =?us-ascii?Q?3raBWHPwGLG9gQGS7RnhR1BCy2zI0asHnQ2YJ0L6YKU6a6yAvczd79ZR0nxV?= =?us-ascii?Q?bAPtvuq6Z4JrZNBPfyiPHIO+yLmBV0Y5lyMGM+Ahlzglu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vGvtywUKP1dkHt4TLevBzcfbhh6ewzjMnMGtN2FuCCmSfYPp8WXJBRGGB9rO5hpKLk+aGhGqMJv4GRjpGjQzbcxhCPcQmy4f3Qw==;24:xI994wgtDcfkVWEueqQGDA9L3smbSsbW3W0ghSP7KkQgz8PKkMtZpb+/MjBSBisJBb50KfL9s2kvMseROfiriZe//+s9XHnZB6d1ahfmHKU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;VI1PR0201MB2317;7:QvTRxSJQa1eW2g6CeZC+VuTGkJ5H45BymJ7ixNVqrqvsOvZIj6u1puOVO9F8pRWO98EROn4HAgtOxQPRuzi52sudnqOYDTSvOgJj4iRUowJVGBvuxr6QAF7tAlNPm6qhd/umFUHx13z7/mI62iA+Z3QqshLzjJ/LsMv4/3AJHk4UNrwrW/McvLJuwSUmAAqNxsmQJJVZ3vfGuyyQbuXR9Q1P8YwEmigJyNS58kdspKlfWKMBysMr7E/5Xj9zs661AbsLPyJqSGXzl0JroyFR+vlx6bkcosXqOIX1m7AweGqdDyDwwFiTAodkvqO4va3MHsa7AlTwRhCndEFFXM7n0LNh78KLEw39MwetD3+dUY4= X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2016 22:44:34.2136 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0201MB2317 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 7204 Lines: 163 Signed-off-by: Peter Rosin --- drivers/iio/potentiometer/mcp4531.c | 104 +++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 42 deletions(-) diff --git a/drivers/iio/potentiometer/mcp4531.c b/drivers/iio/potentiometer/mcp4531.c index 13b6ae2fcf7b..0d1bcf89ae17 100644 --- a/drivers/iio/potentiometer/mcp4531.c +++ b/drivers/iio/potentiometer/mcp4531.c @@ -38,7 +38,7 @@ struct mcp4531_cfg { int wipers; - int max_pos; + int avail[3]; int kohms; }; @@ -78,38 +78,38 @@ enum mcp4531_type { }; static const struct mcp4531_cfg mcp4531_cfg[] = { - [MCP453x_502] = { .wipers = 1, .max_pos = 128, .kohms = 5, }, - [MCP453x_103] = { .wipers = 1, .max_pos = 128, .kohms = 10, }, - [MCP453x_503] = { .wipers = 1, .max_pos = 128, .kohms = 50, }, - [MCP453x_104] = { .wipers = 1, .max_pos = 128, .kohms = 100, }, - [MCP454x_502] = { .wipers = 1, .max_pos = 128, .kohms = 5, }, - [MCP454x_103] = { .wipers = 1, .max_pos = 128, .kohms = 10, }, - [MCP454x_503] = { .wipers = 1, .max_pos = 128, .kohms = 50, }, - [MCP454x_104] = { .wipers = 1, .max_pos = 128, .kohms = 100, }, - [MCP455x_502] = { .wipers = 1, .max_pos = 256, .kohms = 5, }, - [MCP455x_103] = { .wipers = 1, .max_pos = 256, .kohms = 10, }, - [MCP455x_503] = { .wipers = 1, .max_pos = 256, .kohms = 50, }, - [MCP455x_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, }, - [MCP456x_502] = { .wipers = 1, .max_pos = 256, .kohms = 5, }, - [MCP456x_103] = { .wipers = 1, .max_pos = 256, .kohms = 10, }, - [MCP456x_503] = { .wipers = 1, .max_pos = 256, .kohms = 50, }, - [MCP456x_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, }, - [MCP463x_502] = { .wipers = 2, .max_pos = 128, .kohms = 5, }, - [MCP463x_103] = { .wipers = 2, .max_pos = 128, .kohms = 10, }, - [MCP463x_503] = { .wipers = 2, .max_pos = 128, .kohms = 50, }, - [MCP463x_104] = { .wipers = 2, .max_pos = 128, .kohms = 100, }, - [MCP464x_502] = { .wipers = 2, .max_pos = 128, .kohms = 5, }, - [MCP464x_103] = { .wipers = 2, .max_pos = 128, .kohms = 10, }, - [MCP464x_503] = { .wipers = 2, .max_pos = 128, .kohms = 50, }, - [MCP464x_104] = { .wipers = 2, .max_pos = 128, .kohms = 100, }, - [MCP465x_502] = { .wipers = 2, .max_pos = 256, .kohms = 5, }, - [MCP465x_103] = { .wipers = 2, .max_pos = 256, .kohms = 10, }, - [MCP465x_503] = { .wipers = 2, .max_pos = 256, .kohms = 50, }, - [MCP465x_104] = { .wipers = 2, .max_pos = 256, .kohms = 100, }, - [MCP466x_502] = { .wipers = 2, .max_pos = 256, .kohms = 5, }, - [MCP466x_103] = { .wipers = 2, .max_pos = 256, .kohms = 10, }, - [MCP466x_503] = { .wipers = 2, .max_pos = 256, .kohms = 50, }, - [MCP466x_104] = { .wipers = 2, .max_pos = 256, .kohms = 100, }, + [MCP453x_502] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms = 5, }, + [MCP453x_103] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms = 10, }, + [MCP453x_503] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms = 50, }, + [MCP453x_104] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms = 100, }, + [MCP454x_502] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms = 5, }, + [MCP454x_103] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms = 10, }, + [MCP454x_503] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms = 50, }, + [MCP454x_104] = { .wipers = 1, .avail = { 0, 1, 128 }, .kohms = 100, }, + [MCP455x_502] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms = 5, }, + [MCP455x_103] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms = 10, }, + [MCP455x_503] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms = 50, }, + [MCP455x_104] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms = 100, }, + [MCP456x_502] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms = 5, }, + [MCP456x_103] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms = 10, }, + [MCP456x_503] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms = 50, }, + [MCP456x_104] = { .wipers = 1, .avail = { 0, 1, 256 }, .kohms = 100, }, + [MCP463x_502] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms = 5, }, + [MCP463x_103] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms = 10, }, + [MCP463x_503] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms = 50, }, + [MCP463x_104] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms = 100, }, + [MCP464x_502] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms = 5, }, + [MCP464x_103] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms = 10, }, + [MCP464x_503] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms = 50, }, + [MCP464x_104] = { .wipers = 2, .avail = { 0, 1, 128 }, .kohms = 100, }, + [MCP465x_502] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms = 5, }, + [MCP465x_103] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms = 10, }, + [MCP465x_503] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms = 50, }, + [MCP465x_104] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms = 100, }, + [MCP466x_502] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms = 5, }, + [MCP466x_103] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms = 10, }, + [MCP466x_503] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms = 50, }, + [MCP466x_104] = { .wipers = 2, .avail = { 0, 1, 256 }, .kohms = 100, }, }; #define MCP4531_WRITE (0 << 2) @@ -124,13 +124,14 @@ struct mcp4531_data { const struct mcp4531_cfg *cfg; }; -#define MCP4531_CHANNEL(ch) { \ - .type = IIO_RESISTANCE, \ - .indexed = 1, \ - .output = 1, \ - .channel = (ch), \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ +#define MCP4531_CHANNEL(ch) { \ + .type = IIO_RESISTANCE, \ + .indexed = 1, \ + .output = 1, \ + .channel = (ch), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_RAW), \ } static const struct iio_chan_spec mcp4531_channels[] = { @@ -156,13 +157,31 @@ static int mcp4531_read_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: *val = 1000 * data->cfg->kohms; - *val2 = data->cfg->max_pos; + *val2 = data->cfg->avail[2]; return IIO_VAL_FRACTIONAL; } return -EINVAL; } +static int mcp4531_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) +{ + struct mcp4531_data *data = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + *length = ARRAY_SIZE(data->cfg->avail); + *vals = data->cfg->avail; + *type = IIO_VAL_INT; + return IIO_AVAIL_RANGE; + } + + return -EINVAL; +} + static int mcp4531_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) @@ -172,7 +191,7 @@ static int mcp4531_write_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - if (val > data->cfg->max_pos || val < 0) + if (val > data->cfg->avail[2] || val < 0) return -EINVAL; break; default: @@ -186,6 +205,7 @@ static int mcp4531_write_raw(struct iio_dev *indio_dev, static const struct iio_info mcp4531_info = { .read_raw = mcp4531_read_raw, + .read_avail = mcp4531_read_avail, .write_raw = mcp4531_write_raw, .driver_module = THIS_MODULE, }; -- 2.1.4