From patchwork Fri Jun 28 15:13:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13716323 Received: from mail-oa1-f42.google.com (mail-oa1-f42.google.com [209.85.160.42]) (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 BBD4A1C232B; Fri, 28 Jun 2024 15:13:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719587637; cv=none; b=ARKDAM1sYEd1w3Z4Yu4BOZK6pU12c/RYydkLpM8KN2r3xncWC8GgMZeEz57z46iRBsBs3COreYBBX0AN8p3+AVpvNKZAfezVb+B6WBZptk8RD4Won7TBHFDgWslQajOSNNi+DJQSHRpAwTMVkzkM+CVdawSkHxJCFh1yMK5qd60= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719587637; c=relaxed/simple; bh=3hujbniO9E+7eki3q2BbKuhFLjYti8XPiyEFCjHGHDw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TmPHB2pKQFhW4DiWtaZlh294EsOpe5nagZue6rwn5Ywv0UcfaFfmAlsOw/h+ij8SJQUnZzfKM+nFh2GN0PZ1ndWDJOm2h2WAhEKs6N2EGdF6HEIqFEGyT1sNBbyh6BqrZO98xNIVVm2Nb8OSjDQZAI183EO72hfYcxQvByGXcWQ= 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=PWVZF2Nq; arc=none smtp.client-ip=209.85.160.42 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="PWVZF2Nq" Received: by mail-oa1-f42.google.com with SMTP id 586e51a60fabf-25d584e9fe6so410628fac.1; Fri, 28 Jun 2024 08:13:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719587634; x=1720192434; 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=oxplXSHYof55UO1G/jgJi+L4qN2gtkU5KLIacw8Hjj0=; b=PWVZF2Nqut7H3yTgozFPqjXj+M2+RhiMKCRC3P/AHmb6B6umLd5wMbqpX5gFYe3Y1P zLEKLDlgBBLSTTA41a/5tpZ6GQFS3VhJP2lNoxvOIcF3gFRHpIKUeb9sP7tWAm6gxymb YFi/uxEfn1vRiEo3lLi9Jik6ZrbOEF7wjrxmKoLuppXvrN6cNJOOnMLnzbeAinS0bTN6 C3WvIwrChA+JBMvJ8RhS+25Jo+3qgnuuyk4658ujYBcgzSiDzuGeWneGBn6B4EAaxhb3 JAS+D7/oqhBFFa2fM1HA8dL75S69zisZqBGCcyioWwR42w1XKMFunbxggUpY6YzWH5OB ZDjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719587634; x=1720192434; 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=oxplXSHYof55UO1G/jgJi+L4qN2gtkU5KLIacw8Hjj0=; b=xVAlkbpyzuWkIIaXYKYiUr1JW0BLjvq3RrOiHkxZAEWRzJ3NRgUH/BAhoX+AuKc56Z Rh3ghTaqSBYjdxRy5fYoX/bO0BFhzZHOeCTNtH7L3++2dUuYzzZ7OIZIIDd1iM/63d2m WQ+aKTjIoVciIpbgmnodWiv2QbSwrJ94StydIFJ+Jm1FmNQR65xFjqJMoZ1Oa4vlkw/F vLDprTcGnNNnqkMGZSy+N5jxszfDM26XcEY1IODCoYQxVcf1ThG430yxpM5e0UTULEyo p3lcOJT4o+EUmjYE5h7yjRH9qzEIwiQtlyhmxzlNO39sHdpZ57Jhiqj0HDvNAicMjZpF hOAA== X-Gm-Message-State: AOJu0YxYoCJdG/eCIH4V+TsSuhOwC1bpgV1RRr5oQsMvFk+7zTI1ultJ 6KoTSUpEYxno/6eZU6ii2J0LPBXErBtSruxSh2eDVc/Oouq0527KRkiVCg== X-Google-Smtp-Source: AGHT+IG2OMomzezGRUbhXJ8XKQRxHM7sYn+iB6h+hM408aY2K+C2NCXzblw6WdDmmtXdpKIgQm07lQ== X-Received: by 2002:a05:6871:3429:b0:254:a753:d1cc with SMTP id 586e51a60fabf-25d06b73676mr17322060fac.3.1719587634250; Fri, 28 Jun 2024 08:13: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-7080246e1d9sm1720955b3a.71.2024.06.28.08.13.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 08:13: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 01/10] hwmon: (amc6821) Stop accepting invalid pwm values Date: Fri, 28 Jun 2024 08:13:37 -0700 Message-Id: <20240628151346.1152838-2-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240628151346.1152838-1-linux@roeck-us.net> References: <20240628151346.1152838-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 --- drivers/hwmon/amc6821.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index 9b02b304c2f5..3c614a0bd192 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -360,8 +360,11 @@ static ssize_t pwm1_store(struct device *dev, if (ret) return ret; + if (val < 0 || val > 255) + return -EINVAL; + 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 +561,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); + unsigned long val; + int ret = kstrtoul(buf, 10, &val); if (ret) return ret; + if (val > 255) + 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 Fri Jun 28 15:13: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: 13716324 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (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 3A0051C688C; Fri, 28 Jun 2024 15:13:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719587638; cv=none; b=t8NWDoRuqaQH/Y1mrCt+h7I+vEXQPzonf9jXQPRDwEnUoH/3ZL/2TwJcFkXXBffraqRktBbSQM98qx4MNAmZvqHKcf9X97IVOZgqOLkFKAc9yGFN9sMmRLn5IUM0GJx1ElVecoIvFUSSlL/Cv6Eoflrn61RYuNNw4lfoXm7LcWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719587638; c=relaxed/simple; bh=PmtaC7yNgiN26bRHbRk6FNqhEr90OZ1Ci7FKulVXAHg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dwPV67YZTFeKzPbTHpV2eQPymKIMGygwb0LBI0mIcqjIDmz7U5WowwFY/NZql1LrmtJ2MRnQ6OofFu8FwoqTYcnPFLZSp46s/ZGUBbTGhbQUD8bQTa3pGp2SJnNpgPH+B/3pgbJCou2ciFk7Rj+Pi49gEaw7lssotvlyeIEs6NU= 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=XeX4VMJa; arc=none smtp.client-ip=209.85.215.179 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="XeX4VMJa" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-7226821ad86so505127a12.2; Fri, 28 Jun 2024 08:13:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719587636; x=1720192436; 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=uIApeW/cxziZeQ8Lx+W3IMHYVE9x+3UeM0rtM4gqy8U=; b=XeX4VMJaXv7ODexsJvrUNeIXzeKsRmhgngAZk86pSKw9Gncm2ShX5EQD/Oo9GE2+QV 0mv2LILf4wyZ472q+gq8FHsuaRZwA5c0JFejjU2GSQYgPOz3iuVfW0EwfmmHySAnC0aN 49QUedchuTdJDApQ6kgHvMox4zhU/kXX8e8ylkTiWPX0rHnUtlfS/YthVX4/B6fapzX5 mcgEYxROCcWDNiF0c7vaoGcUEZ61e/ichNwlqa1LpPIhb8wBDZI99yoOuYbfUIN+CzH6 aEY9GqPWP805Fr9UVxceJqFYyZQvTRCDRoajfucOB8vxvyliGKEdPzqNe9M/gzKhEpA8 NibA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719587636; x=1720192436; 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=uIApeW/cxziZeQ8Lx+W3IMHYVE9x+3UeM0rtM4gqy8U=; b=EWyKK2sS02OTDrM5K5y3g9u1wOf/SFRl5II7wzweAXqIKPS5dIcPwi8ItE1HoKSIx8 YBkXZFzgcfx0dE4Pv3aISIAUhc9ObDF/PxxTlndfMd1lMwwJOU775a5rlhbYmrcAgwhj UnWETsiPkZxrcqAzGBRXqXwClvT2qqk6jfs0cvgiPnKLHBpbgDlpQPniz1bbZzMyYuLE 2I3aHdTO7d+AjYcwJHHlJ2S7NibRnDS/z5VxVkhQ02Z2BLS1G2DdFHSGY+xBH+lPvSVb WROpScrS6ujHE+VC0cSu1dwNrIWGxb6SZyTdDW5t2v2/yoKiU61wdBIpMjn6TGUrGD4V yutw== X-Gm-Message-State: AOJu0YyUGYv/s3TZcURVYc6QWgvX7Md0o1o+mXkVZFFm6OkjGazIK/dg N9CMRNMxmdhDvLSojvQGswBNGWfmTNXvlZ7yl73h/hmfIRc1JkmDlaobsw== X-Google-Smtp-Source: AGHT+IHue1VwqUFliIN/gVVynrnVva168H1Z1HzB5eiyeNvpjelRrSEIc0JcDEmbDug1owseqc/n+w== X-Received: by 2002:a05:6a20:3016:b0:1be:c551:b74f with SMTP id adf61e73a8af0-1bec551ba09mr6967503637.27.1719587635912; Fri, 28 Jun 2024 08:13:55 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91c7df8b0sm1787504a91.0.2024.06.28.08.13.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 08:13: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 02/10] hwmon: (amc6821) Make reading and writing fan speed limits consistent Date: Fri, 28 Jun 2024 08:13:38 -0700 Message-Id: <20240628151346.1152838-3-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240628151346.1152838-1-linux@roeck-us.net> References: <20240628151346.1152838-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. Signed-off-by: Guenter Roeck --- drivers/hwmon/amc6821.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index 3c614a0bd192..e37257ae1a6b 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -601,7 +601,7 @@ static ssize_t fan_show(struct device *dev, struct device_attribute *devattr, struct amc6821_data *data = amc6821_update_device(dev); int ix = to_sensor_dev_attr(devattr)->index; if (0 == data->fan[ix]) - return sprintf(buf, "0"); + return sprintf(buf, "6000000"); return sprintf(buf, "%d\n", (int)(6000000 / data->fan[ix])); } @@ -625,10 +625,10 @@ static ssize_t fan_store(struct device *dev, struct device_attribute *attr, int ret = kstrtol(buf, 10, &val); if (ret) return ret; - val = 1 > val ? 0xFFFF : 6000000/val; + val = val < 1 ? 0xFFFF : 6000000 / val; mutex_lock(&data->update_lock); - data->fan[ix] = (u16) clamp_val(val, 1, 0xFFFF); + data->fan[ix] = (u16)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 Fri Jun 28 15:13: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: 13716325 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.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 E31471C68B0; Fri, 28 Jun 2024 15:13:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719587640; cv=none; b=szoN00DgCS6Mqy0bdm6v92l/bb1PujlmOCmeXD3E8PDe6gGOvdJTLl5QzotxFhjy8vdyTsLCZxmLyyHQNzSpWgvKTrgqFcJVrGPVVkT2K1QCVXxryi5UCmsYZ/jWQRhmvrKK/iQh7cXUVq1HY5Y46yVPAHzzpX+/ZvioYGZnrrk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719587640; c=relaxed/simple; bh=HkjQXDqoq4CW9BM40Ocb/uoZr3Zx/2lsLABP+q5jUAo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=i66YIQz/3Ho3nmA1817XJ0nnFzfwBnByt6rLAZDYx+vaf+8gHXab54pJ38Djx/A38pvGVTUoS2To/J6/RfyfRlmyEp4zV923DGZ0oYgtu+1XSr+G/KRFjuOYmvQVly9Xy7my0MYXmBg4WxnjJmUxf+kF5H5cbxRxByuKXJeNbv0= 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=GAYyVwcY; arc=none smtp.client-ip=209.85.215.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="GAYyVwcY" Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-7163489149eso532206a12.1; Fri, 28 Jun 2024 08:13:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719587638; x=1720192438; 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=ejEx78WKXom23aFc7lD9B6dUuYkDYrO71Mml1PP5MG8=; b=GAYyVwcYs+r3rFKaM7N+NQuc8uyIqQiHObGGWtvm+c8uW4ftXQtrXkDC7ZEC57yT2r 61RR0PP9GxCbYZskxKD9WVwrwUKFxOsTqHMsehlcwC88TOU59Wyjed544rc6qZAchCd8 +LbBrKKDiiAjMeMflajwN2GHQaVLNCpu6CIEo72iHtFJ/OUYaoKTmLXWj+8Og1rkGXu3 WSwnd5KQhaS6vmta3OkAhtN6t6GVB5EOOOEHbV0yeqV2dTgmPEtAZENxiPbPcFdBFxqc GuTA3GunC0abDop72AWZWp5WR/NSh6Y7jr1qYGHomi3hlN7aOLtTpQGk3CJBFgg8/99s q+NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719587638; x=1720192438; 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=ejEx78WKXom23aFc7lD9B6dUuYkDYrO71Mml1PP5MG8=; b=UmKriVUvMpGR76IcToSVmfDTwqicjyA+5jvJ8fXHnoqCnPSbV+H2Pv7xUOszYb1HKH PsAebz68suTsDvLlu8NaP+LKxrA7B1Ma45h3+xE015uzwHtkFu8VIDqoh8/F5dos/qbG QbtB7ZI7l4yrQ8MRhli/nS10k8kLHJjj/PyXn+elotbqcWwyDLzmSX622erql6zBj/aF 1Cea2e77Z/0rK8/Hf+Ukb4/5OuMhaq3Hdd0qnOUh++buLYpHNALOoqleMW6lq8oOzIkK mN86Kj0bnz/R/xpHsfZvwpLqmFI5xKwYe6n6g7LCH7YhBqFPwybKeK/bpbvii1mWd8Tm 8dFA== X-Gm-Message-State: AOJu0Yw1kWs6Ff/ZMlqZRcfwmID7voPQoPkq2WQdvXTrD87/IqAGApIo S5P4PUSE0fyCegRAsHzPOPayopktRsDONF6GvswaNT/2M60neT5PagQd3w== X-Google-Smtp-Source: AGHT+IHp1Jij6wrmYCVNwQm3eVA7ft0BIW+QlXbEXxyUfgEx8/Nxa8iHnjYYaw6wICjCikkPtRk/Zw== X-Received: by 2002:a05:6a21:394c:b0:1be:d0c8:d562 with SMTP id adf61e73a8af0-1bed0c8d7a1mr6940727637.37.1719587637550; Fri, 28 Jun 2024 08:13:57 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fac1537373sm16359605ad.135.2024.06.28.08.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 08:13:57 -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 03/10] hwmon: (amc6821) Rename fan1_div to fan1_pulses Date: Fri, 28 Jun 2024 08:13:39 -0700 Message-Id: <20240628151346.1152838-4-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240628151346.1152838-1-linux@roeck-us.net> References: <20240628151346.1152838-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. Signed-off-by: Guenter Roeck Reviewed-by: Quentin Schulz --- 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 e37257ae1a6b..6eb7edd9aca9 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; @@ -645,16 +645,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; @@ -674,11 +674,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; @@ -713,7 +713,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); @@ -756,7 +756,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 Fri Jun 28 15:13: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: 13716326 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BBAA1C232B; Fri, 28 Jun 2024 15:14:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719587642; cv=none; b=flGihgrsKvhHi0fQSogK8gm8dhtBJyaiC9MadupFCjDKQPXE17sMHpzz8vPmuGN0ok/V8PS063yHvpTuxBi2jce63mI8wZQ6MmSGC5DVMfjB0wSOqGJ9HOVfPsG+va/aekIqSxq29Dm+L8sOK2QJhxnyveRLem8D1mGT0NcJbZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719587642; c=relaxed/simple; bh=YSYpn1pimr6FemNkAAjzhVb5FiuVB1chZr+kY8qXBF0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KQq9Y+tJkgL842NadJvGd14mib4PHVuQ2PvXrCqw6GzAwxDyKAy64MEveou3stjewy9DbAswA3rio/i2FJJ0/ry7rQUqM+DDVxQc9cheAAuRxB41uDd3Or1awptn8K5Ax9OaUNSckdFGRkGrRLDY8xFLNqt2H4OBDO/6YG7IHWA= 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=ch7kLxbJ; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ch7kLxbJ" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1fa2ea1c443so5408275ad.0; Fri, 28 Jun 2024 08:14:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719587639; x=1720192439; 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=W3FT09DFUGTWcjqSb93NRz9BnJQ9+ZX/Fyen/MdZdis=; b=ch7kLxbJznlKrRCj6ZhXZkbVMrgqdsOnGvOSpDKfToAmAQkLur3OIVoRnkyF9HJ38H Wjmjnn8EmRA/F1aTm9tsX+rkPteAYQwoZPLqtk+vzl698+1uMytgC4iptc4z0zHpY2NU 8dVwM5xHjPFXpbL3yP0SWRbxOVV1GX3ihoykTZm+JZrUNbX8jNMjyQ75+XcUB2ScHjU9 oiFzSzegNUSeNzffpbo72LqFCAgQzGF++oSp3331WcCLPHbYgqkYjyifOAqGUtF0jjHk YOn+kQ9v35m9YFxNmUcEHR0H+TXJRaUTtuUSh2MpPb1lZI7rO2n2vTi2xGhh3+NBui2x ma4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719587639; x=1720192439; 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=W3FT09DFUGTWcjqSb93NRz9BnJQ9+ZX/Fyen/MdZdis=; b=M3sniGSK+8QECYChcBUYvCRdLXEAC7ra5oVRVjoij+gAtHZMjs8gBkFAL7TxiANXfN o1Dp9gsZeqf+BX5HOJ+Uy+IT7jB0YkPV2uccgWr/bxRNWf5r0wvHb3KeVCZP5eDURtVb boIo8VLRWkYbzdwDd7MGfi1PK3TtTCcfBctROXE+yMk35++Dl71Dd+Frrx36lbLG72BC ehykUVB3E15QzZmSC2OE97jU+bkg0Td52W/uTD/n0yLvDVWABvmdXkhi9TitTHnFLCwl 5QtOnDGbOt1kc43MqVmM21UaYgI4oFckEwQ9oJEmFLcnuo1KNqoRHx/eUMjBI6c1BLvZ Pn7A== X-Gm-Message-State: AOJu0Yz0gS96nnL4BSJWbosfIcpcG2IiFvhaB7CFratePk1CmCLpHUOa hVBLhECW8QSqqWxvXgnL6KeDI53kWK66lUpKCOCJ3bpAW9NfEt5/VAEYjg== X-Google-Smtp-Source: AGHT+IGrhesP1pAkasRLq/rXvtHuQLIPLrn6RsX0Yqx776c6Mbs8EyVNu4tZz5xDn3wbwOG39oIpeA== X-Received: by 2002:a17:902:650e:b0:1f7:174e:354d with SMTP id d9443c01a7336-1fa23ef7ef4mr127803105ad.48.1719587639269; Fri, 28 Jun 2024 08:13:59 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fac159be6fsm16299065ad.283.2024.06.28.08.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 08:13: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 04/10] hwmon: (amc6821) Add support for fan1_target and pwm1_enable mode 4 Date: Fri, 28 Jun 2024 08:13:40 -0700 Message-Id: <20240628151346.1152838-5-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240628151346.1152838-1-linux@roeck-us.net> References: <20240628151346.1152838-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 --- Documentation/hwmon/amc6821.rst | 4 ++++ drivers/hwmon/amc6821.c | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 6 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 6eb7edd9aca9..8801208430df 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; } @@ -410,6 +413,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; @@ -712,6 +719,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); @@ -755,6 +763,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 Fri Jun 28 15:13: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: 13716327 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 211361C8FCD; Fri, 28 Jun 2024 15:14:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719587643; cv=none; b=R9pwN0uB+uvPmqyTq/ZNlMr+h/sJ6p6jDZqQQlY34ETNRX/XO83me/Vd1MXM1I25Nrn9CLH8MqwlgRgMwK7M6LhpR5Um5gUe9TI0H3GBmZXzIaOgs6Sxx/KV1CgfBpbdvKmUqlqGTDRjvdrJN9PTEou/dsurxrd+c/p5+9/WBCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719587643; c=relaxed/simple; bh=LPsHvyhPi0NAqAqAHrD4tpDxpxtOTqe2gPC7Izmxq8U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=R43sfpnM3uIqS/bTogwTxkuebRuNhF464dRvL+n+uFz7Krfx6xM1aRzqUctZKylCbmcjedFtP4KxpmmT9nBYD2ug1IkDeQKT/nJnNK2txRO7vdJR65JNrKOflpCU+EpLLqYn6ZVUqQ+v/mOLf5TfxnDGvnRHraBLGXQy713ZlEc= 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=VgIGT0fX; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VgIGT0fX" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-70a078edb8aso57276b3a.1; Fri, 28 Jun 2024 08:14:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719587641; x=1720192441; 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=RSfP1MHnLnGUcfVfM2NqaHUyr+LblKMCMxBJCwu9uFk=; b=VgIGT0fXolXj/U/joHJI08bjLovoN4dw2S9ADFHY9J22DZl9fPqLpimkj0an962p8U tY9HAfV98BuE7IYVAi68sCVU3gHEG2CqVEiPMPwWns5P5DQxnPs75PpKNT1OyeR0zTPA QkkT4BeHoJfsZoYZx87e/iapM6vHkQ8l5hZIJxvBmyQGBMV70F3RRfVQ5/KJwiGtpz6o PGy0lmkpCdbHr5pIwwR8nsvxxVLBxm12geLpILUNAHNs9ydggOUGENJPmwqY2a1ACxbD MPpcniBG5E2eY+Q8hE7q2pJ9p0bJtEl7k9CRhD+zD+kJG/+rzcW82FmAAxVNUGrFOGFb VFUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719587641; x=1720192441; 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=RSfP1MHnLnGUcfVfM2NqaHUyr+LblKMCMxBJCwu9uFk=; b=dCiirF+Yec3POnBkHHXwxg2uJchg1RuNfZvtcI5dusl6I8j+McZKiCOGoL3jlUXKN8 xR9dcjFznI1BBL+9DteY1/nx3uj7zAEi7O0pVYbgJx9P9qcnDzsTepwWCm/dF4IwdciK H/NPctBH3kL9WDCmrDL4CQ8nkk36QXeZ81LcFiUho7vGDLGSRohHfZFntF5vRrV5LvOw k9QiVGIMAo/gMDSo5P9QvAZnEuZWK6r0V5/G+DFEmOBJ1ZfdEySuiAVJMxgO8xS4UxxO TjKxSuwN1skCQygsBb0cEjoWnY3M1OyYryjX3jMYF1YGhHf3QTa8wMu1xHO4gIywkHKh mJsg== X-Gm-Message-State: AOJu0Yy9z4rymjGNITAEV+0BLzEdKroK7evlBH9l7qdllIPWjvl/TC6t iNffXAzUKBrOBhTef/fR2s/55vd/ndOz7QHdgB9+bdSJxQLibOmTTdngIw== X-Google-Smtp-Source: AGHT+IFSFruCwsgJcLv7Q414hO/8xYSg5dB4F2TJeAIN3zulCnk8xgUsbDPVmK0MyNwbG11EPpnyBA== X-Received: by 2002:a05:6a00:14c8:b0:706:5b39:2b18 with SMTP id d2e1a72fcca58-708531f355cmr3424596b3a.11.1719587640946; Fri, 28 Jun 2024 08:14:00 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-708045a9998sm1716902b3a.158.2024.06.28.08.14.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 08:14:00 -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 05/10] hwmon: (amc2821) Reorder include files, drop unnecessary ones Date: Fri, 28 Jun 2024 08:13:41 -0700 Message-Id: <20240628151346.1152838-6-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240628151346.1152838-1-linux@roeck-us.net> References: <20240628151346.1152838-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. Signed-off-by: Guenter Roeck Reviewed-by: Quentin Schulz --- 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 8801208430df..0ac073f83c19 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 Fri Jun 28 15:13: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: 13716328 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 DE6381C9EAA; Fri, 28 Jun 2024 15:14:03 +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=1719587645; cv=none; b=htJnYlrJnV66JVd5O9NBMO0euUe+fkToRfL2fKKZj7YEKnPKihJKzMd4+ZosnEHn0tz/fNlOwLqNzv+YnE0tDiP/ycX8zZsbpFW67atFkAwyO7sB5CAIXYHduCESVV0/T5VRN5Pyts520SHyesLYBblJtrkgFWFRpk7L/537o6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719587645; c=relaxed/simple; bh=FPcAS1h017rsrdrXADJIQuYuXZQ7Be8062QstMNA5Cs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=H6k7MdJHSa8vKohq8hRT4KW4hf2o0r/EGY5ngd3VRb+FVsTTdsUUZcjy2R0KrgEGyx6xdXYaAnSoPwQxfFyYfcohOd1EtPvHiZ7c0eVH51/VDbCOcFlrtmUnJdadoKEuWhDe5YIg4oSYMfj1/N80sGJyXs68qVdzDfjxl3EIRIM= 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=A9xroZbZ; 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="A9xroZbZ" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-70698bcd19eso563572b3a.0; Fri, 28 Jun 2024 08:14:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719587643; x=1720192443; 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=YAJlamRBY7B+Tl0+O7T2GO8BElHTOfeCvUNUKkSsRao=; b=A9xroZbZqSfmCqZHzdljqvPXAu/Yz84OfuOWDw/hePPLkzqiE4+30l29RTzBrXpr8E SzV830fi+G0SndQe6qxPtGrwxUeSG/ZV/RkRtmyBW4jwv91PCUeeaXsRxlLVHufgtqZr idJa1ByWwn0GPK8F1hnfmkBNSHJt05na3YwABnjXvtmozvvL+0aQykFS4BSfT27EdFBw 1xku/UF0p2+BAElOnfZ80hB+pkqwHWB0EQmwqMgJG60M920qdKt8fKAQXx5LyRH4rrFy fCIXtn58QR8cHc1Wxta3K3KJs6Qz4Kxh0pVVSEJBJzuoZs3llWLaNEIej2TAdQHpSu2u vhiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719587643; x=1720192443; 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=YAJlamRBY7B+Tl0+O7T2GO8BElHTOfeCvUNUKkSsRao=; b=LYykGYQoOOT+8+/cpW+8oJ1M7Tt0vo5f0OrzfaavOhLXhhs1e4r4BALBUYmrcxlcUl SE3BRorSGjvZublzrl7sfJC+y8w2+N+dqp5RapowdrAnFeNFmQDNFdxAt9w87N5lni/T lcWC1aazPFw+OieWfNm0Hnuwb9BF2uOVH0KqqPK7yMkodVGAMe9uTNzH7hUyZfJX7tnE jrYf5euqSowUTMpfSLtr0yUdxBe6G2Emmlq4YowTehavC8R9nZVIWqbi3jbZM4Z3VWka jwqPETHBjNHl7X4m8YCjbyEGr4cTUhCX9yuRdaj/i3IvTQcEOHswoPqaRmO2Dr5RxbWy j3WQ== X-Gm-Message-State: AOJu0YyUtzvH2fvZN/rb5+7XegCxAhV0u0BKogHtWnrVYKrkbySdBdmM JsW6xVJV7nAAPCn1NYRI2EyTWnME72D8c23vqiYymLjzZNyDdQ+2b56YgQ== X-Google-Smtp-Source: AGHT+IGaAMDPQscgSyXb1Y5MEPrlkV/Ec8UWpq77gpLbKIA0RegkGbfvpTV35paXwsq02tFEW+l/Cw== X-Received: by 2002:aa7:870e:0:b0:706:6f82:7e0c with SMTP id d2e1a72fcca58-706746b5896mr15093147b3a.32.1719587642690; Fri, 28 Jun 2024 08:14:02 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70804a97ae3sm1713860b3a.206.2024.06.28.08.14.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 08:14:02 -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 06/10] hwmon: (amc6821) Use tabs for column alignment in defines Date: Fri, 28 Jun 2024 08:13:42 -0700 Message-Id: <20240628151346.1152838-7-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240628151346.1152838-1-linux@roeck-us.net> References: <20240628151346.1152838-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. Signed-off-by: Guenter Roeck Reviewed-by: Quentin Schulz --- 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 0ac073f83c19..03ce2e3ffd86 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 Fri Jun 28 15:13: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: 13716329 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 860721C9EC3; Fri, 28 Jun 2024 15:14:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719587646; cv=none; b=H1zy3D1f25n1qoQ5minUevuWLGBMf9rsRlCuKHn4Sii2dNYa69SHjQXVnfwL4ghQMoU43xSLrBCvdVKlL6ELNnVY94Jiuz+IYdZyxMqOFti6N4/ViFJL9orgoz+5LjtcluvpVj/4yE1juYF7D0SXnil3lhiZ2Dy7g4a2AtbKUrY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719587646; c=relaxed/simple; bh=gjZNisN3UNBQNSjn05RmJck5ECw4A8z2ZF6EBVwQ13Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gx2puhsSx4mbOYPTgAGMZ8Uudwp/E++WTtAVQG5XyBKCm8SnCLxUrulRhe92xa063oiyODgSyH9G6E1S8ugsarVA4SHbS55NdZ08OO4kXzzia2t96eXo4x/KeX4wwUfRAI2L1/bSbndpDEyEgti0ND1DgnZKLMUorZ/7PtVddO8= 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=c2I1c4Yn; arc=none smtp.client-ip=209.85.214.172 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="c2I1c4Yn" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1f6fabe9da3so4784985ad.0; Fri, 28 Jun 2024 08:14:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719587644; x=1720192444; 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=+gztMhVxUqECP9wITlVEZK0vKrOtrBdNLPHM8t3kssk=; b=c2I1c4Yne+ptwHQiE+qafuPUnM1qWVUhk/LnlqkNcLgwm9QEUB36II/kF9W2vzHDoR HhuelD1llrvI5zqMDdK/ZrhfscOXf+FHt6u6+mClodgm1m+x+xrk1G3W5jL7tRb+Gfdl cetuEOSXIvVQxQnyhszIqSeC7xt8LusMt1vq9OTIaqvmfYVYd+LUzNUKTnQp3lAl4JsF YKzrD/FIrRtAmyQ5BuVcnpEMPWmaUAv593jyBuDl+543QSa04iHq4PMrssi/84Nh4fCr nbzHV5HRb5ygjQk5/aCbYDCgnfMJZxBZdGaIXIH8dCs2KW+kOsWutcwAmZGbGRHLUxdU JB6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719587644; x=1720192444; 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=+gztMhVxUqECP9wITlVEZK0vKrOtrBdNLPHM8t3kssk=; b=hFr3BX7W0FR1FjIfklnRHsodBZiJF2e0SaQ0r213gDgyCT2NwtfVj6BOqbl89UxzbH 70yENP5uOeb7uCjlOpKit0WyAZx2HeAVyHnbErnw5KbTaNTBF4efNGw7lwIs4mnu2Voe lxpzss2nI514XqLi9cqjAVKXSymUa8qQuKJYMOeCh6z5KD6pZPZFUgG0EMMKPMnlJFly qJdJnVPc9piYXtbTlu5geHXHDCPtIPgu7p93eTMK9pXBqHqVsN/U9EtT7MU+D/msCQWo r8fL+BA0VR5or223dUXnoC5M2Nb1Gcyq1QJ6Uyo9JB1Zsvfqwb1BRTAsup4e5W91hYae veDQ== X-Gm-Message-State: AOJu0Yy1ZJ1uiReusIymM5nDFCGH888Kp1nm2V6ry1n8JbBuu5ZzTIRc BGuQ/YJS0tXe2CznEZKp8LEVYFUEBRtKJd6+3XsLoZCoC041ynJKEgvhaA== X-Google-Smtp-Source: AGHT+IEJ6dYlObITfhu84TW1xf8ZScAxYDFJJLlPVS01oYygX+MPVCfdn1WlSePUxtGX+HQ0qwFHeQ== X-Received: by 2002:a17:902:da8b:b0:1fa:81bc:f4cc with SMTP id d9443c01a7336-1fa81bcf71amr82852455ad.68.1719587644321; Fri, 28 Jun 2024 08:14:04 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fac1599d28sm16344915ad.287.2024.06.28.08.14.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 08:14: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 07/10] hwmon: (amc2821) Use BIT() and GENMASK() Date: Fri, 28 Jun 2024 08:13:43 -0700 Message-Id: <20240628151346.1152838-8-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240628151346.1152838-1-linux@roeck-us.net> References: <20240628151346.1152838-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. Signed-off-by: Guenter Roeck --- 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 03ce2e3ffd86..042e2044de7b 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(7) +#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 Fri Jun 28 15:13: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: 13716330 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 27D451CB303; Fri, 28 Jun 2024 15:14:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719587648; cv=none; b=dh0Sc8Yguhpt2sGDDsO463tJlDc/HlFyVDvp+JwfgA7/UKHnih++HcMmcrfdxL/ed0sxbwG2P7KFoWYnGvMMuQQ02IsinMoBiKsusYdL6AISlXT6GwRj7Lk1ZH3SRba+rKjcCxOfB3j+hrVcZkXOuxgUsNUGS2BNh5IIjNV0rvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719587648; c=relaxed/simple; bh=S1GqPUeD62e+cLY6wRun1LgVGPMovWQtBrE+LAucsdY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NgIIgDJYe2/VyP/zZHst396ittQdScaFJ6e+4aFbwEk7lpeYWbgeHhZcZ5Efho5QohN93eOH1ZI4SKso2rGRPyAQ3+4raJz8upAeGR8Jnuek3KjvkqRJSxiUS8VFH0YWQYkRAQMAU9TocvNkXBSPV58A4b2duC+QBMwjTqmOcCk= 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=jWN+KvVW; arc=none smtp.client-ip=209.85.214.172 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="jWN+KvVW" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1f9ffd24262so4689235ad.0; Fri, 28 Jun 2024 08:14:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719587646; x=1720192446; 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=YheIpGNRGqJ0fUYQU2ae3gFEDlB9LZEMJcvfRhzF7CQ=; b=jWN+KvVWArul2g/nJL6xsS8kbZeUFbzRb6vQZyrojlqh/cRq32Zq5A58YihAWOyVZQ +cn7fXQ36WOhfrb7H8ZPdcWdtkZj6sU8MrjxiqhbIv/2K8h6OOMH8Ufko2wOx7zHEWvc MF2dPow2UDONfVeCkUEDzF0Rt43x+/0/uzkVeePLRj4nhOa3ds1SVGNOmcWCRhKLBTQJ EXBzD1uwyBLwTv1Tb4g7SX1HQ55kXIc9Q/bBF96QKM7T3mI1jysLzBT1Pxy4bIo71A86 Xw8iDZF1OKJojdf5e78Ltw2whkKGBOpw5RCYG485wTkIv3/1dz4Mb9pxNKyj19JHX0d3 6m6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719587646; x=1720192446; 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=YheIpGNRGqJ0fUYQU2ae3gFEDlB9LZEMJcvfRhzF7CQ=; b=Bwf1zpKT58EJe0eIY/lWk0uESTJlzNxL1jsGGCTuBguLSPvKLx+0vjC8ABbKyfDDHH 16K0T08N8y5ch2ak/2ti/+gN0khQn1IxsLhQBGXZWQ37rmCOmq+aSmj9CMvoho6YUxKh Q1MC1uk1Eqgu04cM2LoCrph9NirlC0b8/PtgqG7w8YnQuWcAXRHzye5rAxw/vgXze4HL bOONXPBA63UQ+9+HshVQfvnoIRHEId7lSuD92SNiJQSk+y42PBprzaU4es5Z3sOzqLaF 4jKm4Im1I71/xhnlOv0usq03SGfBNzm8b1W0ZqOJ2aniGCwMxcIAzSoSkfwr03oGvXf8 YVWg== X-Gm-Message-State: AOJu0Yw8UM9Ky1eX91SL96lCPVv+TlFIeTy9066iaH2DKJsrTihOpxeE T4HgVTq/JmzqLHRqm0lw2LPjJR+6kcCvd1tNzNimqtSVxkBewHJpdyTmNQ== X-Google-Smtp-Source: AGHT+IEVxF0VQbhf4Ltareoctw6e4hLu1XIBgtCDncl2XYgMAydhYgvi0JQ6RgzCGo6tnDilQzXQcg== X-Received: by 2002:a17:902:ce82:b0:1f9:9c40:edff with SMTP id d9443c01a7336-1fa2413d3b1mr176875685ad.61.1719587645973; Fri, 28 Jun 2024 08:14:05 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fac15966b1sm16447705ad.262.2024.06.28.08.14.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 08:14:05 -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 08/10] hwmon: (amc6821) Drop unnecessary enum chips Date: Fri, 28 Jun 2024 08:13:44 -0700 Message-Id: <20240628151346.1152838-9-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240628151346.1152838-1-linux@roeck-us.net> References: <20240628151346.1152838-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. Signed-off-by: Guenter Roeck Reviewed-by: Quentin Schulz --- 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 042e2044de7b..ebffc9393c3d 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 @@ -943,7 +941,7 @@ static int amc6821_probe(struct i2c_client *client) } static const struct i2c_device_id amc6821_id[] = { - { "amc6821", amc6821 }, + { "amc6821", 0 }, { } }; @@ -952,7 +950,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 Fri Jun 28 15:13: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: 13716331 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E64E1CB329; Fri, 28 Jun 2024 15:14:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719587651; cv=none; b=cFlDE2++SOncmPMqq6luFq2iAJVQzHah6bbe9aDfn7rW0uv/A0HeI2iFA5yNvTGBV94DewkeoRWYTal2gbL8LzW/9nAKbGdN91IPv+nTKnHlIBbOrPFbBc29lWBrA+HlR7HHjFoMDDnRtg41g9GWarnkk3UAMKRzLYY/8Ni+FJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719587651; c=relaxed/simple; bh=ZbJhOAqQZCMBdnhjK04gJEOKQrEHkT863t4ky8wGXAQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=douls3XmsRj81CRQwSn1xLEmMi0Xe/UOwZHilBK3sm1Z8KB26CcorSugYwi9+8c6JLk2yVRWH1qyjuFHeYNh3d3qCwyY4QbiLAZO4dfAyEUSrcFDawCvAWaAlCfHkiN2fajS9ESYl48ozRYdFMMUgiyGNDD5e07h1Y+SaH6lKMo= 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=naFxpBW+; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="naFxpBW+" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1f480624d0dso5227065ad.1; Fri, 28 Jun 2024 08:14:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719587648; x=1720192448; 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=/W3zJ6VEnkMTA8IHP/+PzEqouaOw2+HRHWJqW4vFypw=; b=naFxpBW+2B3N1dPpwNEzfvNJBjj3+OwaTwbncPUul8QDzSlrOjTfSLx2sZ49AwgBZP J1COTYLfHYpRCnIac2HxRcxSQGmKUx3bETdt63vWhrY3/b2+r44I79z5aZug5bYvUPn4 jfid5+SVK7hwzzegpTkUuXcnMin6ZqCJxT9SwOMnj7aW4H8XM0F7bAyq/hvY3WVVCAMX SVz28Yi9NLE4v5hNFXCveK7AeI2nrgHtKL5Qag/jazRki7fmpZB/ZtPwYz1J1KJZkv+0 I2UB8hp78A+XdXZJuKlvCeDn+c3l+Uw3PuSgTAcol6NXZBD8vzZt6AwAHOuBUvQyXMk1 rLOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719587648; x=1720192448; 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=/W3zJ6VEnkMTA8IHP/+PzEqouaOw2+HRHWJqW4vFypw=; b=U2R7Z8jXzJOv+dc/w7P4V5usL7vPsxMrlP5bJtKvGPHuUN8C2f03rzlAyw3oOhQIBx dbMpd51PwR7GPIH6UKSh0DHBkEWRrl3eoNDBg/n6kz57Dwm8zlW3Mvyt8SFFJET2Zunl 1w5VbCcFm5VpSXlCN2slxq5tvzx3xEl9nM+pZdB9OiTR8/NljIXS2PKTz+3W+ZfiWudH AEhGU1eJMPAdmik1cdADvUsxJov9QbK4cj/tgw0tHqCll4Ec1ETuE6F8DBRz1tpEu06B +ASEiIbwg/EEjQW1olhDl2BaYG8lyrG4Ga9eRAXHlH64TfUDbYT8nf3+9LjI4c0sXl7p 0M5g== X-Gm-Message-State: AOJu0Yx7z2gYbOeBZ0BNL9gQaDbnTInW+QgC7GN7ig8KIreFEtvwzgWy pkHYvGt0CyYbZeyByRos2hUFY1/7Ent2jgOuorI8Lc/ZBaVFp/8zyQL2jQ== X-Google-Smtp-Source: AGHT+IHwuQpSxs4S6PGMFUkWkqHz/qWgBSOqeXyvNC1stChjx194NhW4maQ6JGTeMQ48abDTktdcrQ== X-Received: by 2002:a17:903:2302:b0:1f7:1b59:6f5c with SMTP id d9443c01a7336-1fa23f156e6mr202771765ad.44.1719587647791; Fri, 28 Jun 2024 08:14: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-1fad2083614sm6520385ad.87.2024.06.28.08.14.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 08:14:07 -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 09/10] hwmon: (amc6821) Convert to use regmap Date: Fri, 28 Jun 2024 08:13:45 -0700 Message-Id: <20240628151346.1152838-10-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240628151346.1152838-1-linux@roeck-us.net> References: <20240628151346.1152838-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. Signed-off-by: Guenter Roeck --- drivers/hwmon/amc6821.c | 711 +++++++++++++++++++--------------------- 1 file changed, 330 insertions(+), 381 deletions(-) diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index ebffc9393c3d..6ffab4288134 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -14,9 +14,9 @@ #include #include #include -#include #include #include +#include #include /* @@ -44,6 +44,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 +62,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) @@ -73,7 +71,7 @@ module_param(init, int, 0444); #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(7) +#define AMC6821_CONF1_FDRC1 BIT(6) #define AMC6821_CONF1_THERMOVIE BIT(7) #define AMC6821_CONF2_PWM_EN BIT(0) @@ -130,224 +128,170 @@ 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", (int8_t)regval * 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,7 +299,6 @@ 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; long val; int ret = kstrtol(buf, 10, &val); if (ret) @@ -364,18 +307,38 @@ static ssize_t pwm1_store(struct device *dev, if (val < 0 || val > 255) return -EINVAL; - 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, @@ -383,49 +346,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 mask; + 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; + mask = 0; break; case 2: - config &= ~AMC6821_CONF1_FDRC0; - config |= AMC6821_CONF1_FDRC1; + mask = AMC6821_CONF1_FDRC1; break; case 3: - config |= AMC6821_CONF1_FDRC0; - config |= AMC6821_CONF1_FDRC1; + mask = AMC6821_CONF1_FDRC0 | AMC6821_CONF1_FDRC1; break; case 4: - config |= AMC6821_CONF1_FDRC0; - config &= ~AMC6821_CONF1_FDRC1; + mask = 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, + mask); + if (err < 0) + return err; + return count; } @@ -433,8 +384,27 @@ 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 sprintf(buf, "%d\n", val); } static ssize_t temp_auto_point_temp_show(struct device *dev, @@ -443,7 +413,8 @@ static ssize_t temp_auto_point_temp_show(struct device *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); + struct amc6821_data *data = dev_get_drvdata(dev); + switch (nr) { case 1: return sprintf(buf, "%d\n", @@ -461,44 +432,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); + struct regmap *regmap = data->regmap; int ix = to_sensor_dev_attr_2(attr)->index; int nr = to_sensor_dev_attr_2(attr)->nr; u8 *ptemp; u8 reg; - int dpwm; long val; int ret = kstrtol(buf, 10, &val); if (ret) @@ -519,7 +505,6 @@ static ssize_t temp_auto_point_temp_store(struct device *dev, } mutex_lock(&data->update_lock); - data->valid = false; switch (ix) { case 0: @@ -528,13 +513,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: @@ -550,8 +531,7 @@ static ssize_t temp_auto_point_temp_store(struct device *dev, 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: @@ -564,38 +544,37 @@ 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; - unsigned long val; - int ret = kstrtoul(buf, 10, &val); + struct regmap *regmap = data->regmap; + long val; + int ret; + + ret = kstrtoul(buf, 10, &val); if (ret) return ret; - if (val > 255) + if (val > 254) 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; } @@ -603,58 +582,72 @@ 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, "6000000"); - 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; - long val; int ix = to_sensor_dev_attr(attr)->index; - int ret = kstrtol(buf, 10, &val); - if (ret) - return ret; - val = val < 1 ? 0xFFFF : 6000000 / val; + u8 regs[2]; + long val; + int err; + + err = kstrtol(buf, 10, &val); + if (err) + return err; + + val = val < 1 ? 0xFFFF : 6000000 / val; + 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] = (u16)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, @@ -662,40 +655,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; } @@ -827,110 +802,84 @@ 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); - /* - * Initialize the amc6821 chip - */ - err = amc6821_init_client(client); + 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; + + err = amc6821_init_client(data); if (err) return err; From patchwork Fri Jun 28 15:13: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: 13716332 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 D8BC01CCCA2; Fri, 28 Jun 2024 15:14:10 +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=1719587653; cv=none; b=LKwdkftVwebeEnJOqgicVF4ZVIE+PUeNne8YensH0oPuVYgwDScjkt6sOyH9b0yboTTf5DNLTpKd466mDimzokRs3T/fEOsiZpF1pdxvHaDe6W2kLtasUirV2jr3cxO0PKm3pWzl7Xj8aY9M/6DPn3144e9ai2DMW+yVPODJ9uM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719587653; c=relaxed/simple; bh=67+pPDB9hrjsu57CEbG1fh7bqOdYqEOcVAFhIvSxE9M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Bqb9gSGUuJbj4L0Mt3Zo3TGaaFs8mof4vBtPojYN68RNFWOI+WmHW24k6yeRx23tw4ejbsAEYdGYt5quJEps5r3HlXhWyLkth8vbRgbZL7WrY+HtyIwhHS9O5lMcZnNlernhbn5VzPI3oX5A5KcrlIFV+GkmCjVCskjevojNbK8= 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=ECnG0EI5; 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="ECnG0EI5" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-7163489149eso532392a12.1; Fri, 28 Jun 2024 08:14:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719587650; x=1720192450; 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=lW6Pd9Wzwjx1lXXTnOZIchp2EV9ymFzV8ODIWR95e3Y=; b=ECnG0EI5sHm3BsNSZwi6ENSBZCdiGMsnRgiytNSaNGmvVp1WsHdpbs8oO+IDTDHr5N nhQVVZ1m3iKe2OxZ0TrLDNSZ18zZ/pFJYlvVqMH5+lmN9u7dDyIvQsJe55lDQ6BOVieV vUvGfXsLp1ODY6Le9jWHDocHt1k7CgnfHcM3bItu3vShen5/I3WsY61rKHkZqkIx+6eh fJ7cQV+ijll8t27Fwk00fGcLi3LheE+9SaGJNOvR2jNVMPAizJAKveHNJVNB63BTYp4O G3QIcDEDIAlgUSslRG1p/IShOqoxJBhHxUo3BSEK2ICrnShfdiX4G8yo7G6xR28ACuvR rThg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719587650; x=1720192450; 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=lW6Pd9Wzwjx1lXXTnOZIchp2EV9ymFzV8ODIWR95e3Y=; b=peAwGL/wWey24IQli9aUrHb+KDjdE0Wj6HVC7YgDh4ZqJqAk0hG9LR1C2pPUS5tWK4 ktelJGcSgrN1iXQxu49EomHiUf0Wis27lI9I3UOjbJ+D4Js/jTlZEarXDpVk7jS7Lpcm i/kYlhRPBALD7Hx1NSCNkFSCyv4zgVhuPKsksxy5pltYHUURCUKUuy22wQlK7jYidfII DQTlmMmqp9I70vgsQLzwcPNNPaLB/QhzQbNvOKk674Et3XLAyY89woroiWD645/7T5uM RhL2iIbJeyky4mqFdvWr92pQpQ+J8XKcFut+oKZfXugh7Uez7e0Dj/IcnYmezy6CST+Y VEKg== X-Gm-Message-State: AOJu0Yya+n8VkhdAIvQaNKcCcURUc4isfsdV5+9Xn2Ec5p+EsaGm2eBG 8mvzE+HU2hdTNWjGudQUdp/lLMwDv0Gg7LSQ9eW4KUF1MTgJ4LKf5EoffQ== X-Google-Smtp-Source: AGHT+IFbFmi/iAMTicJOL2GrOzNLzoQyBgRiskZ/2xLxTlRNgYuIo4NFdDiMjqS4re3zd2jdM6HvsQ== X-Received: by 2002:a05:6a21:3289:b0:1be:cea5:c781 with SMTP id adf61e73a8af0-1becea5cfb2mr6759745637.16.1719587649527; Fri, 28 Jun 2024 08:14:09 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-708043b76a5sm1768887b3a.149.2024.06.28.08.14.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 08:14:09 -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 10/10] hwmon: (amc6821) Convert to with_info API Date: Fri, 28 Jun 2024 08:13:46 -0700 Message-Id: <20240628151346.1152838-11-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240628151346.1152838-1-linux@roeck-us.net> References: <20240628151346.1152838-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%. Signed-off-by: Guenter Roeck --- drivers/hwmon/amc6821.c | 743 +++++++++++++++++++++------------------- 1 file changed, 386 insertions(+), 357 deletions(-) diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index 6ffab4288134..14d59aa4254b 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 @@ -106,28 +109,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) */ @@ -188,232 +169,323 @@ 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", (int8_t)regval * 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: - dev_dbg(dev, "Unknown attr->index (%d).\n", ix); - 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 = (int8_t)regval * 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); - long val; - int ret = kstrtol(buf, 10, &val); - if (ret) - return ret; - - if (val < 0 || val > 255) - return -EINVAL; - - 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 mask; - int err; - err = kstrtol(buf, 10, &val); - if (err) - return err; - - switch (val) { - case 1: - mask = 0; - break; - case 2: - mask = AMC6821_CONF1_FDRC1; - break; - case 3: - mask = AMC6821_CONF1_FDRC0 | AMC6821_CONF1_FDRC1; - break; - case 4: - mask = AMC6821_CONF1_FDRC0; - break; + switch (attr) { + case hwmon_pwm_enable: + switch (val) { + case 1: + mask = 0; + break; + case 2: + mask = AMC6821_CONF1_FDRC1; + break; + case 3: + mask = AMC6821_CONF1_FDRC0 | AMC6821_CONF1_FDRC1; + break; + case 4: + mask = AMC6821_CONF1_FDRC0; + break; + default: + return -EINVAL; + } + return regmap_update_bits(regmap, AMC6821_REG_CONF1, + AMC6821_CONF1_FDRC0 | AMC6821_CONF1_FDRC1, + mask); + 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, - mask); - if (err < 0) - 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 sprintf(buf, "%d\n", val); + err = regmap_bulk_read(regmap, reg, regs, 2); + if (err) + return err; + + regval = (regs[1] << 8) | regs[0]; + *val = 6000000 / (regval ? : 1); + + 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; + + val = clamp_val(6000000 / (val ? : 1), 0, 0xffff); + + switch (attr) { + 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: + return -EOPNOTSUPP; + } + + 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, 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 = dev_get_drvdata(dev); switch (nr) { case 1: @@ -423,7 +495,6 @@ static ssize_t temp_auto_point_temp_show(struct device *dev, return sprintf(buf, "%d\n", data->temp2_auto_point_temp[ix] * 1000); default: - dev_dbg(dev, "Unknown attr->nr (%d).\n", nr); return -EINVAL; } } @@ -579,130 +650,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; - u8 regs[2]; - long val; - int err; - - err = kstrtol(buf, 10, &val); - if (err) - return err; - - val = val < 1 ? 0xFFFF : 6000000 / val; - 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, @@ -718,30 +668,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, @@ -753,13 +679,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; @@ -872,7 +902,6 @@ static int amc6821_probe(struct i2c_client *client) if (!data) return -ENOMEM; - regmap = devm_regmap_init_i2c(client, &amc6821_regmap_config); if (IS_ERR(regmap)) return dev_err_probe(dev, PTR_ERR(regmap), @@ -883,9 +912,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); }