From patchwork Wed Jun 24 15:17:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Tachici X-Patchwork-Id: 198528 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16F82C433E0 for ; Wed, 24 Jun 2020 15:16:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0322F20781 for ; Wed, 24 Jun 2020 15:16:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404519AbgFXPQI (ORCPT ); Wed, 24 Jun 2020 11:16:08 -0400 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:60756 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404052AbgFXPQC (ORCPT ); Wed, 24 Jun 2020 11:16:02 -0400 Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05OEvg1N023449; Wed, 24 Jun 2020 11:15:46 -0400 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com with ESMTP id 31uuqvjesd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 24 Jun 2020 11:15:45 -0400 Received: from ASHBMBX8.ad.analog.com (ashbmbx8.ad.analog.com [10.64.17.5]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 05OFFiGA044770 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Wed, 24 Jun 2020 11:15:44 -0400 Received: from ASHBMBX9.ad.analog.com (10.64.17.10) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Wed, 24 Jun 2020 11:15:43 -0400 Received: from zeus.spd.analog.com (10.64.82.11) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server id 15.1.1779.2 via Frontend Transport; Wed, 24 Jun 2020 11:15:43 -0400 Received: from localhost.localdomain ([10.48.65.12]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 05OFFdRq023607; Wed, 24 Jun 2020 11:15:41 -0400 From: To: , , CC: , , Alexandru Tachici Subject: [PATCH v5 1/7] hwmon: pmbus: adm1266: add support Date: Wed, 24 Jun 2020 18:17:30 +0300 Message-ID: <20200624151736.95785-2-alexandru.tachici@analog.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200624151736.95785-1-alexandru.tachici@analog.com> References: <20200624151736.95785-1-alexandru.tachici@analog.com> MIME-Version: 1.0 X-ADIRoutedOnPrem: True X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-06-24_08:2020-06-24,2020-06-24 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxlogscore=999 spamscore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 cotscore=-2147483648 priorityscore=1501 mlxscore=0 bulkscore=0 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006240107 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Alexandru Tachici Add pmbus probing driver for the adm1266 Cascadable Super Sequencer with Margin Control and Fault Recording. Driver is using the pmbus_core, creating sysfs files under hwmon for inputs: vh1->vh4 and vp1->vp13. Signed-off-by: Alexandru Tachici --- Documentation/hwmon/adm1266.rst | 35 +++++++++++++++++++ drivers/hwmon/pmbus/Kconfig | 9 +++++ drivers/hwmon/pmbus/Makefile | 1 + drivers/hwmon/pmbus/adm1266.c | 62 +++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 Documentation/hwmon/adm1266.rst create mode 100644 drivers/hwmon/pmbus/adm1266.c diff --git a/Documentation/hwmon/adm1266.rst b/Documentation/hwmon/adm1266.rst new file mode 100644 index 000000000000..65662115750c --- /dev/null +++ b/Documentation/hwmon/adm1266.rst @@ -0,0 +1,35 @@ +Kernel driver adm1266 +===================== + +Supported chips: + * Analog Devices ADM1266 + Prefix: 'adm1266' + Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ADM1266.pdf + +Author: Alexandru Tachici + + +Description +----------- + +This driver supports hardware monitoring for Analog Devices ADM1266 sequencer. + +ADM1266 is a sequencer that features voltage readback from 17 channels via an +integrated 12 bit SAR ADC, accessed using a PMBus interface. + +The driver is a client driver to the core PMBus driver. Please see +Documentation/hwmon/pmbus for details on PMBus client drivers. + + +Sysfs entries +------------- + +The following attributes are supported. Limits are read-write, history reset +attributes are write-only, all other attributes are read-only. + +inX_label "voutx" +inX_input Measured voltage. +inX_min Minimum Voltage. +inX_max Maximum voltage. +inX_min_alarm Voltage low alarm. +inX_max_alarm Voltage high alarm. diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig index a337195b1c39..da34083e1ffd 100644 --- a/drivers/hwmon/pmbus/Kconfig +++ b/drivers/hwmon/pmbus/Kconfig @@ -26,6 +26,15 @@ config SENSORS_PMBUS This driver can also be built as a module. If so, the module will be called pmbus. +config SENSORS_ADM1266 + tristate "Analog Devices ADM1266 Sequencer" + help + If you say yes here you get hardware monitoring support for Analog + Devices ADM1266 Cascadable Super Sequencer. + + This driver can also be built as a module. If so, the module will + be called adm1266. + config SENSORS_ADM1275 tristate "Analog Devices ADM1275 and compatibles" help diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile index c4b15db996ad..da41d22be1c9 100644 --- a/drivers/hwmon/pmbus/Makefile +++ b/drivers/hwmon/pmbus/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_PMBUS) += pmbus_core.o obj-$(CONFIG_SENSORS_PMBUS) += pmbus.o +obj-$(CONFIG_SENSORS_ADM1266) += adm1266.o obj-$(CONFIG_SENSORS_ADM1275) += adm1275.o obj-$(CONFIG_SENSORS_BEL_PFE) += bel-pfe.o obj-$(CONFIG_SENSORS_IBM_CFFPS) += ibm-cffps.o diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c new file mode 100644 index 000000000000..a7ef048a9a5c --- /dev/null +++ b/drivers/hwmon/pmbus/adm1266.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * ADM1266 - Cascadable Super Sequencer with Margin + * Control and Fault Recording + * + * Copyright 2020 Analog Devices Inc. + */ + +#include +#include +#include +#include +#include + +#include "pmbus.h" + +static int adm1266_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct pmbus_driver_info *info; + u32 funcs; + int i; + + info = devm_kzalloc(&client->dev, sizeof(struct pmbus_driver_info), + GFP_KERNEL); + + info->pages = 17; + info->format[PSC_VOLTAGE_OUT] = linear; + funcs = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; + for (i = 0; i < info->pages; i++) + info->func[i] = funcs; + + return pmbus_do_probe(client, id, info); +} + +static const struct of_device_id adm1266_of_match[] = { + { .compatible = "adi,adm1266" }, + { } +}; +MODULE_DEVICE_TABLE(of, adm1266_of_match); + +static const struct i2c_device_id adm1266_id[] = { + { "adm1266", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, adm1266_id); + +static struct i2c_driver adm1266_driver = { + .driver = { + .name = "adm1266", + .of_match_table = adm1266_of_match, + }, + .probe = adm1266_probe, + .remove = pmbus_do_remove, + .id_table = adm1266_id, +}; + +module_i2c_driver(adm1266_driver); + +MODULE_AUTHOR("Alexandru Tachici "); +MODULE_DESCRIPTION("PMBus driver for Analog Devices ADM1266"); +MODULE_LICENSE("GPL v2"); From patchwork Wed Jun 24 15:17:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Tachici X-Patchwork-Id: 198526 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5EAC9C433DF for ; Wed, 24 Jun 2020 15:16:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4580C2076E for ; Wed, 24 Jun 2020 15:16:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404555AbgFXPQc (ORCPT ); Wed, 24 Jun 2020 11:16:32 -0400 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:5408 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404511AbgFXPQH (ORCPT ); Wed, 24 Jun 2020 11:16:07 -0400 Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05OEvnKD023504; Wed, 24 Jun 2020 11:15:49 -0400 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com with ESMTP id 31uuqvjesq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 24 Jun 2020 11:15:49 -0400 Received: from SCSQMBX10.ad.analog.com (scsqmbx10.ad.analog.com [10.77.17.5]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 05OFFlr0044789 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Wed, 24 Jun 2020 11:15:48 -0400 Received: from SCSQMBX10.ad.analog.com (10.77.17.5) by SCSQMBX10.ad.analog.com (10.77.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Wed, 24 Jun 2020 08:15:46 -0700 Received: from zeus.spd.analog.com (10.64.82.11) by SCSQMBX10.ad.analog.com (10.77.17.5) with Microsoft SMTP Server id 15.1.1779.2 via Frontend Transport; Wed, 24 Jun 2020 08:15:46 -0700 Received: from localhost.localdomain ([10.48.65.12]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 05OFFdRt023607; Wed, 24 Jun 2020 11:15:44 -0400 From: To: , , CC: , , Alexandru Tachici Subject: [PATCH v5 4/7] hwmon: pmbus: adm1266: Add ioctl commands Date: Wed, 24 Jun 2020 18:17:33 +0300 Message-ID: <20200624151736.95785-5-alexandru.tachici@analog.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200624151736.95785-1-alexandru.tachici@analog.com> References: <20200624151736.95785-1-alexandru.tachici@analog.com> MIME-Version: 1.0 X-ADIRoutedOnPrem: True X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-06-24_08:2020-06-24,2020-06-24 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxlogscore=999 spamscore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 cotscore=-2147483648 priorityscore=1501 mlxscore=0 bulkscore=0 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006240107 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Alexandru Tachici Add two ioctl commands for reading the current state of the adm1266 sequencer and sending commands. Signed-off-by: Alexandru Tachici --- Documentation/hwmon/adm1266.rst | 15 +++ .../userspace-api/ioctl/ioctl-number.rst | 1 + drivers/hwmon/pmbus/adm1266.c | 97 +++++++++++++++++++ include/uapi/linux/adm1266.h | 16 +++ 4 files changed, 129 insertions(+) create mode 100644 include/uapi/linux/adm1266.h diff --git a/Documentation/hwmon/adm1266.rst b/Documentation/hwmon/adm1266.rst index 65662115750c..5dc05808db60 100644 --- a/Documentation/hwmon/adm1266.rst +++ b/Documentation/hwmon/adm1266.rst @@ -33,3 +33,18 @@ inX_min Minimum Voltage. inX_max Maximum voltage. inX_min_alarm Voltage low alarm. inX_max_alarm Voltage high alarm. + + +User API +======== + +ioctls +------ + +ADM1266_SET_GO_COMMAND: + + Issue a GO_COMMAND to the device. + +ADM1266_GET_STATUS: + + Returns state of the sequencer. diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst index 59472cd6a11d..df92ca274622 100644 --- a/Documentation/userspace-api/ioctl/ioctl-number.rst +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst @@ -348,6 +348,7 @@ Code Seq# Include File Comments 0xCC 00-0F drivers/misc/ibmvmc.h pseries VMC driver 0xCD 01 linux/reiserfs_fs.h 0xCF 02 fs/cifs/ioctl.c +0xD1 00-0F linux/adm1266.h 0xDB 00-0F drivers/char/mwave/mwavepub.h 0xDD 00-3F ZFCP device driver see drivers/s390/scsi/ diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c index 76bf2c78e737..0960ead8d96a 100644 --- a/drivers/hwmon/pmbus/adm1266.c +++ b/drivers/hwmon/pmbus/adm1266.c @@ -15,11 +15,16 @@ #include #include #include +#include #include +#include +#include #include "pmbus.h" #define ADM1266_PDIO_CONFIG 0xD4 +#define ADM1266_GO_COMMAND 0xD8 +#define ADM1266_READ_STATE 0xD9 #define ADM1266_GPIO_CONFIG 0xE1 #define ADM1266_PDIO_STATUS 0xE9 #define ADM1266_GPIO_STATUS 0xEA @@ -46,6 +51,7 @@ struct adm1266_data { struct gpio_chip gc; const char *gpio_names[ADM1266_GPIO_NR + ADM1266_PDIO_NR]; struct i2c_client *client; + struct mutex ioctl_mutex; /* lock ioctl access */ }; /* Different from Block Read as it sends data and waits for the slave to @@ -311,6 +317,93 @@ static int adm1266_config_gpio(struct adm1266_data *data) } #endif +static int adm1266_set_go_command_op(struct adm1266_data *data, u8 val) +{ + val = FIELD_GET(GENMASK(4, 0), val); + + return i2c_smbus_write_word_data(data->client, ADM1266_GO_COMMAND, val); +} + +static int adm1266_ioctl_unlocked(struct file *fp, unsigned int cmd, + unsigned long arg) +{ + int __user *argp = (int __user *)arg; + struct adm1266_data *data; + int val; + int ret; + + data = fp->private_data; + + if (!argp) + return -EINVAL; + + switch (cmd) { + case ADM1266_SET_GO_COMMAND: + if (copy_from_user(&val, argp, sizeof(int))) + return -EFAULT; + + return adm1266_set_go_command_op(data, val); + case ADM1266_GET_STATUS: + ret = i2c_smbus_read_word_data(data->client, + ADM1266_READ_STATE); + + if (ret < 0) + return ret; + + if (copy_to_user(argp, &ret, sizeof(int))) + return -EFAULT; + + break; + default: + return -ENOTTY; + } + + return 0; +} + +static long adm1266_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) +{ + struct adm1266_data *data; + long ret; + + data = fp->private_data; + + mutex_lock(&data->ioctl_mutex); + ret = adm1266_ioctl_unlocked(fp, cmd, arg); + mutex_unlock(&data->ioctl_mutex); + + return ret; +} + +static int adm1266_open(struct inode *inode, struct file *filp) +{ + filp->private_data = PDE_DATA(inode); + + return 0; +} + +static const struct proc_ops adm1266_proc_ops = { + .proc_open = adm1266_open, + .proc_ioctl = adm1266_ioctl, +}; + +static int adm1266_init_procfs(struct adm1266_data *data) +{ + struct proc_dir_entry *proc_dir; + u8 proc_fs_name[32]; + + mutex_init(&data->ioctl_mutex); + + snprintf(proc_fs_name, 32, "adm1266-%x", data->client->addr); + proc_dir = proc_create_data(proc_fs_name, 0, NULL, &adm1266_proc_ops, + data); + + if (!proc_dir) + return -EINVAL; + + return 0; +} + static int adm1266_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -333,6 +426,10 @@ static int adm1266_probe(struct i2c_client *client, crc8_populate_msb(pmbus_crc_table, 0x7); + ret = adm1266_init_procfs(data); + if (ret < 0) + return ret; + info = &data->info; info->pages = 17; info->format[PSC_VOLTAGE_OUT] = linear; diff --git a/include/uapi/linux/adm1266.h b/include/uapi/linux/adm1266.h new file mode 100644 index 000000000000..535d270ee8c5 --- /dev/null +++ b/include/uapi/linux/adm1266.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * ADM1266 - Cascadable Super Sequencer with Margin + * Control and Fault Recording + * + * Copyright 2020 Analog Devices Inc. + */ + +#ifndef _LINUX_ADM1266_H +#define _LINUX_ADM1266_H + +/* ADM1266 ioctl commands */ +#define ADM1266_SET_GO_COMMAND _IOW(0xD1, 0x00, int) +#define ADM1266_GET_STATUS _IOR(0xD1, 0x01, int) + +#endif From patchwork Wed Jun 24 15:17:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Tachici X-Patchwork-Id: 198529 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4EE3C433DF for ; Wed, 24 Jun 2020 15:16:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 87A4D20781 for ; Wed, 24 Jun 2020 15:16:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404499AbgFXPP6 (ORCPT ); Wed, 24 Jun 2020 11:15:58 -0400 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:51082 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404144AbgFXPP5 (ORCPT ); Wed, 24 Jun 2020 11:15:57 -0400 Received: from pps.filterd (m0167088.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05OEtUxk019718; Wed, 24 Jun 2020 11:15:56 -0400 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com with ESMTP id 31uurjjgc1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 24 Jun 2020 11:15:56 -0400 Received: from ASHBMBX9.ad.analog.com (ashbmbx9.ad.analog.com [10.64.17.10]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 05OFFtIR044839 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Wed, 24 Jun 2020 11:15:55 -0400 Received: from ASHBCASHYB5.ad.analog.com (10.64.17.133) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Wed, 24 Jun 2020 11:15:54 -0400 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBCASHYB5.ad.analog.com (10.64.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Wed, 24 Jun 2020 11:15:53 -0400 Received: from zeus.spd.analog.com (10.64.82.11) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.1.1779.2 via Frontend Transport; Wed, 24 Jun 2020 11:15:47 -0400 Received: from localhost.localdomain ([10.48.65.12]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 05OFFdRu023607; Wed, 24 Jun 2020 11:15:46 -0400 From: To: , , CC: , , Alexandru Tachici Subject: [PATCH v5 5/7] hwmon: pmbus: adm1266: read blackbox Date: Wed, 24 Jun 2020 18:17:34 +0300 Message-ID: <20200624151736.95785-6-alexandru.tachici@analog.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200624151736.95785-1-alexandru.tachici@analog.com> References: <20200624151736.95785-1-alexandru.tachici@analog.com> MIME-Version: 1.0 X-ADIRoutedOnPrem: True X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-06-24_08:2020-06-24,2020-06-24 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 suspectscore=0 adultscore=0 mlxscore=0 spamscore=0 priorityscore=1501 cotscore=-2147483648 bulkscore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006240107 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Alexandru Tachici Use the nvmem kernel api to expose the black box chip functionality to userspace. Signed-off-by: Alexandru Tachici --- drivers/hwmon/pmbus/adm1266.c | 134 ++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c index 0960ead8d96a..b9e92ab1e39a 100644 --- a/drivers/hwmon/pmbus/adm1266.c +++ b/drivers/hwmon/pmbus/adm1266.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include #include @@ -22,10 +24,13 @@ #include #include "pmbus.h" +#define ADM1266_BLACKBOX_CONFIG 0xD3 #define ADM1266_PDIO_CONFIG 0xD4 #define ADM1266_GO_COMMAND 0xD8 #define ADM1266_READ_STATE 0xD9 +#define ADM1266_READ_BLACKBOX 0xDE #define ADM1266_GPIO_CONFIG 0xE1 +#define ADM1266_BLACKBOX_INFO 0xE6 #define ADM1266_PDIO_STATUS 0xE9 #define ADM1266_GPIO_STATUS 0xEA @@ -42,6 +47,9 @@ #define ADM1266_PDIO_GLITCH_FILT(x) FIELD_GET(GENMASK(12, 9), x) #define ADM1266_PDIO_OUT_CFG(x) FIELD_GET(GENMASK(2, 0), x) +#define ADM1266_BLACKBOX_OFFSET 0x7F700 +#define ADM1266_BLACKBOX_SIZE 64 + #define ADM1266_PMBUS_BLOCK_MAX 255 DECLARE_CRC8_TABLE(pmbus_crc_table); @@ -52,6 +60,17 @@ struct adm1266_data { const char *gpio_names[ADM1266_GPIO_NR + ADM1266_PDIO_NR]; struct i2c_client *client; struct mutex ioctl_mutex; /* lock ioctl access */ + struct nvmem_config nvmem_config; + struct nvmem_device *nvmem; + u8 *dev_mem; +}; + +static const struct nvmem_cell_info adm1266_nvmem_cells[] = { + { + .name = "blackbox", + .offset = ADM1266_BLACKBOX_OFFSET, + .bytes = 2048, + }, }; /* Different from Block Read as it sends data and waits for the slave to @@ -404,6 +423,117 @@ static int adm1266_init_procfs(struct adm1266_data *data) return 0; } +static int adm1266_nvmem_read_blackbox(struct adm1266_data *data, u8 *buf) +{ + u8 read_buf[5]; + char index; + int record_count; + int ret; + + ret = i2c_smbus_read_block_data(data->client, ADM1266_BLACKBOX_INFO, + read_buf); + if (ret < 0) + return ret; + + record_count = read_buf[3]; + + for (index = 0; index < record_count; index++) { + ret = pmbus_block_xfer(data->client, ADM1266_READ_BLACKBOX, 1, + &index, buf); + if (ret < 0) + return ret; + + buf += ADM1266_BLACKBOX_SIZE; + } + + return 0; +} + +static bool adm1266_cell_is_accessed(const struct nvmem_cell_info *mem_cell, + unsigned int offset, size_t bytes) +{ + unsigned int start_addr = offset; + unsigned int end_addr = offset + bytes; + unsigned int cell_start = mem_cell->offset; + unsigned int cell_end = mem_cell->offset + mem_cell->bytes; + + if (start_addr <= cell_end && cell_start <= end_addr) + return true; + + return false; +} + +static int adm1266_read_mem_cell(struct adm1266_data *data, + const struct nvmem_cell_info *mem_cell) +{ + u8 *mem_offset; + int ret; + + switch (mem_cell->offset) { + case ADM1266_BLACKBOX_OFFSET: + mem_offset = data->dev_mem + mem_cell->offset; + ret = adm1266_nvmem_read_blackbox(data, mem_offset); + if (ret) + dev_err(&data->client->dev, "Could not read blackbox!"); + return ret; + default: + return -EINVAL; + } +} + +static int adm1266_nvmem_read(void *priv, unsigned int offset, void *val, + size_t bytes) +{ + const struct nvmem_cell_info *mem_cell; + struct adm1266_data *data = priv; + int ret; + int i; + + for (i = 0; i < data->nvmem_config.ncells; i++) { + mem_cell = &adm1266_nvmem_cells[i]; + if (!adm1266_cell_is_accessed(mem_cell, offset, bytes)) + continue; + + ret = adm1266_read_mem_cell(data, mem_cell); + if (ret < 0) + return ret; + } + + memcpy(val, data->dev_mem + offset, bytes); + + return 0; +} + +static int adm1266_config_nvmem(struct adm1266_data *data) +{ + data->nvmem_config.name = dev_name(&data->client->dev); + data->nvmem_config.dev = &data->client->dev; + data->nvmem_config.root_only = true; + data->nvmem_config.read_only = true; + data->nvmem_config.owner = THIS_MODULE; + data->nvmem_config.reg_read = adm1266_nvmem_read; + data->nvmem_config.cells = adm1266_nvmem_cells; + data->nvmem_config.ncells = ARRAY_SIZE(adm1266_nvmem_cells); + data->nvmem_config.priv = data; + data->nvmem_config.stride = 1; + data->nvmem_config.word_size = 1; + data->nvmem_config.size = 0x80000; + + data->nvmem = nvmem_register(&data->nvmem_config); + if (IS_ERR(data->nvmem)) { + dev_err(&data->client->dev, "Could not register nvmem!"); + return PTR_ERR(data->nvmem); + } + + data->dev_mem = devm_kzalloc(&data->client->dev, + data->nvmem_config.size, + GFP_KERNEL); + if (!data->dev_mem) + return -ENOMEM; + + return 0; +} + static int adm1266_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -430,6 +560,10 @@ static int adm1266_probe(struct i2c_client *client, if (ret < 0) return ret; + ret = adm1266_config_nvmem(data); + if (ret < 0) + return ret; + info = &data->info; info->pages = 17; info->format[PSC_VOLTAGE_OUT] = linear; From patchwork Wed Jun 24 15:17:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Tachici X-Patchwork-Id: 198527 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A486AC433E2 for ; Wed, 24 Jun 2020 15:16:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D1332078A for ; Wed, 24 Jun 2020 15:16:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404099AbgFXPQZ (ORCPT ); Wed, 24 Jun 2020 11:16:25 -0400 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:7318 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404523AbgFXPQI (ORCPT ); Wed, 24 Jun 2020 11:16:08 -0400 Received: from pps.filterd (m0167088.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05OEtLat019662; Wed, 24 Jun 2020 11:15:52 -0400 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com with ESMTP id 31uurjjgbq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 24 Jun 2020 11:15:52 -0400 Received: from SCSQMBX10.ad.analog.com (scsqmbx10.ad.analog.com [10.77.17.5]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 05OFFoSU044808 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Wed, 24 Jun 2020 11:15:51 -0400 Received: from SCSQCASHYB7.ad.analog.com (10.77.17.133) by SCSQMBX10.ad.analog.com (10.77.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Wed, 24 Jun 2020 08:15:49 -0700 Received: from SCSQMBX11.ad.analog.com (10.77.17.10) by SCSQCASHYB7.ad.analog.com (10.77.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Wed, 24 Jun 2020 08:15:49 -0700 Received: from zeus.spd.analog.com (10.64.82.11) by SCSQMBX11.ad.analog.com (10.77.17.10) with Microsoft SMTP Server id 15.1.1779.2 via Frontend Transport; Wed, 24 Jun 2020 08:15:49 -0700 Received: from localhost.localdomain ([10.48.65.12]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 05OFFdRv023607; Wed, 24 Jun 2020 11:15:47 -0400 From: To: , , CC: , , Alexandru Tachici Subject: [PATCH v5 6/7] hwmon: pmbus: adm1266: debugfs for blackbox info Date: Wed, 24 Jun 2020 18:17:35 +0300 Message-ID: <20200624151736.95785-7-alexandru.tachici@analog.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200624151736.95785-1-alexandru.tachici@analog.com> References: <20200624151736.95785-1-alexandru.tachici@analog.com> MIME-Version: 1.0 X-ADIRoutedOnPrem: True X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-06-24_08:2020-06-24,2020-06-24 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 suspectscore=0 adultscore=0 mlxscore=0 spamscore=0 priorityscore=1501 cotscore=-2147483648 bulkscore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006240107 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Alexandru Tachici Add a debugfs file to print information in the BLACKBOX_INFORMATION register. Contains information about the number of stored records, logic index and id of the latest record. Signed-off-by: Alexandru Tachici --- drivers/hwmon/pmbus/adm1266.c | 56 ++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c index b9e92ab1e39a..ea2dc481094b 100644 --- a/drivers/hwmon/pmbus/adm1266.c +++ b/drivers/hwmon/pmbus/adm1266.c @@ -60,6 +60,7 @@ struct adm1266_data { const char *gpio_names[ADM1266_GPIO_NR + ADM1266_PDIO_NR]; struct i2c_client *client; struct mutex ioctl_mutex; /* lock ioctl access */ + struct dentry *debugfs_dir; struct nvmem_config nvmem_config; struct nvmem_device *nvmem; u8 *dev_mem; @@ -406,6 +407,28 @@ static const struct proc_ops adm1266_proc_ops = { .proc_ioctl = adm1266_ioctl, }; +static int adm1266_blackbox_information_read(struct seq_file *s, void *pdata) +{ + struct device *dev = s->private; + struct i2c_client *client = to_i2c_client(dev); + u8 read_buf[5]; + unsigned int latest_id; + int ret; + + ret = i2c_smbus_read_block_data(client, ADM1266_BLACKBOX_INFO, + read_buf); + if (ret < 0) + return ret; + + seq_puts(s, "BLACKBOX_INFORMATION:\n"); + latest_id = read_buf[0] + (read_buf[1] << 8); + seq_printf(s, "Black box ID: %u\n", latest_id); + seq_printf(s, "Logic index: %u\n", read_buf[2]); + seq_printf(s, "Record count: %u\n", read_buf[3]); + + return 0; +} + static int adm1266_init_procfs(struct adm1266_data *data) { struct proc_dir_entry *proc_dir; @@ -423,6 +446,29 @@ static int adm1266_init_procfs(struct adm1266_data *data) return 0; } +static int adm1266_init_debugfs(struct adm1266_data *data) +{ + struct dentry *entry; + struct dentry *root; + + root = pmbus_get_debugfs_dir(data->client); + if (!root) + return -ENOENT; + + data->debugfs_dir = debugfs_create_dir(data->client->name, root); + if (!data->debugfs_dir) + return -ENOENT; + + entry = debugfs_create_devm_seqfile(&data->client->dev, + "blackbox_information", + data->debugfs_dir, + adm1266_blackbox_information_read); + if (!entry) + return -ENOENT; + + return 0; +} + static int adm1266_nvmem_read_blackbox(struct adm1266_data *data, u8 *buf) { u8 read_buf[5]; @@ -571,7 +617,15 @@ static int adm1266_probe(struct i2c_client *client, for (i = 0; i < info->pages; i++) info->func[i] = funcs; - return pmbus_do_probe(client, id, info); + ret = pmbus_do_probe(client, id, info); + if (ret) + return ret; + + ret = adm1266_init_debugfs(data); + if (ret) + dev_warn(&client->dev, "Failed to register debugfs: %d\n", ret); + + return 0; } static const struct of_device_id adm1266_of_match[] = {