From patchwork Mon May 15 01:30:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 9725987 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C262C60381 for ; Mon, 15 May 2017 01:30:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B59A62892A for ; Mon, 15 May 2017 01:30:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA67728936; Mon, 15 May 2017 01:30:57 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 573262892A for ; Mon, 15 May 2017 01:30:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753783AbdEOBas (ORCPT ); Sun, 14 May 2017 21:30:48 -0400 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:57326 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752570AbdEOBaq (ORCPT ); Sun, 14 May 2017 21:30:46 -0400 Received: from mmarshal3.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 385F78448D; Mon, 15 May 2017 13:30:41 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail; t=1494811841; bh=BAM3tVIBqx8JtcdrZhcY/O0DwX822hC2+1xz8SeVKu8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ONoUjakdYU9OtoXRp/vASnh0tTJ3ghqCTy0f7aGzdJyBw/dd3V2mKcE1Zg8nxOePm wPGFCPpqKUXZdwDTAZcGQPNskcwIiGKzxfYM0ahJdo2GGTq8vB39SbMFU5qSxS9e10 daKcU7JpqOUr0/PvVcmWYWR389SOp30JSLqbVqgc= Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7, 5, 7, 9061) id ; Mon, 15 May 2017 13:30:41 +1200 Received: from chrisp-dl.atlnz.lc (chrisp-dl.ws.atlnz.lc [10.33.22.30]) by smtp (Postfix) with ESMTP id B2A1313F08E; Mon, 15 May 2017 13:30:41 +1200 (NZST) Received: by chrisp-dl.atlnz.lc (Postfix, from userid 1030) id 489341E0BB7; Mon, 15 May 2017 13:30:40 +1200 (NZST) From: Chris Packham To: linux@roeck-us.net, linux-hwmon@vger.kernel.org, jdelvare@suse.com Cc: Chris Packham , linux-kernel@vger.kernel.org Subject: [PATCH v4 3/3] hwmon: (adt7475) add high frequency support Date: Mon, 15 May 2017 13:30:29 +1200 Message-Id: <20170515013029.31397-4-chris.packham@alliedtelesis.co.nz> X-Mailer: git-send-email 2.11.0.24.ge6920cf In-Reply-To: <20170515013029.31397-1-chris.packham@alliedtelesis.co.nz> References: <20170515013029.31397-1-chris.packham@alliedtelesis.co.nz> 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 Systems using 4-wire fans usually require high frequency (22.5kHz) output on the pwm. Add 22500 as a valid option in the pwmfreq_table. In high frequency mode the low-order bit are ignored so they can safely be set to 0. Signed-off-by: Chris Packham --- Changes in v3: - New Changes in v4: - Fix pwmfreq_table array indexing drivers/hwmon/adt7475.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 3056076fae27..1baa213a60bd 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -934,7 +934,7 @@ static ssize_t set_pwmctrl(struct device *dev, struct device_attribute *attr, /* List of frequencies for the PWM */ static const int pwmfreq_table[] = { - 11, 14, 22, 29, 35, 44, 58, 88 + 11, 14, 22, 29, 35, 44, 58, 88, 22500 }; static ssize_t show_pwmfreq(struct device *dev, struct device_attribute *attr, @@ -942,9 +942,10 @@ static ssize_t show_pwmfreq(struct device *dev, struct device_attribute *attr, { struct adt7475_data *data = adt7475_update_device(dev); struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); + int i = clamp_val(data->range[sattr->index] & 0xf, 0, + ARRAY_SIZE(pwmfreq_table) - 1); - return sprintf(buf, "%d\n", - pwmfreq_table[data->range[sattr->index] & 7]); + return sprintf(buf, "%d\n", pwmfreq_table[i]); } static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr, @@ -965,7 +966,7 @@ static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr, data->range[sattr->index] = adt7475_read(TEMP_TRANGE_REG(sattr->index)); - data->range[sattr->index] &= ~7; + data->range[sattr->index] &= ~0xf; data->range[sattr->index] |= out; i2c_smbus_write_byte_data(client, TEMP_TRANGE_REG(sattr->index),