Received: by 10.223.185.111 with SMTP id b44csp1574043wrg; Sat, 10 Mar 2018 08:52:09 -0800 (PST) X-Google-Smtp-Source: AG47ELu+FRIdxhhDnpfCq9nkBhWWCdIk9hD9DFIQD7vFOE0w9qC+9gEnTUFY+voT/FNDY1KAd8Wn X-Received: by 2002:a17:902:7482:: with SMTP id h2-v6mr1413133pll.98.1520700729297; Sat, 10 Mar 2018 08:52:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520700729; cv=none; d=google.com; s=arc-20160816; b=BtPZPAdnAv7t7Flxo2lpTyWVd+TrizxNrdB9yn8meXI1nFMLkASIepHpO3KbC2udo+ IqWfwxmPB/iOCxvK4l368xq3m2E12AnFK7wiv68FpCtO2WNbs+uj1v2f9L6RT43NYYCu HhNaUf6Csuw+R69SEifrpCglIjDduCDYYo8r6qsCi8UlBwMlR7Z7P1fV4qxmGuIyDvjj vOOxf/PWggFxeQCT6tJ+xKwYEQ+v/+ghlc29yENF3R4mB9o9DRXT4ePpypJcVIo1OXBK zIlEHi8jArllxx7M5eKIIpTDBKt12vlPoJWoVB8ZZqAJDRFFhhblxVp18Y4O1S1lqI6Y IAcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=PpdCfxJ6yuo5MubD5jxFbMNQDP7en0mTXXsnyw/b6qk=; b=RXlWrNByNJZKFUleqVlZdW0LFYkJNGKOjgeRl33HjHasLrB16CCJXZr6gaR1o1nPjT 4TRasmA0jIkt4PV5m6Plp3zXw4/MQrD98mdkcsyfouRSi3THW8PW27UnbdXzjyDzByoT RKuvyoSNgAWeAB7AUOUKLPjkCvXf2WK1QNiJ6jzzTLJnxMv+/X+0rtBAphoTFjcskZBs nsHqNrMbDenzan+qWuJSzPC+glBBJK4zesVaDcSuvVZYkQ/Od+Wn7iNwW7t2Pd5vsJdE WSWfnNvbCc+nbXeTnUhEL5wXnsFbf9c5SQ+gEU2GlhPCsIJz3d0ubr6m8kax63J4GJ7B 627A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=pk3Zj6vY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s62si2541473pgc.184.2018.03.10.08.51.54; Sat, 10 Mar 2018 08:52:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=pk3Zj6vY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751213AbeCJQvA (ORCPT + 99 others); Sat, 10 Mar 2018 11:51:00 -0500 Received: from mail-ot0-f193.google.com ([74.125.82.193]:39949 "EHLO mail-ot0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750946AbeCJQu6 (ORCPT ); Sat, 10 Mar 2018 11:50:58 -0500 Received: by mail-ot0-f193.google.com with SMTP id l12so11535930otj.7; Sat, 10 Mar 2018 08:50:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=PpdCfxJ6yuo5MubD5jxFbMNQDP7en0mTXXsnyw/b6qk=; b=pk3Zj6vYplpIraa/6jbDLEIaMehALm0pOSK2pe0B3DQYYAKyaW0RGD+gCVB0zQ6HDQ Qx0869eastrZYdJzIzsuJxARQDtmGoiI5LzxkD8GjlcajXEXGxvTfC3frHzaD772i03I /DbvlNofwlVCmpOtv2e9SidUfq8XyuRh3OScMIriOsSC+NX6Xngs4Sab1crjsApZ257W oofdrNxYbDbudeF0h9q1sXIBXrS+UmnwDJMVOp6r72PZdZMHQ9brJFlIofDAxVK+wb14 RYDE0B8K9MjhkIbTAA/+QumrUd6pKnUUOuTvaTGP14jSWsGu1OXgVyFbqzZnzLITi6+V nBaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=PpdCfxJ6yuo5MubD5jxFbMNQDP7en0mTXXsnyw/b6qk=; b=A68nD6cVoyBOwmMJp0f3sOtAFlvIzWjNRBM8UrdBbQQ+2RArNFgy6A1TptHiL6j8gy 7WPo1Nvq/GQl5k6zSSY31mq3MfwaKxL4SNio/PMKwlPq0j4XBIz7cBsYVC9mbYcoiTaR NgCkdwLCsEZSSki+zvZOyhtwikQByA/paNox8mLJ9UabmTGWnKw52WxQNMtEPBoAoyrM v3AjPV/PVBKkYBZ0eN1/DR5DphYD5qcWAWoeSl0Y5r5E5MMpt7wf/gq7+td60ytHwD4N Ez7dP5dTWLDt1rH4+AsZlpIwZ4E7b+dpY3rpoSEPn/PPt4PYINDzpPqFMD4v8XgmFNYb HYgA== X-Gm-Message-State: AElRT7HGue054SHxYPWij0pDNimfwhHZRDXesteKwLg7V1/FqA5QtREv +M3lADLofcbe57aC9ObcKGc= X-Received: by 10.157.31.122 with SMTP id x55mr1649178otx.248.1520700657599; Sat, 10 Mar 2018 08:50:57 -0800 (PST) Received: from server.roeck-us.net (108-223-40-66.lightspeed.sntcca.sbcglobal.net. [108.223.40.66]) by smtp.gmail.com with ESMTPSA id y9sm1637010oia.54.2018.03.10.08.50.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 10 Mar 2018 08:50:57 -0800 (PST) Subject: Re: [PATCH 2/2] hwmon: (ucd9000) Add debugfs attributes to provide mfr_status To: Eddie James , linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jdelvare@suse.com, joel@jms.id.au, Christopher Bostic , Andrew Jeffery References: <1520623196-9534-1-git-send-email-eajames@linux.vnet.ibm.com> <1520623196-9534-3-git-send-email-eajames@linux.vnet.ibm.com> From: Guenter Roeck Message-ID: Date: Sat, 10 Mar 2018 08:50:55 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1520623196-9534-3-git-send-email-eajames@linux.vnet.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/09/2018 11:19 AM, Eddie James wrote: > From: Christopher Bostic > > Expose the gpiN_fault fields of mfr_status as individual debugfs > attributes. This provides a way for users to be easily notified of gpi > faults. Also provide the whole mfr_status register in debugfs. > > Signed-off-by: Christopher Bostic > Signed-off-by: Andrew Jeffery > Signed-off-by: Eddie James > --- > drivers/hwmon/pmbus/ucd9000.c | 172 +++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 171 insertions(+), 1 deletion(-) > > diff --git a/drivers/hwmon/pmbus/ucd9000.c b/drivers/hwmon/pmbus/ucd9000.c > index e3a507f..297da0e 100644 > --- a/drivers/hwmon/pmbus/ucd9000.c > +++ b/drivers/hwmon/pmbus/ucd9000.c > @@ -19,6 +19,7 @@ > * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. > */ > > +#include > #include > #include > #include > @@ -36,6 +37,7 @@ > #define UCD9000_NUM_PAGES 0xd6 > #define UCD9000_FAN_CONFIG_INDEX 0xe7 > #define UCD9000_FAN_CONFIG 0xe8 > +#define UCD9000_MFR_STATUS 0xf3 > #define UCD9000_GPIO_SELECT 0xfa > #define UCD9000_GPIO_CONFIG 0xfb > #define UCD9000_DEVICE_ID 0xfd > @@ -63,13 +65,22 @@ > #define UCD901XX_NUM_GPIOS 26 > #define UCD90910_NUM_GPIOS 26 > > +#define UCD9000_DEBUGFS_NAME_LEN 24 > +#define UCD9000_GPI_COUNT 8 > + > struct ucd9000_data { > u8 fan_data[UCD9000_NUM_FAN][I2C_SMBUS_BLOCK_MAX]; > struct pmbus_driver_info info; > struct gpio_chip gpio; > + struct dentry *debugfs; > }; > #define to_ucd9000_data(_info) container_of(_info, struct ucd9000_data, info) > > +struct ucd9000_debugfs_entry { > + struct i2c_client *client; > + u8 index; > +}; > + > static int ucd9000_get_fan_config(struct i2c_client *client, int fan) > { > int fan_config = 0; > @@ -328,6 +339,156 @@ static int ucd9000_gpio_direction_output(struct gpio_chip *gc, > val); > } > > +#if IS_ENABLED(CONFIG_DEBUG_FS) > +static int ucd9000_get_mfr_status(struct i2c_client *client, u8 *buffer) > +{ > + int ret = pmbus_set_page(client, 0); > + > + if (ret < 0) > + return ret; > + > + /* > + * With the ucd90120 and ucd90124 devices, this command [MFR_STATUS] > + * is 2 bytes long (bits 0-15). With the ucd90240 this command is 5 > + * bytes long. With all other devices, it is 4 bytes long. > + */ > + return i2c_smbus_read_block_data(client, UCD9000_MFR_STATUS, buffer); > +} > + > +static int ucd9000_debugfs_show_mfr_status_bit(void *data, u64 *val) > +{ > + struct ucd9000_debugfs_entry *entry = data; > + struct i2c_client *client = entry->client; > + u8 buffer[4]; > + int ret; > + > + /* > + * This attribute is only created for devices that return 4 bytes for > + * status_mfr, so it's safe to call with 4-byte buffer. > + */ > + ret = ucd9000_get_mfr_status(client, buffer); > + if (ret < 0) { > + dev_err(&client->dev, "Failed to read mfr status. rc:%d\n", > + ret); > + > + return ret; > + } > + > + /* > + * Attribute only created for devices with gpi fault bits at bits > + * 16-23, which is the second byte of the response. > + */ > + *val = !!(buffer[1] & BIT(entry->index)); > + > + return 0; > +} > +DEFINE_DEBUGFS_ATTRIBUTE(ucd9000_debugfs_mfr_status_bit, > + ucd9000_debugfs_show_mfr_status_bit, NULL, "%1lld\n"); > + > +static int ucd9000_debugfs_show_mfr_status_word2(void *data, u64 *val) > +{ > + struct i2c_client *client = data; > + __be16 buffer; > + int ret; > + > + ret = ucd9000_get_mfr_status(client, (u8 *)&buffer); > + if (ret < 0) { > + dev_err(&client->dev, "Failed to read mfr status. rc:%d\n", > + ret); > + > + return ret; > + } > + > + *val = be16_to_cpu(buffer); > + > + return 0; > +} > +DEFINE_DEBUGFS_ATTRIBUTE(ucd9000_debugfs_mfr_status_word2, > + ucd9000_debugfs_show_mfr_status_word2, NULL, > + "%04llx\n"); > + > +static int ucd9000_debugfs_show_mfr_status_word4(void *data, u64 *val) > +{ > + struct i2c_client *client = data; > + __be32 buffer; > + int ret; > + > + ret = ucd9000_get_mfr_status(client, (u8 *)&buffer); > + if (ret < 0) { > + dev_err(&client->dev, "Failed to read mfr status. rc:%d\n", > + ret); > + > + return ret; > + } > + > + *val = be32_to_cpu(buffer); > + > + return 0; > +} > +DEFINE_DEBUGFS_ATTRIBUTE(ucd9000_debugfs_mfr_status_word4, > + ucd9000_debugfs_show_mfr_status_word4, NULL, > + "%08llx\n"); > + > +static int ucd9000_init_debugfs(struct i2c_client *client, > + const struct i2c_device_id *mid, > + struct ucd9000_data *data) > +{ > + struct dentry *debugfs; > + struct ucd9000_debugfs_entry *entries; > + int i; > + char name[UCD9000_DEBUGFS_NAME_LEN]; > + > + debugfs = pmbus_get_debugfs_dir(client); > + if (!debugfs) > + return -ENOENT; > + > + data->debugfs = debugfs_create_dir(client->name, debugfs); > + if (!data->debugfs) > + return -ENOENT; > + > + /* > + * Of the chips this driver supports, only the UCD9090, UCD90160, > + * and UCD90910 report GPI faults in their MFR_STATUS register, so only > + * create the GPI fault debugfs attributes for those chips. > + */ > + if (mid->driver_data == ucd9090 || mid->driver_data == ucd90160 || > + mid->driver_data == ucd90910) { > + entries = devm_kzalloc(&client->dev, > + sizeof(*entries) * UCD9000_GPI_COUNT, > + GFP_KERNEL); > + if (!entries) > + return -ENOMEM; > + > + for (i = 0; i < UCD9000_GPI_COUNT; i++) { > + entries[i].client = client; > + entries[i].index = i; > + scnprintf(name, UCD9000_DEBUGFS_NAME_LEN, > + "gpi%d_alarm", i + 1); > + debugfs_create_file(name, 0444, data->debugfs, > + &entries[i], > + &ucd9000_debugfs_mfr_status_bit); > + } > + > + scnprintf(name, UCD9000_DEBUGFS_NAME_LEN, "mfr_status"); > + debugfs_create_file(name, 0444, data->debugfs, client, > + &ucd9000_debugfs_mfr_status_word4); > + } else if (mid->driver_data == ucd90120 || > + mid->driver_data == ucd90124) { > + scnprintf(name, UCD9000_DEBUGFS_NAME_LEN, "mfr_status"); > + debugfs_create_file(name, 0444, data->debugfs, client, > + &ucd9000_debugfs_mfr_status_word2); > + } > + > + return 0; > +} Is all that complexity really worth it ? Why not just read the manufacturing status as byte string into a buffer and use hexdump to pront it, no matter how many bytes are actually returned ? This would also be less error prone, and automatically support future chips. Thanks, Guenter > +#else > +static int ucd9000_init_debugfs(struct i2c_client *client, > + struct ucd9000_data *data) > +{ > + return 0; > +} > +#endif /* IS_ENABLED(CONFIG_DEBUG_FS) */ > + > static int ucd9000_probe(struct i2c_client *client, > const struct i2c_device_id *id) > { > @@ -483,7 +644,16 @@ static int ucd9000_probe(struct i2c_client *client, > return ret; > } > > - return pmbus_do_probe(client, mid, info); > + ret = pmbus_do_probe(client, mid, info); > + if (ret) > + return ret; > + > + ret = ucd9000_init_debugfs(client, mid, data); > + if (ret) > + dev_warn(&client->dev, "Failed to register debugfs: %d\n", > + ret); > + > + return 0; > } > > /* This is the driver that will be inserted */ >