outreachy.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Gokhan Celik <gokhan.celik@analog.com>
To: <outreachy@lists.linux.dev>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>, Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Gokhan Celik <Gokhan.Celik@analog.com>,
	<linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>,
	Gokhan Celik <gokhan.celik@analog.com>
Subject: [PATCH v4 1/2] regulator: max77503: Add ADI MAX77503 support
Date: Sun, 22 Oct 2023 21:52:50 +0300	[thread overview]
Message-ID: <10bb3894fea31a098d768e346c8721e730d7cb21.1698000185.git.gokhan.celik@analog.com> (raw)
In-Reply-To: <cover.1698000185.git.gokhan.celik@analog.com>

Add ADI MAX77503 buck converter driver support.

Signed-off-by: Gokhan Celik <gokhan.celik@analog.com>
---
Changelog:
V3 -> V4: The kernel is updated

 drivers/regulator/Kconfig              |  10 ++
 drivers/regulator/Makefile             |   1 +
 drivers/regulator/max77503-regulator.c | 137 +++++++++++++++++++++++++
 3 files changed, 148 insertions(+)
 create mode 100644 drivers/regulator/max77503-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 965d4f0c18a6..f3ec24691378 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -564,6 +564,16 @@ config REGULATOR_MAX5970
 	  The MAX5970/5978 is a smart switch with no output regulation, but
 	  fault protection and voltage and current monitoring capabilities.
 
+config REGULATOR_MAX77503
+	tristate "Analog Devices MAX77503 Regulator"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  This driver controls a Analog Devices MAX77503 14V input, 1.5A
+	  high-efficiency buck converter via I2C bus.
+	  Say M here if you want to include support for the regulator as a
+	  module.
+
 config REGULATOR_MAX77541
 	tristate "Analog Devices MAX77541/77540 Regulator"
 	depends on MFD_MAX77541
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 23074714a81a..b2b059b5ee56 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -69,6 +69,7 @@ obj-$(CONFIG_REGULATOR_LTC3676) += ltc3676.o
 obj-$(CONFIG_REGULATOR_MAX14577) += max14577-regulator.o
 obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o
 obj-$(CONFIG_REGULATOR_MAX5970) += max5970-regulator.o
+obj-$(CONFIG_REGULATOR_MAX77503) += max77503-regulator.o
 obj-$(CONFIG_REGULATOR_MAX77541) += max77541-regulator.o
 obj-$(CONFIG_REGULATOR_MAX77620) += max77620-regulator.o
 obj-$(CONFIG_REGULATOR_MAX77650) += max77650-regulator.o
