mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Scott Smith <scott8440@gmail.com>
To: linux@roeck-us.net, jdelvare@suse.com
Cc: Scott Smith <scott8440@gmail.com>,
	linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org
Subject: [PATCH] hwmon: (pmbus) add ir35215 driver
Date: Thu, 27 Apr 2023 12:35:31 -0700	[thread overview]
Message-ID: <20230427193533.718526-1-scott8440@gmail.com> (raw)

IR35215 is a digital multi-phase controller.

Signed-off-by: Scott Smith <scott8440@gmail.com>
---
 drivers/hwmon/pmbus/Kconfig   |  9 +++++
 drivers/hwmon/pmbus/Makefile  |  1 +
 drivers/hwmon/pmbus/ir35215.c | 65 +++++++++++++++++++++++++++++++++++
 3 files changed, 75 insertions(+)
 create mode 100644 drivers/hwmon/pmbus/ir35215.c

diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
index 270b6336b76d..5c089f7e4423 100644
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -123,6 +123,15 @@ config SENSORS_INSPUR_IPSPS
 	  This driver can also be built as a module. If so, the module will
 	  be called inspur-ipsps.
 
+config SENSORS_IR35215
+       tristate "Infineon IR35215"
+       help
+         If you say yes here you get hardware monitoring support for the
+         Infineon IR35215 controller.
+
+         This driver can also be built as a module. If so, the module will
+         be called ir35215.
+
 config SENSORS_IR35221
 	tristate "Infineon IR35221"
 	help
diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
index 84ee960a6c2d..fbb9cf048326 100644
--- a/drivers/hwmon/pmbus/Makefile
+++ b/drivers/hwmon/pmbus/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_SENSORS_FSP_3Y)	+= fsp-3y.o
 obj-$(CONFIG_SENSORS_IBM_CFFPS)	+= ibm-cffps.o
 obj-$(CONFIG_SENSORS_DPS920AB)	+= dps920ab.o
 obj-$(CONFIG_SENSORS_INSPUR_IPSPS) += inspur-ipsps.o
+obj-$(CONFIG_SENSORS_IR35215)   += ir35215.o
 obj-$(CONFIG_SENSORS_IR35221)	+= ir35221.o
 obj-$(CONFIG_SENSORS_IR36021)	+= ir36021.o
 obj-$(CONFIG_SENSORS_IR38064)	+= ir38064.o
diff --git a/drivers/hwmon/pmbus/ir35215.c b/drivers/hwmon/pmbus/ir35215.c
new file mode 100644
index 000000000000..92d59e78bfd0
--- /dev/null
+++ b/drivers/hwmon/pmbus/ir35215.c
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Hardware monitoring driver for Infineon IR35215
+ *
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
+ */
+
+#include <linux/err.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include "pmbus.h"
+
+static const u32 functionality = PMBUS_HAVE_TEMP
+	| PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT
+	| PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT
+	| PMBUS_HAVE_PIN | PMBUS_HAVE_POUT
+	| PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT
+	| PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP;
+
+static struct pmbus_driver_info ir35215_info = {
+	.pages = 2,
+	.format[PSC_VOLTAGE_IN] = linear,
+	.format[PSC_VOLTAGE_OUT] = linear,
+	.format[PSC_CURRENT_IN] = linear,
+	.format[PSC_CURRENT_OUT] = linear,
+	.format[PSC_POWER] = linear,
+	.format[PSC_TEMPERATURE] = linear,
+	.func[0] = functionality,
+	.func[1] = functionality,
+};
+
+static int ir35215_probe(struct i2c_client *client)
+{
+	/*
+	 * IR35215 devices may not stay in page 0 during device
+	 * probe which leads to probe failure (read status word failed).
+	 * So let's set the device to page 0 at the beginning.
+	 */
+	i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
+	return pmbus_do_probe(client, &ir35215_info);
+}
+
+static const struct i2c_device_id ir35215_id[] = {
+	{ "ir35215", 0 },
+	{}
+};
+MODULE_DEVICE_TABLE(i2c, ir35215_id);
+
+static struct i2c_driver ir35215_driver = {
+	.driver = {
+		   .name = "ir35215",
+	},
+	.probe_new = ir35215_probe,
+	.id_table = ir35215_id,
+};
+
+module_i2c_driver(ir35215_driver);
+
+MODULE_AUTHOR("Tao Ren <rentao.bupt@gmail.com>");
+MODULE_DESCRIPTION("PMBus driver for Infineon IR35215");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS(PMBUS);
-- 
2.34.1


             reply	other threads:[~2023-04-27 19:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-27 19:35 Scott Smith [this message]
2023-04-27 21:09 ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230427193533.718526-1-scott8440@gmail.com \
    --to=scott8440@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®