From patchwork Wed Jul 10 01:56:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13728784 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B1A6848E; Wed, 10 Jul 2024 01:56:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720576589; cv=none; b=eqsxTFsVZIdPmiPEv9vMPl3l9fy1Yl6C7Gc3FL1Osd13OXgRREyDu4EGhdUvw6+8erL+9Nw6Ji8s61jPsUNYuJNuukai/E/Lucmaj3T7jlRxJiyOdBMGCJNdBJdnS/XFfzY4mpHYU0LyfKH2hsb4aDLhS5m7GT7POPVbHsvcUoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720576589; c=relaxed/simple; bh=DPQSUvhX4PdWA7X3fADcAWaw1ST7AdomkqkRK1Iy0yc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XrYrVL9tP+dM8MdkZ0r393gJzDRJ82IxMWB3E0X2qwTVKskaiwl+OH7ZJi2W/jO/nQcseXmwW+pObkT7UH+rz42lfJP+t+1RQc/8h1R4KBE02WbIO+VRA8LiuRju8Z+ssY/tw+WiFrjt7SZu8DD2xa7iZJGfGf5nXdf0aSQoTLI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BbGymyEU; arc=none smtp.client-ip=209.85.215.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BbGymyEU" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-710437d0affso3340668a12.3; Tue, 09 Jul 2024 18:56:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720576588; x=1721181388; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=50E7e9XbaKO5ydSbs6JqjTR85kdRi8RGBw5e5A+dUM8=; b=BbGymyEUfgXd1WT2g/gD6S7ZSXppcX6bMxgcHFalFKQb4NbfHixdNcsklz6DAtqmLq 7qbic2/lgjKYouMgnV2OLlapRG9Tf7n9DjPyK7OT3YVQlp7Lx92YME0peNcNk+bnGuKk YhSYDwxzjUTm++wkXmYSI2hB0YiQFGazuL5dFWiQNSYnu+z1Nnia/3toJ6CSPyU5/P4g 4runqKHfNA03/J6FQ4rO8tsilt2HTc0H9bkrh/EVrMcUrEyx8dHK1PsmCO4VshUAIjYq caVkwaAWG7fg3B4GrWTYIYww96TeFrIeLQrs9UEHgI5SPsqJn4+jy8iEQKsMmzwZvp6T XAGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720576588; x=1721181388; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=50E7e9XbaKO5ydSbs6JqjTR85kdRi8RGBw5e5A+dUM8=; b=eHtgXVx+XExKiTWCxk7GVViy0GQlYbdneqm3br3Q9g+PdY2EEGNQZdYJOHVeIvbYGY nKULPDI4LFVL9bMRWmWX6cHAKWyXYuemcpfeWVeHfhk2ylFEbn9M2FPP4y5EF2Z8wrsH YdMWt95wlkHqf5e1Vphx65wEICjUFEocIpBSoiGvHAp4GKKbnm1/QjmKe5bedKYdQOdA PtdZxwoRefU/0cNhOzVsJmRN2JtlsP/7RstQAeE0DR0JTUAj/VKhuP+YWcZhQvuspQ8Z QW3CptwoZwJwFiV2tNf+N1cFLMfnINy637zQDYGa4Qr4GMTv7k4HfiwN4NNuwVE7Y8ji VMrA== X-Forwarded-Encrypted: i=1; AJvYcCX5n6BvcoqbRWTUBFKcntGINf6vOVeiRBJ/LDrlYDwVVFsd8wDJ7pXlXOR3T5G9Aigh3F1s8rEKhSAnoLG96kz46nTFaVhrqLjOrjQv2Bz7ufaT/6qTjw4mkCcK1MPPTeIiHgOZlxsgnlU= X-Gm-Message-State: AOJu0YwZL3RjcC7EqEaq8gF0oIoSqkWjtNxzAVFZbS8vVXqmMxReh9+i x0yJBFjllFP+2sJFLOj20zbgKf4jO+GwlTc4Py4UtjxEMUnOonX3GSiw+A== X-Google-Smtp-Source: AGHT+IEBC9ahW7iL/vncll/jucOxKWPyGm2xZQ8QnkhIwuw4FtjenZMH5/iJ7ygDysNUYtMHWenKeg== X-Received: by 2002:a05:6a20:daa4:b0:1c0:f5af:7967 with SMTP id adf61e73a8af0-1c29822d023mr4664012637.15.1720576587423; Tue, 09 Jul 2024 18:56:27 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ca353cc6cfsm2576310a91.54.2024.07.09.18.56.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jul 2024 18:56:26 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Mark Brown Cc: Greg Kroah-Hartman , "Rafael J . Wysocki" , Jean Delvare , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck Subject: [RFC PATCH 1/3] regmap: Implement regmap_multi_reg_read() Date: Tue, 9 Jul 2024 18:56:20 -0700 Message-Id: <20240710015622.1960522-2-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710015622.1960522-1-linux@roeck-us.net> References: <20240710015622.1960522-1-linux@roeck-us.net> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 regmap_multi_reg_read() is similar to regmap_bilk_read() but reads from an array of non-sequential registers. Signed-off-by: Guenter Roeck --- drivers/base/regmap/regmap.c | 103 +++++++++++++++++++++++------------ include/linux/regmap.h | 2 + 2 files changed, 70 insertions(+), 35 deletions(-) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 0a34dd3c4f38..dff6c515305a 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -3101,8 +3101,53 @@ int regmap_fields_read(struct regmap_field *field, unsigned int id, } EXPORT_SYMBOL_GPL(regmap_fields_read); +static int _regmap_bulk_read(struct regmap *map, unsigned int reg, + unsigned int *regs, void *val, size_t val_count) +{ + u32 *u32 = val; + u16 *u16 = val; + u8 *u8 = val; + int ret, i; + + map->lock(map->lock_arg); + + for (i = 0; i < val_count; i++) { + unsigned int ival; + + if (regs) { + if (!IS_ALIGNED(regs[i], map->reg_stride)) { + ret = -EINVAL; + goto out; + } + ret = _regmap_read(map, regs[i], &ival); + } else { + ret = _regmap_read(map, reg + regmap_get_offset(map, i), &ival); + } + if (ret != 0) + goto out; + + switch (map->format.val_bytes) { + case 4: + u32[i] = ival; + break; + case 2: + u16[i] = ival; + break; + case 1: + u8[i] = ival; + break; + default: + ret = -EINVAL; + goto out; + } + } +out: + map->unlock(map->lock_arg); + return ret; +} + /** - * regmap_bulk_read() - Read multiple registers from the device + * regmap_bulk_read() - Read multiple sequential registers from the device * * @map: Register map to read from * @reg: First register to be read from @@ -3132,47 +3177,35 @@ int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, for (i = 0; i < val_count * val_bytes; i += val_bytes) map->format.parse_inplace(val + i); } else { - u32 *u32 = val; - u16 *u16 = val; - u8 *u8 = val; - - map->lock(map->lock_arg); - - for (i = 0; i < val_count; i++) { - unsigned int ival; - - ret = _regmap_read(map, reg + regmap_get_offset(map, i), - &ival); - if (ret != 0) - goto out; - - switch (map->format.val_bytes) { - case 4: - u32[i] = ival; - break; - case 2: - u16[i] = ival; - break; - case 1: - u8[i] = ival; - break; - default: - ret = -EINVAL; - goto out; - } - } - -out: - map->unlock(map->lock_arg); + ret = _regmap_bulk_read(map, reg, NULL, val, val_count); } - if (!ret) trace_regmap_bulk_read(map, reg, val, val_bytes * val_count); - return ret; } EXPORT_SYMBOL_GPL(regmap_bulk_read); +/** + * regmap_multi_reg_read() - Read multiple non-sequential registers from the device + * + * @map: Register map to read from + * @regs: Array of registers to read from + * @val: Pointer to store read value, in native register size for device + * @val_count: Number of registers to read + * + * A value of zero will be returned on success, a negative errno will + * be returned in error cases. + */ +int regmap_multi_reg_read(struct regmap *map, unsigned int *regs, void *val, + size_t val_count) +{ + if (val_count == 0) + return -EINVAL; + + return _regmap_bulk_read(map, 0, regs, val, val_count); +} +EXPORT_SYMBOL_GPL(regmap_multi_reg_read); + static int _regmap_update_bits(struct regmap *map, unsigned int reg, unsigned int mask, unsigned int val, bool *change, bool force_write) diff --git a/include/linux/regmap.h b/include/linux/regmap.h index a6bc2980a98b..9c1ddbf82719 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -1237,6 +1237,8 @@ int regmap_noinc_read(struct regmap *map, unsigned int reg, void *val, size_t val_len); int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, size_t val_count); +int regmap_multi_reg_read(struct regmap *map, unsigned int *reg, void *val, + size_t val_count); int regmap_update_bits_base(struct regmap *map, unsigned int reg, unsigned int mask, unsigned int val, bool *change, bool async, bool force); From patchwork Wed Jul 10 01:56:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13728785 Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E3FDB647; Wed, 10 Jul 2024 01:56:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720576591; cv=none; b=qXUKNp0eoPS3EMh8K34h5oIyQo7eqHCcGX5oSL+vdE9lWNTPhfHowWBBha/98Ekt0i8DRKfz5D7gNYYmxm7B/eGeGcl6E5XZcKJ+3nX9EpfTkPxpgN0GAox1Ay7D4eHSqc+ccQ6kBFuS9sukL1Wqpwh7uy2sKCOV59a0bzgCjWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720576591; c=relaxed/simple; bh=Y1mdpr9XQdu5XHaFoKoLviUoJjMeQqle7EYcHlrpHkA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=e+NxepdU0F6G+hv+2X9g8VWvAE2j/l1T8nu6Ujb+Un6vOf45dP8gEuTR3M3k+Ro9mnFNUY0fnEGRUJxBkVxI4T7iWKCjGUDSfltLYUNJrsRjaENofIMgkwiavjPBp7aq8zPK/qe8s+LKGjpNxqys+H7yya8mWwgYVIwZj3ir0Ek= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VpDFl7X7; arc=none smtp.client-ip=209.85.167.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VpDFl7X7" Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3d9da46ca13so319644b6e.2; Tue, 09 Jul 2024 18:56:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720576589; x=1721181389; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=YyOWpYNkYzIiMpmxD1xm3Y7YW6/4GApHOEr/JS0DEEc=; b=VpDFl7X70SqiwdewR6Kyo5tFCKxuxoXzSm9h47Y+GQEDrrSwO1GJD2SNTgeMuyqx12 8285ROHBgLJGzNdSHla9aK+aU6kOXn9ipg0NqGV2hLSO//JtOjl6olZJUZTdbPX2kiaB TaP5zew3W89OX407lJK1MJvhJq80r58Wbw84KBQWkH1lTWgm/fN260o4yG4Y4HXHmCFm 7KPxvGKTOWGIcjdjIDRHI0B240pt7xO6hFSDSC6MJnRmyH1T9hSksBCioPP5oJDw3FkM X3tgHvSJJvotTCaSg3iyP6XoiihBG5CBj/yQeMpeWmm5bEa2uIXZ7A9KNVWAwvTZeRws mwZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720576589; x=1721181389; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=YyOWpYNkYzIiMpmxD1xm3Y7YW6/4GApHOEr/JS0DEEc=; b=jexzAfXfVxNqO1HAWmd4ldUOBZY7EauX9LklyzGwDua6t2BPyqtWJJRUyVkK6gPIFh ZOcK3MevGpLMBvsDRAvZFgjvy9f0VQ05mB6/T1pXQL9/HOqa7tXQWyIr+cXvstM5yQS2 MHcjIisq7nAPCyXGEDUH5+F2ECeLLMO6TcklYeLME8f/8s5/metlId344wFMbKGkkBLJ tQI2HCHYg18A9uJm1FxWiKrXwvEc+xKa6JcU2AJJJ2e9BqTD8JGzQvApItLJzW8eT2Pv xj6GoEiWL45FwKfo6Z6dFp1DQ2fd3VsVmz/KuX0YJTM9OXVOjkb1ozr8AHjle97A4YMM eYqQ== X-Forwarded-Encrypted: i=1; AJvYcCVpw6WArkxDehlXl9OLuV3xyXaqNgD2syih/VJvb5eB0A4Ks2m3qz6ETQ/6FYDOWBJK9T2Ptc2p2qPC3mP+YbqlmjsBx8jCk61EyP+ZGlzGv4OutJNtIcYgaPxI3NOuTp+fYfXASbxxor8= X-Gm-Message-State: AOJu0Yz4fGKykQqWH3KNVH2WTvkOeYuW5eBEm0uwsIuqLUtP6VPWoMxL ou7xRzHkXjBEoTNfKj8+2ZmO0TJceXwOt0nYbkHe3F+R6Mz1ib7+u6WyFg== X-Google-Smtp-Source: AGHT+IE5AHL4/vtQqyuZ9UbrCmX7+hEX6L9dqIBONCxJi56T4LFcIDDzIdWkwQlMBrHj9zMN/Ax3SQ== X-Received: by 2002:a05:6808:191d:b0:3d9:b33e:d3e2 with SMTP id 5614622812f47-3d9b33ed905mr2468289b6e.19.1720576588986; Tue, 09 Jul 2024 18:56:28 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70b439673f4sm2507662b3a.117.2024.07.09.18.56.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jul 2024 18:56:28 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Mark Brown Cc: Greg Kroah-Hartman , "Rafael J . Wysocki" , Jean Delvare , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck Subject: [RFC PATCH 2/3] hwmon: (adt7470) Use multi-byte regmap operations Date: Tue, 9 Jul 2024 18:56:21 -0700 Message-Id: <20240710015622.1960522-3-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710015622.1960522-1-linux@roeck-us.net> References: <20240710015622.1960522-1-linux@roeck-us.net> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use multi-byte regmap operations where possible to reduce code size and the need for mutex protection. No functional change. Signed-off-by: Guenter Roeck --- drivers/hwmon/adt7470.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c index 517248d2994e..dbee6926fa05 100644 --- a/drivers/hwmon/adt7470.c +++ b/drivers/hwmon/adt7470.c @@ -728,30 +728,22 @@ static const int adt7470_freq_map[] = { static int pwm1_freq_get(struct device *dev) { struct adt7470_data *data = dev_get_drvdata(dev); - unsigned int cfg_reg_1, cfg_reg_2; + unsigned int regs[2] = {ADT7470_REG_CFG, ADT7470_REG_CFG_2}; + u8 cfg_reg[2]; int index; int err; - mutex_lock(&data->lock); - err = regmap_read(data->regmap, ADT7470_REG_CFG, &cfg_reg_1); - if (err < 0) - goto out; - err = regmap_read(data->regmap, ADT7470_REG_CFG_2, &cfg_reg_2); - if (err < 0) - goto out; - mutex_unlock(&data->lock); + err = regmap_multi_reg_read(data->regmap, regs, cfg_reg, 2); + if (err) + return err; - index = (cfg_reg_2 & ADT7470_FREQ_MASK) >> ADT7470_FREQ_SHIFT; - if (!(cfg_reg_1 & ADT7470_CFG_LF)) + index = (cfg_reg[1] & ADT7470_FREQ_MASK) >> ADT7470_FREQ_SHIFT; + if (!(cfg_reg[0] & ADT7470_CFG_LF)) index += 8; if (index >= ARRAY_SIZE(adt7470_freq_map)) index = ARRAY_SIZE(adt7470_freq_map) - 1; return adt7470_freq_map[index]; - -out: - mutex_unlock(&data->lock); - return err; } static int adt7470_pwm_read(struct device *dev, u32 attr, int channel, long *val) From patchwork Wed Jul 10 01:56:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13728786 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 625D1D535; Wed, 10 Jul 2024 01:56:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720576592; cv=none; b=k9m+lDDqMEUqY5kmKNY0pB8o5XpCIdxrgWIWBUbbP50njXhXHSdDzq9RkqwRA5qGNO/laksJtqtGXnRlC7TqMeAPdlr/VVZMlXD/EGARLLLwxsL6najHLQgU1Haw1q3yIqtRRVPZRUOF3slts8Q7u2l/GL9RSlwfyRSWgO818ME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720576592; c=relaxed/simple; bh=yVwBcqo4n7dV6025dgqgRj70ZSUioMAfZgJ1GaxdRSs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EK351j1fN/gPphMMdhGqLPmgl4/7EicR1dfwYfZ+FOFeJYG4Zo8L+Le9rs7JUdn8jPxWKS+Wd6ap56wz5DWVUOCvRNzy+A/Jyfo9o0EEEvY0njPfSBzeG+IHoEzU1yK7Yr4m2rFWhy3vyehtBKyBs6QnkLRik4LS1nRir//s+C0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AeM1VTcg; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AeM1VTcg" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-75c3afd7a50so3044818a12.2; Tue, 09 Jul 2024 18:56:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720576591; x=1721181391; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=ytinKlxNOsRvdg10ANmVnaYKwTMMTQXNjKLYhperoZ4=; b=AeM1VTcgMGdUIfwtVRWbyPlF6MK33r1nOIE9zwsUT7Svmw/KrSp69oGYnSzyhOHqAn w8fSjtyDPvwJgCS5f53aI4wq5ap0U5HMlS0EO6Qts+o+r4QMsJJHdiU9HBt4ZqemvOMo 5I3Mh65X1F+x16wdkDk3WYWFzZQHhW6EJfhzmXZ/3Bl4YuorHlYCBQYWIuiciVn94WC2 ++Lb+NAU2SWsIOqWqhO5Xbzz1DtSRIQa/H5luyXQd0tjy+gQFPXExaWutETu3mPQQbK6 4wQ4FIV8NHFda8AENFY+TxnTadwjpGk/kCpyYYZ7WuPVEM70tv3qn1EvdfYwqsCZZ0mQ llug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720576591; x=1721181391; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ytinKlxNOsRvdg10ANmVnaYKwTMMTQXNjKLYhperoZ4=; b=tiBHivrshmNhgWy8lj+A11ME3OjoGkPXj/WJscnUHtD+A80v1s1mR/jCjIUt2dm2GU 9XRER7c53BFLeX/Pp8d8yCVzgrgpYaVaHr8HEwyhumPlKGg+bl4u4VL+O1r3TLqdXW5G aHh2xQzMTeD+0rbQwMgNTU/dsdXf4CiT1j/RIxUqebVWaHXmzjgvFN7PTgbe+oVGyWSR iSo1cZu4fGNqnofC+BYUmQldNOYNQPvZzhMC/bgJQXMrFNq9f8m8DKRlq/7I0waP2IX8 F6VdtY2MltCBP/IDcIF7VgwgkA2JpUKySAg3bEbjtEQvLzJXDSDnn33Na1sA9idtzQre T7kQ== X-Forwarded-Encrypted: i=1; AJvYcCXXgfR8Q2l2k7Q+QSRuIXFcrJCmG6drEuACpLsJj6jntbq3cxxmi4O6TgB0DnUDe4wGj1k8BYv6my9W7bcPjUzWibnA08e/UpsXMdpfeltnV+rHE26lVdj+VeHpL9f7i4qsQ+xGLh1A1BM= X-Gm-Message-State: AOJu0Yy5vHKljA2Nar3ssaNsGKlqXAdfACiQn63oHTBqhfXqyPH3R/FP dHPgXRG8oqfuIVCU2tXpNorkLsnVUwy/U30i602KG8i+StScqSE2 X-Google-Smtp-Source: AGHT+IGsQHA1+z9NEfnc6SwgPlZp/8CqOTvpjdPg6Ag3ZGwmLc/fCDreMoAXNkD7OJQA24cVEhV7fQ== X-Received: by 2002:a05:6a20:3ca4:b0:1b3:d59f:2d87 with SMTP id adf61e73a8af0-1c2984e10b8mr4616766637.55.1720576590556; Tue, 09 Jul 2024 18:56:30 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6acfe85sm22342955ad.253.2024.07.09.18.56.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jul 2024 18:56:30 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Mark Brown Cc: Greg Kroah-Hartman , "Rafael J . Wysocki" , Jean Delvare , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck Subject: [RFC PATCH 3/3] hwmon: (tmp401) Use multi-byte regmap operations Date: Tue, 9 Jul 2024 18:56:22 -0700 Message-Id: <20240710015622.1960522-4-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710015622.1960522-1-linux@roeck-us.net> References: <20240710015622.1960522-1-linux@roeck-us.net> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use multi-byte regmap operations where possible to reduce code size and the need for mutex protection. No functional change. Signed-off-by: Guenter Roeck --- drivers/hwmon/tmp401.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c index df1b45a62e80..8a1497cca2d2 100644 --- a/drivers/hwmon/tmp401.c +++ b/drivers/hwmon/tmp401.c @@ -308,7 +308,9 @@ static int tmp401_temp_read(struct device *dev, u32 attr, int channel, long *val { struct tmp401_data *data = dev_get_drvdata(dev); struct regmap *regmap = data->regmap; + unsigned int regs[2]; unsigned int regval; + u16 regvals[2]; int reg, ret; switch (attr) { @@ -325,20 +327,13 @@ static int tmp401_temp_read(struct device *dev, u32 attr, int channel, long *val *val = tmp401_register_to_temp(regval, data->extended_range); break; case hwmon_temp_crit_hyst: - mutex_lock(&data->update_lock); - reg = TMP401_TEMP_MSB[3][channel]; - ret = regmap_read(regmap, reg, ®val); - if (ret < 0) - goto unlock; - *val = tmp401_register_to_temp(regval, data->extended_range); - ret = regmap_read(regmap, TMP401_TEMP_CRIT_HYST, ®val); - if (ret < 0) - goto unlock; - *val -= regval * 1000; -unlock: - mutex_unlock(&data->update_lock); + regs[0] = TMP401_TEMP_MSB[3][channel]; + regs[1] = TMP401_TEMP_CRIT_HYST; + ret = regmap_multi_reg_read(regmap, regs, regvals, 2); if (ret < 0) return ret; + *val = tmp401_register_to_temp(regvals[0], data->extended_range) - + (regvals[1] * 1000); break; case hwmon_temp_fault: case hwmon_temp_min_alarm: