From patchwork Tue Apr 23 13:33:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 10913001 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3E50A1515 for ; Tue, 23 Apr 2019 13:33:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F73928736 for ; Tue, 23 Apr 2019 13:33:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 237E32887D; Tue, 23 Apr 2019 13:33:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C10BB28736 for ; Tue, 23 Apr 2019 13:33:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726801AbfDWNdR (ORCPT ); Tue, 23 Apr 2019 09:33:17 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:40906 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726655AbfDWNdR (ORCPT ); Tue, 23 Apr 2019 09:33:17 -0400 Received: by mail-pf1-f195.google.com with SMTP id c207so7500957pfc.7 for ; Tue, 23 Apr 2019 06:33:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=B2UiuBzj5CPFoIEP3O7C/Y9iGXiGX1o/2iIF9COFt10=; b=uTKFzn9uA4dmTiD696CBXeLdovLikwLnKshNnMETeiQ9nlDeT3FpLa5GczTuNTPa7k KpUNBPT0YDDg1zJkX9Lno9+SJrTphRE+QxlR5Zg1jUBJ0OL6sdb1Ci0r1wexhRpyXMQ9 EdNFYWSJUSugdEDY/0Toi6w1u8YvBcDdsNQv6GFnh22T+B4tA58XfGs6qjjupfpkTvVn xqMITin8aYrSD68kpP3J+w1++R97tvDRVKtXK0MX9jm5N3Z1fGOd9OwXPPGpu3MdB8TE zMgTdEWJmRHaLuYMGADOjbToEsk8u+F9eZI55vW45Ii7NgPZJHkC9w2PbTyvqcIOFh8v eCmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=B2UiuBzj5CPFoIEP3O7C/Y9iGXiGX1o/2iIF9COFt10=; b=ZWZq6PWAACwuGC5hV/alyfaVSGOPg3rz+oRpuVS3IABzsF7i767KDcrFufXaH89TyL l/92Qap1AByQhuBqeFEGZR13nkUQsFEI4O4jso0aTUzetR8/Mc1cQlJFs91onRe6N/Vn teKYji7mslMrmMS3khWC4Y1Z2tVUA3cjd8uyPBXMH7cs2vy5aFB8Qj+KAbd6L1JJ1b8y QvWg2z41lIbJ6UAWbHH8Jwr80bH/80drgjXEr2M+cXRdF2vO5Z0RiYehrlNc6ZMw1BdG RfzoCU6COmRoEP5z8aKTxR2fVgsBcPeCMtd1mrcjdcZQfyFMHw3x2zKw6yE8aZI9/QYd ECzA== X-Gm-Message-State: APjAAAWgGkURnsWDv+CkW4dogadGjrp24OG07aP3S/OHagQN0l6Vn9BU hhd8DUtmiPXDmIPTxiLK6rCc1gbn X-Google-Smtp-Source: APXvYqyDFQGsAkk215oCLk03hRE0iTrBwq6Cc9EIW9lM8HLxzj+TctV5Tm6HAAF1UOa0xGuiA8x6cw== X-Received: by 2002:a63:7444:: with SMTP id e4mr25042798pgn.261.1556026396090; Tue, 23 Apr 2019 06:33:16 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id j19sm24633606pfr.155.2019.04.23.06.33.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 06:33:14 -0700 (PDT) From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck , Jean-Francois Dagenais Subject: [PATCH 01/11] hwmon: (max6650) Use devm_add_action to unregister thermal device Date: Tue, 23 Apr 2019 06:33:01 -0700 Message-Id: <1556026391-15360-1-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use devm_add_action to unregister the thermal cooling device. This lets us drop the remove function. At the same time, use 'dev' variable in probe function consistently. Cc: Jean-Francois Dagenais Signed-off-by: Guenter Roeck --- drivers/hwmon/max6650.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index 939953240827..6cce199dab6a 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c @@ -752,6 +752,11 @@ static const struct thermal_cooling_device_ops max6650_cooling_ops = { .get_cur_state = max6650_get_cur_state, .set_cur_state = max6650_set_cur_state, }; + +static void max6650_thermal_unregister(void *data) +{ + thermal_cooling_device_unregister(data); +} #endif static int max6650_probe(struct i2c_client *client, @@ -794,27 +799,20 @@ static int max6650_probe(struct i2c_client *client, #if IS_ENABLED(CONFIG_THERMAL) data->cooling_dev = - thermal_of_cooling_device_register(client->dev.of_node, + thermal_of_cooling_device_register(dev->of_node, client->name, data, &max6650_cooling_ops); - if (IS_ERR(data->cooling_dev)) - dev_warn(&client->dev, - "thermal cooling device register failed: %ld\n", + if (IS_ERR(data->cooling_dev)) { + dev_warn(dev, "thermal cooling device register failed: %ld\n", PTR_ERR(data->cooling_dev)); + } else { + devm_add_action(dev, max6650_thermal_unregister, + data->cooling_dev); + } #endif return 0; } -static int max6650_remove(struct i2c_client *client) -{ - struct max6650_data *data = i2c_get_clientdata(client); - - if (!IS_ERR(data->cooling_dev)) - thermal_cooling_device_unregister(data->cooling_dev); - - return 0; -} - static const struct i2c_device_id max6650_id[] = { { "max6650", 1 }, { "max6651", 4 }, @@ -828,7 +826,6 @@ static struct i2c_driver max6650_driver = { .of_match_table = of_match_ptr(max6650_dt_match), }, .probe = max6650_probe, - .remove = max6650_remove, .id_table = max6650_id, }; From patchwork Tue Apr 23 13:33:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 10913003 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 25DFB1515 for ; Tue, 23 Apr 2019 13:33:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16B3D28736 for ; Tue, 23 Apr 2019 13:33:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A8552887D; Tue, 23 Apr 2019 13:33:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9301F28736 for ; Tue, 23 Apr 2019 13:33:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727305AbfDWNdT (ORCPT ); Tue, 23 Apr 2019 09:33:19 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:40712 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726655AbfDWNdT (ORCPT ); Tue, 23 Apr 2019 09:33:19 -0400 Received: by mail-pg1-f193.google.com with SMTP id d31so7627582pgl.7 for ; Tue, 23 Apr 2019 06:33:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=6QuEQC8Acwq8/ngaLvJIOqLJtRqH5NI3hqsDkpN460U=; b=ncISTZJkfIwvinlfT6VScODaUlDMqbT4hWSAvtk4ynD0o+ioFz1abhI3WBPKqz97kZ ZPGURM7I3WMpoho/DsaXtqAAQrf8Wns7GDxMCuVIijAa2fKBwZJ09sfVp7bl4iwFk1rs 6SChtPU4j9PC4nb7EVRoHSgcEe8QcjxYLFL86h0hzkhSM6e+SK+Z6eQzfa+JmOeu6/3c V+UkBcCv53Hu/xAkncPRiCKyvSz5JKOIgw5M3iNXuUBPhnN/clslOVqZOKL6J9b8QniE g6apDEA27gmr8wyGBsAyvZlbGuQX2+1qB7RAPHDiu+G8cgBRwqn2AZ75ssy4DIc45Onl A0hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=6QuEQC8Acwq8/ngaLvJIOqLJtRqH5NI3hqsDkpN460U=; b=mQotPE7ebkUv/U7d/nPlcGCY7F9mg04C4yQ7bdPWMSHKRddsOdJQ+dfSSHwaQUsKVG NxT8oWoavhD5/sb3kE3JLSHNTSgiicvhs2p6gD10Xf+Kzz3fjgbe/eG1zYcpZJGEzPfT Y4O2YenGOFsRlOk0hy91DFn/Lfl3jR5EEMhpGd7hfFKu8YO/+Y0VBsQ2gfMwLz0adzsy QnkNiN2twHvAdbi9BUYamOeukXrSWVlHUjSZ8foNBw/ZqE446Q/SxsVhhVAqO4cpsN2l UDiCo1qIQnxM7J4oW3hUAqx4z616nWsIAqeU8lBW5MBs7WpKwHowOAlgc/moKGN4NJb+ /Rbg== X-Gm-Message-State: APjAAAX5V6HGKpS21vdqbsLo36nRukhfALhKsN5douoGFbcuKL7kSnoV ozQebpEOIbV04ML/axIuxU09kwTE X-Google-Smtp-Source: APXvYqyP/q3mt1VZJeLp6Pqd2nFYAvNIHAznxKkIlKd6ETRaFhU2efZRDhpSb9rWAWKzMGjKHJXF0A== X-Received: by 2002:a63:7444:: with SMTP id e4mr25042992pgn.261.1556026398235; Tue, 23 Apr 2019 06:33:18 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id b14sm20724368pfi.92.2019.04.23.06.33.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 06:33:17 -0700 (PDT) From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck , Jean-Francois Dagenais Subject: [PATCH 02/11] hwmon: (max6650) Introduce pwm_to_dac and dac_to_pwm Date: Tue, 23 Apr 2019 06:33:02 -0700 Message-Id: <1556026391-15360-2-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556026391-15360-1-git-send-email-linux@roeck-us.net> References: <1556026391-15360-1-git-send-email-linux@roeck-us.net> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Consolidate conversion from pwm value to dac value and from dac value to pwm value into helper functions. While doing this, only update the cached dac value if writing it to the chip was successful after an update. Also, put macro argument of DIV_FROM_REG() into (). Cc: Jean-Francois Dagenais Signed-off-by: Guenter Roeck --- drivers/hwmon/max6650.c | 53 ++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index 6cce199dab6a..b6b8f8edc1b0 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c @@ -105,7 +105,8 @@ module_param(clock, int, 0444); #define FAN_RPM_MIN 240 #define FAN_RPM_MAX 30000 -#define DIV_FROM_REG(reg) (1 << (reg & 7)) +#define DIV_FROM_REG(reg) (1 << ((reg) & 7)) +#define DAC_LIMIT(v12) ((v12) ? 180 : 76) /* * Client data (each client gets its own) @@ -150,6 +151,22 @@ static const struct of_device_id __maybe_unused max6650_dt_match[] = { }; MODULE_DEVICE_TABLE(of, max6650_dt_match); +static int dac_to_pwm(int dac, bool v12) +{ + /* + * Useful range for dac is 0-180 for 12V fans and 0-76 for 5V fans. + * Lower DAC values mean higher speeds. + */ + return clamp_val(255 - (255 * dac) / DAC_LIMIT(v12), 0, 255); +} + +static u8 pwm_to_dac(unsigned int pwm, bool v12) +{ + int limit = DAC_LIMIT(v12); + + return limit - (limit * pwm) / 255; +} + static struct max6650_data *max6650_update_device(struct device *dev) { struct max6650_data *data = dev_get_drvdata(dev); @@ -357,22 +374,10 @@ static ssize_t fan1_target_store(struct device *dev, static ssize_t pwm1_show(struct device *dev, struct device_attribute *devattr, char *buf) { - int pwm; struct max6650_data *data = max6650_update_device(dev); - /* - * Useful range for dac is 0-180 for 12V fans and 0-76 for 5V fans. - * Lower DAC values mean higher speeds. - */ - if (data->config & MAX6650_CFG_V12) - pwm = 255 - (255 * (int)data->dac)/180; - else - pwm = 255 - (255 * (int)data->dac)/76; - - if (pwm < 0) - pwm = 0; - - return sprintf(buf, "%d\n", pwm); + return sprintf(buf, "%d\n", dac_to_pwm(data->dac, + data->config & MAX6650_CFG_V12)); } static ssize_t pwm1_store(struct device *dev, @@ -383,6 +388,7 @@ static ssize_t pwm1_store(struct device *dev, struct i2c_client *client = data->client; unsigned long pwm; int err; + u8 dac; err = kstrtoul(buf, 10, &pwm); if (err) @@ -391,13 +397,10 @@ static ssize_t pwm1_store(struct device *dev, pwm = clamp_val(pwm, 0, 255); mutex_lock(&data->update_lock); - - if (data->config & MAX6650_CFG_V12) - data->dac = 180 - (180 * pwm)/255; - else - data->dac = 76 - (76 * pwm)/255; - err = i2c_smbus_write_byte_data(client, MAX6650_REG_DAC, data->dac); - + dac = pwm_to_dac(pwm, data->config & MAX6650_CFG_V12); + err = i2c_smbus_write_byte_data(client, MAX6650_REG_DAC, dac); + if (!err) + data->dac = dac; mutex_unlock(&data->update_lock); return err < 0 ? err : count; @@ -728,11 +731,7 @@ static int max6650_set_cur_state(struct thermal_cooling_device *cdev, mutex_lock(&data->update_lock); - if (data->config & MAX6650_CFG_V12) - data->dac = 180 - (180 * state)/255; - else - data->dac = 76 - (76 * state)/255; - + data->dac = pwm_to_dac(state, data->config & MAX6650_CFG_V12); err = i2c_smbus_write_byte_data(client, MAX6650_REG_DAC, data->dac); if (!err) { From patchwork Tue Apr 23 13:33:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 10913005 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CBD75112C for ; Tue, 23 Apr 2019 13:33:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD78328736 for ; Tue, 23 Apr 2019 13:33:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B23C32887D; Tue, 23 Apr 2019 13:33:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C855287FB for ; Tue, 23 Apr 2019 13:33:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727656AbfDWNdV (ORCPT ); Tue, 23 Apr 2019 09:33:21 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:45368 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726655AbfDWNdU (ORCPT ); Tue, 23 Apr 2019 09:33:20 -0400 Received: by mail-pg1-f194.google.com with SMTP id y3so7613222pgk.12 for ; Tue, 23 Apr 2019 06:33:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=n9qvVHdLoiJgCQaY7R3RnCVk3RBwDzs7n8e2FDJaOvU=; b=XQQQ/VhEc0VOXakBO/OMR4tfQFVNtDy34DylzJn3vXYeAAyYAAXQdT391Xf0NuSrNp WP50C9D7qmNQhPUxqU9FKUQi/ZEq3rCgkfTcdNWYEvAWaC+eNmQO7F4GOOrkqaZweEk8 h78mev2kfEJww0syWUNjwM7FSYhZ5raLtNKejpguBEFqe9kiwBK0G7Bprjzv7tuHV2Pb LcqCPySGva02c/L2FXVsM4DeByT10EZ0PzLIj+Osb3EMxmLlBwKfr6+kVop08tc+I73o 9Adgg9YEzJaBIv70TEKHrJK30RrhiZIm9wNuO1UzOyn5+qJRzL1C0g/WG+XNMKkzF4Xm WO4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=n9qvVHdLoiJgCQaY7R3RnCVk3RBwDzs7n8e2FDJaOvU=; b=aEqdZ4udyhFX9QSb2OWOWdNkhA+2TzG6qSBpLHKDUw33QZRz/MEFPeTq1oFjGr4c8m bmPIraVTDDP+BnJidvfGEc1rEP0gmvITtph9qfy2dW8A+7TiWM9/dWa56qh9IXXxX0fl XirXO9fbDrMpF7xw3ioEKQZKdd7V11hlwvcEvK1nP1an7oiFfCrq23t0So5EHeHSwsVS tfd5W/7/fZuSSNL/BevlmU4ba/rhiE4msPPLhHtQ60h8+UYaflsxbpS71+miTLX4bFfx RN5GIEuJZeO8AimVBAZfDIbGeRcsd1x2lyU1fR6m+llYNJR8x/PNQsTqP+M5R/iVG8eb mAtw== X-Gm-Message-State: APjAAAWLuXU4jXTWncmfVMJ4UADD5zSMLrJX2EZll7/eWfLvxqNijNbF nP5TbcOnqK8/VrA7/uVKg+GrY9t3 X-Google-Smtp-Source: APXvYqyA59NsGgh3xr3wZC6HW9Im87pZsiL+rlzQmdOM4z/YikGYHiU5fMZ0c8h2MwVFY0/1kDAhDQ== X-Received: by 2002:a63:c61:: with SMTP id 33mr25261243pgm.293.1556026399974; Tue, 23 Apr 2019 06:33:19 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id f27sm2788230pfk.111.2019.04.23.06.33.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 06:33:19 -0700 (PDT) From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck , Jean-Francois Dagenais Subject: [PATCH 03/11] hwmon: (max6650) Improve error handling in max6650_init_client Date: Tue, 23 Apr 2019 06:33:03 -0700 Message-Id: <1556026391-15360-3-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556026391-15360-1-git-send-email-linux@roeck-us.net> References: <1556026391-15360-1-git-send-email-linux@roeck-us.net> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Do not overwrite errors reported from i2c functions, and don't ignore any errors. Cc: Jean-Francois Dagenais Signed-off-by: Guenter Roeck --- drivers/hwmon/max6650.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index b6b8f8edc1b0..ac05cc5627d7 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c @@ -618,8 +618,8 @@ static int max6650_init_client(struct max6650_data *data, struct i2c_client *client) { struct device *dev = &client->dev; - int config; - int err = -EIO; + int reg; + int err; u32 voltage; u32 prescale; u32 target_rpm; @@ -633,21 +633,20 @@ static int max6650_init_client(struct max6650_data *data, &prescale)) prescale = prescaler; - config = i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG); - - if (config < 0) { - dev_err(dev, "Error reading config, aborting.\n"); - return err; + reg = i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG); + if (reg < 0) { + dev_err(dev, "Error reading config register, aborting.\n"); + return reg; } switch (voltage) { case 0: break; case 5: - config &= ~MAX6650_CFG_V12; + reg &= ~MAX6650_CFG_V12; break; case 12: - config |= MAX6650_CFG_V12; + reg |= MAX6650_CFG_V12; break; default: dev_err(dev, "illegal value for fan_voltage (%d)\n", voltage); @@ -657,22 +656,22 @@ static int max6650_init_client(struct max6650_data *data, case 0: break; case 1: - config &= ~MAX6650_CFG_PRESCALER_MASK; + reg &= ~MAX6650_CFG_PRESCALER_MASK; break; case 2: - config = (config & ~MAX6650_CFG_PRESCALER_MASK) + reg = (reg & ~MAX6650_CFG_PRESCALER_MASK) | MAX6650_CFG_PRESCALER_2; break; case 4: - config = (config & ~MAX6650_CFG_PRESCALER_MASK) + reg = (reg & ~MAX6650_CFG_PRESCALER_MASK) | MAX6650_CFG_PRESCALER_4; break; case 8: - config = (config & ~MAX6650_CFG_PRESCALER_MASK) + reg = (reg & ~MAX6650_CFG_PRESCALER_MASK) | MAX6650_CFG_PRESCALER_8; break; case 16: - config = (config & ~MAX6650_CFG_PRESCALER_MASK) + reg = (reg & ~MAX6650_CFG_PRESCALER_MASK) | MAX6650_CFG_PRESCALER_16; break; default: @@ -680,16 +679,22 @@ static int max6650_init_client(struct max6650_data *data, } dev_info(dev, "Fan voltage: %dV, prescaler: %d.\n", - (config & MAX6650_CFG_V12) ? 12 : 5, - 1 << (config & MAX6650_CFG_PRESCALER_MASK)); + (reg & MAX6650_CFG_V12) ? 12 : 5, + 1 << (reg & MAX6650_CFG_PRESCALER_MASK)); - if (i2c_smbus_write_byte_data(client, MAX6650_REG_CONFIG, config)) { + err = i2c_smbus_write_byte_data(client, MAX6650_REG_CONFIG, reg); + if (err) { dev_err(dev, "Config write error, aborting.\n"); return err; } - data->config = config; - data->count = i2c_smbus_read_byte_data(client, MAX6650_REG_COUNT); + data->config = reg; + reg = i2c_smbus_read_byte_data(client, MAX6650_REG_COUNT); + if (reg < 0) { + dev_err(dev, "Failed to read count register, aborting.\n"); + return reg; + } + data->count = reg; if (!of_property_read_u32(client->dev.of_node, "maxim,fan-target-rpm", &target_rpm)) { From patchwork Tue Apr 23 13:33:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 10913007 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 65EB4112C for ; Tue, 23 Apr 2019 13:33:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5825D28736 for ; Tue, 23 Apr 2019 13:33:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CB9B2887D; Tue, 23 Apr 2019 13:33:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0176628736 for ; Tue, 23 Apr 2019 13:33:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727754AbfDWNdW (ORCPT ); Tue, 23 Apr 2019 09:33:22 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:37353 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726655AbfDWNdW (ORCPT ); Tue, 23 Apr 2019 09:33:22 -0400 Received: by mail-pg1-f194.google.com with SMTP id e6so7629540pgc.4 for ; Tue, 23 Apr 2019 06:33:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=LeFMqufZ1aNyR/ECVgA8MKG1sr/7G1G8j4FK204c/FI=; b=Hah/BTLvvCdpSfWPZyFDGIrNtenau67HRF7oBEBwGJYIQpoHQ2hg7O39nTuukl1AD2 X8rJdm5hdA58pTiP/bSJD1sAc8+WZ5lvWv0IizGgu3hMwrqOMlhUl6+w27VheQwCPi1g TLssOml5RdnbjW0tsXKuTwHuULIsGSCAh+iS91sJMRH1+5S2jV8Zyuz8ypWJf/l2v21D 1wInQ/uM31gzl981/aXMHG5JKP59fzxJ3CdjQfqbfIef93yAdEpZ2VqUe/eTf3UjCE3U b11dbE+WaCPQAllRh86E0VJfSFJhIiKtAWms/5jXmsMnye0JusFxhMFc2N6U0gidwt8E Lf2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=LeFMqufZ1aNyR/ECVgA8MKG1sr/7G1G8j4FK204c/FI=; b=di0wHAKrN1MZ4KMkxewBfgSshbJT3+QjV3x8RtMzKuN8nOhFbH5F76ccfa7LtfbaiX JYAZUya+3dyFmk8LaPs2pqsMCQ/2SvQlbTchVogfnuqMtflQuKH2/5Pdtvno11DHlFfq a8s21Hd2AB1FmPkZ8YbCP3/ebnUpclJDjyPKw0nLFWdkojJDMr/nCIg0DA8iHqqQ5HSR qwpuxROPLxPY7cBOSC3YIW3DW2dPM5NTRtZSxVk7cHTEkNoze67E3eUqn1spT6kJqvD2 7Yl0gxEEb0F5PdeYpM8MI9m8NXyX/TC5rzInd9ey7hnOx95fEZ2rrUjoLsnfq0hUARFM X9sg== X-Gm-Message-State: APjAAAWsiMRz8zutl1qdZvyiO5lPgW6W6jPgt6MGzDCgKvpsp/A0hYsV CHd5gWWxGKCKJCiWneFdXD23BunY X-Google-Smtp-Source: APXvYqyep9D2flkkhKSyoNorSisYlmbirJh5a/VscBkvUvLGbcGo55yUykuBG58JYMXktRNz5Q2AuQ== X-Received: by 2002:a63:171a:: with SMTP id x26mr25303235pgl.438.1556026401728; Tue, 23 Apr 2019 06:33:21 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id j12sm19757432pgg.79.2019.04.23.06.33.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 06:33:20 -0700 (PDT) From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck , Jean-Francois Dagenais Subject: [PATCH 04/11] hwmon: (max6650) Declare valid as boolean Date: Tue, 23 Apr 2019 06:33:04 -0700 Message-Id: <1556026391-15360-4-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556026391-15360-1-git-send-email-linux@roeck-us.net> References: <1556026391-15360-1-git-send-email-linux@roeck-us.net> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Declare valid as boolean to match its use case. Cc: Jean-Francois Dagenais Signed-off-by: Guenter Roeck --- drivers/hwmon/max6650.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index ac05cc5627d7..8fa888b57efa 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c @@ -118,7 +118,7 @@ struct max6650_data { struct thermal_cooling_device *cooling_dev; struct mutex update_lock; int nr_fans; - char valid; /* zero until following fields are valid */ + bool valid; /* false until following fields are valid */ unsigned long last_updated; /* in jiffies */ /* register values */ @@ -197,7 +197,7 @@ static struct max6650_data *max6650_update_device(struct device *dev) MAX6650_REG_ALARM); data->last_updated = jiffies; - data->valid = 1; + data->valid = true; } mutex_unlock(&data->update_lock); From patchwork Tue Apr 23 13:33:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 10913009 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CD76C1515 for ; Tue, 23 Apr 2019 13:33:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDBC128736 for ; Tue, 23 Apr 2019 13:33:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B24D02887D; Tue, 23 Apr 2019 13:33:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A40C28736 for ; Tue, 23 Apr 2019 13:33:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727758AbfDWNdZ (ORCPT ); Tue, 23 Apr 2019 09:33:25 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:44806 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726655AbfDWNdY (ORCPT ); Tue, 23 Apr 2019 09:33:24 -0400 Received: by mail-pf1-f194.google.com with SMTP id y13so7498521pfm.11 for ; Tue, 23 Apr 2019 06:33:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=pGcObMtV4vMLhnhuHLhErwbxM+qb0J/S+nwXzNsCbJ8=; b=kfEqK7EoIINtCNpUipY2OcLkBRq5IadiEQhj+tFy2Ua8lyt4kt3bZFTZgw3NnZXk/j QEb6Q+G6NFexO6ekwYskEuDoqjgNj9oFqoPpSlfj5V8vDs6zfn+R0yAlVZMVRMk4a0QV Q21P1ho6n2p35yA7/Yqrzq87MMy0HxCCcGkDWMC9zIXvZJHcloa66/q+MKtV1SUESYPX NUE/8/Zn4mCe88xNbf1ogE+lQNEdriyfTQsCxtX4oDK5FxTSkncdhu6aiZFTEZ/IU0Hi ci/ZjR8YD6SPhH69hW86EhF6OfQza8uT9/ifG138IjZzRQPnpp0l/1h7tEb5tVkzIFc9 4dqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=pGcObMtV4vMLhnhuHLhErwbxM+qb0J/S+nwXzNsCbJ8=; b=ufLr7or1NtXnYjXRsht1dBFkPTqbe0XPuMO3kx2uuzb2HBSIevVpYxK6XKQQhn+IZ5 J3luVCAQHudLA3GARngU+zXH5lUTHZEqQPBEaUuQM6f9jf9kzyxiPzmY/tBEZQW9m2Jz ushky2WLKzKClLrhteKkJGOdaVYF0E+c+rPFcNI8f2cqOZtb63Oanxqc+wbnhFeD6q7a WNv/hcNhdsnEYTcc0AfHx4gZ1EB/1KJYPvOIoey1v95XSciqQNmzrRBHORahHgglU8f7 87NtmZiWiY6XwLHy4iLW9+YZDIPblTBbJLOFxeTdH4if5ccI18bydCuoBJ15aD6xzMUt u6Og== X-Gm-Message-State: APjAAAWBo46QOYVbg/5s50dG5fHDgcRjASErRpWcD/Jaf+Xx0q8jLi3q FHuB/s3rtNDXFMjE+WHYaN2oV0lb X-Google-Smtp-Source: APXvYqxKhuwoL9YiE4Re7XxhqO0P7Ffeb1gndK1dMOuwJ+ElfokRkWppFLZyxMtq7eCxSCLHuIXIfQ== X-Received: by 2002:a63:e004:: with SMTP id e4mr24883474pgh.344.1556026403513; Tue, 23 Apr 2019 06:33:23 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id h15sm6350512pfr.146.2019.04.23.06.33.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 06:33:22 -0700 (PDT) From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck , Jean-Francois Dagenais Subject: [PATCH 05/11] hwmon: (max6650) Cache alarm_en register Date: Tue, 23 Apr 2019 06:33:05 -0700 Message-Id: <1556026391-15360-5-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556026391-15360-1-git-send-email-linux@roeck-us.net> References: <1556026391-15360-1-git-send-email-linux@roeck-us.net> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The alarm_en register is read each time the is_visible function is called. Since it is a configuration register, this is completely unnecessary. Read it once and cache its value. Cc: Jean-Francois Dagenais Signed-off-by: Guenter Roeck --- drivers/hwmon/max6650.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index 8fa888b57efa..cf051f3acf26 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c @@ -128,6 +128,7 @@ struct max6650_data { u8 count; u8 dac; u8 alarm; + u8 alarm_en; unsigned long cooling_dev_state; }; @@ -559,8 +560,6 @@ static umode_t max6650_attrs_visible(struct kobject *kobj, struct attribute *a, { struct device *dev = container_of(kobj, struct device, kobj); struct max6650_data *data = dev_get_drvdata(dev); - struct i2c_client *client = data->client; - u8 alarm_en = i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM_EN); struct device_attribute *devattr; /* @@ -573,7 +572,7 @@ static umode_t max6650_attrs_visible(struct kobject *kobj, struct attribute *a, || devattr == &sensor_dev_attr_fan1_fault.dev_attr || devattr == &sensor_dev_attr_gpio1_alarm.dev_attr || devattr == &sensor_dev_attr_gpio2_alarm.dev_attr) { - if (!(alarm_en & to_sensor_dev_attr(devattr)->index)) + if (!(data->alarm_en & to_sensor_dev_attr(devattr)->index)) return 0; } @@ -696,6 +695,13 @@ static int max6650_init_client(struct max6650_data *data, } data->count = reg; + reg = i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM_EN); + if (reg < 0) { + dev_err(dev, "Failed to read alarm configuration, aborting.\n"); + return reg; + } + data->alarm_en = reg; + if (!of_property_read_u32(client->dev.of_node, "maxim,fan-target-rpm", &target_rpm)) { max6650_set_target(data, target_rpm); From patchwork Tue Apr 23 13:33:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 10913011 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24D321515 for ; Tue, 23 Apr 2019 13:33:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1638828736 for ; Tue, 23 Apr 2019 13:33:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AFF32887D; Tue, 23 Apr 2019 13:33:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B056E28736 for ; Tue, 23 Apr 2019 13:33:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727776AbfDWNd0 (ORCPT ); Tue, 23 Apr 2019 09:33:26 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:34256 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726655AbfDWNd0 (ORCPT ); Tue, 23 Apr 2019 09:33:26 -0400 Received: by mail-pg1-f196.google.com with SMTP id v12so7642798pgq.1 for ; Tue, 23 Apr 2019 06:33:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=iy6wDuU665dHl0Hi6m6kbnGqDtd0stHO3a+7x+yFHdY=; b=HcAH6uE8tVEw6TDPBKdpXwq9Y/sL6h7fDe4R0SJ5xg2DpxeKg3x6hmihfn+RcO2g9h QIeGw6GBNJZyF9SRG34YPh6Yso2KMHyagCeqiMO0vRdoURXkWlqrsdbAf0RMPfn1sLKq Zd52mbwkQNDYlOiQjp3Dk91nADk6n9hI2P4EuecSjofv2YHhwbpmiwIUMoGTeC6P9rgT dczaBIPfdjnRwtBV2DDXAWpslpNV1nrVdPbuBSYElt1KUziOzJL4LQmbKLTdEXoV1B0M H73pliNrjeG7Bcpk47eaVxm9+ICpLuu85Amrm5d+idPlXLUsv5qZunqo0tUKD22tBZRt 4NFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=iy6wDuU665dHl0Hi6m6kbnGqDtd0stHO3a+7x+yFHdY=; b=MD8v54dnceBtsxf9VJkNwFQ7G+flQb0+72MnkGwZPapF/FZ/B/3jfdhbCE+9YlFyZ9 0nDNe3BJ7NzmWtFZVSFihKIgU8q4/R6HXkVYCA2A2NCqsdocknOwPz4gsCekibJ3Xe33 dfpLCxkBMFw4kGUlALXclGUFc9lJL/Qr9PGDMcKBIIb3mUaMlvHSZw2gDQBax9ij8m74 AHBBxV7ke/QG84ddeJn+kX0i8MTfaOf+CVZY6kckOVzV8D+qKhPDnnLG//nWsIvStkVg 2pEm1jjCNiKvKID1D87DjM/rzKy4Fqy/155kQShlmfxoeLjZQSRyWIh8o/8oXJykoz/W e0UA== X-Gm-Message-State: APjAAAXXsXKp24eA1FctdQe9IIgblHKCWeKr/ek4B7q0/U0av4Q03pG6 8ujeIGH0h1z0bnELNYw7f7DNukXr X-Google-Smtp-Source: APXvYqyBOEV1860/F47dT2sDkboPNs/2amMRveh2b6UB0hxFKHdp2lZjPJa8CCpCDklqHhAmJu+3eA== X-Received: by 2002:a63:b305:: with SMTP id i5mr24617570pgf.274.1556026405368; Tue, 23 Apr 2019 06:33:25 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id c1sm21071387pfd.114.2019.04.23.06.33.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 06:33:24 -0700 (PDT) From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck , Jean-Francois Dagenais Subject: [PATCH 06/11] hwmon: (max6650) Simplify alarm handling Date: Tue, 23 Apr 2019 06:33:06 -0700 Message-Id: <1556026391-15360-6-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556026391-15360-1-git-send-email-linux@roeck-us.net> References: <1556026391-15360-1-git-send-email-linux@roeck-us.net> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of re-reading the alarm register after reporting an alarm, mark cached values as invalid. While this results in always reading all data on subsequent reads, it is quite unlikely that such reads will actually happen before the cache times out. The upside is avoiding unnecessary unconditional i2c read operations. Cc: Jean-Francois Dagenais Signed-off-by: Guenter Roeck --- drivers/hwmon/max6650.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index cf051f3acf26..c02694d70eee 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c @@ -526,15 +526,12 @@ static ssize_t alarm_show(struct device *dev, { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct max6650_data *data = max6650_update_device(dev); - struct i2c_client *client = data->client; - int alarm = 0; + bool alarm = data->alarm & attr->index; - if (data->alarm & attr->index) { + if (alarm) { mutex_lock(&data->update_lock); - alarm = 1; data->alarm &= ~attr->index; - data->alarm |= i2c_smbus_read_byte_data(client, - MAX6650_REG_ALARM); + data->valid = false; mutex_unlock(&data->update_lock); } From patchwork Tue Apr 23 13:33:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 10913013 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 20537112C for ; Tue, 23 Apr 2019 13:33:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 109E128736 for ; Tue, 23 Apr 2019 13:33:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04FE72887D; Tue, 23 Apr 2019 13:33:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4FC028736 for ; Tue, 23 Apr 2019 13:33:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727795AbfDWNd2 (ORCPT ); Tue, 23 Apr 2019 09:33:28 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:46520 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726655AbfDWNd2 (ORCPT ); Tue, 23 Apr 2019 09:33:28 -0400 Received: by mail-pg1-f193.google.com with SMTP id v2so5204038pge.13 for ; Tue, 23 Apr 2019 06:33:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Uq962SE9DlRCWxG3UvCH/7+kxAGwY6qQCB0UflcgdKE=; b=i6Kw7ORYp2KNxK0+dqjRXgPvIBWJpVk0LOMi7rLCBq759jdoT89CpURL/NtdlSn6Yv 2bRJR4+OzF7L4FnIpRFGlRSpFEyYQf7sbSYFE5RgyVqXiSJE49la0qXzlt/CmkOXZ0pE 2rCMRYOVOKSMyRvxRDM7H4rcqprQbhMWZUkDsMeeNFqxznUPmlIj0eR8MBJkjtmL4lCK /RJTyucslJfO+xZCgS1BC0yDRxCVcBLa7iCOBekugPhdUfuU/yeqQMaV2BdJl9SWLKdC okzw4KWoJhRNXnnSrDayLPy8cflOG59wiMfYs25mkG415z6DYZ8JjgpPJ9vFUqgFmI31 quWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Uq962SE9DlRCWxG3UvCH/7+kxAGwY6qQCB0UflcgdKE=; b=EYHpGxHgj2Ddll8nAibnZp/lYE3x2TVlYDt6RVAAIdYVK3/KrisjjgYulxiXaGXKvz Yiov9NBa6KFkGrWuSeZhuHqbibnly81ZGHgdvuDHWB7BEKYTzqAm/iu202t/3te9f/g7 QCWHvy0gO22yb4aHrVS9Ya/TJMv34JogTWIrdFpFUo7kZ8RkZdPXVxZTCgdf+co/1Nfs vyp/1mn3twEX2DWJE3rqkX/3WLtc9IDmcqZ6EtUpb/XDcezvyAKDI7q8khlOTKiQv/+2 VZcvIfODXkjGhjorfq/f1gN7R/LS3cKyQYmDDxHJJ8lq278U5c9AeesDxLPfFtB37wlM EGuA== X-Gm-Message-State: APjAAAXEhjb0RwlrrSYJ1L0hrZuBHrlUelDyxsQl2680yoHpz8J6HyqX jWLI1iu32p4uGwzW9dPxmo98TJYm X-Google-Smtp-Source: APXvYqwxqPREoVkDiIkmyFlkyTKIdVLkd3X4Z1V3T6pbYFlO1f8NK8tOmDt0sIMZSXwgnufy2RvyNw== X-Received: by 2002:a65:5089:: with SMTP id r9mr24540668pgp.14.1556026407125; Tue, 23 Apr 2019 06:33:27 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id x6sm39745996pfb.171.2019.04.23.06.33.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 06:33:26 -0700 (PDT) From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck , Jean-Francois Dagenais Subject: [PATCH 07/11] hwmon: (max6650) Convert to use devm_hwmon_device_register_with_info Date: Tue, 23 Apr 2019 06:33:07 -0700 Message-Id: <1556026391-15360-7-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556026391-15360-1-git-send-email-linux@roeck-us.net> References: <1556026391-15360-1-git-send-email-linux@roeck-us.net> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert driver to use devm_hwmon_device_register_with_info to simplify the code and to reduce its size. Cc: Jean-Francois Dagenais Signed-off-by: Guenter Roeck --- drivers/hwmon/max6650.c | 505 +++++++++++++++++++++++------------------------- 1 file changed, 244 insertions(+), 261 deletions(-) diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index c02694d70eee..301184172ab1 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c @@ -114,7 +114,6 @@ module_param(clock, int, 0444); struct max6650_data { struct i2c_client *client; - const struct attribute_group *groups[3]; struct thermal_cooling_device *cooling_dev; struct mutex update_lock; int nr_fans; @@ -230,26 +229,6 @@ static int max6650_set_operating_mode(struct max6650_data *data, u8 mode) return 0; } -static ssize_t fan_show(struct device *dev, struct device_attribute *devattr, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct max6650_data *data = max6650_update_device(dev); - int rpm; - - /* - * Calculation details: - * - * Each tachometer counts over an interval given by the "count" - * register (0.25, 0.5, 1 or 2 seconds). This module assumes - * that the fans produce two pulses per revolution (this seems - * to be the most common). - */ - - rpm = ((data->tach[attr->index] * 120) / DIV_FROM_REG(data->count)); - return sprintf(buf, "%d\n", rpm); -} - /* * Set the fan speed to the specified RPM (or read back the RPM setting). * This works in closed loop mode only. Use pwm1 for open loop speed setting. @@ -291,26 +270,6 @@ static ssize_t fan_show(struct device *dev, struct device_attribute *devattr, * controlled. */ -static ssize_t fan1_target_show(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct max6650_data *data = max6650_update_device(dev); - int kscale, ktach, rpm; - - /* - * Use the datasheet equation: - * - * FanSpeed = KSCALE x fCLK / [256 x (KTACH + 1)] - * - * then multiply by 60 to give rpm. - */ - - kscale = DIV_FROM_REG(data->config); - ktach = data->speed; - rpm = 60 * kscale * clock / (256 * (ktach + 1)); - return sprintf(buf, "%d\n", rpm); -} - static int max6650_set_target(struct max6650_data *data, unsigned long rpm) { int kscale, ktach; @@ -339,183 +298,8 @@ static int max6650_set_target(struct max6650_data *data, unsigned long rpm) data->speed); } -static ssize_t fan1_target_store(struct device *dev, - struct device_attribute *devattr, - const char *buf, size_t count) -{ - struct max6650_data *data = dev_get_drvdata(dev); - unsigned long rpm; - int err; - - err = kstrtoul(buf, 10, &rpm); - if (err) - return err; - - mutex_lock(&data->update_lock); - - err = max6650_set_target(data, rpm); - - mutex_unlock(&data->update_lock); - - if (err < 0) - return err; - - return count; -} - -/* - * Get/set the fan speed in open loop mode using pwm1 sysfs file. - * Speed is given as a relative value from 0 to 255, where 255 is maximum - * speed. Note that this is done by writing directly to the chip's DAC, - * it won't change the closed loop speed set by fan1_target. - * Also note that due to rounding errors it is possible that you don't read - * back exactly the value you have set. - */ - -static ssize_t pwm1_show(struct device *dev, struct device_attribute *devattr, - char *buf) -{ - struct max6650_data *data = max6650_update_device(dev); - - return sprintf(buf, "%d\n", dac_to_pwm(data->dac, - data->config & MAX6650_CFG_V12)); -} - -static ssize_t pwm1_store(struct device *dev, - struct device_attribute *devattr, const char *buf, - size_t count) -{ - struct max6650_data *data = dev_get_drvdata(dev); - struct i2c_client *client = data->client; - unsigned long pwm; - int err; - u8 dac; - - err = kstrtoul(buf, 10, &pwm); - if (err) - return err; - - pwm = clamp_val(pwm, 0, 255); - - mutex_lock(&data->update_lock); - dac = pwm_to_dac(pwm, data->config & MAX6650_CFG_V12); - err = i2c_smbus_write_byte_data(client, MAX6650_REG_DAC, dac); - if (!err) - data->dac = dac; - mutex_unlock(&data->update_lock); - - return err < 0 ? err : count; -} - -/* - * Get/Set controller mode: - * Possible values: - * 0 = Fan always on - * 1 = Open loop, Voltage is set according to speed, not regulated. - * 2 = Closed loop, RPM for all fans regulated by fan1 tachometer - * 3 = Fan off - */ -static ssize_t pwm1_enable_show(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct max6650_data *data = max6650_update_device(dev); - int mode = (data->config & MAX6650_CFG_MODE_MASK) >> 4; - int sysfs_modes[4] = {0, 3, 2, 1}; - - return sprintf(buf, "%d\n", sysfs_modes[mode]); -} - -static ssize_t pwm1_enable_store(struct device *dev, - struct device_attribute *devattr, - const char *buf, size_t count) -{ - struct max6650_data *data = dev_get_drvdata(dev); - unsigned long mode; - int err; - const u8 max6650_modes[] = { - MAX6650_CFG_MODE_ON, - MAX6650_CFG_MODE_OPEN_LOOP, - MAX6650_CFG_MODE_CLOSED_LOOP, - MAX6650_CFG_MODE_OFF, - }; - - err = kstrtoul(buf, 10, &mode); - if (err) - return err; - - if (mode >= ARRAY_SIZE(max6650_modes)) - return -EINVAL; - - mutex_lock(&data->update_lock); - - max6650_set_operating_mode(data, max6650_modes[mode]); - - mutex_unlock(&data->update_lock); - - return count; -} - -/* - * Read/write functions for fan1_div sysfs file. The MAX6650 has no such - * divider. We handle this by converting between divider and counttime: - * - * (counttime == k) <==> (divider == 2^k), k = 0, 1, 2, or 3 - * - * Lower values of k allow to connect a faster fan without the risk of - * counter overflow. The price is lower resolution. You can also set counttime - * using the module parameter. Note that the module parameter "prescaler" also - * influences the behaviour. Unfortunately, there's no sysfs attribute - * defined for that. See the data sheet for details. - */ - -static ssize_t fan1_div_show(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct max6650_data *data = max6650_update_device(dev); - - return sprintf(buf, "%d\n", DIV_FROM_REG(data->count)); -} - -static ssize_t fan1_div_store(struct device *dev, - struct device_attribute *devattr, - const char *buf, size_t count) -{ - struct max6650_data *data = dev_get_drvdata(dev); - struct i2c_client *client = data->client; - unsigned long div; - int err; - - err = kstrtoul(buf, 10, &div); - if (err) - return err; - - mutex_lock(&data->update_lock); - switch (div) { - case 1: - data->count = 0; - break; - case 2: - data->count = 1; - break; - case 4: - data->count = 2; - break; - case 8: - data->count = 3; - break; - default: - mutex_unlock(&data->update_lock); - return -EINVAL; - } - - i2c_smbus_write_byte_data(client, MAX6650_REG_COUNT, data->count); - mutex_unlock(&data->update_lock); - - return count; -} - /* - * Get alarm stati: + * Get gpio alarm status: * Possible values: * 0 = no alarm * 1 = alarm @@ -538,17 +322,6 @@ static ssize_t alarm_show(struct device *dev, return sprintf(buf, "%d\n", alarm); } -static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0); -static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1); -static SENSOR_DEVICE_ATTR_RO(fan3_input, fan, 2); -static SENSOR_DEVICE_ATTR_RO(fan4_input, fan, 3); -static DEVICE_ATTR_RW(fan1_target); -static DEVICE_ATTR_RW(fan1_div); -static DEVICE_ATTR_RW(pwm1_enable); -static DEVICE_ATTR_RW(pwm1); -static SENSOR_DEVICE_ATTR_RO(fan1_max_alarm, alarm, MAX6650_ALRM_MAX); -static SENSOR_DEVICE_ATTR_RO(fan1_min_alarm, alarm, MAX6650_ALRM_MIN); -static SENSOR_DEVICE_ATTR_RO(fan1_fault, alarm, MAX6650_ALRM_TACH); static SENSOR_DEVICE_ATTR_RO(gpio1_alarm, alarm, MAX6650_ALRM_GPIO1); static SENSOR_DEVICE_ATTR_RO(gpio2_alarm, alarm, MAX6650_ALRM_GPIO2); @@ -564,11 +337,8 @@ static umode_t max6650_attrs_visible(struct kobject *kobj, struct attribute *a, */ devattr = container_of(a, struct device_attribute, attr); - if (devattr == &sensor_dev_attr_fan1_max_alarm.dev_attr - || devattr == &sensor_dev_attr_fan1_min_alarm.dev_attr - || devattr == &sensor_dev_attr_fan1_fault.dev_attr - || devattr == &sensor_dev_attr_gpio1_alarm.dev_attr - || devattr == &sensor_dev_attr_gpio2_alarm.dev_attr) { + if (devattr == &sensor_dev_attr_gpio1_alarm.dev_attr || + devattr == &sensor_dev_attr_gpio2_alarm.dev_attr) { if (!(data->alarm_en & to_sensor_dev_attr(devattr)->index)) return 0; } @@ -577,14 +347,6 @@ static umode_t max6650_attrs_visible(struct kobject *kobj, struct attribute *a, } static struct attribute *max6650_attrs[] = { - &sensor_dev_attr_fan1_input.dev_attr.attr, - &dev_attr_fan1_target.attr, - &dev_attr_fan1_div.attr, - &dev_attr_pwm1_enable.attr, - &dev_attr_pwm1.attr, - &sensor_dev_attr_fan1_max_alarm.dev_attr.attr, - &sensor_dev_attr_fan1_min_alarm.dev_attr.attr, - &sensor_dev_attr_fan1_fault.dev_attr.attr, &sensor_dev_attr_gpio1_alarm.dev_attr.attr, &sensor_dev_attr_gpio2_alarm.dev_attr.attr, NULL @@ -595,21 +357,11 @@ static const struct attribute_group max6650_group = { .is_visible = max6650_attrs_visible, }; -static struct attribute *max6651_attrs[] = { - &sensor_dev_attr_fan2_input.dev_attr.attr, - &sensor_dev_attr_fan3_input.dev_attr.attr, - &sensor_dev_attr_fan4_input.dev_attr.attr, +static const struct attribute_group *max6650_groups[] = { + &max6650_group, NULL }; -static const struct attribute_group max6651_group = { - .attrs = max6651_attrs, -}; - -/* - * Real code - */ - static int max6650_init_client(struct max6650_data *data, struct i2c_client *client) { @@ -766,6 +518,241 @@ static void max6650_thermal_unregister(void *data) } #endif +static int max6650_read(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long *val) +{ + struct max6650_data *data = max6650_update_device(dev); + int mode; + + switch (type) { + case hwmon_pwm: + switch (attr) { + case hwmon_pwm_input: + *val = dac_to_pwm(data->dac, + data->config & MAX6650_CFG_V12); + break; + case hwmon_pwm_enable: + /* + * Possible values: + * 0 = Fan always on + * 1 = Open loop, Voltage is set according to speed, + * not regulated. + * 2 = Closed loop, RPM for all fans regulated by fan1 + * tachometer + * 3 = Fan off + */ + mode = (data->config & MAX6650_CFG_MODE_MASK) >> 4; + *val = (4 - mode) & 3; /* {0 1 2 3} -> {0 3 2 1} */ + break; + default: + return -EOPNOTSUPP; + } + break; + case hwmon_fan: + switch (attr) { + case hwmon_fan_input: + /* + * Calculation details: + * + * Each tachometer counts over an interval given by the + * "count" register (0.25, 0.5, 1 or 2 seconds). + * The driver assumes that the fans produce two pulses + * per revolution (this seems to be the most common). + */ + *val = DIV_ROUND_CLOSEST(data->tach[channel] * 120, + DIV_FROM_REG(data->count)); + break; + case hwmon_fan_div: + *val = DIV_FROM_REG(data->count); + break; + case hwmon_fan_target: + /* + * Use the datasheet equation: + * FanSpeed = KSCALE x fCLK / [256 x (KTACH + 1)] + * then multiply by 60 to give rpm. + */ + *val = 60 * DIV_FROM_REG(data->config) * clock / + (256 * (data->speed + 1)); + break; + case hwmon_fan_min_alarm: + *val = !!(data->alarm & MAX6650_ALRM_MIN); + data->alarm &= ~MAX6650_ALRM_MIN; + data->valid = false; + break; + case hwmon_fan_max_alarm: + *val = !!(data->alarm & MAX6650_ALRM_MAX); + data->alarm &= ~MAX6650_ALRM_MAX; + data->valid = false; + break; + case hwmon_fan_fault: + *val = !!(data->alarm & MAX6650_ALRM_TACH); + data->alarm &= ~MAX6650_ALRM_TACH; + data->valid = false; + break; + default: + return -EOPNOTSUPP; + } + break; + default: + return -EOPNOTSUPP; + } + return 0; +} + +const u8 max6650_pwm_modes[] = { + MAX6650_CFG_MODE_ON, + MAX6650_CFG_MODE_OPEN_LOOP, + MAX6650_CFG_MODE_CLOSED_LOOP, + MAX6650_CFG_MODE_OFF, +}; + +static int max6650_write(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long val) +{ + struct max6650_data *data = dev_get_drvdata(dev); + int ret = 0; + u8 reg; + + mutex_lock(&data->update_lock); + + switch (type) { + case hwmon_pwm: + switch (attr) { + case hwmon_pwm_input: + reg = pwm_to_dac(clamp_val(val, 0, 255), + data->config & MAX6650_CFG_V12); + ret = i2c_smbus_write_byte_data(data->client, + MAX6650_REG_DAC, reg); + if (ret) + break; + data->dac = reg; + break; + case hwmon_pwm_enable: + if (val < 0 || val >= ARRAY_SIZE(max6650_pwm_modes)) + return -EINVAL; + ret = max6650_set_operating_mode(data, + max6650_pwm_modes[val]); + break; + default: + ret = -EOPNOTSUPP; + break; + } + case hwmon_fan: + switch (attr) { + case hwmon_fan_div: + switch (val) { + case 1: + reg = 0; + break; + case 2: + reg = 1; + break; + case 4: + reg = 2; + break; + case 8: + reg = 3; + break; + default: + ret = -EINVAL; + goto error; + } + ret = i2c_smbus_write_byte_data(data->client, + MAX6650_REG_COUNT, reg); + if (ret) + break; + data->count = reg; + break; + case hwmon_fan_target: + if (val < 0) { + ret = -EINVAL; + break; + } + ret = max6650_set_target(data, val); + break; + default: + ret = -EOPNOTSUPP; + break; + } + break; + default: + ret = -EOPNOTSUPP; + break; + } + +error: + mutex_unlock(&data->update_lock); + return ret; +} + +static umode_t max6650_is_visible(const void *_data, + enum hwmon_sensor_types type, u32 attr, + int channel) +{ + const struct max6650_data *data = _data; + + if (channel && (channel >= data->nr_fans || type != hwmon_fan)) + return 0; + + switch (type) { + case hwmon_fan: + switch (attr) { + case hwmon_fan_input: + return 0444; + case hwmon_fan_target: + case hwmon_fan_div: + return 0644; + case hwmon_fan_min_alarm: + if (data->alarm_en & MAX6650_ALRM_MIN) + return 0444; + break; + case hwmon_fan_max_alarm: + if (data->alarm_en & MAX6650_ALRM_MAX) + return 0444; + break; + case hwmon_fan_fault: + if (data->alarm_en & MAX6650_ALRM_TACH) + return 0444; + break; + default: + break; + } + break; + case hwmon_pwm: + switch (attr) { + case hwmon_pwm_input: + case hwmon_pwm_enable: + return 0644; + default: + break; + } + break; + default: + break; + } + return 0; +} + +static const struct hwmon_channel_info *max6650_info[] = { + HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_DIV | + HWMON_F_MIN_ALARM | HWMON_F_MAX_ALARM | + HWMON_F_FAULT, + HWMON_F_INPUT, HWMON_F_INPUT, HWMON_F_INPUT), + HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE), + NULL +}; + +static const struct hwmon_ops max6650_hwmon_ops = { + .read = max6650_read, + .write = max6650_write, + .is_visible = max6650_is_visible, +}; + +static const struct hwmon_chip_info max6650_chip_info = { + .ops = &max6650_hwmon_ops, + .info = max6650_info, +}; + static int max6650_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -792,14 +779,10 @@ static int max6650_probe(struct i2c_client *client, if (err) return err; - data->groups[0] = &max6650_group; - /* 3 additional fan inputs for the MAX6651 */ - if (data->nr_fans == 4) - data->groups[1] = &max6651_group; - - hwmon_dev = devm_hwmon_device_register_with_groups(dev, - client->name, data, - data->groups); + hwmon_dev = devm_hwmon_device_register_with_info(dev, + client->name, data, + &max6650_chip_info, + max6650_groups); err = PTR_ERR_OR_ZERO(hwmon_dev); if (err) return err; From patchwork Tue Apr 23 13:33:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 10913015 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BA6ED1515 for ; Tue, 23 Apr 2019 13:33:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A671528736 for ; Tue, 23 Apr 2019 13:33:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B0DB2887D; Tue, 23 Apr 2019 13:33:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4395528736 for ; Tue, 23 Apr 2019 13:33:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727812AbfDWNda (ORCPT ); Tue, 23 Apr 2019 09:33:30 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:37366 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726655AbfDWNd3 (ORCPT ); Tue, 23 Apr 2019 09:33:29 -0400 Received: by mail-pg1-f196.google.com with SMTP id e6so7629729pgc.4 for ; Tue, 23 Apr 2019 06:33:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=c9QrzKrL/UB0/0inA34pNYc1HJpllaSc+gekWPocaSY=; b=fMUpO7/41IWFNloFqTh1SBqDccpjf+UFTgVcuOmy973PKG70PkfUoTsC22gA3JO6/v 47AXYxsQraNsFEDmFNB7f/+JtzsLKHQO3ozdCw3m6iY6NGqukIHMhBLZR5RNhwrKnBxY V1us8paNBV5KrGgZiN4+nkCDfbU5fouoQK0x99UffR+2jKsCoLUO6IGDwKSNBD35UHcl Qemha/UDWMx0Bgvw0rQIa60nmFVDp+3mkE5dUXeQdRzEZb9cQ4PmYS3At+/8C9Ecc8LD TpsrU8gRSJ0YpmvuQKsEBgYf/nctLmmp7deLzZVfU9DaZ6/LSuffZe6Lt8150uqi8xbs IHsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=c9QrzKrL/UB0/0inA34pNYc1HJpllaSc+gekWPocaSY=; b=ZHXpE24SQscVc5FUHg/SfcaWux7hTKixDwLD3fyw8pRVL43rD8eWfwa9ELOFJfIkEu u1kqMy5iexD44SbHBSTwYYuEGguYoypde0ukeCsbn9F/aGOOCvMU80eGqnqi7m447lxg 3FriEl2SUSlPpHZ6CxYP/glwa7hMLFSWAFUPHMJZOvXTisdK4INhohL3xwgCsfPKCWNo 78SmWhHvTcYOvCFaxZlsq+bovFYz8hkc44LSRzQDYIigCdpEygEX3T1n96wNjWe32S8E YkceL8Is6dnz7H7JwrYvaiSGJDJxA87jMXyjWPMclivJn9Q/GA/r9J9xiVA61ErQ+HGy csQw== X-Gm-Message-State: APjAAAUBvmmK2KOQ3Af8guwv6pG+tMIzTMC/OdwqwvUJa1ZK8fMD6naA 7Fnc8N9LQKR29+OGEI1za9Jjw0Yj X-Google-Smtp-Source: APXvYqw5O5IijseW9e77bmUAtCJz5BDAKzQOy9V4sSHc8nNotMRM5RdYC2w4oikdJnbTTH4rtDWSQg== X-Received: by 2002:a63:494f:: with SMTP id y15mr24624152pgk.56.1556026408830; Tue, 23 Apr 2019 06:33:28 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id j5sm20913038pfe.15.2019.04.23.06.33.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 06:33:28 -0700 (PDT) From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck , Jean-Francois Dagenais Subject: [PATCH 08/11] hwmon: (max6650) Read non-volatile registers only once Date: Tue, 23 Apr 2019 06:33:08 -0700 Message-Id: <1556026391-15360-8-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556026391-15360-1-git-send-email-linux@roeck-us.net> References: <1556026391-15360-1-git-send-email-linux@roeck-us.net> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Only tachometer and alarm status registers are modified by the chip. All other registers only need to be read only once, and reading them repeatedly does not add any value. Cc: Jean-Francois Dagenais Signed-off-by: Guenter Roeck --- drivers/hwmon/max6650.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index 301184172ab1..7c8b1b8ededc 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c @@ -176,17 +176,10 @@ static struct max6650_data *max6650_update_device(struct device *dev) mutex_lock(&data->update_lock); if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { - data->speed = i2c_smbus_read_byte_data(client, - MAX6650_REG_SPEED); - data->config = i2c_smbus_read_byte_data(client, - MAX6650_REG_CONFIG); for (i = 0; i < data->nr_fans; i++) { data->tach[i] = i2c_smbus_read_byte_data(client, tach_reg[i]); } - data->count = i2c_smbus_read_byte_data(client, - MAX6650_REG_COUNT); - data->dac = i2c_smbus_read_byte_data(client, MAX6650_REG_DAC); /* * Alarms are cleared on read in case the condition that @@ -435,8 +428,22 @@ static int max6650_init_client(struct max6650_data *data, dev_err(dev, "Config write error, aborting.\n"); return err; } - data->config = reg; + + reg = i2c_smbus_read_byte_data(client, MAX6650_REG_SPEED); + if (reg < 0) { + dev_err(dev, "Failed to read speed register, aborting.\n"); + return reg; + } + data->speed = reg; + + reg = i2c_smbus_read_byte_data(client, MAX6650_REG_DAC); + if (reg < 0) { + dev_err(dev, "Failed to read DAC register, aborting.\n"); + return reg; + } + data->dac = reg; + reg = i2c_smbus_read_byte_data(client, MAX6650_REG_COUNT); if (reg < 0) { dev_err(dev, "Failed to read count register, aborting.\n"); From patchwork Tue Apr 23 13:33:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 10913017 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 622D6112C for ; Tue, 23 Apr 2019 13:33:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5077028736 for ; Tue, 23 Apr 2019 13:33:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 446D12887D; Tue, 23 Apr 2019 13:33:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA88328736 for ; Tue, 23 Apr 2019 13:33:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727815AbfDWNdb (ORCPT ); Tue, 23 Apr 2019 09:33:31 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:41318 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726655AbfDWNdb (ORCPT ); Tue, 23 Apr 2019 09:33:31 -0400 Received: by mail-pf1-f195.google.com with SMTP id 188so7502175pfd.8 for ; Tue, 23 Apr 2019 06:33:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=uVYTZjgdXMQ/MJbbt7RN8oRmdDqyxdXIQwT02b93xtk=; b=D0ta/tqF602yPitvvyg9xzhTgJi6lbmGzR4hqxeeKB2X6ShKNEyomo0ttxBAuppKCe nNVScYi68dDn5fZ7YeEHQzCZUifokZdaC61vPAZqs7S84WRJfpoextZTynvWVTXnRWkY tYV37m2euMtCYIg7/Y2kr3V3ug6O3XOHy1FvZZdDpaaqFlZcI4RK0KxoqyxszJFb6yKI s/3Wrp/IK99VLlA4c4tNH0n2mbcrw8Fkt2QTfH7Clb+0ZniY9O8+pC8A16mrpbimXzJz ECLmd5IZwSEHCl/rmGrmk7QoR9hK858PkZUa6g2K0kmbK5nKEvnHSkbgmJsn1pOFlMF9 jvRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=uVYTZjgdXMQ/MJbbt7RN8oRmdDqyxdXIQwT02b93xtk=; b=NegaoGDAk0CWd8UjX37pubyJOfisFK19bTTYCOf4t+F095mnVrv+WKI69mxpo+6ZRX RqLTLXSv2nqn/VYXag2oEsiaCUcFyDlDzCyHNlsCXJ1nomkRyDiPOhUR8OAx+O/GPR47 hQdi05e6t+2Rvq156J33t3D1CvOPUqT3TFNQwhIaBF+El8e3ETKqCD3EK9fV8SZ4JkYS CUSw3Iea0e4JMXmAU6cR4SYaVVRnAeiAcuMLtMAqhJmz1sbaUB/62r5AYmKBpkEZgiR8 QwWrVsT8XT6tGbcE3XU0J9kLdPHFIUsFDi2dLq2yUCoSrMWabpdPJoUAKyoUUsUojS8d m9zw== X-Gm-Message-State: APjAAAVg9e5ZbTgxtGqj1HmJ0J94e7SGjJintCrXFqYWGj9/hROd0cWU RJ5uGZIDqFNgCD9QoDJKo1srP1fF X-Google-Smtp-Source: APXvYqyyI/XMm3Rwq8MKHy4Mp2PCL9KTtU3JYxW/nJpoR03KW1CdCPF8tmPHweHB21i2aK8LxUzMQA== X-Received: by 2002:aa7:8282:: with SMTP id s2mr26675695pfm.7.1556026410450; Tue, 23 Apr 2019 06:33:30 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id q10sm19591274pgh.93.2019.04.23.06.33.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 06:33:29 -0700 (PDT) From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck , Jean-Francois Dagenais Subject: [PATCH 09/11] hwmon: (max6650) Improve error handling in max6650_update_device Date: Tue, 23 Apr 2019 06:33:09 -0700 Message-Id: <1556026391-15360-9-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556026391-15360-1-git-send-email-linux@roeck-us.net> References: <1556026391-15360-1-git-send-email-linux@roeck-us.net> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Pass errors from i2c_smbus_read_byte_data() back to the caller of max6650_update_device(). Cc: Jean-Francois Dagenais Signed-off-by: Guenter Roeck --- drivers/hwmon/max6650.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index 7c8b1b8ededc..3c79949a741c 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c @@ -171,14 +171,19 @@ static struct max6650_data *max6650_update_device(struct device *dev) { struct max6650_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; + int reg, err = 0; int i; mutex_lock(&data->update_lock); if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { for (i = 0; i < data->nr_fans; i++) { - data->tach[i] = i2c_smbus_read_byte_data(client, - tach_reg[i]); + reg = i2c_smbus_read_byte_data(client, tach_reg[i]); + if (reg < 0) { + err = reg; + goto error; + } + data->tach[i] = reg; } /* @@ -186,15 +191,20 @@ static struct max6650_data *max6650_update_device(struct device *dev) * caused the alarm is removed. Keep the value latched here * for providing the register through different alarm files. */ - data->alarm |= i2c_smbus_read_byte_data(client, - MAX6650_REG_ALARM); - + reg = i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM); + if (reg < 0) { + err = reg; + goto error; + } + data->alarm |= reg; data->last_updated = jiffies; data->valid = true; } +error: mutex_unlock(&data->update_lock); - + if (err) + data = ERR_PTR(err); return data; } @@ -303,8 +313,12 @@ static ssize_t alarm_show(struct device *dev, { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct max6650_data *data = max6650_update_device(dev); - bool alarm = data->alarm & attr->index; + bool alarm; + if (IS_ERR(data)) + return PTR_ERR(data); + + alarm = data->alarm & attr->index; if (alarm) { mutex_lock(&data->update_lock); data->alarm &= ~attr->index; @@ -531,6 +545,9 @@ static int max6650_read(struct device *dev, enum hwmon_sensor_types type, struct max6650_data *data = max6650_update_device(dev); int mode; + if (IS_ERR(data)) + return PTR_ERR(data); + switch (type) { case hwmon_pwm: switch (attr) { From patchwork Tue Apr 23 13:33:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 10913019 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 08120112C for ; Tue, 23 Apr 2019 13:33:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED8E9287FB for ; Tue, 23 Apr 2019 13:33:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1E972888E; Tue, 23 Apr 2019 13:33:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82AE0287FB for ; Tue, 23 Apr 2019 13:33:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727819AbfDWNdd (ORCPT ); Tue, 23 Apr 2019 09:33:33 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:39029 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726655AbfDWNdd (ORCPT ); Tue, 23 Apr 2019 09:33:33 -0400 Received: by mail-pg1-f193.google.com with SMTP id l18so7492002pgj.6 for ; Tue, 23 Apr 2019 06:33:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=0epv67DQy1tcGredx/ZYA/voDATZj4/orE/2fEAJJhM=; b=nCCDtwVyxNHoZmAPbK2YwNTzwrgDsaEnYod6RBsVSFAo8pINhwHnlDwLGRmudX454J 4cel23BGMnRDkcFIPpht3zBxGakVNuvvumWrb24kFsk0DeM9WrYqSKPsciTcgOZjqXjQ BdvIa4rnPoQb/L5E3Z1o1NM9zT1Ik5hQeZs8VQpvkPY0CpT9Q6O60+0glvMv/vuZFfAf Vl1Sd4A9bLSCV5bH4TzdIAhgOEjdrmpdBC+z2cv/+q6U5E2W6si56F4HRV7v49VWyz+A AvJkfxjztcJ6a5mzJhdfSg4wx5TD3WdnOJ5YiL3NDLZytVxaEntP0jJwCQeOMWXUvotV kc9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=0epv67DQy1tcGredx/ZYA/voDATZj4/orE/2fEAJJhM=; b=H/94kE85dVDwnmBXVdwjL1GooOWQwqQzVnVkWKYPToRuoctmrblNrxKhoQ26e4ZMvm 8W1RrJ/raWMccszVzbrgHpuxQydPJSsmDP4Z+RHputMbeoUE/ZbjfMOYg5Vl9XSc6ccy curnwSnWlWpMbQQY3+fzRoBhpskMdGlbUyA/N6SiTCLDkVHwnIak2BhAupsXAr07lITE dHFwp64n3J2hed78bzRj03UfrUIan6LENc+eYqdYrtBCYgCS365vmvEnvke804HJnpM+ YZmayRKbdFa6DtgspcarpoGZAn4tXtNm5r7r27GeXlpARbU7oV43Ac1Mq5zxR0SXcXYw zMiA== X-Gm-Message-State: APjAAAXf+2636EwFxwn1QnlEbP5ZDq/CyOySDmA2BDWESVi52WCW3bAd wwnEU+43JK6eklbKFIQ/Zq9W8RPQ X-Google-Smtp-Source: APXvYqyUN9Gw11Y6ZrkazFBER6LBxH5S3dt1M91KrXkxE77lthzjDp8YREoFvl+gEFgy+93YaQeoCw== X-Received: by 2002:a62:6f47:: with SMTP id k68mr27040940pfc.196.1556026412059; Tue, 23 Apr 2019 06:33:32 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id m16sm35286271pfi.29.2019.04.23.06.33.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 06:33:31 -0700 (PDT) From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck , Jean-Francois Dagenais Subject: [PATCH 10/11] hwmon: (max6650) Use SPDX license identifier Date: Tue, 23 Apr 2019 06:33:10 -0700 Message-Id: <1556026391-15360-10-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556026391-15360-1-git-send-email-linux@roeck-us.net> References: <1556026391-15360-1-git-send-email-linux@roeck-us.net> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace boilerplace license text with SPDX license identifier. Cc: Jean-Francois Dagenais Signed-off-by: Guenter Roeck --- drivers/hwmon/max6650.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index 3c79949a741c..83824e0c9a8e 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * max6650.c - Part of lm_sensors, Linux kernel modules for hardware * monitoring. @@ -13,22 +14,7 @@ * chips. * * The datasheet was last seen at: - * * http://pdfserv.maxim-ic.com/en/ds/MAX6650-MAX6651.pdf - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include From patchwork Tue Apr 23 13:33:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 10913021 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F2241515 for ; Tue, 23 Apr 2019 13:33:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 006CA28736 for ; Tue, 23 Apr 2019 13:33:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8FA52887D; Tue, 23 Apr 2019 13:33:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94B1F28736 for ; Tue, 23 Apr 2019 13:33:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727825AbfDWNdf (ORCPT ); Tue, 23 Apr 2019 09:33:35 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:41299 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726655AbfDWNdf (ORCPT ); Tue, 23 Apr 2019 09:33:35 -0400 Received: by mail-pg1-f194.google.com with SMTP id f6so7613152pgs.8 for ; Tue, 23 Apr 2019 06:33:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=emizb0Bm8pNop8Ua+O0Wj8j5Wmqxw6pBjnGlQIQmGw0=; b=eKw0cRnkunYh7UimKUnfR2JaJo8ruwQi5EtDHtBaKPtMklz4wQU9vFwuIJ2pWA39J0 rZufsgnRcTtgZYRPHkZa1t5R2MKo0P/Hd0tFbYoQw3WBnOU4xlnQbQdzKLoSRd5MF1yA YGXkKm9vu8LQUpxcdhs9K6HYUCl0xsqjDrwqAZIxFvUb0ovp1+1poXEXDpC93p6IcA5y 12mbyCWET6Tsq3+9rzWkgzx3ihJmPJZg+WcWlQ3toW7uRa8VH+v9xkfTw54g8kGl7t4U Zba1Cvh5+idUOnJD7C4pnU6Iw9Uvqd3HjEd9862F3r8YSTgBgL0gJq3GdbeBv0GuemW9 Y71g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=emizb0Bm8pNop8Ua+O0Wj8j5Wmqxw6pBjnGlQIQmGw0=; b=q5tYhOj+oERndwHQx2QgW2e1kwNetvuM1GmTCCvWQW5f0t1aO6sCARmWr0lOX9n+UB EtInmS+8yEJeNFfnkxCxvXjiCjpdrWNqiIjw5xasz5AEBBfl8lhHX3nwtzst7leM8FXZ rlIqLYiuIG0N7+qEE0ISGzEtvI6hyZUOQd9yMiB9zAc2wAxGCKV6Ozn0OidpPmTwuZq3 k/g+8bbEEvlnqYdCVq5zCmsgCGFrJlZsponG8YqLYv5KqWEFdeRnBLyKQX+uEdRW5Ww8 gGaOO45WiagZ7TGzGAdthfMSQIEqJ2SeVp2Jf7AU2lMp8heUEh03nJt4/NGDtlczH/1w sEkA== X-Gm-Message-State: APjAAAUrQFhwrFAg4yMlfx7I6ze8aJxN8+iNfD+dSuFGPk5XNoEFY7HB tKBdrwiGf7ZIOzV7Ow+iAHMfGN9Y X-Google-Smtp-Source: APXvYqxcuf3klNPRIfkExQaXFPb1PCWV/V7DN3lLWEydEh+HROhZA9pmoSMtwHzzmVXl+2vktH02aA== X-Received: by 2002:a62:140d:: with SMTP id 13mr1372125pfu.114.1556026413969; Tue, 23 Apr 2019 06:33:33 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id z14sm21729265pfn.161.2019.04.23.06.33.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 06:33:33 -0700 (PDT) From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck , Jean-Francois Dagenais Subject: [PATCH 11/11] hwmon: (max6650) Fix minor formatting issues Date: Tue, 23 Apr 2019 06:33:11 -0700 Message-Id: <1556026391-15360-11-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556026391-15360-1-git-send-email-linux@roeck-us.net> References: <1556026391-15360-1-git-send-email-linux@roeck-us.net> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP CHECK: struct mutex definition without comment CHECK: Alignment should match open parenthesis Cc: Jean-Francois Dagenais Signed-off-by: Guenter Roeck --- drivers/hwmon/max6650.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index 83824e0c9a8e..635ef662f600 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c @@ -101,7 +101,7 @@ module_param(clock, int, 0444); struct max6650_data { struct i2c_client *client; struct thermal_cooling_device *cooling_dev; - struct mutex update_lock; + struct mutex update_lock; /* protect alarm register updates */ int nr_fans; bool valid; /* false until following fields are valid */ unsigned long last_updated; /* in jiffies */ @@ -319,7 +319,7 @@ static SENSOR_DEVICE_ATTR_RO(gpio1_alarm, alarm, MAX6650_ALRM_GPIO1); static SENSOR_DEVICE_ATTR_RO(gpio2_alarm, alarm, MAX6650_ALRM_GPIO2); static umode_t max6650_attrs_visible(struct kobject *kobj, struct attribute *a, - int n) + int n) { struct device *dev = container_of(kobj, struct device, kobj); struct max6650_data *data = dev_get_drvdata(dev); @@ -500,11 +500,10 @@ static int max6650_set_cur_state(struct thermal_cooling_device *cdev, data->dac = pwm_to_dac(state, data->config & MAX6650_CFG_V12); err = i2c_smbus_write_byte_data(client, MAX6650_REG_DAC, data->dac); - if (!err) { max6650_set_operating_mode(data, state ? - MAX6650_CFG_MODE_OPEN_LOOP : - MAX6650_CFG_MODE_OFF); + MAX6650_CFG_MODE_OPEN_LOOP : + MAX6650_CFG_MODE_OFF); data->cooling_dev_state = state; }