From patchwork Fri Jul 26 00:43:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13742344 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.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 84866628 for ; Fri, 26 Jul 2024 00:43:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721954617; cv=none; b=AZvIh32rnUXTWR8zP9ZLDHVmcbnC2m2NwLDUm4KLrAN4Rhnymuf1rv2BFfb9mMFN4lxWYsT4PyLtB9wmVBM+lJnC8sEJmXHgUGM8Upej5I2SodHQJ+COCf8LyjXPuEl9YNbbWohBZx85oZigA74MRQDtJQSbuYT55o9vRgAB8S8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721954617; c=relaxed/simple; bh=z+nCM/m+QxunRt/e4sGwKV/6GJ+qaUgh8zcNkvi/mn8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tWxukXI3Q3if1g0bH03MtayDGiqgQBbp61nk1SDcXLdKykzSdwhE8tfLcW1JZkcWv+Md4p8mfZa9AUW/jTU3cDJwycTT1XJrFJgl9i7Vt+t+g1L/RtTfuhDyLCZwozpsNFyvmyExMnbyWwplbE3FU0pUIjb5KqaRPBFgWf8Smi8= 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=MbOaSI37; arc=none smtp.client-ip=209.85.210.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="MbOaSI37" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-70d199fb3dfso403913b3a.3 for ; Thu, 25 Jul 2024 17:43:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721954614; x=1722559414; 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=YZ3EaG/4CXd4QBVocifml96MCTY/RdzDlPE18sv8YM8=; b=MbOaSI37f34e1GP+oH2xXmDzEAJHU+7KzSJ2P4yrfqVuautMRc3xwqt4fY7I6d9kaE RWMGEC73T5WLqDanU+m6ijfkq4h5HTX27g1GkZttQ8c+gGAx7Fl0Hdr3tjrhlo95rtFk avShAUui2kA9NLnrHv+gKBqCes6NebTqREoN3afFkocAS3B/gi8HEzW/lgVEWsSpoB2Y tyfnVphFhelT6T2axaWEjXCS415O+A5eBCqdQsdWBkOL8EikAXwft66VtLe2thuR0ol4 8Qar1fGFxHmpvrTHE2bKOV36/hmKt5EZ9KIGlTMejZcbaHY6osphGtIbkHA21nNmPGmH fAHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721954614; x=1722559414; 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=YZ3EaG/4CXd4QBVocifml96MCTY/RdzDlPE18sv8YM8=; b=KT78ABxpZpNpKHF95ll1Wc02ZD4cckb0gwy7GYwzddE5p1bLVPL5ueLBrsN7RVHuS7 4TAFhMeWfSlvvo7iv5yOSD8NqQ01SwKrPaGT1NlPiH5i0qIW1btjwrm16ReIlhV7xyEf n5zR0e0Trd9WRyJhXYEku26F82o5czsDG05ntgkb1MRe8HRL2OZoCyMtgH7SncOGRhDz fD7k+UH6QQwNovtgG0LGje58IrM+xQ3OmM0mQ4upYBY22UaJq88J2zjpbO4BkidH2CXW 8AranWNUc4rEyPWO1kr2migdr4jt9aXhS++0Xt4fJrkibK4byiVl46A/Y0YSH60T/cIR mkbg== X-Gm-Message-State: AOJu0YwpUbm++JN2sxtdiGvQUaqTbTtDMpncYvTcR9x0rwpk0Oz1mlms og6cJhgC6DP1imlaxxlPYse9oL6DDW25yon2hjvx1XNljS/HtQnOcpDsgg== X-Google-Smtp-Source: AGHT+IFpTa26e2HjP5DbMRWC3je8H8RqQIxAXMHTX2p6674ZnhjtzbN8/Zuj0msyh96OGeLqTYPOEA== X-Received: by 2002:a05:6a21:a4c1:b0:1c4:8bba:76e9 with SMTP id adf61e73a8af0-1c48bbaac17mr1200630637.53.1721954614265; Thu, 25 Jul 2024 17:43:34 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7f3efdcsm20154535ad.217.2024.07.25.17.43.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 17:43:33 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 1/5] hwmon: (max1668) Reorder include files to alphabetic order Date: Thu, 25 Jul 2024 17:43:25 -0700 Message-Id: <20240726004329.934763-2-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240726004329.934763-1-linux@roeck-us.net> References: <20240726004329.934763-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 Reorder include files to alphabetic order to simplify driver maintenance. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/max1668.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/max1668.c b/drivers/hwmon/max1668.c index 9fc583ebb11b..f5b5cc29da17 100644 --- a/drivers/hwmon/max1668.c +++ b/drivers/hwmon/max1668.c @@ -6,15 +6,15 @@ * some credit to Christoph Scheurer, but largely a rewrite */ -#include -#include -#include -#include -#include +#include #include #include -#include +#include +#include +#include +#include #include +#include /* Addresses to scan */ static const unsigned short max1668_addr_list[] = { From patchwork Fri Jul 26 00:43:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13742345 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 12E3E7F8 for ; Fri, 26 Jul 2024 00:43:36 +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=1721954618; cv=none; b=mRtItePmBCDMs9VgkIApQAg9DkhEETuuFAxqHtz82+2TEbx9bA3eJOpdBBvkN9TKcUw6iGLgVWDj91yDBub8lKFOMmwqGgCjb+sSgzOsJpsnNpHDJQ7rlZTXp9scE7kawKDFcExqAqz2neoAhfIYfO9Apf/gt0fYKXpH5J9QIWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721954618; c=relaxed/simple; bh=oYH1gMvwELeH8/rKH2A6V0cP+kzRmMeuv2nYfoJ1G5Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SS6/fexEuUcT9ISNTiCNxt7pmJzyWjtno2C73ELh7PqnUpFhqEyCG+8RMNkSmM6etza6RdWfsKMysEDXHoDleny/19FE+DKJhp24Mn5YLIrryBsDJVs8nwbtPA3HNRZtRtkNM1Xd+Yz8IA1vWLupXhCIXuFNrPFbo+2sCQqDcpI= 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=ZSZuvO2r; 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="ZSZuvO2r" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1fc60c3ead4so1062145ad.0 for ; Thu, 25 Jul 2024 17:43:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721954616; x=1722559416; 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=QhmEI39jJ8nW4OsEZ3phhwIyTyjfbbsfmey5uN1ic1o=; b=ZSZuvO2r9RZGmvoE46bM1qgShk9lKV6USmXE4BC2mUsDBLp7mt153ESGF0kHYA7j/0 oA7bAdxvs65/cQIgMSm2AtdJcajtuMvMqXEPhIgMOM1bK+NyPsOuDdetaRYUd+FtiwLO zC40pEtBpx7c+1Fq7rQbyQvXAmFy2fgxjBaaXY+TDCtOoNxr1Yy2RmZLkpIZXicDd4bJ KC5haQ0L9NUIVy2qOhZyszyllbwxxT+i0Jw+tHNijzG3wl52/+krp6PgYDM0S6XOd5ly jX6kKVjCuIzfHxJpSWCpSUXn53sjW3vBfDivir0fCk10FUTLZdFZGHQ4pUGMEr5gO7Mz uJjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721954616; x=1722559416; 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=QhmEI39jJ8nW4OsEZ3phhwIyTyjfbbsfmey5uN1ic1o=; b=D1WEVm/3NyEcydisL4uF63jPxhmy6cCfFTObp+h5crz2MUtpeEZZmiGtqMEm3G5cxk OeNTB85/jjapqVjJzK8KwV5pp/A24ZgLR1cS5WqObj4f/biKHZVT6Que1lUxkol34t1o QSihwpE8ew/b6vvj6YOpNOCQbqRecUINwgSh/VJ//uSH3Gp7AT2mxyS+aXd/jlk+18hN uSETXGjz2JAWdvf1wfcaJPoOy7EGmT1YXR3BWRh+TQ0S77jk7DypYdwSQXpcPbsdJdAJ Q7ll9F1rgGN4OJ88vxXAyHvhYiOWQYzdsCPJOxw0ty+GIh1eCvmzyJc6CY8P5jTzARrS jboA== X-Gm-Message-State: AOJu0Yxzgis+wKL7QZzuWzkbVHcfBBtQ2pN6fWjUE7vpblsmx/VzwwS7 C4VVJ/5Glb2Qb/fuKTbxmpZwwuWJ/r2Ox2WdVMxWJJwXtxhL2s3pANAZtg== X-Google-Smtp-Source: AGHT+IEf+aMd5WnNvd3do9AjfOPeg5IGhU5gcTmL3r/AaSHmJQZ5ZqPauh7REOOXuGkIMPeNui5iBg== X-Received: by 2002:a17:902:d489:b0:1fb:a1cb:cb31 with SMTP id d9443c01a7336-1fed3860384mr61743785ad.17.1721954615844; Thu, 25 Jul 2024 17:43:35 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7ff5fadsm20000775ad.297.2024.07.25.17.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 17:43:35 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 2/5] hwmon: (max1668) Use BIT macro Date: Thu, 25 Jul 2024 17:43:26 -0700 Message-Id: <20240726004329.934763-3-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240726004329.934763-1-linux@roeck-us.net> References: <20240726004329.934763-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 bit macro to make the code easier to understand and reduce duplication. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/max1668.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/max1668.c b/drivers/hwmon/max1668.c index f5b5cc29da17..83085ed0ae7e 100644 --- a/drivers/hwmon/max1668.c +++ b/drivers/hwmon/max1668.c @@ -6,6 +6,7 @@ * some credit to Christoph Scheurer, but largely a rewrite */ +#include #include #include #include @@ -172,7 +173,7 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, if (IS_ERR(data)) return PTR_ERR(data); - return sprintf(buf, "%u\n", (data->alarms >> index) & 0x1); + return sprintf(buf, "%u\n", !!(data->alarms & BIT(index))); } static ssize_t show_fault(struct device *dev, @@ -185,7 +186,7 @@ static ssize_t show_fault(struct device *dev, return PTR_ERR(data); return sprintf(buf, "%u\n", - (data->alarms & (1 << 12)) && data->temp[index] == 127); + (data->alarms & BIT(12)) && data->temp[index] == 127); } static ssize_t set_temp_max(struct device *dev, From patchwork Fri Jul 26 00:43:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13742346 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 D332C7F8 for ; Fri, 26 Jul 2024 00:43:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721954620; cv=none; b=GNMoQOwCrG/QBIZoJs0ay14lp88J8Zz4TUMe1tVA9m0bCFFpejiDvBrCPtapomU60P/IMsLfLSkxASYvvxWlFguIR6PZd/YTvxePWxRan+rngNpMPdi6ot0g4na2DCfLl3QhLt60YCePo6cLCGlJUFZPcLIM2PjrksMbKou3PSY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721954620; c=relaxed/simple; bh=sJ4ec0VsW/lYIvBjkzqWcIFosfOl1DXQL8c80Kvjib0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZPwYjt8T6b5GCAy5JXNSdyZhqOWpmLx4JtW1p7l6Yva1eXcLbRTH6m2LHrl44hLYkQiGkmNV/ZI5x7tFGsvrZmeIBrdI/OmVI8BxOFZlQiQjmFwAPyrfQeuwU+hSQxdxMoieHgvsT3Q0mi4+Ys4VwuBRsV6PMfHLCOFFbjF/EOU= 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=iI2GZHAX; arc=none smtp.client-ip=209.85.210.181 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="iI2GZHAX" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-70eb0ae23e4so367001b3a.0 for ; Thu, 25 Jul 2024 17:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721954618; x=1722559418; 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=fB4rWSA75m+3bDIKlV6IH6eF8vMXOGsxT0cmgrUQois=; b=iI2GZHAXJzW207H03XnW5tuZbRTwSv2gEUnTEsUXF3vZ97STmTdqvHAYw/GH4Q3U+s mV8oUD7xNtHKhj2+qLlAo4vwrO0fBHg5Fl+Yx6FHEu2F0SXRIgOUdh21WIDripdJOEJ8 rkqxjrc19mDJHqzJSqsL++mq9Qc6cgjBLHLbdGaG/CCerS6ElBtuw2WKT2+fyKURX06e 5StlgVmiyfBtg0Vq6tYMfy6fgs8hn1DoskN1uD6/RStWGJwMQpTCr4wpjwcD7eixs3TB Yjhh2ImVbRSIBC8iF2Rkz/kZrMcWkhHMy0dSnn8vZ9RNlUs+VD/fQgydg+En6xaiT5vD ldOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721954618; x=1722559418; 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=fB4rWSA75m+3bDIKlV6IH6eF8vMXOGsxT0cmgrUQois=; b=aMAHBVFfoiiIpvyZo4AwglGR4ATE121pcfydowWMjR46n0QY4d96iqHE/yvvnPTq3U UAIXScOvbt3xbmveOrFQSwsnzCmNDuv4BFUR3MTCqUyzzcd4vI7CnVZKOqNBkEGIXQYE 5lzbMkSfyjAmwYADxsnEl+safE/Q+M4mrGz9Rp0eotlj+L1li+MfGleT4GutNCJHSpQK XQqFbg8UZy2iyax+xGRXXrusCS9AJcb5DF8yhd+/s4aUCb4WvZvAIWdrkvOa2TLToCKe rNX7ZU5enTJOqcanZ/KkcsfdbfmeBzmWxbu9RBke62YWhj0/X5YTwfiniKGNt3jGYmey A2YA== X-Gm-Message-State: AOJu0YyzJaSip6ib3JqRNqLXELQ02jlxqSSqQ0nIFT7e30QWzVUHU+q4 PBBtSJho1eV6jpOZQfoVupjr4sPptTVTdUrhI4oYqR6r1QmYuW41lot0QA== X-Google-Smtp-Source: AGHT+IHSNE3nZX0qyF6PM/wBPmAbeVZ818rHBtU6mp5TcHag1dLfvuJ2EqXN8V+4gRmiX2vH+PDxxQ== X-Received: by 2002:a05:6a21:78a5:b0:1c2:8d2f:65f4 with SMTP id adf61e73a8af0-1c47b4f0ca2mr4438877637.44.1721954617439; Thu, 25 Jul 2024 17:43:37 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cdb74e894csm4198685a91.41.2024.07.25.17.43.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 17:43:36 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 3/5] hwmon: (max1668) Convert to use regmap Date: Thu, 25 Jul 2024 17:43:27 -0700 Message-Id: <20240726004329.934763-4-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240726004329.934763-1-linux@roeck-us.net> References: <20240726004329.934763-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 caching to simplify the code and to hide read/write register address differences. Signed-off-by: Guenter Roeck --- drivers/hwmon/max1668.c | 213 +++++++++++++++++++--------------------- 1 file changed, 99 insertions(+), 114 deletions(-) diff --git a/drivers/hwmon/max1668.c b/drivers/hwmon/max1668.c index 83085ed0ae7e..48f247ca5d85 100644 --- a/drivers/hwmon/max1668.c +++ b/drivers/hwmon/max1668.c @@ -6,6 +6,7 @@ * some credit to Christoph Scheurer, but largely a rewrite */ +#include #include #include #include @@ -15,6 +16,7 @@ #include #include #include +#include #include /* Addresses to scan */ @@ -31,14 +33,10 @@ static const unsigned short max1668_addr_list[] = { /* limits */ -/* write high limits */ -#define MAX1668_REG_LIMH_WR(nr) (0x13 + 2 * (nr)) -/* write low limits */ -#define MAX1668_REG_LIML_WR(nr) (0x14 + 2 * (nr)) -/* read high limits */ -#define MAX1668_REG_LIMH_RD(nr) (0x08 + 2 * (nr)) +/* high limits */ +#define MAX1668_REG_LIMH(nr) (0x08 + 2 * (nr)) /* read low limits */ -#define MAX1668_REG_LIML_RD(nr) (0x09 + 2 * (nr)) +#define MAX1668_REG_LIML(nr) (0x09 + 2 * (nr)) /* manufacturer and device ID Constants */ #define MAN_ID_MAXIM 0x4d @@ -54,139 +52,91 @@ MODULE_PARM_DESC(read_only, "Don't set any values, read only mode"); enum chips { max1668, max1805, max1989 }; struct max1668_data { - struct i2c_client *client; + struct regmap *regmap; const struct attribute_group *groups[3]; enum chips type; - - struct mutex update_lock; - bool valid; /* true if following fields are valid */ - unsigned long last_updated; /* In jiffies */ - - /* 1x local and 4x remote */ - s8 temp_max[5]; - s8 temp_min[5]; - s8 temp[5]; - u16 alarms; }; -static struct max1668_data *max1668_update_device(struct device *dev) -{ - struct max1668_data *data = dev_get_drvdata(dev); - struct i2c_client *client = data->client; - struct max1668_data *ret = data; - s32 val; - int i; - - mutex_lock(&data->update_lock); - - if (data->valid && !time_after(jiffies, - data->last_updated + HZ + HZ / 2)) - goto abort; - - for (i = 0; i < 5; i++) { - val = i2c_smbus_read_byte_data(client, MAX1668_REG_TEMP(i)); - if (unlikely(val < 0)) { - ret = ERR_PTR(val); - goto abort; - } - data->temp[i] = (s8) val; - - val = i2c_smbus_read_byte_data(client, MAX1668_REG_LIMH_RD(i)); - if (unlikely(val < 0)) { - ret = ERR_PTR(val); - goto abort; - } - data->temp_max[i] = (s8) val; - - val = i2c_smbus_read_byte_data(client, MAX1668_REG_LIML_RD(i)); - if (unlikely(val < 0)) { - ret = ERR_PTR(val); - goto abort; - } - data->temp_min[i] = (s8) val; - } - - val = i2c_smbus_read_byte_data(client, MAX1668_REG_STAT1); - if (unlikely(val < 0)) { - ret = ERR_PTR(val); - goto abort; - } - data->alarms = val << 8; - - val = i2c_smbus_read_byte_data(client, MAX1668_REG_STAT2); - if (unlikely(val < 0)) { - ret = ERR_PTR(val); - goto abort; - } - data->alarms |= val; - - data->last_updated = jiffies; - data->valid = true; -abort: - mutex_unlock(&data->update_lock); - - return ret; -} - static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, char *buf) { int index = to_sensor_dev_attr(devattr)->index; - struct max1668_data *data = max1668_update_device(dev); + struct max1668_data *data = dev_get_drvdata(dev); + u32 temp; + int ret; - if (IS_ERR(data)) - return PTR_ERR(data); + ret = regmap_read(data->regmap, MAX1668_REG_TEMP(index), &temp); + if (ret) + return ret; - return sprintf(buf, "%d\n", data->temp[index] * 1000); + return sprintf(buf, "%d\n", sign_extend32(temp, 7) * 1000); } static ssize_t show_temp_max(struct device *dev, struct device_attribute *devattr, char *buf) { int index = to_sensor_dev_attr(devattr)->index; - struct max1668_data *data = max1668_update_device(dev); + struct max1668_data *data = dev_get_drvdata(dev); + u32 temp; + int ret; - if (IS_ERR(data)) - return PTR_ERR(data); + ret = regmap_read(data->regmap, MAX1668_REG_LIMH(index), &temp); + if (ret) + return ret; - return sprintf(buf, "%d\n", data->temp_max[index] * 1000); + return sprintf(buf, "%d\n", sign_extend32(temp, 7) * 1000); } static ssize_t show_temp_min(struct device *dev, struct device_attribute *devattr, char *buf) { int index = to_sensor_dev_attr(devattr)->index; - struct max1668_data *data = max1668_update_device(dev); + struct max1668_data *data = dev_get_drvdata(dev); + u32 temp; + int ret; - if (IS_ERR(data)) - return PTR_ERR(data); + ret = regmap_read(data->regmap, MAX1668_REG_LIML(index), &temp); + if (ret) + return ret; - return sprintf(buf, "%d\n", data->temp_min[index] * 1000); + return sprintf(buf, "%d\n", sign_extend32(temp, 7) * 1000); } static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, char *buf) { int index = to_sensor_dev_attr(attr)->index; - struct max1668_data *data = max1668_update_device(dev); + struct max1668_data *data = dev_get_drvdata(dev); + u32 alarm; + int ret; - if (IS_ERR(data)) - return PTR_ERR(data); + ret = regmap_read(data->regmap, + index >= 8 ? MAX1668_REG_STAT1 : MAX1668_REG_STAT2, + &alarm); + if (ret) + return ret; - return sprintf(buf, "%u\n", !!(data->alarms & BIT(index))); + return sprintf(buf, "%u\n", !!(alarm & BIT(index & 7))); } static ssize_t show_fault(struct device *dev, struct device_attribute *devattr, char *buf) { int index = to_sensor_dev_attr(devattr)->index; - struct max1668_data *data = max1668_update_device(dev); + struct max1668_data *data = dev_get_drvdata(dev); + struct regmap *regmap = data->regmap; + u32 alarm, temp; + int ret; - if (IS_ERR(data)) - return PTR_ERR(data); + ret = regmap_read(regmap, MAX1668_REG_STAT1, &alarm); + if (ret) + return ret; - return sprintf(buf, "%u\n", - (data->alarms & BIT(12)) && data->temp[index] == 127); + ret = regmap_read(regmap, MAX1668_REG_TEMP(index), &temp); + if (ret) + return ret; + + return sprintf(buf, "%u\n", (alarm & BIT(12)) && temp == 127); } static ssize_t set_temp_max(struct device *dev, @@ -195,7 +145,6 @@ static ssize_t set_temp_max(struct device *dev, { int index = to_sensor_dev_attr(devattr)->index; struct max1668_data *data = dev_get_drvdata(dev); - struct i2c_client *client = data->client; long temp; int ret; @@ -203,14 +152,10 @@ static ssize_t set_temp_max(struct device *dev, if (ret < 0) return ret; - mutex_lock(&data->update_lock); - data->temp_max[index] = clamp_val(temp/1000, -128, 127); - ret = i2c_smbus_write_byte_data(client, - MAX1668_REG_LIMH_WR(index), - data->temp_max[index]); + temp = clamp_val(temp / 1000, -128, 127); + ret = regmap_write(data->regmap, MAX1668_REG_LIMH(index), temp); if (ret < 0) count = ret; - mutex_unlock(&data->update_lock); return count; } @@ -221,7 +166,6 @@ static ssize_t set_temp_min(struct device *dev, { int index = to_sensor_dev_attr(devattr)->index; struct max1668_data *data = dev_get_drvdata(dev); - struct i2c_client *client = data->client; long temp; int ret; @@ -229,14 +173,10 @@ static ssize_t set_temp_min(struct device *dev, if (ret < 0) return ret; - mutex_lock(&data->update_lock); - data->temp_min[index] = clamp_val(temp/1000, -128, 127); - ret = i2c_smbus_write_byte_data(client, - MAX1668_REG_LIML_WR(index), - data->temp_min[index]); + temp = clamp_val(temp / 1000, -128, 127); + ret = regmap_write(data->regmap, MAX1668_REG_LIML(index), temp); if (ret < 0) count = ret; - mutex_unlock(&data->update_lock); return count; } @@ -392,6 +332,48 @@ static int max1668_detect(struct i2c_client *client, return 0; } +/* regmap */ + +static int max1668_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 max1668_reg_write(void *context, unsigned int reg, unsigned int val) +{ + return i2c_smbus_write_byte_data(context, reg + 11, val); +} + +static bool max1668_regmap_is_volatile(struct device *dev, unsigned int reg) +{ + return reg <= MAX1668_REG_STAT2; +} + +static bool max1668_regmap_is_writeable(struct device *dev, unsigned int reg) +{ + return reg > MAX1668_REG_STAT2 && reg <= MAX1668_REG_LIML(4); +} + +static const struct regmap_config max1668_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .cache_type = REGCACHE_MAPLE, + .volatile_reg = max1668_regmap_is_volatile, + .writeable_reg = max1668_regmap_is_writeable, +}; + +static const struct regmap_bus max1668_regmap_bus = { + .reg_write = max1668_reg_write, + .reg_read = max1668_reg_read, +}; + static int max1668_probe(struct i2c_client *client) { struct i2c_adapter *adapter = client->adapter; @@ -406,9 +388,12 @@ static int max1668_probe(struct i2c_client *client) if (!data) return -ENOMEM; - data->client = client; + data->regmap = devm_regmap_init(dev, &max1668_regmap_bus, client, + &max1668_regmap_config); + if (IS_ERR(data->regmap)) + return PTR_ERR(data->regmap); + data->type = (uintptr_t)i2c_get_match_data(client); - mutex_init(&data->update_lock); /* sysfs hooks */ data->groups[0] = &max1668_group_common; From patchwork Fri Jul 26 00:43:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13742347 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 7E852368 for ; Fri, 26 Jul 2024 00:43:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721954621; cv=none; b=nm2fO7Y5TXp7DUVGD5DHin5dcq9oWdvrU6VpVbKY7t13OC63e5Lps9gEFzUUaaU9nXGognBmH/J4sbvKkOdRgxIi9rtsLc214e75h7B2l5xnkZ6AwqBBbVd7GwAIaAlQvWLnHoEuyg3LCxrgfeH6W12/rVMb/6rBO9D56PPRNzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721954621; c=relaxed/simple; bh=T0RsmXJPUlgEEvSy2H7bz0v+bSp3+bX61Je6KEq/+N0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z8foVkQNmbCrfCU2d4LxcmNUam0Wif1OTWQ2hI1L4QbLYtIz1gd1UWS9/P470u7ElEXg0YS9ww52gn/amKZy26Zcc4nvVwj4g0asyldNQNOqDzStpjTM4UFjzfZJYzpoXoQR59ZF6nSamKmGGYdXiTA0Y8pEs29tdvBjUeO7LWY= 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=mIVggO3A; arc=none smtp.client-ip=209.85.214.173 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="mIVggO3A" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1fc6ee64512so1338815ad.0 for ; Thu, 25 Jul 2024 17:43:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721954619; x=1722559419; 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=XrVbaCcus6wpRkj9Yd4FLW6PkRhzF3be0RsLbmirXBI=; b=mIVggO3AOTPqD8G9LoydItM3JZiT0J1X7R8K5JULF32C8plgVkOHUQpdvwm70/ufcC rjaC8WndclX3/EdVrqOktdfOMkx8eoNF/2KhuAW3b05XQmjAQ0soScQ6XEuISyFDAFrG uJ3FXdUkBozHCaxqE1gAMvSwZW8ofDWQ73I2Zg2OTdOQOwHCcIstMkYxBOwwdeiO5Afj gasRCIYVxwhUCoOJUfjyLdYqyIgpIbsMAQ5i3Pv6tINq7sjm9TqqZI5fLKdfbsc1Ygjk 4FtEvV9iMTh39A8fCL8sTVWx2Rc7oNL88f9P0BIFBlwXaFgA0nrvq8KLdkuCOgR7dv2G U3vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721954619; x=1722559419; 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=XrVbaCcus6wpRkj9Yd4FLW6PkRhzF3be0RsLbmirXBI=; b=KkfSkDZe3rEmZ5esPMXNEUa/8a38wI74LCdDq0hHuRyxFtJ2RcePQ0jxaD8yLgC83M 17MlHFUBqe7KH8Uv5+lJAbfUO8XqOFwpD3fGil/lTTm5vAX0nnBI+rwSpH6Thaavbbtr 0YQX/KRvxQaNhJ73oWxkhstZMkfr/BRlMK8zmMZjrH1LVrSMeK2gZfjV03tzViksEbPV q098ssfBstI4Mky5kgbFu8O3sjBWKQqyEAo0BxLK8dai8LRx56sqgMSZ76lNXYNBVvsI UtPQK+WDL3NU3zGUxkoGQLu66Sr3/uTYiSnpHYvUqaooin84svR/M4bbI1qLGKAyLx2x nVDw== X-Gm-Message-State: AOJu0Yy7QK3uPF4U0kYN+T+PZEXcQzlpBuCUo68dW4Q79R5y1aikhplk VXwjpVCOqnMcuBaSLhy0G39aeLSLZR0AwUlTB1xK8tYf8GwkCTzOSWdupg== X-Google-Smtp-Source: AGHT+IHkIPjSA5PrOMNSAtjGn2PX+3lJPmAW1mSTqEh3HKfqFewi92j8vWb2oxeTACHPT8eS/uudDA== X-Received: by 2002:a17:902:e2d2:b0:1fd:7520:fea6 with SMTP id d9443c01a7336-1fed924271fmr31412285ad.23.1721954619354; Thu, 25 Jul 2024 17:43:39 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7f9f43csm20078965ad.257.2024.07.25.17.43.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 17:43:38 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 4/5] hwmon: (max1668) Replace chip type with number of channels Date: Thu, 25 Jul 2024 17:43:28 -0700 Message-Id: <20240726004329.934763-5-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240726004329.934763-1-linux@roeck-us.net> References: <20240726004329.934763-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 only difference between supported chips is the number of channels. Drop enum chips and list the number of channels in struct i2c_device_id directly. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/max1668.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/hwmon/max1668.c b/drivers/hwmon/max1668.c index 48f247ca5d85..071c17604131 100644 --- a/drivers/hwmon/max1668.c +++ b/drivers/hwmon/max1668.c @@ -49,12 +49,10 @@ static bool read_only; module_param(read_only, bool, 0); MODULE_PARM_DESC(read_only, "Don't set any values, read only mode"); -enum chips { max1668, max1805, max1989 }; - struct max1668_data { struct regmap *regmap; const struct attribute_group *groups[3]; - enum chips type; + int channels; }; static ssize_t show_temp(struct device *dev, @@ -393,11 +391,11 @@ static int max1668_probe(struct i2c_client *client) if (IS_ERR(data->regmap)) return PTR_ERR(data->regmap); - data->type = (uintptr_t)i2c_get_match_data(client); + data->channels = (uintptr_t)i2c_get_match_data(client); /* sysfs hooks */ data->groups[0] = &max1668_group_common; - if (data->type == max1668 || data->type == max1989) + if (data->channels == 5) data->groups[1] = &max1668_group_unique; hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, @@ -406,9 +404,9 @@ static int max1668_probe(struct i2c_client *client) } static const struct i2c_device_id max1668_id[] = { - { "max1668", max1668 }, - { "max1805", max1805 }, - { "max1989", max1989 }, + { "max1668", 5 }, + { "max1805", 3 }, + { "max1989", 5 }, { } }; MODULE_DEVICE_TABLE(i2c, max1668_id); From patchwork Fri Jul 26 00:43:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13742348 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5633B7F8 for ; Fri, 26 Jul 2024 00:43:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721954624; cv=none; b=QLnk2ULXHzJMmM+zPskb8R2mkjyHQMbEC9+jeqB45K3a+h9FP6jbrwA2tG/9b+x9WBuvuGEgvFxS28+4terkiSv78xP4+2MMErw9f9QU2LbLaudIN8h3gVWYOQdZOg9IavgSWrAPPClEqfUdsdagU9KnCIe4q98qEizT6302jVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721954624; c=relaxed/simple; bh=EH9axeCS4R70WT2AZbd0M0lVZgpU18MMjf47V1L1r7Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DBQqBXcKhVAkp6TUBxYmQ0bBgSrrY5zwRe1AuDky1oq/HbsknY5UNtLmPGIMVdvCQtwWCeDmpwYOoFmqWrCZBJuoezoIxSYeMLpYAQ41YqKldqnL6nfU+RBYAUGZOweYQoN+AuPrPTCai5NbgH+J+B6OMb9WWvSOATPLFeRc3HE= 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=kPGphpmL; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kPGphpmL" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-70d18d4b94cso402414b3a.2 for ; Thu, 25 Jul 2024 17:43:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721954621; x=1722559421; 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=vCXW6NBsWlrOtveo7YWDxfGgi0FLl2/KnvYTnndMY4I=; b=kPGphpmLQztBzXc6ZF2aus5PrSVMM1xPXuvcJJ2Z3Kyn9ku/5fCkZBbGRc9lyZLu3y 7PQV6YbFhalwcz7wcekylNgX0cnr+ntLRkffBwMO0ExLzWP8xKtnDiYYUNLJ6DXpedLC utnUN6OUD69GgdiavuHXOTJ1NJk7PqyqLdhWqK1N2X/ZNa/nhpjd3jMcxXpSgWTP2xI/ 9UUyVgeWn824DNz9SbzM8n3xnwYzCc38PDyK3g8jKWt8EvWwNFuwBz7An+KoHdrL1VHr mdtz97rNVGIcwcjn5z+cHmgpa3lyICwJf3aBX6IxPd2EHDrtgoqKNhAx1Dpbl9aTZmMj O5OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721954621; x=1722559421; 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=vCXW6NBsWlrOtveo7YWDxfGgi0FLl2/KnvYTnndMY4I=; b=dn+7SzIb6zBPpXbulYjJ/zXLg50+5vf/o/x4fLE2Bhc/6Fr5pTZFj6pbNhoPYFE9qR nwZiYhHRM7H2rTrSr9QazRjR+hx2FMUifkQGSM0EreFp3WBZ9+WwWwzqkxIAhHdsG20v V/iVasZMWqe/W3DaIrmq/iseif4I3iheuoLyNkeFN+S5omlwUMKO4t07K2OG9bTHm50p JgaWRgWfw3okSM6w2a57dk7wgPvlqjIMPA9s/iybR5WcJvYoE8kOON5cwCen7ljN7Cj6 opkoSn9OwXMyzN/aG3otKFnO4p3gef3zvMYBi2qB7tlmI06KnWvpeFZVKvTl2210FVvy 2gCw== X-Gm-Message-State: AOJu0Yy8kL3MdxyunuZl9vbcCFjbGPab/6upq4J2Ia03ZMTBDcu/05it RIoB8HV3bS3Z6e8fAjQ5b3j2A86ZWzPztAcsS+Ikp4W0IS4JuLCDy/w32Q== X-Google-Smtp-Source: AGHT+IGPxTffH50NP1/qnTLBvF8A3JWAvuceFSe3Ysr/NSmoayoMhfTJKPTx2Na7t10i8S6uKKxAlg== X-Received: by 2002:a05:6a00:2388:b0:706:61d5:2792 with SMTP id d2e1a72fcca58-70eaa88be90mr5507244b3a.8.1721954621041; Thu, 25 Jul 2024 17:43:41 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead874619sm1677741b3a.164.2024.07.25.17.43.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 17:43:40 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 5/5] hwmon: (max1668) Convert to use with_info hwmon API Date: Thu, 25 Jul 2024 17:43:29 -0700 Message-Id: <20240726004329.934763-6-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240726004329.934763-1-linux@roeck-us.net> References: <20240726004329.934763-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 use with_info API to simplify the code and to reduce its size. This patch reduces object file size by approximately 25%. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/max1668.c | 337 ++++++++++++++-------------------------- 1 file changed, 114 insertions(+), 223 deletions(-) diff --git a/drivers/hwmon/max1668.c b/drivers/hwmon/max1668.c index 071c17604131..86f77a3f85c0 100644 --- a/drivers/hwmon/max1668.c +++ b/drivers/hwmon/max1668.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -51,247 +50,144 @@ MODULE_PARM_DESC(read_only, "Don't set any values, read only mode"); struct max1668_data { struct regmap *regmap; - const struct attribute_group *groups[3]; int channels; }; -static ssize_t show_temp(struct device *dev, - struct device_attribute *devattr, char *buf) +static int max1668_read(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long *val) { - int index = to_sensor_dev_attr(devattr)->index; - struct max1668_data *data = dev_get_drvdata(dev); - u32 temp; - int ret; - - ret = regmap_read(data->regmap, MAX1668_REG_TEMP(index), &temp); - if (ret) - return ret; - - return sprintf(buf, "%d\n", sign_extend32(temp, 7) * 1000); -} - -static ssize_t show_temp_max(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - int index = to_sensor_dev_attr(devattr)->index; - struct max1668_data *data = dev_get_drvdata(dev); - u32 temp; - int ret; - - ret = regmap_read(data->regmap, MAX1668_REG_LIMH(index), &temp); - if (ret) - return ret; - - return sprintf(buf, "%d\n", sign_extend32(temp, 7) * 1000); -} - -static ssize_t show_temp_min(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - int index = to_sensor_dev_attr(devattr)->index; - struct max1668_data *data = dev_get_drvdata(dev); - u32 temp; - int ret; - - ret = regmap_read(data->regmap, MAX1668_REG_LIML(index), &temp); - if (ret) - return ret; - - return sprintf(buf, "%d\n", sign_extend32(temp, 7) * 1000); -} - -static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, - char *buf) -{ - int index = to_sensor_dev_attr(attr)->index; - struct max1668_data *data = dev_get_drvdata(dev); - u32 alarm; - int ret; - - ret = regmap_read(data->regmap, - index >= 8 ? MAX1668_REG_STAT1 : MAX1668_REG_STAT2, - &alarm); - if (ret) - return ret; - - return sprintf(buf, "%u\n", !!(alarm & BIT(index & 7))); -} - -static ssize_t show_fault(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - int index = to_sensor_dev_attr(devattr)->index; struct max1668_data *data = dev_get_drvdata(dev); struct regmap *regmap = data->regmap; - u32 alarm, temp; + u32 regs[2] = { MAX1668_REG_STAT1, MAX1668_REG_TEMP(channel) }; + u8 regvals[2]; + u32 regval; int ret; - ret = regmap_read(regmap, MAX1668_REG_STAT1, &alarm); - if (ret) - return ret; - - ret = regmap_read(regmap, MAX1668_REG_TEMP(index), &temp); - if (ret) - return ret; - - return sprintf(buf, "%u\n", (alarm & BIT(12)) && temp == 127); + switch (attr) { + case hwmon_temp_input: + ret = regmap_read(regmap, MAX1668_REG_TEMP(channel), ®val); + if (ret) + return ret; + *val = sign_extend32(regval, 7) * 1000; + break; + case hwmon_temp_min: + ret = regmap_read(regmap, MAX1668_REG_LIML(channel), ®val); + if (ret) + return ret; + *val = sign_extend32(regval, 7) * 1000; + break; + case hwmon_temp_max: + ret = regmap_read(regmap, MAX1668_REG_LIMH(channel), ®val); + if (ret) + return ret; + *val = sign_extend32(regval, 7) * 1000; + break; + case hwmon_temp_min_alarm: + ret = regmap_read(regmap, + channel ? MAX1668_REG_STAT2 : MAX1668_REG_STAT1, + ®val); + if (ret) + return ret; + if (channel) + *val = !!(regval & BIT(9 - channel * 2)); + else + *val = !!(regval & BIT(5)); + break; + case hwmon_temp_max_alarm: + ret = regmap_read(regmap, + channel ? MAX1668_REG_STAT2 : MAX1668_REG_STAT1, + ®val); + if (ret) + return ret; + if (channel) + *val = !!(regval & BIT(8 - channel * 2)); + else + *val = !!(regval & BIT(6)); + break; + case hwmon_temp_fault: + ret = regmap_multi_reg_read(regmap, regs, regvals, 2); + if (ret) + return ret; + *val = !!((regvals[0] & BIT(4)) && regvals[1] == 127); + break; + default: + return -EOPNOTSUPP; + } + return 0; } -static ssize_t set_temp_max(struct device *dev, - struct device_attribute *devattr, - const char *buf, size_t count) +static int max1668_write(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long val) { - int index = to_sensor_dev_attr(devattr)->index; struct max1668_data *data = dev_get_drvdata(dev); - long temp; - int ret; + struct regmap *regmap = data->regmap; - ret = kstrtol(buf, 10, &temp); - if (ret < 0) - return ret; + val = clamp_val(val / 1000, -128, 127); - temp = clamp_val(temp / 1000, -128, 127); - ret = regmap_write(data->regmap, MAX1668_REG_LIMH(index), temp); - if (ret < 0) - count = ret; - - return count; + switch (attr) { + case hwmon_temp_min: + return regmap_write(regmap, MAX1668_REG_LIML(channel), val); + case hwmon_temp_max: + return regmap_write(regmap, MAX1668_REG_LIMH(channel), val); + default: + return -EOPNOTSUPP; + } } -static ssize_t set_temp_min(struct device *dev, - struct device_attribute *devattr, - const char *buf, size_t count) +static umode_t max1668_is_visible(const void *_data, enum hwmon_sensor_types type, + u32 attr, int channel) { - int index = to_sensor_dev_attr(devattr)->index; - struct max1668_data *data = dev_get_drvdata(dev); - long temp; - int ret; + const struct max1668_data *data = _data; - ret = kstrtol(buf, 10, &temp); - if (ret < 0) - return ret; + if (channel >= data->channels) + return 0; - temp = clamp_val(temp / 1000, -128, 127); - ret = regmap_write(data->regmap, MAX1668_REG_LIML(index), temp); - if (ret < 0) - count = ret; - - return count; + switch (attr) { + case hwmon_temp_min: + case hwmon_temp_max: + return read_only ? 0444 : 0644; + case hwmon_temp_input: + case hwmon_temp_min_alarm: + case hwmon_temp_max_alarm: + return 0444; + case hwmon_temp_fault: + if (channel) + return 0444; + break; + default: + break; + } + return 0; } -static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); -static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_temp_max, - set_temp_max, 0); -static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO, show_temp_min, - set_temp_min, 0); -static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1); -static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO, show_temp_max, - set_temp_max, 1); -static SENSOR_DEVICE_ATTR(temp2_min, S_IRUGO, show_temp_min, - set_temp_min, 1); -static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2); -static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO, show_temp_max, - set_temp_max, 2); -static SENSOR_DEVICE_ATTR(temp3_min, S_IRUGO, show_temp_min, - set_temp_min, 2); -static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3); -static SENSOR_DEVICE_ATTR(temp4_max, S_IRUGO, show_temp_max, - set_temp_max, 3); -static SENSOR_DEVICE_ATTR(temp4_min, S_IRUGO, show_temp_min, - set_temp_min, 3); -static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO, show_temp, NULL, 4); -static SENSOR_DEVICE_ATTR(temp5_max, S_IRUGO, show_temp_max, - set_temp_max, 4); -static SENSOR_DEVICE_ATTR(temp5_min, S_IRUGO, show_temp_min, - set_temp_min, 4); - -static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 14); -static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 13); -static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 7); -static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 6); -static SENSOR_DEVICE_ATTR(temp3_min_alarm, S_IRUGO, show_alarm, NULL, 5); -static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 4); -static SENSOR_DEVICE_ATTR(temp4_min_alarm, S_IRUGO, show_alarm, NULL, 3); -static SENSOR_DEVICE_ATTR(temp4_max_alarm, S_IRUGO, show_alarm, NULL, 2); -static SENSOR_DEVICE_ATTR(temp5_min_alarm, S_IRUGO, show_alarm, NULL, 1); -static SENSOR_DEVICE_ATTR(temp5_max_alarm, S_IRUGO, show_alarm, NULL, 0); - -static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_fault, NULL, 1); -static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_fault, NULL, 2); -static SENSOR_DEVICE_ATTR(temp4_fault, S_IRUGO, show_fault, NULL, 3); -static SENSOR_DEVICE_ATTR(temp5_fault, S_IRUGO, show_fault, NULL, 4); - -/* Attributes common to MAX1668, MAX1989 and MAX1805 */ -static struct attribute *max1668_attribute_common[] = { - &sensor_dev_attr_temp1_max.dev_attr.attr, - &sensor_dev_attr_temp1_min.dev_attr.attr, - &sensor_dev_attr_temp1_input.dev_attr.attr, - &sensor_dev_attr_temp2_max.dev_attr.attr, - &sensor_dev_attr_temp2_min.dev_attr.attr, - &sensor_dev_attr_temp2_input.dev_attr.attr, - &sensor_dev_attr_temp3_max.dev_attr.attr, - &sensor_dev_attr_temp3_min.dev_attr.attr, - &sensor_dev_attr_temp3_input.dev_attr.attr, - - &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, - &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, - &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, - &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, - &sensor_dev_attr_temp3_max_alarm.dev_attr.attr, - &sensor_dev_attr_temp3_min_alarm.dev_attr.attr, - - &sensor_dev_attr_temp2_fault.dev_attr.attr, - &sensor_dev_attr_temp3_fault.dev_attr.attr, +static const struct hwmon_channel_info * const max1668_info[] = { + HWMON_CHANNEL_INFO(temp, + HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | + HWMON_T_MIN_ALARM | HWMON_T_MAX_ALARM, + HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | + HWMON_T_MIN_ALARM | HWMON_T_MAX_ALARM | + HWMON_T_FAULT, + HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | + HWMON_T_MIN_ALARM | HWMON_T_MAX_ALARM | + HWMON_T_FAULT, + HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | + HWMON_T_MIN_ALARM | HWMON_T_MAX_ALARM | + HWMON_T_FAULT, + HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | + HWMON_T_MIN_ALARM | HWMON_T_MAX_ALARM | + HWMON_T_FAULT), NULL }; -/* Attributes not present on MAX1805 */ -static struct attribute *max1668_attribute_unique[] = { - &sensor_dev_attr_temp4_max.dev_attr.attr, - &sensor_dev_attr_temp4_min.dev_attr.attr, - &sensor_dev_attr_temp4_input.dev_attr.attr, - &sensor_dev_attr_temp5_max.dev_attr.attr, - &sensor_dev_attr_temp5_min.dev_attr.attr, - &sensor_dev_attr_temp5_input.dev_attr.attr, - - &sensor_dev_attr_temp4_max_alarm.dev_attr.attr, - &sensor_dev_attr_temp4_min_alarm.dev_attr.attr, - &sensor_dev_attr_temp5_max_alarm.dev_attr.attr, - &sensor_dev_attr_temp5_min_alarm.dev_attr.attr, - - &sensor_dev_attr_temp4_fault.dev_attr.attr, - &sensor_dev_attr_temp5_fault.dev_attr.attr, - NULL +static const struct hwmon_ops max1668_hwmon_ops = { + .is_visible = max1668_is_visible, + .read = max1668_read, + .write = max1668_write, }; -static umode_t max1668_attribute_mode(struct kobject *kobj, - struct attribute *attr, int index) -{ - umode_t ret = S_IRUGO; - if (read_only) - return ret; - if (attr == &sensor_dev_attr_temp1_max.dev_attr.attr || - attr == &sensor_dev_attr_temp2_max.dev_attr.attr || - attr == &sensor_dev_attr_temp3_max.dev_attr.attr || - attr == &sensor_dev_attr_temp4_max.dev_attr.attr || - attr == &sensor_dev_attr_temp5_max.dev_attr.attr || - attr == &sensor_dev_attr_temp1_min.dev_attr.attr || - attr == &sensor_dev_attr_temp2_min.dev_attr.attr || - attr == &sensor_dev_attr_temp3_min.dev_attr.attr || - attr == &sensor_dev_attr_temp4_min.dev_attr.attr || - attr == &sensor_dev_attr_temp5_min.dev_attr.attr) - ret |= S_IWUSR; - return ret; -} - -static const struct attribute_group max1668_group_common = { - .attrs = max1668_attribute_common, - .is_visible = max1668_attribute_mode -}; - -static const struct attribute_group max1668_group_unique = { - .attrs = max1668_attribute_unique, - .is_visible = max1668_attribute_mode +static const struct hwmon_chip_info max1668_chip_info = { + .ops = &max1668_hwmon_ops, + .info = max1668_info, }; /* Return 0 if detection is successful, -ENODEV otherwise */ @@ -393,13 +289,8 @@ static int max1668_probe(struct i2c_client *client) data->channels = (uintptr_t)i2c_get_match_data(client); - /* sysfs hooks */ - data->groups[0] = &max1668_group_common; - if (data->channels == 5) - data->groups[1] = &max1668_group_unique; - - 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, + &max1668_chip_info, NULL); return PTR_ERR_OR_ZERO(hwmon_dev); }