From patchwork Sat Jul 27 14:38:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13743748 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 429AA17E8F0 for ; Sat, 27 Jul 2024 14:38:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722091110; cv=none; b=GSyS1v1PuncdAh7s4ij13LsaVhSJse5J0KFsqfeeEpWdVHmD0TBwimN0/3Zq8BGuQvfPEc7NaIWQ4FU9/0xtjrkcZvzsZNxYHNV7CSc3tfjvtGPQrFIF1tSq2zD9TMYSFmPBm4gZcc7Gd+z0uWe+Xuf37CluYo6PJwHTJLgTUqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722091110; c=relaxed/simple; bh=1GderYZUYa1fLCggFyIitxpPq2weN1rhRHUmWaHAO4o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Yk9bjOfLHu5ySYeSKYyVps53cFAOawQG3oTfikuU3GXEc8GnO4HuqUBev3NxXXDkrcj16vX26ruFs12s1+6/0uapKrk0B36mcM+mk3RB+BO31VXcF9+XgjIR6ye/CP7ytFhl/ZTG3W5mET/qAso7wlk2hYLj7D/hqTvVsD+oHLw= 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=Sg+9AclF; arc=none smtp.client-ip=209.85.216.47 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="Sg+9AclF" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2cb5787b4a5so1263235a91.2 for ; Sat, 27 Jul 2024 07:38:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722091107; x=1722695907; 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=/zVshvsVtHrjbqy8l31EBw8xCXGzitW1cD53mRc0Lcw=; b=Sg+9AclF7j7Z9p/ZkxUZX67u/37Q2cAZjeVloDAYW1UPVZbqU0sCZKvAQARq2pK8Tg ardpcACGlsc66tKTVey2ixm9jO4xgFbsCtCvNn4S1rmSr+a1JZ/Il08XONpYHQhFPcAF qLcHjx6hQiVUQMfC8Gt87ROQEm4QYN+Cq/vwXQ/QvCs/U0gofzUrGQAZhU1orVXNe2r1 XuP9OOcNr4+mxG9z0N3b3S4BABPyWPsAhOOtoWxjGiWU2sNcUuZBMk47XlYcXvyhVSDy 2qYnyOLqeeliSsL4V0WHiXWdqY5Zy3Btr2ISXoKN3NcGMOJSbTPvTRnbb4CCcPPCgOLF 7Xjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722091107; x=1722695907; 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=/zVshvsVtHrjbqy8l31EBw8xCXGzitW1cD53mRc0Lcw=; b=Ia3vXvRxml4uufb5j6uegHlhtFzp0tYPIIL8puWnniNXs6r5wVA1XP5M1hwbdvvpVb SgOfzYgeSq8J3sEOTY8vGGYCSSzIcaKhOZDCNH6ej0Sm53cP4J5VW6em2DXQa1BQzPyV oq3VXntr8wsQ4crhO/hVWWrvdyhAt+V+05n3iEFXQu5jqms58orS4wEbw2uVitRnQGlw VLLF0YyVuwXBrZyB4VO5Dg/sppKlOce5X00IA44mCyW/MbxGkh5hdu4qvv0zhGw48+K5 wKzyTEH7FkwdgsXIGPWnaiLJglvOVM3Y/6D+aNOB6OT7VhzhqyWeE0emPeRpnosUSibr al5g== X-Gm-Message-State: AOJu0YzLHwwMDGpYO9Od00LCAg+vyDVa4YlbvEM+ElR0Qgkh5FP5yxOY nI6sQqah8tiK6qaIpJ4iUXbckp+6d/AvnsGC/bxaQCdVScPrTPZGou9f7g== X-Google-Smtp-Source: AGHT+IEkIVQeLGV4Bpnt0NeAgJ+mNVQMFEvF+ns0vcwRkg093NP4JemOg5u4UkEFC9EV6NQiWD2NLw== X-Received: by 2002:a17:90a:ab93:b0:2c4:dc63:96d7 with SMTP id 98e67ed59e1d1-2cf7e71c28fmr2254121a91.41.1722091106630; Sat, 27 Jul 2024 07:38:26 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cdb760e6absm7323986a91.55.2024.07.27.07.38.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jul 2024 07:38:25 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 1/6] hwmon: (max1619) Clamp temperature range when writing limits Date: Sat, 27 Jul 2024 07:38:15 -0700 Message-Id: <20240727143820.1358225-2-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240727143820.1358225-1-linux@roeck-us.net> References: <20240727143820.1358225-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 Module test code reports underflows when writing sensor limits. temp2_min: Suspected underflow: [min=-77000, read 101000, written -2147483648] temp2_max: Suspected underflow: [min=-77000, read 101000, written -2147483648] temp2_crit: Suspected underflow: [min=-77000, read 101000, written -2147483648] Clamp temperature ranges when writing limits to fix the problem. While at it, use sign_extend32() when reading temperatures to make the code easier to understand. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/max1619.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c index a89a519cf5d9..464f4c838394 100644 --- a/drivers/hwmon/max1619.c +++ b/drivers/hwmon/max1619.c @@ -52,16 +52,6 @@ static const unsigned short normal_i2c[] = { * Conversions */ -static int temp_from_reg(int val) -{ - return (val & 0x80 ? val-0x100 : val) * 1000; -} - -static int temp_to_reg(int val) -{ - return (val < 0 ? val+0x100*1000 : val) / 1000; -} - enum temp_index { t_input1 = 0, t_input2, @@ -142,7 +132,7 @@ static ssize_t temp_show(struct device *dev, struct device_attribute *devattr, struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct max1619_data *data = max1619_update_device(dev); - return sprintf(buf, "%d\n", temp_from_reg(data->temp[attr->index])); + return sprintf(buf, "%d\n", sign_extend(data->temp[attr->index], 7) * 1000); } static ssize_t temp_store(struct device *dev, @@ -158,7 +148,7 @@ static ssize_t temp_store(struct device *dev, return err; mutex_lock(&data->update_lock); - data->temp[attr->index] = temp_to_reg(val); + data->temp[attr->index] = DIV_ROUND_CLOSEST(clamp_val(val, -128000, 127000), 1000); i2c_smbus_write_byte_data(client, regs_write[attr->index], data->temp[attr->index]); mutex_unlock(&data->update_lock); From patchwork Sat Jul 27 14:38:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13743749 Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (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 C094717E90A for ; Sat, 27 Jul 2024 14:38:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722091111; cv=none; b=rtGxv3RlRRobiJAXsCFUeM9W1hp3dFuK30WhhQG/oKy3ghaD3i8aLRZlTxuGPjhIs4FZlSuhY6O103Xaw4dZ3slpVBrO7K0kbP+dGm0LoXAaJvn2glArpX7FbQWM83JHFE8OJAsQMZUeN49rQGyDE2TVn5dGs/xhRJGSpjgb3Vo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722091111; c=relaxed/simple; bh=Mm2GoKyBQDGqsY/Q1kmZEvCefXYvb6EdKF8s5hgCBRE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CyeqvdZwyPT5qvUEv1PJRuLs5vVOQNNftLBpK1G7uFAhzR8QuhbfW/rh/n+IeT0TzpCtHUDq9VuzBXsDkA68GTL49nQamGO+7GaYyairH4Chnf9IGI692oAA3oDpG5JJQ2a6jqd+ndQ1dsm3XrX6ncFOxcMDo9FXWzCoJV48bVo= 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=e3LuWdlP; arc=none smtp.client-ip=209.85.210.48 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="e3LuWdlP" Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-70942ebcc29so352947a34.0 for ; Sat, 27 Jul 2024 07:38:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722091108; x=1722695908; 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=tyb/h9fq2J1X3JG/8j30Z/QFEsnqq4g5IsDaX+MAsBc=; b=e3LuWdlPx/HWbVnkZO2F6vr2r/mK38vwcBvxUlejbU/GoFqMcfDJgm2rSAFeqwe4xB uiYEPMVCaUVQSbigpOe3brENrR3UfB4gXe1ljv7+1GLgAdBxIpLJtngbcmd4HwRP5VEc 76vn1U7sDOdcYtUS5Tw+L+pSDgCTK7K+totNqCvmloCwDuDdSgfOQxlTnMdQ/MluiLPo ajzDMB9P25y03TI/JH/FAVI7WlyX9m6RITfnSQfOmRMyHIPfjY73hIcnt2YVaU4HlVuX 7tnp84CWpdIZ6ASbnuRSMzwtQnb/y636ysZDrPI7Wym0AUErLoPEzrizltK2w+G1jhaI BUDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722091108; x=1722695908; 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=tyb/h9fq2J1X3JG/8j30Z/QFEsnqq4g5IsDaX+MAsBc=; b=WKwanrj5sBRh6zzbE+mKNrYOWFR9lzPYcfnPltrnWDtBBmvMiJHVr/Y3TSR/qftrxU 3A9Gfl5cWWaVFCtqxyeyp/vFNQjZ1VgimUv2tVf0aZjw5IGosXlJkfBlXJiLiFOWR4bF uC1wBHgxGZ3FYZ5rcOvaBOtYeRa2aJtXEsFZzlpaPwML7UBoPDjBNx5rEFtpU11hjgl6 X135EguGCkfU4BF483Ew6r8sMa0etx94Cra6Nb5suikZXgda56OtVkGN+hrhBvIKMywT f/FMUmJtNO4j+jd4nk6Y+9LyqSLrJd2cMy1HVRsywiKeC+GMNv/1stIyQHjTlWz8ndLA CphQ== X-Gm-Message-State: AOJu0YxXmp1spNAsAQfTigb0FsNZqz041gNfrb/c+5ALDi/CNyUO1lWz OhZg2fr/TrCjEtAcBNJcfpglVX3DJXIu4Wgx8S487v3Ytfjnuxwr/SaCFw== X-Google-Smtp-Source: AGHT+IGL9a++hMMkFF5pfIZHaVgx/mpaEfaQznPxjEJYbBLhPYmc+zNnPKfV9T2sVZ+3GxmofTClPA== X-Received: by 2002:a05:6830:6519:b0:703:6a59:b52b with SMTP id 46e09a7af769-70940c054f6mr3284094a34.3.1722091108323; Sat, 27 Jul 2024 07:38:28 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28c7f7b0sm5378876a91.23.2024.07.27.07.38.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jul 2024 07:38:27 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 2/6] hwmon: (max1619) Reorder include files to alphabetic order Date: Sat, 27 Jul 2024 07:38:16 -0700 Message-Id: <20240727143820.1358225-3-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240727143820.1358225-1-linux@roeck-us.net> References: <20240727143820.1358225-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 Simplify maintenance by reordering include files to alphabetic order. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/max1619.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c index 464f4c838394..8eb7d04bd2f5 100644 --- a/drivers/hwmon/max1619.c +++ b/drivers/hwmon/max1619.c @@ -12,15 +12,15 @@ * http://pdfserv.maxim-ic.com/en/ds/MAX1619.pdf */ -#include -#include -#include -#include -#include +#include #include #include -#include +#include +#include +#include +#include #include +#include #include static const unsigned short normal_i2c[] = { From patchwork Sat Jul 27 14:38:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13743750 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 B6EB217F36E for ; Sat, 27 Jul 2024 14:38:31 +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=1722091113; cv=none; b=hVRoCrVomb4cQztKnK6/VNFnKLksn1zgPGsUaBpUp3YoCIJUEKotUbqLywfYZyZQgw+kkPcahawabQTnloIgHUfnpswKYY+be+xCDXKHRlHN3xV25wl0yyQTMHSh8muCYZeC0qB8VcjLUqnLunzHakHjZ2UxKJD/JWdfcar0euw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722091113; c=relaxed/simple; bh=O/X38hbHx6ZEK2bwgUH9Z+vJe2jG2lZDuVqAd+J07mM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bxQ14RVaCV05y+WxWCMSr0QnlcoW7k+hULxUba5jT8laIRL6bo/cN6uxloafpi4nVT1coiprjzSFPZpXvj0WGJVpfrkbCtVrVRzBqh45pGakgEhwvo4QXmAi3Yw0+IqCImJsznwyr+mq69bIrtkuDPdZUZKJF92AT57zKdMLw9Y= 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=BzU74Rvv; 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="BzU74Rvv" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-2cb56c2c30eso1236820a91.1 for ; Sat, 27 Jul 2024 07:38:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722091110; x=1722695910; 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=iRhsUCWHS2j6LGPP/IvPRK3jkh5v5yvL4Ij3H2Wzhfs=; b=BzU74Rvv6XUnzPjTwFa4hfjG22z2zJJfTcqGQOLeXkSKWRvwhRRuiNQlpdbNJQ0oaP /ClhgTMmJ3+umNUzUGZjxSYxDJzUSXCEiIA0pXBUXI60RJa5bb5kJnxhdvGh9oS0CVcN WvqVuFnSS+hxGl6tvNIlTo4WHbBGSyeryidsdOeaCiSMLY5Y18V69VCrvKQ1RMSSOomN Qkea7MgwA/D2NAyTmYOCktzX246oIR5FeHDHyk1G1NDig3uPII8Xpau1eExoElh13Sfp y77BtULdlG2ifb4hgIn7rCt3nyUSleuGIDAC/ejkQBqxKmFw3UqUj0JJ5wICZM58lIUj RV5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722091110; x=1722695910; 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=iRhsUCWHS2j6LGPP/IvPRK3jkh5v5yvL4Ij3H2Wzhfs=; b=KnhhWshLLSLJsQ5n8EKwh8nD6OPNlklF8Tv+GsuhMxe7rA+XNwoh8E2Za5voRlKvH/ o23dY424vuBhM0kCLMfFXJ4B7zxffm7ONL/PqYvCHHJWb6ODzrl+32CVao570OQ6pIeR QE11C+QGyOraFKa75ri2k0OHmeO56A/LY1mXBhTDjXaoUaqjWltfnUwCpuQa9git47CB 1Kcw6WELGGU5MkCPIYEHyV55qd5tLte/6GU4lirbfKB95oDmXdyEw28l9bg2+KqWMg2z SgvOdlaTk79kLAluY/vzu9CxaF5MAWcg5pA9wS//CYTACDkyu5NeAEWWerpShWZGmcIK 0z+Q== X-Gm-Message-State: AOJu0YxgRgHur81f0lsHkZntrBzFGLadvbcWyWEPUWrbK3PeJl8W+DkQ SCpQ6JSH+Inqq9tXTfKu4F3xG9UafsiMdUHPHRuVgapUimlgfG8jAEKH9w== X-Google-Smtp-Source: AGHT+IHYIJSqwgCKC6tsOE95NiSW9v63nQSubJcnEhynJwkz4QNX+ErQtkP5Z+MJAAug88CHvhi7ww== X-Received: by 2002:a17:90a:8586:b0:2c7:c5f5:1c72 with SMTP id 98e67ed59e1d1-2cf7cedd529mr4386100a91.13.1722091109944; Sat, 27 Jul 2024 07:38:29 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28dfb6e4sm5289722a91.37.2024.07.27.07.38.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jul 2024 07:38:29 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 3/6] hwmon: (max1619) Convert to use regmap Date: Sat, 27 Jul 2024 07:38:17 -0700 Message-Id: <20240727143820.1358225-4-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240727143820.1358225-1-linux@roeck-us.net> References: <20240727143820.1358225-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 for local caching, to hide register read/write address differences, and for multi-byte operations. With this change, the driver specific lock is no longer necessary. Signed-off-by: Guenter Roeck --- Documentation/hwmon/max1619.rst | 4 - drivers/hwmon/max1619.c | 245 ++++++++++++++++---------------- 2 files changed, 122 insertions(+), 127 deletions(-) diff --git a/Documentation/hwmon/max1619.rst b/Documentation/hwmon/max1619.rst index e25956e70f73..b5fc175ae18d 100644 --- a/Documentation/hwmon/max1619.rst +++ b/Documentation/hwmon/max1619.rst @@ -27,7 +27,3 @@ All temperature values are given in degrees Celsius. Resolution is 1.0 degree for the local temperature and for the remote temperature. Only the external sensor has high and low limits. - -The max1619 driver will not update its values more frequently than every -other second; reading them more often will do no harm, but will return -'old' values. diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c index 8eb7d04bd2f5..ae0ea4156f24 100644 --- a/drivers/hwmon/max1619.c +++ b/drivers/hwmon/max1619.c @@ -17,10 +17,8 @@ #include #include #include -#include #include -#include -#include +#include #include static const unsigned short normal_i2c[] = { @@ -30,27 +28,17 @@ static const unsigned short normal_i2c[] = { * The MAX1619 registers */ -#define MAX1619_REG_R_MAN_ID 0xFE -#define MAX1619_REG_R_CHIP_ID 0xFF -#define MAX1619_REG_R_CONFIG 0x03 -#define MAX1619_REG_W_CONFIG 0x09 -#define MAX1619_REG_R_CONVRATE 0x04 -#define MAX1619_REG_W_CONVRATE 0x0A -#define MAX1619_REG_R_STATUS 0x02 -#define MAX1619_REG_R_LOCAL_TEMP 0x00 -#define MAX1619_REG_R_REMOTE_TEMP 0x01 -#define MAX1619_REG_R_REMOTE_HIGH 0x07 -#define MAX1619_REG_W_REMOTE_HIGH 0x0D -#define MAX1619_REG_R_REMOTE_LOW 0x08 -#define MAX1619_REG_W_REMOTE_LOW 0x0E -#define MAX1619_REG_R_REMOTE_CRIT 0x10 -#define MAX1619_REG_W_REMOTE_CRIT 0x12 -#define MAX1619_REG_R_TCRIT_HYST 0x11 -#define MAX1619_REG_W_TCRIT_HYST 0x13 - -/* - * Conversions - */ +#define MAX1619_REG_LOCAL_TEMP 0x00 +#define MAX1619_REG_REMOTE_TEMP 0x01 +#define MAX1619_REG_STATUS 0x02 +#define MAX1619_REG_CONFIG 0x03 +#define MAX1619_REG_CONVRATE 0x04 +#define MAX1619_REG_REMOTE_HIGH 0x07 +#define MAX1619_REG_REMOTE_LOW 0x08 +#define MAX1619_REG_REMOTE_CRIT 0x10 +#define MAX1619_REG_REMOTE_CRIT_HYST 0x11 +#define MAX1619_REG_MAN_ID 0xFE +#define MAX1619_REG_CHIP_ID 0xFF enum temp_index { t_input1 = 0, @@ -66,62 +54,15 @@ enum temp_index { * Client data (each client gets its own) */ -struct max1619_data { - struct i2c_client *client; - struct mutex update_lock; - bool valid; /* false until following fields are valid */ - unsigned long last_updated; /* in jiffies */ - - /* registers values */ - u8 temp[t_num_regs]; /* index with enum temp_index */ - u8 alarms; +static const u8 regs[t_num_regs] = { + [t_input1] = MAX1619_REG_LOCAL_TEMP, + [t_input2] = MAX1619_REG_REMOTE_TEMP, + [t_low2] = MAX1619_REG_REMOTE_LOW, + [t_high2] = MAX1619_REG_REMOTE_HIGH, + [t_crit2] = MAX1619_REG_REMOTE_CRIT, + [t_hyst2] = MAX1619_REG_REMOTE_CRIT_HYST, }; -static const u8 regs_read[t_num_regs] = { - [t_input1] = MAX1619_REG_R_LOCAL_TEMP, - [t_input2] = MAX1619_REG_R_REMOTE_TEMP, - [t_low2] = MAX1619_REG_R_REMOTE_LOW, - [t_high2] = MAX1619_REG_R_REMOTE_HIGH, - [t_crit2] = MAX1619_REG_R_REMOTE_CRIT, - [t_hyst2] = MAX1619_REG_R_TCRIT_HYST, -}; - -static const u8 regs_write[t_num_regs] = { - [t_low2] = MAX1619_REG_W_REMOTE_LOW, - [t_high2] = MAX1619_REG_W_REMOTE_HIGH, - [t_crit2] = MAX1619_REG_W_REMOTE_CRIT, - [t_hyst2] = MAX1619_REG_W_TCRIT_HYST, -}; - -static struct max1619_data *max1619_update_device(struct device *dev) -{ - struct max1619_data *data = dev_get_drvdata(dev); - struct i2c_client *client = data->client; - int config, i; - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { - dev_dbg(&client->dev, "Updating max1619 data.\n"); - for (i = 0; i < t_num_regs; i++) - data->temp[i] = i2c_smbus_read_byte_data(client, - regs_read[i]); - data->alarms = i2c_smbus_read_byte_data(client, - MAX1619_REG_R_STATUS); - /* If OVERT polarity is low, reverse alarm bit */ - config = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CONFIG); - if (!(config & 0x20)) - data->alarms ^= 0x02; - - data->last_updated = jiffies; - data->valid = true; - } - - mutex_unlock(&data->update_lock); - - return data; -} - /* * Sysfs stuff */ @@ -130,9 +71,15 @@ static ssize_t temp_show(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct max1619_data *data = max1619_update_device(dev); + struct regmap *regmap = dev_get_drvdata(dev); + u32 temp; + int ret; - return sprintf(buf, "%d\n", sign_extend(data->temp[attr->index], 7) * 1000); + ret = regmap_read(regmap, regs[attr->index], &temp); + if (ret < 0) + return ret; + + return sprintf(buf, "%d\n", sign_extend32(temp, 7) * 1000); } static ssize_t temp_store(struct device *dev, @@ -140,34 +87,61 @@ static ssize_t temp_store(struct device *dev, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct max1619_data *data = dev_get_drvdata(dev); - struct i2c_client *client = data->client; + struct regmap *regmap = dev_get_drvdata(dev); long val; int err = kstrtol(buf, 10, &val); if (err) return err; - mutex_lock(&data->update_lock); - data->temp[attr->index] = DIV_ROUND_CLOSEST(clamp_val(val, -128000, 127000), 1000); - i2c_smbus_write_byte_data(client, regs_write[attr->index], - data->temp[attr->index]); - mutex_unlock(&data->update_lock); + val = DIV_ROUND_CLOSEST(clamp_val(val, -128000, 127000), 1000); + err = regmap_write(regmap, regs[attr->index], val); + if (err < 0) + return err; return count; } +static int get_alarms(struct regmap *regmap) +{ + static u32 regs[2] = { MAX1619_REG_STATUS, MAX1619_REG_CONFIG }; + u8 regdata[2]; + int ret; + + ret = regmap_multi_reg_read(regmap, regs, regdata, 2); + if (ret) + return ret; + + /* OVERT status bit may be reversed */ + if (!(regdata[1] & 0x20)) + regdata[0] ^= 0x02; + + return regdata[0] & 0x1e; +} + static ssize_t alarms_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct max1619_data *data = max1619_update_device(dev); - return sprintf(buf, "%d\n", data->alarms); + struct regmap *regmap = dev_get_drvdata(dev); + int alarms; + + alarms = get_alarms(regmap); + if (alarms < 0) + return alarms; + + return sprintf(buf, "%d\n", alarms); } static ssize_t alarm_show(struct device *dev, struct device_attribute *attr, char *buf) { int bitnr = to_sensor_dev_attr(attr)->index; - struct max1619_data *data = max1619_update_device(dev); - return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); + struct regmap *regmap = dev_get_drvdata(dev); + int alarms; + + alarms = get_alarms(regmap); + if (alarms < 0) + return alarms; + + return sprintf(buf, "%d\n", (alarms >> bitnr) & 1); } static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, t_input1); @@ -211,9 +185,9 @@ static int max1619_detect(struct i2c_client *client, return -ENODEV; /* detection */ - reg_config = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CONFIG); - reg_convrate = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CONVRATE); - reg_status = i2c_smbus_read_byte_data(client, MAX1619_REG_R_STATUS); + reg_config = i2c_smbus_read_byte_data(client, MAX1619_REG_CONFIG); + reg_convrate = i2c_smbus_read_byte_data(client, MAX1619_REG_CONVRATE); + reg_status = i2c_smbus_read_byte_data(client, MAX1619_REG_STATUS); if ((reg_config & 0x03) != 0x00 || reg_convrate > 0x07 || (reg_status & 0x61) != 0x00) { dev_dbg(&adapter->dev, "MAX1619 detection failed at 0x%02x\n", @@ -222,8 +196,8 @@ static int max1619_detect(struct i2c_client *client, } /* identification */ - man_id = i2c_smbus_read_byte_data(client, MAX1619_REG_R_MAN_ID); - chip_id = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CHIP_ID); + man_id = i2c_smbus_read_byte_data(client, MAX1619_REG_MAN_ID); + chip_id = i2c_smbus_read_byte_data(client, MAX1619_REG_CHIP_ID); if (man_id != 0x4D || chip_id != 0x04) { dev_info(&adapter->dev, "Unsupported chip (man_id=0x%02X, chip_id=0x%02X).\n", @@ -236,40 +210,65 @@ static int max1619_detect(struct i2c_client *client, return 0; } -static void max1619_init_client(struct i2c_client *client) -{ - u8 config; +/* regmap */ - /* - * Start the conversions. - */ - i2c_smbus_write_byte_data(client, MAX1619_REG_W_CONVRATE, - 5); /* 2 Hz */ - config = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CONFIG); - if (config & 0x40) - i2c_smbus_write_byte_data(client, MAX1619_REG_W_CONFIG, - config & 0xBF); /* run */ +static int max1619_reg_read(void *context, unsigned int reg, unsigned int *val) +{ + int ret; + + ret = i2c_smbus_read_byte_data(context, reg); + if (ret < 0) + return ret; + + *val = ret; + return 0; } -static int max1619_probe(struct i2c_client *new_client) +static int max1619_reg_write(void *context, unsigned int reg, unsigned int val) { - struct max1619_data *data; + int offset = reg < MAX1619_REG_REMOTE_CRIT ? 6 : 2; + + return i2c_smbus_write_byte_data(context, reg + offset, val); +} + +static bool max1619_regmap_is_volatile(struct device *dev, unsigned int reg) +{ + return reg <= MAX1619_REG_STATUS; +} + +static bool max1619_regmap_is_writeable(struct device *dev, unsigned int reg) +{ + return reg > MAX1619_REG_STATUS && reg <= MAX1619_REG_REMOTE_CRIT_HYST; +} + +static const struct regmap_config max1619_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX1619_REG_REMOTE_CRIT_HYST, + .cache_type = REGCACHE_MAPLE, + .volatile_reg = max1619_regmap_is_volatile, + .writeable_reg = max1619_regmap_is_writeable, +}; + +static const struct regmap_bus max1619_regmap_bus = { + .reg_write = max1619_reg_write, + .reg_read = max1619_reg_read, +}; + +static int max1619_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; struct device *hwmon_dev; + struct regmap *regmap; - data = devm_kzalloc(&new_client->dev, sizeof(struct max1619_data), - GFP_KERNEL); - if (!data) - return -ENOMEM; + regmap = devm_regmap_init(dev, &max1619_regmap_bus, client, + &max1619_regmap_config); + if (IS_ERR(regmap)) + return PTR_ERR(regmap); - data->client = new_client; - mutex_init(&data->update_lock); - - /* Initialize the MAX1619 chip */ - max1619_init_client(new_client); - - hwmon_dev = devm_hwmon_device_register_with_groups(&new_client->dev, - new_client->name, - data, + hwmon_dev = devm_hwmon_device_register_with_groups(dev, + client->name, + regmap, max1619_groups); return PTR_ERR_OR_ZERO(hwmon_dev); } From patchwork Sat Jul 27 14:38:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13743751 Received: from mail-oa1-f44.google.com (mail-oa1-f44.google.com [209.85.160.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 45E6617F390 for ; Sat, 27 Jul 2024 14:38:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722091115; cv=none; b=nHpXPWD9eOj2gRPuquEnDo6fKE+g4Lx/+3b3Gx4IcXFYaPy8mwY1tPUBT5BDh6T3/Oigrpk3KuWXkSmnjHBDt2N7F+0xiqzkpcgQOLK1Dmy6bEXXkL37c/af695ocUHI5O5C4NJcU0ULdoWG7wBmTOO1QFyTGvbSGq0AePdtN3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722091115; c=relaxed/simple; bh=2vh+IfNdb1HanU4TFhjxLPXOAvwiT/PchKUFR4Sgdqs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qPt4BG/0+prJEtGC8GD/vmHJI//M6Tc9l9I5nda/uOCFkuPl8LH/wYWFzbYUrOcFNGG73oqcord44JTFapNez69N3ff7DZeN79Kb+ebKLY/cRM66ZEpT1YkyBvluHK5JwGcxh+QdZWxqnXupg17BNruCJ6tT+52VNUxLbgR1tio= 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=R1CG0URJ; arc=none smtp.client-ip=209.85.160.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="R1CG0URJ" Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-25d634c5907so1359888fac.2 for ; Sat, 27 Jul 2024 07:38:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722091112; x=1722695912; 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=oqBblu+xmxP9/L9U7NykNaXSEChfy7uv80jYd0PlnX8=; b=R1CG0URJScxfrkdhk4JgildrIlG9tkTf6NHzNpBvRSnh3dcDegSgmZRnVf7UIYMV7Z GyKgxxHPba0oR1dt8o54oTpw2JMkCZRnhl24Xkjoc1X0J4n32+aYDz7rUA2Vr3eqrqjj /3kXS/Bq5wfnHRJRFFQI16eh4mPg9XALik0ZCPsIU5Xj8WLEQSqsoWpdSMFygZhxMiP5 dwADRio0e0onuJ4z+RL+/gWzXsCKd2bH723/i6V8bPYiW1zsYo2hiC7O4WyTN/Ta2WIS ivny8R+GMX2qtjN7RHGOMkNZRaN71NrGClXcKBS4wgXnjsnGuYKlGlgKLqfUX0gXsf4u wIIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722091112; x=1722695912; 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=oqBblu+xmxP9/L9U7NykNaXSEChfy7uv80jYd0PlnX8=; b=LU1ohzx0IizUdTfy/fg8NyoNWEAm31p9RqLmMmKbXF+j4yS5qRJTzpNXP0GYyDcRrz rTXkVMLbOibrt8L6b9UKt4uW9nicNNJi0wjK/D6+S8UTPwoA45QR063U3wve0Ft+8/k2 xsI+w2VTUThrXR2K4CyORd+D1YiTHuXsgdEtcIOk8EF0WCoAfkPcFh5Hv9IGkblgyFGy Yd6Pj8S/3dxR7yn68YFtpX3T6jSQY2vyAcAcchUmxW0K5DClTC7xv0FBHqPZ1cCWMksI l4xGpcPvst5eeZyn5ByCbZXxK5cKJxv0aAbnwFr5hryJu3d+8pz866G2ag1Vpemc+TW4 hwIw== X-Gm-Message-State: AOJu0Yy8kGlGhNVyE35FP7EQF8Vfz0GFKj9CVPzc7YCLNXEVbF2jZlGC eQMsmFwSWSUii/6L+OorAP9UlJUAldoy99R6UcljPFD/DJrikYB0aq2qcA== X-Google-Smtp-Source: AGHT+IHRIb+2rJllw/PoRmAOuS1DYXYRDpwOPXQsmL44PGCkIDPVfVdMbzzAQAAQyeIhhkYAjZ48tw== X-Received: by 2002:a05:6870:8a11:b0:261:ff6:7496 with SMTP id 586e51a60fabf-267d4ee606amr3500735fac.40.1722091111728; Sat, 27 Jul 2024 07:38:31 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead7156c8sm4240754b3a.83.2024.07.27.07.38.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jul 2024 07:38:31 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 4/6] hwmon: (max1619) Convert to with_info API Date: Sat, 27 Jul 2024 07:38:18 -0700 Message-Id: <20240727143820.1358225-5-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240727143820.1358225-1-linux@roeck-us.net> References: <20240727143820.1358225-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 driver to with_info hwmon API to simplify the code and with it its maintainability. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/max1619.c | 269 +++++++++++++++++++++++----------------- 1 file changed, 157 insertions(+), 112 deletions(-) diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c index ae0ea4156f24..966fe650aa59 100644 --- a/drivers/hwmon/max1619.c +++ b/drivers/hwmon/max1619.c @@ -14,20 +14,14 @@ #include #include -#include #include #include #include #include -#include static const unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; -/* - * The MAX1619 registers - */ - #define MAX1619_REG_LOCAL_TEMP 0x00 #define MAX1619_REG_REMOTE_TEMP 0x01 #define MAX1619_REG_STATUS 0x02 @@ -40,66 +34,6 @@ static const unsigned short normal_i2c[] = { #define MAX1619_REG_MAN_ID 0xFE #define MAX1619_REG_CHIP_ID 0xFF -enum temp_index { - t_input1 = 0, - t_input2, - t_low2, - t_high2, - t_crit2, - t_hyst2, - t_num_regs -}; - -/* - * Client data (each client gets its own) - */ - -static const u8 regs[t_num_regs] = { - [t_input1] = MAX1619_REG_LOCAL_TEMP, - [t_input2] = MAX1619_REG_REMOTE_TEMP, - [t_low2] = MAX1619_REG_REMOTE_LOW, - [t_high2] = MAX1619_REG_REMOTE_HIGH, - [t_crit2] = MAX1619_REG_REMOTE_CRIT, - [t_hyst2] = MAX1619_REG_REMOTE_CRIT_HYST, -}; - -/* - * Sysfs stuff - */ - -static ssize_t temp_show(struct device *dev, struct device_attribute *devattr, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct regmap *regmap = dev_get_drvdata(dev); - u32 temp; - int ret; - - ret = regmap_read(regmap, regs[attr->index], &temp); - if (ret < 0) - return ret; - - return sprintf(buf, "%d\n", sign_extend32(temp, 7) * 1000); -} - -static ssize_t temp_store(struct device *dev, - struct device_attribute *devattr, const char *buf, - size_t count) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct regmap *regmap = dev_get_drvdata(dev); - long val; - int err = kstrtol(buf, 10, &val); - if (err) - return err; - - val = DIV_ROUND_CLOSEST(clamp_val(val, -128000, 127000), 1000); - err = regmap_write(regmap, regs[attr->index], val); - if (err < 0) - return err; - return count; -} - static int get_alarms(struct regmap *regmap) { static u32 regs[2] = { MAX1619_REG_STATUS, MAX1619_REG_CONFIG }; @@ -117,62 +51,175 @@ static int get_alarms(struct regmap *regmap) return regdata[0] & 0x1e; } -static ssize_t alarms_show(struct device *dev, struct device_attribute *attr, - char *buf) +static int max1619_temp_read(struct regmap *regmap, u32 attr, int channel, long *val) { - struct regmap *regmap = dev_get_drvdata(dev); - int alarms; + int reg = -1, alarm_bit = 0; + u32 temp; + int ret; - alarms = get_alarms(regmap); - if (alarms < 0) - return alarms; - - return sprintf(buf, "%d\n", alarms); + switch (attr) { + case hwmon_temp_input: + reg = channel ? MAX1619_REG_REMOTE_TEMP : MAX1619_REG_LOCAL_TEMP; + break; + case hwmon_temp_min: + reg = MAX1619_REG_REMOTE_LOW; + break; + case hwmon_temp_max: + reg = MAX1619_REG_REMOTE_HIGH; + break; + case hwmon_temp_crit: + reg = MAX1619_REG_REMOTE_CRIT; + break; + case hwmon_temp_crit_hyst: + reg = MAX1619_REG_REMOTE_CRIT_HYST; + break; + case hwmon_temp_min_alarm: + alarm_bit = 3; + break; + case hwmon_temp_max_alarm: + alarm_bit = 4; + break; + case hwmon_temp_crit_alarm: + alarm_bit = 1; + break; + case hwmon_temp_fault: + alarm_bit = 2; + break; + default: + return -EOPNOTSUPP; + } + if (reg >= 0) { + ret = regmap_read(regmap, reg, &temp); + if (ret < 0) + return ret; + *val = sign_extend32(temp, 7) * 1000; + } else { + ret = get_alarms(regmap); + if (ret < 0) + return ret; + *val = !!(ret & BIT(alarm_bit)); + } + return 0; } -static ssize_t alarm_show(struct device *dev, struct device_attribute *attr, - char *buf) +static int max1619_chip_read(struct regmap *regmap, u32 attr, long *val) { - int bitnr = to_sensor_dev_attr(attr)->index; - struct regmap *regmap = dev_get_drvdata(dev); int alarms; - alarms = get_alarms(regmap); - if (alarms < 0) - return alarms; - - return sprintf(buf, "%d\n", (alarms >> bitnr) & 1); + switch (attr) { + case hwmon_chip_alarms: + alarms = get_alarms(regmap); + if (alarms < 0) + return alarms; + *val = alarms; + break; + default: + return -EOPNOTSUPP; + } + return 0; } -static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, t_input1); -static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, t_input2); -static SENSOR_DEVICE_ATTR_RW(temp2_min, temp, t_low2); -static SENSOR_DEVICE_ATTR_RW(temp2_max, temp, t_high2); -static SENSOR_DEVICE_ATTR_RW(temp2_crit, temp, t_crit2); -static SENSOR_DEVICE_ATTR_RW(temp2_crit_hyst, temp, t_hyst2); +static int max1619_read(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long *val) +{ + struct regmap *regmap = dev_get_drvdata(dev); -static DEVICE_ATTR_RO(alarms); -static SENSOR_DEVICE_ATTR_RO(temp2_crit_alarm, alarm, 1); -static SENSOR_DEVICE_ATTR_RO(temp2_fault, alarm, 2); -static SENSOR_DEVICE_ATTR_RO(temp2_min_alarm, alarm, 3); -static SENSOR_DEVICE_ATTR_RO(temp2_max_alarm, alarm, 4); + switch (type) { + case hwmon_chip: + return max1619_chip_read(regmap, attr, val); + case hwmon_temp: + return max1619_temp_read(regmap, attr, channel, val); + default: + return -EOPNOTSUPP; + } +} -static struct attribute *max1619_attrs[] = { - &sensor_dev_attr_temp1_input.dev_attr.attr, - &sensor_dev_attr_temp2_input.dev_attr.attr, - &sensor_dev_attr_temp2_min.dev_attr.attr, - &sensor_dev_attr_temp2_max.dev_attr.attr, - &sensor_dev_attr_temp2_crit.dev_attr.attr, - &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr, +static int max1619_write(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long val) +{ + struct regmap *regmap = dev_get_drvdata(dev); + int reg; - &dev_attr_alarms.attr, - &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, - &sensor_dev_attr_temp2_fault.dev_attr.attr, - &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, - &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, + if (type != hwmon_temp) + return -EOPNOTSUPP; + + switch (attr) { + case hwmon_temp_min: + reg = MAX1619_REG_REMOTE_LOW; + break; + case hwmon_temp_max: + reg = MAX1619_REG_REMOTE_HIGH; + break; + case hwmon_temp_crit: + reg = MAX1619_REG_REMOTE_CRIT; + break; + case hwmon_temp_crit_hyst: + reg = MAX1619_REG_REMOTE_CRIT_HYST; + break; + default: + return -EOPNOTSUPP; + } + val = DIV_ROUND_CLOSEST(clamp_val(val, -128000, 127000), 1000); + return regmap_write(regmap, reg, val); +} + +static umode_t max1619_is_visible(const void *_data, enum hwmon_sensor_types type, + u32 attr, int channel) +{ + switch (type) { + case hwmon_chip: + switch (attr) { + case hwmon_chip_alarms: + return 0444; + default: + break; + } + break; + case hwmon_temp: + switch (attr) { + case hwmon_temp_input: + return 0444; + case hwmon_temp_min: + case hwmon_temp_max: + case hwmon_temp_crit: + case hwmon_temp_crit_hyst: + return 0644; + case hwmon_temp_min_alarm: + case hwmon_temp_max_alarm: + case hwmon_temp_crit_alarm: + case hwmon_temp_fault: + return 0444; + default: + break; + } + break; + default: + break; + } + return 0; +} + +static const struct hwmon_channel_info * const max1619_info[] = { + HWMON_CHANNEL_INFO(chip, HWMON_C_ALARMS), + HWMON_CHANNEL_INFO(temp, + HWMON_T_INPUT, + HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | + HWMON_T_CRIT | HWMON_T_CRIT_HYST | + HWMON_T_MIN_ALARM | HWMON_T_MAX_ALARM | + HWMON_T_CRIT_ALARM | HWMON_T_FAULT), NULL }; -ATTRIBUTE_GROUPS(max1619); + +static const struct hwmon_ops max1619_hwmon_ops = { + .is_visible = max1619_is_visible, + .read = max1619_read, + .write = max1619_write, +}; + +static const struct hwmon_chip_info max1619_chip_info = { + .ops = &max1619_hwmon_ops, + .info = max1619_info, +}; /* Return 0 if detection is successful, -ENODEV otherwise */ static int max1619_detect(struct i2c_client *client, @@ -266,10 +313,8 @@ static int max1619_probe(struct i2c_client *client) if (IS_ERR(regmap)) return PTR_ERR(regmap); - hwmon_dev = devm_hwmon_device_register_with_groups(dev, - client->name, - regmap, - max1619_groups); + hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, + regmap, &max1619_chip_info, NULL); return PTR_ERR_OR_ZERO(hwmon_dev); } From patchwork Sat Jul 27 14:38:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13743752 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 8E86317F4E7 for ; Sat, 27 Jul 2024 14:38:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722091116; cv=none; b=TZjWb4uGcA+VzVC+KrLQ7ii/erxKtkL9rMxO3OYFsJrAfISizpBZ/GFhXY17n13av9FFbYcK9l8W2P9A4nfzC+Uofzb5OVjOEZIe2o7AXq/YdesTU3lxd9OVD3knagU1ocuOBjgUUa1GVNrG26B2VZ6Mi6fIRQ5uifFhaeeog7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722091116; c=relaxed/simple; bh=P9oZ68LneqTkxD52x28dXbNSxuL0oRl4hl0x7QpyVEc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oLuBFZ8C9jJvXKus7BzqHVwhHhUS7ztBIG+NZu0eq9TfauhO7QAY1+HS74BVYYQYPS/X+8RFqrkBki9xt7v6dgIyNQ2q8XA5+OxVWQ0VTmkb1ZBPjM2KW1jIPPe8XSwImBf8n/z5/Erxddr8lakf9ubSIZdpUXz15PKfdQNR3PA= 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=QaPxl9cF; arc=none smtp.client-ip=209.85.214.171 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="QaPxl9cF" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1fc4fccdd78so11768815ad.2 for ; Sat, 27 Jul 2024 07:38:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722091113; x=1722695913; 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=rgP4eqX8nQMm7kPlYFEnUJf4BHxvfPBYpZaKMJ8sc3g=; b=QaPxl9cFk59Zst5mex2EvCMGBvt0B8Cq6RfXrvBi26R7V/kNHs33Ddh/xZr4VPTCyM Jf9sqUZCTOSaOa9kuJ8+wf63lk8/2WzYcN8rsWsTTB9fJgEOyh5eCfZ7BZYkLeRWtTHy GIPmQSkDEQwCNve2veOA8ci5ioWppYGeq7lKv21PTiQyd/zQAxFJ09aWwuGQm4aI19Am ev3xrfw6SqSXZ0t17kxa8BIJkgN7QVLVNQzA1yyfP0yssSmxC5l7g/27YeWTzV7JxA1y 60+EbCtem+NS4ApPgErhvrV3Aid3r1e10WSPv37/d1Ipikvw44QhgaDtfXOITPRqwFGk oDAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722091113; x=1722695913; 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=rgP4eqX8nQMm7kPlYFEnUJf4BHxvfPBYpZaKMJ8sc3g=; b=PNAwkQ6EFXi7i1Xo+tbDZFZfVaPMc+Em9GkfTpQmZhG9NaDRSWuvvqH5hrTKG93Krl izKciPQympfKre0CbUcoRJ3MBamIQxJIpaRAonaExKk+aXRORuYBnFVoeLTljJ7fuCGN uKU6CzpqZA+I207tzFkgCX3Cf/VHgQ+qYugvfaW5IMN2QAyGAardqffSyK9gTPj4WVyR LBCrfChB1T4rdlfmS/vbOUlVTwmM8e8Zk6A55Dkox768ECpfNOujI+94Zd7b4jdOsqxK SxQLM0YzjMt2IuHIFKkeowf5ABFRWb92kR+ZoMwPe5gTV13xREPNP083dJLZvO20AAS4 6Bzw== X-Gm-Message-State: AOJu0YzRxXxoZaExPpWUfCdY/VcOKaxQld0EcB+TkpCes4sZF6mNkI9X w608r7MQoMBwBIgeGNbYwo1ex+Hrr2OyeRbhsHz170+3evo/QIjAfZcp8w== X-Google-Smtp-Source: AGHT+IFFVlfYIaALMCa9EgcPBwv4f2+faksMDySfpSB98W77nflVlpJrz/GGxyZdXatlEAJt6QRHRg== X-Received: by 2002:a17:902:8208:b0:1fd:9269:72c6 with SMTP id d9443c01a7336-1ff04950890mr22758165ad.62.1722091113411; Sat, 27 Jul 2024 07:38:33 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7edd813sm51477515ad.170.2024.07.27.07.38.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jul 2024 07:38:32 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 5/6] hwmon: (max1619) Add support for update_interval attribute Date: Sat, 27 Jul 2024 07:38:19 -0700 Message-Id: <20240727143820.1358225-6-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240727143820.1358225-1-linux@roeck-us.net> References: <20240727143820.1358225-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 The chip supports reading and writing the conversion rate. Add support for the update_interval sysfs attribute. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/max1619.c | 50 ++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c index 966fe650aa59..40f0726e9f22 100644 --- a/drivers/hwmon/max1619.c +++ b/drivers/hwmon/max1619.c @@ -18,6 +18,7 @@ #include #include #include +#include static const unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; @@ -102,11 +103,20 @@ static int max1619_temp_read(struct regmap *regmap, u32 attr, int channel, long return 0; } +static u16 update_intervals[] = { 16000, 8000, 4000, 2000, 1000, 500, 250, 125 }; + static int max1619_chip_read(struct regmap *regmap, u32 attr, long *val) { - int alarms; + int alarms, ret; + u32 regval; switch (attr) { + case hwmon_chip_update_interval: + ret = regmap_read(regmap, MAX1619_REG_CONVRATE, ®val); + if (ret < 0) + return ret; + *val = update_intervals[regval & 7]; + break; case hwmon_chip_alarms: alarms = get_alarms(regmap); if (alarms < 0) @@ -134,14 +144,21 @@ static int max1619_read(struct device *dev, enum hwmon_sensor_types type, } } -static int max1619_write(struct device *dev, enum hwmon_sensor_types type, - u32 attr, int channel, long val) +static int max1619_chip_write(struct regmap *regmap, u32 attr, long val) { - struct regmap *regmap = dev_get_drvdata(dev); - int reg; - - if (type != hwmon_temp) + switch (attr) { + case hwmon_chip_update_interval: + val = find_closest_descending(val, update_intervals, ARRAY_SIZE(update_intervals)); + return regmap_write(regmap, MAX1619_REG_CONVRATE, val); + default: return -EOPNOTSUPP; + } +} + +static int max1619_temp_write(struct regmap *regmap, + u32 attr, int channel, long val) +{ + int reg; switch (attr) { case hwmon_temp_min: @@ -163,12 +180,29 @@ static int max1619_write(struct device *dev, enum hwmon_sensor_types type, return regmap_write(regmap, reg, val); } +static int max1619_write(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long val) +{ + struct regmap *regmap = dev_get_drvdata(dev); + + switch (type) { + case hwmon_chip: + return max1619_chip_write(regmap, attr, val); + case hwmon_temp: + return max1619_temp_write(regmap, attr, channel, val); + default: + return -EOPNOTSUPP; + } +} + static umode_t max1619_is_visible(const void *_data, enum hwmon_sensor_types type, u32 attr, int channel) { switch (type) { case hwmon_chip: switch (attr) { + case hwmon_chip_update_interval: + return 0644; case hwmon_chip_alarms: return 0444; default: @@ -200,7 +234,7 @@ static umode_t max1619_is_visible(const void *_data, enum hwmon_sensor_types typ } static const struct hwmon_channel_info * const max1619_info[] = { - HWMON_CHANNEL_INFO(chip, HWMON_C_ALARMS), + HWMON_CHANNEL_INFO(chip, HWMON_C_ALARMS | HWMON_C_UPDATE_INTERVAL), HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT, HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | From patchwork Sat Jul 27 14:38: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: 13743753 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 5D92717F4FA for ; Sat, 27 Jul 2024 14:38:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722091117; cv=none; b=MgQsfDhC+oAcJtLOdy7pBqrGPf2P63W+2HPz3iN1Z3QS0eBR4xocG3mRr0iXGqpa6uwYMuBewpw/aHKg9IEFttgIlQlzxZPyDnpfbK+kaN+mk4uVI6uEfhbMKo5McSSs9FUY6Zy2BIXNvg0F5t+qQ67oLhqeo97/fck+22TPMJQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722091117; c=relaxed/simple; bh=RSvztWsFC8r+hApjT51Ztdy0YP6vZiSrufocsnKTE8I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RE468sYfSkFaNUrH8SImPnFh8axcH7z/fjm8WBqC50FA2I0e4rpGG74ZS24bockfS988TrgmEdfgYOOJ4Gw1NXzOzhh3SCCazek12a/3drL3zTa8kEdxWE50tUYUXHcOXjaf+zNr6/NFYGryBxYHWnXl1c8wqMDPPwUSxz6wG0A= 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=DRy0B71/; arc=none smtp.client-ip=209.85.210.178 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="DRy0B71/" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-70b703eda27so1220336b3a.3 for ; Sat, 27 Jul 2024 07:38:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722091115; x=1722695915; 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=ftpkBdMptxPsjLxu2uLiHpkSFlQTD+VnwsJlH+CgPTg=; b=DRy0B71/IRxI26WHSXNJfc8TEPKYddoIkymTdQLfgeWBmSCqAjAHA8uYxziZJ3Ztl8 Zf/Kk+4Onf21Ilf2nPb0wl0D0y9hhVkTBmlba1OZgYAcVScMVJPNqZVM3vOoKjY4T35W ILRWBJkja/FPlU9balntC9l34Xr0jXI0f19LpShkr9Fn96hKi0gKxj1GI1I5pNWppG2A 4SuGXVMdlMeMC8Ic70Zdrfhy2bDtQ0CK7Gc08g6Ye26wykeSNSGpiqExOhbXqeRwitXV hI3P5q/7vxTwXVAo4rjrbcc7LfHTeWYJcJbpTYuGFoyc+SAzExe4tvz9itMhC9dIe9rG l0Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722091115; x=1722695915; 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=ftpkBdMptxPsjLxu2uLiHpkSFlQTD+VnwsJlH+CgPTg=; b=GpA6AjnxtBwtZIkD/3UTP7j8+XvWI7uQmMBDyf3R39FYcW1e8nVrdU+VStP3f5fV7p hSAeqFLyhPB0seFUUH56l3Nst5NAdESceV2ERoW7nBlcDO/cmi8HPO/NiLq0ZkcyzjIt Y3fuZXmBa8g9b/zC2PI0PiIPhnPuPe6vtJk4ELI0lWaFulvnRH+fd6j/PE3Xb2eCOm2c Ud3KsplrIuGX0vJQMdn+3ltIosyyYY8ZH97zXkjyXonmk//YzFTtIh0Rip7lv4hlEaF2 /PtlzHgBeBVRFlbPrTOofXXKtPLH+dV9eGFXQgk6JgHYsJUu7ptWVGt7J/Q1zGoFzApW iNnw== X-Gm-Message-State: AOJu0YwPsKkCYB7TAD7/Hn3cOAdao6FnyvUwsMVKbItIrdCm9goRXx3+ h0J95Tu6wDHqN4Ingdrm/kvnRuKaaUIN8ltRmckTkIBeO9/18Z9U0tGFkg== X-Google-Smtp-Source: AGHT+IHu7g3McASfrvoZSL2Pjv4HpXHtBi2s5lJup9tEVFNLORduHtIxwdIKVDZN05tdvijHSD+jsA== X-Received: by 2002:a05:6a00:4651:b0:706:34f3:7b60 with SMTP id d2e1a72fcca58-70eceda1d57mr2381409b3a.23.1722091115081; Sat, 27 Jul 2024 07:38:35 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead8a3a86sm4221091b3a.205.2024.07.27.07.38.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jul 2024 07:38:34 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 6/6] hwmon: (max1619) Improve chip detection code Date: Sat, 27 Jul 2024 07:38:20 -0700 Message-Id: <20240727143820.1358225-7-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240727143820.1358225-1-linux@roeck-us.net> References: <20240727143820.1358225-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 Bail out immediately if reading any of the registers used for chip detection fails, or if it returns an unexpected value. Drop all log messages from detection code. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/max1619.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c index 40f0726e9f22..9cbca17f27a5 100644 --- a/drivers/hwmon/max1619.c +++ b/drivers/hwmon/max1619.c @@ -260,31 +260,27 @@ static int max1619_detect(struct i2c_client *client, struct i2c_board_info *info) { struct i2c_adapter *adapter = client->adapter; - u8 reg_config, reg_convrate, reg_status, man_id, chip_id; + int regval; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -ENODEV; - /* detection */ - reg_config = i2c_smbus_read_byte_data(client, MAX1619_REG_CONFIG); - reg_convrate = i2c_smbus_read_byte_data(client, MAX1619_REG_CONVRATE); - reg_status = i2c_smbus_read_byte_data(client, MAX1619_REG_STATUS); - if ((reg_config & 0x03) != 0x00 - || reg_convrate > 0x07 || (reg_status & 0x61) != 0x00) { - dev_dbg(&adapter->dev, "MAX1619 detection failed at 0x%02x\n", - client->addr); + regval = i2c_smbus_read_byte_data(client, MAX1619_REG_CONFIG); + if (regval < 0 || (regval & 0x03)) + return -ENODEV; + regval = i2c_smbus_read_byte_data(client, MAX1619_REG_CONVRATE); + if (regval < 0 || regval > 0x07) + return -ENODEV; + regval = i2c_smbus_read_byte_data(client, MAX1619_REG_STATUS); + if (regval < 0 || (regval & 0x61)) return -ENODEV; - } - /* identification */ - man_id = i2c_smbus_read_byte_data(client, MAX1619_REG_MAN_ID); - chip_id = i2c_smbus_read_byte_data(client, MAX1619_REG_CHIP_ID); - if (man_id != 0x4D || chip_id != 0x04) { - dev_info(&adapter->dev, - "Unsupported chip (man_id=0x%02X, chip_id=0x%02X).\n", - man_id, chip_id); + regval = i2c_smbus_read_byte_data(client, MAX1619_REG_MAN_ID); + if (regval != 0x4d) + return -ENODEV; + regval = i2c_smbus_read_byte_data(client, MAX1619_REG_CHIP_ID); + if (regval != 0x04) return -ENODEV; - } strscpy(info->type, "max1619", I2C_NAME_SIZE);