Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756125AbdCWOog (ORCPT ); Thu, 23 Mar 2017 10:44:36 -0400 Received: from mail-by2nam01on0046.outbound.protection.outlook.com ([104.47.34.46]:52448 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755894AbdCWOoc (ORCPT ); Thu, 23 Mar 2017 10:44:32 -0400 Authentication-Results: spf=pass (sender IP is 137.71.25.57) smtp.mailfrom=analog.com; metafoo.de; dkim=none (message not signed) header.d=none;metafoo.de; dmarc=bestguesspass action=none header.from=analog.com; Reply-To: Subject: Re: [PATCH] iio/adc/ltc2497: Driver for Linear Technology LTC2497 ADC References: <1490265310-6162-1-git-send-email-michael.hennerich@analog.com> To: Peter Meerwald-Stadler CC: , , , , , , , From: Michael Hennerich Organization: Analog Devices Inc. Message-ID: <3e7d3718-e199-b876-94be-526da1ddd9da@analog.com> Date: Thu, 23 Mar 2017 15:45:40 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:137.71.25.57;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(39450400003)(39860400002)(39410400002)(39850400002)(39840400002)(2980300002)(438002)(199003)(189002)(24454002)(51914003)(4326008)(8936002)(6306002)(54906002)(83506001)(38730400002)(6246003)(2870700001)(106466001)(7636002)(65956001)(33646002)(23746002)(4001350100001)(43066003)(8676002)(305945005)(2906002)(31696002)(86362001)(1720100001)(50986999)(47776003)(54356999)(2950100002)(6666003)(229853002)(76176999)(3450700001)(356003)(36756003)(31686004)(8666007)(110136004)(966004)(189998001)(6916009)(53546009)(5660300001)(50466002)(77096006)(562404015);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR03MB2950;H:nwd2mta2.analog.com;FPR:;SPF:Pass;MLV:sfv;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD022;1:pHJwKPt8H0ezrrVYJkvGdAsjO5UqOo6bUPcDoSmwAjTYjSqP6GClSyCfvLut+ugmyACjM1hNdYSfAvIGWtzGNmpWkASur2h3t2gp1HzBkaN2InaZThe6kxkX7WcIyaHh7JSSk4j3ltWeSPsJ0gIKv/WIraSoRJcxDmSbK6XqEg2/1Xa0NThJ6rWHJ5WPc8rGqzYkO/7S68J9UhaUyQ7LJaDug8E+pOezkYLw+IONokA6YX6q4D8W87Nx9ahWVkGsyEwdVA7IxWeo4ZssW48HD32wZ1AAQ1E/eF4XK9ULyk8jJb1x7X3Lx8kpMAUw3ECox/zFA0om2WbwQssDgbqEEJVnfmKRdb5SdvxMW66znyja4m5RK2gLABAT4Rb+uyibqaqLO5w2SK4GxJCetzBhCaBUBw0QZyGYlHgwJqdcd2dh0sVgUq9sFwz+wE6NoAZT7C6zKlv5PYOsXq/f/Z6yaXXWHxH01RCDV+G33Db3xdPBZt3JNMx1cIV8Oecw71CuMetPFK997cnT+yqCF+ecfLexi31DpdkswK6GnV0ajuwcbiROwEMPwjA/N3d3yRS1tIWQoUvW4WxxjsTV3dXu61CzcGR+1Be9kFIqglSdyvioT2Bv6D+uzVnaVfzts2IG X-MS-Office365-Filtering-Correlation-Id: de24805b-444a-4881-dd4d-08d471fb187d X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(8251501002)(2017030254075);SRVR:CY4PR03MB2950; X-Microsoft-Exchange-Diagnostics: 1;CY4PR03MB2950;3:bl5FLpIvL4H/Ss7qWGWcWrTtiKNKckIuAR8RwG9bSuzg/k9cKCUQw0CpkRtRyp33xyGmff18iDhy2ZF0BbHMwGOP9NbtYoL5tdShjQ7h5KhRNmL/TUxEZqLjBHvZ9QC8bfO5a9QgFP04UlJHIQjFZm8IYtVNTM+myZrLTHkwsCyF/4ySxpPedViKjZ9s6n9zxJxnRd3aEs4CPBdCSQXaBh3aoK/d2Je1bgyTJRC4YSU1FUe4USIN2n5seNHg5dtHw7h2lVro69KsnS9jcKVp749Fj4J22Sx4qcrVI8+sEPooii8O2gt1hop+DyzAvDSlTKq9Zd0DHIciT6qHnWvGYRtMc03gmKk5EMM4NxSadDg0X0QvKPSWUCK/PMK0mAxZk0ClmiTmrGXrtqSXGYrM2E5p4CmFgWEQ5pHEzk3st9M=;25:B5Qgy6SF9r9rw+Tk5wgO5uIqWOzAXH4sUgTMfW+f0AESyPKDbosNxKbh24o7l5clZQwALzBI9ZYYbNc455OmHca6tA6FZ7kqsJLGDlR+byvbgPJpm2MRjvFglHfJYLcLdACT6JFHi7HajR3Rak1Uor7VGIYYhd/Ub8c7y+PnYynGtsgQvFEGPY6P6C7BlXh+kWghV8KyaBZbN6Chxbk6pgrsqEmzN+2CxPsK4YgIMTYex0xzZSV3P+3EJa79V4aoQ5b9LtLMVlA4tFhV2uWxILvRwGAcbI6DvoTNQl128jPByPgr2Z0BBF67/8IYYJQyk8QnXM5HuPkyfLMKmYxBaeMr9AG8Adq3mGlH9H7AYAMtSkW/OexsLZdNxVQ9CDXAi6oJ7jrKW1BXZbIwUj38A36ZiGnkBgWmiyfkR2KhHIqdiG8Eaw7FKYkVkPxGdAHB7UpAnpJiMh1I4LbqgXHowA== X-Microsoft-Exchange-Diagnostics: 1;CY4PR03MB2950;31:FIYmy1dzPBXb+MSW/R12M64Y8mV44vkxtVhLI6eRziGh8mLJ96IU0OrlxB6gY2t6ulFDt59qbYY7RYAopbnTukeXKZse28jUHOE91VGE5rjYHQpLspTcwXUBeFeMcrxf73r9tyZUTbCQwpYOYUYhWeoi9WLkA6ZHq3lcHlPlPgm+YscRt/3WUc7R/2rgcTtqVu2CcKv7zSdrhK3lXlcpPFPYpB4Et9gm55N9KEeYkBR9vCdWoSRcn3f0JXyUKMglRqh+Z+HwfujpYQcoyeIQ6w==;20:J17L/oc4z8dgSRdHybGZPkU+0hO/mtMRKVsU8pbNdwKU52xuUocO7s5xrIMPAvYMwwlIc1KAzsIANPhMwdpjFm1IyVFmoW2s1xkIu+Pc6tvrOW5BdmBlJBiEZfUq8B73PUe50Sy/CaiqucuaRP+t5PZM07/BDG6QoagDJ80F75ZNf87Z8M5g5Gnm8Z2OwWAppr1bsO9UsmQv78XLWcXEP3ahaLDRhjCoaPyYadtvSa+SkmdGpxDdiBzVijCNgJTNYKYLrJuxfCUxw7b/Q4Eh0eIZGFK2utD4rmR+P0vgDO8dp2qaRRjMq7VXa0ZTPYYnztem3dZAV4EIgkaSSClVCLxfZDR0V+24UJq0QsaX0R09GjG5bcuq/euYmdxgUwW+xrvCNxEoeY4b5WfDUlB0YKTpNorMs6NoC3lp2ApV02LNUHYke+n4O010ZzB3vU0+Gq+19BxI76MHZYrOJyCp2orAJ57HdeiJI1hjjNV5rxG97eXBZz2QZZOdNVaerPsx X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(232431446821674)(170811661138872); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(5005006)(13015025)(13018025)(13024025)(13017025)(13023025)(8121501046)(3002001)(10201501046)(6055026)(6041248)(20161123558025)(20161123564025)(20161123562025)(20161123560025)(20161123555025)(6072148);SRVR:CY4PR03MB2950;BCL:0;PCL:0;RULEID:;SRVR:CY4PR03MB2950; X-Microsoft-Exchange-Diagnostics: 1;CY4PR03MB2950;4:Ypo8O8IQMwzT1EopAv4HEzLe6K7mrlGuVKrHY43othQw08F9oh0cYIMT0Ald8G/Nd7Bzvn4AhYeBRaW5Yf+n+ZfzsBX5J5zMuRf3V4A0JTwvprtxqSlmaBeKHo5hfoFAy1hDYzM3TSOxo3U5DgmaaqS7wb9Qano9vyrME7hCKhmSIOXLHnPdX+OewHkuNJmCsQfYqmdyGlojW1S6ZqHAhx6YJBfnugs0LhGpZ7TvGdZbIlinyGhGOLMeQh4QDhWbT+iUcaGG4U9AKvDCOaK7JZsWXK6eAS28SI0nqAi/QgTgFQbiUCvztaAvYjdGh8qUN8I1gjGUGw26EXCYxcFr8inl8tsgJhmSlO/dwJPl78vV+Ekgkif40HAk0Xe3Rxb0IKCwJS5JPGqF94egBVyt84QC4vJW1o75Gnn8zn88a9MyWto2kZ/hv5jceZgmsVX0JdlTWpQxVsV+P2j6nQnhEPzIpitRHXr/YDJCOkfV2VR2IC0F5Vj6WP/6Xzv4wYetPrHWamebFTJiZFjVXC6MHRuJT06sl3NbUbtrcVmdZFlPHXeuQV+vtHgGVkfHOf5Adj5BuIKFwuwhKtXeDTdlp8OR5MTx4wWn+G2AaRVm4YDVFQ5gRq8i7zo+cNBTfEx51elW1AnNkbpw1isLEkTF5mUgWj+gFeJFrGiHFJpdtCRfTH8Qtz1gEykgUfkwSSrgxlIH6QMITo7ECAoQSARDRPPiXxciP0X68ugzuk0vR1LIucEPbrAgN5bjsacJNIgOaAk/ZdN8hcpjrkwO5WAF9w0p7CSpmiqoBPEMm1Vdf8Q= X-Forefront-PRVS: 0255DF69B9 X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;CY4PR03MB2950;23:wHyHKiyK20sZDtyspmmPprVFK76bw26O1GMSB?= =?Windows-1252?Q?lfYCgEvuL/dqEV10uc1Dk8XIgmxntIErJtHFHTDn+9ez0nnbudNWUKAq?= =?Windows-1252?Q?msqu+x0/D3Q1fhd46muEP1Rgg49Ae1F863rN3/YPQeIfi6FN0iA/OkX/?= =?Windows-1252?Q?sqGpTkitFuQpWUzPzek3U1J73/B9y9YaPysls7HgCoZ4TImPWLJlK4hn?= =?Windows-1252?Q?mmXLRKk42ojopWikcznoKYBDpRjXkYmO8x1e8kXhevh7ZrZyMilODZVA?= =?Windows-1252?Q?Ca7s/Y2gMEfJs5Z+5KUUtj1dl4/fotXHcc96FC2RcDurVmRGOZsJjcrV?= =?Windows-1252?Q?cqRIFnsgl03CZLBv9nj499muTS8OeJFMeoHA0MgmvZTYyRmwHpuAbXgY?= =?Windows-1252?Q?KUnNK0JD0fpUYgvF6HHTGUWK7SSqLxVpyrCXPJX05wPktTzUn1He5ByA?= =?Windows-1252?Q?qup/nZiCSvsrKMoflDt5gGTzdAeHoLHb2vHK1mIQLHgKNqvUhRv4yHm0?= =?Windows-1252?Q?+CsVF+THXBFon6cQx6qDKvG2eR8tMCGJ8rqEEOcJmotHdZfCKE0xdOuM?= =?Windows-1252?Q?aoJUSSbbcMzEKwi2uG0Q8PkMeBXP1Gvcj2oAyaZE8VMvFOIcl9C6gv5E?= =?Windows-1252?Q?50hRScYX3FZSWFBForCfm0HJ5a+SG4Y3yCldwENx6oPct5B93CCgLa8h?= =?Windows-1252?Q?5r9sH051CgQKutChM/Z55/GePdU/mlM6VNwh53gJ6bX4xxIYIdpTI1gc?= =?Windows-1252?Q?Jkvqz9Enq7i/dpN2wTtkFRd27taGMu4AnOyNO1Cyi6a3aluVh0563hAP?= =?Windows-1252?Q?1I8Y8wxgzG0uwSyzgDgPLn+xGQ87VOWGsh9CTCpOVWkAEzgEODtRaW/Q?= =?Windows-1252?Q?Xc3/EBZ4Z27jpX3VA1xyFmtRjJ3cbA9bod9oZRHZabfAwaDnsR4YJMAq?= =?Windows-1252?Q?cw3/S8tXGsvNZ0/Mw6fDZ6hNN+GKW9J7XCzkNyys5+xG2Ay/mZ3O6KSd?= =?Windows-1252?Q?nT3egqRbkQduKle+PfdC1wPadO2wssXCqh9KLtt3tkHCu8/zap/h63du?= =?Windows-1252?Q?eXpxxtLJNFysxF1qd4DnQ3PSokIVvilXgDjxOap0rVuwVFOKfLu5fDSh?= =?Windows-1252?Q?JfBpi1Pts5HPlL/R6INa96dqkI7wXpW5Gx453U/5Qh+zp/W+c/MTcOUB?= =?Windows-1252?Q?FEFt1lOXx93M7quBjuFOp3XAwW/Qsb62LWy+P/te3SnG8GIt9KCMDrEz?= =?Windows-1252?Q?cSbr6kgqLE4CpIpsr/sSMoHGPOMtNR3kkVxa7VMUn9eapJi8iWp3tJQB?= =?Windows-1252?Q?bJGLzNYzpwRCToBlQYgsFVV5b6sdu6xAn2Ba9rOGsCaoxSsS0Nab7r/3?= =?Windows-1252?Q?mOURXt56WPJJPtRbyVK98DSmUNsbJUod7g8PDurcsdvWAfFI6LF0dg?= =?Windows-1252?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1;CY4PR03MB2950;6:V4eD1CpxTmdJePi3bG1+07RuKW27oX8pl1sP1QKlAxHId2Zddyuwbjo47aseGymuuNAf6GaX1ATxb3HTBCuPnyVLwUtIag/kd7caOTNuaoVv92rewaAzaA8p9fh06FgvXnVixuVfWIwIWHIMX7w9Eclici+9iQkmjIZ8DOzjkwN2GbI0+iGplpDfBjEBxLXzqxajHkDY8u3sc3qDPL59xd29untzrEbPewWPM+U7CwYDhgziX/DRXd03tiYVsa9BTxwTKXxYKndOANdMhWl5FEmntPEKo4WBkWKrBSPc9a5T9KCRXAvj6zn2ovoeMhvsjTaVH2dyuVhLd7qpNyItMD1AgZuCKCCIk6Xz5TuT3hF6D1iRQB5jznFXABFkVqVj80+CgXBUOoYndLyPGLkPcSr/u3DSSm4jw6HoiSZZTPU=;5:T49mMxOhWUcf8tzcNfKopbkwXDxgHihhetEpPTYVZRu7SPkEtATJa+Ymj3G5BOBylU4DkqOI6AIqod+1zvziYrBN21aMM0g1/81nOILCw/mMwyju3YPup2k/OnNG1zcWfSC//nRdlznjsg1to4FXaA==;24:A90xkDHtSKrZPMWxgY4QyC7+rWGKR4tPiFRGORGQqj5Us/aP3CxUtStEFn1GOhQwChrUpNMKSZGYKxDLhcYZvhHtUBqdVvlEbq/kQLh9LUc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY4PR03MB2950;7:aCU9BGoz6UY6rusLtOnoaopDpFCB+8nYjjU0W48qM/vhqqqjN0excxiNglDQdz+o/0YjWVWlRCLD+9x4eBAMrV83q5mlCcCtDa/FyPE63WLy0jxPd19mfIlLgLy/Tjhq++zFQKqOi3DG0Ag+ViE1Xk6XWwuhCg5bxF0Rl7s+/LHx9JVA6YDDb0Kz6rE5oB9aYvJnv+Nl2NOxOSdb+a1bcNOCCmNV6mWxuzA9fvEg87OojLmbANACBLt1Q7D1VT18tXygPu+HBW/IYjGNjmxsxVzr2qU8mLBvdp4B5MGCzTDndy34SufnhJTtQcnaGnImAyaNzvcbmsikLkFXxRW8NQ== X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2017 14:44:22.4438 (UTC) X-MS-Exchange-CrossTenant-Id: eaa689b4-8f87-40e0-9c6f-7228de4d754a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=eaa689b4-8f87-40e0-9c6f-7228de4d754a;Ip=[137.71.25.57];Helo=[nwd2mta2.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR03MB2950 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 11823 Lines: 402 On 23.03.2017 12:28, Peter Meerwald-Stadler wrote: > On Thu, 23 Mar 2017, michael.hennerich@analog.com wrote: > >> From: Michael Hennerich > > comments below Hi Peter, Thanks for the review - comments inline. > >> Signed-off-by: Michael Hennerich >> --- >> .../devicetree/bindings/iio/adc/ltc2497.txt | 13 + >> MAINTAINERS | 1 + >> drivers/iio/adc/Kconfig | 11 + >> drivers/iio/adc/Makefile | 1 + >> drivers/iio/adc/ltc2497.c | 263 +++++++++++++++++++++ >> 5 files changed, 289 insertions(+) >> create mode 100644 Documentation/devicetree/bindings/iio/adc/ltc2497.txt >> create mode 100644 drivers/iio/adc/ltc2497.c >> >> diff --git a/Documentation/devicetree/bindings/iio/adc/ltc2497.txt b/Documentation/devicetree/bindings/iio/adc/ltc2497.txt >> new file mode 100644 >> index 0000000..c2829c19 >> --- /dev/null >> +++ b/Documentation/devicetree/bindings/iio/adc/ltc2497.txt >> @@ -0,0 +1,13 @@ >> +* Linear Technology / Analog Devices LTC2497 ADC >> + >> +Required properties: >> + - compatible: Should be "lltc,ltc2497" >> + - reg: Should contain the ADC I2C address >> + - vref-supply: The regulator supply for ADC reference voltage >> + >> +Example: >> + ltc2497: adc@76 { >> + compatible = "lltc,ltc2497"; >> + reg = <0x76>; >> + vref-supply = <<c2497_reg>; >> + }; >> diff --git a/MAINTAINERS b/MAINTAINERS >> index a7d6f9a..173043c 100644 >> --- a/MAINTAINERS >> +++ b/MAINTAINERS >> @@ -813,6 +813,7 @@ W: http://wiki.analog.com/ >> W: http://ez.analog.com/community/linux-device-drivers >> S: Supported >> F: drivers/iio/*/ad* >> +F: drivers/iio/adc/ltc2497* >> X: drivers/iio/*/adjd* >> F: drivers/staging/iio/*/ad* >> F: drivers/staging/iio/trigger/iio-trig-bfin-timer.c >> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig >> index 2268a6f..141cf4a 100644 >> --- a/drivers/iio/adc/Kconfig >> +++ b/drivers/iio/adc/Kconfig >> @@ -326,6 +326,17 @@ config LTC2485 >> To compile this driver as a module, choose M here: the module will be >> called ltc2485. >> >> +config LTC2497 >> + tristate "Linear Technology LTC2497 ADC driver" >> + depends on I2C >> + help >> + Say yes here to build support for Linear Technology LTC2497 >> + 16-Bit 8-/16-Channel Delta Sigma ADC. >> + Provides direct access via sysfs > > the line "Provides..." should be removed I think, it confuses me at least Sure I can remove - originally added to make checkpatch happy. > >> + >> + To compile this driver as a module, choose M here: the module will be >> + called ltc2497. >> + >> config MAX1027 >> tristate "Maxim max1027 ADC driver" >> depends on SPI >> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile >> index 73dbe39..9d626b5 100644 >> --- a/drivers/iio/adc/Makefile >> +++ b/drivers/iio/adc/Makefile >> @@ -32,6 +32,7 @@ obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o >> obj-$(CONFIG_LPC18XX_ADC) += lpc18xx_adc.o >> obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o >> obj-$(CONFIG_LTC2485) += ltc2485.o >> +obj-$(CONFIG_LTC2497) += ltc2497.o >> obj-$(CONFIG_MAX1027) += max1027.o >> obj-$(CONFIG_MAX11100) += max11100.o >> obj-$(CONFIG_MAX1363) += max1363.o >> diff --git a/drivers/iio/adc/ltc2497.c b/drivers/iio/adc/ltc2497.c >> new file mode 100644 >> index 0000000..0452715 >> --- /dev/null >> +++ b/drivers/iio/adc/ltc2497.c >> @@ -0,0 +1,263 @@ >> +/* >> + * ltc2497.c - Driver for Linear Technology LTC2497 ADC >> + * >> + * Copyright (C) 2017 Analog Devices Inc. >> + * >> + * Licensed under the GPL-2. >> + * >> + * Datasheet: http://cds.linear.com/docs/en/datasheet/2497fd.pdf >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +#include >> +#include >> + >> +#define LTC2497_ENABLE 0xA0 >> +#define LTC2497_SGL (1 << 4) >> +#define LTC2497_DIFF (0 << 4) >> +#define LTC2497_SIGN (1 << 3) >> +#define LTC2497_CONFIG_DEFAULT LTC2497_ENABLE >> +#define LTC2497_CONVERSION_TIME_MS 150ULL > > is the ULL really needed? Needed? - maybe not - but probably not wrong ktime_ms_delta() returns 64bit and we later do some comparisons... > >> +struct ltc2497_st { >> + struct i2c_client *client; >> + struct regulator *ref; >> + ktime_t time_prev; >> + u8 addr_prev; >> +}; >> + >> +static int ltc2497_wait_conv(struct ltc2497_st *st) >> +{ >> + s64 time_elapsed; >> + >> + time_elapsed = ktime_ms_delta(ktime_get(), st->time_prev); >> + >> + if (time_elapsed < LTC2497_CONVERSION_TIME_MS) { >> + /* delay if conversion time not passed >> + * since last read or write >> + */ >> + msleep(LTC2497_CONVERSION_TIME_MS - time_elapsed); >> + return 0; >> + } >> + >> + if (time_elapsed - LTC2497_CONVERSION_TIME_MS <= 0) { >> + /* We're in automatic mode - >> + * so the last reading is stil not outdated >> + */ >> + return 0; >> + } >> + >> + return -ETIMEDOUT; >> +} >> + >> +static int ltc2497_read(struct ltc2497_st *st, u8 address, int *val) >> +{ >> + struct i2c_client *client = st->client; >> + __be32 buf = 0; >> + int ret; >> + >> + ret = ltc2497_wait_conv(st); >> + if (ret < 0 || st->addr_prev != address) { >> + ret = i2c_smbus_write_byte(st->client, 0xA0 | address); > > use LTC2497_ENABLE instead of 0xa0 good catch. > >> + if (ret < 0) >> + return ret; >> + st->addr_prev = address; >> + msleep(LTC2497_CONVERSION_TIME_MS); >> + } >> + ret = i2c_master_recv(client, (char *)&buf, 3); >> + if (ret < 0) { >> + dev_err(&client->dev, "i2c_master_recv failed\n"); >> + return ret; >> + } >> + st->time_prev = ktime_get(); >> + *val = (be32_to_cpu(buf) >> 14) - (1 << 17); > > what is the purpose of - (1 << 17)? maybe add a comment? > I'd rather do it with bit operations that arithmetic Well - this is for offset binary to signed conversion. I'll add a comment. > >> + >> + return ret; >> +} >> + >> +static int ltc2497_read_raw(struct iio_dev *indio_dev, >> + struct iio_chan_spec const *chan, >> + int *val, int *val2, long mask) >> +{ >> + struct ltc2497_st *st = iio_priv(indio_dev); >> + int ret; >> + >> + switch (mask) { >> + case IIO_CHAN_INFO_RAW: >> + mutex_lock(&indio_dev->mlock); >> + ret = ltc2497_read(st, chan->address, val); >> + mutex_unlock(&indio_dev->mlock); >> + if (ret < 0) >> + return ret; >> + >> + return IIO_VAL_INT; >> + >> + case IIO_CHAN_INFO_SCALE: >> + ret = regulator_get_voltage(st->ref); >> + if (ret < 0) >> + return ret; >> + >> + *val = ret / 1000; >> + *val2 = 17; >> + >> + return IIO_VAL_FRACTIONAL_LOG2; >> + >> + default: >> + return -EINVAL; >> + } >> +} >> + >> +#define LTC2497_CHAN(_chan, _addr) { \ >> + .type = IIO_VOLTAGE, \ >> + .indexed = 1, \ >> + .channel = (_chan), \ >> + .address = (_addr | (_chan / 2) | ((_chan & 1) ? LTC2497_SIGN : 0)), \ >> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ >> + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ >> +} >> + >> +#define LTC2497_CHAN_DIFF(_chan, _addr) { \ >> + .type = IIO_VOLTAGE, \ >> + .indexed = 1, \ >> + .channel = (_chan) * 2 + ((_addr) & LTC2497_SIGN ? 1 : 0), \ >> + .channel2 = (_chan) * 2 + ((_addr) & LTC2497_SIGN ? 0 : 1),\ >> + .address = (_addr | _chan), \ >> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ >> + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ >> + .differential = 1, \ >> +} >> + >> +static const struct iio_chan_spec ltc2497_channel[] = { >> + LTC2497_CHAN(0, LTC2497_SGL), >> + LTC2497_CHAN(1, LTC2497_SGL), >> + LTC2497_CHAN(2, LTC2497_SGL), >> + LTC2497_CHAN(3, LTC2497_SGL), >> + LTC2497_CHAN(4, LTC2497_SGL), >> + LTC2497_CHAN(5, LTC2497_SGL), >> + LTC2497_CHAN(6, LTC2497_SGL), >> + LTC2497_CHAN(7, LTC2497_SGL), >> + LTC2497_CHAN(8, LTC2497_SGL), >> + LTC2497_CHAN(9, LTC2497_SGL), >> + LTC2497_CHAN(10, LTC2497_SGL), >> + LTC2497_CHAN(11, LTC2497_SGL), >> + LTC2497_CHAN(12, LTC2497_SGL), >> + LTC2497_CHAN(13, LTC2497_SGL), >> + LTC2497_CHAN(14, LTC2497_SGL), >> + LTC2497_CHAN(15, LTC2497_SGL), >> + LTC2497_CHAN_DIFF(0, LTC2497_DIFF), >> + LTC2497_CHAN_DIFF(1, LTC2497_DIFF), >> + LTC2497_CHAN_DIFF(2, LTC2497_DIFF), >> + LTC2497_CHAN_DIFF(3, LTC2497_DIFF), >> + LTC2497_CHAN_DIFF(4, LTC2497_DIFF), >> + LTC2497_CHAN_DIFF(5, LTC2497_DIFF), >> + LTC2497_CHAN_DIFF(6, LTC2497_DIFF), >> + LTC2497_CHAN_DIFF(7, LTC2497_DIFF), >> + LTC2497_CHAN_DIFF(0, LTC2497_DIFF | LTC2497_SIGN), >> + LTC2497_CHAN_DIFF(1, LTC2497_DIFF | LTC2497_SIGN), >> + LTC2497_CHAN_DIFF(2, LTC2497_DIFF | LTC2497_SIGN), >> + LTC2497_CHAN_DIFF(3, LTC2497_DIFF | LTC2497_SIGN), >> + LTC2497_CHAN_DIFF(4, LTC2497_DIFF | LTC2497_SIGN), >> + LTC2497_CHAN_DIFF(5, LTC2497_DIFF | LTC2497_SIGN), >> + LTC2497_CHAN_DIFF(6, LTC2497_DIFF | LTC2497_SIGN), >> + LTC2497_CHAN_DIFF(7, LTC2497_DIFF | LTC2497_SIGN), >> +}; >> + >> +static const struct iio_info ltc2497_info = { >> + .read_raw = ltc2497_read_raw, >> + .driver_module = THIS_MODULE, >> +}; >> + >> +static int ltc2497_probe(struct i2c_client *client, >> + const struct i2c_device_id *id) >> +{ >> + struct iio_dev *indio_dev; >> + struct ltc2497_st *st; >> + int ret; >> + >> + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | >> + I2C_FUNC_SMBUS_WRITE_BYTE)) >> + return -EOPNOTSUPP; >> + >> + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st)); >> + if (!indio_dev) >> + return -ENOMEM; >> + >> + st = iio_priv(indio_dev); >> + i2c_set_clientdata(client, indio_dev); >> + st->client = client; >> + >> + indio_dev->dev.parent = &client->dev; >> + indio_dev->name = id->name; >> + indio_dev->info = <c2497_info; >> + indio_dev->modes = INDIO_DIRECT_MODE; >> + indio_dev->channels = ltc2497_channel; >> + indio_dev->num_channels = ARRAY_SIZE(ltc2497_channel); >> + >> + st->ref = devm_regulator_get(&client->dev, "vref"); >> + if (IS_ERR(st->ref)) >> + return PTR_ERR(st->ref); >> + >> + ret = regulator_enable(st->ref); >> + if (ret < 0) >> + return ret; >> + >> + ret = i2c_smbus_write_byte(st->client, LTC2497_CONFIG_DEFAULT); >> + if (ret < 0) >> + goto err_regulator_disable; >> + >> + st->addr_prev = LTC2497_CONFIG_DEFAULT; >> + st->time_prev = ktime_get(); >> + >> + ret = devm_iio_device_register(&client->dev, indio_dev); > > no devm_ since we have a non-empty _remove()? ok > >> + if (ret < 0) >> + goto err_regulator_disable; >> + >> + return 0; >> + >> +err_regulator_disable: >> + regulator_disable(st->ref); >> + >> + return ret; >> +} >> + >> +static int ltc2497_remove(struct i2c_client *client) >> +{ >> + struct iio_dev *indio_dev = i2c_get_clientdata(client); >> + struct ltc2497_st *st = iio_priv(indio_dev); >> + >> + regulator_disable(st->ref); >> + >> + return 0; >> +} >> + >> +static const struct i2c_device_id ltc2497_id[] = { >> + { "ltc2497", 0 }, >> + { } >> +}; >> +MODULE_DEVICE_TABLE(i2c, ltc2497_id); >> + >> +static const struct of_device_id ltc2497_of_match[] = { >> + { .compatible = "lltc,ltc2497", }, >> + {}, >> +}; >> +MODULE_DEVICE_TABLE(of, ltc2497_of_match); >> + >> +static struct i2c_driver ltc2497_driver = { >> + .driver = { >> + .name = "ltc2497", >> + .of_match_table = of_match_ptr(ltc2497_of_match), >> + }, >> + .probe = ltc2497_probe, >> + .remove = ltc2497_remove, >> + .id_table = ltc2497_id, >> +}; >> +module_i2c_driver(ltc2497_driver); >> + >> +MODULE_AUTHOR("Michael Hennerich "); >> +MODULE_DESCRIPTION("Linear Technology LTC2497 ADC driver"); >> +MODULE_LICENSE("GPL v2"); >> > -- Greetings, Michael -- Analog Devices GmbH Otl-Aicher Strasse 60-64 80807 M?nchen Sitz der Gesellschaft M?nchen, Registergericht M?nchen HRB 40368, Gesch?ftsf?hrer: Peter Kolberg, Ali Raza Husain, Eileen Wynne