Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp758744pxb; Fri, 22 Apr 2022 10:31:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEI6IJdoHMlZuuaPQoy5DfbxtO9b/iTMcezp2+1+FXEo++6KRmzngN4FU973UEhJ+pfuF4 X-Received: by 2002:a17:90a:f3d6:b0:1cb:91e3:f1f6 with SMTP id ha22-20020a17090af3d600b001cb91e3f1f6mr17384006pjb.171.1650648712244; Fri, 22 Apr 2022 10:31:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650648712; cv=none; d=google.com; s=arc-20160816; b=GO1GRpTqzEZoHBTaxHZOrPWrrV5boHGkBuW7u55eAXo37SEX7S7WjuM33u/riScZKK 2SnUOyGG7cxukNX9UWCuu2ZYgd6Hxf629OhFni5DTzeXubCSMpKAHwbr1fs/I5DNqY4Z 0k8bule8EXvtRRG8BqJZaKDU12/FRRrR7c6JfxVcV+1+Zw4j3IH2I8UicZYs/udTyvA5 l+TFQdN28OdsFeYt47EthLGgrQdcnalVzoY+ncrCaBfC2JHhgF8P2+gnqNXk91Uy9gY1 NdU5S/EBpDY+NkznYJrvU62iMbntk5MyQC06Kct8P/YQE4v6g9cgAVhf3yYGgzD2WIiU hvLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:reply-to:cc :from:dkim-signature:date; bh=KmMNR6faHtqUvs9lVAABz3wIvjkciGijqVJv/rEeN9I=; b=MBM01dUn2yjQ4DaJAfkc5L8Ewf9CzfZkm+FxcqhqwEIihj4ycz1b6A9GeI3E/hDwGu TqaRw6wLxT/eUXzt+ezkAQEhWgJMeqo216Xn3ZqcFnCimp4DuwqX1fPaBo2zyDWddpR7 wmmj8Zfr33gJsVoyXEM9XVZ/9K2siMSbNYKvfyNbNr2ZJAuwk5Jk8onzjmF+s8dVnMrg sxkFcqi91SXSueRH4oTTNRCCYxFZiCJulz0sangKg4lUsW8GZNIJbCpjrRE7k1/VbESU n/N3E7vfmai665WjayPZ5LdQ8JqC10gklXrFdqn/dccrN/EPvPJhhbiV86+go6VMn5my CGLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wujek.eu header.s=protonmail2 header.b=BQOGgQSp; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id ot7-20020a17090b3b4700b001d10b7911d8si9510322pjb.10.2022.04.22.10.31.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 10:31:52 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=fail header.i=@wujek.eu header.s=protonmail2 header.b=BQOGgQSp; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B2465D0827; Fri, 22 Apr 2022 10:24:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382630AbiDTVoI (ORCPT + 99 others); Wed, 20 Apr 2022 17:44:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382624AbiDTVoH (ORCPT ); Wed, 20 Apr 2022 17:44:07 -0400 Received: from mail-4323.proton.ch (mail-4323.proton.ch [185.70.43.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06CF8427CD; Wed, 20 Apr 2022 14:41:16 -0700 (PDT) Date: Wed, 20 Apr 2022 21:41:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wujek.eu; s=protonmail2; t=1650490875; bh=KmMNR6faHtqUvs9lVAABz3wIvjkciGijqVJv/rEeN9I=; h=Date:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=BQOGgQSpieFh8CzNHO1r9GsXm5vX25hwrxRQgpNc6JPeFNbfvuyQYPPXqk63USmoq 4wFe02/TalZU1zaSWcQwbJYXRBhRGrUJMARxkPReRzYl5wBG4kVcZwT4/ekUHsk+6L 4B0ImiqaYTAqHQcD0EQ/abedaoDN7/0YwuBHbXcq3/3GWHT0RVR89hw3dYlTUQDVQr uwxdYoAjZOdfjisuC+yRsvRF1u2tg6qt4wJ6t12TgnmPmBWoRP7RDcsvD04YcvhMH/ RirH6RldwGVSdf7ncjjo7pAjR5/hIuJuAdcEQoWNzaOAwcf9N9DSdpsibnFOADnX9d cQea3NZRgV+rA== From: Adam Wujek Cc: Adam Wujek , Guenter Roeck , Jean Delvare , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Reply-To: Adam Wujek Subject: [v4 PATCH] hwmon: (pmbus) add MFR_* registers to debugfs Message-ID: <20220420214053.482902-1-dev_public@wujek.eu> In-Reply-To: <1b12cb3a-3d87-8254-b229-dcf83ad0bc0a@roeck-us.net> References: <20220419215326.309991-1-dev_public@wujek.eu> <20220420122128.411757-1-dev_public@wujek.eu> <6f697b2c-58aa-6ca4-966b-147bcc184dad@roeck-us.net> <1b12cb3a-3d87-8254-b229-dcf83ad0bc0a@roeck-us.net> Feedback-ID: 23425257:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add registers to debugfs: PMBUS_MFR_ID PMBUS_MFR_MODEL PMBUS_MFR_REVISION PMBUS_MFR_LOCATION PMBUS_MFR_DATE PMBUS_MFR_SERIAL Signed-off-by: Adam Wujek --- Notes: Changes in v2: - Rebase to the latest kernel - Marked wrongly as a part of series of patches Changes in v3: - Submit as a single patch. V2 was wrongly submitted as a part of series of patches - Add justification for "rc +=3D 2;" - Increase allocated memory for debugfs entries Changes in v4: - Change "rc +=3D 2;" into "rc +=3D 1;". With "rc +=3D 2" an extra '\0'= is observed after '\n' at the end of debugfs file's output. drivers/hwmon/pmbus/pmbus_core.c | 89 +++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_c= ore.c index d93574d6a1fb..a791e5f08fb2 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -2627,6 +2627,33 @@ static int pmbus_debugfs_get_status(void *data, u64 = *val) DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_statu= s, =09=09=09 NULL, "0x%04llx\n"); +static ssize_t pmbus_debugfs_mfr_read(struct file *file, char __user *buf, +=09=09=09=09 size_t count, loff_t *ppos) +{ +=09int rc; +=09struct pmbus_debugfs_entry *entry =3D file->private_data; +=09char data[I2C_SMBUS_BLOCK_MAX + 2] =3D { 0 }; + +=09rc =3D i2c_smbus_read_block_data(entry->client, entry->reg, data); +=09if (rc < 0) +=09=09return rc; + +=09/* Add newline at the end of a read data */ +=09data[rc] =3D '\n'; + +=09/* Include newline into the length */ +=09rc +=3D 1; + +=09return simple_read_from_buffer(buf, count, ppos, data, rc); +} + +static const struct file_operations pmbus_debugfs_ops_mfr =3D { +=09.llseek =3D noop_llseek, +=09.read =3D pmbus_debugfs_mfr_read, +=09.write =3D NULL, +=09.open =3D simple_open, +}; + static int pmbus_debugfs_get_pec(void *data, u64 *val) { =09struct i2c_client *client =3D data; @@ -2693,7 +2720,7 @@ static int pmbus_init_debugfs(struct i2c_client *clie= nt, =09/* Allocate the max possible entries we need. */ =09entries =3D devm_kcalloc(data->dev, -=09=09=09 data->info->pages * 10, sizeof(*entries), +=09=09=09 data->info->pages * 16, sizeof(*entries), =09=09=09 GFP_KERNEL); =09if (!entries) =09=09return -ENOMEM; @@ -2803,6 +2830,66 @@ static int pmbus_init_debugfs(struct i2c_client *cli= ent, =09=09=09=09=09 &entries[idx++], =09=09=09=09=09 &pmbus_debugfs_ops); =09=09} + +=09=09if (pmbus_check_byte_register(client, i, PMBUS_MFR_ID)) { +=09=09=09entries[idx].client =3D client; +=09=09=09entries[idx].page =3D i; +=09=09=09entries[idx].reg =3D PMBUS_MFR_ID; +=09=09=09scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_id", i); +=09=09=09debugfs_create_file(name, 0444, data->debugfs, +=09=09=09=09=09 &entries[idx++], +=09=09=09=09=09 &pmbus_debugfs_ops_mfr); +=09=09} + +=09=09if (pmbus_check_byte_register(client, i, PMBUS_MFR_MODEL)) { +=09=09=09entries[idx].client =3D client; +=09=09=09entries[idx].page =3D i; +=09=09=09entries[idx].reg =3D PMBUS_MFR_MODEL; +=09=09=09scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_model", i); +=09=09=09debugfs_create_file(name, 0444, data->debugfs, +=09=09=09=09=09 &entries[idx++], +=09=09=09=09=09 &pmbus_debugfs_ops_mfr); +=09=09} + +=09=09if (pmbus_check_byte_register(client, i, PMBUS_MFR_REVISION)) { +=09=09=09entries[idx].client =3D client; +=09=09=09entries[idx].page =3D i; +=09=09=09entries[idx].reg =3D PMBUS_MFR_REVISION; +=09=09=09scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_revision", i); +=09=09=09debugfs_create_file(name, 0444, data->debugfs, +=09=09=09=09=09 &entries[idx++], +=09=09=09=09=09 &pmbus_debugfs_ops_mfr); +=09=09} + +=09=09if (pmbus_check_byte_register(client, i, PMBUS_MFR_LOCATION)) { +=09=09=09entries[idx].client =3D client; +=09=09=09entries[idx].page =3D i; +=09=09=09entries[idx].reg =3D PMBUS_MFR_LOCATION; +=09=09=09scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_location", i); +=09=09=09debugfs_create_file(name, 0444, data->debugfs, +=09=09=09=09=09 &entries[idx++], +=09=09=09=09=09 &pmbus_debugfs_ops_mfr); +=09=09} + +=09=09if (pmbus_check_byte_register(client, i, PMBUS_MFR_DATE)) { +=09=09=09entries[idx].client =3D client; +=09=09=09entries[idx].page =3D i; +=09=09=09entries[idx].reg =3D PMBUS_MFR_DATE; +=09=09=09scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_date", i); +=09=09=09debugfs_create_file(name, 0444, data->debugfs, +=09=09=09=09=09 &entries[idx++], +=09=09=09=09=09 &pmbus_debugfs_ops_mfr); +=09=09} + +=09=09if (pmbus_check_byte_register(client, i, PMBUS_MFR_SERIAL)) { +=09=09=09entries[idx].client =3D client; +=09=09=09entries[idx].page =3D i; +=09=09=09entries[idx].reg =3D PMBUS_MFR_SERIAL; +=09=09=09scnprintf(name, PMBUS_NAME_SIZE, "mfr%d_serial", i); +=09=09=09debugfs_create_file(name, 0444, data->debugfs, +=09=09=09=09=09 &entries[idx++], +=09=09=09=09=09 &pmbus_debugfs_ops_mfr); +=09=09} =09} =09return devm_add_action_or_reset(data->dev, -- 2.25.1