diff --git a/drivers/regulator/max77503-regulator.c b/drivers/regulator/max77503-regulator.c
new file mode 100644
index 000000000000..4a6ba4dd2acd
--- /dev/null
+++ b/drivers/regulator/max77503-regulator.c
@@ -0,0 +1,137 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2023 Analog Devices, Inc.
+ * ADI regulator driver for MAX77503.
+ */
+
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+#include <linux/regulator/of_regulator.h>
+#include <linux/util_macros.h>
+
+#define MAX77503_REG_CFG			0x00
+#define MAX77503_REG_VOUT			0x01
+
+#define MAX77503_BIT_EN				BIT(0)
+#define MAX77503_BIT_CURR_LIM		BIT(3)
+#define MAX77503_BIT_ADEN			BIT(6)
+
+#define MAX77503_BITS_SOFT_START	GENMASK(5, 4)
+#define MAX77503_BITS_MX_VOUT		GENMASK(7, 0)
+
+#define MAX77503_AD_ENABLED			0x1
+#define MAX77503_AD_DISABLED		0x0
+
+struct max77503_dev {
+	struct device *dev;
+	struct device_node *of_node;
+	struct regulator_desc desc;
+	struct regulator_dev *rdev;
+	struct regmap *regmap;
+};
+
+static const struct regmap_config max77503_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = 0x2,
+};
+
+static const struct regulator_ops max77503_buck_ops = {
+	.list_voltage = regulator_list_voltage_linear_range,
+	.map_voltage = regulator_map_voltage_ascend,
+	.is_enabled = regulator_is_enabled_regmap,
+	.enable = regulator_enable_regmap,
+	.disable = regulator_disable_regmap,
+	.get_voltage_sel = regulator_get_voltage_sel_regmap,
+	.set_voltage_sel = regulator_set_voltage_sel_regmap,
+	.get_current_limit = regulator_get_current_limit_regmap,
+	.set_current_limit = regulator_set_current_limit_regmap,
+	.set_active_discharge = regulator_set_active_discharge_regmap,
+	.set_soft_start = regulator_set_soft_start_regmap,
+};
+
+static const struct linear_range max77503_buck_ranges[] = {
+	REGULATOR_LINEAR_RANGE(800000, 0x00, 0x54, 50000)
+};
+
+static const unsigned int max77503_current_limit_table[] = {
+	500000, 2000000
+};
+
+static const struct regulator_desc max77503_regulators_desc = {
+	.name = "max77503",
+	.enable_reg = MAX77503_REG_CFG,
+	.enable_mask = MAX77503_BIT_EN,
+	.ops = &max77503_buck_ops,
+	.type = REGULATOR_VOLTAGE,
+	.linear_ranges = max77503_buck_ranges,
+	.n_linear_ranges = ARRAY_SIZE(max77503_buck_ranges),
+	.vsel_reg = MAX77503_REG_VOUT,
+	.vsel_mask = MAX77503_BITS_MX_VOUT,
+	.soft_start_reg = MAX77503_REG_CFG,
+	.soft_start_mask = MAX77503_BITS_SOFT_START,
+	.active_discharge_reg = MAX77503_REG_CFG,
+	.active_discharge_mask = MAX77503_BIT_ADEN,
+	.active_discharge_off = MAX77503_AD_DISABLED,
+	.active_discharge_on = MAX77503_AD_ENABLED,
+	.csel_reg = MAX77503_REG_CFG,
+	.csel_mask = MAX77503_BIT_CURR_LIM,
+	.curr_table = max77503_current_limit_table,
+	.n_current_limits = ARRAY_SIZE(max77503_current_limit_table),
+	.owner = THIS_MODULE,
+};
+
+static int max77503_regulator_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct regulator_config config = {};
+	struct regulator_dev *rdev;
+
+	config.dev = dev;
+	config.of_node = dev->of_node;
+	config.regmap = devm_regmap_init_i2c(client, &max77503_regmap_config);
+	if (IS_ERR(config.regmap)) {
+		dev_err(dev, "Failed to init regmap");
+		return PTR_ERR(config.regmap);
+	}
+
+	rdev = devm_regulator_register(dev, &max77503_regulators_desc, &config);
+	if (IS_ERR(rdev)) {
+		dev_err(dev, "Failed to register regulator MAX77503");
+		return PTR_ERR(rdev);
+	}
+
+	return 0;
+}
+
+static const struct of_device_id of_max77503_match_tbl[] = {
+	{ .compatible = "adi,max77503", },
+	{ }
+};
+
+MODULE_DEVICE_TABLE(of, of_max77503_match_tbl);
+
+static const struct i2c_device_id max77503_regulator_id[] = {
+	{"max77503"},
+	{ }
+};
+
+MODULE_DEVICE_TABLE(i2c, max77503_regulator_id);
+
+static struct i2c_driver max77503_regulator_driver = {
+	.driver = {
+		.name = "max77503",
+		.of_match_table = of_max77503_match_tbl
+	},
+	.probe = max77503_regulator_probe,
+	.id_table = max77503_regulator_id,
+};
+
+module_i2c_driver(max77503_regulator_driver);
+
+MODULE_AUTHOR("Gokhan Celik <Gokhan.Celik@analog.com>");
+MODULE_DESCRIPTION("MAX77503 regulator driver");
+MODULE_LICENSE("GPL");
-- 
2.34.1


  reply	other threads:[~2023-10-22 19:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-22 18:52 [PATCH v4 0/2] Add ADI MAX77503 regulator driver and bindings Gokhan Celik
2023-10-22 18:52 ` Gokhan Celik [this message]
2023-10-22 18:52 ` [PATCH v4 2/2] regulator: dt-bindings: Add ADI MAX77503 support Gokhan Celik
2023-10-23 17:00 ` [PATCH v4 0/2] Add ADI MAX77503 regulator driver and bindings Mark Brown

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=10bb3894fea31a098d768e346c8721e730d7cb21.1698000185.git.gokhan.celik@analog.com \
    --to=gokhan.celik@analog.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=outreachy@lists.linux.dev \
    --cc=robh+dt@kernel.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).