From patchwork Mon Jul 1 21:23:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13718653 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 CDBC7170849; Mon, 1 Jul 2024 21:23:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869035; cv=none; b=CRYbLv5X2RJ/vg9gNaf+ZHF7kovwNt8Pj0KaHG6blBclUjdNzGaOQ3qgWj4gy6Mk2Y41ZBfZv8cZbgU/RR5qo3tKs7UcbU9BnBHUwTKV8hoG2NseFtKXqHDIr7v/p/W+CIG7przd593JXoFdLUNH9UD5+CB7GxKRxXR/5YcNCgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869035; c=relaxed/simple; bh=8cLePAE2uXB/cHC4f7PJI5dtXvetRldVhV9xDT+3JOI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pzMAdgdBtWp7nYKxh2PAgBnM0PRAghHlziF5DbHtGDywoUCl3X7WJU1Y38W5YfAJ4SwJl6PgK/1xy7nfn58lSNEsMdrRcS84A9VnxabNZ+xRC5ObuRGWCO/pSCFNuuLdliS3SIh7OiucX6l6FaaauBaBXTN/8MUYUlYAoUKrnuE= 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=A42fuPkY; arc=none smtp.client-ip=209.85.214.170 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="A42fuPkY" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1f480624d0dso27124755ad.1; Mon, 01 Jul 2024 14:23:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719869032; x=1720473832; 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=o+f1iaiYwmxi54lhj1FA2zbbeJVXd7etxzvGD4MuT3w=; b=A42fuPkYd0aNEkREBHPROrXEF4mfoJ1busbdf5FkJCy0j8FMMCm1QmGUHytxuNdzNu gKGE496tfJ3kcvU5HxQm/wFJGpvPiRP8egbS/S7lwrVXU9D7jb8yyTS/4MAimALCCtcf tox2m3f5TFZtXnRzLeAGm/KhRZgHI4KdNM1omIm2WYkAU1L6CZfk4BMTxSl+wx1aQETf md/47CWyl9GySwzXYD5BTwzBMkF+yrGzJ4N6H1xrNpSzsiqYwTWJ1brOxoDLwDvksLib /px4KCJ9a+Fmwp2ZkV5Ak89rpbcNXVREbcvMT/kBVOdAlE3Bi28UEsyH5Ou6yi+eVOoc nqqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719869032; x=1720473832; 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=o+f1iaiYwmxi54lhj1FA2zbbeJVXd7etxzvGD4MuT3w=; b=QUfCHapWhPquo+2ynVFWPN+xwinfDOTbKd62B6LVlRDu3Z7IXuNCfi3JWnhCnspZag m3WRzY4z8dTPFzVKq76nUIzCVP3X4lOzujzHXPwM7p1Lmebcnyn3axt6F7ryWjGAd9nR 4pAKcUHZiVt+xI5kCACr9RAcdaEi8r60bYN989TCQEqxDZcA1SFojVdhwPm/oNkNCS0P SgJrbPYa5K3TYjoxXR4QaOF5EgKvzPRDbwnkDqJNu92tVN3AtF4CEMBv9OaP6ji8uu0q 7XC2M4btMrzBtukz6l0vUJQIrPb+EvsBB/FZieh4jpr4QzWStuPQ9vl1gTkqh+0tb26v S99Q== X-Gm-Message-State: AOJu0Yyc/NgBzAuR+H/POw9yF8MI4PMxWH6kthT7zYBIujzrP7ANJmVr 72ts3tYq8VmoMBzEkrpubsaIdvWHDFHwAy4NcgaUaIOMvw1OlZV/nymNnA== X-Google-Smtp-Source: AGHT+IEu0YcxUZlhoscn58T1HiwaaKjZJtQ2BONoFMxA2Tbq/IKDvcenNc5OCWGA48NbbwOEtE6IPg== X-Received: by 2002:a17:902:ecc4:b0:1fa:a34e:8806 with SMTP id d9443c01a7336-1fadbca5ba7mr75660805ad.39.1719869032227; Mon, 01 Jul 2024 14:23:52 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fac10d1577sm69681445ad.56.2024.07.01.14.23.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 14:23:51 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Farouk Bouabid , Quentin Schulz , Guenter Roeck Subject: [PATCH v2 01/11] hwmon: (amc6821) Stop accepting invalid pwm values Date: Mon, 1 Jul 2024 14:23:38 -0700 Message-Id: <20240701212348.1670617-2-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240701212348.1670617-1-linux@roeck-us.net> References: <20240701212348.1670617-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 pwm value range is well defined from 0..255. Don't accept any values outside this range. Signed-off-by: Guenter Roeck Reviewed-by: Quentin Schulz --- v2: Use kstrtou8() instead of kstrtol() where possible. Limit range of pwm1_auto_point_pwm to 0..254 in patch 1 instead of limiting it later, and do not accept invalid values for the attribute. drivers/hwmon/amc6821.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index 9b02b304c2f5..eb2d5592a41a 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -355,13 +355,13 @@ static ssize_t pwm1_store(struct device *dev, { struct amc6821_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; - long val; - int ret = kstrtol(buf, 10, &val); + u8 val; + int ret = kstrtou8(buf, 10, &val); if (ret) return ret; mutex_lock(&data->update_lock); - data->pwm1 = clamp_val(val , 0, 255); + data->pwm1 = val; i2c_smbus_write_byte_data(client, AMC6821_REG_DCY, data->pwm1); mutex_unlock(&data->update_lock); return count; @@ -558,13 +558,16 @@ static ssize_t pwm1_auto_point_pwm_store(struct device *dev, struct amc6821_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; int dpwm; - long val; - int ret = kstrtol(buf, 10, &val); + u8 val; + int ret = kstrtou8(buf, 10, &val); if (ret) return ret; + if (val > 254) + return -EINVAL; + mutex_lock(&data->update_lock); - data->pwm1_auto_point_pwm[1] = clamp_val(val, 0, 254); + data->pwm1_auto_point_pwm[1] = val; if (i2c_smbus_write_byte_data(client, AMC6821_REG_DCY_LOW_TEMP, data->pwm1_auto_point_pwm[1])) { dev_err(&client->dev, "Register write error, aborting.\n"); From patchwork Mon Jul 1 21:23:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13718654 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 4137B171670; Mon, 1 Jul 2024 21:23:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869036; cv=none; b=Urs5ofjO5zSiafzRRZXiztqG2jSH0VlwYZseJ28UPs1+n5HxEnIaAHNQey4/FeHZqaNNJY8Ar5Oj4KN+VTVtSyHndnlScXTPKx1493l0mi/Hsn7/KTWOtJLRFrAODtYdjmIscQg6X/9e6tuuqtb4N9ncFODUY6OQsur2C/Ziuhw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869036; c=relaxed/simple; bh=ehlx/cZHs4t9IhkDGvLqftJNB8rDqbZBSV12nsZHxMo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TDjlHiL9QVEYiLvOeDyl1fFItDwwtk7MTh2miqshONXO+ul9zuh836kL+ajH8xlnMuMuJZPW6/mBZk5GkA/PFf8vh2ChWlw8e9v3+b6lHNo609il58v4msB/dThiXPM1+RhS/EpUYXVAZcSYdGiNLi3IcPcK88hDfqI3atisgNM= 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=VoWR6OSM; arc=none smtp.client-ip=209.85.210.170 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="VoWR6OSM" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-701b0b0be38so2840413b3a.0; Mon, 01 Jul 2024 14:23:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719869034; x=1720473834; 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=VkigCce3AAryLns4lvvimzCkFqi+WzN5f1sxehWDswI=; b=VoWR6OSMr2afAoeuZvpzEECkM+cJI42HeR6bFUfcPenp7rgvX9I/pdJuvw/9C4tysH Z/NlA/nZzMEPsiYwh791BZv7CCjBavzW9q3acxc6APkx28+he5FmCfPr3BHNX2vtFtoh XTRk12sokfbdaAURC5ItxNnDgpHXzGigfRZVUwRF8KCUydLlQDYouVfnhh5uEuMs/tnY +SRCupk225/mjl3ohV1xzwqIQOs4h7SNvH3rO0d6iU43aGKRl7mIfarmUp6GSTSzkU3p 7XiUdwFjCQc+b6TSID6RTud6fUk9EkdciNx3DMf4Htd5rwA4kzhOOuIEqGn6xMrwTBUV S2Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719869034; x=1720473834; 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=VkigCce3AAryLns4lvvimzCkFqi+WzN5f1sxehWDswI=; b=chdDUSuUHAnj/SOk8VzZKnevb7SAfY0c6OnpGVy6g6qtwyEd7yW/Q9rL4a/LZ4HALV w5YAlFF6UShEGYGYvpeRQEQqCB3w0iiuU5qYjfgsiO8xL7YMKZNTNkAKDxOCbsTo5iOb zl878PeYt2q6t762l7FVvIrxfAVQoJxMyAYFArjcDEQK7OADm89bjEfvMoID+j0ywMJM Tn8mthjobXvrldDrDtGQHiLr3o9YSEPHqN48nLftDcafKbBgVqTniJ/X8u9QFcppybuD lFeDh8e3QdE/E39ZG8gygEqsVK0NEIO4+rR0XI2c6brC+R3aB8/0kQ/LBKkJhEqyR30k BMIg== X-Gm-Message-State: AOJu0Yy6RZurAlbT7MBZSnNOffEzeqo2GOGrECGtcsPTrBaKPI7lOphX lp53T15xjDBQilk4XO0xoe/u6nmKW2zzWzoamKkqgbC+e+C4islI0o6b9Q== X-Google-Smtp-Source: AGHT+IHYBIqjXnL3dv5bJjy8amNn6eCgXMt9GWN9UcOZxbPLmLAdF0Sr+UTHzNEmWwdC1uzKGRDcMg== X-Received: by 2002:a05:6a20:3949:b0:1be:c967:311d with SMTP id adf61e73a8af0-1bef613f997mr11628600637.35.1719869034095; Mon, 01 Jul 2024 14:23:54 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7080205ebbcsm7000549b3a.40.2024.07.01.14.23.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 14:23:53 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Farouk Bouabid , Quentin Schulz , Guenter Roeck Subject: [PATCH v2 02/11] hwmon: (amc6821) Make reading and writing fan speed limits consistent Date: Mon, 1 Jul 2024 14:23:39 -0700 Message-Id: <20240701212348.1670617-3-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240701212348.1670617-1-linux@roeck-us.net> References: <20240701212348.1670617-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 default value of the maximum fan speed limit register is 0, essentially translating to an unlimited fan speed. When reading the limit, a value of 0 is reported in this case. However, writing a value of 0 results in writing a value of 0xffff into the register, which is inconsistent. To solve the problem, permit writing a limit of 0 for the maximim fan speed, effectively translating to "no limit". Write 0 into the register if a limit value of 0 is written. Otherwise limit the range to <1..6000000> and write 1..0xffff into the register. This ensures that reading and writing from and to a limit register return the same value while at the same time not changing reported values when reading the speed or limits. While at it, restrict fan limit writes to non-negative numbers; writing a negative limit does not make sense and should be reported instead of being corrected. Signed-off-by: Guenter Roeck Reviewed-by: Quentin Schulz --- v2: Do not accept negative fan speed values Display fan speed and speed limit as 0 if register value is 0 (instead of 6000000), as in original code. Only permit writing 0 (unlimited) for the maximum fan speed. drivers/hwmon/amc6821.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index eb2d5592a41a..9c19d4d278ec 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -617,15 +617,20 @@ static ssize_t fan_store(struct device *dev, struct device_attribute *attr, { struct amc6821_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; - long val; + unsigned long val; int ix = to_sensor_dev_attr(attr)->index; - int ret = kstrtol(buf, 10, &val); + int ret = kstrtoul(buf, 10, &val); if (ret) return ret; - val = 1 > val ? 0xFFFF : 6000000/val; + + /* The minimum fan speed must not be unlimited (0) */ + if (ix == IDX_FAN1_MIN && !val) + return -EINVAL; + + val = val > 0 ? 6000000 / clamp_val(val, 1, 6000000) : 0; mutex_lock(&data->update_lock); - data->fan[ix] = (u16) clamp_val(val, 1, 0xFFFF); + data->fan[ix] = clamp_val(val, 0, 0xFFFF); if (i2c_smbus_write_byte_data(client, fan_reg_low[ix], data->fan[ix] & 0xFF)) { dev_err(&client->dev, "Register write error, aborting.\n"); From patchwork Mon Jul 1 21:23:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13718655 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB342171E58; Mon, 1 Jul 2024 21:23:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869038; cv=none; b=rcqWoiLspX3qWhu7hdsy9ZWRoo3PuM3bu/Fu9m3yQvxocx54FMbHeW3j2YOfsl4wsCqdBGI9t8zDjzbRm1sF94pKule0X+SD+Id4IF/I0iRILF+k1lysqKd45YWe6Y7sgfWTjqK6hTlnqpd+aHvQ8pXUTxGRDdP15CVRfZwuFhU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869038; c=relaxed/simple; bh=CqB+VNcXP1Nl0fPDDpfijIsB2LJx7LhGZyddAwfay/k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bITBXgqXQzZctTCHvIy1/6bFLqynqilR3NYcl5O+Fk/PgD2uyDNlUFk2sK2VMZfVD7K2+G7tbQXUpFGEcPiTND1Q3ymQhCkvqX6R+OBiPTdfMWFXWZewqwODhMsNvKr25BHf2Ri73NoeBe4NzCIhA0UvADr+vrIT564A2QLijhc= 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=YgWzcWoy; arc=none smtp.client-ip=209.85.215.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YgWzcWoy" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-70b2421471aso2087608a12.0; Mon, 01 Jul 2024 14:23:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719869036; x=1720473836; 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=lcBcMrVYxfSOpGlKyqBSRUtROv7w28yE9/aoEhvsmPM=; b=YgWzcWoyYCIVO6NDZHDI1bzIV4r3TClfJ1HWxDAA32zFHDnRKS4IK7pXObF9k2+3US atmM3JeseV0z+H4tEok4BuAgw01RJn6xcZKXLxNICSDOncw1dsHUcbUR9HtwzgtIKpik Y1Wzml7YJhCXUVPi5e/Ttx8wCkJsEY05Dg0wLRbHcyV+RrGLemLk9coCrElNrO4j3BN6 auIL+N/nB267olESIUbY1ya1Eo2Zu6Md3lxoU1yLoL0MUDuRhXwWLyj2CQSQyOMjjn+1 K2+ZHue+G5NKHY7+bd8geGvAb+paMtJIMSDDoJw+rbNmO3ohB4Ie24SeyhuU79e5XY52 BaWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719869036; x=1720473836; 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=lcBcMrVYxfSOpGlKyqBSRUtROv7w28yE9/aoEhvsmPM=; b=ig9bAQc1DVFX48DAAVuMaW4DsypBM0nx5lZHlPVu0QI1mBCbsWvv2F5uC3PbjN2WLW hDtdWK812PZByRyjkrho/8J5lWT20YIMmKZHfrFf8D9UZj/LQYuiXyTUrBT800sVNTcm AU8bzOGajZzcOkd2u1qQ1geGjVHX/nisag5+0dd5sZ3KwH8Z4DqApsoXG1jLO46Op17N dDCiV/8IIoQ5VaGBNBBaegHRi2W6teSyN3YmAIWxYQlOqqi6BpudP6BQS2QUrRmJsBQW pEHSm3uJtRzAORteZPnuIuvSYB9CoCD2/zF1hWHLz1WLs+nYQYtAyqWxPmI6yQblcDkN z2lQ== X-Gm-Message-State: AOJu0YymG7VyrI+p6OKcVmcGMHuWkUmDmEIjlutU/0yHydbczcn+jI3c 9wJOeceg7V6mRKEyelMQ/GVVB5Z6VdgD1XKcTv3TienVkBy3mv6n9qpkJQ== X-Google-Smtp-Source: AGHT+IFfEzCXtaZQKrs9KO3NuSgl29NW7Xj55k2pUxT02U/Ud5h33ovlgRKzzurYwvKyKJQ2j2E+mQ== X-Received: by 2002:a05:6a20:3ca5:b0:1be:e1d1:7ea8 with SMTP id adf61e73a8af0-1bef60f2070mr6169211637.1.1719869035664; Mon, 01 Jul 2024 14:23:55 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7080295b982sm7215765b3a.94.2024.07.01.14.23.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 14:23:55 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Farouk Bouabid , Quentin Schulz , Guenter Roeck Subject: [PATCH v2 03/11] hwmon: (amc6821) Rename fan1_div to fan1_pulses Date: Mon, 1 Jul 2024 14:23:40 -0700 Message-Id: <20240701212348.1670617-4-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240701212348.1670617-1-linux@roeck-us.net> References: <20240701212348.1670617-1-linux@roeck-us.net> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The chip does not have a fan divisor. What it does have is a configuration to set either 2 or 4 pulses per fan rotation. Rename the attribute to reflect its use. Update documentation accordingly. Reviewed-by: Quentin Schulz Signed-off-by: Guenter Roeck --- v2: Add Quentin's Reviewed-by: tag Documentation/hwmon/amc6821.rst | 2 +- drivers/hwmon/amc6821.c | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Documentation/hwmon/amc6821.rst b/Documentation/hwmon/amc6821.rst index 5ddb2849da90..4ce67c268e52 100644 --- a/Documentation/hwmon/amc6821.rst +++ b/Documentation/hwmon/amc6821.rst @@ -47,7 +47,7 @@ fan1_input ro tachometer speed fan1_min rw " fan1_max rw " fan1_fault ro " -fan1_div rw Fan divisor can be either 2 or 4. +fan1_pulses rw Pulses per revolution can be either 2 or 4. pwm1 rw pwm1 pwm1_enable rw regulator mode, 1=open loop, 2=fan controlled diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index 9c19d4d278ec..ed98d470a308 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -148,7 +148,7 @@ struct amc6821_data { int temp[TEMP_IDX_LEN]; u16 fan[FAN1_IDX_LEN]; - u8 fan1_div; + u8 fan1_pulses; u8 pwm1; u8 temp1_auto_point_temp[3]; @@ -193,9 +193,9 @@ static struct amc6821_data *amc6821_update_device(struct device *dev) client, fan_reg_hi[i]) << 8; } - data->fan1_div = i2c_smbus_read_byte_data(client, + data->fan1_pulses = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF4); - data->fan1_div = data->fan1_div & AMC6821_CONF4_PSPR ? 4 : 2; + data->fan1_pulses = data->fan1_pulses & AMC6821_CONF4_PSPR ? 4 : 2; data->pwm1_auto_point_pwm[0] = 0; data->pwm1_auto_point_pwm[2] = 255; @@ -647,16 +647,16 @@ static ssize_t fan_store(struct device *dev, struct device_attribute *attr, return count; } -static ssize_t fan1_div_show(struct device *dev, - struct device_attribute *devattr, char *buf) +static ssize_t fan1_pulses_show(struct device *dev, + struct device_attribute *devattr, char *buf) { struct amc6821_data *data = amc6821_update_device(dev); - return sprintf(buf, "%d\n", data->fan1_div); + return sprintf(buf, "%d\n", data->fan1_pulses); } -static ssize_t fan1_div_store(struct device *dev, - struct device_attribute *attr, const char *buf, - size_t count) +static ssize_t fan1_pulses_store(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) { struct amc6821_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; @@ -676,11 +676,11 @@ static ssize_t fan1_div_store(struct device *dev, switch (val) { case 2: config &= ~AMC6821_CONF4_PSPR; - data->fan1_div = 2; + data->fan1_pulses = 2; break; case 4: config |= AMC6821_CONF4_PSPR; - data->fan1_div = 4; + data->fan1_pulses = 4; break; default: count = -EINVAL; @@ -715,7 +715,7 @@ static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, IDX_FAN1_INPUT); static SENSOR_DEVICE_ATTR_RW(fan1_min, fan, IDX_FAN1_MIN); static SENSOR_DEVICE_ATTR_RW(fan1_max, fan, IDX_FAN1_MAX); static SENSOR_DEVICE_ATTR_RO(fan1_fault, fan1_fault, 0); -static SENSOR_DEVICE_ATTR_RW(fan1_div, fan1_div, 0); +static SENSOR_DEVICE_ATTR_RW(fan1_pulses, fan1_pulses, 0); static SENSOR_DEVICE_ATTR_RW(pwm1, pwm1, 0); static SENSOR_DEVICE_ATTR_RW(pwm1_enable, pwm1_enable, 0); @@ -758,7 +758,7 @@ static struct attribute *amc6821_attrs[] = { &sensor_dev_attr_fan1_min.dev_attr.attr, &sensor_dev_attr_fan1_max.dev_attr.attr, &sensor_dev_attr_fan1_fault.dev_attr.attr, - &sensor_dev_attr_fan1_div.dev_attr.attr, + &sensor_dev_attr_fan1_pulses.dev_attr.attr, &sensor_dev_attr_pwm1.dev_attr.attr, &sensor_dev_attr_pwm1_enable.dev_attr.attr, &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr, From patchwork Mon Jul 1 21:23:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13718656 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 BE834172BA7; Mon, 1 Jul 2024 21:23:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869040; cv=none; b=RS06sIp+64cZyfMxhkwYW5ZXhxOdwZfw9/BED1yFev8OJrEbMJgtj9W6Euz8YIDG0YJszsbpPqZucBKEXlDNKrtRxGKmkn6xL3cgQy1xzhlqDgE9ykR+3xH89Vc0Kh/VCsRkA9+Z6f+Mw/A6RBFfvhoVYxWfKXm6m8TAOXEwBAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869040; c=relaxed/simple; bh=yr7KgnBlnn4MHLO3e94iSzXYHjx2To5fTXFFFgUWlPE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kYONkxuRT2I+3bVkNWTlml/dSaQul9RiaTdCCnRXctmi7UrQ6bDIiCWYXUA5IytLXQATL3H3lN0NDZmVttTSVXDf4SvJ8fqmC5baI7zEcdAP8grJRlbCcOVBY/lr1aCXrGdimnArzp1W5Vb/HsCLrwYt7klaT9put6YoT4wgBv0= 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=OhmY328I; arc=none smtp.client-ip=209.85.210.170 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="OhmY328I" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-706524adf91so2814852b3a.2; Mon, 01 Jul 2024 14:23:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719869037; x=1720473837; 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=ZOynw5tALStq7JlQfZMm5YT3RcSHQA1ieLjO326B2mo=; b=OhmY328IkK+swmAGcDgLN8NC9zDXy3tZ4AdbqVlUJNbdeJzmafPddZKnvwnE+Qf6nz rTQs8fr641H75s2+nGlu646NV2TYGOZxkaGusKV3klRispeyVERHzXgnMPgZYpmiMZUL m97uV03wEt/F3rmxW115iCj4i+9QXFR3/rSs6UhpRn0JGYYz3p5gIzG99UekwsgDC6SN m+xaNm6gKjPOBK/95mw+W5dwplAqwoPQjAMTuHcV8D8urhl+klCcEhYHw3IFleOY/YwZ 0NjTrl/ncF43VjrXz8O8BGWD7p1fA2EdNXDsSAZaEWxurFfAf6TVSEH7iEG/Awctkeus fzRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719869037; x=1720473837; 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=ZOynw5tALStq7JlQfZMm5YT3RcSHQA1ieLjO326B2mo=; b=mvonPKaqCt38atKHVZTMS2DyDOedego9Uj+39tHDSXk12dCPGLzvgkwq2Vxc9XGTgc lOpt6WN9KPP8IWTsd+wGYUvCdp3HfG6xMDL/JBLLPJEiIXLlzyXvAUDnJcXoQQkfm2hh SjINt4JlArdo6WzR/Lq4G/GKo7NoVVqilIdy1xn7CDMhzGTWx3OP1K3MwZYIobq77hLC MjWWwEkJjWHL3KVVaM5qEu5luZP0P3Xy43ieB7KEfXEagFHgNQjMIViWnBOay+Kh21O7 etcswOiaZyTO27TvyFj/AWjRBcJw09igC8nw+XgnGpNUCqALNE7V21pKpYt4on00SX4E bpBw== X-Gm-Message-State: AOJu0YxXQu+0ihk1tGVTRc488pPLtHclkMkMMPqCjujgiKzmr9LmECRR DHskBxzJ2dKOy2XD/A/6+AmMtjqIOI1togmliF8vKI0np0v0Ho36dVkb9w== X-Google-Smtp-Source: AGHT+IFgirt6QyPd9S9HzJitZM83cHBdnkh6CDr8EOD64Yghy2EQZx0wjbB6imfIBwmKkcRNFXoGvQ== X-Received: by 2002:a05:6a00:3c8e:b0:705:c0a1:61d8 with SMTP id d2e1a72fcca58-70aaad2af71mr8982010b3a.4.1719869037229; Mon, 01 Jul 2024 14:23:57 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70804a8ed66sm7000232b3a.194.2024.07.01.14.23.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 14:23:56 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Farouk Bouabid , Quentin Schulz , Guenter Roeck Subject: [PATCH v2 04/11] hwmon: (amc6821) Add support for fan1_target and pwm1_enable mode 4 Date: Mon, 1 Jul 2024 14:23:41 -0700 Message-Id: <20240701212348.1670617-5-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240701212348.1670617-1-linux@roeck-us.net> References: <20240701212348.1670617-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 After setting fan1_target and setting pwm1_enable to 4, the fan controller tries to achieve the requested fan speed. Signed-off-by: Guenter Roeck Reviewed-by: Quentin Schulz --- v2: Do not permit writing negative or unlimited target fan speed Documentation/hwmon/amc6821.rst | 4 ++++ drivers/hwmon/amc6821.c | 25 +++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Documentation/hwmon/amc6821.rst b/Documentation/hwmon/amc6821.rst index 4ce67c268e52..96e604c5ea8e 100644 --- a/Documentation/hwmon/amc6821.rst +++ b/Documentation/hwmon/amc6821.rst @@ -48,12 +48,16 @@ fan1_min rw " fan1_max rw " fan1_fault ro " fan1_pulses rw Pulses per revolution can be either 2 or 4. +fan1_target rw Target fan speed, to be used with pwm1_enable + mode 4. pwm1 rw pwm1 pwm1_enable rw regulator mode, 1=open loop, 2=fan controlled by remote temperature, 3=fan controlled by combination of the on-chip temperature and remote-sensor temperature, + 4=fan controlled by target rpm set with + fan1_target attribute. pwm1_auto_channels_temp ro 1 if pwm_enable==2, 3 if pwm_enable==3 pwm1_auto_point1_pwm ro Hardwired to 0, shared for both temperature channels. diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index ed98d470a308..caf720ff674c 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -66,6 +66,8 @@ enum chips { amc6821 }; #define AMC6821_REG_TACH_LLIMITH 0x11 #define AMC6821_REG_TACH_HLIMITL 0x12 #define AMC6821_REG_TACH_HLIMITH 0x13 +#define AMC6821_REG_TACH_SETTINGL 0x1e +#define AMC6821_REG_TACH_SETTINGH 0x1f #define AMC6821_CONF1_START 0x01 #define AMC6821_CONF1_FAN_INT_EN 0x02 @@ -122,17 +124,18 @@ static const u8 temp_reg[] = {AMC6821_REG_LTEMP_HI, AMC6821_REG_RTEMP_LIMIT_MAX, AMC6821_REG_RTEMP_CRIT, }; -enum {IDX_FAN1_INPUT = 0, IDX_FAN1_MIN, IDX_FAN1_MAX, +enum {IDX_FAN1_INPUT = 0, IDX_FAN1_MIN, IDX_FAN1_MAX, IDX_FAN1_TARGET, FAN1_IDX_LEN, }; static const u8 fan_reg_low[] = {AMC6821_REG_TDATA_LOW, AMC6821_REG_TACH_LLIMITL, - AMC6821_REG_TACH_HLIMITL, }; - + AMC6821_REG_TACH_HLIMITL, + AMC6821_REG_TACH_SETTINGL, }; static const u8 fan_reg_hi[] = {AMC6821_REG_TDATA_HI, AMC6821_REG_TACH_LLIMITH, - AMC6821_REG_TACH_HLIMITH, }; + AMC6821_REG_TACH_HLIMITH, + AMC6821_REG_TACH_SETTINGH, }; /* * Client data (each client gets its own) @@ -250,10 +253,10 @@ static struct amc6821_data *amc6821_update_device(struct device *dev) break; case 1: /* * semi-open loop: software sets rpm, chip controls - * pwm1, currently not implemented + * pwm1 */ data->pwm1_auto_channels_temp = 0; - data->pwm1_enable = 0; + data->pwm1_enable = 4; break; } @@ -407,6 +410,10 @@ static ssize_t pwm1_enable_store(struct device *dev, config |= AMC6821_CONF1_FDRC0; config |= AMC6821_CONF1_FDRC1; break; + case 4: + config |= AMC6821_CONF1_FDRC0; + config &= ~AMC6821_CONF1_FDRC1; + break; default: count = -EINVAL; goto unlock; @@ -623,8 +630,8 @@ static ssize_t fan_store(struct device *dev, struct device_attribute *attr, if (ret) return ret; - /* The minimum fan speed must not be unlimited (0) */ - if (ix == IDX_FAN1_MIN && !val) + /* Minimum and target fan speed must not be unlimited (0) */ + if ((ix == IDX_FAN1_MIN || ix == IDX_FAN1_TARGET) && !val) return -EINVAL; val = val > 0 ? 6000000 / clamp_val(val, 1, 6000000) : 0; @@ -714,6 +721,7 @@ static SENSOR_DEVICE_ATTR_RO(temp2_crit_alarm, temp_alarm, IDX_TEMP2_CRIT); static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, IDX_FAN1_INPUT); static SENSOR_DEVICE_ATTR_RW(fan1_min, fan, IDX_FAN1_MIN); static SENSOR_DEVICE_ATTR_RW(fan1_max, fan, IDX_FAN1_MAX); +static SENSOR_DEVICE_ATTR_RW(fan1_target, fan, IDX_FAN1_TARGET); static SENSOR_DEVICE_ATTR_RO(fan1_fault, fan1_fault, 0); static SENSOR_DEVICE_ATTR_RW(fan1_pulses, fan1_pulses, 0); @@ -757,6 +765,7 @@ static struct attribute *amc6821_attrs[] = { &sensor_dev_attr_fan1_input.dev_attr.attr, &sensor_dev_attr_fan1_min.dev_attr.attr, &sensor_dev_attr_fan1_max.dev_attr.attr, + &sensor_dev_attr_fan1_target.dev_attr.attr, &sensor_dev_attr_fan1_fault.dev_attr.attr, &sensor_dev_attr_fan1_pulses.dev_attr.attr, &sensor_dev_attr_pwm1.dev_attr.attr, From patchwork Mon Jul 1 21:23:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13718657 Received: from mail-il1-f177.google.com (mail-il1-f177.google.com [209.85.166.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 02F96171650; Mon, 1 Jul 2024 21:23:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869041; cv=none; b=tFCPzvlFQ1zbyrOX5Yrfm1wUsibfy60t0qg8jmZY4uLxAgkbL+XZjMIe0l5YeCrJfuUOePNyGpbkueFS0ZjIwzcTYU+9//gOe0v6cwfXTs0Ie+K2hZu3VctMacu3WT/FK1bSK5L5/hM3CLOWJA9mFGfGtTEt8XeVCAh9e/UWsF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869041; c=relaxed/simple; bh=HFhKz1+bEinxN3liv5VLA6r0a8T/KM1FqNlY0sb0voQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jeDE09LcubeAYR0y0M/kit7gVVLcOUpwi3D5EfKAoNTMKZgfWEkY7FvhPquPP1v4BIGcLAMxV38SG5hKuBBEdq6CLHYVnwyUmCE0+UvCKGOx4REe3gPiEZ73WBFeqNOjUXoyQo1ak3yUGBt8aw41NqV3QwvP0WjSm3yP+hPhrgc= 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=KhwUkcsL; arc=none smtp.client-ip=209.85.166.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="KhwUkcsL" Received: by mail-il1-f177.google.com with SMTP id e9e14a558f8ab-375e0e258b7so14235045ab.1; Mon, 01 Jul 2024 14:23:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719869039; x=1720473839; 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=hMBsNqatyB0OB7H5r1hWkgSSTu9pZYQoHiRxXoc6VP4=; b=KhwUkcsL7PXH5IiydsRKcdOJYUFPmfIkIeOEXNM+YXHFkyatGqdv5xtgUcydCDXyIr xwc6OsqL+3WqXU2SpyD5Ggzoc4BrAriGeoA+BKJusPgyqsdJ+kKAYdT9Y5TO7GrFphb1 Ja4wG0NS5Ni/qQMaQruHxYlwwYf0TtIW990D/OPp4l0IiR/gKxCiaZnQANbds5Nt2FNt LWBE1VcnU38Mgjz/2E52rfZRPuQ2pQov2zJPMbUECy2v2ggDnVt7YOhRPUxiwvzDP9rk dK2/xa9xyCxvb6I6zQJ8b7AXLFNHEB0rnnWkrw/gFk4kiC5UDwp80KFvGxrs2dNA2//S RJug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719869039; x=1720473839; 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=hMBsNqatyB0OB7H5r1hWkgSSTu9pZYQoHiRxXoc6VP4=; b=DI3N30HqPFfKL2KF8dTK0rie4qF4wyU8Evz5HFzDyx+aydwQ2/hC3YLIXtf8OCuf0q NR8ux0yah8Uapx3N7UXOW5fShGyQNIYMU4yASKfTwXOdg/vn++y254jJxtKmhDCMsnod m61ek8BYHWT2i4pUM7sqml9U87e50wnEAWsjpMzzvowiH8VwE+zITQ3cITpaBzpxxIwS 8qoVp++r5v1iEa6OLP+GWw6xQYJToVK5LrQjKL9VSeUeFHEwotScuq0qnRgrRH5HYTwl J4Ln+ne2e5vqB0KlsTuN0Dio3iTJw8wwDRXLfamwxAwaQGqbjQTMgHKsdPKgpHEnk/64 PoZQ== X-Gm-Message-State: AOJu0YzMO2lq0mVxRVOlNlegy6Qa6GKFIYkBEZp/zgT0X6OTpHmt08lk NYX4JaA9iqjYWNT7NgYYcF8EKkR27RJ53eegpEdDFZ3ztK5mWypI5tgSEA== X-Google-Smtp-Source: AGHT+IFt+2TcuUbDsvhvyd6nBvXxv9QqONc0ng8FtkQhA8mI02Z9FsB7YvCI4a7OqW2C7k4wHyrbeg== X-Received: by 2002:a05:6e02:1a0b:b0:376:115e:bc4a with SMTP id e9e14a558f8ab-37cd13b19bemr81219555ab.10.1719869038773; Mon, 01 Jul 2024 14:23:58 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-72c6d41655fsm5492698a12.92.2024.07.01.14.23.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 14:23:58 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Farouk Bouabid , Quentin Schulz , Guenter Roeck Subject: [PATCH v2 05/11] hwmon: (amc2821) Reorder include files, drop unnecessary ones Date: Mon, 1 Jul 2024 14:23:42 -0700 Message-Id: <20240701212348.1670617-6-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240701212348.1670617-1-linux@roeck-us.net> References: <20240701212348.1670617-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 maintenance, and drop the unnecessary kernel.h include. No functional change intended. Reviewed-by: Quentin Schulz Signed-off-by: Guenter Roeck --- v2: Add Quentin's Reviewed-by: tag drivers/hwmon/amc6821.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index caf720ff674c..e9d345c8064e 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -8,16 +8,15 @@ * Copyright (C) 2007 Hans J. Koch */ -#include /* Needed for KERN_INFO */ -#include -#include -#include -#include -#include +#include #include #include -#include +#include +#include +#include +#include #include +#include /* * Addresses to scan. From patchwork Mon Jul 1 21:23:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13718658 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 8883E173320; Mon, 1 Jul 2024 21:24:01 +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=1719869043; cv=none; b=iApsSh0gABlRJ1hweeNlqae6Qmkb4MItDCWgqIMc2hkueLXufEhji2RqRjV38disRt8sxO0TXnZ8T7E4UzEH8e8ocHNBv3xTH3p2tLWfIBbpLNyB4JrZg84mDTLq5MYXHBK4j+tZDHSxJfYhrrh8Pz4sHGETe9tAZlWdBtQtBlQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869043; c=relaxed/simple; bh=iMHG/Iy5JSd+zMx6HbmL1U/PD3sdQzLYPScMt54Et/s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Kt7mF+k/Z7nfzNPsx3B5zWxT0lskMk5uMZrE4NZhWlW8chkUbAj0o0DClr/B5UpuMB2YWtcHuRoMCR6WGWGD1Y957uAbjYhzd6pAcd945dbXm63DnfTDQuJrMBSqyl8SsJYDuzumlfJLuMn7Zcz/6HhHU5RrhMB7Oy8B2TKFOpU= 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=kumCN9O1; 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="kumCN9O1" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1fa07e4f44eso23014215ad.2; Mon, 01 Jul 2024 14:24:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719869040; x=1720473840; 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=PdZRAJCKkdsgV4TiQnVnwZ/lQYo9HpZX2FKBPS+q5ps=; b=kumCN9O1PJlu51VjPhvm1UsMNYSqPnqg46vxs9kCW6A6oVe/c9jJcFmXpB7Gqx2wDe kjrexCUII0+CwN6WtJ7Z1hAhKtOjzwNwPDj2CgOYh9hDFtodVdeZ7SeRiCQ7g9L0t4wh ne2CGdpexzlULwhfhz7wzav8q1cxdu8Y8CkRV9IO96CO3rZWiPWC70rzdmfYTuhVBi7i 0252IJYshCv3QJK2kW+LDTu1GCtVzAkLhOC88yrrf5qsX0ly3SzoTqq35mKrVnf8Wmb+ l+4BRBdIsbh6iHR7QA112kyKAXW0NIc7U6kkTg95iH6CIvRC8Egi1PD0ucr4dqoWxyoP 42NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719869040; x=1720473840; 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=PdZRAJCKkdsgV4TiQnVnwZ/lQYo9HpZX2FKBPS+q5ps=; b=QX5vkiEzn1t4nX4CO8ZfDNdJi7I/wgL6UlLSezuUZfC931XdC7+nZivUv1Y2LV1d3r /Xbs1UlkI1ytlRnhRh8f/77CvZ4o3u1l1/az0qufLlbThQ7GOXamKCSxyqdSZBRB3E/x GuVQ1p61FkxjQE14mFpCktvh5vxXgWhv9onklUznGOgyBZYtCaxYYxIrOiYs1MO2bwy5 N15z2JL5EAD7imPO+nFlE3FTmPtrJbieauIjzRyEvf07jIgWZtd7qG+cAP/sLlVvQe9f H2WCkLevZtUaz/JhKtHVoIaQf74ykw4hiLc0lJkPg0So7xgrcLXB/6q91WjqnTDaMHqZ Qp0w== X-Gm-Message-State: AOJu0YxW02mJb/I5EduzbKKr+W0iEtO4vyMjiunCQFaV5x4MJobcvcj7 c3RIScQ2G4pJGauj0zkJMPHmbzxT4ACX5jPnja+sTtOC4ly8lku2qEngHQ== X-Google-Smtp-Source: AGHT+IH5C4N3MVTn0yTQGkwrV6cttoG9nF7ef8UuTK/xwoDVdQEr3Y7vkv1+9x7sBoA1t+vtV2anEw== X-Received: by 2002:a17:903:183:b0:1fa:a94:4fe with SMTP id d9443c01a7336-1fadbc73db6mr63615875ad.17.1719869040381; Mon, 01 Jul 2024 14:24:00 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fac10c7067sm69701875ad.51.2024.07.01.14.23.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 14:23:59 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Farouk Bouabid , Quentin Schulz , Guenter Roeck Subject: [PATCH v2 06/11] hwmon: (amc6821) Use tabs for column alignment in defines Date: Mon, 1 Jul 2024 14:23:43 -0700 Message-Id: <20240701212348.1670617-7-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240701212348.1670617-1-linux@roeck-us.net> References: <20240701212348.1670617-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 Using tabs for column alignment makes the code easier to read. No functional change intended. Reviewed-by: Quentin Schulz Signed-off-by: Guenter Roeck --- v2: Add Quentin's Reviewed-by: tag drivers/hwmon/amc6821.c | 128 ++++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index e9d345c8064e..23111c6cb142 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -37,77 +37,77 @@ module_param(init, int, 0444); enum chips { amc6821 }; -#define AMC6821_REG_DEV_ID 0x3D -#define AMC6821_REG_COMP_ID 0x3E -#define AMC6821_REG_CONF1 0x00 -#define AMC6821_REG_CONF2 0x01 -#define AMC6821_REG_CONF3 0x3F -#define AMC6821_REG_CONF4 0x04 -#define AMC6821_REG_STAT1 0x02 -#define AMC6821_REG_STAT2 0x03 -#define AMC6821_REG_TDATA_LOW 0x08 -#define AMC6821_REG_TDATA_HI 0x09 -#define AMC6821_REG_LTEMP_HI 0x0A -#define AMC6821_REG_RTEMP_HI 0x0B -#define AMC6821_REG_LTEMP_LIMIT_MIN 0x15 -#define AMC6821_REG_LTEMP_LIMIT_MAX 0x14 -#define AMC6821_REG_RTEMP_LIMIT_MIN 0x19 -#define AMC6821_REG_RTEMP_LIMIT_MAX 0x18 -#define AMC6821_REG_LTEMP_CRIT 0x1B -#define AMC6821_REG_RTEMP_CRIT 0x1D -#define AMC6821_REG_PSV_TEMP 0x1C -#define AMC6821_REG_DCY 0x22 -#define AMC6821_REG_LTEMP_FAN_CTRL 0x24 -#define AMC6821_REG_RTEMP_FAN_CTRL 0x25 -#define AMC6821_REG_DCY_LOW_TEMP 0x21 +#define AMC6821_REG_DEV_ID 0x3D +#define AMC6821_REG_COMP_ID 0x3E +#define AMC6821_REG_CONF1 0x00 +#define AMC6821_REG_CONF2 0x01 +#define AMC6821_REG_CONF3 0x3F +#define AMC6821_REG_CONF4 0x04 +#define AMC6821_REG_STAT1 0x02 +#define AMC6821_REG_STAT2 0x03 +#define AMC6821_REG_TDATA_LOW 0x08 +#define AMC6821_REG_TDATA_HI 0x09 +#define AMC6821_REG_LTEMP_HI 0x0A +#define AMC6821_REG_RTEMP_HI 0x0B +#define AMC6821_REG_LTEMP_LIMIT_MIN 0x15 +#define AMC6821_REG_LTEMP_LIMIT_MAX 0x14 +#define AMC6821_REG_RTEMP_LIMIT_MIN 0x19 +#define AMC6821_REG_RTEMP_LIMIT_MAX 0x18 +#define AMC6821_REG_LTEMP_CRIT 0x1B +#define AMC6821_REG_RTEMP_CRIT 0x1D +#define AMC6821_REG_PSV_TEMP 0x1C +#define AMC6821_REG_DCY 0x22 +#define AMC6821_REG_LTEMP_FAN_CTRL 0x24 +#define AMC6821_REG_RTEMP_FAN_CTRL 0x25 +#define AMC6821_REG_DCY_LOW_TEMP 0x21 -#define AMC6821_REG_TACH_LLIMITL 0x10 -#define AMC6821_REG_TACH_LLIMITH 0x11 -#define AMC6821_REG_TACH_HLIMITL 0x12 -#define AMC6821_REG_TACH_HLIMITH 0x13 -#define AMC6821_REG_TACH_SETTINGL 0x1e -#define AMC6821_REG_TACH_SETTINGH 0x1f +#define AMC6821_REG_TACH_LLIMITL 0x10 +#define AMC6821_REG_TACH_LLIMITH 0x11 +#define AMC6821_REG_TACH_HLIMITL 0x12 +#define AMC6821_REG_TACH_HLIMITH 0x13 +#define AMC6821_REG_TACH_SETTINGL 0x1e +#define AMC6821_REG_TACH_SETTINGH 0x1f -#define AMC6821_CONF1_START 0x01 -#define AMC6821_CONF1_FAN_INT_EN 0x02 -#define AMC6821_CONF1_FANIE 0x04 -#define AMC6821_CONF1_PWMINV 0x08 -#define AMC6821_CONF1_FAN_FAULT_EN 0x10 -#define AMC6821_CONF1_FDRC0 0x20 -#define AMC6821_CONF1_FDRC1 0x40 -#define AMC6821_CONF1_THERMOVIE 0x80 +#define AMC6821_CONF1_START 0x01 +#define AMC6821_CONF1_FAN_INT_EN 0x02 +#define AMC6821_CONF1_FANIE 0x04 +#define AMC6821_CONF1_PWMINV 0x08 +#define AMC6821_CONF1_FAN_FAULT_EN 0x10 +#define AMC6821_CONF1_FDRC0 0x20 +#define AMC6821_CONF1_FDRC1 0x40 +#define AMC6821_CONF1_THERMOVIE 0x80 -#define AMC6821_CONF2_PWM_EN 0x01 -#define AMC6821_CONF2_TACH_MODE 0x02 -#define AMC6821_CONF2_TACH_EN 0x04 -#define AMC6821_CONF2_RTFIE 0x08 -#define AMC6821_CONF2_LTOIE 0x10 -#define AMC6821_CONF2_RTOIE 0x20 -#define AMC6821_CONF2_PSVIE 0x40 -#define AMC6821_CONF2_RST 0x80 +#define AMC6821_CONF2_PWM_EN 0x01 +#define AMC6821_CONF2_TACH_MODE 0x02 +#define AMC6821_CONF2_TACH_EN 0x04 +#define AMC6821_CONF2_RTFIE 0x08 +#define AMC6821_CONF2_LTOIE 0x10 +#define AMC6821_CONF2_RTOIE 0x20 +#define AMC6821_CONF2_PSVIE 0x40 +#define AMC6821_CONF2_RST 0x80 -#define AMC6821_CONF3_THERM_FAN_EN 0x80 -#define AMC6821_CONF3_REV_MASK 0x0F +#define AMC6821_CONF3_THERM_FAN_EN 0x80 +#define AMC6821_CONF3_REV_MASK 0x0F -#define AMC6821_CONF4_OVREN 0x10 -#define AMC6821_CONF4_TACH_FAST 0x20 -#define AMC6821_CONF4_PSPR 0x40 -#define AMC6821_CONF4_MODE 0x80 +#define AMC6821_CONF4_OVREN 0x10 +#define AMC6821_CONF4_TACH_FAST 0x20 +#define AMC6821_CONF4_PSPR 0x40 +#define AMC6821_CONF4_MODE 0x80 -#define AMC6821_STAT1_RPM_ALARM 0x01 -#define AMC6821_STAT1_FANS 0x02 -#define AMC6821_STAT1_RTH 0x04 -#define AMC6821_STAT1_RTL 0x08 -#define AMC6821_STAT1_R_THERM 0x10 -#define AMC6821_STAT1_RTF 0x20 -#define AMC6821_STAT1_LTH 0x40 -#define AMC6821_STAT1_LTL 0x80 +#define AMC6821_STAT1_RPM_ALARM 0x01 +#define AMC6821_STAT1_FANS 0x02 +#define AMC6821_STAT1_RTH 0x04 +#define AMC6821_STAT1_RTL 0x08 +#define AMC6821_STAT1_R_THERM 0x10 +#define AMC6821_STAT1_RTF 0x20 +#define AMC6821_STAT1_LTH 0x40 +#define AMC6821_STAT1_LTL 0x80 -#define AMC6821_STAT2_RTC 0x08 -#define AMC6821_STAT2_LTC 0x10 -#define AMC6821_STAT2_LPSV 0x20 -#define AMC6821_STAT2_L_THERM 0x40 -#define AMC6821_STAT2_THERM_IN 0x80 +#define AMC6821_STAT2_RTC 0x08 +#define AMC6821_STAT2_LTC 0x10 +#define AMC6821_STAT2_LPSV 0x20 +#define AMC6821_STAT2_L_THERM 0x40 +#define AMC6821_STAT2_THERM_IN 0x80 enum {IDX_TEMP1_INPUT = 0, IDX_TEMP1_MIN, IDX_TEMP1_MAX, IDX_TEMP1_CRIT, IDX_TEMP2_INPUT, IDX_TEMP2_MIN, From patchwork Mon Jul 1 21:23:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13718659 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.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 3599217335E; Mon, 1 Jul 2024 21:24:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869044; cv=none; b=MIlQsVANB+kz54C1FZZ/kgebjsDfKQvJ7y4N2tCvbVL1WMlb5vj+//IMqdlMPdNs8lGNn3QE/owOcty0qADEuZnGC9pNL8TZ/oQh5DbNI0nETODgWnUgePLo/T9ImLq5AGHdBgwFNEbizZC5fHCUh2bNHxExHttOII87ZuwZJqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869044; c=relaxed/simple; bh=hNu8n8FRkycAzwLJxL9+KeyRfii/UWJCZK0Eps9I9TM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AQkZiiQvacCw4uQDvahnEg4lVGqQRIn4ulq3e0Auk3xGaelzjohFnmk+3vK5/aQJ579j42Fydp51Gxj2VcOxOvGYvL9qtS2E3AR14CL2ZOZt+aiK4Qii+kKNsPxKRvxW9WIUKQJGRlCfUXf/qY4yg9zpghMp/8ebqXtRmxhuDQg= 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=j1l6XQ23; arc=none smtp.client-ip=209.85.210.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="j1l6XQ23" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-7065e2fe7d9so2701518b3a.3; Mon, 01 Jul 2024 14:24:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719869042; x=1720473842; 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=Rmn+YmqKMxbvYebriTViJTZY4oGoFXAx7v/gdLiYFoI=; b=j1l6XQ236o2fLjY6kaMQWhgFhDaHAlhbeR+/Kc5TqbklGEgO4G6taW/pRTR66OaBkA tWl67UUNAypTsFYB4AEhOSiTgb8eL244Ph+BZaZvxpFoR+HK3M+D8gCCGI7z5hJl8T59 /ikVfK0ZPSzi2iwYharkNlNktANb3SjGnxzncSuNatmHn41mUizeSMVVg2V+5tAf6r8c EcQP9KgTPwzKpECQa+i8u+1x8Qk5P85iL3DiAE0aUlK00d5igVItWAP2K149EE6taW2x zJKImQoeUNrXLGDASkNscZ4I00QLy/lD1elp7frYmmb526aZmQ4lUWJ5B+fFOsMEJd8R 7ZmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719869042; x=1720473842; 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=Rmn+YmqKMxbvYebriTViJTZY4oGoFXAx7v/gdLiYFoI=; b=SwdykxRRIzTQr7+nzP5e2q/zsWKG42CXQI/+4djp3keP1T+GxoM94/PFJk9YCZMd2/ SKs9V84PWJluByBh4Cxoxml9GMd2wX/AkHN52Ap9NYHirl8mvML0QTiWZP5VAom2gHm2 kWPkr9/CSL7Fa+Kf44pOh+MUdT7w2iE/aECBJhE+sMdY4CzqkAfQmbmfIRYGFl6IEIgP 0LYiSQ1BozVKjgRJQ7OZac6/73V8yiYvUEUvM3GUZ50nPfUIcUq9oQ9LrNMlIGP6qUW+ UgJcz/5GpupN8eENROlAj4q1AexKdGGwIGf8Mj8f+/A0d33CjDnbAlsWn7e17HEIY/R4 Idfw== X-Gm-Message-State: AOJu0YxhbZVwZ0FH5K6KrrNpB/c0w7bQruc4llyBgpSxKtlXjbsAGb0C yAdid1+xxb/OebanMAP6rux0xevFqMTNwVk2wrPPp1717sVSUitA7NN3zQ== X-Google-Smtp-Source: AGHT+IErh4E/qAyUmiDcqrQSqrJr+CPWae2d6mGIuhOKxxYqw4Nm8I+IhyBzbgRugxz5kLIBUwqD4A== X-Received: by 2002:a05:6a20:3d83:b0:1be:c0c9:d014 with SMTP id adf61e73a8af0-1bef6109df7mr12242726637.19.1719869042005; Mon, 01 Jul 2024 14:24:02 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fac1568ea7sm69748735ad.186.2024.07.01.14.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 14:24:01 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Farouk Bouabid , Quentin Schulz , Guenter Roeck Subject: [PATCH v2 07/11] hwmon: (amc2821) Use BIT() and GENMASK() Date: Mon, 1 Jul 2024 14:23:44 -0700 Message-Id: <20240701212348.1670617-8-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240701212348.1670617-1-linux@roeck-us.net> References: <20240701212348.1670617-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() and GENMASK() for bit and mask definitions to help distinguish bit and mask definitions from other defines and to make the code easier to read. No functional change intended. Signed-off-by: Guenter Roeck Reviewed-by: Quentin Schulz --- v2: Fix definition of AMC6821_CONF1_FDRC1 in this patch drivers/hwmon/amc6821.c | 71 +++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index 23111c6cb142..fa9f64c743ff 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -8,6 +8,7 @@ * Copyright (C) 2007 Hans J. Koch */ +#include #include #include #include @@ -68,46 +69,46 @@ enum chips { amc6821 }; #define AMC6821_REG_TACH_SETTINGL 0x1e #define AMC6821_REG_TACH_SETTINGH 0x1f -#define AMC6821_CONF1_START 0x01 -#define AMC6821_CONF1_FAN_INT_EN 0x02 -#define AMC6821_CONF1_FANIE 0x04 -#define AMC6821_CONF1_PWMINV 0x08 -#define AMC6821_CONF1_FAN_FAULT_EN 0x10 -#define AMC6821_CONF1_FDRC0 0x20 -#define AMC6821_CONF1_FDRC1 0x40 -#define AMC6821_CONF1_THERMOVIE 0x80 +#define AMC6821_CONF1_START BIT(0) +#define AMC6821_CONF1_FAN_INT_EN BIT(1) +#define AMC6821_CONF1_FANIE BIT(2) +#define AMC6821_CONF1_PWMINV BIT(3) +#define AMC6821_CONF1_FAN_FAULT_EN BIT(4) +#define AMC6821_CONF1_FDRC0 BIT(5) +#define AMC6821_CONF1_FDRC1 BIT(6) +#define AMC6821_CONF1_THERMOVIE BIT(7) -#define AMC6821_CONF2_PWM_EN 0x01 -#define AMC6821_CONF2_TACH_MODE 0x02 -#define AMC6821_CONF2_TACH_EN 0x04 -#define AMC6821_CONF2_RTFIE 0x08 -#define AMC6821_CONF2_LTOIE 0x10 -#define AMC6821_CONF2_RTOIE 0x20 -#define AMC6821_CONF2_PSVIE 0x40 -#define AMC6821_CONF2_RST 0x80 +#define AMC6821_CONF2_PWM_EN BIT(0) +#define AMC6821_CONF2_TACH_MODE BIT(1) +#define AMC6821_CONF2_TACH_EN BIT(2) +#define AMC6821_CONF2_RTFIE BIT(3) +#define AMC6821_CONF2_LTOIE BIT(4) +#define AMC6821_CONF2_RTOIE BIT(5) +#define AMC6821_CONF2_PSVIE BIT(6) +#define AMC6821_CONF2_RST BIT(7) -#define AMC6821_CONF3_THERM_FAN_EN 0x80 -#define AMC6821_CONF3_REV_MASK 0x0F +#define AMC6821_CONF3_THERM_FAN_EN BIT(7) +#define AMC6821_CONF3_REV_MASK GENMASK(3, 0) -#define AMC6821_CONF4_OVREN 0x10 -#define AMC6821_CONF4_TACH_FAST 0x20 -#define AMC6821_CONF4_PSPR 0x40 -#define AMC6821_CONF4_MODE 0x80 +#define AMC6821_CONF4_OVREN BIT(4) +#define AMC6821_CONF4_TACH_FAST BIT(5) +#define AMC6821_CONF4_PSPR BIT(6) +#define AMC6821_CONF4_MODE BIT(7) -#define AMC6821_STAT1_RPM_ALARM 0x01 -#define AMC6821_STAT1_FANS 0x02 -#define AMC6821_STAT1_RTH 0x04 -#define AMC6821_STAT1_RTL 0x08 -#define AMC6821_STAT1_R_THERM 0x10 -#define AMC6821_STAT1_RTF 0x20 -#define AMC6821_STAT1_LTH 0x40 -#define AMC6821_STAT1_LTL 0x80 +#define AMC6821_STAT1_RPM_ALARM BIT(0) +#define AMC6821_STAT1_FANS BIT(1) +#define AMC6821_STAT1_RTH BIT(2) +#define AMC6821_STAT1_RTL BIT(3) +#define AMC6821_STAT1_R_THERM BIT(4) +#define AMC6821_STAT1_RTF BIT(5) +#define AMC6821_STAT1_LTH BIT(6) +#define AMC6821_STAT1_LTL BIT(7) -#define AMC6821_STAT2_RTC 0x08 -#define AMC6821_STAT2_LTC 0x10 -#define AMC6821_STAT2_LPSV 0x20 -#define AMC6821_STAT2_L_THERM 0x40 -#define AMC6821_STAT2_THERM_IN 0x80 +#define AMC6821_STAT2_RTC BIT(3) +#define AMC6821_STAT2_LTC BIT(4) +#define AMC6821_STAT2_LPSV BIT(5) +#define AMC6821_STAT2_L_THERM BIT(6) +#define AMC6821_STAT2_THERM_IN BIT(7) enum {IDX_TEMP1_INPUT = 0, IDX_TEMP1_MIN, IDX_TEMP1_MAX, IDX_TEMP1_CRIT, IDX_TEMP2_INPUT, IDX_TEMP2_MIN, From patchwork Mon Jul 1 21:23:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13718660 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEA7D1741E6; Mon, 1 Jul 2024 21:24:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869046; cv=none; b=Mpfqn/hXZmKxk/2qLPT4wp/Da/QOYC4Z83J2OZmI/BcgXKiq1UNOgliJZIa6XYV0zFYgzRMNnEyOqnpUcgliS7Tp+yBsz9MUvsd3naI45SuCbE9+T1CEQ0TW/QreBoJJn86ikF30SvID1okIdFZCj30M742VcYTomj4SGe++zNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869046; c=relaxed/simple; bh=WWqKbPULAyL+L74YBgZ1+0YNecn/uWNBOcNZ8wqjbeY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lHSslQG2uROZCI5brCyH28q+AmvbyJfcgtFg04gW2CC0xAB7onb2z9Lq+0/YwTqOCOG35VWCRunzBEWjI6L4s/75Dv0AeTm+m3FogS80eL9i5npamdHqF9Lio/HkKds8o6ficRWVZMuItmtrsh9UOqr+aas4wGhnf+Ujyu7sX1g= 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=nnM+00j4; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nnM+00j4" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-70670188420so2286437b3a.2; Mon, 01 Jul 2024 14:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719869044; x=1720473844; 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=IHw3nW5B/4WNQZhvjY2+OxpbgE14RxG/DICilGYvdEM=; b=nnM+00j4e7vL6AcMLDnyzy545mlb8vR9DuDX+fk0l2VvqYIPHCQUjlaFUqAszr6y9A UxVjGca5Z7usEp7IzlgaeBVpeKP9Zi/heC2wy08jWysCZl5J0aYmARYB6sGAERLpn8L/ VqHRwb71mcXqylmy3+hYsWHhSE6z5UpOR2px4i5qTugHYpp9z65GlFfLDf5eS+F0vgqE x7ugsqKRvGFNs3kFgLM5YLrKg1ozBW4OaokXi5bY1MQOCUdSfFZYB9Cpp2z6msMU6e+b TGb3Y6JAUSqIf5dFZkgx1SWEU4cr7J007HmJ/Qp8BHxiICJCLA7pkrQH4JBxJtxdj6m2 rghw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719869044; x=1720473844; 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=IHw3nW5B/4WNQZhvjY2+OxpbgE14RxG/DICilGYvdEM=; b=lufmdqWJWlcbEcJno3OCALlwWAYW48h8vbiw/nMAIelSRxNIl2TstQgkx8XTG+di/+ PxZzlr+bUjoFAsx+JP0LiNQQ1o5cVdgrOuhZiTrdIFImheTVO9gqXl5LQkObyC1413tQ yiLYrUtvztAzZuqoBqGzXCn9MLjF/jnEE26DW42neN8JOZpSKrSMz3Ag6wOD2lIt081z ixzT4BNxUd/RWY2BGGG8XWXXUGn2m795xjWtR3ez3wqnOajDzWui8nzY+x9R746GA591 pjqd3fajmfektL/w+J4N8YaobKOGUck+QvK5UfvsgPnZ+BoWjaG+lqZAGbjIHrvBJAKy uz9g== X-Gm-Message-State: AOJu0YxbO9O8Aq+AqPVy8J7UZSuxAe5109VPe6rErniamS0DFndutBzy hlmsp5g98X10D9YBAFevgnON4MCNKNIurwf3X7fPZcxy0wdAyXt1Lt8/jQ== X-Google-Smtp-Source: AGHT+IHp1XoYAtCO8bCKKGWm2SNmqXwx3EPn9ba4c3JEwFEqr77NQdEWX5MyqCCrqxnOZOExhp1B8g== X-Received: by 2002:a05:6a00:1482:b0:706:5cd9:655d with SMTP id d2e1a72fcca58-70aaadd1023mr5573827b3a.22.1719869043565; Mon, 01 Jul 2024 14:24:03 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7080246ee8bsm6995788b3a.68.2024.07.01.14.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 14:24:03 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Farouk Bouabid , Quentin Schulz , Guenter Roeck Subject: [PATCH v2 08/11] hwmon: (amc6821) Drop unnecessary enum chips Date: Mon, 1 Jul 2024 14:23:45 -0700 Message-Id: <20240701212348.1670617-9-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240701212348.1670617-1-linux@roeck-us.net> References: <20240701212348.1670617-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 driver only supports a single chip, so an enum to determine the chip type is unnecessary. Drop it. No functional change intended. Reviewed-by: Quentin Schulz Signed-off-by: Guenter Roeck --- v2: Add Quentin's Reviewed-by: tag drivers/hwmon/amc6821.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index fa9f64c743ff..028998d3bedf 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -36,8 +36,6 @@ module_param(pwminv, int, 0444); static int init = 1; /*Power-on initialization.*/ module_param(init, int, 0444); -enum chips { amc6821 }; - #define AMC6821_REG_DEV_ID 0x3D #define AMC6821_REG_COMP_ID 0x3E #define AMC6821_REG_CONF1 0x00 @@ -945,7 +943,7 @@ static int amc6821_probe(struct i2c_client *client) } static const struct i2c_device_id amc6821_id[] = { - { "amc6821", amc6821 }, + { "amc6821", 0 }, { } }; @@ -954,7 +952,6 @@ MODULE_DEVICE_TABLE(i2c, amc6821_id); static const struct of_device_id __maybe_unused amc6821_of_match[] = { { .compatible = "ti,amc6821", - .data = (void *)amc6821, }, { } }; From patchwork Mon Jul 1 21:23:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13718661 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 9D3521741FF; Mon, 1 Jul 2024 21:24:06 +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=1719869048; cv=none; b=TGnVjrCSgP5JiuA8C/VkytpAOzjV2EVGuy1bkQNOD584xju+BpHsfwlf8b2Gg7Ni0A+H7B1b396hHrY6iNf3rVs/amm+flBjDTOaaoPTN1e0Z+8gZmn9SrypUz1chVr2bZCNua4/NqM2dFHEjK3WnzY+JgYdoWK2SN+eZXrvj6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869048; c=relaxed/simple; bh=cP/Te4vYlcEA2DyQm3mhACaSkg+fKuSH/l6VfZ9060U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lzuXIXphNRuocaUL2sAmZzycH+bsuETCSSm6bYA/MvmxrEaxvmPktvhbaZKhL5jvnDlXccG6daa6oefBvisV3aa+D6j5QHkCaKgKktvR0/O0numdtMgPNQrOVQ/3K8/lY+5IPfpG4tyfwTW8yumLD0VsB1Kwa0bAkmgXUOv6xtA= 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=JGD597ZB; 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="JGD597ZB" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-70ad2488fb1so575188b3a.1; Mon, 01 Jul 2024 14:24:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719869045; x=1720473845; 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=iSxJWFowv5lUUeg2OJwZzPUg88dacVPoyWzeuKBMJO4=; b=JGD597ZBz1LtrKKk++MsfVgkjtlN1wushAP/PxewuZSxRf6yUDNoTdSUs/by5v0BZw TUWtXXqvbzYnU6cxKnFnTso1+2eDc1SO+5bvFC8Umg8iuLAWbET2T7i+y85gRtBxAnUA Y6QIhujZa6oJqfS1UVC4x03pfjyRZmfK2kCNpEqOaQC/Xjmre7ncsXfu28SYABM/c6AT Hu6CwGg/IGySisOMVNANFBI8J48fMjJByVI9crxoyLM4nIpbXNIfY9dTR1aEU7bP5A61 vmBsf0Q8PlM8WHuviV6avjz+SHqXQrEibSc1bu2nRwg9zZAFy+Lopdsbd59qjxJkbmMu RYMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719869045; x=1720473845; 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=iSxJWFowv5lUUeg2OJwZzPUg88dacVPoyWzeuKBMJO4=; b=rLgzPPOZnLBpvSlxYyf39Kem4XfGVGFTpTt8AbCgld/JTFPGxDs/1n/oUxjvLAXf66 KwBEWK0ZX8Uoh31trwMZfq8AJodQ5ASwWJRSaodTAU2UjTo8vcm7oWbkrYoI07P4z4o3 WZ+wSi34a5txiVkvcdcJ26oD4js//R8UdSYS2OtrJdvOEj3QI49vezfsjhzxG3npYRns NYE4VrhWTD4o8yvqpjNkTCOJVMG1ruWu32+NQdfw/Eh2CVO31rlJ/mLulPNttdmjMJxd PXTZk22goWaBXBw89bmsnGW+zYGAm3PMm8eo645VbtEncoVwbaM7ek7e49fnWonRoO7I Uuzw== X-Gm-Message-State: AOJu0YwYggeLeczQONVRdZHm77UEjFu32ZUHbs0OOkW4SkBbuHk6Hk8T XCnrr+aJv8++CwTQGQTcZY7aJBX25wXuU9w5R6d7/t/MjW5WPp7VTlcskQ== X-Google-Smtp-Source: AGHT+IFTn+wYkDLtgUaVoZsKa0dDG7n8VqzCW83jo420t/c/oLJlzZrTjjtxnorhVmkXsfcUSZp7EQ== X-Received: by 2002:a05:6a20:47df:b0:1be:e4ca:e077 with SMTP id adf61e73a8af0-1bef6244884mr7074981637.52.1719869045214; Mon, 01 Jul 2024 14:24:05 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91d3ba044sm7269423a91.42.2024.07.01.14.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 14:24:04 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Farouk Bouabid , Quentin Schulz , Guenter Roeck Subject: [PATCH v2 09/11] hwmon: (amc6821) Convert to use regmap Date: Mon, 1 Jul 2024 14:23:46 -0700 Message-Id: <20240701212348.1670617-10-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240701212348.1670617-1-linux@roeck-us.net> References: <20240701212348.1670617-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 register accesses and for most caching. While at it, use sysfs_emit() instead of sprintf() to write sysfs attribute data, and remove spurious debug messages which would only be seen as result of a bug in the code. No functional change intended. Signed-off-by: Guenter Roeck --- v2: Drop another spurious debug message in this patch instead of patch 10 Add missing "select REGMAP_I2C" to Kconfig Change misleading variable name from 'mask' to 'mode'. Use sysfs_emit instead of sprintf everywhere drivers/hwmon/Kconfig | 1 + drivers/hwmon/amc6821.c | 713 ++++++++++++++++++---------------------- 2 files changed, 329 insertions(+), 385 deletions(-) diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index e14ae18a973b..a8fa87a96e8f 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -2127,6 +2127,7 @@ config SENSORS_ADS7871 config SENSORS_AMC6821 tristate "Texas Instruments AMC6821" depends on I2C + select REGMAP_I2C help If you say yes here you get support for the Texas Instruments AMC6821 hardware monitoring chips. diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index 028998d3bedf..3fe0bfeac843 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -8,15 +8,16 @@ * Copyright (C) 2007 Hans J. Koch */ +#include #include #include #include #include #include #include -#include #include #include +#include #include /* @@ -44,6 +45,7 @@ module_param(init, int, 0444); #define AMC6821_REG_CONF4 0x04 #define AMC6821_REG_STAT1 0x02 #define AMC6821_REG_STAT2 0x03 +#define AMC6821_REG_TEMP_LO 0x06 #define AMC6821_REG_TDATA_LOW 0x08 #define AMC6821_REG_TDATA_HI 0x09 #define AMC6821_REG_LTEMP_HI 0x0A @@ -61,11 +63,8 @@ module_param(init, int, 0444); #define AMC6821_REG_DCY_LOW_TEMP 0x21 #define AMC6821_REG_TACH_LLIMITL 0x10 -#define AMC6821_REG_TACH_LLIMITH 0x11 #define AMC6821_REG_TACH_HLIMITL 0x12 -#define AMC6821_REG_TACH_HLIMITH 0x13 #define AMC6821_REG_TACH_SETTINGL 0x1e -#define AMC6821_REG_TACH_SETTINGH 0x1f #define AMC6821_CONF1_START BIT(0) #define AMC6821_CONF1_FAN_INT_EN BIT(1) @@ -130,224 +129,169 @@ static const u8 fan_reg_low[] = {AMC6821_REG_TDATA_LOW, AMC6821_REG_TACH_HLIMITL, AMC6821_REG_TACH_SETTINGL, }; -static const u8 fan_reg_hi[] = {AMC6821_REG_TDATA_HI, - AMC6821_REG_TACH_LLIMITH, - AMC6821_REG_TACH_HLIMITH, - AMC6821_REG_TACH_SETTINGH, }; - /* * Client data (each client gets its own) */ struct amc6821_data { - struct i2c_client *client; + struct regmap *regmap; struct mutex update_lock; - bool valid; /* false until following fields are valid */ - unsigned long last_updated; /* in jiffies */ - /* register values */ - int temp[TEMP_IDX_LEN]; - - u16 fan[FAN1_IDX_LEN]; - u8 fan1_pulses; - - u8 pwm1; u8 temp1_auto_point_temp[3]; u8 temp2_auto_point_temp[3]; - u8 pwm1_auto_point_pwm[3]; - u8 pwm1_enable; - u8 pwm1_auto_channels_temp; - - u8 stat1; - u8 stat2; }; -static struct amc6821_data *amc6821_update_device(struct device *dev) +static int amc6821_init_auto_point_data(struct amc6821_data *data) { - struct amc6821_data *data = dev_get_drvdata(dev); - struct i2c_client *client = data->client; - int timeout = HZ; - u8 reg; - int i; + struct regmap *regmap = data->regmap; + u32 pwm, regval; + int err; - mutex_lock(&data->update_lock); + err = regmap_read(regmap, AMC6821_REG_DCY_LOW_TEMP, &pwm); + if (err) + return err; - if (time_after(jiffies, data->last_updated + timeout) || - !data->valid) { + err = regmap_read(regmap, AMC6821_REG_PSV_TEMP, ®val); + if (err) + return err; + data->temp1_auto_point_temp[0] = regval; + data->temp2_auto_point_temp[0] = data->temp1_auto_point_temp[0]; - for (i = 0; i < TEMP_IDX_LEN; i++) - data->temp[i] = (int8_t)i2c_smbus_read_byte_data( - client, temp_reg[i]); + err = regmap_read(regmap, AMC6821_REG_LTEMP_FAN_CTRL, ®val); + if (err) + return err; + data->temp1_auto_point_temp[1] = (regval & 0xF8) >> 1; - data->stat1 = i2c_smbus_read_byte_data(client, - AMC6821_REG_STAT1); - data->stat2 = i2c_smbus_read_byte_data(client, - AMC6821_REG_STAT2); + regval &= 0x07; + regval = 0x20 >> regval; + if (regval) + data->temp1_auto_point_temp[2] = + data->temp1_auto_point_temp[1] + + (255 - pwm) / regval; + else + data->temp1_auto_point_temp[2] = 255; - data->pwm1 = i2c_smbus_read_byte_data(client, - AMC6821_REG_DCY); - for (i = 0; i < FAN1_IDX_LEN; i++) { - data->fan[i] = i2c_smbus_read_byte_data( - client, - fan_reg_low[i]); - data->fan[i] += i2c_smbus_read_byte_data( - client, - fan_reg_hi[i]) << 8; - } - data->fan1_pulses = i2c_smbus_read_byte_data(client, - AMC6821_REG_CONF4); - data->fan1_pulses = data->fan1_pulses & AMC6821_CONF4_PSPR ? 4 : 2; + err = regmap_read(regmap, AMC6821_REG_RTEMP_FAN_CTRL, ®val); + if (err) + return err; - data->pwm1_auto_point_pwm[0] = 0; - data->pwm1_auto_point_pwm[2] = 255; - data->pwm1_auto_point_pwm[1] = i2c_smbus_read_byte_data(client, - AMC6821_REG_DCY_LOW_TEMP); + data->temp2_auto_point_temp[1] = (regval & 0xF8) >> 1; + regval &= 0x07; + regval = 0x20 >> regval; - data->temp1_auto_point_temp[0] = - i2c_smbus_read_byte_data(client, - AMC6821_REG_PSV_TEMP); - data->temp2_auto_point_temp[0] = - data->temp1_auto_point_temp[0]; - reg = i2c_smbus_read_byte_data(client, - AMC6821_REG_LTEMP_FAN_CTRL); - data->temp1_auto_point_temp[1] = (reg & 0xF8) >> 1; - reg &= 0x07; - reg = 0x20 >> reg; - if (reg > 0) - data->temp1_auto_point_temp[2] = - data->temp1_auto_point_temp[1] + - (data->pwm1_auto_point_pwm[2] - - data->pwm1_auto_point_pwm[1]) / reg; - else - data->temp1_auto_point_temp[2] = 255; + if (regval) + data->temp2_auto_point_temp[2] = + data->temp2_auto_point_temp[1] + + (255 - pwm) / regval; + else + data->temp2_auto_point_temp[2] = 255; - reg = i2c_smbus_read_byte_data(client, - AMC6821_REG_RTEMP_FAN_CTRL); - data->temp2_auto_point_temp[1] = (reg & 0xF8) >> 1; - reg &= 0x07; - reg = 0x20 >> reg; - if (reg > 0) - data->temp2_auto_point_temp[2] = - data->temp2_auto_point_temp[1] + - (data->pwm1_auto_point_pwm[2] - - data->pwm1_auto_point_pwm[1]) / reg; - else - data->temp2_auto_point_temp[2] = 255; - - reg = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF1); - reg = (reg >> 5) & 0x3; - switch (reg) { - case 0: /*open loop: software sets pwm1*/ - data->pwm1_auto_channels_temp = 0; - data->pwm1_enable = 1; - break; - case 2: /*closed loop: remote T (temp2)*/ - data->pwm1_auto_channels_temp = 2; - data->pwm1_enable = 2; - break; - case 3: /*closed loop: local and remote T (temp2)*/ - data->pwm1_auto_channels_temp = 3; - data->pwm1_enable = 3; - break; - case 1: /* - * semi-open loop: software sets rpm, chip controls - * pwm1 - */ - data->pwm1_auto_channels_temp = 0; - data->pwm1_enable = 4; - break; - } - - data->last_updated = jiffies; - data->valid = true; - } - mutex_unlock(&data->update_lock); - return data; + return 0; } static ssize_t temp_show(struct device *dev, struct device_attribute *devattr, char *buf) { - struct amc6821_data *data = amc6821_update_device(dev); + struct amc6821_data *data = dev_get_drvdata(dev); int ix = to_sensor_dev_attr(devattr)->index; + u32 regval; + int err; - return sprintf(buf, "%d\n", data->temp[ix] * 1000); + err = regmap_read(data->regmap, temp_reg[ix], ®val); + if (err) + return err; + + return sysfs_emit(buf, "%d\n", sign_extend32(regval, 7) * 1000); } static ssize_t temp_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct amc6821_data *data = dev_get_drvdata(dev); - struct i2c_client *client = data->client; int ix = to_sensor_dev_attr(attr)->index; long val; + int err; int ret = kstrtol(buf, 10, &val); if (ret) return ret; val = clamp_val(val / 1000, -128, 127); - mutex_lock(&data->update_lock); - data->temp[ix] = val; - if (i2c_smbus_write_byte_data(client, temp_reg[ix], data->temp[ix])) { - dev_err(&client->dev, "Register write error, aborting.\n"); - count = -EIO; - } - mutex_unlock(&data->update_lock); + err = regmap_write(data->regmap, temp_reg[ix], val); + if (err) + return err; + return count; } static ssize_t temp_alarm_show(struct device *dev, struct device_attribute *devattr, char *buf) { - struct amc6821_data *data = amc6821_update_device(dev); + struct amc6821_data *data = dev_get_drvdata(dev); int ix = to_sensor_dev_attr(devattr)->index; - u8 flag; + u32 regval, mask, reg; + int err; switch (ix) { case IDX_TEMP1_MIN: - flag = data->stat1 & AMC6821_STAT1_LTL; + reg = AMC6821_REG_STAT1; + mask = AMC6821_STAT1_LTL; break; case IDX_TEMP1_MAX: - flag = data->stat1 & AMC6821_STAT1_LTH; + reg = AMC6821_REG_STAT1; + mask = AMC6821_STAT1_LTH; break; case IDX_TEMP1_CRIT: - flag = data->stat2 & AMC6821_STAT2_LTC; + reg = AMC6821_REG_STAT2; + mask = AMC6821_STAT2_LTC; break; case IDX_TEMP2_MIN: - flag = data->stat1 & AMC6821_STAT1_RTL; + reg = AMC6821_REG_STAT1; + mask = AMC6821_STAT1_RTL; break; case IDX_TEMP2_MAX: - flag = data->stat1 & AMC6821_STAT1_RTH; + reg = AMC6821_REG_STAT1; + mask = AMC6821_STAT1_RTH; break; case IDX_TEMP2_CRIT: - flag = data->stat2 & AMC6821_STAT2_RTC; + reg = AMC6821_REG_STAT2; + mask = AMC6821_STAT2_RTC; break; default: - dev_dbg(dev, "Unknown attr->index (%d).\n", ix); return -EINVAL; } - if (flag) - return sprintf(buf, "1"); - else - return sprintf(buf, "0"); + err = regmap_read(data->regmap, reg, ®val); + if (err) + return err; + return sysfs_emit(buf, "%d\n", !!(regval & mask)); } static ssize_t temp2_fault_show(struct device *dev, struct device_attribute *devattr, char *buf) { - struct amc6821_data *data = amc6821_update_device(dev); - if (data->stat1 & AMC6821_STAT1_RTF) - return sprintf(buf, "1"); - else - return sprintf(buf, "0"); + struct amc6821_data *data = dev_get_drvdata(dev); + u32 regval; + int err; + + err = regmap_read(data->regmap, AMC6821_REG_STAT1, ®val); + if (err) + return err; + + return sysfs_emit(buf, "%d\n", !!(regval & AMC6821_STAT1_RTF)); } static ssize_t pwm1_show(struct device *dev, struct device_attribute *devattr, char *buf) { - struct amc6821_data *data = amc6821_update_device(dev); - return sprintf(buf, "%d\n", data->pwm1); + struct amc6821_data *data = dev_get_drvdata(dev); + u32 regval; + int err; + + err = regmap_read(data->regmap, AMC6821_REG_DCY, ®val); + if (err) + return err; + + return sysfs_emit(buf, "%d\n", regval); } static ssize_t pwm1_store(struct device *dev, @@ -355,24 +299,43 @@ static ssize_t pwm1_store(struct device *dev, size_t count) { struct amc6821_data *data = dev_get_drvdata(dev); - struct i2c_client *client = data->client; u8 val; int ret = kstrtou8(buf, 10, &val); if (ret) return ret; - mutex_lock(&data->update_lock); - data->pwm1 = val; - i2c_smbus_write_byte_data(client, AMC6821_REG_DCY, data->pwm1); - mutex_unlock(&data->update_lock); + ret = regmap_write(data->regmap, AMC6821_REG_DCY, val); + if (ret) + return ret; + return count; } static ssize_t pwm1_enable_show(struct device *dev, struct device_attribute *devattr, char *buf) { - struct amc6821_data *data = amc6821_update_device(dev); - return sprintf(buf, "%d\n", data->pwm1_enable); + struct amc6821_data *data = dev_get_drvdata(dev); + int err; + u32 val; + + err = regmap_read(data->regmap, AMC6821_REG_CONF1, &val); + if (err) + return err; + switch (val & (AMC6821_CONF1_FDRC0 | AMC6821_CONF1_FDRC1)) { + case 0: + val = 1; /* manual */ + break; + case AMC6821_CONF1_FDRC0: + val = 4; /* target rpm (fan1_target) controlled */ + break; + case AMC6821_CONF1_FDRC1: + val = 2; /* remote temp controlled */ + break; + default: + val = 3; /* max(local, remote) temp controlled */ + break; + } + return sysfs_emit(buf, "%d\n", val); } static ssize_t pwm1_enable_store(struct device *dev, @@ -380,49 +343,37 @@ static ssize_t pwm1_enable_store(struct device *dev, const char *buf, size_t count) { struct amc6821_data *data = dev_get_drvdata(dev); - struct i2c_client *client = data->client; long val; - int config = kstrtol(buf, 10, &val); - if (config) - return config; + u32 mode; + int err; - mutex_lock(&data->update_lock); - config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF1); - if (config < 0) { - dev_err(&client->dev, - "Error reading configuration register, aborting.\n"); - count = config; - goto unlock; - } + err = kstrtol(buf, 10, &val); + if (err) + return err; switch (val) { case 1: - config &= ~AMC6821_CONF1_FDRC0; - config &= ~AMC6821_CONF1_FDRC1; + mode = 0; break; case 2: - config &= ~AMC6821_CONF1_FDRC0; - config |= AMC6821_CONF1_FDRC1; + mode = AMC6821_CONF1_FDRC1; break; case 3: - config |= AMC6821_CONF1_FDRC0; - config |= AMC6821_CONF1_FDRC1; + mode = AMC6821_CONF1_FDRC0 | AMC6821_CONF1_FDRC1; break; case 4: - config |= AMC6821_CONF1_FDRC0; - config &= ~AMC6821_CONF1_FDRC1; + mode = AMC6821_CONF1_FDRC0; break; default: - count = -EINVAL; - goto unlock; + return -EINVAL; } - if (i2c_smbus_write_byte_data(client, AMC6821_REG_CONF1, config)) { - dev_err(&client->dev, - "Configuration register write error, aborting.\n"); - count = -EIO; - } -unlock: - mutex_unlock(&data->update_lock); + + err = regmap_update_bits(data->regmap, AMC6821_REG_CONF1, + AMC6821_CONF1_FDRC0 | AMC6821_CONF1_FDRC1, + mode); + if (err) + return err; + return count; } @@ -430,26 +381,45 @@ static ssize_t pwm1_auto_channels_temp_show(struct device *dev, struct device_attribute *devattr, char *buf) { - struct amc6821_data *data = amc6821_update_device(dev); - return sprintf(buf, "%d\n", data->pwm1_auto_channels_temp); + struct amc6821_data *data = dev_get_drvdata(dev); + u32 val; + int err; + + err = regmap_read(data->regmap, AMC6821_REG_CONF1, &val); + if (err) + return err; + switch (val & (AMC6821_CONF1_FDRC0 | AMC6821_CONF1_FDRC1)) { + case 0: + case AMC6821_CONF1_FDRC0: + val = 0; /* manual or target rpm controlled */ + break; + case AMC6821_CONF1_FDRC1: + val = 2; /* remote temp controlled */ + break; + default: + val = 3; /* max(local, remote) temp controlled */ + break; + } + + return sysfs_emit(buf, "%d\n", val); } static ssize_t temp_auto_point_temp_show(struct device *dev, struct device_attribute *devattr, char *buf) { + struct amc6821_data *data = dev_get_drvdata(dev); int ix = to_sensor_dev_attr_2(devattr)->index; int nr = to_sensor_dev_attr_2(devattr)->nr; - struct amc6821_data *data = amc6821_update_device(dev); + switch (nr) { case 1: - return sprintf(buf, "%d\n", - data->temp1_auto_point_temp[ix] * 1000); + return sysfs_emit(buf, "%d\n", + data->temp1_auto_point_temp[ix] * 1000); case 2: - return sprintf(buf, "%d\n", - data->temp2_auto_point_temp[ix] * 1000); + return sysfs_emit(buf, "%d\n", + data->temp2_auto_point_temp[ix] * 1000); default: - dev_dbg(dev, "Unknown attr->nr (%d).\n", nr); return -EINVAL; } } @@ -458,44 +428,59 @@ static ssize_t pwm1_auto_point_pwm_show(struct device *dev, struct device_attribute *devattr, char *buf) { + struct amc6821_data *data = dev_get_drvdata(dev); int ix = to_sensor_dev_attr(devattr)->index; - struct amc6821_data *data = amc6821_update_device(dev); - return sprintf(buf, "%d\n", data->pwm1_auto_point_pwm[ix]); + u32 val; + int err; + + switch (ix) { + case 0: + val = 0; + break; + case 1: + err = regmap_read(data->regmap, AMC6821_REG_DCY_LOW_TEMP, &val); + if (err) + return err; + break; + default: + val = 255; + break; + } + return sysfs_emit(buf, "%d\n", val); } -static inline ssize_t set_slope_register(struct i2c_client *client, - u8 reg, - u8 dpwm, - u8 *ptemp) +static inline int set_slope_register(struct regmap *regmap, + u8 reg, u8 *ptemp) { - int dt; - u8 tmp; + u8 tmp, dpwm; + int err, dt; + u32 pwm; - dt = ptemp[2]-ptemp[1]; + err = regmap_read(regmap, AMC6821_REG_DCY_LOW_TEMP, &pwm); + if (err) + return err; + + dpwm = 255 - pwm; + + dt = ptemp[2] - ptemp[1]; for (tmp = 4; tmp > 0; tmp--) { if (dt * (0x20 >> tmp) >= dpwm) break; } tmp |= (ptemp[1] & 0x7C) << 1; - if (i2c_smbus_write_byte_data(client, - reg, tmp)) { - dev_err(&client->dev, "Register write error, aborting.\n"); - return -EIO; - } - return 0; + return regmap_write(regmap, reg, tmp); } static ssize_t temp_auto_point_temp_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct amc6821_data *data = amc6821_update_device(dev); - struct i2c_client *client = data->client; + struct amc6821_data *data = dev_get_drvdata(dev); int ix = to_sensor_dev_attr_2(attr)->index; int nr = to_sensor_dev_attr_2(attr)->nr; + struct regmap *regmap = data->regmap; u8 *ptemp; u8 reg; - int dpwm; long val; int ret = kstrtol(buf, 10, &val); if (ret) @@ -511,12 +496,10 @@ static ssize_t temp_auto_point_temp_store(struct device *dev, reg = AMC6821_REG_RTEMP_FAN_CTRL; break; default: - dev_dbg(dev, "Unknown attr->nr (%d).\n", nr); return -EINVAL; } mutex_lock(&data->update_lock); - data->valid = false; switch (ix) { case 0: @@ -525,13 +508,9 @@ static ssize_t temp_auto_point_temp_store(struct device *dev, ptemp[0] = clamp_val(ptemp[0], 0, data->temp2_auto_point_temp[1]); ptemp[0] = clamp_val(ptemp[0], 0, 63); - if (i2c_smbus_write_byte_data( - client, - AMC6821_REG_PSV_TEMP, - ptemp[0])) { - dev_err(&client->dev, - "Register write error, aborting.\n"); - count = -EIO; + if (regmap_write(regmap, AMC6821_REG_PSV_TEMP, ptemp[0])) { + dev_err(dev, "Register write error, aborting.\n"); + count = -EIO; } goto EXIT; case 1: @@ -543,12 +522,10 @@ static ssize_t temp_auto_point_temp_store(struct device *dev, ptemp[2] = clamp_val(val / 1000, ptemp[1]+1, 255); break; default: - dev_dbg(dev, "Unknown attr->index (%d).\n", ix); count = -EINVAL; goto EXIT; } - dpwm = data->pwm1_auto_point_pwm[2] - data->pwm1_auto_point_pwm[1]; - if (set_slope_register(client, reg, dpwm, ptemp)) + if (set_slope_register(regmap, reg, ptemp)) count = -EIO; EXIT: @@ -561,10 +538,11 @@ static ssize_t pwm1_auto_point_pwm_store(struct device *dev, const char *buf, size_t count) { struct amc6821_data *data = dev_get_drvdata(dev); - struct i2c_client *client = data->client; - int dpwm; + struct regmap *regmap = data->regmap; u8 val; - int ret = kstrtou8(buf, 10, &val); + int ret; + + ret = kstrtou8(buf, 10, &val); if (ret) return ret; @@ -572,27 +550,24 @@ static ssize_t pwm1_auto_point_pwm_store(struct device *dev, return -EINVAL; mutex_lock(&data->update_lock); - data->pwm1_auto_point_pwm[1] = val; - if (i2c_smbus_write_byte_data(client, AMC6821_REG_DCY_LOW_TEMP, - data->pwm1_auto_point_pwm[1])) { - dev_err(&client->dev, "Register write error, aborting.\n"); - count = -EIO; - goto EXIT; + ret = regmap_write(regmap, AMC6821_REG_DCY_LOW_TEMP, val); + if (ret) + goto unlock; + + ret = set_slope_register(regmap, AMC6821_REG_LTEMP_FAN_CTRL, + data->temp1_auto_point_temp); + if (ret) { + count = ret; + goto unlock; } - dpwm = data->pwm1_auto_point_pwm[2] - data->pwm1_auto_point_pwm[1]; - if (set_slope_register(client, AMC6821_REG_LTEMP_FAN_CTRL, dpwm, - data->temp1_auto_point_temp)) { - count = -EIO; - goto EXIT; - } - if (set_slope_register(client, AMC6821_REG_RTEMP_FAN_CTRL, dpwm, - data->temp2_auto_point_temp)) { - count = -EIO; - goto EXIT; + ret = set_slope_register(regmap, AMC6821_REG_RTEMP_FAN_CTRL, + data->temp2_auto_point_temp); + if (ret) { + count = ret; + goto unlock; } -EXIT: - data->valid = false; +unlock: mutex_unlock(&data->update_lock); return count; } @@ -600,63 +575,76 @@ static ssize_t pwm1_auto_point_pwm_store(struct device *dev, static ssize_t fan_show(struct device *dev, struct device_attribute *devattr, char *buf) { - struct amc6821_data *data = amc6821_update_device(dev); + struct amc6821_data *data = dev_get_drvdata(dev); int ix = to_sensor_dev_attr(devattr)->index; - if (0 == data->fan[ix]) - return sprintf(buf, "0"); - return sprintf(buf, "%d\n", (int)(6000000 / data->fan[ix])); + u32 regval; + u8 regs[2]; + int err; + + err = regmap_bulk_read(data->regmap, fan_reg_low[ix], regs, 2); + if (err) + return err; + regval = (regs[1] << 8) | regs[0]; + + return sysfs_emit(buf, "%d\n", 6000000 / (regval ? : 1)); } static ssize_t fan1_fault_show(struct device *dev, struct device_attribute *devattr, char *buf) { - struct amc6821_data *data = amc6821_update_device(dev); - if (data->stat1 & AMC6821_STAT1_FANS) - return sprintf(buf, "1"); - else - return sprintf(buf, "0"); + struct amc6821_data *data = dev_get_drvdata(dev); + u32 regval; + int err; + + err = regmap_read(data->regmap, AMC6821_REG_STAT1, ®val); + if (err) + return err; + + return sysfs_emit(buf, "%d\n", !!(regval & AMC6821_STAT1_FANS)); } static ssize_t fan_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct amc6821_data *data = dev_get_drvdata(dev); - struct i2c_client *client = data->client; - unsigned long val; int ix = to_sensor_dev_attr(attr)->index; - int ret = kstrtoul(buf, 10, &val); - if (ret) - return ret; + unsigned long val; + u8 regs[2]; + int err; + + err = kstrtoul(buf, 10, &val); + if (err) + return err; /* Minimum and target fan speed must not be unlimited (0) */ if ((ix == IDX_FAN1_MIN || ix == IDX_FAN1_TARGET) && !val) return -EINVAL; val = val > 0 ? 6000000 / clamp_val(val, 1, 6000000) : 0; + val = clamp_val(val, 0, 0xFFFF); + + regs[0] = val & 0xff; + regs[1] = val >> 8; + + err = regmap_bulk_write(data->regmap, fan_reg_low[ix], regs, 2); + if (err) + return err; - mutex_lock(&data->update_lock); - data->fan[ix] = clamp_val(val, 0, 0xFFFF); - if (i2c_smbus_write_byte_data(client, fan_reg_low[ix], - data->fan[ix] & 0xFF)) { - dev_err(&client->dev, "Register write error, aborting.\n"); - count = -EIO; - goto EXIT; - } - if (i2c_smbus_write_byte_data(client, - fan_reg_hi[ix], data->fan[ix] >> 8)) { - dev_err(&client->dev, "Register write error, aborting.\n"); - count = -EIO; - } -EXIT: - mutex_unlock(&data->update_lock); return count; } static ssize_t fan1_pulses_show(struct device *dev, struct device_attribute *devattr, char *buf) { - struct amc6821_data *data = amc6821_update_device(dev); - return sprintf(buf, "%d\n", data->fan1_pulses); + struct amc6821_data *data = dev_get_drvdata(dev); + u32 regval; + int err; + + err = regmap_read(data->regmap, AMC6821_REG_CONF4, ®val); + if (err) + return err; + + return sysfs_emit(buf, "%d\n", (regval & AMC6821_CONF4_PSPR) ? 4 : 2); } static ssize_t fan1_pulses_store(struct device *dev, @@ -664,40 +652,22 @@ static ssize_t fan1_pulses_store(struct device *dev, size_t count) { struct amc6821_data *data = dev_get_drvdata(dev); - struct i2c_client *client = data->client; long val; - int config = kstrtol(buf, 10, &val); - if (config) - return config; + int err; + + err = kstrtol(buf, 10, &val); + if (err) + return err; + + if (val != 2 && val != 4) + return -EINVAL; + + err = regmap_update_bits(data->regmap, AMC6821_REG_CONF4, + AMC6821_CONF4_PSPR, + val == 4 ? AMC6821_CONF4_PSPR : 0); + if (err) + return err; - mutex_lock(&data->update_lock); - config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF4); - if (config < 0) { - dev_err(&client->dev, - "Error reading configuration register, aborting.\n"); - count = config; - goto EXIT; - } - switch (val) { - case 2: - config &= ~AMC6821_CONF4_PSPR; - data->fan1_pulses = 2; - break; - case 4: - config |= AMC6821_CONF4_PSPR; - data->fan1_pulses = 4; - break; - default: - count = -EINVAL; - goto EXIT; - } - if (i2c_smbus_write_byte_data(client, AMC6821_REG_CONF4, config)) { - dev_err(&client->dev, - "Configuration register write error, aborting.\n"); - count = -EIO; - } -EXIT: - mutex_unlock(&data->update_lock); return count; } @@ -829,110 +799,83 @@ static int amc6821_detect( return 0; } -static int amc6821_init_client(struct i2c_client *client) +static int amc6821_init_client(struct amc6821_data *data) { - int config; - int err = -EIO; + struct regmap *regmap = data->regmap; + int err; + + err = amc6821_init_auto_point_data(data); + if (err) + return err; if (init) { - config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF4); - - if (config < 0) { - dev_err(&client->dev, - "Error reading configuration register, aborting.\n"); - return err; - } - - config |= AMC6821_CONF4_MODE; - - if (i2c_smbus_write_byte_data(client, AMC6821_REG_CONF4, - config)) { - dev_err(&client->dev, - "Configuration register write error, aborting.\n"); + err = regmap_set_bits(regmap, AMC6821_REG_CONF4, AMC6821_CONF4_MODE); + if (err) return err; - } - - config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF3); - - if (config < 0) { - dev_err(&client->dev, - "Error reading configuration register, aborting.\n"); + err = regmap_clear_bits(regmap, AMC6821_REG_CONF3, AMC6821_CONF3_THERM_FAN_EN); + if (err) return err; - } - - dev_info(&client->dev, "Revision %d\n", config & 0x0f); - - config &= ~AMC6821_CONF3_THERM_FAN_EN; - - if (i2c_smbus_write_byte_data(client, AMC6821_REG_CONF3, - config)) { - dev_err(&client->dev, - "Configuration register write error, aborting.\n"); + err = regmap_clear_bits(regmap, AMC6821_REG_CONF2, + AMC6821_CONF2_RTFIE | + AMC6821_CONF2_LTOIE | + AMC6821_CONF2_RTOIE); + if (err) return err; - } - config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF2); - - if (config < 0) { - dev_err(&client->dev, - "Error reading configuration register, aborting.\n"); + err = regmap_update_bits(regmap, AMC6821_REG_CONF1, + AMC6821_CONF1_THERMOVIE | AMC6821_CONF1_FANIE | + AMC6821_CONF1_START | AMC6821_CONF1_PWMINV, + AMC6821_CONF1_START | + (pwminv ? AMC6821_CONF1_PWMINV : 0)); + if (err) return err; - } - - config &= ~AMC6821_CONF2_RTFIE; - config &= ~AMC6821_CONF2_LTOIE; - config &= ~AMC6821_CONF2_RTOIE; - if (i2c_smbus_write_byte_data(client, - AMC6821_REG_CONF2, config)) { - dev_err(&client->dev, - "Configuration register write error, aborting.\n"); - return err; - } - - config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF1); - - if (config < 0) { - dev_err(&client->dev, - "Error reading configuration register, aborting.\n"); - return err; - } - - config &= ~AMC6821_CONF1_THERMOVIE; - config &= ~AMC6821_CONF1_FANIE; - config |= AMC6821_CONF1_START; - if (pwminv) - config |= AMC6821_CONF1_PWMINV; - else - config &= ~AMC6821_CONF1_PWMINV; - - if (i2c_smbus_write_byte_data( - client, AMC6821_REG_CONF1, config)) { - dev_err(&client->dev, - "Configuration register write error, aborting.\n"); - return err; - } } return 0; } +static bool amc6821_volatile_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case AMC6821_REG_STAT1: + case AMC6821_REG_STAT2: + case AMC6821_REG_TEMP_LO: + case AMC6821_REG_TDATA_LOW: + case AMC6821_REG_LTEMP_HI: + case AMC6821_REG_RTEMP_HI: + case AMC6821_REG_TDATA_HI: + return true; + default: + return false; + } +} + +static const struct regmap_config amc6821_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = AMC6821_REG_CONF3, + .volatile_reg = amc6821_volatile_reg, + .cache_type = REGCACHE_MAPLE, +}; + static int amc6821_probe(struct i2c_client *client) { struct device *dev = &client->dev; struct amc6821_data *data; struct device *hwmon_dev; + struct regmap *regmap; int err; data = devm_kzalloc(dev, sizeof(struct amc6821_data), GFP_KERNEL); if (!data) return -ENOMEM; - data->client = client; - mutex_init(&data->update_lock); + regmap = devm_regmap_init_i2c(client, &amc6821_regmap_config); + if (IS_ERR(regmap)) + return dev_err_probe(dev, PTR_ERR(regmap), + "Failed to initialize regmap\n"); + data->regmap = regmap; - /* - * Initialize the amc6821 chip - */ - err = amc6821_init_client(client); + err = amc6821_init_client(data); if (err) return err; From patchwork Mon Jul 1 21:23:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13718662 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 75453175545; Mon, 1 Jul 2024 21:24:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869050; cv=none; b=QBKlrfz0J9o/oEwp5wx4bC0PLzYoMq1Zw+gmO8BVREBu8mThgf0tW2wT28xAzBOg9smh+cH+0waUV5Wlze92TWtcPiO0wPs7lQsgRqtD4bchTHVD8XR1ouPyWjf1T6zoPs2ahS1vsAMIHktkrzCziYfNbJVFLKag8s2GESIBptA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869050; c=relaxed/simple; bh=w2ytLGhxJ8xqtikhcDFb/101DvsxVLKLiN7+ClASY6E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lalpiRDkZehL9t1WHr4rNmYpwP51R6s9ydWmbJnty6zTa/XYWi1TdQzNkrP1FdR+HxiMsPqQet3QzJLpp2WblNX2S9g4HTPK9/fv1w43jgizmwtJt8Idsk2SUmVNA7h+hse8M+6oHh7f6mRZaqEApXbnnyZvAsTvy+03mntCl44= 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=MEixF0aX; arc=none smtp.client-ip=209.85.214.174 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="MEixF0aX" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1f4a5344ec7so24941905ad.1; Mon, 01 Jul 2024 14:24:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719869047; x=1720473847; 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=pTDoHQSoLzBP9qWdmxxdqRGtTFu78ggoAtSKR8+CFuA=; b=MEixF0aX5pQVUYmCAqPIfPSWQ6LnEUCVC1MGzn1Cp4KK27BqpYHKvKjwbT2/dS9BpH KavPpkweKiHSyiTCXWQboE4lBxqtpy8/U6vESBNSWOEJVUQXW9ftR/2MBDR/K8pkxlu/ 4hVA22Wje2F8AU+/qp0R23IojjDaDVfNLpQ1zCO+bI+FDZ+LMeKFnK9pwmcf8mosrbRr d7EUmT4RyLHCccVVJkl58NdkmgbTXLKPDzh37iVtluLkFACyHIUnnErTAe4asXz/zOhZ oISyNkK4oOEIa5UTzePs2dT+7h61ICnCX1ZvD1pf23KeiUMvHqek9pnhtqRd1ey1GA7y fsQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719869047; x=1720473847; 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=pTDoHQSoLzBP9qWdmxxdqRGtTFu78ggoAtSKR8+CFuA=; b=YhPM4RTK12HCaAjxjXoY3V7C0ypdy2mzk4eha2Q757MaRWGvKmNMT+BPfoHkzBIvRx dL7Eg3pZDhBXqdXcWNdDP4+WAl6M2fAmfRXFjBlJhrF8Qpt/gL7FaP9/Nvbi9hC7NJhD QJCzrff6wUfJJbbGibgYlZ8DTrCR+m5mvgWjqmvFr3ki/A9HlNfM3ZFjAKQToZCXPGi5 Tfm+ZF5XB27REJI70thvBdiYes8DC8Obw71V3tejU0v6f+/ccfLSlbsYx8pwSCXYlJFy 6a6/YUMja3neX+noxaiMz4FA85nQM4PHYfc4mf/nhBUN+1bZ294moYwqzgmpGfHciwPu EyCw== X-Gm-Message-State: AOJu0YzEPKAyE+c+yOeXH0IecWdQwWYmlwi3Tu0mkCz4jaoZVTdKfB1f dpPzYYR5exGcgZOWWElQOHzTGPvOhl2IlKtzmdbNfLbbafsbtXDqPDPaLQ== X-Google-Smtp-Source: AGHT+IHXORxruQ4TT2KAZusn2tzEmegiZY0CZlxrUZ7bTVytQEg/2hAg2Jn4xvh6kAidqoo3OnTluQ== X-Received: by 2002:a17:902:f203:b0:1f9:e97d:9460 with SMTP id d9443c01a7336-1fac7e7fcf3mr99242875ad.16.1719869047004; Mon, 01 Jul 2024 14:24:07 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fac1598d35sm69427795ad.285.2024.07.01.14.24.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 14:24:06 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Farouk Bouabid , Quentin Schulz , Guenter Roeck Subject: [PATCH v2 10/11] hwmon: (amc6821) Convert to with_info API Date: Mon, 1 Jul 2024 14:23:47 -0700 Message-Id: <20240701212348.1670617-11-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240701212348.1670617-1-linux@roeck-us.net> References: <20240701212348.1670617-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 make it easier to maintain. This also reduces code size by approximately 20%. No functional change intended. Signed-off-by: Guenter Roeck Reviewed-by: Quentin Schulz --- v2: Adjust to changes made in preceding patches drivers/hwmon/amc6821.c | 744 +++++++++++++++++++++------------------- 1 file changed, 390 insertions(+), 354 deletions(-) diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index 3fe0bfeac843..5a3c089ae06f 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -6,6 +6,9 @@ * * Based on max6650.c: * Copyright (C) 2007 Hans J. Koch + * + * Conversion to regmap and with_info API: + * Copyright (C) 2024 Guenter Roeck */ #include @@ -107,28 +110,6 @@ module_param(init, int, 0444); #define AMC6821_STAT2_L_THERM BIT(6) #define AMC6821_STAT2_THERM_IN BIT(7) -enum {IDX_TEMP1_INPUT = 0, IDX_TEMP1_MIN, IDX_TEMP1_MAX, - IDX_TEMP1_CRIT, IDX_TEMP2_INPUT, IDX_TEMP2_MIN, - IDX_TEMP2_MAX, IDX_TEMP2_CRIT, - TEMP_IDX_LEN, }; - -static const u8 temp_reg[] = {AMC6821_REG_LTEMP_HI, - AMC6821_REG_LTEMP_LIMIT_MIN, - AMC6821_REG_LTEMP_LIMIT_MAX, - AMC6821_REG_LTEMP_CRIT, - AMC6821_REG_RTEMP_HI, - AMC6821_REG_RTEMP_LIMIT_MIN, - AMC6821_REG_RTEMP_LIMIT_MAX, - AMC6821_REG_RTEMP_CRIT, }; - -enum {IDX_FAN1_INPUT = 0, IDX_FAN1_MIN, IDX_FAN1_MAX, IDX_FAN1_TARGET, - FAN1_IDX_LEN, }; - -static const u8 fan_reg_low[] = {AMC6821_REG_TDATA_LOW, - AMC6821_REG_TACH_LLIMITL, - AMC6821_REG_TACH_HLIMITL, - AMC6821_REG_TACH_SETTINGL, }; - /* * Client data (each client gets its own) */ @@ -189,219 +170,319 @@ static int amc6821_init_auto_point_data(struct amc6821_data *data) return 0; } -static ssize_t temp_show(struct device *dev, struct device_attribute *devattr, - char *buf) +static int amc6821_temp_read_values(struct regmap *regmap, u32 attr, int channel, long *val) { - struct amc6821_data *data = dev_get_drvdata(dev); - int ix = to_sensor_dev_attr(devattr)->index; + int reg, err; u32 regval; - int err; - err = regmap_read(data->regmap, temp_reg[ix], ®val); - if (err) - return err; - - return sysfs_emit(buf, "%d\n", sign_extend32(regval, 7) * 1000); -} - -static ssize_t temp_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct amc6821_data *data = dev_get_drvdata(dev); - int ix = to_sensor_dev_attr(attr)->index; - long val; - int err; - - int ret = kstrtol(buf, 10, &val); - if (ret) - return ret; - val = clamp_val(val / 1000, -128, 127); - - err = regmap_write(data->regmap, temp_reg[ix], val); - if (err) - return err; - - return count; -} - -static ssize_t temp_alarm_show(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct amc6821_data *data = dev_get_drvdata(dev); - int ix = to_sensor_dev_attr(devattr)->index; - u32 regval, mask, reg; - int err; - - switch (ix) { - case IDX_TEMP1_MIN: - reg = AMC6821_REG_STAT1; - mask = AMC6821_STAT1_LTL; + switch (attr) { + case hwmon_temp_input: + reg = channel ? AMC6821_REG_RTEMP_HI : AMC6821_REG_LTEMP_HI; break; - case IDX_TEMP1_MAX: - reg = AMC6821_REG_STAT1; - mask = AMC6821_STAT1_LTH; + case hwmon_temp_min: + reg = channel ? AMC6821_REG_RTEMP_LIMIT_MIN : AMC6821_REG_LTEMP_LIMIT_MIN; break; - case IDX_TEMP1_CRIT: - reg = AMC6821_REG_STAT2; - mask = AMC6821_STAT2_LTC; + case hwmon_temp_max: + reg = channel ? AMC6821_REG_RTEMP_LIMIT_MAX : AMC6821_REG_LTEMP_LIMIT_MAX; break; - case IDX_TEMP2_MIN: - reg = AMC6821_REG_STAT1; - mask = AMC6821_STAT1_RTL; - break; - case IDX_TEMP2_MAX: - reg = AMC6821_REG_STAT1; - mask = AMC6821_STAT1_RTH; - break; - case IDX_TEMP2_CRIT: - reg = AMC6821_REG_STAT2; - mask = AMC6821_STAT2_RTC; + case hwmon_temp_crit: + reg = channel ? AMC6821_REG_RTEMP_CRIT : AMC6821_REG_LTEMP_CRIT; break; default: - return -EINVAL; + return -EOPNOTSUPP; } - err = regmap_read(data->regmap, reg, ®val); + err = regmap_read(regmap, reg, ®val); if (err) return err; - return sysfs_emit(buf, "%d\n", !!(regval & mask)); + *val = sign_extend32(regval, 7) * 1000; + return 0; } -static ssize_t temp2_fault_show(struct device *dev, - struct device_attribute *devattr, char *buf) +static int amc6821_read_alarms(struct regmap *regmap, enum hwmon_sensor_types type, + u32 attr, int channel, long *val) { - struct amc6821_data *data = dev_get_drvdata(dev); + int reg, mask, err; u32 regval; - int err; - err = regmap_read(data->regmap, AMC6821_REG_STAT1, ®val); - if (err) - return err; - - return sysfs_emit(buf, "%d\n", !!(regval & AMC6821_STAT1_RTF)); -} - -static ssize_t pwm1_show(struct device *dev, struct device_attribute *devattr, - char *buf) -{ - struct amc6821_data *data = dev_get_drvdata(dev); - u32 regval; - int err; - - err = regmap_read(data->regmap, AMC6821_REG_DCY, ®val); - if (err) - return err; - - return sysfs_emit(buf, "%d\n", regval); -} - -static ssize_t pwm1_store(struct device *dev, - struct device_attribute *devattr, const char *buf, - size_t count) -{ - struct amc6821_data *data = dev_get_drvdata(dev); - u8 val; - int ret = kstrtou8(buf, 10, &val); - if (ret) - return ret; - - ret = regmap_write(data->regmap, AMC6821_REG_DCY, val); - if (ret) - return ret; - - return count; -} - -static ssize_t pwm1_enable_show(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct amc6821_data *data = dev_get_drvdata(dev); - int err; - u32 val; - - err = regmap_read(data->regmap, AMC6821_REG_CONF1, &val); - if (err) - return err; - switch (val & (AMC6821_CONF1_FDRC0 | AMC6821_CONF1_FDRC1)) { - case 0: - val = 1; /* manual */ + switch (type) { + case hwmon_temp: + switch (attr) { + case hwmon_temp_min_alarm: + reg = AMC6821_REG_STAT1; + mask = channel ? AMC6821_STAT1_RTL : AMC6821_STAT1_LTL; + break; + case hwmon_temp_max_alarm: + reg = AMC6821_REG_STAT1; + mask = channel ? AMC6821_STAT1_RTH : AMC6821_STAT1_LTH; + break; + case hwmon_temp_crit_alarm: + reg = AMC6821_REG_STAT2; + mask = channel ? AMC6821_STAT2_RTC : AMC6821_STAT2_LTC; + break; + case hwmon_temp_fault: + reg = AMC6821_REG_STAT1; + mask = AMC6821_STAT1_RTF; + break; + default: + return -EOPNOTSUPP; + } break; - case AMC6821_CONF1_FDRC0: - val = 4; /* target rpm (fan1_target) controlled */ - break; - case AMC6821_CONF1_FDRC1: - val = 2; /* remote temp controlled */ + case hwmon_fan: + switch (attr) { + case hwmon_fan_fault: + reg = AMC6821_REG_STAT1; + mask = AMC6821_STAT1_FANS; + break; + default: + return -EOPNOTSUPP; + } break; default: - val = 3; /* max(local, remote) temp controlled */ - break; + return -EOPNOTSUPP; } - return sysfs_emit(buf, "%d\n", val); + err = regmap_read(regmap, reg, ®val); + if (err) + return err; + *val = !!(regval & mask); + return 0; } -static ssize_t pwm1_enable_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static int amc6821_temp_read(struct device *dev, u32 attr, int channel, long *val) { struct amc6821_data *data = dev_get_drvdata(dev); - long val; + + switch (attr) { + case hwmon_temp_input: + case hwmon_temp_min: + case hwmon_temp_max: + case hwmon_temp_crit: + return amc6821_temp_read_values(data->regmap, attr, channel, val); + case hwmon_temp_min_alarm: + case hwmon_temp_max_alarm: + case hwmon_temp_crit_alarm: + case hwmon_temp_fault: + return amc6821_read_alarms(data->regmap, hwmon_temp, attr, channel, val); + default: + return -EOPNOTSUPP; + } +} + +static int amc6821_temp_write(struct device *dev, u32 attr, int channel, long val) +{ + struct amc6821_data *data = dev_get_drvdata(dev); + int reg; + + val = DIV_ROUND_CLOSEST(clamp_val(val, -128000, 127000), 1000); + + switch (attr) { + case hwmon_temp_min: + reg = channel ? AMC6821_REG_RTEMP_LIMIT_MIN : AMC6821_REG_LTEMP_LIMIT_MIN; + break; + case hwmon_temp_max: + reg = channel ? AMC6821_REG_RTEMP_LIMIT_MAX : AMC6821_REG_LTEMP_LIMIT_MAX; + break; + case hwmon_temp_crit: + reg = channel ? AMC6821_REG_RTEMP_CRIT : AMC6821_REG_LTEMP_CRIT; + break; + default: + return -EOPNOTSUPP; + } + return regmap_write(data->regmap, reg, val); +} + +static int amc6821_pwm_read(struct device *dev, u32 attr, long *val) +{ + struct amc6821_data *data = dev_get_drvdata(dev); + struct regmap *regmap = data->regmap; + u32 regval; + int err; + + switch (attr) { + case hwmon_pwm_enable: + err = regmap_read(regmap, AMC6821_REG_CONF1, ®val); + if (err) + return err; + switch (regval & (AMC6821_CONF1_FDRC0 | AMC6821_CONF1_FDRC1)) { + case 0: + *val = 1; /* manual */ + break; + case AMC6821_CONF1_FDRC0: + *val = 4; /* target rpm (fan1_target) controlled */ + break; + case AMC6821_CONF1_FDRC1: + *val = 2; /* remote temp controlled */ + break; + default: + *val = 3; /* max(local, remote) temp controlled */ + break; + } + return 0; + case hwmon_pwm_auto_channels_temp: + err = regmap_read(regmap, AMC6821_REG_CONF1, ®val); + if (err) + return err; + switch (regval & (AMC6821_CONF1_FDRC0 | AMC6821_CONF1_FDRC1)) { + case 0: + case AMC6821_CONF1_FDRC0: + *val = 0; /* manual or target rpm controlled */ + break; + case AMC6821_CONF1_FDRC1: + *val = 2; /* remote temp controlled */ + break; + default: + *val = 3; /* max(local, remote) temp controlled */ + break; + } + return 0; + case hwmon_pwm_input: + err = regmap_read(regmap, AMC6821_REG_DCY, ®val); + if (err) + return err; + *val = regval; + return 0; + default: + return -EOPNOTSUPP; + } +} + +static int amc6821_pwm_write(struct device *dev, u32 attr, long val) +{ + struct amc6821_data *data = dev_get_drvdata(dev); + struct regmap *regmap = data->regmap; u32 mode; - int err; - err = kstrtol(buf, 10, &val); - if (err) - return err; - - switch (val) { - case 1: - mode = 0; - break; - case 2: - mode = AMC6821_CONF1_FDRC1; - break; - case 3: - mode = AMC6821_CONF1_FDRC0 | AMC6821_CONF1_FDRC1; - break; - case 4: - mode = AMC6821_CONF1_FDRC0; - break; + switch (attr) { + case hwmon_pwm_enable: + switch (val) { + case 1: + mode = 0; + break; + case 2: + mode = AMC6821_CONF1_FDRC1; + break; + case 3: + mode = AMC6821_CONF1_FDRC0 | AMC6821_CONF1_FDRC1; + break; + case 4: + mode = AMC6821_CONF1_FDRC0; + break; + default: + return -EINVAL; + } + return regmap_update_bits(regmap, AMC6821_REG_CONF1, + AMC6821_CONF1_FDRC0 | AMC6821_CONF1_FDRC1, + mode); + case hwmon_pwm_input: + if (val < 0 || val > 255) + return -EINVAL; + return regmap_write(regmap, AMC6821_REG_DCY, val); default: - return -EINVAL; + return -EOPNOTSUPP; } - - err = regmap_update_bits(data->regmap, AMC6821_REG_CONF1, - AMC6821_CONF1_FDRC0 | AMC6821_CONF1_FDRC1, - mode); - if (err) - return err; - - return count; } -static ssize_t pwm1_auto_channels_temp_show(struct device *dev, - struct device_attribute *devattr, - char *buf) +static int amc6821_fan_read_rpm(struct regmap *regmap, u32 attr, long *val) { - struct amc6821_data *data = dev_get_drvdata(dev); - u32 val; - int err; + int reg, err; + u8 regs[2]; + u32 regval; - err = regmap_read(data->regmap, AMC6821_REG_CONF1, &val); - if (err) - return err; - switch (val & (AMC6821_CONF1_FDRC0 | AMC6821_CONF1_FDRC1)) { - case 0: - case AMC6821_CONF1_FDRC0: - val = 0; /* manual or target rpm controlled */ + switch (attr) { + case hwmon_fan_input: + reg = AMC6821_REG_TDATA_LOW; break; - case AMC6821_CONF1_FDRC1: - val = 2; /* remote temp controlled */ + case hwmon_fan_min: + reg = AMC6821_REG_TACH_LLIMITL; + break; + case hwmon_fan_max: + reg = AMC6821_REG_TACH_HLIMITL; + break; + case hwmon_fan_target: + reg = AMC6821_REG_TACH_SETTINGL; break; default: - val = 3; /* max(local, remote) temp controlled */ - break; + return -EOPNOTSUPP; } - return sysfs_emit(buf, "%d\n", val); + err = regmap_bulk_read(regmap, reg, regs, 2); + if (err) + return err; + + regval = (regs[1] << 8) | regs[0]; + *val = regval ? 6000000 / regval : 0; + + return 0; +} + +static int amc6821_fan_read(struct device *dev, u32 attr, long *val) +{ + struct amc6821_data *data = dev_get_drvdata(dev); + struct regmap *regmap = data->regmap; + u32 regval; + int err; + + switch (attr) { + case hwmon_fan_input: + case hwmon_fan_min: + case hwmon_fan_max: + case hwmon_fan_target: + return amc6821_fan_read_rpm(regmap, attr, val); + case hwmon_fan_fault: + return amc6821_read_alarms(regmap, hwmon_fan, attr, 0, val); + case hwmon_fan_pulses: + err = regmap_read(regmap, AMC6821_REG_CONF4, ®val); + if (err) + return err; + *val = (regval & AMC6821_CONF4_PSPR) ? 4 : 2; + return 0; + default: + return -EOPNOTSUPP; + } +} + +static int amc6821_fan_write(struct device *dev, u32 attr, long val) +{ + struct amc6821_data *data = dev_get_drvdata(dev); + struct regmap *regmap = data->regmap; + u8 regs[2]; + int reg; + + if (attr == hwmon_fan_pulses) { + if (val != 2 && val != 4) + return -EINVAL; + return regmap_update_bits(regmap, AMC6821_REG_CONF4, + AMC6821_CONF4_PSPR, + val == 4 ? AMC6821_CONF4_PSPR : 0); + } + + if (val < 0) + return -EINVAL; + + switch (attr) { + case hwmon_fan_min: + if (!val) /* no unlimited minimum speed */ + return -EINVAL; + reg = AMC6821_REG_TACH_LLIMITL; + break; + case hwmon_fan_max: + reg = AMC6821_REG_TACH_HLIMITL; + break; + case hwmon_fan_target: + if (!val) /* no unlimited target speed */ + return -EINVAL; + reg = AMC6821_REG_TACH_SETTINGL; + break; + default: + return -EOPNOTSUPP; + } + + val = val ? 6000000 / clamp_val(val, 1, 6000000) : 0; + val = clamp_val(val, 0, 0xffff); + + regs[0] = val & 0xff; + regs[1] = val >> 8; + + return regmap_bulk_write(data->regmap, reg, regs, 2); } static ssize_t temp_auto_point_temp_show(struct device *dev, @@ -572,134 +653,9 @@ static ssize_t pwm1_auto_point_pwm_store(struct device *dev, return count; } -static ssize_t fan_show(struct device *dev, struct device_attribute *devattr, - char *buf) -{ - struct amc6821_data *data = dev_get_drvdata(dev); - int ix = to_sensor_dev_attr(devattr)->index; - u32 regval; - u8 regs[2]; - int err; - - err = regmap_bulk_read(data->regmap, fan_reg_low[ix], regs, 2); - if (err) - return err; - regval = (regs[1] << 8) | regs[0]; - - return sysfs_emit(buf, "%d\n", 6000000 / (regval ? : 1)); -} - -static ssize_t fan1_fault_show(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct amc6821_data *data = dev_get_drvdata(dev); - u32 regval; - int err; - - err = regmap_read(data->regmap, AMC6821_REG_STAT1, ®val); - if (err) - return err; - - return sysfs_emit(buf, "%d\n", !!(regval & AMC6821_STAT1_FANS)); -} - -static ssize_t fan_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct amc6821_data *data = dev_get_drvdata(dev); - int ix = to_sensor_dev_attr(attr)->index; - unsigned long val; - u8 regs[2]; - int err; - - err = kstrtoul(buf, 10, &val); - if (err) - return err; - - /* Minimum and target fan speed must not be unlimited (0) */ - if ((ix == IDX_FAN1_MIN || ix == IDX_FAN1_TARGET) && !val) - return -EINVAL; - - val = val > 0 ? 6000000 / clamp_val(val, 1, 6000000) : 0; - val = clamp_val(val, 0, 0xFFFF); - - regs[0] = val & 0xff; - regs[1] = val >> 8; - - err = regmap_bulk_write(data->regmap, fan_reg_low[ix], regs, 2); - if (err) - return err; - - return count; -} - -static ssize_t fan1_pulses_show(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct amc6821_data *data = dev_get_drvdata(dev); - u32 regval; - int err; - - err = regmap_read(data->regmap, AMC6821_REG_CONF4, ®val); - if (err) - return err; - - return sysfs_emit(buf, "%d\n", (regval & AMC6821_CONF4_PSPR) ? 4 : 2); -} - -static ssize_t fan1_pulses_store(struct device *dev, - struct device_attribute *attr, const char *buf, - size_t count) -{ - struct amc6821_data *data = dev_get_drvdata(dev); - long val; - int err; - - err = kstrtol(buf, 10, &val); - if (err) - return err; - - if (val != 2 && val != 4) - return -EINVAL; - - err = regmap_update_bits(data->regmap, AMC6821_REG_CONF4, - AMC6821_CONF4_PSPR, - val == 4 ? AMC6821_CONF4_PSPR : 0); - if (err) - return err; - - return count; -} - -static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, IDX_TEMP1_INPUT); -static SENSOR_DEVICE_ATTR_RW(temp1_min, temp, IDX_TEMP1_MIN); -static SENSOR_DEVICE_ATTR_RW(temp1_max, temp, IDX_TEMP1_MAX); -static SENSOR_DEVICE_ATTR_RW(temp1_crit, temp, IDX_TEMP1_CRIT); -static SENSOR_DEVICE_ATTR_RO(temp1_min_alarm, temp_alarm, IDX_TEMP1_MIN); -static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, temp_alarm, IDX_TEMP1_MAX); -static SENSOR_DEVICE_ATTR_RO(temp1_crit_alarm, temp_alarm, IDX_TEMP1_CRIT); -static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, IDX_TEMP2_INPUT); -static SENSOR_DEVICE_ATTR_RW(temp2_min, temp, IDX_TEMP2_MIN); -static SENSOR_DEVICE_ATTR_RW(temp2_max, temp, IDX_TEMP2_MAX); -static SENSOR_DEVICE_ATTR_RW(temp2_crit, temp, IDX_TEMP2_CRIT); -static SENSOR_DEVICE_ATTR_RO(temp2_fault, temp2_fault, 0); -static SENSOR_DEVICE_ATTR_RO(temp2_min_alarm, temp_alarm, IDX_TEMP2_MIN); -static SENSOR_DEVICE_ATTR_RO(temp2_max_alarm, temp_alarm, IDX_TEMP2_MAX); -static SENSOR_DEVICE_ATTR_RO(temp2_crit_alarm, temp_alarm, IDX_TEMP2_CRIT); -static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, IDX_FAN1_INPUT); -static SENSOR_DEVICE_ATTR_RW(fan1_min, fan, IDX_FAN1_MIN); -static SENSOR_DEVICE_ATTR_RW(fan1_max, fan, IDX_FAN1_MAX); -static SENSOR_DEVICE_ATTR_RW(fan1_target, fan, IDX_FAN1_TARGET); -static SENSOR_DEVICE_ATTR_RO(fan1_fault, fan1_fault, 0); -static SENSOR_DEVICE_ATTR_RW(fan1_pulses, fan1_pulses, 0); - -static SENSOR_DEVICE_ATTR_RW(pwm1, pwm1, 0); -static SENSOR_DEVICE_ATTR_RW(pwm1_enable, pwm1_enable, 0); static SENSOR_DEVICE_ATTR_RO(pwm1_auto_point1_pwm, pwm1_auto_point_pwm, 0); static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point2_pwm, pwm1_auto_point_pwm, 1); static SENSOR_DEVICE_ATTR_RO(pwm1_auto_point3_pwm, pwm1_auto_point_pwm, 2); -static SENSOR_DEVICE_ATTR_RO(pwm1_auto_channels_temp, pwm1_auto_channels_temp, - 0); static SENSOR_DEVICE_ATTR_2_RO(temp1_auto_point1_temp, temp_auto_point_temp, 1, 0); static SENSOR_DEVICE_ATTR_2_RW(temp1_auto_point2_temp, temp_auto_point_temp, @@ -715,30 +671,6 @@ static SENSOR_DEVICE_ATTR_2_RW(temp2_auto_point3_temp, temp_auto_point_temp, 2, 2); static struct attribute *amc6821_attrs[] = { - &sensor_dev_attr_temp1_input.dev_attr.attr, - &sensor_dev_attr_temp1_min.dev_attr.attr, - &sensor_dev_attr_temp1_max.dev_attr.attr, - &sensor_dev_attr_temp1_crit.dev_attr.attr, - &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, - &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, - &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, - &sensor_dev_attr_temp2_input.dev_attr.attr, - &sensor_dev_attr_temp2_min.dev_attr.attr, - &sensor_dev_attr_temp2_max.dev_attr.attr, - &sensor_dev_attr_temp2_crit.dev_attr.attr, - &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, - &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, - &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, - &sensor_dev_attr_temp2_fault.dev_attr.attr, - &sensor_dev_attr_fan1_input.dev_attr.attr, - &sensor_dev_attr_fan1_min.dev_attr.attr, - &sensor_dev_attr_fan1_max.dev_attr.attr, - &sensor_dev_attr_fan1_target.dev_attr.attr, - &sensor_dev_attr_fan1_fault.dev_attr.attr, - &sensor_dev_attr_fan1_pulses.dev_attr.attr, - &sensor_dev_attr_pwm1.dev_attr.attr, - &sensor_dev_attr_pwm1_enable.dev_attr.attr, - &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr, @@ -750,13 +682,117 @@ static struct attribute *amc6821_attrs[] = { &sensor_dev_attr_temp2_auto_point3_temp.dev_attr.attr, NULL }; - ATTRIBUTE_GROUPS(amc6821); +static int amc6821_read(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long *val) +{ + switch (type) { + case hwmon_temp: + return amc6821_temp_read(dev, attr, channel, val); + case hwmon_fan: + return amc6821_fan_read(dev, attr, val); + case hwmon_pwm: + return amc6821_pwm_read(dev, attr, val); + default: + return -EOPNOTSUPP; + } +} + +static int amc6821_write(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long val) +{ + switch (type) { + case hwmon_temp: + return amc6821_temp_write(dev, attr, channel, val); + case hwmon_fan: + return amc6821_fan_write(dev, attr, val); + case hwmon_pwm: + return amc6821_pwm_write(dev, attr, val); + default: + return -EOPNOTSUPP; + } +} + +static umode_t amc6821_is_visible(const void *data, + enum hwmon_sensor_types type, + u32 attr, int channel) +{ + switch (type) { + case hwmon_temp: + switch (attr) { + case hwmon_temp_input: + case hwmon_temp_min_alarm: + case hwmon_temp_max_alarm: + case hwmon_temp_crit_alarm: + case hwmon_temp_fault: + return 0444; + case hwmon_temp_min: + case hwmon_temp_max: + case hwmon_temp_crit: + return 0644; + default: + return 0; + } + case hwmon_fan: + switch (attr) { + case hwmon_fan_input: + case hwmon_fan_fault: + return 0444; + case hwmon_fan_pulses: + case hwmon_fan_min: + case hwmon_fan_max: + case hwmon_fan_target: + return 0644; + default: + return 0; + } + case hwmon_pwm: + switch (attr) { + case hwmon_pwm_enable: + case hwmon_pwm_input: + return 0644; + case hwmon_pwm_auto_channels_temp: + return 0444; + default: + return 0; + } + default: + return 0; + } +} + +static const struct hwmon_channel_info * const amc6821_info[] = { + HWMON_CHANNEL_INFO(temp, + HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | + HWMON_T_CRIT | HWMON_T_MIN_ALARM | + HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM, + HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | + HWMON_T_CRIT | HWMON_T_MIN_ALARM | + HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM | + HWMON_T_FAULT), + HWMON_CHANNEL_INFO(fan, + HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_MAX | + HWMON_F_TARGET | HWMON_F_PULSES | HWMON_F_FAULT), + HWMON_CHANNEL_INFO(pwm, + HWMON_PWM_INPUT | HWMON_PWM_ENABLE | + HWMON_PWM_AUTO_CHANNELS_TEMP), + NULL +}; + +static const struct hwmon_ops amc6821_hwmon_ops = { + .is_visible = amc6821_is_visible, + .read = amc6821_read, + .write = amc6821_write, +}; + +static const struct hwmon_chip_info amc6821_chip_info = { + .ops = &amc6821_hwmon_ops, + .info = amc6821_info, +}; + /* Return 0 if detection is successful, -ENODEV otherwise */ -static int amc6821_detect( - struct i2c_client *client, - struct i2c_board_info *info) +static int amc6821_detect(struct i2c_client *client, struct i2c_board_info *info) { struct i2c_adapter *adapter = client->adapter; int address = client->addr; @@ -879,9 +915,9 @@ static int amc6821_probe(struct i2c_client *client) if (err) return err; - hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, - data, - amc6821_groups); + hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, + data, &amc6821_chip_info, + amc6821_groups); return PTR_ERR_OR_ZERO(hwmon_dev); } From patchwork Mon Jul 1 21:23:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13718663 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 C552817556B; Mon, 1 Jul 2024 21:24:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869051; cv=none; b=NxgxnUXvxyUukfpsQpO/YJ0mvB32yVAUH5m4j7/c+ZIaE8CeQitpa1zim3pXV2k39TUdb6v1bvZIHnt8xXKxHRNIZlPBSPN/efD7uJofkPV6nySKt5V5VDFy3SgaSopshicQfymzjOjNgJmN+wFqggjRq3EHbMq/qtZk+NMVR7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719869051; c=relaxed/simple; bh=HtaUQZY6PdMTzY4wNxSAu9k0222peQdQm0FUhCEWFuc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Nd8WrhvbQ9pAbgmrOz62eiGpWKylaJrtODCkfSRcQCnnCYWczZ/SjK3PGN7gOOBJ9Hez5f8XGJYoaePz278TRBInuRLiUzZipLJhvtVfg/UPs/pCeOZ5QcLJ5OVuSiEDmc2+QzC8YHo0YCTfoJZwsox0I6Wjn8172GGdwJBsieI= 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=H86NSpSK; arc=none smtp.client-ip=209.85.214.170 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="H86NSpSK" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1f6a837e9a3so14163255ad.1; Mon, 01 Jul 2024 14:24:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719869049; x=1720473849; 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=YOpXTWHEXnjjvx9LV4U8IMiTxHBdnBSzp3nuNfveMIA=; b=H86NSpSKvCzLb5nn+UHYUeQpd1MrgUocTuu4B6LVR7yKvYzmPaT2YoiLh16Neuxz/U 04jfU1le94NWE0IdnbqQOqfutButu3G2mdlzNou0r6nTE/NtJZuIQe4u6MvbHIMP2bXj Ub8ROTZJUsmtd4FQdHnBhAGZ56KQD6DT+FZkLDDuPVj52t8HH70Ny660LbvH2pZ0hd+A 5I+lCzjafd7z4wzMeYrDcekU9tBa2MFB4pswDSvC4CgKR9NErYmI+w/hyqeYx7yAwUFC xdS2Z+iHBLvlcz2Aq4PGILzKjugLCtHoQ/oamwFPey3j0oJ2MZq45LUjVqMKFLkromyw RzQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719869049; x=1720473849; 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=YOpXTWHEXnjjvx9LV4U8IMiTxHBdnBSzp3nuNfveMIA=; b=EDWjKBK4xOhqRhErKtjNRTNwU2d1v/tVl8HT1RaKXd0zf2PxDYI/jlAtpaiU1rqoxr H3pRbmHYdGY2J4mh6FcLiZ4eoZE2KCS/aeZV9UxIRIFiJe5Z0TsCvXm6U39fGGZm+Bo7 BJeMagnt+ZJm6CbKkpZXB3tnZ8EN3P58O2pKCh4GjXbEPJZbxsiGN/ZiVPZ4iEWyaqWO 7jvSamBABYNMnODLIkUQlvy4SD9oBtVtDOJAYrgjjr0af2cX7GOCwYifkmJ4bFtxSWCB GXzl/43tzXfIoPymcxGGULMjRA0scjvU1do0QMuTEembf2fzK7x/mtKAEStSxAeFUeRl vZCA== X-Gm-Message-State: AOJu0YwWMJUpl2Cl4budoEXf1Ir6que99J8taQnyRAVEtHDPVMTu0/rd cNXKmWMVjY6OATbI7hahl3aL4hx4TZTvnJ/FWXy9SynjCEwpABUytf3lig== X-Google-Smtp-Source: AGHT+IF5xzD0UHn0TgJqM0MM34LPR67PGpGlrjjz2021w9Z0Oiavk/7Ph5O9N/wAgW/MjT7wpPo9Ng== X-Received: by 2002:a17:903:41cc:b0:1f5:e635:21fc with SMTP id d9443c01a7336-1fadbc746bemr28760955ad.21.1719869048632; Mon, 01 Jul 2024 14:24:08 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fad4933a80sm57256755ad.289.2024.07.01.14.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 14:24:08 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Farouk Bouabid , Quentin Schulz , Guenter Roeck Subject: [PATCH v2 11/11] hwmon: (amc6821) Add support for pwm1_mode attribute Date: Mon, 1 Jul 2024 14:23:48 -0700 Message-Id: <20240701212348.1670617-12-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240701212348.1670617-1-linux@roeck-us.net> References: <20240701212348.1670617-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 AMC6821 supports configuring if a fan is DC or PWM controlled. Add support for the pwm1_mode attribute to make it runtime configurable. Signed-off-by: Guenter Roeck --- v2: New patch Documentation/hwmon/amc6821.rst | 1 + drivers/hwmon/amc6821.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Documentation/hwmon/amc6821.rst b/Documentation/hwmon/amc6821.rst index 96e604c5ea8e..dbd544cd1160 100644 --- a/Documentation/hwmon/amc6821.rst +++ b/Documentation/hwmon/amc6821.rst @@ -58,6 +58,7 @@ pwm1_enable rw regulator mode, 1=open loop, 2=fan controlled remote-sensor temperature, 4=fan controlled by target rpm set with fan1_target attribute. +pwm1_mode rw Fan duty control mode (0=DC, 1=PWM) pwm1_auto_channels_temp ro 1 if pwm_enable==2, 3 if pwm_enable==3 pwm1_auto_point1_pwm ro Hardwired to 0, shared for both temperature channels. diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index 5a3c089ae06f..98a45fe529e0 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -317,6 +317,12 @@ static int amc6821_pwm_read(struct device *dev, u32 attr, long *val) break; } return 0; + case hwmon_pwm_mode: + err = regmap_read(regmap, AMC6821_REG_CONF2, ®val); + if (err) + return err; + *val = !!(regval & AMC6821_CONF2_TACH_MODE); + return 0; case hwmon_pwm_auto_channels_temp: err = regmap_read(regmap, AMC6821_REG_CONF1, ®val); if (err) @@ -372,6 +378,13 @@ static int amc6821_pwm_write(struct device *dev, u32 attr, long val) return regmap_update_bits(regmap, AMC6821_REG_CONF1, AMC6821_CONF1_FDRC0 | AMC6821_CONF1_FDRC1, mode); + case hwmon_pwm_mode: + if (val < 0 || val > 1) + return -EINVAL; + return regmap_update_bits(regmap, AMC6821_REG_CONF1, + AMC6821_CONF2_TACH_MODE, + val ? AMC6821_CONF2_TACH_MODE : 0); + break; case hwmon_pwm_input: if (val < 0 || val > 255) return -EINVAL; @@ -749,6 +762,7 @@ static umode_t amc6821_is_visible(const void *data, } case hwmon_pwm: switch (attr) { + case hwmon_pwm_mode: case hwmon_pwm_enable: case hwmon_pwm_input: return 0644; @@ -775,7 +789,7 @@ static const struct hwmon_channel_info * const amc6821_info[] = { HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_MAX | HWMON_F_TARGET | HWMON_F_PULSES | HWMON_F_FAULT), HWMON_CHANNEL_INFO(pwm, - HWMON_PWM_INPUT | HWMON_PWM_ENABLE | + HWMON_PWM_INPUT | HWMON_PWM_ENABLE | HWMON_PWM_MODE | HWMON_PWM_AUTO_CHANNELS_TEMP), NULL };