Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp937124lqa; Sun, 28 Apr 2024 10:27:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUlibbRnr4ipJAMR0NL9Z3sZvs3t0/CwmcNftLw98fZScfdCQtP6A8eqZhSo4CpdltxgmNoEBTFyjou6jXpUlneYnX7HbyRQmOQAxSxEQ== X-Google-Smtp-Source: AGHT+IHGr/u6tip5VtvsWVeGQPOMFSTUMqmpw9A2sgMSwPW55q8YTUSHEGLjlea0w8X9ji3o7A+I X-Received: by 2002:a17:903:2282:b0:1eb:2f02:cd0d with SMTP id b2-20020a170903228200b001eb2f02cd0dmr8859554plh.0.1714325277575; Sun, 28 Apr 2024 10:27:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714325277; cv=pass; d=google.com; s=arc-20160816; b=HCEaeOGBpd7kQXqoL8KvynFioPEtYy7zbqYAMb/MYgrHStKfdjpAyoBLyNoxJK0t1Y zEKEgy8a8iE7+SYFtvjbWfXjdG1p9er4A/D3+yrR8ciMwQYdxX0ubzbpFHW8K5xgM8RS UwqHXSMcxjLZd78GMU/NLHnSPtAs1tDmj/cGX3hI06ty5zmaxdTOANGSx/sbQYlFwO2u QDvODUf34+2X0BOFFTNv8f2aXPSNM0Gi4Rs6HTLFbm0880otGXEYZJ8JfSwYMKBkdM/4 Y96m5VwRgWLUC7UJGREiqoVARibhst3gCyIB6OGM4OTl1fTiNF3Tlkr3ndmzzqSf4xjW QB1Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:sender:dkim-signature; bh=C2knqG68Gw3E1+Yz7J083d0kVRWJTtEFT+L1mHqaNus=; fh=Uju6ig8uPv6v3jfGj0dbdnU7JgFj9l00tjm/8irVfgc=; b=nhHCJgLO/mA5i3LCT2Y9R8UlS66hAdwkXxnvKEt8aVwRsTTkR/XE62qsotQ82+QDEB 2K6lWlqU+ZQ1mnmn3y3IJ4OJJWYU2j+n0xIRR9k9L5Gc8QXeHnC/xDsEcHrziwqAumad 4Bg3oS2iV3irVWSN8FfwOvT9fO8Ae51nqhPykDeMnEIsqryecFz5vBvlq21sDClQmzPr JXKjt5PgeBU2JzDfmlN/AeanyK64BYh9EIQzMpCqj/vHhmA0TD/bwdQhCujvCN79Q3q+ 7aXQ6JxxB27KQtqwxHMhe3rMpT0gcuz4mJqyUh5t59hZcXTHdz7ArzoHUPm/K9k4jjQ0 dong==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=D7QAeBkA; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-161527-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161527-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id h15-20020a170902680f00b001e3d54989adsi18022310plk.62.2024.04.28.10.27.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Apr 2024 10:27:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-161527-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=D7QAeBkA; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-161527-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161527-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 00C82B21365 for ; Sun, 28 Apr 2024 17:27:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 083F47351A; Sun, 28 Apr 2024 17:27:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="D7QAeBkA" Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E7721EB45; Sun, 28 Apr 2024 17:27:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714325233; cv=none; b=UdtKBMcwOgEM6fM9Y0V9f4t/t+WsB5TE5ioOARlUeRq4ULomchyNgFujPH7Tbk9kUBcw4kWEveoGiBO4JN9tJRHS0g0aAc/rHWmGz4Qn+OcHPPnB2kHZhUU6AJsp9slcAt0i28CKQ1Guzp89z8Pee8K/u17FhlnWiU3wLAZG7e8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714325233; c=relaxed/simple; bh=M3F90mdVr3tGo2no1WTzvSAVRjgKAuQEvaGgDaruVKg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BzKANr2+FMsF1+9tjB9HfikxUbRI19ode0g4WtNQHJPTBaUXwuHBHCZXReFBRTwZBn+inDg7Dx2pOvSkoff2xmzuxhbMZnmNZ+DSYGyVyT/ImchyhRGPRVvtGcgAlo3V6POaYrrJlpebeyirud4FrxCsrLwN4fGib4qm0xYWs0w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=D7QAeBkA; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-5d4d15ec7c5so2979254a12.1; Sun, 28 Apr 2024 10:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714325231; x=1714930031; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=C2knqG68Gw3E1+Yz7J083d0kVRWJTtEFT+L1mHqaNus=; b=D7QAeBkAWiYwQ9l5IS73gAcMX2iPLl/MhOcLxGpNw0197X5mNCf+O6n54cHRy/Mxjw Tt1/AseLWc0W9IbS86Lw4VkxiGYLZR3ZQNGOcNb8iQOLnJB5Gtlz5WDAMRhRQOyys4mO YKNEws7hJu5L3pfZa5wpwo4T1mujAb9esiPCtR7fPJalgGALo2DeBGEPmrmPQgW+nTf8 gXjO3M6mR2steCWKhmB0nm2cime81EqPoBpEybwOaOverJg0/YLn18gDYBg+SZCAS2Az vTkBYOja68LfKf4AIHBER+SCZXVwrsWRBESrflQfNUzPDKgiLEMq5humR1WcsKhnZhs7 DImg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714325231; x=1714930031; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C2knqG68Gw3E1+Yz7J083d0kVRWJTtEFT+L1mHqaNus=; b=RVLPPgUWtFP2ceMms2Aij1ZvZywN7V4cLIeg42QiHvsC3Gp0YWKIkTnfjVH5waTurT PSTVeGG34rkUDBL7f7pV6gQhuVZog+sn01IDL1W1lZjtdsJnys6BbWq5x/6ynB/PLRF8 wL15/srvEVTsAyQzo/tlj4T9WnngDb8nHyGd8Uoh/fKBOuye+EIM9EmpwD3XQxasikTT drvCRs/045pVNiGhROvRxt/oEwL5IlA4FDKryOz1FtBcibeMw4p0jAlQSfUdg28TTTk7 I7MacOTF31UJniKa2HRSo9NZMY4wLbF+jcQyFpCNY/XE41oTV3Yf/wy8HopkWofbjmu6 d6Lg== X-Forwarded-Encrypted: i=1; AJvYcCVi0Calbwdy/UHSw8q9PV+rQdCwFGakzoTBmLK6li3tmFc68+kQJROimy1hXyFsPKUhBNSVOM1GLXLSpnUaAjskbqiOb/8PanjEOwB4am1F1U3KaCXKuZw22f9YQ3f+c31zfm5a2IrdHaSVe3Ecc/DlcZgYa0LuW5mxoW9y/+X/CNtsCLuRMZlvdTzcxo3o1zVWqBDCvYhgRfEiZFpOYXJtEZx6AqGHW7iY+v/4d3wL9rb7+YgAHIi97zLN X-Gm-Message-State: AOJu0YzqiPTj/f/ymhhVlho+TfZ6L90keODWK/jAOaj0wHoSUtjkUe12 7cJm2tnFGoeknK46R5O1mECkiNckefIZFqImgRngOcZNo+JsHD9d X-Received: by 2002:a05:6a20:dc95:b0:1a9:86dd:177b with SMTP id ky21-20020a056a20dc9500b001a986dd177bmr9404831pzb.44.1714325231432; Sun, 28 Apr 2024 10:27:11 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id r30-20020a638f5e000000b005f7f51967e9sm16073440pgn.27.2024.04.28.10.27.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Apr 2024 10:27:10 -0700 (PDT) Sender: Guenter Roeck Date: Sun, 28 Apr 2024 10:27:09 -0700 From: Guenter Roeck To: Peter Yin Cc: patrick@stwcx.xyz, Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jean Delvare , Jonathan Corbet , Delphine CC Chiu , Patrick Rudolph , Bjorn Helgaas , Ninad Palsule , Fabio Estevam , Lukas Wunner , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, linux-i2c@vger.kernel.org Subject: Re: [PATCH v2 1/2] hwmon: (pmbus) Add support for Infineon XDP710 Message-ID: References: <20240425153608.4003782-1-peteryin.openbmc@gmail.com> <20240425153608.4003782-2-peteryin.openbmc@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240425153608.4003782-2-peteryin.openbmc@gmail.com> On Thu, Apr 25, 2024 at 11:36:01PM +0800, Peter Yin wrote: > Add support for Infineon XDP710.This is a Hot-Swap Controller. > > Signed-off-by: Peter Yin Applied, after "s/microOhmRsense/micro_ohm_rsense/g" Guenter > --- > Documentation/hwmon/index.rst | 1 + > Documentation/hwmon/xdp710.rst | 83 +++++++++++++++++++++ > drivers/hwmon/pmbus/Kconfig | 9 +++ > drivers/hwmon/pmbus/Makefile | 1 + > drivers/hwmon/pmbus/xdp710.c | 132 +++++++++++++++++++++++++++++++++ > 5 files changed, 226 insertions(+) > create mode 100644 Documentation/hwmon/xdp710.rst > create mode 100644 drivers/hwmon/pmbus/xdp710.c > > diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst > index 1ca7a4fe1f8f..b2546925fb15 100644 > --- a/Documentation/hwmon/index.rst > +++ b/Documentation/hwmon/index.rst > @@ -250,6 +250,7 @@ Hardware Monitoring Kernel Drivers > wm831x > wm8350 > xgene-hwmon > + xdp710 > xdpe12284 > xdpe152c4 > zl6100 > diff --git a/Documentation/hwmon/xdp710.rst b/Documentation/hwmon/xdp710.rst > new file mode 100644 > index 000000000000..083891f27818 > --- /dev/null > +++ b/Documentation/hwmon/xdp710.rst > @@ -0,0 +1,83 @@ > +.. SPDX-License-Identifier: GPL-2.0 > + > +Kernel driver xdp710 > +==================== > + > +Supported chips: > + > + * Infineon XDP710 > + > + Prefix: 'xdp710' > + > + * Datasheet > + > + Publicly available at the Infineon website : https://www.infineon.com/dgdl/Infineon-XDP710-001-DataSheet-v01_00-EN.pdf?fileId=8ac78c8c8412f8d301848a5316290b97 > + > +Author: > + > + Peter Yin > + > +Description > +----------- > + > +This driver implements support for Infineon XDP710 Hot-Swap Controller. > + > +Device compliant with: > + > +- PMBus rev 1.3 interface. > + > +Device supports direct and linear format for reading input voltage, > +output voltage, output current, input power and temperature. > + > +The driver exports the following attributes via the 'sysfs' files > +for input voltage: > + > +**in1_input** > + > +**in1_label** > + > +**in1_max** > + > +**in1_max_alarm** > + > +**in1_min** > + > +**in1_min_alarm** > + > +The driver provides the following attributes for output voltage: > + > +**in2_input** > + > +**in2_label** > + > +**in2_alarm** > + > +The driver provides the following attributes for output current: > + > +**curr1_input** > + > +**curr1_label** > + > +**curr1_alarm** > + > +**curr1_max** > + > +The driver provides the following attributes for input power: > + > +**power1_input** > + > +**power1_label** > + > +**power1_alarm** > + > +The driver provides the following attributes for temperature: > + > +**temp1_input** > + > +**temp1_max** > + > +**temp1_max_alarm** > + > +**temp1_crit** > + > +**temp1_crit_alarm** > diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig > index 557ae0c414b0..c775128c2ea7 100644 > --- a/drivers/hwmon/pmbus/Kconfig > +++ b/drivers/hwmon/pmbus/Kconfig > @@ -511,6 +511,15 @@ config SENSORS_UCD9200 > This driver can also be built as a module. If so, the module will > be called ucd9200. > > +config SENSORS_XDP710 > + tristate "Infineon XDP710 family" > + help > + If you say yes here you get hardware monitoring support for Infineon > + XDP710. > + > + This driver can also be built as a module. If so, the module will > + be called xdp710. > + > config SENSORS_XDPE152 > tristate "Infineon XDPE152 family" > help > diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile > index f14ecf03ad77..4fe630793721 100644 > --- a/drivers/hwmon/pmbus/Makefile > +++ b/drivers/hwmon/pmbus/Makefile > @@ -51,6 +51,7 @@ obj-$(CONFIG_SENSORS_TPS53679) += tps53679.o > obj-$(CONFIG_SENSORS_TPS546D24) += tps546d24.o > obj-$(CONFIG_SENSORS_UCD9000) += ucd9000.o > obj-$(CONFIG_SENSORS_UCD9200) += ucd9200.o > +obj-$(CONFIG_SENSORS_XDP710) += xdp710.o > obj-$(CONFIG_SENSORS_XDPE122) += xdpe12284.o > obj-$(CONFIG_SENSORS_XDPE152) += xdpe152c4.o > obj-$(CONFIG_SENSORS_ZL6100) += zl6100.o > diff --git a/drivers/hwmon/pmbus/xdp710.c b/drivers/hwmon/pmbus/xdp710.c > new file mode 100644 > index 000000000000..a00f79cda5e5 > --- /dev/null > +++ b/drivers/hwmon/pmbus/xdp710.c > @@ -0,0 +1,132 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Driver for Infineon XDP710 Hot-Swap Controller > + */ > + > +#include > +#include > +#include > +#include > +#include "pmbus.h" > + > +#define XDP710_REG_CFG 0xD3 > +#define XDP710_V_SNS_CFG 0xD4 > +#define XDP710_CS_RNG 0xD5 > + > +/* > + * The table to map configuration register values > + * to sense resistor values > + */ > +const int microOhmRsense[] = { > + 200, 250, 300, 330, 400, 470, 500, 600, > + 670, 700, 750, 800, 900, 1000, 1100, 1200, > + 1250, 1300, 1400, 1500, 1600, 1700, 1800, 1900, > + 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, > + 2800, 3000, 3100, 3200, 3300, 3400, 3500, 3600, > + 3700, 3800, 3900, 4000, 4100, 4200, 4300, 4400, > + 4500, 4600, 4700, 4800, 4900, 5000, 5500, 6000, > + 6500, 7000, 7500, 8000, 8500, 9000, 9500, 10000 > +}; > + > +static struct pmbus_driver_info xdp710_info = { > + .pages = 1, > + .format[PSC_VOLTAGE_IN] = direct, > + .format[PSC_VOLTAGE_OUT] = direct, > + .format[PSC_CURRENT_OUT] = direct, > + .format[PSC_POWER] = direct, > + .format[PSC_TEMPERATURE] = direct, > + .m[PSC_VOLTAGE_IN] = 4653, > + .b[PSC_VOLTAGE_IN] = 0, > + .R[PSC_VOLTAGE_IN] = -2, > + .m[PSC_VOLTAGE_OUT] = 4653, > + .b[PSC_VOLTAGE_OUT] = 0, > + .R[PSC_VOLTAGE_OUT] = -2, > + .m[PSC_CURRENT_OUT] = 23165, > + .b[PSC_CURRENT_OUT] = 0, > + .R[PSC_CURRENT_OUT] = -2, > + .m[PSC_POWER] = 4211, > + .b[PSC_POWER] = 0, > + .R[PSC_POWER] = -2, > + .m[PSC_TEMPERATURE] = 52, > + .b[PSC_TEMPERATURE] = 14321, > + .R[PSC_TEMPERATURE] = -1, > + .func[0] = > + PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_PIN | > + PMBUS_HAVE_TEMP | PMBUS_HAVE_IOUT | > + PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP, > +}; > + > +static int xdp710_probe(struct i2c_client *client) > +{ > + struct pmbus_driver_info *info; > + u8 cs_rng; > + u8 vtlm_rng; > + int rsense; > + int ret; > + int m = 0; > + > + info = devm_kmemdup(&client->dev, &xdp710_info, sizeof(*info), > + GFP_KERNEL); > + if (!info) > + return -ENOMEM; > + > + ret = i2c_smbus_read_word_data(client, XDP710_CS_RNG); > + if (ret < 0) { > + dev_err(&client->dev, "Can't get CS_RNG"); > + return ret; > + } > + cs_rng = (ret >> 6) & GENMASK(1, 0); > + > + ret = i2c_smbus_read_word_data(client, XDP710_V_SNS_CFG); > + if (ret < 0) { > + dev_err(&client->dev, "Can't get V_SNS_CFG"); > + return ret; > + } > + vtlm_rng = ret & GENMASK(1, 0); > + > + ret = i2c_smbus_read_word_data(client, XDP710_REG_CFG); > + if (ret < 0) { > + dev_err(&client->dev, "Can't get REG_CFG"); > + return ret; > + } > + ret &= GENMASK(5, 0); > + rsense = microOhmRsense[ret]; > + > + info->m[PSC_VOLTAGE_IN] <<= vtlm_rng; > + info->m[PSC_VOLTAGE_OUT] <<= vtlm_rng; > + > + m = info->m[PSC_CURRENT_OUT]; > + info->m[PSC_CURRENT_OUT] = DIV_ROUND_CLOSEST(m * rsense >> cs_rng, > + 1000); > + > + m = info->m[PSC_POWER]; > + info->m[PSC_POWER] = DIV_ROUND_CLOSEST(m * rsense >> cs_rng, 1000); > + > + return pmbus_do_probe(client, info); > +} > + > +static const struct of_device_id xdp710_of_match[] = { > + { .compatible = "infineon,xdp710" }, > + {} > +}; > + > +static const struct i2c_device_id xdp710_id[] = { > + {"xdp710", 0}, > + { } > +}; > +MODULE_DEVICE_TABLE(i2c, xdp710_id); > + > +static struct i2c_driver xdp710_driver = { > + .driver = { > + .name = "xdp710", > + .of_match_table = xdp710_of_match, > + }, > + .probe = xdp710_probe, > + .id_table = xdp710_id, > +}; > +module_i2c_driver(xdp710_driver); > + > +MODULE_AUTHOR("Peter Yin "); > +MODULE_DESCRIPTION("PMBus driver for XDP710 HSC"); > +MODULE_LICENSE("GPL"); > +MODULE_IMPORT_NS(PMBUS);