From patchwork Thu Feb 27 08:46:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 11408011 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 36AA91805 for ; Thu, 27 Feb 2020 08:46:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 16D102467B for ; Thu, 27 Feb 2020 08:46:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="UYQM+Vkg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728738AbgB0Iqz (ORCPT ); Thu, 27 Feb 2020 03:46:55 -0500 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:40292 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728720AbgB0Iqz (ORCPT ); Thu, 27 Feb 2020 03:46:55 -0500 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 793B6891AE; Thu, 27 Feb 2020 21:46:52 +1300 (NZDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1582793212; bh=7ES6tEyEz8XnCzXTzvkZrM7yYWWqjmJ6wjX0UjtGUNo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UYQM+VkgT40nWUTOK56c3OPmdy3/3eNIkjCExJgaJJAg1Y8xboPo5QXITBC4whZdx ZkvJcMuRonwPWu4l5dNkvf+zOIq6IR5dl8cfI1GAsTzKsADT8ewSYguM3zUsTsOtQw UVbXC9v1JJOdhjFL6GdeudfQ3u3yKw8UY4UtQOafVfjz1aTEYj6cTa+WlG723FlYO1 stK/R0GBvixN6w4ipNWwzSCM28e+BZcNAcsqBEVZOhMTZI1hOjmlhpqtebCa8EvidO uNbvo5N8x+aZGncym8w8VLn+/7ED5vUMeHOoD6pki/WO3Nog6NdEGOaSpszkjmzhV5 XV21vfKa8+UkQ== Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7,5,8,10121) id ; Thu, 27 Feb 2020 21:46:51 +1300 Received: from chrisp-dl.ws.atlnz.lc (chrisp-dl.ws.atlnz.lc [10.33.22.20]) by smtp (Postfix) with ESMTP id 810C913EECD; Thu, 27 Feb 2020 21:46:51 +1300 (NZDT) Received: by chrisp-dl.ws.atlnz.lc (Postfix, from userid 1030) id 4713C280072; Thu, 27 Feb 2020 21:46:52 +1300 (NZDT) From: Chris Packham To: jdelvare@suse.com, linux@roeck-us.net, robh+dt@kernel.org, mark.rutland@arm.com Cc: logan.shaw@alliedtelesis.co.nz, linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Chris Packham Subject: [PATCH v5 5/5] hwmon: (adt7475) Add support for inverting pwm output Date: Thu, 27 Feb 2020 21:46:42 +1300 Message-Id: <20200227084642.7057-6-chris.packham@alliedtelesis.co.nz> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227084642.7057-1-chris.packham@alliedtelesis.co.nz> References: <20200227084642.7057-1-chris.packham@alliedtelesis.co.nz> MIME-Version: 1.0 x-atlnz-ls: pat Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add a "adi,pwm-active-state" device-tree property to allow hardware designs to use inverted logic on the PWM output. Signed-off-by: Chris Packham --- Notes: Changes in v5: - change to adi,pwm-active-state - uint32 array Changes in v4: - use vendor prefix for new property Changes in v3: - New drivers/hwmon/adt7475.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 3649b18359dc..142a4fec688b 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -1509,6 +1509,36 @@ static int load_attenuators(const struct i2c_client *client, int chip, return 0; } +static int adt7475_set_pwm_polarity(struct i2c_client *client) +{ + u32 states[ADT7475_PWM_COUNT]; + int ret, i; + u8 val; + + ret = of_property_read_u32_array(client->dev.of_node, + "adi,pwm-active-state", states, + ARRAY_SIZE(states)); + if (ret) + return ret; + + for (i = 0; i < ADT7475_PWM_COUNT; i++) { + ret = adt7475_read(PWM_CONFIG_REG(i)); + if (ret < 0) + return ret; + val = ret; + if (states[i]) + val &= ~BIT(4); + else + val |= BIT(4); + + ret = i2c_smbus_write_byte_data(client, PWM_CONFIG_REG(i), val); + if (ret) + return ret; + } + + return 0; +} + static int adt7475_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -1617,6 +1647,10 @@ static int adt7475_probe(struct i2c_client *client, for (i = 0; i < ADT7475_PWM_COUNT; i++) adt7475_read_pwm(client, i); + ret = adt7475_set_pwm_polarity(client); + if (ret && ret != -EINVAL) + dev_err(&client->dev, "Error configuring pwm polarity\n"); + /* Start monitoring */ switch (chip) { case adt7475: