From patchwork Fri Jul 26 22:15:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13743216 Received: from mail-il1-f178.google.com (mail-il1-f178.google.com [209.85.166.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 B61EC4C99 for ; Fri, 26 Jul 2024 22:16:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722032172; cv=none; b=eOlTPaWAr6A/E63Rs8BoQScVGWnWGs2QGe/uDAiqxBjMwOavqTGL7ji+zRz5aWcsEHnfI1mJSowvfwkrSlL3TzxyC1nZJhTh7N+KdqJ/6079ihCyBOV0HqlKIs3pjsycCXuF/eYZWB/v44N8EbqRM3VSoHfeADyCnOpmH5sQRM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722032172; c=relaxed/simple; bh=5A3HmYWrG/JHfNl8CBkFrnLUVXeSext/VolRVBGiMCY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IxWSc4Ww9L75qWQk+BF1pke9L+CtOpXl82zLWcGhBfNoQAMIsOhnl/bZB5zEl/ww4gAK2gxgTLHG7qiaPk3OIcmWbdetzymAbFMj1lXuJTrfBxy+vGiqjFZwy3PPvXwEQp94ZxppCJMxkOlLUZu633T18CL4f6XE7tlVi14tfZk= 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=muTZogd/; arc=none smtp.client-ip=209.85.166.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="muTZogd/" Received: by mail-il1-f178.google.com with SMTP id e9e14a558f8ab-3992195d08aso11163855ab.0 for ; Fri, 26 Jul 2024 15:16:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722032168; x=1722636968; 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=tP3rxUGqnF8b5+X7YA/COhrego+TOipxI7A0odRA2wc=; b=muTZogd/m0doD2S8znR5i31sEGs6N+cS7BcYIwd4VzpmXVFBTWzmQG8c/YjEuOzzr1 64yt/wNlJnVXkkDwXVP3ZeIuD4PFLMqde66Sb55Q/5T6RuzlQcv+5bky05164FYPVqBm 99Y0utJRGY0bJ+rnVdoYxSjMIMBz0WTbK3CUJCBhqh5hGAIYMvN/jBZ6GV0velhZv8xQ FDpYX5z34hWFLalK8ww1iEjiXqbJtIVIxndVihes3qJqzUv1gqTjvua9WiEpjucav6xu +/iqr5kuJcgHp8HonOsChhGpful679V8kUppzDjgCywu3yswV74FySld80qJ4Dhuvxzd pjBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722032168; x=1722636968; 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=tP3rxUGqnF8b5+X7YA/COhrego+TOipxI7A0odRA2wc=; b=uyvbi/Nm1/I7joYAQRrRghsWcZlzOOTKN14GVgb4Rjq4M0KobNm/B16G13F6Aby33V AjCNeRRKWYtZYOdVISyRyi3oWxGiAiuo/v26bA/5PO7oNsOf90soRtX2dDsIeXn1IvCZ FAC2k08fW0iD7UJ+lGFUSjBV0vRvvwhsiil9DXLxbyFCrmi3l3X0aICpb3pFu8GQf4bZ puw4gNaJQul0oX4RFPog+wvgPXIBFZ/XhVwQQxO6w5tm3nv0qxMfrFwj2cOihWEmX8N4 ja1HcibE4g4hKnjALKuDDD3Qp99yn/fBP6gViIjW0WAlinuT9pMYYamDzTxrxbB29yRW 1uQw== X-Gm-Message-State: AOJu0YyAlRCWd8uKcu1BeBKGt4nLC4j9Ed2Z0yeMtpykmfC7ttyVcpSh Y27l8YtaE+XLvKuatlIHy7lfdVAPqMrrG4JZJVZZeJTBGxraXYHH2OXqFQ== X-Google-Smtp-Source: AGHT+IFSvS2jso9taDMqZ7T9TiXNQN2WVyqjknbB11TH7RfzKNmUGAFV2qL3QY5eo1HWFtYy6kVNIg== X-Received: by 2002:a05:6e02:184d:b0:39a:12d7:2841 with SMTP id e9e14a558f8ab-39aec2e3585mr12358665ab.15.1722032168355; Fri, 26 Jul 2024 15:16:08 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7a9f9ec428bsm2793299a12.63.2024.07.26.15.16.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jul 2024 15:16:07 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Tzung-Bi Shih , Guenter Roeck Subject: [PATCH v2 1/5] hwmon: (max1668) Reorder include files to alphabetic order Date: Fri, 26 Jul 2024 15:15:59 -0700 Message-Id: <20240726221603.1190437-2-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240726221603.1190437-1-linux@roeck-us.net> References: <20240726221603.1190437-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. Reviewed-by: Tzung-Bi Shih Signed-off-by: Guenter Roeck --- v2: Added Reviewed-by: tag 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 22:16:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13743217 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56E25145B00 for ; Fri, 26 Jul 2024 22:16:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722032172; cv=none; b=VqtN1Uooj+LUBBHhriagrOwzWFGVt+5AJBTRwCtsvH92bTSonoyS/CcTMBvfnTETheWCLiuO2IXBLyoDew0LOoHjt6GBS67Ko3je6bxkeug9a1EZAkXJFwAfwf8kNbRVnmJPFzUzTzNEhtdxhzapZaQ8UH5nrGNvn522YplH5MQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722032172; c=relaxed/simple; bh=MNGRWShIXSAPpetGWzn03TiUPTocpGetpbW5Ice8Sek=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OqxPxQXXD9vO4VfS89Nm7/5VKNtl/gLlSex/r5y13SUkpLdyBpfx7NfXZ3LIUNTeEQ448Pozl8VpZjyOSsNsbVQal7cgXt+d/lWTDGvgiyCcvi5rmimhxLNg7+in2T9XaA9xKfRfgeqwrwTZMv1SBJ2pvmyoOtm/ZLBw8jnP3dU= 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=Bsfuk5+H; arc=none smtp.client-ip=209.85.215.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bsfuk5+H" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-7ab34117cc2so958228a12.0 for ; Fri, 26 Jul 2024 15:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722032170; x=1722636970; 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=ivmweaHNVSRGPcIiM3EZwCm2c3itWMgLKJURT/wMvE8=; b=Bsfuk5+HyzslR5IeC2fu6rDx/HgKdOPD9xyychfjBeYcjcrgwniJK3kMkdZf5Ou700 wiz61gBhKlX4RqXLGTOmIy7adgf3E5bmAZAXYuQr/vjFq5KS9Cc7JMeQPE3+QtTIImOY i84U+N+POi/sBfbBC4SuePvviG/i/yFevrZTgmgIVT1OuFoEtvrzU2RpKEEAOx+rE9hh vmKyvkTKgLWLs9uizvYqk+U6CH5Eis7U9/bmL7FnWce47BOCERiQXtELPqX37BtkcH4q IV58Eb2StxzGINZhPEumkNDryfD2fHPp4j1kU5//lFKV890exQO+2/RMvwQmBXrfoilU fysQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722032170; x=1722636970; 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=ivmweaHNVSRGPcIiM3EZwCm2c3itWMgLKJURT/wMvE8=; b=SBRehsPUKolsQZwE13LaX8XtdZjNtA2XXCBc0719D/nk3c5InQQqu866uJFvxsIyYh wEBkd6/QYXUEokPKJYSfGyXe383H3keoP4LQiGtTELV2a/WkSsoC5iVNGVUar4lB/BlP 55ZdZDm8CEWqHG1GJpQh5D0Z7Wuip7roYdcb08ZTXdRa9lZp84mXMkhDDbuqQtSec/sj T+OMf+RFwXxtoKWqg/EEplOWbtwguZfxjuarVwUATx4jJgyaSnyL8nZg6GiduivXCIxo /gRRKoJI9vYvM+gb5yJOBCw+4KlRUGWXGODg1l+igiwdegU/UvCacwxR6YSeNzbOeRV1 yCIg== X-Gm-Message-State: AOJu0YzR5n2iL9fzMbeNQYlcMVFN7RXRHG8MWw4U//2hHYE0H3z2Uys8 zEIWTKh+A1hjrB7Rr69gPV96TOyIwkU2kY+9P1/XQcxP4mya7XUTFGETIg== X-Google-Smtp-Source: AGHT+IFs0MbDTS22UFHwi9yQqRlP20Z6jkc9h19Lfl6e6Eh9Crc/czqHcw8Bv7Qkke2l+YtDOopZhw== X-Received: by 2002:a17:90b:350f:b0:2c9:5f45:5d2a with SMTP id 98e67ed59e1d1-2cf7e1c1a75mr1027045a91.12.1722032170113; Fri, 26 Jul 2024 15:16:10 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28df2b63sm3969289a91.42.2024.07.26.15.16.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jul 2024 15:16:09 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Tzung-Bi Shih , Guenter Roeck Subject: [PATCH v2 2/5] hwmon: (max1668) Use BIT macro Date: Fri, 26 Jul 2024 15:16:00 -0700 Message-Id: <20240726221603.1190437-3-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240726221603.1190437-1-linux@roeck-us.net> References: <20240726221603.1190437-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. Reviewed-by: Tzung-Bi Shih Signed-off-by: Guenter Roeck --- v2: Added Reviewed-by: tag 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 22:16:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13743218 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 3C1F3145B00 for ; Fri, 26 Jul 2024 22:16:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722032175; cv=none; b=UKcuOe3vrOX8ijZS4sPgMw3IZTESbWqPz6cd1mBDYQw3nuS7bKZrh3XRj5aaOCf0JN5al7OdjBPmCjAd+i20ZEFQEs7BVCM74f0FCPcQNT9iKtbiq0DMWks/5dKOynSDN5WJ00z1X/SSX1RTTsEIUHGmclBmPjYCnxhtNhY4O9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722032175; c=relaxed/simple; bh=tQcttyCDpiBBKqNXI+nI/smu9SwcasY0beoVnelsTMU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=l0GoLf0+VkiUWZ4KIwDFSxUvK6iuMZlzA/fSLNbtLV//ygiLXyOZ6WU8LnskKnux/66YncsAfLaQUDDNFy4KWs3GxtzamaDTlj9nAwfBrcMPahI4Iq9FU8EUGHvOhu+BHNoi8qJ1sjCI5SMeFr7vNRjXgUoXwzB8NGGU/IZJ9dg= 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=ctNshZG/; arc=none smtp.client-ip=209.85.214.180 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="ctNshZG/" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1fc4fccdd78so9256785ad.2 for ; Fri, 26 Jul 2024 15:16:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722032172; x=1722636972; 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=ujmz13mdjHhISOELB6uSnObnZ5kP0k5qMFCeC8Fo6tk=; b=ctNshZG/Qv0Hkd3Oc+tfqpXuzIUdMq7B0Gimw2YZ0bbN/o/txYGoUNl88vXMJR0Vze NYSa1V1RIifbvlQk9dbIcLCd25smEbMpSLOO8LYdarDkx0ECyf2sbooooHrK7DinAVCe PX5ie6GZFQnKRHk4q7NA584cbhx3vShk/yE+09wKONhVlpNwWcJ2FnkIEaqLcauR7WgH E3o0Vow38AOkwyf3sBKCZRzZZOfVfqvsAdIRjg8Acz0Lw6gKGLYgSPj8MeiCnFyxw88/ 54SW6bg4ZycJ2AmnYNrkfR24I9WJ3cZrUTQMqzrTKFMgIxGL2jwZhQGkB55GSHw9O7gP 6CJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722032172; x=1722636972; 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=ujmz13mdjHhISOELB6uSnObnZ5kP0k5qMFCeC8Fo6tk=; b=gujMUEuWqI2vCWrg11auP0LdOjw9BRyW2oD9IFqpNdVUuTW8HybVBueY366enT+q1x oVvcivo/u4At8KLk4hJx9FQ9m1iTtV78idNq4qbncUg3fYztF+5+PJNoM2jS843ARCdK IQhBNnwUQE69Bt+uwJP43a8fU/PAzen3sjHYg+sZEfliay13f6x4CE5EanBaZmkQO96R CsoN697LBJLuB6oG7M4z733PuMcEqNkpWTVJAHucVLFSXwHHpePz0aAUw4VLJqrP6WX/ rwAKVRTaaKTcv8FuLudnOaIbeMi9m7hqnq7y/MxR03bkz8mfCTg4YyhXVkW17I5V4ptK YrBA== X-Gm-Message-State: AOJu0Ywew7cPjIj2ftAWRpoF2cFtDo/xkgC5ddRWtd6/oDKxWxo2gf1I AvbeZzu728ed/6geIo7qwXvNpkXAbMgS/A/oNLEV27VAENUsQ1m9vFC6Sg== X-Google-Smtp-Source: AGHT+IEAo47pKi34ICdDZGq4PUGRrAirGzAqqJhFy0oQkB0KuoAU6BiwGjLuQutd9mFaxNQSAPVy2Q== X-Received: by 2002:a17:902:fc46:b0:1ff:52c:34ce with SMTP id d9443c01a7336-1ff052c3e33mr10679985ad.53.1722032171905; Fri, 26 Jul 2024 15:16:11 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7fbf285sm38559645ad.267.2024.07.26.15.16.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jul 2024 15:16:11 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Tzung-Bi Shih , Guenter Roeck Subject: [PATCH v2 3/5] hwmon: (max1668) Convert to use regmap Date: Fri, 26 Jul 2024 15:16:01 -0700 Message-Id: <20240726221603.1190437-4-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240726221603.1190437-1-linux@roeck-us.net> References: <20240726221603.1190437-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 Reviewed-by: Tzung-Bi Shih --- v2: Dropped no longer needed jiffies.h and mutex.h includes Fixed wrong fault bit mask drivers/hwmon/max1668.c | 215 ++++++++++++++++++---------------------- 1 file changed, 99 insertions(+), 116 deletions(-) diff --git a/drivers/hwmon/max1668.c b/drivers/hwmon/max1668.c index 83085ed0ae7e..c7eae28c0b01 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 /* Addresses to scan */ @@ -31,14 +31,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 +50,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(4)) && temp == 127); } static ssize_t set_temp_max(struct device *dev, @@ -195,7 +143,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 +150,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 +164,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 +171,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 +330,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 +386,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 22:16:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13743219 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E592143C6A for ; Fri, 26 Jul 2024 22:16:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722032176; cv=none; b=ft9Zj1KSQXLdOv5rMuBFG0WWYMEdwh/q3k/4Ncbjx9jBu+4/PpoQuLPV+CA3HhVHmEn+ti/Pmh/5hQigS2owm3J4tHJNxOZp3rn3yhz0a3xemZegO+mvobWrvzi2PJ95hBAalefk/fy3HVX1RbGcrxhNXUu118kEhcfK2eN/VeY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722032176; c=relaxed/simple; bh=5Eb/dktSz2cEBHHZtJSYuDYfeV+KYI18S2QFetkCMGI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tDWR3MIC89lHoScVZ0k/PUgav2t5tRg6rwPbJ+7xbBssqDdfazMbQZUTv/4/V+fyNWYwJKV0X3V8UO+IE7QOxF2mwEExtTddSo+519DwoisRj9STgigIh+piGu5+MlUQoXppbteMk+cXKBT/L5iJFh16+qIsYQw5fBe8KG1MmgM= 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=SllzHeb4; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SllzHeb4" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1fda7fa60a9so10421835ad.3 for ; Fri, 26 Jul 2024 15:16:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722032174; x=1722636974; 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=0W6/TSHCMutZOKNlnhzgug6EeVBwor+VPANFIfSeEQ4=; b=SllzHeb4DEFI9zr7IOGcPhPbryGXg/pJ7SkAI4cmDE197K6528RQ9NYARkECDXyA7f IkhztcwEtKchoYG4/1RmrXZUhST3bB3rIyV6r0yP90vm1NZ+a+w3NrE4D5aoJMZ2HEen XM3KMKg3c2eH/pe24ZN7sL3KmdVLADLEADXWSDLEkzoH50ktcJhupVhHmzDEe2Ynzqh2 czIJSDlVExIrWAGCbuLoUZHqfSKoC7kWsEdOJaZK1Jb2zkCgG4EH5uICuEokulke1SOt KeQIC80shDsQJzHHlpa8q2l3Od8aaKbizJCADOgyLuIxyEOQ1M1mNw9XYh4rqVNQ7iVE BKbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722032174; x=1722636974; 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=0W6/TSHCMutZOKNlnhzgug6EeVBwor+VPANFIfSeEQ4=; b=pW1bKII8tIaOg+a8828z38RGBbh2A0KlZJck2pyRS5QPEqE5fCet1BQvFNz+hZvFni TuoXS8Xvaisoc1ruL8Qj7z2svDG7Ns09+XZnSHpQ71DyFKXFuGRpW3MMK59EoXbv4OHX sHGJWthw056xyxc8dFVNolMQBin4IVhzGGNd9pMfEQPlO2eGBlzbjuclVahgxObkj42t NXOR3UVP4kkR3ABbeCehlVRqZysTvfRSQTqHc2RV0cWjcUVd0MIxBf4x2RqvZ88QxKYk 2L8VN9knCL7XXrVuPHRDhLByjFzCa67HRmE51kLI9N3mnTWlFTMG5w2NAn4HwnUYqxXq ro5w== X-Gm-Message-State: AOJu0YwS8Tw33XMltqoqUjnGCp6h8ZGpMUbH4nwzvVlqMquMVRLLeFeH npoBW/Fbf9z1meRNLPcFj44wU3fhKv6cO/aeF6ofKvGNUD2SCVoldzO+9g== X-Google-Smtp-Source: AGHT+IFmaeJiJDJ4fiVgcgCCN57U0IvzPMrAvsD8KKxR8aw5aDe3XwGrrmWBm0DMLkarQrkNVM35ZA== X-Received: by 2002:a17:902:ea05:b0:1fc:58fc:caf7 with SMTP id d9443c01a7336-1ff04808f6cmr12328655ad.14.1722032173963; Fri, 26 Jul 2024 15:16:13 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7ffaa10sm37810645ad.303.2024.07.26.15.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jul 2024 15:16:13 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Tzung-Bi Shih , Guenter Roeck Subject: [PATCH v2 4/5] hwmon: (max1668) Replace chip type with number of channels Date: Fri, 26 Jul 2024 15:16:02 -0700 Message-Id: <20240726221603.1190437-5-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240726221603.1190437-1-linux@roeck-us.net> References: <20240726221603.1190437-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. Reviewed-by: Tzung-Bi Shih Signed-off-by: Guenter Roeck --- v2: Added Reviewed-by: tag 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 c7eae28c0b01..f8180a8597c0 100644 --- a/drivers/hwmon/max1668.c +++ b/drivers/hwmon/max1668.c @@ -47,12 +47,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, @@ -391,11 +389,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, @@ -404,9 +402,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 22:16:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13743220 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 EE29F143C6A for ; Fri, 26 Jul 2024 22:16:16 +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=1722032178; cv=none; b=WYHevEXK3UDSkJPDGngvFt3sPeD1ObEeMd4k+h2oJCYyF8+Z98w3EdkiclY7FMpO0zWWSeJI28TAbvVwZXv5Xip7CkJMju01DKKe6nSah21wiTlbL2GzAZV9ouzh37yJhMBucnJu11CU3ZDsylY7kRR3xjckTPul/CEYKADid7I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722032178; c=relaxed/simple; bh=hdOqATi7V7ons+f6SmCPsNjpiudcNOZjO+9v2n145Bc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=n+YrThRl4fy8WxkTR4xG8S0fmylLQYlCDwlQaHztoewt0HME4FCcn4pPKrl5TRxX3XHT98zQUmw2NaQJMArMM6K95rA7PppiPazPdcuKQqTZIHXlvM8o++wl65SAmCSbTurpzGmLuGV9SAHwLZb1KUSUBYWRrojNtIU5JLaAVTc= 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=GByLepEM; 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="GByLepEM" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-2cb6662ba3aso964345a91.1 for ; Fri, 26 Jul 2024 15:16:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722032176; x=1722636976; 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=20n1mgY9VWNYW8kklXMJzqW7jBitYbssfc+A5oatdLc=; b=GByLepEMG3vkp/apDdarTg4NGG1nlnQbyDaVdIXnm7YU3Dj3n1WcxDBE0MQ9GL+WAu Bd1I+zFpHiw7+nubP1o5cXuayEp+pqM/CaZdDvDEZ6eZKARPwul9Rpa66pA6+aeLbNDQ DCFU32vhY/RfnkKUFLayXGuB9N3QrxtnbSV+ZtzH9QQRhMetjUwzuZSCoX5KPod8o8zu HBhupcp2lQhqVh/GOI7jPoby/38IfddQm4W50Y4V6UmCLCR5M7eGNrvfZ/VoL3pRKsU2 XwjMSzs/nEF1BijEXB23YJuYnE9eYccWHzzP0A/iUPebZsA+iIdZk/etWHaGDCkGT6S4 K9JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722032176; x=1722636976; 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=20n1mgY9VWNYW8kklXMJzqW7jBitYbssfc+A5oatdLc=; b=GOVrBF+mU7hxFWfPcWXHxwtBJCA3kDkhugZJb0di7tEPyVrgeleON9UiBldglmfZaq GHWkpQoJW9NGucj9qXsG9TJ8Y6loJWNME12sl4llINNcrHPpqDMwxHSgHyumKAUJ9TWd G/2Ufa6rJtmvXFmrGFk3wLD4FnDpbqIkt35HSm+rY2Vh+Gf9tnjur2uQE/Mn+uNSb56+ IYiaQwZYA7QWdFIIlYqROnFsjzW3nN6rjjXfAPIewQDTqVrN7pvj7SewvQ5mTUb6ba1P q2Ziz0yHGmIUVrD5a2wpZIxgzVyDf0M3anwtHQHwBsUtzyHHbMMbdI4kKGF5WzZOVVpw wjZg== X-Gm-Message-State: AOJu0YykqmW54NPOzcrns5LnqDzvJ8Lj1fBC+2JtkSYVbdHBPMApLlpZ LhQUHalN/0h8jwuleVNnmG73yN5HSuL7ow6thZwCZImWl3QYTwkW+7OhgQ== X-Google-Smtp-Source: AGHT+IFeQFdvM85GLG3FOOIdZF1CXE7ZKUp8LO2jCIYqLeY2DRrMGoD3rI7ioe4cTpBqVTcoTRXgEw== X-Received: by 2002:a17:90b:1211:b0:2cb:56bd:5d7 with SMTP id 98e67ed59e1d1-2cf7ce8abc6mr1498849a91.5.1722032175732; Fri, 26 Jul 2024 15:16:15 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead6e1a40sm3186110b3a.37.2024.07.26.15.16.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jul 2024 15:16:15 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Tzung-Bi Shih , Guenter Roeck Subject: [PATCH v2 5/5] hwmon: (max1668) Convert to use with_info hwmon API Date: Fri, 26 Jul 2024 15:16:03 -0700 Message-Id: <20240726221603.1190437-6-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240726221603.1190437-1-linux@roeck-us.net> References: <20240726221603.1190437-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%. Reviewed-by: Tzung-Bi Shih Signed-off-by: Guenter Roeck --- v2: Added Reviewed-by: tag 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 f8180a8597c0..a8197a86f559 100644 --- a/drivers/hwmon/max1668.c +++ b/drivers/hwmon/max1668.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -49,247 +48,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(4)) && 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 */ @@ -391,13 +287,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); }