Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6535545rwd; Mon, 5 Jun 2023 20:55:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6QXCXbxJGagUQvWyqCm6E5JlcSPy/Pf6Mz1vPqDzMWRxLtDsRZF3PuXnm/eb2jvnGRawq0 X-Received: by 2002:a05:620a:2626:b0:75e:bb4d:f68d with SMTP id z38-20020a05620a262600b0075ebb4df68dmr774992qko.27.1686023726734; Mon, 05 Jun 2023 20:55:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686023726; cv=none; d=google.com; s=arc-20160816; b=voEvECTIlf2Y9OZnFLWI6YoOC7KFClkcXoONKdyZNA12Quv9eGD6PaNfh3SV0B2wPJ FLlxQBsW3iZ9cUZ+gW+ujo97NhKF6KXd1+G/aU4u06FaW5n2q/zlZ/vWOjQF/Jdz12rr YOhGJDc8rQdQhpPkoWWjYMsm6KAS8TQbJeGFyfQgsoe5/7ZEperNqjzJqH+AsXSmjwnx II9MwAZxgTKq6zvqa/ht4PLXR3mI58yxfXvNCqgMW0bs92YpunVIOx1nLO8GC6GOBWhj TR6EItTK+kAVs0/D/fUcQ/CV6EYGmRHP8wYedqfWoIBN+M1CYxcXRMemKlXlwuDenGMJ 8kdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=2iocNpBeLIV6wHEbLSB1vBFf87kQDART4kSlQhInqYo=; b=bWiSOPJdittMVBf34rVLpeYG2RS7RLmNNenCTxgloQ3slbi3EJ21kAleHACpkLTeGn tZd8pamHKBwm1NQidX1Zl3sego9Nk/ZSGU3g+lVUAhl186g9vTPVFmOTbnw79ZuhBzkA NFPHvG0Scbu4mNVSyU19aHV7z0zGNzgTfGBuBe6ftHw7pF361xBDjnb41PkkhcJz0lz3 m6M1MqoD9EOD6U9fO+nbVvHgAKvZmacpZ1ahzlMrzkNeo1YVJJGA/E3loElMklPdFNFZ 4kYJWtHdsHLbfwQbPiWN2mqXR1g5EY5lBsb/O8ThKi41g9fUCRFVKqpzy6C3bWyqJx7L eK4w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g10-20020a37e20a000000b0075ec53f72cesi1247690qki.481.2023.06.05.20.55.12; Mon, 05 Jun 2023 20:55:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230410AbjFFDkG convert rfc822-to-8bit (ORCPT + 99 others); Mon, 5 Jun 2023 23:40:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233863AbjFFDkD (ORCPT ); Mon, 5 Jun 2023 23:40:03 -0400 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E33CC11D; Mon, 5 Jun 2023 20:40:01 -0700 (PDT) Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3561U8aT025628; Mon, 5 Jun 2023 23:39:46 -0400 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3r02e4eddh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 05 Jun 2023 23:39:45 -0400 Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 3563diac057394 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 5 Jun 2023 23:39:44 -0400 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Mon, 5 Jun 2023 23:39:43 -0400 Received: from ASHBMBX8.ad.analog.com ([fe80::30b9:230c:9621:902f]) by ASHBMBX8.ad.analog.com ([fe80::30b9:230c:9621:902f%9]) with mapi id 15.02.0986.014; Mon, 5 Jun 2023 23:39:43 -0400 From: "Paller, Kim Seer" To: "andy.shevchenko@gmail.com" CC: "jic23@kernel.org" , "lars@metafoo.de" , "krzysztof.kozlowski@linaro.org" , "broonie@kernel.org" , "lgirdwood@gmail.com" , "linux-iio@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH v2 2/2] iio: adc: max14001: New driver Thread-Topic: [PATCH v2 2/2] iio: adc: max14001: New driver Thread-Index: AQHZl67Y+VuDoLqrgE+gZ2yoOVHpUq99NPAA///oTSA= Date: Tue, 6 Jun 2023 03:39:43 +0000 Message-ID: References: <20230605130755.92642-1-kimseer.paller@analog.com> <20230605130755.92642-3-kimseer.paller@analog.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-dg-ref: =?us-ascii?Q?PG1ldGE+PGF0IG5tPSJib2R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FBR0VBWkFCcEFGOEFjd0JsQUdNQWRR?= =?us-ascii?Q?QnlBR1VBWHdCd0FISUFid0JxQUdVQVl3QjBBSE1BWHdCMEFHa0FaUUJ5QURF?= =?us-ascii?Q?QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFB?= =?us-ascii?Q?QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFB?= =?us-ascii?Q?QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFRQUFBQUFBQUFBQ0FB?= =?us-ascii?Q?QUFBQUNlQUFBQVlRQmtBR2tBWHdCekFHVUFZd0IxQUhJQVpRQmZBSEFBY2dC?= =?us-ascii?Q?dkFHb0FaUUJqQUhRQWN3QmZBSFFBYVFCbEFISUFNZ0FBQUFBQUFBQUFBQUFB?= =?us-ascii?Q?QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFB?= =?us-ascii?Q?QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFB?= =?us-ascii?Q?QUFBQUFBQUFBQUFBQUFBQUFCQUFBQUFBQUFBQUlBQUFBQUFBPT0iLz48L21l?= =?us-ascii?Q?dGE+?= x-dg-rorf: true x-originating-ip: [10.116.242.24] x-adiruleop-newscl: Rule Triggered Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: sYOn1QDTncZRPlNhYdXtDSWei8qFZv_G X-Proofpoint-GUID: sYOn1QDTncZRPlNhYdXtDSWei8qFZv_G X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-06_01,2023-06-05_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=999 adultscore=0 impostorscore=0 spamscore=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 clxscore=1011 phishscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2306060032 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > -----Original Message----- > From: andy.shevchenko@gmail.com > Sent: Tuesday, June 6, 2023 8:49 AM > To: Paller, Kim Seer > Cc: jic23@kernel.org; lars@metafoo.de; krzysztof.kozlowski@linaro.org; > broonie@kernel.org; lgirdwood@gmail.com; linux-iio@vger.kernel.org; linux- > kernel@vger.kernel.org > Subject: Re: [PATCH v2 2/2] iio: adc: max14001: New driver > > [External] > > Mon, Jun 05, 2023 at 09:07:55PM +0800, Kim Seer Paller kirjoitti: > > The MAX14001 is configurable, isolated 10-bit ADCs for multi-range > > binary inputs. > > First question, why don't you use regmap SPI? I found it difficult to implement the regmap interface due to the timing diagram requirements. The chip select needs to be changed between transfers, which, as far as I know, does not work with regmap. Additionally, the regmap_config parameters, specifically reg_bits and val_bits, cannot be set to specific values. This limitation makes it challenging to accommodate specific configurations such as using 5 bits for register address and 10 bits for data. > > ... > > > +static int max14001_read(void *context, unsigned int reg_addr, > > + unsigned int *data) > > Strange indentation. > > > +{ > > + struct max14001_state *st = context; > > + u16 tx = 0; > > Redundant assignment. > > > + int ret; > > + > > + struct spi_transfer xfers[] = { > > + { > > + .tx_buf = &st->spi_tx_buffer, > > + .len = 2, > > + .cs_change = 1, > > + }, { > > + .rx_buf = &st->spi_rx_buffer, > > + .len = 2, > > + }, > > + }; > > + > > + tx = FIELD_PREP(MAX14001_ADDR_MASK, reg_addr); > > > + st->spi_tx_buffer = bitrev16(cpu_to_be16(tx)); > > This is strange. Why this monsteur construct with bitrev16() is used? > > According to the datasheet, the bit stream is LE16, where 10 LSB is data, > 5 MSB is address and bit 11 is R/W. I discovered that following the instructions in the application note made the implementation much easier. https://www.analog.com/media/en/technical-documentation/user-guides/guide-to-programming-the-max14001max14002-isolated-adcs--maxim-integrated.pdf To ensure compatibility with the device, I changed the format to big endian and reversed the data before sending it to the device. This is why I used the "bitrev" function. I'm happy to report that this approach worked perfectly. > > > + ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers)); > > + if (ret) > > + return ret; > > > + *data = bitrev16(be16_to_cpu(st->spi_rx_buffer)) & > > +MAX14001_DATA_MASK; > > Ditto. > > > + return 0; > > +} > > > +static int max14001_write(void *context, unsigned int reg_addr, > > + unsigned int data) > > +{ > > + struct max14001_state *st = context; > > + u16 tx = 0; > > Redundant assignment. > > > + tx = FIELD_PREP(MAX14001_ADDR_MASK, reg_addr); > > + tx |= FIELD_PREP(MAX14001_SET_WRITE_BIT, 1); > > + tx |= FIELD_PREP(MAX14001_DATA_MASK, data); > > + > > + st->spi_tx_buffer = bitrev16(cpu_to_be16(tx)); > > + > > + return spi_write(st->spi, &st->spi_tx_buffer, 2); > > sizeof() ? > > > +} > > ... > > > + return dev_err_probe(&spi->dev, PTR_ERR(vref), > > + "Failed to get vref regulator"); > > With > > struct device *dev = &spi->dev; > > this and other calls in this function can be made neater. > > -- > With Best Regards, > Andy Shevchenko >