Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp23239ioo; Wed, 25 May 2022 19:21:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy21ZI+f/S6o28WAbLyPmYPCgJ5sTrc29AraYJP5Ps6kdSwbhEz4rA5vYpTnqUjlT53A4WX X-Received: by 2002:a17:906:4fc4:b0:6da:b4c6:fadb with SMTP id i4-20020a1709064fc400b006dab4c6fadbmr32896456ejw.282.1653531691723; Wed, 25 May 2022 19:21:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653531691; cv=none; d=google.com; s=arc-20160816; b=0yUPhNt3HclqR2Wbkzvz+sBB+durtu6qLlLDTorKo43VpY/7XdtW4N0PcZWSqxFcH/ r4uBIITPxj7iTB8UD8a9GBol9zk4qVajZcob+FY4UrnZsOrTXfv4zrlk2knqAQV3JNpJ KbRG07zyuxGA8woBvdsz3FTFrb/Cs2wukZubyWJhV9nGFoOoEAlzQdOF1K6I8UnMk28K 5lOCr+8g4SizkwCNhN2oS3TMxlQe2QcBjULVLzj5pubpMEyOzI4dNHLeAyWqfhtKU0AX jE8NvfNMp0kgVehoJas2NTRcaLtDulu6znYWHQt5fwA7rztGb/L/O0eIyYbkUr4dI754 xiqA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=5hp0dbekvuABHpYBUEs96KVN5ghBlLRpdsHmk4A4gsY=; b=n++4FzvXa3iy71rK5OX5QAQOGH3aaWQsRqccgEUOZ+QPmkUFYPCzlOVGeLChapLIuh 5VWS6eAZEilXktph2ozc2DYb3zxtSUkUxkR01GMeDw6I4NnJOyBgGaxLhzOtI9+OHdt5 v29zEH60to0ij5zCHQtP+bIb0o2YhKKJqDmBsehL8zbBJ5KMD8g4gDDKoXCOXLY+8gTc islIRRWMZRoOaBAsD9K9CFs2MFleq87C7pgfFPNHAiX/+o6uWJtWGvm6fH20m/y64HLS PiAKx5d2+8xZ3K290zZJksjriWFvEdiyBV7NRgJweIW+FYluD5K5eHufR2z3YLV/sNGS fcXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TwKEsWyv; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y16-20020a056402441000b0042acd8ede70si341386eda.573.2022.05.25.19.20.56; Wed, 25 May 2022 19:21:31 -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=@gmail.com header.s=20210112 header.b=TwKEsWyv; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244629AbiEYOBQ (ORCPT + 99 others); Wed, 25 May 2022 10:01:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244706AbiEYN7d (ORCPT ); Wed, 25 May 2022 09:59:33 -0400 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85941AEE0A; Wed, 25 May 2022 06:58:53 -0700 (PDT) Received: by mail-oi1-x22e.google.com with SMTP id m125so2069831oia.6; Wed, 25 May 2022 06:58:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5hp0dbekvuABHpYBUEs96KVN5ghBlLRpdsHmk4A4gsY=; b=TwKEsWyvpZ5GlzTloFURMTbxmwYufAFPvBfAvNoLWcwZFhoEHowOPFlxE7iFsANSCf P2kkioCKJ6fhEgLydhYgp2Je9alxCdb4kGEREmMhKkPj439cIoyxd+ASO/GwTHYfZHpA KUtnLSPrdk6bpgVm4bM9nUgAfm4DejsOVpibG2Jrt7WPdJIQF5SbsIzy5bSVdWup3gVy jOgVFgcs7IP9qD4qg3BD1f8FdQdbZaMuvRhqr9cF+6H9Z3bRCCHFF3VxAmO/tRj9zQHh Gqej0VZ8qwKXR886642M7jGc4lMbqJVoNA1pnJFQk+eVySCmQiEyhyZXJV9DO0btVecZ NJpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=5hp0dbekvuABHpYBUEs96KVN5ghBlLRpdsHmk4A4gsY=; b=R3d3DZJX8J4t88GVlxJ5t1tZ4roYG2cgjfM+uhqxFK5bS5R4nl0b4j9cMvbPLBp2c2 Ux/TOw5iT3KRrQ239JUpqoweUxurMvkdqE71zR/ONiXme1Q+Dw5XYwnR9TcJvlfiOVUW 6T/sK+74QtM1v+lr2Pm9CRz8tOQTzEfMLsT0Usb19dJXiuBGIYpamNK8W9jYIMy05Bvu +RF2WO4JsjSimC0nyT/JBM/z75YKYwnoFk+ST7DWjq7ZAf8DN8XtL+Z/iLU/4g1WHiEp QCAiNWh9xoXyGb9J+VbrNA+tqNQkpMhtAmafsLMe2tUxCPGFH2+th3X+TVyo7tgJdMkx cyEg== X-Gm-Message-State: AOAM530kBuhHE9UNZ6cWMyhXZeNCgt7EiDRytoPZPjVwHyedd24wYG55 GazBQqK86WLql08oOPcaFao0R40LQTX8qQ== X-Received: by 2002:aca:f1a:0:b0:32a:e909:a490 with SMTP id 26-20020aca0f1a000000b0032ae909a490mr5629095oip.239.1653487132634; Wed, 25 May 2022 06:58:52 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 126-20020a4a0384000000b0035eb4e5a6cdsm6597357ooi.35.2022.05.25.06.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 06:58:52 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Jean Delvare , Slawomir Stepien , Guenter Roeck Subject: [PATCH 27/40] hwmon: (lm90) Introduce 16-bit register write function Date: Wed, 25 May 2022 06:57:45 -0700 Message-Id: <20220525135758.2944744-28-linux@roeck-us.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220525135758.2944744-1-linux@roeck-us.net> References: <20220525135758.2944744-1-linux@roeck-us.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 Introduce 16-bit register write function to simplify the code in some places. Signed-off-by: Guenter Roeck --- drivers/hwmon/lm90.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 20208f127508..46837f0bf62e 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -665,6 +665,21 @@ static int lm90_write_reg(struct i2c_client *client, u8 reg, u8 val) return i2c_smbus_write_byte_data(client, lm90_write_reg_addr(reg), val); } +/* + * Write into 16-bit LM90 register. + * Convert register addresses to write address if needed, then execute the + * operation. + */ +static int lm90_write16(struct i2c_client *client, u8 regh, u8 regl, u16 val) +{ + int ret; + + ret = lm90_write_reg(client, regh, val >> 8); + if (ret < 0 || !regl) + return ret; + return lm90_write_reg(client, regl, val & 0xff); +} + static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, bool is_volatile) { @@ -1240,12 +1255,8 @@ static int lm90_set_temp(struct lm90_data *data, int index, int channel, long va if (channel > 1) lm90_select_remote_channel(data, true); - err = lm90_write_reg(client, regh, data->temp[index] >> 8); - if (err < 0) - goto deselect; - if (regl) - err = lm90_write_reg(client, regl, data->temp[index] & 0xff); -deselect: + err = lm90_write16(client, regh, regl, data->temp[index]); + if (channel > 1) lm90_select_remote_channel(data, false); @@ -1405,14 +1416,8 @@ static int lm90_temp_write(struct device *dev, u32 attr, int channel, long val) val = lm90_temp_to_reg(0, val, lm90_temp_get_resolution(data, REMOTE_OFFSET)); data->temp[REMOTE_OFFSET] = val; - err = i2c_smbus_write_byte_data(data->client, - LM90_REG_REMOTE_OFFSH, - val >> 8); - if (err) - break; - err = i2c_smbus_write_byte_data(data->client, - LM90_REG_REMOTE_OFFSL, - val & 0xff); + err = lm90_write16(data->client, LM90_REG_REMOTE_OFFSH, + LM90_REG_REMOTE_OFFSL, val); break; default: err = -EOPNOTSUPP; -- 2.35.1