From patchwork Wed Oct 19 08:21:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4516 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp203169wrs; Wed, 19 Oct 2022 01:42:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ZsPrgwFs+hMexps/nZykw48KnzYCzlHYtJ+nJ/qMHkjKTlXskkcc9XmKdYbtlJH0EEivt X-Received: by 2002:a17:906:ee89:b0:73d:70c5:1a4e with SMTP id wt9-20020a170906ee8900b0073d70c51a4emr5519916ejb.683.1666168945107; Wed, 19 Oct 2022 01:42:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666168945; cv=none; d=google.com; s=arc-20160816; b=jbmNm9uqJuwDWa3JPxbieQeDa/qvkH/bxYa1U9005xKxxG3xfMHuX9mOMkGtutejec +MCm4jfv+f9rMu6InQEFtTJu38WrOD/SbAR9Z1wNDAbRBGuymNn+e7+SAXML4K+y1Re/ 9IrWTH1ycpGKDLMMK00+Ye7844xfo9MpmikCoNL/HNnTIKT0DdA0Wvx1Ruu2YJ3gIAQZ mbH5FLgQ6oBt4RoBQQWoEftLhXkgY4xZTwGbiw6tZz3jeCQXl6lNdZ9yhkdLL3LpAeE3 QAeiP8lUtLcRNTbosVrp9CUbSDhVcoHCh4N3I6UZnA+ALhaxzjBf6y16BYMgA9W7Vxz/ 1xmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jQQ3lBtOkQf+d1Gg3b/h1c8ZppgjH0DXRnlUpyoFj+4=; b=DGjI9BurnBZ9CD0NZ0c3RBfkx9CiQ64U/O1U8BmBFxBBW0/rMzeP73hO6MmIWXhZXR shEzeF/jGqqlkznichjyX2YaJZed3tPshr8xUbDG7WyEndW8bgOh6wcfK+bH58X0emtZ rlId4BHpzWy6TpVKidZuxkdWsOqYqRElYgXTQRdHQsQRiMkMXanU1Kmbg0LKEVc3TcuY fLfnbtc+DJWdp/JzL66v+4uztCzVZ/UkNTV8yLW31CC/uup1HK+FblrhOSs7F6q6RhYU n7zY7ATrHBufeN+I3hmBtHRIl5xfjg4KTG8db6Hc6mCwuSzJulM+k8odh5ejO9CsvddA X86g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HmLaQ8Eq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ji6-20020a170907980600b0073d6ad8251asi14886230ejc.812.2022.10.19.01.42.00; Wed, 19 Oct 2022 01:42:25 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HmLaQ8Eq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230006AbiJSIlb (ORCPT + 99 others); Wed, 19 Oct 2022 04:41:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230311AbiJSIkK (ORCPT ); Wed, 19 Oct 2022 04:40:10 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E76C581123; Wed, 19 Oct 2022 01:39:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 8E1CACE20EC; Wed, 19 Oct 2022 08:38:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 878DEC433C1; Wed, 19 Oct 2022 08:38:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666168698; bh=LKzotlONbnZIXGa7AgoINdc1KVArDb4wRqS7Xv8qXCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HmLaQ8Eqio0Z8ENHP28QCMObKKQHeI3GxsHhRkU8d9T9ybtiYj+K9f5z84QSZgSz2 2Uo76Hx6wlWAlQxD0oRC68lFnIinPMX1cwVocblTlESEatJJS63+eKz6gNiJ6NOL8H QK72+04Mp5EZoV9VddExSm4dfTVJ9+oQaG8+MQVE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 6.0 024/862] iio: dac: ad5593r: Fix i2c read protocol requirements Date: Wed, 19 Oct 2022 10:21:51 +0200 Message-Id: <20221019083251.069031817@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747104767629534579?= X-GMAIL-MSGID: =?utf-8?q?1747104767629534579?= From: Michael Hennerich commit 558a25f903b4af6361b7fbeea08a6446a0745653 upstream. For reliable operation across the full range of supported interface rates, the AD5593R needs a STOP condition between address write, and data read (like show in the datasheet Figure 40) so in turn i2c_smbus_read_word_swapped cannot be used. While at it, a simple helper was added to make the code simpler. Fixes: 56ca9db862bf ("iio: dac: Add support for the AD5592R/AD5593R ADCs/DACs") Signed-off-by: Michael Hennerich Signed-off-by: Nuno Sá Cc: Link: https://lore.kernel.org/r/20220913073413.140475-2-nuno.sa@analog.com Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/dac/ad5593r.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) --- a/drivers/iio/dac/ad5593r.c +++ b/drivers/iio/dac/ad5593r.c @@ -13,6 +13,8 @@ #include #include +#include + #define AD5593R_MODE_CONF (0 << 4) #define AD5593R_MODE_DAC_WRITE (1 << 4) #define AD5593R_MODE_ADC_READBACK (4 << 4) @@ -20,6 +22,24 @@ #define AD5593R_MODE_GPIO_READBACK (6 << 4) #define AD5593R_MODE_REG_READBACK (7 << 4) +static int ad5593r_read_word(struct i2c_client *i2c, u8 reg, u16 *value) +{ + int ret; + u8 buf[2]; + + ret = i2c_smbus_write_byte(i2c, reg); + if (ret < 0) + return ret; + + ret = i2c_master_recv(i2c, buf, sizeof(buf)); + if (ret < 0) + return ret; + + *value = get_unaligned_be16(buf); + + return 0; +} + static int ad5593r_write_dac(struct ad5592r_state *st, unsigned chan, u16 value) { struct i2c_client *i2c = to_i2c_client(st->dev); @@ -38,13 +58,7 @@ static int ad5593r_read_adc(struct ad559 if (val < 0) return (int) val; - val = i2c_smbus_read_word_swapped(i2c, AD5593R_MODE_ADC_READBACK); - if (val < 0) - return (int) val; - - *value = (u16) val; - - return 0; + return ad5593r_read_word(i2c, AD5593R_MODE_ADC_READBACK, value); } static int ad5593r_reg_write(struct ad5592r_state *st, u8 reg, u16 value) @@ -58,25 +72,19 @@ static int ad5593r_reg_write(struct ad55 static int ad5593r_reg_read(struct ad5592r_state *st, u8 reg, u16 *value) { struct i2c_client *i2c = to_i2c_client(st->dev); - s32 val; - - val = i2c_smbus_read_word_swapped(i2c, AD5593R_MODE_REG_READBACK | reg); - if (val < 0) - return (int) val; - *value = (u16) val; - - return 0; + return ad5593r_read_word(i2c, AD5593R_MODE_REG_READBACK | reg, value); } static int ad5593r_gpio_read(struct ad5592r_state *st, u8 *value) { struct i2c_client *i2c = to_i2c_client(st->dev); - s32 val; + u16 val; + int ret; - val = i2c_smbus_read_word_swapped(i2c, AD5593R_MODE_GPIO_READBACK); - if (val < 0) - return (int) val; + ret = ad5593r_read_word(i2c, AD5593R_MODE_GPIO_READBACK, &val); + if (ret) + return ret; *value = (u8) val;