From patchwork Thu Jul 18 03:39:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13735983 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (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 8BFE4376F5 for ; Thu, 18 Jul 2024 03:39:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721273983; cv=none; b=KIJAiBa7HMW5yVuGgV+WqFtlfMCqfC/n+d8zRNBnkW6MzjDA1eDg2CG/p6XN7o91QwZ9dcpCw3s87ZngarFVnM/N5B00wACaws81gnpBYYXDSPxbxbzSFSiNeboQzA8MidTUj5nWVdIWpKNL+1H9FvlHyABhUKR7aDyywyBib3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721273983; c=relaxed/simple; bh=GNDiW0+GJXij673+KU7H7ynI48GkMPJSU84i5l5aW5g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tgxxI+GPvn0qZflBhnC/NA8Ozbg7DEh+CNbXlFChNhIPmyl9dFcwWtPD+B6WD9K+AePtHTqKPzddq6QifiONAwYUvZaE7QD/s7LddYDq6q1i1662xFxxWUsk+PPNyAOt81CFVDtuVV0BKKlppbOY09YtuF5ShcH6XOt+6S8vANo= 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=idywjrMy; arc=none smtp.client-ip=209.85.210.44 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="idywjrMy" Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-708bf659898so167123a34.2 for ; Wed, 17 Jul 2024 20:39:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721273980; x=1721878780; 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=EF4XxHS390yRURmyVH/W1GTZ/aUx5MCavuLnoSaN6lc=; b=idywjrMyTnmDqn1hyWkM/TkYBqwMe4I2SILSe5Mis/g5V57uOWX/s1USBH2DEjqHJQ VnjdnYOoCiopDvFrgWCl0k1giHVdmXgbdyEVvnf5kCll6CLNFNvQE8FEQch+UMw4fbrh /2L6FMplu9Xqzazs2R/QnnhfLGBdI3speV2wnc58Y6pCFjV4kYN/fvL4L0hT18Pzh5R7 s9hhUjbcMRqMhPQcT3pfpWIaMG5Th7cU0aRZwAlI/2qFv4J08fF9yqKyTH1nMbY5z9Rm 20AcWvPGHNVdUpd9xwkvPIqoOaD9nBnc1zWloFkD+M7Tdb8oxxRgUI98tuoK6II5azdK GOLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721273980; x=1721878780; 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=EF4XxHS390yRURmyVH/W1GTZ/aUx5MCavuLnoSaN6lc=; b=oyFjOSPY8ytP+EJp6FyB4mxFUkdzOuJy+ie8sP68yFw33PsYGeH750Wiy+k6VaCzi0 tkOJgwwkxe2akyZy89Kn5WIfcCZVufndNLF38K5T27+TWFEZHUeKXeJRp4j9a/gVFhAV yUVZqXHkerN1XYi60ZyAtRR0uid5/0GDOeDVba5h0wjFBVxPq2BFRa2V0HWZsIt7PG+t PiY+PJ7kEoa8J+L/4302OWm+MCtfxMq8m04LN4Zdizd17G1Kd4j/93f8WSX+3ByMud2s CDHcsiGhKx7D4AR5FDDTYFgGYB33rBvnSq9VQi/n7RXpC9VZftizYPVRPwRm2RSR6nmo zOdg== X-Gm-Message-State: AOJu0Yypupka6pgN10oWGwcmhtRNb36s0KPkBcElqd309x36ZfnESCTt xAoMJQxuz6Ck4L/NRplKyUjNrRG0GiwG+42pOMfMXx9fSIrl2oIh2FJhZw== X-Google-Smtp-Source: AGHT+IHBMchzZZxqItYeRnYgnGxSWWpstrmhE1PclPfAkX6rB7/DJjvUIQSpYlrqDPeVBmMGZjHK7w== X-Received: by 2002:a05:6830:3143:b0:6fa:732b:862e with SMTP id 46e09a7af769-708e37961f1mr4732954a34.9.1721273980198; Wed, 17 Jul 2024 20:39:40 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70b7eca758fsm8903450b3a.162.2024.07.17.20.39.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 20:39:39 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 1/6] hwmon: (lm95234) Reorder include files to be in alphabetic order Date: Wed, 17 Jul 2024 20:39:30 -0700 Message-Id: <20240718033935.205185-2-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240718033935.205185-1-linux@roeck-us.net> References: <20240718033935.205185-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 Alphabetic include file order simplifies maintenance and makes it easier to add or remove files. No functional change. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/lm95234.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/lm95234.c b/drivers/hwmon/lm95234.c index 9a7afdb49895..0c509eed6a01 100644 --- a/drivers/hwmon/lm95234.c +++ b/drivers/hwmon/lm95234.c @@ -8,14 +8,14 @@ * Copyright (C) 2008, 2010 Davide Rizzo */ -#include -#include -#include -#include -#include +#include #include #include -#include +#include +#include +#include +#include +#include #include #include From patchwork Thu Jul 18 03:39:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13735984 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (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 5157429CFB for ; Thu, 18 Jul 2024 03:39:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721273984; cv=none; b=t6Bu5Q0uCRnNLbFBHydK/1WD3M5YDfLDopahz/L3nZ5fz6K5r56SbKuqcEJjBDdOhdn5RmqDg1ur7yIkmk76HF7F4pM0037fJZsumJ1wgA4MUaXX6UWl5bARVoQtnFNio9GTaeWBoj75lkibUh0/TFEdT8bOTIKOIuLTlSAGMEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721273984; c=relaxed/simple; bh=kXuVsiUcHiRrUPXOfDzsst+Aune/F/C5lJ9RZ1R/TwY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ViiIU5tATONyyfht8JEV4ISEA27jpF4uAzgmiBARZ1d1XanAz8IdkqI4Fxix74OouYYqdQhD4/iAslTGg79Tftq525tO5NNMo17hnEAtCqXGk0E3khv64NyW8hD6a3g7VeyT8yJ3irvHq81TlxaPGPFliws5gs9wrs+VxfLUb1Y= 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=kLvnN8gG; arc=none smtp.client-ip=209.85.161.43 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="kLvnN8gG" Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-5c6924f2383so134422eaf.2 for ; Wed, 17 Jul 2024 20:39:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721273982; x=1721878782; 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=DfwGsHdrUqlbm7Vhok1OoEqQT4Awjff9BELZTJX76ew=; b=kLvnN8gGeENg1xwxlmIfgYYOXbro0ZNN5x7jCvcuFPNyH/CDnUtMNRCzAb+arJ2v9g oANPhLz0uEt/3Qlk5WXbi5BBWZcfQSSgYI7HgQk8MSaSpTM+KY6yCAQHnVa0GDfdCVI9 Fy1jKuhAvP7Kjdv3zoGn/A+wujzzbj2DKAbMkiSKIdBpaBFlDmWZxvuKl+fazR0HXaFe VG0eonT2iR8C5w1PcdtSTGVY1vm73jX3vioOMCXA7YilDBYLC2ViIA+f66ycwId1rBGq 6V2/1a1S8Z+EGU96EyDLIiDENCDGGuQVAu6PSQ/OA0spGEs8AVE+/8TtvUZBcIBQgZND sBDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721273982; x=1721878782; 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=DfwGsHdrUqlbm7Vhok1OoEqQT4Awjff9BELZTJX76ew=; b=tehQdODw/Fm5jmrp7mhin7bSVLuKbiYRWTvus/nXctwbsCK08/I/f6XeezPsRlH1XQ 1QgnJemR7O6Q8anJ6l5pC/OgIH51J8ffmEF8LPwxgpmGAcr2qxuMqZYSn9as8CrHZtsI pVhqfNPQQfJLvI93XrS1278zKtE2as6+H6gC9ck3frepy+plBTdVFfAgMP0ZsC+f8MYB ggtUrRl0AdgBD5SdhTG9FN1rGTBL5nsu6kW+q5BIAE66PCTEYC4Xk9gTBrHFYVKpWf+h aYmeYsVpTRa8T2Ung/NkdisilQwrNpERRDUCmbvdfQt7LHgeEjHxnK0iQuGVZxSB7wFy mrDA== X-Gm-Message-State: AOJu0YwLcvXWVvttEe6QFaw1FHD8Tif73u48y/ZjVKihlErP6jouTkHN PQq4jMFruDtdOWiqicFIVe/aFuupMlR2usqiQYt0yi01jamub2LoKjQxRQ== X-Google-Smtp-Source: AGHT+IHXWXiAziHSpWbNjEtMPkVSawI31pd9klAtNwtjzycZ2zWGZ2GZQPrNfLyd9PHWDPq4JsY0Tg== X-Received: by 2002:a4a:ee95:0:b0:5c6:5cc9:bf29 with SMTP id 006d021491bc7-5d41bd339cfmr3722450eaf.5.1721273982027; Wed, 17 Jul 2024 20:39:42 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-78e386d7b15sm6989147a12.72.2024.07.17.20.39.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 20:39:41 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 2/6] hwmon: (lm95234) Use find_closest to find matching update interval Date: Wed, 17 Jul 2024 20:39:31 -0700 Message-Id: <20240718033935.205185-3-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240718033935.205185-1-linux@roeck-us.net> References: <20240718033935.205185-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 find_closest() instead of manually coding it to find best update interval. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/lm95234.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/hwmon/lm95234.c b/drivers/hwmon/lm95234.c index 0c509eed6a01..a36fa7824da8 100644 --- a/drivers/hwmon/lm95234.c +++ b/drivers/hwmon/lm95234.c @@ -18,6 +18,7 @@ #include #include #include +#include #define DRVNAME "lm95234" @@ -471,10 +472,7 @@ static ssize_t update_interval_store(struct device *dev, if (ret < 0) return ret; - for (regval = 0; regval < 3; regval++) { - if (val <= update_intervals[regval]) - break; - } + regval = find_closest(val, update_intervals, ARRAY_SIZE(update_intervals)); mutex_lock(&data->update_lock); data->interval = msecs_to_jiffies(update_intervals[regval]); From patchwork Thu Jul 18 03:39:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13735985 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 437A029CFB for ; Thu, 18 Jul 2024 03:39:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721273987; cv=none; b=nD+GULfjfm0f3P9pTgHYqkawCqX9QqbDDbRyS4ux6w0llAjRQw2xqmDGd0t92arDBc+mdG3YfLb0OG2gfyfq9LokPnz0SPrAmt8MD3ZaY1wGrSycUZvF/fJE1y8jHg2KQZ1fHjeOe3sM24ullz2g87uNEu55zGKuEC37guMgj+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721273987; c=relaxed/simple; bh=CUBjAHo0a0GiTXAFr/ztsfSI8JUBfEwzpXfjN2Rw82Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gaB129VS9kU0Cy1bm2MHoJ06oCGcJm6Np0j03rwJBpzIV45H4vhHOYm0CBUBHZ0H2OO6DtPdScxe3uvWuqF2rrw3MrcVqyyC5077udCGix7VtXDug5s5RxcUU+rvwgyjSnIVemrWkmmteL4L4QzYJ4DR/qYIR28LQmHjBzxDso0= 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=HlhjQPOg; arc=none smtp.client-ip=209.85.216.46 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="HlhjQPOg" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-2caeafd16deso254301a91.2 for ; Wed, 17 Jul 2024 20:39:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721273984; x=1721878784; 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=kML916YJrKJe7LqhvwLQlFlDcJ5D6uky50LwP5en5ME=; b=HlhjQPOgFcSEDstq9mtaP/EdNL5IfCD4GOQyoe1pQ+qH2l1Vk5RLBq3Ink/zVa4Rkq N4uMyspAnnt5h/WqrCFV/lRxU18LQAlFeCtvIwARwE46/Nwgk7gB1nZr6X/PEtu5FKOU bPHHiZYzynNmjUn17i6ytSIvTxfN7L5hOjHLEZKvsSlQfmMjsDjHbxvTwe92x8TkyweE /dvOek4AsgbQXwjOu0E4tGkaP9DLK3koUdpoTtRTaopjoaNbUrsRKcoMOVozLfWKNg/K +zITTR9wA1IIIv/3UE0ppOT5IVANGp9lG4Ckbdv7akZwqdXVIRzWvQWFnAq5Wfteo72Y E5LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721273984; x=1721878784; 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=kML916YJrKJe7LqhvwLQlFlDcJ5D6uky50LwP5en5ME=; b=YNgXrwhUbDfA741+93+Zt/rjF+M7CT4u3vz2gWYFu645yjqS2IOQTsSrRLaOJYvort b6mDcMK13yx2oAyaQ7Euqxv3t0JgpclyIbmGUPKzonYEGy0c2182U1JEczd52SYRAETB teRSPvpFsMSnQU6B5iF5up0dbAQgO/kKCgCp5KM8tqttWBKWw9BvGtKkOG7L2RcrlPks Y23rSxlUZXf8/OmM09WupUEd2tze7qyJzOYKCUGJ28Q/wXgnkoO0MxYikITfsg10eh+R VbJoLJm7Zn+uyfrpgDkB15hSXvQmuAFc0p+wbTWyPTxGzgNiLHBP2tAgakB6PRdWswXk U8Ag== X-Gm-Message-State: AOJu0Yzt5ym+Q8A4B1zCilG0A0EqaiSbxYfpotwM/auU1skyoB+fZVDF nvzUUdIhNBlvRxT4e3wXIVvRhdPRuSa+xB1LKJgJ4vXLdvG7QYet1rGMqg== X-Google-Smtp-Source: AGHT+IGF+Ro4HYS5ZKB8LFOmEfoKx8yTfhYBPpApeE48UnmDrxtF/W7VNnHE43+nyUvJH5ljh/WrNw== X-Received: by 2002:a17:90b:3102:b0:2c2:1d7a:1e10 with SMTP id 98e67ed59e1d1-2cb52691c48mr3052292a91.15.1721273983808; Wed, 17 Jul 2024 20:39:43 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cb600eae2esm750080a91.20.2024.07.17.20.39.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 20:39:43 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 3/6] hwmon: (lm95234) Convert to use regmap Date: Wed, 17 Jul 2024 20:39:32 -0700 Message-Id: <20240718033935.205185-4-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240718033935.205185-1-linux@roeck-us.net> References: <20240718033935.205185-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 regmap to replace local caching and to be able to use regmap API functions. No functional change. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/Kconfig | 1 + drivers/hwmon/lm95234.c | 437 +++++++++++++++++----------------------- 2 files changed, 186 insertions(+), 252 deletions(-) diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index b60fe2e58ad6..e838a55bb3cb 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1532,6 +1532,7 @@ config SENSORS_LM93 config SENSORS_LM95234 tristate "National Semiconductor LM95234 and compatibles" depends on I2C + select REGMAP_I2C help If you say yes here you get support for the LM95233 and LM95234 temperature sensor chips. diff --git a/drivers/hwmon/lm95234.c b/drivers/hwmon/lm95234.c index a36fa7824da8..7a3aff1d183a 100644 --- a/drivers/hwmon/lm95234.c +++ b/drivers/hwmon/lm95234.c @@ -13,10 +13,10 @@ #include #include #include -#include #include #include #include +#include #include #include @@ -33,6 +33,8 @@ static const unsigned short normal_i2c[] = { #define LM95234_REG_STATUS 0x02 #define LM95234_REG_CONFIG 0x03 #define LM95234_REG_CONVRATE 0x04 +#define LM95234_REG_ENABLE 0x05 +#define LM95234_REG_FILTER 0x06 #define LM95234_REG_STS_FAULT 0x07 #define LM95234_REG_STS_TCRIT1 0x08 #define LM95234_REG_STS_TCRIT2 0x09 @@ -53,181 +55,72 @@ static const unsigned short normal_i2c[] = { /* Client data (each client gets its own) */ struct lm95234_data { - struct i2c_client *client; + struct regmap *regmap; const struct attribute_group *groups[3]; struct mutex update_lock; - unsigned long last_updated, interval; /* in jiffies */ - bool valid; /* false until following fields are valid */ - /* registers values */ - int temp[5]; /* temperature (signed) */ - u32 status; /* fault/alarm status */ - u8 tcrit1[5]; /* critical temperature limit */ - u8 tcrit2[2]; /* high temperature limit */ - s8 toffset[4]; /* remote temperature offset */ - u8 thyst; /* common hysteresis */ - - u8 sensor_type; /* temperature sensor type */ }; -static int lm95234_read_temp(struct i2c_client *client, int index, int *t) +static int lm95234_read_temp(struct regmap *regmap, int index, int *t) { - int val; - u16 temp = 0; + int temp = 0, ret; + u32 val; if (index) { - val = i2c_smbus_read_byte_data(client, - LM95234_REG_UTEMPH(index - 1)); - if (val < 0) - return val; + ret = regmap_read(regmap, LM95234_REG_UTEMPH(index - 1), &val); + if (ret) + return ret; temp = val << 8; - val = i2c_smbus_read_byte_data(client, - LM95234_REG_UTEMPL(index - 1)); - if (val < 0) - return val; + ret = regmap_read(regmap, LM95234_REG_UTEMPL(index - 1), &val); + if (ret) + return ret; temp |= val; - *t = temp; } /* * Read signed temperature if unsigned temperature is 0, * or if this is the local sensor. */ if (!temp) { - val = i2c_smbus_read_byte_data(client, - LM95234_REG_TEMPH(index)); - if (val < 0) - return val; + ret = regmap_read(regmap, LM95234_REG_TEMPH(index), &val); + if (ret) + return ret; temp = val << 8; - val = i2c_smbus_read_byte_data(client, - LM95234_REG_TEMPL(index)); - if (val < 0) - return val; - temp |= val; - *t = (s16)temp; + ret = regmap_read(regmap, LM95234_REG_TEMPL(index), &val); + if (ret) + return ret; + temp = sign_extend32(temp | val, 15); } + *t = DIV_ROUND_CLOSEST(temp * 125, 32); return 0; } -static u16 update_intervals[] = { 143, 364, 1000, 2500 }; - -/* Fill value cache. Must be called with update lock held. */ - -static int lm95234_fill_cache(struct lm95234_data *data, - struct i2c_client *client) -{ - int i, ret; - - ret = i2c_smbus_read_byte_data(client, LM95234_REG_CONVRATE); - if (ret < 0) - return ret; - - data->interval = msecs_to_jiffies(update_intervals[ret & 0x03]); - - for (i = 0; i < ARRAY_SIZE(data->tcrit1); i++) { - ret = i2c_smbus_read_byte_data(client, LM95234_REG_TCRIT1(i)); - if (ret < 0) - return ret; - data->tcrit1[i] = ret; - } - for (i = 0; i < ARRAY_SIZE(data->tcrit2); i++) { - ret = i2c_smbus_read_byte_data(client, LM95234_REG_TCRIT2(i)); - if (ret < 0) - return ret; - data->tcrit2[i] = ret; - } - for (i = 0; i < ARRAY_SIZE(data->toffset); i++) { - ret = i2c_smbus_read_byte_data(client, LM95234_REG_OFFSET(i)); - if (ret < 0) - return ret; - data->toffset[i] = ret; - } - - ret = i2c_smbus_read_byte_data(client, LM95234_REG_TCRIT_HYST); - if (ret < 0) - return ret; - data->thyst = ret; - - ret = i2c_smbus_read_byte_data(client, LM95234_REG_REM_MODEL); - if (ret < 0) - return ret; - data->sensor_type = ret; - - return 0; -} - -static int lm95234_update_device(struct lm95234_data *data) -{ - struct i2c_client *client = data->client; - int ret; - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + data->interval) || - !data->valid) { - int i; - - if (!data->valid) { - ret = lm95234_fill_cache(data, client); - if (ret < 0) - goto abort; - } - - data->valid = false; - for (i = 0; i < ARRAY_SIZE(data->temp); i++) { - ret = lm95234_read_temp(client, i, &data->temp[i]); - if (ret < 0) - goto abort; - } - - ret = i2c_smbus_read_byte_data(client, LM95234_REG_STS_FAULT); - if (ret < 0) - goto abort; - data->status = ret; - - ret = i2c_smbus_read_byte_data(client, LM95234_REG_STS_TCRIT1); - if (ret < 0) - goto abort; - data->status |= ret << 8; - - ret = i2c_smbus_read_byte_data(client, LM95234_REG_STS_TCRIT2); - if (ret < 0) - goto abort; - data->status |= ret << 16; - - data->last_updated = jiffies; - data->valid = true; - } - ret = 0; -abort: - mutex_unlock(&data->update_lock); - - return ret; -} - static ssize_t temp_show(struct device *dev, struct device_attribute *attr, char *buf) { struct lm95234_data *data = dev_get_drvdata(dev); int index = to_sensor_dev_attr(attr)->index; - int ret = lm95234_update_device(data); + int ret, temp; + ret = lm95234_read_temp(data->regmap, index, &temp); if (ret) return ret; - return sprintf(buf, "%d\n", - DIV_ROUND_CLOSEST(data->temp[index] * 125, 32)); + return sysfs_emit(buf, "%d\n", temp); } static ssize_t alarm_show(struct device *dev, struct device_attribute *attr, char *buf) { struct lm95234_data *data = dev_get_drvdata(dev); - u32 mask = to_sensor_dev_attr(attr)->index; - int ret = lm95234_update_device(data); + u8 mask = to_sensor_dev_attr_2(attr)->index; + u8 reg = to_sensor_dev_attr_2(attr)->nr; + int ret; + u32 val; + ret = regmap_read(data->regmap, reg, &val); if (ret) return ret; - return sprintf(buf, "%u", !!(data->status & mask)); + return sysfs_emit(buf, "%u\n", !!(val & mask)); } static ssize_t type_show(struct device *dev, struct device_attribute *attr, @@ -235,24 +128,23 @@ static ssize_t type_show(struct device *dev, struct device_attribute *attr, { struct lm95234_data *data = dev_get_drvdata(dev); u8 mask = to_sensor_dev_attr(attr)->index; - int ret = lm95234_update_device(data); + u32 val; + int ret; + ret = regmap_read(data->regmap, LM95234_REG_REM_MODEL, &val); if (ret) return ret; - return sprintf(buf, data->sensor_type & mask ? "1\n" : "2\n"); + return sysfs_emit(buf, "%s\n", val & mask ? "1" : "2"); } static ssize_t type_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct lm95234_data *data = dev_get_drvdata(dev); - unsigned long val; u8 mask = to_sensor_dev_attr(attr)->index; - int ret = lm95234_update_device(data); - - if (ret) - return ret; + unsigned long val; + int ret; ret = kstrtoul(buf, 10, &val); if (ret < 0) @@ -261,16 +153,10 @@ static ssize_t type_store(struct device *dev, struct device_attribute *attr, if (val != 1 && val != 2) return -EINVAL; - mutex_lock(&data->update_lock); - if (val == 1) - data->sensor_type |= mask; - else - data->sensor_type &= ~mask; - data->valid = false; - i2c_smbus_write_byte_data(data->client, LM95234_REG_REM_MODEL, - data->sensor_type); - mutex_unlock(&data->update_lock); - + ret = regmap_update_bits(data->regmap, LM95234_REG_REM_MODEL, + mask, val == 1 ? mask : 0); + if (ret) + return ret; return count; } @@ -279,12 +165,14 @@ static ssize_t tcrit2_show(struct device *dev, struct device_attribute *attr, { struct lm95234_data *data = dev_get_drvdata(dev); int index = to_sensor_dev_attr(attr)->index; - int ret = lm95234_update_device(data); + int ret; + u32 tcrit2; + ret = regmap_read(data->regmap, LM95234_REG_TCRIT2(index), &tcrit2); if (ret) return ret; - return sprintf(buf, "%u", data->tcrit2[index] * 1000); + return sysfs_emit(buf, "%u\n", tcrit2 * 1000); } static ssize_t tcrit2_store(struct device *dev, struct device_attribute *attr, @@ -293,10 +181,7 @@ static ssize_t tcrit2_store(struct device *dev, struct device_attribute *attr, struct lm95234_data *data = dev_get_drvdata(dev); int index = to_sensor_dev_attr(attr)->index; long val; - int ret = lm95234_update_device(data); - - if (ret) - return ret; + int ret; ret = kstrtol(buf, 10, &val); if (ret < 0) @@ -305,27 +190,38 @@ static ssize_t tcrit2_store(struct device *dev, struct device_attribute *attr, val = DIV_ROUND_CLOSEST(clamp_val(val, 0, (index ? 255 : 127) * 1000), 1000); - mutex_lock(&data->update_lock); - data->tcrit2[index] = val; - i2c_smbus_write_byte_data(data->client, LM95234_REG_TCRIT2(index), val); - mutex_unlock(&data->update_lock); - + ret = regmap_write(data->regmap, LM95234_REG_TCRIT2(index), val); + if (ret) + return ret; return count; } +static ssize_t tcrit_hyst_show(struct lm95234_data *data, char *buf, int reg) +{ + u32 thyst, tcrit; + int ret; + + mutex_lock(&data->update_lock); + ret = regmap_read(data->regmap, reg, &tcrit); + if (ret) + goto unlock; + ret = regmap_read(data->regmap, LM95234_REG_TCRIT_HYST, &thyst); +unlock: + mutex_unlock(&data->update_lock); + if (ret) + return ret; + + /* Result can be negative, so be careful with unsigned operands */ + return sysfs_emit(buf, "%d\n", ((int)tcrit - (int)thyst) * 1000); +} + static ssize_t tcrit2_hyst_show(struct device *dev, struct device_attribute *attr, char *buf) { struct lm95234_data *data = dev_get_drvdata(dev); int index = to_sensor_dev_attr(attr)->index; - int ret = lm95234_update_device(data); - if (ret) - return ret; - - /* Result can be negative, so be careful with unsigned operands */ - return sprintf(buf, "%d", - ((int)data->tcrit2[index] - (int)data->thyst) * 1000); + return tcrit_hyst_show(data, buf, LM95234_REG_TCRIT2(index)); } static ssize_t tcrit1_show(struct device *dev, struct device_attribute *attr, @@ -333,8 +229,14 @@ static ssize_t tcrit1_show(struct device *dev, struct device_attribute *attr, { struct lm95234_data *data = dev_get_drvdata(dev); int index = to_sensor_dev_attr(attr)->index; + int ret; + u32 val; - return sprintf(buf, "%u", data->tcrit1[index] * 1000); + ret = regmap_read(data->regmap, LM95234_REG_TCRIT1(index), &val); + if (ret) + return ret; + + return sysfs_emit(buf, "%u\n", val * 1000); } static ssize_t tcrit1_store(struct device *dev, struct device_attribute *attr, @@ -342,11 +244,8 @@ static ssize_t tcrit1_store(struct device *dev, struct device_attribute *attr, { struct lm95234_data *data = dev_get_drvdata(dev); int index = to_sensor_dev_attr(attr)->index; - int ret = lm95234_update_device(data); long val; - - if (ret) - return ret; + int ret; ret = kstrtol(buf, 10, &val); if (ret < 0) @@ -354,10 +253,9 @@ static ssize_t tcrit1_store(struct device *dev, struct device_attribute *attr, val = DIV_ROUND_CLOSEST(clamp_val(val, 0, 255000), 1000); - mutex_lock(&data->update_lock); - data->tcrit1[index] = val; - i2c_smbus_write_byte_data(data->client, LM95234_REG_TCRIT1(index), val); - mutex_unlock(&data->update_lock); + ret = regmap_write(data->regmap, LM95234_REG_TCRIT1(index), val); + if (ret) + return ret; return count; } @@ -367,14 +265,8 @@ static ssize_t tcrit1_hyst_show(struct device *dev, { struct lm95234_data *data = dev_get_drvdata(dev); int index = to_sensor_dev_attr(attr)->index; - int ret = lm95234_update_device(data); - if (ret) - return ret; - - /* Result can be negative, so be careful with unsigned operands */ - return sprintf(buf, "%d", - ((int)data->tcrit1[index] - (int)data->thyst) * 1000); + return tcrit_hyst_show(data, buf, LM95234_REG_TCRIT1(index)); } static ssize_t tcrit1_hyst_store(struct device *dev, @@ -383,23 +275,28 @@ static ssize_t tcrit1_hyst_store(struct device *dev, { struct lm95234_data *data = dev_get_drvdata(dev); int index = to_sensor_dev_attr(attr)->index; - int ret = lm95234_update_device(data); + u32 tcrit; long val; - - if (ret) - return ret; + int ret; ret = kstrtol(buf, 10, &val); if (ret < 0) return ret; - val = DIV_ROUND_CLOSEST(clamp_val(val, -255000, 255000), 1000); - val = clamp_val((int)data->tcrit1[index] - val, 0, 31); - mutex_lock(&data->update_lock); - data->thyst = val; - i2c_smbus_write_byte_data(data->client, LM95234_REG_TCRIT_HYST, val); + + ret = regmap_read(data->regmap, LM95234_REG_TCRIT1(index), &tcrit); + if (ret) + goto unlock; + + val = DIV_ROUND_CLOSEST(clamp_val(val, -255000, 255000), 1000); + val = clamp_val((int)tcrit - val, 0, 31); + + ret = regmap_write(data->regmap, LM95234_REG_TCRIT_HYST, val); +unlock: mutex_unlock(&data->update_lock); + if (ret) + return ret; return count; } @@ -409,12 +306,14 @@ static ssize_t offset_show(struct device *dev, struct device_attribute *attr, { struct lm95234_data *data = dev_get_drvdata(dev); int index = to_sensor_dev_attr(attr)->index; - int ret = lm95234_update_device(data); + u32 offset; + int ret; + ret = regmap_read(data->regmap, LM95234_REG_OFFSET(index), &offset); if (ret) return ret; - return sprintf(buf, "%d", data->toffset[index] * 500); + return sysfs_emit(buf, "%d\n", sign_extend32(offset, 7) * 500); } static ssize_t offset_store(struct device *dev, struct device_attribute *attr, @@ -422,11 +321,8 @@ static ssize_t offset_store(struct device *dev, struct device_attribute *attr, { struct lm95234_data *data = dev_get_drvdata(dev); int index = to_sensor_dev_attr(attr)->index; - int ret = lm95234_update_device(data); long val; - - if (ret) - return ret; + int ret; ret = kstrtol(buf, 10, &val); if (ret < 0) @@ -435,25 +331,27 @@ static ssize_t offset_store(struct device *dev, struct device_attribute *attr, /* Accuracy is 1/2 degrees C */ val = DIV_ROUND_CLOSEST(clamp_val(val, -64000, 63500), 500); - mutex_lock(&data->update_lock); - data->toffset[index] = val; - i2c_smbus_write_byte_data(data->client, LM95234_REG_OFFSET(index), val); - mutex_unlock(&data->update_lock); + ret = regmap_write(data->regmap, LM95234_REG_OFFSET(index), val); + if (ret < 0) + return ret; return count; } +static u16 update_intervals[] = { 143, 364, 1000, 2500 }; + static ssize_t update_interval_show(struct device *dev, struct device_attribute *attr, char *buf) { struct lm95234_data *data = dev_get_drvdata(dev); - int ret = lm95234_update_device(data); + u32 convrate; + int ret; + ret = regmap_read(data->regmap, LM95234_REG_CONVRATE, &convrate); if (ret) return ret; - return sprintf(buf, "%lu\n", - DIV_ROUND_CLOSEST(data->interval * 1000, HZ)); + return sysfs_emit(buf, "%u\n", update_intervals[convrate & 0x03]); } static ssize_t update_interval_store(struct device *dev, @@ -461,23 +359,17 @@ static ssize_t update_interval_store(struct device *dev, const char *buf, size_t count) { struct lm95234_data *data = dev_get_drvdata(dev); - int ret = lm95234_update_device(data); unsigned long val; - u8 regval; - - if (ret) - return ret; + int ret; ret = kstrtoul(buf, 10, &val); if (ret < 0) return ret; - regval = find_closest(val, update_intervals, ARRAY_SIZE(update_intervals)); - - mutex_lock(&data->update_lock); - data->interval = msecs_to_jiffies(update_intervals[regval]); - i2c_smbus_write_byte_data(data->client, LM95234_REG_CONVRATE, regval); - mutex_unlock(&data->update_lock); + val = find_closest(val, update_intervals, ARRAY_SIZE(update_intervals)); + ret = regmap_write(data->regmap, LM95234_REG_CONVRATE, val); + if (ret) + return ret; return count; } @@ -488,10 +380,10 @@ static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2); static SENSOR_DEVICE_ATTR_RO(temp4_input, temp, 3); static SENSOR_DEVICE_ATTR_RO(temp5_input, temp, 4); -static SENSOR_DEVICE_ATTR_RO(temp2_fault, alarm, BIT(0) | BIT(1)); -static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, BIT(2) | BIT(3)); -static SENSOR_DEVICE_ATTR_RO(temp4_fault, alarm, BIT(4) | BIT(5)); -static SENSOR_DEVICE_ATTR_RO(temp5_fault, alarm, BIT(6) | BIT(7)); +static SENSOR_DEVICE_ATTR_2_RO(temp2_fault, alarm, LM95234_REG_STS_FAULT, BIT(0) | BIT(1)); +static SENSOR_DEVICE_ATTR_2_RO(temp3_fault, alarm, LM95234_REG_STS_FAULT, BIT(2) | BIT(3)); +static SENSOR_DEVICE_ATTR_2_RO(temp4_fault, alarm, LM95234_REG_STS_FAULT, BIT(4) | BIT(5)); +static SENSOR_DEVICE_ATTR_2_RO(temp5_fault, alarm, LM95234_REG_STS_FAULT, BIT(6) | BIT(7)); static SENSOR_DEVICE_ATTR_RW(temp2_type, type, BIT(1)); static SENSOR_DEVICE_ATTR_RW(temp3_type, type, BIT(2)); @@ -510,11 +402,11 @@ static SENSOR_DEVICE_ATTR_RO(temp3_max_hyst, tcrit2_hyst, 1); static SENSOR_DEVICE_ATTR_RO(temp4_max_hyst, tcrit1_hyst, 3); static SENSOR_DEVICE_ATTR_RO(temp5_max_hyst, tcrit1_hyst, 4); -static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, alarm, BIT(0 + 8)); -static SENSOR_DEVICE_ATTR_RO(temp2_max_alarm, alarm, BIT(1 + 16)); -static SENSOR_DEVICE_ATTR_RO(temp3_max_alarm, alarm, BIT(2 + 16)); -static SENSOR_DEVICE_ATTR_RO(temp4_max_alarm, alarm, BIT(3 + 8)); -static SENSOR_DEVICE_ATTR_RO(temp5_max_alarm, alarm, BIT(4 + 8)); +static SENSOR_DEVICE_ATTR_2_RO(temp1_max_alarm, alarm, LM95234_REG_STS_TCRIT1, BIT(0)); +static SENSOR_DEVICE_ATTR_2_RO(temp2_max_alarm, alarm, LM95234_REG_STS_TCRIT2, BIT(1)); +static SENSOR_DEVICE_ATTR_2_RO(temp3_max_alarm, alarm, LM95234_REG_STS_TCRIT2, BIT(2)); +static SENSOR_DEVICE_ATTR_2_RO(temp4_max_alarm, alarm, LM95234_REG_STS_TCRIT1, BIT(3)); +static SENSOR_DEVICE_ATTR_2_RO(temp5_max_alarm, alarm, LM95234_REG_STS_TCRIT1, BIT(4)); static SENSOR_DEVICE_ATTR_RW(temp2_crit, tcrit1, 1); static SENSOR_DEVICE_ATTR_RW(temp3_crit, tcrit1, 2); @@ -522,8 +414,8 @@ static SENSOR_DEVICE_ATTR_RW(temp3_crit, tcrit1, 2); static SENSOR_DEVICE_ATTR_RO(temp2_crit_hyst, tcrit1_hyst, 1); static SENSOR_DEVICE_ATTR_RO(temp3_crit_hyst, tcrit1_hyst, 2); -static SENSOR_DEVICE_ATTR_RO(temp2_crit_alarm, alarm, BIT(1 + 8)); -static SENSOR_DEVICE_ATTR_RO(temp3_crit_alarm, alarm, BIT(2 + 8)); +static SENSOR_DEVICE_ATTR_2_RO(temp2_crit_alarm, alarm, LM95234_REG_STS_TCRIT1, BIT(1)); +static SENSOR_DEVICE_ATTR_2_RO(temp3_crit_alarm, alarm, LM95234_REG_STS_TCRIT1, BIT(2)); static SENSOR_DEVICE_ATTR_RW(temp2_offset, offset, 0); static SENSOR_DEVICE_ATTR_RW(temp3_offset, offset, 1); @@ -587,6 +479,45 @@ static const struct attribute_group lm95234_group = { .attrs = lm95234_attrs, }; +static bool lm95234_volatile_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case LM95234_REG_TEMPH(0) ... LM95234_REG_TEMPH(4): + case LM95234_REG_TEMPL(0) ... LM95234_REG_TEMPL(4): + case LM95234_REG_UTEMPH(0) ... LM95234_REG_UTEMPH(3): + case LM95234_REG_UTEMPL(0) ... LM95234_REG_UTEMPL(3): + case LM95234_REG_STS_FAULT: + case LM95234_REG_STS_TCRIT1: + case LM95234_REG_STS_TCRIT2: + case LM95234_REG_REM_MODEL_STS: + return true; + default: + return false; + } +} + +static bool lm95234_writeable_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case LM95234_REG_CONFIG ... LM95234_REG_FILTER: + case LM95234_REG_REM_MODEL ... LM95234_REG_OFFSET(3): + case LM95234_REG_TCRIT1(0) ... LM95234_REG_TCRIT1(4): + case LM95234_REG_TCRIT2(0) ... LM95234_REG_TCRIT2(1): + case LM95234_REG_TCRIT_HYST: + return true; + default: + return false; + } +} + +static const struct regmap_config lm95234_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .writeable_reg = lm95234_writeable_reg, + .volatile_reg = lm95234_volatile_reg, + .cache_type = REGCACHE_MAPLE, +}; + static int lm95234_detect(struct i2c_client *client, struct i2c_board_info *info) { @@ -647,33 +578,30 @@ static int lm95234_detect(struct i2c_client *client, return 0; } -static int lm95234_init_client(struct i2c_client *client) +static int lm95234_init_client(struct device *dev, struct regmap *regmap) { - int val, model; + u32 val, model; + int ret; /* start conversion if necessary */ - val = i2c_smbus_read_byte_data(client, LM95234_REG_CONFIG); - if (val < 0) - return val; - if (val & 0x40) - i2c_smbus_write_byte_data(client, LM95234_REG_CONFIG, - val & ~0x40); + ret = regmap_clear_bits(regmap, LM95234_REG_CONFIG, 0x40); + if (ret) + return ret; /* If diode type status reports an error, try to fix it */ - val = i2c_smbus_read_byte_data(client, LM95234_REG_REM_MODEL_STS); - if (val < 0) - return val; - model = i2c_smbus_read_byte_data(client, LM95234_REG_REM_MODEL); - if (model < 0) - return model; + ret = regmap_read(regmap, LM95234_REG_REM_MODEL_STS, &val); + if (ret < 0) + return ret; + ret = regmap_read(regmap, LM95234_REG_REM_MODEL, &model); + if (ret < 0) + return ret; if (model & val) { - dev_notice(&client->dev, + dev_notice(dev, "Fixing remote diode type misconfiguration (0x%x)\n", val); - i2c_smbus_write_byte_data(client, LM95234_REG_REM_MODEL, - model & ~val); + ret = regmap_write(regmap, LM95234_REG_REM_MODEL, model & ~val); } - return 0; + return ret; } static int lm95234_probe(struct i2c_client *client) @@ -682,17 +610,22 @@ static int lm95234_probe(struct i2c_client *client) struct device *dev = &client->dev; struct lm95234_data *data; struct device *hwmon_dev; + struct regmap *regmap; int err; data = devm_kzalloc(dev, sizeof(struct lm95234_data), GFP_KERNEL); if (!data) return -ENOMEM; - data->client = client; + regmap = devm_regmap_init_i2c(client, &lm95234_regmap_config); + if (IS_ERR(regmap)) + return PTR_ERR(regmap); + + data->regmap = regmap; mutex_init(&data->update_lock); /* Initialize the LM95234 chip */ - err = lm95234_init_client(client); + err = lm95234_init_client(dev, regmap); if (err < 0) return err; From patchwork Thu Jul 18 03:39:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13735986 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 09341376EC for ; Thu, 18 Jul 2024 03:39:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721273989; cv=none; b=YvrzaVGIx2u91sr4vc55Yg7fvAMO/JegWPsCHJRMxdUbAXqF1aqoiXAwVKuYV4e8+5q3CjTcxavjyWE/yGxfeF9fYk7UiH7eeJkXAdumwpiDIBgOfvb6kgNNZSYgmpsjvbIIuh1Fm2VK/01tNY6VHirlHQ1AaO2o498GofYI9xg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721273989; c=relaxed/simple; bh=QVHdiHbitZ3+6bWTxAqLkygh0YL7aR8MV6QaSbbJb5s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=F3GN4oi/FI4EVdzO63AgBWI2GTbW7XGMsKB52uzJR4TvboEecKeZyJJO9jPzRIj7X5GMkoalCpGoqb5kxw7REjWFD3cVXYU/HX/bDyCpecMXTLITbLvFvQn60mO21KlFFC1V+Cie8RHg7Eu6YrWaFsbDXWOx9pYT436rtl4d5eA= 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=FHj/lNY7; arc=none smtp.client-ip=209.85.214.176 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="FHj/lNY7" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1fc65329979so627925ad.0 for ; Wed, 17 Jul 2024 20:39:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721273986; x=1721878786; 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=rKEA7NJtk7nS+aiqxxxiD858+gRnVFS4bV5BwmnGIVQ=; b=FHj/lNY7if8VvCNtugVbjZ3D3kBSUgzDnE4W5ScpaayzbVT7Zll9RtDdaUs4vfiko8 3RJIZX8JWkYFM2ztLcroJF2UgflZIOE+6n9x1InyDH/k5yIgUSXyJxhBcEUKXAXBw/3Q SV9OsDVA7703Wxsv3yFOfyfufoc/0KQTavWSuEEdRWvWfdivUyPXUhnL6Nt+0baiWzFj xwc30kd7MuO0gyi+WjK4+gHC7PlnOXPe4QerdAdVJYffKhV5f+VxTJv34HF1lImY+8sf fz+wSzTBesnChfC/oMfK3u3Joif9TsmJ4q/Ieyay8jS0H+qYDCW7ppDJEhpM/NiP4sv4 2QEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721273986; x=1721878786; 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=rKEA7NJtk7nS+aiqxxxiD858+gRnVFS4bV5BwmnGIVQ=; b=RmxOuHTA0ZHUUBUE1FIAxfXGJHB8tebX0jkffknEYm2s8R+auMbcpj3uEnyII1pJqv VtBjPZsWPQg+Ebg7eYilXeWNDmWd69jV8wJp/EBm6mD2eYKxcNMKc0TnyvdLWX/5OD8d vzrORsGzji88kMQ0gBGcEFG6z/Teu+K3W4hIMWoUuMg+5e1KGcMsDahHPeNifincYw18 DArBOFHl1Oyg1NA0SUSMrelVLMdnmxLV3tRJ/ENDtxozKxR4ESZ7A47jWYWdnDirWzpa 5RPwPn7EYN0pDQJVfi4X4tHow5lqXrbYoaHu3/sdSpFcG1iYqft6C79l4maSvNKq9uNi huvw== X-Gm-Message-State: AOJu0YzPoSdn5XxsZ4mI5mVANzimz9fF/CX9Sn5eqx/tofIoxE211XV4 hzP6Up/4bLQzZsRQBlIurUCOy4ZAv1CZcO8e/P5YNAaxE0kuYQVfp6dxkg== X-Google-Smtp-Source: AGHT+IGU7kMvB/6PeVJ7u6aDGKv1zQsFYl313RMNQRWkr7WvxM8xxeTpsw/erudq88JP30IJmhc5qQ== X-Received: by 2002:a17:902:ec85:b0:1fb:715d:df83 with SMTP id d9443c01a7336-1fc4e154b16mr35992735ad.13.1721273985550; Wed, 17 Jul 2024 20:39:45 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fc0bbc4d7esm82004815ad.101.2024.07.17.20.39.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 20:39:44 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 4/6] hwmon: (lm95234) Convert to with_info hwmon API Date: Wed, 17 Jul 2024 20:39:33 -0700 Message-Id: <20240718033935.205185-5-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240718033935.205185-1-linux@roeck-us.net> References: <20240718033935.205185-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 Convert to with_info API to simplify the code and reduce its size. This patch reduces the object file size by about 30%. No functional change. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/lm95234.c | 557 ++++++++++++++++------------------------ 1 file changed, 227 insertions(+), 330 deletions(-) diff --git a/drivers/hwmon/lm95234.c b/drivers/hwmon/lm95234.c index 7a3aff1d183a..1a164f47fb3e 100644 --- a/drivers/hwmon/lm95234.c +++ b/drivers/hwmon/lm95234.c @@ -10,14 +10,12 @@ #include #include -#include #include #include #include #include #include #include -#include #include #define DRVNAME "lm95234" @@ -56,11 +54,11 @@ static const unsigned short normal_i2c[] = { /* Client data (each client gets its own) */ struct lm95234_data { struct regmap *regmap; - const struct attribute_group *groups[3]; struct mutex update_lock; + enum chips type; }; -static int lm95234_read_temp(struct regmap *regmap, int index, int *t) +static int lm95234_read_temp(struct regmap *regmap, int index, long *t) { int temp = 0, ret; u32 val; @@ -93,110 +91,7 @@ static int lm95234_read_temp(struct regmap *regmap, int index, int *t) return 0; } -static ssize_t temp_show(struct device *dev, struct device_attribute *attr, - char *buf) -{ - struct lm95234_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(attr)->index; - int ret, temp; - - ret = lm95234_read_temp(data->regmap, index, &temp); - if (ret) - return ret; - - return sysfs_emit(buf, "%d\n", temp); -} - -static ssize_t alarm_show(struct device *dev, struct device_attribute *attr, - char *buf) -{ - struct lm95234_data *data = dev_get_drvdata(dev); - u8 mask = to_sensor_dev_attr_2(attr)->index; - u8 reg = to_sensor_dev_attr_2(attr)->nr; - int ret; - u32 val; - - ret = regmap_read(data->regmap, reg, &val); - if (ret) - return ret; - - return sysfs_emit(buf, "%u\n", !!(val & mask)); -} - -static ssize_t type_show(struct device *dev, struct device_attribute *attr, - char *buf) -{ - struct lm95234_data *data = dev_get_drvdata(dev); - u8 mask = to_sensor_dev_attr(attr)->index; - u32 val; - int ret; - - ret = regmap_read(data->regmap, LM95234_REG_REM_MODEL, &val); - if (ret) - return ret; - - return sysfs_emit(buf, "%s\n", val & mask ? "1" : "2"); -} - -static ssize_t type_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct lm95234_data *data = dev_get_drvdata(dev); - u8 mask = to_sensor_dev_attr(attr)->index; - unsigned long val; - int ret; - - ret = kstrtoul(buf, 10, &val); - if (ret < 0) - return ret; - - if (val != 1 && val != 2) - return -EINVAL; - - ret = regmap_update_bits(data->regmap, LM95234_REG_REM_MODEL, - mask, val == 1 ? mask : 0); - if (ret) - return ret; - return count; -} - -static ssize_t tcrit2_show(struct device *dev, struct device_attribute *attr, - char *buf) -{ - struct lm95234_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(attr)->index; - int ret; - u32 tcrit2; - - ret = regmap_read(data->regmap, LM95234_REG_TCRIT2(index), &tcrit2); - if (ret) - return ret; - - return sysfs_emit(buf, "%u\n", tcrit2 * 1000); -} - -static ssize_t tcrit2_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct lm95234_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(attr)->index; - long val; - int ret; - - ret = kstrtol(buf, 10, &val); - if (ret < 0) - return ret; - - val = DIV_ROUND_CLOSEST(clamp_val(val, 0, (index ? 255 : 127) * 1000), - 1000); - - ret = regmap_write(data->regmap, LM95234_REG_TCRIT2(index), val); - if (ret) - return ret; - return count; -} - -static ssize_t tcrit_hyst_show(struct lm95234_data *data, char *buf, int reg) +static int lm95234_hyst_get(struct lm95234_data *data, int reg, long *val) { u32 thyst, tcrit; int ret; @@ -212,80 +107,18 @@ static ssize_t tcrit_hyst_show(struct lm95234_data *data, char *buf, int reg) return ret; /* Result can be negative, so be careful with unsigned operands */ - return sysfs_emit(buf, "%d\n", ((int)tcrit - (int)thyst) * 1000); + *val = ((int)tcrit - (int)thyst) * 1000; + return 0; } -static ssize_t tcrit2_hyst_show(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t lm95234_hyst_set(struct lm95234_data *data, long val) { - struct lm95234_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(attr)->index; - - return tcrit_hyst_show(data, buf, LM95234_REG_TCRIT2(index)); -} - -static ssize_t tcrit1_show(struct device *dev, struct device_attribute *attr, - char *buf) -{ - struct lm95234_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(attr)->index; - int ret; - u32 val; - - ret = regmap_read(data->regmap, LM95234_REG_TCRIT1(index), &val); - if (ret) - return ret; - - return sysfs_emit(buf, "%u\n", val * 1000); -} - -static ssize_t tcrit1_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct lm95234_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(attr)->index; - long val; - int ret; - - ret = kstrtol(buf, 10, &val); - if (ret < 0) - return ret; - - val = DIV_ROUND_CLOSEST(clamp_val(val, 0, 255000), 1000); - - ret = regmap_write(data->regmap, LM95234_REG_TCRIT1(index), val); - if (ret) - return ret; - - return count; -} - -static ssize_t tcrit1_hyst_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct lm95234_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(attr)->index; - - return tcrit_hyst_show(data, buf, LM95234_REG_TCRIT1(index)); -} - -static ssize_t tcrit1_hyst_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct lm95234_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(attr)->index; u32 tcrit; - long val; int ret; - ret = kstrtol(buf, 10, &val); - if (ret < 0) - return ret; - mutex_lock(&data->update_lock); - ret = regmap_read(data->regmap, LM95234_REG_TCRIT1(index), &tcrit); + ret = regmap_read(data->regmap, LM95234_REG_TCRIT1(0), &tcrit); if (ret) goto unlock; @@ -295,188 +128,255 @@ static ssize_t tcrit1_hyst_store(struct device *dev, ret = regmap_write(data->regmap, LM95234_REG_TCRIT_HYST, val); unlock: mutex_unlock(&data->update_lock); - if (ret) - return ret; - - return count; + return ret; } -static ssize_t offset_show(struct device *dev, struct device_attribute *attr, - char *buf) +static int lm95234_crit_reg(int channel) { - struct lm95234_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(attr)->index; - u32 offset; - int ret; - - ret = regmap_read(data->regmap, LM95234_REG_OFFSET(index), &offset); - if (ret) - return ret; - - return sysfs_emit(buf, "%d\n", sign_extend32(offset, 7) * 500); + if (channel == 1 || channel == 2) + return LM95234_REG_TCRIT2(channel - 1); + return LM95234_REG_TCRIT1(channel); } -static ssize_t offset_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) +static int lm95234_temp_write(struct device *dev, u32 attr, int channel, long val) { struct lm95234_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(attr)->index; - long val; + struct regmap *regmap = data->regmap; + + switch (attr) { + case hwmon_temp_type: + if (val != 1 && val != 2) + return -EINVAL; + return regmap_update_bits(regmap, LM95234_REG_REM_MODEL, + BIT(channel), + val == 1 ? BIT(channel) : 0); + case hwmon_temp_offset: + val = DIV_ROUND_CLOSEST(clamp_val(val, -64000, 63500), 500); + return regmap_write(regmap, LM95234_REG_OFFSET(channel - 1), val); + case hwmon_temp_max: + val = clamp_val(val, 0, channel ? 255000 : 127000); + val = DIV_ROUND_CLOSEST(val, 1000); + return regmap_write(regmap, lm95234_crit_reg(channel), val); + case hwmon_temp_max_hyst: + return lm95234_hyst_set(data, val); + case hwmon_temp_crit: + val = DIV_ROUND_CLOSEST(clamp_val(val, 0, 255000), 1000); + return regmap_write(regmap, LM95234_REG_TCRIT1(channel), val); + default: + return -EOPNOTSUPP; + } + return 0; +} + +static int lm95234_alarm_reg(int channel) +{ + if (channel == 1 || channel == 2) + return LM95234_REG_STS_TCRIT2; + return LM95234_REG_STS_TCRIT1; +} + +static int lm95234_temp_read(struct device *dev, u32 attr, int channel, long *val) +{ + struct lm95234_data *data = dev_get_drvdata(dev); + struct regmap *regmap = data->regmap; + u32 regval, mask; int ret; - ret = kstrtol(buf, 10, &val); - if (ret < 0) - return ret; - - /* Accuracy is 1/2 degrees C */ - val = DIV_ROUND_CLOSEST(clamp_val(val, -64000, 63500), 500); - - ret = regmap_write(data->regmap, LM95234_REG_OFFSET(index), val); - if (ret < 0) - return ret; - - return count; + switch (attr) { + case hwmon_temp_input: + return lm95234_read_temp(regmap, channel, val); + case hwmon_temp_max_alarm: + ret = regmap_read(regmap, lm95234_alarm_reg(channel), ®val); + if (ret) + return ret; + *val = !!(regval & BIT(channel)); + break; + case hwmon_temp_crit_alarm: + ret = regmap_read(regmap, LM95234_REG_STS_TCRIT1, ®val); + if (ret) + return ret; + *val = !!(regval & BIT(channel)); + break; + case hwmon_temp_crit_hyst: + return lm95234_hyst_get(data, LM95234_REG_TCRIT1(channel), val); + case hwmon_temp_type: + ret = regmap_read(regmap, LM95234_REG_REM_MODEL, ®val); + if (ret) + return ret; + *val = (regval & BIT(channel)) ? 1 : 2; + break; + case hwmon_temp_offset: + ret = regmap_read(regmap, LM95234_REG_OFFSET(channel - 1), ®val); + if (ret) + return ret; + *val = sign_extend32(regval, 7) * 500; + break; + case hwmon_temp_fault: + ret = regmap_read(regmap, LM95234_REG_STS_FAULT, ®val); + if (ret) + return ret; + mask = (BIT(0) | BIT(1)) << ((channel - 1) << 1); + *val = !!(regval & mask); + break; + case hwmon_temp_max: + ret = regmap_read(regmap, lm95234_crit_reg(channel), ®val); + if (ret) + return ret; + *val = regval * 1000; + break; + case hwmon_temp_max_hyst: + return lm95234_hyst_get(data, lm95234_crit_reg(channel), val); + case hwmon_temp_crit: + ret = regmap_read(regmap, LM95234_REG_TCRIT1(channel), ®val); + if (ret) + return ret; + *val = regval * 1000; + break; + default: + return -EOPNOTSUPP; + } + return 0; } static u16 update_intervals[] = { 143, 364, 1000, 2500 }; -static ssize_t update_interval_show(struct device *dev, - struct device_attribute *attr, char *buf) +static int lm95234_chip_write(struct device *dev, u32 attr, long val) +{ + struct lm95234_data *data = dev_get_drvdata(dev); + + switch (attr) { + case hwmon_chip_update_interval: + val = find_closest(val, update_intervals, ARRAY_SIZE(update_intervals)); + return regmap_write(data->regmap, LM95234_REG_CONVRATE, val); + default: + return -EOPNOTSUPP; + } + return 0; +} + +static int lm95234_chip_read(struct device *dev, u32 attr, long *val) { struct lm95234_data *data = dev_get_drvdata(dev); u32 convrate; int ret; - ret = regmap_read(data->regmap, LM95234_REG_CONVRATE, &convrate); - if (ret) - return ret; + switch (attr) { + case hwmon_chip_update_interval: + ret = regmap_read(data->regmap, LM95234_REG_CONVRATE, &convrate); + if (ret) + return ret; - return sysfs_emit(buf, "%u\n", update_intervals[convrate & 0x03]); + *val = update_intervals[convrate & 0x03]; + break; + default: + return -EOPNOTSUPP; + } + return 0; } -static ssize_t update_interval_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static int lm95234_write(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long val) { - struct lm95234_data *data = dev_get_drvdata(dev); - unsigned long val; - int ret; - - ret = kstrtoul(buf, 10, &val); - if (ret < 0) - return ret; - - val = find_closest(val, update_intervals, ARRAY_SIZE(update_intervals)); - ret = regmap_write(data->regmap, LM95234_REG_CONVRATE, val); - if (ret) - return ret; - - return count; + switch (type) { + case hwmon_chip: + return lm95234_chip_write(dev, attr, val); + case hwmon_temp: + return lm95234_temp_write(dev, attr, channel, val); + default: + return -EOPNOTSUPP; + } } -static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0); -static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1); -static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2); -static SENSOR_DEVICE_ATTR_RO(temp4_input, temp, 3); -static SENSOR_DEVICE_ATTR_RO(temp5_input, temp, 4); +static int lm95234_read(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long *val) +{ + switch (type) { + case hwmon_chip: + return lm95234_chip_read(dev, attr, val); + case hwmon_temp: + return lm95234_temp_read(dev, attr, channel, val); + default: + return -EOPNOTSUPP; + } +} -static SENSOR_DEVICE_ATTR_2_RO(temp2_fault, alarm, LM95234_REG_STS_FAULT, BIT(0) | BIT(1)); -static SENSOR_DEVICE_ATTR_2_RO(temp3_fault, alarm, LM95234_REG_STS_FAULT, BIT(2) | BIT(3)); -static SENSOR_DEVICE_ATTR_2_RO(temp4_fault, alarm, LM95234_REG_STS_FAULT, BIT(4) | BIT(5)); -static SENSOR_DEVICE_ATTR_2_RO(temp5_fault, alarm, LM95234_REG_STS_FAULT, BIT(6) | BIT(7)); +static umode_t lm95234_is_visible(const void *_data, enum hwmon_sensor_types type, + u32 attr, int channel) +{ + const struct lm95234_data *data = _data; -static SENSOR_DEVICE_ATTR_RW(temp2_type, type, BIT(1)); -static SENSOR_DEVICE_ATTR_RW(temp3_type, type, BIT(2)); -static SENSOR_DEVICE_ATTR_RW(temp4_type, type, BIT(3)); -static SENSOR_DEVICE_ATTR_RW(temp5_type, type, BIT(4)); + if (data->type == lm95233 && channel > 2) + return 0; -static SENSOR_DEVICE_ATTR_RW(temp1_max, tcrit1, 0); -static SENSOR_DEVICE_ATTR_RW(temp2_max, tcrit2, 0); -static SENSOR_DEVICE_ATTR_RW(temp3_max, tcrit2, 1); -static SENSOR_DEVICE_ATTR_RW(temp4_max, tcrit1, 3); -static SENSOR_DEVICE_ATTR_RW(temp5_max, tcrit1, 4); + switch (type) { + case hwmon_chip: + switch (attr) { + case hwmon_chip_update_interval: + return 0644; + default: + break; + } + break; + case hwmon_temp: + switch (attr) { + case hwmon_temp_input: + case hwmon_temp_max_alarm: + return 0444; + case hwmon_temp_crit_alarm: + case hwmon_temp_crit_hyst: + return (channel && channel < 3) ? 0444 : 0; + case hwmon_temp_type: + case hwmon_temp_offset: + return channel ? 0644 : 0; + case hwmon_temp_fault: + return channel ? 0444 : 0; + case hwmon_temp_max: + return 0644; + case hwmon_temp_max_hyst: + return channel ? 0444 : 0644; + case hwmon_temp_crit: + return (channel && channel < 3) ? 0644 : 0; + default: + break; + } + break; + default: + break; + } + return 0; +} -static SENSOR_DEVICE_ATTR_RW(temp1_max_hyst, tcrit1_hyst, 0); -static SENSOR_DEVICE_ATTR_RO(temp2_max_hyst, tcrit2_hyst, 0); -static SENSOR_DEVICE_ATTR_RO(temp3_max_hyst, tcrit2_hyst, 1); -static SENSOR_DEVICE_ATTR_RO(temp4_max_hyst, tcrit1_hyst, 3); -static SENSOR_DEVICE_ATTR_RO(temp5_max_hyst, tcrit1_hyst, 4); - -static SENSOR_DEVICE_ATTR_2_RO(temp1_max_alarm, alarm, LM95234_REG_STS_TCRIT1, BIT(0)); -static SENSOR_DEVICE_ATTR_2_RO(temp2_max_alarm, alarm, LM95234_REG_STS_TCRIT2, BIT(1)); -static SENSOR_DEVICE_ATTR_2_RO(temp3_max_alarm, alarm, LM95234_REG_STS_TCRIT2, BIT(2)); -static SENSOR_DEVICE_ATTR_2_RO(temp4_max_alarm, alarm, LM95234_REG_STS_TCRIT1, BIT(3)); -static SENSOR_DEVICE_ATTR_2_RO(temp5_max_alarm, alarm, LM95234_REG_STS_TCRIT1, BIT(4)); - -static SENSOR_DEVICE_ATTR_RW(temp2_crit, tcrit1, 1); -static SENSOR_DEVICE_ATTR_RW(temp3_crit, tcrit1, 2); - -static SENSOR_DEVICE_ATTR_RO(temp2_crit_hyst, tcrit1_hyst, 1); -static SENSOR_DEVICE_ATTR_RO(temp3_crit_hyst, tcrit1_hyst, 2); - -static SENSOR_DEVICE_ATTR_2_RO(temp2_crit_alarm, alarm, LM95234_REG_STS_TCRIT1, BIT(1)); -static SENSOR_DEVICE_ATTR_2_RO(temp3_crit_alarm, alarm, LM95234_REG_STS_TCRIT1, BIT(2)); - -static SENSOR_DEVICE_ATTR_RW(temp2_offset, offset, 0); -static SENSOR_DEVICE_ATTR_RW(temp3_offset, offset, 1); -static SENSOR_DEVICE_ATTR_RW(temp4_offset, offset, 2); -static SENSOR_DEVICE_ATTR_RW(temp5_offset, offset, 3); - -static DEVICE_ATTR_RW(update_interval); - -static struct attribute *lm95234_common_attrs[] = { - &sensor_dev_attr_temp1_input.dev_attr.attr, - &sensor_dev_attr_temp2_input.dev_attr.attr, - &sensor_dev_attr_temp3_input.dev_attr.attr, - &sensor_dev_attr_temp2_fault.dev_attr.attr, - &sensor_dev_attr_temp3_fault.dev_attr.attr, - &sensor_dev_attr_temp2_type.dev_attr.attr, - &sensor_dev_attr_temp3_type.dev_attr.attr, - &sensor_dev_attr_temp1_max.dev_attr.attr, - &sensor_dev_attr_temp2_max.dev_attr.attr, - &sensor_dev_attr_temp3_max.dev_attr.attr, - &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, - &sensor_dev_attr_temp2_max_hyst.dev_attr.attr, - &sensor_dev_attr_temp3_max_hyst.dev_attr.attr, - &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, - &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, - &sensor_dev_attr_temp3_max_alarm.dev_attr.attr, - &sensor_dev_attr_temp2_crit.dev_attr.attr, - &sensor_dev_attr_temp3_crit.dev_attr.attr, - &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr, - &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr, - &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, - &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr, - &sensor_dev_attr_temp2_offset.dev_attr.attr, - &sensor_dev_attr_temp3_offset.dev_attr.attr, - &dev_attr_update_interval.attr, +static const struct hwmon_channel_info * const lm95234_info[] = { + HWMON_CHANNEL_INFO(chip, HWMON_C_UPDATE_INTERVAL), + HWMON_CHANNEL_INFO(temp, + HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST | + HWMON_T_MAX_ALARM, + HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST | + HWMON_T_MAX_ALARM | HWMON_T_FAULT | HWMON_T_TYPE | + HWMON_T_CRIT | HWMON_T_CRIT_HYST | + HWMON_T_CRIT_ALARM | HWMON_T_OFFSET, + HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST | + HWMON_T_MAX_ALARM | HWMON_T_FAULT | HWMON_T_TYPE | + HWMON_T_CRIT | HWMON_T_CRIT_HYST | + HWMON_T_CRIT_ALARM | HWMON_T_OFFSET, + HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST | + HWMON_T_MAX_ALARM | HWMON_T_FAULT | HWMON_T_TYPE | + HWMON_T_OFFSET, + HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST | + HWMON_T_MAX_ALARM | HWMON_T_FAULT | HWMON_T_TYPE | + HWMON_T_OFFSET), NULL }; -static const struct attribute_group lm95234_common_group = { - .attrs = lm95234_common_attrs, +static const struct hwmon_ops lm95234_hwmon_ops = { + .is_visible = lm95234_is_visible, + .read = lm95234_read, + .write = lm95234_write, }; -static struct attribute *lm95234_attrs[] = { - &sensor_dev_attr_temp4_input.dev_attr.attr, - &sensor_dev_attr_temp5_input.dev_attr.attr, - &sensor_dev_attr_temp4_fault.dev_attr.attr, - &sensor_dev_attr_temp5_fault.dev_attr.attr, - &sensor_dev_attr_temp4_type.dev_attr.attr, - &sensor_dev_attr_temp5_type.dev_attr.attr, - &sensor_dev_attr_temp4_max.dev_attr.attr, - &sensor_dev_attr_temp5_max.dev_attr.attr, - &sensor_dev_attr_temp4_max_hyst.dev_attr.attr, - &sensor_dev_attr_temp5_max_hyst.dev_attr.attr, - &sensor_dev_attr_temp4_max_alarm.dev_attr.attr, - &sensor_dev_attr_temp5_max_alarm.dev_attr.attr, - &sensor_dev_attr_temp4_offset.dev_attr.attr, - &sensor_dev_attr_temp5_offset.dev_attr.attr, - NULL -}; - -static const struct attribute_group lm95234_group = { - .attrs = lm95234_attrs, +static const struct hwmon_chip_info lm95234_chip_info = { + .ops = &lm95234_hwmon_ops, + .info = lm95234_info, }; static bool lm95234_volatile_reg(struct device *dev, unsigned int reg) @@ -606,7 +506,6 @@ static int lm95234_init_client(struct device *dev, struct regmap *regmap) static int lm95234_probe(struct i2c_client *client) { - enum chips type = (uintptr_t)i2c_get_match_data(client); struct device *dev = &client->dev; struct lm95234_data *data; struct device *hwmon_dev; @@ -617,6 +516,8 @@ static int lm95234_probe(struct i2c_client *client) if (!data) return -ENOMEM; + data->type = (uintptr_t)i2c_get_match_data(client); + regmap = devm_regmap_init_i2c(client, &lm95234_regmap_config); if (IS_ERR(regmap)) return PTR_ERR(regmap); @@ -629,12 +530,8 @@ static int lm95234_probe(struct i2c_client *client) if (err < 0) return err; - data->groups[0] = &lm95234_common_group; - if (type == lm95234) - data->groups[1] = &lm95234_group; - - hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, - data, data->groups); + hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, + data, &lm95234_chip_info, NULL); return PTR_ERR_OR_ZERO(hwmon_dev); } From patchwork Thu Jul 18 03:39:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13735987 Received: from mail-il1-f182.google.com (mail-il1-f182.google.com [209.85.166.182]) (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 1869E29CFB for ; Thu, 18 Jul 2024 03:39:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721273990; cv=none; b=EJYWyKpSaKk1VcJ8Eb4MjR96l/ZYO/Uklsst8yRUHvTOZPviKtRSYd7XzdD1gxq8+xdC8vA4PqI59yeoR04tRR4bDyn9T6Qa2av8CbWc5T9xZXKr0fza3EB3xQRslRWihmr9GfjvPHZS6IEIazAjFmMevDP8ENF20pNJ627UBKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721273990; c=relaxed/simple; bh=LQ5d9lXguP9bTKK4RlKNlY68L4o/NPa/2cSucBUXfKg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FrkEv158Dtl5hGh9EwVhxqKuKqPlFtrzw2Qr2WL9/PrVKRjtZ1re9xmU9bbJq1P2sIqApvj7TgIKolLbUR8QhAYo6a9ZJAt56iyu9huzqLXellldF9VkDV/4dkAXI0JRSE6Ygb7dt79mXIMwAS2nKVbvYDpP0ScRXPuiinnTGrA= 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=AcFuXz2X; arc=none smtp.client-ip=209.85.166.182 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="AcFuXz2X" Received: by mail-il1-f182.google.com with SMTP id e9e14a558f8ab-381f24d6bc4so1050055ab.2 for ; Wed, 17 Jul 2024 20:39:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721273987; x=1721878787; 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=g0L7pTOARV5ET+Bp4V/IgQd3bIzYDALg6WqZkmWTvDE=; b=AcFuXz2XYuULT+yzxh3JpyI/7YyeL7QHIk//79NIBQ1mL3HD+I6n+Eqp7uO0F9UcTz dLR0Pq3pJ9f0xpG9s7pyEVDbcnWVZV0s5YMPCWyJvNWBpgJQBtU12M5t8SQ4hWsKAYNy b1yy6adXLW1P87K5Ekew/BLT9GpQeX93ARDsqoLsSq6lMbQhg2oXtKOLoX4LszCe9bt+ HTtRwlnWzFOe9e+CbrETqUXUjLU+vvTDtj4hDq78vgX9DC6yps2GgvCcPwjlMadbCJgc aDerMcWgPo9lJxfiynHKtYY8XJzijvb0jnnwk3dMbXWELDy1bAgqvpTQgNC6caTjJLGj CZCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721273987; x=1721878787; 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=g0L7pTOARV5ET+Bp4V/IgQd3bIzYDALg6WqZkmWTvDE=; b=DLYk2bTUp9fPcUJLXmaDdBMKGWSaY2i7qHWN9VjFO3pu4C1IQbGv/DnUpPs0kVf3KT WWa7DdQ9DOssM5u/D2UsGo8yvervDVfpwjyfYckDiwtsB3k0XqlQiUzSQnBqas96E85H jXGBdtPDyYkhTfom23igjcaaX1HXwW7zM7GIedSVpqW32k1wndGGgdYLh2jbciLAT083 1CO3qx52LSy4VT2EBfK/fzTMZaG8hwF+2jwasJ6eZ9CeBgb5MHPvEDOScVLJW+OQstJ8 7Tzz6+9uNaNEg59j8KxLj860yFZ9vlxnH6BAWiV72w/sS3UwNDj7qpavrRqO6In0U88B iPXA== X-Gm-Message-State: AOJu0Yw6TV4JlD2SeaMI760duuTFGyCi5YrPDlKXnyQUYshGK7E/2Ahf Oz4FJm/kDV3dvQ7nXshthZUBh6IRTR1UXSLJdeCX5PT1vXf+2oFQJSF2zw== X-Google-Smtp-Source: AGHT+IFNEXDG6KQAyxWex8tWsZ7/5RL7WxmJmyDpGJvJEabuVf9iuduJ5ho9pXNGzt1EmQROIikmjg== X-Received: by 2002:a05:6e02:1e0c:b0:375:e93b:7c8c with SMTP id e9e14a558f8ab-39555613f3amr49927755ab.12.1721273987326; Wed, 17 Jul 2024 20:39:47 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70b7ec7d2a1sm8940983b3a.123.2024.07.17.20.39.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 20:39:46 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 5/6] hwmon: (lm95234) Add support for tempX_enable attribute Date: Wed, 17 Jul 2024 20:39:34 -0700 Message-Id: <20240718033935.205185-6-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240718033935.205185-1-linux@roeck-us.net> References: <20240718033935.205185-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 LM95233/LM95234 support enabling temperature channels one by one. Add support for tempX_enable attribute to be able to use that functionality. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/lm95234.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/lm95234.c b/drivers/hwmon/lm95234.c index 1a164f47fb3e..f0df1134f811 100644 --- a/drivers/hwmon/lm95234.c +++ b/drivers/hwmon/lm95234.c @@ -144,6 +144,11 @@ static int lm95234_temp_write(struct device *dev, u32 attr, int channel, long va struct regmap *regmap = data->regmap; switch (attr) { + case hwmon_temp_enable: + if (val && val != 1) + return -EINVAL; + return regmap_update_bits(regmap, LM95234_REG_ENABLE, + BIT(channel), val ? BIT(channel) : 0); case hwmon_temp_type: if (val != 1 && val != 2) return -EINVAL; @@ -183,6 +188,12 @@ static int lm95234_temp_read(struct device *dev, u32 attr, int channel, long *va int ret; switch (attr) { + case hwmon_temp_enable: + ret = regmap_read(regmap, LM95234_REG_ENABLE, ®val); + if (ret) + return ret; + *val = !!(regval & BIT(channel)); + break; case hwmon_temp_input: return lm95234_read_temp(regmap, channel, val); case hwmon_temp_max_alarm: @@ -331,6 +342,7 @@ static umode_t lm95234_is_visible(const void *_data, enum hwmon_sensor_types typ case hwmon_temp_fault: return channel ? 0444 : 0; case hwmon_temp_max: + case hwmon_temp_enable: return 0644; case hwmon_temp_max_hyst: return channel ? 0444 : 0644; @@ -350,21 +362,21 @@ static const struct hwmon_channel_info * const lm95234_info[] = { HWMON_CHANNEL_INFO(chip, HWMON_C_UPDATE_INTERVAL), HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST | - HWMON_T_MAX_ALARM, + HWMON_T_MAX_ALARM | HWMON_T_ENABLE, HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_MAX_ALARM | HWMON_T_FAULT | HWMON_T_TYPE | HWMON_T_CRIT | HWMON_T_CRIT_HYST | - HWMON_T_CRIT_ALARM | HWMON_T_OFFSET, + HWMON_T_CRIT_ALARM | HWMON_T_OFFSET | HWMON_T_ENABLE, HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_MAX_ALARM | HWMON_T_FAULT | HWMON_T_TYPE | HWMON_T_CRIT | HWMON_T_CRIT_HYST | - HWMON_T_CRIT_ALARM | HWMON_T_OFFSET, + HWMON_T_CRIT_ALARM | HWMON_T_OFFSET | HWMON_T_ENABLE, HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_MAX_ALARM | HWMON_T_FAULT | HWMON_T_TYPE | - HWMON_T_OFFSET, + HWMON_T_OFFSET | HWMON_T_ENABLE, HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST | HWMON_T_MAX_ALARM | HWMON_T_FAULT | HWMON_T_TYPE | - HWMON_T_OFFSET), + HWMON_T_OFFSET | HWMON_T_ENABLE), NULL }; From patchwork Thu Jul 18 03:39:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13735988 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (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 59722376EC for ; Thu, 18 Jul 2024 03:39:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721273991; cv=none; b=bWBCXEP0gKGHRFsrkROXGi5XTgEbgQMTpZKXNtteydmQs5dN3zUSV15+9R42Ov4IGK30ukxcgvRRABbSGMQSnsTUfH3JM4jiVRIFDslCOGG0KmknLLYJ+5pEuRUFyd1KwToYlB/evF0OeD1n0xISo23xxNFbC+rXUrgHLwfMAHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721273991; c=relaxed/simple; bh=ZSUKnyPagFPXGvQh5AWOfjDC/CyVQKLPsGjkfl+fpbM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=h8uXi7gCL4WmkNhEZGsU8Drf0B8AchY5orx/pX6AtYiL22DkruXbNqewfkFylqa7lohQbMdEMZ4wmhqnjkyNLqpYhXPa4Skrj21JeGmqaUgC8s0ODpUxwqtEGkUTBkw1/w33/AKxMPLBJB+J696KPiuuCOdAJu6OgmjKlSoAr+s= 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=ESw6Pvwb; arc=none smtp.client-ip=209.85.215.177 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="ESw6Pvwb" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-6e7e23b42c3so165475a12.1 for ; Wed, 17 Jul 2024 20:39:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721273989; x=1721878789; 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=2FwDj35630PyXblV66255RUUtmvKovzhDSAYap7udCQ=; b=ESw6PvwbtAeC81nVaGDNOOCS86Q2Rz2JFcKMkYDv9gUIHJtccbRfjrewh4s3Pkb4yo 3PvMU89gGCseZ9nBPnf4Krzq7flPxJXbaAq2//8T/r/DR4olFgFbd73rrOFvijdErqpU ImCk6QRfjx8di6a0sxuSU+2NQmMJvGyMwniDxRp+F3OMA4O//axw/OBYcc6ixadXQS5J Otu7i5wUbpQgatwjEGkCHtd3Jxd4/04VQiAl/pa5YRmHQCLWsplRKLevPM18QpKAZQ2x thjqaMv/ljvhRIlIjWphle4CaumNVLTimdMbP+krtRo4c3IKgzx2gzuJnSjJuaeP7rpL /+Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721273989; x=1721878789; 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=2FwDj35630PyXblV66255RUUtmvKovzhDSAYap7udCQ=; b=BAjT3qQoaM3nTLwWqWAyxsg8mp9XC6kk+uAfOsO/6tlqQ5sWOJc65jvoSpFvh/uW9B 9IhPOVL0aU4VaRu/v8ODZTj4YHySjjR6NcKbi9lEIq8d+yG3uYRWoPglK1JKRupQqnp1 n/Lqo2FcifV8PD+IFx0jFQPD08KBoyRAjY6+6e/3YY+3bAq08runOavI3SgjZwWSfjIm pY1uUkhlRpy2G4/CAaez6MazzyN/e0/idPiCcpXfXRdKxo+Jy867MGji2CqquUrFhIwX 5zS3Qgi0Zfv3Fc3/0LKc7kXjnhzaxPWrWptIWTWomP2vcm+Xz7MfliK/mfwQqaPJyu51 ip3Q== X-Gm-Message-State: AOJu0YwCswwbiwh5WElBMIaMSKupU6WujsOpNAV+Qk4p3VpUYOU6JCSy LC1ZFjQo9tsVi5fa7AUDXlYIXLalsND/W2BC4KudmSYZCUGyHgzH4nSciA== X-Google-Smtp-Source: AGHT+IHqsb8El+N0+M0yJhkr82Q3pReNuwDkrJfRxWEjQO/ozVDX34UyaMGrDKHKn50wySGZeLozpQ== X-Received: by 2002:a05:6a20:748a:b0:1c0:ef1c:b80 with SMTP id adf61e73a8af0-1c3fdd781d6mr4393360637.52.1721273988976; Wed, 17 Jul 2024 20:39:48 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cb6017b923sm733216a91.43.2024.07.17.20.39.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 20:39:48 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 6/6] hwmon: (lm95234) Use multi-byte regmap operations Date: Wed, 17 Jul 2024 20:39:35 -0700 Message-Id: <20240718033935.205185-7-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240718033935.205185-1-linux@roeck-us.net> References: <20240718033935.205185-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 to simplify the code and to reduce dependency on locking. No functional change. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/lm95234.c | 45 +++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/drivers/hwmon/lm95234.c b/drivers/hwmon/lm95234.c index f0df1134f811..c3c68c196479 100644 --- a/drivers/hwmon/lm95234.c +++ b/drivers/hwmon/lm95234.c @@ -60,54 +60,45 @@ struct lm95234_data { static int lm95234_read_temp(struct regmap *regmap, int index, long *t) { + unsigned int regs[2]; int temp = 0, ret; - u32 val; + u8 regvals[2]; if (index) { - ret = regmap_read(regmap, LM95234_REG_UTEMPH(index - 1), &val); + regs[0] = LM95234_REG_UTEMPH(index - 1); + regs[1] = LM95234_REG_UTEMPL(index - 1); + ret = regmap_multi_reg_read(regmap, regs, regvals, 2); if (ret) return ret; - temp = val << 8; - ret = regmap_read(regmap, LM95234_REG_UTEMPL(index - 1), &val); - if (ret) - return ret; - temp |= val; + temp = (regvals[0] << 8) | regvals[1]; } /* * Read signed temperature if unsigned temperature is 0, * or if this is the local sensor. */ if (!temp) { - ret = regmap_read(regmap, LM95234_REG_TEMPH(index), &val); + regs[0] = LM95234_REG_TEMPH(index); + regs[1] = LM95234_REG_TEMPL(index); + ret = regmap_multi_reg_read(regmap, regs, regvals, 2); if (ret) return ret; - temp = val << 8; - ret = regmap_read(regmap, LM95234_REG_TEMPL(index), &val); - if (ret) - return ret; - temp = sign_extend32(temp | val, 15); + temp = (regvals[0] << 8) | regvals[1]; + temp = sign_extend32(temp, 15); } *t = DIV_ROUND_CLOSEST(temp * 125, 32); return 0; } -static int lm95234_hyst_get(struct lm95234_data *data, int reg, long *val) +static int lm95234_hyst_get(struct regmap *regmap, int reg, long *val) { - u32 thyst, tcrit; + unsigned int regs[2] = {reg, LM95234_REG_TCRIT_HYST}; + u8 regvals[2]; int ret; - mutex_lock(&data->update_lock); - ret = regmap_read(data->regmap, reg, &tcrit); - if (ret) - goto unlock; - ret = regmap_read(data->regmap, LM95234_REG_TCRIT_HYST, &thyst); -unlock: - mutex_unlock(&data->update_lock); + ret = regmap_multi_reg_read(regmap, regs, regvals, 2); if (ret) return ret; - - /* Result can be negative, so be careful with unsigned operands */ - *val = ((int)tcrit - (int)thyst) * 1000; + *val = (regvals[0] - regvals[1]) * 1000; return 0; } @@ -209,7 +200,7 @@ static int lm95234_temp_read(struct device *dev, u32 attr, int channel, long *va *val = !!(regval & BIT(channel)); break; case hwmon_temp_crit_hyst: - return lm95234_hyst_get(data, LM95234_REG_TCRIT1(channel), val); + return lm95234_hyst_get(regmap, LM95234_REG_TCRIT1(channel), val); case hwmon_temp_type: ret = regmap_read(regmap, LM95234_REG_REM_MODEL, ®val); if (ret) @@ -236,7 +227,7 @@ static int lm95234_temp_read(struct device *dev, u32 attr, int channel, long *va *val = regval * 1000; break; case hwmon_temp_max_hyst: - return lm95234_hyst_get(data, lm95234_crit_reg(channel), val); + return lm95234_hyst_get(regmap, lm95234_crit_reg(channel), val); case hwmon_temp_crit: ret = regmap_read(regmap, LM95234_REG_TCRIT1(channel), ®val); if (ret)