From patchwork Mon Oct 24 11:28:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9013 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp441109wru; Mon, 24 Oct 2022 06:05:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5ZLU7gWdL36L8Ec5zCClc+I1xYW0p+Md7WJTQswqRt7ukzwVSaF60Ny4DdbgyxE3X0n12j X-Received: by 2002:a17:902:848c:b0:17a:b4c0:a02b with SMTP id c12-20020a170902848c00b0017ab4c0a02bmr33106197plo.122.1666616722687; Mon, 24 Oct 2022 06:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666616722; cv=none; d=google.com; s=arc-20160816; b=TBPHWjyxLHFh2HS3YviN54+Ahccb221KnAXfFV60OJ6OtJFweiKP6cUXc9yER00WWm mP6rR/8KnTlJpMizLi5uJv9XBRmPovkh2sSnrm0OOvl4/mMu2pngwjwQlDRUi+hA4HYK I6q5vN7fzPlCcuEBO7JGYb6keiAKMIvsRxat74PpaEV7aIYcbn9IZVhivsEsl3TfJMQc qBOnVOSGepbEdwAr0/p+P1ttdmbjuVC0PSUmASUg8apKxl29CE44FhQp9JWHTO/bpTur tOrA6tUEPyD8Nf1f3UqG6J1sYsoRa7FJEuCq2/C9XnxYY83ZszHWOy8k87CB3b75DdRZ zbJA== 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=07mgNwZiYIM+hCP8s0MIpcJ8VTKO61AipDsF1BChDlA=; b=J7cR7PTZuRkAOHRDW4CUUBG423B1QLQzDfTXxLeQPPbo+nc/+CN24fVTLsEAUr6gTT Ec+hWSrlMlFS7AHQcRSfYAoaw0RMvIIRyC2ruTYl5R7z0i06dmFCrBqZe6VmvDtTv4Gk bhBOx3knOG42I1z9WUWyZeEkI/lhCLSlueQcltpEJV/KnsEz56gtB3dL+qL8YAcC3fHa VsqckPsIH5L0HiOKIMvCH48xsixXQ7ZdE3t1fA5qntNNbhPh34CjICo9NoUW+ROfX7hd ElHrFclhA1xhXeqltVUckC2VTT+CVCM0S6EfSZQUett7xSRVFt/sPllvtOxvTUoBCRld 1y1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZTl7kcxq; 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 w14-20020a17090a8a0e00b0020a84ae69b1si7549392pjn.71.2022.10.24.06.04.55; Mon, 24 Oct 2022 06:05:22 -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=ZTl7kcxq; 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 S235233AbiJXNDr (ORCPT + 99 others); Mon, 24 Oct 2022 09:03:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235318AbiJXM74 (ORCPT ); Mon, 24 Oct 2022 08:59:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AA08816A7; Mon, 24 Oct 2022 05:19:17 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 4FCDC612CC; Mon, 24 Oct 2022 12:05:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F02DC433C1; Mon, 24 Oct 2022 12:05:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613108; bh=d2zFU1lQNCR2OxIHoZ43iXVPZ2TmY3D6P0W58UNPdaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZTl7kcxqrlZ+dssaWGOPq9ewW1UedXIkatdUNC9ITP/Y4/97k6889ERBvH5iV6lY9 /MtyaTs62Yf9vT2FfNh6Z3ZhexLetivZQjlKNVpjug2seaLbPxZTkfMQ21v2V4Yub7 a/xG3i0xI8kGG+oFsF0sSL/HpmA9g39cWi+pOs5Q= 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 5.4 012/255] iio: dac: ad5593r: Fix i2c read protocol requirements Date: Mon, 24 Oct 2022 13:28:42 +0200 Message-Id: <20221024113002.852005537@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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?1747574296764956206?= X-GMAIL-MSGID: =?utf-8?q?1747574296764956206?= 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 @@ -14,6 +14,8 @@ #include #include +#include + #define AD5593R_MODE_CONF (0 << 4) #define AD5593R_MODE_DAC_WRITE (1 << 4) #define AD5593R_MODE_ADC_READBACK (4 << 4) @@ -21,6 +23,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); @@ -39,13 +59,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) @@ -59,25 +73,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;